wj-elements 0.1.128 → 0.1.129

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 (94) hide show
  1. package/dist/dark.css +6 -1
  2. package/dist/{infinite-scroll.element-DcO1E5Es.js → infinite-scroll.element-R3y_ZQj6.js} +42 -14
  3. package/dist/light.css +5 -0
  4. package/dist/{list.element-TZXMx1rt.js → list.element-syl98NWS.js} +4 -1
  5. package/dist/localize.js +4 -3
  6. package/dist/{popup.element-l8v-dMoK.js → popup.element-C0a1z1y2.js} +191 -78
  7. package/dist/wje-accordion-item.js +1 -1
  8. package/dist/wje-animation.js +141 -13
  9. package/dist/wje-aside.js +1 -1
  10. package/dist/wje-avatar.js +5 -5
  11. package/dist/wje-badge.js +1 -1
  12. package/dist/wje-breadcrumb.js +16 -6
  13. package/dist/wje-breadcrumbs.js +4 -4
  14. package/dist/wje-button-group.js +2 -2
  15. package/dist/wje-button.js +64 -6
  16. package/dist/wje-card-content.js +1 -1
  17. package/dist/wje-card-controls.js +1 -1
  18. package/dist/wje-card-header.js +1 -1
  19. package/dist/wje-card-subtitle.js +1 -1
  20. package/dist/wje-card-title.js +1 -1
  21. package/dist/wje-carousel-item.js +1 -1
  22. package/dist/wje-carousel.js +1 -1
  23. package/dist/wje-checkbox.js +14 -11
  24. package/dist/wje-chip.js +1 -1
  25. package/dist/wje-col.js +9 -3
  26. package/dist/wje-color-picker.js +72 -42
  27. package/dist/wje-container.js +1 -1
  28. package/dist/wje-copy-button.js +3 -3
  29. package/dist/wje-dialog.js +89 -0
  30. package/dist/wje-divider.js +1 -1
  31. package/dist/wje-dropdown.js +21 -6
  32. package/dist/wje-element.js +284 -127
  33. package/dist/wje-fetchAndParseCSS.js +2 -1
  34. package/dist/wje-file-upload-item.js +5 -2
  35. package/dist/wje-file-upload.js +57 -13
  36. package/dist/wje-footer.js +1 -1
  37. package/dist/wje-form.js +1 -1
  38. package/dist/wje-format-digital.js +1 -1
  39. package/dist/wje-grid.js +1 -1
  40. package/dist/wje-header.js +1 -1
  41. package/dist/wje-icon-picker.js +6 -3
  42. package/dist/wje-icon.js +4 -1
  43. package/dist/wje-img-comparer.js +1 -3
  44. package/dist/wje-img.js +5 -2
  45. package/dist/wje-infinite-scroll.js +1 -1
  46. package/dist/wje-input-file.js +4 -1
  47. package/dist/wje-input.js +9 -4
  48. package/dist/wje-item.js +34 -3
  49. package/dist/wje-kanban.js +16 -31
  50. package/dist/wje-label.js +1 -10
  51. package/dist/wje-list.js +1 -1
  52. package/dist/wje-main.js +1 -1
  53. package/dist/wje-masonry.js +9 -9
  54. package/dist/wje-master.js +9 -117
  55. package/dist/wje-menu-button.js +4 -1
  56. package/dist/wje-menu-item.js +13 -4
  57. package/dist/wje-menu-label.js +1 -1
  58. package/dist/wje-menu.js +4 -1
  59. package/dist/wje-option.js +8 -4
  60. package/dist/wje-options.js +25 -11
  61. package/dist/wje-orgchart-group.js +2 -2
  62. package/dist/wje-orgchart-item.js +7 -4
  63. package/dist/wje-orgchart.js +1 -1
  64. package/dist/wje-popup.js +1 -1
  65. package/dist/wje-progress-bar.js +6 -2
  66. package/dist/wje-qr-code.js +2 -2
  67. package/dist/wje-radio-group.js +4 -1
  68. package/dist/wje-radio.js +1 -1
  69. package/dist/wje-rate.js +6 -3
  70. package/dist/wje-relative-time.js +37 -19
  71. package/dist/wje-reorder.js +73 -10
  72. package/dist/wje-route.js +1 -1
  73. package/dist/wje-router-link.js +1 -2
  74. package/dist/wje-routerx.js +3 -1
  75. package/dist/wje-row.js +1 -11
  76. package/dist/wje-select.js +15 -12
  77. package/dist/wje-slider.js +7 -4
  78. package/dist/wje-sliding-container.js +125 -49
  79. package/dist/wje-split-view.js +10 -2
  80. package/dist/wje-status.js +1 -1
  81. package/dist/wje-stepper.js +879 -766
  82. package/dist/wje-store.js +17 -18
  83. package/dist/wje-tab-group.js +4 -1
  84. package/dist/wje-tab-panel.js +1 -1
  85. package/dist/wje-tab.js +4 -1
  86. package/dist/wje-textarea.js +8 -2
  87. package/dist/wje-thumbnail.js +1 -9
  88. package/dist/wje-toast.js +24 -23
  89. package/dist/wje-toggle.js +7 -1
  90. package/dist/wje-toolbar-action.js +1 -1
  91. package/dist/wje-toolbar.js +1 -1
  92. package/dist/wje-tooltip.js +5 -1
  93. package/dist/wje-visually-hidden.js +1 -1
  94. package/package.json +16 -5
