simplyflow 0.8.1 → 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.
- package/dist/simply.flow.js +272 -152
- package/dist/simply.flow.min.js +1 -1
- package/dist/simply.flow.min.js.map +4 -4
- package/package.json +1 -1
- package/src/bind.mjs +3 -5
- package/src/bind.render.mjs +21 -64
- package/src/dom.mjs +107 -6
- package/src/edit/anchor.mjs +130 -0
- package/src/edit/toolbars.mjs +315 -0
- package/src/edit.mjs +168 -83
- package/src/model.mjs +2 -1
- package/src/state.mjs +205 -95
- package/src/symbols.mjs +8 -0
package/dist/simply.flow.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var Ee=Object.defineProperty;var W=(e,t)=>{for(var n in t)Ee(e,n,{get:t[n],enumerable:!0})};var _={};W(_,{addTracer:()=>Me,batch:()=>T,clockEffect:()=>ie,clone:()=>Ce,destroy:()=>K,effect:()=>re,makeContext:()=>y,notifyGet:()=>v,notifySet:()=>g,signal:()=>A,signals:()=>h,throttledEffect:()=>b,trace:()=>ke,untracked:()=>V});Symbol.iterate||(Symbol.iterate=Symbol("iterate"));Symbol.xRay||(Symbol.xRay=Symbol("xRay"));Symbol.Signal||(Symbol.Signal=Symbol("Signal"));var ve={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"?A(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=h.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=h.get(e);g(r,y(t,{delete:!0,was:n}))}return!0},defineProperty:(e,t,n)=>{if(typeof e[t]>"u"){let r=h.get(e);g(r,y(Symbol.iterate,{}))}return Object.defineProperty(e,t,n)},ownKeys:e=>{let t=h.get(e);return v(t,Symbol.iterate),Reflect.ownKeys(e)}},h=new WeakMap;function A(e){return e||(e={}),e[Symbol.Signal]?e:(h.has(e)||h.set(e,new Proxy(e,ve)),h.get(e))}var z=[],I=!1;function ke(e,t){if(typeof e=="function")I=!0,e(),I=!1;else return ne(e,t).map(r=>({effect:r.effectType,fn:r.effectFunction,signal:h.get(r.effectFunction)}))}function Me(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);z.push(e)}function ee(e,...t){for(let n of z)n[e]&&n[e](...t)}var q=new Set,k=0;function g(e,t={}){let n=[];if(t.forEach((r,i)=>{let s=ne(e,i);if(s?.length){for(let o of s)Le(o,y(i,r));n=n.concat(s)}}),n=new Set(n.filter(Boolean)),n)if(k)q=q.union(n);else{let r=d[d.length-1];for(let i of Array.from(n))i!=r&&i?.needsUpdate&&(I&&z.length&&ee("set",e,t,i),i()),te(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 Le(e,t){e.context?t.forEach((n,r)=>{e.context.set(r,n)}):e.context=t,e.needsUpdate=!0}function te(e){delete e.context,delete e.needsUpdate}function v(e,t){let n=d[d.length-1];n&&(I&&z.length&&ee("get",e,t),Oe(e,t,n))}var L=new WeakMap,H=new WeakMap;function ne(e,t){let n=L.get(e);return n?Array.from(n.get(t)||[]):[]}function Oe(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),H.has(n)||H.set(n,new Map);let i=H.get(n);i.has(t)||i.set(t,new Set),i.get(t).add(e)}function $(e){let t=H.get(e);t&&t.forEach(n=>{n.forEach(r=>{let i=L.get(r);i.has(n)&&i.get(n).delete(e)})})}var d=[],R=[],D=new WeakMap,E=[];function re(e){if(R.findIndex(r=>e==r)!==-1)throw new Error("Recursive update() call",{cause:e});R.push(e);let t=h.get(e);t||(t=A({current:null}),h.set(e,t));let n=function r(){if(E.findIndex(s=>s==t)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});$(r),r.effectFunction=e,r.effectType=re,d.push(r),E.push(t);let i;try{i=e(r,d,E)}finally{d.pop(),E.pop(),i instanceof Promise?i.then(s=>{t.current=s}):t.current=i}};return n.fn=e,D.set(t,n),n(),t}function K(e){let t=D.get(e)?.deref();if(!t)return;$(t);let n=t.fn;h.remove(n),D.delete(e)}function T(e){k++;let t;try{t=e()}finally{t instanceof Promise?t.then(()=>{k--,k||x()}):(k--,k||x())}return t}function x(){let e=Array.from(q);q=new Set;let t=d[d.length-1];for(let n of e)n!=t&&n?.needsUpdate&&n(),te(n)}function b(e,t){if(R.findIndex(o=>e==o)!==-1)throw new Error("Recursive update() call",{cause:e});R.push(e);let n=h.get(e);n||(n=A({current:null}),h.set(e,n));let r=!1,i=!0;return function o(){if(E.findIndex(c=>c==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:e});if(r&&r>Date.now()){i=!0;return}$(o),o.effectFunction=e,o.effectType=b,d.push(o),E.push(n);let l;try{l=e(o,d,E)}finally{i=!1,d.pop(),E.pop(),l instanceof Promise?l.then(c=>{n.current=c}):n.current=l}r=Date.now()+t,globalThis.setTimeout(()=>{i&&o()},t)}(),n}function ie(e,t){let n=h.get(e);n||(n=A({current:null}),h.set(e,n));let r=-1,i=!0;return function o(){if(r<t.time)if(i){$(o),o.effectFunction=e,o.effectType=ie,d.push(o),r=t.time;let l;try{l=e(o,d)}finally{d.pop(),l instanceof Promise?l.then(c=>{n.current=c}):n.current=l,i=!1}}else r=t.time;else i=!0}(),n}function V(e){let t=d.length-1,n=d[t];d[t]=!1;try{return e()}finally{d[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 se(e,t){let n=e.value?.innerHTML;typeof e.value=="string"&&(n=e.value,e.value={innerHTML:n}),n&&(n=n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),e.value.innerHTML=n),t(e)}function oe(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var G={};W(G,{signal:()=>F});var 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"?A(r):r},has:(e,t)=>{let n=h.get(e);return n&&v(n,t),Object.hasOwn(e,t)},ownKeys:e=>{let t=h.get(e);return t&&v(t,iterate),Reflect.ownKeys(e)}};function F(e,t){return e[Symbol.xRay]?e:(h.has(e)||(h.set(e,new Proxy(e,je)),Be(e,h.get(e),t)),h.get(e))}var le=new WeakMap;function Be(e,t,n){n||(n={characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0});let i=e.innerHTML,s=e.innerText;if(!le.has(e)){let o=new MutationObserver((l,c)=>{let a={};for(let u of l)u.type==="attributes"?a[u.attributeName]=u.attributeOldValue:u.type==="subtree"||u.type==="characterData"?(e.innerHTML!=i&&(a.innerHTML=i,i=e.innerHTML),e.innerText!=s&&(a.innerText=s,s=e.innerText)):u.type==="childList"?(a.children={was:Array.from(e.children)},a.length=-1):console.log("nothing to do for",e,u.type);for(let u in a)g(t,y(u,{was:a[u],now:e[u]}))});if(o.observe(e,n),le.set(e,o),e.matches("input, textarea, select")){let l=e.value;e.addEventListener("change",c=>{g(t,y("value",{was:l,now:e.value})),l=e.value}),e.matches("input, textarea")&&e.addEventListener("input",c=>{g(t,y("value",{was:l,now:e.value})),l=e.value})}}}function ue(e){if(e.templates?.length)Ie.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 ce(e){Array.isArray(e.value)||(e.value=[e.value]);let t=e.value.length;return e.templates?.length?Ne.call(this,e):console.error("No templates found in",e.element),e}function pe(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?He.call(this,e):console.error("No templates found in",e.element),e}function Pe(e){if(parseInt(e)==e)return!0}function he(e,t,n){T(()=>{let r=t.split("."),i=e,s;s=r.shift();let o=null,l=null,c=i;for(;s&&i;){if(c=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)&&!Pe(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 a=parseInt(s);a>=0&&s===""+a?c[l]=[]:c[l]={},i=c[l]}}if(o&&l&&o[l]!==n)if(n&&typeof n=="object"){i=o[l],i||(o[l]={},i=o[l]);for(let a in n)i[a]!==n[a]&&(i[a]=n[a])}else o[l]=n})}function Ne(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 c=Array.from(o.querySelectorAll(`[${t}]`));o.matches(`[${t}]`)&&c.unshift(o);let a=c.find(u=>{let w=u.getAttribute(t);return w.substr(0,5)!==":root"&&w.substr(0,e.path.length)!==e.path});if(!a&&o[Symbol.bindTemplate]){let u=this.findTemplate(e.templates,e.list[r]);u!=o[Symbol.bindTemplate]&&(a=!0,u||i++)}a&&(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++;if(this.options.twoway){let o=F(e.element,{childList:!0});b(()=>{let l=Array.from(o.children);T(()=>{V(()=>{let c=0,a=e.value.slice();for(let u of l)u.tagName!=="TEMPLATE"&&u.dataset.flowKey&&(u.dataset.flowKey!=c&&he(this.options.root,e.path+"."+c,a[u.dataset.flowKey]),c++);if(e.value.length>c){let u=B(this.options.root,e.path);u.length=c}})})})}}function He(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 Ie(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=qe(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 qe(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 de(e){let t=e.element,n=e.value;O.call(this,e),typeof n>"u"&&(n=""),t.type=="checkbox"||t.type=="radio"?U(t.value,n)?t.checked=!0:t.checked=!1:U(t.value,n)||(t.value=""+n)}function me(e){O.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=>U(i.value,n));r&&(r.selected=!0,r.setAttribute("selected",!0))}else n.options&&Re(t,n.options),n.selected&&J(Object.asssign({},e,{value:n.selected})),j(t,n,"name","id","selectedIndex","className")}function ae(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 Re(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)ae(e,n);else if(t&&typeof t=="object")for(let n in t)ae(e,{text:t[n],value:n})}function ye(e){O.call(this,e,"target","href","name","newwindow","nofollow"),this.options.twoway&&T(()=>{C.call(this,e,["target","href","name","newwindow","nofollow"])})}function be(e){j(e.element,e.value,"title","alt","src","id"),this.options.twoway&&T(()=>{C.call(this,e,["title","alt","src","id"])})}function ge(e){j(e.element,e.value,"title","src","id"),this.options.twoway&&T(()=>{C.call(this,e,["title","src","id"])})}function we(e){j(e.element,e.value,"content","id"),this.options.twoway&&T(()=>{C.call(this,e,["content","id"])})}var fe=new WeakMap;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);j(n,r,...s),this.options.twoway&&T(()=>{C.call(this,e,s,i)})}function C(e,t,n){if(fe.has(e.element))return;let r=F(e.element);fe.set(e.element,r),b(()=>{let i=r.innerHTML;n||(i=ze(r,...t)),V(()=>{he(this.options.root,e.path,i)})})}function j(e,t,...n){if(!(!t||typeof t!="object"))for(let r of n)typeof t[r]>"u"||U(e[r],t[r])||(t[r]===null?e[r]="":e[r]=""+t[r])}function ze(e,...t){let n={};for(let r of t)switch(r){default:n[r]=e[r];break}return n}function U(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}Symbol.bindTemplate||(Symbol.bindTemplate=Symbol("bindTemplate"));var Q=class{constructor(t){this.bindings=new Map;let n={escape_html:se,fixed_content:oe},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[ue],list:[ce],map:[pe]},renderers:{INPUT:de,BUTTON:me,SELECT:J,A:ye,IMG:be,IFRAME:ge,META:we,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=f=>{let p=s.find(m=>f.hasAttribute(m));return p||console.error("No matching attribute found",f,s),p},c=f=>{this.bindings.set(f,b(()=>{if(!f.isConnected){Ve(f,this.getBindingPath(f)),K(this.bindings.get(f));return}let p={templates:f.querySelectorAll(":scope > template"),attribute:l(f)};p.path=this.getBindingPath(f),p.value=B(this.options.root,p.path),p.element=f,Ke(f,p),a(p)},50))},a=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(S=>{this.options.transformers[S]?p.push(this.options.transformers[S]):console.warn("No transformer with name "+S+" configured",{cause:f.element})});let m;for(let S of p)m=((M,Te)=>Ae=>Te.call(this,Ae,M))(m,S);m(f)},u=f=>{for(let p of f)this.bindings.get(p)||c(p)},w=f=>{let p=`[${i}-field],[${i}-list],[${i}-map]`;for(let m of f)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&&u(M)}}};this.observer=new MutationObserver(f=>{w(f)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let N=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");N.length&&u(N)}applyTemplate(t){let n=t.path,r=t.parent,i=t.templates,s=t.list,o=t.index,l=s?s[o]:t.value,c=this.findTemplate(i,l);if(!c){let f=new DocumentFragment;return f.innerHTML="<!-- no matching template -->",f}let a=c.content.cloneNode(!0);if(!a.children?.length)return a;if(a.children.length>1)throw new Error("template must contain a single root node",{cause:c});let u=this.options.attribute,w=[u+"-field",u+"-list",u+"-map"],N=a.querySelectorAll(`[${u}-field],[${u}-list],[${u}-map]`);for(let f of N){if(f.tagName=="TEMPLATE")continue;let p=w.find(S=>f.hasAttribute(S)),m=f.getAttribute(p);m=this.applyLinks(c.links,m),m.substring(0,6)==":root."?f.setAttribute(p,m.substring(6)):m==":value"&&o!=null?f.setAttribute(p,n+"."+o):o!=null?f.setAttribute(p,n+"."+o+"."+m):f.setAttribute(p,r+m)}return typeof o<"u"&&a.children[0].setAttribute(u+"-key",o),a.children[0][Symbol.bindTemplate]=c,a}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 c=this.getBindingPath(l),a;c?c.substr(0,6)==":root."?a=B(this.options.root,c):a=B(n,c):a=n;let u=""+a,w=l.getAttribute(this.options.attribute+"-match");if(w){if(w===":empty"&&!a)return l;if(w===":notempty"&&a||u==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=>{K(t)}),this.bindings=new Map,this.observer.disconnect()}};function Se(e){return new Q(e)}var P=new Map;function Ke(e,t){P.has(t.path)?P.get(t.path).push(t):P.set(t.path,[t])}function Ve(e,t){let n=P.get(t);n&&(n=n.filter(r=>r.element==e),P.set(t,n))}function B(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 Y={};W(Y,{columns:()=>_e,filter:()=>De,model:()=>Fe,paging:()=>We,scroll:()=>Ge,sort:()=>Ue});var X=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=A(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 Fe(e){return new X(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 De(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 _e(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 Ge(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 Z=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",Z);globalThis.simply||(globalThis.simply={});Object.assign(globalThis.simply,{bind:Se,flow:Y,state:_,dom:G});var ft=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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),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
|