@joystick.js/ui-canary 0.0.0-canary.270 → 0.0.0-canary.271

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var Lt=(t="",e=[])=>{console.error(`${t} failed with the following errors:`);for(let r=0;r<e?.length;r+=1){let n=e[r];console.error(n.message),n.stack&&console.error(n.stack)}},y=Lt;var Rt=(t="{}")=>{try{return JSON.parse(t)}catch{return t}},j=Rt;var Tt=async(t={})=>{let e=await t.text();return j(e)},Nt=(t="GET",e={})=>["POST"].includes(t)?JSON.stringify({...e,origin:window?.location?.origin}):null,Pt=(t=null)=>{switch(t){case"authenticated":return"GET";case"user":default:return"POST"}},Zt=(t="",e={})=>{if(typeof window.fetch<"u")return new Promise((r,n)=>{let o=`${window.location.origin}/api/_accounts/${t}`,i=Pt(t),c=Nt(i,e);return fetch(o,{method:i,mode:"cors",headers:{"Content-Type":"application/json"},body:c,credentials:"include"}).then(async a=>{let d=await Tt(a);return d?.errors?(y(`accounts.${t}`,d.errors),n(d)):r(d)}).catch(a=>(y(`accounts.${t}`,[a]),n({errors:[a]})))})},$=Zt;var zt=async(t={})=>{let e=await $("authenticated",t);return e?.status===200&&e?.authenticated},pe=zt;var qt=(t={})=>$("login",t),we=qt;var It=()=>$("logout"),ge=It;var Gt=(t={})=>$("recover-password",t),H=Gt;var Bt=(t={})=>$("reset-password",t),V=Bt;var Dt=(t={})=>$("signup",t),$e=Dt;var Ut=async(t={})=>{let e=await $("user",t);return e?.status===200&&e?.user},ye=Ut;var Ft={authenticated:pe,login:we,logout:ge,recoverPassword:H,recover_password:H,resetPassword:V,reset_password:V,signup:$e,user:ye},xe=Ft;var Ht=t=>!!t,Vt=t=>!!Array.isArray(t),Kt=t=>t===!0||t===!1,Jt=t=>Number(t)===t&&t%1!==0,Yt=t=>typeof t=="function",Xt=t=>Number(t)===t&&t%1===0,Wt=t=>t===null,Qt=t=>Number(t)===t,er=t=>!!(t&&typeof t=="object"&&!Array.isArray(t)),tr=t=>typeof t=="string",rr=t=>typeof t>"u",nr={is_any:Ht,is_array:Vt,is_boolean:Kt,is_float:Jt,is_function:Yt,is_integer:Xt,is_null:Wt,is_number:Qt,is_object:er,is_string:tr,is_undefined:rr},s=nr;var K=class{constructor(e="",r={}){this.name=e,this.value=r||{},this.listeners={change:[],set:[],unset:[]}}_get_value_at_path(e=""){return e?.split(".").reduce((r=null,n="")=>(r[n]&&(r=r[n]),r),this.value)}get(e=""){return e?.trim()===""?{...this.value||{}}:this._get_value_at_path(e)}set(e=null,r=""){if(!e||!s.is_function(e))throw new Error("First argument passed to set() must be a function.");let n=e(this.value);if(!s.is_object(n))throw new Error("Value to set must be an object representing the current cache state.");this.value=n,this._handle_event("set",r),this._handle_event("change",r)}unset(e="",r=""){e?.trim()===""&&(this.value={});let n=e?.split("."),o=n?.length-1;n.reduce((i,c,a)=>(a===o&&delete i[c],i[c]),this.value),this._handle_event("unset",r),this._handle_event("change",r)}on(e="",r=null){if(!["change","set","unset"].includes(e))throw new Error(`Event to listen for must be change, set, or unset. ${e} is not supported.`);if(!r||!s.is_function(r))throw new Error("Second argument passed to on("<e>") must be a function.");this.listeners={[e]:[...this.listeners[e]||[],r]}}_handle_event(e="",r=""){let n=this.listeners[e]||[];for(let o=0;o<n?.length;o+=1){let i=n[o];s.is_function(i)&&i(this.value,e,r)}}},be=K;var J=(t="",e={})=>new be(t,e);var or=(t="")=>joystick._external[t]?joystick._external[t]:null,ve=or;var ir=(t=128,e="test.txt",r="text/plain")=>{let n=t instanceof Blob;return new File(n?t:new Blob(new Uint8Array(t||128),{type:r}),e,{type:r})},Y=ir;var sr=(t="",e=[])=>{typeof window<"u"&&window.__joystick_test__&&(window.test={...window.test||{},function_calls:{...window?.test?.function_calls||{},[t]:[...window?.test?.function_calls&&window?.test?.function_calls[t]||[],{called_at:new Date().toISOString(),args:e}]}})},u=sr;var dr={utils:{createFile:Y,create_file:Y,trackFunctionCall:u,track_function_call:u}},je=dr;var cr=(t="",e={})=>{typeof window<"u"&&(joystick._external[t]={...joystick._external[t]||{},...e})},ke=cr;var Ee="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890".split(""),ar=(t=16)=>{let e="",r=0;for(;r<t;)e+=Ee[Math.floor(Math.random()*(Ee.length-1))],r+=1;return e},m=ar;var k=null,R=0,Se=(t={},e=null)=>{if(window?.__joystick_test__)return e();let r=t?.url;t?.query&&(r=`${r}?${new URLSearchParams(t.query).toString()}`);let n=new WebSocket(r);k&&(clearInterval(k),k=null);let o={_id:m(8),client:n,send:(i={})=>(u(`ui.${t?.test?.name||m(16)}.websockets.send`,[i]),n.send(JSON.stringify(i)))};return n.addEventListener("open",()=>{t?.options?.logging&&console.log(`[joystick.websockets] Connected to ${t?.url}`),(t?.events?.onOpen||t?.events?.on_open)&&((t.events.onOpen||t.events.on_open)(o),u(`ui.websockets.${t?.test?.name||m()}.on_open`,[o])),R=0}),n.addEventListener("message",i=>{i?.data&&(t?.events?.onMessage||t?.events?.on_message)&&((t.events.onMessage||t.events.on_message)(JSON.parse(i.data||{}),o),u(`ui.websockets.${t?.test?.name||m()}.on_message`,[i.data||{},o]))}),n.addEventListener("close",i=>{t?.options?.logging&&console.log(`[joystick.websockets] Disconnected from ${t?.url}`),(t?.events?.onClose||t?.events?.on_close)&&((t.events.onClose||t.events.on_close)(i?.code,i?.reason,o),u(`ui.websockets.${t?.test?.name||m()}.on_close`,[i.data||{},o])),n=null;let c=[1e3,1001].includes(i?.code);window.joystick._internal.websockets&&(window.joystick._internal.websockets=window.joystick._internal.websockets?.filter(a=>a?._id!==o?._id)),(t?.options?.autoReconnect||t?.options?.auto_reconnect)&&!k&&!c&&(k=setInterval(()=>{n=null,R<(t?.options?.reconnectAttempts||t?.options?.reconnect_attempts||12)?(Se(t,e),t?.options?.logging&&console.log(`[joystick.websockets] Attempting to reconnect (${R+1}/12)...`),R+=1):clearInterval(k)},(t?.options?.reconnectDelayInSeconds||t?.options?.reconnect_delay_in_seconds)*1e3||5e3))}),e&&e(o),window.joystick?._internal&&(window.joystick._internal.websockets=[...window.joystick._internal.websockets||[],o]),o},T=Se;var Ae=(t="",e={})=>{if(window?.__joystick_test__){u(`ui.upload.${t}`,[t,e]);return}return new Promise((r,n)=>{let o=m(16),i=0;T({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/uploaders`,options:{logging:!1,autoReconnect:!0,reconnectAttempts:12,reconnectDelayInSeconds:5},query:{id:o},events:{on_message:(c={})=>{c?.type==="PROGRESS"&&(e?.onProgress||e?.on_progress)&&i<100&&i!==c?.progress&&(i=c?.progress,(e.onProgress||e?.on_progress)(c?.progress,c?.provider))}}},()=>{let c;if(e?.files?.length>0){c=new FormData;let a=Array.from(e?.files);for(let d=0;d<a?.length;d+=1){let _=a[d];c.append("files",_,_.name)}}fetch(`${window.location.origin}/api/_uploaders/${t}`,{method:"POST",headers:{"x-joystick-upload-id":o,"x-joystick-upload-input":JSON.stringify(e?.input||{})},body:c}).then(async a=>{let d=await a.json();d&&d.errors?(y("upload",d.errors),n({errors:d.errors})):r(d?.uploads)})})})};var lr=(t={})=>Object.entries(t).map(([e,r])=>`${e}=${r}`)?.join("; "),N=lr;var _r=async(t={})=>{let e=await t.text();return j(e)},fr=(t="",e={})=>typeof window.fetch<"u"&&!e?.skip?new Promise((r,n)=>{let o=e.input?JSON.stringify(e.input):null,i=e.output?JSON.stringify(e.output):null,c=`${window.location.origin}/api/_getters/${t}?input=${o}&output=${i}`,a=document.querySelector('[name="csrf"]')?.getAttribute("content"),d={...e?.headers||{},"x-joystick-csrf":a};return window?.__joystick_test__&&(d.Cookie=N({joystick_login_token:window.__joystick_test_login_token__,joystick_login_token_expires_at:window.__joystick_test_login_token_expires_at__})),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!0}),fetch(c,{method:"GET",mode:"cors",headers:d,credentials:"include"}).then(async _=>{let f=await _r(_);return e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),f?.errors?(y("Get request",f.errors),n(f)):r(f)}).catch(_=>(y("Get request",[_]),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),n({errors:[_]})))}):Promise.resolve(),Oe=fr;var ur=async(t={})=>{let e=await t.text();return j(e)},mr=(t={})=>{let e={...t};return e?.loader&&delete e.loader,JSON.stringify(e)},hr=(t="",e={})=>typeof window.fetch<"u"?new Promise((r,n)=>{let o=`${window.location.origin}/api/_setters/${t}`,i=mr(e),c=document.querySelector('[name="csrf"]')?.getAttribute("content"),a={...e?.headers||{},"Content-Type":"application/json","x-joystick-csrf":c};return window?.__joystick_test__&&(a.Cookie=N({joystick_login_token:window?.__joystick_test_login_token__,joystick_login_token_expires_at:window.__joystick_test_login_token_expires_at__})),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!0}),fetch(o,{method:"POST",mode:"cors",headers:a,body:i,credentials:"include"}).then(async d=>{let _=await ur(d);return e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),_?.errors?(y("Set request",_.errors),n(_)):r(_)}).catch(d=>(y("Set request",[d]),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),n({errors:[d]})))}):Promise.resolve(),Me=hr;var pr={fetch:typeof window<"u"?window.fetch.bind(window):null,get:Oe,set:Me},O=pr;var wr=(t="",e=new Error)=>{throw new Error(`[joystick${t?`.${t}`:""}] ${e.message||e}`)},Ce=wr;var gr=(t={})=>{let e=null;typeof window<"u"&&(e=window),typeof global<"u"&&(e=global),e&&(e.joystick={...e?.joystick||{},settings:e?.__joystick_settings__,...t})},Le=gr;var $r=(t={})=>Object.values(t)?.flatMap((e=[])=>e),E=$r;var yr=(t={})=>{joystick._internal.tree=joystick?._internal?.tree?.filter(e=>!!document.querySelector(`[js-i="${e?.instance_id}"]`))},Re=yr;var xr=(t={},e=null)=>{let r=e(t);return r&&s.is_object(r)&&!s.is_array(r)?Object.assign({},r):{}},br=(t={},e={})=>s.is_function(e)?xr(t,e):Object.assign({},e),P=br;var vr=new RegExp(/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g),jr=new RegExp(/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g),kr=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),Er=new RegExp("<when>|</when>","g"),Sr={CSS_COMMENT_REGEX:vr,CSS_SELECTOR_REGEX:jr,JOYSTICK_COMMENT_REGEX:kr,WHEN_TAG_REGEX:Er},M=Sr;var Ar=(()=>{let t=0;return(e,r)=>{clearTimeout(t),t=setTimeout(e,r)}})(),Te=Ar;var Or=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}},Z=Or;var Mr=(t={},e={})=>{let r=[];for(let[n,o]of Object.entries(e))r.push(i=>(i&&i.setAttribute&&Z(n)&&i.setAttribute(n,o),i));for(let n in t)n in e||r.push(o=>(o&&o.removeAttribute&&o.removeAttribute(n),o));return n=>{for(let o of r)o&&typeof o=="function"&&o(n)}},z=Mr;var Cr=(t=[],e=[])=>{let r=[],n=Math.max(t.length,e.length);for(let o=0;o<n;o+=1){let i=t[o],c=e[o];r.push([i,c])}return r},Ne=Cr;var Lr=(t={})=>{let e=document.createElement(t.tag_name),r=Object.entries(t.attributes);for(let n=0;n<r.length;n+=1){let[o,i]=r[n];Z(o)&&e.setAttribute(o,i)}for(let n=0;n<t?.children?.length;n+=1){let o=t?.children[n];if(o){let i=Pe(o);e.appendChild(i)}}return e},Pe=(t=null)=>s.is_string(t)?document.createTextNode(t):Lr(t),q=Pe;var Rr=(t=[],e)=>{for(let r=0;r<t?.length;r+=1){let n=t[r];n&&typeof n=="function"&&n(e)}},Tr=(t=[])=>{for(let e=0;e<t?.length;e+=1){let[r,n]=t[e];r&&typeof r=="function"&&r(n)}},Nr=(t=[],e=[])=>{let r=[],n=e.slice(t.length);for(let o=0;o<n?.length;o+=1){let i=n[o],c=a=>{let d=q(i);return a.appendChild(d),a};r.push(c)}return r},Pr=(t=[],e=[])=>{let r=[];for(let n=0;n<t?.length;n+=1){let o=t[n],i=G(o,e[n]);r.push(i)}return r},Zr=(t=[],e=[])=>{let r=Pr(t,e),n=Nr(t,e);return o=>{if(o){let i=Ne(r,o.childNodes);Tr(i),Rr(n,o)}return o}},I=Zr;var zr={select:(t,e)=>r=>{let n=r.value;r.replaceChildren(),z(t.attributes,e.attributes)(r),I([],e.children)(r);let o=r.querySelector(`option[value="${n}"]`);if(o&&(r.value=n),!o){let i=r.querySelector("option");r.value=i?.value||""}return r}},Ze=zr;var X=t=>e=>{let r=t?q(t):null;return e&&e.replaceWith(r),r},qr=()=>t=>{t&&t.remove()},Ir=(t=void 0,e=void 0)=>t===void 0||e===void 0?qr():typeof t=="string"||typeof e=="string"?X(e,t):t.tag_name!==e.tag_name?X(e):e.tag_name==="select"?Ze.select(t,e):["pre","code"].includes(e.tag_name)?X(e,t):o=>(z(t.attributes,e.attributes)(o),I(t.children,e.children)(o),o),G=Ir;var ze=(t=[],e=[])=>{let r=e||[],n=window?.joystick?._internal?.tree?.filter(o=>t?.includes(o?.instance_id));for(let o=0;o<n?.length;o+=1){let i=n[o];r.push(i);let c=E(i.children);c?.length>0&&ze(c,r)}return r},B=ze;var Gr=(t={},e={})=>{let r=e(t);return r&&s.is_object(r)&&!s.is_array(r)?Object.assign({},r):{}},Br=(t={},e={})=>s.is_function(e)?Gr(t,e):Object.assign({},e),W=Br;var Dr=(t={},e={})=>Object.entries(e).reduce((r={},[n,o])=>(r[n]=(...i)=>(u(`ui.${t?.options?.test?.name||m()}.methods.${n}`,[...i,{...t,set_state:t.setState.bind(t),setState:t.setState.bind(t),...t.compile_render_methods({},{},typeof window>"u"?[]:null)||{}}]),o(...i,{...t,set_state:t.setState.bind(t),setState:t.setState.bind(t),...t.compile_render_methods({},{},typeof window>"u"?[]:null)||{}})),r),{}),qe=Dr;var Ur=(t={},e={})=>[...Object.keys(e),...Object.keys(t)].filter((n,o,i)=>i.indexOf(n)===o).reduce((n,o)=>{let i=e[o],c=t[o]||null,a=!s.is_undefined(i)&&!s.is_null(i);return n[o]=a?i:c,n},{}),Ie=Ur;var Ge=(t="",e={})=>s.is_string(t)&&e?.route!=="*"?t===(typeof location<"u"?location.pathname:e.path):!1,Fr=(t={})=>({...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window<"u"){let n=new URL(window.location);n.searchParams.append(e,r),window.history.pushState({},"",n)}},unset:(e="")=>{if(typeof window<"u"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},is_active:(e="")=>Ge(e,t),isActive:(e="")=>Ge(e,t)}),Q=Fr;var Hr=async(t={},e={},r={},n={})=>{if(n?.options?.data&&s.is_function(n.options.data)){let o=await n.options.data(t,e,r,n);return Promise.resolve(o)}return Promise.resolve()},Be=Hr;var Vr=(t={},e={},r={})=>{let n=function(i){t.handler(i,{...t?.instance||{},set_state:t?.instance?.setState.bind(t?.instance),setState:t?.instance?.setState.bind(t?.instance),...r||{}}),u(`ui.${t?.instance?.options?.test?.name||m()}.events.${t.type}.selector_${t?.selector}`,[i,{...t?.instance||{},set_state:t?.instance?.setState.bind(t?.instance),setState:t?.instance?.setState.bind(t?.instance),...r||{}}])};e.addEventListener(t?.type,n),t.instance._event_listeners=[...t?.instance?._event_listeners||[],{selector:t?.selector,type:t?.type,element:e,handler:n}]},De=Vr;var Kr=(t="",e={})=>{let r="";if(t&&s.is_string(t))return r=t,r;if(t&&s.is_function(t))return r=t(e),r;if(t&&s.is_object(t)){let n=t?.print&&(s.is_string(t?.print)||s.is_function(t?.print)),o=t?.min&&s.is_object(t?.min),i=t?.min?.width&&s.is_object(t?.min?.width),c=t?.min?.height&&s.is_object(t?.min?.height),a=t?.max&&s.is_object(t?.max),d=t?.max?.width&&s.is_object(t?.max?.width),_=t?.max?.height&&s.is_object(t?.max?.height);if(n&&(r+=`
1
+ var Lt=(t="",e=[])=>{console.error(`${t} failed with the following errors:`);for(let r=0;r<e?.length;r+=1){let n=e[r];console.error(n.message),n.stack&&console.error(n.stack)}},y=Lt;var Rt=(t="{}")=>{try{return JSON.parse(t)}catch{return t}},j=Rt;var Tt=async(t={})=>{let e=await t.text();return j(e)},Nt=(t="GET",e={})=>["POST"].includes(t)?JSON.stringify({...e,origin:window?.location?.origin}):null,Pt=(t=null)=>{switch(t){case"authenticated":return"GET";case"user":default:return"POST"}},Zt=(t="",e={})=>{if(typeof window.fetch<"u")return new Promise((r,n)=>{let o=`${window.location.origin}/api/_accounts/${t}`,i=Pt(t),c=Nt(i,e);return fetch(o,{method:i,mode:"cors",headers:{"Content-Type":"application/json"},body:c,credentials:"include"}).then(async a=>{let d=await Tt(a);return d?.errors?(y(`accounts.${t}`,d.errors),n(d)):r(d)}).catch(a=>(y(`accounts.${t}`,[a]),n({errors:[a]})))})},$=Zt;var zt=async(t={})=>{let e=await $("authenticated",t);return e?.status===200&&e?.authenticated},pe=zt;var qt=(t={})=>$("login",t),we=qt;var It=()=>$("logout"),ge=It;var Gt=(t={})=>$("recover-password",t),H=Gt;var Bt=(t={})=>$("reset-password",t),V=Bt;var Dt=(t={})=>$("signup",t),$e=Dt;var Ut=async(t={})=>{let e=await $("user",t);return e?.status===200&&e?.user},ye=Ut;var Ft={authenticated:pe,login:we,logout:ge,recoverPassword:H,recover_password:H,resetPassword:V,reset_password:V,signup:$e,user:ye},xe=Ft;var Ht=t=>!!t,Vt=t=>!!Array.isArray(t),Kt=t=>t===!0||t===!1,Jt=t=>Number(t)===t&&t%1!==0,Yt=t=>typeof t=="function",Xt=t=>Number(t)===t&&t%1===0,Wt=t=>t===null,Qt=t=>Number(t)===t,er=t=>!!(t&&typeof t=="object"&&!Array.isArray(t)),tr=t=>typeof t=="string",rr=t=>typeof t>"u",nr={is_any:Ht,is_array:Vt,is_boolean:Kt,is_float:Jt,is_function:Yt,is_integer:Xt,is_null:Wt,is_number:Qt,is_object:er,is_string:tr,is_undefined:rr},s=nr;var K=class{constructor(e="",r={}){this.name=e,this.value=r||{},this.listeners={change:[],set:[],unset:[]}}_get_value_at_path(e=""){return e?.split(".").reduce((r=null,n="")=>(r[n]&&(r=r[n]),r),this.value)}get(e=""){return e?.trim()===""?{...this.value||{}}:this._get_value_at_path(e)}set(e=null,r=""){if(!e||!s.is_function(e))throw new Error("First argument passed to set() must be a function.");let n=e(this.value);if(!s.is_object(n))throw new Error("Value to set must be an object representing the current cache state.");this.value=n,this._handle_event("set",r),this._handle_event("change",r)}unset(e="",r=""){e?.trim()===""&&(this.value={});let n=e?.split("."),o=n?.length-1;n.reduce((i,c,a)=>(a===o&&delete i[c],i[c]),this.value),this._handle_event("unset",r),this._handle_event("change",r)}on(e="",r=null){if(!["change","set","unset"].includes(e))throw new Error(`Event to listen for must be change, set, or unset. ${e} is not supported.`);if(!r||!s.is_function(r))throw new Error("Second argument passed to on("<e>") must be a function.");this.listeners={[e]:[...this.listeners[e]||[],r]}}_handle_event(e="",r=""){let n=this.listeners[e]||[];for(let o=0;o<n?.length;o+=1){let i=n[o];s.is_function(i)&&i(this.value,e,r)}}},be=K;var J=(t="",e={})=>new be(t,e);var or=(t="")=>joystick._external[t]?joystick._external[t]:null,ve=or;var ir=(t=128,e="test.txt",r="text/plain")=>{let n=t instanceof Blob;return new File(n?t:new Blob(new Uint8Array(t||128),{type:r}),e,{type:r})},Y=ir;var sr=(t="",e=[])=>{typeof window<"u"&&window.__joystick_test__&&(window.test={...window.test||{},function_calls:{...window?.test?.function_calls||{},[t]:[...window?.test?.function_calls&&window?.test?.function_calls[t]||[],{called_at:new Date().toISOString(),args:e}]}})},u=sr;var dr={utils:{createFile:Y,create_file:Y,trackFunctionCall:u,track_function_call:u}},je=dr;var cr=(t="",e={})=>{typeof window<"u"&&(joystick._external[t]={...joystick._external[t]||{},...e})},ke=cr;var Ee="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890".split(""),ar=(t=16)=>{let e="",r=0;for(;r<t;)e+=Ee[Math.floor(Math.random()*(Ee.length-1))],r+=1;return e},m=ar;var k=null,R=0,Se=(t={},e=null)=>{if(window?.__joystick_test__)return e();let r=t?.url;t?.query&&(r=`${r}?${new URLSearchParams(t.query).toString()}`);let n=new WebSocket(r);k&&(clearInterval(k),k=null);let o={_id:m(8),client:n,send:(i={})=>(u(`ui.${t?.test?.name||m(16)}.websockets.send`,[i]),n.send(JSON.stringify(i)))};return n.addEventListener("open",()=>{t?.options?.logging&&console.log(`[joystick.websockets] Connected to ${t?.url}`),(t?.events?.onOpen||t?.events?.on_open)&&((t.events.onOpen||t.events.on_open)(o),u(`ui.websockets.${t?.test?.name||m()}.on_open`,[o])),R=0}),n.addEventListener("message",i=>{i?.data&&(t?.events?.onMessage||t?.events?.on_message)&&((t.events.onMessage||t.events.on_message)(JSON.parse(i.data||{}),o),u(`ui.websockets.${t?.test?.name||m()}.on_message`,[i.data||{},o]))}),n.addEventListener("close",i=>{t?.options?.logging&&console.log(`[joystick.websockets] Disconnected from ${t?.url}`),(t?.events?.onClose||t?.events?.on_close)&&((t.events.onClose||t.events.on_close)(i?.code,i?.reason,o),u(`ui.websockets.${t?.test?.name||m()}.on_close`,[i.data||{},o])),n=null;let c=[1e3,1001].includes(i?.code);window.joystick._internal.websockets&&(window.joystick._internal.websockets=window.joystick._internal.websockets?.filter(a=>a?._id!==o?._id)),(t?.options?.autoReconnect||t?.options?.auto_reconnect)&&!k&&!c&&(k=setInterval(()=>{n=null,R<(t?.options?.reconnectAttempts||t?.options?.reconnect_attempts||12)?(Se(t,e),t?.options?.logging&&console.log(`[joystick.websockets] Attempting to reconnect (${R+1}/12)...`),R+=1):clearInterval(k)},(t?.options?.reconnectDelayInSeconds||t?.options?.reconnect_delay_in_seconds)*1e3||5e3))}),e&&e(o),window.joystick?._internal&&(window.joystick._internal.websockets=[...window.joystick._internal.websockets||[],o]),o},T=Se;var Ae=(t="",e={})=>{if(window?.__joystick_test__){u(`ui.upload.${t}`,[t,e]);return}return new Promise((r,n)=>{let o=m(16),i=0;T({url:`${window?.process?.env.NODE_ENV==="development"?"ws":"wss"}://${location.host}/api/_websockets/uploaders`,options:{logging:!1,autoReconnect:!0,reconnectAttempts:12,reconnectDelayInSeconds:5},query:{id:o},events:{on_message:(c={})=>{c?.type==="PROGRESS"&&(e?.onProgress||e?.on_progress)&&i<100&&i!==c?.progress&&(i=c?.progress,(e.onProgress||e?.on_progress)(c?.progress,c?.provider))}}},()=>{let c;if(e?.files?.length>0){c=new FormData;let a=Array.from(e?.files);for(let d=0;d<a?.length;d+=1){let _=a[d];c.append("files",_,_.name)}}fetch(`${window.location.origin}/api/_uploaders/${t}`,{method:"POST",headers:{"x-joystick-upload-id":o,"x-joystick-upload-input":JSON.stringify(e?.input||{})},body:c}).then(async a=>{let d=await a.json();d&&d.errors?(y("upload",d.errors),n({errors:d.errors})):r(d?.uploads)})})})};var lr=(t={})=>Object.entries(t).map(([e,r])=>`${e}=${r}`)?.join("; "),N=lr;var _r=async(t={})=>{let e=await t.text();return j(e)},fr=(t="",e={})=>typeof window.fetch<"u"&&!e?.skip?new Promise((r,n)=>{let o=e.input?JSON.stringify(e.input):null,i=e.output?JSON.stringify(e.output):null,c=`${window.location.origin}/api/_getters/${t}?input=${o}&output=${i}`,a=document.querySelector('[name="csrf"]')?.getAttribute("content"),d={...e?.headers||{},"x-joystick-csrf":a};return window?.__joystick_test__&&(d.Cookie=N({joystick_login_token:window.__joystick_test_login_token__,joystick_login_token_expires_at:window.__joystick_test_login_token_expires_at__})),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!0}),fetch(c,{method:"GET",mode:"cors",headers:d,credentials:"include"}).then(async _=>{let f=await _r(_);return e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),f?.errors?(y("Get request",f.errors),n(f)):r(f)}).catch(_=>(y("Get request",[_]),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),n({errors:[_]})))}):Promise.resolve(),Oe=fr;var ur=async(t={})=>{let e=await t.text();return j(e)},mr=(t={})=>{let e={...t};return e?.loader&&delete e.loader,JSON.stringify(e)},hr=(t="",e={})=>typeof window.fetch<"u"?new Promise((r,n)=>{let o=`${window.location.origin}/api/_setters/${t}`,i=mr(e),c=document.querySelector('[name="csrf"]')?.getAttribute("content"),a={...e?.headers||{},"Content-Type":"application/json","x-joystick-csrf":c};return window?.__joystick_test__&&(a.Cookie=N({joystick_login_token:window?.__joystick_test_login_token__,joystick_login_token_expires_at:window.__joystick_test_login_token_expires_at__})),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!0}),fetch(o,{method:"POST",mode:"cors",headers:a,body:i,credentials:"include"}).then(async d=>{let _=await ur(d);return e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),_?.errors?(y("Set request",_.errors),n(_)):r(_)}).catch(d=>(y("Set request",[d]),e?.loader?.instance&&e?.loader?.instance?.setState({[e?.loader?.state||`${t}_loading`]:!1}),n({errors:[d]})))}):Promise.resolve(),Me=hr;var pr={fetch:typeof window<"u"?window.fetch.bind(window):null,get:Oe,set:Me},O=pr;var wr=(t="",e=new Error)=>{throw new Error(`[joystick${t?`.${t}`:""}] ${e.message||e}`)},Ce=wr;var gr=(t={})=>{let e=null;typeof window<"u"&&(e=window),typeof global<"u"&&(e=global),e&&(e.joystick={...e?.joystick||{},settings:e?.__joystick_settings__,...t})},Le=gr;var $r=(t={})=>Object.values(t)?.flatMap((e=[])=>e),E=$r;var yr=()=>{joystick._internal.tree=joystick?._internal?.tree?.filter(t=>!!document.querySelector(`[js-i="${t?.instance_id}"]`))},Re=yr;var xr=(t={},e=null)=>{let r=e(t);return r&&s.is_object(r)&&!s.is_array(r)?Object.assign({},r):{}},br=(t={},e={})=>s.is_function(e)?xr(t,e):Object.assign({},e),P=br;var vr=new RegExp(/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g),jr=new RegExp(/([^\r\n,{}]+)(,(?=[^}]*{)|\s*{)/g),kr=new RegExp(/\<\!\-\-(?:.|\n|\r)*?-->/g),Er=new RegExp("<when>|</when>","g"),Sr={CSS_COMMENT_REGEX:vr,CSS_SELECTOR_REGEX:jr,JOYSTICK_COMMENT_REGEX:kr,WHEN_TAG_REGEX:Er},M=Sr;var Ar=(()=>{let t=0;return(e,r)=>{clearTimeout(t),t=setTimeout(e,r)}})(),Te=Ar;var Or=(t="")=>{try{return document.createElement("div").setAttribute(t,"Test"),!0}catch{return!1}},Z=Or;var Mr=(t={},e={})=>{let r=[];for(let[n,o]of Object.entries(e))r.push(i=>(i&&i.setAttribute&&Z(n)&&i.setAttribute(n,o),i));for(let n in t)n in e||r.push(o=>(o&&o.removeAttribute&&o.removeAttribute(n),o));return n=>{for(let o of r)o&&typeof o=="function"&&o(n)}},z=Mr;var Cr=(t=[],e=[])=>{let r=[],n=Math.max(t.length,e.length);for(let o=0;o<n;o+=1){let i=t[o],c=e[o];r.push([i,c])}return r},Ne=Cr;var Lr=(t={})=>{let e=document.createElement(t.tag_name),r=Object.entries(t.attributes);for(let n=0;n<r.length;n+=1){let[o,i]=r[n];Z(o)&&e.setAttribute(o,i)}for(let n=0;n<t?.children?.length;n+=1){let o=t?.children[n];if(o){let i=Pe(o);e.appendChild(i)}}return e},Pe=(t=null)=>s.is_string(t)?document.createTextNode(t):Lr(t),q=Pe;var Rr=(t=[],e)=>{for(let r=0;r<t?.length;r+=1){let n=t[r];n&&typeof n=="function"&&n(e)}},Tr=(t=[])=>{for(let e=0;e<t?.length;e+=1){let[r,n]=t[e];r&&typeof r=="function"&&r(n)}},Nr=(t=[],e=[])=>{let r=[],n=e.slice(t.length);for(let o=0;o<n?.length;o+=1){let i=n[o],c=a=>{let d=q(i);return a.appendChild(d),a};r.push(c)}return r},Pr=(t=[],e=[])=>{let r=[];for(let n=0;n<t?.length;n+=1){let o=t[n],i=G(o,e[n]);r.push(i)}return r},Zr=(t=[],e=[])=>{let r=Pr(t,e),n=Nr(t,e);return o=>{if(o){let i=Ne(r,o.childNodes);Tr(i),Rr(n,o)}return o}},I=Zr;var zr={select:(t,e)=>r=>{let n=r.value;r.replaceChildren(),z(t.attributes,e.attributes)(r),I([],e.children)(r);let o=r.querySelector(`option[value="${n}"]`);if(o&&(r.value=n),!o){let i=r.querySelector("option");r.value=i?.value||""}return r}},Ze=zr;var X=t=>e=>{let r=t?q(t):null;return e&&e.replaceWith(r),r},qr=()=>t=>{t&&t.remove()},Ir=(t=void 0,e=void 0)=>t===void 0||e===void 0?qr():typeof t=="string"||typeof e=="string"?X(e,t):t.tag_name!==e.tag_name?X(e):e.tag_name==="select"?Ze.select(t,e):["pre","code"].includes(e.tag_name)?X(e,t):o=>(z(t.attributes,e.attributes)(o),I(t.children,e.children)(o),o),G=Ir;var ze=(t=[],e=[])=>{let r=e||[],n=window?.joystick?._internal?.tree?.filter(o=>t?.includes(o?.instance_id));for(let o=0;o<n?.length;o+=1){let i=n[o];r.push(i);let c=E(i.children);c?.length>0&&ze(c,r)}return r},B=ze;var Gr=(t={},e={})=>{let r=e(t);return r&&s.is_object(r)&&!s.is_array(r)?Object.assign({},r):{}},Br=(t={},e={})=>s.is_function(e)?Gr(t,e):Object.assign({},e),W=Br;var Dr=(t={},e={})=>Object.entries(e).reduce((r={},[n,o])=>(r[n]=(...i)=>(u(`ui.${t?.options?.test?.name||m()}.methods.${n}`,[...i,{...t,set_state:t.setState.bind(t),setState:t.setState.bind(t),...t.compile_render_methods({},{},typeof window>"u"?[]:null)||{}}]),o(...i,{...t,set_state:t.setState.bind(t),setState:t.setState.bind(t),...t.compile_render_methods({},{},typeof window>"u"?[]:null)||{}})),r),{}),qe=Dr;var Ur=(t={},e={})=>[...Object.keys(e),...Object.keys(t)].filter((n,o,i)=>i.indexOf(n)===o).reduce((n,o)=>{let i=e[o],c=t[o]||null,a=!s.is_undefined(i)&&!s.is_null(i);return n[o]=a?i:c,n},{}),Ie=Ur;var Ge=(t="",e={})=>s.is_string(t)&&e?.route!=="*"?t===(typeof location<"u"?location.pathname:e.path):!1,Fr=(t={})=>({...t,query:{...t?.query||{},set:(e="",r="")=>{if(typeof window<"u"){let n=new URL(window.location);n.searchParams.append(e,r),window.history.pushState({},"",n)}},unset:(e="")=>{if(typeof window<"u"){let r=new URL(window.location);r.searchParams.delete(e),window.history.pushState({},"",r)}}},is_active:(e="")=>Ge(e,t),isActive:(e="")=>Ge(e,t)}),Q=Fr;var Hr=async(t={},e={},r={},n={})=>{if(n?.options?.data&&s.is_function(n.options.data)){let o=await n.options.data(t,e,r,n);return Promise.resolve(o)}return Promise.resolve()},Be=Hr;var Vr=(t={},e={},r={})=>{let n=function(i){t.handler(i,{...t?.instance||{},set_state:t?.instance?.setState.bind(t?.instance),setState:t?.instance?.setState.bind(t?.instance),...r||{}}),u(`ui.${t?.instance?.options?.test?.name||m()}.events.${t.type}.selector_${t?.selector}`,[i,{...t?.instance||{},set_state:t?.instance?.setState.bind(t?.instance),setState:t?.instance?.setState.bind(t?.instance),...r||{}}])};e.addEventListener(t?.type,n),t.instance._event_listeners=[...t?.instance?._event_listeners||[],{selector:t?.selector,type:t?.type,element:e,handler:n}]},De=Vr;var Kr=(t="",e={})=>{let r="";if(t&&s.is_string(t))return r=t,r;if(t&&s.is_function(t))return r=t(e),r;if(t&&s.is_object(t)){let n=t?.print&&(s.is_string(t?.print)||s.is_function(t?.print)),o=t?.min&&s.is_object(t?.min),i=t?.min?.width&&s.is_object(t?.min?.width),c=t?.min?.height&&s.is_object(t?.min?.height),a=t?.max&&s.is_object(t?.max),d=t?.max?.width&&s.is_object(t?.max?.width),_=t?.max?.height&&s.is_object(t?.max?.height);if(n&&(r+=`
2
2
  @media print {
3
3
  ${typeof t?.print=="function"?t?.print(e):t.print}
4
4
  }
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.270",
4
+ "version": "0.0.0-canary.271",
5
5
  "description": "The UI framework for Joystick.",
6
6
  "main": "./dist/index.js",
7
7
  "scripts": {
@@ -1,6 +1,8 @@
1
1
  import get_child_instance_ids from "./get_child_instance_ids.js";
2
2
 
3
- const clean_up = (existing_children = {}) => {
3
+ const clean_up = () => {
4
+ // NOTE: If we can't find the instance_id in the DOM, we know that the instance
5
+ // was nuked during re-render and can safely be removed from the tree.
4
6
  joystick._internal.tree = joystick?._internal?.tree?.filter((node) => {
5
7
  return !!document.querySelector(`[js-i="${node?.instance_id}"]`);
6
8
  });