From ebe21c4d07d9b2805c524bad0e40d45cc8f12c91 Mon Sep 17 00:00:00 2001 From: liujuping Date: Tue, 21 Mar 2023 17:12:38 +0800 Subject: [PATCH 1/2] feat: resourceList children support different resourceName --- packages/workspace/src/context/base-context.ts | 3 ++- packages/workspace/src/inner-plugins/webview.tsx | 2 +- packages/workspace/src/resource.ts | 5 ++++- packages/workspace/src/view/resource-view.tsx | 8 ++++---- packages/workspace/src/window.ts | 2 ++ packages/workspace/src/workspace.ts | 2 ++ 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/workspace/src/context/base-context.ts b/packages/workspace/src/context/base-context.ts index b82e25872..e74ae2ffb 100644 --- a/packages/workspace/src/context/base-context.ts +++ b/packages/workspace/src/context/base-context.ts @@ -16,6 +16,7 @@ import { ILowCodePluginManager, } from '@alilc/lowcode-designer'; import { + ISkeleton, Skeleton as InnerSkeleton, } from '@alilc/lowcode-editor-skeleton'; import { @@ -65,7 +66,7 @@ export interface IBasicContext extends Omit Promise; innerSetters: InnerSetters; - innerSkeleton: InnerSkeleton; + innerSkeleton: ISkeleton; innerHotkey: IHotKey; innerPlugins: ILowCodePluginManager; canvas: IPublicApiCanvas; diff --git a/packages/workspace/src/inner-plugins/webview.tsx b/packages/workspace/src/inner-plugins/webview.tsx index de40bb521..820b843ab 100644 --- a/packages/workspace/src/inner-plugins/webview.tsx +++ b/packages/workspace/src/inner-plugins/webview.tsx @@ -2,7 +2,7 @@ import { IPublicModelPluginContext } from '@alilc/lowcode-types'; export function DesignerView(props: { url: string; - viewName: string; + viewName?: string; }) { return (
diff --git a/packages/workspace/src/resource.ts b/packages/workspace/src/resource.ts index 27b1fdcd1..10cb7f0a1 100644 --- a/packages/workspace/src/resource.ts +++ b/packages/workspace/src/resource.ts @@ -1,3 +1,4 @@ +import { ISkeleton } from '@alilc/lowcode-editor-skeleton'; import { IPublicTypeEditorView, IPublicResourceData, IPublicResourceTypeConfig, IBaseModelResource } from '@alilc/lowcode-types'; import { Logger } from '@alilc/lowcode-utils'; import { BasicContext, IBasicContext } from './context/base-context'; @@ -9,6 +10,8 @@ const logger = new Logger({ level: 'warn', bizName: 'workspace:resource' }); export interface IBaseResource extends IBaseModelResource { readonly resourceType: ResourceType; + skeleton: ISkeleton; + get editorViews(): IPublicTypeEditorView[]; get defaultViewType(): string; @@ -68,7 +71,7 @@ export class Resource implements IResource { } get children(): IResource[] { - return this.resourceData?.children?.map(d => new Resource(d, this.resourceType, this.workspace)) || []; + return this.resourceData?.children?.map(d => new Resource(d, this.workspace.getResourceType(d.resourceName || this.resourceType.name), this.workspace)) || []; } constructor(readonly resourceData: IPublicResourceData, readonly resourceType: IResourceType, readonly workspace: IWorkspace) { diff --git a/packages/workspace/src/view/resource-view.tsx b/packages/workspace/src/view/resource-view.tsx index 37e960b99..9ef30af09 100644 --- a/packages/workspace/src/view/resource-view.tsx +++ b/packages/workspace/src/view/resource-view.tsx @@ -2,14 +2,14 @@ import { PureComponent } from 'react'; import { EditorView } from './editor-view'; import { observer } from '@alilc/lowcode-editor-core'; import TopArea from '../layouts/top-area'; -import { Resource } from '../resource'; -import { EditorWindow } from '../window'; +import { IResource } from '../resource'; +import { IEditorWindow } from '../window'; import './resource-view.less'; @observer export class ResourceView extends PureComponent<{ - window: EditorWindow; - resource: Resource; + window: IEditorWindow; + resource: IResource; }, any> { render() { const { skeleton } = this.props.resource; diff --git a/packages/workspace/src/window.ts b/packages/workspace/src/window.ts index 1fa426524..96707dcb8 100644 --- a/packages/workspace/src/window.ts +++ b/packages/workspace/src/window.ts @@ -15,6 +15,8 @@ interface IWindowCOnfig { export interface IEditorWindow extends Omit, 'changeViewType'> { readonly resource: IResource; + editorViews: Map; + changeViewType: (name: string, ignoreEmit?: boolean) => void; } diff --git a/packages/workspace/src/workspace.ts b/packages/workspace/src/workspace.ts index 526e1f2ca..24c81cc79 100644 --- a/packages/workspace/src/workspace.ts +++ b/packages/workspace/src/workspace.ts @@ -27,6 +27,8 @@ export interface IWorkspace extends Omit Date: Tue, 21 Mar 2023 19:14:44 +0800 Subject: [PATCH 2/2] fix: fixed an issue where the outline tree was not displayed correctly when deleting a node --- .../designer/src/document/document-model.ts | 8 +++--- packages/designer/src/document/node/node.ts | 9 ++++-- .../src/controllers/tree.ts | 21 +++----------- .../src/views/tree-branches.tsx | 10 ++++--- .../src/views/tree-node.tsx | 28 +++++++++++++++---- packages/shell/src/model/document-model.ts | 2 +- 6 files changed, 44 insertions(+), 34 deletions(-) diff --git a/packages/designer/src/document/document-model.ts b/packages/designer/src/document/document-model.ts index 2731aa5e6..63b1a45dd 100644 --- a/packages/designer/src/document/document-model.ts +++ b/packages/designer/src/document/document-model.ts @@ -342,18 +342,18 @@ export class DocumentModel implements IDocumentModel { } onChangeNodeVisible(fn: (node: INode, visible: boolean) => void): IPublicTypeDisposable { - this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_CHILDREN_CHANGE, fn); + this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_VISIBLE_CHANGE, fn); return () => { - this.designer.editor?.eventBus.off(EDITOR_EVENT.NODE_CHILDREN_CHANGE, fn); + this.designer.editor?.eventBus.off(EDITOR_EVENT.NODE_VISIBLE_CHANGE, fn); }; } onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): IPublicTypeDisposable { - this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_VISIBLE_CHANGE, fn); + this.designer.editor?.eventBus.on(EDITOR_EVENT.NODE_CHILDREN_CHANGE, fn); return () => { - this.designer.editor?.eventBus.off(EDITOR_EVENT.NODE_VISIBLE_CHANGE, fn); + this.designer.editor?.eventBus.off(EDITOR_EVENT.NODE_CHILDREN_CHANGE, fn); }; } diff --git a/packages/designer/src/document/node/node.ts b/packages/designer/src/document/node/node.ts index d8b371ddf..df4e30c6f 100644 --- a/packages/designer/src/document/node/node.ts +++ b/packages/designer/src/document/node/node.ts @@ -98,11 +98,11 @@ export interface IBaseNode(stage: IPublicEnumTransformStage, options?: any): T; + export(stage: IPublicEnumTransformStage, options?: any): T; emitPropChange(val: IPublicTypePropChangeOptions): void; - import(data: IPublicTypeNodeSchema, checkId?: boolean): void; + import(data: Schema, checkId?: boolean): void; internalSetSlotFor(slotFor: Prop | null | undefined): void; @@ -394,7 +394,10 @@ export class Node editor?.eventBus.emit(EDITOR_EVENT.NODE_VISIBLE_CHANGE, this, visible); }); this.onChildrenChange((info?: { type: string; node: INode }) => { - editor?.eventBus.emit(EDITOR_EVENT.NODE_VISIBLE_CHANGE, info); + editor?.eventBus.emit(EDITOR_EVENT.NODE_CHILDREN_CHANGE, { + type: info?.type, + node: this, + }); }); } diff --git a/packages/plugin-outline-pane/src/controllers/tree.ts b/packages/plugin-outline-pane/src/controllers/tree.ts index 2256d45d9..be44db2f6 100644 --- a/packages/plugin-outline-pane/src/controllers/tree.ts +++ b/packages/plugin-outline-pane/src/controllers/tree.ts @@ -20,23 +20,10 @@ export class Tree { const doc = this.pluginContext.project.currentDocument; this.id = doc?.id; - doc?.onMountNode((payload: {node: IPublicModelNode }) => { - const { node } = payload; - const parentNode = node.parent; - if (!parentNode) { - return; - } - const parentTreeNode = this.getTreeNodeById(parentNode.id); - parentTreeNode?.notifyExpandableChanged(); - }); - - doc?.onRemoveNode((node: IPublicModelNode) => { - const parentNode = node.parent; - if (!parentNode) { - return; - } - const parentTreeNode = this.getTreeNodeById(parentNode.id); - parentTreeNode?.notifyExpandableChanged(); + doc?.onChangeNodeChildren((info: {node: IPublicModelNode }) => { + const { node } = info; + const treeNode = this.getTreeNodeById(node.id); + treeNode?.notifyExpandableChanged(); }); } diff --git a/packages/plugin-outline-pane/src/views/tree-branches.tsx b/packages/plugin-outline-pane/src/views/tree-branches.tsx index abbc5a840..210fe0af8 100644 --- a/packages/plugin-outline-pane/src/views/tree-branches.tsx +++ b/packages/plugin-outline-pane/src/views/tree-branches.tsx @@ -9,6 +9,7 @@ export default class TreeBranches extends PureComponent<{ isModal?: boolean; pluginContext: IPublicModelPluginContext; expanded: boolean; + treeChildren: TreeNode[] | null; }> { state = { filterWorking: false, @@ -56,13 +57,13 @@ export default class TreeBranches extends PureComponent<{ treeNode={treeNode} isModal={isModal || false} pluginContext={this.props.pluginContext} + treeChildren={this.props.treeChildren} />
); } } - interface ITreeNodeChildrenState { filterWorking: boolean; matchSelf: boolean; @@ -73,6 +74,7 @@ class TreeNodeChildren extends PureComponent<{ treeNode: TreeNode; isModal?: boolean; pluginContext: IPublicModelPluginContext; + treeChildren: TreeNode[] | null; }, ITreeNodeChildrenState> { state: ITreeNodeChildrenState = { filterWorking: false, @@ -115,7 +117,7 @@ class TreeNodeChildren extends PureComponent<{ } render() { - const { treeNode, isModal } = this.props; + const { isModal } = this.props; const children: any = []; let groupContents: any[] = []; let currentGrp: IPublicModelExclusiveGroup; @@ -150,7 +152,7 @@ class TreeNodeChildren extends PureComponent<{ })} /> ); - treeNode.children?.forEach((child, index) => { + this.props.treeChildren?.forEach((child, index) => { const childIsModal = child.node.componentMeta?.isModal || false; if (isModal != childIsModal) { return; @@ -178,7 +180,7 @@ class TreeNodeChildren extends PureComponent<{ } }); endGroup(); - const length = treeNode.children?.length || 0; + const length = this.props.treeChildren?.length || 0; if (dropIndex != null && dropIndex >= length) { children.push(insertion); } diff --git a/packages/plugin-outline-pane/src/views/tree-node.tsx b/packages/plugin-outline-pane/src/views/tree-node.tsx index 1531eaf63..712dc20fa 100644 --- a/packages/plugin-outline-pane/src/views/tree-node.tsx +++ b/packages/plugin-outline-pane/src/views/tree-node.tsx @@ -4,7 +4,7 @@ import TreeNode from '../controllers/tree-node'; import TreeTitle from './tree-title'; import TreeBranches from './tree-branches'; import { IconEyeClose } from '../icons/eye-close'; -import { IPublicModelPluginContext, IPublicModelModalNodesManager, IPublicModelDocumentModel, IPublicTypeDisposable } from '@alilc/lowcode-types'; +import { IPublicModelPluginContext, IPublicModelModalNodesManager, IPublicTypeDisposable } from '@alilc/lowcode-types'; class ModalTreeNodeView extends PureComponent<{ treeNode: TreeNode; @@ -49,6 +49,7 @@ class ModalTreeNodeView extends PureComponent<{
{ - state = { + state: { + expanded: boolean; + selected: boolean; + hidden: boolean; + locked: boolean; + detecting: boolean; + isRoot: boolean; + highlight: boolean; + dropping: boolean; + conditionFlow: boolean; + expandable: boolean; + treeChildren: TreeNode[] | null; + } = { expanded: false, selected: false, hidden: false, @@ -76,6 +89,7 @@ export default class TreeNodeView extends PureComponent<{ dropping: false, conditionFlow: false, expandable: false, + treeChildren: [], }; eventOffCallbacks: Array = []; @@ -95,6 +109,7 @@ export default class TreeNodeView extends PureComponent<{ conditionFlow: treeNode.node.conditionGroup != null, highlight: treeNode.isFocusingNode(), expandable: treeNode.expandable, + treeChildren: treeNode.children, }; } @@ -114,11 +129,13 @@ export default class TreeNodeView extends PureComponent<{ this.setState({ locked }); }); treeNode.onExpandableChanged((expandable: boolean) => { - this.setState({ expandable }); + this.setState({ + expandable, + treeChildren: treeNode.children, + }); }); - this.eventOffCallbacks.push( - doc?.onDropLocationChanged((document: IPublicModelDocumentModel) => { + doc?.onDropLocationChanged(() => { this.setState({ dropping: treeNode.dropDetail?.index != null, }); @@ -210,6 +227,7 @@ export default class TreeNodeView extends PureComponent<{ isModal={false} expanded={this.state.expanded} pluginContext={this.props.pluginContext} + treeChildren={this.state.treeChildren} />
); diff --git a/packages/shell/src/model/document-model.ts b/packages/shell/src/model/document-model.ts index b1015b8de..b8698ebf7 100644 --- a/packages/shell/src/model/document-model.ts +++ b/packages/shell/src/model/document-model.ts @@ -300,7 +300,7 @@ export class DocumentModel implements IPublicModelDocumentModel { * @param fn */ onChangeNodeChildren(fn: (info: IPublicTypeOnChangeOptions) => void): IPublicTypeDisposable { - return this[documentSymbol].onChangeNodeChildren((info?: IPublicTypeOnChangeOptions) => { + return this[documentSymbol].onChangeNodeChildren((info?: IPublicTypeOnChangeOptions) => { if (!info) { return; }