jqtree 1.8.7 → 1.8.9

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.
@@ -1,6 +1,5 @@
1
1
  import { DropHint } from "../dragAndDropHandler/types";
2
- import { Node } from "../node";
3
- import { Position } from "../position";
2
+ import { Node, Position } from "../node";
4
3
 
5
4
  class GhostDropHint implements DropHint {
6
5
  private element: HTMLElement;
@@ -13,15 +12,15 @@ class GhostDropHint implements DropHint {
13
12
  this.ghost = this.createGhostElement();
14
13
 
15
14
  switch (position) {
16
- case Position.After:
15
+ case "after":
17
16
  this.moveAfter();
18
17
  break;
19
18
 
20
- case Position.Before:
19
+ case "before":
21
20
  this.moveBefore();
22
21
  break;
23
22
 
24
- case Position.Inside: {
23
+ case "inside": {
25
24
  if (node.isFolder() && node.is_open) {
26
25
  this.moveInsideOpenFolder();
27
26
  } else {
@@ -31,6 +30,10 @@ class GhostDropHint implements DropHint {
31
30
  }
32
31
  }
33
32
 
33
+ public remove(): void {
34
+ this.ghost.remove();
35
+ }
36
+
34
37
  private createGhostElement() {
35
38
  const ghost = document.createElement("li");
36
39
  ghost.className = "jqtree_common jqtree-ghost";
@@ -66,10 +69,6 @@ class GhostDropHint implements DropHint {
66
69
  childElement.before(this.ghost);
67
70
  }
68
71
  }
69
-
70
- public remove(): void {
71
- this.ghost.remove();
72
- }
73
72
  }
74
73
 
75
74
  export default GhostDropHint;
@@ -1,52 +1,37 @@
1
1
  import { DropHint } from "../dragAndDropHandler/types";
2
2
  import { GetScrollLeft } from "../jqtreeMethodTypes";
3
- import { Node } from "../node";
4
- import { Position } from "../position";
3
+ import { Node, Position } from "../node";
5
4
  import BorderDropHint from "./borderDropHint";
6
5
  import GhostDropHint from "./ghostDropHint";
7
6
 
8
7
  export interface NodeElementParams {
9
- $treeElement: JQuery;
10
8
  getScrollLeft: GetScrollLeft;
11
9
  node: Node;
12
10
  tabIndex?: number;
11
+ treeElement: HTMLElement;
13
12
  }
14
13
 
15
14
  class NodeElement {
16
- private $treeElement: JQuery;
17
- private getScrollLeft: GetScrollLeft;
18
- private tabIndex?: number;
19
15
  public element: HTMLElement;
20
16
  public node: Node;
17
+ private getScrollLeft: GetScrollLeft;
18
+ private tabIndex?: number;
19
+ private treeElement: HTMLElement;
21
20
 
22
21
  constructor({
23
- $treeElement,
24
22
  getScrollLeft,
25
23
  node,
26
24
  tabIndex,
25
+ treeElement,
27
26
  }: NodeElementParams) {
28
27
  this.getScrollLeft = getScrollLeft;
29
28
  this.tabIndex = tabIndex;
30
- this.$treeElement = $treeElement;
29
+ this.treeElement = treeElement;
31
30
 
32
31
  this.init(node);
33
32
  }
34
33
 
35
- protected getTitleSpan(): HTMLSpanElement {
36
- return this.element.querySelector(
37
- ":scope > .jqtree-element > span.jqtree-title",
38
- ) as HTMLSpanElement;
39
- }
40
-
41
- protected getUl(): HTMLUListElement {
42
- return this.element.querySelector(":scope > ul") as HTMLUListElement;
43
- }
44
-
45
- protected mustShowBorderDropHint(position: Position): boolean {
46
- return position === Position.Inside;
47
- }
48
-
49
- public addDropHint(position: number): DropHint {
34
+ public addDropHint(position: Position): DropHint {
50
35
  if (this.mustShowBorderDropHint(position)) {
51
36
  return new BorderDropHint(this.element, this.getScrollLeft());
52
37
  } else {
@@ -68,16 +53,10 @@ class NodeElement {
68
53
  this.node = node;
69
54
 
70
55
  if (!node.element) {
71
- const element = this.$treeElement.get(0);
72
-
73
- if (element) {
74
- node.element = element;
75
- }
56
+ node.element = this.treeElement;
76
57
  }
77
58
 
78
- if (node.element) {
79
- this.element = node.element;
80
- }
59
+ this.element = node.element;
81
60
  }
82
61
 
83
62
  public select(mustSetFocus: boolean): void {
@@ -97,6 +76,20 @@ class NodeElement {
97
76
  titleSpan.focus();
98
77
  }
99
78
  }
79
+
80
+ protected getTitleSpan(): HTMLSpanElement {
81
+ return this.element.querySelector(
82
+ ":scope > .jqtree-element > span.jqtree-title",
83
+ ) as HTMLSpanElement;
84
+ }
85
+
86
+ protected getUl(): HTMLUListElement {
87
+ return this.element.querySelector(":scope > ul") as HTMLUListElement;
88
+ }
89
+
90
+ protected mustShowBorderDropHint(position: Position): boolean {
91
+ return position === "inside";
92
+ }
100
93
  }
101
94
 
102
95
  export default NodeElement;
@@ -30,7 +30,6 @@ interface SaveStateHandlerParams {
30
30
  }
31
31
 
32
32
  export default class SaveStateHandler {
33
- private _supportsLocalStorage: boolean | null;
34
33
  private addToSelection: AddToSelection;
35
34
  private getNodeById: GetNodeById;
36
35
  private getSelectedNodes: GetSelectedNodes;
@@ -66,99 +65,6 @@ export default class SaveStateHandler {
66
65
  this.saveStateOption = saveState;
67
66
  }
68
67
 
69
- private getKeyName(): string {
70
- if (typeof this.saveStateOption === "string") {
71
- return this.saveStateOption;
72
- } else {
73
- return "tree";
74
- }
75
- }
76
-
77
- private loadFromStorage(): null | string {
78
- if (this.onGetStateFromStorage) {
79
- return this.onGetStateFromStorage();
80
- } else if (this.supportsLocalStorage()) {
81
- return localStorage.getItem(this.getKeyName());
82
- } else {
83
- return null;
84
- }
85
- }
86
-
87
- private openInitialNodes(nodeIds: NodeId[]): boolean {
88
- let mustLoadOnDemand = false;
89
-
90
- for (const nodeId of nodeIds) {
91
- const node = this.getNodeById(nodeId);
92
-
93
- if (node) {
94
- if (!node.load_on_demand) {
95
- node.is_open = true;
96
- } else {
97
- mustLoadOnDemand = true;
98
- }
99
- }
100
- }
101
-
102
- return mustLoadOnDemand;
103
- }
104
-
105
- private parseState(jsonData: string): SavedState {
106
- const state = JSON.parse(jsonData) as Record<string, unknown>;
107
-
108
- // Check if selected_node is an int (instead of an array)
109
- if (state.selected_node && isInt(state.selected_node)) {
110
- // Convert to array
111
- state.selected_node = [state.selected_node];
112
- }
113
-
114
- return state as unknown as SavedState;
115
- }
116
-
117
- private resetSelection(): void {
118
- const selectedNodes = this.getSelectedNodes();
119
-
120
- selectedNodes.forEach((node) => {
121
- this.removeFromSelection(node);
122
- });
123
- }
124
-
125
- private selectInitialNodes(nodeIds: NodeId[]): boolean {
126
- let selectCount = 0;
127
-
128
- for (const nodeId of nodeIds) {
129
- const node = this.getNodeById(nodeId);
130
-
131
- if (node) {
132
- selectCount += 1;
133
-
134
- this.addToSelection(node);
135
- }
136
- }
137
-
138
- return selectCount !== 0;
139
- }
140
-
141
- private supportsLocalStorage(): boolean {
142
- const testSupport = (): boolean => {
143
- // Check if it's possible to store an item. Safari does not allow this in private browsing mode.
144
- try {
145
- const key = "_storage_test";
146
- sessionStorage.setItem(key, "value");
147
- sessionStorage.removeItem(key);
148
- } catch {
149
- return false;
150
- }
151
-
152
- return true;
153
- };
154
-
155
- if (this._supportsLocalStorage == null) {
156
- this._supportsLocalStorage = testSupport();
157
- }
158
-
159
- return this._supportsLocalStorage;
160
- }
161
-
162
68
  public getNodeIdToBeSelected(): NodeId | null {
163
69
  const state = this.getStateFromStorage();
164
70
 
@@ -216,7 +122,7 @@ export default class SaveStateHandler {
216
122
 
217
123
  if (this.onSetStateFromStorage) {
218
124
  this.onSetStateFromStorage(state);
219
- } else if (this.supportsLocalStorage()) {
125
+ } else {
220
126
  localStorage.setItem(this.getKeyName(), state);
221
127
  }
222
128
  }
@@ -225,7 +131,7 @@ export default class SaveStateHandler {
225
131
  Set initial state
226
132
  Don't handle nodes that are loaded on demand
227
133
 
228
- result: must load on demand
134
+ result: must load on demand (boolean)
229
135
  */
230
136
  public setInitialState(state: SavedState): boolean {
231
137
  let mustLoadOnDemand = false;
@@ -296,4 +202,74 @@ export default class SaveStateHandler {
296
202
 
297
203
  openNodes();
298
204
  }
205
+
206
+ private getKeyName(): string {
207
+ if (typeof this.saveStateOption === "string") {
208
+ return this.saveStateOption;
209
+ } else {
210
+ return "tree";
211
+ }
212
+ }
213
+
214
+ private loadFromStorage(): null | string {
215
+ if (this.onGetStateFromStorage) {
216
+ return this.onGetStateFromStorage();
217
+ } else {
218
+ return localStorage.getItem(this.getKeyName());
219
+ }
220
+ }
221
+
222
+ private openInitialNodes(nodeIds: NodeId[]): boolean {
223
+ let mustLoadOnDemand = false;
224
+
225
+ for (const nodeId of nodeIds) {
226
+ const node = this.getNodeById(nodeId);
227
+
228
+ if (node) {
229
+ if (!node.load_on_demand) {
230
+ node.is_open = true;
231
+ } else {
232
+ mustLoadOnDemand = true;
233
+ }
234
+ }
235
+ }
236
+
237
+ return mustLoadOnDemand;
238
+ }
239
+
240
+ private parseState(jsonData: string): SavedState {
241
+ const state = JSON.parse(jsonData) as Record<string, unknown>;
242
+
243
+ // Check if selected_node is an int (instead of an array)
244
+ if (state.selected_node && isInt(state.selected_node)) {
245
+ // Convert to array
246
+ state.selected_node = [state.selected_node];
247
+ }
248
+
249
+ return state as unknown as SavedState;
250
+ }
251
+
252
+ private resetSelection(): void {
253
+ const selectedNodes = this.getSelectedNodes();
254
+
255
+ selectedNodes.forEach((node) => {
256
+ this.removeFromSelection(node);
257
+ });
258
+ }
259
+
260
+ private selectInitialNodes(nodeIds: NodeId[]): boolean {
261
+ let selectCount = 0;
262
+
263
+ for (const nodeId of nodeIds) {
264
+ const node = this.getNodeById(nodeId);
265
+
266
+ if (node) {
267
+ selectCount += 1;
268
+
269
+ this.addToSelection(node);
270
+ }
271
+ }
272
+
273
+ return selectCount !== 0;
274
+ }
299
275
  }
@@ -3,13 +3,13 @@ import type { ScrollParent } from "./types";
3
3
  import { getElementPosition, getOffsetTop } from '../util'
4
4
 
5
5
  type HorizontalScrollDirection = "left" | "right";
6
- type VerticalScrollDirection = "bottom" | "top";
7
-
8
6
  interface Params {
9
7
  container: HTMLElement;
10
8
  refreshHitAreas: () => void;
11
9
  }
12
10
 
11
+ type VerticalScrollDirection = "bottom" | "top";
12
+
13
13
  export default class ContainerScrollParent implements ScrollParent {
14
14
  private container: HTMLElement;
15
15
  private horizontalScrollDirection?: HorizontalScrollDirection;
@@ -25,6 +25,62 @@ export default class ContainerScrollParent implements ScrollParent {
25
25
  this.refreshHitAreas = refreshHitAreas;
26
26
  }
27
27
 
28
+ public checkHorizontalScrolling(pageX: number): void {
29
+ const newHorizontalScrollDirection =
30
+ this.getNewHorizontalScrollDirection(pageX);
31
+
32
+ if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
33
+ this.horizontalScrollDirection = newHorizontalScrollDirection;
34
+
35
+ if (this.horizontalScrollTimeout != null) {
36
+ window.clearTimeout(this.verticalScrollTimeout);
37
+ }
38
+
39
+ if (newHorizontalScrollDirection) {
40
+ this.horizontalScrollTimeout = window.setTimeout(
41
+ this.scrollHorizontally.bind(this),
42
+ 40,
43
+ );
44
+ }
45
+ }
46
+ }
47
+
48
+ public checkVerticalScrolling(pageY: number) {
49
+ const newVerticalScrollDirection =
50
+ this.getNewVerticalScrollDirection(pageY);
51
+
52
+ if (this.verticalScrollDirection !== newVerticalScrollDirection) {
53
+ this.verticalScrollDirection = newVerticalScrollDirection;
54
+
55
+ if (this.verticalScrollTimeout != null) {
56
+ window.clearTimeout(this.verticalScrollTimeout);
57
+ this.verticalScrollTimeout = undefined;
58
+ }
59
+
60
+ if (newVerticalScrollDirection) {
61
+ this.verticalScrollTimeout = window.setTimeout(
62
+ this.scrollVertically.bind(this),
63
+ 40,
64
+ );
65
+ }
66
+ }
67
+ }
68
+
69
+ public getScrollLeft(): number {
70
+ return this.container.scrollLeft;
71
+ }
72
+
73
+ public scrollToY(top: number): void {
74
+ this.container.scrollTop = top;
75
+ }
76
+
77
+ public stopScrolling() {
78
+ this.horizontalScrollDirection = undefined;
79
+ this.verticalScrollDirection = undefined;
80
+ this.scrollParentTop = undefined;
81
+ this.scrollParentBottom = undefined;
82
+ }
83
+
28
84
  private getNewHorizontalScrollDirection(
29
85
  pageX: number,
30
86
  ): HorizontalScrollDirection | undefined {
@@ -109,60 +165,4 @@ export default class ContainerScrollParent implements ScrollParent {
109
165
 
110
166
  setTimeout(this.scrollVertically.bind(this), 40);
111
167
  }
112
-
113
- public checkHorizontalScrolling(pageX: number): void {
114
- const newHorizontalScrollDirection =
115
- this.getNewHorizontalScrollDirection(pageX);
116
-
117
- if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
118
- this.horizontalScrollDirection = newHorizontalScrollDirection;
119
-
120
- if (this.horizontalScrollTimeout != null) {
121
- window.clearTimeout(this.verticalScrollTimeout);
122
- }
123
-
124
- if (newHorizontalScrollDirection) {
125
- this.horizontalScrollTimeout = window.setTimeout(
126
- this.scrollHorizontally.bind(this),
127
- 40,
128
- );
129
- }
130
- }
131
- }
132
-
133
- public checkVerticalScrolling(pageY: number) {
134
- const newVerticalScrollDirection =
135
- this.getNewVerticalScrollDirection(pageY);
136
-
137
- if (this.verticalScrollDirection !== newVerticalScrollDirection) {
138
- this.verticalScrollDirection = newVerticalScrollDirection;
139
-
140
- if (this.verticalScrollTimeout != null) {
141
- window.clearTimeout(this.verticalScrollTimeout);
142
- this.verticalScrollTimeout = undefined;
143
- }
144
-
145
- if (newVerticalScrollDirection) {
146
- this.verticalScrollTimeout = window.setTimeout(
147
- this.scrollVertically.bind(this),
148
- 40,
149
- );
150
- }
151
- }
152
- }
153
-
154
- public getScrollLeft(): number {
155
- return this.container.scrollLeft;
156
- }
157
-
158
- public scrollToY(top: number): void {
159
- this.container.scrollTop = top;
160
- }
161
-
162
- public stopScrolling() {
163
- this.horizontalScrollDirection = undefined;
164
- this.verticalScrollDirection = undefined;
165
- this.scrollParentTop = undefined;
166
- this.scrollParentBottom = undefined;
167
- }
168
168
  }
@@ -3,13 +3,13 @@ import type { ScrollParent } from "./types";
3
3
  import { getOffsetTop } from "../util";
4
4
 
5
5
  type HorizontalScrollDirection = "left" | "right";
6
- type VerticalScrollDirection = "bottom" | "top";
7
-
8
6
  interface Params {
9
7
  refreshHitAreas: () => void;
10
8
  treeElement: HTMLElement;
11
9
  }
12
10
 
11
+ type VerticalScrollDirection = "bottom" | "top";
12
+
13
13
  export default class DocumentScrollParent implements ScrollParent {
14
14
  private documentScrollHeight?: number;
15
15
  private documentScrollWidth?: number;
@@ -25,6 +25,64 @@ export default class DocumentScrollParent implements ScrollParent {
25
25
  this.treeElement = treeElement;
26
26
  }
27
27
 
28
+ public checkHorizontalScrolling(pageX: number): void {
29
+ const newHorizontalScrollDirection =
30
+ this.getNewHorizontalScrollDirection(pageX);
31
+
32
+ if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
33
+ this.horizontalScrollDirection = newHorizontalScrollDirection;
34
+
35
+ if (this.horizontalScrollTimeout != null) {
36
+ window.clearTimeout(this.horizontalScrollTimeout);
37
+ }
38
+
39
+ if (newHorizontalScrollDirection) {
40
+ this.horizontalScrollTimeout = window.setTimeout(
41
+ this.scrollHorizontally.bind(this),
42
+ 40,
43
+ );
44
+ }
45
+ }
46
+ }
47
+
48
+ public checkVerticalScrolling(pageY: number) {
49
+ const newVerticalScrollDirection =
50
+ this.getNewVerticalScrollDirection(pageY);
51
+
52
+ if (this.verticalScrollDirection !== newVerticalScrollDirection) {
53
+ this.verticalScrollDirection = newVerticalScrollDirection;
54
+
55
+ if (this.verticalScrollTimeout != null) {
56
+ window.clearTimeout(this.verticalScrollTimeout);
57
+ this.verticalScrollTimeout = undefined;
58
+ }
59
+
60
+ if (newVerticalScrollDirection) {
61
+ this.verticalScrollTimeout = window.setTimeout(
62
+ this.scrollVertically.bind(this),
63
+ 40,
64
+ );
65
+ }
66
+ }
67
+ }
68
+
69
+ public getScrollLeft(): number {
70
+ return document.documentElement.scrollLeft;
71
+ }
72
+
73
+ public scrollToY(top: number): void {
74
+ const treeTop = getOffsetTop(this.treeElement);
75
+
76
+ document.documentElement.scrollTop = top + treeTop;
77
+ }
78
+
79
+ public stopScrolling() {
80
+ this.horizontalScrollDirection = undefined;
81
+ this.verticalScrollDirection = undefined;
82
+ this.documentScrollHeight = undefined;
83
+ this.documentScrollWidth = undefined;
84
+ }
85
+
28
86
  private canScrollDown() {
29
87
  const documentElement = document.documentElement;
30
88
 
@@ -125,62 +183,4 @@ export default class DocumentScrollParent implements ScrollParent {
125
183
 
126
184
  setTimeout(this.scrollVertically.bind(this), 40);
127
185
  }
128
-
129
- public checkHorizontalScrolling(pageX: number): void {
130
- const newHorizontalScrollDirection =
131
- this.getNewHorizontalScrollDirection(pageX);
132
-
133
- if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
134
- this.horizontalScrollDirection = newHorizontalScrollDirection;
135
-
136
- if (this.horizontalScrollTimeout != null) {
137
- window.clearTimeout(this.horizontalScrollTimeout);
138
- }
139
-
140
- if (newHorizontalScrollDirection) {
141
- this.horizontalScrollTimeout = window.setTimeout(
142
- this.scrollHorizontally.bind(this),
143
- 40,
144
- );
145
- }
146
- }
147
- }
148
-
149
- public checkVerticalScrolling(pageY: number) {
150
- const newVerticalScrollDirection =
151
- this.getNewVerticalScrollDirection(pageY);
152
-
153
- if (this.verticalScrollDirection !== newVerticalScrollDirection) {
154
- this.verticalScrollDirection = newVerticalScrollDirection;
155
-
156
- if (this.verticalScrollTimeout != null) {
157
- window.clearTimeout(this.verticalScrollTimeout);
158
- this.verticalScrollTimeout = undefined;
159
- }
160
-
161
- if (newVerticalScrollDirection) {
162
- this.verticalScrollTimeout = window.setTimeout(
163
- this.scrollVertically.bind(this),
164
- 40,
165
- );
166
- }
167
- }
168
- }
169
-
170
- public getScrollLeft(): number {
171
- return document.documentElement.scrollLeft;
172
- }
173
-
174
- public scrollToY(top: number): void {
175
- const treeTop = getOffsetTop(this.treeElement);
176
-
177
- document.documentElement.scrollTop = top + treeTop;
178
- }
179
-
180
- public stopScrolling() {
181
- this.horizontalScrollDirection = undefined;
182
- this.verticalScrollDirection = undefined;
183
- this.documentScrollHeight = undefined;
184
- this.documentScrollWidth = undefined;
185
- }
186
186
  }
@@ -18,6 +18,23 @@ export default class ScrollHandler {
18
18
  this.treeElement = treeElement;
19
19
  }
20
20
 
21
+ public checkScrolling(positionInfo: PositionInfo): void {
22
+ this.checkVerticalScrolling(positionInfo);
23
+ this.checkHorizontalScrolling(positionInfo);
24
+ }
25
+
26
+ public getScrollLeft(): number {
27
+ return this.getScrollParent().getScrollLeft();
28
+ }
29
+
30
+ public scrollToY(top: number): void {
31
+ this.getScrollParent().scrollToY(top);
32
+ }
33
+
34
+ public stopScrolling() {
35
+ this.getScrollParent().stopScrolling();
36
+ }
37
+
21
38
  private checkHorizontalScrolling(positionInfo: PositionInfo): void {
22
39
  this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
23
40
  }
@@ -36,21 +53,4 @@ export default class ScrollHandler {
36
53
 
37
54
  return this.scrollParent;
38
55
  }
39
-
40
- public checkScrolling(positionInfo: PositionInfo): void {
41
- this.checkVerticalScrolling(positionInfo);
42
- this.checkHorizontalScrolling(positionInfo);
43
- }
44
-
45
- public getScrollLeft(): number {
46
- return this.getScrollParent().getScrollLeft();
47
- }
48
-
49
- public scrollToY(top: number): void {
50
- this.getScrollParent().scrollToY(top);
51
- }
52
-
53
- public stopScrolling() {
54
- this.getScrollParent().stopScrolling();
55
- }
56
56
  }
@@ -64,18 +64,14 @@ export default class SelectNodeHandler {
64
64
  return [];
65
65
  }
66
66
  } else {
67
- const selectedNodes = [];
68
-
69
- for (const id in this.selectedNodes) {
70
- if (
71
- Object.prototype.hasOwnProperty.call(this.selectedNodes, id)
72
- ) {
73
- const node = this.getNodeById(id);
74
- if (node && parent.isParentOf(node)) {
75
- selectedNodes.push(node);
76
- }
67
+ const selectedNodes: Node[] = [];
68
+
69
+ this.selectedNodes.forEach((id) => {
70
+ const node = this.getNodeById(id);
71
+ if (node && parent.isParentOf(node)) {
72
+ selectedNodes.push(node);
77
73
  }
78
- }
74
+ });
79
75
 
80
76
  return selectedNodes;
81
77
  }