jqtree 1.9.0 → 2.0.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/js-coverage/coverage-final.json +13 -0
- package/lib/jqtreeOptions.js +1 -0
- package/lib/tree.jquery.d.js +0 -0
- package/lib/tree.jquery.js +394 -0
- package/lib/triggerJQueryEvent.js +68 -0
- package/lib/typings.d.js +1 -0
- package/lib/version.js +2 -0
- package/package.json +34 -29
- package/pnpm-workspace.yaml +3 -3
- package/src/jqtreeOptions.ts +20 -62
- package/src/tree.jquery.d.ts +81 -92
- package/src/tree.jquery.ts +234 -938
- package/src/triggerJQueryEvent.ts +97 -0
- package/src/version.ts +2 -2
- package/tree.jquery.debug.js +4226 -3281
- package/tree.jquery.debug.js.map +1 -1
- package/tree.jquery.js +22 -2
- package/tree.jquery.js.map +1 -1
- package/eslint.config.mjs +0 -112
- package/src/animation.ts +0 -48
- package/src/dataLoader.ts +0 -143
- package/src/dragAndDropHandler/binarySearch.ts +0 -27
- package/src/dragAndDropHandler/dragElement.ts +0 -54
- package/src/dragAndDropHandler/generateHitAreas.ts +0 -195
- package/src/dragAndDropHandler/index.ts +0 -432
- package/src/dragAndDropHandler/iterateVisibleNodes.ts +0 -91
- package/src/dragAndDropHandler/types.ts +0 -12
- package/src/elementsRenderer.ts +0 -359
- package/src/jqtreeMethodTypes.ts +0 -40
- package/src/keyHandler.ts +0 -139
- package/src/mouseHandler.ts +0 -383
- package/src/mouseUtils.ts +0 -23
- package/src/node.ts +0 -653
- package/src/nodeElement/borderDropHint.ts +0 -32
- package/src/nodeElement/folderElement.ts +0 -138
- package/src/nodeElement/ghostDropHint.ts +0 -74
- package/src/nodeElement/index.ts +0 -94
- package/src/nodeUtils.ts +0 -10
- package/src/positionUtils.ts +0 -18
- package/src/saveStateHandler.ts +0 -276
- package/src/scrollHandler/containerScrollParent.ts +0 -71
- package/src/scrollHandler/createScrollParent.ts +0 -51
- package/src/scrollHandler/documentScrollParent.ts +0 -104
- package/src/scrollHandler/scrollParent.ts +0 -117
- package/src/scrollHandler.ts +0 -55
- package/src/selectNodeHandler.ts +0 -111
- package/src/simple.widget.ts +0 -134
- package/src/util.ts +0 -5
package/src/mouseHandler.ts
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import type { TriggerEvent } from "./jqtreeMethodTypes";
|
|
2
|
-
import type { PositionInfo } from "./mouseUtils";
|
|
3
|
-
import type { Node } from "./node";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
getPositionInfoFromMouseEvent,
|
|
7
|
-
getPositionInfoFromTouch,
|
|
8
|
-
} from "./mouseUtils";
|
|
9
|
-
|
|
10
|
-
export type GetMouseDelay = () => number;
|
|
11
|
-
export type GetNode = (element: HTMLElement) => Node | null;
|
|
12
|
-
export type MouseCapture = (positionInfo: PositionInfo) => boolean | null;
|
|
13
|
-
export type MouseStart = (positionInfo: PositionInfo) => boolean;
|
|
14
|
-
|
|
15
|
-
interface ClickTarget {
|
|
16
|
-
node: Node;
|
|
17
|
-
type: "button" | "label";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface MouseHandlerParams {
|
|
21
|
-
element: HTMLElement;
|
|
22
|
-
getMouseDelay: () => number;
|
|
23
|
-
getNode: GetNode;
|
|
24
|
-
onClickButton: (node: Node) => void;
|
|
25
|
-
onClickTitle: (node: Node) => void;
|
|
26
|
-
onMouseCapture: MouseCapture;
|
|
27
|
-
onMouseDrag: (positionInfo: PositionInfo) => void;
|
|
28
|
-
onMouseStart: MouseStart;
|
|
29
|
-
onMouseStop: (positionInfo: PositionInfo) => void;
|
|
30
|
-
triggerEvent: TriggerEvent;
|
|
31
|
-
useContextMenu: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
class MouseHandler {
|
|
35
|
-
private _element: HTMLElement;
|
|
36
|
-
private _getMouseDelay: GetMouseDelay;
|
|
37
|
-
private _getNode: GetNode;
|
|
38
|
-
|
|
39
|
-
private _isMouseDelayMet: boolean;
|
|
40
|
-
|
|
41
|
-
private _isMouseStarted: boolean;
|
|
42
|
-
|
|
43
|
-
private _mouseDelayTimer: null | number;
|
|
44
|
-
|
|
45
|
-
private _mouseDownInfo: null | PositionInfo;
|
|
46
|
-
private _onClickButton: (node: Node) => void;
|
|
47
|
-
private _onClickTitle: (node: Node) => void;
|
|
48
|
-
|
|
49
|
-
private _onMouseCapture: MouseCapture;
|
|
50
|
-
|
|
51
|
-
private _onMouseDrag: (positionInfo: PositionInfo) => void;
|
|
52
|
-
|
|
53
|
-
private _onMouseStart: MouseStart;
|
|
54
|
-
|
|
55
|
-
private _onMouseStop: (positionInfo: PositionInfo) => void;
|
|
56
|
-
|
|
57
|
-
private _triggerEvent: TriggerEvent;
|
|
58
|
-
private _useContextMenu: boolean;
|
|
59
|
-
constructor({
|
|
60
|
-
element,
|
|
61
|
-
getMouseDelay,
|
|
62
|
-
getNode,
|
|
63
|
-
onClickButton,
|
|
64
|
-
onClickTitle,
|
|
65
|
-
onMouseCapture,
|
|
66
|
-
onMouseDrag,
|
|
67
|
-
onMouseStart,
|
|
68
|
-
onMouseStop,
|
|
69
|
-
triggerEvent,
|
|
70
|
-
useContextMenu,
|
|
71
|
-
}: MouseHandlerParams) {
|
|
72
|
-
this._element = element;
|
|
73
|
-
this._getMouseDelay = getMouseDelay;
|
|
74
|
-
this._getNode = getNode;
|
|
75
|
-
this._onClickButton = onClickButton;
|
|
76
|
-
this._onClickTitle = onClickTitle;
|
|
77
|
-
this._onMouseCapture = onMouseCapture;
|
|
78
|
-
this._onMouseDrag = onMouseDrag;
|
|
79
|
-
this._onMouseStart = onMouseStart;
|
|
80
|
-
this._onMouseStop = onMouseStop;
|
|
81
|
-
this._triggerEvent = triggerEvent;
|
|
82
|
-
this._useContextMenu = useContextMenu;
|
|
83
|
-
|
|
84
|
-
element.addEventListener("click", this._handleClick);
|
|
85
|
-
element.addEventListener("dblclick", this._handleDblclick);
|
|
86
|
-
element.addEventListener("mousedown", this._mouseDown, {
|
|
87
|
-
passive: false,
|
|
88
|
-
});
|
|
89
|
-
element.addEventListener("touchstart", this._touchStart, {
|
|
90
|
-
passive: false,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (useContextMenu) {
|
|
94
|
-
element.addEventListener("contextmenu", this._handleContextmenu);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
this._isMouseStarted = false;
|
|
98
|
-
this._mouseDelayTimer = null;
|
|
99
|
-
this._isMouseDelayMet = false;
|
|
100
|
-
this._mouseDownInfo = null;
|
|
101
|
-
}
|
|
102
|
-
public deinit(): void {
|
|
103
|
-
this._element.removeEventListener("click", this._handleClick);
|
|
104
|
-
this._element.removeEventListener("dblclick", this._handleDblclick);
|
|
105
|
-
|
|
106
|
-
if (this._useContextMenu) {
|
|
107
|
-
this._element.removeEventListener(
|
|
108
|
-
"contextmenu",
|
|
109
|
-
this._handleContextmenu,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this._element.removeEventListener("mousedown", this._mouseDown);
|
|
114
|
-
this._element.removeEventListener("touchstart", this._touchStart);
|
|
115
|
-
this._removeMouseMoveEventListeners();
|
|
116
|
-
}
|
|
117
|
-
private _getClickTarget(element: HTMLElement): ClickTarget | null {
|
|
118
|
-
const button = element.closest<HTMLElement>(".jqtree-toggler");
|
|
119
|
-
|
|
120
|
-
if (button) {
|
|
121
|
-
const node = this._getNode(button);
|
|
122
|
-
|
|
123
|
-
if (node) {
|
|
124
|
-
return {
|
|
125
|
-
node,
|
|
126
|
-
type: "button",
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
const jqTreeElement =
|
|
131
|
-
element.closest<HTMLElement>(".jqtree-element");
|
|
132
|
-
|
|
133
|
-
if (jqTreeElement) {
|
|
134
|
-
const node = this._getNode(jqTreeElement);
|
|
135
|
-
if (node) {
|
|
136
|
-
return {
|
|
137
|
-
node,
|
|
138
|
-
type: "label",
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
private _handleClick = (e: MouseEvent): void => {
|
|
147
|
-
if (!e.target) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const clickTarget = this._getClickTarget(e.target as HTMLElement);
|
|
152
|
-
|
|
153
|
-
if (!clickTarget) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
switch (clickTarget.type) {
|
|
158
|
-
case "button":
|
|
159
|
-
this._onClickButton(clickTarget.node);
|
|
160
|
-
|
|
161
|
-
e.preventDefault();
|
|
162
|
-
e.stopPropagation();
|
|
163
|
-
break;
|
|
164
|
-
|
|
165
|
-
case "label": {
|
|
166
|
-
if (this._triggerEvent("tree.click", {
|
|
167
|
-
click_event: e,
|
|
168
|
-
node: clickTarget.node,
|
|
169
|
-
})) {
|
|
170
|
-
this._onClickTitle(clickTarget.node);
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
private _handleContextmenu = (e: MouseEvent) => {
|
|
178
|
-
if (!e.target) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const div = (e.target as HTMLElement).closest<HTMLElement>(
|
|
183
|
-
"ul.jqtree-tree .jqtree-element",
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
if (div) {
|
|
187
|
-
const node = this._getNode(div);
|
|
188
|
-
if (node) {
|
|
189
|
-
e.preventDefault();
|
|
190
|
-
e.stopPropagation();
|
|
191
|
-
|
|
192
|
-
this._triggerEvent("tree.contextmenu", {
|
|
193
|
-
click_event: e,
|
|
194
|
-
node,
|
|
195
|
-
});
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return null;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
private _handleDblclick = (e: MouseEvent): void => {
|
|
204
|
-
if (!e.target) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const clickTarget = this._getClickTarget(e.target as HTMLElement);
|
|
209
|
-
|
|
210
|
-
if (clickTarget?.type === "label") {
|
|
211
|
-
this._triggerEvent("tree.dblclick", {
|
|
212
|
-
click_event: e,
|
|
213
|
-
node: clickTarget.node,
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
private _handleMouseDown(positionInfo: PositionInfo): boolean {
|
|
219
|
-
// We may have missed mouseup (out of window)
|
|
220
|
-
if (this._isMouseStarted) {
|
|
221
|
-
this._handleMouseUp(positionInfo);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
this._mouseDownInfo = positionInfo;
|
|
225
|
-
|
|
226
|
-
if (!this._onMouseCapture(positionInfo)) {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
this._handleStartMouse();
|
|
231
|
-
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
private _handleMouseMove(
|
|
236
|
-
e: MouseEvent | TouchEvent,
|
|
237
|
-
positionInfo: PositionInfo,
|
|
238
|
-
): void {
|
|
239
|
-
if (this._isMouseStarted) {
|
|
240
|
-
this._onMouseDrag(positionInfo);
|
|
241
|
-
|
|
242
|
-
if (e.cancelable) {
|
|
243
|
-
e.preventDefault();
|
|
244
|
-
}
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (!this._isMouseDelayMet) {
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (this._mouseDownInfo) {
|
|
253
|
-
this._isMouseStarted = this._onMouseStart(this._mouseDownInfo);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (this._isMouseStarted) {
|
|
257
|
-
this._onMouseDrag(positionInfo);
|
|
258
|
-
|
|
259
|
-
if (e.cancelable) {
|
|
260
|
-
e.preventDefault();
|
|
261
|
-
}
|
|
262
|
-
} else {
|
|
263
|
-
this._handleMouseUp(positionInfo);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
private _handleMouseUp(positionInfo: PositionInfo): void {
|
|
267
|
-
this._removeMouseMoveEventListeners();
|
|
268
|
-
this._isMouseDelayMet = false;
|
|
269
|
-
this._mouseDownInfo = null;
|
|
270
|
-
|
|
271
|
-
if (this._isMouseStarted) {
|
|
272
|
-
this._isMouseStarted = false;
|
|
273
|
-
this._onMouseStop(positionInfo);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
private _handleStartMouse(): void {
|
|
278
|
-
document.addEventListener("mousemove", this._mouseMove, {
|
|
279
|
-
passive: false,
|
|
280
|
-
});
|
|
281
|
-
document.addEventListener("touchmove", this._touchMove, {
|
|
282
|
-
passive: false,
|
|
283
|
-
});
|
|
284
|
-
document.addEventListener("mouseup", this._mouseUp, { passive: false });
|
|
285
|
-
document.addEventListener("touchend", this._touchEnd, {
|
|
286
|
-
passive: false,
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
const mouseDelay = this._getMouseDelay();
|
|
290
|
-
|
|
291
|
-
if (mouseDelay) {
|
|
292
|
-
this._startMouseDelayTimer(mouseDelay);
|
|
293
|
-
} else {
|
|
294
|
-
this._isMouseDelayMet = true;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private _mouseDown = (e: MouseEvent): void => {
|
|
299
|
-
// Left mouse button?
|
|
300
|
-
if (e.button !== 0) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const result = this._handleMouseDown(getPositionInfoFromMouseEvent(e));
|
|
305
|
-
|
|
306
|
-
if (result && e.cancelable) {
|
|
307
|
-
e.preventDefault();
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
private _mouseMove = (e: MouseEvent): void => {
|
|
312
|
-
this._handleMouseMove(e, getPositionInfoFromMouseEvent(e));
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
private _mouseUp = (e: MouseEvent): void => {
|
|
316
|
-
this._handleMouseUp(getPositionInfoFromMouseEvent(e));
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
private _removeMouseMoveEventListeners() {
|
|
320
|
-
document.removeEventListener("mousemove", this._mouseMove);
|
|
321
|
-
document.removeEventListener("touchmove", this._touchMove);
|
|
322
|
-
document.removeEventListener("mouseup", this._mouseUp);
|
|
323
|
-
document.removeEventListener("touchend", this._touchEnd);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
private _startMouseDelayTimer(mouseDelay: number): void {
|
|
327
|
-
if (this._mouseDelayTimer) {
|
|
328
|
-
clearTimeout(this._mouseDelayTimer);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
this._mouseDelayTimer = window.setTimeout(() => {
|
|
332
|
-
if (this._mouseDownInfo) {
|
|
333
|
-
this._isMouseDelayMet = true;
|
|
334
|
-
}
|
|
335
|
-
}, mouseDelay);
|
|
336
|
-
|
|
337
|
-
this._isMouseDelayMet = false;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
private _touchEnd = (e: TouchEvent): void => {
|
|
341
|
-
if (e.touches.length > 1) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const touch = e.touches[0];
|
|
346
|
-
|
|
347
|
-
if (!touch) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
this._handleMouseUp(getPositionInfoFromTouch(touch, e));
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
private _touchMove = (e: TouchEvent): void => {
|
|
355
|
-
if (e.touches.length > 1) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const touch = e.touches[0];
|
|
360
|
-
|
|
361
|
-
if (!touch) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
this._handleMouseMove(e, getPositionInfoFromTouch(touch, e));
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
private _touchStart = (e: TouchEvent): void => {
|
|
369
|
-
if (e.touches.length > 1) {
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const touch = e.touches[0];
|
|
374
|
-
|
|
375
|
-
if (!touch) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
this._handleMouseDown(getPositionInfoFromTouch(touch, e));
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export default MouseHandler;
|
package/src/mouseUtils.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface PositionInfo {
|
|
2
|
-
originalEvent: Event;
|
|
3
|
-
pageX: number;
|
|
4
|
-
pageY: number;
|
|
5
|
-
target: HTMLElement;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const getPositionInfoFromMouseEvent = (e: MouseEvent): PositionInfo => ({
|
|
9
|
-
originalEvent: e,
|
|
10
|
-
pageX: e.pageX,
|
|
11
|
-
pageY: e.pageY,
|
|
12
|
-
target: e.target as HTMLElement,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export const getPositionInfoFromTouch = (
|
|
16
|
-
touch: Touch,
|
|
17
|
-
e: TouchEvent,
|
|
18
|
-
): PositionInfo => ({
|
|
19
|
-
originalEvent: e,
|
|
20
|
-
pageX: touch.pageX,
|
|
21
|
-
pageY: touch.pageY,
|
|
22
|
-
target: touch.target as HTMLElement,
|
|
23
|
-
});
|