wj-elements 0.1.141 → 0.1.142

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 (114) hide show
  1. package/dist/dark.css +6 -2
  2. package/dist/infinite-scroll.element-XVJukzjy.js.map +1 -1
  3. package/dist/light.css +14 -2
  4. package/dist/localize.js +2 -6
  5. package/dist/localize.js.map +1 -1
  6. package/dist/packages/index.d.ts +2 -0
  7. package/dist/packages/localize/localize.d.ts +1 -1
  8. package/dist/packages/translations/en-gb.d.ts +5 -0
  9. package/dist/packages/utils/permissions-api.d.ts +2 -2
  10. package/dist/packages/wje-accordion/accordion.element.d.ts +2 -2
  11. package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +1 -1
  12. package/dist/packages/wje-animation/animation.element.d.ts +1 -1
  13. package/dist/packages/wje-aside/aside.element.d.ts +1 -1
  14. package/dist/packages/wje-badge/badge.element.d.ts +1 -1
  15. package/dist/packages/wje-breadcrumb/breadcrumb.element.d.ts +2 -2
  16. package/dist/packages/wje-breadcrumbs/breadcrumbs.element.d.ts +3 -3
  17. package/dist/packages/wje-button/button.element.d.ts +5 -5
  18. package/dist/packages/wje-button-group/button-group.element.d.ts +2 -2
  19. package/dist/packages/wje-card/card.element.d.ts +1 -1
  20. package/dist/packages/wje-card-content/card-content.element.d.ts +1 -1
  21. package/dist/packages/wje-card-controls/card-controls.element.d.ts +1 -1
  22. package/dist/packages/wje-card-header/card-header.element.d.ts +1 -1
  23. package/dist/packages/wje-card-subtitle/card-subtitle.element.d.ts +1 -1
  24. package/dist/packages/wje-card-title/card-title.element.d.ts +1 -1
  25. package/dist/packages/wje-carousel/carousel.element.d.ts +2 -2
  26. package/dist/packages/wje-chip/chip.element.d.ts +1 -0
  27. package/dist/packages/wje-color-picker/color-picker.element.d.ts +4 -4
  28. package/dist/packages/wje-color-picker/color-picker.test.d.ts +1 -0
  29. package/dist/packages/wje-container/container.element.d.ts +1 -1
  30. package/dist/packages/wje-dialog/dialog.element.d.ts +2 -2
  31. package/dist/packages/wje-dropdown/dropdown.element.d.ts +2 -2
  32. package/dist/packages/wje-element/element.d.ts +2 -2
  33. package/dist/packages/wje-file-upload/file-upload.element.d.ts +2 -2
  34. package/dist/packages/wje-file-upload-item/file-upload-item.element.d.ts +1 -1
  35. package/dist/packages/wje-footer/footer.element.d.ts +1 -1
  36. package/dist/packages/wje-format-digital/format-digital.element.d.ts +1 -1
  37. package/dist/packages/wje-header/header.element.d.ts +1 -1
  38. package/dist/packages/wje-icon/icon.element.d.ts +1 -1
  39. package/dist/packages/wje-icon-picker/icon-picker.element.d.ts +1 -1
  40. package/dist/packages/wje-img/img.element.d.ts +1 -1
  41. package/dist/packages/wje-img-comparer/img-comparer.element.d.ts +1 -1
  42. package/dist/packages/wje-infinite-scroll/infinite-scroll.element.d.ts +3 -3
  43. package/dist/packages/wje-input-file/input-file.element.d.ts +1 -1
  44. package/dist/packages/wje-item/item.element.d.ts +1 -1
  45. package/dist/packages/wje-kanban/kanban.element.d.ts +3 -3
  46. package/dist/packages/wje-label/label.element.d.ts +1 -1
  47. package/dist/packages/wje-level-indicator/level-indicator.d.ts +2 -0
  48. package/dist/packages/wje-level-indicator/level-indicator.element.d.ts +91 -0
  49. package/dist/packages/wje-main/main.element.d.ts +1 -1
  50. package/dist/packages/wje-menu/menu.element.d.ts +1 -1
  51. package/dist/packages/wje-menu-button/menu-button.element.d.ts +1 -1
  52. package/dist/packages/wje-menu-label/menu-label.element.d.ts +1 -1
  53. package/dist/packages/wje-option/option.element.d.ts +1 -1
  54. package/dist/packages/wje-options/options.element.d.ts +1 -1
  55. package/dist/packages/wje-pagination/pagination.d.ts +2 -0
  56. package/dist/packages/wje-pagination/pagination.element.d.ts +166 -0
  57. package/dist/packages/wje-pagination/pagination.test.d.ts +1 -0
  58. package/dist/packages/wje-pagination/service/service.d.ts +9 -0
  59. package/dist/packages/wje-popup/popup.element.d.ts +1 -1
  60. package/dist/packages/wje-progress-bar/progress-bar.element.d.ts +1 -1
  61. package/dist/packages/wje-radio/radio.element.d.ts +1 -1
  62. package/dist/packages/wje-rate/rate.element.d.ts +3 -3
  63. package/dist/packages/wje-relative-time/relative-time.element.d.ts +1 -1
  64. package/dist/packages/wje-reorder/reorder.element.d.ts +1 -1
  65. package/dist/packages/wje-route/route.element.d.ts +1 -1
  66. package/dist/packages/wje-router/router.element.d.ts +1 -1
  67. package/dist/packages/wje-router-link/router-link.element.d.ts +1 -1
  68. package/dist/packages/wje-select/select.element.d.ts +2 -2
  69. package/dist/packages/wje-slider/slider.element.d.ts +1 -1
  70. package/dist/packages/wje-split-view/split-view.element.d.ts +1 -1
  71. package/dist/packages/wje-textarea/textarea.element.d.ts +1 -1
  72. package/dist/packages/wje-tree/tree.test.d.ts +1 -0
  73. package/dist/packages/wje-tree-item/tree-item.element.d.ts +2 -2
  74. package/dist/packages/wje-tree-item/tree-item.test.d.ts +1 -0
  75. package/dist/wje-animation.js +3 -3
  76. package/dist/wje-animation.js.map +1 -1
  77. package/dist/wje-button.js +4 -2
  78. package/dist/wje-button.js.map +1 -1
  79. package/dist/wje-checkbox.js +1 -1
  80. package/dist/wje-checkbox.js.map +1 -1
  81. package/dist/wje-chip.js +7 -2
  82. package/dist/wje-chip.js.map +1 -1
  83. package/dist/wje-color-picker.js.map +1 -1
  84. package/dist/wje-dialog.js +1 -1
  85. package/dist/wje-dialog.js.map +1 -1
  86. package/dist/wje-element.js +4 -5
  87. package/dist/wje-element.js.map +1 -1
  88. package/dist/wje-fetchAndParseCSS.js.map +1 -1
  89. package/dist/wje-file-upload-item.js.map +1 -1
  90. package/dist/wje-file-upload.js.map +1 -1
  91. package/dist/wje-format-digital.js.map +1 -1
  92. package/dist/wje-icon-picker.js +6 -8
  93. package/dist/wje-icon-picker.js.map +1 -1
  94. package/dist/wje-level-indicator.js +160 -0
  95. package/dist/wje-level-indicator.js.map +1 -0
  96. package/dist/wje-master.js +190 -651
  97. package/dist/wje-master.js.map +1 -1
  98. package/dist/wje-options.js +1 -6
  99. package/dist/wje-options.js.map +1 -1
  100. package/dist/wje-pagination.js +355 -0
  101. package/dist/wje-pagination.js.map +1 -0
  102. package/dist/wje-slider.js +1 -1
  103. package/dist/wje-slider.js.map +1 -1
  104. package/dist/wje-split-view.js.map +1 -1
  105. package/dist/wje-store.js +5 -7
  106. package/dist/wje-store.js.map +1 -1
  107. package/dist/wje-textarea.js +1 -4
  108. package/dist/wje-textarea.js.map +1 -1
  109. package/dist/wje-tree-item.js +371 -0
  110. package/dist/wje-tree-item.js.map +1 -0
  111. package/dist/wje-tree.js +205 -0
  112. package/dist/wje-tree.js.map +1 -0
  113. package/package.json +6 -3
  114. /package/dist/packages/{bundle.d.ts → wje-accordion/accordion.test.d.ts} +0 -0
