@optionfactory/ful 0.65.0 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ful.mjs CHANGED
@@ -557,14 +557,28 @@ const timing = {
557
557
  }
558
558
  };
559
559
 
560
+ class Deferred {
561
+ constructor() {
562
+ this.promise = new Promise((resolve, reject) => {
563
+ this.reject = reject;
564
+ this.resolve = resolve;
565
+ });
566
+ }
567
+ }
568
+
560
569
  // SyncEvent.on($0, 'asd', async e => { await ful.timing.sleep(10_000); return 3; })
561
- // const [success, results] = await new SyncEvent("asd").dispatchTo($0);
570
+ // const success = await new SyncEvent("asd").dispatchTo($0);
562
571
  class SyncEvent extends CustomEvent {
572
+ #promises;
563
573
  #results;
564
574
  constructor(type, options) {
565
575
  super(type, {...options, cancelable: true});
576
+ this.#promises = [];
566
577
  this.#results = [];
567
578
  }
579
+ get results(){
580
+ return this.#results;
581
+ }
568
582
 
569
583
  async dispatchTo(el) {
570
584
  // unlike "native" events, which are fired by the browser and invoke
@@ -574,14 +588,14 @@ class SyncEvent extends CustomEvent {
574
588
  el.dispatchEvent(this);
575
589
  //we ignore the result of dispatchEvent and use defaultPrevented instead
576
590
  //because handlers can be async
577
- const results = await Promise.all(this.#results);
578
- return [!this.defaultPrevented, results];
591
+ this.#results = await Promise.all(this.#promises);
592
+ return !this.defaultPrevented;
579
593
  }
580
594
 
581
595
  static on(el, type, h, useCapture) {
582
596
  el.addEventListener(type, e => {
583
597
  //e *must* be an async event
584
- e.#results.push(h(e));
598
+ e.#promises.push(h(e));
585
599
  }, useCapture);
586
600
  }
587
601
  }
@@ -672,6 +686,19 @@ class Attributes {
672
686
  to.setAttribute(target, from.getAttribute(a));
673
687
  });
674
688
  }
689
+ /**
690
+ *
691
+ * @param {HTMLElement} el
692
+ * @param {stirng} attr
693
+ * @param {boolean} value
694
+ */
695
+ static toggle(el, attr, value) {
696
+ if (value) {
697
+ el.setAttribute(attr, '');
698
+ } else {
699
+ el.removeAttribute(attr);
700
+ }
701
+ }
675
702
  }
676
703
 
677
704
  class LightSlots {
@@ -708,7 +735,7 @@ class Nodes {
708
735
  }
709
736
 
710
737
  class Events {
711
- static dispatchChange(el, value){
738
+ static dispatchChange(el, value) {
712
739
  return el.dispatchEvent(new CustomEvent("change", {
713
740
  bubbles: true,
714
741
  cancelable: true,
@@ -844,6 +871,7 @@ const ParsedElement = (conf) => {
844
871
  }
845
872
  #parsed;
846
873
  #initialized;
874
+ #reflecting;
847
875
  #internals;
848
876
  constructor(...args) {
849
877
  super(...args);
@@ -880,9 +908,20 @@ const ParsedElement = (conf) => {
880
908
  if (!this.#parsed || oldValue === newValue) {
881
909
  return;
882
910
  }
911
+ if (this.#reflecting) {
912
+ return;
913
+ }
883
914
  const mapper = attrToMapper[attr];
884
915
  this[attr] = mapper(newValue);
885
916
  }
917
+ reflect(fn) {
918
+ this.#reflecting = true;
919
+ try {
920
+ fn();
921
+ } finally {
922
+ this.#reflecting = false;
923
+ }
924
+ }
886
925
  async upgrade() {
887
926
  if (this.#parsed) {
888
927
  return;
@@ -907,29 +946,16 @@ const ParsedElement = (conf) => {
907
946
  return this.internals.states.has(`--${attr}`);
908
947
  },
909
948
  set(value) {
910
- const etb = this.initialized ? 'change' : 'init';
911
- const before = new SyncEvent(`${attr}:${etb}`, {
912
- detail: {
913
- target: this,
914
- value: value
915
- }
916
- });
917
- const eta = this.initialized ? 'changed' : 'inited';
918
- const after = new SyncEvent(`${attr}:${eta}`, {
919
- detail: {
920
- target: this,
921
- value: value
922
- }
923
- });
924
-
949
+ const detail = { target: this, value };
950
+ const before = new SyncEvent(`${attr}:${this.initialized ? 'change' : 'init'}`, { detail });
951
+ const after = new SyncEvent(`${attr}:${this.initialized ? 'changed' : 'inited'}`, { detail });
925
952
  (async () => {
926
- const [success, results] = await before.dispatchTo(this);
927
- if (!success) {
953
+ if (!await before.dispatchTo(this)) {
928
954
  return;
929
955
  }
930
956
  //see https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet#using_double_dash_prefixed_idents
931
957
  this.internals.states[value ? 'add' : 'delete'](`--${attr}`);
932
-
958
+ this.reflect(() => Attributes.toggle(this, attr, value));
933
959
  await after.dispatchTo(this);
934
960
  })();
935
961
  }
@@ -1413,5 +1439,5 @@ class Wizard extends HTMLElement {
1413
1439
  }
1414
1440
  }
1415
1441
 
1416
- export { Attributes, AuthorizationCodeFlow, AuthorizationCodeFlowInterceptor, AuthorizationCodeFlowSession, Base64, ElementsRegistry, Failure, Form, Fragments, Hex, HttpClient, INPUT_TEMPLATE, Input, LightSlots, LocalStorage, Nodes, ParsedElement, RadioGroup, Select, SessionStorage, Spinner, SyncEvent, TemplatesRegistry, VersionedStorage, Wizard, elements, jsonPatch, jsonPost, jsonPut, jsonRequest, makeInputFragment, timing };
1442
+ export { Attributes, AuthorizationCodeFlow, AuthorizationCodeFlowInterceptor, AuthorizationCodeFlowSession, Base64, Deferred, ElementsRegistry, Failure, Form, Fragments, Hex, HttpClient, INPUT_TEMPLATE, Input, LightSlots, LocalStorage, Nodes, ParsedElement, RadioGroup, Select, SessionStorage, Spinner, SyncEvent, TemplatesRegistry, VersionedStorage, Wizard, elements, jsonPatch, jsonPost, jsonPut, jsonRequest, makeInputFragment, timing };
1417
1443
  //# sourceMappingURL=ful.mjs.map