wj-elements 0.1.155 → 0.1.156

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 (92) hide show
  1. package/dist/dark.css +8 -5
  2. package/dist/light.css +9 -6
  3. package/dist/packages/utils/event.d.ts +1 -0
  4. package/dist/packages/utils/permissions-api.d.ts +2 -2
  5. package/dist/packages/wje-accordion/accordion.element.d.ts +2 -2
  6. package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +1 -1
  7. package/dist/packages/wje-animation/animation.element.d.ts +1 -1
  8. package/dist/packages/wje-aside/aside.element.d.ts +1 -1
  9. package/dist/packages/wje-avatar/avatar.element.d.ts +3 -3
  10. package/dist/packages/wje-badge/badge.element.d.ts +1 -1
  11. package/dist/packages/wje-breadcrumb/breadcrumb.element.d.ts +2 -2
  12. package/dist/packages/wje-breadcrumbs/breadcrumbs.element.d.ts +3 -3
  13. package/dist/packages/wje-button/button.element.d.ts +9 -5
  14. package/dist/packages/wje-button-group/button-group.element.d.ts +2 -2
  15. package/dist/packages/wje-card/card.element.d.ts +1 -1
  16. package/dist/packages/wje-card-content/card-content.element.d.ts +1 -1
  17. package/dist/packages/wje-card-controls/card-controls.element.d.ts +1 -1
  18. package/dist/packages/wje-card-header/card-header.element.d.ts +1 -1
  19. package/dist/packages/wje-card-subtitle/card-subtitle.element.d.ts +1 -1
  20. package/dist/packages/wje-card-title/card-title.element.d.ts +1 -1
  21. package/dist/packages/wje-carousel/carousel.element.d.ts +2 -2
  22. package/dist/packages/wje-color-picker/color-picker.element.d.ts +4 -4
  23. package/dist/packages/wje-container/container.element.d.ts +1 -1
  24. package/dist/packages/wje-dialog/dialog.element.d.ts +2 -2
  25. package/dist/packages/wje-dropdown/dropdown.element.d.ts +6 -7
  26. package/dist/packages/wje-element/element.d.ts +11 -9
  27. package/dist/packages/wje-file-upload/file-upload.element.d.ts +2 -2
  28. package/dist/packages/wje-file-upload-item/file-upload-item.element.d.ts +1 -1
  29. package/dist/packages/wje-footer/footer.element.d.ts +1 -1
  30. package/dist/packages/wje-format-digital/format-digital.element.d.ts +1 -1
  31. package/dist/packages/wje-header/header.element.d.ts +1 -1
  32. package/dist/packages/wje-icon/icon.element.d.ts +1 -1
  33. package/dist/packages/wje-icon-picker/icon-picker.element.d.ts +1 -1
  34. package/dist/packages/wje-img/img.element.d.ts +5 -5
  35. package/dist/packages/wje-img-comparer/img-comparer.element.d.ts +1 -1
  36. package/dist/packages/wje-infinite-scroll/infinite-scroll.element.d.ts +3 -3
  37. package/dist/packages/wje-input-file/input-file.element.d.ts +1 -1
  38. package/dist/packages/wje-item/item.element.d.ts +1 -1
  39. package/dist/packages/wje-kanban/kanban.element.d.ts +3 -3
  40. package/dist/packages/wje-label/label.element.d.ts +1 -1
  41. package/dist/packages/wje-level-indicator/level-indicator.element.d.ts +2 -2
  42. package/dist/packages/wje-main/main.element.d.ts +1 -1
  43. package/dist/packages/wje-menu/menu.element.d.ts +1 -1
  44. package/dist/packages/wje-menu-button/menu-button.element.d.ts +1 -1
  45. package/dist/packages/wje-menu-label/menu-label.element.d.ts +1 -1
  46. package/dist/packages/wje-option/option.element.d.ts +1 -1
  47. package/dist/packages/wje-options/options.element.d.ts +1 -1
  48. package/dist/packages/wje-pagination/pagination.element.d.ts +5 -5
  49. package/dist/packages/wje-popup/popup.element.d.ts +1 -10
  50. package/dist/packages/wje-progress-bar/progress-bar.element.d.ts +1 -1
  51. package/dist/packages/wje-radio/radio.element.d.ts +1 -1
  52. package/dist/packages/wje-rate/rate.element.d.ts +3 -3
  53. package/dist/packages/wje-relative-time/relative-time.element.d.ts +1 -1
  54. package/dist/packages/wje-reorder/reorder.element.d.ts +1 -1
  55. package/dist/packages/wje-route/route.element.d.ts +1 -1
  56. package/dist/packages/wje-router/router.element.d.ts +1 -1
  57. package/dist/packages/wje-router-link/router-link.element.d.ts +1 -1
  58. package/dist/packages/wje-select/select.element.d.ts +2 -2
  59. package/dist/packages/wje-slider/slider.element.d.ts +1 -1
  60. package/dist/packages/wje-split-view/split-view.element.d.ts +1 -1
  61. package/dist/packages/wje-textarea/textarea.element.d.ts +1 -1
  62. package/dist/packages/wje-tooltip/tooltip.element.d.ts +1 -0
  63. package/dist/packages/wje-tree-item/tree-item.element.d.ts +2 -2
  64. package/dist/{popup.element-tyYxow0p.js → popup.element-AaduHP2r.js} +44 -44
  65. package/dist/{popup.element-tyYxow0p.js.map → popup.element-AaduHP2r.js.map} +1 -1
  66. package/dist/wje-button.js +30 -0
  67. package/dist/wje-button.js.map +1 -1
  68. package/dist/wje-color-picker.js +8 -1
  69. package/dist/wje-color-picker.js.map +1 -1
  70. package/dist/wje-dialog.js +1 -3
  71. package/dist/wje-dialog.js.map +1 -1
  72. package/dist/wje-dropdown.js +32 -14
  73. package/dist/wje-dropdown.js.map +1 -1
  74. package/dist/wje-element.js +114 -59
  75. package/dist/wje-element.js.map +1 -1
  76. package/dist/wje-icon-picker.js +1 -1
  77. package/dist/wje-img.js +0 -1
  78. package/dist/wje-img.js.map +1 -1
  79. package/dist/wje-master.js +1 -1
  80. package/dist/wje-menu-item.js +4 -5
  81. package/dist/wje-menu-item.js.map +1 -1
  82. package/dist/wje-pagination.js +2 -4
  83. package/dist/wje-pagination.js.map +1 -1
  84. package/dist/wje-popup.js +1 -1
  85. package/dist/wje-select.js +1 -1
  86. package/dist/wje-sliding-container.js +2 -2
  87. package/dist/wje-sliding-container.js.map +1 -1
  88. package/dist/wje-tooltip.js +11 -0
  89. package/dist/wje-tooltip.js.map +1 -1
  90. package/package.json +7 -12
  91. package/dist/packages/wje-accordion/accordion.test.d.ts +0 -0
  92. package/dist/packages/wje-color-picker/color-picker.test.d.ts +0 -1
