@optionfactory/ful 0.46.0 → 0.47.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.iife.js CHANGED
@@ -686,83 +686,85 @@ var ful = (function (exports) {
686
686
 
687
687
  const upgradeQueue = new UpgradeQueue();
688
688
 
689
- class ParsedElement extends HTMLElement {
690
- #parsed;
691
- connectedCallback() {
692
- if (this.#parsed) {
693
- return;
694
- }
695
- if (this.ownerDocument.readyState === 'complete' || Nodes.isParsed(this)) {
696
- upgradeQueue.enqueue(this);
697
- return;
698
- }
699
- this.ownerDocument.addEventListener('DOMContentLoaded', () => {
700
- observer.disconnect();
701
- upgradeQueue.enqueue(this);
702
- });
703
- const observer = new MutationObserver(() => {
704
- if (!Nodes.isParsed(this)) {
705
- return;
706
- }
707
- observer.disconnect();
708
- upgradeQueue.enqueue(this);
709
- });
710
- observer.observe(this.parentNode, { childList: true, subtree: true });
711
- }
712
- attributeChangedCallback(name, oldValue, newValue) {
713
- if (!this.#parsed || oldValue === newValue) {
714
- return;
715
- }
716
- this[name] = newValue;
717
- }
718
- upgrade() {
719
- if (this.#parsed) {
720
- return;
721
- }
722
- this.#parsed = true;
723
- return this.ready();
724
- }
725
- }
726
-
727
-
728
- const Templated = (SuperClass, template) => {
729
- return class extends SuperClass {
730
- async ready() {
731
- const slotted = Slots.from(this);
732
- const fragment = await Promise.resolve(this.render(slotted, template));
733
- this.replaceChildren(fragment);
734
- }
735
- };
736
- };
689
+ const ParsedElement = (flags, others) => {
737
690
 
738
- const Stateful = (SuperClass, flags, others) => {
691
+ const observed_flags = flags || [];
692
+ const observed_others = others || [];
693
+ const observed = [].concat(observed_flags).concat(observed_others);
739
694
 
740
- const all = [].concat(flags).concat(others || []);
741
-
742
- const k = class extends SuperClass {
695
+ const k = class extends HTMLElement {
743
696
  static get observedAttributes() {
744
- return all;
697
+ return observed;
745
698
  }
699
+ #parsed;
700
+ #internals;
746
701
  constructor(...args) {
747
702
  super(...args);
748
- this.internals_ = this.internals_ || this.attachInternals();
703
+ this.#internals = this.attachInternals();
704
+ }
705
+ get internals() {
706
+ return this.#internals;
707
+ }
708
+ connectedCallback() {
709
+ if (this.#parsed) {
710
+ return;
711
+ }
712
+ if (this.ownerDocument.readyState === 'complete' || Nodes.isParsed(this)) {
713
+ upgradeQueue.enqueue(this);
714
+ return;
715
+ }
716
+ this.ownerDocument.addEventListener('DOMContentLoaded', () => {
717
+ observer.disconnect();
718
+ upgradeQueue.enqueue(this);
719
+ });
720
+ const observer = new MutationObserver(() => {
721
+ if (!Nodes.isParsed(this)) {
722
+ return;
723
+ }
724
+ observer.disconnect();
725
+ upgradeQueue.enqueue(this);
726
+ });
727
+ observer.observe(this.parentNode, { childList: true, subtree: true });
728
+ }
729
+ attributeChangedCallback(name, oldValue, newValue) {
730
+ if (!this.#parsed || oldValue === newValue) {
731
+ return;
732
+ }
733
+ this[name] = newValue;
749
734
  }
735
+ async upgrade() {
736
+ if (this.#parsed) {
737
+ return;
738
+ }
739
+ this.#parsed = true;
740
+ await this.render();
741
+ for (const flag of observed_flags) {
742
+ if(this.hasAttribute(flag)){
743
+ this[flag] = true;
744
+ }
745
+ }
746
+ for (const other of observed_others) {
747
+ if(this.hasAttribute(other)){
748
+ this[other] = this.getAttribute(other);
749
+ }
750
+ }
751
+ }
750
752
  };
751
753
 
752
- for (const flag of flags) {
754
+ for (const flag of observed_flags) {
753
755
  Object.defineProperty(k.prototype, flag, {
754
756
  enumerable: true,
755
757
  configurable: true,
756
758
  get() {
757
- return this.internals_.states.has(`--${flag}`);
759
+ return this.internals.states.has(`--${flag}`);
758
760
  },
759
761
  set(value) {
760
762
  //see https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet#using_double_dash_prefixed_idents
761
763
  if (Attributes.asBoolean(value)) {
762
- this.internals_.states.add(`--${flag}`);
764
+ this.internals.states.add(`--${flag}`);
763
765
  return;
764
766
  }
765
- this.internals_.states.delete(`--${flag}`);
767
+ this.internals.states.delete(`--${flag}`);
766
768
  }
767
769
  });
768
770
  }
@@ -839,12 +841,12 @@ var ful = (function (exports) {
839
841
  el.value = raw;
840
842
  }
841
843
 
842
- class Form extends Templated(ParsedElement) {
844
+ class Form extends ParsedElement() {
843
845
  static IGNORED_CHILDREN_SELECTOR = '.d-none, [hidden]';
844
846
  static SCROLL_OFFSET = 50;
845
- render(slotted) {
847
+ render() {
846
848
  const form = document.createElement('form');
847
- form.append(slotted.default);
849
+ form.replaceChildren(...this.childNodes);
848
850
  form.addEventListener('submit', async (e) => {
849
851
  e.preventDefault();
850
852
  this.spinner(true);
@@ -862,7 +864,7 @@ var ful = (function (exports) {
862
864
  this.spinner(false);
863
865
  }
864
866
  });
865
- return form;
867
+ this.replaceChildren(form);
866
868
  }
867
869
  spinner(spin) {
868
870
  this.querySelectorAll('ful-spinner').forEach(el => el.hidden = !spin);
@@ -923,7 +925,7 @@ var ful = (function (exports) {
923
925
 
924
926
  });
925
927
 
926
- const ful_input_template_ = globalThis.ful_input_template || ftl.Template.fromHtml(`
928
+ const template$1 = globalThis.ful_input_template || ftl.Template.fromHtml(`
927
929
  <label data-tpl-for="id" class="form-label">{{{{ slotted.default }}}}</label>
928
930
  <div class="input-group">
929
931
  <span data-tpl-if="slotted.ibefore" class="input-group-text">{{{{ slotted.ibefore }}}}</span>
@@ -935,31 +937,34 @@ var ful = (function (exports) {
935
937
  <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>
936
938
  `, ful_input_ec);
937
939
 
938
- class StatelessInput extends Templated(ParsedElement, ful_input_template_) {
939
- render(slotted, template) {
940
- const input = this.input = slotted.input = slotted.input || (() => {
941
- const el = document.createElement("input");
942
- el.classList.add("form-control");
943
- return el;
944
- })();
945
- input.setAttribute('ful-validation-target', '');
940
+ const renderInput = (el) => {
941
+ const slotted = Slots.from(el);
942
+
943
+ const input = el.input = slotted.input = slotted.input || (() => {
944
+ const el = document.createElement("input");
945
+ el.classList.add("form-control");
946
+ return el;
947
+ })();
948
+ input.setAttribute('ful-validation-target', '');
949
+
950
+ const id = input.getAttribute('id') || el.getAttribute('input-id') || Attributes.uid('ful-input');
951
+ Attributes.forward('input-', el, slotted.input);
952
+ Attributes.defaultValue(slotted.input, "id", id);
953
+ Attributes.defaultValue(slotted.input, "type", "text");
954
+ Attributes.defaultValue(slotted.input, "placeholder", " ");
955
+ const name = el.getAttribute('name');
956
+ template$1.renderTo(el, { id, name, slotted });
957
+ };
946
958
 
947
- const id = input.getAttribute('id') || this.getAttribute('input-id') || Attributes.uid('ful-input');
948
- Attributes.forward('input-', this, slotted.input);
949
- Attributes.defaultValue(slotted.input, "id", id);
950
- Attributes.defaultValue(slotted.input, "type", "text");
951
- Attributes.defaultValue(slotted.input, "placeholder", " ");
952
- const name = this.getAttribute('name');
953
- return template.render({ id, name, slotted });
959
+ class StatelessInput extends ParsedElement() {
960
+ render() {
961
+ renderInput(this);
954
962
  }
955
-
956
963
  }
957
964
 
958
- class Input extends Stateful(StatelessInput, [], ['value']) {
959
- render(slotted, template) {
960
- const fragment = super.render(slotted, template);
961
- this.input.value = this.getAttribute('value');
962
- return fragment;
965
+ class Input extends ParsedElement([], ['value']) {
966
+ render() {
967
+ renderInput(this);
963
968
  }
964
969
  get value() {
965
970
  return this.input.value;
@@ -991,12 +996,14 @@ var ful = (function (exports) {
991
996
  `, ful_select_ec);
992
997
 
993
998
 
994
- class Select extends Stateful(Templated(ParsedElement, ful_select_template_), [], ["value"]) {
999
+ class Select extends ParsedElement([], ["value"]) {
995
1000
  constructor(tsConfig) {
996
1001
  super();
997
1002
  this.tsConfig = tsConfig;
998
1003
  }
999
- render(slotted, template) {
1004
+ render() {
1005
+ const slotted = Slots.from(this);
1006
+
1000
1007
  const type = this.getAttribute("type") || 'local';
1001
1008
  const remote = type != 'local';
1002
1009
  const loadOnce = this.getAttribute('load') != 'always';
@@ -1024,7 +1031,6 @@ var ful = (function (exports) {
1024
1031
  }
1025
1032
  };
1026
1033
 
1027
-
1028
1034
  this._remote = remote;
1029
1035
  // we need to await this load in setValue when remote is configured and the option
1030
1036
  // is not loaded yet.
@@ -1039,7 +1045,7 @@ var ful = (function (exports) {
1039
1045
  const type = query && query.hasOwnProperty('byId') ? 'id' : 'query';
1040
1046
  const qvalue = type === 'id' ? query.byId : query;
1041
1047
  const data = await (this.loader ? this.loader(qvalue, type) : []);
1042
- if(type !== 'id'){
1048
+ if (type !== 'id') {
1043
1049
  this.loaded = true;
1044
1050
  }
1045
1051
  callback(data);
@@ -1053,12 +1059,12 @@ var ful = (function (exports) {
1053
1059
  } : {}, tsDefaultConfig, this.tsConfig));
1054
1060
  //we remove the input to move it
1055
1061
  input.remove();
1056
- return template.render({ id, tsId, name, input, slotted });
1062
+ ful_select_template_.renderTo(this, { id, tsId, name, input, slotted });
1057
1063
  }
1058
1064
  set value(v) {
1059
1065
  (async () => {
1060
- if(this._remote){
1061
- await this._unwrappedRemoteLoad({byId: v}, this.ts.loadCallback.bind(this.ts));
1066
+ if (this._remote) {
1067
+ await this._unwrappedRemoteLoad({ byId: v }, this.ts.loadCallback.bind(this.ts));
1062
1068
  }
1063
1069
  this.ts.setValue(v);
1064
1070
  })();
@@ -1095,8 +1101,9 @@ var ful = (function (exports) {
1095
1101
  `, ful_radiogroup_ec);
1096
1102
 
1097
1103
 
1098
- class RadioGroup extends Stateful(Templated(ParsedElement, ful_radiougroup_template_), ['disabled'], ['value']) {
1099
- render(slotted, template) {
1104
+ class RadioGroup extends ParsedElement(['disabled'], ['value']) {
1105
+ render() {
1106
+ const slotted = Slots.from(this);
1100
1107
  const name = this.getAttribute('name') || Attributes.uid('ful-radiogroup');
1101
1108
  const radioEls = Array.from(slotted.default.querySelectorAll('ful-radio'));
1102
1109
  const inputsAndLabels = radioEls.map(el => {
@@ -1111,19 +1118,18 @@ var ful = (function (exports) {
1111
1118
  return [input, label];
1112
1119
  });
1113
1120
  radioEls.forEach(el => el.remove());
1114
-
1115
- const fragment = template.render({
1121
+
1122
+ ful_radiougroup_template_.renderTo(this, {
1116
1123
  name: name,
1117
1124
  slotted: slotted,
1118
1125
  inputsAndLabels: inputsAndLabels
1119
1126
  });
1120
- return fragment;
1121
1127
  }
1122
1128
  get value() {
1123
1129
  const checked = this.querySelector('input[type=radio]:checked');
1124
1130
  return checked ? checked.value : null;
1125
1131
  }
1126
- set value(value){
1132
+ set value(value) {
1127
1133
  this.querySelector(`input[type=radio][value=${CSS.escape(value)}]`).checked = true;
1128
1134
  }
1129
1135
  }
@@ -1132,7 +1138,7 @@ var ful = (function (exports) {
1132
1138
 
1133
1139
  });
1134
1140
 
1135
- const ful_spinner_template_ = globalThis.ful_spinner_template || ftl.Template.fromHtml(`
1141
+ const template = globalThis.ful_spinner_template || ftl.Template.fromHtml(`
1136
1142
  <div class="ful-spinner-wrapper">
1137
1143
  <div class="ful-spinner-text">{{{{ slotted.default }}}}</div>
1138
1144
  <div class="ful-spinner-icon"></div>
@@ -1140,9 +1146,10 @@ var ful = (function (exports) {
1140
1146
  `, ful_spinner_ec);
1141
1147
 
1142
1148
 
1143
- class Spinner extends Templated(ParsedElement, ful_spinner_template_) {
1144
- render(slotted, template) {
1145
- return template.render({ slotted });
1149
+ class Spinner extends ParsedElement() {
1150
+ render() {
1151
+ const slotted = Slots.from(this);
1152
+ template.renderTo(this, { slotted });
1146
1153
  }
1147
1154
  }
1148
1155
 
@@ -1248,10 +1255,8 @@ var ful = (function (exports) {
1248
1255
  exports.SessionStorage = SessionStorage;
1249
1256
  exports.Slots = Slots;
1250
1257
  exports.Spinner = Spinner;
1251
- exports.Stateful = Stateful;
1252
1258
  exports.StatelessInput = StatelessInput;
1253
1259
  exports.SyncEvent = SyncEvent;
1254
- exports.Templated = Templated;
1255
1260
  exports.VersionedStorage = VersionedStorage;
1256
1261
  exports.Wizard = Wizard;
1257
1262
  exports.jsonPatch = jsonPatch;