phlex-reactive 0.14.4 → 0.15.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -0
  3. data/README.md +191 -1
  4. data/app/controllers/phlex/reactive/actions_controller.rb +28 -18
  5. data/app/javascript/phlex/reactive/core.js +5 -5
  6. data/app/javascript/phlex/reactive/core.min.js +3 -3
  7. data/app/javascript/phlex/reactive/core.min.js.map +4 -4
  8. data/app/javascript/phlex/reactive/early.js +28 -9
  9. data/app/javascript/phlex/reactive/early.min.js +2 -2
  10. data/app/javascript/phlex/reactive/early.min.js.map +3 -3
  11. data/app/javascript/phlex/reactive/features/bindings.js +125 -140
  12. data/app/javascript/phlex/reactive/features/bindings.min.js +2 -2
  13. data/app/javascript/phlex/reactive/features/bindings.min.js.map +3 -3
  14. data/app/javascript/phlex/reactive/features/form.js +63 -41
  15. data/app/javascript/phlex/reactive/features/form.min.js +2 -2
  16. data/app/javascript/phlex/reactive/features/form.min.js.map +3 -3
  17. data/app/javascript/phlex/reactive/features/presence.js +205 -0
  18. data/app/javascript/phlex/reactive/features/presence.min.js +4 -0
  19. data/app/javascript/phlex/reactive/features/presence.min.js.map +10 -0
  20. data/app/javascript/phlex/reactive/inspect.js +5 -1
  21. data/app/javascript/phlex/reactive/inspect.min.js +2 -2
  22. data/app/javascript/phlex/reactive/inspect.min.js.map +3 -3
  23. data/app/javascript/phlex/reactive/reactive_controller.js +3 -1
  24. data/app/javascript/phlex/reactive/reactive_controller.min.js +3 -3
  25. data/app/javascript/phlex/reactive/reactive_controller.min.js.map +8 -7
  26. data/app/javascript/phlex/reactive/runtime.js +175 -14
  27. data/lib/phlex/reactive/component/dsl.rb +5 -0
  28. data/lib/phlex/reactive/component/helpers.rb +79 -8
  29. data/lib/phlex/reactive/component/presence_declaration.rb +118 -0
  30. data/lib/phlex/reactive/component/registry.rb +3 -1
  31. data/lib/phlex/reactive/component.rb +1 -0
  32. data/lib/phlex/reactive/defer.rb +5 -0
  33. data/lib/phlex/reactive/engine.rb +9 -4
  34. data/lib/phlex/reactive/js.rb +24 -0
  35. data/lib/phlex/reactive/presence/component_methods.rb +130 -0
  36. data/lib/phlex/reactive/presence/roster.rb +90 -0
  37. data/lib/phlex/reactive/presence/transport.rb +154 -0
  38. data/lib/phlex/reactive/presence.rb +162 -0
  39. data/lib/phlex/reactive/presence_render_job.rb +26 -0
  40. data/lib/phlex/reactive/shortcut.rb +105 -0
  41. data/lib/phlex/reactive/streamable.rb +7 -3
  42. data/lib/phlex/reactive/version.rb +1 -1
  43. data/lib/phlex/reactive.rb +10 -0
  44. metadata +11 -1
