phlex-reactive 0.15.2 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +269 -2
- data/README.md +92 -13
- data/app/javascript/phlex/reactive/core.js +1 -0
- data/app/javascript/phlex/reactive/core.min.js +6 -6
- data/app/javascript/phlex/reactive/core.min.js.map +4 -4
- data/app/javascript/phlex/reactive/features/bindings.js +153 -21
- data/app/javascript/phlex/reactive/features/bindings.min.js +2 -2
- data/app/javascript/phlex/reactive/features/bindings.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/countdown.js +140 -0
- data/app/javascript/phlex/reactive/features/countdown.min.js +4 -0
- data/app/javascript/phlex/reactive/features/countdown.min.js.map +10 -0
- data/app/javascript/phlex/reactive/features/form.js +54 -22
- data/app/javascript/phlex/reactive/features/form.min.js +2 -2
- data/app/javascript/phlex/reactive/features/form.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/persist.js +41 -8
- data/app/javascript/phlex/reactive/features/persist.min.js +2 -2
- data/app/javascript/phlex/reactive/features/persist.min.js.map +3 -3
- data/app/javascript/phlex/reactive/reactive_controller.js +2 -0
- data/app/javascript/phlex/reactive/reactive_controller.min.js +4 -4
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +9 -8
- data/app/javascript/phlex/reactive/runtime.js +313 -32
- data/lib/phlex/reactive/component/countdown_binding.rb +80 -0
- data/lib/phlex/reactive/component/field_references.rb +130 -0
- data/lib/phlex/reactive/component/helpers.rb +81 -19
- data/lib/phlex/reactive/component/identity.rb +34 -1
- data/lib/phlex/reactive/component/image_fallback_binding.rb +67 -0
- data/lib/phlex/reactive/component/media_binding.rb +30 -4
- data/lib/phlex/reactive/component/media_pattern.rb +79 -0
- data/lib/phlex/reactive/component/selection.rb +24 -2
- data/lib/phlex/reactive/component/show_options.rb +91 -0
- data/lib/phlex/reactive/doctor.rb +20 -8
- data/lib/phlex/reactive/engine.rb +2 -2
- data/lib/phlex/reactive/js.rb +58 -5
- data/lib/phlex/reactive/show_conditions/compare_terms.rb +142 -0
- data/lib/phlex/reactive/show_conditions.rb +39 -6
- data/lib/phlex/reactive/streamable.rb +6 -3
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +10 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{Controller as Zs}from"@hotwired/stimulus";import{confirmResolver as ro}from"phlex/reactive/confirm";import{confirmPredicate as Yo}from"phlex/reactive/confirm_predicate";var C=new WeakMap,Le=new WeakMap;function k(e,t){let n=C.get(e);if(!n){if(C.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)Le.set(n.root,n)}return n}function E(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function I(e,t){E(e,"turbo:morph-element",t),e.seeds.push(t),t()}function Fe(e,t){let n=k(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&ei(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")ui(n,s.target);else n.groups=ci(n),kn(n);ri(n)},E(n,"input change",n.show),I(n,n.show);if(!n.arm&&ti(n))E(n,"input change",(s)=>En(n,s)),I(n,n.arm=()=>{En(n,null),kn(n)});if(!r&&(r=n.show||n.arm))E(n,"reset",()=>setTimeout(()=>{if(C.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=Z(n)))E(n,"input",(s)=>di(n,s)&&D(n)),I(n,()=>D(n));if(!i&&(i=ee(n)))I(n,()=>Dn(n));if(!a&&(a=pi(n)))E(n,"input change",(s)=>Bn(n,s)),I(n,()=>qe(n))})(),E(n,"keydown",(s)=>Ri(n,s)),E(n,"paste drop",(s)=>Li(n,s)),E(n,"input",(s)=>Fi(n,s))}function Oe(e){let t=C.get(e);if(!t)return;C.delete(e),Le.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Ne(e){let t=C.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function M(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Ce(e,t,n){return Bn(k(e,t),n)}function Me(e,t,n){return Kn(k(e,t),n)}var Vo=/^#[A-Za-z_][\w-]*$/,Rn="[data-reactive-show-field], [data-reactive-show]";function Xo(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of Jn){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return zn(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Ln(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 Zo(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function Fn(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return q(n,t);return Qo(e,t)}function Qo(e,t){let n=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!n)return null;let r=e[n];if(r.length===0)return null;let o=r.map((i)=>He(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function X(e,t="show"){if(typeof e==="string"&&Vo.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function ei(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?.(Rn)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(Q)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(Mn)??[])if(e.core.owns(n))return!0;return!1}function ti(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function ni(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Zo(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function En(e,t){let n=ni(e);if(!n.length)return;let r=Cn(e,e.core.ownership());n.forEach((o,i)=>{let a=q(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function ri(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=Cn(e,t);for(let o of e.root.querySelectorAll(Rn)){if(!t(o))continue;let i=o.getAttribute("data-reactive-show");if(i!==null){let u=Fn(Ln(i),r);if(u!==null)_n(o,u,t,n);continue}let a=o.getAttribute("data-reactive-show-field");if(!a)continue;let s=r(a);if(s===null)continue;let c=Xo(o,s);if(c===null)continue;_n(o,c,t,n)}if(e.groups)li(e,r,t,n);ai(e,r,t),oi(e,r),fi(e,r)}function _n(e,t,n,r){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let o of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(o))o.disabled=!t;if(e.name&&n(e))e.disabled=!t}function oi(e,t){let n=On(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){ii(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!X(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)=>He(l,a))}else{let l=Gn(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 ii(e,t,n){if(!X(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=ki(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!Ti(r))return;let i=q(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function On(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function si(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(Nn(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function Nn(e,t){return`[name="${t&&!e.includes("[")?`${t}[${e}]`:e}"]`}function Cn(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?Pe(e,o,t,n).filter((s)=>s.checked).length:si(e,o,t,n));return r.get(a)}}var Mn="[data-reactive-media]";function ai(e,t,n){for(let r of e.root.querySelectorAll(Mn)){if(!n(r))continue;let o;try{o=JSON.parse(r.getAttribute("data-reactive-media"))}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let i=t(o.field);if(i===null)continue;let a=o.take>0?[...i].slice(0,o.take).join(""):i,s=Object.hasOwn(o.pool,a)?xn(e,o.pool[a])[0]:null,c=e.core.copyMedia(r,s??null);if(c===null||typeof o.label!=="string")continue;let u=c===!1?String(o.blank??""):c;for(let l of xn(e,o.label))if(l.textContent!==u)l.textContent=u}}function xn(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var Q="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function ci(e){return!!e.root.querySelector?.(Q)}function Pe(e,t,n,r){return[...e.root.querySelectorAll(Nn(t,r))].filter((o)=>o.type==="checkbox"&&n(o))}function ui(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))Pn(e,n,t.checked,t)}function $e(e,t,n){if(!t)return;let r=Le.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};Pn(r,t,n!==!1),r.show?.()}function Pn(e,t,n,r){let o=e.root.getAttribute?.("data-reactive-scope")||null,i=Pe(e,t,e.core.ownership(),o).filter((a)=>a!==r&&a.checked!==n);for(let a of i)a.checked=n;e.flipping=!0;try{for(let a of i)for(let s of["input","change"])a.dispatchEvent?.(new Event(s,{bubbles:!0}))}finally{e.flipping=!1}}function li(e,t,n,r){for(let o of e.root.querySelectorAll(Q)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Fn(Ln(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=Pe(e,s,n,r).filter((l)=>l!==o),u=c.filter((l)=>l.checked).length;o.checked=u>0&&u===c.length,o.indeterminate=u>0&&u<c.length}}}function fi(e,t){for(let[n,r]of Object.entries(On(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!X(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!X(a,"group"))continue;let c=q(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function kn(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?.(`${Q}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let r=(o)=>o.nodeType===1&&(o.matches('input[type="checkbox"]')||!!o.querySelector('input[type="checkbox"]'));e.groupObserver=new MutationObserver((o)=>{if(!o.some((i)=>[...i.addedNodes,...i.removedNodes].some(r)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function Z(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function di(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}function D(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=(o.value??"").trim().toLowerCase(),a=0;for(let u of e.root.querySelectorAll(n)){if(!r(u))continue;let l=(u.getAttribute("data-reactive-filter-text")??u.textContent??"").toLowerCase(),p=u.hasAttribute?.("data-reactive-tags-selected")||i!==""&&!l.includes(i);if(u.hidden=p,p)u.removeAttribute("data-reactive-highlighted");else a++}let s=e.root.getAttribute("data-reactive-filter-group");if(s)for(let u of e.root.querySelectorAll(s)){if(!r(u))continue;let l=[...u.querySelectorAll(n)].filter(r);if(l.length===0)continue;u.hidden=l.every((p)=>p.hidden)}let c=e.root.getAttribute("data-reactive-filter-empty");if(c){for(let u of e.root.querySelectorAll(c))if(r(u))u.hidden=a>0}}function ee(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function pi(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function Ie(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function De(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function $n(e,t){let n=Ie(e);if(!n)return!1;let r=De(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)In(e,n,r);return i}function In(e,t,n){t.value=n.join(","),M(t),Dn(e)}function mi(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function Dn(e){let t=Ie(e);if(!t)return;let n=De(t),r=e.core.ownership();hi(e,n,r),gi(e,n,r)}function hi(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function gi(e,t,n){let r=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!n(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(r.has(i.toLowerCase()))o.setAttribute("data-reactive-tags-selected","true"),o.hidden=!0,o.removeAttribute?.("data-reactive-highlighted");else if(o.hasAttribute?.("data-reactive-tags-selected")){if(o.removeAttribute("data-reactive-tags-selected"),!Z(e))o.hidden=!1}}if(Z(e))D(e)}function bi(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function yi(e,t){let n=[e,...e.querySelectorAll?.("*")??[]];for(let r of n)for(let o of["name","id","for"]){let i=r.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))r.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function vi(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 Ai(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let p=a.find((m)=>Wn(m.getAttribute?.("name"))===c);if(!p)continue;wi(p,l),s.push(l)}if(r)for(let c of s)Si(c);return s[0]??null}function wi(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Re(t)!=="";else e.value=Re(t);M(e)}function Si(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function Ei(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Tn(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",M(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);qe(e)}function qe(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))jn(e,n.getAttribute("data-reactive-nested-json"))}function _i(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function qn(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=Wn(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Re(o)}return n}function Wn(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 jn(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=_i(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(qn(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function We(e,t,n){let r=k(e,t);if(!ee(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!$n(r,String(o.value??"").split(",")))return;if(o.value="",Z(r))D(r)}function je(e,t,n){let r=k(e,t);if(!ee(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!$n(r,[i]))return;let a=mi(r);if(!a)return;a.value="",D(r),a.focus?.()}function Be(e,t,n){let r=k(e,t);if(!ee(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=Ie(r);if(!a)return;let s=De(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;In(r,a,c)}function Je(e,t,n){let r=k(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){vi(r,i);return}let l=u.cloneNode(!0);yi(l,bi(r)),s.appendChild(l);let p=o?.getAttribute?.("data-reactive-nested-from-param"),m=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",g=Ai(r,l,p,m);if(p)g?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)jn(r,i)}function Ue(e,t,n){let r=k(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?Kn(r,s):null);if(!c)return Tn(r,i);let u=qn(r,i),l=Ei(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((p)=>{if(p)Tn(r,i)})}function Bn(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;qe(e)}var Jn=["gte","gt","lte","lt"],xi=["len_eq","len_gte","len_gt","len_lte","len_lt"],Un=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"];function Hn(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function zn(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function Gn(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of Jn)if(n in e)return zn(n,e[n],t);for(let n of xi)if(n in e)return Hn(n,e[n],[...String(t??"")].length);return null}function He(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=Un.find((o)=>(o in e));if(n){let o=t(e.field,!0);return Hn(n,e[n],Array.isArray(o)?o.length:Number(o)||0)===!0}let r=t(e.field)??"";return Gn(e,r)===!0}function q(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>He(r,t)))}function ki(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let n of e){if(!Array.isArray(n))continue;for(let r of n)if(r&&typeof r==="object"&&typeof r.field==="string")t.add(r.field)}return t.size>0?[...t]:null}function Ti(e){return e.flat().every((t)=>Un.some((n)=>(n in Object(t))))}function Kn(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=Yo(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=q(n.groups?.any,o)===!0;return i?n.message:null}function ze(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function Ri(e,t){let n=ze(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),M(n),n.blur()}function Li(e,t){let n=ze(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||e.core.plain()&&!(r&&/[\r\n]/.test(o)))return;if(t.preventDefault(),r)o=o.replace(/\r?\n|\r/g," ");n.focus(),document.execCommand("insertText",!1,o)}function Fi(e,t){let n=ze(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as Oi}from"phlex/reactive/compute";var j=new WeakMap;function Zn(e,t){let n=j.get(e);if(!n)j.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function Ke(e,t,n,r){let o=Zn(e,t),i=zi(o);if(i)o.seed=()=>Ge(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)Ge(o)}function Ye(e){let t=j.get(e);if(!t)return;if(j.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function Ve(e){j.get(e)?.seed?.()}function Xe(e,t,n){return Ge(Zn(e,t),n)}var Ni=Object.freeze({el:null,kind:""}),Ci=/^#[A-Za-z_][\w-]*$/;function W({el:e,kind:t}){if(!e)return"";if(t==="checkbox")return e.checked?"true":"false";if(t==="radio")return e.checked?e.value??"":"";return e.value??""}function Qn(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function Mi(e,t){if(t==="string")return W(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Qn(W(e));if(n)return e.el.checked?1:0;let r=Number(W(e));return Number.isFinite(r)?r:0}function Pi(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Qn(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return $i(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function $i(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function Ii(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 Di(e){if(typeof e==="string"&&Ci.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function qi(e,t,n){let r=t===null?null:JSON.stringify(t),o=r!==null&&r!==e.opsSig&&n;if(e.opsSig=r,!o)return;e.core.applyOps(t,"@root")}function Wi(e,t){let n=e.root.getAttribute(t);if(!n)return[];try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function ji(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let n=JSON.parse(t);if(Array.isArray(n))return n.map((r)=>[r,"number"]);if(n&&typeof n==="object")return Object.entries(n);return[]}catch{return[]}}function Bi(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=Ji(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function Ji(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Vn(e,t,n){let r=String(n);for(let o of Ui(e,t)){if(o.textContent===r)continue;o.textContent=r}}function Ui(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Xn(e,t,n){let r=Hi(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?W(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!Di(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Hi(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let n=JSON.parse(t);return n&&typeof n==="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function zi(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function Ge(e,t){if(t&&e.ours.has(t))return;let n=ji(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.ownership(),s=new Map,c=(h)=>{let d=s.get(h);if(d)return d;let y=null,A=null,O=null;for(let N of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(N))continue;let V=N.type;if(V==="checkbox"||V==="radio"&&N.checked){O={el:N,kind:V};break}if(V==="radio")y??=N;else A??=N}if(!O)if(y)O={el:y,kind:"radio"};else O=A?{el:A,kind:""}:Ni;return s.set(h,O),O};for(let h of r)Vn(e,h,W(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?Oi(u):null;if(!l){Xn(e,{},c);return}let p=Wi(e,"data-reactive-compute-outputs-param"),m={};for(let[h,d]of n)m[h]=Mi(c(h),d);let g=l(m,{changed:Bi(e,t,r,o)})||{},b=Ii(g.$ops),v=[];for(let h of p){if(h==="$ops"||!(h in g))continue;let d=c(h);if(!d.el)continue;let y=Pi(e.root,a,d,i(h),g[h]);if(y)v.push(y)}for(let h of Object.keys(g)){if(h==="$ops")continue;let d=g[h];if(d===void 0||d===null)continue;Vn(e,h,d)}Xn(e,g,c);for(let h of v){let d=new Event("input",{bubbles:!0});e.ours.add(d),h.dispatchEvent(d)}qi(e,b,Boolean(t))}var et;function tt(e){et=e}var or=1,Gi="phlex-reactive:persist:",Ki=new Set(["hidden","file","password","submit","button","reset","image"]),nt=Symbol("persist-no-value"),rt="data-reactive-persist-state",Yi=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Vi=new Set(["lexxy-editor","trix-editor"]),Xi="lexxy-editor, trix-editor, trix-toolbar",Zi=["lexxy:change","trix-change"],Qi=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),tr=new WeakSet,nr=new WeakSet,rr=new WeakSet;function ne(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let n=JSON.parse(t);if(n&&typeof n==="object"&&typeof n.key==="string"&&n.key!=="")return n}catch{}if(!tr.has(e))tr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function ot(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function it(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||nr.has(e))return;nr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function st(e){return Gi+e.key}function Ze(e,t){let n=ot();if(!n)return null;let r;try{r=n.getItem(st(t))}catch(c){return it(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==or)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return te(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 ir(e,t,{fields:n,state:r}){let o=ot();if(!o)return!1;let i={v:or,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(st(t),JSON.stringify(i)),!0}catch(a){return it(e,a),!1}}function te(e,t){e?.removeAttribute?.(rt);let n=ot();if(!n)return;try{n.removeItem(st(t))}catch(r){it(e,r)}}function at(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||Ki.has(i.type)||i.closest(Xi))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(Yi)){if(!o(i))continue;let a=es(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Vi.has(i.localName)?"editor":"contenteditable"})}return r}function sr(e){return e.hasAttribute("data-reactive-editable")?et.text(e):e.textContent??""}function es(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function ct(e){return typeof e.value==="string"}function ts(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Qi.has(e.value.trim())}function ns(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||rr.has(e))return;rr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function B(e){return e.tagName==="SELECT"&&e.multiple}function ar(e){let t=new Map;for(let{el:n,name:r}of e){if(n.type==="radio"||!String(r).endsWith("[]"))continue;t.set(r,(t.get(r)??0)+1)}return t}function cr(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return nt;return e[0]}function ur(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of at(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(ct(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=sr(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(B(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function rs(e,t,n){let r=t.restore==="always",o=at(e,t),i=ar(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&B(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||B(s))){if(l=cr(l,c,i),l===nt)continue}if((s.type==="checkbox"||B(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")lr(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&sr(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&o.some((p)=>p.kind==="native"&&p.el.type==="radio"&&p.name===c&&p.el.checked))continue;s.checked=s.value===String(l)}else if(s.type==="checkbox"&&Array.isArray(l)){if(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(B(s)){if(!r&&[...s.options].some((m)=>m.selected))continue;let p=new Set((Array.isArray(l)?l:[l]).map(String));for(let m of s.options)m.selected=p.has(m.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}os(e,t,n)}function lr(e,t,n,r,o){if(Array.isArray(r))return;if(!ct(t))return;if(!o&&!ts(t))return;try{t.value=String(r)}catch(i){ns(e,n,i)}}function os(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!ct(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=at(e,t),c=ar(s);for(let{el:u,name:l,kind:p}of s){if(p!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let m=cr(n[l],l,c);if(m===null||m===void 0||m===nt)continue;lr(e,u,l,m,i)}})}function is(e,t,n=!0){let r=ne(e);if(!r){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=Ze(e,r),i={...o?.state??{},...t},a=n?ur(e,r):o?.fields??{};if(ir(e,r,{fields:a,state:i}))e.setAttribute?.(rt,JSON.stringify(i))}function ss(e){let t=ne(e);if(t)te(e,t)}var Qe=new WeakMap;function ut(e,t,n,r){let o=e.element,i=ne(o);if(!i)return;if(r?.submitted)te(o,i);let a=Ze(o,i);if(a){if(rs(o,i,a.fields),a.state)o.setAttribute?.(rt,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let g=Ze(o,i);ir(o,i,{fields:ur(o,i),state:g?.state??null})},l=()=>{let g=Number(i.debounce)||0;if(g<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},g)},p=(g)=>{if(!g?.detail?.success)return;let b=g.target;if(b?.tagName!=="FORM"||typeof b.contains!=="function")return;if(!b.contains(o))return;c(),te(o,i)},m=["input",...Zi];for(let g of m)o.addEventListener?.(g,l);if(o.addEventListener?.("change",u),document.addEventListener?.("turbo:submit-end",p),Qe.set(e,()=>{if(s!==null)u();for(let g of m)o.removeEventListener?.(g,l);o.removeEventListener?.("change",u),document.removeEventListener?.("turbo:submit-end",p)}),r?.edited&&!r.submitted)u();for(let g of r?.ops??[])g(!0)}function lt(e){let t=Qe.get(e);Qe.delete(e),t?.()}function fr(e,t){let n=et?.waiting.get(e)?.persist;if(!n||!ne(e))return t(!0);(n.ops??=[]).push(t)}function ft(e,t){fr(e,(n)=>is(e,t,n))}function dt(e){fr(e,()=>ss(e))}var re=new WeakMap,pr=new WeakSet;function pt(e,t){let n=e.element,r=[],o=[],i=(u,l,p)=>{u.addEventListener?.(l,p),r.push(()=>u.removeEventListener?.(l,p))},a,s,c=()=>{if(!a&&(a=as(n,t))){let u=()=>oe(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")us(n,i)}if(!s&&(s=ls(n,t))){let u=()=>fs(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};re.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function mt(e){for(let t of re.get(e)?.[0]??[])t();re.delete(e)}function ht(e){re.get(e)?.[1]()}function as(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let n=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let r of n)if(t.owns(r))return!0;return!1}function oe(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,cs(i))}),n.querySelectorAll("[data-reactive-editable][name]").forEach((i)=>{if(t.owns(i))o(i,t.text(i)!==t.served(i))}),r>0)n.setAttribute("data-reactive-dirty",String(r));else n.removeAttribute("data-reactive-dirty")}function cs(e){if(e.type==="checkbox"||e.type==="radio")return e.checked!==e.defaultChecked;if(e.tag==="select"||e.options){let t=Array.from(e.options??[]),n=!e.multiple&&!(e.size>1),r=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(n?o===r:o.defaultSelected))}return e.value!==e.defaultValue}function mr(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function us(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;t(window,"beforeunload",(n)=>{if(mr(e)===0)return;return n.preventDefault(),n.returnValue="You have unsaved changes.",n.returnValue}),t(window,"turbo:before-visit",(n)=>{if(mr(e)===0||pr.has(n))return;if(pr.add(n),!(typeof window.confirm==="function"?window.confirm("You have unsaved changes. Leave anyway?"):!0))n.preventDefault?.()})}function ls(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let n=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let r of n)if(t.owns(r))return!0;return!1}function fs(e,t){let n=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!n;for(let r of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(r))r.hidden=!n}function vt(e){ds(e),ms(e)}function ds(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(gt);else setTimeout(gt,0);return}let r=async(o)=>{await n(o),gt()};r.__reactiveDismissWrapped=!0,t.render=r}function gt(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let n=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(n)||n<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),n)}}var ps=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),bt=Object.freeze(["fade","slide","scale","highlight","shake"]),yt="data-reactive-fx-pending",At=1000;function ms(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=ps[r?.getAttribute?.("action")];if(!o||bs())return;let i=hs(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await As(ie(r),i),await n(s)}:async(s)=>{let c=o==="enter"?ys(r):null;if(await n(s),o==="enter")vs(c,i);else br(ie(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function hs(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return gr(n,t);let o=(t==="enter"?gs(e):ie(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?gr(o,t):null}function ie(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function gs(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function gr(e,t){if(e.startsWith("[")){let r=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)r=o.map(String)}catch{}if(r)return{legs:r};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let n=e==="random"?bt[Math.floor(Math.random()*bt.length)]:e;if(!bt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function bs(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function ys(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(yt,"");return ie(e)}function vs(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${yt}]`)))n.removeAttribute(yt),br(n,t)}async function As(e,t){if(!e?.classList)return;if(t.legs){await yr(e,t.legs);return}e.classList.add(t.className);let n=wt(e);if(n<=0){e.classList.remove(t.className);return}await St(e,n),e.classList.remove(t.className)}function br(e,t){if(!e?.classList)return;if(t.legs){yr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=wt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;St(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function yr(e,t){let[n,r,o]=t.map(ws),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Ss(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=wt(e);if(a>0)await St(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function ws(e){return String(e??"").split(/\s+/).filter(Boolean)}function wt(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,At)}catch{return 0}}function St(e,t){return new Promise((n)=>{let r=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",r),e.removeEventListener?.("transitionend",r),n()};e.addEventListener?.("animationend",r),e.addEventListener?.("transitionend",r),setTimeout(r,Math.min(t+50,At))})}function Ss(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},At),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Es="phlex-reactive:latency",Et=!1;function wr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Sr(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Et=!1}function xt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:wr,disableLatencySim:Sr}}function kt(){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(!Et)Et=!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 Ar=new WeakMap;function Tt(e){let t=globalThis.document;if(!t)return!0;let n=Ar.get(t);if(!n)n=new Set,Ar.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function _t(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function Er(e,t,n,r){if(Tt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function Rt(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=_t(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}Er(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Lt(e){if(!Tt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function Ft(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(_t(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=_t(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}Er(t,o,`scoped to #${r?.id||"?"}`,i)}function Ot(e,t){let n=e.element?.id||"?";if(Tt(`no-binding|${t.type}|${n}`))return;console.warn(`[phlex-reactive] runOps on #${n} found no on_client binding matching a "${t.type}" event — nothing ran`)}function _s(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function Nt(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function se(e,t,n){e.streams=_s(t),e.tokenRefreshed=n!=null}var ae=new WeakMap;function Ct(e,t,n,r){let o=n&&typeof n==="object"?Ts(n):n;return o?xr(t,o,r,!1):[]}function Mt(e,t,n,r){if(!n)return null;let o=xr(t,n,r,!0);return o.length?o:null}function xr(e,t,n,r){let o=[];for(let i of kr(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(xs(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function kr(e,t,n){if(t.to==null)return n?[n]:[];let r=e.opTargets({to:t.to});if(r.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return r}function xs(e,t){let n=ae.get(t);if(n)n.count++;else ae.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()=>ks(t,e)}function ks(e,t){let n=ae.get(e);if(!n)return;if(--n.count>0)return;if(ae.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function Ts(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function Pt(e,t,n,r){if(!n?.hide)return null;let o=kr(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var le;function Dt(e){le=e}var _=new Map;function Fr(e,t){let n=!_.has(e);if(_.set(e,t),n)le.enter()}function fe(e){if(_.delete(e))le.exit()}var Rr=!1;function qt(e){Or();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){Cs(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;U(t,n)}function Or(){if(Rr||typeof document>"u"||!document.addEventListener)return;Rr=!0,document.addEventListener("turbo:before-stream-render",Ps,!0),document.addEventListener("turbo:before-stream-render",Rs)}function Rs(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(_.get(n)?.via==="stream")fe(n)}function U(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}jt(e),Pr(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Fr(e,r),Ms(e,r,t)}function Ls(e,t){if(typeof e!=="string"){let n={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)n.cache="no-store";return[e.src,n]}return[Is(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Ds()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Nr(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Cr(t))return{src:t};return console.error(Fs(t)),Os(t)||Ns(e)}function Fs(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Wt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function Os(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Wt()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Cr(r))return{src:r,fallback:!0}}function Ns(e){jt(e.id),Bt(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 Cr(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Wt()}/`)}catch{return!1}}function Wt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function Cs(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let r=t.getAttribute("data-reactive-defer-src");if(!r)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){U(e,i);return}console.error("[phlex-reactive] reactive:defer via=stream but <pgbus-stream-source> is not registered "+"and no fallback token was provided — is the pgbus client loaded on this page?");return}jt(e),Pr(n);let o=document.createElement("pgbus-stream-source");o.id=Mr(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Fr(e,{via:"stream"})}function Mr(e){return`reactive-defer-src-${e}`}async function Ms(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},qs()),o;try{le.count("defer"),o=await fetch(...Ls(n,t.abort.signal))}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),J(e,n);return}if(_.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),J(e,n,o.status);return}if(o.status===204){clearTimeout(r),Lr(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),J(e,n,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),J(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),J(e,n);return}if(clearTimeout(r),_.get(e)!==t)return;Lr(e),$s(a)}var It=null,Ps=(e)=>It?.push(e);function $s(e){let t=It=[];try{window.Turbo.renderStreamMessage(e)}finally{It=null}for(let n of t){if(n.defaultPrevented)continue;let r=n.detail,o=r.render;r.render=()=>{},new Promise((i)=>i(o(r.newStream))).catch(console.error)}}function jt(e){let t=_.get(e);if(!t)return;if(fe(e),t.via==="fetch")t.abort.abort();else document.getElementById(Mr(e))?.remove?.()}function Pr(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Bt(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Lr(e){fe(e);let t=document.getElementById(e);if(!t)return;Bt(t),t.removeAttribute("data-reactive-error")}function J(e,t,n){fe(e);let r=document.getElementById(e);if(!r)return;Bt(r),r.setAttribute("data-reactive-error","defer");let o=()=>{let i=document.getElementById(e);if(!i){console.warn("[phlex-reactive] defer retry() ignored — the target left the DOM");return}i.removeAttribute("data-reactive-error"),U(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function Is(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Ds(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function qs(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var $r="__materialize",ue=new WeakMap;function ce(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function Jt(e,t,n){Or();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>de(e),p=(d)=>{if(ce(r)==="visible"){if(!a)g()}else if(d){let y=r.getAttribute("data-reactive-lazy-on");if(s===y)return;m(),r.addEventListener?.(y,l),s=y}},m=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},g=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let d=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((y)=>{if(y.some((A)=>A.isIntersecting))l()},{rootMargin:d}),a.observe(r)},b=()=>{let d=ce(r)!==null,y=o;if(o=d,!d)return m();if(i)return;if(t.forgetToken(),!y)return l();p(!0)};if(ue.set(e,{load(){if(i)return;let d=Nr(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&Ws(r,t))return;let y=d?U(r.id,d):t.proceed(r,$r,"{}");if(!y)return;i=!0,m();let A=()=>{i=!1};return y.then(A,A),y},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);m()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&ce(r)===null)$t(r),c=(d)=>d.target===r&&$t(r),r.addEventListener?.("turbo:morph-element",c);if(r.getAttribute?.("data-reactive-token-value")==null&&r.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(d)=>{if(d.target!==r)return;if(!c)$t(r);b()},r.addEventListener?.("turbo:morph-element",u),n)return b();if(o=ce(r)!==null,o)p(!1)}function Ut(e){let t=ue.get(e);ue.delete(e),t?.off()}function de(e){return ue.get(e)?.load()}function Ws(e,t){return t.emit("reactive:before-dispatch",{action:$r,params:{},element:e},{cancelable:!0}).defaultPrevented}function $t(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Nr(e);if(t)U(e.id,t)}var Ht=new WeakMap,me=new WeakMap,f=null,R,Dr;function Yt(e,t){let n=e.element;me.set(n,t),Gr();let r=(i)=>Bs(i,t),o=(i)=>Gs(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),Ht.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function Vt(e){if(Ht.get(e)?.(),Ht.delete(e),me.delete(e.element),f&&he(f.origin)===e.element)pe()}var w=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),H=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},he=(e)=>e?.closest?.('[data-controller~="reactive"]'),Br=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==f?.row&&Br(t)===e),qr=(e)=>H(w(e,"-item"),null),zt=(e)=>w(e,"-disabled")==="true",js=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Jr=(e)=>{let t=w(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>w(n,"-group")===t&&!zt(n)&&me.has(he(n)))};function Ur(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Br(n);if(f||!r||!t.owns(r)||zt(r)||zt(n))return;if(he(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Bs(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Ur(e.target,t);if(!n)return;let r=w(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(d)=>d.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(d)=>{if(!a(d))return;if(f)return Gt(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return h();Us(n,t,d),Gt(d.clientX,d.clientY)},p=(d)=>f&&d.cancelable&&d.preventDefault(),m=(d)=>{if(!a(d))return;if(h(),f)Js(),Kt()},g=(d)=>{if(d.type==="pointercancel"&&!a(d))return;if(h(),f)pe()},v=[["pointermove",l],["pointerup",m],["pointercancel",g],["keydown",(d)=>d.key==="Escape"&&f&&(d.preventDefault(),g(d))],["touchmove",p,{passive:!1}]];for(let[d,y,A]of v)document.addEventListener(d,y,A);function h(){clearTimeout(u);for(let[d,y]of v)document.removeEventListener(d,y)}}function Js(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Us({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,f=Hr({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),f.dx=r.clientX-o.left,f.dy=r.clientY-o.top,f.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function Hr(e){let{row:t,origin:n,source:r}=e;return e.index=T(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),z(n,!0),e}var z=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function ge(e,t,n,r){if(t[n])t[n].before(r);else if(t.length)t.at(-1).after(r);else e.append(r)}function Gt(e,t){f.x=e,f.y=t,f.row.style.left=`${e-f.dx}px`,f.row.style.top=`${t-f.dy}px`;let n=Jr(f.origin).find((r)=>js(r,e,t));if(n)Hs(n,e,t);else if(f.source)Xt(null),f.placeholder.remove();zs(e,t)}function Xt(e){if(f.target!==f.origin)z(f.target,!1);f.target=e,z(e,!0)}function Hs(e,t,n){Xt(e);let r=T(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});ge(e,r,s<0?r.length:s,f.placeholder)}function zs(e,t){let n=f.target??f.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(f.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,f.wy=t<40?-12:t>window.innerHeight-40?12:0,(f.vy||f.wy)&&!f.raf){let i=()=>{if(!f||!(f.vy||f.wy))return f&&(f.raf=0);if((f.target??f.origin).scrollTop+=f.vy,f.wy)window.scrollBy(0,f.wy);Gt(f.x,f.y),f.raf=requestAnimationFrame(i)};f.raf=requestAnimationFrame(i)}}function Gs(e,t){let n=e.key;if(f?.keyboard){if(e.target!==f.row||f.core!==t)return;let o={" ":Kt,Enter:Kt,Escape:pe,Tab:pe,ArrowUp:()=>Wr(-1),ArrowDown:()=>Wr(1),ArrowLeft:()=>jr(-1),ArrowRight:()=>jr(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=Ur(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),f=Hr({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),ye("picked")}function Wr(e){let t=T(f.target),n=be()+e;if(n>=0&&n<=t.length)ge(f.target,t,n,f.row);zr()}function jr(e){let t=Jr(f.origin),n=t[t.indexOf(f.target)+e];if(n){let r=be();Xt(n),ge(n,T(n),r,f.row)}zr()}function zr(){f.row.focus?.(),ye("moved")}function be(){let e=T(f.target),t=f.keyboard?f.row:f.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function Gr(){if(!R?.isConnected)R=document.createElement("div"),R.setAttribute("aria-live","polite"),R.setAttribute("data-reactive-sortable-live",""),R.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(R);return R}function ye(e){let t=f.target??f.origin,n=(H(w(t,"-messages"),{})[e]??"").replaceAll("{position}",be()+1).replaceAll("{count}",T(t).length+1),r=Gr();r.textContent="",cancelAnimationFrame(Dr),Dr=requestAnimationFrame(()=>r.textContent=n)}function Kt(){let e=f,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?be():-1,c=a?qr(T(t)[s-1]):null;if(e.keyboard)ye("dropped");if(!r&&i)i.replaceWith(o);if(Yr(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?w(n,"-source"):w(n,"-name")??"list",l=H(w(t,"-from"),{})[u]??w(t),p={...H(w(t,"-params"),{}),item:qr(e.item),position:s,after:c,from:u},m=[];for(let b=t;b;b=b.parentElement)m.push(b);let g=me.get(he(t))?.proceed(t,l,JSON.stringify(p),H(w(t,"-busy")));if(r)return;Promise.resolve(g).then((b)=>Ks(b,m)||Kr(e))}function Ks(e,t){if(!e)return!1;let n=document.createElement("template");return n.innerHTML=e,[...n.content.querySelectorAll("turbo-stream")].some((r)=>/^(replace|update)$/.test(r.getAttribute("action"))&&Ys(r,t))}function Ys(e,t){let n=e.getAttribute("target");if(n)return t.some((o)=>o.id===n);let r=e.getAttribute("targets");try{return Boolean(r)&&t.some((o)=>o.matches(r))}catch{return!1}}function pe(){let e=f;if(e.keyboard)ye("cancelled");e.placeholder?.remove(),Yr(e),Kr(e)}function Kr({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(ge(t,T(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function Yr(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(f=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),z(n,!1),z(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var L=new Map,Xr=new WeakSet;function Zt(e,t){let n=e.element,r=L.get(n.id);if(!r)L.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Vs(n);let o=(a)=>a.target===n&&queueMicrotask(()=>Qr(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},Qr(r)}function Qt(e){let t=e.element,n=L.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;L.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function en(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=L.get(e.id);if(!n)L.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},eo(n)}function Vs(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&Xr.has(n))return;if(n?.remove(),!Zr())setTimeout(()=>{if(!Zr())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=L.get(e.id);if(!o||o.removing)return;eo(o),Xs(o)}),Xr.add(r),document.body.appendChild(r)}var Zr=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Xs(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&to(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function eo(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function to(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function Qr(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=to(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}function Qs(){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 ea(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),n=this.getAttribute("target");if(!t||!n)return;let r=document.getElementById(n);if(r)r.setAttribute("data-reactive-token-value",t)}}function ta(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Sn(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)Lt(n);return}pn(t,(i)=>ja(i,o),r?(i,a)=>Rt(i,a,o):void 0)}}function na(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){qt(this)}}var oo=!1,ra=null;function oa(){if(oo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;oo=!0,document.addEventListener("turbo:before-stream-render",(e)=>{ha(e),ia(e),aa(e),vt(e)})}var Ae="reactive:streamed";function ia(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(Ae))}}function mn(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function hn(e){try{return e.matches(":modal")}catch{return!1}}function Oo(e){if(!mn(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||hn(e))return;if(e.open)e.close();e.showModal()}function sa(e){if(mn(e)&&e.open)e.close()}function _e(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!hn(r))Oo(r)}function aa(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target;if(typeof n!=="function"||!r?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(o)=>{await n(o),_e(document)}}var io=!1;function ca(){if(io)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;io=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))_e(t.target)}),document.addEventListener("turbo:morph",()=>_e(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!mn(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!hn(n))return;e.delete(n),t.preventDefault(),n.close()})}var dn=new WeakMap;function No(e,t,n,r){let o=dn.get(e)??new Map;dn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))Jo(n.name)||i(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(i("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))No(a,"set_attr",{name:"aria-expanded"})}}var so=!1;function ua(){if(so)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;so=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of dn.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}function ac(e){ra=e}var ve,tn=null,ao="[data-reactive-editable][contenteditable=plaintext-only]";function Co(){if(ve===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",ve=e.contentEditable==="plaintext-only"}catch{ve=!1}return ve}function we(e){if(e.matches?.(ao))e.setAttribute("contenteditable","true");e.querySelectorAll?.(ao).forEach(we)}function la(){if(tn||typeof document>"u"||typeof document.createElement!=="function")return;if(Co())return;we(document),tn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")we(t.target);else t.addedNodes.forEach(we)}),tn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var co=!1;function uo(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea"||e.hasAttribute("data-reactive-editable"))&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function fa(){if(co)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;co=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=uo(t);if(r)pa(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(xe.set(t,F(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==S)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>An(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===S)&&uo(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(S)&&bn(t)===yn(t))t.removeAttribute(S)})}var S="data-reactive-held",gn='[data-controller~="reactive"]',Se=null,P=new Map;function bn(e){return e.hasAttribute("data-reactive-editable")?F(e):e.value}function yn(e){return e.hasAttribute("data-reactive-editable")?wn(e):e.defaultValue}function da(e){if(e.hasAttribute("data-reactive-editable"))return F(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function pa(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||P.has(e.closest(gn)))return;let r=da(t);if(r===bn(e))return e.removeAttribute(S);if(r===yn(e))return;e.setAttribute(S,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function ma(e){let t=[];for(let n of e.querySelectorAll(`[${S}]`)){if(n.closest(gn)!==e)continue;let r=n.getAttribute("name");if(bn(n)===yn(n))n.removeAttribute(S);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Mo(e){for(let t of e.querySelectorAll(`[${S}]`))if(t.closest(gn)===e)t.removeAttribute(S)}function lo(e,t,n=!0){let r={root:e,streams:0,release:n},o=Se;Se=r;try{window.Turbo.renderStreamMessage(t)}finally{Se=o}if(n&&r.streams===0)Mo(e)}function ha(e){let t=Se,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{P.set(t.root,(P.get(t.root)||0)+1);try{return await r(o)}finally{let i=P.get(t.root)-1;if(i)P.set(t.root,i);else P.delete(t.root);if(t.release)Mo(t.root)}}}var ga="__materialize",fo=!1;function ba(){if(fo)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;fo=!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 vn(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")xt()}var Po="data-reactive-active",x=0;function $o(){if(x++,x===1)Do("reactive:busy")}function Io(){if(x===0)return;if(x--,x===0)Do("reactive:idle")}function cc(){return x}function uc(){x=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(Po)}function Do(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(Po,x>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:x}}))}var qo="data-reactive-requests";function Wo(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!ya(t))return;let n=va(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(qo,JSON.stringify(n))}function ya(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function va(e){try{let t=JSON.parse(e.getAttribute(qo));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function po(){Qs(),ea(),ta(),na(),oa(),fa(),ca(),ua(),la(),ba(),vn()}function Aa(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var jo=Symbol.for("phlex-reactive.core");if(globalThis[jo])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[jo]=!0;var Bo=!1;function wa(){if(Bo)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(wa,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Sa=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Jo(e){let t=String(e).toLowerCase();return t.startsWith("on")||Sa.has(t)}var nn=new WeakMap;function Ea(e,t,n){let[r,o,i]=t;nn.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,nn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};nn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,_a(e))}function _a(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var xa=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",ka=new Set(["lexxy-editor","trix-editor"]);function F(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as Fa}from"@hotwired/stimulus";import{confirmResolver as xo}from"phlex/reactive/confirm";import{confirmPredicate as Si}from"phlex/reactive/confirm_predicate";var M=new WeakMap,$e=new WeakMap;function k(e,t){let n=M.get(e);if(!n){if(M.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)$e.set(n.root,n)}return n}function S(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function I(e,t){S(e,"turbo:morph-element",t),e.seeds.push(t),t()}function Pe(e,t){let n=k(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&Ti(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")Di(n,s.target);else n.groups=Pi(n),zn(n);Bn(n)},S(n,"input change",n.show),S(n,"focusout",(s)=>{let c=s.target?.getAttribute?.("name");if(!c||n.touched?.has(c)||!n.core.owns(s.target))return;if((n.touched??=new Set).add(c),n.root.querySelector?.("[data-reactive-show-after]"))Bn(n)}),I(n,n.show);if(!n.arm&&Li(n))S(n,"input change",(s)=>jn(n,s)),I(n,n.arm=()=>{jn(n,null),zn(n)});if(!r&&(r=n.show||n.arm))S(n,"reset",()=>setTimeout(()=>{if(M.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=ee(n)))S(n,"input",(s)=>ji(n,s)&&D(n)),I(n,()=>D(n));if(!i&&(i=ne(n)))I(n,()=>or(n));if(!a&&(a=Bi(n)))S(n,"input change",(s)=>cr(n,s)),I(n,()=>ze(n))})(),S(n,"keydown",(s)=>os(n,s)),S(n,"paste drop",(s)=>is(n,s)),S(n,"input",(s)=>ss(n,s))}function Ie(e){let t=M.get(e);if(!t)return;M.delete(e),$e.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function De(e){let t=M.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function L(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function qe(e,t,n){return cr(k(e,t),n)}function We(e,t,n){return pr(k(e,t),n)}var Ei=/^#[A-Za-z_][\w-]*$/,Kn="[data-reactive-show-field], [data-reactive-show]";function _i(e,t){let n=e.getAttribute("data-reactive-show-equals");if(n!==null)return t===n;let r=e.getAttribute("data-reactive-show-not");if(r!==null)return t!==r;let o=e.getAttribute("data-reactive-show-in");if(o!==null){try{let i=JSON.parse(o);if(Array.isArray(i))return i.includes(t)}catch{}return console.warn(`[phlex-reactive] malformed reactive_show in: list ${JSON.stringify(o)} — skipped`),null}for(let i of ur){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return fr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Yn(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 xi(e){try{let t=JSON.parse(e);if(Array.isArray(t)&&t.every((n)=>n&&typeof n==="object"&&Array.isArray(n.any)&&Array.isArray(n.ops)))return t}catch{}return console.warn(`[phlex-reactive] malformed reactive_on_complete payload ${JSON.stringify(e)} — skipped`),[]}function Vn(e,t){if(!e||typeof e!=="object")return null;let n=e.any;if(Array.isArray(n)&&(n.length===0||Array.isArray(n[0])))return q(n,t);return ki(e,t)}function ki(e,t){let n=Array.isArray(e.all)?"all":Array.isArray(e.any)?"any":null;if(!n)return null;let r=e[n];if(r.length===0)return null;let o=r.map((i)=>Ze(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function Q(e,t="show"){if(typeof e==="string"&&Ei.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Ti(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?.(Kn)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(te)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(er)??[])if(e.core.owns(n))return!0;return!1}function Li(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function Ri(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:xi(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function jn(e,t){let n=Ri(e);if(!n.length)return;let r=Qn(e,e.core.ownership());n.forEach((o,i)=>{let a=q(o.any,r);if(a===null)return;let s=a&&!e.onCompleteStates[i]&&Boolean(t);if(e.onCompleteStates[i]=a,s)e.core.applyOps(o.ops,"@root")})}function Bn(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=Qn(e,t),o=[];for(let i of e.root.querySelectorAll(Kn)){if(!t(i))continue;let a=i.getAttribute("data-reactive-show");if(a!==null){let l=Vn(Yn(a),r);if(l===null)continue;let f=i.getAttribute("data-reactive-show-after"),p=l&&(f==null||!!e.touched?.has(je(f,n)));Jn(i,p,t,n);let b=(e.shown??=new WeakMap).get(i);if(e.shown.set(i,p),Oi.some((v)=>i.hasAttribute(`data-reactive-show-${v}`))&&b!==void 0&&b!==p)o.push(i);continue}let s=i.getAttribute("data-reactive-show-field");if(!s)continue;let c=r(s);if(c===null)continue;let u=_i(i,c);if(u===null)continue;Jn(i,u,t,n)}if(e.groups)qi(e,r,t,n);$i(e,r,t),Ni(e,r),Wi(e,r);for(let i of o)Fi(e,i,t,n)}var Oi=["clear","focus","scroll"];function Fi(e,t,n,r){if(t.hidden){let s=[];try{s=JSON.parse(t.getAttribute("data-reactive-show-clear")??"[]")}catch{}let c=new Set((Array.isArray(s)?s:[]).map((u)=>je(String(u),r)));for(let u of c.size?e.root.querySelectorAll("[name]"):[]){if(!c.has(u.getAttribute("name"))||!n(u)||u.type==="file")continue;if(u.type==="checkbox"||u.type==="radio"){if(u.checked)u.checked=!1,L(u)}else e.core.setValue(u,"")}return}let o=t.getAttribute("data-reactive-show-scroll")==="true";if(o)t.scrollIntoView?.({block:"nearest"});let i=t.getAttribute("data-reactive-show-focus"),a=null;try{a=i?e.root.querySelector(i):null}catch{}a?.focus?.(o?{preventScroll:!0}:void 0)}function Jn(e,t,n,r){if(e.hidden=!t,e.getAttribute("data-reactive-show-disable")!=="true")return;if(typeof e.querySelectorAll!=="function")return;for(let o of e.querySelectorAll("input[name], select[name], textarea[name]"))if(n(o))o.disabled=!t;if(e.name&&n(e))e.disabled=!t}function Ni(e,t){let n=Xn(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){Ci(r,o,t);continue}if(!o||typeof o!=="object"||Array.isArray(o))continue;let i=t(r);if(i===null)continue;let a=(s,c)=>c?t(r,!0):i;for(let[s,c]of Object.entries(o)){if(!Q(s))continue;let u;if(Array.isArray(c)){if(c.length===0){console.warn(`[phlex-reactive] malformed reactive_show_targets group for ${s} — skipped`);continue}u=c.every((l)=>Ze(l,a))}else{let l=dr(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 Ci(e,t,n){if(!Q(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=ns(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!rs(r))return;let i=q(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function Xn(e,t="show",n="mode: { ... }, kind: { ... }"){let r=e.root.getAttribute?.(`data-reactive-${t}-targets`);if(!r)return{};try{let o=JSON.parse(r);if(o&&typeof o==="object"&&!Array.isArray(o))return o}catch{}return console.warn(`[phlex-reactive] malformed data-reactive-${t}-targets — ignored. `+`Did two reactive_${t}_targets calls collide on one root? Declare every entry in ONE call: reactive_${t}_targets(${n})`),{}}function Mi(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(Zn(t,r))){if(!n(a))continue;if(a.type==="checkbox")return a.checked?"true":"false";if(a.type==="radio"){if(a.checked)return a.value??"";o=!0;continue}i??=a}if(i)return i.value??"";return o?"":null}function Zn(e,t){return`[name="${je(e,t)}"]`}function je(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Qn(e,t){let n=e.root.getAttribute?.("data-reactive-scope")||null,r=new Map;return(o,i)=>{let a=i?`#${o}`:o;if(!r.has(a))r.set(a,i?Be(e,o,t,n).filter((s)=>s.checked).length:Mi(e,o,t,n));return r.get(a)}}var er="[data-reactive-media]";function $i(e,t,n){for(let r of e.root.querySelectorAll(er)){if(!n(r))continue;let o,i,a;try{if(o=JSON.parse(r.getAttribute("data-reactive-media")),o?.match!=null)i=new RegExp(`^(?:${o.match})$`);if(o?.when!=null)a=new RegExp(`^(?:${o.when})$`)}catch{}if(typeof o?.field!=="string"||!o.pool||typeof o.pool!=="object"||o.match!=null&&!i||o.when!=null&&!a){console.warn("[phlex-reactive] malformed data-reactive-media — skipped");continue}let s=t(o.field);if(s===null)continue;let c=o.take>0?[...s]:null,u=c?c.slice(0,o.take).join(""):s,l=c?.length<o.take||i?.test(u)===!1||a?.test(s)===!1;if(l&&o.pending==="keep"){Un(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?Hn(e,o.pool[u])[0]:null,p=e.core.copyMedia(r,f??null);if(p===null)continue;if(Un(r,l?"pending":p===!1?"miss":"hit"),typeof o.label!=="string")continue;let b=l?"":p===!1?String(o.blank??""):p;for(let g of Hn(e,o.label))if(g.textContent!==b)g.textContent=b}}function Un(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function Hn(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var te="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Pi(e){return!!e.root.querySelector?.(te)}function Be(e,t,n,r,o){return[...e.root.querySelectorAll(Zn(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Ii(i.getAttribute("data-reactive-group"),o)))}function Ii(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Di(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))tr(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function Je(e,t,n){if(!t)return;let r=$e.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};tr(r,t,n!==!1),r.show?.()}function tr(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=Be(e,t,e.core.ownership(),i,o).filter((s)=>s!==r&&s.checked!==n);for(let s of a)s.checked=n;e.flipping=!0;try{for(let s of a)for(let c of["input","change"])s.dispatchEvent?.(new Event(c,{bubbles:!0}))}finally{e.flipping=!1}}function qi(e,t,n,r){for(let o of e.root.querySelectorAll(te)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Vn(Yn(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=o.getAttribute("data-reactive-select-all-under"),u=Be(e,s,n,r,c).filter((f)=>f!==o),l=u.filter((f)=>f.checked).length;o.checked=l>0&&l===u.length,o.indeterminate=l>0&&l<u.length}}}function Wi(e,t){for(let[n,r]of Object.entries(Xn(e,"group",'"ids[]" => { ... }, "tags[]" => { ... }'))){if(!r||typeof r!=="object"||Array.isArray(r))continue;let o=String(t(n,!0));for(let a of Array.isArray(r.count)?r.count:[]){if(!Q(a,"group"))continue;for(let s of document.querySelectorAll(a))if(s.textContent!==o)s.textContent=o}let i=r.enable&&typeof r.enable==="object"?r.enable:{};for(let[a,s]of Object.entries(i)){if(!Q(a,"group"))continue;let c=q(s?.any,t);if(c===null){console.warn(`[phlex-reactive] malformed reactive_group_targets enable for ${a} — skipped`);continue}for(let u of document.querySelectorAll(a))u.disabled=!c}}}function zn(e){if(e.groupObserver||typeof MutationObserver!=="function")return;let t=(o)=>e.root.getAttribute?.(`data-reactive-${o}`)?.includes("checked_");if(!e.root.getAttribute?.("data-reactive-group-targets")&&!e.root.querySelector?.(`${te}, [data-reactive-show*=checked_]`)&&!t("show-targets")&&!t("on-complete"))return;let r=(o)=>o.nodeType===1&&(o.matches('input[type="checkbox"]')||!!o.querySelector('input[type="checkbox"]'));e.groupObserver=new MutationObserver((o)=>{if(!o.some((i)=>[...i.addedNodes,...i.removedNodes].some(r)))return;e.show?.(),e.arm?.()}),e.groupObserver.observe(e.root,{childList:!0,subtree:!0})}function ee(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function ji(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}function D(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.root.getAttribute("data-reactive-filter-input"),n=e.root.getAttribute("data-reactive-filter-option");if(!t||!n)return;let r=e.core.ownership(),o=[...e.root.querySelectorAll(t)].find(r);if(!o)return;let i=(o.value??"").trim().toLowerCase(),a=0;for(let u of e.root.querySelectorAll(n)){if(!r(u))continue;let l=(u.getAttribute("data-reactive-filter-text")??u.textContent??"").toLowerCase(),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(!r(u))continue;let l=[...u.querySelectorAll(n)].filter(r);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(r(u))u.hidden=a>0}}function ne(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Bi(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function Ue(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-tags-field");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function He(e){let t=new Set,n=[];for(let r of String(e.value??"").split(",")){let o=r.trim();if(o===""||t.has(o.toLowerCase()))continue;t.add(o.toLowerCase()),n.push(o)}return n}function nr(e,t){let n=Ue(e);if(!n)return!1;let r=He(n),o=new Set(r.map((a)=>a.toLowerCase())),i=!1;for(let a of t){let s=String(a??"").trim();if(s===""||o.has(s.toLowerCase()))continue;o.add(s.toLowerCase()),r.push(s),i=!0}if(i)rr(e,n,r);return i}function rr(e,t,n){t.value=n.join(","),L(t),or(e)}function Ji(e){if(typeof e.root?.querySelectorAll!=="function")return null;let t=e.root.getAttribute("data-reactive-filter-input");if(!t)return null;let n=e.core.ownership();return[...e.root.querySelectorAll(t)].find(n)??null}function or(e){let t=Ue(e);if(!t)return;let n=He(t),r=e.core.ownership();Ui(e,n,r),Hi(e,n,r)}function Ui(e,t,n){let r=[...e.root.querySelectorAll("[data-reactive-tags-list]")].find(n);if(!r)return;let i=[...e.root.querySelectorAll("[data-reactive-tags-template]")].find(n)?.content?.firstElementChild;if(!i){if(!e.tagsWarnedTemplate)console.warn("[phlex-reactive] reactive_tags: no chip <template data-reactive-tags-template> found in this root — "+"chips will not render (the hidden field still updates). Add a template with a [data-reactive-tag-text] node and a reactive_tags_remove button."),e.tagsWarnedTemplate=!0;return}while(r.firstChild)r.removeChild(r.firstChild);for(let a of t){let s=i.cloneNode(!0);s.setAttribute?.("data-reactive-tag",a);let c=s.matches?.("[data-reactive-tag-text]")?s:(s.querySelectorAll?.("[data-reactive-tag-text]")??[])[0];if(c)c.textContent=a;let u=[...s.querySelectorAll?.('[data-action*="reactive#tagsRemove"]')??[]];if(s.matches?.('[data-action*="reactive#tagsRemove"]'))u.push(s);for(let l of u)l.setAttribute?.("data-reactive-tag-param",a);r.appendChild(s)}}function Hi(e,t,n){let r=new Set(t.map((o)=>o.toLowerCase()));for(let o of e.root.querySelectorAll("[role=option]")){if(!n(o))continue;let i=o.getAttribute?.("data-reactive-tag-param");if(!i)continue;if(r.has(i.toLowerCase()))o.setAttribute("data-reactive-tags-selected","true"),o.hidden=!0,o.removeAttribute?.("data-reactive-highlighted");else if(o.hasAttribute?.("data-reactive-tags-selected")){if(o.removeAttribute("data-reactive-tags-selected"),!ee(e))o.hidden=!1}}if(ee(e))D(e)}function zi(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Gi(e,t){let n=[e,...e.querySelectorAll?.("*")??[]];for(let r of n)for(let o of["name","id","for"]){let i=r.getAttribute?.(o);if(i&&i.includes("NEW_ROW"))r.setAttribute?.(o,i.replaceAll("NEW_ROW",String(t)))}}function Ki(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 Yi(e,t,n,r){if(!n)return null;let o;try{o=JSON.parse(n)}catch{return null}if(!o||typeof o!=="object")return null;let i=e.core.ownership(),a=[...t.querySelectorAll?.("input, select, textarea")??[]],s=[];for(let[c,u]of Object.entries(o)){let l=[...e.root.querySelectorAll?.(u)??[]].find(i);if(!l)continue;let f=a.find((p)=>sr(p.getAttribute?.("name"))===c);if(!f)continue;Vi(f,l),s.push(l)}if(r)for(let c of s)Xi(c);return s[0]??null}function Vi(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Ce(t)!=="";else e.value=Ce(t);L(e)}function Xi(e){if(e.type==="checkbox")e.checked=!1;else e.value="";L(e)}function Zi(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Gn(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",L(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);ze(e)}function ze(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership();for(let n of[...e.root.querySelectorAll("[data-reactive-nested-json]")].filter(t))ar(e,n.getAttribute("data-reactive-nested-json"))}function Qi(e,t){let n=t.getAttribute?.("data-reactive-nested-json-field");if(!n)return null;let r=e.core.ownership();return[...e.root.querySelectorAll(n)].find(r)??null}function ir(e,t){let n={},r=e.core.ownership();for(let o of[...t.querySelectorAll?.("input, select, textarea")??[]]){if(o.matches(":disabled")||o.type==="radio"&&!o.checked||!r(o))continue;let i=sr(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Ce(o)}return n}function sr(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Ce(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function ar(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=Qi(e,r);if(!o)return;let i=[];for(let s of[...r.querySelectorAll?.("[data-reactive-nested-row]")??[]]){if(!n(s)||s.hidden)continue;i.push(ir(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,L(o)}function Ge(e,t,n){let r=k(e,t);if(!ne(r))return;if(n?.defaultPrevented)return;if(r.core.listnavOptions(n).some((a)=>a.hasAttribute?.("data-reactive-highlighted")))return;n?.preventDefault?.();let o=n?.currentTarget??n?.target;if(!o)return;if(!nr(r,String(o.value??"").split(",")))return;if(o.value="",ee(r))D(r)}function Ke(e,t,n){let r=k(e,t);if(!ne(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!nr(r,[i]))return;let a=Ji(r);if(!a)return;a.value="",D(r),a.focus?.()}function Ye(e,t,n){let r=k(e,t);if(!ne(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=Ue(r);if(!a)return;let s=He(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;rr(r,a,c)}function Ve(e,t,n){let r=k(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.getAttribute?.("data-reactive-association-param");if(!i)return;if(typeof r.root?.querySelectorAll!=="function")return;let a=r.core.ownership(),s=[...r.root.querySelectorAll(`[data-reactive-nested-list="${i}"]`)].find(a),u=[...r.root.querySelectorAll(`[data-reactive-nested-template="${i}"]`)].find(a)?.content?.firstElementChild;if(!s||!u){Ki(r,i);return}let l=u.cloneNode(!0);Gi(l,zi(r)),s.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),p=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",b=Yi(r,l,f,p);if(f)b?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)ar(r,i)}function Xe(e,t,n){let r=k(e,t);n?.preventDefault?.();let o=n?.currentTarget??n?.target,i=o?.closest?.("[data-reactive-nested-row]");if(!i)return;if(i.closest?.('[data-controller~="reactive"]')!==r.root)return;let a=o?.getAttribute?.("data-reactive-confirm-param"),s=o?.getAttribute?.("data-reactive-confirm-when-param"),c=a||(s?pr(r,s):null);if(!c)return Gn(r,i);let u=ir(r,i),l=Zi(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Gn(r,i)})}function cr(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;ze(e)}var ur=["gte","gt","lte","lt"],es=["len_eq","len_gte","len_gt","len_lte","len_lt"],lr=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],ts=["digits_eq","digits_gte","digits_lt","digits_lte"];function Me(e,t,n){if(!Number.isInteger(t))return console.warn(`[phlex-reactive] reactive_show ${e}: needs an integer literal, got ${JSON.stringify(t)} — skipped`),null;switch(e.slice(e.indexOf("_")+1)){case"eq":return n===t;case"gte":return n>=t;case"gt":return n>t;case"lte":return n<=t;case"lt":return n<t;default:return null}}function fr(e,t,n){let r=Number(t);if(Number.isNaN(r))return console.warn(`[phlex-reactive] reactive_show ${e}: needs a numeric literal, got ${JSON.stringify(t)} — skipped`),null;let o=n==null?"":String(n).trim(),i=o===""?NaN:Number(o);if(Number.isNaN(i))return!1;switch(e){case"gte":return i>=r;case"gt":return i>r;case"lte":return i<=r;case"lt":return i<r;default:return null}}function dr(e,t){if(!e||typeof e!=="object")return null;if(typeof e.equals==="string")return t===e.equals;if(typeof e.not==="string")return t!==e.not;if(Array.isArray(e.in))return e.in.includes(t);for(let n of ur)if(n in e)return fr(n,e[n],t);for(let n of es)if(n in e)return Me(n,e[n],[...String(t??"")].length);return null}function Ze(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=lr.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Me(n,e[n],Array.isArray(i)?i.length:Number(i)||0)===!0}if(typeof e.same==="string"){let i=(a)=>{let s=String(t(a)??"");return e.fold===!0?s.replace(/[A-Z]/g,(c)=>String.fromCharCode(c.charCodeAt(0)+32)):s};return i(e.field)===i(e.same)!==(e.negate===!0)}let r=ts.filter((i)=>(i in e));if(r.length){let i=String(t(e.field)??"");if(!r.every((s)=>Number.isInteger(e[s]))||e.prefix!=null&&typeof e.prefix!=="string")return!1;return(/^[0-9]*$/.test(i)&&r.every((s)=>Me(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return dr(e,o)===!0}function q(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>Ze(r,t)))}function ns(e){if(!Array.isArray(e)||e.length===0)return null;let t=new Set;for(let n of e){if(!Array.isArray(n))continue;for(let r of n){if(r&&typeof r==="object"&&typeof r.field==="string")t.add(r.field);if(typeof r?.same==="string")t.add(r.same)}}return t.size>0?[...t]:null}function rs(e){return e.flat().every((t)=>lr.some((n)=>(n in Object(t))))}function pr(e,t){let n=t;if(typeof t==="string")try{n=JSON.parse(t)}catch{return console.warn(`[phlex-reactive] malformed conditional confirm payload ${JSON.stringify(t)} — skipped`),null}if(!n||typeof n!=="object")return null;let{fields:r}=e.core.collectFields(),o=(a)=>r[a],i;if(typeof n.predicate==="string"){let a=Si(n.predicate);if(!a)return console.warn(`[phlex-reactive] confirm predicate "${n.predicate}" is not registered — proceeding without a dialog (register it with setConfirmPredicate)`),null;i=!!a(r)}else i=q(n.groups?.any,o)===!0;return i?n.message:null}function Qe(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function os(e,t){let n=Qe(e,t);if(!n||t.isComposing||t.keyCode===229)return;if(t.key==="Enter"){let r=n.getAttribute("data-reactive-editable-enter");if(n.getAttribute("data-reactive-editable")==="multi"&&(r==null||t.shiftKey))return;if(t.preventDefault(),r==="submit")n.closest("form")?.requestSubmit();else if(r)e.core.applyOps(JSON.parse(r),"@root")}else if(t.key==="Escape"&&n.hasAttribute("data-reactive-editable-escape"))t.preventDefault(),n.textContent=e.core.served(n),L(n),n.blur()}function is(e,t){let n=Qe(e,t),r=n?.getAttribute("data-reactive-editable")!=="multi",o=(t.clipboardData??t.dataTransfer)?.getData("text/plain");if(!n||o==null||e.core.plain()&&!(r&&/[\r\n]/.test(o)))return;if(t.preventDefault(),r)o=o.replace(/\r?\n|\r/g," ");n.focus(),document.execCommand("insertText",!1,o)}function ss(e,t){let n=Qe(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as as}from"phlex/reactive/compute";var j=new WeakMap;function br(e,t){let n=j.get(e);if(!n)j.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function tt(e,t,n,r){let o=br(e,t),i=Ss(o);if(i)o.seed=()=>et(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)et(o)}function nt(e){let t=j.get(e);if(!t)return;if(j.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function rt(e){j.get(e)?.seed?.()}function ot(e,t,n){return et(br(e,t),n)}var cs=Object.freeze({el:null,kind:""}),us=/^#[A-Za-z_][\w-]*$/;function W({el:e,kind:t}){if(!e)return"";if(t==="checkbox")return e.checked?"true":"false";if(t==="radio")return e.checked?e.value??"":"";return e.value??""}function vr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function ls(e,t){if(t==="string")return W(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):vr(W(e));if(n)return e.el.checked?1:0;let r=Number(W(e));return Number.isFinite(r)?r:0}function fs(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=vr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return ds(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function ds(e,t,n,r){let o=null;for(let i of e.querySelectorAll(`[name="${n}"]`)){if(i.type!=="radio"||!t(i))continue;let a=i.value===r;if(Boolean(i.checked)===a)continue;if(i.checked=a,a)o=i;else o??=i}return o}function ps(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 ms(e){if(typeof e==="string"&&us.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function hs(e,t,n){let r=t===null?null:JSON.stringify(t),o=r!==null&&r!==e.opsSig&&n;if(e.opsSig=r,!o)return;e.core.applyOps(t,"@root")}function gs(e,t){let n=e.root.getAttribute(t);if(!n)return[];try{let r=JSON.parse(n);return Array.isArray(r)?r:[]}catch{return[]}}function bs(e){let t=e.root.getAttribute("data-reactive-compute-inputs-param");if(!t)return[];try{let n=JSON.parse(t);if(Array.isArray(n))return n.map((r)=>[r,"number"]);if(n&&typeof n==="object")return Object.entries(n);return[]}catch{return[]}}function vs(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=ys(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function ys(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function hr(e,t,n){let r=String(n);for(let o of As(e,t)){if(o.textContent===r)continue;o.textContent=r}}function As(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function gr(e,t,n){let r=ws(e);for(let[o,i]of Object.entries(r)){let a=o in t?null:n(o),s=o in t?t[o]:a.el?W(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!ms(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function ws(e){let t=e.root.getAttribute("data-reactive-compute-mirror-param");if(!t)return{};try{let n=JSON.parse(t);return n&&typeof n==="object"&&!Array.isArray(n)?n:{}}catch{return{}}}function Ss(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function et(e,t){if(t&&e.ours.has(t))return;let n=bs(e),r=n.map(([h])=>h),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(h)=>o&&!h.includes("[")?`${o}[${h}]`:h,a=e.core.ownership(),s=new Map,c=(h)=>{let d=s.get(h);if(d)return d;let y=null,A=null,N=null;for(let C of e.root.querySelectorAll(`[name="${i(h)}"]`)){if(!a(C))continue;let Z=C.type;if(Z==="checkbox"||Z==="radio"&&C.checked){N={el:C,kind:Z};break}if(Z==="radio")y??=C;else A??=C}if(!N)if(y)N={el:y,kind:"radio"};else N=A?{el:A,kind:""}:cs;return s.set(h,N),N};for(let h of r)hr(e,h,W(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?as(u):null;if(!l){gr(e,{},c);return}let f=gs(e,"data-reactive-compute-outputs-param"),p={};for(let[h,d]of n)p[h]=ls(c(h),d);let b=l(p,{changed:vs(e,t,r,o)})||{},g=ps(b.$ops),v=[];for(let h of f){if(h==="$ops"||!(h in b))continue;let d=c(h);if(!d.el)continue;let y=fs(e.root,a,d,i(h),b[h]);if(y)v.push(y)}for(let h of Object.keys(b)){if(h==="$ops")continue;let d=b[h];if(d===void 0||d===null)continue;hr(e,h,d)}gr(e,b,c);for(let h of v){let d=new Event("input",{bubbles:!0});e.ours.add(d),h.dispatchEvent(d)}hs(e,g,Boolean(t))}var ct;function ut(e){ct=e}var Er=1,Es="phlex-reactive:persist:",_s=new Set(["hidden","file","password","submit","button","reset","image"]),lt=Symbol("persist-no-value"),ft="data-reactive-persist-state",xs=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",ks=new Set(["lexxy-editor","trix-editor"]),Ts="lexxy-editor, trix-editor, trix-toolbar",Ls=["lexxy:change","trix-change"],Rs=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Ar=new WeakSet,wr=new WeakSet,Sr=new WeakSet;function oe(e){let t=e?.getAttribute?.("data-reactive-persist");if(!t||t==="off")return null;try{let n=JSON.parse(t);if(n&&typeof n==="object"&&typeof n.key==="string"&&n.key!=="")return n}catch{}if(!Ar.has(e))Ar.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function dt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function pt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||wr.has(e))return;wr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function mt(e){return Es+e.key}function st(e,t){let n=dt(t);if(!n)return null;let r;try{r=n.getItem(mt(t))}catch(c){return pt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Er)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return re(e,t),null;let a=o.fields&&typeof o.fields==="object"?o.fields:{},s=o.state&&typeof o.state==="object"?o.state:null;return{fields:a,state:s}}function _r(e,t,{fields:n,state:r}){let o=dt(t);if(!o)return!1;let i={v:Er,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(mt(t),JSON.stringify(i)),!0}catch(a){return pt(e,a),!1}}function re(e,t){e?.removeAttribute?.(ft);let n=dt(t);if(!n)return;try{n.removeItem(mt(t))}catch(r){pt(e,r)}}function ht(e,t){let n=Array.isArray(t.fields)?new Set(t.fields):null,r=[],o=(i)=>i.closest('[data-controller~="reactive"]')===e&&i.getAttribute("data-reactive-persist")!=="off";for(let i of e.querySelectorAll("input[name], select[name], textarea[name]")){if(!o(i)||_s.has(i.type)||i.closest(Ts))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(xs)){if(!o(i))continue;let a=Os(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:ks.has(i.localName)?"editor":"contenteditable"})}return r}function xr(e){return e.hasAttribute("data-reactive-editable")?ct.text(e):e.textContent??""}function Os(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function gt(e){return typeof e.value==="string"}function Fs(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return Rs.has(e.value.trim())}function Ns(e,t,n){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)} — ${n?.message??n}`)}function B(e){return e.tagName==="SELECT"&&e.multiple}function kr(e){let t=new Map;for(let{el:n,name:r}of e){if(n.type==="radio"||!String(r).endsWith("[]"))continue;t.set(r,(t.get(r)??0)+1)}return t}function Tr(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return lt;return e[0]}function Lr(e,t){let n={},r=(o)=>{let i=n[o];return Array.isArray(i)?i:n[o]=[]};for(let{el:o,name:i,kind:a}of ht(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(gt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=xr(o);if(s)r(i).push(c);else n[i]=c}else if(o.type==="radio"){if(o.checked)n[i]=o.value;else if(!Object.hasOwn(n,i))n[i]=null}else if(o.type==="checkbox")if(s){let c=r(i);if(o.checked)c.push(o.value)}else n[i]=o.checked;else if(B(o)){let c=[...o.options].filter((u)=>u.selected).map((u)=>u.value);if(s)r(i).push(...c);else n[i]=c}else if(s)r(i).push(o.value);else n[i]=o.value}return n}function Cs(e,t,n){let r=t.restore==="always",o=ht(e,t),i=kr(o),a=new Set;for(let s of o)if(s.kind==="native"&&s.el.type==="checkbox"&&s.el.checked)a.add(s.name);for(let{el:s,name:c,kind:u}of o){if(!Object.hasOwn(n,c))continue;let l=n[c];if(l===null||l===void 0)continue;if(Array.isArray(l)&&B(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||B(s))){if(l=Tr(l,c,i),l===lt)continue}if((s.type==="checkbox"||B(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")Rr(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&xr(s).trim()!=="")continue;s.textContent=String(l)}else if(s.type==="radio"){if(!r&&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(!r&&a.has(c))continue;s.checked=l.map(String).includes(s.value)}else if(s.type==="checkbox"){if(!r&&s.checked)continue;s.checked=Boolean(l)}else if(B(s)){if(!r&&[...s.options].some((p)=>p.selected))continue;let f=new Set((Array.isArray(l)?l:[l]).map(String));for(let p of s.options)p.selected=f.has(p.value)}else{if(!r&&s.value!=="")continue;s.value=String(l)}}Ms(e,t,n)}function Rr(e,t,n,r,o){if(Array.isArray(r))return;if(!gt(t))return;if(!o&&!Fs(t))return;try{t.value=String(r)}catch(i){Ns(e,n,i)}}function Ms(e,t,n){let r=globalThis.customElements;if(typeof r?.whenDefined!=="function")return;let o=new Set;for(let a of e.querySelectorAll("lexxy-editor, trix-editor"))if(!gt(a)&&!r.get?.(a.localName))o.add(a.localName);let i=t.restore==="always";for(let a of o)r.whenDefined(a).then(()=>{if(!e.isConnected)return;let s=ht(e,t),c=kr(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let p=Tr(n[l],l,c);if(p===null||p===void 0||p===lt)continue;Rr(e,u,l,p,i)}})}function $s(e,t,n=!0){let r=oe(e);if(!r){console.warn("[phlex-reactive] persist_state on a root without reactive_persist — skipped");return}if(!t||typeof t!=="object")return;let o=st(e,r),i={...o?.state??{},...t},a=n?Lr(e,r):o?.fields??{};if(_r(e,r,{fields:a,state:i}))e.setAttribute?.(ft,JSON.stringify(i))}function Ps(e){let t=oe(e);if(t)re(e,t)}var at=new WeakMap,it=new WeakMap;function Is(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=it.get(e);if(!n){let i=new Set,a=(s)=>{for(let c of i)c(s)};e.addEventListener("turbo:submit-end",a),n=[i,a],it.set(e,n)}let[r,o]=n;return r.add(t),()=>{if(r.delete(t),r.size>0)return;e.removeEventListener?.("turbo:submit-end",o),it.delete(e)}}function bt(e,t,n,r){let o=e.element,i=oe(o);if(!i)return;if(r?.submitted)re(o,i);let a=st(o,i);if(a){if(Cs(o,i,a.fields),a.state)o.setAttribute?.(ft,JSON.stringify(a.state));t.emit("reactive:persist-restored",{key:i.key,fields:a.fields,state:a.state??{}}),t.reseed()}let s=null,c=()=>{if(s!==null)clearTimeout(s),s=null},u=()=>{c();let g=st(o,i);_r(o,i,{fields:Lr(o,i),state:g?.state??null})},l=()=>{let g=Number(i.debounce)||0;if(g<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},g)},f=(g)=>{if(!g?.detail?.success)return;let v=g.target;if(v?.tagName!=="FORM"||typeof v.contains!=="function")return;if(!v.contains(o))return;c(),re(o,i)},p=["input",...Ls];for(let g of p)o.addEventListener?.(g,l);o.addEventListener?.("change",u);let b=Is(globalThis.document,f);if(at.set(e,()=>{if(s!==null)u();for(let g of p)o.removeEventListener?.(g,l);o.removeEventListener?.("change",u),b()}),r?.edited&&!r.submitted)u();for(let g of r?.ops??[])g(!0)}function vt(e){let t=at.get(e);at.delete(e),t?.()}function Or(e,t){let n=ct?.waiting.get(e)?.persist;if(!n||!oe(e))return t(!0);(n.ops??=[]).push(t)}function yt(e,t){Or(e,(n)=>$s(e,t,n))}function At(e){Or(e,()=>Ps(e))}var ie=new WeakMap,Nr=new WeakSet,wt=new WeakMap;function St(e,t){let n=e.element,r=[],o=[],i=(u,l,f)=>{u.addEventListener?.(l,f),r.push(()=>u.removeEventListener?.(l,f))},a,s,c=()=>{if(!a&&(a=Ds(n,t))){let u=()=>se(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")js(n,r)}if(!s&&(s=Bs(n,t))){let u=()=>Js(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};ie.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function Et(e){for(let t of ie.get(e)?.[0]??[])t();ie.delete(e)}function _t(e){ie.get(e)?.[1]()}function Ds(e,t){if((e.getAttribute?.("data-action")??"").includes("reactive#trackDirty"))return!0;let n=e.querySelectorAll?.('[data-action*="reactive#trackDirty"]')??[];for(let r of n)if(t.owns(r))return!0;return!1}function se(e,t){let n=e.element;if(typeof n?.querySelectorAll!=="function")return;let r=0,o=(i,a)=>{if(a)i.setAttribute("data-reactive-dirty","true"),r++;else i.removeAttribute("data-reactive-dirty")};if(n.querySelectorAll("input[name], select[name], textarea[name]").forEach((i)=>{if(!t.owns(i))return;if(i.type==="file")return;o(i,qs(i))}),n.querySelectorAll("[data-reactive-editable][name]").forEach((i)=>{if(t.owns(i))o(i,t.text(i)!==t.served(i))}),r>0)n.setAttribute("data-reactive-dirty",String(r));else n.removeAttribute("data-reactive-dirty")}function qs(e){if(e.type==="checkbox"||e.type==="radio")return e.checked!==e.defaultChecked;if(e.tag==="select"||e.options){let t=Array.from(e.options??[]),n=!e.multiple&&!(e.size>1),r=t.filter((o)=>o.defaultSelected).pop()??t.find((o)=>!o.closest?.("optgroup")?.disabled&&!o.disabled);return t.some((o)=>o.selected!==(n?o===r:o.defaultSelected))}return e.value!==e.defaultValue}function Ws(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function js(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=wt.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(Ws(c)>0)return c;return null},a=(c)=>{if(!i())return;return c.preventDefault(),c.returnValue="You have unsaved changes.",c.returnValue},s=(c)=>{if(Nr.has(c)||!i())return;if(Nr.add(c),!(typeof n.confirm==="function"?n.confirm("You have unsaved changes. Leave anyway?"):!0))c.preventDefault?.()};n.addEventListener("beforeunload",a),n.addEventListener("turbo:before-visit",s),r={roots:o,remove:()=>{n.removeEventListener?.("beforeunload",a),n.removeEventListener?.("turbo:before-visit",s),wt.delete(n)}},wt.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Bs(e,t){if(e.getAttribute?.("data-reactive-clipboard"))return!0;let n=e.querySelectorAll?.("[data-reactive-clipboard]")??[];for(let r of n)if(t.owns(r))return!0;return!1}function Js(e,t){let n=typeof globalThis.navigator?.clipboard?.readText==="function";if(e.getAttribute?.("data-reactive-clipboard"))e.hidden=!n;for(let r of e.querySelectorAll?.("[data-reactive-clipboard]")??[])if(t.owns(r))r.hidden=!n}function Lt(e){Us(e),zs(e)}function Us(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(xt);else setTimeout(xt,0);return}let r=async(o)=>{await n(o),xt()};r.__reactiveDismissWrapped=!0,t.render=r}function xt(){let e=document.querySelectorAll("[data-reactive-dismiss-after]");for(let t of e){if(t.hasAttribute("data-reactive-dismiss-scheduled"))continue;let n=Number(t.getAttribute("data-reactive-dismiss-after"));if(!Number.isFinite(n)||n<=0)continue;t.setAttribute("data-reactive-dismiss-scheduled",""),setTimeout(()=>t.remove(),n)}}var Hs=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),kt=Object.freeze(["fade","slide","scale","highlight","shake"]),Tt="data-reactive-fx-pending",Rt=1000;function zs(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Hs[r?.getAttribute?.("action")];if(!o||Ys())return;let i=Gs(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await Zs(ae(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Vs(r):null;if(await n(s),o==="enter")Xs(c,i);else $r(ae(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Gs(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return Mr(n,t);let o=(t==="enter"?Ks(e):ae(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?Mr(o,t):null}function ae(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Ks(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function Mr(e,t){if(e.startsWith("[")){let r=null;try{let o=JSON.parse(e);if(Array.isArray(o)&&o.length===3)r=o.map(String)}catch{}if(r)return{legs:r};return console.warn(`[phlex-reactive] malformed effect legs ${JSON.stringify(e)} — skipped`),null}let n=e==="random"?kt[Math.floor(Math.random()*kt.length)]:e;if(!kt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Ys(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Vs(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Tt,"");return ae(e)}function Xs(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Tt}]`)))n.removeAttribute(Tt),$r(n,t)}async function Zs(e,t){if(!e?.classList)return;if(t.legs){await Pr(e,t.legs);return}e.classList.add(t.className);let n=Ot(e);if(n<=0){e.classList.remove(t.className);return}await Ft(e,n),e.classList.remove(t.className)}function $r(e,t){if(!e?.classList)return;if(t.legs){Pr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Ot(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ft(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function Pr(e,t){let[n,r,o]=t.map(Qs),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await ea(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Ot(e);if(a>0)await Ft(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function Qs(e){return String(e??"").split(/\s+/).filter(Boolean)}function Ot(e){if(typeof getComputedStyle!=="function")return 0;try{let t=getComputedStyle(e),n=(i)=>String(i??"").split(",").reduce((a,s)=>Math.max(a,parseFloat(s)||0),0),r=n(t.animationDuration)+n(t.animationDelay),o=n(t.transitionDuration)+n(t.transitionDelay);return Math.min(Math.max(r,o)*1000,Rt)}catch{return 0}}function Ft(e,t){return new Promise((n)=>{let r=(o)=>{if(o&&o.target!==e)return;e.removeEventListener?.("animationend",r),e.removeEventListener?.("transitionend",r),n()};e.addEventListener?.("animationend",r),e.addEventListener?.("transitionend",r),setTimeout(r,Math.min(t+50,Rt))})}function ea(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Rt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var ta="phlex-reactive:latency",Nt=!1;function qr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Wr(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Nt=!1}function Mt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:qr,disableLatencySim:Wr}}function $t(){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(!Nt)Nt=!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 Dr=new WeakMap;function Pt(e){let t=globalThis.document;if(!t)return!0;let n=Dr.get(t);if(!n)n=new Set,Dr.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Ct(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function jr(e,t,n,r){if(Pt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function It(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=Ct(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}jr(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Dt(e){if(!Pt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function qt(e,t,n){let r=e.element,o=n.to;if(typeof o!=="string"||o===""||o==="@root")return;let i="";if(!n.global)if(r?.matches?.(o))i=" — the selector matches this component's own root, which root-scoped resolution never includes; use to: :root";else if(Ct(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Ct(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}jr(t,o,`scoped to #${r?.id||"?"}`,i)}function Wt(e,t){let n=e.element?.id||"?";if(Pt(`no-binding|${t.type}|${n}`))return;console.warn(`[phlex-reactive] runOps on #${n} found no on_client binding matching a "${t.type}" event — nothing ran`)}function na(e){if(!e)return[];let t=[],n=/<turbo-stream\b([^>]*)>/g,r;while((r=n.exec(e))!==null){let o=r[1],i=o.match(/\baction="([^"]*)"/)?.[1]??"?",a=o.match(/\btarget="([^"]*)"/)?.[1];t.push(a?`${i} → #${a}`:i)}return t}function jt(e,t){let{action:n,status:r,ms:o}=t,i=e.element?.id,s=`reactive ${i?`#${i} `:""}${n} → ${r??"—"} (${Math.round(o)}ms)`;if(console.groupCollapsed(s),console.log(`params: [${t.paramNames.join(", ")}] + collected: [${t.fieldNames.join(", ")}]`),console.log(`encoding: ${t.encoding}`),t.streams.length)console.log(`streams: ${t.streams.join(" ")}`);console.log(`token: ${t.tokenRefreshed?"refreshed ✓":"unchanged"}`),console.groupEnd()}function ce(e,t,n){e.streams=na(t),e.tokenRefreshed=n!=null}var ue=new WeakMap;function Bt(e,t,n,r){let o=n&&typeof n==="object"?ia(n):n;return o?Jr(t,o,r,!1):[]}function Jt(e,t,n,r){if(!n)return null;let o=Jr(t,n,r,!0);return o.length?o:null}function Jr(e,t,n,r){let o=[];for(let i of Ur(e,t,n)){if(t.add_class){let a=t.add_class.filter((s)=>!i.classList.contains(s));if(i.classList.add(...a),a.length)o.push(()=>i.classList.remove(...a))}if(t.remove_class){let a=t.remove_class.filter((s)=>i.classList.contains(s));if(i.classList.remove(...a),a.length)o.push(()=>i.classList.add(...a))}if(t.toggle_class)t.toggle_class.forEach((a)=>i.classList.toggle(a)),o.push(()=>t.toggle_class.forEach((a)=>i.classList.toggle(a)));if(t.hide&&!i.hidden)i.hidden=!0,o.push(()=>i.hidden=!1);if(t.show&&i.hidden)i.hidden=!1,o.push(()=>i.hidden=!0)}if(n&&(t.disable||t.text!=null))o.push(ra(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function Ur(e,t,n){if(t.to==null)return n?[n]:[];let r=e.opTargets({to:t.to});if(r.length===0)e.diagnose("busy/optimistic hint",{to:t.to});return r}function ra(e,t){let n=ue.get(t);if(n)n.count++;else ue.set(t,{count:1,disabled:t.disabled,html:t.innerHTML,hadText:e.text!=null,swappedTo:e.text});if(e.disable)t.disabled=!0;if(e.text!=null)t.innerHTML=e.text;return()=>oa(t,e)}function oa(e,t){let n=ue.get(e);if(!n)return;if(--n.count>0)return;if(ue.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function ia(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function Ut(e,t,n,r){if(!n?.hide)return null;let o=Ur(t,n,r);if(!o.length)return null;return()=>{let i=o.filter((a)=>a.isConnected&&!a.hidden);if(!i.length)return;console.warn("[phlex-reactive] optimistic: { hide: true } was undone by the reply's re-render — "+"the element is visible again. For an instant delete, return reply.remove so the server removes it; otherwise the hide only flashes.",i)}}var de;function Gt(e){de=e}var _=new Map;function Kr(e,t){let n=!_.has(e);if(_.set(e,t),n)de.enter()}function pe(e){if(_.delete(e))de.exit()}var zr=!1;function Kt(e){Yr();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){fa(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;U(t,n)}function Yr(){if(zr||typeof document>"u"||!document.addEventListener)return;zr=!0,document.addEventListener("turbo:before-stream-render",pa,!0),document.addEventListener("turbo:before-stream-render",sa)}function sa(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(_.get(n)?.via==="stream")pe(n)}function U(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}Vt(e),Qr(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Kr(e,r),da(e,r,t)}function aa(e,t){if(typeof e!=="string"){let n={headers:{Accept:"text/vnd.turbo-stream.html"},credentials:"same-origin",signal:t};if(e.fallback)n.cache="no-store";return[e.src,n]}return[ha(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":ga()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function Vr(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Xr(t))return{src:t};return console.error(ca(t)),ua(t)||la(e)}function ca(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Yt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function ua(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Yt()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Xr(r))return{src:r,fallback:!0}}function la(e){Vt(e.id),Xt(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 Xr(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Yt()}/`)}catch{return!1}}function Yt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function fa(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}let r=t.getAttribute("data-reactive-defer-src");if(!r)return;if(!globalThis.customElements?.get?.("pgbus-stream-source")){let i=t.getAttribute("data-reactive-defer-token");if(i){U(e,i);return}console.error("[phlex-reactive] reactive:defer via=stream but <pgbus-stream-source> is not registered "+"and no fallback token was provided — is the pgbus client loaded on this page?");return}Vt(e),Qr(n);let o=document.createElement("pgbus-stream-source");o.id=Zr(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Kr(e,{via:"stream"})}function Zr(e){return`reactive-defer-src-${e}`}async function da(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},ba()),o;try{de.count("defer"),o=await fetch(...aa(n,t.abort.signal))}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),J(e,n);return}if(_.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),J(e,n,o.status);return}if(o.status===204){clearTimeout(r),Gr(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),J(e,n,o.status);return}let i=o.headers?.get?.("Content-Type")||"";if(!i.includes("turbo-stream")){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: expected a turbo-stream, got "${i}"`),J(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),_.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),J(e,n);return}if(clearTimeout(r),_.get(e)!==t)return;Gr(e),ma(a)}var zt=null,pa=(e)=>zt?.push(e);function ma(e){let t=zt=[];try{window.Turbo.renderStreamMessage(e)}finally{zt=null}for(let n of t){if(n.defaultPrevented)continue;let r=n.detail,o=r.render;r.render=()=>{},new Promise((i)=>i(o(r.newStream))).catch(console.error)}}function Vt(e){let t=_.get(e);if(!t)return;if(pe(e),t.via==="fetch")t.abort.abort();else document.getElementById(Zr(e))?.remove?.()}function Qr(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Xt(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Gr(e){pe(e);let t=document.getElementById(e);if(!t)return;Xt(t),t.removeAttribute("data-reactive-error")}function J(e,t,n){pe(e);let r=document.getElementById(e);if(!r)return;Xt(r),r.setAttribute("data-reactive-error","defer");let o=()=>{let i=document.getElementById(e);if(!i){console.warn("[phlex-reactive] defer retry() ignored — the target left the DOM");return}i.removeAttribute("data-reactive-error"),U(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function ha(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function ga(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function ba(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var eo="__materialize",fe=new WeakMap;function le(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function Zt(e,t,n){Yr();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>me(e),f=(d)=>{if(le(r)==="visible"){if(!a)b()}else if(d){let y=r.getAttribute("data-reactive-lazy-on");if(s===y)return;p(),r.addEventListener?.(y,l),s=y}},p=()=>{if(a?.disconnect(),a=null,s)r.removeEventListener?.(s,l);s=null},b=()=>{if(typeof IntersectionObserver>"u")return queueMicrotask(l);let d=r.getAttribute("data-reactive-lazy-visible")||"0px";a=new IntersectionObserver((y)=>{if(y.some((A)=>A.isIntersecting))l()},{rootMargin:d}),a.observe(r)},g=()=>{let d=le(r)!==null,y=o;if(o=d,!d)return p();if(i)return;if(t.forgetToken(),!y)return l();f(!0)};if(fe.set(e,{load(){if(i)return;let d=Vr(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&va(r,t))return;let y=d?U(r.id,d):t.proceed(r,eo,"{}");if(!y)return;i=!0,p();let A=()=>{i=!1};return y.then(A,A),y},off(){if(c)r.removeEventListener?.("turbo:morph-element",c);if(u)r.removeEventListener?.("turbo:morph-element",u);p()}}),(r.getAttribute?.("data-reactive-defer-token")||r.getAttribute?.("data-reactive-defer-src"))&&le(r)===null)Ht(r),c=(d)=>d.target===r&&Ht(r),r.addEventListener?.("turbo:morph-element",c);if(r.getAttribute?.("data-reactive-token-value")==null&&r.getAttribute?.("data-reactive-defer-src")==null)return;if(u=(d)=>{if(d.target!==r)return;if(!c)Ht(r);g()},r.addEventListener?.("turbo:morph-element",u),n)return g();if(o=le(r)!==null,o)f(!1)}function Qt(e){let t=fe.get(e);fe.delete(e),t?.off()}function me(e){return fe.get(e)?.load()}function va(e,t){return t.emit("reactive:before-dispatch",{action:eo,params:{},element:e},{cancelable:!0}).defaultPrevented}function Ht(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||Vr(e);if(t)U(e.id,t)}var en=new WeakMap,ge=new WeakMap,m=null,R,no;function on(e,t){let n=e.element;ge.set(n,t),fo();let r=(i)=>Aa(i,t),o=(i)=>xa(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),en.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function sn(e){if(en.get(e)?.(),en.delete(e),ge.delete(e.element),m&&be(m.origin)===e.element)he()}var w=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),H=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},be=(e)=>e?.closest?.('[data-controller~="reactive"]'),so=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==m?.row&&so(t)===e),ro=(e)=>H(w(e,"-item"),null),tn=(e)=>w(e,"-disabled")==="true",ya=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},ao=(e)=>{let t=w(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>w(n,"-group")===t&&!tn(n)&&ge.has(be(n)))};function co(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&so(n);if(m||!r||!t.owns(r)||tn(r)||tn(n))return;if(be(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function Aa(e,t){if(e.button>0||e.isPrimary===!1)return;let n=co(e.target,t);if(!n)return;let r=w(n.list,"-handle");if(r?!n.item.contains(e.target.closest(r)):e.target.closest("input,textarea,select,[contenteditable]"))return;let{clientX:o,clientY:i}=e,a=(d)=>d.pointerId===e.pointerId,s=e.pointerType==="touch",c=!s,u=s&&setTimeout(()=>c=!0,200),l=(d)=>{if(!a(d))return;if(m)return nn(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return h();Sa(n,t,d),nn(d.clientX,d.clientY)},f=(d)=>m&&d.cancelable&&d.preventDefault(),p=(d)=>{if(!a(d))return;if(h(),m)wa(),rn()},b=(d)=>{if(d.type==="pointercancel"&&!a(d))return;if(h(),m)he()},v=[["pointermove",l],["pointerup",p],["pointercancel",b],["keydown",(d)=>d.key==="Escape"&&m&&(d.preventDefault(),b(d))],["touchmove",f,{passive:!1}]];for(let[d,y,A]of v)document.addEventListener(d,y,A);function h(){clearTimeout(u);for(let[d,y]of v)document.removeEventListener(d,y)}}function wa(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Sa({item:e,list:t},n,r){let o=e.getBoundingClientRect(),i=t.matches("[data-reactive-sortable-source]"),a=i?e.cloneNode(!0):e;if(i){for(let c of[a,...a.querySelectorAll("[id],[data-controller]")])c.removeAttribute("id"),c.removeAttribute("data-controller");document.body.append(a)}let s=document.createElement(e.tagName);if(s.setAttribute("data-reactive-sortable-placeholder",""),s.setAttribute("aria-hidden","true"),s.style.height=`${o.height}px`,m=uo({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),m.dx=r.clientX-o.left,m.dy=r.clientY-o.top,m.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none",!i)e.before(s);Object.assign(a.style,{position:"fixed",left:`${o.left}px`,top:`${o.top}px`,width:`${o.width}px`,height:`${o.height}px`,margin:"0",boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"})}function uo(e){let{row:t,origin:n,source:r}=e;return e.index=T(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),z(n,!0),e}var z=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function ve(e,t,n,r){if(t[n])t[n].before(r);else if(t.length)t.at(-1).after(r);else e.append(r)}function nn(e,t){m.x=e,m.y=t,m.row.style.left=`${e-m.dx}px`,m.row.style.top=`${t-m.dy}px`;let n=ao(m.origin).find((r)=>ya(r,e,t));if(n)Ea(n,e,t);else if(m.source)an(null),m.placeholder.remove();_a(e,t)}function an(e){if(m.target!==m.origin)z(m.target,!1);m.target=e,z(e,!0)}function Ea(e,t,n){an(e);let r=T(e),[o,i]=r.map((c)=>c.getBoundingClientRect()),a=i&&o.top===i.top&&o.left!==i.left,s=r.findIndex((c)=>{let u=c.getBoundingClientRect();return a?t<u.left+u.width/2:n<u.top+u.height/2});ve(e,r,s<0?r.length:s,m.placeholder)}function _a(e,t){let n=m.target??m.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(m.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,m.wy=t<40?-12:t>window.innerHeight-40?12:0,(m.vy||m.wy)&&!m.raf){let i=()=>{if(!m||!(m.vy||m.wy))return m&&(m.raf=0);if((m.target??m.origin).scrollTop+=m.vy,m.wy)window.scrollBy(0,m.wy);nn(m.x,m.y),m.raf=requestAnimationFrame(i)};m.raf=requestAnimationFrame(i)}}function xa(e,t){let n=e.key;if(m?.keyboard){if(e.target!==m.row||m.core!==t)return;let o={" ":rn,Enter:rn,Escape:he,Tab:he,ArrowUp:()=>oo(-1),ArrowDown:()=>oo(1),ArrowLeft:()=>io(-1),ArrowRight:()=>io(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=co(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),m=uo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Ae("picked")}function oo(e){let t=T(m.target),n=ye()+e;if(n>=0&&n<=t.length)ve(m.target,t,n,m.row);lo()}function io(e){let t=ao(m.origin),n=t[t.indexOf(m.target)+e];if(n){let r=ye();an(n),ve(n,T(n),r,m.row)}lo()}function lo(){m.row.focus?.(),Ae("moved")}function ye(){let e=T(m.target),t=m.keyboard?m.row:m.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function fo(){if(!R?.isConnected)R=document.createElement("div"),R.setAttribute("aria-live","polite"),R.setAttribute("data-reactive-sortable-live",""),R.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(R);return R}function Ae(e){let t=m.target??m.origin,n=(H(w(t,"-messages"),{})[e]??"").replaceAll("{position}",ye()+1).replaceAll("{count}",T(t).length+1),r=fo();r.textContent="",cancelAnimationFrame(no),no=requestAnimationFrame(()=>r.textContent=n)}function rn(){let e=m,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?ye():-1,c=a?ro(T(t)[s-1]):null;if(e.keyboard)Ae("dropped");if(!r&&i)i.replaceWith(o);if(mo(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?w(n,"-source"):w(n,"-name")??"list",l=H(w(t,"-from"),{})[u]??w(t),f={...H(w(t,"-params"),{}),item:ro(e.item),position:s,after:c,from:u},p=[];for(let g=t;g;g=g.parentElement)p.push(g);let b=ge.get(be(t))?.proceed(t,l,JSON.stringify(f),H(w(t,"-busy")));if(r)return;Promise.resolve(b).then((g)=>ka(g,p)||po(e))}function ka(e,t){if(!e)return!1;let n=document.createElement("template");return n.innerHTML=e,[...n.content.querySelectorAll("turbo-stream")].some((r)=>/^(replace|update)$/.test(r.getAttribute("action"))&&Ta(r,t))}function Ta(e,t){let n=e.getAttribute("target");if(n)return t.some((o)=>o.id===n);let r=e.getAttribute("targets");try{return Boolean(r)&&t.some((o)=>o.matches(r))}catch{return!1}}function he(){let e=m;if(e.keyboard)Ae("cancelled");e.placeholder?.remove(),mo(e),po(e)}function po({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(ve(t,T(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function mo(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(m=null,e.raf)cancelAnimationFrame(e.raf);if(t.removeAttribute("data-reactive-sortable-dragging"),o)t.remove();else if(!e.keyboard)i==null?t.removeAttribute("style"):t.setAttribute("style",i);if(a?.remove(),z(n,!1),z(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var O=new Map,go=new WeakSet;function cn(e,t){let n=e.element,r=O.get(n.id);if(!r)O.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,La(n);let o=(a)=>a.target===n&&queueMicrotask(()=>vo(r)),i=(a)=>a.target===n&&a.detail?.action==="presence_set"&&console.error(`[phlex-reactive] #${n.id}: its presence_set request failed`,a.detail);n.addEventListener("turbo:morph-element",o),n.addEventListener("reactive:error",i),r.off=()=>{n.removeEventListener("turbo:morph-element",o),n.removeEventListener("reactive:error",i)},vo(r)}function un(e){let t=e.element,n=O.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;O.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function ln(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=O.get(e.id);if(!n)O.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},yo(n)}function La(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&go.has(n))return;if(n?.remove(),!bo())setTimeout(()=>{if(!bo())console.error("[phlex-reactive] reactive_presence needs the pgbus client (<pgbus-stream-source>) on this page — "+`#${e.id} is not subscribed to its presence stream`)},5000);let r=document.createElement("pgbus-stream-source");r.id=t,r.setAttribute("src",e.getAttribute("data-reactive-presence")),r.setAttribute("presence",""),r.hidden=!0,r.addEventListener("pgbus:connected",()=>{let o=O.get(e.id);if(!o||o.removing)return;yo(o),Ra(o)}),go.add(r),document.body.appendChild(r)}var bo=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Ra(e){clearTimeout(e.timer),e.timer=setTimeout(()=>{let t=e.root;if(e.removing||!t.isConnected)return;let n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat;if(n&&Ao(t).has(n))return;console.warn(`[phlex-reactive] #${t.id} never appeared on its presence roster: config.streams_authorize returned no identity for this stream, or its presence_set request failed (logged above)`)},2500)}function yo(e){let t=e.root;if(!e.core||!t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.getAttribute("connection-id"))return;e.core.proceed(t,"presence_set",JSON.stringify(e.state??{}))}function Ao(e){let t=e.getAttribute("data-reactive-presence-roster");if(t!=null)return new Set(t.split(" ").filter(Boolean));return new Set([...e.querySelectorAll("[data-reactive-presence-peer]")].map((n)=>n.getAttribute("data-reactive-presence-peer")))}function vo(e){let t=e.root,n=t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.pgbusSeat,r=t.querySelectorAll("[data-reactive-presence-peer],[data-reactive-presence-member]"),o=Ao(t),i;for(let u of r)if(u.getAttribute("data-reactive-presence-peer")===n)i=u.getAttribute("data-reactive-presence-member");for(let u of r){let l=u.getAttribute("data-reactive-presence-peer")===n;u.toggleAttribute("data-reactive-presence-me",l),u.toggleAttribute("data-reactive-presence-same-member",!l&&i!=null&&u.getAttribute("data-reactive-presence-member")===i)}let a=e.seats;if(e.seats=o,!a)return;let s=[...o].filter((u)=>!a.has(u)),c=[...a].filter((u)=>!o.has(u));if(s.length||c.length)e.core.emit("reactive:presence",{joined:s,left:c,me:n??null})}var So=new Map,fn=new WeakMap,Oa=0,we=new WeakMap;function dn(e,t){let n=e.element;if(!n.id&&!fn.has(n))fn.set(n,`#${++Oa}`);let r=n.id||fn.get(n),o=new Map,i=!1,a=(b)=>{clearTimeout(o.get(b)),o.delete(b)},s=(b,g,v)=>{a(b);let h=Date.parse(g.until)-Date.now();if(!(h>0))return c(b,g,v);let d=Math.ceil(h/1000);Eo(b,`${Math.floor(d/60)}:${String(d%60).padStart(2,"0")}`,"running"),u(g.waiting,!0),u(g.done,!1),o.set(b,setTimeout(()=>s(b,g,v),(h-1)%1000+1))},c=(b,g,v)=>{Eo(b,"0:00","done"),u(g.waiting,!1),u(g.done,!0);let h=So.get(v)??new Set;if(h.has(g.until))return;So.set(v,h.add(g.until)),b.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:g.until}}))},u=(b,g)=>{let v;try{v=b&&n.querySelector(b)}catch{}if(v&&v.hidden===g)v.hidden=!g},l=()=>{if(i=!1,!we.has(e))return;let b=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((v,h)=>{if(!t.owns(v))return;let d;try{d=JSON.parse(v.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(d?.until)))return;b.add(v),s(v,d,`${r}|${v.id||h}`)});for(let v of o.keys())if(!b.has(v))a(v)},f=()=>{if(i)return;i=!0,queueMicrotask(l)},p=()=>document.visibilityState==="visible"&&l();n.addEventListener("turbo:morph-element",f),n.addEventListener("reactive:streamed",f),document.addEventListener("visibilitychange",p),we.set(e,()=>{n.removeEventListener("turbo:morph-element",f),n.removeEventListener("reactive:streamed",f),document.removeEventListener("visibilitychange",p);for(let b of[...o.keys()])a(b)}),l()}function pn(e){we.get(e)?.(),we.delete(e)}function Eo(e,t,n){if(e.textContent!==t)e.textContent=t;if(e.getAttribute("data-reactive-countdown-state")!==n)e.setAttribute("data-reactive-countdown-state",n)}function Na(){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 Ca(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),n=this.getAttribute("target");if(!t||!n)return;let r=document.getElementById(n);if(r)r.setAttribute("data-reactive-token-value",t)}}function Ma(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=qn(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",o=n?document.getElementById(n):null;if(n&&!o){if(r)Dt(n);return}Rn(t,(i)=>wc(i,o),r?(i,a)=>It(i,a,o):void 0)}}function $a(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){Kt(this)}}var ko=!1,Pa=null;function Ia(){if(ko)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ko=!0,document.addEventListener("turbo:before-stream-render",(e)=>{Ya(e),Da(e),Wa(e),Lt(e)})}var Ee="reactive:streamed";function Da(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,o=r?.getAttribute?.("action"),i=/^(append|prepend|update)$/.test(o);if(typeof n!=="function"||!(i||/^(before|after|replace)$/.test(o)))return;let a=r.getAttribute("target"),s=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let l=(i?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(l)c.add(l)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let l of c)if(l.isConnected)l.dispatchEvent(new Event(Ee))}}function On(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function Fn(e){try{return e.matches(":modal")}catch{return!1}}function Qo(e){if(!On(e)){if(e?.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] show_modal targets a <dialog>, not <${e.localName}> — skipped`);return}if(!e.isConnected||Fn(e))return;if(e.open)e.close();e.showModal()}function qa(e){if(On(e)&&e.open)e.close()}function Te(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!Fn(r))Qo(r)}function Wa(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target;if(typeof n!=="function"||!r?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(o)=>{await n(o),Te(document)}}var To=!1;function ja(){if(To)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;To=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Te(t.target)}),document.addEventListener("turbo:morph",()=>Te(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!On(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!Fn(n))return;e.delete(n),t.preventDefault(),n.close()})}var kn=new WeakMap;function ei(e,t,n,r){let o=kn.get(e)??new Map;kn.set(e,o);let i=(a,s)=>{o.delete(a),o.set(a,s)};if(t.endsWith("_class"))for(let a of n.classes??[])i(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))gi(n.name)||i(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(i("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))ei(a,"set_attr",{name:"aria-expanded"})}}var Lo=!1;function Ba(){if(Lo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Lo=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of kn.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var ti="data-reactive-image-fallback",G="data-reactive-image-state",Tn="data-reactive-image-hidden",mn=null,Ln="data-reactive-wrap-hidden";function ni(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(Ln,"")}function ri(e){if(!e.hasAttribute(Ln))return;e.removeAttribute("hidden"),e.removeAttribute(Ln)}function K(e){if(e?.localName!=="img")return null;let t=e.getAttribute(ti);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var oi=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Nn(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function ii(e,t){let n=Nn(e,t.alt);return n&&!n.contains(e)?n:null}function Le(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Tn,"");if(t.wrap){let o=Nn(e,t.wrap);if(o)ni(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=ii(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Fe(e,t);e.setAttribute(G,n)}function Fe(e,t=K(e)){if(!t||e.getAttribute(G)==null)return;if(e.getAttribute(G)==="error"){if(e.hasAttribute(Tn))e.removeAttribute("hidden");let n=Nn(e,t.wrap);if(n)ri(n);let r=ii(e,t);if(r)r.hidden=!0}e.removeAttribute(G),e.removeAttribute(Tn)}function Ro(e){let t=e.target,n=K(t);if(!n)return;if(e.type==="load")Le(t,n,"loaded");else if(oi(t))Le(t,n,"error");else Fe(t,n)}function Ja(){if(mn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;mn={error:Ro,load:Ro,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(G);if(o==null||!r||!K(n))return;let i=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(i("src")&&i("srcset"))e.set(n,o)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let o=K(n);if(o)Le(n,o,r)})}};for(let[t,n]of Object.entries(mn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${ti}]`)??[]){if(!t.complete||!oi(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Le(t,K(t)??{},o);if(t.naturalWidth>0)r("loaded");else if(typeof t.decode==="function")t.decode().then(()=>r("loaded"),()=>r("error"));else r("error")}}function Jc(e){Pa=e}var Se,hn=null,Oo="[data-reactive-editable][contenteditable=plaintext-only]";function si(){if(Se===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Se=e.contentEditable==="plaintext-only"}catch{Se=!1}return Se}function _e(e){if(e.matches?.(Oo))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Oo).forEach(_e)}function Ua(){if(hn||typeof document>"u"||typeof document.createElement!=="function")return;if(si())return;_e(document),hn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")_e(t.target);else t.addedNodes.forEach(_e)}),hn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var Fo=!1;function No(e){return e===document.activeElement&&(e.localName==="input"||e.localName==="textarea"||e.hasAttribute("data-reactive-editable"))&&!e.hasAttribute("data-reactive-morph-value")&&!!e.closest('[data-controller~="reactive"]')}function Ha(){if(Fo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Fo=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=No(t);if(r)Ga(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Re.set(t,F(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==E)t.removeAttribute(i);for(let{name:i,value:a}of n.attributes)if(i!=="contenteditable"&&t.getAttribute(i)!==a)t.setAttribute(i,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let o=n.getAttribute("value");if(o==null)t.removeAttribute("value");else if(t.getAttribute("value")!==o)t.setAttribute("value",o)}),document.addEventListener("focusin",(e)=>In(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===E)&&No(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(E)&&Mn(t)===$n(t))t.removeAttribute(E)})}var E="data-reactive-held",Cn='[data-controller~="reactive"]',xe=null,P=new Map;function Mn(e){return e.hasAttribute("data-reactive-editable")?F(e):e.value}function $n(e){return e.hasAttribute("data-reactive-editable")?Dn(e):e.defaultValue}function za(e){if(e.hasAttribute("data-reactive-editable"))return F(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Ga(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||P.has(e.closest(Cn)))return;let r=za(t);if(r===Mn(e))return e.removeAttribute(E);if(r===$n(e))return;e.setAttribute(E,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function Ka(e){let t=[];for(let n of e.querySelectorAll(`[${E}]`)){if(n.closest(Cn)!==e)continue;let r=n.getAttribute("name");if(Mn(n)===$n(n))n.removeAttribute(E);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function ai(e){for(let t of e.querySelectorAll(`[${E}]`))if(t.closest(Cn)===e)t.removeAttribute(E)}function Co(e,t,n=!0){let r={root:e,streams:0,release:n},o=xe;xe=r;try{window.Turbo.renderStreamMessage(t)}finally{xe=o}if(n&&r.streams===0)ai(e)}function Ya(e){let t=xe,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{P.set(t.root,(P.get(t.root)||0)+1);try{return await r(o)}finally{let i=P.get(t.root)-1;if(i)P.set(t.root,i);else P.delete(t.root);if(t.release)ai(t.root)}}}var Va="__materialize",Mo=!1;function Xa(){if(Mo)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Mo=!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 Pn(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Mt()}var ci="data-reactive-active",x=0;function ui(){if(x++,x===1)fi("reactive:busy")}function li(){if(x===0)return;if(x--,x===0)fi("reactive:idle")}function Uc(){return x}function Hc(){x=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(ci)}function fi(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(ci,x>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:x}}))}var di="data-reactive-requests";function pi(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Za(t))return;let n=Qa(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(di,JSON.stringify(n))}function Za(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Qa(e){try{let t=JSON.parse(e.getAttribute(di));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function $o(){Na(),Ca(),Ma(),$a(),Ia(),Ha(),ja(),Ba(),Ja(),Ua(),Xa(),Pn()}function ec(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var mi=Symbol.for("phlex-reactive.core");if(globalThis[mi])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[mi]=!0;var hi=!1;function tc(){if(hi)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(tc,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var nc=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function gi(e){let t=String(e).toLowerCase();return t.startsWith("on")||nc.has(t)}var gn=new WeakMap;function rc(e,t,n){let[r,o,i]=t;gn.get(e)?.(),e.classList.add(r,o),n();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(o),e.classList.add(i)}),c=(l)=>{if(a||l&&l.target!==e)return;a=!0,gn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};gn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,oc(e))}function oc(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[o,i]=["Duration","Delay"].map((s)=>String(n[r+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<o.length||s<i.length||s<a.length;s++){let c=o[s%o.length]*a[s%a.length]||0;t=Math.max(t,c+i[s%i.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var ic=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",sc=new Set(["lexxy-editor","trix-editor"]);function F(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
2
2
|
`))t+=`
|
|
3
3
|
`;n=!1,t+=i},o=(i)=>{for(let a of i.childNodes){let s=/^(div|p|li)$/.test(a.localName);if(s)n=!0;if(a.nodeType===3)a.data&&r(a.data);else if(a.localName==="br")r(`
|
|
4
4
|
`);else if(a.nodeType===1)o(a);if(s)n=!0}};return o(e),t=t.replace(/\r\n?/g,`
|
|
5
|
-
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var
|
|
6
|
-
`):e.value}function Ca(e,t,n){if(n?.transition)Ea(e,n.transition,()=>e.hidden=t);else e.hidden=t}function rn(e,t,n,r){if(Ca(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let o of r({...n,to:n.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function on(e){if(!Jo(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function zo(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t.getAttribute("src"):null,r=(i)=>n?t.getAttribute(i):null;for(let i of["srcset","src"]){let a=r(i);if(a==null){if(e.hasAttribute(i))e.removeAttribute(i)}else if(e.getAttribute(i)!==a)e.setAttribute(i,a)}let o=r("alt")??"";if(e.getAttribute("alt")!==o)e.setAttribute("alt",o);return n?o:!1}var Ma='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Pa(e){return e.querySelectorAll?.(Ma)?.[0]??null}function Sn(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 bo=Object.freeze({backspace:"Backspace",delete:"Delete",enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"}),yo=Object.freeze(["meta","ctrl","alt","shift"]);function Te(e,t,n){let r=e.split("+");for(let a of yo)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!yo.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(bo,o)?bo[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var $a=(e)=>e&&typeof e==="object"?e.keys:String(e);function sn(e,t,n){let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Te($a(e).replace(/^mod\+/,`${o}+`),t,n)}function Ia(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:Sn(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function vo(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==Go(t.currentTarget))return!1;return o<0||n===null||Te(r.slice(o+1),t,n)}function Da(e,t){let n=e.detail;if(n===void 0)return!0;if(n===null||typeof n!=="object"||Array.isArray(n))return!1;let r=t.detail;if(r===null||typeof r!=="object")return!1;return Object.keys(n).every((o)=>r[o]===n[o])}var Ao=new WeakMap;function qa(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Ao.get(e);if(!o)o=new WeakMap,Ao.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var wo=new WeakMap;function Wa(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=wo.get(e);if(!o)o=new WeakMap,wo.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function pn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(mo,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)if(mo[o](s,i,t),i?.keep===!0)No(s,o,i,t)}}function ja(e,t){let n=e.to;if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function Ba(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function So(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function Ja(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 Ua(e){return["show-targets","group-targets","on-complete","filter-input","tags-field"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)||(e.querySelectorAll?.("[data-reactive-show-field], [data-reactive-show]")??[]).length>0||e.querySelector?.("[data-reactive-nested-json], [data-reactive-nested-list], [data-reactive-confirm-when-param], [data-reactive-enable], [data-reactive-select-all], [data-reactive-count], [data-reactive-editable], [data-reactive-media]")!=null}function Ha(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function za(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Eo(e){return e.getAttribute?.("data-reactive-presence")!=null}function lc(e,t,n){}function Ga(e,t){}function fc(e){return[]}function dc(e){return Promise.resolve()}var _o=new Set;function Ka(e,t,n){let r=e+t;if(_o.has(r))return;_o.add(r),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,n)}function pc(){return["persist","defer","form","bindings","compute","sortable","presence","effects","hints","devtools"]}var xo=Promise.resolve();var ko={enter:$o,exit:Io,count:Wo,text:F,served:wn,waiting:new WeakMap},To=1,an=2,cn=4,un=8,ln=16,Ro=32,Lo=64;tt(ko),Dt(ko);var Y=Symbol.for("phlex-reactive.early"),Ya=1e4,Va=1500,Go=(e)=>e!=null&&(e===globalThis.window||e.window===e);function fn(){return globalThis[Y]??={queue:[],connected:new WeakSet},globalThis[Y]}function Xa(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Ya}function Za(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function Qa(e,t,n){return{[Y]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Za(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 ke=new WeakMap;function ec(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=ke.get(e);if(!s)ke.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function Fo(e,t,n,r){if(e?.[Y])return!1;let o=Go(e?.currentTarget),i=o?r:e?.currentTarget,a=nc(e,i,o?`@${t}`:t),s=ke.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&&!Te(u.filter,e,n))continue;return u.armed=!1,!0}return a}var Ee=new WeakMap;function tc(e,t,n){let r=Ee.get(e);if(!r)Ee.set(e,r=new Map),setTimeout(()=>Ee.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function nc(e,t,n){let r=e&&Ee.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class Ko extends Zs{static values={token:String};#m;#h=new Map;#f=new Map;#z;#w;#M;#S=0;#d=new Map;#E=new WeakMap;#t;featuresReady=xo;#xe=new Map;#ke=new Set;#G=!1;#P=null;#Te=new Map;#Re=new Map;#Le=new Map;#K=0;#$;#_=0;#n=0;connect(){if(Bo=!0,fn().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||So(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Ae)this.#D();this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(Ae,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(An),this.#K++,this.featuresReady=xo,this.#I(),_e(this.element),this.#V()}#I(e){this.#r(To,"persist",Ba,(t)=>ut(this,t,e)),this.#r(an,"defer",So,(t)=>Jt(this,t,e)),this.#r(cn,"form",Ja,(t)=>pt(this,t,e)),this.#r(un,"bindings",Ua,(t)=>Fe(this,t,e)),this.#r(ln,"compute",Ha,(t)=>Ke(this,t,e)),this.#r(Ro,"sortable",za,(t)=>Yt(this,t)),this.#r(Lo,"presence",Eo,(t)=>Zt(this,t))}#r(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#n|=e}catch(o){this.#q(t,"connect",o)}}#Y(){{let e=this.#n;this.#_=this.#n=0;let t=this.#e();if(e&To)this.#o("persist",()=>lt(this,t));if(e&an)this.#o("defer",()=>Ut(this,t));if(e&cn)this.#o("form",()=>mt(this,t));if(e&un)this.#o("bindings",()=>Oe(this,t));if(e&ln)this.#o("compute",()=>Ye(this,t));if(e&Ro)this.#o("sortable",()=>Vt(this,t));if(e&Lo)this.#o("presence",()=>Qt(this,t))}}#o(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Fe(e){}#Oe(e,t){}#Ne(e){}#Ce(e,t){}#Me(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#D(),proceed:(e,t,n,r)=>this.#k(e,t,n,0,0,null,r),forgetToken:()=>{this.#m=void 0},owns:(e)=>this.#v(e),ownership:()=>this.#L(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>pn(e,(n)=>this.#C(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#p(e),collectFields:()=>this.#J(),plain:Co,text:F,served:wn,copyMedia:zo,confirm:(e,t)=>Promise.resolve().then(()=>ro(e,t)).catch(()=>!1)},this.#$}#D(){if(this.#n&cn)ht(this);if(this.#n&un)Ne(this);if(this.#n&ln)Ve(this)}#q(e,t,n){if(Ka(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#Pe(){}#V(){if(this.element.setAttribute?.("data-reactive-connected",""),this.element.isConnected)this.element.dispatchEvent?.(new CustomEvent("reactive:connect",{bubbles:!0,composed:!0,detail:{id:this.element.id}}));this.#X()}#x=new Set;#X(){let{queue:e}=fn();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=Xa(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(Va,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#O())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#Z(o)}}#Z({event:e,el:t,descs:n,win:r}){let o=Qa(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Te(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!ec(s,c,r&&JSON.stringify(o.params)))continue;this.#x.add(s)}if(tc(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Y(),this.#re(),this.#ie(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(Ae,this.#t);fn().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#x)ke.delete(e);this.#x.clear()}dispatch(e){let t=e.params?.shortcut;if(t!=null&&!sn(t,e,this.application?.schema?.keyMappings))return;if(Fo(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l}=e.params;if(!n)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let m=e.currentTarget??e.target;if((t!=null||!u)&&!this.#be(l,m))e.preventDefault();if(n===ga){let v=()=>{if(this.#n&an)return de(this);if(this.tokenValue)return this.#k(m,n,"{}")};return this.#G?this.featuresReady.then(v):v()}let g=this.#W(a,s),b=()=>this.#k(m,n,r,o,i,l,p);if(!g)return b();if(g instanceof Promise)return g.then((v)=>v?this.#g(v,m,b):b());this.#g(g,m,b)}#g(e,t,n){return Promise.resolve().then(()=>ro(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return Me(this,this.#e(),t)}#Q(e){}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!sn(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Fo(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Wa(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Ia(n.ops),i=o.filter((s)=>vo(s,e,null)),a=i.length<=1?i:i.filter((s)=>vo(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())Ot(this,e);return}for(let s of a){if(s.outside&&e[Y])continue;if(!Da(s,e))continue;if(s.shortcut!=null&&!sn(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(qa(this,e,s))continue;this.#ee(s.legacy?{...n,ops:s.ops}:s,e,r)}}#ee({ops:e,confirm:t,confirmWhen:n,outside:r,window:o,shortcut:i},a,s){if(r&&this.element.contains(a.target))return;if(i!=null||!o)a.preventDefault();let c=this.#W(t,n),u=()=>this.#ge(this.#he(e));if(!c)return u();if(c instanceof Promise)return c.then((l)=>l?this.#g(l,s,u):u());this.#g(c,s,u)}recompute(e){return Xe(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#p(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return We(this,this.#e(),e)}tagsPick(e){return je(this,this.#e(),e)}tagsRemove(e){return Be(this,this.#e(),e)}nestedAdd(e){return Je(this,this.#e(),e)}nestedRemove(e){return Ue(this,this.#e(),e)}syncNestedJson(e){return Ce(this,this.#e(),e)}#$e(e,t){}trackDirty(){oe(this,this.#e())}listnavNext(e){this.#b(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#b(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#b(e,()=>0)}listnavLast(e){this.#b(e,(t,n)=>n-1)}listnavPick(e){let t=this.#p(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#p(e))t.removeAttribute("data-reactive-highlighted")}#b(e,t){let n=this.#p(e);if(!n.length)return;e.preventDefault();let r=this.#te(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#te(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#p(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#L();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#k(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#U(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ne(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#oe(e,u,t,n,i,a);return this.#y(t,n,i,e,a)}#y(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#ye(e,r,i),s=Boolean(n||o),c=(m)=>{if(!s||!m)return;let g=this.#e();if(i.inverse=Mt(this,g,n,r),i.undo.push(...Ct(this,g,o,r)),this.#R())i.resurrect=Pt(this,g,n,r)},u=!0;c(!0);let l=()=>this.#ue(e,t,i,a),p=()=>this.#P?this.#P.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>p()),this.queue}#Ie(){return this.#Q("hints")}#ne(e,t,n,r,o,i){this.#T(e);let a=()=>{this.#T(e),this.#y(n,r,o,e,i)},s=setTimeout(a,t);e?.addEventListener?.("blur",a,{once:!0}),this.#h.set(e,{timer:s,flush:a})}#T(e){let t=this.#h.get(e);if(!t)return;clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),this.#h.delete(e)}#re(){for(let e of[...this.#h.keys()])this.#T(e)}#oe(e,t,n,r,o,i){let a=this.#f.get(e)??new Map;if(a.has(n))return;let s=setTimeout(()=>{if(a.delete(n),a.size===0)this.#f.delete(e)},t);return a.set(n,s),this.#f.set(e,a),this.#y(n,r,o,e,i)}#ie(){for(let e of this.#f.values())for(let t of e.values())clearTimeout(t);this.#f.clear()}#s(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#y(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#se(){this.element?.removeAttribute?.("data-reactive-error")}#ae(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#ce(){return kt()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#j(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#ue(e,t,n,r){let{fields:o,files:i}=this.#J(),a=this.#U(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#pe(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),p=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#j()}:null;await this.#ce();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let m;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Ee()};if(!u)h["Content-Type"]="application/json";let d=this.#_e();if(d)h["X-Pgbus-Connection"]=d;let y=Eo(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(y)h["X-Reactive-Presence"]=y;let A=ma(this.element);if(A)h["X-Reactive-Held"]=A;Wo("action"),m=await fetch(this.#we(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Se())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#u(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#ae(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(p)p.status=m.status;if(m.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:m.status});return}if(!m.ok){let h=await m.text();if(console.error(`[phlex-reactive] action failed: HTTP ${m.status}`,h),this.#u(n.inverse),(m.headers.get("Content-Type")||"").includes("turbo-stream")){let d=this.#B(h);if(this.#c=d??this.#c,p)se(p,h,d);lo(this.element,h,!1)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:m.status,body:h});return}let g=m.headers.get("Content-Type")||"";if(!g.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${g}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:m.status});return}let b=await m.text(),v=this.#B(b);if(this.#c=v??this.#c,p)se(p,b,v);if(lo(this.element,b),n.resurrect)queueMicrotask(n.resurrect);return this.#se(),this.#s("reactive:applied",{action:e,params:s,html:b}),b}catch(m){console.error("[phlex-reactive] action error",m),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),p)Nt(this,{...p,ms:this.#j()-p.started})}}get#c(){return this.#m??this.tokenValue}set#c(e){this.#m=e}tokenValueChanged(){this.#m=void 0}#B(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#le(t),o=e.match(n);if(o)return o[1];let i=e.match(r);if(i)return i[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#le(e){let t=this.#M;if(t&&t.id===e)return t;let n=Aa(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#v(e){return e.closest('[data-controller~="reactive"]')===this.element}#L(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#v(t)}#J(){let e={},t=[],n=this.#L(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${xa}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#fe(r),a=this.#de(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?F(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!Ta(s))return;if(String(c).endsWith("[]")&&(l===void 0||Array.isArray(l))){(Array.isArray(l)?l:e[c]=[]).push(u);return}if(l==null||l==="")e[c]=u}),{fields:e,files:t}}#fe(e){let t=new Set;for(let n of e){if(n.type==="radio")continue;if(String(n.name).endsWith("[]"))t.add(n.name)}return t}#de(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#pe(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#A(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#F(o,this.#A(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#me(r);for(let{name:s,file:c,multiple:u}of r){let p=u||a.has(s)?`${this.#A(s)}[]`:this.#A(s);o.append(p,c,c.name)}return o}#A(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#F(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#F(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#F(e,`${t}[${r}]`,o);else e.append(t,String(n))}#me(e){let t=new Map;for(let{name:n}of e)t.set(n,(t.get(n)??0)+1);return new Set([...t].filter(([,n])=>n>1).map(([n])=>n))}#U(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#he(e){return Sn(e)}#ge(e){pn(e,(t)=>this.#C(t),(t,n)=>this.#N(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#N(e,t){if(!this.#O())return;Ft(this,e,t)}#De(e){}#C(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((n)=>this.#v(n))}#be(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#ye(e,t,n){this.#ve(e,t),$o();let r=!1;return()=>{if(r)return;r=!0,this.#Ae(e,t),Io();for(let o of n.undo)o()}}#ve(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#d.set(e,(this.#d.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#H(e))this.#l(n,e,1)}#Ae(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#d.get(e)??1)-1;if(n<=0)this.#d.delete(e);else this.#d.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#H(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#H(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#v(n))}#we(){return this.#z??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Se(){if(this.#w!=null)return this.#w;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#w=Number.isFinite(t)&&t>0?t:30000}#Ee(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#_e(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)po();else document.addEventListener("turbo:load",po,{once:!0});vn();var Sc=Ko;export{Po as ACTIVE_ATTR,xa as EDITOR_SELECTOR,ka as EDITOR_TAGS,Es as LATENCY_KEY,qo as REQUESTS_ATTR,wa as checkReactiveRegistration,Wo as countReactiveRequest,Sc as default,Sr as disableLatencySim,F as editableValue,wr as enableLatencySim,$o as enterReactiveActivity,Aa as escapeRegExp,Io as exitReactiveActivity,dc as loadReactiveFeature,ac as onReactiveStreamWithoutEffects,cc as reactiveActivityCount,pc as reactiveFeatureNames,po as registerReactiveActions,na as registerReactiveDefer,vn as registerReactiveDev,oa as registerReactiveDismiss,oa as registerReactiveEffects,Ga as registerReactiveFeature,lc as registerReactiveFeatureLoader,ta as registerReactiveJs,ua as registerReactiveKeep,ca as registerReactiveModals,fa as registerReactiveMorphFocus,ba as registerReactiveOffline,la as registerReactivePlaintext,oa as registerReactiveStreamRender,ea as registerReactiveToken,Qs as registerReactiveVisit,uc as resetReactiveActivity,wn as serverText,fc as unloadedFeaturesFor};
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var Re=new WeakMap;function In(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Re.has(e))Re.set(e,F(e))}function Dn(e){return In(e),Re.get(e)}function ac(e){return sc.has(e.localName)?typeof e.value==="string":!0}var Po=Object.freeze({show:(e,t,n)=>vn(e,!1,t,n),hide:(e,t,n)=>vn(e,!0,t,n),toggle:(e,t,n)=>vn(e,!e.hidden,t,n),add_class:(e,t)=>e.classList.add(...t.classes??[]),remove_class:(e,t)=>e.classList.remove(...t.classes??[]),toggle_class:(e,t)=>(t.classes??[]).forEach((n)=>e.classList.toggle(n)),set_attr:(e,t)=>{if(yn(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(yn(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!yn(t.name))return;if(Array.isArray(t.values)){let[n,r]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===n?r:n)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>hc(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Qo(e),close_dialog:(e)=>qa(e),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},copy_media:(e,t,n)=>{let r=null;try{r=n({...t,to:t.from})[0]??null}catch{}Ai(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)Je(r,t.group,t.checked)},presence:(e,t)=>ln(e,t.state),dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,n)=>{let r=cc(e);if(!r)return;let o=null;if(t?.submitter!=null&&typeof n==="function"){if(o=n({...t,to:t.submitter})[0]??null,!(o?.form===r&&(o.type==="submit"||o.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),o=null}o?r.requestSubmit?.(o):r.requestSubmit?.()},paste_into:(e)=>uc(e),preview_file:(e,t,n)=>lc(e,t,n),set_value:(e,t)=>yi(e,String(t.value??"")),persist_state:(e,t)=>yt(e,t.state),persist_clear:(e)=>At(e)});function cc(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function uc(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,vi(e),e.focus?.()}).catch(()=>{})}var Y=new Map,V=null;function lc(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return bn(`reads an input[type=file], not <${e?.localName}>`);let r=typeof n==="function"?n({...t,to:t.into})[0]:null;if(r?.tagName!=="IMG")return bn(`paints an <img>, and ${JSON.stringify(t.into)} is ${r?`a <${r.localName}>`:"not on the page"}`);let o=[...t.valid===!0&&e.validity?.valid===!1?[]:e.files??[]],i=fc(e,t.accept),a=o.filter((l)=>typeof l?.type==="string"&&i(l)),s=a.find((l)=>l.type.startsWith("image/")),c=o.length>0&&a.length===0?"type":null;if(s&&Number.isInteger(t.max_bytes)&&s.size>t.max_bytes)c="size";let u=c==="size"?s:o[0];if(c)s=null;if(bi(r),s){let l=URL.createObjectURL(s);Y.set(r,l),r.setAttribute("src",l),dc()}else r.removeAttribute("src");if(Fe(r),t.wrap!=null){let l=n({...t,to:t.wrap});if(l.length===0)bn(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let f of l)s?ri(f):ni(f)}if(t.name!=null)for(let l of n({...t,to:t.name}))l.textContent=s?s.name:"";if(c)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:{reason:c,file:u}}))}function fc(e,t){let n=String((t===!0?e.getAttribute("accept"):typeof t==="string"&&t)||"").toLowerCase().split(",").map((r)=>r.trim()).filter(Boolean);if(n.length===0)return(r)=>r.type.startsWith("image/");return(r)=>{let o=r.type.toLowerCase();return n.some((i)=>i[0]==="."?String(r.name).toLowerCase().endsWith(i):i.endsWith("/*")?o.startsWith(i.slice(0,-1)):o===i)}}function bn(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function bi(e){let t=Y.get(e);if(t===void 0)return;if(Y.delete(e),URL.revokeObjectURL(t),Y.size===0)V?.disconnect(),V=null}function dc(){if(V||typeof MutationObserver!=="function"||!document?.documentElement)return;V=new MutationObserver(()=>{for(let[e,t]of Y)if(!e.isConnected||e.getAttribute("src")!==t)bi(e)}),V.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function vi(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function yi(e,t){if(!/^(input|textarea|select)$/.test(e.localName)||e.type==="file"&&t!==""){console.warn("[phlex-reactive] set_value skipped: not a field it can write",e);return}let n=Io(e);if(e.value=t,Io(e)!==n)vi(e)}function Io(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function pc(e,t,n){if(n?.transition)rc(e,n.transition,()=>e.hidden=t);else e.hidden=t}function vn(e,t,n,r){if(pc(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let o of r({...n,to:n.expanded}))o.setAttribute?.("aria-expanded",String(!t))}function yn(e){if(!gi(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function Ai(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),o=!1;for(let a of["srcset","src"]){let s=r?n.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))o=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)o=e.setAttribute(a,s)??!0}if(o)Fe(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var mc='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function hc(e){return e.querySelectorAll?.(mc)?.[0]??null}function qn(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 Do=Object.freeze({backspace:"Backspace",delete:"Delete",enter:"Enter",tab:"Tab",esc:"Escape",space:" ",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight",home:"Home",end:"End",page_up:"PageUp",page_down:"PageDown"}),qo=Object.freeze(["meta","ctrl","alt","shift"]);function Ne(e,t,n){let r=e.split("+");for(let a of qo)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!qo.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Do,o)?Do[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var gc=(e)=>e&&typeof e==="object"?e.keys:String(e);function An(e,t,n){let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let o=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return Ne(gc(e).replace(/^mod\+/,`${o}+`),t,n)}function bc(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:qn(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let o=null;try{o=JSON.parse(r)}catch{o=null}if(o&&typeof o==="object"&&!Array.isArray(o))n.push(o);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function Wo(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let o=r.indexOf(".");if(t.type!==(o<0?r:r.slice(0,o)))return!1;if(Boolean(e.window)!==Wn(t.currentTarget))return!1;return o<0||n===null||Ne(r.slice(o+1),t,n)}function vc(e,t){let n=e.detail;if(n===void 0)return!0;if(n===null||typeof n!=="object"||Array.isArray(n))return!1;let r=t.detail;if(r===null||typeof r!=="object")return!1;return Object.keys(n).every((o)=>r[o]===n[o])}var jo=new WeakMap;function yc(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=jo.get(e);if(!o)o=new WeakMap,jo.set(e,o);let i=o.get(r);if(!i)i=new Set,o.set(r,i);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(i.has(c))return!0;return i.add(c),!1}var Bo=new WeakMap;function Ac(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),o=Bo.get(e);if(!o)o=new WeakMap,Bo.set(e,o);let i=o.get(t);if(!i)i=new Map,o.set(t,i);let a=i.get(e.currentTarget);if(!a)a=new Set,i.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}function Rn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(Po,o)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(o)} — skipped`);continue}let a=t(i);if(a.length===0&&n)n(o,i);for(let s of a)if(Po[o](s,i,t),i?.keep===!0)ei(s,o,i,t)}}function wc(e,t){let n=e.to;if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function Sc(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Jo(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}function Ec(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 _c(e){return["show-targets","group-targets","on-complete","filter-input","tags-field"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)||(e.querySelectorAll?.("[data-reactive-show-field], [data-reactive-show]")??[]).length>0||e.querySelector?.("[data-reactive-nested-json], [data-reactive-nested-list], [data-reactive-confirm-when-param], [data-reactive-enable], [data-reactive-select-all], [data-reactive-count], [data-reactive-editable], [data-reactive-media]")!=null}function xc(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function kc(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Uo(e){return e.getAttribute?.("data-reactive-presence")!=null}function Tc(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function zc(e,t,n){}function Lc(e,t){}function Gc(e){return[]}function Kc(e){return Promise.resolve()}var Ho=new Set;function Rc(e,t,n){let r=e+t;if(Ho.has(r))return;Ho.add(r),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,n)}function Yc(){return["persist","defer","form","bindings","compute","sortable","presence","countdown","effects","hints","devtools"]}var zo=Promise.resolve();var Go={enter:ui,exit:li,count:pi,text:F,served:Dn,waiting:new WeakMap},Ko=1,wn=2,Sn=4,En=8,_n=16,Yo=32,Vo=64,Xo=128;ut(Go),Gt(Go);var X=Symbol.for("phlex-reactive.early"),Oc=1e4,Fc=1500,Wn=(e)=>e!=null&&(e===globalThis.window||e.window===e),Nc="dispatch";function xn(){return globalThis[X]??={queue:[],connected:new WeakSet},globalThis[X]}function Cc(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Oc}function Mc(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let o=/^data-reactive-(.+)-param$/i.exec(n);if(!o)continue;let i;try{i=JSON.parse(r)}catch{i=r}t[o[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=i}return t}function $c(e,t,n){return{[X]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Mc(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 Oe=new WeakMap;function Pc(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Oe.get(e);if(!s)Oe.set(e,s=new Map);let c=i?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:n,method:r,filter:o,win:i,params:a,armed:!0}),!0}function Zo(e,t,n,r){if(e?.[X])return!1;let o=Wn(e?.currentTarget),i=o?r:e?.currentTarget,a=Dc(e,i,o?`@${t}`:t),s=Oe.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&&!Ne(u.filter,e,n))continue;return u.armed=!1,!0}return a}var ke=new WeakMap;function Ic(e,t,n){let r=ke.get(e);if(!r)ke.set(e,r=new Map),setTimeout(()=>ke.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Dc(e,t,n){let r=e&&ke.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class wi extends Fa{static values={token:String};#h;#f=new Map;#d=new Map;#K;#w;#M;#S=0;#p=new Map;#E=new WeakMap;#t;featuresReady=zo;#Le=new Map;#Re=new Set;#Y=!1;#$=null;#Oe=new Map;#Fe=new Map;#Ne=new Map;#V=0;#P;#_=0;#o=0;connect(){if(hi=!0,xn().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||Jo(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Ee)this.#D();this.#I(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(Ee,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(In),this.#V++,this.featuresReady=zo,this.#I(),Te(this.element),this.#Z()}#I(e){this.#n(Ko,"persist",Sc,(t)=>bt(this,t,e)),this.#n(wn,"defer",Jo,(t)=>Zt(this,t,e)),this.#n(Sn,"form",Ec,(t)=>St(this,t,e)),this.#n(En,"bindings",_c,(t)=>Pe(this,t,e)),this.#n(_n,"compute",xc,(t)=>tt(this,t,e)),this.#n(Yo,"sortable",kc,(t)=>on(this,t)),this.#n(Vo,"presence",Uo,(t)=>cn(this,t)),this.#n(Xo,"countdown",Tc,(t)=>dn(this,t))}#n(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#q(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#q(t,"connect",o)}}#X(){{let e=this.#o;this.#_=this.#o=0;let t=this.#e();if(e&Ko)this.#r("persist",()=>vt(this,t));if(e&wn)this.#r("defer",()=>Qt(this,t));if(e&Sn)this.#r("form",()=>Et(this,t));if(e&En)this.#r("bindings",()=>Ie(this,t));if(e&_n)this.#r("compute",()=>nt(this,t));if(e&Yo)this.#r("sortable",()=>sn(this,t));if(e&Vo)this.#r("presence",()=>un(this,t));if(e&Xo)this.#r("countdown",()=>pn(this,t))}}#r(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Ce(e){}#Me(e,t){}#$e(e){}#Pe(e,t){}#Ie(e,t,n,r){}#e(){return this.#P??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#D(),proceed:(e,t,n,r)=>this.#k(e,t,n,0,0,null,r),forgetToken:()=>{this.#h=void 0},owns:(e)=>this.#y(e),ownership:()=>this.#R(),opTargets:(e)=>this.#C(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>Rn(e,(n)=>this.#C(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#H(),plain:si,text:F,served:Dn,copyMedia:Ai,setValue:yi,confirm:(e,t)=>Promise.resolve().then(()=>xo(e,t)).catch(()=>!1)},this.#P}#D(){if(this.#o&Sn)_t(this);if(this.#o&En)De(this);if(this.#o&_n)rt(this)}#q(e,t,n){if(Rc(e,t,n),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#s("reactive:error",{kind:"feature",feature:e,phase:t,error:n})}#De(){}#Z(){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.#Q()}#x=new Set;#Q(){let{queue:e}=xn();if(e.length===0)return;let t=[];for(let o=e.length-1;o>=0;o--){let{root:i}=e[o];if(i===this.element||!i.isConnected)t.unshift(...e.splice(o,1))}let n=Cc(),r=new Map;for(let o of t){let i=r.get(o.event)??[new Set,new Set];r.set(o.event,i);let a=i[+!!o.win];if(a.has(o.el))continue;a.add(o.el);let s=o.win?Math.min(Fc,n):n,c=o.root!==this.element?"its root left the page before a controller connected":performance.now()-o.at>s?`it is older than the ${s} ms ${o.win?"window-trigger":"early-event"} TTL`:o.el.isConnected&&this.element.contains(o.el)?null:"its element left the root before the controller connected";if(c){if(this.#F())console.warn(`[phlex-reactive] dropped an early "${o.event.type}" trigger: ${c}`);continue}this.#ee(o)}}#ee({event:e,el:t,descs:n,win:r}){let o=$c(e,t,r),i=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!Ne(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Pc(s,c,r&&JSON.stringify(o.params)))continue;this.#x.add(s)}if(Ic(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#X(),this.#se(),this.#ce(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(Ee,this.#t);xn().connected.delete(this.element),this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#x)Oe.delete(e);this.#x.clear()}dispatch(e){let t=e.params?.shortcut;if(t!=null&&!An(t,e,this.application?.schema?.keyMappings))return;if(Zo(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:o,throttle:i,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:l}=e.params;if(!n)return;let f=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if((t!=null||!u)&&!this.#Ae(l,p))e.preventDefault();if(n===Va){let v=()=>{if(this.#o&wn)return me(this);if(this.tokenValue)return this.#k(p,n,"{}")};return this.#Y?this.featuresReady.then(v):v()}let b=this.#W(a,s),g=()=>this.#k(p,n,r,o,i,l,f);if(!b)return g();if(b instanceof Promise)return b.then((v)=>v?this.#g(v,p,g):g());this.#g(b,p,g)}#g(e,t,n){return Promise.resolve().then(()=>xo(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#W(e,t){if(e)return e;if(!t)return null;return We(this,this.#e(),t)}#te(e){}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!An(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Zo(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(Ac(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=bc(n.ops),i=o.filter((s)=>Wo(s,e,null)),a=i.length<=1?i:i.filter((s)=>Wo(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#F())Wt(this,e);return}for(let s of a){if(s.outside&&e[X])continue;if(!vc(s,e))continue;if(s.shortcut!=null&&!An(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(yc(this,e,s))continue;this.#ne(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0}:s,e,r,o.indexOf(s))}}#ne(e,t,n,r){let{ops:o,confirm:i,confirmWhen:a,outside:s,window:c,shortcut:u}=e;if(s&&this.element.contains(t.target))return;if(u!=null||!c)t.preventDefault();let l=this.#W(i,a),f=this.#re(e,r,n,()=>this.#ye(this.#ve(o)));if(!l)return f();if(l instanceof Promise)return l.then((p)=>p?this.#g(p,n,f):f());this.#g(l,n,f)}#re(e,t,n,r){let o=Number(e.debounce)||0,i=Number(e.throttle)||0;if(o<=0&&i<=0)return r;let a=JSON.stringify([t,e]);if(o>0)return()=>this.#j(n,a,o,r);return()=>this.#B(n,a,i,r)}recompute(e){return ot(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return Ge(this,this.#e(),e)}tagsPick(e){return Ke(this,this.#e(),e)}tagsRemove(e){return Ye(this,this.#e(),e)}nestedAdd(e){return Ve(this,this.#e(),e)}nestedRemove(e){return Xe(this,this.#e(),e)}syncNestedJson(e){return qe(this,this.#e(),e)}#qe(e,t){}trackDirty(){se(this,this.#e())}listnavNext(e){this.#b(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#b(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#b(e,()=>0)}listnavLast(e){this.#b(e,(t,n)=>n-1)}listnavPick(e){let t=this.#m(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#m(e))t.removeAttribute("data-reactive-highlighted")}#b(e,t){let n=this.#m(e);if(!n.length)return;e.preventDefault();let r=this.#oe(e),o=globalThis.document?.activeElement,i=r?n.findIndex((s)=>s===o||o!=null&&s.contains?.(o)):n.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=n[t(i,n.length)];if(r)a.focus?.();else{for(let s of n)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#oe(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#m(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#R();return Array.from(this.element.querySelectorAll(n)).filter((o)=>!o.hidden&&r(o))}#k(e,t,n,r,o,i,a){if(this.#s("reactive:before-dispatch",{action:t,params:this.#z(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ie(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#ae(e,u,t,n,i,a);return this.#v(t,n,i,e,a)}#v(e,t,n,r,o){let i={inverse:null,undo:[],resurrect:null},a=this.#we(e,r,i),s=Boolean(n||o),c=(p)=>{if(!s||!p)return;let b=this.#e();if(i.inverse=Jt(this,b,n,r),i.undo.push(...Bt(this,b,o,r)),this.#L())i.resurrect=Ut(this,b,n,r)},u=!0;c(!0);let l=()=>this.#de(e,t,i,a),f=()=>this.#$?this.#$.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#We(){return this.#te("hints")}#ie(e,t,n,r,o,i){this.#j(e,Nc,t,()=>this.#v(n,r,o,e,i))}#j(e,t,n,r){this.#T(e,t);let o=()=>{this.#T(e,t),r()},i=setTimeout(o,n);if(!Wn(e))e?.addEventListener?.("blur",o,{once:!0});let a=this.#f.get(e);if(!a)this.#f.set(e,a=new Map);a.set(t,{timer:i,flush:o})}#T(e,t){let n=this.#f.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#f.delete(e)}#se(){for(let[e,t]of[...this.#f])for(let n of[...t.keys()])this.#T(e,n)}#ae(e,t,n,r,o,i){return this.#B(e,n,t,()=>this.#v(n,r,o,e,i))}#B(e,t,n,r){let o=this.#d.get(e)??new Map;if(o.has(t))return;let i=setTimeout(()=>{if(o.delete(t),o.size===0)this.#d.delete(e)},n);return o.set(t,i),this.#d.set(e,o),r()}#ce(){for(let e of this.#d.values())for(let t of e.values())clearTimeout(t);this.#d.clear()}#s(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#a(e,t,n,r){let o=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#v(e,t)};this.#s("reactive:error",{action:e,params:n,...r,retry:o})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#ue(){this.element?.removeAttribute?.("data-reactive-error")}#le(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#fe(){return $t()}#L(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#J(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#de(e,t,n,r){let{fields:o,files:i}=this.#H(),a=this.#z(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#ge(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#L()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#J()}:null;await this.#fe();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let p;try{let h={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#ke()};if(!u)h["Content-Type"]="application/json";let d=this.#Te();if(d)h["X-Pgbus-Connection"]=d;let y=Uo(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(y)h["X-Reactive-Presence"]=y;let A=Ka(this.element);if(A)h["X-Reactive-Held"]=A;pi("action"),p=await fetch(this.#_e(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#xe())})}catch(h){if(console.error("[phlex-reactive] action error",h),this.#u(n.inverse),h?.name==="TimeoutError"||h?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#le(),this.#i("network"),this.#a(e,t,s,{kind:"network"});return}if(f)f.status=p.status;if(p.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#u(n.inverse),this.#i("redirected"),this.#a(e,t,s,{kind:"redirected",status:p.status});return}if(!p.ok){let h=await p.text();if(console.error(`[phlex-reactive] action failed: HTTP ${p.status}`,h),this.#u(n.inverse),(p.headers.get("Content-Type")||"").includes("turbo-stream")){let d=this.#U(h);if(this.#c=d??this.#c,f)ce(f,h,d);Co(this.element,h,!1)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:p.status,body:h});return}let b=p.headers.get("Content-Type")||"";if(!b.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${b}" — no update applied`),this.#u(n.inverse),this.#i("content-type"),this.#a(e,t,s,{kind:"content-type",status:p.status});return}let g=await p.text(),v=this.#U(g);if(this.#c=v??this.#c,f)ce(f,g,v);if(Co(this.element,g),n.resurrect)queueMicrotask(n.resurrect);return this.#ue(),this.#s("reactive:applied",{action:e,params:s,html:g}),g}catch(p){console.error("[phlex-reactive] action error",p),this.#u(n.inverse),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(r?.(),f)jt(this,{...f,ms:this.#J()-f.started})}}get#c(){return this.#h??this.tokenValue}set#c(e){this.#h=e}tokenValueChanged(){this.#h=void 0}#U(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#pe(t),o=e.match(n);if(o)return o[1];let i=e.match(r);if(i)return i[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#pe(e){let t=this.#M;if(t&&t.id===e)return t;let n=ec(e);return this.#M={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#y(e){return e.closest('[data-controller~="reactive"]')===this.element}#R(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#y(t)}#H(){let e={},t=[],n=this.#R(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!n(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else r.push(s)});let o=[];this.element.querySelectorAll(`[name]${ic}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#me(r),a=this.#he(r);for(let s of r)if(i.has(s.name)){let c=e[s.name]??(e[s.name]=[]);if(s.type==="checkbox"||s.type==="radio"){if(s.checked)c.push(s.value)}else if(s.type==="hidden"){if(!a.has(s.name))c.push(s.value)}else if(s.multiple&&s.options){for(let u of s.options)if(u.selected)c.push(u.value)}else c.push(s.value)}else if(s.type==="checkbox")e[s.name]=s.checked;else if(s.type==="radio"){if(s.checked)e[s.name]=s.value}else e[s.name]=s.value;return o.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?F(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!ac(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}}#me(e){let t=new Set;for(let n of e){if(n.type==="radio")continue;if(String(n.name).endsWith("[]"))t.add(n.name)}return t}#he(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#ge(e,t,n,r){let o=new FormData;o.append("token",e),o.append("act",t);let i=[];for(let[s,c]of Object.entries(n))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)i.push(String(s).slice(0,-2));else{let u=`${this.#A(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#O(o,this.#A(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#be(r);for(let{name:s,file:c,multiple:u}of r){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),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((o)=>`[${o}]`).join("")}`}#O(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#O(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#O(e,`${t}[${r}]`,o);else e.append(t,String(n))}#be(e){let t=new Map;for(let{name:n}of e)t.set(n,(t.get(n)??0)+1);return new Set([...t].filter(([,n])=>n>1).map(([n])=>n))}#z(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#ve(e){return qn(e)}#ye(e){Rn(e,(t)=>this.#C(t),(t,n)=>this.#N(`client op "${t}"`,n))}#F(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#L()}#N(e,t){if(!this.#F())return;qt(this,e,t)}#je(e){}#C(e){let t=e.to;if(t==="@root")return[this.element];if(typeof t!=="string"||t==="")return[];if(e.global)return[...document.querySelectorAll(t)];return[...this.element.querySelectorAll(t)].filter((n)=>this.#y(n))}#Ae(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#we(e,t,n){this.#Se(e,t),ui();let r=!1;return()=>{if(r)return;r=!0,this.#Ee(e,t),li();for(let o of n.undo)o()}}#Se(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#p.set(e,(this.#p.get(e)??0)+1),this.#S++===0)this.element.setAttribute("aria-busy","true");for(let n of this.#G(e))this.#l(n,e,1)}#Ee(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#p.get(e)??1)-1;if(n<=0)this.#p.delete(e);else this.#p.set(e,n);if(--this.#S<=0)this.#S=0,this.element.removeAttribute("aria-busy");for(let r of this.#G(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#E.get(e)??new Map,o=(r.get(t)??0)+n;if(o<=0)r.delete(t);else r.set(t,o);if(r.size===0){this.#E.delete(e),e.removeAttribute("data-reactive-busy");return}this.#E.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#G(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#y(n))}#_e(){return this.#K??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#xe(){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}#ke(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Te(){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)$o();else document.addEventListener("turbo:load",$o,{once:!0});Pn();var ou=wi;export{ci as ACTIVE_ATTR,ic as EDITOR_SELECTOR,sc as EDITOR_TAGS,ta as LATENCY_KEY,di as REQUESTS_ATTR,tc as checkReactiveRegistration,pi as countReactiveRequest,ou as default,Wr as disableLatencySim,F as editableValue,qr as enableLatencySim,ui as enterReactiveActivity,ec as escapeRegExp,li as exitReactiveActivity,Kc as loadReactiveFeature,Jc as onReactiveStreamWithoutEffects,Uc as reactiveActivityCount,Yc as reactiveFeatureNames,$o as registerReactiveActions,$a as registerReactiveDefer,Pn as registerReactiveDev,Ia as registerReactiveDismiss,Ia as registerReactiveEffects,Lc as registerReactiveFeature,zc as registerReactiveFeatureLoader,Ja as registerReactiveImageFallback,Ma as registerReactiveJs,Ba as registerReactiveKeep,ja as registerReactiveModals,Ha as registerReactiveMorphFocus,Xa as registerReactiveOffline,Ua as registerReactivePlaintext,Ia as registerReactiveStreamRender,Ca as registerReactiveToken,Na as registerReactiveVisit,Hc as resetReactiveActivity,Dn as serverText,Gc as unloadedFeaturesFor};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=CBF72DB61A6E762B64756E2164756E21
|
|
9
9
|
//# sourceMappingURL=reactive_controller.min.js.map
|