@optionfactory/ful 0.45.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
@@ -589,14 +589,14 @@ var ful = (function (exports) {
589
589
 
590
590
  class Fragments {
591
591
  static fromHtml(...html) {
592
- const el = document.createElement('div');
592
+ const el = document.createElement("div");
593
593
  el.innerHTML = html.join("");
594
594
  const fragment = new DocumentFragment();
595
595
  fragment.append(...el.childNodes);
596
596
  return fragment;
597
597
  }
598
598
  static toHtml(fragment) {
599
- var r = document.createElement("root");
599
+ var r = document.createElement("div");
600
600
  r.appendChild(fragment);
601
601
  return r.innerHTML;
602
602
  }
@@ -686,86 +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.innerHTML = '';
734
- if (fragment) {
735
- this.appendChild(fragment);
736
- }
737
- }
738
- };
739
- };
740
-
741
- const Stateful = (SuperClass, flags, others) => {
689
+ const ParsedElement = (flags, others) => {
742
690
 
743
- const all = [].concat(flags).concat(others || []);
691
+ const observed_flags = flags || [];
692
+ const observed_others = others || [];
693
+ const observed = [].concat(observed_flags).concat(observed_others);
744
694
 
745
- const k = class extends SuperClass {
695
+ const k = class extends HTMLElement {
746
696
  static get observedAttributes() {
747
- return all;
697
+ return observed;
748
698
  }
699
+ #parsed;
700
+ #internals;
749
701
  constructor(...args) {
750
702
  super(...args);
751
- this.internals_ = this.internals_ || this.attachInternals();
703
+ this.#internals = this.attachInternals();
752
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;
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
+ }
753
752
  };
754
753
 
755
- for (const flag of flags) {
754
+ for (const flag of observed_flags) {
756
755
  Object.defineProperty(k.prototype, flag, {
757
756
  enumerable: true,
758
757
  configurable: true,
759
758
  get() {
760
- return this.internals_.states.has(`--${flag}`);
759
+ return this.internals.states.has(`--${flag}`);
761
760
  },
762
761
  set(value) {
763
762
  //see https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet#using_double_dash_prefixed_idents
764
763
  if (Attributes.asBoolean(value)) {
765
- this.internals_.states.add(`--${flag}`);
764
+ this.internals.states.add(`--${flag}`);
766
765
  return;
767
766
  }
768
- this.internals_.states.delete(`--${flag}`);
767
+ this.internals.states.delete(`--${flag}`);
769
768
  }
770
769
  });
771
770
  }
@@ -842,12 +841,12 @@ var ful = (function (exports) {
842
841
  el.value = raw;
843
842
  }
844
843
 
845
- class Form extends Templated(ParsedElement) {
844
+ class Form extends ParsedElement() {
846
845
  static IGNORED_CHILDREN_SELECTOR = '.d-none, [hidden]';
847
846
  static SCROLL_OFFSET = 50;
848
- render(slotted) {
847
+ render() {
849
848
  const form = document.createElement('form');
850
- form.append(slotted.default);
849
+ form.replaceChildren(...this.childNodes);
851
850
  form.addEventListener('submit', async (e) => {
852
851
  e.preventDefault();
853
852
  this.spinner(true);
@@ -865,7 +864,7 @@ var ful = (function (exports) {
865
864
  this.spinner(false);
866
865
  }
867
866
  });
868
- return form;
867
+ this.replaceChildren(form);
869
868
  }
870
869
  spinner(spin) {
871
870
  this.querySelectorAll('ful-spinner').forEach(el => el.hidden = !spin);
@@ -893,7 +892,7 @@ var ful = (function (exports) {
893
892
  const globalErrors = es.filter((e) => e.type !== 'FIELD_ERROR' && e.type !== 'INVALID_FORMAT');
894
893
  this.querySelectorAll('.is-invalid').forEach(el => el.classList.remove('is-invalid'));
895
894
  this.querySelectorAll("ful-errors").forEach(el => {
896
- el.innerHTML = '';
895
+ el.replaceChildren();
897
896
  el.setAttribute('hidden', '');
898
897
  });
899
898
  fieldErrors.forEach((e) => {
@@ -926,7 +925,7 @@ var ful = (function (exports) {
926
925
 
927
926
  });
928
927
 
929
- const ful_input_template_ = globalThis.ful_input_template || ftl.Template.fromHtml(`
928
+ const template$1 = globalThis.ful_input_template || ftl.Template.fromHtml(`
930
929
  <label data-tpl-for="id" class="form-label">{{{{ slotted.default }}}}</label>
931
930
  <div class="input-group">
932
931
  <span data-tpl-if="slotted.ibefore" class="input-group-text">{{{{ slotted.ibefore }}}}</span>
@@ -938,31 +937,34 @@ var ful = (function (exports) {
938
937
  <ful-field-error data-tpl-if="name" data-tpl-field="name"></ful-field-error>
939
938
  `, ful_input_ec);
940
939
 
941
- class StatelessInput extends Templated(ParsedElement, ful_input_template_) {
942
- render(slotted, template) {
943
- const input = this.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', '');
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
+ };
949
958
 
950
- const id = input.getAttribute('id') || this.getAttribute('input-id') || Attributes.uid('ful-input');
951
- Attributes.forward('input-', this, 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 = this.getAttribute('name');
956
- return template.render({ id, name, slotted });
959
+ class StatelessInput extends ParsedElement() {
960
+ render() {
961
+ renderInput(this);
957
962
  }
958
-
959
963
  }
960
964
 
961
- class Input extends Stateful(StatelessInput, [], ['value']) {
962
- render(slotted, template) {
963
- const fragment = super.render(slotted, template);
964
- this.input.value = this.getAttribute('value');
965
- return fragment;
965
+ class Input extends ParsedElement([], ['value']) {
966
+ render() {
967
+ renderInput(this);
966
968
  }
967
969
  get value() {
968
970
  return this.input.value;
@@ -994,12 +996,14 @@ var ful = (function (exports) {
994
996
  `, ful_select_ec);
995
997
 
996
998
 
997
- class Select extends Stateful(Templated(ParsedElement, ful_select_template_), [], ["value"]) {
999
+ class Select extends ParsedElement([], ["value"]) {
998
1000
  constructor(tsConfig) {
999
1001
  super();
1000
1002
  this.tsConfig = tsConfig;
1001
1003
  }
1002
- render(slotted, template) {
1004
+ render() {
1005
+ const slotted = Slots.from(this);
1006
+
1003
1007
  const type = this.getAttribute("type") || 'local';
1004
1008
  const remote = type != 'local';
1005
1009
  const loadOnce = this.getAttribute('load') != 'always';
@@ -1027,7 +1031,6 @@ var ful = (function (exports) {
1027
1031
  }
1028
1032
  };
1029
1033
 
1030
-
1031
1034
  this._remote = remote;
1032
1035
  // we need to await this load in setValue when remote is configured and the option
1033
1036
  // is not loaded yet.
@@ -1042,7 +1045,7 @@ var ful = (function (exports) {
1042
1045
  const type = query && query.hasOwnProperty('byId') ? 'id' : 'query';
1043
1046
  const qvalue = type === 'id' ? query.byId : query;
1044
1047
  const data = await (this.loader ? this.loader(qvalue, type) : []);
1045
- if(type !== 'id'){
1048
+ if (type !== 'id') {
1046
1049
  this.loaded = true;
1047
1050
  }
1048
1051
  callback(data);
@@ -1056,12 +1059,12 @@ var ful = (function (exports) {
1056
1059
  } : {}, tsDefaultConfig, this.tsConfig));
1057
1060
  //we remove the input to move it
1058
1061
  input.remove();
1059
- return template.render({ id, tsId, name, input, slotted });
1062
+ ful_select_template_.renderTo(this, { id, tsId, name, input, slotted });
1060
1063
  }
1061
1064
  set value(v) {
1062
1065
  (async () => {
1063
- if(this._remote){
1064
- 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));
1065
1068
  }
1066
1069
  this.ts.setValue(v);
1067
1070
  })();
@@ -1098,8 +1101,9 @@ var ful = (function (exports) {
1098
1101
  `, ful_radiogroup_ec);
1099
1102
 
1100
1103
 
1101
- class RadioGroup extends Stateful(Templated(ParsedElement, ful_radiougroup_template_), ['disabled'], ['value']) {
1102
- render(slotted, template) {
1104
+ class RadioGroup extends ParsedElement(['disabled'], ['value']) {
1105
+ render() {
1106
+ const slotted = Slots.from(this);
1103
1107
  const name = this.getAttribute('name') || Attributes.uid('ful-radiogroup');
1104
1108
  const radioEls = Array.from(slotted.default.querySelectorAll('ful-radio'));
1105
1109
  const inputsAndLabels = radioEls.map(el => {
@@ -1114,19 +1118,18 @@ var ful = (function (exports) {
1114
1118
  return [input, label];
1115
1119
  });
1116
1120
  radioEls.forEach(el => el.remove());
1117
-
1118
- const fragment = template.render({
1121
+
1122
+ ful_radiougroup_template_.renderTo(this, {
1119
1123
  name: name,
1120
1124
  slotted: slotted,
1121
1125
  inputsAndLabels: inputsAndLabels
1122
1126
  });
1123
- return fragment;
1124
1127
  }
1125
1128
  get value() {
1126
1129
  const checked = this.querySelector('input[type=radio]:checked');
1127
1130
  return checked ? checked.value : null;
1128
1131
  }
1129
- set value(value){
1132
+ set value(value) {
1130
1133
  this.querySelector(`input[type=radio][value=${CSS.escape(value)}]`).checked = true;
1131
1134
  }
1132
1135
  }
@@ -1135,7 +1138,7 @@ var ful = (function (exports) {
1135
1138
 
1136
1139
  });
1137
1140
 
1138
- const ful_spinner_template_ = globalThis.ful_spinner_template || ftl.Template.fromHtml(`
1141
+ const template = globalThis.ful_spinner_template || ftl.Template.fromHtml(`
1139
1142
  <div class="ful-spinner-wrapper">
1140
1143
  <div class="ful-spinner-text">{{{{ slotted.default }}}}</div>
1141
1144
  <div class="ful-spinner-icon"></div>
@@ -1143,9 +1146,10 @@ var ful = (function (exports) {
1143
1146
  `, ful_spinner_ec);
1144
1147
 
1145
1148
 
1146
- class Spinner extends Templated(ParsedElement, ful_spinner_template_) {
1147
- render(slotted, template) {
1148
- return template.render({ slotted });
1149
+ class Spinner extends ParsedElement() {
1150
+ render() {
1151
+ const slotted = Slots.from(this);
1152
+ template.renderTo(this, { slotted });
1149
1153
  }
1150
1154
  }
1151
1155
 
@@ -1251,10 +1255,8 @@ var ful = (function (exports) {
1251
1255
  exports.SessionStorage = SessionStorage;
1252
1256
  exports.Slots = Slots;
1253
1257
  exports.Spinner = Spinner;
1254
- exports.Stateful = Stateful;
1255
1258
  exports.StatelessInput = StatelessInput;
1256
1259
  exports.SyncEvent = SyncEvent;
1257
- exports.Templated = Templated;
1258
1260
  exports.VersionedStorage = VersionedStorage;
1259
1261
  exports.Wizard = Wizard;
1260
1262
  exports.jsonPatch = jsonPatch;