jqtree 1.8.11 → 1.9.0
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/eslint.config.mjs +21 -7
- package/package.json +40 -46
- package/pnpm-workspace.yaml +4 -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 +30 -22
- package/src/nodeElement/ghostDropHint.ts +24 -24
- package/src/nodeElement/index.ts +13 -12
- package/src/positionUtils.ts +18 -0
- package/src/saveStateHandler.ts +56 -55
- package/src/scrollHandler/containerScrollParent.ts +17 -15
- package/src/scrollHandler/documentScrollParent.ts +23 -22
- package/src/scrollHandler.ts +23 -22
- package/src/selectNodeHandler.ts +28 -28
- package/src/tree.jquery.ts +251 -269
- package/src/util.ts +0 -14
- package/src/version.ts +1 -1
- package/tree.jquery.debug.js +873 -734
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +2 -2
- package/tree.jquery.js.map +1 -1
package/src/tree.jquery.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { HandleFinishedLoading } from "./dataLoader";
|
|
2
|
+
import type { OnFinishOpenNode } from "./jqtreeMethodTypes";
|
|
3
|
+
import type { JQTreeOptions } from "./jqtreeOptions";
|
|
4
|
+
import type { PositionInfo } from "./mouseUtils";
|
|
5
|
+
import type { Position } from "./node";
|
|
6
|
+
import type { SavedState } from "./saveStateHandler";
|
|
7
|
+
|
|
8
|
+
import DataLoader from "./dataLoader";
|
|
2
9
|
import { DragAndDropHandler } from "./dragAndDropHandler";
|
|
3
10
|
import ElementsRenderer from "./elementsRenderer";
|
|
4
|
-
import { OnFinishOpenNode } from "./jqtreeMethodTypes";
|
|
5
|
-
import { JQTreeOptions } from "./jqtreeOptions";
|
|
6
11
|
import KeyHandler from "./keyHandler";
|
|
7
12
|
import MouseHandler from "./mouseHandler";
|
|
8
|
-
import {
|
|
9
|
-
import { Node, Position } from "./node";
|
|
13
|
+
import { Node } from "./node";
|
|
10
14
|
import NodeElement from "./nodeElement";
|
|
11
15
|
import FolderElement from "./nodeElement/folderElement";
|
|
12
|
-
import
|
|
16
|
+
import { getOffsetTop } from "./positionUtils";
|
|
17
|
+
import SaveStateHandler from "./saveStateHandler";
|
|
13
18
|
import ScrollHandler from "./scrollHandler";
|
|
14
19
|
import SelectNodeHandler from "./selectNodeHandler";
|
|
15
20
|
import SimpleWidget from "./simple.widget";
|
|
16
|
-
import { getOffsetTop, isFunction } from "./util";
|
|
17
21
|
import __version__ from "./version";
|
|
18
22
|
|
|
19
23
|
interface SelectNodeOptions {
|
|
@@ -64,18 +68,18 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
64
68
|
useContextMenu: true,
|
|
65
69
|
};
|
|
66
70
|
|
|
67
|
-
private
|
|
68
|
-
private
|
|
69
|
-
private
|
|
70
|
-
|
|
71
|
-
private
|
|
72
|
-
private
|
|
73
|
-
private
|
|
74
|
-
private
|
|
75
|
-
private
|
|
76
|
-
private
|
|
77
|
-
private
|
|
78
|
-
private
|
|
71
|
+
private _dataLoader: DataLoader;
|
|
72
|
+
private _dndHandler: DragAndDropHandler;
|
|
73
|
+
private _element: JQuery;
|
|
74
|
+
private _htmlElement: HTMLElement;
|
|
75
|
+
private _isInitialized: boolean;
|
|
76
|
+
private _keyHandler: KeyHandler;
|
|
77
|
+
private _mouseHandler: MouseHandler;
|
|
78
|
+
private _renderer: ElementsRenderer;
|
|
79
|
+
private _saveStateHandler: SaveStateHandler;
|
|
80
|
+
private _scrollHandler: ScrollHandler;
|
|
81
|
+
private _selectNodeHandler: SelectNodeHandler;
|
|
82
|
+
private _tree: Node;
|
|
79
83
|
|
|
80
84
|
public addNodeAfter(
|
|
81
85
|
newNodeInfo: NodeData,
|
|
@@ -84,7 +88,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
84
88
|
const newNode = existingNode.addAfter(newNodeInfo);
|
|
85
89
|
|
|
86
90
|
if (newNode) {
|
|
87
|
-
this.
|
|
91
|
+
this._refreshElements(existingNode.parent);
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
return newNode;
|
|
@@ -101,7 +105,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
101
105
|
const newNode = existingNode.addBefore(newNodeInfo);
|
|
102
106
|
|
|
103
107
|
if (newNode) {
|
|
104
|
-
this.
|
|
108
|
+
this._refreshElements(existingNode.parent);
|
|
105
109
|
}
|
|
106
110
|
|
|
107
111
|
return newNode;
|
|
@@ -118,7 +122,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
118
122
|
const newNode = existingNode.addParent(newNodeInfo);
|
|
119
123
|
|
|
120
124
|
if (newNode) {
|
|
121
|
-
this.
|
|
125
|
+
this._refreshElements(newNode.parent);
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
return newNode;
|
|
@@ -129,22 +133,22 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
129
133
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
130
134
|
}
|
|
131
135
|
|
|
132
|
-
this.
|
|
133
|
-
this.
|
|
136
|
+
this._selectNodeHandler.addToSelection(node);
|
|
137
|
+
this._openParents(node);
|
|
134
138
|
|
|
135
|
-
this.
|
|
139
|
+
this._getNodeElementForNode(node).select(mustSetFocus ?? true);
|
|
136
140
|
|
|
137
|
-
this.
|
|
141
|
+
this._saveState();
|
|
138
142
|
|
|
139
|
-
return this.
|
|
143
|
+
return this._element;
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
public appendNode(newNodeInfo: NodeData, parentNodeParam?: Node): Node {
|
|
143
|
-
const parentNode = parentNodeParam ?? this.
|
|
147
|
+
const parentNode = parentNodeParam ?? this._tree;
|
|
144
148
|
|
|
145
149
|
const node = parentNode.append(newNodeInfo);
|
|
146
150
|
|
|
147
|
-
this.
|
|
151
|
+
this._refreshElements(parentNode);
|
|
148
152
|
|
|
149
153
|
return node;
|
|
150
154
|
}
|
|
@@ -157,31 +161,31 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
157
161
|
const slide = slideParam ?? this.options.slide;
|
|
158
162
|
|
|
159
163
|
if (node.isFolder() || node.isEmptyFolder) {
|
|
160
|
-
this.
|
|
164
|
+
this._createFolderElement(node).close(
|
|
161
165
|
slide,
|
|
162
166
|
this.options.animationSpeed,
|
|
163
167
|
);
|
|
164
168
|
|
|
165
|
-
this.
|
|
169
|
+
this._saveState();
|
|
166
170
|
}
|
|
167
171
|
|
|
168
|
-
return this.
|
|
172
|
+
return this._element;
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
public deinit(): void {
|
|
172
|
-
this.
|
|
173
|
-
this.
|
|
176
|
+
this._htmlElement.textContent = "";
|
|
177
|
+
this._element.off();
|
|
174
178
|
|
|
175
|
-
this.
|
|
176
|
-
this.
|
|
179
|
+
this._keyHandler.deinit();
|
|
180
|
+
this._mouseHandler.deinit();
|
|
177
181
|
|
|
178
|
-
this.
|
|
182
|
+
this._tree = new Node({}, true);
|
|
179
183
|
|
|
180
184
|
super.deinit();
|
|
181
185
|
}
|
|
182
186
|
|
|
183
187
|
public getNodeByCallback(callback: (node: Node) => boolean): Node | null {
|
|
184
|
-
return this.
|
|
188
|
+
return this._tree.getNodeByCallback(callback);
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
public getNodeByHtmlElement(
|
|
@@ -196,43 +200,43 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
196
200
|
return null;
|
|
197
201
|
}
|
|
198
202
|
|
|
199
|
-
return this.
|
|
203
|
+
return this._getNode(element);
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
public getNodeById(nodeId: NodeId): Node | null {
|
|
203
|
-
return this.
|
|
207
|
+
return this._tree.getNodeById(nodeId);
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
public getNodeByName(name: string): Node | null {
|
|
207
|
-
return this.
|
|
211
|
+
return this._tree.getNodeByName(name);
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
public getNodeByNameMustExist(name: string): Node {
|
|
211
|
-
return this.
|
|
215
|
+
return this._tree.getNodeByNameMustExist(name);
|
|
212
216
|
}
|
|
213
217
|
|
|
214
218
|
public getNodesByProperty(key: string, value: unknown): Node[] {
|
|
215
|
-
return this.
|
|
219
|
+
return this._tree.getNodesByProperty(key, value);
|
|
216
220
|
}
|
|
217
221
|
|
|
218
222
|
public getSelectedNode(): false | Node {
|
|
219
|
-
return this.
|
|
223
|
+
return this._selectNodeHandler.getSelectedNode();
|
|
220
224
|
}
|
|
221
225
|
|
|
222
226
|
public getSelectedNodes(): Node[] {
|
|
223
|
-
return this.
|
|
227
|
+
return this._selectNodeHandler.getSelectedNodes();
|
|
224
228
|
}
|
|
225
229
|
|
|
226
230
|
public getState(): null | SavedState {
|
|
227
|
-
return this.
|
|
231
|
+
return this._saveStateHandler.getState();
|
|
228
232
|
}
|
|
229
233
|
|
|
230
234
|
public getStateFromStorage(): null | SavedState {
|
|
231
|
-
return this.
|
|
235
|
+
return this._saveStateHandler.getStateFromStorage();
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
public getTree(): Node {
|
|
235
|
-
return this.
|
|
239
|
+
return this._tree;
|
|
236
240
|
}
|
|
237
241
|
|
|
238
242
|
public getVersion(): string {
|
|
@@ -242,20 +246,23 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
242
246
|
public init(): void {
|
|
243
247
|
super.init();
|
|
244
248
|
|
|
245
|
-
this.
|
|
246
|
-
this.
|
|
249
|
+
this._element = this.$el;
|
|
250
|
+
this._htmlElement = this._element.get(0) as HTMLElement;
|
|
251
|
+
this._isInitialized = false;
|
|
247
252
|
|
|
248
|
-
this.options.
|
|
253
|
+
this.options.dataUrl ??= this._element.data("url");
|
|
249
254
|
|
|
250
|
-
|
|
255
|
+
const dataRtl = this._element.data("rtl") as unknown;
|
|
256
|
+
this.options.rtl ??= dataRtl === '' ? true : Boolean(dataRtl);
|
|
251
257
|
|
|
252
|
-
this.
|
|
258
|
+
this.options.closedIcon ??= this._getDefaultClosedIcon();
|
|
253
259
|
|
|
254
|
-
this.
|
|
260
|
+
this._connectHandlers();
|
|
261
|
+
this._initData();
|
|
255
262
|
}
|
|
256
263
|
|
|
257
264
|
public isDragging(): boolean {
|
|
258
|
-
return this.
|
|
265
|
+
return this._dndHandler.isDragging;
|
|
259
266
|
}
|
|
260
267
|
|
|
261
268
|
public isNodeSelected(node?: Node): boolean {
|
|
@@ -263,12 +270,12 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
263
270
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
264
271
|
}
|
|
265
272
|
|
|
266
|
-
return this.
|
|
273
|
+
return this._selectNodeHandler.isNodeSelected(node);
|
|
267
274
|
}
|
|
268
275
|
|
|
269
276
|
public loadData(data: NodeData[], parentNode: Node | null): JQuery {
|
|
270
|
-
this.
|
|
271
|
-
return this.
|
|
277
|
+
this._doLoadData(data, parentNode);
|
|
278
|
+
return this._element;
|
|
272
279
|
}
|
|
273
280
|
|
|
274
281
|
/*
|
|
@@ -292,30 +299,30 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
292
299
|
): JQuery {
|
|
293
300
|
if (typeof param1 === "string") {
|
|
294
301
|
// first parameter is url
|
|
295
|
-
this.
|
|
302
|
+
this._doLoadDataFromUrl(
|
|
296
303
|
param1,
|
|
297
304
|
param2 as Node | null,
|
|
298
305
|
param3 ?? null,
|
|
299
306
|
);
|
|
300
307
|
} else {
|
|
301
308
|
// first parameter is not url
|
|
302
|
-
this.
|
|
309
|
+
this._doLoadDataFromUrl(
|
|
303
310
|
null,
|
|
304
311
|
param1,
|
|
305
312
|
param2 as HandleFinishedLoading | null,
|
|
306
313
|
);
|
|
307
314
|
}
|
|
308
315
|
|
|
309
|
-
return this.
|
|
316
|
+
return this._element;
|
|
310
317
|
}
|
|
311
318
|
|
|
312
319
|
public moveDown(): JQuery {
|
|
313
320
|
const selectedNode = this.getSelectedNode();
|
|
314
321
|
if (selectedNode) {
|
|
315
|
-
this.
|
|
322
|
+
this._keyHandler.moveDown(selectedNode);
|
|
316
323
|
}
|
|
317
324
|
|
|
318
|
-
return this.
|
|
325
|
+
return this._element;
|
|
319
326
|
}
|
|
320
327
|
|
|
321
328
|
public moveNode(
|
|
@@ -335,19 +342,19 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
335
342
|
throw Error(PARAM_IS_EMPTY + "position");
|
|
336
343
|
}
|
|
337
344
|
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
345
|
+
this._tree.moveNode(node, targetNode, position);
|
|
346
|
+
this._refreshElements(null);
|
|
340
347
|
|
|
341
|
-
return this.
|
|
348
|
+
return this._element;
|
|
342
349
|
}
|
|
343
350
|
|
|
344
351
|
public moveUp(): JQuery {
|
|
345
352
|
const selectedNode = this.getSelectedNode();
|
|
346
353
|
if (selectedNode) {
|
|
347
|
-
this.
|
|
354
|
+
this._keyHandler.moveUp(selectedNode);
|
|
348
355
|
}
|
|
349
356
|
|
|
350
|
-
return this.
|
|
357
|
+
return this._element;
|
|
351
358
|
}
|
|
352
359
|
|
|
353
360
|
public openNode(
|
|
@@ -363,8 +370,8 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
363
370
|
let onFinished: null | OnFinishOpenNode;
|
|
364
371
|
let slide: boolean | null;
|
|
365
372
|
|
|
366
|
-
if (
|
|
367
|
-
onFinished = param1
|
|
373
|
+
if (typeof param1 === "function") {
|
|
374
|
+
onFinished = param1;
|
|
368
375
|
slide = null;
|
|
369
376
|
} else {
|
|
370
377
|
slide = param1 as boolean;
|
|
@@ -378,33 +385,28 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
378
385
|
|
|
379
386
|
const [slide, onFinished] = parseParams();
|
|
380
387
|
|
|
381
|
-
this.
|
|
382
|
-
return this.
|
|
388
|
+
this._openNodeInternal(node, slide, onFinished);
|
|
389
|
+
return this._element;
|
|
383
390
|
}
|
|
384
391
|
|
|
385
392
|
public prependNode(newNodeInfo: NodeData, parentNodeParam?: Node): Node {
|
|
386
|
-
const parentNode = parentNodeParam ?? this.
|
|
393
|
+
const parentNode = parentNodeParam ?? this._tree;
|
|
387
394
|
|
|
388
395
|
const node = parentNode.prepend(newNodeInfo);
|
|
389
396
|
|
|
390
|
-
this.
|
|
397
|
+
this._refreshElements(parentNode);
|
|
391
398
|
|
|
392
399
|
return node;
|
|
393
400
|
}
|
|
394
401
|
|
|
395
402
|
public refresh(): JQuery {
|
|
396
|
-
this.
|
|
397
|
-
return this.
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
public refreshHitAreas(): JQuery {
|
|
401
|
-
this.dndHandler.refresh();
|
|
402
|
-
return this.element;
|
|
403
|
+
this._refreshElements(null);
|
|
404
|
+
return this._element;
|
|
403
405
|
}
|
|
404
406
|
|
|
405
407
|
public reload(onFinished: HandleFinishedLoading | null): JQuery {
|
|
406
|
-
this.
|
|
407
|
-
return this.
|
|
408
|
+
this._doLoadDataFromUrl(null, null, onFinished);
|
|
409
|
+
return this._element;
|
|
408
410
|
}
|
|
409
411
|
|
|
410
412
|
public removeFromSelection(node?: Node): JQuery {
|
|
@@ -412,12 +414,12 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
412
414
|
throw Error(NODE_PARAM_IS_EMPTY);
|
|
413
415
|
}
|
|
414
416
|
|
|
415
|
-
this.
|
|
417
|
+
this._selectNodeHandler.removeFromSelection(node);
|
|
416
418
|
|
|
417
|
-
this.
|
|
418
|
-
this.
|
|
419
|
+
this._getNodeElementForNode(node).deselect();
|
|
420
|
+
this._saveState();
|
|
419
421
|
|
|
420
|
-
return this.
|
|
422
|
+
return this._element;
|
|
421
423
|
}
|
|
422
424
|
|
|
423
425
|
public removeNode(node?: Node): JQuery {
|
|
@@ -429,13 +431,13 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
429
431
|
throw Error("Node has no parent");
|
|
430
432
|
}
|
|
431
433
|
|
|
432
|
-
this.
|
|
434
|
+
this._selectNodeHandler.removeFromSelection(node, true); // including children
|
|
433
435
|
|
|
434
436
|
const parent = node.parent;
|
|
435
437
|
node.remove();
|
|
436
|
-
this.
|
|
438
|
+
this._refreshElements(parent);
|
|
437
439
|
|
|
438
|
-
return this.
|
|
440
|
+
return this._element;
|
|
439
441
|
}
|
|
440
442
|
|
|
441
443
|
public scrollToNode(node?: Node): JQuery {
|
|
@@ -444,38 +446,38 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
444
446
|
}
|
|
445
447
|
|
|
446
448
|
if (!node.element) {
|
|
447
|
-
return this.
|
|
449
|
+
return this._element;
|
|
448
450
|
}
|
|
449
451
|
|
|
450
452
|
const top =
|
|
451
453
|
getOffsetTop(node.element) -
|
|
452
|
-
getOffsetTop(this
|
|
454
|
+
getOffsetTop(this._htmlElement);
|
|
453
455
|
|
|
454
|
-
this.
|
|
456
|
+
this._scrollHandler.scrollToY(top);
|
|
455
457
|
|
|
456
|
-
return this.
|
|
458
|
+
return this._element;
|
|
457
459
|
}
|
|
458
460
|
|
|
459
461
|
public selectNode(
|
|
460
462
|
node: Node | null,
|
|
461
463
|
optionsParam?: SelectNodeOptions,
|
|
462
464
|
): JQuery {
|
|
463
|
-
this.
|
|
464
|
-
return this.
|
|
465
|
+
this._doSelectNode(node, optionsParam);
|
|
466
|
+
return this._element;
|
|
465
467
|
}
|
|
466
468
|
|
|
467
469
|
public setOption(option: string, value: unknown): JQuery {
|
|
468
470
|
(this.options as unknown as Record<string, unknown>)[option] = value;
|
|
469
|
-
return this.
|
|
471
|
+
return this._element;
|
|
470
472
|
}
|
|
471
473
|
|
|
472
474
|
public setState(state?: SavedState): JQuery {
|
|
473
475
|
if (state) {
|
|
474
|
-
this.
|
|
475
|
-
this.
|
|
476
|
+
this._saveStateHandler.setInitialState(state);
|
|
477
|
+
this._refreshElements(null);
|
|
476
478
|
}
|
|
477
479
|
|
|
478
|
-
return this.
|
|
480
|
+
return this._element;
|
|
479
481
|
}
|
|
480
482
|
|
|
481
483
|
public toggle(node?: Node, slideParam: boolean | null = null): JQuery {
|
|
@@ -491,11 +493,11 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
491
493
|
this.openNode(node, slide);
|
|
492
494
|
}
|
|
493
495
|
|
|
494
|
-
return this.
|
|
496
|
+
return this._element;
|
|
495
497
|
}
|
|
496
498
|
|
|
497
499
|
public toJson(): string {
|
|
498
|
-
return JSON.stringify(this.
|
|
500
|
+
return JSON.stringify(this._tree.getData());
|
|
499
501
|
}
|
|
500
502
|
|
|
501
503
|
public updateNode(node?: Node, data?: NodeData): JQuery {
|
|
@@ -504,20 +506,20 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
504
506
|
}
|
|
505
507
|
|
|
506
508
|
if (!data) {
|
|
507
|
-
return this.
|
|
509
|
+
return this._element;
|
|
508
510
|
}
|
|
509
511
|
|
|
510
512
|
const idIsChanged =
|
|
511
513
|
typeof data === "object" && data.id && data.id !== node.id;
|
|
512
514
|
|
|
513
515
|
if (idIsChanged) {
|
|
514
|
-
this.
|
|
516
|
+
this._tree.removeNodeFromIndex(node);
|
|
515
517
|
}
|
|
516
518
|
|
|
517
519
|
node.setData(data);
|
|
518
520
|
|
|
519
521
|
if (idIsChanged) {
|
|
520
|
-
this.
|
|
522
|
+
this._tree.addNodeToIndex(node);
|
|
521
523
|
}
|
|
522
524
|
|
|
523
525
|
if (
|
|
@@ -528,16 +530,16 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
528
530
|
node.removeChildren();
|
|
529
531
|
|
|
530
532
|
if (data.children.length) {
|
|
531
|
-
node.loadFromData(data.children
|
|
533
|
+
node.loadFromData(data.children);
|
|
532
534
|
}
|
|
533
535
|
}
|
|
534
536
|
|
|
535
|
-
this.
|
|
537
|
+
this._refreshElements(node);
|
|
536
538
|
|
|
537
|
-
return this.
|
|
539
|
+
return this._element;
|
|
538
540
|
}
|
|
539
541
|
|
|
540
|
-
private
|
|
542
|
+
private _connectHandlers() {
|
|
541
543
|
const {
|
|
542
544
|
autoEscape,
|
|
543
545
|
buttonLeft,
|
|
@@ -565,20 +567,18 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
565
567
|
} = this.options;
|
|
566
568
|
|
|
567
569
|
const closeNode = this.closeNode.bind(this);
|
|
568
|
-
const getNodeElement = this.
|
|
569
|
-
const getNodeElementForNode = this.
|
|
570
|
+
const getNodeElement = this._getNodeElement.bind(this);
|
|
571
|
+
const getNodeElementForNode = this._getNodeElementForNode.bind(this);
|
|
570
572
|
const getNodeById = this.getNodeById.bind(this);
|
|
571
573
|
const getSelectedNode = this.getSelectedNode.bind(this);
|
|
572
574
|
const getTree = this.getTree.bind(this);
|
|
573
|
-
const isFocusOnTree = this.
|
|
575
|
+
const isFocusOnTree = this._isFocusOnTree.bind(this);
|
|
574
576
|
const loadData = this.loadData.bind(this);
|
|
575
|
-
const openNode = this.
|
|
576
|
-
const refreshElements = this.
|
|
577
|
-
const refreshHitAreas = this.refreshHitAreas.bind(this);
|
|
577
|
+
const openNode = this._openNodeInternal.bind(this);
|
|
578
|
+
const refreshElements = this._refreshElements.bind(this);
|
|
578
579
|
const selectNode = this.selectNode.bind(this);
|
|
579
|
-
const
|
|
580
|
-
const
|
|
581
|
-
const triggerEvent = this.triggerEvent.bind(this);
|
|
580
|
+
const treeElement = this._htmlElement;
|
|
581
|
+
const triggerEvent = this._triggerEvent.bind(this);
|
|
582
582
|
|
|
583
583
|
const selectNodeHandler = new SelectNodeHandler({
|
|
584
584
|
getNodeById,
|
|
@@ -594,6 +594,10 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
594
594
|
selectNodeHandler.removeFromSelection.bind(selectNodeHandler);
|
|
595
595
|
const getMouseDelay = () => this.options.startDndDelay ?? 0;
|
|
596
596
|
|
|
597
|
+
const refreshHitAreas = () => {
|
|
598
|
+
dndHandler.refresh();
|
|
599
|
+
}
|
|
600
|
+
|
|
597
601
|
const dataLoader = new DataLoader({
|
|
598
602
|
dataFilter,
|
|
599
603
|
loadData,
|
|
@@ -652,12 +656,12 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
652
656
|
});
|
|
653
657
|
|
|
654
658
|
const renderer = new ElementsRenderer({
|
|
655
|
-
$element: $treeElement,
|
|
656
659
|
autoEscape,
|
|
657
660
|
buttonLeft,
|
|
658
661
|
closedIcon,
|
|
659
662
|
dragAndDrop,
|
|
660
663
|
getTree,
|
|
664
|
+
htmlElement: treeElement,
|
|
661
665
|
isNodeSelected,
|
|
662
666
|
onCreateLi,
|
|
663
667
|
openedIcon,
|
|
@@ -666,18 +670,18 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
666
670
|
tabIndex,
|
|
667
671
|
});
|
|
668
672
|
|
|
669
|
-
const getNode = this.
|
|
670
|
-
const onMouseCapture = this.
|
|
671
|
-
const onMouseDrag = this.
|
|
672
|
-
const onMouseStart = this.
|
|
673
|
-
const onMouseStop = this.
|
|
673
|
+
const getNode = this._getNode.bind(this);
|
|
674
|
+
const onMouseCapture = this._mouseCapture.bind(this);
|
|
675
|
+
const onMouseDrag = this._mouseDrag.bind(this);
|
|
676
|
+
const onMouseStart = this._mouseStart.bind(this);
|
|
677
|
+
const onMouseStop = this._mouseStop.bind(this);
|
|
674
678
|
|
|
675
679
|
const mouseHandler = new MouseHandler({
|
|
676
680
|
element: treeElement,
|
|
677
681
|
getMouseDelay,
|
|
678
682
|
getNode,
|
|
679
683
|
onClickButton: this.toggle.bind(this),
|
|
680
|
-
onClickTitle: this.
|
|
684
|
+
onClickTitle: this._doSelectNode.bind(this),
|
|
681
685
|
onMouseCapture,
|
|
682
686
|
onMouseDrag,
|
|
683
687
|
onMouseStart,
|
|
@@ -686,31 +690,30 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
686
690
|
useContextMenu: this.options.useContextMenu,
|
|
687
691
|
});
|
|
688
692
|
|
|
689
|
-
this.
|
|
690
|
-
this.
|
|
691
|
-
this.
|
|
692
|
-
this.
|
|
693
|
-
this.
|
|
694
|
-
this.
|
|
695
|
-
this.
|
|
696
|
-
this.
|
|
693
|
+
this._dataLoader = dataLoader;
|
|
694
|
+
this._dndHandler = dndHandler;
|
|
695
|
+
this._keyHandler = keyHandler;
|
|
696
|
+
this._mouseHandler = mouseHandler;
|
|
697
|
+
this._renderer = renderer;
|
|
698
|
+
this._saveStateHandler = saveStateHandler;
|
|
699
|
+
this._scrollHandler = scrollHandler;
|
|
700
|
+
this._selectNodeHandler = selectNodeHandler;
|
|
697
701
|
}
|
|
698
702
|
|
|
699
|
-
private
|
|
700
|
-
const node = this.
|
|
703
|
+
private _containsElement(element: HTMLElement): boolean {
|
|
704
|
+
const node = this._getNode(element);
|
|
701
705
|
|
|
702
|
-
return node?.tree === this.
|
|
706
|
+
return node?.tree === this._tree;
|
|
703
707
|
}
|
|
704
708
|
|
|
705
|
-
private
|
|
706
|
-
const closedIconElement = this.
|
|
707
|
-
const getScrollLeft = this.
|
|
708
|
-
this.
|
|
709
|
+
private _createFolderElement(node: Node) {
|
|
710
|
+
const closedIconElement = this._renderer.closedIconElement;
|
|
711
|
+
const getScrollLeft = this._scrollHandler.getScrollLeft.bind(
|
|
712
|
+
this._scrollHandler,
|
|
709
713
|
);
|
|
710
|
-
const openedIconElement = this.
|
|
714
|
+
const openedIconElement = this._renderer.openedIconElement;
|
|
711
715
|
const tabIndex = this.options.tabIndex;
|
|
712
|
-
const
|
|
713
|
-
const triggerEvent = this.triggerEvent.bind(this);
|
|
716
|
+
const triggerEvent = this._triggerEvent.bind(this);
|
|
714
717
|
|
|
715
718
|
return new FolderElement({
|
|
716
719
|
closedIconElement,
|
|
@@ -718,84 +721,83 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
718
721
|
node,
|
|
719
722
|
openedIconElement,
|
|
720
723
|
tabIndex,
|
|
721
|
-
treeElement,
|
|
724
|
+
treeElement: this._htmlElement,
|
|
722
725
|
triggerEvent,
|
|
723
726
|
});
|
|
724
727
|
}
|
|
725
728
|
|
|
726
|
-
private
|
|
727
|
-
const getScrollLeft = this.
|
|
728
|
-
this.
|
|
729
|
+
private _createNodeElement(node: Node) {
|
|
730
|
+
const getScrollLeft = this._scrollHandler.getScrollLeft.bind(
|
|
731
|
+
this._scrollHandler,
|
|
729
732
|
);
|
|
730
733
|
const tabIndex = this.options.tabIndex;
|
|
731
|
-
const treeElement = this.element.get(0) as HTMLElement;
|
|
732
734
|
|
|
733
735
|
return new NodeElement({
|
|
734
736
|
getScrollLeft,
|
|
735
737
|
node,
|
|
736
738
|
tabIndex,
|
|
737
|
-
treeElement
|
|
739
|
+
treeElement: this._htmlElement
|
|
738
740
|
});
|
|
739
741
|
}
|
|
740
742
|
|
|
741
|
-
private
|
|
743
|
+
private _deselectCurrentNode(): void {
|
|
742
744
|
const node = this.getSelectedNode();
|
|
743
745
|
if (node) {
|
|
744
746
|
this.removeFromSelection(node);
|
|
745
747
|
}
|
|
746
748
|
}
|
|
747
749
|
|
|
748
|
-
private
|
|
750
|
+
private _deselectNodes(parentNode: Node): void {
|
|
749
751
|
const selectedNodesUnderParent =
|
|
750
|
-
this.
|
|
752
|
+
this._selectNodeHandler.getSelectedNodesUnder(parentNode);
|
|
751
753
|
for (const n of selectedNodesUnderParent) {
|
|
752
|
-
this.
|
|
754
|
+
this._selectNodeHandler.removeFromSelection(n);
|
|
753
755
|
}
|
|
754
756
|
}
|
|
755
757
|
|
|
756
|
-
private
|
|
758
|
+
private _doLoadData(data: NodeData[] | null, parentNode: Node | null): void {
|
|
757
759
|
if (data) {
|
|
758
760
|
if (parentNode) {
|
|
759
|
-
this.
|
|
760
|
-
this.
|
|
761
|
+
this._deselectNodes(parentNode);
|
|
762
|
+
this._loadSubtree(data, parentNode);
|
|
761
763
|
} else {
|
|
762
|
-
this.
|
|
764
|
+
this._initTree(data);
|
|
763
765
|
}
|
|
764
766
|
|
|
765
767
|
if (this.isDragging()) {
|
|
766
|
-
this.
|
|
768
|
+
this._dndHandler.refresh();
|
|
767
769
|
}
|
|
768
770
|
}
|
|
769
771
|
|
|
770
|
-
this.
|
|
772
|
+
this._triggerEvent("tree.load_data", {
|
|
771
773
|
parent_node: parentNode,
|
|
772
774
|
tree_data: data,
|
|
773
775
|
});
|
|
774
776
|
}
|
|
775
777
|
|
|
776
|
-
private
|
|
778
|
+
private _doLoadDataFromUrl(
|
|
777
779
|
urlInfoParam: JQuery.AjaxSettings | null | string,
|
|
778
780
|
parentNode: Node | null,
|
|
779
781
|
onFinished: HandleFinishedLoading | null,
|
|
780
782
|
): void {
|
|
781
|
-
const urlInfo = urlInfoParam ?? this.
|
|
783
|
+
const urlInfo = urlInfoParam ?? this._getDataUrlInfo(parentNode);
|
|
782
784
|
|
|
783
|
-
this.
|
|
785
|
+
this._dataLoader.loadFromUrl(urlInfo, parentNode, onFinished);
|
|
784
786
|
}
|
|
785
787
|
|
|
786
|
-
private
|
|
788
|
+
private _doSelectNode(
|
|
787
789
|
node: Node | null,
|
|
788
790
|
optionsParam?: SelectNodeOptions,
|
|
789
791
|
): void {
|
|
790
792
|
const saveState = (): void => {
|
|
791
793
|
if (this.options.saveState) {
|
|
792
|
-
this.
|
|
794
|
+
this._saveStateHandler.saveState();
|
|
793
795
|
}
|
|
794
796
|
};
|
|
795
797
|
|
|
796
798
|
if (!node) {
|
|
797
799
|
// Called with empty node -> deselect current node
|
|
798
|
-
this.
|
|
800
|
+
this._deselectCurrentNode();
|
|
799
801
|
saveState();
|
|
800
802
|
return;
|
|
801
803
|
}
|
|
@@ -817,30 +819,30 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
817
819
|
return;
|
|
818
820
|
}
|
|
819
821
|
|
|
820
|
-
if (this.
|
|
822
|
+
if (this._selectNodeHandler.isNodeSelected(node)) {
|
|
821
823
|
if (selectOptions.mustToggle) {
|
|
822
|
-
this.
|
|
823
|
-
this.
|
|
824
|
+
this._deselectCurrentNode();
|
|
825
|
+
this._triggerEvent("tree.select", {
|
|
824
826
|
node: null,
|
|
825
827
|
previous_node: node,
|
|
826
828
|
});
|
|
827
829
|
}
|
|
828
830
|
} else {
|
|
829
831
|
const deselectedNode = this.getSelectedNode() || null;
|
|
830
|
-
this.
|
|
832
|
+
this._deselectCurrentNode();
|
|
831
833
|
this.addToSelection(node, selectOptions.mustSetFocus);
|
|
832
834
|
|
|
833
|
-
this.
|
|
835
|
+
this._triggerEvent("tree.select", {
|
|
834
836
|
deselected_node: deselectedNode,
|
|
835
837
|
node,
|
|
836
838
|
});
|
|
837
|
-
this.
|
|
839
|
+
this._openParents(node);
|
|
838
840
|
}
|
|
839
841
|
|
|
840
842
|
saveState();
|
|
841
843
|
}
|
|
842
844
|
|
|
843
|
-
private
|
|
845
|
+
private _getAutoOpenMaxLevel(): number {
|
|
844
846
|
if (this.options.autoOpen === true) {
|
|
845
847
|
return -1;
|
|
846
848
|
} else if (typeof this.options.autoOpen === "number") {
|
|
@@ -852,10 +854,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
852
854
|
}
|
|
853
855
|
}
|
|
854
856
|
|
|
855
|
-
private
|
|
856
|
-
const dataUrl =
|
|
857
|
-
this.options.dataUrl ?? (this.element.data("url") as null | string);
|
|
858
|
-
|
|
857
|
+
private _getDataUrlInfo(node: Node | null): JQuery.AjaxSettings | null {
|
|
859
858
|
const getUrlFromString = (url: string): JQuery.AjaxSettings => {
|
|
860
859
|
const urlInfo: JQuery.AjaxSettings = { url };
|
|
861
860
|
|
|
@@ -871,7 +870,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
871
870
|
urlInfo.data = data;
|
|
872
871
|
} else {
|
|
873
872
|
// Add selected_node parameter
|
|
874
|
-
const selectedNodeId = this.
|
|
873
|
+
const selectedNodeId = this._getNodeIdToBeSelected();
|
|
875
874
|
if (selectedNodeId) {
|
|
876
875
|
const data = { selected_node: selectedNodeId };
|
|
877
876
|
urlInfo.data = data;
|
|
@@ -879,6 +878,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
879
878
|
}
|
|
880
879
|
};
|
|
881
880
|
|
|
881
|
+
const dataUrl = this.options.dataUrl;
|
|
882
882
|
if (typeof dataUrl === "function") {
|
|
883
883
|
return dataUrl(node);
|
|
884
884
|
} else if (typeof dataUrl === "string") {
|
|
@@ -891,7 +891,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
891
891
|
}
|
|
892
892
|
}
|
|
893
893
|
|
|
894
|
-
private
|
|
894
|
+
private _getDefaultClosedIcon(): string {
|
|
895
895
|
if (this.options.rtl) {
|
|
896
896
|
// triangle to the left
|
|
897
897
|
return "◀";
|
|
@@ -901,7 +901,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
|
|
904
|
-
private
|
|
904
|
+
private _getNode(element: HTMLElement): Node | null {
|
|
905
905
|
const liElement = element.closest("li.jqtree_common");
|
|
906
906
|
|
|
907
907
|
if (liElement) {
|
|
@@ -911,100 +911,82 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
911
911
|
}
|
|
912
912
|
}
|
|
913
913
|
|
|
914
|
-
private
|
|
915
|
-
const node = this.
|
|
914
|
+
private _getNodeElement(element: HTMLElement): NodeElement | null {
|
|
915
|
+
const node = this._getNode(element);
|
|
916
916
|
if (node) {
|
|
917
|
-
return this.
|
|
917
|
+
return this._getNodeElementForNode(node);
|
|
918
918
|
} else {
|
|
919
919
|
return null;
|
|
920
920
|
}
|
|
921
921
|
}
|
|
922
922
|
|
|
923
|
-
private
|
|
923
|
+
private _getNodeElementForNode(node: Node): NodeElement {
|
|
924
924
|
if (node.isFolder()) {
|
|
925
|
-
return this.
|
|
925
|
+
return this._createFolderElement(node);
|
|
926
926
|
} else {
|
|
927
|
-
return this.
|
|
927
|
+
return this._createNodeElement(node);
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
930
|
|
|
931
|
-
private
|
|
931
|
+
private _getNodeIdToBeSelected(): NodeId | null {
|
|
932
932
|
if (this.options.saveState) {
|
|
933
|
-
return this.
|
|
933
|
+
return this._saveStateHandler.getNodeIdToBeSelected();
|
|
934
934
|
} else {
|
|
935
935
|
return null;
|
|
936
936
|
}
|
|
937
937
|
}
|
|
938
938
|
|
|
939
|
-
private
|
|
940
|
-
if (this.options.rtl != null) {
|
|
941
|
-
return this.options.rtl;
|
|
942
|
-
} else {
|
|
943
|
-
const dataRtl = this.element.data("rtl") as unknown;
|
|
944
|
-
|
|
945
|
-
if (
|
|
946
|
-
dataRtl !== null &&
|
|
947
|
-
dataRtl !== false &&
|
|
948
|
-
dataRtl !== undefined
|
|
949
|
-
) {
|
|
950
|
-
return true;
|
|
951
|
-
} else {
|
|
952
|
-
return false;
|
|
953
|
-
}
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
private initData(): void {
|
|
939
|
+
private _initData(): void {
|
|
958
940
|
if (this.options.data) {
|
|
959
|
-
this.
|
|
941
|
+
this._doLoadData(this.options.data, null);
|
|
960
942
|
} else {
|
|
961
|
-
const dataUrl = this.
|
|
943
|
+
const dataUrl = this._getDataUrlInfo(null);
|
|
962
944
|
|
|
963
945
|
if (dataUrl) {
|
|
964
|
-
this.
|
|
946
|
+
this._doLoadDataFromUrl(null, null, null);
|
|
965
947
|
} else {
|
|
966
|
-
this.
|
|
948
|
+
this._doLoadData([], null);
|
|
967
949
|
}
|
|
968
950
|
}
|
|
969
951
|
}
|
|
970
952
|
|
|
971
|
-
private
|
|
953
|
+
private _initTree(data: NodeData[]): void {
|
|
972
954
|
const doInit = (): void => {
|
|
973
|
-
if (!this.
|
|
974
|
-
this.
|
|
975
|
-
this.
|
|
955
|
+
if (!this._isInitialized) {
|
|
956
|
+
this._isInitialized = true;
|
|
957
|
+
this._triggerEvent("tree.init");
|
|
976
958
|
}
|
|
977
959
|
};
|
|
978
960
|
|
|
979
|
-
this.
|
|
961
|
+
this._tree = new this.options.nodeClass(
|
|
980
962
|
null,
|
|
981
963
|
true,
|
|
982
964
|
this.options.nodeClass,
|
|
983
965
|
);
|
|
984
966
|
|
|
985
|
-
this.
|
|
967
|
+
this._selectNodeHandler.clear();
|
|
986
968
|
|
|
987
|
-
this.
|
|
969
|
+
this._tree.loadFromData(data);
|
|
988
970
|
|
|
989
|
-
const mustLoadOnDemand = this.
|
|
971
|
+
const mustLoadOnDemand = this._setInitialState();
|
|
990
972
|
|
|
991
|
-
this.
|
|
973
|
+
this._refreshElements(null);
|
|
992
974
|
|
|
993
975
|
if (!mustLoadOnDemand) {
|
|
994
976
|
doInit();
|
|
995
977
|
} else {
|
|
996
978
|
// Load data on demand and then init the tree
|
|
997
|
-
this.
|
|
979
|
+
this._setInitialStateOnDemand(doInit);
|
|
998
980
|
}
|
|
999
981
|
}
|
|
1000
982
|
|
|
1001
|
-
private
|
|
983
|
+
private _isFocusOnTree(): boolean {
|
|
1002
984
|
const activeElement = document.activeElement;
|
|
1003
985
|
|
|
1004
|
-
return activeElement?.tagName === "SPAN" && this.
|
|
986
|
+
return activeElement?.tagName === "SPAN" && this._containsElement(activeElement as HTMLElement);
|
|
1005
987
|
}
|
|
1006
988
|
|
|
1007
|
-
private
|
|
989
|
+
private _isSelectedNodeInSubtree(subtree: Node): boolean {
|
|
1008
990
|
const selectedNode = this.getSelectedNode();
|
|
1009
991
|
|
|
1010
992
|
if (!selectedNode) {
|
|
@@ -1014,64 +996,64 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1014
996
|
}
|
|
1015
997
|
}
|
|
1016
998
|
|
|
1017
|
-
private
|
|
999
|
+
private _loadFolderOnDemand(
|
|
1018
1000
|
node: Node,
|
|
1019
1001
|
slide = true,
|
|
1020
1002
|
onFinished?: OnFinishOpenNode,
|
|
1021
1003
|
): void {
|
|
1022
1004
|
node.is_loading = true;
|
|
1023
1005
|
|
|
1024
|
-
this.
|
|
1025
|
-
this.
|
|
1006
|
+
this._doLoadDataFromUrl(null, node, () => {
|
|
1007
|
+
this._openNodeInternal(node, slide, onFinished);
|
|
1026
1008
|
});
|
|
1027
1009
|
}
|
|
1028
1010
|
|
|
1029
|
-
private
|
|
1011
|
+
private _loadSubtree(data: NodeData[], parentNode: Node): void {
|
|
1030
1012
|
parentNode.loadFromData(data);
|
|
1031
1013
|
|
|
1032
1014
|
parentNode.load_on_demand = false;
|
|
1033
1015
|
parentNode.is_loading = false;
|
|
1034
1016
|
|
|
1035
|
-
this.
|
|
1017
|
+
this._refreshElements(parentNode);
|
|
1036
1018
|
}
|
|
1037
1019
|
|
|
1038
|
-
private
|
|
1020
|
+
private _mouseCapture(positionInfo: PositionInfo): boolean | null {
|
|
1039
1021
|
if (this.options.dragAndDrop) {
|
|
1040
|
-
return this.
|
|
1022
|
+
return this._dndHandler.mouseCapture(positionInfo);
|
|
1041
1023
|
} else {
|
|
1042
1024
|
return false;
|
|
1043
1025
|
}
|
|
1044
1026
|
}
|
|
1045
1027
|
|
|
1046
|
-
private
|
|
1028
|
+
private _mouseDrag(positionInfo: PositionInfo): boolean {
|
|
1047
1029
|
if (this.options.dragAndDrop) {
|
|
1048
|
-
const result = this.
|
|
1030
|
+
const result = this._dndHandler.mouseDrag(positionInfo);
|
|
1049
1031
|
|
|
1050
|
-
this.
|
|
1032
|
+
this._scrollHandler.checkScrolling(positionInfo);
|
|
1051
1033
|
return result;
|
|
1052
1034
|
} else {
|
|
1053
1035
|
return false;
|
|
1054
1036
|
}
|
|
1055
1037
|
}
|
|
1056
1038
|
|
|
1057
|
-
private
|
|
1039
|
+
private _mouseStart(positionInfo: PositionInfo): boolean {
|
|
1058
1040
|
if (this.options.dragAndDrop) {
|
|
1059
|
-
return this.
|
|
1041
|
+
return this._dndHandler.mouseStart(positionInfo);
|
|
1060
1042
|
} else {
|
|
1061
1043
|
return false;
|
|
1062
1044
|
}
|
|
1063
1045
|
}
|
|
1064
1046
|
|
|
1065
|
-
private
|
|
1047
|
+
private _mouseStop(positionInfo: PositionInfo): boolean {
|
|
1066
1048
|
if (this.options.dragAndDrop) {
|
|
1067
|
-
this.
|
|
1068
|
-
return this.
|
|
1049
|
+
this._scrollHandler.stopScrolling();
|
|
1050
|
+
return this._dndHandler.mouseStop(positionInfo);
|
|
1069
1051
|
} else {
|
|
1070
1052
|
return false;
|
|
1071
1053
|
}
|
|
1072
1054
|
}
|
|
1073
1055
|
|
|
1074
|
-
private
|
|
1056
|
+
private _openNodeInternal(
|
|
1075
1057
|
node: Node,
|
|
1076
1058
|
slide = true,
|
|
1077
1059
|
onFinished?: OnFinishOpenNode,
|
|
@@ -1085,7 +1067,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1085
1067
|
return;
|
|
1086
1068
|
}
|
|
1087
1069
|
|
|
1088
|
-
const folderElement = this.
|
|
1070
|
+
const folderElement = this._createFolderElement(_node);
|
|
1089
1071
|
folderElement.open(
|
|
1090
1072
|
_onFinished,
|
|
1091
1073
|
_slide,
|
|
@@ -1095,7 +1077,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1095
1077
|
|
|
1096
1078
|
if (node.isFolder() || node.isEmptyFolder) {
|
|
1097
1079
|
if (node.load_on_demand) {
|
|
1098
|
-
this.
|
|
1080
|
+
this._loadFolderOnDemand(node, slide, onFinished);
|
|
1099
1081
|
} else {
|
|
1100
1082
|
let parent = node.parent;
|
|
1101
1083
|
|
|
@@ -1108,12 +1090,12 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1108
1090
|
}
|
|
1109
1091
|
|
|
1110
1092
|
doOpenNode(node, slide, onFinished);
|
|
1111
|
-
this.
|
|
1093
|
+
this._saveState();
|
|
1112
1094
|
}
|
|
1113
1095
|
}
|
|
1114
1096
|
}
|
|
1115
1097
|
|
|
1116
|
-
private
|
|
1098
|
+
private _openParents(node: Node) {
|
|
1117
1099
|
const parent = node.parent;
|
|
1118
1100
|
|
|
1119
1101
|
if (parent?.parent && !parent.is_open) {
|
|
@@ -1125,50 +1107,50 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1125
1107
|
Redraw the tree or part of the tree.
|
|
1126
1108
|
from_node: redraw this subtree
|
|
1127
1109
|
*/
|
|
1128
|
-
private
|
|
1129
|
-
const mustSetFocus = this.
|
|
1110
|
+
private _refreshElements(fromNode: Node | null): void {
|
|
1111
|
+
const mustSetFocus = this._isFocusOnTree();
|
|
1130
1112
|
const mustSelect = fromNode
|
|
1131
|
-
? this.
|
|
1113
|
+
? this._isSelectedNodeInSubtree(fromNode)
|
|
1132
1114
|
: false;
|
|
1133
1115
|
|
|
1134
|
-
this.
|
|
1116
|
+
this._renderer.render(fromNode);
|
|
1135
1117
|
|
|
1136
1118
|
if (mustSelect) {
|
|
1137
|
-
this.
|
|
1119
|
+
this._selectCurrentNode(mustSetFocus);
|
|
1138
1120
|
}
|
|
1139
1121
|
|
|
1140
|
-
this.
|
|
1122
|
+
this._triggerEvent("tree.refresh");
|
|
1141
1123
|
}
|
|
1142
1124
|
|
|
1143
|
-
private
|
|
1125
|
+
private _saveState(): void {
|
|
1144
1126
|
if (this.options.saveState) {
|
|
1145
|
-
this.
|
|
1127
|
+
this._saveStateHandler.saveState();
|
|
1146
1128
|
}
|
|
1147
1129
|
}
|
|
1148
1130
|
|
|
1149
|
-
private
|
|
1131
|
+
private _selectCurrentNode(mustSetFocus: boolean): void {
|
|
1150
1132
|
const node = this.getSelectedNode();
|
|
1151
1133
|
if (node) {
|
|
1152
|
-
const nodeElement = this.
|
|
1134
|
+
const nodeElement = this._getNodeElementForNode(node);
|
|
1153
1135
|
nodeElement.select(mustSetFocus);
|
|
1154
1136
|
}
|
|
1155
1137
|
}
|
|
1156
1138
|
|
|
1157
1139
|
// Set initial state, either by restoring the state or auto-opening nodes
|
|
1158
1140
|
// result: must load nodes on demand?
|
|
1159
|
-
private
|
|
1141
|
+
private _setInitialState(): boolean {
|
|
1160
1142
|
const restoreState = (): [boolean, boolean] => {
|
|
1161
1143
|
// result: is state restored, must load on demand?
|
|
1162
1144
|
if (!this.options.saveState) {
|
|
1163
1145
|
return [false, false];
|
|
1164
1146
|
} else {
|
|
1165
|
-
const state = this.
|
|
1147
|
+
const state = this._saveStateHandler.getStateFromStorage();
|
|
1166
1148
|
|
|
1167
1149
|
if (!state) {
|
|
1168
1150
|
return [false, false];
|
|
1169
1151
|
} else {
|
|
1170
1152
|
const mustLoadOnDemand =
|
|
1171
|
-
this.
|
|
1153
|
+
this._saveStateHandler.setInitialState(state);
|
|
1172
1154
|
|
|
1173
1155
|
// return true: the state is restored
|
|
1174
1156
|
return [true, mustLoadOnDemand];
|
|
@@ -1182,10 +1164,10 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1182
1164
|
return false;
|
|
1183
1165
|
}
|
|
1184
1166
|
|
|
1185
|
-
const maxLevel = this.
|
|
1167
|
+
const maxLevel = this._getAutoOpenMaxLevel();
|
|
1186
1168
|
let mustLoadOnDemand = false;
|
|
1187
1169
|
|
|
1188
|
-
this.
|
|
1170
|
+
this._tree.iterate((node: Node, level: number) => {
|
|
1189
1171
|
if (node.load_on_demand) {
|
|
1190
1172
|
mustLoadOnDemand = true;
|
|
1191
1173
|
return false;
|
|
@@ -1211,17 +1193,17 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1211
1193
|
|
|
1212
1194
|
// Set the initial state for nodes that are loaded on demand
|
|
1213
1195
|
// Call cb_finished when done
|
|
1214
|
-
private
|
|
1196
|
+
private _setInitialStateOnDemand(cbFinished: () => void): void {
|
|
1215
1197
|
const restoreState = (): boolean => {
|
|
1216
1198
|
if (!this.options.saveState) {
|
|
1217
1199
|
return false;
|
|
1218
1200
|
} else {
|
|
1219
|
-
const state = this.
|
|
1201
|
+
const state = this._saveStateHandler.getStateFromStorage();
|
|
1220
1202
|
|
|
1221
1203
|
if (!state) {
|
|
1222
1204
|
return false;
|
|
1223
1205
|
} else {
|
|
1224
|
-
this.
|
|
1206
|
+
this._saveStateHandler.setInitialStateOnDemand(
|
|
1225
1207
|
state,
|
|
1226
1208
|
cbFinished,
|
|
1227
1209
|
);
|
|
@@ -1232,19 +1214,19 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1232
1214
|
};
|
|
1233
1215
|
|
|
1234
1216
|
const autoOpenNodes = (): void => {
|
|
1235
|
-
const maxLevel = this.
|
|
1217
|
+
const maxLevel = this._getAutoOpenMaxLevel();
|
|
1236
1218
|
let loadingCount = 0;
|
|
1237
1219
|
|
|
1238
1220
|
const loadAndOpenNode = (node: Node): void => {
|
|
1239
1221
|
loadingCount += 1;
|
|
1240
|
-
this.
|
|
1222
|
+
this._openNodeInternal(node, false, () => {
|
|
1241
1223
|
loadingCount -= 1;
|
|
1242
1224
|
openNodes();
|
|
1243
1225
|
});
|
|
1244
1226
|
};
|
|
1245
1227
|
|
|
1246
1228
|
const openNodes = (): void => {
|
|
1247
|
-
this.
|
|
1229
|
+
this._tree.iterate((node: Node, level: number) => {
|
|
1248
1230
|
if (node.load_on_demand) {
|
|
1249
1231
|
if (!node.is_loading) {
|
|
1250
1232
|
loadAndOpenNode(node);
|
|
@@ -1252,7 +1234,7 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1252
1234
|
|
|
1253
1235
|
return false;
|
|
1254
1236
|
} else {
|
|
1255
|
-
this.
|
|
1237
|
+
this._openNodeInternal(node, false);
|
|
1256
1238
|
|
|
1257
1239
|
return level !== maxLevel;
|
|
1258
1240
|
}
|
|
@@ -1271,13 +1253,13 @@ export class JqTreeWidget extends SimpleWidget<JQTreeOptions> {
|
|
|
1271
1253
|
}
|
|
1272
1254
|
}
|
|
1273
1255
|
|
|
1274
|
-
private
|
|
1256
|
+
private _triggerEvent(
|
|
1275
1257
|
eventName: string,
|
|
1276
1258
|
values?: Record<string, unknown>,
|
|
1277
|
-
):
|
|
1259
|
+
): boolean {
|
|
1278
1260
|
const event = jQuery.Event(eventName, values);
|
|
1279
|
-
this.
|
|
1280
|
-
return event;
|
|
1261
|
+
this._element.trigger(event);
|
|
1262
|
+
return !event.isDefaultPrevented();
|
|
1281
1263
|
}
|
|
1282
1264
|
}
|
|
1283
1265
|
|