tree-element 0.1.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 (182) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +221 -0
  3. package/lib/animation.d.ts +5 -0
  4. package/lib/animation.d.ts.map +1 -0
  5. package/lib/animation.js +39 -0
  6. package/lib/animation.js.map +1 -0
  7. package/lib/classNames.d.ts +34 -0
  8. package/lib/classNames.d.ts.map +1 -0
  9. package/lib/classNames.js +39 -0
  10. package/lib/classNames.js.map +1 -0
  11. package/lib/dataLoader.d.ts +25 -0
  12. package/lib/dataLoader.d.ts.map +1 -0
  13. package/lib/dataLoader.js +69 -0
  14. package/lib/dataLoader.js.map +1 -0
  15. package/lib/dragAndDropHandler/binarySearch.d.ts +3 -0
  16. package/lib/dragAndDropHandler/binarySearch.d.ts.map +1 -0
  17. package/lib/dragAndDropHandler/binarySearch.js +23 -0
  18. package/lib/dragAndDropHandler/binarySearch.js.map +1 -0
  19. package/lib/dragAndDropHandler/dragElement.d.ts +20 -0
  20. package/lib/dragAndDropHandler/dragElement.d.ts.map +1 -0
  21. package/lib/dragAndDropHandler/dragElement.js +39 -0
  22. package/lib/dragAndDropHandler/dragElement.js.map +1 -0
  23. package/lib/dragAndDropHandler/generateHitAreas.d.ts +13 -0
  24. package/lib/dragAndDropHandler/generateHitAreas.d.ts.map +1 -0
  25. package/lib/dragAndDropHandler/generateHitAreas.js +130 -0
  26. package/lib/dragAndDropHandler/generateHitAreas.js.map +1 -0
  27. package/lib/dragAndDropHandler/index.d.ts +76 -0
  28. package/lib/dragAndDropHandler/index.d.ts.map +1 -0
  29. package/lib/dragAndDropHandler/index.js +311 -0
  30. package/lib/dragAndDropHandler/index.js.map +1 -0
  31. package/lib/dragAndDropHandler/iterateVisibleNodes.d.ts +11 -0
  32. package/lib/dragAndDropHandler/iterateVisibleNodes.d.ts.map +1 -0
  33. package/lib/dragAndDropHandler/iterateVisibleNodes.js +54 -0
  34. package/lib/dragAndDropHandler/iterateVisibleNodes.js.map +1 -0
  35. package/lib/dragAndDropHandler/types.d.ts +11 -0
  36. package/lib/dragAndDropHandler/types.d.ts.map +1 -0
  37. package/lib/elementsRenderer.d.ts +53 -0
  38. package/lib/elementsRenderer.d.ts.map +1 -0
  39. package/lib/elementsRenderer.js +251 -0
  40. package/lib/elementsRenderer.js.map +1 -0
  41. package/lib/events.d.ts +224 -0
  42. package/lib/events.d.ts.map +1 -0
  43. package/lib/index.d.ts +367 -0
  44. package/lib/index.d.ts.map +1 -0
  45. package/lib/index.js +1098 -0
  46. package/lib/index.js.map +1 -0
  47. package/lib/keyHandler.d.ts +29 -0
  48. package/lib/keyHandler.d.ts.map +1 -0
  49. package/lib/keyHandler.js +107 -0
  50. package/lib/keyHandler.js.map +1 -0
  51. package/lib/methodTypes.d.ts +21 -0
  52. package/lib/methodTypes.d.ts.map +1 -0
  53. package/lib/mouseHandler.d.ts +60 -0
  54. package/lib/mouseHandler.d.ts.map +1 -0
  55. package/lib/mouseHandler.js +283 -0
  56. package/lib/mouseHandler.js.map +1 -0
  57. package/lib/mouseUtils.d.ts +9 -0
  58. package/lib/mouseUtils.d.ts.map +1 -0
  59. package/lib/mouseUtils.js +15 -0
  60. package/lib/mouseUtils.js.map +1 -0
  61. package/lib/node.d.ts +320 -0
  62. package/lib/node.d.ts.map +1 -0
  63. package/lib/node.js +737 -0
  64. package/lib/node.js.map +1 -0
  65. package/lib/nodeElement/borderDropHint.d.ts +9 -0
  66. package/lib/nodeElement/borderDropHint.d.ts.map +1 -0
  67. package/lib/nodeElement/borderDropHint.js +24 -0
  68. package/lib/nodeElement/borderDropHint.js.map +1 -0
  69. package/lib/nodeElement/folderElement.d.ts +22 -0
  70. package/lib/nodeElement/folderElement.d.ts.map +1 -0
  71. package/lib/nodeElement/folderElement.js +100 -0
  72. package/lib/nodeElement/folderElement.js.map +1 -0
  73. package/lib/nodeElement/ghostDropHint.d.ts +18 -0
  74. package/lib/nodeElement/ghostDropHint.d.ts.map +1 -0
  75. package/lib/nodeElement/ghostDropHint.js +67 -0
  76. package/lib/nodeElement/ghostDropHint.js.map +1 -0
  77. package/lib/nodeElement/index.d.ts +28 -0
  78. package/lib/nodeElement/index.d.ts.map +1 -0
  79. package/lib/nodeElement/index.js +66 -0
  80. package/lib/nodeElement/index.js.map +1 -0
  81. package/lib/nodeUtils.d.ts +7 -0
  82. package/lib/nodeUtils.d.ts.map +1 -0
  83. package/lib/nodeUtils.js +4 -0
  84. package/lib/nodeUtils.js.map +1 -0
  85. package/lib/options.d.ts +310 -0
  86. package/lib/options.d.ts.map +1 -0
  87. package/lib/package.json +3 -0
  88. package/lib/positionUtils.d.ts +8 -0
  89. package/lib/positionUtils.d.ts.map +1 -0
  90. package/lib/positionUtils.js +14 -0
  91. package/lib/positionUtils.js.map +1 -0
  92. package/lib/requestUrl.d.ts +9 -0
  93. package/lib/requestUrl.d.ts.map +1 -0
  94. package/lib/requestUrl.js +37 -0
  95. package/lib/requestUrl.js.map +1 -0
  96. package/lib/saveStateHandler.d.ts +46 -0
  97. package/lib/saveStateHandler.d.ts.map +1 -0
  98. package/lib/saveStateHandler.js +204 -0
  99. package/lib/saveStateHandler.js.map +1 -0
  100. package/lib/scrollHandler/containerScrollParent.d.ts +12 -0
  101. package/lib/scrollHandler/containerScrollParent.d.ts.map +1 -0
  102. package/lib/scrollHandler/containerScrollParent.js +49 -0
  103. package/lib/scrollHandler/containerScrollParent.js.map +1 -0
  104. package/lib/scrollHandler/createScrollParent.d.ts +4 -0
  105. package/lib/scrollHandler/createScrollParent.d.ts.map +1 -0
  106. package/lib/scrollHandler/createScrollParent.js +38 -0
  107. package/lib/scrollHandler/createScrollParent.js.map +1 -0
  108. package/lib/scrollHandler/documentScrollParent.d.ts +22 -0
  109. package/lib/scrollHandler/documentScrollParent.d.ts.map +1 -0
  110. package/lib/scrollHandler/documentScrollParent.js +71 -0
  111. package/lib/scrollHandler/documentScrollParent.js.map +1 -0
  112. package/lib/scrollHandler/scrollParent.d.ts +26 -0
  113. package/lib/scrollHandler/scrollParent.d.ts.map +1 -0
  114. package/lib/scrollHandler/scrollParent.js +79 -0
  115. package/lib/scrollHandler/scrollParent.js.map +1 -0
  116. package/lib/scrollHandler.d.ts +20 -0
  117. package/lib/scrollHandler.d.ts.map +1 -0
  118. package/lib/scrollHandler.js +41 -0
  119. package/lib/scrollHandler.js.map +1 -0
  120. package/lib/selectNodeHandler.d.ts +38 -0
  121. package/lib/selectNodeHandler.d.ts.map +1 -0
  122. package/lib/selectNodeHandler.js +166 -0
  123. package/lib/selectNodeHandler.js.map +1 -0
  124. package/lib/setDefaultOptions.d.ts +4 -0
  125. package/lib/setDefaultOptions.d.ts.map +1 -0
  126. package/lib/setDefaultOptions.js +86 -0
  127. package/lib/setDefaultOptions.js.map +1 -0
  128. package/lib/triggerCustomEvent.d.ts +3 -0
  129. package/lib/triggerCustomEvent.d.ts.map +1 -0
  130. package/lib/triggerCustomEvent.js +13 -0
  131. package/lib/triggerCustomEvent.js.map +1 -0
  132. package/lib/util.d.ts +3 -0
  133. package/lib/util.d.ts.map +1 -0
  134. package/lib/util.js +5 -0
  135. package/lib/util.js.map +1 -0
  136. package/lib/version.d.ts +3 -0
  137. package/lib/version.d.ts.map +1 -0
  138. package/lib/version.js +5 -0
  139. package/lib/version.js.map +1 -0
  140. package/package.json +110 -0
  141. package/src/animation.ts +48 -0
  142. package/src/classNames.ts +70 -0
  143. package/src/dataLoader.ts +92 -0
  144. package/src/dragAndDropHandler/binarySearch.ts +27 -0
  145. package/src/dragAndDropHandler/dragElement.ts +62 -0
  146. package/src/dragAndDropHandler/generateHitAreas.ts +195 -0
  147. package/src/dragAndDropHandler/index.ts +442 -0
  148. package/src/dragAndDropHandler/iterateVisibleNodes.ts +91 -0
  149. package/src/dragAndDropHandler/types.ts +12 -0
  150. package/src/elementsRenderer.ts +367 -0
  151. package/src/events.ts +237 -0
  152. package/src/header.txt +16 -0
  153. package/src/index.ts +1290 -0
  154. package/src/keyHandler.ts +139 -0
  155. package/src/methodTypes.ts +44 -0
  156. package/src/mouseHandler.ts +391 -0
  157. package/src/mouseUtils.ts +23 -0
  158. package/src/node.ts +831 -0
  159. package/src/nodeElement/borderDropHint.ts +37 -0
  160. package/src/nodeElement/folderElement.ts +140 -0
  161. package/src/nodeElement/ghostDropHint.ts +84 -0
  162. package/src/nodeElement/index.ts +103 -0
  163. package/src/nodeUtils.ts +12 -0
  164. package/src/options.ts +325 -0
  165. package/src/positionUtils.ts +18 -0
  166. package/src/requestUrl.ts +41 -0
  167. package/src/saveStateHandler.ts +279 -0
  168. package/src/scrollHandler/containerScrollParent.ts +71 -0
  169. package/src/scrollHandler/createScrollParent.ts +51 -0
  170. package/src/scrollHandler/documentScrollParent.ts +104 -0
  171. package/src/scrollHandler/scrollParent.ts +117 -0
  172. package/src/scrollHandler.ts +55 -0
  173. package/src/selectNodeHandler.ts +192 -0
  174. package/src/setDefaultOptions.ts +79 -0
  175. package/src/triggerCustomEvent.ts +14 -0
  176. package/src/util.ts +5 -0
  177. package/src/version.ts +4 -0
  178. package/tree_element.css +195 -0
  179. package/tree_element.debug.js +4153 -0
  180. package/tree_element.debug.js.map +1 -0
  181. package/tree_element.js +21 -0
  182. package/tree_element.js.map +1 -0
