Skip to content

Commit

Permalink
Add FileTreeSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 11, 2024
1 parent f23e0f2 commit 0f3da03
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 119 deletions.
28 changes: 22 additions & 6 deletions panel/models/jstree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export class NodeEvent extends ModelEvent {
}
}

function sync_state(node: any, tree: any) {
const node_json = tree.get_node(node.id)
if (node_json) {
node.state = node_json.state
}
for (const child of (node.children || [])) {
sync_state(child, tree)
}
}

export class jsTreeView extends LayoutDOMView {
declare model: jsTree
protected _container: HTMLDivElement
Expand All @@ -37,13 +47,19 @@ export class jsTreeView extends LayoutDOMView {
override connect_signals(): void {
super.connect_signals()
const {nodes, value, checkbox, show_icons, show_dots, multiple} = this.model.properties
this.on_change(nodes, () => this._jstree.jstree(true).load_node("#", () => {
this._jstree.jstree(true).refresh({
skip_loading: false,
forget_state: true,
this.on_change(nodes, () => {
const tree = this._jstree.jstree(true)
for (const node of this.model.nodes) {
sync_state(node, tree)
}
tree.load_node("#", () => {
tree.refresh({
skip_loading: false,
forget_state: false,
})
this._update_selection_from_value()
})
this._update_selection_from_value()
}))
})
this.on_change(value, () => this._update_selection_from_value())
this.on_change(checkbox, () => this.setCheckboxes())
this.on_change(show_icons, () => this._setShowIcons())
Expand Down
Loading

0 comments on commit 0f3da03

Please sign in to comment.