wj-elements 0.1.115 → 0.1.117

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.
@@ -222,7 +222,7 @@ class Checkbox extends WJElement {
222
222
  /**
223
223
  * Removes the event listener when the checkbox is disconnected.
224
224
  */
225
- disconnectedCallback() {
225
+ beforeDisconnect() {
226
226
  event.removeElement(this.input);
227
227
  }
228
228
  /**
@@ -231,7 +231,7 @@ class Checkbox extends WJElement {
231
231
  * @param {HTMLFormElement} form - The form the custom element is associated with.
232
232
  */
233
233
  formAssociatedCallback(form) {
234
- form.addEventListener("submit", () => {
234
+ form == null ? void 0 : form.addEventListener("submit", () => {
235
235
  });
236
236
  }
237
237
  /**
@@ -1276,7 +1276,7 @@ class ColorPicker extends WJElement {
1276
1276
  y: this.colorArea.offsetTop
1277
1277
  };
1278
1278
  }
1279
- disconnectedCallback() {
1279
+ beforeDisconnect() {
1280
1280
  this.init = false;
1281
1281
  }
1282
1282
  getPointerPosition(event2) {
@@ -124,10 +124,6 @@ class Dialog extends WJElement {
124
124
  }
125
125
  afterClose() {
126
126
  }
127
- disconnectedCallback() {
128
- event.removeElement(this.button);
129
- event.removeElement(this.dialog);
130
- }
131
127
  }
132
128
  Dialog.define("wje-dialog", Dialog);
133
129
  export {
@@ -393,20 +393,21 @@ const _WJElement = class _WJElement extends HTMLElement {
393
393
  constructor(componentTemplate) {
394
394
  super();
395
395
  __publicField(this, "initWjElement", async (force = false) => {
396
- var _a;
397
- this.functionStack = [];
398
- const processId = Date.now();
399
- this.functionStack.push(processId);
400
- (_a = this.setupAttributes) == null ? void 0 : _a.call(this);
401
- if (this.isShadowRoot) {
402
- !this.shadowRoot && this.attachShadow({ mode: this.shadowType || "open" });
403
- }
404
- this.setUpAccessors();
405
- this.drawingStatus = "BEGINING";
406
- this.display(force, processId);
407
- const sheet = new CSSStyleSheet();
408
- sheet.replaceSync(this.constructor.cssStyleSheet);
409
- this.context.adoptedStyleSheets = [sheet];
396
+ return new Promise(async (resolve, reject) => {
397
+ var _a;
398
+ this.drawingStatus = this.drawingStatuses.BEGINING;
399
+ (_a = this.setupAttributes) == null ? void 0 : _a.call(this);
400
+ if (this.isShadowRoot) {
401
+ !this.shadowRoot && this.attachShadow({ mode: this.shadowType || "open" });
402
+ }
403
+ this.setUpAccessors();
404
+ this.drawingStatus = this.drawingStatuses.START;
405
+ await this.display(force);
406
+ const sheet = new CSSStyleSheet();
407
+ sheet.replaceSync(this.constructor.cssStyleSheet);
408
+ this.context.adoptedStyleSheets = [sheet];
409
+ resolve();
410
+ });
410
411
  });
411
412
  this.template = componentTemplate || template;
412
413
  this.isAttached = false;
@@ -415,11 +416,15 @@ const _WJElement = class _WJElement extends HTMLElement {
415
416
  });
416
417
  this.definedependencies();
417
418
  this.rendering = false;
418
- this.runtimeTimeout = null;
419
- this.count = 0;
420
- this.functionStack = [];
421
- this.scheludedRefresh = false;
422
419
  this._dependencies = {};
420
+ this.drawingStatuses = {
421
+ ATTACHED: 1,
422
+ BEGINING: 2,
423
+ START: 3,
424
+ DRAWING: 4,
425
+ DONE: 5,
426
+ DISCONNECTED: 6
427
+ };
423
428
  }
424
429
  get permission() {
425
430
  return this.getAttribute("permission-check");
@@ -508,6 +513,7 @@ const _WJElement = class _WJElement extends HTMLElement {
508
513
  });
509
514
  }
510
515
  async connectedCallback() {
516
+ this.drawingStatus = this.drawingStatuses.ATTACHED;
511
517
  this.finisPromise = (resolve) => {
512
518
  resolve();
513
519
  };
@@ -515,7 +521,7 @@ const _WJElement = class _WJElement extends HTMLElement {
515
521
  reject();
516
522
  };
517
523
  this.refreshUpdatePromise();
518
- await this.initWjElement(true);
524
+ this.renderPromise = this.initWjElement(true);
519
525
  }
520
526
  setupAttributes() {
521
527
  let allEvents = WjElementUtils.getEvents(this);
@@ -533,32 +539,37 @@ const _WJElement = class _WJElement extends HTMLElement {
533
539
  (_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
534
540
  if (this.isAttached)
535
541
  this.context.innerHTML = "";
536
- this.drawingStatus = "DISCONNECTED";
537
542
  this.isAttached = false;
538
543
  (_b = this.afterDisconnect) == null ? void 0 : _b.call(this);
544
+ this.drawingStatus = this.drawingStatuses.DISCONNECTED;
545
+ }
546
+ async enqueueUpdate() {
547
+ try {
548
+ await this.renderPromise;
549
+ } catch (e) {
550
+ Promise.reject(e);
551
+ }
552
+ const result = this.refresh();
553
+ if (result != null) {
554
+ await result;
555
+ }
556
+ this.renderPromise = null;
539
557
  }
540
558
  /**
541
559
  * Lifecycle method, called whenever an observed property changes
542
560
  */
543
561
  attributeChangedCallback(name, old, newName) {
544
- if (!this.isAttached && old !== newName) {
545
- this.scheludedRefresh = true;
546
- return;
547
- }
548
562
  if (old !== newName) {
549
- this.refresh();
563
+ this.renderPromise = this.enqueueUpdate();
550
564
  }
551
565
  }
552
566
  async refresh() {
553
- var _a, _b, _c;
554
- (_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
555
- this.refreshUpdatePromise();
556
- if (this.drawingStatus != "AFTER") {
567
+ var _a, _b;
568
+ if (this.drawingStatus && this.drawingStatus >= this.drawingStatuses.START) {
569
+ (_a = this.beforeDisconnect) == null ? void 0 : _a.call(this);
570
+ this.refreshUpdatePromise();
557
571
  (_b = this.afterDisconnect) == null ? void 0 : _b.call(this);
558
- await this.initWjElement(true);
559
- } else {
560
- (_c = this.unregister) == null ? void 0 : _c.call(this);
561
- await this.initWjElement(true);
572
+ return this.initWjElement(true);
562
573
  }
563
574
  }
564
575
  /**
@@ -567,9 +578,7 @@ const _WJElement = class _WJElement extends HTMLElement {
567
578
  draw(context, store2, params) {
568
579
  return null;
569
580
  }
570
- display(force = false, processId) {
571
- if (this.isProcessingFlow(processId))
572
- return;
581
+ display(force = false, signal) {
573
582
  if (force) {
574
583
  [...this.context.childNodes].forEach(this.context.removeChild.bind(this.context));
575
584
  this.isAttached = false;
@@ -577,33 +586,32 @@ const _WJElement = class _WJElement extends HTMLElement {
577
586
  this.context.append(this.template.content.cloneNode(true));
578
587
  if (this.isPermissionCheck || this.isShow) {
579
588
  if (WjePermissionsApi.isPermissionFulfilled.bind(this)(this.permission)) {
580
- this._resolveRender(processId);
589
+ this.drawingStatus = this.drawingStatuses.DRAWING;
590
+ return this._resolveRender(signal);
581
591
  } else {
582
592
  this.remove();
583
593
  }
584
594
  } else {
585
- this._resolveRender(processId);
595
+ return this._resolveRender(signal);
586
596
  }
587
597
  }
588
- async render(processId) {
598
+ async render() {
589
599
  this.drawingStatus = "DRAWING";
590
- if (this.isProcessingFlow(processId))
591
- return;
592
- await Promise.resolve(this.draw(this.context, this.store, WjElementUtils.getAttributes(this))).then((res) => {
593
- let rend = res || "";
594
- let element;
595
- if (rend instanceof HTMLElement || rend instanceof DocumentFragment) {
596
- element = rend;
597
- } else {
598
- let template2 = document.createElement("template");
599
- template2.innerHTML = rend;
600
- element = template2.content.cloneNode(true);
601
- }
602
- let rendered = element;
603
- if (this.isProcessingFlow(processId))
604
- return;
605
- this.context.appendChild(rendered);
606
- });
600
+ let _draw = this.draw(this.context, this.store, WjElementUtils.getAttributes(this));
601
+ if (_draw instanceof Promise) {
602
+ _draw = await _draw;
603
+ }
604
+ let rend = _draw;
605
+ let element;
606
+ if (rend instanceof HTMLElement || rend instanceof DocumentFragment) {
607
+ element = rend;
608
+ } else {
609
+ let template2 = document.createElement("template");
610
+ template2.innerHTML = rend;
611
+ element = template2.content.cloneNode(true);
612
+ }
613
+ let rendered = element;
614
+ this.context.appendChild(rendered);
607
615
  }
608
616
  /**
609
617
  * Turns a string split with "-" into camel case notation
@@ -641,33 +649,27 @@ const _WJElement = class _WJElement extends HTMLElement {
641
649
  });
642
650
  });
643
651
  }
644
- isProcessingFlow(processId) {
645
- return !this.functionStack.find((d) => d == processId);
646
- }
647
- _resolveRender(processId) {
648
- if (this.isProcessingFlow(processId))
649
- return;
652
+ async _resolveRender(signal) {
650
653
  this.params = WjElementUtils.getAttributes(this);
651
- Promise.resolve(this.beforeDraw(this.context, this.store, WjElementUtils.getAttributes(this))).then((res) => {
652
- this.drawingStatus = "BEFORE";
653
- Promise.resolve(this.render(processId)).then((res2) => {
654
- var _a;
655
- if (this.isProcessingFlow(processId))
656
- return;
657
- Promise.resolve((_a = this.afterDraw) == null ? void 0 : _a.call(this, this.context, this.store, WjElementUtils.getAttributes(this))).then(
658
- (a, b, c) => {
659
- this.drawingStatus = "AFTER";
660
- this.finisPromise();
661
- this.rendering = false;
662
- this.isAttached = true;
663
- this.removeClassAfterConnect && this.classList.remove(...this.removeClassAfterConnect);
664
- if (this.scheludedRefresh) {
665
- this.refresh();
666
- this.scheludedRefresh = false;
667
- }
668
- }
669
- );
670
- });
654
+ return new Promise(async (resolve, reject) => {
655
+ var _a;
656
+ const __beforeDraw = this.beforeDraw(this.context, this.store, WjElementUtils.getAttributes(this));
657
+ if (__beforeDraw instanceof Promise) {
658
+ await __beforeDraw;
659
+ }
660
+ await this.render();
661
+ const __afterDraw = (_a = this.afterDraw) == null ? void 0 : _a.call(this, this.context, this.store, WjElementUtils.getAttributes(this));
662
+ if (__afterDraw instanceof Promise) {
663
+ await __afterDraw;
664
+ }
665
+ this.finisPromise();
666
+ this.rendering = false;
667
+ this.isAttached = true;
668
+ this.removeClassAfterConnect && this.classList.remove(...this.removeClassAfterConnect);
669
+ this.drawingStatus = this.drawingStatuses.DONE;
670
+ resolve();
671
+ }).catch((e) => {
672
+ console.log(e);
671
673
  });
672
674
  }
673
675
  };
@@ -255,7 +255,7 @@ class IconPicker extends WJElement {
255
255
  /**
256
256
  * Called when the component is disconnected.
257
257
  */
258
- disconnectedCallback() {
258
+ beforeDisconnect() {
259
259
  this.init = false;
260
260
  }
261
261
  /**
package/dist/wje-input.js CHANGED
@@ -390,7 +390,7 @@ class Input extends WJElement {
390
390
  * @param {HTMLFormElement} form - The form the custom element is associated with.
391
391
  */
392
392
  formAssociatedCallback(form) {
393
- form.addEventListener("submit", () => {
393
+ form == null ? void 0 : form.addEventListener("submit", () => {
394
394
  this.validateInput();
395
395
  this.propagateValidation();
396
396
  });
@@ -192,7 +192,7 @@ class Masonry extends WJElement {
192
192
  /**
193
193
  * Callback for when the element is disconnected.
194
194
  */
195
- disconnectedCallback() {
195
+ beforeDisconnect() {
196
196
  this.unsetSlot.removeEventListener("slotchange", this.onSlotChange);
197
197
  window.removeEventListener("resize", this.onResize);
198
198
  if (this.ro != null) {
@@ -60,6 +60,12 @@ class Options extends WJElement {
60
60
  get hasOptionArrayPath() {
61
61
  return this.hasAttribute("option-array-path");
62
62
  }
63
+ get dropdownHeight() {
64
+ return this.getAttribute("dropdown-height") || "100%";
65
+ }
66
+ set dropdownHeight(value) {
67
+ this.setAttribute("dropdown-height", value);
68
+ }
63
69
  set itemValue(value) {
64
70
  this.setAttribute("item-value", value);
65
71
  }
@@ -128,7 +134,7 @@ class Options extends WJElement {
128
134
  const list = document.createElement("wje-list");
129
135
  const infiniteScroll = document.createElement("wje-infinite-scroll");
130
136
  infiniteScroll.setAttribute("placement", "wje-list");
131
- infiniteScroll.setAttribute("height", "100%");
137
+ infiniteScroll.setAttribute("height", this.dropdownHeight);
132
138
  infiniteScroll.setAttribute("object-name", this.optionArrayPath);
133
139
  infiniteScroll.append(list);
134
140
  infiniteScroll.dataToHtml = this.htmlItem;
package/dist/wje-radio.js CHANGED
@@ -60,7 +60,7 @@ class Radio extends WJElement {
60
60
  event.addListener(this, "click", "wje-radio:input");
61
61
  }
62
62
  }
63
- disconnectedCallback() {
63
+ beforeDisconnect() {
64
64
  event.removeElement(this);
65
65
  }
66
66
  }
@@ -72,7 +72,11 @@ class Select extends WJElement {
72
72
  * @param {string} value - The value to set.
73
73
  */
74
74
  set value(value) {
75
- this.internals.setFormValue(JSON.stringify(value));
75
+ if (Array.isArray(value)) {
76
+ this.internals.setFormValue(JSON.stringify(value));
77
+ } else {
78
+ this.internals.setFormValue(value);
79
+ }
76
80
  }
77
81
  /**
78
82
  * Getter for the value attribute.
@@ -593,7 +597,7 @@ class Select extends WJElement {
593
597
  * @param {HTMLFormElement} form - The form the custom element is associated with.
594
598
  */
595
599
  formAssociatedCallback(form) {
596
- form.addEventListener("submit", () => {
600
+ form == null ? void 0 : form.addEventListener("submit", () => {
597
601
  });
598
602
  }
599
603
  /**
@@ -143,7 +143,7 @@ class Textarea extends WJElement {
143
143
  /**
144
144
  * Disconnects the component.
145
145
  */
146
- disconnectedCallback() {
146
+ beforeDisconnect() {
147
147
  this.resizeObserver.unobserve(this.input);
148
148
  }
149
149
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wj-elements",
3
3
  "description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
4
- "version": "0.1.115",
4
+ "version": "0.1.117",
5
5
  "homepage": "https://github.com/lencys/wj-elements",
6
6
  "author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
7
7
  "license": "MIT",