@@ -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) {
@@ -217,8 +200,6 @@ class WjePermissionsApi {
217
200
  }
218
201
  }
219
202
  class WjElementUtils {
220
- constructor() {
221
- }
222
203
  /**
223
204
  * This function creates an element
224
205
  * @param element : HTMLElement
@@ -238,7 +219,7 @@ class WjElementUtils {
238
219
  if (typeof el === "string")
239
220
  el = document.querySelector(el);
240
221
  return Array.from(el.attributes).filter((a) => !a.name.startsWith("@")).map((a) => [a.name.split("-").map((s, i) => {
241
- if (i != 0) {
222
+ if (i !== 0) {
242
223
  return s.charAt(0).toUpperCase() + s.slice(1);
243
224
  } else {
244
225
  return s;
@@ -300,11 +281,13 @@ class WjElementUtils {
300
281
  }
301
282
  /**
302
283
  * This function converts a string to a boolean
303
- * @param string
284
+ * @param value
304
285
  * @returns {boolean}
305
286
  */
306
- static stringToBoolean(string) {
307
- return !["false", "0", 0].includes(string);
287
+ static stringToBoolean(value) {
288
+ if (typeof value === "boolean")
289
+ return value;
290
+ return !["false", "0", 0].includes(value);
308
291
  }
309
292
  }
310
293
  var self;
@@ -314,6 +297,12 @@ class Event {
314
297
  this.customEventStorage = [];
315
298
  self = this;
316
299
  }
300
+ /**
301
+ * Dispatch custom event
302
+ * @param element
303
+ * @param event
304
+ * @param detail
305
+ */
317
306
  dispatchCustomEvent(element, event2, detail) {
318
307
  element.dispatchEvent(
319
308
  new CustomEvent(event2, {
@@ -322,19 +311,33 @@ class Event {
322
311
  event: self
323
312
  },
324
313
  bubbles: true,
325
- composed: true
314
+ composed: true,
315
+ cancelable: true
326
316
  })
327
317
  );
328
318
  }
319
+ /**
320
+ * Find record by element
321
+ * @param element
322
+ * @returns {*|boolean}
323
+ */
329
324
  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) {
325
+ for (let index = 0, length = this.customEventStorage.length; index < length; index++) {
326
+ let record = this.customEventStorage[index];
327
+ if (element === record.element) {
333
328
  return record;
334
329
  }
335
330
  }
336
331
  return false;
337
332
  }
333
+ /**
334
+ * Add listener to the element
335
+ * @param element
336
+ * @param originalEvent
337
+ * @param event
338
+ * @param listener
339
+ * @param options
340
+ */
338
341
  addListener(element, originalEvent, event2, listener, options) {
339
342
  if (!element)
340
343
  return;
@@ -344,6 +347,14 @@ class Event {
344
347
  this.writeRecord(el, originalEvent, event2, listener, options);
345
348
  });
346
349
  }
