simplyview 3.0.1 → 3.0.2
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.app.js +42 -61
- package/dist/simply.app.min.js +1 -1
- package/dist/simply.app.min.js.map +3 -3
- package/dist/simply.everything.js +42 -61
- package/dist/simply.everything.min.js +1 -1
- package/dist/simply.everything.min.js.map +3 -3
- package/package.json +8 -3
- package/src/bind.mjs +35 -53
- package/src/include.mjs +1 -1
- package/src/include.next.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var Ee=Object.defineProperty;var S=(t,e)=>{for(var n in e)Ee(t,n,{get:e[n],enumerable:!0})};var w=new Map,he={addListener:(t,e)=>{w.has(t)||w.set(t,[]),w.get(t).push(e),Se(t)},removeListener:(t,e)=>{if(!w.has(t))return!1;w.set(t,w.get(t).filter(n=>n!=e))}};function Se(t){let e=document.querySelectorAll('[data-simply-activate="'+t+'"]');if(e)for(let n of e)de(n)}function de(t){let e=t?.dataset?.simplyActivate;if(e&&w.has(e))for(let n of w.get(e))n.call(t)}function Le(t){let e=[];for(let r of t)if(r.type=="childList"){for(let s of r.addedNodes)if(s.querySelectorAll){var n=Array.from(s.querySelectorAll("[data-simply-activate]"));s.matches("[data-simply-activate]")&&n.push(s),e=e.concat(n)}}for(let r of e)de(r)}var Ce=new MutationObserver(Le);Ce.observe(document,{subtree:!0,childList:!0});var U={};S(U,{actions:()=>H});function H(t){if(t.app){let e={get:(n,r)=>n[r].bind(t.app)};return new Proxy(t.actions,e)}else return t}var z={};S(z,{routes:()=>K});function K(t){return new $(t)}var $=class{constructor(e={}){this.root=e.root||"/",this.app=e.app,this.clear(),e.routes&&this.load(e.routes)}load(e){xe(e,this.routeInfo)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},finish:{}}}match(e,n){let r={path:e,options:n};r=this.runListeners("match",r),e=r.path?r.path:e;let s;if(!e)return this.match(document.location.pathname+document.location.hash)?!0:this.match(document.location.pathname);e=k(e);for(let l of this.routeInfo)if(s=l.match.exec(e),s&&s.length){var i={};return l.params.forEach((a,o)=>{a=="*"&&(a="remainder"),i[a]=s[o+1]}),Object.assign(i,n),r.route=l,r.params=i,r=this.runListeners("call",r),i=r.params?r.params:i,r.result=l.action.call(l,i),this.runListeners("finish",r),r.result}return e&&e[e.length-1]!="/"?this.match(e+"/",n):!1}runListeners(e,n){if(Object.keys(this.listeners[e]))return Object.keys(this.listeners[e]).forEach(r=>{var s=me(r);if(s.exec(n.path)){var i;for(let l of this.listeners[e][r])i=l.call(this.app,n),i&&(n=i)}}),n}handleEvents(){globalThis.addEventListener("popstate",()=>{this.match(k(document.location.pathname+document.location.hash,this.root))===!1&&this.match(k(document.location.pathname,this.root))}),globalThis.document.addEventListener("click",e=>{if(!e.ctrlKey&&e.which==1){for(var n=e.target;n&&n.tagName!="A";)n=n.parentElement;if(n&&n.pathname&&n.hostname==globalThis.location.hostname&&!n.link&&!n.dataset.simplyCommand){let r=k(n.pathname+n.hash,this.root);if(this.has(r)||(r=k(n.pathname,this.root)),this.has(r)){let s=this.runListeners("goto",{path:r});return s.path&&this.goto(s.path),e.preventDefault(),!1}}}})}goto(e){return history.pushState({},"",Me(e)),this.match(e)}has(e){e=k(e,this.root);for(let r of this.routeInfo){var n=r.match.exec(e);if(n&&n.length)return!0}return!1}addListener(e,n,r){if(["goto","match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][n]||(this.listeners[e][n]=[]),this.listeners[e][n].push(r)}removeListener(e,n,r){if(["match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][n]&&(this.listeners[e][n]=this.listeners[e][n].filter(s=>s!=r))}init(e){e.root&&(this.root=e.root)}};function k(t,e="/"){return(t.substring(0,e.length)==e||e[e.length-1]=="/"&&t.length==e.length-1&&t==e.substring(0,t.length))&&(t=t.substring(e.length)),t[0]!="/"&&t[0]!="#"&&(t="/"+t),t}function Me(t,e){return t=k(t,e),e[e.length-1]==="/"&&t[0]==="/"&&(t=t.substring(1)),e+t}function me(t){return new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)"))}function xe(t){let e=[],n=Object.keys(t),r=/:(\w+|\*)/g;for(let s of n){let i=[],l=[];do i=r.exec(s),i&&l.push(i[1]);while(i);e.push({match:me(s),params:l,action:t[s]})}return e}var V={};S(V,{commands:()=>D});var F=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),this.$handlers=e.handlers||qe,e.commands&&Object.assign(this,e.commands);let n=r=>{let s=Be(r,this.$handlers);if(!s)return;if(!this[s.name]){console.error("simply.command: undefined command "+s.name,s.source);return}if(this[s.name].call(e.app,s.source,s.value)===!1)return r.preventDefault(),r.stopPropagation(),!1};e.app.container.addEventListener("click",n),e.app.container.addEventListener("submit",n),e.app.container.addEventListener("change",n),e.app.container.addEventListener("input",n)}};function D(t={}){return new F(t)}function Be(t,e){var n=t.target.closest("[data-simply-command]");if(n){for(let r of e)if(n.matches(r.match))return r.check(n,t)?{name:n.dataset.simplyCommand,source:n,value:r.get(n)}:null}return null}var qe=[{match:"input,select,textarea",get:function(t){if(t.tagName==="SELECT"&&t.multiple){let e=[];for(let n of t.options)n.selected&&e.push(n.value);return e}return t.dataset.simplyValue||t.value},check:function(t,e){return e.type=="change"||t.dataset.simplyImmediate&&e.type=="input"}},{match:"a,button",get:function(t){return t.dataset.simplyValue||t.href||t.value},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}},{match:"form",get:function(t){let e={};for(let n of Array.from(t.elements)){if(n.tagName=="INPUT"&&(n.type=="checkbox"||n.type=="radio")&&!n.checked)return;e[n.name]&&!Array.isArray(e[n.name])&&(e[n.name]=[e[n.name]]),Array.isArray(e[n.name])?e[n.name].push(n.value):e[n.name]=n.value}return e},check:function(t,e){return e.type=="submit"}},{match:"*",get:function(t){return t.dataset.simplyValue},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}}];var J={};S(J,{keys:()=>G});var W=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),Object.assign(this,e.keys);let n=r=>{if(r.isComposing||r.keyCode===229||r.defaultPrevented||!r.target)return;let s="default";r.target.closest("[data-simply-keyboard]")&&(s=r.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard);let i="";r.ctrlKey&&r.keyCode!=17&&(i+="Control+"),r.metaKey&&r.keyCode!=224&&(i+="Meta+"),r.altKey&&r.keyCode!=18&&(i+="Alt+"),r.shiftKey&&r.keyCode!=16&&(i+="Shift+"),i+=r.key,this[s]&&this[s][i]&&this[s][i].call(e.app,r)};e.app.container.addEventListener("keydown",n)}};function G(t={}){return new W(t)}var te={};S(te,{batch:()=>_,clockEffect:()=>Ie,destroy:()=>Z,effect:()=>C,signal:()=>b,throttledEffect:()=>ee,untracked:()=>Re});var Q=Symbol("iterate");Symbol.xRay||(Symbol.xRay=Symbol("xRay"));var Ne={get:(t,e,n)=>{if(e===Symbol.xRay)return t;let r=t?.[e];return X(n,e),typeof r=="function"?Array.isArray(t)?(...s)=>{let i=t.length,l=r.apply(n,s);return i!=t.length&&A(n,v("length",{was:i,now:t.length})),l}:t instanceof Set||t instanceof Map?(...s)=>{let i=t.size,l=r.apply(t,s);return i!=t.size&&A(n,v("size",{was:i,now:t.size})),["set","add","clear","delete"].includes(e)&&A(n,v({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),l}:t instanceof HTMLElement||t instanceof Number||t instanceof String||t instanceof Boolean?r.bind(t):r.bind(n):r&&typeof r=="object"?b(r):r},set:(t,e,n,r)=>{n=n?.[Symbol.xRay]||n;let s=t[e];return s!==n&&(t[e]=n,A(r,v(e,{was:s,now:n}))),typeof s>"u"&&A(r,v(Q,{})),!0},has:(t,e)=>{let n=p.get(t);return n&&X(n,e),Object.hasOwn(t,e)},deleteProperty:(t,e)=>{if(typeof t[e]<"u"){let n=t[e];delete t[e];let r=p.get(t);A(r,v(e,{delete:!0,was:n}))}return!0},defineProperty:(t,e,n)=>{if(typeof t[e]>"u"){let r=p.get(t);A(r,v(Q,{}))}return Object.defineProperty(t,e,n)},ownKeys:t=>{let e=p.get(t);return X(e,Q),Reflect.ownKeys(t)}},p=new WeakMap;function b(t){return p.has(t)||p.set(t,new Proxy(t,Ne)),p.get(t)}var O=new Set,L=0;function A(t,e={}){let n=[];if(e.forEach((r,s)=>{let i=Pe(t,s);if(i?.length){for(let l of i)Oe(l,v(s,r));n=n.concat(i)}}),n=new Set(n.filter(Boolean)),n)if(L)O=O.union(n);else{let r=d[d.length-1];for(let s of Array.from(n))s!=r&&s?.needsUpdate&&s(),ge(s)}}function v(t,e){let n=new Map;if(typeof t=="object")for(let r in t)n.set(r,t[r]);else n.set(t,e);return n}function Oe(t,e){t.context?e.forEach((n,r)=>{t.context.set(r,n)}):t.context=e,t.needsUpdate=!0}function ge(t){delete t.context,delete t.needsUpdate}function X(t,e){let n=d[d.length-1];n&&je(t,e,n)}var B=new WeakMap,N=new WeakMap;function Pe(t,e){let n=B.get(t);return n?Array.from(n.get(e)||[]):[]}function je(t,e,n){B.has(t)||B.set(t,new Map);let r=B.get(t);r.has(e)||r.set(e,new Set),r.get(e).add(n),N.has(n)||N.set(n,new Map);let s=N.get(n);s.has(e)||s.set(e,new Set),s.get(e).add(t)}function j(t){let e=N.get(t);e&&e.forEach(n=>{n.forEach(r=>{let s=B.get(r);s.has(n)&&s.get(n).delete(t)})})}var d=[],P=[],Y=new WeakMap,T=[];function C(t){if(P.findIndex(r=>t==r)!==-1)throw new Error("Recursive update() call",{cause:t});P.push(t);let e=p.get(t);e||(e=b({current:null}),p.set(t,e));let n=function r(){if(T.findIndex(i=>i==e)!==-1)throw new Error("Cyclical dependency in update() call",{cause:t});j(r),d.push(r),T.push(e);let s;try{s=t(r,d,T)}finally{d.pop(),T.pop(),s instanceof Promise?s.then(i=>{e.current=i}):e.current=s}};return n.fn=t,Y.set(e,n),n(),e}function Z(t){let e=Y.get(t)?.deref();if(!e)return;j(e);let n=e.fn;p.remove(n),Y.delete(t)}function _(t){L++;let e;try{e=t()}finally{e instanceof Promise?e.then(()=>{L--,L||pe()}):(L--,L||pe())}return e}function pe(){let t=Array.from(O);O=new Set;let e=d[d.length-1];for(let n of t)n!=e&&n?.needsUpdate&&n(),ge(n)}function ee(t,e){if(P.findIndex(l=>t==l)!==-1)throw new Error("Recursive update() call",{cause:t});P.push(t);let n=p.get(t);n||(n=b({current:null}),p.set(t,n));let r=!1,s=!0;return function l(){if(T.findIndex(o=>o==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:t});if(r&&r>Date.now()){s=!0;return}j(l),d.push(l),T.push(n);let a;try{a=t(l,d,T)}finally{s=!1,d.pop(),T.pop(),a instanceof Promise?a.then(o=>{n.current=o}):n.current=a}r=Date.now()+e,globalThis.setTimeout(()=>{s&&l()},e)}(),n}function Ie(t,e){let n=p.get(t);n||(n=b({current:null}),p.set(t,n));let r=-1,s=!0;return function l(){if(r<e.time)if(s){j(l),d.push(l),r=e.time;let a;try{a=t(l,d)}finally{d.pop(),a instanceof Promise?a.then(o=>{n.current=o}):n.current=a,s=!1}}else r=e.time;else s=!0}(),n}function Re(t){let e=d.slice();d=[];try{return t()}finally{d=e}}var re=class{constructor(e){this.bindings=new Map;let n={container:document.body,attribute:"data-bind",transformers:[],defaultTransformers:[He]};if(!e?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},n,e);let r=this.options.attribute,s=u=>{this.bindings.set(u,ee(()=>{let f={templates:u.querySelectorAll(":scope > template"),path:this.getBindingPath(u)};f.value=ne(this.options.root,f.path),f.element=u,i(f)},100))},i=u=>{let f=this.options.defaultTransformers||[];u.element.dataset.transform&&u.element.dataset.transform.split(" ").filter(Boolean).forEach(h=>{this.options.transformers[h]?f.push(this.options.transformers[h]):console.warn("No transformer with name "+h+" configured",{cause:u.element})});let c;for(let h of f)c=((m,y)=>g=>y.call(this,g,m))(c,h);c(u)},l=u=>{for(let f of u)s(f)},a=u=>{for(let f of u)if(f.type=="childList"&&f.addedNodes){for(let c of f.addedNodes)if(c instanceof HTMLElement){let h=Array.from(c.querySelectorAll(`[${r}]`));c.matches(`[${r}]`)&&h.unshift(c),h.length&&l(h)}}};this.observer=new MutationObserver(u=>{a(u)}),this.observer.observe(e.container,{subtree:!0,childList:!0});let o=this.options.container.querySelectorAll("["+this.options.attribute+"]:not(template)");o.length&&l(o)}applyTemplate(e){let n=e.path,r=e.templates,s=e.list,i=e.index,l=e.parent,a=s?s[i]:e.value,o=this.findTemplate(r,a);if(!o){let h=new DocumentFragment;return h.innerHTML="<!-- no matching template -->",h}let u=o.content.cloneNode(!0);if(!u.children?.length)throw new Error("template must contain a single html element",{cause:o});if(u.children.length>1)throw new Error("template must contain a single root node",{cause:o});let f=u.querySelectorAll("["+this.options.attribute+"]"),c=this.options.attribute;for(let h of f){let m=h.getAttribute(c);m.substring(0,6)=="#root."?h.setAttribute(c,m.substring(6)):m=="#value"&&i!=null?h.setAttribute(c,n+"."+i):i!=null?h.setAttribute(c,n+"."+i+"."+m):h.setAttribute(c,l+"."+m)}return typeof i<"u"&&u.children[0].setAttribute(c+"-key",i),u.children[0].$bindTemplate=o,u}getBindingPath(e){return e.getAttribute(this.options.attribute)}findTemplate(e,n){let r=l=>{let a=this.getBindingPath(l),o;a?a.substr(0,6)=="#root."?o=ne(this.options.root,a):o=ne(n,a):o=n;let u=""+o,f=l.getAttribute(this.options.attribute+"-match");if(f){if(f==="#empty"&&!o)return l;if(f==="#notempty"&&o||u.match(f))return l}if(!f&&o)return l},s=Array.from(e).find(r),i=s?.getAttribute("rel");if(i){let l=document.querySelector("template#"+i);if(!l)throw new Error("Could not find template with id "+i);s=l}return s}destroy(){this.bindings.forEach(e=>{Z(e)}),this.bindings=new Map,this.observer.disconnect()}};function I(t){return new re(t)}function E(t,e){return t=="#empty"&&!e||e=="#empty"&&!t||""+t==""+e}function ne(t,e){let n=e.split("."),r=t,s,i;for(;n.length&&r;){if(s=n.shift(),s=="#key")return i;if(s=="#value")return r;s=="#root"?r=t:(s=decodeURIComponent(s),r=r[s],i=s)}return r}function He(t){let e=t.element,n=t.templates,r=n.length,s=t.path,i=t.value,l=this.options.attribute;return Array.isArray(i)&&n?.length?Ue.call(this,t):typeof i=="object"&&n?.length?$e.call(this,t):n?.length?Ke.call(this,t):e.tagName=="INPUT"?ze.call(this,t):e.tagName=="BUTTON"?Fe.call(this,t):e.tagName=="SELECT"?De.call(this,t):e.tagName=="A"?Ve.call(this,t):We.call(this,t),t}function Ue(t){let e=t.element,n=t.templates,r=n.length,s=t.path,i=t.value,l=this.options.attribute,a=e.querySelectorAll(":scope > ["+l+"-key]"),o=0,u=0;t.list=i;for(let c of a){let h=parseInt(c.getAttribute(l+"-key"));if(h>o)t.index=o,e.insertBefore(this.applyTemplate(t),c);else if(h<o)c.remove();else{let m=Array.from(c.querySelectorAll(`[${l}]`));c.matches(`[${l}]`)&&m.unshift(c);let y=m.find(g=>{let x=g.getAttribute(l);return x.substr(0,5)!=="#root"&&x.substr(0,s.length)!==s});if(!y&&c.$bindTemplate){let g=this.findTemplate(n,i[o]);g!=c.$bindTemplate&&(y=!0,g||u++)}y&&(t.index=o,e.replaceChild(this.applyTemplate(t),c))}if(o++,o>=i.length)break}a=e.querySelectorAll(":scope > ["+l+"-key]");let f=a.length+u;if(f>i.length)for(;f>i.length;)e.querySelectorAll(":scope > :not(template)")?.[f-1]?.remove(),f--;else if(f<i.length)for(;f<i.length;)t.index=f,e.appendChild(this.applyTemplate(t)),f++}function $e(t){let e=t.element,n=t.templates,r=n.length,s=t.path,i=t.value,l=this.options.attribute;t.list=i;let a=Object.entries(i),o=e.querySelectorAll(":scope > ["+l+"-key]"),u=0,f=0;for(let h of o){if(u>=a.length)break;let m=a[u][0];u++;let y=s+"."+m,g,x=h.getAttribute(l);if(x&&x.substr(0,y.length)!=y)g=!0;else if(g=Array.from(h.querySelectorAll(`[${l}]`)).find(q=>{let ue=q.getAttribute(l);return ue.substr(0,5)!=="#root"&&ue.substr(0,y.length)!==y}),!g&&h.$bindTemplate){let q=this.findTemplate(n,i[m]);q!=h.$bindTemplate&&(g=!0,q||f++)}if(g){t.index=m;let fe=this.applyTemplate(t);e.replaceChild(fe,h)}}o=e.querySelectorAll(":scope > ["+l+"-key]");let c=o.length+f;if(c>a.length)for(;c>a.length;)e.querySelectorAll(":scope > :not(template)")?.[c-1]?.remove(),c--;else if(c<a.length)for(;c<a.length;)t.index=a[c][0],e.appendChild(this.applyTemplate(t)),c++}function Ke(t){let e=t.element,n=t.templates,r=t.value,s=this.options.attribute,i=e.querySelector(":scope > :not(template)"),l=this.findTemplate(n,r);if(t.parent=e.parentElement?.closest(`[${s}]`)?.getAttribute(s)||"#root",i)if(l){if(i?.$bindTemplate!=l){let a=this.applyTemplate(t);e.replaceChild(a,i)}}else e.removeChild(i);else if(l){let a=this.applyTemplate(t);e.appendChild(a)}}function ze(t){let e=t.element,n=t.value;e.type=="checkbox"||e.type=="radio"?E(e.value,n)?e.checked=!0:e.checked=!1:E(e.value,n)||(e.value=""+n)}function Fe(t){let e=t.element,n=t.value;E(e.value,n)||(e.value=""+n)}function De(t){let e=t.element,n=t.value;if(e.multiple){if(Array.isArray(n))for(let r of e.options)n.indexOf(r.value)===!1?r.selected=!1:r.selected=!0}else{let r=e.options.find(s=>E(s.value,n));r&&(r.selected=!0)}}function Ve(t){let e=t.element,n=t.value;n?.innerHTML&&!E(e.innerHTML,n.innerHTML)&&(e.innerHTML=""+n.innerHTML),n?.href&&!E(e.href,n.href)&&(e.href=""+n.href)}function We(t){let e=t.element,n=t.value;E(e.innerHTML,n)||(e.innerHTML=""+n)}var se=class{constructor(e={}){this.container=e.container||document.body,e.state||(e.state={}),this.state=b(e.state),e.commands&&(this.commands=D({app:this,container:this.container,commands:e.commands})),e.keys&&(this.keys=G({app:this,keys:e.keys})),e.routes&&(this.routes=K({app:this,routes:e.routes})),e.actions&&(this.actions=H({app:this,actions:e.actions}));let n={container:this.container,root:this.state};e.defaultTransformers&&(n.defaultTransformers=e.defaultTransformers),e.transformers&&(n.transformers=e.transformers),this.bind=I(n)}};function ye(t={}){return new se(t)}function Ge(t,e){let n=0;return()=>{let r=arguments;n||(n=globalThis.setTimeout(()=>{t.apply(this,r),n=0},e))}}var Je=globalThis.requestIdleCallback?t=>{globalThis.requestIdleCallback(t,{timeout:500})}:globalThis.requestAnimationFrame;function ie(t,e){let n=new URL(t,e);return M.cacheBuster&&n.searchParams.set("cb",M.cacheBuster),n.href}var be,Qe={},le=globalThis.document.querySelector("head"),we=globalThis.document.currentScript,ve,ae;we?ae=we.src:(ve=(()=>{var t=document.getElementsByTagName("script"),e=t.length-1,n=t[e];return()=>n.src})(),ae=ve());var Xe=async()=>new Promise(function(t){var e=globalThis.document.createElement("script");e.src=ie("simply.include.next.js",ae),e.async=!1,globalThis.document.addEventListener("simply-include-next",()=>{le.removeChild(e),t()},{once:!0,passive:!0}),le.appendChild(e)}),R=[],M={cacheBuster:null,scripts:(t,e)=>{let n=t.slice(),r=()=>{let s=n.shift();if(!s)return;let i=[].map.call(s.attributes,a=>a.name),l=globalThis.document.createElement("script");for(let a of i)l.setAttribute(a,s.getAttribute(a));if(l.removeAttribute("data-simply-location"),!l.src)l.innerHTML=s.innerHTML,Xe().then(()=>{let a=R[s.dataset.simplyLocation];a.parentNode.insertBefore(l,a),a.parentNode.removeChild(a),r()});else{l.src=ie(l.src,e),!l.hasAttribute("async")&&!l.hasAttribute("defer")&&(l.async=!1);let a=R[s.dataset.simplyLocation];a.parentNode.insertBefore(l,a),a.parentNode.removeChild(a),Qe[l.src]=!0,r()}};n.length&&r()},html:(t,e)=>{let n=globalThis.document.createRange().createContextualFragment(t),r=n.querySelectorAll('link[rel="stylesheet"],style');for(let l of r)l.href&&(l.href=ie(l.href,e.href)),le.appendChild(l);let s=globalThis.document.createDocumentFragment(),i=n.querySelectorAll("script");for(let l of i){let a=globalThis.document.createComment(l.src||"inline script");l.parentNode.insertBefore(a,l),l.dataset.simplyLocation=R.length,R.push(a),s.appendChild(l)}e.parentNode.insertBefore(n,e||null),globalThis.setTimeout(function(){M.scripts(s.childNodes,e?e.href:globalThis.location.href)},10)}},Te={},Ye=async t=>{let e=[].reduce.call(t,(n,r)=>(r.rel=="simply-include-once"&&Te[r.href]?r.parentNode.removeChild(r):(Te[r.href]=!0,r.rel="simply-include-loading",n.push(r)),n),[]);for(let n of e){if(!n.href)return;let r=await fetch(n.href);if(!r.ok){console.log("simply-include: failed to load "+n.href);continue}console.log("simply-include: loaded "+n.href);let s=await r.text();M.html(s,n),n.parentNode.removeChild(n)}},ke=Ge(()=>{Je(()=>{var t=globalThis.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');t.length&&Ye(t)})}),Ze=()=>{be=new MutationObserver(ke),be.observe(globalThis.document,{subtree:!0,childList:!0})};Ze();ke();var ce={};S(ce,{columns:()=>rt,filter:()=>nt,model:()=>_e,paging:()=>tt,sort:()=>et});var oe=class{constructor(e){this.state=b(e),this.state.options||(this.state.options={}),this.effects=[{current:e.data}],this.view=b(e.data)}addEffect(e){let n=this.effects[this.effects.length-1];this.view=e.call(this,n),this.effects.push(this.view)}};function _e(t){return new oe(t)}function et(t={}){return function(e){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let s=this.state.options.sort,i=s.sortBy;if(!s.sortBy)return 0;let l=s.direction=="asc"?1:-1,a=s.direction=="asc"?-1:1;return typeof n?.[i]>"u"?typeof r?.[i]>"u"?0:l:typeof r?.[i]>"u"||n[i]<r[i]?a:n[i]>r[i]?l:0}},t),C(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?e.current.toSorted(n?.sortFn):e.current})}}function tt(t={}){return function(e){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},t),C(()=>_(()=>{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,s=r+n.pageSize;return e.current.slice(r,s)}))}}function nt(t){if(!t?.name||typeof t.name!="string")throw new Error("filter requires options.name to be a string");if(!t.matches||typeof t.matches!="function")throw new Error("filter requires options.matches to be a function");return function(e){return this.state.options[t.name]=t,C(()=>{if(this.state.options[t.name].enabled)return e.filter(this.state.options.matches)})}}function rt(t={}){if(!t||typeof t!="object"||Object.keys(t).length===0)throw new Error("columns requires options to be an object with at least one property");return function(e){return this.state.options.columns=t,C(()=>e.current.map(n=>{let r={};for(let s of Object.keys(this.state.options.columns))this.state.options.columns[s].hidden||(r[s]=n[s]);return r}))}}var Ae={activate:he,action:U,app:ye,bind:I,command:V,include:M,key:J,model:ce,route:z,state:te};window.simply=Ae;var Tt=Ae;})();
|
|
1
|
+
(()=>{var Te=Object.defineProperty;var A=(t,e)=>{for(var n in e)Te(t,n,{get:e[n],enumerable:!0})};var y=new Map,ae={addListener:(t,e)=>{y.has(t)||y.set(t,[]),y.get(t).push(e),ke(t)},removeListener:(t,e)=>{if(!y.has(t))return!1;y.set(t,y.get(t).filter(n=>n!=e))}};function ke(t){let e=document.querySelectorAll('[data-simply-activate="'+t+'"]');if(e)for(let n of e)oe(n)}function oe(t){let e=t?.dataset?.simplyActivate;if(e&&y.has(e))for(let n of y.get(e))n.call(t)}function Ee(t){let e=[];for(let r of t)if(r.type=="childList"){for(let s of r.addedNodes)if(s.querySelectorAll){var n=Array.from(s.querySelectorAll("[data-simply-activate]"));s.matches("[data-simply-activate]")&&n.push(s),e=e.concat(n)}}for(let r of e)oe(r)}var Ae=new MutationObserver(Ee);Ae.observe(document,{subtree:!0,childList:!0});var H={};A(H,{actions:()=>j});function j(t){if(t.app){let e={get:(n,r)=>n[r].bind(t.app)};return new Proxy(t.actions,e)}else return t}var K={};A(K,{routes:()=>U});function U(t){return new R(t)}var R=class{constructor(e={}){this.root=e.root||"/",this.app=e.app,this.clear(),e.routes&&this.load(e.routes)}load(e){Se(e,this.routeInfo)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},finish:{}}}match(e,n){let r={path:e,options:n};r=this.runListeners("match",r),e=r.path?r.path:e;let s;if(!e)return this.match(document.location.pathname+document.location.hash)?!0:this.match(document.location.pathname);e=v(e);for(let l of this.routeInfo)if(s=l.match.exec(e),s&&s.length){var i={};return l.params.forEach((a,o)=>{a=="*"&&(a="remainder"),i[a]=s[o+1]}),Object.assign(i,n),r.route=l,r.params=i,r=this.runListeners("call",r),i=r.params?r.params:i,r.result=l.action.call(l,i),this.runListeners("finish",r),r.result}return e&&e[e.length-1]!="/"?this.match(e+"/",n):!1}runListeners(e,n){if(Object.keys(this.listeners[e]))return Object.keys(this.listeners[e]).forEach(r=>{var s=ce(r);if(s.exec(n.path)){var i;for(let l of this.listeners[e][r])i=l.call(this.app,n),i&&(n=i)}}),n}handleEvents(){globalThis.addEventListener("popstate",()=>{this.match(v(document.location.pathname+document.location.hash,this.root))===!1&&this.match(v(document.location.pathname,this.root))}),globalThis.document.addEventListener("click",e=>{if(!e.ctrlKey&&e.which==1){for(var n=e.target;n&&n.tagName!="A";)n=n.parentElement;if(n&&n.pathname&&n.hostname==globalThis.location.hostname&&!n.link&&!n.dataset.simplyCommand){let r=v(n.pathname+n.hash,this.root);if(this.has(r)||(r=v(n.pathname,this.root)),this.has(r)){let s=this.runListeners("goto",{path:r});return s.path&&this.goto(s.path),e.preventDefault(),!1}}}})}goto(e){return history.pushState({},"",Le(e)),this.match(e)}has(e){e=v(e,this.root);for(let r of this.routeInfo){var n=r.match.exec(e);if(n&&n.length)return!0}return!1}addListener(e,n,r){if(["goto","match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][n]||(this.listeners[e][n]=[]),this.listeners[e][n].push(r)}removeListener(e,n,r){if(["match","call","finish"].indexOf(e)==-1)throw new Error("Unknown action "+e);this.listeners[e][n]&&(this.listeners[e][n]=this.listeners[e][n].filter(s=>s!=r))}init(e){e.root&&(this.root=e.root)}};function v(t,e="/"){return(t.substring(0,e.length)==e||e[e.length-1]=="/"&&t.length==e.length-1&&t==e.substring(0,t.length))&&(t=t.substring(e.length)),t[0]!="/"&&t[0]!="#"&&(t="/"+t),t}function Le(t,e){return t=v(t,e),e[e.length-1]==="/"&&t[0]==="/"&&(t=t.substring(1)),e+t}function ce(t){return new RegExp("^"+t.replace(/:\w+/g,"([^/]+)").replace(/:\*/,"(.*)"))}function Se(t){let e=[],n=Object.keys(t),r=/:(\w+|\*)/g;for(let s of n){let i=[],l=[];do i=r.exec(s),i&&l.push(i[1]);while(i);e.push({match:ce(s),params:l,action:t[s]})}return e}var F={};A(F,{commands:()=>z});var $=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),this.$handlers=e.handlers||Me,e.commands&&Object.assign(this,e.commands);let n=r=>{let s=Ce(r,this.$handlers);if(!s)return;if(!this[s.name]){console.error("simply.command: undefined command "+s.name,s.source);return}if(this[s.name].call(e.app,s.source,s.value)===!1)return r.preventDefault(),r.stopPropagation(),!1};e.app.container.addEventListener("click",n),e.app.container.addEventListener("submit",n),e.app.container.addEventListener("change",n),e.app.container.addEventListener("input",n)}};function z(t={}){return new $(t)}function Ce(t,e){var n=t.target.closest("[data-simply-command]");if(n){for(let r of e)if(n.matches(r.match))return r.check(n,t)?{name:n.dataset.simplyCommand,source:n,value:r.get(n)}:null}return null}var Me=[{match:"input,select,textarea",get:function(t){if(t.tagName==="SELECT"&&t.multiple){let e=[];for(let n of t.options)n.selected&&e.push(n.value);return e}return t.dataset.simplyValue||t.value},check:function(t,e){return e.type=="change"||t.dataset.simplyImmediate&&e.type=="input"}},{match:"a,button",get:function(t){return t.dataset.simplyValue||t.href||t.value},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}},{match:"form",get:function(t){let e={};for(let n of Array.from(t.elements)){if(n.tagName=="INPUT"&&(n.type=="checkbox"||n.type=="radio")&&!n.checked)return;e[n.name]&&!Array.isArray(e[n.name])&&(e[n.name]=[e[n.name]]),Array.isArray(e[n.name])?e[n.name].push(n.value):e[n.name]=n.value}return e},check:function(t,e){return e.type=="submit"}},{match:"*",get:function(t){return t.dataset.simplyValue},check:function(t,e){return e.type=="click"&&e.ctrlKey==!1&&e.button==0}}];var W={};A(W,{keys:()=>V});var D=class{constructor(e={}){e.app||(e.app={}),e.app.container||(e.app.container=document.body),Object.assign(this,e.keys);let n=r=>{if(r.isComposing||r.keyCode===229||r.defaultPrevented||!r.target)return;let s="default";r.target.closest("[data-simply-keyboard]")&&(s=r.target.closest("[data-simply-keyboard]").dataset.simplyKeyboard);let i="";r.ctrlKey&&r.keyCode!=17&&(i+="Control+"),r.metaKey&&r.keyCode!=224&&(i+="Meta+"),r.altKey&&r.keyCode!=18&&(i+="Alt+"),r.shiftKey&&r.keyCode!=16&&(i+="Shift+"),i+=r.key,this[s]&&this[s][i]&&this[s][i].call(e.app,r)};e.app.container.addEventListener("keydown",n)}};function V(t={}){return new D(t)}var _={};A(_,{batch:()=>Y,clockEffect:()=>qe,destroy:()=>X,effect:()=>S,signal:()=>g,throttledEffect:()=>Z,untracked:()=>Pe});var G=Symbol("iterate");Symbol.xRay||(Symbol.xRay=Symbol("xRay"));var xe={get:(t,e,n)=>{if(e===Symbol.xRay)return t;let r=t?.[e];return J(n,e),typeof r=="function"?Array.isArray(t)?(...s)=>{let i=t.length,l=r.apply(n,s);return i!=t.length&&T(n,b("length",{was:i,now:t.length})),l}:t instanceof Set||t instanceof Map?(...s)=>{let i=t.size,l=r.apply(t,s);return i!=t.size&&T(n,b("size",{was:i,now:t.size})),["set","add","clear","delete"].includes(e)&&T(n,b({entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}})),l}:t instanceof HTMLElement||t instanceof Number||t instanceof String||t instanceof Boolean?r.bind(t):r.bind(n):r&&typeof r=="object"?g(r):r},set:(t,e,n,r)=>{n=n?.[Symbol.xRay]||n;let s=t[e];return s!==n&&(t[e]=n,T(r,b(e,{was:s,now:n}))),typeof s>"u"&&T(r,b(G,{})),!0},has:(t,e)=>{let n=d.get(t);return n&&J(n,e),Object.hasOwn(t,e)},deleteProperty:(t,e)=>{if(typeof t[e]<"u"){let n=t[e];delete t[e];let r=d.get(t);T(r,b(e,{delete:!0,was:n}))}return!0},defineProperty:(t,e,n)=>{if(typeof t[e]>"u"){let r=d.get(t);T(r,b(G,{}))}return Object.defineProperty(t,e,n)},ownKeys:t=>{let e=d.get(t);return J(e,G),Reflect.ownKeys(t)}},d=new WeakMap;function g(t){return d.has(t)||d.set(t,new Proxy(t,xe)),d.get(t)}var N=new Set,L=0;function T(t,e={}){let n=[];if(e.forEach((r,s)=>{let i=Ne(t,s);if(i?.length){for(let l of i)Be(l,b(s,r));n=n.concat(i)}}),n=new Set(n.filter(Boolean)),n)if(L)N=N.union(n);else{let r=m[m.length-1];for(let s of Array.from(n))s!=r&&s?.needsUpdate&&s(),ue(s)}}function b(t,e){let n=new Map;if(typeof t=="object")for(let r in t)n.set(r,t[r]);else n.set(t,e);return n}function Be(t,e){t.context?e.forEach((n,r)=>{t.context.set(r,n)}):t.context=e,t.needsUpdate=!0}function ue(t){delete t.context,delete t.needsUpdate}function J(t,e){let n=m[m.length-1];n&&Oe(t,e,n)}var x=new WeakMap,B=new WeakMap;function Ne(t,e){let n=x.get(t);return n?Array.from(n.get(e)||[]):[]}function Oe(t,e,n){x.has(t)||x.set(t,new Map);let r=x.get(t);r.has(e)||r.set(e,new Set),r.get(e).add(n),B.has(n)||B.set(n,new Map);let s=B.get(n);s.has(e)||s.set(e,new Set),s.get(e).add(t)}function q(t){let e=B.get(t);e&&e.forEach(n=>{n.forEach(r=>{let s=x.get(r);s.has(n)&&s.get(n).delete(t)})})}var m=[],O=[],Q=new WeakMap,w=[];function S(t){if(O.findIndex(r=>t==r)!==-1)throw new Error("Recursive update() call",{cause:t});O.push(t);let e=d.get(t);e||(e=g({current:null}),d.set(t,e));let n=function r(){if(w.findIndex(i=>i==e)!==-1)throw new Error("Cyclical dependency in update() call",{cause:t});q(r),m.push(r),w.push(e);let s;try{s=t(r,m,w)}finally{m.pop(),w.pop(),s instanceof Promise?s.then(i=>{e.current=i}):e.current=s}};return n.fn=t,Q.set(e,n),n(),e}function X(t){let e=Q.get(t)?.deref();if(!e)return;q(e);let n=e.fn;d.remove(n),Q.delete(t)}function Y(t){L++;let e;try{e=t()}finally{e instanceof Promise?e.then(()=>{L--,L||fe()}):(L--,L||fe())}return e}function fe(){let t=Array.from(N);N=new Set;let e=m[m.length-1];for(let n of t)n!=e&&n?.needsUpdate&&n(),ue(n)}function Z(t,e){if(O.findIndex(l=>t==l)!==-1)throw new Error("Recursive update() call",{cause:t});O.push(t);let n=d.get(t);n||(n=g({current:null}),d.set(t,n));let r=!1,s=!0;return function l(){if(w.findIndex(o=>o==n)!==-1)throw new Error("Cyclical dependency in update() call",{cause:t});if(r&&r>Date.now()){s=!0;return}q(l),m.push(l),w.push(n);let a;try{a=t(l,m,w)}finally{s=!1,m.pop(),w.pop(),a instanceof Promise?a.then(o=>{n.current=o}):n.current=a}r=Date.now()+e,globalThis.setTimeout(()=>{s&&l()},e)}(),n}function qe(t,e){let n=d.get(t);n||(n=g({current:null}),d.set(t,n));let r=-1,s=!0;return function l(){if(r<e.time)if(s){q(l),m.push(l),r=e.time;let a;try{a=t(l,m)}finally{m.pop(),a instanceof Promise?a.then(o=>{n.current=o}):n.current=a,s=!1}}else r=e.time;else s=!0}(),n}function Pe(t){let e=m.slice();m=[];try{return t()}finally{m=e}}var te=class{constructor(e){this.bindings=new Map;let n={container:document.body,attribute:"data-bind",transformers:[],defaultTransformers:[Ie]};if(!e?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},n,e);let r=this.options.attribute,s=c=>{this.bindings.set(c,Z(()=>{let u={templates:c.querySelectorAll(":scope > template"),path:this.getBindingPath(c)};u.value=ee(this.options.root,u.path),u.element=c,i(u)},100))},i=c=>{let u=this.options.defaultTransformers||[];c.element.dataset.transform&&c.element.dataset.transform.split(" ").filter(Boolean).forEach(h=>{this.options.transformers[h]?u.push(this.options.transformers[h]):console.warn("No transformer with name "+h+" configured",{cause:c.element})});let f;for(let h of u)f=((p,M)=>E=>M.call(this,E,p))(f,h);f(c)},l=c=>{for(let u of c)s(u)},a=c=>{for(let u of c)if(u.type=="childList"&&u.addedNodes){for(let f of u.addedNodes)if(f instanceof HTMLElement){let h=Array.from(f.querySelectorAll(`[${r}]`));f.matches(`[${r}]`)&&h.unshift(f),h.length&&l(h)}}};this.observer=new MutationObserver(c=>{a(c)}),this.observer.observe(e.container,{subtree:!0,childList:!0});let o=this.options.container.querySelectorAll("["+this.options.attribute+"]:not(template)");o.length&&l(o)}applyTemplate(e){let n=e.path,r=e.templates,s=e.list,i=e.index,l=e.parent,a=s?s[i]:e.value,o=this.findTemplate(r,a);if(!o){let h=new DocumentFragment;return h.innerHTML="<!-- no matching template -->",h}let c=o.content.cloneNode(!0);if(!c.children?.length)throw new Error("template must contain a single html element",{cause:o});if(c.children.length>1)throw new Error("template must contain a single root node",{cause:o});let u=c.querySelectorAll("["+this.options.attribute+"]"),f=this.options.attribute;for(let h of u){let p=h.getAttribute(f);p.substring(0,6)=="#root."?h.setAttribute(f,p.substring(6)):p=="#value"&&i!=null?h.setAttribute(f,n+"."+i):i!=null?h.setAttribute(f,n+"."+i+"."+p):h.setAttribute(f,l+"."+p)}return typeof i<"u"&&c.children[0].setAttribute(f+"-key",i),c.children[0].$bindTemplate=o,c}getBindingPath(e){return e.getAttribute(this.options.attribute)}findTemplate(e,n){let r=l=>{let a=this.getBindingPath(l),o;a?a.substr(0,6)=="#root."?o=ee(this.options.root,a):o=ee(n,a):o=n;let c=""+o,u=l.getAttribute(this.options.attribute+"-match");if(u){if(u==="#empty"&&!o)return l;if(u==="#notempty"&&o||c.match(u))return l}if(!u)return l},s=Array.from(e).find(r),i=s?.getAttribute("rel");if(i){let l=document.querySelector("template#"+i);if(!l)throw new Error("Could not find template with id "+i);s=l}return s}destroy(){this.bindings.forEach(e=>{X(e)}),this.bindings=new Map,this.observer.disconnect()}};function P(t){return new te(t)}function k(t,e){return t=="#empty"&&!e||e=="#empty"&&!t||""+t==""+e}function ee(t,e){let n=e.split("."),r=t,s,i;for(;n.length&&r;){if(s=n.shift(),s=="#key")return i;if(s=="#value")return r;s=="#root"?r=t:(s=decodeURIComponent(s),r=r[s],i=s)}return r}function Ie(t){let e=t.element,n=t.templates,r=n.length,s=t.path,i=t.value,l=this.options.attribute;return Array.isArray(i)&&n?.length?je.call(this,t):typeof i=="object"&&n?.length?He.call(this,t):n?.length?Re.call(this,t):e.tagName=="INPUT"?Ue.call(this,t):e.tagName=="BUTTON"?Ke.call(this,t):e.tagName=="SELECT"?$e.call(this,t):e.tagName=="A"?ze.call(this,t):Fe.call(this,t),t}function je(t){let e=t.element,n=t.templates,r=n.length,s=t.path,i=t.value,l=this.options.attribute,a=e.querySelectorAll(":scope > ["+l+"-key]"),o=0,c=0;t.list=i;for(let f of a){let h=parseInt(f.getAttribute(l+"-key"));if(h>o)t.index=o,e.insertBefore(this.applyTemplate(t),f);else if(h<o)f.remove();else{let p=Array.from(f.querySelectorAll(`[${l}]`));f.matches(`[${l}]`)&&p.unshift(f);let M=p.find(E=>{let le=E.getAttribute(l);return le.substr(0,5)!=="#root"&&le.substr(0,s.length)!==s});if(!M&&f.$bindTemplate){let E=this.findTemplate(n,i[o]);E!=f.$bindTemplate&&(M=!0,E||c++)}M&&(t.index=o,e.replaceChild(this.applyTemplate(t),f))}if(o++,o>=i.length)break}a=e.querySelectorAll(":scope > ["+l+"-key]");let u=a.length+c;if(u>i.length)for(;u>i.length;)e.querySelectorAll(":scope > :not(template)")?.[u-1]?.remove(),u--;else if(u<i.length)for(;u<i.length;)t.index=u,e.appendChild(this.applyTemplate(t)),u++}function He(t){let e=t.element,n=t.templates,r=n.length,s=t.path,i=t.value,l=this.options.attribute;t.list=i;let a=Array.from(e.querySelectorAll(":scope > ["+l+"-key]"));for(let o in t.list){t.index=o;let c=a.shift();if(!c){e.appendChild(this.applyTemplate(t));continue}if(c.getAttribute[l+"-key"]!=o){a.unshift(c);let f=e.querySelector(":scope > ["+l+'-key="'+o+'"]');if(f)e.insertBefore(f,c),c=f,a=a.filter(h=>h!=f);else{let h=this.applyTemplate(t);h.firstElementChild&&e.insertBefore(h,c);continue}}if(this.findTemplate(n,i[o])!=c.$bindTemplate){let f=this.applyTemplate(t);e.replaceChild(f,c)}}for(;a.length;)item=a.shift(),item.remove()}function Re(t){let e=t.element,n=t.templates,r=t.value,s=this.options.attribute,i=e.querySelector(":scope > :not(template)"),l=this.findTemplate(n,r);if(t.parent=e.parentElement?.closest(`[${s}]`)?.getAttribute(s)||"#root",i)if(l){if(i?.$bindTemplate!=l){let a=this.applyTemplate(t);e.replaceChild(a,i)}}else e.removeChild(i);else if(l){let a=this.applyTemplate(t);e.appendChild(a)}}function Ue(t){let e=t.element,n=t.value;e.type=="checkbox"||e.type=="radio"?k(e.value,n)?e.checked=!0:e.checked=!1:k(e.value,n)||(e.value=""+n)}function Ke(t){let e=t.element,n=t.value;k(e.value,n)||(e.value=""+n)}function $e(t){let e=t.element,n=t.value;if(e.multiple){if(Array.isArray(n))for(let r of e.options)n.indexOf(r.value)===!1?r.selected=!1:r.selected=!0}else{let r=e.options.find(s=>k(s.value,n));r&&(r.selected=!0)}}function ze(t){let e=t.element,n=t.value;n?.innerHTML&&!k(e.innerHTML,n.innerHTML)&&(e.innerHTML=""+n.innerHTML),n?.href&&!k(e.href,n.href)&&(e.href=""+n.href)}function Fe(t){let e=t.element,n=t.value;k(e.innerHTML,n)||(typeof n>"u"||n==null?e.innerHTML="":e.innerHTML=""+n)}var ne=class{constructor(e={}){this.container=e.container||document.body,e.state||(e.state={}),this.state=g(e.state),e.commands&&(this.commands=z({app:this,container:this.container,commands:e.commands})),e.keys&&(this.keys=V({app:this,keys:e.keys})),e.routes&&(this.routes=U({app:this,routes:e.routes})),e.actions&&(this.actions=j({app:this,actions:e.actions}));let n={container:this.container,root:this.state};e.defaultTransformers&&(n.defaultTransformers=e.defaultTransformers),e.transformers&&(n.transformers=e.transformers),this.bind=P(n)}};function he(t={}){return new ne(t)}function De(t,e){let n=0;return()=>{let r=arguments;n||(n=globalThis.setTimeout(()=>{t.apply(this,r),n=0},e))}}var Ve=globalThis.requestIdleCallback?t=>{globalThis.requestIdleCallback(t,{timeout:500})}:globalThis.requestAnimationFrame;function me(t,e){let n=new URL(t,e);return C.cacheBuster&&n.searchParams.set("cb",C.cacheBuster),n.href}var de,We={},re=globalThis.document.querySelector("head"),pe=globalThis.document.currentScript,ge,ye;pe?ye=pe.src:(ge=(()=>{var t=document.getElementsByTagName("script"),e=t.length-1,n=t[e];return()=>n.src})(),ye=ge());var Ge=async()=>new Promise(function(t){var e=globalThis.document.createElement("script");e.src="javascript:document.dispatchEvent(new Event('simply-include-next'))",e.async=!1,globalThis.document.addEventListener("simply-include-next",()=>{re.removeChild(e),t()},{once:!0,passive:!0}),re.appendChild(e)}),I=[],C={cacheBuster:null,scripts:(t,e)=>{let n=t.slice(),r=()=>{let s=n.shift();if(!s)return;let i=[].map.call(s.attributes,a=>a.name),l=globalThis.document.createElement("script");for(let a of i)l.setAttribute(a,s.getAttribute(a));if(l.removeAttribute("data-simply-location"),!l.src)l.innerHTML=s.innerHTML,Ge().then(()=>{let a=I[s.dataset.simplyLocation];a.parentNode.insertBefore(l,a),a.parentNode.removeChild(a),r()});else{l.src=me(l.src,e),!l.hasAttribute("async")&&!l.hasAttribute("defer")&&(l.async=!1);let a=I[s.dataset.simplyLocation];a.parentNode.insertBefore(l,a),a.parentNode.removeChild(a),We[l.src]=!0,r()}};n.length&&r()},html:(t,e)=>{let n=globalThis.document.createRange().createContextualFragment(t),r=n.querySelectorAll('link[rel="stylesheet"],style');for(let l of r)l.href&&(l.href=me(l.href,e.href)),re.appendChild(l);let s=globalThis.document.createDocumentFragment(),i=n.querySelectorAll("script");for(let l of i){let a=globalThis.document.createComment(l.src||"inline script");l.parentNode.insertBefore(a,l),l.dataset.simplyLocation=I.length,I.push(a),s.appendChild(l)}e.parentNode.insertBefore(n,e||null),globalThis.setTimeout(function(){C.scripts(s.childNodes,e?e.href:globalThis.location.href)},10)}},be={},Je=async t=>{let e=[].reduce.call(t,(n,r)=>(r.rel=="simply-include-once"&&be[r.href]?r.parentNode.removeChild(r):(be[r.href]=!0,r.rel="simply-include-loading",n.push(r)),n),[]);for(let n of e){if(!n.href)return;let r=await fetch(n.href);if(!r.ok){console.log("simply-include: failed to load "+n.href);continue}console.log("simply-include: loaded "+n.href);let s=await r.text();C.html(s,n),n.parentNode.removeChild(n)}},we=De(()=>{Ve(()=>{var t=globalThis.document.querySelectorAll('link[rel="simply-include"],link[rel="simply-include-once"]');t.length&&Je(t)})}),Qe=()=>{de=new MutationObserver(we),de.observe(globalThis.document,{subtree:!0,childList:!0})};Qe();we();var ie={};A(ie,{columns:()=>et,filter:()=>_e,model:()=>Xe,paging:()=>Ze,sort:()=>Ye});var se=class{constructor(e){this.state=g(e),this.state.options||(this.state.options={}),this.effects=[{current:e.data}],this.view=g(e.data)}addEffect(e){let n=this.effects[this.effects.length-1];this.view=e.call(this,n),this.effects.push(this.view)}};function Xe(t){return new se(t)}function Ye(t={}){return function(e){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let s=this.state.options.sort,i=s.sortBy;if(!s.sortBy)return 0;let l=s.direction=="asc"?1:-1,a=s.direction=="asc"?-1:1;return typeof n?.[i]>"u"?typeof r?.[i]>"u"?0:l:typeof r?.[i]>"u"||n[i]<r[i]?a:n[i]>r[i]?l:0}},t),S(()=>{let n=this.state.options.sort;return n?.sortBy&&n?.direction?e.current.toSorted(n?.sortFn):e.current})}}function Ze(t={}){return function(e){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},t),S(()=>Y(()=>{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,s=r+n.pageSize;return e.current.slice(r,s)}))}}function _e(t){if(!t?.name||typeof t.name!="string")throw new Error("filter requires options.name to be a string");if(!t.matches||typeof t.matches!="function")throw new Error("filter requires options.matches to be a function");return function(e){return this.state.options[t.name]=t,S(()=>{if(this.state.options[t.name].enabled)return e.filter(this.state.options.matches)})}}function et(t={}){if(!t||typeof t!="object"||Object.keys(t).length===0)throw new Error("columns requires options to be an object with at least one property");return function(e){return this.state.options.columns=t,S(()=>e.current.map(n=>{let r={};for(let s of Object.keys(this.state.options.columns))this.state.options.columns[s].hidden||(r[s]=n[s]);return r}))}}var ve={activate:ae,action:H,app:he,bind:P,command:F,include:C,key:W,model:ie,route:K,state:_};window.simply=ve;var bt=ve;})();
|
|
2
2
|
//# sourceMappingURL=simply.everything.min.js.map
|