phlex-reactive 0.14.1 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{Controller as ii}from"@hotwired/stimulus";import{confirmResolver as jr}from"phlex/reactive/confirm";import{confirmPredicate as gn}from"phlex/reactive/confirm_predicate";var E=new WeakMap,ne=new WeakMap;function w(e,t){let r=E.get(e);if(!r){if(E.set(e,r={root:e.element,core:t,nestedIndex:0}),r.root)ne.set(r.root,r)}return r}function T(e,t,r){for(let n of t.split(" "))e.root.addEventListener?.(n,r),e.offs.push(()=>e.root.removeEventListener?.(n,r))}function k(e,t){T(e,"turbo:morph-element",t),e.seeds.push(t),t()}function oe(e,t){let r=w(e,t);if(r.offs=[],r.seeds=[],wn(r))r.show=(n)=>{if(r.flipping)return;if(n?.type==="input"||n?.type==="change")Ln(r,n.target);else r.groups=Fn(r),Nt(r);xn(r)},T(r,"input change",r.show),k(r,r.show);if(Sn(r))T(r,"input change",(n)=>Lt(r,n)),k(r,r.arm=()=>{Lt(r,null),Nt(r)});if(r.show||r.arm)T(r,"reset",()=>setTimeout(()=>{if(E.get(e)!==r)return;r.show?.(),r.arm?.()},0));if(j(r))T(r,"input",(n)=>On(r,n)&&F(r)),k(r,()=>F(r));if(J(r))k(r,()=>Bt(r));if(Cn(r))T(r,"input change",(n)=>Ht(r,n)),k(r,()=>pe(r))}function ie(e){let t=E.get(e);if(!t)return;E.delete(e),ne.delete(t.root);for(let r of t.offs??[])r();t.groupObserver?.disconnect()}function se(e){for(let t of E.get(e)?.seeds??[])t()}function L(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ae(e,t,r){return Ht(w(e,t),r)}function ce(e,t,r){return Zt(w(e,t),r)}var yn=/^#[A-Za-z_][\w-]*$/,Ct="[data-reactive-show-field], [data-reactive-show]";function vn(e,t){let r=e.getAttribute("data-reactive-show-equals");if(r!==null)return t===r;let n=e.getAttribute("data-reactive-show-not");if(n!==null)return t!==n;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 Gt){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Yt(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Mt(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 bn(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((r)=>r&&typeof r==="object"&&Array.isArray(r.any)&&Array.isArray(r.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function Pt(e,t){if(!e||typeof e!=="object")return null;let r=e.any;if(Array.isArray(r)&&(r.length===0||Array.isArray(r[0])))return R(r,t);return An(e,t)}function An(e,t){let r=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!r)return null;let n=e[r];if(n.length===0)return null;let o=n.map((i)=>be(i,t));return r==="all"?o.every(Boolean):o.some(Boolean)}function W(e,t="show"){if(typeof e==="string"&&yn.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function wn(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?.(Ct)??[];for(let r of t)if(e.core.owns(r))return!0;for(let r of e.root.querySelectorAll?.(B)??[])if(e.core.owns(r))return!0;return!1}function Sn(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function _n(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:bn(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Lt(e,t){let r=_n(e);if(!r.length)return;let n=qt(e,e.core.ownership());r.forEach((o,i)=>{let a=R(o.any,n);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 xn(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),r=e.root.getAttribute?.("data-reactive-scope")||null,n=qt(e,t);for(let o of e.root.querySelectorAll(Ct)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=Pt(Mt(i),n);if(u!==null)Rt(o,u,t,r);continue}let a=o.getAttribute("data-reactive-show-field");if(!a)continue;let s=n(a);if(s===null)continue;let c=vn(o,s);if(c===null)continue;Rt(o,c,t,r)}if(e.groups)Rn(e,n,t,r);Tn(e,n),Nn(e,n)}function Rt(e,t,r,n){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(r(o))o.disabled=!t;if(e.name&&r(e))e.disabled=!t}function Tn(e,t){let r=$t(e);for(let[n,o]of Object.entries(r)){if(n.startsWith("#")){En(n,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(n);if(i===null)continue;let a=(s,c)=>c?t(n,!0):i;for(let[s,c]of Object.entries(o)){if(!W(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)=>be(l,a))}else{let l=Vt(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 En(e,t,r){if(!W(e))return;let n=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Gn(n);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>r(a)===null))return;let i=R(n,r);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function $t(e,t="show",r="mode: { ... }, kind: { ... }"){let n=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!n)return{};try{let o=JSON.parse(n);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(${r})`),{}}function kn(e,t,r,n){let o=!1,i=null;for(let a of e.root.querySelectorAll(It(t,n))){if(!r(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 It(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function qt(e,t){let r=e.root.getAttribute?.("data-reactive-scope")||null,n=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!n.has(a))n.set(a,i?ue(e,o,t,r).filter((s)=>s.checked).length:kn(e,o,t,r));return n.get(a)}}var B="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Fn(e){return!!e.root.querySelector?.(B)}function ue(e,t,r,n){return[...e.root.querySelectorAll(It(t,n))].filter((o)=>o.type==="checkbox"&&r(o))}function Ln(e,t){let r=t?.getAttribute?.("data-reactive-select-all");if(r&&e.core.owns(t))Dt(e,r,t.checked,t)}function le(e,t,r){if(!t)return;let n=ne.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Dt(n,t,r!==!1),n.show?.()}function Dt(e,t,r,n){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=ue(e,t,e.core.ownership(),o).filter((a)=>a!==n&&a.checked!==r);for(let a of i)a.checked=r;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 Rn(e,t,r,n){for(let o of e.root.querySelectorAll(B)){if(!r(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Pt(Mt(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=ue(e,s,r,n).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 Nn(e,t){for(let[r,n]of Object.entries($t(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!n||typeof n!=="object"||Array.isArray(n))continue;let o=String(t(r,!0));for(let a of Array.isArray(n.count)?n.count:[]){if(!W(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=n.enable&&typeof n.enable==="object"?n.enable:{};for(let[a,s]of Object.entries(i)){if(!W(a,"group"))continue;let c=R(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 Nt(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?.(`${B}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let n=(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(n)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function j(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function On(e,t){let r=e.root.getAttribute("data-reactive-filter-input");return!!r&&typeof t.target?.matches==="function"&&t.target.matches(r)}function F(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),r=e.root.getAttribute("data-reactive-filter-option");if(!t||!r)return;let n=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(n);if(!o)return;let i=(o.value??"").trim().toLowerCase(),a=0;for(let u of e.root.querySelectorAll(r)){if(!n(u))continue;let l=(u.getAttribute("data-reactive-filter-text")??u.textContent??"").toLowerCase(),f=u.hasAttribute?.("data-reactive-tags-selected")||i!==""&&!l.includes(i);if(u.hidden=f,f)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(!n(u))continue;let l=[...u.querySelectorAll(r)].filter(n);if(l.length===0)continue;u.hidden=l.every((f)=>f.hidden)}let c=e.root.getAttribute("data-reactive-filter-empty");if(c){for(let u of e.root.querySelectorAll(c))if(n(u))u.hidden=a>0}}function J(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Cn(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function fe(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(t)].find(r)??null}function de(e){let t=new Set,r=[];for(let n of String(e.value??"").split(",")){let o=n.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),r.push(o)}return r}function Wt(e,t){let r=fe(e);if(!r)return!1;let n=de(r),o=new Set(n.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()),n.push(s),i=!0}if(i)jt(e,r,n);return i}function jt(e,t,r){t.value=r.join(","),L(t),Bt(e)}function Mn(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(t)].find(r)??null}function Bt(e){let t=fe(e);if(!t)return;let r=de(t),n=e.core.ownership();Pn(e,r,n),$n(e,r,n)}function Pn(e,t,r){let n=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(r);if(!n)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(r)?.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(n.firstChild)n.removeChild(n.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);n.appendChild(s)}}function $n(e,t,r){let n=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!r(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(n.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"),!j(e))o.hidden=!1}}if(j(e))F(e)}function In(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function qn(e,t){let r=[e,...e.querySelectorAll?.("*")??[]];for(let n of r)for(let o of["name","id","for"]){let i=n.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))n.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Dn(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 Wn(e,t,r,n){if(!r)return null;let o;try{o=JSON.parse(r)}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 f=a.find((d)=>Ut(d.getAttribute?.("name"))===c);if(!f)continue;jn(f,l),s.push(l)}if(n)for(let c of s)Bn(c);return s[0]??null}function jn(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:re(t)!=="";else e.value=re(t);L(e)}function Bn(e){if(e.type==="checkbox")e.checked=!1;else e.value="";L(e)}function Jn(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(r,n)=>Object.prototype.hasOwnProperty.call(t,n)?t[n]:r)}function Ot(e,t){let r=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(r)r.value="1",L(r),t.hidden=!0;else t.parentNode?.removeChild?.(t);pe(e)}function pe(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let r of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))zt(e,r.getAttribute("data-reactive-nested-json"))}function Un(e,t){let r=t.getAttribute?.("data-reactive-nested-json-field");if(!r)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(r)].find(n)??null}function Jt(e,t){let r={},n=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!n(o))continue;let i=Ut(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;r[i]=re(o)}return r}function Ut(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function re(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function zt(e,t){let r=e.core.ownership(),n=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(r);if(!n)return;let o=Un(e,n);if(!o)return;let i=[];for(let s of[...n.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!r(s)||s.hidden)continue;i.push(Jt(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,L(o)}function he(e,t,r){let n=w(e,t);if(!J(n))return;if(r?.defaultPrevented)return;if(n.core.listnavOptions(r).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;r?.preventDefault?.();let o=r?.currentTarget??r?.target;if(!o)return;if(!Wt(n,String(o.value??"").split(",")))return;if(o.value="",j(n))F(n)}function me(e,t,r){let n=w(e,t);if(!J(n))return;r?.preventDefault?.();let i=(r?.currentTarget??r?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Wt(n,[i]))return;let a=Mn(n);if(!a)return;a.value="",F(n),a.focus?.()}function ge(e,t,r){let n=w(e,t);if(!J(n))return;r?.preventDefault?.();let i=(r?.currentTarget??r?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=fe(n);if(!a)return;let s=de(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;jt(n,a,c)}function ye(e,t,r){let n=w(e,t);r?.preventDefault?.();let o=r?.currentTarget??r?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof n.root?.querySelectorAll!=="function")return;let a=n.core.ownership(),s=[...n.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...n.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Dn(n,i);return}let l=u.cloneNode(!0);qn(l,In(n)),s.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),d=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",h=Wn(n,l,f,d);if(f)h?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)zt(n,i)}function ve(e,t,r){let n=w(e,t);r?.preventDefault?.();let o=r?.currentTarget??r?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==n.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Zt(n,s):null);if(!c)return Ot(n,i);let u=Jt(n,i),l=Jn(c,u);return n.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Ot(n,i)})}function Ht(e,t){let r=t?.target;if(!r||!e.core.owns(r))return;pe(e)}var Gt=["gte","gt","lte","lt"],zn=["len_eq","len_gte","len_gt","len_lte","len_lt"],Hn=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function Kt(e,t,r){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 r===t;case"gte":return r>=t;case"gt":return r>t;case"lte":return r<=t;case"lt":return r<t;default:return null}}function Yt(e,t,r){let n=Number(t);if(Number.isNaN(n))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=r==null?"":String(r).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=n;case"gt":return i>n;case"lte":return i<=n;case"lt":return i<n;default:return null}}function Vt(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 r of Gt)if(r in e)return Yt(r,e[r],t);for(let r of zn)if(r in e)return Kt(r,e[r],[...String(t??"")].length);return null}function be(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let r=Hn.find((o)=>(o in e));if(r){let o=t(e.field,!0);return Kt(r,e[r],Array.isArray(o)?o.length:Number(o)||0)===!0}let n=t(e.field)??"";return Vt(e,n)===!0}function R(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((r)=>Array.isArray(r)&&r.length>0&&r.every((n)=>be(n,t)))}function Gn(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let r of e){if(!Array.isArray(r))continue;for(let n of r)if(n&&typeof n==="object"&&typeof n.field==="string")t.add(n.field)}return t.size>0?[...t]:null}function Zt(e,t){let r=t;if(typeof t==="string")try{r=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!r||typeof r!=="object")return null;let{fields:n}=e.core.collectFields(),o=(a)=>n[a],i;if(typeof r.predicate==="string"){let a=gn(r.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${r.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(n)}else i=R(r.groups?.any,o)===!0;return i?r.message:null}import{computeReducer as Kn}from"phlex/reactive/compute";var O=new WeakMap;function tr(e,t){let r=O.get(e);if(!r)O.set(e,r={root:e.element,core:t,ours:new WeakSet,opsSig:null});return r}function we(e,t,r,n){let o=tr(e,t),i=uo(o);if(i)o.seed=()=>Ae(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||n?.edited)Ae(o)}function Se(e){let t=O.get(e);if(!t)return;if(O.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function _e(e){O.get(e)?.seed?.()}function xe(e,t,r){return Ae(tr(e,t),r)}var Yn=Object.freeze({el:null,kind:""}),Vn=/^#[A-Za-z_][\w-]*$/;function N({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 rr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function Zn(e,t){if(t==="string")return N(e);let r=e.kind==="checkbox";if(t==="boolean")return r?Boolean(e.el.checked):rr(N(e));if(r)return e.el.checked?1:0;let n=Number(N(e));return Number.isFinite(n)?n:0}function Xn(e,t,{el:r,kind:n},o,i){if(n==="checkbox"){let a=rr(i);if(Boolean(r.checked)===a)return null;return r.checked=a,r}if(n==="radio")return Qn(e,t,o,String(i));if(String(i)===r.value)return null;return r.value=i,r}function Qn(e,t,r,n){let o=null;for(let i of e.querySelectorAll(`[name="${r}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===n;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function eo(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 to(e){if(typeof e==="string"&&Vn.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function ro(e,t,r){let n=t===null?null:JSON.stringify(t),o=n!==null&&n!==e.opsSig&&r;if(e.opsSig=n,!o)return;e.core.applyOps(t,"@root")}function no(e,t){let r=e.root.getAttribute(t);if(!r)return[];try{let n=JSON.parse(r);return Array.isArray(n)?n:[]}catch{return[]}}function oo(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let r=JSON.parse(t);if(Array.isArray(r))return r.map((n)=>[n,"number"]);if(r&&typeof r==="object")return Object.entries(r);return[]}catch{return[]}}function io(e,t,r,n){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=so(o.name,n);if(!r.includes(i))return null;return e.core.owns(o)?i:null}function so(e,t){if(!t)return e;let r=`${t}[`;return e.startsWith(r)&&e.endsWith("]")?e.slice(r.length,-1):e}function Qt(e,t,r){let n=String(r);for(let o of ao(e,t)){if(o.textContent===n)continue;o.textContent=n}}function ao(e,t){let r=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(r).filter((n)=>e.core.owns(n))}function er(e,t,r){let n=co(e);for(let[o,i]of Object.entries(n)){let a=o in t?null:r(o),s=o in t?t[o]:a.el?N(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!to(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function co(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let r=JSON.parse(t);return r&&typeof r==="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function uo(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function Ae(e,t){if(t&&e.ours.has(t))return;let r=oo(e),n=r.map(([p])=>p),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(p)=>o&&!p.includes("[")?`${o}[${p}]`:p,a=e.core.ownership(),s=new Map,c=(p)=>{let m=s.get(p);if(m)return m;let y=null,A=null,_=null;for(let x of e.root.querySelectorAll(`[name="${i(p)}"]`)){if(!a(x))continue;let D=x.type;if(D==="checkbox"||D==="radio"&&x.checked){_={el:x,kind:D};break}if(D==="radio")y??=x;else A??=x}if(!_)if(y)_={el:y,kind:"radio"};else _=A?{el:A,kind:""}:Yn;return s.set(p,_),_};for(let p of n)Qt(e,p,N(c(p)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?Kn(u):null;if(!l){er(e,{},c);return}let f=no(e,"data-reactive-compute-outputs-param"),d={};for(let[p,m]of r)d[p]=Zn(c(p),m);let h=l(d,{changed:io(e,t,n,o)})||{},g=eo(h.$ops),S=[];for(let p of f){if(p==="$ops"||!(p in h))continue;let m=c(p);if(!m.el)continue;let y=Xn(e.root,a,m,i(p),h[p]);if(y)S.push(y)}for(let p of Object.keys(h)){if(p==="$ops")continue;let m=h[p];if(m===void 0||m===null)continue;Qt(e,p,m)}er(e,h,c);for(let p of S){let m=new Event("input",{bubbles:!0});e.ours.add(m),p.dispatchEvent(m)}ro(e,g,Boolean(t))}var ar;function ke(e){ar=e}var cr=1,lo="phlex-reactive:persist:",fo=new Set(["hidden","file","password","submit","button","reset","image"]),Fe=Symbol("persist-no-value"),Le="data-reactive-persist-state",po=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",ho=new Set(["lexxy-editor","trix-editor"]),mo="lexxy-editor, trix-editor, trix-toolbar",go=["lexxy:change","trix-change"],yo=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),or=new WeakSet,ir=new WeakSet,sr=new WeakSet;function z(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let r=JSON.parse(t);if(r&&typeof r==="object"&&typeof r.key==="string"&&r.key!=="")return r}catch{}if(!or.has(e))or.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Re(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function Ne(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||ir.has(e))return;ir.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Oe(e){return lo+e.key}function Te(e,t){let r=Re();if(!r)return null;let n;try{n=r.getItem(Oe(t))}catch(c){return Ne(e,c),null}if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object"||o.v!==cr)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return U(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 ur(e,t,{fields:r,state:n}){let o=Re();if(!o)return!1;let i={v:cr,savedAt:Date.now(),fields:r};if(n)i.state=n;try{return o.setItem(Oe(t),JSON.stringify(i)),!0}catch(a){return Ne(e,a),!1}}function U(e,t){e?.removeAttribute?.(Le);let r=Re();if(!r)return;try{r.removeItem(Oe(t))}catch(n){Ne(e,n)}}function Ce(e,t){let r=Array.isArray(t.fields)?new Set(t.fields):null,n=[],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)||fo.has(i.type)||i.closest(mo))continue;if(r&&!r.has(i.name))continue;n.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(po)){if(!o(i))continue;let a=vo(i);if(!a||r&&!r.has(a))continue;n.push({el:i,name:a,kind:ho.has(i.localName)?"editor":"contenteditable"})}return n}function vo(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Me(e){return typeof e.value==="string"}function bo(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return yo.has(e.value.trim())}function Ao(e,t,r){if(e?.getAttribute?.("data-reactive-debug")!=="true"||sr.has(e))return;sr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${r?.message??r}`)}function C(e){return e.tagName==="SELECT"&&e.multiple}function lr(e){let t=new Map;for(let{el:r,name:n}of e){if(r.type==="radio"||!String(n).endsWith("[]"))continue;t.set(n,(t.get(n)??0)+1)}return t}function fr(e,t,r){if(!Array.isArray(e))return e;if(r.get(t)!==1||e.length!==1)return Fe;return e[0]}function dr(e,t){let r={},n=(o)=>{let i=r[o];return Array.isArray(i)?i:r[o]=[]};for(let{el:o,name:i,kind:a}of Ce(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Me(o))if(s)n(i).push(o.value);else r[i]=o.value}else if(a==="contenteditable"){let c=o.textContent??"";if(s)n(i).push(c);else r[i]=c}else if(o.type==="radio"){if(o.checked)r[i]=o.value;else if(!Object.hasOwn(r,i))r[i]=null}else if(o.type==="checkbox")if(s){let c=n(i);if(o.checked)c.push(o.value)}else r[i]=o.checked;else if(C(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)n(i).push(...c);else r[i]=c}else if(s)n(i).push(o.value);else r[i]=o.value}return r}function wo(e,t,r){let n=t.restore==="always",o=Ce(e,t),i=lr(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(r,c))continue;let l=r[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&C(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||C(s))){if(l=fr(l,c,i),l===Fe)continue}if((s.type==="checkbox"||C(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")pr(e,s,c,l,n);else if(u==="contenteditable"){if(!n&&(s.textContent??"").trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!n&&o.some((f)=>f.kind==="native"&&f.el.type==="radio"&&f.name===c&&f.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!n&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!n&&s.checked)continue;s.checked=Boolean(l)}else if(C(s)){if(!n&&[...s.options].some((d)=>d.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let d of s.options)d.selected=f.has(d.value)}else{if(!n&&s.value!=="")continue;s.value=String(l)}}So(e,t,r)}function pr(e,t,r,n,o){if(Array.isArray(n))return;if(!Me(t))return;if(!o&&!bo(t))return;try{t.value=String(n)}catch(i){Ao(e,r,i)}}function So(e,t,r){let n=globalThis.customElements;if(typeof n?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Me(a)&&!n.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)n.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=Ce(e,t),c=lr(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(r,l))continue;let d=fr(r[l],l,c);if(d===null||d===void 0||d===Fe)continue;pr(e,u,l,d,i)}})}function _o(e,t,r=!0){let n=z(e);if(!n){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=Te(e,n),i={...o?.state??{},...t},a=r?dr(e,n):o?.fields??{};if(ur(e,n,{fields:a,state:i}))e.setAttribute?.(Le,JSON.stringify(i))}function xo(e){let t=z(e);if(t)U(e,t)}var Ee=new WeakMap;function Pe(e,t,r,n){let o=e.element,i=z(o);if(!i)return;if(n?.submitted)U(o,i);let a=Te(o,i);if(a){if(wo(o,i,a.fields),a.state)o.setAttribute?.(Le,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 h=Te(o,i);ur(o,i,{fields:dr(o,i),state:h?.state??null})},l=()=>{let h=Number(i.debounce)||0;if(h<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},h)},f=(h)=>{if(!h?.detail?.success)return;let g=h.target;if(g?.tagName!=="FORM"||typeof g.contains!=="function")return;if(!g.contains(o))return;c(),U(o,i)},d=["input",...go];for(let h of d)o.addEventListener?.(h,l);if(o.addEventListener?.("change",u),document.addEventListener?.("turbo:submit-end",f),Ee.set(e,()=>{if(s!==null)u();for(let h of d)o.removeEventListener?.(h,l);o.removeEventListener?.("change",u),document.removeEventListener?.("turbo:submit-end",f)}),n?.edited&&!n.submitted)u();for(let h of n?.ops??[])h(!0)}function $e(e){let t=Ee.get(e);Ee.delete(e),t?.()}function hr(e,t){let r=ar?.waiting.get(e)?.persist;if(!r||!z(e))return t(!0);(r.ops??=[]).push(t)}function Ie(e,t){hr(e,(r)=>_o(e,t,r))}function qe(e){hr(e,()=>xo(e))}var De=new WeakMap,gr=new WeakSet;function We(e,t){let r=e.element,n=[];De.set(e,n);let o=(i,a,s)=>{i.addEventListener?.(a,s),n.push(()=>i.removeEventListener?.(a,s))};if(To(r,t)){let i=()=>M(e,t);if(o(r,"turbo:morph-element",i),i(),r.getAttribute?.("data-reactive-warn-unsaved")==="true")ko(r,o)}if(Fo(r,t)){let i=()=>Lo(r,t);o(r,"turbo:morph-element",i),i()}}function je(e){for(let t of De.get(e)??[])t();De.delete(e)}function To(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let r=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let n of r)if(t.owns(n))return!0;return!1}function M(e,t){let r=e.element;if(typeof r?.querySelectorAll!=="function")return;let n=0;if(r.querySelectorAll("input[name], select[name], textarea[name]").forEach((o)=>{if(!t.owns(o))return;if(o.type==="file")return;if(Eo(o))o.setAttribute("data-reactive-dirty","true"),n++;else o.removeAttribute("data-reactive-dirty")}),n>0)r.setAttribute("data-reactive-dirty",String(n));else r.removeAttribute("data-reactive-dirty")}function Eo(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??[]),r=!e.multiple&&!(e.size>1),n=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(r?o===n:o.defaultSelected))}return e.value!==e.defaultValue}function yr(e){let t=e.getAttribute?.("data-reactive-dirty"),r=Number(t);return Number.isFinite(r)&&r>0?r:0}function ko(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;t(window,"beforeunload",(r)=>{if(yr(e)===0)return;return r.preventDefault(),r.returnValue="You have unsaved changes.",r.returnValue}),t(window,"turbo:before-visit",(r)=>{if(yr(e)===0||gr.has(r))return;if(gr.add(r),!(typeof window.confirm==="function"?window.confirm("You have unsaved changes. Leave anyway?"):!0))r.preventDefault?.()})}function Fo(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let r=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let n of r)if(t.owns(n))return!0;return!1}function Lo(e,t){let r=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!r;for(let n of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(n))n.hidden=!r}function ze(e){Ro(e),Oo(e)}function Ro(e){let t=e.detail,r=t?.render;if(typeof r!=="function"||r.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Be);else setTimeout(Be,0);return}let n=async(o)=>{await r(o),Be()};n.__reactiveDismissWrapped=!0,t.render=n}function Be(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let r=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(r)||r<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),r)}}var No=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Je=Object.freeze(["fade","slide","scale","highlight","shake"]),Ue="data-reactive-fx-pending",He=1000;function Oo(e){let t=e.detail,r=t?.render;if(typeof r!=="function"||r.__reactiveEffectsWrapped)return;let n=t?.newStream??e.target,o=No[n?.getAttribute?.("action")];if(!o||Po())return;let i=Co(n,o);if(!i)return;let a=o==="exit"?async(s)=>{await qo(H(n),i),await r(s)}:async(s)=>{let c=o==="enter"?$o(n):null;if(await r(s),o==="enter")Io(c,i);else Ar(H(n),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Co(e,t){let r=e.getAttribute?.("data-reactive-effect");if(r==="off")return null;if(r)return br(r,t);let o=(t==="enter"?Mo(e):H(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?br(o,t):null}function H(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Mo(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function br(e,t){if(e.startsWith("[")){let n=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)n=o.map(String)}catch{}if(n)return{legs:n};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let r=e==="random"?Je[Math.floor(Math.random()*Je.length)]:e;if(!Je.includes(r))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${r}-${t}`}}function Po(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function $o(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let r of Array.from(t.children??[]))r.setAttribute?.(Ue,"");return H(e)}function Io(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let r of Array.from(e.querySelectorAll(`[${Ue}]`)))r.removeAttribute(Ue),Ar(r,t)}async function qo(e,t){if(!e?.classList)return;if(t.legs){await wr(e,t.legs);return}e.classList.add(t.className);let r=Ge(e);if(r<=0){e.classList.remove(t.className);return}await Ke(e,r),e.classList.remove(t.className)}function Ar(e,t){if(!e?.classList)return;if(t.legs){wr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let r=Ge(e);if(r<=0){e.classList.remove(t.className);return}let n=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ke(e,r).then(()=>{if(e.__reactiveFxToken===n)e.classList.remove(t.className)})}async function wr(e,t){let[r,n,o]=t.map(Do),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...r,...n,...o),e.classList.add(...r,...n),await Wo(),e.__reactiveFxToken!==i)return;e.classList.remove(...n),e.classList.add(...o);let a=Ge(e);if(a>0)await Ke(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...r,...o)}function Do(e){return String(e??"").split(/\s+/).filter(Boolean)}function Ge(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),r=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),n=r(t.animationDuration)+r(t.animationDelay),o=r(t.transitionDuration)+r(t.transitionDelay);return Math.min(Math.max(n,o)*1000,He)}catch{return 0}}function Ke(e,t){return new Promise((r)=>{let n=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",n),e.removeEventListener?.("transitionend",n),r()};e.addEventListener?.("animationend",n),e.addEventListener?.("transitionend",n),setTimeout(n,Math.min(t+50,He))})}function Wo(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(r),e()},He),r=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var jo="phlex-reactive:latency",Ye=!1;function xr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Tr(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Ye=!1}function Ze(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:xr,disableLatencySim:Tr}}function Xe(){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(!Ye)Ye=!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 _r=new WeakMap;function Qe(e){let t=globalThis.document;if(!t)return!0;let r=_r.get(t);if(!r)r=new Set,_r.set(t,r);if(r.has(e))return!0;return r.add(e),!1}function Ve(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function Er(e,t,r,n){if(Qe(`${e}|${t}|${r}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${r})${n}`)}function et(e,t,r){let n=t.to;if(typeof n!=="string"||n===""||n==="@root")return;let o="";if(r&&!t.global){let i=Ve(globalThis.document,n);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}Er(`client op "${e}"`,n,r?`scoped to #${r.id||"?"}`:"document-scoped",o)}function tt(e){if(!Qe(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function rt(e,t,r){let n=e.element,o=r.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!r.global)if(n?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Ve(n,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Ve(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}Er(t,o,`scoped to #${n?.id||"?"}`,i)}function nt(e,t){let r=e.element?.id||"?";if(Qe(`no-binding|${t.type}|${r}`))return;console.warn(`[phlex-reactive] runOps on #${r} found no on_client binding matching a "${t.type}" event — nothing ran`)}function Bo(e){if(!e)return[];let t=[],r=/<turbo-stream\b([^>]*)>/g,n;while((n=r.exec(e))!==null){let o=n[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function ot(e,t){let{action:r,status:n,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${r} → ${n??"—"} (${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 G(e,t,r){e.streams=Bo(t),e.tokenRefreshed=r!=null}var K=new WeakMap;function it(e,t,r,n){let o=r&&typeof r==="object"?zo(r):r;return o?Fr(t,o,n,!1):[]}function st(e,t,r,n){if(!r)return null;let o=Fr(t,r,n,!0);return o.length?o:null}function Fr(e,t,r,n){let o=[];for(let i of Lr(e,t,r)){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(r&&(t.disable||t.text!=null))o.push(Jo(t,r));if(n&&t.checked==="keep"&&r&&"checked"in r){let i=r.checked;o.push(()=>r.checked=!i)}return o}function Lr(e,t,r){if(t.to==null)return r?[r]:[];let n=e.opTargets({to:t.to});if(n.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return n}function Jo(e,t){let r=K.get(t);if(r)r.count++;else K.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()=>Uo(t,e)}function Uo(e,t){let r=K.get(e);if(!r)return;if(--r.count>0)return;if(K.delete(e),!e.isConnected)return;if(t.disable)e.disabled=r.disabled;if(r.hadText&&e.innerHTML===r.swappedTo)e.innerHTML=r.html}function zo(e){if(!e||typeof e!=="object")return null;let{class:t,...r}=e;return t==null?e:{...r,add_class:t}}function at(e,t,r,n){if(!r?.hide)return null;let o=Lr(t,r,n);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 Z;function lt(e){Z=e}var v=new Map;function Cr(e,t){let r=!v.has(e);if(v.set(e,t),r)Z.enter()}function X(e){if(v.delete(e))Z.exit()}var Nr=!1;function ft(e){Mr();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){Zo(t,e);return}let r=e.getAttribute("data-reactive-defer-token");if(!r)return;I(t,r)}function Mr(){if(Nr||typeof document>"u"||!document.addEventListener)return;Nr=!0,document.addEventListener("turbo:before-stream-render",Qo,!0),document.addEventListener("turbo:before-stream-render",Ho)}function Ho(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let r=t.slice(19);if(v.get(r)?.via==="stream")X(r)}function I(e,t){let r=document.getElementById(e);if(!r){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}pt(e),qr(r);let n={via:"fetch",abort:new AbortController,timedOut:!1};return Cr(e,n),Xo(e,n,t)}function Go(e,t){if(typeof e!=="string"){let r={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)r.cache="no-store";return[e.src,r]}return[ti(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":ri()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Pr(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if($r(t))return{src:t};return console.error(Ko(t)),Yo(t)||Vo(e)}function Ko(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${dt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function Yo(e){let t;try{t=new URL(e,window.location.href)}catch{return}let r=t.pathname.split("/").pop(),n=`${dt()}/${r}${t.search}`;if(/^[\w-]+$/.test(r)&&$r(n))return{src:n,fallback:!0}}function Vo(e){pt(e.id),ht(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 $r(e){try{let t=new URL(window.location.href),r=new URL(e,t);return r.origin===t.origin&&r.pathname.startsWith(`${dt()}/`)}catch{return!1}}function dt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function Zo(e,t){let r=document.getElementById(e);if(!r){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let n=t.getAttribute("data-reactive-defer-src");if(!n)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){I(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),qr(r);let o=document.createElement("pgbus-stream-source");o.id=Ir(e),o.setAttribute("src",n),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Cr(e,{via:"stream"})}function Ir(e){return`reactive-defer-src-${e}`}async function Xo(e,t,r){let n=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},ni()),o;try{Z.count("defer"),o=await fetch(...Go(r,t.abort.signal))}catch(s){if(clearTimeout(n),v.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),P(e,r);return}if(v.get(e)!==t){clearTimeout(n);return}if(o.redirected){clearTimeout(n),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),P(e,r,o.status);return}if(o.status===204){clearTimeout(n),Or(e);return}if(!o.ok){clearTimeout(n),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),P(e,r,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(n),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),P(e,r,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(n),v.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),P(e,r);return}if(clearTimeout(n),v.get(e)!==t)return;Or(e),ei(a)}var ut=null,Qo=(e)=>ut?.push(e);function ei(e){let t=ut=[];try{window.Turbo.renderStreamMessage(e)}finally{ut=null}for(let r of t){if(r.defaultPrevented)continue;let n=r.detail,o=n.render;n.render=()=>{},new Promise((i)=>i(o(n.newStream))).catch(console.error)}}function pt(e){let t=v.get(e);if(!t)return;if(X(e),t.via==="fetch")t.abort.abort();else document.getElementById(Ir(e))?.remove?.()}function qr(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function ht(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Or(e){X(e);let t=document.getElementById(e);if(!t)return;ht(t),t.removeAttribute("data-reactive-error")}function P(e,t,r){X(e);let n=document.getElementById(e);if(!n)return;ht(n),n.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"),I(e,t)};n.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:r,retry:o}}))}function ti(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function ri(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function ni(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Dr="__materialize",V=new WeakMap;function Y(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function mt(e,t,r){Mr();let n=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>Q(e),f=(m)=>{if(Y(n)==="visible"){if(!a)h()}else if(m){let y=n.getAttribute("data-reactive-lazy-on");if(s===y)return;d(),n.addEventListener?.(y,l),s=y}},d=()=>{if(a?.disconnect(),a=null,s)n.removeEventListener?.(s,l);s=null},h=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let m=n.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((y)=>{if(y.some((A)=>A.isIntersecting))l()},{rootMargin:m}),a.observe(n)},g=()=>{let m=Y(n)!==null,y=o;if(o=m,!m)return d();if(i)return;if(t.forgetToken(),!y)return l();f(!0)};if(V.set(e,{load(){if(i)return;let m=Pr(n);if(!m&&n.getAttribute("data-reactive-defer-src")!=null)return;if(m&&oi(n,t))return;let y=m?I(n.id,m):t.proceed(n,Dr,"{}");if(!y)return;i=!0,d();let A=()=>{i=!1};return y.then(A,A),y},off(){if(c)n.removeEventListener?.("turbo:morph-element",c);if(u)n.removeEventListener?.("turbo:morph-element",u);d()}}),(n.getAttribute?.("data-reactive-defer-token")||n.getAttribute?.("data-reactive-defer-src"))&&Y(n)===null)ct(n),c=(m)=>m.target===n&&ct(n),n.addEventListener?.("turbo:morph-element",c);if(n.getAttribute?.("data-reactive-token-value")==null&&n.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(m)=>{if(m.target!==n)return;if(!c)ct(n);g()},n.addEventListener?.("turbo:morph-element",u),r)return g();if(o=Y(n)!==null,o)f(!1)}function gt(e){let t=V.get(e);V.delete(e),t?.off()}function Q(e){return V.get(e)?.load()}function oi(e,t){return t.emit("reactive:before-dispatch",{action:Dr,params:{},element:e},{cancelable:!0}).defaultPrevented}function ct(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Pr(e);if(t)I(e.id,t)}function si(){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 ai(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),r=this.getAttribute("target");if(!t||!r)return;let n=document.getElementById(r);if(n)n.setAttribute("data-reactive-token-value",t)}}function ci(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=kt(this.getAttribute("data-reactive-ops"));if(!t.length)return;let r=this.getAttribute("target"),n=this.getAttribute("data-reactive-verbose")==="true",o=r?document.getElementById(r):null;if(r&&!o){if(n)tt(r);return}Tt(t,(i)=>Mi(i,o),n?(i,a)=>et(i,a,o):void 0)}}function ui(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){ft(this)}}var Br=!1,li=null;function fi(){if(Br)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Br=!0,document.addEventListener("turbo:before-stream-render",(e)=>{ze(e)})}function Qi(e){li=e}var Jr=!1;function Ur(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea")&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function di(){if(Jr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Jr=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented||t.localName!=="input"||!Ur(t))return;let n=r.getAttribute("value");if(n==null)t.removeAttribute("value");else if(t.getAttribute("value")!==n)t.setAttribute("value",n)}),document.addEventListener("turbo:before-morph-attribute",(e)=>{if(e.detail?.attributeName==="value"&&Ur(e.target))e.preventDefault()})}var pi="__materialize",zr=!1;function hi(){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 Et(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Ze()}var sn="data-reactive-active",b=0;function an(){if(b++,b===1)un("reactive:busy")}function cn(){if(b===0)return;if(b--,b===0)un("reactive:idle")}function es(){return b}function ts(){b=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(sn)}function un(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(sn,b>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:b}}))}var ln="data-reactive-requests";function fn(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!mi(t))return;let r=gi(t);r[e]=(Number(r[e])||0)+1,t.setAttribute(ln,JSON.stringify(r))}function mi(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function gi(e){try{let t=JSON.parse(e.getAttribute(ln));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Hr(){si(),ai(),ci(),ui(),fi(),di(),hi(),Et()}function yi(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var dn=Symbol.for("phlex-reactive.core");if(globalThis[dn])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[dn]=!0;var pn=!1;function vi(){if(pn)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(vi,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var bi=new Set(["href","src","srcdoc","action","formaction","xlink:href","style"]);function Ai(e){let t=String(e).toLowerCase();return t.startsWith("on")||bi.has(t)}var yt=new WeakMap;function wi(e,t,r){let[n,o,i]=t;yt.get(e)?.(),e.classList.add(n,o),r();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,yt.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(n,o,i)};yt.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Si(e))}function Si(e){let t=0;try{let r=getComputedStyle(e);for(let n of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(r[n+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(r[n+"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 _i=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",xi=new Set(["lexxy-editor","trix-editor"]);function Ti(e){return xi.has(e.localName)?typeof e.value==="string":!0}var Gr=Object.freeze({show:(e,t,r)=>vt(e,!1,t,r),hide:(e,t,r)=>vt(e,!0,t,r),toggle:(e,t,r)=>vt(e,!e.hidden,t,r),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((r)=>e.classList.toggle(r)),set_attr:(e,t)=>{if(bt(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(bt(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!bt(t.name))return;if(Array.isArray(t.values)){let[r,n]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===r?n:r)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>Ri(e)?.focus?.(),text:(e,t)=>{let r=String(t.value??"");if(e.textContent!==r)e.textContent=r},check_group:(e,t)=>{let r=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let n of r)le(n,t.group,t.checked)},dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,r)=>{let n=Ei(e);if(!n)return;let o=null;if(t?.submitter!=null&&typeof r==="function"){if(o=r({...t,to:t.submitter})[0]??null,!(o?.form===n&&(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?n.requestSubmit?.(o):n.requestSubmit?.()},paste_into:(e)=>ki(e),persist_state:(e,t)=>Ie(e,t.state),persist_clear:(e)=>qe(e)});function Ei(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function ki(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((r)=>{if(!r)return;if(e.value=r,typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}));e.focus?.()}).catch(()=>{})}function Fi(e,t,r){if(r?.transition)wi(e,r.transition,()=>e.hidden=t);else e.hidden=t}function vt(e,t,r,n){if(Fi(e,t,r),r?.expanded==null||typeof n!=="function")return;for(let o of n({...r,to:r.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function bt(e){if(!Ai(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}var Li='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ri(e){return e.querySelectorAll?.(Li)?.[0]??null}function kt(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"}),Yr=Object.freeze(["meta","ctrl","alt","shift"]);function Ft(e,t,r){let n=e.split("+");for(let a of Yr)if(n.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=n.find((a)=>!Yr.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=r&&Object.hasOwn(r,o)?r[o]:Object.hasOwn(Kr,o)?Kr[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}function Ni(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:kt(t),legacy:!0}];let r=[];for(let n of t.split(" ")){if(n==="")continue;let o=null;try{o=JSON.parse(n)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))r.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(n)} — skipped`)}return r}function Vr(e,t,r){if(e.legacy)return!0;let n=e.on;if(typeof n!=="string"||n==="")return!1;let o=n.indexOf(".");if(t.type!==(o<0?n:n.slice(0,o)))return!1;if(Boolean(e.window)!==hn(t.currentTarget))return!1;return o<0||r===null||Ft(n.slice(o+1),t,r)}var Zr=new WeakMap;function Oi(e,t,r){if(!r.once)return!1;let n=t.currentTarget??e.element,o=Zr.get(e);if(!o)o=new WeakMap,Zr.set(e,o);let i=o.get(n);if(!i)i=new Set,o.set(n,i);let a=t.params?.ops,c=(n===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(r);if(i.has(c))return!0;return i.add(c),!1}var Xr=new WeakMap;function Ci(e,t){if(e===null||typeof e!=="object")return!1;let r=e.params?.ops,n=typeof r==="string"?r:JSON.stringify(r??null),o=Xr.get(e);if(!o)o=new WeakMap,Xr.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(n))return!0;return a.add(n),!1}function Tt(e,t,r){for(let n of e){if(!Array.isArray(n))continue;let[o,i={}]=n;if(!Object.hasOwn(Gr,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&r)r(o,i);for(let s of a)Gr[o](s,i,t)}}function Mi(e,t){let r=e.to;if(t){if(r==="@root")return[t];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...t.querySelectorAll(r)]}if(typeof r!=="string"||r===""||r==="@root")return[];return[...document.querySelectorAll(r)]}function Pi(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Qr(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function $i(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 Ii(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]")!=null}function qi(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function rs(e,t,r){}function Di(e,t){}function ns(e){return[]}function os(e){return Promise.resolve()}var en=new Set;function Wi(e,t,r){let n=e+t;if(en.has(n))return;en.add(n),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,r)}function is(){return["persist","defer","form","bindings","compute","effects","hints","devtools"]}var tn=Promise.resolve();var rn={enter:an,exit:cn,count:fn,waiting:new WeakMap},nn=1,At=2,wt=4,St=8,_t=16;ke(rn),lt(rn);var q=Symbol.for("phlex-reactive.early"),ji=1e4,Bi=1500,hn=(e)=>e!=null&&(e===globalThis.window||e.window===e);function xt(){return globalThis[q]??={queue:[],connected:new WeakSet},globalThis[q]}function Ji(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:ji}function Ui(e){let t={};for(let{name:r,value:n}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(r);if(!o)continue;let i;try{i=JSON.parse(n)}catch{i=n}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function zi(e,t,r){return{[q]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:r?t.ownerDocument.defaultView:t,params:Ui(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 te=new WeakMap;function Hi(e,{token:t,type:r,method:n,filter:o,win:i},a){let s=te.get(e);if(!s)te.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:r,method:n,filter:o,win:i,params:a,armed:!0}),!0}function on(e,t,r,n){if(e?.[q])return!1;let o=hn(e?.currentTarget),i=o?n:e?.currentTarget,a=Ki(e,i,o?`@${t}`:t),s=te.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&&!Ft(u.filter,e,r))continue;return u.armed=!1,!0}return a}var ee=new WeakMap;function Gi(e,t,r){let n=ee.get(e);if(!n)ee.set(e,n=new Map),setTimeout(()=>ee.delete(e));let o=n.get(t)??{};n.set(t,o),o[r]=(o[r]??0)+1}function Ki(e,t,r){let n=e&&ee.get(e)?.get(t);if(!n?.[r])return!1;return n[r]-=1,!0}class mn extends ii{static values={token:String};#p;#h=new Map;#c=new Map;#z;#w;#M;#S=0;#u=new Map;#_=new WeakMap;#m;featuresReady=tn;#Te=new Map;#Ee=new Set;#H=!1;#P=null;#ke=new Map;#Fe=new Map;#Le=new Map;#G=0;#$;#x=0;#t=0;connect(){if(pn=!0,xt().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||Qr(this.element))this.#m=(e)=>{if(e.target!==this.element)return;this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#m);this.#G++,this.featuresReady=tn,this.#I(),this.#V()}#I(e){this.#l(nn,"persist",Pi,(t)=>Pe(this,t,e)),this.#l(At,"defer",Qr,(t)=>mt(this,t,e)),this.#l(wt,"form",$i,(t)=>We(this,t,e)),this.#l(St,"bindings",Ii,(t)=>oe(this,t,e)),this.#l(_t,"compute",qi,(t)=>we(this,t,e))}#l(e,t,r,n){if(this.#x&e)return;try{if(!r(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#x|=e;try{n(this.#e()),this.#t|=e}catch(o){this.#q(t,"connect",o)}}#K(){{let e=this.#t;this.#x=this.#t=0;let t=this.#e();if(e&nn)this.#f("persist",()=>$e(this,t));if(e&At)this.#f("defer",()=>gt(this,t));if(e&wt)this.#f("form",()=>je(this,t));if(e&St)this.#f("bindings",()=>ie(this,t));if(e&_t)this.#f("compute",()=>Se(this,t))}}#f(e,t){try{t()}catch(r){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,r)}}#Re(e){}#Ne(e,t){}#Oe(e){}#Ce(e,t){}#Me(e,t,r,n){}#e(){return this.#$??={emit:(e,t,r)=>this.#n(e,t,r),reseed:()=>this.#Y(),proceed:(e,t,r)=>this.#E(e,t,r),forgetToken:()=>{this.#p=void 0},owns:(e)=>this.#b(e),ownership:()=>this.#L(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#O(e,t),applyOps:(e,t)=>Tt(e,(r)=>this.#C(t!=null&&r.to==null?{...r,to:t}:r),(r,n)=>this.#O(`client op "${r}"`,n)),listnavOptions:(e)=>this.#d(e),collectFields:()=>this.#B(),confirm:(e,t)=>Promise.resolve().then(()=>jr(e,t)).catch(()=>!1)},this.#$}#Y(){if(this.#t&wt)M(this,this.#e());if(this.#t&St)se(this);if(this.#t&_t)_e(this)}#q(e,t,r){if(Wi(e,t,r),this.#r("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#n("reactive:error",{kind:"feature",feature:e,phase:t,error:r})}#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.#Z()}#T=new Set;#Z(){let{queue:e}=xt();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 r=Ji(),n=new Map;for(let o of t){let i=n.get(o.event)??[new Set,new Set];n.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(Bi,r):r,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.#N())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#X(o)}}#X({event:e,el:t,descs:r,win:n}){let o=zi(e,t,n),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=n?this.element:t;for(let c of r){if(!a.includes(c.token))continue;if(c.filter&&!Ft(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Hi(s,c,n&&JSON.stringify(o.params)))continue;this.#T.add(s)}if(Gi(e,s,n?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#K(),this.#ne(),this.#ie(),this.#m)this.element.removeEventListener?.("turbo:morph-element",this.#m);xt().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#T)te.delete(e);this.#T.clear()}dispatch(e){if(on(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:t,params:r,debounce:n,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 f=e.currentTarget??e.target;if(!c&&!this.#ye(u,f))e.preventDefault();if(t===pi){let g=()=>{if(this.#t&At)return Q(this);if(this.tokenValue)return this.#E(f,t,"{}")};return this.#H?this.featuresReady.then(g):g()}let d=this.#D(i,a),h=()=>this.#E(f,t,r,n,o,u,l);if(!d)return h();if(d instanceof Promise)return d.then((g)=>g?this.#g(g,f,h):h());this.#g(d,f,h)}#g(e,t,r){return Promise.resolve().then(()=>jr(e,{el:t})).catch(()=>!1).then((n)=>{if(n)r()})}#D(e,t){if(e)return e;if(!t)return null;return ce(this,this.#e(),t)}#Q(e){}runOps(e){if(on(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Ci(e,this))return;let t=e.params??{},r=e.currentTarget??e.target,n=Ni(t.ops),o=n.filter((a)=>Vr(a,e,null)),i=o.length<=1?o:o.filter((a)=>Vr(a,e,this.application?.schema?.keyMappings));if(i.length===0&&n.length>0){if(this.#N())nt(this,e);return}for(let a of i){if(a.outside&&e[q])continue;if(Oi(this,e,a))continue;this.#ee(a.legacy?{...t,ops:a.ops}:a,e,r)}}#ee({ops:e,confirm:t,confirmWhen:r,outside:n,window:o},i,a){if(n&&this.element.contains(i.target))return;if(!o)i.preventDefault();let s=this.#D(t,r),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 xe(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#d(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return he(this,this.#e(),e)}tagsPick(e){return me(this,this.#e(),e)}tagsRemove(e){return ge(this,this.#e(),e)}nestedAdd(e){return ye(this,this.#e(),e)}nestedRemove(e){return ve(this,this.#e(),e)}syncNestedJson(e){return ae(this,this.#e(),e)}#$e(e,t){}trackDirty(){M(this,this.#e())}listnavNext(e){this.#y(e,(t,r)=>t<0?0:(t+1)%r)}listnavPrev(e){this.#y(e,(t,r)=>t<0?r-1:(t-1+r)%r)}listnavFirst(e){this.#y(e,()=>0)}listnavLast(e){this.#y(e,(t,r)=>r-1)}listnavPick(e){let t=this.#d(e),r=t.findIndex((n)=>n.hasAttribute("data-reactive-highlighted"));if(r<0)return;e.preventDefault(),t[r].click()}listnavClose(e){for(let t of this.#d(e))t.removeAttribute("data-reactive-highlighted")}#y(e,t){let r=this.#d(e);if(!r.length)return;e.preventDefault();let n=this.#te(e),o=globalThis.document?.activeElement,i=n?r.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):r.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=r[t(i,r.length)];if(n)a.focus?.();else{for(let s of r)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"}#d(e){let r=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!r)return[];let n=this.#L();return Array.from(this.element.querySelectorAll(r)).filter((o)=>!o.hidden&&n(o))}#E(e,t,r,n,o,i,a){if(this.#n("reactive:before-dispatch",{action:t,params:this.#J(r),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(n)||0;if(c>0)return this.#re(e,c,t,r,i,a);let u=Number(o)||0;if(u>0)return this.#oe(e,u,t,r,i,a);return this.#v(t,r,i,e,a)}#v(e,t,r,n,o){let i={inverse:null,undo:[],resurrect:null},a=this.#ve(e,n,i),s=Boolean(r||o),c=(d)=>{if(!s||!d)return;let h=this.#e();if(i.inverse=st(this,h,r,n),i.undo.push(...it(this,h,o,n)),this.#F())i.resurrect=at(this,h,r,n)},u=!0;c(!0);let l=()=>this.#ue(e,t,i,a),f=()=>this.#P?this.#P.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Ie(){return this.#Q("hints")}#re(e,t,r,n,o,i){this.#k(e);let a=()=>{this.#k(e),this.#v(r,n,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)}#ne(){for(let e of[...this.#h.keys()])this.#k(e)}#oe(e,t,r,n,o,i){let a=this.#c.get(e)??new Map;if(a.has(r))return;let s=setTimeout(()=>{if(a.delete(r),a.size===0)this.#c.delete(e)},t);return a.set(r,s),this.#c.set(e,a),this.#v(r,n,o,e,i)}#ie(){for(let e of this.#c.values())for(let t of e.values())clearTimeout(t);this.#c.clear()}#n(e,t,{cancelable:r=!1}={}){let n=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:r,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(n),n}#o(e,t,r,n){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#v(e,t)};this.#n("reactive:error",{action:e,params:r,...n,retry:o})}#r(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",r=document.getElementById(t);if(!r)return;r.appendChild(e.content.cloneNode(!0))}#ce(){return Xe()}#F(){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,r,n){let{fields:o,files:i}=this.#B(),a=this.#J(t),s={...o,...a},c=this.#i,u=i.length>0,l=u?this.#pe(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#F()?{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.#s(r.inverse),this.#r("offline"),this.#o(e,t,s,{kind:"offline"});return}let d;try{let p={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#_e()};if(!u)p["Content-Type"]="application/json";let m=this.#xe();if(m)p["X-Pgbus-Connection"]=m;fn("action"),d=await fetch(this.#we(),{method:"POST",headers:p,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Se())})}catch(p){if(console.error("[phlex-reactive] action error",p),this.#s(r.inverse),p?.name==="TimeoutError"||p?.name==="AbortError"){this.#r("timeout"),this.#o(e,t,s,{kind:"timeout"});return}this.#ae(),this.#r("network"),this.#o(e,t,s,{kind:"network"});return}if(f)f.status=d.status;if(d.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#s(r.inverse),this.#r("redirected"),this.#o(e,t,s,{kind:"redirected",status:d.status});return}if(!d.ok){let p=await d.text();if(console.error(`[phlex-reactive] action failed: HTTP ${d.status}`,p),this.#s(r.inverse),(d.headers.get("Content-Type")||"").includes("turbo-stream")){let m=this.#j(p);if(this.#i=m??this.#i,f)G(f,p,m);window.Turbo.renderStreamMessage(p)}this.#r("http"),this.#o(e,t,s,{kind:"http",status:d.status,body:p});return}let h=d.headers.get("Content-Type")||"";if(!h.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${h}" — no update applied`),this.#s(r.inverse),this.#r("content-type"),this.#o(e,t,s,{kind:"content-type",status:d.status});return}let g=await d.text(),S=this.#j(g);if(this.#i=S??this.#i,f)G(f,g,S);if(window.Turbo.renderStreamMessage(g),r.resurrect)queueMicrotask(r.resurrect);this.#se(),this.#n("reactive:applied",{action:e,params:s,html:g})}catch(d){console.error("[phlex-reactive] action error",d),this.#s(r.inverse),this.#n("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(n?.(),f)ot(this,{...f,ms:this.#W()-f.started})}}get#i(){return this.#p??this.tokenValue}set#i(e){this.#p=e}tokenValueChanged(){this.#p=void 0}#j(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:r,self:n}=this.#le(t),o=e.match(r);if(o)return o[1];let i=e.match(n);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 r=yi(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${r}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${r}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#b(e){return e.closest('[data-controller~="reactive"]')===this.element}#L(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#b(t)}#B(){let e={},t=[],r=this.#L(),n=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!r(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else n.push(s)});let o=[];this.element.querySelectorAll(`[name]${_i}`).forEach((s)=>{if(r(s))o.push(s)});let i=this.#fe(n),a=this.#de(n);for(let s of n)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.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Ti(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 r of e){if(r.type==="radio")continue;if(String(r.name).endsWith("[]"))t.add(r.name)}return t}#de(e){let t=new Set;for(let r of e)if(r.type==="checkbox")t.add(r.name);return t}#pe(e,t,r,n){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(r))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(n);for(let{name:s,file:c,multiple:u}of n){let f=u||a.has(s)?`${this.#A(s)}[]`:this.#A(s);o.append(f,c,c.name)}return o}#A(e){let t=String(e),r=t.indexOf("[");if(r===-1)return`params[${t}]`;return`params${[t.slice(0,r),...t.slice(r).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#R(e,t,r){if(r==null)e.append(t,"");else if(Array.isArray(r))r.forEach((n,o)=>this.#R(e,`${t}[${o}]`,n));else if(typeof r==="object")for(let[n,o]of Object.entries(r))this.#R(e,`${t}[${n}]`,o);else e.append(t,String(r))}#he(e){let t=new Map;for(let{name:r}of e)t.set(r,(t.get(r)??0)+1);return new Set([...t].filter(([,r])=>r>1).map(([r])=>r))}#J(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#me(e){return kt(e)}#ge(e){Tt(e,(t)=>this.#C(t),(t,r)=>this.#O(`client op "${t}"`,r))}#N(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#F()}#O(e,t){if(!this.#N())return;rt(this,e,t)}#qe(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((r)=>this.#b(r))}#ye(e,t){if(e?.checked!=="keep")return!1;let r=t?.type;return r==="checkbox"||r==="radio"}#s(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#ve(e,t,r){this.#be(e,t),an();let n=!1;return()=>{if(n)return;n=!0,this.#Ae(e,t),cn();for(let o of r.undo)o()}}#be(e,t){if(this.#a(t,e,1),this.#a(this.element,e,1),this.#u.set(e,(this.#u.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let r of this.#U(e))this.#a(r,e,1)}#Ae(e,t){this.#a(t,e,-1),this.#a(this.element,e,-1);let r=(this.#u.get(e)??1)-1;if(r<=0)this.#u.delete(e);else this.#u.set(e,r);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let n of this.#U(e))this.#a(n,e,-1)}#a(e,t,r){if(!e||typeof e.getAttribute!=="function")return;let n=this.#_.get(e)??new Map,o=(n.get(t)??0)+r;if(o<=0)n.delete(t);else n.set(t,o);if(n.size===0){this.#_.delete(e),e.removeAttribute("data-reactive-busy");return}this.#_.set(e,n),e.setAttribute("data-reactive-busy",[...n.keys()].join(" "))}#U(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((r)=>r.getAttribute("data-reactive-busy-on")===e&&this.#b(r))}#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}#_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)Hr();else document.addEventListener("turbo:load",Hr,{once:!0});Et();var hs=mn;export{sn as ACTIVE_ATTR,_i as EDITOR_SELECTOR,xi as EDITOR_TAGS,jo as LATENCY_KEY,ln as REQUESTS_ATTR,vi as checkReactiveRegistration,fn as countReactiveRequest,hs as default,Tr as disableLatencySim,xr as enableLatencySim,an as enterReactiveActivity,yi as escapeRegExp,cn as exitReactiveActivity,os as loadReactiveFeature,Qi as onReactiveStreamWithoutEffects,es as reactiveActivityCount,is as reactiveFeatureNames,Hr as registerReactiveActions,ui as registerReactiveDefer,Et as registerReactiveDev,fi as registerReactiveDismiss,fi as registerReactiveEffects,Di as registerReactiveFeature,rs as registerReactiveFeatureLoader,ci as registerReactiveJs,di as registerReactiveMorphFocus,hi as registerReactiveOffline,fi as registerReactiveStreamRender,ai as registerReactiveToken,si as registerReactiveVisit,ts as resetReactiveActivity,ns as unloadedFeaturesFor};
1
+ import{Controller as si}from"@hotwired/stimulus";import{confirmResolver as Br}from"phlex/reactive/confirm";import{confirmPredicate as yn}from"phlex/reactive/confirm_predicate";var E=new WeakMap,ne=new WeakMap;function w(e,t){let r=E.get(e);if(!r){if(E.set(e,r={root:e.element,core:t,nestedIndex:0}),r.root)ne.set(r.root,r)}return r}function T(e,t,r){for(let n of t.split(" "))e.root.addEventListener?.(n,r),e.offs.push(()=>e.root.removeEventListener?.(n,r))}function k(e,t){T(e,"turbo:morph-element",t),e.seeds.push(t),t()}function oe(e,t){let r=w(e,t);if(r.offs=[],r.seeds=[],Sn(r))r.show=(n)=>{if(r.flipping)return;if(n?.type==="input"||n?.type==="change")Rn(r,n.target);else r.groups=Ln(r),Nt(r);Tn(r)},T(r,"input change",r.show),k(r,r.show);if(_n(r))T(r,"input change",(n)=>Lt(r,n)),k(r,r.arm=()=>{Lt(r,null),Nt(r)});if(r.show||r.arm)T(r,"reset",()=>setTimeout(()=>{if(E.get(e)!==r)return;r.show?.(),r.arm?.()},0));if(j(r))T(r,"input",(n)=>Cn(r,n)&&F(r)),k(r,()=>F(r));if(J(r))k(r,()=>Bt(r));if(Mn(r))T(r,"input change",(n)=>Ht(r,n)),k(r,()=>pe(r))}function ie(e){let t=E.get(e);if(!t)return;E.delete(e),ne.delete(t.root);for(let r of t.offs??[])r();t.groupObserver?.disconnect()}function se(e){for(let t of E.get(e)?.seeds??[])t()}function L(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ae(e,t,r){return Ht(w(e,t),r)}function ce(e,t,r){return Xt(w(e,t),r)}var vn=/^#[A-Za-z_][\w-]*$/,Ct="[data-reactive-show-field], [data-reactive-show]";function bn(e,t){let r=e.getAttribute("data-reactive-show-equals");if(r!==null)return t===r;let n=e.getAttribute("data-reactive-show-not");if(n!==null)return t!==n;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 Gt){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Vt(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Mt(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 An(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((r)=>r&&typeof r==="object"&&Array.isArray(r.any)&&Array.isArray(r.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function Pt(e,t){if(!e||typeof e!=="object")return null;let r=e.any;if(Array.isArray(r)&&(r.length===0||Array.isArray(r[0])))return R(r,t);return wn(e,t)}function wn(e,t){let r=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!r)return null;let n=e[r];if(n.length===0)return null;let o=n.map((i)=>be(i,t));return r==="all"?o.every(Boolean):o.some(Boolean)}function W(e,t="show"){if(typeof e==="string"&&vn.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Sn(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?.(Ct)??[];for(let r of t)if(e.core.owns(r))return!0;for(let r of e.root.querySelectorAll?.(B)??[])if(e.core.owns(r))return!0;return!1}function _n(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function xn(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:An(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Lt(e,t){let r=xn(e);if(!r.length)return;let n=qt(e,e.core.ownership());r.forEach((o,i)=>{let a=R(o.any,n);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 Tn(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),r=e.root.getAttribute?.("data-reactive-scope")||null,n=qt(e,t);for(let o of e.root.querySelectorAll(Ct)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=Pt(Mt(i),n);if(u!==null)Rt(o,u,t,r);continue}let a=o.getAttribute("data-reactive-show-field");if(!a)continue;let s=n(a);if(s===null)continue;let c=bn(o,s);if(c===null)continue;Rt(o,c,t,r)}if(e.groups)Nn(e,n,t,r);En(e,n),On(e,n)}function Rt(e,t,r,n){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(r(o))o.disabled=!t;if(e.name&&r(e))e.disabled=!t}function En(e,t){let r=$t(e);for(let[n,o]of Object.entries(r)){if(n.startsWith("#")){kn(n,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(n);if(i===null)continue;let a=(s,c)=>c?t(n,!0):i;for(let[s,c]of Object.entries(o)){if(!W(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)=>be(l,a))}else{let l=Zt(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 kn(e,t,r){if(!W(e))return;let n=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Gn(n);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>r(a)===null)&&!Kn(n))return;let i=R(n,r);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function $t(e,t="show",r="mode: { ... }, kind: { ... }"){let n=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!n)return{};try{let o=JSON.parse(n);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(${r})`),{}}function Fn(e,t,r,n){let o=!1,i=null;for(let a of e.root.querySelectorAll(It(t,n))){if(!r(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 It(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function qt(e,t){let r=e.root.getAttribute?.("data-reactive-scope")||null,n=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!n.has(a))n.set(a,i?ue(e,o,t,r).filter((s)=>s.checked).length:Fn(e,o,t,r));return n.get(a)}}var B="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Ln(e){return!!e.root.querySelector?.(B)}function ue(e,t,r,n){return[...e.root.querySelectorAll(It(t,n))].filter((o)=>o.type==="checkbox"&&r(o))}function Rn(e,t){let r=t?.getAttribute?.("data-reactive-select-all");if(r&&e.core.owns(t))Dt(e,r,t.checked,t)}function le(e,t,r){if(!t)return;let n=ne.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Dt(n,t,r!==!1),n.show?.()}function Dt(e,t,r,n){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=ue(e,t,e.core.ownership(),o).filter((a)=>a!==n&&a.checked!==r);for(let a of i)a.checked=r;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 Nn(e,t,r,n){for(let o of e.root.querySelectorAll(B)){if(!r(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Pt(Mt(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=ue(e,s,r,n).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 On(e,t){for(let[r,n]of Object.entries($t(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!n||typeof n!=="object"||Array.isArray(n))continue;let o=String(t(r,!0));for(let a of Array.isArray(n.count)?n.count:[]){if(!W(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=n.enable&&typeof n.enable==="object"?n.enable:{};for(let[a,s]of Object.entries(i)){if(!W(a,"group"))continue;let c=R(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 Nt(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?.(`${B}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let n=(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(n)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function j(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Cn(e,t){let r=e.root.getAttribute("data-reactive-filter-input");return!!r&&typeof t.target?.matches==="function"&&t.target.matches(r)}function F(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),r=e.root.getAttribute("data-reactive-filter-option");if(!t||!r)return;let n=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(n);if(!o)return;let i=(o.value??"").trim().toLowerCase(),a=0;for(let u of e.root.querySelectorAll(r)){if(!n(u))continue;let l=(u.getAttribute("data-reactive-filter-text")??u.textContent??"").toLowerCase(),f=u.hasAttribute?.("data-reactive-tags-selected")||i!==""&&!l.includes(i);if(u.hidden=f,f)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(!n(u))continue;let l=[...u.querySelectorAll(r)].filter(n);if(l.length===0)continue;u.hidden=l.every((f)=>f.hidden)}let c=e.root.getAttribute("data-reactive-filter-empty");if(c){for(let u of e.root.querySelectorAll(c))if(n(u))u.hidden=a>0}}function J(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Mn(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function fe(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(t)].find(r)??null}function de(e){let t=new Set,r=[];for(let n of String(e.value??"").split(",")){let o=n.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),r.push(o)}return r}function Wt(e,t){let r=fe(e);if(!r)return!1;let n=de(r),o=new Set(n.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()),n.push(s),i=!0}if(i)jt(e,r,n);return i}function jt(e,t,r){t.value=r.join(","),L(t),Bt(e)}function Pn(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(t)].find(r)??null}function Bt(e){let t=fe(e);if(!t)return;let r=de(t),n=e.core.ownership();$n(e,r,n),In(e,r,n)}function $n(e,t,r){let n=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(r);if(!n)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(r)?.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(n.firstChild)n.removeChild(n.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);n.appendChild(s)}}function In(e,t,r){let n=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!r(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(n.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"),!j(e))o.hidden=!1}}if(j(e))F(e)}function qn(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Dn(e,t){let r=[e,...e.querySelectorAll?.("*")??[]];for(let n of r)for(let o of["name","id","for"]){let i=n.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))n.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Wn(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 jn(e,t,r,n){if(!r)return null;let o;try{o=JSON.parse(r)}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 f=a.find((d)=>Ut(d.getAttribute?.("name"))===c);if(!f)continue;Bn(f,l),s.push(l)}if(n)for(let c of s)Jn(c);return s[0]??null}function Bn(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:re(t)!=="";else e.value=re(t);L(e)}function Jn(e){if(e.type==="checkbox")e.checked=!1;else e.value="";L(e)}function Un(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(r,n)=>Object.prototype.hasOwnProperty.call(t,n)?t[n]:r)}function Ot(e,t){let r=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(r)r.value="1",L(r),t.hidden=!0;else t.parentNode?.removeChild?.(t);pe(e)}function pe(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let r of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))zt(e,r.getAttribute("data-reactive-nested-json"))}function zn(e,t){let r=t.getAttribute?.("data-reactive-nested-json-field");if(!r)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(r)].find(n)??null}function Jt(e,t){let r={},n=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!n(o))continue;let i=Ut(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;r[i]=re(o)}return r}function Ut(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function re(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function zt(e,t){let r=e.core.ownership(),n=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(r);if(!n)return;let o=zn(e,n);if(!o)return;let i=[];for(let s of[...n.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!r(s)||s.hidden)continue;i.push(Jt(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,L(o)}function he(e,t,r){let n=w(e,t);if(!J(n))return;if(r?.defaultPrevented)return;if(n.core.listnavOptions(r).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;r?.preventDefault?.();let o=r?.currentTarget??r?.target;if(!o)return;if(!Wt(n,String(o.value??"").split(",")))return;if(o.value="",j(n))F(n)}function me(e,t,r){let n=w(e,t);if(!J(n))return;r?.preventDefault?.();let i=(r?.currentTarget??r?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Wt(n,[i]))return;let a=Pn(n);if(!a)return;a.value="",F(n),a.focus?.()}function ge(e,t,r){let n=w(e,t);if(!J(n))return;r?.preventDefault?.();let i=(r?.currentTarget??r?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=fe(n);if(!a)return;let s=de(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;jt(n,a,c)}function ye(e,t,r){let n=w(e,t);r?.preventDefault?.();let o=r?.currentTarget??r?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof n.root?.querySelectorAll!=="function")return;let a=n.core.ownership(),s=[...n.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...n.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Wn(n,i);return}let l=u.cloneNode(!0);Dn(l,qn(n)),s.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),d=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",h=jn(n,l,f,d);if(f)h?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)zt(n,i)}function ve(e,t,r){let n=w(e,t);r?.preventDefault?.();let o=r?.currentTarget??r?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==n.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Xt(n,s):null);if(!c)return Ot(n,i);let u=Jt(n,i),l=Un(c,u);return n.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Ot(n,i)})}function Ht(e,t){let r=t?.target;if(!r||!e.core.owns(r))return;pe(e)}var Gt=["gte","gt","lte","lt"],Hn=["len_eq","len_gte","len_gt","len_lte","len_lt"],Kt=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function Yt(e,t,r){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 r===t;case"gte":return r>=t;case"gt":return r>t;case"lte":return r<=t;case"lt":return r<t;default:return null}}function Vt(e,t,r){let n=Number(t);if(Number.isNaN(n))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=r==null?"":String(r).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=n;case"gt":return i>n;case"lte":return i<=n;case"lt":return i<n;default:return null}}function Zt(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 r of Gt)if(r in e)return Vt(r,e[r],t);for(let r of Hn)if(r in e)return Yt(r,e[r],[...String(t??"")].length);return null}function be(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let r=Kt.find((o)=>(o in e));if(r){let o=t(e.field,!0);return Yt(r,e[r],Array.isArray(o)?o.length:Number(o)||0)===!0}let n=t(e.field)??"";return Zt(e,n)===!0}function R(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((r)=>Array.isArray(r)&&r.length>0&&r.every((n)=>be(n,t)))}function Gn(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let r of e){if(!Array.isArray(r))continue;for(let n of r)if(n&&typeof n==="object"&&typeof n.field==="string")t.add(n.field)}return t.size>0?[...t]:null}function Kn(e){return e.flat().every((t)=>Kt.some((r)=>(r in Object(t))))}function Xt(e,t){let r=t;if(typeof t==="string")try{r=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!r||typeof r!=="object")return null;let{fields:n}=e.core.collectFields(),o=(a)=>n[a],i;if(typeof r.predicate==="string"){let a=yn(r.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${r.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(n)}else i=R(r.groups?.any,o)===!0;return i?r.message:null}import{computeReducer as Yn}from"phlex/reactive/compute";var O=new WeakMap;function rr(e,t){let r=O.get(e);if(!r)O.set(e,r={root:e.element,core:t,ours:new WeakSet,opsSig:null});return r}function we(e,t,r,n){let o=rr(e,t),i=lo(o);if(i)o.seed=()=>Ae(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||n?.edited)Ae(o)}function Se(e){let t=O.get(e);if(!t)return;if(O.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function _e(e){O.get(e)?.seed?.()}function xe(e,t,r){return Ae(rr(e,t),r)}var Vn=Object.freeze({el:null,kind:""}),Zn=/^#[A-Za-z_][\w-]*$/;function N({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 nr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function Xn(e,t){if(t==="string")return N(e);let r=e.kind==="checkbox";if(t==="boolean")return r?Boolean(e.el.checked):nr(N(e));if(r)return e.el.checked?1:0;let n=Number(N(e));return Number.isFinite(n)?n:0}function Qn(e,t,{el:r,kind:n},o,i){if(n==="checkbox"){let a=nr(i);if(Boolean(r.checked)===a)return null;return r.checked=a,r}if(n==="radio")return eo(e,t,o,String(i));if(String(i)===r.value)return null;return r.value=i,r}function eo(e,t,r,n){let o=null;for(let i of e.querySelectorAll(`[name="${r}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===n;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function to(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 ro(e){if(typeof e==="string"&&Zn.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function no(e,t,r){let n=t===null?null:JSON.stringify(t),o=n!==null&&n!==e.opsSig&&r;if(e.opsSig=n,!o)return;e.core.applyOps(t,"@root")}function oo(e,t){let r=e.root.getAttribute(t);if(!r)return[];try{let n=JSON.parse(r);return Array.isArray(n)?n:[]}catch{return[]}}function io(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let r=JSON.parse(t);if(Array.isArray(r))return r.map((n)=>[n,"number"]);if(r&&typeof r==="object")return Object.entries(r);return[]}catch{return[]}}function so(e,t,r,n){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=ao(o.name,n);if(!r.includes(i))return null;return e.core.owns(o)?i:null}function ao(e,t){if(!t)return e;let r=`${t}[`;return e.startsWith(r)&&e.endsWith("]")?e.slice(r.length,-1):e}function er(e,t,r){let n=String(r);for(let o of co(e,t)){if(o.textContent===n)continue;o.textContent=n}}function co(e,t){let r=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(r).filter((n)=>e.core.owns(n))}function tr(e,t,r){let n=uo(e);for(let[o,i]of Object.entries(n)){let a=o in t?null:r(o),s=o in t?t[o]:a.el?N(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!ro(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function uo(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let r=JSON.parse(t);return r&&typeof r==="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function lo(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function Ae(e,t){if(t&&e.ours.has(t))return;let r=io(e),n=r.map(([p])=>p),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(p)=>o&&!p.includes("[")?`${o}[${p}]`:p,a=e.core.ownership(),s=new Map,c=(p)=>{let m=s.get(p);if(m)return m;let y=null,A=null,_=null;for(let x of e.root.querySelectorAll(`[name="${i(p)}"]`)){if(!a(x))continue;let D=x.type;if(D==="checkbox"||D==="radio"&&x.checked){_={el:x,kind:D};break}if(D==="radio")y??=x;else A??=x}if(!_)if(y)_={el:y,kind:"radio"};else _=A?{el:A,kind:""}:Vn;return s.set(p,_),_};for(let p of n)er(e,p,N(c(p)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?Yn(u):null;if(!l){tr(e,{},c);return}let f=oo(e,"data-reactive-compute-outputs-param"),d={};for(let[p,m]of r)d[p]=Xn(c(p),m);let h=l(d,{changed:so(e,t,n,o)})||{},g=to(h.$ops),S=[];for(let p of f){if(p==="$ops"||!(p in h))continue;let m=c(p);if(!m.el)continue;let y=Qn(e.root,a,m,i(p),h[p]);if(y)S.push(y)}for(let p of Object.keys(h)){if(p==="$ops")continue;let m=h[p];if(m===void 0||m===null)continue;er(e,p,m)}tr(e,h,c);for(let p of S){let m=new Event("input",{bubbles:!0});e.ours.add(m),p.dispatchEvent(m)}no(e,g,Boolean(t))}var cr;function ke(e){cr=e}var ur=1,fo="phlex-reactive:persist:",po=new Set(["hidden","file","password","submit","button","reset","image"]),Fe=Symbol("persist-no-value"),Le="data-reactive-persist-state",ho=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",mo=new Set(["lexxy-editor","trix-editor"]),go="lexxy-editor, trix-editor, trix-toolbar",yo=["lexxy:change","trix-change"],vo=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),ir=new WeakSet,sr=new WeakSet,ar=new WeakSet;function z(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let r=JSON.parse(t);if(r&&typeof r==="object"&&typeof r.key==="string"&&r.key!=="")return r}catch{}if(!ir.has(e))ir.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function Re(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function Ne(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||sr.has(e))return;sr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Oe(e){return fo+e.key}function Te(e,t){let r=Re();if(!r)return null;let n;try{n=r.getItem(Oe(t))}catch(c){return Ne(e,c),null}if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object"||o.v!==ur)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return U(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 lr(e,t,{fields:r,state:n}){let o=Re();if(!o)return!1;let i={v:ur,savedAt:Date.now(),fields:r};if(n)i.state=n;try{return o.setItem(Oe(t),JSON.stringify(i)),!0}catch(a){return Ne(e,a),!1}}function U(e,t){e?.removeAttribute?.(Le);let r=Re();if(!r)return;try{r.removeItem(Oe(t))}catch(n){Ne(e,n)}}function Ce(e,t){let r=Array.isArray(t.fields)?new Set(t.fields):null,n=[],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)||po.has(i.type)||i.closest(go))continue;if(r&&!r.has(i.name))continue;n.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(ho)){if(!o(i))continue;let a=bo(i);if(!a||r&&!r.has(a))continue;n.push({el:i,name:a,kind:mo.has(i.localName)?"editor":"contenteditable"})}return n}function bo(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Me(e){return typeof e.value==="string"}function Ao(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return vo.has(e.value.trim())}function wo(e,t,r){if(e?.getAttribute?.("data-reactive-debug")!=="true"||ar.has(e))return;ar.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${r?.message??r}`)}function C(e){return e.tagName==="SELECT"&&e.multiple}function fr(e){let t=new Map;for(let{el:r,name:n}of e){if(r.type==="radio"||!String(n).endsWith("[]"))continue;t.set(n,(t.get(n)??0)+1)}return t}function dr(e,t,r){if(!Array.isArray(e))return e;if(r.get(t)!==1||e.length!==1)return Fe;return e[0]}function pr(e,t){let r={},n=(o)=>{let i=r[o];return Array.isArray(i)?i:r[o]=[]};for(let{el:o,name:i,kind:a}of Ce(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Me(o))if(s)n(i).push(o.value);else r[i]=o.value}else if(a==="contenteditable"){let c=o.textContent??"";if(s)n(i).push(c);else r[i]=c}else if(o.type==="radio"){if(o.checked)r[i]=o.value;else if(!Object.hasOwn(r,i))r[i]=null}else if(o.type==="checkbox")if(s){let c=n(i);if(o.checked)c.push(o.value)}else r[i]=o.checked;else if(C(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)n(i).push(...c);else r[i]=c}else if(s)n(i).push(o.value);else r[i]=o.value}return r}function So(e,t,r){let n=t.restore==="always",o=Ce(e,t),i=fr(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(r,c))continue;let l=r[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&C(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||C(s))){if(l=dr(l,c,i),l===Fe)continue}if((s.type==="checkbox"||C(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")hr(e,s,c,l,n);else if(u==="contenteditable"){if(!n&&(s.textContent??"").trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!n&&o.some((f)=>f.kind==="native"&&f.el.type==="radio"&&f.name===c&&f.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!n&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!n&&s.checked)continue;s.checked=Boolean(l)}else if(C(s)){if(!n&&[...s.options].some((d)=>d.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let d of s.options)d.selected=f.has(d.value)}else{if(!n&&s.value!=="")continue;s.value=String(l)}}_o(e,t,r)}function hr(e,t,r,n,o){if(Array.isArray(n))return;if(!Me(t))return;if(!o&&!Ao(t))return;try{t.value=String(n)}catch(i){wo(e,r,i)}}function _o(e,t,r){let n=globalThis.customElements;if(typeof n?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!Me(a)&&!n.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)n.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=Ce(e,t),c=fr(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(r,l))continue;let d=dr(r[l],l,c);if(d===null||d===void 0||d===Fe)continue;hr(e,u,l,d,i)}})}function xo(e,t,r=!0){let n=z(e);if(!n){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=Te(e,n),i={...o?.state??{},...t},a=r?pr(e,n):o?.fields??{};if(lr(e,n,{fields:a,state:i}))e.setAttribute?.(Le,JSON.stringify(i))}function To(e){let t=z(e);if(t)U(e,t)}var Ee=new WeakMap;function Pe(e,t,r,n){let o=e.element,i=z(o);if(!i)return;if(n?.submitted)U(o,i);let a=Te(o,i);if(a){if(So(o,i,a.fields),a.state)o.setAttribute?.(Le,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 h=Te(o,i);lr(o,i,{fields:pr(o,i),state:h?.state??null})},l=()=>{let h=Number(i.debounce)||0;if(h<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},h)},f=(h)=>{if(!h?.detail?.success)return;let g=h.target;if(g?.tagName!=="FORM"||typeof g.contains!=="function")return;if(!g.contains(o))return;c(),U(o,i)},d=["input",...yo];for(let h of d)o.addEventListener?.(h,l);if(o.addEventListener?.("change",u),document.addEventListener?.("turbo:submit-end",f),Ee.set(e,()=>{if(s!==null)u();for(let h of d)o.removeEventListener?.(h,l);o.removeEventListener?.("change",u),document.removeEventListener?.("turbo:submit-end",f)}),n?.edited&&!n.submitted)u();for(let h of n?.ops??[])h(!0)}function $e(e){let t=Ee.get(e);Ee.delete(e),t?.()}function mr(e,t){let r=cr?.waiting.get(e)?.persist;if(!r||!z(e))return t(!0);(r.ops??=[]).push(t)}function Ie(e,t){mr(e,(r)=>xo(e,t,r))}function qe(e){mr(e,()=>To(e))}var De=new WeakMap,yr=new WeakSet;function We(e,t){let r=e.element,n=[];De.set(e,n);let o=(i,a,s)=>{i.addEventListener?.(a,s),n.push(()=>i.removeEventListener?.(a,s))};if(Eo(r,t)){let i=()=>M(e,t);if(o(r,"turbo:morph-element",i),i(),r.getAttribute?.("data-reactive-warn-unsaved")==="true")Fo(r,o)}if(Lo(r,t)){let i=()=>Ro(r,t);o(r,"turbo:morph-element",i),i()}}function je(e){for(let t of De.get(e)??[])t();De.delete(e)}function Eo(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let r=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let n of r)if(t.owns(n))return!0;return!1}function M(e,t){let r=e.element;if(typeof r?.querySelectorAll!=="function")return;let n=0;if(r.querySelectorAll("input[name], select[name], textarea[name]").forEach((o)=>{if(!t.owns(o))return;if(o.type==="file")return;if(ko(o))o.setAttribute("data-reactive-dirty","true"),n++;else o.removeAttribute("data-reactive-dirty")}),n>0)r.setAttribute("data-reactive-dirty",String(n));else r.removeAttribute("data-reactive-dirty")}function ko(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??[]),r=!e.multiple&&!(e.size>1),n=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(r?o===n:o.defaultSelected))}return e.value!==e.defaultValue}function vr(e){let t=e.getAttribute?.("data-reactive-dirty"),r=Number(t);return Number.isFinite(r)&&r>0?r:0}function Fo(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;t(window,"beforeunload",(r)=>{if(vr(e)===0)return;return r.preventDefault(),r.returnValue="You have unsaved changes.",r.returnValue}),t(window,"turbo:before-visit",(r)=>{if(vr(e)===0||yr.has(r))return;if(yr.add(r),!(typeof window.confirm==="function"?window.confirm("You have unsaved changes. Leave anyway?"):!0))r.preventDefault?.()})}function Lo(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let r=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let n of r)if(t.owns(n))return!0;return!1}function Ro(e,t){let r=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!r;for(let n of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(n))n.hidden=!r}function ze(e){No(e),Co(e)}function No(e){let t=e.detail,r=t?.render;if(typeof r!=="function"||r.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Be);else setTimeout(Be,0);return}let n=async(o)=>{await r(o),Be()};n.__reactiveDismissWrapped=!0,t.render=n}function Be(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let r=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(r)||r<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),r)}}var Oo=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Je=Object.freeze(["fade","slide","scale","highlight","shake"]),Ue="data-reactive-fx-pending",He=1000;function Co(e){let t=e.detail,r=t?.render;if(typeof r!=="function"||r.__reactiveEffectsWrapped)return;let n=t?.newStream??e.target,o=Oo[n?.getAttribute?.("action")];if(!o||$o())return;let i=Mo(n,o);if(!i)return;let a=o==="exit"?async(s)=>{await Do(H(n),i),await r(s)}:async(s)=>{let c=o==="enter"?Io(n):null;if(await r(s),o==="enter")qo(c,i);else wr(H(n),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Mo(e,t){let r=e.getAttribute?.("data-reactive-effect");if(r==="off")return null;if(r)return Ar(r,t);let o=(t==="enter"?Po(e):H(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?Ar(o,t):null}function H(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Po(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function Ar(e,t){if(e.startsWith("[")){let n=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)n=o.map(String)}catch{}if(n)return{legs:n};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let r=e==="random"?Je[Math.floor(Math.random()*Je.length)]:e;if(!Je.includes(r))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${r}-${t}`}}function $o(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Io(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let r of Array.from(t.children??[]))r.setAttribute?.(Ue,"");return H(e)}function qo(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let r of Array.from(e.querySelectorAll(`[${Ue}]`)))r.removeAttribute(Ue),wr(r,t)}async function Do(e,t){if(!e?.classList)return;if(t.legs){await Sr(e,t.legs);return}e.classList.add(t.className);let r=Ge(e);if(r<=0){e.classList.remove(t.className);return}await Ke(e,r),e.classList.remove(t.className)}function wr(e,t){if(!e?.classList)return;if(t.legs){Sr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let r=Ge(e);if(r<=0){e.classList.remove(t.className);return}let n=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ke(e,r).then(()=>{if(e.__reactiveFxToken===n)e.classList.remove(t.className)})}async function Sr(e,t){let[r,n,o]=t.map(Wo),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...r,...n,...o),e.classList.add(...r,...n),await jo(),e.__reactiveFxToken!==i)return;e.classList.remove(...n),e.classList.add(...o);let a=Ge(e);if(a>0)await Ke(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...r,...o)}function Wo(e){return String(e??"").split(/\s+/).filter(Boolean)}function Ge(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),r=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),n=r(t.animationDuration)+r(t.animationDelay),o=r(t.transitionDuration)+r(t.transitionDelay);return Math.min(Math.max(n,o)*1000,He)}catch{return 0}}function Ke(e,t){return new Promise((r)=>{let n=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",n),e.removeEventListener?.("transitionend",n),r()};e.addEventListener?.("animationend",n),e.addEventListener?.("transitionend",n),setTimeout(n,Math.min(t+50,He))})}function jo(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(r),e()},He),r=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Bo="phlex-reactive:latency",Ye=!1;function Tr(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"),Ye=!1}function Ze(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:Tr,disableLatencySim:Er}}function Xe(){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(!Ye)Ye=!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 xr=new WeakMap;function Qe(e){let t=globalThis.document;if(!t)return!0;let r=xr.get(t);if(!r)r=new Set,xr.set(t,r);if(r.has(e))return!0;return r.add(e),!1}function Ve(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function kr(e,t,r,n){if(Qe(`${e}|${t}|${r}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${r})${n}`)}function et(e,t,r){let n=t.to;if(typeof n!=="string"||n===""||n==="@root")return;let o="";if(r&&!t.global){let i=Ve(globalThis.document,n);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}kr(`client op "${e}"`,n,r?`scoped to #${r.id||"?"}`:"document-scoped",o)}function tt(e){if(!Qe(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function rt(e,t,r){let n=e.element,o=r.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!r.global)if(n?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Ve(n,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Ve(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}kr(t,o,`scoped to #${n?.id||"?"}`,i)}function nt(e,t){let r=e.element?.id||"?";if(Qe(`no-binding|${t.type}|${r}`))return;console.warn(`[phlex-reactive] runOps on #${r} found no on_client binding matching a "${t.type}" event — nothing ran`)}function Jo(e){if(!e)return[];let t=[],r=/<turbo-stream\b([^>]*)>/g,n;while((n=r.exec(e))!==null){let o=n[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function ot(e,t){let{action:r,status:n,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${r} → ${n??"—"} (${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 G(e,t,r){e.streams=Jo(t),e.tokenRefreshed=r!=null}var K=new WeakMap;function it(e,t,r,n){let o=r&&typeof r==="object"?Ho(r):r;return o?Lr(t,o,n,!1):[]}function st(e,t,r,n){if(!r)return null;let o=Lr(t,r,n,!0);return o.length?o:null}function Lr(e,t,r,n){let o=[];for(let i of Rr(e,t,r)){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(r&&(t.disable||t.text!=null))o.push(Uo(t,r));if(n&&t.checked==="keep"&&r&&"checked"in r){let i=r.checked;o.push(()=>r.checked=!i)}return o}function Rr(e,t,r){if(t.to==null)return r?[r]:[];let n=e.opTargets({to:t.to});if(n.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return n}function Uo(e,t){let r=K.get(t);if(r)r.count++;else K.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()=>zo(t,e)}function zo(e,t){let r=K.get(e);if(!r)return;if(--r.count>0)return;if(K.delete(e),!e.isConnected)return;if(t.disable)e.disabled=r.disabled;if(r.hadText&&e.innerHTML===r.swappedTo)e.innerHTML=r.html}function Ho(e){if(!e||typeof e!=="object")return null;let{class:t,...r}=e;return t==null?e:{...r,add_class:t}}function at(e,t,r,n){if(!r?.hide)return null;let o=Rr(t,r,n);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 Z;function lt(e){Z=e}var v=new Map;function Mr(e,t){let r=!v.has(e);if(v.set(e,t),r)Z.enter()}function X(e){if(v.delete(e))Z.exit()}var Or=!1;function ft(e){Pr();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){Xo(t,e);return}let r=e.getAttribute("data-reactive-defer-token");if(!r)return;I(t,r)}function Pr(){if(Or||typeof document>"u"||!document.addEventListener)return;Or=!0,document.addEventListener("turbo:before-stream-render",ei,!0),document.addEventListener("turbo:before-stream-render",Go)}function Go(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let r=t.slice(19);if(v.get(r)?.via==="stream")X(r)}function I(e,t){let r=document.getElementById(e);if(!r){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}pt(e),Dr(r);let n={via:"fetch",abort:new AbortController,timedOut:!1};return Mr(e,n),Qo(e,n,t)}function Ko(e,t){if(typeof e!=="string"){let r={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)r.cache="no-store";return[e.src,r]}return[ri(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":ni()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function $r(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Ir(t))return{src:t};return console.error(Yo(t)),Vo(t)||Zo(e)}function Yo(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${dt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function Vo(e){let t;try{t=new URL(e,window.location.href)}catch{return}let r=t.pathname.split("/").pop(),n=`${dt()}/${r}${t.search}`;if(/^[\w-]+$/.test(r)&&Ir(n))return{src:n,fallback:!0}}function Zo(e){pt(e.id),ht(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 Ir(e){try{let t=new URL(window.location.href),r=new URL(e,t);return r.origin===t.origin&&r.pathname.startsWith(`${dt()}/`)}catch{return!1}}function dt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function Xo(e,t){let r=document.getElementById(e);if(!r){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let n=t.getAttribute("data-reactive-defer-src");if(!n)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){I(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),Dr(r);let o=document.createElement("pgbus-stream-source");o.id=qr(e),o.setAttribute("src",n),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Mr(e,{via:"stream"})}function qr(e){return`reactive-defer-src-${e}`}async function Qo(e,t,r){let n=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},oi()),o;try{Z.count("defer"),o=await fetch(...Ko(r,t.abort.signal))}catch(s){if(clearTimeout(n),v.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),P(e,r);return}if(v.get(e)!==t){clearTimeout(n);return}if(o.redirected){clearTimeout(n),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),P(e,r,o.status);return}if(o.status===204){clearTimeout(n),Cr(e);return}if(!o.ok){clearTimeout(n),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),P(e,r,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(n),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),P(e,r,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(n),v.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),P(e,r);return}if(clearTimeout(n),v.get(e)!==t)return;Cr(e),ti(a)}var ut=null,ei=(e)=>ut?.push(e);function ti(e){let t=ut=[];try{window.Turbo.renderStreamMessage(e)}finally{ut=null}for(let r of t){if(r.defaultPrevented)continue;let n=r.detail,o=n.render;n.render=()=>{},new Promise((i)=>i(o(n.newStream))).catch(console.error)}}function pt(e){let t=v.get(e);if(!t)return;if(X(e),t.via==="fetch")t.abort.abort();else document.getElementById(qr(e))?.remove?.()}function Dr(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function ht(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Cr(e){X(e);let t=document.getElementById(e);if(!t)return;ht(t),t.removeAttribute("data-reactive-error")}function P(e,t,r){X(e);let n=document.getElementById(e);if(!n)return;ht(n),n.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"),I(e,t)};n.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:r,retry:o}}))}function ri(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function ni(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function oi(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var Wr="__materialize",V=new WeakMap;function Y(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function mt(e,t,r){Pr();let n=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>Q(e),f=(m)=>{if(Y(n)==="visible"){if(!a)h()}else if(m){let y=n.getAttribute("data-reactive-lazy-on");if(s===y)return;d(),n.addEventListener?.(y,l),s=y}},d=()=>{if(a?.disconnect(),a=null,s)n.removeEventListener?.(s,l);s=null},h=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let m=n.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((y)=>{if(y.some((A)=>A.isIntersecting))l()},{rootMargin:m}),a.observe(n)},g=()=>{let m=Y(n)!==null,y=o;if(o=m,!m)return d();if(i)return;if(t.forgetToken(),!y)return l();f(!0)};if(V.set(e,{load(){if(i)return;let m=$r(n);if(!m&&n.getAttribute("data-reactive-defer-src")!=null)return;if(m&&ii(n,t))return;let y=m?I(n.id,m):t.proceed(n,Wr,"{}");if(!y)return;i=!0,d();let A=()=>{i=!1};return y.then(A,A),y},off(){if(c)n.removeEventListener?.("turbo:morph-element",c);if(u)n.removeEventListener?.("turbo:morph-element",u);d()}}),(n.getAttribute?.("data-reactive-defer-token")||n.getAttribute?.("data-reactive-defer-src"))&&Y(n)===null)ct(n),c=(m)=>m.target===n&&ct(n),n.addEventListener?.("turbo:morph-element",c);if(n.getAttribute?.("data-reactive-token-value")==null&&n.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(m)=>{if(m.target!==n)return;if(!c)ct(n);g()},n.addEventListener?.("turbo:morph-element",u),r)return g();if(o=Y(n)!==null,o)f(!1)}function gt(e){let t=V.get(e);V.delete(e),t?.off()}function Q(e){return V.get(e)?.load()}function ii(e,t){return t.emit("reactive:before-dispatch",{action:Wr,params:{},element:e},{cancelable:!0}).defaultPrevented}function ct(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||$r(e);if(t)I(e.id,t)}function ai(){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 ci(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),r=this.getAttribute("target");if(!t||!r)return;let n=document.getElementById(r);if(n)n.setAttribute("data-reactive-token-value",t)}}function ui(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=kt(this.getAttribute("data-reactive-ops"));if(!t.length)return;let r=this.getAttribute("target"),n=this.getAttribute("data-reactive-verbose")==="true",o=r?document.getElementById(r):null;if(r&&!o){if(n)tt(r);return}Tt(t,(i)=>$i(i,o),n?(i,a)=>et(i,a,o):void 0)}}function li(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){ft(this)}}var Jr=!1,fi=null;function di(){if(Jr)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Jr=!0,document.addEventListener("turbo:before-stream-render",(e)=>{ze(e)})}function ts(e){fi=e}var Ur=!1;function zr(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea")&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function pi(){if(Ur)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ur=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented||t.localName!=="input"||!zr(t))return;let n=r.getAttribute("value");if(n==null)t.removeAttribute("value");else if(t.getAttribute("value")!==n)t.setAttribute("value",n)}),document.addEventListener("turbo:before-morph-attribute",(e)=>{if(e.detail?.attributeName==="value"&&zr(e.target))e.preventDefault()})}var hi="__materialize",Hr=!1;function mi(){if(Hr)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Hr=!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 Et(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Ze()}var an="data-reactive-active",b=0;function cn(){if(b++,b===1)ln("reactive:busy")}function un(){if(b===0)return;if(b--,b===0)ln("reactive:idle")}function rs(){return b}function ns(){b=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(an)}function ln(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(an,b>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:b}}))}var fn="data-reactive-requests";function dn(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!gi(t))return;let r=yi(t);r[e]=(Number(r[e])||0)+1,t.setAttribute(fn,JSON.stringify(r))}function gi(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function yi(e){try{let t=JSON.parse(e.getAttribute(fn));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Gr(){ai(),ci(),ui(),li(),di(),pi(),mi(),Et()}function vi(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var pn=Symbol.for("phlex-reactive.core");if(globalThis[pn])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[pn]=!0;var hn=!1;function bi(){if(hn)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(bi,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Ai=new Set(["href","src","srcdoc","action","formaction","xlink:href","style"]);function wi(e){let t=String(e).toLowerCase();return t.startsWith("on")||Ai.has(t)}var yt=new WeakMap;function Si(e,t,r){let[n,o,i]=t;yt.get(e)?.(),e.classList.add(n,o),r();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,yt.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(n,o,i)};yt.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,_i(e))}function _i(e){let t=0;try{let r=getComputedStyle(e);for(let n of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(r[n+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(r[n+"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 xi=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Ti=new Set(["lexxy-editor","trix-editor"]);function Ei(e){return Ti.has(e.localName)?typeof e.value==="string":!0}var Kr=Object.freeze({show:(e,t,r)=>vt(e,!1,t,r),hide:(e,t,r)=>vt(e,!0,t,r),toggle:(e,t,r)=>vt(e,!e.hidden,t,r),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((r)=>e.classList.toggle(r)),set_attr:(e,t)=>{if(bt(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(bt(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!bt(t.name))return;if(Array.isArray(t.values)){let[r,n]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===r?n:r)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>Ni(e)?.focus?.(),text:(e,t)=>{let r=String(t.value??"");if(e.textContent!==r)e.textContent=r},check_group:(e,t)=>{let r=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let n of r)le(n,t.group,t.checked)},dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,r)=>{let n=ki(e);if(!n)return;let o=null;if(t?.submitter!=null&&typeof r==="function"){if(o=r({...t,to:t.submitter})[0]??null,!(o?.form===n&&(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?n.requestSubmit?.(o):n.requestSubmit?.()},paste_into:(e)=>Fi(e),persist_state:(e,t)=>Ie(e,t.state),persist_clear:(e)=>qe(e)});function ki(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function Fi(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((r)=>{if(!r)return;if(e.value=r,typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}));e.focus?.()}).catch(()=>{})}function Li(e,t,r){if(r?.transition)Si(e,r.transition,()=>e.hidden=t);else e.hidden=t}function vt(e,t,r,n){if(Li(e,t,r),r?.expanded==null||typeof n!=="function")return;for(let o of n({...r,to:r.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function bt(e){if(!wi(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}var Ri='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ni(e){return e.querySelectorAll?.(Ri)?.[0]??null}function kt(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 Yr=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 Ft(e,t,r){let n=e.split("+");for(let a of Vr)if(n.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=n.find((a)=>!Vr.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=r&&Object.hasOwn(r,o)?r[o]:Object.hasOwn(Yr,o)?Yr[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}function Oi(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:kt(t),legacy:!0}];let r=[];for(let n of t.split(" ")){if(n==="")continue;let o=null;try{o=JSON.parse(n)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))r.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(n)} — skipped`)}return r}function Zr(e,t,r){if(e.legacy)return!0;let n=e.on;if(typeof n!=="string"||n==="")return!1;let o=n.indexOf(".");if(t.type!==(o<0?n:n.slice(0,o)))return!1;if(Boolean(e.window)!==mn(t.currentTarget))return!1;return o<0||r===null||Ft(n.slice(o+1),t,r)}function Ci(e,t){let r=e.detail;if(r===void 0)return!0;if(r===null||typeof r!=="object"||Array.isArray(r))return!1;let n=t.detail;if(n===null||typeof n!=="object")return!1;return Object.keys(r).every((o)=>n[o]===r[o])}var Xr=new WeakMap;function Mi(e,t,r){if(!r.once)return!1;let n=t.currentTarget??e.element,o=Xr.get(e);if(!o)o=new WeakMap,Xr.set(e,o);let i=o.get(n);if(!i)i=new Set,o.set(n,i);let a=t.params?.ops,c=(n===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(r);if(i.has(c))return!0;return i.add(c),!1}var Qr=new WeakMap;function Pi(e,t){if(e===null||typeof e!=="object")return!1;let r=e.params?.ops,n=typeof r==="string"?r:JSON.stringify(r??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(n))return!0;return a.add(n),!1}function Tt(e,t,r){for(let n of e){if(!Array.isArray(n))continue;let[o,i={}]=n;if(!Object.hasOwn(Kr,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&r)r(o,i);for(let s of a)Kr[o](s,i,t)}}function $i(e,t){let r=e.to;if(t){if(r==="@root")return[t];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...t.querySelectorAll(r)]}if(typeof r!=="string"||r===""||r==="@root")return[];return[...document.querySelectorAll(r)]}function Ii(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function en(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function qi(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 Di(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]")!=null}function Wi(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function os(e,t,r){}function ji(e,t){}function is(e){return[]}function ss(e){return Promise.resolve()}var tn=new Set;function Bi(e,t,r){let n=e+t;if(tn.has(n))return;tn.add(n),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,r)}function as(){return["persist","defer","form","bindings","compute","effects","hints","devtools"]}var rn=Promise.resolve();var nn={enter:cn,exit:un,count:dn,waiting:new WeakMap},on=1,At=2,wt=4,St=8,_t=16;ke(nn),lt(nn);var q=Symbol.for("phlex-reactive.early"),Ji=1e4,Ui=1500,mn=(e)=>e!=null&&(e===globalThis.window||e.window===e);function xt(){return globalThis[q]??={queue:[],connected:new WeakSet},globalThis[q]}function zi(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Ji}function Hi(e){let t={};for(let{name:r,value:n}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(r);if(!o)continue;let i;try{i=JSON.parse(n)}catch{i=n}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function Gi(e,t,r){return{[q]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:r?t.ownerDocument.defaultView:t,params:Hi(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 te=new WeakMap;function Ki(e,{token:t,type:r,method:n,filter:o,win:i},a){let s=te.get(e);if(!s)te.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:r,method:n,filter:o,win:i,params:a,armed:!0}),!0}function sn(e,t,r,n){if(e?.[q])return!1;let o=mn(e?.currentTarget),i=o?n:e?.currentTarget,a=Vi(e,i,o?`@${t}`:t),s=te.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&&!Ft(u.filter,e,r))continue;return u.armed=!1,!0}return a}var ee=new WeakMap;function Yi(e,t,r){let n=ee.get(e);if(!n)ee.set(e,n=new Map),setTimeout(()=>ee.delete(e));let o=n.get(t)??{};n.set(t,o),o[r]=(o[r]??0)+1}function Vi(e,t,r){let n=e&&ee.get(e)?.get(t);if(!n?.[r])return!1;return n[r]-=1,!0}class gn extends si{static values={token:String};#p;#h=new Map;#c=new Map;#z;#w;#M;#S=0;#u=new Map;#_=new WeakMap;#m;featuresReady=rn;#Te=new Map;#Ee=new Set;#H=!1;#P=null;#ke=new Map;#Fe=new Map;#Le=new Map;#G=0;#$;#x=0;#t=0;connect(){if(hn=!0,xt().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||en(this.element))this.#m=(e)=>{if(e.target!==this.element)return;this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#m);this.#G++,this.featuresReady=rn,this.#I(),this.#V()}#I(e){this.#l(on,"persist",Ii,(t)=>Pe(this,t,e)),this.#l(At,"defer",en,(t)=>mt(this,t,e)),this.#l(wt,"form",qi,(t)=>We(this,t,e)),this.#l(St,"bindings",Di,(t)=>oe(this,t,e)),this.#l(_t,"compute",Wi,(t)=>we(this,t,e))}#l(e,t,r,n){if(this.#x&e)return;try{if(!r(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#x|=e;try{n(this.#e()),this.#t|=e}catch(o){this.#q(t,"connect",o)}}#K(){{let e=this.#t;this.#x=this.#t=0;let t=this.#e();if(e&on)this.#f("persist",()=>$e(this,t));if(e&At)this.#f("defer",()=>gt(this,t));if(e&wt)this.#f("form",()=>je(this,t));if(e&St)this.#f("bindings",()=>ie(this,t));if(e&_t)this.#f("compute",()=>Se(this,t))}}#f(e,t){try{t()}catch(r){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,r)}}#Re(e){}#Ne(e,t){}#Oe(e){}#Ce(e,t){}#Me(e,t,r,n){}#e(){return this.#$??={emit:(e,t,r)=>this.#n(e,t,r),reseed:()=>this.#Y(),proceed:(e,t,r)=>this.#E(e,t,r),forgetToken:()=>{this.#p=void 0},owns:(e)=>this.#b(e),ownership:()=>this.#L(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#O(e,t),applyOps:(e,t)=>Tt(e,(r)=>this.#C(t!=null&&r.to==null?{...r,to:t}:r),(r,n)=>this.#O(`client op "${r}"`,n)),listnavOptions:(e)=>this.#d(e),collectFields:()=>this.#B(),confirm:(e,t)=>Promise.resolve().then(()=>Br(e,t)).catch(()=>!1)},this.#$}#Y(){if(this.#t&wt)M(this,this.#e());if(this.#t&St)se(this);if(this.#t&_t)_e(this)}#q(e,t,r){if(Bi(e,t,r),this.#r("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#n("reactive:error",{kind:"feature",feature:e,phase:t,error:r})}#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.#Z()}#T=new Set;#Z(){let{queue:e}=xt();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 r=zi(),n=new Map;for(let o of t){let i=n.get(o.event)??[new Set,new Set];n.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(Ui,r):r,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.#N())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#X(o)}}#X({event:e,el:t,descs:r,win:n}){let o=Gi(e,t,n),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=n?this.element:t;for(let c of r){if(!a.includes(c.token))continue;if(c.filter&&!Ft(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Ki(s,c,n&&JSON.stringify(o.params)))continue;this.#T.add(s)}if(Yi(e,s,n?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#K(),this.#ne(),this.#ie(),this.#m)this.element.removeEventListener?.("turbo:morph-element",this.#m);xt().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#T)te.delete(e);this.#T.clear()}dispatch(e){if(sn(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:t,params:r,debounce:n,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 f=e.currentTarget??e.target;if(!c&&!this.#ye(u,f))e.preventDefault();if(t===hi){let g=()=>{if(this.#t&At)return Q(this);if(this.tokenValue)return this.#E(f,t,"{}")};return this.#H?this.featuresReady.then(g):g()}let d=this.#D(i,a),h=()=>this.#E(f,t,r,n,o,u,l);if(!d)return h();if(d instanceof Promise)return d.then((g)=>g?this.#g(g,f,h):h());this.#g(d,f,h)}#g(e,t,r){return Promise.resolve().then(()=>Br(e,{el:t})).catch(()=>!1).then((n)=>{if(n)r()})}#D(e,t){if(e)return e;if(!t)return null;return ce(this,this.#e(),t)}#Q(e){}runOps(e){if(sn(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Pi(e,this))return;let t=e.params??{},r=e.currentTarget??e.target,n=Oi(t.ops),o=n.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&&n.length>0){if(this.#N())nt(this,e);return}for(let a of i){if(a.outside&&e[q])continue;if(!Ci(a,e))continue;if(Mi(this,e,a))continue;this.#ee(a.legacy?{...t,ops:a.ops}:a,e,r)}}#ee({ops:e,confirm:t,confirmWhen:r,outside:n,window:o},i,a){if(n&&this.element.contains(i.target))return;if(!o)i.preventDefault();let s=this.#D(t,r),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 xe(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#d(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return he(this,this.#e(),e)}tagsPick(e){return me(this,this.#e(),e)}tagsRemove(e){return ge(this,this.#e(),e)}nestedAdd(e){return ye(this,this.#e(),e)}nestedRemove(e){return ve(this,this.#e(),e)}syncNestedJson(e){return ae(this,this.#e(),e)}#$e(e,t){}trackDirty(){M(this,this.#e())}listnavNext(e){this.#y(e,(t,r)=>t<0?0:(t+1)%r)}listnavPrev(e){this.#y(e,(t,r)=>t<0?r-1:(t-1+r)%r)}listnavFirst(e){this.#y(e,()=>0)}listnavLast(e){this.#y(e,(t,r)=>r-1)}listnavPick(e){let t=this.#d(e),r=t.findIndex((n)=>n.hasAttribute("data-reactive-highlighted"));if(r<0)return;e.preventDefault(),t[r].click()}listnavClose(e){for(let t of this.#d(e))t.removeAttribute("data-reactive-highlighted")}#y(e,t){let r=this.#d(e);if(!r.length)return;e.preventDefault();let n=this.#te(e),o=globalThis.document?.activeElement,i=n?r.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):r.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=r[t(i,r.length)];if(n)a.focus?.();else{for(let s of r)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"}#d(e){let r=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!r)return[];let n=this.#L();return Array.from(this.element.querySelectorAll(r)).filter((o)=>!o.hidden&&n(o))}#E(e,t,r,n,o,i,a){if(this.#n("reactive:before-dispatch",{action:t,params:this.#J(r),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(n)||0;if(c>0)return this.#re(e,c,t,r,i,a);let u=Number(o)||0;if(u>0)return this.#oe(e,u,t,r,i,a);return this.#v(t,r,i,e,a)}#v(e,t,r,n,o){let i={inverse:null,undo:[],resurrect:null},a=this.#ve(e,n,i),s=Boolean(r||o),c=(d)=>{if(!s||!d)return;let h=this.#e();if(i.inverse=st(this,h,r,n),i.undo.push(...it(this,h,o,n)),this.#F())i.resurrect=at(this,h,r,n)},u=!0;c(!0);let l=()=>this.#ue(e,t,i,a),f=()=>this.#P?this.#P.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Ie(){return this.#Q("hints")}#re(e,t,r,n,o,i){this.#k(e);let a=()=>{this.#k(e),this.#v(r,n,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)}#ne(){for(let e of[...this.#h.keys()])this.#k(e)}#oe(e,t,r,n,o,i){let a=this.#c.get(e)??new Map;if(a.has(r))return;let s=setTimeout(()=>{if(a.delete(r),a.size===0)this.#c.delete(e)},t);return a.set(r,s),this.#c.set(e,a),this.#v(r,n,o,e,i)}#ie(){for(let e of this.#c.values())for(let t of e.values())clearTimeout(t);this.#c.clear()}#n(e,t,{cancelable:r=!1}={}){let n=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:r,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(n),n}#o(e,t,r,n){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#v(e,t)};this.#n("reactive:error",{action:e,params:r,...n,retry:o})}#r(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",r=document.getElementById(t);if(!r)return;r.appendChild(e.content.cloneNode(!0))}#ce(){return Xe()}#F(){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,r,n){let{fields:o,files:i}=this.#B(),a=this.#J(t),s={...o,...a},c=this.#i,u=i.length>0,l=u?this.#pe(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#F()?{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.#s(r.inverse),this.#r("offline"),this.#o(e,t,s,{kind:"offline"});return}let d;try{let p={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#_e()};if(!u)p["Content-Type"]="application/json";let m=this.#xe();if(m)p["X-Pgbus-Connection"]=m;dn("action"),d=await fetch(this.#we(),{method:"POST",headers:p,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Se())})}catch(p){if(console.error("[phlex-reactive] action error",p),this.#s(r.inverse),p?.name==="TimeoutError"||p?.name==="AbortError"){this.#r("timeout"),this.#o(e,t,s,{kind:"timeout"});return}this.#ae(),this.#r("network"),this.#o(e,t,s,{kind:"network"});return}if(f)f.status=d.status;if(d.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#s(r.inverse),this.#r("redirected"),this.#o(e,t,s,{kind:"redirected",status:d.status});return}if(!d.ok){let p=await d.text();if(console.error(`[phlex-reactive] action failed: HTTP ${d.status}`,p),this.#s(r.inverse),(d.headers.get("Content-Type")||"").includes("turbo-stream")){let m=this.#j(p);if(this.#i=m??this.#i,f)G(f,p,m);window.Turbo.renderStreamMessage(p)}this.#r("http"),this.#o(e,t,s,{kind:"http",status:d.status,body:p});return}let h=d.headers.get("Content-Type")||"";if(!h.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${h}" — no update applied`),this.#s(r.inverse),this.#r("content-type"),this.#o(e,t,s,{kind:"content-type",status:d.status});return}let g=await d.text(),S=this.#j(g);if(this.#i=S??this.#i,f)G(f,g,S);if(window.Turbo.renderStreamMessage(g),r.resurrect)queueMicrotask(r.resurrect);this.#se(),this.#n("reactive:applied",{action:e,params:s,html:g})}catch(d){console.error("[phlex-reactive] action error",d),this.#s(r.inverse),this.#n("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(n?.(),f)ot(this,{...f,ms:this.#W()-f.started})}}get#i(){return this.#p??this.tokenValue}set#i(e){this.#p=e}tokenValueChanged(){this.#p=void 0}#j(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:r,self:n}=this.#le(t),o=e.match(r);if(o)return o[1];let i=e.match(n);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 r=vi(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${r}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${r}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#b(e){return e.closest('[data-controller~="reactive"]')===this.element}#L(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#b(t)}#B(){let e={},t=[],r=this.#L(),n=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!r(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else n.push(s)});let o=[];this.element.querySelectorAll(`[name]${xi}`).forEach((s)=>{if(r(s))o.push(s)});let i=this.#fe(n),a=this.#de(n);for(let s of n)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.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Ei(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 r of e){if(r.type==="radio")continue;if(String(r.name).endsWith("[]"))t.add(r.name)}return t}#de(e){let t=new Set;for(let r of e)if(r.type==="checkbox")t.add(r.name);return t}#pe(e,t,r,n){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(r))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(n);for(let{name:s,file:c,multiple:u}of n){let f=u||a.has(s)?`${this.#A(s)}[]`:this.#A(s);o.append(f,c,c.name)}return o}#A(e){let t=String(e),r=t.indexOf("[");if(r===-1)return`params[${t}]`;return`params${[t.slice(0,r),...t.slice(r).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#R(e,t,r){if(r==null)e.append(t,"");else if(Array.isArray(r))r.forEach((n,o)=>this.#R(e,`${t}[${o}]`,n));else if(typeof r==="object")for(let[n,o]of Object.entries(r))this.#R(e,`${t}[${n}]`,o);else e.append(t,String(r))}#he(e){let t=new Map;for(let{name:r}of e)t.set(r,(t.get(r)??0)+1);return new Set([...t].filter(([,r])=>r>1).map(([r])=>r))}#J(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#me(e){return kt(e)}#ge(e){Tt(e,(t)=>this.#C(t),(t,r)=>this.#O(`client op "${t}"`,r))}#N(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#F()}#O(e,t){if(!this.#N())return;rt(this,e,t)}#qe(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((r)=>this.#b(r))}#ye(e,t){if(e?.checked!=="keep")return!1;let r=t?.type;return r==="checkbox"||r==="radio"}#s(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#ve(e,t,r){this.#be(e,t),cn();let n=!1;return()=>{if(n)return;n=!0,this.#Ae(e,t),un();for(let o of r.undo)o()}}#be(e,t){if(this.#a(t,e,1),this.#a(this.element,e,1),this.#u.set(e,(this.#u.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let r of this.#U(e))this.#a(r,e,1)}#Ae(e,t){this.#a(t,e,-1),this.#a(this.element,e,-1);let r=(this.#u.get(e)??1)-1;if(r<=0)this.#u.delete(e);else this.#u.set(e,r);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let n of this.#U(e))this.#a(n,e,-1)}#a(e,t,r){if(!e||typeof e.getAttribute!=="function")return;let n=this.#_.get(e)??new Map,o=(n.get(t)??0)+r;if(o<=0)n.delete(t);else n.set(t,o);if(n.size===0){this.#_.delete(e),e.removeAttribute("data-reactive-busy");return}this.#_.set(e,n),e.setAttribute("data-reactive-busy",[...n.keys()].join(" "))}#U(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((r)=>r.getAttribute("data-reactive-busy-on")===e&&this.#b(r))}#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}#_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)Gr();else document.addEventListener("turbo:load",Gr,{once:!0});Et();var gs=gn;export{an as ACTIVE_ATTR,xi as EDITOR_SELECTOR,Ti as EDITOR_TAGS,Bo as LATENCY_KEY,fn as REQUESTS_ATTR,bi as checkReactiveRegistration,dn as countReactiveRequest,gs as default,Er as disableLatencySim,Tr as enableLatencySim,cn as enterReactiveActivity,vi as escapeRegExp,un as exitReactiveActivity,ss as loadReactiveFeature,ts as onReactiveStreamWithoutEffects,rs as reactiveActivityCount,as as reactiveFeatureNames,Gr as registerReactiveActions,li as registerReactiveDefer,Et as registerReactiveDev,di as registerReactiveDismiss,di as registerReactiveEffects,ji as registerReactiveFeature,os as registerReactiveFeatureLoader,ui as registerReactiveJs,pi as registerReactiveMorphFocus,mi as registerReactiveOffline,di as registerReactiveStreamRender,ci as registerReactiveToken,ai as registerReactiveVisit,ns as resetReactiveActivity,is as unloadedFeaturesFor};
2
2
 
3
- //# debugId=D52C13EF29302DAC64756E2164756E21
3
+ //# debugId=473E27CDB8E7C76064756E2164756E21
4
4
  //# sourceMappingURL=reactive_controller.min.js.map