jqtree 1.9.1 → 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.
Files changed (47) hide show
  1. package/bower.json +1 -1
  2. package/js-coverage/coverage-final.json +13 -0
  3. package/lib/jqtreeOptions.js +1 -0
  4. package/lib/tree.jquery.d.js +0 -0
  5. package/lib/tree.jquery.js +394 -0
  6. package/lib/triggerJQueryEvent.js +68 -0
  7. package/lib/typings.d.js +1 -0
  8. package/lib/version.js +2 -0
  9. package/package.json +20 -15
  10. package/pnpm-workspace.yaml +0 -1
  11. package/src/jqtreeOptions.ts +20 -62
  12. package/src/tree.jquery.d.ts +80 -92
  13. package/src/tree.jquery.ts +157 -967
  14. package/src/triggerJQueryEvent.ts +97 -0
  15. package/src/version.ts +2 -2
  16. package/tree.jquery.debug.js +4209 -3246
  17. package/tree.jquery.debug.js.map +1 -1
  18. package/tree.jquery.js +22 -2
  19. package/tree.jquery.js.map +1 -1
  20. package/src/animation.ts +0 -48
  21. package/src/dataLoader.ts +0 -143
  22. package/src/dragAndDropHandler/binarySearch.ts +0 -27
  23. package/src/dragAndDropHandler/dragElement.ts +0 -54
  24. package/src/dragAndDropHandler/generateHitAreas.ts +0 -195
  25. package/src/dragAndDropHandler/index.ts +0 -432
  26. package/src/dragAndDropHandler/iterateVisibleNodes.ts +0 -91
  27. package/src/dragAndDropHandler/types.ts +0 -12
  28. package/src/elementsRenderer.ts +0 -359
  29. package/src/jqtreeMethodTypes.ts +0 -40
  30. package/src/keyHandler.ts +0 -139
  31. package/src/mouseHandler.ts +0 -383
  32. package/src/mouseUtils.ts +0 -23
  33. package/src/node.ts +0 -653
  34. package/src/nodeElement/borderDropHint.ts +0 -32
  35. package/src/nodeElement/folderElement.ts +0 -138
  36. package/src/nodeElement/ghostDropHint.ts +0 -74
  37. package/src/nodeElement/index.ts +0 -94
  38. package/src/nodeUtils.ts +0 -10
  39. package/src/positionUtils.ts +0 -18
  40. package/src/saveStateHandler.ts +0 -276
  41. package/src/scrollHandler/containerScrollParent.ts +0 -71
  42. package/src/scrollHandler/createScrollParent.ts +0 -51
  43. package/src/scrollHandler/documentScrollParent.ts +0 -104
  44. package/src/scrollHandler/scrollParent.ts +0 -117
  45. package/src/scrollHandler.ts +0 -55
  46. package/src/selectNodeHandler.ts +0 -111
  47. package/src/util.ts +0 -5
