jqtree 1.8.8 → 1.8.10

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,7 +1,6 @@
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
 
@@ -13,11 +12,11 @@ export interface NodeElementParams {
13
12
  }
14
13
 
15
14
  class NodeElement {
15
+ public element: HTMLElement;
16
+ public node: Node;
16
17
  private getScrollLeft: GetScrollLeft;
17
18
  private tabIndex?: number;
18
19
  private treeElement: HTMLElement;
19
- public element: HTMLElement;
20
- public node: Node;
21
20
 
22
21
  constructor({
23
22
  getScrollLeft,
@@ -32,21 +31,7 @@ class NodeElement {
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 {
@@ -91,6 +76,20 @@ class NodeElement {
91
76
  titleSpan.focus();
92
77
  }
93
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
+ }
94
93
  }
95
94
 
96
95
  export default NodeElement;
@@ -65,76 +65,6 @@ export default class SaveStateHandler {
65
65
  this.saveStateOption = saveState;
66
66
  }
67
67
 
68
- private getKeyName(): string {
69
- if (typeof this.saveStateOption === "string") {
70
- return this.saveStateOption;
71
- } else {
72
- return "tree";
73
- }
74
- }
75
-
76
- private loadFromStorage(): null | string {
77
- if (this.onGetStateFromStorage) {
78
- return this.onGetStateFromStorage();
79
- } else {
80
- return localStorage.getItem(this.getKeyName());
81
- }
82
- }
83
-
84
- private openInitialNodes(nodeIds: NodeId[]): boolean {
85
- let mustLoadOnDemand = false;
86
-
87
- for (const nodeId of nodeIds) {
88
- const node = this.getNodeById(nodeId);
89
-
90
- if (node) {
91
- if (!node.load_on_demand) {
92
- node.is_open = true;
93
- } else {
94
- mustLoadOnDemand = true;
95
- }
96
- }
97
- }
98
-
99
- return mustLoadOnDemand;
100
- }
101
-
102
- private parseState(jsonData: string): SavedState {
103
- const state = JSON.parse(jsonData) as Record<string, unknown>;
104
-
105
- // Check if selected_node is an int (instead of an array)
106
- if (state.selected_node && isInt(state.selected_node)) {
107
- // Convert to array
108
- state.selected_node = [state.selected_node];
109
- }
110
-
111
- return state as unknown as SavedState;
112
- }
113
-
114
- private resetSelection(): void {
115
- const selectedNodes = this.getSelectedNodes();
116
-
117
- selectedNodes.forEach((node) => {
118
- this.removeFromSelection(node);
119
- });
120
- }
121
-
122
- private selectInitialNodes(nodeIds: NodeId[]): boolean {
123
- let selectCount = 0;
124
-
125
- for (const nodeId of nodeIds) {
126
- const node = this.getNodeById(nodeId);
127
-
128
- if (node) {
129
- selectCount += 1;
130
-
131
- this.addToSelection(node);
132
- }
133
- }
134
-
135
- return selectCount !== 0;
136
- }
137
-
138
68
  public getNodeIdToBeSelected(): NodeId | null {
139
69
  const state = this.getStateFromStorage();
140
70
 
@@ -272,4 +202,74 @@ export default class SaveStateHandler {
272
202
 
273
203
  openNodes();
274
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
+ }
275
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
  }
@@ -1,31 +1,3 @@
1
- type NodeId = number | string;
2
-
3
- interface NodeRecord {
4
- [key: string]: unknown;
5
- children?: NodeData[];
6
- id?: NodeId;
7
- }
8
-
9
- type NodeData = NodeRecord | string;
10
-
11
- type IterateCallback = (node: INode, level: number) => boolean;
12
-
13
- interface INode {
14
- [key: string]: unknown;
15
- children: INode[];
16
- element?: HTMLElement;
17
- id?: NodeId;
18
- is_open: boolean;
19
- iterate(callback: IterateCallback): void;
20
-
21
- name: string;
22
-
23
- parent: INode | null;
24
- }
25
-
26
- type DataUrlFunction = (node?: Node) => JQuery.AjaxSettings;
27
- type DataUrl = DataUrlFunction | JQuery.AjaxSettings | string;
28
-
29
1
  interface ClickNodeEvent {
30
2
  click_event: JQuery.ClickEvent;
31
3
  deselected_node?: INode | null;
@@ -33,15 +5,9 @@ interface ClickNodeEvent {
33
5
  previous_node?: INode;
34
6
  }
35
7
 
36
- interface SelectNodeOptions {
37
- mustSetFocus?: boolean;
38
- mustToggle?: boolean;
39
- }
8
+ type DataUrl = DataUrlFunction | JQuery.AjaxSettings | string;
40
9
 
41
- interface SavedState {
42
- open_nodes: NodeId[];
43
- selected_node: NodeId[];
44
- }
10
+ type DataUrlFunction = (node?: Node) => JQuery.AjaxSettings;
45
11
 
46
12
  interface IJQTreeOptions {
47
13
  animationSpeed?: number | string;
@@ -126,7 +92,7 @@ interface IJQTreePlugin {
126
92
  behavior: "moveNode",
127
93
  node: INode,
128
94
  targetNode: INode,
129
- position: string,
95
+ position: "after" | "before" | "inside",
130
96
  ): JQuery;
131
97
  (behavior: "moveUp"): JQuery;
132
98
  (behavior: "openNode", node: INode): JQuery;
@@ -160,6 +126,40 @@ interface IJQTreePlugin {
160
126
  (behavior: "updateNode", node: INode, data: NodeData): JQuery;
161
127
  }
162
128
 
129
+ interface INode {
130
+ [key: string]: unknown;
131
+ children: INode[];
132
+ element?: HTMLElement;
133
+ id?: NodeId;
134
+ is_open: boolean;
135
+ iterate(callback: IterateCallback): void;
136
+
137
+ name: string;
138
+
139
+ parent: INode | null;
140
+ }
141
+ type IterateCallback = (node: INode, level: number) => boolean;
142
+
163
143
  interface JQuery {
164
144
  tree: IJQTreePlugin;
165
145
  }
146
+
147
+ type NodeData = NodeRecord | string;
148
+
149
+ type NodeId = number | string;
150
+
151
+ interface NodeRecord {
152
+ [key: string]: unknown;
153
+ children?: NodeData[];
154
+ id?: NodeId;
155
+ }
156
+
157
+ interface SavedState {
158
+ open_nodes: NodeId[];
159
+ selected_node: NodeId[];
160
+ }
161
+
162
+ interface SelectNodeOptions {
163
+ mustSetFocus?: boolean;
164
+ mustToggle?: boolean;
165
+ }