cotomy 0.3.2 → 0.3.4

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.
@@ -174,7 +174,7 @@ module.exports = cuid;
174
174
  /***/ 826:
175
175
  /***/ (function(module) {
176
176
 
177
- !function(t,i){ true?module.exports=i():0}(this,(function(){"use strict";var t="minute",i=/[+-]\d\d(?::?\d\d)?/g,e=/([+-]|\d\d)/g;return function(s,f,n){var u=f.prototype;n.utc=function(t){var i={date:t,utc:!0,args:arguments};return new f(i)},u.utc=function(i){var e=n(this.toDate(),{locale:this.$L,utc:!0});return i?e.add(this.utcOffset(),t):e},u.local=function(){return n(this.toDate(),{locale:this.$L,utc:!1})};var r=u.parse;u.parse=function(t){t.utc&&(this.$u=!0),this.$utils().u(t.$offset)||(this.$offset=t.$offset),r.call(this,t)};var o=u.init;u.init=function(){if(this.$u){var t=this.$d;this.$y=t.getUTCFullYear(),this.$M=t.getUTCMonth(),this.$D=t.getUTCDate(),this.$W=t.getUTCDay(),this.$H=t.getUTCHours(),this.$m=t.getUTCMinutes(),this.$s=t.getUTCSeconds(),this.$ms=t.getUTCMilliseconds()}else o.call(this)};var a=u.utcOffset;u.utcOffset=function(s,f){var n=this.$utils().u;if(n(s))return this.$u?0:n(this.$offset)?a.call(this):this.$offset;if("string"==typeof s&&(s=function(t){void 0===t&&(t="");var s=t.match(i);if(!s)return null;var f=(""+s[0]).match(e)||["-",0,0],n=f[0],u=60*+f[1]+ +f[2];return 0===u?0:"+"===n?u:-u}(s),null===s))return this;var u=Math.abs(s)<=16?60*s:s;if(0===u)return this.utc(f);var r=this.clone();if(f)return r.$offset=u,r.$u=!1,r;var o=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();return(r=this.local().add(u+o,t)).$offset=u,r.$x.$localOffset=o,r};var h=u.format;u.format=function(t){var i=t||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,i)},u.valueOf=function(){var t=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*t},u.isUTC=function(){return!!this.$u},u.toISOString=function(){return this.toDate().toISOString()},u.toString=function(){return this.toDate().toUTCString()};var l=u.toDate;u.toDate=function(t){return"s"===t&&this.$offset?n(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():l.call(this)};var c=u.diff;u.diff=function(t,i,e){if(t&&this.$u===t.$u)return c.call(this,t,i,e);var s=this.local(),f=n(t).local();return c.call(s,f,i,e)}}}));
177
+ !function(t,i){ true?module.exports=i():0}(this,(function(){"use strict";var t="minute",i=/[+-]\d\d(?::?\d\d)?/g,e=/([+-]|\d\d)/g;return function(s,f,n){var u=f.prototype;n.utc=function(t){var i={date:t,utc:!0,args:arguments};return new f(i)},u.utc=function(i){var e=n(this.toDate(),{locale:this.$L,utc:!0});return i?e.add(this.utcOffset(),t):e},u.local=function(){return n(this.toDate(),{locale:this.$L,utc:!1})};var o=u.parse;u.parse=function(t){t.utc&&(this.$u=!0),this.$utils().u(t.$offset)||(this.$offset=t.$offset),o.call(this,t)};var r=u.init;u.init=function(){if(this.$u){var t=this.$d;this.$y=t.getUTCFullYear(),this.$M=t.getUTCMonth(),this.$D=t.getUTCDate(),this.$W=t.getUTCDay(),this.$H=t.getUTCHours(),this.$m=t.getUTCMinutes(),this.$s=t.getUTCSeconds(),this.$ms=t.getUTCMilliseconds()}else r.call(this)};var a=u.utcOffset;u.utcOffset=function(s,f){var n=this.$utils().u;if(n(s))return this.$u?0:n(this.$offset)?a.call(this):this.$offset;if("string"==typeof s&&(s=function(t){void 0===t&&(t="");var s=t.match(i);if(!s)return null;var f=(""+s[0]).match(e)||["-",0,0],n=f[0],u=60*+f[1]+ +f[2];return 0===u?0:"+"===n?u:-u}(s),null===s))return this;var u=Math.abs(s)<=16?60*s:s,o=this;if(f)return o.$offset=u,o.$u=0===s,o;if(0!==s){var r=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(o=this.local().add(u+r,t)).$offset=u,o.$x.$localOffset=r}else o=this.utc();return o};var h=u.format;u.format=function(t){var i=t||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return h.call(this,i)},u.valueOf=function(){var t=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*t},u.isUTC=function(){return!!this.$u},u.toISOString=function(){return this.toDate().toISOString()},u.toString=function(){return this.toDate().toUTCString()};var l=u.toDate;u.toDate=function(t){return"s"===t&&this.$offset?n(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():l.call(this)};var c=u.diff;u.diff=function(t,i,e){if(t&&this.$u===t.$u)return c.call(this,t,i,e);var s=this.local(),f=n(t).local();return c.call(s,f,i,e)}}}));
178
178
 
179
179
  /***/ })
180
180
 
@@ -943,10 +943,24 @@ class CotomyElement {
943
943
  }
944
944
  }
