simplyflow 0.8.2 → 0.9.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.
@@ -1,2 +1,2 @@
1
- (()=>{var ke=Object.defineProperty;var D=(e,t)=>{for(var n in t)ke(e,n,{get:t[n],enumerable:!0})};var U={};D(U,{addTracer:()=>Pe,batch:()=>T,clockEffect:()=>oe,clone:()=>Ce,destroy:()=>$,effect:()=>se,makeContext:()=>y,notifyGet:()=>v,notifySet:()=>g,signal:()=>E,signals:()=>d,throttledEffect:()=>b,trace:()=>Le,untracked:()=>V});Symbol.iterate||(Symbol.iterate=Symbol("iterate"));Symbol.xRay||(Symbol.xRay=Symbol("xRay"));Symbol.Signal||(Symbol.Signal=Symbol("Signal"));var Me={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let r=e?.[t];return v(n,t),typeof r=="function"?Array.isArray(e)?(...i)=>{let s=e.length,o=r.apply(n,i);return s!=e.length&&g(n,y("length",{was:s,now:e.length})),o}:e instanceof Set||e instanceof Map?(...i)=>{let s=e.size,o=r.apply(e,i);return s!=e.size&&g(n,y("size",{was:s,now:e.size})),["set","add","clear","delete"].includes(t)&&g(n,y({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),o}:e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?r.bind(e):r.bind(n):r&&typeof r=="object"?E(r):r},set:(e,t,n,r)=>{let i=e[t];return i!==n&&(e[t]=n,g(r,y(t,{was:i,now:n}))),typeof i>"u"&&(g(r,y(Symbol.iterate,{})),g(r,y("length",{}))),!0},has:(e,t)=>{let n=d.get(e);return n&&v(n,t),Object.hasOwn(e,t)},deleteProperty:(e,t)=>{if(typeof e[t]<"u"){let n=e[t];delete e[t];let r=d.get(e);g(r,y(t,{delete:!0,was:n}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let r=d.get(e);g(r,y(Symbol.iterate,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=d.get(e);return v(t,Symbol.iterate),Reflect.ownKeys(e)}},d=new WeakMap;function E(e){return e||(e={}),e[Symbol.Signal]?e:(d.has(e)||d.set(e,new Proxy(e,Me)),d.get(e))}var R=[],H=!1;function Le(e,t){if(typeof e=="function")H=!0,e(),H=!1;else return ie(e,t).map(r=>({effect:r.effectType,fn:r.effectFunction,signal:d.get(r.effectFunction)}))}function Pe(e){if(!e.get&&!e.set)throw new Error('simply.state: addTracer: missing "get" or "set" property in tracer',e);if(e.get&&typeof e.get!="function")throw new Error('simply.state: addTracer: "get" is not a function',e);if(e.set&&typeof e.set!="function")throw new Error('simply.state: addTracer: "set" is not a function',e);R.push(e)}function ne(e,...t){for(let n of R)n[e]&&n[e](...t)}var I=new Set,k=0;function g(e,t={}){let n=[];if(t.forEach((r,i)=>{let s=ie(e,i);if(s?.length){for(let o of s)Oe(o,y(i,r));n=n.concat(s)}}),n=new Set(n.filter(Boolean)),n)if(k)I=I.union(n);else{let r=h[h.length-1];for(let i of Array.from(n))i!=r&&i?.needsUpdate&&(H&&R.length&&ne("set",e,t,i),i()),re(i)}}function y(e,t){let n=new Map;if(typeof e=="object")for(let r in e)n.set(r,e[r]);else n.set(e,t);return n}function Oe(e,t){e.context?t.forEach((n,r)=>{e.context.set(r,n)}):e.context=t,e.needsUpdate=!0}function re(e){delete e.context,delete e.needsUpdate}function v(e,t){let n=h[h.length-1];n&&(H&&R.length&&ne("get",e,t),Be(e,t,n))}var L=new WeakMap,N=new WeakMap;function ie(e,t){let n=L.get(e);return n?Array.from(n.get(t)||[]):[]}function Be(e,t,n){L.has(e)||L.set(e,new Map);let r=L.get(e);r.has(t)||r.set(t,new Set),r.get(t).add(n),N.has(n)||N.set(n,new Map);let i=N.get(n);i.has(t)||i.set(t,new Set),i.get(t).add(e)}function z(e){let t=N.get(e);t&&t.forEach(n=>{n.forEach(r=>{let i=L.get(r);i.has(n)&&i.get(n).delete(e)})})}var h=[],q=[],K=new WeakMap,A=[];function se(e){if(q.findIndex(r=>e==r)!==-1)throw new Error("Recursive update() call",{cause:e});q.push(e);let t=d.get(e);t||(t=E({current:null}),d.set(e,t));let n=function r(){if(A.findIndex(s=>s==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});z(r),r.effectFunction=e,r.effectType=se,h.push(r),A.push(t);let i;try{i=e(r,h,A)}finally{h.pop(),A.pop(),i instanceof Promise?i.then(s=>{t.current=s}):t.current=i}};return n.fn=e,K.set(t,n),n(),t}function $(e){let t=K.get(e)?.deref();if(!t)return;z(t);let n=t.fn;d.remove(n),K.delete(e)}function T(e){k++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{k--,k||te()}):(k--,k||te())}return t}function te(){let e=Array.from(I);I=new Set;let t=h[h.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),re(n)}function b(e,t){if(q.findIndex(o=>e==o)!==-1)throw new Error("Recursive update() call",{cause:e});q.push(e);let n=d.get(e);n||(n=E({current:null}),d.set(e,n));let r=!1,i=!0;return function o(){if(A.findIndex(u=>u==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});if(r&&r>Date.now()){i=!0;return}z(o),o.effectFunction=e,o.effectType=b,h.push(o),A.push(n);let l;try{l=e(o,h,A)}finally{i=!1,h.pop(),A.pop(),l instanceof Promise?l.then(u=>{n.current=u}):n.current=l}r=Date.now()+t,globalThis.setTimeout(()=>{i&&o()},t)}(),n}function oe(e,t){let n=d.get(e);n||(n=E({current:null}),d.set(e,n));let r=-1,i=!0;return function o(){if(r<t.time)if(i){z(o),o.effectFunction=e,o.effectType=oe,h.push(o),r=t.time;let l;try{l=e(o,h)}finally{h.pop(),l instanceof Promise?l.then(u=>{n.current=u}):n.current=l,i=!1}}else r=t.time;else i=!0}(),n}function V(e){let t=h.length-1,n=h[t];h[t]=!1;try{return e()}finally{h[t]=n}}function Ce(e,t=!1){let n=new Map,r=function(i){if(n.has(i))return n.get(i);switch(typeof i){case"object":if(!i)return i;if(Array.isArray(i)){let s=[];if(!t)return s=i.slice(),n.set(i,s),s;n.set(i,s);for(let o of i)s[o]=r(i[o])}else if(!i.constructor||i.constructor===Object){let s={};i.constructor||(s=Object.create(null)),n.set(i,s);for(let o in i)s[o]=t?r(i[o]):i[o];return s}else return i;break;default:return null}};return r(e)}function le(e,t){let n=e.value?.innerHTML;typeof e.value=="string"&&(n=e.value,e.value={innerHTML:n}),n&&(n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),e.value.innerHTML=n),t(e)}function ae(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var J={};D(J,{signal:()=>W,trackDomField:()=>G,trackDomList:()=>_});var fe=new WeakMap,je={get:(e,t,n)=>{if(t===Symbol.xRay)return e;if(t===Symbol.Signal)return!0;let r=e?.[t];return v(n,t),typeof r=="function"?r.bind(e):r&&typeof r=="object"?E(r):r},has:(e,t)=>{let n=d.get(e);return n&&v(n,t),Object.hasOwn(e,t)},ownKeys:e=>{let t=d.get(e);return t&&v(t,iterate),Reflect.ownKeys(e)}};function W(e,t){return e[Symbol.xRay]?e:(d.has(e)||(d.set(e,new Proxy(e,je)),Ne(e,d.get(e),t)),d.get(e))}var ue=new WeakMap;function Ne(e,t,n){n||(n={characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0});let i=e.innerHTML,s=e.innerText;if(!ue.has(e)){let o=new MutationObserver((l,u)=>{let f={};for(let c of l)c.type==="attributes"?f[c.attributeName]=c.attributeOldValue:c.type==="subtree"||c.type==="characterData"?(e.innerHTML!=i&&(f.innerHTML=i,i=e.innerHTML),e.innerText!=s&&(f.innerText=s,s=e.innerText)):c.type==="childList"?(f.children={was:Array.from(e.children)},f.length=-1):console.log("nothing to do for",e,c.type);for(let c in f)g(t,y(c,{was:f[c],now:e[c]}))});if(o.observe(e,n),ue.set(e,o),e.matches("input, textarea, select")){let l=e.value;e.addEventListener("change",u=>{g(t,y("value",{was:l,now:e.value})),l=e.value}),e.matches("input, textarea")&&e.addEventListener("input",u=>{g(t,y("value",{was:l,now:e.value})),l=e.value})}}}function _(e){let t=this.getBindingPath(e);if(!t)throw new Error("Could not find binding path for element",{cause:e});let n=W(e,{childList:!0});b(()=>{let r=Array.from(n.children);V(()=>{T(()=>{let i=0,s=P(this.options.root,t),o=s.slice();for(let l of r)l.tagName!=="TEMPLATE"&&l.dataset.flowKey&&(l.dataset.flowKey!=i&&Q(this.options.root,t+"."+i,o[l.dataset.flowKey]),i++);s.length>i&&(s.length=i)})})})}function G(e,t,n){if(fe.has(e))return;let r=this.getBindingPath(e);if(!r)throw new Error("Could not find binding path for element",{cause:e});let i=W(e);fe.set(e,i),T(()=>{b(()=>{let s=i.innerHTML;n||(s=ce(i,...t)),V(()=>{Q(this.options.root,r,s)})})})}function de(e){if(e.templates?.length)Re.call(this,e);else if(Object.hasOwnProperty.call(this.options.renderers,e.element.tagName)){let t=this.options.renderers[e.element.tagName];t&&t.call(this,e)}else this.options.renderers["*"]&&this.options.renderers["*"].call(this,e);return e}function he(e){Array.isArray(e.value)||(e.value=[e.value]);let t=e.value.length;return e.templates?.length?Ie.call(this,e):console.error("No templates found in",e.element),e}function me(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?qe.call(this,e):console.error("No templates found in",e.element),e}function He(e){if(parseInt(e)==e)return!0}function Q(e,t,n){T(()=>{let r=t.split("."),i=e,s;s=r.shift();let o=null,l=null,u=i;for(;s&&i;){if(u=i,s=decodeURIComponent(s),!(s=="0"&&!Array.isArray(i))){if(s==":key")throw new Error("setting key not yet supported");s==":value"||(Array.isArray(i)&&!He(s)&&typeof i[s]>"u"?(o=i[0],i=i[0][s]):(o=i,i=i[s]))}if(l=s,s=r.shift(),s&&!i){let f=parseInt(s);f>=0&&s===""+f?u[l]=[]:u[l]={},i=u[l]}}if(o&&l&&o[l]!==n)if(n&&typeof n=="object"){i=o[l],i||(o[l]={},i=o[l]);for(let f in n)i[f]!==n[f]&&(i[f]=n[f])}else o[l]=n})}function Ie(e){let t=this.options.attribute,n=e.element.querySelectorAll(":scope > ["+t+"-key]"),r=0,i=0;e.list=e.value;for(let o of n){let l=parseInt(o.getAttribute(t+"-key"));if(l>r)e.index=r,e.element.insertBefore(this.applyTemplate(e),o);else if(l<r)o.remove();else{let u=Array.from(o.querySelectorAll(`[${t}]`));o.matches(`[${t}]`)&&u.unshift(o);let f=u.find(c=>{let w=c.getAttribute(t);return w.substr(0,5)!==":root"&&w.substr(0,e.path.length)!==e.path});if(!f&&o[Symbol.bindTemplate]){let c=this.findTemplate(e.templates,e.list[r]);c!=o[Symbol.bindTemplate]&&(f=!0,c||i++)}f&&(e.index=r,e.element.replaceChild(this.applyTemplate(e),o))}if(r++,r>=e.value.length)break}n=e.element.querySelectorAll(":scope > ["+t+"-key]");let s=n.length+i;if(s>e.value.length)for(;s>e.value.length;)e.element.querySelectorAll(":scope > :not(template)")?.[s-1]?.remove(),s--;else if(s<e.value.length)for(;s<e.value.length;)e.index=s,e.element.appendChild(this.applyTemplate(e)),s++;this.options.twoway&&_.call(this,e.element)}function qe(e){let t=this.options.attribute;e.list=e.value;let n=Array.from(e.element.querySelectorAll(":scope > ["+t+"-key]"));for(let r in e.list){e.index=r;let i=n.shift();if(!i){let o=this.applyTemplate(e);e.element.appendChild(o);continue}if(i.getAttribute(t+"-key")!=r){n.unshift(i);let o=e.element.querySelector(":scope > ["+t+'-key="'+r+'"]');if(o)e.element.insertBefore(o,i),i=o,n=n.filter(l=>l!=o);else{let l=this.applyTemplate(e);e.element.insertBefore(l,i);continue}}if(this.findTemplate(e.templates,e.list[e.index])!=i[Symbol.bindTemplate]){let o=this.applyTemplate(e);e.element.replaceChild(o,i)}}for(;n.length;)n.shift().remove()}function Re(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=ze(e.element),t)if(n){if(t?.[Symbol.bindTemplate]!=n){let r=this.applyTemplate(e);e.element.replaceChild(r,t)}}else e.element.removeChild(t);else if(n){let r=this.applyTemplate(e);e.element.appendChild(r)}}function ze(e,t){let n=e.parentElement?.closest(`[${t}-list],[${t}-map]`);return n?n.hasAttribute(`${t}-list`)?n.getAttribute(`${t}-list`)+".":n.getAttribute(`${t}-map`)+".":""}function ye(e){let t=e.element,n=e.value;O.call(this,e),typeof n>"u"&&(n=""),t.type=="checkbox"||t.type=="radio"?F(t.value,n)?t.checked=!0:t.checked=!1:F(t.value,n)||(t.value=""+n)}function be(e){O.call(this,e,"value")}function X(e){let t=e.element,n=e.value;if(n===null&&(n=""),typeof n!="object")if(t.multiple){if(Array.isArray(n))for(let r of t.options)n.indexOf(r.value)===!1?r.selected=!1:r.selected=!0}else{let r=t.options.find(i=>F(i.value,n));r&&(r.selected=!0,r.setAttribute("selected",!0))}else n.options&&$e(t,n.options),n.selected&&X(Object.asssign({},e,{value:n.selected})),B(t,n,"name","id","selectedIndex","className")}function pe(e,t){t&&(typeof t!="object"?e.options.add(new Option(""+t)):t.text?e.options.add(new Option(t.text,t.value,t.defaultSelected,t.selected)):typeof t.value<"u"&&e.options.add(new Option(""+t.value,t.value,t.defaultSelected,t.selected)))}function $e(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)pe(e,n);else if(t&&typeof t=="object")for(let n in t)pe(e,{text:t[n],value:n})}function ge(e){O.call(this,e,"target","href","name","newwindow","nofollow"),this.options.twoway&&T(()=>{updateProperties.call(this,e,["target","href","name","newwindow","nofollow"])})}function we(e){B(e.element,e.value,"title","alt","src","id"),this.options.twoway&&T(()=>{updateProperties.call(this,e,["title","alt","src","id"])})}function Se(e){B(e.element,e.value,"title","src","id"),this.options.twoway&&T(()=>{updateProperties.call(this,e,["title","src","id"])})}function Te(e){B(e.element,e.value,"content","id"),this.options.twoway&&T(()=>{updateProperties.call(this,e,["content","id"])})}function O(e,...t){let n=e.element,r=e.value,i=!1;if(typeof r<"u"&&r!==null){let o=""+r;(typeof r!="object"||o.substring(0,8)!="[object ")&&(r={innerHTML:r},i=!0)}let s=["innerHTML","title","id","className"].concat(t);B(n,r,...s),this.options.twoway&&G.call(this,e.element,s,i)}function B(e,t,...n){if(!(!t||typeof t!="object"))for(let r of n)typeof t[r]>"u"||F(e[r],t[r])||(t[r]===null?e[r]="":e[r]=""+t[r])}function ce(e,...t){let n={};for(let r of t)switch(r){default:n[r]=e[r];break}return n}function F(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}Symbol.bindTemplate||(Symbol.bindTemplate=Symbol("bindTemplate"));var Y=class{constructor(t){this.bindings=new Map;let n={escape_html:le,fixed_content:ae},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[de],list:[he],map:[me]},renderers:{INPUT:ye,BUTTON:be,SELECT:X,A:ge,IMG:we,IFRAME:Se,META:Te,TEMPLATE:null,"*":O},twoway:!1};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},r,t),t.transformers&&(this.options.transformers=Object.assign({},n,t?.transformers));let i=this.options.attribute,s=[i+"-field",i+"-list",i+"-map"],o=i+"-transform",l=a=>{let p=s.find(m=>a.hasAttribute(m));return p||console.error("No matching attribute found",a,s),p},u=a=>{this.bindings.set(a,b(()=>{if(!a.isConnected){De(a,this.getBindingPath(a)),$(this.bindings.get(a));return}let p={templates:a.querySelectorAll(":scope > template"),attribute:l(a)};p.path=this.getBindingPath(a),p.value=P(this.options.root,p.path),p.element=a,Fe(a,p),f(p)},50))},f=a=>{let p;switch(a.attribute){case this.options.attribute+"-field":p=Array.from(this.options.render.field);break;case this.options.attribute+"-list":p=Array.from(this.options.render.list);break;case this.options.attribute+"-map":p=Array.from(this.options.render.map);break;default:throw new Error("no valid context attribute specified",a)}a.element.hasAttribute(o)&&a.element.getAttribute(o).split(" ").filter(Boolean).forEach(S=>{this.options.transformers[S]?p.push(this.options.transformers[S]):console.warn("No transformer with name "+S+" configured",{cause:a.element})});let m;for(let S of p)m=((M,Ae)=>ve=>Ae.call(this,ve,M))(m,S);m(a)},c=a=>{for(let p of a)this.bindings.get(p)||u(p)},w=a=>{let p=`[${i}-field],[${i}-list],[${i}-map]`;for(let m of a)if(m.type=="childList"&&m.addedNodes){for(let S of m.addedNodes)if(S instanceof HTMLElement){let M=Array.from(S.querySelectorAll(p));S.matches(p)&&M.unshift(S),M.length&&c(M)}}};this.observer=new MutationObserver(a=>{w(a)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let j=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");j.length&&c(j)}applyTemplate(t){let n=t.path,r=t.parent,i=t.templates,s=t.list,o=t.index,l=s?s[o]:t.value,u=this.findTemplate(i,l);if(!u){let a=new DocumentFragment;return a.innerHTML="<!-- no matching template -->",a}let f=u.content.cloneNode(!0);if(!f.children?.length)return f;if(f.children.length>1)throw new Error("template must contain a single root node",{cause:u});let c=this.options.attribute,w=[c+"-field",c+"-list",c+"-map"],j=f.querySelectorAll(`[${c}-field],[${c}-list],[${c}-map]`);for(let a of j){if(a.tagName=="TEMPLATE")continue;let p=w.find(S=>a.hasAttribute(S)),m=a.getAttribute(p);m=this.applyLinks(u.links,m),m.substring(0,6)==":root."?a.setAttribute(p,m.substring(6)):m==":value"&&o!=null?a.setAttribute(p,n+"."+o):o!=null?a.setAttribute(p,n+"."+o+"."+m):a.setAttribute(p,r+m)}return typeof o<"u"&&f.children[0].setAttribute(c+"-key",o),f.children[0][Symbol.bindTemplate]=u,f}parseLinks(t){let n={};t=t.split(";").map(r=>r.trim());for(let r of t)r=r.split("="),n[r[0].trim()]=r[1].trim();return n}applyLinks(t,n){for(let r in t){if(n.startsWith(r+"."))return t[r]+n.substr(r.length);if(n==r)return t[r]}return n}getBindingPath(t){let n=[this.options.attribute+"-field",this.options.attribute+"-list",this.options.attribute+"-map"];for(let r of n)if(t.hasAttribute(r))return t.getAttribute(r)}findTemplate(t,n){let r=l=>{let u=this.getBindingPath(l),f;u?u.substr(0,6)==":root."?f=P(this.options.root,u):f=P(n,u):f=n;let c=""+f,w=l.getAttribute(this.options.attribute+"-match");if(w){if(w===":empty"&&!f)return l;if(w===":notempty"&&f||c==w)return l}if(!w)return l},i=Array.from(t).find(r),s=null;i?.hasAttribute(this.options.attribute+"-link")&&(s=this.parseLinks(i.getAttribute(this.options.attribute+"-link")));let o=i?.getAttribute("rel");if(o){let l=document.querySelector("template#"+o);if(!l)throw new Error("Could not find template with id "+o);i=l}return i&&(i.links=s),i}destroy(){this.bindings.forEach(t=>{$(t)}),this.bindings=new Map,this.observer.disconnect()}};function Ee(e){return new Y(e)}var C=new Map;function Fe(e,t){C.has(t.path)?C.get(t.path).push(t):C.set(t.path,[t])}function De(e,t){let n=C.get(t);n&&(n=n.filter(r=>r.element==e),C.set(t,n))}function P(e,t){let n=t.split("."),r=e,i;i=n.shift();let s=null;for(;i&&r;)i=decodeURIComponent(i),i=="0"&&!Array.isArray(r)||(i==":key"?r=s:i==":value"||(Array.isArray(r)&&typeof r[i]>"u"&&r[0]?r=r[0][i]:r=r[i])),s=i,i=n.shift();return r}var x={};D(x,{columns:()=>Ge,filter:()=>_e,model:()=>Ke,paging:()=>We,scroll:()=>Je,sort:()=>Ue});var Z=class{constructor(t){if(!t)throw new Error("no options set");(t.data==null||typeof t.data[Symbol.iterator]!="function")&&console.warn("SimplyFlowModel: options.data is not iterable"),this.state=E(t),this.state.options||(this.state.options={}),this.effects=[{current:this.state.data}],this.view={current:this.state.data}}addEffect(t){if(!t||typeof t!="function")throw new Error("addEffect requires an effect function as its parameter",{cause:t});let n=this.effects[this.effects.length-1],r=t.call(this,n);if(!r||!r[Symbol.Signal])throw new Error("addEffect function parameter must return a Signal",{cause:t});this.view=r,this.effects.push(this.view)}};function Ke(e){return new Z(e)}function Ue(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let i=this.state.options.sort,s=i.sortBy;if(!i.sortBy)return 0;let o=i.direction=="asc"?1:-1,l=i.direction=="asc"?-1:1;return typeof n?.[s]>"u"?typeof r?.[s]>"u"?0:o:typeof r?.[s]>"u"||n[s]<r[s]?l:n[s]>r[s]?o:0}},e),b(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?t.current.toSorted(n?.sortFn):t.current},50)}}function We(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),b(()=>T(()=>{let n=this.state.options.paging;n.pageSize||(n.pageSize=20),n.max=Math.ceil(this.state.data.length/n.pageSize),n.page=Math.max(1,Math.min(n.max,n.page));let r=(n.page-1)*n.pageSize,i=r+n.pageSize;return t.current.slice(r,i)}),50)}}function _e(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");return this.state.options[e.name]=e,b(()=>this.state.options[e.name].enabled?t.current.filter(this.state.options[e.name].matches.bind(this)):t.current,50)}}function Ge(e={}){if(!e||typeof e!="object"||Object.keys(e).length===0)throw new Error("columns requires options to be an object with at least one property");return function(t){return this.state.options.columns=e,b(()=>t.current.map(n=>{let r={};for(let i of Object.keys(this.state.options.columns))this.state.options.columns[i]?.hidden||(r[i]=n[i]??null);return r}),50)}}function Je(e){return function(t){this.state.options.scroll=Object.assign({offset:0,rowHeight:26,rowCount:20,itemsPerRow:1,size:t.current.length},e);let n=this.state.options.scroll,r=n.scrollbar||n.container?.querySelector("[data-flow-scrollbar]");return r&&(n.container&&n.container.addEventListener("scroll",i=>{n.offset=Math.floor(n.container.scrollTop/(n.rowHeight*n.itemsPerRow))}),b(()=>{n.size=t.current.length*n.rowHeight,r.style.height=n.size+"px"},50)),b(()=>{n.container&&(n.rowCount=Math.ceil(n.container.getBoundingClientRect().height/n.rowHeight)),n.data=t.current;let i=Math.min(n.offset,t.current.length-1),s=i+n.rowCount;return s>t.current.length&&(s=t.current.length,i=s-n.rowCount),t.current.slice(i,s)},50)}}var ee=class extends HTMLElement{constructor(){super()}connectedCallback(){let t=this.getAttribute("rel"),n=document.getElementById(t);if(n){let r=n.content.cloneNode(!0);for(let i of r.childNodes){let s=i.cloneNode(!0);if(s.nodeType==document.ELEMENT_NODE&&(s.querySelectorAll("template").forEach(function(o){o.setAttribute("simply-render","")}),this.attributes))for(let o of this.attributes)o.name!="rel"&&s.setAttribute(o.name,o.value);this.parentNode.insertBefore(s,this)}this.parentNode.removeChild(this)}else(()=>{let i=new MutationObserver(()=>{n=document.getElementById(t),n&&(i.disconnect(),this.replaceWith(this))});i.observe(globalThis.document,{subtree:!0,childList:!0})})()}};customElements.get("simply-render")||customElements.define("simply-render",ee);globalThis.simply||(globalThis.simply={});Object.assign(globalThis.simply,{bind:Ee,flow:x,state:U,dom:J});var bt=globalThis.simply;})();
1
+ (()=>{var ve=Object.defineProperty;var K=(e,t)=>{for(var n in t)ve(e,n,{get:t[n],enumerable:!0})};var W={};K(W,{addTracer:()=>Ce,batch:()=>A,clockEffect:()=>fe,clone:()=>Re,destroy:()=>F,effect:()=>ae,makeContext:()=>m,notifyGet:()=>S,notifySet:()=>g,signal:()=>L,signals:()=>d,throttledEffect:()=>E,trace:()=>Ne,untracked:()=>$});var h={ITERATE:Symbol.for("@simplyedit/simplyflow.iterate"),XRAY:Symbol.for("@simplyedit/simplyflow.xRay"),SIGNAL:Symbol.for("@simplyedit/simplyflow.Signal"),TEMPLATE:Symbol.for("@simplyedit/simplyflow.bindTemplate"),LENGTH:"length",SIZE:"size"};function Pe(e,t,n,r){return(...i)=>{(t==="get"||t==="has")&&S(n,i[0]),["keys","values","entries","forEach",Symbol.iterator].includes(t)&&S(n,h.ITERATE);let s=e.size,o=r.apply(e,i);return t==="set"&&g(n,m(i[0],{now:i[1]})),t==="delete"&&g(n,m(i[0],{delete:!0})),s!==e.size&&g(n,m(h.SIZE,{})),(["set","delete","clear"].includes(t)||s!==e.size)&&g(n,m(h.ITERATE,{})),o}}function Ie(e,t,n,r){return(...i)=>{let s=e.length,o=r.apply(n,i);return s!=e.length&&g(n,m(h.LENGTH,{was:s,now:e.length})),o}}function je(e,t,n,r){return(...i)=>{let s=e.size,o=r.apply(e,i);return s!=e.size&&g(n,m(h.SIZE,{was:s,now:e.size})),["set","add","clear","delete"].includes(t)&&g(n,m({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),o}}var Oe={get:(e,t,n)=>{if(t===h.XRAY)return e;if(t===h.SIGNAL)return!0;let r=e?.[t];return S(n,t),typeof r=="function"?Array.isArray(e)?Ie(e,t,n,r):e instanceof Map?Pe(e,t,n,r):e instanceof Set?je(e,t,n,r):e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?r.bind(e):r.bind(n):r&&typeof r=="object"?L(r):r},set:(e,t,n,r)=>{let i=e[t];return i!==n&&(e[t]=n,g(r,m(t,{was:i,now:n}))),typeof i>"u"&&(g(r,m(h.ITERATE,{})),g(r,m(h.LENGTH,{}))),!0},has:(e,t)=>{let n=d.get(e);return n&&S(n,t),Object.hasOwn(e,t)},deleteProperty:(e,t)=>{if(typeof e[t]<"u"){let n=e[t];delete e[t];let r=d.get(e);g(r,m(t,{delete:!0,was:n})),g(r,m(h.ITERATE,{delete:!0,property:t}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let r=d.get(e);g(r,m(h.ITERATE,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=d.get(e);return S(t,h.ITERATE),Reflect.ownKeys(e)}},d=new WeakMap;function L(e={}){if(e===null||typeof e!="object"&&typeof e!="function")throw new TypeError(`simplyflow/state: signal() expects an object, array, Map, Set, class instance, or function; received ${typeof e}`);return e[h.SIGNAL]?e:(d.has(e)||d.set(e,new Proxy(e,Oe)),d.get(e))}var D=[],R=!1;function Ne(e,t){if(typeof e=="function"){R=!0;try{return e()}finally{R=!1}}if(!e||!e[h.SIGNAL])throw new TypeError("simplyflow/state: trace() expects either a function or a signal");return le(e,t).map(r=>({effect:r.effectType,fn:r.effectFunction,signal:d.get(r.effectFunction)}))}function Ce(e){if(!e||typeof e!="object")throw new TypeError("simplyflow/state: addTracer() expects a tracer object");if(!e.get&&!e.set)throw new Error('simply.state: addTracer: missing "get" or "set" property in tracer',e);if(e.get&&typeof e.get!="function")throw new Error('simply.state: addTracer: "get" is not a function',e);if(e.set&&typeof e.set!="function")throw new Error('simply.state: addTracer: "set" is not a function',e);D.push(e)}function se(e,...t){for(let n of D)n[e]&&n[e](...t)}var q=new Set,v=0;function g(e,t=new Map){if(!e||!e[h.SIGNAL])throw new TypeError("simplyflow/state: notifySet() expects a signal as first argument");if(!(t instanceof Map))throw new TypeError("simplyflow/state: notifySet() expects context to be a Map; use makeContext()");let n=[];if(t.forEach((r,i)=>{let s=le(e,i);if(s?.length){for(let o of s)Be(o,m(i,r));n=n.concat(s)}}),n=new Set(n.filter(Boolean)),n)if(v)q=q.union(n);else{let r=y[y.length-1];for(let i of Array.from(n))i!=r&&i?.needsUpdate&&(R&&D.length&&se("set",e,t,i),i()),oe(i)}}function m(e,t){let n=new Map;if(e instanceof Map)return e.forEach((r,i)=>{n.set(i,r)}),n;if(e!==null&&typeof e=="object")for(let r of Reflect.ownKeys(e))n.set(r,e[r]);else n.set(e,t);return n}function Be(e,t){e.context?t.forEach((n,r)=>{e.context.set(r,n)}):e.context=t,e.needsUpdate=!0}function oe(e){delete e.context,delete e.needsUpdate}function S(e,t){let n=y[y.length-1];n&&(R&&D.length&&se("get",e,t),He(e,t,n))}var I=new WeakMap,j=new WeakMap;function le(e,t){let n=I.get(e);return n?Array.from(n.get(t)||[]):[]}function He(e,t,n){I.has(e)||I.set(e,new Map);let r=I.get(e);r.has(t)||r.set(t,new Set),r.get(t).add(n),j.has(n)||j.set(n,new Map);let i=j.get(n);i.has(t)||i.set(t,new Set),i.get(t).add(e)}function G(e){let t=j.get(e);t&&(t.forEach((n,r)=>{n.forEach(i=>{let s=I.get(i);s?.has(r)&&s.get(r).delete(e)})}),j.delete(e))}var y=[],z=[],U=new WeakMap,k=[];function O(e,t){if(typeof e!="function")throw new TypeError(`simplyflow/state: ${t}() expects a function`)}function ae(e){if(O(e,"effect"),z.findIndex(r=>e==r)!==-1)throw new Error("Recursive update() call",{cause:e});z.push(e);let t=d.get(e);t||(t=L({current:null}),d.set(e,t));let n=function r(){if(k.findIndex(s=>s==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});G(r),r.effectFunction=e,r.effectType=ae,y.push(r),k.push(t);let i;try{i=e(r,y,k)}finally{y.pop(),k.pop(),i instanceof Promise?i.then(s=>{t.current=s}):t.current=i}};return n.fn=e,U.set(t,n),n(),t}function F(e){if(!e||!e[h.SIGNAL])throw new TypeError("simplyflow/state: destroy() expects an effect signal");let t=U.get(e);t&&(G(t),t.fn&&d.delete(t.fn),U.delete(e))}function A(e){O(e,"batch"),v++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{v--,v||ie()}):(v--,v||ie())}return t}function ie(){let e=Array.from(q);q=new Set;let t=y[y.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),oe(n)}function E(e,t){if(O(e,"throttledEffect"),!Number.isFinite(t)||t<0)throw new TypeError("simplyflow/state: throttledEffect() expects throttleTime to be a non-negative number");if(z.findIndex(a=>e==a)!==-1)throw new Error("Recursive update() call",{cause:e});z.push(e);let n=d.get(e);n||(n=L({current:null}),d.set(e,n));let r=0,i=!0,s=null;function o(){if(s)return;let a=Math.max(0,r-Date.now());s=globalThis.setTimeout(()=>{s=null,i&&l()},a)}let l=function a(){let u=Date.now();if(r>u){i=!0,o();return}if(k.findIndex(b=>b==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});G(a),a.effectFunction=e,a.effectType=E,y.push(a),k.push(n);let c;try{c=e(a,y,k)}finally{i=!1,y.pop(),k.pop(),c instanceof Promise?c.then(b=>{n.current=b}):n.current=c}r=Date.now()+t,o()};return l(),n}function fe(e,t){if(O(e,"clockEffect"),!t||typeof t!="object"||typeof t.time!="number")throw new TypeError("simplyflow/state: clockEffect() expects a clock object with a numeric .time property");let n=d.get(e);n||(n=L({current:null}),d.set(e,n));let r=-1,i=!0;return function o(){if(r<t.time)if(i){G(o),o.effectFunction=e,o.effectType=fe,y.push(o),r=t.time;let l;try{l=e(o,y)}finally{y.pop(),l instanceof Promise?l.then(a=>{n.current=a}):n.current=l,i=!1}}else r=t.time;else i=!0}(),n}function $(e){O(e,"untracked");let t=y.length-1,n=y[t];y[t]=!1;try{return e()}finally{y[t]=n}}function Re(e,t=!1){let n=new Map,r=function(i){if(n.has(i))return n.get(i);switch(typeof i){case"object":if(!i)return i;if(Array.isArray(i)){let s=[];if(!t)return i.slice();n.set(i,s);for(let o=0;o<i.length;o++)s[o]=r(i[o]);return s}else if(!i.constructor||i.constructor===Object){let s={};i.constructor||(s=Object.create(null)),n.set(i,s);for(let o in i)s[o]=t?r(i[o]):i[o];return s}else return i;break;default:return i}};return r(e)}function ue(e,t){let n=e.value?.innerHTML;typeof e.value=="string"&&(n=e.value,e.value={innerHTML:n}),n&&(n=n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),e.value.innerHTML=n),t(e)}function ce(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var Y={};K(Y,{signal:()=>x,trackDomField:()=>_,trackDomList:()=>X});var pe=new WeakMap,he=new WeakMap,qe={get:(e,t,n)=>{if(t===h.XRAY)return e;if(t===h.SIGNAL)return!0;let r=e?.[t];return S(n,t),typeof r=="function"?r.bind(e):r&&typeof r=="object"?L(r):r},has:(e,t)=>{let n=d.get(e);return n&&S(n,t),Object.hasOwn(e,t)},ownKeys:e=>{let t=d.get(e);return t&&S(t,iterate),Reflect.ownKeys(e)}};function x(e,t){return e[h.XRAY]?e:(d.has(e)||(d.set(e,new Proxy(e,qe)),ze(e,d.get(e),t)),d.get(e))}function ze(e,t,n){n||(n={characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0});let i=e.innerHTML,s=e.innerText;if(!he.has(e)){let o=new MutationObserver((l,a)=>{let u={};for(let c of l)c.type==="attributes"?u[c.attributeName]=c.attributeOldValue:c.type==="subtree"||c.type==="characterData"?(e.innerHTML!=i&&(u.innerHTML=i,i=e.innerHTML),e.innerText!=s&&(u.innerText=s,s=e.innerText)):c.type==="childList"?(u.children={was:Array.from(e.children)},u.length=-1):console.log("nothing to do for",e,c.type);for(let c in u)g(t,m(c,{was:u[c],now:e[c]}))});if(o.observe(e,n),he.set(e,o),e.matches("input, textarea, select")){let l=e.value;e.addEventListener("change",a=>{g(t,m("value",{was:l,now:e.value})),l=e.value}),e.matches("input, textarea")&&e.addEventListener("input",a=>{g(t,m("value",{was:l,now:e.value})),l=e.value})}}}function X(e){let t=this.getBindingPath(e);if(!t)throw new Error("Could not find binding path for element",{cause:e});let n=x(e,{childList:!0});return E(()=>{let r=Array.from(n.children);$(()=>{A(()=>{let i=0,s=N(this.options.root,t),o=s.slice();for(let l of r)l.tagName!=="TEMPLATE"&&l.dataset.flowKey&&(l.dataset.flowKey!=i&&Z(this.options.root,t+"."+i,o[l.dataset.flowKey]),i++);s.length>i&&(s.length=i)})})}),n}function _(e,t,n){if(pe.has(e))return;let r=this.getBindingPath(e);if(!r)throw new Error("Could not find binding path for element",{cause:e});let i=x(e);return pe.set(e,i),A(()=>{E(()=>{let s=i.innerHTML;n||(s=de(i,...t)),$(()=>{Z(this.options.root,r,s)})})}),i}function ye(e){if(e.templates?.length)$e.call(this,e);else if(Object.hasOwnProperty.call(this.options.renderers,e.element.tagName)){let t=this.options.renderers[e.element.tagName];t&&t.call(this,e)}else this.options.renderers["*"]&&this.options.renderers["*"].call(this,e);return e}function ge(e){Array.isArray(e.value)||(e.value=[e.value]);let t=e.value.length;return e.templates?.length?Ge.call(this,e):console.error("No templates found in",e.element),e}function be(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?Fe.call(this,e):console.error("No templates found in",e.element),e}function De(e){if(parseInt(e)==e)return!0}function Z(e,t,n){A(()=>{let r=t.split("."),i=e,s;s=r.shift();let o=null,l=null,a=i;for(;s&&i;){if(a=i,s=decodeURIComponent(s),!(s=="0"&&!Array.isArray(i))){if(s==":key")throw new Error("setting key not yet supported");s==":value"||(Array.isArray(i)&&!De(s)&&typeof i[s]>"u"?(o=i[0],i=i[0][s]):(o=i,i=i[s]))}if(l=s,s=r.shift(),s&&!i){let u=parseInt(s);u>=0&&s===""+u?a[l]=[]:a[l]={},i=a[l]}}if(o&&l&&o[l]!==n)if(n&&typeof n=="object"){i=o[l],i||(o[l]={},i=o[l]);for(let u in n)i[u]!==n[u]&&(i[u]=n[u])}else o[l]=n})}function Ge(e){let t=this.options.attribute,n=[t+"-field",t+"-list",t+"-map"],r="["+n.join("],[")+"]",i=e.element.querySelectorAll(":scope > ["+t+"-key]"),s=0,o=0;e.list=e.value;for(let a of i){let u=parseInt(a.getAttribute(t+"-key"));if(u>s)e.index=s,e.element.insertBefore(this.applyTemplate(e),a);else if(u<s)a.remove();else{let c=Array.from(a.querySelectorAll(r));a.matches(r)&&c.unshift(a);let b=c.find(M=>{for(let f of n){let p=M.getAttribute(f);if(p&&p.substr(0,5)!==":root"&&p.substr(0,e.path.length)!==e.path)return!0}return!1});if(!b&&a[h.TEMPLATE]){let M=this.findTemplate(e.templates,e.list[s]);M!=a[h.TEMPLATE]&&(b=!0,M||o++)}b&&(e.index=s,e.element.replaceChild(this.applyTemplate(e),a))}if(s++,s>=e.value.length)break}i=e.element.querySelectorAll(":scope > ["+t+"-key]");let l=i.length+o;if(l>e.value.length)for(;l>e.value.length;)e.element.querySelectorAll(":scope > :not(template)")?.[l-1]?.remove(),l--;else if(l<e.value.length)for(;l<e.value.length;)e.index=l,e.element.appendChild(this.applyTemplate(e)),l++;this.options.twoway&&X.call(this,e.element)}function Fe(e){let t=this.options.attribute;e.list=e.value;let n=Array.from(e.element.querySelectorAll(":scope > ["+t+"-key]"));for(let r in e.list){e.index=r;let i=n.shift();if(!i){let o=this.applyTemplate(e);e.element.appendChild(o);continue}if(i.getAttribute(t+"-key")!=r){n.unshift(i);let o=e.element.querySelector(":scope > ["+t+'-key="'+r+'"]');if(o)e.element.insertBefore(o,i),i=o,n=n.filter(l=>l!=o);else{let l=this.applyTemplate(e);e.element.insertBefore(l,i);continue}}if(this.findTemplate(e.templates,e.list[e.index])!=i[h.TEMPLATE]){let o=this.applyTemplate(e);e.element.replaceChild(o,i)}}for(;n.length;)n.shift().remove()}function $e(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=Ve(e.element),t)if(n){if(t?.[h.TEMPLATE]!=n){let r=this.applyTemplate(e);e.element.replaceChild(r,t)}}else e.element.removeChild(t);else if(n){let r=this.applyTemplate(e);e.element.appendChild(r)}}function Ve(e,t){let n=e.parentElement?.closest(`[${t}-list],[${t}-map]`);return n?n.hasAttribute(`${t}-list`)?n.getAttribute(`${t}-list`)+".":n.getAttribute(`${t}-map`)+".":""}function Q(e){let t=e.element,n=e.value;C.call(this,e),typeof n>"u"&&(n=""),t.type=="checkbox"||t.type=="radio"?V(t.value,n)?t.checked=!0:t.checked=!1:V(t.value,n)||(t.value=""+n)}function we(e){C.call(this,e,"value")}function J(e){let t=e.element,n=e.value;if(n===null&&(n=""),typeof n!="object")if(t.multiple){if(Array.isArray(n))for(let r of t.options)n.indexOf(r.value)===!1?r.selected=!1:r.selected=!0}else{let r=t.options.find(i=>V(i.value,n));r&&(r.selected=!0,r.setAttribute("selected",!0))}else n.options&&Ke(t,n.options),n.selected&&J(Object.asssign({},e,{value:n.selected})),B(t,n,"name","id","selectedIndex","className")}function me(e,t){t&&(typeof t!="object"?e.options.add(new Option(""+t)):t.text?e.options.add(new Option(t.text,t.value,t.defaultSelected,t.selected)):typeof t.value<"u"&&e.options.add(new Option(""+t.value,t.value,t.defaultSelected,t.selected)))}function Ke(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)me(e,n);else if(t&&typeof t=="object")for(let n in t)me(e,{text:t[n],value:n})}function Ee(e){C.call(this,e,"target","href","name","newwindow","nofollow"),this.options.twoway&&A(()=>{updateProperties.call(this,e,["target","href","name","newwindow","nofollow"])})}function Te(e){B(e.element,e.value,"title","alt","src","id"),this.options.twoway&&A(()=>{updateProperties.call(this,e,["title","alt","src","id"])})}function Ae(e){B(e.element,e.value,"title","src","id"),this.options.twoway&&A(()=>{updateProperties.call(this,e,["title","src","id"])})}function Se(e){B(e.element,e.value,"content","id"),this.options.twoway&&A(()=>{updateProperties.call(this,e,["content","id"])})}function C(e,...t){let n=e.element,r=e.value,i=!1;if(typeof r<"u"&&r!==null){let o=""+r;(typeof r!="object"||o.substring(0,8)!="[object ")&&(r={innerHTML:r},i=!0)}let s=["innerHTML","title","id","className"].concat(t);B(n,r,...s),this.options.twoway&&_.call(this,e.element,s,i)}function B(e,t,...n){if(!(!t||typeof t!="object"))for(let r of n)typeof t[r]>"u"||V(e[r],t[r])||(t[r]===null?e[r]="":e[r]=""+t[r])}function de(e,...t){let n={};for(let r of t)switch(r){default:n[r]=e[r];break}return n}function V(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}var ee=class{constructor(t){this.bindings=new Map;let n={escape_html:ue,fixed_content:ce},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[ye],list:[ge],map:[be]},renderers:{INPUT:Q,TEXTAREA:Q,BUTTON:we,SELECT:J,A:Ee,IMG:Te,IFRAME:Ae,META:Se,TEMPLATE:null,"*":C},twoway:!1};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},r,t),t.transformers&&(this.options.transformers=Object.assign({},n,t?.transformers));let i=this.options.attribute,s=[i+"-field",i+"-list",i+"-map"],o=i+"-transform",l=f=>{let p=s.find(w=>f.hasAttribute(w));return p||console.error("No matching attribute found",f,s),p},a=f=>{this.bindings.set(f,E(()=>{if(!f.isConnected){xe(f,this.getBindingPath(f)),F(this.bindings.get(f));return}let p={templates:f.querySelectorAll(":scope > template"),attribute:l(f)};p.path=this.getBindingPath(f),p.value=N(this.options.root,p.path),p.element=f,We(f,p),u(p)},50))},u=f=>{let p;switch(f.attribute){case this.options.attribute+"-field":p=Array.from(this.options.render.field);break;case this.options.attribute+"-list":p=Array.from(this.options.render.list);break;case this.options.attribute+"-map":p=Array.from(this.options.render.map);break;default:throw new Error("no valid context attribute specified",f)}f.element.hasAttribute(o)&&f.element.getAttribute(o).split(" ").filter(Boolean).forEach(T=>{this.options.transformers[T]?p.push(this.options.transformers[T]):console.warn("No transformer with name "+T+" configured",{cause:f.element})});let w;for(let T of p)w=((P,Le)=>ke=>Le.call(this,ke,P))(w,T);w(f)},c=f=>{for(let p of f)this.bindings.get(p)||a(p)},b=f=>{let p=`[${i}-field],[${i}-list],[${i}-map]`;for(let w of f)if(w.type=="childList"&&w.addedNodes){for(let T of w.addedNodes)if(T instanceof HTMLElement){let P=Array.from(T.querySelectorAll(p));T.matches(p)&&P.unshift(T),P.length&&c(P)}}};this.observer=new MutationObserver(f=>{b(f)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let M=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");M.length&&c(M)}applyTemplate(t){let n=t.path,r=t.parent,i=t.templates,s=t.list,o=t.index,l=s?s[o]:t.value,a=this.findTemplate(i,l);if(!a){let f=new DocumentFragment;return f.innerHTML="<!-- no matching template -->",f}let u=a.content.cloneNode(!0);if(!u.children?.length)return u;if(u.children.length>1)throw new Error("template must contain a single root node",{cause:a});let c=this.options.attribute,b=[c+"-field",c+"-list",c+"-map"],M=u.querySelectorAll(`[${c}-field],[${c}-list],[${c}-map]`);for(let f of M){if(f.tagName=="TEMPLATE")continue;let p=b.find(T=>f.hasAttribute(T)),w=f.getAttribute(p);w=this.applyLinks(a.links,w),w.substring(0,6)==":root."?f.setAttribute(p,w.substring(6)):w==":value"&&o!=null?f.setAttribute(p,n+"."+o):o!=null?f.setAttribute(p,n+"."+o+"."+w):f.setAttribute(p,r+w)}return typeof o<"u"&&u.children[0].setAttribute(c+"-key",o),u.children[0][h.TEMPLATE]=a,u}parseLinks(t){let n={};t=t.split(";").map(r=>r.trim());for(let r of t)r=r.split("="),n[r[0].trim()]=r[1].trim();return n}applyLinks(t,n){for(let r in t){if(n.startsWith(r+"."))return t[r]+n.substr(r.length);if(n==r)return t[r]}return n}getBindingPath(t){let n=[this.options.attribute+"-field",this.options.attribute+"-list",this.options.attribute+"-map"];for(let r of n)if(t.hasAttribute(r))return t.getAttribute(r)}findTemplate(t,n){let r=l=>{let a=this.getBindingPath(l),u;a?a.substr(0,6)==":root."?u=N(this.options.root,a):u=N(n,a):u=n;let c=""+u,b=l.getAttribute(this.options.attribute+"-match");if(b){if(b===":empty"&&!u)return l;if(b===":notempty"&&u||c==b)return l}if(!b)return l},i=Array.from(t).find(r),s=null;i?.hasAttribute(this.options.attribute+"-link")&&(s=this.parseLinks(i.getAttribute(this.options.attribute+"-link")));let o=i?.getAttribute("rel");if(o){let l=document.querySelector("template#"+o);if(!l)throw new Error("Could not find template with id "+o);i=l}return i&&(i.links=s),i}destroy(){this.bindings.forEach(t=>{F(t)}),this.bindings=new Map,this.observer.disconnect()}};function Me(e){return new ee(e)}var H=new Map;function We(e,t){H.has(t.path)?H.get(t.path).push(t):H.set(t.path,[t])}function xe(e,t){let n=H.get(t);n&&(n=n.filter(r=>r.element==e),H.set(t,n))}function N(e,t){let n=t.split("."),r=e,i;i=n.shift();let s=null;for(;i&&r;)i=decodeURIComponent(i),i=="0"&&!Array.isArray(r)||(i==":key"?r=s:i==":value"||(Array.isArray(r)&&typeof r[i]>"u"&&r[0]?r=r[0][i]:r=r[i])),s=i,i=n.shift();return r}var ne={};K(ne,{columns:()=>Qe,filter:()=>Ze,model:()=>Xe,paging:()=>Ye,scroll:()=>Je,sort:()=>_e});var te=class{constructor(t){if(!t)throw new Error("no options set");(t.data==null||typeof t.data[Symbol.iterator]!="function")&&console.warn("SimplyFlowModel: options.data is not iterable"),this.state=L(t),this.state.options||(this.state.options={}),this.effects=[{current:this.state.data}],this.view={current:this.state.data}}addEffect(t){if(!t||typeof t!="function")throw new Error("addEffect requires an effect function as its parameter",{cause:t});let n=this.effects[this.effects.length-1],r=t.call(this,n);if(!r||!r[h.SIGNAL])throw new Error("addEffect function parameter must return a Signal",{cause:t});this.view=r,this.effects.push(this.view)}};function Xe(e){return new te(e)}function _e(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let i=this.state.options.sort,s=i.sortBy;if(!i.sortBy)return 0;let o=i.direction=="asc"?1:-1,l=i.direction=="asc"?-1:1;return typeof n?.[s]>"u"?typeof r?.[s]>"u"?0:o:typeof r?.[s]>"u"||n[s]<r[s]?l:n[s]>r[s]?o:0}},e),E(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?t.current.toSorted(n?.sortFn):t.current},50)}}function Ye(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),E(()=>A(()=>{let n=this.state.options.paging;n.pageSize||(n.pageSize=20),n.max=Math.ceil(this.state.data.length/n.pageSize),n.page=Math.max(1,Math.min(n.max,n.page));let r=(n.page-1)*n.pageSize,i=r+n.pageSize;return t.current.slice(r,i)}),50)}}function Ze(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");return this.state.options[e.name]=e,E(()=>this.state.options[e.name].enabled?t.current.filter(this.state.options[e.name].matches.bind(this)):t.current,50)}}function Qe(e={}){if(!e||typeof e!="object"||Object.keys(e).length===0)throw new Error("columns requires options to be an object with at least one property");return function(t){return this.state.options.columns=e,E(()=>t.current.map(n=>{let r={};for(let i of Object.keys(this.state.options.columns))this.state.options.columns[i]?.hidden||(r[i]=n[i]??null);return r}),50)}}function Je(e){return function(t){this.state.options.scroll=Object.assign({offset:0,rowHeight:26,rowCount:20,itemsPerRow:1,size:t.current.length},e);let n=this.state.options.scroll,r=n.scrollbar||n.container?.querySelector("[data-flow-scrollbar]");return r&&(n.container&&n.container.addEventListener("scroll",i=>{n.offset=Math.floor(n.container.scrollTop/(n.rowHeight*n.itemsPerRow))}),E(()=>{n.size=t.current.length*n.rowHeight,r.style.height=n.size+"px"},50)),E(()=>{n.container&&(n.rowCount=Math.ceil(n.container.getBoundingClientRect().height/n.rowHeight)),n.data=t.current;let i=Math.min(n.offset,t.current.length-1),s=i+n.rowCount;return s>t.current.length&&(s=t.current.length,i=s-n.rowCount),t.current.slice(i,s)},50)}}var re=class extends HTMLElement{constructor(){super()}connectedCallback(){let t=this.getAttribute("rel"),n=document.getElementById(t);if(n){let r=n.content.cloneNode(!0);for(let i of r.childNodes){let s=i.cloneNode(!0);if(s.nodeType==document.ELEMENT_NODE&&(s.querySelectorAll("template").forEach(function(o){o.setAttribute("simply-render","")}),this.attributes))for(let o of this.attributes)o.name!="rel"&&s.setAttribute(o.name,o.value);this.parentNode.insertBefore(s,this)}this.parentNode.removeChild(this)}else(()=>{let i=new MutationObserver(()=>{n=document.getElementById(t),n&&(i.disconnect(),this.replaceWith(this))});i.observe(globalThis.document,{subtree:!0,childList:!0})})()}};customElements.get("simply-render")||customElements.define("simply-render",re);globalThis.simply||(globalThis.simply={});Object.assign(globalThis.simply,{bind:Me,flow:ne,state:W,dom:Y});var Pt=globalThis.simply;})();
2
2
  //# sourceMappingURL=simply.flow.min.js.map