cotomy 0.3.3 → 0.3.5

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 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)}}}));
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)}}}));
178
178
 
179
179
  /***/ })
180
180
 
@@ -916,7 +916,6 @@ class CotomyElement {
916
916
  }
917
917
  constructor(element) {
918
918
  this._parentElement = null;
919
- this._scopeId = null;
920
919
  if (element instanceof HTMLElement) {
921
920
  this._element = element;
922
921
  }
@@ -944,7 +943,7 @@ class CotomyElement {
944
943
  }
945
944
  }
946
945
  if (!this.instanceId) {
947
- this.attribute("data-cotomy-instance", `__cotomy_instance_${cuid_default()()}`);
946
+ this.attribute("data-cotomy-instance", cuid_default()());
948
947
  this.removed(() => {
949
948
  this._element = CotomyElement.createHTMLElement(`<div data-cotomy-invalidated style="display: none;"></div>`);
950
949
  EventRegistry.instance.clear(this);
@@ -963,14 +962,10 @@ class CotomyElement {
963
962
  return this.attribute("data-cotomy-instance");
964
963
  }
965
964
  get scopeId() {
966
- if (!this._scopeId) {
967
- this._scopeId = `__cotomy_scope__${cuid_default()()}`;
968
- this.attribute(this._scopeId, "");
965
+ if (!this.hasAttribute("data-cotomy-scopeid")) {
966
+ this.attribute("data-cotomy-scopeid", cuid_default()());
969
967
  }
970
- return this._scopeId;
971
- }
972
- get scopedSelector() {
973
- return `[${this.scopeId}]`;
968
+ return this.attribute("data-cotomy-scopeid");
974
969
  }
975
970
  get stylable() {
976
971
  return !["script", "style", "link", "meta"].includes(this.tagname);
@@ -983,7 +978,7 @@ class CotomyElement {
983
978
  const cssid = this.scopedCssElementId;
984
979
  CotomyElement.find(`#${cssid}`).forEach(e => e.remove());
985
980
  const element = document.createElement("style");
986
- const writeCss = css.replace(/\[scope\]/g, `[${this.scopeId}]`);
981
+ const writeCss = css.replace(/\[scope\]/g, `[data-cotomy-scopeid="${this.scopeId}"]`);
987
982
  const node = document.createTextNode(writeCss);
988
983
  element.appendChild(node);
989
984
  element.id = cssid;
@@ -1014,7 +1009,10 @@ class CotomyElement {
1014
1009
  }
1015
1010
  clone(type) {
1016
1011
  const ctor = (type ?? CotomyElement);
1017
- return new ctor(this.element.cloneNode(true));
1012
+ const cloned = new ctor(this.element.cloneNode(true));
1013
+ cloned.attribute("data-cotomy-scopeid", null);
1014
+ cloned.find("[data-cotomy-scopeid]").forEach(e => e.attribute("data-cotomy-scopeid", null));
1015
+ return cloned;
1018
1016
  }
1019
1017
  get tagname() {
1020
1018
  return this.element.tagName.toLowerCase();
@@ -1468,8 +1466,11 @@ class CotomyElement {
1468
1466
  return this;
1469
1467
  }
1470
1468
  on(event, handle, options) {
1471
- const entry = new HandlerEntry(handle, undefined, options);
1472
- EventRegistry.instance.on(event, this, entry);
1469
+ const events = Array.isArray(event) ? event : [event];
1470
+ events.forEach(eventName => {
1471
+ const entry = new HandlerEntry(handle, undefined, options);
1472
+ EventRegistry.instance.on(eventName, this, entry);
1473
+ });
1473
1474
  return this;
1474
1475
  }
1475
1476
  onSubTree(event, selector, handle, options) {
@@ -1479,25 +1480,34 @@ class CotomyElement {
1479
1480
  return handle(e);
1480
1481
  }
1481
1482
  };
1482
- const entry = new HandlerEntry(handle, delegate, options);
1483
- EventRegistry.instance.on(event, this, entry);
1483
+ const events = Array.isArray(event) ? event : [event];
1484
+ events.forEach(eventName => {
1485
+ const entry = new HandlerEntry(handle, delegate, options);
1486
+ EventRegistry.instance.on(eventName, this, entry);
1487
+ });
1484
1488
  return this;
1485
1489
  }
1486
1490
  once(event, handle, options) {
1487
1491
  const mergedOptions = { ...(options ?? {}), once: true };
1488
- const entry = new HandlerEntry(handle, undefined, mergedOptions);
1489
1492
  this.off(event, handle, mergedOptions);
1490
- EventRegistry.instance.on(event, this, entry);
1493
+ const events = Array.isArray(event) ? event : [event];
1494
+ events.forEach(eventName => {
1495
+ const entry = new HandlerEntry(handle, undefined, mergedOptions);
1496
+ EventRegistry.instance.on(eventName, this, entry);
1497
+ });
1491
1498
  return this;
1492
1499
  }
1493
1500
  off(event, handle, options) {
1494
- if (handle) {
1495
- const entry = new HandlerEntry(handle, undefined, options);
1496
- EventRegistry.instance.off(event, this, entry);
1497
- }
1498
- else {
1499
- EventRegistry.instance.off(event, this);
1500
- }
1501
+ const events = Array.isArray(event) ? event : [event];
1502
+ events.forEach(eventName => {
1503
+ if (handle) {
1504
+ const entry = new HandlerEntry(handle, undefined, options);
1505
+ EventRegistry.instance.off(eventName, this, entry);
1506
+ }
1507
+ else {
1508
+ EventRegistry.instance.off(eventName, this);
1509
+ }
1510
+ });
1501
1511
  return this;
1502
1512
  }
1503
1513
  click(handle) {
@@ -1902,22 +1912,34 @@ class CotomyWindow {
1902
1912
  window.dispatchEvent(e ?? new Event(event, { bubbles: true }));
1903
1913
  }
1904
1914
  on(event, handle) {
1905
- if (!this._eventHandlers[event])
1906
- this._eventHandlers[event] = [];
1907
- this._eventHandlers[event].push(handle);
1908
- window.addEventListener(event, handle);
1915
+ const events = Array.isArray(event) ? event : [event];
1916
+ events.forEach(eventName => {
1917
+ if (!this._eventHandlers[eventName])
1918
+ this._eventHandlers[eventName] = [];
1919
+ this._eventHandlers[eventName].push(handle);
1920
+ window.addEventListener(eventName, handle);
1921
+ });
1909
1922
  }
1910
1923
  off(event, handle) {
1911
- if (handle) {
1912
- window.removeEventListener(event, handle);
1913
- this._eventHandlers[event] = this._eventHandlers[event]?.filter(h => h !== handle) ?? [];
1914
- }
1915
- else {
1916
- for (const h of this._eventHandlers[event] ?? []) {
1917
- window.removeEventListener(event, h);
1924
+ const events = Array.isArray(event) ? event : [event];
1925
+ events.forEach(eventName => {
1926
+ if (handle) {
1927
+ window.removeEventListener(eventName, handle);
1928
+ const handlers = this._eventHandlers[eventName]?.filter(h => h !== handle) ?? [];
1929
+ if (handlers.length > 0) {
1930
+ this._eventHandlers[eventName] = handlers;
1931
+ }
1932
+ else {
1933
+ delete this._eventHandlers[eventName];
1934
+ }
1918
1935
  }
1919
- delete this._eventHandlers[event];
1920
- }
1936
+ else {
1937
+ for (const h of this._eventHandlers[eventName] ?? []) {
1938
+ window.removeEventListener(eventName, h);
1939
+ }
1940
+ delete this._eventHandlers[eventName];
1941
+ }
1942
+ });
1921
1943
  }
1922
1944
  load(handle) {
1923
1945
  this.on("load", handle);
@@ -2696,7 +2718,7 @@ class CotomyEntityApiForm extends CotomyApiForm {
2696
2718
  this.attribute("data-cotomy-entity-key", addedParts[0]);
2697
2719
  }
2698
2720
  else {
2699
- const msg = `Location does not contain a single entity key segment.
2721
+ const msg = `Location does not contain a single entity key segment.
2700
2722
  action="${baseAction}", location="${locPath}", added=["${addedParts.join('","')}"]`;
2701
2723
  throw new Error(msg);
2702
2724
  }
@@ -2786,8 +2808,8 @@ class CotomyEntityFillApiForm extends CotomyEntityApiForm {
2786
2808
  }
2787
2809
  }
2788
2810
  applyValueToInputs(pname, value) {
2789
- this.find(`input[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple]),
2790
- textarea[name="${pname}" i]:not([data-cotomy-fill="false"]),
2811
+ this.find(`input[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple]),
2812
+ textarea[name="${pname}" i]:not([data-cotomy-fill="false"]),
2791
2813
  select[name="${pname}" i]:not([data-cotomy-fill="false"]):not([multiple])`).forEach(input => {
2792
2814
  if (CotomyDebugSettings.isEnabled(CotomyDebugFeature.Fill)) {
2793
2815
  console.debug(`Filling input[name="${pname}"] with value:`, value);