MCPcopy Create free account
hub / github.com/alibaba/lowcode-engine / getTopNodes

Method getTopNodes

packages/designer/src/document/selection.ts:155–182  ·  view source on GitHub ↗

* 获取顶层选区节点,场景:拖拽时,建立蒙层,只蒙在最上层

(includeRoot = false)

Source from the content-addressed store, hash-verified

153 * 获取顶层选区节点,场景:拖拽时,建立蒙层,只蒙在最上层
154 */
155 getTopNodes(includeRoot = false) {
156 const nodes = [];
157 for (const id of this._selected) {
158 const node = this.doc.getNode(id);
159 // 排除根节点
160 if (!node || (!includeRoot && node.contains(this.doc.focusNode))) {
161 continue;
162 }
163 let i = nodes.length;
164 let isTop = true;
165 while (i-- > 0) {
166 const n = comparePosition(nodes[i], node);
167 // nodes[i] contains node
168 if (n === PositionNO.Contains || n === PositionNO.TheSame) {
169 isTop = false;
170 break;
171 } else if (n === PositionNO.ContainedBy) {
172 // node contains nodes[i], delete nodes[i]
173 nodes.splice(i, 1);
174 }
175 }
176 // node is top item, push to nodes
177 if (isTop) {
178 nodes.push(node);
179 }
180 }
181 return nodes;
182 }
183
184 onSelectionChange(fn: (ids: string[]) => void): () => void {
185 this.emitter.on('selectionchange', fn);

Callers

nothing calls this directly

Calls 5

comparePositionFunction · 0.90
pushMethod · 0.80
getNodeMethod · 0.65
containsMethod · 0.65
spliceMethod · 0.65

Tested by

no test coverage detected