@schukai/monster 3.72.0 → 3.73.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.
@@ -12,37 +12,38 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import {buildTree} from "../../data/buildtree.mjs";
16
- import {Datasource} from "../datatable/datasource.mjs";
17
- import {addAttributeToken} from "../../dom/attributes.mjs";
15
+ import { buildTree } from "../../data/buildtree.mjs";
16
+ import { Datasource } from "../datatable/datasource.mjs";
17
+ import { addAttributeToken } from "../../dom/attributes.mjs";
18
18
  import {
19
- ATTRIBUTE_ERRORMESSAGE,
20
- ATTRIBUTE_ROLE,
21
- ATTRIBUTE_UPDATER_INSERT_REFERENCE,
19
+ ATTRIBUTE_ERRORMESSAGE,
20
+ ATTRIBUTE_ROLE,
21
+ ATTRIBUTE_UPDATER_INSERT_REFERENCE,
22
22
  } from "../../dom/constants.mjs";
23
23
  import {
24
- assembleMethodSymbol,
25
- CustomElement, getSlottedElements,
26
- initMethodSymbol,
27
- registerCustomElement,
24
+ assembleMethodSymbol,
25
+ CustomElement,
26
+ getSlottedElements,
27
+ initMethodSymbol,
28
+ registerCustomElement,
28
29
  } from "../../dom/customelement.mjs";
29
- import {findTargetElementFromEvent} from "../../dom/events.mjs";
30
- import {findElementWithSelectorUpwards} from "../../dom/util.mjs";
31
- import {Formatter} from "../../text/formatter.mjs";
32
- import {isFunction, isString} from "../../types/is.mjs";
33
- import {Node} from "../../types/node.mjs";
34
- import {NodeRecursiveIterator} from "../../types/noderecursiveiterator.mjs";
35
- import {Observer} from "../../types/observer.mjs";
36
- import {validateInstance} from "../../types/validate.mjs";
30
+ import { findTargetElementFromEvent } from "../../dom/events.mjs";
31
+ import { findElementWithSelectorUpwards } from "../../dom/util.mjs";
32
+ import { Formatter } from "../../text/formatter.mjs";
33
+ import { isFunction, isString } from "../../types/is.mjs";
34
+ import { Node } from "../../types/node.mjs";
35
+ import { NodeRecursiveIterator } from "../../types/noderecursiveiterator.mjs";
36
+ import { Observer } from "../../types/observer.mjs";
37
+ import { validateInstance } from "../../types/validate.mjs";
37
38
  import {
38
- datasourceLinkedElementSymbol,
39
- handleDataSourceChanges,
39
+ datasourceLinkedElementSymbol,
40
+ handleDataSourceChanges,
40
41
  } from "../datatable/util.mjs";
41
- import {ATTRIBUTE_INTEND} from "./../constants.mjs";
42
- import {CommonStyleSheet} from "../stylesheet/common.mjs";
43
- import {TreeMenuStyleSheet} from "./stylesheet/tree-menu.mjs";
42
+ import { ATTRIBUTE_INTEND } from "./../constants.mjs";
43
+ import { CommonStyleSheet } from "../stylesheet/common.mjs";
44
+ import { TreeMenuStyleSheet } from "./stylesheet/tree-menu.mjs";
44
45
 
45
- export {TreeMenu};
46
+ export { TreeMenu };
46
47
 
47
48
  /**
48
49
  * @private
@@ -99,353 +100,346 @@ const openEntryEventHandlerSymbol = Symbol("openEntryEventHandler");
99
100
  * @fires Monster.Components.TreeMenu.event:monster-fetched
100
101
  */
