@optionfactory/ful 0.53.0 → 0.55.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 +49 -48
- package/dist/ful.iife.js.map +1 -1
- package/dist/ful.iife.min.js +1 -1
- package/dist/ful.iife.min.js.map +1 -1
- package/dist/ful.min.mjs +1 -1
- package/dist/ful.min.mjs.map +1 -1
- package/dist/ful.mjs +49 -48
- package/dist/ful.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ful.iife.js
CHANGED
|
@@ -644,14 +644,6 @@ var ful = (function (exports) {
|
|
|
644
644
|
static uid(prefix) {
|
|
645
645
|
return `${prefix}-${++Attributes.id}`;
|
|
646
646
|
}
|
|
647
|
-
/**
|
|
648
|
-
*
|
|
649
|
-
* @param {any} value
|
|
650
|
-
* @returns
|
|
651
|
-
*/
|
|
652
|
-
static asBoolean(value) {
|
|
653
|
-
return value !== null && value !== undefined && value !== false;
|
|
654
|
-
}
|
|
655
647
|
/**
|
|
656
648
|
*
|
|
657
649
|
* @param {HTMLElement} el
|
|
@@ -754,36 +746,36 @@ var ful = (function (exports) {
|
|
|
754
746
|
#tagToclass;
|
|
755
747
|
#configured;
|
|
756
748
|
#id = 0;
|
|
757
|
-
constructor(){
|
|
749
|
+
constructor() {
|
|
758
750
|
this.#templates = new TemplatesRegistry();
|
|
759
751
|
this.#tagToclass = {};
|
|
760
752
|
}
|
|
761
|
-
defineTemplate(html){
|
|
762
|
-
if(html === null || html === undefined){
|
|
753
|
+
defineTemplate(html) {
|
|
754
|
+
if (html === null || html === undefined) {
|
|
763
755
|
return undefined;
|
|
764
756
|
}
|
|
765
757
|
const name = `unnamed-${++this.#id}`;
|
|
766
758
|
this.#templates.put(name, Fragments.fromHtml(html));
|
|
767
759
|
return name;
|
|
768
760
|
}
|
|
769
|
-
template(k){
|
|
770
|
-
if(k === null || k === undefined){
|
|
761
|
+
template(k) {
|
|
762
|
+
if (k === null || k === undefined) {
|
|
771
763
|
return undefined;
|
|
772
764
|
}
|
|
773
765
|
return this.#templates.get(k);
|
|
774
766
|
}
|
|
775
|
-
define(tag, klass){
|
|
776
|
-
if(!this.#configured){
|
|
767
|
+
define(tag, klass) {
|
|
768
|
+
if (!this.#configured) {
|
|
777
769
|
this.#tagToclass[tag] = klass;
|
|
778
770
|
return this;
|
|
779
771
|
}
|
|
780
|
-
customElements.define(tag, klass);
|
|
772
|
+
customElements.define(tag, klass);
|
|
781
773
|
return this;
|
|
782
774
|
}
|
|
783
775
|
configure(ec) {
|
|
784
776
|
this.#templates.configure(ec);
|
|
785
|
-
for(const [tag, klass] of Object.entries(this.#tagToclass)) {
|
|
786
|
-
customElements.define(tag, klass);
|
|
777
|
+
for (const [tag, klass] of Object.entries(this.#tagToclass)) {
|
|
778
|
+
customElements.define(tag, klass);
|
|
787
779
|
delete this.#tagToclass[tag];
|
|
788
780
|
}
|
|
789
781
|
this.#configured = true;
|
|
@@ -811,18 +803,34 @@ var ful = (function (exports) {
|
|
|
811
803
|
|
|
812
804
|
const upgradeQueue = new UpgradeQueue();
|
|
813
805
|
|
|
806
|
+
const mappers = {
|
|
807
|
+
'string': attr => attr,
|
|
808
|
+
'number': attr => attr === null ? null : Number(attr),
|
|
809
|
+
'bool': attr => attr !== null,
|
|
810
|
+
'json': attr => JSON.parse(attr)
|
|
811
|
+
};
|
|
812
|
+
|
|
814
813
|
const ParsedElement = (conf) => {
|
|
815
|
-
const {
|
|
814
|
+
const { observed, template, slots } = conf || {};
|
|
815
|
+
|
|
816
|
+
const attrsAndTypes = (observed || []).map(a => {
|
|
817
|
+
const [attr, maybeType] = a.split(":");
|
|
818
|
+
const type = maybeType?.trim() || 'string';
|
|
819
|
+
if (!(type in mappers)) {
|
|
820
|
+
throw new Error(`unsupported attribute type: ${type}`);
|
|
821
|
+
}
|
|
822
|
+
return [attr.trim(), type];
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
const attrsAndMappers = attrsAndTypes.map(([attr, type]) => [attr, mappers[type]]);
|
|
816
826
|
|
|
817
|
-
const
|
|
818
|
-
const observed_attributes = attributes || [];
|
|
819
|
-
const observed = [].concat(observed_states).concat(observed_attributes);
|
|
827
|
+
const attrToMapper = Object.fromEntries(attrsAndMappers);
|
|
820
828
|
|
|
821
829
|
const templateId = elements.defineTemplate(template);
|
|
822
830
|
|
|
823
831
|
const k = class extends HTMLElement {
|
|
824
832
|
static get observedAttributes() {
|
|
825
|
-
return
|
|
833
|
+
return Object.keys(attrToMapper);
|
|
826
834
|
}
|
|
827
835
|
#parsed;
|
|
828
836
|
#initialized;
|
|
@@ -831,7 +839,7 @@ var ful = (function (exports) {
|
|
|
831
839
|
super(...args);
|
|
832
840
|
this.#internals = this.attachInternals();
|
|
833
841
|
}
|
|
834
|
-
get initialized(){
|
|
842
|
+
get initialized() {
|
|
835
843
|
return this.#initialized;
|
|
836
844
|
}
|
|
837
845
|
get internals() {
|
|
@@ -858,11 +866,12 @@ var ful = (function (exports) {
|
|
|
858
866
|
});
|
|
859
867
|
observer.observe(this.parentNode, { childList: true, subtree: true });
|
|
860
868
|
}
|
|
861
|
-
attributeChangedCallback(
|
|
869
|
+
attributeChangedCallback(attr, oldValue, newValue) {
|
|
862
870
|
if (!this.#parsed || oldValue === newValue) {
|
|
863
871
|
return;
|
|
864
872
|
}
|
|
865
|
-
|
|
873
|
+
const mapper = attrToMapper[attr];
|
|
874
|
+
this[attr] = mapper(newValue);
|
|
866
875
|
}
|
|
867
876
|
async upgrade() {
|
|
868
877
|
if (this.#parsed) {
|
|
@@ -870,34 +879,29 @@ var ful = (function (exports) {
|
|
|
870
879
|
}
|
|
871
880
|
this.#parsed = true;
|
|
872
881
|
await this.render(elements.template(templateId), slots ? LightSlots.from(this) : undefined);
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}
|
|
878
|
-
for (const other of observed_attributes) {
|
|
879
|
-
if (this.hasAttribute(other)) {
|
|
880
|
-
this[other] = this.getAttribute(other);
|
|
882
|
+
|
|
883
|
+
for (const [attr, mapper] of attrsAndMappers) {
|
|
884
|
+
if (this.hasAttribute(attr)) {
|
|
885
|
+
this[attr] = mapper(this.getAttribute(attr));
|
|
881
886
|
}
|
|
882
887
|
}
|
|
883
888
|
this.#initialized = true;
|
|
884
889
|
}
|
|
885
890
|
};
|
|
886
891
|
|
|
887
|
-
for (const
|
|
888
|
-
Object.defineProperty(k.prototype,
|
|
892
|
+
for (const [attr, type] of attrsAndTypes.filter(([a, t]) => t === 'bool')) {
|
|
893
|
+
Object.defineProperty(k.prototype, attr, {
|
|
889
894
|
enumerable: true,
|
|
890
895
|
configurable: true,
|
|
891
896
|
get() {
|
|
892
|
-
return this.internals.states.has(`--${
|
|
897
|
+
return this.internals.states.has(`--${attr}`);
|
|
893
898
|
},
|
|
894
899
|
set(value) {
|
|
895
|
-
const v = Attributes.asBoolean(value);
|
|
896
900
|
const et = this.initialized ? 'changed' : 'init';
|
|
897
|
-
const event = new SyncEvent(`${
|
|
898
|
-
detail: {
|
|
901
|
+
const event = new SyncEvent(`${attr}:${et}`, {
|
|
902
|
+
detail: {
|
|
899
903
|
target: this,
|
|
900
|
-
value:
|
|
904
|
+
value: value
|
|
901
905
|
}
|
|
902
906
|
});
|
|
903
907
|
(async () => {
|
|
@@ -906,7 +910,7 @@ var ful = (function (exports) {
|
|
|
906
910
|
return;
|
|
907
911
|
}
|
|
908
912
|
//see https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet#using_double_dash_prefixed_idents
|
|
909
|
-
this.internals.states[
|
|
913
|
+
this.internals.states[value ? 'add' : 'delete'](`--${attr}`);
|
|
910
914
|
})();
|
|
911
915
|
}
|
|
912
916
|
});
|
|
@@ -1094,8 +1098,7 @@ var ful = (function (exports) {
|
|
|
1094
1098
|
};
|
|
1095
1099
|
|
|
1096
1100
|
class Input extends ParsedElement({
|
|
1097
|
-
|
|
1098
|
-
attributes: ['value'],
|
|
1101
|
+
observed: ['value'],
|
|
1099
1102
|
slots: true,
|
|
1100
1103
|
template: INPUT_TEMPLATE
|
|
1101
1104
|
}){
|
|
@@ -1117,8 +1120,7 @@ var ful = (function (exports) {
|
|
|
1117
1120
|
*/
|
|
1118
1121
|
|
|
1119
1122
|
class Select extends ParsedElement({
|
|
1120
|
-
|
|
1121
|
-
attributes: ["value"],
|
|
1123
|
+
observed: ["value"],
|
|
1122
1124
|
slots: true,
|
|
1123
1125
|
template: `
|
|
1124
1126
|
<label data-tpl-for="tsId" class="form-label">{{{{ slots.default }}}}</label>
|
|
@@ -1218,8 +1220,7 @@ var ful = (function (exports) {
|
|
|
1218
1220
|
}
|
|
1219
1221
|
|
|
1220
1222
|
class RadioGroup extends ParsedElement({
|
|
1221
|
-
|
|
1222
|
-
attributes: ['value'],
|
|
1223
|
+
observed: ['value', 'disabled:bool'],
|
|
1223
1224
|
slots: true,
|
|
1224
1225
|
template: `
|
|
1225
1226
|
<fieldset>
|