Skip to content

Commit 67c4ccf

Browse files
committed
fix: update outline tree when node loop property changes
1 parent 09707ce commit 67c4ccf

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

packages/plugin-outline-pane/src/controllers/tree-node.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ enum EVENT_NAMES {
3737
expandableChanged = 'expandableChanged',
3838

3939
conditionChanged = 'conditionChanged',
40+
41+
loopChanged = 'loopChanged',
4042
}
4143

4244
export default class TreeNode {
@@ -160,6 +162,10 @@ export default class TreeNode {
160162
return this.node.hasCondition() && !this.node.conditionGroup;
161163
}
162164

165+
get loop(): boolean {
166+
return this.node.hasLoop();
167+
}
168+
163169
get children(): TreeNode[] | null {
164170
return this.node.children?.map((node) => this.tree.getTreeNode(node)) || null;
165171
}
@@ -222,6 +228,14 @@ export default class TreeNode {
222228
};
223229
}
224230

231+
onLoopChanged(fn: (treeNode: TreeNode) => void): IPublicTypeDisposable {
232+
this.event.on(EVENT_NAMES.loopChanged, fn);
233+
234+
return () => {
235+
this.event.off(EVENT_NAMES.loopChanged, fn);
236+
};
237+
}
238+
225239
onExpandableChanged(fn: (expandable: boolean) => void): IPublicTypeDisposable {
226240
this.event.on(EVENT_NAMES.expandableChanged, fn);
227241
return () => {
@@ -244,6 +258,10 @@ export default class TreeNode {
244258
this.event.emit(EVENT_NAMES.conditionChanged, this.condition);
245259
}
246260

261+
notifyLoopChanged(): void {
262+
this.event.emit(EVENT_NAMES.loopChanged, this.loop);
263+
}
264+
247265
setHidden(flag: boolean) {
248266
if (this.node.conditionGroup) {
249267
return;

packages/plugin-outline-pane/src/controllers/tree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export class Tree {
3636

3737
doc?.onChangeNodeProp((info: IPublicTypePropChangeOptions) => {
3838
const { node, key } = info;
39+
const treeNode = this.getTreeNodeById(node.id);
3940
if (key === '___title___') {
40-
const treeNode = this.getTreeNodeById(node.id);
4141
treeNode?.notifyTitleLabelChanged();
4242
} else if (key === '___condition___') {
43-
const treeNode = this.getTreeNodeById(node.id);
4443
treeNode?.notifyConditionChanged();
44+
} else if (key === '___loop___') {
45+
treeNode?.notifyLoopChanged();
4546
}
4647
});
4748

packages/plugin-outline-pane/src/views/tree-title.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default class TreeTitle extends PureComponent<{
2828
editing: boolean;
2929
title: string;
3030
condition?: boolean;
31+
loop?: boolean;
3132
visible?: boolean;
3233
filterWorking: boolean;
3334
keywords: string;
@@ -89,6 +90,7 @@ export default class TreeTitle extends PureComponent<{
8990
editing: false,
9091
title: treeNode.titleLabel,
9192
condition: treeNode.condition,
93+
loop: treeNode.loop,
9294
visible: !treeNode.hidden,
9395
});
9496
treeNode.onTitleLabelChanged(() => {
@@ -101,6 +103,11 @@ export default class TreeTitle extends PureComponent<{
101103
condition: treeNode.condition,
102104
});
103105
});
106+
treeNode.onLoopChanged(() => {
107+
this.setState({
108+
loop: treeNode.loop,
109+
});
110+
});
104111
treeNode.onHiddenChanged((hidden: boolean) => {
105112
this.setState({
106113
visible: !hidden,
@@ -207,7 +214,7 @@ export default class TreeTitle extends PureComponent<{
207214
<Tip>{intlNode('Slot for {prop}', { prop: node.slotFor.key })}</Tip>
208215
</a>
209216
)}
210-
{node.hasLoop() && (
217+
{this.state.loop && (
211218
<a className="tree-node-tag loop">
212219
{/* todo: click todo something */}
213220
<IconLoop />

packages/renderer-core/tests/renderer/__snapshots__/renderer.test.tsx.snap

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ exports[`Base Render renderComp 1`] = `
259259
"hidden": undefined,
260260
}
261261
}
262+
aria-expanded="false"
263+
aria-label="select"
262264
autoComplete="off"
263265
disabled={false}
264266
height="100%"
265-
maxLength={null}
266267
onBlur={[Function]}
267268
onChange={[Function]}
268269
onCompositionEnd={[Function]}
@@ -378,10 +379,11 @@ exports[`Base Render renderComp 1`] = `
378379
"hidden": undefined,
379380
}
380381
}
382+
aria-expanded="false"
383+
aria-label="select"
381384
autoComplete="off"
382385
disabled={false}
383386
height="100%"
384-
maxLength={null}
385387
onBlur={[Function]}
386388
onChange={[Function]}
387389
onCompositionEnd={[Function]}
@@ -485,7 +487,6 @@ exports[`Base Render renderComp 1`] = `
485487
autoComplete="off"
486488
disabled={false}
487489
height="100%"
488-
maxLength={null}
489490
onBlur={[Function]}
490491
onChange={[Function]}
491492
onCompositionEnd={[Function]}
@@ -988,7 +989,6 @@ exports[`Base Render renderComp 1`] = `
988989
autoComplete="off"
989990
disabled={false}
990991
height="100%"
991-
maxLength={null}
992992
onBlur={[Function]}
993993
onChange={[Function]}
994994
onCompositionEnd={[Function]}
@@ -1048,10 +1048,11 @@ exports[`Base Render renderComp 1`] = `
10481048
"hidden": undefined,
10491049
}
10501050
}
1051+
aria-expanded="false"
1052+
aria-label="select"
10511053
autoComplete="off"
10521054
disabled={false}
10531055
height="100%"
1054-
maxLength={null}
10551056
name="error"
10561057
onBlur={[Function]}
10571058
onChange={[Function]}

0 commit comments

Comments
 (0)