turbo_boost-commands 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of turbo_boost-commands might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c57a8dd2bb434b411ec32bbe64d1f498738c99fc68d91c041db9114eba061ca7
4
- data.tar.gz: 510cc6f5ac6888822481e25ba9818817d4871c9b72f240c0b10b41da975cefd4
3
+ metadata.gz: d6ce5aabbfcc72bb2794ad5bb0ce5a15f1e26520db26cddf7e3c87af7b8a2c17
4
+ data.tar.gz: 454ec89f229218b01e9c2eb8a4defa88abc573c221358de94965aba110e9582e
5
5
  SHA512:
6
- metadata.gz: 952eeacf8ac98cb10c4c35751a1c3aae39a80bb5ba8888e5e7a6a023bf2f4932e68c91eabaee58580308fc1014d1c06bd6b87555b64e74058fabe45652ecf1be
7
- data.tar.gz: 7dd109d16bb50386169a22a758090a4cf0ba44325d7a79c06bc49bb0af1060f03455f6cc976593cfebec4a003728dd379185819ec1397d4d7d3f0660608f1183
6
+ metadata.gz: 530e465c9cc43777b8bc50f4fe6a13b6cf97a4cb0745646137ec6139b3c6a72431e330954beabe74362a87d52973daf05c1961106f8f22046e9945e0d2763b06
7
+ data.tar.gz: 2f2d7c2cb5d5954531e91c75977e0afc6dd2e750d7532dfbd1dc496d5b3caf06c259dbff3ad26caab41876ff4130130db8126b337c58cbed4e3d263d80477cd0
@@ -1,2 +1,2 @@
1
- var Q=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var X=(e,t,r)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,s=(e,t)=>{for(var r in t||(t={}))ee.call(t,r)&&X(e,r,t[r]);if(I)for(var r of I(t))te.call(t,r)&&X(e,r,t[r]);return e},c=(e,t)=>Y(e,Z(t));var d={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"},f={stateLoad:"turbo-boost:state:load",stateChange:"turbo-boost:state:change"},u=s(s({},d),f);function a(e,t,r={}){return new Promise(o=>{r=r||{},r.detail=r.detail||{},t=t||document;let n=new CustomEvent(e,c(s({},r),{bubbles:!0}));t.dispatchEvent(n),o(n)})}var L;function C(e,t=null){if(!e||typeof e!="object")return e;let r=new Proxy(e,{deleteProperty(o,n){return delete o[n],a(f.stateChange,document,{detail:{state:L}}),!0},set(o,n,i,b){return o[n]=C(i,this),a(f.stateChange,document,{detail:{state:L}}),!0}});if(Array.isArray(e))e.forEach((o,n)=>e[n]=C(o,r));else if(typeof e=="object")for(let[o,n]of Object.entries(e))e[o]=C(n,r);return t||(L=r),r}var _=C;var S,A,O,q;function re(e,t){let r=JSON.parse(e);S=s({},r),q=t,A=_(r),O={},setTimeout(()=>a(f.stateLoad,document,{detail:{state:A}}))}addEventListener(f.stateChange,e=>{for(let[t,r]of Object.entries(A))S[t]!==r&&(O[t]=r)});var y={initialize:re,events:f,get initial(){return S},get current(){return A},get changed(){return O},get signed(){return q}};function oe(e){let t="<html",r="</html",o=e.indexOf(t),n=e.lastIndexOf(r);if(o>=0&&n>=0){let i=e.slice(e.indexOf(">",o)+1,n);document.documentElement.innerHTML=i}}function ne(e){document.body.insertAdjacentHTML("beforeend",e)}var h={append:ne,replaceDocument:oe};var T={};function se(e){T[e.id]=e}function ae(e){delete T[e]}var k={add:se,remove:ae,get commands(){return[...Object.values(T)]},get length(){return Object.keys(T).length}};function F(e){e.detail.endedAt=Date.now(),e.detail.milliseconds=e.detail.endedAt-e.detail.startedAt,setTimeout(()=>a(d.finish,e.target,{detail:e.detail}),25)}addEventListener(d.serverError,F);addEventListener(d.success,F);addEventListener(d.finish,e=>k.remove(e.detail.id),!0);var g={events:d};var B={};addEventListener("turbo:before-fetch-request",e=>{var o,n;let t=e.target.closest("turbo-frame"),{fetchOptions:r}=e.detail;if((n=(o=self.TurboBoost)==null?void 0:o.Commands)!=null&&n.busy){let i=["text/vnd.turbo-boost.html",r.headers.Accept];i=i.filter(b=>b&&b.trim().length>0).join(", "),r.headers.Accept=i}});addEventListener("turbo:before-fetch-response",e=>{let t=e.target.closest("turbo-frame"),{fetchResponse:r}=e.detail;if(t&&(B[t.id]=t.src),r.header("TurboBoost")){if(r.statusCode<200||r.statusCode>399){let o=`Server returned a ${r.statusCode} status code! TurboBoost Commands require 2XX-3XX status codes.`;a(g.events.clientError,document,{detail:c(s({},e.detail),{error:o})},!0)}r.header("TurboBoost")==="Append"&&(e.preventDefault(),r.responseText.then(o=>h.append(o)))}});addEventListener("turbo:frame-load",e=>{let t=e.target.closest("turbo-frame");t.dataset.turboBoostSrc=B[t.id]||t.src||t.dataset.turboBoostSrc,delete B[t.id]});var ie={frameAttribute:"data-turbo-frame",methodAttribute:"data-turbo-method",commandAttribute:"data-turbo-command",confirmAttribute:"data-turbo-confirm"},m=s({},ie);var N={method:e=>Promise.resolve(confirm(e))},de=e=>e.detail.driver==="method",me=e=>{if(e.detail.driver!=="form")return!1;let t=e.target,r=t.closest("turbo-frame"),o=t.closest(`[${m.frameAttribute}]`);return!!(r||o)},ce=e=>de(e)||me(e);document.addEventListener(d.start,async e=>{let t=e.target.getAttribute(m.confirmAttribute);if(!t||(e.detail.confirmation=!0,ce(e)))return;await N.method(t)||e.preventDefault()});var M=N;var l=[],D;function ue(e,t){let r=l.find(o=>o.name===e);return r&&l.splice(l.indexOf(r),1),l=[{name:e,selectors:t},...l],document.removeEventListener(e,D,!0),document.addEventListener(e,D,!0),s({},l.find(o=>o.name===e))}function fe(e){return l.find(t=>t.selectors.find(r=>Array.from(document.querySelectorAll(r)).find(o=>o===e)))}function le(e,t){let r=fe(t);return r&&r.name===e}var p={register:ue,isRegisteredForElement:le,get events(){return[...l]},set handler(e){D=e}};function pe(e){return e.closest(`[${m.commandAttribute}]`)}function be(e){return e.closest("turbo-frame[src]")||e.closest("turbo-frame[data-turbo-frame-src]")||e.closest("turbo-frame")}function he(e,t={}){if(e.tagName.toLowerCase()!=="select")return t.value=e.value||null;if(!e.multiple)return t.value=e.options[e.selectedIndex].value;t.values=Array.from(e.options).reduce((r,o)=>(o.selected&&r.push(o.value),r),[])}function ve(e){let t=Array.from(e.attributes).reduce((r,o)=>{let n=o.value;return r[o.name]=n,r},{});return t.tag=e.tagName,t.checked=!!e.checked,t.disabled=!!e.disabled,he(e,t),delete t.class,delete t.action,delete t.href,delete t[m.commandAttribute],delete t[m.frameAttribute],t}var E={buildAttributePayload:ve,findClosestCommand:pe,findClosestFrameWithSource:be};function ge(e,t={},r={}){let o=e.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");o.type="hidden",o.name="turbo_boost_command",o.value=JSON.stringify(t),e.appendChild(o)}var j={invokeCommand:ge};function Ee(e,t={}){let r=document.createElement("a");r.href=e;let o=new URL(r);return o.searchParams.set("tbc",JSON.stringify(t)),o}var v={build:Ee};function xe(e,t){let r=t.src;t=s({},t),delete t.src,e.src=v.build(r,t)}var R={invokeCommand:xe};function Ce(e,t={}){let r=t.src;t=s({},t),delete t.src,delete t.href,e.setAttribute("href",v.build(r,t))}var W={invokeCommand:Ce};function Ae(e){let t=e.target;a(g.events.abort,document,{detail:c(s({},e.detail),{xhr:t})})}function P(e){let t=e.target;(t.getResponseHeader("TurboBoost")==="Append"||t.getResponseHeader("Content-Type").startsWith("text/vnd.turbo-boost.html"))&&h.append(t.responseText);let o=`Server returned a ${t.status} status code! TurboBoost Commands require 2XX-3XX status codes.`;a(g.events.clientError,document,{detail:c(s({},e.detail),{error:o,xhr:t})},!0)}function ye(e){let t=e.target;if(t.status<200||t.status>399)return P(e);let r=t.responseText;t.getResponseHeader("TurboBoost")==="Append"||t.getResponseHeader("Content-Type").startsWith("text/vnd.turbo-boost.html")?h.append(t.responseText):h.replaceDocument(t.responseText)}function Te(e){let t=e.src;e=s({},e),delete e.src;try{let r=new XMLHttpRequest;r.open("GET",v.build(t,e),!0),r.setRequestHeader("Accept","text/vnd.turbo-boost.html, text/html, application/xhtml+xml"),r.addEventListener("abort",Ae),r.addEventListener("error",P),r.addEventListener("load",ye),r.send()}catch(r){let o=`Unexpected error sending HTTP request! ${r.message}`;P(r,{detail:{message:o}})}}var J={invokeCommand:Te};function $(e,t){return t=t||{dataset:{}},e.href||t.src||t.dataset.turboBoostSrc||location.href}function ke(e){let t=E.findClosestFrameWithSource(e),{turboFrame:r,turboMethod:o}=e.dataset;return e.tagName.toLowerCase()==="form"?{name:"form",reason:"Element is a form.",frame:t,src:e.action,invokeCommand:j.invokeCommand}:o&&o.length>0?{name:"method",reason:"Element defines data-turbo-method.",frame:t,src:e.href,invokeCommand:W.invokeCommand}:r&&r!=="_self"?(t=document.getElementById(r),{name:"frame",reason:"element targets a frame that is not _self",frame:t,src:$(e,t),invokeCommand:R.invokeCommand}):(!r||r==="_self")&&t?{name:"frame",reason:"element does NOT target a frame or targets _self and is contained by a frame",frame:t,src:$(e,t),invokeCommand:R.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:$(e),invokeCommand:J.invokeCommand}}var H={find:ke};var w="unknown",U={debug:Object.values(u),info:Object.values(u),warn:[u.abort,u.clientError,u.serverError],error:[u.clientError,u.serverError],unknown:[]};Object.values(u).forEach(e=>{addEventListener(e,t=>{if(U[w].includes(t.type)){let{target:r,detail:o}=t;console[w](t.type,{target:r,detail:o})}})});var V={get level(){return w},set level(e){return Object.keys(U).includes(e)||(e="unknown"),w=e}};function we(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))}var z={v4:we};var G="0.1.3";var Le=self.TurboBoost||{},x={VERSION:G,busy:!1,confirmation:M,logger:V,schema:m,events:d,registerEventDelegate:p.register,get eventDelegates(){return p.events}};function K(e,t){return{id:e,name:t.getAttribute(m.commandAttribute),elementId:t.id.length>0?t.id:null,elementAttributes:E.buildAttributePayload(t),startedAt:Date.now(),token:x.token,signedState:y.signed,clientState:y.changed}}async function Se(e){let t,r={};try{if(t=E.findClosestCommand(e.target),!t||!p.isRegisteredForElement(e.type,t))return;let o=`turbo-command-${z.v4()}`,n=H.find(t),i=c(s({},K(o,t)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),b=await a(d.start,t,{cancelable:!0,detail:i});if(b.defaultPrevented||b.detail.confirmation&&e.defaultPrevented)return a(d.abort,t,{detail:{message:`An event handler for '${d.start}' prevented default behavior and blocked command invocation!`,source:b}});switch(n=H.find(t),i=c(s({},K(o,t)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),k.add(i),["frame","window"].includes(n.name)&&e.preventDefault(),x.busy=!0,setTimeout(()=>x.busy=!1,10),n.name){case"method":return n.invokeCommand(t,i);case"form":return n.invokeCommand(t,i,e);case"frame":return n.invokeCommand(n.frame,i);case"window":return n.invokeCommand(i)}}catch(o){a(d.clientError,t,{detail:c(s({},r),{error:o})})}}self.TurboBoost=s({},Le);self.TurboBoost.Commands||(p.handler=Se,p.register("click",[`[${m.commandAttribute}]`]),p.register("submit",[`form[${m.commandAttribute}]`]),p.register("change",[`input[${m.commandAttribute}]`,`select[${m.commandAttribute}]`,`textarea[${m.commandAttribute}]`]),self.TurboBoost.Commands=x,self.TurboBoost.State=y);var Gt=x;export{Gt as default};
1
+ var rt=Object.defineProperty,ot=Object.defineProperties;var nt=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var at=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var X=(t,e,r)=>e in t?rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e)=>{for(var r in e||(e={}))at.call(e,r)&&X(t,r,e[r]);if(N)for(var r of N(e))st.call(e,r)&&X(t,r,e[r]);return t},v=(t,e)=>ot(t,nt(e));var it="TurboBoost-Command",h={boost:"text/vnd.turbo-boost.html",stream:"text/vnd.turbo-stream.html",html:"text/html",xhtml:"application/xhtml+xml",json:"application/json"},dt=(t={})=>{t=a({},t);let e=(t.Accept||"").split(",").map(r=>r.trim()).filter(r=>r.length);return e.unshift(h.boost,h.stream,h.html,h.xhtml),t.Accept=[...new Set(e)].join(", "),t["Content-Type"]=h.json,t["X-Requested-With"]="XMLHttpRequest",t},mt=t=>{if(t){let[e,r,o]=t.split(", ");return{status:e,strategy:r,name:o}}return{}},b={prepare:dt,tokenize:mt,RESPONSE_HEADER:it};var A={};function ct(t){A[t.id]=t}function ut(t){delete A[t]}var x={add:ct,remove:ut,get commands(){return[...Object.values(A)]},get length(){return Object.keys(A).length}};var i={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"},l={stateLoad:"turbo-boost:state:load",stateChange:"turbo-boost:state:change"},c=a(a({},i),l);function s(t,e,r={}){return new Promise(o=>{r=r||{},r.detail=r.detail||{},e=e||document;let n=new CustomEvent(t,v(a({},r),{bubbles:!0}));e.dispatchEvent(n),o(n)})}function F(t){t.detail.endedAt=Date.now(),t.detail.milliseconds=t.detail.endedAt-t.detail.startedAt,setTimeout(()=>s(i.finish,t.target,{detail:t.detail}),25)}addEventListener(i.serverError,F);addEventListener(i.success,F);addEventListener(i.finish,t=>x.remove(t.detail.id),!0);var g={events:i};var lt=t=>{document.body.insertAdjacentHTML("beforeend",t)},ft=t=>{let r=new DOMParser().parseFromString(t,"text/html");document.head.innerHTML=r.head.innerHTML,document.body.innerHTML=r.body.innerHTML},k=(t,e)=>{if(t.match(/^Append$/i))return lt(e);if(t.match(/^Replace$/i))return ft(e)};var O={};addEventListener("turbo:before-fetch-response",t=>{let e=t.target.closest("turbo-frame");e!=null&&e.id&&(e!=null&&e.src)&&(O[e.id]=e.src);let{fetchResponse:r}=t.detail,o=r.header(b.RESPONSE_HEADER);if(!o)return;t.preventDefault();let{statusCode:n}=r,{strategy:m}=b.tokenize(o);if(n<200||n>399){let u=`Server returned a ${status} status code! TurboBoost Commands require 2XX-3XX status codes.`;s(g.events.clientError,document,{detail:{error:u,response:r}},!0)}r.responseHTML.then(u=>k(m,u))});addEventListener("turbo:frame-load",t=>{let e=t.target.closest("turbo-frame");e.dataset.src=O[e.id]||e.src||e.dataset.src,delete O[e.id]});var pt={frameAttribute:"data-turbo-frame",methodAttribute:"data-turbo-method",commandAttribute:"data-turbo-command",confirmAttribute:"data-turbo-confirm"},d=a({},pt);var I={method:t=>Promise.resolve(confirm(t))},bt=t=>t.detail.driver==="method",vt=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)},ht=t=>bt(t)||vt(t);document.addEventListener(i.start,async t=>{let e=t.target.getAttribute(d.confirmAttribute);if(!e||(t.detail.confirmation=!0,ht(t)))return;await I.method(e)||t.preventDefault()});var j=I;var f=[],R;function gt(t,e){let r=f.find(o=>o.name===t);return r&&f.splice(f.indexOf(r),1),f=[{name:t,selectors:e},...f],document.removeEventListener(t,R,!0),document.addEventListener(t,R,!0),a({},f.find(o=>o.name===t))}function Et(t){return f.find(e=>e.selectors.find(r=>Array.from(document.querySelectorAll(r)).find(o=>o===t)))}function yt(t,e){let r=Et(e);return r&&r.name===t}var p={register:gt,isRegisteredForElement:yt,get events(){return[...f]},set handler(t){R=t}};function Ct(t){return t.closest(`[${d.commandAttribute}]`)}function At(t){return t.closest("turbo-frame[src]")||t.closest("turbo-frame[data-turbo-frame-src]")||t.closest("turbo-frame")}function xt(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 kt(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,xt(t,e),delete e.class,delete e.action,delete e.href,delete e[d.commandAttribute],delete e[d.frameAttribute],e}var E={buildAttributePayload:kt,findClosestCommand:Ct,findClosestFrameWithSource:At};var St=(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)},q={invokeCommand:St};var _;function S(t,e=null){if(!t||typeof t!="object")return t;let r=new Proxy(t,{deleteProperty(o,n){return delete o[n],s(l.stateChange,document,{detail:{state:_}}),!0},set(o,n,m,u){return o[n]=S(m,this),s(l.stateChange,document,{detail:{state:_}}),!0}});if(Array.isArray(t))t.forEach((o,n)=>t[n]=S(o,r));else if(typeof t=="object")for(let[o,n]of Object.entries(t))t[o]=S(n,r);return e||(_=r),r}var U=S;var D,L,P,z;function Lt(t,e){let r=JSON.parse(t);D=a({},r),z=e,L=U(r),P={},setTimeout(()=>s(l.stateLoad,document,{detail:{state:L}}))}addEventListener(l.stateChange,t=>{for(let[e,r]of Object.entries(L))D[e]!==r&&(P[e]=r)});var y={initialize:Lt,events:l,get initial(){return D},get current(){return L},get changed(){return P},get signed(){return z}};var wt=t=>{let e=document.createElement("a");return e.href=t,new URL(e)},J={get commandInvocationURL(){return wt("/turbo-boost-command-invocation")}};var V=t=>{let e=`Unexpected error performing a TurboBoost Command! ${t.message}`;s(g.events.clientError,document,{detail:{error:e}},!0)},Tt=t=>{let{strategy:e}=b.tokenize(t.headers.get(b.RESPONSE_HEADER));if(t.status<200||t.status>399){let r=`Server returned a ${t.status} status code! TurboBoost Commands require 2XX-3XX status codes.`;s(g.events.serverError,document,{detail:{error:r,response:t}},!0)}t.text().then(r=>k(e,r))},w=(t={})=>{try{fetch(J.commandInvocationURL.href,{method:"POST",headers:b.prepare({}),body:JSON.stringify(t)}).then(Tt).catch(V)}catch(e){V(e)}};var Ot=(t,e)=>w(e),$={invokeCommand:Ot};var C,M,Rt=()=>{C=null,M=null},_t=(t,e={})=>{C=t,M=e},Dt=t=>{try{if(!C||t.getAttribute("method")!==C.dataset.turboMethod||t.getAttribute("action")!==C.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(M),t.contains(e)||t.appendChild(e)}finally{Rt()}};document.addEventListener("submit",t=>Dt(t.target),!0);var W={invokeCommand:_t};var Pt=(t,e={})=>w(e),G={invokeCommand:Pt};function B(t,e){return e=e||{dataset:{}},t.href||e.src||e.dataset.src||location.href}function $t(t){let e=E.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:q.invokeCommand}:o&&o.length>0?{name:"method",reason:"Element defines data-turbo-method.",frame:e,src:t.href,invokeCommand:W.invokeCommand}:r&&r!=="_self"?(e=document.getElementById(r),{name:"frame",reason:"element targets a frame that is not _self",frame:e,src:B(t,e),invokeCommand:$.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:B(t,e),invokeCommand:$.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:B(t),invokeCommand:G.invokeCommand}}var H={find:$t};var T="unknown",K={debug:Object.values(c),info:Object.values(c),warn:[c.abort,c.clientError,c.serverError],error:[c.clientError,c.serverError],unknown:[]};Object.values(c).forEach(t=>{addEventListener(t,e=>{if(K[T].includes(e.type)){let{target:r,detail:o}=e;console[T](e.type,{target:r,detail:o})}})});var Q={get level(){return T},set level(t){return Object.keys(K).includes(t)||(t="unknown"),T=t}};function Mt(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}var Y={v4:Mt};var Z="0.2.0";var Bt=self.TurboBoost||{},et={VERSION:Z,active:!1,confirmation:j,logger:Q,schema:d,events:i,registerEventDelegate:p.register,get eventDelegates(){return p.events}};function tt(t,e){return{id:t,name:e.getAttribute(d.commandAttribute),elementId:e.id.length>0?e.id:null,elementAttributes:E.buildAttributePayload(e),startedAt:Date.now(),changedState:y.changed,clientState:y.current,signedState:y.signed}}async function Ht(t){let e,r={};try{if(e=E.findClosestCommand(t.target),!e||!p.isRegisteredForElement(t.type,e))return;let o=`turbo-command-${Y.v4()}`,n=H.find(e),m=v(a({},tt(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),u=await s(i.start,e,{cancelable:!0,detail:m});if(u.defaultPrevented||u.detail.confirmation&&t.defaultPrevented)return s(i.abort,e,{detail:{message:`An event handler for '${i.start}' prevented default behavior and blocked command invocation!`,source:u}});switch(n=H.find(e),m=v(a({},tt(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),x.add(m),["frame","window"].includes(n.name)&&t.preventDefault(),n.name){case"method":return n.invokeCommand(e,m);case"form":return n.invokeCommand(e,m,t);case"frame":return n.invokeCommand(n.frame,m);case"window":return n.invokeCommand(self,m)}}catch(o){s(i.clientError,e,{detail:v(a({},r),{error:o})})}}self.TurboBoost=a({},Bt);self.TurboBoost.Commands||(p.handler=Ht,p.register("click",[`[${d.commandAttribute}]`]),p.register("submit",[`form[${d.commandAttribute}]`]),p.register("change",[`input[${d.commandAttribute}]`,`select[${d.commandAttribute}]`,`textarea[${d.commandAttribute}]`]),self.TurboBoost.Commands=et,self.TurboBoost.State=y);var er=et;export{er as default};
2
2
  //# sourceMappingURL=commands.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../javascript/events.js", "../../../javascript/state/observable.js", "../../../javascript/state/index.js", "../../../javascript/renderer.js", "../../../javascript/activity.js", "../../../javascript/lifecycle.js", "../../../javascript/turbo.js", "../../../javascript/schema.js", "../../../javascript/confirmation.js", "../../../javascript/delegates.js", "../../../javascript/elements.js", "../../../javascript/drivers/form.js", "../../../javascript/urls.js", "../../../javascript/drivers/frame.js", "../../../javascript/drivers/method.js", "../../../javascript/drivers/window.js", "../../../javascript/drivers/index.js", "../../../javascript/logger.js", "../../../javascript/uuids.js", "../../../javascript/version.js", "../../../javascript/index.js"],
4
- "sourcesContent": ["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 stateLoad: 'turbo-boost:state:load',\n stateChange: 'turbo-boost:state:change'\n}\n\nexport const allEvents = { ...commandEvents, ...stateEvents }\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", "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", "// TODO: Consider moving State to its own library\nimport observable from './observable'\nimport { dispatch, commandEvents, stateEvents } from '../events'\n\nlet initialState, currentState, changedState, signedState\n\nfunction initialize(initial, signed) {\n const json = JSON.parse(initial)\n initialState = { ...json }\n signedState = signed\n currentState = observable(json)\n changedState = {}\n setTimeout(() =>\n dispatch(stateEvents.stateLoad, document, {\n detail: { state: currentState }\n })\n )\n}\n\naddEventListener(stateEvents.stateChange, event => {\n for (const [key, value] of Object.entries(currentState))\n if (initialState[key] !== value) changedState[key] = value\n})\n\nexport default {\n initialize,\n events: stateEvents,\n\n get initial() {\n return initialState\n },\n\n get current() {\n return currentState\n },\n\n get changed() {\n return changedState\n },\n\n get signed() {\n return signedState\n }\n}\n", "function replaceDocument(content) {\n const head = '<html'\n const tail = '</html'\n const headIndex = content.indexOf(head)\n const tailIndex = content.lastIndexOf(tail)\n if (headIndex >= 0 && tailIndex >= 0) {\n const html = content.slice(content.indexOf('>', headIndex) + 1, tailIndex)\n document.documentElement.innerHTML = html\n }\n}\n\nfunction append(content) {\n document.body.insertAdjacentHTML('beforeend', content)\n}\n\nexport default { append, replaceDocument }\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 activity from './activity'\nimport { dispatch, commandEvents } from './events'\n\nfunction finish(event) {\n event.detail.endedAt = Date.now()\n event.detail.milliseconds = event.detail.endedAt - event.detail.startedAt\n setTimeout(() => dispatch(commandEvents.finish, event.target, { detail: event.detail }), 25)\n}\n\n// TODO: forward source event to finish (error or success)\naddEventListener(commandEvents.serverError, finish)\naddEventListener(commandEvents.success, finish)\naddEventListener(commandEvents.finish, event => activity.remove(event.detail.id), true)\n\nexport default { events: commandEvents }\n", "import state from './state'\nimport renderer from './renderer'\nimport { dispatch } from './events'\nimport lifecycle from './lifecycle'\n\nconst frameSources = {}\n\n// fires before making a turbo HTTP request\naddEventListener('turbo:before-fetch-request', event => {\n const frame = event.target.closest('turbo-frame')\n const { fetchOptions } = event.detail\n\n // command invoked and busy\n if (self.TurboBoost?.Commands?.busy) {\n let acceptHeaders = ['text/vnd.turbo-boost.html', fetchOptions.headers['Accept']]\n acceptHeaders = acceptHeaders.filter(entry => entry && entry.trim().length > 0).join(', ')\n fetchOptions.headers['Accept'] = acceptHeaders\n }\n})\n\n// fires after receiving a turbo HTTP response\naddEventListener('turbo:before-fetch-response', event => {\n const frame = event.target.closest('turbo-frame')\n const { fetchResponse: response } = event.detail\n\n if (frame) frameSources[frame.id] = frame.src\n\n if (response.header('TurboBoost')) {\n if (response.statusCode < 200 || response.statusCode > 399) {\n const error = `Server returned a ${response.statusCode} status code! TurboBoost Commands require 2XX-3XX status codes.`\n dispatch(lifecycle.events.clientError, document, { detail: { ...event.detail, error } }, true)\n }\n\n if (response.header('TurboBoost') === 'Append') {\n event.preventDefault()\n response.responseText.then(content => renderer.append(content))\n }\n }\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.turboBoostSrc = frameSources[frame.id] || frame.src || frame.dataset.turboBoostSrc\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}\n\nexport default { ...schema }\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'\nimport lifecycle from './lifecycle'\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", "function invokeCommand(form, payload = {}, event = {}) {\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 form.appendChild(input)\n}\n\nexport default { invokeCommand }\n", "function build(urlString, payload = {}) {\n const a = document.createElement('a')\n a.href = urlString\n const url = new URL(a)\n url.searchParams.set('tbc', JSON.stringify(payload))\n return url\n}\n\nexport default { build }\n", "import urls from '../urls'\n\nfunction invokeCommand(frame, payload) {\n const src = payload.src\n payload = { ...payload }\n delete payload.src\n frame.src = urls.build(src, payload)\n}\n\nexport default { invokeCommand }\n", "import urls from '../urls'\n\nfunction invokeCommand(element, payload = {}) {\n const src = payload.src\n payload = { ...payload }\n delete payload.src\n delete payload.href\n element.setAttribute('href', urls.build(src, payload))\n}\n\nexport default { invokeCommand }\n", "import state from '../state'\nimport { dispatch } from '../events'\nimport lifecycle from '../lifecycle'\nimport urls from '../urls'\nimport renderer from '../renderer'\n\nfunction aborted(event) {\n const xhr = event.target\n dispatch(lifecycle.events.abort, document, {\n detail: { ...event.detail, xhr }\n })\n}\n\nfunction errored(event) {\n const xhr = event.target\n\n const append =\n xhr.getResponseHeader('TurboBoost') === 'Append' ||\n xhr.getResponseHeader('Content-Type').startsWith('text/vnd.turbo-boost.html')\n\n if (append) renderer.append(xhr.responseText)\n\n const error = `Server returned a ${xhr.status} status code! TurboBoost Commands require 2XX-3XX status codes.`\n\n dispatch(lifecycle.events.clientError, document, { detail: { ...event.detail, error, xhr } }, true)\n}\n\nfunction loaded(event) {\n const xhr = event.target\n if (xhr.status < 200 || xhr.status > 399) return errored(event)\n const content = xhr.responseText\n const append =\n xhr.getResponseHeader('TurboBoost') === 'Append' ||\n xhr.getResponseHeader('Content-Type').startsWith('text/vnd.turbo-boost.html')\n append ? renderer.append(xhr.responseText) : renderer.replaceDocument(xhr.responseText)\n}\n\nfunction invokeCommand(payload) {\n const src = payload.src\n payload = { ...payload }\n delete payload.src\n\n try {\n const xhr = new XMLHttpRequest()\n xhr.open('GET', urls.build(src, payload), true)\n xhr.setRequestHeader('Accept', 'text/vnd.turbo-boost.html, text/html, application/xhtml+xml')\n xhr.addEventListener('abort', aborted)\n xhr.addEventListener('error', errored)\n xhr.addEventListener('load', loaded)\n xhr.send()\n } catch (ex) {\n const message = `Unexpected error sending HTTP request! ${ex.message}`\n errored(ex, { detail: { message } })\n }\n}\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.turboBoostSrc || 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 && turboMethod.length > 0)\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", "import { allEvents as events } from './events'\n\nlet currentLevel = 'unknown'\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\nObject.values(events).forEach(name => {\n addEventListener(name, event => {\n if (logLevels[currentLevel].includes(event.type)) {\n const { target, detail } = event\n console[currentLevel](event.type, { target, detail })\n }\n })\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", "function v4() {\n return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>\n (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)\n )\n}\n\nexport default { v4 }\n", "export default '0.1.3'\n", "import './turbo'\nimport schema from './schema'\nimport { dispatch, commandEvents } from './events'\nimport activity from './activity'\nimport confirmation from './confirmation'\nimport delegates from './delegates'\nimport drivers from './drivers'\nimport elements from './elements'\nimport lifecycle from './lifecycle'\nimport logger from './logger'\nimport state from './state'\nimport urls from './urls'\nimport uuids from './uuids'\nimport VERSION from './version'\n\nconst TurboBoost = self.TurboBoost || {}\n\nconst Commands = {\n VERSION,\n busy: false,\n confirmation,\n logger,\n schema,\n events: commandEvents,\n registerEventDelegate: delegates.register,\n get eventDelegates() {\n return delegates.events\n }\n}\n\nfunction buildCommandPayload(id, element) {\n return {\n id, // uniquely identifies the command\n name: element.getAttribute(schema.commandAttribute),\n elementId: element.id.length > 0 ? element.id : null,\n elementAttributes: elements.buildAttributePayload(element),\n startedAt: Date.now(),\n token: Commands.token, // command token (used for CSRF protection)\n signedState: state.signed, // server side state\n clientState: state.changed // client side state (delta of optimistic updates)\n }\n}\n\nasync function invokeCommand(event) {\n let element\n let payload = {}\n\n try {\n element = elements.findClosestCommand(event.target)\n if (!element) return\n if (!delegates.isRegisteredForElement(event.type, element)) return\n\n const commandId = `turbo-command-${uuids.v4()}`\n let driver = drivers.find(element)\n let payload = {\n ...buildCommandPayload(commandId, element),\n driver: driver.name,\n frameId: driver.frame ? driver.frame.id : null,\n src: driver.src\n }\n\n const startEvent = await dispatch(commandEvents.start, element, {\n cancelable: true,\n detail: payload\n })\n\n if (startEvent.defaultPrevented || (startEvent.detail.confirmation && event.defaultPrevented))\n return dispatch(commandEvents.abort, element, {\n detail: {\n message: `An event handler for '${commandEvents.start}' prevented default behavior and blocked command invocation!`,\n source: startEvent\n }\n })\n\n // the element and thus the driver may have changed based on the start event handler(s)\n driver = drivers.find(element)\n payload = {\n ...buildCommandPayload(commandId, element),\n driver: driver.name,\n frameId: driver.frame ? driver.frame.id : null,\n src: driver.src\n }\n\n activity.add(payload)\n\n if (['frame', 'window'].includes(driver.name)) event.preventDefault()\n\n Commands.busy = true\n setTimeout(() => (Commands.busy = false), 10)\n\n switch (driver.name) {\n case 'method':\n return driver.invokeCommand(element, payload)\n case 'form':\n return driver.invokeCommand(element, payload, event)\n case 'frame':\n return driver.invokeCommand(driver.frame, payload)\n case 'window':\n return driver.invokeCommand(payload)\n }\n } catch (error) {\n dispatch(commandEvents.clientError, element, {\n detail: { ...payload, error }\n })\n }\n}\n\nself.TurboBoost = { ...TurboBoost }\n\nif (!self.TurboBoost.Commands) {\n // wire things up and setup defaults for event delegation\n delegates.handler = invokeCommand\n delegates.register('click', [`[${schema.commandAttribute}]`])\n delegates.register('submit', [`form[${schema.commandAttribute}]`])\n delegates.register('change', [\n `input[${schema.commandAttribute}]`,\n `select[${schema.commandAttribute}]`,\n `textarea[${schema.commandAttribute}]`\n ])\n\n self.TurboBoost.Commands = Commands\n self.TurboBoost.State = state\n}\n\nexport default Commands\n"],
5
- "mappings": "ibAAO,IAAMA,EAAgB,CAC3B,MAAO,4BACP,QAAS,8BACT,OAAQ,6BACR,MAAO,4BACP,YAAa,mCACb,YAAa,kCACf,EAEaC,EAAc,CACzB,UAAW,yBACX,YAAa,0BACf,EAEaC,EAAYC,IAAA,GAAKH,GAAkBC,GAEzC,SAASG,EAASC,EAAMC,EAAQC,EAAU,CAAC,EAAG,CACnD,OAAO,IAAI,Q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AAO,MAAM,GAAK,KAC1C,IAAKA,EAAO,GACd,GAEAM,EAAS,IAAIT,CAAO,EAEhB,CAAC,QAAS,QAAQ,EAAE,SAASG,EAAO,IAAI,GAAGJ,EAAM,eAAe,EAEpEb,EAAS,KAAO,GAChB,WAAW,IAAOA,EAAS,KAAO,GAAQ,EAAE,EAEpCiB,EAAO,KAAM,CACnB,IAAK,SACH,OAAOA,EAAO,cAAcR,EAASK,CAAO,EAC9C,IAAK,OACH,OAAOG,EAAO,cAAcR,EAASK,EAASD,CAAK,EACrD,IAAK,QACH,OAAOI,EAAO,cAAcA,EAAO,MAAOH,CAAO,EACnD,IAAK,SACH,OAAOG,EAAO,cAAcH,CAAO,CACvC,CACF,OAASU,EAAO,CACdF,EAASjB,EAAc,YAAaI,EAAS,CAC3C,OAAQU,EAAAC,EAAA,GAAKN,GAAL,CAAc,MAAAU,CAAM,EAC9B,CAAC,CACH,CACF,CAEA,KAAK,WAAaJ,EAAA,GAAKrB,IAElB,KAAK,WAAW,WAEnBO,EAAU,QAAUM,GACpBN,EAAU,SAAS,QAAS,CAAC,IAAIF,EAAO,gBAAgB,GAAG,CAAC,EAC5DE,EAAU,SAAS,SAAU,CAAC,QAAQF,EAAO,gBAAgB,GAAG,CAAC,EACjEE,EAAU,SAAS,SAAU,CAC3B,SAASF,EAAO,gBAAgB,IAChC,UAAUA,EAAO,gBAAgB,IACjC,YAAYA,EAAO,gBAAgB,GACrC,CAAC,EAED,KAAK,WAAW,SAAWJ,EAC3B,KAAK,WAAW,MAAQW,GAG1B,IAAOc,GAAQzB",
6
- "names": ["commandEvents", "stateEvents", "allEvents", "__spreadValues", "dispatch", "name", "target", "options", "resolve", "evt", "__spreadProps", "head", "observable", "object", "parent", "proxy", "target", "key", "dispatch", "stateEvents", "value", "receiver", "index", "observable_default", "initialState", "currentState", "changedState", "signedState", "initialize", "initial", "signed", "json", "__spreadValues", "observable_default", "dispatch", "stateEvents", "event", "key", "value", "state_default", "replaceDocument", "content", "head", "tail", "headIndex", "tailIndex", "html", "append", "renderer_default", "active", "add", "payload", "remove", "id", "activity_default", "finish", "event", "dispatch", "commandEvents", "activity_default", "lifecycle_default", "frameSources", "event", "_a", "_b", "frame", "fetchOptions", "acceptHeaders", "entry", "response", "error", "dispatch", "lifecycle_default", "__spreadProps", "__spreadValues", "content", "renderer_default", "schema", "schema_default", "__spreadValues", "confirmation", "message", "isTurboMethod", "event", "isTurboForm", "element", "frame", "target", "schema_default", "shouldDelegate", "commandEvents", "confirmation_default", "events", "eventListener", "register", "eventName", "selectors", "match", "evt", "__spreadValues", "getRegisteredEventForElement", "element", "selector", "el", "isRegisteredForElement", "delegates_default", "fn", "findClosestCommand", "element", "schema_default", "findClosestFrameWithSource", "assignElementValueToPayload", "payload", "memo", "option", "buildAttributePayload", "attr", "value", "elements_default", "invokeCommand", "form", "payload", "event", "input", "form_default", "build", "urlString", "payload", "a", "url", "urls_default", "invokeCommand", "frame", "payload", "src", "__spreadValues", "urls_default", "frame_default", "invokeCommand", "element", "payload", "src", "__spreadValues", "urls_default", "method_default", "aborted", "event", "xhr", "dispatch", "lifecycle_default", "__spreadProps", "__spreadValues", "errored", "renderer_default", "error", "loaded", "content", "invokeCommand", "payload", "src", "urls_default", "ex", "message", "window_default", "src", "element", "frame", "find", "elements_default", "turboFrame", "turboMethod", "form_default", "method_default", "frame_default", "window_default", "drivers_default", "currentLevel", "logLevels", "allEvents", "name", "event", "target", "detail", "logger_default", "value", "v4", "c", "uuids_default", "version_default", "TurboBoost", "Commands", "version_default", "confirmation_default", "logger_default", "schema_default", "commandEvents", "delegates_default", "buildCommandPayload", "id", "element", "elements_default", "state_default", "invokeCommand", "event", "payload", "commandId", "uuids_default", "driver", "drivers_default", "__spreadProps", "__spreadValues", "startEvent", "dispatch", "activity_default", "error", "javascript_default"]
3
+ "sources": ["../../../javascript/headers.js", "../../../javascript/activity.js", "../../../javascript/events.js", "../../../javascript/lifecycle.js", "../../../javascript/renderer.js", "../../../javascript/turbo.js", "../../../javascript/schema.js", "../../../javascript/confirmation.js", "../../../javascript/delegates.js", "../../../javascript/elements.js", "../../../javascript/drivers/form.js", "../../../javascript/state/observable.js", "../../../javascript/state/index.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/uuids.js", "../../../javascript/version.js", "../../../javascript/index.js"],
4
+ "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 [status, strategy, name] = value.split(', ')\n return { status, strategy, name }\n }\n\n return {}\n}\n\nexport default { prepare, tokenize, RESPONSE_HEADER }\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", "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 stateLoad: 'turbo-boost:state:load',\n stateChange: 'turbo-boost:state:change'\n}\n\nexport const allEvents = { ...commandEvents, ...stateEvents }\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", "import activity from './activity'\nimport { dispatch, commandEvents } from './events'\n\nfunction finish(event) {\n event.detail.endedAt = Date.now()\n event.detail.milliseconds = event.detail.endedAt - event.detail.startedAt\n setTimeout(() => dispatch(commandEvents.finish, event.target, { detail: event.detail }), 25)\n}\n\n// TODO: forward source event to finish (error or success)\naddEventListener(commandEvents.serverError, finish)\naddEventListener(commandEvents.success, finish)\naddEventListener(commandEvents.finish, event => activity.remove(event.detail.id), true)\n\nexport default { events: commandEvents }\n", "const append = content => {\n document.body.insertAdjacentHTML('beforeend', content)\n}\n\n// TODO: Revisit the \"Replace\" strategy after morph ships with Turbo 8\nconst replace = content => {\n const parser = new DOMParser()\n const doc = parser.parseFromString(content, 'text/html')\n document.head.innerHTML = doc.head.innerHTML\n document.body.innerHTML = doc.body.innerHTML\n}\n\nexport const render = (strategy, content) => {\n if (strategy.match(/^Append$/i)) return append(content)\n if (strategy.match(/^Replace$/i)) return replace(content)\n}\n\nexport default { render }\n", "import headers from './headers'\nimport lifecycle from './lifecycle'\nimport { dispatch } from './events'\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 { statusCode } = response\n const { strategy } = headers.tokenize(header)\n\n // FAIL: Status outside the range of 200-399\n if (statusCode < 200 || statusCode > 399) {\n const error = `Server returned a ${status} status code! TurboBoost Commands require 2XX-3XX status codes.`\n dispatch(lifecycle.events.clientError, document, { detail: { error, response } }, true)\n }\n\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}\n\nexport default { ...schema }\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'\nimport lifecycle from './lifecycle'\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 { 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", "// TODO: Consider moving State to its own library\nimport observable from './observable'\nimport { dispatch, commandEvents, stateEvents } from '../events'\n\nlet initialState, currentState, changedState, signedState\n\nfunction initialize(initial, signed) {\n const json = JSON.parse(initial)\n initialState = { ...json }\n signedState = signed\n currentState = observable(json)\n changedState = {}\n setTimeout(() =>\n dispatch(stateEvents.stateLoad, document, {\n detail: { state: currentState }\n })\n )\n}\n\naddEventListener(stateEvents.stateChange, event => {\n for (const [key, value] of Object.entries(currentState))\n if (initialState[key] !== value) changedState[key] = value\n})\n\nexport default {\n initialize,\n events: stateEvents,\n\n get initial() {\n return initialState\n },\n\n get current() {\n return currentState\n },\n\n get changed() {\n return changedState\n },\n\n get signed() {\n return signedState\n }\n}\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 state from './state'\nimport urls from './urls'\nimport { dispatch } from './events'\nimport { render } from './renderer'\n\nconst parseError = error => {\n const errorMessage = `Unexpected error performing a TurboBoost Command! ${error.message}`\n dispatch(lifecycle.events.clientError, document, { detail: { error: errorMessage } }, true)\n}\n\nconst parseAndRenderResponse = response => {\n const { strategy } = headers.tokenize(response.headers.get(headers.RESPONSE_HEADER))\n\n // FAIL: Status outside the range of 200-399\n if (response.status < 200 || response.status > 399) {\n const error = `Server returned a ${response.status} status code! TurboBoost Commands require 2XX-3XX status codes.`\n dispatch(lifecycle.events.serverError, document, { detail: { error, response } }, true)\n }\n\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 && turboMethod.length > 0)\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", "import { allEvents as events } from './events'\n\nlet currentLevel = 'unknown'\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\nObject.values(events).forEach(name => {\n addEventListener(name, event => {\n if (logLevels[currentLevel].includes(event.type)) {\n const { target, detail } = event\n console[currentLevel](event.type, { target, detail })\n }\n })\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", "function v4() {\n return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>\n (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)\n )\n}\n\nexport default { v4 }\n", "export default '0.2.0'\n", "import './turbo'\nimport schema from './schema'\nimport { dispatch, commandEvents } from './events'\nimport activity from './activity'\nimport confirmation from './confirmation'\nimport delegates from './delegates'\nimport drivers from './drivers'\nimport elements from './elements'\nimport lifecycle from './lifecycle'\nimport logger from './logger'\nimport state from './state'\nimport uuids from './uuids'\nimport VERSION from './version'\n\nconst TurboBoost = self.TurboBoost || {}\n\nconst Commands = {\n VERSION,\n active: false,\n confirmation,\n logger,\n schema,\n events: commandEvents,\n registerEventDelegate: delegates.register,\n get eventDelegates() {\n return delegates.events\n }\n}\n\nfunction buildCommandPayload(id, element) {\n return {\n id, // uniquely identifies the command\n name: element.getAttribute(schema.commandAttribute),\n elementId: element.id.length > 0 ? element.id : null,\n elementAttributes: elements.buildAttributePayload(element),\n startedAt: Date.now(),\n changedState: state.changed, // changed-state (delta of optimistic updates)\n clientState: state.current, // client-side state\n signedState: state.signed // server-side state\n }\n}\n\nasync function invokeCommand(event) {\n let element\n let payload = {}\n\n try {\n element = elements.findClosestCommand(event.target)\n if (!element) return\n if (!delegates.isRegisteredForElement(event.type, element)) return\n\n const commandId = `turbo-command-${uuids.v4()}`\n let driver = drivers.find(element)\n let payload = {\n ...buildCommandPayload(commandId, element),\n driver: driver.name,\n frameId: driver.frame ? driver.frame.id : null,\n src: driver.src\n }\n\n const startEvent = await dispatch(commandEvents.start, element, {\n cancelable: true,\n detail: payload\n })\n\n if (startEvent.defaultPrevented || (startEvent.detail.confirmation && event.defaultPrevented))\n return dispatch(commandEvents.abort, element, {\n detail: {\n message: `An event handler for '${commandEvents.start}' prevented default behavior and blocked command invocation!`,\n source: startEvent\n }\n })\n\n // the element and thus the driver may have changed based on the start event handler(s)\n driver = drivers.find(element)\n payload = {\n ...buildCommandPayload(commandId, element),\n driver: driver.name,\n frameId: driver.frame ? driver.frame.id : null,\n src: driver.src\n }\n\n activity.add(payload)\n\n if (['frame', 'window'].includes(driver.name)) event.preventDefault()\n\n switch (driver.name) {\n case 'method':\n return driver.invokeCommand(element, payload)\n case 'form':\n return driver.invokeCommand(element, payload, event)\n case 'frame':\n return driver.invokeCommand(driver.frame, payload)\n case 'window':\n return driver.invokeCommand(self, payload)\n }\n } catch (error) {\n dispatch(commandEvents.clientError, element, {\n detail: { ...payload, error }\n })\n }\n}\n\nself.TurboBoost = { ...TurboBoost }\n\nif (!self.TurboBoost.Commands) {\n // wire things up and setup defaults for event delegation\n delegates.handler = invokeCommand\n delegates.register('click', [`[${schema.commandAttribute}]`])\n delegates.register('submit', [`form[${schema.commandAttribute}]`])\n delegates.register('change', [\n `input[${schema.commandAttribute}]`,\n `select[${schema.commandAttribute}]`,\n `textarea[${schema.commandAttribute}]`\n ])\n\n self.TurboBoost.Commands = Commands\n self.TurboBoost.State = state\n}\n\nexport default Commands\n"],
5
+ "mappings": "ubAAA,IAAMA,GAAkB,qBAElBC,EAAQ,CACZ,MAAO,4BACP,OAAQ,6BACR,KAAM,YACN,MAAO,wBACP,KAAM,kBACR,EAGMC,GAAU,CAACC,EAAU,CAAC,IAAM,CAChCA,EAAUC,EAAA,GAAKD,GAGf,IAAME,GAAWF,EAAQ,QAAa,IACnC,MAAM,GAAG,EACT,IAAIG,GAAOA,EAAI,KAAK,CAAC,EACrB,OAAOA,GAAOA,EAAI,MAAM,EAE3B,OAAAD,EAAQ,QAAQJ,EAAM,MAAOA,EAAM,OAAQA,EAAM,KAAMA,EAAM,KAAK,EAClEE,EAAQ,OAAY,CAAC,GAAG,IAAI,IAAIE,CAAO,CAAC,EAAE,KAAK,IAAI,EAGnDF,EAAQ,cAAc,EAAIF,EAAM,KAGhCE,EAAQ,kBAAkB,EAAI,iBAEvBA,CACT,EAGMI,GAAWC,GAAS,CACxB,GAAIA,EAAO,CACT,GAAM,CAACC,EAAQC,EAAUC,CAAI,EAAIH,EAAM,MAAM,IAAI,EACjD,MAAO,CAAE,OAAAC,EAAQ,SAAAC,EAAU,KAAAC,CAAK,CAClC,CAEA,MAAO,CAAC,CACV,EAEOC,EAAQ,CAAE,QAAAV,GAAS,SAAAK,GAAU,gBAAAP,EAAgB,EC1CpD,IAAMa,EAAS,CAAC,EAEhB,SAASC,GAAIC,EAAS,CACpBF,EAAOE,EAAQ,EAAE,EAAIA,CACvB,CAEA,SAASC,GAAOC,EAAI,CAClB,OAAOJ,EAAOI,CAAE,CAClB,CAEA,IAAOC,EAAQ,CACb,IAAAJ,GACA,OAAAE,GACA,IAAI,UAAW,CACb,MAAO,CAAC,GAAG,OAAO,OAAOH,CAAM,CAAC,C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QAAUM,GACpBN,EAAU,SAAS,QAAS,CAAC,IAAIF,EAAO,gBAAgB,GAAG,CAAC,EAC5DE,EAAU,SAAS,SAAU,CAAC,QAAQF,EAAO,gBAAgB,GAAG,CAAC,EACjEE,EAAU,SAAS,SAAU,CAC3B,SAASF,EAAO,gBAAgB,IAChC,UAAUA,EAAO,gBAAgB,IACjC,YAAYA,EAAO,gBAAgB,GACrC,CAAC,EAED,KAAK,WAAW,SAAWJ,GAC3B,KAAK,WAAW,MAAQW,GAG1B,IAAOc,GAAQzB",
6
+ "names": ["RESPONSE_HEADER", "types", "prepare", "headers", "__spreadValues", "accepts", "val", "tokenize", "value", "status", "strategy", "name", "headers_default", "active", "add", "payload", "remove", "id", "activity_default", "commandEvents", "stateEvents", "allEvents", "__spreadValues", "dispatch", "name", "target", "options", "resolve", "evt", "__spreadProps", "finish", "event", "dispatch", "commandEvents", "activity_default", "lifecycle_default", "append", "content", "replace", "doc", "render", "strategy", "frameSources", "event", "frame", "response", "header", "headers_default", "statusCode", "strategy", "error", "dispatch", "lifecycle_default", "content", "render", "schema", "schema_default", "__spreadValues", "confirmation", "message", "isTurboMethod", "event", "isTurboForm", "element", "frame", "target", "schema_default", "shouldDelegate", "commandEvents", "confirmation_default", "events", "eventListener", "register", "eventName", "selectors", "match", "evt", "__spreadValues", "getRegisteredEventForElement", "element", "selector", "el", "isRegisteredForElement", "delegates_default", "fn", "findClosestCommand", "element", "schema_default", "findClosestFrameWithSource", "assignElementValueToPayload", "payload", "memo", "option", "buildAttributePayload", "attr", "value", "elements_default", "invokeCommand", "form", "payload", "input", "form_default", "head", "observable", "object", "parent", "proxy", "target", "key", "dispatch", "stateEvents", "value", "receiver", "index", "observable_default", "initialState", "currentState", "changedState", "signedState", "initialize", "initial", "signed", "json", "__spreadValues", "observable_default", "dispatch", "stateEvents", "event", "key", "value", "state_default", "buildURL", "path", "a", "urls_default", "parseError", "error", "errorMessage", "dispatch", "lifecycle_default", "parseAndRenderResponse", "response", "strategy", "headers_default", "content", "render", "invoke", "payload", "urls_default", "invokeCommand", "_", "payload", "invoke", "frame_default", "activeElement", "activePayload", "reset", "invokeCommand", "element", "payload", "amendForm", "form", "input", "event", "method_default", "invokeCommand", "_", "payload", "invoke", "window_default", "src", "element", "frame", "find", "elements_default", "turboFrame", "turboMethod", "form_default", "method_default", "frame_default", "window_default", "drivers_default", "currentLevel", "logLevels", "allEvents", "name", "event", "target", "detail", "logger_default", "value", "v4", "c", "uuids_default", "version_default", "TurboBoost", "Commands", "version_default", "confirmation_default", "logger_default", "schema_default", "commandEvents", "delegates_default", "buildCommandPayload", "id", "element", "elements_default", "state_default", "invokeCommand", "event", "payload", "commandId", "uuids_default", "driver", "drivers_default", "__spreadProps", "__spreadValues", "startEvent", "dispatch", "activity_default", "error", "javascript_default"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"app/javascript/events.js":{"bytes":783,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/state/observable.js":{"bytes":885,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"}],"format":"esm"},"app/javascript/state/index.js":{"bytes":936,"imports":[{"path":"app/javascript/state/observable.js","kind":"import-statement","original":"./observable"},{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/renderer.js":{"bytes":475,"imports":[],"format":"esm"},"app/javascript/activity.js":{"bytes":279,"imports":[],"format":"esm"},"app/javascript/lifecycle.js":{"bytes":610,"imports":[{"path":"app/javascript/activity.js","kind":"import-statement","original":"./activity"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"}],"format":"esm"},"app/javascript/turbo.js":{"bytes":1729,"imports":[{"path":"app/javascript/state/index.js","kind":"import-statement","original":"./state"},{"path":"app/javascript/renderer.js","kind":"import-statement","original":"./renderer"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/schema.js":{"bytes":226,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/confirmation.js":{"bytes":947,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"}],"format":"esm"},"app/javascript/delegates.js":{"bytes":923,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/elements.js":{"bytes":1451,"imports":[{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"}],"format":"esm"},"app/javascript/drivers/form.js":{"bytes":327,"imports":[],"format":"esm"},"app/javascript/urls.js":{"bytes":224,"imports":[],"format":"esm"},"app/javascript/drivers/frame.js":{"bytes":218,"imports":[{"path":"app/javascript/urls.js","kind":"import-statement","original":"../urls"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/drivers/method.js":{"bytes":265,"imports":[{"path":"app/javascript/urls.js","kind":"import-statement","original":"../urls"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/drivers/window.js":{"bytes":1809,"imports":[{"path":"app/javascript/state/index.js","kind":"import-statement","original":"../state"},{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"../lifecycle"},{"path":"app/javascript/urls.js","kind":"import-statement","original":"../urls"},{"path":"app/javascript/renderer.js","kind":"import-statement","original":"../renderer"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/drivers/index.js":{"bytes":2044,"imports":[{"path":"app/javascript/elements.js","kind":"import-statement","original":"../elements"},{"path":"app/javascript/drivers/form.js","kind":"import-statement","original":"./form"},{"path":"app/javascript/drivers/frame.js","kind":"import-statement","original":"./frame"},{"path":"app/javascript/drivers/method.js","kind":"import-statement","original":"./method"},{"path":"app/javascript/drivers/window.js","kind":"import-statement","original":"./window"}],"format":"esm"},"app/javascript/logger.js":{"bytes":729,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"}],"format":"esm"},"app/javascript/uuids.js":{"bytes":202,"imports":[],"format":"esm"},"app/javascript/version.js":{"bytes":23,"imports":[],"format":"esm"},"app/javascript/index.js":{"bytes":3697,"imports":[{"path":"app/javascript/turbo.js","kind":"import-statement","original":"./turbo"},{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/activity.js","kind":"import-statement","original":"./activity"},{"path":"app/javascript/confirmation.js","kind":"import-statement","original":"./confirmation"},{"path":"app/javascript/delegates.js","kind":"import-statement","original":"./delegates"},{"path":"app/javascript/drivers/index.js","kind":"import-statement","original":"./drivers"},{"path":"app/javascript/elements.js","kind":"import-statement","original":"./elements"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"},{"path":"app/javascript/logger.js","kind":"import-statement","original":"./logger"},{"path":"app/javascript/state/index.js","kind":"import-statement","original":"./state"},{"path":"app/javascript/urls.js","kind":"import-statement","original":"./urls"},{"path":"app/javascript/uuids.js","kind":"import-statement","original":"./uuids"},{"path":"app/javascript/version.js","kind":"import-statement","original":"./version"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"app/assets/builds/@turbo-boost/commands.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":34791},"app/assets/builds/@turbo-boost/commands.js":{"imports":[],"exports":["default"],"entryPoint":"app/javascript/index.js","inputs":{"app/javascript/events.js":{"bytesInOutput":500},"app/javascript/state/observable.js":{"bytesInOutput":403},"app/javascript/state/index.js":{"bytesInOutput":349},"app/javascript/renderer.js":{"bytesInOutput":263},"app/javascript/activity.js":{"bytesInOutput":173},"app/javascript/lifecycle.js":{"bytesInOutput":294},"app/javascript/turbo.js":{"bytesInOutput":952},"app/javascript/schema.js":{"bytesInOutput":166},"app/javascript/confirmation.js":{"bytesInOutput":424},"app/javascript/delegates.js":{"bytesInOutput":473},"app/javascript/elements.js":{"bytesInOutput":782},"app/javascript/drivers/form.js":{"bytesInOutput":230},"app/javascript/urls.js":{"bytesInOutput":150},"app/javascript/drivers/frame.js":{"bytesInOutput":96},"app/javascript/drivers/method.js":{"bytesInOutput":130},"app/javascript/drivers/window.js":{"bytesInOutput":1146},"app/javascript/drivers/index.js":{"bytesInOutput":991},"app/javascript/logger.js":{"bytesInOutput":399},"app/javascript/uuids.js":{"bytesInOutput":159},"app/javascript/version.js":{"bytesInOutput":14},"app/javascript/index.js":{"bytesInOutput":1662}},"bytes":10249}}}
1
+ {"inputs":{"app/javascript/headers.js":{"bytes":1116,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/activity.js":{"bytes":279,"imports":[],"format":"esm"},"app/javascript/events.js":{"bytes":783,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/lifecycle.js":{"bytes":610,"imports":[{"path":"app/javascript/activity.js","kind":"import-statement","original":"./activity"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"}],"format":"esm"},"app/javascript/renderer.js":{"bytes":571,"imports":[],"format":"esm"},"app/javascript/turbo.js":{"bytes":1322,"imports":[{"path":"app/javascript/headers.js","kind":"import-statement","original":"./headers"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/renderer.js","kind":"import-statement","original":"./renderer"}],"format":"esm"},"app/javascript/schema.js":{"bytes":226,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/confirmation.js":{"bytes":947,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"}],"format":"esm"},"app/javascript/delegates.js":{"bytes":923,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/elements.js":{"bytes":1451,"imports":[{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"}],"format":"esm"},"app/javascript/drivers/form.js":{"bytes":345,"imports":[],"format":"esm"},"app/javascript/state/observable.js":{"bytes":885,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"}],"format":"esm"},"app/javascript/state/index.js":{"bytes":936,"imports":[{"path":"app/javascript/state/observable.js","kind":"import-statement","original":"./observable"},{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/urls.js":{"bytes":215,"imports":[],"format":"esm"},"app/javascript/invoker.js":{"bytes":1247,"imports":[{"path":"app/javascript/headers.js","kind":"import-statement","original":"./headers"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"},{"path":"app/javascript/state/index.js","kind":"import-statement","original":"./state"},{"path":"app/javascript/urls.js","kind":"import-statement","original":"./urls"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/renderer.js","kind":"import-statement","original":"./renderer"}],"format":"esm"},"app/javascript/drivers/frame.js":{"bytes":125,"imports":[{"path":"app/javascript/invoker.js","kind":"import-statement","original":"../invoker"}],"format":"esm"},"app/javascript/drivers/method.js":{"bytes":867,"imports":[],"format":"esm"},"app/javascript/drivers/window.js":{"bytes":130,"imports":[{"path":"app/javascript/invoker.js","kind":"import-statement","original":"../invoker"}],"format":"esm"},"app/javascript/drivers/index.js":{"bytes":2034,"imports":[{"path":"app/javascript/elements.js","kind":"import-statement","original":"../elements"},{"path":"app/javascript/drivers/form.js","kind":"import-statement","original":"./form"},{"path":"app/javascript/drivers/frame.js","kind":"import-statement","original":"./frame"},{"path":"app/javascript/drivers/method.js","kind":"import-statement","original":"./method"},{"path":"app/javascript/drivers/window.js","kind":"import-statement","original":"./window"}],"format":"esm"},"app/javascript/logger.js":{"bytes":729,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"}],"format":"esm"},"app/javascript/uuids.js":{"bytes":202,"imports":[],"format":"esm"},"app/javascript/version.js":{"bytes":23,"imports":[],"format":"esm"},"app/javascript/index.js":{"bytes":3582,"imports":[{"path":"app/javascript/turbo.js","kind":"import-statement","original":"./turbo"},{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"},{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"},{"path":"app/javascript/activity.js","kind":"import-statement","original":"./activity"},{"path":"app/javascript/confirmation.js","kind":"import-statement","original":"./confirmation"},{"path":"app/javascript/delegates.js","kind":"import-statement","original":"./delegates"},{"path":"app/javascript/drivers/index.js","kind":"import-statement","original":"./drivers"},{"path":"app/javascript/elements.js","kind":"import-statement","original":"./elements"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"},{"path":"app/javascript/logger.js","kind":"import-statement","original":"./logger"},{"path":"app/javascript/state/index.js","kind":"import-statement","original":"./state"},{"path":"app/javascript/uuids.js","kind":"import-statement","original":"./uuids"},{"path":"app/javascript/version.js","kind":"import-statement","original":"./version"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"app/assets/builds/@turbo-boost/commands.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":35864},"app/assets/builds/@turbo-boost/commands.js":{"imports":[],"exports":["default"],"entryPoint":"app/javascript/index.js","inputs":{"app/javascript/headers.js":{"bytesInOutput":546},"app/javascript/activity.js":{"bytesInOutput":173},"app/javascript/events.js":{"bytesInOutput":500},"app/javascript/lifecycle.js":{"bytesInOutput":294},"app/javascript/renderer.js":{"bytesInOutput":289},"app/javascript/turbo.js":{"bytesInOutput":640},"app/javascript/schema.js":{"bytesInOutput":166},"app/javascript/confirmation.js":{"bytesInOutput":424},"app/javascript/delegates.js":{"bytesInOutput":473},"app/javascript/elements.js":{"bytesInOutput":782},"app/javascript/drivers/form.js":{"bytesInOutput":235},"app/javascript/state/observable.js":{"bytesInOutput":403},"app/javascript/state/index.js":{"bytesInOutput":349},"app/javascript/urls.js":{"bytesInOutput":150},"app/javascript/invoker.js":{"bytesInOutput":574},"app/javascript/drivers/frame.js":{"bytesInOutput":40},"app/javascript/drivers/method.js":{"bytesInOutput":453},"app/javascript/drivers/window.js":{"bytesInOutput":43},"app/javascript/drivers/index.js":{"bytesInOutput":981},"app/javascript/logger.js":{"bytesInOutput":399},"app/javascript/uuids.js":{"bytesInOutput":159},"app/javascript/version.js":{"bytesInOutput":14},"app/javascript/index.js":{"bytesInOutput":1645}},"bytes":10231}}}
@@ -3,12 +3,6 @@
3
3
  module TurboBoost::Commands::Controller
4
4
  extend ActiveSupport::Concern
5
5
 
6
- module ClassMethods
7
- def turbo_boost_state(&block)
8
- TurboBoost::Commands::State.assign_resolver(&block)
9
- end
10
- end
11
-
12
6
  included do
13
7
  before_action -> { turbo_boost.runner.run }
14
8
  after_action -> { turbo_boost.runner.update_response }
@@ -1,9 +1,9 @@
1
- function invokeCommand(form, payload = {}, event = {}) {
1
+ const invokeCommand = (form, payload = {}) => {
2
2
  const input = form.querySelector('input[name="turbo_boost_command"]') || document.createElement('input')
3
3
  input.type = 'hidden'
4
4
  input.name = 'turbo_boost_command'
5
5
  input.value = JSON.stringify(payload)
6
- form.appendChild(input)
6
+ if (!form.contains(input)) form.appendChild(input)
7
7
  }
8
8
 
9
9
  export default { invokeCommand }
@@ -1,10 +1,5 @@
1
- import urls from '../urls'
1
+ import { invoke } from '../invoker'
2
2
 
3
- function invokeCommand(frame, payload) {
4
- const src = payload.src
5
- payload = { ...payload }
6
- delete payload.src
7
- frame.src = urls.build(src, payload)
8
- }
3
+ const invokeCommand = (_, payload) => invoke(payload)
9
4
 
10
5
  export default { invokeCommand }
@@ -6,7 +6,7 @@ import windowDriver from './window'
6
6
 
7
7
  function src(element, frame) {
8
8
  frame = frame || { dataset: {} }
9
- return element.href || frame.src || frame.dataset.turboBoostSrc || location.href
9
+ return element.href || frame.src || frame.dataset.src || location.href
10
10
  }
11
11
 
12
12
  function find(element) {
@@ -1,11 +1,32 @@
1
- import urls from '../urls'
2
-
3
- function invokeCommand(element, payload = {}) {
4
- const src = payload.src
5
- payload = { ...payload }
6
- delete payload.src
7
- delete payload.href
8
- element.setAttribute('href', urls.build(src, payload))
1
+ let activeElement
2
+ let activePayload
3
+
4
+ const reset = () => {
5
+ activeElement = null
6
+ activePayload = null
7
+ }
8
+
9
+ const invokeCommand = (element, payload = {}) => {
10
+ activeElement = element
11
+ activePayload = payload
9
12
  }
10
13
 
14
+ const amendForm = form => {
15
+ try {
16
+ if (!activeElement) return
17
+ if (form.getAttribute('method') !== activeElement.dataset.turboMethod) return
18
+ if (form.getAttribute('action') !== activeElement.href) return
19
+
20
+ const input = form.querySelector('input[name="turbo_boost_command"]') || document.createElement('input')
21
+ input.type = 'hidden'
22
+ input.name = 'turbo_boost_command'
23
+ input.value = JSON.stringify(activePayload)
24
+ if (!form.contains(input)) form.appendChild(input)
25
+ } finally {
26
+ reset() // ensure reset
27
+ }
28
+ }
29
+
30
+ document.addEventListener('submit', event => amendForm(event.target), true)
31
+
11
32
  export default { invokeCommand }
@@ -1,57 +1,5 @@
1
- import state from '../state'
2
- import { dispatch } from '../events'
3
- import lifecycle from '../lifecycle'
4
- import urls from '../urls'
5
- import renderer from '../renderer'
1
+ import { invoke } from '../invoker'
6
2
 
7
- function aborted(event) {
8
- const xhr = event.target
9
- dispatch(lifecycle.events.abort, document, {
10
- detail: { ...event.detail, xhr }
11
- })
12
- }
13
-
14
- function errored(event) {
15
- const xhr = event.target
16
-
17
- const append =
18
- xhr.getResponseHeader('TurboBoost') === 'Append' ||
19
- xhr.getResponseHeader('Content-Type').startsWith('text/vnd.turbo-boost.html')
20
-
21
- if (append) renderer.append(xhr.responseText)
22
-
23
- const error = `Server returned a ${xhr.status} status code! TurboBoost Commands require 2XX-3XX status codes.`
24
-
25
- dispatch(lifecycle.events.clientError, document, { detail: { ...event.detail, error, xhr } }, true)
26
- }
27
-
28
- function loaded(event) {
29
- const xhr = event.target
30
- if (xhr.status < 200 || xhr.status > 399) return errored(event)
31
- const content = xhr.responseText
32
- const append =
33
- xhr.getResponseHeader('TurboBoost') === 'Append' ||
34
- xhr.getResponseHeader('Content-Type').startsWith('text/vnd.turbo-boost.html')
35
- append ? renderer.append(xhr.responseText) : renderer.replaceDocument(xhr.responseText)
36
- }
37
-
38
- function invokeCommand(payload) {
39
- const src = payload.src
40
- payload = { ...payload }
41
- delete payload.src
42
-
43
- try {
44
- const xhr = new XMLHttpRequest()
45
- xhr.open('GET', urls.build(src, payload), true)
46
- xhr.setRequestHeader('Accept', 'text/vnd.turbo-boost.html, text/html, application/xhtml+xml')
47
- xhr.addEventListener('abort', aborted)
48
- xhr.addEventListener('error', errored)
49
- xhr.addEventListener('load', loaded)
50
- xhr.send()
51
- } catch (ex) {
52
- const message = `Unexpected error sending HTTP request! ${ex.message}`
53
- errored(ex, { detail: { message } })
54
- }
55
- }
3
+ const invokeCommand = (_, payload = {}) => invoke(payload)
56
4
 
57
5
  export default { invokeCommand }
@@ -0,0 +1,43 @@
1
+ const RESPONSE_HEADER = 'TurboBoost-Command'
2
+
3
+ const types = {
4
+ boost: 'text/vnd.turbo-boost.html',
5
+ stream: 'text/vnd.turbo-stream.html',
6
+ html: 'text/html',
7
+ xhtml: 'application/xhtml+xml',
8
+ json: 'application/json'
9
+ }
10
+
11
+ // Prepares request headers for TurboBoost Command invocations
12
+ const prepare = (headers = {}) => {
13
+ headers = { ...headers }
14
+
15
+ // Assign Accept values
16
+ const accepts = (headers['Accept'] || '')
17
+ .split(',')
18
+ .map(val => val.trim())
19
+ .filter(val => val.length)
20
+
21
+ accepts.unshift(types.boost, types.stream, types.html, types.xhtml)
22
+ headers['Accept'] = [...new Set(accepts)].join(', ')
23
+
24
+ // Assign Content-Type (Commands POST JSON via fetch/XHR)
25
+ headers['Content-Type'] = types.json
26
+
27
+ // Assign X-Requested-With for XHR detection
28
+ headers['X-Requested-With'] = 'XMLHttpRequest'
29
+
30
+ return headers
31
+ }
32
+
33
+ // Tokenizes the 'TurboBoost-Command' HTTP response header value
34
+ const tokenize = value => {
35
+ if (value) {
36
+ const [status, strategy, name] = value.split(', ')
37
+ return { status, strategy, name }
38
+ }
39
+
40
+ return {}
41
+ }
42
+
43
+ export default { prepare, tokenize, RESPONSE_HEADER }
@@ -9,7 +9,6 @@ import elements from './elements'
9
9
  import lifecycle from './lifecycle'
10
10
  import logger from './logger'
11
11
  import state from './state'
12
- import urls from './urls'
13
12
  import uuids from './uuids'
14
13
  import VERSION from './version'
15
14
 
@@ -17,7 +16,7 @@ const TurboBoost = self.TurboBoost || {}
17
16
 
18
17
  const Commands = {
19
18
  VERSION,
20
- busy: false,
19
+ active: false,
21
20
  confirmation,
22
21
  logger,
23
22
  schema,
@@ -35,9 +34,9 @@ function buildCommandPayload(id, element) {
35
34
  elementId: element.id.length > 0 ? element.id : null,
36
35
  elementAttributes: elements.buildAttributePayload(element),
37
36
  startedAt: Date.now(),
38
- token: Commands.token, // command token (used for CSRF protection)
39
- signedState: state.signed, // server side state
40
- clientState: state.changed // client side state (delta of optimistic updates)
37
+ changedState: state.changed, // changed-state (delta of optimistic updates)
38
+ clientState: state.current, // client-side state
39
+ signedState: state.signed // server-side state
41
40
  }
42
41
  }
43
42
 
@@ -85,9 +84,6 @@ async function invokeCommand(event) {
85
84
 
86
85
  if (['frame', 'window'].includes(driver.name)) event.preventDefault()
87
86
 
88
- Commands.busy = true
89
- setTimeout(() => (Commands.busy = false), 10)
90
-
91
87
  switch (driver.name) {
92
88
  case 'method':
93
89
  return driver.invokeCommand(element, payload)
@@ -96,7 +92,7 @@ async function invokeCommand(event) {
96
92
  case 'frame':
97
93
  return driver.invokeCommand(driver.frame, payload)
98
94
  case 'window':
99
- return driver.invokeCommand(payload)
95
+ return driver.invokeCommand(self, payload)
100
96
  }
101
97
  } catch (error) {
102
98
  dispatch(commandEvents.clientError, element, {
@@ -0,0 +1,39 @@
1
+ import headers from './headers'
2
+ import lifecycle from './lifecycle'
3
+ import state from './state'
4
+ import urls from './urls'
5
+ import { dispatch } from './events'
6
+ import { render } from './renderer'
7
+
8
+ const parseError = error => {
9
+ const errorMessage = `Unexpected error performing a TurboBoost Command! ${error.message}`
10
+ dispatch(lifecycle.events.clientError, document, { detail: { error: errorMessage } }, true)
11
+ }
12
+
13
+ const parseAndRenderResponse = response => {
14
+ const { strategy } = headers.tokenize(response.headers.get(headers.RESPONSE_HEADER))
15
+
16
+ // FAIL: Status outside the range of 200-399
17
+ if (response.status < 200 || response.status > 399) {
18
+ const error = `Server returned a ${response.status} status code! TurboBoost Commands require 2XX-3XX status codes.`
19
+ dispatch(lifecycle.events.serverError, document, { detail: { error, response } }, true)
20
+ }
21
+
22
+ response.text().then(content => render(strategy, content))
23
+ }
24
+
25
+ const invoke = (payload = {}) => {
26
+ try {
27
+ fetch(urls.commandInvocationURL.href, {
28
+ method: 'POST',
29
+ headers: headers.prepare({}),
30
+ body: JSON.stringify(payload)
31
+ })
32
+ .then(parseAndRenderResponse)
33
+ .catch(parseError)
34
+ } catch (error) {
35
+ parseError(error)
36
+ }
37
+ }
38
+
39
+ export { invoke }