101
102
  class TreeMenu extends CustomElement {
102
-
103
- constructor() {
104
- super();
105
- this[preventChangeSymbol] = false;
106
- }
107
-
108
- /**
109
- * This method is called internal and should not be called directly.
110
- *
111
- * The defaults can be set either directly in the object or via an attribute in the HTML tag.
112
- * The value of the attribute `data-monster-options` in the HTML tag must be a JSON string.
113
- *
114
- * ```
115
- * <monster-treemenu data-monster-options="{}"></monster-treemenu>
116
- * ```
117
- *
118
- * Since 1.18.0 the JSON can be specified as a DataURI.
119
- *
120
- * ```
121
- * new Monster.Types.DataUrl(btoa(JSON.stringify({
122
- * shadowMode: 'open',
123
- * })),'application/json',true).toString()
124
- * ```
125
- * @property {Object} templates Template definitions
126
- * @property {string} templates.main Main template
127
- * @property {Datasource} datasource data source
128
- * @property {Object} mapping
129
- * @property {String} mapping.selector=* Path to select the appropriate entries
130
- * @property {String} mapping.labelTemplate="" template with the label placeholders in the form ${name}, where name is the key
131
- * @property {String} mapping.keyTemplate="" template with the key placeholders in the form ${name}, where name is the key
132
- * @property {String} mapping.rootReferences=['0', undefined, null]
133
- * @property {String} mapping.idTemplate=id
134
- * @property {String} mapping.parentKey=parent
135
- * @property {String} mapping.selection
136
- */
137
- get defaults() {
138
- return Object.assign({}, super.defaults, {
139
-
140
- classes: {
141
- control: "monster-theme-primary-1",
142
- label: "monster-theme-primary-1"
143
- },
144
-
145
- mapping: {
146
- rootReferences: ["0", undefined, null],
147
- idTemplate: "id",
148
- parentKey: "parent",
149
- selector: "*",
150
- labelTemplate: "",
151
- valueTemplate: "",
152
- iconTemplate: "",
153
- filter: undefined,
154
- },
155
-
156
- templates: {
157
- main: getTemplate(),
158
- },
159
-
160
- datasource: {
161
- selector: null,
162
- },
163
-
164
- actions: {
165
- "open": null,
166
- "close": null,
167
- "select": (entry) => {
168
- throw new Error("no action defined for select");
169
- },
170
-
171
- },
172
-
173
- data: [],
174
- entries: [],
175
- });
176
- }
177
-
178
- /**
179
- *
180
- */
181
- [initMethodSymbol]() {
182
- super[initMethodSymbol]();
183
- }
184
-
185
- /**
186
- * @return {void}
187
- */
188
- [assembleMethodSymbol]() {
189
- super[assembleMethodSymbol]();
190
-
191
- initControlReferences.call(this);
192
- initEventHandler.call(this);
193
- initObserver.call(this);
194
- setTimeout(() => {
195
- copyIconMap.call(this);
196
- }, 0)
197
- }
198
-
199
- /**
200
- * This method is called internal and should not be called directly.
201
- *
202
- * @return {CSSStyleSheet[]}
203
- */
204
- static getCSSStyleSheet() {
205
- return [CommonStyleSheet, TreeMenuStyleSheet];
206
- }
207
-
208
- /**
209
- * This method is called internal and should not be called directly.
210
- *
211
- * @return {string}
212
- */
213
- static getTag() {
214
- return "monster-tree-menu";
215
- }
216
-
217
- /**
218
- * @param {string} value
219
- * @param value
220
- */
221
- selectEntry(value) {
222
- this.shadowRoot.querySelectorAll("[data-monster-role=entry]").forEach((entry) => {
223
- entry.classList.remove("selected");
224
- })
225
-
226
- value = String(value);
227
-
228
- const entries = this.getOption("entries");
229
- const index = entries.findIndex((entry) => entry.value === value);
230
-
231
- if (index === -1) {
232
- return;
233
- }
234
-
235
- const currentNode = this.shadowRoot.querySelector("[data-monster-insert-reference=entries-" + index + "]")
236
-
237
- console.log(currentNode)
238
-
239
- currentNode.click();
240
-
241
- let intend = parseInt(currentNode.getAttribute(ATTRIBUTE_INTEND));
242
-
243
- if (intend > 0) {
244
- let ref = currentNode.previousElementSibling;
245
- while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) {
246
- const i = parseInt(ref.getAttribute(ATTRIBUTE_INTEND));
247
-
248
- if (isNaN(i)) {
249
- break;
250
- }
251
-
252
- if (i < intend) {
253
-
254
- if (ref.getAttribute("data-monster-state") !== "open") {
255
- ref.click()
256
- }
257
-
258
- if (i === 0) {
259
- break;
260
- }
261
- intend = i;
262
- }
263
- ref = ref.previousElementSibling;
264
- }
265
- }
266
-
267
- }
268
-
269
-
103
+ constructor() {
104
+ super();
105
+ this[preventChangeSymbol] = false;
106
+ }
107
+
108
+ /**
109
+ * This method is called internal and should not be called directly.
110
+ *
111
+ * The defaults can be set either directly in the object or via an attribute in the HTML tag.
112
+ * The value of the attribute `data-monster-options` in the HTML tag must be a JSON string.
113
+ *
114
+ * ```
115
+ * <monster-treemenu data-monster-options="{}"></monster-treemenu>
116
+ * ```
117
+ *
118
+ * Since 1.18.0 the JSON can be specified as a DataURI.
119
+ *
120
+ * ```
121
+ * new Monster.Types.DataUrl(btoa(JSON.stringify({
122
+ * shadowMode: 'open',
123
+ * })),'application/json',true).toString()
124
+ * ```
125
+ * @property {Object} templates Template definitions
126
+ * @property {string} templates.main Main template
127
+ * @property {Datasource} datasource data source
128
+ * @property {Object} mapping
129
+ * @property {String} mapping.selector=* Path to select the appropriate entries
130
+ * @property {String} mapping.labelTemplate="" template with the label placeholders in the form ${name}, where name is the key
131
+ * @property {String} mapping.keyTemplate="" template with the key placeholders in the form ${name}, where name is the key
132
+ * @property {String} mapping.rootReferences=['0', undefined, null]
133
+ * @property {String} mapping.idTemplate=id
134
+ * @property {String} mapping.parentKey=parent
135
+ * @property {String} mapping.selection
136
+ */
137
+ get defaults() {
138
+ return Object.assign({}, super.defaults, {
139
+ classes: {
140
+ control: "monster-theme-primary-1",
141
+ label: "monster-theme-primary-1",
142
+ },
143
+
144
+ mapping: {
145
+ rootReferences: ["0", undefined, null],
146
+ idTemplate: "id",
147
+ parentKey: "parent",
148
+ selector: "*",
149
+ labelTemplate: "",
150
+ valueTemplate: "",
151
+ iconTemplate: "",
152
+ filter: undefined,
153
+ },
154
+
155
+ templates: {
156
+ main: getTemplate(),
157
+ },
158
+
159
+ datasource: {
160
+ selector: null,
161
+ },
162
+
163
+ actions: {
164
+ open: null,
165
+ close: null,
166
+ select: (entry) => {
167
+ throw new Error("no action defined for select");
168
+ },
169
+ },
170
+
171
+ data: [],
172
+ entries: [],
173
+ });
174
+ }
175
+
176
+ /**
177
+ *
178
+ */
179
+ [initMethodSymbol]() {
180
+ super[initMethodSymbol]();
181
+ }
182
+
183
+ /**
184
+ * @return {void}
185
+ */
186
+ [assembleMethodSymbol]() {
187
+ super[assembleMethodSymbol]();
188
+
189
+ initControlReferences.call(this);
190
+ initEventHandler.call(this);
191
+ initObserver.call(this);
192
+ setTimeout(() => {
193
+ copyIconMap.call(this);
194
+ }, 0);
195
+ }
196
+
197
+ /**
198
+ * This method is called internal and should not be called directly.
199
+ *
200
+ * @return {CSSStyleSheet[]}
201
+ */
202
+ static getCSSStyleSheet() {
203
+ return [CommonStyleSheet, TreeMenuStyleSheet];
204
+ }
205
+
206
+ /**
207
+ * This method is called internal and should not be called directly.
208
+ *
209
+ * @return {string}
210
+ */
211
+ static getTag() {
212
+ return "monster-tree-menu";
213
+ }
214
+
215
+ /**
216
+ * @param {string} value
217
+ * @param value
218
+ */
219
+ selectEntry(value) {
220
+ this.shadowRoot
221
+ .querySelectorAll("[data-monster-role=entry]")
222
+ .forEach((entry) => {
223
+ entry.classList.remove("selected");
224
+ });
225
+
226
+ value = String(value);
227
+
228
+ const entries = this.getOption("entries");
229
+ const index = entries.findIndex((entry) => entry.value === value);
230
+
231
+ if (index === -1) {
232
+ return;
233
+ }
234
+
235
+ const currentNode = this.shadowRoot.querySelector(
236
+ "[data-monster-insert-reference=entries-" + index + "]",
237
+ );
238
+
239
+ console.log(currentNode);
240
+
241
+ currentNode.click();
242
+
243
+ let intend = parseInt(currentNode.getAttribute(ATTRIBUTE_INTEND));
244
+
245
+ if (intend > 0) {
246
+ let ref = currentNode.previousElementSibling;
247
+ while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) {
248
+ const i = parseInt(ref.getAttribute(ATTRIBUTE_INTEND));
249
+
250
+ if (isNaN(i)) {
251
+ break;
252
+ }
253
+
254
+ if (i < intend) {
255
+ if (ref.getAttribute("data-monster-state") !== "open") {
256
+ ref.click();
257
+ }
258
+
259
+ if (i === 0) {
260
+ break;
261
+ }
262
+ intend = i;
263
+ }
264
+ ref = ref.previousElementSibling;
265
+ }
266
+ }
267
+ }
270
268
  }
