wj-elements 0.1.128 → 0.1.130

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 (105) hide show
  1. package/README.md +8 -4
  2. package/dist/assets/tags.json +3252 -22012
  3. package/dist/dark.css +211 -203
  4. package/dist/{infinite-scroll.element-DcO1E5Es.js → infinite-scroll.element-BmojLp3Z.js} +54 -44
  5. package/dist/light.css +511 -496
  6. package/dist/{list.element-TZXMx1rt.js → list.element-Ce1vIm1O.js} +3 -9
  7. package/dist/localize.js +4 -4
  8. package/dist/{popup.element-l8v-dMoK.js → popup.element-4DNn6DjX.js} +44 -53
  9. package/dist/{router-links-I2vcmVCs.js → router-links-CJnOdbas.js} +30 -77
  10. package/dist/styles.css +485 -473
  11. package/dist/wje-accordion-item.js +13 -11
  12. package/dist/wje-accordion.js +51 -14
  13. package/dist/wje-animation.js +149 -25
  14. package/dist/wje-aside.js +7 -12
  15. package/dist/wje-avatar.js +12 -15
  16. package/dist/wje-badge.js +24 -19
  17. package/dist/wje-breadcrumb.js +36 -44
  18. package/dist/wje-breadcrumbs.js +84 -27
  19. package/dist/wje-button-group.js +17 -23
  20. package/dist/wje-button.js +117 -66
  21. package/dist/wje-card-content.js +10 -13
  22. package/dist/wje-card-controls.js +10 -13
  23. package/dist/wje-card-header.js +5 -9
  24. package/dist/wje-card-subtitle.js +5 -8
  25. package/dist/wje-card-title.js +5 -8
  26. package/dist/wje-card.js +13 -14
  27. package/dist/wje-carousel-item.js +26 -1
  28. package/dist/wje-carousel.js +141 -24
  29. package/dist/wje-checkbox.js +300 -51
  30. package/dist/wje-chip.js +31 -12
  31. package/dist/wje-col.js +11 -15
  32. package/dist/wje-color-picker.js +92 -64
  33. package/dist/wje-container.js +6 -10
  34. package/dist/wje-copy-button.js +14 -18
  35. package/dist/wje-dialog.js +89 -5
  36. package/dist/wje-divider.js +2 -5
  37. package/dist/wje-dropdown.js +57 -24
  38. package/dist/wje-element.js +393 -218
  39. package/dist/wje-fetchAndParseCSS.js +2 -1
  40. package/dist/wje-file-upload-item.js +12 -19
  41. package/dist/wje-file-upload.js +117 -68
  42. package/dist/wje-footer.js +3 -10
  43. package/dist/wje-form.js +23 -1
  44. package/dist/wje-format-digital.js +5 -13
  45. package/dist/wje-grid.js +24 -3
  46. package/dist/wje-header.js +3 -10
  47. package/dist/wje-icon-picker.js +15 -31
  48. package/dist/wje-icon.js +10 -10
  49. package/dist/wje-img-comparer.js +8 -18
  50. package/dist/wje-img.js +5 -11
  51. package/dist/wje-infinite-scroll.js +1 -1
  52. package/dist/wje-input-file.js +20 -17
  53. package/dist/wje-input.js +51 -62
  54. package/dist/wje-item.js +31 -4
  55. package/dist/wje-kanban.js +37 -53
  56. package/dist/wje-label.js +4 -21
  57. package/dist/wje-list.js +1 -1
  58. package/dist/wje-main.js +4 -11
  59. package/dist/wje-masonry.js +21 -26
  60. package/dist/wje-master.js +201 -348
  61. package/dist/wje-menu-button.js +5 -13
  62. package/dist/wje-menu-item.js +211 -30
  63. package/dist/wje-menu-label.js +4 -11
  64. package/dist/wje-menu.js +6 -15
  65. package/dist/wje-option.js +19 -26
  66. package/dist/wje-options.js +148 -48
  67. package/dist/wje-orgchart-group.js +10 -17
  68. package/dist/wje-orgchart-item.js +13 -157
  69. package/dist/wje-orgchart.js +4 -10
  70. package/dist/wje-popup.js +1 -1
  71. package/dist/wje-progress-bar.js +17 -27
  72. package/dist/wje-qr-code.js +29 -13
  73. package/dist/wje-radio-group.js +21 -43
  74. package/dist/wje-radio.js +46 -8
  75. package/dist/wje-rate.js +38 -58
  76. package/dist/wje-relative-time.js +51 -43
  77. package/dist/wje-reorder-dropzone.js +20 -2
  78. package/dist/wje-reorder-handle.js +62 -3
  79. package/dist/wje-reorder-item.js +20 -2
  80. package/dist/wje-reorder.js +93 -36
  81. package/dist/wje-route.js +3 -9
  82. package/dist/wje-router-link.js +10 -14
  83. package/dist/wje-router-outlet.js +35 -37
  84. package/dist/wje-routerx.js +231 -338
  85. package/dist/wje-row.js +8 -20
  86. package/dist/wje-select.js +80 -104
  87. package/dist/wje-slider.js +17 -33
  88. package/dist/wje-sliding-container.js +127 -55
  89. package/dist/wje-split-view.js +15 -21
  90. package/dist/wje-status.js +9 -13
  91. package/dist/wje-step.js +18 -0
  92. package/dist/wje-stepper.js +65 -4734
  93. package/dist/wje-store.js +193 -90
  94. package/dist/wje-tab-group.js +7 -16
  95. package/dist/wje-tab-panel.js +4 -13
  96. package/dist/wje-tab.js +6 -14
  97. package/dist/wje-textarea.js +128 -42
  98. package/dist/wje-thumbnail.js +10 -23
  99. package/dist/wje-toast.js +38 -74
  100. package/dist/wje-toggle.js +24 -29
  101. package/dist/wje-toolbar-action.js +11 -15
  102. package/dist/wje-toolbar.js +11 -16
  103. package/dist/wje-tooltip.js +35 -23
  104. package/dist/wje-visually-hidden.js +10 -14
  105. package/package.json +22 -4
