data-tier
Advanced tools
Comparing version 3.6.1 to 3.6.3
@@ -7,3 +7,3 @@ import { DOMProcessor } from './dom-processor.js'; | ||
export const version = '3.6.1'; | ||
export const version = '3.6.3'; | ||
@@ -10,0 +10,0 @@ const initStartTime = performance.now(); |
@@ -1,1 +0,1 @@ | ||
import{DOMProcessor as s}from"./dom-processor.min.js";import{Ties as o}from"./ties.min.js";import{Views as r}from"./views.min.js";export{Observable}from"./ties.min.js";var e="3.6.1",i=performance.now();console.info("DT (3.6.1): starting initialization...");const t=new class{constructor(){this.params=Object.freeze(Array.from(new URL(import.meta.url).searchParams).reduce((s,o)=>(s[o[0]]=o[1],s),{})),this.paramsKey=Symbol("view.params.key"),this.domProcessor=new s(this),this.ties=new o(this),this.views=new r(this),"false"!==this.params.autostart&&!1!==this.params.autostart&&this.domProcessor.addDocument(document)}};var a=t.ties,m=t.domProcessor.addDocument.bind(t.domProcessor),n=t.domProcessor.removeDocument.bind(t.domProcessor);console.info(`DT (3.6.1): ... initialization DONE (took ${(performance.now()-i).toFixed(2)}ms)`);export{e as version,a as ties,m as addDocument,n as removeDocument}; | ||
import{DOMProcessor as o}from"./dom-processor.min.js";import{Ties as s}from"./ties.min.js";import{Views as e}from"./views.min.js";export{Observable}from"./ties.min.js";var r="3.6.3",i=performance.now();console.info("DT (3.6.3): starting initialization...");var t=new class{constructor(){this.params=Object.freeze(Array.from(new URL(import.meta.url).searchParams).reduce((o,s)=>(o[s[0]]=s[1],o),{})),this.paramsKey=Symbol("view.params.key"),this.domProcessor=new o(this),this.ties=new s(this),this.views=new e(this),"false"!==this.params.autostart&&!1!==this.params.autostart&&this.domProcessor.addDocument(document)}},m=t.ties,a=t.domProcessor.addDocument.bind(t.domProcessor),t=t.domProcessor.removeDocument.bind(t.domProcessor);console.info(`DT (3.6.3): ... initialization DONE (took ${(performance.now()-i).toFixed(2)}ms)`);export{r as version,m as ties,a as addDocument,t as removeDocument}; |
@@ -1,1 +0,1 @@ | ||
import{TARGET_TYPES as d,getPath as r,setPath as o,callViewMethod as h,extractViewParams as s}from"./utils.min.js";const t=Object.freeze({subtree:!0,childList:!0,attributes:!0,attributeFilter:["data-tie"],attributeOldValue:!0,characterData:!1,characterDataOldValue:!1}),a="addEventListener",i="removeEventListener";class e{constructor(e){this._dtInstance=e,this._roots=new WeakMap,this._elementsMap=new WeakSet,this._boundDOMChangesListener=this._domChangesListener.bind(this),this._boundChangeListener=this._changeListener.bind(this)}addDocument(n){if(!n||Node.DOCUMENT_NODE!==n.nodeType&&Node.DOCUMENT_FRAGMENT_NODE!==n.nodeType)throw new Error("invalid argument, must be one of: DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE");if(this._roots.has(n))return console.warn("any root document may be added only once"),!1;const e=new MutationObserver(this._boundDOMChangesListener);e.observe(n,t),this._roots.set(n,e);for(let e=0,t=n.children.length;e<t;e++)this._addTree(n.children[e]);return!0}removeDocument(n){if(!this._roots.has(n))return console.warn(`no root document ${n} known`),!1;this._roots.get(n).disconnect(),this._roots.delete(n);for(let e=0,t=n.children.length;e<t;e++)this._dropTree(n.children[e]);return!0}_domChangesListener(n){let s,c,a,i,r,d;for(let e=0,t=n.length;e<t;e++)if("childList"===(c=(s=n[e]).type)){for(a=s.addedNodes,i=0,r=a.length;i<r;i++)(d=a[i]).nodeType===Node.ELEMENT_NODE&&this._addTree(d);for(a=s.removedNodes,i=0,r=a.length;i<r;i++)(d=a[i]).nodeType===Node.ELEMENT_NODE&&this._dropTree(d)}else if("attributes"===c){const o=s.attributeName,h=s.target,l=s.oldValue,_=h.getAttribute(o);"data-tie"===o&&l!==_&&this._onTieParamChange(h,_,l)}}_onTieParamChange(e,t,n){!n||(n=e[this._dtInstance.paramsKey])&&(this._dtInstance.views.delView(e,n),this._handleChangeListener(e,i,n)),!t||(n=s(e))&&(this._dtInstance.views.addView(e,n),this._updateFromView(e,n),this._handleChangeListener(e,a,n))}_addTree(e){if(this._addOne(e),e.childElementCount){var t;const n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT);for(;t=n.nextNode();)this._addOne(t)}}_dropTree(e){if(this._dropOne(e),e.childElementCount){var t;const n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT);for(;t=n.nextNode();)this._dropOne(t)}}_addOne(e){var t;this._elementsMap.has(e)||(this._elementsMap.add(e),0<e.nodeName.indexOf("-")&&!e.matches(":defined")?this._waitDefined(e):((t=s(e))&&(this._dtInstance.views.addView(e,t),this._updateFromView(e,t),this._handleChangeListener(e,a,t)),e.shadowRoot&&this.addDocument(e.shadowRoot)))}_waitDefined(e){customElements.whenDefined(e.nodeName.toLowerCase()).then(()=>{this._elementsMap.delete(e),this._addOne(e)})}_dropOne(e){var t;this._elementsMap.has(e)&&(this._elementsMap.delete(e),(t=e[this._dtInstance.paramsKey])&&(this._dtInstance.views.delView(e,t),this._handleChangeListener(e,i,t)),e.shadowRoot&&this.removeDocument(e.shadowRoot))}_changeListener(e){const a=e.type,i=e.currentTarget,r=i[this._dtInstance.paramsKey];if(r){let e,t,n,s=r.length;for(;s--;)(e=r[s]).changeEvent===a&&(t=this._dtInstance.ties.get(e.tieKey))&&(n=e.targetType===d.ATTRIBUTE?i.getAttribute(e.targetKey):i[e.targetKey],o(t,e.path,n))}}_handleChangeListener(n,s,a){var i;for(let e=0,t=a.length;e<t;e++)(i=a[e].changeEvent)&&n[s](i,this._boundChangeListener)}_updateFromView(e,t){let n=t.length;for(;n--;){const a=t[n];if(a.targetType===d.METHOD){let s=!1;const i=[];a.fParams.forEach(e=>{let t;var n=this._dtInstance.ties.get(e.tieKey);n&&(t=r(n,e.path),s=!0),i.push(t)}),s&&(i.push(null),h(e,a.targetKey,i))}else{var s=this._dtInstance.ties.get(a.tieKey);void 0!==s&&(s=r(s,a.path),this._dtInstance.views.updateViewByModel(e,a,s))}}}}export{e as DOMProcessor}; | ||
import{TARGET_TYPES as d,getPath as r,setPath as o,callViewMethod as h,extractViewParams as a}from"./utils.min.js";const t=Object.freeze({subtree:!0,childList:!0,attributes:!0,attributeFilter:["data-tie"],attributeOldValue:!0,characterData:!1,characterDataOldValue:!1}),s="addEventListener",i="removeEventListener";class e{constructor(e){this._dtInstance=e,this._roots=new WeakMap,this._elementsMap=new WeakSet,this._boundDOMChangesListener=this._domChangesListener.bind(this),this._boundChangeListener=this._changeListener.bind(this)}addDocument(n){if(!n||Node.DOCUMENT_NODE!==n.nodeType&&Node.DOCUMENT_FRAGMENT_NODE!==n.nodeType)throw new Error("invalid argument, must be one of: DOCUMENT_NODE, DOCUMENT_FRAGMENT_NODE");if(this._roots.has(n))return console.warn("any root document may be added only once"),!1;var e=new MutationObserver(this._boundDOMChangesListener);e.observe(n,t),this._roots.set(n,e);for(let e=0,t=n.children.length;e<t;e++)this._addTree(n.children[e]);return!0}removeDocument(n){if(!this._roots.has(n))return console.warn(`no root document ${n} known`),!1;this._roots.get(n).disconnect(),this._roots.delete(n);for(let e=0,t=n.children.length;e<t;e++)this._dropTree(n.children[e]);return!0}_domChangesListener(n){let a,s,i,r,d,o;for(let e=0,t=n.length;e<t;e++)if("childList"===(s=(a=n[e]).type)){for(i=a.addedNodes,r=0,d=i.length;r<d;r++)(o=i[r]).nodeType===Node.ELEMENT_NODE&&this._addTree(o);for(i=a.removedNodes,r=0,d=i.length;r<d;r++)(o=i[r]).nodeType===Node.ELEMENT_NODE&&this._dropTree(o)}else{var h,l,_,c;"attributes"===s&&(h=a.attributeName,l=a.target,_=a.oldValue,c=l.getAttribute(h),"data-tie"===h)&&_!==c&&this._onTieParamChange(l,c,_)}}_onTieParamChange(e,t,n){n&&(n=e[this._dtInstance.paramsKey])&&(this._dtInstance.views.delView(e,n),this._handleChangeListener(e,i,n)),t&&(n=a(e))&&(this._dtInstance.views.addView(e,n),this._updateFromView(e,n),this._handleChangeListener(e,s,n))}_addTree(e){if(this._addOne(e),e.childElementCount)for(var t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT);t=n.nextNode();)this._addOne(t)}_dropTree(e){if(this._dropOne(e),e.childElementCount)for(var t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT);t=n.nextNode();)this._dropOne(t)}_addOne(e){var t;this._elementsMap.has(e)||(this._elementsMap.add(e),0<e.nodeName.indexOf("-")&&!e.matches(":defined")?this._waitDefined(e):((t=a(e))&&(this._dtInstance.views.addView(e,t),this._updateFromView(e,t),this._handleChangeListener(e,s,t)),e.shadowRoot&&this.addDocument(e.shadowRoot)))}_waitDefined(e){customElements.whenDefined(e.nodeName.toLowerCase()).then(()=>{this._elementsMap.delete(e),this._addOne(e)})}_dropOne(e){var t;this._elementsMap.has(e)&&(this._elementsMap.delete(e),(t=e[this._dtInstance.paramsKey])&&(this._dtInstance.views.delView(e,t),this._handleChangeListener(e,i,t)),e.shadowRoot)&&this.removeDocument(e.shadowRoot)}_changeListener(e){var s=e.type,i=e.currentTarget,r=i[this._dtInstance.paramsKey];if(r){let e,t,n,a=r.length;for(;a--;)(e=r[a]).changeEvent===s&&(t=this._dtInstance.ties.get(e.tieKey))&&(n=e.targetType===d.ATTRIBUTE?i.getAttribute(e.targetKey):i[e.targetKey],o(t,e.path,n))}}_handleChangeListener(n,a,s){var i;for(let e=0,t=s.length;e<t;e++)(i=s[e].changeEvent)&&n[a](i,this._boundChangeListener)}_updateFromView(e,t){let n=t.length;for(;n--;){var s=t[n];if(s.targetType===d.METHOD){let a=!1;const i=[];s.fParams.forEach(e=>{let t;var n=this._dtInstance.ties.get(e.tieKey);n&&(t=r(n,e.path),a=!0),i.push(t)}),a&&(i.push(null),h(e,s.targetKey,i))}else{var a=this._dtInstance.ties.get(s.tieKey);void 0!==a&&(a=r(a,s.path),this._dtInstance.views.updateViewByModel(e,s,a))}}}}export{e as DOMProcessor}; |
@@ -1,1 +0,2 @@ | ||
function t(){const t=this[d],e=t.target;let o,r,n;for(e.reverse(),o=0,r=e.length;o<r;o++)if((n=e[o])&&"object"==typeof n){const i=n[d];i&&(i.ownKey=o)}var s=[new O(h,[],void 0,void 0,this)];return j(t,s),this}function e(t){const e=this[d],o=e.target;let r,n,s;for(o.sort(t),r=0,n=o.length;r<n;r++)if((s=o[r])&&"object"==typeof s){const i=s[d];i&&(i.ownKey=r)}return t=[new O(a,[],void 0,void 0,this)],j(e,t),this}function s(t,n,s){const i=this[d],h=i.target,a=[],e=h.length,l=h.slice(0);if(n=void 0===n?0:n<0?Math.max(e+n,0):Math.min(n,e),s=void 0===s?e:s<0?Math.max(e+s,0):Math.min(s,e),n<e&&n<s){h.fill(t,n,s);let r;for(let t=n,e,o;t<s;t++)e=h[t],h[t]=m(e,t,i),t in l?((o=l[t])&&"object"==typeof o&&(r=o[d])&&(o=r.detach()),a.push(new O(v,[t],h[t],o,this))):a.push(new O(w,[t],h[t],void 0,this));j(i,a)}return this}function i(n,t,e){const s=this[d],i=s.target,o=i.length;n=n<0?Math.max(o+n,0):n,t=void 0===t?0:t<0?Math.max(o+t,0):Math.min(t,o),e=void 0===e?o:e<0?Math.max(o+e,0):Math.min(e,o);var h=Math.min(e-t,o-n);if(n<o&&n!==t&&0<h){const a=i.slice(0),l=[];i.copyWithin(n,t,e);for(let t=n,e,o,r;t<n+h;t++)(e=i[t])&&"object"==typeof e&&(e=m(e,t,s),i[t]=e),(o=a[t])&&"object"==typeof o&&(r=o[d])&&(o=r.detach()),"object"!=typeof e&&e===o||l.push(new O(v,[t],e,o,this));j(s,l)}return this}const w="insert",v="update",g="delete",h="reverse",a="shuffle",d=Symbol.for("object-observer-meta-key-0"),l={async:1},f=(t,e)=>{const o={};o[d]=e;for(const r in t)o[r]=m(t[r],r,e);return o},p=(e,o)=>{var r=e.length;const n=new Array(r);n[d]=o;for(let t=0;t<r;t++)n[t]=m(e[t],t,o);return n},c=(t,e)=>(t[d]=e,t),b=(t,e)=>{if(null===t)return e;let o=e;if(t.path){const r=t.path;o=e.filter(t=>t.path.join(".")===r)}else if(t.pathsOf){const n=t.pathsOf,s=n.join(".");o=e.filter(t=>(t.path.length===n.length+1||t.path.length===n.length&&(t.type===h||t.type===a))&&t.path.join(".").startsWith(s))}else if(t.pathsFrom){const i=t.pathsFrom;o=e.filter(t=>t.path.join(".").startsWith(i))}return o},y=(e,o)=>{try{e(o)}catch(t){console.error(`failed to notify listener ${e} with `+o,t)}},u=function(){var t,e,o=this.batches;this.batches=[];for([t,e]of o)y(t,e)},j=(f,e)=>{let o=f,t,r,n,s,i,h;var p=e.length;do{for(t=o.options.async,r=o.observers,h=r.length;h--;)if([n,s]=r[h],(i=b(s,e)).length)if(t){0===o.batches.length&&queueMicrotask(u.bind(o));let t;for(const l of o.batches)if(l[0]===n){t=l;break}t||(t=[n,[]],o.batches.push(t)),Array.prototype.push.apply(t[1],i)}else y(n,i);var c=o.parent;if(c){for(let t=0;t<p;t++){var a=e[t];e[t]=new O(a.type,[o.ownKey,...a.path],a.value,a.oldValue,a.object)}o=c}else o=null}while(o)},m=(t,e,o)=>"object"!=typeof t||null===t?t:Array.isArray(t)?new E({target:t,ownKey:e,parent:o}).proxy:ArrayBuffer.isView(t)?new S({target:t,ownKey:e,parent:o}).proxy:t instanceof Date?t:new K({target:t,ownKey:e,parent:o}).proxy,x={pop:function(){const t=this[d],e=t.target,o=e.length-1;let r=e.pop();if(r&&"object"==typeof r){const s=r[d];s&&(r=s.detach())}var n=[new O(g,[o],void 0,r,this)];return j(t,n),r},push:function(){const e=this[d],o=e.target,r=arguments.length,n=new Array(r),s=o.length;for(let t=0;t<r;t++)n[t]=m(arguments[t],s+t,e);var t=Reflect.apply(o.push,o,n);const i=[];for(let t=s,e=o.length;t<e;t++)i[t-s]=new O(w,[t],o[t],void 0,this);return j(e,i),t},shift:function(){const t=this[d],e=t.target;let o,r,n,s,i;for((o=e.shift())&&"object"==typeof o&&(i=o[d])&&(o=i.detach()),r=0,n=e.length;r<n;r++)(s=e[r])&&"object"==typeof s&&(i=s[d])&&(i.ownKey=r);var h=[new O(g,[0],void 0,o,this)];return j(t,h),o},unshift:function(){const e=this[d],r=e.target,o=arguments.length,n=new Array(o);for(let t=0;t<o;t++)n[t]=m(arguments[t],t,e);var t=Reflect.apply(r.unshift,r,n);for(let t=0,e=r.length,o;t<e;t++)if((o=r[t])&&"object"==typeof o){const h=o[d];h&&(h.ownKey=t)}var s=n.length;const i=new Array(s);for(let t=0;t<s;t++)i[t]=new O(w,[t],r[t],void 0,this);return j(e,i),t},reverse:t,sort:e,fill:s,copyWithin:i,splice:function(){const e=this[d],o=e.target,r=arguments.length,n=new Array(r),f=o.length;for(let t=0;t<r;t++)n[t]=m(arguments[t],t,e);const t=0===r?0:n[0]<0?f+n[0]:n[0],p=r<2?f-t:n[1],c=Math.max(r-2,0),s=Reflect.apply(o.splice,o,n),b=o.length;let i;for(let t=0,e;t<b;t++)(e=o[t])&&"object"==typeof e&&(i=e[d])&&(i.ownKey=t);let h,y,u;for(h=0,y=s.length;h<y;h++)(u=s[h])&&"object"==typeof u&&(i=u[d])&&(s[h]=i.detach());const a=[];let l;for(l=0;l<p;l++)l<c?a.push(new O(v,[t+l],o[t+l],s[l],this)):a.push(new O(g,[t+l],void 0,s[l],this));for(;l<c;l++)a.push(new O(w,[t+l],o[t+l],void 0,this));return j(e,a),s}},M={reverse:t,sort:e,fill:s,copyWithin:i,set:function(t,e){const o=this[d],r=o.target,n=t.length,s=r.slice(0),i=(e=e||0,r.set(t,e),new Array(n));for(let t=e;t<n+e;t++)i[t-e]=new O(v,[t],r[t],s[t],this);j(o,i)}};class O{constructor(t,e,o,r,n){this.type=t,this.path=e,this.value=o,this.oldValue=r,this.object=n}}class A{constructor(t,e){var{target:o,parent:r,ownKey:n}=t,r=(r&&void 0!==n?(this.parent=r,this.ownKey=n):(this.parent=null,this.ownKey=null),e(o,this));this.observers=[],this.revocable=Proxy.revocable(r,this),this.proxy=this.revocable.proxy,this.target=r,this.options=this.processOptions(t.options),this.options.async&&(this.batches=[])}processOptions(t){if(t){if("object"!=typeof t)throw new Error(`Observable options if/when provided, MAY only be an object, got '${t}'`);const e=Object.keys(t).filter(t=>!(t in l));if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid Observable option/s`);return Object.assign({},t)}return{}}detach(){return this.parent=null,this.target}set(t,e,o){let r=t[e];if(o!==r){o=m(o,e,this);if(t[e]=o,r&&"object"==typeof r){const n=r[d];n&&(r=n.detach())}t=void 0===r?[new O(w,[e],o,void 0,this.proxy)]:[new O(v,[e],o,r,this.proxy)];j(this,t)}return!0}deleteProperty(t,e){let o=t[e];if(delete t[e],o&&"object"==typeof o){const r=o[d];r&&(o=r.detach())}t=[new O(g,[e],void 0,o,this.proxy)];return j(this,t),!0}}class K extends A{constructor(t){super(t,f)}}class E extends A{constructor(t){super(t,p)}get(t,e){return x[e]||t[e]}}class S extends A{constructor(t){super(t,c)}get(t,e){return M[e]||t[e]}}const n=Object.freeze({from:(t,e)=>{if(t&&"object"==typeof t){if(t[d])return t;if(Array.isArray(t))return new E({target:t,ownKey:null,parent:null,options:e}).proxy;if(ArrayBuffer.isView(t))return new S({target:t,ownKey:null,parent:null,options:e}).proxy;if(t instanceof Date)throw new Error(t+" found to be one of a non-observable types");return new K({target:t,ownKey:null,parent:null,options:e}).proxy}throw new Error("observable MAY ONLY be created from a non-null object")},isObservable:t=>!(!t||!t[d]),observe:(t,e,o)=>{if(!n.isObservable(t))throw new Error("invalid observable parameter");if("function"!=typeof e)throw new Error(`observer MUST be a function, got '${e}'`);const r=t[d].observers;r.some(t=>t[0]===e)?console.warn("observer may be bound to an observable only once; will NOT rebind"):r.push([e,(t=>{if(!t||"object"!=typeof t)return null;const e={},o=[];for(var[r,n]of Object.entries(t))if("path"===r){if("string"!=typeof n||""===n)throw new Error('"path" option, if/when provided, MUST be a non-empty string');e[r]=n}else if("pathsOf"===r){if(t.path)throw new Error('"pathsOf" option MAY NOT be specified together with "path" option');if("string"!=typeof n)throw new Error('"pathsOf" option, if/when provided, MUST be a string (MAY be empty)');e[r]=t.pathsOf.split(".").filter(Boolean)}else if("pathsFrom"===r){if(t.path||t.pathsOf)throw new Error('"pathsFrom" option MAY NOT be specified together with "path"/"pathsOf" option/s');if("string"!=typeof n||""===n)throw new Error('"pathsFrom" option, if/when provided, MUST be a non-empty string');e[r]=n}else o.push(r);if(o.length)throw new Error(`'${o.join(", ")}' is/are not a valid observer option/s`);return e})(o)])},unobserve:(t,...e)=>{if(!n.isObservable(t))throw new Error("invalid observable parameter");const o=t[d].observers;let r=o.length;if(r)if(e.length)for(;r;)0<=e.indexOf(o[--r][0])&&o.splice(r,1);else o.splice(0)}}),o=Symbol("observer-key"),r=Symbol("targets-key");class T{constructor(t){this[o]=t,this[r]=new Set,Object.freeze(this)}observe(t,e){t=n.from(t);return n.observe(t,this[o],e),this[r].add(t),t}unobserve(t){n.unobserve(t,this[o]),this[r].delete(t)}disconnect(){for(const t of this[r])n.unobserve(t,this[o]);this[r].clear()}}export{n as Observable,T as ObjectObserver}; | ||
export{v as Observable,te as ObjectObserver};const m="insert",x="update",S="delete",R="reverse",F="shuffle",c=Symbol.for("object-observer-meta-key-0"),Y={async:1},I=o=>{if(!o||typeof o!="object")return null;const t={},e=[];for(const[r,n]of Object.entries(o))if(r==="path"){if(typeof n!="string"||n==="")throw new Error('"path" option, if/when provided, MUST be a non-empty string');t[r]=n}else if(r==="pathsOf"){if(o.path)throw new Error('"pathsOf" option MAY NOT be specified together with "path" option');if(typeof n!="string")throw new Error('"pathsOf" option, if/when provided, MUST be a string (MAY be empty)');t[r]=o.pathsOf.split(".").filter(Boolean)}else if(r==="pathsFrom"){if(o.path||o.pathsOf)throw new Error('"pathsFrom" option MAY NOT be specified together with "path"/"pathsOf" option/s');if(typeof n!="string"||n==="")throw new Error('"pathsFrom" option, if/when provided, MUST be a non-empty string');t[r]=n}else e.push(r);if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid observer option/s`);return t},B=(o,t,e)=>{const r={};r[c]=t;for(const n in o)r[n]=g(o[n],n,t,e);return r},D=(o,t,e)=>{let r=o.length;const n=new Array(r);n[c]=t;for(let i=0;i<r;i++)n[i]=g(o[i],i,t,e);return n},z=(o,t)=>(o[c]=t,o),q=(o,t)=>{if(o===null)return t;let e=t;if(o.path){const r=o.path;e=t.filter(n=>n.path.join(".")===r)}else if(o.pathsOf){const r=o.pathsOf,n=r.join(".");e=t.filter(i=>(i.path.length===r.length+1||i.path.length===r.length&&(i.type===R||i.type===F))&&i.path.join(".").startsWith(n))}else if(o.pathsFrom){const r=o.pathsFrom;e=t.filter(n=>n.path.join(".").startsWith(r))}return e},P=(o,t)=>{try{o(t)}catch(e){console.error(`failed to notify listener ${o} with ${t}`,e)}},H=function(){const t=this.batches;this.batches=[];for(const[e,r]of t)P(e,r)},y=(o,t)=>{let e=o,r,n,i,l,h,s;const u=t.length;do{for(r=e.options.async,n=e.observers,s=n.length;s--;)if([i,l]=n[s],h=q(l,t),h.length)if(r){e.batches.length===0&&queueMicrotask(H.bind(e));let a;for(const p of e.batches)if(p[0]===i){a=p;break}a||(a=[i,[]],e.batches.push(a)),Array.prototype.push.apply(a[1],h)}else P(i,h);const f=e.parent;if(f){for(let a=0;a<u;a++){const p=t[a];t[a]=new b(p.type,[e.ownKey,...p.path],p.value,p.oldValue,p.object)}e=f}else e=null}while(e)},g=(o,t,e,r)=>r!==void 0&&r.has(o)?null:typeof o!="object"||o===null?o:Array.isArray(o)?new $({target:o,ownKey:t,parent:e,visited:r}).proxy:ArrayBuffer.isView(o)?new N({target:o,ownKey:t,parent:e}).proxy:o instanceof Date?o:new W({target:o,ownKey:t,parent:e,visited:r}).proxy,G=function(){const t=this[c],e=t.target,r=e.length-1;let n=e.pop();if(n&&typeof n=="object"){const l=n[c];l&&(n=l.detach())}const i=[new b(S,[r],void 0,n,this)];return y(t,i),n},J=function(){const t=this[c],e=t.target,r=arguments.length,n=new Array(r),i=e.length;for(let s=0;s<r;s++)n[s]=g(arguments[s],i+s,t);const l=Reflect.apply(e.push,e,n),h=[];for(let s=i,u=e.length;s<u;s++)h[s-i]=new b(m,[s],e[s],void 0,this);return y(t,h),l},Q=function(){const t=this[c],e=t.target;let r,n,i,l,h;for(r=e.shift(),r&&typeof r=="object"&&(h=r[c],h&&(r=h.detach())),n=0,i=e.length;n<i;n++)l=e[n],l&&typeof l=="object"&&(h=l[c],h&&(h.ownKey=n));const s=[new b(S,[0],void 0,r,this)];return y(t,s),r},X=function(){const t=this[c],e=t.target,r=arguments.length,n=new Array(r);for(let s=0;s<r;s++)n[s]=g(arguments[s],s,t);const i=Reflect.apply(e.unshift,e,n);for(let s=0,u=e.length,f;s<u;s++)if(f=e[s],f&&typeof f=="object"){const a=f[c];a&&(a.ownKey=s)}const l=n.length,h=new Array(l);for(let s=0;s<l;s++)h[s]=new b(m,[s],e[s],void 0,this);return y(t,h),i},L=function(){const t=this[c],e=t.target;let r,n,i;for(e.reverse(),r=0,n=e.length;r<n;r++)if(i=e[r],i&&typeof i=="object"){const h=i[c];h&&(h.ownKey=r)}const l=[new b(R,[],void 0,void 0,this)];return y(t,l),this},C=function(t){const e=this[c],r=e.target;let n,i,l;for(r.sort(t),n=0,i=r.length;n<i;n++)if(l=r[n],l&&typeof l=="object"){const s=l[c];s&&(s.ownKey=n)}const h=[new b(F,[],void 0,void 0,this)];return y(e,h),this},V=function(t,e,r){const n=this[c],i=n.target,l=[],h=i.length,s=i.slice(0);if(e=e===void 0?0:e<0?Math.max(h+e,0):Math.min(e,h),r=r===void 0?h:r<0?Math.max(h+r,0):Math.min(r,h),e<h&&r>e){i.fill(t,e,r);let u;for(let f=e,a,p;f<r;f++)a=i[f],i[f]=g(a,f,n),f in s?(p=s[f],p&&typeof p=="object"&&(u=p[c],u&&(p=u.detach())),l.push(new b(x,[f],i[f],p,this))):l.push(new b(m,[f],i[f],void 0,this));y(n,l)}return this},U=function(t,e,r){const n=this[c],i=n.target,l=i.length;t=t<0?Math.max(l+t,0):t,e=e===void 0?0:e<0?Math.max(l+e,0):Math.min(e,l),r=r===void 0?l:r<0?Math.max(l+r,0):Math.min(r,l);const h=Math.min(r-e,l-t);if(t<l&&t!==e&&h>0){const s=i.slice(0),u=[];i.copyWithin(t,e,r);for(let f=t,a,p,O;f<t+h;f++)a=i[f],a&&typeof a=="object"&&(a=g(a,f,n),i[f]=a),p=s[f],p&&typeof p=="object"&&(O=p[c],O&&(p=O.detach())),!(typeof a!="object"&&a===p)&&u.push(new b(x,[f],a,p,this));y(n,u)}return this},Z=function(){const t=this[c],e=t.target,r=arguments.length,n=new Array(r),i=e.length;for(let w=0;w<r;w++)n[w]=g(arguments[w],w,t);const l=r===0?0:n[0]<0?i+n[0]:n[0],h=r<2?i-l:n[1],s=Math.max(r-2,0),u=Reflect.apply(e.splice,e,n),f=e.length;let a;for(let w=0,E;w<f;w++)E=e[w],E&&typeof E=="object"&&(a=E[c],a&&(a.ownKey=w));let p,O,M;for(p=0,O=u.length;p<O;p++)M=u[p],M&&typeof M=="object"&&(a=M[c],a&&(u[p]=a.detach()));const A=[];let d;for(d=0;d<h;d++)d<s?A.push(new b(x,[l+d],e[l+d],u[d],this)):A.push(new b(S,[l+d],void 0,u[d],this));for(;d<s;d++)A.push(new b(m,[l+d],e[l+d],void 0,this));return y(t,A),u},_=function(t,e){const r=this[c],n=r.target,i=t.length,l=n.slice(0);e=e||0,n.set(t,e);const h=new Array(i);for(let s=e;s<i+e;s++)h[s-e]=new b(x,[s],n[s],l[s],this);y(r,h)},k={pop:G,push:J,shift:Q,unshift:X,reverse:L,sort:C,fill:V,copyWithin:U,splice:Z},ee={reverse:L,sort:C,fill:V,copyWithin:U,set:_};class b{constructor(t,e,r,n,i){this.type=t,this.path=e,this.value=r,this.oldValue=n,this.object=i}}class T{constructor(t,e){const{target:r,parent:n,ownKey:i,visited:l=new Set}=t;n&&i!==void 0?(this.parent=n,this.ownKey=i):(this.parent=null,this.ownKey=null),l.add(r);const h=e(r,this,l);l.delete(r),this.observers=[],this.revocable=Proxy.revocable(h,this),this.proxy=this.revocable.proxy,this.target=h,this.options=this.processOptions(t.options),this.options.async&&(this.batches=[])}processOptions(t){if(t){if(typeof t!="object")throw new Error(`Observable options if/when provided, MAY only be an object, got '${t}'`);const e=Object.keys(t).filter(r=>!(r in Y));if(e.length)throw new Error(`'${e.join(", ")}' is/are not a valid Observable option/s`);return Object.assign({},t)}else return{}}detach(){return this.parent=null,this.target}set(t,e,r){let n=t[e];if(r!==n){const i=g(r,e,this);if(t[e]=i,n&&typeof n=="object"){const h=n[c];h&&(n=h.detach())}const l=n===void 0?[new b(m,[e],i,void 0,this.proxy)]:[new b(x,[e],i,n,this.proxy)];y(this,l)}return!0}deleteProperty(t,e){let r=t[e];if(delete t[e],r&&typeof r=="object"){const i=r[c];i&&(r=i.detach())}const n=[new b(S,[e],void 0,r,this.proxy)];return y(this,n),!0}}class W extends T{constructor(t){super(t,B)}}class $ extends T{constructor(t){super(t,D)}get(t,e){return k[e]||t[e]}}class N extends T{constructor(t){super(t,z)}get(t,e){return ee[e]||t[e]}}const v=Object.freeze({from:(o,t)=>{if(!o||typeof o!="object")throw new Error("observable MAY ONLY be created from a non-null object");if(o[c])return o;if(Array.isArray(o))return new $({target:o,ownKey:null,parent:null,options:t}).proxy;if(ArrayBuffer.isView(o))return new N({target:o,ownKey:null,parent:null,options:t}).proxy;if(o instanceof Date)throw new Error(`${o} found to be one of a non-observable types`);return new W({target:o,ownKey:null,parent:null,options:t}).proxy},isObservable:o=>!!(o&&o[c]),observe:(o,t,e)=>{if(!v.isObservable(o))throw new Error("invalid observable parameter");if(typeof t!="function")throw new Error(`observer MUST be a function, got '${t}'`);const r=o[c].observers;r.some(n=>n[0]===t)?console.warn("observer may be bound to an observable only once; will NOT rebind"):r.push([t,I(e)])},unobserve:(o,...t)=>{if(!v.isObservable(o))throw new Error("invalid observable parameter");const e=o[c].observers;let r=e.length;if(r){if(!t.length){e.splice(0);return}for(;r;)t.indexOf(e[--r][0])>=0&&e.splice(r,1)}}}),K=Symbol("observer-key"),j=Symbol("targets-key");class te{constructor(t){this[K]=t,this[j]=new Set,Object.freeze(this)}observe(t,e){const r=v.from(t);return v.observe(r,this[K],e),this[j].add(r),r}unobserve(t){v.unobserve(t,this[K]),this[j].delete(t)}disconnect(){for(const t of this[j])v.unobserve(t,this[K]);this[j].clear()}} | ||
//# sourceMappingURL=object-observer.min.js.map |
@@ -1,1 +0,1 @@ | ||
import{Observable as i}from"./object-observer.min.js";import{TARGET_TYPES as l,getPath as n,callViewMethod as d,getRandomKey as o}from"./utils.min.js";const t=/^[a-zA-Z0-9]+$/,s=["scope"];class r{constructor(e,t,i){this.key=e,this.ties=i,this.model=t}set model(e){[e={}]=[e];var[e,t]=i.isObservable(e)?[e,!0]:e&&"object"==typeof e?[i.from(e),!0]:[e,!1];this._model=e,t&&i.observe(this._model,e=>this.processDataChanges(e))}get model(){return this._model}processDataChanges(u){var v=this.ties._dti.views.obtainTieViews(this.key),w=v._pathsCache,b=w.length;if(b){let i,c,s,o,r="",a,h,l,n,f,d,p,y,g,m;for(let e=0,t=u.length;e<t;e++)if(i=u[e],o=(s=i.path).length,!s.some(e=>"symbol"==typeof e))for(y=!1,c=i.object,!Array.isArray(c)||"insert"!==i.type&&"delete"!==i.type||isNaN(s[s.length-1])?1===o?r=s[0]:o&&(r=2===o?s[0]+"."+s[1]:s.join(".")):(r=s.slice(0,-1).join("."),y=!0),f=r.length,a=b;a--;)if(h=w[a],p=f>h.length?(d=h,r):(d=r,h),g=d===p&&!y,0===p.indexOf(d))for(l=v[h],n=l.length;n--;)m=l[n],this.updateView(m,h,g,i)}}updateView(t,i,s,o){var e=t[this.ties._dti.paramsKey];let r=e.length;for(;r--;){const a=e[r];if(a.targetType===l.METHOD){if(a.fParams.some(e=>e.tieKey===this.key&&e.rawPath===i)){let s=!1;const h=[];a.fParams.forEach(e=>{let t;var i=this.ties.get(e.tieKey);i&&(t=n(i,e.path),s=!0),h.push(t)}),s&&(h.push([o]),d(t,a.targetKey,h))}}else if(a.tieKey===this.key&&a.rawPath===i){let e;e=void 0!==o.value&&s?o.value:n(this._model,a.path),this.ties._dti.views.updateViewByModel(t,a,e,o.oldValue)}}}}class a{constructor(e){this._dti=e,this._ties={}}get(e){e="string"==typeof e?e:e&&e.getAttribute?e.getAttribute("data-tie-scope"):null,e=this._ties[e];return e?e.model:void 0}create(e,t){let i;if("string"==typeof e?i=e:e&&e.nodeType===Node.ELEMENT_NODE&&((i=e.getAttribute("data-tie-scope"))?console.log("inspect this"):(i=o(16),e.setAttribute("data-tie-scope",i))),a.validateTieKey(i),this._ties[i])throw new Error(`tie '${i}' already exists`);e.nodeType&&this._dti.views.addScope(e);const s=new r(i,t,this);return(this._ties[i]=s).processDataChanges([{path:[]}]),s.model}update(e,t){if(void 0===t)throw new Error(`illegal model '${t}'`);var i="string"==typeof e?e:e&&e.getAttribute?e.getAttribute("data-tie-scope"):null;const s=this._ties[i];return s?(s.model!==t&&(s.model=t,s.processDataChanges([{path:[]}])),s.model):this.create(e,t)}remove(t){let e=t;if("object"==typeof t)e=t.nodeType===Node.ELEMENT_NODE?t.getAttribute("data-tie-scope"):Object.keys(this._ties).find(e=>this._ties[e].model===t);else if("string"!=typeof t)throw new Error("invalid tieToRemove parameter "+t);this._ties[e]&&(delete this._ties[e],this._dti.views.deleteTieViews(e))}static validateTieKey(e){if(!e||"string"!=typeof e)throw new Error(`invalid key '${e}'`);if(!t.test(e))throw new Error(`tie key MUST match ${t}; '${e}' doesn't`);if(0<=s.indexOf(e))throw new Error("tie key MUST NOT be one of those: "+s.join(", "))}}export{i as Observable,a as Ties}; | ||
import{Observable as i}from"./object-observer.min.js";import{TARGET_TYPES as l,getPath as n,callViewMethod as d,getRandomKey as s}from"./utils.min.js";const t=/^[a-zA-Z0-9]+$/,o=["scope"];class r{constructor(e,t,i){this.key=e,this.ties=i,this.model=t}set model(e){var[e,t]=h(e);this._model=e,t&&i.observe(this._model,e=>this.processDataChanges(e))}get model(){return this._model}processDataChanges(u){var v=this.ties._dti.views.obtainTieViews(this.key),w=v._pathsCache,b=w.length;if(b){let i,s,o,r,a="",h,l,n,d,p,f,c,y,g,m;for(let e=0,t=u.length;e<t;e++)if(i=u[e],r=(o=i.path).length,!o.some(e=>"symbol"==typeof e))for(y=!1,s=i.object,!Array.isArray(s)||"insert"!==i.type&&"delete"!==i.type||isNaN(o[o.length-1])?1===r?a=o[0]:r&&(a=2===r?o[0]+"."+o[1]:o.join(".")):(a=o.slice(0,-1).join("."),y=!0),p=a.length,h=b;h--;)if(l=w[h],c=p>l.length?(f=l,a):(f=a,l),g=f===c&&!y,0===c.indexOf(f))for(n=v[l],d=n.length;d--;)m=n[d],this.updateView(m,l,g,i)}}updateView(t,i,s,o){var e=t[this.ties._dti.paramsKey];let r=e.length;for(;r--;){var a=e[r];if(a.targetType===l.METHOD){if(a.fParams.some(e=>e.tieKey===this.key&&e.rawPath===i)){let s=!1;const h=[];a.fParams.forEach(e=>{let t;var i=this.ties.get(e.tieKey);i&&(t=n(i,e.path),s=!0),h.push(t)}),s&&(h.push([o]),d(t,a.targetKey,h))}}else if(a.tieKey===this.key&&a.rawPath===i){let e;e=void 0!==o.value&&s?o.value:n(this._model,a.path),this.ties._dti.views.updateViewByModel(t,a,e,o.oldValue)}}}}class a{constructor(e){this._dti=e,this._ties={}}get(e){e="string"==typeof e?e:e&&e.getAttribute?e.getAttribute("data-tie-scope"):null,e=this._ties[e];return e?e.model:void 0}create(e,t){let i;if("string"==typeof e?i=e:e&&e.nodeType===Node.ELEMENT_NODE&&((i=e.getAttribute("data-tie-scope"))?console.log("inspect this"):(i=s(16),e.setAttribute("data-tie-scope",i))),a.validateTieKey(i),this._ties[i])throw new Error(`tie '${i}' already exists`);e.nodeType&&this._dti.views.addScope(e);e=new r(i,t,this);return(this._ties[i]=e).processDataChanges([{path:[]}]),e.model}update(e,t){if(void 0===t)throw new Error(`illegal model '${t}'`);var i="string"==typeof e?e:e&&e.getAttribute?e.getAttribute("data-tie-scope"):null,i=this._ties[i];return i?(i.model!==t&&(i.model=t,i.processDataChanges([{path:[]}])),i.model):this.create(e,t)}remove(t){let e=t;if("object"==typeof t)e=t.nodeType===Node.ELEMENT_NODE?t.getAttribute("data-tie-scope"):Object.keys(this._ties).find(e=>this._ties[e].model===t);else if("string"!=typeof t)throw new Error("invalid tieToRemove parameter "+t);this._ties[e]&&(delete this._ties[e],this._dti.views.deleteTieViews(e))}static validateTieKey(e){if(!e||"string"!=typeof e)throw new Error(`invalid key '${e}'`);if(!t.test(e))throw new Error(`tie key MUST match ${t}; '${e}' doesn't`);if(0<=o.indexOf(e))throw new Error("tie key MUST NOT be one of those: "+o.join(", "))}}function h(e={}){return i.isObservable(e)?[e,!0]:e&&"object"==typeof e?[i.from(e),!0]:[e,!1]}export{i as Observable,a as Ties}; |
@@ -1,1 +0,1 @@ | ||
const u=/\s*[,;]\s*/,f=/\s*([=ae]>)\s*/,E={A:"href",ANIMATE:"href",AREA:"href",BASE:"href",DISCARD:"href",IMAGE:"href",LINK:"href",PATTERN:"href",use:"href",INPUT:"value",SELECT:"value",TEXTAREA:"value",IFRAME:"src",IMG:"src",SOURCE:"src"},p=["INPUT","SELECT","TEXTAREA"],T={ATTRIBUTE:1,EVENT:2,METHOD:3,PROPERTY:4},a="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",s=a.length;class d{constructor(e,t,r,n,a,s,i){this.tieKey=e,this.rawPath=t,this.path=r,this.targetType=n,this.targetKey=a,this.changeEvent=s,this.fParams=i,this.iClasses=null,Object.seal(this)}}function e(a){var s=a.getAttribute("data-tie");if(s){var i=a;const l=[],o={},h=s.trim().split(u),c=h.length;let e=0,t,r,n;for(;e<c;e++)if((t=h[e])&&(r&&(r+=","+t),!(0<t.indexOf("(")&&(r=t).indexOf(")")<0)))try{r?(n=function(e){const[t,r]=e.split(/[()]/),n=r.trim().split(/\s*,\s*/).map(A);if(n.length)return new d(null,null,null,T.METHOD,t,null,n);throw new Error(`method tie parameter MUST have at least one tied argument, '${e}' doesn't`)}(r),r=null):n=function(e,t){let[r,n,a,,s]=e.split(f);const i="a>"===n?T.ATTRIBUTE:"e>"===n?T.EVENT:T.PROPERTY,{tieKey:l,rawPath:o,path:c}=A(r),h=(a=a||function(e){let t=E[e.nodeName];t?"checkbox"===e.type&&(t="checked"):t="textContent";return t}(t),s=s||function(e){let t=null;p.includes(e.nodeName)&&(t="change");return t}(t),new d(l,o,c,i,a,s,null));"classList"===a&&(h.iClasses=Array.from(t.classList));return h}(t,i),n.targetKey in o?console.error(`elements's property '${n.targetKey}' tied more than once; all but first tie dismissed`):(l.push(n),o[n.targetKey]=!0)}catch(e){console.error(`failed to parse one of a multi param parts (${t}), skipping it`,e)}return l.length?l:null}return null}function A(e){const[t,r=""]=e.split(":");if(!t)throw new Error(`tie key missing in tie parameter '${e}'; expected example: "orders:0.address.apt => title"`);e=r.split(".").filter(Boolean);return{tieKey:t,rawPath:r,path:e}}function t(e,t){if(!e)return e;var r=t,n=r.length;if(!n)return e;let a=e,s=0,i;for(;s<n;s++)if(i=r[s],null===(a=a[i])||void 0===a)return a;return a}function r(n,a,s){if(n){var i=a.length;let e=0,t,r;for(;e<i-1;e++)if((r=n[t=a[e]])&&"object"==typeof r)n=r;else if(null==r)n[t]={},n=n[t];else if("object"!=typeof r)return void console.error("setting deep path MAY NOT override primitives along the way");n[a[e]]=s}}function n(t,r,n){try{t[r].apply(t,n)}catch(e){console.error(`failed to call '${r}' of '${t}' with '${n}'`,e)}}function i(e){let t="",r=e;for(var n=crypto.getRandomValues(new Uint8Array(e));r--;)t+=a.charAt(s*n[r]/256);return t}export{e as extractViewParams,t as getPath,r as setPath,n as callViewMethod,i as getRandomKey,E as DEFAULT_TARGET,p as DEFAULT_EVENTS_CHANGE,T as TARGET_TYPES}; | ||
const f=/\s*[,;]\s*/,c=/\s*([=ae]>)\s*/,E={A:"href",ANIMATE:"href",AREA:"href",BASE:"href",DISCARD:"href",IMAGE:"href",LINK:"href",PATTERN:"href",use:"href",INPUT:"value",SELECT:"value",TEXTAREA:"value",IFRAME:"src",IMG:"src",SOURCE:"src"},p=["INPUT","SELECT","TEXTAREA"],T={ATTRIBUTE:1,EVENT:2,METHOD:3,PROPERTY:4},n="abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i=n.length;class d{constructor(e,t,r,a,n,i,s){this.tieKey=e,this.rawPath=t,this.path=r,this.targetType=a,this.targetKey=n,this.changeEvent=i,this.fParams=s,this.iClasses=null,Object.seal(this)}}function e(n){var i=n.getAttribute("data-tie");if(i){var s=n;var l=[],o={},h=i.trim().split(f),u=h.length;let e=0,t,r,a;for(;e<u;e++)if((t=h[e])&&(r&&(r+=","+t),!(0<t.indexOf("(")&&(r=t).indexOf(")")<0)))try{r?(a=function(e){var[t,r]=e.split(/[()]/),r=r.trim().split(/\s*,\s*/).map(A);if(r.length)return new d(null,null,null,T.METHOD,t,null,r);throw new Error(`method tie parameter MUST have at least one tied argument, '${e}' doesn't`)}(r),r=null):a=function(e,t){var[e,r,a,,n]=e.split(c);var r="a>"===r?T.ATTRIBUTE:"e>"===r?T.EVENT:T.PROPERTY,{tieKey:e,rawPath:i,path:s}=A(e),e=(a=a||function(e){let t=E[e.nodeName];t?"checkbox"===e.type&&(t="checked"):t="textContent";return t}(t),n=n||function(e){let t=null;p.includes(e.nodeName)&&(t="change");return t}(t),new d(e,i,s,r,a,n,null));"classList"===a&&(e.iClasses=Array.from(t.classList));return e}(t,s),a.targetKey in o?console.error(`elements's property '${a.targetKey}' tied more than once; all but first tie dismissed`):(l.push(a),o[a.targetKey]=!0)}catch(e){console.error(`failed to parse one of a multi param parts (${t}), skipping it`,e)}return l.length?l:null}return null}function A(e){var t,[r,a=""]=e.split(":");if(r)return t=a.split(".").filter(Boolean),{tieKey:r,rawPath:a,path:t};throw new Error(`tie key missing in tie parameter '${e}'; expected example: "orders:0.address.apt => title"`)}function t(e,t){if(!e)return e;var r=t,a=r.length;if(!a)return e;let n=e,i=0,s;for(;i<a;i++)if(s=r[i],null===(n=n[s])||void 0===n)return n;return n}function r(a,n,i){if(a){var s=n.length;let e=0,t,r;for(;e<s-1;e++)if((r=a[t=n[e]])&&"object"==typeof r)a=r;else if(null==r)a[t]={},a=a[t];else if("object"!=typeof r)return void console.error("setting deep path MAY NOT override primitives along the way");a[n[e]]=i}}function a(t,r,a){try{t[r].apply(t,a)}catch(e){console.error(`failed to call '${r}' of '${t}' with '${a}'`,e)}}function s(e){let t="",r=e;for(var a=crypto.getRandomValues(new Uint8Array(e));r--;)t+=n.charAt(i*a[r]/256);return t}export{e as extractViewParams,t as getPath,r as setPath,a as callViewMethod,s as getRandomKey,E as DEFAULT_TARGET,p as DEFAULT_EVENTS_CHANGE,T as TARGET_TYPES}; |
@@ -1,1 +0,1 @@ | ||
import{extractViewParams as o,getRandomKey as r,TARGET_TYPES as h}from"./utils.min.js";class e{constructor(e){this.dti=e,this.views={},this.scopes={},this.unscoped=[]}obtainTieViews(e){let t=this.views[e];return t||(t={_pathsCache:[]},this.views[e]=t),t}deleteTieViews(e){delete this.views[e]}addView(e,t){this._handleView(e,t,!0)}delView(e,t){this._handleView(e,t,!1)}addScope(e){var t,s=e.getAttribute("data-tie-scope");if(s){if(s in this.scopes&&this.scopes[s]!==e)throw new Error(`scope key '${s} already claimed by another element`);if(this.scopes[s]!==e){this.scopes[s]=e;for(const i of this.unscoped)!e.contains(i)||(t=o(i))&&(this.addView(i,t),this.unscoped.splice(this.unscoped.indexOf(i),1))}}else e.setAttribute("data-tie-scope",r(16))}delScope(){throw new Error("not implemented")}_handleView(e,t,s){var i,o,r;let a=t.length,n;for(;a--;)if((i=t[a]).targetType===h.METHOD)for(o=i.fParams,n=o.length;n--;)r=o[n],this[s?"_seekAndInsertView":"_seekAndRemoveView"](r,e);else this[s?"_seekAndInsertView":"_seekAndRemoveView"](i,e);s?e[this.dti.paramsKey]=t:delete e[this.dti.paramsKey]}_seekAndInsertView(e,t){let s=e.tieKey;if("scope"===s){if(!(s=this._lookupClosestScopeKey(t)))return void this.unscoped.push(t);e.tieKey=s}e=e.rawPath;const i=this.obtainTieViews(s);let o=i[e];o||(o=[],i[e]=o,i._pathsCache.push(e)),o.indexOf(t)<0&&o.push(t)}_seekAndRemoveView(e,t){var s=e.tieKey,e=e.rawPath,s=this.views[s];if(s){const i=s[e];!i||0<=(s=i.indexOf(t))&&i.splice(s,1)}}_lookupClosestScopeKey(e){let t=e,s;for(;!(s=t.getAttribute("data-tie-scope"))&&((t=(t=t.parentNode).host?t.host:t)&&t.nodeType!==Node.DOCUMENT_NODE););return s}updateViewByModel(t,e,s,i){var o=e.targetType||h.PROPERTY,r=e.targetKey;try{switch(o){case h.ATTRIBUTE:this._unsafeSetAttribute(t,r,s);break;case h.EVENT:this._unsafeSetEvent(t,r,s,i);break;case h.PROPERTY:this._unsafeSetProperty(t,e,r,s);break;default:throw new Error(`unsupported target type '${o}'`)}}catch(e){console.error(`failed to set '${r}' of '${t}' to '${s}'`,e)}}_unsafeSetAttribute(e,t,s){null==s?e.removeAttribute(t):e.setAttribute(t,String(s))}_unsafeSetEvent(e,t,s,i){"function"==typeof i&&e.removeEventListener(t,i),"function"==typeof s&&e.addEventListener(t,s)}_unsafeSetProperty(e,t,s,i){if("textContent"===s)this._setTextContentProperty(e,i);else if("value"===s)this._setValueProperty(e,i);else if("href"===s&&"object"==typeof e.href)e.href.baseVal=i;else if("scope"===s)this.dti.ties.update(e,i);else if("classList"===s){const o=t.iClasses.slice(0);i&&(Array.isArray(i)&&i.length?i.forEach(e=>{o.indexOf(e)<0&&o.push(e)}):"object"==typeof i?Object.keys(i).forEach(e=>{var t=o.indexOf(e);i[e]?t<0&&o.push(e):0<=t&&o.splice(t,1)}):"string"==typeof i&&o.indexOf(i)<0&&o.push(i)),e.className=o.join(" ")}else e[s]=i}_setTextContentProperty(e,t){e.textContent=null==t?"":t}_setValueProperty(e,t){let s=t;null==t&&("INPUT"!==(t=e.nodeName)&&"SELECT"!==t&&"TEXTAREA"!==t||(s="")),e.value=s}}export{e as Views}; | ||
import{extractViewParams as o,getRandomKey as r,TARGET_TYPES as h}from"./utils.min.js";class e{constructor(e){this.dti=e,this.views={},this.scopes={},this.unscoped=[]}obtainTieViews(e){let t=this.views[e];return t||(t={_pathsCache:[]},this.views[e]=t),t}deleteTieViews(e){delete this.views[e]}addView(e,t){this._handleView(e,t,!0)}delView(e,t){this._handleView(e,t,!1)}addScope(e){var t,s=e.getAttribute("data-tie-scope");if(s){if(s in this.scopes&&this.scopes[s]!==e)throw new Error(`scope key '${s} already claimed by another element`);if(this.scopes[s]!==e){this.scopes[s]=e;for(const i of this.unscoped)e.contains(i)&&(t=o(i))&&(this.addView(i,t),this.unscoped.splice(this.unscoped.indexOf(i),1))}}else e.setAttribute("data-tie-scope",r(16))}delScope(){throw new Error("not implemented")}_handleView(e,t,s){var i,o,r;let a=t.length,n;for(;a--;)if((i=t[a]).targetType===h.METHOD)for(o=i.fParams,n=o.length;n--;)r=o[n],this[s?"_seekAndInsertView":"_seekAndRemoveView"](r,e);else this[s?"_seekAndInsertView":"_seekAndRemoveView"](i,e);s?e[this.dti.paramsKey]=t:delete e[this.dti.paramsKey]}_seekAndInsertView(e,t){let s=e.tieKey;if("scope"===s){if(!(s=this._lookupClosestScopeKey(t)))return void this.unscoped.push(t);e.tieKey=s}var e=e.rawPath,i=this.obtainTieViews(s);let o=i[e];o||(o=[],i[e]=o,i._pathsCache.push(e)),o.indexOf(t)<0&&o.push(t)}_seekAndRemoveView(e,t){var s=e.tieKey,e=e.rawPath,s=this.views[s];s&&(s=s[e])&&0<=(e=s.indexOf(t))&&s.splice(e,1)}_lookupClosestScopeKey(e){let t=e,s;for(;!(s=t.getAttribute("data-tie-scope"))&&(t=(t=t.parentNode).host?t.host:t)&&t.nodeType!==Node.DOCUMENT_NODE;);return s}updateViewByModel(t,e,s,i){var o=e.targetType||h.PROPERTY,r=e.targetKey;try{switch(o){case h.ATTRIBUTE:this._unsafeSetAttribute(t,r,s);break;case h.EVENT:this._unsafeSetEvent(t,r,s,i);break;case h.PROPERTY:this._unsafeSetProperty(t,e,r,s);break;default:throw new Error(`unsupported target type '${o}'`)}}catch(e){console.error(`failed to set '${r}' of '${t}' to '${s}'`,e)}}_unsafeSetAttribute(e,t,s){null==s?e.removeAttribute(t):e.setAttribute(t,String(s))}_unsafeSetEvent(e,t,s,i){"function"==typeof i&&e.removeEventListener(t,i),"function"==typeof s&&e.addEventListener(t,s)}_unsafeSetProperty(e,t,s,i){if("textContent"===s)this._setTextContentProperty(e,i);else if("value"===s)this._setValueProperty(e,i);else if("href"===s&&"object"==typeof e.href)e.href.baseVal=i;else if("scope"===s)this.dti.ties.update(e,i);else if("classList"===s){const o=t.iClasses.slice(0);i&&(Array.isArray(i)&&i.length?i.forEach(e=>{o.indexOf(e)<0&&o.push(e)}):"object"==typeof i?Object.keys(i).forEach(e=>{var t=o.indexOf(e);i[e]?t<0&&o.push(e):0<=t&&o.splice(t,1)}):"string"==typeof i&&o.indexOf(i)<0&&o.push(i)),e.className=o.join(" ")}else e[s]=i}_setTextContentProperty(e,t){e.textContent=null==t?"":t}_setValueProperty(e,t){let s=t;null!=t||"INPUT"!==(t=e.nodeName)&&"SELECT"!==t&&"TEXTAREA"!==t||(s=""),e.value=s}}export{e as Views}; |
{ | ||
"name": "data-tier", | ||
"version": "3.6.1", | ||
"version": "3.6.3", | ||
"description": "Tiny and fast two way (MV-VM) data binding framework for browser environments.", | ||
@@ -54,11 +54,9 @@ "type": "module", | ||
"dependencies": { | ||
"object-observer": "^5.0.0" | ||
"@gullerya/object-observer": "^6.0.4" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.9.0", | ||
"fs-extra": "^10.0.0", | ||
"just-test": "2.3.2", | ||
"puppeteer": "^13.3.2", | ||
"uglify-js": "^3.15.1" | ||
"eslint": "^8.35.0", | ||
"fs-extra": "^11.1.0", | ||
"uglify-js": "^3.17.4" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
[![NPM](https://img.shields.io/npm/v/data-tier.svg?label=npm%20data-tier)](https://www.npmjs.com/package/data-tier) | ||
[![NPM](https://img.shields.io/npm/v/data-tier.svg?label=npm)](https://www.npmjs.com/package/data-tier) | ||
[![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](./license.md) | ||
@@ -10,2 +10,4 @@ | ||
> Starting v4 `data-tier`'s NPM will be relocated to the scoped [@gullerya/data-tier](https://www.npmjs.com/package/@gullerya/data-tier). | ||
`data-tier` ('tier' from 'to tie') is a two way binding (MVVM) library targeting client (browser) HTML/JavaScript applications. | ||
@@ -12,0 +14,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55185
3
924
122
+ Added@gullerya/object-observer@6.1.3(transitive)
- Removedobject-observer@^5.0.0
- Removedobject-observer@5.2.0(transitive)