@@ -0,0 +1,310 @@
1
+ import type { AnimationSpeed } from "./animation.js";
2
+ import type { Node, NodeData } from "./node.js";
3
+ export type DataFilter = (data: unknown) => NodeData[];
4
+ export type DataUrl = DataUrlFunction | string;
5
+ export type DragMethod = (node: Node, event: Event | Touch) => void;
6
+ export type IconElement = HTMLElement | string;
7
+ export type OnCanMove = ((node: Node) => boolean) | undefined;
8
+ export type OnCanMoveTo = (node: Node, targetNode: Node, positionName: string) => boolean;
9
+ export type OnCanSelectNode = (node: Node) => boolean;
10
+ export type OnCreateLi = (node: Node, el: HTMLElement, isSelected: boolean) => void;
11
+ export type OnGetStateFromStorage = (() => string) | undefined;
12
+ export type OnIsMoveHandle = (el: HTMLElement) => boolean;
13
+ export type OnSetStateFromStorage = ((data: string) => void) | undefined;
14
+ export interface TreeElementOptions {
15
+ /**
16
+ * The duration of the slide animation: `"fast"` is 200ms, `"slow"` is
17
+ * 600ms, a number is milliseconds.
18
+ *
19
+ * @defaultValue `"fast"`
20
+ * @group Appearance
21
+ */
22
+ animationSpeed: AnimationSpeed;
23
+ /**
24
+ * Escape node names. With `false`, names are inserted as html — only do
25
+ * that for data you control.
26
+ *
27
+ * @defaultValue `true`
28
+ * @group Data
29
+ */
30
+ autoEscape: boolean;
31
+ /**
32
+ * Which levels are open initially: `false` none, `true` all, a number that
33
+ * many levels starting at `0` (so `0` opens the top level, `1` the first
34
+ * two levels).
35
+ *
36
+ * @defaultValue `false`
37
+ * @group Appearance
38
+ */
39
+ autoOpen: boolean | number;
40
+ /**
41
+ * Put the open/close button before the node title. With `false` it goes
42
+ * after it.
43
+ *
44
+ * @defaultValue `true`
45
+ * @group Appearance
46
+ */
47
+ buttonLeft: boolean;
48
+ /**
49
+ * The prefix of the css classes the widget puts on the elements it
50
+ * creates: with `"my-tree"` a title gets `my-tree-title` instead of
51
+ * `tree-element-title`. The bundled stylesheet uses the default prefix, so
52
+ * change it only if you bring your own css. See
53
+ * [Styling](/guide/styling#changing-the-class-names).
54
+ *
55
+ * @defaultValue `"tree-element"`
56
+ * @group Appearance
57
+ */
58
+ classPrefix: string;
59
+ /**
60
+ * The icon of a closed folder. A string is inserted as html; an element is
61
+ * cloned for every node.
62
+ *
63
+ * Type: `HTMLElement | string`
64
+ *
65
+ * @defaultValue `"►"` (`►`), or `"◀"` (`◀`) when `rtl` is
66
+ * true.
67
+ * @group Appearance
68
+ */
69
+ closedIcon?: IconElement;
70
+ /**
71
+ * The class that every element of the widget gets.
72
+ *
73
+ * @defaultValue `"<classPrefix>-common"`
74
+ * @group Appearance
75
+ */
76
+ commonClassName?: string;
77
+ /**
78
+ * The nodes of the tree. See [Data](/guide/data) for the format.
79
+ *
80
+ * @group Data
81
+ */
82
+ data?: NodeData[];
83
+ /**
84
+ * Transforms a response from `dataUrl` into node data. Use it when the
85
+ * server wraps the nodes in another object.
86
+ *
87
+ * Type: `(data: unknown) => NodeData[]`
88
+ *
89
+ * @group Data
90
+ */
91
+ dataFilter?: DataFilter;
92
+ /**
93
+ * A url to fetch the data from, or a function that returns one. The
94
+ * function is called with the node that is being loaded, and without an
95
+ * argument for the initial load. See
96
+ * [Loading on demand](/guide/loading-on-demand).
97
+ *
98
+ * Type: `string | ((node?: Node) => string)`
99
+ *
100
+ * @defaultValue The element's `data-url` attribute.
101
+ * @group Data
102
+ */
103
+ dataUrl?: DataUrl;
104
+ /**
105
+ * Let the user move nodes by dragging them.
106
+ *
107
+ * @defaultValue `false`
108
+ * @group Drag and drop
109
+ */
110
+ dragAndDrop: boolean;
111
+ /**
112
+ * Handle the arrow keys when the focus is on the tree. See
113
+ * [Selection](/guide/selection#keyboard-navigation).
114
+ *
115
+ * @defaultValue `true`
116
+ * @group Selection
117
+ */
118
+ keyboardSupport: boolean;
119
+ /**
120
+ * The class used to create nodes. Subclass [`Node`](/reference/node) to
121
+ * add your own methods. The `Node` class is not exposed on the global
122
+ * `TreeElement`, so this option needs the `lib` build.
123
+ *
124
+ * @example
125
+ * ```js
126
+ * import TreeElement from "tree-element/lib/index.js";
127
+ * import { Node } from "tree-element/lib/node.js";
128
+ *
129
+ * class MyNode extends Node {
130
+ * fullName() {
131
+ * return this.getParent()
132
+ * ? `${this.getParent().name}/${this.name}`
133
+ * : this.name;
134
+ * }
135
+ * }
136
+ *
137
+ * new TreeElement({ data, htmlElement, nodeClass: MyNode });
138
+ * ```
139
+ *
140
+ * @defaultValue `Node`
141
+ * @group Advanced
142
+ */
143
+ nodeClass: typeof Node;
144
+ /**
145
+ * Called before a drag starts. Return `false` to keep the node in place.
146
+ *
147
+ * Type: `(node: Node) => boolean`
148
+ *
149
+ * @group Drag and drop
150
+ */
151
+ onCanMove?: OnCanMove;
152
+ /**
153
+ * Called for a possible drop. `position` is `"before"`, `"after"` or
154
+ * `"inside"`. Return `false` to refuse the drop.
155
+ *
156
+ * Type: `(movedNode: Node, targetNode: Node, position: string) => boolean`
157
+ *
158
+ * @group Drag and drop
159
+ */
160
+ onCanMoveTo?: OnCanMoveTo;
161
+ /**
162
+ * Called before a node is selected. Return `false` to refuse.
163
+ *
164
+ * Type: `(node: Node) => boolean`
165
+ *
166
+ * @group Selection
167
+ */
168
+ onCanSelectNode?: OnCanSelectNode;
169
+ /**
170
+ * Called after the `li` of a node is created, so you can add to it. See
171
+ * [Styling](/guide/styling#customizing-the-markup).
172
+ *
173
+ * Type: `(node: Node, li: HTMLElement, isSelected: boolean) => void`
174
+ *
175
+ * @group Appearance
176
+ */
177
+ onCreateLi?: OnCreateLi;
178
+ /**
179
+ * Called while a node is being dragged.
180
+ *
181
+ * Type: `(node: Node, event: Event | Touch) => void`
182
+ *
183
+ * @group Drag and drop
184
+ */
185
+ onDragMove?: DragMethod;
186
+ /**
187
+ * Called when a drag ends.
188
+ *
189
+ * Type: `(node: Node, event: Event | Touch) => void`
190
+ *
191
+ * @group Drag and drop
192
+ */
193
+ onDragStop?: DragMethod;
194
+ /**
195
+ * Read the saved state, as a json string, from somewhere other than
196
+ * `localStorage`.
197
+ *
198
+ * Type: `() => string`
199
+ *
200
+ * @group State
201
+ */
202
+ onGetStateFromStorage?: OnGetStateFromStorage;
203
+ /**
204
+ * Decides whether an element inside a node starts a drag. Without it, the
205
+ * whole node is a handle.
206
+ *
207
+ * Type: `(element: HTMLElement) => boolean`
208
+ *
209
+ * @group Drag and drop
210
+ */
211
+ onIsMoveHandle?: OnIsMoveHandle;
212
+ /**
213
+ * Write the state, as a json string, to somewhere other than
214
+ * `localStorage`.
215
+ *
216
+ * Type: `(state: string) => void`
217
+ *
218
+ * @group State
219
+ */
220
+ onSetStateFromStorage?: OnSetStateFromStorage;
221
+ /**
222
+ * The icon of an open folder.
223
+ *
224
+ * Type: `HTMLElement | string`
225
+ *
226
+ * @defaultValue `"&#x25bc;"` (`▼`)
227
+ * @group Appearance
228
+ */
229
+ openedIcon?: IconElement;
230
+ /**
231
+ * How long, in milliseconds, a closed folder has to be hovered during a
232
+ * drag before it opens. `false` never opens folders while dragging.
233
+ *
234
+ * @defaultValue `500`
235
+ * @group Drag and drop
236
+ */
237
+ openFolderDelay: false | number;
238
+ /**
239
+ * Mirror the tree for right-to-left languages.
240
+ *
241
+ * @defaultValue The element's `data-rtl` attribute, otherwise `false`.
242
+ * @group Appearance
243
+ */
244
+ rtl?: boolean;
245
+ /**
246
+ * Remember the open and selected nodes in `localStorage`. A string is used
247
+ * as the storage key; `true` uses `tree`. See
248
+ * [Saving state](/guide/saving-state).
249
+ *
250
+ * @defaultValue `false`
251
+ * @group State
252
+ */
253
+ saveState: boolean | string;
254
+ /**
255
+ * Allow the user to select nodes.
256
+ *
257
+ * @defaultValue `true`
258
+ * @group Selection
259
+ */
260
+ selectable: boolean;
261
+ /**
262
+ * Render a node with `children: []` as a folder instead of as a leaf.
263
+ *
264
+ * @defaultValue `false`
265
+ * @group Appearance
266
+ */
267
+ showEmptyFolder: boolean;
268
+ /**
269
+ * Animate opening and closing folders.
270
+ *
271
+ * @defaultValue `true`
272
+ * @group Appearance
273
+ */
274
+ slide: boolean;
275
+ /**
276
+ * How long, in milliseconds, the mouse has to be held down on a node
277
+ * before a drag starts.
278
+ *
279
+ * @defaultValue `300`
280
+ * @group Drag and drop
281
+ */
282
+ startDndDelay?: number;
283
+ /**
284
+ * The `tabindex` of the selected node's title, which is what makes the
285
+ * tree focusable.
286
+ *
287
+ * @defaultValue `0`
288
+ * @group Selection
289
+ */
290
+ tabIndex?: number;
291
+ /**
292
+ * The class of the root `ul`.
293
+ *
294
+ * @defaultValue The value of `classPrefix`.
295
+ * @group Appearance
296
+ */
297
+ treeClassName?: string;
298
+ /**
299
+ * Handle right clicks on a node: the browser menu is suppressed and
300
+ * [`tree.contextmenu`](/reference/events#tree-contextmenu) is dispatched
301
+ * instead.
302
+ *
303
+ * @defaultValue `true`
304
+ * @group Selection
305
+ */
306
+ useContextMenu: boolean;
307
+ }
308
+ type DataUrlFunction = (node?: Node) => string;
309
+ export {};
310
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,QAAQ,EAAE,CAAC;AAEvD,MAAM,MAAM,OAAO,GAAG,eAAe,GAAG,MAAM,CAAC;AAE/C,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,KAAK,IAAI,CAAC;AAEpE,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,MAAM,CAAC;AAE/C,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;AAE9D,MAAM,MAAM,WAAW,GAAG,CACxB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,IAAI,EAChB,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC;AAEb,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAA;AAErD,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;AAEpF,MAAM,MAAM,qBAAqB,GAAG,CAAC,MAAM,MAAM,CAAC,GAAG,SAAS,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC;AAE1D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,EAAE,M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B,CAAC,EAAE,qBAAqB,CAAC;IAC9C;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB;;;;;;OAMG;IACH,eAAe,EAAE,KAAK,GAAG,MAAM,CAAC;IAChC;;;;;OAKG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;;;;;OAOG;IACH,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC;IAC5B;;;;;OAKG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;;;;OAKG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAC;IACf;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;;;OAOG;IACH,cAAc,EAAE,OAAO,CAAC;CACzB;AAED,KAAK,eAAe,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,KAAK,MAAM,CAAC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,8 @@
1
+ interface TopLeftPosition {
2
+ left: number;
3
+ top: number;
4
+ }
5
+ export declare const getOffsetTop: (element: HTMLElement) => number;
6
+ export declare const getElementPosition: (element: HTMLElement) => TopLeftPosition;
7
+ export {};
8
+ //# sourceMappingURL=positionUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positionUtils.d.ts","sourceRoot":"","sources":["../src/positionUtils.ts"],"names":[],"mappings":"AAAA,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAGD,eAAO,MAAM,YAAY,GAAI,SAAS,WAAW,KAAG,MACnB,CAAC;AAGlC,eAAO,MAAM,kBAAkB,GAAI,SAAS,WAAW,KAAG,eAOzD,CAAC"}
@@ -0,0 +1,14 @@
1
+ // Get the top position of the HTML element.
2
+ const getOffsetTop = element => getElementPosition(element).top;
3
+
4
+ // Get the top left position of the HTML element.
5
+ const getElementPosition = element => {
6
+ const rect = element.getBoundingClientRect();
7
+ return {
8
+ left: rect.x + window.scrollX,
9
+ top: rect.y + window.scrollY
10
+ };
11
+ };
12
+
13
+ export { getElementPosition, getOffsetTop };
14
+ //# sourceMappingURL=positionUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positionUtils.js","sources":["../src/positionUtils.ts"],"sourcesContent":["interface TopLeftPosition {\n left: number;\n top: number;\n}\n\n// Get the top position of the HTML element.\nexport const getOffsetTop = (element: HTMLElement): number =>\n getElementPosition(element).top;\n\n// Get the top left position of the HTML element.\nexport const getElementPosition = (element: HTMLElement): TopLeftPosition => {\n const rect = element.getBoundingClientRect();\n\n return {\n left: rect.x + window.scrollX,\n top: rect.y + window.scrollY,\n };\n};\n"],"names":[],"mappings":"AAKA;AACO,MAAM,YAAY,GAAI,OAAoB,IAC/C,kBAAkB,CAAC,OAAO,CAAC,CAAC;;AAE9B;AACO,MAAM,kBAAkB,GAAI,OAAoB,IAAsB;AAC3E,EAAA,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE;EAE5C,OAAO;AACL,IAAA,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,OAAO;AAC7B,IAAA,GAAG,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC;GACtB;AACH;;"}
@@ -0,0 +1,9 @@
1
+ declare class RequestUrl {
2
+ private isAbsolute;
3
+ private url;
4
+ constructor(inputUrl: string);
5
+ setSearchParam(key: string, value: string): void;
6
+ toString(): string;
7
+ }
8
+ export default RequestUrl;
9
+ //# sourceMappingURL=requestUrl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestUrl.d.ts","sourceRoot":"","sources":["../src/requestUrl.ts"],"names":[],"mappings":"AAaA,cAAM,UAAU;IACd,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,GAAG,CAAM;gBAEL,QAAQ,EAAE,MAAM;IAU5B,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAIzC,QAAQ;CAOT;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,37 @@
1
+ // Url class for absolute and relative urls.
2
+
3
+ const isAbsoluteUrl = inputUrl => {
4
+ try {
5
+ new URL(inputUrl);
6
+ return true;
7
+ } catch {
8
+ return false;
9
+ }
10
+ };
11
+ const LOCALHOST = "http://localhost";
12
+ class RequestUrl {
13
+ _isAbsolute;
14
+ _url;
15
+ constructor(inputUrl) {
16
+ if (isAbsoluteUrl(inputUrl)) {
17
+ this._url = new URL(inputUrl);
18
+ this._isAbsolute = true;
19
+ } else {
20
+ this._url = new URL(inputUrl, LOCALHOST);
21
+ this._isAbsolute = false;
22
+ }
23
+ }
24
+ setSearchParam(key, value) {
25
+ this._url.searchParams.set(key, value);
26
+ }
27
+ toString() {
28
+ if (this._isAbsolute) {
29
+ return this._url.href;
30
+ } else {
31
+ return this._url.href.slice(LOCALHOST.length);
32
+ }
33
+ }
34
+ }
35
+
36
+ export { RequestUrl as default };
37
+ //# sourceMappingURL=requestUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestUrl.js","sources":["../src/requestUrl.ts"],"sourcesContent":["// Url class for absolute and relative urls.\n\nconst isAbsoluteUrl = (inputUrl: string) => {\n try {\n new URL(inputUrl);\n return true;\n } catch {\n return false;\n }\n}\n\nconst LOCALHOST = \"http://localhost\";\n\nclass RequestUrl {\n private isAbsolute: boolean;\n private url: URL;\n\n constructor(inputUrl: string) {\n if (isAbsoluteUrl(inputUrl)) {\n this.url = new URL(inputUrl);\n this.isAbsolute = true;\n } else {\n this.url = new URL(inputUrl, LOCALHOST);\n this.isAbsolute = false;\n }\n }\n\n setSearchParam(key: string, value: string) {\n this.url.searchParams.set(key, value);\n }\n\n toString() {\n if (this.isAbsolute) {\n return this.url.href;\n } else {\n return this.url.href.slice(LOCALHOST.length);\n }\n }\n}\n\nexport default RequestUrl;"],"names":["isAbsolute","url"],"mappings":"AAAA;;AAEA,MAAM,aAAa,GAAI,QAAgB,IAAK;EAC1C,IAAI;IACF,IAAI,GAAG,CAAC,QAAQ,CAAC;AACjB,IAAA,OAAO,IAAI;AACb,EAAA,CAAC,CAAC,MAAM;AACN,IAAA,OAAO,KAAK;AACd,EAAA;AACF,CAAC;AAED,MAAM,SAAS,GAAG,kBAAkB;AAEpC,MAAM,UAAU,CAAC;EACPA,WAAU;EACVC,IAAG;EAEX,WAAW,CAAC,QAAgB,EAAE;AAC5B,IAAA,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE;AAC3B,MAAA,IAAI,CAACA,IAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC;MAC5B,IAAI,CAACD,WAAU,GAAG,IAAI;AACxB,IAAA,CAAC,MAAM;MACL,IAAI,CAACC,IAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC;MACvC,IAAI,CAACD,WAAU,GAAG,KAAK;AACzB,IAAA;AACF,EAAA;AAEA,EAAA,cAAc,CAAC,GAAW,EAAE,KAAa,EAAE;IACzC,IAAI,CAACC,IAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACvC,EAAA;AAEA,EAAA,QAAQ,GAAG;IACT,IAAI,IAAI,CAACD,WAAU,EAAE;AACnB,MAAA,OAAO,IAAI,CAACC,IAAG,CAAC,IAAI;AACtB,IAAA,CAAC,MAAM;MACL,OAAO,IAAI,CAACA,IAAG,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC;AAC9C,IAAA;AACF,EAAA;AACF;;"}
@@ -0,0 +1,46 @@
1
+ import type { AddToSelection, GetNodeById, GetSelectedNodes, GetTree, OpenNode, RefreshElements, RemoveFromSelection } from "./methodTypes.js";
2
+ import type { NodeId } from "./node.js";
3
+ import type { OnGetStateFromStorage, OnSetStateFromStorage } from "./options.js";
4
+ export interface SavedState {
5
+ open_nodes?: NodeId[];
6
+ selected_node?: NodeId[];
7
+ }
8
+ interface SaveStateHandlerParams {
9
+ addToSelection: AddToSelection;
10
+ getNodeById: GetNodeById;
11
+ getSelectedNodes: GetSelectedNodes;
12
+ getTree: GetTree;
13
+ onGetStateFromStorage?: OnGetStateFromStorage;
14
+ onSetStateFromStorage?: OnSetStateFromStorage;
15
+ openNode: OpenNode;
16
+ refreshElements: RefreshElements;
17
+ removeFromSelection: RemoveFromSelection;
18
+ saveState: boolean | string;
19
+ }
20
+ export default class SaveStateHandler {
21
+ private addToSelection;
22
+ private getNodeById;
23
+ private getSelectedNodes;
24
+ private getTree;
25
+ private onGetStateFromStorage?;
26
+ private onSetStateFromStorage?;
27
+ private openNode;
28
+ private refreshElements;
29
+ private removeFromSelection;
30
+ private saveStateOption;
31
+ constructor({ addToSelection, getNodeById, getSelectedNodes, getTree, onGetStateFromStorage, onSetStateFromStorage, openNode, refreshElements, removeFromSelection, saveState, }: SaveStateHandlerParams);
32
+ getNodeIdToBeSelected(): NodeId | null;
33
+ getState(): SavedState;
34
+ getStateFromStorage(): null | SavedState;
35
+ saveState(): void;
36
+ setInitialState(state: SavedState): boolean;
37
+ setInitialStateOnDemand(state: SavedState): Promise<void>;
38
+ private getKeyName;
39
+ private loadFromStorage;
40
+ private openInitialNodes;
41
+ private parseState;
42
+ private resetSelection;
43
+ private selectInitialNodes;
44
+ }
45
+ export {};
46
+ //# sourceMappingURL=saveStateHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"saveStateHandler.d.ts","sourceRoot":"","sources":["../src/saveStateHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,eAAe,EACf,mBAAmB,EACtB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAQ,MAAM,EAAE,MAAM,QA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AoBjB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO;IAgBrC,uBAAuB,CAChC,KAAK,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC;IA2ChB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,kBAAkB;CAe7B"}
@@ -0,0 +1,204 @@
1
+ import { isInt } from './util.js';
2
+
3
+ class SaveStateHandler {
4
+ _addToSelection;
5
+ _getNodeById;
6
+ _getSelectedNodes;
7
+ _getTree;
8
+ _onGetStateFromStorage;
9
+ _onSetStateFromStorage;
10
+ _openNode;
11
+ _refreshElements;
12
+ _removeFromSelection;
13
+ _saveStateOption;
14
+ constructor({
15
+ addToSelection,
16
+ getNodeById,
17
+ getSelectedNodes,
18
+ getTree,
19
+ onGetStateFromStorage,
20
+ onSetStateFromStorage,
21
+ openNode,
22
+ refreshElements,
23
+ removeFromSelection,
24
+ saveState
25
+ }) {
26
+ this._addToSelection = addToSelection;
27
+ this._getNodeById = getNodeById;
28
+ this._getSelectedNodes = getSelectedNodes;
29
+ this._getTree = getTree;
30
+ this._onGetStateFromStorage = onGetStateFromStorage;
31
+ this._onSetStateFromStorage = onSetStateFromStorage;
32
+ this._openNode = openNode;
33
+ this._refreshElements = refreshElements;
34
+ this._removeFromSelection = removeFromSelection;
35
+ this._saveStateOption = saveState;
36
+ }
37
+ getNodeIdToBeSelected() {
38
+ if (!this._saveStateOption) {
39
+ return null;
40
+ }
41
+ const state = this.getStateFromStorage();
42
+ if (state?.selected_node) {
43
+ return state.selected_node[0] ?? null;
44
+ } else {
45
+ return null;
46
+ }
47
+ }
48
+ getState() {
49
+ const getOpenNodeIds = () => {
50
+ const openNodes = [];
51
+ this._getTree()?.iterate(node => {
52
+ if (node.is_open && node.id && node.hasChildren()) {
53
+ openNodes.push(node.id);
54
+ }
55
+ return true;
56
+ });
57
+ return openNodes;
58
+ };
59
+ const getSelectedNodeIds = () => {
60
+ const selectedNodeIds = [];
61
+ this._getSelectedNodes().forEach(node => {
62
+ if (node.id != null) {
63
+ selectedNodeIds.push(node.id);
64
+ }
65
+ });
66
+ return selectedNodeIds;
67
+ };
68
+ return {
69
+ open_nodes: getOpenNodeIds(),
70
+ selected_node: getSelectedNodeIds()
71
+ };
72
+ }
73
+ getStateFromStorage() {
74
+ if (!this._saveStateOption) {
75
+ return null;
76
+ }
77
+ const jsonData = this._loadFromStorage();
78
+ if (jsonData) {
79
+ return this._parseState(jsonData);
80
+ } else {
81
+ return null;
82
+ }
83
+ }
84
+ saveState() {
85
+ if (!this._saveStateOption) {
86
+ return;
87
+ }
88
+ const state = JSON.stringify(this.getState());
89
+ if (this._onSetStateFromStorage) {
90
+ this._onSetStateFromStorage(state);
91
+ } else {
92
+ localStorage.setItem(this._getKeyName(), state);
93
+ }
94
+ }
95
+
96
+ /*
97
+ Set initial state
98
+ Don't handle nodes that are loaded on demand
99
+ result: must load on demand (boolean)
100
+ */
101
+ setInitialState(state) {
102
+ let mustLoadOnDemand = false;
103
+ if (state.open_nodes) {
104
+ mustLoadOnDemand = this._openInitialNodes(state.open_nodes);
105
+ }
106
+ this._resetSelection();
107
+ if (state.selected_node) {
108
+ this._selectInitialNodes(state.selected_node);
109
+ }
110
+ return mustLoadOnDemand;
111
+ }
112
+ async setInitialStateOnDemand(state) {
113
+ let nodeIds = state.open_nodes;
114
+ const openNodes = async () => {
115
+ if (!nodeIds) {
116
+ return;
117
+ }
118
+ const newNodesIds = [];
119
+ for (const nodeId of nodeIds) {
120
+ const node = this._getNodeById(nodeId);
121
+ if (!node) {
122
+ newNodesIds.push(nodeId);
123
+ } else {
124
+ if (!node.is_loading) {
125
+ if (node.load_on_demand) {
126
+ await loadAndOpenNode(node);
127
+ } else {
128
+ await this._openNode(node, false);
129
+ }
130
+ }
131
+ }
132
+ }
133
+ nodeIds = newNodesIds;
134
+ if (state.selected_node) {
135
+ if (this._selectInitialNodes(state.selected_node)) {
136
+ this._refreshElements(null);
137
+ }
138
+ }
139
+ };
140
+ const loadAndOpenNode = async node => {
141
+ await this._openNode(node, false);
142
+ await openNodes();
143
+ };
144
+ await openNodes();
145
+ }
146
+ _getKeyName() {
147
+ if (typeof this._saveStateOption === "string") {
148
+ return this._saveStateOption;
149
+ } else {
150
+ return "tree";
151
+ }
152
+ }
153
+ _loadFromStorage() {
154
+ if (this._onGetStateFromStorage) {
155
+ return this._onGetStateFromStorage();
156
+ } else {
157
+ return localStorage.getItem(this._getKeyName());
158
+ }
159
+ }
160
+ _openInitialNodes(nodeIds) {
161
+ let mustLoadOnDemand = false;
162
+ for (const nodeId of nodeIds) {
163
+ const node = this._getNodeById(nodeId);
164
+ if (node) {
165
+ if (!node.load_on_demand) {
166
+ node.is_open = true;
167
+ } else {
168
+ mustLoadOnDemand = true;
169
+ }
170
+ }
171
+ }
172
+ return mustLoadOnDemand;
173
+ }
174
+ _parseState(jsonData) {
175
+ const state = JSON.parse(jsonData);
176
+
177
+ // Check if selected_node is an int (instead of an array)
178
+ if (state.selected_node && isInt(state.selected_node)) {
179
+ // Convert to array
180
+ state.selected_node = [state.selected_node];
181
+ }
182
+ return state;
183
+ }
184
+ _resetSelection() {
185
+ const selectedNodes = this._getSelectedNodes();
186
+ selectedNodes.forEach(node => {
187
+ this._removeFromSelection(node);
188
+ });
189
+ }
190
+ _selectInitialNodes(nodeIds) {
191
+ let selectCount = 0;
192
+ for (const nodeId of nodeIds) {
193
+ const node = this._getNodeById(nodeId);
194
+ if (node) {
195
+ selectCount += 1;
196
+ this._addToSelection(node);
197
+ }
198
+ }
199
+ return selectCount !== 0;
200
+ }
201
+ }
202
+
203
+ export { SaveStateHandler as default };
204
+ //# sourceMappingURL=saveStateHandler.js.map