wunderbaum 0.13.0 → 0.14.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.
- package/LICENSE +1 -1
- package/dist/wunderbaum.css +31 -11
- package/dist/wunderbaum.css.map +1 -1
- package/dist/wunderbaum.d.ts +535 -296
- package/dist/wunderbaum.esm.js +619 -221
- package/dist/wunderbaum.esm.min.js +28 -28
- package/dist/wunderbaum.esm.min.js.map +1 -1
- package/dist/wunderbaum.umd.js +619 -221
- package/dist/wunderbaum.umd.min.js +32 -32
- package/dist/wunderbaum.umd.min.js.map +1 -1
- package/package.json +3 -2
- package/src/common.ts +23 -4
- package/src/types.ts +86 -40
- package/src/util.ts +75 -2
- package/src/wb_ext_dnd.ts +21 -20
- package/src/wb_ext_edit.ts +1 -1
- package/src/wb_ext_filter.ts +6 -2
- package/src/wb_ext_grid.ts +1 -1
- package/src/wb_extension_base.ts +16 -1
- package/src/wb_node.ts +222 -106
- package/src/wb_options.ts +169 -108
- package/src/wunderbaum.ts +351 -127
package/src/wb_options.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Wunderbaum -
|
|
2
|
+
* Wunderbaum - options
|
|
3
3
|
* Copyright (c) 2021-2025, Martin Wendt. Released under the MIT license.
|
|
4
4
|
* @VERSION, @DATE (https://github.com/mar10/wunderbaum)
|
|
5
5
|
*/
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
NavModeEnum,
|
|
21
21
|
NodeTypeDefinitionMap,
|
|
22
22
|
SelectModeType,
|
|
23
|
+
SourceType,
|
|
23
24
|
TranslationsType,
|
|
24
25
|
WbActivateEventType,
|
|
25
26
|
WbButtonClickEventType,
|
|
@@ -33,7 +34,6 @@ import {
|
|
|
33
34
|
WbIconBadgeEventResultType,
|
|
34
35
|
WbInitEventType,
|
|
35
36
|
WbKeydownEventType,
|
|
36
|
-
WbNodeData,
|
|
37
37
|
WbNodeEventType,
|
|
38
38
|
WbReceiveEventType,
|
|
39
39
|
WbRenderEventType,
|
|
@@ -42,121 +42,73 @@ import {
|
|
|
42
42
|
} from "./types";
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* Options are passed to the constructor as plain object:
|
|
45
|
+
* Properties of {@link wunderbaum.Wunderbaum.options}.
|
|
48
46
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* id: "demo",
|
|
52
|
-
* element: document.getElementById("demo-tree"),
|
|
53
|
-
* source: "url/of/data/request",
|
|
54
|
-
* ...
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* Event handlers are also passed as callbacks
|
|
59
|
-
*
|
|
60
|
-
* ```js
|
|
61
|
-
* const tree = new mar10.Wunderbaum({
|
|
62
|
-
* ...
|
|
63
|
-
* init: (e) => {
|
|
64
|
-
* console.log(`Tree ${e.tree} was initialized and loaded.`)
|
|
65
|
-
* },
|
|
66
|
-
* activate: (e) => {
|
|
67
|
-
* console.log(`Node ${e.node} was activated.`)
|
|
68
|
-
* },
|
|
69
|
-
* ...
|
|
70
|
-
* });
|
|
71
|
-
* ```
|
|
47
|
+
* This is similar, but not identical, to the options that can be passed to the
|
|
48
|
+
* constructor(@see {@link InitWunderbaumOptions}).
|
|
72
49
|
*/
|
|
73
50
|
export interface WunderbaumOptions {
|
|
74
|
-
/**
|
|
75
|
-
* The target `div` element (or selector) that shall become a Wunderbaum.
|
|
76
|
-
*/
|
|
77
|
-
element: string | HTMLDivElement;
|
|
78
|
-
/**
|
|
79
|
-
* The identifier of this tree. Used to reference the instance, especially
|
|
80
|
-
* when multiple trees are present (e.g. `tree = mar10.Wunderbaum.getTree("demo")`).
|
|
81
|
-
*
|
|
82
|
-
* Default: `"wb_" + COUNTER`.
|
|
83
|
-
*/
|
|
84
|
-
id?: string;
|
|
85
|
-
/**
|
|
86
|
-
* Define the initial tree data. Typically a URL of an endpoint that serves
|
|
87
|
-
* a JSON formatted structure, but also a callback, Promise, or static data
|
|
88
|
-
* is allowed.
|
|
89
|
-
*
|
|
90
|
-
* Default: `{}`.
|
|
91
|
-
*/
|
|
92
|
-
source?: string | Array<WbNodeData>;
|
|
93
|
-
/**
|
|
94
|
-
* Define shared attributes for multiple nodes of the same type.
|
|
95
|
-
* This allows for more compact data models. Type definitions can be passed
|
|
96
|
-
* as tree option, or be part of a `source` response.
|
|
97
|
-
*
|
|
98
|
-
* Default: `{}`.
|
|
99
|
-
*/
|
|
100
|
-
types?: NodeTypeDefinitionMap;
|
|
101
|
-
/**
|
|
102
|
-
* A list of maps that define column headers. If this option is set,
|
|
103
|
-
* Wunderbaum becomes a treegrid control instead of a plain tree.
|
|
104
|
-
* Column definitions can be passed as tree option, or be part of a `source`
|
|
105
|
-
* response.
|
|
106
|
-
* Default: `[]` meaning this is a plain tree.
|
|
107
|
-
*/
|
|
108
|
-
columns?: ColumnDefinitionList;
|
|
109
51
|
/**
|
|
110
52
|
* If true, add a `wb-skeleton` class to all nodes, that will result in a
|
|
111
53
|
* 'glow' effect. Typically used with initial dummy nodes, while loading the
|
|
112
54
|
* real data.
|
|
113
|
-
*
|
|
55
|
+
* @default false.
|
|
114
56
|
*/
|
|
115
|
-
skeleton
|
|
57
|
+
skeleton: boolean;
|
|
116
58
|
/**
|
|
117
59
|
* Translation map for some system messages.
|
|
118
60
|
*/
|
|
119
|
-
strings
|
|
61
|
+
strings: TranslationsType;
|
|
120
62
|
/**
|
|
121
63
|
* 0:quiet, 1:errors, 2:warnings, 3:info, 4:verbose
|
|
122
|
-
*
|
|
64
|
+
* @default 3 (4 in local debug environment)
|
|
123
65
|
*/
|
|
124
|
-
debugLevel
|
|
66
|
+
debugLevel: number;
|
|
125
67
|
/**
|
|
126
68
|
* Number of levels that are forced to be expanded, and have no expander icon.
|
|
127
69
|
* E.g. 1 would keep all toplevel nodes expanded.
|
|
128
|
-
*
|
|
70
|
+
* @default 0
|
|
129
71
|
*/
|
|
130
|
-
minExpandLevel
|
|
72
|
+
minExpandLevel: number;
|
|
131
73
|
/**
|
|
132
74
|
* If true, allow to expand parent nodes, even if `node.children` conatains
|
|
133
75
|
* an empty array (`[]`). This is the the behavior of macOS Finder, for example.
|
|
134
|
-
*
|
|
76
|
+
* @default false
|
|
135
77
|
*/
|
|
136
|
-
emptyChildListExpandable
|
|
78
|
+
emptyChildListExpandable: boolean;
|
|
137
79
|
// escapeTitles: boolean;
|
|
138
80
|
// /**
|
|
139
81
|
// * Height of the header row div.
|
|
140
|
-
// *
|
|
82
|
+
// * @default 22
|
|
141
83
|
// */
|
|
142
84
|
// headerHeightPx: number;
|
|
143
85
|
/**
|
|
144
86
|
* Height of a node row div.
|
|
145
|
-
*
|
|
87
|
+
* @default 22
|
|
146
88
|
*/
|
|
147
|
-
rowHeightPx
|
|
89
|
+
rowHeightPx: number;
|
|
148
90
|
/**
|
|
149
91
|
* Icon font definition. May be a string (e.g. "fontawesome6" or "bootstrap")
|
|
150
92
|
* or a map of `iconName: iconClass` pairs.
|
|
151
93
|
* Note: the icon font must be loaded separately.
|
|
152
|
-
*
|
|
94
|
+
* In order to only override some defauöt icons, use this pattern:
|
|
95
|
+
* ```js
|
|
96
|
+
* const tree = new mar10.Wunderbaum({
|
|
97
|
+
* ...
|
|
98
|
+
* iconMap: Object.assign(Wunderbaum.iconMaps.bootstrap, {
|
|
99
|
+
* folder: "bi bi-archive",
|
|
100
|
+
* }),
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
|
|
104
|
+
* @default "bootstrap"
|
|
153
105
|
*/
|
|
154
|
-
iconMap
|
|
106
|
+
iconMap: string | IconMapType;
|
|
155
107
|
/**
|
|
156
108
|
* Collapse siblings when a node is expanded.
|
|
157
|
-
*
|
|
109
|
+
* @default false
|
|
158
110
|
*/
|
|
159
|
-
autoCollapse
|
|
111
|
+
autoCollapse: boolean;
|
|
160
112
|
/**
|
|
161
113
|
* If true, the tree will automatically adjust its height to fit the parent
|
|
162
114
|
* container. This is useful when the tree is embedded in a container with
|
|
@@ -170,16 +122,16 @@ export interface WunderbaumOptions {
|
|
|
170
122
|
*
|
|
171
123
|
* @default: true
|
|
172
124
|
*/
|
|
173
|
-
adjustHeight
|
|
125
|
+
adjustHeight: boolean;
|
|
174
126
|
/**
|
|
175
127
|
* HTMLElement or selector that receives the top nodes breadcrumb.
|
|
176
|
-
*
|
|
128
|
+
* @default undefined
|
|
177
129
|
*/
|
|
178
|
-
connectTopBreadcrumb
|
|
130
|
+
connectTopBreadcrumb: HTMLElement | string | null;
|
|
179
131
|
/**
|
|
180
|
-
*
|
|
132
|
+
* @default NavModeEnum.startRow
|
|
181
133
|
*/
|
|
182
|
-
navigationModeOption
|
|
134
|
+
navigationModeOption: NavModeEnum;
|
|
183
135
|
/**
|
|
184
136
|
* Show/hide header (default: null)
|
|
185
137
|
* null: assume false for plain tree and true for grids.
|
|
@@ -187,17 +139,27 @@ export interface WunderbaumOptions {
|
|
|
187
139
|
* true: display a header (use tree's id as text for plain trees)
|
|
188
140
|
* false: do not display a header
|
|
189
141
|
*/
|
|
190
|
-
header
|
|
142
|
+
header: boolean | string | null;
|
|
191
143
|
/**
|
|
192
|
-
*
|
|
144
|
+
* Show a `<progress>` element while loading data.
|
|
145
|
+
* @default false.
|
|
146
|
+
*/
|
|
147
|
+
showSpinner: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Generate missing keys by hashing a combination of refKey (or title) and
|
|
150
|
+
* the parent key. This is useful when the source data does not contain unique
|
|
151
|
+
* keys but we want stable keys for persisting the active node, selection or
|
|
152
|
+
* expansion state. Note that this still assumes that the same refKey must not
|
|
153
|
+
* appear twice in the same parent node.
|
|
154
|
+
* @default false.
|
|
193
155
|
*/
|
|
194
|
-
|
|
156
|
+
autoKeys: boolean;
|
|
195
157
|
/**
|
|
196
158
|
* If true, render a checkbox before the node tile to allow selection with the
|
|
197
159
|
* mouse. Pass `"radio"` to render a radio button instead.
|
|
198
|
-
*
|
|
160
|
+
* @default false.
|
|
199
161
|
*/
|
|
200
|
-
checkbox
|
|
162
|
+
checkbox: DynamicCheckboxOption;
|
|
201
163
|
/** Optional callback to render icons per node. */
|
|
202
164
|
icon?: DynamicIconOption;
|
|
203
165
|
/** Optional callback to render a tooltip for the icon. */
|
|
@@ -209,65 +171,79 @@ export interface WunderbaumOptions {
|
|
|
209
171
|
/** Optional callback to make a node unselectable. */
|
|
210
172
|
unselectable?: DynamicBoolOption;
|
|
211
173
|
// /**
|
|
212
|
-
// *
|
|
174
|
+
// * @default 200
|
|
213
175
|
// */
|
|
214
176
|
// updateThrottleWait?: number;
|
|
215
177
|
/**
|
|
216
|
-
*
|
|
178
|
+
* @default true
|
|
217
179
|
*/
|
|
218
|
-
enabled
|
|
180
|
+
enabled: boolean;
|
|
219
181
|
/**
|
|
220
|
-
*
|
|
182
|
+
*
|
|
183
|
+
* @default false
|
|
221
184
|
*/
|
|
222
|
-
fixedCol
|
|
185
|
+
fixedCol: boolean;
|
|
223
186
|
/**
|
|
224
187
|
* Default value for ColumnDefinition.filterable option.
|
|
225
|
-
*
|
|
188
|
+
* @default false
|
|
226
189
|
* @since 0.11.0
|
|
227
190
|
*/
|
|
228
|
-
columnsFilterable
|
|
191
|
+
columnsFilterable: boolean;
|
|
229
192
|
/**
|
|
230
193
|
* Default value for ColumnDefinition.menu option.
|
|
231
|
-
*
|
|
194
|
+
* @default false
|
|
232
195
|
* @since 0.11.0
|
|
233
196
|
*/
|
|
234
|
-
columnsMenu
|
|
197
|
+
columnsMenu: boolean;
|
|
235
198
|
/**
|
|
236
199
|
* Default value for ColumnDefinition.resizable option.
|
|
237
|
-
*
|
|
200
|
+
* @default false
|
|
238
201
|
* @since 0.10.0
|
|
239
202
|
*/
|
|
240
203
|
columnsResizable?: boolean;
|
|
241
204
|
/**
|
|
242
205
|
* Default value for ColumnDefinition.sortable option.
|
|
243
|
-
*
|
|
206
|
+
* @default false
|
|
244
207
|
* @since 0.11.0
|
|
245
208
|
*/
|
|
246
209
|
columnsSortable?: boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Group nodes with children or of `type: 'folder'` at the top when sorting.
|
|
212
|
+
* If a function is passed, it is called with the node as argument to determine
|
|
213
|
+
* whether the node is a folder or not. The function should return `true` for
|
|
214
|
+
* folders.
|
|
215
|
+
* and should return `true` for folders.
|
|
216
|
+
* @default false
|
|
217
|
+
* @since 0.14.0
|
|
218
|
+
*/
|
|
219
|
+
sortFoldersFirst?: DynamicBoolOption;
|
|
247
220
|
|
|
248
221
|
// --- Selection ---
|
|
249
222
|
/**
|
|
250
|
-
*
|
|
223
|
+
* @default "multi"
|
|
251
224
|
*/
|
|
252
|
-
selectMode
|
|
225
|
+
selectMode: SelectModeType;
|
|
253
226
|
|
|
254
227
|
// --- KeyNav ---
|
|
255
228
|
/**
|
|
256
|
-
*
|
|
229
|
+
* @default true
|
|
257
230
|
*/
|
|
258
|
-
quicksearch
|
|
231
|
+
quicksearch: boolean;
|
|
259
232
|
|
|
260
233
|
/**
|
|
261
234
|
* Scroll Node into view on Expand Click
|
|
262
235
|
* @default true
|
|
263
236
|
*/
|
|
264
|
-
scrollIntoViewOnExpandClick
|
|
237
|
+
scrollIntoViewOnExpandClick: boolean;
|
|
265
238
|
|
|
266
239
|
// --- Extensions ------------------------------------------------------------
|
|
267
240
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
241
|
+
/** Configuration options for the drag-and-drop extension. */
|
|
242
|
+
dnd: DndOptionsType;
|
|
243
|
+
/** Configuration options for the edit-title extension. */
|
|
244
|
+
edit: EditOptionsType;
|
|
245
|
+
/** Configuration options for the node-filter extension. */
|
|
246
|
+
filter: FilterOptionsType;
|
|
271
247
|
// grid?: GridOptionsType;
|
|
272
248
|
// keynav?: KeynavOptionsType;
|
|
273
249
|
// logger?: LoggerOptionsType;
|
|
@@ -418,3 +394,88 @@ export interface WunderbaumOptions {
|
|
|
418
394
|
*/
|
|
419
395
|
update?: (e: WbTreeEventType) => void;
|
|
420
396
|
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Available options for {@link wunderbaum.Wunderbaum}.
|
|
400
|
+
*
|
|
401
|
+
* Options are passed to the constructor as plain object:
|
|
402
|
+
*
|
|
403
|
+
* ```js
|
|
404
|
+
* const tree = new mar10.Wunderbaum({
|
|
405
|
+
* id: "demo",
|
|
406
|
+
* element: document.getElementById("demo-tree"),
|
|
407
|
+
* source: "url/of/data/request",
|
|
408
|
+
* ...
|
|
409
|
+
* });
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* Event handlers are also passed as callbacks
|
|
413
|
+
*
|
|
414
|
+
* ```js
|
|
415
|
+
* const tree = new mar10.Wunderbaum({
|
|
416
|
+
* ...
|
|
417
|
+
* init: (e) => {
|
|
418
|
+
* console.log(`Tree ${e.tree} was initialized and loaded.`)
|
|
419
|
+
* },
|
|
420
|
+
* activate: (e) => {
|
|
421
|
+
* console.log(`Node ${e.node} was activated.`)
|
|
422
|
+
* },
|
|
423
|
+
* ...
|
|
424
|
+
* });
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* Most of the properties are optional and have resonable default.
|
|
428
|
+
* They are then available as {@link Wunderbaum.options} property and can be
|
|
429
|
+
* changed at runtime. <br>
|
|
430
|
+
* Only the `element` option is mandatory.
|
|
431
|
+
*
|
|
432
|
+
* Note that some options passed here, are *not* available as {@link Wunderbaum.options}.
|
|
433
|
+
* They are moved to the `tree` instance instead:
|
|
434
|
+
* - `tree.element`
|
|
435
|
+
* - `tree.id`
|
|
436
|
+
* - `tree.columns`
|
|
437
|
+
* - `tree.types`
|
|
438
|
+
* - ...
|
|
439
|
+
*
|
|
440
|
+
* Some options are only used during initialization and are not stored in the
|
|
441
|
+
* tree instance:
|
|
442
|
+
* - `source`
|
|
443
|
+
*
|
|
444
|
+
*/
|
|
445
|
+
export interface InitWunderbaumOptions extends Partial<WunderbaumOptions> {
|
|
446
|
+
/**
|
|
447
|
+
* The target `div` element (or selector) that shall become a Wunderbaum.
|
|
448
|
+
*/
|
|
449
|
+
element: string | HTMLDivElement;
|
|
450
|
+
/**
|
|
451
|
+
* The identifier of this tree. Used to reference the instance, especially
|
|
452
|
+
* when multiple trees are present (e.g. `tree = mar10.Wunderbaum.getTree("demo")`).
|
|
453
|
+
*
|
|
454
|
+
* @default `"wb_" + COUNTER`.
|
|
455
|
+
*/
|
|
456
|
+
id?: string;
|
|
457
|
+
/**
|
|
458
|
+
* A list of maps that define column headers. If this option is set,
|
|
459
|
+
* Wunderbaum becomes a treegrid control instead of a plain tree.
|
|
460
|
+
* Column definitions can be passed as tree option, or be part of a `source`
|
|
461
|
+
* response.
|
|
462
|
+
* @default `[]` meaning this is a plain tree.
|
|
463
|
+
*/
|
|
464
|
+
columns?: ColumnDefinitionList;
|
|
465
|
+
/**
|
|
466
|
+
* Define shared attributes for multiple nodes of the same type.
|
|
467
|
+
* This allows for more compact data models. Type definitions can be passed
|
|
468
|
+
* as tree option, or be part of a `source` response.
|
|
469
|
+
*
|
|
470
|
+
* @default `{}`.
|
|
471
|
+
*/
|
|
472
|
+
types?: NodeTypeDefinitionMap;
|
|
473
|
+
/**
|
|
474
|
+
* Define the initial tree data. Typically a URL of an endpoint that serves
|
|
475
|
+
* a JSON formatted structure, but also a callback, Promise, or static data
|
|
476
|
+
* is allowed.
|
|
477
|
+
*
|
|
478
|
+
* @default `[]`.
|
|
479
|
+
*/
|
|
480
|
+
source?: SourceType;
|
|
481
|
+
}
|