wj-elements 0.7.7 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/dist/animations.js +28 -51
  2. package/dist/animations.js.map +1 -1
  3. package/dist/base-path.js +19 -31
  4. package/dist/base-path.js.map +1 -1
  5. package/dist/custom-elements.json +11504 -11499
  6. package/dist/dark.css +1 -302
  7. package/dist/date.js +16 -36
  8. package/dist/date.js.map +1 -1
  9. package/dist/element-utils.js +20 -81
  10. package/dist/element-utils.js.map +1 -1
  11. package/dist/event.js +49 -165
  12. package/dist/event.js.map +1 -1
  13. package/dist/form-associated-element-BjeJn7j8.js +101 -0
  14. package/dist/{form-associated-element-DEQ4y-jn.js.map → form-associated-element-BjeJn7j8.js.map} +1 -1
  15. package/dist/icon-DmsqtDpL.js +102 -0
  16. package/dist/{icon-CReYMzAK.js.map → icon-DmsqtDpL.js.map} +1 -1
  17. package/dist/light.css +1 -731
  18. package/dist/localize.js +36 -111
  19. package/dist/localize.js.map +1 -1
  20. package/dist/packages/wje-accordion-item/accordion-item.element.d.ts +3 -2
  21. package/dist/permissions.js +14 -41
  22. package/dist/permissions.js.map +1 -1
  23. package/dist/popup.element-CbkhthPP.js +806 -0
  24. package/dist/{popup.element-CwXvVFK7.js.map → popup.element-CbkhthPP.js.map} +1 -1
  25. package/dist/router-links-CNsJ-elb.js +105 -0
  26. package/dist/{router-links-wjqCnncc.js.map → router-links-CNsJ-elb.js.map} +1 -1
  27. package/dist/skeleton.css +1 -197
  28. package/dist/styles.css +1 -866
  29. package/dist/universal-service.js +48 -109
  30. package/dist/universal-service.js.map +1 -1
  31. package/dist/utils.js +11 -18
  32. package/dist/utils.js.map +1 -1
  33. package/dist/web-types.json +760 -760
  34. package/dist/wje-accordion-item.js +33 -106
  35. package/dist/wje-accordion-item.js.map +1 -1
  36. package/dist/wje-accordion.js +19 -84
  37. package/dist/wje-accordion.js.map +1 -1
  38. package/dist/wje-animation.js +37 -4258
  39. package/dist/wje-animation.js.map +1 -1
  40. package/dist/wje-aside.js +9 -34
  41. package/dist/wje-aside.js.map +1 -1
  42. package/dist/wje-avatar.js +36 -126
  43. package/dist/wje-avatar.js.map +1 -1
  44. package/dist/wje-badge.js +10 -52
  45. package/dist/wje-badge.js.map +1 -1
  46. package/dist/wje-breadcrumb.js +205 -672
  47. package/dist/wje-breadcrumb.js.map +1 -1
  48. package/dist/wje-breadcrumbs.js +177 -633
  49. package/dist/wje-breadcrumbs.js.map +1 -1
  50. package/dist/wje-button-group.js +48 -153
  51. package/dist/wje-button-group.js.map +1 -1
  52. package/dist/wje-button.js +92 -413
  53. package/dist/wje-button.js.map +1 -1
  54. package/dist/wje-card-content.js +7 -30
  55. package/dist/wje-card-content.js.map +1 -1
  56. package/dist/wje-card-controls.js +7 -30
  57. package/dist/wje-card-controls.js.map +1 -1
  58. package/dist/wje-card-header.js +7 -30
  59. package/dist/wje-card-header.js.map +1 -1
  60. package/dist/wje-card-subtitle.js +7 -34
  61. package/dist/wje-card-subtitle.js.map +1 -1
  62. package/dist/wje-card-title.js +7 -34
  63. package/dist/wje-card-title.js.map +1 -1
  64. package/dist/wje-card.js +15 -71
  65. package/dist/wje-card.js.map +1 -1
  66. package/dist/wje-carousel-item.js +12 -56
  67. package/dist/wje-carousel-item.js.map +1 -1
  68. package/dist/wje-carousel.js +154 -509
  69. package/dist/wje-carousel.js.map +1 -1
  70. package/dist/wje-checkbox.js +50 -227
  71. package/dist/wje-checkbox.js.map +1 -1
  72. package/dist/wje-chip.js +43 -160
  73. package/dist/wje-chip.js.map +1 -1
  74. package/dist/wje-col.js +7 -20
  75. package/dist/wje-col.js.map +1 -1
  76. package/dist/wje-color-picker.js +445 -1464
  77. package/dist/wje-color-picker.js.map +1 -1
  78. package/dist/wje-container.js +9 -35
  79. package/dist/wje-container.js.map +1 -1
  80. package/dist/wje-copy-button.js +64 -204
  81. package/dist/wje-copy-button.js.map +1 -1
  82. package/dist/wje-dialog.js +85 -553
  83. package/dist/wje-dialog.js.map +1 -1
  84. package/dist/wje-divider.js +7 -34
  85. package/dist/wje-divider.js.map +1 -1
  86. package/dist/wje-dropdown.js +78 -305
  87. package/dist/wje-dropdown.js.map +1 -1
  88. package/dist/wje-element.js +191 -700
  89. package/dist/wje-element.js.map +1 -1
  90. package/dist/wje-file-upload-item.js +51 -156
  91. package/dist/wje-file-upload-item.js.map +1 -1
  92. package/dist/wje-file-upload.js +181 -619
  93. package/dist/wje-file-upload.js.map +1 -1
  94. package/dist/wje-footer.js +7 -31
  95. package/dist/wje-footer.js.map +1 -1
  96. package/dist/wje-form.js +7 -32
  97. package/dist/wje-form.js.map +1 -1
  98. package/dist/wje-format-digital.js +26 -118
  99. package/dist/wje-format-digital.js.map +1 -1
  100. package/dist/wje-grid.js +7 -33
  101. package/dist/wje-grid.js.map +1 -1
  102. package/dist/wje-header.js +9 -35
  103. package/dist/wje-header.js.map +1 -1
  104. package/dist/wje-icon-library.js +12 -18
  105. package/dist/wje-icon-library.js.map +1 -1
  106. package/dist/wje-icon-picker.js +65 -320
  107. package/dist/wje-icon-picker.js.map +1 -1
  108. package/dist/wje-icon.js +1 -1
  109. package/dist/wje-img-comparer.js +37 -114
  110. package/dist/wje-img-comparer.js.map +1 -1
  111. package/dist/wje-img.js +50 -198
  112. package/dist/wje-img.js.map +1 -1
  113. package/dist/wje-infinite-scroll.js +94 -346
  114. package/dist/wje-infinite-scroll.js.map +1 -1
  115. package/dist/wje-input-file.js +23 -84
  116. package/dist/wje-input-file.js.map +1 -1
  117. package/dist/wje-input.js +78 -392
  118. package/dist/wje-input.js.map +1 -1
  119. package/dist/wje-item.js +11 -64
  120. package/dist/wje-item.js.map +1 -1
  121. package/dist/wje-kanban.js +124 -401
  122. package/dist/wje-kanban.js.map +1 -1
  123. package/dist/wje-label.js +9 -32
  124. package/dist/wje-label.js.map +1 -1
  125. package/dist/wje-level-indicator.js +38 -157
  126. package/dist/wje-level-indicator.js.map +1 -1
  127. package/dist/wje-list.js +10 -40
  128. package/dist/wje-list.js.map +1 -1
  129. package/dist/wje-main.js +7 -31
  130. package/dist/wje-main.js.map +1 -1
  131. package/dist/wje-masonry.js +66 -211
  132. package/dist/wje-masonry.js.map +1 -1
  133. package/dist/wje-master.js +45 -161
  134. package/dist/wje-master.js.map +1 -1
  135. package/dist/wje-menu-button.js +10 -38
  136. package/dist/wje-menu-button.js.map +1 -1
  137. package/dist/wje-menu-item.js +127 -577
  138. package/dist/wje-menu-item.js.map +1 -1
  139. package/dist/wje-menu-label.js +9 -35
  140. package/dist/wje-menu-label.js.map +1 -1
  141. package/dist/wje-menu.js +14 -49
  142. package/dist/wje-menu.js.map +1 -1
  143. package/dist/wje-option.js +48 -279
  144. package/dist/wje-option.js.map +1 -1
  145. package/dist/wje-options.js +130 -384
  146. package/dist/wje-options.js.map +1 -1
  147. package/dist/wje-orgchart-group.js +16 -52
  148. package/dist/wje-orgchart-group.js.map +1 -1
  149. package/dist/wje-orgchart-item.js +24 -93
  150. package/dist/wje-orgchart-item.js.map +1 -1
  151. package/dist/wje-orgchart.js +18 -68
  152. package/dist/wje-orgchart.js.map +1 -1
  153. package/dist/wje-pagination.js +113 -397
  154. package/dist/wje-pagination.js.map +1 -1
  155. package/dist/wje-popup.js +3 -3
  156. package/dist/wje-popup.js.map +1 -1
  157. package/dist/wje-progress-bar.js +53 -205
  158. package/dist/wje-progress-bar.js.map +1 -1
  159. package/dist/wje-qr-code.js +398 -2980
  160. package/dist/wje-qr-code.js.map +1 -1
  161. package/dist/wje-radio-group.js +52 -190
  162. package/dist/wje-radio-group.js.map +1 -1
  163. package/dist/wje-radio.js +24 -118
  164. package/dist/wje-radio.js.map +1 -1
  165. package/dist/wje-rate.js +62 -266
  166. package/dist/wje-rate.js.map +1 -1
  167. package/dist/wje-relative-time.js +24 -99
  168. package/dist/wje-relative-time.js.map +1 -1
  169. package/dist/wje-reorder-dropzone.js +9 -31
  170. package/dist/wje-reorder-dropzone.js.map +1 -1
  171. package/dist/wje-reorder-handle.js +67 -204
  172. package/dist/wje-reorder-handle.js.map +1 -1
  173. package/dist/wje-reorder-item.js +14 -44
  174. package/dist/wje-reorder-item.js.map +1 -1
  175. package/dist/wje-reorder.js +61 -246
  176. package/dist/wje-reorder.js.map +1 -1
  177. package/dist/wje-route.js +6 -24
  178. package/dist/wje-route.js.map +1 -1
  179. package/dist/wje-router-link.js +11 -39
  180. package/dist/wje-router-link.js.map +1 -1
  181. package/dist/wje-router-outlet.js +76 -172
  182. package/dist/wje-router-outlet.js.map +1 -1
  183. package/dist/wje-routerx.js +537 -1331
  184. package/dist/wje-routerx.js.map +1 -1
  185. package/dist/wje-row.js +9 -31
  186. package/dist/wje-row.js.map +1 -1
  187. package/dist/wje-select.js +326 -1152
  188. package/dist/wje-select.js.map +1 -1
  189. package/dist/wje-slider.js +44 -225
  190. package/dist/wje-slider.js.map +1 -1
  191. package/dist/wje-sliding-container.js +295 -1319
  192. package/dist/wje-sliding-container.js.map +1 -1
  193. package/dist/wje-split-view.js +35 -121
  194. package/dist/wje-split-view.js.map +1 -1
  195. package/dist/wje-status.js +14 -45
  196. package/dist/wje-status.js.map +1 -1
  197. package/dist/wje-step.js +9 -32
  198. package/dist/wje-step.js.map +1 -1
  199. package/dist/wje-stepper.js +109 -357
  200. package/dist/wje-stepper.js.map +1 -1
  201. package/dist/wje-store.js +67 -360
  202. package/dist/wje-store.js.map +1 -1
  203. package/dist/wje-tab-group.js +85 -314
  204. package/dist/wje-tab-group.js.map +1 -1
  205. package/dist/wje-tab-panel.js +7 -28
  206. package/dist/wje-tab-panel.js.map +1 -1
  207. package/dist/wje-tab.js +21 -198
  208. package/dist/wje-tab.js.map +1 -1
  209. package/dist/wje-textarea.js +64 -264
  210. package/dist/wje-textarea.js.map +1 -1
  211. package/dist/wje-thumbnail.js +10 -51
  212. package/dist/wje-thumbnail.js.map +1 -1
  213. package/dist/wje-toast.js +127 -632
  214. package/dist/wje-toast.js.map +1 -1
  215. package/dist/wje-toggle.js +52 -177
  216. package/dist/wje-toggle.js.map +1 -1
  217. package/dist/wje-toolbar-action.js +128 -456
  218. package/dist/wje-toolbar-action.js.map +1 -1
  219. package/dist/wje-toolbar.js +75 -270
  220. package/dist/wje-toolbar.js.map +1 -1
  221. package/dist/wje-tooltip.js +50 -161
  222. package/dist/wje-tooltip.js.map +1 -1
  223. package/dist/wje-tree-item.js +70 -301
  224. package/dist/wje-tree-item.js.map +1 -1
  225. package/dist/wje-tree.js +145 -489
  226. package/dist/wje-tree.js.map +1 -1
  227. package/dist/wje-visually-hidden.js +7 -34
  228. package/dist/wje-visually-hidden.js.map +1 -1
  229. package/package.json +3 -2
  230. package/dist/form-associated-element-DEQ4y-jn.js +0 -245
  231. package/dist/icon-CReYMzAK.js +0 -245
  232. package/dist/popup.element-CwXvVFK7.js +0 -2133
  233. package/dist/router-links-wjqCnncc.js +0 -156
