wj-elements 0.1.160 → 0.1.161
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/packages/wje-accordion/accordion.test.d.ts +0 -0
- package/dist/packages/wje-color-picker/color-picker.test.d.ts +1 -0
- package/dist/packages/wje-element/element.d.ts +1 -1
- package/dist/packages/wje-options/options.element.d.ts +25 -1
- package/dist/packages/wje-stepper/stepper.element.d.ts +1 -0
- package/dist/packages/wje-store/pubsub.d.ts +5 -4
- package/dist/packages/wje-tab/tab.element.d.ts +23 -0
- package/dist/packages/wje-tab-group/tab-group.element.d.ts +5 -0
- package/dist/wje-dialog.js +3 -1
- package/dist/wje-dialog.js.map +1 -1
- package/dist/wje-options.js +29 -1
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-stepper.js +52 -36
- package/dist/wje-stepper.js.map +1 -1
- package/dist/wje-store.js +7 -6
- package/dist/wje-store.js.map +1 -1
- package/dist/wje-tab-group.js +72 -12
- package/dist/wje-tab-group.js.map +1 -1
- package/dist/wje-tab-panel.js +1 -1
- package/dist/wje-tab.js +146 -1
- package/dist/wje-tab.js.map +1 -1
- package/package.json +1 -1
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -97,7 +97,7 @@ export default class WJElement extends HTMLElement {
|
|
|
97
97
|
* Gets the rendering context, either the shadow root or the component itself.
|
|
98
98
|
* @returns The rendering context.
|
|
99
99
|
*/
|
|
100
|
-
get context():
|
|
100
|
+
get context(): any;
|
|
101
101
|
/**
|
|
102
102
|
* Gets the store instance.
|
|
103
103
|
* @returns {object} The store instance.
|
|
@@ -95,9 +95,33 @@ export default class Options extends WJElement {
|
|
|
95
95
|
* @returns {boolean} True if the search attribute is present, false otherwise.
|
|
96
96
|
*/
|
|
97
97
|
get hasSearch(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Sets the value to define search-to-query params behavior.
|
|
100
|
+
* @param {string} value The value to be set for the search-to-query-params attribute.
|
|
101
|
+
*/
|
|
98
102
|
set searchToQueryParams(value: string);
|
|
99
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Retrieves the value of the 'search-to-query-params' attribute from the current instance.
|
|
105
|
+
* @returns {string | null} The value of the 'search-to-query-params' attribute, or null if the attribute is not set.
|
|
106
|
+
*/
|
|
107
|
+
get searchToQueryParams(): string | null;
|
|
108
|
+
/**
|
|
109
|
+
* Determines whether the 'search-to-query-params' attribute is present on the element.
|
|
110
|
+
* @returns {boolean} True if the 'search-to-query-params' attribute exists, otherwise false.
|
|
111
|
+
*/
|
|
100
112
|
get hasSearchToQueryParams(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Sets the value of the search parameter name attribute.
|
|
115
|
+
* @param {string} value The string value to set as the search parameter name.
|
|
116
|
+
*/
|
|
117
|
+
set searchParamName(value: string);
|
|
118
|
+
/**
|
|
119
|
+
* Gets the search parameter name used in queries.
|
|
120
|
+
* Retrieves the value of the 'search-param-name' attribute.
|
|
121
|
+
* If the attribute is not set, it defaults to 'search'.
|
|
122
|
+
* @returns {string} The search parameter name used for queries.
|
|
123
|
+
*/
|
|
124
|
+
get searchParamName(): string;
|
|
101
125
|
/**
|
|
102
126
|
* Sets the lazy attribute.
|
|
103
127
|
* @param {boolean} value The value to set for the lazy attribute.
|
|
@@ -12,10 +12,11 @@ export default class PubSub {
|
|
|
12
12
|
/**
|
|
13
13
|
* If the passed event has callbacks attached to it, loop through each one and call it.
|
|
14
14
|
* @param {string} event The name of the event to publish
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {object} [
|
|
17
|
-
* @
|
|
15
|
+
* @param {any} state The current state to pass to the callbacks
|
|
16
|
+
* @param {object} [newData] The new data to pass to the callbacks
|
|
17
|
+
* @param {object} [oldData] The old data to pass to the callbacks
|
|
18
|
+
* @returns {Array} The results of the callbacks for this event, or an empty array if no event exists
|
|
18
19
|
* @memberof PubSub
|
|
19
20
|
*/
|
|
20
|
-
publish(event: string, newData?: object, oldData?: object): any[];
|
|
21
|
+
publish(event: string, state: any, newData?: object, oldData?: object): any[];
|
|
21
22
|
}
|
|
@@ -28,6 +28,28 @@ export default class Tab extends WJElement {
|
|
|
28
28
|
* @type {boolean}
|
|
29
29
|
*/
|
|
30
30
|
last: boolean;
|
|
31
|
+
_hasPanel: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the panel attribute to the specified value.
|
|
34
|
+
* @param {string} value The value to set for the panel attribute.
|
|
35
|
+
*/
|
|
36
|
+
set panel(value: string);
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves the value of the 'panel' attribute of the element.
|
|
39
|
+
* @returns {string|null} Returns the 'panel' attribute value if it exists; otherwise, returns null.
|
|
40
|
+
*/
|
|
41
|
+
get panel(): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Sets the value of the 'route' attribute for the current object.
|
|
44
|
+
* @param {string} value The new value to set for the 'route' attribute.
|
|
45
|
+
*/
|
|
46
|
+
set route(value: string);
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the value of the 'route' attribute.
|
|
49
|
+
* If the 'route' attribute is not set, it returns null.
|
|
50
|
+
* @returns {string|null} The value of the 'route' attribute or null if not set.
|
|
51
|
+
*/
|
|
52
|
+
get route(): string | null;
|
|
31
53
|
/**
|
|
32
54
|
* Draws the component for the tab.
|
|
33
55
|
* @returns {DocumentFragment}
|
|
@@ -38,4 +60,5 @@ export default class Tab extends WJElement {
|
|
|
38
60
|
* // @fires wje-tab:change - Dispatched when the component is clicked, indicating a tab change.
|
|
39
61
|
*/
|
|
40
62
|
afterDraw(): void;
|
|
63
|
+
unbindRouterLinks: any;
|
|
41
64
|
}
|
|
@@ -31,10 +31,13 @@ export default class TabGroup extends WJElement {
|
|
|
31
31
|
* @returns {DocumentFragment}
|
|
32
32
|
*/
|
|
33
33
|
draw(context: object, store: object, params: object): DocumentFragment;
|
|
34
|
+
nav: HTMLElement;
|
|
35
|
+
moreDropdown: HTMLElement;
|
|
34
36
|
/**
|
|
35
37
|
* Sets up the event listeners after the component is drawn.
|
|
36
38
|
*/
|
|
37
39
|
afterDraw(): void;
|
|
40
|
+
checkOverflow(): void;
|
|
38
41
|
/**
|
|
39
42
|
* Removes the active attribute from all tabs and panels.
|
|
40
43
|
*/
|
|
@@ -64,4 +67,6 @@ export default class TabGroup extends WJElement {
|
|
|
64
67
|
* @returns {Array<string>} An array of all tab names.
|
|
65
68
|
*/
|
|
66
69
|
getPanelAllName(): Array<string>;
|
|
70
|
+
toggleMoreVisibility(): void;
|
|
71
|
+
dropdownActive(el: any): void;
|
|
67
72
|
}
|
package/dist/wje-dialog.js
CHANGED
|
@@ -19,7 +19,9 @@ class Dialog extends WJElement {
|
|
|
19
19
|
* @param e
|
|
20
20
|
*/
|
|
21
21
|
__publicField(this, "onOpen", (e) => {
|
|
22
|
-
this.dialog
|
|
22
|
+
if (this.dialog) {
|
|
23
|
+
this.dialog.innerHTML = "";
|
|
24
|
+
}
|
|
23
25
|
Promise.resolve(this.beforeOpen(this, e)).then((res) => {
|
|
24
26
|
this.htmlDialogBody(this.dialog);
|
|
25
27
|
this.dialog.showModal();
|
package/dist/wje-dialog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-dialog.js","sources":["../packages/wje-dialog/dialog.element.js","../packages/wje-dialog/dialog.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport '../wje-button/button.element.js';\nimport '../wje-icon/icon.element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Dialog` is a custom web component that represents a dialog.\n * @summary This element represents a dialog.\n * @documentation https://elements.webjet.sk/components/dialog\n * @status stable\n * @augments {WJElement}\n * @slot header - Slot for the header content.\n * @slot body - Slot for the body content.\n * @slot footer - Slot for the footer content.\n * @csspart dialog - The dialog wrapper.\n * @csspart header - The header of the dialog.\n * @csspart body - The body of the dialog.\n * @csspart footer - The footer of the dialog.\n * @csspart close - The close button of the dialog.\n * @cssproperty [--wje-dialog-background=var(--wje-background-color)] - Specifies the background color of the dialog.\n * @cssproperty [--wje-dialog-color=var(--wje-text-color)] - Defines the text color within the dialog.\n * @cssproperty [--wje-dialog-padding=1rem] - Controls the padding inside the dialog.\n * @cssproperty [--wje-dialog-border-radius=0.5rem] - Sets the border radius for the dialog's corners.\n * @cssproperty [--wje-dialog-box-shadow=0 2px 10px rgba(0, 0, 0, 0.1)] - Applies a shadow effect to the dialog.\n * @tag wje-dialog\n */\n\nexport default class Dialog extends WJElement {\n /**\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set placement(value) {\n this.setAttribute('placement', value);\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {string|string}\n */\n get placement() {\n return this.getAttribute('placement') || 'slide-up';\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set async(value) {\n this.setAttribute('async', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get async() {\n return this.hasAttribute('async');\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set closeHidden(value) {\n if (value) this.setAttribute('close-hidden', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get closeHidden() {\n return !!this.hasAttribute('close-hidden');\n }\n\n /**\n * Sets the headline of the dialog.\n * @type {string}\n */\n className = 'Dialog';\n\n /**\n * Returns the CSS styles for the component.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {*[]}\n */\n static get observedAttributes() {\n return [];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('fade', this.placement, params.size);\n\n let dialog = document.createElement('dialog');\n dialog.classList.add('modal-dialog');\n\n fragment.appendChild(dialog);\n\n this.dialog = dialog;\n return fragment;\n }\n\n /**\n * Creates the dialog body.\n * @param dialog\n */\n htmlDialogBody(dialog) {\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'x');\n icon.setAttribute('slot', 'icon-only');\n\n let close = document.createElement('wje-button');\n close.setAttribute('fill', 'link');\n close.setAttribute('size', 'small');\n close.setAttribute('part', 'close');\n close.addEventListener('click', (e) => {\n this.close(e);\n });\n close.appendChild(icon);\n\n let header = document.createElement('div');\n header.setAttribute('part', 'header');\n header.classList.add('dialog-header');\n if (this.hasAttribute('headline'))\n header.innerHTML = `<span part=\"headline\">${this.getAttribute('headline')}</span>`;\n\n let slotHeader = document.createElement('slot');\n slotHeader.setAttribute('name', 'header');\n\n const headerActions = document.createElement('div');\n headerActions.classList.add('header-actions');\n headerActions.setAttribute('part', 'header-actions');\n headerActions.appendChild(slotHeader);\n\n header.appendChild(headerActions);\n if (!this.closeHidden) header.appendChild(close);\n\n let contentSlot = document.createElement('slot');\n\n let body = document.createElement('div');\n body.setAttribute('part', 'body');\n body.classList.add('dialog-content');\n body.appendChild(contentSlot);\n\n let footer = document.createElement('div');\n footer.setAttribute('part', 'footer');\n footer.classList.add('dialog-footer');\n footer.innerHTML = '';\n\n let slotFooter = document.createElement('slot');\n slotFooter.setAttribute('name', 'footer');\n\n footer.appendChild(slotFooter);\n\n dialog.appendChild(header);\n dialog.appendChild(body);\n dialog.appendChild(footer);\n }\n\n /**\n * Closes the dialog.\n * @param e\n */\n close(e) {\n this.onClose(e);\n }\n\n /**\n * Draws the component after it has been drawn.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n */\n afterDraw(context, store, params) {\n if (params.trigger) {\n event.addListener(document, params.trigger, null, this.onOpen);\n }\n\n //this.dialog.addEventListener('close', this.onClose);\n }\n\n /**\n * Before the component is disconnected.\n */\n beforeDisconnect() {\n if (this.params?.trigger) {\n event.removeListener(document, this.params?.trigger, null, this.onOpen);\n }\n\n //this.dialog.removeEventListener('close', this.onClose);\n }\n\n /**\n * Before the dialog opens.\n */\n beforeOpen() {\n // Hook for extending behavior before the dialog opens\n }\n\n /**\n * After the dialog opens.\n */\n afterOpen() {\n // Hook for extending behavior after the dialog opens\n }\n\n /**\n * Before the dialog closes.\n */\n beforeClose() {\n // Hook for extending behavior before the dialog closes\n }\n\n /**\n * After the dialog closes.\n */\n afterClose() {\n // Hook for extending behavior after the dialog closes\n }\n\n /**\n * Opens the dialog.\n * @param e\n */\n onOpen = (e) => {\n this.dialog.innerHTML = '';\n\n Promise.resolve(this.beforeOpen(this, e)).then((res) => {\n this.htmlDialogBody(this.dialog);\n\n this.dialog.showModal(); // Now open the dialog\n\n if (this.dialog.open) {\n Promise.resolve(this.afterOpen(this, e));\n }\n });\n };\n\n /**\n * Closes the dialog.\n * @param {object} e\n */\n onClose = (e) => {\n Promise.resolve(this.beforeClose(this, e)).then((res) => {\n this.dialog.close(); // Now close the dialog\n\n if (!this.dialog.open) {\n Promise.resolve(this.afterClose(this, e));\n }\n });\n };\n\n /**\n * Registers an event listener on the provided button that triggers a blocking UI element\n * and executes a given promise when the button is clicked.\n * @param {HTMLElement} button The button element to attach the event listener to.\n * @param {Function} promise A function that returns a promise to be executed when the button is clicked.\n */\n registerBlockingEvent(button, promise) {\n button.addEventListener('wje-button:click', async (e) => {\n console.log('Button clicked');\n\n let blockingElement = document.createElement('div');\n blockingElement.classList.add('blocking-element');\n\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'loader-2');\n icon.setAttribute('size', '2x-large');\n\n blockingElement.appendChild(icon);\n\n let scrollOffset = this.dialog.scrollTop;\n blockingElement.style.top = `${scrollOffset}px`;\n blockingElement.style.bottom = `-${scrollOffset}px`;\n\n this.dialog.appendChild(blockingElement);\n\n await promise()\n .then((res) => {\n this.close();\n blockingElement.remove();\n })\n .catch((err) => {\n console.error(err);\n blockingElement.remove();\n });\n });\n }\n}\n","import Dialog from './d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AAAA;AAAA;AAAA;AAAA,EAKI,YAAY;AAAA,EAEhB;AAAA;AAAA;AAAA;AAAA,EAKI,cAAc;AAAA,EAElB;AAAA;AAAA;AAAA;AAAA,EAKI,aAAa;AAAA,EAEjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwCI,sBAAsB,QAAQ,SAAS;AACnC,WAAO,iBAAiB,oBAAoB,OAAO,MAAM;AACrD,cAAQ,IAAI,gBAAgB;AAE5B,UAAI,kBAAkB,SAAS,cAAc,KAAK;AAClD,sBAAgB,UAAU,IAAI,kBAAkB;AAEhD,UAAI,OAAO,SAAS,cAAc,UAAU;AAC5C,WAAK,aAAa,QAAQ,UAAU;AACpC,WAAK,aAAa,QAAQ,UAAU;AAEpC,sBAAgB,YAAY,IAAI;AAEhC,UAAI,eAAe,KAAK,OAAO;AAC/B,sBAAgB,MAAM,MAAM,GAAG,YAAY;AAC3C,sBAAgB,MAAM,SAAS,IAAI,YAAY;AAE/C,WAAK,OAAO,YAAY,eAAe;AAEvC,YAAM,QAAO,EACR,KAAK,CAAC,QAAQ;AACX,aAAK,MAAO;AACZ,wBAAgB,OAAQ;AAAA,MAC3B,CAAA,EACA,MAAM,CAAC,QAAQ;AACZ,gBAAQ,MAAM,GAAG;AACjB,wBAAgB,OAAQ;AAAA,MAC5C,CAAiB;AAAA,IACjB,CAAS;AAAA,EACT;AACA;AC3TA,OAAO,OAAO,cAAc,MAAM;"}
|
|
1
|
+
{"version":3,"file":"wje-dialog.js","sources":["../packages/wje-dialog/dialog.element.js","../packages/wje-dialog/dialog.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport '../wje-button/button.element.js';\nimport '../wje-icon/icon.element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Dialog` is a custom web component that represents a dialog.\n * @summary This element represents a dialog.\n * @documentation https://elements.webjet.sk/components/dialog\n * @status stable\n * @augments {WJElement}\n * @slot header - Slot for the header content.\n * @slot body - Slot for the body content.\n * @slot footer - Slot for the footer content.\n * @csspart dialog - The dialog wrapper.\n * @csspart header - The header of the dialog.\n * @csspart body - The body of the dialog.\n * @csspart footer - The footer of the dialog.\n * @csspart close - The close button of the dialog.\n * @cssproperty [--wje-dialog-background=var(--wje-background-color)] - Specifies the background color of the dialog.\n * @cssproperty [--wje-dialog-color=var(--wje-text-color)] - Defines the text color within the dialog.\n * @cssproperty [--wje-dialog-padding=1rem] - Controls the padding inside the dialog.\n * @cssproperty [--wje-dialog-border-radius=0.5rem] - Sets the border radius for the dialog's corners.\n * @cssproperty [--wje-dialog-box-shadow=0 2px 10px rgba(0, 0, 0, 0.1)] - Applies a shadow effect to the dialog.\n * @tag wje-dialog\n */\n\nexport default class Dialog extends WJElement {\n /**\n * @class\n */\n constructor() {\n super();\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set placement(value) {\n this.setAttribute('placement', value);\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {string|string}\n */\n get placement() {\n return this.getAttribute('placement') || 'slide-up';\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set async(value) {\n this.setAttribute('async', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get async() {\n return this.hasAttribute('async');\n }\n\n /**\n * Sets the headline of the dialog.\n * @param value\n */\n set closeHidden(value) {\n if (value) this.setAttribute('close-hidden', '');\n }\n\n /**\n * Gets the headline of the dialog.\n * @returns {boolean}\n */\n get closeHidden() {\n return !!this.hasAttribute('close-hidden');\n }\n\n /**\n * Sets the headline of the dialog.\n * @type {string}\n */\n className = 'Dialog';\n\n /**\n * Returns the CSS styles for the component.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {*[]}\n */\n static get observedAttributes() {\n return [];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n this.classList.add('fade', this.placement, params.size);\n\n let dialog = document.createElement('dialog');\n dialog.classList.add('modal-dialog');\n\n fragment.appendChild(dialog);\n\n this.dialog = dialog;\n return fragment;\n }\n\n /**\n * Creates the dialog body.\n * @param dialog\n */\n htmlDialogBody(dialog) {\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'x');\n icon.setAttribute('slot', 'icon-only');\n\n let close = document.createElement('wje-button');\n close.setAttribute('fill', 'link');\n close.setAttribute('size', 'small');\n close.setAttribute('part', 'close');\n close.addEventListener('click', (e) => {\n this.close(e);\n });\n close.appendChild(icon);\n\n let header = document.createElement('div');\n header.setAttribute('part', 'header');\n header.classList.add('dialog-header');\n if (this.hasAttribute('headline'))\n header.innerHTML = `<span part=\"headline\">${this.getAttribute('headline')}</span>`;\n\n let slotHeader = document.createElement('slot');\n slotHeader.setAttribute('name', 'header');\n\n const headerActions = document.createElement('div');\n headerActions.classList.add('header-actions');\n headerActions.setAttribute('part', 'header-actions');\n headerActions.appendChild(slotHeader);\n\n header.appendChild(headerActions);\n if (!this.closeHidden) header.appendChild(close);\n\n let contentSlot = document.createElement('slot');\n\n let body = document.createElement('div');\n body.setAttribute('part', 'body');\n body.classList.add('dialog-content');\n body.appendChild(contentSlot);\n\n let footer = document.createElement('div');\n footer.setAttribute('part', 'footer');\n footer.classList.add('dialog-footer');\n footer.innerHTML = '';\n\n let slotFooter = document.createElement('slot');\n slotFooter.setAttribute('name', 'footer');\n\n footer.appendChild(slotFooter);\n\n dialog.appendChild(header);\n dialog.appendChild(body);\n dialog.appendChild(footer);\n }\n\n /**\n * Closes the dialog.\n * @param e\n */\n close(e) {\n this.onClose(e);\n }\n\n /**\n * Draws the component after it has been drawn.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n */\n afterDraw(context, store, params) {\n if (params.trigger) {\n event.addListener(document, params.trigger, null, this.onOpen);\n }\n\n //this.dialog.addEventListener('close', this.onClose);\n }\n\n /**\n * Before the component is disconnected.\n */\n beforeDisconnect() {\n if (this.params?.trigger) {\n event.removeListener(document, this.params?.trigger, null, this.onOpen);\n }\n\n //this.dialog.removeEventListener('close', this.onClose);\n }\n\n /**\n * Before the dialog opens.\n */\n beforeOpen() {\n // Hook for extending behavior before the dialog opens\n }\n\n /**\n * After the dialog opens.\n */\n afterOpen() {\n // Hook for extending behavior after the dialog opens\n }\n\n /**\n * Before the dialog closes.\n */\n beforeClose() {\n // Hook for extending behavior before the dialog closes\n }\n\n /**\n * After the dialog closes.\n */\n afterClose() {\n // Hook for extending behavior after the dialog closes\n }\n\n /**\n * Opens the dialog.\n * @param e\n */\n onOpen = (e) => {\n if (this.dialog) {\n this.dialog.innerHTML = '';\n }\n\n Promise.resolve(this.beforeOpen(this, e)).then((res) => {\n this.htmlDialogBody(this.dialog);\n\n this.dialog.showModal(); // Now open the dialog\n\n if (this.dialog.open) {\n Promise.resolve(this.afterOpen(this, e));\n }\n });\n }\n\n /**\n * Closes the dialog.\n * @param {object} e\n */\n onClose = (e) => {\n Promise.resolve(this.beforeClose(this, e)).then((res) => {\n this.dialog.close(); // Now close the dialog\n\n if (!this.dialog.open) {\n Promise.resolve(this.afterClose(this, e));\n }\n });\n };\n\n /**\n * Registers an event listener on the provided button that triggers a blocking UI element\n * and executes a given promise when the button is clicked.\n * @param {HTMLElement} button The button element to attach the event listener to.\n * @param {Function} promise A function that returns a promise to be executed when the button is clicked.\n */\n registerBlockingEvent(button, promise) {\n button.addEventListener('wje-button:click', async (e) => {\n console.log('Button clicked');\n\n let blockingElement = document.createElement('div');\n blockingElement.classList.add('blocking-element');\n\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'loader-2');\n icon.setAttribute('size', '2x-large');\n\n blockingElement.appendChild(icon);\n\n let scrollOffset = this.dialog.scrollTop;\n blockingElement.style.top = `${scrollOffset}px`;\n blockingElement.style.bottom = `-${scrollOffset}px`;\n\n this.dialog.appendChild(blockingElement);\n\n await promise()\n .then((res) => {\n this.close();\n blockingElement.remove();\n })\n .catch((err) => {\n console.error(err);\n blockingElement.remove();\n });\n });\n }\n}\n","import Dialog from './dialog.element.js';\n\nexport default Dialog;\n\nDialog.define('wje-dialog', Dialog);\n"],"names":[],"mappings":";;;;;AA2Be,MAAM,eAAe,UAAU;AAAA;AAAA;AAAA;AAAA,EAI1C,cAAc;AACV,UAAO;AAuDX;AAAA;AAAA;AAAA;AAAA,qCAAY;AAwKZ;AAAA;AAAA;AAAA;AAAA,kCAAS,CAAC,MAAM;AACZ,UAAI,KAAK,QAAQ;AACb,aAAK,OAAO,YAAY;AAAA,MACpC;AAEQ,cAAQ,QAAQ,KAAK,WAAW,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ;AACpD,aAAK,eAAe,KAAK,MAAM;AAE/B,aAAK,OAAO;AAEZ,YAAI,KAAK,OAAO,MAAM;AAClB,kBAAQ,QAAQ,KAAK,UAAU,MAAM,CAAC,CAAC;AAAA,QACvD;AAAA,MACA,CAAS;AAAA,IACT;AAMI;AAAA;AAAA;AAAA;AAAA,mCAAU,CAAC,MAAM;AACb,cAAQ,QAAQ,KAAK,YAAY,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ;AACrD,aAAK,OAAO;AAEZ,YAAI,CAAC,KAAK,OAAO,MAAM;AACnB,kBAAQ,QAAQ,KAAK,WAAW,MAAM,CAAC,CAAC;AAAA,QACxD;AAAA,MACA,CAAS;AAAA,IACJ;AAAA,EA1PL;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,UAAU,OAAO;AACjB,SAAK,aAAa,aAAa,KAAK;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,YAAY;AACZ,WAAO,KAAK,aAAa,WAAW,KAAK;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI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|
178
|
+
/**
|
|
179
|
+
* Retrieves the value of the 'search-to-query-params' attribute from the current instance.
|
|
180
|
+
* @returns {string | null} The value of the 'search-to-query-params' attribute, or null if the attribute is not set.
|
|
181
|
+
*/
|
|
178
182
|
get searchToQueryParams() {
|
|
179
183
|
return this.getAttribute("search-to-query-params");
|
|
180
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Sets the value to define search-to-query params behavior.
|
|
187
|
+
* @param {string} value The value to be set for the search-to-query-params attribute.
|
|
188
|
+
*/
|
|
181
189
|
set searchToQueryParams(value) {
|
|
182
190
|
this.setAttribute("search-to-query-params", value);
|
|
183
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Determines whether the 'search-to-query-params' attribute is present on the element.
|
|
194
|
+
* @returns {boolean} True if the 'search-to-query-params' attribute exists, otherwise false.
|
|
195
|
+
*/
|
|
184
196
|
get hasSearchToQueryParams() {
|
|
185
197
|
return this.hasAttribute("search-to-query-params");
|
|
186
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Sets the value of the search parameter name attribute.
|
|
201
|
+
* @param {string} value The string value to set as the search parameter name.
|
|
202
|
+
*/
|
|
203
|
+
set searchParamName(value) {
|
|
204
|
+
this.setAttribute("search-param-name", value);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Gets the search parameter name used in queries.
|
|
208
|
+
* Retrieves the value of the 'search-param-name' attribute.
|
|
209
|
+
* If the attribute is not set, it defaults to 'search'.
|
|
210
|
+
* @returns {string} The search parameter name used for queries.
|
|
211
|
+
*/
|
|
212
|
+
get searchParamName() {
|
|
213
|
+
return this.getAttribute("search-param-name") || "search";
|
|
214
|
+
}
|
|
187
215
|
/**
|
|
188
216
|
* Checks if the lazy attribute is present.
|
|
189
217
|
* @returns {boolean} True if the lazy attribute is present, false otherwise.
|
|
@@ -254,7 +282,7 @@ class Options extends WJElement {
|
|
|
254
282
|
infiniteScroll.setCustomData = async (page, signal) => {
|
|
255
283
|
let processedUrl = `${this.url}${this.search ? `/${this.search}` : ""}?page=${page}&size=${this.lazyLoadSize}`;
|
|
256
284
|
if (this.hasSearchToQueryParams) {
|
|
257
|
-
processedUrl = `${this.url}?page=${page}&size=${this.lazyLoadSize}${this.search ?
|
|
285
|
+
processedUrl = `${this.url}?page=${page}&size=${this.lazyLoadSize}${this.search ? `&${this.searchParamName}=${this.search}` : ""}`;
|
|
258
286
|
}
|
|
259
287
|
let res = await this.service.get(processedUrl, null, false, signal);
|
|
260
288
|
const filteredOptions = this.filterOutDrawnOptions(res);
|
package/dist/wje-options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-options.js","sources":["../packages/wje-options/options.element.js","../packages/wje-options/options.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport InfiniteScroll from '../wje-infinite-scroll/infinite-scroll.element.js';\nimport List from '../wje-list/list.element.js';\nimport Option from '../wje-option/option.js';\n\n/**\n * `Options` is a custom web component that represents a set of options.\n * It extends from `WJElement`.\n * @summary This element represents a set of options.\n * @documentation https://elements.webjet.sk/components/options\n * @status stable\n * @augments {WJElement}\n * // @fires wje-options:load - Event fired when the options are loaded.\n * @tag wje-options\n */\nexport default class Options extends WJElement {\n /**\n * Creates an instance of Options.\n * @class\n */\n constructor() {\n super();\n\n this._loadedOptions = [];\n }\n\n dependencies = {\n 'wje-option': Option,\n 'wje-infinite-scroll': InfiniteScroll,\n 'wje-list': List,\n };\n\n className = 'Options';\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 ['search'];\n }\n\n /**\n * Sets the option array path attribute.\n * @param {string} value The value to set for the option array path.\n */\n set optionArrayPath(value) {\n this.setAttribute('option-array-path', value);\n }\n\n /**\n * Gets the option array path attribute.\n * @returns {string} The value of the option array path attribute or \"data\" if not set.\n */\n get optionArrayPath() {\n return this.getAttribute('option-array-path');\n }\n\n /**\n * Checks if the option array path attribute is present.\n * @returns {boolean} True if the option array path attribute is present, false otherwise.\n */\n get hasOptionArrayPath() {\n return this.hasAttribute('option-array-path');\n }\n\n /**\n * Gets the dropdown height attribute.\n * @returns {string} The value of the dropdown height attribute or \"100%\" if not set.\n */\n get dropdownHeight() {\n return this.getAttribute('dropdown-height') || '100%';\n }\n\n /**\n * Sets the dropdown height attribute.\n * @param {string} value The value to set for the dropdown height.\n */\n set dropdownHeight(value) {\n this.setAttribute('dropdown-height', value);\n }\n\n /**\n * Sets the item value attribute.\n * @param {string} value The value to set for the item value.\n */\n set itemValue(value) {\n this.setAttribute('item-value', value);\n }\n\n /**\n * Gets the item value attribute.\n * @returns {string} The value of the item value attribute or \"value\" if not set.\n */\n get itemValue() {\n return this.getAttribute('item-value') || 'value';\n }\n\n /**\n * Sets the item text attribute.\n * @param {string} value The value to set for the item text.\n */\n set itemText(value) {\n this.setAttribute('item-text', value);\n }\n\n /**\n * Gets the item text attribute.\n * @returns {string} The value of the item text attribute or \"text\" if not set.\n */\n get itemText() {\n return this.getAttribute('item-text') || 'text';\n }\n\n /**\n * Gets the lazy load size attribute.\n * @returns {number} The value of the lazy load size attribute or 10 if not set.\n */\n get lazyLoadSize() {\n return this.getAttribute('lazy-load-size') || 10;\n }\n\n /**\n * Sets the lazy load size attribute.\n * @param {number} value The value to set for the lazy load size.\n */\n set lazyLoadSize(value) {\n this.setAttribute('lazy-load-size', value);\n }\n\n /**\n * Sets the search attribute.\n * @param {string} value The value to set for the search.\n */\n set search(value) {\n this.setAttribute('search', value);\n }\n\n /**\n * Gets the search attribute.\n * @returns {string} The value of the search attribute.\n */\n get search() {\n return this.getAttribute('search');\n }\n\n /**\n * Checks if the search attribute is present.\n * @returns {boolean} True if the search attribute is present, false otherwise.\n */\n get hasSearch() {\n return this.hasAttribute('search');\n }\n\n get searchToQueryParams() {\n return this.getAttribute('search-to-query-params');\n }\n\n set searchToQueryParams(value) {\n this.setAttribute('search-to-query-params', value);\n }\n\n get hasSearchToQueryParams() {\n return this.hasAttribute('search-to-query-params');\n }\n\n /**\n * Checks if the lazy attribute is present.\n * @returns {boolean} True if the lazy attribute is present, false otherwise.\n */\n get lazy() {\n return this.hasAttribute('lazy');\n }\n\n /**\n * Sets the lazy attribute.\n * @param {boolean} value The value to set for the lazy attribute.\n */\n set lazy(value) {\n this.setAttribute('lazy', value);\n }\n\n /**\n * Gets the loaded options.\n * @returns {Array} The loaded options.\n */\n get options() {\n return this.loadedOptions?.flat();\n }\n\n get loadedOptions() {\n return this._loadedOptions;\n }\n\n set loadedOptions(loadedOptions) {\n this._loadedOptions = loadedOptions;\n }\n\n /**\n * Lifecycle method, called whenever an observed property changes.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (this.infiniteScroll && name === 'search' && oldValue !== newValue) {\n this.loadedOptions = [];\n this.infiniteScroll.placementObj.innerHTML = '';\n this.infiniteScroll.totalPages = 0;\n this.infiniteScroll.refresh();\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Prepares the component before drawing.\n * Fetches the pages and creates the options elements.\n */\n afterDraw() {\n event.dispatchCustomEvent(this, 'wje-options:load', {}); // nepomohlo to, v ff stale je scroll hore\n }\n\n /**\n * Draws the component.\n * @returns {DocumentFragment}\n */\n async draw() {\n let fragment = document.createDocumentFragment();\n\n const slot = document.createElement('slot');\n\n if (this.hasAttribute('lazy')) {\n const list = document.createElement('wje-list');\n\n const infiniteScroll = document.createElement('wje-infinite-scroll');\n infiniteScroll.setAttribute('placement', 'wje-list');\n infiniteScroll.setAttribute('height', this.dropdownHeight);\n infiniteScroll.setAttribute('object-name', this.optionArrayPath);\n infiniteScroll.append(list);\n\n infiniteScroll.dataToHtml = this.htmlItem;\n\n infiniteScroll.setCustomData = async (page, signal) => {\n let processedUrl = `${this.url}${this.search ? `/${this.search}` : ''}?page=${page}&size=${this.lazyLoadSize}`;\n\n if (this.hasSearchToQueryParams) {\n processedUrl = `${this.url}?page=${page}&size=${this.lazyLoadSize}${this.search ? `&search=${this.search}` : ''}`;\n }\n\n let res = await this.service.get(processedUrl, null, false, signal);\n const filteredOptions = this.filterOutDrawnOptions(res);\n this.loadedOptions.push(...this.processData(filteredOptions));\n\n return filteredOptions;\n };\n\n if (!this.contains(infiniteScroll)) {\n this.appendChild(infiniteScroll);\n }\n\n this.infiniteScroll = infiniteScroll;\n } else {\n this.response = await this.getPages();\n let optionsData = this.filterOutDrawnOptions(this.response);\n optionsData = this.processData(optionsData);\n\n this.loadedOptions.push(...optionsData);\n\n this.append(...optionsData.map(this.htmlItem));\n }\n\n fragment.appendChild(slot);\n\n return fragment;\n }\n\n /**\n * Processes the given data and returns the options based on the option array path.\n * @param {any} data The data to be processed.\n * @returns {any} - The options based on the option array path.\n */\n processData(data) {\n const splittedOptionArrayPath = this.optionArrayPath ? this.optionArrayPath?.split('.') : null;\n let options = data;\n\n splittedOptionArrayPath?.forEach((path) => {\n options = options[path];\n });\n\n return options ?? [];\n }\n\n /**\n * Filters out drawn options from the response.\n * @param {object | null} response The response to filter.\n * @returns {object} The filtered response.\n */\n filterOutDrawnOptions(response) {\n const splittedOptionArrayPath = this.optionArrayPath ? this.optionArrayPath?.split('.') : [];\n let filteredResponse = structuredClone(response);\n\n filteredResponse = this.recursiveUpdate(filteredResponse, splittedOptionArrayPath);\n return filteredResponse;\n }\n\n /**\n * Recursively updates the object based on the provided path to the property.\n * @param {object | Array | null} object\n * @param {Array<string> | null} pathToProperty\n * @returns {object | Array | null}\n */\n recursiveUpdate = (object, pathToProperty) => {\n if (pathToProperty.length === 0) {\n if (Array.isArray(object)) {\n return object.filter(\n (option) =>\n !this.loadedOptions.some(\n (loadedOption) => loadedOption[this.itemValue] === option[this.itemValue]\n )\n );\n } else {\n console.error('Expected an array but got:', object, pathToProperty);\n return [];\n }\n }\n\n const [currentPath, ...remainingPath] = pathToProperty;\n if (remainingPath.length > 0) {\n object[currentPath] = this.recursiveUpdate(object[currentPath], remainingPath);\n } else {\n object[currentPath] =\n object[currentPath]?.filter(\n (option) =>\n !this.loadedOptions.some(\n (loadedOption) => loadedOption[this.itemValue] === option[this.itemValue]\n )\n ) ?? [];\n }\n return object;\n };\n\n /**\n * Generates an HTML option element based on the provided item.\n * @param {object} item The item to generate the option element for.\n * @returns {HTMLElement} The generated option element.\n */\n htmlItem = (item) => {\n let option = document.createElement('wje-option');\n\n if (item[this.itemValue] === null || item[this.itemValue] === undefined) {\n console.warn(`The item ${JSON.stringify(item)} does not have the property ${this.itemValue}`);\n }\n\n if (item[this.itemText] === null || item[this.itemText] === undefined) {\n console.warn(`The item ${JSON.stringify(item)} does not have the property ${this.itemText}`);\n }\n\n option.setAttribute('value', item[this.itemValue] ?? '');\n option.innerText = item[this.itemText] ?? '';\n\n return option;\n };\n\n /**\n * Fetches the pages from the provided URL.\n * @param {number} page The page number to fetch.\n * @returns {Promise<object>} The fetched data.\n * @throws Will throw an error if the response is not ok.\n */\n async getPages(page) {\n const response = await fetch(this.url);\n if (!response.ok) {\n throw new Error(`An error occurred: ${response.status}`);\n }\n return await response.json();\n }\n\n /**\n * Finds the selected option data based on the given selected option values.\n * @param {Array} selectedOptionValues The array of selected option values.\n * @returns {Array} - The array of option data that matches the selected option values.\n */\n findSelectedOptionData(selectedOptionValues = []) {\n return this.options.filter((option) => selectedOptionValues.includes(option[this.itemValue]));\n }\n\n /**\n * Adds an option to the element.\n * @param {object} optionData The data of the option to be added.\n */\n addOption(optionData) {\n if (this.loadedOptions.some((option) => option[this.itemValue] === optionData[this.itemValue])) {\n return;\n }\n\n this.prepend(this.htmlItem(optionData));\n this.loadedOptions.push(optionData);\n }\n\n /**\n * Adds options to the element.\n * @param {Array} optionsData The array of option data to be added.\n * @param {boolean} [silent] Whether to suppress events triggered by adding options.\n */\n addOptions(optionsData = [], silent = false) {\n if (Array.isArray(optionsData)) optionsData?.forEach((od) => this.addOption(od, silent));\n else this.addOption(optionsData, silent);\n }\n}\n","import Options from './options.element.js';\n\nexport default Options;\n\nOptions.define('wje-options', Options);\n"],"names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,KAAK,SAAS,CAAC,CAAC;AAAA,EACpG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,UAAU,YAAY;AAClB,QAAI,KAAK,cAAc,KAAK,CAAC,WAAW,OAAO,KAAK,SAAS,MAAM,WAAW,KAAK,SAAS,CAAC,GAAG;AAC5F;AAAA,IACZ;AAEQ,SAAK,QAAQ,KAAK,SAAS,UAAU,CAAC;AACtC,SAAK,cAAc,KAAK,UAAU;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,WAAW,cAAc,IAAI,SAAS,OAAO;AACzC,QAAI,MAAM,QAAQ,WAAW,EAAG,4CAAa,QAAQ,CAAC,OAAO,KAAK,UAAU,IAAI,MAAM;AAAA,QACjF,MAAK,UAAU,aAAa,MAAM;AAAA,EAC/C;AACA;ACxZA,QAAQ,OAAO,eAAe,OAAO;"}
|
|
1
|
+
{"version":3,"file":"wje-options.js","sources":["../packages/wje-options/options.element.js","../packages/wje-options/options.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport InfiniteScroll from '../wje-infinite-scroll/infinite-scroll.element.js';\nimport List from '../wje-list/list.element.js';\nimport Option from '../wje-option/option.js';\n\n/**\n * `Options` is a custom web component that represents a set of options.\n * It extends from `WJElement`.\n * @summary This element represents a set of options.\n * @documentation https://elements.webjet.sk/components/options\n * @status stable\n * @augments {WJElement}\n * // @fires wje-options:load - Event fired when the options are loaded.\n * @tag wje-options\n */\nexport default class Options extends WJElement {\n /**\n * Creates an instance of Options.\n * @class\n */\n constructor() {\n super();\n\n this._loadedOptions = [];\n }\n\n dependencies = {\n 'wje-option': Option,\n 'wje-infinite-scroll': InfiniteScroll,\n 'wje-list': List,\n };\n\n className = 'Options';\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 ['search'];\n }\n\n /**\n * Sets the option array path attribute.\n * @param {string} value The value to set for the option array path.\n */\n set optionArrayPath(value) {\n this.setAttribute('option-array-path', value);\n }\n\n /**\n * Gets the option array path attribute.\n * @returns {string} The value of the option array path attribute or \"data\" if not set.\n */\n get optionArrayPath() {\n return this.getAttribute('option-array-path');\n }\n\n /**\n * Checks if the option array path attribute is present.\n * @returns {boolean} True if the option array path attribute is present, false otherwise.\n */\n get hasOptionArrayPath() {\n return this.hasAttribute('option-array-path');\n }\n\n /**\n * Gets the dropdown height attribute.\n * @returns {string} The value of the dropdown height attribute or \"100%\" if not set.\n */\n get dropdownHeight() {\n return this.getAttribute('dropdown-height') || '100%';\n }\n\n /**\n * Sets the dropdown height attribute.\n * @param {string} value The value to set for the dropdown height.\n */\n set dropdownHeight(value) {\n this.setAttribute('dropdown-height', value);\n }\n\n /**\n * Sets the item value attribute.\n * @param {string} value The value to set for the item value.\n */\n set itemValue(value) {\n this.setAttribute('item-value', value);\n }\n\n /**\n * Gets the item value attribute.\n * @returns {string} The value of the item value attribute or \"value\" if not set.\n */\n get itemValue() {\n return this.getAttribute('item-value') || 'value';\n }\n\n /**\n * Sets the item text attribute.\n * @param {string} value The value to set for the item text.\n */\n set itemText(value) {\n this.setAttribute('item-text', value);\n }\n\n /**\n * Gets the item text attribute.\n * @returns {string} The value of the item text attribute or \"text\" if not set.\n */\n get itemText() {\n return this.getAttribute('item-text') || 'text';\n }\n\n /**\n * Gets the lazy load size attribute.\n * @returns {number} The value of the lazy load size attribute or 10 if not set.\n */\n get lazyLoadSize() {\n return this.getAttribute('lazy-load-size') || 10;\n }\n\n /**\n * Sets the lazy load size attribute.\n * @param {number} value The value to set for the lazy load size.\n */\n set lazyLoadSize(value) {\n this.setAttribute('lazy-load-size', value);\n }\n\n /**\n * Sets the search attribute.\n * @param {string} value The value to set for the search.\n */\n set search(value) {\n this.setAttribute('search', value);\n }\n\n /**\n * Gets the search attribute.\n * @returns {string} The value of the search attribute.\n */\n get search() {\n return this.getAttribute('search');\n }\n\n /**\n * Checks if the search attribute is present.\n * @returns {boolean} True if the search attribute is present, false otherwise.\n */\n get hasSearch() {\n return this.hasAttribute('search');\n }\n\n /**\n * Retrieves the value of the 'search-to-query-params' attribute from the current instance.\n * @returns {string | null} The value of the 'search-to-query-params' attribute, or null if the attribute is not set.\n */\n get searchToQueryParams() {\n return this.getAttribute('search-to-query-params');\n }\n\n /**\n * Sets the value to define search-to-query params behavior.\n * @param {string} value The value to be set for the search-to-query-params attribute.\n */\n set searchToQueryParams(value) {\n this.setAttribute('search-to-query-params', value);\n }\n\n /**\n * Determines whether the 'search-to-query-params' attribute is present on the element.\n * @returns {boolean} True if the 'search-to-query-params' attribute exists, otherwise false.\n */\n get hasSearchToQueryParams() {\n return this.hasAttribute('search-to-query-params');\n }\n\n /**\n * Sets the value of the search parameter name attribute.\n * @param {string} value The string value to set as the search parameter name.\n */\n set searchParamName(value) {\n this.setAttribute('search-param-name', value);\n }\n\n /**\n * Gets the search parameter name used in queries.\n * Retrieves the value of the 'search-param-name' attribute.\n * If the attribute is not set, it defaults to 'search'.\n * @returns {string} The search parameter name used for queries.\n */\n get searchParamName() {\n return this.getAttribute('search-param-name') || 'search';\n }\n /**\n * Checks if the lazy attribute is present.\n * @returns {boolean} True if the lazy attribute is present, false otherwise.\n */\n get lazy() {\n return this.hasAttribute('lazy');\n }\n\n /**\n * Sets the lazy attribute.\n * @param {boolean} value The value to set for the lazy attribute.\n */\n set lazy(value) {\n this.setAttribute('lazy', value);\n }\n\n /**\n * Gets the loaded options.\n * @returns {Array} The loaded options.\n */\n get options() {\n return this.loadedOptions?.flat();\n }\n\n get loadedOptions() {\n return this._loadedOptions;\n }\n\n set loadedOptions(loadedOptions) {\n this._loadedOptions = loadedOptions;\n }\n\n /**\n * Lifecycle method, called whenever an observed property changes.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (this.infiniteScroll && name === 'search' && oldValue !== newValue) {\n this.loadedOptions = [];\n this.infiniteScroll.placementObj.innerHTML = '';\n this.infiniteScroll.totalPages = 0;\n this.infiniteScroll.refresh();\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Prepares the component before drawing.\n * Fetches the pages and creates the options elements.\n */\n afterDraw() {\n event.dispatchCustomEvent(this, 'wje-options:load', {}); // nepomohlo to, v ff stale je scroll hore\n }\n\n /**\n * Draws the component.\n * @returns {DocumentFragment}\n */\n async draw() {\n let fragment = document.createDocumentFragment();\n\n const slot = document.createElement('slot');\n\n if (this.hasAttribute('lazy')) {\n const list = document.createElement('wje-list');\n\n const infiniteScroll = document.createElement('wje-infinite-scroll');\n infiniteScroll.setAttribute('placement', 'wje-list');\n infiniteScroll.setAttribute('height', this.dropdownHeight);\n infiniteScroll.setAttribute('object-name', this.optionArrayPath);\n infiniteScroll.append(list);\n\n infiniteScroll.dataToHtml = this.htmlItem;\n\n infiniteScroll.setCustomData = async (page, signal) => {\n let processedUrl = `${this.url}${this.search ? `/${this.search}` : ''}?page=${page}&size=${this.lazyLoadSize}`;\n\n if (this.hasSearchToQueryParams) {\n processedUrl = `${this.url}?page=${page}&size=${this.lazyLoadSize}${this.search ? `&${this.searchParamName}=${this.search}` : ''}`;\n }\n\n let res = await this.service.get(processedUrl, null, false, signal);\n const filteredOptions = this.filterOutDrawnOptions(res);\n this.loadedOptions.push(...this.processData(filteredOptions));\n\n return filteredOptions;\n };\n\n if (!this.contains(infiniteScroll)) {\n this.appendChild(infiniteScroll);\n }\n\n this.infiniteScroll = infiniteScroll;\n } else {\n this.response = await this.getPages();\n let optionsData = this.filterOutDrawnOptions(this.response);\n optionsData = this.processData(optionsData);\n\n this.loadedOptions.push(...optionsData);\n\n this.append(...optionsData.map(this.htmlItem));\n }\n\n fragment.appendChild(slot);\n\n return fragment;\n }\n\n /**\n * Processes the given data and returns the options based on the option array path.\n * @param {any} data The data to be processed.\n * @returns {any} - The options based on the option array path.\n */\n processData(data) {\n const splittedOptionArrayPath = this.optionArrayPath ? this.optionArrayPath?.split('.') : null;\n let options = data;\n\n splittedOptionArrayPath?.forEach((path) => {\n options = options[path];\n });\n\n return options ?? [];\n }\n\n /**\n * Filters out drawn options from the response.\n * @param {object | null} response The response to filter.\n * @returns {object} The filtered response.\n */\n filterOutDrawnOptions(response) {\n const splittedOptionArrayPath = this.optionArrayPath ? this.optionArrayPath?.split('.') : [];\n let filteredResponse = structuredClone(response);\n\n filteredResponse = this.recursiveUpdate(filteredResponse, splittedOptionArrayPath);\n return filteredResponse;\n }\n\n /**\n * Recursively updates the object based on the provided path to the property.\n * @param {object | Array | null} object\n * @param {Array<string> | null} pathToProperty\n * @returns {object | Array | null}\n */\n recursiveUpdate = (object, pathToProperty) => {\n if (pathToProperty.length === 0) {\n if (Array.isArray(object)) {\n return object.filter(\n (option) =>\n !this.loadedOptions.some(\n (loadedOption) => loadedOption[this.itemValue] === option[this.itemValue]\n )\n );\n } else {\n console.error('Expected an array but got:', object, pathToProperty);\n return [];\n }\n }\n\n const [currentPath, ...remainingPath] = pathToProperty;\n if (remainingPath.length > 0) {\n object[currentPath] = this.recursiveUpdate(object[currentPath], remainingPath);\n } else {\n object[currentPath] =\n object[currentPath]?.filter(\n (option) =>\n !this.loadedOptions.some(\n (loadedOption) => loadedOption[this.itemValue] === option[this.itemValue]\n )\n ) ?? [];\n }\n return object;\n };\n\n /**\n * Generates an HTML option element based on the provided item.\n * @param {object} item The item to generate the option element for.\n * @returns {HTMLElement} The generated option element.\n */\n htmlItem = (item) => {\n let option = document.createElement('wje-option');\n\n if (item[this.itemValue] === null || item[this.itemValue] === undefined) {\n console.warn(`The item ${JSON.stringify(item)} does not have the property ${this.itemValue}`);\n }\n\n if (item[this.itemText] === null || item[this.itemText] === undefined) {\n console.warn(`The item ${JSON.stringify(item)} does not have the property ${this.itemText}`);\n }\n\n option.setAttribute('value', item[this.itemValue] ?? '');\n option.innerText = item[this.itemText] ?? '';\n\n return option;\n };\n\n /**\n * Fetches the pages from the provided URL.\n * @param {number} page The page number to fetch.\n * @returns {Promise<object>} The fetched data.\n * @throws Will throw an error if the response is not ok.\n */\n async getPages(page) {\n const response = await fetch(this.url);\n if (!response.ok) {\n throw new Error(`An error occurred: ${response.status}`);\n }\n return await response.json();\n }\n\n /**\n * Finds the selected option data based on the given selected option values.\n * @param {Array} selectedOptionValues The array of selected option values.\n * @returns {Array} - The array of option data that matches the selected option values.\n */\n findSelectedOptionData(selectedOptionValues = []) {\n return this.options.filter((option) => selectedOptionValues.includes(option[this.itemValue]));\n }\n\n /**\n * Adds an option to the element.\n * @param {object} optionData The data of the option to be added.\n */\n addOption(optionData) {\n if (this.loadedOptions.some((option) => option[this.itemValue] === optionData[this.itemValue])) {\n return;\n }\n\n this.prepend(this.htmlItem(optionData));\n this.loadedOptions.push(optionData);\n }\n\n /**\n * Adds options to the element.\n * @param {Array} optionsData The array of option data to be added.\n * @param {boolean} [silent] Whether to suppress events triggered by adding options.\n */\n addOptions(optionsData = [], silent = false) {\n if (Array.isArray(optionsData)) optionsData?.forEach((od) => this.addOption(od, silent));\n else this.addOption(optionsData, silent);\n }\n}\n","import Options from './options.element.js';\n\nexport default Options;\n\nOptions.define('wje-options', Options);\n"],"names":[],"mappings":";;;;;;;AAee,MAAM,gBAAgB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3C,cAAc;AACV,UAAO;AAKX,wCAAe;AAAA,MACX,cAAc;AAAA,MACd,uBAAuB;AAAA,MACvB,YAAY;AAAA,IACf;AAED,qCAAY;AAwTZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2CAAkB,CAAC,QAAQ,mBAAmB;;AAC1C,UAAI,eAAe,WAAW,GAAG;AAC7B,YAAI,MAAM,QAAQ,MAAM,GAAG;AACvB,iBAAO,OAAO;AAAA,YACV,CAAC,WACG,CAAC,KAAK,cAAc;AAAA,cAChB,CAAC,iBAAiB,aAAa,KAAK,SAAS,MAAM,OAAO,KAAK,SAAS;AAAA,YACpG;AAAA,UACiB;AAAA,QACjB,OAAmB;AACH,kBAAQ,MAAM,8BAA8B,QAAQ,cAAc;AAClE,iBAAO,CAAE;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AAc,KAAK,UAAU;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,WAAW,cAAc,IAAI,SAAS,OAAO;AACzC,QAAI,MAAM,QAAQ,WAAW,EAAG,4CAAa,QAAQ,CAAC,OAAO,KAAK,UAAU,IAAI,MAAM;AAAA,QACjF,MAAK,UAAU,aAAa,MAAM;AAAA,EAC/C;AACA;ACrbA,QAAQ,OAAO,eAAe,OAAO;"}
|
package/dist/wje-stepper.js
CHANGED
|
@@ -42,40 +42,9 @@ class Stepper extends WJElement {
|
|
|
42
42
|
content.setAttribute("part", "content");
|
|
43
43
|
content.className = "content";
|
|
44
44
|
const steps = Array.from(this.children);
|
|
45
|
-
steps.forEach((step, index) => {
|
|
45
|
+
steps == null ? void 0 : steps.forEach((step, index) => {
|
|
46
46
|
if (step.nodeName === "WJE-STEP") {
|
|
47
|
-
|
|
48
|
-
nav.className = "step-header";
|
|
49
|
-
nav.addEventListener("click", () => this.goToStep(index));
|
|
50
|
-
const badge = document.createElement("wje-badge");
|
|
51
|
-
badge.setAttribute("label", (index + 1).toString());
|
|
52
|
-
badge.className = "step-badge";
|
|
53
|
-
badge.innerHTML = index + 1;
|
|
54
|
-
const label = document.createElement("span");
|
|
55
|
-
label.innerText = step.getAttribute("label") || `${this.localizer.translate("wj.stepper.step")} ${index + 1}`;
|
|
56
|
-
if (index === this.currentStep || step.hasAttribute("active")) {
|
|
57
|
-
this.setStepActive(nav, badge);
|
|
58
|
-
}
|
|
59
|
-
if (step.hasAttribute("disabled")) {
|
|
60
|
-
nav.setAttribute("disabled", "");
|
|
61
|
-
} else {
|
|
62
|
-
nav.classList.add("pointer");
|
|
63
|
-
}
|
|
64
|
-
nav.appendChild(badge);
|
|
65
|
-
nav.appendChild(label);
|
|
66
|
-
header.appendChild(nav);
|
|
67
|
-
if (index < steps.length - 1) {
|
|
68
|
-
const arrowIcon = document.createElement("wje-icon");
|
|
69
|
-
arrowIcon.setAttribute("name", "chevron-right");
|
|
70
|
-
arrowIcon.classList.add("arrow-icon");
|
|
71
|
-
arrowIcon.setAttribute("size", "small");
|
|
72
|
-
header.appendChild(arrowIcon);
|
|
73
|
-
}
|
|
74
|
-
step.classList.add("step");
|
|
75
|
-
if (index !== this.currentStep) {
|
|
76
|
-
step.style.display = "none";
|
|
77
|
-
}
|
|
78
|
-
this.steps.push(step);
|
|
47
|
+
this.processStep(index, step, header, steps);
|
|
79
48
|
}
|
|
80
49
|
});
|
|
81
50
|
let slot = document.createElement("slot");
|
|
@@ -85,12 +54,22 @@ class Stepper extends WJElement {
|
|
|
85
54
|
prevButton.setAttribute("label", this.localizer.translate("wj.stepper.button.previous"));
|
|
86
55
|
prevButton.disabled = this.currentStep === 0;
|
|
87
56
|
prevButton.innerHTML = "Prev";
|
|
88
|
-
|
|
57
|
+
let nextButton = document.createElement("wje-button");
|
|
89
58
|
nextButton.setAttribute("label", this.localizer.translate("wj.stepper.button.next"));
|
|
90
59
|
nextButton.disabled = this.currentStep === this.steps.length - 1;
|
|
91
60
|
nextButton.innerHTML = "Next";
|
|
92
|
-
|
|
93
|
-
|
|
61
|
+
if (steps.length > 1) {
|
|
62
|
+
navButtons.appendChild(prevButton);
|
|
63
|
+
navButtons.appendChild(nextButton);
|
|
64
|
+
} else {
|
|
65
|
+
nextButton = document.createElement("wje-button");
|
|
66
|
+
nextButton.setAttribute("label", this.localizer.translate("wj.stepper.button.finish"));
|
|
67
|
+
nextButton.innerHTML = this.localizer.translate("wj.stepper.button.finish");
|
|
68
|
+
nextButton.setAttribute("color", "primary");
|
|
69
|
+
prevButton.hidden = true;
|
|
70
|
+
navButtons.appendChild(prevButton);
|
|
71
|
+
navButtons.appendChild(nextButton);
|
|
72
|
+
}
|
|
94
73
|
content.appendChild(slot);
|
|
95
74
|
native.appendChild(header);
|
|
96
75
|
native.appendChild(content);
|
|
@@ -102,10 +81,47 @@ class Stepper extends WJElement {
|
|
|
102
81
|
this.next = nextButton;
|
|
103
82
|
return fragment;
|
|
104
83
|
}
|
|
84
|
+
processStep(index, step, header, steps) {
|
|
85
|
+
const nav = document.createElement("div");
|
|
86
|
+
nav.className = "step-header";
|
|
87
|
+
nav.addEventListener("click", () => this.goToStep(index));
|
|
88
|
+
const badge = document.createElement("wje-badge");
|
|
89
|
+
badge.setAttribute("label", (index + 1).toString());
|
|
90
|
+
badge.className = "step-badge";
|
|
91
|
+
badge.innerHTML = index + 1;
|
|
92
|
+
const label = document.createElement("span");
|
|
93
|
+
label.innerText = step.getAttribute("label") || `${this.localizer.translate("wj.stepper.step")} ${index + 1}`;
|
|
94
|
+
if (index === this.currentStep || step.hasAttribute("active")) {
|
|
95
|
+
this.setStepActive(nav, badge);
|
|
96
|
+
}
|
|
97
|
+
if (step.hasAttribute("disabled")) {
|
|
98
|
+
nav.setAttribute("disabled", "");
|
|
99
|
+
} else {
|
|
100
|
+
nav.classList.add("pointer");
|
|
101
|
+
}
|
|
102
|
+
nav.appendChild(badge);
|
|
103
|
+
nav.appendChild(label);
|
|
104
|
+
header.appendChild(nav);
|
|
105
|
+
if (index < steps.length - 1) {
|
|
106
|
+
const arrowIcon = document.createElement("wje-icon");
|
|
107
|
+
arrowIcon.setAttribute("name", "chevron-right");
|
|
108
|
+
arrowIcon.classList.add("arrow-icon");
|
|
109
|
+
arrowIcon.setAttribute("size", "small");
|
|
110
|
+
header.appendChild(arrowIcon);
|
|
111
|
+
}
|
|
112
|
+
step.classList.add("step");
|
|
113
|
+
if (index !== this.currentStep) {
|
|
114
|
+
step.style.display = "none";
|
|
115
|
+
}
|
|
116
|
+
this.steps.push(step);
|
|
117
|
+
}
|
|
105
118
|
/**
|
|
106
119
|
* Sets up the attributes for the component.
|
|
107
120
|
*/
|
|
108
121
|
afterDraw() {
|
|
122
|
+
if (this.steps.length <= 1) {
|
|
123
|
+
this.prev.hidden = true;
|
|
124
|
+
}
|
|
109
125
|
event.addListener(this.prev, "click", "", () => this.navigate(-1));
|
|
110
126
|
event.addListener(this.next, "click", "", () => this.navigate(1));
|
|
111
127
|
}
|
package/dist/wje-stepper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-stepper.js","sources":["../packages/wje-stepper/stepper.element.js","../packages/wje-stepper/stepper.js"],"sourcesContent":["import { Localizer } from '../utils/localize.js';\nimport { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Stepper` is a custom web component that represents a stepper.\n * @summary This element represents a stepper.\n * @documentation https://elements.webjet.sk/components/stepper\n * @status stable\n * @augments WJElement\n * @attribute {string} active - The active color for the stepper.\n * @attribute {string} done - The done color for the stepper.\n * @slot - The default slot for the stepper.\n * @csspart native - The native part of the stepper.\n * @csspart header - The header part of the stepper.\n * @csspart content - The content part of the stepper.\n * @tag wje-stepper\n */\nexport default class Stepper extends WJElement {\n constructor() {\n super();\n this.currentStep = 0;\n\n this.localizer = new Localizer(this);\n this.steps = [];\n }\n\n get active() {\n if (this.hasAttribute('active')) return this.getAttribute('active');\n\n return 'primary';\n }\n\n get done() {\n if (this.hasAttribute('done')) return this.getAttribute('done');\n\n return 'success';\n }\n\n className = 'Stepper';\n\n static get cssStyleSheet() {\n return styles;\n }\n\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component for the stepper.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n const native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.className = 'native-stepper';\n\n const header = document.createElement('div');\n header.setAttribute('part', 'header');\n header.className = 'header';\n\n const content = document.createElement('div');\n content.setAttribute('part', 'content');\n content.className = 'content';\n\n const steps = Array.from(this.children);\n\n steps.forEach((step, index) => {\n if (step.nodeName === 'WJE-STEP') {\n const nav = document.createElement('div');\n nav.className = 'step-header';\n nav.addEventListener('click', () => this.goToStep(index));\n\n const badge = document.createElement('wje-badge');\n badge.setAttribute('label', (index + 1).toString());\n badge.className = 'step-badge';\n badge.innerHTML = index + 1;\n\n const label = document.createElement('span');\n label.innerText =\n step.getAttribute('label') || `${this.localizer.translate('wj.stepper.step')} ${index + 1}`; // default label\n\n // set active step\n if (index === this.currentStep || step.hasAttribute('active')) {\n this.setStepActive(nav, badge);\n }\n\n if (step.hasAttribute('disabled')) {\n nav.setAttribute('disabled', '');\n } else {\n nav.classList.add('pointer');\n }\n\n nav.appendChild(badge);\n nav.appendChild(label);\n\n header.appendChild(nav);\n\n if (index < steps.length - 1) {\n const arrowIcon = document.createElement('wje-icon');\n arrowIcon.setAttribute('name', 'chevron-right');\n arrowIcon.classList.add('arrow-icon');\n arrowIcon.setAttribute('size', 'small');\n\n header.appendChild(arrowIcon);\n }\n\n step.classList.add('step');\n if (index !== this.currentStep) {\n step.style.display = 'none';\n }\n\n this.steps.push(step);\n }\n });\n\n let slot = document.createElement('slot');\n\n const navButtons = document.createElement('div');\n navButtons.className = 'nav-buttons';\n\n const prevButton = document.createElement('wje-button');\n prevButton.setAttribute('label', this.localizer.translate('wj.stepper.button.previous'));\n prevButton.disabled = this.currentStep === 0;\n prevButton.innerHTML = 'Prev';\n\n const nextButton = document.createElement('wje-button');\n nextButton.setAttribute('label', this.localizer.translate('wj.stepper.button.next'));\n nextButton.disabled = this.currentStep === this.steps.length - 1;\n nextButton.innerHTML = 'Next';\n\n navButtons.appendChild(prevButton);\n navButtons.appendChild(nextButton);\n\n content.appendChild(slot);\n\n native.appendChild(header);\n native.appendChild(content);\n native.appendChild(navButtons);\n\n fragment.appendChild(native);\n\n this.header = header;\n this.headerSteps = header.querySelectorAll('.step-header');\n this.prev = prevButton;\n this.next = nextButton;\n\n return fragment;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n afterDraw() {\n event.addListener(this.prev, 'click', '', () => this.navigate(-1));\n event.addListener(this.next, 'click', '', () => this.navigate(1));\n }\n\n /**\n * Navigates to a different step in a multi-step process based on the provided direction.\n * @param {number} direction The navigation direction.\n * Use a positive value to move forward or a negative value to move backward.\n */\n navigate(direction) {\n this.goToStep(this.currentStep + direction, direction);\n }\n\n /**\n * Navigates to a specific step in a multi-step process and updates the stepper UI accordingly.\n * @param {number} stepIndex The index of the step to navigate to.\n * @param {number} direction The navigation direction. A positive value indicates forward navigation, and a negative value indicates backward navigation.\n * //@fires stepper:next Dispatched when navigating to the next step.\n * //@fires stepper:prev Dispatched when navigating to the previous step.\n * //@fires stepper:finish Dispatched when the final step is completed.\n */\n goToStep(stepIndex, direction) {\n if (stepIndex >= 0 && stepIndex < this.steps.length) {\n if (direction > 0) {\n this.dispatchEvent(\n new CustomEvent('stepper:next', { detail: { stepIndex }, bubbles: true, composed: true })\n );\n } else {\n this.dispatchEvent(\n new CustomEvent('stepper:prev', { detail: { stepIndex }, bubbles: true, composed: true })\n );\n }\n\n if (this.headerSteps[stepIndex].hasAttribute('disabled')) stepIndex += direction;\n\n this.headerSteps.forEach((step, index) => {\n let badge = step.querySelector('wje-badge');\n\n this.setStepDefault(step, badge, index);\n if (index < stepIndex) this.setStepDone(step, badge);\n });\n\n this.setStepActive(this.headerSteps[stepIndex], null, stepIndex);\n this.setContentActive(stepIndex);\n\n this.currentStep = stepIndex;\n\n this.prev.disabled = this.currentStep === 0;\n if (this.currentStep === this.steps.length - 1) {\n this.next.innerHTML = this.localizer.translate('wj.stepper.button.finish');\n this.next.setAttribute('color', 'primary');\n this.next.refresh();\n } else {\n this.next.innerHTML = this.localizer.translate('wj.stepper.button.next');\n this.next.removeAttribute('color');\n this.next.refresh();\n }\n } else if (stepIndex === this.steps.length) {\n this.dispatchEvent(\n new CustomEvent('stepper:finish', { detail: { stepIndex }, bubbles: true, composed: true })\n );\n }\n }\n\n /**\n * Resets a step to its default state by clearing its active and done attributes.\n * Updates the step's badge to show its index and removes any color styling.\n * @param {HTMLElement} nav The navigation element representing the step.\n * @param {HTMLElement|null} [badge] The badge element within the step. If not provided, it will be selected from the `nav` element.\n * @param {number} [stepIndex] The index of the step, used to set the badge content.\n */\n setStepDefault(nav, badge = null, stepIndex = 0) {\n nav.removeAttribute('active');\n nav.removeAttribute('done');\n\n if (!badge) {\n badge = nav.querySelector('wje-badge');\n }\n badge.innerHTML = stepIndex + 1;\n badge.removeAttribute('color');\n }\n\n /**\n * Sets a step as active by adding the `active` attribute and updating the step's badge.\n * @param {HTMLElement} nav The navigation element representing the step to activate.\n * @param {HTMLElement|null} [badge] The badge element within the step. If not provided, it will be selected from the `nav` element.\n * @param {number|null} [stepIndex] The index of the step, used to set the badge content. Defaults to `null` if not provided.\n */\n setStepActive(nav, badge = null, stepIndex = null) {\n nav.setAttribute('active', '');\n\n if (!badge) {\n badge = nav.querySelector('wje-badge');\n }\n badge.innerHTML = stepIndex + 1;\n badge.setAttribute('color', this.active);\n }\n\n /**\n * Activates the content of a specific step by displaying it and hiding all others.\n * @param {number} stepIndex The index of the step whose content should be displayed.\n */\n setContentActive(stepIndex) {\n this.steps?.forEach((step, index) => {\n if (index === stepIndex) {\n step.style.display = 'block';\n } else {\n step.style.display = 'none';\n }\n });\n }\n\n /**\n * Marks a step as completed by setting the `done` attribute and updating its badge with a check icon.\n * @param {HTMLElement} nav The navigation element representing the completed step.\n * @param {HTMLElement|null} [badge] The badge element within the step. If not provided, it will be selected from the `nav` element.\n */\n setStepDone(nav, badge = null) {\n nav.setAttribute('done', '');\n\n const checkIcon = document.createElement('wje-icon');\n checkIcon.setAttribute('name', 'check');\n checkIcon.setAttribute('color', this.done);\n checkIcon.setAttribute('size', 'medium');\n\n if (!badge) {\n badge = nav.querySelector('wje-badge');\n }\n\n badge.setAttribute('color', this.done);\n badge.innerHTML = '';\n badge.appendChild(checkIcon);\n }\n}\n","import Stepper from './stepper.element.js';\n\nexport default Stepper;\n\nStepper.define('wje-stepper', Stepper);\n"],"names":[],"mappings":";;;;;;AAkBe,MAAM,gBAAgB,UAAU;AAAA,EAC3C,cAAc;AACV,UAAO;AAmBX,qCAAY;AAlBR,SAAK,cAAc;AAEnB,SAAK,YAAY,IAAI,UAAU,IAAI;AACnC,SAAK,QAAQ,CAAE;AAAA,EACvB;AAAA,EAEI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I,aAAa,QAAQ,EAAE;AAE3B,UAAM,YAAY,SAAS,cAAc,UAAU;AACnD,cAAU,aAAa,QAAQ,OAAO;AACtC,cAAU,aAAa,SAAS,KAAK,IAAI;AACzC,cAAU,aAAa,QAAQ,QAAQ;AAEvC,QAAI,CAAC,OAAO;AACR,cAAQ,IAAI,cAAc,WAAW;AAAA,IACjD;AAEQ,UAAM,aAAa,SAAS,KAAK,IAAI;AACrC,UAAM,YAAY;AAClB,UAAM,YAAY,SAAS;AAAA,EACnC;AACA;AC9RA,QAAQ,OAAO,eAAe,OAAO;"}
|
|
1
|
+
{"version":3,"file":"wje-stepper.js","sources":["../packages/wje-stepper/stepper.element.js","../packages/wje-stepper/stepper.js"],"sourcesContent":["import { Localizer } from '../utils/localize.js';\nimport { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Stepper` is a custom web component that represents a stepper.\n * @summary This element represents a stepper.\n * @documentation https://elements.webjet.sk/components/stepper\n * @status stable\n * @augments WJElement\n * @attribute {string} active - The active color for the stepper.\n * @attribute {string} done - The done color for the stepper.\n * @slot - The default slot for the stepper.\n * @csspart native - The native part of the stepper.\n * @csspart header - The header part of the stepper.\n * @csspart content - The content part of the stepper.\n * @tag wje-stepper\n */\nexport default class Stepper extends WJElement {\n constructor() {\n super();\n this.currentStep = 0;\n\n this.localizer = new Localizer(this);\n this.steps = [];\n }\n\n get active() {\n if (this.hasAttribute('active')) return this.getAttribute('active');\n\n return 'primary';\n }\n\n get done() {\n if (this.hasAttribute('done')) return this.getAttribute('done');\n\n return 'success';\n }\n\n className = 'Stepper';\n\n static get cssStyleSheet() {\n return styles;\n }\n\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component for the stepper.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n const native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.className = 'native-stepper';\n\n const header = document.createElement('div');\n header.setAttribute('part', 'header');\n header.className = 'header';\n\n const content = document.createElement('div');\n content.setAttribute('part', 'content');\n content.className = 'content';\n\n const steps = Array.from(this.children);\n\n steps?.forEach((step, index) => {\n if (step.nodeName === 'WJE-STEP') {\n this.processStep(index, step, header, steps);\n }\n });\n\n let slot = document.createElement('slot');\n\n const navButtons = document.createElement('div');\n navButtons.className = 'nav-buttons';\n\n const prevButton = document.createElement('wje-button');\n prevButton.setAttribute('label', this.localizer.translate('wj.stepper.button.previous'));\n prevButton.disabled = this.currentStep === 0;\n prevButton.innerHTML = 'Prev';\n\n let nextButton = document.createElement('wje-button');\n nextButton.setAttribute('label', this.localizer.translate('wj.stepper.button.next'));\n nextButton.disabled = this.currentStep === this.steps.length - 1;\n nextButton.innerHTML = 'Next';\n\n if (steps.length > 1) {\n navButtons.appendChild(prevButton);\n navButtons.appendChild(nextButton);\n } else {\n nextButton = document.createElement('wje-button');\n nextButton.setAttribute('label', this.localizer.translate('wj.stepper.button.finish'));\n nextButton.innerHTML = this.localizer.translate('wj.stepper.button.finish');\n nextButton.setAttribute('color', 'primary');\n\n prevButton.hidden = true;\n navButtons.appendChild(prevButton);\n navButtons.appendChild(nextButton);\n }\n\n content.appendChild(slot);\n\n native.appendChild(header);\n native.appendChild(content);\n native.appendChild(navButtons);\n\n fragment.appendChild(native);\n\n this.header = header;\n this.headerSteps = header.querySelectorAll('.step-header');\n this.prev = prevButton;\n this.next = nextButton;\n\n return fragment;\n }\n\n processStep(index, step, header, steps) {\n const nav = document.createElement('div');\n nav.className = 'step-header';\n nav.addEventListener('click', () => this.goToStep(index));\n\n const badge = document.createElement('wje-badge');\n badge.setAttribute('label', (index + 1).toString());\n badge.className = 'step-badge';\n badge.innerHTML = index + 1;\n\n const label = document.createElement('span');\n label.innerText = step.getAttribute('label') || `${this.localizer.translate('wj.stepper.step')} ${index + 1}`; // default label\n\n // set active step\n if (index === this.currentStep || step.hasAttribute('active')) {\n this.setStepActive(nav, badge);\n }\n\n if (step.hasAttribute('disabled')) {\n nav.setAttribute('disabled', '');\n } else {\n nav.classList.add('pointer');\n }\n\n nav.appendChild(badge);\n nav.appendChild(label);\n\n header.appendChild(nav);\n\n if (index < steps.length - 1) {\n const arrowIcon = document.createElement('wje-icon');\n arrowIcon.setAttribute('name', 'chevron-right');\n arrowIcon.classList.add('arrow-icon');\n arrowIcon.setAttribute('size', 'small');\n\n header.appendChild(arrowIcon);\n }\n\n step.classList.add('step');\n if (index !== this.currentStep) {\n step.style.display = 'none';\n }\n\n this.steps.push(step);\n }\n\n /**\n * Sets up the attributes for the component.\n */\n afterDraw() {\n if (this.steps.length <= 1) {\n this.prev.hidden = true;\n }\n\n event.addListener(this.prev, 'click', '', () => this.navigate(-1));\n event.addListener(this.next, 'click', '', () => this.navigate(1));\n }\n\n /**\n * Navigates to a different step in a multi-step process based on the provided direction.\n * @param {number} direction The navigation direction.\n * Use a positive value to move forward or a negative value to move backward.\n */\n navigate(direction) {\n this.goToStep(this.currentStep + direction, direction);\n }\n\n /**\n * Navigates to a specific step in a multi-step process and updates the stepper UI accordingly.\n * @param {number} stepIndex The index of the step to navigate to.\n * @param {number} direction The navigation direction. A positive value indicates forward navigation, and a negative value indicates backward navigation.\n * //@fires stepper:next Dispatched when navigating to the next step.\n * //@fires stepper:prev Dispatched when navigating to the previous step.\n * //@fires stepper:finish Dispatched when the final step is completed.\n */\n goToStep(stepIndex, direction) {\n if (stepIndex >= 0 && stepIndex < this.steps.length) {\n if (direction > 0) {\n this.dispatchEvent(\n new CustomEvent('stepper:next', { detail: { stepIndex }, bubbles: true, composed: true })\n );\n } else {\n this.dispatchEvent(\n new CustomEvent('stepper:prev', { detail: { stepIndex }, bubbles: true, composed: true })\n );\n }\n\n if (this.headerSteps[stepIndex].hasAttribute('disabled')) stepIndex += direction;\n\n this.headerSteps.forEach((step, index) => {\n let badge = step.querySelector('wje-badge');\n\n this.setStepDefault(step, badge, index);\n if (index < stepIndex) this.setStepDone(step, badge);\n });\n\n this.setStepActive(this.headerSteps[stepIndex], null, stepIndex);\n this.setContentActive(stepIndex);\n\n this.currentStep = stepIndex;\n\n this.prev.disabled = this.currentStep === 0;\n if (this.currentStep === this.steps.length - 1) {\n this.next.innerHTML = this.localizer.translate('wj.stepper.button.finish');\n this.next.setAttribute('color', 'primary');\n this.next.refresh();\n } else {\n this.next.innerHTML = this.localizer.translate('wj.stepper.button.next');\n this.next.removeAttribute('color');\n this.next.refresh();\n }\n } else if (stepIndex === this.steps.length) {\n this.dispatchEvent(\n new CustomEvent('stepper:finish', { detail: { stepIndex }, bubbles: true, composed: true })\n );\n }\n }\n\n /**\n * Resets a step to its default state by clearing its active and done attributes.\n * Updates the step's badge to show its index and removes any color styling.\n * @param {HTMLElement} nav The navigation element representing the step.\n * @param {HTMLElement|null} [badge] The badge element within the step. If not provided, it will be selected from the `nav` element.\n * @param {number} [stepIndex] The index of the step, used to set the badge content.\n */\n setStepDefault(nav, badge = null, stepIndex = 0) {\n nav.removeAttribute('active');\n nav.removeAttribute('done');\n\n if (!badge) {\n badge = nav.querySelector('wje-badge');\n }\n badge.innerHTML = stepIndex + 1;\n badge.removeAttribute('color');\n }\n\n /**\n * Sets a step as active by adding the `active` attribute and updating the step's badge.\n * @param {HTMLElement} nav The navigation element representing the step to activate.\n * @param {HTMLElement|null} [badge] The badge element within the step. If not provided, it will be selected from the `nav` element.\n * @param {number|null} [stepIndex] The index of the step, used to set the badge content. Defaults to `null` if not provided.\n */\n setStepActive(nav, badge = null, stepIndex = null) {\n nav.setAttribute('active', '');\n\n if (!badge) {\n badge = nav.querySelector('wje-badge');\n }\n badge.innerHTML = stepIndex + 1;\n badge.setAttribute('color', this.active);\n }\n\n /**\n * Activates the content of a specific step by displaying it and hiding all others.\n * @param {number} stepIndex The index of the step whose content should be displayed.\n */\n setContentActive(stepIndex) {\n this.steps?.forEach((step, index) => {\n if (index === stepIndex) {\n step.style.display = 'block';\n } else {\n step.style.display = 'none';\n }\n });\n }\n\n /**\n * Marks a step as completed by setting the `done` attribute and updating its badge with a check icon.\n * @param {HTMLElement} nav The navigation element representing the completed step.\n * @param {HTMLElement|null} [badge] The badge element within the step. If not provided, it will be selected from the `nav` element.\n */\n setStepDone(nav, badge = null) {\n nav.setAttribute('done', '');\n\n const checkIcon = document.createElement('wje-icon');\n checkIcon.setAttribute('name', 'check');\n checkIcon.setAttribute('color', this.done);\n checkIcon.setAttribute('size', 'medium');\n\n if (!badge) {\n badge = nav.querySelector('wje-badge');\n }\n\n badge.setAttribute('color', this.done);\n badge.innerHTML = '';\n badge.appendChild(checkIcon);\n }\n}\n","import Stepper from './stepper.element.js';\n\nexport default Stepper;\n\nStepper.define('wje-stepper', Stepper);\n"],"names":[],"mappings":";;;;;;AAkBe,MAAM,gBAAgB,UAAU;AAAA,EAC3C,cAAc;AACV,UAAO;AAmBX,qCAAY;AAlBR,SAAK,cAAc;AAEnB,SAAK,YAAY,IAAI,UAAU,IAAI;AACnC,SAAK,QAAQ,CAAE;AAAA,EACvB;AAAA,EAEI,IAAI,SAAS;AACT,QAAI,KAAK,aAAa,QAAQ,EAAG,QAAO,KAAK,aAAa,QAAQ;AAElE,WAAO;AAAA,EACf;AAAA,EAEI,IAAI,OAAO;AACP,QAAI,KAAK,aAAa,MAAM,EAAG,QAAO,KAAK,aAAa,MAAM;AAE9D,WAAO;AAAA,EACf;AAAA,EAII,WAAW,gBAAgB;AACvB,WAAO;AAAA,EACf;AAAA,EAEI,kBAAkB;AACd,SAAK,eAAe;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,OAAO;AACH,QAAI,WAAW,SAAS,uBAAwB;AAEhD,UAAM,SAAS,SAAS,cAAc,KAAK;AAC3C,WAAO,aAAa,QAAQ,QAAQ;AACpC,WAAO,YAAY;AAEnB,UAAM,SAAS,SAAS,cAAc,KAAK;AAC3C,WAAO,aAAa,QAAQ,QAAQ;AACpC,WAAO,YAAY;AAEnB,UAAM,UAAU,SAAS,cAAc,KAAK;AAC5C,YAAQ,aAAa,QAAQ,SAAS;AACtC,Y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AEvC,QAAI,CAAC,OAAO;AACR,cAAQ,IAAI,cAAc,WAAW;AAAA,IACjD;AAEQ,UAAM,aAAa,SAAS,KAAK,IAAI;AACrC,UAAM,YAAY;AAClB,UAAM,YAAY,SAAS;AAAA,EACnC;AACA;AChTA,QAAQ,OAAO,eAAe,OAAO;"}
|
package/dist/wje-store.js
CHANGED
|
@@ -81,17 +81,18 @@ class PubSub {
|
|
|
81
81
|
/**
|
|
82
82
|
* If the passed event has callbacks attached to it, loop through each one and call it.
|
|
83
83
|
* @param {string} event The name of the event to publish
|
|
84
|
-
* @param {
|
|
85
|
-
* @param {object} [
|
|
86
|
-
* @
|
|
84
|
+
* @param {any} state The current state to pass to the callbacks
|
|
85
|
+
* @param {object} [newData] The new data to pass to the callbacks
|
|
86
|
+
* @param {object} [oldData] The old data to pass to the callbacks
|
|
87
|
+
* @returns {Array} The results of the callbacks for this event, or an empty array if no event exists
|
|
87
88
|
* @memberof PubSub
|
|
88
89
|
*/
|
|
89
|
-
publish(event, newData = {}, oldData = {}) {
|
|
90
|
+
publish(event, state, newData = {}, oldData = {}) {
|
|
90
91
|
let self = this;
|
|
91
92
|
if (!self.events.hasOwnProperty(event)) {
|
|
92
93
|
return [];
|
|
93
94
|
}
|
|
94
|
-
return self.events[event].map((callback) => callback(
|
|
95
|
+
return self.events[event].map((callback) => callback(state, oldData, newData));
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
class Store {
|
|
@@ -281,7 +282,7 @@ class Store {
|
|
|
281
282
|
}
|
|
282
283
|
let oldState = state[key];
|
|
283
284
|
state[key] = value;
|
|
284
|
-
if (!this._isPause) this.events.publish(key, this._state, oldState);
|
|
285
|
+
if (!this._isPause) this.events.publish(key, this._state, state[key], oldState);
|
|
285
286
|
if (this.status !== "mutation") {
|
|
286
287
|
console.warn(`You should use a mutation to set ${key}`);
|
|
287
288
|
}
|
package/dist/wje-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-store.js","sources":["../packages/wje-store/default-store-actions.js","../packages/wje-store/pubsub.js","../packages/wje-store/store.js"],"sourcesContent":["const addAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/ADD`,\n payload: payload2,\n actionType: 'ADD',\n };\n };\n};\n\nconst addManyAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/ADD_MANY`,\n payload: payload2,\n actionType: 'ADD_MANY',\n };\n };\n};\n\nconst updateAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/UPDATE`,\n payload: payload2,\n actionType: 'UPDATE',\n };\n };\n};\n\nconst deleteAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/DELETE`,\n payload: payload2,\n actionType: 'DELETE',\n };\n };\n};\n\nconst loadAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/LOAD`,\n payload: payload2,\n actionType: 'LOAD',\n };\n };\n};\n\nexport { addAction, deleteAction, loadAction, updateAction, addManyAction };\n","export default class PubSub {\n constructor() {\n this.events = {};\n }\n\n /**\n * Either create a new event instance for passed `event` name.\n * or push a new callback into the existing collection.\n * @param {string} event The event name to subscribe to\n * @param {Function} callback The callback function to subscribe to the event\n * @returns {number} A count of callbacks for this event\n * @memberof PubSub\n */\n subscribe(event, callback) {\n let self = this;\n let index;\n\n // If there's not already an event with this name set in our collection\n // go ahead and create a new one and set it with an empty array, so we don't\n // have to type check it later down-the-line\n if (!self.events.hasOwnProperty(event)) {\n self.events[event] = [];\n }\n\n index = self.events[event].push(callback) - 1;\n\n return {\n unsubscribe() {\n self.events[event].splice(self.events[event].indexOf(callback), 1);\n },\n };\n }\n\n /**\n * If the passed event has callbacks attached to it, loop through each one and call it.\n * @param {string} event The name of the event to publish\n * @param {object} [newData] The data to pass to the callbacks\n * @param {object} [oldData] The data to pass to the callbacks\n * @returns {Array} The callbacks for this event, or an empty array if no event exits\n * @memberof PubSub\n */\n publish(event, newData = {}, oldData = {}) {\n let self = this;\n\n // There's no event to publish to, so bail out\n if (!self.events.hasOwnProperty(event)) {\n return [];\n }\n\n // Get each subscription and call its callback with the passed data\n return self.events[event].map((callback) => callback(newData, oldData));\n }\n}\n","import * as defaultStoreActions from './default-store-actions.js';\nimport PubSub from './pubsub.js';\n\n/**\n * @summary A reactive state management system with support for reducers, events, and state immutability.\n * @description The `Store` class provides a centralized way to manage application state with actions, reducers, and event subscriptions. It supports handling both object and array state, with flexibility for custom reducers.\n * @example\n * const store = new Store({\n * reducer: (state, action) => { ... },\n * state: { user: { id: 1, name: 'John' } }\n * });\n * store.subscribe('user', (newState, oldState) => console.log('User changed:', newState));\n * store.dispatch({ type: 'user/UPDATE', payload: { name: 'Jane' } });\n */\nclass Store {\n _state;\n _reducer;\n events;\n status;\n\n /**\n * Initializes the store with optional reducer and state.\n * @param {object} [params] Configuration for the store.\n * @param {Function} [params.reducer] Initial reducer function for handling state updates.\n * @param {object} [params.state] Initial state of the store.\n */\n constructor(params = {}) {\n this._isPause = false;\n this._state = {};\n this._reducer = () => {\n return {};\n };\n\n // A status enum to set during actions and mutations\n this.status = 'resting';\n\n // Attach our PubSub module as an `events` element\n this.events = new PubSub();\n\n if (params?.hasOwnProperty('reducer')) {\n this._reducer = params.reducer;\n }\n\n this.refreshProxy(params?.state);\n }\n\n /**\n * Dispatches an action to update the state by invoking the reducer function.\n * @param {object} action The action object containing the type and any associated payload.\n * @param {string} action.type The type of the action being dispatched.\n * @returns {boolean} Returns `true` after the state has been successfully updated.\n * @example\n * const action = { type: 'INCREMENT', payload: { amount: 1 } };\n * store.dispatch(action);\n */\n dispatch(action) {\n // Create a console group which will contain the logs from our Proxy etc\n // console.groupCollapsed(`ACTION: ${action.type}`);\n\n // Let anything that's watching the status know that we're dispatching an action\n this.status = 'action';\n\n let newState = this._reducer(this._state, action);\n\n this.status = 'mutation';\n // Merge the old and new together to create a new state and set it\n this._state = Object.assign(this._state, newState);\n\n // Close our console group to keep things nice and neat\n // console.groupEnd();\n\n return true;\n }\n\n /**\n * Retrieves a deep copy of the current state to ensure immutability.\n * @returns {object} A deep copy of the current state.\n * @example\n * const currentState = store.getState();\n * console.log(currentState);\n */\n getState() {\n return JSON.parse(JSON.stringify(this._state));\n }\n\n /**\n * Subscribes to a specific event with a provided callback function.\n * @param {string} eventName The name of the event to subscribe to.\n * @param {Function} callbackFn The function to execute when the event is triggered.\n * @returns {Function} - A function to unsubscribe from the event.\n * @example\n * const unsubscribe = store.subscribe('stateChange', (newState) => {\n * console.log('State changed:', newState);\n * });\n * // Later, to unsubscribe\n * unsubscribe();\n */\n subscribe(eventName, callbackFn) {\n return this.events.subscribe(eventName, callbackFn);\n }\n\n /**\n * Unsubscribes from a specific event by removing all associated listeners.\n * @param {string} eventName The name of the event to unsubscribe from.\n * @returns {void}\n * @example\n * store.unsubscribe('stateChange');\n */\n unsubscribe(eventName) {\n delete this.events[eventName];\n }\n\n /**\n * Pauses event handling or other operations.\n * @returns {this} Returns the current instance for method chaining.\n * @example\n * store.pause().doSomething();\n */\n pause() {\n this._isPause = true;\n return this;\n }\n\n /**\n * Resumes event handling or other operations.\n * @param {*} [val] Optional value to pass while resuming.\n * @returns {this} Returns the current instance for method chaining.\n * @example\n * store.play().doSomething();\n */\n play(val) {\n this._isPause = false;\n return this;\n }\n\n /**\n * Merges a new reducer function into the existing reducer for a specific state property.\n * @param {string} stateValueName The key in the state object that the new reducer will manage.\n * @param {Function} newReducer The reducer function to handle updates for the specified state property.\n * @returns {void}\n * @example\n * const newReducer = (newState, currentState) => ({ ...currentState, ...newState });\n * store.mergeReducers('user', newReducer);\n */\n mergeReducers(stateValueName, newReducer) {\n let reducerCopy = this._reducer;\n this._reducer = (state, newState) => {\n let preState = reducerCopy(state, newState);\n return {\n ...preState,\n [stateValueName]: newReducer(newState, state[stateValueName]),\n };\n };\n }\n\n /**\n * Synchronizes each entry in an array with the store by defining or updating state entries.\n * @param {string} storeKey The key prefix used for defining or updating store entries.\n * @param {Array<object>} [array] The array of entries to be synchronized with the store.\n * @param {string} [identificator] The property name used as a unique identifier for each entry.\n * @returns {void}\n * @example\n * const data = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }];\n * store.makeEveryArrayEntryAsStoreState('items', data, 'id');\n */\n makeEveryArrayEntryAsStoreState(storeKey, array = [], identificator = 'id') {\n array.forEach((entry) => {\n if (this.getState().hasOwnProperty(`${storeKey}-${entry[identificator]}`)) {\n this.dispatch(defaultStoreActions.updateAction(`${storeKey}-${entry[identificator]}`)(entry));\n } else {\n this.define(\n `${storeKey}-${entry.id || entry.source || entry[identificator]}`,\n entry,\n null,\n identificator\n );\n }\n });\n }\n\n /**\n * Defines a new state variable and associates it with a reducer.\n * @param {string} stateValueName The name of the state variable to define.\n * @param {*} defaultValue The initial value of the state variable.\n * @param {Function|null} [reducer] An optional reducer function to manage updates for the state variable.\n * @param {string} [key] The key used to identify individual entries if the state value is an array or object.\n * @returns {void}\n * @example\n * // Define a new state with a custom reducer\n * store.define('user', { id: 1, name: 'John Doe' }, (newState, currentState) => ({ ...currentState, ...newState }));\n * @example\n * // Define a new state with default array reducer\n * store.define('items', [], null, 'itemId');\n */\n define(stateValueName, defaultValue, reducer, key = 'id') {\n if (this._state.hasOwnProperty(stateValueName)) {\n console.warn(`STATE už obsahuje premennú ${stateValueName},ktorú sa pokúšate pridať`);\n return;\n }\n\n if (reducer instanceof Function) {\n this.mergeReducers(stateValueName, reducer);\n } else {\n if (defaultValue instanceof Array) {\n this.mergeReducers(stateValueName, this.createArrayReducer(stateValueName, key));\n } else {\n this.mergeReducers(stateValueName, this.createObjectReducer(stateValueName, key));\n }\n }\n\n this.refreshProxy({\n ...this._state,\n [stateValueName]: defaultValue,\n });\n }\n\n /**\n * Refreshes the state by wrapping it in a Proxy to track changes and notify subscribers.\n * @param {object} newState The new state object to be set. Defaults to an empty object if not provided.\n * @returns {void}\n * @example\n * store.refreshProxy({ user: { id: 1, name: 'John Doe' } });\n */\n refreshProxy(newState) {\n // Set our state to be a Proxy. We are setting the default state by\n // checking the params and defaulting to an empty object if no default\n // state is passed in\n this._state = new Proxy(newState || {}, {\n set: (state, key, value) => {\n if (JSON.stringify(state[key]) === JSON.stringify(value)) {\n return true;\n }\n\n //Set the value as we would normally\n let oldState = state[key];\n state[key] = value;\n\n // Trace out to the console. This will be grouped by the related action\n // console.log(`stateChange: ${key}: `, value);\n\n // TODO vieme to rozšíríť a subscripe sa len na zmenu určitej časti statu\n // Publish the change event for the components that are listening\n if (!this._isPause) this.events.publish(key, this._state, oldState);\n\n // Give the user a little telling off if they set a value directly\n if (this.status !== 'mutation') {\n console.warn(`You should use a mutation to set ${key}`);\n }\n\n // Reset the status ready for the next operation\n this.status = 'resting';\n\n return true;\n },\n });\n }\n\n /**\n * Creates a reducer function to manage an object state.\n * @param {string} stateValueName The name of the state property this reducer manages.\n * @returns {Function} A reducer function that handles `ADD`, `UPDATE`, and `DELETE` actions for the specified state property.\n * @throws {Error} If the payload is an array, an error is logged since the reducer is designed for object state management.\n * @example\n * const userReducer = store.createObjectReducer('user');\n * const newState = userReducer({ type: 'user/ADD', payload: { id: 1, name: 'John Doe' } });\n */\n createObjectReducer(stateValueName) {\n return (action, state = {}) => {\n if (\n Array.isArray(action.payload) &&\n (action.type === `${stateValueName}/ADD` || action.type === `${stateValueName}/UPDATE`)\n ) {\n console.error(`Nemôžete pridať do objektu ${stateValueName} hodnotu, ktorá je pole.`);\n }\n\n const actionType = action.type.split('/')[1];\n\n if (!['ADD', 'UPDATE', 'DELETE'].includes(actionType)) {\n console.error(\n `Nemôžete použiť akciu ${actionType} na objekt. Správne akcie pre objekt sú: ADD, UPDATE, DELETE`\n );\n }\n\n switch (action.type) {\n case `${stateValueName}/ADD`:\n return {\n ...action.payload,\n };\n case `${stateValueName}/UPDATE`:\n return {\n ...state,\n ...action.payload,\n };\n case `${stateValueName}/DELETE`:\n return {};\n default:\n return state;\n }\n };\n }\n\n /**\n * Creates a reducer function to manage an array state.\n * @param {string} stateValueName The name of the state property this reducer manages.\n * @param {string} key The unique key used to identify items in the array for updates and deletions.\n * @returns {Function} A reducer function that handles `ADD`, `ADD_MANY`, `UPDATE`, `DELETE`, and `LOAD` actions for the specified state property.\n * @throws {Error} If `action.payload` is not an array when required.\n * @example\n * const itemsReducer = store.createArrayReducer('items', 'id');\n * const newState = itemsReducer({ type: 'items/ADD', payload: { id: 1, name: 'Item 1' } });\n */\n createArrayReducer(stateValueName, key) {\n return (action, state = []) => {\n if (action.actionType === 'LOAD' && action.type?.includes(stateValueName)) {\n if (!Array.isArray(action.payload)) {\n console.error(`Snažíte sa použiť \"LOAD\" akciu na pole, ale payload nie je pole.`);\n\n return [...state];\n }\n }\n\n switch (action.type) {\n case `${stateValueName}/ADD`:\n if (Array.isArray(action.payload)) {\n return [...state, ...action.payload];\n } else {\n return [...state, action.payload];\n }\n case `${stateValueName}/ADD_MANY`:\n return [...state, ...action.payload];\n case `${stateValueName}/UPDATE`:\n if (state.some((obj) => obj[key] === action.payload[key])) {\n return [\n ...state.map((obj) => {\n if (obj[key] === action.payload[key]) {\n return action.payload;\n }\n return obj;\n }),\n ];\n } else {\n return [...state, action.payload];\n }\n case `${stateValueName}/DELETE`:\n if (Array.isArray(action.payload)) {\n return [\n ...state.filter(\n (obj) =>\n !action.payload.some(\n (item) =>\n (obj.hasOwnProperty(key) && obj[key] !== item[key]) ||\n (!obj.hasOwnProperty(key) && obj !== item)\n )\n ),\n ];\n }\n\n return [\n ...state.filter(\n (obj) =>\n (obj.hasOwnProperty(key) && obj[key] !== action.payload[key]) ||\n (!obj.hasOwnProperty(key) && obj !== action.payload)\n ),\n ];\n\n case `${stateValueName}/LOAD`:\n return [...action.payload];\n default:\n return state;\n }\n };\n }\n}\n\nlet store = new Store();\nexport { store, defaultStoreActions };\n"],"names":["defaultStoreActions.updateAction"],"mappings":";;;AAAA,MAAM,YAAY,CAAC,mBAAmB;AAClC,SAAO,CAAC,aAAa;AACjB,WAAO;AAAA,MACH,MAAM,GAAG,cAAc;AAAA,MACvB,SA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G;AACvD,mBAAO;AAAA,cACH,GAAG,MAAM,IAAI,CAAC,QAAQ;AAClB,oBAAI,IAAI,GAAG,MAAM,OAAO,QAAQ,GAAG,GAAG;AAClC,yBAAO,OAAO;AAAA,gBAClD;AACgC,uBAAO;AAAA,cACvC,CAA6B;AAAA,YACJ;AAAA,UACzB,OAA2B;AACH,mBAAO,CAAC,GAAG,OAAO,OAAO,OAAO;AAAA,UACxD;AAAA,QACgB,KAAK,GAAG,cAAc;AAClB,cAAI,MAAM,QAAQ,OAAO,OAAO,GAAG;AAC/B,mBAAO;AAAA,cACH,GAAG,MAAM;AAAA,gBACL,CAAC,QACG,CAAC,OAAO,QAAQ;AAAA,kBACZ,CAAC,SACI,IAAI,eAAe,GAAG,KAAK,IAAI,GAAG,MAAM,KAAK,GAAG,KAChD,CAAC,IAAI,eAAe,GAAG,KAAK,QAAQ;AAAA,gBACjF;AAAA,cAC6B;AAAA,YACJ;AAAA,UACzB;AAEoB,iBAAO;AAAA,YACH,GAAG,MAAM;AAAA,cACL,CAAC,QACI,IAAI,eAAe,GAAG,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,GAAG,KAC1D,CAAC,IAAI,eAAe,GAAG,KAAK,QAAQ,OAAO;AAAA,YACnD;AAAA,UACJ;AAAA,QAEL,KAAK,GAAG,cAAc;AAClB,iBAAO,CAAC,GAAG,OAAO,OAAO;AAAA,QAC7B;AACI,iBAAO;AAAA,MAC3B;AAAA,IACS;AAAA,EACT;AACA;AAEG,IAAC,QAAQ,IAAI,MAAK;"}
|
|
1
|
+
{"version":3,"file":"wje-store.js","sources":["../packages/wje-store/default-store-actions.js","../packages/wje-store/pubsub.js","../packages/wje-store/store.js"],"sourcesContent":["const addAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/ADD`,\n payload: payload2,\n actionType: 'ADD',\n };\n };\n};\n\nconst addManyAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/ADD_MANY`,\n payload: payload2,\n actionType: 'ADD_MANY',\n };\n };\n};\n\nconst updateAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/UPDATE`,\n payload: payload2,\n actionType: 'UPDATE',\n };\n };\n};\n\nconst deleteAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/DELETE`,\n payload: payload2,\n actionType: 'DELETE',\n };\n };\n};\n\nconst loadAction = (stateValueName) => {\n return (payload2) => {\n return {\n type: `${stateValueName}/LOAD`,\n payload: payload2,\n actionType: 'LOAD',\n };\n };\n};\n\nexport { addAction, deleteAction, loadAction, updateAction, addManyAction };\n","export default class PubSub {\n constructor() {\n this.events = {};\n }\n\n /**\n * Either create a new event instance for passed `event` name.\n * or push a new callback into the existing collection.\n * @param {string} event The event name to subscribe to\n * @param {Function} callback The callback function to subscribe to the event\n * @returns {number} A count of callbacks for this event\n * @memberof PubSub\n */\n subscribe(event, callback) {\n let self = this;\n let index;\n\n // If there's not already an event with this name set in our collection\n // go ahead and create a new one and set it with an empty array, so we don't\n // have to type check it later down-the-line\n if (!self.events.hasOwnProperty(event)) {\n self.events[event] = [];\n }\n\n index = self.events[event].push(callback) - 1;\n\n return {\n unsubscribe() {\n self.events[event].splice(self.events[event].indexOf(callback), 1);\n },\n };\n }\n\n /**\n * If the passed event has callbacks attached to it, loop through each one and call it.\n * @param {string} event The name of the event to publish\n * @param {any} state The current state to pass to the callbacks\n * @param {object} [newData] The new data to pass to the callbacks\n * @param {object} [oldData] The old data to pass to the callbacks\n * @returns {Array} The results of the callbacks for this event, or an empty array if no event exists\n * @memberof PubSub\n */\n publish(event, state, newData = {}, oldData = {}) {\n let self = this;\n\n // There's no event to publish to, so bail out\n if (!self.events.hasOwnProperty(event)) {\n return [];\n }\n\n // Get each subscription and call its callback with the passed data\n return self.events[event].map((callback) => callback(state, oldData, newData));\n }\n}\n","import * as defaultStoreActions from './default-store-actions.js';\nimport PubSub from './pubsub.js';\n\n/**\n * @summary A reactive state management system with support for reducers, events, and state immutability.\n * @description The `Store` class provides a centralized way to manage application state with actions, reducers, and event subscriptions. It supports handling both object and array state, with flexibility for custom reducers.\n * @example\n * const store = new Store({\n * reducer: (state, action) => { ... },\n * state: { user: { id: 1, name: 'John' } }\n * });\n * store.subscribe('user', (newState, oldState) => console.log('User changed:', newState));\n * store.dispatch({ type: 'user/UPDATE', payload: { name: 'Jane' } });\n */\nclass Store {\n _state;\n _reducer;\n events;\n status;\n\n /**\n * Initializes the store with optional reducer and state.\n * @param {object} [params] Configuration for the store.\n * @param {Function} [params.reducer] Initial reducer function for handling state updates.\n * @param {object} [params.state] Initial state of the store.\n */\n constructor(params = {}) {\n this._isPause = false;\n this._state = {};\n this._reducer = () => {\n return {};\n };\n\n // A status enum to set during actions and mutations\n this.status = 'resting';\n\n // Attach our PubSub module as an `events` element\n this.events = new PubSub();\n\n if (params?.hasOwnProperty('reducer')) {\n this._reducer = params.reducer;\n }\n\n this.refreshProxy(params?.state);\n }\n\n /**\n * Dispatches an action to update the state by invoking the reducer function.\n * @param {object} action The action object containing the type and any associated payload.\n * @param {string} action.type The type of the action being dispatched.\n * @returns {boolean} Returns `true` after the state has been successfully updated.\n * @example\n * const action = { type: 'INCREMENT', payload: { amount: 1 } };\n * store.dispatch(action);\n */\n dispatch(action) {\n // Create a console group which will contain the logs from our Proxy etc\n // console.groupCollapsed(`ACTION: ${action.type}`);\n\n // Let anything that's watching the status know that we're dispatching an action\n this.status = 'action';\n\n let newState = this._reducer(this._state, action);\n\n this.status = 'mutation';\n // Merge the old and new together to create a new state and set it\n this._state = Object.assign(this._state, newState);\n\n // Close our console group to keep things nice and neat\n // console.groupEnd();\n\n return true;\n }\n\n /**\n * Retrieves a deep copy of the current state to ensure immutability.\n * @returns {object} A deep copy of the current state.\n * @example\n * const currentState = store.getState();\n * console.log(currentState);\n */\n getState() {\n return JSON.parse(JSON.stringify(this._state));\n }\n\n /**\n * Subscribes to a specific event with a provided callback function.\n * @param {string} eventName The name of the event to subscribe to.\n * @param {Function} callbackFn The function to execute when the event is triggered.\n * @returns {Function} - A function to unsubscribe from the event.\n * @example\n * const unsubscribe = store.subscribe('stateChange', (newState) => {\n * console.log('State changed:', newState);\n * });\n * // Later, to unsubscribe\n * unsubscribe();\n */\n subscribe(eventName, callbackFn) {\n return this.events.subscribe(eventName, callbackFn);\n }\n\n /**\n * Unsubscribes from a specific event by removing all associated listeners.\n * @param {string} eventName The name of the event to unsubscribe from.\n * @returns {void}\n * @example\n * store.unsubscribe('stateChange');\n */\n unsubscribe(eventName) {\n delete this.events[eventName];\n }\n\n /**\n * Pauses event handling or other operations.\n * @returns {this} Returns the current instance for method chaining.\n * @example\n * store.pause().doSomething();\n */\n pause() {\n this._isPause = true;\n return this;\n }\n\n /**\n * Resumes event handling or other operations.\n * @param {*} [val] Optional value to pass while resuming.\n * @returns {this} Returns the current instance for method chaining.\n * @example\n * store.play().doSomething();\n */\n play(val) {\n this._isPause = false;\n return this;\n }\n\n /**\n * Merges a new reducer function into the existing reducer for a specific state property.\n * @param {string} stateValueName The key in the state object that the new reducer will manage.\n * @param {Function} newReducer The reducer function to handle updates for the specified state property.\n * @returns {void}\n * @example\n * const newReducer = (newState, currentState) => ({ ...currentState, ...newState });\n * store.mergeReducers('user', newReducer);\n */\n mergeReducers(stateValueName, newReducer) {\n let reducerCopy = this._reducer;\n this._reducer = (state, newState) => {\n let preState = reducerCopy(state, newState);\n return {\n ...preState,\n [stateValueName]: newReducer(newState, state[stateValueName]),\n };\n };\n }\n\n /**\n * Synchronizes each entry in an array with the store by defining or updating state entries.\n * @param {string} storeKey The key prefix used for defining or updating store entries.\n * @param {Array<object>} [array] The array of entries to be synchronized with the store.\n * @param {string} [identificator] The property name used as a unique identifier for each entry.\n * @returns {void}\n * @example\n * const data = [{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }];\n * store.makeEveryArrayEntryAsStoreState('items', data, 'id');\n */\n makeEveryArrayEntryAsStoreState(storeKey, array = [], identificator = 'id') {\n array.forEach((entry) => {\n if (this.getState().hasOwnProperty(`${storeKey}-${entry[identificator]}`)) {\n this.dispatch(defaultStoreActions.updateAction(`${storeKey}-${entry[identificator]}`)(entry));\n } else {\n this.define(\n `${storeKey}-${entry.id || entry.source || entry[identificator]}`,\n entry,\n null,\n identificator\n );\n }\n });\n }\n\n /**\n * Defines a new state variable and associates it with a reducer.\n * @param {string} stateValueName The name of the state variable to define.\n * @param {*} defaultValue The initial value of the state variable.\n * @param {Function|null} [reducer] An optional reducer function to manage updates for the state variable.\n * @param {string} [key] The key used to identify individual entries if the state value is an array or object.\n * @returns {void}\n * @example\n * // Define a new state with a custom reducer\n * store.define('user', { id: 1, name: 'John Doe' }, (newState, currentState) => ({ ...currentState, ...newState }));\n * @example\n * // Define a new state with default array reducer\n * store.define('items', [], null, 'itemId');\n */\n define(stateValueName, defaultValue, reducer, key = 'id') {\n if (this._state.hasOwnProperty(stateValueName)) {\n console.warn(`STATE už obsahuje premennú ${stateValueName},ktorú sa pokúšate pridať`);\n return;\n }\n\n if (reducer instanceof Function) {\n this.mergeReducers(stateValueName, reducer);\n } else {\n if (defaultValue instanceof Array) {\n this.mergeReducers(stateValueName, this.createArrayReducer(stateValueName, key));\n } else {\n this.mergeReducers(stateValueName, this.createObjectReducer(stateValueName, key));\n }\n }\n\n this.refreshProxy({\n ...this._state,\n [stateValueName]: defaultValue,\n });\n }\n\n /**\n * Refreshes the state by wrapping it in a Proxy to track changes and notify subscribers.\n * @param {object} newState The new state object to be set. Defaults to an empty object if not provided.\n * @returns {void}\n * @example\n * store.refreshProxy({ user: { id: 1, name: 'John Doe' } });\n */\n refreshProxy(newState) {\n // Set our state to be a Proxy. We are setting the default state by\n // checking the params and defaulting to an empty object if no default\n // state is passed in\n this._state = new Proxy(newState || {}, {\n set: (state, key, value) => {\n if (JSON.stringify(state[key]) === JSON.stringify(value)) {\n return true;\n }\n\n //Set the value as we would normally\n let oldState = state[key];\n state[key] = value;\n\n // Trace out to the console. This will be grouped by the related action\n // console.log(`stateChange: ${key}: `, value);\n\n // TODO vieme to rozšíríť a subscripe sa len na zmenu určitej časti statu\n // Publish the change event for the components that are listening\n if (!this._isPause) this.events.publish(key, this._state, state[key], oldState);\n\n // Give the user a little telling off if they set a value directly\n if (this.status !== 'mutation') {\n console.warn(`You should use a mutation to set ${key}`);\n }\n\n // Reset the status ready for the next operation\n this.status = 'resting';\n\n return true;\n },\n });\n }\n\n /**\n * Creates a reducer function to manage an object state.\n * @param {string} stateValueName The name of the state property this reducer manages.\n * @returns {Function} A reducer function that handles `ADD`, `UPDATE`, and `DELETE` actions for the specified state property.\n * @throws {Error} If the payload is an array, an error is logged since the reducer is designed for object state management.\n * @example\n * const userReducer = store.createObjectReducer('user');\n * const newState = userReducer({ type: 'user/ADD', payload: { id: 1, name: 'John Doe' } });\n */\n createObjectReducer(stateValueName) {\n return (action, state = {}) => {\n if (\n Array.isArray(action.payload) &&\n (action.type === `${stateValueName}/ADD` || action.type === `${stateValueName}/UPDATE`)\n ) {\n console.error(`Nemôžete pridať do objektu ${stateValueName} hodnotu, ktorá je pole.`);\n }\n\n const actionType = action.type.split('/')[1];\n\n if (!['ADD', 'UPDATE', 'DELETE'].includes(actionType)) {\n console.error(\n `Nemôžete použiť akciu ${actionType} na objekt. Správne akcie pre objekt sú: ADD, UPDATE, DELETE`\n );\n }\n\n switch (action.type) {\n case `${stateValueName}/ADD`:\n return {\n ...action.payload,\n };\n case `${stateValueName}/UPDATE`:\n return {\n ...state,\n ...action.payload,\n };\n case `${stateValueName}/DELETE`:\n return {};\n default:\n return state;\n }\n };\n }\n\n /**\n * Creates a reducer function to manage an array state.\n * @param {string} stateValueName The name of the state property this reducer manages.\n * @param {string} key The unique key used to identify items in the array for updates and deletions.\n * @returns {Function} A reducer function that handles `ADD`, `ADD_MANY`, `UPDATE`, `DELETE`, and `LOAD` actions for the specified state property.\n * @throws {Error} If `action.payload` is not an array when required.\n * @example\n * const itemsReducer = store.createArrayReducer('items', 'id');\n * const newState = itemsReducer({ type: 'items/ADD', payload: { id: 1, name: 'Item 1' } });\n */\n createArrayReducer(stateValueName, key) {\n return (action, state = []) => {\n if (action.actionType === 'LOAD' && action.type?.includes(stateValueName)) {\n if (!Array.isArray(action.payload)) {\n console.error(`Snažíte sa použiť \"LOAD\" akciu na pole, ale payload nie je pole.`);\n\n return [...state];\n }\n }\n\n switch (action.type) {\n case `${stateValueName}/ADD`:\n if (Array.isArray(action.payload)) {\n return [...state, ...action.payload];\n } else {\n return [...state, action.payload];\n }\n case `${stateValueName}/ADD_MANY`:\n return [...state, ...action.payload];\n case `${stateValueName}/UPDATE`:\n if (state.some((obj) => obj[key] === action.payload[key])) {\n return [\n ...state.map((obj) => {\n if (obj[key] === action.payload[key]) {\n return action.payload;\n }\n return obj;\n }),\n ];\n } else {\n return [...state, action.payload];\n }\n case `${stateValueName}/DELETE`:\n if (Array.isArray(action.payload)) {\n return [\n ...state.filter(\n (obj) =>\n !action.payload.some(\n (item) =>\n (obj.hasOwnProperty(key) && obj[key] !== item[key]) ||\n (!obj.hasOwnProperty(key) && obj !== item)\n )\n ),\n ];\n }\n\n return [\n ...state.filter(\n (obj) =>\n (obj.hasOwnProperty(key) && obj[key] !== action.payload[key]) ||\n (!obj.hasOwnProperty(key) && obj !== action.payload)\n ),\n ];\n\n case `${stateValueName}/LOAD`:\n return [...action.payload];\n default:\n return state;\n }\n };\n }\n}\n\nlet store = new Store();\nexport { store, defaultStoreActions };\n"],"names":["defaultStoreActions.updateAction"],"mappings":";;;AAAA,MAAM,YAAY,CAAC,mBAAmB;AAClC,SAAO,CAAC,aAAa;AACjB,WAAO;AAAA,MACH,MAAM,GAAG,cAAc;AAAA,MACvB,SAAS;AAAA,MACT,YAAY;AAAA,IACf;AAAA,EACJ;AACL;AAEA,MAAM,gBAAgB,CAAC,mBAAmB;AACtC,SAAO,CAAC,aAAa;AACjB,WAAO;AAAA,MACH,MAAM,GAAG,cAAc;AAAA,MACvB,SAAS;AAAA,MACT,YAAY;AAAA,IACf;AAAA,EACJ;AACL;A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AA,YACJ;AAAA,UACzB,OAA2B;AACH,mBAAO,CAAC,GAAG,OAAO,OAAO,OAAO;AAAA,UACxD;AAAA,QACgB,KAAK,GAAG,cAAc;AAClB,cAAI,MAAM,QAAQ,OAAO,OAAO,GAAG;AAC/B,mBAAO;AAAA,cACH,GAAG,MAAM;AAAA,gBACL,CAAC,QACG,CAAC,OAAO,QAAQ;AAAA,kBACZ,CAAC,SACI,IAAI,eAAe,GAAG,KAAK,IAAI,GAAG,MAAM,KAAK,GAAG,KAChD,CAAC,IAAI,eAAe,GAAG,KAAK,QAAQ;AAAA,gBACjF;AAAA,cAC6B;AAAA,YACJ;AAAA,UACzB;AAEoB,iBAAO;AAAA,YACH,GAAG,MAAM;AAAA,cACL,CAAC,QACI,IAAI,eAAe,GAAG,KAAK,IAAI,GAAG,MAAM,OAAO,QAAQ,GAAG,KAC1D,CAAC,IAAI,eAAe,GAAG,KAAK,QAAQ,OAAO;AAAA,YACnD;AAAA,UACJ;AAAA,QAEL,KAAK,GAAG,cAAc;AAClB,iBAAO,CAAC,GAAG,OAAO,OAAO;AAAA,QAC7B;AACI,iBAAO;AAAA,MAC3B;AAAA,IACS;AAAA,EACT;AACA;AAEG,IAAC,QAAQ,IAAI,MAAK;"}
|
package/dist/wje-tab-group.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 from "./wje-element.js";
|
|
5
|
-
const styles = "/*\n[ WJ Tab Group ]\n*/\n\n:host {\n --wje-tab-top: 0;\n --wje-tab-start: 0;\n --wje-tab-end: 0;\n --wje-tab-bottom: 0;\n}\n.native-tab-group {\n display: flex;\n flex-direction: column;\n\n overflow: hidden;\n position: relative;\n}\n\n.native-tab-group > header {\n display: flex;\n flex-direction: column;\n\n & > nav {\n display: flex;\n }\n}\n\n.native-tab-group > section {\n width: 100%;\n\n & > article {\n scroll-snap-align: start;\n overflow-y: auto;\n overscroll-behavior-y: contain;\n }\n}\n\n/*TOP*/\n:host([variant='top']) {\n --wje-tab-top: auto !important;\n --wje-tab-writing-mode: horizontal-tb;\n .native-tab-group {\n flex-direction: column;\n }\n nav {\n border-bottom: 1px solid var(--wje-border-color);\n }\n}\n\n/*START*/\n:host([variant='start']) {\n --wje-tab-start: auto !important;\n --wje-tab-writing-mode: vertical-rl;\n .native-tab-group {\n flex-direction: row;\n }\n nav {\n flex-direction: column;\n border-right: 1px solid var(--wje-border-color);\n }\n}\n\n/*END*/\n:host([variant='end']) {\n --wje-tab-writing-mode: vertical-rl;\n .native-tab-group {\n flex-direction: row-reverse;\n }\n nav {\n flex-direction: column;\n border-left: 1px solid var(--wje-border-color);\n }\n}\n\n/*BOTTOM*/\n:host([variant='bottom']) {\n --wje-tab-bottom: auto !important;\n --wje-tab-writing-mode: horizontal-tb;\n .native-tab-group {\n flex-direction: column-reverse;\n }\n nav {\n border-top: 1px solid var(--wje-border-color);\n }\n}\n";
|
|
5
|
+
const styles = "/*\n[ WJ Tab Group ]\n*/\n\n:host {\n --wje-tab-top: 0;\n --wje-tab-start: 0;\n --wje-tab-end: 0;\n --wje-tab-bottom: 0;\n width: 100%;\n}\n.native-tab-group {\n display: flex;\n flex-direction: column;\n\n overflow: hidden;\n position: relative;\n}\n\n.native-tab-group > header {\n display: flex;\n flex-direction: column;\n\n & > nav {\n display: flex;\n align-items: center;\n }\n}\n\n.native-tab-group > section {\n width: 100%;\n\n & > article {\n scroll-snap-align: start;\n overflow-y: auto;\n overscroll-behavior-y: contain;\n }\n}\n\n/*TOP*/\n:host([variant='top']) {\n --wje-tab-top: auto !important;\n --wje-tab-writing-mode: horizontal-tb;\n .native-tab-group {\n flex-direction: column;\n }\n nav {\n border-bottom: 1px solid var(--wje-border-color);\n }\n}\n\n/*START*/\n:host([variant='start']) {\n --wje-tab-start: auto !important;\n --wje-tab-writing-mode: vertical-rl;\n .native-tab-group {\n flex-direction: row;\n }\n nav {\n flex-direction: column;\n border-right: 1px solid var(--wje-border-color);\n }\n}\n\n/*END*/\n:host([variant='end']) {\n --wje-tab-writing-mode: vertical-rl;\n .native-tab-group {\n flex-direction: row-reverse;\n }\n nav {\n flex-direction: column;\n border-left: 1px solid var(--wje-border-color);\n }\n}\n\n/*BOTTOM*/\n:host([variant='bottom']) {\n --wje-tab-bottom: auto !important;\n --wje-tab-writing-mode: horizontal-tb;\n .native-tab-group {\n flex-direction: column-reverse;\n }\n nav {\n border-top: 1px solid var(--wje-border-color);\n }\n}\n\n.dropdown-active {\n wje-button{\n &::part(native) {\n color: var(--wje-color-primary-8);\n }\n }\n}";
|
|
6
6
|
class TabGroup extends WJElement {
|
|
7
7
|
/**
|
|
8
8
|
* Creates an instance of TabGroup.
|
|
@@ -60,12 +60,32 @@ class TabGroup extends WJElement {
|
|
|
60
60
|
let slot = document.createElement("slot");
|
|
61
61
|
let slotNav = document.createElement("slot");
|
|
62
62
|
slotNav.setAttribute("name", "nav");
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
let icon = document.createElement("wje-icon");
|
|
64
|
+
icon.setAttribute("name", "dots");
|
|
65
|
+
let button = document.createElement("wje-button");
|
|
66
|
+
button.setAttribute("slot", "trigger");
|
|
67
|
+
button.setAttribute("fill", "link");
|
|
68
|
+
let menu = document.createElement("wje-menu");
|
|
69
|
+
menu.setAttribute("variant", "context");
|
|
70
|
+
let slotMore = document.createElement("slot");
|
|
71
|
+
slotMore.setAttribute("name", "more");
|
|
72
|
+
let moreDropdown = document.createElement("wje-dropdown");
|
|
73
|
+
moreDropdown.setAttribute("placement", "bottom-end");
|
|
74
|
+
moreDropdown.setAttribute("collapsible", "");
|
|
75
|
+
moreDropdown.classList.add("more-tabs");
|
|
76
|
+
button.append(icon);
|
|
77
|
+
menu.append(slotMore);
|
|
78
|
+
moreDropdown.append(button);
|
|
79
|
+
moreDropdown.append(menu);
|
|
80
|
+
header.append(nav);
|
|
81
|
+
nav.append(slotNav);
|
|
82
|
+
nav.append(moreDropdown);
|
|
83
|
+
section.append(slot);
|
|
84
|
+
native.append(header);
|
|
85
|
+
native.append(section);
|
|
86
|
+
fragment.append(native);
|
|
87
|
+
this.nav = nav;
|
|
88
|
+
this.moreDropdown = moreDropdown;
|
|
69
89
|
return fragment;
|
|
70
90
|
}
|
|
71
91
|
/**
|
|
@@ -77,18 +97,22 @@ class TabGroup extends WJElement {
|
|
|
77
97
|
this.setActiveTab(activeTabName);
|
|
78
98
|
this.addEventListener("wje-tab:change", (e) => {
|
|
79
99
|
if (e.detail.context.hasAttribute("disabled")) return;
|
|
100
|
+
console.log("tab change");
|
|
80
101
|
this.setActiveTab(e.detail.context.panel);
|
|
81
102
|
});
|
|
103
|
+
this.checkOverflow = this.checkOverflow.bind(this);
|
|
104
|
+
window.addEventListener("resize", this.checkOverflow);
|
|
105
|
+
requestAnimationFrame(() => this.checkOverflow());
|
|
82
106
|
}
|
|
83
107
|
/**
|
|
84
108
|
* Removes the active attribute from all tabs and panels.
|
|
85
109
|
*/
|
|
86
110
|
removeActiveTab() {
|
|
87
111
|
this.getPanelAll().forEach((el) => {
|
|
88
|
-
el.
|
|
112
|
+
el.classList.remove("active");
|
|
89
113
|
});
|
|
90
114
|
this.getTabAll().forEach((el) => {
|
|
91
|
-
el.
|
|
115
|
+
el.classList.remove("active");
|
|
92
116
|
});
|
|
93
117
|
}
|
|
94
118
|
/**
|
|
@@ -96,16 +120,19 @@ class TabGroup extends WJElement {
|
|
|
96
120
|
* @param {string} tab The name of the tab to set as active.
|
|
97
121
|
*/
|
|
98
122
|
setActiveTab(tab) {
|
|
123
|
+
var _a;
|
|
99
124
|
this.removeActiveTab();
|
|
100
|
-
this.querySelector(`[panel="${tab}"]`)
|
|
101
|
-
|
|
125
|
+
const el = this.querySelector(`[panel="${tab}"]`);
|
|
126
|
+
el == null ? void 0 : el.classList.add("active");
|
|
127
|
+
(_a = this.querySelector(`[name="${tab}"]`)) == null ? void 0 : _a.classList.add("active");
|
|
128
|
+
this.dropdownActive(el);
|
|
102
129
|
}
|
|
103
130
|
/**
|
|
104
131
|
* Returns the currently active tab.
|
|
105
132
|
* @returns {Element|null} The active tab, or null if no tab is active.
|
|
106
133
|
*/
|
|
107
134
|
getActiveTab() {
|
|
108
|
-
let activeTabs = Array.from(this.querySelectorAll("wje-tab
|
|
135
|
+
let activeTabs = Array.from(this.querySelectorAll("wje-tab.active"));
|
|
109
136
|
return activeTabs.length > 0 ? activeTabs : null;
|
|
110
137
|
}
|
|
111
138
|
/**
|
|
@@ -129,6 +156,39 @@ class TabGroup extends WJElement {
|
|
|
129
156
|
getPanelAllName() {
|
|
130
157
|
return this.getPanelAll().map((el) => el.getAttribute("name"));
|
|
131
158
|
}
|
|
159
|
+
toggleMoreVisibility() {
|
|
160
|
+
const hasTabsInMore = this.querySelector('wje-tab[slot="more"]');
|
|
161
|
+
this.moreDropdown.hidden = !hasTabsInMore;
|
|
162
|
+
}
|
|
163
|
+
checkOverflow() {
|
|
164
|
+
const nav = this.nav;
|
|
165
|
+
const moreBtn = this.moreDropdown;
|
|
166
|
+
const moreWidth = moreBtn.offsetWidth || 48;
|
|
167
|
+
const tabs = Array.from(this.querySelectorAll("wje-tab"));
|
|
168
|
+
tabs.forEach((tab) => tab.setAttribute("slot", "nav"));
|
|
169
|
+
requestAnimationFrame(() => {
|
|
170
|
+
const navRight = nav.getBoundingClientRect().right;
|
|
171
|
+
let overflowStarted = false;
|
|
172
|
+
for (const tab of tabs) {
|
|
173
|
+
const tabRect = tab.getBoundingClientRect();
|
|
174
|
+
const fits = tabRect.right + moreWidth <= navRight;
|
|
175
|
+
if (!fits || overflowStarted) {
|
|
176
|
+
tab.setAttribute("slot", "more");
|
|
177
|
+
this.dropdownActive(tab);
|
|
178
|
+
overflowStarted = true;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
this.toggleMoreVisibility();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
dropdownActive(el) {
|
|
185
|
+
if (el.classList.contains("active")) {
|
|
186
|
+
if (el.getAttribute("slot") === "more")
|
|
187
|
+
this.moreDropdown.classList.add("dropdown-active");
|
|
188
|
+
else
|
|
189
|
+
this.moreDropdown.classList.remove("dropdown-active");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
132
192
|
}
|
|
133
193
|
TabGroup.define("wje-tab-group", TabGroup);
|
|
134
194
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-tab-group.js","sources":["../packages/wje-tab-group/tab-group.element.js","../packages/wje-tab-group/tab-group.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `TabGroup` is a custom web component that represents a group of tabs.\n * @summary This element represents a group of tabs.\n * @documentation https://elements.webjet.sk/components/tab-group\n * @status stable\n * @augments WJElement\n * @slot - The default slot for the tab group.\n * @slot nav - Slot for the navigation of the tab group.\n * @cssproperty [--wje-tab-group-padding=1rem] - Specifies the padding inside the tab group. This property defines the space between the content of the tab group and its outer boundary. Accepts any valid CSS length unit (e.g., `px`, `rem`, `em`, `%`).\n * @tag wje-tab-group\n */\n\nexport default class TabGroup extends WJElement {\n /**\n * Creates an instance of TabGroup.\n * @class\n */\n constructor() {\n super();\n }\n\n className = 'TabGroup';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Sets up the event listeners before the component is drawn.\n * This method is called before the component is drawn.\n * It is used to set up event listeners.\n */\n beforeDraw() {\n let activeTabName = location.hash.replace('#', '');\n\n // skontrolujeme ci sa nachadza v paneloch\n if (this.getPanelAllName().includes(activeTabName)) {\n // window.addEventListener('hashchange', (e) => {\n // this.setActiveTab(activeTabName);\n // });\n\n window.addEventListener('load', (e) => {\n this.setActiveTab(activeTabName);\n });\n }\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-tab-group');\n\n let header = document.createElement('header');\n header.setAttribute('part', 'tabs');\n header.classList.add('scroll-snap-x');\n\n let nav = document.createElement('nav');\n\n let section = document.createElement('section');\n section.setAttribute('part', 'panels');\n\n let slot = document.createElement('slot');\n\n let slotNav = document.createElement('slot');\n slotNav.setAttribute('name', 'nav');\n\n header.appendChild(nav);\n nav.appendChild(slotNav);\n section.appendChild(slot);\n\n native.appendChild(header);\n native.appendChild(section);\n\n fragment.appendChild(native);\n\n return fragment;\n }\n\n /**\n * Sets up the event listeners after the component is drawn.\n */\n afterDraw() {\n let activeTab = this.getActiveTab();\n let activeTabName = activeTab ? activeTab[0].panel : this.getTabAll()[0].panel;\n\n this.setActiveTab(activeTabName);\n\n this.addEventListener('wje-tab:change', (e) => {\n if (e.detail.context.hasAttribute('disabled')) return;\n\n this.setActiveTab(e.detail.context.panel);\n });\n }\n\n /**\n * Removes the active attribute from all tabs and panels.\n */\n removeActiveTab() {\n this.getPanelAll().forEach((el) => {\n el.removeAttribute('active');\n });\n\n this.getTabAll().forEach((el) => {\n el.removeAttribute('active');\n });\n }\n\n /**\n * Sets the active tab and panel.\n * @param {string} tab The name of the tab to set as active.\n */\n setActiveTab(tab) {\n this.removeActiveTab();\n this.querySelector(`[panel=\"${tab}\"]`).setAttribute('active', '');\n this.querySelector(`[name=\"${tab}\"]`).setAttribute('active', '');\n }\n\n /**\n * Returns the currently active tab.\n * @returns {Element|null} The active tab, or null if no tab is active.\n */\n getActiveTab() {\n let activeTabs = Array.from(this.querySelectorAll('wje-tab[active]'));\n return activeTabs.length > 0 ? activeTabs : null;\n }\n\n /**\n * Returns all tabs.\n * @returns {Array<Element>} An array of all tabs.\n */\n getTabAll() {\n return this.context.querySelector('[name=\"nav\"]').assignedElements();\n }\n\n /**\n * Returns all panels.\n * @returns {Array<Element>} An array of all panels.\n */\n getPanelAll() {\n return Array.from(this.querySelectorAll('wje-tab-panel'));\n }\n\n /**\n * Returns the names of all tabs.\n * @returns {Array<string>} An array of all tab names.\n */\n getPanelAllName() {\n return this.getPanelAll().map((el) => el.getAttribute('name'));\n }\n}\n","import TabGroup from './tab-group.element.js';\n\nexport default TabGroup;\n\nTabGroup.define('wje-tab-group', TabGroup);\n"],"names":[],"mappings":";;;;;AAee,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAK5C,cAAc;AACV,UAAO;AAGX,qCAAY;AAAA,EAFhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASI,WAAW,gBAAgB;AACvB,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKI,kBAAkB;AACd,SAAK,eAAe;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,aAAa;AACT,QAAI,gBAAgB,SAAS,KAAK,QAAQ,KAAK,EAAE;AAGjD,QAAI,KAAK,gBAAe,EAAG,SAAS,aAAa,GAAG;AAKhD,aAAO,iBAAiB,QAAQ,CAAC,MAAM;AACnC,aAAK,aAAa,aAAa;AAAA,MAC/C,CAAa;AAAA,IACb;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASI,KAAK,SAAS,OAAO,QAAQ;AACzB,QAAI,WAAW,SAAS,uBAAwB;AAEhD,QAAI,SAAS,SAAS,cAAc,KAAK;AACzC,WAAO,aAAa,QAAQ,QAAQ;AACpC,WAAO,UAAU,IAAI,kBAAkB;AAEvC,QAAI,SAAS,SAAS,cAAc,QAAQ;AAC5C,WA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A,EAMI,eAAe;AACX,QAAI,aAAa,MAAM,KAAK,KAAK,iBAAiB,iBAAiB,CAAC;AACpE,WAAO,WAAW,SAAS,IAAI,aAAa;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,YAAY;AACR,WAAO,KAAK,QAAQ,cAAc,cAAc,EAAE,iBAAkB;AAAA,EAC5E;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,cAAc;AACV,WAAO,MAAM,KAAK,KAAK,iBAAiB,eAAe,CAAC;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,kBAAkB;AACd,WAAO,KAAK,YAAW,EAAG,IAAI,CAAC,OAAO,GAAG,aAAa,MAAM,CAAC;AAAA,EACrE;AACA;ACzKA,SAAS,OAAO,iBAAiB,QAAQ;"}
|
|
1
|
+
{"version":3,"file":"wje-tab-group.js","sources":["../packages/wje-tab-group/tab-group.element.js","../packages/wje-tab-group/tab-group.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `TabGroup` is a custom web component that represents a group of tabs.\n * @summary This element represents a group of tabs.\n * @documentation https://elements.webjet.sk/components/tab-group\n * @status stable\n * @augments WJElement\n * @slot - The default slot for the tab group.\n * @slot nav - Slot for the navigation of the tab group.\n * @cssproperty [--wje-tab-group-padding=1rem] - Specifies the padding inside the tab group. This property defines the space between the content of the tab group and its outer boundary. Accepts any valid CSS length unit (e.g., `px`, `rem`, `em`, `%`).\n * @tag wje-tab-group\n */\n\nexport default class TabGroup extends WJElement {\n /**\n * Creates an instance of TabGroup.\n * @class\n */\n constructor() {\n super();\n }\n\n className = 'TabGroup';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Sets up the event listeners before the component is drawn.\n * This method is called before the component is drawn.\n * It is used to set up event listeners.\n */\n beforeDraw() {\n let activeTabName = location.hash.replace('#', '');\n\n // skontrolujeme ci sa nachadza v paneloch\n if (this.getPanelAllName().includes(activeTabName)) {\n // window.addEventListener('hashchange', (e) => {\n // console.log('hashchange');\n // this.setActiveTab(activeTabName);\n // });\n\n window.addEventListener('load', (e) => {\n this.setActiveTab(activeTabName);\n });\n }\n }\n\n /**\n * Draws the component.\n * @param {object} context The context for drawing.\n * @param {object} store The store for drawing.\n * @param {object} params The parameters for drawing.\n * @returns {DocumentFragment}\n */\n draw(context, store, params) {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-tab-group');\n\n let header = document.createElement('header');\n header.setAttribute('part', 'tabs');\n header.classList.add('scroll-snap-x');\n\n let nav = document.createElement('nav');\n\n let section = document.createElement('section');\n section.setAttribute('part', 'panels');\n\n let slot = document.createElement('slot');\n\n let slotNav = document.createElement('slot');\n slotNav.setAttribute('name', 'nav');\n\n let icon = document.createElement('wje-icon');\n icon.setAttribute('name', 'dots');\n\n let button = document.createElement('wje-button');\n button.setAttribute('slot', 'trigger');\n button.setAttribute('fill', 'link');\n\n let menu = document.createElement('wje-menu');\n menu.setAttribute('variant', 'context');\n\n let slotMore = document.createElement('slot');\n slotMore.setAttribute('name', 'more');\n\n let moreDropdown = document.createElement('wje-dropdown');\n moreDropdown.setAttribute('placement', 'bottom-end');\n moreDropdown.setAttribute('collapsible', '');\n moreDropdown.classList.add('more-tabs');\n\n button.append(icon);\n\n menu.append(slotMore);\n\n moreDropdown.append(button);\n moreDropdown.append(menu);\n\n header.append(nav);\n\n nav.append(slotNav);\n nav.append(moreDropdown);\n\n section.append(slot);\n\n native.append(header);\n native.append(section);\n\n fragment.append(native);\n\n this.nav = nav;\n this.moreDropdown = moreDropdown;\n\n return fragment;\n }\n\n /**\n * Sets up the event listeners after the component is drawn.\n */\n afterDraw() {\n let activeTab = this.getActiveTab();\n let activeTabName = activeTab ? activeTab[0].panel : this.getTabAll()[0].panel;\n\n this.setActiveTab(activeTabName);\n\n this.addEventListener('wje-tab:change', (e) => {\n if (e.detail.context.hasAttribute('disabled')) return;\n console.log('tab change');\n this.setActiveTab(e.detail.context.panel);\n });\n\n // this.checkOverflow = this.checkOverflow.bind(this);\n // window.addEventListener('resize', this.checkOverflow);\n\n // this.setupTabObserver();\n // this.toggleMoreVisibility();\n\n this.checkOverflow = this.checkOverflow.bind(this);\n\n window.addEventListener('resize', this.checkOverflow);\n\n requestAnimationFrame(() => this.checkOverflow());\n }\n\n /**\n * Removes the active attribute from all tabs and panels.\n */\n removeActiveTab() {\n this.getPanelAll().forEach((el) => {\n el.classList.remove('active');\n });\n\n this.getTabAll().forEach((el) => {\n el.classList.remove('active');\n });\n }\n\n /**\n * Sets the active tab and panel.\n * @param {string} tab The name of the tab to set as active.\n */\n setActiveTab(tab) {\n this.removeActiveTab();\n const el = this.querySelector(`[panel=\"${tab}\"]`)\n el?.classList.add('active');\n this.querySelector(`[name=\"${tab}\"]`)?.classList.add('active');\n\n this.dropdownActive(el);\n }\n\n /**\n * Returns the currently active tab.\n * @returns {Element|null} The active tab, or null if no tab is active.\n */\n getActiveTab() {\n let activeTabs = Array.from(this.querySelectorAll('wje-tab.active'));\n return activeTabs.length > 0 ? activeTabs : null;\n }\n\n /**\n * Returns all tabs.\n * @returns {Array<Element>} An array of all tabs.\n */\n getTabAll() {\n return this.context.querySelector('[name=\"nav\"]').assignedElements();\n }\n\n /**\n * Returns all panels.\n * @returns {Array<Element>} An array of all panels.\n */\n getPanelAll() {\n return Array.from(this.querySelectorAll('wje-tab-panel'));\n }\n\n /**\n * Returns the names of all tabs.\n * @returns {Array<string>} An array of all tab names.\n */\n getPanelAllName() {\n return this.getPanelAll().map((el) => el.getAttribute('name'));\n }\n\n toggleMoreVisibility() {\n const hasTabsInMore = this.querySelector('wje-tab[slot=\"more\"]');\n this.moreDropdown.hidden = !hasTabsInMore;\n }\n\n checkOverflow() {\n const nav = this.nav;\n const moreBtn = this.moreDropdown;\n const moreWidth = moreBtn.offsetWidth || 48; // fallback ak ešte nie je vykreslený\n\n const tabs = Array.from(this.querySelectorAll('wje-tab'));\n\n // Reset: presunieme všetky taby naspäť do nav slotu\n tabs.forEach(tab => tab.setAttribute('slot', 'nav'));\n\n // Vykreslíme nanovo, aby sa more button správne umiestnil\n requestAnimationFrame(() => {\n const navRight = nav.getBoundingClientRect().right;\n let overflowStarted = false;\n\n for (const tab of tabs) {\n const tabRect = tab.getBoundingClientRect();\n\n // Ak by pretekal vrátane rezervy na more, presunieme ho\n const fits = tabRect.right + moreWidth <= navRight;\n\n if (!fits || overflowStarted) {\n tab.setAttribute('slot', 'more');\n this.dropdownActive(tab);\n overflowStarted = true;\n }\n }\n\n this.toggleMoreVisibility();\n });\n }\n\n dropdownActive(el) {\n if(el.classList.contains('active')) {\n if(el.getAttribute('slot') === 'more')\n this.moreDropdown.classList.add('dropdown-active');\n else\n this.moreDropdown.classList.remove('dropdown-active');\n }\n }\n}\n","import TabGroup from './tab-group.element.js';\n\nexport default TabGroup;\n\nTabGroup.define('wje-tab-group', TabGroup);\n"],"names":[],"mappings":";;;;;AAee,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAK5C,cAAc;AACV,UAAO;AAGX,qCAAY;AAAA,EAFhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASI,WAAW,gBAAgB;AACvB,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKI,kBAAkB;AACd,SAAK,eAAe;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOI,aAAa;AACT,QAAI,gBAAgB,SAAS,KAAK,QAAQ,KAAK,EAAE;AAGjD,QAAI,KAAK,gBAAe,EAAG,SAAS,aAAa,GAAG;AAMhD,aAAO,iBAAiB,QAAQ,CAAC,MAAM;AACnC,aAAK,aAAa,aAAa;AAAA,MAC/C,CAAa;AAAA,IACb;AAAA,EACA;A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panel.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 from "./wje-element.js";
|
|
5
|
-
const styles = "/*\n[ WJ Tab Panel ]\n*/\n\n:host {\n display: none;\n flex-wrap: wrap;\n align-items: center;\n padding: 1rem;\n}\n\n:host(
|
|
5
|
+
const styles = "/*\n[ WJ Tab Panel ]\n*/\n\n:host {\n display: none;\n flex-wrap: wrap;\n align-items: center;\n padding: 1rem;\n}\n\n:host(.active) {\n display: block;\n}\n";
|
|
6
6
|
class TabPanel extends WJElement {
|
|
7
7
|
/**
|
|
8
8
|
* Creates an instance of TabPanel.
|
package/dist/wje-tab.js
CHANGED
|
@@ -2,7 +2,113 @@ 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
|
-
|
|
5
|
+
import { b as bindRouterLinks } from "./router-links-CJnOdbas.js";
|
|
6
|
+
const styles = `/*
|
|
7
|
+
[ WJ Tab ]
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
:host(:not([slot="more"])) {
|
|
11
|
+
display: block;
|
|
12
|
+
position: relative;
|
|
13
|
+
.native-tab {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
white-space: nowrap;
|
|
17
|
+
font-family: var(--wje-tab-font-family);
|
|
18
|
+
font-size: var(--wje-tab-font-size);
|
|
19
|
+
letter-spacing: var(--wje-tab-letter-spacing);
|
|
20
|
+
text-transform: var(--wje-tab-text-transfrom);
|
|
21
|
+
font-weight: var(--wje-tab-font-weight);
|
|
22
|
+
text-decoration: none;
|
|
23
|
+
padding-inline: var(--wje-tab-padding-inline);
|
|
24
|
+
padding-top: var(--wje-tab-padding-top);
|
|
25
|
+
padding-bottom: var(--wje-tab-padding-bottom);
|
|
26
|
+
border-radius: var(--wje-tab-border-radius);
|
|
27
|
+
color: var(--wje-color);
|
|
28
|
+
line-height: var(--wje-tab-line-height);
|
|
29
|
+
& > svg {
|
|
30
|
+
inline-size: 1.5em;
|
|
31
|
+
pointer-events: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:hover {
|
|
35
|
+
background: var(--wje-tab-color-hover);
|
|
36
|
+
&:after {
|
|
37
|
+
display: block;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:after {
|
|
42
|
+
content: ' ';
|
|
43
|
+
display: none;
|
|
44
|
+
block-size: 0.15rem;
|
|
45
|
+
writing-mode: var(--wje-tab-writing-mode);
|
|
46
|
+
background: var(--wje-tab-color-active);
|
|
47
|
+
position: absolute;
|
|
48
|
+
bottom: var(--wje-tab-bottom);
|
|
49
|
+
left: var(--wje-tab-start);
|
|
50
|
+
right: var(--wje-tab-end);
|
|
51
|
+
top: var(--wje-tab-top);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
:host([slot="more"]) {
|
|
57
|
+
--wje-menu-item-safe-triangle-cursor-x: 0;
|
|
58
|
+
--wje-menu-item-safe-triangle-cursor-y: 0;
|
|
59
|
+
--wje-menu-item-safe-triangle-submenu-start-x: 0;
|
|
60
|
+
--wje-menu-item-safe-triangle-submenu-start-y: 0;
|
|
61
|
+
--wje-menu-item-safe-triangle-submenu-end-x: 0;
|
|
62
|
+
--wje-menu-item-safe-triangle-submenu-end-y: 0;
|
|
63
|
+
|
|
64
|
+
display: block;
|
|
65
|
+
.native-tab {
|
|
66
|
+
background: var(--wje-menu-item-background);
|
|
67
|
+
position: relative;
|
|
68
|
+
display: block;
|
|
69
|
+
flex-wrap: nowrap;
|
|
70
|
+
align-items: center;
|
|
71
|
+
justify-content: center;
|
|
72
|
+
color: var(--wje-menu-item-color);
|
|
73
|
+
padding-top: var(--wje-menu-item-padding-top);
|
|
74
|
+
padding-bottom: var(--wje-menu-item-padding-bottom);
|
|
75
|
+
padding-inline: var(--wje-spacing-large);
|
|
76
|
+
transition: var(--wje-transition-fast) fill;
|
|
77
|
+
user-select: none;
|
|
78
|
+
white-space: nowrap;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
text-decoration: none;
|
|
81
|
+
|
|
82
|
+
&:hover {
|
|
83
|
+
color: var(--wje-menu-item-color-hover);
|
|
84
|
+
background: var(--wje-menu-item-background-hover);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&:focus {
|
|
88
|
+
color: var(--wje-menu-item-color-focus);
|
|
89
|
+
background: var(--wje-menu-item-background-focus);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&:active {
|
|
93
|
+
color: var(--wje-menu-item-color-active);
|
|
94
|
+
background: var(--wje-menu-item-background-active);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
:host([disabled]) a {
|
|
100
|
+
opacity: 0.5;
|
|
101
|
+
cursor: not-allowed;
|
|
102
|
+
background: inherit;
|
|
103
|
+
&:after {
|
|
104
|
+
display: none;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
:host(:not([slot="more"]).active) a:after {
|
|
109
|
+
display: block;
|
|
110
|
+
}
|
|
111
|
+
`;
|
|
6
112
|
class Tab extends WJElement {
|
|
7
113
|
/**
|
|
8
114
|
* Creates an instance of Tab.
|
|
@@ -14,6 +120,36 @@ class Tab extends WJElement {
|
|
|
14
120
|
*/
|
|
15
121
|
__publicField(this, "className", "Tab");
|
|
16
122
|
this.last = false;
|
|
123
|
+
this._hasPanel = false;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Sets the panel attribute to the specified value.
|
|
127
|
+
* @param {string} value The value to set for the panel attribute.
|
|
128
|
+
*/
|
|
129
|
+
set panel(value) {
|
|
130
|
+
this.setAttribute("panel", value);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves the value of the 'panel' attribute of the element.
|
|
134
|
+
* @returns {string|null} Returns the 'panel' attribute value if it exists; otherwise, returns null.
|
|
135
|
+
*/
|
|
136
|
+
get panel() {
|
|
137
|
+
return this.getAttribute("panel") || null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Sets the value of the 'route' attribute for the current object.
|
|
141
|
+
* @param {string} value The new value to set for the 'route' attribute.
|
|
142
|
+
*/
|
|
143
|
+
set route(value) {
|
|
144
|
+
this.setAttribute("route", value);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Retrieves the value of the 'route' attribute.
|
|
148
|
+
* If the 'route' attribute is not set, it returns null.
|
|
149
|
+
* @returns {string|null} The value of the 'route' attribute or null if not set.
|
|
150
|
+
*/
|
|
151
|
+
get route() {
|
|
152
|
+
return this.getAttribute("route") || null;
|
|
17
153
|
}
|
|
18
154
|
/**
|
|
19
155
|
* Returns the CSS styles for the component.
|
|
@@ -28,6 +164,7 @@ class Tab extends WJElement {
|
|
|
28
164
|
*/
|
|
29
165
|
setupAttributes() {
|
|
30
166
|
this.isShadowRoot = "open";
|
|
167
|
+
this.setAttribute("active-class", "active");
|
|
31
168
|
}
|
|
32
169
|
/**
|
|
33
170
|
* Draws the component for the tab.
|
|
@@ -49,8 +186,16 @@ class Tab extends WJElement {
|
|
|
49
186
|
* // @fires wje-tab:change - Dispatched when the component is clicked, indicating a tab change.
|
|
50
187
|
*/
|
|
51
188
|
afterDraw() {
|
|
189
|
+
this.unbindRouterLinks = bindRouterLinks(this.parentElement, { selector: false });
|
|
52
190
|
event.addListener(this, "click", "wje-tab:change");
|
|
53
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Cleans up before the component is disconnected.
|
|
194
|
+
*/
|
|
195
|
+
beforeDisconnect() {
|
|
196
|
+
var _a;
|
|
197
|
+
(_a = this.unbindRouterLinks) == null ? void 0 : _a.call(this);
|
|
198
|
+
}
|
|
54
199
|
}
|
|
55
200
|
Tab.define("wje-tab", Tab);
|
|
56
201
|
export {
|
package/dist/wje-tab.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-tab.js","sources":["../packages/wje-tab/tab.element.js","../packages/wje-tab/tab.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Tab` is a custom web component that represents a tab.\n * @summary This element represents a tab.\n * @documentation https://elements.webjet.sk/components/tab\n * @status stable\n * @augments {WJElement}\n * @cssproperty [--wje-tab-text-transform=uppercase] - The text transformation for the tab (e.g., uppercase, lowercase).\n * @cssproperty [--wje-tab-font-weight=500] - The font weight of the tab text.\n * @cssproperty [--wje-tab-letter-spacing=0.06em] - The letter spacing of the tab text.\n * @cssproperty [--wje-tab-padding-inline=1rem] - The horizontal padding of the tab.\n * @cssproperty [--wje-tab-padding-top=.75rem] - The top padding of the tab text.\n * @cssproperty [--wje-tab-padding-bottom=.75rem] - The bottom padding of the tab text.\n * @cssproperty [--wje-tab-color-active=var(--wje-color-primary-11)] - The text color of the active tab.\n * @cssproperty [--wje-tab-color-hover=var(--wje-color-primary-1)] - The text color of the tab when hovered.\n * //@fires wje-tab:change - Dispatched when the tab is changed.\n * @tag wje-tab\n */\nexport default class Tab extends WJElement {\n /**\n * Creates an instance of Tab.\n */\n constructor() {\n super();\n\n /**\n * Indicates whether this is the last tab.\n * @type {boolean}\n */\n this.last = false;\n }\n\n /**\n * The class name for the component.\n */\n className = 'Tab';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the component for the tab.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let slot = document.createElement('slot');\n\n let a = document.createElement('a');\n a.setAttribute('href', '#' + this.panel);\n a.setAttribute('part', 'native');\n a.classList.add('native-tab');\n a.appendChild(slot);\n\n fragment.appendChild(a);\n\n return fragment;\n }\n\n /**\n * Sets up event listeners after the component is rendered.\n * // @fires wje-tab:change - Dispatched when the component is clicked, indicating a tab change.\n */\n afterDraw() {\n event.addListener(this, 'click', 'wje-tab:change');\n }\n}\n","import Tab from './tab.element.js';\n\nexport default Tab;\n\nTab.define('wje-tab', Tab);\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wje-tab.js","sources":["../packages/wje-tab/tab.element.js","../packages/wje-tab/tab.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport { bindRouterLinks } from 'slick-router/middlewares/router-links.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `Tab` is a custom web component that represents a tab.\n * @summary This element represents a tab.\n * @documentation https://elements.webjet.sk/components/tab\n * @status stable\n * @augments {WJElement}\n * @cssproperty [--wje-tab-text-transform=uppercase] - The text transformation for the tab (e.g., uppercase, lowercase).\n * @cssproperty [--wje-tab-font-weight=500] - The font weight of the tab text.\n * @cssproperty [--wje-tab-letter-spacing=0.06em] - The letter spacing of the tab text.\n * @cssproperty [--wje-tab-padding-inline=1rem] - The horizontal padding of the tab.\n * @cssproperty [--wje-tab-padding-top=.75rem] - The top padding of the tab text.\n * @cssproperty [--wje-tab-padding-bottom=.75rem] - The bottom padding of the tab text.\n * @cssproperty [--wje-tab-color-active=var(--wje-color-primary-11)] - The text color of the active tab.\n * @cssproperty [--wje-tab-color-hover=var(--wje-color-primary-1)] - The text color of the tab when hovered.\n * //@fires wje-tab:change - Dispatched when the tab is changed.\n * @tag wje-tab\n */\nexport default class Tab extends WJElement {\n /**\n * Creates an instance of Tab.\n */\n constructor() {\n super();\n\n /**\n * Indicates whether this is the last tab.\n * @type {boolean}\n */\n this.last = false;\n this._hasPanel = false;\n }\n\n /**\n * Sets the panel attribute to the specified value.\n * @param {string} value The value to set for the panel attribute.\n */\n set panel(value) {\n this.setAttribute('panel', value);\n }\n\n /**\n * Retrieves the value of the 'panel' attribute of the element.\n * @returns {string|null} Returns the 'panel' attribute value if it exists; otherwise, returns null.\n */\n get panel() {\n return this.getAttribute('panel') || null;\n }\n\n /**\n * Sets the value of the 'route' attribute for the current object.\n * @param {string} value The new value to set for the 'route' attribute.\n */\n set route(value) {\n this.setAttribute('route', value);\n }\n\n /**\n * Retrieves the value of the 'route' attribute.\n * If the 'route' attribute is not set, it returns null.\n * @returns {string|null} The value of the 'route' attribute or null if not set.\n */\n get route() {\n return this.getAttribute('route') || null;\n }\n\n /**\n * The class name for the component.\n */\n className = 'Tab';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n this.setAttribute('active-class', 'active');\n }\n\n /**\n * Draws the component for the tab.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let slot = document.createElement('slot');\n\n let a = document.createElement('a');\n a.setAttribute('href', '#' + this.panel);\n a.setAttribute('part', 'native');\n a.classList.add('native-tab');\n a.appendChild(slot);\n\n fragment.appendChild(a);\n\n return fragment;\n }\n\n /**\n * Sets up event listeners after the component is rendered.\n * // @fires wje-tab:change - Dispatched when the component is clicked, indicating a tab change.\n */\n afterDraw() {\n this.unbindRouterLinks = bindRouterLinks(this.parentElement, { selector: false });\n event.addListener(this, 'click', 'wje-tab:change');\n }\n\n /**\n * Cleans up before the component is disconnected.\n */\n beforeDisconnect() {\n this.unbindRouterLinks?.();\n }\n}\n","import Tab from './tab.element.js';\n\nexport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;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,YAAY;AACR,SAAK,oBAAoB,gBAAgB,KAAK,eAAe,EAAE,UAAU,OAAO;AAChF,UAAM,YAAY,MAAM,SAAS,gBAAgB;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA,EAKI,mBAAmB;;AACf,eAAK,sBAAL;AAAA,EACR;AACA;AC1HA,IAAI,OAAO,WAAW,GAAG;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wj-elements",
|
|
3
3
|
"description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.161",
|
|
5
5
|
"homepage": "https://github.com/lencys/wj-elements",
|
|
6
6
|
"author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
|
|
7
7
|
"license": "MIT",
|