turbo_boost-commands 0.2.1.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -29
  3. data/app/assets/builds/@turbo-boost/commands.js +1 -1
  4. data/app/assets/builds/@turbo-boost/commands.js.map +4 -4
  5. data/app/assets/builds/@turbo-boost/commands.metafile.json +1 -1
  6. data/app/controllers/concerns/turbo_boost/commands/controller.rb +1 -1
  7. data/app/javascript/elements.js +0 -1
  8. data/app/javascript/events.js +6 -3
  9. data/app/javascript/headers.js +2 -2
  10. data/app/javascript/index.js +20 -11
  11. data/app/javascript/invoker.js +2 -10
  12. data/app/javascript/lifecycle.js +3 -6
  13. data/app/javascript/logger.js +29 -2
  14. data/app/javascript/renderer.js +11 -5
  15. data/app/javascript/schema.js +2 -1
  16. data/app/javascript/state/index.js +47 -34
  17. data/app/javascript/state/observable.js +1 -1
  18. data/app/javascript/state/page.js +33 -0
  19. data/app/javascript/state/storage.js +11 -0
  20. data/app/javascript/turbo.js +0 -10
  21. data/app/javascript/version.js +1 -1
  22. data/lib/turbo_boost/commands/attribute_set.rb +8 -0
  23. data/lib/turbo_boost/commands/command.rb +8 -3
  24. data/lib/turbo_boost/commands/command_callbacks.rb +23 -6
  25. data/lib/turbo_boost/commands/command_validator.rb +44 -0
  26. data/lib/turbo_boost/commands/controller_pack.rb +10 -10
  27. data/lib/turbo_boost/commands/engine.rb +14 -10
  28. data/lib/turbo_boost/commands/errors.rb +15 -8
  29. data/lib/turbo_boost/commands/{middleware.rb → middlewares/entry_middleware.rb} +30 -21
  30. data/lib/turbo_boost/commands/middlewares/exit_middleware.rb +63 -0
  31. data/lib/turbo_boost/commands/patches/action_view_helpers_tag_helper_tag_builder_patch.rb +10 -2
  32. data/lib/turbo_boost/commands/responder.rb +28 -0
  33. data/lib/turbo_boost/commands/runner.rb +150 -186
  34. data/lib/turbo_boost/commands/sanitizer.rb +1 -1
  35. data/lib/turbo_boost/commands/state.rb +97 -47
  36. data/lib/turbo_boost/commands/state_store.rb +72 -0
  37. data/lib/turbo_boost/commands/token_validator.rb +51 -0
  38. data/lib/turbo_boost/commands/version.rb +1 -1
  39. metadata +29 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 443e413bd26d0ea5fa7d48cc4b11510d2cf7c5bca2a4c94edb74fc1328580dc8
4
- data.tar.gz: 49e7ec9da50a046233b013b2c69a6c4a781e80c0fd0c4334ceed3095a163f31f
3
+ metadata.gz: 11cb4c3233367fbd2a6733033ee352f8f217bcd929817fdd6b9999203129ceb9
4
+ data.tar.gz: 8edb64dcc1ee4b64c5df89eb9f080b97eff887fb7a388637178e57ec3fe157de
5
5
  SHA512:
6
- metadata.gz: f0c9c92ed9b6bc401f5e0f4cbdf174f24c8460114e9a64b76f1ff46d69bb69c612daf7977e919e728f523c03b1e596857df09fdbf006eaa1279e59da5cec6bc7
7
- data.tar.gz: 80d485a7dc26331793b225a3abdd52e22d4baac5fd06a76bf4131633b6aad57108766069daa5e75874d30259a01edc6f3d674c22ed505463bc72590bf3e65e63
6
+ metadata.gz: f57b7ae1c028189688e7099493163b81dedf6ea765baed04acbdc80c81bb62681768426e4c8b9228104899146107de9752e76ba441c6be19617f54ba12b21e9a
7
+ data.tar.gz: 255efbedfc0281af6fd6b56a816ca6a503fd5176a26d9dff58f67b03683879de705142aade018a33189651174495f19ddc506037a9cc56d043c28e88dfc051b1
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  </h1>
9
9
  <p align="center">
10
10
  <a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/">
11
- <img alt="Lines of Code" src="https://img.shields.io/badge/loc-1450-47d299.svg" />
11
+ <img alt="Lines of Code" src="https://img.shields.io/badge/loc-1736-47d299.svg" />
12
12
  </a>
13
13
  <a href="https://codeclimate.com/github/hopsoft/turbo_boost-commands/maintainability">
14
14
  <img src="https://api.codeclimate.com/v1/badges/fe1162a742fe83a4fdfd/maintainability" />
@@ -31,8 +31,8 @@
31
31
  <a href="https://bundlephobia.com/package/@turbo-boost/commands@">
32
32
  <img alt="NPM Bundle Size" src="https://img.shields.io/bundlephobia/minzip/@turbo-boost/commands?label=bundle%20size&logo=npm&color=47d299">
33
33
  </a>
34
- <a href="https://github.com/sheerun/prettier-standard">
35
- <img alt="JavaScript Style" src="https://img.shields.io/badge/style-prettier--standard-168AFE?logo=javascript&logoColor=f4e137" />
34
+ <a href="https://github.com/prettier/prettier">
35
+ <img alt="JavaScript Style" src="https://img.shields.io/badge/style-prettier-ff69b4?logo=javascript&logoColor=f4e137" />
36
36
  </a>
37
37
  <a href="https://github.com/hopsoft/turbo_boost-commands/actions/workflows/tests.yml">
38
38
  <img alt="Tests" src="https://github.com/hopsoft/turbo_boost-commands/actions/workflows/tests.yml/badge.svg" />
@@ -59,29 +59,31 @@
59
59
 
60
60
  ## Table of Contents
61
61
 
