GeezerVison is showing github.com — feat: support webview type resource in workspace mode · DBvc/lowcode-engine@36d1d3b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/shell/src/model/resource.ts +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,4 +32,12 @@ export class Resource implements IPublicModelResource { | 32 | 32 | get category() { | 33 | 33 | return this[resourceSymbol].category; | 34 | 34 | } | | 35 | + | | 36 | + get children() { | | 37 | + return this[resourceSymbol].children.map((child) => new Resource(child)); | | 38 | + } | | 39 | + | | 40 | + get viewType() { | | 41 | + return this[resourceSymbol].viewType; | | 42 | + } | 35 | 43 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/api/workspace.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,7 +21,7 @@ export interface IPublicApiWorkspace { | 21 | 21 | setResourceList(resourceList: IPublicResourceList): void; | 22 | 22 |
| 23 | 23 | /** 资源树列表更新事件 */ | 24 | | - onResourceListChange(fn: (resourceList: IPublicResourceList) => void): () => IPublicTypeDisposable; | | 24 | + onResourceListChange(fn: (resourceList: IPublicResourceList) => void): IPublicTypeDisposable; | 25 | 25 |
| 26 | 26 | /** 注册资源 */ | 27 | 27 | registerResourceType(resourceTypeModel: IPublicTypeResourceType): void; | |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/type/editor-view-config.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,4 +5,7 @@ export interface IPublicEditorViewConfig { | 5 | 5 |
| 6 | 6 | /** 资源保存时,会调用视图的钩子 */ | 7 | 7 | save?: () => Promise<void>; | | 8 | + | | 9 | + /** viewType 类型为 'webview' 时渲染的地址 */ | | 10 | + url?: () => Promise<string>; | 8 | 11 | } |
Collapse file Copy file name to clipboard +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { ReactElement } from 'react'; | | 2 | + | 1 | 3 | export interface IPublicResourceData { | 2 | 4 | resourceName: string; | 3 | 5 | title: string; | 4 | 6 | category?: string; | | 7 | + viewType?: string; | | 8 | + icon?: ReactElement; | 5 | 9 | options: { | 6 | 10 | [key: string]: any; | 7 | 11 | }; | | 12 | + children?: IPublicResourceData[]; | 8 | 13 | } | 9 | 14 |
| 10 | 15 | export type IPublicResourceList = IPublicResourceData[]; |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/type/resource-type-config.ts +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,4 +28,7 @@ export interface IPublicResourceTypeConfig { | 28 | 28 |
| 29 | 29 | /** 默认标题 */ | 30 | 30 | defaultTitle?: string; | | 31 | + | | 32 | + /** resourceType 类型为 'webview' 时渲染的地址 */ | | 33 | + url?: () => Promise<string>; | 31 | 34 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/types/src/shell/type/resource-type.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,7 +4,7 @@ import { IPublicResourceTypeConfig } from './resource-type-config'; | 4 | 4 | export interface IPublicTypeResourceType { | 5 | 5 | resourceName: string; | 6 | 6 |
| 7 | | - resourceType: string; | | 7 | + resourceType: 'editor' | 'webview'; | 8 | 8 |
| 9 | | - (ctx: IPublicModelPluginContext): IPublicResourceTypeConfig; | | 9 | + (ctx: IPublicModelPluginContext, options: Object): IPublicResourceTypeConfig; | 10 | 10 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/workspace/src/context/base-context.ts +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,18 +28,22 @@ import { | 28 | 28 | Canvas, | 29 | 29 | } from '@alilc/lowcode-shell'; | 30 | 30 | import { | | 31 | + IPluginPreferenceMananger, | | 32 | + IPublicApiEvent, | | 33 | + IPublicModelPluginContext, | 31 | 34 | IPublicTypePluginMeta, | 32 | 35 | } from '@alilc/lowcode-types'; | 33 | 36 | import { getLogger } from '@alilc/lowcode-utils'; | 34 | 37 | import { Workspace as InnerWorkspace } from '../workspace'; | 35 | 38 | import { EditorWindow } from '../window'; | 36 | 39 |
| 37 | | -export class BasicContext { | | 40 | +export class BasicContext implements IPublicModelPluginContext { | 38 | 41 | skeleton: Skeleton; | 39 | 42 | plugins: Plugins; | 40 | 43 | project: Project; | 41 | 44 | setters: Setters; | 42 | 45 | material: Material; | | 46 | + common: Common; | 43 | 47 | config; | 44 | 48 | event; | 45 | 49 | logger; | @@ -53,6 +57,8 @@ export class BasicContext { | 53 | 57 | innerHotkey: InnerHotkey; | 54 | 58 | innerPlugins: LowCodePluginManager; | 55 | 59 | canvas: Canvas; | | 60 | + pluginEvent: IPublicApiEvent; | | 61 | + preference: IPluginPreferenceMananger; | 56 | 62 |
| 57 | 63 | constructor(innerWorkspace: InnerWorkspace, viewName: string, public editorWindow?: EditorWindow) { | 58 | 64 | const editor = new Editor(viewName, true); | @@ -101,6 +107,7 @@ export class BasicContext { | 101 | 107 | this.designer = designer; | 102 | 108 | this.canvas = canvas; | 103 | 109 | const common = new Common(editor, innerSkeleton); | | 110 | + this.common = common; | 104 | 111 | let plugins: any; | 105 | 112 |
| 106 | 113 | const pluginContextApiAssembler: ILowCodePluginContextApiAssembler = { | |
Collapse file Copy file name to clipboardExpand all lines: packages/workspace/src/context/view-context.ts +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { makeObservable, obx } from '@alilc/lowcode-editor-core'; | | 1 | +import { computed, makeObservable, obx } from '@alilc/lowcode-editor-core'; | 2 | 2 | import { IPublicEditorViewConfig, IPublicTypeEditorView } from '@alilc/lowcode-types'; | 3 | 3 | import { flow } from 'mobx'; | 4 | 4 | import { Workspace as InnerWorkspace } from '../workspace'; | @@ -17,7 +17,7 @@ export class Context extends BasicContext { | 17 | 17 |
| 18 | 18 | @obx isInit: boolean = false; | 19 | 19 |
| 20 | | - get active() { | | 20 | + @computed get active() { | 21 | 21 | return this._activate; | 22 | 22 | } | 23 | 23 |
| @@ -33,7 +33,7 @@ export class Context extends BasicContext { | 33 | 33 | this.isInit = true; | 34 | 34 | }); | 35 | 35 |
| 36 | | - constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicTypeEditorView, options: Object) { | | 36 | + constructor(public workspace: InnerWorkspace, public editorWindow: EditorWindow, public editorView: IPublicTypeEditorView, options: Object | undefined) { | 37 | 37 | super(workspace, editorView.viewName, editorWindow); | 38 | 38 | this.viewType = editorView.viewType || 'editor'; | 39 | 39 | this.viewName = editorView.viewName; | |
Collapse file Copy file name to clipboardExpand all lines: packages/workspace/src/inner-plugins/webview.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { IPublicModelPluginContext } from '@alilc/lowcode-types'; | 2 | 2 |
| 3 | | -function DesignerView(props: { | | 3 | +export function DesignerView(props: { | 4 | 4 | url: string; | 5 | 5 | viewName: string; | 6 | 6 | }) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/workspace/src/resource.ts +15-3Lines changed: 15 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,12 +17,16 @@ export class Resource implements IPublicModelResource { | 17 | 17 | return this.resourceType.name; | 18 | 18 | } | 19 | 19 |
| | 20 | + get viewType() { | | 21 | + return this.resourceData.viewType; | | 22 | + } | | 23 | + | 20 | 24 | get description() { | 21 | 25 | return this.resourceTypeInstance?.description; | 22 | 26 | } | 23 | 27 |
| 24 | 28 | get icon() { | 25 | | - return this.resourceTypeInstance?.icon; | | 29 | + return this.resourceData.icon || this.resourceTypeInstance?.icon; | 26 | 30 | } | 27 | 31 |
| 28 | 32 | get type() { | @@ -45,9 +49,13 @@ export class Resource implements IPublicModelResource { | 45 | 49 | return this.context.innerSkeleton; | 46 | 50 | } | 47 | 51 |
| 48 | | - constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, workspace: InnerWorkSpace) { | | 52 | + get children(): Resource[] { | | 53 | + return this.resourceData?.children?.map(d => new Resource(d, this.resourceType, this.workspace)) || []; | | 54 | + } | | 55 | + | | 56 | + constructor(readonly resourceData: IPublicResourceData, readonly resourceType: ResourceType, readonly workspace: InnerWorkSpace) { | 49 | 57 | this.context = new BasicContext(workspace, `resource-${resourceData.resourceName || resourceType.name}`); | 50 | | - this.resourceTypeInstance = resourceType.resourceTypeModel(this.context, {}); | | 58 | + this.resourceTypeInstance = resourceType.resourceTypeModel(this.context, this.options); | 51 | 59 | this.init(); | 52 | 60 | if (this.resourceTypeInstance.editorViews) { | 53 | 61 | this.resourceTypeInstance.editorViews.forEach((d: any) => { | @@ -68,6 +76,10 @@ export class Resource implements IPublicModelResource { | 68 | 76 | return await this.resourceTypeInstance.import?.(schema); | 69 | 77 | } | 70 | 78 |
| | 79 | + async url() { | | 80 | + return await this.resourceTypeInstance.url?.(); | | 81 | + } | | 82 | + | 71 | 83 | async save(value: any) { | 72 | 84 | return await this.resourceTypeInstance.save?.(value); | 73 | 85 | } | |
|