diff --git a/README.md b/README.md
index a4733965..dbd0b95a 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
-
+
@@ -62,6 +62,7 @@
- [Why TurboBoost Commands?](#why-turboboost-commands)
- [Sponsors](#sponsors)
+ - [Open Source projects like TurboBoost rely on your support](#open-source-projects-like-turboboost-rely-on-your-support)
- [Dependencies](#dependencies)
- [Setup](#setup)
- [Configuration](#configuration)
@@ -75,7 +76,8 @@
- [Setting Instance Variables](#setting-instance-variables)
- [Prevent Controller Action](#prevent-controller-action)
- [Broadcasting Turbo Streams](#broadcasting-turbo-streams)
- - [Tracking Page State](#tracking-page-state)
+ - [State](#state)
+ - [Ephemeral Page State](#ephemeral-page-state)
- [Community](#community)
- [Developing](#developing)
- [Notable Files](#notable-files)
@@ -113,8 +115,6 @@ Namely,
3. **(Re)render to reflect the new state**
4. _repeat..._
-_The primary distinction being that **state is wholly managed by the server**._
-
Commands are executed via a Rails `before_action` which means that reactivity runs over HTTP.
_**Web sockets are NOT used for the reactive critical path!** 🎉_
This also means that standard Rails mechanics drive their behavior.
@@ -134,10 +134,10 @@ Your contribution will help drive the evolution of **TurboBoost**, enabling new
-
+
-
+
@@ -527,7 +527,11 @@ _Learn more about Turbo Stream broadcasting by reading through the
> [!NOTE]
> `broadcast_invoke_later_to` is a [TurboBoost Streams](https://github.com/hopsoft/turbo_boost-streams#broadcasting) feature.
-### Tracking Page State
+## State
+
+TODO: Document state tracking
+
+### Ephemeral Page State
You can opt-in to remember transient page state when using Rails tag helpers with `turbo_boost[:remember]` to track
element attribute values between requests.
diff --git a/app/assets/builds/@turbo-boost/commands.js b/app/assets/builds/@turbo-boost/commands.js
index 1e13744b..ec0d6cfe 100644
--- a/app/assets/builds/@turbo-boost/commands.js
+++ b/app/assets/builds/@turbo-boost/commands.js
@@ -1,2 +1,2 @@
-var mt=Object.defineProperty,lt=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable;var K=(t,e,r)=>e in t?mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s=(t,e)=>{for(var r in e||(e={}))pt.call(e,r)&&K(t,r,e[r]);if(X)for(var r of X(e))bt.call(e,r)&&K(t,r,e[r]);return t},p=(t,e)=>lt(t,ft(e));var gt="TurboBoost-Command",y={boost:"text/vnd.turbo-boost.html",stream:"text/vnd.turbo-stream.html",html:"text/html",xhtml:"application/xhtml+xml",json:"application/json"},ht=(t={})=>{t=s({},t);let e=(t.Accept||"").split(",").map(r=>r.trim()).filter(r=>r.length);return e.unshift(y.boost,y.stream,y.html,y.xhtml),t.Accept=[...new Set(e)].join(", "),t["Content-Type"]=y.json,t["X-Requested-With"]="XMLHttpRequest",t},vt=t=>{if(t){let[e,r,o]=t.split(", ");return{name:e,status:r,strategy:o}}return{}},f={prepare:ht,tokenize:vt,RESPONSE_HEADER:gt};var yt=t=>{document.body.insertAdjacentHTML("beforeend",t)},Et=t=>{var h,k,v,C;let r=new DOMParser().parseFromString(t,"text/html"),o=document.querySelector("head"),n=document.querySelector("body"),i=r.querySelector("head"),c=r.querySelector("body");o&&i&&((k=(h=TurboBoost==null?void 0:TurboBoost.Streams)==null?void 0:h.morph)==null||k.method(o,i)),n&&c&&((C=(v=TurboBoost==null?void 0:TurboBoost.Streams)==null?void 0:v.morph)==null||C.method(n,c))},w=(t,e)=>{if(t&&e){if(t.match(/^Append$/i))return yt(e);if(t.match(/^Replace$/i))return Et(e)}};var B={};addEventListener("turbo:before-fetch-response",t=>{let e=t.target.closest("turbo-frame");e!=null&&e.id&&(e!=null&&e.src)&&(B[e.id]=e.src);let{fetchResponse:r}=t.detail,o=r.header(f.RESPONSE_HEADER);if(!o)return;t.preventDefault();let{strategy:n}=f.tokenize(o);r.responseHTML.then(i=>w(n,i))});addEventListener("turbo:frame-load",t=>{let e=t.target.closest("turbo-frame");e.dataset.src=B[e.id]||e.src||e.dataset.src,delete B[e.id]});var At={frameAttribute:"data-turbo-frame",methodAttribute:"data-turbo-method",commandAttribute:"data-turbo-command",confirmAttribute:"data-turbo-confirm",stateAttributesAttribute:"data-turbo-boost-state-attributes"},d=s({},At);var a={start:"turbo-boost:command:start",success:"turbo-boost:command:success",finish:"turbo-boost:command:finish",abort:"turbo-boost:command:abort",clientError:"turbo-boost:command:client-error",serverError:"turbo-boost:command:server-error"},E={stateChange:"turbo-boost:state:change",stateInitialize:"turbo-boost:state:initialize"};function u(t,e,r={}){return new Promise(o=>{r=r||{},r.detail=r.detail||{},e=e||document;let n=new CustomEvent(t,p(s({},r),{bubbles:!0}));e.dispatchEvent(n),o(n)})}var L={};function St(t){L[t.id]=t}function xt(t){delete L[t]}var O={add:St,remove:xt,get commands(){return[...Object.values(L)]},get length(){return Object.keys(L).length}};var G={method:t=>Promise.resolve(confirm(t))},kt=t=>t.detail.driver==="method",Ct=t=>{if(t.detail.driver!=="form")return!1;let e=t.target,r=e.closest("turbo-frame"),o=e.closest(`[${d.frameAttribute}]`);return!!(r||o)},wt=t=>kt(t)||Ct(t);document.addEventListener(a.start,async t=>{let e=t.target.getAttribute(d.confirmAttribute);if(!e||(t.detail.confirmation=!0,wt(t)))return;await G.method(e)||t.preventDefault()});var Q=G;var l=[],I;function Lt(t,e){let r=l.find(o=>o.name===t);return r&&l.splice(l.indexOf(r),1),l=[{name:t,selectors:e},...l],document.removeEventListener(t,I,!0),document.addEventListener(t,I,!0),s({},l.find(o=>o.name===t))}function Ot(t){return l.find(e=>e.selectors.find(r=>Array.from(document.querySelectorAll(r)).find(o=>o===t)))}function Tt(t,e){let r=Ot(e);return r&&r.name===t}var m={register:Lt,isRegisteredForElement:Tt,get events(){return[...l]},set handler(t){I=t}};function Rt(t){return t.closest(`[${d.commandAttribute}]`)}function Pt(t){return t.closest("turbo-frame[src]")||t.closest("turbo-frame[data-turbo-frame-src]")||t.closest("turbo-frame")}function $t(t,e={}){if(t.tagName.toLowerCase()!=="select")return e.value=t.value||null;if(!t.multiple)return e.value=t.options[t.selectedIndex].value;e.values=Array.from(t.options).reduce((r,o)=>(o.selected&&r.push(o.value),r),[])}function _t(t){let e=Array.from(t.attributes).reduce((r,o)=>{let n=o.value;return r[o.name]=n,r},{});return e.tag=t.tagName,e.checked=!!t.checked,e.disabled=!!t.disabled,$t(t,e),delete e.class,delete e.action,delete e.href,delete e[d.commandAttribute],delete e[d.frameAttribute],e}var A={buildAttributePayload:_t,findClosestCommand:Rt,findClosestFrameWithSource:Pt};var Dt=(t,e={})=>{let r=t.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");r.type="hidden",r.name="turbo_boost_command",r.value=JSON.stringify(e),t.contains(r)||t.appendChild(r)},Y={invokeCommand:Dt};function Nt(t){setTimeout(()=>u(a.finish,t.target,{detail:t.detail}))}var Bt=[a.abort,a.serverError,a.success];Bt.forEach(t=>addEventListener(t,Nt));addEventListener(a.finish,t=>O.remove(t.detail.id),!0);var Z={events:a};var It=t=>{let e=document.createElement("a");return e.href=t,new URL(e)},tt={get commandInvocationURL(){return It("/turbo-boost-command-invocation")}};var et=t=>{let e=`Unexpected error performing a TurboBoost Command! ${t.message}`;u(Z.events.clientError,document,{detail:{message:e,error:t}},!0)},jt=t=>{let{strategy:e}=f.tokenize(t.headers.get(f.RESPONSE_HEADER));t.text().then(r=>w(e,r))},T=(t={})=>{try{fetch(tt.commandInvocationURL.href,{method:"POST",headers:f.prepare({}),body:JSON.stringify(t)}).then(jt).catch(et)}catch(e){et(e)}};var qt=(t,e)=>T(e),j={invokeCommand:qt};var S,q,zt=()=>{S=null,q=null},Ft=(t,e={})=>{S=t,q=e},Ht=t=>{try{if(!S||t.getAttribute("method")!==S.dataset.turboMethod||t.getAttribute("action")!==S.href)return;let e=t.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");e.type="hidden",e.name="turbo_boost_command",e.value=JSON.stringify(q),t.contains(e)||t.appendChild(e)}finally{zt()}};document.addEventListener("submit",t=>Ht(t.target),!0);var rt={invokeCommand:Ft};var Jt=(t,e={})=>T(e),ot={invokeCommand:Jt};function z(t,e){return e=e||{dataset:{}},t.href||e.src||e.dataset.src||location.href}function Mt(t){let e=A.findClosestFrameWithSource(t),{turboFrame:r,turboMethod:o}=t.dataset;return t.tagName.toLowerCase()==="form"?{name:"form",reason:"Element is a form.",frame:e,src:t.action,invokeCommand:Y.invokeCommand}:o!=null&&o.length?{name:"method",reason:"Element defines data-turbo-method.",frame:e,src:t.href,invokeCommand:rt.invokeCommand}:r&&r!=="_self"?(e=document.getElementById(r),{name:"frame",reason:"element targets a frame that is not _self",frame:e,src:z(t,e),invokeCommand:j.invokeCommand}):(!r||r==="_self")&&e?{name:"frame",reason:"element does NOT target a frame or targets _self and is contained by a frame",frame:e,src:z(t,e),invokeCommand:j.invokeCommand}:{name:"window",reason:"element matches one or more of the following conditions (targets _top, does NOT target a frame, is NOT contained by a frame)",frame:null,src:z(t),invokeCommand:ot.invokeCommand}}var F={find:Mt};var P="unknown",nt=!1,R=[],b={debug:Object.values(a),info:Object.values(a),warn:[a.abort,a.clientError,a.serverError],error:[a.clientError,a.serverError],unknown:[]},Ut=t=>{if(!b[P].includes(t.type)||typeof console[P]!="function")return!1;let{detail:e}=t;if(!e.id)return!0;let r=`${t.type}-${e.id}`;return R.includes(r)?!1:(R.length>16&&R.shift(),R.push(r),!0)},Vt=t=>b.error.includes(t.type)?"error":b.warn.includes(t.type)?"warn":b.info.includes(t.type)?"info":b.debug.includes(t.type)?"debug":"log",Wt=t=>{if(Ut(t)){let{target:e,type:r,detail:o}=t,n=o.id||"",i=o.name||"",c="";o.startedAt&&(c=`${Date.now()-o.startedAt}ms `);let h=r.split(":"),k=h.pop(),v=`%c${h.join(":")}:%c${k}`,C=[`%c${i}`,`%c${c}`,v];console[Vt(t)](C.join(" ").replace(/\s{2,}/g," "),"color:deepskyblue","color:lime","color:darkgray",v.match(/abort|error/i)?"color:red":"color:deepskyblue",{id:n,detail:o,target:e})}};nt||(nt=!0,Object.values(a).forEach(t=>addEventListener(t,e=>Wt(e))));var at={get level(){return P},set level(t){return Object.keys(b).includes(t)||(t="unknown"),P=t}};var H;function $(t,e=null){if(!t||typeof t!="object")return t;let r=new Proxy(t,{deleteProperty(o,n){return delete o[n],u(E.stateChange,document,{detail:{state:H}}),!0},set(o,n,i,c){return o[n]=$(i,this),u(E.stateChange,document,{detail:{state:H}}),!0}});if(Array.isArray(t))t.forEach((o,n)=>t[n]=$(o,r));else if(typeof t=="object")for(let[o,n]of Object.entries(t))t[o]=$(n,r);return e||(H=r),r}var J=$;var st=(t,e,r,o=1)=>{if(o>20)return;let n=document.getElementById(t);if(n!=null&&n.isConnected)return n.setAttribute(e,r);setTimeout(()=>st(t,e,r,o+1),o*5)},Xt=()=>Array.from(document.querySelectorAll(`[id][${d.stateAttributesAttribute}]`)).reduce((e,r)=>{let o=JSON.parse(r.getAttribute(d.stateAttributesAttribute));if(r.id){let n=o.reduce((i,c)=>(r.hasAttribute(c)&&(i[c]=r.getAttribute(c)||c),i),{});Object.values(n).length&&(e[r.id]=n)}return e},{}),Kt=(t={})=>{for(let[e,r]of Object.entries(t))for(let[o,n]of Object.entries(r))st(e,o,n)},_={buildState:Xt,restoreState:Kt};function Gt(t,e){return typeof e!="object"&&(e={}),localStorage.setItem(String(t),JSON.stringify(e))}function Qt(t){let e=localStorage.getItem(String(t));return e?JSON.parse(e):{}}var D={save:Gt,find:Qt};var M="TurboBoost::State",U={pages:{},signed:null,unsigned:{}},N=null,x={},V=()=>{let t=s(s({},U),D.find(M));N=t.signed,x=J(t.unsigned),t.pages[location.pathname]=t.pages[location.pathname]||{},_.restoreState(t.pages[location.pathname])},W=()=>{let t=s(s({},U),D.find(M)),e={signed:N||t.signed,unsigned:s(s({},t.unsigned),x),pages:s({},t.pages)},r=location.pathname,o=_.buildState();Object.values(o).length?e.pages[r]=o:delete e.pages[r],D.save(M,e)},Yt=t=>{let e=s(s({},U),JSON.parse(t));N=e.signed,x=J(e.unsigned),W(),u(E.stateInitialize,document,{detail:x})};addEventListener("DOMContentLoaded",V);addEventListener("turbo:morph",V);addEventListener("turbo:render",V);addEventListener("turbo:before-fetch-request",W);addEventListener("beforeunload",W);var g={initialize:Yt,buildPageState:_.buildState,get signed(){return N},get unsigned(){return x}};function Zt(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}var it={v4:Zt};var dt="0.3.1";var te=self.TurboBoost||{},ut={VERSION:dt,active:!1,confirmation:Q,logger:at,schema:d,events:a,registerEventDelegate:m.register,get eventDelegates(){return m.events}};function ct(t,e){var r;return{csrfToken:(r=document.querySelector('meta[name="csrf-token"]'))==null?void 0:r.getAttribute("content"),id:t,name:e.getAttribute(d.commandAttribute),elementId:e.id.length?e.id:null,elementAttributes:A.buildAttributePayload(e),startedAt:Date.now(),state:{page:g.buildPageState(),signed:g.signed,unsigned:g.unsigned}}}async function ee(t){let e,r={};try{if(e=A.findClosestCommand(t.target),!e||!m.isRegisteredForElement(t.type,e))return;let o=it.v4(),n=F.find(e),i=p(s({},ct(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),c=await u(a.start,e,{cancelable:!0,detail:i});if(c.defaultPrevented||c.detail.confirmation&&t.defaultPrevented)return u(a.abort,e,{detail:{message:`An event handler for '${a.start}' prevented default behavior and blocked command invocation!`,source:c}});switch(n=F.find(e),i=p(s({},ct(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),O.add(i),["frame","window"].includes(n.name)&&t.preventDefault(),n.name){case"method":return n.invokeCommand(e,i);case"form":return n.invokeCommand(e,i,t);case"frame":return n.invokeCommand(n.frame,i);case"window":return n.invokeCommand(self,i)}}catch(o){u(a.clientError,e,{detail:p(s({},r),{error:o})})}}self.TurboBoost=s({},te);self.TurboBoost.Commands||(m.handler=ee,m.register("click",[`[${d.commandAttribute}]`]),m.register("submit",[`form[${d.commandAttribute}]`]),m.register("toggle",[`details[${d.commandAttribute}]`]),m.register("change",[`input[${d.commandAttribute}]`,`select[${d.commandAttribute}]`,`textarea[${d.commandAttribute}]`]),self.TurboBoost.Commands=ut,self.TurboBoost.State={initialize:g.initialize,get current(){return g.unsigned}});var gr=ut;export{gr as default};
+var mt=Object.defineProperty,lt=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable;var K=(t,e,r)=>e in t?mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,s=(t,e)=>{for(var r in e||(e={}))pt.call(e,r)&&K(t,r,e[r]);if(X)for(var r of X(e))bt.call(e,r)&&K(t,r,e[r]);return t},p=(t,e)=>lt(t,ft(e));var gt="TurboBoost-Command",y={boost:"text/vnd.turbo-boost.html",stream:"text/vnd.turbo-stream.html",html:"text/html",xhtml:"application/xhtml+xml",json:"application/json"},ht=(t={})=>{t=s({},t);let e=(t.Accept||"").split(",").map(r=>r.trim()).filter(r=>r.length);return e.unshift(y.boost,y.stream,y.html,y.xhtml),t.Accept=[...new Set(e)].join(", "),t["Content-Type"]=y.json,t["X-Requested-With"]="XMLHttpRequest",t},vt=t=>{if(t){let[e,r,o]=t.split(", ");return{name:e,status:r,strategy:o}}return{}},f={prepare:ht,tokenize:vt,RESPONSE_HEADER:gt};var yt=t=>{document.body.insertAdjacentHTML("beforeend",t)},Et=t=>{var h,k,v,C;let r=new DOMParser().parseFromString(t,"text/html"),o=document.querySelector("head"),n=document.querySelector("body"),i=r.querySelector("head"),c=r.querySelector("body");o&&i&&((k=(h=TurboBoost==null?void 0:TurboBoost.Streams)==null?void 0:h.morph)==null||k.method(o,i)),n&&c&&((C=(v=TurboBoost==null?void 0:TurboBoost.Streams)==null?void 0:v.morph)==null||C.method(n,c))},w=(t,e)=>{if(t&&e){if(t.match(/^Append$/i))return yt(e);if(t.match(/^Replace$/i))return Et(e)}};var B={};addEventListener("turbo:before-fetch-response",t=>{let e=t.target.closest("turbo-frame");e!=null&&e.id&&(e!=null&&e.src)&&(B[e.id]=e.src);let{fetchResponse:r}=t.detail,o=r.header(f.RESPONSE_HEADER);if(!o)return;t.preventDefault();let{strategy:n}=f.tokenize(o);r.responseHTML.then(i=>w(n,i))});addEventListener("turbo:frame-load",t=>{let e=t.target.closest("turbo-frame");e.dataset.src=B[e.id]||e.src||e.dataset.src,delete B[e.id]});var At={frameAttribute:"data-turbo-frame",methodAttribute:"data-turbo-method",commandAttribute:"data-turbo-command",confirmAttribute:"data-turbo-confirm",stateAttributesAttribute:"data-turbo-boost-state-attributes"},d=s({},At);var a={start:"turbo-boost:command:start",success:"turbo-boost:command:success",finish:"turbo-boost:command:finish",abort:"turbo-boost:command:abort",clientError:"turbo-boost:command:client-error",serverError:"turbo-boost:command:server-error"},E={stateChange:"turbo-boost:state:change",stateInitialize:"turbo-boost:state:initialize"};function u(t,e,r={}){return new Promise(o=>{r=r||{},r.detail=r.detail||{},e=e||document;let n=new CustomEvent(t,p(s({},r),{bubbles:!0}));e.dispatchEvent(n),o(n)})}var L={};function St(t){L[t.id]=t}function xt(t){delete L[t]}var O={add:St,remove:xt,get commands(){return[...Object.values(L)]},get length(){return Object.keys(L).length}};var G={method:t=>Promise.resolve(confirm(t))},kt=t=>t.detail.driver==="method",Ct=t=>{if(t.detail.driver!=="form")return!1;let e=t.target,r=e.closest("turbo-frame"),o=e.closest(`[${d.frameAttribute}]`);return!!(r||o)},wt=t=>kt(t)||Ct(t);document.addEventListener(a.start,async t=>{let e=t.target.getAttribute(d.confirmAttribute);if(!e||(t.detail.confirmation=!0,wt(t)))return;await G.method(e)||t.preventDefault()});var Q=G;var l=[],I;function Lt(t,e){let r=l.find(o=>o.name===t);return r&&l.splice(l.indexOf(r),1),l=[{name:t,selectors:e},...l],document.removeEventListener(t,I,!0),document.addEventListener(t,I,!0),s({},l.find(o=>o.name===t))}function Ot(t){return l.find(e=>e.selectors.find(r=>Array.from(document.querySelectorAll(r)).find(o=>o===t)))}function Tt(t,e){let r=Ot(e);return r&&r.name===t}var m={register:Lt,isRegisteredForElement:Tt,get events(){return[...l]},set handler(t){I=t}};function Rt(t){return t.closest(`[${d.commandAttribute}]`)}function Pt(t){return t.closest("turbo-frame[src]")||t.closest("turbo-frame[data-turbo-frame-src]")||t.closest("turbo-frame")}function $t(t,e={}){if(t.tagName.toLowerCase()!=="select")return e.value=t.value||null;if(!t.multiple)return e.value=t.options[t.selectedIndex].value;e.values=Array.from(t.options).reduce((r,o)=>(o.selected&&r.push(o.value),r),[])}function _t(t){let e=Array.from(t.attributes).reduce((r,o)=>{let n=o.value;return r[o.name]=n,r},{});return e.tag=t.tagName,e.checked=!!t.checked,e.disabled=!!t.disabled,$t(t,e),delete e.class,delete e.action,delete e.href,delete e[d.commandAttribute],delete e[d.frameAttribute],e}var A={buildAttributePayload:_t,findClosestCommand:Rt,findClosestFrameWithSource:Pt};var Dt=(t,e={})=>{let r=t.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");r.type="hidden",r.name="turbo_boost_command",r.value=JSON.stringify(e),t.contains(r)||t.appendChild(r)},Y={invokeCommand:Dt};function Nt(t){setTimeout(()=>u(a.finish,t.target,{detail:t.detail}))}var Bt=[a.abort,a.serverError,a.success];Bt.forEach(t=>addEventListener(t,Nt));addEventListener(a.finish,t=>O.remove(t.detail.id),!0);var Z={events:a};var It=t=>{let e=document.createElement("a");return e.href=t,new URL(e)},tt={get commandInvocationURL(){return It("/turbo-boost-command-invocation")}};var et=t=>{let e=`Unexpected error performing a TurboBoost Command! ${t.message}`;u(Z.events.clientError,document,{detail:{message:e,error:t}},!0)},jt=t=>{let{strategy:e}=f.tokenize(t.headers.get(f.RESPONSE_HEADER));t.text().then(r=>w(e,r))},T=(t={})=>{try{fetch(tt.commandInvocationURL.href,{method:"POST",headers:f.prepare({}),body:JSON.stringify(t)}).then(jt).catch(et)}catch(e){et(e)}};var qt=(t,e)=>T(e),j={invokeCommand:qt};var S,q,zt=()=>{S=null,q=null},Ft=(t,e={})=>{S=t,q=e},Ht=t=>{try{if(!S||t.getAttribute("method")!==S.dataset.turboMethod||t.getAttribute("action")!==S.href)return;let e=t.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");e.type="hidden",e.name="turbo_boost_command",e.value=JSON.stringify(q),t.contains(e)||t.appendChild(e)}finally{zt()}};document.addEventListener("submit",t=>Ht(t.target),!0);var rt={invokeCommand:Ft};var Jt=(t,e={})=>T(e),ot={invokeCommand:Jt};function z(t,e){return e=e||{dataset:{}},t.href||e.src||e.dataset.src||location.href}function Mt(t){let e=A.findClosestFrameWithSource(t),{turboFrame:r,turboMethod:o}=t.dataset;return t.tagName.toLowerCase()==="form"?{name:"form",reason:"Element is a form.",frame:e,src:t.action,invokeCommand:Y.invokeCommand}:o!=null&&o.length?{name:"method",reason:"Element defines data-turbo-method.",frame:e,src:t.href,invokeCommand:rt.invokeCommand}:r&&r!=="_self"?(e=document.getElementById(r),{name:"frame",reason:"element targets a frame that is not _self",frame:e,src:z(t,e),invokeCommand:j.invokeCommand}):(!r||r==="_self")&&e?{name:"frame",reason:"element does NOT target a frame or targets _self and is contained by a frame",frame:e,src:z(t,e),invokeCommand:j.invokeCommand}:{name:"window",reason:"element matches one or more of the following conditions (targets _top, does NOT target a frame, is NOT contained by a frame)",frame:null,src:z(t),invokeCommand:ot.invokeCommand}}var F={find:Mt};var P="unknown",nt=!1,R=[],b={debug:Object.values(a),info:Object.values(a),warn:[a.abort,a.clientError,a.serverError],error:[a.clientError,a.serverError],unknown:[]},Ut=t=>{if(!b[P].includes(t.type)||typeof console[P]!="function")return!1;let{detail:e}=t;if(!e.id)return!0;let r=`${t.type}-${e.id}`;return R.includes(r)?!1:(R.length>16&&R.shift(),R.push(r),!0)},Vt=t=>b.error.includes(t.type)?"error":b.warn.includes(t.type)?"warn":b.info.includes(t.type)?"info":b.debug.includes(t.type)?"debug":"log",Wt=t=>{if(Ut(t)){let{target:e,type:r,detail:o}=t,n=o.id||"",i=o.name||"",c="";o.startedAt&&(c=`${Date.now()-o.startedAt}ms `);let h=r.split(":"),k=h.pop(),v=`%c${h.join(":")}:%c${k}`,C=[`%c${i}`,`%c${c}`,v];console[Vt(t)](C.join(" ").replace(/\s{2,}/g," "),"color:deepskyblue","color:lime","color:darkgray",v.match(/abort|error/i)?"color:red":"color:deepskyblue",{id:n,detail:o,target:e})}};nt||(nt=!0,Object.values(a).forEach(t=>addEventListener(t,e=>Wt(e))));var at={get level(){return P},set level(t){return Object.keys(b).includes(t)||(t="unknown"),P=t}};var H;function $(t,e=null){if(!t||typeof t!="object")return t;let r=new Proxy(t,{deleteProperty(o,n){return delete o[n],u(E.stateChange,document,{detail:{state:H}}),!0},set(o,n,i,c){return o[n]=$(i,this),u(E.stateChange,document,{detail:{state:H}}),!0}});if(Array.isArray(t))t.forEach((o,n)=>t[n]=$(o,r));else if(typeof t=="object")for(let[o,n]of Object.entries(t))t[o]=$(n,r);return e||(H=r),r}var J=$;var st=(t,e,r,o=1)=>{if(o>20)return;let n=document.getElementById(t);if(n!=null&&n.isConnected)return n.setAttribute(e,r);setTimeout(()=>st(t,e,r,o+1),o*5)},Xt=()=>Array.from(document.querySelectorAll(`[id][${d.stateAttributesAttribute}]`)).reduce((e,r)=>{let o=JSON.parse(r.getAttribute(d.stateAttributesAttribute));if(r.id){let n=o.reduce((i,c)=>(r.hasAttribute(c)&&(i[c]=r.getAttribute(c)||c),i),{});Object.values(n).length&&(e[r.id]=n)}return e},{}),Kt=(t={})=>{for(let[e,r]of Object.entries(t))for(let[o,n]of Object.entries(r))st(e,o,n)},_={buildState:Xt,restoreState:Kt};function Gt(t,e){return typeof e!="object"&&(e={}),localStorage.setItem(String(t),JSON.stringify(e))}function Qt(t){let e=localStorage.getItem(String(t));return e?JSON.parse(e):{}}var D={save:Gt,find:Qt};var M="TurboBoost::State",U={pages:{},signed:null,unsigned:{}},N=null,x={},V=()=>{let t=s(s({},U),D.find(M));N=t.signed,x=J(t.unsigned),t.pages[location.pathname]=t.pages[location.pathname]||{},_.restoreState(t.pages[location.pathname])},W=()=>{let t=s(s({},U),D.find(M)),e={signed:N||t.signed,unsigned:s(s({},t.unsigned),x),pages:s({},t.pages)},r=location.pathname,o=_.buildState();Object.values(o).length?e.pages[r]=o:delete e.pages[r],D.save(M,e)},Yt=t=>{let e=s(s({},U),JSON.parse(t));N=e.signed,x=J(e.unsigned),W(),u(E.stateInitialize,document,{detail:x})};addEventListener("DOMContentLoaded",V);addEventListener("turbo:morph",V);addEventListener("turbo:render",V);addEventListener("turbo:before-fetch-request",W);addEventListener("beforeunload",W);var g={initialize:Yt,buildPageState:_.buildState,get signed(){return N},get unsigned(){return x}};function Zt(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}var it={v4:Zt};var dt="0.3.2";var te=self.TurboBoost||{},ut={VERSION:dt,active:!1,confirmation:Q,logger:at,schema:d,events:a,registerEventDelegate:m.register,get eventDelegates(){return m.events}};function ct(t,e){var r;return{csrfToken:(r=document.querySelector('meta[name="csrf-token"]'))==null?void 0:r.getAttribute("content"),id:t,name:e.getAttribute(d.commandAttribute),elementId:e.id.length?e.id:null,elementAttributes:A.buildAttributePayload(e),startedAt:Date.now(),state:{page:g.buildPageState(),signed:g.signed,unsigned:g.unsigned}}}async function ee(t){let e,r={};try{if(e=A.findClosestCommand(t.target),!e||!m.isRegisteredForElement(t.type,e))return;let o=it.v4(),n=F.find(e),i=p(s({},ct(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),c=await u(a.start,e,{cancelable:!0,detail:i});if(c.defaultPrevented||c.detail.confirmation&&t.defaultPrevented)return u(a.abort,e,{detail:{message:`An event handler for '${a.start}' prevented default behavior and blocked command invocation!`,source:c}});switch(n=F.find(e),i=p(s({},ct(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),O.add(i),["frame","window"].includes(n.name)&&t.preventDefault(),n.name){case"method":return n.invokeCommand(e,i);case"form":return n.invokeCommand(e,i,t);case"frame":return n.invokeCommand(n.frame,i);case"window":return n.invokeCommand(self,i)}}catch(o){u(a.clientError,e,{detail:p(s({},r),{error:o})})}}self.TurboBoost=s({},te);self.TurboBoost.Commands||(m.handler=ee,m.register("click",[`[${d.commandAttribute}]`]),m.register("submit",[`form[${d.commandAttribute}]`]),m.register("toggle",[`details[${d.commandAttribute}]`]),m.register("change",[`input[${d.commandAttribute}]`,`select[${d.commandAttribute}]`,`textarea[${d.commandAttribute}]`]),self.TurboBoost.Commands=ut,self.TurboBoost.State={initialize:g.initialize,get current(){return g.unsigned}});var gr=ut;export{gr as default};
//# sourceMappingURL=commands.js.map
diff --git a/app/assets/builds/@turbo-boost/commands.js.map b/app/assets/builds/@turbo-boost/commands.js.map
index 12bf9d93..6a58d910 100644
--- a/app/assets/builds/@turbo-boost/commands.js.map
+++ b/app/assets/builds/@turbo-boost/commands.js.map
@@ -1,7 +1,7 @@
{
"version": 3,
"sources": ["../../../javascript/headers.js", "../../../javascript/renderer.js", "../../../javascript/turbo.js", "../../../javascript/schema.js", "../../../javascript/events.js", "../../../javascript/activity.js", "../../../javascript/confirmation.js", "../../../javascript/delegates.js", "../../../javascript/elements.js", "../../../javascript/drivers/form.js", "../../../javascript/lifecycle.js", "../../../javascript/urls.js", "../../../javascript/invoker.js", "../../../javascript/drivers/frame.js", "../../../javascript/drivers/method.js", "../../../javascript/drivers/window.js", "../../../javascript/drivers/index.js", "../../../javascript/logger.js", "../../../javascript/state/observable.js", "../../../javascript/state/page.js", "../../../javascript/state/storage.js", "../../../javascript/state/index.js", "../../../javascript/uuids.js", "../../../javascript/version.js", "../../../javascript/index.js"],
- "sourcesContent": ["const RESPONSE_HEADER = 'TurboBoost-Command'\n\nconst types = {\n boost: 'text/vnd.turbo-boost.html',\n stream: 'text/vnd.turbo-stream.html',\n html: 'text/html',\n xhtml: 'application/xhtml+xml',\n json: 'application/json'\n}\n\n// Prepares request headers for TurboBoost Command invocations\nconst prepare = (headers = {}) => {\n headers = { ...headers }\n\n // Assign Accept values\n const accepts = (headers['Accept'] || '')\n .split(',')\n .map(val => val.trim())\n .filter(val => val.length)\n\n accepts.unshift(types.boost, types.stream, types.html, types.xhtml)\n headers['Accept'] = [...new Set(accepts)].join(', ')\n\n // Assign Content-Type (Commands POST JSON via fetch/XHR)\n headers['Content-Type'] = types.json\n\n // Assign X-Requested-With for XHR detection\n headers['X-Requested-With'] = 'XMLHttpRequest'\n\n return headers\n}\n\n// Tokenizes the 'TurboBoost-Command' HTTP response header value\nconst tokenize = value => {\n if (value) {\n const [name, status, strategy] = value.split(', ')\n return { name, status, strategy }\n }\n\n return {}\n}\n\nexport default { prepare, tokenize, RESPONSE_HEADER }\n", "const append = content => {\n document.body.insertAdjacentHTML('beforeend', content)\n}\n\nconst replace = content => {\n const parser = new DOMParser()\n const doc = parser.parseFromString(content, 'text/html')\n const head = document.querySelector('head')\n const body = document.querySelector('body')\n const newHead = doc.querySelector('head')\n const newBody = doc.querySelector('body')\n if (head && newHead) TurboBoost?.Streams?.morph?.method(head, newHead)\n if (body && newBody) TurboBoost?.Streams?.morph?.method(body, newBody)\n}\n\n// TODO: dispatch events after append/replace so we can apply page state\nexport const render = (strategy, content) => {\n if (strategy && content) {\n if (strategy.match(/^Append$/i)) return append(content)\n if (strategy.match(/^Replace$/i)) return replace(content)\n }\n}\n\nexport default { render }\n", "import headers from './headers'\nimport { render } from './renderer'\n\nconst frameSources = {}\n\n// fires after receiving a turbo HTTP response\naddEventListener('turbo:before-fetch-response', event => {\n const frame = event.target.closest('turbo-frame')\n if (frame?.id && frame?.src) frameSources[frame.id] = frame.src\n\n const { fetchResponse: response } = event.detail\n const header = response.header(headers.RESPONSE_HEADER)\n\n if (!header) return\n\n // We'll take it from here Hotwire...\n event.preventDefault()\n const { strategy } = headers.tokenize(header)\n response.responseHTML.then(content => render(strategy, content))\n})\n\n// fires when a frame element is navigated and finishes loading\naddEventListener('turbo:frame-load', event => {\n const frame = event.target.closest('turbo-frame')\n frame.dataset.src = frameSources[frame.id] || frame.src || frame.dataset.src\n delete frameSources[frame.id]\n})\n", "const schema = {\n // attributes\n frameAttribute: 'data-turbo-frame',\n methodAttribute: 'data-turbo-method',\n commandAttribute: 'data-turbo-command',\n confirmAttribute: 'data-turbo-confirm',\n stateAttributesAttribute: 'data-turbo-boost-state-attributes'\n}\n\nexport default { ...schema }\n", "export const commandEvents = {\n start: 'turbo-boost:command:start',\n success: 'turbo-boost:command:success',\n finish: 'turbo-boost:command:finish',\n abort: 'turbo-boost:command:abort',\n clientError: 'turbo-boost:command:client-error',\n serverError: 'turbo-boost:command:server-error'\n}\n\nexport const stateEvents = {\n stateChange: 'turbo-boost:state:change',\n stateInitialize: 'turbo-boost:state:initialize'\n}\n\nexport const turboEvents = {\n frameLoad: 'turbo:frame-load',\n load: 'turbo:load'\n}\n\nexport function dispatch(name, target, options = {}) {\n return new Promise(resolve => {\n options = options || {}\n options.detail = options.detail || {}\n target = target || document\n const evt = new CustomEvent(name, { ...options, bubbles: true })\n target.dispatchEvent(evt)\n resolve(evt)\n })\n}\n", "const active = {}\n\nfunction add(payload) {\n active[payload.id] = payload\n}\n\nfunction remove(id) {\n delete active[id]\n}\n\nexport default {\n add,\n remove,\n get commands() {\n return [...Object.values(active)]\n },\n get length() {\n return Object.keys(active).length\n }\n}\n", "import { commandEvents } from './events'\nimport schema from './schema'\n\nconst confirmation = {\n method: message => Promise.resolve(confirm(message))\n}\n\nconst isTurboMethod = event => event.detail.driver === 'method'\n\nconst isTurboForm = event => {\n if (event.detail.driver !== 'form') return false\n\n const element = event.target\n const frame = element.closest('turbo-frame')\n const target = element.closest(`[${schema.frameAttribute}]`)\n return !!(frame || target)\n}\n\nconst shouldDelegate = event => isTurboMethod(event) || isTurboForm(event)\n\ndocument.addEventListener(commandEvents.start, async event => {\n const message = event.target.getAttribute(schema.confirmAttribute)\n if (!message) return\n\n event.detail.confirmation = true\n\n if (shouldDelegate(event)) return // delegate confirmation handling to Turbo\n\n const proceed = await confirmation.method(message)\n if (!proceed) event.preventDefault()\n})\n\nexport default confirmation\n", "let events = []\nlet eventListener\n\nfunction register(eventName, selectors) {\n const match = events.find(evt => evt.name === eventName)\n if (match) events.splice(events.indexOf(match), 1)\n events = [{ name: eventName, selectors }, ...events]\n\n document.removeEventListener(eventName, eventListener, true)\n document.addEventListener(eventName, eventListener, true)\n\n return { ...events.find(evt => evt.name === eventName) }\n}\n\nfunction getRegisteredEventForElement(element) {\n return events.find(evt =>\n evt.selectors.find(selector => Array.from(document.querySelectorAll(selector)).find(el => el === element))\n )\n}\n\nfunction isRegisteredForElement(eventName, element) {\n const evt = getRegisteredEventForElement(element)\n return evt && evt.name === eventName\n}\n\nexport default {\n register,\n isRegisteredForElement,\n get events() {\n return [...events]\n },\n set handler(fn) {\n eventListener = fn\n }\n}\n", "import schema from './schema'\n\nfunction findClosestCommand(element) {\n return element.closest(`[${schema.commandAttribute}]`)\n}\n\nfunction findClosestFrameWithSource(element) {\n return (\n element.closest('turbo-frame[src]') ||\n element.closest('turbo-frame[data-turbo-frame-src]') ||\n element.closest('turbo-frame')\n )\n}\n\nfunction assignElementValueToPayload(element, payload = {}) {\n if (element.tagName.toLowerCase() !== 'select') return (payload.value = element.value || null)\n\n if (!element.multiple) return (payload.value = element.options[element.selectedIndex].value)\n\n payload.values = Array.from(element.options).reduce((memo, option) => {\n if (option.selected) memo.push(option.value)\n return memo\n }, [])\n}\n\nfunction buildAttributePayload(element) {\n const payload = Array.from(element.attributes).reduce((memo, attr) => {\n let value = attr.value\n memo[attr.name] = value\n return memo\n }, {})\n\n payload.tag = element.tagName\n payload.checked = !!element.checked\n payload.disabled = !!element.disabled\n assignElementValueToPayload(element, payload)\n\n // reduce payload size to keep URL length smaller\n delete payload.class\n delete payload.action\n delete payload.href\n delete payload[schema.commandAttribute]\n delete payload[schema.frameAttribute]\n\n return payload\n}\n\nexport default {\n buildAttributePayload,\n findClosestCommand,\n findClosestFrameWithSource\n}\n", "const invokeCommand = (form, payload = {}) => {\n const input = form.querySelector('input[name=\"turbo_boost_command\"]') || document.createElement('input')\n input.type = 'hidden'\n input.name = 'turbo_boost_command'\n input.value = JSON.stringify(payload)\n if (!form.contains(input)) form.appendChild(input)\n}\n\nexport default { invokeCommand }\n", "import activity from './activity'\nimport { dispatch, commandEvents } from './events'\n\nfunction finish(event) {\n setTimeout(() => dispatch(commandEvents.finish, event.target, { detail: event.detail }))\n}\n\nconst events = [commandEvents.abort, commandEvents.serverError, commandEvents.success]\nevents.forEach(name => addEventListener(name, finish))\naddEventListener(commandEvents.finish, event => activity.remove(event.detail.id), true)\n\nexport default { events: commandEvents }\n", "const buildURL = path => {\n const a = document.createElement('a')\n a.href = path\n return new URL(a)\n}\n\nexport default {\n get commandInvocationURL() {\n return buildURL('/turbo-boost-command-invocation')\n }\n}\n", "import headers from './headers'\nimport lifecycle from './lifecycle'\nimport urls from './urls'\nimport { dispatch } from './events'\nimport { render } from './renderer'\n\nconst parseError = error => {\n const message = `Unexpected error performing a TurboBoost Command! ${error.message}`\n dispatch(lifecycle.events.clientError, document, { detail: { message, error } }, true)\n}\n\nconst parseAndRenderResponse = response => {\n const { strategy } = headers.tokenize(response.headers.get(headers.RESPONSE_HEADER))\n response.text().then(content => render(strategy, content))\n}\n\nconst invoke = (payload = {}) => {\n try {\n fetch(urls.commandInvocationURL.href, {\n method: 'POST',\n headers: headers.prepare({}),\n body: JSON.stringify(payload)\n })\n .then(parseAndRenderResponse)\n .catch(parseError)\n } catch (error) {\n parseError(error)\n }\n}\n\nexport { invoke }\n", "import { invoke } from '../invoker'\n\nconst invokeCommand = (_, payload) => invoke(payload)\n\nexport default { invokeCommand }\n", "let activeElement\nlet activePayload\n\nconst reset = () => {\n activeElement = null\n activePayload = null\n}\n\nconst invokeCommand = (element, payload = {}) => {\n activeElement = element\n activePayload = payload\n}\n\nconst amendForm = form => {\n try {\n if (!activeElement) return\n if (form.getAttribute('method') !== activeElement.dataset.turboMethod) return\n if (form.getAttribute('action') !== activeElement.href) return\n\n const input = form.querySelector('input[name=\"turbo_boost_command\"]') || document.createElement('input')\n input.type = 'hidden'\n input.name = 'turbo_boost_command'\n input.value = JSON.stringify(activePayload)\n if (!form.contains(input)) form.appendChild(input)\n } finally {\n reset() // ensure reset\n }\n}\n\ndocument.addEventListener('submit', event => amendForm(event.target), true)\n\nexport default { invokeCommand }\n", "import { invoke } from '../invoker'\n\nconst invokeCommand = (_, payload = {}) => invoke(payload)\n\nexport default { invokeCommand }\n", "import elements from '../elements'\nimport formDriver from './form'\nimport frameDriver from './frame'\nimport methodDriver from './method'\nimport windowDriver from './window'\n\nfunction src(element, frame) {\n frame = frame || { dataset: {} }\n return element.href || frame.src || frame.dataset.src || location.href\n}\n\nfunction find(element) {\n let frame = elements.findClosestFrameWithSource(element)\n\n const { turboFrame, turboMethod } = element.dataset\n\n if (element.tagName.toLowerCase() === 'form')\n return {\n name: 'form',\n reason: 'Element is a form.',\n frame,\n src: element.action,\n invokeCommand: formDriver.invokeCommand\n }\n\n if (turboMethod?.length)\n return {\n name: 'method',\n reason: 'Element defines data-turbo-method.',\n frame,\n src: element.href,\n invokeCommand: methodDriver.invokeCommand\n }\n\n // element targets a frame that is not _self\n if (turboFrame && turboFrame !== '_self') {\n frame = document.getElementById(turboFrame)\n return {\n name: 'frame',\n reason: 'element targets a frame that is not _self',\n frame,\n src: src(element, frame),\n invokeCommand: frameDriver.invokeCommand\n }\n }\n\n // element does NOT target a frame or targets _self and is contained by a frame\n if ((!turboFrame || turboFrame === '_self') && frame)\n return {\n name: 'frame',\n reason: 'element does NOT target a frame or targets _self and is contained by a frame',\n frame,\n src: src(element, frame),\n invokeCommand: frameDriver.invokeCommand\n }\n\n // element matches one or more of the following conditions\n // - targets _top\n // - does NOT target a frame\n // - is NOT contained by a frame\n return {\n name: 'window',\n reason:\n 'element matches one or more of the following conditions (targets _top, does NOT target a frame, is NOT contained by a frame)',\n frame: null,\n src: src(element),\n invokeCommand: windowDriver.invokeCommand\n }\n}\n\nexport default { find }\n", "// TODO: Move Logger to its own library (i.e. TurboBoost.Logger)\nimport { commandEvents as events } from './events'\n\nlet currentLevel = 'unknown'\nlet initialized = false\nlet history = []\n\nconst logLevels = {\n debug: Object.values(events),\n info: Object.values(events),\n warn: [events.abort, events.clientError, events.serverError],\n error: [events.clientError, events.serverError],\n unknown: []\n}\n\nconst shouldLogEvent = event => {\n if (!logLevels[currentLevel].includes(event.type)) return false\n if (typeof console[currentLevel] !== 'function') return false\n\n const { detail } = event\n if (!detail.id) return true\n\n const key = `${event.type}-${detail.id}`\n if (history.includes(key)) return false\n\n if (history.length > 16) history.shift()\n history.push(key)\n\n return true\n}\n\nconst logMethod = event => {\n if (logLevels.error.includes(event.type)) return 'error'\n if (logLevels.warn.includes(event.type)) return 'warn'\n if (logLevels.info.includes(event.type)) return 'info'\n if (logLevels.debug.includes(event.type)) return 'debug'\n return 'log'\n}\n\nconst logEvent = event => {\n if (shouldLogEvent(event)) {\n const { target, type, detail } = event\n const id = detail.id || ''\n const commandName = detail.name || ''\n\n let duration = ''\n if (detail.startedAt) duration = `${Date.now() - detail.startedAt}ms `\n\n const typeParts = type.split(':')\n const lastPart = typeParts.pop()\n const eventName = `%c${typeParts.join(':')}:%c${lastPart}`\n const message = [`%c${commandName}`, `%c${duration}`, eventName]\n\n console[logMethod(event)](\n message.join(' ').replace(/\\s{2,}/g, ' '),\n 'color:deepskyblue',\n 'color:lime',\n 'color:darkgray',\n eventName.match(/abort|error/i) ? 'color:red' : 'color:deepskyblue',\n { id, detail, target }\n )\n }\n}\n\nif (!initialized) {\n initialized = true\n Object.values(events).forEach(name => addEventListener(name, event => logEvent(event)))\n}\n\nexport default {\n get level() {\n return currentLevel\n },\n set level(value) {\n if (!Object.keys(logLevels).includes(value)) value = 'unknown'\n return (currentLevel = value)\n }\n}\n", "import { dispatch, stateEvents as events } from '../events'\n\nlet head\n\nfunction observable(object, parent = null) {\n if (!object || typeof object !== 'object') return object\n\n const proxy = new Proxy(object, {\n deleteProperty(target, key) {\n delete target[key]\n dispatch(events.stateChange, document, { detail: { state: head } })\n return true\n },\n\n set(target, key, value, _receiver) {\n target[key] = observable(value, this)\n dispatch(events.stateChange, document, { detail: { state: head } })\n return true\n }\n })\n\n if (Array.isArray(object)) {\n object.forEach((value, index) => (object[index] = observable(value, proxy)))\n } else if (typeof object === 'object') {\n for (const [key, value] of Object.entries(object)) object[key] = observable(value, proxy)\n }\n\n if (!parent) head = proxy\n return proxy\n}\n\nexport default observable\n", "import schema from '../schema.js'\n\nconst updateElement = (id, attribute, value, attempts = 1) => {\n if (attempts > 20) return\n const element = document.getElementById(id)\n if (element?.isConnected) return element.setAttribute(attribute, value)\n setTimeout(() => updateElement(id, attribute, value, attempts + 1), attempts * 5)\n}\n\nconst buildState = () => {\n const elements = Array.from(document.querySelectorAll(`[id][${schema.stateAttributesAttribute}]`))\n return elements.reduce((memo, element) => {\n const attributes = JSON.parse(element.getAttribute(schema.stateAttributesAttribute))\n if (element.id) {\n const stateAttributes = attributes.reduce((acc, name) => {\n if (element.hasAttribute(name)) acc[name] = element.getAttribute(name) || name\n return acc\n }, {})\n if (Object.values(stateAttributes).length) memo[element.id] = stateAttributes\n }\n return memo\n }, {})\n}\n\nconst restoreState = (state = {}) => {\n for (const [id, attributes] of Object.entries(state)) {\n for (const [attribute, value] of Object.entries(attributes)) updateElement(id, attribute, value)\n }\n}\n\nexport default {\n buildState,\n restoreState\n}\n", "function save(name, value) {\n if (typeof value !== 'object') value = {}\n return localStorage.setItem(String(name), JSON.stringify(value))\n}\n\nfunction find(name) {\n const stored = localStorage.getItem(String(name))\n return stored ? JSON.parse(stored) : {}\n}\n\nexport default { save, find }\n", "// TODO: Move State to its own library\nimport observable from './observable'\nimport page from './page'\nimport storage from './storage'\nimport { dispatch, stateEvents } from '../events'\n\nconst key = 'TurboBoost::State'\nconst stub = { pages: {}, signed: null, unsigned: {} }\n\nlet signed = null // signed state \nlet unsigned = {} // unsigned state (optimistic)