@@ -13,18 +13,18 @@ class UniversalService {
13
13
  constructor(props = {}) {
14
14
  __publicField(this, "findByKey", (attrName, key, keyValue) => {
15
15
  if (this._store.getState()[attrName] instanceof Array) {
16
- let find = this._store.getState()[attrName].find((item) => item[key] == keyValue);
17
- return find;
16
+ return this._store.getState()[attrName].find((item) => item[key] === keyValue);
18
17
  } else {
19
18
  console.warn(` Attribute ${attrName} is not array`);
19
+ return null;
20
20
  }
21
21
  });
22
22
  __publicField(this, "findById", (attrName, id) => {
23
23
  if (this._store.getState()[attrName] instanceof Array) {
24
- let find = this._store.getState()[attrName].find((item) => item.id == id);
25
- return find;
24
+ return this._store.getState()[attrName].find((item) => item.id === id);
26
25
  } else {
27
26
  console.warn(` Attribute ${attrName} is not array`);
27
+ return null;
28
28
  }
29
29
  });
30
30
  __publicField(this, "findAttributeValue", (attrName) => {
@@ -36,17 +36,15 @@ class UniversalService {
36
36
  __publicField(this, "add", (data, action) => {
37
37
  this._store.dispatch(action(data));
38
38
  });
39
- __publicField(this, "loadPromise", (url, action, method = "GET", data, permissionCallBack = () => {
39
+ __publicField(this, "loadPromise", (url, action, method = "GET", data = "", permissionCallBack = () => {
40
40
  }) => {
41
41
  return fetch(url, {
42
42
  method,
43
43
  body: data,
44
- // cache: 'no-cache',
45
44
  headers: {
46
45
  "Content-Type": "application/json"
47
46
  },
48
47
  async: true
49
- // referrerPolicy: 'same-origin',
50
48
  }).then((response, e) => {
51
49
  var _a;
52
50
  let permissions = (_a = response.headers.get("permissions")) == null ? void 0 : _a.split(",");
@@ -56,46 +54,33 @@ class UniversalService {
56
54
  } else {
57
55
  throw response.json();
58
56
  }
59
- }).then((data2) => {
60
- this._store.dispatch(action(data2));
61
- return data2;
57
+ }).then((responseData) => {
58
+ this._store.dispatch(action(responseData));
59
+ return responseData;
62
60
  });
63
61
  });
64
62
  __publicField(this, "loadOnePromise", (url, action) => {
65
63
  return fetch(url, {
66
- // cache: 'no-cache',
67
64
  headers: {
68
65
  "Content-Type": "application/json"
69
66
  }
70
- // referrerPolicy: 'same-origin',
71
- }).then((data) => {
72
- data = data.json();
67
+ }).then((response) => {
68
+ const responseData = response.json();
73
69
  if (action) {
74
- this._store.dispatch(action(data));
70
+ this._store.dispatch(action(responseData));
75
71
  }
76
- return data;
77
- });
78
- });
79
- __publicField(this, "load", (url, async = false) => {
80
- return $.ajax({
81
- method: "GET",
82
- url,
83
- async,
84
- dataType: "json"
72
+ return responseData;
85
73
  });
86
74
  });
87
75
  this._store = props.store;
88
- this.premenna = null;
89
76
  }
90
77
  _save(url, data, action, dispatchMethod, method) {
91
78
  let promise = fetch(url, {
92
79
  method,
93
80
  body: JSON.stringify(data),
94
- // cache: 'no-cache',
95
81
  headers: {
96
82
  "Content-Type": "application/json"
97
83
  }
98
- // referrerPolicy: 'same-origin',
99
84
  }).then((response) => {
100
85
  if (response.ok) {
101
86
  return response.json();
@@ -108,20 +93,18 @@ class UniversalService {
108
93
  _get(url, action, dispatchMethod, signal) {
109
94
  let promise = fetch(url, {
110
95
  method: "GET",
111
- // cache: 'no-cache',
112
96
  headers: {
113
97
  "Content-Type": "application/json"
114
98
  },
115
99
  ...signal ? { signal } : {}
116
- // referrerPolicy: 'same-origin',
117
100
  }).then(async (response) => {
118
- let text;
101
+ let responseText;
119
102
  try {
120
- let text2 = await response.text();
121
- const data = JSON.parse(text2);
122
- return data;
103
+ responseText = await response.text();
104
+ return JSON.parse(responseText);
123
105
  } catch (err) {
124
- return text;
106
+ console.error(err);
107
+ return responseText;
125
108
  }
126
109
  });
127
110
  return this.dispatch(promise, dispatchMethod, action);
@@ -135,7 +118,7 @@ class UniversalService {
135
118
  delete(url, data, action, dispatchMethod = true) {
136
119
  return this._save(url, data, action, dispatchMethod, "DELETE");
137
120
  }
138
- get(url, action, dispatchMethod = true, signal) {
121
+ get(url, action, dispatchMethod = true) {
139
122
  return this._get(url, action, dispatchMethod);
140
123
  }
141
124
  dispatch(promise, dispatchMethod, action) {
@@ -150,37 +133,34 @@ class UniversalService {
150
133
  return promise;
151
134
  }
152
135
  }
153
- class WjePermissionsApi {
154
- constructor() {
155
- this._permissionKey = "permissions";
156
- }
136
+ const _WjePermissionsApi = class _WjePermissionsApi {
157
137
  /**
158
138
  * Sets the permission key.
159
139
  * @param value
160
140
  */
161
141
  static set permissionKey(value) {
162
- WjePermissionsApi._permissionKey = value || "permissions";
142
+ _WjePermissionsApi._permissionKey = value || "permissions";
163
143
  }
164
144
  /**
165
145
  * Returns the permission key.
166
146
  * @returns {*|string}
167
147
  */
168
148
  static get permissionKey() {
169
- return WjePermissionsApi._permissionKey;
149
+ return _WjePermissionsApi._permissionKey;
170
150
  }
171
151
  /**
172
152
  * Sets the permissions.
173
153
  * @param value
174
154
  */
175
155
  static set permissions(value) {
176
- window.localStorage.setItem(WjePermissionsApi.permissionKey, value);
156
+ window.localStorage.setItem(_WjePermissionsApi.permissionKey, JSON.stringify(value));
177
157
  }
178
158
  /**
179
159
  * Returns the permissions.
180
160
  * @returns {string[]}
181
161
  */
182
162
  static get permissions() {
183
- return window.localStorage.getItem(WjePermissionsApi.permissionKey) || [];
163
+ return JSON.parse(window.localStorage.getItem(_WjePermissionsApi.permissionKey)) || [];
184
164
  }
185
165
  /**
186
166
  * Checks if the permission is included.
@@ -188,41 +168,23 @@ class WjePermissionsApi {
188
168
  * @returns {boolean}
189
169
  */
190
170
  static includesKey(key) {
191
- return WjePermissionsApi.permissions.includes(key);
192
- }
193
- /**
194
- * Returns the keys for the permission check.
195
- * @returns {string[]}
196
- */
197
- static getKeys() {
198
- let key = [];
199
- if (this.hasAttribute("permission-check")) {
200
- key = this.getAttribute("permission-check").split(",");
201
- }
202
- return key;
203
- }
204
- /**
205
- * Checks if the component should be shown.
206
- * @returns {boolean}
207
- */
208
- static shouldShow() {
209
- return this.hasAttribute("show") && JSON.parse(this.getAttribute("show"));
171
+ return _WjePermissionsApi.permissions.includes(key);
210
172
  }
211
173
  /**
212
174
  * Checks if the permission is fulfilled.
213
175
  * @returns {boolean}
214
176
  */
215
- static isPermissionFulfilled() {
216
- return WjePermissionsApi.getKeys.bind(this)().some((perm) => WjePermissionsApi.permissions.includes(perm)) || WjePermissionsApi.shouldShow.bind(this)();
177
+ static isPermissionFulfilled(permissions) {
178
+ return permissions.some((perm) => _WjePermissionsApi.permissions.includes(perm));
217
179
  }
218
- }
180
+ };
181
+ __publicField(_WjePermissionsApi, "_permissionKey", "permissions");
182
+ let WjePermissionsApi = _WjePermissionsApi;
219
183
  class WjElementUtils {
220
- constructor() {
221
- }
222
184
  /**
223
- * This function creates an element
224
- * @param element : HTMLElement
225
- * @param object : Object
185
+ * This function creates an element.
186
+ * @param element : HTMLElement - The element value.
187
+ * @param object : Object - The object value.
226
188
  */
227
189
  static setAttributesToElement(element, object) {
228
190
  Object.entries(object).forEach(([key, value]) => {
@@ -230,41 +192,42 @@ class WjElementUtils {
230
192
  });
231
193
  }
232
194
  /**
233
- * This function gets the attributes from an element
234
- * @param el (string | HTMLElement)
235
- * @return (array)
195
+ * This function gets the attributes from an element.
196
+ * @param {string|HTMLElement} el The element or selector to retrieve attributes from.
197
+ * @returns {object} - An object containing the element's attributes as key-value pairs.
236
198
  */
237
199
  static getAttributes(el) {
238
- if (typeof el === "string")
239
- el = document.querySelector(el);
240
- return Array.from(el.attributes).filter((a) => !a.name.startsWith("@")).map((a) => [a.name.split("-").map((s, i) => {
241
- if (i != 0) {
242
- return s.charAt(0).toUpperCase() + s.slice(1);
243
- } else {
244
- return s;
245
- }
246
- }).join(""), a.value]).reduce((acc, attr) => {
200
+ if (typeof el === "string") el = document.querySelector(el);
201
+ return Array.from(el.attributes).filter((a) => !a.name.startsWith("@")).map((a) => [
202
+ a.name.split("-").map((s, i) => {
203
+ if (i !== 0) {
204
+ return s.charAt(0).toUpperCase() + s.slice(1);
205
+ } else {
206
+ return s;
207
+ }
208
+ }).join(""),
209
+ a.value
210
+ ]).reduce((acc, attr) => {
247
211
  acc[attr[0]] = attr[1];
248
212
  return acc;
249
213
  }, {});
250
214
  }
251
215
  /**
252
- * This function gets the events from an element
253
- * @param el
254
- * @returns {Map<any, any>}
216
+ * This function gets the events from an element.
217
+ * @param {string|HTMLElement} el The element or selector to retrieve events from.
218
+ * @returns {Map<any, any>} - The map value.
255
219
  */
256
220
  static getEvents(el) {
257
- if (typeof el === "string")
258
- el = document.querySelector(el);
221
+ if (typeof el === "string") el = document.querySelector(el);
259
222
  return Array.from(el.attributes).filter((a) => a.name.startsWith("@wje")).map((a) => [a.name.substring(3).split("-").join(""), a.value]).reduce((acc, attr) => {
260
223
  acc.set(attr[0], attr[1]);
261
224
  return acc;
262
225
  }, /* @__PURE__ */ new Map());
263
226
  }
264
227
  /**
265
- * This function converts an object to a string
266
- * @param object
267
- * @returns {string}
228
+ * This function converts an object to a string.
229
+ * @param {object} object The object to convert.
230
+ * @returns {string} - The string value.
268
231
  */
269
232
  static attributesToString(object) {
270
233
  return Object.entries(object).map(([key, value]) => {
@@ -272,20 +235,20 @@ class WjElementUtils {
272
235
  }).join(" ");
273
236
  }
274
237
  /**
275
- * This function checks if the slot exists
276
- * @param el
277
- * @param slotName
278
- * @returns {boolean}
238
+ * This function checks if the slot exists.
239
+ * @param {string|HTMLElement} el The element or selector to check for slots.
240
+ * @param slotName The slot name to check for.
241
+ * @returns {boolean} - The boolean value.
279
242
  */
280
243
  static hasSlot(el, slotName = null) {
281
244
  let selector = slotName ? `[slot="${slotName}"]` : "[slot]";
282
245
  return el.querySelectorAll(selector).length > 0 ? true : false;
283
246
  }
284
247
  /**
285
- * This function checks if the slot has content
286
- * @param el
287
- * @param slotName
288
- * @returns {boolean}
248
+ * This function checks if the slot has content.
249
+ * @param {string|HTMLElement} el The element or selector to check for slot content
250
+ * @param slotName The slot name to check for.
251
+ * @returns {boolean} - The boolean value.
289
252
  */
290
253
  static hasSlotContent(el, slotName = null) {
291
254
  let slotElement = el.querySelector(`slot`);
@@ -299,12 +262,13 @@ class WjElementUtils {
299
262
  return false;
300
263
  }
301
264
  /**
302
- * This function converts a string to a boolean
303
- * @param string
304
- * @returns {boolean}
265
+ * This function converts a string to a boolean.
266
+ * @param {string | object} value The value to convert to a boolean. If the value is a boolean, it will be returned as is.
267
+ * @returns {boolean} - The boolean value.
305
268
  */
306
- static stringToBoolean(string) {
307
- return !["false", "0", 0].includes(string);
269
+ static stringToBoolean(value) {
270
+ if (typeof value === "boolean") return value;
271
+ return !["false", "0", 0].includes(value);
308
272
  }
309
273
  }
310
274
  var self;
@@ -314,6 +278,12 @@ class Event {
314
278
  this.customEventStorage = [];
315
279
  self = this;
316
280
  }
281
+ /**
282
+ * Dispatch custom event to the element with the specified event name and detail.
283
+ * @param element
284
+ * @param event
285
+ * @param detail
286
+ */
317
287
  dispatchCustomEvent(element, event2, detail) {
318
288
  element.dispatchEvent(
319
289
  new CustomEvent(event2, {
@@ -322,28 +292,48 @@ class Event {
322
292
  event: self
323
293
  },
324
294
  bubbles: true,
325
- composed: true
295
+ composed: true,
296
+ cancelable: true
326
297
  })
327
298
  );
328
299
  }
300
+ /**
301
+ * Find record by element in the storage.
302
+ * @param element
303
+ * @returns {*}
304
+ */
329
305
  findRecordByElement(element) {
330
- for (var index = 0, length = this.customEventStorage.length; index < length; index++) {
331
- var record = this.customEventStorage[index];
332
- if (element == record.element) {
306
+ for (let index = 0, length = this.customEventStorage.length; index < length; index++) {
307
+ let record = this.customEventStorage[index];
308
+ if (element === record.element) {
333
309
  return record;
334
310
  }
335
311
  }
336
312
  return false;
337
313
  }
314
+ /**
315
+ * Add listener to the element. If the element is an array, the listener will be added to all elements in the array.
316
+ * @param element
317
+ * @param originalEvent
318
+ * @param event
319
+ * @param listener
320
+ * @param options
321
+ */
338
322
  addListener(element, originalEvent, event2, listener, options) {
339
- if (!element)
340
- return;
341
- if (!Array.isArray(element))
342
- element = [element];
323
+ if (!element) return;
324
+ if (!Array.isArray(element)) element = [element];
343
325
  element.forEach((el) => {
344
326
  this.writeRecord(el, originalEvent, event2, listener, options);
345
327
  });
346
328
  }
329
+ /**
330
+ * Write record to the storage.
331
+ * @param element
332
+ * @param originalEvent
333
+ * @param event
334
+ * @param listener
335
+ * @param options
336
+ */
347
337
  writeRecord(element, originalEvent, event2, listener, options) {
348
338
  let record = this.findRecordByElement(element);
349
339
  if (record) {
@@ -369,23 +359,37 @@ class Event {
369
359
  }
370
360
  /**
371
361
  * Performs a deep equality check between two objects.
372
- *
373
- * @param {any} x - The first object to compare.
374
- * @param {any} y - The second object to compare.
375
- * @returns {boolean} - Returns `true` if the objects are deeply equal, `false` otherwise.
362
+ * @param x The first object to compare.
363
+ * @param y The second object to compare.
364
+ * @returns - Returns `true` if the objects are deeply equal, `false` otherwise.
376
365
  */
377
366
  deepEqual(x, y) {
378
367
  return x && y && typeof x === "object" && typeof x === typeof y ? Object.keys(x).length === Object.keys(y).length && Object.keys(x).every((key) => this.deepEqual(x[key], y[key])) : x === y;
379
368
  }
369
+ /**
370
+ * Check if the listener already exists on the element.
371
+ * @param element
372
+ * @param event
373
+ * @param listener
374
+ * @returns
375
+ */
380
376
  listenerExists(element, event2, listener) {
381
377
  let record = this.findRecordByElement(element);
382
378
  return record.listeners[event2].some((e) => this.deepEqual(e, listener));
383
379
  }
380
+ /**
381
+ * Remove listener from the element and delete the listener from the custom event storage.
382
+ * @param element
383
+ * @param originalEvent
384
+ * @param event
385
+ * @param listener
386
+ * @param options
387
+ */
384
388
  removeListener(element, originalEvent, event2, listener, options) {
385
389
  let record = this.findRecordByElement(element);
386
390
  if (record && originalEvent in record.listeners) {
387
- var index = record.listeners[originalEvent].indexOf(listener);
388
- if (~index) {
391
+ let index = record.listeners[originalEvent].indexOf(listener);
392
+ if (index !== -1) {
389
393
  record.listeners[originalEvent].splice(index, 1);
390
394
  }
391
395
  if (!record.listeners[originalEvent].length) {
@@ -395,10 +399,13 @@ class Event {
395
399
  listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
396
400
  element.removeEventListener(originalEvent, listener, options);
397
401
  }
402
+ /**
403
+ * Remove all event listeners from the specified element and delete the element from the custom event storage.
404
+ * @param {HTMLElement} element The element from which all listeners will be removed.
405
+ */
398
406
  removeElement(element) {
399
407
  this.customEventStorage = this.customEventStorage.filter((e) => {
400
- if (e.element !== element)
401
- return e;
408
+ return e.element !== element;
402
409
  });
403
410
  }
404
411
  // TODO
@@ -413,46 +420,54 @@ class Event {
413
420
  }
414
421
  }
415
422
  _Event_instances = new WeakSet();
423
+ /**
424
+ * Dispatch event to the element and trigger the listener.
425
+ * @param e
426
+ */
416
427
  dispatch_fn = function(e) {
417
428
  let element = this;
418
429
  let record = self.findRecordByElement(element);
419
430
  let listeners = record.listeners[e.type];
420
- listeners.forEach((listener, i) => {
431
+ listeners.forEach((listener) => {
421
432
  self.dispatchCustomEvent(element, listener.event, {
422
433
  originalEvent: (e == null ? void 0 : e.type) || null,
423
434
  context: element,
424
435
  event: self
425
436
  });
426
- if (listener.options && listener.options.stopPropagation === true)
427
- e.stopPropagation();
437
+ if (listener.options && listener.options.stopPropagation === true) e.stopPropagation();
428
438
  });
429
439
  };
430
440
  let event = new Event();
431
441
  const template = document.createElement("template");
432
442
  template.innerHTML = ``;
433
443
  const _WJElement = class _WJElement extends HTMLElement {
434
- constructor(componentTemplate) {
444
+ /**
445
+ * Initializes a new instance of the WJElement class.
446
+ */
447
+ constructor() {
435
448
  super();
436
- __publicField(this, "initWjElement", async (force = false) => {
449
+ /**
450
+ * Initializes the component, setting up attributes and rendering.
451
+ * @param [force] Whether to force initialization.
452
+ * @returns A promise that resolves when initialization is complete.
453
+ */
454
+ __publicField(this, "initWjElement", (force = false) => {
437
455
  return new Promise(async (resolve, reject) => {
438
456
  var _a;
439
457
  this.drawingStatus = this.drawingStatuses.BEGINING;
440
458
  (_a = this.setupAttributes) == null ? void 0 : _a.call(this);
441
459
  if (this.isShadowRoot) {
442
- !this.shadowRoot && this.attachShadow({ mode: this.shadowType || "open" });
460
+ if (!this.shadowRoot) this.attachShadow({ mode: this.shadowType || "open" });
443
461
  }
444
462
  this.setUpAccessors();
445
463
  this.drawingStatus = this.drawingStatuses.START;
446
464
  await this.display(force);
447
- if (typeof this.constructor.cssStyleSheet === "string" && this.constructor.cssStyleSheet) {
448
- const sheet = new CSSStyleSheet();
449
- sheet.replaceSync(this.constructor.cssStyleSheet);
450
- this.context.adoptedStyleSheets = [sheet];
451
- }
465
+ const sheet = new CSSStyleSheet();
466
+ sheet.replaceSync(this.constructor.cssStyleSheet);
467
+ this.context.adoptedStyleSheets = [sheet];
452
468
  resolve();
453
469
  });
454
470
  });
455
- this.template = componentTemplate || template;
456
471
  this.isAttached = false;
457
472
  this.service = new UniversalService({
458
473
  store
@@ -461,6 +476,7 @@ const _WJElement = class _WJElement extends HTMLElement {
461
476
  this.rendering = false;
462
477
  this._dependencies = {};
463
478
  this.drawingStatuses = {
479
+ CREATED: 0,
464
480
  ATTACHED: 1,
465
481
  BEGINING: 2,
466
482
  START: 3,
@@ -468,28 +484,74 @@ const _WJElement = class _WJElement extends HTMLElement {
468
484
  DONE: 5,
469
485
  DISCONNECTED: 6
470
486
  };
487
+ this.drawingStatus = this.drawingStatuses.CREATED;
488
+ }
489
+ /**
490
+ * Sets the value of the 'permission' attribute.
491
+ * @param {string[]} value The value to set for the 'permission' attribute.
492
+ */
493
+ set permission(value) {
494
+ this.setAttribute("permission", value.join(","));
471
495
  }
496
+ /**
497
+ * Gets the value of the 'permission-check' attribute.
498
+ * @returns {string[]} The value of the 'permission' attribute.
499
+ */
472
500
  get permission() {
473
- return this.getAttribute("permission-check");
501
+ var _a;
502
+ return ((_a = this.getAttribute("permission")) == null ? void 0 : _a.split(",")) || [];
503
+ }
504
+ /**
505
+ * Sets the 'permission-check' attribute.
506
+ * @param {boolean} value The value to set for the 'permission-check' attribute.
507
+ */
508
+ set isPermissionCheck(value) {
509
+ if (value) this.setAttribute("permission-check", "");
510
+ else this.removeAttribute("permission-check");
474
511
  }
512
+ /**
513
+ * Checks if the 'permission-check' attribute is present.
514
+ * @returns {boolean} True if the 'permission-check' attribute is present.
515
+ */
475
516
  get isPermissionCheck() {
476
517
  return this.hasAttribute("permission-check");
477
518
  }
478
- set isPermissionCheck(shadow) {
479
- return this.setAttribute("permission-check", "permission-check");
519
+ set noShow(value) {
520
+ if (value) this.setAttribute("no-show", "");
521
+ else this.removeAttribute("no-show");
480
522
  }
481
- get isShow() {
482
- return this.hasAttribute("show");
523
+ /**
524
+ * Checks if the 'show' attribute is present.
525
+ * @returns {boolean} True if the 'show' attribute is present.
526
+ */
527
+ get noShow() {
528
+ return this.hasAttribute("no-show");
529
+ }
530
+ /**
531
+ * Sets the 'shadow' attribute.
532
+ * @param value The value to set for the 'shadow' attribute.
533
+ */
534
+ set isShadowRoot(value) {
535
+ return this.setAttribute("shadow", value);
483
536
  }
537
+ /**
538
+ * Checks if the 'shadow' attribute is present.
539
+ * @returns {boolean} True if the 'shadow' attribute is present.
540
+ */
484
541
  get isShadowRoot() {
485
542
  return this.hasAttribute("shadow");
486
543
  }
487
- set isShadowRoot(shadow) {
488
- return this.setAttribute("shadow", shadow);
489
- }
544
+ /**
545
+ * Gets the value of the 'shadow' attribute or 'open' if not set.
546
+ * @returns {string} The value of the 'shadow' attribute or 'open'.
547
+ */
490
548
  get shadowType() {
491
549
  return this.getAttribute("shadow") || "open";
492
550
  }
551
+ /**
552
+ * Gets the rendering context, either the shadow root or the component itself.
553
+ * @returns The rendering context.
554
+ */
493
555
  get context() {
494
556
  if (this.isShadowRoot) {
495
557
  return this.shadowRoot;
@@ -497,65 +559,125 @@ const _WJElement = class _WJElement extends HTMLElement {
497
559
  return this;
498
560
  }
499
561
  }
562
+ /**
563
+ * Gets the store instance.
564
+ * @returns {object} The store instance.
565
+ */
500
566
  get store() {
501
567
  return store;
502
568
  }
503
- // addAction,
504
- // deleteAction,
505
- // loadAction,
506
- // updateAction,
507
- // addManyAction
508
569
  /**
509
- * @typedef {Object} ArrayActions
510
- * @property {function} addAction - Indicates whether the Courage component is present.
511
- * @property {function} deleteAction - Indicates whether the Power component is present.
512
- * @property {function} loadAction - Indicates whether the Wisdom component is present.
513
- * @property {function} updateAction - Indicates whether the Wisdom component is present.
570
+ * @typedef {object} ArrayActions
571
+ * @property {Function} addAction - Adds an item to the array.
572
+ * @property {Function} deleteAction - Deletes an item from the array.
573
+ * @property {Function} loadAction - Loads an array.
574
+ * @property {Function} updateAction - Updates an item in the array.
575
+ * @property {Function} addManyAction - Adds many items to the array.
514
576
  */
515
577
  /**
516
- * @typedef {Object} ObjectActions
517
- * @property {function} addAction - Indicates whether the Courage component is present.
518
- * @property {function} deleteAction - Indicates whether the Power component is present.
519
- * @property {function} updateAction - Indicates whether the Wisdom component is present.
578
+ * @typedef {object} ObjectActions
579
+ * @property {Function} addAction - Replace old object with new object
580
+ * @property {Function} deleteAction - Delete item based on key
581
+ * @property {Function} updateAction - Update item based on key
520
582
  */
521
583
  /**
522
- * @typedef {Object} StoreActions
584
+ * Gets the default store actions.
585
+ * @returns The default store actions for arrays and objects.
523
586
  */
524
587
  get defaultStoreActions() {
525
588
  return defaultStoreActions;
526
589
  }
590
+ /**
591
+ * Gets the classes to be removed after the component is connected.
592
+ * @returns An array of class names to remove.
593
+ */
527
594
  get removeClassAfterConnect() {
528
595
  var _a;
529
596
  return (_a = this.getAttribute("remove-class-after-connect")) == null ? void 0 : _a.split(" ");
530
597
  }
531
- get dependencies() {
532
- return this._dependencies;
533
- }
598
+ /**
599
+ * Sets the component dependencies.
600
+ * @param value The dependencies to set.
601
+ */
534
602
  set dependencies(value) {
535
603
  this._dependencies = value;
536
604
  }
605
+ /**
606
+ * Gets the component dependencies.
607
+ * @returns The component dependencies.
608
+ */
609
+ get dependencies() {
610
+ return this._dependencies;
611
+ }
612
+ /**
613
+ * Defines a custom element if not already defined.
614
+ * @param name The name of the custom element.
615
+ * @param [elementConstructor] The constructor for the custom element.
616
+ * @param [options] Additional options for defining the element.
617
+ */
537
618
  static define(name, elementConstructor = this, options = {}) {
538
619
  const definedElement = customElements.get(name);
539
620
  if (!definedElement) {
540
621
  customElements.define(name, elementConstructor, options);
541
- return;
542
622
  }
543
623
  }
624
+ /**
625
+ * Defines component dependencies by registering custom elements.
626
+ */
544
627
  defineDependencies() {
545
628
  if (this.dependencies)
546
629
  Object.entries(this.dependencies).forEach((name, component) => _WJElement.define(name, component));
547
630
  }
548
- beforeDraw() {
631
+ /**
632
+ * Hook for extending behavior before drawing the component.
633
+ * @param context The rendering context, usually the element's shadow root or main DOM element.
634
+ * @param appStoreObj The global application store for managing state.
635
+ * @param params Additional parameters or attributes for rendering the component.
636
+ */
637
+ beforeDraw(context, appStoreObj, params) {
638
+ }
639
+ /**
640
+ * Renders the component within the provided context.
641
+ * @param context The rendering context, usually the element's shadow root or main DOM element.
642
+ * @param appStoreObj
643
+ * @param params Additional parameters or attributes for rendering the component.
644
+ * @returns This implementation does not render anything and returns `null`.
645
+ * @description
646
+ * The `draw` method is responsible for rendering the component's content.
647
+ * Override this method in subclasses to define custom rendering logic.
648
+ * @example
649
+ * class MyComponent extends WJElement {
650
+ * draw(context, appStoreObj, params) {
651
+ * const div = document.createElement('div');
652
+ * div.textContent = 'Hello, world!';
653
+ * context.appendChild(div);
654
+ * }
655
+ * }
656
+ */
657
+ draw(context, appStoreObj, params) {
658
+ return null;
549
659
  }
550
- afterDraw() {
660
+ /**
661
+ * Hook for extending behavior after drawing the component.
662
+ * @param context The rendering context, usually the element's shadow root or main DOM element.
663
+ * @param appStoreObj The global application store for managing state.
664
+ * @param params Additional parameters or attributes for rendering the component.
665
+ */
666
+ afterDraw(context, appStoreObj, params) {
551
667
  }
668
+ /**
669
+ * Refreshes the update promise for rendering lifecycle management.
670
+ */
552
671
  refreshUpdatePromise() {
553
672
  this.updateComplete = new Promise((resolve, reject) => {
554
673
  this.finisPromise = resolve;
555
674
  this.rejectPromise = reject;
556
675
  });
557
676
  }
558
- async connectedCallback() {
677
+ /**
678
+ * Lifecycle method invoked when the component is connected to the DOM.
679
+ */
680
+ connectedCallback() {
559
681
  this.drawingStatus = this.drawingStatuses.ATTACHED;
560
682
  this.finisPromise = (resolve) => {
561
683
  resolve();
@@ -566,6 +688,12 @@ const _WJElement = class _WJElement extends HTMLElement {
566
688
  this.refreshUpdatePromise();
567
689
  this.renderPromise = this.initWjElement(true);
568
690
  }
691
+ /**
692
+ * Sets up attributes and event listeners for the component.
693
+ * This method retrieves all custom events defined for the component
694
+ * and adds event listeners for each of them. When an event is triggered,
695
+ * it calls the corresponding method on the host element.
696
+ */
569
697
  setupAttributes() {
570
698
  let allEvents = WjElementUtils.getEvents(this);
571
699
  allEvents.forEach((customEvent, domEvent) => {
@@ -576,25 +704,28 @@ const _WJElement = class _WJElement extends HTMLElement {
576
704
  });
577
705
  }
578
706
  /**
579
- * This method is called before the element is disconnected from the DOM.
707
+ * Hook for extending behavior before disconnecting the component.
580
708
  */
581
709
  beforeDisconnect() {
582
710
  }
583
711
  /**
584
- * This method is called after the element is disconnected from the DOM.
712
+ * Hook for extending behavior after disconnecting the component.
585
713
  */
586
714
  afterDisconnect() {
587
715
  }
588
716
  /**
589
- * This method is called before the element is redrawn.
717
+ * Hook for extending behavior before redrawing the component.
590
718
  */
591
719
  beforeRedraw() {
592
720
  }
593
721
  /**
594
- * Cleans up the component.
722
+ * Cleans up resources and event listeners for the component.
595
723
  */
596
724
  componentCleanup() {
597
725
  }
726
+ /**
727
+ * Lifecycle method invoked when the component is disconnected from the DOM.
728
+ */
598
729
  disconnectedCallback() {
599
730
  var _a, _b;
600
731
  (_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
@@ -604,26 +735,30 @@ const _WJElement = class _WJElement extends HTMLElement {
604
735
  this.drawingStatus = this.drawingStatuses.DISCONNECTED;
605
736
  this.componentCleanup();
606
737
  }
607
- // internal method
608
738
  /**
609
- * Enqueues an update for the element.
610
- *
611
- * @returns {Promise} A promise that resolves when the update is complete.
739
+ * Enqueues an update to the component.
740
+ * @returns A promise that resolves when the update is complete.
612
741
  */
613
742
  async enqueueUpdate() {
614
743
  try {
615
- await this.renderPromise;
744
+ if (this.renderPromise && this.renderPromise instanceof Promise) {
745
+ await this.renderPromise;
746
+ }
616
747
  } catch (e) {
748
+ console.error("An error occurred:", e);
617
749
  Promise.reject(e);
618
750
  }
619
751
  const result = this.refresh();
620
- if (result != null) {
752
+ if (result !== null) {
621
753
  await result;
622
754
  }
623
755
  this.renderPromise = null;
624
756
  }
625
757
  /**
626
- * Lifecycle method, called whenever an observed property changes
758
+ * Lifecycle method invoked when an observed attribute changes.
759
+ * @param name The name of the attribute that changed.
760
+ * @param old The old value of the attribute.
761
+ * @param newName The new value of the attribute.
627
762
  */
628
763
  attributeChangedCallback(name, old, newName) {
629
764
  if (old !== newName) {
@@ -631,12 +766,18 @@ const _WJElement = class _WJElement extends HTMLElement {
631
766
  }
632
767
  }
633
768
  /**
634
- * Refreshes the element.
635
- * Re-renders the element and updates the shadow DOM.
636
- *
637
- * @returns {Promise<void>} A promise that resolves when the element has been refreshed.
769
+ * Refreshes the component by reinitializing it if it is in a drawing state.
770
+ * This method checks if the component's drawing status is at least in the START state.
771
+ * If so, it performs the following steps:
772
+ * 1. Calls the `beforeRedraw` hook if defined.
773
+ * 2. Calls the `beforeDisconnect` hook if defined.
774
+ * 3. Refreshes the update promise to manage the rendering lifecycle.
775
+ * 4. Calls the `afterDisconnect` hook if defined.
776
+ * 5. Reinitializes the component by calling `initWjElement` with `true` to force initialization.
777
+ * If the component is not in a drawing state, it simply returns a resolved promise.
778
+ * @returns {Promise<void>} A promise that resolves when the refresh is complete.
638
779
  */
639
- async refresh() {
780
+ refresh() {
640
781
  var _a, _b, _c;
641
782
  if (this.drawingStatus && this.drawingStatus >= this.drawingStatuses.START) {
642
783
  (_a = this.beforeRedraw) == null ? void 0 : _a.call(this);
@@ -645,39 +786,49 @@ const _WJElement = class _WJElement extends HTMLElement {
645
786
  (_c = this.afterDisconnect) == null ? void 0 : _c.call(this);
646
787
  return this.initWjElement(true);
647
788
  }
648
- }
649
- /**
650
- * To be implemented by the child class
651
- */
652
- draw(context, store2, params) {
789
+ return Promise.resolve();
790
+ }
791
+ /**
792
+ * Renders the component within the provided context.
793
+ * @param context The rendering context, usually the element's shadow root or main DOM element.
794
+ * @param appStore The global application store for managing state.
795
+ * @param params Additional parameters or attributes for rendering the component.
796
+ * @returns This implementation does not render anything and returns `null`.
797
+ * @description
798
+ * The `draw` method is responsible for rendering the component's content.
799
+ * Override this method in subclasses to define custom rendering logic.
800
+ * @example
801
+ * class MyComponent extends WJElement {
802
+ * draw(context, appStore, params) {
803
+ * const div = document.createElement('div');
804
+ * div.textContent = 'Hello, world!';
805
+ * context.appendChild(div);
806
+ * }
807
+ * }
808
+ */
809
+ draw(context, appStore, params) {
653
810
  return null;
654
811
  }
655
812
  /**
656
- * Displays the element.
657
- *
658
- * @param {boolean} [force=false] - Indicates whether to force the display of the element.
659
- * @returns {Promise} - A promise that resolves when the element is rendered.
813
+ * Displays the component's content, optionally forcing a re-render.
814
+ * @param [force] Whether to force a re-render.
815
+ * @returns A promise that resolves when the display is complete.
660
816
  */
661
817
  display(force = false) {
818
+ this.template = this.constructor.customTemplate || document.createElement("template");
662
819
  if (force) {
663
820
  [...this.context.childNodes].forEach(this.context.removeChild.bind(this.context));
664
821
  this.isAttached = false;
665
822
  }
666
823
  this.context.append(this.template.content.cloneNode(true));
667
- if (this.isPermissionCheck || this.isShow) {
668
- if (WjePermissionsApi.isPermissionFulfilled.bind(this)(this.permission)) {
669
- this.drawingStatus = this.drawingStatuses.DRAWING;
670
- return this._resolveRender();
671
- } else {
672
- this.remove();
673
- }
674
- } else {
675
- return this._resolveRender();
824
+ if (this.noShow || this.isPermissionCheck && !WjePermissionsApi.isPermissionFulfilled(this.permission)) {
825
+ this.remove();
826
+ return Promise.resolve();
676
827
  }
828
+ return this._resolveRender();
677
829
  }
678
830
  /**
679
- * Renders the element.
680
- * @returns {Promise<void>} A promise that resolves when the rendering is complete.
831
+ * Renders the component's content.
681
832
  */
682
833
  async render() {
683
834
  this.drawingStatus = this.drawingStatuses.DRAWING;
@@ -690,29 +841,46 @@ const _WJElement = class _WJElement extends HTMLElement {
690
841
  if (rend instanceof HTMLElement || rend instanceof DocumentFragment) {
691
842
  element = rend;
692
843
  } else {
693
- let template2 = document.createElement("template");
694
- template2.innerHTML = rend;
695
- element = template2.content.cloneNode(true);
844
+ let inputTemplate = document.createElement("template");
845
+ inputTemplate.innerHTML = rend;
846
+ element = inputTemplate.content.cloneNode(true);
696
847
  }
697
848
  let rendered = element;
698
849
  this.context.appendChild(rendered);
699
850
  }
700
851
  /**
701
- * Turns a string split with "-" into camel case notation
852
+ * Sanitizes a given name by converting it from kebab-case to camelCase.
853
+ * @param {string} name The name in kebab-case format (e.g., "example-name").
854
+ * @returns {string} The sanitized name in camelCase format (e.g., "exampleName").
855
+ * @example
856
+ * // Returns 'exampleName'
857
+ * sanitizeName('example-name');
858
+ * @example
859
+ * // Returns 'myCustomComponent'
860
+ * sanitizeName('my-custom-component');
702
861
  */
703
862
  sanitizeName(name) {
704
863
  let parts = name.split("-");
705
864
  return [parts.shift(), ...parts.map((n) => n[0].toUpperCase() + n.slice(1))].join("");
706
865
  }
707
866
  /**
708
- * Checks if an object has a getter and/or setter for a given property.
709
- *
710
- * @param {Object} obj - The object to check.
711
- * @param {string} property - The property to check for getter and/or setter.
712
- * @returns {Object} - An object containing information about the getter and/or setter.
713
- * - If the getter exists, it will be assigned to the `hasGetter` property.
714
- * - If the setter exists, it will be assigned to the `hasSetter` property.
715
- * - If neither getter nor setter exists, both `hasGetter` and `hasSetter` will be `null`.
867
+ * Checks if a property on an object has a getter or setter method defined.
868
+ * @param {object} obj The object on which the property is defined.
869
+ * @param {string} property The name of the property to check.
870
+ * @returns {object} An object indicating the presence of getter and setter methods.
871
+ * @property {Function|null} hasGetter The getter function if it exists, otherwise `null`.
872
+ * @property {Function|null} hasSetter The setter function if it exists, otherwise `null`.
873
+ * @example
874
+ * const obj = {
875
+ * get name() { return 'value'; },
876
+ * set name(val) { console.log(val); }
877
+ * };
878
+ * // Returns { hasGetter: [Function: get name], hasSetter: [Function: set name] }
879
+ * checkGetterSetter(obj, 'name');
880
+ * @example
881
+ * const obj = { prop: 42 };
882
+ * // Returns { hasGetter: null, hasSetter: null }
883
+ * checkGetterSetter(obj, 'prop');
716
884
  */
717
885
  checkGetterSetter(obj, property) {
718
886
  let descriptor = Object.getOwnPropertyDescriptor(obj, property);
@@ -729,8 +897,7 @@ const _WJElement = class _WJElement extends HTMLElement {
729
897
  return { hasGetter: null, hasSetter: null };
730
898
  }
731
899
  /**
732
- * Creates one property on this class for every
733
- * HTML property defined on the element
900
+ * Sets up property accessors for the component's attributes.
734
901
  */
735
902
  setUpAccessors() {
736
903
  let attrs = this.getAttributeNames();
@@ -744,11 +911,11 @@ const _WJElement = class _WJElement extends HTMLElement {
744
911
  });
745
912
  }
746
913
  /**
747
- * Resolves the rendering of the element.
748
- *
749
- * @returns {Promise<void>} A promise that resolves when the rendering is complete.
914
+ * Resolves the rendering process of the component.
915
+ * @returns A promise that resolves when rendering is complete.
916
+ * @private
750
917
  */
751
- async _resolveRender() {
918
+ _resolveRender() {
752
919
  this.params = WjElementUtils.getAttributes(this);
753
920
  return new Promise(async (resolve, reject) => {
754
921
  var _a;
@@ -764,7 +931,9 @@ const _WJElement = class _WJElement extends HTMLElement {
764
931
  this.finisPromise();
765
932
  this.rendering = false;
766
933
  this.isAttached = true;
767
- this.removeClassAfterConnect && this.classList.remove(...this.removeClassAfterConnect);
934
+ if (this.removeClassAfterConnect) {
935
+ this.classList.remove(...this.removeClassAfterConnect);
936
+ }
768
937
  this.drawingStatus = this.drawingStatuses.DONE;
769
938
  resolve();
770
939
  }).catch((e) => {
@@ -772,9 +941,15 @@ const _WJElement = class _WJElement extends HTMLElement {
772
941
  });
773
942
  }
774
943
  };
775
- __publicField(_WJElement, "processTemplates", (pTemplate, template2) => {
944
+ /**
945
+ * Processes and combines two templates into one.
946
+ * @param pTemplate The primary template.
947
+ * @param inputTemplate The secondary template.
948
+ * @returns The combined template.
949
+ */
950
+ __publicField(_WJElement, "processTemplates", (pTemplate, inputTemplate) => {
776
951
  const newTemplate = document.createElement("template");
777
- newTemplate.innerHTML = [template2.innerHTML, (pTemplate == null ? void 0 : pTemplate.innerHTML) || ""].join("");
952
+ newTemplate.innerHTML = [inputTemplate.innerHTML, (pTemplate == null ? void 0 : pTemplate.innerHTML) || ""].join("");
778
953
  return newTemplate;
779
954
  });
780
955
  let WJElement = _WJElement;