wj-elements 0.1.155 → 0.1.157
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dark.css +8 -5
- package/dist/light.css +9 -6
- package/dist/packages/utils/event.d.ts +1 -1
- package/dist/packages/utils/permissions-api.d.ts +2 -2
- package/dist/packages/wje-accordion/accordion.element.d.ts +2 -2
- package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +1 -1
- package/dist/packages/wje-animation/animation.element.d.ts +1 -1
- package/dist/packages/wje-aside/aside.element.d.ts +1 -1
- package/dist/packages/wje-avatar/avatar.element.d.ts +3 -3
- package/dist/packages/wje-badge/badge.element.d.ts +1 -1
- package/dist/packages/wje-breadcrumb/breadcrumb.element.d.ts +2 -2
- package/dist/packages/wje-breadcrumbs/breadcrumbs.element.d.ts +3 -3
- package/dist/packages/wje-button/button.element.d.ts +9 -5
- package/dist/packages/wje-button-group/button-group.element.d.ts +2 -2
- package/dist/packages/wje-card/card.element.d.ts +1 -1
- package/dist/packages/wje-card-content/card-content.element.d.ts +1 -1
- package/dist/packages/wje-card-controls/card-controls.element.d.ts +1 -1
- package/dist/packages/wje-card-header/card-header.element.d.ts +1 -1
- package/dist/packages/wje-card-subtitle/card-subtitle.element.d.ts +1 -1
- package/dist/packages/wje-card-title/card-title.element.d.ts +1 -1
- package/dist/packages/wje-carousel/carousel.element.d.ts +2 -2
- package/dist/packages/wje-color-picker/color-picker.element.d.ts +4 -4
- package/dist/packages/wje-container/container.element.d.ts +1 -1
- package/dist/packages/wje-dialog/dialog.element.d.ts +2 -2
- package/dist/packages/wje-dropdown/dropdown.element.d.ts +6 -7
- package/dist/packages/wje-element/element.d.ts +11 -9
- package/dist/packages/wje-file-upload/file-upload.element.d.ts +2 -2
- package/dist/packages/wje-file-upload-item/file-upload-item.element.d.ts +1 -1
- package/dist/packages/wje-footer/footer.element.d.ts +1 -1
- package/dist/packages/wje-format-digital/format-digital.element.d.ts +1 -1
- package/dist/packages/wje-header/header.element.d.ts +1 -1
- package/dist/packages/wje-icon/icon.element.d.ts +1 -1
- package/dist/packages/wje-icon-picker/icon-picker.element.d.ts +1 -1
- package/dist/packages/wje-img/img.element.d.ts +5 -5
- package/dist/packages/wje-img-comparer/img-comparer.element.d.ts +1 -1
- package/dist/packages/wje-infinite-scroll/infinite-scroll.element.d.ts +3 -3
- package/dist/packages/wje-input-file/input-file.element.d.ts +1 -1
- package/dist/packages/wje-item/item.element.d.ts +1 -1
- package/dist/packages/wje-kanban/kanban.element.d.ts +3 -3
- package/dist/packages/wje-label/label.element.d.ts +1 -1
- package/dist/packages/wje-level-indicator/level-indicator.element.d.ts +2 -2
- package/dist/packages/wje-main/main.element.d.ts +1 -1
- package/dist/packages/wje-menu/menu.element.d.ts +1 -1
- package/dist/packages/wje-menu-button/menu-button.element.d.ts +1 -1
- package/dist/packages/wje-menu-label/menu-label.element.d.ts +1 -1
- package/dist/packages/wje-option/option.element.d.ts +1 -1
- package/dist/packages/wje-options/options.element.d.ts +1 -1
- package/dist/packages/wje-pagination/pagination.element.d.ts +5 -5
- package/dist/packages/wje-popup/popup.element.d.ts +1 -10
- package/dist/packages/wje-progress-bar/progress-bar.element.d.ts +1 -1
- package/dist/packages/wje-radio/radio.element.d.ts +1 -1
- package/dist/packages/wje-rate/rate.element.d.ts +3 -3
- package/dist/packages/wje-relative-time/relative-time.element.d.ts +1 -1
- package/dist/packages/wje-reorder/reorder.element.d.ts +1 -1
- package/dist/packages/wje-route/route.element.d.ts +1 -1
- package/dist/packages/wje-router/router.element.d.ts +1 -1
- package/dist/packages/wje-router-link/router-link.element.d.ts +1 -1
- package/dist/packages/wje-select/select.element.d.ts +2 -2
- package/dist/packages/wje-slider/slider.element.d.ts +1 -1
- package/dist/packages/wje-split-view/split-view.element.d.ts +1 -1
- package/dist/packages/wje-textarea/textarea.element.d.ts +1 -1
- package/dist/packages/wje-tooltip/tooltip.element.d.ts +1 -0
- package/dist/packages/wje-tree-item/tree-item.element.d.ts +2 -2
- package/dist/{popup.element-tyYxow0p.js → popup.element-AaduHP2r.js} +44 -44
- package/dist/{popup.element-tyYxow0p.js.map → popup.element-AaduHP2r.js.map} +1 -1
- package/dist/wje-button.js +30 -0
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-color-picker.js +8 -1
- package/dist/wje-color-picker.js.map +1 -1
- package/dist/wje-dialog.js +1 -3
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-dropdown.js +32 -14
- package/dist/wje-dropdown.js.map +1 -1
- package/dist/wje-element.js +112 -79
- package/dist/wje-element.js.map +1 -1
- package/dist/wje-icon-picker.js +1 -1
- package/dist/wje-img.js +0 -1
- package/dist/wje-img.js.map +1 -1
- package/dist/wje-master.js +1 -1
- package/dist/wje-menu-item.js +4 -5
- package/dist/wje-menu-item.js.map +1 -1
- package/dist/wje-pagination.js +2 -4
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-popup.js +1 -1
- package/dist/wje-select.js +1 -1
- package/dist/wje-sliding-container.js +2 -2
- package/dist/wje-sliding-container.js.map +1 -1
- package/dist/wje-toast.js +2 -1
- package/dist/wje-toast.js.map +1 -1
- package/dist/wje-tooltip.js +11 -0
- package/dist/wje-tooltip.js.map +1 -1
- package/package.json +7 -12
- package/dist/packages/wje-accordion/accordion.test.d.ts +0 -0
- package/dist/packages/wje-color-picker/color-picker.test.d.ts +0 -1
package/dist/wje-dropdown.js
CHANGED
|
@@ -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-
|
|
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
|
-
|
|
73
|
-
|
|
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.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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);
|
package/dist/wje-dropdown.js.map
CHANGED
|
@@ -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: this },\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,MAAM;AAClC,UAAI,EAAE,OAAO,OAAO,WAAW,MAAM;AACjC,aAAK,UAAU,OAAO,QAAQ;AAC9B,aAAK,MAAM,KAAM;AAAA,MAC7B;AAAA,IACK;AAkHD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0CAAiB,CAAC,MAAM;AACpB,QAAE,gBAAiB;AACnB,UAAI,KAAK,UAAU,SAAS,QAAQ,GAAG;AACnC,aAAK,QAAQ,CAAC;AAAA,MAC1B,OAAe;AACH,aAAK,OAAO,CAAC;AAAA,MACzB;AAAA,IACK;AAMD;AAAA;AAAA;AAAA;AAAA,kCAAS,CAAC,MAAM;AACZ,QAAE,gBAAiB;AAEnB,WAAK,UAAU,IAAI,QAAQ;AAC3B,cAAQ,QAAQ,KAAK,WAAW,IAAI,CAAC,E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aAAa,GAAG;AAClC,YAAM;AAAA,QACF,MAAM,KAAK,KAAK,iBAAiB,eAAe,CAAC;AAAA,QACjD;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;AA4DA;AC1OA,SAAS,OAAO,gBAAgB,QAAQ;"}
|
|
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 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,MAAM;AAClC,UAAI,EAAE,OAAO,OAAO,WAAW,MAAM;AACjC,aAAK,UAAU,OAAO,QAAQ;AAC9B,aAAK,MAAM,KAAM;AAAA,MAC7B;AAAA,IACK;AAqED,6CAAoB,MAAM;AACtB,UAAI,KAAK,UAAU,SAAS,QAAQ,GAAG;AACnC,aAAK,UAAU,OAAO,QAAQ;AAE9B,cAAM,oBAAoB,MAAM,sBAAsB;AAAA,UAClD,SAAS;AAAA,UACT,QAAQ,EAAE,QAAQ,KAAM;AAAA,QACxC,CAAa;AAAA,MACb;AAAA,IACK;AA8CD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0CAAiB,CAAC,MAAM;AACpB,QAAE,gBAAiB;AAEnB,UAAI,KAAK,UAAU,SAAS,QAAQ,GAAG;AACnC,aAAK,QAAQ,CAAC;AAAA,MAC1B,OAAe;AACH,aAAK,OAAO,CAAC;AAAA,MACzB;AAAA,IACK;AAMD;AAAA;AAAA;AAAA;AAAA,kCAAS,CAAC,MAAM;AACZ,QAAE,gBAAiB;AAEnB,WAAK,UAAU,IAAI,QAAQ;AAC3B,cAAQ,QAAQ,KAAK,WAAW,IAAI,CAAC,EAChC,KAAK,CAAC,QAAQ;AACX,YAAI,CAAC,KAAK,UAAU,SAAS,QAAQ,GAAG;AACpC,gBAAM,IAAI,MAAM,gDAAgD;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I,YAAY;AACR,UAAM,YAAY,MAAM,kBAAkB,MAAM,KAAK,iBAAiB;AAEtE,QAAI,KAAK,YAAY,SAAS;AAC1B,YAAM,YAAY,MAAM,cAAc,MAAM,KAAK,MAAM;AACvD,YAAM,YAAY,MAAM,cAAc,MAAM,KAAK,OAAO;AAAA,IACpE,OAAe;AACH,YAAM,YAAY,KAAK,YAAY,SAAS,MAAM,KAAK,gBAAgB,EAAE,SAAS,KAAI,CAAE;AAAA,IACpG;AAEQ,QAAI,KAAK,aAAa,aAAa,GAAG;AAClC,YAAM;AAAA,QACF,MAAM,KAAK,KAAK,iBAAiB,eAAe,CAAC;AAAA,QACjD;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;"}
|
package/dist/wje-element.js
CHANGED
|
@@ -275,7 +275,7 @@ var self;
|
|
|
275
275
|
class Event {
|
|
276
276
|
constructor() {
|
|
277
277
|
__privateAdd(this, _Event_instances);
|
|
278
|
-
this.
|
|
278
|
+
this.customEventWeakMap = /* @__PURE__ */ new WeakMap();
|
|
279
279
|
self = this;
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
@@ -303,13 +303,7 @@ class Event {
|
|
|
303
303
|
* @returns {*}
|
|
304
304
|
*/
|
|
305
305
|
findRecordByElement(element) {
|
|
306
|
-
|
|
307
|
-
let record = this.customEventStorage[index];
|
|
308
|
-
if (element === record.element) {
|
|
309
|
-
return record;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return false;
|
|
306
|
+
return this.customEventWeakMap.get(element);
|
|
313
307
|
}
|
|
314
308
|
/**
|
|
315
309
|
* Add listener to the element. If the element is an array, the listener will be added to all elements in the array.
|
|
@@ -335,16 +329,14 @@ class Event {
|
|
|
335
329
|
* @param options
|
|
336
330
|
*/
|
|
337
331
|
writeRecord(element, originalEvent, event2, listener, options) {
|
|
338
|
-
let
|
|
339
|
-
if (
|
|
340
|
-
|
|
332
|
+
let recordListeners = this.findRecordByElement(element);
|
|
333
|
+
if (!recordListeners) {
|
|
334
|
+
this.customEventWeakMap.set(element, {
|
|
335
|
+
[originalEvent]: []
|
|
336
|
+
});
|
|
337
|
+
recordListeners = this.findRecordByElement(element);
|
|
341
338
|
} else {
|
|
342
|
-
|
|
343
|
-
element,
|
|
344
|
-
listeners: {}
|
|
345
|
-
};
|
|
346
|
-
record.listeners[originalEvent] = [];
|
|
347
|
-
this.customEventStorage.push(record);
|
|
339
|
+
recordListeners[originalEvent] = recordListeners[originalEvent] || [];
|
|
348
340
|
}
|
|
349
341
|
listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
|
|
350
342
|
let obj = {
|
|
@@ -353,8 +345,11 @@ class Event {
|
|
|
353
345
|
event: event2
|
|
354
346
|
};
|
|
355
347
|
if (!this.listenerExists(element, originalEvent, obj)) {
|
|
356
|
-
|
|
348
|
+
recordListeners[originalEvent].push(obj);
|
|
357
349
|
element.addEventListener(originalEvent, listener, options);
|
|
350
|
+
obj.unbind = () => {
|
|
351
|
+
element.removeEventListener(originalEvent, listener, options);
|
|
352
|
+
};
|
|
358
353
|
}
|
|
359
354
|
}
|
|
360
355
|
/**
|
|
@@ -375,7 +370,7 @@ class Event {
|
|
|
375
370
|
*/
|
|
376
371
|
listenerExists(element, event2, listener) {
|
|
377
372
|
let record = this.findRecordByElement(element);
|
|
378
|
-
return record
|
|
373
|
+
return record[event2].some((e) => this.deepEqual(e, listener));
|
|
379
374
|
}
|
|
380
375
|
/**
|
|
381
376
|
* Remove listener from the element and delete the listener from the custom event storage.
|
|
@@ -386,27 +381,36 @@ class Event {
|
|
|
386
381
|
* @param options
|
|
387
382
|
*/
|
|
388
383
|
removeListener(element, originalEvent, event2, listener, options) {
|
|
389
|
-
let
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
384
|
+
let records = this.findRecordByElement(element);
|
|
385
|
+
let listeners = records == null ? void 0 : records[originalEvent];
|
|
386
|
+
listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
|
|
387
|
+
if (listeners) {
|
|
388
|
+
let listenerOfWeakMap = listeners.find((e) => e.listener === listener);
|
|
389
|
+
if (listenerOfWeakMap) {
|
|
390
|
+
listeners.splice(listeners.indexOf(listenerOfWeakMap), 1);
|
|
394
391
|
}
|
|
395
|
-
if (!
|
|
396
|
-
delete
|
|
392
|
+
if (!listeners.length) {
|
|
393
|
+
delete records[originalEvent];
|
|
397
394
|
}
|
|
398
395
|
}
|
|
399
|
-
|
|
400
|
-
element.removeEventListener(originalEvent, listener, options);
|
|
396
|
+
element == null ? void 0 : element.removeEventListener(originalEvent, listener, options);
|
|
401
397
|
}
|
|
402
398
|
/**
|
|
403
399
|
* Remove all event listeners from the specified element and delete the element from the custom event storage.
|
|
404
400
|
* @param {HTMLElement} element The element from which all listeners will be removed.
|
|
405
401
|
*/
|
|
406
402
|
removeElement(element) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
403
|
+
let listeners = this.customEventWeakMap.get(element);
|
|
404
|
+
if (listeners) {
|
|
405
|
+
queueMicrotask(() => {
|
|
406
|
+
for (let event2 in listeners) {
|
|
407
|
+
listeners[event2].forEach((e) => {
|
|
408
|
+
element.removeEventListener(event2, e.listener, e.options);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
this.customEventWeakMap.delete(element);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
410
414
|
}
|
|
411
415
|
// TODO
|
|
412
416
|
createPromiseFromEvent(element, event2) {
|
|
@@ -426,15 +430,20 @@ _Event_instances = new WeakSet();
|
|
|
426
430
|
*/
|
|
427
431
|
dispatch_fn = function(e) {
|
|
428
432
|
let element = this;
|
|
429
|
-
let record = self.
|
|
430
|
-
|
|
433
|
+
let record = self.customEventWeakMap.get(this);
|
|
434
|
+
if (!record) return;
|
|
435
|
+
let listeners = record[e.type];
|
|
431
436
|
listeners.forEach((listener) => {
|
|
432
437
|
self.dispatchCustomEvent(element, listener.event, {
|
|
433
438
|
originalEvent: (e == null ? void 0 : e.type) || null,
|
|
434
439
|
context: element,
|
|
435
440
|
event: self
|
|
436
441
|
});
|
|
437
|
-
if (listener.options && listener.options.stopPropagation === true)
|
|
442
|
+
if (listener.options && listener.options.stopPropagation === true) {
|
|
443
|
+
e.stopPropagation();
|
|
444
|
+
e.stopImmediatePropagation();
|
|
445
|
+
e.preventDefault();
|
|
446
|
+
}
|
|
438
447
|
});
|
|
439
448
|
};
|
|
440
449
|
let event = new Event();
|
|
@@ -462,6 +471,9 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
462
471
|
this.setUpAccessors();
|
|
463
472
|
this.drawingStatus = this.drawingStatuses.START;
|
|
464
473
|
await this.display(force);
|
|
474
|
+
const sheet = new CSSStyleSheet();
|
|
475
|
+
sheet.replaceSync(this.constructor.cssStyleSheet);
|
|
476
|
+
this.context.adoptedStyleSheets = [sheet];
|
|
465
477
|
resolve();
|
|
466
478
|
});
|
|
467
479
|
});
|
|
@@ -482,7 +494,11 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
482
494
|
DISCONNECTED: 6
|
|
483
495
|
};
|
|
484
496
|
this.drawingStatus = this.drawingStatuses.CREATED;
|
|
485
|
-
this.
|
|
497
|
+
this.refreshUpdatePromise();
|
|
498
|
+
this._pristine = true;
|
|
499
|
+
this._pristineCauseWeakMap = /* @__PURE__ */ new WeakMap();
|
|
500
|
+
this.isRendering = false;
|
|
501
|
+
this.rafId = null;
|
|
486
502
|
}
|
|
487
503
|
/**
|
|
488
504
|
* Sets the value of the 'permission' attribute.
|
|
@@ -670,9 +686,6 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
670
686
|
* Refreshes the update promise for rendering lifecycle management.
|
|
671
687
|
*/
|
|
672
688
|
refreshUpdatePromise() {
|
|
673
|
-
if (this.updateComplete) {
|
|
674
|
-
this.rejectPromise("Update cancelled");
|
|
675
|
-
}
|
|
676
689
|
this.updateComplete = new Promise((resolve, reject) => {
|
|
677
690
|
this.finisPromise = resolve;
|
|
678
691
|
this.rejectPromise = reject;
|
|
@@ -683,10 +696,16 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
683
696
|
* Lifecycle method invoked when the component is connected to the DOM.
|
|
684
697
|
*/
|
|
685
698
|
connectedCallback() {
|
|
699
|
+
var _a;
|
|
700
|
+
this.originalVisibility = this.style.visibility;
|
|
701
|
+
this.style.visibility = "hidden";
|
|
702
|
+
(_a = this.setupAttributes) == null ? void 0 : _a.call(this);
|
|
703
|
+
this.setUpAccessors();
|
|
686
704
|
this.drawingStatus = this.drawingStatuses.ATTACHED;
|
|
687
|
-
this.
|
|
688
|
-
|
|
689
|
-
|
|
705
|
+
if (!this.isRendering) {
|
|
706
|
+
this._pristine = false;
|
|
707
|
+
this.enqueueUpdate();
|
|
708
|
+
}
|
|
690
709
|
}
|
|
691
710
|
/**
|
|
692
711
|
* Sets up attributes and event listeners for the component.
|
|
@@ -728,6 +747,7 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
728
747
|
*/
|
|
729
748
|
disconnectedCallback() {
|
|
730
749
|
var _a, _b;
|
|
750
|
+
this.stopRenderLoop();
|
|
731
751
|
(_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
|
|
732
752
|
if (this.isAttached) this.context.innerHTML = "";
|
|
733
753
|
this.isAttached = false;
|
|
@@ -735,28 +755,14 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
735
755
|
this.drawingStatus = this.drawingStatuses.DISCONNECTED;
|
|
736
756
|
this.componentCleanup();
|
|
737
757
|
}
|
|
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
758
|
/**
|
|
750
|
-
* Enqueues an update
|
|
751
|
-
*
|
|
759
|
+
* Enqueues an update for the component.
|
|
760
|
+
* This method processes the current render promise and then refreshes the component.
|
|
752
761
|
*/
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
if (result !== null) {
|
|
757
|
-
await result;
|
|
762
|
+
enqueueUpdate() {
|
|
763
|
+
if (!this.rafId) {
|
|
764
|
+
this.rafId = requestAnimationFrame(() => this._refresh());
|
|
758
765
|
}
|
|
759
|
-
this.renderPromise = null;
|
|
760
766
|
}
|
|
761
767
|
/**
|
|
762
768
|
* Lifecycle method invoked when an observed attribute changes.
|
|
@@ -765,12 +771,14 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
765
771
|
* @param newName The new value of the attribute.
|
|
766
772
|
*/
|
|
767
773
|
attributeChangedCallback(name, old, newName) {
|
|
768
|
-
if (old !== newName
|
|
769
|
-
this.
|
|
774
|
+
if (old !== newName) {
|
|
775
|
+
this._pristine = false;
|
|
776
|
+
this.enqueueUpdate();
|
|
770
777
|
}
|
|
771
778
|
}
|
|
772
779
|
refresh() {
|
|
773
|
-
this.
|
|
780
|
+
this._pristine = false;
|
|
781
|
+
this.enqueueUpdate();
|
|
774
782
|
}
|
|
775
783
|
/**
|
|
776
784
|
* Refreshes the component by reinitializing it if it is in a drawing state.
|
|
@@ -782,18 +790,47 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
782
790
|
* 4. Calls the `afterDisconnect` hook if defined.
|
|
783
791
|
* 5. Reinitializes the component by calling `initWjElement` with `true` to force initialization.
|
|
784
792
|
* 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
793
|
*/
|
|
787
|
-
_refresh() {
|
|
794
|
+
async _refresh() {
|
|
788
795
|
var _a, _b, _c;
|
|
789
|
-
if (this.
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
796
|
+
if (this.isRendering) {
|
|
797
|
+
this.rafId = requestAnimationFrame(() => this._refresh());
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
if (!this._pristine) {
|
|
801
|
+
this._pristine = true;
|
|
802
|
+
this.isRendering = true;
|
|
803
|
+
if (this.isAttached) {
|
|
804
|
+
(_a = this.beforeRedraw) == null ? void 0 : _a.call(this);
|
|
805
|
+
(_b = this.beforeDisconnect) == null ? void 0 : _b.call(this);
|
|
806
|
+
this.refreshUpdatePromise();
|
|
807
|
+
(_c = this.afterDisconnect) == null ? void 0 : _c.call(this);
|
|
808
|
+
} else {
|
|
809
|
+
this.stopRenderLoop();
|
|
810
|
+
}
|
|
811
|
+
try {
|
|
812
|
+
await this.initWjElement(true);
|
|
813
|
+
} catch (error) {
|
|
814
|
+
console.error("Render error:", error);
|
|
815
|
+
} finally {
|
|
816
|
+
this.isRendering = false;
|
|
817
|
+
if (!this._pristine) {
|
|
818
|
+
this._pristine = false;
|
|
819
|
+
this.enqueueUpdate();
|
|
820
|
+
} else {
|
|
821
|
+
this.style.visibility = this.originalVisibility;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (this.isAttached && !this.isRendering) {
|
|
826
|
+
this.rafId = requestAnimationFrame(() => this._refresh());
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
stopRenderLoop() {
|
|
830
|
+
if (this.rafId) {
|
|
831
|
+
cancelAnimationFrame(this.rafId);
|
|
832
|
+
this.rafId = null;
|
|
795
833
|
}
|
|
796
|
-
return Promise.resolve();
|
|
797
834
|
}
|
|
798
835
|
/**
|
|
799
836
|
* Renders the component within the provided context.
|
|
@@ -825,7 +862,6 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
825
862
|
this.template = this.constructor.customTemplate || document.createElement("template");
|
|
826
863
|
if (force) {
|
|
827
864
|
[...this.context.childNodes].forEach(this.context.removeChild.bind(this.context));
|
|
828
|
-
this.isAttached = false;
|
|
829
865
|
}
|
|
830
866
|
this.context.append(this.template.content.cloneNode(true));
|
|
831
867
|
if (this.noShow || this.isPermissionCheck && !WjePermissionsApi.isPermissionFulfilled(this.permission)) {
|
|
@@ -840,7 +876,7 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
840
876
|
async render() {
|
|
841
877
|
this.drawingStatus = this.drawingStatuses.DRAWING;
|
|
842
878
|
let _draw = this.draw(this.context, this.store, WjElementUtils.getAttributes(this));
|
|
843
|
-
if (_draw instanceof Promise
|
|
879
|
+
if (_draw instanceof Promise) {
|
|
844
880
|
_draw = await _draw;
|
|
845
881
|
}
|
|
846
882
|
let rend = _draw;
|
|
@@ -927,15 +963,12 @@ const _WJElement = class _WJElement extends HTMLElement {
|
|
|
927
963
|
return new Promise(async (resolve, reject) => {
|
|
928
964
|
var _a;
|
|
929
965
|
const __beforeDraw = this.beforeDraw(this.context, this.store, WjElementUtils.getAttributes(this));
|
|
930
|
-
if (__beforeDraw instanceof Promise
|
|
966
|
+
if (__beforeDraw instanceof Promise) {
|
|
931
967
|
await __beforeDraw;
|
|
932
968
|
}
|
|
933
|
-
const sheet = new CSSStyleSheet();
|
|
934
|
-
sheet.replaceSync(this.constructor.cssStyleSheet);
|
|
935
|
-
this.context.adoptedStyleSheets = [sheet];
|
|
936
969
|
await this.render();
|
|
937
970
|
const __afterDraw = (_a = this.afterDraw) == null ? void 0 : _a.call(this, this.context, this.store, WjElementUtils.getAttributes(this));
|
|
938
|
-
if (__afterDraw instanceof Promise
|
|
971
|
+
if (__afterDraw instanceof Promise) {
|
|
939
972
|
await __afterDraw;
|
|
940
973
|
}
|
|
941
974
|
this.finisPromise();
|