jqtree 1.8.5 → 1.8.7

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,6 +1,6 @@
1
+ import { OnFinishOpenNode, TriggerEvent } from "../jqtreeMethodTypes";
1
2
  import { Position } from "../position";
2
3
  import NodeElement, { NodeElementParams } from "./index";
3
- import { OnFinishOpenNode, TriggerEvent } from "../jqtreeMethodTypes";
4
4
 
5
5
  interface FolderElementParams extends NodeElementParams {
6
6
  closedIconElement?: HTMLElement | Text;
@@ -14,19 +14,19 @@ class FolderElement extends NodeElement {
14
14
  private triggerEvent: TriggerEvent;
15
15
 
16
16
  constructor({
17
+ $treeElement,
17
18
  closedIconElement,
18
19
  getScrollLeft,
19
20
  node,
20
21
  openedIconElement,
21
22
  tabIndex,
22
- $treeElement,
23
23
  triggerEvent,
24
24
  }: FolderElementParams) {
25
25
  super({
26
+ $treeElement,
26
27
  getScrollLeft,
27
28
  node,
28
29
  tabIndex,
29
- $treeElement,
30
30
  });
31
31
 
32
32
  this.closedIconElement = closedIconElement;
@@ -34,100 +34,100 @@ class FolderElement extends NodeElement {
34
34
  this.triggerEvent = triggerEvent;
35
35
  }
36
36
 
37
- public open(
38
- onFinished: OnFinishOpenNode | undefined,
37
+ protected mustShowBorderDropHint(position: Position): boolean {
38
+ return !this.node.is_open && position === Position.Inside;
39
+ }
40
+
41
+ private getButton(): HTMLLinkElement {
42
+ return this.element.querySelector(
43
+ ":scope > .jqtree-element > a.jqtree-toggler",
44
+ ) as HTMLLinkElement;
45
+ }
46
+
47
+ public close(
39
48
  slide = true,
40
- animationSpeed: JQuery.Duration = "fast",
49
+ animationSpeed: JQuery.Duration | undefined = "fast",
41
50
  ): void {
42
- if (this.node.is_open) {
51
+ if (!this.node.is_open) {
43
52
  return;
44
53
  }
45
54
 
46
- this.node.is_open = true;
55
+ this.node.is_open = false;
47
56
 
48
57
  const button = this.getButton();
49
- button.classList.remove("jqtree-closed");
58
+ button.classList.add("jqtree-closed");
50
59
  button.innerHTML = "";
51
60
 
52
- const openedIconElement = this.openedIconElement;
61
+ const closedIconElement = this.closedIconElement;
53
62
 
54
- if (openedIconElement) {
55
- const icon = openedIconElement.cloneNode(true);
63
+ if (closedIconElement) {
64
+ const icon = closedIconElement.cloneNode(true);
56
65
  button.appendChild(icon);
57
66
  }
58
67
 
59
- const doOpen = (): void => {
60
- this.element.classList.remove("jqtree-closed");
68
+ const doClose = (): void => {
69
+ this.element.classList.add("jqtree-closed");
61
70
 
62
71
  const titleSpan = this.getTitleSpan();
63
- titleSpan.setAttribute("aria-expanded", "true");
64
-
65
- if (onFinished) {
66
- onFinished(this.node);
67
- }
72
+ titleSpan.setAttribute("aria-expanded", "false");
68
73
 
69
- this.triggerEvent("tree.open", {
74
+ this.triggerEvent("tree.close", {
70
75
  node: this.node,
71
76
  });
72
77
  };
73
78
 
74
79
  if (slide) {
75
- jQuery(this.getUl()).slideDown(animationSpeed, doOpen);
80
+ jQuery(this.getUl()).slideUp(animationSpeed, doClose);
76
81
  } else {
77
- jQuery(this.getUl()).show();
78
- doOpen();
82
+ jQuery(this.getUl()).hide();
83
+ doClose();
79
84
  }
80
85
  }
81
86
 
82
- public close(
87
+ public open(
88
+ onFinished: OnFinishOpenNode | undefined,
83
89
  slide = true,
84
- animationSpeed: JQuery.Duration | undefined = "fast",
90
+ animationSpeed: JQuery.Duration = "fast",
85
91
  ): void {
86
- if (!this.node.is_open) {
92
+ if (this.node.is_open) {
87
93
  return;
88
94
  }
89
95
 
90
- this.node.is_open = false;
96
+ this.node.is_open = true;
91
97
 
92
98
  const button = this.getButton();
93
- button.classList.add("jqtree-closed");
99
+ button.classList.remove("jqtree-closed");
94
100
  button.innerHTML = "";
95
101
 
96
- const closedIconElement = this.closedIconElement;
102
+ const openedIconElement = this.openedIconElement;
97
103
 
98
- if (closedIconElement) {
99
- const icon = closedIconElement.cloneNode(true);
104
+ if (openedIconElement) {
105
+ const icon = openedIconElement.cloneNode(true);
100
106
  button.appendChild(icon);
101
107
  }
102
108
 
103
- const doClose = (): void => {
104
- this.element.classList.add("jqtree-closed");
109
+ const doOpen = (): void => {
110
+ this.element.classList.remove("jqtree-closed");
105
111
 
106
112
  const titleSpan = this.getTitleSpan();
107
- titleSpan.setAttribute("aria-expanded", "false");
113
+ titleSpan.setAttribute("aria-expanded", "true");
108
114
 
109
- this.triggerEvent("tree.close", {
115
+ if (onFinished) {
116
+ onFinished(this.node);
117
+ }
118
+
119
+ this.triggerEvent("tree.open", {
110
120
  node: this.node,
111
121
  });
112
122
  };
113
123
 
114
124
  if (slide) {
115
- jQuery(this.getUl()).slideUp(animationSpeed, doClose);
125
+ jQuery(this.getUl()).slideDown(animationSpeed, doOpen);
116
126
  } else {
117
- jQuery(this.getUl()).hide();
118
- doClose();
127
+ jQuery(this.getUl()).show();
128
+ doOpen();
119
129
  }
120
130
  }
121
-
122
- protected mustShowBorderDropHint(position: Position): boolean {
123
- return !this.node.is_open && position === Position.Inside;
124
- }
125
-
126
- private getButton(): HTMLLinkElement {
127
- return this.element.querySelector(
128
- ":scope > .jqtree-element > a.jqtree-toggler",
129
- ) as HTMLLinkElement;
130
- }
131
131
  }
132
132
 
133
133
  export default FolderElement;
@@ -1,19 +1,34 @@
1
1
  import { DropHint } from "../dragAndDropHandler/types";
2
+ import { Node } from "../node";
3
+ import { Position } from "../position";
2
4
 
3
5
  class GhostDropHint implements DropHint {
4
6
  private element: HTMLElement;
5
7
  private ghost: HTMLElement;
8
+ private node: Node;
6
9
 
7
- constructor(element: HTMLElement) {
10
+ constructor(node: Node, element: HTMLElement, position: Position) {
8
11
  this.element = element;
12
+ this.node = node;
9
13
  this.ghost = this.createGhostElement();
10
14
 
11
- this.element.after(this.ghost);
12
- this.ghost.classList.add("jqtree-inside");
13
- }
15
+ switch (position) {
16
+ case Position.After:
17
+ this.moveAfter();
18
+ break;
14
19
 
15
- public remove(): void {
16
- this.ghost.remove();
20
+ case Position.Before:
21
+ this.moveBefore();
22
+ break;
23
+
24
+ case Position.Inside: {
25
+ if (node.isFolder() && node.is_open) {
26
+ this.moveInsideOpenFolder();
27
+ } else {
28
+ this.moveInside();
29
+ }
30
+ }
31
+ }
17
32
  }
18
33
 
19
34
  private createGhostElement() {
@@ -30,6 +45,31 @@ class GhostDropHint implements DropHint {
30
45
 
31
46
  return ghost;
32
47
  }
48
+
49
+ private moveAfter(): void {
50
+ this.element.after(this.ghost);
51
+ }
52
+
53
+ private moveBefore(): void {
54
+ this.element.before(this.ghost);
55
+ }
56
+
57
+ private moveInside(): void {
58
+ this.element.after(this.ghost);
59
+ this.ghost.classList.add("jqtree-inside");
60
+ }
61
+
62
+ private moveInsideOpenFolder(): void {
63
+ const childElement = this.node.children[0]?.element;
64
+
65
+ if (childElement) {
66
+ childElement.before(this.ghost);
67
+ }
68
+ }
69
+
70
+ public remove(): void {
71
+ this.ghost.remove();
72
+ }
33
73
  }
34
74
 
35
75
  export default GhostDropHint;
@@ -1,29 +1,29 @@
1
+ import { DropHint } from "../dragAndDropHandler/types";
2
+ import { GetScrollLeft } from "../jqtreeMethodTypes";
1
3
  import { Node } from "../node";
2
4
  import { Position } from "../position";
3
- import { DropHint } from "../dragAndDropHandler/types";
4
5
  import BorderDropHint from "./borderDropHint";
5
6
  import GhostDropHint from "./ghostDropHint";
6
- import { GetScrollLeft } from "../jqtreeMethodTypes";
7
7
 
8
8
  export interface NodeElementParams {
9
+ $treeElement: JQuery;
9
10
  getScrollLeft: GetScrollLeft;
10
11
  node: Node;
11
12
  tabIndex?: number;
12
- $treeElement: JQuery<HTMLElement>;
13
13
  }
14
14
 
15
15
  class NodeElement {
16
- public node: Node;
17
- public element: HTMLElement;
16
+ private $treeElement: JQuery;
18
17
  private getScrollLeft: GetScrollLeft;
19
18
  private tabIndex?: number;
20
- private $treeElement: JQuery<HTMLElement>;
19
+ public element: HTMLElement;
20
+ public node: Node;
21
21
 
22
22
  constructor({
23
+ $treeElement,
23
24
  getScrollLeft,
24
25
  node,
25
26
  tabIndex,
26
- $treeElement,
27
27
  }: NodeElementParams) {
28
28
  this.getScrollLeft = getScrollLeft;
29
29
  this.tabIndex = tabIndex;
@@ -32,6 +32,38 @@ class NodeElement {
32
32
  this.init(node);
33
33
  }
34
34
 
35
+ protected getTitleSpan(): HTMLSpanElement {
36
+ return this.element.querySelector(
37
+ ":scope > .jqtree-element > span.jqtree-title",
38
+ ) as HTMLSpanElement;
39
+ }
40
+
41
+ protected getUl(): HTMLUListElement {
42
+ return this.element.querySelector(":scope > ul") as HTMLUListElement;
43
+ }
44
+
45
+ protected mustShowBorderDropHint(position: Position): boolean {
46
+ return position === Position.Inside;
47
+ }
48
+
49
+ public addDropHint(position: number): DropHint {
50
+ if (this.mustShowBorderDropHint(position)) {
51
+ return new BorderDropHint(this.element, this.getScrollLeft());
52
+ } else {
53
+ return new GhostDropHint(this.node, this.element, position);
54
+ }
55
+ }
56
+
57
+ public deselect(): void {
58
+ this.element.classList.remove("jqtree-selected");
59
+
60
+ const titleSpan = this.getTitleSpan();
61
+ titleSpan.removeAttribute("tabindex");
62
+ titleSpan.setAttribute("aria-selected", "false");
63
+
64
+ titleSpan.blur();
65
+ }
66
+
35
67
  public init(node: Node): void {
36
68
  this.node = node;
37
69
 
@@ -48,14 +80,6 @@ class NodeElement {
48
80
  }
49
81
  }
50
82
 
51
- public addDropHint(position: number): DropHint {
52
- if (this.mustShowBorderDropHint(position)) {
53
- return new BorderDropHint(this.element, this.getScrollLeft());
54
- } else {
55
- return new GhostDropHint(this.element);
56
- }
57
- }
58
-
59
83
  public select(mustSetFocus: boolean): void {
60
84
  this.element.classList.add("jqtree-selected");
61
85
 
@@ -73,30 +97,6 @@ class NodeElement {
73
97
  titleSpan.focus();
74
98
  }
75
99
  }
76
-
77
- public deselect(): void {
78
- this.element.classList.remove("jqtree-selected");
79
-
80
- const titleSpan = this.getTitleSpan();
81
- titleSpan.removeAttribute("tabindex");
82
- titleSpan.setAttribute("aria-selected", "false");
83
-
84
- titleSpan.blur();
85
- }
86
-
87
- protected getUl(): HTMLUListElement {
88
- return this.element.querySelector(":scope > ul") as HTMLUListElement;
89
- }
90
-
91
- protected getTitleSpan(): HTMLSpanElement {
92
- return this.element.querySelector(
93
- ":scope > .jqtree-element > span.jqtree-title",
94
- ) as HTMLSpanElement;
95
- }
96
-
97
- protected mustShowBorderDropHint(position: Position): boolean {
98
- return position === Position.Inside;
99
- }
100
100
  }
101
101
 
102
102
  export default NodeElement;
package/src/nodeUtils.ts CHANGED
@@ -7,4 +7,4 @@ export const isNodeRecordWithChildren = (
7
7
  ): data is NodeRecordWithChildren =>
8
8
  typeof data === "object" &&
9
9
  "children" in data &&
10
- data["children"] instanceof Array;
10
+ data.children instanceof Array;
package/src/position.ts CHANGED
@@ -6,8 +6,8 @@ export enum Position {
6
6
  }
7
7
 
8
8
  const positionNames: Record<string, Position> = {
9
- before: Position.Before,
10
9
  after: Position.After,
10
+ before: Position.Before,
11
11
  inside: Position.Inside,
12
12
  none: Position.None,
13
13
  };