350
+ /**
351
+ * Write record to the storage
352
+ * @param element
353
+ * @param originalEvent
354
+ * @param event
355
+ * @param listener
356
+ * @param options
357
+ */
347
358
  writeRecord(element, originalEvent, event2, listener, options) {
348
359
  let record = this.findRecordByElement(element);
349
360
  if (record) {
@@ -377,15 +388,30 @@ class Event {
377
388
  deepEqual(x, y) {
378
389
  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
390
  }
391
+ /**
392
+ * Check if the listener already exists
393
+ * @param element
394
+ * @param event
395
+ * @param listener
396
+ * @returns {*}
397
+ */
380
398
  listenerExists(element, event2, listener) {
381
399
  let record = this.findRecordByElement(element);
382
400
  return record.listeners[event2].some((e) => this.deepEqual(e, listener));
383
401
  }
402
+ /**
403
+ * Remove listener from the element
404
+ * @param element
405
+ * @param originalEvent
406
+ * @param event
407
+ * @param listener
408
+ * @param options
409
+ */
384
410
  removeListener(element, originalEvent, event2, listener, options) {
385
411
  let record = this.findRecordByElement(element);
386
412
  if (record && originalEvent in record.listeners) {
387
- var index = record.listeners[originalEvent].indexOf(listener);
388
- if (~index) {
413
+ let index = record.listeners[originalEvent].indexOf(listener);
414
+ if (index !== -1) {
389
415
  record.listeners[originalEvent].splice(index, 1);
390
416
  }
391
417
  if (!record.listeners[originalEvent].length) {
@@ -395,10 +421,13 @@ class Event {
395
421
  listener = listener || __privateMethod(this, _Event_instances, dispatch_fn);
396
422
  element.removeEventListener(originalEvent, listener, options);
397
423
  }
424
+ /**
425
+ * Remove all listeners from the element
426
+ * @param element
427
+ */
398
428
  removeElement(element) {
399
429
  this.customEventStorage = this.customEventStorage.filter((e) => {
400
- if (e.element !== element)
401
- return e;
430
+ return e.element !== element;
402
431
  });
403
432
  }
404
433
  // TODO
@@ -413,11 +442,15 @@ class Event {
413
442
  }
414
443
  }
415
444
  _Event_instances = new WeakSet();
445
+ /**
446
+ * Dispatch event to the element
447
+ * @param e
448
+ */
416
449
  dispatch_fn = function(e) {
417
450
  let element = this;
418
451
  let record = self.findRecordByElement(element);
419
452
  let listeners = record.listeners[e.type];
420
- listeners.forEach((listener, i) => {
453
+ listeners.forEach((listener) => {
421
454
  self.dispatchCustomEvent(element, listener.event, {
422
455
  originalEvent: (e == null ? void 0 : e.type) || null,
423
456
  context: element,
@@ -431,24 +464,34 @@ let event = new Event();
431
464
  const template = document.createElement("template");
432
465
  template.innerHTML = ``;
433
466
  const _WJElement = class _WJElement extends HTMLElement {
467
+ /**
468
+ * Initializes a new instance of the WJElement class.
469
+ *
470
+ * @param {HTMLTemplateElement} [componentTemplate] - The template to use for this component.
471
+ */
434
472
  constructor(componentTemplate) {
435
473
  super();
436
- __publicField(this, "initWjElement", async (force = false) => {
474
+ /**
475
+ * Initializes the component, setting up attributes and rendering.
476
+ *
477
+ * @param {boolean} [force=false] - Whether to force initialization.
478
+ * @return {Promise<void>} A promise that resolves when initialization is complete.
479
+ */
480
+ __publicField(this, "initWjElement", (force = false) => {
437
481
  return new Promise(async (resolve, reject) => {
438
482
  var _a;
439
483
  this.drawingStatus = this.drawingStatuses.BEGINING;
440
484
  (_a = this.setupAttributes) == null ? void 0 : _a.call(this);
441
485
  if (this.isShadowRoot) {
442
- !this.shadowRoot && this.attachShadow({ mode: this.shadowType || "open" });
486
+ if (!this.shadowRoot)
487
+ this.attachShadow({ mode: this.shadowType || "open" });
443
488
  }
444
489
  this.setUpAccessors();
445
490
  this.drawingStatus = this.drawingStatuses.START;
446
491
  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
- }
492
+ const sheet = new CSSStyleSheet();
493
+ sheet.replaceSync(this.constructor.cssStyleSheet);
494
+ this.context.adoptedStyleSheets = [sheet];
452
495
  resolve();
453
496
  });
454
497
  });
@@ -461,6 +504,7 @@ const _WJElement = class _WJElement extends HTMLElement {
461
504
  this.rendering = false;
462
505
  this._dependencies = {};
463
506
  this.drawingStatuses = {
507
+ CREATED: 0,
464
508
  ATTACHED: 1,
465
509
  BEGINING: 2,
466
510
  START: 3,
@@ -468,28 +512,69 @@ const _WJElement = class _WJElement extends HTMLElement {
468
512
  DONE: 5,
469
513
  DISCONNECTED: 6
470
514
  };
515
+ this.drawingStatus = this.drawingStatuses.CREATED;
471
516
  }
517
+ /**
518
+ * Gets the value of the 'permission-check' attribute.
519
+ *
520
+ * @return {string|null} The value of the 'permission-check' attribute or null if not set.
521
+ */
472
522
  get permission() {
473
523
  return this.getAttribute("permission-check");
474
524
  }
475
- get isPermissionCheck() {
476
- return this.hasAttribute("permission-check");
477
- }
525
+ /**
526
+ * Sets the 'permission-check' attribute.
527
+ *
528
+ * @param {string} shadow - The value to set for the 'permission-check' attribute.
529
+ */
478
530
  set isPermissionCheck(shadow) {
479
531
  return this.setAttribute("permission-check", "permission-check");
480
532
  }
533
+ /**
534
+ * Checks if the 'permission-check' attribute is present.
535
+ *
536
+ * @return {boolean} True if the 'permission-check' attribute is present.
537
+ */
538
+ get isPermissionCheck() {
539
+ return this.hasAttribute("permission-check");
540
+ }
541
+ /**
542
+ * Checks if the 'show' attribute is present.
543
+ *
544
+ * @return {boolean} True if the 'show' attribute is present.
545
+ */
481
546
  get isShow() {
482
547
  return this.hasAttribute("show");
483
548
  }
549
+ /**
550
+ * Sets the 'shadow' attribute.
551
+ *
552
+ * @param {string} shadow - The value to set for the 'shadow' attribute.
553
+ */
554
+ set isShadowRoot(value) {
555
+ return this.setAttribute("shadow", value);
556
+ }
557
+ /**
558
+ * Checks if the 'shadow' attribute is present.
559
+ *
560
+ * @return {boolean} True if the 'shadow' attribute is present.
561
+ */
484
562
  get isShadowRoot() {
485
563
  return this.hasAttribute("shadow");
486
564
  }
487
- set isShadowRoot(shadow) {
488
- return this.setAttribute("shadow", shadow);
489
- }
565
+ /**
566
+ * Gets the value of the 'shadow' attribute or 'open' if not set.
567
+ *
568
+ * @return {string} The value of the 'shadow' attribute or 'open'.
569
+ */
490
570
  get shadowType() {
491
571
  return this.getAttribute("shadow") || "open";
492
572
  }
573
+ /**
574
+ * Gets the rendering context, either the shadow root or the component itself.
575
+ *
576
+ * @return {HTMLElement|ShadowRoot} The rendering context.
577
+ */
493
578
  get context() {
494
579
  if (this.isShadowRoot) {
495
580
  return this.shadowRoot;
@@ -497,65 +582,112 @@ const _WJElement = class _WJElement extends HTMLElement {
497
582
  return this;
498
583
  }
499
584
  }
585
+ /**
586
+ * Gets the store instance.
587
+ *
588
+ * @return {Object} The store instance.
589
+ */
500
590
  get store() {
501
591
  return store;
502
592
  }
503
- // addAction,
504
- // deleteAction,
505
- // loadAction,
506
- // updateAction,
507
- // addManyAction
508
593
  /**
509
594
  * @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.
595
+ * @property {function} addAction - Adds an item to the array.
596
+ * @property {function} deleteAction - Deletes an item from the array.
597
+ * @property {function} loadAction - Loads an array.
598
+ * @property {function} updateAction - Updates an item in the array.
599
+ * @property {function} addManyAction - Adds many items to the array.
514
600
  */
515
601
  /**
516
602
  * @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.
603
+ * @property {function} addAction - Replace old object with new object
604
+ * @property {function} deleteAction - Delete item based on key
605
+ * @property {function} updateAction - Update item based on key
520
606
  */
521
607
  /**
522
- * @typedef {Object} StoreActions
608
+ * Gets the default store actions.
609
+ *
610
+ * @return {ArrayActions|ObjectActions} The default store actions.
523
611
  */
524
612
  get defaultStoreActions() {
525
613
  return defaultStoreActions;
526
614
  }
615
+ /**
616
+ * Gets the classes to be removed after the component is connected.
617
+ *
618
+ * @return {Array<string>} An array of class names to remove.
619
+ */
527
620
  get removeClassAfterConnect() {
528
621
  var _a;
529
622
  return (_a = this.getAttribute("remove-class-after-connect")) == null ? void 0 : _a.split(" ");
530
623
  }
531
- get dependencies() {
532
- return this._dependencies;
533
- }
624
+ /**
625
+ * Sets the component dependencies.
626
+ *
627
+ * @param {Object} value - The dependencies to set.
628
+ */
534
629
  set dependencies(value) {
535
630
  this._dependencies = value;
536
631
  }
632
+ /**
633
+ * Gets the component dependencies.
634
+ *
635
+ * @return {Object} The dependencies.
636
+ */
637
+ get dependencies() {
638
+ return this._dependencies;
639
+ }
640
+ /**
641
+ * Defines a custom element if not already defined.
642
+ *
643
+ * @param {string} name - The name of the custom element.
644
+ * @param {WJElement} [elementConstructor=this] - The element constructor.
645
+ * @param {Object} [options={}] - Additional options for defining the element.
646
+ */
537
647
  static define(name, elementConstructor = this, options = {}) {
538
648
  const definedElement = customElements.get(name);
539
649
  if (!definedElement) {
540
650
  customElements.define(name, elementConstructor, options);
541
- return;
542
651
  }
543
652
  }
653
+ /**
654
+ * Defines component dependencies by registering custom elements.
655
+ */
544
656
  defineDependencies() {
545
657
  if (this.dependencies)
546
658
  Object.entries(this.dependencies).forEach((name, component) => _WJElement.define(name, component));
547
659
  }
548
- beforeDraw() {
660
+ /**
661
+ * Hook for extending behavior before drawing the component.
662
+ *
663
+ * @param {HTMLElement} context - The rendering context.
664
+ * @param {Object} store - The store instance.
665
+ * @param {Object} attributes - The component attributes.
666
+ */
667
+ beforeDraw(context, appStore, attributes) {
549
668
  }
550
- afterDraw() {
669
+ /**
670
+ * Hook for extending behavior after drawing the component.
671
+ *
672
+ * @param {HTMLElement} context - The rendering context.
673
+ * @param {Object} store - The store instance.
674
+ * @param {Object} attributes - The component attributes.
675
+ */
676
+ afterDraw(context, appStore, attributes) {
551
677
  }
678
+ /**
679
+ * Refreshes the update promise for rendering lifecycle management.
680
+ */
552
681
  refreshUpdatePromise() {
553
682
  this.updateComplete = new Promise((resolve, reject) => {
554
683
  this.finisPromise = resolve;
555
684
  this.rejectPromise = reject;
556
685
  });
557
686
  }
558
- async connectedCallback() {
687
+ /**
688
+ * Lifecycle method invoked when the component is connected to the DOM.
689
+ */
690
+ connectedCallback() {
559
691
  this.drawingStatus = this.drawingStatuses.ATTACHED;
560
692
  this.finisPromise = (resolve) => {
561
693
  resolve();
@@ -566,6 +698,9 @@ const _WJElement = class _WJElement extends HTMLElement {
566
698
  this.refreshUpdatePromise();
567
699
  this.renderPromise = this.initWjElement(true);
568
700
  }
701
+ /**
702
+ * Sets up attributes and event listeners for the component.
703
+ */
569
704
  setupAttributes() {
570
705
  let allEvents = WjElementUtils.getEvents(this);
571
706
  allEvents.forEach((customEvent, domEvent) => {
@@ -576,25 +711,28 @@ const _WJElement = class _WJElement extends HTMLElement {
576
711
  });
577
712
  }
578
713
  /**
579
- * This method is called before the element is disconnected from the DOM.
714
+ * Hook for extending behavior before disconnecting the component.
580
715
  */
581
716
  beforeDisconnect() {
582
717
  }
583
718
  /**
584
- * This method is called after the element is disconnected from the DOM.
719
+ * Hook for extending behavior after disconnecting the component.
585
720
  */
586
721
  afterDisconnect() {
587
722
  }
588
723
  /**
589
- * This method is called before the element is redrawn.
724
+ * Hook for extending behavior before redrawing the component.
590
725
  */
591
726
  beforeRedraw() {
592
727
  }
593
728
  /**
594
- * Cleans up the component.
729
+ * Cleans up resources and event listeners for the component.
595
730
  */
596
731
  componentCleanup() {
597
732
  }
733
+ /**
734
+ * Lifecycle method invoked when the component is disconnected from the DOM.
735
+ */
598
736
  disconnectedCallback() {
599
737
  var _a, _b;
600
738
  (_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
@@ -604,26 +742,32 @@ const _WJElement = class _WJElement extends HTMLElement {
604
742
  this.drawingStatus = this.drawingStatuses.DISCONNECTED;
605
743
  this.componentCleanup();
606
744
  }
607
- // internal method
608
745
  /**
609
- * Enqueues an update for the element.
610
- *
611
- * @returns {Promise} A promise that resolves when the update is complete.
746
+ * Enqueues an update to the component.
747
+ *
748
+ * @return {Promise<void>} A promise that resolves when the update is complete.
612
749
  */
613
750
  async enqueueUpdate() {
614
751
  try {
615
- await this.renderPromise;
752
+ if (this.renderPromise && this.renderPromise instanceof Promise) {
753
+ await this.renderPromise;
754
+ }
616
755
  } catch (e) {
756
+ console.error("An error occurred:", e);
617
757
  Promise.reject(e);
618
758
  }
619
759
  const result = this.refresh();
620
- if (result != null) {
760
+ if (result !== null) {
621
761
  await result;
622
762
  }
623
763
  this.renderPromise = null;
624
764
  }
625
765
  /**
626
- * Lifecycle method, called whenever an observed property changes
766
+ * Lifecycle method invoked when an observed attribute changes.
767
+ *
768
+ * @param {string} name - The attribute name.
769
+ * @param {string} old - The old value of the attribute.
770
+ * @param {string} newName - The new value of the attribute.
627
771
  */
628
772
  attributeChangedCallback(name, old, newName) {
629
773
  if (old !== newName) {
@@ -631,12 +775,11 @@ const _WJElement = class _WJElement extends HTMLElement {
631
775
  }
632
776
  }
633
777
  /**
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.
778
+ * Refreshes the component.
779
+ *
780
+ * @return {Promise<void>} A promise that resolves when the refresh is complete.
638
781
  */
639
- async refresh() {
782
+ refresh() {
640
783
  var _a, _b, _c;
641
784
  if (this.drawingStatus && this.drawingStatus >= this.drawingStatuses.START) {
642
785
  (_a = this.beforeRedraw) == null ? void 0 : _a.call(this);
@@ -645,18 +788,24 @@ const _WJElement = class _WJElement extends HTMLElement {
645
788
  (_c = this.afterDisconnect) == null ? void 0 : _c.call(this);
646
789
  return this.initWjElement(true);
647
790
  }
791
+ return Promise.resolve();
648
792
  }
649
793
  /**
650
- * To be implemented by the child class
794
+ * Draws the component's content.
795
+ *
796
+ * @param {HTMLElement} context - The rendering context.
797
+ * @param {Object} appStore - The store instance.
798
+ * @param {Object} params - Parameters for drawing.
799
+ * @return {DocumentFragment|HTMLElement|string|null} The rendered content.
651
800
  */
652
- draw(context, store2, params) {
801
+ draw(context, appStore, params) {
653
802
  return null;
654
803
  }
655
804
  /**
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.
805
+ * Displays the component's content, optionally forcing a re-render.
806
+ *
807
+ * @param {boolean} [force=false] - Whether to force a re-render.
808
+ * @return {Promise<void>} A promise that resolves when the display is complete.
660
809
  */
661
810
  display(force = false) {
662
811
  if (force) {
@@ -670,14 +819,14 @@ const _WJElement = class _WJElement extends HTMLElement {
670
819
  return this._resolveRender();
671
820
  } else {
672
821
  this.remove();
822
+ return Promise.resolve();
673
823
  }
674
824
  } else {
675
825
  return this._resolveRender();
676
826
  }
677
827
  }
678
828
  /**
679
- * Renders the element.
680
- * @returns {Promise<void>} A promise that resolves when the rendering is complete.
829
+ * Renders the component's content.
681
830
  */
682
831
  async render() {
683
832
  this.drawingStatus = this.drawingStatuses.DRAWING;
@@ -690,29 +839,29 @@ const _WJElement = class _WJElement extends HTMLElement {
690
839
  if (rend instanceof HTMLElement || rend instanceof DocumentFragment) {
691
840
  element = rend;
692
841
  } else {
693
- let template2 = document.createElement("template");
694
- template2.innerHTML = rend;
695
- element = template2.content.cloneNode(true);
842
+ let inputTemplate = document.createElement("template");
843
+ inputTemplate.innerHTML = rend;
844
+ element = inputTemplate.content.cloneNode(true);
696
845
  }
697
846
  let rendered = element;
698
847
  this.context.appendChild(rendered);
699
848
  }
700
849
  /**
701
- * Turns a string split with "-" into camel case notation
850
+ * Converts a hyphenated string to camelCase.
851
+ *
852
+ * @param {string} name - The string to sanitize.
853
+ * @return {string} The camelCase version of the string.
702
854
  */
703
855
  sanitizeName(name) {
704
856
  let parts = name.split("-");
705
857
  return [parts.shift(), ...parts.map((n) => n[0].toUpperCase() + n.slice(1))].join("");
706
858
  }
707
859
  /**
708
- * Checks if an object has a getter and/or setter for a given property.
709
- *
860
+ * Checks if an object property has a getter or setter.
861
+ *
710
862
  * @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`.
863
+ * @param {string} property - The property name.
864
+ * @return {Object} An object containing references to the getter and setter, if they exist.
716
865
  */
717
866
  checkGetterSetter(obj, property) {
718
867
  let descriptor = Object.getOwnPropertyDescriptor(obj, property);
@@ -729,8 +878,7 @@ const _WJElement = class _WJElement extends HTMLElement {
729
878
  return { hasGetter: null, hasSetter: null };
730
879
  }
731
880
  /**
732
- * Creates one property on this class for every
733
- * HTML property defined on the element
881
+ * Sets up property accessors for the component's attributes.
734
882
  */
735
883
  setUpAccessors() {
736
884
  let attrs = this.getAttributeNames();
@@ -744,11 +892,12 @@ const _WJElement = class _WJElement extends HTMLElement {
744
892
  });
745
893
  }
746
894
  /**
747
- * Resolves the rendering of the element.
748
- *
749
- * @returns {Promise<void>} A promise that resolves when the rendering is complete.
895
+ * Resolves the rendering process of the component.
896
+ *
897
+ * @return {Promise<void>} A promise that resolves when rendering is complete.
898
+ * @private
750
899
  */
751
- async _resolveRender() {
900
+ _resolveRender() {
752
901
  this.params = WjElementUtils.getAttributes(this);
753
902
  return new Promise(async (resolve, reject) => {
754
903
  var _a;
@@ -764,7 +913,8 @@ const _WJElement = class _WJElement extends HTMLElement {
764
913
  this.finisPromise();
765
914
  this.rendering = false;
766
915
  this.isAttached = true;
767
- this.removeClassAfterConnect && this.classList.remove(...this.removeClassAfterConnect);
916
+ if (this.removeClassAfterConnect)
917
+ this.classList.remove(...this.removeClassAfterConnect);
768
918
  this.drawingStatus = this.drawingStatuses.DONE;
769
919
  resolve();
770
920
  }).catch((e) => {
@@ -772,9 +922,16 @@ const _WJElement = class _WJElement extends HTMLElement {
772
922
  });
773
923
  }
774
924
  };
775
- __publicField(_WJElement, "processTemplates", (pTemplate, template2) => {
925
+ /**
926
+ * Processes and combines two templates into one.
927
+ *
928
+ * @param {HTMLTemplateElement} pTemplate - The primary template.
929
+ * @param {HTMLTemplateElement|null} inputTemplate - The secondary template.
930
+ * @return {HTMLTemplateElement} The combined template.
931
+ */
932
+ __publicField(_WJElement, "processTemplates", (pTemplate, inputTemplate) => {
776
933
  const newTemplate = document.createElement("template");
777
- newTemplate.innerHTML = [template2.innerHTML, (pTemplate == null ? void 0 : pTemplate.innerHTML) || ""].join("");
934
+ newTemplate.innerHTML = [inputTemplate.innerHTML, (pTemplate == null ? void 0 : pTemplate.innerHTML) || ""].join("");
778
935
  return newTemplate;
779
936
  });
780
937
  let WJElement = _WJElement;