271
269
 
272
270
  /**
273
271
  * @private
274
272
  */
275
273
  function copyIconMap() {
276
- const nodes = getSlottedElements.call(this, "svg", null);
277
- if (nodes.size > 0) {
278
- for (const node of nodes) {
279
- this.shadowRoot.appendChild(node);
280
- }
281
- }
274
+ const nodes = getSlottedElements.call(this, "svg", null);
275
+ if (nodes.size > 0) {
276
+ for (const node of nodes) {
277
+ this.shadowRoot.appendChild(node);
278
+ }
279
+ }
282
280
  }
283
281
 
284
282
  /**
285
283
  * @private
286
284
  */
287
285
  function initEventHandler() {
288
- const selector = this.getOption("datasource.selector");
289
-
290
- if (isString(selector)) {
291
- const element = findElementWithSelectorUpwards(this, selector);
292
- if (element === null) {
293
- throw new Error("the selector must match exactly one element");
294
- }
295
-
296
- if (!(element instanceof HTMLElement)) {
297
- throw new TypeError("the element must be an HTMLElement");
298
- }
299
-
300
- customElements.whenDefined(element.tagName.toLocaleLowerCase()).then(() => {
301
- if (!(element instanceof Datasource)) {
302
- throw new TypeError("the element must be a datasource");
303
- }
304
-
305
- this[datasourceLinkedElementSymbol] = element;
306
-
307
- handleDataSourceChanges.call(this);
308
- element.datasource.attachObserver(
309
- new Observer(handleDataSourceChanges.bind(this)),
310
- );
311
-
312
- this.attachObserver(
313
- new Observer(() => {
314
- if (this[preventChangeSymbol] === true) {
315
- return
316
- }
317
- this[preventChangeSymbol] = true
318
- importEntries.call(this);
319
- }),
320
- );
321
- });
322
- }
323
-
324
- this[openEntryEventHandlerSymbol] = (event) => {
325
-
326
- const container = findTargetElementFromEvent(
327
- event,
328
- ATTRIBUTE_ROLE,
329
- "entry",
330
- );
331
-
332
- if (!(container instanceof HTMLElement)) {
333
- return;
334
- }
335
-
336
- const index = container
337
- .getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE)
338
- .split("-")
339
- .pop();
340
-
341
- const currentEntry = this.getOption("entries." + index);
342
-
343
- if (currentEntry["has-children"] === false) {
344
- const doAction = this.getOption("actions.select");
345
-
346
- this.shadowRoot.querySelectorAll("[data-monster-role=entry].selected").forEach((entry) => {
347
- entry.classList.remove("selected");
348
- })
349
-
350
- let intend = currentEntry.intend;
351
- if (intend > 0) {
352
- let ref = container.previousElementSibling;
353
- while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) {
354
- const i = parseInt(ref.getAttribute(ATTRIBUTE_INTEND));
355
-
356
- if (isNaN(i)) {
357
- break;
358
- }
359
-
360
- if (i < intend) {
361
- ref.classList.add("selected");
362
- if (i === 0) {
363
- break;
364
- }
365
- intend = i;
366
- }
367
- ref = ref.previousElementSibling;
368
- }
369
- }
370
-
371
- container.classList.add("selected");
372
-
373
- if (isFunction(doAction)) {
374
- doAction.call(this, currentEntry, index);
375
- }
376
- return;
377
- }
378
-
379
- const currentState = this.getOption("entries." + index + ".state");
380
-
381
- const newState = currentState === "close" ? "open" : "close";
382
-
383
- const doAction = this.getOption("actions." + newState);
384
- if (isFunction(doAction)) {
385
- doAction.call(this, this.getOption("entries." + index), index);
386
- }
387
-
388
- this.setOption("entries." + index + ".state", newState);
389
- const newVisibility = (newState === "open") ? "visible" : "hidden";
390
-
391
- if (container.hasAttribute(ATTRIBUTE_INTEND)) {
392
- const intend = container.getAttribute(ATTRIBUTE_INTEND);
393
- let ref = container.nextElementSibling;
394
- const childIntend = parseInt(intend) + 1;
395
-
396
- const cmp = (a, b) => {
397
- if (newState === "open") {
398
- return a === b;
399
- }
400
-
401
- return a >= b;
402
- };
403
-
404
- while (
405
- ref &&
406
- ref.hasAttribute(ATTRIBUTE_INTEND)
407
- ) {
408
-
409
- const refIntend = ref.getAttribute(ATTRIBUTE_INTEND);
410
-
411
- if (!cmp(parseInt(refIntend), childIntend)) {
412
- if (refIntend === intend) {
413
- break;
414
- }
415
- ref = ref.nextElementSibling;
416
- continue;
417
- }
418
-
419
- const refIndex = ref
420
- .getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE)
421
- .split("-")
422
- .pop();
423
-
424
- this.setOption("entries." + refIndex + ".visibility", newVisibility);
425
-
426
- if (newState === "close") {
427
- this.setOption("entries." + refIndex + ".state", "close");
428
- }
429
-
430
- ref = ref.nextElementSibling;
431
- }
432
- }
433
- };
434
-
435
- const types = this.getOption("toggleEventType", ["click"]);
436
- for (const [, type] of Object.entries(types)) {
437
- this.shadowRoot.addEventListener(type, this[openEntryEventHandlerSymbol]);
438
- }
439
-
440
- return this;
286
+ const selector = this.getOption("datasource.selector");
287
+
288
+ if (isString(selector)) {
289
+ const element = findElementWithSelectorUpwards(this, selector);
290
+ if (element === null) {
291
+ throw new Error("the selector must match exactly one element");
292
+ }
293
+
294
+ if (!(element instanceof HTMLElement)) {
295
+ throw new TypeError("the element must be an HTMLElement");
296
+ }
297
+
298
+ customElements.whenDefined(element.tagName.toLocaleLowerCase()).then(() => {
299
+ if (!(element instanceof Datasource)) {
300
+ throw new TypeError("the element must be a datasource");
301
+ }
302
+
303
+ this[datasourceLinkedElementSymbol] = element;
304
+
305
+ handleDataSourceChanges.call(this);
306
+ element.datasource.attachObserver(
307
+ new Observer(handleDataSourceChanges.bind(this)),
308
+ );
309
+
310
+ this.attachObserver(
311
+ new Observer(() => {
312
+ if (this[preventChangeSymbol] === true) {
313
+ return;
314
+ }
315
+ this[preventChangeSymbol] = true;
316
+ importEntries.call(this);
317
+ }),
318
+ );
319
+ });
320
+ }
321
+
322
+ this[openEntryEventHandlerSymbol] = (event) => {
323
+ const container = findTargetElementFromEvent(
324
+ event,
325
+ ATTRIBUTE_ROLE,
326
+ "entry",
327
+ );
328
+
329
+ if (!(container instanceof HTMLElement)) {
330
+ return;
331
+ }
332
+
333
+ const index = container
334
+ .getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE)
335
+ .split("-")
336
+ .pop();
337
+
338
+ const currentEntry = this.getOption("entries." + index);
339
+
340
+ if (currentEntry["has-children"] === false) {
341
+ const doAction = this.getOption("actions.select");
342
+
343
+ this.shadowRoot
344
+ .querySelectorAll("[data-monster-role=entry].selected")
345
+ .forEach((entry) => {
346
+ entry.classList.remove("selected");
347
+ });
348
+
349
+ let intend = currentEntry.intend;
350
+ if (intend > 0) {
351
+ let ref = container.previousElementSibling;
352
+ while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) {
353
+ const i = parseInt(ref.getAttribute(ATTRIBUTE_INTEND));
354
+
355
+ if (isNaN(i)) {
356
+ break;
357
+ }
358
+
359
+ if (i < intend) {
360
+ ref.classList.add("selected");
361
+ if (i === 0) {
362
+ break;
363
+ }
364
+ intend = i;
365
+ }
366
+ ref = ref.previousElementSibling;
367
+ }
368
+ }
369
+
370
+ container.classList.add("selected");
371
+
372
+ if (isFunction(doAction)) {
373
+ doAction.call(this, currentEntry, index);
374
+ }
375
+ return;
376
+ }
377
+
378
+ const currentState = this.getOption("entries." + index + ".state");
379
+
380
+ const newState = currentState === "close" ? "open" : "close";
381
+
382
+ const doAction = this.getOption("actions." + newState);
383
+ if (isFunction(doAction)) {
384
+ doAction.call(this, this.getOption("entries." + index), index);
385
+ }
386
+
387
+ this.setOption("entries." + index + ".state", newState);
388
+ const newVisibility = newState === "open" ? "visible" : "hidden";
389
+
390
+ if (container.hasAttribute(ATTRIBUTE_INTEND)) {
391
+ const intend = container.getAttribute(ATTRIBUTE_INTEND);
392
+ let ref = container.nextElementSibling;
393
+ const childIntend = parseInt(intend) + 1;
394
+
395
+ const cmp = (a, b) => {
396
+ if (newState === "open") {
397
+ return a === b;
398
+ }
399
+
400
+ return a >= b;
401
+ };
402
+
403
+ while (ref && ref.hasAttribute(ATTRIBUTE_INTEND)) {
404
+ const refIntend = ref.getAttribute(ATTRIBUTE_INTEND);
405
+
406
+ if (!cmp(parseInt(refIntend), childIntend)) {
407
+ if (refIntend === intend) {
408
+ break;
409
+ }
410
+ ref = ref.nextElementSibling;
411
+ continue;
412
+ }
413
+
414
+ const refIndex = ref
415
+ .getAttribute(ATTRIBUTE_UPDATER_INSERT_REFERENCE)
416
+ .split("-")
417
+ .pop();
418
+
419
+ this.setOption("entries." + refIndex + ".visibility", newVisibility);
420
+
421
+ if (newState === "close") {
422
+ this.setOption("entries." + refIndex + ".state", "close");
423
+ }
424
+
425
+ ref = ref.nextElementSibling;
426
+ }
427
+ }
428
+ };
429
+
430
+ const types = this.getOption("toggleEventType", ["click"]);
431
+ for (const [, type] of Object.entries(types)) {
432
+ this.shadowRoot.addEventListener(type, this[openEntryEventHandlerSymbol]);
433
+ }
434
+
435
+ return this;
441
436
  }
