wj-elements 0.7.3 → 0.7.4

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.
@@ -2,10 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import WJElement from "./wje-element.js";
5
- const styles = "/*\n[ WJ Tree Item ]\n*/\n\n:host {\n .native-tree-item {\n position: relative;\n display: flex;\n align-items: stretch;\n flex-direction: column;\n &.multiple {\n .item {\n border-radius: 0 !important;\n }\n }\n .item {\n display: flex;\n align-items: center;\n padding-inline: var(--wje-tree-item-padding-inline);\n padding-block: var(--wje-tree-item-padding-block);\n border-radius: var(--wje-tree-item-border-radius);\n background-color: var(--wje-tree-item-background);\n color: var(--wje-tree-item-color);\n\n &:hover {\n background-color: var(--wje-tree-item-background-hover);\n color: var(--wje-tree-item-color-hover);\n }\n\n .indent {\n display: block;\n width: calc(var(--wje-tree-item-indent, var(--wje-spacing-medium)) * var(--wje-tree-item-depth, 0));\n flex-shrink: 0;\n }\n\n .toggle {\n font-size: var(--wje-tree-item-font-size);\n display: flex;\n align-items: center;\n justify-content: center;\n box-sizing: content-box;\n width: var(--wje-tree-item-indent);\n height: var(--wje-tree-item-indent);\n flex-shrink: 0;\n }\n\n wje-checkbox {\n font-size: var(--wje-tree-item-font-size);\n margin: 0;\n }\n\n .content {\n font-size: var(--wje-tree-item-font-size);\n }\n\n slot {\n display: flex;\n align-items: center;\n }\n\n slot:not([name])::slotted(wje-icon) {\n margin-right: var(--wje-spacing-2x-small);\n }\n\n slot[name='end'] {\n margin-inline-start: auto;\n }\n }\n .children {\n display: none;\n &.open {\n font-size: var(--wje-tree-item-font-size);\n display: block;\n\n ::before {\n content: '';\n position: absolute;\n top: var(--wje-tree-item-indent);\n bottom: 5px;\n left: calc(\n (var(--wje-tree-item-indent, var(--wje-spacing-medium)) * var(--wje-tree-item-depth, 0)) +\n 1em -\n (var(--wje-spacing-3x-small) * 2) -\n (var(--wje-tree-item-indent-guid-width) / 2)\n );\n border-inline-end: var(--wje-tree-item-indent-guid-width) solid var(--wje-border-color);\n z-index: 1;\n }\n }\n }\n }\n\n .native-tree-item.expanded .item slot[name='expand'],\n .native-tree-item:not(.expanded) slot[name='collapse'] {\n display: none;\n }\n}\n\n:host([selected]) {\n .item {\n background-color: var(--wje-tree-item-background-selected);\n color: var(--wje-tree-item-color-selected);\n }\n}\n:host([slot-hover-visible]) {\n .item {\n &:hover {\n slot[name='start'], slot[name='end'] {\n visibility: visible;\n }\n }\n slot[name='start'], slot[name='end'] {\n visibility: hidden;\n }\n }\n}\n";
5
+ const styles = "/*\n[ WJ Tree Item ]\n*/\n\n:host {\n .native-tree-item {\n position: relative;\n display: flex;\n align-items: stretch;\n flex-direction: column;\n &.multiple {\n .item {\n border-radius: 0 !important;\n }\n }\n .item {\n position: relative;\n display: flex;\n align-items: center;\n padding-inline: var(--wje-tree-item-padding-inline);\n padding-block: var(--wje-tree-item-padding-block);\n border-radius: var(--wje-tree-item-border-radius);\n border-width: var(--wje-tree-item-border-width);\n border-style: var(--wje-tree-item-border-style);\n border-color: var(--wje-tree-item-border-color);\n background-color: var(--wje-tree-item-background);\n color: var(--wje-tree-item-color);\n\n &::before,\n &::after {\n content: '';\n position: absolute;\n box-sizing: border-box;\n pointer-events: none;\n opacity: 0;\n z-index: 2;\n }\n\n &:hover {\n border-color: var(--wje-tree-item-border-color-hover);\n background-color: var(--wje-tree-item-background-hover);\n color: var(--wje-tree-item-color-hover);\n }\n\n .indent {\n display: block;\n width: calc(var(--wje-tree-item-indent) * var(--wje-tree-item-depth));\n flex-shrink: 0;\n }\n\n .toggle {\n font-size: var(--wje-tree-item-font-size);\n display: flex;\n align-items: center;\n justify-content: center;\n box-sizing: content-box;\n width: var(--wje-tree-item-indent);\n height: var(--wje-tree-item-indent);\n flex-shrink: 0;\n }\n\n wje-checkbox {\n font-size: var(--wje-tree-item-font-size);\n margin: 0;\n }\n\n .content {\n font-size: var(--wje-tree-item-font-size);\n }\n\n slot {\n display: flex;\n align-items: center;\n }\n\n slot:not([name])::slotted(wje-icon) {\n margin-right: var(--wje-spacing-2x-small);\n }\n\n slot[name='end'] {\n margin-inline-start: auto;\n }\n\n slot[name='start']::slotted(.wje-tree-drag-handle) {\n cursor: grab;\n }\n }\n .children {\n display: none;\n &.open {\n font-size: var(--wje-tree-item-font-size);\n display: block;\n\n ::before {\n content: '';\n position: absolute;\n top: var(--wje-tree-item-indent);\n bottom: 5px;\n left: calc(\n (var(--wje-tree-item-indent) * var(--wje-tree-item-depth)) +\n 1em -\n (var(--wje-spacing-3x-small) * 2) -\n (var(--wje-tree-item-indent-guid-width) / 2)\n );\n border-inline-end-width: var(--wje-tree-item-indent-guid-width);\n border-inline-end-style: var(--wje-tree-item-indent-guid-style);\n border-inline-end-color: var(--wje-tree-item-indent-guid-color);\n z-index: 1;\n }\n }\n }\n }\n\n .native-tree-item.expanded .item slot[name='expand'],\n .native-tree-item:not(.expanded) slot[name='collapse'] {\n display: none;\n }\n}\n\n:host([selected]) {\n .item {\n border-color: var(--wje-tree-item-border-color-selected);\n background-color: var(--wje-tree-item-background-selected);\n color: var(--wje-tree-item-color-selected);\n }\n}\n\n:host(.wje-tree-dragging) {\n opacity: 0.35;\n\n .item {\n slot[name='start']::slotted(.wje-tree-drag-handle) {\n cursor: grabbing;\n }\n }\n}\n\n:host(.wje-tree-drop-before) {\n .item {\n &::before {\n inset-inline: 0;\n top: -1px;\n height: var(--wje-tree-item-drop-line-width);\n background-color: var(--wje-tree-item-drop-color);\n border-radius: var(--wje-tree-item-drop-line-border-radius);\n opacity: 1;\n }\n }\n}\n\n:host(.wje-tree-drop-after) {\n .item {\n &::after {\n inset-inline: 0;\n bottom: -1px;\n height: var(--wje-tree-item-drop-line-width);\n background-color: var(--wje-tree-item-drop-color);\n border-radius: var(--wje-tree-item-drop-line-border-radius);\n opacity: 1;\n }\n }\n}\n\n:host(.wje-tree-drop-inside) {\n .item {\n &::before {\n inset: 0;\n border-width: var(--wje-tree-item-drop-border-width);\n border-style: var(--wje-tree-item-drop-border-style);\n border-color: var(--wje-tree-item-drop-border-color);\n border-radius: var(--wje-tree-item-drop-border-radius);\n opacity: 1;\n }\n }\n}\n\n:host([slot-hover-visible]) {\n .item {\n &:hover {\n slot[name='start'], slot[name='end'] {\n visibility: visible;\n }\n }\n slot[name='start'], slot[name='end'] {\n visibility: hidden;\n }\n }\n}\n";
6
6
  class TreeItem extends WJElement {
7
7
  /**
8
- * Creates an instance of Toast.
8
+ * Creates an instance of TreeItem.
9
9
  */
10
10
  constructor() {
11
11
  super();
@@ -115,7 +115,7 @@ class TreeItem extends WJElement {
115
115
  * @returns {Array<string>}
116
116
  */
117
117
  static get observedAttributes() {
118
- return ["selected", "indeterminate"];
118
+ return ["selected", "indeterminate", "expanded"];
119
119
  }
120
120
  /**
121
121
  * Handles updates when observed attributes of the element are changed.
@@ -126,6 +126,10 @@ class TreeItem extends WJElement {
126
126
  * @returns {void}
127
127
  */
128
128
  attributeChangedCallback(name, oldValue, newValue) {
129
+ if (name === "expanded") {
130
+ this.setChildrenExpanded(this.expanded, { syncAttribute: false });
131
+ return;
132
+ }
129
133
  if (!this.checkbox) {
130
134
  this.syncAria();
131
135
  return;
@@ -249,7 +253,7 @@ class TreeItem extends WJElement {
249
253
  * @returns {void} Does not return a value.
250
254
  */
251
255
  afterDraw() {
252
- if (this.expanded) this.toggleChildren();
256
+ this.setChildrenExpanded(this.expanded, { syncAttribute: false });
253
257
  this.button.addEventListener("click", this.toggleChildren.bind(this));
254
258
  this.setAttribute("tabindex", "0");
255
259
  this.syncAria();
@@ -280,10 +284,10 @@ class TreeItem extends WJElement {
280
284
  /**
281
285
  * Checks whether the given node is a tree item.
282
286
  * @param {object} node The node to check.
283
- * @returns {boolean} Returns true if the node is an Element and has a class name of 'TreeItem', otherwise false.
287
+ * @returns {boolean} Returns true when the node is a tree item element.
284
288
  */
285
289
  isTreeItem(node) {
286
- return node instanceof Element && node.className === "TreeItem";
290
+ return node instanceof Element && node.localName === "wje-tree-item";
287
291
  }
288
292
  /**
289
293
  * Toggles the visibility state of the children element and updates the class of the parent element.
@@ -292,8 +296,24 @@ class TreeItem extends WJElement {
292
296
  * @returns {void} Does not return a value.
293
297
  */
294
298
  toggleChildren() {
295
- this.childrenElement.classList.toggle("open");
296
- this.native.classList.toggle("expanded");
299
+ this.setChildrenExpanded(!this.childrenElement.classList.contains("open"));
300
+ }
301
+ /**
302
+ * Sets the rendered children visibility and optionally mirrors it to the expanded attribute.
303
+ * @param {boolean} expanded Whether child items should be visible.
304
+ * @param {object} [options] Configuration for attribute syncing.
305
+ * @param {boolean} [options.syncAttribute] Mirrors the visual state to the host attribute when true.
306
+ * @returns {void}
307
+ */
308
+ setChildrenExpanded(expanded, options = {}) {
309
+ var _a, _b;
310
+ const syncAttribute = options.syncAttribute ?? true;
311
+ (_a = this.childrenElement) == null ? void 0 : _a.classList.toggle("open", expanded);
312
+ (_b = this.native) == null ? void 0 : _b.classList.toggle("expanded", expanded);
313
+ if (syncAttribute) {
314
+ if (expanded) this.setAttribute("expanded", "");
315
+ else this.removeAttribute("expanded");
316
+ }
297
317
  this.syncAria();
298
318
  }
299
319
  /**
@@ -1 +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 this.syncAria();\n }\n\n connectedCallback() {\n super.connectedCallback?.();\n this.syncNestingState();\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 (!this.checkbox) {\n this.syncAria();\n return;\n }\n if (name === 'selected') {\n // this.checkbox.removeAttribute('indeterminate');\n if (this.selected) {\n this.checkbox.checked = true;\n } else {\n this.checkbox.checked = false;\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 this.syncAria();\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 this.syncNestingState();\n\n if(this.closest('wje-tree')?.hasAttribute('slot-hover-visible'))\n this.setAttribute('slot-hover-visible', '');\n }\n\n /**\n * Synchronizes the nesting-related state on the host element.\n * Sets the \"slot\" to children for nested items and updates\n * the nesting depth used to compute visual indentation.\n * @returns {void}\n */\n syncNestingState() {\n const depth = this.getNestingDepth();\n this.style.setProperty('--wje-tree-item-depth', String(depth));\n\n if (depth > 0) {\n this.slot = 'children';\n } else if (this.getAttribute('slot') === 'children') {\n this.removeAttribute('slot');\n }\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 slotStart = document.createElement('slot');\n slotStart.setAttribute('name', 'start');\n\n let item = document.createElement('div');\n item.setAttribute('part', 'item');\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.setAttribute('part', 'label');\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 let slotEnd = document.createElement('slot');\n slotEnd.setAttribute('name', 'end');\n\n item.appendChild(slotStart);\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 item.appendChild(slotEnd);\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 this.setAttribute('tabindex', '0');\n this.syncAria();\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 * Calculates nesting depth based on ancestor tree items.\n * Root items have depth 0, direct children depth 1, etc.\n * @returns {number}\n */\n getNestingDepth() {\n let depth = 0;\n let current = this.parentElement;\n\n while (current) {\n if (this.isTreeItem(current)) depth += 1;\n current = current.parentElement;\n }\n\n return depth;\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 this.syncAria();\n }\n\n /**\n * Syncs ARIA attributes on the host element.\n */\n syncAria() {\n const hasChildren = this.querySelectorAll(':scope > wje-tree-item').length > 0;\n const expanded = hasChildren ? this.native?.classList?.contains('expanded') : undefined;\n if (this.selection === 'multiple') {\n const checked = this.indeterminate ? 'mixed' : (this.selected ? 'true' : 'false');\n this.setAriaState({\n role: 'treeitem',\n checked,\n expanded,\n });\n } else {\n this.setAriaState({\n role: 'treeitem',\n selected: this.selected,\n expanded,\n });\n }\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 const assigned = this.childrenSlot\n ? this.childrenSlot.assignedElements({ flatten: true })\n : [];\n const direct = assigned.length\n ? assigned\n : Array.from(this.querySelectorAll(':scope > wje-tree-item'));\n\n return direct.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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AAAA,EAOA,mBAAmB,UAAU,IAAI;AAC7B,UAAM,iBAAiB,KAAK,iBAAiB,OAAO;AACpD,WAAO,eAAe,QAAQ,CAAC,UAAU,CAAC,OAAO,GAAG,MAAM,mBAAmB,OAAO,CAAC,CAAC;AAAA,EAC1F;AACJ;ACjaA,SAAS,OAAO,iBAAiB,QAAQ;"}
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-indent-guid-style=solid] - Defines the guide border style for nested tree items.\n * @cssproperty [--wje-tree-item-indent-guid-color=var(--wje-border-color)] - Defines the guide border color for nested tree items.\n * @cssproperty [--wje-tree-item-border-radius=var(--wje-border-radius-medium)] - Sets the border radius of the tree item's container.\n * @cssproperty [--wje-tree-item-border-width=0px] - Sets the border width of the tree item row.\n * @cssproperty [--wje-tree-item-border-style=solid] - Sets the border style of the tree item row.\n * @cssproperty [--wje-tree-item-border-color=transparent] - Sets the border color of the tree item row.\n * @cssproperty [--wje-tree-item-border-color-hover=transparent] - Sets the border color of the hovered tree item row.\n * @cssproperty [--wje-tree-item-border-color-selected=transparent] - Sets the border color of the selected tree item row.\n * @cssproperty [--wje-tree-item-drop-color=var(--wje-color-primary)] - Sets the color of reorder drop indicators.\n * @cssproperty [--wje-tree-item-drop-line-width=2px] - Sets the thickness of before/after reorder drop indicators.\n * @cssproperty [--wje-tree-item-drop-line-border-radius=var(--wje-border-radius-pill)] - Sets the radius of before/after reorder drop indicators.\n * @cssproperty [--wje-tree-item-drop-border-width=1px] - Sets the width of the inside reorder drop border.\n * @cssproperty [--wje-tree-item-drop-border-style=solid] - Sets the style of the inside reorder drop border.\n * @cssproperty [--wje-tree-item-drop-border-color=var(--wje-tree-item-drop-color)] - Sets the color of the inside reorder drop border.\n * @cssproperty [--wje-tree-item-drop-border-radius=inherit] - Sets the radius of the inside reorder drop border.\n * @tag wje-tree-item\n */\n\nexport default class TreeItem extends WJElement {\n /**\n * Creates an instance of TreeItem.\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 this.syncAria();\n }\n\n connectedCallback() {\n super.connectedCallback?.();\n this.syncNestingState();\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', 'expanded'];\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 === 'expanded') {\n this.setChildrenExpanded(this.expanded, { syncAttribute: false });\n return;\n }\n\n if (!this.checkbox) {\n this.syncAria();\n return;\n }\n if (name === 'selected') {\n // this.checkbox.removeAttribute('indeterminate');\n if (this.selected) {\n this.checkbox.checked = true;\n } else {\n this.checkbox.checked = false;\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 this.syncAria();\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 this.syncNestingState();\n\n if (this.closest('wje-tree')?.hasAttribute('slot-hover-visible'))\n this.setAttribute('slot-hover-visible', '');\n }\n\n /**\n * Synchronizes the nesting-related state on the host element.\n * Sets the \"slot\" to children for nested items and updates\n * the nesting depth used to compute visual indentation.\n * @returns {void}\n */\n syncNestingState() {\n const depth = this.getNestingDepth();\n this.style.setProperty('--wje-tree-item-depth', String(depth));\n\n if (depth > 0) {\n this.slot = 'children';\n } else if (this.getAttribute('slot') === 'children') {\n this.removeAttribute('slot');\n }\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 slotStart = document.createElement('slot');\n slotStart.setAttribute('name', 'start');\n\n let item = document.createElement('div');\n item.setAttribute('part', 'item');\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.setAttribute('part', 'label');\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 let slotEnd = document.createElement('slot');\n slotEnd.setAttribute('name', 'end');\n\n item.appendChild(slotStart);\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 item.appendChild(slotEnd);\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 this.setChildrenExpanded(this.expanded, { syncAttribute: false });\n\n this.button.addEventListener('click', this.toggleChildren.bind(this));\n this.setAttribute('tabindex', '0');\n this.syncAria();\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 * Calculates nesting depth based on ancestor tree items.\n * Root items have depth 0, direct children depth 1, etc.\n * @returns {number}\n */\n getNestingDepth() {\n let depth = 0;\n let current = this.parentElement;\n\n while (current) {\n if (this.isTreeItem(current)) depth += 1;\n current = current.parentElement;\n }\n\n return depth;\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 when the node is a tree item element.\n */\n isTreeItem(node) {\n return node instanceof Element && node.localName === 'wje-tree-item';\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.setChildrenExpanded(!this.childrenElement.classList.contains('open'));\n }\n\n /**\n * Sets the rendered children visibility and optionally mirrors it to the expanded attribute.\n * @param {boolean} expanded Whether child items should be visible.\n * @param {object} [options] Configuration for attribute syncing.\n * @param {boolean} [options.syncAttribute] Mirrors the visual state to the host attribute when true.\n * @returns {void}\n */\n setChildrenExpanded(expanded, options = {}) {\n const syncAttribute = options.syncAttribute ?? true;\n\n this.childrenElement?.classList.toggle('open', expanded);\n this.native?.classList.toggle('expanded', expanded);\n\n if (syncAttribute) {\n if (expanded) this.setAttribute('expanded', '');\n else this.removeAttribute('expanded');\n }\n\n this.syncAria();\n }\n\n /**\n * Syncs ARIA attributes on the host element.\n */\n syncAria() {\n const hasChildren = this.querySelectorAll(':scope > wje-tree-item').length > 0;\n const expanded = hasChildren ? this.native?.classList?.contains('expanded') : undefined;\n if (this.selection === 'multiple') {\n const checked = this.indeterminate ? 'mixed' : (this.selected ? 'true' : 'false');\n this.setAriaState({\n role: 'treeitem',\n checked,\n expanded,\n });\n } else {\n this.setAriaState({\n role: 'treeitem',\n selected: this.selected,\n expanded,\n });\n }\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;\n\n const assigned = this.childrenSlot\n ? this.childrenSlot.assignedElements({ flatten: true })\n : [];\n const direct = assigned.length\n ? assigned\n : Array.from(this.querySelectorAll(':scope > wje-tree-item'));\n\n return direct.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":";;;;;AAgCe,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA,EAI5C,cAAc;AACV,UAAK;AA4FT;AAAA;AAAA;AAAA;AAAA,qCAAY;AA1FR,SAAK,aAAa;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,SAAS,OAAO;AAChB,QAAI,OAAO;AACP,WAAK,aAAa,YAAY,EAAE;AAAA,IACpC,OAAO;AACH,WAAK,gBAAgB,UAAU;AAAA,IACnC;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,WAAW;AACX,WAAO,KAAK,aAAa,UAAU;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI,SAAS,OAAO;AAChB,SAAK,gBAAgB,UAAU;AAE/B,QAAI,MAAO,MAAK,aAAa,YAAY,EAAE;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAI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