Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: supoort set default active view #157

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading