@joystick.js/ui-canary 0.0.0-canary.6 → 0.0.0-canary.8

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 +1 @@
1
- var i=(e="",o={})=>{throw new Error(`[joystick${e?`.${e}`:""}] ${o.message||o.reason||o}`)};var p=(e={})=>{try{return Object.entries(e).map(([o,n])=>{let[s,...t]=o.split(" ");return{type:s.toLowerCase(),selector:t.join(" "),handler:n}})}catch(o){i("component.events.serialize",o)}};var h=(e={},o={},n=[])=>{try{let s=Object.keys(e?.events||{})?.length>0?p(e?.events):[];for(let t=0;t<s?.length;t+=1){let r=s[t];n.push({...r,instance:e,elements:document.querySelectorAll(`body [js-i="${e.instanceId}"] ${r?.selector}`),handler:function(c){Object.defineProperty(c,"target",{value:c.composedPath()[0]}),r.handler(c,{...e||{},setState:e?.setState.bind(e),...o||{}})}})}if(e?.children){let t=Object.entries(e?.children)?.flatMap(([r,l])=>l);for(let r=0;r<t?.length;r+=1){let l=t[r];h(l,o,n)}}return n}catch(s){i("component.events.registerListenersFix.getListeners",s)}},d=(e={},o={})=>{try{let n=h(e,o,[]);console.log("GETTING CALLED",n);let s=n?.flatMap((t={})=>[].flatMap.call(t?.elements||[],r=>{let{elements:l=[],...c}=t||{};return{...c,element:r}}));for(let t=0;t<s?.length;t+=1){let{instance:r,element:l,elementSelector:c,type:a,handler:m}=s[t];console.log({element:l,type:a,handler:m}),l.addEventListener(a,m),r._eventListeners=[...r?._eventListeners||[],{instance:r,element:l,elementSelector:c,type:a,handler:m}]}}catch(n){i("component.events.registerListenersFix",n)}},y=d;export{y as default};
1
+ var i=(e="",o={})=>{throw new Error(`[joystick${e?`.${e}`:""}] ${o.message||o.reason||o}`)};var p=(e={})=>{try{return Object.entries(e).map(([o,n])=>{let[s,...t]=o.split(" ");return{type:s.toLowerCase(),selector:t.join(" "),handler:n}})}catch(o){i("component.events.serialize",o)}};var h=(e={},o={},n=[])=>{try{let s=Object.keys(e?.events||{})?.length>0?p(e?.events):[];for(let t=0;t<s?.length;t+=1){let r=s[t];n.push({...r,instance:e,elements:document.querySelectorAll(`body [js-i="${e.instanceId}"] ${r?.selector}`),handler:function(c){console.log("DOM EVENT",c),Object.defineProperty(c,"target",{value:c.composedPath()[0]}),r.handler(c,{...e||{},setState:e?.setState.bind(e),...o||{}})}})}if(e?.children){let t=Object.entries(e?.children)?.flatMap(([r,l])=>l);for(let r=0;r<t?.length;r+=1){let l=t[r];h(l,o,n)}}return n}catch(s){i("component.events.registerListenersFix.getListeners",s)}},d=(e={},o={})=>{try{let n=h(e,o,[]);console.log("GETTING CALLED",n);let s=n?.flatMap((t={})=>[].flatMap.call(t?.elements||[],r=>{let{elements:l=[],...c}=t||{};return{...c,element:r}}));for(let t=0;t<s?.length;t+=1){let{instance:r,element:l,elementSelector:c,type:a,handler:m}=s[t];console.log({element:l,type:a,handler:m}),l.addEventListener(a,m),r._eventListeners=[...r?._eventListeners||[],{instance:r,element:l,elementSelector:c,type:a,handler:m}]}}catch(n){i("component.events.registerListenersFix",n)}},L=d;export{L as default};
@@ -18,4 +18,4 @@ var Kt=Object.create;var oe=Object.defineProperty;var Wt=Object.getOwnPropertyDe
18
18
  @media screen and (max-height: ${v}px) {
19
19
  ${typeof f=="function"?f(e):f}
20
20
  }
21
- `}}return r}return""}catch(r){n("component.css.compileCSS",r)}};var ir=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.state.compile.compileState",r)}},G=(t={},e={})=>{try{return m(e)?ir(t,e):Object.assign({},e)}catch(r){n("component.state.compile",r)}};var ie={onBeforeMount:()=>null,onMount:()=>null,onBeforeUnmount:()=>null,onUpdateProps:()=>null,onRefetchData:()=>null};var st=(t={},e={})=>{try{return e?Object.entries({...ie,...e||{}}).reduce((r={},[o,i])=>(r[o]=()=>i({...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{}):ie}catch(r){n("component.lifecycle.compile",r)}};var K=(t={},e={})=>{try{return Object.entries(e).reduce((r={},[o,i])=>(r[o]=(...s)=>i(...s,{...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{})}catch{n("component.methods.compile")}};var ne=(t={})=>{try{return{...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window!="undefined"){let o=new URL(window.location);o.searchParams.append(e,r),window.history.pushState({},"",o)}},unset:(e="")=>{if(typeof window!="undefined"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},isActive:(e="")=>C(e)&&t?.route!=="*"?e===(typeof location!="undefined"?location.pathname:t.path):!1}}catch(e){n("component.url.compile",e)}};var S=()=>typeof window=="undefined";var I=null,W=0,at=(t={},e=null)=>{try{let r=t?.url;t?.query&&(r=`${r}?${new URLSearchParams(t.query).toString()}`);let o=new WebSocket(r);I&&(clearInterval(I),I=null);let i={client:o,send:(s={})=>o.send(JSON.stringify(s))};return o.addEventListener("open",()=>{t?.options?.logging&&console.log(`[joystick.websockets] Connected to ${t?.url}`),t?.events?.onOpen&&t.events.onOpen(i),W=0}),o.addEventListener("message",s=>{s?.data&&t?.events?.onMessage&&t.events.onMessage(JSON.parse(s.data||{}),i)}),o.addEventListener("close",s=>{t?.options?.logging&&console.log(`[joystick.websockets] Disconnected from ${t?.url}`),t?.events?.onClose&&t.events.onClose(s?.code,s?.reason,i),o=null;let d=[1e3,1001].includes(s?.code);t?.options?.autoReconnect&&!I&&!d&&(I=setInterval(()=>{o=null,W<(t?.options?.reconnectAttempts||12)?(at(t,e),t?.options?.logging&&console.log(`[joystick.websockets] Attempting to reconnect (${W+1}/12)...`),W+=1):clearInterval(I)},t?.options?.reconnectDelayInSeconds*1e3||5e3))}),e&&e(i),i}catch(r){n("websockets.client",r)}},dt=at;var nr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.props.compileDefaultProps.compile",r)}},ct=(t={},e={})=>{try{return m(e)?nr(t,e):Object.assign({},e)}catch(r){n("component.props.compileDefaultProps",r)}};var lt=(t={},e={})=>{try{t.options=e||{},t.id=e?._componentId||null,t.instanceId=U(8),t.ssrId=e?._ssrId||null,t.css=nt(),t.data=B(e?.dataFromSSR,e?._componentId),t.defaultProps=ct(t,e?.defaultProps),t.props=it(t?.defaultProps,e?.props),t.state=G(t,e?.state),t.events=e?.events||{},t.lifecycle=st(t,e?.lifecycle),t.methods=K(t,e?.methods),t.wrapper=e?.wrapper||{},t.translations=e?.translations||{},t.validateForm=ot,t.DOMNode=null,t.dom={},t.dom.virtual={},t.dom.actual={};let r=!S();if(r||(t.url=ne(e?.url)),r&&window.__joystick_url__&&(t.url=ne(window.__joystick_url__)),r&&e?.websockets&&m(e?.websockets)){let o=e.websockets(t),i=u(o)&&Object.entries(o);for(let s=0;s<i?.length;s+=1){let[d,a]=i[s];dt({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/${d}`,options:a?.options||{},query:a?.query||{},events:a?.events||{}},(l={})=>{t.websockets={...t.websockets||{},[d]:l}})}}}catch(r){n("component.registerOptions",r)}};var _=(t="",e=[])=>{try{console.error(`${t} failed with the following errors:`),e.forEach(r=>{console.log(r.message),r.stack&&console.log(r.stack)})}catch(r){n(t,r)}};var J=(t="{}")=>{try{return JSON.parse(t)}catch{return t}};var sr=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.get.handleParseResponse",e)}},mt=(t="",e={})=>{try{return typeof window.fetch!="undefined"&&!e?.skip?new Promise((r,o)=>{let i=e.input?JSON.stringify(e.input):null,s=e.output?JSON.stringify(e.output):null,d=`${window.location.origin}/api/_getters/${t}?input=${i}&output=${s}`,a=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(d,{method:"GET",mode:"cors",headers:{...e?.headers||{},"x-joystick-csrf":a},credentials:"include"}).then(async l=>{let g=await sr(l);return g?.errors?(_("get request",g.errors),o(g)):r(g)}).catch(l=>(_("get request",[l]),o({errors:[l]})))}):Promise.resolve()}catch(r){n("get request",r)}};var ar=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.set.handleParseResponse",e)}},dr=(t={})=>{try{return JSON.stringify(t)}catch(e){n("api.set.getBody",e)}},pt=(t="",e={})=>{try{return typeof window.fetch!="undefined"?new Promise((r,o)=>{let i=`${window.location.origin}/api/_setters/${t}`,s=dr(e),d=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(i,{method:"POST",mode:"cors",headers:{...e?.headers||{},"Content-Type":"application/json","x-joystick-csrf":d},body:s,credentials:"include"}).then(async a=>{let l=await ar(a);return l?.errors?(_("set request",l.errors),o(l)):r(l)}).catch(a=>(_("set request",[a]),o({errors:[a]})))}):Promise.resolve()}catch(r){n("set request",r)}};var ut={get:mt,set:pt};var cr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("addToQueue.getQueue",e)}},q=(t="",e=null)=>{try{S()||(cr(t)||{}).array.push({callback:e})}catch(r){n("addToQueue",r)}};var Q=async(t={},e={},r={},o={})=>{try{if(o?.options?.data&&m(o.options.data)){let i=await o.options.data(t,e,r,o);return Promise.resolve(i)}return Promise.resolve()}catch(i){n("component.data.fetch",i)}};var ft=(t={},e={},r={})=>{try{return{...t,refetch:async(o={})=>{let i=await Q(ut,e,o,r);return r.data=ft(i,e,r),window.__joystick_data__[r?.id]=i,r.render({afterRefetchDataRender:()=>{r?.lifecycle?.onRefetchData&&r?.lifecycle?.onRefetchData(r)}}),i}}}catch(o){n("component.data.compile",o)}},ht=ft;var wt=(t={})=>{try{if(!S()&&window.__joystick_data__&&window.__joystick_data__[t?.id]){let e=window.__joystick_data__[t?.id]||{},r=window.__joystick_req__||{};return ht(e,r,t)}return t?.data||{}}catch(e){n("component.loadDataFromWindow",e)}};var bt=rr(yt());var xt=(t={},e="",r="id")=>{try{let o=t&&t.id;if(u(t)&&o){let i=Object.keys(t);for(let s=0;s<i.length;s+=1){let d=i[s],a=t[d];if(d===r&&a===e)return t;if(d==="children"&&Array.isArray(a))for(let l=0;l<a.length;l+=1){let g=a[l],y=xt(g,e,r);if(y!==null)return y}}}return null}catch(o){n("component.findComponentInTreeByField",o)}},R=xt;var gt=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.children=[...o.children||[],e])};var lr=(t={},e={},r=null)=>{try{let o=N(t,{includeActual:!0,existingChildren:r});return t.dom=o,t.setDOMNodeOnInstance(),e.renderedComponent=t,o.html.wrapped}catch(o){n("component.renderMethods.component.renderForClient",o)}},mr=(t={})=>{try{return t.renderToHTML({ssrTree:t.parent.ssrTree,translations:t.parent.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t.parent?.dataFromSSR}).wrapped}catch(e){n("component.renderMethods.component.renderToHTMLForSSR",e)}},pr=(t={})=>{try{return t.parent.ssrTree.dataFunctions.push(async()=>{try{let e=await t.options.data(t.parent.options.api,t.parent.options.req);return t.data=e||{},{componentId:t.id,ssrId:t.ssrId,data:e}}catch(e){return{componentId:t.id,ssrId:t.ssrId,data:null,error:e}}}),t.renderToHTML({ssrTree:t?.parent?.ssrTree,translations:t?.parent?.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t?.parent?.dataFromSSR})}catch(e){n("component.renderMethods.component.collectDataFunctionsForSSR",e)}},ur=(t={})=>{try{let e={id:t.id,instanceId:t.instanceId,instance:t,children:[]};gt(t.parent.instanceId,e,t.parent&&t.parent.ssrTree||null)}catch(e){n("component.renderMethods.component.handleAddComponentToParent",e)}},fr=(t={},e={})=>{try{!t.renderedComponent&&e.options&&e.options.lifecycle&&(e.options.lifecycle.onBeforeMount&&q("lifecycle.onBeforeMount",()=>{e.options.lifecycle.onBeforeMount(e)}),!t.renderedComponent&&e.options.lifecycle.onMount&&q("lifecycle.onMount",()=>{e.options.lifecycle.onMount(e)}))}catch(r){n("component.renderMethods.component.handleLifecycle",r)}},hr=(t={},e={},r={})=>{try{!e.walkingTreeForSSR&&t?.options?.lifecycle?.onUpdateProps&&(0,bt.diff)(e?.existingPropsMap,r)?.length>0&&q("lifecycle.onUpdateProps",()=>{let i=e?.existingPropsMap&&e?.existingPropsMap[t.id];t.options.lifecycle.onUpdateProps(i||{},r,t)})}catch(o){n("component.renderMethods.component.handleOnChangeProps",o)}},wr=function(){return function(e=null,r={},o={}){let i=e({props:r,url:o.url,translations:o.translations,api:o.options.api,req:o.options.req,dataFromSSR:o?.dataFromSSR,parent:o}),s=o?.existingStateMap[i.id]||{},d=o.children[i.id]||[],a=s[d?.length];return i.state=a?.state||i.state,o.children[i.id]=[...o.children[i.id]||[],i],i.parent=o,hr(i,o,r),q("lifecycle.onMount",()=>{i.setDOMNodeOnInstance()}),fr(this,i),i.parent&&ur(i),i.options.data&&i.parent.walkingTreeForSSR&&i.parent.ssrTree.dataFunctions?pr(i):i.parent&&i.parent.ssrTree?mr(i):lr(i,this,a?.children)}},yr=function(e,r){try{let o=this;return new wr().bind({})(e,r,o)}catch(o){n("component.renderMethods.component",o)}},se=yr;var xr=function(e=[],r=null){try{return m(r)&&e&&Array.isArray(e)?e.map((o,i)=>r(o,i)).join(""):""}catch(o){n("component.renderMethods.each",o)}},ae=xr;var gr=function(e="",r={}){try{let o=S()?this.translations:window.__joystick_i18n__;if(!o||!o[e])return"";let i=Object.entries(r);return i.length>0?i.reduce((s,[d,a])=>s.replace(`{{${d}}}`,a),o[e]):o[e]}catch(o){n("component.renderMethods.i18n",o)}},de=gr;var br=function(e=!1,r=""){try{return this?.renderingHTMLWithDataForSSR||e?`<when>${r.trim()}</when>`:"<when> </when>"}catch(o){n("component.renderMethods.when",o)}},ce=br;var $t={c:se,component:se,e:ae,each:ae,i:de,i18n:de,w:ce,when:ce};var Ft=(t={},e={})=>{try{return Object.entries($t).reduce((r,[o,i])=>(r[o]=i.bind({...t,...e}),r),{})}catch(r){n("component.renderMethods.compile",r)}};var Et=(t={})=>{try{return Object.entries(t)?.reduce((e={},[r,o]={})=>(e[r]=o?.map((i={})=>({state:i?.state,children:Et(i?.children)})),e),{})}catch(e){n("component.render.getExistingStateMap.buildMapForChildren",e)}},Mt=(t={})=>{try{return Et(t)}catch(e){n("component.render.getExistingStateMap",e)}};var kt=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),$r=new RegExp(/\n/g);var Fr=(t="")=>{try{return(t.match(kt)||[]).forEach(r=>{t=t.replace(r,"")}),t}catch(e){n("component.render.sanitizeHTML.removeCommentedCode",e)}},St=(t="")=>{try{let e=`${t}`;return e=Fr(e),e}catch(e){n("component.render.sanitizeHTML",e)}};var Ot=(t={},e="")=>{try{let{wrapper:r=null,ssrId:o=null,id:i=null,instanceId:s=null}=t;return`<div ${r?.id?`id="${r.id}" `:""}${r?.classList?`class="${r.classList?.join(" ")}" `:""}js-ssrId="${o}" js-c="${i}" js-i="${s}">${e}</div>`}catch(r){n("component.render.wrapHTML",r)}};var Tt=(t={},e=[])=>{try{let r=[...e],o=Object.entries(t);for(let i=0;i<o?.length;i+=1){let[s,d]=o[i];for(let a=0;a<d?.length;a+=1){let l=d[a];Object.entries(l?.timers)?.length>0&&r.push(...Object.values(l?.timers)),Object.entries(l?.children)?.length>0&&Tt(l?.children,r)}}if(r?.length>0)for(let i=0;i<r?.length;i+=1)clearTimeout(r[i])}catch(r){n("component.render.clearTimersOnChildren",r)}},vt=Tt;var X=(t={},e={})=>{try{e?.dataFromSSR&&(t.data=B(e.dataFromSSR,t.id)||{}),vt(t?.children);let r=Mt(e?.existingChildren||t?.children)||{};t.children={},t.renderMethods=Ft({...t,existingStateMap:r,translations:e?.translations||t.translations||{},ssrTree:e?.ssrTree,walkingTreeForSSR:e?.walkingTreeForSSR,renderingHTMLWithDataForSSR:e?.renderingHTMLWithDataForSSR,dataFromSSR:e?.dataFromSSR}),t.methods=K(t,t.options.methods);let o=t.options.render({...t||{},setState:t.setState.bind(t),...t.renderMethods||{}}),i=St(o),s=Ot(t,i);return{unwrapped:i,wrapped:s}}catch(r){n("component.render.toHTML",r)}};var Er=(t={})=>{try{return Object.values(t).reduce((e={},r)=>(e[r.name]=r.value,e),{})}catch(e){n("component.virtualDOM.build.parseAttributeMap",e)}},Ct=(t={})=>{try{return t.tagName==="WHEN"?[].flatMap.call(t?.childNodes,e=>e?.tagName==="WHEN"?Ct(e):le(e)):le(t)}catch(e){n("component.virtualDOM.build.flattenWhenTags",e)}},le=(t={})=>{try{let e=t&&t.tagName&&t.tagName.toLowerCase()||"text",r={tagName:e,attributes:Er(t.attributes),children:[].flatMap.call(t.childNodes,o=>Ct(o))};return e==="text"&&(r=t.textContent),r}catch(e){n("component.virtualDOM.build",e)}},z=le;var Mr=(t="")=>{try{let e=document.createElement("div");return e.innerHTML=t,e?.childNodes[0]}catch(e){n("component.virtualDOM.build.convertHTMLToDOM",e)}},Rt=(t="")=>{try{let e=Mr(t);return z(e)}catch(e){n("component.virtualDOM.build",e)}};var At=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}};var kr=(t={})=>{try{let e=document.createElement(t.tagName),r=Object.entries(t.attributes);for(let o=0;o<r.length;o+=1){let[i,s]=r[o];At(i)&&e.setAttribute(i,s)}for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(i){let s=Lt(i);e.appendChild(s)}}return e}catch(e){n("component.virtualDOM.renderTreeToDOM.renderElement",e)}},Lt=(t=null)=>{try{return C(t)?document.createTextNode(t):kr(t)}catch(e){n("component.virtualDOM.renderTreeToDOM",e)}},V=Lt;var N=(t={},e={})=>{try{let r=X(t,{existingChildren:e?.existingChildren}),o=Rt(r.wrapped,t),i=e.includeActual&&o?V(o):null;return{html:r,virtual:o,actual:i}}catch(r){n("component.render.getUpdatedDOM",r)}};var Dt=(t={},e={})=>{try{let r=N(t,{includeActual:!0,existingChildren:e?.existingChildren});return t.dom=r,r.actual}catch(r){n("component.render.forMount",r)}};var Sr=(t={},e={})=>{let r=[];for(let[o,i]of Object.entries(e))r.push(s=>(s&&s.setAttribute&&s.setAttribute(o,i),s));for(let o in t)o in e||r.push(i=>(i&&i.removeAttribute&&i.removeAttribute(o),i));return o=>{for(let i of r)i&&typeof i=="function"&&i(o)}},ee=Sr;var Or=(t=[],e=[])=>{let r=[],o=Math.max(t.length,e.length);for(let i=0;i<o;i+=1){let s=t[i],d=e[i];r.push([s,d])}return r},jt=Or;var Tr=(t=[],e)=>{t.forEach(r=>{r&&typeof r=="function"&&r(e)})},vr=(t=[])=>{t.forEach(([e,r])=>{e&&typeof e=="function"&&e(r)})},Cr=(t=[],e=[])=>{let r=[];return e.slice(t.length).forEach(i=>{let s=d=>{let a=V(i);return d.appendChild(a),d};r.push(s)}),r},Rr=(t=[],e=[])=>{let r=[];return t.forEach((o,i)=>{let s=re(o,e[i]);r.push(s)}),r},Ar=(t=[],e=[])=>{let r=Rr(t,e),o=Cr(t,e);return i=>{if(i){let s=jt(r,i.childNodes);vr(s),Tr(o,i)}return i}},te=Ar;var Pt={select:(t,e)=>r=>{let o=r.value;r.replaceChildren(),ee(t.attributes,e.attributes)(r),te([],e.children)(r);let i=r.querySelector(`option[value="${o}"]`);if(i&&(r.value=o),!i){let s=r.querySelector("option");r.value=s?.value||""}return r}};var me=(t,e)=>r=>{let o=t?V(t):null;return r&&r.replaceWith(o),o},Lr=()=>t=>{t&&t.remove()},Dr=(t=void 0,e=void 0)=>t===void 0||e===void 0?Lr():typeof t=="string"||typeof e=="string"?me(e,t):t.tagName!==e.tagName?me(e):e.tagName==="select"?Pt.select(t,e):["pre","code"].includes(e.tagName)?me(e,t):i=>(ee(t.attributes,e.attributes)(i),te(t.children,e.children)(i),i),re=Dr;var jr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("processQueue.getQueue",e)}},H=(t="",e=null)=>{try{S()||(jr(t)||{}).process(e)}catch(r){n("processQueue",r)}};var It=(t="",e=null)=>{let r=R(e||window.joystick._internal.tree,t,"instanceId");r&&(r.children=[])};var _t=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.instanceId=e?.instanceId,o.instance=e)};var Nt=(t={},e="",r={})=>{for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(u(i)&&i.attributes&&i.attributes["js-i"]&&i.attributes["js-i"]===e){t.children[o]=r;break}u(i)&&Nt(i,e,r)}},Vt=Nt;var Ut=(t={})=>{try{return Object.entries(t).map(([e,r])=>{let[o,...i]=e.split(" ");return{type:o.toLowerCase(),selector:i.join(" "),handler:r}})}catch(e){n("component.events.serialize",e)}};var qt=(t={},e={},r=[])=>{try{let o=Object.keys(t?.events||{})?.length>0?Ut(t?.events):[];for(let i=0;i<o?.length;i+=1){let s=o[i];r.push({...s,instance:t,elements:document.querySelectorAll(`body [js-i="${t.instanceId}"] ${s?.selector}`),handler:function(a){Object.defineProperty(a,"target",{value:a.composedPath()[0]}),s.handler(a,{...t||{},setState:t?.setState.bind(t),...e||{}})}})}if(t?.children){let i=Object.entries(t?.children)?.flatMap(([s,d])=>d);for(let s=0;s<i?.length;s+=1){let d=i[s];qt(d,e,r)}}return r}catch(o){n("component.events.registerListenersFix.getListeners",o)}},Pr=(t={},e={})=>{try{let r=qt(t,e,[]);console.log("GETTING CALLED",r);let o=r?.flatMap((i={})=>[].flatMap.call(i?.elements||[],s=>{let{elements:d=[],...a}=i||{};return{...a,element:s}}));for(let i=0;i<o?.length;i+=1){let{instance:s,element:d,elementSelector:a,type:l,handler:g}=o[i];console.log({element:d,type:l,handler:g}),d.addEventListener(l,g),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:d,elementSelector:a,type:l,handler:g}]}}catch(r){n("component.events.registerListenersFix",r)}},zt=Pr;var Ht=(t={})=>{try{let e=t?._eventListeners||[];if(t?.children){let o=(Object.values(t?.children||{})?.reduce((i=[],s=[])=>[...i,...s],[])).flatMap((i={})=>Ht(i));e=[...e,...o]}return e}catch(e){n("component.events.unregisterListenersFix.getListeners",e)}},Ir=(t={})=>{try{let e=Ht(t);for(let r=0;r<e?.length;r+=1){let{instance:o,element:i,type:s,handler:d}=e[r];i.removeEventListener(s,d),o._eventListeners=o._eventListeners?.splice(r,1)}}catch(e){n("component.events.unregisterListenersFix",e)}},Zt=Ir;var Bt=class{constructor(e={}){this.parent=e?.parent||null,this.onUpdateChildComponent=this.handleUpdateChildComponentInVDOM,this.updateVirtualDOM=this.handleUpdateVirtualDOM,this.timers={},this.children={},Te(e),lt(this,e),this.data=wt(this)}setDOMNodeOnInstance(){this.DOMNode=document.querySelector(`body [js-i="${this.instanceId}"]`)}async handleFetchData(e={},r={},o={},i=this){let s=await Q(e,r,o,i);return this.data=s,s}handleGetInstance(){return this}handleUpdateVirtualDOM(){if(this.DOMNode){let r=z(this.DOMNode);this.dom.virtual=r}let e=this.parent?R(window.joystick._internal.tree,this.parent?.instanceId,"instanceId"):null;e?.instance&&e.instance.updateVirtualDOM()}onBeforeRender(){if(!S())return{instanceId:this.instanceId}}render(e={}){if(e?.mounting)return Dt(this,e);let r=this.onBeforeRender();Zt(this),It(this.instanceId);let o=N(this,{}),i=re(this.dom.virtual,o.virtual);i&&m(i)&&H("lifecycle.onBeforeMount",()=>{let s=i(this.DOMNode);this.dom.actual=s,this.dom.virtual=o.virtual,zt(this,this.renderMethods),this.setDOMNodeOnInstance(),H("domNodes",()=>{H("lifecycle.onMount",()=>{this.onAfterRender(r,e)})})})}renderToHTML(e={}){return X(this,e)}onAfterRender(e={},r={}){S()||(_t(e.instanceId,this),window.joystick._internal.css.update(),H("lifecycle.onUpdateProps"),r?.afterSetStateRender&&m(r.afterSetStateRender)&&r.afterSetStateRender(),r?.afterRefetchDataRender&&m(r.afterRefetchDataRender)&&r.afterRefetchDataRender(),this.parent&&this.parent.onUpdateChildComponent(this.id,this.instanceId))}setState(e={},r=null){this.state=G(this,{...this.state||{},...e}),this.render({afterSetStateRender:()=>{r&&m(r)&&r()}})}setTimeout(e=null,r=0){e&&(this.timers[U()]=window.setTimeout(e,r))}setInterval(e=null,r=0){e&&(this.timers[U()]=window.setInterval(e,r))}handleUpdateChildComponentInVDOM(e="",r=""){let o=R(window.joystick._internal.tree,this.instanceId,"instanceId"),i=R(window.joystick._internal.tree,r,"instanceId");if(i?.instance?.DOMNode){let s=z(i?.instance?.DOMNode);Vt(o?.instance?.dom?.virtual,i?.instanceId,s)}}},Ja=Bt;export{Ja as default};
21
+ `}}return r}return""}catch(r){n("component.css.compileCSS",r)}};var ir=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.state.compile.compileState",r)}},G=(t={},e={})=>{try{return m(e)?ir(t,e):Object.assign({},e)}catch(r){n("component.state.compile",r)}};var ie={onBeforeMount:()=>null,onMount:()=>null,onBeforeUnmount:()=>null,onUpdateProps:()=>null,onRefetchData:()=>null};var st=(t={},e={})=>{try{return e?Object.entries({...ie,...e||{}}).reduce((r={},[o,i])=>(r[o]=()=>i({...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{}):ie}catch(r){n("component.lifecycle.compile",r)}};var K=(t={},e={})=>{try{return Object.entries(e).reduce((r={},[o,i])=>(r[o]=(...s)=>i(...s,{...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{})}catch{n("component.methods.compile")}};var ne=(t={})=>{try{return{...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window!="undefined"){let o=new URL(window.location);o.searchParams.append(e,r),window.history.pushState({},"",o)}},unset:(e="")=>{if(typeof window!="undefined"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},isActive:(e="")=>C(e)&&t?.route!=="*"?e===(typeof location!="undefined"?location.pathname:t.path):!1}}catch(e){n("component.url.compile",e)}};var S=()=>typeof window=="undefined";var I=null,W=0,at=(t={},e=null)=>{try{let r=t?.url;t?.query&&(r=`${r}?${new URLSearchParams(t.query).toString()}`);let o=new WebSocket(r);I&&(clearInterval(I),I=null);let i={client:o,send:(s={})=>o.send(JSON.stringify(s))};return o.addEventListener("open",()=>{t?.options?.logging&&console.log(`[joystick.websockets] Connected to ${t?.url}`),t?.events?.onOpen&&t.events.onOpen(i),W=0}),o.addEventListener("message",s=>{s?.data&&t?.events?.onMessage&&t.events.onMessage(JSON.parse(s.data||{}),i)}),o.addEventListener("close",s=>{t?.options?.logging&&console.log(`[joystick.websockets] Disconnected from ${t?.url}`),t?.events?.onClose&&t.events.onClose(s?.code,s?.reason,i),o=null;let d=[1e3,1001].includes(s?.code);t?.options?.autoReconnect&&!I&&!d&&(I=setInterval(()=>{o=null,W<(t?.options?.reconnectAttempts||12)?(at(t,e),t?.options?.logging&&console.log(`[joystick.websockets] Attempting to reconnect (${W+1}/12)...`),W+=1):clearInterval(I)},t?.options?.reconnectDelayInSeconds*1e3||5e3))}),e&&e(i),i}catch(r){n("websockets.client",r)}},dt=at;var nr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.props.compileDefaultProps.compile",r)}},ct=(t={},e={})=>{try{return m(e)?nr(t,e):Object.assign({},e)}catch(r){n("component.props.compileDefaultProps",r)}};var lt=(t={},e={})=>{try{t.options=e||{},t.id=e?._componentId||null,t.instanceId=U(8),t.ssrId=e?._ssrId||null,t.css=nt(),t.data=B(e?.dataFromSSR,e?._componentId),t.defaultProps=ct(t,e?.defaultProps),t.props=it(t?.defaultProps,e?.props),t.state=G(t,e?.state),t.events=e?.events||{},t.lifecycle=st(t,e?.lifecycle),t.methods=K(t,e?.methods),t.wrapper=e?.wrapper||{},t.translations=e?.translations||{},t.validateForm=ot,t.DOMNode=null,t.dom={},t.dom.virtual={},t.dom.actual={};let r=!S();if(r||(t.url=ne(e?.url)),r&&window.__joystick_url__&&(t.url=ne(window.__joystick_url__)),r&&e?.websockets&&m(e?.websockets)){let o=e.websockets(t),i=u(o)&&Object.entries(o);for(let s=0;s<i?.length;s+=1){let[d,a]=i[s];dt({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/${d}`,options:a?.options||{},query:a?.query||{},events:a?.events||{}},(l={})=>{t.websockets={...t.websockets||{},[d]:l}})}}}catch(r){n("component.registerOptions",r)}};var _=(t="",e=[])=>{try{console.error(`${t} failed with the following errors:`),e.forEach(r=>{console.log(r.message),r.stack&&console.log(r.stack)})}catch(r){n(t,r)}};var J=(t="{}")=>{try{return JSON.parse(t)}catch{return t}};var sr=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.get.handleParseResponse",e)}},mt=(t="",e={})=>{try{return typeof window.fetch!="undefined"&&!e?.skip?new Promise((r,o)=>{let i=e.input?JSON.stringify(e.input):null,s=e.output?JSON.stringify(e.output):null,d=`${window.location.origin}/api/_getters/${t}?input=${i}&output=${s}`,a=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(d,{method:"GET",mode:"cors",headers:{...e?.headers||{},"x-joystick-csrf":a},credentials:"include"}).then(async l=>{let g=await sr(l);return g?.errors?(_("get request",g.errors),o(g)):r(g)}).catch(l=>(_("get request",[l]),o({errors:[l]})))}):Promise.resolve()}catch(r){n("get request",r)}};var ar=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.set.handleParseResponse",e)}},dr=(t={})=>{try{return JSON.stringify(t)}catch(e){n("api.set.getBody",e)}},pt=(t="",e={})=>{try{return typeof window.fetch!="undefined"?new Promise((r,o)=>{let i=`${window.location.origin}/api/_setters/${t}`,s=dr(e),d=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(i,{method:"POST",mode:"cors",headers:{...e?.headers||{},"Content-Type":"application/json","x-joystick-csrf":d},body:s,credentials:"include"}).then(async a=>{let l=await ar(a);return l?.errors?(_("set request",l.errors),o(l)):r(l)}).catch(a=>(_("set request",[a]),o({errors:[a]})))}):Promise.resolve()}catch(r){n("set request",r)}};var ut={get:mt,set:pt};var cr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("addToQueue.getQueue",e)}},q=(t="",e=null)=>{try{S()||(cr(t)||{}).array.push({callback:e})}catch(r){n("addToQueue",r)}};var Q=async(t={},e={},r={},o={})=>{try{if(o?.options?.data&&m(o.options.data)){let i=await o.options.data(t,e,r,o);return Promise.resolve(i)}return Promise.resolve()}catch(i){n("component.data.fetch",i)}};var ft=(t={},e={},r={})=>{try{return{...t,refetch:async(o={})=>{let i=await Q(ut,e,o,r);return r.data=ft(i,e,r),window.__joystick_data__[r?.id]=i,r.render({afterRefetchDataRender:()=>{r?.lifecycle?.onRefetchData&&r?.lifecycle?.onRefetchData(r)}}),i}}}catch(o){n("component.data.compile",o)}},ht=ft;var wt=(t={})=>{try{if(!S()&&window.__joystick_data__&&window.__joystick_data__[t?.id]){let e=window.__joystick_data__[t?.id]||{},r=window.__joystick_req__||{};return ht(e,r,t)}return t?.data||{}}catch(e){n("component.loadDataFromWindow",e)}};var bt=rr(yt());var xt=(t={},e="",r="id")=>{try{let o=t&&t.id;if(u(t)&&o){let i=Object.keys(t);for(let s=0;s<i.length;s+=1){let d=i[s],a=t[d];if(d===r&&a===e)return t;if(d==="children"&&Array.isArray(a))for(let l=0;l<a.length;l+=1){let g=a[l],y=xt(g,e,r);if(y!==null)return y}}}return null}catch(o){n("component.findComponentInTreeByField",o)}},R=xt;var gt=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.children=[...o.children||[],e])};var lr=(t={},e={},r=null)=>{try{let o=N(t,{includeActual:!0,existingChildren:r});return t.dom=o,t.setDOMNodeOnInstance(),e.renderedComponent=t,o.html.wrapped}catch(o){n("component.renderMethods.component.renderForClient",o)}},mr=(t={})=>{try{return t.renderToHTML({ssrTree:t.parent.ssrTree,translations:t.parent.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t.parent?.dataFromSSR}).wrapped}catch(e){n("component.renderMethods.component.renderToHTMLForSSR",e)}},pr=(t={})=>{try{return t.parent.ssrTree.dataFunctions.push(async()=>{try{let e=await t.options.data(t.parent.options.api,t.parent.options.req);return t.data=e||{},{componentId:t.id,ssrId:t.ssrId,data:e}}catch(e){return{componentId:t.id,ssrId:t.ssrId,data:null,error:e}}}),t.renderToHTML({ssrTree:t?.parent?.ssrTree,translations:t?.parent?.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t?.parent?.dataFromSSR})}catch(e){n("component.renderMethods.component.collectDataFunctionsForSSR",e)}},ur=(t={})=>{try{let e={id:t.id,instanceId:t.instanceId,instance:t,children:[]};gt(t.parent.instanceId,e,t.parent&&t.parent.ssrTree||null)}catch(e){n("component.renderMethods.component.handleAddComponentToParent",e)}},fr=(t={},e={})=>{try{!t.renderedComponent&&e.options&&e.options.lifecycle&&(e.options.lifecycle.onBeforeMount&&q("lifecycle.onBeforeMount",()=>{e.options.lifecycle.onBeforeMount(e)}),!t.renderedComponent&&e.options.lifecycle.onMount&&q("lifecycle.onMount",()=>{e.options.lifecycle.onMount(e)}))}catch(r){n("component.renderMethods.component.handleLifecycle",r)}},hr=(t={},e={},r={})=>{try{!e.walkingTreeForSSR&&t?.options?.lifecycle?.onUpdateProps&&(0,bt.diff)(e?.existingPropsMap,r)?.length>0&&q("lifecycle.onUpdateProps",()=>{let i=e?.existingPropsMap&&e?.existingPropsMap[t.id];t.options.lifecycle.onUpdateProps(i||{},r,t)})}catch(o){n("component.renderMethods.component.handleOnChangeProps",o)}},wr=function(){return function(e=null,r={},o={}){let i=e({props:r,url:o.url,translations:o.translations,api:o.options.api,req:o.options.req,dataFromSSR:o?.dataFromSSR,parent:o}),s=o?.existingStateMap[i.id]||{},d=o.children[i.id]||[],a=s[d?.length];return i.state=a?.state||i.state,o.children[i.id]=[...o.children[i.id]||[],i],i.parent=o,hr(i,o,r),q("lifecycle.onMount",()=>{i.setDOMNodeOnInstance()}),fr(this,i),i.parent&&ur(i),i.options.data&&i.parent.walkingTreeForSSR&&i.parent.ssrTree.dataFunctions?pr(i):i.parent&&i.parent.ssrTree?mr(i):lr(i,this,a?.children)}},yr=function(e,r){try{let o=this;return new wr().bind({})(e,r,o)}catch(o){n("component.renderMethods.component",o)}},se=yr;var xr=function(e=[],r=null){try{return m(r)&&e&&Array.isArray(e)?e.map((o,i)=>r(o,i)).join(""):""}catch(o){n("component.renderMethods.each",o)}},ae=xr;var gr=function(e="",r={}){try{let o=S()?this.translations:window.__joystick_i18n__;if(!o||!o[e])return"";let i=Object.entries(r);return i.length>0?i.reduce((s,[d,a])=>s.replace(`{{${d}}}`,a),o[e]):o[e]}catch(o){n("component.renderMethods.i18n",o)}},de=gr;var br=function(e=!1,r=""){try{return this?.renderingHTMLWithDataForSSR||e?`<when>${r.trim()}</when>`:"<when> </when>"}catch(o){n("component.renderMethods.when",o)}},ce=br;var $t={c:se,component:se,e:ae,each:ae,i:de,i18n:de,w:ce,when:ce};var Ft=(t={},e={})=>{try{return Object.entries($t).reduce((r,[o,i])=>(r[o]=i.bind({...t,...e}),r),{})}catch(r){n("component.renderMethods.compile",r)}};var Et=(t={})=>{try{return Object.entries(t)?.reduce((e={},[r,o]={})=>(e[r]=o?.map((i={})=>({state:i?.state,children:Et(i?.children)})),e),{})}catch(e){n("component.render.getExistingStateMap.buildMapForChildren",e)}},Mt=(t={})=>{try{return Et(t)}catch(e){n("component.render.getExistingStateMap",e)}};var kt=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),$r=new RegExp(/\n/g);var Fr=(t="")=>{try{return(t.match(kt)||[]).forEach(r=>{t=t.replace(r,"")}),t}catch(e){n("component.render.sanitizeHTML.removeCommentedCode",e)}},St=(t="")=>{try{let e=`${t}`;return e=Fr(e),e}catch(e){n("component.render.sanitizeHTML",e)}};var Ot=(t={},e="")=>{try{let{wrapper:r=null,ssrId:o=null,id:i=null,instanceId:s=null}=t;return`<div ${r?.id?`id="${r.id}" `:""}${r?.classList?`class="${r.classList?.join(" ")}" `:""}js-ssrId="${o}" js-c="${i}" js-i="${s}">${e}</div>`}catch(r){n("component.render.wrapHTML",r)}};var Tt=(t={},e=[])=>{try{let r=[...e],o=Object.entries(t);for(let i=0;i<o?.length;i+=1){let[s,d]=o[i];for(let a=0;a<d?.length;a+=1){let l=d[a];Object.entries(l?.timers)?.length>0&&r.push(...Object.values(l?.timers)),Object.entries(l?.children)?.length>0&&Tt(l?.children,r)}}if(r?.length>0)for(let i=0;i<r?.length;i+=1)clearTimeout(r[i])}catch(r){n("component.render.clearTimersOnChildren",r)}},vt=Tt;var X=(t={},e={})=>{try{e?.dataFromSSR&&(t.data=B(e.dataFromSSR,t.id)||{}),vt(t?.children);let r=Mt(e?.existingChildren||t?.children)||{};t.children={},t.renderMethods=Ft({...t,existingStateMap:r,translations:e?.translations||t.translations||{},ssrTree:e?.ssrTree,walkingTreeForSSR:e?.walkingTreeForSSR,renderingHTMLWithDataForSSR:e?.renderingHTMLWithDataForSSR,dataFromSSR:e?.dataFromSSR}),t.methods=K(t,t.options.methods);let o=t.options.render({...t||{},setState:t.setState.bind(t),...t.renderMethods||{}}),i=St(o),s=Ot(t,i);return{unwrapped:i,wrapped:s}}catch(r){n("component.render.toHTML",r)}};var Er=(t={})=>{try{return Object.values(t).reduce((e={},r)=>(e[r.name]=r.value,e),{})}catch(e){n("component.virtualDOM.build.parseAttributeMap",e)}},Ct=(t={})=>{try{return t.tagName==="WHEN"?[].flatMap.call(t?.childNodes,e=>e?.tagName==="WHEN"?Ct(e):le(e)):le(t)}catch(e){n("component.virtualDOM.build.flattenWhenTags",e)}},le=(t={})=>{try{let e=t&&t.tagName&&t.tagName.toLowerCase()||"text",r={tagName:e,attributes:Er(t.attributes),children:[].flatMap.call(t.childNodes,o=>Ct(o))};return e==="text"&&(r=t.textContent),r}catch(e){n("component.virtualDOM.build",e)}},z=le;var Mr=(t="")=>{try{let e=document.createElement("div");return e.innerHTML=t,e?.childNodes[0]}catch(e){n("component.virtualDOM.build.convertHTMLToDOM",e)}},Rt=(t="")=>{try{let e=Mr(t);return z(e)}catch(e){n("component.virtualDOM.build",e)}};var At=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}};var kr=(t={})=>{try{let e=document.createElement(t.tagName),r=Object.entries(t.attributes);for(let o=0;o<r.length;o+=1){let[i,s]=r[o];At(i)&&e.setAttribute(i,s)}for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(i){let s=Lt(i);e.appendChild(s)}}return e}catch(e){n("component.virtualDOM.renderTreeToDOM.renderElement",e)}},Lt=(t=null)=>{try{return C(t)?document.createTextNode(t):kr(t)}catch(e){n("component.virtualDOM.renderTreeToDOM",e)}},V=Lt;var N=(t={},e={})=>{try{let r=X(t,{existingChildren:e?.existingChildren}),o=Rt(r.wrapped,t),i=e.includeActual&&o?V(o):null;return{html:r,virtual:o,actual:i}}catch(r){n("component.render.getUpdatedDOM",r)}};var Dt=(t={},e={})=>{try{let r=N(t,{includeActual:!0,existingChildren:e?.existingChildren});return t.dom=r,r.actual}catch(r){n("component.render.forMount",r)}};var Sr=(t={},e={})=>{let r=[];for(let[o,i]of Object.entries(e))r.push(s=>(s&&s.setAttribute&&s.setAttribute(o,i),s));for(let o in t)o in e||r.push(i=>(i&&i.removeAttribute&&i.removeAttribute(o),i));return o=>{for(let i of r)i&&typeof i=="function"&&i(o)}},ee=Sr;var Or=(t=[],e=[])=>{let r=[],o=Math.max(t.length,e.length);for(let i=0;i<o;i+=1){let s=t[i],d=e[i];r.push([s,d])}return r},jt=Or;var Tr=(t=[],e)=>{t.forEach(r=>{r&&typeof r=="function"&&r(e)})},vr=(t=[])=>{t.forEach(([e,r])=>{e&&typeof e=="function"&&e(r)})},Cr=(t=[],e=[])=>{let r=[];return e.slice(t.length).forEach(i=>{let s=d=>{let a=V(i);return d.appendChild(a),d};r.push(s)}),r},Rr=(t=[],e=[])=>{let r=[];return t.forEach((o,i)=>{let s=re(o,e[i]);r.push(s)}),r},Ar=(t=[],e=[])=>{let r=Rr(t,e),o=Cr(t,e);return i=>{if(i){let s=jt(r,i.childNodes);vr(s),Tr(o,i)}return i}},te=Ar;var Pt={select:(t,e)=>r=>{let o=r.value;r.replaceChildren(),ee(t.attributes,e.attributes)(r),te([],e.children)(r);let i=r.querySelector(`option[value="${o}"]`);if(i&&(r.value=o),!i){let s=r.querySelector("option");r.value=s?.value||""}return r}};var me=(t,e)=>r=>{let o=t?V(t):null;return r&&r.replaceWith(o),o},Lr=()=>t=>{t&&t.remove()},Dr=(t=void 0,e=void 0)=>t===void 0||e===void 0?Lr():typeof t=="string"||typeof e=="string"?me(e,t):t.tagName!==e.tagName?me(e):e.tagName==="select"?Pt.select(t,e):["pre","code"].includes(e.tagName)?me(e,t):i=>(ee(t.attributes,e.attributes)(i),te(t.children,e.children)(i),i),re=Dr;var jr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("processQueue.getQueue",e)}},H=(t="",e=null)=>{try{S()||(jr(t)||{}).process(e)}catch(r){n("processQueue",r)}};var It=(t="",e=null)=>{let r=R(e||window.joystick._internal.tree,t,"instanceId");r&&(r.children=[])};var _t=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.instanceId=e?.instanceId,o.instance=e)};var Nt=(t={},e="",r={})=>{for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(u(i)&&i.attributes&&i.attributes["js-i"]&&i.attributes["js-i"]===e){t.children[o]=r;break}u(i)&&Nt(i,e,r)}},Vt=Nt;var Ut=(t={})=>{try{return Object.entries(t).map(([e,r])=>{let[o,...i]=e.split(" ");return{type:o.toLowerCase(),selector:i.join(" "),handler:r}})}catch(e){n("component.events.serialize",e)}};var qt=(t={},e={},r=[])=>{try{let o=Object.keys(t?.events||{})?.length>0?Ut(t?.events):[];for(let i=0;i<o?.length;i+=1){let s=o[i];r.push({...s,instance:t,elements:document.querySelectorAll(`body [js-i="${t.instanceId}"] ${s?.selector}`),handler:function(a){console.log("DOM EVENT",a),Object.defineProperty(a,"target",{value:a.composedPath()[0]}),s.handler(a,{...t||{},setState:t?.setState.bind(t),...e||{}})}})}if(t?.children){let i=Object.entries(t?.children)?.flatMap(([s,d])=>d);for(let s=0;s<i?.length;s+=1){let d=i[s];qt(d,e,r)}}return r}catch(o){n("component.events.registerListenersFix.getListeners",o)}},Pr=(t={},e={})=>{try{let r=qt(t,e,[]);console.log("GETTING CALLED",r);let o=r?.flatMap((i={})=>[].flatMap.call(i?.elements||[],s=>{let{elements:d=[],...a}=i||{};return{...a,element:s}}));for(let i=0;i<o?.length;i+=1){let{instance:s,element:d,elementSelector:a,type:l,handler:g}=o[i];console.log({element:d,type:l,handler:g}),d.addEventListener(l,g),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:d,elementSelector:a,type:l,handler:g}]}}catch(r){n("component.events.registerListenersFix",r)}},zt=Pr;var Ht=(t={})=>{try{let e=t?._eventListeners||[];if(t?.children){let o=(Object.values(t?.children||{})?.reduce((i=[],s=[])=>[...i,...s],[])).flatMap((i={})=>Ht(i));e=[...e,...o]}return e}catch(e){n("component.events.unregisterListenersFix.getListeners",e)}},Ir=(t={})=>{try{let e=Ht(t);for(let r=0;r<e?.length;r+=1){let{instance:o,element:i,type:s,handler:d}=e[r];i.removeEventListener(s,d),o._eventListeners=o._eventListeners?.splice(r,1)}}catch(e){n("component.events.unregisterListenersFix",e)}},Zt=Ir;var Bt=class{constructor(e={}){this.parent=e?.parent||null,this.onUpdateChildComponent=this.handleUpdateChildComponentInVDOM,this.updateVirtualDOM=this.handleUpdateVirtualDOM,this.timers={},this.children={},Te(e),lt(this,e),this.data=wt(this)}setDOMNodeOnInstance(){this.DOMNode=document.querySelector(`body [js-i="${this.instanceId}"]`)}async handleFetchData(e={},r={},o={},i=this){let s=await Q(e,r,o,i);return this.data=s,s}handleGetInstance(){return this}handleUpdateVirtualDOM(){if(this.DOMNode){let r=z(this.DOMNode);this.dom.virtual=r}let e=this.parent?R(window.joystick._internal.tree,this.parent?.instanceId,"instanceId"):null;e?.instance&&e.instance.updateVirtualDOM()}onBeforeRender(){if(!S())return{instanceId:this.instanceId}}render(e={}){if(e?.mounting)return Dt(this,e);let r=this.onBeforeRender();Zt(this),It(this.instanceId);let o=N(this,{}),i=re(this.dom.virtual,o.virtual);i&&m(i)&&H("lifecycle.onBeforeMount",()=>{let s=i(this.DOMNode);this.dom.actual=s,this.dom.virtual=o.virtual,zt(this,this.renderMethods),this.setDOMNodeOnInstance(),H("domNodes",()=>{H("lifecycle.onMount",()=>{this.onAfterRender(r,e)})})})}renderToHTML(e={}){return X(this,e)}onAfterRender(e={},r={}){S()||(_t(e.instanceId,this),window.joystick._internal.css.update(),H("lifecycle.onUpdateProps"),r?.afterSetStateRender&&m(r.afterSetStateRender)&&r.afterSetStateRender(),r?.afterRefetchDataRender&&m(r.afterRefetchDataRender)&&r.afterRefetchDataRender(),this.parent&&this.parent.onUpdateChildComponent(this.id,this.instanceId))}setState(e={},r=null){this.state=G(this,{...this.state||{},...e}),this.render({afterSetStateRender:()=>{r&&m(r)&&r()}})}setTimeout(e=null,r=0){e&&(this.timers[U()]=window.setTimeout(e,r))}setInterval(e=null,r=0){e&&(this.timers[U()]=window.setInterval(e,r))}handleUpdateChildComponentInVDOM(e="",r=""){let o=R(window.joystick._internal.tree,this.instanceId,"instanceId"),i=R(window.joystick._internal.tree,r,"instanceId");if(i?.instance?.DOMNode){let s=z(i?.instance?.DOMNode);Vt(o?.instance?.dom?.virtual,i?.instanceId,s)}}},Ja=Bt;export{Ja as default};
@@ -18,4 +18,4 @@ var Wt=Object.create;var oe=Object.defineProperty;var Jt=Object.getOwnPropertyDe
18
18
  @media screen and (max-height: ${v}px) {
19
19
  ${typeof f=="function"?f(e):f}
20
20
  }
