@optionfactory/ful 0.64.0 → 0.66.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 +52 -28
- 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 +52 -29
- package/dist/ful.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
-
|
|
578
|
-
return
|
|
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.#
|
|
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.remvoeAttribute(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
|
|
911
|
-
const before = new SyncEvent(`${attr}:${
|
|
912
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -1145,7 +1171,7 @@ class Input extends ParsedElement({
|
|
|
1145
1171
|
return this.input.value;
|
|
1146
1172
|
}
|
|
1147
1173
|
set value(value) {
|
|
1148
|
-
if(!Events.dispatchChange(
|
|
1174
|
+
if(!Events.dispatchChange(this, value)){
|
|
1149
1175
|
return;
|
|
1150
1176
|
}
|
|
1151
1177
|
this.input.value = value;
|
|
@@ -1302,10 +1328,7 @@ class RadioGroup extends ParsedElement({
|
|
|
1302
1328
|
input.setAttribute('name', `${name}-ignore`);
|
|
1303
1329
|
input.setAttribute('ful-validation-target', '');
|
|
1304
1330
|
input.dataset['fulBindInclude'] = 'never';
|
|
1305
|
-
input.addEventListener('change', (evt) =>
|
|
1306
|
-
evt.stopPropagation();
|
|
1307
|
-
console.log("stopped");
|
|
1308
|
-
});
|
|
1331
|
+
input.addEventListener('change', (evt) => evt.stopPropagation());
|
|
1309
1332
|
input.addEventListener('click', (evt) => {
|
|
1310
1333
|
if(!Events.dispatchChange(this, this.value)){
|
|
1311
1334
|
evt.preventDefault();
|
|
@@ -1416,5 +1439,5 @@ class Wizard extends HTMLElement {
|
|
|
1416
1439
|
}
|
|
1417
1440
|
}
|
|
1418
1441
|
|
|
1419
|
-
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 };
|
|
1420
1443
|
//# sourceMappingURL=ful.mjs.map
|