@@ -1,51 +0,0 @@
1
- import type { ScrollParent } from "./scrollParent";
2
-
3
- import ContainerScrollParent from "./containerScrollParent";
4
- import DocumentScrollParent from "./documentScrollParent";
5
-
6
- const isOverflow = (overflowValue: string) =>
7
- overflowValue === "auto" || overflowValue === "scroll";
8
-
9
- const hasOverFlow = (element: HTMLElement): boolean => {
10
- const style = getComputedStyle(element);
11
-
12
- return isOverflow(style.overflowX) || isOverflow(style.overflowY);
13
- };
14
-
15
- const getParentWithOverflow = (
16
- treeElement: HTMLElement,
17
- ): HTMLElement | null => {
18
- if (hasOverFlow(treeElement)) {
19
- return treeElement;
20
- }
21
-
22
- let parent = treeElement.parentElement;
23
-
24
- while (parent) {
25
- if (hasOverFlow(parent)) {
26
- return parent;
27
- }
28
-
29
- parent = parent.parentElement;
30
- }
31
-
32
- return null;
33
- };
34
-
35
- const createScrollParent = (
36
- treeElement: HTMLElement,
37
- refreshHitAreas: () => void,
38
- ): ScrollParent => {
39
- const container = getParentWithOverflow(treeElement);
40
-
41
- if (container && container.tagName !== "HTML") {
42
- return new ContainerScrollParent({
43
- container,
44
- refreshHitAreas,
45
- });
46
- } else {
47
- return new DocumentScrollParent({ refreshHitAreas, treeElement });
48
- }
49
- };
50
-
51
- export default createScrollParent;
@@ -1,104 +0,0 @@
1
- import type {
2
- HorizontalScrollDirection,
3
- VerticalScrollDirection,
4
- } from "./scrollParent";
5
-
6
- import { getOffsetTop } from "../positionUtils";
7
- import { ScrollParent } from "./scrollParent";
8
-
9
- interface Params {
10
- refreshHitAreas: () => void;
11
- treeElement: HTMLElement;
12
- }
13
-
14
- export default class DocumentScrollParent extends ScrollParent {
15
- private _documentScrollHeight?: number;
16
- private _documentScrollWidth?: number;
17
- private _treeElement: HTMLElement;
18
-
19
- constructor({ refreshHitAreas, treeElement }: Params) {
20
- super({ container: document.documentElement, refreshHitAreas });
21
-
22
- this._treeElement = treeElement;
23
- }
24
-
25
- public scrollToY(top: number): void {
26
- const treeTop = getOffsetTop(this._treeElement);
27
-
28
- super.scrollToY(top + treeTop);
29
- }
30
-
31
- public stopScrolling() {
32
- super.stopScrolling();
33
-
34
- this._documentScrollHeight = undefined;
35
- this._documentScrollWidth = undefined;
36
- }
37
-
38
- protected _getNewHorizontalScrollDirection(
39
- pageX: number,
40
- ): HorizontalScrollDirection | undefined {
41
- const scrollLeft = this._container.scrollLeft;
42
- const windowWidth = window.innerWidth;
43
-
44
- const isNearRightEdge = pageX > windowWidth - 20;
45
- const isNearLeftEdge = pageX - scrollLeft < 20;
46
-
47
- if (isNearRightEdge && this._canScrollRight()) {
48
- return "right";
49
- }
50
-
51
- if (isNearLeftEdge) {
52
- return "left";
53
- }
54
-
55
- return undefined;
56
- }
57
-
58
- protected _getNewVerticalScrollDirection(
59
- pageY: number,
60
- ): undefined | VerticalScrollDirection {
61
- const scrollTop = this._container.scrollTop;
62
- const distanceTop = pageY - scrollTop;
63
-
64
- if (distanceTop < 20) {
65
- return "top";
66
- }
67
-
68
- const windowHeight = window.innerHeight;
69
-
70
- if (windowHeight - (pageY - scrollTop) < 20 && this._canScrollDown()) {
71
- return "bottom";
72
- }
73
-
74
- return undefined;
75
- }
76
-
77
- private _canScrollDown() {
78
- return (
79
- this._container.scrollTop + this._container.clientHeight <
80
- this._getDocumentScrollHeight()
81
- );
82
- }
83
-
84
- private _canScrollRight() {
85
- return (
86
- this._container.scrollLeft + this._container.clientWidth <
87
- this._getDocumentScrollWidth()
88
- );
89
- }
90
-
91
- private _getDocumentScrollHeight() {
92
- // Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
93
- this._documentScrollHeight ??= this._container.scrollHeight;
94
-
95
- return this._documentScrollHeight;
96
- }
97
-
98
- private _getDocumentScrollWidth() {
99
- // Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
100
- this._documentScrollWidth ??= this._container.scrollWidth;
101
-
102
- return this._documentScrollWidth;
103
- }
104
- }
@@ -1,117 +0,0 @@
1
- export type HorizontalScrollDirection = "left" | "right";
2
- export type VerticalScrollDirection = "bottom" | "top";
3
-
4
- interface ConstructorParams {
5
- container: HTMLElement;
6
- refreshHitAreas: () => void;
7
- }
8
-
9
- export abstract class ScrollParent {
10
- protected _container: HTMLElement;
11
- protected _horizontalScrollDirection?: HorizontalScrollDirection;
12
- protected _horizontalScrollTimeout?: number;
13
-
14
- protected _refreshHitAreas: () => void;
15
- protected _verticalScrollDirection?: VerticalScrollDirection;
16
- protected _verticalScrollTimeout?: number;
17
-
18
- constructor({ container, refreshHitAreas }: ConstructorParams) {
19
- this._container = container;
20
- this._refreshHitAreas = refreshHitAreas;
21
- }
22
-
23
- public checkHorizontalScrolling(pageX: number): void {
24
- const newHorizontalScrollDirection =
25
- this._getNewHorizontalScrollDirection(pageX);
26
-
27
- if (this._horizontalScrollDirection !== newHorizontalScrollDirection) {
28
- this._horizontalScrollDirection = newHorizontalScrollDirection;
29
-
30
- if (this._horizontalScrollTimeout != null) {
31
- window.clearTimeout(this._horizontalScrollTimeout);
32
- }
33
-
34
- if (newHorizontalScrollDirection) {
35
- this._horizontalScrollTimeout = window.setTimeout(
36
- this._scrollHorizontally.bind(this),
37
- 40,
38
- );
39
- }
40
- }
41
- }
42
-
43
- public checkVerticalScrolling(pageY: number) {
44
- const newVerticalScrollDirection =
45
- this._getNewVerticalScrollDirection(pageY);
46
-
47
- if (this._verticalScrollDirection !== newVerticalScrollDirection) {
48
- this._verticalScrollDirection = newVerticalScrollDirection;
49
-
50
- if (this._verticalScrollTimeout != null) {
51
- window.clearTimeout(this._verticalScrollTimeout);
52
- this._verticalScrollTimeout = undefined;
53
- }
54
-
55
- if (newVerticalScrollDirection) {
56
- this._verticalScrollTimeout = window.setTimeout(
57
- this._scrollVertically.bind(this),
58
- 40,
59
- );
60
- }
61
- }
62
- }
63
-
64
- public getScrollLeft(): number {
65
- return this._container.scrollLeft;
66
- }
67
-
68
- public scrollToY(top: number): void {
69
- this._container.scrollTop = top;
70
- }
71
-
72
- public stopScrolling() {
73
- this._horizontalScrollDirection = undefined;
74
- this._verticalScrollDirection = undefined;
75
- }
76
-
77
- protected abstract _getNewHorizontalScrollDirection(
78
- pageX: number,
79
- ): HorizontalScrollDirection | undefined;
80
- protected abstract _getNewVerticalScrollDirection(
81
- pageY: number,
82
- ): undefined | VerticalScrollDirection;
83
-
84
- protected _scrollHorizontally() {
85
- if (!this._horizontalScrollDirection) {
86
- return;
87
- }
88
-
89
- const distance = this._horizontalScrollDirection === "left" ? -20 : 20;
90
- this._container.scrollBy({
91
- behavior: "instant",
92
- left: distance,
93
- top: 0,
94
- });
95
-
96
- this._refreshHitAreas();
97
-
98
- setTimeout(this._scrollHorizontally.bind(this), 40);
99
- }
100
-
101
- protected _scrollVertically() {
102
- if (!this._verticalScrollDirection) {
103
- return;
104
- }
105
-
106
- const distance = this._verticalScrollDirection === "top" ? -20 : 20;
107
- this._container.scrollBy({
108
- behavior: "instant",
109
- left: 0,
110
- top: distance,
111
- });
112
-
113
- this._refreshHitAreas();
114
-
115
- setTimeout(this._scrollVertically.bind(this), 40);
116
- }
117
- }
@@ -1,55 +0,0 @@
1
- import type { PositionInfo } from "./mouseUtils";
2
- import type { ScrollParent } from "./scrollHandler/scrollParent";
3
-
4
- import createScrollParent from "./scrollHandler/createScrollParent";
5
-
6
- interface ScrollHandlerParams {
7
- refreshHitAreas: () => void;
8
- treeElement: HTMLElement;
9
- }
10
-
11
- export default class ScrollHandler {
12
- private _refreshHitAreas: () => void;
13
- private _scrollParent?: ScrollParent;
14
- private _treeElement: HTMLElement;
15
-
16
- constructor({ refreshHitAreas, treeElement }: ScrollHandlerParams) {
17
- this._refreshHitAreas = refreshHitAreas;
18
- this._scrollParent = undefined;
19
- this._treeElement = treeElement;
20
- }
21
-
22
- public checkScrolling(positionInfo: PositionInfo): void {
23
- this._checkVerticalScrolling(positionInfo);
24
- this._checkHorizontalScrolling(positionInfo);
25
- }
26
-
27
- public getScrollLeft(): number {
28
- return this._getScrollParent().getScrollLeft();
29
- }
30
-
31
- public scrollToY(top: number): void {
32
- this._getScrollParent().scrollToY(top);
33
- }
34
-
35
- public stopScrolling() {
36
- this._getScrollParent().stopScrolling();
37
- }
38
-
39
- private _checkHorizontalScrolling(positionInfo: PositionInfo): void {
40
- this._getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
41
- }
42
-
43
- private _checkVerticalScrolling(positionInfo: PositionInfo): void {
44
- this._getScrollParent().checkVerticalScrolling(positionInfo.pageY);
45
- }
46
-
47
- private _getScrollParent(): ScrollParent {
48
- this._scrollParent ??= createScrollParent(
49
- this._treeElement,
50
- this._refreshHitAreas,
51
- );
52
-
53
- return this._scrollParent;
54
- }
55
- }
@@ -1,111 +0,0 @@
1
- import type { GetNodeById } from "./jqtreeMethodTypes";
2
- import type { Node } from "./node";
3
-
4
- interface SelectNodeHandlerParameters {
5
- getNodeById: GetNodeById;
6
- }
7
-
8
- export default class SelectNodeHandler {
9
- private _getNodeById: GetNodeById;
10
- private _selectedNodes: Set<NodeId>;
11
- private _selectedSingleNode: Node | null;
12
-
13
- constructor({ getNodeById }: SelectNodeHandlerParameters) {
14
- this._getNodeById = getNodeById;
15
- this._selectedNodes = new Set<NodeId>();
16
- this.clear();
17
- }
18
-
19
- public addToSelection(node: Node): void {
20
- if (node.id != null) {
21
- this._selectedNodes.add(node.id);
22
- } else {
23
- this._selectedSingleNode = node;
24
- }
25
- }
26
-
27
- public clear(): void {
28
- this._selectedNodes.clear();
29
- this._selectedSingleNode = null;
30
- }
31
-
32
- public getSelectedNode(): false | Node {
33
- const selectedNodes = this.getSelectedNodes();
34
-
35
- if (selectedNodes.length) {
36
- return selectedNodes[0] ?? false;
37
- } else {
38
- return false;
39
- }
40
- }
41
-
42
- public getSelectedNodes(): Node[] {
43
- if (this._selectedSingleNode) {
44
- return [this._selectedSingleNode];
45
- } else {
46
- const selectedNodes: Node[] = [];
47
-
48
- this._selectedNodes.forEach((id) => {
49
- const node = this._getNodeById(id);
50
- if (node) {
51
- selectedNodes.push(node);
52
- }
53
- });
54
-
55
- return selectedNodes;
56
- }
57
- }
58
-
59
- public getSelectedNodesUnder(parent: Node): Node[] {
60
- if (this._selectedSingleNode) {
61
- if (parent.isParentOf(this._selectedSingleNode)) {
62
- return [this._selectedSingleNode];
63
- } else {
64
- return [];
65
- }
66
- } else {
67
- const selectedNodes: Node[] = [];
68
-
69
- this._selectedNodes.forEach((id) => {
70
- const node = this._getNodeById(id);
71
- if (node && parent.isParentOf(node)) {
72
- selectedNodes.push(node);
73
- }
74
- });
75
-
76
- return selectedNodes;
77
- }
78
- }
79
-
80
- public isNodeSelected(node: Node): boolean {
81
- if (node.id != null) {
82
- return this._selectedNodes.has(node.id);
83
- } else if (this._selectedSingleNode) {
84
- return this._selectedSingleNode.element === node.element;
85
- } else {
86
- return false;
87
- }
88
- }
89
-
90
- public removeFromSelection(node: Node, includeChildren = false): void {
91
- if (node.id == null) {
92
- if (
93
- this._selectedSingleNode &&
94
- node.element === this._selectedSingleNode.element
95
- ) {
96
- this._selectedSingleNode = null;
97
- }
98
- } else {
99
- this._selectedNodes.delete(node.id);
100
-
101
- if (includeChildren) {
102
- node.iterate(() => {
103
- if (node.id != null) {
104
- this._selectedNodes.delete(node.id);
105
- }
106
- return true;
107
- });
108
- }
109
- }
110
- }
111
- }
package/src/util.ts DELETED
@@ -1,5 +0,0 @@
1
- export const isInt = (n: unknown): boolean =>
2
- typeof n === "number" && n % 1 === 0;
3
-
4
- export const getBoolString = (value: unknown): string =>
5
- value ? "true" : "false";