@optionfactory/ful 0.72.0 → 0.74.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
@@ -566,40 +566,6 @@ class Deferred {
566
566
  }
567
567
  }
568
568
 
569
- // SyncEvent.on($0, 'asd', async e => { await ful.timing.sleep(10_000); return 3; })
570
- // const success = await new SyncEvent("asd").dispatchTo($0);
571
- class SyncEvent extends CustomEvent {
572
- #promises;
573
- #results;
574
- constructor(type, options) {
575
- super(type, {...options, cancelable: true});
576
- this.#promises = [];
577
- this.#results = [];
578
- }
579
- get results(){
580
- return this.#results;
581
- }
582
-
583
- async dispatchTo(el) {
584
- // unlike "native" events, which are fired by the browser and invoke
585
- // event handlers asynchronously via the event loop, dispatchEvent()
586
- // invokes event handlers synchronously.
587
- // see: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent
588
- el.dispatchEvent(this);
589
- //we ignore the result of dispatchEvent and use defaultPrevented instead
590
- //because handlers can be async
591
- this.#results = await Promise.all(this.#promises);
592
- return !this.defaultPrevented;
593
- }
594
-
595
- static on(el, type, h, useCapture) {
596
- el.addEventListener(type, e => {
597
- //e *must* be an async event
598
- e.#promises.push(h(e));
599
- }, useCapture);
600
- }
601
- }
602
-
603
569
  class Fragments {
604
570
  /**
605
571
  *
@@ -855,7 +821,9 @@ const upgradeQueue = new UpgradeQueue();
855
821
  const mappers = {
856
822
  'string': attr => attr,
857
823
  'number': attr => attr === null ? null : Number(attr),
858
- 'bool': attr => attr !== null,
824
+ 'presence': attr => attr !== null,
825
+ 'state': attr => attr !== null,
826
+ 'bool': attr => attr === 'true',
859
827
  'json': attr => JSON.parse(attr)
860
828
  };
861
829
 
@@ -950,7 +918,7 @@ const ParsedElement = (conf) => {
950
918
  }
951
919
  };
952
920
 
953
- for (const [attr, type] of attrsAndTypes.filter(([a, t]) => t === 'bool')) {
921
+ for (const [attr, type] of attrsAndTypes.filter(([a, t]) => t === 'state')) {
954
922
  Object.defineProperty(k.prototype, attr, {
955
923
  enumerable: true,
956
924
  configurable: true,
@@ -958,18 +926,8 @@ const ParsedElement = (conf) => {
958
926
  return this.internals.states.has(`--${attr}`);
959
927
  },
960
928
  set(value) {
961
- const detail = { target: this, value };
962
- const before = new SyncEvent(`${attr}:${this.initialized ? 'change' : 'init'}`, { detail });
963
- const after = new SyncEvent(`${attr}:${this.initialized ? 'changed' : 'inited'}`, { detail });
964
- (async () => {
965
- if (!await before.dispatchTo(this)) {
966
- return;
967
- }
968
- //see https://developer.mozilla.org/en-US/docs/Web/API/CustomStateSet#using_double_dash_prefixed_idents
969
- this.internals.states[value ? 'add' : 'delete'](`--${attr}`);
970
- this.reflect(() => Attributes.toggle(this, attr, value));
971
- await after.dispatchTo(this);
972
- })();
929
+ this.internals.states[value ? 'add' : 'delete'](`--${attr}`);
930
+ this.reflect(() => Attributes.toggle(this, attr, value));
973
931
  }
974
932
  });
975
933
  }
@@ -1031,7 +989,7 @@ function extract(el) {
1031
989
  if (el.dataset['fulBindType'] === 'boolean') {
1032
990
  return !el.value ? null : el.value === 'true';
1033
991
  }
1034
- return el.value || null;
992
+ return el.value === '' || el.value === undefined ? null : el.value;
1035
993
  }
1036
994
 
1037
995
  function mutate(el, raw) {
@@ -1165,9 +1123,7 @@ const makeInputFragment = (el, template, slots) => {
1165
1123
  input.setAttribute('ful-validation-target', '');
1166
1124
  input.addEventListener('change', (evt) => {
1167
1125
  evt.stopPropagation();
1168
- if(!Events.dispatchChange(el, el.value)){
1169
- evt.preventDefault();
1170
- }
1126
+ Events.dispatchChange(el, el.value);
1171
1127
  });
1172
1128
  const id = input.getAttribute('id') || el.getAttribute('input-id') || Attributes.uid('ful-input');
1173
1129
  Attributes.forward('input-', el, slots.input);
@@ -1191,9 +1147,6 @@ class Input extends ParsedElement({
1191
1147
  return this.input.value;
1192
1148
  }
1193
1149
  set value(value) {
1194
- if(!Events.dispatchChange(this, value)){
1195
- return;
1196
- }
1197
1150
  this.input.value = value;
1198
1151
  }
1199
1152
  }
@@ -1272,13 +1225,14 @@ class Select extends ParsedElement({
1272
1225
  }
1273
1226
  callback(data);
1274
1227
  };
1275
-
1276
-
1277
1228
  this.ts = new TomSelect(input, Object.assign(remote ? {
1278
1229
  preload: 'focus',
1279
1230
  load: this._unwrappedRemoteLoad,
1280
1231
  shouldLoad: (query) => this.shouldLoad ? this.shouldLoad(query) : true
1281
1232
  } : {}, tsDefaultConfig, this.tsConfig));
1233
+ this.ts.on('change', value => {
1234
+ Events.dispatchChange(this, this.value);
1235
+ });
1282
1236
  //we remove the input to move it
1283
1237
  input.addEventListener('change', (evt) => {
1284
1238
  evt.stopPropagation();
@@ -1287,10 +1241,10 @@ class Select extends ParsedElement({
1287
1241
  template.renderTo(this, { id, tsId, name, input, slots });
1288
1242
  }
1289
1243
  #loader;
1290
- set loader(l){
1244
+ set loader(l) {
1291
1245
  this.#loader = l;
1292
1246
  // loader can be configured later so we load now
1293
- if(this.hasAttribute('value')){
1247
+ if (this.hasAttribute('value')) {
1294
1248
  this.value = this.getAttribute("value");
1295
1249
  }
1296
1250
  }
@@ -1299,20 +1253,18 @@ class Select extends ParsedElement({
1299
1253
  return v === '' ? null : v;
1300
1254
  }
1301
1255
  set value(value) {
1302
- if(!Events.dispatchChange(this, value)){
1303
- return;
1304
- }
1305
1256
  (async () => {
1306
1257
  if (this._remote) {
1307
1258
  await this._unwrappedRemoteLoad({ byId: value }, this.ts.loadCallback.bind(this.ts));
1308
1259
  }
1309
- this.ts.setValue(value);
1260
+ const silent = true;
1261
+ this.ts.setValue(value, silent);
1310
1262
  })();
1311
1263
  }
1312
1264
  }
1313
1265
 
1314
1266
  class RadioGroup extends ParsedElement({
1315
- observed: ['value', 'disabled:bool'],
1267
+ observed: ['value', 'disabled:state'],
1316
1268
  slots: true,
1317
1269
  template: `
1318
1270
  <fieldset ful-validated-field>
@@ -1348,12 +1300,11 @@ class RadioGroup extends ParsedElement({
1348
1300
  input.setAttribute('name', `${name}-ignore`);
1349
1301
  input.setAttribute('ful-validation-target', '');
1350
1302
  input.dataset['fulBindInclude'] = 'never';
1351
- input.addEventListener('change', (evt) => evt.stopPropagation());
1352
- input.addEventListener('click', (evt) => {
1353
- if(!Events.dispatchChange(this, this.value)){
1354
- evt.preventDefault();
1355
- }
1356
- });
1303
+ input.addEventListener('change', evt => {
1304
+ evt.stopPropagation();
1305
+ //change is not cancelable
1306
+ Events.dispatchChange(el, this.value);
1307
+ });
1357
1308
  const label = Fragments.fromChildNodes(el);
1358
1309
  return [input, label];
1359
1310
  });
@@ -1387,77 +1338,5 @@ class Spinner extends ParsedElement({
1387
1338
  }
1388
1339
  }
1389
1340
 
1390
- class Wizard extends HTMLElement {
1391
- constructor() {
1392
- super();
1393
- this.progress = [...this.children].filter(e => e.matches("header,ol,ul"));
1394
-
1395
- this.progress.forEach(p => {
1396
- const children = [...p.children];
1397
- const current = children.filter(e => e.matches(".active"))[0];
1398
- if (current === undefined && children.length > 0) {
1399
- children[0].classList.add('active');
1400
- }
1401
- });
1402
- if (this.querySelector('section.current') === null) {
1403
- const firstSection = this.querySelector('section:first-of-type');
1404
- if (firstSection !== null) {
1405
- firstSection.classList.add('current');
1406
- }
1407
- }
1408
- }
1409
- next() {
1410
- this.progress.forEach(p => {
1411
- const children = [...p.children];
1412
- const current = children.filter(e => e.matches(".active"))[0];
1413
- current?.classList.remove('active');
1414
- current?.nextElementSibling?.classList.add('active');
1415
- });
1416
- const currentSection = this.querySelector('section.current');
1417
- currentSection.classList.remove("current");
1418
- currentSection.nextElementSibling.classList.add('current');
1419
-
1420
- this.dispatchEvent(new CustomEvent('wizard:activate', {
1421
- bubbles: true,
1422
- cancelable: true
1423
- }));
1424
-
1425
- }
1426
- prev() {
1427
- this.progress.forEach(p => {
1428
- const children = [...p.children];
1429
- const current = children.filter(e => e.matches(".active"))[0];
1430
- current?.classList.remove('active');
1431
- current?.previousElementSibling?.classList.add('active');
1432
- });
1433
- const currentSection = this.querySelector('section.current');
1434
- currentSection.classList.remove("current");
1435
- currentSection.previousElementSibling.classList.add('current');
1436
- this.dispatchEvent(new CustomEvent('wizard:activate', {
1437
- bubbles: true,
1438
- cancelable: true
1439
- }));
1440
- }
1441
- moveTo(n) {
1442
- this.progress.forEach(p => {
1443
- const children = [...p.children];
1444
- const current = children.filter(e => e.matches(".active"))[0];
1445
- current?.classList.remove('active');
1446
- p.children[+n]?.classList.add('active');
1447
- });
1448
- const currentSection = this.querySelector('section.current');
1449
- currentSection?.classList.remove("current");
1450
- const nthSection = this.querySelector(`section:nth-child(${+n})`);
1451
- nthSection.classList.add('current');
1452
- this.dispatchEvent(new CustomEvent('wizard:activate', {
1453
- bubbles: true,
1454
- cancelable: true
1455
- }));
1456
- }
1457
- static configure() {
1458
- return Wizard.custom('ful-wizard');
1459
- }
1460
- }
1461
-
1462
- 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 };
1341
+ export { Attributes, AuthorizationCodeFlow, AuthorizationCodeFlowInterceptor, AuthorizationCodeFlowSession, Base64, Deferred, ElementsRegistry, Failure, Form, Fragments, Hex, HttpClient, INPUT_TEMPLATE, Input, LightSlots, LocalStorage, Nodes, ParsedElement, RadioGroup, Select, SessionStorage, Spinner, TemplatesRegistry, VersionedStorage, elements, jsonPatch, jsonPost, jsonPut, jsonRequest, makeInputFragment, timing };
1463
1342
  //# sourceMappingURL=ful.mjs.map