21
- `}}return r}return""}catch(r){n("component.css.compileCSS",r)}};var nr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.state.compile.compileState",r)}},G=(t={},e={})=>{try{return m(e)?nr(t,e):Object.assign({},e)}catch(r){n("component.state.compile",r)}};var ie={onBeforeMount:()=>null,onMount:()=>null,onBeforeUnmount:()=>null,onUpdateProps:()=>null,onRefetchData:()=>null};var st=(t={},e={})=>{try{return e?Object.entries({...ie,...e||{}}).reduce((r={},[o,i])=>(r[o]=()=>i({...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{}):ie}catch(r){n("component.lifecycle.compile",r)}};var K=(t={},e={})=>{try{return Object.entries(e).reduce((r={},[o,i])=>(r[o]=(...s)=>i(...s,{...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{})}catch{n("component.methods.compile")}};var ne=(t={})=>{try{return{...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window!="undefined"){let o=new URL(window.location);o.searchParams.append(e,r),window.history.pushState({},"",o)}},unset:(e="")=>{if(typeof window!="undefined"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},isActive:(e="")=>C(e)&&t?.route!=="*"?e===(typeof location!="undefined"?location.pathname:t.path):!1}}catch(e){n("component.url.compile",e)}};var S=()=>typeof window=="undefined";var I=null,W=0,at=(t={},e=null)=>{try{let r=t?.url;t?.query&&(r=`${r}?${new URLSearchParams(t.query).toString()}`);let o=new WebSocket(r);I&&(clearInterval(I),I=null);let i={client:o,send:(s={})=>o.send(JSON.stringify(s))};return o.addEventListener("open",()=>{t?.options?.logging&&console.log(`[joystick.websockets] Connected to ${t?.url}`),t?.events?.onOpen&&t.events.onOpen(i),W=0}),o.addEventListener("message",s=>{s?.data&&t?.events?.onMessage&&t.events.onMessage(JSON.parse(s.data||{}),i)}),o.addEventListener("close",s=>{t?.options?.logging&&console.log(`[joystick.websockets] Disconnected from ${t?.url}`),t?.events?.onClose&&t.events.onClose(s?.code,s?.reason,i),o=null;let d=[1e3,1001].includes(s?.code);t?.options?.autoReconnect&&!I&&!d&&(I=setInterval(()=>{o=null,W<(t?.options?.reconnectAttempts||12)?(at(t,e),t?.options?.logging&&console.log(`[joystick.websockets] Attempting to reconnect (${W+1}/12)...`),W+=1):clearInterval(I)},t?.options?.reconnectDelayInSeconds*1e3||5e3))}),e&&e(i),i}catch(r){n("websockets.client",r)}},dt=at;var sr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.props.compileDefaultProps.compile",r)}},ct=(t={},e={})=>{try{return m(e)?sr(t,e):Object.assign({},e)}catch(r){n("component.props.compileDefaultProps",r)}};var lt=(t={},e={})=>{try{t.options=e||{},t.id=e?._componentId||null,t.instanceId=U(8),t.ssrId=e?._ssrId||null,t.css=nt(),t.data=B(e?.dataFromSSR,e?._componentId),t.defaultProps=ct(t,e?.defaultProps),t.props=it(t?.defaultProps,e?.props),t.state=G(t,e?.state),t.events=e?.events||{},t.lifecycle=st(t,e?.lifecycle),t.methods=K(t,e?.methods),t.wrapper=e?.wrapper||{},t.translations=e?.translations||{},t.validateForm=ot,t.DOMNode=null,t.dom={},t.dom.virtual={},t.dom.actual={};let r=!S();if(r||(t.url=ne(e?.url)),r&&window.__joystick_url__&&(t.url=ne(window.__joystick_url__)),r&&e?.websockets&&m(e?.websockets)){let o=e.websockets(t),i=u(o)&&Object.entries(o);for(let s=0;s<i?.length;s+=1){let[d,a]=i[s];dt({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/${d}`,options:a?.options||{},query:a?.query||{},events:a?.events||{}},(l={})=>{t.websockets={...t.websockets||{},[d]:l}})}}}catch(r){n("component.registerOptions",r)}};var _=(t="",e=[])=>{try{console.error(`${t} failed with the following errors:`),e.forEach(r=>{console.log(r.message),r.stack&&console.log(r.stack)})}catch(r){n(t,r)}};var J=(t="{}")=>{try{return JSON.parse(t)}catch{return t}};var ar=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.get.handleParseResponse",e)}},mt=(t="",e={})=>{try{return typeof window.fetch!="undefined"&&!e?.skip?new Promise((r,o)=>{let i=e.input?JSON.stringify(e.input):null,s=e.output?JSON.stringify(e.output):null,d=`${window.location.origin}/api/_getters/${t}?input=${i}&output=${s}`,a=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(d,{method:"GET",mode:"cors",headers:{...e?.headers||{},"x-joystick-csrf":a},credentials:"include"}).then(async l=>{let g=await ar(l);return g?.errors?(_("get request",g.errors),o(g)):r(g)}).catch(l=>(_("get request",[l]),o({errors:[l]})))}):Promise.resolve()}catch(r){n("get request",r)}};var dr=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.set.handleParseResponse",e)}},cr=(t={})=>{try{return JSON.stringify(t)}catch(e){n("api.set.getBody",e)}},pt=(t="",e={})=>{try{return typeof window.fetch!="undefined"?new Promise((r,o)=>{let i=`${window.location.origin}/api/_setters/${t}`,s=cr(e),d=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(i,{method:"POST",mode:"cors",headers:{...e?.headers||{},"Content-Type":"application/json","x-joystick-csrf":d},body:s,credentials:"include"}).then(async a=>{let l=await dr(a);return l?.errors?(_("set request",l.errors),o(l)):r(l)}).catch(a=>(_("set request",[a]),o({errors:[a]})))}):Promise.resolve()}catch(r){n("set request",r)}};var ut={get:mt,set:pt};var lr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("addToQueue.getQueue",e)}},q=(t="",e=null)=>{try{S()||(lr(t)||{}).array.push({callback:e})}catch(r){n("addToQueue",r)}};var Q=async(t={},e={},r={},o={})=>{try{if(o?.options?.data&&m(o.options.data)){let i=await o.options.data(t,e,r,o);return Promise.resolve(i)}return Promise.resolve()}catch(i){n("component.data.fetch",i)}};var ft=(t={},e={},r={})=>{try{return{...t,refetch:async(o={})=>{let i=await Q(ut,e,o,r);return r.data=ft(i,e,r),window.__joystick_data__[r?.id]=i,r.render({afterRefetchDataRender:()=>{r?.lifecycle?.onRefetchData&&r?.lifecycle?.onRefetchData(r)}}),i}}}catch(o){n("component.data.compile",o)}},ht=ft;var wt=(t={})=>{try{if(!S()&&window.__joystick_data__&&window.__joystick_data__[t?.id]){let e=window.__joystick_data__[t?.id]||{},r=window.__joystick_req__||{};return ht(e,r,t)}return t?.data||{}}catch(e){n("component.loadDataFromWindow",e)}};var bt=or(yt());var xt=(t={},e="",r="id")=>{try{let o=t&&t.id;if(u(t)&&o){let i=Object.keys(t);for(let s=0;s<i.length;s+=1){let d=i[s],a=t[d];if(d===r&&a===e)return t;if(d==="children"&&Array.isArray(a))for(let l=0;l<a.length;l+=1){let g=a[l],y=xt(g,e,r);if(y!==null)return y}}}return null}catch(o){n("component.findComponentInTreeByField",o)}},R=xt;var gt=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.children=[...o.children||[],e])};var mr=(t={},e={},r=null)=>{try{let o=N(t,{includeActual:!0,existingChildren:r});return t.dom=o,t.setDOMNodeOnInstance(),e.renderedComponent=t,o.html.wrapped}catch(o){n("component.renderMethods.component.renderForClient",o)}},pr=(t={})=>{try{return t.renderToHTML({ssrTree:t.parent.ssrTree,translations:t.parent.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t.parent?.dataFromSSR}).wrapped}catch(e){n("component.renderMethods.component.renderToHTMLForSSR",e)}},ur=(t={})=>{try{return t.parent.ssrTree.dataFunctions.push(async()=>{try{let e=await t.options.data(t.parent.options.api,t.parent.options.req);return t.data=e||{},{componentId:t.id,ssrId:t.ssrId,data:e}}catch(e){return{componentId:t.id,ssrId:t.ssrId,data:null,error:e}}}),t.renderToHTML({ssrTree:t?.parent?.ssrTree,translations:t?.parent?.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t?.parent?.dataFromSSR})}catch(e){n("component.renderMethods.component.collectDataFunctionsForSSR",e)}},fr=(t={})=>{try{let e={id:t.id,instanceId:t.instanceId,instance:t,children:[]};gt(t.parent.instanceId,e,t.parent&&t.parent.ssrTree||null)}catch(e){n("component.renderMethods.component.handleAddComponentToParent",e)}},hr=(t={},e={})=>{try{!t.renderedComponent&&e.options&&e.options.lifecycle&&(e.options.lifecycle.onBeforeMount&&q("lifecycle.onBeforeMount",()=>{e.options.lifecycle.onBeforeMount(e)}),!t.renderedComponent&&e.options.lifecycle.onMount&&q("lifecycle.onMount",()=>{e.options.lifecycle.onMount(e)}))}catch(r){n("component.renderMethods.component.handleLifecycle",r)}},wr=(t={},e={},r={})=>{try{!e.walkingTreeForSSR&&t?.options?.lifecycle?.onUpdateProps&&(0,bt.diff)(e?.existingPropsMap,r)?.length>0&&q("lifecycle.onUpdateProps",()=>{let i=e?.existingPropsMap&&e?.existingPropsMap[t.id];t.options.lifecycle.onUpdateProps(i||{},r,t)})}catch(o){n("component.renderMethods.component.handleOnChangeProps",o)}},yr=function(){return function(e=null,r={},o={}){let i=e({props:r,url:o.url,translations:o.translations,api:o.options.api,req:o.options.req,dataFromSSR:o?.dataFromSSR,parent:o}),s=o?.existingStateMap[i.id]||{},d=o.children[i.id]||[],a=s[d?.length];return i.state=a?.state||i.state,o.children[i.id]=[...o.children[i.id]||[],i],i.parent=o,wr(i,o,r),q("lifecycle.onMount",()=>{i.setDOMNodeOnInstance()}),hr(this,i),i.parent&&fr(i),i.options.data&&i.parent.walkingTreeForSSR&&i.parent.ssrTree.dataFunctions?ur(i):i.parent&&i.parent.ssrTree?pr(i):mr(i,this,a?.children)}},xr=function(e,r){try{let o=this;return new yr().bind({})(e,r,o)}catch(o){n("component.renderMethods.component",o)}},se=xr;var gr=function(e=[],r=null){try{return m(r)&&e&&Array.isArray(e)?e.map((o,i)=>r(o,i)).join(""):""}catch(o){n("component.renderMethods.each",o)}},ae=gr;var br=function(e="",r={}){try{let o=S()?this.translations:window.__joystick_i18n__;if(!o||!o[e])return"";let i=Object.entries(r);return i.length>0?i.reduce((s,[d,a])=>s.replace(`{{${d}}}`,a),o[e]):o[e]}catch(o){n("component.renderMethods.i18n",o)}},de=br;var $r=function(e=!1,r=""){try{return this?.renderingHTMLWithDataForSSR||e?`<when>${r.trim()}</when>`:"<when> </when>"}catch(o){n("component.renderMethods.when",o)}},ce=$r;var $t={c:se,component:se,e:ae,each:ae,i:de,i18n:de,w:ce,when:ce};var Ft=(t={},e={})=>{try{return Object.entries($t).reduce((r,[o,i])=>(r[o]=i.bind({...t,...e}),r),{})}catch(r){n("component.renderMethods.compile",r)}};var Et=(t={})=>{try{return Object.entries(t)?.reduce((e={},[r,o]={})=>(e[r]=o?.map((i={})=>({state:i?.state,children:Et(i?.children)})),e),{})}catch(e){n("component.render.getExistingStateMap.buildMapForChildren",e)}},Mt=(t={})=>{try{return Et(t)}catch(e){n("component.render.getExistingStateMap",e)}};var kt=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),Fr=new RegExp(/\n/g);var Er=(t="")=>{try{return(t.match(kt)||[]).forEach(r=>{t=t.replace(r,"")}),t}catch(e){n("component.render.sanitizeHTML.removeCommentedCode",e)}},St=(t="")=>{try{let e=`${t}`;return e=Er(e),e}catch(e){n("component.render.sanitizeHTML",e)}};var Ot=(t={},e="")=>{try{let{wrapper:r=null,ssrId:o=null,id:i=null,instanceId:s=null}=t;return`<div ${r?.id?`id="${r.id}" `:""}${r?.classList?`class="${r.classList?.join(" ")}" `:""}js-ssrId="${o}" js-c="${i}" js-i="${s}">${e}</div>`}catch(r){n("component.render.wrapHTML",r)}};var Tt=(t={},e=[])=>{try{let r=[...e],o=Object.entries(t);for(let i=0;i<o?.length;i+=1){let[s,d]=o[i];for(let a=0;a<d?.length;a+=1){let l=d[a];Object.entries(l?.timers)?.length>0&&r.push(...Object.values(l?.timers)),Object.entries(l?.children)?.length>0&&Tt(l?.children,r)}}if(r?.length>0)for(let i=0;i<r?.length;i+=1)clearTimeout(r[i])}catch(r){n("component.render.clearTimersOnChildren",r)}},vt=Tt;var X=(t={},e={})=>{try{e?.dataFromSSR&&(t.data=B(e.dataFromSSR,t.id)||{}),vt(t?.children);let r=Mt(e?.existingChildren||t?.children)||{};t.children={},t.renderMethods=Ft({...t,existingStateMap:r,translations:e?.translations||t.translations||{},ssrTree:e?.ssrTree,walkingTreeForSSR:e?.walkingTreeForSSR,renderingHTMLWithDataForSSR:e?.renderingHTMLWithDataForSSR,dataFromSSR:e?.dataFromSSR}),t.methods=K(t,t.options.methods);let o=t.options.render({...t||{},setState:t.setState.bind(t),...t.renderMethods||{}}),i=St(o),s=Ot(t,i);return{unwrapped:i,wrapped:s}}catch(r){n("component.render.toHTML",r)}};var Mr=(t={})=>{try{return Object.values(t).reduce((e={},r)=>(e[r.name]=r.value,e),{})}catch(e){n("component.virtualDOM.build.parseAttributeMap",e)}},Ct=(t={})=>{try{return t.tagName==="WHEN"?[].flatMap.call(t?.childNodes,e=>e?.tagName==="WHEN"?Ct(e):le(e)):le(t)}catch(e){n("component.virtualDOM.build.flattenWhenTags",e)}},le=(t={})=>{try{let e=t&&t.tagName&&t.tagName.toLowerCase()||"text",r={tagName:e,attributes:Mr(t.attributes),children:[].flatMap.call(t.childNodes,o=>Ct(o))};return e==="text"&&(r=t.textContent),r}catch(e){n("component.virtualDOM.build",e)}},z=le;var kr=(t="")=>{try{let e=document.createElement("div");return e.innerHTML=t,e?.childNodes[0]}catch(e){n("component.virtualDOM.build.convertHTMLToDOM",e)}},Rt=(t="")=>{try{let e=kr(t);return z(e)}catch(e){n("component.virtualDOM.build",e)}};var At=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}};var Sr=(t={})=>{try{let e=document.createElement(t.tagName),r=Object.entries(t.attributes);for(let o=0;o<r.length;o+=1){let[i,s]=r[o];At(i)&&e.setAttribute(i,s)}for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(i){let s=Lt(i);e.appendChild(s)}}return e}catch(e){n("component.virtualDOM.renderTreeToDOM.renderElement",e)}},Lt=(t=null)=>{try{return C(t)?document.createTextNode(t):Sr(t)}catch(e){n("component.virtualDOM.renderTreeToDOM",e)}},V=Lt;var N=(t={},e={})=>{try{let r=X(t,{existingChildren:e?.existingChildren}),o=Rt(r.wrapped,t),i=e.includeActual&&o?V(o):null;return{html:r,virtual:o,actual:i}}catch(r){n("component.render.getUpdatedDOM",r)}};var Dt=(t={},e={})=>{try{let r=N(t,{includeActual:!0,existingChildren:e?.existingChildren});return t.dom=r,r.actual}catch(r){n("component.render.forMount",r)}};var Or=(t={},e={})=>{let r=[];for(let[o,i]of Object.entries(e))r.push(s=>(s&&s.setAttribute&&s.setAttribute(o,i),s));for(let o in t)o in e||r.push(i=>(i&&i.removeAttribute&&i.removeAttribute(o),i));return o=>{for(let i of r)i&&typeof i=="function"&&i(o)}},ee=Or;var Tr=(t=[],e=[])=>{let r=[],o=Math.max(t.length,e.length);for(let i=0;i<o;i+=1){let s=t[i],d=e[i];r.push([s,d])}return r},jt=Tr;var vr=(t=[],e)=>{t.forEach(r=>{r&&typeof r=="function"&&r(e)})},Cr=(t=[])=>{t.forEach(([e,r])=>{e&&typeof e=="function"&&e(r)})},Rr=(t=[],e=[])=>{let r=[];return e.slice(t.length).forEach(i=>{let s=d=>{let a=V(i);return d.appendChild(a),d};r.push(s)}),r},Ar=(t=[],e=[])=>{let r=[];return t.forEach((o,i)=>{let s=re(o,e[i]);r.push(s)}),r},Lr=(t=[],e=[])=>{let r=Ar(t,e),o=Rr(t,e);return i=>{if(i){let s=jt(r,i.childNodes);Cr(s),vr(o,i)}return i}},te=Lr;var Pt={select:(t,e)=>r=>{let o=r.value;r.replaceChildren(),ee(t.attributes,e.attributes)(r),te([],e.children)(r);let i=r.querySelector(`option[value="${o}"]`);if(i&&(r.value=o),!i){let s=r.querySelector("option");r.value=s?.value||""}return r}};var me=(t,e)=>r=>{let o=t?V(t):null;return r&&r.replaceWith(o),o},Dr=()=>t=>{t&&t.remove()},jr=(t=void 0,e=void 0)=>t===void 0||e===void 0?Dr():typeof t=="string"||typeof e=="string"?me(e,t):t.tagName!==e.tagName?me(e):e.tagName==="select"?Pt.select(t,e):["pre","code"].includes(e.tagName)?me(e,t):i=>(ee(t.attributes,e.attributes)(i),te(t.children,e.children)(i),i),re=jr;var Pr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("processQueue.getQueue",e)}},H=(t="",e=null)=>{try{S()||(Pr(t)||{}).process(e)}catch(r){n("processQueue",r)}};var It=(t="",e=null)=>{let r=R(e||window.joystick._internal.tree,t,"instanceId");r&&(r.children=[])};var _t=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.instanceId=e?.instanceId,o.instance=e)};var Nt=(t={},e="",r={})=>{for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(u(i)&&i.attributes&&i.attributes["js-i"]&&i.attributes["js-i"]===e){t.children[o]=r;break}u(i)&&Nt(i,e,r)}},Vt=Nt;var Ut=(t={})=>{try{return Object.entries(t).map(([e,r])=>{let[o,...i]=e.split(" ");return{type:o.toLowerCase(),selector:i.join(" "),handler:r}})}catch(e){n("component.events.serialize",e)}};var qt=(t={},e={},r=[])=>{try{let o=Object.keys(t?.events||{})?.length>0?Ut(t?.events):[];for(let i=0;i<o?.length;i+=1){let s=o[i];r.push({...s,instance:t,elements:document.querySelectorAll(`body [js-i="${t.instanceId}"] ${s?.selector}`),handler:function(a){Object.defineProperty(a,"target",{value:a.composedPath()[0]}),s.handler(a,{...t||{},setState:t?.setState.bind(t),...e||{}})}})}if(t?.children){let i=Object.entries(t?.children)?.flatMap(([s,d])=>d);for(let s=0;s<i?.length;s+=1){let d=i[s];qt(d,e,r)}}return r}catch(o){n("component.events.registerListenersFix.getListeners",o)}},Ir=(t={},e={})=>{try{let r=qt(t,e,[]);console.log("GETTING CALLED",r);let o=r?.flatMap((i={})=>[].flatMap.call(i?.elements||[],s=>{let{elements:d=[],...a}=i||{};return{...a,element:s}}));for(let i=0;i<o?.length;i+=1){let{instance:s,element:d,elementSelector:a,type:l,handler:g}=o[i];console.log({element:d,type:l,handler:g}),d.addEventListener(l,g),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:d,elementSelector:a,type:l,handler:g}]}}catch(r){n("component.events.registerListenersFix",r)}},zt=Ir;var Ht=(t={})=>{try{let e=t?._eventListeners||[];if(t?.children){let o=(Object.values(t?.children||{})?.reduce((i=[],s=[])=>[...i,...s],[])).flatMap((i={})=>Ht(i));e=[...e,...o]}return e}catch(e){n("component.events.unregisterListenersFix.getListeners",e)}},_r=(t={})=>{try{let e=Ht(t);for(let r=0;r<e?.length;r+=1){let{instance:o,element:i,type:s,handler:d}=e[r];i.removeEventListener(s,d),o._eventListeners=o._eventListeners?.splice(r,1)}}catch(e){n("component.events.unregisterListenersFix",e)}},Zt=_r;var Bt=class{constructor(e={}){this.parent=e?.parent||null,this.onUpdateChildComponent=this.handleUpdateChildComponentInVDOM,this.updateVirtualDOM=this.handleUpdateVirtualDOM,this.timers={},this.children={},Te(e),lt(this,e),this.data=wt(this)}setDOMNodeOnInstance(){this.DOMNode=document.querySelector(`body [js-i="${this.instanceId}"]`)}async handleFetchData(e={},r={},o={},i=this){let s=await Q(e,r,o,i);return this.data=s,s}handleGetInstance(){return this}handleUpdateVirtualDOM(){if(this.DOMNode){let r=z(this.DOMNode);this.dom.virtual=r}let e=this.parent?R(window.joystick._internal.tree,this.parent?.instanceId,"instanceId"):null;e?.instance&&e.instance.updateVirtualDOM()}onBeforeRender(){if(!S())return{instanceId:this.instanceId}}render(e={}){if(e?.mounting)return Dt(this,e);let r=this.onBeforeRender();Zt(this),It(this.instanceId);let o=N(this,{}),i=re(this.dom.virtual,o.virtual);i&&m(i)&&H("lifecycle.onBeforeMount",()=>{let s=i(this.DOMNode);this.dom.actual=s,this.dom.virtual=o.virtual,zt(this,this.renderMethods),this.setDOMNodeOnInstance(),H("domNodes",()=>{H("lifecycle.onMount",()=>{this.onAfterRender(r,e)})})})}renderToHTML(e={}){return X(this,e)}onAfterRender(e={},r={}){S()||(_t(e.instanceId,this),window.joystick._internal.css.update(),H("lifecycle.onUpdateProps"),r?.afterSetStateRender&&m(r.afterSetStateRender)&&r.afterSetStateRender(),r?.afterRefetchDataRender&&m(r.afterRefetchDataRender)&&r.afterRefetchDataRender(),this.parent&&this.parent.onUpdateChildComponent(this.id,this.instanceId))}setState(e={},r=null){this.state=G(this,{...this.state||{},...e}),this.render({afterSetStateRender:()=>{r&&m(r)&&r()}})}setTimeout(e=null,r=0){e&&(this.timers[U()]=window.setTimeout(e,r))}setInterval(e=null,r=0){e&&(this.timers[U()]=window.setInterval(e,r))}handleUpdateChildComponentInVDOM(e="",r=""){let o=R(window.joystick._internal.tree,this.instanceId,"instanceId"),i=R(window.joystick._internal.tree,r,"instanceId");if(i?.instance?.DOMNode){let s=z(i?.instance?.DOMNode);Vt(o?.instance?.dom?.virtual,i?.instanceId,s)}}},Gt=Bt;var ed=(t={})=>{try{return(e={})=>new Gt({...t,props:e?.props,url:e?.url,translations:e?.translations,api:e?.api,req:e?.req,parent:e?.parent})}catch(e){n("component",e)}};export{ed as default};
21
+ `}}return r}return""}catch(r){n("component.css.compileCSS",r)}};var nr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.state.compile.compileState",r)}},G=(t={},e={})=>{try{return m(e)?nr(t,e):Object.assign({},e)}catch(r){n("component.state.compile",r)}};var ie={onBeforeMount:()=>null,onMount:()=>null,onBeforeUnmount:()=>null,onUpdateProps:()=>null,onRefetchData:()=>null};var st=(t={},e={})=>{try{return e?Object.entries({...ie,...e||{}}).reduce((r={},[o,i])=>(r[o]=()=>i({...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{}):ie}catch(r){n("component.lifecycle.compile",r)}};var K=(t={},e={})=>{try{return Object.entries(e).reduce((r={},[o,i])=>(r[o]=(...s)=>i(...s,{...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{})}catch{n("component.methods.compile")}};var ne=(t={})=>{try{return{...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window!="undefined"){let o=new URL(window.location);o.searchParams.append(e,r),window.history.pushState({},"",o)}},unset:(e="")=>{if(typeof window!="undefined"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},isActive:(e="")=>C(e)&&t?.route!=="*"?e===(typeof location!="undefined"?location.pathname:t.path):!1}}catch(e){n("component.url.compile",e)}};var S=()=>typeof window=="undefined";var I=null,W=0,at=(t={},e=null)=>{try{let r=t?.url;t?.query&&(r=`${r}?${new URLSearchParams(t.query).toString()}`);let o=new WebSocket(r);I&&(clearInterval(I),I=null);let i={client:o,send:(s={})=>o.send(JSON.stringify(s))};return o.addEventListener("open",()=>{t?.options?.logging&&console.log(`[joystick.websockets] Connected to ${t?.url}`),t?.events?.onOpen&&t.events.onOpen(i),W=0}),o.addEventListener("message",s=>{s?.data&&t?.events?.onMessage&&t.events.onMessage(JSON.parse(s.data||{}),i)}),o.addEventListener("close",s=>{t?.options?.logging&&console.log(`[joystick.websockets] Disconnected from ${t?.url}`),t?.events?.onClose&&t.events.onClose(s?.code,s?.reason,i),o=null;let d=[1e3,1001].includes(s?.code);t?.options?.autoReconnect&&!I&&!d&&(I=setInterval(()=>{o=null,W<(t?.options?.reconnectAttempts||12)?(at(t,e),t?.options?.logging&&console.log(`[joystick.websockets] Attempting to reconnect (${W+1}/12)...`),W+=1):clearInterval(I)},t?.options?.reconnectDelayInSeconds*1e3||5e3))}),e&&e(i),i}catch(r){n("websockets.client",r)}},dt=at;var sr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!j(r)?Object.assign({},r):{}}catch(r){n("component.props.compileDefaultProps.compile",r)}},ct=(t={},e={})=>{try{return m(e)?sr(t,e):Object.assign({},e)}catch(r){n("component.props.compileDefaultProps",r)}};var lt=(t={},e={})=>{try{t.options=e||{},t.id=e?._componentId||null,t.instanceId=U(8),t.ssrId=e?._ssrId||null,t.css=nt(),t.data=B(e?.dataFromSSR,e?._componentId),t.defaultProps=ct(t,e?.defaultProps),t.props=it(t?.defaultProps,e?.props),t.state=G(t,e?.state),t.events=e?.events||{},t.lifecycle=st(t,e?.lifecycle),t.methods=K(t,e?.methods),t.wrapper=e?.wrapper||{},t.translations=e?.translations||{},t.validateForm=ot,t.DOMNode=null,t.dom={},t.dom.virtual={},t.dom.actual={};let r=!S();if(r||(t.url=ne(e?.url)),r&&window.__joystick_url__&&(t.url=ne(window.__joystick_url__)),r&&e?.websockets&&m(e?.websockets)){let o=e.websockets(t),i=u(o)&&Object.entries(o);for(let s=0;s<i?.length;s+=1){let[d,a]=i[s];dt({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/${d}`,options:a?.options||{},query:a?.query||{},events:a?.events||{}},(l={})=>{t.websockets={...t.websockets||{},[d]:l}})}}}catch(r){n("component.registerOptions",r)}};var _=(t="",e=[])=>{try{console.error(`${t} failed with the following errors:`),e.forEach(r=>{console.log(r.message),r.stack&&console.log(r.stack)})}catch(r){n(t,r)}};var J=(t="{}")=>{try{return JSON.parse(t)}catch{return t}};var ar=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.get.handleParseResponse",e)}},mt=(t="",e={})=>{try{return typeof window.fetch!="undefined"&&!e?.skip?new Promise((r,o)=>{let i=e.input?JSON.stringify(e.input):null,s=e.output?JSON.stringify(e.output):null,d=`${window.location.origin}/api/_getters/${t}?input=${i}&output=${s}`,a=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(d,{method:"GET",mode:"cors",headers:{...e?.headers||{},"x-joystick-csrf":a},credentials:"include"}).then(async l=>{let g=await ar(l);return g?.errors?(_("get request",g.errors),o(g)):r(g)}).catch(l=>(_("get request",[l]),o({errors:[l]})))}):Promise.resolve()}catch(r){n("get request",r)}};var dr=async(t={})=>{try{let e=await t.text();return J(e)}catch(e){n("api.set.handleParseResponse",e)}},cr=(t={})=>{try{return JSON.stringify(t)}catch(e){n("api.set.getBody",e)}},pt=(t="",e={})=>{try{return typeof window.fetch!="undefined"?new Promise((r,o)=>{let i=`${window.location.origin}/api/_setters/${t}`,s=cr(e),d=document.querySelector('[name="csrf"]')?.getAttribute("content");return fetch(i,{method:"POST",mode:"cors",headers:{...e?.headers||{},"Content-Type":"application/json","x-joystick-csrf":d},body:s,credentials:"include"}).then(async a=>{let l=await dr(a);return l?.errors?(_("set request",l.errors),o(l)):r(l)}).catch(a=>(_("set request",[a]),o({errors:[a]})))}):Promise.resolve()}catch(r){n("set request",r)}};var ut={get:mt,set:pt};var lr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("addToQueue.getQueue",e)}},q=(t="",e=null)=>{try{S()||(lr(t)||{}).array.push({callback:e})}catch(r){n("addToQueue",r)}};var Q=async(t={},e={},r={},o={})=>{try{if(o?.options?.data&&m(o.options.data)){let i=await o.options.data(t,e,r,o);return Promise.resolve(i)}return Promise.resolve()}catch(i){n("component.data.fetch",i)}};var ft=(t={},e={},r={})=>{try{return{...t,refetch:async(o={})=>{let i=await Q(ut,e,o,r);return r.data=ft(i,e,r),window.__joystick_data__[r?.id]=i,r.render({afterRefetchDataRender:()=>{r?.lifecycle?.onRefetchData&&r?.lifecycle?.onRefetchData(r)}}),i}}}catch(o){n("component.data.compile",o)}},ht=ft;var wt=(t={})=>{try{if(!S()&&window.__joystick_data__&&window.__joystick_data__[t?.id]){let e=window.__joystick_data__[t?.id]||{},r=window.__joystick_req__||{};return ht(e,r,t)}return t?.data||{}}catch(e){n("component.loadDataFromWindow",e)}};var bt=or(yt());var xt=(t={},e="",r="id")=>{try{let o=t&&t.id;if(u(t)&&o){let i=Object.keys(t);for(let s=0;s<i.length;s+=1){let d=i[s],a=t[d];if(d===r&&a===e)return t;if(d==="children"&&Array.isArray(a))for(let l=0;l<a.length;l+=1){let g=a[l],y=xt(g,e,r);if(y!==null)return y}}}return null}catch(o){n("component.findComponentInTreeByField",o)}},R=xt;var gt=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.children=[...o.children||[],e])};var mr=(t={},e={},r=null)=>{try{let o=N(t,{includeActual:!0,existingChildren:r});return t.dom=o,t.setDOMNodeOnInstance(),e.renderedComponent=t,o.html.wrapped}catch(o){n("component.renderMethods.component.renderForClient",o)}},pr=(t={})=>{try{return t.renderToHTML({ssrTree:t.parent.ssrTree,translations:t.parent.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t.parent?.dataFromSSR}).wrapped}catch(e){n("component.renderMethods.component.renderToHTMLForSSR",e)}},ur=(t={})=>{try{return t.parent.ssrTree.dataFunctions.push(async()=>{try{let e=await t.options.data(t.parent.options.api,t.parent.options.req);return t.data=e||{},{componentId:t.id,ssrId:t.ssrId,data:e}}catch(e){return{componentId:t.id,ssrId:t.ssrId,data:null,error:e}}}),t.renderToHTML({ssrTree:t?.parent?.ssrTree,translations:t?.parent?.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t?.parent?.dataFromSSR})}catch(e){n("component.renderMethods.component.collectDataFunctionsForSSR",e)}},fr=(t={})=>{try{let e={id:t.id,instanceId:t.instanceId,instance:t,children:[]};gt(t.parent.instanceId,e,t.parent&&t.parent.ssrTree||null)}catch(e){n("component.renderMethods.component.handleAddComponentToParent",e)}},hr=(t={},e={})=>{try{!t.renderedComponent&&e.options&&e.options.lifecycle&&(e.options.lifecycle.onBeforeMount&&q("lifecycle.onBeforeMount",()=>{e.options.lifecycle.onBeforeMount(e)}),!t.renderedComponent&&e.options.lifecycle.onMount&&q("lifecycle.onMount",()=>{e.options.lifecycle.onMount(e)}))}catch(r){n("component.renderMethods.component.handleLifecycle",r)}},wr=(t={},e={},r={})=>{try{!e.walkingTreeForSSR&&t?.options?.lifecycle?.onUpdateProps&&(0,bt.diff)(e?.existingPropsMap,r)?.length>0&&q("lifecycle.onUpdateProps",()=>{let i=e?.existingPropsMap&&e?.existingPropsMap[t.id];t.options.lifecycle.onUpdateProps(i||{},r,t)})}catch(o){n("component.renderMethods.component.handleOnChangeProps",o)}},yr=function(){return function(e=null,r={},o={}){let i=e({props:r,url:o.url,translations:o.translations,api:o.options.api,req:o.options.req,dataFromSSR:o?.dataFromSSR,parent:o}),s=o?.existingStateMap[i.id]||{},d=o.children[i.id]||[],a=s[d?.length];return i.state=a?.state||i.state,o.children[i.id]=[...o.children[i.id]||[],i],i.parent=o,wr(i,o,r),q("lifecycle.onMount",()=>{i.setDOMNodeOnInstance()}),hr(this,i),i.parent&&fr(i),i.options.data&&i.parent.walkingTreeForSSR&&i.parent.ssrTree.dataFunctions?ur(i):i.parent&&i.parent.ssrTree?pr(i):mr(i,this,a?.children)}},xr=function(e,r){try{let o=this;return new yr().bind({})(e,r,o)}catch(o){n("component.renderMethods.component",o)}},se=xr;var gr=function(e=[],r=null){try{return m(r)&&e&&Array.isArray(e)?e.map((o,i)=>r(o,i)).join(""):""}catch(o){n("component.renderMethods.each",o)}},ae=gr;var br=function(e="",r={}){try{let o=S()?this.translations:window.__joystick_i18n__;if(!o||!o[e])return"";let i=Object.entries(r);return i.length>0?i.reduce((s,[d,a])=>s.replace(`{{${d}}}`,a),o[e]):o[e]}catch(o){n("component.renderMethods.i18n",o)}},de=br;var $r=function(e=!1,r=""){try{return this?.renderingHTMLWithDataForSSR||e?`<when>${r.trim()}</when>`:"<when> </when>"}catch(o){n("component.renderMethods.when",o)}},ce=$r;var $t={c:se,component:se,e:ae,each:ae,i:de,i18n:de,w:ce,when:ce};var Ft=(t={},e={})=>{try{return Object.entries($t).reduce((r,[o,i])=>(r[o]=i.bind({...t,...e}),r),{})}catch(r){n("component.renderMethods.compile",r)}};var Et=(t={})=>{try{return Object.entries(t)?.reduce((e={},[r,o]={})=>(e[r]=o?.map((i={})=>({state:i?.state,children:Et(i?.children)})),e),{})}catch(e){n("component.render.getExistingStateMap.buildMapForChildren",e)}},Mt=(t={})=>{try{return Et(t)}catch(e){n("component.render.getExistingStateMap",e)}};var kt=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),Fr=new RegExp(/\n/g);var Er=(t="")=>{try{return(t.match(kt)||[]).forEach(r=>{t=t.replace(r,"")}),t}catch(e){n("component.render.sanitizeHTML.removeCommentedCode",e)}},St=(t="")=>{try{let e=`${t}`;return e=Er(e),e}catch(e){n("component.render.sanitizeHTML",e)}};var Ot=(t={},e="")=>{try{let{wrapper:r=null,ssrId:o=null,id:i=null,instanceId:s=null}=t;return`<div ${r?.id?`id="${r.id}" `:""}${r?.classList?`class="${r.classList?.join(" ")}" `:""}js-ssrId="${o}" js-c="${i}" js-i="${s}">${e}</div>`}catch(r){n("component.render.wrapHTML",r)}};var Tt=(t={},e=[])=>{try{let r=[...e],o=Object.entries(t);for(let i=0;i<o?.length;i+=1){let[s,d]=o[i];for(let a=0;a<d?.length;a+=1){let l=d[a];Object.entries(l?.timers)?.length>0&&r.push(...Object.values(l?.timers)),Object.entries(l?.children)?.length>0&&Tt(l?.children,r)}}if(r?.length>0)for(let i=0;i<r?.length;i+=1)clearTimeout(r[i])}catch(r){n("component.render.clearTimersOnChildren",r)}},vt=Tt;var X=(t={},e={})=>{try{e?.dataFromSSR&&(t.data=B(e.dataFromSSR,t.id)||{}),vt(t?.children);let r=Mt(e?.existingChildren||t?.children)||{};t.children={},t.renderMethods=Ft({...t,existingStateMap:r,translations:e?.translations||t.translations||{},ssrTree:e?.ssrTree,walkingTreeForSSR:e?.walkingTreeForSSR,renderingHTMLWithDataForSSR:e?.renderingHTMLWithDataForSSR,dataFromSSR:e?.dataFromSSR}),t.methods=K(t,t.options.methods);let o=t.options.render({...t||{},setState:t.setState.bind(t),...t.renderMethods||{}}),i=St(o),s=Ot(t,i);return{unwrapped:i,wrapped:s}}catch(r){n("component.render.toHTML",r)}};var Mr=(t={})=>{try{return Object.values(t).reduce((e={},r)=>(e[r.name]=r.value,e),{})}catch(e){n("component.virtualDOM.build.parseAttributeMap",e)}},Ct=(t={})=>{try{return t.tagName==="WHEN"?[].flatMap.call(t?.childNodes,e=>e?.tagName==="WHEN"?Ct(e):le(e)):le(t)}catch(e){n("component.virtualDOM.build.flattenWhenTags",e)}},le=(t={})=>{try{let e=t&&t.tagName&&t.tagName.toLowerCase()||"text",r={tagName:e,attributes:Mr(t.attributes),children:[].flatMap.call(t.childNodes,o=>Ct(o))};return e==="text"&&(r=t.textContent),r}catch(e){n("component.virtualDOM.build",e)}},z=le;var kr=(t="")=>{try{let e=document.createElement("div");return e.innerHTML=t,e?.childNodes[0]}catch(e){n("component.virtualDOM.build.convertHTMLToDOM",e)}},Rt=(t="")=>{try{let e=kr(t);return z(e)}catch(e){n("component.virtualDOM.build",e)}};var At=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}};var Sr=(t={})=>{try{let e=document.createElement(t.tagName),r=Object.entries(t.attributes);for(let o=0;o<r.length;o+=1){let[i,s]=r[o];At(i)&&e.setAttribute(i,s)}for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(i){let s=Lt(i);e.appendChild(s)}}return e}catch(e){n("component.virtualDOM.renderTreeToDOM.renderElement",e)}},Lt=(t=null)=>{try{return C(t)?document.createTextNode(t):Sr(t)}catch(e){n("component.virtualDOM.renderTreeToDOM",e)}},V=Lt;var N=(t={},e={})=>{try{let r=X(t,{existingChildren:e?.existingChildren}),o=Rt(r.wrapped,t),i=e.includeActual&&o?V(o):null;return{html:r,virtual:o,actual:i}}catch(r){n("component.render.getUpdatedDOM",r)}};var Dt=(t={},e={})=>{try{let r=N(t,{includeActual:!0,existingChildren:e?.existingChildren});return t.dom=r,r.actual}catch(r){n("component.render.forMount",r)}};var Or=(t={},e={})=>{let r=[];for(let[o,i]of Object.entries(e))r.push(s=>(s&&s.setAttribute&&s.setAttribute(o,i),s));for(let o in t)o in e||r.push(i=>(i&&i.removeAttribute&&i.removeAttribute(o),i));return o=>{for(let i of r)i&&typeof i=="function"&&i(o)}},ee=Or;var Tr=(t=[],e=[])=>{let r=[],o=Math.max(t.length,e.length);for(let i=0;i<o;i+=1){let s=t[i],d=e[i];r.push([s,d])}return r},jt=Tr;var vr=(t=[],e)=>{t.forEach(r=>{r&&typeof r=="function"&&r(e)})},Cr=(t=[])=>{t.forEach(([e,r])=>{e&&typeof e=="function"&&e(r)})},Rr=(t=[],e=[])=>{let r=[];return e.slice(t.length).forEach(i=>{let s=d=>{let a=V(i);return d.appendChild(a),d};r.push(s)}),r},Ar=(t=[],e=[])=>{let r=[];return t.forEach((o,i)=>{let s=re(o,e[i]);r.push(s)}),r},Lr=(t=[],e=[])=>{let r=Ar(t,e),o=Rr(t,e);return i=>{if(i){let s=jt(r,i.childNodes);Cr(s),vr(o,i)}return i}},te=Lr;var Pt={select:(t,e)=>r=>{let o=r.value;r.replaceChildren(),ee(t.attributes,e.attributes)(r),te([],e.children)(r);let i=r.querySelector(`option[value="${o}"]`);if(i&&(r.value=o),!i){let s=r.querySelector("option");r.value=s?.value||""}return r}};var me=(t,e)=>r=>{let o=t?V(t):null;return r&&r.replaceWith(o),o},Dr=()=>t=>{t&&t.remove()},jr=(t=void 0,e=void 0)=>t===void 0||e===void 0?Dr():typeof t=="string"||typeof e=="string"?me(e,t):t.tagName!==e.tagName?me(e):e.tagName==="select"?Pt.select(t,e):["pre","code"].includes(e.tagName)?me(e,t):i=>(ee(t.attributes,e.attributes)(i),te(t.children,e.children)(i),i),re=jr;var Pr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){n("processQueue.getQueue",e)}},H=(t="",e=null)=>{try{S()||(Pr(t)||{}).process(e)}catch(r){n("processQueue",r)}};var It=(t="",e=null)=>{let r=R(e||window.joystick._internal.tree,t,"instanceId");r&&(r.children=[])};var _t=(t="",e={},r=null)=>{let o=R(r||window.joystick._internal.tree,t,"instanceId");o&&(o.instanceId=e?.instanceId,o.instance=e)};var Nt=(t={},e="",r={})=>{for(let o=0;o<t?.children?.length;o+=1){let i=t?.children[o];if(u(i)&&i.attributes&&i.attributes["js-i"]&&i.attributes["js-i"]===e){t.children[o]=r;break}u(i)&&Nt(i,e,r)}},Vt=Nt;var Ut=(t={})=>{try{return Object.entries(t).map(([e,r])=>{let[o,...i]=e.split(" ");return{type:o.toLowerCase(),selector:i.join(" "),handler:r}})}catch(e){n("component.events.serialize",e)}};var qt=(t={},e={},r=[])=>{try{let o=Object.keys(t?.events||{})?.length>0?Ut(t?.events):[];for(let i=0;i<o?.length;i+=1){let s=o[i];r.push({...s,instance:t,elements:document.querySelectorAll(`body [js-i="${t.instanceId}"] ${s?.selector}`),handler:function(a){console.log("DOM EVENT",a),Object.defineProperty(a,"target",{value:a.composedPath()[0]}),s.handler(a,{...t||{},setState:t?.setState.bind(t),...e||{}})}})}if(t?.children){let i=Object.entries(t?.children)?.flatMap(([s,d])=>d);for(let s=0;s<i?.length;s+=1){let d=i[s];qt(d,e,r)}}return r}catch(o){n("component.events.registerListenersFix.getListeners",o)}},Ir=(t={},e={})=>{try{let r=qt(t,e,[]);console.log("GETTING CALLED",r);let o=r?.flatMap((i={})=>[].flatMap.call(i?.elements||[],s=>{let{elements:d=[],...a}=i||{};return{...a,element:s}}));for(let i=0;i<o?.length;i+=1){let{instance:s,element:d,elementSelector:a,type:l,handler:g}=o[i];console.log({element:d,type:l,handler:g}),d.addEventListener(l,g),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:d,elementSelector:a,type:l,handler:g}]}}catch(r){n("component.events.registerListenersFix",r)}},zt=Ir;var Ht=(t={})=>{try{let e=t?._eventListeners||[];if(t?.children){let o=(Object.values(t?.children||{})?.reduce((i=[],s=[])=>[...i,...s],[])).flatMap((i={})=>Ht(i));e=[...e,...o]}return e}catch(e){n("component.events.unregisterListenersFix.getListeners",e)}},_r=(t={})=>{try{let e=Ht(t);for(let r=0;r<e?.length;r+=1){let{instance:o,element:i,type:s,handler:d}=e[r];i.removeEventListener(s,d),o._eventListeners=o._eventListeners?.splice(r,1)}}catch(e){n("component.events.unregisterListenersFix",e)}},Zt=_r;var Bt=class{constructor(e={}){this.parent=e?.parent||null,this.onUpdateChildComponent=this.handleUpdateChildComponentInVDOM,this.updateVirtualDOM=this.handleUpdateVirtualDOM,this.timers={},this.children={},Te(e),lt(this,e),this.data=wt(this)}setDOMNodeOnInstance(){this.DOMNode=document.querySelector(`body [js-i="${this.instanceId}"]`)}async handleFetchData(e={},r={},o={},i=this){let s=await Q(e,r,o,i);return this.data=s,s}handleGetInstance(){return this}handleUpdateVirtualDOM(){if(this.DOMNode){let r=z(this.DOMNode);this.dom.virtual=r}let e=this.parent?R(window.joystick._internal.tree,this.parent?.instanceId,"instanceId"):null;e?.instance&&e.instance.updateVirtualDOM()}onBeforeRender(){if(!S())return{instanceId:this.instanceId}}render(e={}){if(e?.mounting)return Dt(this,e);let r=this.onBeforeRender();Zt(this),It(this.instanceId);let o=N(this,{}),i=re(this.dom.virtual,o.virtual);i&&m(i)&&H("lifecycle.onBeforeMount",()=>{let s=i(this.DOMNode);this.dom.actual=s,this.dom.virtual=o.virtual,zt(this,this.renderMethods),this.setDOMNodeOnInstance(),H("domNodes",()=>{H("lifecycle.onMount",()=>{this.onAfterRender(r,e)})})})}renderToHTML(e={}){return X(this,e)}onAfterRender(e={},r={}){S()||(_t(e.instanceId,this),window.joystick._internal.css.update(),H("lifecycle.onUpdateProps"),r?.afterSetStateRender&&m(r.afterSetStateRender)&&r.afterSetStateRender(),r?.afterRefetchDataRender&&m(r.afterRefetchDataRender)&&r.afterRefetchDataRender(),this.parent&&this.parent.onUpdateChildComponent(this.id,this.instanceId))}setState(e={},r=null){this.state=G(this,{...this.state||{},...e}),this.render({afterSetStateRender:()=>{r&&m(r)&&r()}})}setTimeout(e=null,r=0){e&&(this.timers[U()]=window.setTimeout(e,r))}setInterval(e=null,r=0){e&&(this.timers[U()]=window.setInterval(e,r))}handleUpdateChildComponentInVDOM(e="",r=""){let o=R(window.joystick._internal.tree,this.instanceId,"instanceId"),i=R(window.joystick._internal.tree,r,"instanceId");if(i?.instance?.DOMNode){let s=z(i?.instance?.DOMNode);Vt(o?.instance?.dom?.virtual,i?.instanceId,s)}}},Gt=Bt;var ed=(t={})=>{try{return(e={})=>new Gt({...t,props:e?.props,url:e?.url,translations:e?.translations,api:e?.api,req:e?.req,parent:e?.parent})}catch(e){n("component",e)}};export{ed as default};
package/dist/index.js CHANGED
@@ -18,4 +18,4 @@ var Er=Object.create;var de=Object.defineProperty;var Fr=Object.getOwnPropertyDe
18
18
  @media screen and (max-height: ${R}px) {
19
19
  ${typeof f=="function"?f(e):f}
20
20
  }
21
- `}}return r}return""}catch(r){i("component.css.compileCSS",r)}};var Ir=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!I(r)?Object.assign({},r):{}}catch(r){i("component.state.compile.compileState",r)}},ee=(t={},e={})=>{try{return m(e)?Ir(t,e):Object.assign({},e)}catch(r){i("component.state.compile",r)}};var le={onBeforeMount:()=>null,onMount:()=>null,onBeforeUnmount:()=>null,onUpdateProps:()=>null,onRefetchData:()=>null};var Ct=(t={},e={})=>{try{return e?Object.entries({...le,...e||{}}).reduce((r={},[o,n])=>(r[o]=()=>n({...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{}):le}catch(r){i("component.lifecycle.compile",r)}};var te=(t={},e={})=>{try{return Object.entries(e).reduce((r={},[o,n])=>(r[o]=(...s)=>n(...s,{...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{})}catch{i("component.methods.compile")}};var me=(t={})=>{try{return{...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window!="undefined"){let o=new URL(window.location);o.searchParams.append(e,r),window.history.pushState({},"",o)}},unset:(e="")=>{if(typeof window!="undefined"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},isActive:(e="")=>O(e)&&t?.route!=="*"?e===(typeof location!="undefined"?location.pathname:t.path):!1}}catch(e){i("component.url.compile",e)}};var qr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!I(r)?Object.assign({},r):{}}catch(r){i("component.props.compileDefaultProps.compile",r)}},Rt=(t={},e={})=>{try{return m(e)?qr(t,e):Object.assign({},e)}catch(r){i("component.props.compileDefaultProps",r)}};var At=(t={},e={})=>{try{t.options=e||{},t.id=e?._componentId||null,t.instanceId=_(8),t.ssrId=e?._ssrId||null,t.css=X(),t.data=Y(e?.dataFromSSR,e?._componentId),t.defaultProps=Rt(t,e?.defaultProps),t.props=vt(t?.defaultProps,e?.props),t.state=ee(t,e?.state),t.events=e?.events||{},t.lifecycle=Ct(t,e?.lifecycle),t.methods=te(t,e?.methods),t.wrapper=e?.wrapper||{},t.translations=e?.translations||{},t.validateForm=Ot,t.DOMNode=null,t.dom={},t.dom.virtual={},t.dom.actual={};let r=!F();if(r||(t.url=me(e?.url)),r&&window.__joystick_url__&&(t.url=me(window.__joystick_url__)),r&&e?.websockets&&m(e?.websockets)){let o=e.websockets(t),n=u(o)&&Object.entries(o);for(let s=0;s<n?.length;s+=1){let[c,a]=n[s];Q({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/${c}`,options:a?.options||{},query:a?.query||{},events:a?.events||{}},(l={})=>{t.websockets={...t.websockets||{},[c]:l}})}}}catch(r){i("component.registerOptions",r)}};var Nr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){i("addToQueue.getQueue",e)}},G=(t="",e=null)=>{try{F()||(Nr(t)||{}).array.push({callback:e})}catch(r){i("addToQueue",r)}};var re=async(t={},e={},r={},o={})=>{try{if(o?.options?.data&&m(o.options.data)){let n=await o.options.data(t,e,r,o);return Promise.resolve(n)}return Promise.resolve()}catch(n){i("component.data.fetch",n)}};var Lt=(t={},e={},r={})=>{try{return{...t,refetch:async(o={})=>{let n=await re(Z,e,o,r);return r.data=Lt(n,e,r),window.__joystick_data__[r?.id]=n,r.render({afterRefetchDataRender:()=>{r?.lifecycle?.onRefetchData&&r?.lifecycle?.onRefetchData(r)}}),n}}}catch(o){i("component.data.compile",o)}},jt=Lt;var Dt=(t={})=>{try{if(!F()&&window.__joystick_data__&&window.__joystick_data__[t?.id]){let e=window.__joystick_data__[t?.id]||{},r=window.__joystick_req__||{};return jt(e,r,t)}return t?.data||{}}catch(e){i("component.loadDataFromWindow",e)}};var qt=Cr(_t());var Pt=(t={},e="",r="id")=>{try{let o=t&&t.id;if(u(t)&&o){let n=Object.keys(t);for(let s=0;s<n.length;s+=1){let c=n[s],a=t[c];if(c===r&&a===e)return t;if(c==="children"&&Array.isArray(a))for(let l=0;l<a.length;l+=1){let x=a[l],y=Pt(x,e,r);if(y!==null)return y}}}return null}catch(o){i("component.findComponentInTreeByField",o)}},L=Pt;var It=(t="",e={},r=null)=>{let o=L(r||window.joystick._internal.tree,t,"instanceId");o&&(o.children=[...o.children||[],e])};var Vr=(t={},e={},r=null)=>{try{let o=z(t,{includeActual:!0,existingChildren:r});return t.dom=o,t.setDOMNodeOnInstance(),e.renderedComponent=t,o.html.wrapped}catch(o){i("component.renderMethods.component.renderForClient",o)}},Ur=(t={})=>{try{return t.renderToHTML({ssrTree:t.parent.ssrTree,translations:t.parent.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t.parent?.dataFromSSR}).wrapped}catch(e){i("component.renderMethods.component.renderToHTMLForSSR",e)}},Hr=(t={})=>{try{return t.parent.ssrTree.dataFunctions.push(async()=>{try{let e=await t.options.data(t.parent.options.api,t.parent.options.req);return t.data=e||{},{componentId:t.id,ssrId:t.ssrId,data:e}}catch(e){return{componentId:t.id,ssrId:t.ssrId,data:null,error:e}}}),t.renderToHTML({ssrTree:t?.parent?.ssrTree,translations:t?.parent?.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t?.parent?.dataFromSSR})}catch(e){i("component.renderMethods.component.collectDataFunctionsForSSR",e)}},zr=(t={})=>{try{let e={id:t.id,instanceId:t.instanceId,instance:t,children:[]};It(t.parent.instanceId,e,t.parent&&t.parent.ssrTree||null)}catch(e){i("component.renderMethods.component.handleAddComponentToParent",e)}},Br=(t={},e={})=>{try{!t.renderedComponent&&e.options&&e.options.lifecycle&&(e.options.lifecycle.onBeforeMount&&G("lifecycle.onBeforeMount",()=>{e.options.lifecycle.onBeforeMount(e)}),!t.renderedComponent&&e.options.lifecycle.onMount&&G("lifecycle.onMount",()=>{e.options.lifecycle.onMount(e)}))}catch(r){i("component.renderMethods.component.handleLifecycle",r)}},Zr=(t={},e={},r={})=>{try{!e.walkingTreeForSSR&&t?.options?.lifecycle?.onUpdateProps&&(0,qt.diff)(e?.existingPropsMap,r)?.length>0&&G("lifecycle.onUpdateProps",()=>{let n=e?.existingPropsMap&&e?.existingPropsMap[t.id];t.options.lifecycle.onUpdateProps(n||{},r,t)})}catch(o){i("component.renderMethods.component.handleOnChangeProps",o)}},Gr=function(){return function(e=null,r={},o={}){let n=e({props:r,url:o.url,translations:o.translations,api:o.options.api,req:o.options.req,dataFromSSR:o?.dataFromSSR,parent:o}),s=o?.existingStateMap[n.id]||{},c=o.children[n.id]||[],a=s[c?.length];return n.state=a?.state||n.state,o.children[n.id]=[...o.children[n.id]||[],n],n.parent=o,Zr(n,o,r),G("lifecycle.onMount",()=>{n.setDOMNodeOnInstance()}),Br(this,n),n.parent&&zr(n),n.options.data&&n.parent.walkingTreeForSSR&&n.parent.ssrTree.dataFunctions?Hr(n):n.parent&&n.parent.ssrTree?Ur(n):Vr(n,this,a?.children)}},Wr=function(e,r){try{let o=this;return new Gr().bind({})(e,r,o)}catch(o){i("component.renderMethods.component",o)}},ue=Wr;var Kr=function(e=[],r=null){try{return m(r)&&e&&Array.isArray(e)?e.map((o,n)=>r(o,n)).join(""):""}catch(o){i("component.renderMethods.each",o)}},pe=Kr;var Jr=function(e="",r={}){try{let o=F()?this.translations:window.__joystick_i18n__;if(!o||!o[e])return"";let n=Object.entries(r);return n.length>0?n.reduce((s,[c,a])=>s.replace(`{{${c}}}`,a),o[e]):o[e]}catch(o){i("component.renderMethods.i18n",o)}},fe=Jr;var Qr=function(e=!1,r=""){try{return this?.renderingHTMLWithDataForSSR||e?`<when>${r.trim()}</when>`:"<when> </when>"}catch(o){i("component.renderMethods.when",o)}},he=Qr;var Nt={c:ue,component:ue,e:pe,each:pe,i:fe,i18n:fe,w:he,when:he};var Vt=(t={},e={})=>{try{return Object.entries(Nt).reduce((r,[o,n])=>(r[o]=n.bind({...t,...e}),r),{})}catch(r){i("component.renderMethods.compile",r)}};var Ut=(t={})=>{try{return Object.entries(t)?.reduce((e={},[r,o]={})=>(e[r]=o?.map((n={})=>({state:n?.state,children:Ut(n?.children)})),e),{})}catch(e){i("component.render.getExistingStateMap.buildMapForChildren",e)}},Ht=(t={})=>{try{return Ut(t)}catch(e){i("component.render.getExistingStateMap",e)}};var zt=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),Yr=new RegExp(/\n/g);var Xr=(t="")=>{try{return(t.match(zt)||[]).forEach(r=>{t=t.replace(r,"")}),t}catch(e){i("component.render.sanitizeHTML.removeCommentedCode",e)}},Bt=(t="")=>{try{let e=`${t}`;return e=Xr(e),e}catch(e){i("component.render.sanitizeHTML",e)}};var Zt=(t={},e="")=>{try{let{wrapper:r=null,ssrId:o=null,id:n=null,instanceId:s=null}=t;return`<div ${r?.id?`id="${r.id}" `:""}${r?.classList?`class="${r.classList?.join(" ")}" `:""}js-ssrId="${o}" js-c="${n}" js-i="${s}">${e}</div>`}catch(r){i("component.render.wrapHTML",r)}};var Gt=(t={},e=[])=>{try{let r=[...e],o=Object.entries(t);for(let n=0;n<o?.length;n+=1){let[s,c]=o[n];for(let a=0;a<c?.length;a+=1){let l=c[a];Object.entries(l?.timers)?.length>0&&r.push(...Object.values(l?.timers)),Object.entries(l?.children)?.length>0&&Gt(l?.children,r)}}if(r?.length>0)for(let n=0;n<r?.length;n+=1)clearTimeout(r[n])}catch(r){i("component.render.clearTimersOnChildren",r)}},Wt=Gt;var ne=(t={},e={})=>{try{e?.dataFromSSR&&(t.data=Y(e.dataFromSSR,t.id)||{}),Wt(t?.children);let r=Ht(e?.existingChildren||t?.children)||{};t.children={},t.renderMethods=Vt({...t,existingStateMap:r,translations:e?.translations||t.translations||{},ssrTree:e?.ssrTree,walkingTreeForSSR:e?.walkingTreeForSSR,renderingHTMLWithDataForSSR:e?.renderingHTMLWithDataForSSR,dataFromSSR:e?.dataFromSSR}),t.methods=te(t,t.options.methods);let o=t.options.render({...t||{},setState:t.setState.bind(t),...t.renderMethods||{}}),n=Bt(o),s=Zt(t,n);return{unwrapped:n,wrapped:s}}catch(r){i("component.render.toHTML",r)}};var eo=(t={})=>{try{return Object.values(t).reduce((e={},r)=>(e[r.name]=r.value,e),{})}catch(e){i("component.virtualDOM.build.parseAttributeMap",e)}},Kt=(t={})=>{try{return t.tagName==="WHEN"?[].flatMap.call(t?.childNodes,e=>e?.tagName==="WHEN"?Kt(e):we(e)):we(t)}catch(e){i("component.virtualDOM.build.flattenWhenTags",e)}},we=(t={})=>{try{let e=t&&t.tagName&&t.tagName.toLowerCase()||"text",r={tagName:e,attributes:eo(t.attributes),children:[].flatMap.call(t.childNodes,o=>Kt(o))};return e==="text"&&(r=t.textContent),r}catch(e){i("component.virtualDOM.build",e)}},W=we;var to=(t="")=>{try{let e=document.createElement("div");return e.innerHTML=t,e?.childNodes[0]}catch(e){i("component.virtualDOM.build.convertHTMLToDOM",e)}},Jt=(t="")=>{try{let e=to(t);return W(e)}catch(e){i("component.virtualDOM.build",e)}};var Qt=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}};var ro=(t={})=>{try{let e=document.createElement(t.tagName),r=Object.entries(t.attributes);for(let o=0;o<r.length;o+=1){let[n,s]=r[o];Qt(n)&&e.setAttribute(n,s)}for(let o=0;o<t?.children?.length;o+=1){let n=t?.children[o];if(n){let s=Yt(n);e.appendChild(s)}}return e}catch(e){i("component.virtualDOM.renderTreeToDOM.renderElement",e)}},Yt=(t=null)=>{try{return O(t)?document.createTextNode(t):ro(t)}catch(e){i("component.virtualDOM.renderTreeToDOM",e)}},B=Yt;var z=(t={},e={})=>{try{let r=ne(t,{existingChildren:e?.existingChildren}),o=Jt(r.wrapped,t),n=e.includeActual&&o?B(o):null;return{html:r,virtual:o,actual:n}}catch(r){i("component.render.getUpdatedDOM",r)}};var Xt=(t={},e={})=>{try{let r=z(t,{includeActual:!0,existingChildren:e?.existingChildren});return t.dom=r,r.actual}catch(r){i("component.render.forMount",r)}};var oo=(t={},e={})=>{let r=[];for(let[o,n]of Object.entries(e))r.push(s=>(s&&s.setAttribute&&s.setAttribute(o,n),s));for(let o in t)o in e||r.push(n=>(n&&n.removeAttribute&&n.removeAttribute(o),n));return o=>{for(let n of r)n&&typeof n=="function"&&n(o)}},ie=oo;var no=(t=[],e=[])=>{let r=[],o=Math.max(t.length,e.length);for(let n=0;n<o;n+=1){let s=t[n],c=e[n];r.push([s,c])}return r},er=no;var io=(t=[],e)=>{t.forEach(r=>{r&&typeof r=="function"&&r(e)})},so=(t=[])=>{t.forEach(([e,r])=>{e&&typeof e=="function"&&e(r)})},ao=(t=[],e=[])=>{let r=[];return e.slice(t.length).forEach(n=>{let s=c=>{let a=B(n);return c.appendChild(a),c};r.push(s)}),r},co=(t=[],e=[])=>{let r=[];return t.forEach((o,n)=>{let s=ae(o,e[n]);r.push(s)}),r},lo=(t=[],e=[])=>{let r=co(t,e),o=ao(t,e);return n=>{if(n){let s=er(r,n.childNodes);so(s),io(o,n)}return n}},se=lo;var tr={select:(t,e)=>r=>{let o=r.value;r.replaceChildren(),ie(t.attributes,e.attributes)(r),se([],e.children)(r);let n=r.querySelector(`option[value="${o}"]`);if(n&&(r.value=o),!n){let s=r.querySelector("option");r.value=s?.value||""}return r}};var ye=(t,e)=>r=>{let o=t?B(t):null;return r&&r.replaceWith(o),o},mo=()=>t=>{t&&t.remove()},uo=(t=void 0,e=void 0)=>t===void 0||e===void 0?mo():typeof t=="string"||typeof e=="string"?ye(e,t):t.tagName!==e.tagName?ye(e):e.tagName==="select"?tr.select(t,e):["pre","code"].includes(e.tagName)?ye(e,t):n=>(ie(t.attributes,e.attributes)(n),se(t.children,e.children)(n),n),ae=uo;var po=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){i("processQueue.getQueue",e)}},q=(t="",e=null)=>{try{F()||(po(t)||{}).process(e)}catch(r){i("processQueue",r)}};var rr=(t="",e=null)=>{let r=L(e||window.joystick._internal.tree,t,"instanceId");r&&(r.children=[])};var or=(t="",e={},r=null)=>{let o=L(r||window.joystick._internal.tree,t,"instanceId");o&&(o.instanceId=e?.instanceId,o.instance=e)};var nr=(t={},e="",r={})=>{for(let o=0;o<t?.children?.length;o+=1){let n=t?.children[o];if(u(n)&&n.attributes&&n.attributes["js-i"]&&n.attributes["js-i"]===e){t.children[o]=r;break}u(n)&&nr(n,e,r)}},ir=nr;var sr=(t={})=>{try{return Object.entries(t).map(([e,r])=>{let[o,...n]=e.split(" ");return{type:o.toLowerCase(),selector:n.join(" "),handler:r}})}catch(e){i("component.events.serialize",e)}};var ar=(t={},e={},r=[])=>{try{let o=Object.keys(t?.events||{})?.length>0?sr(t?.events):[];for(let n=0;n<o?.length;n+=1){let s=o[n];r.push({...s,instance:t,elements:document.querySelectorAll(`body [js-i="${t.instanceId}"] ${s?.selector}`),handler:function(a){Object.defineProperty(a,"target",{value:a.composedPath()[0]}),s.handler(a,{...t||{},setState:t?.setState.bind(t),...e||{}})}})}if(t?.children){let n=Object.entries(t?.children)?.flatMap(([s,c])=>c);for(let s=0;s<n?.length;s+=1){let c=n[s];ar(c,e,r)}}return r}catch(o){i("component.events.registerListenersFix.getListeners",o)}},fo=(t={},e={})=>{try{let r=ar(t,e,[]);console.log("GETTING CALLED",r);let o=r?.flatMap((n={})=>[].flatMap.call(n?.elements||[],s=>{let{elements:c=[],...a}=n||{};return{...a,element:s}}));for(let n=0;n<o?.length;n+=1){let{instance:s,element:c,elementSelector:a,type:l,handler:x}=o[n];console.log({element:c,type:l,handler:x}),c.addEventListener(l,x),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:c,elementSelector:a,type:l,handler:x}]}}catch(r){i("component.events.registerListenersFix",r)}},ce=fo;var cr=(t={})=>{try{let e=t?._eventListeners||[];if(t?.children){let o=(Object.values(t?.children||{})?.reduce((n=[],s=[])=>[...n,...s],[])).flatMap((n={})=>cr(n));e=[...e,...o]}return e}catch(e){i("component.events.unregisterListenersFix.getListeners",e)}},ho=(t={})=>{try{let e=cr(t);for(let r=0;r<e?.length;r+=1){let{instance:o,element:n,type:s,handler:c}=e[r];n.removeEventListener(s,c),o._eventListeners=o._eventListeners?.splice(r,1)}}catch(e){i("component.events.unregisterListenersFix",e)}},dr=ho;var lr=class{constructor(e={}){this.parent=e?.parent||null,this.onUpdateChildComponent=this.handleUpdateChildComponentInVDOM,this.updateVirtualDOM=this.handleUpdateVirtualDOM,this.timers={},this.children={},et(e),At(this,e),this.data=Dt(this)}setDOMNodeOnInstance(){this.DOMNode=document.querySelector(`body [js-i="${this.instanceId}"]`)}async handleFetchData(e={},r={},o={},n=this){let s=await re(e,r,o,n);return this.data=s,s}handleGetInstance(){return this}handleUpdateVirtualDOM(){if(this.DOMNode){let r=W(this.DOMNode);this.dom.virtual=r}let e=this.parent?L(window.joystick._internal.tree,this.parent?.instanceId,"instanceId"):null;e?.instance&&e.instance.updateVirtualDOM()}onBeforeRender(){if(!F())return{instanceId:this.instanceId}}render(e={}){if(e?.mounting)return Xt(this,e);let r=this.onBeforeRender();dr(this),rr(this.instanceId);let o=z(this,{}),n=ae(this.dom.virtual,o.virtual);n&&m(n)&&q("lifecycle.onBeforeMount",()=>{let s=n(this.DOMNode);this.dom.actual=s,this.dom.virtual=o.virtual,ce(this,this.renderMethods),this.setDOMNodeOnInstance(),q("domNodes",()=>{q("lifecycle.onMount",()=>{this.onAfterRender(r,e)})})})}renderToHTML(e={}){return ne(this,e)}onAfterRender(e={},r={}){F()||(or(e.instanceId,this),window.joystick._internal.css.update(),q("lifecycle.onUpdateProps"),r?.afterSetStateRender&&m(r.afterSetStateRender)&&r.afterSetStateRender(),r?.afterRefetchDataRender&&m(r.afterRefetchDataRender)&&r.afterRefetchDataRender(),this.parent&&this.parent.onUpdateChildComponent(this.id,this.instanceId))}setState(e={},r=null){this.state=ee(this,{...this.state||{},...e}),this.render({afterSetStateRender:()=>{r&&m(r)&&r()}})}setTimeout(e=null,r=0){e&&(this.timers[_()]=window.setTimeout(e,r))}setInterval(e=null,r=0){e&&(this.timers[_()]=window.setInterval(e,r))}handleUpdateChildComponentInVDOM(e="",r=""){let o=L(window.joystick._internal.tree,this.instanceId,"instanceId"),n=L(window.joystick._internal.tree,r,"instanceId");if(n?.instance?.DOMNode){let s=W(n?.instance?.DOMNode);ir(o?.instance?.dom?.virtual,n?.instanceId,s)}}},mr=lr;var ur=(t={})=>{try{return(e={})=>new mr({...t,props:e?.props,url:e?.url,translations:e?.translations,api:e?.api,req:e?.req,parent:e?.parent})}catch(e){i("component",e)}};var pr=(t={})=>{try{window.joystick._internal.tree={id:t?.id||null,instanceId:t?.instanceId||null,instance:t,children:[]}}catch(e){i("mount.initializeJoystickComponentTree",e)}};var fr=(t={},e=null)=>{try{return t.innerHTML="",t.appendChild(e),e}catch(r){i("mount.appendToDOM",r)}};var hr=(t=null,e={},r=null)=>{try{m(t)||i("mount","Component to mount must be a function."),u(e)||i("mount","props must be an object."),Oe(r)||i("mount","target must be a DOM node.");let o=t({props:e});pr(o);let n=o.render({mounting:!0,existingChildren:window.__joystick_childrenBeforeHMRUpdate__||null});n&&(n.setAttribute("js-ssrId",o.ssrId),n.setAttribute("js-c",o.id),n.setAttribute("js-i",o.instanceId)),o.lifecycle.onBeforeMount(),q("lifecycle.onBeforeMount"),fr(r,n),o.setDOMNodeOnInstance(),window.joystick._internal.css.update(),ce(o,o.renderMethods),o.lifecycle.onMount(),q("lifecycle.onMount")}catch(o){i("mount",o)}};var wr=class{constructor(e=[]){this.array=[...e],this.array.push=function(){Array.prototype.push.apply(this,arguments)}}async process(e=null){if(this.array.length>0){let r=this.array.shift();r&&r.callback&&(await r.callback(),this.process(e))}else e&&e()}},N=wr;var wo=new RegExp(/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g),yo=new RegExp(/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g),go=(t,e)=>(e||"").replace(wo,()=>"").replace(yo,r=>["@",": "].some(o=>r?.includes(o))?r:`[js-c="${t}"] ${r.trim()}`)?.trim(),yr=(t={},e=[])=>{if(t.instance&&t.instance.options&&t.instance.options.css){let r=t.instance.id,o=t.instance.options.css,n=X(o,t.instance),s=go(r,n);e.push(s)}if(t.children&&t.children.length>0){let r=t?.children?.length||0;for(;r--;)yr(t.children[r],e)}return e},gr=yr;var xr=()=>{try{let t=document.head.querySelector("style[js-styles]"),r=gr(window.joystick?._internal?.tree).reverse().join("").trim();if(t?.innerText===r)return;if(t&&(t.innerHTML=r),!t){let o=document.createElement("style");o.setAttribute("js-styles",""),o.innerHTML=r,document.head.appendChild(o)}}catch(t){i("css.update",t)}};var xo=Me,bo=Re,$o=Z.get,Eo=Ae,Fo=Le,ko=Z.set,Mo=_e,br={_external:{},_internal:{css:{update:xr},queues:{domNodes:new N([]),eventListeners:new N([]),lifecycle:{onBeforeMount:new N([]),onMount:new N([]),onUpdateProps:new N([])},render:new N([])},tree:{},eventListeners:[]},accounts:xo,cache:bo,component:ur,get:$o,html:Eo,id:_,mount:hr,renderComponentToHTML:Fo,set:ko,upload:Mo,timers:{}};Pe(br);var ml=br;export{xo as accounts,bo as cache,ml as default,$o as get,Eo as html,Fo as renderComponentToHTML,ko as set,Mo as upload};
21
+ `}}return r}return""}catch(r){i("component.css.compileCSS",r)}};var Ir=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!I(r)?Object.assign({},r):{}}catch(r){i("component.state.compile.compileState",r)}},ee=(t={},e={})=>{try{return m(e)?Ir(t,e):Object.assign({},e)}catch(r){i("component.state.compile",r)}};var le={onBeforeMount:()=>null,onMount:()=>null,onBeforeUnmount:()=>null,onUpdateProps:()=>null,onRefetchData:()=>null};var Ct=(t={},e={})=>{try{return e?Object.entries({...le,...e||{}}).reduce((r={},[o,n])=>(r[o]=()=>n({...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{}):le}catch(r){i("component.lifecycle.compile",r)}};var te=(t={},e={})=>{try{return Object.entries(e).reduce((r={},[o,n])=>(r[o]=(...s)=>n(...s,{...t,setState:t.setState.bind(t),...t.renderMethods||{}}),r),{})}catch{i("component.methods.compile")}};var me=(t={})=>{try{return{...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window!="undefined"){let o=new URL(window.location);o.searchParams.append(e,r),window.history.pushState({},"",o)}},unset:(e="")=>{if(typeof window!="undefined"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},isActive:(e="")=>O(e)&&t?.route!=="*"?e===(typeof location!="undefined"?location.pathname:t.path):!1}}catch(e){i("component.url.compile",e)}};var qr=(t={},e=null)=>{try{let r=e(t);return r&&u(r)&&!I(r)?Object.assign({},r):{}}catch(r){i("component.props.compileDefaultProps.compile",r)}},Rt=(t={},e={})=>{try{return m(e)?qr(t,e):Object.assign({},e)}catch(r){i("component.props.compileDefaultProps",r)}};var At=(t={},e={})=>{try{t.options=e||{},t.id=e?._componentId||null,t.instanceId=_(8),t.ssrId=e?._ssrId||null,t.css=X(),t.data=Y(e?.dataFromSSR,e?._componentId),t.defaultProps=Rt(t,e?.defaultProps),t.props=vt(t?.defaultProps,e?.props),t.state=ee(t,e?.state),t.events=e?.events||{},t.lifecycle=Ct(t,e?.lifecycle),t.methods=te(t,e?.methods),t.wrapper=e?.wrapper||{},t.translations=e?.translations||{},t.validateForm=Ot,t.DOMNode=null,t.dom={},t.dom.virtual={},t.dom.actual={};let r=!F();if(r||(t.url=me(e?.url)),r&&window.__joystick_url__&&(t.url=me(window.__joystick_url__)),r&&e?.websockets&&m(e?.websockets)){let o=e.websockets(t),n=u(o)&&Object.entries(o);for(let s=0;s<n?.length;s+=1){let[c,a]=n[s];Q({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/${c}`,options:a?.options||{},query:a?.query||{},events:a?.events||{}},(l={})=>{t.websockets={...t.websockets||{},[c]:l}})}}}catch(r){i("component.registerOptions",r)}};var Nr=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){i("addToQueue.getQueue",e)}},G=(t="",e=null)=>{try{F()||(Nr(t)||{}).array.push({callback:e})}catch(r){i("addToQueue",r)}};var re=async(t={},e={},r={},o={})=>{try{if(o?.options?.data&&m(o.options.data)){let n=await o.options.data(t,e,r,o);return Promise.resolve(n)}return Promise.resolve()}catch(n){i("component.data.fetch",n)}};var Lt=(t={},e={},r={})=>{try{return{...t,refetch:async(o={})=>{let n=await re(Z,e,o,r);return r.data=Lt(n,e,r),window.__joystick_data__[r?.id]=n,r.render({afterRefetchDataRender:()=>{r?.lifecycle?.onRefetchData&&r?.lifecycle?.onRefetchData(r)}}),n}}}catch(o){i("component.data.compile",o)}},jt=Lt;var Dt=(t={})=>{try{if(!F()&&window.__joystick_data__&&window.__joystick_data__[t?.id]){let e=window.__joystick_data__[t?.id]||{},r=window.__joystick_req__||{};return jt(e,r,t)}return t?.data||{}}catch(e){i("component.loadDataFromWindow",e)}};var qt=Cr(_t());var Pt=(t={},e="",r="id")=>{try{let o=t&&t.id;if(u(t)&&o){let n=Object.keys(t);for(let s=0;s<n.length;s+=1){let c=n[s],a=t[c];if(c===r&&a===e)return t;if(c==="children"&&Array.isArray(a))for(let l=0;l<a.length;l+=1){let x=a[l],y=Pt(x,e,r);if(y!==null)return y}}}return null}catch(o){i("component.findComponentInTreeByField",o)}},L=Pt;var It=(t="",e={},r=null)=>{let o=L(r||window.joystick._internal.tree,t,"instanceId");o&&(o.children=[...o.children||[],e])};var Vr=(t={},e={},r=null)=>{try{let o=z(t,{includeActual:!0,existingChildren:r});return t.dom=o,t.setDOMNodeOnInstance(),e.renderedComponent=t,o.html.wrapped}catch(o){i("component.renderMethods.component.renderForClient",o)}},Ur=(t={})=>{try{return t.renderToHTML({ssrTree:t.parent.ssrTree,translations:t.parent.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t.parent?.dataFromSSR}).wrapped}catch(e){i("component.renderMethods.component.renderToHTMLForSSR",e)}},Hr=(t={})=>{try{return t.parent.ssrTree.dataFunctions.push(async()=>{try{let e=await t.options.data(t.parent.options.api,t.parent.options.req);return t.data=e||{},{componentId:t.id,ssrId:t.ssrId,data:e}}catch(e){return{componentId:t.id,ssrId:t.ssrId,data:null,error:e}}}),t.renderToHTML({ssrTree:t?.parent?.ssrTree,translations:t?.parent?.translations,walkingTreeForSSR:t?.parent?.walkingTreeForSSR,dataFromSSR:t?.parent?.dataFromSSR})}catch(e){i("component.renderMethods.component.collectDataFunctionsForSSR",e)}},zr=(t={})=>{try{let e={id:t.id,instanceId:t.instanceId,instance:t,children:[]};It(t.parent.instanceId,e,t.parent&&t.parent.ssrTree||null)}catch(e){i("component.renderMethods.component.handleAddComponentToParent",e)}},Br=(t={},e={})=>{try{!t.renderedComponent&&e.options&&e.options.lifecycle&&(e.options.lifecycle.onBeforeMount&&G("lifecycle.onBeforeMount",()=>{e.options.lifecycle.onBeforeMount(e)}),!t.renderedComponent&&e.options.lifecycle.onMount&&G("lifecycle.onMount",()=>{e.options.lifecycle.onMount(e)}))}catch(r){i("component.renderMethods.component.handleLifecycle",r)}},Zr=(t={},e={},r={})=>{try{!e.walkingTreeForSSR&&t?.options?.lifecycle?.onUpdateProps&&(0,qt.diff)(e?.existingPropsMap,r)?.length>0&&G("lifecycle.onUpdateProps",()=>{let n=e?.existingPropsMap&&e?.existingPropsMap[t.id];t.options.lifecycle.onUpdateProps(n||{},r,t)})}catch(o){i("component.renderMethods.component.handleOnChangeProps",o)}},Gr=function(){return function(e=null,r={},o={}){let n=e({props:r,url:o.url,translations:o.translations,api:o.options.api,req:o.options.req,dataFromSSR:o?.dataFromSSR,parent:o}),s=o?.existingStateMap[n.id]||{},c=o.children[n.id]||[],a=s[c?.length];return n.state=a?.state||n.state,o.children[n.id]=[...o.children[n.id]||[],n],n.parent=o,Zr(n,o,r),G("lifecycle.onMount",()=>{n.setDOMNodeOnInstance()}),Br(this,n),n.parent&&zr(n),n.options.data&&n.parent.walkingTreeForSSR&&n.parent.ssrTree.dataFunctions?Hr(n):n.parent&&n.parent.ssrTree?Ur(n):Vr(n,this,a?.children)}},Wr=function(e,r){try{let o=this;return new Gr().bind({})(e,r,o)}catch(o){i("component.renderMethods.component",o)}},ue=Wr;var Kr=function(e=[],r=null){try{return m(r)&&e&&Array.isArray(e)?e.map((o,n)=>r(o,n)).join(""):""}catch(o){i("component.renderMethods.each",o)}},pe=Kr;var Jr=function(e="",r={}){try{let o=F()?this.translations:window.__joystick_i18n__;if(!o||!o[e])return"";let n=Object.entries(r);return n.length>0?n.reduce((s,[c,a])=>s.replace(`{{${c}}}`,a),o[e]):o[e]}catch(o){i("component.renderMethods.i18n",o)}},fe=Jr;var Qr=function(e=!1,r=""){try{return this?.renderingHTMLWithDataForSSR||e?`<when>${r.trim()}</when>`:"<when> </when>"}catch(o){i("component.renderMethods.when",o)}},he=Qr;var Nt={c:ue,component:ue,e:pe,each:pe,i:fe,i18n:fe,w:he,when:he};var Vt=(t={},e={})=>{try{return Object.entries(Nt).reduce((r,[o,n])=>(r[o]=n.bind({...t,...e}),r),{})}catch(r){i("component.renderMethods.compile",r)}};var Ut=(t={})=>{try{return Object.entries(t)?.reduce((e={},[r,o]={})=>(e[r]=o?.map((n={})=>({state:n?.state,children:Ut(n?.children)})),e),{})}catch(e){i("component.render.getExistingStateMap.buildMapForChildren",e)}},Ht=(t={})=>{try{return Ut(t)}catch(e){i("component.render.getExistingStateMap",e)}};var zt=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),Yr=new RegExp(/\n/g);var Xr=(t="")=>{try{return(t.match(zt)||[]).forEach(r=>{t=t.replace(r,"")}),t}catch(e){i("component.render.sanitizeHTML.removeCommentedCode",e)}},Bt=(t="")=>{try{let e=`${t}`;return e=Xr(e),e}catch(e){i("component.render.sanitizeHTML",e)}};var Zt=(t={},e="")=>{try{let{wrapper:r=null,ssrId:o=null,id:n=null,instanceId:s=null}=t;return`<div ${r?.id?`id="${r.id}" `:""}${r?.classList?`class="${r.classList?.join(" ")}" `:""}js-ssrId="${o}" js-c="${n}" js-i="${s}">${e}</div>`}catch(r){i("component.render.wrapHTML",r)}};var Gt=(t={},e=[])=>{try{let r=[...e],o=Object.entries(t);for(let n=0;n<o?.length;n+=1){let[s,c]=o[n];for(let a=0;a<c?.length;a+=1){let l=c[a];Object.entries(l?.timers)?.length>0&&r.push(...Object.values(l?.timers)),Object.entries(l?.children)?.length>0&&Gt(l?.children,r)}}if(r?.length>0)for(let n=0;n<r?.length;n+=1)clearTimeout(r[n])}catch(r){i("component.render.clearTimersOnChildren",r)}},Wt=Gt;var ne=(t={},e={})=>{try{e?.dataFromSSR&&(t.data=Y(e.dataFromSSR,t.id)||{}),Wt(t?.children);let r=Ht(e?.existingChildren||t?.children)||{};t.children={},t.renderMethods=Vt({...t,existingStateMap:r,translations:e?.translations||t.translations||{},ssrTree:e?.ssrTree,walkingTreeForSSR:e?.walkingTreeForSSR,renderingHTMLWithDataForSSR:e?.renderingHTMLWithDataForSSR,dataFromSSR:e?.dataFromSSR}),t.methods=te(t,t.options.methods);let o=t.options.render({...t||{},setState:t.setState.bind(t),...t.renderMethods||{}}),n=Bt(o),s=Zt(t,n);return{unwrapped:n,wrapped:s}}catch(r){i("component.render.toHTML",r)}};var eo=(t={})=>{try{return Object.values(t).reduce((e={},r)=>(e[r.name]=r.value,e),{})}catch(e){i("component.virtualDOM.build.parseAttributeMap",e)}},Kt=(t={})=>{try{return t.tagName==="WHEN"?[].flatMap.call(t?.childNodes,e=>e?.tagName==="WHEN"?Kt(e):we(e)):we(t)}catch(e){i("component.virtualDOM.build.flattenWhenTags",e)}},we=(t={})=>{try{let e=t&&t.tagName&&t.tagName.toLowerCase()||"text",r={tagName:e,attributes:eo(t.attributes),children:[].flatMap.call(t.childNodes,o=>Kt(o))};return e==="text"&&(r=t.textContent),r}catch(e){i("component.virtualDOM.build",e)}},W=we;var to=(t="")=>{try{let e=document.createElement("div");return e.innerHTML=t,e?.childNodes[0]}catch(e){i("component.virtualDOM.build.convertHTMLToDOM",e)}},Jt=(t="")=>{try{let e=to(t);return W(e)}catch(e){i("component.virtualDOM.build",e)}};var Qt=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}};var ro=(t={})=>{try{let e=document.createElement(t.tagName),r=Object.entries(t.attributes);for(let o=0;o<r.length;o+=1){let[n,s]=r[o];Qt(n)&&e.setAttribute(n,s)}for(let o=0;o<t?.children?.length;o+=1){let n=t?.children[o];if(n){let s=Yt(n);e.appendChild(s)}}return e}catch(e){i("component.virtualDOM.renderTreeToDOM.renderElement",e)}},Yt=(t=null)=>{try{return O(t)?document.createTextNode(t):ro(t)}catch(e){i("component.virtualDOM.renderTreeToDOM",e)}},B=Yt;var z=(t={},e={})=>{try{let r=ne(t,{existingChildren:e?.existingChildren}),o=Jt(r.wrapped,t),n=e.includeActual&&o?B(o):null;return{html:r,virtual:o,actual:n}}catch(r){i("component.render.getUpdatedDOM",r)}};var Xt=(t={},e={})=>{try{let r=z(t,{includeActual:!0,existingChildren:e?.existingChildren});return t.dom=r,r.actual}catch(r){i("component.render.forMount",r)}};var oo=(t={},e={})=>{let r=[];for(let[o,n]of Object.entries(e))r.push(s=>(s&&s.setAttribute&&s.setAttribute(o,n),s));for(let o in t)o in e||r.push(n=>(n&&n.removeAttribute&&n.removeAttribute(o),n));return o=>{for(let n of r)n&&typeof n=="function"&&n(o)}},ie=oo;var no=(t=[],e=[])=>{let r=[],o=Math.max(t.length,e.length);for(let n=0;n<o;n+=1){let s=t[n],c=e[n];r.push([s,c])}return r},er=no;var io=(t=[],e)=>{t.forEach(r=>{r&&typeof r=="function"&&r(e)})},so=(t=[])=>{t.forEach(([e,r])=>{e&&typeof e=="function"&&e(r)})},ao=(t=[],e=[])=>{let r=[];return e.slice(t.length).forEach(n=>{let s=c=>{let a=B(n);return c.appendChild(a),c};r.push(s)}),r},co=(t=[],e=[])=>{let r=[];return t.forEach((o,n)=>{let s=ae(o,e[n]);r.push(s)}),r},lo=(t=[],e=[])=>{let r=co(t,e),o=ao(t,e);return n=>{if(n){let s=er(r,n.childNodes);so(s),io(o,n)}return n}},se=lo;var tr={select:(t,e)=>r=>{let o=r.value;r.replaceChildren(),ie(t.attributes,e.attributes)(r),se([],e.children)(r);let n=r.querySelector(`option[value="${o}"]`);if(n&&(r.value=o),!n){let s=r.querySelector("option");r.value=s?.value||""}return r}};var ye=(t,e)=>r=>{let o=t?B(t):null;return r&&r.replaceWith(o),o},mo=()=>t=>{t&&t.remove()},uo=(t=void 0,e=void 0)=>t===void 0||e===void 0?mo():typeof t=="string"||typeof e=="string"?ye(e,t):t.tagName!==e.tagName?ye(e):e.tagName==="select"?tr.select(t,e):["pre","code"].includes(e.tagName)?ye(e,t):n=>(ie(t.attributes,e.attributes)(n),se(t.children,e.children)(n),n),ae=uo;var po=(t="")=>{try{let[e,r]=t?.split(".");return r?window?.joystick?._internal?.queues[e][r]:window?.joystick?._internal?.queues[e]}catch(e){i("processQueue.getQueue",e)}},q=(t="",e=null)=>{try{F()||(po(t)||{}).process(e)}catch(r){i("processQueue",r)}};var rr=(t="",e=null)=>{let r=L(e||window.joystick._internal.tree,t,"instanceId");r&&(r.children=[])};var or=(t="",e={},r=null)=>{let o=L(r||window.joystick._internal.tree,t,"instanceId");o&&(o.instanceId=e?.instanceId,o.instance=e)};var nr=(t={},e="",r={})=>{for(let o=0;o<t?.children?.length;o+=1){let n=t?.children[o];if(u(n)&&n.attributes&&n.attributes["js-i"]&&n.attributes["js-i"]===e){t.children[o]=r;break}u(n)&&nr(n,e,r)}},ir=nr;var sr=(t={})=>{try{return Object.entries(t).map(([e,r])=>{let[o,...n]=e.split(" ");return{type:o.toLowerCase(),selector:n.join(" "),handler:r}})}catch(e){i("component.events.serialize",e)}};var ar=(t={},e={},r=[])=>{try{let o=Object.keys(t?.events||{})?.length>0?sr(t?.events):[];for(let n=0;n<o?.length;n+=1){let s=o[n];r.push({...s,instance:t,elements:document.querySelectorAll(`body [js-i="${t.instanceId}"] ${s?.selector}`),handler:function(a){console.log("DOM EVENT",a),Object.defineProperty(a,"target",{value:a.composedPath()[0]}),s.handler(a,{...t||{},setState:t?.setState.bind(t),...e||{}})}})}if(t?.children){let n=Object.entries(t?.children)?.flatMap(([s,c])=>c);for(let s=0;s<n?.length;s+=1){let c=n[s];ar(c,e,r)}}return r}catch(o){i("component.events.registerListenersFix.getListeners",o)}},fo=(t={},e={})=>{try{let r=ar(t,e,[]);console.log("GETTING CALLED",r);let o=r?.flatMap((n={})=>[].flatMap.call(n?.elements||[],s=>{let{elements:c=[],...a}=n||{};return{...a,element:s}}));for(let n=0;n<o?.length;n+=1){let{instance:s,element:c,elementSelector:a,type:l,handler:x}=o[n];console.log({element:c,type:l,handler:x}),c.addEventListener(l,x),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:c,elementSelector:a,type:l,handler:x}]}}catch(r){i("component.events.registerListenersFix",r)}},ce=fo;var cr=(t={})=>{try{let e=t?._eventListeners||[];if(t?.children){let o=(Object.values(t?.children||{})?.reduce((n=[],s=[])=>[...n,...s],[])).flatMap((n={})=>cr(n));e=[...e,...o]}return e}catch(e){i("component.events.unregisterListenersFix.getListeners",e)}},ho=(t={})=>{try{let e=cr(t);for(let r=0;r<e?.length;r+=1){let{instance:o,element:n,type:s,handler:c}=e[r];n.removeEventListener(s,c),o._eventListeners=o._eventListeners?.splice(r,1)}}catch(e){i("component.events.unregisterListenersFix",e)}},dr=ho;var lr=class{constructor(e={}){this.parent=e?.parent||null,this.onUpdateChildComponent=this.handleUpdateChildComponentInVDOM,this.updateVirtualDOM=this.handleUpdateVirtualDOM,this.timers={},this.children={},et(e),At(this,e),this.data=Dt(this)}setDOMNodeOnInstance(){this.DOMNode=document.querySelector(`body [js-i="${this.instanceId}"]`)}async handleFetchData(e={},r={},o={},n=this){let s=await re(e,r,o,n);return this.data=s,s}handleGetInstance(){return this}handleUpdateVirtualDOM(){if(this.DOMNode){let r=W(this.DOMNode);this.dom.virtual=r}let e=this.parent?L(window.joystick._internal.tree,this.parent?.instanceId,"instanceId"):null;e?.instance&&e.instance.updateVirtualDOM()}onBeforeRender(){if(!F())return{instanceId:this.instanceId}}render(e={}){if(e?.mounting)return Xt(this,e);let r=this.onBeforeRender();dr(this),rr(this.instanceId);let o=z(this,{}),n=ae(this.dom.virtual,o.virtual);n&&m(n)&&q("lifecycle.onBeforeMount",()=>{let s=n(this.DOMNode);this.dom.actual=s,this.dom.virtual=o.virtual,ce(this,this.renderMethods),this.setDOMNodeOnInstance(),q("domNodes",()=>{q("lifecycle.onMount",()=>{this.onAfterRender(r,e)})})})}renderToHTML(e={}){return ne(this,e)}onAfterRender(e={},r={}){F()||(or(e.instanceId,this),window.joystick._internal.css.update(),q("lifecycle.onUpdateProps"),r?.afterSetStateRender&&m(r.afterSetStateRender)&&r.afterSetStateRender(),r?.afterRefetchDataRender&&m(r.afterRefetchDataRender)&&r.afterRefetchDataRender(),this.parent&&this.parent.onUpdateChildComponent(this.id,this.instanceId))}setState(e={},r=null){this.state=ee(this,{...this.state||{},...e}),this.render({afterSetStateRender:()=>{r&&m(r)&&r()}})}setTimeout(e=null,r=0){e&&(this.timers[_()]=window.setTimeout(e,r))}setInterval(e=null,r=0){e&&(this.timers[_()]=window.setInterval(e,r))}handleUpdateChildComponentInVDOM(e="",r=""){let o=L(window.joystick._internal.tree,this.instanceId,"instanceId"),n=L(window.joystick._internal.tree,r,"instanceId");if(n?.instance?.DOMNode){let s=W(n?.instance?.DOMNode);ir(o?.instance?.dom?.virtual,n?.instanceId,s)}}},mr=lr;var ur=(t={})=>{try{return(e={})=>new mr({...t,props:e?.props,url:e?.url,translations:e?.translations,api:e?.api,req:e?.req,parent:e?.parent})}catch(e){i("component",e)}};var pr=(t={})=>{try{window.joystick._internal.tree={id:t?.id||null,instanceId:t?.instanceId||null,instance:t,children:[]}}catch(e){i("mount.initializeJoystickComponentTree",e)}};var fr=(t={},e=null)=>{try{return t.innerHTML="",t.appendChild(e),e}catch(r){i("mount.appendToDOM",r)}};var hr=(t=null,e={},r=null)=>{try{m(t)||i("mount","Component to mount must be a function."),u(e)||i("mount","props must be an object."),Oe(r)||i("mount","target must be a DOM node.");let o=t({props:e});pr(o);let n=o.render({mounting:!0,existingChildren:window.__joystick_childrenBeforeHMRUpdate__||null});n&&(n.setAttribute("js-ssrId",o.ssrId),n.setAttribute("js-c",o.id),n.setAttribute("js-i",o.instanceId)),o.lifecycle.onBeforeMount(),q("lifecycle.onBeforeMount"),fr(r,n),o.setDOMNodeOnInstance(),window.joystick._internal.css.update(),ce(o,o.renderMethods),o.lifecycle.onMount(),q("lifecycle.onMount")}catch(o){i("mount",o)}};var wr=class{constructor(e=[]){this.array=[...e],this.array.push=function(){Array.prototype.push.apply(this,arguments)}}async process(e=null){if(this.array.length>0){let r=this.array.shift();r&&r.callback&&(await r.callback(),this.process(e))}else e&&e()}},N=wr;var wo=new RegExp(/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g),yo=new RegExp(/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g),go=(t,e)=>(e||"").replace(wo,()=>"").replace(yo,r=>["@",": "].some(o=>r?.includes(o))?r:`[js-c="${t}"] ${r.trim()}`)?.trim(),yr=(t={},e=[])=>{if(t.instance&&t.instance.options&&t.instance.options.css){let r=t.instance.id,o=t.instance.options.css,n=X(o,t.instance),s=go(r,n);e.push(s)}if(t.children&&t.children.length>0){let r=t?.children?.length||0;for(;r--;)yr(t.children[r],e)}return e},gr=yr;var xr=()=>{try{let t=document.head.querySelector("style[js-styles]"),r=gr(window.joystick?._internal?.tree).reverse().join("").trim();if(t?.innerText===r)return;if(t&&(t.innerHTML=r),!t){let o=document.createElement("style");o.setAttribute("js-styles",""),o.innerHTML=r,document.head.appendChild(o)}}catch(t){i("css.update",t)}};var xo=Me,bo=Re,$o=Z.get,Eo=Ae,Fo=Le,ko=Z.set,Mo=_e,br={_external:{},_internal:{css:{update:xr},queues:{domNodes:new N([]),eventListeners:new N([]),lifecycle:{onBeforeMount:new N([]),onMount:new N([]),onUpdateProps:new N([])},render:new N([])},tree:{},eventListeners:[]},accounts:xo,cache:bo,component:ur,get:$o,html:Eo,id:_,mount:hr,renderComponentToHTML:Fo,set:ko,upload:Mo,timers:{}};Pe(br);var ml=br;export{xo as accounts,bo as cache,ml as default,$o as get,Eo as html,Fo as renderComponentToHTML,ko as set,Mo as upload};
@@ -1 +1 @@
1
- var i=(e="",t={})=>{throw new Error(`[joystick${e?`.${e}`:""}] ${t.message||t.reason||t}`)};var m=e=>{try{return!0}catch(t){i("types.isDOM",t)}};var d=e=>{try{return typeof e=="function"}catch(t){i("types.isFunction",t)}};var y=e=>{try{return!!(e&&typeof e=="object"&&!Array.isArray(e))}catch(t){i("types.isObject",t)}};var f=(e={})=>{try{window.joystick._internal.tree={id:e?.id||null,instanceId:e?.instanceId||null,instance:e,children:[]}}catch(t){i("mount.initializeJoystickComponentTree",t)}};var h=()=>typeof window=="undefined";var k=(e="")=>{try{let[t,o]=e?.split(".");return o?window?.joystick?._internal?.queues[t][o]:window?.joystick?._internal?.queues[t]}catch(t){i("processQueue.getQueue",t)}},a=(e="",t=null)=>{try{h()||(k(e)||{}).process(t)}catch(o){i("processQueue",o)}};var w=(e={},t=null)=>{try{return e.innerHTML="",e.appendChild(t),t}catch(o){i("mount.appendToDOM",o)}};var x=(e={})=>{try{return Object.entries(e).map(([t,o])=>{let[r,...n]=t.split(" ");return{type:r.toLowerCase(),selector:n.join(" "),handler:o}})}catch(t){i("component.events.serialize",t)}};var b=(e={},t={},o=[])=>{try{let r=Object.keys(e?.events||{})?.length>0?x(e?.events):[];for(let n=0;n<r?.length;n+=1){let s=r[n];o.push({...s,instance:e,elements:document.querySelectorAll(`body [js-i="${e.instanceId}"] ${s?.selector}`),handler:function(p){Object.defineProperty(p,"target",{value:p.composedPath()[0]}),s.handler(p,{...e||{},setState:e?.setState.bind(e),...t||{}})}})}if(e?.children){let n=Object.entries(e?.children)?.flatMap(([s,c])=>c);for(let s=0;s<n?.length;s+=1){let c=n[s];b(c,t,o)}}return o}catch(r){i("component.events.registerListenersFix.getListeners",r)}},F=(e={},t={})=>{try{let o=b(e,t,[]);console.log("GETTING CALLED",o);let r=o?.flatMap((n={})=>[].flatMap.call(n?.elements||[],s=>{let{elements:c=[],...p}=n||{};return{...p,element:s}}));for(let n=0;n<r?.length;n+=1){let{instance:s,element:c,elementSelector:p,type:u,handler:l}=r[n];console.log({element:c,type:u,handler:l}),c.addEventListener(u,l),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:c,elementSelector:p,type:u,handler:l}]}}catch(o){i("component.events.registerListenersFix",o)}},g=F;var J=(e=null,t={},o=null)=>{try{d(e)||i("mount","Component to mount must be a function."),y(t)||i("mount","props must be an object."),m(o)||i("mount","target must be a DOM node.");let r=e({props:t});f(r);let n=r.render({mounting:!0,existingChildren:window.__joystick_childrenBeforeHMRUpdate__||null});n&&(n.setAttribute("js-ssrId",r.ssrId),n.setAttribute("js-c",r.id),n.setAttribute("js-i",r.instanceId)),r.lifecycle.onBeforeMount(),a("lifecycle.onBeforeMount"),w(o,n),r.setDOMNodeOnInstance(),window.joystick._internal.css.update(),g(r,r.renderMethods),r.lifecycle.onMount(),a("lifecycle.onMount")}catch(r){i("mount",r)}};export{J as default};
1
+ var i=(e="",t={})=>{throw new Error(`[joystick${e?`.${e}`:""}] ${t.message||t.reason||t}`)};var m=e=>{try{return!0}catch(t){i("types.isDOM",t)}};var d=e=>{try{return typeof e=="function"}catch(t){i("types.isFunction",t)}};var y=e=>{try{return!!(e&&typeof e=="object"&&!Array.isArray(e))}catch(t){i("types.isObject",t)}};var f=(e={})=>{try{window.joystick._internal.tree={id:e?.id||null,instanceId:e?.instanceId||null,instance:e,children:[]}}catch(t){i("mount.initializeJoystickComponentTree",t)}};var h=()=>typeof window=="undefined";var k=(e="")=>{try{let[t,o]=e?.split(".");return o?window?.joystick?._internal?.queues[t][o]:window?.joystick?._internal?.queues[t]}catch(t){i("processQueue.getQueue",t)}},a=(e="",t=null)=>{try{h()||(k(e)||{}).process(t)}catch(o){i("processQueue",o)}};var w=(e={},t=null)=>{try{return e.innerHTML="",e.appendChild(t),t}catch(o){i("mount.appendToDOM",o)}};var x=(e={})=>{try{return Object.entries(e).map(([t,o])=>{let[r,...n]=t.split(" ");return{type:r.toLowerCase(),selector:n.join(" "),handler:o}})}catch(t){i("component.events.serialize",t)}};var b=(e={},t={},o=[])=>{try{let r=Object.keys(e?.events||{})?.length>0?x(e?.events):[];for(let n=0;n<r?.length;n+=1){let s=r[n];o.push({...s,instance:e,elements:document.querySelectorAll(`body [js-i="${e.instanceId}"] ${s?.selector}`),handler:function(p){console.log("DOM EVENT",p),Object.defineProperty(p,"target",{value:p.composedPath()[0]}),s.handler(p,{...e||{},setState:e?.setState.bind(e),...t||{}})}})}if(e?.children){let n=Object.entries(e?.children)?.flatMap(([s,c])=>c);for(let s=0;s<n?.length;s+=1){let c=n[s];b(c,t,o)}}return o}catch(r){i("component.events.registerListenersFix.getListeners",r)}},F=(e={},t={})=>{try{let o=b(e,t,[]);console.log("GETTING CALLED",o);let r=o?.flatMap((n={})=>[].flatMap.call(n?.elements||[],s=>{let{elements:c=[],...p}=n||{};return{...p,element:s}}));for(let n=0;n<r?.length;n+=1){let{instance:s,element:c,elementSelector:p,type:u,handler:l}=r[n];console.log({element:c,type:u,handler:l}),c.addEventListener(u,l),s._eventListeners=[...s?._eventListeners||[],{instance:s,element:c,elementSelector:p,type:u,handler:l}]}}catch(o){i("component.events.registerListenersFix",o)}},g=F;var J=(e=null,t={},o=null)=>{try{d(e)||i("mount","Component to mount must be a function."),y(t)||i("mount","props must be an object."),m(o)||i("mount","target must be a DOM node.");let r=e({props:t});f(r);let n=r.render({mounting:!0,existingChildren:window.__joystick_childrenBeforeHMRUpdate__||null});n&&(n.setAttribute("js-ssrId",r.ssrId),n.setAttribute("js-c",r.id),n.setAttribute("js-i",r.instanceId)),r.lifecycle.onBeforeMount(),a("lifecycle.onBeforeMount"),w(o,n),r.setDOMNodeOnInstance(),window.joystick._internal.css.update(),g(r,r.renderMethods),r.lifecycle.onMount(),a("lifecycle.onMount")}catch(r){i("mount",r)}};export{J as default};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@joystick.js/ui-canary",
3
3
  "type": "module",
4
- "version": "0.0.0-canary.6",
4
+ "version": "0.0.0-canary.8",
5
5
  "description": "A JavaScript framework for building user interfaces.",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {