phlex-reactive 0.15.2 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +269 -2
- data/README.md +92 -13
- data/app/javascript/phlex/reactive/core.js +1 -0
- data/app/javascript/phlex/reactive/core.min.js +6 -6
- data/app/javascript/phlex/reactive/core.min.js.map +4 -4
- data/app/javascript/phlex/reactive/features/bindings.js +153 -21
- data/app/javascript/phlex/reactive/features/bindings.min.js +2 -2
- data/app/javascript/phlex/reactive/features/bindings.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/countdown.js +140 -0
- data/app/javascript/phlex/reactive/features/countdown.min.js +4 -0
- data/app/javascript/phlex/reactive/features/countdown.min.js.map +10 -0
- data/app/javascript/phlex/reactive/features/form.js +54 -22
- data/app/javascript/phlex/reactive/features/form.min.js +2 -2
- data/app/javascript/phlex/reactive/features/form.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/persist.js +41 -8
- data/app/javascript/phlex/reactive/features/persist.min.js +2 -2
- data/app/javascript/phlex/reactive/features/persist.min.js.map +3 -3
- data/app/javascript/phlex/reactive/reactive_controller.js +2 -0
- data/app/javascript/phlex/reactive/reactive_controller.min.js +4 -4
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +9 -8
- data/app/javascript/phlex/reactive/runtime.js +313 -32
- data/lib/phlex/reactive/component/countdown_binding.rb +80 -0
- data/lib/phlex/reactive/component/field_references.rb +130 -0
- data/lib/phlex/reactive/component/helpers.rb +81 -19
- data/lib/phlex/reactive/component/identity.rb +34 -1
- data/lib/phlex/reactive/component/image_fallback_binding.rb +67 -0
- data/lib/phlex/reactive/component/media_binding.rb +30 -4
- data/lib/phlex/reactive/component/media_pattern.rb +79 -0
- data/lib/phlex/reactive/component/selection.rb +24 -2
- data/lib/phlex/reactive/component/show_options.rb +91 -0
- data/lib/phlex/reactive/doctor.rb +20 -8
- data/lib/phlex/reactive/engine.rb +2 -2
- data/lib/phlex/reactive/js.rb +58 -5
- data/lib/phlex/reactive/show_conditions/compare_terms.rb +142 -0
- data/lib/phlex/reactive/show_conditions.rb +39 -6
- data/lib/phlex/reactive/streamable.rb +6 -3
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +10 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{Controller as at}from"@hotwired/stimulus";import{confirmResolver as fe}from"phlex/reactive/confirm";function ct(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:visit"])return;e["reactive:visit"]=function(){let t=this.getAttribute("data-url");if(t)window.Turbo.visit(t,{action:"advance"})}}function ut(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),r=this.getAttribute("target");if(!t||!r)return;let n=document.getElementById(r);if(n)n.setAttribute("data-reactive-token-value",t)}}function lt(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=le(this.getAttribute("data-reactive-ops"));if(!t.length)return;let r=this.getAttribute("target"),n=this.getAttribute("data-reactive-verbose")==="true",i=r?document.getElementById(r):null;if(r&&!i){if(n)b("devtools",(s)=>s.missingRoot(r));return}te(t,(s)=>Yt(s,i),n?(s,a)=>b("devtools",(o)=>o.diagnoseStream(s,a,i)):void 0)}}function dt(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){b("defer",(t)=>t.streamAction(this))}}var he=!1,Q=null;function ft(){if(he)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;he=!0,document.addEventListener("turbo:before-stream-render",(e)=>{if(St(e),ht(e),pt(e),Q)Q(e,p.get("effects"));else p.get("effects")?.wrap(e)})}var M="reactive:streamed";function ht(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target,i=n?.getAttribute?.("action"),s=/^(append|prepend|update)$/.test(i);if(typeof r!=="function"||!(s||/^(before|after|replace)$/.test(i)))return;let a=n.getAttribute("target"),o=n.getAttribute("targets"),c=new Set;for(let l of a?[document.getElementById(a)]:o?document.querySelectorAll(o):[]){let d=(s?l:l?.parentElement)?.closest?.('[data-controller~="reactive"]');if(d)c.add(d)}if(c.size===0)return;t.render=async(l)=>{await r(l);for(let d of c)if(d.isConnected)d.dispatchEvent(new Event(M))}}function re(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function ne(e){try{return e.matches(":modal")}catch{return!1}}function Me(e){if(!re(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||ne(e))return;if(e.open)e.close();e.showModal()}function mt(e){if(re(e)&&e.open)e.close()}function B(e){let r=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))r.push(e);for(let n of r)if(n.open&&!ne(n))Me(n)}function pt(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target;if(typeof r!=="function"||!n?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(i)=>{await r(i),B(document)}}var me=!1;function gt(){if(me)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;me=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))B(t.target)}),document.addEventListener("turbo:morph",()=>B(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let r=t.target,n=t.detail?.newElement;if(!re(r)||!n)return;if(n.hasAttribute?.("open"))e.delete(r);else e.add(r)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:r,detail:n}=t;if(n?.attributeName!=="open"||n.mutationType!=="remove")return;if(!e.has(r)||!r.open||!ne(r))return;e.delete(r),t.preventDefault(),r.close()})}var ee=new WeakMap;function Ce(e,t,r,n){let i=ee.get(e)??new Map;ee.set(e,i);let s=(a,o)=>{i.delete(a),i.set(a,o)};if(t.endsWith("_class"))for(let a of r.classes??[])s(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))Ge(r.name)||s(r.name,e.getAttribute(r.name));else if(t==="show"||t==="hide"||t==="toggle"){if(s("hidden",e.getAttribute("hidden")),r.expanded!=null)for(let a of n({...r,to:r.expanded}))Ce(a,"set_attr",{name:"aria-expanded"})}}var pe=!1;function bt(){if(pe)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;pe=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[r,n]of ee.get(t)??[])if(r[0]===".")t.classList.toggle(r.slice(1),n);else if(n==null)t.removeAttribute(r);else if(t.getAttribute(r)!==n)t.setAttribute(r,n)})}function De(e){Q=e}var O,K=null,ge="[data-reactive-editable][contenteditable=plaintext-only]";function $e(){if(O===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",O=e.contentEditable==="plaintext-only"}catch{O=!1}return O}function C(e){if(e.matches?.(ge))e.setAttribute("contenteditable","true");e.querySelectorAll?.(ge).forEach(C)}function yt(){if(K||typeof document>"u"||typeof document.createElement!=="function")return;if($e())return;C(document),K=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")C(t.target);else t.addedNodes.forEach(C)}),K.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var be=!1;function ye(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea"||e.hasAttribute("data-reactive-editable"))&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function vt(){if(be)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;be=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented)return;let n=ye(t);if(n)wt(t,r);if(t.hasAttribute?.("data-reactive-editable")){if(W.set(t,E(r)),!n)return;for(let{name:s}of[...t.attributes])if(!r.hasAttribute(s)&&s!=="contenteditable"&&s!==_)t.removeAttribute(s);for(let{name:s,value:a}of r.attributes)if(s!=="contenteditable"&&t.getAttribute(s)!==a)t.setAttribute(s,a);return e.preventDefault()}if(t.localName!=="input"||!n)return;let i=r.getAttribute("value");if(i==null)t.removeAttribute("value");else if(t.getAttribute("value")!==i)t.setAttribute("value",i)}),document.addEventListener("focusin",(e)=>ce(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===_)&&ye(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(_)&&se(t)===oe(t))t.removeAttribute(_)})}var _="data-reactive-held",ie='[data-controller~="reactive"]',D=null,T=new Map;function se(e){return e.hasAttribute("data-reactive-editable")?E(e):e.value}function oe(e){return e.hasAttribute("data-reactive-editable")?ue(e):e.defaultValue}function _t(e){if(e.hasAttribute("data-reactive-editable"))return E(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function wt(e,t){let r=e.getAttribute("name");if(!r||/^(checkbox|radio)$/.test(e.type)||T.has(e.closest(ie)))return;let n=_t(t);if(n===se(e))return e.removeAttribute(_);if(n===oe(e))return;e.setAttribute(_,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:r,theirs:n}}))}function At(e){let t=[];for(let r of e.querySelectorAll(`[${_}]`)){if(r.closest(ie)!==e)continue;let n=r.getAttribute("name");if(se(r)===oe(r))r.removeAttribute(_);else if(n&&!t.includes(n))t.push(n)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(r)=>`\\u${r.charCodeAt(0).toString(16).padStart(4,"0")}`)}function qe(e){for(let t of e.querySelectorAll(`[${_}]`))if(t.closest(ie)===e)t.removeAttribute(_)}function ve(e,t,r=!0){let n={root:e,streams:0,release:r},i=D;D=n;try{window.Turbo.renderStreamMessage(t)}finally{D=i}if(r&&n.streams===0)qe(e)}function St(e){let t=D,r=e.detail,n=r?.render;if(!t||typeof n!=="function")return;t.streams++,r.render=async(i)=>{T.set(t.root,(T.get(t.root)||0)+1);try{return await n(i)}finally{let s=T.get(t.root)-1;if(s)T.set(t.root,s);else T.delete(t.root);if(t.release)qe(t.root)}}}var Et="__materialize",_e=!1;function Tt(){if(_e)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;_e=!0;let e=()=>{let t=document.documentElement;if(typeof t?.toggleAttribute!=="function")return;t.toggleAttribute("data-reactive-offline",globalThis.navigator?.onLine===!1)};e(),window.addEventListener("online",e),window.addEventListener("offline",e)}var Ft="phlex-reactive:latency";function Be(){return typeof sessionStorage<"u"&&Boolean(sessionStorage.getItem(Ft))}function ae(){if(typeof document>"u")return;if(!p.has("devtools")&&!w.get("devtools")[1])return;let e=document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development";if(e||Be())b("devtools",(t)=>e&&t.attach())}var We="data-reactive-active",A=0;function je(){if(A++,A===1)Je("reactive:busy")}function Ue(){if(A===0)return;if(A--,A===0)Je("reactive:idle")}function Sr(){return A}function Er(){A=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(We)}function Je(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(We,A>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:A}}))}var He="data-reactive-requests";function Ke(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Lt(t))return;let r=kt(t);r[e]=(Number(r[e])||0)+1,t.setAttribute(He,JSON.stringify(r))}function Lt(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function kt(e){try{let t=JSON.parse(e.getAttribute(He));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function we(){ct(),ut(),lt(),dt(),ft(),vt(),gt(),bt(),yt(),Tt(),ae()}function xt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ze=Symbol.for("phlex-reactive.core");if(globalThis[ze])console.error("[phlex-reactive] the client was loaded twice. Import EITHER phlex/reactive/reactive_controller (the default, "+"everything in one file) OR phlex/reactive/core (features on demand), not both — each carries its own state.");globalThis[ze]=!0;var Ve=!1;function Rt(){if(Ve)return;if(typeof document>"u")return;let e=document.querySelectorAll('[data-controller~="reactive"]');if(!e||e.length===0)return;console.warn("[phlex-reactive] found "+e.length+' element(s) with data-controller="reactive" '+"but the reactive controller never connected. It is loaded but not registered — "+'add `application.register("reactive", ReactiveController)` (importmap) or import it into app/javascript/controllers/ for lazyLoadControllersFrom apps. See the README.')}if(typeof window<"u"&&typeof document<"u"){let e=()=>setTimeout(Rt,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Nt=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Ge(e){let t=String(e).toLowerCase();return t.startsWith("on")||Nt.has(t)}var z=new WeakMap;function Pt(e,t,r){let[n,i,s]=t;z.get(e)?.(),e.classList.add(n,i),r();let a=!1,o=requestAnimationFrame(()=>{if(a)return;e.classList.remove(i),e.classList.add(s)}),c=(d)=>{if(a||d&&d.target!==e)return;a=!0,z.delete(e),clearTimeout(l),globalThis.cancelAnimationFrame?.(o),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(n,i,s)};z.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let l=setTimeout(c,It(e))}function It(e){let t=0;try{let r=getComputedStyle(e);for(let n of["transition","animation"]){let[i,s]=["Duration","Delay"].map((o)=>String(r[n+o]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(r[n+"IterationCount"]).split(",").map((o)=>/inf/.test(o)?1/0:parseFloat(o)>=0?parseFloat(o):1);for(let o=0;o<i.length||o<s.length||o<a.length;o++){let c=i[o%i.length]*a[o%a.length]||0;t=Math.max(t,c+s[o%s.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Ot=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Mt=new Set(["lexxy-editor","trix-editor"]);function E(e){let t="",r=!1,n=(s)=>{if(r&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as At}from"@hotwired/stimulus";import{confirmResolver as Ae}from"phlex/reactive/confirm";function St(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:visit"])return;e["reactive:visit"]=function(){let t=this.getAttribute("data-url");if(t)window.Turbo.visit(t,{action:"advance"})}}function Et(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),n=this.getAttribute("target");if(!t||!n)return;let r=document.getElementById(n);if(r)r.setAttribute("data-reactive-token-value",t)}}function Tt(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=ve(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",i=n?document.getElementById(n):null;if(n&&!i){if(r)y("devtools",(s)=>s.missingRoot(n));return}ue(t,(s)=>hn(s,i),r?(s,a)=>y("devtools",(o)=>o.diagnoseStream(s,a,i)):void 0)}}function Ft(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){y("defer",(t)=>t.streamAction(this))}}var Se=!1,oe=null;function Lt(){if(Se)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Se=!0,document.addEventListener("turbo:before-stream-render",(e)=>{if(qt(e),kt(e),Nt(e),oe)oe(e,p.get("effects"));else p.get("effects")?.wrap(e)})}var D="reactive:streamed";function kt(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,i=r?.getAttribute?.("action"),s=/^(append|prepend|update)$/.test(i);if(typeof n!=="function"||!(s||/^(before|after|replace)$/.test(i)))return;let a=r.getAttribute("target"),o=r.getAttribute("targets"),c=new Set;for(let l of a?[document.getElementById(a)]:o?document.querySelectorAll(o):[]){let d=(s?l:l?.parentElement)?.closest?.('[data-controller~="reactive"]');if(d)c.add(d)}if(c.size===0)return;t.render=async(l)=>{await n(l);for(let d of c)if(d.isConnected)d.dispatchEvent(new Event(D))}}function le(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function de(e){try{return e.matches(":modal")}catch{return!1}}function He(e){if(!le(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||de(e))return;if(e.open)e.close();e.showModal()}function xt(e){if(le(e)&&e.open)e.close()}function j(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!de(r))He(r)}function Nt(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target;if(typeof n!=="function"||!r?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(i)=>{await n(i),j(document)}}var Ee=!1;function Rt(){if(Ee)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ee=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))j(t.target)}),document.addEventListener("turbo:morph",()=>j(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!le(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!de(n))return;e.delete(n),t.preventDefault(),n.close()})}var se=new WeakMap;function Ke(e,t,n,r){let i=se.get(e)??new Map;se.set(e,i);let s=(a,o)=>{i.delete(a),i.set(a,o)};if(t.endsWith("_class"))for(let a of n.classes??[])s(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))lt(n.name)||s(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(s("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))Ke(a,"set_attr",{name:"aria-expanded"})}}var Te=!1;function It(){if(Te)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Te=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of se.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var ze="data-reactive-image-fallback",k="data-reactive-image-state",ae="data-reactive-image-hidden",Y=null,ce="data-reactive-wrap-hidden";function Ve(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(ce,"")}function Ge(e){if(!e.hasAttribute(ce))return;e.removeAttribute("hidden"),e.removeAttribute(ce)}function x(e){if(e?.localName!=="img")return null;let t=e.getAttribute(ze);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var Ye=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function fe(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function Xe(e,t){let n=fe(e,t.alt);return n&&!n.contains(e)?n:null}function U(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(ae,"");if(t.wrap){let i=fe(e,t.wrap);if(i)Ve(i);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=Xe(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else z(e,t);e.setAttribute(k,n)}function z(e,t=x(e)){if(!t||e.getAttribute(k)==null)return;if(e.getAttribute(k)==="error"){if(e.hasAttribute(ae))e.removeAttribute("hidden");let n=fe(e,t.wrap);if(n)Ge(n);let r=Xe(e,t);if(r)r.hidden=!0}e.removeAttribute(k),e.removeAttribute(ae)}function Fe(e){let t=e.target,n=x(t);if(!n)return;if(e.type==="load")U(t,n,"loaded");else if(Ye(t))U(t,n,"error");else z(t,n)}function Pt(){if(Y)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;Y={error:Fe,load:Fe,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,i=n?.getAttribute?.(k);if(i==null||!r||!x(n))return;let s=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(s("src")&&s("srcset"))e.set(n,i)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let i=x(n);if(i)U(n,i,r)})}};for(let[t,n]of Object.entries(Y))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${ze}]`)??[]){if(!t.complete||!Ye(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(i)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&U(t,x(t)??{},i);if(t.naturalWidth>0)r("loaded");else if(typeof t.decode==="function")t.decode().then(()=>r("loaded"),()=>r("error"));else r("error")}}function Ze(e){oe=e}var C,X=null,Le="[data-reactive-editable][contenteditable=plaintext-only]";function Qe(){if(C===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",C=e.contentEditable==="plaintext-only"}catch{C=!1}return C}function q(e){if(e.matches?.(Le))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Le).forEach(q)}function Ot(){if(X||typeof document>"u"||typeof document.createElement!=="function")return;if(Qe())return;q(document),X=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")q(t.target);else t.addedNodes.forEach(q)}),X.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var ke=!1;function xe(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea"||e.hasAttribute("data-reactive-editable"))&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function Mt(){if(ke)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ke=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=xe(t);if(r)Dt(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(J.set(t,E(n)),!r)return;for(let{name:s}of[...t.attributes])if(!n.hasAttribute(s)&&s!=="contenteditable"&&s!==_)t.removeAttribute(s);for(let{name:s,value:a}of n.attributes)if(s!=="contenteditable"&&t.getAttribute(s)!==a)t.setAttribute(s,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let i=n.getAttribute("value");if(i==null)t.removeAttribute("value");else if(t.getAttribute("value")!==i)t.setAttribute("value",i)}),document.addEventListener("focusin",(e)=>be(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===_)&&xe(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(_)&&me(t)===pe(t))t.removeAttribute(_)})}var _="data-reactive-held",he='[data-controller~="reactive"]',W=null,T=new Map;function me(e){return e.hasAttribute("data-reactive-editable")?E(e):e.value}function pe(e){return e.hasAttribute("data-reactive-editable")?ye(e):e.defaultValue}function Ct(e){if(e.hasAttribute("data-reactive-editable"))return E(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Dt(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||T.has(e.closest(he)))return;let r=Ct(t);if(r===me(e))return e.removeAttribute(_);if(r===pe(e))return;e.setAttribute(_,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function $t(e){let t=[];for(let n of e.querySelectorAll(`[${_}]`)){if(n.closest(he)!==e)continue;let r=n.getAttribute("name");if(me(n)===pe(n))n.removeAttribute(_);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function et(e){for(let t of e.querySelectorAll(`[${_}]`))if(t.closest(he)===e)t.removeAttribute(_)}function Ne(e,t,n=!0){let r={root:e,streams:0,release:n},i=W;W=r;try{window.Turbo.renderStreamMessage(t)}finally{W=i}if(n&&r.streams===0)et(e)}function qt(e){let t=W,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(i)=>{T.set(t.root,(T.get(t.root)||0)+1);try{return await r(i)}finally{let s=T.get(t.root)-1;if(s)T.set(t.root,s);else T.delete(t.root);if(t.release)et(t.root)}}}var Wt="__materialize",Re=!1;function Bt(){if(Re)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Re=!0;let e=()=>{let t=document.documentElement;if(typeof t?.toggleAttribute!=="function")return;t.toggleAttribute("data-reactive-offline",globalThis.navigator?.onLine===!1)};e(),window.addEventListener("online",e),window.addEventListener("offline",e)}var jt="phlex-reactive:latency";function tt(){return typeof sessionStorage<"u"&&Boolean(sessionStorage.getItem(jt))}function ge(){if(typeof document>"u")return;if(!p.has("devtools")&&!w.get("devtools")[1])return;let e=document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development";if(e||tt())y("devtools",(t)=>e&&t.attach())}var nt="data-reactive-active",A=0;function rt(){if(A++,A===1)ot("reactive:busy")}function it(){if(A===0)return;if(A--,A===0)ot("reactive:idle")}function jn(){return A}function Un(){A=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(nt)}function ot(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(nt,A>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:A}}))}var st="data-reactive-requests";function at(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Ut(t))return;let n=Jt(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(st,JSON.stringify(n))}function Ut(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Jt(e){try{let t=JSON.parse(e.getAttribute(st));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Ie(){St(),Et(),Tt(),Ft(),Lt(),Mt(),Rt(),It(),Pt(),Ot(),Bt(),ge()}function Ht(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ct=Symbol.for("phlex-reactive.core");if(globalThis[ct])console.error("[phlex-reactive] the client was loaded twice. Import EITHER phlex/reactive/reactive_controller (the default, "+"everything in one file) OR phlex/reactive/core (features on demand), not both — each carries its own state.");globalThis[ct]=!0;var ut=!1;function Kt(){if(ut)return;if(typeof document>"u")return;let e=document.querySelectorAll('[data-controller~="reactive"]');if(!e||e.length===0)return;console.warn("[phlex-reactive] found "+e.length+' element(s) with data-controller="reactive" '+"but the reactive controller never connected. It is loaded but not registered — "+'add `application.register("reactive", ReactiveController)` (importmap) or import it into app/javascript/controllers/ for lazyLoadControllersFrom apps. See the README.')}if(typeof window<"u"&&typeof document<"u"){let e=()=>setTimeout(Kt,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var zt=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function lt(e){let t=String(e).toLowerCase();return t.startsWith("on")||zt.has(t)}var Z=new WeakMap;function Vt(e,t,n){let[r,i,s]=t;Z.get(e)?.(),e.classList.add(r,i),n();let a=!1,o=requestAnimationFrame(()=>{if(a)return;e.classList.remove(i),e.classList.add(s)}),c=(d)=>{if(a||d&&d.target!==e)return;a=!0,Z.delete(e),clearTimeout(l),globalThis.cancelAnimationFrame?.(o),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,i,s)};Z.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let l=setTimeout(c,Gt(e))}function Gt(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[i,s]=["Duration","Delay"].map((o)=>String(n[r+o]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((o)=>/inf/.test(o)?1/0:parseFloat(o)>=0?parseFloat(o):1);for(let o=0;o<i.length||o<s.length||o<a.length;o++){let c=i[o%i.length]*a[o%a.length]||0;t=Math.max(t,c+s[o%s.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Yt=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Xt=new Set(["lexxy-editor","trix-editor"]);function E(e){let t="",n=!1,r=(s)=>{if(n&&t&&!t.endsWith(`
|
|
2
2
|
`))t+=`
|
|
3
|
-
`;
|
|
4
|
-
`);else if(a.nodeType===1)i(a);if(o)
|
|
5
|
-
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var
|
|
6
|
-
`):e.value}function jt(e,t,r){if(r?.transition)Pt(e,r.transition,()=>e.hidden=t);else e.hidden=t}function V(e,t,r,n){if(jt(e,t,r),r?.expanded==null||typeof n!=="function")return;for(let i of n({...r,to:r.expanded}))i.setAttribute?.("aria-expanded",String(!t))}function G(e){if(!Ge(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function Ze(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let r=t?.localName==="img"?t.getAttribute("src"):null,n=(s)=>r?t.getAttribute(s):null;for(let s of["srcset","src"]){let a=n(s);if(a==null){if(e.hasAttribute(s))e.removeAttribute(s)}else if(e.getAttribute(s)!==a)e.setAttribute(s,a)}let i=n("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return r?i:!1}var Ut='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Jt(e){return e.querySelectorAll?.(Ut)?.[0]??null}function le(e){if(Array.isArray(e))return e;if(typeof e!=="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}var Te=Object.freeze({backspace:"Backspace",delete:"Delete",enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"}),Fe=Object.freeze(["meta","ctrl","alt","shift"]);function J(e,t,r){let n=e.split("+");for(let a of Fe)if(n.includes(a)!==Boolean(t[`${a}Key`]))return!1;let i=n.find((a)=>!Fe.includes(a));if(i===void 0||typeof t.key!=="string")return!0;let s=r&&Object.hasOwn(r,i)?r[i]:Object.hasOwn(Te,i)?Te[i]:/^[a-z0-9]$/.test(i)?i:null;return typeof s==="string"&&s.toLowerCase()===t.key.toLowerCase()}var Ht=(e)=>e&&typeof e==="object"?e.keys:String(e);function Y(e,t,r){let n=t.target;if(e?.inEditable!==!0&&(n?.isContentEditable||/^(input|textarea|select)$/.test(n?.localName)))return!1;let i=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return J(Ht(e).replace(/^mod\+/,`${i}+`),t,r)}function Kt(e){if(Array.isArray(e))return[{ops:e,legacy:!0}];if(e&&typeof e==="object")return[e];if(typeof e!=="string")return[];let t=e.trim();if(t.startsWith("["))return[{ops:le(t),legacy:!0}];let r=[];for(let n of t.split(" ")){if(n==="")continue;let i=null;try{i=JSON.parse(n)}catch{i=null}if(i&&typeof i==="object"&&!Array.isArray(i))r.push(i);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(n)} — skipped`)}return r}function Le(e,t,r){if(e.legacy)return!0;let n=e.on;if(typeof n!=="string"||n==="")return!1;let i=n.indexOf(".");if(t.type!==(i<0?n:n.slice(0,i)))return!1;if(Boolean(e.window)!==it(t.currentTarget))return!1;return i<0||r===null||J(n.slice(i+1),t,r)}function zt(e,t){let r=e.detail;if(r===void 0)return!0;if(r===null||typeof r!=="object"||Array.isArray(r))return!1;let n=t.detail;if(n===null||typeof n!=="object")return!1;return Object.keys(r).every((i)=>n[i]===r[i])}var ke=new WeakMap;function Vt(e,t,r){if(!r.once)return!1;let n=t.currentTarget??e.element,i=ke.get(e);if(!i)i=new WeakMap,ke.set(e,i);let s=i.get(n);if(!s)s=new Set,i.set(n,s);let a=t.params?.ops,c=(n===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(r);if(s.has(c))return!0;return s.add(c),!1}var xe=new WeakMap;function Gt(e,t){if(e===null||typeof e!=="object")return!1;let r=e.params?.ops,n=typeof r==="string"?r:JSON.stringify(r??null),i=xe.get(e);if(!i)i=new WeakMap,xe.set(e,i);let s=i.get(t);if(!s)s=new Map,i.set(t,s);let a=s.get(e.currentTarget);if(!a)a=new Set,s.set(e.currentTarget,a);if(a.has(n))return!0;return a.add(n),!1}function te(e,t,r){for(let n of e){if(!Array.isArray(n))continue;let[i,s={}]=n;if(!Object.hasOwn(Ae,i)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(i)} — skipped`);continue}let a=t(s);if(a.length===0&&r)r(i,s);for(let o of a)if(Ae[i](o,s,t),s?.keep===!0)Ce(o,i,s,t)}}function Yt(e,t){let r=e.to;if(t){if(r==="@root")return[t];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...t.querySelectorAll(r)]}if(typeof r!=="string"||r===""||r==="@root")return[];return[...document.querySelectorAll(r)]}function Xt(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Qe(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function Zt(e){return(e.getAttribute?.("data-action")??"").includes("reactive#trackDirty")||e.getAttribute?.("data-reactive-clipboard")!=null||e.querySelector?.('[data-action*="reactive#trackDirty"],[data-reactive-clipboard]')!=null}function Qt(e){return["show-targets","group-targets","on-complete","filter-input","tags-field"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)||(e.querySelectorAll?.("[data-reactive-show-field], [data-reactive-show]")??[]).length>0||e.querySelector?.("[data-reactive-nested-json], [data-reactive-nested-list], [data-reactive-confirm-when-param], [data-reactive-enable], [data-reactive-select-all], [data-reactive-count], [data-reactive-editable], [data-reactive-media]")!=null}function er(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function tr(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function et(e){return e.getAttribute?.("data-reactive-presence")!=null}var rr=[["persist",[Xt,null,null,!0]],["defer",[Qe,null]],["form",[Zt,null]],["bindings",[Qt,null,null,!0]],["compute",[er,null,null,!0]],["sortable",[tr,null]],["presence",[et,null]],["effects",[(e)=>["enter","update","exit"].some((t)=>e.getAttribute?.(`data-reactive-effect-${t}`)!=null),null]],["hints",[(e)=>e.querySelector?.("[data-reactive-optimistic-param], [data-reactive-busy-param], [data-reactive-loading-param]")!=null,null]],["devtools",[(e)=>e.getAttribute?.("data-reactive-debug")==="true",null]]],w=new Map(rr),Re=new Map,p=new Map,nr=new Map;function y(e,t,r){tt.set(e,[t,r]),ir(e)}var tt=new Map;function ir(e){let t=w.get(e),[r,n]=tt.get(e);t[1]=r,t[2]=n}function Tr(e,t){t.install?.(N),p.set(e,t),nr.set(e,t)}function rt(e){let t=[];for(let[r,[n]]of w){if(!n||p.has(r))continue;try{if(e.some((i)=>n(i)))t.push(r)}catch{}}return t}function nt(e){return R(e).catch((t)=>j(e,"load",t))}function R(e){let t=Re.get(e);if(!t)t=(w.get(e)[1]??(()=>Promise.reject(Error("this entry has no way to import it"))))().then((n)=>(n.install?.(N),p.set(e,n),n)),Re.set(e,t);return t}var Ne=new Set;function j(e,t,r){let n=e+t;if(Ne.has(n))return;Ne.add(n),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,r)}function b(e,t){let r=p.get(e);if(r)return t(r);R(e).then(t,(n)=>j(e,"load",n))}var sr=1e4;function X(){let e=Number(globalThis.document?.head?.querySelector?.('meta[name="phlex-reactive-feature-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:sr}function Fr(){return[...w.keys()]}var Pe=Promise.resolve();function Ie(e,t,r){let n=N.waiting.get(e);if(n&&n[t]===r)delete n[t]}var N={enter:je,exit:Ue,count:Ke,text:E,served:ue,waiting:new WeakMap};var P=Symbol.for("phlex-reactive.early"),or=1e4,ar=1500,it=(e)=>e!=null&&(e===globalThis.window||e.window===e);function Z(){return globalThis[P]??={queue:[],connected:new WeakSet},globalThis[P]}function cr(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:or}function ur(e){let t={};for(let{name:r,value:n}of Array.from(e.attributes??[])){let i=/^data-reactive-(.+)-param$/i.exec(r);if(!i)continue;let s;try{s=JSON.parse(n)}catch{s=n}t[i[1].replace(/[-_]([a-z0-9])/g,(a,o)=>o.toUpperCase())]=s}return t}function lr(e,t,r){return{[P]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:r?t.ownerDocument.defaultView:t,params:ur(t),key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,button:e.button,submitter:e.submitter,bubbles:e.bubbles,timeStamp:e.timeStamp,defaultPrevented:e.defaultPrevented,preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var U=new WeakMap;function dr(e,{token:t,type:r,method:n,filter:i,win:s},a){let o=U.get(e);if(!o)U.set(e,o=new Map);let c=s?`${t} ${a}`:t;if(o.has(c))return!1;return o.set(c,{type:r,method:n,filter:i,win:s,params:a,armed:!0}),!0}function Oe(e,t,r,n){if(e?.[P])return!1;let i=it(e?.currentTarget),s=i?n:e?.currentTarget,a=hr(e,s,i?`@${t}`:t),o=U.get(s),c=i&&JSON.stringify(e.params);for(let l of o?.values()??[]){if(!l.armed||l.method!==t||l.type!==e.type||Boolean(l.win)!==i)continue;if(i&&l.params!==c)continue;if(l.filter&&!J(l.filter,e,r))continue;return l.armed=!1,!0}return a}var q=new WeakMap;function fr(e,t,r){let n=q.get(e);if(!n)q.set(e,n=new Map),setTimeout(()=>q.delete(e));let i=n.get(t)??{};n.set(t,i),i[r]=(i[r]??0)+1}function hr(e,t,r){let n=e&&q.get(e)?.get(t);if(!n?.[r])return!1;return n[r]-=1,!0}class st extends at{static values={token:String};#_;#w=new Map;#l=new Map;#ee;#k;#j;#x=0;#d=new Map;#R=new WeakMap;#t;featuresReady=Pe;#r=new Map;#N=new Set;#f=!1;#n=null;#h=new Map;#A=new Map;#m=new Map;#p=0;#U;#Ie=0;#Oe=0;connect(){if(Ve=!0,Z().connected.add(this.element),this.element.id==="")console.warn("[phlex-reactive] a reactive root has no id; its next-action token can't self-match "+"and may fall back to the first token in the response → a silent HTTP 403 on the NEXT action. "+"Put id: on the SAME element as reactive_attrs — use div(**reactive_root) (emits id + token together), "+"or div(id:, **reactive_attrs). The id: must NOT be on a child. See the README.");if(this.element.getAttribute?.("data-reactive-token-value")!=null||Qe(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===M)this.#K();this.#J(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(M,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(ce),this.#p++,this.featuresReady=Pe,this.#J(),B(this.element),this.#ie()}#Me(e){}#Ce(e,t,r,n){}#De(){}#$e(e,t){}#J(e){{let t=this.#p,r=[];for(let[s,[a]]of w){if(!a||this.#N.has(s))continue;let o=p.get(s);if(o&&!o.connect)continue;try{if(a(this.element))r.push(s)}catch(c){this.#g(s,"detect",c)}}if(r.length===0)return;for(let s of r)this.#N.add(s);if(!this.#f&&r.every((s)=>p.has(s))){for(let s of r)this.#P(t,s,p.get(s),e);return}for(let s of r){let a=this.#te(t,s),o=[];for(let l of w.keys()){if(l===s)break;if(this.#m.has(l))o.push(this.#m.get(l))}let c=Promise.all(o).then(()=>a).then((l)=>l&&this.#P(t,s,l,e));if(this.#m.set(s,c),w.get(s)[3])this.#n=c}let n=this.#n;n?.then(()=>{if(this.#n===n)this.#n=null}),this.#f=!0;let i=Promise.all(this.#m.values()).then(()=>{if(this.featuresReady===i)this.#f=!1});this.featuresReady=i}}#te(e,t){{let r=()=>e===this.#p;return this.#re(t),new Promise((n)=>{let i=!1,s=setTimeout(()=>{if(this.#h.delete(s),i=!0,r())this.#g(t,"timeout",Error(`not loaded after ${X()} ms`));n(null)},X());this.#h.set(s,n);let a=()=>{clearTimeout(s),this.#h.delete(s)};R(t).then((o)=>{if(a(),i)queueMicrotask(()=>this.#P(e,t,o));else n(o)},(o)=>{if(a(),r())this.#g(t,"load",o);n(null)})})}}#re(e){{let t=w.get(e)[2];if(!t)return;let r={};try{this.#A.set(e,[t(this.element,r),r]),N.waiting.set(this.element,{...N.waiting.get(this.element),[e]:r})}catch(n){this.#g(e,"detect",n)}}}#H(e,t){{let[r,n]=this.#A.get(e)??[];if(this.#A.delete(e),!t)Ie(this.element,e,n);try{r?.()}catch(i){console.error(`[phlex-reactive] the "${e}" feature module failed to stop waiting`,i)}return n}}#P(e,t,r,n){{if(e!==this.#p)return;let i=this.#H(t);try{r.connect?.(this,this.#e(),n,i),this.#r.set(t,r)}catch(s){this.#g(t,"connect",s)}}}#e(){return this.#U??={emit:(e,t,r)=>this.#s(e,t,r),reseed:()=>this.#K(),proceed:(e,t,r,n)=>this.#O(e,t,r,0,0,null,n),forgetToken:()=>{this.#_=void 0},owns:(e)=>this.#F(e),ownership:()=>this.#D(),opTargets:(e)=>this.#W(e),diagnose:(e,t)=>this.#B(e,t),applyOps:(e,t)=>te(e,(r)=>this.#W(t!=null&&r.to==null?{...r,to:t}:r),(r,n)=>this.#B(`client op "${r}"`,n)),listnavOptions:(e)=>this.#y(e),collectFields:()=>this.#X(),plain:$e,text:E,served:ue,copyMedia:Ze,confirm:(e,t)=>Promise.resolve().then(()=>fe(e,t)).catch(()=>!1)},this.#U}#K(){this.#r.get("form")?.reseed(this),this.#r.get("bindings")?.reseed(this),this.#r.get("compute")?.seed(this)}#g(e,t,r){if(j(e,t,r),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:r})}#ne(){{this.#p++;for(let[t,r]of this.#h)clearTimeout(t),r(null);this.#h.clear();for(let t of[...this.#A.keys()]){let r=this.#H(t,!0),n=this.element;b(t,(i)=>{i.abandon?.(n,r),Ie(n,t,r)})}this.#N.clear(),this.#m.clear(),this.#f=!1,this.#n=null;let e=[...this.#r];this.#r.clear();for(let[t,r]of e)try{r.disconnect?.(this,this.#e())}catch(n){console.error(`[phlex-reactive] the "${t}" feature module failed to disconnect`,n)}}}#ie(){if(this.element.setAttribute?.("data-reactive-connected",""),this.element.isConnected)this.element.dispatchEvent?.(new CustomEvent("reactive:connect",{bubbles:!0,composed:!0,detail:{id:this.element.id}}));this.#se()}#I=new Set;#se(){let{queue:e}=Z();if(e.length===0)return;let t=[];for(let i=e.length-1;i>=0;i--){let{root:s}=e[i];if(s===this.element||!s.isConnected)t.unshift(...e.splice(i,1))}let r=cr(),n=new Map;for(let i of t){let s=n.get(i.event)??[new Set,new Set];n.set(i.event,s);let a=s[+!!i.win];if(a.has(i.el))continue;a.add(i.el);let o=i.win?Math.min(ar,r):r,c=i.root!==this.element?"its root left the page before a controller connected":performance.now()-i.at>o?`it is older than the ${o} ms ${i.win?"window-trigger":"early-event"} TTL`:i.el.isConnected&&this.element.contains(i.el)?null:"its element left the root before the controller connected";if(c){if(this.#q())console.warn(`[phlex-reactive] dropped an early "${i.event.type}" trigger: ${c}`);continue}this.#oe(i)}}#oe({event:e,el:t,descs:r,win:n}){let i=lr(e,t,n),s=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),o=n?this.element:t;for(let c of r){if(!a.includes(c.token))continue;if(c.filter&&!J(c.filter,e,s))continue;if(/#\w+.*:once\b/.test(c.token)){if(!dr(o,c,n&&JSON.stringify(i.params)))continue;this.#I.add(o)}if(fr(e,o,n?`@${c.method}`:c.method),c.method==="runOps")this.runOps(i);else this.dispatch(i)}}disconnect(){if(this.#ne(),this.#de(),this.#he(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(M,this.#t);Z().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#I)U.delete(e);this.#I.clear()}dispatch(e){let t=e.params?.shortcut;if(t!=null&&!Y(t,e,this.application?.schema?.keyMappings))return;if(Oe(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:r,params:n,debounce:i,throttle:s,confirm:a,confirmWhen:o,outside:c,window:l,optimistic:d}=e.params;if(!r)return;let m=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let f=e.currentTarget??e.target;if((t!=null||!l)&&!this.#Te(d,f))e.preventDefault();if(r===Et){let S=()=>{{let h=this.#r.get("defer");if(h)return h.materialize(this)}if(this.tokenValue)return this.#O(f,r,"{}")};return this.#f?this.featuresReady.then(S):S()}let g=this.#z(a,o),v=()=>this.#O(f,r,n,i,s,d,m);if(!g)return v();if(g instanceof Promise)return g.then((S)=>S?this.#S(S,f,v):v());this.#S(g,f,v)}#S(e,t,r){return Promise.resolve().then(()=>fe(e,{el:t})).catch(()=>!1).then((n)=>{if(n)r()})}#z(e,t){if(e)return e;if(!t)return null;{let r=p.get("bindings");if(r)return r.confirmMessage(this,this.#e(),t);return this.#V("bindings").then((n)=>n&&n.confirmMessage(this,this.#e(),t))}}#V(e){{let t;return Promise.race([R(e).catch((r)=>(j(e,"load",r),null)),new Promise((r)=>t=setTimeout(()=>r(null),X()))]).finally(()=>clearTimeout(t))}}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Y(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Oe(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Gt(e,this))return;let r=e.params??{},n=e.currentTarget??e.target,i=Kt(r.ops),s=i.filter((o)=>Le(o,e,null)),a=s.length<=1?s:s.filter((o)=>Le(o,e,this.application?.schema?.keyMappings));if(a.length===0&&i.length>0){if(this.#q())this.#v((o)=>o.noBinding(this,e));return}for(let o of a){if(o.outside&&e[P])continue;if(!zt(o,e))continue;if(o.shortcut!=null&&!Y(o.shortcut,e,this.application?.schema?.keyMappings))continue;if(Vt(this,e,o))continue;this.#ae(o.legacy?{...r,ops:o.ops}:o,e,n)}}#ae({ops:e,confirm:t,confirmWhen:r,outside:n,window:i,shortcut:s},a,o){if(n&&this.element.contains(a.target))return;if(s!=null||!i)a.preventDefault();let c=this.#z(t,r),l=()=>this.#Ee(this.#Se(e));if(!c)return l();if(c instanceof Promise)return c.then((d)=>d?this.#S(d,o,l):l());this.#S(c,o,l)}recompute(e){return p.get("compute")?.recompute(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#y(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return this.#b("tagsAdd",e)}tagsPick(e){return this.#b("tagsPick",e)}tagsRemove(e){return this.#b("tagsRemove",e)}nestedAdd(e){return this.#b("nestedAdd",e)}nestedRemove(e){return this.#b("nestedRemove",e)}syncNestedJson(e){return p.get("bindings")?.syncNestedJson(this,this.#e(),e)}#b(e,t){{let r=p.get("bindings");if(r)return r[e](this,this.#e(),t);t?.preventDefault?.();let n={currentTarget:t?.currentTarget??null,target:t?.target??null,preventDefault(){}};return b("bindings",(i)=>i[e](this,this.#e(),n))}}trackDirty(){(this.#r.get("form")??p.get("form"))?.scan(this,this.#e())}listnavNext(e){this.#E(e,(t,r)=>t<0?0:(t+1)%r)}listnavPrev(e){this.#E(e,(t,r)=>t<0?r-1:(t-1+r)%r)}listnavFirst(e){this.#E(e,()=>0)}listnavLast(e){this.#E(e,(t,r)=>r-1)}listnavPick(e){let t=this.#y(e),r=t.findIndex((n)=>n.hasAttribute("data-reactive-highlighted"));if(r<0)return;e.preventDefault(),t[r].click()}listnavClose(e){for(let t of this.#y(e))t.removeAttribute("data-reactive-highlighted")}#E(e,t){let r=this.#y(e);if(!r.length)return;e.preventDefault();let n=this.#ce(e),i=globalThis.document?.activeElement,s=n?r.findIndex((o)=>o===i||i!=null&&o.contains?.(i)):r.findIndex((o)=>o.hasAttribute("data-reactive-highlighted")),a=r[t(s,r.length)];if(n)a.focus?.();else{for(let o of r)o.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ce(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#y(e){let r=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!r)return[];let n=this.#D();return Array.from(this.element.querySelectorAll(r)).filter((i)=>!i.hidden&&n(i))}#O(e,t,r,n,i,s,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#Z(r),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(n)||0;if(c>0)return this.#le(e,c,t,r,s,a);let l=Number(i)||0;if(l>0)return this.#fe(e,l,t,r,s,a);return this.#T(t,r,s,e,a)}#T(e,t,r,n,i){let s={inverse:null,undo:[],resurrect:null},a=this.#Fe(e,n,s),o=Boolean(r||i),c=(f)=>{if(!o||!f)return;let g=this.#e();if(s.inverse=f.optimistic(this,g,r,n),s.undo.push(...f.busy(this,g,i,n)),this.#C())s.resurrect=f.resurrection(this,g,r,n)},l=p.get("hints");if(!o||l)c(l);let d=()=>this.#be(e,t,s,a),m=()=>this.#n?this.#n.then(d):d();return this.queue=(this.queue??Promise.resolve()).then(()=>o&&!l?this.#ue().then(c).then(m):m()),this.queue}#ue(){return this.#V("hints")}#le(e,t,r,n,i,s){this.#M(e);let a=()=>{this.#M(e),this.#T(r,n,i,e,s)},o=setTimeout(a,t);e?.addEventListener?.("blur",a,{once:!0}),this.#w.set(e,{timer:o,flush:a})}#M(e){let t=this.#w.get(e);if(!t)return;clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),this.#w.delete(e)}#de(){for(let e of[...this.#w.keys()])this.#M(e)}#fe(e,t,r,n,i,s){let a=this.#l.get(e)??new Map;if(a.has(r))return;let o=setTimeout(()=>{if(a.delete(r),a.size===0)this.#l.delete(e)},t);return a.set(r,o),this.#l.set(e,a),this.#T(r,n,i,e,s)}#he(){for(let e of this.#l.values())for(let t of e.values())clearTimeout(t);this.#l.clear()}#s(e,t,{cancelable:r=!1}={}){let n=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:r,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(n),n}#o(e,t,r,n){let i=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#T(e,t)};this.#s("reactive:error",{action:e,params:r,...n,retry:i})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#me(){this.element?.removeAttribute?.("data-reactive-error")}#pe(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",r=document.getElementById(t);if(!r)return;r.appendChild(e.content.cloneNode(!0))}#ge(){{let e=p.get("devtools");if(e)return e.delay();if(Be())return R("devtools").then((t)=>t.delay(),()=>{})}}#C(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#G(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#be(e,t,r,n){let{fields:i,files:s}=this.#X(),a=this.#Z(t),o={...i,...a},c=this.#a,l=s.length>0,d=l?this.#we(c,e,o,s):JSON.stringify({token:c,act:e,params:o}),m=this.#C()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(i),encoding:l?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#G()}:null;await this.#ge();try{if(navigator.onLine===!1){this.#c(r.inverse),this.#i("offline"),this.#o(e,t,o,{kind:"offline"});return}let f;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Ne()};if(!l)h["Content-Type"]="application/json";let L=this.#Pe();if(L)h["X-Pgbus-Connection"]=L;let I=et(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(I)h["X-Reactive-Presence"]=I;let de=At(this.element);if(de)h["X-Reactive-Held"]=de;Ke("action"),f=await fetch(this.#xe(),{method:"POST",headers:h,body:d,credentials:"same-origin",signal:AbortSignal.timeout(this.#Re())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#c(r.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#o(e,t,o,{kind:"timeout"});return}this.#pe(),this.#i("network"),this.#o(e,t,o,{kind:"network"});return}if(m)m.status=f.status;if(f.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#c(r.inverse),this.#i("redirected"),this.#o(e,t,o,{kind:"redirected",status:f.status});return}if(!f.ok){let h=await f.text();if(console.error(`[phlex-reactive] action failed: HTTP ${f.status}`,h),this.#c(r.inverse),(f.headers.get("Content-Type")||"").includes("turbo-stream")){let L=this.#Y(h);if(this.#a=L??this.#a,m)this.#v((I)=>I.recordBody(m,h,L));ve(this.element,h,!1)}this.#i("http"),this.#o(e,t,o,{kind:"http",status:f.status,body:h});return}let g=f.headers.get("Content-Type")||"";if(!g.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${g}" — no update applied`),this.#c(r.inverse),this.#i("content-type"),this.#o(e,t,o,{kind:"content-type",status:f.status});return}let v=await f.text(),S=this.#Y(v);if(this.#a=S??this.#a,m)this.#v((h)=>h.recordBody(m,v,S));if(ve(this.element,v),r.resurrect)queueMicrotask(r.resurrect);return this.#me(),this.#s("reactive:applied",{action:e,params:o,html:v}),v}catch(f){console.error("[phlex-reactive] action error",f),this.#c(r.inverse),this.#s("reactive:error",{action:e,params:o,kind:"apply"})}finally{if(n?.(),m)this.#v((f)=>f.trace(this,{...m,ms:this.#G()-m.started}))}}get#a(){return this.#_??this.tokenValue}set#a(e){this.#_=e}tokenValueChanged(){this.#_=void 0}#Y(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:r,self:n}=this.#ye(t),i=e.match(r);if(i)return i[1];let s=e.match(n);if(s)return s[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#ye(e){let t=this.#j;if(t&&t.id===e)return t;let r=xt(e);return this.#j={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${r}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${r}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#F(e){return e.closest('[data-controller~="reactive"]')===this.element}#D(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#F(t)}#X(){let e={},t=[],r=this.#D(),n=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((o)=>{if(!r(o))return;if(o.type==="file")for(let c of o.files??[])t.push({name:o.name,file:c,multiple:o.multiple});else n.push(o)});let i=[];this.element.querySelectorAll(`[name]${Ot}`).forEach((o)=>{if(r(o))i.push(o)});let s=this.#ve(n),a=this.#_e(n);for(let o of n)if(s.has(o.name)){let c=e[o.name]??(e[o.name]=[]);if(o.type==="checkbox"||o.type==="radio"){if(o.checked)c.push(o.value)}else if(o.type==="hidden"){if(!a.has(o.name))c.push(o.value)}else if(o.multiple&&o.options){for(let l of o.options)if(l.selected)c.push(l.value)}else c.push(o.value)}else if(o.type==="checkbox")e[o.name]=o.checked;else if(o.type==="radio"){if(o.checked)e[o.name]=o.value}else e[o.name]=o.value;return i.forEach((o)=>{let c=o.getAttribute("name");if(!c)return;let l=o.getAttribute("data-reactive-editable")!=null?E(o):o.value??o.textContent??o.innerHTML??"",d=e[c];if(String(c).endsWith("[]")&&!Ct(o))return;if(String(c).endsWith("[]")&&(d===void 0||Array.isArray(d))){(Array.isArray(d)?d:e[c]=[]).push(l);return}if(d==null||d==="")e[c]=l}),{fields:e,files:t}}#ve(e){let t=new Set;for(let r of e){if(r.type==="radio")continue;if(String(r.name).endsWith("[]"))t.add(r.name)}return t}#_e(e){let t=new Set;for(let r of e)if(r.type==="checkbox")t.add(r.name);return t}#we(e,t,r,n){let i=new FormData;i.append("token",e),i.append("act",t);let s=[];for(let[o,c]of Object.entries(r))if(Array.isArray(c)&&String(o).endsWith("[]"))if(c.length===0)s.push(String(o).slice(0,-2));else{let l=`${this.#L(o)}[]`;for(let d of c)i.append(l,String(d))}else this.#$(i,this.#L(o),c);for(let o of s)i.append("empty_groups[]",o);let a=this.#Ae(n);for(let{name:o,file:c,multiple:l}of n){let m=l||a.has(o)?`${this.#L(o)}[]`:this.#L(o);i.append(m,c,c.name)}return i}#L(e){let t=String(e),r=t.indexOf("[");if(r===-1)return`params[${t}]`;return`params${[t.slice(0,r),...t.slice(r).match(/[^\[\]]+/g)??[]].map((i)=>`[${i}]`).join("")}`}#$(e,t,r){if(r==null)e.append(t,"");else if(Array.isArray(r))r.forEach((n,i)=>this.#$(e,`${t}[${i}]`,n));else if(typeof r==="object")for(let[n,i]of Object.entries(r))this.#$(e,`${t}[${n}]`,i);else e.append(t,String(r))}#Ae(e){let t=new Map;for(let{name:r}of e)t.set(r,(t.get(r)??0)+1);return new Set([...t].filter(([,r])=>r>1).map(([r])=>r))}#Z(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Se(e){return le(e)}#Ee(e){te(e,(t)=>this.#W(t),(t,r)=>this.#B(`client op "${t}"`,r))}#q(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#C()}#B(e,t){if(!this.#q())return;this.#v((r)=>r.diagnose(this,e,t))}#v(e){b("devtools",e)}#W(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((r)=>this.#F(r))}#Te(e,t){if(e?.checked!=="keep")return!1;let r=t?.type;return r==="checkbox"||r==="radio"}#c(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Fe(e,t,r){this.#Le(e,t),je();let n=!1;return()=>{if(n)return;n=!0,this.#ke(e,t),Ue();for(let i of r.undo)i()}}#Le(e,t){if(this.#u(t,e,1),this.#u(this.element,e,1),this.#d.set(e,(this.#d.get(e)??0)+1),this.#x++===0)this.element.setAttribute("aria-busy","true");for(let r of this.#Q(e))this.#u(r,e,1)}#ke(e,t){this.#u(t,e,-1),this.#u(this.element,e,-1);let r=(this.#d.get(e)??1)-1;if(r<=0)this.#d.delete(e);else this.#d.set(e,r);if(--this.#x<=0)this.#x=0,this.element.removeAttribute("aria-busy");for(let n of this.#Q(e))this.#u(n,e,-1)}#u(e,t,r){if(!e||typeof e.getAttribute!=="function")return;let n=this.#R.get(e)??new Map,i=(n.get(t)??0)+r;if(i<=0)n.delete(t);else n.set(t,i);if(n.size===0){this.#R.delete(e),e.removeAttribute("data-reactive-busy");return}this.#R.set(e,n),e.setAttribute("data-reactive-busy",[...n.keys()].join(" "))}#Q(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((r)=>r.getAttribute("data-reactive-busy-on")===e&&this.#F(r))}#xe(){return this.#ee??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Re(){if(this.#k!=null)return this.#k;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#k=Number.isFinite(t)&&t>0?t:30000}#Ne(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Pe(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)we();else document.addEventListener("turbo:load",we,{once:!0});y("persist",()=>import("phlex/reactive/features/persist"),mr);y("defer",()=>import("phlex/reactive/features/defer"));y("form",()=>import("phlex/reactive/features/form"));y("bindings",()=>import("phlex/reactive/features/bindings"));y("compute",()=>import("phlex/reactive/features/compute"),pr);y("sortable",()=>import("phlex/reactive/features/sortable"));y("presence",()=>import("phlex/reactive/features/presence"));y("effects",()=>import("phlex/reactive/features/effects"));y("hints",()=>import("phlex/reactive/features/hints"));y("devtools",()=>import("phlex/reactive/features/devtools"));ae();function mr(e,t){let r=()=>{t.edited=!0},n=(s)=>{let a=s.target;if(s.detail?.success&&a?.tagName==="FORM"&&a.contains?.(e))t.submitted=!0},i=["input","change","lexxy:change","trix-change"];for(let s of i)e.addEventListener?.(s,r);return document.addEventListener("turbo:submit-end",n),()=>{for(let s of i)e.removeEventListener?.(s,r);document.removeEventListener("turbo:submit-end",n)}}function pr(e,t){let r=()=>{t.edited=!0};return e.addEventListener?.("input",r),e.addEventListener?.("change",r),()=>{e.removeEventListener?.("input",r),e.removeEventListener?.("change",r)}}var gr=1000,F=null,ot,H=new Set;function br(e){return nt(e).then((t)=>{if(e!=="effects")return;ot=t,t?.sweep()})}De((e,t)=>{let r=e.detail,n=r?.render;if(typeof n!=="function")return;let i=r.newStream??e.target,s=rt(yr(i)).filter((o)=>!H.has(o));if(!t&&!H.has("effects")&&vr(i))s.push("effects");if(s.length===0&&!F)return t?.wrap(e);if(s.length>0){for(let c of s)H.add(c);let o=F=Promise.race([Promise.all([F,...s.map(br)]),new Promise((c)=>setTimeout(c,gr))]).then(()=>{if(F!==o)return;F=null,H.clear()})}let a=F;r.render=async(o)=>{await a;let c={target:e.target,detail:{newStream:r.newStream,render:n}};(t??ot)?.wrap(c),await c.detail.render(o)}});function yr(e){let t=e?.querySelector?.("template")?.content;if(!t)return[];let r=[...t.querySelectorAll?.('[data-controller~="reactive"]')??[]];for(let n of t.children??[])if(n.matches?.('[data-controller~="reactive"]')&&!r.includes(n))r.unshift(n);return r.push(t),r}function vr(e){return Boolean(e?.hasAttribute?.("data-reactive-effect")||document.getElementById?.(e?.getAttribute?.("target"))?.matches?.("[data-reactive-effect-update],[data-reactive-effect-exit]")||e?.querySelector?.("template")?.content?.querySelector?.("[data-reactive-effect-enter],[data-reactive-dismiss-after]")||document.querySelector?.("[data-reactive-dismiss-after]:not([data-reactive-dismiss-scheduled])"))}var Pr=st;export{We as ACTIVE_ATTR,Ot as EDITOR_SELECTOR,Mt as EDITOR_TAGS,He as REQUESTS_ATTR,Rt as checkReactiveRegistration,Ke as countReactiveRequest,Pr as default,E as editableValue,je as enterReactiveActivity,xt as escapeRegExp,Ue as exitReactiveActivity,nt as loadReactiveFeature,De as onReactiveStreamWithoutEffects,Sr as reactiveActivityCount,Fr as reactiveFeatureNames,we as registerReactiveActions,dt as registerReactiveDefer,ae as registerReactiveDev,ft as registerReactiveDismiss,ft as registerReactiveEffects,Tr as registerReactiveFeature,y as registerReactiveFeatureLoader,lt as registerReactiveJs,bt as registerReactiveKeep,gt as registerReactiveModals,vt as registerReactiveMorphFocus,Tt as registerReactiveOffline,yt as registerReactivePlaintext,ft as registerReactiveStreamRender,ut as registerReactiveToken,ct as registerReactiveVisit,Er as resetReactiveActivity,ue as serverText,rt as unloadedFeaturesFor};
|
|
3
|
+
`;n=!1,t+=s},i=(s)=>{for(let a of s.childNodes){let o=/^(div|p|li)$/.test(a.localName);if(o)n=!0;if(a.nodeType===3)a.data&&r(a.data);else if(a.localName==="br")r(`
|
|
4
|
+
`);else if(a.nodeType===1)i(a);if(o)n=!0}};return i(e),t=t.replace(/\r\n?/g,`
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var J=new WeakMap;function be(e){if(e?.hasAttribute?.("data-reactive-editable")&&!J.has(e))J.set(e,E(e))}function ye(e){return be(e),J.get(e)}function Zt(e){return Xt.has(e.localName)?typeof e.value==="string":!0}var Pe=Object.freeze({show:(e,t,n)=>ee(e,!1,t,n),hide:(e,t,n)=>ee(e,!0,t,n),toggle:(e,t,n)=>ee(e,!e.hidden,t,n),add_class:(e,t)=>e.classList.add(...t.classes??[]),remove_class:(e,t)=>e.classList.remove(...t.classes??[]),toggle_class:(e,t)=>(t.classes??[]).forEach((n)=>e.classList.toggle(n)),set_attr:(e,t)=>{if(te(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(te(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!te(t.name))return;if(Array.isArray(t.values)){let[n,r]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===n?r:n)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>an(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>He(e),close_dialog:(e)=>xt(e),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},copy_media:(e,t,n)=>{let r=null;try{r=n({...t,to:t.from})[0]??null}catch{}mt(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)y("bindings",(i)=>i.checkGroup(r,t.group,t.checked))},presence:(e,t)=>y("presence",(n)=>n.set(e,t.state)),dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,n)=>{let r=Qt(e);if(!r)return;let i=null;if(t?.submitter!=null&&typeof n==="function"){if(i=n({...t,to:t.submitter})[0]??null,!(i?.form===r&&(i.type==="submit"||i.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),i=null}i?r.requestSubmit?.(i):r.requestSubmit?.()},paste_into:(e)=>en(e),preview_file:(e,t,n)=>tn(e,t,n),set_value:(e,t)=>ht(e,String(t.value??"")),persist_state:(e,t)=>y("persist",(n)=>n.writeState(e,t.state)),persist_clear:(e)=>y("persist",(t)=>t.clearRoot(e))});function Qt(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function en(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,ft(e),e.focus?.()}).catch(()=>{})}var N=new Map,R=null;function tn(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Q(`reads an input[type=file], not <${e?.localName}>`);let r=typeof n==="function"?n({...t,to:t.into})[0]:null;if(r?.tagName!=="IMG")return Q(`paints an <img>, and ${JSON.stringify(t.into)} is ${r?`a <${r.localName}>`:"not on the page"}`);let i=[...t.valid===!0&&e.validity?.valid===!1?[]:e.files??[]],s=nn(e,t.accept),a=i.filter((d)=>typeof d?.type==="string"&&s(d)),o=a.find((d)=>d.type.startsWith("image/")),c=i.length>0&&a.length===0?"type":null;if(o&&Number.isInteger(t.max_bytes)&&o.size>t.max_bytes)c="size";let l=c==="size"?o:i[0];if(c)o=null;if(dt(r),o){let d=URL.createObjectURL(o);N.set(r,d),r.setAttribute("src",d),rn()}else r.removeAttribute("src");if(z(r),t.wrap!=null){let d=n({...t,to:t.wrap});if(d.length===0)Q(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let h of d)o?Ge(h):Ve(h)}if(t.name!=null)for(let d of n({...t,to:t.name}))d.textContent=o?o.name:"";if(c)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:{reason:c,file:l}}))}function nn(e,t){let n=String((t===!0?e.getAttribute("accept"):typeof t==="string"&&t)||"").toLowerCase().split(",").map((r)=>r.trim()).filter(Boolean);if(n.length===0)return(r)=>r.type.startsWith("image/");return(r)=>{let i=r.type.toLowerCase();return n.some((s)=>s[0]==="."?String(r.name).toLowerCase().endsWith(s):s.endsWith("/*")?i.startsWith(s.slice(0,-1)):i===s)}}function Q(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function dt(e){let t=N.get(e);if(t===void 0)return;if(N.delete(e),URL.revokeObjectURL(t),N.size===0)R?.disconnect(),R=null}function rn(){if(R||typeof MutationObserver!=="function"||!document?.documentElement)return;R=new MutationObserver(()=>{for(let[e,t]of N)if(!e.isConnected||e.getAttribute("src")!==t)dt(e)}),R.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function ft(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ht(e,t){if(!/^(input|textarea|select)$/.test(e.localName)||e.type==="file"&&t!==""){console.warn("[phlex-reactive] set_value skipped: not a field it can write",e);return}let n=Oe(e);if(e.value=t,Oe(e)!==n)ft(e)}function Oe(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function on(e,t,n){if(n?.transition)Vt(e,n.transition,()=>e.hidden=t);else e.hidden=t}function ee(e,t,n,r){if(on(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let i of r({...n,to:n.expanded}))i.setAttribute?.("aria-expanded",String(!t))}function te(e){if(!lt(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function mt(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),i=!1;for(let a of["srcset","src"]){let o=r?n.getAttribute(a):null;if(o==null){if(e.hasAttribute(a))i=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==o)i=e.setAttribute(a,o)??!0}if(i)z(e);let s=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==s)e.setAttribute("alt",s);return n?s:!1}var sn='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function an(e){return e.querySelectorAll?.(sn)?.[0]??null}function ve(e){if(Array.isArray(e))return e;if(typeof e!=="string")return[];try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}var Me=Object.freeze({backspace:"Backspace",delete:"Delete",enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"}),Ce=Object.freeze(["meta","ctrl","alt","shift"]);function V(e,t,n){let r=e.split("+");for(let a of Ce)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let i=r.find((a)=>!Ce.includes(a));if(i===void 0||typeof t.key!=="string")return!0;let s=n&&Object.hasOwn(n,i)?n[i]:Object.hasOwn(Me,i)?Me[i]:/^[a-z0-9]$/.test(i)?i:null;return typeof s==="string"&&s.toLowerCase()===t.key.toLowerCase()}var cn=(e)=>e&&typeof e==="object"?e.keys:String(e);function ne(e,t,n){let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let i=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return V(cn(e).replace(/^mod\+/,`${i}+`),t,n)}function un(e){if(Array.isArray(e))return[{ops:e,legacy:!0}];if(e&&typeof e==="object")return[e];if(typeof e!=="string")return[];let t=e.trim();if(t.startsWith("["))return[{ops:ve(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let i=null;try{i=JSON.parse(r)}catch{i=null}if(i&&typeof i==="object"&&!Array.isArray(i))n.push(i);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function De(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let i=r.indexOf(".");if(t.type!==(i<0?r:r.slice(0,i)))return!1;if(Boolean(e.window)!==_e(t.currentTarget))return!1;return i<0||n===null||V(r.slice(i+1),t,n)}function ln(e,t){let n=e.detail;if(n===void 0)return!0;if(n===null||typeof n!=="object"||Array.isArray(n))return!1;let r=t.detail;if(r===null||typeof r!=="object")return!1;return Object.keys(n).every((i)=>r[i]===n[i])}var $e=new WeakMap;function dn(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,i=$e.get(e);if(!i)i=new WeakMap,$e.set(e,i);let s=i.get(r);if(!s)s=new Set,i.set(r,s);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(s.has(c))return!0;return s.add(c),!1}var qe=new WeakMap;function fn(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),i=qe.get(e);if(!i)i=new WeakMap,qe.set(e,i);let s=i.get(t);if(!s)s=new Map,i.set(t,s);let a=s.get(e.currentTarget);if(!a)a=new Set,s.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function ue(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[i,s={}]=r;if(!Object.hasOwn(Pe,i)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(i)} — skipped`);continue}let a=t(s);if(a.length===0&&n)n(i,s);for(let o of a)if(Pe[i](o,s,t),s?.keep===!0)Ke(o,i,s,t)}}function hn(e,t){let n=e.to;if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function mn(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function pt(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function pn(e){return(e.getAttribute?.("data-action")??"").includes("reactive#trackDirty")||e.getAttribute?.("data-reactive-clipboard")!=null||e.querySelector?.('[data-action*="reactive#trackDirty"],[data-reactive-clipboard]')!=null}function gn(e){return["show-targets","group-targets","on-complete","filter-input","tags-field"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)||(e.querySelectorAll?.("[data-reactive-show-field], [data-reactive-show]")??[]).length>0||e.querySelector?.("[data-reactive-nested-json], [data-reactive-nested-list], [data-reactive-confirm-when-param], [data-reactive-enable], [data-reactive-select-all], [data-reactive-count], [data-reactive-editable], [data-reactive-media]")!=null}function bn(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function yn(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function gt(e){return e.getAttribute?.("data-reactive-presence")!=null}function vn(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}var _n=[["persist",[mn,null,null,!0]],["defer",[pt,null]],["form",[pn,null]],["bindings",[gn,null,null,!0]],["compute",[bn,null,null,!0]],["sortable",[yn,null]],["presence",[gt,null]],["countdown",[vn,null]],["effects",[(e)=>["enter","update","exit"].some((t)=>e.getAttribute?.(`data-reactive-effect-${t}`)!=null),null]],["hints",[(e)=>e.querySelector?.("[data-reactive-optimistic-param], [data-reactive-busy-param], [data-reactive-loading-param]")!=null,null]],["devtools",[(e)=>e.getAttribute?.("data-reactive-debug")==="true",null]]],w=new Map(_n),We=new Map,p=new Map,wn=new Map;function g(e,t,n){bt.set(e,[t,n]),An(e)}var bt=new Map;function An(e){let t=w.get(e),[n,r]=bt.get(e);t[1]=n,t[2]=r}function Jn(e,t){t.install?.(P),p.set(e,t),wn.set(e,t)}function yt(e){let t=[];for(let[n,[r]]of w){if(!r||p.has(n))continue;try{if(e.some((i)=>r(i)))t.push(n)}catch{}}return t}function vt(e){return I(e).catch((t)=>H(e,"load",t))}function I(e){let t=We.get(e);if(!t)t=(w.get(e)[1]??(()=>Promise.reject(Error("this entry has no way to import it"))))().then((r)=>(r.install?.(P),p.set(e,r),r)),We.set(e,t);return t}var Be=new Set;function H(e,t,n){let r=e+t;if(Be.has(r))return;Be.add(r),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,n)}function y(e,t){let n=p.get(e);if(n)return t(n);I(e).then(t,(r)=>H(e,"load",r))}var Sn=1e4;function re(){let e=Number(globalThis.document?.head?.querySelector?.('meta[name="phlex-reactive-feature-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:Sn}function Hn(){return[...w.keys()]}var je=Promise.resolve();function Ue(e,t,n){let r=P.waiting.get(e);if(r&&r[t]===n)delete r[t]}var P={enter:rt,exit:it,count:at,text:E,served:ye,waiting:new WeakMap};var O=Symbol.for("phlex-reactive.early"),En=1e4,Tn=1500,_e=(e)=>e!=null&&(e===globalThis.window||e.window===e),Fn="dispatch";function ie(){return globalThis[O]??={queue:[],connected:new WeakSet},globalThis[O]}function Ln(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:En}function kn(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let i=/^data-reactive-(.+)-param$/i.exec(n);if(!i)continue;let s;try{s=JSON.parse(r)}catch{s=r}t[i[1].replace(/[-_]([a-z0-9])/g,(a,o)=>o.toUpperCase())]=s}return t}function xn(e,t,n){return{[O]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:kn(t),key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,button:e.button,submitter:e.submitter,bubbles:e.bubbles,timeStamp:e.timeStamp,defaultPrevented:e.defaultPrevented,preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var K=new WeakMap;function Nn(e,{token:t,type:n,method:r,filter:i,win:s},a){let o=K.get(e);if(!o)K.set(e,o=new Map);let c=s?`${t} ${a}`:t;if(o.has(c))return!1;return o.set(c,{type:n,method:r,filter:i,win:s,params:a,armed:!0}),!0}function Je(e,t,n,r){if(e?.[O])return!1;let i=_e(e?.currentTarget),s=i?r:e?.currentTarget,a=In(e,s,i?`@${t}`:t),o=K.get(s),c=i&&JSON.stringify(e.params);for(let l of o?.values()??[]){if(!l.armed||l.method!==t||l.type!==e.type||Boolean(l.win)!==i)continue;if(i&&l.params!==c)continue;if(l.filter&&!V(l.filter,e,n))continue;return l.armed=!1,!0}return a}var B=new WeakMap;function Rn(e,t,n){let r=B.get(e);if(!r)B.set(e,r=new Map),setTimeout(()=>B.delete(e));let i=r.get(t)??{};r.set(t,i),i[n]=(i[n]??0)+1}function In(e,t,n){let r=e&&B.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class _t extends At{static values={token:String};#w;#l=new Map;#d=new Map;#ne;#k;#j;#x=0;#f=new Map;#N=new WeakMap;#t;featuresReady=je;#n=new Map;#R=new Set;#h=!1;#r=null;#m=new Map;#A=new Map;#p=new Map;#g=0;#U;#Ce=0;#De=0;connect(){if(ut=!0,ie().connected.add(this.element),this.element.id==="")console.warn("[phlex-reactive] a reactive root has no id; its next-action token can't self-match "+"and may fall back to the first token in the response → a silent HTTP 403 on the NEXT action. "+"Put id: on the SAME element as reactive_attrs — use div(**reactive_root) (emits id + token together), "+"or div(id:, **reactive_attrs). The id: must NOT be on a child. See the README.");if(this.element.getAttribute?.("data-reactive-token-value")!=null||pt(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===D)this.#K();this.#J(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(D,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(be),this.#g++,this.featuresReady=je,this.#J(),j(this.element),this.#se()}#$e(e){}#qe(e,t,n,r){}#We(){}#Be(e,t){}#J(e){{let t=this.#g,n=[];for(let[s,[a]]of w){if(!a||this.#R.has(s))continue;let o=p.get(s);if(o&&!o.connect)continue;try{if(a(this.element))n.push(s)}catch(c){this.#b(s,"detect",c)}}if(n.length===0)return;for(let s of n)this.#R.add(s);if(!this.#h&&n.every((s)=>p.has(s))){for(let s of n)this.#I(t,s,p.get(s),e);return}for(let s of n){let a=this.#re(t,s),o=[];for(let l of w.keys()){if(l===s)break;if(this.#p.has(l))o.push(this.#p.get(l))}let c=Promise.all(o).then(()=>a).then((l)=>l&&this.#I(t,s,l,e));if(this.#p.set(s,c),w.get(s)[3])this.#r=c}let r=this.#r;r?.then(()=>{if(this.#r===r)this.#r=null}),this.#h=!0;let i=Promise.all(this.#p.values()).then(()=>{if(this.featuresReady===i)this.#h=!1});this.featuresReady=i}}#re(e,t){{let n=()=>e===this.#g;return this.#ie(t),new Promise((r)=>{let i=!1,s=setTimeout(()=>{if(this.#m.delete(s),i=!0,n())this.#b(t,"timeout",Error(`not loaded after ${re()} ms`));r(null)},re());this.#m.set(s,r);let a=()=>{clearTimeout(s),this.#m.delete(s)};I(t).then((o)=>{if(a(),i)queueMicrotask(()=>this.#I(e,t,o));else r(o)},(o)=>{if(a(),n())this.#b(t,"load",o);r(null)})})}}#ie(e){{let t=w.get(e)[2];if(!t)return;let n={};try{this.#A.set(e,[t(this.element,n),n]),P.waiting.set(this.element,{...P.waiting.get(this.element),[e]:n})}catch(r){this.#b(e,"detect",r)}}}#H(e,t){{let[n,r]=this.#A.get(e)??[];if(this.#A.delete(e),!t)Ue(this.element,e,r);try{n?.()}catch(i){console.error(`[phlex-reactive] the "${e}" feature module failed to stop waiting`,i)}return r}}#I(e,t,n,r){{if(e!==this.#g)return;let i=this.#H(t);try{n.connect?.(this,this.#e(),r,i),this.#n.set(t,n)}catch(s){this.#b(t,"connect",s)}}}#e(){return this.#U??={emit:(e,t,n)=>this.#o(e,t,n),reseed:()=>this.#K(),proceed:(e,t,n,r)=>this.#O(e,t,n,0,0,null,r),forgetToken:()=>{this.#w=void 0},owns:(e)=>this.#F(e),ownership:()=>this.#D(),opTargets:(e)=>this.#B(e),diagnose:(e,t)=>this.#W(e,t),applyOps:(e,t)=>ue(e,(n)=>this.#B(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#W(`client op "${n}"`,r)),listnavOptions:(e)=>this.#v(e),collectFields:()=>this.#Q(),plain:Qe,text:E,served:ye,copyMedia:mt,setValue:ht,confirm:(e,t)=>Promise.resolve().then(()=>Ae(e,t)).catch(()=>!1)},this.#U}#K(){this.#n.get("form")?.reseed(this),this.#n.get("bindings")?.reseed(this),this.#n.get("compute")?.seed(this)}#b(e,t,n){if(H(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#o("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#oe(){{this.#g++;for(let[t,n]of this.#m)clearTimeout(t),n(null);this.#m.clear();for(let t of[...this.#A.keys()]){let n=this.#H(t,!0),r=this.element;y(t,(i)=>{i.abandon?.(r,n),Ue(r,t,n)})}this.#R.clear(),this.#p.clear(),this.#h=!1,this.#r=null;let e=[...this.#n];this.#n.clear();for(let[t,n]of e)try{n.disconnect?.(this,this.#e())}catch(r){console.error(`[phlex-reactive] the "${t}" feature module failed to disconnect`,r)}}}#se(){if(this.element.setAttribute?.("data-reactive-connected",""),this.element.isConnected)this.element.dispatchEvent?.(new CustomEvent("reactive:connect",{bubbles:!0,composed:!0,detail:{id:this.element.id}}));this.#ae()}#P=new Set;#ae(){let{queue:e}=ie();if(e.length===0)return;let t=[];for(let i=e.length-1;i>=0;i--){let{root:s}=e[i];if(s===this.element||!s.isConnected)t.unshift(...e.splice(i,1))}let n=Ln(),r=new Map;for(let i of t){let s=r.get(i.event)??[new Set,new Set];r.set(i.event,s);let a=s[+!!i.win];if(a.has(i.el))continue;a.add(i.el);let o=i.win?Math.min(Tn,n):n,c=i.root!==this.element?"its root left the page before a controller connected":performance.now()-i.at>o?`it is older than the ${o} ms ${i.win?"window-trigger":"early-event"} TTL`:i.el.isConnected&&this.element.contains(i.el)?null:"its element left the root before the controller connected";if(c){if(this.#q())console.warn(`[phlex-reactive] dropped an early "${i.event.type}" trigger: ${c}`);continue}this.#ce(i)}}#ce({event:e,el:t,descs:n,win:r}){let i=xn(e,t,r),s=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),o=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!V(c.filter,e,s))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Nn(o,c,r&&JSON.stringify(i.params)))continue;this.#P.add(o)}if(Rn(e,o,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(i);else this.dispatch(i)}}disconnect(){if(this.#oe(),this.#me(),this.#ge(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(D,this.#t);ie().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#P)K.delete(e);this.#P.clear()}dispatch(e){let t=e.params?.shortcut;if(t!=null&&!ne(t,e,this.application?.schema?.keyMappings))return;if(Je(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:i,throttle:s,confirm:a,confirmWhen:o,outside:c,window:l,optimistic:d}=e.params;if(!n)return;let h=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let f=e.currentTarget??e.target;if((t!=null||!l)&&!this.#ke(d,f))e.preventDefault();if(n===Wt){let S=()=>{{let m=this.#n.get("defer");if(m)return m.materialize(this)}if(this.tokenValue)return this.#O(f,n,"{}")};return this.#h?this.featuresReady.then(S):S()}let b=this.#z(a,o),v=()=>this.#O(f,n,r,i,s,d,h);if(!b)return v();if(b instanceof Promise)return b.then((S)=>S?this.#S(S,f,v):v());this.#S(b,f,v)}#S(e,t,n){return Promise.resolve().then(()=>Ae(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#z(e,t){if(e)return e;if(!t)return null;{let n=p.get("bindings");if(n)return n.confirmMessage(this,this.#e(),t);return this.#V("bindings").then((r)=>r&&r.confirmMessage(this,this.#e(),t))}}#V(e){{let t;return Promise.race([I(e).catch((n)=>(H(e,"load",n),null)),new Promise((n)=>t=setTimeout(()=>n(null),re()))]).finally(()=>clearTimeout(t))}}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!ne(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Je(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(fn(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,i=un(n.ops),s=i.filter((o)=>De(o,e,null)),a=s.length<=1?s:s.filter((o)=>De(o,e,this.application?.schema?.keyMappings));if(a.length===0&&i.length>0){if(this.#q())this.#_((o)=>o.noBinding(this,e));return}for(let o of a){if(o.outside&&e[O])continue;if(!ln(o,e))continue;if(o.shortcut!=null&&!ne(o.shortcut,e,this.application?.schema?.keyMappings))continue;if(dn(this,e,o))continue;this.#ue(o.legacy?{...n,ops:o.ops,debounce:void 0,throttle:void 0}:o,e,r,i.indexOf(o))}}#ue(e,t,n,r){let{ops:i,confirm:s,confirmWhen:a,outside:o,window:c,shortcut:l}=e;if(o&&this.element.contains(t.target))return;if(l!=null||!c)t.preventDefault();let d=this.#z(s,a),h=this.#le(e,r,n,()=>this.#Le(this.#Fe(i)));if(!d)return h();if(d instanceof Promise)return d.then((f)=>f?this.#S(f,n,h):h());this.#S(d,n,h)}#le(e,t,n,r){let i=Number(e.debounce)||0,s=Number(e.throttle)||0;if(i<=0&&s<=0)return r;let a=JSON.stringify([t,e]);if(i>0)return()=>this.#G(n,a,i,r);return()=>this.#Y(n,a,s,r)}recompute(e){return p.get("compute")?.recompute(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#v(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return this.#y("tagsAdd",e)}tagsPick(e){return this.#y("tagsPick",e)}tagsRemove(e){return this.#y("tagsRemove",e)}nestedAdd(e){return this.#y("nestedAdd",e)}nestedRemove(e){return this.#y("nestedRemove",e)}syncNestedJson(e){return p.get("bindings")?.syncNestedJson(this,this.#e(),e)}#y(e,t){{let n=p.get("bindings");if(n)return n[e](this,this.#e(),t);t?.preventDefault?.();let r={currentTarget:t?.currentTarget??null,target:t?.target??null,preventDefault(){}};return y("bindings",(i)=>i[e](this,this.#e(),r))}}trackDirty(){(this.#n.get("form")??p.get("form"))?.scan(this,this.#e())}listnavNext(e){this.#E(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#E(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#E(e,()=>0)}listnavLast(e){this.#E(e,(t,n)=>n-1)}listnavPick(e){let t=this.#v(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#v(e))t.removeAttribute("data-reactive-highlighted")}#E(e,t){let n=this.#v(e);if(!n.length)return;e.preventDefault();let r=this.#de(e),i=globalThis.document?.activeElement,s=r?n.findIndex((o)=>o===i||i!=null&&o.contains?.(i)):n.findIndex((o)=>o.hasAttribute("data-reactive-highlighted")),a=n[t(s,n.length)];if(r)a.focus?.();else{for(let o of n)o.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#de(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#v(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#D();return Array.from(this.element.querySelectorAll(n)).filter((i)=>!i.hidden&&r(i))}#O(e,t,n,r,i,s,a){if(this.#o("reactive:before-dispatch",{action:t,params:this.#ee(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#he(e,c,t,n,s,a);let l=Number(i)||0;if(l>0)return this.#pe(e,l,t,n,s,a);return this.#T(t,n,s,e,a)}#T(e,t,n,r,i){let s={inverse:null,undo:[],resurrect:null},a=this.#xe(e,r,s),o=Boolean(n||i),c=(f)=>{if(!o||!f)return;let b=this.#e();if(s.inverse=f.optimistic(this,b,n,r),s.undo.push(...f.busy(this,b,i,r)),this.#C())s.resurrect=f.resurrection(this,b,n,r)},l=p.get("hints");if(!o||l)c(l);let d=()=>this.#_e(e,t,s,a),h=()=>this.#r?this.#r.then(d):d();return this.queue=(this.queue??Promise.resolve()).then(()=>o&&!l?this.#fe().then(c).then(h):h()),this.queue}#fe(){return this.#V("hints")}#he(e,t,n,r,i,s){this.#G(e,Fn,t,()=>this.#T(n,r,i,e,s))}#G(e,t,n,r){this.#M(e,t);let i=()=>{this.#M(e,t),r()},s=setTimeout(i,n);if(!_e(e))e?.addEventListener?.("blur",i,{once:!0});let a=this.#l.get(e);if(!a)this.#l.set(e,a=new Map);a.set(t,{timer:s,flush:i})}#M(e,t){let n=this.#l.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#l.delete(e)}#me(){for(let[e,t]of[...this.#l])for(let n of[...t.keys()])this.#M(e,n)}#pe(e,t,n,r,i,s){return this.#Y(e,n,t,()=>this.#T(n,r,i,e,s))}#Y(e,t,n,r){let i=this.#d.get(e)??new Map;if(i.has(t))return;let s=setTimeout(()=>{if(i.delete(t),i.size===0)this.#d.delete(e)},n);return i.set(t,s),this.#d.set(e,i),r()}#ge(){for(let e of this.#d.values())for(let t of e.values())clearTimeout(t);this.#d.clear()}#o(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#s(e,t,n,r){let i=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#T(e,t)};this.#o("reactive:error",{action:e,params:n,...r,retry:i})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#be(){this.element?.removeAttribute?.("data-reactive-error")}#ye(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#ve(){{let e=p.get("devtools");if(e)return e.delay();if(tt())return I("devtools").then((t)=>t.delay(),()=>{})}}#C(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#X(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#_e(e,t,n,r){let{fields:i,files:s}=this.#Q(),a=this.#ee(t),o={...i,...a},c=this.#a,l=s.length>0,d=l?this.#Ee(c,e,o,s):JSON.stringify({token:c,act:e,params:o}),h=this.#C()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(i),encoding:l?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#X()}:null;await this.#ve();try{if(navigator.onLine===!1){this.#c(n.inverse),this.#i("offline"),this.#s(e,t,o,{kind:"offline"});return}let f;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Oe()};if(!l)m["Content-Type"]="application/json";let L=this.#Me();if(L)m["X-Pgbus-Connection"]=L;let M=gt(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(M)m["X-Reactive-Presence"]=M;let we=$t(this.element);if(we)m["X-Reactive-Held"]=we;at("action"),f=await fetch(this.#Ie(),{method:"POST",headers:m,body:d,credentials:"same-origin",signal:AbortSignal.timeout(this.#Pe())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#c(n.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#i("timeout"),this.#s(e,t,o,{kind:"timeout"});return}this.#ye(),this.#i("network"),this.#s(e,t,o,{kind:"network"});return}if(h)h.status=f.status;if(f.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#c(n.inverse),this.#i("redirected"),this.#s(e,t,o,{kind:"redirected",status:f.status});return}if(!f.ok){let m=await f.text();if(console.error(`[phlex-reactive] action failed: HTTP ${f.status}`,m),this.#c(n.inverse),(f.headers.get("Content-Type")||"").includes("turbo-stream")){let L=this.#Z(m);if(this.#a=L??this.#a,h)this.#_((M)=>M.recordBody(h,m,L));Ne(this.element,m,!1)}this.#i("http"),this.#s(e,t,o,{kind:"http",status:f.status,body:m});return}let b=f.headers.get("Content-Type")||"";if(!b.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${b}" — no update applied`),this.#c(n.inverse),this.#i("content-type"),this.#s(e,t,o,{kind:"content-type",status:f.status});return}let v=await f.text(),S=this.#Z(v);if(this.#a=S??this.#a,h)this.#_((m)=>m.recordBody(h,v,S));if(Ne(this.element,v),n.resurrect)queueMicrotask(n.resurrect);return this.#be(),this.#o("reactive:applied",{action:e,params:o,html:v}),v}catch(f){console.error("[phlex-reactive] action error",f),this.#c(n.inverse),this.#o("reactive:error",{action:e,params:o,kind:"apply"})}finally{if(r?.(),h)this.#_((f)=>f.trace(this,{...h,ms:this.#X()-h.started}))}}get#a(){return this.#w??this.tokenValue}set#a(e){this.#w=e}tokenValueChanged(){this.#w=void 0}#Z(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#we(t),i=e.match(n);if(i)return i[1];let s=e.match(r);if(s)return s[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#we(e){let t=this.#j;if(t&&t.id===e)return t;let n=Ht(e);return this.#j={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#F(e){return e.closest('[data-controller~="reactive"]')===this.element}#D(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#F(t)}#Q(){let e={},t=[],n=this.#D(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((o)=>{if(!n(o))return;if(o.type==="file")for(let c of o.files??[])t.push({name:o.name,file:c,multiple:o.multiple});else r.push(o)});let i=[];this.element.querySelectorAll(`[name]${Yt}`).forEach((o)=>{if(n(o))i.push(o)});let s=this.#Ae(r),a=this.#Se(r);for(let o of r)if(s.has(o.name)){let c=e[o.name]??(e[o.name]=[]);if(o.type==="checkbox"||o.type==="radio"){if(o.checked)c.push(o.value)}else if(o.type==="hidden"){if(!a.has(o.name))c.push(o.value)}else if(o.multiple&&o.options){for(let l of o.options)if(l.selected)c.push(l.value)}else c.push(o.value)}else if(o.type==="checkbox")e[o.name]=o.checked;else if(o.type==="radio"){if(o.checked)e[o.name]=o.value}else e[o.name]=o.value;return i.forEach((o)=>{let c=o.getAttribute("name");if(!c)return;let l=o.getAttribute("data-reactive-editable")!=null?E(o):o.value??o.textContent??o.innerHTML??"",d=e[c];if(String(c).endsWith("[]")&&!Zt(o))return;if(String(c).endsWith("[]")&&(d===void 0||Array.isArray(d))){(Array.isArray(d)?d:e[c]=[]).push(l);return}if(d==null||d==="")e[c]=l}),{fields:e,files:t}}#Ae(e){let t=new Set;for(let n of e){if(n.type==="radio")continue;if(String(n.name).endsWith("[]"))t.add(n.name)}return t}#Se(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#Ee(e,t,n,r){let i=new FormData;i.append("token",e),i.append("act",t);let s=[];for(let[o,c]of Object.entries(n))if(Array.isArray(c)&&String(o).endsWith("[]"))if(c.length===0)s.push(String(o).slice(0,-2));else{let l=`${this.#L(o)}[]`;for(let d of c)i.append(l,String(d))}else this.#$(i,this.#L(o),c);for(let o of s)i.append("empty_groups[]",o);let a=this.#Te(r);for(let{name:o,file:c,multiple:l}of r){let h=l||a.has(o)?`${this.#L(o)}[]`:this.#L(o);i.append(h,c,c.name)}return i}#L(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((i)=>`[${i}]`).join("")}`}#$(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,i)=>this.#$(e,`${t}[${i}]`,r));else if(typeof n==="object")for(let[r,i]of Object.entries(n))this.#$(e,`${t}[${r}]`,i);else e.append(t,String(n))}#Te(e){let t=new Map;for(let{name:n}of e)t.set(n,(t.get(n)??0)+1);return new Set([...t].filter(([,n])=>n>1).map(([n])=>n))}#ee(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Fe(e){return ve(e)}#Le(e){ue(e,(t)=>this.#B(t),(t,n)=>this.#W(`client op "${t}"`,n))}#q(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#C()}#W(e,t){if(!this.#q())return;this.#_((n)=>n.diagnose(this,e,t))}#_(e){y("devtools",e)}#B(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((n)=>this.#F(n))}#ke(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#c(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#xe(e,t,n){this.#Ne(e,t),rt();let r=!1;return()=>{if(r)return;r=!0,this.#Re(e,t),it();for(let i of n.undo)i()}}#Ne(e,t){if(this.#u(t,e,1),this.#u(this.element,e,1),this.#f.set(e,(this.#f.get(e)??0)+1),this.#x++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#te(e))this.#u(n,e,1)}#Re(e,t){this.#u(t,e,-1),this.#u(this.element,e,-1);let n=(this.#f.get(e)??1)-1;if(n<=0)this.#f.delete(e);else this.#f.set(e,n);if(--this.#x<=0)this.#x=0,this.element.removeAttribute("aria-busy");for(let r of this.#te(e))this.#u(r,e,-1)}#u(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#N.get(e)??new Map,i=(r.get(t)??0)+n;if(i<=0)r.delete(t);else r.set(t,i);if(r.size===0){this.#N.delete(e),e.removeAttribute("data-reactive-busy");return}this.#N.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#te(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#F(n))}#Ie(){return this.#ne??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Pe(){if(this.#k!=null)return this.#k;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#k=Number.isFinite(t)&&t>0?t:30000}#Oe(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Me(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)Ie();else document.addEventListener("turbo:load",Ie,{once:!0});g("persist",()=>import("phlex/reactive/features/persist"),Pn);g("defer",()=>import("phlex/reactive/features/defer"));g("form",()=>import("phlex/reactive/features/form"));g("bindings",()=>import("phlex/reactive/features/bindings"));g("compute",()=>import("phlex/reactive/features/compute"),On);g("sortable",()=>import("phlex/reactive/features/sortable"));g("presence",()=>import("phlex/reactive/features/presence"));g("countdown",()=>import("phlex/reactive/features/countdown"));g("effects",()=>import("phlex/reactive/features/effects"));g("hints",()=>import("phlex/reactive/features/hints"));g("devtools",()=>import("phlex/reactive/features/devtools"));ge();function Pn(e,t){let n=()=>{t.edited=!0},r=(s)=>{let a=s.target;if(s.detail?.success&&a?.tagName==="FORM"&&a.contains?.(e))t.submitted=!0},i=["input","change","lexxy:change","trix-change"];for(let s of i)e.addEventListener?.(s,n);return document.addEventListener("turbo:submit-end",r),()=>{for(let s of i)e.removeEventListener?.(s,n);document.removeEventListener("turbo:submit-end",r)}}function On(e,t){let n=()=>{t.edited=!0};return e.addEventListener?.("input",n),e.addEventListener?.("change",n),()=>{e.removeEventListener?.("input",n),e.removeEventListener?.("change",n)}}var Mn=1000,F=null,wt,G=new Set;function Cn(e){return vt(e).then((t)=>{if(e!=="effects")return;wt=t,t?.sweep()})}Ze((e,t)=>{let n=e.detail,r=n?.render;if(typeof r!=="function")return;let i=n.newStream??e.target,s=yt(Dn(i)).filter((o)=>!G.has(o));if(!t&&!G.has("effects")&&$n(i))s.push("effects");if(s.length===0&&!F)return t?.wrap(e);if(s.length>0){for(let c of s)G.add(c);let o=F=Promise.race([Promise.all([F,...s.map(Cn)]),new Promise((c)=>setTimeout(c,Mn))]).then(()=>{if(F!==o)return;F=null,G.clear()})}let a=F;n.render=async(o)=>{await a;let c={target:e.target,detail:{newStream:n.newStream,render:r}};(t??wt)?.wrap(c),await c.detail.render(o)}});function Dn(e){let t=e?.querySelector?.("template")?.content;if(!t)return[];let n=[...t.querySelectorAll?.('[data-controller~="reactive"]')??[]];for(let r of t.children??[])if(r.matches?.('[data-controller~="reactive"]')&&!n.includes(r))n.unshift(r);return n.push(t),n}function $n(e){return Boolean(e?.hasAttribute?.("data-reactive-effect")||document.getElementById?.(e?.getAttribute?.("target"))?.matches?.("[data-reactive-effect-update],[data-reactive-effect-exit]")||e?.querySelector?.("template")?.content?.querySelector?.("[data-reactive-effect-enter],[data-reactive-dismiss-after]")||document.querySelector?.("[data-reactive-dismiss-after]:not([data-reactive-dismiss-scheduled])"))}var Xn=_t;export{nt as ACTIVE_ATTR,Yt as EDITOR_SELECTOR,Xt as EDITOR_TAGS,st as REQUESTS_ATTR,Kt as checkReactiveRegistration,at as countReactiveRequest,Xn as default,E as editableValue,rt as enterReactiveActivity,Ht as escapeRegExp,it as exitReactiveActivity,vt as loadReactiveFeature,Ze as onReactiveStreamWithoutEffects,jn as reactiveActivityCount,Hn as reactiveFeatureNames,Ie as registerReactiveActions,Ft as registerReactiveDefer,ge as registerReactiveDev,Lt as registerReactiveDismiss,Lt as registerReactiveEffects,Jn as registerReactiveFeature,g as registerReactiveFeatureLoader,Pt as registerReactiveImageFallback,Tt as registerReactiveJs,It as registerReactiveKeep,Rt as registerReactiveModals,Mt as registerReactiveMorphFocus,Bt as registerReactiveOffline,Ot as registerReactivePlaintext,Lt as registerReactiveStreamRender,Et as registerReactiveToken,St as registerReactiveVisit,Un as resetReactiveActivity,ye as serverText,yt as unloadedFeaturesFor};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=487097BB218E972964756E2164756E21
|
|
9
9
|
//# sourceMappingURL=core.min.js.map
|