@@ -2,7 +2,7 @@ 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, { event } from "./wje-element.js";
5
- import { P as Popup } from "./popup.element-tyYxow0p.js";
5
+ import { P as Popup } from "./popup.element-AaduHP2r.js";
6
6
  class Dropdown extends WJElement {
7
7
  /**
8
8
  * Creates an instance of Dropdown.
@@ -32,6 +32,15 @@ class Dropdown extends WJElement {
32
32
  this.popup.hide();
33
33
  }
34
34
  });
35
+ __publicField(this, "popupHideCallback", () => {
36
+ if (this.classList.contains("active")) {
37
+ this.classList.remove("active");
38
+ event.dispatchCustomEvent(this, "wje-dropdown:close", {
39
+ bubbles: true,
40
+ detail: { target: this }
41
+ });
42
+ }
43
+ });
35
44
  /**
36
45
  * @summary Toggles the dropdown element between active and inactive states.
37
46
  * Calls the `onOpen` method if the element is currently inactive,
@@ -57,7 +66,7 @@ class Dropdown extends WJElement {
57
66
  if (!this.classList.contains("active")) {
58
67
  throw new Error("beforeShow method returned false or not string");
59
68
  }
60
- this.popup.show();
69
+ this.popup.show(true);
61
70
  event.dispatchCustomEvent(this, "wje-dropdown:open", {
62
71
  bubbles: true,
63
72
  detail: { target: this }
@@ -65,19 +74,29 @@ class Dropdown extends WJElement {
65
74
  Promise.resolve(this.afterShow(this));
66
75
  }).catch((error) => {
67
76
  this.classList.remove("active");
68
- this.popup.hide();
77
+ this.popup.hide(true);
69
78
  });
70
79
  });
71
- /**
72
- * Close the popup element.
73
- * @param {object} e
74
- */
80
+ __publicField(this, "beforeClose", () => {
81
+ });
82
+ __publicField(this, "afterClose", () => {
83
+ });
75
84
  __publicField(this, "onClose", (e) => {
85
+ e.stopPropagation();
76
86
  this.classList.remove("active");
77
- this.popup.hide();
78
- event.dispatchCustomEvent(this, "wje-dropdown:close", {
79
- bubbles: true,
80
- detail: { target: this }
87
+ Promise.resolve(this.beforeClose(this)).then((res) => {
88
+ if (this.classList.contains("active")) {
89
+ throw new Error("beforeShow method returned false or not string");
90
+ }
91
+ this.popup.hide(true);
92
+ event.dispatchCustomEvent(this, "wje-dropdown:close", {
93
+ bubbles: true,
94
+ detail: { target: this }
95
+ });
96
+ Promise.resolve(this.afterClose(this));
97
+ }).catch((error) => {
98
+ this.classList.add("active");
99
+ this.popup.show(true);
81
100
  });
82
101
  });
83
102
  }
@@ -151,14 +170,13 @@ class Dropdown extends WJElement {
151
170
  event.removeListener(this, "mouseenter", null, this.onOpen);
152
171
  event.removeListener(this, "mouseleave", null, this.onClose);
153
172
  event.removeListener(this.anchorSlot, "click", null, this.toggleCallback, { capture: true });
173
+ event.removeListener(this, "wje-popup:hide", null, this.popupHideCallback);
154
174
  }
155
175
  /**
156
176
  * Adds event listeners for the mouseenter and mouseleave events.
157
177
  */
158
178
  afterDraw() {
159
- event.addListener(this, "wje-popup:hide", null, () => {
160
- this.classList.remove("active");
161
- });
179
+ event.addListener(this, "wje-popup:hide", null, this.popupHideCallback);
162
180
  if (this.trigger !== "click") {
163
181
  event.addListener(this, "mouseenter", null, this.onOpen);
164
182
  event.addListener(this, "mouseleave", null, this.onClose);
@@ -1 +1 @@
1
- {"version":3,"file":"wje-dropdown.js","sources":["../packages/wje-dropdown/dropdown.element.js","../packages/wje-dropdown/dropdown.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport Popup from '../wje-popup/popup.element.js';\n\n/**\n * `Dropdown` is a custom element that displays a dropdown menu.\n * @summary This element represents a dropdown menu.\n * @documentation https://elements.webjet.sk/components/dropdown\n * @status stable\n * @augments {WJElement}\n * @csspart native - The native part of the dropdown.\n * @slot trigger - The slot for the trigger of the dropdown.\n * @slot - The default slot for the dropdown.\n * // @fires wje-dropdown:open - Event fired when the dropdown is opened.\n * // @fires wje-dropdown:close - Event fired when the dropdown is closed.\n * @tag wje-dropdown\n */\nexport default class Dropdown extends WJElement {\n /**\n * Creates an instance of Dropdown.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * The placement of the dropdown.\n * @type {{\"wje-popup\": Popup}}\n */\n dependencies = {\n 'wje-popup': Popup,\n };\n\n /**\n * Sets the placement of the dropdown.\n * @param value\n */\n set trigger(value) {\n this.setAttribute('trigger', value);\n }\n\n /**\n * Gets the placement of the dropdown.\n * @returns {string|string}\n */\n get trigger() {\n return this.getAttribute('trigger') || 'click';\n }\n\n /**\n * Sets the placement of the dropdown.\n * @type {string}\n */\n className = 'Dropdown';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['active'];\n }\n\n /**\n * Callback function to handle other dropdowns being opened. Close the dropdown if it is not the target and collapse is enabled.\n * @param {Event} e The event object.\n */\n otherDropdownOpennedCallback = (e) => {\n if (e.detail.detail.target !== this) {\n this.classList.remove('active');\n this.popup.hide();\n }\n };\n\n /**\n * Sets up the attributes for the dropdown.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Removes the popup element.\n */\n beforeDraw() {\n this.popup?.remove();\n this.popup = null;\n }\n\n /**\n * Draws the dropdown element and returns the created document fragment.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('wje-placement', 'wje-' + this.placement || 'wje-start');\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-dropdown');\n\n let tooltip = document.createElement('wje-tooltip');\n tooltip.setAttribute('content', this.tooltip);\n\n let anchorSlot = document.createElement('slot');\n anchorSlot.setAttribute('name', 'trigger');\n anchorSlot.setAttribute('slot', 'anchor');\n\n let slot = document.createElement('slot');\n\n let popup = document.createElement('wje-popup');\n popup.setAttribute('placement', this.placement);\n popup.setAttribute('offset', this.offset);\n\n popup.appendChild(anchorSlot);\n popup.appendChild(slot);\n\n // if(this.trigger === \"click\")\n popup.setAttribute('manual', '');\n\n native.appendChild(popup);\n\n fragment.appendChild(native);\n\n this.popup = popup;\n this.anchorSlot = anchorSlot;\n\n return fragment;\n }\n\n /**\n * Adds event listeners for the mouseenter and mouseleave events.\n */\n afterDisconnect() {\n event.removeListener(this, 'mouseenter', null, this.onOpen);\n event.removeListener(this, 'mouseleave', null, this.onClose);\n event.removeListener(this.anchorSlot, 'click', null, this.toggleCallback, { capture: true });\n }\n\n /**\n * Adds event listeners for the mouseenter and mouseleave events.\n */\n afterDraw() {\n event.addListener(this, 'wje-popup:hide', null, () => {\n this.classList.remove('active');\n });\n\n if (this.trigger !== 'click') {\n event.addListener(this, 'mouseenter', null, this.onOpen);\n event.addListener(this, 'mouseleave', null, this.onClose);\n } else {\n event.addListener(this.anchorSlot, 'click', null, this.toggleCallback, { capture: true });\n }\n\n if (this.hasAttribute('collapsible')) {\n event.addListener(\n Array.from(this.querySelectorAll('wje-menu-item')),\n 'click',\n 'wje-menu-item:click',\n this.onClose\n );\n }\n }\n\n /**\n * @summary Returns the content to be displayed before showing the dropdown.\n * @returns {any} The content to be displayed.\n */\n beforeShow() {\n return this.content;\n }\n\n /**\n * This method is called after the dropdown is shown.\n */\n afterShow() {\n // Do nothing\n }\n\n /**\n * @summary Toggles the dropdown element between active and inactive states.\n * Calls the `onOpen` method if the element is currently inactive,\n * and calls the `onClose` method if the element is currently active.\n * @param {Event} e The event object.\n */\n toggleCallback = (e) => {\n e.stopPropagation();\n if (this.classList.contains('active')) {\n this.onClose(e);\n } else {\n this.onOpen(e);\n }\n };\n\n /**\n * Open the popup element.\n * @param {object} e\n */\n onOpen = (e) => {\n e.stopPropagation();\n\n this.classList.add('active');\n Promise.resolve(this.beforeShow(this))\n .then((res) => {\n if (!this.classList.contains('active')) {\n throw new Error('beforeShow method returned false or not string');\n }\n\n this.popup.show(); // Show tooltip\n\n event.dispatchCustomEvent(this, 'wje-dropdown:open', {\n bubbles: true,\n detail: { target: this },\n });\n\n Promise.resolve(this.afterShow(this));\n })\n .catch((error) => {\n // ak je nejaka chyba tak to len zatvorime\n this.classList.remove('active');\n this.popup.hide();\n });\n };\n\n /**\n * Close the popup element.\n * @param {object} e\n */\n onClose = (e) => {\n this.classList.remove('active');\n this.popup.hide(); // Now close the popup\n\n event.dispatchCustomEvent(this, 'wje-dropdown:close', {\n bubbles: true,\n detail: { target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ourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport Popup from '../wje-popup/popup.element.js';\n\n/**\n * `Dropdown` is a custom element that displays a dropdown menu.\n * @summary This element represents a dropdown menu.\n * @documentation https://elements.webjet.sk/components/dropdown\n * @status stable\n * @augments {WJElement}\n * @csspart native - The native part of the dropdown.\n * @slot trigger - The slot for the trigger of the dropdown.\n * @slot - The default slot for the dropdown.\n * // @fires wje-dropdown:open - Event fired when the dropdown is opened.\n * // @fires wje-dropdown:close - Event fired when the dropdown is closed.\n * @tag wje-dropdown\n */\nexport default class Dropdown extends WJElement {\n /**\n * Creates an instance of Dropdown.\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * The placement of the dropdown.\n * @type {{\"wje-popup\": Popup}}\n */\n dependencies = {\n 'wje-popup': Popup,\n };\n\n /**\n * Sets the placement of the dropdown.\n * @param value\n */\n set trigger(value) {\n this.setAttribute('trigger', value);\n }\n\n /**\n * Gets the placement of the dropdown.\n * @returns {string|string}\n */\n get trigger() {\n return this.getAttribute('trigger') || 'click';\n }\n\n /**\n * Sets the placement of the dropdown.\n * @type {string}\n */\n className = 'Dropdown';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['active'];\n }\n\n /**\n * Callback function to handle other dropdowns being opened. Close the dropdown if it is not the target and collapse is enabled.\n * @param {Event} e The event object.\n */\n otherDropdownOpennedCallback = (e) => {\n if (e.detail.detail.target !== this) {\n this.classList.remove('active');\n this.popup.hide();\n }\n };\n\n /**\n * Sets up the attributes for the dropdown.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Removes the popup element.\n */\n beforeDraw() {\n this.popup?.remove();\n this.popup = null;\n }\n\n /**\n * Draws the dropdown element and returns the created document fragment.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('wje-placement', 'wje-' + this.placement || 'wje-start');\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-dropdown');\n\n let tooltip = document.createElement('wje-tooltip');\n tooltip.setAttribute('content', this.tooltip);\n\n let anchorSlot = document.createElement('slot');\n anchorSlot.setAttribute('name', 'trigger');\n anchorSlot.setAttribute('slot', 'anchor');\n\n let slot = document.createElement('slot');\n\n let popup = document.createElement('wje-popup');\n popup.setAttribute('placement', this.placement);\n popup.setAttribute('offset', this.offset);\n\n popup.appendChild(anchorSlot);\n popup.appendChild(slot);\n\n // if(this.trigger === \"click\")\n popup.setAttribute('manual', '');\n\n native.appendChild(popup);\n\n fragment.appendChild(native);\n\n this.popup = popup;\n this.anchorSlot = anchorSlot;\n\n return fragment;\n }\n\n /**\n * Adds event listeners for the mouseenter and mouseleave events.\n */\n afterDisconnect() {\n event.removeListener(this, 'mouseenter', null, this.onOpen);\n event.removeListener(this, 'mouseleave', null, this.onClose);\n event.removeListener(this.anchorSlot, 'click', null, this.toggleCallback, { capture: true });\n event.removeListener(this, 'wje-popup:hide', null, this.popupHideCallback);\n }\n\n popupHideCallback = () => {\n if (this.classList.contains('active')) {\n this.classList.remove('active');\n\n event.dispatchCustomEvent(this, 'wje-dropdown:close', {\n bubbles: true,\n detail: { target: this },\n });\n }\n };\n\n /**\n * Adds event listeners for the mouseenter and mouseleave events.\n */\n afterDraw() {\n event.addListener(this, 'wje-popup:hide', null, this.popupHideCallback);\n\n if (this.trigger !== 'click') {\n event.addListener(this, 'mouseenter', null, this.onOpen);\n event.addListener(this, 'mouseleave', null, this.onClose);\n } else {\n event.addListener(this.anchorSlot, 'click', null, this.toggleCallback, { capture: true });\n }\n\n if (this.hasAttribute('collapsible')) {\n event.addListener(\n Array.from(this.querySelectorAll('wje-menu-item')),\n 'click',\n 'wje-menu-item:click',\n this.onClose\n );\n }\n }\n\n /**\n * @summary Returns the content to be displayed before showing the dropdown.\n * @returns {any} The content to be displayed.\n */\n beforeShow() {\n return this.content;\n }\n\n /**\n * This method is called after the dropdown is shown.\n */\n afterShow() {\n // Do nothing\n }\n\n /**\n * @summary Toggles the dropdown element between active and inactive states.\n * Calls the `onOpen` method if the element is currently inactive,\n * and calls the `onClose` method if the element is currently active.\n * @param {Event} e The event object.\n */\n toggleCallback = (e) => {\n e.stopPropagation();\n\n if (this.classList.contains('active')) {\n this.onClose(e);\n } else {\n this.onOpen(e);\n }\n };\n\n /**\n * Open the popup element.\n * @param {object} e\n */\n onOpen = (e) => {\n e.stopPropagation();\n\n this.classList.add('active');\n Promise.resolve(this.beforeShow(this))\n .then((res) => {\n if (!this.classList.contains('active')) {\n throw new Error('beforeShow method returned false or not string');\n }\n\n this.popup.show(true); // Show tooltip\n\n event.dispatchCustomEvent(this, 'wje-dropdown:open', {\n bubbles: true,\n detail: { target: this },\n });\n\n Promise.resolve(this.afterShow(this));\n })\n .catch((error) => {\n // ak je nejaka chyba tak to len zatvorime\n this.classList.remove('active');\n this.popup.hide(true);\n });\n };\n\n beforeClose = () => {\n // Do nothing\n };\n\n afterClose = () => {\n // Do nothing\n };\n\n onClose = (e) => {\n e.stopPropagation();\n\n this.classList.remove('active');\n Promise.resolve(this.beforeClose(this))\n .then((res) => {\n if (this.classList.contains('active')) {\n throw new Error('beforeShow method returned false or not string');\n }\n\n this.popup.hide(true); // Show tooltip\n\n event.dispatchCustomEvent(this, 'wje-dropdown:close', {\n bubbles: true,\n detail: { target: this },\n });\n\n Promise.resolve(this.afterClose(this));\n })\n .catch((error) => {\n this.classList.add('active');\n this.popup.show(true);\n });\n };\n}\n","import Dropdown from './dropdown.element.js';\n\nexport default Dropdown;\n\nDropdown.define('wje-dropdown', Dropdown);\n"],"names":[],"mappings":";;;;;AAgBe,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAK5C,cAAc;AACV,UAAO;AAOX;AAAA;AAAA;AAAA;AAAA,wCAAe;AAAA,MACX,aAAa;AAAA,IAChB;AAsBD;AAAA;AAAA;AAAA;AAAA,qCAAY;AAcZ;AAAA;AAAA;AAAA;AAAA,wDAA+B,CAAC,M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ACjD;AAAA,QACA;AAAA,QACA,KAAK;AAAA,MACR;AAAA,IACb;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,aAAa;AACT,WAAO,KAAK;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKI,YAAY;AAAA,EAEhB;AAgFA;ACxQA,SAAS,OAAO,gBAAgB,QAAQ;"}
@@ -276,6 +276,7 @@ class Event {
276
276
  constructor() {
277
277
  __privateAdd(this, _Event_instances);
278
278
  this.customEventStorage = [];
279
+ this.customEventWeakMap = /* @__PURE__ */ new WeakMap();
279
280
  self = this;
280
281
  }
281
282
  /**
@@ -303,13 +304,7 @@ class Event {
303
304
  * @returns {*}
304
305
  */
305
306
  findRecordByElement(element) {
306
- for (let index = 0, length = this.customEventStorage.length; index < length; index++) {
307
- let record = this.customEventStorage[index];
308
- if (element === record.element) {
309
- return record;
310
- }
311
- }
312
- return false;
307
+ return this.customEventStorage.find((e) => e.element === element);
313
308
  }
314
309
  /**
315
310
  * Add listener to the element. If the element is an array, the listener will be added to all elements in the array.
@@ -336,6 +331,15 @@ class Event {
336
331
  */
337
332
  writeRecord(element, originalEvent, event2, listener, options) {
338
333
  let record = this.findRecordByElement(element);
334
+ let recordListeners = this.customEventWeakMap.get(element);
335
+ if (!recordListeners) {
336
+ this.customEventWeakMap.set(element, {
337
+ [originalEvent]: []
338
+ });
339
+ recordListeners = this.customEventWeakMap.get(element);
340
+ } else {
341
+ recordListeners[originalEvent] = recordListeners[originalEvent] || [];
342
+ }
339
343
  if (record) {
340
344
  record.listeners[originalEvent] = record.listeners[originalEvent] || [];
341
345
  } else {
@@ -353,6 +357,7 @@ class Event {
353
357
  event: event2
354
358
  };
355
359
  if (!this.listenerExists(element, originalEvent, obj)) {
360
+ recordListeners[originalEvent].push(obj);
356
361
  record.listeners[originalEvent].push(obj);
357
362
  element.addEventListener(originalEvent, listener, options);
358
363
  }
@@ -388,22 +393,43 @@ class Event {
388
393
  removeListener(element, originalEvent, event2, listener, options) {
389
394
  let record = this.findRecordByElement(element);
390
395
  if (record && originalEvent in record.listeners) {
391
- let index = record.listeners[originalEvent].indexOf(listener);
392
- if (index !== -1) {
393
- record.listeners[originalEvent].splice(index, 1);
396
+ let listenerOfRecord = record.listeners[originalEvent].find((e) => e.listener === listener);
397
+ if (listenerOfRecord) {
398
+ record.listeners[originalEvent].splice(record.listeners[originalEvent].indexOf(listenerOfRecord), 1);
394
399
  }
395
400
  if (!record.listeners[originalEvent].length) {
396
401
  delete record.listeners[originalEvent];
397
402
  }
398
403
  }
404
+ let records = this.customEventWeakMap.get(element);
405
+ let listeners = records == null ? void 0 : records[originalEvent];
406
+ if (listeners) {
407
+ let listenerOfWeakMap = listeners.find((e) => e.listener === listener);
408
+ if (listenerOfWeakMap) {
409
+ listeners.splice(listeners.indexOf(listenerOfWeakMap), 1);
410
+ }
411
+ if (!listeners.length) {
412
+ delete records[originalEvent];
413
+ }
414
+ }
399
415
  listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
400
- element.removeEventListener(originalEvent, listener, options);
416
+ element == null ? void 0 : element.removeEventListener(originalEvent, listener, options);
401
417
  }
402
418
  /**
403
419
  * Remove all event listeners from the specified element and delete the element from the custom event storage.
404
420
  * @param {HTMLElement} element The element from which all listeners will be removed.
405
421
  */
406
422
  removeElement(element) {
423
+ let listeners = this.customEventWeakMap.get(element);
424
+ if (listeners) {
425
+ queueMicrotask(() => {
426
+ for (let event2 in listeners) {
427
+ listeners[event2].forEach((e) => {
428
+ element.removeEventListener(event2, e.listener, e.options);
429
+ });
430
+ }
431
+ });
432
+ }
407
433
  this.customEventStorage = this.customEventStorage.filter((e) => {
408
434
  return e.element !== element;
409
435
  });
@@ -426,15 +452,20 @@ _Event_instances = new WeakSet();
426
452
  */
427
453
  dispatch_fn = function(e) {
428
454
  let element = this;
429
- let record = self.findRecordByElement(element);
430
- let listeners = record.listeners[e.type];
455
+ let record = self.customEventWeakMap.get(this);
456
+ if (!record) return;
457
+ let listeners = record[e.type];
431
458
  listeners.forEach((listener) => {
432
459
  self.dispatchCustomEvent(element, listener.event, {
433
460
  originalEvent: (e == null ? void 0 : e.type) || null,
434
461
  context: element,
435
462
  event: self
436
463
  });
437
- if (listener.options && listener.options.stopPropagation === true) e.stopPropagation();
464
+ if (listener.options && listener.options.stopPropagation === true) {
465
+ e.stopPropagation();
466
+ e.stopImmediatePropagation();
467
+ e.preventDefault();
468
+ }
438
469
  });
439
470
  };
440
471
  let event = new Event();
@@ -462,6 +493,9 @@ const _WJElement = class _WJElement extends HTMLElement {
462
493
  this.setUpAccessors();
463
494
  this.drawingStatus = this.drawingStatuses.START;
464
495
  await this.display(force);
496
+ const sheet = new CSSStyleSheet();
497
+ sheet.replaceSync(this.constructor.cssStyleSheet);
498
+ this.context.adoptedStyleSheets = [sheet];
465
499
  resolve();
466
500
  });
467
501
  });
@@ -482,7 +516,11 @@ const _WJElement = class _WJElement extends HTMLElement {
482
516
  DISCONNECTED: 6
483
517
  };
484
518
  this.drawingStatus = this.drawingStatuses.CREATED;
485
- this.isInitializing = true;
519
+ this.refreshUpdatePromise();
520
+ this._pristine = true;
521
+ this._pristineCauseWeakMap = /* @__PURE__ */ new WeakMap();
522
+ this.isRendering = false;
523
+ this.rafId = null;
486
524
  }
487
525
  /**
488
526
  * Sets the value of the 'permission' attribute.
@@ -670,9 +708,6 @@ const _WJElement = class _WJElement extends HTMLElement {
670
708
  * Refreshes the update promise for rendering lifecycle management.
671
709
  */
672
710
  refreshUpdatePromise() {
673
- if (this.updateComplete) {
674
- this.rejectPromise("Update cancelled");
675
- }
676
711
  this.updateComplete = new Promise((resolve, reject) => {
677
712
  this.finisPromise = resolve;
678
713
  this.rejectPromise = reject;
@@ -683,10 +718,16 @@ const _WJElement = class _WJElement extends HTMLElement {
683
718
  * Lifecycle method invoked when the component is connected to the DOM.
684
719
  */
685
720
  connectedCallback() {
721
+ var _a;
722
+ this.originalVisibility = this.style.visibility;
723
+ this.style.visibility = "hidden";
724
+ (_a = this.setupAttributes) == null ? void 0 : _a.call(this);
725
+ this.setUpAccessors();
686
726
  this.drawingStatus = this.drawingStatuses.ATTACHED;
687
- this.refreshUpdatePromise();
688
- this.renderPromise = this.initWjElement(true);
689
- this.isInitializing = false;
727
+ if (!this.isRendering) {
728
+ this._pristine = false;
729
+ this.enqueueUpdate();
730
+ }
690
731
  }
691
732
  /**
692
733
  * Sets up attributes and event listeners for the component.
@@ -728,6 +769,7 @@ const _WJElement = class _WJElement extends HTMLElement {
728
769
  */
729
770
  disconnectedCallback() {
730
771
  var _a, _b;
772
+ this.stopRenderLoop();
731
773
  (_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
732
774
  if (this.isAttached) this.context.innerHTML = "";
733
775
  this.isAttached = false;
@@ -735,28 +777,14 @@ const _WJElement = class _WJElement extends HTMLElement {
735
777
  this.drawingStatus = this.drawingStatuses.DISCONNECTED;
736
778
  this.componentCleanup();
737
779
  }
738
- async processCurrentRenderPromise() {
739
- var _a;
740
- try {
741
- if (this.renderPromise && (this.renderPromise instanceof Promise || ((_a = this.renderPromise) == null ? void 0 : _a.constructor.name) === "Promise")) {
742
- await this.renderPromise;
743
- }
744
- } catch (e) {
745
- console.error("An error occurred:", e);
746
- Promise.reject(e);
747
- }
748
- }
749
780
  /**
750
- * Enqueues an update to the component.
751
- * @returns A promise that resolves when the update is complete.
781
+ * Enqueues an update for the component.
782
+ * This method processes the current render promise and then refreshes the component.
752
783
  */
753
- async enqueueUpdate() {
754
- await this.processCurrentRenderPromise();
755
- const result = this._refresh();
756
- if (result !== null) {
757
- await result;
784
+ enqueueUpdate() {
785
+ if (!this.rafId) {
786
+ this.rafId = requestAnimationFrame(() => this._refresh());
758
787
  }
759
- this.renderPromise = null;
760
788
  }
761
789
  /**
762
790
  * Lifecycle method invoked when an observed attribute changes.
@@ -765,12 +793,14 @@ const _WJElement = class _WJElement extends HTMLElement {
765
793
  * @param newName The new value of the attribute.
766
794
  */
767
795
  attributeChangedCallback(name, old, newName) {
768
- if (old !== newName && !this.isInitializing) {
769
- this.renderPromise = this.enqueueUpdate();
796
+ if (old !== newName) {
797
+ this._pristine = false;
798
+ this.enqueueUpdate();
770
799
  }
771
800
  }
772
801
  refresh() {
773
- this.renderPromise = this.enqueueUpdate();
802
+ this._pristine = false;
803
+ this.enqueueUpdate();
774
804
  }
775
805
  /**
776
806
  * Refreshes the component by reinitializing it if it is in a drawing state.
@@ -782,18 +812,47 @@ const _WJElement = class _WJElement extends HTMLElement {
782
812
  * 4. Calls the `afterDisconnect` hook if defined.
783
813
  * 5. Reinitializes the component by calling `initWjElement` with `true` to force initialization.
784
814
  * If the component is not in a drawing state, it simply returns a resolved promise.
785
- * @returns {Promise<void>} A promise that resolves when the refresh is complete.
786
815
  */
787
- _refresh() {
816
+ async _refresh() {
788
817
  var _a, _b, _c;
789
- if (this.drawingStatus && this.drawingStatus >= this.drawingStatuses.START) {
790
- (_a = this.beforeRedraw) == null ? void 0 : _a.call(this);
791
- (_b = this.beforeDisconnect) == null ? void 0 : _b.call(this);
792
- this.refreshUpdatePromise();
793
- (_c = this.afterDisconnect) == null ? void 0 : _c.call(this);
794
- return this.initWjElement(true);
818
+ if (this.isRendering) {
819
+ this.rafId = requestAnimationFrame(() => this._refresh());
820
+ return;
821
+ }
822
+ if (!this._pristine) {
823
+ this._pristine = true;
824
+ this.isRendering = true;
825
+ if (this.isAttached) {
826
+ (_a = this.beforeRedraw) == null ? void 0 : _a.call(this);
827
+ (_b = this.beforeDisconnect) == null ? void 0 : _b.call(this);
828
+ this.refreshUpdatePromise();
829
+ (_c = this.afterDisconnect) == null ? void 0 : _c.call(this);
830
+ } else {
831
+ this.stopRenderLoop();
832
+ }
833
+ try {
834
+ await this.initWjElement(true);
835
+ } catch (error) {
836
+ console.error("Render error:", error);
837
+ } finally {
838
+ this.isRendering = false;
839
+ if (!this._pristine) {
840
+ this._pristine = false;
841
+ this.enqueueUpdate();
842
+ } else {
843
+ this.style.visibility = this.originalVisibility;
844
+ }
845
+ }
846
+ }
847
+ if (this.isAttached && !this.isRendering) {
848
+ this.rafId = requestAnimationFrame(() => this._refresh());
849
+ }
850
+ }
851
+ stopRenderLoop() {
852
+ if (this.rafId) {
853
+ cancelAnimationFrame(this.rafId);
854
+ this.rafId = null;
795
855
  }
796
- return Promise.resolve();
797
856
  }
798
857
  /**
799
858
  * Renders the component within the provided context.
@@ -825,7 +884,6 @@ const _WJElement = class _WJElement extends HTMLElement {
825
884
  this.template = this.constructor.customTemplate || document.createElement("template");
826
885
  if (force) {
827
886
  [...this.context.childNodes].forEach(this.context.removeChild.bind(this.context));
828
- this.isAttached = false;
829
887
  }
830
888
  this.context.append(this.template.content.cloneNode(true));
831
889
  if (this.noShow || this.isPermissionCheck && !WjePermissionsApi.isPermissionFulfilled(this.permission)) {
@@ -840,7 +898,7 @@ const _WJElement = class _WJElement extends HTMLElement {
840
898
  async render() {
841
899
  this.drawingStatus = this.drawingStatuses.DRAWING;
842
900
  let _draw = this.draw(this.context, this.store, WjElementUtils.getAttributes(this));
843
- if (_draw instanceof Promise || (_draw == null ? void 0 : _draw.constructor.name) === "Promise") {
901
+ if (_draw instanceof Promise) {
844
902
  _draw = await _draw;
845
903
  }
846
904
  let rend = _draw;
@@ -927,15 +985,12 @@ const _WJElement = class _WJElement extends HTMLElement {
927
985
  return new Promise(async (resolve, reject) => {
928
986
  var _a;
929
987
  const __beforeDraw = this.beforeDraw(this.context, this.store, WjElementUtils.getAttributes(this));
930
- if (__beforeDraw instanceof Promise || (__beforeDraw == null ? void 0 : __beforeDraw.constructor.name) === "Promise") {
988
+ if (__beforeDraw instanceof Promise) {
931
989
  await __beforeDraw;
932
990
  }
933
- const sheet = new CSSStyleSheet();
934
- sheet.replaceSync(this.constructor.cssStyleSheet);
935
- this.context.adoptedStyleSheets = [sheet];
936
991
  await this.render();
937
992
  const __afterDraw = (_a = this.afterDraw) == null ? void 0 : _a.call(this, this.context, this.store, WjElementUtils.getAttributes(this));
938
- if (__afterDraw instanceof Promise || (__afterDraw == null ? void 0 : __afterDraw.constructor.name) === "Promise") {
993
+ if (__afterDraw instanceof Promise) {
939
994
  await __afterDraw;
940
995
  }
941
996
  this.finisPromise();