@@ -41,43 +41,22 @@ export default class TreeNode { |
41 | 41 | readonly pluginContext: IPublicModelPluginContext; |
42 | 42 | event = new EventEmitter(); |
43 | 43 |
|
44 | | - onFilterResultChanged(fn: () => void): IPublicTypeDisposable { |
45 | | - this.event.on(EVENT_NAMES.filterResultChanged, fn); |
46 | | - return () => { |
47 | | - this.event.off(EVENT_NAMES.filterResultChanged, fn); |
48 | | - } |
49 | | - }; |
50 | | - onExpandedChanged(fn: (expanded: boolean) => void): IPublicTypeDisposable { |
51 | | - this.event.on(EVENT_NAMES.expandedChanged, fn); |
52 | | - return () => { |
53 | | - this.event.off(EVENT_NAMES.expandedChanged, fn); |
54 | | - } |
55 | | - }; |
56 | | - onHiddenChanged(fn: (hidden: boolean) => void): IPublicTypeDisposable { |
57 | | - this.event.on(EVENT_NAMES.hiddenChanged, fn); |
58 | | - return () => { |
59 | | - this.event.off(EVENT_NAMES.hiddenChanged, fn); |
60 | | - } |
61 | | - }; |
62 | | - onLockedChanged(fn: (locked: boolean) => void): IPublicTypeDisposable { |
63 | | - this.event.on(EVENT_NAMES.lockedChanged, fn); |
64 | | - return () => { |
65 | | - this.event.off(EVENT_NAMES.lockedChanged, fn); |
66 | | - } |
67 | | - }; |
68 | | - onTitleLabelChanged(fn: (treeNode: TreeNode) => void): IPublicTypeDisposable { |
69 | | - this.event.on(EVENT_NAMES.titleLabelChanged, fn); |
| 44 | + private _node: IPublicModelNode; |
70 | 45 |
|
71 | | - return () => { |
72 | | - this.event.off(EVENT_NAMES.titleLabelChanged, fn); |
73 | | - } |
| 46 | + readonly tree: Tree; |
| 47 | + |
| 48 | + private _filterResult: FilterResult = { |
| 49 | + filterWorking: false, |
| 50 | + matchChild: false, |
| 51 | + matchSelf: false, |
| 52 | + keywords: '', |
74 | 53 | }; |
75 | | - onExpandableChanged(fn: (expandable: boolean) => void): IPublicTypeDisposable { |
76 | | - this.event.on(EVENT_NAMES.expandableChanged, fn); |
77 | | - return () => { |
78 | | - this.event.off(EVENT_NAMES.expandableChanged, fn); |
79 | | - } |
80 | | - } |
| 54 | + |
| 55 | + /** |
| 56 | + * 默认为折叠状态 |
| 57 | + * 在初始化根节点时,设置为展开状态 |
| 58 | + */ |
| 59 | + private _expanded = false; |
81 | 60 |
|
82 | 61 | get id(): string { |
83 | 62 | return this.node.id; |
@@ -91,11 +70,8 @@ export default class TreeNode { |
91 | 70 | return this.hasChildren() || this.hasSlots() || this.dropDetail?.index != null; |
92 | 71 | } |
93 | 72 |
|
94 | | - /** |
95 | | - * 触发 onExpandableChanged 回调 |
96 | | - */ |
97 | | - notifyExpandableChanged(): void { |
98 | | - this.event.emit(EVENT_NAMES.expandableChanged, this.expandable); |
| 73 | + get expanded(): boolean { |
| 74 | + return this.isRoot(true) || (this.expandable && this._expanded); |
99 | 75 | } |
100 | 76 |
|
101 | 77 | /** |
@@ -110,47 +86,6 @@ export default class TreeNode { |
110 | 86 | return this.node.zLevel; |
111 | 87 | } |
112 | 88 |
|
113 | | - isRoot(includeOriginalRoot = false) { |
114 | | - const rootNode = this.pluginContext.project.getCurrentDocument()?.root; |
115 | | - return this.tree.root === this || (includeOriginalRoot && rootNode === this.node); |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * 是否是响应投放区 |
120 | | - */ |
121 | | - isResponseDropping(): boolean { |
122 | | - const loc = this.pluginContext.project.getCurrentDocument()?.dropLocation; |
123 | | - if (!loc) { |
124 | | - return false; |
125 | | - } |
126 | | - return loc.target?.id === this.id; |
127 | | - } |
128 | | - |
129 | | - isFocusingNode(): boolean { |
130 | | - const loc = this.pluginContext.project.getCurrentDocument()?.dropLocation; |
131 | | - if (!loc) { |
132 | | - return false; |
133 | | - } |
134 | | - return ( |
135 | | - isLocationChildrenDetail(loc.detail) && loc.detail.focus?.type === 'node' && loc.detail?.focus?.node.id === this.id |
136 | | - ); |
137 | | - } |
138 | | - |
139 | | - /** |
140 | | - * 默认为折叠状态 |
141 | | - * 在初始化根节点时,设置为展开状态 |
142 | | - */ |
143 | | - private _expanded = false; |
144 | | - |
145 | | - get expanded(): boolean { |
146 | | - return this.isRoot(true) || (this.expandable && this._expanded); |
147 | | - } |
148 | | - |
149 | | - setExpanded(value: boolean) { |
150 | | - this._expanded = value; |
151 | | - this.event.emit(EVENT_NAMES.expandedChanged, value); |
152 | | - } |
153 | | - |
154 | 89 | get detecting() { |
155 | 90 | const doc = this.pluginContext.project.currentDocument; |
156 | 91 | return !!(doc?.isDetectingNode(this.node)); |
@@ -164,23 +99,10 @@ export default class TreeNode { |
164 | 99 | return !cv; |
165 | 100 | } |
166 | 101 |
|
167 | | - setHidden(flag: boolean) { |
168 | | - if (this.node.conditionGroup) { |
169 | | - return; |
170 | | - } |
171 | | - this.node.visible = !flag; |
172 | | - this.event.emit(EVENT_NAMES.hiddenChanged, flag); |
173 | | - } |
174 | | - |
175 | 102 | get locked(): boolean { |
176 | 103 | return this.node.isLocked; |
177 | 104 | } |
178 | 105 |
|
179 | | - setLocked(flag: boolean) { |
180 | | - this.node.lock(flag); |
181 | | - this.event.emit(EVENT_NAMES.lockedChanged, flag); |
182 | | - } |
183 | | - |
184 | 106 | get selected(): boolean { |
185 | 107 | // TODO: check is dragging |
186 | 108 | const selection = this.pluginContext.project.getCurrentDocument()?.selection; |
@@ -213,19 +135,6 @@ export default class TreeNode { |
213 | 135 | return this.node.componentName; |
214 | 136 | } |
215 | 137 |
|
216 | | - setTitleLabel(label: string) { |
217 | | - const origLabel = this.titleLabel; |
218 | | - if (label === origLabel) { |
219 | | - return; |
220 | | - } |
221 | | - if (label === '') { |
222 | | - this.node.getExtraProp('title', false)?.remove(); |
223 | | - } else { |
224 | | - this.node.getExtraProp('title', true)?.setValue(label); |
225 | | - } |
226 | | - this.event.emit(EVENT_NAMES.titleLabelChanged, this); |
227 | | - } |
228 | | - |
229 | 138 | get icon() { |
230 | 139 | return this.node.componentMeta?.icon; |
231 | 140 | } |
@@ -247,6 +156,123 @@ export default class TreeNode { |
247 | 156 | return this.node.children?.map((node) => this.tree.getTreeNode(node)) || null; |
248 | 157 | } |
249 | 158 |
|
| 159 | + get node(): IPublicModelNode { |
| 160 | + return this._node; |
| 161 | + } |
| 162 | + |
| 163 | + constructor(tree: Tree, node: IPublicModelNode, pluginContext: IPublicModelPluginContext) { |
| 164 | + this.tree = tree; |
| 165 | + this.pluginContext = pluginContext; |
| 166 | + this._node = node; |
| 167 | + } |
| 168 | + |
| 169 | + setLocked(flag: boolean) { |
| 170 | + this.node.lock(flag); |
| 171 | + this.event.emit(EVENT_NAMES.lockedChanged, flag); |
| 172 | + } |
| 173 | + |
| 174 | + onFilterResultChanged(fn: () => void): IPublicTypeDisposable { |
| 175 | + this.event.on(EVENT_NAMES.filterResultChanged, fn); |
| 176 | + return () => { |
| 177 | + this.event.off(EVENT_NAMES.filterResultChanged, fn); |
| 178 | + }; |
| 179 | + } |
| 180 | + onExpandedChanged(fn: (expanded: boolean) => void): IPublicTypeDisposable { |
| 181 | + this.event.on(EVENT_NAMES.expandedChanged, fn); |
| 182 | + return () => { |
| 183 | + this.event.off(EVENT_NAMES.expandedChanged, fn); |
| 184 | + }; |
| 185 | + } |
| 186 | + onHiddenChanged(fn: (hidden: boolean) => void): IPublicTypeDisposable { |
| 187 | + this.event.on(EVENT_NAMES.hiddenChanged, fn); |
| 188 | + return () => { |
| 189 | + this.event.off(EVENT_NAMES.hiddenChanged, fn); |
| 190 | + }; |
| 191 | + } |
| 192 | + onLockedChanged(fn: (locked: boolean) => void): IPublicTypeDisposable { |
| 193 | + this.event.on(EVENT_NAMES.lockedChanged, fn); |
| 194 | + return () => { |
| 195 | + this.event.off(EVENT_NAMES.lockedChanged, fn); |
| 196 | + }; |
| 197 | + } |
| 198 | + |
| 199 | + onTitleLabelChanged(fn: (treeNode: TreeNode) => void): IPublicTypeDisposable { |
| 200 | + this.event.on(EVENT_NAMES.titleLabelChanged, fn); |
| 201 | + |
| 202 | + return () => { |
| 203 | + this.event.off(EVENT_NAMES.titleLabelChanged, fn); |
| 204 | + }; |
| 205 | + } |
| 206 | + onExpandableChanged(fn: (expandable: boolean) => void): IPublicTypeDisposable { |
| 207 | + this.event.on(EVENT_NAMES.expandableChanged, fn); |
| 208 | + return () => { |
| 209 | + this.event.off(EVENT_NAMES.expandableChanged, fn); |
| 210 | + }; |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * 触发 onExpandableChanged 回调 |
| 215 | + */ |
| 216 | + notifyExpandableChanged(): void { |
| 217 | + this.event.emit(EVENT_NAMES.expandableChanged, this.expandable); |
| 218 | + } |
| 219 | + |
| 220 | + notifyTitleLabelChanged(): void { |
| 221 | + this.event.emit(EVENT_NAMES.titleLabelChanged, this.title); |
| 222 | + } |
| 223 | + |
| 224 | + setHidden(flag: boolean) { |
| 225 | + if (this.node.conditionGroup) { |
| 226 | + return; |
| 227 | + } |
| 228 | + this.node.visible = !flag; |
| 229 | + this.event.emit(EVENT_NAMES.hiddenChanged, flag); |
| 230 | + } |
| 231 | + |
| 232 | + isFocusingNode(): boolean { |
| 233 | + const loc = this.pluginContext.project.getCurrentDocument()?.dropLocation; |
| 234 | + if (!loc) { |
| 235 | + return false; |
| 236 | + } |
| 237 | + return ( |
| 238 | + isLocationChildrenDetail(loc.detail) && loc.detail.focus?.type === 'node' && loc.detail?.focus?.node.id === this.id |
| 239 | + ); |
| 240 | + } |
| 241 | + |
| 242 | + setExpanded(value: boolean) { |
| 243 | + this._expanded = value; |
| 244 | + this.event.emit(EVENT_NAMES.expandedChanged, value); |
| 245 | + } |
| 246 | + |
| 247 | + isRoot(includeOriginalRoot = false) { |
| 248 | + const rootNode = this.pluginContext.project.getCurrentDocument()?.root; |
| 249 | + return this.tree.root === this || (includeOriginalRoot && rootNode === this.node); |
| 250 | + } |
| 251 | + |
| 252 | + /** |
| 253 | + * 是否是响应投放区 |
| 254 | + */ |
| 255 | + isResponseDropping(): boolean { |
| 256 | + const loc = this.pluginContext.project.getCurrentDocument()?.dropLocation; |
| 257 | + if (!loc) { |
| 258 | + return false; |
| 259 | + } |
| 260 | + return loc.target?.id === this.id; |
| 261 | + } |
| 262 | + |
| 263 | + setTitleLabel(label: string) { |
| 264 | + const origLabel = this.titleLabel; |
| 265 | + if (label === origLabel) { |
| 266 | + return; |
| 267 | + } |
| 268 | + if (label === '') { |
| 269 | + this.node.getExtraProp('title', false)?.remove(); |
| 270 | + } else { |
| 271 | + this.node.getExtraProp('title', true)?.setValue(label); |
| 272 | + } |
| 273 | + this.event.emit(EVENT_NAMES.titleLabelChanged, this); |
| 274 | + } |
| 275 | + |
250 | 276 | /** |
251 | 277 | * 是否是容器,允许子节点拖入 |
252 | 278 | */ |
@@ -298,39 +324,18 @@ export default class TreeNode { |
298 | 324 | } |
299 | 325 | } |
300 | 326 |
|
301 | | - private _node: IPublicModelNode; |
302 | | - |
303 | | - get node(): IPublicModelNode { |
304 | | - return this._node; |
305 | | - } |
306 | | - |
307 | | - readonly tree: Tree; |
308 | | - |
309 | | - constructor(tree: Tree, node: IPublicModelNode, pluginContext: IPublicModelPluginContext) { |
310 | | - this.tree = tree; |
311 | | - this.pluginContext = pluginContext; |
312 | | - this._node = node; |
313 | | - } |
314 | | - |
315 | 327 | setNode(node: IPublicModelNode) { |
316 | 328 | if (this._node !== node) { |
317 | 329 | this._node = node; |
318 | 330 | } |
319 | 331 | } |
320 | 332 |
|
321 | | - private _filterResult: FilterResult = { |
322 | | - filterWorking: false, |
323 | | - matchChild: false, |
324 | | - matchSelf: false, |
325 | | - keywords: '', |
326 | | - }; |
327 | | - |
328 | 333 | get filterReult(): FilterResult { |
329 | 334 | return this._filterResult; |
330 | 335 | } |
331 | 336 |
|
332 | 337 | setFilterReult(val: FilterResult) { |
333 | 338 | this._filterResult = val; |
334 | | - this.event.emit(EVENT_NAMES.filterResultChanged) |
| 339 | + this.event.emit(EVENT_NAMES.filterResultChanged); |
335 | 340 | } |
336 | 341 | } |