jqtree 1.8.5 → 1.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import type { ScrollParent } from "./types";
2
+
2
3
  import { getElementPosition, getOffsetTop } from '../util'
3
4
 
4
5
  type HorizontalScrollDirection = "left" | "right";
@@ -16,70 +17,14 @@ export default class ContainerScrollParent implements ScrollParent {
16
17
  private refreshHitAreas: () => void;
17
18
  private scrollParentBottom?: number;
18
19
  private scrollParentTop?: number;
19
- private verticalScrollTimeout?: number;
20
20
  private verticalScrollDirection?: VerticalScrollDirection;
21
+ private verticalScrollTimeout?: number;
21
22
 
22
23
  constructor({ container, refreshHitAreas }: Params) {
23
24
  this.container = container;
24
25
  this.refreshHitAreas = refreshHitAreas;
25
26
  }
26
27
 
27
- public checkHorizontalScrolling(pageX: number): void {
28
- const newHorizontalScrollDirection =
29
- this.getNewHorizontalScrollDirection(pageX);
30
-
31
- if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
32
- this.horizontalScrollDirection = newHorizontalScrollDirection;
33
-
34
- if (this.horizontalScrollTimeout != null) {
35
- window.clearTimeout(this.verticalScrollTimeout);
36
- }
37
-
38
- if (newHorizontalScrollDirection) {
39
- this.horizontalScrollTimeout = window.setTimeout(
40
- this.scrollHorizontally.bind(this),
41
- 40,
42
- );
43
- }
44
- }
45
- }
46
-
47
- public checkVerticalScrolling(pageY: number) {
48
- const newVerticalScrollDirection =
49
- this.getNewVerticalScrollDirection(pageY);
50
-
51
- if (this.verticalScrollDirection !== newVerticalScrollDirection) {
52
- this.verticalScrollDirection = newVerticalScrollDirection;
53
-
54
- if (this.verticalScrollTimeout != null) {
55
- window.clearTimeout(this.verticalScrollTimeout);
56
- this.verticalScrollTimeout = undefined;
57
- }
58
-
59
- if (newVerticalScrollDirection) {
60
- this.verticalScrollTimeout = window.setTimeout(
61
- this.scrollVertically.bind(this),
62
- 40,
63
- );
64
- }
65
- }
66
- }
67
-
68
- public getScrollLeft(): number {
69
- return this.container.scrollLeft;
70
- }
71
-
72
- public scrollToY(top: number): void {
73
- this.container.scrollTop = top;
74
- }
75
-
76
- public stopScrolling() {
77
- this.horizontalScrollDirection = undefined;
78
- this.verticalScrollDirection = undefined;
79
- this.scrollParentTop = undefined;
80
- this.scrollParentBottom = undefined;
81
- }
82
-
83
28
  private getNewHorizontalScrollDirection(
84
29
  pageX: number,
85
30
  ): HorizontalScrollDirection | undefined {
@@ -101,7 +46,7 @@ export default class ContainerScrollParent implements ScrollParent {
101
46
 
102
47
  private getNewVerticalScrollDirection(
103
48
  pageY: number,
104
- ): VerticalScrollDirection | undefined {
49
+ ): undefined | VerticalScrollDirection {
105
50
  if (pageY < this.getScrollParentTop()) {
106
51
  return "top";
107
52
  }
@@ -113,6 +58,22 @@ export default class ContainerScrollParent implements ScrollParent {
113
58
  return undefined;
114
59
  }
115
60
 
61
+ private getScrollParentBottom() {
62
+ if (this.scrollParentBottom == null) {
63
+ this.scrollParentBottom = this.getScrollParentTop() + this.container.clientHeight;
64
+ }
65
+
66
+ return this.scrollParentBottom;
67
+ }
68
+
69
+ private getScrollParentTop() {
70
+ if (this.scrollParentTop == null) {
71
+ this.scrollParentTop = getOffsetTop(this.container)
72
+ }
73
+
74
+ return this.scrollParentTop;
75
+ }
76
+
116
77
  private scrollHorizontally() {
117
78
  if (!this.horizontalScrollDirection) {
118
79
  return;
@@ -121,9 +82,9 @@ export default class ContainerScrollParent implements ScrollParent {
121
82
  const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
122
83
 
123
84
  this.container.scrollBy({
85
+ behavior: "instant",
124
86
  left: distance,
125
87
  top: 0,
126
- behavior: "instant",
127
88
  });
128
89
 
129
90
  this.refreshHitAreas();
@@ -139,9 +100,9 @@ export default class ContainerScrollParent implements ScrollParent {
139
100
  const distance = this.verticalScrollDirection === "top" ? -20 : 20;
140
101
 
141
102
  this.container.scrollBy({
103
+ behavior: "instant",
142
104
  left: 0,
143
105
  top: distance,
144
- behavior: "instant",
145
106
  });
146
107
 
147
108
  this.refreshHitAreas();
@@ -149,19 +110,59 @@ export default class ContainerScrollParent implements ScrollParent {
149
110
  setTimeout(this.scrollVertically.bind(this), 40);
150
111
  }
151
112
 
152
- private getScrollParentTop() {
153
- if (this.scrollParentTop == null) {
154
- this.scrollParentTop = getOffsetTop(this.container)
155
- }
113
+ public checkHorizontalScrolling(pageX: number): void {
114
+ const newHorizontalScrollDirection =
115
+ this.getNewHorizontalScrollDirection(pageX);
156
116
 
157
- return this.scrollParentTop;
117
+ if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
118
+ this.horizontalScrollDirection = newHorizontalScrollDirection;
119
+
120
+ if (this.horizontalScrollTimeout != null) {
121
+ window.clearTimeout(this.verticalScrollTimeout);
122
+ }
123
+
124
+ if (newHorizontalScrollDirection) {
125
+ this.horizontalScrollTimeout = window.setTimeout(
126
+ this.scrollHorizontally.bind(this),
127
+ 40,
128
+ );
129
+ }
130
+ }
158
131
  }
159
132
 
160
- private getScrollParentBottom() {
161
- if (this.scrollParentBottom == null) {
162
- this.scrollParentBottom = this.getScrollParentTop() + this.container.clientHeight;
133
+ public checkVerticalScrolling(pageY: number) {
134
+ const newVerticalScrollDirection =
135
+ this.getNewVerticalScrollDirection(pageY);
136
+
137
+ if (this.verticalScrollDirection !== newVerticalScrollDirection) {
138
+ this.verticalScrollDirection = newVerticalScrollDirection;
139
+
140
+ if (this.verticalScrollTimeout != null) {
141
+ window.clearTimeout(this.verticalScrollTimeout);
142
+ this.verticalScrollTimeout = undefined;
143
+ }
144
+
145
+ if (newVerticalScrollDirection) {
146
+ this.verticalScrollTimeout = window.setTimeout(
147
+ this.scrollVertically.bind(this),
148
+ 40,
149
+ );
150
+ }
163
151
  }
152
+ }
164
153
 
165
- return this.scrollParentBottom;
154
+ public getScrollLeft(): number {
155
+ return this.container.scrollLeft;
156
+ }
157
+
158
+ public scrollToY(top: number): void {
159
+ this.container.scrollTop = top;
160
+ }
161
+
162
+ public stopScrolling() {
163
+ this.horizontalScrollDirection = undefined;
164
+ this.verticalScrollDirection = undefined;
165
+ this.scrollParentTop = undefined;
166
+ this.scrollParentBottom = undefined;
166
167
  }
167
168
  }
@@ -1,4 +1,5 @@
1
1
  import type { ScrollParent } from "./types";
2
+
2
3
  import ContainerScrollParent from "./containerScrollParent";
3
4
  import DocumentScrollParent from "./documentScrollParent";
4
5
 
@@ -1,5 +1,6 @@
1
1
  import type { ScrollParent } from "./types";
2
- import { getOffsetTop } from '../util'
2
+
3
+ import { getOffsetTop } from "../util";
3
4
 
4
5
  type HorizontalScrollDirection = "left" | "right";
5
6
  type VerticalScrollDirection = "bottom" | "top";
@@ -24,62 +25,40 @@ export default class DocumentScrollParent implements ScrollParent {
24
25
  this.treeElement = treeElement;
25
26
  }
26
27
 
27
- public checkHorizontalScrolling(pageX: number): void {
28
- const newHorizontalScrollDirection =
29
- this.getNewHorizontalScrollDirection(pageX);
30
-
31
- if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
32
- this.horizontalScrollDirection = newHorizontalScrollDirection;
33
-
34
- if (this.horizontalScrollTimeout != null) {
35
- window.clearTimeout(this.horizontalScrollTimeout);
36
- }
28
+ private canScrollDown() {
29
+ const documentElement = document.documentElement;
37
30
 
38
- if (newHorizontalScrollDirection) {
39
- this.horizontalScrollTimeout = window.setTimeout(
40
- this.scrollHorizontally.bind(this),
41
- 40,
42
- );
43
- }
44
- }
31
+ return (
32
+ documentElement.scrollTop + documentElement.clientHeight <
33
+ this.getDocumentScrollHeight()
34
+ );
45
35
  }
46
36
 
47
- public checkVerticalScrolling(pageY: number) {
48
- const newVerticalScrollDirection =
49
- this.getNewVerticalScrollDirection(pageY);
50
-
51
- if (this.verticalScrollDirection !== newVerticalScrollDirection) {
52
- this.verticalScrollDirection = newVerticalScrollDirection;
37
+ private canScrollRight() {
38
+ const documentElement = document.documentElement;
53
39
 
54
- if (this.verticalScrollTimeout != null) {
55
- window.clearTimeout(this.verticalScrollTimeout);
56
- this.verticalScrollTimeout = undefined;
57
- }
40
+ return (
41
+ documentElement.scrollLeft + documentElement.clientWidth <
42
+ this.getDocumentScrollWidth()
43
+ );
44
+ }
58
45
 
59
- if (newVerticalScrollDirection) {
60
- this.verticalScrollTimeout = window.setTimeout(
61
- this.scrollVertically.bind(this),
62
- 40,
63
- );
64
- }
46
+ private getDocumentScrollHeight() {
47
+ // Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
48
+ if (this.documentScrollHeight == null) {
49
+ this.documentScrollHeight = document.documentElement.scrollHeight;
65
50
  }
66
- }
67
51
 
68
- public getScrollLeft(): number {
69
- return document.documentElement.scrollLeft;
52
+ return this.documentScrollHeight;
70
53
  }
71
54
 
72
- public scrollToY(top: number): void {
73
- const treeTop = getOffsetTop(this.treeElement);
74
-
75
- document.documentElement.scrollTop = top + treeTop;
76
- }
55
+ private getDocumentScrollWidth() {
56
+ // Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
57
+ if (this.documentScrollWidth == null) {
58
+ this.documentScrollWidth = document.documentElement.scrollWidth;
59
+ }
77
60
 
78
- public stopScrolling() {
79
- this.horizontalScrollDirection = undefined;
80
- this.verticalScrollDirection = undefined;
81
- this.documentScrollHeight = undefined;
82
- this.documentScrollWidth = undefined;
61
+ return this.documentScrollWidth;
83
62
  }
84
63
 
85
64
  private getNewHorizontalScrollDirection(
@@ -102,46 +81,10 @@ export default class DocumentScrollParent implements ScrollParent {
102
81
  return undefined;
103
82
  }
104
83
 
105
- private canScrollRight() {
106
- const documentElement = document.documentElement;
107
-
108
- return (
109
- documentElement.scrollLeft + documentElement.clientWidth <
110
- this.getDocumentScrollWidth()
111
- );
112
- }
113
-
114
- private canScrollDown() {
115
- const documentElement = document.documentElement;
116
-
117
- return (
118
- documentElement.scrollTop + documentElement.clientHeight <
119
- this.getDocumentScrollHeight()
120
- );
121
- }
122
-
123
- private getDocumentScrollHeight() {
124
- // Store the original scroll height because the scroll height can increase when the drag element is moved beyond the scroll height.
125
- if (this.documentScrollHeight == null) {
126
- this.documentScrollHeight = document.documentElement.scrollHeight;
127
- }
128
-
129
- return this.documentScrollHeight;
130
- }
131
-
132
- private getDocumentScrollWidth() {
133
- // Store the original scroll width because the scroll width can increase when the drag element is moved beyond the scroll width.
134
- if (this.documentScrollWidth == null) {
135
- this.documentScrollWidth = document.documentElement.scrollWidth;
136
- }
137
-
138
- return this.documentScrollWidth;
139
- }
140
-
141
84
  private getNewVerticalScrollDirection(
142
85
  pageY: number,
143
- ): VerticalScrollDirection | undefined {
144
- const scrollTop = jQuery(document).scrollTop() || 0;
86
+ ): undefined | VerticalScrollDirection {
87
+ const scrollTop = jQuery(document).scrollTop() ?? 0;
145
88
  const distanceTop = pageY - scrollTop;
146
89
 
147
90
  if (distanceTop < 20) {
@@ -163,7 +106,7 @@ export default class DocumentScrollParent implements ScrollParent {
163
106
  }
164
107
 
165
108
  const distance = this.horizontalScrollDirection === "left" ? -20 : 20;
166
- window.scrollBy({ left: distance, top: 0, behavior: "instant" });
109
+ window.scrollBy({ behavior: "instant", left: distance, top: 0 });
167
110
 
168
111
  this.refreshHitAreas();
169
112
 
@@ -176,10 +119,68 @@ export default class DocumentScrollParent implements ScrollParent {
176
119
  }
177
120
 
178
121
  const distance = this.verticalScrollDirection === "top" ? -20 : 20;
179
- window.scrollBy({ left: 0, top: distance, behavior: "instant" });
122
+ window.scrollBy({ behavior: "instant", left: 0, top: distance });
180
123
 
181
124
  this.refreshHitAreas();
182
125
 
183
126
  setTimeout(this.scrollVertically.bind(this), 40);
184
127
  }
128
+
129
+ public checkHorizontalScrolling(pageX: number): void {
130
+ const newHorizontalScrollDirection =
131
+ this.getNewHorizontalScrollDirection(pageX);
132
+
133
+ if (this.horizontalScrollDirection !== newHorizontalScrollDirection) {
134
+ this.horizontalScrollDirection = newHorizontalScrollDirection;
135
+
136
+ if (this.horizontalScrollTimeout != null) {
137
+ window.clearTimeout(this.horizontalScrollTimeout);
138
+ }
139
+
140
+ if (newHorizontalScrollDirection) {
141
+ this.horizontalScrollTimeout = window.setTimeout(
142
+ this.scrollHorizontally.bind(this),
143
+ 40,
144
+ );
145
+ }
146
+ }
147
+ }
148
+
149
+ public checkVerticalScrolling(pageY: number) {
150
+ const newVerticalScrollDirection =
151
+ this.getNewVerticalScrollDirection(pageY);
152
+
153
+ if (this.verticalScrollDirection !== newVerticalScrollDirection) {
154
+ this.verticalScrollDirection = newVerticalScrollDirection;
155
+
156
+ if (this.verticalScrollTimeout != null) {
157
+ window.clearTimeout(this.verticalScrollTimeout);
158
+ this.verticalScrollTimeout = undefined;
159
+ }
160
+
161
+ if (newVerticalScrollDirection) {
162
+ this.verticalScrollTimeout = window.setTimeout(
163
+ this.scrollVertically.bind(this),
164
+ 40,
165
+ );
166
+ }
167
+ }
168
+ }
169
+
170
+ public getScrollLeft(): number {
171
+ return document.documentElement.scrollLeft;
172
+ }
173
+
174
+ public scrollToY(top: number): void {
175
+ const treeTop = getOffsetTop(this.treeElement);
176
+
177
+ document.documentElement.scrollTop = top + treeTop;
178
+ }
179
+
180
+ public stopScrolling() {
181
+ this.horizontalScrollDirection = undefined;
182
+ this.verticalScrollDirection = undefined;
183
+ this.documentScrollHeight = undefined;
184
+ this.documentScrollWidth = undefined;
185
+ }
185
186
  }
@@ -1,6 +1,6 @@
1
1
  import { PositionInfo } from "./mouseUtils";
2
- import { ScrollParent } from "./scrollHandler/types";
3
2
  import createScrollParent from "./scrollHandler/createScrollParent";
3
+ import { ScrollParent } from "./scrollHandler/types";
4
4
 
5
5
  interface ScrollHandlerParams {
6
6
  refreshHitAreas: () => void;
@@ -18,31 +18,14 @@ export default class ScrollHandler {
18
18
  this.treeElement = treeElement;
19
19
  }
20
20
 
21
- public checkScrolling(positionInfo: PositionInfo): void {
22
- this.checkVerticalScrolling(positionInfo);
23
- this.checkHorizontalScrolling(positionInfo);
24
- }
25
-
26
- public stopScrolling() {
27
- this.getScrollParent().stopScrolling();
28
- }
29
-
30
- public scrollToY(top: number): void {
31
- this.getScrollParent().scrollToY(top);
32
- }
33
-
34
- public getScrollLeft(): number {
35
- return this.getScrollParent().getScrollLeft();
21
+ private checkHorizontalScrolling(positionInfo: PositionInfo): void {
22
+ this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
36
23
  }
37
24
 
38
25
  private checkVerticalScrolling(positionInfo: PositionInfo): void {
39
26
  this.getScrollParent().checkVerticalScrolling(positionInfo.pageY);
40
27
  }
41
28
 
42
- private checkHorizontalScrolling(positionInfo: PositionInfo): void {
43
- this.getScrollParent().checkHorizontalScrolling(positionInfo.pageX);
44
- }
45
-
46
29
  private getScrollParent(): ScrollParent {
47
30
  if (!this.scrollParent) {
48
31
  this.scrollParent = createScrollParent(
@@ -53,4 +36,21 @@ export default class ScrollHandler {
53
36
 
54
37
  return this.scrollParent;
55
38
  }
39
+
40
+ public checkScrolling(positionInfo: PositionInfo): void {
41
+ this.checkVerticalScrolling(positionInfo);
42
+ this.checkHorizontalScrolling(positionInfo);
43
+ }
44
+
45
+ public getScrollLeft(): number {
46
+ return this.getScrollParent().getScrollLeft();
47
+ }
48
+
49
+ public scrollToY(top: number): void {
50
+ this.getScrollParent().scrollToY(top);
51
+ }
52
+
53
+ public stopScrolling() {
54
+ this.getScrollParent().stopScrolling();
55
+ }
56
56
  }
@@ -1,5 +1,5 @@
1
- import { Node } from "./node";
2
1
  import { GetNodeById } from "./jqtreeMethodTypes";
2
+ import { Node } from "./node";
3
3
 
4
4
  interface SelectNodeHandlerParameters {
5
5
  getNodeById: GetNodeById;
@@ -16,11 +16,24 @@ export default class SelectNodeHandler {
16
16
  this.clear();
17
17
  }
18
18
 
19
- public getSelectedNode(): Node | false {
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 {
20
33
  const selectedNodes = this.getSelectedNodes();
21
34
 
22
35
  if (selectedNodes.length) {
23
- return selectedNodes[0] || false;
36
+ return selectedNodes[0] ?? false;
24
37
  } else {
25
38
  return false;
26
39
  }
@@ -78,11 +91,6 @@ export default class SelectNodeHandler {
78
91
  }
79
92
  }
80
93
 
81
- public clear(): void {
82
- this.selectedNodes.clear();
83
- this.selectedSingleNode = null;
84
- }
85
-
86
94
  public removeFromSelection(node: Node, includeChildren = false): void {
87
95
  if (node.id == null) {
88
96
  if (
@@ -104,12 +112,4 @@ export default class SelectNodeHandler {
104
112
  }
105
113
  }
106
114
  }
107
-
108
- public addToSelection(node: Node): void {
109
- if (node.id != null) {
110
- this.selectedNodes.add(node.id);
111
- } else {
112
- this.selectedSingleNode = node;
113
- }
114
- }
115
115
  }
@@ -3,8 +3,8 @@ const register = (widgetClass: unknown, widgetName: string): void => {
3
3
 
4
4
  const getWidgetData = (
5
5
  el: HTMLElement,
6
- dataKey: string
7
- ): SimpleWidget<unknown> | null => {
6
+ dataKey: string,
7
+ ): null | SimpleWidget<unknown> => {
8
8
  const widget = jQuery.data(el, dataKey) as unknown;
9
9
 
10
10
  if (widget && widget instanceof SimpleWidget) {
@@ -53,7 +53,7 @@ const register = (widgetClass: unknown, widgetName: string): void => {
53
53
  const callFunction = (
54
54
  $el: JQuery,
55
55
  functionName: string,
56
- args: unknown[]
56
+ args: unknown[],
57
57
  ): unknown => {
58
58
  let result = null;
59
59
 
@@ -88,7 +88,8 @@ const register = (widgetClass: unknown, widgetName: string): void => {
88
88
  const functionName = argument1;
89
89
 
90
90
  if (functionName === "destroy") {
91
- return destroyWidget(this);
91
+ destroyWidget(this);
92
+ return undefined;
92
93
  } else if (functionName === "get_widget_class") {
93
94
  return widgetClass;
94
95
  } else {
@@ -101,35 +102,35 @@ const register = (widgetClass: unknown, widgetName: string): void => {
101
102
  };
102
103
 
103
104
  export default class SimpleWidget<WidgetOptions> {
104
- public static register(widgetClass: unknown, widgetName: string): void {
105
- register(widgetClass, widgetName);
106
- }
107
-
108
105
  [key: string]: unknown;
109
106
 
110
107
  protected static defaults: unknown = {};
111
108
 
112
- public options: WidgetOptions;
109
+ public $el: JQuery;
113
110
 
114
- public $el: JQuery<HTMLElement>;
111
+ public options: WidgetOptions;
115
112
 
116
113
  constructor(el: HTMLElement, options: WidgetOptions) {
117
114
  this.$el = jQuery(el);
118
115
 
119
116
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
120
- const defaults = (this.constructor as any)["defaults"] as WidgetOptions;
117
+ const defaults = (this.constructor as any).defaults as WidgetOptions;
121
118
  this.options = { ...defaults, ...options };
122
119
  }
123
120
 
124
- public destroy(): void {
125
- this.deinit();
121
+ public static register(widgetClass: unknown, widgetName: string): void {
122
+ register(widgetClass, widgetName);
126
123
  }
127
124
 
128
- public init(): void {
125
+ public deinit(): void {
129
126
  //
130
127
  }
131
128
 
132
- public deinit(): void {
129
+ public destroy(): void {
130
+ this.deinit();
131
+ }
132
+
133
+ public init(): void {
133
134
  //
134
135
  }
135
136
  }