@@ -1,8 +1,8 @@
1
- import{Controller as ss}from"@hotwired/stimulus";import{confirmResolver as Fr}from"phlex/reactive/confirm";import{confirmPredicate as oo}from"phlex/reactive/confirm_predicate";var O=new WeakMap,ye=new WeakMap;function E(e,t){let n=O.get(e);if(!n){if(O.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)ye.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 R(e,t){S(e,"turbo:morph-element",t),e.seeds.push(t),t()}function ve(e,t){let n=E(e,t);if(n.offs=[],n.seeds=[],uo(n))n.show=(r)=>{if(n.flipping)return;if(r?.type==="input"||r?.type==="change")yo(n,r.target);else n.groups=bo(n),rn(n);po(n)},S(n,"input change",n.show),R(n,n.show);if(lo(n))S(n,"input change",(r)=>tn(n,r)),R(n,n.arm=()=>{tn(n,null),rn(n)});if(n.show||n.arm)S(n,"reset",()=>setTimeout(()=>{if(O.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(K(n))S(n,"input",(r)=>wo(n,r)&&C(n)),R(n,()=>C(n));if(X(n))R(n,()=>mn(n));if(So(n))S(n,"input change",(r)=>vn(n,r)),R(n,()=>Le(n));R(n,()=>Io(n)),S(n,"keydown",(r)=>Do(n,r)),S(n,"paste drop",(r)=>qo(n,r)),S(n,"input",(r)=>Wo(n,r))}function Ae(e){let t=O.get(e);if(!t)return;O.delete(e),ye.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function we(e){for(let t of O.get(e)?.seeds??[])t()}function N(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Se(e,t,n){return vn(E(e,t),n)}function _e(e,t,n){return En(E(e,t),n)}var io=/^#[A-Za-z_][\w-]*$/,sn="[data-reactive-show-field], [data-reactive-show]";function so(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 An){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return _n(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function an(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 ao(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 cn(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 M(n,t);return co(e,t)}function co(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)=>Me(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function Y(e,t="show"){if(typeof e==="string"&&io.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function uo(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?.(sn)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(V)??[])if(e.core.owns(n))return!0;return!1}function lo(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function fo(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:ao(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function tn(e,t){let n=fo(e);if(!n.length)return;let r=fn(e,e.core.ownership());n.forEach((o,i)=>{let a=M(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 po(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=fn(e,t);for(let o of e.root.querySelectorAll(sn)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=cn(an(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=so(o,s);if(c===null)continue;nn(o,c,t,n)}if(e.groups)vo(e,r,t,n);ho(e,r),Ao(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 ho(e,t){let n=un(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){mo(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(!Y(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)=>Me(l,a))}else{let l=xn(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 mo(e,t,n){if(!Y(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Po(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!$o(r))return;let i=M(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function un(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 go(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(ln(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 ln(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function fn(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?xe(e,o,t,n).filter((s)=>s.checked).length:go(e,o,t,n));return r.get(a)}}var V="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function bo(e){return!!e.root.querySelector?.(V)}function xe(e,t,n,r){return[...e.root.querySelectorAll(ln(t,r))].filter((o)=>o.type==="checkbox"&&n(o))}function yo(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))dn(e,n,t.checked,t)}function Ee(e,t,n){if(!t)return;let r=ye.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};dn(r,t,n!==!1),r.show?.()}function dn(e,t,n,r){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=xe(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 vo(e,t,n,r){for(let o of e.root.querySelectorAll(V)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=cn(an(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=xe(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 Ao(e,t){for(let[n,r]of Object.entries(un(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(!Y(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(!Y(a,"group"))continue;let c=M(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 rn(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?.(`${V}, [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 K(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function wo(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}function C(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 X(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function So(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function Te(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 ke(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 pn(e,t){let n=Te(e);if(!n)return!1;let r=ke(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)hn(e,n,r);return i}function hn(e,t,n){t.value=n.join(","),N(t),mn(e)}function _o(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 mn(e){let t=Te(e);if(!t)return;let n=ke(t),r=e.core.ownership();xo(e,n,r),Eo(e,n,r)}function xo(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 Eo(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"),!K(e))o.hidden=!1}}if(K(e))C(e)}function To(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function ko(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 Lo(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 Fo(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((h)=>bn(h.getAttribute?.("name"))===c);if(!p)continue;Ro(p,l),s.push(l)}if(r)for(let c of s)Oo(c);return s[0]??null}function Ro(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:be(t)!=="";else e.value=be(t);N(e)}function Oo(e){if(e.type==="checkbox")e.checked=!1;else e.value="";N(e)}function No(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function on(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);Le(e)}function Le(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))yn(e,n.getAttribute("data-reactive-nested-json"))}function Co(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 gn(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=bn(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=be(o)}return n}function bn(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function be(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function yn(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=Co(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(gn(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,N(o)}function Fe(e,t,n){let r=E(e,t);if(!X(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(!pn(r,String(o.value??"").split(",")))return;if(o.value="",K(r))C(r)}function Re(e,t,n){let r=E(e,t);if(!X(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!pn(r,[i]))return;let a=_o(r);if(!a)return;a.value="",C(r),a.focus?.()}function Oe(e,t,n){let r=E(e,t);if(!X(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=Te(r);if(!a)return;let s=ke(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;hn(r,a,c)}function Ne(e,t,n){let r=E(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){Lo(r,i);return}let l=u.cloneNode(!0);ko(l,To(r)),s.appendChild(l);let p=o?.getAttribute?.("data-reactive-nested-from-param"),h=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",g=Fo(r,l,p,h);if(p)g?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)yn(r,i)}function Ce(e,t,n){let r=E(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?En(r,s):null);if(!c)return on(r,i);let u=gn(r,i),l=No(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((p)=>{if(p)on(r,i)})}function vn(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;Le(e)}var An=["gte","gt","lte","lt"],Mo=["len_eq","len_gte","len_gt","len_lte","len_lt"],wn=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function Sn(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 _n(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 xn(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 An)if(n in e)return _n(n,e[n],t);for(let n of Mo)if(n in e)return Sn(n,e[n],[...String(t??"")].length);return null}function Me(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=wn.find((o)=>(o in e));if(n){let o=t(e.field,!0);return Sn(n,e[n],Array.isArray(o)?o.length:Number(o)||0)===!0}let r=t(e.field)??"";return xn(e,r)===!0}function M(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>Me(r,t)))}function Po(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 $o(e){return e.flat().every((t)=>wn.some((n)=>(n in Object(t))))}function En(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=oo(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=M(n.groups?.any,o)===!0;return i?n.message:null}var G;function Tn(){if(G===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",G=e.contentEditable==="plaintext-only"}catch{G=!1}return G}function Pe(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function Io(e){if(Tn())return;for(let t of e.root.querySelectorAll("[data-reactive-editable][contenteditable=plaintext-only]"))t.setAttribute("contenteditable","true")}function Do(e,t){let n=Pe(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 qo(e,t){let n=Pe(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||Tn()&&!(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 Wo(e,t){let n=Pe(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as jo}from"phlex/reactive/compute";var I=new WeakMap;function Rn(e,t){let n=I.get(e);if(!n)I.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Ie(e,t,n,r){let o=Rn(e,t),i=ni(o);if(i)o.seed=()=>$e(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)$e(o)}function De(e){let t=I.get(e);if(!t)return;if(I.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function qe(e){I.get(e)?.seed?.()}function We(e,t,n){return $e(Rn(e,t),n)}var Bo=Object.freeze({el:null,kind:""}),Jo=/^#[A-Za-z_][\w-]*$/;function P({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 On(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function Uo(e,t){if(t==="string")return P(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):On(P(e));if(n)return e.el.checked?1:0;let r=Number(P(e));return Number.isFinite(r)?r:0}function Ho(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=On(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return zo(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function zo(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 Go(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 Yo(e){if(typeof e==="string"&&Jo.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function Ko(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 Vo(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 Xo(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 Zo(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=Qo(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function Qo(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Ln(e,t,n){let r=String(n);for(let o of ei(e,t)){if(o.textContent===r)continue;o.textContent=r}}function ei(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Fn(e,t,n){let r=ti(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?P(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!Yo(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function ti(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 ni(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function $e(e,t){if(t&&e.ours.has(t))return;let n=Xo(e),r=n.map(([m])=>m),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(m)=>o&&!m.includes("[")?`${o}[${m}]`:m,a=e.core.ownership(),s=new Map,c=(m)=>{let d=s.get(m);if(d)return d;let y=null,w=null,L=null;for(let F of e.root.querySelectorAll(`[name="${i(m)}"]`)){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:""}:Bo;return s.set(m,L),L};for(let m of r)Ln(e,m,P(c(m)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?jo(u):null;if(!l){Fn(e,{},c);return}let p=Vo(e,"data-reactive-compute-outputs-param"),h={};for(let[m,d]of n)h[m]=Uo(c(m),d);let g=l(h,{changed:Zo(e,t,r,o)})||{},b=Go(g.$ops),A=[];for(let m of p){if(m==="$ops"||!(m in g))continue;let d=c(m);if(!d.el)continue;let y=Ho(e.root,a,d,i(m),g[m]);if(y)A.push(y)}for(let m of Object.keys(g)){if(m==="$ops")continue;let d=g[m];if(d===void 0||d===null)continue;Ln(e,m,d)}Fn(e,g,c);for(let m of A){let d=new Event("input",{bubbles:!0});e.ours.add(d),m.dispatchEvent(d)}Ko(e,b,Boolean(t))}var Je;function Ue(e){Je=e}var $n=1,ri="phlex-reactive:persist:",oi=new Set(["hidden","file","password","submit","button","reset","image"]),He=Symbol("persist-no-value"),ze="data-reactive-persist-state",ii=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",si=new Set(["lexxy-editor","trix-editor"]),ai="lexxy-editor, trix-editor, trix-toolbar",ci=["lexxy:change","trix-change"],ui=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Cn=new WeakSet,Mn=new WeakSet,Pn=new WeakSet;function Q(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(!Cn.has(e))Cn.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Ge(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function Ye(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Mn.has(e))return;Mn.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Ke(e){return ri+e.key}function je(e,t){let n=Ge();if(!n)return null;let r;try{r=n.getItem(Ke(t))}catch(c){return Ye(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==$n)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return Z(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 In(e,t,{fields:n,state:r}){let o=Ge();if(!o)return!1;let i={v:$n,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Ke(t),JSON.stringify(i)),!0}catch(a){return Ye(e,a),!1}}function Z(e,t){e?.removeAttribute?.(ze);let n=Ge();if(!n)return;try{n.removeItem(Ke(t))}catch(r){Ye(e,r)}}function Ve(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)||oi.has(i.type)||i.closest(ai))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(ii)){if(!o(i))continue;let a=li(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:si.has(i.localName)?"editor":"contenteditable"})}return r}function Dn(e){return e.hasAttribute("data-reactive-editable")?Je.text(e):e.textContent??""}function li(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Xe(e){return typeof e.value==="string"}function fi(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return ui.has(e.value.trim())}function di(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Pn.has(e))return;Pn.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function D(e){return e.tagName==="SELECT"&&e.multiple}function qn(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 Wn(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return He;return e[0]}function jn(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 Ve(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Xe(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=Dn(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(D(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=Ve(e,t),i=qn(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)&&D(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||D(s))){if(l=Wn(l,c,i),l===He)continue}if((s.type==="checkbox"||D(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")Bn(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&Dn(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(D(s)){if(!r&&[...s.options].some((h)=>h.selected))continue;let p=new Set((Array.isArray(l)?l:[l]).map(String));for(let h of s.options)h.selected=p.has(h.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}hi(e,t,n)}function Bn(e,t,n,r,o){if(Array.isArray(r))return;if(!Xe(t))return;if(!o&&!fi(t))return;try{t.value=String(r)}catch(i){di(e,n,i)}}function hi(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(!Xe(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=Ve(e,t),c=qn(s);for(let{el:u,name:l,kind:p}of s){if(p!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let h=Wn(n[l],l,c);if(h===null||h===void 0||h===He)continue;Bn(e,u,l,h,i)}})}function mi(e,t,n=!0){let r=Q(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=je(e,r),i={...o?.state??{},...t},a=n?jn(e,r):o?.fields??{};if(In(e,r,{fields:a,state:i}))e.setAttribute?.(ze,JSON.stringify(i))}function gi(e){let t=Q(e);if(t)Z(e,t)}var Be=new WeakMap;function Ze(e,t,n,r){let o=e.element,i=Q(o);if(!i)return;if(r?.submitted)Z(o,i);let a=je(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=je(o,i);In(o,i,{fields:jn(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(),Z(o,i)},h=["input",...ci];for(let g of h)o.addEventListener?.(g,l);if(o.addEventListener?.("change",u),document.addEventListener?.("turbo:submit-end",p),Be.set(e,()=>{if(s!==null)u();for(let g of h)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 Qe(e){let t=Be.get(e);Be.delete(e),t?.()}function Jn(e,t){let n=Je?.waiting.get(e)?.persist;if(!n||!Q(e))return t(!0);(n.ops??=[]).push(t)}function et(e,t){Jn(e,(n)=>mi(e,t,n))}function tt(e){Jn(e,()=>gi(e))}var nt=new WeakMap,Hn=new WeakSet;function rt(e,t){let n=e.element,r=[];nt.set(e,r);let o=(i,a,s)=>{i.addEventListener?.(a,s),r.push(()=>i.removeEventListener?.(a,s))};if(bi(n,t)){let i=()=>q(e,t);if(o(n,"turbo:morph-element",i),i(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")vi(n,o)}if(Ai(n,t)){let i=()=>wi(n,t);o(n,"turbo:morph-element",i),i()}}function ot(e){for(let t of nt.get(e)??[])t();nt.delete(e)}function bi(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 q(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,yi(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 yi(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 zn(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function vi(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;t(window,"beforeunload",(n)=>{if(zn(e)===0)return;return n.preventDefault(),n.returnValue="You have unsaved changes.",n.returnValue}),t(window,"turbo:before-visit",(n)=>{if(zn(e)===0||Hn.has(n))return;if(Hn.add(n),!(typeof window.confirm==="function"?window.confirm("You have unsaved changes. Leave anyway?"):!0))n.preventDefault?.()})}function Ai(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 wi(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 ct(e){Si(e),xi(e)}function Si(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(it);else setTimeout(it,0);return}let r=async(o)=>{await n(o),it()};r.__reactiveDismissWrapped=!0,t.render=r}function it(){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 _i=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),st=Object.freeze(["fade","slide","scale","highlight","shake"]),at="data-reactive-fx-pending",ut=1000;function xi(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=_i[r?.getAttribute?.("action")];if(!o||ki())return;let i=Ei(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Ri(ee(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Li(r):null;if(await n(s),o==="enter")Fi(c,i);else Kn(ee(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Ei(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return Yn(n,t);let o=(t==="enter"?Ti(e):ee(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?Yn(o,t):null}function ee(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Ti(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function Yn(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"?st[Math.floor(Math.random()*st.length)]:e;if(!st.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 Li(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(at,"");return ee(e)}function Fi(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${at}]`)))n.removeAttribute(at),Kn(n,t)}async function Ri(e,t){if(!e?.classList)return;if(t.legs){await Vn(e,t.legs);return}e.classList.add(t.className);let n=lt(e);if(n<=0){e.classList.remove(t.className);return}await ft(e,n),e.classList.remove(t.className)}function Kn(e,t){if(!e?.classList)return;if(t.legs){Vn(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=lt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;ft(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function Vn(e,t){let[n,r,o]=t.map(Oi),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Ni(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=lt(e);if(a>0)await ft(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function Oi(e){return String(e??"").split(/\s+/).filter(Boolean)}function lt(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,ut)}catch{return 0}}function ft(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,ut))})}function Ni(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},ut),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Ci="phlex-reactive:latency",dt=!1;function Qn(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function er(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),dt=!1}function ht(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:Qn,disableLatencySim:er}}function mt(){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(!dt)dt=!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 Zn=new WeakMap;function gt(e){let t=globalThis.document;if(!t)return!0;let n=Zn.get(t);if(!n)n=new Set,Zn.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function pt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function tr(e,t,n,r){if(gt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function bt(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=pt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}tr(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function yt(e){if(!gt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function vt(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(pt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=pt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}tr(t,o,`scoped to #${r?.id||"?"}`,i)}function At(e,t){let n=e.element?.id||"?";if(gt(`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 Mi(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 wt(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 te(e,t,n){e.streams=Mi(t),e.tokenRefreshed=n!=null}var ne=new WeakMap;function St(e,t,n,r){let o=n&&typeof n==="object"?Ii(n):n;return o?rr(t,o,r,!1):[]}function _t(e,t,n,r){if(!n)return null;let o=rr(t,n,r,!0);return o.length?o:null}function rr(e,t,n,r){let o=[];for(let i of or(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(Pi(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function or(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 Pi(e,t){let n=ne.get(t);if(n)n.count++;else ne.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()=>$i(t,e)}function $i(e,t){let n=ne.get(e);if(!n)return;if(--n.count>0)return;if(ne.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function Ii(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function xt(e,t,n,r){if(!n?.hide)return null;let o=or(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 ie;function kt(e){ie=e}var _=new Map;function cr(e,t){let n=!_.has(e);if(_.set(e,t),n)ie.enter()}function se(e){if(_.delete(e))ie.exit()}var sr=!1;function Lt(e){ur();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){Ji(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;j(t,n)}function ur(){if(sr||typeof document>"u"||!document.addEventListener)return;sr=!0,document.addEventListener("turbo:before-stream-render",Hi,!0),document.addEventListener("turbo:before-stream-render",Di)}function Di(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(_.get(n)?.via==="stream")se(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}Rt(e),pr(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return cr(e,r),Ui(e,r,t)}function qi(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[Gi(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Yi()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function lr(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(fr(t))return{src:t};return console.error(Wi(t)),ji(t)||Bi(e)}function Wi(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Ft()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function ji(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Ft()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&fr(r))return{src:r,fallback:!0}}function Bi(e){Rt(e.id),Ot(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 fr(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Ft()}/`)}catch{return!1}}function Ft(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function Ji(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}Rt(e),pr(n);let o=document.createElement("pgbus-stream-source");o.id=dr(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),cr(e,{via:"stream"})}function dr(e){return`reactive-defer-src-${e}`}async function Ui(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Ki()),o;try{ie.count("defer"),o=await fetch(...qi(n,t.abort.signal))}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),W(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"}`),W(e,n,o.status);return}if(o.status===204){clearTimeout(r),ar(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),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),W(e,n);return}if(clearTimeout(r),_.get(e)!==t)return;ar(e),zi(a)}var Tt=null,Hi=(e)=>Tt?.push(e);function zi(e){let t=Tt=[];try{window.Turbo.renderStreamMessage(e)}finally{Tt=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 Rt(e){let t=_.get(e);if(!t)return;if(se(e),t.via==="fetch")t.abort.abort();else document.getElementById(dr(e))?.remove?.()}function pr(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Ot(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function ar(e){se(e);let t=document.getElementById(e);if(!t)return;Ot(t),t.removeAttribute("data-reactive-error")}function W(e,t,n){se(e);let r=document.getElementById(e);if(!r)return;Ot(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 Gi(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Yi(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Ki(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var hr="__materialize",oe=new WeakMap;function re(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function Nt(e,t,n){ur();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>ae(e),p=(d)=>{if(re(r)==="visible"){if(!a)g()}else if(d){let y=r.getAttribute("data-reactive-lazy-on");if(s===y)return;h(),r.addEventListener?.(y,l),s=y}},h=()=>{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=re(r)!==null,y=o;if(o=d,!d)return h();if(i)return;if(t.forgetToken(),!y)return l();p(!0)};if(oe.set(e,{load(){if(i)return;let d=lr(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&Vi(r,t))return;let y=d?j(r.id,d):t.proceed(r,hr,"{}");if(!y)return;i=!0,h();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);h()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&re(r)===null)Et(r),c=(d)=>d.target===r&&Et(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)Et(r);b()},r.addEventListener?.("turbo:morph-element",u),n)return b();if(o=re(r)!==null,o)p(!1)}function Ct(e){let t=oe.get(e);oe.delete(e),t?.off()}function ae(e){return oe.get(e)?.load()}function Vi(e,t){return t.emit("reactive:before-dispatch",{action:hr,params:{},element:e},{cancelable:!0}).defaultPrevented}function Et(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||lr(e);if(t)j(e.id,t)}var Mt=new WeakMap,ue=new WeakMap,f=null,k,gr;function Dt(e,t){let n=e.element;ue.set(n,t),Er();let r=(i)=>Zi(i,t),o=(i)=>rs(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),Mt.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function qt(e){if(Mt.get(e)?.(),Mt.delete(e),ue.delete(e.element),f&&le(f.origin)===e.element)ce()}var v=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),B=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},le=(e)=>e?.closest?.('[data-controller~="reactive"]'),Ar=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==f?.row&&Ar(t)===e),br=(e)=>B(v(e,"-item"),null),Pt=(e)=>v(e,"-disabled")==="true",Xi=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},wr=(e)=>{let t=v(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>v(n,"-group")===t&&!Pt(n)&&ue.has(le(n)))};function Sr(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Ar(n);if(f||!r||!t.owns(r)||Pt(r)||Pt(n))return;if(le(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Zi(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Sr(e.target,t);if(!n)return;let r=v(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 $t(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return m();es(n,t,d),$t(d.clientX,d.clientY)},p=(d)=>f&&d.cancelable&&d.preventDefault(),h=(d)=>{if(!a(d))return;if(m(),f)Qi(),It()},g=(d)=>{if(d.type==="pointercancel"&&!a(d))return;if(m(),f)ce()},A=[["pointermove",l],["pointerup",h],["pointercancel",g],["keydown",(d)=>d.key==="Escape"&&f&&(d.preventDefault(),g(d))],["touchmove",p,{passive:!1}]];for(let[d,y,w]of A)document.addEventListener(d,y,w);function m(){clearTimeout(u);for(let[d,y]of A)document.removeEventListener(d,y)}}function Qi(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function es({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=_r({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 _r(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 fe(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 $t(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=wr(f.origin).find((r)=>Xi(r,e,t));if(n)ts(n,e,t);else if(f.source)Wt(null),f.placeholder.remove();ns(e,t)}function Wt(e){if(f.target!==f.origin)J(f.target,!1);f.target=e,J(e,!0)}function ts(e,t,n){Wt(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});fe(e,r,s<0?r.length:s,f.placeholder)}function ns(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);$t(f.x,f.y),f.raf=requestAnimationFrame(i)};f.raf=requestAnimationFrame(i)}}function rs(e,t){let n=e.key;if(f?.keyboard){if(e.target!==f.row||f.core!==t)return;let o={" ":It,Enter:It,Escape:ce,Tab:ce,ArrowUp:()=>yr(-1),ArrowDown:()=>yr(1),ArrowLeft:()=>vr(-1),ArrowRight:()=>vr(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Sr(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),f=_r({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),pe("picked")}function yr(e){let t=T(f.target),n=de()+e;if(n>=0&&n<=t.length)fe(f.target,t,n,f.row);xr()}function vr(e){let t=wr(f.origin),n=t[t.indexOf(f.target)+e];if(n){let r=de();Wt(n),fe(n,T(n),r,f.row)}xr()}function xr(){f.row.focus?.(),pe("moved")}function de(){let e=T(f.target),t=f.keyboard?f.row:f.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function Er(){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 pe(e){let t=f.target??f.origin,n=(B(v(t,"-messages"),{})[e]??"").replaceAll("{position}",de()+1).replaceAll("{count}",T(t).length+1),r=Er();r.textContent="",cancelAnimationFrame(gr),gr=requestAnimationFrame(()=>r.textContent=n)}function It(){let e=f,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?de():-1,c=a?br(T(t)[s-1]):null;if(e.keyboard)pe("dropped");if(!r&&i)i.replaceWith(o);if(kr(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?v(n,"-source"):v(n,"-name")??"list",l=B(v(t,"-from"),{})[u]??v(t),p={...B(v(t,"-params"),{}),item:br(e.item),position:s,after:c,from:u},h=[];for(let b=t;b;b=b.parentElement)h.push(b);let g=ue.get(le(t))?.proceed(t,l,JSON.stringify(p),B(v(t,"-busy")));if(r)return;Promise.resolve(g).then((b)=>os(b,h)||Tr(e))}function os(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"))&&is(r,t))}function is(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 ce(){let e=f;if(e.keyboard)pe("cancelled");e.placeholder?.remove(),kr(e),Tr(e)}function Tr({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(fe(t,T(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function kr(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??""}function as(){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 cs(){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 us(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Qt(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)yt(n);return}Vt(t,(i)=>$s(i,o),r?(i,a)=>bt(i,a,o):void 0)}}function ls(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){Lt(this)}}var Rr=!1,fs=null;function ds(){if(Rr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Rr=!0,document.addEventListener("turbo:before-stream-render",(e)=>{ct(e)})}function na(e){fs=e}var Or=!1;function jt(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 ps(){if(Or)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Or=!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(me.set(t,U(n)),!jt(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"||!jt(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)=>Zt(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{if(e.detail?.attributeName==="value"&&jt(e.target))e.preventDefault()})}var hs="__materialize",Nr=!1;function ms(){if(Nr)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Nr=!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 Xt(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")ht()}var Gr="data-reactive-active",x=0;function Yr(){if(x++,x===1)Vr("reactive:busy")}function Kr(){if(x===0)return;if(x--,x===0)Vr("reactive:idle")}function ra(){return x}function oa(){x=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(Gr)}function Vr(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(Gr,x>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:x}}))}var Xr="data-reactive-requests";function Zr(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!gs(t))return;let n=bs(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(Xr,JSON.stringify(n))}function gs(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function bs(e){try{let t=JSON.parse(e.getAttribute(Xr));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Cr(){as(),cs(),us(),ls(),ds(),ps(),ms(),Xt()}function ys(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Qr=Symbol.for("phlex-reactive.core");if(globalThis[Qr])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[Qr]=!0;var eo=!1;function vs(){if(eo)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(vs,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var As=new Set(["href","src","srcdoc","action","formaction","xlink:href","style"]);function ws(e){let t=String(e).toLowerCase();return t.startsWith("on")||As.has(t)}var Bt=new WeakMap;function Ss(e,t,n){let[r,o,i]=t;Bt.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,Bt.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Bt.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,_s(e))}function _s(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 xs=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Es=new Set(["lexxy-editor","trix-editor"]);function U(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
1
+ import{Controller as xs}from"@hotwired/stimulus";import{confirmResolver as Br}from"phlex/reactive/confirm";import{confirmPredicate as Eo}from"phlex/reactive/confirm_predicate";var O=new WeakMap,Ee=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)Ee.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 _e(e,t){let n=x(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&Ro(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")$o(n,s.target);else n.groups=Po(n),dn(n);Oo(n)},S(n,"input change",n.show),C(n,n.show);if(!n.arm&&Lo(n))S(n,"input change",(s)=>ln(n,s)),C(n,n.arm=()=>{ln(n,null),dn(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)=>qo(n,s)&&M(n)),C(n,()=>M(n));if(!i&&(i=V(n)))C(n,()=>En(n));if(!a&&(a=Wo(n)))S(n,"input change",(s)=>kn(n,s)),C(n,()=>Ce(n))})(),S(n,"keydown",(s)=>ti(n,s)),S(n,"paste drop",(s)=>ni(n,s)),S(n,"input",(s)=>ri(n,s))}function xe(e){let t=O.get(e);if(!t)return;O.delete(e),Ee.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Te(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 ke(e,t,n){return kn(x(e,t),n)}function Re(e,t,n){return Cn(x(e,t),n)}var _o=/^#[A-Za-z_][\w-]*$/,mn="[data-reactive-show-field], [data-reactive-show]";function xo(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 Rn){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return On(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function hn(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 To(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 gn(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 ko(e,t)}function ko(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)=>qe(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function G(e,t="show"){if(typeof e==="string"&&_o.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Ro(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?.(mn)??[];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 Lo(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Fo(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:To(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function ln(e,t){let n=Fo(e);if(!n.length)return;let r=vn(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 Oo(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=vn(e,t);for(let o of e.root.querySelectorAll(mn)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=gn(hn(i),r);if(u!==null)fn(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=xo(o,s);if(c===null)continue;fn(o,c,t,n)}if(e.groups)Io(e,r,t,n);No(e,r),Do(e,r)}function fn(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 No(e,t){let n=bn(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Co(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)=>qe(l,a))}else{let l=Nn(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 Co(e,t,n){if(!G(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Qo(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!ei(r))return;let i=P(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function bn(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 Mo(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(yn(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 yn(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function vn(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?Le(e,o,t,n).filter((s)=>s.checked).length:Mo(e,o,t,n));return r.get(a)}}var K="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Po(e){return!!e.root.querySelector?.(K)}function Le(e,t,n,r){return[...e.root.querySelectorAll(yn(t,r))].filter((o)=>o.type==="checkbox"&&n(o))}function $o(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))An(e,n,t.checked,t)}function Fe(e,t,n){if(!t)return;let r=Ee.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};An(r,t,n!==!1),r.show?.()}function An(e,t,n,r){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=Le(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 Io(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=gn(hn(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=Le(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 Do(e,t){for(let[n,r]of Object.entries(bn(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 dn(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 qo(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 Wo(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function Oe(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 Ne(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 wn(e,t){let n=Oe(e);if(!n)return!1;let r=Ne(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)Sn(e,n,r);return i}function Sn(e,t,n){t.value=n.join(","),N(t),En(e)}function jo(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 En(e){let t=Oe(e);if(!t)return;let n=Ne(t),r=e.core.ownership();Bo(e,n,r),Jo(e,n,r)}function Bo(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 Jo(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 Uo(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Ho(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 zo(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 Go(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)=>xn(m.getAttribute?.("name"))===c);if(!p)continue;Yo(p,l),s.push(l)}if(r)for(let c of s)Ko(c);return s[0]??null}function Yo(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Se(t)!=="";else e.value=Se(t);N(e)}function Ko(e){if(e.type==="checkbox")e.checked=!1;else e.value="";N(e)}function Vo(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",N(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);Ce(e)}function Ce(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))Tn(e,n.getAttribute("data-reactive-nested-json"))}function Xo(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 _n(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=xn(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Se(o)}return n}function xn(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Se(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Tn(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=Xo(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(_n(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,N(o)}function Me(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(!wn(r,String(o.value??"").split(",")))return;if(o.value="",Y(r))M(r)}function Pe(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(!wn(r,[i]))return;let a=jo(r);if(!a)return;a.value="",M(r),a.focus?.()}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;let a=Oe(r);if(!a)return;let s=Ne(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Sn(r,a,c)}function Ie(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){zo(r,i);return}let l=u.cloneNode(!0);Ho(l,Uo(r)),s.appendChild(l);let p=o?.getAttribute?.("data-reactive-nested-from-param"),m=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",g=Go(r,l,p,m);if(p)g?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Tn(r,i)}function De(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?Cn(r,s):null);if(!c)return pn(r,i);let u=_n(r,i),l=Vo(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((p)=>{if(p)pn(r,i)})}function kn(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;Ce(e)}var Rn=["gte","gt","lte","lt"],Zo=["len_eq","len_gte","len_gt","len_lte","len_lt"],Ln=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function Fn(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 On(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 Nn(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 Rn)if(n in e)return On(n,e[n],t);for(let n of Zo)if(n in e)return Fn(n,e[n],[...String(t??"")].length);return null}function qe(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Ln.find((o)=>(o in e));if(n){let o=t(e.field,!0);return Fn(n,e[n],Array.isArray(o)?o.length:Number(o)||0)===!0}let r=t(e.field)??"";return Nn(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)=>qe(r,t)))}function Qo(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 ei(e){return e.flat().every((t)=>Ln.some((n)=>(n in Object(t))))}function Cn(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=Eo(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 We(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ti(e,t){let n=We(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 ni(e,t){let n=We(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 ri(e,t){let n=We(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as oi}from"phlex/reactive/compute";var D=new WeakMap;function In(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 Be(e,t,n,r){let o=In(e,t),i=vi(o);if(i)o.seed=()=>je(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)je(o)}function Je(e){let t=D.get(e);if(!t)return;if(D.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function Ue(e){D.get(e)?.seed?.()}function He(e,t,n){return je(In(e,t),n)}var ii=Object.freeze({el:null,kind:""}),si=/^#[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 Dn(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function ai(e,t){if(t==="string")return I(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Dn(I(e));if(n)return e.el.checked?1:0;let r=Number(I(e));return Number.isFinite(r)?r:0}function ci(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Dn(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return ui(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function ui(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 li(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 fi(e){if(typeof e==="string"&&si.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function di(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 pi(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 mi(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 hi(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=gi(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function gi(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Pn(e,t,n){let r=String(n);for(let o of bi(e,t)){if(o.textContent===r)continue;o.textContent=r}}function bi(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function $n(e,t,n){let r=yi(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(!fi(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function yi(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 vi(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function je(e,t){if(t&&e.ours.has(t))return;let n=mi(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:""}:ii;return s.set(h,L),L};for(let h of r)Pn(e,h,I(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?oi(u):null;if(!l){$n(e,{},c);return}let p=pi(e,"data-reactive-compute-outputs-param"),m={};for(let[h,d]of n)m[h]=ai(c(h),d);let g=l(m,{changed:hi(e,t,r,o)})||{},b=li(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=ci(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;Pn(e,h,d)}$n(e,g,c);for(let h of v){let d=new Event("input",{bubbles:!0});e.ours.add(d),h.dispatchEvent(d)}di(e,b,Boolean(t))}var Ye;function Ke(e){Ye=e}var Jn=1,Ai="phlex-reactive:persist:",wi=new Set(["hidden","file","password","submit","button","reset","image"]),Ve=Symbol("persist-no-value"),Xe="data-reactive-persist-state",Si=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Ei=new Set(["lexxy-editor","trix-editor"]),_i="lexxy-editor, trix-editor, trix-toolbar",xi=["lexxy:change","trix-change"],Ti=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Wn=new WeakSet,jn=new WeakSet,Bn=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(!Wn.has(e))Wn.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Ze(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function Qe(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||jn.has(e))return;jn.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function et(e){return Ai+e.key}function ze(e,t){let n=Ze();if(!n)return null;let r;try{r=n.getItem(et(t))}catch(c){return Qe(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Jn)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 Un(e,t,{fields:n,state:r}){let o=Ze();if(!o)return!1;let i={v:Jn,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(et(t),JSON.stringify(i)),!0}catch(a){return Qe(e,a),!1}}function X(e,t){e?.removeAttribute?.(Xe);let n=Ze();if(!n)return;try{n.removeItem(et(t))}catch(r){Qe(e,r)}}function tt(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)||wi.has(i.type)||i.closest(_i))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(Si)){if(!o(i))continue;let a=ki(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Ei.has(i.localName)?"editor":"contenteditable"})}return r}function Hn(e){return e.hasAttribute("data-reactive-editable")?Ye.text(e):e.textContent??""}function ki(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function nt(e){return typeof e.value==="string"}function Ri(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Ti.has(e.value.trim())}function Li(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Bn.has(e))return;Bn.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 zn(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 Gn(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Ve;return e[0]}function Yn(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 tt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(nt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=Hn(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 Fi(e,t,n){let r=t.restore==="always",o=tt(e,t),i=zn(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=Gn(l,c,i),l===Ve)continue}if((s.type==="checkbox"||q(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")Kn(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&Hn(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)}}Oi(e,t,n)}function Kn(e,t,n,r,o){if(Array.isArray(r))return;if(!nt(t))return;if(!o&&!Ri(t))return;try{t.value=String(r)}catch(i){Li(e,n,i)}}function Oi(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(!nt(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=tt(e,t),c=zn(s);for(let{el:u,name:l,kind:p}of s){if(p!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let m=Gn(n[l],l,c);if(m===null||m===void 0||m===Ve)continue;Kn(e,u,l,m,i)}})}function Ni(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=ze(e,r),i={...o?.state??{},...t},a=n?Yn(e,r):o?.fields??{};if(Un(e,r,{fields:a,state:i}))e.setAttribute?.(Xe,JSON.stringify(i))}function Ci(e){let t=Z(e);if(t)X(e,t)}var Ge=new WeakMap;function rt(e,t,n,r){let o=e.element,i=Z(o);if(!i)return;if(r?.submitted)X(o,i);let a=ze(o,i);if(a){if(Fi(o,i,a.fields),a.state)o.setAttribute?.(Xe,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=ze(o,i);Un(o,i,{fields:Yn(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",...xi];for(let g of m)o.addEventListener?.(g,l);if(o.addEventListener?.("change",u),document.addEventListener?.("turbo:submit-end",p),Ge.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 ot(e){let t=Ge.get(e);Ge.delete(e),t?.()}function Vn(e,t){let n=Ye?.waiting.get(e)?.persist;if(!n||!Z(e))return t(!0);(n.ops??=[]).push(t)}function it(e,t){Vn(e,(n)=>Ni(e,t,n))}function st(e){Vn(e,()=>Ci(e))}var Q=new WeakMap,Zn=new WeakSet;function at(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=Mi(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")$i(n,i)}if(!s&&(s=Ii(n,t))){let u=()=>Di(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 ct(e){for(let t of Q.get(e)?.[0]??[])t();Q.delete(e)}function ut(e){Q.get(e)?.[1]()}function Mi(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,Pi(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 Pi(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 Qn(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function $i(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;t(window,"beforeunload",(n)=>{if(Qn(e)===0)return;return n.preventDefault(),n.returnValue="You have unsaved changes.",n.returnValue}),t(window,"turbo:before-visit",(n)=>{if(Qn(e)===0||Zn.has(n))return;if(Zn.add(n),!(typeof window.confirm==="function"?window.confirm("You have unsaved changes. Leave anyway?"):!0))n.preventDefault?.()})}function Ii(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 Di(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 pt(e){qi(e),ji(e)}function qi(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(lt);else setTimeout(lt,0);return}let r=async(o)=>{await n(o),lt()};r.__reactiveDismissWrapped=!0,t.render=r}function lt(){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 Wi=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),ft=Object.freeze(["fade","slide","scale","highlight","shake"]),dt="data-reactive-fx-pending",mt=1000;function ji(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Wi[r?.getAttribute?.("action")];if(!o||Ui())return;let i=Bi(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Gi(te(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Hi(r):null;if(await n(s),o==="enter")zi(c,i);else nr(te(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Bi(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return tr(n,t);let o=(t==="enter"?Ji(e):te(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?tr(o,t):null}function te(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Ji(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function tr(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"?ft[Math.floor(Math.random()*ft.length)]:e;if(!ft.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Ui(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Hi(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(dt,"");return te(e)}function zi(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${dt}]`)))n.removeAttribute(dt),nr(n,t)}async function Gi(e,t){if(!e?.classList)return;if(t.legs){await rr(e,t.legs);return}e.classList.add(t.className);let n=ht(e);if(n<=0){e.classList.remove(t.className);return}await gt(e,n),e.classList.remove(t.className)}function nr(e,t){if(!e?.classList)return;if(t.legs){rr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=ht(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;gt(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function rr(e,t){let[n,r,o]=t.map(Yi),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Ki(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=ht(e);if(a>0)await gt(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function Yi(e){return String(e??"").split(/\s+/).filter(Boolean)}function ht(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,mt)}catch{return 0}}function gt(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,mt))})}function Ki(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},mt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Vi="phlex-reactive:latency",bt=!1;function sr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function ar(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),bt=!1}function vt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:sr,disableLatencySim:ar}}function At(){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(!bt)bt=!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 ir=new WeakMap;function wt(e){let t=globalThis.document;if(!t)return!0;let n=ir.get(t);if(!n)n=new Set,ir.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function yt(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function cr(e,t,n,r){if(wt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function St(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=yt(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}cr(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Et(e){if(!wt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function _t(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(yt(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=yt(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}cr(t,o,`scoped to #${r?.id||"?"}`,i)}function xt(e,t){let n=e.element?.id||"?";if(wt(`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 Xi(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 Tt(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=Xi(t),e.tokenRefreshed=n!=null}var re=new WeakMap;function kt(e,t,n,r){let o=n&&typeof n==="object"?es(n):n;return o?lr(t,o,r,!1):[]}function Rt(e,t,n,r){if(!n)return null;let o=lr(t,n,r,!0);return o.length?o:null}function lr(e,t,n,r){let o=[];for(let i of fr(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(Zi(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function fr(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 Zi(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()=>Qi(t,e)}function Qi(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 es(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function Lt(e,t,n,r){if(!n?.hide)return null;let o=fr(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 Nt(e){se=e}var E=new Map;function hr(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 pr=!1;function Ct(e){gr();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){ss(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;j(t,n)}function gr(){if(pr||typeof document>"u"||!document.addEventListener)return;pr=!0,document.addEventListener("turbo:before-stream-render",cs,!0),document.addEventListener("turbo:before-stream-render",ts)}function ts(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}Pt(e),Ar(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return hr(e,r),as(e,r,t)}function ns(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[ls(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":fs()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function br(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(yr(t))return{src:t};return console.error(rs(t)),os(t)||is(e)}function rs(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Mt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function os(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Mt()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&yr(r))return{src:r,fallback:!0}}function is(e){Pt(e.id),$t(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 yr(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Mt()}/`)}catch{return!1}}function Mt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function ss(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}Pt(e),Ar(n);let o=document.createElement("pgbus-stream-source");o.id=vr(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),hr(e,{via:"stream"})}function vr(e){return`reactive-defer-src-${e}`}async function as(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},ds()),o;try{se.count("defer"),o=await fetch(...ns(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),mr(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;mr(e),us(a)}var Ot=null,cs=(e)=>Ot?.push(e);function us(e){let t=Ot=[];try{window.Turbo.renderStreamMessage(e)}finally{Ot=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 Pt(e){let t=E.get(e);if(!t)return;if(ae(e),t.via==="fetch")t.abort.abort();else document.getElementById(vr(e))?.remove?.()}function Ar(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function $t(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function mr(e){ae(e);let t=document.getElementById(e);if(!t)return;$t(t),t.removeAttribute("data-reactive-error")}function W(e,t,n){ae(e);let r=document.getElementById(e);if(!r)return;$t(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 ls(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function fs(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function ds(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var wr="__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 It(e,t,n){gr();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=br(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&ps(r,t))return;let y=d?j(r.id,d):t.proceed(r,wr,"{}");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)Ft(r),c=(d)=>d.target===r&&Ft(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)Ft(r);b()},r.addEventListener?.("turbo:morph-element",u),n)return b();if(o=oe(r)!==null,o)p(!1)}function Dt(e){let t=ie.get(e);ie.delete(e),t?.off()}function ce(e){return ie.get(e)?.load()}function ps(e,t){return t.emit("reactive:before-dispatch",{action:wr,params:{},element:e},{cancelable:!0}).defaultPrevented}function Ft(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||br(e);if(t)j(e.id,t)}var qt=new WeakMap,le=new WeakMap,f=null,k,Er;function Jt(e,t){let n=e.element;le.set(n,t),Nr();let r=(i)=>hs(i,t),o=(i)=>As(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),qt.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function Ut(e){if(qt.get(e)?.(),qt.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"]'),kr=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==f?.row&&kr(t)===e),_r=(e)=>B(A(e,"-item"),null),Wt=(e)=>A(e,"-disabled")==="true",ms=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Rr=(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&&!Wt(n)&&le.has(fe(n)))};function Lr(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&kr(n);if(f||!r||!t.owns(r)||Wt(r)||Wt(n))return;if(fe(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function hs(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Lr(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 jt(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return h();bs(n,t,d),jt(d.clientX,d.clientY)},p=(d)=>f&&d.cancelable&&d.preventDefault(),m=(d)=>{if(!a(d))return;if(h(),f)gs(),Bt()},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 gs(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function bs({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=Fr({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 Fr(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 jt(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=Rr(f.origin).find((r)=>ms(r,e,t));if(n)ys(n,e,t);else if(f.source)Ht(null),f.placeholder.remove();vs(e,t)}function Ht(e){if(f.target!==f.origin)J(f.target,!1);f.target=e,J(e,!0)}function ys(e,t,n){Ht(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 vs(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);jt(f.x,f.y),f.raf=requestAnimationFrame(i)};f.raf=requestAnimationFrame(i)}}function As(e,t){let n=e.key;if(f?.keyboard){if(e.target!==f.row||f.core!==t)return;let o={" ":Bt,Enter:Bt,Escape:ue,Tab:ue,ArrowUp:()=>xr(-1),ArrowDown:()=>xr(1),ArrowLeft:()=>Tr(-1),ArrowRight:()=>Tr(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Lr(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),f=Fr({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),me("picked")}function xr(e){let t=T(f.target),n=pe()+e;if(n>=0&&n<=t.length)de(f.target,t,n,f.row);Or()}function Tr(e){let t=Rr(f.origin),n=t[t.indexOf(f.target)+e];if(n){let r=pe();Ht(n),de(n,T(n),r,f.row)}Or()}function Or(){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 Nr(){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=Nr();r.textContent="",cancelAnimationFrame(Er),Er=requestAnimationFrame(()=>r.textContent=n)}function Bt(){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?_r(T(t)[s-1]):null;if(e.keyboard)me("dropped");if(!r&&i)i.replaceWith(o);if(Mr(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:_r(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)=>ws(b,m)||Cr(e))}function ws(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"))&&Ss(r,t))}function Ss(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(),Mr(e),Cr(e)}function Cr({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 Mr(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,$r=new WeakSet;function zt(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,Es(n);let o=(a)=>a.target===n&&queueMicrotask(()=>Dr(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)},Dr(r)}function Gt(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 Yt(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},qr(n)}function Es(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&$r.has(n))return;if(n?.remove(),!Ir())setTimeout(()=>{if(!Ir())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;qr(o),_s(o)}),$r.add(r),document.body.appendChild(r)}var Ir=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function _s(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&&Wr(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 qr(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 Wr(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 Dr(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=Wr(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 Ts(){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 ks(){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 Rs(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=un(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)Et(n);return}sn(t,(i)=>oa(i,o),r?(i,a)=>St(i,a,o):void 0)}}function Ls(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){Ct(this)}}var Jr=!1,Fs=null;function Os(){if(Jr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Jr=!0,document.addEventListener("turbo:before-stream-render",(e)=>{Ns(e),pt(e)})}var ge="reactive:streamed";function Ns(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 _a(e){Fs=e}var he,Kt=null,Ur="[data-reactive-editable][contenteditable=plaintext-only]";function lo(){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?.(Ur))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Ur).forEach(be)}function Cs(){if(Kt||typeof document>"u"||typeof document.createElement!=="function")return;if(lo())return;be(document),Kt=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")be(t.target);else t.addedNodes.forEach(be)}),Kt.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Hr=!1;function Vt(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 Ms(){if(Hr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Hr=!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(ve.set(t,U(n)),!Vt(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"||!Vt(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)=>cn(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{if(e.detail?.attributeName==="value"&&Vt(e.target))e.preventDefault()})}var Ps="__materialize",zr=!1;function $s(){if(zr)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;zr=!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 an(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")vt()}var fo="data-reactive-active",_=0;function po(){if(_++,_===1)ho("reactive:busy")}function mo(){if(_===0)return;if(_--,_===0)ho("reactive:idle")}function xa(){return _}function Ta(){_=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(fo)}function ho(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(fo,_>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:_}}))}var go="data-reactive-requests";function bo(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Is(t))return;let n=Ds(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(go,JSON.stringify(n))}function Is(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Ds(e){try{let t=JSON.parse(e.getAttribute(go));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Gr(){Ts(),ks(),Rs(),Ls(),Os(),Ms(),Cs(),$s(),an()}function qs(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var yo=Symbol.for("phlex-reactive.core");if(globalThis[yo])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[yo]=!0;var vo=!1;function Ws(){if(vo)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(Ws,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var js=new Set(["href","src","srcdoc","action","formaction","xlink:href","style"]);function Bs(e){let t=String(e).toLowerCase();return t.startsWith("on")||js.has(t)}var Xt=new WeakMap;function Js(e,t,n){let[r,o,i]=t;Xt.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,Xt.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};Xt.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Us(e))}function Us(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 Hs=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",zs=new Set(["lexxy-editor","trix-editor"]);function U(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 me=new WeakMap;function Zt(e){if(e?.hasAttribute?.("data-reactive-editable")&&!me.has(e))me.set(e,U(e))}function to(e){return Zt(e),me.get(e)}function Ts(e){return Es.has(e.localName)?typeof e.value==="string":!0}var Mr=Object.freeze({show:(e,t,n)=>Jt(e,!1,t,n),hide:(e,t,n)=>Jt(e,!0,t,n),toggle:(e,t,n)=>Jt(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(Ut(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Ut(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Ut(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)=>Os(e)?.focus?.(),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)Ee(r,t.group,t.checked)},dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,n)=>{let r=ks(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)=>Ls(e),persist_state:(e,t)=>et(e,t.state),persist_clear:(e)=>tt(e)});function ks(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Ls(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 Fs(e,t,n){if(n?.transition)Ss(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Jt(e,t,n,r){if(Fs(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 Ut(e){if(!ws(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}var Rs='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Os(e){return e.querySelectorAll?.(Rs)?.[0]??null}function Qt(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 Pr=Object.freeze({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"}),$r=Object.freeze(["meta","ctrl","alt","shift"]);function en(e,t,n){let r=e.split("+");for(let a of $r)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!$r.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Pr,o)?Pr[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}function Ns(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:Qt(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 Ir(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)!==no(t.currentTarget))return!1;return o<0||n===null||en(r.slice(o+1),t,n)}function Cs(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 Dr=new WeakMap;function Ms(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Dr.get(e);if(!o)o=new WeakMap,Dr.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 qr=new WeakMap;function Ps(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=qr.get(e);if(!o)o=new WeakMap,qr.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 Vt(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Mr,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)Mr[o](s,i,t)}}function $s(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 Is(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Wr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function Ds(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 qs(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 Ws(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function js(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function ia(e,t,n){}function Bs(e,t){}function sa(e){return[]}function aa(e){return Promise.resolve()}var jr=new Set;function Js(e,t,n){let r=e+t;if(jr.has(r))return;jr.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 ca(){return["persist","defer","form","bindings","compute","sortable","effects","hints","devtools"]}var Br=Promise.resolve();var Jr={enter:Yr,exit:Kr,count:Zr,text:U,served:to,waiting:new WeakMap},Ur=1,Ht=2,zt=4,Gt=8,Yt=16,Hr=32;Ue(Jr),kt(Jr);var H=Symbol.for("phlex-reactive.early"),Us=1e4,Hs=1500,no=(e)=>e!=null&&(e===globalThis.window||e.window===e);function Kt(){return globalThis[H]??={queue:[],connected:new WeakSet},globalThis[H]}function zs(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Us}function Gs(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 Ys(e,t,n){return{[H]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Gs(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 ge=new WeakMap;function Ks(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=ge.get(e);if(!s)ge.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 zr(e,t,n,r){if(e?.[H])return!1;let o=no(e?.currentTarget),i=o?r:e?.currentTarget,a=Xs(e,i,o?`@${t}`:t),s=ge.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&&!en(u.filter,e,n))continue;return u.armed=!1,!0}return a}var he=new WeakMap;function Vs(e,t,n){let r=he.get(e);if(!r)he.set(e,r=new Map),setTimeout(()=>he.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Xs(e,t,n){let r=e&&he.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class ro extends ss{static values={token:String};#h;#m=new Map;#f=new Map;#H;#w;#M;#S=0;#d=new Map;#_=new WeakMap;#r;featuresReady=Br;#Ee=new Map;#Te=new Set;#z=!1;#P=null;#ke=new Map;#Le=new Map;#Fe=new Map;#G=0;#$;#x=0;#t=0;connect(){if(eo=!0,Kt().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||Wr(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(Zt),this.#G++,this.featuresReady=Br,this.#I(),this.#V()}#I(e){this.#o(Ur,"persist",Is,(t)=>Ze(this,t,e)),this.#o(Ht,"defer",Wr,(t)=>Nt(this,t,e)),this.#o(zt,"form",Ds,(t)=>rt(this,t,e)),this.#o(Gt,"bindings",qs,(t)=>ve(this,t,e)),this.#o(Yt,"compute",Ws,(t)=>Ie(this,t,e)),this.#o(Hr,"sortable",js,(t)=>Dt(this,t))}#o(e,t,n,r){if(this.#x&e)return;try{if(!n(this.element))return}catch(o){return this.#D(t,"detect",o)}this.#x|=e;try{r(this.#e()),this.#t|=e}catch(o){this.#D(t,"connect",o)}}#Y(){{let e=this.#t;this.#x=this.#t=0;let t=this.#e();if(e&Ur)this.#i("persist",()=>Qe(this,t));if(e&Ht)this.#i("defer",()=>Ct(this,t));if(e&zt)this.#i("form",()=>ot(this,t));if(e&Gt)this.#i("bindings",()=>Ae(this,t));if(e&Yt)this.#i("compute",()=>De(this,t));if(e&Hr)this.#i("sortable",()=>qt(this,t))}}#i(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Re(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.#K(),proceed:(e,t,n,r)=>this.#T(e,t,n,0,0,null,r),forgetToken:()=>{this.#h=void 0},owns:(e)=>this.#v(e),ownership:()=>this.#F(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>Vt(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.#B(),text:U,served:to,confirm:(e,t)=>Promise.resolve().then(()=>Fr(e,t)).catch(()=>!1)},this.#$}#K(){if(this.#t&zt)q(this,this.#e());if(this.#t&Gt)we(this);if(this.#t&Yt)qe(this)}#D(e,t,n){if(Js(e,t,n),this.#n("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()}#E=new Set;#X(){let{queue:e}=Kt();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=zs(),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(Hs,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=Ys(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&&!en(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Ks(s,c,r&&JSON.stringify(o.params)))continue;this.#E.add(s)}if(Vs(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.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r);Kt().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#E)ge.delete(e);this.#E.clear()}dispatch(e){if(zr(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:t,params:n,debounce:r,throttle:o,confirm:i,confirmWhen:a,outside:s,window:c,optimistic:u}=e.params;if(!t)return;let l=e.params.busy??e.params.loading;if(s&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if(!c&&!this.#be(u,p))e.preventDefault();if(t===hs){let b=()=>{if(this.#t&Ht)return ae(this);if(this.tokenValue)return this.#T(p,t,"{}")};return this.#z?this.featuresReady.then(b):b()}let h=this.#q(i,a),g=()=>this.#T(p,t,n,r,o,u,l);if(!h)return g();if(h instanceof Promise)return h.then((b)=>b?this.#g(b,p,g):g());this.#g(h,p,g)}#g(e,t,n){return Promise.resolve().then(()=>Fr(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return _e(this,this.#e(),t)}#Q(e){}runOps(e){if(zr(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Ps(e,this))return;let t=e.params??{},n=e.currentTarget??e.target,r=Ns(t.ops),o=r.filter((a)=>Ir(a,e,null)),i=o.length<=1?o:o.filter((a)=>Ir(a,e,this.application?.schema?.keyMappings));if(i.length===0&&r.length>0){if(this.#O())At(this,e);return}for(let a of i){if(a.outside&&e[H])continue;if(!Cs(a,e))continue;if(Ms(this,e,a))continue;this.#ee(a.legacy?{...t,ops:a.ops}:a,e,n)}}#ee({ops:e,confirm:t,confirmWhen:n,outside:r,window:o},i,a){if(r&&this.element.contains(i.target))return;if(!o)i.preventDefault();let s=this.#q(t,n),c=()=>this.#ge(this.#me(e));if(!s)return c();if(s instanceof Promise)return s.then((u)=>u?this.#g(u,a,c):c());this.#g(s,a,c)}recompute(e){return We(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#p(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return Fe(this,this.#e(),e)}tagsPick(e){return Re(this,this.#e(),e)}tagsRemove(e){return Oe(this,this.#e(),e)}nestedAdd(e){return Ne(this,this.#e(),e)}nestedRemove(e){return Ce(this,this.#e(),e)}syncNestedJson(e){return Se(this,this.#e(),e)}#$e(e,t){}trackDirty(){q(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.#F();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.#J(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=(h)=>{if(!s||!h)return;let g=this.#e();if(i.inverse=_t(this,g,n,r),i.undo.push(...St(this,g,o,r)),this.#L())i.resurrect=xt(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.#m.set(e,{timer:s,flush:a})}#k(e){let t=this.#m.get(e);if(!t)return;clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),this.#m.delete(e)}#re(){for(let e of[...this.#m.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})}#n(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 mt()}#L(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#W(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ue(e,t,n,r){let{fields:o,files:i}=this.#B(),a=this.#J(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.#W()}:null;await this.#ce();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#n("offline"),this.#a(e,t,s,{kind:"offline"});return}let h;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#_e()};if(!u)m["Content-Type"]="application/json";let d=this.#xe();if(d)m["X-Pgbus-Connection"]=d;Zr("action"),h=await fetch(this.#we(),{method:"POST",headers:m,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Se())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#u(n.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#n("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#ae(),this.#n("network"),this.#a(e,t,s,{kind:"network"});return}if(p)p.status=h.status;if(h.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#n("redirected"),this.#a(e,t,s,{kind:"redirected",status:h.status});return}if(!h.ok){let m=await h.text();if(console.error(`[phlex-reactive] action failed: HTTP ${h.status}`,m),this.#u(n.inverse),(h.headers.get("Content-Type")||"").includes("turbo-stream")){let d=this.#j(m);if(this.#c=d??this.#c,p)te(p,m,d);window.Turbo.renderStreamMessage(m)}this.#n("http"),this.#a(e,t,s,{kind:"http",status:h.status,body:m});return}let g=h.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.#n("content-type"),this.#a(e,t,s,{kind:"content-type",status:h.status});return}let b=await h.text(),A=this.#j(b);if(this.#c=A??this.#c,p)te(p,b,A);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(h){console.error("[phlex-reactive] action error",h),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),p)wt(this,{...p,ms:this.#W()-p.started})}}get#c(){return this.#h??this.tokenValue}set#c(e){this.#h=e}tokenValueChanged(){this.#h=void 0}#j(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=ys(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}#F(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#v(t)}#B(){let e={},t=[],n=this.#F(),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]${xs}`).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("[]")&&!Ts(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.#R(o,this.#A(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#he(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("")}`}#R(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#R(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#R(e,`${t}[${r}]`,o);else e.append(t,String(n))}#he(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))}#J(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#me(e){return Qt(e)}#ge(e){Vt(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;vt(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),Yr();let r=!1;return()=>{if(r)return;r=!0,this.#Ae(e,t),Kr();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.#U(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.#U(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#_.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.#_.delete(e),e.removeAttribute("data-reactive-busy");return}this.#_.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#U(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#v(n))}#we(){return this.#H??=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}#_e(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#xe(){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)Cr();else document.addEventListener("turbo:load",Cr,{once:!0});Xt();var ba=ro;export{Gr as ACTIVE_ATTR,xs as EDITOR_SELECTOR,Es as EDITOR_TAGS,Ci as LATENCY_KEY,Xr as REQUESTS_ATTR,vs as checkReactiveRegistration,Zr as countReactiveRequest,ba as default,er as disableLatencySim,U as editableValue,Qn as enableLatencySim,Yr as enterReactiveActivity,ys as escapeRegExp,Kr as exitReactiveActivity,aa as loadReactiveFeature,na as onReactiveStreamWithoutEffects,ra as reactiveActivityCount,ca as reactiveFeatureNames,Cr as registerReactiveActions,ls as registerReactiveDefer,Xt as registerReactiveDev,ds as registerReactiveDismiss,ds as registerReactiveEffects,Bs as registerReactiveFeature,ia as registerReactiveFeatureLoader,us as registerReactiveJs,ps as registerReactiveMorphFocus,ms as registerReactiveOffline,ds as registerReactiveStreamRender,cs as registerReactiveToken,as as registerReactiveVisit,oa as resetReactiveActivity,to as serverText,sa as unloadedFeaturesFor};
5
+ `).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var ve=new WeakMap;function cn(e){if(e?.hasAttribute?.("data-reactive-editable")&&!ve.has(e))ve.set(e,U(e))}function Ao(e){return cn(e),ve.get(e)}function Gs(e){return zs.has(e.localName)?typeof e.value==="string":!0}var Yr=Object.freeze({show:(e,t,n)=>Zt(e,!1,t,n),hide:(e,t,n)=>Zt(e,!0,t,n),toggle:(e,t,n)=>Zt(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(Qt(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Qt(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Qt(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)=>Zs(e)?.focus?.(),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)Fe(r,t.group,t.checked)},presence:(e,t)=>Yt(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=Ys(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)=>Ks(e),persist_state:(e,t)=>it(e,t.state),persist_clear:(e)=>st(e)});function Ys(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Ks(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 Vs(e,t,n){if(n?.transition)Js(e,n.transition,()=>e.hidden=t);else e.hidden=t}function Zt(e,t,n,r){if(Vs(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 Qt(e){if(!Bs(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}var Xs='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Zs(e){return e.querySelectorAll?.(Xs)?.[0]??null}function un(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 Kr=Object.freeze({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"}),Vr=Object.freeze(["meta","ctrl","alt","shift"]);function we(e,t,n){let r=e.split("+");for(let a of Vr)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Vr.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Kr,o)?Kr[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Qs=(e)=>e&&typeof e==="object"?e.keys:String(e);function Xr(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 we(Qs(e).replace(/^mod\+/,`${o}+`),t,n)}function ea(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:un(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 Zr(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)!==wo(t.currentTarget))return!1;return o<0||n===null||we(r.slice(o+1),t,n)}function ta(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 Qr=new WeakMap;function na(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Qr.get(e);if(!o)o=new WeakMap,Qr.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 eo=new WeakMap;function ra(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=eo.get(e);if(!o)o=new WeakMap,eo.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 sn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Yr,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)Yr[o](s,i,t)}}function oa(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 ia(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function to(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function sa(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 aa(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 ca(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function ua(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 ka(e,t,n){}function la(e,t){}function Ra(e){return[]}function La(e){return Promise.resolve()}var ro=new Set;function fa(e,t,n){let r=e+t;if(ro.has(r))return;ro.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 Fa(){return["persist","defer","form","bindings","compute","sortable","presence","effects","hints","devtools"]}var oo=Promise.resolve();var io={enter:po,exit:mo,count:bo,text:U,served:Ao,waiting:new WeakMap},so=1,en=2,tn=4,nn=8,rn=16,ao=32,co=64;Ke(io),Nt(io);var H=Symbol.for("phlex-reactive.early"),da=1e4,pa=1500,wo=(e)=>e!=null&&(e===globalThis.window||e.window===e);function on(){return globalThis[H]??={queue:[],connected:new WeakSet},globalThis[H]}function ma(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:da}function ha(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 ga(e,t,n){return{[H]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:ha(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 Ae=new WeakMap;function ba(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Ae.get(e);if(!s)Ae.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 uo(e,t,n,r){if(e?.[H])return!1;let o=wo(e?.currentTarget),i=o?r:e?.currentTarget,a=va(e,i,o?`@${t}`:t),s=Ae.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&&!we(u.filter,e,n))continue;return u.armed=!1,!0}return a}var ye=new WeakMap;function ya(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 va(e,t,n){let r=e&&ye.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class So extends xs{static values={token:String};#m;#h=new Map;#f=new Map;#z;#w;#M;#S=0;#d=new Map;#E=new WeakMap;#t;featuresReady=oo;#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(vo=!0,on().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||to(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(cn),this.#Y++,this.featuresReady=oo,this.#I(),this.#V()}#I(e){this.#r(so,"persist",ia,(t)=>rt(this,t,e)),this.#r(en,"defer",to,(t)=>It(this,t,e)),this.#r(tn,"form",sa,(t)=>at(this,t,e)),this.#r(nn,"bindings",aa,(t)=>_e(this,t,e)),this.#r(rn,"compute",ca,(t)=>Be(this,t,e)),this.#r(ao,"sortable",ua,(t)=>Jt(this,t)),this.#r(co,"presence",no,(t)=>zt(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&so)this.#o("persist",()=>ot(this,t));if(e&en)this.#o("defer",()=>Dt(this,t));if(e&tn)this.#o("form",()=>ct(this,t));if(e&nn)this.#o("bindings",()=>xe(this,t));if(e&rn)this.#o("compute",()=>Je(this,t));if(e&ao)this.#o("sortable",()=>Ut(this,t));if(e&co)this.#o("presence",()=>Gt(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)=>sn(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:lo,text:U,served:Ao,confirm:(e,t)=>Promise.resolve().then(()=>Br(e,t)).catch(()=>!1)},this.#$}#D(){if(this.#n&tn)ut(this);if(this.#n&nn)Te(this);if(this.#n&rn)Ue(this)}#q(e,t,n){if(fa(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}=on();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=ma(),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(pa,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=ga(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&&!we(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!ba(s,c,r&&JSON.stringify(o.params)))continue;this.#x.add(s)}if(ya(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);on().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#x)Ae.delete(e);this.#x.clear()}dispatch(e){if(uo(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:t,params:n,debounce:r,throttle:o,confirm:i,confirmWhen:a,outside:s,window:c,optimistic:u,shortcut:l}=e.params;if(!t)return;if(l!=null&&!Xr(l,e,this.application?.schema?.keyMappings))return;let p=e.params.busy??e.params.loading;if(s&&this.element.contains(e.target))return;let m=e.currentTarget??e.target;if((l!=null||!c)&&!this.#be(u,m))e.preventDefault();if(t===Ps){let v=()=>{if(this.#n&en)return ce(this);if(this.tokenValue)return this.#T(m,t,"{}")};return this.#G?this.featuresReady.then(v):v()}let g=this.#W(i,a),b=()=>this.#T(m,t,n,r,o,u,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(()=>Br(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return Re(this,this.#e(),t)}#Q(e){}runOps(e){if(uo(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(ra(e,this))return;let t=e.params??{},n=e.currentTarget??e.target,r=ea(t.ops),o=r.filter((a)=>Zr(a,e,null)),i=o.length<=1?o:o.filter((a)=>Zr(a,e,this.application?.schema?.keyMappings));if(i.length===0&&r.length>0){if(this.#O())xt(this,e);return}for(let a of i){if(a.outside&&e[H])continue;if(!ta(a,e))continue;if(a.shortcut!=null&&!Xr(a.shortcut,e,this.application?.schema?.keyMappings))continue;if(na(this,e,a))continue;this.#ee(a.legacy?{...t,ops:a.ops}:a,e,n)}}#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 He(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#p(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return Me(this,this.#e(),e)}tagsPick(e){return Pe(this,this.#e(),e)}tagsRemove(e){return $e(this,this.#e(),e)}nestedAdd(e){return Ie(this,this.#e(),e)}nestedRemove(e){return De(this,this.#e(),e)}syncNestedJson(e){return ke(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=Rt(this,g,n,r),i.undo.push(...kt(this,g,o,r)),this.#R())i.resurrect=Lt(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 At()}#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=no(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(y)h["X-Reactive-Presence"]=y;bo("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)Tt(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=qs(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]${Hs}`).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("[]")&&!Gs(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 un(e)}#ge(e){sn(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;_t(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),po();let r=!1;return()=>{if(r)return;r=!0,this.#Ae(e,t),mo();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)Gr();else document.addEventListener("turbo:load",Gr,{once:!0});an();var qa=So;export{fo as ACTIVE_ATTR,Hs as EDITOR_SELECTOR,zs as EDITOR_TAGS,Vi as LATENCY_KEY,go as REQUESTS_ATTR,Ws as checkReactiveRegistration,bo as countReactiveRequest,qa as default,ar as disableLatencySim,U as editableValue,sr as enableLatencySim,po as enterReactiveActivity,qs as escapeRegExp,mo as exitReactiveActivity,La as loadReactiveFeature,_a as onReactiveStreamWithoutEffects,xa as reactiveActivityCount,Fa as reactiveFeatureNames,Gr as registerReactiveActions,Ls as registerReactiveDefer,an as registerReactiveDev,Os as registerReactiveDismiss,Os as registerReactiveEffects,la as registerReactiveFeature,ka as registerReactiveFeatureLoader,Rs as registerReactiveJs,Ms as registerReactiveMorphFocus,$s as registerReactiveOffline,Cs as registerReactivePlaintext,Os as registerReactiveStreamRender,ks as registerReactiveToken,Ts as registerReactiveVisit,Ta as resetReactiveActivity,Ao as serverText,Ra as unloadedFeaturesFor};
6
6
 
7
- //# debugId=D9E1FAEE6C6589A664756E2164756E21
7
+ //# debugId=4F31FFF4F704480B64756E2164756E21
8
8
  //# sourceMappingURL=reactive_controller.min.js.map