62
- - [Why TurboBoost Commands?](#why-turboboost-commands)
63
- - [Sponsors](#sponsors)
64
- - [Dependencies](#dependencies)
65
- - [Setup](#setup)
66
- - [Usage](#usage)
67
- - [Event Delegates](#event-delegates)
68
- - [Lifecycle Events](#lifecycle-events)
69
- - [Targeting Frames](#targeting-frames)
70
- - [Working with Forms](#working-with-forms)
71
- - [Server Side Commands](#server-side-commands)
72
- - [Appending Turbo Streams](#appending-turbo-streams)
73
- - [Setting Instance Variables](#setting-instance-variables)
74
- - [Prevent Controller Action](#prevent-controller-action)
75
- - [Broadcasting Turbo Streams](#broadcasting-turbo-streams)
76
- - [Community](#community)
77
- - [Developing](#developing)
78
- - [Notable Files](#notable-files)
79
- - [Deploying](#deploying)
80
- - [Notable Files](#notable-files-1)
81
- - [How to Deploy](#how-to-deploy)
82
- - [Releasing](#releasing)
83
- - [About TurboBoost](#about-turboboost)
84
- - [License](#license)
62
+ - [Why TurboBoost Commands?](#why-turboboost-commands)
63
+ - [Sponsors](#sponsors)
64
+ - [Dependencies](#dependencies)
65
+ - [Setup](#setup)
66
+ - [Configuration](#configuration)
67
+ - [Usage](#usage)
68
+ - [Event Delegates](#event-delegates)
69
+ - [Lifecycle Events](#lifecycle-events)
70
+ - [Targeting Frames](#targeting-frames)
71
+ - [Working with Forms](#working-with-forms)
72
+ - [Server Side Commands](#server-side-commands)
73
+ - [Appending Turbo Streams](#appending-turbo-streams)
74
+ - [Setting Instance Variables](#setting-instance-variables)
75
+ - [Prevent Controller Action](#prevent-controller-action)
76
+ - [Broadcasting Turbo Streams](#broadcasting-turbo-streams)
77
+ - [Tracking Page State](#tracking-page-state)
78
+ - [Community](#community)
79
+ - [Developing](#developing)
80
+ - [Notable Files](#notable-files)
81
+ - [Deploying](#deploying)
82
+ - [Notable Files](#notable-files-1)
83
+ - [How to Deploy](#how-to-deploy)
84
+ - [Releasing](#releasing)
85
+ - [About TurboBoost](#about-turboboost)
86
+ - [License](#license)
85
87
 
86
88
  <!-- Tocer[finish]: Auto-generated, don't remove. -->
87
89
 
@@ -170,6 +172,33 @@ rails app:template LOCATION='https://railsbytes.com/script/xkjsbB'
170
172
  +import '@turbo-boost/commands'
171
173
  ```
172
174
 
175
+ ## Configuration
176
+
177
+ TurboBoost Commands can be configured via Rails initializer.
178
+
179
+ ```ruby
180
+ # config/initializers/turbo_boost_commands.rb
181
+ TurboBoost::Commands.config.tap do |config|
182
+ # opt-[in/out] of alerting on abort (true, *false, "development", "test", "production")
183
+ config.alert_on_abort = "development"
184
+
185
+ # opt-[in/out] of alerting on error (true, *false, "development", "test", "production")
186
+ config.alert_on_error = "development"
187
+
188
+ # opt-[in/out] of precompiling TurboBoost assets (*true, false)
189
+ config.precompile_assets = true
190
+
191
+ # opt-[in/out] of forgery protection (true, *false)
192
+ config.protect_from_forgery = true
193
+
194
+ # opt-[in/out] of raising an error when an invalid command is invoked (true, false, *"development", "test", "production")
195
+ config.raise_on_invalid_command = "development"
196
+
197
+ # opt-[in/out] of state resolution (true, *false)
198
+ config.resolve_state = true
199
+ end
200
+ ```
201
+
173
202
  ## Usage
174
203
 
175
204
  This example illustrates how to use TurboBoost Commands to manage upvotes on a Post.
@@ -381,7 +410,8 @@ end
381
410
 
382
411
  _This proves especially powerful when paired with [TurboBoost Streams](https://github.com/hopsoft/turbo_boost-streams)._
383
412
 
384
- > 📘 **NOTE:** `turbo_stream.invoke` is a [TurboBoost Streams](https://github.com/hopsoft/turbo_boost-streams#usage) feature.
413
+ > [!NOTE]
414
+ > `turbo_stream.invoke` is a [TurboBoost Streams](https://github.com/hopsoft/turbo_boost-streams#usage) feature.
385
415
 
386
416
  ### Setting Instance Variables
387
417
 
@@ -476,7 +506,44 @@ end
476
506
  _Learn more about Turbo Stream broadcasting by reading through the
477
507
  [hotwired/turbo-rails](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb) source code._
478
508
 
479
- > 📘 **NOTE:** `broadcast_invoke_later_to` is a [TurboBoost Streams](https://github.com/hopsoft/turbo_boost-streams#broadcasting) feature.
509
+ > [!NOTE]
510
+ > `broadcast_invoke_later_to` is a [TurboBoost Streams](https://github.com/hopsoft/turbo_boost-streams#broadcasting) feature.
511
+
512
+ ### Tracking Page State
513
+
514
+ You can opt-in to remember transient page state when using Rails tag helpers with `turbo_boost[:remember]` to track
515
+ element attribute values between requests.
516
+
517
+ ```erb
518
+ <%= tag.details id: "page-state-example", open: "open", turbo_boost: { remember: [:open] } do %>
519
+ <summary>Page State Example</summary>
520
+ Content...
521
+ <% end %>
522
+ ```
523
+
524
+ The code above will be expanded to this HTML.
525
+
526
+ ```html
527
+ <details id="page-state-example" open="open" data-turbo-boost-state-attributes="['open']">
528
+ <summary>Page State Example</summary>
529
+ Content...
530
+ </details>
531
+ ```
532
+
533
+ If the user closes the details element and invokes a command or performs a request,
534
+ the server will pre-render the markup with the current page state preserving the `open` attribute value.
535
+ _The client also ensures that remembered attributes are restored after DOM mutations._
536
+
537
+ Several things happen when you use `turbo_boost[:remember]` to track page state.
538
+
539
+ 1. The client builds the current page state before emitting requests to the server.
540
+ 1. The server uses the page state when rendering the response.
541
+ 1. The client client verifies the page state and restores attribute values _(if necessary)_ after the DOM updates.
542
+
543
+ This feature works with all attributes, including aria, data, and custom attributes.
544
+
545
+ > [!NOTE]
546
+ > Elements must have a unique `id` assigned to participate in page state tracking.
480
547
 
481
548
  ## Community
482
549
 
@@ -558,7 +625,7 @@ fly deploy
558
625
  1. Commit and push any changes to GitHub
559
626
  1. Run `rake release`
560
627
  1. Run `npm publish --access public`
561
- 1. Create a new release on GitHub ([here](https://github.com/hopsoft/turbo_boost-commands/releases)) and generate the changelog for the stable release for it
628
+ 1. Create a new release on GitHub ([here](https://github.com/hopsoft/turbo_boost-commands/releases))
562
629
 
563
630
  ## About TurboBoost
564
631
 
@@ -1,2 +1,2 @@
1
- var nt=Object.defineProperty,at=Object.defineProperties;var st=Object.getOwnPropertyDescriptors;var I=Object.getOwnPropertySymbols;var it=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var M=(t,e,r)=>e in t?nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e)=>{for(var r in e||(e={}))it.call(e,r)&&M(t,r,e[r]);if(I)for(var r of I(e))dt.call(e,r)&&M(t,r,e[r]);return t},v=(t,e)=>at(t,st(e));var mt="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"},ct=(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},ut=t=>{if(t){let[e,r,o]=t.split(", ");return{status:e,strategy:r,name:o}}return{}},b={prepare:ct,tokenize:ut,RESPONSE_HEADER:mt};var x={};function lt(t){x[t.id]=t}function ft(t){delete x[t]}var k={add:lt,remove:ft,get commands(){return[...Object.values(x)]},get length(){return Object.keys(x).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 j(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,j);addEventListener(i.success,j);addEventListener(i.finish,t=>k.remove(t.detail.id),!0);var g={events:i};function pt(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}var q={v4:pt};var bt=t=>{document.body.insertAdjacentHTML("beforeend",t)},vt=t=>{let r=new DOMParser().parseFromString(t,"text/html");TurboBoost.Streams.morph.method(document.documentElement,r.documentElement)},S=(t,e)=>{if(t.match(/^Append$/i))return bt(e);if(t.match(/^Replace$/i))return vt(e)};var R={};addEventListener("turbo:before-fetch-response",t=>{let e=t.target.closest("turbo-frame");e!=null&&e.id&&(e!=null&&e.src)&&(R[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=>S(m,u))});addEventListener("turbo:frame-load",t=>{let e=t.target.closest("turbo-frame");e.dataset.src=R[e.id]||e.src||e.dataset.src,delete R[e.id]});var ht={frameAttribute:"data-turbo-frame",methodAttribute:"data-turbo-method",commandAttribute:"data-turbo-command",confirmAttribute:"data-turbo-confirm"},d=a({},ht);var H={method:t=>Promise.resolve(confirm(t))},gt=t=>t.detail.driver==="method",Et=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)},yt=t=>gt(t)||Et(t);document.addEventListener(i.start,async t=>{let e=t.target.getAttribute(d.confirmAttribute);if(!e||(t.detail.confirmation=!0,yt(t)))return;await H.method(e)||t.preventDefault()});var U=H;var f=[],_;function Ct(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,_,!0),document.addEventListener(t,_,!0),a({},f.find(o=>o.name===t))}function At(t){return f.find(e=>e.selectors.find(r=>Array.from(document.querySelectorAll(r)).find(o=>o===t)))}function xt(t,e){let r=At(e);return r&&r.name===t}var p={register:Ct,isRegisteredForElement:xt,get events(){return[...f]},set handler(t){_=t}};function kt(t){return t.closest(`[${d.commandAttribute}]`)}function St(t){return t.closest("turbo-frame[src]")||t.closest("turbo-frame[data-turbo-frame-src]")||t.closest("turbo-frame")}function wt(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 Lt(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,wt(t,e),delete e.class,delete e.action,delete e.href,delete e[d.commandAttribute],delete e[d.frameAttribute],e}var E={buildAttributePayload:Lt,findClosestCommand:kt,findClosestFrameWithSource:St};var Tt=(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)},z={invokeCommand:Tt};var D;function w(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:D}}),!0},set(o,n,m,u){return o[n]=w(m,this),s(l.stateChange,document,{detail:{state:D}}),!0}});if(Array.isArray(t))t.forEach((o,n)=>t[n]=w(o,r));else if(typeof t=="object")for(let[o,n]of Object.entries(t))t[o]=w(n,r);return e||(D=r),r}var J=w;var P,L,$,V;function Ot(t,e){let r=JSON.parse(t);P=a({},r),V=e,L=J(r),$={},setTimeout(()=>s(l.stateLoad,document,{detail:{state:L}}))}addEventListener(l.stateChange,t=>{for(let[e,r]of Object.entries(L))P[e]!==r&&($[e]=r)});var y={initialize:Ot,events:l,get initial(){return P},get current(){return L},get changed(){return $},get signed(){return V}};var Rt=t=>{let e=document.createElement("a");return e.href=t,new URL(e)},W={get commandInvocationURL(){return Rt("/turbo-boost-command-invocation")}};var G=t=>{let e=`Unexpected error performing a TurboBoost Command! ${t.message}`;s(g.events.clientError,document,{detail:{error:e}},!0)},_t=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=>S(e,r))},T=(t={})=>{try{fetch(W.commandInvocationURL.href,{method:"POST",headers:b.prepare({}),body:JSON.stringify(t)}).then(_t).catch(G)}catch(e){G(e)}};var Dt=(t,e)=>T(e),B={invokeCommand:Dt};var C,N,Pt=()=>{C=null,N=null},$t=(t,e={})=>{C=t,N=e},Bt=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(N),t.contains(e)||t.appendChild(e)}finally{Pt()}};document.addEventListener("submit",t=>Bt(t.target),!0);var K={invokeCommand:$t};var Nt=(t,e={})=>T(e),Q={invokeCommand:Nt};function X(t,e){return e=e||{dataset:{}},t.href||e.src||e.dataset.src||location.href}function Xt(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:z.invokeCommand}:o&&o.length>0?{name:"method",reason:"Element defines data-turbo-method.",frame:e,src:t.href,invokeCommand:K.invokeCommand}:r&&r!=="_self"?(e=document.getElementById(r),{name:"frame",reason:"element targets a frame that is not _self",frame:e,src:X(t,e),invokeCommand:B.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:X(t,e),invokeCommand:B.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:X(t),invokeCommand:Q.invokeCommand}}var F={find:Xt};var A="unknown",Y=!1,O=[],Z={debug:Object.values(c),info:Object.values(c),warn:[c.abort,c.clientError,c.serverError],error:[c.clientError,c.serverError],unknown:[]},Ft=t=>{if(!Z[A].includes(t.type)||typeof console[A]!="function")return!1;let{detail:e}=t;if(!e.id)return!0;let r=`${t.type}-${e.id}`;return O.includes(r)?!1:(O.length>16&&O.shift(),O.push(r),!0)},It=t=>{if(Ft(t)){let{target:e,type:r,detail:o}=t;console[A](r,o.id||"",{target:e,detail:o})}};Y||(Y=!0,Object.values(c).forEach(t=>addEventListener(t,e=>It(e))));var tt={get level(){return A},set level(t){return Object.keys(Z).includes(t)||(t="unknown"),A=t}};var et="0.2.1.1";var Mt=self.TurboBoost||{},ot={VERSION:et,active:!1,confirmation:U,logger:tt,schema:d,events:i,registerEventDelegate:p.register,get eventDelegates(){return p.events}};function rt(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 jt(t){let e,r={};try{if(e=E.findClosestCommand(t.target),!e||!p.isRegisteredForElement(t.type,e))return;let o=`turbo-command-${q.v4()}`,n=F.find(e),m=v(a({},rt(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=F.find(e),m=v(a({},rt(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),k.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({},Mt);self.TurboBoost.Commands||(p.handler=jt,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=ot,self.TurboBoost.State=y);var ir=ot;export{ir as default};
1
+ var mt=Object.defineProperty,lt=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var X=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,bt=Object.prototype.propertyIsEnumerable;var G=(t,e,r)=>e in t?mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,a=(t,e)=>{for(var r in e||(e={}))pt.call(e,r)&&G(t,r,e[r]);if(X)for(var r of X(e))bt.call(e,r)&&G(t,r,e[r]);return t},p=(t,e)=>lt(t,ft(e));var gt="TurboBoost-Command",y={boost:"text/vnd.turbo-boost.html",stream:"text/vnd.turbo-stream.html",html:"text/html",xhtml:"application/xhtml+xml",json:"application/json"},ht=(t={})=>{t=a({},t);let e=(t.Accept||"").split(",").map(r=>r.trim()).filter(r=>r.length);return e.unshift(y.boost,y.stream,y.html,y.xhtml),t.Accept=[...new Set(e)].join(", "),t["Content-Type"]=y.json,t["X-Requested-With"]="XMLHttpRequest",t},vt=t=>{if(t){let[e,r,o]=t.split(", ");return{name:e,status:r,strategy:o}}return{}},f={prepare:ht,tokenize:vt,RESPONSE_HEADER:gt};var yt=t=>{document.body.insertAdjacentHTML("beforeend",t)},Et=t=>{var h,k,v,C;let r=new DOMParser().parseFromString(t,"text/html"),o=document.querySelector("head"),n=document.querySelector("body"),i=r.querySelector("head"),u=r.querySelector("body");o&&i&&((k=(h=TurboBoost==null?void 0:TurboBoost.Streams)==null?void 0:h.morph)==null||k.method(o,i)),n&&u&&((C=(v=TurboBoost==null?void 0:TurboBoost.Streams)==null?void 0:v.morph)==null||C.method(n,u))},w=(t,e)=>{if(t&&e){if(t.match(/^Append$/i))return yt(e);if(t.match(/^Replace$/i))return Et(e)}};var B={};addEventListener("turbo:before-fetch-response",t=>{let e=t.target.closest("turbo-frame");e!=null&&e.id&&(e!=null&&e.src)&&(B[e.id]=e.src);let{fetchResponse:r}=t.detail,o=r.header(f.RESPONSE_HEADER);if(!o)return;t.preventDefault();let{strategy:n}=f.tokenize(o);r.responseHTML.then(i=>w(n,i))});addEventListener("turbo:frame-load",t=>{let e=t.target.closest("turbo-frame");e.dataset.src=B[e.id]||e.src||e.dataset.src,delete B[e.id]});var At={frameAttribute:"data-turbo-frame",methodAttribute:"data-turbo-method",commandAttribute:"data-turbo-command",confirmAttribute:"data-turbo-confirm",stateAttributesAttribute:"data-turbo-boost-state-attributes"},d=a({},At);var s={start:"turbo-boost:command:start",success:"turbo-boost:command:success",finish:"turbo-boost:command:finish",abort:"turbo-boost:command:abort",clientError:"turbo-boost:command:client-error",serverError:"turbo-boost:command:server-error"},E={stateChange:"turbo-boost:state:change",stateInitialize:"turbo-boost:state:initialize"};function c(t,e,r={}){return new Promise(o=>{r=r||{},r.detail=r.detail||{},e=e||document;let n=new CustomEvent(t,p(a({},r),{bubbles:!0}));e.dispatchEvent(n),o(n)})}var L={};function St(t){L[t.id]=t}function xt(t){delete L[t]}var O={add:St,remove:xt,get commands(){return[...Object.values(L)]},get length(){return Object.keys(L).length}};var K={method:t=>Promise.resolve(confirm(t))},kt=t=>t.detail.driver==="method",Ct=t=>{if(t.detail.driver!=="form")return!1;let e=t.target,r=e.closest("turbo-frame"),o=e.closest(`[${d.frameAttribute}]`);return!!(r||o)},wt=t=>kt(t)||Ct(t);document.addEventListener(s.start,async t=>{let e=t.target.getAttribute(d.confirmAttribute);if(!e||(t.detail.confirmation=!0,wt(t)))return;await K.method(e)||t.preventDefault()});var Q=K;var l=[],I;function Lt(t,e){let r=l.find(o=>o.name===t);return r&&l.splice(l.indexOf(r),1),l=[{name:t,selectors:e},...l],document.removeEventListener(t,I,!0),document.addEventListener(t,I,!0),a({},l.find(o=>o.name===t))}function Ot(t){return l.find(e=>e.selectors.find(r=>Array.from(document.querySelectorAll(r)).find(o=>o===t)))}function Tt(t,e){let r=Ot(e);return r&&r.name===t}var m={register:Lt,isRegisteredForElement:Tt,get events(){return[...l]},set handler(t){I=t}};function Rt(t){return t.closest(`[${d.commandAttribute}]`)}function Pt(t){return t.closest("turbo-frame[src]")||t.closest("turbo-frame[data-turbo-frame-src]")||t.closest("turbo-frame")}function $t(t,e={}){if(t.tagName.toLowerCase()!=="select")return e.value=t.value||null;if(!t.multiple)return e.value=t.options[t.selectedIndex].value;e.values=Array.from(t.options).reduce((r,o)=>(o.selected&&r.push(o.value),r),[])}function _t(t){let e=Array.from(t.attributes).reduce((r,o)=>{let n=o.value;return r[o.name]=n,r},{});return e.tag=t.tagName,e.checked=!!t.checked,e.disabled=!!t.disabled,$t(t,e),delete e.class,delete e.action,delete e.href,delete e[d.commandAttribute],delete e[d.frameAttribute],e}var A={buildAttributePayload:_t,findClosestCommand:Rt,findClosestFrameWithSource:Pt};var Dt=(t,e={})=>{let r=t.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");r.type="hidden",r.name="turbo_boost_command",r.value=JSON.stringify(e),t.contains(r)||t.appendChild(r)},Y={invokeCommand:Dt};function Nt(t){setTimeout(()=>c(s.finish,t.target,{detail:t.detail}))}var Bt=[s.abort,s.serverError,s.success];Bt.forEach(t=>addEventListener(t,Nt));addEventListener(s.finish,t=>O.remove(t.detail.id),!0);var Z={events:s};var It=t=>{let e=document.createElement("a");return e.href=t,new URL(e)},tt={get commandInvocationURL(){return It("/turbo-boost-command-invocation")}};var et=t=>{let e=`Unexpected error performing a TurboBoost Command! ${t.message}`;c(Z.events.clientError,document,{detail:{message:e,error:t}},!0)},qt=t=>{let{strategy:e}=f.tokenize(t.headers.get(f.RESPONSE_HEADER));t.text().then(r=>w(e,r))},T=(t={})=>{try{fetch(tt.commandInvocationURL.href,{method:"POST",headers:f.prepare({}),body:JSON.stringify(t)}).then(qt).catch(et)}catch(e){et(e)}};var jt=(t,e)=>T(e),q={invokeCommand:jt};var S,j,zt=()=>{S=null,j=null},Ft=(t,e={})=>{S=t,j=e},Mt=t=>{try{if(!S||t.getAttribute("method")!==S.dataset.turboMethod||t.getAttribute("action")!==S.href)return;let e=t.querySelector('input[name="turbo_boost_command"]')||document.createElement("input");e.type="hidden",e.name="turbo_boost_command",e.value=JSON.stringify(j),t.contains(e)||t.appendChild(e)}finally{zt()}};document.addEventListener("submit",t=>Mt(t.target),!0);var rt={invokeCommand:Ft};var Ht=(t,e={})=>T(e),ot={invokeCommand:Ht};function z(t,e){return e=e||{dataset:{}},t.href||e.src||e.dataset.src||location.href}function Jt(t){let e=A.findClosestFrameWithSource(t),{turboFrame:r,turboMethod:o}=t.dataset;return t.tagName.toLowerCase()==="form"?{name:"form",reason:"Element is a form.",frame:e,src:t.action,invokeCommand:Y.invokeCommand}:o&&o.length>0?{name:"method",reason:"Element defines data-turbo-method.",frame:e,src:t.href,invokeCommand:rt.invokeCommand}:r&&r!=="_self"?(e=document.getElementById(r),{name:"frame",reason:"element targets a frame that is not _self",frame:e,src:z(t,e),invokeCommand:q.invokeCommand}):(!r||r==="_self")&&e?{name:"frame",reason:"element does NOT target a frame or targets _self and is contained by a frame",frame:e,src:z(t,e),invokeCommand:q.invokeCommand}:{name:"window",reason:"element matches one or more of the following conditions (targets _top, does NOT target a frame, is NOT contained by a frame)",frame:null,src:z(t),invokeCommand:ot.invokeCommand}}var F={find:Jt};var P="unknown",nt=!1,R=[],b={debug:Object.values(s),info:Object.values(s),warn:[s.abort,s.clientError,s.serverError],error:[s.clientError,s.serverError],unknown:[]},Ut=t=>{if(!b[P].includes(t.type)||typeof console[P]!="function")return!1;let{detail:e}=t;if(!e.id)return!0;let r=`${t.type}-${e.id}`;return R.includes(r)?!1:(R.length>16&&R.shift(),R.push(r),!0)},Vt=t=>b.error.includes(t.type)?"error":b.warn.includes(t.type)?"warn":b.info.includes(t.type)?"info":b.debug.includes(t.type)?"debug":"log",Wt=t=>{if(Ut(t)){let{target:e,type:r,detail:o}=t,n=o.id||"",i=o.name||"",u="";o.startedAt&&(u=`${Date.now()-o.startedAt}ms `);let h=r.split(":"),k=h.pop(),v=`%c${h.join(":")}:%c${k}`,C=[`%c${i}`,`%c${u}`,v];console[Vt(t)](C.join(" ").replace(/\s{2,}/g," "),"color:deepskyblue","color:lime","color:darkgray",v.match(/abort|error/i)?"color:red":"color:deepskyblue",{id:n,detail:o,target:e})}};nt||(nt=!0,Object.values(s).forEach(t=>addEventListener(t,e=>Wt(e))));var at={get level(){return P},set level(t){return Object.keys(b).includes(t)||(t="unknown"),P=t}};var M;function $(t,e=null){if(!t||typeof t!="object")return t;let r=new Proxy(t,{deleteProperty(o,n){return delete o[n],c(E.stateChange,document,{detail:{state:M}}),!0},set(o,n,i,u){return o[n]=$(i,this),c(E.stateChange,document,{detail:{state:M}}),!0}});if(Array.isArray(t))t.forEach((o,n)=>t[n]=$(o,r));else if(typeof t=="object")for(let[o,n]of Object.entries(t))t[o]=$(n,r);return e||(M=r),r}var H=$;var st=(t,e,r,o=1)=>{if(o>20)return;let n=document.getElementById(t);if(n!=null&&n.isConnected)return n.setAttribute(e,r);setTimeout(()=>st(t,e,r,o+1),o*5)},Xt=()=>Array.from(document.querySelectorAll(`[id][${d.stateAttributesAttribute}]`)).reduce((e,r)=>{let o=JSON.parse(r.getAttribute(d.stateAttributesAttribute));return r.id&&(e[r.id]=o.reduce((n,i)=>(r.hasAttribute(i)&&(n[i]=r.getAttribute(i)||i),n),{})),e},{}),Gt=(t={})=>{for(let[e,r]of Object.entries(t))for(let[o,n]of Object.entries(r))st(e,o,n)},_={buildState:Xt,restoreState:Gt};function Kt(t,e){return typeof e!="object"&&(e={}),localStorage.setItem(String(t),JSON.stringify(e))}function Qt(t){let e=localStorage.getItem(String(t));return e?JSON.parse(e):{}}var D={save:Kt,find:Qt};var J="TurboBoost::State",U={pages:{},signed:null,unsigned:{}},N=null,x={},V=()=>{let t=a(a({},U),D.find(J));N=t.signed,x=H(t.unsigned),t.pages[location.pathname]=t.pages[location.pathname]||{},_.restoreState(t.pages[location.pathname])},W=()=>{let t=a(a({},U),D.find(J)),e={signed:N||t.signed,unsigned:a(a({},t.unsigned),x),pages:a({},t.pages)};e.pages[location.pathname]=a(a({},e.pages[location.pathname]),_.buildState()),D.save(J,e)},Yt=t=>{let e=a(a({},U),JSON.parse(t));N=e.signed,x=H(e.unsigned),W(),c(E.stateInitialize,document,{detail:x})};addEventListener("DOMContentLoaded",V);addEventListener("turbo:morph",V);addEventListener("turbo:render",V);addEventListener("turbo:before-fetch-request",W);addEventListener("beforeunload",W);var g={initialize:Yt,buildPageState:_.buildState,get signed(){return N},get unsigned(){return x}};function Zt(){return("10000000-1000-4000-8000"+-1e11).replace(/[018]/g,t=>(t^crypto.getRandomValues(new Uint8Array(1))[0]&15>>t/4).toString(16))}var it={v4:Zt};var dt="0.3.0";var te=self.TurboBoost||{},ut={VERSION:dt,active:!1,confirmation:Q,logger:at,schema:d,events:s,registerEventDelegate:m.register,get eventDelegates(){return m.events}};function ct(t,e){var r;return{csrfToken:(r=document.querySelector('meta[name="csrf-token"]'))==null?void 0:r.getAttribute("content"),id:t,name:e.getAttribute(d.commandAttribute),elementId:e.id.length>0?e.id:null,elementAttributes:A.buildAttributePayload(e),startedAt:Date.now(),state:{page:g.buildPageState(),signed:g.signed,unsigned:g.unsigned}}}async function ee(t){let e,r={};try{if(e=A.findClosestCommand(t.target),!e||!m.isRegisteredForElement(t.type,e))return;let o=it.v4(),n=F.find(e),i=p(a({},ct(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),u=await c(s.start,e,{cancelable:!0,detail:i});if(u.defaultPrevented||u.detail.confirmation&&t.defaultPrevented)return c(s.abort,e,{detail:{message:`An event handler for '${s.start}' prevented default behavior and blocked command invocation!`,source:u}});switch(n=F.find(e),i=p(a({},ct(o,e)),{driver:n.name,frameId:n.frame?n.frame.id:null,src:n.src}),O.add(i),["frame","window"].includes(n.name)&&t.preventDefault(),n.name){case"method":return n.invokeCommand(e,i);case"form":return n.invokeCommand(e,i,t);case"frame":return n.invokeCommand(n.frame,i);case"window":return n.invokeCommand(self,i)}}catch(o){c(s.clientError,e,{detail:p(a({},r),{error:o})})}}self.TurboBoost=a({},te);self.TurboBoost.Commands||(m.handler=ee,m.register("click",[`[${d.commandAttribute}]`]),m.register("submit",[`form[${d.commandAttribute}]`]),m.register("toggle",[`details[${d.commandAttribute}]`]),m.register("change",[`input[${d.commandAttribute}]`,`select[${d.commandAttribute}]`,`textarea[${d.commandAttribute}]`]),self.TurboBoost.Commands=ut,self.TurboBoost.State={initialize:g.initialize,get current(){return g.unsigned}});var gr=ut;export{gr as default};
2
2
  //# sourceMappingURL=commands.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../javascript/headers.js", "../../../javascript/activity.js", "../../../javascript/events.js", "../../../javascript/lifecycle.js", "../../../javascript/uuids.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/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", "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", "import uuids from './uuids'\n\nconst append = content => {\n document.body.insertAdjacentHTML('beforeend', content)\n}\n\nconst replace = content => {\n const parser = new DOMParser()\n const doc = parser.parseFromString(content, 'text/html')\n TurboBoost.Streams.morph.method(document.documentElement, doc.documentElement)\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'\nlet initialized = false\nlet history = []\n\nconst logLevels = {\n debug: Object.values(events),\n info: Object.values(events),\n warn: [events.abort, events.clientError, events.serverError],\n error: [events.clientError, events.serverError],\n unknown: []\n}\n\nconst shouldLogEvent = event => {\n if (!logLevels[currentLevel].includes(event.type)) return false\n if (typeof console[currentLevel] !== 'function') return false\n\n const { detail } = event\n if (!detail.id) return true\n\n const key = `${event.type}-${detail.id}`\n if (history.includes(key)) return false\n\n if (history.length > 16) history.shift()\n history.push(key)\n\n return true\n}\n\nconst logEvent = event => {\n if (shouldLogEvent(event)) {\n const { target, type, detail } = event\n console[currentLevel](type, detail.id || '', { target, detail })\n }\n}\n\nif (!initialized) {\n initialized = true\n Object.values(events).forEach(name => addEventListener(name, event => logEvent(event)))\n}\n\nexport default {\n get level() {\n return currentLevel\n },\n set level(value) {\n if (!Object.keys(logLevels).includes(value)) value = 'unknown'\n return (currentLevel = value)\n }\n}\n", "export default '0.2.1.1'\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,EAA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IT,CAAO,EAEhB,CAAC,QAAS,QAAQ,EAAE,SAASG,EAAO,IAAI,GAAGJ,EAAM,eAAe,EAE5DI,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,cAAc,KAAMH,CAAO,CAC7C,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,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", "v4", "c", "uuids_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", "initialized", "history", "logLevels", "allEvents", "shouldLogEvent", "event", "detail", "key", "logEvent", "target", "type", "name", "logger_default", "value", "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/renderer.js", "../../../javascript/turbo.js", "../../../javascript/schema.js", "../../../javascript/events.js", "../../../javascript/activity.js", "../../../javascript/confirmation.js", "../../../javascript/delegates.js", "../../../javascript/elements.js", "../../../javascript/drivers/form.js", "../../../javascript/lifecycle.js", "../../../javascript/urls.js", "../../../javascript/invoker.js", "../../../javascript/drivers/frame.js", "../../../javascript/drivers/method.js", "../../../javascript/drivers/window.js", "../../../javascript/drivers/index.js", "../../../javascript/logger.js", "../../../javascript/state/observable.js", "../../../javascript/state/page.js", "../../../javascript/state/storage.js", "../../../javascript/state/index.js", "../../../javascript/uuids.js", "../../../javascript/version.js", "../../../javascript/index.js"],
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 [name, status, strategy] = value.split(', ')\n return { name, status, strategy }\n }\n\n return {}\n}\n\nexport default { prepare, tokenize, RESPONSE_HEADER }\n", "const append = content => {\n document.body.insertAdjacentHTML('beforeend', content)\n}\n\nconst replace = content => {\n const parser = new DOMParser()\n const doc = parser.parseFromString(content, 'text/html')\n const head = document.querySelector('head')\n const body = document.querySelector('body')\n const newHead = doc.querySelector('head')\n const newBody = doc.querySelector('body')\n if (head && newHead) TurboBoost?.Streams?.morph?.method(head, newHead)\n if (body && newBody) TurboBoost?.Streams?.morph?.method(body, newBody)\n}\n\n// TODO: dispatch events after append/replace so we can apply page state\nexport const render = (strategy, content) => {\n if (strategy && content) {\n if (strategy.match(/^Append$/i)) return append(content)\n if (strategy.match(/^Replace$/i)) return replace(content)\n }\n}\n\nexport default { render }\n", "import headers from './headers'\nimport { render } from './renderer'\n\nconst frameSources = {}\n\n// fires after receiving a turbo HTTP response\naddEventListener('turbo:before-fetch-response', event => {\n const frame = event.target.closest('turbo-frame')\n if (frame?.id && frame?.src) frameSources[frame.id] = frame.src\n\n const { fetchResponse: response } = event.detail\n const header = response.header(headers.RESPONSE_HEADER)\n\n if (!header) return\n\n // We'll take it from here Hotwire...\n event.preventDefault()\n const { strategy } = headers.tokenize(header)\n response.responseHTML.then(content => render(strategy, content))\n})\n\n// fires when a frame element is navigated and finishes loading\naddEventListener('turbo:frame-load', event => {\n const frame = event.target.closest('turbo-frame')\n frame.dataset.src = frameSources[frame.id] || frame.src || frame.dataset.src\n delete frameSources[frame.id]\n})\n", "const schema = {\n // attributes\n frameAttribute: 'data-turbo-frame',\n methodAttribute: 'data-turbo-method',\n commandAttribute: 'data-turbo-command',\n confirmAttribute: 'data-turbo-confirm',\n stateAttributesAttribute: 'data-turbo-boost-state-attributes'\n}\n\nexport default { ...schema }\n", "export const commandEvents = {\n start: 'turbo-boost:command:start',\n success: 'turbo-boost:command:success',\n finish: 'turbo-boost:command:finish',\n abort: 'turbo-boost:command:abort',\n clientError: 'turbo-boost:command:client-error',\n serverError: 'turbo-boost:command:server-error'\n}\n\nexport const stateEvents = {\n stateChange: 'turbo-boost:state:change',\n stateInitialize: 'turbo-boost:state:initialize'\n}\n\nexport const turboEvents = {\n frameLoad: 'turbo:frame-load',\n load: 'turbo:load'\n}\n\nexport function dispatch(name, target, options = {}) {\n return new Promise(resolve => {\n options = options || {}\n options.detail = options.detail || {}\n target = target || document\n const evt = new CustomEvent(name, { ...options, bubbles: true })\n target.dispatchEvent(evt)\n resolve(evt)\n })\n}\n", "const active = {}\n\nfunction add(payload) {\n active[payload.id] = payload\n}\n\nfunction remove(id) {\n delete active[id]\n}\n\nexport default {\n add,\n remove,\n get commands() {\n return [...Object.values(active)]\n },\n get length() {\n return Object.keys(active).length\n }\n}\n", "import { commandEvents } from './events'\nimport schema from './schema'\n\nconst confirmation = {\n method: message => Promise.resolve(confirm(message))\n}\n\nconst isTurboMethod = event => event.detail.driver === 'method'\n\nconst isTurboForm = event => {\n if (event.detail.driver !== 'form') return false\n\n const element = event.target\n const frame = element.closest('turbo-frame')\n const target = element.closest(`[${schema.frameAttribute}]`)\n return !!(frame || target)\n}\n\nconst shouldDelegate = event => isTurboMethod(event) || isTurboForm(event)\n\ndocument.addEventListener(commandEvents.start, async event => {\n const message = event.target.getAttribute(schema.confirmAttribute)\n if (!message) return\n\n event.detail.confirmation = true\n\n if (shouldDelegate(event)) return // delegate confirmation handling to Turbo\n\n const proceed = await confirmation.method(message)\n if (!proceed) event.preventDefault()\n})\n\nexport default confirmation\n", "let events = []\nlet eventListener\n\nfunction register(eventName, selectors) {\n const match = events.find(evt => evt.name === eventName)\n if (match) events.splice(events.indexOf(match), 1)\n events = [{ name: eventName, selectors }, ...events]\n\n document.removeEventListener(eventName, eventListener, true)\n document.addEventListener(eventName, eventListener, true)\n\n return { ...events.find(evt => evt.name === eventName) }\n}\n\nfunction getRegisteredEventForElement(element) {\n return events.find(evt =>\n evt.selectors.find(selector => Array.from(document.querySelectorAll(selector)).find(el => el === element))\n )\n}\n\nfunction isRegisteredForElement(eventName, element) {\n const evt = getRegisteredEventForElement(element)\n return evt && evt.name === eventName\n}\n\nexport default {\n register,\n isRegisteredForElement,\n get events() {\n return [...events]\n },\n set handler(fn) {\n eventListener = fn\n }\n}\n", "import schema from './schema'\n\nfunction findClosestCommand(element) {\n return element.closest(`[${schema.commandAttribute}]`)\n}\n\nfunction findClosestFrameWithSource(element) {\n return (\n element.closest('turbo-frame[src]') ||\n element.closest('turbo-frame[data-turbo-frame-src]') ||\n element.closest('turbo-frame')\n )\n}\n\nfunction assignElementValueToPayload(element, payload = {}) {\n if (element.tagName.toLowerCase() !== 'select') return (payload.value = element.value || null)\n\n if (!element.multiple) return (payload.value = element.options[element.selectedIndex].value)\n\n payload.values = Array.from(element.options).reduce((memo, option) => {\n if (option.selected) memo.push(option.value)\n return memo\n }, [])\n}\n\nfunction buildAttributePayload(element) {\n const payload = Array.from(element.attributes).reduce((memo, attr) => {\n let value = attr.value\n memo[attr.name] = value\n return memo\n }, {})\n\n payload.tag = element.tagName\n payload.checked = !!element.checked\n payload.disabled = !!element.disabled\n assignElementValueToPayload(element, payload)\n\n // reduce payload size to keep URL length smaller\n delete payload.class\n delete payload.action\n delete payload.href\n delete payload[schema.commandAttribute]\n delete payload[schema.frameAttribute]\n\n return payload\n}\n\nexport default {\n buildAttributePayload,\n findClosestCommand,\n findClosestFrameWithSource\n}\n", "const invokeCommand = (form, payload = {}) => {\n const input = form.querySelector('input[name=\"turbo_boost_command\"]') || document.createElement('input')\n input.type = 'hidden'\n input.name = 'turbo_boost_command'\n input.value = JSON.stringify(payload)\n if (!form.contains(input)) form.appendChild(input)\n}\n\nexport default { invokeCommand }\n", "import activity from './activity'\nimport { dispatch, commandEvents } from './events'\n\nfunction finish(event) {\n setTimeout(() => dispatch(commandEvents.finish, event.target, { detail: event.detail }))\n}\n\nconst events = [commandEvents.abort, commandEvents.serverError, commandEvents.success]\nevents.forEach(name => addEventListener(name, finish))\naddEventListener(commandEvents.finish, event => activity.remove(event.detail.id), true)\n\nexport default { events: commandEvents }\n", "const buildURL = path => {\n const a = document.createElement('a')\n a.href = path\n return new URL(a)\n}\n\nexport default {\n get commandInvocationURL() {\n return buildURL('/turbo-boost-command-invocation')\n }\n}\n", "import headers from './headers'\nimport lifecycle from './lifecycle'\nimport urls from './urls'\nimport { dispatch } from './events'\nimport { render } from './renderer'\n\nconst parseError = error => {\n const message = `Unexpected error performing a TurboBoost Command! ${error.message}`\n dispatch(lifecycle.events.clientError, document, { detail: { message, error } }, true)\n}\n\nconst parseAndRenderResponse = response => {\n const { strategy } = headers.tokenize(response.headers.get(headers.RESPONSE_HEADER))\n response.text().then(content => render(strategy, content))\n}\n\nconst invoke = (payload = {}) => {\n try {\n fetch(urls.commandInvocationURL.href, {\n method: 'POST',\n headers: headers.prepare({}),\n body: JSON.stringify(payload)\n })\n .then(parseAndRenderResponse)\n .catch(parseError)\n } catch (error) {\n parseError(error)\n }\n}\n\nexport { invoke }\n", "import { invoke } from '../invoker'\n\nconst invokeCommand = (_, payload) => invoke(payload)\n\nexport default { invokeCommand }\n", "let activeElement\nlet activePayload\n\nconst reset = () => {\n activeElement = null\n activePayload = null\n}\n\nconst invokeCommand = (element, payload = {}) => {\n activeElement = element\n activePayload = payload\n}\n\nconst amendForm = form => {\n try {\n if (!activeElement) return\n if (form.getAttribute('method') !== activeElement.dataset.turboMethod) return\n if (form.getAttribute('action') !== activeElement.href) return\n\n const input = form.querySelector('input[name=\"turbo_boost_command\"]') || document.createElement('input')\n input.type = 'hidden'\n input.name = 'turbo_boost_command'\n input.value = JSON.stringify(activePayload)\n if (!form.contains(input)) form.appendChild(input)\n } finally {\n reset() // ensure reset\n }\n}\n\ndocument.addEventListener('submit', event => amendForm(event.target), true)\n\nexport default { invokeCommand }\n", "import { invoke } from '../invoker'\n\nconst invokeCommand = (_, payload = {}) => invoke(payload)\n\nexport default { invokeCommand }\n", "import elements from '../elements'\nimport formDriver from './form'\nimport frameDriver from './frame'\nimport methodDriver from './method'\nimport windowDriver from './window'\n\nfunction src(element, frame) {\n frame = frame || { dataset: {} }\n return element.href || frame.src || frame.dataset.src || location.href\n}\n\nfunction find(element) {\n let frame = elements.findClosestFrameWithSource(element)\n\n const { turboFrame, turboMethod } = element.dataset\n\n if (element.tagName.toLowerCase() === 'form')\n return {\n name: 'form',\n reason: 'Element is a form.',\n frame,\n src: element.action,\n invokeCommand: formDriver.invokeCommand\n }\n\n if (turboMethod && 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", "// TODO: Move Logger to its own library (i.e. TurboBoost.Logger)\nimport { commandEvents as events } from './events'\n\nlet currentLevel = 'unknown'\nlet initialized = false\nlet history = []\n\nconst logLevels = {\n debug: Object.values(events),\n info: Object.values(events),\n warn: [events.abort, events.clientError, events.serverError],\n error: [events.clientError, events.serverError],\n unknown: []\n}\n\nconst shouldLogEvent = event => {\n if (!logLevels[currentLevel].includes(event.type)) return false\n if (typeof console[currentLevel] !== 'function') return false\n\n const { detail } = event\n if (!detail.id) return true\n\n const key = `${event.type}-${detail.id}`\n if (history.includes(key)) return false\n\n if (history.length > 16) history.shift()\n history.push(key)\n\n return true\n}\n\nconst logMethod = event => {\n if (logLevels.error.includes(event.type)) return 'error'\n if (logLevels.warn.includes(event.type)) return 'warn'\n if (logLevels.info.includes(event.type)) return 'info'\n if (logLevels.debug.includes(event.type)) return 'debug'\n return 'log'\n}\n\nconst logEvent = event => {\n if (shouldLogEvent(event)) {\n const { target, type, detail } = event\n const id = detail.id || ''\n const commandName = detail.name || ''\n\n let duration = ''\n if (detail.startedAt) duration = `${Date.now() - detail.startedAt}ms `\n\n const typeParts = type.split(':')\n const lastPart = typeParts.pop()\n const eventName = `%c${typeParts.join(':')}:%c${lastPart}`\n const message = [`%c${commandName}`, `%c${duration}`, eventName]\n\n console[logMethod(event)](\n message.join(' ').replace(/\\s{2,}/g, ' '),\n 'color:deepskyblue',\n 'color:lime',\n 'color:darkgray',\n eventName.match(/abort|error/i) ? 'color:red' : 'color:deepskyblue',\n { id, detail, target }\n )\n }\n}\n\nif (!initialized) {\n initialized = true\n Object.values(events).forEach(name => addEventListener(name, event => logEvent(event)))\n}\n\nexport default {\n get level() {\n return currentLevel\n },\n set level(value) {\n if (!Object.keys(logLevels).includes(value)) value = 'unknown'\n return (currentLevel = value)\n }\n}\n", "import { dispatch, stateEvents as events } from '../events'\n\nlet head\n\nfunction observable(object, parent = null) {\n if (!object || typeof object !== 'object') return object\n\n const proxy = new Proxy(object, {\n deleteProperty(target, key) {\n delete target[key]\n dispatch(events.stateChange, document, { detail: { state: head } })\n return true\n },\n\n set(target, key, value, _receiver) {\n target[key] = observable(value, this)\n dispatch(events.stateChange, document, { detail: { state: head } })\n return true\n }\n })\n\n if (Array.isArray(object)) {\n object.forEach((value, index) => (object[index] = observable(value, proxy)))\n } else if (typeof object === 'object') {\n for (const [key, value] of Object.entries(object)) object[key] = observable(value, proxy)\n }\n\n if (!parent) head = proxy\n return proxy\n}\n\nexport default observable\n", "import schema from '../schema.js'\n\nconst updateElement = (id, attribute, value, attempts = 1) => {\n if (attempts > 20) return\n const element = document.getElementById(id)\n if (element?.isConnected) return element.setAttribute(attribute, value)\n setTimeout(() => updateElement(id, attribute, value, attempts + 1), attempts * 5)\n}\n\nconst buildState = () => {\n const elements = Array.from(document.querySelectorAll(`[id][${schema.stateAttributesAttribute}]`))\n return elements.reduce((memo, element) => {\n const attributes = JSON.parse(element.getAttribute(schema.stateAttributesAttribute))\n if (element.id) {\n memo[element.id] = attributes.reduce((acc, name) => {\n if (element.hasAttribute(name)) acc[name] = element.getAttribute(name) || name\n return acc\n }, {})\n }\n return memo\n }, {})\n}\n\nconst restoreState = (state = {}) => {\n for (const [id, attributes] of Object.entries(state)) {\n for (const [attribute, value] of Object.entries(attributes)) updateElement(id, attribute, value)\n }\n}\n\nexport default {\n buildState,\n restoreState\n}\n", "function save(name, value) {\n if (typeof value !== 'object') value = {}\n return localStorage.setItem(String(name), JSON.stringify(value))\n}\n\nfunction find(name) {\n const stored = localStorage.getItem(String(name))\n return stored ? JSON.parse(stored) : {}\n}\n\nexport default { save, find }\n", "// TODO: Move State to its own library\nimport observable from './observable'\nimport page from './page'\nimport storage from './storage'\nimport { dispatch, stateEvents } from '../events'\n\nconst key = 'TurboBoost::State'\nconst stub = { pages: {}, signed: null, unsigned: {} }\n\nlet signed = null // signed state <string>\nlet unsigned = {} // unsigned state (optimistic) <object>\n\nconst restore = () => {\n const saved = { ...stub, ...storage.find(key) }\n signed = saved.signed\n unsigned = observable(saved.unsigned)\n saved.pages[location.pathname] = saved.pages[location.pathname] || {}\n page.restoreState(saved.pages[location.pathname])\n}\n\nconst save = () => {\n const saved = { ...stub, ...storage.find(key) }\n const fresh = {\n signed: signed || saved.signed,\n unsigned: { ...saved.unsigned, ...unsigned },\n pages: { ...saved.pages }\n }\n\n fresh.pages[location.pathname] = { ...fresh.pages[location.pathname], ...page.buildState() }\n storage.save(key, fresh)\n}\n\nconst initialize = json => {\n const state = { ...stub, ...JSON.parse(json) }\n signed = state.signed\n unsigned = observable(state.unsigned)\n save()\n dispatch(stateEvents.stateInitialize, document, { detail: unsigned })\n}\n\n// setup\naddEventListener('DOMContentLoaded', restore)\naddEventListener('turbo:morph', restore)\naddEventListener('turbo:render', restore)\naddEventListener('turbo:before-fetch-request', save)\naddEventListener('beforeunload', save)\n\nexport default {\n initialize,\n buildPageState: page.buildState,\n get signed() {\n return signed\n },\n get unsigned() {\n return unsigned\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.3.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'\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 csrfToken: document.querySelector('meta[name=\"csrf-token\"]')?.getAttribute('content'), // -- Rails CSRF token\n id, //-------------------------------------------------------------------------------------- Uniquely identifies the command invocation\n name: element.getAttribute(schema.commandAttribute), //------------------------------------- Command name\n elementId: element.id.length > 0 ? element.id : null, //------------------------------------ ID of the element that triggered the command\n elementAttributes: elements.buildAttributePayload(element), //------------------------------ Attributes of the element that triggered the command\n startedAt: Date.now(), //------------------------------------------------------------------- Start time of when the command was invoked\n state: {\n page: state.buildPageState(),\n signed: state.signed,\n unsigned: state.unsigned\n }\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 = 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('toggle', [`details[${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 = {\n initialize: state.initialize,\n get current() {\n return state.unsigned\n }\n }\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,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,WAAW,MAAQ,CACtB,WAAYY,EAAM,WAClB,IAAI,SAAU,CACZ,OAAOA,EAAM,QACf,CACF,GAGF,IAAOc,GAAQ1B",
6
+ "names": ["RESPONSE_HEADER", "types", "prepare", "headers", "__spreadValues", "accepts", "val", "tokenize", "value", "name", "status", "strategy", "headers_default", "append", "content", "replace", "_a", "_b", "_c", "_d", "doc", "head", "body", "newHead", "newBody", "render", "strategy", "frameSources", "event", "frame", "response", "header", "headers_default", "strategy", "content", "render", "schema", "schema_default", "__spreadValues", "commandEvents", "stateEvents", "dispatch", "name", "target", "options", "resolve", "evt", "__spreadProps", "__spreadValues", "active", "add", "payload", "remove", "id", "activity_default", "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", "finish", "event", "dispatch", "commandEvents", "events", "name", "activity_default", "lifecycle_default", "buildURL", "path", "a", "urls_default", "parseError", "error", "message", "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", "initialized", "history", "logLevels", "commandEvents", "shouldLogEvent", "event", "detail", "key", "logMethod", "logEvent", "target", "type", "id", "commandName", "duration", "typeParts", "lastPart", "eventName", "message", "name", "logger_default", "value", "head", "observable", "object", "parent", "proxy", "target", "key", "dispatch", "stateEvents", "value", "_receiver", "index", "observable_default", "updateElement", "id", "attribute", "value", "attempts", "element", "buildState", "schema_default", "memo", "attributes", "acc", "name", "restoreState", "state", "page_default", "save", "name", "value", "find", "stored", "storage_default", "key", "stub", "signed", "unsigned", "restore", "saved", "__spreadValues", "storage_default", "observable_default", "page_default", "save", "fresh", "initialize", "json", "state", "dispatch", "stateEvents", "state_default", "v4", "c", "uuids_default", "version_default", "TurboBoost", "Commands", "version_default", "confirmation_default", "logger_default", "schema_default", "commandEvents", "delegates_default", "buildCommandPayload", "id", "element", "_a", "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/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/uuids.js":{"bytes":202,"imports":[],"format":"esm"},"app/javascript/renderer.js":{"bytes":516,"imports":[{"path":"app/javascript/uuids.js","kind":"import-statement","original":"./uuids"}],"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":1226,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"}],"format":"esm"},"app/javascript/version.js":{"bytes":25,"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":36764},"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/uuids.js":{"bytesInOutput":159},"app/javascript/renderer.js":{"bytesInOutput":283},"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":621},"app/javascript/version.js":{"bytesInOutput":17},"app/javascript/index.js":{"bytesInOutput":1647}},"bytes":10452}}}
1
+ {"inputs":{"app/javascript/headers.js":{"bytes":1116,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/renderer.js":{"bytes":842,"imports":[],"format":"esm"},"app/javascript/turbo.js":{"bytes":914,"imports":[{"path":"app/javascript/headers.js","kind":"import-statement","original":"./headers"},{"path":"app/javascript/renderer.js","kind":"import-statement","original":"./renderer"}],"format":"esm"},"app/javascript/schema.js":{"bytes":291,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/events.js":{"bytes":818,"imports":[{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"app/javascript/activity.js":{"bytes":279,"imports":[],"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":1415,"imports":[{"path":"app/javascript/schema.js","kind":"import-statement","original":"./schema"}],"format":"esm"},"app/javascript/drivers/form.js":{"bytes":345,"imports":[],"format":"esm"},"app/javascript/lifecycle.js":{"bytes":477,"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/urls.js":{"bytes":215,"imports":[],"format":"esm"},"app/javascript/invoker.js":{"bytes":888,"imports":[{"path":"app/javascript/headers.js","kind":"import-statement","original":"./headers"},{"path":"app/javascript/lifecycle.js","kind":"import-statement","original":"./lifecycle"},{"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":2146,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"./events"}],"format":"esm"},"app/javascript/state/observable.js":{"bytes":886,"imports":[{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"}],"format":"esm"},"app/javascript/state/page.js":{"bytes":1085,"imports":[{"path":"app/javascript/schema.js","kind":"import-statement","original":"../schema.js"}],"format":"esm"},"app/javascript/state/storage.js":{"bytes":292,"imports":[],"format":"esm"},"app/javascript/state/index.js":{"bytes":1584,"imports":[{"path":"app/javascript/state/observable.js","kind":"import-statement","original":"./observable"},{"path":"app/javascript/state/page.js","kind":"import-statement","original":"./page"},{"path":"app/javascript/state/storage.js","kind":"import-statement","original":"./storage"},{"path":"app/javascript/events.js","kind":"import-statement","original":"../events"},{"path":"<runtime>","kind":"import-statement","external":true}],"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":4185,"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":42478},"app/assets/builds/@turbo-boost/commands.js":{"imports":[],"exports":["default"],"entryPoint":"app/javascript/index.js","inputs":{"app/javascript/headers.js":{"bytesInOutput":546},"app/javascript/renderer.js":{"bytesInOutput":549},"app/javascript/turbo.js":{"bytesInOutput":441},"app/javascript/schema.js":{"bytesInOutput":227},"app/javascript/events.js":{"bytesInOutput":497},"app/javascript/activity.js":{"bytesInOutput":173},"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/lifecycle.js":{"bytesInOutput":221},"app/javascript/urls.js":{"bytesInOutput":151},"app/javascript/invoker.js":{"bytesInOutput":390},"app/javascript/drivers/frame.js":{"bytesInOutput":40},"app/javascript/drivers/method.js":{"bytesInOutput":454},"app/javascript/drivers/window.js":{"bytesInOutput":44},"app/javascript/drivers/index.js":{"bytesInOutput":983},"app/javascript/logger.js":{"bytesInOutput":1061},"app/javascript/state/observable.js":{"bytesInOutput":403},"app/javascript/state/page.js":{"bytesInOutput":541},"app/javascript/state/storage.js":{"bytesInOutput":204},"app/javascript/state/index.js":{"bytesInOutput":838},"app/javascript/uuids.js":{"bytesInOutput":160},"app/javascript/version.js":{"bytesInOutput":15},"app/javascript/index.js":{"bytesInOutput":1853}},"bytes":12204}}}
@@ -5,7 +5,7 @@ module TurboBoost::Commands::Controller
5
5
 
6
6
  included do
7
7
  before_action -> { turbo_boost.runner.run }
8
- after_action -> { turbo_boost.runner.update_response }
8
+ after_action -> { turbo_boost.runner.flush }
9
9
  helper_method :turbo_boost
10
10
  end
11
11
 
@@ -1,5 +1,4 @@
1
1
  import schema from './schema'
2
- import lifecycle from './lifecycle'
3
2
 
4
3
  function findClosestCommand(element) {
5
4
  return element.closest(`[${schema.commandAttribute}]`)
@@ -8,11 +8,14 @@ export const commandEvents = {
8
8
  }
9
9
 
10
10
  export const stateEvents = {
11
- stateLoad: 'turbo-boost:state:load',
12
- stateChange: 'turbo-boost:state:change'
11
+ stateChange: 'turbo-boost:state:change',
12
+ stateInitialize: 'turbo-boost:state:initialize'
13
13
  }
14
14
 
15
- export const allEvents = { ...commandEvents, ...stateEvents }
15
+ export const turboEvents = {
16
+ frameLoad: 'turbo:frame-load',
17
+ load: 'turbo:load'
18
+ }
16
19
 
17
20
  export function dispatch(name, target, options = {}) {
18
21
  return new Promise(resolve => {
@@ -33,8 +33,8 @@ const prepare = (headers = {}) => {
33
33
  // Tokenizes the 'TurboBoost-Command' HTTP response header value
34
34
  const tokenize = value => {
35
35
  if (value) {
36
- const [status, strategy, name] = value.split(', ')
37
- return { status, strategy, name }
36
+ const [name, status, strategy] = value.split(', ')
37
+ return { name, status, strategy }
38
38
  }
39
39
 
40
40
  return {}