jqtree 1.8.11 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/bower.json +1 -1
  2. package/package.json +45 -51
  3. package/pnpm-workspace.yaml +5 -0
  4. package/src/animation.ts +48 -0
  5. package/src/dataLoader.ts +38 -48
  6. package/src/dragAndDropHandler/dragElement.ts +11 -11
  7. package/src/dragAndDropHandler/generateHitAreas.ts +4 -3
  8. package/src/dragAndDropHandler/index.ts +119 -120
  9. package/src/dragAndDropHandler/iterateVisibleNodes.ts +1 -1
  10. package/src/dragAndDropHandler/types.ts +1 -1
  11. package/src/elementsRenderer.ts +71 -78
  12. package/src/jqtreeMethodTypes.ts +2 -2
  13. package/src/jqtreeOptions.ts +3 -2
  14. package/src/keyHandler.ts +34 -34
  15. package/src/mouseHandler.ts +118 -119
  16. package/src/node.ts +22 -22
  17. package/src/nodeElement/borderDropHint.ts +6 -6
  18. package/src/nodeElement/folderElement.ts +33 -25
  19. package/src/nodeElement/ghostDropHint.ts +24 -24
  20. package/src/nodeElement/index.ts +19 -18
  21. package/src/positionUtils.ts +18 -0
  22. package/src/saveStateHandler.ts +56 -55
  23. package/src/scrollHandler/containerScrollParent.ts +24 -22
  24. package/src/scrollHandler/documentScrollParent.ts +29 -28
  25. package/src/scrollHandler/scrollParent.ts +41 -41
  26. package/src/scrollHandler.ts +23 -22
  27. package/src/selectNodeHandler.ts +28 -28
  28. package/src/tree.jquery.d.ts +3 -2
  29. package/src/tree.jquery.ts +456 -368
  30. package/src/util.ts +0 -14
  31. package/src/version.ts +1 -1
  32. package/tree.jquery.debug.js +1094 -973
  33. package/tree.jquery.debug.js.map +1 -1
  34. package/tree.jquery.js +2 -2
  35. package/tree.jquery.js.map +1 -1
  36. package/eslint.config.mjs +0 -98
  37. package/src/simple.widget.ts +0 -134
