diff --git a/docs/docs/api/model/window.md b/docs/docs/api/model/window.md index 8c2fa1802..177d3438a 100644 --- a/docs/docs/api/model/window.md +++ b/docs/docs/api/model/window.md @@ -16,8 +16,10 @@ sidebar_position: 12 ### importSchema(schema: IPublicTypeNodeSchema) 当前窗口导入 schema +相关类型:[IPublicTypeNodeSchema](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/node-schema.ts) + ### changeViewType(viewName: string) 修改当前窗口视图类型 -### async save +### async save() 调用当前窗口视图保存钩子 diff --git a/docs/docs/api/workspace.md b/docs/docs/api/workspace.md index 99d1fb6df..e710bceec 100644 --- a/docs/docs/api/workspace.md +++ b/docs/docs/api/workspace.md @@ -32,3 +32,5 @@ sidebar_position: 12 /** 注册资源 */ registerResourceType(resourceName: string, resourceType: 'editor', options: IPublicResourceOptions): void; ``` + +相关类型:[IPublicResourceOptions](https://github.com/alibaba/lowcode-engine/blob/main/packages/types/src/shell/type/resource-options.ts) diff --git a/packages/editor-skeleton/src/layouts/left-area.tsx b/packages/editor-skeleton/src/layouts/left-area.tsx index 1164c9799..cbeba5a5c 100644 --- a/packages/editor-skeleton/src/layouts/left-area.tsx +++ b/packages/editor-skeleton/src/layouts/left-area.tsx @@ -7,6 +7,9 @@ import { Area } from '../area'; export default class LeftArea extends Component<{ area: Area }> { render() { const { area } = this.props; + if (area.isEmpty()) { + return null; + } return (
}> { render() { const { area } = this.props; + if (area.isEmpty()) { + return null; + } return (
{ render() { const { area, itemClassName } = this.props; + if (area.isEmpty()) { + return null; + } return (
{ +export class Workbench extends Component<{ + skeleton: Skeleton; + config?: EditorConfig; + components?: PluginClassSet; + className?: string; + topAreaItemClassName?: string; +}> { constructor(props: any) { super(props); const { config, components, skeleton } = this.props; skeleton.buildFromConfig(config, components); } - // componentDidCatch(error: any) { - // globalContext.get(Editor).emit('editor.skeleton.workbench.error', error); - // } - render() { - const { skeleton, className, topAreaItemClassName } = this.props; + const { + skeleton, + className, + topAreaItemClassName, + } = this.props; return (
diff --git a/packages/engine/src/engine-core.ts b/packages/engine/src/engine-core.ts index 42019ad26..99286c3c3 100644 --- a/packages/engine/src/engine-core.ts +++ b/packages/engine/src/engine-core.ts @@ -66,7 +66,7 @@ async function registryInnerPlugin(designer: Designer, editor: Editor, plugins: await plugins.register(OutlinePlugin, {}, { autoInit: true }); await plugins.register(componentMetaParser(designer)); await plugins.register(setterRegistry, {}, { autoInit: true }); - await plugins.register(defaultPanelRegistry(editor, designer)); + await plugins.register(defaultPanelRegistry(editor)); await plugins.register(builtinHotkey); } diff --git a/packages/engine/src/inner-plugins/default-panel-registry.tsx b/packages/engine/src/inner-plugins/default-panel-registry.tsx index 9ef1db7cb..d7549d764 100644 --- a/packages/engine/src/inner-plugins/default-panel-registry.tsx +++ b/packages/engine/src/inner-plugins/default-panel-registry.tsx @@ -3,7 +3,7 @@ import { SettingsPrimaryPane } from '@alilc/lowcode-editor-skeleton'; import DesignerPlugin from '@alilc/lowcode-plugin-designer'; // 注册默认的面板 -export const defaultPanelRegistry = (editor: any, designer: any) => { +export const defaultPanelRegistry = (editor: any) => { const fun = (ctx: IPublicModelPluginContext) => { return { init() { diff --git a/packages/types/src/shell/model/window.ts b/packages/types/src/shell/model/window.ts index 4ffed5d07..f0faedbcd 100644 --- a/packages/types/src/shell/model/window.ts +++ b/packages/types/src/shell/model/window.ts @@ -8,7 +8,5 @@ export interface IPublicModelWindow { changeViewType(viewName: string): void; /** 调用当前窗口视图保存钩子 */ - save(): Promise<{ - [viewName: string]: IPublicTypeNodeSchema | any; - }>; + save(): Promise; } \ No newline at end of file diff --git a/packages/types/src/shell/type/resource-options.ts b/packages/types/src/shell/type/resource-options.ts index 63e8e4add..94547bb57 100644 --- a/packages/types/src/shell/type/resource-options.ts +++ b/packages/types/src/shell/type/resource-options.ts @@ -8,6 +8,8 @@ export interface IPublicViewFunctions { export interface IPublicEditorView { /** 资源名字 */ viewName: string; + /** 资源类型 */ + viewType?: 'editor' | 'webview'; (ctx: any): IPublicViewFunctions; } @@ -25,8 +27,12 @@ export interface IPublicResourceOptions { editorViews: IPublicEditorView[]; /** save 钩子 */ - save?: () => Promise; + save?: (schema: { + [viewName: string]: any; + }) => Promise; /** import 钩子 */ - import?: () => Promise; + import?: (schema: any) => Promise<{ + [viewName: string]: any; + }>; } \ No newline at end of file diff --git a/packages/workspace/src/base-context.ts b/packages/workspace/src/base-context.ts index 86b66fc31..047e5179e 100644 --- a/packages/workspace/src/base-context.ts +++ b/packages/workspace/src/base-context.ts @@ -35,6 +35,7 @@ import { import { getLogger } from '@alilc/lowcode-utils'; import { Workspace as InnerWorkspace } from './index'; import { EditorWindow } from './editor-window/context'; + export class BasicContext { skeleton: Skeleton; plugins: Plugins; diff --git a/packages/workspace/src/editor-view/context.ts b/packages/workspace/src/editor-view/context.ts index 63f1e2965..913228674 100644 --- a/packages/workspace/src/editor-view/context.ts +++ b/packages/workspace/src/editor-view/context.ts @@ -1,16 +1,22 @@ import { makeObservable, obx } from '@alilc/lowcode-editor-core'; -import { EditorViewOptions, EditorWindow, ViewFunctions } from '@alilc/lowcode-workspace'; +import { IPublicEditorView, IPublicViewFunctions } from '@alilc/lowcode-types'; import { flow } from 'mobx'; +import { Workspace as InnerWorkspace } from '../'; import { BasicContext } from '../base-context'; +import { EditorWindow } from '../editor-window/context'; +import { getWebviewPlugin } from '../inner-plugins/webview'; export class Context extends BasicContext { - name = 'editor-view'; + viewName = 'editor-view'; - instance: ViewFunctions; + instance: IPublicViewFunctions; - constructor(public workspace: any, public editorWindow: EditorWindow, public editorView: EditorViewOptions) { + viewType: 'editor' | 'webview'; + + constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicEditorView) { super(workspace, editorView.viewName, editorWindow); - this.name = editorView.viewName; + this.viewType = editorView.viewType || 'editor'; + this.viewName = editorView.viewName; this.instance = editorView(this.innerPlugins._getLowCodePluginContext({ pluginName: 'any', })); @@ -31,8 +37,13 @@ export class Context extends BasicContext { @obx isInit: boolean = false; init = flow(function* (this: any) { - yield this.registerInnerPlugins(); - yield this.instance?.init(); + if (this.viewType === 'webview') { + const url = yield this.instance?.url?.(); + yield this.plugins.register(getWebviewPlugin(url, this.viewName)); + } else { + yield this.registerInnerPlugins(); + } + yield this.instance?.init?.(); yield this.innerPlugins.init(); this.isInit = true; }); diff --git a/packages/workspace/src/editor-view/view.tsx b/packages/workspace/src/editor-view/view.tsx index 7611a0010..ca3a08fb2 100644 --- a/packages/workspace/src/editor-view/view.tsx +++ b/packages/workspace/src/editor-view/view.tsx @@ -3,11 +3,15 @@ import { Workbench, } from '@alilc/lowcode-editor-skeleton'; import { Component } from 'react'; +import { Context } from './context'; export * from '../base-context'; @observer -export class EditorView extends Component { +export class EditorView extends Component<{ + editorView: Context; + active: boolean; +}, any> { render() { const { active } = this.props; const editorView = this.props.editorView; diff --git a/packages/workspace/src/editor-window/context.ts b/packages/workspace/src/editor-window/context.ts index 31bbc88f3..ee680b140 100644 --- a/packages/workspace/src/editor-window/context.ts +++ b/packages/workspace/src/editor-window/context.ts @@ -12,6 +12,10 @@ export class EditorWindow { async importSchema(schema: any) { const newSchema = await this.resource.import(schema); + if (!newSchema) { + return; + } + Object.keys(newSchema).forEach(key => { const view = this.editorViews.get(key); view?.project.importSchema(newSchema[key]); diff --git a/packages/workspace/src/inner-plugins/webview.tsx b/packages/workspace/src/inner-plugins/webview.tsx new file mode 100644 index 000000000..be9c15f8b --- /dev/null +++ b/packages/workspace/src/inner-plugins/webview.tsx @@ -0,0 +1,49 @@ +import { IPublicModelPluginContext } from '@alilc/lowcode-types'; + +function DesignerView(props: { + url: string; + viewName: string; +}) { + return ( +
+
+
+