phlex-reactive 0.15.1 → 0.15.3
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 +188 -0
- data/README.md +82 -9
- data/app/controllers/phlex/reactive/actions_controller.rb +4 -1
- data/app/javascript/phlex/reactive/compute.js +14 -1
- data/app/javascript/phlex/reactive/compute.min.js +2 -2
- data/app/javascript/phlex/reactive/compute.min.js.map +3 -3
- data/app/javascript/phlex/reactive/core.min.js +4 -3
- data/app/javascript/phlex/reactive/core.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/bindings.js +66 -0
- 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/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 +31 -2
- 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.min.js +4 -3
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +6 -6
- data/app/javascript/phlex/reactive/runtime.js +476 -13
- data/lib/phlex/reactive/component/helpers.rb +24 -5
- data/lib/phlex/reactive/component/identity.rb +34 -1
- data/lib/phlex/reactive/component/image_fallback_binding.rb +54 -0
- data/lib/phlex/reactive/component/media_binding.rb +103 -0
- data/lib/phlex/reactive/component/media_pattern.rb +79 -0
- data/lib/phlex/reactive/doctor.rb +20 -8
- data/lib/phlex/reactive/held_fields.rb +87 -0
- data/lib/phlex/reactive/js.rb +153 -29
- data/lib/phlex/reactive/streamable.rb +26 -2
- data/lib/phlex/reactive/test_helpers.rb +11 -2
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +5 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import{Controller as Fs}from"@hotwired/stimulus";import{confirmResolver as zr}from"phlex/reactive/confirm";import{confirmPredicate as Ro}from"phlex/reactive/confirm_predicate";var O=new WeakMap,_e=new WeakMap;function x(e,t){let n=O.get(e);if(!n){if(O.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)_e.set(n.root,n)}return n}function S(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function C(e,t){S(e,"turbo:morph-element",t),e.seeds.push(t),t()}function xe(e,t){let n=x(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&Co(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")jo(n,s.target);else n.groups=Wo(n),gn(n);$o(n)},S(n,"input change",n.show),C(n,n.show);if(!n.arm&&Mo(n))S(n,"input change",(s)=>mn(n,s)),C(n,n.arm=()=>{mn(n,null),gn(n)});if(!r&&(r=n.show||n.arm))S(n,"reset",()=>setTimeout(()=>{if(O.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=Y(n)))S(n,"input",(s)=>Uo(n,s)&&M(n)),C(n,()=>M(n));if(!i&&(i=V(n)))C(n,()=>kn(n));if(!a&&(a=Ho(n)))S(n,"input change",(s)=>On(n,s)),C(n,()=>Me(n))})(),S(n,"keydown",(s)=>si(n,s)),S(n,"paste drop",(s)=>ai(n,s)),S(n,"input",(s)=>ci(n,s))}function Te(e){let t=O.get(e);if(!t)return;O.delete(e),_e.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function ke(e){let t=O.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function N(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Re(e,t,n){return On(x(e,t),n)}function Le(e,t,n){return In(x(e,t),n)}var Lo=/^#[A-Za-z_][\w-]*$/,yn="[data-reactive-show-field], [data-reactive-show]";function Fo(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of Nn){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Pn(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function vn(e){try{let t=JSON.parse(e);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return console.warn(`[phlex-reactive] malformed compound reactive_show payload ${JSON.stringify(e)} — skipped`),null}function Oo(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function An(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return P(n,t);return No(e,t)}function No(e,t){let n=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!n)return null;let r=e[n];if(r.length===0)return null;let o=r.map((i)=>We(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function G(e,t="show"){if(typeof e==="string"&&Lo.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Co(e){if(e.root.getAttribute?.("data-reactive-show-targets"))return!0;if(e.root.getAttribute?.("data-reactive-group-targets"))return!0;let t=e.root.querySelectorAll?.(yn)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(K)??[])if(e.core.owns(n))return!0;return!1}function Mo(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Po(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Oo(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function mn(e,t){let n=Po(e);if(!n.length)return;let r=En(e,e.core.ownership());n.forEach((o,i)=>{let a=P(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function $o(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=En(e,t);for(let o of e.root.querySelectorAll(yn)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=An(vn(i),r);if(u!==null)hn(o,u,t,n);continue}let a=o.getAttribute("data-reactive-show-field");if(!a)continue;let s=r(a);if(s===null)continue;let c=Fo(o,s);if(c===null)continue;hn(o,c,t,n)}if(e.groups)Bo(e,r,t,n);Io(e,r),Jo(e,r)}function hn(e,t,n,r){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let o of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(o))o.disabled=!t;if(e.name&&n(e))e.disabled=!t}function Io(e,t){let n=wn(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Do(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!G(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>We(l,a))}else{let l=$n(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${s} — skipped`);continue}u=l}for(let l of document.querySelectorAll(s))l.hidden=!u}}}function Do(e,t,n){if(!G(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=oi(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!ii(r))return;let i=P(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function wn(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function qo(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(Sn(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function Sn(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function En(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?Fe(e,o,t,n).filter((s)=>s.checked).length:qo(e,o,t,n));return r.get(a)}}var K="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Wo(e){return!!e.root.querySelector?.(K)}function Fe(e,t,n,r){return[...e.root.querySelectorAll(Sn(t,r))].filter((o)=>o.type==="checkbox"&&n(o))}function jo(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))_n(e,n,t.checked,t)}function Oe(e,t,n){if(!t)return;let r=_e.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};_n(r,t,n!==!1),r.show?.()}function _n(e,t,n,r){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=Fe(e,t,e.core.ownership(),o).filter((a)=>a!==r&&a.checked!==n);for(let a of i)a.checked=n;e.flipping=!0;try{for(let a of i)for(let s of["input","change"])a.dispatchEvent?.(new Event(s,{bubbles:!0}))}finally{e.flipping=!1}}function Bo(e,t,n,r){for(let o of e.root.querySelectorAll(K)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=An(vn(i),t);if(c!==null)o.disabled=!c}let a=o.getAttribute("data-reactive-count");if(a){let c=String(t(a,!0));if(o.textContent!==c)o.textContent=c}let s=o.getAttribute("data-reactive-select-all");if(s){let c=Fe(e,s,n,r).filter((l)=>l!==o),u=c.filter((l)=>l.checked).length;o.checked=u>0&&u===c.length,o.indeterminate=u>0&&u<c.length}}}function Jo(e,t){for(let[n,r]of Object.entries(wn(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!G(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!G(a,"group"))continue;let c=P(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function gn(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${K}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let r=(o)=>o.nodeType===1&&(o.matches('input[type="checkbox"]')||!!o.querySelector('input[type="checkbox"]'));e.groupObserver=new MutationObserver((o)=>{if(!o.some((i)=>[...i.addedNodes,...i.removedNodes].some(r)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function Y(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Uo(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}function M(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=(o.value??"").trim().toLowerCase(),a=0;for(let u of e.root.querySelectorAll(n)){if(!r(u))continue;let l=(u.getAttribute("data-reactive-filter-text")??u.textContent??"").toLowerCase(),p=u.hasAttribute?.("data-reactive-tags-selected")||i!==""&&!l.includes(i);if(u.hidden=p,p)u.removeAttribute("data-reactive-highlighted");else a++}let s=e.root.getAttribute("data-reactive-filter-group");if(s)for(let u of e.root.querySelectorAll(s)){if(!r(u))continue;let l=[...u.querySelectorAll(n)].filter(r);if(l.length===0)continue;u.hidden=l.every((p)=>p.hidden)}let c=e.root.getAttribute("data-reactive-filter-empty");if(c){for(let u of e.root.querySelectorAll(c))if(r(u))u.hidden=a>0}}function V(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Ho(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function Ne(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Ce(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function xn(e,t){let n=Ne(e);if(!n)return!1;let r=Ce(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)Tn(e,n,r);return i}function Tn(e,t,n){t.value=n.join(","),N(t),kn(e)}function zo(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function kn(e){let t=Ne(e);if(!t)return;let n=Ce(t),r=e.core.ownership();Go(e,n,r),Yo(e,n,r)}function Go(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Yo(e,t,n){let r=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!n(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(r.has(i.toLowerCase()))o.setAttribute("data-reactive-tags-selected","true"),o.hidden=!0,o.removeAttribute?.("data-reactive-highlighted");else if(o.hasAttribute?.("data-reactive-tags-selected")){if(o.removeAttribute("data-reactive-tags-selected"),!Y(e))o.hidden=!1}}if(Y(e))M(e)}function Ko(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Vo(e,t){let n=[e,...e.querySelectorAll?.("*")??[]];for(let r of n)for(let o of["name","id","for"]){let i=r.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))r.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Xo(e,t){if(e.nestedWarned)return;console.warn(`[phlex-reactive] nested rows: no owned [data-reactive-nested-list="${t}"] container + <template data-reactive-nested-template="${t}"> pair found in this root — the add `+"trigger did nothing. Render both inside the same reactive root (reactive_nested_list / reactive_nested_template)."),e.nestedWarned=!0}function Zo(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let p=a.find((m)=>Ln(m.getAttribute?.("name"))===c);if(!p)continue;Qo(p,l),s.push(l)}if(r)for(let c of s)ei(c);return s[0]??null}function Qo(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Ee(t)!=="";else e.value=Ee(t);N(e)}function ei(e){if(e.type==="checkbox")e.checked=!1;else e.value="";N(e)}function ti(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function bn(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",N(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);Me(e)}function Me(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))Fn(e,n.getAttribute("data-reactive-nested-json"))}function ni(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function Rn(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=Ln(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Ee(o)}return n}function Ln(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Ee(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Fn(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=ni(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(Rn(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,N(o)}function Pe(e,t,n){let r=x(e,t);if(!V(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!xn(r,String(o.value??"").split(",")))return;if(o.value="",Y(r))M(r)}function $e(e,t,n){let r=x(e,t);if(!V(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!xn(r,[i]))return;let a=zo(r);if(!a)return;a.value="",M(r),a.focus?.()}function Ie(e,t,n){let r=x(e,t);if(!V(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=Ne(r);if(!a)return;let s=Ce(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Tn(r,a,c)}function De(e,t,n){let r=x(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Xo(r,i);return}let l=u.cloneNode(!0);Vo(l,Ko(r)),s.appendChild(l);let p=o?.getAttribute?.("data-reactive-nested-from-param"),m=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",g=Zo(r,l,p,m);if(p)g?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Fn(r,i)}function qe(e,t,n){let r=x(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?In(r,s):null);if(!c)return bn(r,i);let u=Rn(r,i),l=ti(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((p)=>{if(p)bn(r,i)})}function On(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;Me(e)}var Nn=["gte","gt","lte","lt"],ri=["len_eq","len_gte","len_gt","len_lte","len_lt"],Cn=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function Mn(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function Pn(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function $n(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Nn)if(n in e)return Pn(n,e[n],t);for(let n of ri)if(n in e)return Mn(n,e[n],[...String(t??"")].length);return null}function We(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Cn.find((o)=>(o in e));if(n){let o=t(e.field,!0);return Mn(n,e[n],Array.isArray(o)?o.length:Number(o)||0)===!0}let r=t(e.field)??"";return $n(e,r)===!0}function P(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>We(r,t)))}function oi(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let n of e){if(!Array.isArray(n))continue;for(let r of n)if(r&&typeof r==="object"&&typeof r.field==="string")t.add(r.field)}return t.size>0?[...t]:null}function ii(e){return e.flat().every((t)=>Cn.some((n)=>(n in Object(t))))}function In(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=Ro(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=P(n.groups?.any,o)===!0;return i?n.message:null}function je(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function si(e,t){let n=je(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),N(n),n.blur()}function ai(e,t){let n=je(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||e.core.plain()&&!(r&&/[\r\n]/.test(o)))return;if(t.preventDefault(),r)o=o.replace(/\r?\n|\r/g," ");n.focus(),document.execCommand("insertText",!1,o)}function ci(e,t){let n=je(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as ui}from"phlex/reactive/compute";var D=new WeakMap;function jn(e,t){let n=D.get(e);if(!n)D.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Je(e,t,n,r){let o=jn(e,t),i=_i(o);if(i)o.seed=()=>Be(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)Be(o)}function Ue(e){let t=D.get(e);if(!t)return;if(D.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function He(e){D.get(e)?.seed?.()}function ze(e,t,n){return Be(jn(e,t),n)}var li=Object.freeze({el:null,kind:""}),fi=/^#[A-Za-z_][\w-]*$/;function I({el:e,kind:t}){if(!e)return"";if(t==="checkbox")return e.checked?"true":"false";if(t==="radio")return e.checked?e.value??"":"";return e.value??""}function Bn(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function di(e,t){if(t==="string")return I(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Bn(I(e));if(n)return e.el.checked?1:0;let r=Number(I(e));return Number.isFinite(r)?r:0}function pi(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Bn(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return mi(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function mi(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function hi(e){if(e==null)return null;let t=Array.isArray(e)?e:e.ops;if(Array.isArray(t))return t.length>0?t:null;return console.warn("[phlex-reactive] $ops must be an ops chain or a [[op, args], ...] list — skipped"),null}function gi(e){if(typeof e==="string"&&fi.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function bi(e,t,n){let r=t===null?null:JSON.stringify(t),o=r!==null&&r!==e.opsSig&&n;if(e.opsSig=r,!o)return;e.core.applyOps(t,"@root")}function yi(e,t){let n=e.root.getAttribute(t);if(!n)return[];try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function vi(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let n=JSON.parse(t);if(Array.isArray(n))return n.map((r)=>[r,"number"]);if(n&&typeof n==="object")return Object.entries(n);return[]}catch{return[]}}function Ai(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=wi(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function wi(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function qn(e,t,n){let r=String(n);for(let o of Si(e,t)){if(o.textContent===r)continue;o.textContent=r}}function Si(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Wn(e,t,n){let r=Ei(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?I(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!gi(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Ei(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let n=JSON.parse(t);return n&&typeof n==="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function _i(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function Be(e,t){if(t&&e.ours.has(t))return;let n=vi(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.ownership(),s=new Map,c=(h)=>{let d=s.get(h);if(d)return d;let y=null,w=null,L=null;for(let F of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(F))continue;let z=F.type;if(z==="checkbox"||z==="radio"&&F.checked){L={el:F,kind:z};break}if(z==="radio")y??=F;else w??=F}if(!L)if(y)L={el:y,kind:"radio"};else L=w?{el:w,kind:""}:li;return s.set(h,L),L};for(let h of r)qn(e,h,I(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?ui(u):null;if(!l){Wn(e,{},c);return}let p=yi(e,"data-reactive-compute-outputs-param"),m={};for(let[h,d]of n)m[h]=di(c(h),d);let g=l(m,{changed:Ai(e,t,r,o)})||{},b=hi(g.$ops),v=[];for(let h of p){if(h==="$ops"||!(h in g))continue;let d=c(h);if(!d.el)continue;let y=pi(e.root,a,d,i(h),g[h]);if(y)v.push(y)}for(let h of Object.keys(g)){if(h==="$ops")continue;let d=g[h];if(d===void 0||d===null)continue;qn(e,h,d)}Wn(e,g,c);for(let h of v){let d=new Event("input",{bubbles:!0});e.ours.add(d),h.dispatchEvent(d)}bi(e,b,Boolean(t))}var Ke;function Ve(e){Ke=e}var Gn=1,xi="phlex-reactive:persist:",Ti=new Set(["hidden","file","password","submit","button","reset","image"]),Xe=Symbol("persist-no-value"),Ze="data-reactive-persist-state",ki=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Ri=new Set(["lexxy-editor","trix-editor"]),Li="lexxy-editor, trix-editor, trix-toolbar",Fi=["lexxy:change","trix-change"],Oi=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Un=new WeakSet,Hn=new WeakSet,zn=new WeakSet;function Z(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let n=JSON.parse(t);if(n&&typeof n==="object"&&typeof n.key==="string"&&n.key!=="")return n}catch{}if(!Un.has(e))Un.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Qe(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function et(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Hn.has(e))return;Hn.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function tt(e){return xi+e.key}function Ge(e,t){let n=Qe();if(!n)return null;let r;try{r=n.getItem(tt(t))}catch(c){return et(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Gn)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return X(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function Yn(e,t,{fields:n,state:r}){let o=Qe();if(!o)return!1;let i={v:Gn,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(tt(t),JSON.stringify(i)),!0}catch(a){return et(e,a),!1}}function X(e,t){e?.removeAttribute?.(Ze);let n=Qe();if(!n)return;try{n.removeItem(tt(t))}catch(r){et(e,r)}}function nt(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||Ti.has(i.type)||i.closest(Li))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(ki)){if(!o(i))continue;let a=Ni(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Ri.has(i.localName)?"editor":"contenteditable"})}return r}function Kn(e){return e.hasAttribute("data-reactive-editable")?Ke.text(e):e.textContent??""}function Ni(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function rt(e){return typeof e.value==="string"}function Ci(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Oi.has(e.value.trim())}function Mi(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||zn.has(e))return;zn.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function q(e){return e.tagName==="SELECT"&&e.multiple}function Vn(e){let t=new Map;for(let{el:n,name:r}of e){if(n.type==="radio"||!String(r).endsWith("[]"))continue;t.set(r,(t.get(r)??0)+1)}return t}function Xn(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Xe;return e[0]}function Zn(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of nt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(rt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=Kn(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(q(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function Pi(e,t,n){let r=t.restore==="always",o=nt(e,t),i=Vn(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&q(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||q(s))){if(l=Xn(l,c,i),l===Xe)continue}if((s.type==="checkbox"||q(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")Qn(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&Kn(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((p)=>p.kind==="native"&&p.el.type==="radio"&&p.name===c&&p.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(q(s)){if(!r&&[...s.options].some((m)=>m.selected))continue;let p=new Set((Array.isArray(l)?l:[l]).map(String));for(let m of s.options)m.selected=p.has(m.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}$i(e,t,n)}function Qn(e,t,n,r,o){if(Array.isArray(r))return;if(!rt(t))return;if(!o&&!Ci(t))return;try{t.value=String(r)}catch(i){Mi(e,n,i)}}function $i(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!rt(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=nt(e,t),c=Vn(s);for(let{el:u,name:l,kind:p}of s){if(p!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let m=Xn(n[l],l,c);if(m===null||m===void 0||m===Xe)continue;Qn(e,u,l,m,i)}})}function Ii(e,t,n=!0){let r=Z(e);if(!r){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=Ge(e,r),i={...o?.state??{},...t},a=n?Zn(e,r):o?.fields??{};if(Yn(e,r,{fields:a,state:i}))e.setAttribute?.(Ze,JSON.stringify(i))}function Di(e){let t=Z(e);if(t)X(e,t)}var Ye=new WeakMap;function ot(e,t,n,r){let o=e.element,i=Z(o);if(!i)return;if(r?.submitted)X(o,i);let a=Ge(o,i);if(a){if(Pi(o,i,a.fields),a.state)o.setAttribute?.(Ze,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let g=Ge(o,i);Yn(o,i,{fields:Zn(o,i),state:g?.state??null})},l=()=>{let g=Number(i.debounce)||0;if(g<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},g)},p=(g)=>{if(!g?.detail?.success)return;let b=g.target;if(b?.tagName!=="FORM"||typeof b.contains!=="function")return;if(!b.contains(o))return;c(),X(o,i)},m=["input",...Fi];for(let g of m)o.addEventListener?.(g,l);if(o.addEventListener?.("change",u),document.addEventListener?.("turbo:submit-end",p),Ye.set(e,()=>{if(s!==null)u();for(let g of m)o.removeEventListener?.(g,l);o.removeEventListener?.("change",u),document.removeEventListener?.("turbo:submit-end",p)}),r?.edited&&!r.submitted)u();for(let g of r?.ops??[])g(!0)}function it(e){let t=Ye.get(e);Ye.delete(e),t?.()}function er(e,t){let n=Ke?.waiting.get(e)?.persist;if(!n||!Z(e))return t(!0);(n.ops??=[]).push(t)}function st(e,t){er(e,(n)=>Ii(e,t,n))}function at(e){er(e,()=>Di(e))}var Q=new WeakMap,nr=new WeakSet;function ct(e,t){let n=e.element,r=[],o=[],i=(u,l,p)=>{u.addEventListener?.(l,p),r.push(()=>u.removeEventListener?.(l,p))},a,s,c=()=>{if(!a&&(a=qi(n,t))){let u=()=>ee(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")ji(n,i)}if(!s&&(s=Bi(n,t))){let u=()=>Ji(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};Q.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function ut(e){for(let t of Q.get(e)?.[0]??[])t();Q.delete(e)}function lt(e){Q.get(e)?.[1]()}function qi(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let n=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let r of n)if(t.owns(r))return!0;return!1}function ee(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,Wi(i))}),n.querySelectorAll("[data-reactive-editable][name]").forEach((i)=>{if(t.owns(i))o(i,t.text(i)!==t.served(i))}),r>0)n.setAttribute("data-reactive-dirty",String(r));else n.removeAttribute("data-reactive-dirty")}function Wi(e){if(e.type==="checkbox"||e.type==="radio")return e.checked!==e.defaultChecked;if(e.tag==="select"||e.options){let t=Array.from(e.options??[]),n=!e.multiple&&!(e.size>1),r=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(n?o===r:o.defaultSelected))}return e.value!==e.defaultValue}function rr(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function ji(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;t(window,"beforeunload",(n)=>{if(rr(e)===0)return;return n.preventDefault(),n.returnValue="You have unsaved changes.",n.returnValue}),t(window,"turbo:before-visit",(n)=>{if(rr(e)===0||nr.has(n))return;if(nr.add(n),!(typeof window.confirm==="function"?window.confirm("You have unsaved changes. Leave anyway?"):!0))n.preventDefault?.()})}function Bi(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let n=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let r of n)if(t.owns(r))return!0;return!1}function Ji(e,t){let n=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!n;for(let r of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(r))r.hidden=!n}function mt(e){Ui(e),zi(e)}function Ui(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(ft);else setTimeout(ft,0);return}let r=async(o)=>{await n(o),ft()};r.__reactiveDismissWrapped=!0,t.render=r}function ft(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let n=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(n)||n<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),n)}}var Hi=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),dt=Object.freeze(["fade","slide","scale","highlight","shake"]),pt="data-reactive-fx-pending",ht=1000;function zi(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Hi[r?.getAttribute?.("action")];if(!o||Ki())return;let i=Gi(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Zi(te(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Vi(r):null;if(await n(s),o==="enter")Xi(c,i);else sr(te(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Gi(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return ir(n,t);let o=(t==="enter"?Yi(e):te(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?ir(o,t):null}function te(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Yi(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function ir(e,t){if(e.startsWith("[")){let r=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)r=o.map(String)}catch{}if(r)return{legs:r};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let n=e==="random"?dt[Math.floor(Math.random()*dt.length)]:e;if(!dt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Ki(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Vi(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(pt,"");return te(e)}function Xi(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${pt}]`)))n.removeAttribute(pt),sr(n,t)}async function Zi(e,t){if(!e?.classList)return;if(t.legs){await ar(e,t.legs);return}e.classList.add(t.className);let n=gt(e);if(n<=0){e.classList.remove(t.className);return}await bt(e,n),e.classList.remove(t.className)}function sr(e,t){if(!e?.classList)return;if(t.legs){ar(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=gt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;bt(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function ar(e,t){let[n,r,o]=t.map(Qi),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await es(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=gt(e);if(a>0)await bt(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function Qi(e){return String(e??"").split(/\s+/).filter(Boolean)}function gt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,ht)}catch{return 0}}function bt(e,t){return new Promise((n)=>{let r=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",r),e.removeEventListener?.("transitionend",r),n()};e.addEventListener?.("animationend",r),e.addEventListener?.("transitionend",r),setTimeout(r,Math.min(t+50,ht))})}function es(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},ht),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var ts="phlex-reactive:latency",yt=!1;function lr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function fr(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),yt=!1}function At(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:lr,disableLatencySim:fr}}function wt(){if(typeof sessionStorage>"u")return Promise.resolve();let e=Number(sessionStorage.getItem("phlex-reactive:latency"));if(!Number.isFinite(e)||e<=0)return Promise.resolve();if(!yt)yt=!0,console.warn(`[phlex-reactive] latency simulator ACTIVE — every action is delayed by ${e}ms. Call PhlexReactive.disableLatencySim() (or clear sessionStorage) to turn it off.`);return new Promise((t)=>setTimeout(t,e))}var ur=new WeakMap;function St(e){let t=globalThis.document;if(!t)return!0;let n=ur.get(t);if(!n)n=new Set,ur.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function vt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function dr(e,t,n,r){if(St(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function Et(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=vt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}dr(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function _t(e){if(!St(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function xt(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(vt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=vt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}dr(t,o,`scoped to #${r?.id||"?"}`,i)}function Tt(e,t){let n=e.element?.id||"?";if(St(`no-binding|${t.type}|${n}`))return;console.warn(`[phlex-reactive] runOps on #${n} found no on_client binding matching a "${t.type}" event — nothing ran`)}function ns(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function kt(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function ne(e,t,n){e.streams=ns(t),e.tokenRefreshed=n!=null}var re=new WeakMap;function Rt(e,t,n,r){let o=n&&typeof n==="object"?is(n):n;return o?mr(t,o,r,!1):[]}function Lt(e,t,n,r){if(!n)return null;let o=mr(t,n,r,!0);return o.length?o:null}function mr(e,t,n,r){let o=[];for(let i of hr(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(rs(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function hr(e,t,n){if(t.to==null)return n?[n]:[];let r=e.opTargets({to:t.to});if(r.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return r}function rs(e,t){let n=re.get(t);if(n)n.count++;else re.set(t,{count:1,disabled:t.disabled,html:t.innerHTML,hadText:e.text!=null,swappedTo:e.text});if(e.disable)t.disabled=!0;if(e.text!=null)t.innerHTML=e.text;return()=>os(t,e)}function os(e,t){let n=re.get(e);if(!n)return;if(--n.count>0)return;if(re.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function is(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function Ft(e,t,n,r){if(!n?.hide)return null;let o=hr(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var se;function Ct(e){se=e}var E=new Map;function vr(e,t){let n=!E.has(e);if(E.set(e,t),n)se.enter()}function ae(e){if(E.delete(e))se.exit()}var br=!1;function Mt(e){Ar();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){fs(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;j(t,n)}function Ar(){if(br||typeof document>"u"||!document.addEventListener)return;br=!0,document.addEventListener("turbo:before-stream-render",ps,!0),document.addEventListener("turbo:before-stream-render",ss)}function ss(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(E.get(n)?.via==="stream")ae(n)}function j(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}$t(e),_r(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return vr(e,r),ds(e,r,t)}function as(e,t){if(typeof e!=="string"){let n={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)n.cache="no-store";return[e.src,n]}return[hs(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":gs()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function wr(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Sr(t))return{src:t};return console.error(cs(t)),us(t)||ls(e)}function cs(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Pt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function us(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Pt()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Sr(r))return{src:r,fallback:!0}}function ls(e){$t(e.id),It(e),e.setAttribute("data-reactive-error","defer"),e.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e.id,reason:"refused-url"}}))}function Sr(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Pt()}/`)}catch{return!1}}function Pt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function fs(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let r=t.getAttribute("data-reactive-defer-src");if(!r)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){j(e,i);return}console.error("[phlex-reactive] reactive:defer via=stream but <pgbus-stream-source> is not registered "+"and no fallback token was provided — is the pgbus client loaded on this page?");return}$t(e),_r(n);let o=document.createElement("pgbus-stream-source");o.id=Er(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),vr(e,{via:"stream"})}function Er(e){return`reactive-defer-src-${e}`}async function ds(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},bs()),o;try{se.count("defer"),o=await fetch(...as(n,t.abort.signal))}catch(s){if(clearTimeout(r),E.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),W(e,n);return}if(E.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),W(e,n,o.status);return}if(o.status===204){clearTimeout(r),yr(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),W(e,n,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),W(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),E.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),W(e,n);return}if(clearTimeout(r),E.get(e)!==t)return;yr(e),ms(a)}var Nt=null,ps=(e)=>Nt?.push(e);function ms(e){let t=Nt=[];try{window.Turbo.renderStreamMessage(e)}finally{Nt=null}for(let n of t){if(n.defaultPrevented)continue;let r=n.detail,o=r.render;r.render=()=>{},new Promise((i)=>i(o(r.newStream))).catch(console.error)}}function $t(e){let t=E.get(e);if(!t)return;if(ae(e),t.via==="fetch")t.abort.abort();else document.getElementById(Er(e))?.remove?.()}function _r(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function It(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function yr(e){ae(e);let t=document.getElementById(e);if(!t)return;It(t),t.removeAttribute("data-reactive-error")}function W(e,t,n){ae(e);let r=document.getElementById(e);if(!r)return;It(r),r.setAttribute("data-reactive-error","defer");let o=()=>{let i=document.getElementById(e);if(!i){console.warn("[phlex-reactive] defer retry() ignored — the target left the DOM");return}i.removeAttribute("data-reactive-error"),j(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function hs(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function gs(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function bs(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var xr="__materialize",ie=new WeakMap;function oe(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function Dt(e,t,n){Ar();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>ce(e),p=(d)=>{if(oe(r)==="visible"){if(!a)g()}else if(d){let y=r.getAttribute("data-reactive-lazy-on");if(s===y)return;m(),r.addEventListener?.(y,l),s=y}},m=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},g=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let d=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((y)=>{if(y.some((w)=>w.isIntersecting))l()},{rootMargin:d}),a.observe(r)},b=()=>{let d=oe(r)!==null,y=o;if(o=d,!d)return m();if(i)return;if(t.forgetToken(),!y)return l();p(!0)};if(ie.set(e,{load(){if(i)return;let d=wr(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&ys(r,t))return;let y=d?j(r.id,d):t.proceed(r,xr,"{}");if(!y)return;i=!0,m();let w=()=>{i=!1};return y.then(w,w),y},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);m()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&oe(r)===null)Ot(r),c=(d)=>d.target===r&&Ot(r),r.addEventListener?.("turbo:morph-element",c);if(r.getAttribute?.("data-reactive-token-value")==null&&r.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(d)=>{if(d.target!==r)return;if(!c)Ot(r);b()},r.addEventListener?.("turbo:morph-element",u),n)return b();if(o=oe(r)!==null,o)p(!1)}function qt(e){let t=ie.get(e);ie.delete(e),t?.off()}function ce(e){return ie.get(e)?.load()}function ys(e,t){return t.emit("reactive:before-dispatch",{action:xr,params:{},element:e},{cancelable:!0}).defaultPrevented}function Ot(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||wr(e);if(t)j(e.id,t)}var Wt=new WeakMap,le=new WeakMap,f=null,k,kr;function Ut(e,t){let n=e.element;le.set(n,t),$r();let r=(i)=>As(i,t),o=(i)=>xs(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),Wt.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function Ht(e){if(Wt.get(e)?.(),Wt.delete(e),le.delete(e.element),f&&fe(f.origin)===e.element)ue()}var A=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),B=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},fe=(e)=>e?.closest?.('[data-controller~="reactive"]'),Or=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==f?.row&&Or(t)===e),Rr=(e)=>B(A(e,"-item"),null),jt=(e)=>A(e,"-disabled")==="true",vs=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Nr=(e)=>{let t=A(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>A(n,"-group")===t&&!jt(n)&&le.has(fe(n)))};function Cr(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Or(n);if(f||!r||!t.owns(r)||jt(r)||jt(n))return;if(fe(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function As(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Cr(e.target,t);if(!n)return;let r=A(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(d)=>d.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(d)=>{if(!a(d))return;if(f)return Bt(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return h();Ss(n,t,d),Bt(d.clientX,d.clientY)},p=(d)=>f&&d.cancelable&&d.preventDefault(),m=(d)=>{if(!a(d))return;if(h(),f)ws(),Jt()},g=(d)=>{if(d.type==="pointercancel"&&!a(d))return;if(h(),f)ue()},v=[["pointermove",l],["pointerup",m],["pointercancel",g],["keydown",(d)=>d.key==="Escape"&&f&&(d.preventDefault(),g(d))],["touchmove",p,{passive:!1}]];for(let[d,y,w]of v)document.addEventListener(d,y,w);function h(){clearTimeout(u);for(let[d,y]of v)document.removeEventListener(d,y)}}function ws(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Ss({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,f=Mr({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),f.dx=r.clientX-o.left,f.dy=r.clientY-o.top,f.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function Mr(e){let{row:t,origin:n,source:r}=e;return e.index=T(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),J(n,!0),e}var J=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function de(e,t,n,r){if(t[n])t[n].before(r);else if(t.length)t.at(-1).after(r);else e.append(r)}function Bt(e,t){f.x=e,f.y=t,f.row.style.left=`${e-f.dx}px`,f.row.style.top=`${t-f.dy}px`;let n=Nr(f.origin).find((r)=>vs(r,e,t));if(n)Es(n,e,t);else if(f.source)zt(null),f.placeholder.remove();_s(e,t)}function zt(e){if(f.target!==f.origin)J(f.target,!1);f.target=e,J(e,!0)}function Es(e,t,n){zt(e);let r=T(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});de(e,r,s<0?r.length:s,f.placeholder)}function _s(e,t){let n=f.target??f.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(f.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,f.wy=t<40?-12:t>window.innerHeight-40?12:0,(f.vy||f.wy)&&!f.raf){let i=()=>{if(!f||!(f.vy||f.wy))return f&&(f.raf=0);if((f.target??f.origin).scrollTop+=f.vy,f.wy)window.scrollBy(0,f.wy);Bt(f.x,f.y),f.raf=requestAnimationFrame(i)};f.raf=requestAnimationFrame(i)}}function xs(e,t){let n=e.key;if(f?.keyboard){if(e.target!==f.row||f.core!==t)return;let o={" ":Jt,Enter:Jt,Escape:ue,Tab:ue,ArrowUp:()=>Lr(-1),ArrowDown:()=>Lr(1),ArrowLeft:()=>Fr(-1),ArrowRight:()=>Fr(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Cr(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),f=Mr({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),me("picked")}function Lr(e){let t=T(f.target),n=pe()+e;if(n>=0&&n<=t.length)de(f.target,t,n,f.row);Pr()}function Fr(e){let t=Nr(f.origin),n=t[t.indexOf(f.target)+e];if(n){let r=pe();zt(n),de(n,T(n),r,f.row)}Pr()}function Pr(){f.row.focus?.(),me("moved")}function pe(){let e=T(f.target),t=f.keyboard?f.row:f.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function $r(){if(!k?.isConnected)k=document.createElement("div"),k.setAttribute("aria-live","polite"),k.setAttribute("data-reactive-sortable-live",""),k.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(k);return k}function me(e){let t=f.target??f.origin,n=(B(A(t,"-messages"),{})[e]??"").replaceAll("{position}",pe()+1).replaceAll("{count}",T(t).length+1),r=$r();r.textContent="",cancelAnimationFrame(kr),kr=requestAnimationFrame(()=>r.textContent=n)}function Jt(){let e=f,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?pe():-1,c=a?Rr(T(t)[s-1]):null;if(e.keyboard)me("dropped");if(!r&&i)i.replaceWith(o);if(Dr(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?A(n,"-source"):A(n,"-name")??"list",l=B(A(t,"-from"),{})[u]??A(t),p={...B(A(t,"-params"),{}),item:Rr(e.item),position:s,after:c,from:u},m=[];for(let b=t;b;b=b.parentElement)m.push(b);let g=le.get(fe(t))?.proceed(t,l,JSON.stringify(p),B(A(t,"-busy")));if(r)return;Promise.resolve(g).then((b)=>Ts(b,m)||Ir(e))}function Ts(e,t){if(!e)return!1;let n=document.createElement("template");return n.innerHTML=e,[...n.content.querySelectorAll("turbo-stream")].some((r)=>/^(replace|update)$/.test(r.getAttribute("action"))&&ks(r,t))}function ks(e,t){let n=e.getAttribute("target");if(n)return t.some((o)=>o.id===n);let r=e.getAttribute("targets");try{return Boolean(r)&&t.some((o)=>o.matches(r))}catch{return!1}}function ue(){let e=f;if(e.keyboard)me("cancelled");e.placeholder?.remove(),Dr(e),Ir(e)}function Ir({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(de(t,T(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function Dr(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(f=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),J(n,!1),J(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var R=new Map,Wr=new WeakSet;function Gt(e,t){let n=e.element,r=R.get(n.id);if(!r)R.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Rs(n);let o=(a)=>a.target===n&&queueMicrotask(()=>Br(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},Br(r)}function Yt(e){let t=e.element,n=R.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;R.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function Kt(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=R.get(e.id);if(!n)R.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},Jr(n)}function Rs(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&Wr.has(n))return;if(n?.remove(),!jr())setTimeout(()=>{if(!jr())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=R.get(e.id);if(!o||o.removing)return;Jr(o),Ls(o)}),Wr.add(r),document.body.appendChild(r)}var jr=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Ls(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&Ur(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function Jr(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function Ur(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function Br(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=Ur(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}function Os(){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 Ns(){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 Cs(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=pn(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)_t(n);return}cn(t,(i)=>da(i,o),r?(i,a)=>Et(i,a,o):void 0)}}function Ms(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){Mt(this)}}var Gr=!1,Ps=null;function $s(){if(Gr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Gr=!0,document.addEventListener("turbo:before-stream-render",(e)=>{Is(e),qs(e),mt(e)})}var ge="reactive:streamed";function Is(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(ge))}}function un(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function ln(e){try{return e.matches(":modal")}catch{return!1}}function ho(e){if(!un(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||ln(e))return;if(e.open)e.close();e.showModal()}function Ds(e){if(un(e)&&e.open)e.close()}function ve(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&&!ln(r))ho(r)}function qs(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(o)=>{await n(o),ve(document)}}var Yr=!1;function Ws(){if(Yr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Yr=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))ve(t.target)}),document.addEventListener("turbo:morph",()=>ve(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!un(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||!ln(n))return;e.delete(n),t.preventDefault(),n.close()})}function Na(e){Ps=e}var he,Vt=null,Kr="[data-reactive-editable][contenteditable=plaintext-only]";function go(){if(he===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",he=e.contentEditable==="plaintext-only"}catch{he=!1}return he}function be(e){if(e.matches?.(Kr))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Kr).forEach(be)}function js(){if(Vt||typeof document>"u"||typeof document.createElement!=="function")return;if(go())return;be(document),Vt=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")be(t.target);else t.addedNodes.forEach(be)}),Vt.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Vr=!1;function Xt(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 Bs(){if(Vr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Vr=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;if(t.hasAttribute?.("data-reactive-editable")){if(Ae.set(t,U(n)),!Xt(t))return;for(let{name:o}of[...t.attributes])if(!n.hasAttribute(o)&&o!=="contenteditable")t.removeAttribute(o);for(let{name:o,value:i}of n.attributes)if(o!=="contenteditable"&&t.getAttribute(o)!==i)t.setAttribute(o,i);return e.preventDefault()}if(t.localName!=="input"||!Xt(t))return;let r=n.getAttribute("value");if(r==null)t.removeAttribute("value");else if(t.getAttribute("value")!==r)t.setAttribute("value",r)}),document.addEventListener("focusin",(e)=>dn(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{if(e.detail?.attributeName==="value"&&Xt(e.target))e.preventDefault()})}var Js="__materialize",Xr=!1;function Us(){if(Xr)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Xr=!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)}function fn(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")At()}var bo="data-reactive-active",_=0;function yo(){if(_++,_===1)Ao("reactive:busy")}function vo(){if(_===0)return;if(_--,_===0)Ao("reactive:idle")}function Ca(){return _}function Ma(){_=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(bo)}function Ao(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(bo,_>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:_}}))}var wo="data-reactive-requests";function So(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Hs(t))return;let n=zs(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(wo,JSON.stringify(n))}function Hs(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function zs(e){try{let t=JSON.parse(e.getAttribute(wo));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Zr(){Os(),Ns(),Cs(),Ms(),$s(),Bs(),Ws(),js(),Us(),fn()}function Gs(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Eo=Symbol.for("phlex-reactive.core");if(globalThis[Eo])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[Eo]=!0;var _o=!1;function Ys(){if(_o)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(Ys,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Ks=new Set(["href","src","srcdoc","action","formaction","xlink:href","style"]);function Vs(e){let t=String(e).toLowerCase();return t.startsWith("on")||Ks.has(t)}var Zt=new WeakMap;function Xs(e,t,n){let[r,o,i]=t;Zt.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,Zt.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Zt.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Zs(e))}function Zs(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Qs=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",ea=new Set(["lexxy-editor","trix-editor"]);function U(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as da}from"@hotwired/stimulus";import{confirmResolver as fo}from"phlex/reactive/confirm";import{confirmPredicate as ai}from"phlex/reactive/confirm_predicate";var C=new WeakMap,Ce=new WeakMap;function k(e,t){let n=C.get(e);if(!n){if(C.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)Ce.set(n.root,n)}return n}function E(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function I(e,t){E(e,"turbo:morph-element",t),e.seeds.push(t),t()}function Me(e,t){let n=k(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&di(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")wi(n,s.target);else n.groups=Ai(n),$n(n);hi(n)},E(n,"input change",n.show),I(n,n.show);if(!n.arm&&pi(n))E(n,"input change",(s)=>On(n,s)),I(n,n.arm=()=>{On(n,null),$n(n)});if(!r&&(r=n.show||n.arm))E(n,"reset",()=>setTimeout(()=>{if(C.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=ee(n)))E(n,"input",(s)=>_i(n,s)&&D(n)),I(n,()=>D(n));if(!i&&(i=ne(n)))I(n,()=>Gn(n));if(!a&&(a=xi(n)))E(n,"input change",(s)=>Xn(n,s)),I(n,()=>Je(n))})(),E(n,"keydown",(s)=>Wi(n,s)),E(n,"paste drop",(s)=>ji(n,s)),E(n,"input",(s)=>Bi(n,s))}function $e(e){let t=C.get(e);if(!t)return;C.delete(e),Ce.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Pe(e){let t=C.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function M(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Ie(e,t,n){return Xn(k(e,t),n)}function De(e,t,n){return rr(k(e,t),n)}var ci=/^#[A-Za-z_][\w-]*$/,In="[data-reactive-show-field], [data-reactive-show]";function ui(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of Zn){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return tr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Dn(e){try{let t=JSON.parse(e);if(t&&typeof t==="object"&&!Array.isArray(t))return t}catch{}return console.warn(`[phlex-reactive] malformed compound reactive_show payload ${JSON.stringify(e)} — skipped`),null}function li(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function qn(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return q(n,t);return fi(e,t)}function fi(e,t){let n=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!n)return null;let r=e[n];if(r.length===0)return null;let o=r.map((i)=>Ye(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function Q(e,t="show"){if(typeof e==="string"&&ci.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function di(e){if(e.root.getAttribute?.("data-reactive-show-targets"))return!0;if(e.root.getAttribute?.("data-reactive-group-targets"))return!0;let t=e.root.querySelectorAll?.(In)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(te)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(Jn)??[])if(e.core.owns(n))return!0;return!1}function pi(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function mi(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:li(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function On(e,t){let n=mi(e);if(!n.length)return;let r=Bn(e,e.core.ownership());n.forEach((o,i)=>{let a=q(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function hi(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=Bn(e,t);for(let o of e.root.querySelectorAll(In)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=qn(Dn(i),r);if(u!==null)Nn(o,u,t,n);continue}let a=o.getAttribute("data-reactive-show-field");if(!a)continue;let s=r(a);if(s===null)continue;let c=ui(o,s);if(c===null)continue;Nn(o,c,t,n)}if(e.groups)Si(e,r,t,n);yi(e,r,t),gi(e,r),Ei(e,r)}function Nn(e,t,n,r){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let o of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(o))o.disabled=!t;if(e.name&&n(e))e.disabled=!t}function gi(e,t){let n=Wn(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){bi(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!Q(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>Ye(l,a))}else{let l=nr(c,i);if(l===null){console.warn(`[phlex-reactive] malformed reactive_show_targets predicate for ${s} — skipped`);continue}u=l}for(let l of document.querySelectorAll(s))l.hidden=!u}}}function bi(e,t,n){if(!Q(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Di(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!qi(r))return;let i=q(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function Wn(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function vi(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(jn(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function jn(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function Bn(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?qe(e,o,t,n).filter((s)=>s.checked).length:vi(e,o,t,n));return r.get(a)}}var Jn="[data-reactive-media]";function yi(e,t,n){for(let r of e.root.querySelectorAll(Jn)){if(!n(r))continue;let o,i;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let a=t(o.field);if(a===null)continue;let s=o.take>0?[...a]:null,c=s?s.slice(0,o.take).join(""):a,u=s?.length<o.take||i?.test(c)===!1;if(u&&o.pending==="keep"){Cn(r,"pending");continue}let l=!u&&Object.hasOwn(o.pool,c)?Mn(e,o.pool[c])[0]:null,p=e.core.copyMedia(r,l??null);if(p===null)continue;if(Cn(r,u?"pending":p===!1?"miss":"hit"),typeof o.label!=="string")continue;let m=u?"":p===!1?String(o.blank??""):p;for(let b of Mn(e,o.label))if(b.textContent!==m)b.textContent=m}}function Cn(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function Mn(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var te="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Ai(e){return!!e.root.querySelector?.(te)}function qe(e,t,n,r){return[...e.root.querySelectorAll(jn(t,r))].filter((o)=>o.type==="checkbox"&&n(o))}function wi(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Un(e,n,t.checked,t)}function We(e,t,n){if(!t)return;let r=Ce.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Un(r,t,n!==!1),r.show?.()}function Un(e,t,n,r){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=qe(e,t,e.core.ownership(),o).filter((a)=>a!==r&&a.checked!==n);for(let a of i)a.checked=n;e.flipping=!0;try{for(let a of i)for(let s of["input","change"])a.dispatchEvent?.(new Event(s,{bubbles:!0}))}finally{e.flipping=!1}}function Si(e,t,n,r){for(let o of e.root.querySelectorAll(te)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=qn(Dn(i),t);if(c!==null)o.disabled=!c}let a=o.getAttribute("data-reactive-count");if(a){let c=String(t(a,!0));if(o.textContent!==c)o.textContent=c}let s=o.getAttribute("data-reactive-select-all");if(s){let c=qe(e,s,n,r).filter((l)=>l!==o),u=c.filter((l)=>l.checked).length;o.checked=u>0&&u===c.length,o.indeterminate=u>0&&u<c.length}}}function Ei(e,t){for(let[n,r]of Object.entries(Wn(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!Q(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!Q(a,"group"))continue;let c=q(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function $n(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${te}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let r=(o)=>o.nodeType===1&&(o.matches('input[type="checkbox"]')||!!o.querySelector('input[type="checkbox"]'));e.groupObserver=new MutationObserver((o)=>{if(!o.some((i)=>[...i.addedNodes,...i.removedNodes].some(r)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function ee(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function _i(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}function D(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=(o.value??"").trim().toLowerCase(),a=0;for(let u of e.root.querySelectorAll(n)){if(!r(u))continue;let l=(u.getAttribute("data-reactive-filter-text")??u.textContent??"").toLowerCase(),p=u.hasAttribute?.("data-reactive-tags-selected")||i!==""&&!l.includes(i);if(u.hidden=p,p)u.removeAttribute("data-reactive-highlighted");else a++}let s=e.root.getAttribute("data-reactive-filter-group");if(s)for(let u of e.root.querySelectorAll(s)){if(!r(u))continue;let l=[...u.querySelectorAll(n)].filter(r);if(l.length===0)continue;u.hidden=l.every((p)=>p.hidden)}let c=e.root.getAttribute("data-reactive-filter-empty");if(c){for(let u of e.root.querySelectorAll(c))if(r(u))u.hidden=a>0}}function ne(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function xi(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function je(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Be(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function Hn(e,t){let n=je(e);if(!n)return!1;let r=Be(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)zn(e,n,r);return i}function zn(e,t,n){t.value=n.join(","),M(t),Gn(e)}function ki(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Gn(e){let t=je(e);if(!t)return;let n=Be(t),r=e.core.ownership();Ti(e,n,r),Li(e,n,r)}function Ti(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Li(e,t,n){let r=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!n(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(r.has(i.toLowerCase()))o.setAttribute("data-reactive-tags-selected","true"),o.hidden=!0,o.removeAttribute?.("data-reactive-highlighted");else if(o.hasAttribute?.("data-reactive-tags-selected")){if(o.removeAttribute("data-reactive-tags-selected"),!ee(e))o.hidden=!1}}if(ee(e))D(e)}function Ri(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Fi(e,t){let n=[e,...e.querySelectorAll?.("*")??[]];for(let r of n)for(let o of["name","id","for"]){let i=r.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))r.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Oi(e,t){if(e.nestedWarned)return;console.warn(`[phlex-reactive] nested rows: no owned [data-reactive-nested-list="${t}"] container + <template data-reactive-nested-template="${t}"> pair found in this root — the add `+"trigger did nothing. Render both inside the same reactive root (reactive_nested_list / reactive_nested_template)."),e.nestedWarned=!0}function Ni(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let p=a.find((m)=>Yn(m.getAttribute?.("name"))===c);if(!p)continue;Ci(p,l),s.push(l)}if(r)for(let c of s)Mi(c);return s[0]??null}function Ci(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Ne(t)!=="";else e.value=Ne(t);M(e)}function Mi(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function $i(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Pn(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",M(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);Je(e)}function Je(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))Vn(e,n.getAttribute("data-reactive-nested-json"))}function Pi(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function Kn(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=Yn(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Ne(o)}return n}function Yn(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Ne(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Vn(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=Pi(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(Kn(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function Ue(e,t,n){let r=k(e,t);if(!ne(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!Hn(r,String(o.value??"").split(",")))return;if(o.value="",ee(r))D(r)}function He(e,t,n){let r=k(e,t);if(!ne(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Hn(r,[i]))return;let a=ki(r);if(!a)return;a.value="",D(r),a.focus?.()}function ze(e,t,n){let r=k(e,t);if(!ne(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=je(r);if(!a)return;let s=Be(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;zn(r,a,c)}function Ge(e,t,n){let r=k(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Oi(r,i);return}let l=u.cloneNode(!0);Fi(l,Ri(r)),s.appendChild(l);let p=o?.getAttribute?.("data-reactive-nested-from-param"),m=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",b=Ni(r,l,p,m);if(p)b?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Vn(r,i)}function Ke(e,t,n){let r=k(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?rr(r,s):null);if(!c)return Pn(r,i);let u=Kn(r,i),l=$i(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((p)=>{if(p)Pn(r,i)})}function Xn(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;Je(e)}var Zn=["gte","gt","lte","lt"],Ii=["len_eq","len_gte","len_gt","len_lte","len_lt"],Qn=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function er(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function tr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function nr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Zn)if(n in e)return tr(n,e[n],t);for(let n of Ii)if(n in e)return er(n,e[n],[...String(t??"")].length);return null}function Ye(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Qn.find((o)=>(o in e));if(n){let o=t(e.field,!0);return er(n,e[n],Array.isArray(o)?o.length:Number(o)||0)===!0}let r=t(e.field)??"";return nr(e,r)===!0}function q(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>Ye(r,t)))}function Di(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let n of e){if(!Array.isArray(n))continue;for(let r of n)if(r&&typeof r==="object"&&typeof r.field==="string")t.add(r.field)}return t.size>0?[...t]:null}function qi(e){return e.flat().every((t)=>Qn.some((n)=>(n in Object(t))))}function rr(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=ai(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=q(n.groups?.any,o)===!0;return i?n.message:null}function Ve(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function Wi(e,t){let n=Ve(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),M(n),n.blur()}function ji(e,t){let n=Ve(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||e.core.plain()&&!(r&&/[\r\n]/.test(o)))return;if(t.preventDefault(),r)o=o.replace(/\r?\n|\r/g," ");n.focus(),document.execCommand("insertText",!1,o)}function Bi(e,t){let n=Ve(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as Ji}from"phlex/reactive/compute";var j=new WeakMap;function ar(e,t){let n=j.get(e);if(!n)j.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Ze(e,t,n,r){let o=ar(e,t),i=os(o);if(i)o.seed=()=>Xe(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)Xe(o)}function Qe(e){let t=j.get(e);if(!t)return;if(j.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function et(e){j.get(e)?.seed?.()}function tt(e,t,n){return Xe(ar(e,t),n)}var Ui=Object.freeze({el:null,kind:""}),Hi=/^#[A-Za-z_][\w-]*$/;function W({el:e,kind:t}){if(!e)return"";if(t==="checkbox")return e.checked?"true":"false";if(t==="radio")return e.checked?e.value??"":"";return e.value??""}function cr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function zi(e,t){if(t==="string")return W(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):cr(W(e));if(n)return e.el.checked?1:0;let r=Number(W(e));return Number.isFinite(r)?r:0}function Gi(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=cr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return Ki(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function Ki(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function Yi(e){if(e==null)return null;let t=Array.isArray(e)?e:e.ops;if(Array.isArray(t))return t.length>0?t:null;return console.warn("[phlex-reactive] $ops must be an ops chain or a [[op, args], ...] list — skipped"),null}function Vi(e){if(typeof e==="string"&&Hi.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function Xi(e,t,n){let r=t===null?null:JSON.stringify(t),o=r!==null&&r!==e.opsSig&&n;if(e.opsSig=r,!o)return;e.core.applyOps(t,"@root")}function Zi(e,t){let n=e.root.getAttribute(t);if(!n)return[];try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function Qi(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let n=JSON.parse(t);if(Array.isArray(n))return n.map((r)=>[r,"number"]);if(n&&typeof n==="object")return Object.entries(n);return[]}catch{return[]}}function es(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=ts(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function ts(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function ir(e,t,n){let r=String(n);for(let o of ns(e,t)){if(o.textContent===r)continue;o.textContent=r}}function ns(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function sr(e,t,n){let r=rs(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?W(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!Vi(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function rs(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let n=JSON.parse(t);return n&&typeof n==="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function os(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function Xe(e,t){if(t&&e.ours.has(t))return;let n=Qi(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.ownership(),s=new Map,c=(h)=>{let d=s.get(h);if(d)return d;let v=null,A=null,O=null;for(let N of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(N))continue;let Z=N.type;if(Z==="checkbox"||Z==="radio"&&N.checked){O={el:N,kind:Z};break}if(Z==="radio")v??=N;else A??=N}if(!O)if(v)O={el:v,kind:"radio"};else O=A?{el:A,kind:""}:Ui;return s.set(h,O),O};for(let h of r)ir(e,h,W(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?Ji(u):null;if(!l){sr(e,{},c);return}let p=Zi(e,"data-reactive-compute-outputs-param"),m={};for(let[h,d]of n)m[h]=zi(c(h),d);let b=l(m,{changed:es(e,t,r,o)})||{},g=Yi(b.$ops),y=[];for(let h of p){if(h==="$ops"||!(h in b))continue;let d=c(h);if(!d.el)continue;let v=Gi(e.root,a,d,i(h),b[h]);if(v)y.push(v)}for(let h of Object.keys(b)){if(h==="$ops")continue;let d=b[h];if(d===void 0||d===null)continue;ir(e,h,d)}sr(e,b,c);for(let h of y){let d=new Event("input",{bubbles:!0});e.ours.add(d),h.dispatchEvent(d)}Xi(e,g,Boolean(t))}var it;function st(e){it=e}var pr=1,is="phlex-reactive:persist:",ss=new Set(["hidden","file","password","submit","button","reset","image"]),at=Symbol("persist-no-value"),ct="data-reactive-persist-state",as=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",cs=new Set(["lexxy-editor","trix-editor"]),us="lexxy-editor, trix-editor, trix-toolbar",ls=["lexxy:change","trix-change"],fs=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),lr=new WeakSet,fr=new WeakSet,dr=new WeakSet;function oe(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let n=JSON.parse(t);if(n&&typeof n==="object"&&typeof n.key==="string"&&n.key!=="")return n}catch{}if(!lr.has(e))lr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function ut(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function lt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||fr.has(e))return;fr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function ft(e){return is+e.key}function rt(e,t){let n=ut();if(!n)return null;let r;try{r=n.getItem(ft(t))}catch(c){return lt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==pr)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return re(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function mr(e,t,{fields:n,state:r}){let o=ut();if(!o)return!1;let i={v:pr,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(ft(t),JSON.stringify(i)),!0}catch(a){return lt(e,a),!1}}function re(e,t){e?.removeAttribute?.(ct);let n=ut();if(!n)return;try{n.removeItem(ft(t))}catch(r){lt(e,r)}}function dt(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||ss.has(i.type)||i.closest(us))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(as)){if(!o(i))continue;let a=ds(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:cs.has(i.localName)?"editor":"contenteditable"})}return r}function hr(e){return e.hasAttribute("data-reactive-editable")?it.text(e):e.textContent??""}function ds(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function pt(e){return typeof e.value==="string"}function ps(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return fs.has(e.value.trim())}function ms(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||dr.has(e))return;dr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function B(e){return e.tagName==="SELECT"&&e.multiple}function gr(e){let t=new Map;for(let{el:n,name:r}of e){if(n.type==="radio"||!String(r).endsWith("[]"))continue;t.set(r,(t.get(r)??0)+1)}return t}function br(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return at;return e[0]}function vr(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of dt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(pt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=hr(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(B(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function hs(e,t,n){let r=t.restore==="always",o=dt(e,t),i=gr(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&B(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||B(s))){if(l=br(l,c,i),l===at)continue}if((s.type==="checkbox"||B(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")yr(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&hr(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((p)=>p.kind==="native"&&p.el.type==="radio"&&p.name===c&&p.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(B(s)){if(!r&&[...s.options].some((m)=>m.selected))continue;let p=new Set((Array.isArray(l)?l:[l]).map(String));for(let m of s.options)m.selected=p.has(m.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}gs(e,t,n)}function yr(e,t,n,r,o){if(Array.isArray(r))return;if(!pt(t))return;if(!o&&!ps(t))return;try{t.value=String(r)}catch(i){ms(e,n,i)}}function gs(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!pt(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=dt(e,t),c=gr(s);for(let{el:u,name:l,kind:p}of s){if(p!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let m=br(n[l],l,c);if(m===null||m===void 0||m===at)continue;yr(e,u,l,m,i)}})}function bs(e,t,n=!0){let r=oe(e);if(!r){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=rt(e,r),i={...o?.state??{},...t},a=n?vr(e,r):o?.fields??{};if(mr(e,r,{fields:a,state:i}))e.setAttribute?.(ct,JSON.stringify(i))}function vs(e){let t=oe(e);if(t)re(e,t)}var ot=new WeakMap,nt=new WeakMap;function ys(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=nt.get(e);if(!n){let i=new Set,a=(s)=>{for(let c of i)c(s)};e.addEventListener("turbo:submit-end",a),n=[i,a],nt.set(e,n)}let[r,o]=n;return r.add(t),()=>{if(r.delete(t),r.size>0)return;e.removeEventListener?.("turbo:submit-end",o),nt.delete(e)}}function mt(e,t,n,r){let o=e.element,i=oe(o);if(!i)return;if(r?.submitted)re(o,i);let a=rt(o,i);if(a){if(hs(o,i,a.fields),a.state)o.setAttribute?.(ct,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let g=rt(o,i);mr(o,i,{fields:vr(o,i),state:g?.state??null})},l=()=>{let g=Number(i.debounce)||0;if(g<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},g)},p=(g)=>{if(!g?.detail?.success)return;let y=g.target;if(y?.tagName!=="FORM"||typeof y.contains!=="function")return;if(!y.contains(o))return;c(),re(o,i)},m=["input",...ls];for(let g of m)o.addEventListener?.(g,l);o.addEventListener?.("change",u);let b=ys(globalThis.document,p);if(ot.set(e,()=>{if(s!==null)u();for(let g of m)o.removeEventListener?.(g,l);o.removeEventListener?.("change",u),b()}),r?.edited&&!r.submitted)u();for(let g of r?.ops??[])g(!0)}function ht(e){let t=ot.get(e);ot.delete(e),t?.()}function Ar(e,t){let n=it?.waiting.get(e)?.persist;if(!n||!oe(e))return t(!0);(n.ops??=[]).push(t)}function gt(e,t){Ar(e,(n)=>bs(e,t,n))}function bt(e){Ar(e,()=>vs(e))}var ie=new WeakMap,Sr=new WeakSet,vt=new WeakMap;function yt(e,t){let n=e.element,r=[],o=[],i=(u,l,p)=>{u.addEventListener?.(l,p),r.push(()=>u.removeEventListener?.(l,p))},a,s,c=()=>{if(!a&&(a=As(n,t))){let u=()=>se(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Es(n,r)}if(!s&&(s=_s(n,t))){let u=()=>xs(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};ie.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function At(e){for(let t of ie.get(e)?.[0]??[])t();ie.delete(e)}function wt(e){ie.get(e)?.[1]()}function As(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let n=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let r of n)if(t.owns(r))return!0;return!1}function se(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,ws(i))}),n.querySelectorAll("[data-reactive-editable][name]").forEach((i)=>{if(t.owns(i))o(i,t.text(i)!==t.served(i))}),r>0)n.setAttribute("data-reactive-dirty",String(r));else n.removeAttribute("data-reactive-dirty")}function ws(e){if(e.type==="checkbox"||e.type==="radio")return e.checked!==e.defaultChecked;if(e.tag==="select"||e.options){let t=Array.from(e.options??[]),n=!e.multiple&&!(e.size>1),r=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(n?o===r:o.defaultSelected))}return e.value!==e.defaultValue}function Ss(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Es(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=vt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(Ss(c)>0)return c;return null},a=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},s=(c)=>{if(Sr.has(c)||!i())return;if(Sr.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",a),n.addEventListener("turbo:before-visit",s),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",a),n.removeEventListener?.("turbo:before-visit",s),vt.delete(n)}},vt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function _s(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let n=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let r of n)if(t.owns(r))return!0;return!1}function xs(e,t){let n=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!n;for(let r of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(r))r.hidden=!n}function xt(e){ks(e),Ls(e)}function ks(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(St);else setTimeout(St,0);return}let r=async(o)=>{await n(o),St()};r.__reactiveDismissWrapped=!0,t.render=r}function St(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let n=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(n)||n<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),n)}}var Ts=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Et=Object.freeze(["fade","slide","scale","highlight","shake"]),_t="data-reactive-fx-pending",kt=1000;function Ls(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Ts[r?.getAttribute?.("action")];if(!o||Os())return;let i=Rs(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Ms(ae(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Ns(r):null;if(await n(s),o==="enter")Cs(c,i);else xr(ae(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Rs(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return _r(n,t);let o=(t==="enter"?Fs(e):ae(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?_r(o,t):null}function ae(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Fs(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function _r(e,t){if(e.startsWith("[")){let r=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)r=o.map(String)}catch{}if(r)return{legs:r};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let n=e==="random"?Et[Math.floor(Math.random()*Et.length)]:e;if(!Et.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Os(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Ns(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(_t,"");return ae(e)}function Cs(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${_t}]`)))n.removeAttribute(_t),xr(n,t)}async function Ms(e,t){if(!e?.classList)return;if(t.legs){await kr(e,t.legs);return}e.classList.add(t.className);let n=Tt(e);if(n<=0){e.classList.remove(t.className);return}await Lt(e,n),e.classList.remove(t.className)}function xr(e,t){if(!e?.classList)return;if(t.legs){kr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Tt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Lt(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function kr(e,t){let[n,r,o]=t.map($s),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Ps(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Tt(e);if(a>0)await Lt(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function $s(e){return String(e??"").split(/\s+/).filter(Boolean)}function Tt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,kt)}catch{return 0}}function Lt(e,t){return new Promise((n)=>{let r=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",r),e.removeEventListener?.("transitionend",r),n()};e.addEventListener?.("animationend",r),e.addEventListener?.("transitionend",r),setTimeout(r,Math.min(t+50,kt))})}function Ps(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},kt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Is="phlex-reactive:latency",Rt=!1;function Rr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Fr(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Rt=!1}function Ot(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:Rr,disableLatencySim:Fr}}function Nt(){if(typeof sessionStorage>"u")return Promise.resolve();let e=Number(sessionStorage.getItem("phlex-reactive:latency"));if(!Number.isFinite(e)||e<=0)return Promise.resolve();if(!Rt)Rt=!0,console.warn(`[phlex-reactive] latency simulator ACTIVE — every action is delayed by ${e}ms. Call PhlexReactive.disableLatencySim() (or clear sessionStorage) to turn it off.`);return new Promise((t)=>setTimeout(t,e))}var Lr=new WeakMap;function Ct(e){let t=globalThis.document;if(!t)return!0;let n=Lr.get(t);if(!n)n=new Set,Lr.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Ft(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function Or(e,t,n,r){if(Ct(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function Mt(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=Ft(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}Or(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function $t(e){if(!Ct(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function Pt(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Ft(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Ft(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}Or(t,o,`scoped to #${r?.id||"?"}`,i)}function It(e,t){let n=e.element?.id||"?";if(Ct(`no-binding|${t.type}|${n}`))return;console.warn(`[phlex-reactive] runOps on #${n} found no on_client binding matching a "${t.type}" event — nothing ran`)}function Ds(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function Dt(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function ce(e,t,n){e.streams=Ds(t),e.tokenRefreshed=n!=null}var ue=new WeakMap;function qt(e,t,n,r){let o=n&&typeof n==="object"?js(n):n;return o?Cr(t,o,r,!1):[]}function Wt(e,t,n,r){if(!n)return null;let o=Cr(t,n,r,!0);return o.length?o:null}function Cr(e,t,n,r){let o=[];for(let i of Mr(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(qs(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function Mr(e,t,n){if(t.to==null)return n?[n]:[];let r=e.opTargets({to:t.to});if(r.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return r}function qs(e,t){let n=ue.get(t);if(n)n.count++;else ue.set(t,{count:1,disabled:t.disabled,html:t.innerHTML,hadText:e.text!=null,swappedTo:e.text});if(e.disable)t.disabled=!0;if(e.text!=null)t.innerHTML=e.text;return()=>Ws(t,e)}function Ws(e,t){let n=ue.get(e);if(!n)return;if(--n.count>0)return;if(ue.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function js(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function jt(e,t,n,r){if(!n?.hide)return null;let o=Mr(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var de;function Ut(e){de=e}var _=new Map;function Dr(e,t){let n=!_.has(e);if(_.set(e,t),n)de.enter()}function pe(e){if(_.delete(e))de.exit()}var Pr=!1;function Ht(e){qr();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){Gs(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;U(t,n)}function qr(){if(Pr||typeof document>"u"||!document.addEventListener)return;Pr=!0,document.addEventListener("turbo:before-stream-render",Ys,!0),document.addEventListener("turbo:before-stream-render",Bs)}function Bs(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(_.get(n)?.via==="stream")pe(n)}function U(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}Gt(e),Jr(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Dr(e,r),Ks(e,r,t)}function Js(e,t){if(typeof e!=="string"){let n={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)n.cache="no-store";return[e.src,n]}return[Xs(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Zs()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Wr(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(jr(t))return{src:t};return console.error(Us(t)),Hs(t)||zs(e)}function Us(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${zt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function Hs(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${zt()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&jr(r))return{src:r,fallback:!0}}function zs(e){Gt(e.id),Kt(e),e.setAttribute("data-reactive-error","defer"),e.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e.id,reason:"refused-url"}}))}function jr(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${zt()}/`)}catch{return!1}}function zt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function Gs(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let r=t.getAttribute("data-reactive-defer-src");if(!r)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){U(e,i);return}console.error("[phlex-reactive] reactive:defer via=stream but <pgbus-stream-source> is not registered "+"and no fallback token was provided — is the pgbus client loaded on this page?");return}Gt(e),Jr(n);let o=document.createElement("pgbus-stream-source");o.id=Br(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Dr(e,{via:"stream"})}function Br(e){return`reactive-defer-src-${e}`}async function Ks(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Qs()),o;try{de.count("defer"),o=await fetch(...Js(n,t.abort.signal))}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),J(e,n);return}if(_.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),J(e,n,o.status);return}if(o.status===204){clearTimeout(r),Ir(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),J(e,n,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),J(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),J(e,n);return}if(clearTimeout(r),_.get(e)!==t)return;Ir(e),Vs(a)}var Jt=null,Ys=(e)=>Jt?.push(e);function Vs(e){let t=Jt=[];try{window.Turbo.renderStreamMessage(e)}finally{Jt=null}for(let n of t){if(n.defaultPrevented)continue;let r=n.detail,o=r.render;r.render=()=>{},new Promise((i)=>i(o(r.newStream))).catch(console.error)}}function Gt(e){let t=_.get(e);if(!t)return;if(pe(e),t.via==="fetch")t.abort.abort();else document.getElementById(Br(e))?.remove?.()}function Jr(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Kt(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Ir(e){pe(e);let t=document.getElementById(e);if(!t)return;Kt(t),t.removeAttribute("data-reactive-error")}function J(e,t,n){pe(e);let r=document.getElementById(e);if(!r)return;Kt(r),r.setAttribute("data-reactive-error","defer");let o=()=>{let i=document.getElementById(e);if(!i){console.warn("[phlex-reactive] defer retry() ignored — the target left the DOM");return}i.removeAttribute("data-reactive-error"),U(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function Xs(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Zs(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Qs(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Ur="__materialize",fe=new WeakMap;function le(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function Yt(e,t,n){qr();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>me(e),p=(d)=>{if(le(r)==="visible"){if(!a)b()}else if(d){let v=r.getAttribute("data-reactive-lazy-on");if(s===v)return;m(),r.addEventListener?.(v,l),s=v}},m=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},b=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let d=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((v)=>{if(v.some((A)=>A.isIntersecting))l()},{rootMargin:d}),a.observe(r)},g=()=>{let d=le(r)!==null,v=o;if(o=d,!d)return m();if(i)return;if(t.forgetToken(),!v)return l();p(!0)};if(fe.set(e,{load(){if(i)return;let d=Wr(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&ea(r,t))return;let v=d?U(r.id,d):t.proceed(r,Ur,"{}");if(!v)return;i=!0,m();let A=()=>{i=!1};return v.then(A,A),v},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);m()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&le(r)===null)Bt(r),c=(d)=>d.target===r&&Bt(r),r.addEventListener?.("turbo:morph-element",c);if(r.getAttribute?.("data-reactive-token-value")==null&&r.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(d)=>{if(d.target!==r)return;if(!c)Bt(r);g()},r.addEventListener?.("turbo:morph-element",u),n)return g();if(o=le(r)!==null,o)p(!1)}function Vt(e){let t=fe.get(e);fe.delete(e),t?.off()}function me(e){return fe.get(e)?.load()}function ea(e,t){return t.emit("reactive:before-dispatch",{action:Ur,params:{},element:e},{cancelable:!0}).defaultPrevented}function Bt(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Wr(e);if(t)U(e.id,t)}var Xt=new WeakMap,ge=new WeakMap,f=null,L,zr;function tn(e,t){let n=e.element;ge.set(n,t),to();let r=(i)=>na(i,t),o=(i)=>aa(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),Xt.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function nn(e){if(Xt.get(e)?.(),Xt.delete(e),ge.delete(e.element),f&&be(f.origin)===e.element)he()}var w=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),H=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},be=(e)=>e?.closest?.('[data-controller~="reactive"]'),Vr=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==f?.row&&Vr(t)===e),Gr=(e)=>H(w(e,"-item"),null),Zt=(e)=>w(e,"-disabled")==="true",ta=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Xr=(e)=>{let t=w(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>w(n,"-group")===t&&!Zt(n)&&ge.has(be(n)))};function Zr(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Vr(n);if(f||!r||!t.owns(r)||Zt(r)||Zt(n))return;if(be(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function na(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Zr(e.target,t);if(!n)return;let r=w(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(d)=>d.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(d)=>{if(!a(d))return;if(f)return Qt(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return h();oa(n,t,d),Qt(d.clientX,d.clientY)},p=(d)=>f&&d.cancelable&&d.preventDefault(),m=(d)=>{if(!a(d))return;if(h(),f)ra(),en()},b=(d)=>{if(d.type==="pointercancel"&&!a(d))return;if(h(),f)he()},y=[["pointermove",l],["pointerup",m],["pointercancel",b],["keydown",(d)=>d.key==="Escape"&&f&&(d.preventDefault(),b(d))],["touchmove",p,{passive:!1}]];for(let[d,v,A]of y)document.addEventListener(d,v,A);function h(){clearTimeout(u);for(let[d,v]of y)document.removeEventListener(d,v)}}function ra(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function oa({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,f=Qr({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),f.dx=r.clientX-o.left,f.dy=r.clientY-o.top,f.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function Qr(e){let{row:t,origin:n,source:r}=e;return e.index=T(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),z(n,!0),e}var z=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function ve(e,t,n,r){if(t[n])t[n].before(r);else if(t.length)t.at(-1).after(r);else e.append(r)}function Qt(e,t){f.x=e,f.y=t,f.row.style.left=`${e-f.dx}px`,f.row.style.top=`${t-f.dy}px`;let n=Xr(f.origin).find((r)=>ta(r,e,t));if(n)ia(n,e,t);else if(f.source)rn(null),f.placeholder.remove();sa(e,t)}function rn(e){if(f.target!==f.origin)z(f.target,!1);f.target=e,z(e,!0)}function ia(e,t,n){rn(e);let r=T(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});ve(e,r,s<0?r.length:s,f.placeholder)}function sa(e,t){let n=f.target??f.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(f.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,f.wy=t<40?-12:t>window.innerHeight-40?12:0,(f.vy||f.wy)&&!f.raf){let i=()=>{if(!f||!(f.vy||f.wy))return f&&(f.raf=0);if((f.target??f.origin).scrollTop+=f.vy,f.wy)window.scrollBy(0,f.wy);Qt(f.x,f.y),f.raf=requestAnimationFrame(i)};f.raf=requestAnimationFrame(i)}}function aa(e,t){let n=e.key;if(f?.keyboard){if(e.target!==f.row||f.core!==t)return;let o={" ":en,Enter:en,Escape:he,Tab:he,ArrowUp:()=>Kr(-1),ArrowDown:()=>Kr(1),ArrowLeft:()=>Yr(-1),ArrowRight:()=>Yr(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Zr(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),f=Qr({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Ae("picked")}function Kr(e){let t=T(f.target),n=ye()+e;if(n>=0&&n<=t.length)ve(f.target,t,n,f.row);eo()}function Yr(e){let t=Xr(f.origin),n=t[t.indexOf(f.target)+e];if(n){let r=ye();rn(n),ve(n,T(n),r,f.row)}eo()}function eo(){f.row.focus?.(),Ae("moved")}function ye(){let e=T(f.target),t=f.keyboard?f.row:f.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function to(){if(!L?.isConnected)L=document.createElement("div"),L.setAttribute("aria-live","polite"),L.setAttribute("data-reactive-sortable-live",""),L.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(L);return L}function Ae(e){let t=f.target??f.origin,n=(H(w(t,"-messages"),{})[e]??"").replaceAll("{position}",ye()+1).replaceAll("{count}",T(t).length+1),r=to();r.textContent="",cancelAnimationFrame(zr),zr=requestAnimationFrame(()=>r.textContent=n)}function en(){let e=f,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?ye():-1,c=a?Gr(T(t)[s-1]):null;if(e.keyboard)Ae("dropped");if(!r&&i)i.replaceWith(o);if(ro(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?w(n,"-source"):w(n,"-name")??"list",l=H(w(t,"-from"),{})[u]??w(t),p={...H(w(t,"-params"),{}),item:Gr(e.item),position:s,after:c,from:u},m=[];for(let g=t;g;g=g.parentElement)m.push(g);let b=ge.get(be(t))?.proceed(t,l,JSON.stringify(p),H(w(t,"-busy")));if(r)return;Promise.resolve(b).then((g)=>ca(g,m)||no(e))}function ca(e,t){if(!e)return!1;let n=document.createElement("template");return n.innerHTML=e,[...n.content.querySelectorAll("turbo-stream")].some((r)=>/^(replace|update)$/.test(r.getAttribute("action"))&&ua(r,t))}function ua(e,t){let n=e.getAttribute("target");if(n)return t.some((o)=>o.id===n);let r=e.getAttribute("targets");try{return Boolean(r)&&t.some((o)=>o.matches(r))}catch{return!1}}function he(){let e=f;if(e.keyboard)Ae("cancelled");e.placeholder?.remove(),ro(e),no(e)}function no({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(ve(t,T(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function ro(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(f=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),z(n,!1),z(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var R=new Map,io=new WeakSet;function on(e,t){let n=e.element,r=R.get(n.id);if(!r)R.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,la(n);let o=(a)=>a.target===n&&queueMicrotask(()=>ao(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},ao(r)}function sn(e){let t=e.element,n=R.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;R.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function an(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=R.get(e.id);if(!n)R.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},co(n)}function la(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&io.has(n))return;if(n?.remove(),!so())setTimeout(()=>{if(!so())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=R.get(e.id);if(!o||o.removing)return;co(o),fa(o)}),io.add(r),document.body.appendChild(r)}var so=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function fa(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&uo(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function co(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function uo(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function ao(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=uo(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}function pa(){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 ma(){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 ha(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Fn(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)$t(n);return}wn(t,(i)=>nc(i,o),r?(i,a)=>Mt(i,a,o):void 0)}}function ga(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){Ht(this)}}var po=!1,ba=null;function va(){if(po)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;po=!0,document.addEventListener("turbo:before-stream-render",(e)=>{Fa(e),ya(e),wa(e),xt(e)})}var Se="reactive:streamed";function ya(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(Se))}}function Sn(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function En(e){try{return e.matches(":modal")}catch{return!1}}function Wo(e){if(!Sn(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||En(e))return;if(e.open)e.close();e.showModal()}function Aa(e){if(Sn(e)&&e.open)e.close()}function ke(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&&!En(r))Wo(r)}function wa(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(o)=>{await n(o),ke(document)}}var mo=!1;function Sa(){if(mo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;mo=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))ke(t.target)}),document.addEventListener("turbo:morph",()=>ke(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!Sn(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||!En(n))return;e.delete(n),t.preventDefault(),n.close()})}var yn=new WeakMap;function jo(e,t,n,r){let o=yn.get(e)??new Map;yn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))ti(n.name)||i(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(i("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))jo(a,"set_attr",{name:"aria-expanded"})}}var ho=!1;function Ea(){if(ho)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ho=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of yn.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 Bo="data-reactive-image-fallback",G="data-reactive-image-state",An="data-reactive-image-hidden",cn=null;function K(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Bo);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var Jo=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Uo(e,t){if(typeof t.alt!=="string"||!t.alt)return null;try{let n=e.closest('[data-controller~="reactive"]')?.querySelector(t.alt);return n&&!n.contains(e)?n:null}catch{return null}}function Te(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(An,"");let r=Uo(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Fe(e,t);e.setAttribute(G,n)}function Fe(e,t=K(e)){if(!t||e.getAttribute(G)==null)return;if(e.getAttribute(G)==="error"){if(e.hasAttribute(An))e.removeAttribute("hidden");let n=Uo(e,t);if(n)n.hidden=!0}e.removeAttribute(G),e.removeAttribute(An)}function go(e){let t=e.target,n=K(t);if(!n)return;if(e.type==="load")Te(t,n,"loaded");else if(Jo(t))Te(t,n,"error");else Fe(t,n)}function _a(){if(cn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;cn={error:go,load:go,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(G);if(o==null||!r||!K(n))return;let i=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(i("src")&&i("srcset"))e.set(n,o)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let o=K(n);if(o)Te(n,o,r)})}};for(let[t,n]of Object.entries(cn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${Bo}]`)??[]){if(!t.complete||!Jo(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Te(t,K(t)??{},o);if(t.naturalWidth>0)r("loaded");else if(typeof t.decode==="function")t.decode().then(()=>r("loaded"),()=>r("error"));else r("error")}}function Sc(e){ba=e}var we,un=null,bo="[data-reactive-editable][contenteditable=plaintext-only]";function Ho(){if(we===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",we=e.contentEditable==="plaintext-only"}catch{we=!1}return we}function Ee(e){if(e.matches?.(bo))e.setAttribute("contenteditable","true");e.querySelectorAll?.(bo).forEach(Ee)}function xa(){if(un||typeof document>"u"||typeof document.createElement!=="function")return;if(Ho())return;Ee(document),un=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Ee(t.target);else t.addedNodes.forEach(Ee)}),un.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var vo=!1;function yo(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 ka(){if(vo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;vo=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=yo(t);if(r)La(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Le.set(t,F(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==S)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>Ln(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===S)&&yo(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(S)&&xn(t)===kn(t))t.removeAttribute(S)})}var S="data-reactive-held",_n='[data-controller~="reactive"]',_e=null,P=new Map;function xn(e){return e.hasAttribute("data-reactive-editable")?F(e):e.value}function kn(e){return e.hasAttribute("data-reactive-editable")?Rn(e):e.defaultValue}function Ta(e){if(e.hasAttribute("data-reactive-editable"))return F(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function La(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||P.has(e.closest(_n)))return;let r=Ta(t);if(r===xn(e))return e.removeAttribute(S);if(r===kn(e))return;e.setAttribute(S,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function Ra(e){let t=[];for(let n of e.querySelectorAll(`[${S}]`)){if(n.closest(_n)!==e)continue;let r=n.getAttribute("name");if(xn(n)===kn(n))n.removeAttribute(S);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 zo(e){for(let t of e.querySelectorAll(`[${S}]`))if(t.closest(_n)===e)t.removeAttribute(S)}function Ao(e,t,n=!0){let r={root:e,streams:0,release:n},o=_e;_e=r;try{window.Turbo.renderStreamMessage(t)}finally{_e=o}if(n&&r.streams===0)zo(e)}function Fa(e){let t=_e,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{P.set(t.root,(P.get(t.root)||0)+1);try{return await r(o)}finally{let i=P.get(t.root)-1;if(i)P.set(t.root,i);else P.delete(t.root);if(t.release)zo(t.root)}}}var Oa="__materialize",wo=!1;function Na(){if(wo)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;wo=!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)}function Tn(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Ot()}var Go="data-reactive-active",x=0;function Ko(){if(x++,x===1)Vo("reactive:busy")}function Yo(){if(x===0)return;if(x--,x===0)Vo("reactive:idle")}function Ec(){return x}function _c(){x=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(Go)}function Vo(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(Go,x>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:x}}))}var Xo="data-reactive-requests";function Zo(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Ca(t))return;let n=Ma(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(Xo,JSON.stringify(n))}function Ca(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Ma(e){try{let t=JSON.parse(e.getAttribute(Xo));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function So(){pa(),ma(),ha(),ga(),va(),ka(),Sa(),Ea(),_a(),xa(),Na(),Tn()}function $a(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Qo=Symbol.for("phlex-reactive.core");if(globalThis[Qo])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[Qo]=!0;var ei=!1;function Pa(){if(ei)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(Pa,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Ia=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function ti(e){let t=String(e).toLowerCase();return t.startsWith("on")||Ia.has(t)}var ln=new WeakMap;function Da(e,t,n){let[r,o,i]=t;ln.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,ln.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};ln.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,qa(e))}function qa(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Wa=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",ja=new Set(["lexxy-editor","trix-editor"]);function F(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
2
2
|
`))t+=`
|
|
3
3
|
`;n=!1,t+=i},o=(i)=>{for(let a of i.childNodes){let s=/^(div|p|li)$/.test(a.localName);if(s)n=!0;if(a.nodeType===3)a.data&&r(a.data);else if(a.localName==="br")r(`
|
|
4
4
|
`);else if(a.nodeType===1)o(a);if(s)n=!0}};return o(e),t=t.replace(/\r\n?/g,`
|
|
5
|
-
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var Ae=new WeakMap;function dn(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Ae.has(e))Ae.set(e,U(e))}function xo(e){return dn(e),Ae.get(e)}function ta(e){return ea.has(e.localName)?typeof e.value==="string":!0}var Qr=Object.freeze({show:(e,t,n)=>Qt(e,!1,t,n),hide:(e,t,n)=>Qt(e,!0,t,n),toggle:(e,t,n)=>Qt(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(en(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(en(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!en(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)=>sa(e)?.focus?.(),show_modal:(e)=>ho(e),close_dialog:(e)=>Ds(e),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)Oe(r,t.group,t.checked)},presence:(e,t)=>Kt(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=na(e);if(!r)return;let o=null;if(t?.submitter!=null&&typeof n==="function"){if(o=n({...t,to:t.submitter})[0]??null,!(o?.form===r&&(o.type==="submit"||o.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),o=null}o?r.requestSubmit?.(o):r.requestSubmit?.()},paste_into:(e)=>ra(e),persist_state:(e,t)=>st(e,t.state),persist_clear:(e)=>at(e)});function na(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function ra(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;if(e.value=n,typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}));e.focus?.()}).catch(()=>{})}function oa(e,t,n){if(n?.transition)Xs(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Qt(e,t,n,r){if(oa(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let o of r({...n,to:n.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function en(e){if(!Vs(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}var ia='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function sa(e){return e.querySelectorAll?.(ia)?.[0]??null}function pn(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 eo=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"}),to=Object.freeze(["meta","ctrl","alt","shift"]);function Se(e,t,n){let r=e.split("+");for(let a of to)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!to.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(eo,o)?eo[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var aa=(e)=>e&&typeof e==="object"?e.keys:String(e);function tn(e,t,n){let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Se(aa(e).replace(/^mod\+/,`${o}+`),t,n)}function ca(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:pn(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function no(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==To(t.currentTarget))return!1;return o<0||n===null||Se(r.slice(o+1),t,n)}function ua(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((o)=>r[o]===n[o])}var ro=new WeakMap;function la(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=ro.get(e);if(!o)o=new WeakMap,ro.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var oo=new WeakMap;function fa(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=oo.get(e);if(!o)o=new WeakMap,oo.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function cn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Qr,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)Qr[o](s,i,t)}}function da(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 pa(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function io(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function ma(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 ha(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]")!=null}function ga(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function ba(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function so(e){return e.getAttribute?.("data-reactive-presence")!=null}function Pa(e,t,n){}function ya(e,t){}function $a(e){return[]}function Ia(e){return Promise.resolve()}var ao=new Set;function va(e,t,n){let r=e+t;if(ao.has(r))return;ao.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 Da(){return["persist","defer","form","bindings","compute","sortable","presence","effects","hints","devtools"]}var co=Promise.resolve();var uo={enter:yo,exit:vo,count:So,text:U,served:xo,waiting:new WeakMap},lo=1,nn=2,rn=4,on=8,sn=16,fo=32,po=64;Ve(uo),Ct(uo);var H=Symbol.for("phlex-reactive.early"),Aa=1e4,wa=1500,To=(e)=>e!=null&&(e===globalThis.window||e.window===e);function an(){return globalThis[H]??={queue:[],connected:new WeakSet},globalThis[H]}function Sa(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Aa}function Ea(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function _a(e,t,n){return{[H]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Ea(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 we=new WeakMap;function xa(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=we.get(e);if(!s)we.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function mo(e,t,n,r){if(e?.[H])return!1;let o=To(e?.currentTarget),i=o?r:e?.currentTarget,a=ka(e,i,o?`@${t}`:t),s=we.get(i),c=o&&JSON.stringify(e.params);for(let u of s?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!Se(u.filter,e,n))continue;return u.armed=!1,!0}return a}var ye=new WeakMap;function Ta(e,t,n){let r=ye.get(e);if(!r)ye.set(e,r=new Map),setTimeout(()=>ye.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function ka(e,t,n){let r=e&&ye.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class ko extends Fs{static values={token:String};#m;#h=new Map;#f=new Map;#z;#w;#M;#S=0;#d=new Map;#E=new WeakMap;#t;featuresReady=co;#xe=new Map;#Te=new Set;#G=!1;#P=null;#ke=new Map;#Re=new Map;#Le=new Map;#Y=0;#$;#_=0;#n=0;connect(){if(_o=!0,an().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||io(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===ge)this.#D();this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(ge,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(dn),this.#Y++,this.featuresReady=co,this.#I(),ve(this.element),this.#V()}#I(e){this.#r(lo,"persist",pa,(t)=>ot(this,t,e)),this.#r(nn,"defer",io,(t)=>Dt(this,t,e)),this.#r(rn,"form",ma,(t)=>ct(this,t,e)),this.#r(on,"bindings",ha,(t)=>xe(this,t,e)),this.#r(sn,"compute",ga,(t)=>Je(this,t,e)),this.#r(fo,"sortable",ba,(t)=>Ut(this,t)),this.#r(po,"presence",so,(t)=>Gt(this,t))}#r(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#n|=e}catch(o){this.#q(t,"connect",o)}}#K(){{let e=this.#n;this.#_=this.#n=0;let t=this.#e();if(e&lo)this.#o("persist",()=>it(this,t));if(e&nn)this.#o("defer",()=>qt(this,t));if(e&rn)this.#o("form",()=>ut(this,t));if(e&on)this.#o("bindings",()=>Te(this,t));if(e&sn)this.#o("compute",()=>Ue(this,t));if(e&fo)this.#o("sortable",()=>Ht(this,t));if(e&po)this.#o("presence",()=>Yt(this,t))}}#o(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Fe(e){}#Oe(e,t){}#Ne(e){}#Ce(e,t){}#Me(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#D(),proceed:(e,t,n,r)=>this.#T(e,t,n,0,0,null,r),forgetToken:()=>{this.#m=void 0},owns:(e)=>this.#v(e),ownership:()=>this.#L(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>cn(e,(n)=>this.#C(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#p(e),collectFields:()=>this.#J(),plain:go,text:U,served:xo,confirm:(e,t)=>Promise.resolve().then(()=>zr(e,t)).catch(()=>!1)},this.#$}#D(){if(this.#n&rn)lt(this);if(this.#n&on)ke(this);if(this.#n&sn)He(this)}#q(e,t,n){if(va(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.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#Pe(){}#V(){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.#X()}#x=new Set;#X(){let{queue:e}=an();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=Sa(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(wa,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#O())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#Z(o)}}#Z({event:e,el:t,descs:n,win:r}){let o=_a(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Se(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!xa(s,c,r&&JSON.stringify(o.params)))continue;this.#x.add(s)}if(Ta(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#K(),this.#re(),this.#ie(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(ge,this.#t);an().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#x)we.delete(e);this.#x.clear()}dispatch(e){let t=e.params?.shortcut;if(t!=null&&!tn(t,e,this.application?.schema?.keyMappings))return;if(mo(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l}=e.params;if(!n)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let m=e.currentTarget??e.target;if((t!=null||!u)&&!this.#be(l,m))e.preventDefault();if(n===Js){let v=()=>{if(this.#n&nn)return ce(this);if(this.tokenValue)return this.#T(m,n,"{}")};return this.#G?this.featuresReady.then(v):v()}let g=this.#W(a,s),b=()=>this.#T(m,n,r,o,i,l,p);if(!g)return b();if(g instanceof Promise)return g.then((v)=>v?this.#g(v,m,b):b());this.#g(g,m,b)}#g(e,t,n){return Promise.resolve().then(()=>zr(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return Le(this,this.#e(),t)}#Q(e){}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!tn(t.shortcut,e,this.application?.schema?.keyMappings))return;if(mo(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(fa(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=ca(n.ops),i=o.filter((s)=>no(s,e,null)),a=i.length<=1?i:i.filter((s)=>no(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())Tt(this,e);return}for(let s of a){if(s.outside&&e[H])continue;if(!ua(s,e))continue;if(s.shortcut!=null&&!tn(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(la(this,e,s))continue;this.#ee(s.legacy?{...n,ops:s.ops}:s,e,r)}}#ee({ops:e,confirm:t,confirmWhen:n,outside:r,window:o,shortcut:i},a,s){if(r&&this.element.contains(a.target))return;if(i!=null||!o)a.preventDefault();let c=this.#W(t,n),u=()=>this.#ge(this.#he(e));if(!c)return u();if(c instanceof Promise)return c.then((l)=>l?this.#g(l,s,u):u());this.#g(c,s,u)}recompute(e){return ze(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#p(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return Pe(this,this.#e(),e)}tagsPick(e){return $e(this,this.#e(),e)}tagsRemove(e){return Ie(this,this.#e(),e)}nestedAdd(e){return De(this,this.#e(),e)}nestedRemove(e){return qe(this,this.#e(),e)}syncNestedJson(e){return Re(this,this.#e(),e)}#$e(e,t){}trackDirty(){ee(this,this.#e())}listnavNext(e){this.#b(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#b(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#b(e,()=>0)}listnavLast(e){this.#b(e,(t,n)=>n-1)}listnavPick(e){let t=this.#p(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.#p(e))t.removeAttribute("data-reactive-highlighted")}#b(e,t){let n=this.#p(e);if(!n.length)return;e.preventDefault();let r=this.#te(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#te(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#p(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.#L();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#T(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#U(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ne(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#oe(e,u,t,n,i,a);return this.#y(t,n,i,e,a)}#y(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#ye(e,r,i),s=Boolean(n||o),c=(m)=>{if(!s||!m)return;let g=this.#e();if(i.inverse=Lt(this,g,n,r),i.undo.push(...Rt(this,g,o,r)),this.#R())i.resurrect=Ft(this,g,n,r)},u=!0;c(!0);let l=()=>this.#ue(e,t,i,a),p=()=>this.#P?this.#P.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>p()),this.queue}#Ie(){return this.#Q("hints")}#ne(e,t,n,r,o,i){this.#k(e);let a=()=>{this.#k(e),this.#y(n,r,o,e,i)},s=setTimeout(a,t);e?.addEventListener?.("blur",a,{once:!0}),this.#h.set(e,{timer:s,flush:a})}#k(e){let t=this.#h.get(e);if(!t)return;clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),this.#h.delete(e)}#re(){for(let e of[...this.#h.keys()])this.#k(e)}#oe(e,t,n,r,o,i){let a=this.#f.get(e)??new Map;if(a.has(n))return;let s=setTimeout(()=>{if(a.delete(n),a.size===0)this.#f.delete(e)},t);return a.set(n,s),this.#f.set(e,a),this.#y(n,r,o,e,i)}#ie(){for(let e of this.#f.values())for(let t of e.values())clearTimeout(t);this.#f.clear()}#s(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}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#y(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#se(){this.element?.removeAttribute?.("data-reactive-error")}#ae(){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))}#ce(){return wt()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#j(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ue(e,t,n,r){let{fields:o,files:i}=this.#J(),a=this.#U(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#pe(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),p=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#j()}:null;await this.#ce();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let m;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Ee()};if(!u)h["Content-Type"]="application/json";let d=this.#_e();if(d)h["X-Pgbus-Connection"]=d;let y=so(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(y)h["X-Reactive-Presence"]=y;So("action"),m=await fetch(this.#we(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Se())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#u(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#ae(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(p)p.status=m.status;if(m.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:m.status});return}if(!m.ok){let h=await m.text();if(console.error(`[phlex-reactive] action failed: HTTP ${m.status}`,h),this.#u(n.inverse),(m.headers.get("Content-Type")||"").includes("turbo-stream")){let d=this.#B(h);if(this.#c=d??this.#c,p)ne(p,h,d);window.Turbo.renderStreamMessage(h)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:m.status,body:h});return}let g=m.headers.get("Content-Type")||"";if(!g.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${g}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:m.status});return}let b=await m.text(),v=this.#B(b);if(this.#c=v??this.#c,p)ne(p,b,v);if(window.Turbo.renderStreamMessage(b),n.resurrect)queueMicrotask(n.resurrect);return this.#se(),this.#s("reactive:applied",{action:e,params:s,html:b}),b}catch(m){console.error("[phlex-reactive] action error",m),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),p)kt(this,{...p,ms:this.#j()-p.started})}}get#c(){return this.#m??this.tokenValue}set#c(e){this.#m=e}tokenValueChanged(){this.#m=void 0}#B(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#le(t),o=e.match(n);if(o)return o[1];let i=e.match(r);if(i)return i[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#le(e){let t=this.#M;if(t&&t.id===e)return t;let n=Gs(e);return this.#M={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>`)}}#v(e){return e.closest('[data-controller~="reactive"]')===this.element}#L(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#v(t)}#J(){let e={},t=[],n=this.#L(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${Qs}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#fe(r),a=this.#de(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?U(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!ta(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#fe(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}#de(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#pe(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#A(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#F(o,this.#A(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#me(r);for(let{name:s,file:c,multiple:u}of r){let p=u||a.has(s)?`${this.#A(s)}[]`:this.#A(s);o.append(p,c,c.name)}return o}#A(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((o)=>`[${o}]`).join("")}`}#F(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#F(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#F(e,`${t}[${r}]`,o);else e.append(t,String(n))}#me(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))}#U(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#he(e){return pn(e)}#ge(e){cn(e,(t)=>this.#C(t),(t,n)=>this.#N(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#N(e,t){if(!this.#O())return;xt(this,e,t)}#De(e){}#C(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.#v(n))}#be(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#ye(e,t,n){this.#ve(e,t),yo();let r=!1;return()=>{if(r)return;r=!0,this.#Ae(e,t),vo();for(let o of n.undo)o()}}#ve(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#d.set(e,(this.#d.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#H(e))this.#l(n,e,1)}#Ae(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#d.get(e)??1)-1;if(n<=0)this.#d.delete(e);else this.#d.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#H(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#H(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#v(n))}#we(){return this.#z??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Se(){if(this.#w!=null)return this.#w;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#w=Number.isFinite(t)&&t>0?t:30000}#Ee(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#_e(){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)Zr();else document.addEventListener("turbo:load",Zr,{once:!0});fn();var Ga=ko;export{bo as ACTIVE_ATTR,Qs as EDITOR_SELECTOR,ea as EDITOR_TAGS,ts as LATENCY_KEY,wo as REQUESTS_ATTR,Ys as checkReactiveRegistration,So as countReactiveRequest,Ga as default,fr as disableLatencySim,U as editableValue,lr as enableLatencySim,yo as enterReactiveActivity,Gs as escapeRegExp,vo as exitReactiveActivity,Ia as loadReactiveFeature,Na as onReactiveStreamWithoutEffects,Ca as reactiveActivityCount,Da as reactiveFeatureNames,Zr as registerReactiveActions,Ms as registerReactiveDefer,fn as registerReactiveDev,$s as registerReactiveDismiss,$s as registerReactiveEffects,ya as registerReactiveFeature,Pa as registerReactiveFeatureLoader,Cs as registerReactiveJs,Ws as registerReactiveModals,Bs as registerReactiveMorphFocus,Us as registerReactiveOffline,js as registerReactivePlaintext,$s as registerReactiveStreamRender,Ns as registerReactiveToken,Os as registerReactiveVisit,Ma as resetReactiveActivity,xo as serverText,$a as unloadedFeaturesFor};
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var Le=new WeakMap;function Ln(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Le.has(e))Le.set(e,F(e))}function Rn(e){return Ln(e),Le.get(e)}function Ba(e){return ja.has(e.localName)?typeof e.value==="string":!0}var Eo=Object.freeze({show:(e,t,n)=>fn(e,!1,t,n),hide:(e,t,n)=>fn(e,!0,t,n),toggle:(e,t,n)=>fn(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(dn(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(dn(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!dn(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)=>Va(e)?.focus?.(),show_modal:(e)=>Wo(e),close_dialog:(e)=>Aa(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{}oi(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)We(r,t.group,t.checked)},presence:(e,t)=>an(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=Ja(e);if(!r)return;let o=null;if(t?.submitter!=null&&typeof n==="function"){if(o=n({...t,to:t.submitter})[0]??null,!(o?.form===r&&(o.type==="submit"||o.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),o=null}o?r.requestSubmit?.(o):r.requestSubmit?.()},paste_into:(e)=>Ua(e),preview_file:(e,t,n)=>Ha(e,t,n),set_value:(e,t)=>Ga(e,String(t.value??"")),persist_state:(e,t)=>gt(e,t.state),persist_clear:(e)=>bt(e)});function Ja(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Ua(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,ri(e),e.focus?.()}).catch(()=>{})}var Y=new Map,V=null;function Ha(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return _o(`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 _o(`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??[]].find((a)=>typeof a?.type==="string"&&a.type.startsWith("image/"));if(ni(r),i){let a=URL.createObjectURL(i);Y.set(r,a),r.setAttribute("src",a),za()}else r.removeAttribute("src");if(Fe(r),t.name==null)return;for(let a of n({...t,to:t.name}))a.textContent=i?i.name:""}function _o(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function ni(e){let t=Y.get(e);if(t===void 0)return;if(Y.delete(e),URL.revokeObjectURL(t),Y.size===0)V?.disconnect(),V=null}function za(){if(V||typeof MutationObserver!=="function"||!document?.documentElement)return;V=new MutationObserver(()=>{for(let[e,t]of Y)if(!e.isConnected||e.getAttribute("src")!==t)ni(e)}),V.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function ri(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Ga(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=xo(e);if(e.value=t,xo(e)!==n)ri(e)}function xo(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function Ka(e,t,n){if(n?.transition)Da(e,n.transition,()=>e.hidden=t);else e.hidden=t}function fn(e,t,n,r){if(Ka(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let o of r({...n,to:n.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function dn(e){if(!ti(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function oi(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"),o=!1;for(let a of["srcset","src"]){let s=r?n.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))o=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)o=e.setAttribute(a,s)??!0}if(o)Fe(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var Ya='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Va(e){return e.querySelectorAll?.(Ya)?.[0]??null}function Fn(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 ko=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"}),To=Object.freeze(["meta","ctrl","alt","shift"]);function Oe(e,t,n){let r=e.split("+");for(let a of To)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!To.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(ko,o)?ko[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Xa=(e)=>e&&typeof e==="object"?e.keys:String(e);function pn(e,t,n){let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Oe(Xa(e).replace(/^mod\+/,`${o}+`),t,n)}function Za(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:Fn(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function Lo(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==ii(t.currentTarget))return!1;return o<0||n===null||Oe(r.slice(o+1),t,n)}function Qa(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((o)=>r[o]===n[o])}var Ro=new WeakMap;function ec(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Ro.get(e);if(!o)o=new WeakMap,Ro.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var Fo=new WeakMap;function tc(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=Fo.get(e);if(!o)o=new WeakMap,Fo.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function wn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Eo,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)if(Eo[o](s,i,t),i?.keep===!0)jo(s,o,i,t)}}function nc(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 rc(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Oo(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function oc(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 ic(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 sc(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function ac(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function No(e){return e.getAttribute?.("data-reactive-presence")!=null}function xc(e,t,n){}function cc(e,t){}function kc(e){return[]}function Tc(e){return Promise.resolve()}var Co=new Set;function uc(e,t,n){let r=e+t;if(Co.has(r))return;Co.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 Lc(){return["persist","defer","form","bindings","compute","sortable","presence","effects","hints","devtools"]}var Mo=Promise.resolve();var $o={enter:Ko,exit:Yo,count:Zo,text:F,served:Rn,waiting:new WeakMap},Po=1,mn=2,hn=4,gn=8,bn=16,Io=32,Do=64;st($o),Ut($o);var X=Symbol.for("phlex-reactive.early"),lc=1e4,fc=1500,ii=(e)=>e!=null&&(e===globalThis.window||e.window===e);function vn(){return globalThis[X]??={queue:[],connected:new WeakSet},globalThis[X]}function dc(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:lc}function pc(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function mc(e,t,n){return{[X]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:pc(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 Re=new WeakMap;function hc(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Re.get(e);if(!s)Re.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function qo(e,t,n,r){if(e?.[X])return!1;let o=ii(e?.currentTarget),i=o?r:e?.currentTarget,a=bc(e,i,o?`@${t}`:t),s=Re.get(i),c=o&&JSON.stringify(e.params);for(let u of s?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==o)continue;if(o&&u.params!==c)continue;if(u.filter&&!Oe(u.filter,e,n))continue;return u.armed=!1,!0}return a}var xe=new WeakMap;function gc(e,t,n){let r=xe.get(e);if(!r)xe.set(e,r=new Map),setTimeout(()=>xe.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function bc(e,t,n){let r=e&&xe.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class si extends da{static values={token:String};#m;#h=new Map;#f=new Map;#z;#w;#M;#S=0;#d=new Map;#E=new WeakMap;#t;featuresReady=Mo;#xe=new Map;#ke=new Set;#G=!1;#$=null;#Te=new Map;#Le=new Map;#Re=new Map;#K=0;#P;#_=0;#n=0;connect(){if(ei=!0,vn().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||Oo(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Se)this.#D();this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(Se,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(Ln),this.#K++,this.featuresReady=Mo,this.#I(),ke(this.element),this.#V()}#I(e){this.#r(Po,"persist",rc,(t)=>mt(this,t,e)),this.#r(mn,"defer",Oo,(t)=>Yt(this,t,e)),this.#r(hn,"form",oc,(t)=>yt(this,t,e)),this.#r(gn,"bindings",ic,(t)=>Me(this,t,e)),this.#r(bn,"compute",sc,(t)=>Ze(this,t,e)),this.#r(Io,"sortable",ac,(t)=>tn(this,t)),this.#r(Do,"presence",No,(t)=>on(this,t))}#r(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#n|=e}catch(o){this.#q(t,"connect",o)}}#Y(){{let e=this.#n;this.#_=this.#n=0;let t=this.#e();if(e&Po)this.#o("persist",()=>ht(this,t));if(e&mn)this.#o("defer",()=>Vt(this,t));if(e&hn)this.#o("form",()=>At(this,t));if(e&gn)this.#o("bindings",()=>$e(this,t));if(e&bn)this.#o("compute",()=>Qe(this,t));if(e&Io)this.#o("sortable",()=>nn(this,t));if(e&Do)this.#o("presence",()=>sn(this,t))}}#o(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Fe(e){}#Oe(e,t){}#Ne(e){}#Ce(e,t){}#Me(e,t,n,r){}#e(){return this.#P??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#D(),proceed:(e,t,n,r)=>this.#k(e,t,n,0,0,null,r),forgetToken:()=>{this.#m=void 0},owns:(e)=>this.#y(e),ownership:()=>this.#R(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>wn(e,(n)=>this.#C(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#p(e),collectFields:()=>this.#J(),plain:Ho,text:F,served:Rn,copyMedia:oi,confirm:(e,t)=>Promise.resolve().then(()=>fo(e,t)).catch(()=>!1)},this.#P}#D(){if(this.#n&hn)wt(this);if(this.#n&gn)Pe(this);if(this.#n&bn)et(this)}#q(e,t,n){if(uc(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.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#$e(){}#V(){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.#X()}#x=new Set;#X(){let{queue:e}=vn();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=dc(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(fc,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#O())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#Z(o)}}#Z({event:e,el:t,descs:n,win:r}){let o=mc(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Oe(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!hc(s,c,r&&JSON.stringify(o.params)))continue;this.#x.add(s)}if(gc(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Y(),this.#re(),this.#ie(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(Se,this.#t);vn().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#x)Re.delete(e);this.#x.clear()}dispatch(e){let t=e.params?.shortcut;if(t!=null&&!pn(t,e,this.application?.schema?.keyMappings))return;if(qo(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l}=e.params;if(!n)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let m=e.currentTarget??e.target;if((t!=null||!u)&&!this.#be(l,m))e.preventDefault();if(n===Oa){let y=()=>{if(this.#n&mn)return me(this);if(this.tokenValue)return this.#k(m,n,"{}")};return this.#G?this.featuresReady.then(y):y()}let b=this.#W(a,s),g=()=>this.#k(m,n,r,o,i,l,p);if(!b)return g();if(b instanceof Promise)return b.then((y)=>y?this.#g(y,m,g):g());this.#g(b,m,g)}#g(e,t,n){return Promise.resolve().then(()=>fo(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return De(this,this.#e(),t)}#Q(e){}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!pn(t.shortcut,e,this.application?.schema?.keyMappings))return;if(qo(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(tc(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Za(n.ops),i=o.filter((s)=>Lo(s,e,null)),a=i.length<=1?i:i.filter((s)=>Lo(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())It(this,e);return}for(let s of a){if(s.outside&&e[X])continue;if(!Qa(s,e))continue;if(s.shortcut!=null&&!pn(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(ec(this,e,s))continue;this.#ee(s.legacy?{...n,ops:s.ops}:s,e,r)}}#ee({ops:e,confirm:t,confirmWhen:n,outside:r,window:o,shortcut:i},a,s){if(r&&this.element.contains(a.target))return;if(i!=null||!o)a.preventDefault();let c=this.#W(t,n),u=()=>this.#ge(this.#he(e));if(!c)return u();if(c instanceof Promise)return c.then((l)=>l?this.#g(l,s,u):u());this.#g(c,s,u)}recompute(e){return tt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#p(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return Ue(this,this.#e(),e)}tagsPick(e){return He(this,this.#e(),e)}tagsRemove(e){return ze(this,this.#e(),e)}nestedAdd(e){return Ge(this,this.#e(),e)}nestedRemove(e){return Ke(this,this.#e(),e)}syncNestedJson(e){return Ie(this,this.#e(),e)}#Pe(e,t){}trackDirty(){se(this,this.#e())}listnavNext(e){this.#b(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#b(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#b(e,()=>0)}listnavLast(e){this.#b(e,(t,n)=>n-1)}listnavPick(e){let t=this.#p(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.#p(e))t.removeAttribute("data-reactive-highlighted")}#b(e,t){let n=this.#p(e);if(!n.length)return;e.preventDefault();let r=this.#te(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#te(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#p(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.#R();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#k(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#U(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ne(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#oe(e,u,t,n,i,a);return this.#v(t,n,i,e,a)}#v(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#ve(e,r,i),s=Boolean(n||o),c=(m)=>{if(!s||!m)return;let b=this.#e();if(i.inverse=Wt(this,b,n,r),i.undo.push(...qt(this,b,o,r)),this.#L())i.resurrect=jt(this,b,n,r)},u=!0;c(!0);let l=()=>this.#ue(e,t,i,a),p=()=>this.#$?this.#$.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>p()),this.queue}#Ie(){return this.#Q("hints")}#ne(e,t,n,r,o,i){this.#T(e);let a=()=>{this.#T(e),this.#v(n,r,o,e,i)},s=setTimeout(a,t);e?.addEventListener?.("blur",a,{once:!0}),this.#h.set(e,{timer:s,flush:a})}#T(e){let t=this.#h.get(e);if(!t)return;clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),this.#h.delete(e)}#re(){for(let e of[...this.#h.keys()])this.#T(e)}#oe(e,t,n,r,o,i){let a=this.#f.get(e)??new Map;if(a.has(n))return;let s=setTimeout(()=>{if(a.delete(n),a.size===0)this.#f.delete(e)},t);return a.set(n,s),this.#f.set(e,a),this.#v(n,r,o,e,i)}#ie(){for(let e of this.#f.values())for(let t of e.values())clearTimeout(t);this.#f.clear()}#s(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}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#v(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#se(){this.element?.removeAttribute?.("data-reactive-error")}#ae(){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))}#ce(){return Nt()}#L(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#j(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ue(e,t,n,r){let{fields:o,files:i}=this.#J(),a=this.#U(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#pe(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),p=this.#L()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#j()}:null;await this.#ce();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let m;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Ee()};if(!u)h["Content-Type"]="application/json";let d=this.#_e();if(d)h["X-Pgbus-Connection"]=d;let v=No(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(v)h["X-Reactive-Presence"]=v;let A=Ra(this.element);if(A)h["X-Reactive-Held"]=A;Zo("action"),m=await fetch(this.#we(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Se())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#u(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#ae(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(p)p.status=m.status;if(m.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:m.status});return}if(!m.ok){let h=await m.text();if(console.error(`[phlex-reactive] action failed: HTTP ${m.status}`,h),this.#u(n.inverse),(m.headers.get("Content-Type")||"").includes("turbo-stream")){let d=this.#B(h);if(this.#c=d??this.#c,p)ce(p,h,d);Ao(this.element,h,!1)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:m.status,body:h});return}let b=m.headers.get("Content-Type")||"";if(!b.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${b}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:m.status});return}let g=await m.text(),y=this.#B(g);if(this.#c=y??this.#c,p)ce(p,g,y);if(Ao(this.element,g),n.resurrect)queueMicrotask(n.resurrect);return this.#se(),this.#s("reactive:applied",{action:e,params:s,html:g}),g}catch(m){console.error("[phlex-reactive] action error",m),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),p)Dt(this,{...p,ms:this.#j()-p.started})}}get#c(){return this.#m??this.tokenValue}set#c(e){this.#m=e}tokenValueChanged(){this.#m=void 0}#B(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#le(t),o=e.match(n);if(o)return o[1];let i=e.match(r);if(i)return i[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#le(e){let t=this.#M;if(t&&t.id===e)return t;let n=$a(e);return this.#M={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>`)}}#y(e){return e.closest('[data-controller~="reactive"]')===this.element}#R(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#y(t)}#J(){let e={},t=[],n=this.#R(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${Wa}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#fe(r),a=this.#de(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?F(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Ba(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#fe(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}#de(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#pe(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#A(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#F(o,this.#A(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#me(r);for(let{name:s,file:c,multiple:u}of r){let p=u||a.has(s)?`${this.#A(s)}[]`:this.#A(s);o.append(p,c,c.name)}return o}#A(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((o)=>`[${o}]`).join("")}`}#F(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#F(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#F(e,`${t}[${r}]`,o);else e.append(t,String(n))}#me(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))}#U(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#he(e){return Fn(e)}#ge(e){wn(e,(t)=>this.#C(t),(t,n)=>this.#N(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#L()}#N(e,t){if(!this.#O())return;Pt(this,e,t)}#De(e){}#C(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.#y(n))}#be(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#ve(e,t,n){this.#ye(e,t),Ko();let r=!1;return()=>{if(r)return;r=!0,this.#Ae(e,t),Yo();for(let o of n.undo)o()}}#ye(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#d.set(e,(this.#d.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#H(e))this.#l(n,e,1)}#Ae(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#d.get(e)??1)-1;if(n<=0)this.#d.delete(e);else this.#d.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#H(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#H(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#y(n))}#we(){return this.#z??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Se(){if(this.#w!=null)return this.#w;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#w=Number.isFinite(t)&&t>0?t:30000}#Ee(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#_e(){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)So();else document.addEventListener("turbo:load",So,{once:!0});Tn();var Ic=si;export{Go as ACTIVE_ATTR,Wa as EDITOR_SELECTOR,ja as EDITOR_TAGS,Is as LATENCY_KEY,Xo as REQUESTS_ATTR,Pa as checkReactiveRegistration,Zo as countReactiveRequest,Ic as default,Fr as disableLatencySim,F as editableValue,Rr as enableLatencySim,Ko as enterReactiveActivity,$a as escapeRegExp,Yo as exitReactiveActivity,Tc as loadReactiveFeature,Sc as onReactiveStreamWithoutEffects,Ec as reactiveActivityCount,Lc as reactiveFeatureNames,So as registerReactiveActions,ga as registerReactiveDefer,Tn as registerReactiveDev,va as registerReactiveDismiss,va as registerReactiveEffects,cc as registerReactiveFeature,xc as registerReactiveFeatureLoader,_a as registerReactiveImageFallback,ha as registerReactiveJs,Ea as registerReactiveKeep,Sa as registerReactiveModals,ka as registerReactiveMorphFocus,Na as registerReactiveOffline,xa as registerReactivePlaintext,va as registerReactiveStreamRender,ma as registerReactiveToken,pa as registerReactiveVisit,_c as resetReactiveActivity,Rn as serverText,kc as unloadedFeaturesFor};
|
|
6
7
|
|
|
7
|
-
//# debugId=
|
|
8
|
+
//# debugId=E74D1E7676D7F84064756E2164756E21
|
|
8
9
|
//# sourceMappingURL=reactive_controller.min.js.map
|