Skip to content

Commit

Permalink
feat: supoort set default active view (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed May 20, 2024
1 parent df3021f commit f854f75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 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 @@ -41,6 +41,7 @@ const workspace = new Workspace({
// 2. 引擎初始化
const engine = createEngine({
workspace,
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,4 +1,4 @@
import { Designer, Engine, SimulatorNameType } from './models';
import { Designer, DesignerViewType, Engine, SimulatorNameType } from './models';
import { IWorkspace } from './models/interfaces';

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

/**
Expand All @@ -23,6 +27,7 @@ interface ICreateEngineOptions {
*/
export function createEngine({
workspace,
defaultActiveView = 'design',
defaultSimulatorMode = 'desktop',
defaultActiveSidebarPanel = '',
}: ICreateEngineOptions) {
Expand All @@ -31,6 +36,7 @@ export function createEngine({
designer: new Designer({
workspace,
simulator: defaultSimulatorMode,
activeView: defaultActiveView,
activeSidebarPanel: defaultActiveSidebarPanel,
}),
});
Expand Down
15 changes: 14 additions & 1 deletion packages/core/src/models/designer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ interface IDesignerOptions {
workspace: IWorkspace;
simulator?: SimulatorNameType | ISimulatorType;
activeSidebarPanel?: string;
/**
* 默认激活的视图模式
*/
activeView?: DesignerViewType;
}

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

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

// 默认设计器模式
if (simulator) {
Expand All @@ -124,6 +132,11 @@ export class Designer {
this.setActiveSidebarPanel(defaultActiveSidebarPanel);
}

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

makeObservable(this, {
_simulator: observable,
_viewport: observable,
Expand Down

0 comments on commit f854f75

Please sign in to comment.