@@ -0,0 +1,371 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import WJElement from "./wje-element.js";
5
+ const styles = `/*
6
+ [ WJ Tree Item ]
7
+ */
8
+
9
+ :host {
10
+ .native-tree-item {
11
+ position: relative;
12
+ display: flex;
13
+ align-items: stretch;
14
+ flex-direction: column;
15
+ &.multiple {
16
+ .item {
17
+ border-radius: 0 !important;
18
+ }
19
+ }
20
+ .item {
21
+ display: flex;
22
+ align-items: center;
23
+
24
+ /*--toggle-width: var(--wje-tree-item-indent);*/
25
+ /*--spacer-col: var(--wje-tree-item-indent);*/
26
+
27
+ /*display: grid;*/
28
+ /*grid-template-columns: var(--spacer-col) var(--wje-tree-item-indent) 1fr;*/
29
+ /*grid-template-areas: "indent toggle content";*/
30
+
31
+ padding-inline: var(--wje-spacing-3x-small);
32
+ padding-block: var(--wje-spacing-3x-small);
33
+ border-radius: var(--wje-tree-item-border-radius);
34
+ /*padding-left: var(--wje-tree-item-indent);*/
35
+ &:hover {
36
+ background-color: var(--wje-color-contrast-1);
37
+ }
38
+ .indent {
39
+ /*grid-area: indent;*/
40
+ display: block;
41
+ /*width: var(--wje-tree-item-indent);*/
42
+ width: 1em;
43
+ }
44
+ .toggle {
45
+ font-size: var(--wje-font-size-medium);
46
+ display: flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ box-sizing: content-box;
50
+ width: var(--wje-tree-item-indent);
51
+ height: var(--wje-tree-item-indent);
52
+ flex-shrink: 0;
53
+ /*grid-area: toggle;*/
54
+ }
55
+ wje-checkbox {
56
+ font-size: var(--wje-font-size-medium);
57
+ margin: 0;
58
+ }
59
+ .content {
60
+ font-size: var(--wje-font-size-medium);
61
+ grid-area: content;
62
+ }
63
+ slot {
64
+ display: flex;
65
+ align-items: center;
66
+ }
67
+ slot:not([name])::slotted(wje-icon) {
68
+ margin-right: var(--wje-spacing-2x-small);
69
+ }
70
+ }
71
+ .children {
72
+ font-size: calc(1em + var(--wje-tree-item-indent, var(--wje-spacing-medium)));
73
+ display: none;
74
+ &.open {
75
+ display: block;
76
+
77
+ ::before {
78
+ content: '';
79
+ position: absolute;
80
+ top: var(--wje-tree-item-indent);
81
+ bottom: 5px;
82
+ left: calc(1em - (var(--wje-spacing-3x-small) * 2) - (var(--wje-tree-item-indent-guid-width) / 2));
83
+ border-inline-end: var(--wje-tree-item-indent-guid-width) solid var(--wje-border-color);
84
+ z-index: 1;
85
+ }
86
+ }
87
+ }
88
+ }
89
+
90
+ .native-tree-item.expanded .item slot[name='expand'],
91
+ .native-tree-item:not(.expanded) slot[name='collapse'] {
92
+ display: none;
93
+ }
94
+ }
95
+
96
+ :host([selected]) {
97
+ .item {
98
+ background-color: var(--wje-color-contrast-2);
99
+ }
100
+ }
101
+ `;
102
+ class TreeItem extends WJElement {
103
+ /**
104
+ * Creates an instance of Toast.
105
+ */
106
+ constructor() {
107
+ super();
108
+ /**
109
+ * The class name for the component.
110
+ * @type {string}
111
+ */
112
+ __publicField(this, "className", "TreeItem");
113
+ this._selection = "single";
114
+ }
115
+ /**
116
+ * Sets the expanded state of the element. When set to a truthy value,
117
+ * the 'expanded' attribute will be added to the element. When set to a falsy
118
+ * value, the 'expanded' attribute will be removed.
119
+ * @param {boolean} value A boolean value indicating whether the
120
+ * element should be expanded (true) or collapsed (false).
121
+ */
122
+ set expanded(value) {
123
+ if (value) {
124
+ this.setAttribute("expanded", "");
125
+ } else {
126
+ this.removeAttribute("expanded");
127
+ }
128
+ }
129
+ /**
130
+ * Retrieves the value of the 'expanded' state for the current element.
131
+ * This getter checks whether the 'expanded' attribute is present on the element.
132
+ * If the attribute exists, it returns true, representing that the element is expanded.
133
+ * Otherwise, it returns false, indicating that the element is not expanded.
134
+ * @returns {boolean} True if the 'expanded' attribute is present, false otherwise.
135
+ */
136
+ get expanded() {
137
+ return this.hasAttribute("expanded");
138
+ }
139
+ /**
140
+ * Sets the 'selected' attribute of the element. Removes the attribute if the provided value is falsy; otherwise, sets it.
141
+ * @param {boolean} value The value indicating whether the element should have the 'selected' attribute.
142
+ */
143
+ set selected(value) {
144
+ this.removeAttribute("selected");
145
+ if (value) this.setAttribute("selected", "");
146
+ }
147
+ /**
148
+ * Getter method for determining if the 'selected' attribute is present on the element.
149
+ * @returns {boolean} Returns true if the 'selected' attribute is present, otherwise false.
150
+ */
151
+ get selected() {
152
+ return this.hasAttribute("selected");
153
+ }
154
+ /**
155
+ * Sets the selection mode for the component.
156
+ * @param {string} value The selection mode to apply. Defaults to 'single'
157
+ * if no value is provided. Possible options may be
158
+ * specific to the implementation of the component
159
+ * (e.g., 'single', 'multiple').
160
+ */
161
+ set selection(value) {
162
+ this._selection = value || "single";
163
+ }
164
+ /**
165
+ * Retrieves the current selection.
166
+ * @returns {*} The value of the current selection.
167
+ */
168
+ get selection() {
169
+ return this._selection;
170
+ }
171
+ /**
172
+ * Sets or removes the 'indeterminate' attribute based on the provided value.
173
+ * This can be used to visually indicate an indeterminate state for elements like checkboxes.
174
+ * @param {boolean} value A boolean indicating whether to set the element to an indeterminate state.
175
+ * If true, the 'indeterminate' attribute is added to the element; if false, the attribute is removed.
176
+ */
177
+ set indeterminate(value) {
178
+ this.removeAttribute("indeterminate");
179
+ if (value) this.setAttribute("indeterminate", "");
180
+ }
181
+ /**
182
+ * Retrieves the state of the indeterminate attribute.
183
+ * @returns {boolean} True if the indeterminate attribute is present, otherwise false.
184
+ */
185
+ get indeterminate() {
186
+ return this.hasAttribute("indeterminate");
187
+ }
188
+ /**
189
+ * Returns the CSS stylesheet for the component.
190
+ * @static
191
+ * @returns {CSSStyleSheet} The CSS stylesheet
192
+ */
193
+ static get cssStyleSheet() {
194
+ return styles;
195
+ }
196
+ /**
197
+ * Setup attributes for the Button element.
198
+ */
199
+ setupAttributes() {
200
+ this.isShadowRoot = "open";
201
+ }
202
+ /**
203
+ * Returns the list of attributes to observe for changes.
204
+ * @static
205
+ * @returns {Array<string>}
206
+ */
207
+ static get observedAttributes() {
208
+ return ["selected", "indeterminate"];
209
+ }
210
+ /**
211
+ * Handles updates when observed attributes of the element are changed.
212
+ * Updates the checkbox state based on changes to the "selected" or "indeterminate" attributes.
213
+ * @param {string} name The name of the attribute that was changed.
214
+ * @param {string|null} oldValue The previous value of the attribute before the change.
215
+ * @param {string|null} newValue The new value of the attribute after the change.
216
+ * @returns {void}
217
+ */
218
+ attributeChangedCallback(name, oldValue, newValue) {
219
+ if (name === "selected") {
220
+ this.checkbox.removeAttribute("indeterminate");
221
+ if (this.selected) {
222
+ this.checkbox.setAttribute("checked", "");
223
+ } else {
224
+ this.checkbox.removeAttribute("checked");
225
+ }
226
+ }
227
+ if (name === "indeterminate" && !this.selected) {
228
+ this.checkbox.removeAttribute("indeterminate");
229
+ this.checkbox.removeAttribute("checked");
230
+ if (this.indeterminate) this.checkbox.setAttribute("indeterminate", "");
231
+ }
232
+ }
233
+ /**
234
+ * Custom logic executed before the draw process begins.
235
+ * Determines and sets the appropriate slot if the current item is nested.
236
+ * @returns {void} No return value.
237
+ */
238
+ beforeDraw() {
239
+ if (this.isNestedItem()) this.slot = "children";
240
+ }
241
+ /**
242
+ * Creates and returns a document fragment representing the structure of a tree item component.
243
+ * The method constructs the DOM elements including the native container, indentation, toggle button,
244
+ * selection checkbox, label, and children container, along with their respective slots and attributes.
245
+ * It dynamically handles the creation of expand and collapse icons, as well as appending slots for
246
+ * child components.
247
+ * @returns {DocumentFragment} A fragment containing the complete tree item structure to be rendered.
248
+ */
249
+ draw() {
250
+ let fragment = document.createDocumentFragment();
251
+ let native = document.createElement("div");
252
+ native.setAttribute("part", "native");
253
+ native.classList.add("native-tree-item", this.selection === "multiple" ? "multiple" : "single");
254
+ let item = document.createElement("div");
255
+ item.classList.add("item");
256
+ let indent = document.createElement("div");
257
+ indent.classList.add("indent");
258
+ let button = document.createElement("div");
259
+ button.classList.add("toggle");
260
+ let checkbox = document.createElement("wje-checkbox");
261
+ if (this.selected) checkbox.setAttribute("checked", "");
262
+ let label = document.createElement("div");
263
+ label.classList.add("content");
264
+ let slotElement = document.createElement("slot");
265
+ let children = document.createElement("div");
266
+ children.classList.add("children");
267
+ let slot = document.createElement("slot");
268
+ slot.setAttribute("name", "children");
269
+ children.appendChild(slot);
270
+ item.appendChild(indent);
271
+ if (this.querySelectorAll(":scope > wje-tree-item").length > 0) {
272
+ if (this.querySelectorAll('[slot="expand"]').length < 1) {
273
+ let expandIcon = document.createElement("wje-icon");
274
+ expandIcon.setAttribute("name", "chevron-right");
275
+ expandIcon.setAttribute("slot", "expand");
276
+ this.appendChild(expandIcon);
277
+ }
278
+ if (this.querySelectorAll('[slot="collapse"]').length < 1) {
279
+ let collapseIcon = document.createElement("wje-icon");
280
+ collapseIcon.setAttribute("name", "chevron-down");
281
+ collapseIcon.setAttribute("slot", "collapse");
282
+ this.appendChild(collapseIcon);
283
+ }
284
+ let expandSlot = document.createElement("slot");
285
+ expandSlot.setAttribute("name", "expand");
286
+ let collapseSlot = document.createElement("slot");
287
+ collapseSlot.setAttribute("name", "collapse");
288
+ button.appendChild(expandSlot);
289
+ button.appendChild(collapseSlot);
290
+ }
291
+ item.appendChild(button);
292
+ if (this.selection === "multiple") item.appendChild(checkbox);
293
+ label.appendChild(slotElement);
294
+ item.appendChild(label);
295
+ native.appendChild(item);
296
+ native.appendChild(children);
297
+ fragment.appendChild(native);
298
+ this.checkbox = checkbox;
299
+ this.native = native;
300
+ this.button = button;
301
+ this.childrenElement = children;
302
+ this.childrenSlot = slot;
303
+ return fragment;
304
+ }
305
+ /**
306
+ * Executes operations to be performed after the draw action is completed.
307
+ * If the state indicates it is expanded, toggles its children.
308
+ * Additionally, sets up an event listener on the button element to handle toggling children upon click.
309
+ * @returns {void} Does not return a value.
310
+ */
311
+ afterDraw() {
312
+ if (this.expanded) this.toggleChildren();
313
+ this.button.addEventListener("click", this.toggleChildren.bind(this));
314
+ }
315
+ /**
316
+ * Determines if the current item is a nested item within a tree structure.
317
+ * Checks if the item's parent element exists and is also a tree item.
318
+ * @returns {boolean} Returns true if the current item is a nested tree item; otherwise, false.
319
+ */
320
+ isNestedItem() {
321
+ const parent = this.parentElement;
322
+ return !!parent && this.isTreeItem(parent);
323
+ }
324
+ /**
325
+ * Checks whether the given node is a tree item.
326
+ * @param {object} node The node to check.
327
+ * @returns {boolean} Returns true if the node is an Element and has a class name of 'TreeItem', otherwise false.
328
+ */
329
+ isTreeItem(node) {
330
+ return node instanceof Element && node.className === "TreeItem";
331
+ }
332
+ /**
333
+ * Toggles the visibility state of the children element and updates the class of the parent element.
334
+ * The method toggles the 'open' class on the children elements and the 'expanded' class on the parent element,
335
+ * effectively showing or hiding the children and indicating the expanded state.
336
+ * @returns {void} Does not return a value.
337
+ */
338
+ toggleChildren() {
339
+ this.childrenElement.classList.toggle("open");
340
+ this.native.classList.toggle("expanded");
341
+ }
342
+ /**
343
+ * Retrieves the child items from the `childrenSlot` that match specific criteria.
344
+ * @param {object} [options] Configuration options.
345
+ * @param {boolean} [options.includeDisabled] Determines whether disabled items should be included in the result. Defaults to true.
346
+ * @returns {Array} An array of child items that are valid tree items and meet the criteria specified in the options.
347
+ */
348
+ getChildrenItems(options = {}) {
349
+ const includeDisabled = options.includeDisabled ?? true;
350
+ if (!this.childrenSlot) {
351
+ return [];
352
+ }
353
+ return [...this.childrenSlot.assignedElements({ flatten: true })].filter(
354
+ (item) => this.isTreeItem(item) && (includeDisabled || !item.disabled)
355
+ );
356
+ }
357
+ /**
358
+ * Retrieves all descendant children of the current object in a flattened array structure.
359
+ * @param {object} [options] An optional object specifying filters or configurations for retrieving children.
360
+ * @returns {Array} An array containing all children and their descendants in a flat structure.
361
+ */
362
+ getAllChildrenFlat(options = {}) {
363
+ const directChildren = this.getChildrenItems(options);
364
+ return directChildren.flatMap((child) => [child, ...child.getAllChildrenFlat(options)]);
365
+ }
366
+ }
367
+ TreeItem.define("wje-tree-item", TreeItem);
368
+ export {
369
+ TreeItem as default
370
+ };
371
+ //# sourceMappingURL=wje-tree-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wje-tree-item.js","sources":["../packages/wje-tree-item/tree-item.element.js","../packages/wje-tree-item/tree-item.js"],"sourcesContent":["import { default as WJElement, WjElementUtils, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `wje-tree-item` is a custom web component used as a child of the `wje-tree`.\n * It represents a node within a tree structure, capable of nesting other items.\n * @summary Represents a single item in a tree structure.\n * @documentation https://elements.webjet.sk/components/tree-item\n * @status stable\n * @augments {HTMLElement}\n * @slot - Default slot for rendering the tree item's content (e.g., text or custom elements).\n * @csspart native - The native container of the tree item.\n * @cssproperty [--wje-tree-item-indent=var(--wje-spacing-large)] - Defines the indentation for nested tree items.\n * @cssproperty [--wje-tree-item-indent-guid-width=0px] - Specifies the width of the guide element shown next to a tree item.\n * @cssproperty [--wje-tree-item-border-radius=var(--wje-border-radius-medium)] - Sets the border radius of the tree item’s container.\n * @tag wje-tree-item\n */\n\nexport default class TreeItem extends WJElement {\n /**\n * Creates an instance of Toast.\n */\n constructor() {\n super();\n\n this._selection = 'single';\n }\n\n /**\n * Sets the expanded state of the element. When set to a truthy value,\n * the 'expanded' attribute will be added to the element. When set to a falsy\n * value, the 'expanded' attribute will be removed.\n * @param {boolean} value A boolean value indicating whether the\n * element should be expanded (true) or collapsed (false).\n */\n set expanded(value) {\n if (value) {\n this.setAttribute('expanded', '');\n } else {\n this.removeAttribute('expanded');\n }\n }\n\n /**\n * Retrieves the value of the 'expanded' state for the current element.\n * This getter checks whether the 'expanded' attribute is present on the element.\n * If the attribute exists, it returns true, representing that the element is expanded.\n * Otherwise, it returns false, indicating that the element is not expanded.\n * @returns {boolean} True if the 'expanded' attribute is present, false otherwise.\n */\n get expanded() {\n return this.hasAttribute('expanded');\n }\n\n /**\n * Sets the 'selected' attribute of the element. Removes the attribute if the provided value is falsy; otherwise, sets it.\n * @param {boolean} value The value indicating whether the element should have the 'selected' attribute.\n */\n set selected(value) {\n this.removeAttribute('selected');\n\n if (value) this.setAttribute('selected', '');\n }\n\n /**\n * Getter method for determining if the 'selected' attribute is present on the element.\n * @returns {boolean} Returns true if the 'selected' attribute is present, otherwise false.\n */\n get selected() {\n return this.hasAttribute('selected');\n }\n\n /**\n * Sets the selection mode for the component.\n * @param {string} value The selection mode to apply. Defaults to 'single'\n * if no value is provided. Possible options may be\n * specific to the implementation of the component\n * (e.g., 'single', 'multiple').\n */\n set selection(value) {\n this._selection = value || 'single';\n }\n\n /**\n * Retrieves the current selection.\n * @returns {*} The value of the current selection.\n */\n get selection() {\n return this._selection;\n }\n\n /**\n * Sets or removes the 'indeterminate' attribute based on the provided value.\n * This can be used to visually indicate an indeterminate state for elements like checkboxes.\n * @param {boolean} value A boolean indicating whether to set the element to an indeterminate state.\n * If true, the 'indeterminate' attribute is added to the element; if false, the attribute is removed.\n */\n set indeterminate(value) {\n this.removeAttribute('indeterminate');\n\n if (value) this.setAttribute('indeterminate', '');\n }\n\n /**\n * Retrieves the state of the indeterminate attribute.\n * @returns {boolean} True if the indeterminate attribute is present, otherwise false.\n */\n get indeterminate() {\n return this.hasAttribute('indeterminate');\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'TreeItem';\n\n /**\n * Returns the CSS stylesheet for the component.\n * @static\n * @returns {CSSStyleSheet} The CSS stylesheet\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Setup attributes for the Button element.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['selected', 'indeterminate'];\n }\n\n /**\n * Handles updates when observed attributes of the element are changed.\n * Updates the checkbox state based on changes to the \"selected\" or \"indeterminate\" attributes.\n * @param {string} name The name of the attribute that was changed.\n * @param {string|null} oldValue The previous value of the attribute before the change.\n * @param {string|null} newValue The new value of the attribute after the change.\n * @returns {void}\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'selected') {\n this.checkbox.removeAttribute('indeterminate');\n if (this.selected) {\n this.checkbox.setAttribute('checked', '');\n } else {\n this.checkbox.removeAttribute('checked');\n }\n }\n\n if (name === 'indeterminate' && !this.selected) {\n this.checkbox.removeAttribute('indeterminate');\n this.checkbox.removeAttribute('checked');\n\n if (this.indeterminate) this.checkbox.setAttribute('indeterminate', '');\n }\n }\n\n /**\n * Custom logic executed before the draw process begins.\n * Determines and sets the appropriate slot if the current item is nested.\n * @returns {void} No return value.\n */\n beforeDraw() {\n if (this.isNestedItem()) this.slot = 'children';\n }\n\n /**\n * Creates and returns a document fragment representing the structure of a tree item component.\n * The method constructs the DOM elements including the native container, indentation, toggle button,\n * selection checkbox, label, and children container, along with their respective slots and attributes.\n * It dynamically handles the creation of expand and collapse icons, as well as appending slots for\n * child components.\n * @returns {DocumentFragment} A fragment containing the complete tree item structure to be rendered.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-tree-item', this.selection === 'multiple' ? 'multiple' : 'single');\n\n let item = document.createElement('div');\n item.classList.add('item');\n\n let indent = document.createElement('div');\n indent.classList.add('indent');\n\n let button = document.createElement('div');\n button.classList.add('toggle');\n\n let checkbox = document.createElement('wje-checkbox');\n if (this.selected) checkbox.setAttribute('checked', '');\n\n let label = document.createElement('div');\n label.classList.add('content');\n\n let slotElement = document.createElement('slot');\n\n let children = document.createElement('div');\n children.classList.add('children');\n\n let slot = document.createElement('slot');\n slot.setAttribute('name', 'children');\n children.appendChild(slot);\n\n item.appendChild(indent);\n\n if (this.querySelectorAll(':scope > wje-tree-item').length > 0) {\n if (this.querySelectorAll('[slot=\"expand\"]').length < 1) {\n let expandIcon = document.createElement('wje-icon');\n expandIcon.setAttribute('name', 'chevron-right');\n expandIcon.setAttribute('slot', 'expand');\n\n this.appendChild(expandIcon);\n }\n\n if (this.querySelectorAll('[slot=\"collapse\"]').length < 1) {\n let collapseIcon = document.createElement('wje-icon');\n collapseIcon.setAttribute('name', 'chevron-down');\n collapseIcon.setAttribute('slot', 'collapse');\n\n this.appendChild(collapseIcon);\n }\n\n let expandSlot = document.createElement('slot');\n expandSlot.setAttribute('name', 'expand');\n\n let collapseSlot = document.createElement('slot');\n collapseSlot.setAttribute('name', 'collapse');\n\n button.appendChild(expandSlot);\n button.appendChild(collapseSlot);\n }\n\n item.appendChild(button);\n\n if (this.selection === 'multiple') item.appendChild(checkbox);\n\n label.appendChild(slotElement);\n item.appendChild(label);\n\n native.appendChild(item);\n native.appendChild(children);\n\n fragment.appendChild(native);\n\n this.checkbox = checkbox;\n this.native = native;\n this.button = button;\n this.childrenElement = children;\n this.childrenSlot = slot;\n\n return fragment;\n }\n\n /**\n * Executes operations to be performed after the draw action is completed.\n * If the state indicates it is expanded, toggles its children.\n * Additionally, sets up an event listener on the button element to handle toggling children upon click.\n * @returns {void} Does not return a value.\n */\n afterDraw() {\n if (this.expanded) this.toggleChildren();\n\n this.button.addEventListener('click', this.toggleChildren.bind(this));\n }\n\n /**\n * Determines if the current item is a nested item within a tree structure.\n * Checks if the item's parent element exists and is also a tree item.\n * @returns {boolean} Returns true if the current item is a nested tree item; otherwise, false.\n */\n isNestedItem() {\n const parent = this.parentElement;\n return !!parent && this.isTreeItem(parent);\n }\n\n /**\n * Checks whether the given node is a tree item.\n * @param {object} node The node to check.\n * @returns {boolean} Returns true if the node is an Element and has a class name of 'TreeItem', otherwise false.\n */\n isTreeItem(node) {\n return node instanceof Element && node.className === 'TreeItem';\n }\n\n /**\n * Toggles the visibility state of the children element and updates the class of the parent element.\n * The method toggles the 'open' class on the children elements and the 'expanded' class on the parent element,\n * effectively showing or hiding the children and indicating the expanded state.\n * @returns {void} Does not return a value.\n */\n toggleChildren() {\n this.childrenElement.classList.toggle('open');\n this.native.classList.toggle('expanded');\n }\n\n /**\n * Retrieves the child items from the `childrenSlot` that match specific criteria.\n * @param {object} [options] Configuration options.\n * @param {boolean} [options.includeDisabled] Determines whether disabled items should be included in the result. Defaults to true.\n * @returns {Array} An array of child items that are valid tree items and meet the criteria specified in the options.\n */\n getChildrenItems(options = {}) {\n const includeDisabled = options.includeDisabled ?? true; // Ak nie je zadané, predvolená hodnota je true\n\n if (!this.childrenSlot) {\n return []; // Ak `childrenSlot` neexistuje, vráti prázdne pole\n }\n\n return [...this.childrenSlot.assignedElements({ flatten: true })].filter(\n (item) => this.isTreeItem(item) && (includeDisabled || !item.disabled)\n );\n }\n\n /**\n * Retrieves all descendant children of the current object in a flattened array structure.\n * @param {object} [options] An optional object specifying filters or configurations for retrieving children.\n * @returns {Array} An array containing all children and their descendants in a flat structure.\n */\n getAllChildrenFlat(options = {}) {\n const directChildren = this.getChildrenItems(options);\n return directChildren.flatMap((child) => [child, ...child.getAllChildrenFlat(options)]);\n }\n}\n","import TreeItem from './tree-item.element.js';\n\nexport default TreeItem;\n\nTreeItem.define('wje-tree-item', TreeItem);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,YAAY;AACR,QAAI,KAAK,SAAU,MAAK,eAAgB;AAExC,SAAK,OAAO,iBAAiB,SAAS,KAAK,eAAe,KAAK,IAAI,CAAC;AAAA,EAC5E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,eAAe;AACX,UAAM,SAAS,KAAK;AACpB,WAAO,CAAC,CAAC,UAAU,KAAK,WAAW,MAAM;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,WAAW,MAAM;AACb,WAAO,gBAAgB,WAAW,KAAK,cAAc;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,iBAAiB;AACb,SAAK,gBAAgB,UAAU,OAAO,MAAM;AAC5C,SAAK,OAAO,UAAU,OAAO,UAAU;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,iBAAiB,UAAU,IAAI;AAC3B,UAAM,kBAAkB,QAAQ,mBAAmB;AAEnD,QAAI,CAAC,KAAK,cAAc;AACpB,aAAO;IACnB;AAEQ,WAAO,CAAC,GAAG,KAAK,aAAa,iBAAiB,EAAE,SAAS,MAAM,CAAC,EAAE;AAAA,MAC9D,CAAC,SAAS,KAAK,WAAW,IAAI,MAAM,mBAAmB,CAAC,KAAK;AAAA,IAChE;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,mBAAmB,UAAU,IAAI;AAC7B,UAAM,iBAAiB,KAAK,iBAAiB,OAAO;AACpD,WAAO,eAAe,QAAQ,CAAC,UAAU,CAAC,OAAO,GAAG,MAAM,mBAAmB,OAAO,CAAC,CAAC;AAAA,EAC9F;AACA;AC3UA,SAAS,OAAO,iBAAiB,QAAQ;"}
@@ -0,0 +1,205 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import WJElement from "./wje-element.js";
5
+ const styles = "/*\n[ WJ Tree ]\n*/\n\n:host {\n position: relative;\n width: 100%;\n font-size: 0;\n}\n";
6
+ class Tree extends WJElement {
7
+ /**
8
+ * Creates an instance of Toast.
9
+ */
10
+ constructor() {
11
+ super();
12
+ /**
13
+ * The class name for the component.
14
+ * @type {string}
15
+ */
16
+ __publicField(this, "className", "Tree");
17
+ /**
18
+ * Handles the click event triggered by the user interaction.
19
+ * Identifies the closest tree item element to the event target and sets it
20
+ * as the selected item. Ensures that only one item is selected at a time, resetting
21
+ * the selection state for all other items.
22
+ * @param {Event} e The click event object.
23
+ */
24
+ __publicField(this, "handleClick", (e) => {
25
+ let selectedItem = e.target.closest("wje-tree-item");
26
+ let isClickButton = e.composedPath().some((el) => {
27
+ var _a;
28
+ return (_a = el == null ? void 0 : el.classList) == null ? void 0 : _a.contains("toggle");
29
+ });
30
+ if (isClickButton) return;
31
+ if (this.selection === "single") {
32
+ if (selectedItem) {
33
+ for (let item of this.getAllItems()) {
34
+ item.selected = item === selectedItem;
35
+ }
36
+ }
37
+ } else if (this.selection === "multiple") {
38
+ selectedItem.selected = !selectedItem.selected;
39
+ this.updateCheckboxState(selectedItem);
40
+ }
41
+ });
42
+ }
43
+ /**
44
+ * Sets the selection attribute for the element.
45
+ * @param {string} value The value to set as the selection attribute.
46
+ */
47
+ set selection(value) {
48
+ this.setAttribute("selection", value);
49
+ }
50
+ /**
51
+ * Gets the current selection mode for the element.
52
+ * If no selection is explicitly set, it defaults to 'single'.
53
+ * @returns {string} The current selection mode, either set by the element's attribute or the default value 'single'.
54
+ */
55
+ get selection() {
56
+ return this.getAttribute("selection") || "single";
57
+ }
58
+ /**
59
+ * Returns the CSS stylesheet for the component.
60
+ * @static
61
+ * @returns {CSSStyleSheet} The CSS stylesheet
62
+ */
63
+ static get cssStyleSheet() {
64
+ return styles;
65
+ }
66
+ /**
67
+ * Setup attributes for the Button element.
68
+ */
69
+ setupAttributes() {
70
+ this.isShadowRoot = "open";
71
+ }
72
+ /**
73
+ * A method called before the drawing or rendering process of tree items.
74
+ * It iterates through all `wje-tree-item` elements, updating their selection state
75
+ * and managing their expand/collapse icons accordingly.
76
+ * @returns {void} This method does not return a value.
77
+ */
78
+ beforeDraw() {
79
+ const items = this.querySelectorAll("wje-tree-item");
80
+ items == null ? void 0 : items.forEach((item) => {
81
+ item.selection = this.selection;
82
+ this.getExpandCollapseIcon(item, "expand");
83
+ this.getExpandCollapseIcon(item, "collapse");
84
+ });
85
+ }
86
+ /**
87
+ * Draw method for the toast notification.
88
+ * @returns {object} Document fragment
89
+ */
90
+ draw() {
91
+ let fragment = document.createDocumentFragment();
92
+ let native = document.createElement("div");
93
+ native.setAttribute("part", "native");
94
+ native.classList.add("native-tree");
95
+ let slot = document.createElement("slot");
96
+ native.appendChild(slot);
97
+ fragment.appendChild(native);
98
+ return fragment;
99
+ }
100
+ /**
101
+ * Called after the draw process of the component is completed.
102
+ * Typically used to add event listeners or perform operations
103
+ * that are dependent on the component's drawn state.
104
+ * @returns {void} This method does not return a value.
105
+ */
106
+ afterDraw() {
107
+ this.addEventListener("click", this.handleClick);
108
+ }
109
+ /**
110
+ * Retrieves all items that match the selector 'wje-tree-item' within the current context.
111
+ * @returns {Array<Element>} An array of all matching DOM elements.
112
+ */
113
+ getAllItems() {
114
+ return [...this.querySelectorAll("wje-tree-item")];
115
+ }
116
+ /**
117
+ * Retrieves and appends an expand/collapse icon to a given item based on the provided status.
118
+ * @param {HTMLElement} item The DOM element to which the icon will be appended.
119
+ * @param {string} status The status indicating which icon to retrieve (e.g., "expand" or "collapse").
120
+ * @returns {void} This method does not return a value. If the icon matching the given status is not found, a warning is logged.
121
+ */
122
+ getExpandCollapseIcon(item, status) {
123
+ let icon = this.querySelector(`[slot="${status}"]`);
124
+ if (!icon) {
125
+ console.warn(`Icon with slot "${status}" was not found.`);
126
+ return;
127
+ }
128
+ let iconClone = icon.cloneNode(true);
129
+ item.appendChild(iconClone);
130
+ }
131
+ /**
132
+ * Updates the state of a checkbox, syncing the state both upwards to parent elements
133
+ * and downwards to child elements as necessary.
134
+ * @param {object} changedItem The specific item whose checkbox state has changed.
135
+ * @param {boolean} [isInitialSync] Indicates whether the state update is part of the initial synchronization process.
136
+ * @returns {void} This method does not return a value.
137
+ */
138
+ updateCheckboxState(changedItem, isInitialSync = false) {
139
+ this.isInitialSync = isInitialSync;
140
+ this.propagateStateDownwards(changedItem);
141
+ this.propagateStateUpwards(changedItem);
142
+ }
143
+ /**
144
+ * Updates the state of the parent item based on the state of its child items.
145
+ * Recursively propagates changes up to all parent items to reflect the selection
146
+ * or indeterminate state accurately.
147
+ * @param {object} item The current tree item whose parent state needs to be updated.
148
+ * It is expected to have properties `selected`, `indeterminate`,
149
+ * and a method `getChildrenItems({ includeDisabled: boolean })`.
150
+ * @returns {void} This method does not return a value.
151
+ */
152
+ updateParentState(item) {
153
+ var _a;
154
+ const children = item.getChildrenItems({ includeDisabled: false });
155
+ if (children.length) {
156
+ const areAllChildrenChecked = children.every((child) => child.selected);
157
+ const areSomeChildrenChecked = children.some((child) => child.selected);
158
+ const areSomeChildrenIndeterminate = children.some((child) => child.indeterminate);
159
+ item.selected = areAllChildrenChecked;
160
+ item.indeterminate = areSomeChildrenIndeterminate || areSomeChildrenChecked && !areAllChildrenChecked;
161
+ } else {
162
+ item.indeterminate = false;
163
+ }
164
+ const parent = (_a = item.parentElement) == null ? void 0 : _a.closest("wje-tree-item");
165
+ if (parent) {
166
+ this.updateParentState(parent);
167
+ }
168
+ }
169
+ /**
170
+ * Propagates the state changes of an item upwards through its ancestors in the hierarchy.
171
+ * Calls the `updateParentState` method for each parent element until no parent exists.
172
+ * @param {HTMLElement} item The current item whose state to propagate to its parent.
173
+ * @returns {void} This method does not return a value.
174
+ */
175
+ propagateStateUpwards(item) {
176
+ var _a;
177
+ const parent = (_a = item.parentElement) == null ? void 0 : _a.closest("wje-tree-item");
178
+ if (parent) {
179
+ this.updateParentState(parent);
180
+ this.propagateStateUpwards(parent);
181
+ }
182
+ }
183
+ /**
184
+ * Propagates the selected state of an item to its children recursively. Depending on the `isInitialSync` flag,
185
+ * it also determines how the state should be applied to the child items and updates the parent state if needed.
186
+ * @param {object} item The item whose state is being propagated to its child items. The item must have properties
187
+ * such as `selected` and methods like `getChildrenItems` to retrieve its child elements.
188
+ * @returns {void} This method does not return a value.
189
+ */
190
+ propagateStateDownwards(item) {
191
+ const isChecked = item.selected;
192
+ item.getChildrenItems().forEach((child) => {
193
+ child.selected = this.isInitialSync ? isChecked || child.selected : !child.disabled && isChecked;
194
+ this.propagateStateDownwards(child);
195
+ });
196
+ if (this.isInitialSync) {
197
+ this.updateParentState(item);
198
+ }
199
+ }
200
+ }
201
+ Tree.define("wje-tree", Tree);
202
+ export {
203
+ Tree as default
204
+ };
205
+ //# sourceMappingURL=wje-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wje-tree.js","sources":["../packages/wje-tree/tree.element.js","../packages/wje-tree/tree.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Tree` is a custom web component that represents a hierarchical tree structure.\n * It extends from `WJElement`.\n * @summary This element visually represents a tree structure, supporting single or multiple selection modes and hierarchy management.\n * @documentation https://elements.webjet.sk/components/tree\n * @status stable\n * @augments {WJElement}\n * @csspart native - The native container part of the tree.\n * @slot - The default slot to place `wje-tree-item` child components.\n * @tag wje-tree\n */\n\nexport default class Tree extends WJElement {\n /**\n * Creates an instance of Toast.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the selection attribute for the element.\n * @param {string} value The value to set as the selection attribute.\n */\n set selection(value) {\n this.setAttribute('selection', value);\n }\n\n /**\n * Gets the current selection mode for the element.\n * If no selection is explicitly set, it defaults to 'single'.\n * @returns {string} The current selection mode, either set by the element's attribute or the default value 'single'.\n */\n get selection() {\n return this.getAttribute('selection') || 'single';\n }\n\n /**\n * The class name for the component.\n * @type {string}\n */\n className = 'Tree';\n\n /**\n * Returns the CSS stylesheet for the component.\n * @static\n * @returns {CSSStyleSheet} The CSS stylesheet\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Setup attributes for the Button element.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * A method called before the drawing or rendering process of tree items.\n * It iterates through all `wje-tree-item` elements, updating their selection state\n * and managing their expand/collapse icons accordingly.\n * @returns {void} This method does not return a value.\n */\n beforeDraw() {\n const items = this.querySelectorAll('wje-tree-item');\n items?.forEach((item) => {\n item.selection = this.selection;\n\n this.getExpandCollapseIcon(item, 'expand');\n this.getExpandCollapseIcon(item, 'collapse');\n });\n }\n\n /**\n * Draw method for the toast notification.\n * @returns {object} Document fragment\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-tree');\n\n let slot = document.createElement('slot');\n\n native.appendChild(slot);\n\n fragment.appendChild(native);\n\n return fragment;\n }\n\n /**\n * Called after the draw process of the component is completed.\n * Typically used to add event listeners or perform operations\n * that are dependent on the component's drawn state.\n * @returns {void} This method does not return a value.\n */\n afterDraw() {\n this.addEventListener('click', this.handleClick);\n }\n\n /**\n * Handles the click event triggered by the user interaction.\n * Identifies the closest tree item element to the event target and sets it\n * as the selected item. Ensures that only one item is selected at a time, resetting\n * the selection state for all other items.\n * @param {Event} e The click event object.\n */\n handleClick = (e) => {\n let selectedItem = e.target.closest('wje-tree-item');\n let isClickButton = e.composedPath().some((el) => el?.classList?.contains('toggle'));\n if (isClickButton) return;\n\n if (this.selection === 'single') {\n if (selectedItem) {\n for (let item of this.getAllItems()) {\n item.selected = item === selectedItem;\n }\n }\n } else if (this.selection === 'multiple') {\n // let children = selectedItem.getAllChildrenFlat();\n selectedItem.selected = !selectedItem.selected;\n\n this.updateCheckboxState(selectedItem);\n }\n };\n\n /**\n * Retrieves all items that match the selector 'wje-tree-item' within the current context.\n * @returns {Array<Element>} An array of all matching DOM elements.\n */\n getAllItems() {\n return [...this.querySelectorAll('wje-tree-item')];\n }\n\n /**\n * Retrieves and appends an expand/collapse icon to a given item based on the provided status.\n * @param {HTMLElement} item The DOM element to which the icon will be appended.\n * @param {string} status The status indicating which icon to retrieve (e.g., \"expand\" or \"collapse\").\n * @returns {void} This method does not return a value. If the icon matching the given status is not found, a warning is logged.\n */\n getExpandCollapseIcon(item, status) {\n let icon = this.querySelector(`[slot=\"${status}\"]`);\n if (!icon) {\n console.warn(`Icon with slot \"${status}\" was not found.`);\n return;\n }\n\n let iconClone = icon.cloneNode(true);\n item.appendChild(iconClone);\n }\n\n /**\n * Updates the state of a checkbox, syncing the state both upwards to parent elements\n * and downwards to child elements as necessary.\n * @param {object} changedItem The specific item whose checkbox state has changed.\n * @param {boolean} [isInitialSync] Indicates whether the state update is part of the initial synchronization process.\n * @returns {void} This method does not return a value.\n */\n updateCheckboxState(changedItem, isInitialSync = false) {\n this.isInitialSync = isInitialSync;\n this.propagateStateDownwards(changedItem);\n this.propagateStateUpwards(changedItem);\n }\n\n /**\n * Updates the state of the parent item based on the state of its child items.\n * Recursively propagates changes up to all parent items to reflect the selection\n * or indeterminate state accurately.\n * @param {object} item The current tree item whose parent state needs to be updated.\n * It is expected to have properties `selected`, `indeterminate`,\n * and a method `getChildrenItems({ includeDisabled: boolean })`.\n * @returns {void} This method does not return a value.\n */\n updateParentState(item) {\n const children = item.getChildrenItems({ includeDisabled: false });\n\n if (children.length) {\n const areAllChildrenChecked = children.every((child) => child.selected);\n const areSomeChildrenChecked = children.some((child) => child.selected);\n const areSomeChildrenIndeterminate = children.some((child) => child.indeterminate);\n\n item.selected = areAllChildrenChecked;\n item.indeterminate = areSomeChildrenIndeterminate || (areSomeChildrenChecked && !areAllChildrenChecked);\n } else {\n item.indeterminate = false;\n }\n\n const parent = item.parentElement?.closest('wje-tree-item');\n if (parent) {\n this.updateParentState(parent);\n }\n }\n\n /**\n * Propagates the state changes of an item upwards through its ancestors in the hierarchy.\n * Calls the `updateParentState` method for each parent element until no parent exists.\n * @param {HTMLElement} item The current item whose state to propagate to its parent.\n * @returns {void} This method does not return a value.\n */\n propagateStateUpwards(item) {\n const parent = item.parentElement?.closest('wje-tree-item');\n\n if (parent) {\n this.updateParentState(parent);\n this.propagateStateUpwards(parent);\n }\n }\n\n /**\n * Propagates the selected state of an item to its children recursively. Depending on the `isInitialSync` flag,\n * it also determines how the state should be applied to the child items and updates the parent state if needed.\n * @param {object} item The item whose state is being propagated to its child items. The item must have properties\n * such as `selected` and methods like `getChildrenItems` to retrieve its child elements.\n * @returns {void} This method does not return a value.\n */\n propagateStateDownwards(item) {\n const isChecked = item.selected;\n\n item.getChildrenItems().forEach((child) => {\n child.selected = this.isInitialSync ? isChecked || child.selected : !child.disabled && isChecked;\n this.propagateStateDownwards(child);\n });\n\n if (this.isInitialSync) {\n this.updateParentState(item);\n }\n }\n}\n","import Tree from './tree.element.js';\n\nexport default Tree;\n\nTree.define('wje-tree', Tree);\n"],"names":[],"mappings":";;;;;AAee,MAAM,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA,EAIxC,cAAc;AACV,UAAO;AAwBX;AAAA;AAAA;AAAA;AAAA,qCAAY;AAuEZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAc,CAAC,MAAM;AACjB,UAAI,eAAe,EAAE,OAAO,QAAQ,eAAe;AACnD,UAAI,gBAAgB,EAAE,aAAY,EAAG,KAAK,CAAC,OAAE;;AAAK,8CAAI,cAAJ,mBAAe,SAAS;AAAA,OAAS;AACnF,UAAI,cAAe;AAEnB,UAAI,KAAK,cAAc,UAAU;AAC7B,YAAI,cAAc;AACd,mBAAS,QAAQ,KAAK,eAAe;AACjC,iBAAK,WAAW,SAAS;AAAA,UAC7C;AAAA,QACA;AAAA,MACA,WAAmB,KAAK,cAAc,YAAY;AAEtC,qBAAa,WAAW,CAAC,aA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