@@ -1,28 +1,29 @@
1
- import { getOffsetTop } from "../util";
2
- import {
1
+ import type {
3
2
  HorizontalScrollDirection,
4
- ScrollParent,
5
3
  VerticalScrollDirection,
6
4
  } from "./scrollParent";
7
5
 
6
+ import { getOffsetTop } from "../positionUtils";
7
+ import { ScrollParent } from "./scrollParent";
8
+
8
9
  interface Params {
9
10
  refreshHitAreas: () => void;
10
11
  treeElement: HTMLElement;
11
12
  }
12
13
 
13
14
  export default class DocumentScrollParent extends ScrollParent {
14
- private documentScrollHeight?: number;
15
- private documentScrollWidth?: number;
16
- private treeElement: HTMLElement;
15
+ private _documentScrollHeight?: number;
16
+ private _documentScrollWidth?: number;
17
+ private _treeElement: HTMLElement;
17
18
 
18
19
  constructor({ refreshHitAreas, treeElement }: Params) {
19
20
  super({ container: document.documentElement, refreshHitAreas });
20
21
 
21
- this.treeElement = treeElement;
22
+ this._treeElement = treeElement;
22
23
  }
23
24
 
24
25
  public scrollToY(top: number): void {
25
- const treeTop = getOffsetTop(this.treeElement);
26
+ const treeTop = getOffsetTop(this._treeElement);
26
27
 
27
28
  super.scrollToY(top + treeTop);
28
29
  }
@@ -30,20 +31,20 @@ export default class DocumentScrollParent extends ScrollParent {
30
31
  public stopScrolling() {
31
32
  super.stopScrolling();
32
33
 
33
- this.documentScrollHeight = undefined;
34
- this.documentScrollWidth = undefined;
34
+ this._documentScrollHeight = undefined;
35
+ this._documentScrollWidth = undefined;
35
36
  }
36
37
 
37
- protected getNewHorizontalScrollDirection(
38
+ protected _getNewHorizontalScrollDirection(
38
39
  pageX: number,
39
40
  ): HorizontalScrollDirection | undefined {
40
- const scrollLeft = this.container.scrollLeft;
41
+ const scrollLeft = this._container.scrollLeft;
41
42
  const windowWidth = window.innerWidth;
42
43
 
43
44
  const isNearRightEdge = pageX > windowWidth - 20;
44
45
  const isNearLeftEdge = pageX - scrollLeft < 20;
45
46
 
46
- if (isNearRightEdge && this.canScrollRight()) {
47
+ if (isNearRightEdge && this._canScrollRight()) {
47
48
  return "right";
48
49
  }
49
50
 
@@ -54,10 +55,10 @@ export default class DocumentScrollParent extends ScrollParent {
54
55
  return undefined;
55
56
  }
56
57
 
57
- protected getNewVerticalScrollDirection(
58
+ protected _getNewVerticalScrollDirection(
58
59
  pageY: number,
59
60
  ): undefined | VerticalScrollDirection {
60
- const scrollTop = this.container.scrollTop;
61
+ const scrollTop = this._container.scrollTop;
61
62
  const distanceTop = pageY - scrollTop;
62
63
 
63
64
  if (distanceTop < 20) {
@@ -66,38 +67,38 @@ export default class DocumentScrollParent extends ScrollParent {
66
67
 
67
68
  const windowHeight = window.innerHeight;
68
69
 
69
- if (windowHeight - (pageY - scrollTop) < 20 && this.canScrollDown()) {
70
+ if (windowHeight - (pageY - scrollTop) < 20 && this._canScrollDown()) {
70
71
  return "bottom";
71
72
  }
72
73
 
73
74
  return undefined;
74
75
  }
75
76
 
76
- private canScrollDown() {
77
+ private _canScrollDown() {
77
78
  return (
78
- this.container.scrollTop + this.container.clientHeight <
79
- this.getDocumentScrollHeight()
79
+ this._container.scrollTop + this._container.clientHeight <
80
+ this._getDocumentScrollHeight()
80
81
  );
81
82
  }
82
83
 
83
- private canScrollRight() {
84
+ private _canScrollRight() {
84
85
  return (
85
- this.container.scrollLeft + this.container.clientWidth <
86
- this.getDocumentScrollWidth()
86
+ this._container.scrollLeft + this._container.clientWidth <
87
+ this._getDocumentScrollWidth()
87
88
  );
88
89
  }
89
90
 
90
- private getDocumentScrollHeight() {
91
+ private _getDocumentScrollHeight() {
91
92
  // Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
92
- this.documentScrollHeight ??= this.container.scrollHeight;
93
+ this._documentScrollHeight ??= this._container.scrollHeight;
93
94
 
94
- return this.documentScrollHeight;
95
+ return this._documentScrollHeight;
95
96
  }
96
97
 
97
- private getDocumentScrollWidth() {
98
+ private _getDocumentScrollWidth() {
98
99
  // Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
99
- this.documentScrollWidth ??= this.container.scrollWidth;
100
+ this._documentScrollWidth ??= this._container.scrollWidth;
100
101
 
101
- return this.documentScrollWidth;
102
+ return this._documentScrollWidth;
102
103
  }
103
104
  }
@@ -7,33 +7,33 @@ interface ConstructorParams {
7
7
  }
8
8
 
9
9
  export abstract class ScrollParent {
10
- protected container: HTMLElement;
11
- protected horizontalScrollDirection?: HorizontalScrollDirection;
12
- protected horizontalScrollTimeout?: number;
10
+ protected _container: HTMLElement;
11
+ protected _horizontalScrollDirection?: HorizontalScrollDirection;
12
+ protected _horizontalScrollTimeout?: number;
13
13
 
14
- protected refreshHitAreas: () => void;
15
- protected verticalScrollDirection?: VerticalScrollDirection;
16
- protected verticalScrollTimeout?: number;
14
+ protected _refreshHitAreas: () => void;
15
+ protected _verticalScrollDirection?: VerticalScrollDirection;
16
+ protected _verticalScrollTimeout?: number;
17
17
 
18
18
  constructor({ container, refreshHitAreas }: ConstructorParams) {
19
- this.container = container;
20
- this.refreshHitAreas = refreshHitAreas;
19
+ this._container = container;
20
+ this._refreshHitAreas = refreshHitAreas;
21
21
  }
22
22
 
23
23
  public checkHorizontalScrolling(pageX: number): void {
24
24
  const newHorizontalScrollDirection =
25
- this.getNewHorizontalScrollDirection(pageX);
25
+ this._getNewHorizontalScrollDirection(pageX);
26
26
 
27
- if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
28
- this.horizontalScrollDirection = newHorizontalScrollDirection;
27
+ if (this._horizontalScrollDirection !== newHorizontalScrollDirection) {
28
+ this._horizontalScrollDirection = newHorizontalScrollDirection;
29
29
 
30
- if (this.horizontalScrollTimeout != null) {
31
- window.clearTimeout(this.horizontalScrollTimeout);
30
+ if (this._horizontalScrollTimeout != null) {
31
+ window.clearTimeout(this._horizontalScrollTimeout);
32
32
  }
33
33
 
34
34
  if (newHorizontalScrollDirection) {
35
- this.horizontalScrollTimeout = window.setTimeout(
36
- this.scrollHorizontally.bind(this),
35
+ this._horizontalScrollTimeout = window.setTimeout(
36
+ this._scrollHorizontally.bind(this),
37
37
  40,
38
38
  );
39
39
  }
@@ -42,19 +42,19 @@ export abstract class ScrollParent {
42
42
 
43
43
  public checkVerticalScrolling(pageY: number) {
44
44
  const newVerticalScrollDirection =
45
- this.getNewVerticalScrollDirection(pageY);
45
+ this._getNewVerticalScrollDirection(pageY);
46
46
 
47
- if (this.verticalScrollDirection !== newVerticalScrollDirection) {
48
- this.verticalScrollDirection = newVerticalScrollDirection;
47
+ if (this._verticalScrollDirection !== newVerticalScrollDirection) {
48
+ this._verticalScrollDirection = newVerticalScrollDirection;
49
49
 
50
- if (this.verticalScrollTimeout != null) {
51
- window.clearTimeout(this.verticalScrollTimeout);
52
- this.verticalScrollTimeout = undefined;
50
+ if (this._verticalScrollTimeout != null) {
51
+ window.clearTimeout(this._verticalScrollTimeout);
52
+ this._verticalScrollTimeout = undefined;
53
53
  }
54
54
 
55
55
  if (newVerticalScrollDirection) {
56
- this.verticalScrollTimeout = window.setTimeout(
57
- this.scrollVertically.bind(this),
56
+ this._verticalScrollTimeout = window.setTimeout(
57
+ this._scrollVertically.bind(this),
58
58
  40,
59
59
  );
60
60
  }
@@ -62,56 +62,56 @@ export abstract class ScrollParent {
62
62
  }
63
63
 
64
64
  public getScrollLeft(): number {
65
- return this.container.scrollLeft;
65
+ return this._container.scrollLeft;
66
66
  }
67
67
 
68
68
  public scrollToY(top: number): void {
69
- this.container.scrollTop = top;
69
+ this._container.scrollTop = top;
70
70
  }
71
71
 
72
72
  public stopScrolling() {
73
- this.horizontalScrollDirection = undefined;
74
- this.verticalScrollDirection = undefined;
73
+ this._horizontalScrollDirection = undefined;
74
+ this._verticalScrollDirection = undefined;
75
75
  }
76
76
 
77
- protected abstract getNewHorizontalScrollDirection(
77
+ protected abstract _getNewHorizontalScrollDirection(
78
78
  pageX: number,
79
79
  ): HorizontalScrollDirection | undefined;
80
- protected abstract getNewVerticalScrollDirection(
80
+ protected abstract _getNewVerticalScrollDirection(
81
81
  pageY: number,
82
82
  ): undefined | VerticalScrollDirection;
83
83
 
84
- protected scrollHorizontally() {
85
- if (!this.horizontalScrollDirection) {
84
+ protected _scrollHorizontally() {
85
+ if (!this._horizontalScrollDirection) {
86
86
  return;
87
87
  }
88
88
 
89
- const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
90
- this.container.scrollBy({
89
+ const distance = this._horizontalScrollDirection === "left" ? -20 : 20;
90
+ this._container.scrollBy({
91
91
  behavior: "instant",
92
92
  left: distance,
93
93
  top: 0,
94
94
  });
95
95
 
96
- this.refreshHitAreas();
96
+ this._refreshHitAreas();
97
97
 
98
- setTimeout(this.scrollHorizontally.bind(this), 40);
98
+ setTimeout(this._scrollHorizontally.bind(this), 40);
99
99
  }
100
100
 
101
- protected scrollVertically() {
102
- if (!this.verticalScrollDirection) {
101
+ protected _scrollVertically() {
102
+ if (!this._verticalScrollDirection) {
103
103
  return;
104
104
  }
105
105
 
106
- const distance = this.verticalScrollDirection === "top" ? -20 : 20;
107
- this.container.scrollBy({
106
+ const distance = this._verticalScrollDirection === "top" ? -20 : 20;
107
+ this._container.scrollBy({
108
108
  behavior: "instant",
109
109
  left: 0,
110
110
  top: distance,
111
111
  });
112
112
 
113
- this.refreshHitAreas();
113
+ this._refreshHitAreas();
114
114
 
115
- setTimeout(this.scrollVertically.bind(this), 40);
115
+ setTimeout(this._scrollVertically.bind(this), 40);
116
116
  }
117
117
  }
@@ -1,6 +1,7 @@
1
- import { PositionInfo } from "./mouseUtils";
1
+ import type { PositionInfo } from "./mouseUtils";
2
+ import type { ScrollParent } from "./scrollHandler/scrollParent";
3
+
2
4
  import createScrollParent from "./scrollHandler/createScrollParent";
3
- import { ScrollParent } from "./scrollHandler/scrollParent";
4
5
 
5
6
  interface ScrollHandlerParams {
6
7
  refreshHitAreas: () => void;
@@ -8,47 +9,47 @@ interface ScrollHandlerParams {
8
9
  }
9
10
 
10
11
  export default class ScrollHandler {
11
- private refreshHitAreas: () => void;
12
- private scrollParent?: ScrollParent;
13
- private treeElement: HTMLElement;
12
+ private _refreshHitAreas: () => void;
13
+ private _scrollParent?: ScrollParent;
14
+ private _treeElement: HTMLElement;
14
15
 
15
16
  constructor({ refreshHitAreas, treeElement }: ScrollHandlerParams) {
16
- this.refreshHitAreas = refreshHitAreas;
17
- this.scrollParent = undefined;
18
- this.treeElement = treeElement;
17
+ this._refreshHitAreas = refreshHitAreas;
18
+ this._scrollParent = undefined;
19
+ this._treeElement = treeElement;
19
20
  }
20
21
 
21
22
  public checkScrolling(positionInfo: PositionInfo): void {
22
- this.checkVerticalScrolling(positionInfo);
23
- this.checkHorizontalScrolling(positionInfo);
23
+ this._checkVerticalScrolling(positionInfo);
24
+ this._checkHorizontalScrolling(positionInfo);
24
25
  }
25
26
 
26
27
  public getScrollLeft(): number {
27
- return this.getScrollParent().getScrollLeft();
28
+ return this._getScrollParent().getScrollLeft();
28
29
  }
29
30
 
30
31
  public scrollToY(top: number): void {
31
- this.getScrollParent().scrollToY(top);
32
+ this._getScrollParent().scrollToY(top);
32
33
  }
33
34
 
34
35
  public stopScrolling() {
35
- this.getScrollParent().stopScrolling();
36
+ this._getScrollParent().stopScrolling();
36
37
  }
37
38
 
38
- private checkHorizontalScrolling(positionInfo: PositionInfo): void {
39
- this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
39
+ private _checkHorizontalScrolling(positionInfo: PositionInfo): void {
40
+ this._getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
40
41
  }
41
42
 
42
- private checkVerticalScrolling(positionInfo: PositionInfo): void {
43
- this.getScrollParent().checkVerticalScrolling(positionInfo.pageY);
43
+ private _checkVerticalScrolling(positionInfo: PositionInfo): void {
44
+ this._getScrollParent().checkVerticalScrolling(positionInfo.pageY);
44
45
  }
45
46
 
46
- private getScrollParent(): ScrollParent {
47
- this.scrollParent ??= createScrollParent(
48
- this.treeElement,
49
- this.refreshHitAreas,
47
+ private _getScrollParent(): ScrollParent {
48
+ this._scrollParent ??= createScrollParent(
49
+ this._treeElement,
50
+ this._refreshHitAreas,
50
51
  );
51
52
 
52
- return this.scrollParent;
53
+ return this._scrollParent;
53
54
  }
54
55
  }
@@ -1,32 +1,32 @@
1
- import { GetNodeById } from "./jqtreeMethodTypes";
2
- import { Node } from "./node";
1
+ import type { GetNodeById } from "./jqtreeMethodTypes";
2
+ import type { Node } from "./node";
3
3
 
4
4
  interface SelectNodeHandlerParameters {
5
5
  getNodeById: GetNodeById;
6
6
  }
7
7
 
8
8
  export default class SelectNodeHandler {
9
- private getNodeById: GetNodeById;
10
- private selectedNodes: Set<NodeId>;
11
- private selectedSingleNode: Node | null;
9
+ private _getNodeById: GetNodeById;
10
+ private _selectedNodes: Set<NodeId>;
11
+ private _selectedSingleNode: Node | null;
12
12
 
13
13
  constructor({ getNodeById }: SelectNodeHandlerParameters) {
14
- this.getNodeById = getNodeById;
15
- this.selectedNodes = new Set<NodeId>();
14
+ this._getNodeById = getNodeById;
15
+ this._selectedNodes = new Set<NodeId>();
16
16
  this.clear();
17
17
  }
18
18
 
19
19
  public addToSelection(node: Node): void {
20
20
  if (node.id != null) {
21
- this.selectedNodes.add(node.id);
21
+ this._selectedNodes.add(node.id);
22
22
  } else {
23
- this.selectedSingleNode = node;
23
+ this._selectedSingleNode = node;
24
24
  }
25
25
  }
26
26
 
27
27
  public clear(): void {
28
- this.selectedNodes.clear();
29
- this.selectedSingleNode = null;
28
+ this._selectedNodes.clear();
29
+ this._selectedSingleNode = null;
30
30
  }
31
31
 
32
32
  public getSelectedNode(): false | Node {
@@ -40,13 +40,13 @@ export default class SelectNodeHandler {
40
40
  }
41
41
 
42
42
  public getSelectedNodes(): Node[] {
43
- if (this.selectedSingleNode) {
44
- return [this.selectedSingleNode];
43
+ if (this._selectedSingleNode) {
44
+ return [this._selectedSingleNode];
45
45
  } else {
46
46
  const selectedNodes: Node[] = [];
47
47
 
48
- this.selectedNodes.forEach((id) => {
49
- const node = this.getNodeById(id);
48
+ this._selectedNodes.forEach((id) => {
49
+ const node = this._getNodeById(id);
50
50
  if (node) {
51
51
  selectedNodes.push(node);
52
52
  }
@@ -57,17 +57,17 @@ export default class SelectNodeHandler {
57
57
  }
58
58
 
59
59
  public getSelectedNodesUnder(parent: Node): Node[] {
60
- if (this.selectedSingleNode) {
61
- if (parent.isParentOf(this.selectedSingleNode)) {
62
- return [this.selectedSingleNode];
60
+ if (this._selectedSingleNode) {
61
+ if (parent.isParentOf(this._selectedSingleNode)) {
62
+ return [this._selectedSingleNode];
63
63
  } else {
64
64
  return [];
65
65
  }
66
66
  } else {
67
67
  const selectedNodes: Node[] = [];
68
68
 
69
- this.selectedNodes.forEach((id) => {
70
- const node = this.getNodeById(id);
69
+ this._selectedNodes.forEach((id) => {
70
+ const node = this._getNodeById(id);
71
71
  if (node && parent.isParentOf(node)) {
72
72
  selectedNodes.push(node);
73
73
  }
@@ -79,9 +79,9 @@ export default class SelectNodeHandler {
79
79
 
80
80
  public isNodeSelected(node: Node): boolean {
81
81
  if (node.id != null) {
82
- return this.selectedNodes.has(node.id);
83
- } else if (this.selectedSingleNode) {
84
- return this.selectedSingleNode.element === node.element;
82
+ return this._selectedNodes.has(node.id);
83
+ } else if (this._selectedSingleNode) {
84
+ return this._selectedSingleNode.element === node.element;
85
85
  } else {
86
86
  return false;
87
87
  }
@@ -90,18 +90,18 @@ export default class SelectNodeHandler {
90
90
  public removeFromSelection(node: Node, includeChildren = false): void {
91
91
  if (node.id == null) {
92
92
  if (
93
- this.selectedSingleNode &&
94
- node.element === this.selectedSingleNode.element
93
+ this._selectedSingleNode &&
94
+ node.element === this._selectedSingleNode.element
95
95
  ) {
96
- this.selectedSingleNode = null;
96
+ this._selectedSingleNode = null;
97
97
  }
98
98
  } else {
99
- this.selectedNodes.delete(node.id);
99
+ this._selectedNodes.delete(node.id);
100
100
 
101
101
  if (includeChildren) {
102
102
  node.iterate(() => {
103
103
  if (node.id != null) {
104
- this.selectedNodes.delete(node.id);
104
+ this._selectedNodes.delete(node.id);
105
105
  }
106
106
  return true;
107
107
  });
@@ -24,8 +24,8 @@ interface IJQTreeOptions {
24
24
  onCanMove?: (node: INode) => boolean;
25
25
  onCanSelectNode?: (node: INode) => boolean;
26
26
  onCreateLi?: (node: INode, el: JQuery, isSelected: boolean) => void;
27
- onDragMove?: (node: INode, event: JQuery.Event | Touch) => void;
28
- onDragStop?: (node: INode, event: JQuery.Event | Touch) => void;
27
+ onDragMove?: (node: INode, event: Event | Touch) => void;
28
+ onDragStop?: (node: INode, event: Event | Touch) => void;
29
29
  onGetStateFromStorage?: () => string;
30
30
  onIsMoveHandle?: (el: JQuery) => boolean;
31
31
  onLoadFailed?: (response: JQuery.jqXHR) => void;
@@ -79,6 +79,7 @@ interface IJQTreePlugin {
79
79
  (behavior: "getStateFromStorage"): INode | null;
80
80
  (behavior: "getTree"): INode;
81
81
  (behavior: "getVersion"): string;
82
+ (behavior: "isDragging"): boolean;
82
83
  (behavior: "isNodeSelected", node: INode): boolean;
83
84
  (behavior: "loadData", data: NodeData[], parentNode?: INode): JQuery;
84
85
  (