442
437
 
443
438
  /**
444
439
  * @private
445
440
  * @this {TreeMenu}
446
441
  */
447
- function initObserver() {
448
- }
442
+ function initObserver() {}
449
443
 
450
444
  /**
451
445
  * Import Menu Entries from dataset
@@ -456,61 +450,60 @@ function initObserver() {
456
450
  * @private
457
451
  */
458
452
  function importEntries() {
459
-
460
- const data = this.getOption("data")
461
- this[internalNodesSymbol] = new Map();
462
-
463
- const mappingOptions = this.getOption("mapping", {});
464
-
465
- const filter = mappingOptions?.["filter"];
466
- const rootReferences = mappingOptions?.["rootReferences"];
467
-
468
- const id = this.getOption("mapping.idTemplate");
469
- const parentKey = this.getOption("mapping.parentKey");
470
-
471
- const selector = mappingOptions?.["selector"];
472
-
473
- let nodes;
474
- try {
475
- nodes = buildTree(data, selector, id, parentKey, {
476
- filter,
477
- rootReferences,
478
- });
479
- } catch (error) {
480
- addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, String(error));
481
- }
482
-
483
- const options = [];
484
- for (const node of nodes) {
485
- const iterator = new NodeRecursiveIterator(node);
486
- for (const n of iterator) {
487
- const formattedValues = formatKeyLabel.call(this, n);
488
-
489
- const label = formattedValues?.label;
490
- const value = formattedValues?.value;
491
- const icon = formattedValues?.icon;
492
- const intend = n.level;
493
-
494
- const visibility = (intend > 0) ? "hidden" : "visible";
495
- const state = "close";
496
-
497
- this[internalNodesSymbol].set(value, n);
498
-
499
- options.push({
500
- value,
501
- label,
502
- icon,
503
- intend,
504
- state,
505
- visibility,
506
- ["has-children"]: n.hasChildNodes(),
507
- });
508
- }
509
- }
510
-
511
- this.setOption("entries", options);
512
-
513
- return this;
453
+ const data = this.getOption("data");
454
+ this[internalNodesSymbol] = new Map();
455
+
456
+ const mappingOptions = this.getOption("mapping", {});
457
+
458
+ const filter = mappingOptions?.["filter"];
459
+ const rootReferences = mappingOptions?.["rootReferences"];
460
+
461
+ const id = this.getOption("mapping.idTemplate");
462
+ const parentKey = this.getOption("mapping.parentKey");
463
+
464
+ const selector = mappingOptions?.["selector"];
465
+
466
+ let nodes;
467
+ try {
468
+ nodes = buildTree(data, selector, id, parentKey, {
469
+ filter,
470
+ rootReferences,
471
+ });
472
+ } catch (error) {
473
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, String(error));
474
+ }
475
+
476
+ const options = [];
477
+ for (const node of nodes) {
478
+ const iterator = new NodeRecursiveIterator(node);
479
+ for (const n of iterator) {
480
+ const formattedValues = formatKeyLabel.call(this, n);
481
+
482
+ const label = formattedValues?.label;
483
+ const value = formattedValues?.value;
484
+ const icon = formattedValues?.icon;
485
+ const intend = n.level;
486
+
487
+ const visibility = intend > 0 ? "hidden" : "visible";
488
+ const state = "close";
489
+
490
+ this[internalNodesSymbol].set(value, n);
491
+
492
+ options.push({
493
+ value,
494
+ label,
495
+ icon,
496
+ intend,
497
+ state,
498
+ visibility,
499
+ ["has-children"]: n.hasChildNodes(),
500
+ });
501
+ }
502
+ }
503
+
504
+ this.setOption("entries", options);
505
+
506
+ return this;
514
507
  }