945
945
  }
946
- this.removed(() => {
947
- this._element = CotomyElement.createHTMLElement(`<div data-cotomy-invalidated style="display: none;"></div>`);
948
- EventRegistry.instance.clear(this);
949
- });
946
+ if (!this.instanceId) {
947
+ this.attribute("data-cotomy-instance", `__cotomy_instance_${cuid_default()()}`);
948
+ this.removed(() => {
949
+ this._element = CotomyElement.createHTMLElement(`<div data-cotomy-invalidated style="display: none;"></div>`);
950
+ EventRegistry.instance.clear(this);
951
+ });
952
+ this.on("cotomy:transitstart", () => {
953
+ this.attribute("data-cotomy-moving", "");
954
+ this.find("[data-cotomy-instance]").forEach(e => e.attribute("data-cotomy-moving", ""));
955
+ });
956
+ this.on("cotomy:transitend", () => {
957
+ this.attribute("data-cotomy-moving", null);
958
+ this.find("[data-cotomy-instance]").forEach(e => e.attribute("data-cotomy-moving", null));
959
+ });
960
+ }
961
+ }
962
+ get instanceId() {
963
+ return this.attribute("data-cotomy-instance");
950
964
  }
951
965
  get scopeId() {
952
966
  if (!this._scopeId) {
@@ -1400,12 +1414,25 @@ class CotomyElement {
1400
1414
  contains(selector) {
1401
1415
  return this.find(selector).length > 0;
1402
1416
  }
1417
+ static runWithMoveEvents(target, operation) {
1418
+ target.trigger("cotomy:transitstart");
1419
+ try {
1420
+ operation();
1421
+ }
1422
+ finally {
1423
+ target.trigger("cotomy:transitend");
1424
+ }
1425
+ }
1403
1426
  prepend(prepend) {
1404
- this._element.prepend(prepend.element);
1427
+ CotomyElement.runWithMoveEvents(prepend, () => {
1428
+ this.element.prepend(prepend.element);
1429
+ });
1405
1430
  return this;
1406
1431
  }
1407
1432
  append(target) {
1408
- this.element.append(target.element);
1433
+ CotomyElement.runWithMoveEvents(target, () => {
1434
+ this.element.append(target.element);
1435
+ });
1409
1436
  return this;
1410
1437
  }
1411
1438
  appendAll(targets) {
@@ -1413,19 +1440,27 @@ class CotomyElement {
1413
1440
  return this;
1414
1441
  }
1415
1442
  insertBefore(append) {
1416
- this.element.before(append.element);
1443
+ CotomyElement.runWithMoveEvents(append, () => {
1444
+ this.element.before(append.element);
1445
+ });
1417
1446
  return this;
1418
1447
  }
1419
1448
  insertAfter(append) {
1420
- this.element.after(append.element);
1449
+ CotomyElement.runWithMoveEvents(append, () => {
1450
+ this.element.after(append.element);
1451
+ });
1421
1452
  return this;
1422
1453
  }
1423
1454
  appendTo(target) {
1424
- target.element.append(this.element);
1455
+ CotomyElement.runWithMoveEvents(this, () => {
1456
+ target.element.append(this.element);
1457
+ });
1425
1458
  return this;
1426
1459
  }
1427
1460
  prependTo(target) {
1428
- target.element.prepend(this.element);
1461
+ CotomyElement.runWithMoveEvents(this, () => {
1462
+ target.element.prepend(this.element);
1463
+ });
1429
1464
  return this;
1430
1465
  }
1431
1466
  trigger(event, e) {
@@ -1433,8 +1468,11 @@ class CotomyElement {
1433
1468
  return this;
1434
1469
  }
1435
1470
  on(event, handle, options) {
1436
- const entry = new HandlerEntry(handle, undefined, options);
1437
- EventRegistry.instance.on(event, this, entry);
1471
+ const events = Array.isArray(event) ? event : [event];
1472
+ events.forEach(eventName => {
1473
+ const entry = new HandlerEntry(handle, undefined, options);
1474
+ EventRegistry.instance.on(eventName, this, entry);
1475
+ });
1438
1476
  return this;
1439
1477
  }
1440
1478
  onSubTree(event, selector, handle, options) {
@@ -1444,25 +1482,34 @@ class CotomyElement {
1444
1482
  return handle(e);
1445
1483
  }
1446
1484
  };
1447
- const entry = new HandlerEntry(handle, delegate, options);
1448
- EventRegistry.instance.on(event, this, entry);
1485
+ const events = Array.isArray(event) ? event : [event];
1486
+ events.forEach(eventName => {
1487
+ const entry = new HandlerEntry(handle, delegate, options);
1488
+ EventRegistry.instance.on(eventName, this, entry);
1489
+ });
1449
1490
  return this;
1450
1491
  }
1451
1492
  once(event, handle, options) {
1452
1493
  const mergedOptions = { ...(options ?? {}), once: true };
1453
- const entry = new HandlerEntry(handle, undefined, mergedOptions);
1454
1494
  this.off(event, handle, mergedOptions);
1455
- EventRegistry.instance.on(event, this, entry);
1495
+ const events = Array.isArray(event) ? event : [event];
1496
+ events.forEach(eventName => {
1497
+ const entry = new HandlerEntry(handle, undefined, mergedOptions);
1498
+ EventRegistry.instance.on(eventName, this, entry);
1499
+ });
1456
1500
  return this;
1457
1501
  }
1458
1502
  off(event, handle, options) {
1459
- if (handle) {
1460
- const entry = new HandlerEntry(handle, undefined, options);
1461
- EventRegistry.instance.off(event, this, entry);
1462
- }
1463
- else {
1464
- EventRegistry.instance.off(event, this);
1465
- }
1503
+ const events = Array.isArray(event) ? event : [event];
1504
+ events.forEach(eventName => {
1505
+ if (handle) {
1506
+ const entry = new HandlerEntry(handle, undefined, options);
1507
+ EventRegistry.instance.off(eventName, this, entry);
1508
+ }
1509
+ else {
1510
+ EventRegistry.instance.off(eventName, this);
1511
+ }
1512
+ });
1466
1513
  return this;
1467
1514
  }
1468
1515
  click(handle) {
@@ -1823,7 +1870,9 @@ class CotomyWindow {
1823
1870
  mutation.removedNodes.forEach(node => {
1824
1871
  if (typeof HTMLElement !== "undefined" && node instanceof HTMLElement) {
1825
1872
  const element = new CotomyElement(node);
1826
- element.trigger("removed");
1873
+ if (!element.hasAttribute("data-cotomy-moving") && !element.attached) {
1874
+ element.trigger("removed");
1875
+ }
1827
1876
  }
1828
1877
  });
1829
1878
  });
@@ -1865,22 +1914,34 @@ class CotomyWindow {
1865
1914
  window.dispatchEvent(e ?? new Event(event, { bubbles: true }));
1866
1915
  }
1867
1916
  on(event, handle) {
1868
- if (!this._eventHandlers[event])
1869
- this._eventHandlers[event] = [];
1870
- this._eventHandlers[event].push(handle);
1871
- window.addEventListener(event, handle);
1917
+ const events = Array.isArray(event) ? event : [event];
1918
+ events.forEach(eventName => {
1919
+ if (!this._eventHandlers[eventName])
1920
+ this._eventHandlers[eventName] = [];
1921
+ this._eventHandlers[eventName].push(handle);
1922
+ window.addEventListener(eventName, handle);
1923
+ });
1872
1924
  }
1873
1925
  off(event, handle) {
1874
- if (handle) {
1875
- window.removeEventListener(event, handle);
1876
- this._eventHandlers[event] = this._eventHandlers[event]?.filter(h => h !== handle) ?? [];
1877
- }
1878
- else {
1879
- for (const h of this._eventHandlers[event] ?? []) {
1880
- window.removeEventListener(event, h);
1926
+ const events = Array.isArray(event) ? event : [event];
1927
+ events.forEach(eventName => {
1928
+ if (handle) {
1929
+ window.removeEventListener(eventName, handle);
1930
+ const handlers = this._eventHandlers[eventName]?.filter(h => h !== handle) ?? [];
1931
+ if (handlers.length > 0) {
1932
+ this._eventHandlers[eventName] = handlers;
1933
+ }
1934
+ else {
1935
+ delete this._eventHandlers[eventName];
1936
+ }
1881
1937
  }
1882
- delete this._eventHandlers[event];
1883
- }
1938
+ else {
1939
+ for (const h of this._eventHandlers[eventName] ?? []) {
1940
+ window.removeEventListener(eventName, h);
1941
+ }
1942
+ delete this._eventHandlers[eventName];
1943
+ }
1944
+ });
1884
1945
  }
1885
1946
  load(handle) {
1886
1947
  this.on("load", handle);
@@ -2659,7 +2720,7 @@ class CotomyEntityApiForm extends CotomyApiForm {
2659
2720
  this.attribute("data-cotomy-entity-key", addedParts[0]);
2660
2721
  }
2661
2722
  else {
2662
- const msg = `Location does not contain a single entity key segment.
2723
+ const msg = `Location does not contain a single entity key segment.
2663
2724
  action="${baseAction}", location="${locPath}", added=["${addedParts.join('","')}"]`;
2664
2725
  throw new Error(msg);
2665
2726
  }
@@ -2749,8 +2810,8 @@ class CotomyEntityFillApiForm extends CotomyEntityApiForm {
2749
2810
  }
2750
2811
  }
2751
2812
  applyValueToInputs(pname, value) {
2752
- this.find(`input[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple]),
2753
- textarea[name="${pname}" i]:not([data-cotomy-fill="false"]),
2813
+ this.find(`input[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple]),
2814
+ textarea[name="${pname}" i]:not([data-cotomy-fill="false"]),
2754
2815
  select[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple])`).forEach(input => {
2755
2816
  if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Fill)) {
2756
2817
  console.debug(`Filling input[name="${pname}"] with value:`, value);