fix: expandable state not changed when node added/removed

This commit is contained in:
JackLian 2022-12-26 17:03:10 +08:00 committed by 刘菊萍(絮黎)
parent aa1813d09b
commit 37dffae1b8
5 changed files with 36 additions and 6 deletions

View File

@ -5,7 +5,7 @@ sidebar_position: 3
## 模块简介 ## 模块简介
引擎编排模块中包含多种模型,包括: 引擎编排模块中包含多种模型,包括:
- [文档模型 DocumentModel](./model/document-model) - [文档模型 DocumentModel](./model/document-model)
- [节点模型 Node](./model/node) - [节点模型 Node](./model/node)
- [节点孩子模型 NodeChildren](./model/node-children) - [节点孩子模型 NodeChildren](./model/node-children)
- [属性模型 Prop](./model/prop) - [属性模型 Prop](./model/prop)

View File

@ -28,6 +28,7 @@ export default class TreeNode {
onHiddenChanged: (hidden: boolean) => void; onHiddenChanged: (hidden: boolean) => void;
onLockedChanged: (locked: boolean) => void; onLockedChanged: (locked: boolean) => void;
onTitleLabelChanged: (treeNode: TreeNode) => void; onTitleLabelChanged: (treeNode: TreeNode) => void;
onExpandableChanged: (expandable: boolean) => void;
get id(): string { get id(): string {
return this.node.id; return this.node.id;
@ -41,6 +42,13 @@ export default class TreeNode {
return this.hasChildren() || this.hasSlots() || this.dropDetail?.index != null; return this.hasChildren() || this.hasSlots() || this.dropDetail?.index != null;
} }
/**
* onExpandableChanged
*/
notifyExpandableChanged(): void {
this.onExpandableChanged && this.onExpandableChanged(this.expandable);
}
/** /**
* "线" * "线"
*/ */
@ -96,7 +104,7 @@ export default class TreeNode {
get detecting() { get detecting() {
const doc = this.pluginContext.project.currentDocument; const doc = this.pluginContext.project.currentDocument;
return doc?.isDetectingNode(this.node); return !!(doc?.isDetectingNode(this.node));
} }
get hidden(): boolean { get hidden(): boolean {

View File

@ -17,7 +17,27 @@ export class Tree {
constructor(pluginContext: IPublicModelPluginContext) { constructor(pluginContext: IPublicModelPluginContext) {
this.pluginContext = pluginContext; this.pluginContext = pluginContext;
this.id = this.pluginContext.project.currentDocument?.id; 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();
});
} }
setNodeSelected(nodeId: string): void { setNodeSelected(nodeId: string): void {

View File

@ -32,7 +32,7 @@ class ModalTreeNodeView extends Component<{
const { project } = this.pluginContext; const { project } = this.pluginContext;
const rootNode = project.currentDocument?.root; const rootNode = project.currentDocument?.root;
const rootTreeNode = treeNode.tree.getTreeNode(rootNode!); const rootTreeNode = treeNode.tree.getTreeNode(rootNode!);
const expanded = rootTreeNode.expanded; const { expanded } = rootTreeNode;
const hasVisibleModalNode = !!this.modalNodesManager?.getVisibleModalNode(); const hasVisibleModalNode = !!this.modalNodesManager?.getVisibleModalNode();
return ( return (
@ -100,7 +100,7 @@ export default class TreeNodeView extends Component<{
componentDidMount() { componentDidMount() {
const { treeNode, pluginContext } = this.props; const { treeNode, pluginContext } = this.props;
const { event, project } = pluginContext; const { project } = pluginContext;
const doc = project.currentDocument; const doc = project.currentDocument;
@ -113,6 +113,9 @@ export default class TreeNodeView extends Component<{
treeNode.onLockedChanged = (locked: boolean) => { treeNode.onLockedChanged = (locked: boolean) => {
this.setState({ locked }); this.setState({ locked });
}; };
treeNode.onExpandableChanged = (expandable: boolean) => {
this.setState({ expandable });
};
this.eventOffCallbacks.push( this.eventOffCallbacks.push(
doc?.onDropLocationChanged((document: IPublicModelDocumentModel) => { doc?.onDropLocationChanged((document: IPublicModelDocumentModel) => {

View File

@ -4,7 +4,6 @@ const package = require('../packages/engine/package.json');
const { version, name } = package; const { version, name } = package;
const options = { const options = {
method: 'PUT', method: 'PUT',
// 暂时使用 日常环境的 uipaas-node上线后可切换成线上环境 https://uipaas-node.alibaba-inc.com
hostname: 'uipaas-node.alibaba-inc.com', hostname: 'uipaas-node.alibaba-inc.com',
path: '/staticAssets/cdn/packages', path: '/staticAssets/cdn/packages',
headers: { headers: {