Skip to content

Commit

Permalink
Merge branch 'main' into feat/ui-component
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed May 20, 2024
2 parents 0bf138b + f854f75 commit ce27ab2
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions apps/playground/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const workspace = new Workspace({
const engine = createEngine({
workspace,
menuData,
defaultActiveView: 'design', // dual code design
});

// @ts-ignore
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MenuDataType } from '@music163/tango-helpers';
import { Designer, Engine, SimulatorNameType } from './models';
import { Designer, DesignerViewType, Engine, SimulatorNameType } from './models';
import { IWorkspace } from './models/interfaces';

interface ICreateEngineOptions {
Expand All @@ -19,6 +19,10 @@ interface ICreateEngineOptions {
* 默认激活的侧边栏
*/
defaultActiveSidebarPanel?: string;
/**
* 默认激活的视图
*/
defaultActiveView?: DesignerViewType;
}

/**
Expand All @@ -28,6 +32,7 @@ interface ICreateEngineOptions {
*/
export function createEngine({
workspace,
defaultActiveView = 'design',
defaultSimulatorMode = 'desktop',
defaultActiveSidebarPanel = '',
menuData,
Expand All @@ -37,6 +42,7 @@ export function createEngine({
designer: new Designer({
workspace,
simulator: defaultSimulatorMode,
activeView: defaultActiveView,
activeSidebarPanel: defaultActiveSidebarPanel,
menuData,
}),
Expand Down
16 changes: 10 additions & 6 deletions packages/core/src/helpers/prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function prototype2importDeclarationData(
relativeFilepath?: string,
): { source: string; specifiers: IImportSpecifierData[] } {
let source = prototype.package;
const isSnippet = prototype.type === 'snippet';
if (relativeFilepath && isFilepath(source)) {
source = getRelativePath(relativeFilepath, source);
}
Expand All @@ -35,12 +36,15 @@ export function prototype2importDeclarationData(
type: 'ImportDefaultSpecifier',
});
} else {
[prototype.name, ...(prototype.relatedImports || [])].forEach((item) => {
specifiers.push({
localName: item,
type: 'ImportSpecifier',
});
});
// 忽略代码片段 name
[...(isSnippet ? [] : [prototype.name]), ...(prototype.relatedImports || [])].forEach(
(item) => {
specifiers.push({
localName: item,
type: 'ImportSpecifier',
});
},
);
}

return {
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/models/designer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ interface IDesignerOptions {
*/
menuData: MenuDataType;
activeSidebarPanel?: string;
/**
* 默认激活的视图模式
*/
activeView?: DesignerViewType;
}

const ISimulatorTypes: Record<string, ISimulatorType> = {
Expand Down Expand Up @@ -139,7 +143,12 @@ export class Designer {
constructor(options: IDesignerOptions) {
this.workspace = options.workspace;

const { simulator, menuData, activeSidebarPanel: defaultActiveSidebarPanel } = options;
const {
simulator,
menuData,
activeSidebarPanel: defaultActiveSidebarPanel,
activeView: defaultActiveView,
} = options;

if (menuData) {
this.setMenuData(menuData);
Expand All @@ -155,6 +164,11 @@ export class Designer {
this.setActiveSidebarPanel(defaultActiveSidebarPanel);
}

// 默认激活的视图
if (defaultActiveView) {
this.setActiveView(defaultActiveView);
}

makeObservable(this, {
_simulator: observable,
_viewport: observable,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/models/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class TangoHistory {
}

get couldBack() {
return this._records.length > 0 && this._index > -1;
return this._records.length > 0 && this._index > 0;
}

get couldForward() {
Expand Down
6 changes: 6 additions & 0 deletions packages/designer/src/dnd/use-dnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export function useDnd({
'command+v,ctrl+v': () => {
workspace.pasteSelectedNode();
},
'command+z,ctrl+z': () => {
workspace.history.back();
},
'command+shift+z,ctrl+shift+z': () => {
workspace.history.forward();
},
});
}, [workspace]);

Expand Down
12 changes: 10 additions & 2 deletions packages/designer/src/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, useEffect, useCallback } from 'react';
import { Box } from 'coral-system';
import { MultiEditor, MultiEditorProps } from '@music163/tango-ui';
import { observer, useWorkspace } from '@music163/tango-context';
import { observer, useDesigner, useWorkspace } from '@music163/tango-context';
import { isValidCode } from '@music163/tango-core';
import { Modal } from 'antd';

Expand Down Expand Up @@ -32,6 +32,7 @@ export const CodeEditor = observer(
({ autoRemoveUnusedImports = true, ...rest }: CodeEditorProps) => {
const editorRef = useRef(null);
const workspace = useWorkspace();
const designer = useDesigner();
const files = workspace.listFiles();
const activeFile = workspace.activeFile;

Expand Down Expand Up @@ -101,8 +102,15 @@ export const CodeEditor = observer(
[workspace],
);

const borderStyle =
designer.activeView === 'dual'
? {
borderLeft: 'solid 1px var(--tango-colors-line2)',
}
: {};

return (
<Box display="flex" flexDirection="row" height="100%" bg="white">
<Box display="flex" flexDirection="row" height="100%" bg="white" {...borderStyle}>
<MultiEditor
ref={editorRef}
options={{
Expand Down
2 changes: 2 additions & 0 deletions packages/setting-form/src/form-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ export function FormHeader({ title, extra, subTitle }: FormHeaderProps) {
mr="s"
whiteSpace="nowrap"
className="FormHeaderTitle"
textOverflow="ellipsis"
overflow="hidden"
>
{title}
</Box>
Expand Down

0 comments on commit ce27ab2

Please sign in to comment.