Skip to content

Commit 0f3da03

Browse files
committed
Add FileTreeSelector
1 parent f23e0f2 commit 0f3da03

File tree

3 files changed

+241
-119
lines changed

3 files changed

+241
-119
lines changed

panel/models/jstree.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ export class NodeEvent extends ModelEvent {
2828
}
2929
}
3030

31+
function sync_state(node: any, tree: any) {
32+
const node_json = tree.get_node(node.id)
33+
if (node_json) {
34+
node.state = node_json.state
35+
}
36+
for (const child of (node.children || [])) {
37+
sync_state(child, tree)
38+
}
39+
}
40+
3141
export class jsTreeView extends LayoutDOMView {
3242
declare model: jsTree
3343
protected _container: HTMLDivElement
@@ -37,13 +47,19 @@ export class jsTreeView extends LayoutDOMView {
3747
override connect_signals(): void {
3848
super.connect_signals()
3949
const {nodes, value, checkbox, show_icons, show_dots, multiple} = this.model.properties
40-
this.on_change(nodes, () => this._jstree.jstree(true).load_node("#", () => {
41-
this._jstree.jstree(true).refresh({
42-
skip_loading: false,
43-
forget_state: true,
50+
this.on_change(nodes, () => {
51+
const tree = this._jstree.jstree(true)
52+
for (const node of this.model.nodes) {
53+
sync_state(node, tree)
54+
}
55+
tree.load_node("#", () => {
56+
tree.refresh({
57+
skip_loading: false,
58+
forget_state: false,
59+
})
60+
this._update_selection_from_value()
4461
})
45-
this._update_selection_from_value()
46-
}))
62+
})
4763
this.on_change(value, () => this._update_selection_from_value())
4864
this.on_change(checkbox, () => this.setCheckboxes())
4965
this.on_change(show_icons, () => this._setShowIcons())

0 commit comments

Comments
 (0)