515
508
 
516
509
  /**
@@ -520,27 +513,27 @@ function importEntries() {
520
513
  * @private
521
514
  */
522
515
  function formatKeyLabel(node) {
523
- validateInstance(node, Node);
516
+ validateInstance(node, Node);
524
517
 
525
- const label = new Formatter(node.value).format(
526
- this.getOption("mapping.labelTemplate"),
527
- );
518
+ const label = new Formatter(node.value).format(
519
+ this.getOption("mapping.labelTemplate"),
520
+ );
528
521
 
529
- const value = new Formatter(node.value).format(
530
- this.getOption("mapping.valueTemplate"),
531
- );
522
+ const value = new Formatter(node.value).format(
523
+ this.getOption("mapping.valueTemplate"),
524
+ );
532
525
 
533
- const iconID = new Formatter(node.value).format(
534
- this.getOption("mapping.iconTemplate"),
535
- );
526
+ const iconID = new Formatter(node.value).format(
527
+ this.getOption("mapping.iconTemplate"),
528
+ );
536
529
 
537
- const icon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><use xlink:href="#${iconID}"></use></svg>`;
530
+ const icon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><use xlink:href="#${iconID}"></use></svg>`;
538
531
 
539
- return {
540
- value,
541
- label,
542
- icon,
543
- };
532
+ return {
533
+ value,
534
+ label,
535
+ icon,
536
+ };
544
537
  }
545
538
 
546
539
  /**
@@ -548,15 +541,15 @@ function formatKeyLabel(node) {
548
541
  * @return {TreeMenu}
549
542
  */
550
543
  function initControlReferences() {
551
- if (!this.shadowRoot) {
552
- throw new Error("no shadow-root is defined");
553
- }
544
+ if (!this.shadowRoot) {
545
+ throw new Error("no shadow-root is defined");
546
+ }
554
547
 
555
- this[controlElementSymbol] = this.shadowRoot.querySelector(
556
- "[data-monster-role=control]",
557
- );
548
+ this[controlElementSymbol] = this.shadowRoot.querySelector(
549
+ "[data-monster-role=control]",
550
+ );
558
551
 
559
- return this;
552
+ return this;
560
553
  }
561
554
 
562
555
  /**
@@ -564,8 +557,8 @@ function initControlReferences() {
564
557
  * @return {string}
565
558
  */
566
559
  function getTemplate() {
567
- // language=HTML
568
- return `
560
+ // language=HTML
561
+ return `
569
562
  <slot></slot>
570
563
 
571
564
  <template id="entries">