@@ -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\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/ADD`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'ADD',\n\t\t};\n\t};\n};\n\nconst addManyAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/ADD_MANY`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'ADD_MANY',\n\t\t};\n\t};\n};\n\nconst updateAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/UPDATE`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'UPDATE',\n\t\t};\n\t};\n};\n\nconst deleteAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/DELETE`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'DELETE',\n\t\t};\n\t};\n};\n\nconst loadAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/LOAD`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'LOAD',\n\t\t};\n\t};\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 // 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 (\n action.type.startsWith(`${stateValueName}/`) &&\n !['ADD', 'UPDATE', 'DELETE'].includes(actionType)\n ) {\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;AACrC,SAAO,CAAC,aAAa;AACpB,WAAO;AAAA,MACN,MAAM,GAAG,cAAc;AAAA,MACvB,SAAS,gBAAgB,QAAQ;AAAA,MACjC,YAAY;AAAA,IACf;AAAA,EACC;AACD;AAEA,MAAM,gBAAgB,CAAC,mBAAmB;AACzC,SAAO,CAAC,aAAa;AACpB,WAAO;AAAA,MACN,MAAM,GAAG,cAAc;AAAA,MACvB,SAAS,gBAAgB,QAAQ;AAAA,MACjC,YAAY;AAAA,IACf;AAAA,EACC;AACD;AAEA,MAAM,eAAe,CAAC,mBAAmB;AACxC,SAAO,CAAC,aAAa;AACpB,WAAO;AAAA,MACN,MAAM,GAAG,cAAc;AAAA,MACvB,SAAS,gBAAgB,QAAQ;AAAA,MACjC,YAAY;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AAA,UACpC;AAAA,QACJ,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,cACA;AAAA,YACA;AAAA,UACoB;AAEA,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,YAC5E;AAAA,UACA;AAAA,QAEgB,KAAK,GAAG,cAAc;AAClB,iBAAO,CAAC,GAAG,OAAO,OAAO;AAAA,QAC7B;AACI,iBAAO;AAAA,MAC3B;AAAA,IACQ;AAAA,EACJ;AACJ;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\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/ADD`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'ADD',\n\t\t};\n\t};\n};\n\nconst addManyAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/ADD_MANY`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'ADD_MANY',\n\t\t};\n\t};\n};\n\nconst updateAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/UPDATE`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'UPDATE',\n\t\t};\n\t};\n};\n\nconst deleteAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/DELETE`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'DELETE',\n\t\t};\n\t};\n};\n\nconst loadAction = (stateValueName) => {\n\treturn (payload2) => {\n\t\treturn {\n\t\t\ttype: `${stateValueName}/LOAD`,\n\t\t\tpayload: structuredClone(payload2),\n\t\t\tactionType: 'LOAD',\n\t\t};\n\t};\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 // 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 (\n action.type.startsWith(`${stateValueName}/`) &&\n !['ADD', 'UPDATE', 'DELETE'].includes(actionType)\n ) {\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":["updateAction","stateValueName","payload2","type","payload","structuredClone","actionType","PubSub","constructor","this","events","event","callback","self","hasOwnProperty","push","unsubscribe","splice","indexOf","state","newData","oldData","map","store","params","_state","_reducer","status","_isPause","reducer","refreshProxy","action","newState","Object","assign","JSON","parse","stringify","eventName","callbackFn","subscribe","pause","val","newReducer","reducerCopy","storeKey","array","identificator","forEach","entry","getState","dispatch","defaultStoreActions.updateAction","define","id","source","defaultValue","key","console","warn","Function","mergeReducers","Array","createArrayReducer","createObjectReducer","Proxy","set","value","oldState","publish","isArray","error","split","startsWith","includes","some","obj","filter","item"],"mappings":";;;AAAA,MAoBMA,IAA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WAErB,CAAA,GAAIe,IAAOY,GAAO3B,OAAAA;AAAAA,QAEjC,KAAK,GAAGH,EAAAA;AACJ,iBAAO,CAAA,GAAIkB,OAAUY,GAAO3B,OAAAA;AAAAA,QAChC,KAAK,GAAGH,EAAAA;AACJ,iBAAIkB,GAAMwD,KAAMC,CAAAA,OAAQA,GAAInB,QAAS1B,GAAO3B,QAAQqD,EAAAA,CAAAA,IACzC,CAAA,GACAtC,GAAMG,IAAKsD,CAAAA,OACNA,GAAInB,EAAAA,MAAS1B,GAAO3B,QAAQqD,EAAAA,IACrB1B,GAAO3B,UAEXwE,OAIR,CAAA,GAAIzD,IAAOY,GAAO3B,OAAAA;AAAAA,QAEjC,KAAK,GAAGH,EAAAA;AACJ,iBAAI6D,MAAMQ,QAAQvC,GAAO3B,OAAAA,IACd,CAAA,GACAe,GAAM0D,OACJD,CAAAA,OAAAA,CACI7C,GAAO3B,QAAQuE,KACXG,CAAAA,OACIF,GAAI9D,eAAe2C,EAAAA,KAAQmB,GAAInB,QAASqB,GAAKrB,EAAAA,KAAAA,CAC5CmB,GAAI9D,eAAe2C,OAAQmB,OAAQE,EAAAA,CAAAA,CAAAA,IAMtD,CAAA,GACA3D,GAAM0D,OACJD,CAAAA,OACIA,GAAI9D,eAAe2C,EAAAA,KAAQmB,GAAInB,EAAAA,MAAS1B,GAAO3B,QAAQqD,EAAAA,KAAAA,CACtDmB,GAAI9D,eAAe2C,EAAAA,KAAQmB,OAAQ7C,GAAO3B;QAI5D,KAAK,GAAGH,EAAAA;AACJ,iBAAO,IAAI8B,GAAO3B,OAAAA;AAAAA,QACtB;AACI,iBAAOe;AAAAA,MAAAA;AAAAA,IAAAA;AAAAA,EAGvB;;"}
@@ -1,385 +1,156 @@
1
1
  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
- 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 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 width: 100%;\n min-width: 0;\n box-sizing: border-box;\n\n & > nav {\n display: flex;\n align-items: center;\n width: 100%;\n min-width: 0;\n box-sizing: border-box;\n overflow: hidden;\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: var(--wje-tab-group-nav-border);\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: var(--wje-tab-group-nav-border);\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: var(--wje-tab-group-nav-border);\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: var(--wje-tab-group-nav-border);\n }\n}\n\n.dropdown-active {\n wje-button{\n &::part(native) {\n color: var(--wje-color-primary-8);\n }\n }\n}\n\n.more-tabs {\n flex: 0 0 auto;\n}\n";
6
- const _TabGroup = class _TabGroup extends WJElement {
7
- /**
8
- * Creates an instance of TabGroup.
9
- * @class
10
- */
4
+ import t from "./wje-element.js";
5
+ const _e = class _e extends t {
11
6
  constructor() {
12
7
  super();
13
8
  __publicField(this, "className", "TabGroup");
14
- this._instanceId = ++_TabGroup._instanceId;
15
- this._lastNavWidth = null;
16
- this._initialized = false;
17
- this._moreWidth = 0;
9
+ this._instanceId = ++_e._instanceId, this._lastNavWidth = null, this._initialized = false, this._moreWidth = 0;
18
10
  }
19
- /**
20
- * Sets the value for the 'variant' attribute of the element.
21
- * @param {string} value The value to set for the 'variant' attribute.
22
- */
23
- set variant(value) {
24
- this.setAttribute("variant", value);
25
- this.setAriaState({
26
- orientation: value === "start" || value === "end" ? "vertical" : "horizontal"
27
- });
11
+ set variant(t2) {
12
+ this.setAttribute("variant", t2), this.setAriaState({ orientation: "start" === t2 || "end" === t2 ? "vertical" : "horizontal" });
28
13
  }
29
- /**
30
- * Gets the value of the 'variant' attribute.
31
- * If the attribute is not set, it defaults to 'top'.
32
- * @returns {string} The value of the 'variant' attribute or the default value 'top' if not set.
33
- */
34
14
  get variant() {
35
15
  return this.getAttribute("variant") || "top";
36
16
  }
37
- /**
38
- * Sets the 'type' attribute of the element to the specified value.
39
- * @param {string} value The value to set for the 'type' attribute.
40
- */
41
- set type(value) {
42
- this.setAttribute("type", value);
17
+ set type(t2) {
18
+ this.setAttribute("type", t2);
43
19
  }
44
- /**
45
- * Retrieves the `type` attribute of the element.
46
- * If the `type` attribute is not set, it defaults to `'panel'`.
47
- * @returns {string} The value of the `type` attribute or the default value `'panel'`.
48
- */
49
20
  get type() {
50
21
  return this.getAttribute("type") || "panel";
51
22
  }
52
- /**
53
- * Returns the CSS styles for the component.
54
- * @static
55
- * @returns {CSSStyleSheet}
56
- */
57
23
  static get cssStyleSheet() {
58
- return styles;
24
+ return ':host{--wje-tab-top: 0;--wje-tab-start: 0;--wje-tab-end: 0;--wje-tab-bottom: 0;width:100%}.native-tab-group{display:flex;flex-direction:column;overflow:hidden;position:relative}.native-tab-group>header{display:flex;flex-direction:column;width:100%;min-width:0;box-sizing:border-box}.native-tab-group>header>nav{display:flex;align-items:center;width:100%;min-width:0;box-sizing:border-box;overflow:hidden}.native-tab-group>section{width:100%}.native-tab-group>section>article{scroll-snap-align:start;overflow-y:auto;overscroll-behavior-y:contain}:host([variant="top"]){--wje-tab-top: auto !important;--wje-tab-writing-mode: horizontal-tb}:host([variant="top"]) .native-tab-group{flex-direction:column}:host([variant="top"]) nav{border-bottom:var(--wje-tab-group-nav-border)}:host([variant="start"]){--wje-tab-start: auto !important;--wje-tab-writing-mode: vertical-rl}:host([variant="start"]) .native-tab-group{flex-direction:row}:host([variant="start"]) nav{flex-direction:column;border-right:var(--wje-tab-group-nav-border)}:host([variant="end"]){--wje-tab-writing-mode: vertical-rl}:host([variant="end"]) .native-tab-group{flex-direction:row-reverse}:host([variant="end"]) nav{flex-direction:column;border-left:var(--wje-tab-group-nav-border)}:host([variant="bottom"]){--wje-tab-bottom: auto !important;--wje-tab-writing-mode: horizontal-tb}:host([variant="bottom"]) .native-tab-group{flex-direction:column-reverse}:host([variant="bottom"]) nav{border-top:var(--wje-tab-group-nav-border)}.dropdown-active wje-button::part(native){color:var(--wje-color-primary-8)}.more-tabs{flex:0 0 auto}';
59
25
  }
60
- /**
61
- * Sets up the attributes for the component.
62
- */
63
26
  setupAttributes() {
64
- this.isShadowRoot = "open";
65
- this.setAriaState({
66
- role: "tablist",
67
- orientation: this.variant === "start" || this.variant === "end" ? "vertical" : "horizontal"
68
- });
27
+ this.isShadowRoot = "open", this.setAriaState({ role: "tablist", orientation: "start" === this.variant || "end" === this.variant ? "vertical" : "horizontal" });
69
28
  }
70
- /**
71
- * Sets up the event listeners before the component is drawn.
72
- * This method is called before the component is drawn.
73
- * It is used to set up event listeners.
74
- */
75
29
  beforeDraw() {
76
- let activeTabName = location.hash.replace("#", "");
77
- if (this.getPanelAllName().includes(activeTabName)) {
78
- window.addEventListener("load", (e) => {
79
- this.setActiveTab(activeTabName);
80
- });
81
- }
30
+ let t2 = location.hash.replace("#", "");
31
+ this.getPanelAllName().includes(t2) && window.addEventListener("load", (e2) => {
32
+ this.setActiveTab(t2);
33
+ });
82
34
  }
83
- /**
84
- * Creates and returns a document fragment containing a structured layout for a tab group.
85
- * The tab group layout includes a `header` section with navigational elements,
86
- * a `section` element for tab panels, and slots for customization such as additional navigation items,
87
- * dropdowns, and more.
88
- * The structure comprises:
89
- * - A `div` container with relevant styling and part attributes.
90
- * - A `header` for tabs, including a slot for navigation (`nav`) and additional tabs in a dropdown (`moreDropdown`).
91
- * - A `section` for tab panels with a customizable `slot`.
92
- * This function also initializes the `nav` and `moreDropdown` properties for external use.
93
- * @returns {DocumentFragment} The completed document fragment containing the tab group layout.
94
- */
95
35
  draw() {
96
- let fragment = document.createDocumentFragment();
97
- let native = document.createElement("div");
98
- native.setAttribute("part", "native");
99
- native.classList.add("native-tab-group");
100
- let header = document.createElement("header");
101
- header.setAttribute("part", "tabs");
102
- header.classList.add("scroll-snap-x");
103
- let nav = document.createElement("nav");
104
- nav.setAttribute("part", "nav");
105
- let section = document.createElement("section");
106
- section.setAttribute("part", "panels");
107
- let slot = document.createElement("slot");
108
- let slotNav = document.createElement("slot");
109
- slotNav.setAttribute("name", "nav");
110
- let icon = document.createElement("wje-icon");
111
- icon.setAttribute("name", "dots");
112
- let button = document.createElement("wje-button");
113
- button.setAttribute("slot", "trigger");
114
- button.setAttribute("fill", "link");
115
- let menu = document.createElement("wje-menu");
116
- menu.setAttribute("variant", "context");
117
- let slotMore = document.createElement("slot");
118
- slotMore.setAttribute("name", "more");
119
- let moreDropdown = document.createElement("wje-dropdown");
120
- moreDropdown.setAttribute("placement", "bottom-end");
121
- moreDropdown.setAttribute("collapsible", "");
122
- moreDropdown.classList.add("more-tabs");
123
- button.append(icon);
124
- menu.append(slotMore);
125
- moreDropdown.append(button);
126
- moreDropdown.append(menu);
127
- header.append(nav);
128
- nav.append(slotNav);
129
- if (this.variant === "top" || this.variant === "bottom") {
130
- nav.append(moreDropdown);
131
- }
132
- section.append(slot);
133
- native.append(header);
134
- native.append(section);
135
- fragment.append(native);
136
- this.nav = nav;
137
- this.moreDropdown = moreDropdown;
138
- return fragment;
36
+ let t2 = document.createDocumentFragment(), e2 = document.createElement("div");
37
+ e2.setAttribute("part", "native"), e2.classList.add("native-tab-group");
38
+ let i = document.createElement("header");
39
+ i.setAttribute("part", "tabs"), i.classList.add("scroll-snap-x");
40
+ let a = document.createElement("nav");
41
+ a.setAttribute("part", "nav");
42
+ let r = document.createElement("section");
43
+ r.setAttribute("part", "panels");
44
+ let o = document.createElement("slot"), s = document.createElement("slot");
45
+ s.setAttribute("name", "nav");
46
+ let n = document.createElement("wje-icon");
47
+ n.setAttribute("name", "dots");
48
+ let l = document.createElement("wje-button");
49
+ l.setAttribute("slot", "trigger"), l.setAttribute("fill", "link");
50
+ let d = document.createElement("wje-menu");
51
+ d.setAttribute("variant", "context");
52
+ let c = document.createElement("slot");
53
+ c.setAttribute("name", "more");
54
+ let h = document.createElement("wje-dropdown");
55
+ return h.setAttribute("placement", "bottom-end"), h.setAttribute("collapsible", ""), h.classList.add("more-tabs"), l.append(n), d.append(c), h.append(l), h.append(d), i.append(a), a.append(s), "top" !== this.variant && "bottom" !== this.variant || a.append(h), r.append(o), e2.append(i), e2.append(r), t2.append(e2), this.nav = a, this.moreDropdown = h, t2;
139
56
  }
140
- /**
141
- * Executes necessary initializations and attaches event listeners after a drawing operation.
142
- * Handles active tab selection, 'wje-tab:change' event binding, and window resize event for overflow checking.
143
- * @returns {void} Does not return a value.
144
- */
145
57
  afterDraw() {
146
- let activeTab = this.getActiveTab();
147
- let activeTabName = activeTab ? activeTab[0][this.type] : this.getTabAll()[0][this.type];
148
- this.setActiveTab(activeTabName);
149
- this.addEventListener("wje-tab:change", (e) => {
150
- if (e.detail.context.hasAttribute("disabled")) return;
151
- this.setActiveTab(e.detail.context.panel);
152
- });
153
- if (this.variant === "top" || this.variant === "bottom") {
154
- this.initTabMetrics();
155
- this._resizeObserver = new ResizeObserver((entries) => {
156
- const width = entries[0].contentRect.width;
157
- if (width !== this._lastNavWidth) {
158
- this._lastNavWidth = width;
159
- this.checkOverflow();
160
- }
161
- });
162
- this._resizeObserver.observe(this);
163
- }
58
+ let t2 = this.getActiveTab(), e2 = t2 ? t2[0][this.type] : this.getTabAll()[0][this.type];
59
+ this.setActiveTab(e2), this.addEventListener("wje-tab:change", (t3) => {
60
+ t3.detail.context.hasAttribute("disabled") || this.setActiveTab(t3.detail.context.panel);
61
+ }), "top" !== this.variant && "bottom" !== this.variant || (this.initTabMetrics(), this._resizeObserver = new ResizeObserver((t3) => {
62
+ const e3 = t3[0].contentRect.width;
63
+ e3 !== this._lastNavWidth && (this._lastNavWidth = e3, this.checkOverflow());
64
+ }), this._resizeObserver.observe(this));
164
65
  }
165
- /**
166
- * Removes the 'active' class from all panel and tab elements.
167
- * @returns {void} This method does not return a value.
168
- */
169
66
  removeActiveTab() {
170
- this.getPanelAll().forEach((el) => {
171
- el.classList.remove("active");
172
- });
173
- this.getTabAll().forEach((el) => {
174
- el.classList.remove("active");
67
+ this.getPanelAll().forEach((t2) => {
68
+ t2.classList.remove("active");
69
+ }), this.getTabAll().forEach((t2) => {
70
+ t2.classList.remove("active");
175
71
  });
176
72
  }
177
- /**
178
- * Sets the active tab and panel.
179
- * @param {string} tab The name of the tab to set as active.
180
- */
181
- setActiveTab(tab) {
73
+ setActiveTab(t2) {
182
74
  var _a;
183
75
  this.removeActiveTab();
184
- const el = this.querySelector(`[${this.type}="${tab}"]`);
185
- el == null ? void 0 : el.classList.add("active");
186
- if (this.type === "panel")
187
- (_a = this.querySelector(`[name="${tab}"]`)) == null ? void 0 : _a.classList.add("active");
188
- if (el)
189
- this.dropdownActive(el);
190
- this.syncAria();
76
+ const e2 = this.querySelector(`[${this.type}="${t2}"]`);
77
+ e2 == null ? void 0 : e2.classList.add("active"), "panel" === this.type && ((_a = this.querySelector(`[name="${t2}"]`)) == null ? void 0 : _a.classList.add("active")), e2 && this.dropdownActive(e2), this.syncAria();
191
78
  }
192
- /**
193
- * Returns the currently active tab.
194
- * @returns {Element|null} The active tab, or null if no tab is active.
195
- */
196
79
  getActiveTab() {
197
- let activeTabs = Array.from(this.querySelectorAll("wje-tab.active"));
198
- return activeTabs.length > 0 ? activeTabs : null;
80
+ let t2 = Array.from(this.querySelectorAll("wje-tab.active"));
81
+ return t2.length > 0 ? t2 : null;
199
82
  }
200
- /**
201
- * Returns all tabs.
202
- * @returns {Array<Element>} An array of all tabs.
203
- */
204
83
  getTabAll() {
205
84
  return this.context.querySelector('[name="nav"]').assignedElements();
206
85
  }
207
- /**
208
- * Returns all tabs, including those moved to "more".
209
- * @returns {Array<Element>} An array of all tabs.
210
- */
211
86
  getAllTabs() {
212
87
  return Array.from(this.querySelectorAll("wje-tab"));
213
88
  }
214
- /**
215
- * Returns all panels.
216
- * @returns {Array<Element>} An array of all panels.
217
- */
218
89
  getPanelAll() {
219
90
  return Array.from(this.querySelectorAll("wje-tab-panel"));
220
91
  }
221
- /**
222
- * Returns the names of all tabs.
223
- * @returns {Array<string>} An array of all tab names.
224
- */
225
92
  getPanelAllName() {
226
- return this.getPanelAll().map((el) => el.getAttribute("name"));
93
+ return this.getPanelAll().map((t2) => t2.getAttribute("name"));
227
94
  }
228
- /**
229
- * Toggles the visibility of the "more" dropdown based on the presence of tabs in the "more" slot.
230
- * @returns {void} Does not return a value.
231
- */
232
95
  toggleMoreVisibility() {
233
- const hasTabsInMore = !!this.querySelector('wje-tab[slot="more"]');
234
- const nextHidden = !hasTabsInMore;
235
- if (this.moreDropdown.hidden !== nextHidden) {
236
- this.moreDropdown.hidden = nextHidden;
237
- }
96
+ const t2 = !!!this.querySelector('wje-tab[slot="more"]');
97
+ this.moreDropdown.hidden !== t2 && (this.moreDropdown.hidden = t2);
238
98
  }
239
- /**
240
- * Initializes metrics for tabs within the component. Assigns each tab to the navigation slot
241
- * and calculates their dimensions for further operations.
242
- * @returns {void} Does not return any value.
243
- */
244
99
  initTabMetrics() {
245
100
  requestAnimationFrame(() => {
246
- this._tabMetrics = this.measureTabMetrics();
247
- this.measureMoreWidth();
248
- this._initialized = true;
249
- this.checkOverflow();
250
- this._lastNavWidth = this.nav.getBoundingClientRect().width;
101
+ this._tabMetrics = this.measureTabMetrics(), this.measureMoreWidth(), this._initialized = true, this.checkOverflow(), this._lastNavWidth = this.nav.getBoundingClientRect().width;
251
102
  });
252
103
  }
253
- /**
254
- * Measures current tab widths while all tabs are temporarily placed into the main nav slot.
255
- * @returns {Array<{el: Element, width: number}>}
256
- */
257
104
  measureTabMetrics() {
258
- const tabs = Array.from(this.querySelectorAll("wje-tab"));
259
- tabs.forEach((tab) => tab.setAttribute("slot", "nav"));
260
- return tabs.map((tab) => ({
261
- el: tab,
262
- width: tab.getBoundingClientRect().width
263
- }));
105
+ const t2 = Array.from(this.querySelectorAll("wje-tab"));
106
+ return t2.forEach((t3) => t3.setAttribute("slot", "nav")), t2.map((t3) => ({ el: t3, width: t3.getBoundingClientRect().width }));
264
107
  }
265
- /**
266
- * Stores the measured width of the more dropdown trigger when available.
267
- * @returns {void}
268
- */
269
108
  measureMoreWidth() {
270
- const wasHidden = this.moreDropdown.hidden;
271
- const previousVisibility = this.moreDropdown.style.visibility;
272
- if (wasHidden) {
273
- this.moreDropdown.hidden = false;
274
- this.moreDropdown.style.visibility = "hidden";
275
- }
276
- const width = this.moreDropdown.getBoundingClientRect().width || 0;
277
- if (wasHidden) {
278
- this.moreDropdown.hidden = true;
279
- this.moreDropdown.style.visibility = previousVisibility;
280
- }
281
- if (width > 0) {
282
- this._moreWidth = width;
283
- }
109
+ const t2 = this.moreDropdown.hidden, e2 = this.moreDropdown.style.visibility;
110
+ t2 && (this.moreDropdown.hidden = false, this.moreDropdown.style.visibility = "hidden");
111
+ const i = this.moreDropdown.getBoundingClientRect().width || 0;
112
+ t2 && (this.moreDropdown.hidden = true, this.moreDropdown.style.visibility = e2), i > 0 && (this._moreWidth = i);
284
113
  }
285
- /**
286
- * Checks if the tabs within a navigation bar overflow the available space.
287
- * Moves overflowing tabs into a dropdown menu and updates their state accordingly.
288
- * @returns {void} This method does not return a value.
289
- */
290
114
  checkOverflow() {
291
115
  var _a, _b;
292
116
  if (!this._initialized) return;
293
- this._tabMetrics = this.measureTabMetrics();
294
- this.measureMoreWidth();
295
- const navWidth = this.nav.getBoundingClientRect().width;
296
- const moreWidth = this._moreWidth || 48;
297
- const totalWidth = this._tabMetrics.reduce((sum, { width }) => sum + width, 0);
298
- if (totalWidth <= navWidth) {
299
- this._tabMetrics.forEach(({ el }) => el.setAttribute("slot", "nav"));
300
- this.toggleMoreVisibility();
301
- this.dropdownActive((_a = this.getActiveTab()) == null ? void 0 : _a[0]);
302
- return;
303
- }
304
- let used = 0;
305
- let overflowStarted = false;
306
- const availableWidth = Math.max(navWidth - moreWidth, 0);
307
- for (const { el, width } of this._tabMetrics) {
308
- used += width;
309
- const shouldOverflow = used > availableWidth;
310
- el.setAttribute("slot", shouldOverflow || overflowStarted ? "more" : "nav");
311
- overflowStarted || (overflowStarted = shouldOverflow);
117
+ this._tabMetrics = this.measureTabMetrics(), this.measureMoreWidth();
118
+ const t2 = this.nav.getBoundingClientRect().width, e2 = this._moreWidth || 48;
119
+ if (this._tabMetrics.reduce((t3, { width: e3 }) => t3 + e3, 0) <= t2) return this._tabMetrics.forEach(({ el: t3 }) => t3.setAttribute("slot", "nav")), this.toggleMoreVisibility(), void this.dropdownActive((_a = this.getActiveTab()) == null ? void 0 : _a[0]);
120
+ let i = 0, a = false;
121
+ const r = Math.max(t2 - e2, 0);
122
+ for (const { el: t3, width: e3 } of this._tabMetrics) {
123
+ i += e3;
124
+ const o = i > r;
125
+ t3.setAttribute("slot", o || a ? "more" : "nav"), a || (a = o);
312
126
  }
313
- this.toggleMoreVisibility();
314
- this.dropdownActive((_b = this.getActiveTab()) == null ? void 0 : _b[0]);
127
+ this.toggleMoreVisibility(), this.dropdownActive((_b = this.getActiveTab()) == null ? void 0 : _b[0]);
315
128
  }
316
- /**
317
- * Toggles the "dropdown-active" class on the element based on its "active" status
318
- * and the value of its "slot" attribute.
319
- * @param {HTMLElement} el The HTML element to evaluate and apply the toggle logic.
320
- * @returns {void} This method does not return any value.
321
- */
322
- dropdownActive(el) {
323
- if (!el) {
324
- this.moreDropdown.classList.remove("dropdown-active");
325
- return;
326
- }
327
- if (el.classList.contains("active")) {
328
- if (el.getAttribute("slot") === "more")
329
- this.moreDropdown.classList.add("dropdown-active");
330
- else
331
- this.moreDropdown.classList.remove("dropdown-active");
332
- }
129
+ dropdownActive(t2) {
130
+ t2 ? t2.classList.contains("active") && ("more" === t2.getAttribute("slot") ? this.moreDropdown.classList.add("dropdown-active") : this.moreDropdown.classList.remove("dropdown-active")) : this.moreDropdown.classList.remove("dropdown-active");
333
131
  }
334
- /**
335
- * Syncs ARIA attributes on tabs and panels.
336
- */
337
132
  syncAria() {
338
- const tabs = this.getAllTabs();
339
- const panels = this.getPanelAll();
340
- const panelByName = new Map(panels.map((p) => [p.getAttribute("name"), p]));
341
- this.id || `wje-tab-group-${this._instanceId}`;
342
- this.setAriaState({
343
- orientation: this.variant === "start" || this.variant === "end" ? "vertical" : "horizontal"
344
- });
345
- tabs.forEach((tab, index) => {
346
- const tabName = tab.getAttribute(this.type) || tab.panel || tab.route || String(index);
347
- const isActive = tab.classList.contains("active");
348
- const isDisabled = tab.hasAttribute("disabled");
349
- if (!tab.id) tab.id = `wje-tab-${tabName}`;
350
- let controlsId = "";
351
- if (this.type === "panel") {
352
- const panel = panelByName.get(tabName);
353
- if (panel) {
354
- if (!panel.id) panel.id = `wje-tab-panel-${tabName}`;
355
- controlsId = panel.id;
356
- panel.setAriaState({
357
- role: "tabpanel",
358
- labelledBy: tab.id
359
- });
360
- }
361
- }
362
- tab.setAriaState({
363
- role: "tab",
364
- selected: isActive,
365
- disabled: isDisabled,
366
- controls: controlsId || ""
367
- });
368
- if (typeof tab.setRovingTabIndex === "function") {
369
- tab.setRovingTabIndex(isActive ? 0 : -1);
133
+ const t2 = this.getAllTabs(), e2 = this.getPanelAll(), i = new Map(e2.map((t3) => [t3.getAttribute("name"), t3]));
134
+ this.id || this._instanceId, this.setAriaState({ orientation: "start" === this.variant || "end" === this.variant ? "vertical" : "horizontal" }), t2.forEach((t3, e3) => {
135
+ const a = t3.getAttribute(this.type) || t3.panel || t3.route || String(e3), r = t3.classList.contains("active"), o = t3.hasAttribute("disabled");
136
+ t3.id || (t3.id = `wje-tab-${a}`);
137
+ let s = "";
138
+ if ("panel" === this.type) {
139
+ const e4 = i.get(a);
140
+ e4 && (e4.id || (e4.id = `wje-tab-panel-${a}`), s = e4.id, e4.setAriaState({ role: "tabpanel", labelledBy: t3.id }));
370
141
  }
142
+ t3.setAriaState({ role: "tab", selected: r, disabled: o, controls: s || "" }), "function" == typeof t3.setRovingTabIndex && t3.setRovingTabIndex(r ? 0 : -1);
371
143
  });
372
144
  }
373
145
  disconnectedCallback() {
374
146
  var _a, _b;
375
- (_a = super.disconnectedCallback) == null ? void 0 : _a.call(this);
376
- (_b = this._resizeObserver) == null ? void 0 : _b.disconnect();
147
+ (_a = super.disconnectedCallback) == null ? void 0 : _a.call(this), (_b = this._resizeObserver) == null ? void 0 : _b.disconnect();
377
148
  }
378
149
  };
379
- __publicField(_TabGroup, "_instanceId", 0);
380
- let TabGroup = _TabGroup;
381
- TabGroup.define("wje-tab-group", TabGroup);
150
+ __publicField(_e, "_instanceId", 0);
151
+ let e = _e;
152
+ e.define("wje-tab-group", e);
382
153
  export {
383
- TabGroup as default
154
+ e as default
384
155
  };
385
156
  //# sourceMappingURL=wje-tab-group.js.map