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.
@@ -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,8 +31,8 @@ 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
38
  protected getNewHorizontalScrollDirection(
@@ -43,7 +44,7 @@ export default class DocumentScrollParent extends ScrollParent {
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
 
@@ -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
79
  this.container.scrollTop + this.container.clientHeight <
79
- this.getDocumentScrollHeight()
80
+ this._getDocumentScrollHeight()
80
81
  );
81
82
  }
82
83
 
83
- private canScrollRight() {
84
+ private _canScrollRight() {
84
85
  return (
85
86
  this.container.scrollLeft + this.container.clientWidth <
86
- this.getDocumentScrollWidth()
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
  }
@@ -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
  });