* 获取顶层选区节点,场景:拖拽时,建立蒙层,只蒙在最上层
(includeRoot = false)
| 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); |
nothing calls this directly
no test coverage detected