jqtree 1.8.11 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bower.json +1 -1
- package/package.json +45 -51
- package/pnpm-workspace.yaml +5 -0
- package/src/animation.ts +48 -0
- package/src/dataLoader.ts +38 -48
- package/src/dragAndDropHandler/dragElement.ts +11 -11
- package/src/dragAndDropHandler/generateHitAreas.ts +4 -3
- package/src/dragAndDropHandler/index.ts +119 -120
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +1 -1
- package/src/dragAndDropHandler/types.ts +1 -1
- package/src/elementsRenderer.ts +71 -78
- package/src/jqtreeMethodTypes.ts +2 -2
- package/src/jqtreeOptions.ts +3 -2
- package/src/keyHandler.ts +34 -34
- package/src/mouseHandler.ts +118 -119
- package/src/node.ts +22 -22
- package/src/nodeElement/borderDropHint.ts +6 -6
- package/src/nodeElement/folderElement.ts +33 -25
- package/src/nodeElement/ghostDropHint.ts +24 -24
- package/src/nodeElement/index.ts +19 -18
- package/src/positionUtils.ts +18 -0
- package/src/saveStateHandler.ts +56 -55
- package/src/scrollHandler/containerScrollParent.ts +24 -22
- package/src/scrollHandler/documentScrollParent.ts +29 -28
- package/src/scrollHandler/scrollParent.ts +41 -41
- package/src/scrollHandler.ts +23 -22
- package/src/selectNodeHandler.ts +28 -28
- package/src/tree.jquery.d.ts +3 -2
- package/src/tree.jquery.ts +456 -368
- package/src/util.ts +0 -14
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +1094 -973
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
- package/eslint.config.mjs +0 -98
- package/src/simple.widget.ts +0 -134
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { AnimationSpeed } from "../animation";
|
|
2
|
+
import type { OnFinishOpenNode, TriggerEvent } from "../jqtreeMethodTypes";
|
|
3
|
+
import type { Position } from "../node";
|
|
4
|
+
import type { NodeElementParams } from "./index";
|
|
5
|
+
|
|
6
|
+
import { slideDown, slideUp } from "../animation";
|
|
7
|
+
import NodeElement from "./index";
|
|
4
8
|
|
|
5
9
|
interface FolderElementParams extends NodeElementParams {
|
|
6
10
|
closedIconElement?: HTMLElement | Text;
|
|
@@ -9,9 +13,9 @@ interface FolderElementParams extends NodeElementParams {
|
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
class FolderElement extends NodeElement {
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
16
|
+
private _closedIconElement?: HTMLElement | Text;
|
|
17
|
+
private _openedIconElement?: HTMLElement | Text;
|
|
18
|
+
private _triggerEvent: TriggerEvent;
|
|
15
19
|
|
|
16
20
|
constructor({
|
|
17
21
|
closedIconElement,
|
|
@@ -29,23 +33,23 @@ class FolderElement extends NodeElement {
|
|
|
29
33
|
treeElement,
|
|
30
34
|
});
|
|
31
35
|
|
|
32
|
-
this.
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
36
|
+
this._closedIconElement = closedIconElement;
|
|
37
|
+
this._openedIconElement = openedIconElement;
|
|
38
|
+
this._triggerEvent = triggerEvent;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
public close(slide: boolean, animationSpeed:
|
|
41
|
+
public close(slide: boolean, animationSpeed: AnimationSpeed): void {
|
|
38
42
|
if (!this.node.is_open) {
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
this.node.is_open = false;
|
|
43
47
|
|
|
44
|
-
const button = this.
|
|
48
|
+
const button = this._getButton();
|
|
45
49
|
button.classList.add("jqtree-closed");
|
|
46
50
|
button.innerHTML = "";
|
|
47
51
|
|
|
48
|
-
const closedIconElement = this.
|
|
52
|
+
const closedIconElement = this._closedIconElement;
|
|
49
53
|
|
|
50
54
|
if (closedIconElement) {
|
|
51
55
|
const icon = closedIconElement.cloneNode(true);
|
|
@@ -55,18 +59,20 @@ class FolderElement extends NodeElement {
|
|
|
55
59
|
const doClose = (): void => {
|
|
56
60
|
this.element.classList.add("jqtree-closed");
|
|
57
61
|
|
|
58
|
-
const titleSpan = this.
|
|
62
|
+
const titleSpan = this._getTitleSpan();
|
|
59
63
|
titleSpan.setAttribute("aria-expanded", "false");
|
|
60
64
|
|
|
61
|
-
this.
|
|
65
|
+
this._triggerEvent("tree.close", {
|
|
62
66
|
node: this.node,
|
|
63
67
|
});
|
|
64
68
|
};
|
|
65
69
|
|
|
70
|
+
const ul = this._getUl();
|
|
71
|
+
|
|
66
72
|
if (slide) {
|
|
67
|
-
|
|
73
|
+
slideUp(ul, animationSpeed, doClose);
|
|
68
74
|
} else {
|
|
69
|
-
|
|
75
|
+
ul.style.display = "none";
|
|
70
76
|
doClose();
|
|
71
77
|
}
|
|
72
78
|
}
|
|
@@ -74,7 +80,7 @@ class FolderElement extends NodeElement {
|
|
|
74
80
|
public open(
|
|
75
81
|
onFinished: OnFinishOpenNode | undefined,
|
|
76
82
|
slide: boolean,
|
|
77
|
-
animationSpeed:
|
|
83
|
+
animationSpeed: AnimationSpeed,
|
|
78
84
|
): void {
|
|
79
85
|
if (this.node.is_open) {
|
|
80
86
|
return;
|
|
@@ -82,11 +88,11 @@ class FolderElement extends NodeElement {
|
|
|
82
88
|
|
|
83
89
|
this.node.is_open = true;
|
|
84
90
|
|
|
85
|
-
const button = this.
|
|
91
|
+
const button = this._getButton();
|
|
86
92
|
button.classList.remove("jqtree-closed");
|
|
87
93
|
button.innerHTML = "";
|
|
88
94
|
|
|
89
|
-
const openedIconElement = this.
|
|
95
|
+
const openedIconElement = this._openedIconElement;
|
|
90
96
|
|
|
91
97
|
if (openedIconElement) {
|
|
92
98
|
const icon = openedIconElement.cloneNode(true);
|
|
@@ -96,31 +102,33 @@ class FolderElement extends NodeElement {
|
|
|
96
102
|
const doOpen = (): void => {
|
|
97
103
|
this.element.classList.remove("jqtree-closed");
|
|
98
104
|
|
|
99
|
-
const titleSpan = this.
|
|
105
|
+
const titleSpan = this._getTitleSpan();
|
|
100
106
|
titleSpan.setAttribute("aria-expanded", "true");
|
|
101
107
|
|
|
102
108
|
if (onFinished) {
|
|
103
109
|
onFinished(this.node);
|
|
104
110
|
}
|
|
105
111
|
|
|
106
|
-
this.
|
|
112
|
+
this._triggerEvent("tree.open", {
|
|
107
113
|
node: this.node,
|
|
108
114
|
});
|
|
109
115
|
};
|
|
110
116
|
|
|
117
|
+
const ul = this._getUl();
|
|
118
|
+
|
|
111
119
|
if (slide) {
|
|
112
|
-
|
|
120
|
+
slideDown(ul, animationSpeed, doOpen);
|
|
113
121
|
} else {
|
|
114
|
-
|
|
122
|
+
ul.style.display = "block";
|
|
115
123
|
doOpen();
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
|
|
119
|
-
protected
|
|
127
|
+
protected _mustShowBorderDropHint(position: Position): boolean {
|
|
120
128
|
return !this.node.is_open && position === "inside";
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
private
|
|
131
|
+
private _getButton(): HTMLLinkElement {
|
|
124
132
|
return this.element.querySelector(
|
|
125
133
|
":scope > .jqtree-element > a.jqtree-toggler",
|
|
126
134
|
) as HTMLLinkElement;
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { DropHint } from "../dragAndDropHandler/types";
|
|
2
|
-
import { Node, Position } from "../node";
|
|
1
|
+
import type { DropHint } from "../dragAndDropHandler/types";
|
|
2
|
+
import type { Node, Position } from "../node";
|
|
3
3
|
|
|
4
4
|
class GhostDropHint implements DropHint {
|
|
5
|
-
private
|
|
6
|
-
private
|
|
7
|
-
private
|
|
5
|
+
private _element: HTMLElement;
|
|
6
|
+
private _ghost: HTMLElement;
|
|
7
|
+
private _node: Node;
|
|
8
8
|
|
|
9
9
|
constructor(node: Node, element: HTMLElement, position: Position) {
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
10
|
+
this._element = element;
|
|
11
|
+
this._node = node;
|
|
12
|
+
this._ghost = this._createGhostElement();
|
|
13
13
|
|
|
14
14
|
switch (position) {
|
|
15
15
|
case "after":
|
|
16
|
-
this.
|
|
16
|
+
this._moveAfter();
|
|
17
17
|
break;
|
|
18
18
|
|
|
19
19
|
case "before":
|
|
20
|
-
this.
|
|
20
|
+
this._moveBefore();
|
|
21
21
|
break;
|
|
22
22
|
|
|
23
23
|
case "inside": {
|
|
24
24
|
if (node.isFolder() && node.is_open) {
|
|
25
|
-
this.
|
|
25
|
+
this._moveInsideOpenFolder();
|
|
26
26
|
} else {
|
|
27
|
-
this.
|
|
27
|
+
this._moveInside();
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
public remove(): void {
|
|
34
|
-
this.
|
|
34
|
+
this._ghost.remove();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
private
|
|
37
|
+
private _createGhostElement() {
|
|
38
38
|
const ghost = document.createElement("li");
|
|
39
39
|
ghost.className = "jqtree_common jqtree-ghost";
|
|
40
40
|
|
|
@@ -49,24 +49,24 @@ class GhostDropHint implements DropHint {
|
|
|
49
49
|
return ghost;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
private
|
|
53
|
-
this.
|
|
52
|
+
private _moveAfter(): void {
|
|
53
|
+
this._element.after(this._ghost);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
private
|
|
57
|
-
this.
|
|
56
|
+
private _moveBefore(): void {
|
|
57
|
+
this._element.before(this._ghost);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
private
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
60
|
+
private _moveInside(): void {
|
|
61
|
+
this._element.after(this._ghost);
|
|
62
|
+
this._ghost.classList.add("jqtree-inside");
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
private
|
|
66
|
-
const childElement = this.
|
|
65
|
+
private _moveInsideOpenFolder(): void {
|
|
66
|
+
const childElement = this._node.children[0]?.element;
|
|
67
67
|
|
|
68
68
|
if (childElement) {
|
|
69
|
-
childElement.before(this.
|
|
69
|
+
childElement.before(this._ghost);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
package/src/nodeElement/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DropHint } from "../dragAndDropHandler/types";
|
|
2
|
-
import { GetScrollLeft } from "../jqtreeMethodTypes";
|
|
3
|
-
import { Node, Position } from "../node";
|
|
1
|
+
import type { DropHint } from "../dragAndDropHandler/types";
|
|
2
|
+
import type { GetScrollLeft } from "../jqtreeMethodTypes";
|
|
3
|
+
import type { Node, Position } from "../node";
|
|
4
|
+
|
|
4
5
|
import BorderDropHint from "./borderDropHint";
|
|
5
6
|
import GhostDropHint from "./ghostDropHint";
|
|
6
7
|
|
|
@@ -14,9 +15,9 @@ export interface NodeElementParams {
|
|
|
14
15
|
class NodeElement {
|
|
15
16
|
public element: HTMLElement;
|
|
16
17
|
public node: Node;
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
18
|
+
private _getScrollLeft: GetScrollLeft;
|
|
19
|
+
private _tabIndex?: number;
|
|
20
|
+
private _treeElement: HTMLElement;
|
|
20
21
|
|
|
21
22
|
constructor({
|
|
22
23
|
getScrollLeft,
|
|
@@ -24,16 +25,16 @@ class NodeElement {
|
|
|
24
25
|
tabIndex,
|
|
25
26
|
treeElement,
|
|
26
27
|
}: NodeElementParams) {
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
28
|
+
this._getScrollLeft = getScrollLeft;
|
|
29
|
+
this._tabIndex = tabIndex;
|
|
30
|
+
this._treeElement = treeElement;
|
|
30
31
|
|
|
31
32
|
this.init(node);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
public addDropHint(position: Position): DropHint {
|
|
35
|
-
if (this.
|
|
36
|
-
return new BorderDropHint(this.element, this.
|
|
36
|
+
if (this._mustShowBorderDropHint(position)) {
|
|
37
|
+
return new BorderDropHint(this.element, this._getScrollLeft());
|
|
37
38
|
} else {
|
|
38
39
|
return new GhostDropHint(this.node, this.element, position);
|
|
39
40
|
}
|
|
@@ -42,7 +43,7 @@ class NodeElement {
|
|
|
42
43
|
public deselect(): void {
|
|
43
44
|
this.element.classList.remove("jqtree-selected");
|
|
44
45
|
|
|
45
|
-
const titleSpan = this.
|
|
46
|
+
const titleSpan = this._getTitleSpan();
|
|
46
47
|
titleSpan.removeAttribute("tabindex");
|
|
47
48
|
titleSpan.setAttribute("aria-selected", "false");
|
|
48
49
|
|
|
@@ -52,7 +53,7 @@ class NodeElement {
|
|
|
52
53
|
public init(node: Node): void {
|
|
53
54
|
this.node = node;
|
|
54
55
|
|
|
55
|
-
node.element ??= this.
|
|
56
|
+
node.element ??= this._treeElement;
|
|
56
57
|
|
|
57
58
|
this.element = node.element;
|
|
58
59
|
}
|
|
@@ -60,8 +61,8 @@ class NodeElement {
|
|
|
60
61
|
public select(mustSetFocus: boolean): void {
|
|
61
62
|
this.element.classList.add("jqtree-selected");
|
|
62
63
|
|
|
63
|
-
const titleSpan = this.
|
|
64
|
-
const tabIndex = this.
|
|
64
|
+
const titleSpan = this._getTitleSpan();
|
|
65
|
+
const tabIndex = this._tabIndex;
|
|
65
66
|
|
|
66
67
|
// Check for null or undefined
|
|
67
68
|
if (tabIndex != null) {
|
|
@@ -75,17 +76,17 @@ class NodeElement {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
protected
|
|
79
|
+
protected _getTitleSpan(): HTMLSpanElement {
|
|
79
80
|
return this.element.querySelector(
|
|
80
81
|
":scope > .jqtree-element > span.jqtree-title",
|
|
81
82
|
) as HTMLSpanElement;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
protected
|
|
85
|
+
protected _getUl(): HTMLUListElement {
|
|
85
86
|
return this.element.querySelector(":scope > ul") as HTMLUListElement;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
protected
|
|
89
|
+
protected _mustShowBorderDropHint(position: Position): boolean {
|
|
89
90
|
return position === "inside";
|
|
90
91
|
}
|
|
91
92
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface TopLeftPosition {
|
|
2
|
+
left: number;
|
|
3
|
+
top: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// Get the top position of the HTML element.
|
|
7
|
+
export const getOffsetTop = (element: HTMLElement): number =>
|
|
8
|
+
getElementPosition(element).top;
|
|
9
|
+
|
|
10
|
+
// Get the top left position of the HTML element.
|
|
11
|
+
export const getElementPosition = (element: HTMLElement): TopLeftPosition => {
|
|
12
|
+
const rect = element.getBoundingClientRect();
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
left: rect.x + window.scrollX,
|
|
16
|
+
top: rect.y + window.scrollY,
|
|
17
|
+
};
|
|
18
|
+
};
|
package/src/saveStateHandler.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AddToSelection,
|
|
3
3
|
GetNodeById,
|
|
4
4
|
GetSelectedNodes,
|
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
RefreshElements,
|
|
8
8
|
RemoveFromSelection,
|
|
9
9
|
} from "./jqtreeMethodTypes";
|
|
10
|
-
import { OnGetStateFromStorage, OnSetStateFromStorage } from "./jqtreeOptions";
|
|
11
|
-
import { Node } from "./node";
|
|
10
|
+
import type { OnGetStateFromStorage, OnSetStateFromStorage } from "./jqtreeOptions";
|
|
11
|
+
import type { Node } from "./node";
|
|
12
|
+
|
|
12
13
|
import { isInt } from "./util";
|
|
13
14
|
|
|
14
15
|
export interface SavedState {
|
|
@@ -30,16 +31,16 @@ interface SaveStateHandlerParams {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
export default class SaveStateHandler {
|
|
33
|
-
private
|
|
34
|
-
private
|
|
35
|
-
private
|
|
36
|
-
private
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private
|
|
41
|
-
private
|
|
42
|
-
private
|
|
34
|
+
private _addToSelection: AddToSelection;
|
|
35
|
+
private _getNodeById: GetNodeById;
|
|
36
|
+
private _getSelectedNodes: GetSelectedNodes;
|
|
37
|
+
private _getTree: GetTree;
|
|
38
|
+
private _onGetStateFromStorage?: OnGetStateFromStorage;
|
|
39
|
+
private _onSetStateFromStorage?: OnSetStateFromStorage;
|
|
40
|
+
private _openNode: OpenNode;
|
|
41
|
+
private _refreshElements: RefreshElements;
|
|
42
|
+
private _removeFromSelection: RemoveFromSelection;
|
|
43
|
+
private _saveStateOption: boolean | string;
|
|
43
44
|
|
|
44
45
|
constructor({
|
|
45
46
|
addToSelection,
|
|
@@ -53,16 +54,16 @@ export default class SaveStateHandler {
|
|
|
53
54
|
removeFromSelection,
|
|
54
55
|
saveState,
|
|
55
56
|
}: SaveStateHandlerParams) {
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
57
|
+
this._addToSelection = addToSelection;
|
|
58
|
+
this._getNodeById = getNodeById;
|
|
59
|
+
this._getSelectedNodes = getSelectedNodes;
|
|
60
|
+
this._getTree = getTree;
|
|
61
|
+
this._onGetStateFromStorage = onGetStateFromStorage;
|
|
62
|
+
this._onSetStateFromStorage = onSetStateFromStorage;
|
|
63
|
+
this._openNode = openNode;
|
|
64
|
+
this._refreshElements = refreshElements;
|
|
65
|
+
this._removeFromSelection = removeFromSelection;
|
|
66
|
+
this._saveStateOption = saveState;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
public getNodeIdToBeSelected(): NodeId | null {
|
|
@@ -79,7 +80,7 @@ export default class SaveStateHandler {
|
|
|
79
80
|
const getOpenNodeIds = (): NodeId[] => {
|
|
80
81
|
const openNodes: NodeId[] = [];
|
|
81
82
|
|
|
82
|
-
this.
|
|
83
|
+
this._getTree()?.iterate((node: Node) => {
|
|
83
84
|
if (node.is_open && node.id && node.hasChildren()) {
|
|
84
85
|
openNodes.push(node.id);
|
|
85
86
|
}
|
|
@@ -92,7 +93,7 @@ export default class SaveStateHandler {
|
|
|
92
93
|
const getSelectedNodeIds = (): NodeId[] => {
|
|
93
94
|
const selectedNodeIds: NodeId[] = [];
|
|
94
95
|
|
|
95
|
-
this.
|
|
96
|
+
this._getSelectedNodes().forEach((node) => {
|
|
96
97
|
if (node.id != null) {
|
|
97
98
|
selectedNodeIds.push(node.id);
|
|
98
99
|
}
|
|
@@ -108,10 +109,10 @@ export default class SaveStateHandler {
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
public getStateFromStorage(): null | SavedState {
|
|
111
|
-
const jsonData = this.
|
|
112
|
+
const jsonData = this._loadFromStorage();
|
|
112
113
|
|
|
113
114
|
if (jsonData) {
|
|
114
|
-
return this.
|
|
115
|
+
return this._parseState(jsonData);
|
|
115
116
|
} else {
|
|
116
117
|
return null;
|
|
117
118
|
}
|
|
@@ -120,10 +121,10 @@ export default class SaveStateHandler {
|
|
|
120
121
|
public saveState(): void {
|
|
121
122
|
const state = JSON.stringify(this.getState());
|
|
122
123
|
|
|
123
|
-
if (this.
|
|
124
|
-
this.
|
|
124
|
+
if (this._onSetStateFromStorage) {
|
|
125
|
+
this._onSetStateFromStorage(state);
|
|
125
126
|
} else {
|
|
126
|
-
localStorage.setItem(this.
|
|
127
|
+
localStorage.setItem(this._getKeyName(), state);
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
|
|
@@ -137,13 +138,13 @@ export default class SaveStateHandler {
|
|
|
137
138
|
let mustLoadOnDemand = false;
|
|
138
139
|
|
|
139
140
|
if (state.open_nodes) {
|
|
140
|
-
mustLoadOnDemand = this.
|
|
141
|
+
mustLoadOnDemand = this._openInitialNodes(state.open_nodes);
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
this.
|
|
144
|
+
this._resetSelection();
|
|
144
145
|
|
|
145
146
|
if (state.selected_node) {
|
|
146
|
-
this.
|
|
147
|
+
this._selectInitialNodes(state.selected_node);
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
return mustLoadOnDemand;
|
|
@@ -164,7 +165,7 @@ export default class SaveStateHandler {
|
|
|
164
165
|
const newNodesIds = [];
|
|
165
166
|
|
|
166
167
|
for (const nodeId of nodeIds) {
|
|
167
|
-
const node = this.
|
|
168
|
+
const node = this._getNodeById(nodeId);
|
|
168
169
|
|
|
169
170
|
if (!node) {
|
|
170
171
|
newNodesIds.push(nodeId);
|
|
@@ -173,7 +174,7 @@ export default class SaveStateHandler {
|
|
|
173
174
|
if (node.load_on_demand) {
|
|
174
175
|
loadAndOpenNode(node);
|
|
175
176
|
} else {
|
|
176
|
-
this.
|
|
177
|
+
this._openNode(node, false);
|
|
177
178
|
}
|
|
178
179
|
}
|
|
179
180
|
}
|
|
@@ -182,8 +183,8 @@ export default class SaveStateHandler {
|
|
|
182
183
|
nodeIds = newNodesIds;
|
|
183
184
|
|
|
184
185
|
if (state.selected_node) {
|
|
185
|
-
if (this.
|
|
186
|
-
this.
|
|
186
|
+
if (this._selectInitialNodes(state.selected_node)) {
|
|
187
|
+
this._refreshElements(null);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
|
|
@@ -194,7 +195,7 @@ export default class SaveStateHandler {
|
|
|
194
195
|
|
|
195
196
|
const loadAndOpenNode = (node: Node): void => {
|
|
196
197
|
loadingCount += 1;
|
|
197
|
-
this.
|
|
198
|
+
this._openNode(node, false, () => {
|
|
198
199
|
loadingCount -= 1;
|
|
199
200
|
openNodes();
|
|
200
201
|
});
|
|
@@ -203,27 +204,27 @@ export default class SaveStateHandler {
|
|
|
203
204
|
openNodes();
|
|
204
205
|
}
|
|
205
206
|
|
|
206
|
-
private
|
|
207
|
-
if (typeof this.
|
|
208
|
-
return this.
|
|
207
|
+
private _getKeyName(): string {
|
|
208
|
+
if (typeof this._saveStateOption === "string") {
|
|
209
|
+
return this._saveStateOption;
|
|
209
210
|
} else {
|
|
210
211
|
return "tree";
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
private
|
|
215
|
-
if (this.
|
|
216
|
-
return this.
|
|
215
|
+
private _loadFromStorage(): null | string {
|
|
216
|
+
if (this._onGetStateFromStorage) {
|
|
217
|
+
return this._onGetStateFromStorage();
|
|
217
218
|
} else {
|
|
218
|
-
return localStorage.getItem(this.
|
|
219
|
+
return localStorage.getItem(this._getKeyName());
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
|
|
222
|
-
private
|
|
223
|
+
private _openInitialNodes(nodeIds: NodeId[]): boolean {
|
|
223
224
|
let mustLoadOnDemand = false;
|
|
224
225
|
|
|
225
226
|
for (const nodeId of nodeIds) {
|
|
226
|
-
const node = this.
|
|
227
|
+
const node = this._getNodeById(nodeId);
|
|
227
228
|
|
|
228
229
|
if (node) {
|
|
229
230
|
if (!node.load_on_demand) {
|
|
@@ -237,7 +238,7 @@ export default class SaveStateHandler {
|
|
|
237
238
|
return mustLoadOnDemand;
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
private
|
|
241
|
+
private _parseState(jsonData: string): SavedState {
|
|
241
242
|
const state = JSON.parse(jsonData) as Record<string, unknown>;
|
|
242
243
|
|
|
243
244
|
// Check if selected_node is an int (instead of an array)
|
|
@@ -246,27 +247,27 @@ export default class SaveStateHandler {
|
|
|
246
247
|
state.selected_node = [state.selected_node];
|
|
247
248
|
}
|
|
248
249
|
|
|
249
|
-
return state
|
|
250
|
+
return state;
|
|
250
251
|
}
|
|
251
252
|
|
|
252
|
-
private
|
|
253
|
-
const selectedNodes = this.
|
|
253
|
+
private _resetSelection(): void {
|
|
254
|
+
const selectedNodes = this._getSelectedNodes();
|
|
254
255
|
|
|
255
256
|
selectedNodes.forEach((node) => {
|
|
256
|
-
this.
|
|
257
|
+
this._removeFromSelection(node);
|
|
257
258
|
});
|
|
258
259
|
}
|
|
259
260
|
|
|
260
|
-
private
|
|
261
|
+
private _selectInitialNodes(nodeIds: NodeId[]): boolean {
|
|
261
262
|
let selectCount = 0;
|
|
262
263
|
|
|
263
264
|
for (const nodeId of nodeIds) {
|
|
264
|
-
const node = this.
|
|
265
|
+
const node = this._getNodeById(nodeId);
|
|
265
266
|
|
|
266
267
|
if (node) {
|
|
267
268
|
selectCount += 1;
|
|
268
269
|
|
|
269
|
-
this.
|
|
270
|
+
this._addToSelection(node);
|
|
270
271
|
}
|
|
271
272
|
}
|
|
272
273
|
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type {
|
|
3
2
|
HorizontalScrollDirection,
|
|
4
|
-
ScrollParent,
|
|
5
3
|
VerticalScrollDirection,
|
|
6
4
|
} from "./scrollParent";
|
|
7
5
|
|
|
6
|
+
import { getElementPosition, getOffsetTop } from "../positionUtils";
|
|
7
|
+
import { ScrollParent } from "./scrollParent";
|
|
8
|
+
|
|
9
|
+
|
|
8
10
|
export default class ContainerScrollParent extends ScrollParent {
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
+
private _scrollParentBottom?: number;
|
|
12
|
+
private _scrollParentTop?: number;
|
|
11
13
|
|
|
12
14
|
public stopScrolling() {
|
|
13
15
|
super.stopScrolling();
|
|
14
16
|
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
+
this._horizontalScrollDirection = undefined;
|
|
18
|
+
this._verticalScrollDirection = undefined;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
protected
|
|
21
|
+
protected _getNewHorizontalScrollDirection(
|
|
20
22
|
pageX: number,
|
|
21
23
|
): HorizontalScrollDirection | undefined {
|
|
22
|
-
const scrollParentOffset = getElementPosition(this.
|
|
23
|
-
const containerWidth = this.
|
|
24
|
+
const scrollParentOffset = getElementPosition(this._container);
|
|
25
|
+
const containerWidth = this._container.getBoundingClientRect().width;
|
|
24
26
|
|
|
25
27
|
const rightEdge = scrollParentOffset.left + containerWidth;
|
|
26
28
|
const leftEdge = scrollParentOffset.left;
|
|
@@ -36,34 +38,34 @@ export default class ContainerScrollParent extends ScrollParent {
|
|
|
36
38
|
return undefined;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
protected
|
|
41
|
+
protected _getNewVerticalScrollDirection(
|
|
40
42
|
pageY: number,
|
|
41
43
|
): undefined | VerticalScrollDirection {
|
|
42
|
-
if (pageY < this.
|
|
44
|
+
if (pageY < this._getScrollParentTop()) {
|
|
43
45
|
return "top";
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
if (pageY > this.
|
|
48
|
+
if (pageY > this._getScrollParentBottom()) {
|
|
47
49
|
return "bottom";
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
return undefined;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
private
|
|
54
|
-
if (this.
|
|
55
|
+
private _getScrollParentBottom() {
|
|
56
|
+
if (this._scrollParentBottom == null) {
|
|
55
57
|
const containerHeight =
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
58
|
+
this._container.getBoundingClientRect().height;
|
|
59
|
+
this._scrollParentBottom =
|
|
60
|
+
this._getScrollParentTop() + containerHeight;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
return this.
|
|
63
|
+
return this._scrollParentBottom;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
private
|
|
65
|
-
this.
|
|
66
|
+
private _getScrollParentTop() {
|
|
67
|
+
this._scrollParentTop ??= getOffsetTop(this._container);
|
|
66
68
|
|
|
67
|
-
return this.
|
|
69
|
+
return this._scrollParentTop;
|
|
68
70
|
}
|
|
69
71
|
}
|