-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
roymondchen
committed
Dec 8, 2023
1 parent
258d2bc
commit 741140f
Showing
17 changed files
with
245 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ComputedRef, ref, watch } from 'vue'; | ||
|
||
import type { Id, MNode } from '@tmagic/schema'; | ||
|
||
import { LayerNodeStatus, TreeNodeData } from '@editor/type'; | ||
import { traverseNode } from '@editor/utils'; | ||
|
||
const createPageNodeStatus = (nodeData: TreeNodeData[], initalLayerNodeStatus?: Map<Id, LayerNodeStatus>) => { | ||
const map = new Map<Id, LayerNodeStatus>(); | ||
|
||
nodeData.forEach((node: MNode) => | ||
traverseNode(node, (node) => { | ||
map.set( | ||
node.id, | ||
initalLayerNodeStatus?.get(node.id) || { | ||
visible: true, | ||
expand: false, | ||
selected: false, | ||
draggable: false, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
return map; | ||
}; | ||
|
||
export const useNodeStatus = (nodeData: ComputedRef<TreeNodeData[]>) => { | ||
/** 所有页面的节点状态 */ | ||
const nodeStatusMap = ref(new Map<Id, LayerNodeStatus>()); | ||
|
||
// 切换页面或者新增页面,重新生成节点状态 | ||
watch( | ||
nodeData, | ||
(nodeData) => { | ||
// 生成节点状态 | ||
nodeStatusMap.value = createPageNodeStatus(nodeData, nodeStatusMap.value); | ||
}, | ||
{ | ||
immediate: true, | ||
deep: true, | ||
}, | ||
); | ||
|
||
return { | ||
nodeStatusMap, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.