phlex-reactive 0.16.0 → 0.16.1
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 +247 -145
- data/README.md +85 -1
- data/app/controllers/phlex/reactive/actions_controller.rb +10 -0
- data/app/javascript/phlex/reactive/core.js +1 -0
- data/app/javascript/phlex/reactive/core.min.js +4 -4
- data/app/javascript/phlex/reactive/core.min.js.map +4 -4
- data/app/javascript/phlex/reactive/features/bindings.js +81 -4
- 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/drag.js +522 -0
- data/app/javascript/phlex/reactive/features/drag.min.js +4 -0
- data/app/javascript/phlex/reactive/features/drag.min.js.map +10 -0
- 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 +7 -6
- data/app/javascript/phlex/reactive/runtime.js +57 -23
- data/lib/phlex/reactive/component/css_vars_binding.rb +118 -0
- data/lib/phlex/reactive/component/drag.rb +270 -0
- data/lib/phlex/reactive/component/helpers.rb +5 -1
- data/lib/phlex/reactive/engine.rb +6 -4
- data/lib/phlex/reactive/held_fields.rb +21 -1
- data/lib/phlex/reactive/response.rb +55 -4
- data/lib/phlex/reactive/test_helpers.rb +6 -0
- data/lib/phlex/reactive/version.rb +1 -1
- data/sig/phlex/reactive/response.rbs +3 -0
- metadata +6 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{Controller as Ia}from"@hotwired/stimulus";import{confirmResolver as Lo}from"phlex/reactive/confirm";import{confirmPredicate as Ri}from"phlex/reactive/confirm_predicate";var M=new WeakMap,Ie=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)Ie.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 De(e,t){let n=k(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&Ci(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")Ui(n,s.target);else n.groups=Bi(n),Vn(n);zn(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]"))zn(n)}),I(n,n.show);if(!n.arm&&Mi(n))S(n,"input change",(s)=>Hn(n,s)),I(n,n.arm=()=>{Hn(n,null),Vn(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)=>Gi(n,s)&&D(n)),I(n,()=>D(n));if(!i&&(i=ne(n)))I(n,()=>cr(n));if(!a&&(a=Ki(n)))S(n,"input change",(s)=>dr(n,s)),I(n,()=>Ke(n))})(),S(n,"keydown",(s)=>ls(n,s)),S(n,"paste drop",(s)=>fs(n,s)),S(n,"input",(s)=>ds(n,s))}function qe(e){let t=M.get(e);if(!t)return;M.delete(e),Ie.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function We(e){let t=M.get(e);if(!t)return;for(let n of t.seeds)n();t.wire()}function R(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function je(e,t,n){return dr(k(e,t),n)}function Be(e,t,n){return br(k(e,t),n)}var Li=/^#[A-Za-z_][\w-]*$/,Zn="[data-reactive-show-field], [data-reactive-show]";function Oi(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 pr){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return hr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function Qn(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 Fi(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 er(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 Ni(e,t)}function Ni(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)=>et(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function Q(e,t="show"){if(typeof e==="string"&&Li.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function Ci(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?.(Zn)??[];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?.(or)??[])if(e.core.owns(n))return!0;return!1}function Mi(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function $i(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:Fi(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function Hn(e,t){let n=$i(e);if(!n.length)return;let r=rr(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 zn(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=rr(e,t),o=[];for(let i of e.root.querySelectorAll(Zn)){if(!t(i))continue;let a=i.getAttribute("data-reactive-show");if(a!==null){let l=er(Qn(a),r);if(l===null)continue;let f=i.getAttribute("data-reactive-show-after"),p=l&&(f==null||!!e.touched?.has(Je(f,n)));Gn(i,p,t,n);let b=(e.shown??=new WeakMap).get(i);if(e.shown.set(i,p),Pi.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=Oi(i,c);if(u===null)continue;Gn(i,u,t,n)}if(e.groups)Hi(e,r,t,n);ji(e,r,t),Di(e,r),zi(e,r);for(let i of o)Ii(e,i,t,n)}var Pi=["clear","focus","scroll"];function Ii(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,R(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 Gn(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 Di(e,t){let n=tr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){qi(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)=>et(l,a))}else{let l=gr(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 qi(e,t,n){if(!Q(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=cs(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!us(r))return;let i=q(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function tr(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 Wi(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(nr(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 nr(e,t){return`[name="${Je(e,t)}"]`}function Je(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function rr(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?Ue(e,o,t,n).filter((s)=>s.checked).length:Wi(e,o,t,n));return r.get(a)}}var or="[data-reactive-media]";function ji(e,t,n){for(let r of e.root.querySelectorAll(or)){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"){Kn(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?Yn(e,o.pool[u])[0]:null,p=e.core.copyMedia(r,f??null);if(p===null)continue;if(Kn(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 Yn(e,o.label))if(g.textContent!==b)g.textContent=b}}function Kn(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function Yn(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 Bi(e){return!!e.root.querySelector?.(te)}function Ue(e,t,n,r,o){return[...e.root.querySelectorAll(nr(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Ji(i.getAttribute("data-reactive-group"),o)))}function Ji(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Ui(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))ir(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function He(e,t,n){if(!t)return;let r=Ie.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};ir(r,t,n!==!1),r.show?.()}function ir(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=Ue(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 Hi(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=er(Qn(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=Ue(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 zi(e,t){for(let[n,r]of Object.entries(tr(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 Vn(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 Gi(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 Ki(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function ze(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 Ge(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 sr(e,t){let n=ze(e);if(!n)return!1;let r=Ge(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)ar(e,n,r);return i}function ar(e,t,n){t.value=n.join(","),R(t),cr(e)}function Yi(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 cr(e){let t=ze(e);if(!t)return;let n=Ge(t),r=e.core.ownership();Vi(e,n,r),Xi(e,n,r)}function Vi(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 Xi(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 Qi(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 es(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 ts(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)=>lr(p.getAttribute?.("name"))===c);if(!f)continue;ns(f,l),s.push(l)}if(r)for(let c of s)rs(c);return s[0]??null}function ns(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:$e(t)!=="";else e.value=$e(t);R(e)}function rs(e){if(e.type==="checkbox")e.checked=!1;else e.value="";R(e)}function os(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function Xn(e,t){let n=[...t.querySelectorAll?.('input[name$="[_destroy]"]')??[]][0];if(n)n.value="1",R(n),t.hidden=!0;else t.parentNode?.removeChild?.(t);Ke(e)}function Ke(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))fr(e,n.getAttribute("data-reactive-nested-json"))}function is(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 ur(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=lr(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=$e(o)}return n}function lr(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function $e(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function fr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=is(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(ur(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,R(o)}function Ye(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(!sr(r,String(o.value??"").split(",")))return;if(o.value="",ee(r))D(r)}function Ve(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(!sr(r,[i]))return;let a=Yi(r);if(!a)return;a.value="",D(r),a.focus?.()}function Xe(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=ze(r);if(!a)return;let s=Ge(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;ar(r,a,c)}function Ze(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){es(r,i);return}let l=u.cloneNode(!0);Qi(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=ts(r,l,f,p);if(f)b?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)fr(r,i)}function Qe(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?br(r,s):null);if(!c)return Xn(r,i);let u=ur(r,i),l=os(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)Xn(r,i)})}function dr(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;Ke(e)}var pr=["gte","gt","lte","lt"],ss=["len_eq","len_gte","len_gt","len_lte","len_lt"],mr=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],as=["digits_eq","digits_gte","digits_lt","digits_lte"];function Pe(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 hr(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 gr(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 pr)if(n in e)return hr(n,e[n],t);for(let n of ss)if(n in e)return Pe(n,e[n],[...String(t??"")].length);return null}function et(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=mr.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Pe(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=as.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)=>Pe(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return gr(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)=>et(r,t)))}function cs(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 us(e){return e.flat().every((t)=>mr.some((n)=>(n in Object(t))))}function br(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=Ri(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 tt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function ls(e,t){let n=tt(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),R(n),n.blur()}function fs(e,t){let n=tt(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 ds(e,t){let n=tt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as ps}from"phlex/reactive/compute";var j=new WeakMap;function wr(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 rt(e,t,n,r){let o=wr(e,t),i=Rs(o);if(i)o.seed=()=>nt(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)nt(o)}function ot(e){let t=j.get(e);if(!t)return;if(j.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function it(e){j.get(e)?.seed?.()}function st(e,t,n){return nt(wr(e,t),n)}var ms=Object.freeze({el:null,kind:""}),hs=/^#[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 Sr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function gs(e,t){if(t==="string")return W(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Sr(W(e));if(n)return e.el.checked?1:0;let r=Number(W(e));return Number.isFinite(r)?r:0}function bs(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Sr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return vs(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function vs(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 ys(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 As(e){if(typeof e==="string"&&hs.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function ws(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 Ss(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 Es(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 _s(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=xs(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function xs(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function yr(e,t,n){let r=String(n);for(let o of ks(e,t)){if(o.textContent===r)continue;o.textContent=r}}function ks(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function Ar(e,t,n){let r=Ts(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(!As(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function Ts(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 Rs(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function nt(e,t){if(t&&e.ours.has(t))return;let n=Es(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:""}:ms;return s.set(h,N),N};for(let h of r)yr(e,h,W(c(h)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?ps(u):null;if(!l){Ar(e,{},c);return}let f=Ss(e,"data-reactive-compute-outputs-param"),p={};for(let[h,d]of n)p[h]=gs(c(h),d);let b=l(p,{changed:_s(e,t,r,o)})||{},g=ys(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=bs(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;yr(e,h,d)}Ar(e,b,c);for(let h of v){let d=new Event("input",{bubbles:!0});e.ours.add(d),h.dispatchEvent(d)}ws(e,g,Boolean(t))}var lt;function ft(e){lt=e}var Tr=1,Ls="phlex-reactive:persist:",Os=new Set(["hidden","file","password","submit","button","reset","image"]),dt=Symbol("persist-no-value"),pt="data-reactive-persist-state",Fs=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Ns=new Set(["lexxy-editor","trix-editor"]),Cs="lexxy-editor, trix-editor, trix-toolbar",Ms=["lexxy:change","trix-change"],$s=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),_r=new WeakSet,xr=new WeakSet,kr=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(!_r.has(e))_r.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function mt(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function ht(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||xr.has(e))return;xr.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function gt(e){return Ls+e.key}function ct(e,t){let n=mt(t);if(!n)return null;let r;try{r=n.getItem(gt(t))}catch(c){return ht(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Tr)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 Rr(e,t,{fields:n,state:r}){let o=mt(t);if(!o)return!1;let i={v:Tr,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(gt(t),JSON.stringify(i)),!0}catch(a){return ht(e,a),!1}}function re(e,t){e?.removeAttribute?.(pt);let n=mt(t);if(!n)return;try{n.removeItem(gt(t))}catch(r){ht(e,r)}}function bt(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)||Os.has(i.type)||i.closest(Cs))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(Fs)){if(!o(i))continue;let a=Ps(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Ns.has(i.localName)?"editor":"contenteditable"})}return r}function Lr(e){return e.hasAttribute("data-reactive-editable")?lt.text(e):e.textContent??""}function Ps(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function vt(e){return typeof e.value==="string"}function Is(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return $s.has(e.value.trim())}function Ds(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||kr.has(e))return;kr.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 Or(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 Fr(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return dt;return e[0]}function Nr(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 bt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(vt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=Lr(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 qs(e,t,n){let r=t.restore==="always",o=bt(e,t),i=Or(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=Fr(l,c,i),l===dt)continue}if((s.type==="checkbox"||B(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")Cr(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&Lr(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)}}Ws(e,t,n)}function Cr(e,t,n,r,o){if(Array.isArray(r))return;if(!vt(t))return;if(!o&&!Is(t))return;try{t.value=String(r)}catch(i){Ds(e,n,i)}}function Ws(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(!vt(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=bt(e,t),c=Or(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let p=Fr(n[l],l,c);if(p===null||p===void 0||p===dt)continue;Cr(e,u,l,p,i)}})}function js(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=ct(e,r),i={...o?.state??{},...t},a=n?Nr(e,r):o?.fields??{};if(Rr(e,r,{fields:a,state:i}))e.setAttribute?.(pt,JSON.stringify(i))}function Bs(e){let t=oe(e);if(t)re(e,t)}var ut=new WeakMap,at=new WeakMap;function Js(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=at.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],at.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),at.delete(e)}}function yt(e,t,n,r){let o=e.element,i=oe(o);if(!i)return;if(r?.submitted)re(o,i);let a=ct(o,i);if(a){if(qs(o,i,a.fields),a.state)o.setAttribute?.(pt,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=ct(o,i);Rr(o,i,{fields:Nr(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",...Ms];for(let g of p)o.addEventListener?.(g,l);o.addEventListener?.("change",u);let b=Js(globalThis.document,f);if(ut.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 At(e){let t=ut.get(e);ut.delete(e),t?.()}function Mr(e,t){let n=lt?.waiting.get(e)?.persist;if(!n||!oe(e))return t(!0);(n.ops??=[]).push(t)}function wt(e,t){Mr(e,(n)=>js(e,t,n))}function St(e){Mr(e,()=>Bs(e))}var ie=new WeakMap,Pr=new WeakSet,Et=new WeakMap;function _t(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=Us(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")Gs(n,r)}if(!s&&(s=Ks(n,t))){let u=()=>Ys(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 xt(e){for(let t of ie.get(e)?.[0]??[])t();ie.delete(e)}function kt(e){ie.get(e)?.[1]()}function Us(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,Hs(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 Hs(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 zs(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Gs(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Et.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if(zs(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(Pr.has(c)||!i())return;if(Pr.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),Et.delete(n)}},Et.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Ks(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 Ys(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 Ot(e){Vs(e),Zs(e)}function Vs(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Tt);else setTimeout(Tt,0);return}let r=async(o)=>{await n(o),Tt()};r.__reactiveDismissWrapped=!0,t.render=r}function Tt(){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 Xs=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),Rt=Object.freeze(["fade","slide","scale","highlight","shake"]),Lt="data-reactive-fx-pending",Ft=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=Xs[r?.getAttribute?.("action")];if(!o||ta())return;let i=Qs(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await oa(ae(r),i),await n(s)}:async(s)=>{let c=o==="enter"?na(r):null;if(await n(s),o==="enter")ra(c,i);else qr(ae(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Qs(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return Dr(n,t);let o=(t==="enter"?ea(e):ae(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?Dr(o,t):null}function ae(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function ea(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function Dr(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"?Rt[Math.floor(Math.random()*Rt.length)]:e;if(!Rt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function ta(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function na(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Lt,"");return ae(e)}function ra(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Lt}]`)))n.removeAttribute(Lt),qr(n,t)}async function oa(e,t){if(!e?.classList)return;if(t.legs){await Wr(e,t.legs);return}e.classList.add(t.className);let n=Nt(e);if(n<=0){e.classList.remove(t.className);return}await Ct(e,n),e.classList.remove(t.className)}function qr(e,t){if(!e?.classList)return;if(t.legs){Wr(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Nt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ct(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function Wr(e,t){let[n,r,o]=t.map(ia),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await sa(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Nt(e);if(a>0)await Ct(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function ia(e){return String(e??"").split(/\s+/).filter(Boolean)}function Nt(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,Ft)}catch{return 0}}function Ct(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,Ft))})}function sa(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Ft),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var aa="phlex-reactive:latency",Mt=!1;function Jr(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function Ur(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Mt=!1}function Pt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:Jr,disableLatencySim:Ur}}function It(){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(!Mt)Mt=!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 Br=new WeakMap;function Dt(e){let t=globalThis.document;if(!t)return!0;let n=Br.get(t);if(!n)n=new Set,Br.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 Hr(e,t,n,r){if(Dt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function qt(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`}Hr(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Wt(e){if(!Dt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function jt(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`}Hr(t,o,`scoped to #${r?.id||"?"}`,i)}function Bt(e,t){let n=e.element?.id||"?";if(Dt(`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 ca(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=ca(t),e.tokenRefreshed=n!=null}var ue=new WeakMap;function Ut(e,t,n,r){let o=n&&typeof n==="object"?fa(n):n;return o?Gr(t,o,r,!1):[]}function Ht(e,t,n,r){if(!n)return null;let o=Gr(t,n,r,!0);return o.length?o:null}function Gr(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(ua(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 ua(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()=>la(t,e)}function la(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 fa(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function zt(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 de;function Yt(e){de=e}var _=new Map;function Zr(e,t){let n=!_.has(e);if(_.set(e,t),n)de.enter()}function pe(e){if(_.delete(e))de.exit()}var Vr=!1;function Vt(e){Qr();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){ba(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;U(t,n)}function Qr(){if(Vr||typeof document>"u"||!document.addEventListener)return;Vr=!0,document.addEventListener("turbo:before-stream-render",ya,!0),document.addEventListener("turbo:before-stream-render",da)}function da(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}Zt(e),ro(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return Zr(e,r),va(e,r,t)}function pa(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[wa(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":Sa()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function eo(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(to(t))return{src:t};return console.error(ma(t)),ha(t)||ga(e)}function ma(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${Xt()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function ha(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${Xt()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&to(r))return{src:r,fallback:!0}}function ga(e){Zt(e.id),Qt(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 to(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${Xt()}/`)}catch{return!1}}function Xt(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function ba(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}Zt(e),ro(n);let o=document.createElement("pgbus-stream-source");o.id=no(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),Zr(e,{via:"stream"})}function no(e){return`reactive-defer-src-${e}`}async function va(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},Ea()),o;try{de.count("defer"),o=await fetch(...pa(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),Xr(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;Xr(e),Aa(a)}var Kt=null,ya=(e)=>Kt?.push(e);function Aa(e){let t=Kt=[];try{window.Turbo.renderStreamMessage(e)}finally{Kt=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 Zt(e){let t=_.get(e);if(!t)return;if(pe(e),t.via==="fetch")t.abort.abort();else document.getElementById(no(e))?.remove?.()}function ro(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function Qt(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function Xr(e){pe(e);let t=document.getElementById(e);if(!t)return;Qt(t),t.removeAttribute("data-reactive-error")}function J(e,t,n){pe(e);let r=document.getElementById(e);if(!r)return;Qt(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 wa(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function Sa(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function Ea(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var oo="__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 en(e,t,n){Qr();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=eo(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&_a(r,t))return;let y=d?U(r.id,d):t.proceed(r,oo,"{}");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)Gt(r),c=(d)=>d.target===r&&Gt(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)Gt(r);g()},r.addEventListener?.("turbo:morph-element",u),n)return g();if(o=le(r)!==null,o)f(!1)}function tn(e){let t=fe.get(e);fe.delete(e),t?.off()}function me(e){return fe.get(e)?.load()}function _a(e,t){return t.emit("reactive:before-dispatch",{action:oo,params:{},element:e},{cancelable:!0}).defaultPrevented}function Gt(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||eo(e);if(t)U(e.id,t)}var nn=new WeakMap,ge=new WeakMap,m=null,L,so;function an(e,t){let n=e.element;ge.set(n,t),go();let r=(i)=>ka(i,t),o=(i)=>Fa(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),nn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function cn(e){if(nn.get(e)?.(),nn.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"]'),lo=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),T=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==m?.row&&lo(t)===e),ao=(e)=>H(w(e,"-item"),null),rn=(e)=>w(e,"-disabled")==="true",xa=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},fo=(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&&!rn(n)&&ge.has(be(n)))};function po(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&lo(n);if(m||!r||!t.owns(r)||rn(r)||rn(n))return;if(be(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function ka(e,t){if(e.button>0||e.isPrimary===!1)return;let n=po(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 on(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return h();Ra(n,t,d),on(d.clientX,d.clientY)},f=(d)=>m&&d.cancelable&&d.preventDefault(),p=(d)=>{if(!a(d))return;if(h(),m)Ta(),sn()},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 Ta(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Ra({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=mo({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 mo(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 on(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=fo(m.origin).find((r)=>xa(r,e,t));if(n)La(n,e,t);else if(m.source)un(null),m.placeholder.remove();Oa(e,t)}function un(e){if(m.target!==m.origin)z(m.target,!1);m.target=e,z(e,!0)}function La(e,t,n){un(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 Oa(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);on(m.x,m.y),m.raf=requestAnimationFrame(i)};m.raf=requestAnimationFrame(i)}}function Fa(e,t){let n=e.key;if(m?.keyboard){if(e.target!==m.row||m.core!==t)return;let o={" ":sn,Enter:sn,Escape:he,Tab:he,ArrowUp:()=>co(-1),ArrowDown:()=>co(1),ArrowLeft:()=>uo(-1),ArrowRight:()=>uo(1)}[n];if(!o)return;if(n!=="Tab")e.preventDefault();return o()}if(n!==" "&&n!=="Enter")return;let r=po(e.target,t);if(!r||r.item!==e.target||r.list.matches("[data-reactive-sortable-source]"))return;e.preventDefault(),m=mo({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Ae("picked")}function co(e){let t=T(m.target),n=ye()+e;if(n>=0&&n<=t.length)ve(m.target,t,n,m.row);ho()}function uo(e){let t=fo(m.origin),n=t[t.indexOf(m.target)+e];if(n){let r=ye();un(n),ve(n,T(n),r,m.row)}ho()}function ho(){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 go(){if(!L?.isConnected)L=document.createElement("div"),L.setAttribute("aria-live","polite"),L.setAttribute("data-reactive-sortable-live",""),L.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(L);return L}function Ae(e){let t=m.target??m.origin,n=(H(w(t,"-messages"),{})[e]??"").replaceAll("{position}",ye()+1).replaceAll("{count}",T(t).length+1),r=go();r.textContent="",cancelAnimationFrame(so),so=requestAnimationFrame(()=>r.textContent=n)}function sn(){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?ao(T(t)[s-1]):null;if(e.keyboard)Ae("dropped");if(!r&&i)i.replaceWith(o);if(vo(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:ao(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)=>Na(g,p)||bo(e))}function Na(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"))&&Ca(r,t))}function Ca(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(),vo(e),bo(e)}function bo({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 vo(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,Ao=new WeakSet;function ln(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,Ma(n);let o=(a)=>a.target===n&&queueMicrotask(()=>So(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)},So(r)}function fn(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 dn(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},Eo(n)}function Ma(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&Ao.has(n))return;if(n?.remove(),!wo())setTimeout(()=>{if(!wo())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;Eo(o),$a(o)}),Ao.add(r),document.body.appendChild(r)}var wo=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function $a(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&&_o(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 _o(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 So(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=_o(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 ko=new Map,pn=new WeakMap,Pa=0,we=new WeakMap;function mn(e,t){let n=e.element;if(!n.id&&!pn.has(n))pn.set(n,`#${++Pa}`);let r=n.id||pn.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);To(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)=>{To(b,"0:00","done"),u(g.waiting,!1),u(g.done,!0);let h=ko.get(v)??new Set;if(h.has(g.until))return;ko.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 hn(e){we.get(e)?.(),we.delete(e)}function To(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 Da(){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 qa(){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 Wa(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Jn(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)Wt(n);return}Fn(t,(i)=>kc(i,o),r?(i,a)=>qt(i,a,o):void 0)}}function ja(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){Vt(this)}}var Oo=!1,Ba=null;function Ja(){if(Oo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Oo=!0,document.addEventListener("turbo:before-stream-render",(e)=>{tc(e),Ua(e),za(e),Ot(e)})}var xe="reactive:streamed";function Ua(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(xe))}}function Mn(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function $n(e){try{return e.matches(":modal")}catch{return!1}}function ii(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||$n(e))return;if(e.open)e.close();e.showModal()}function Ha(e){if(Mn(e)&&e.open)e.close()}function Le(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&&!$n(r))ii(r)}function za(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),Le(document)}}var Fo=!1;function Ga(){if(Fo)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Fo=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Le(t.target)}),document.addEventListener("turbo:morph",()=>Le(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||!$n(n))return;e.delete(n),t.preventDefault(),n.close()})}var Rn=new WeakMap;function si(e,t,n,r){let o=Rn.get(e)??new Map;Rn.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"))Si(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}))si(a,"set_attr",{name:"aria-expanded"})}}var No=!1;function Ka(){if(No)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;No=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of Rn.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 ai="data-reactive-image-fallback",G="data-reactive-image-state",Ln="data-reactive-image-hidden",gn=null,On="data-reactive-wrap-hidden";function ci(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(On,"")}function ui(e){if(!e.hasAttribute(On))return;e.removeAttribute("hidden"),e.removeAttribute(On)}function K(e){if(e?.localName!=="img")return null;let t=e.getAttribute(ai);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var li=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Pn(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function fi(e,t){let n=Pn(e,t.alt);return n&&!n.contains(e)?n:null}function Oe(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Ln,"");if(t.wrap){let o=Pn(e,t.wrap);if(o)ci(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=fi(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Ce(e,t);e.setAttribute(G,n)}function Ce(e,t=K(e)){if(!t||e.getAttribute(G)==null)return;if(e.getAttribute(G)==="error"){if(e.hasAttribute(Ln))e.removeAttribute("hidden");let n=Pn(e,t.wrap);if(n)ui(n);let r=fi(e,t);if(r)r.hidden=!0}e.removeAttribute(G),e.removeAttribute(Ln)}function Co(e){let t=e.target,n=K(t);if(!n)return;if(e.type==="load")Oe(t,n,"loaded");else if(li(t))Oe(t,n,"error");else Ce(t,n)}function Ya(){if(gn)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;gn={error:Co,load:Co,"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)Oe(n,o,r)})}};for(let[t,n]of Object.entries(gn))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${ai}]`)??[]){if(!t.complete||!li(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&Oe(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 Yc(e){Ba=e}var Se,bn=null,Mo="[data-reactive-editable][contenteditable=plaintext-only]";function di(){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 ke(e){if(e.matches?.(Mo))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Mo).forEach(ke)}function Va(){if(bn||typeof document>"u"||typeof document.createElement!=="function")return;if(di())return;ke(document),bn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")ke(t.target);else t.addedNodes.forEach(ke)}),bn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var $o=!1;function Po(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 Xa(){if($o)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;$o=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=Po(t);if(r)Qa(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(Fe.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)=>jn(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===E)&&Po(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(E)&&Dn(t)===qn(t))t.removeAttribute(E)})}var E="data-reactive-held",In='[data-controller~="reactive"]',Te=null,P=new Map;function Dn(e){return e.hasAttribute("data-reactive-editable")?F(e):e.value}function qn(e){return e.hasAttribute("data-reactive-editable")?Bn(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 Qa(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||P.has(e.closest(In)))return;let r=Za(t);if(r===Dn(e))return e.removeAttribute(E);if(r===qn(e))return;e.setAttribute(E,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function ec(e){let t=[];for(let n of e.querySelectorAll(`[${E}]`)){if(n.closest(In)!==e)continue;let r=n.getAttribute("name");if(Dn(n)===qn(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 pi(e){for(let t of e.querySelectorAll(`[${E}]`))if(t.closest(In)===e)t.removeAttribute(E)}function Io(e,t,n=!0){let r={root:e,streams:0,release:n},o=Te;Te=r;try{window.Turbo.renderStreamMessage(t)}finally{Te=o}if(n&&r.streams===0)pi(e)}function tc(e){let t=Te,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)pi(t.root)}}}var Do="__materialize",qo=!1;function nc(){if(qo)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;qo=!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 Wn(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")Pt()}var mi="data-reactive-active",x=0;function hi(){if(x++,x===1)bi("reactive:busy")}function gi(){if(x===0)return;if(x--,x===0)bi("reactive:idle")}function Vc(){return x}function Xc(){x=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(mi)}function bi(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(mi,x>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:x}}))}var vi="data-reactive-requests";function yi(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!rc(t))return;let n=oc(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(vi,JSON.stringify(n))}function rc(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function oc(e){try{let t=JSON.parse(e.getAttribute(vi));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Wo(){Da(),qa(),Wa(),ja(),Ja(),Xa(),Ga(),Ka(),Ya(),Va(),nc(),Wn()}function ic(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Ai=Symbol.for("phlex-reactive.core");if(globalThis[Ai])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[Ai]=!0;var wi=!1;function sc(){if(wi)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(sc,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var ac=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Si(e){let t=String(e).toLowerCase();return t.startsWith("on")||ac.has(t)}var vn=new WeakMap;function cc(e,t,n){let[r,o,i]=t;vn.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,vn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};vn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,uc(e))}function uc(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 lc=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",fc=new Set(["lexxy-editor","trix-editor"]);function F(e){let t="",n=!1,r=(i)=>{if(n&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as Pc}from"@hotwired/stimulus";import{confirmResolver as pi}from"phlex/reactive/confirm";import{confirmPredicate as ps}from"phlex/reactive/confirm_predicate";var j=new WeakMap,ze=new WeakMap;function O(e,t){let n=j.get(e);if(!n){if(j.set(e,n={root:e.element,core:t,nestedIndex:0}),n.root)ze.set(n.root,n)}return n}function x(e,t,n){for(let r of t.split(" "))e.root.addEventListener?.(r,n),e.offs.push(()=>e.root.removeEventListener?.(r,n))}function G(e,t){x(e,"turbo:morph-element",t),e.seeds.push(t),t()}function Ke(e,t){let n=O(e,t);n.offs=[],n.seeds=[];let r,o,i,a;(n.wire=()=>{if(!n.show&&vs(n))n.show=(s)=>{if(n.flipping)return;if(s?.type==="input"||s?.type==="change")Ms(n,s.target);else n.groups=Ns(n),br(n);pr(n)},x(n,"input change",n.show),x(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]"))pr(n)}),G(n,n.show);if(!n.arm&&ys(n))x(n,"input change",(s)=>dr(n,s)),G(n,n.arm=()=>{dr(n,null),br(n)});if(!r&&(r=n.show||n.arm))x(n,"reset",()=>setTimeout(()=>{if(j.get(e)!==n)return;n.show?.(),n.arm?.()},0));if(!o&&(o=ue(n)))x(n,"input",(s)=>Ps(n,s)&&U(n)),G(n,()=>U(n));if(!i&&(i=fe(n)))G(n,()=>Lr(n));if(!a&&(a=Is(n)))x(n,"input change",(s)=>Mr(n,s)),G(n,()=>it(n))})(),x(n,"keydown",(s)=>Qs(n,s)),x(n,"paste drop",(s)=>ea(n,s)),x(n,"input",(s)=>ta(n,s))}function Ve(e){let t=j.get(e);if(!t)return;j.delete(e),ze.delete(t.root);for(let n of t.offs??[])n();t.groupObserver?.disconnect()}function Ye(e){let t=j.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 Xe(e,t,n){return Mr(O(e,t),n)}function Ze(e,t,n){return Dr(O(e,t),n)}var ms=/^#[A-Za-z_][\w-]*$/,yr="[data-reactive-show-field], [data-reactive-show]";function hs(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 Cr){let a=e.getAttribute(`data-reactive-show-${i}`);if(a!==null)return Pr(i,a,t)}return console.warn("[phlex-reactive] a reactive_show binding declares no predicate — skipped"),null}function wr(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 gs(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 Ar(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 z(n,t);return bs(e,t)}function bs(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)=>ft(i,t));return n==="all"?o.every(Boolean):o.some(Boolean)}function ce(e,t="show"){if(typeof e==="string"&&ms.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root ${t} target ${JSON.stringify(e)} — skipped`),!1}function vs(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?.(yr)??[];for(let n of t)if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(le)??[])if(e.core.owns(n))return!0;for(let n of e.root.querySelectorAll?.(`${xr}, ${_r}`)??[])if(e.core.owns(n))return!0;return e.root.hasAttribute?.("data-reactive-css-vars")??!1}function ys(e){return!!e.root.getAttribute?.("data-reactive-on-complete")}function ws(e){let t=e.root.getAttribute?.("data-reactive-on-complete")??null;if(t!==e.onCompleteRaw)e.onCompleteRaw=t,e.onCompleteParsed=t==null?[]:gs(t),e.onCompleteStates=e.onCompleteParsed.map(()=>!1);return e.onCompleteParsed}function dr(e,t){let n=ws(e);if(!n.length)return;let r=Er(e,e.core.ownership());n.forEach((o,i)=>{let a=z(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 pr(e){if(typeof e.root?.querySelectorAll!=="function")return;let t=e.core.ownership(),n=e.root.getAttribute?.("data-reactive-scope")||null,r=Er(e,t),o=[];for(let i of e.root.querySelectorAll(yr)){if(!t(i))continue;let a=i.getAttribute("data-reactive-show");if(a!==null){let l=Ar(wr(a),r);if(l===null)continue;let f=i.getAttribute("data-reactive-show-after"),p=l&&(f==null||!!e.touched?.has(et(f,n)));mr(i,p,t,n);let b=(e.shown??=new WeakMap).get(i);if(e.shown.set(i,p),As.some((h)=>i.hasAttribute(`data-reactive-show-${h}`))&&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=hs(i,c);if(u===null)continue;mr(i,u,t,n)}if(e.groups)Cs(e,r,t,n);ks(e,r,t),Ls(e,r,t,n),Es(e,r),$s(e,r);for(let i of o)Ss(e,i,t,n)}var As=["clear","focus","scroll"];function Ss(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)=>et(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,M(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 mr(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 Es(e,t){let n=Sr(e);for(let[r,o]of Object.entries(n)){if(r.startsWith("#")){xs(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(!ce(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)=>ft(l,a))}else{let l=Ir(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 xs(e,t,n){if(!ce(e))return;let r=t&&typeof t==="object"&&!Array.isArray(t)?t.any:null,o=Xs(r);if(o===null){console.warn(`[phlex-reactive] malformed reactive_show_targets conditions for ${e} — skipped`);return}if(o.every((a)=>n(a)===null)&&!Zs(r))return;let i=z(r,n);if(i===null)return;for(let a of document.querySelectorAll(e))a.hidden=!i}function Sr(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 _s(e,t,n,r){let o=!1,i=null;for(let a of e.root.querySelectorAll(Qe(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 Qe(e,t){return`[name="${et(e,t)}"]`}function et(e,t){return t&&!e.includes("[")?`${t}[${e}]`:e}function Er(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?tt(e,o,t,n).filter((s)=>s.checked).length:_s(e,o,t,n));return r.get(a)}}var xr="[data-reactive-media]";function ks(e,t,n){for(let r of e.root.querySelectorAll(xr)){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"){hr(r,"pending");continue}let f=!l&&Object.hasOwn(o.pool,u)?gr(e,o.pool[u])[0]:null,p=e.core.copyMedia(r,f??null);if(p===null)continue;if(hr(r,l?"pending":p===!1?"miss":"hit"),typeof o.label!=="string")continue;let b=l?"":p===!1?String(o.blank??""):p;for(let v of gr(e,o.label))if(v.textContent!==b)v.textContent=b}}function hr(e,t){if(e.getAttribute("data-reactive-media-state")!==t)e.setAttribute("data-reactive-media-state",t)}function gr(e,t){try{return t==="@root"?[]:e.core.opTargets({to:t})}catch{return[]}}var _r="[data-reactive-css-vars]",Ts=/^--[a-z0-9-]+$/i,Rs=["","px","%","deg","turn","ms","s","em","rem","fr"];function Ls(e,t,n,r){let o=[...e.root.querySelectorAll(_r)].filter(n);if(e.root.hasAttribute("data-reactive-css-vars"))o.unshift(e.root);for(let i of o){let a;try{a=JSON.parse(i.getAttribute("data-reactive-css-vars"))}catch{}if(!Array.isArray(a?.to)||!a.vars||typeof a.vars!=="object"){console.warn("[phlex-reactive] malformed data-reactive-css-vars — skipped (two reactive_css_vars on one element?)");continue}let s=a.to.flatMap((c)=>{let u={to:c,global:a.global===!0},l=[];try{l=e.core.opTargets(u)}catch{}if(!l.length)e.core.diagnose("reactive_css_vars",u);return l});for(let[c,u]of Object.entries(a.vars)){let l=u?.unit??"";if(!Ts.test(c)||!Rs.includes(l)||typeof u?.field!=="string"){console.warn(`[phlex-reactive] refused reactive_css_vars entry ${JSON.stringify(c)} — skipped`);continue}let f=Os(e,t,u.field,n,r);if(f===void 0)continue;let p=f===null?"":`${f}${l}`;for(let b of s){if(b.style.getPropertyValue(c)===p)continue;if(p)b.style.setProperty(c,p);else b.style.removeProperty(c)}}}}function Os(e,t,n,r,o){let i=t(n);if(i===null)return;if((i==="true"||i==="false")&&[...e.root.querySelectorAll(Qe(n,o))].some((s)=>r(s)&&s.type==="checkbox"))return i==="true"?1:0;let a=i.trim()?Number(i):NaN;return Number.isFinite(a)?a:null}var le="[data-reactive-enable], [data-reactive-select-all], [data-reactive-count]";function Ns(e){return!!e.root.querySelector?.(le)}function tt(e,t,n,r,o){return[...e.root.querySelectorAll(Qe(t,r))].filter((i)=>i.type==="checkbox"&&n(i)&&(!o||Fs(i.getAttribute("data-reactive-group"),o)))}function Fs(e,t){return e===t||!!e?.startsWith(`${t}.`)}function Ms(e,t){let n=t?.getAttribute?.("data-reactive-select-all");if(n&&e.core.owns(t))kr(e,n,t.checked,t,t.getAttribute("data-reactive-select-all-under"))}function nt(e,t,n){if(!t)return;let r=ze.get(e)??{root:e,core:{ownership:()=>(o)=>o.closest('[data-controller~="reactive"]')===e}};kr(r,t,n!==!1),r.show?.()}function kr(e,t,n,r,o){let i=e.root.getAttribute?.("data-reactive-scope")||null,a=tt(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 Cs(e,t,n,r){for(let o of e.root.querySelectorAll(le)){if(!n(o))continue;let i=o.getAttribute("data-reactive-enable");if(i!==null){let c=Ar(wr(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=tt(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 $s(e,t){for(let[n,r]of Object.entries(Sr(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(!ce(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(!ce(a,"group"))continue;let c=z(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 br(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?.(`${le}, [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 ue(e){return!!(e.root.getAttribute?.("data-reactive-filter-input")&&e.root.getAttribute?.("data-reactive-filter-option"))}function Ps(e,t){let n=e.root.getAttribute("data-reactive-filter-input");return!!n&&typeof t.target?.matches==="function"&&t.target.matches(n)}function U(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 fe(e){return!!e.root.getAttribute?.("data-reactive-tags-field")}function Is(e){if(typeof e.root?.querySelector!=="function")return!1;return!!e.root.querySelector("[data-reactive-nested-json]")}function rt(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 ot(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 Tr(e,t){let n=rt(e);if(!n)return!1;let r=ot(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(","),M(t),Lr(e)}function Ds(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 Lr(e){let t=rt(e);if(!t)return;let n=ot(t),r=e.core.ownership();qs(e,n,r),Ws(e,n,r)}function qs(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 Ws(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"),!ue(e))o.hidden=!1}}if(ue(e))U(e)}function js(e){return e.nestedIndex=Math.max(e.nestedIndex+1,Date.now()),e.nestedIndex}function Bs(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 Js(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 Hs(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)=>Nr(p.getAttribute?.("name"))===c);if(!f)continue;Gs(f,l),s.push(l)}if(r)for(let c of s)Us(c);return s[0]??null}function Gs(e,t){if(e.type==="checkbox")e.checked=t.type==="checkbox"?!!t.checked:Ge(t)!=="";else e.value=Ge(t);M(e)}function Us(e){if(e.type==="checkbox")e.checked=!1;else e.value="";M(e)}function zs(e,t){if(!e.includes("%{"))return e;return e.replace(/%\{(\w+)\}/g,(n,r)=>Object.prototype.hasOwnProperty.call(t,r)?t[r]:n)}function vr(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);it(e)}function it(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))Fr(e,n.getAttribute("data-reactive-nested-json"))}function Ks(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 Or(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=Nr(o.getAttribute?.("name"));if(i===null||i==="_destroy")continue;n[i]=Ge(o)}return n}function Nr(e){if(!e)return null;let t=e.match(/\[([^\][]+)\]$/);return t?t[1]:e}function Ge(e){if(e.type==="checkbox")return e.checked?e.value||"on":"";return e.value??""}function Fr(e,t){let n=e.core.ownership(),r=[...e.root.querySelectorAll(`[data-reactive-nested-list="${t}"]`)].find(n);if(!r)return;let o=Ks(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(Or(e,s))}let a=JSON.stringify(i);if(o.value===a)return;o.value=a,M(o)}function st(e,t,n){let r=O(e,t);if(!fe(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(!Tr(r,String(o.value??"").split(",")))return;if(o.value="",ue(r))U(r)}function at(e,t,n){let r=O(e,t);if(!fe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;if(!Tr(r,[i]))return;let a=Ds(r);if(!a)return;a.value="",U(r),a.focus?.()}function ct(e,t,n){let r=O(e,t);if(!fe(r))return;n?.preventDefault?.();let i=(n?.currentTarget??n?.target)?.getAttribute?.("data-reactive-tag-param");if(!i)return;let a=rt(r);if(!a)return;let s=ot(a),c=s.filter((u)=>u.toLowerCase()!==i.toLowerCase());if(c.length===s.length)return;Rr(r,a,c)}function ut(e,t,n){let r=O(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){Js(r,i);return}let l=u.cloneNode(!0);Bs(l,js(r)),s.appendChild(l);let f=o?.getAttribute?.("data-reactive-nested-from-param"),p=o?.getAttribute?.("data-reactive-nested-clear-param")==="true",b=Hs(r,l,f,p);if(f)b?.focus?.();else[...l.querySelectorAll?.("input, select, textarea")??[]][0]?.focus?.();if(s.getAttribute?.("data-reactive-nested-json")===i)Fr(r,i)}function lt(e,t,n){let r=O(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?Dr(r,s):null);if(!c)return vr(r,i);let u=Or(r,i),l=zs(c,u);return r.core.confirm(l,{el:o,row:i,fields:u}).then((f)=>{if(f)vr(r,i)})}function Mr(e,t){let n=t?.target;if(!n||!e.core.owns(n))return;it(e)}var Cr=["gte","gt","lte","lt"],Vs=["len_eq","len_gte","len_gt","len_lte","len_lt"],$r=["checked_eq","checked_gte","checked_gt","checked_lte","checked_lt"],Ys=["digits_eq","digits_gte","digits_lt","digits_lte"];function Ue(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 Pr(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 Ir(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 Cr)if(n in e)return Pr(n,e[n],t);for(let n of Vs)if(n in e)return Ue(n,e[n],[...String(t??"")].length);return null}function ft(e,t){if(!e||typeof e!=="object"||typeof e.field!=="string")return!1;let n=$r.find((i)=>(i in e));if(n){let i=t(e.field,!0);return Ue(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=Ys.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)=>Ue(s,e[s],i.length))&&i.startsWith(e.prefix??""))!==(e.negate===!0)}let o=t(e.field)??"";return Ir(e,o)===!0}function z(e,t){if(!Array.isArray(e)||e.length===0)return null;return e.some((n)=>Array.isArray(n)&&n.length>0&&n.every((r)=>ft(r,t)))}function Xs(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 Zs(e){return e.flat().every((t)=>$r.some((n)=>(n in Object(t))))}function Dr(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=ps(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=z(n.groups?.any,o)===!0;return i?n.message:null}function dt(e,t){let n=t.target?.closest?.("[data-reactive-editable]");return n&&e.core.owns(n)?n:null}function Qs(e,t){let n=dt(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 ea(e,t){let n=dt(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 ta(e,t){let n=dt(e,t);if(n?.firstChild&&e.core.text(n)==="")n.replaceChildren()}import{computeReducer as na}from"phlex/reactive/compute";var V=new WeakMap;function Br(e,t){let n=V.get(e);if(!n)V.set(e,n={root:e.element,core:t,ours:new WeakSet,opsSig:null});return n}function mt(e,t,n,r){let o=Br(e,t),i=ba(o);if(i)o.seed=()=>pt(o),o.root.addEventListener?.("turbo:morph-element",o.seed);if(i||r?.edited)pt(o)}function ht(e){let t=V.get(e);if(!t)return;if(V.delete(e),t.seed)t.root.removeEventListener?.("turbo:morph-element",t.seed)}function gt(e){V.get(e)?.seed?.()}function bt(e,t,n){return pt(Br(e,t),n)}var ra=Object.freeze({el:null,kind:""}),oa=/^#[A-Za-z_][\w-]*$/;function K({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 Jr(e){if(typeof e==="boolean")return e;if(e==null)return!1;let t=String(e);return t!==""&&t!=="0"&&t!=="false"}function ia(e,t){if(t==="string")return K(e);let n=e.kind==="checkbox";if(t==="boolean")return n?Boolean(e.el.checked):Jr(K(e));if(n)return e.el.checked?1:0;let r=Number(K(e));return Number.isFinite(r)?r:0}function sa(e,t,{el:n,kind:r},o,i){if(r==="checkbox"){let a=Jr(i);if(Boolean(n.checked)===a)return null;return n.checked=a,n}if(r==="radio")return aa(e,t,o,String(i));if(String(i)===n.value)return null;return n.value=i,n}function aa(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 ca(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 ua(e){if(typeof e==="string"&&oa.test(e))return!0;return console.warn(`[phlex-reactive] refused cross-root mirror target ${JSON.stringify(e)} — skipped`),!1}function la(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 fa(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 da(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 pa(e,t,n,r){let o=t?.target;if(!o?.name||typeof o.closest!=="function")return null;let i=ma(o.name,r);if(!n.includes(i))return null;return e.core.owns(o)?i:null}function ma(e,t){if(!t)return e;let n=`${t}[`;return e.startsWith(n)&&e.endsWith("]")?e.slice(n.length,-1):e}function Wr(e,t,n){let r=String(n);for(let o of ha(e,t)){if(o.textContent===r)continue;o.textContent=r}}function ha(e,t){let n=e.root.querySelectorAll(`[data-reactive-text="${t}"]`);return Array.from(n).filter((r)=>e.core.owns(r))}function jr(e,t,n){let r=ga(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?K(a):void 0;if(s===void 0||s===null)continue;let c=String(s);for(let u of Array.isArray(i)?i:[i]){if(!ua(u))continue;for(let l of document.querySelectorAll(u)){if(l.textContent===c)continue;l.textContent=c}}}}function ga(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 ba(e){return e.root.getAttribute?.("data-reactive-compute-seed")==="true"}function pt(e,t){if(t&&e.ours.has(t))return;let n=da(e),r=n.map(([m])=>m),o=e.root.getAttribute?.("data-reactive-scope")||null,i=(m)=>o&&!m.includes("[")?`${o}[${m}]`:m,a=e.core.ownership(),s=new Map,c=(m)=>{let d=s.get(m);if(d)return d;let w=null,A=null,q=null;for(let W of e.root.querySelectorAll(`[name="${i(m)}"]`)){if(!a(W))continue;let ae=W.type;if(ae==="checkbox"||ae==="radio"&&W.checked){q={el:W,kind:ae};break}if(ae==="radio")w??=W;else A??=W}if(!q)if(w)q={el:w,kind:"radio"};else q=A?{el:A,kind:""}:ra;return s.set(m,q),q};for(let m of r)Wr(e,m,K(c(m)));let u=e.root.getAttribute("data-reactive-compute-reducer-param"),l=u?na(u):null;if(!l){jr(e,{},c);return}let f=fa(e,"data-reactive-compute-outputs-param"),p={};for(let[m,d]of n)p[m]=ia(c(m),d);let b=l(p,{changed:pa(e,t,r,o)})||{},v=ca(b.$ops),h=[];for(let m of f){if(m==="$ops"||!(m in b))continue;let d=c(m);if(!d.el)continue;let w=sa(e.root,a,d,i(m),b[m]);if(w)h.push(w)}for(let m of Object.keys(b)){if(m==="$ops")continue;let d=b[m];if(d===void 0||d===null)continue;Wr(e,m,d)}jr(e,b,c);for(let m of h){let d=new Event("input",{bubbles:!0});e.ours.add(d),m.dispatchEvent(d)}la(e,v,Boolean(t))}var At;function St(e){At=e}var Kr=1,va="phlex-reactive:persist:",ya=new Set(["hidden","file","password","submit","button","reset","image"]),Et=Symbol("persist-no-value"),xt="data-reactive-persist-state",wa=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Aa=new Set(["lexxy-editor","trix-editor"]),Sa="lexxy-editor, trix-editor, trix-toolbar",Ea=["lexxy:change","trix-change"],xa=new Set(["","<p></p>","<p><br></p>","<div><br></div>"]),Gr=new WeakSet,Ur=new WeakSet,zr=new WeakSet;function pe(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(!Gr.has(e))Gr.add(e),console.warn(`[phlex-reactive] malformed reactive_persist payload ${JSON.stringify(t)} — persistence disabled`);return null}function _t(e){try{if(e.storage==="session")return typeof sessionStorage>"u"?null:sessionStorage;return typeof localStorage>"u"?null:localStorage}catch{return null}}function kt(e,t){if(e?.getAttribute?.("data-reactive-debug")!=="true"||Ur.has(e))return;Ur.add(e),console.info(`[phlex-reactive] reactive_persist: storage unavailable — draft skipped (${t?.name??t})`)}function Tt(e){return va+e.key}function yt(e,t){let n=_t(t);if(!n)return null;let r;try{r=n.getItem(Tt(t))}catch(c){return kt(e,c),null}if(!r)return null;let o;try{o=JSON.parse(r)}catch{return null}if(!o||typeof o!=="object"||o.v!==Kr)return null;let i=Number(t.ttl)*1000;if(!(Number(o.savedAt)+i>Date.now()))return de(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 Vr(e,t,{fields:n,state:r}){let o=_t(t);if(!o)return!1;let i={v:Kr,savedAt:Date.now(),fields:n};if(r)i.state=r;try{return o.setItem(Tt(t),JSON.stringify(i)),!0}catch(a){return kt(e,a),!1}}function de(e,t){e?.removeAttribute?.(xt);let n=_t(t);if(!n)return;try{n.removeItem(Tt(t))}catch(r){kt(e,r)}}function Rt(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)||ya.has(i.type)||i.closest(Sa))continue;if(n&&!n.has(i.name))continue;r.push({el:i,name:i.name,kind:"native"})}for(let i of e.querySelectorAll(wa)){if(!o(i))continue;let a=_a(i);if(!a||n&&!n.has(a))continue;r.push({el:i,name:a,kind:Aa.has(i.localName)?"editor":"contenteditable"})}return r}function Yr(e){return e.hasAttribute("data-reactive-editable")?At.text(e):e.textContent??""}function _a(e){return e.getAttribute("name")||typeof e.name==="string"&&e.name||null}function Lt(e){return typeof e.value==="string"}function ka(e){if(typeof e.isEmpty==="boolean")return e.isEmpty;let t=e.editor?.getDocument?.();if(typeof t?.isEmpty==="function")return t.isEmpty();return xa.has(e.value.trim())}function Ta(e,t,n){if(e?.getAttribute?.("data-reactive-debug")!=="true"||zr.has(e))return;zr.add(e),console.info(`[phlex-reactive] reactive_persist: could not restore editor ${JSON.stringify(t)} — ${n?.message??n}`)}function Y(e){return e.tagName==="SELECT"&&e.multiple}function Xr(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 Zr(e,t,n){if(!Array.isArray(e))return e;if(n.get(t)!==1||e.length!==1)return Et;return e[0]}function Qr(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 Rt(e,t)){let s=String(i).endsWith("[]");if(a==="editor"){if(Lt(o))if(s)r(i).push(o.value);else n[i]=o.value}else if(a==="contenteditable"){let c=Yr(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(Y(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 Ra(e,t,n){let r=t.restore==="always",o=Rt(e,t),i=Xr(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)&&Y(s)&&(i.get(c)??0)>1)continue;if(Array.isArray(l)&&!(s.type==="checkbox"||Y(s))){if(l=Zr(l,c,i),l===Et)continue}if((s.type==="checkbox"||Y(s))&&String(c).endsWith("[]")&&!Array.isArray(l))continue;if(u==="editor")eo(e,s,c,l,r);else if(u==="contenteditable"){if(!r&&Yr(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(Y(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)}}La(e,t,n)}function eo(e,t,n,r,o){if(Array.isArray(r))return;if(!Lt(t))return;if(!o&&!ka(t))return;try{t.value=String(r)}catch(i){Ta(e,n,i)}}function La(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(!Lt(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=Rt(e,t),c=Xr(s);for(let{el:u,name:l,kind:f}of s){if(f!=="editor"||u.localName!==a||!Object.hasOwn(n,l))continue;let p=Zr(n[l],l,c);if(p===null||p===void 0||p===Et)continue;eo(e,u,l,p,i)}})}function Oa(e,t,n=!0){let r=pe(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=yt(e,r),i={...o?.state??{},...t},a=n?Qr(e,r):o?.fields??{};if(Vr(e,r,{fields:a,state:i}))e.setAttribute?.(xt,JSON.stringify(i))}function Na(e){let t=pe(e);if(t)de(e,t)}var wt=new WeakMap,vt=new WeakMap;function Fa(e,t){if(typeof e?.addEventListener!=="function")return()=>{};let n=vt.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],vt.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),vt.delete(e)}}function Ot(e,t,n,r){let o=e.element,i=pe(o);if(!i)return;if(r?.submitted)de(o,i);let a=yt(o,i);if(a){if(Ra(o,i,a.fields),a.state)o.setAttribute?.(xt,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 v=yt(o,i);Vr(o,i,{fields:Qr(o,i),state:v?.state??null})},l=()=>{let v=Number(i.debounce)||0;if(v<=0)return u();if(s!==null)clearTimeout(s);s=setTimeout(()=>{s=null,u()},v)},f=(v)=>{if(!v?.detail?.success)return;let h=v.target;if(h?.tagName!=="FORM"||typeof h.contains!=="function")return;if(!h.contains(o))return;c(),de(o,i)},p=["input",...Ea];for(let v of p)o.addEventListener?.(v,l);o.addEventListener?.("change",u);let b=Fa(globalThis.document,f);if(wt.set(e,()=>{if(s!==null)u();for(let v of p)o.removeEventListener?.(v,l);o.removeEventListener?.("change",u),b()}),r?.edited&&!r.submitted)u();for(let v of r?.ops??[])v(!0)}function Nt(e){let t=wt.get(e);wt.delete(e),t?.()}function to(e,t){let n=At?.waiting.get(e)?.persist;if(!n||!pe(e))return t(!0);(n.ops??=[]).push(t)}function Ft(e,t){to(e,(n)=>Oa(e,t,n))}function Mt(e){to(e,()=>Na(e))}var me=new WeakMap,ro=new WeakSet,Ct=new WeakMap;function $t(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=Ma(n,t))){let u=()=>he(e,t);if(i(n,"turbo:morph-element",u),o.push(u),u(),n.getAttribute?.("data-reactive-warn-unsaved")==="true")Pa(n,r)}if(!s&&(s=Ia(n,t))){let u=()=>Da(n,t);i(n,"turbo:morph-element",u),o.push(u),u()}};me.set(e,[r,()=>{for(let u of o)u();c()}]),c()}function Pt(e){for(let t of me.get(e)?.[0]??[])t();me.delete(e)}function It(e){me.get(e)?.[1]()}function Ma(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 he(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,Ca(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 Ca(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 $a(e){let t=e.getAttribute?.("data-reactive-dirty"),n=Number(t);return Number.isFinite(n)&&n>0?n:0}function Pa(e,t){if(typeof window>"u"||typeof window.addEventListener!=="function")return;let n=window,r=Ct.get(n);if(!r){let o=new Set,i=()=>{for(let c of o)if($a(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(ro.has(c)||!i())return;if(ro.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),Ct.delete(n)}},Ct.set(n,r)}r.roots.add(e),t.push(()=>{if(r.roots.delete(e),r.roots.size===0)r.remove()})}function Ia(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 Da(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 jt(e){qa(e),ja(e)}function qa(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveDismissWrapped){if(typeof requestAnimationFrame==="function")requestAnimationFrame(Dt);else setTimeout(Dt,0);return}let r=async(o)=>{await n(o),Dt()};r.__reactiveDismissWrapped=!0,t.render=r}function Dt(){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 Wa=Object.freeze({append:"enter",prepend:"enter",replace:"update",update:"update",remove:"exit"}),qt=Object.freeze(["fade","slide","scale","highlight","shake"]),Wt="data-reactive-fx-pending",Bt=1000;function ja(e){let t=e.detail,n=t?.render;if(typeof n!=="function"||n.__reactiveEffectsWrapped)return;let r=t?.newStream??e.target,o=Wa[r?.getAttribute?.("action")];if(!o||Ha())return;let i=Ba(r,o);if(!i)return;let a=o==="exit"?async(s)=>{await za(ge(r),i),await n(s)}:async(s)=>{let c=o==="enter"?Ga(r):null;if(await n(s),o==="enter")Ua(c,i);else so(ge(r),i)};a.__reactiveEffectsWrapped=!0,t.render=a}function Ba(e,t){let n=e.getAttribute?.("data-reactive-effect");if(n==="off")return null;if(n)return io(n,t);let o=(t==="enter"?Ja(e):ge(e))?.getAttribute?.(`data-reactive-effect-${t}`);return o?io(o,t):null}function ge(e){let t=e.getAttribute?.("target");return t?document.getElementById?.(t)??null:null}function Ja(e){return e.querySelector?.("template")?.content?.firstElementChild??null}function io(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"?qt[Math.floor(Math.random()*qt.length)]:e;if(!qt.includes(n))return console.warn(`[phlex-reactive] unknown effect ${JSON.stringify(e)} — skipped`),null;return{className:`reactive-fx--${n}-${t}`}}function Ha(){try{return typeof matchMedia==="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches}catch{return!1}}function Ga(e){let t=e.querySelector?.("template")?.content;if(!t)return null;for(let n of Array.from(t.children??[]))n.setAttribute?.(Wt,"");return ge(e)}function Ua(e,t){if(typeof e?.querySelectorAll!=="function")return;for(let n of Array.from(e.querySelectorAll(`[${Wt}]`)))n.removeAttribute(Wt),so(n,t)}async function za(e,t){if(!e?.classList)return;if(t.legs){await ao(e,t.legs);return}e.classList.add(t.className);let n=Jt(e);if(n<=0){e.classList.remove(t.className);return}await Ht(e,n),e.classList.remove(t.className)}function so(e,t){if(!e?.classList)return;if(t.legs){ao(e,t.legs);return}if(e.classList.contains(t.className))e.classList.remove(t.className),e.offsetWidth;e.classList.add(t.className);let n=Jt(e);if(n<=0){e.classList.remove(t.className);return}let r=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;Ht(e,n).then(()=>{if(e.__reactiveFxToken===r)e.classList.remove(t.className)})}async function ao(e,t){let[n,r,o]=t.map(Ka),i=e.__reactiveFxToken=(e.__reactiveFxToken??0)+1;if(e.classList.remove(...n,...r,...o),e.classList.add(...n,...r),await Va(),e.__reactiveFxToken!==i)return;e.classList.remove(...r),e.classList.add(...o);let a=Jt(e);if(a>0)await Ht(e,a);if(e.__reactiveFxToken!==i)return;e.classList.remove(...n,...o)}function Ka(e){return String(e??"").split(/\s+/).filter(Boolean)}function Jt(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,Bt)}catch{return 0}}function Ht(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,Bt))})}function Va(){return new Promise((e)=>{if(typeof requestAnimationFrame!=="function")return setTimeout(e,16);let t=setTimeout(()=>{globalThis.cancelAnimationFrame?.(n),e()},Bt),n=requestAnimationFrame(()=>{clearTimeout(t),e()})})}var Ya="phlex-reactive:latency",Gt=!1;function lo(e){if(typeof sessionStorage>"u")return;sessionStorage.setItem("phlex-reactive:latency",String(e))}function fo(){if(typeof sessionStorage>"u")return;sessionStorage.removeItem("phlex-reactive:latency"),Gt=!1}function zt(){if(typeof window<"u")window.PhlexReactive={enableLatencySim:lo,disableLatencySim:fo}}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(!Gt)Gt=!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 uo=new WeakMap;function Vt(e){let t=globalThis.document;if(!t)return!0;let n=uo.get(t);if(!n)n=new Set,uo.set(t,n);if(n.has(e))return!0;return n.add(e),!1}function Ut(e,t){try{return e?.querySelectorAll?.(t)?.length??0}catch{return 0}}function po(e,t,n,r){if(Vt(`${e}|${t}|${n}`))return;console.warn(`[phlex-reactive] ${e} matched zero targets for selector "${t}" (${n})${r}`)}function Yt(e,t,n){let r=t.to;if(typeof r!=="string"||r===""||r==="@root")return;let o="";if(n&&!t.global){let i=Ut(globalThis.document,r);if(i>0)o=` — it matches ${i} element(s) outside the stream's target root; use global: true`}po(`client op "${e}"`,r,n?`scoped to #${n.id||"?"}`:"document-scoped",o)}function Xt(e){if(!Vt(`missing-root|#${e}`))console.warn(`[phlex-reactive] reactive:js stream target root #${e} is not in the DOM — its ops were dropped`)}function Zt(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(Ut(r,o)>0)i=" — it matches only inside a nested reactive root (excluded by ownership scoping); use global: true";else{let a=Ut(globalThis.document,o);if(a>0)i=` — it matches ${a} element(s) outside this scope; use global: true`}po(t,o,`scoped to #${r?.id||"?"}`,i)}function Qt(e,t){let n=e.element?.id||"?";if(Vt(`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 Xa(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 en(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 be(e,t,n){e.streams=Xa(t),e.tokenRefreshed=n!=null}var ve=new WeakMap;function tn(e,t,n,r){let o=n&&typeof n==="object"?ec(n):n;return o?ho(t,o,r,!1):[]}function nn(e,t,n,r){if(!n)return null;let o=ho(t,n,r,!0);return o.length?o:null}function ho(e,t,n,r){let o=[];for(let i of go(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(Za(t,n));if(r&&t.checked==="keep"&&n&&"checked"in n){let i=n.checked;o.push(()=>n.checked=!i)}return o}function go(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 Za(e,t){let n=ve.get(t);if(n)n.count++;else ve.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()=>Qa(t,e)}function Qa(e,t){let n=ve.get(e);if(!n)return;if(--n.count>0)return;if(ve.delete(e),!e.isConnected)return;if(t.disable)e.disabled=n.disabled;if(n.hadText&&e.innerHTML===n.swappedTo)e.innerHTML=n.html}function ec(e){if(!e||typeof e!=="object")return null;let{class:t,...n}=e;return t==null?e:{...n,add_class:t}}function rn(e,t,n,r){if(!n?.hide)return null;let o=go(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 Ae;function an(e){Ae=e}var R=new Map;function wo(e,t){let n=!R.has(e);if(R.set(e,t),n)Ae.enter()}function Se(e){if(R.delete(e))Ae.exit()}var vo=!1;function cn(e){Ao();let t=e.getAttribute("target");if(!t)return;if(e.getAttribute("data-reactive-defer-via")==="stream"){sc(t,e);return}let n=e.getAttribute("data-reactive-defer-token");if(!n)return;Z(t,n)}function Ao(){if(vo||typeof document>"u"||!document.addEventListener)return;vo=!0,document.addEventListener("turbo:before-stream-render",cc,!0),document.addEventListener("turbo:before-stream-render",tc)}function tc(e){let t=e.target?.getAttribute?.("target");if(!t?.startsWith("reactive-defer-src-"))return;let n=t.slice(19);if(R.get(n)?.via==="stream")Se(n)}function Z(e,t){let n=document.getElementById(e);if(!n){console.warn(`[phlex-reactive] reactive:defer target #${e} is not on the page — skipped`);return}ln(e),_o(n);let r={via:"fetch",abort:new AbortController,timedOut:!1};return wo(e,r),ac(e,r,t)}function nc(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[lc(),{method:"POST",headers:{Accept:"text/vnd.turbo-stream.html","Content-Type":"application/json","X-CSRF-Token":fc()},body:JSON.stringify({token:e}),credentials:"same-origin",signal:t}]}function So(e){let t=e.getAttribute?.("data-reactive-defer-src");if(!t)return;if(Eo(t))return{src:t};return console.error(rc(t)),oc(t)||ic(e)}function rc(e){return`[phlex-reactive] refused data-reactive-defer-src="${e}" — it is not under this app's fragment path `+`(${un()}). If you changed Phlex::Reactive.fragment_path, add `+'<meta name="phlex-reactive-fragment-path" content="…your path…"> to the layout <head>.'}function oc(e){let t;try{t=new URL(e,window.location.href)}catch{return}let n=t.pathname.split("/").pop(),r=`${un()}/${n}${t.search}`;if(/^[\w-]+$/.test(n)&&Eo(r))return{src:r,fallback:!0}}function ic(e){ln(e.id),fn(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 Eo(e){try{let t=new URL(window.location.href),n=new URL(e,t);return n.origin===t.origin&&n.pathname.startsWith(`${un()}/`)}catch{return!1}}function un(){return document.head?.querySelector?.('meta[name="phlex-reactive-fragment-path"]')?.content||"/reactive/fragment"}function sc(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){Z(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}ln(e),_o(n);let o=document.createElement("pgbus-stream-source");o.id=xo(e),o.setAttribute("src",r),o.setAttribute("since-id",t.getAttribute("data-reactive-defer-since-id")??"0"),o.setAttribute("hidden",""),document.body.appendChild(o),wo(e,{via:"stream"})}function xo(e){return`reactive-defer-src-${e}`}async function ac(e,t,n){let r=setTimeout(()=>{t.timedOut=!0,t.abort.abort()},dc()),o;try{Ae.count("defer"),o=await fetch(...nc(n,t.abort.signal))}catch(s){if(clearTimeout(r),R.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed",s),X(e,n);return}if(R.get(e)!==t){clearTimeout(r);return}if(o.redirected){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: redirected to ${o.url??"another URL"}`),X(e,n,o.status);return}if(o.status===204){clearTimeout(r),yo(e);return}if(!o.ok){clearTimeout(r),console.error(`[phlex-reactive] deferred render failed: HTTP ${o.status}`),X(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}"`),X(e,n,o.status);return}let a;try{a=await o.text()}catch(s){if(clearTimeout(r),R.get(e)!==t)return;console.error("[phlex-reactive] deferred render failed reading the body",s),X(e,n);return}if(clearTimeout(r),R.get(e)!==t)return;yo(e),uc(a)}var sn=null,cc=(e)=>sn?.push(e);function uc(e){let t=sn=[];try{window.Turbo.renderStreamMessage(e)}finally{sn=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 ln(e){let t=R.get(e);if(!t)return;if(Se(e),t.via==="fetch")t.abort.abort();else document.getElementById(xo(e))?.remove?.()}function _o(e){e.setAttribute("data-reactive-defer-pending","true"),e.setAttribute("aria-busy","true")}function fn(e){e.removeAttribute("data-reactive-defer-pending"),e.removeAttribute("aria-busy")}function yo(e){Se(e);let t=document.getElementById(e);if(!t)return;fn(t),t.removeAttribute("data-reactive-error")}function X(e,t,n){Se(e);let r=document.getElementById(e);if(!r)return;fn(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"),Z(e,t)};r.dispatchEvent(new CustomEvent("reactive:error",{bubbles:!0,composed:!0,detail:{kind:"defer",target:e,status:n,retry:o}}))}function lc(){return document.querySelector('meta[name="phlex-reactive-defer-path"]')?.content||"/reactive/defer"}function fc(){return document.querySelector('meta[name="csrf-token"]')?.content??""}function dc(){let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return Number.isFinite(t)&&t>0?t:30000}var ko="__materialize",we=new WeakMap;function ye(e){if(e.getAttribute?.("data-reactive-lazy-visible")!=null)return"visible";if(e.getAttribute?.("data-reactive-lazy-on"))return"event";return null}function dn(e,t,n){Ao();let r=e.element,o=!1,i=!1,a=null,s=null,c,u,l=()=>Ee(e),f=(d)=>{if(ye(r)==="visible"){if(!a)b()}else if(d){let w=r.getAttribute("data-reactive-lazy-on");if(s===w)return;p(),r.addEventListener?.(w,l),s=w}},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((w)=>{if(w.some((A)=>A.isIntersecting))l()},{rootMargin:d}),a.observe(r)},v=()=>{let d=ye(r)!==null,w=o;if(o=d,!d)return p();if(i)return;if(t.forgetToken(),!w)return l();f(!0)};if(we.set(e,{load(){if(i)return;let d=So(r);if(!d&&r.getAttribute("data-reactive-defer-src")!=null)return;if(d&&pc(r,t))return;let w=d?Z(r.id,d):t.proceed(r,ko,"{}");if(!w)return;i=!0,p();let A=()=>{i=!1};return w.then(A,A),w},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"))&&ye(r)===null)on(r),c=(d)=>d.target===r&&on(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)on(r);v()},r.addEventListener?.("turbo:morph-element",u),n)return v();if(o=ye(r)!==null,o)f(!1)}function pn(e){let t=we.get(e);we.delete(e),t?.off()}function Ee(e){return we.get(e)?.load()}function pc(e,t){return t.emit("reactive:before-dispatch",{action:ko,params:{},element:e},{cancelable:!0}).defaultPrevented}function on(e){if(!e?.id)return;if(e.getAttribute?.("data-reactive-defer-pending")!=="true")return;let t=e.getAttribute?.("data-reactive-defer-token")||So(e);if(t)Z(e.id,t)}var mn=new WeakMap,_e=new WeakMap,g=null,C,Ro;function vn(e,t){let n=e.element;_e.set(n,t),Io();let r=(i)=>hc(i,t),o=(i)=>wc(i,t);n.addEventListener("pointerdown",r),n.addEventListener("keydown",o),mn.set(e,()=>{n.removeEventListener("pointerdown",r),n.removeEventListener("keydown",o)})}function yn(e){if(mn.get(e)?.(),mn.delete(e),_e.delete(e.element),g&&ke(g.origin)===e.element)xe()}var S=(e,t="")=>e?.getAttribute?.(`data-reactive-sortable${t}`),Q=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},ke=(e)=>e?.closest?.('[data-controller~="reactive"]'),Fo=(e)=>e.parentElement?.closest("[data-reactive-sortable],[data-reactive-sortable-source]"),N=(e)=>[...e.querySelectorAll("[data-reactive-sortable-item]")].filter((t)=>t!==g?.row&&Fo(t)===e),Lo=(e)=>Q(S(e,"-item"),null),hn=(e)=>S(e,"-disabled")==="true",mc=(e,t,n)=>{let r=e.getBoundingClientRect();return t>=r.left&&t<=r.right&&n>=r.top&&n<=r.bottom},Mo=(e)=>{let t=S(e,"-group");if(!t)return e.matches("[data-reactive-sortable]")?[e]:[];return[...document.querySelectorAll("[data-reactive-sortable]")].filter((n)=>S(n,"-group")===t&&!hn(n)&&_e.has(ke(n)))};function Co(e,t){let n=e?.closest?.("[data-reactive-sortable-item]"),r=n&&Fo(n);if(g||!r||!t.owns(r)||hn(r)||hn(n))return;if(ke(r)?.getAttribute("aria-busy")==="true")return;return{item:n,list:r}}function hc(e,t){if(e.button>0||e.isPrimary===!1)return;let n=Co(e.target,t);if(!n)return;let r=S(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(g)return gn(d.clientX,d.clientY);if(Math.abs(d.clientX-o)<=4&&Math.abs(d.clientY-i)<=4)return;if(!c)return m();bc(n,t,d),gn(d.clientX,d.clientY)},f=(d)=>g&&d.cancelable&&d.preventDefault(),p=(d)=>{if(!a(d))return;if(m(),g)gc(),bn()},b=(d)=>{if(d.type==="pointercancel"&&!a(d))return;if(m(),g)xe()},h=[["pointermove",l],["pointerup",p],["pointercancel",b],["keydown",(d)=>d.key==="Escape"&&g&&(d.preventDefault(),b(d))],["touchmove",f,{passive:!1}]];for(let[d,w,A]of h)document.addEventListener(d,w,A);function m(){clearTimeout(u);for(let[d,w]of h)document.removeEventListener(d,w)}}function gc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function bc({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`,g=$o({core:n,item:e,row:a,origin:t,source:i,placeholder:s,style:a.getAttribute("style")}),g.dx=r.clientX-o.left,g.dy=r.clientY-o.top,g.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 $o(e){let{row:t,origin:n,source:r}=e;return e.index=N(n).indexOf(e.item),e.target=r?null:n,t.setAttribute("data-reactive-sortable-dragging",""),ee(n,!0),e}var ee=(e,t)=>e?.toggleAttribute("data-reactive-sortable-active",t);function Te(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 gn(e,t){g.x=e,g.y=t,g.row.style.left=`${e-g.dx}px`,g.row.style.top=`${t-g.dy}px`;let n=Mo(g.origin).find((r)=>mc(r,e,t));if(n)vc(n,e,t);else if(g.source)wn(null),g.placeholder.remove();yc(e,t)}function wn(e){if(g.target!==g.origin)ee(g.target,!1);g.target=e,ee(e,!0)}function vc(e,t,n){wn(e);let r=N(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});Te(e,r,s<0?r.length:s,g.placeholder)}function yc(e,t){let n=g.target??g.origin,r=n.getBoundingClientRect(),o=n.scrollHeight>n.clientHeight;if(g.vy=o?t<r.top+40?-12:t>r.bottom-40?12:0:0,g.wy=t<40?-12:t>window.innerHeight-40?12:0,(g.vy||g.wy)&&!g.raf){let i=()=>{if(!g||!(g.vy||g.wy))return g&&(g.raf=0);if((g.target??g.origin).scrollTop+=g.vy,g.wy)window.scrollBy(0,g.wy);gn(g.x,g.y),g.raf=requestAnimationFrame(i)};g.raf=requestAnimationFrame(i)}}function wc(e,t){let n=e.key;if(g?.keyboard){if(e.target!==g.row||g.core!==t)return;let o={" ":bn,Enter:bn,Escape:xe,Tab:xe,ArrowUp:()=>Oo(-1),ArrowDown:()=>Oo(1),ArrowLeft:()=>No(-1),ArrowRight:()=>No(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(),g=$o({core:t,keyboard:!0,item:r.item,row:r.item,origin:r.list,style:r.item.getAttribute("style")}),Le("picked")}function Oo(e){let t=N(g.target),n=Re()+e;if(n>=0&&n<=t.length)Te(g.target,t,n,g.row);Po()}function No(e){let t=Mo(g.origin),n=t[t.indexOf(g.target)+e];if(n){let r=Re();wn(n),Te(n,N(n),r,g.row)}Po()}function Po(){g.row.focus?.(),Le("moved")}function Re(){let e=N(g.target),t=g.keyboard?g.row:g.placeholder;return e.filter((n)=>n.compareDocumentPosition(t)&4).length}function Io(){if(!C?.isConnected)C=document.createElement("div"),C.setAttribute("aria-live","polite"),C.setAttribute("data-reactive-sortable-live",""),C.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(C);return C}function Le(e){let t=g.target??g.origin,n=(Q(S(t,"-messages"),{})[e]??"").replaceAll("{position}",Re()+1).replaceAll("{count}",N(t).length+1),r=Io();r.textContent="",cancelAnimationFrame(Ro),Ro=requestAnimationFrame(()=>r.textContent=n)}function bn(){let e=g,{target:t,origin:n,source:r,row:o,placeholder:i}=e,a=t&&(r?i.isConnected:!0),s=a?Re():-1,c=a?Lo(N(t)[s-1]):null;if(e.keyboard)Le("dropped");if(!r&&i)i.replaceWith(o);if(qo(e),!a||t===n&&s===e.index)return;let u=t===n?"self":r?S(n,"-source"):S(n,"-name")??"list",l=Q(S(t,"-from"),{})[u]??S(t),f={...Q(S(t,"-params"),{}),item:Lo(e.item),position:s,after:c,from:u},p=[];for(let v=t;v;v=v.parentElement)p.push(v);let b=_e.get(ke(t))?.proceed(t,l,JSON.stringify(f),Q(S(t,"-busy")));if(r)return;Promise.resolve(b).then((v)=>Ac(v,p)||Do(e))}function Ac(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"))&&Sc(r,t))}function Sc(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 xe(){let e=g;if(e.keyboard)Le("cancelled");e.placeholder?.remove(),qo(e),Do(e)}function Do({row:e,origin:t,index:n,source:r}){if(r||!e.isConnected)return;if(Te(t,N(t).filter((o)=>o!==e),n,e),e===document.activeElement)e.focus?.()}function qo(e){let{row:t,origin:n,target:r,source:o,style:i,placeholder:a}=e;if(g=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(),ee(n,!1),ee(r,!1),!e.keyboard)document.documentElement.style.userSelect=e.select??""}var Ho={ArrowLeft:[-1,0],ArrowRight:[1,0],ArrowUp:[0,-1],ArrowDown:[0,1]},Go={x:"left",y:"top",width:"width",height:"height"},An=new WeakMap,xn=new WeakMap,y=null,P,jo,Bo=!1;function _n(e,t){let n=e.element;xn.set(n,t),Qo(),Fc();let r=[["pointerdown",(o)=>Tc(o,t,n)],["keydown",(o)=>Nc(o,t,n)],["keyup",(o)=>y?.keyboard&&o.target===y.grip&&Ho[o.key]&&En()],["focusout",(o)=>y?.keyboard&&o.target===y.grip&&En()],["input",(o)=>Jo(o,t,n)],["change",(o)=>Jo(o,t,n)]];for(let[o,i]of r)n.addEventListener(o,i);An.set(e,()=>{for(let[o,i]of r)n.removeEventListener(o,i)})}function kn(e){if(An.get(e)?.(),An.delete(e),xn.delete(e.element),y?.root===e.element)J(y)}var _=(e,t,n)=>Math.min(Math.max(e,t),n),E=(e)=>Math.round(e*1e4)/1e4;function Tn(e){let t={x:E(e.x),y:E(e.y)};if(e.width!=null)t.width=E(e.width),t.height=E(e.height),t.x=Math.min(t.x,E(1-t.width)),t.y=Math.min(t.y,E(1-t.height));return t}function Uo(e,t,n){return{x:_(e.x+t,0,1-e.width),y:_(e.y+n,0,1-e.height),width:e.width,height:e.height}}function zo(e,t,n){return{x:_(e.x+t,0,1),y:_(e.y+n,0,1)}}function Ko(e,t,n,r,o,i){let[a,s,c,u]=["n","e","s","w"].map((w)=>t.includes(w)),l=e.x+e.width,f=e.y+e.height,p=e.x+e.width/2,b=e.y+e.height/2,v=s?1-e.x:u?l:i?2*Math.min(p,1-p):1,h=c?1-e.y:a?f:i?2*Math.min(b,1-b):1,m=e.width+(s?n:u?-n:0),d=e.height+(c?r:a?-r:0);if(i){let w=(s||u)&&(!(a||c)||Math.abs(m-e.width)>=Math.abs(d-e.height)*i),A=Math.min(v,h*i);m=_(w?m:d*i,Math.min(Math.max(o,o*i),A),A),d=m/i}else{if(s||u)m=_(m,Math.min(o,v),v);if(a||c)d=_(d,Math.min(o,h),h)}return{x:u?l-m:s?e.x:p-m/2,y:a?f-d:c?e.y:b-d/2,width:m,height:d}}function Ec(e,t,n){let r=Math.min(1,t),o=_(Math.sqrt(e.width*e.height*t),Math.min(Math.max(n,n*t),r),r),i=o/t;return{x:_(e.x+e.width/2-o/2,0,1-o),y:_(e.y+e.height/2-i/2,0,1-i),width:o,height:i}}function xc(e){let[t,n=1,r]=String(e??"").split(":").map(Number),o=r===void 0?t/n:0;return o>0&&Number.isFinite(o)?o:0}var k=(e,t)=>e?.getAttribute?.(`data-reactive-${t}`),Rn=(e,t)=>{try{return e==null?t:JSON.parse(e)}catch{return t}},F=(e)=>e.matches("[data-reactive-point]")?"point":"box",B=(e)=>F(e)==="point"?["x","y"]:["x","y","width","height"];function Vo(e){let t={};for(let n of B(e))t[n]=(parseFloat(e.style[Go[n]])||0)/100;return t}function Oe(e,t){for(let n of B(e))e.style[Go[n]]=`${Math.round(t[n]*1e4)/100}%`}function Ln(e){let t=e.getBoundingClientRect();return{left:t.left+(e.clientLeft||0),top:t.top+(e.clientTop||0),width:e.clientWidth||t.width,height:e.clientHeight||t.height}}function _c(e,t){try{return e.parentElement.closest(k(e,"point-within")||"[data-reactive-frame]")??t}catch{return t}}function Yo(e,t,n){return[...e.querySelectorAll("[name]")].filter((r)=>r.name===n&&t.owns(r))}function Xo(e,t,n){let r=Rn(k(e,F(e)),{}),o={};for(let i of B(e)){let[a]=Yo(t,n,r[i]);if(a)o[i]=a}return o}function kc(e,t,n,r){let o=k(e,"box-aspect"),i=o&&Yo(n,r,o).find((u)=>!/^(radio|checkbox)$/.test(u.type)||u.checked),a=o?xc(i?.value):Number(k(e,"box-ratio"))||0,{width:s,height:c}=Ln(t);return a&&s&&c?a*c/s:0}function On(e,t,n,r){let o=n.matches("[data-reactive-box-handle]")?n.closest("[data-reactive-box]"):n,i=o?.closest("[data-reactive-frame]");if(!i)return null;let a=Vo(o),s=Xo(o,t,e),c=F(o)==="point";return{core:e,root:t,grip:n,el:o,frame:i,keyboard:r,bounds:c?_c(o,i):i,edge:k(n,"box-handle"),start:a,value:a,ratio:c?0:kc(o,i,t,e),min:Number(k(o,"box-min"))||0,fields:s,before:Object.fromEntries(Object.entries(s).map(([u,l])=>[u,l.value]))}}function te(e){cancelAnimationFrame(e.writing),e.writing=0;for(let[t,n]of Object.entries(e.fields))e.core.setValue(n,String(E(e.value[t])))}function Tc(e,t,n){if(Zo(),y||e.button>0||e.isPrimary===!1||e.target.closest?.("input,textarea,select,[contenteditable]"))return;let r=e.target.closest?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]"),o=r&&t.owns(r)&&On(t,n,r,!1);if(!o)return;let{clientX:i,clientY:a}=e,s=Ln(o.bounds);o.p0=[(i-s.left)/s.width,(a-s.top)/s.height];let c=(h)=>h.pointerId===e.pointerId,u=(h)=>{if(!c(h)||o.over)return;if(y)return Sn(h.clientX,h.clientY);if(Math.abs(h.clientX-i)<=4&&Math.abs(h.clientY-a)<=4)return;Lc(o),Sn(h.clientX,h.clientY)},l=(h)=>{if(!c(h))return;if(v(),y)Rc(),En()},f=(h)=>{if(h.type==="pointercancel"&&!c(h))return;if(v(),y)ni()},b=[["pointermove",u],["pointerup",l],["pointercancel",f],["keydown",(h)=>h.key==="Escape"&&y&&(h.preventDefault(),f(h))]];for(let[h,m]of b)document.addEventListener(h,m);function v(){for(let[h,m]of b)document.removeEventListener(h,m)}}function Rc(){let e=(t)=>(t.preventDefault(),t.stopPropagation());window.addEventListener("click",e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener("click",e,{capture:!0}))}function Lc(e){y=e,e.grip.setAttribute("data-reactive-dragging",""),e.frame.setAttribute("data-reactive-frame-active",""),e.select=document.documentElement.style.userSelect,document.documentElement.style.userSelect="none"}function Sn(e,t){let n=y;if(!n.el.isConnected)return J(n);n.x=e,n.y=t;let r=Ln(n.bounds),o=(e-r.left)/r.width-n.p0[0],i=(t-r.top)/r.height-n.p0[1],{start:a,edge:s}=n;n.value=Tn(F(n.el)==="point"?zo(a,o,i):s?Ko(a,s,o,i,n.min,n.ratio):Uo(a,o,i)),Oe(n.el,n.value),n.writing||=requestAnimationFrame(()=>te(n)),Oc(t)}function Oc(e){if(y.wy=e<40?-12:e>window.innerHeight-40?12:0,y.wy&&!y.raf){let t=()=>{if(!y?.wy)return y&&(y.raf=0);if(window.scrollBy(0,y.wy),Sn(y.x,y.y),y)y.raf=requestAnimationFrame(t)};y.raf=requestAnimationFrame(t)}}function Zo(){if(y&&!y.el.isConnected)J(y)}function Nc(e,t,n){Zo();let r=e.target;if(!r?.matches?.("[data-reactive-box-handle],[data-reactive-point],[data-reactive-box]")||!t.owns(r)||y&&(!y.keyboard||y.grip!==r))return;if(e.key==="Escape")return y&&(e.preventDefault(),ni());let o=Ho[e.key];if(!o)return;if(e.preventDefault(),y??=On(t,n,r,!0),!y)return;let[i,a]=o.map((u)=>u*(e.shiftKey?0.1:0.01)),s=e.altKey&&F(y.el)==="box",c=y.value;y.value=Tn(F(y.el)==="point"?zo(c,i,a):s?Ko(c,y.edge??"se",i,a,y.min,y.ratio):Uo(c,i,a)),Oe(y.el,y.value),te(y),ei(y,s?"resized":"moved")}function Qo(){if(!P?.isConnected)P=document.createElement("div"),P.setAttribute("aria-live","polite"),P.setAttribute("data-reactive-drag-live",""),P.style.cssText="position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap",document.body.append(P);return P}function ei(e,t){let n=Rn(k(e.el,`${F(e.el)}-messages`),{})[t]??"";for(let o of B(e.el))n=n.replaceAll(`{${o}}`,Math.round(e.value[o]*100));let r=Qo();r.textContent="",cancelAnimationFrame(jo),jo=requestAnimationFrame(()=>r.textContent=n)}function Jo(e,t,n){let r=e.target?.name;if(!r)return;for(let o of n.querySelectorAll("[data-reactive-box-aspect]")){if(k(o,"box-aspect")!==r||o===y?.el||!t.owns(o))continue;let i=On(t,n,o,!0),{ratio:a,start:s}=i??{};if(!a||Math.abs(s.width/s.height/a-1)<0.005)continue;i.value=Tn(Ec(s,a,i.min)),Oe(o,i.value),te(i),ti(i)}}function En(){let e=y;if(!e.el.isConnected)return J(e);te(e),J(e),ti(e)}function ti(e){for(let[o,i]of Object.entries(e.fields))if(i.value!==e.before[o])i.dispatchEvent(new Event("change",{bubbles:!0}));let t=F(e.el),n=k(e.el,`${t}-action`),r={};for(let o of B(e.el))r[o]=E(e.value[o]);if(!n||B(e.el).every((o)=>r[o]===E(e.start[o])))return;e.core.proceed(e.el,n,JSON.stringify(r),Rn(k(e.el,`${t}-busy`)))}function ni(){let e=y;if(e.value=e.start,Oe(e.el,e.start),te(e),e.keyboard)ei(e,"cancelled");J(e)}function J(e){if(y=null,e.over=!0,cancelAnimationFrame(e.raf),cancelAnimationFrame(e.writing),e.grip.removeAttribute("data-reactive-dragging"),e.frame.removeAttribute("data-reactive-frame-active"),!e.keyboard)document.documentElement.style.userSelect=e.select??""}function Fc(){if(Bo)return;Bo=!0,document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.target,n=e.detail?.attributeName;if(!y)return;if(t===y.el&&n==="style"||t===y.grip&&n==="data-reactive-dragging"||t===y.frame&&n==="data-reactive-frame-active"||n==="value"&&Object.values(y.fields).includes(t))e.preventDefault()}),document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;if(t===y?.el||!t.matches?.("[data-reactive-box],[data-reactive-point]"))return;let n=t.closest('[data-controller~="reactive"]'),r=xn.get(n);if(!r?.owns(t))return;let o=Vo(t);for(let[i,a]of Object.entries(Xo(t,n,r)))if(E(Number(a.value))!==E(o[i]))r.setValue(a,String(E(o[i])))})}var I=new Map,oi=new WeakSet;function Nn(e,t){let n=e.element,r=I.get(n.id);if(!r)I.set(n.id,r={state:null,seats:null});r.root=n,r.core=t,r.removing=!1,Mc(n);let o=(a)=>a.target===n&&queueMicrotask(()=>si(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)},si(r)}function Fn(e){let t=e.element,n=I.get(t.id);if(!n||n.root!==t)return;n.off(),n.removing=!0,queueMicrotask(()=>{if(!n.removing)return;I.delete(t.id),t.ownerDocument.getElementById("reactive-presence-src-"+t.id)?.remove()})}function Mn(e,t){if(!e?.hasAttribute?.("data-reactive-presence")){console.warn("[phlex-reactive] js.presence ran outside a reactive_presence root — ignored");return}let n=I.get(e.id);if(!n)I.set(e.id,n={root:e,state:null,seats:null});n.state={...n.state,...t},ai(n)}function Mc(e){let t="reactive-presence-src-"+e.id,n=document.getElementById(t);if(n&&oi.has(n))return;if(n?.remove(),!ii())setTimeout(()=>{if(!ii())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=I.get(e.id);if(!o||o.removing)return;ai(o),Cc(o)}),oi.add(r),document.body.appendChild(r)}var ii=()=>!!globalThis.customElements?.get?.("pgbus-stream-source");function Cc(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&&ci(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 ai(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 ci(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 si(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=ci(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 li=new Map,Cn=new WeakMap,$c=0,Ne=new WeakMap;function $n(e,t){let n=e.element;if(!n.id&&!Cn.has(n))Cn.set(n,`#${++$c}`);let r=n.id||Cn.get(n),o=new Map,i=!1,a=(b)=>{clearTimeout(o.get(b)),o.delete(b)},s=(b,v,h)=>{a(b);let m=Date.parse(v.until)-Date.now();if(!(m>0))return c(b,v,h);let d=Math.ceil(m/1000);fi(b,`${Math.floor(d/60)}:${String(d%60).padStart(2,"0")}`,"running"),u(v.waiting,!0),u(v.done,!1),o.set(b,setTimeout(()=>s(b,v,h),(m-1)%1000+1))},c=(b,v,h)=>{fi(b,"0:00","done"),u(v.waiting,!1),u(v.done,!0);let m=li.get(h)??new Set;if(m.has(v.until))return;li.set(h,m.add(v.until)),b.dispatchEvent(new CustomEvent("reactive:countdown-done",{bubbles:!0,detail:{until:v.until}}))},u=(b,v)=>{let h;try{h=b&&n.querySelector(b)}catch{}if(h&&h.hidden===v)h.hidden=!v},l=()=>{if(i=!1,!Ne.has(e))return;let b=new Set;[...n.matches("[data-reactive-countdown]")?[n]:[],...n.querySelectorAll("[data-reactive-countdown]")].forEach((h,m)=>{if(!t.owns(h))return;let d;try{d=JSON.parse(h.getAttribute("data-reactive-countdown"))}catch{return}if(Number.isNaN(Date.parse(d?.until)))return;b.add(h),s(h,d,`${r}|${h.id||m}`)});for(let h of o.keys())if(!b.has(h))a(h)},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),Ne.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){Ne.get(e)?.(),Ne.delete(e)}function fi(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 Ic(){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 Dc(){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 qc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=lr(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)Xt(n);return}Zn(t,(i)=>ku(i,o),r?(i,a)=>Yt(i,a,o):void 0)}}function Wc(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){cn(this)}}var mi=!1,jc=null;function Bc(){if(mi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;mi=!0,document.addEventListener("turbo:before-stream-render",(e)=>{tu(e),Jc(e),Gc(e),jt(e)})}var $e="reactive:streamed";function Jc(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($e))}}function tr(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function nr(e){try{return e.matches(":modal")}catch{return!1}}function Hi(e){if(!tr(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||nr(e))return;if(e.open)e.close();e.showModal()}function Hc(e){if(tr(e)&&e.open)e.close()}function qe(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&&!nr(r))Hi(r)}function Gc(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),qe(document)}}var hi=!1;function Uc(){if(hi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;hi=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))qe(t.target)}),document.addEventListener("turbo:morph",()=>qe(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!tr(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||!nr(n))return;e.delete(n),t.preventDefault(),n.close()})}var Vn=new WeakMap;function Gi(e,t,n,r){let o=Vn.get(e)??new Map;Vn.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"))as(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}))Gi(a,"set_attr",{name:"aria-expanded"})}}var gi=!1;function zc(){if(gi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;gi=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of Vn.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 Ui="data-reactive-image-fallback",ne="data-reactive-image-state",Yn="data-reactive-image-hidden",In=null,Xn="data-reactive-wrap-hidden";function zi(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(Xn,"")}function Ki(e){if(!e.hasAttribute(Xn))return;e.removeAttribute("hidden"),e.removeAttribute(Xn)}function re(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Ui);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var Vi=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function rr(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function Yi(e,t){let n=rr(e,t.alt);return n&&!n.contains(e)?n:null}function We(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Yn,"");if(t.wrap){let o=rr(e,t.wrap);if(o)zi(o);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=Yi(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else Je(e,t);e.setAttribute(ne,n)}function Je(e,t=re(e)){if(!t||e.getAttribute(ne)==null)return;if(e.getAttribute(ne)==="error"){if(e.hasAttribute(Yn))e.removeAttribute("hidden");let n=rr(e,t.wrap);if(n)Ki(n);let r=Yi(e,t);if(r)r.hidden=!0}e.removeAttribute(ne),e.removeAttribute(Yn)}function bi(e){let t=e.target,n=re(t);if(!n)return;if(e.type==="load")We(t,n,"loaded");else if(Vi(t))We(t,n,"error");else Je(t,n)}function Kc(){if(In)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;In={error:bi,load:bi,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,o=n?.getAttribute?.(ne);if(o==null||!r||!re(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=re(n);if(o)We(n,o,r)})}};for(let[t,n]of Object.entries(In))document.addEventListener(t,n,!0);for(let t of document.querySelectorAll?.(`img[${Ui}]`)??[]){if(!t.complete||!Vi(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(o)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&We(t,re(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 Yu(e){jc=e}var Fe,Dn=null,vi="[data-reactive-editable][contenteditable=plaintext-only]";function Xi(){if(Fe===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Fe=e.contentEditable==="plaintext-only"}catch{Fe=!1}return Fe}function Pe(e){if(e.matches?.(vi))e.setAttribute("contenteditable","true");e.querySelectorAll?.(vi).forEach(Pe)}function Vc(){if(Dn||typeof document>"u"||typeof document.createElement!=="function")return;if(Xi())return;Pe(document),Dn=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")Pe(t.target);else t.addedNodes.forEach(Pe)}),Dn.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var yi=!1;function wi(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 Yc(){if(yi)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;yi=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=wi(t);if(r)Zc(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(je.set(t,D(n)),!r)return;for(let{name:i}of[...t.attributes])if(!n.hasAttribute(i)&&i!=="contenteditable"&&i!==T)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)=>cr(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===T)&&wi(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(T)&&ir(t)===sr(t))t.removeAttribute(T)})}var T="data-reactive-held",or='[data-controller~="reactive"]',Ie=null,H=new Map;function ir(e){return e.hasAttribute("data-reactive-editable")?D(e):e.value}function sr(e){return e.hasAttribute("data-reactive-editable")?ur(e):e.defaultValue}function Xc(e){if(e.hasAttribute("data-reactive-editable"))return D(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Zc(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||H.has(e.closest(or)))return;let r=Xc(t);if(r===ir(e))return e.removeAttribute(T);if(r===sr(e))return;e.setAttribute(T,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function Qc(e){let t=[];for(let n of e.querySelectorAll(`[${T}]`)){if(n.closest(or)!==e)continue;let r=n.getAttribute("name");if(ir(n)===sr(n))n.removeAttribute(T);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 Zi(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${T}]`))if(n.closest(or)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(T)}function eu(e){let t=e.headers.get("X-Reactive-Refused");if(t==="*")return!0;try{let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ai(e,t,n=null){let r={root:e,streams:0,keep:n},o=Ie;Ie=r;try{window.Turbo.renderStreamMessage(t)}finally{Ie=o}if(r.streams===0)Zi(e,n)}function tu(e){let t=Ie,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++,n.render=async(o)=>{H.set(t.root,(H.get(t.root)||0)+1);try{return await r(o)}finally{let i=H.get(t.root)-1;if(i)H.set(t.root,i);else H.delete(t.root);Zi(t.root,t.keep)}}}var Si="__materialize",Ei=!1;function nu(){if(Ei)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Ei=!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 ar(){if(typeof document>"u")return;if(document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development")zt()}var Qi="data-reactive-active",L=0;function es(){if(L++,L===1)ns("reactive:busy")}function ts(){if(L===0)return;if(L--,L===0)ns("reactive:idle")}function Xu(){return L}function Zu(){L=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(Qi)}function ns(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(Qi,L>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:L}}))}var rs="data-reactive-requests";function os(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!ru(t))return;let n=ou(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(rs,JSON.stringify(n))}function ru(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function ou(e){try{let t=JSON.parse(e.getAttribute(rs));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function xi(){Ic(),Dc(),qc(),Wc(),Bc(),Yc(),Uc(),zc(),Kc(),Vc(),nu(),ar()}function iu(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var is=Symbol.for("phlex-reactive.core");if(globalThis[is])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[is]=!0;var ss=!1;function su(){if(ss)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(su,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var au=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function as(e){let t=String(e).toLowerCase();return t.startsWith("on")||au.has(t)}var qn=new WeakMap;function cu(e,t,n){let[r,o,i]=t;qn.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,qn.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,o,i)};qn.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,uu(e))}function uu(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 lu=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",fu=new Set(["lexxy-editor","trix-editor"]);function D(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 vc(e,t,n){if(n?.transition)cc(e,n.transition,()=>e.hidden=t);else e.hidden=t}function An(e,t,n,r){if(vc(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 wn(e){if(!Si(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function ki(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)Ce(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var yc='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ac(e){return e.querySelectorAll?.(yc)?.[0]??null}function Jn(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 Jo=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"}),Uo=Object.freeze(["meta","ctrl","alt","shift"]);function Me(e,t,n){let r=e.split("+");for(let a of Uo)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Uo.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Jo,o)?Jo[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var wc=(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 Me(wc(e).replace(/^mod\+/,`${o}+`),t,n)}function Sc(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:Jn(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 Ho(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)!==Un(t.currentTarget))return!1;return o<0||n===null||Me(r.slice(o+1),t,n)}function Ec(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 zo=new WeakMap;function _c(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=zo.get(e);if(!o)o=new WeakMap,zo.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 Go=new WeakMap;function xc(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=Go.get(e);if(!o)o=new WeakMap,Go.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 Fn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(jo,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(jo[o](s,i,t),i?.keep===!0)si(s,o,i,t)}}function kc(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 Tc(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Nn(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var Ko='[data-controller~="reactive"]',Rc='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',Cn=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Nn(e);function Yo(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&Cn(r))r=r.parentElement?.closest?.(t);return r??null}var Ee=new WeakMap,_e=new WeakMap;function Lc(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 Oc(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 Fc(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function Nc(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Vo(e){return e.getAttribute?.("data-reactive-presence")!=null}function Cc(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function Zc(e,t,n){}function Mc(e,t){}function Qc(e){return[]}function eu(e){return Promise.resolve()}var Xo=new Set;function $c(e,t,n){let r=e+t;if(Xo.has(r))return;Xo.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 tu(){return["persist","defer","form","bindings","compute","sortable","presence","countdown","effects","hints","devtools"]}var Zo=Promise.resolve();var Qo={enter:hi,exit:gi,count:yi,text:F,served:Bn,waiting:new WeakMap},ei=1,En=2,_n=4,xn=8,kn=16,ti=32,ni=64,ri=128;ft(Qo),Yt(Qo);var X=Symbol.for("phlex-reactive.early"),Pc=1e4,Ic=1500,Un=(e)=>e!=null&&(e===globalThis.window||e.window===e),Dc="dispatch";function Tn(){return globalThis[X]??={queue:[],connected:new WeakSet},globalThis[X]}function qc(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Pc}function Wc(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 jc(e,t,n){return{[X]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:Wc(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 Ne=new WeakMap;function Bc(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Ne.get(e);if(!s)Ne.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 oi(e,t,n,r){if(e?.[X])return!1;let o=Un(e?.currentTarget),i=o?r:e?.currentTarget,a=Uc(e,i,o?`@${t}`:t),s=Ne.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&&!Me(u.filter,e,n))continue;return u.armed=!1,!0}return a}var Re=new WeakMap;function Jc(e,t,n){let r=Re.get(e);if(!r)Re.set(e,r=new Map),setTimeout(()=>Re.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Uc(e,t,n){let r=e&&Re.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class Ti extends Ia{static values={token:String};#h;#f=new Map;#d=new Map;#Y;#w;#C;#S=0;#p=new Map;#E=new WeakMap;#t;featuresReady=Zo;#Fe=new Map;#Ne=new Set;#V=!1;#M=null;#Ce=new Map;#Me=new Map;#$e=new Map;#X=0;#$;#_=0;#o=0;connect(){if(wi=!0,Tn().connected.add(this.element),Ee.set(this.element,this),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||Nn(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===xe)this.#I();this.#P(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(xe,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(jn),this.#X++,this.featuresReady=Zo,this.#P(),Le(this.element),this.#Q()}#P(e){this.#n(ei,"persist",Tc,(t)=>yt(this,t,e)),this.#n(En,"defer",Nn,(t)=>en(this,t,e)),this.#n(_n,"form",Lc,(t)=>_t(this,t,e)),this.#n(xn,"bindings",Oc,(t)=>De(this,t,e)),this.#n(kn,"compute",Fc,(t)=>rt(this,t,e)),this.#n(ti,"sortable",Nc,(t)=>an(this,t)),this.#n(ni,"presence",Vo,(t)=>ln(this,t)),this.#n(ri,"countdown",Cc,(t)=>mn(this,t))}#n(e,t,n,r){if(this.#_&e)return;try{if(!n(this.element))return}catch(o){return this.#D(t,"detect",o)}this.#_|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#D(t,"connect",o)}}#Z(){{let e=this.#o;this.#_=this.#o=0;let t=this.#e();if(e&ei)this.#r("persist",()=>At(this,t));if(e&En)this.#r("defer",()=>tn(this,t));if(e&_n)this.#r("form",()=>xt(this,t));if(e&xn)this.#r("bindings",()=>qe(this,t));if(e&kn)this.#r("compute",()=>ot(this,t));if(e&ti)this.#r("sortable",()=>cn(this,t));if(e&ni)this.#r("presence",()=>fn(this,t));if(e&ri)this.#r("countdown",()=>hn(this,t))}}#r(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Pe(e){}#Ie(e,t){}#De(e){}#qe(e,t){}#We(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#I(),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.#U(),opTargets:(e)=>this.#N(e),diagnose:(e,t)=>this.#F(e,t),applyOps:(e,t)=>Fn(e,(n)=>this.#N(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#F(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#H(),plain:di,text:F,served:Bn,copyMedia:ki,setValue:xi,confirm:(e,t)=>Promise.resolve().then(()=>Lo(e,t)).catch(()=>!1)},this.#$}#I(){if(this.#o&_n)kt(this);if(this.#o&xn)We(this);if(this.#o&kn)it(this)}#D(e,t,n){if($c(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})}#je(){}#Q(){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.#ee();for(let[e,t]of _e.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}_e.delete(this.element)}#x=new Set;#ee(){let{queue:e}=Tn();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=qc(),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(Ic,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.#te(o)}}#te({event:e,el:t,descs:n,win:r}){let o=jc(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&&!Me(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Bc(s,c,r&&JSON.stringify(o.params)))continue;this.#x.add(s)}if(Jc(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Z(),this.#ue(),this.#fe(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(xe,this.#t);if(Tn().connected.delete(this.element),Ee.get(this.element)===this)Ee.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#x)Ne.delete(e);this.#x.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Do&&this.#re())return this.#oe(e);let t=e.params?.shortcut;if(t!=null&&!Sn(t,e,this.application?.schema?.keyMappings))return;if(oi(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.#G(l,p))e.preventDefault();if(n===Do){let v=()=>{if(this.#o&En)return me(this);if(this.tokenValue)return this.#k(p,n,"{}")};return this.#V?this.featuresReady.then(v):v()}let b=this.#q(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(()=>Lo(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return Be(this,this.#e(),t)}#ne(e){}#re(){return!this.tokenValue&&Cn(this.element)}#oe(e){let t=Yo(this.element.parentElement,Rc);if(!t){if(this.element.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] "${e.params.action}": no token on this root or above, nothing sent`);return}let n=Ee.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i}=e.params,a=e.currentTarget??e.target;if((r!=null||!o)&&!this.#G(i,a))e.preventDefault();_e.set(t,[..._e.get(t)??[],[e,a]]);let s=t.dataset;if(s.reactiveDormant)s.controller=`${s.controller??""} ${s.reactiveDormant}`.trim(),delete s.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Sn(t.shortcut,e,this.application?.schema?.keyMappings))return;if(oi(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(xc(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Sc(n.ops),i=o.filter((s)=>Ho(s,e,null)),a=i.length<=1?i:i.filter((s)=>Ho(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())Bt(this,e);return}for(let s of a){if(s.outside&&e[X])continue;if(!Ec(s,e))continue;if(s.shortcut!=null&&!Sn(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(_c(this,e,s))continue;this.#ie(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0}:s,e,r,o.indexOf(s))}}#ie(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.#q(i,a),f=this.#se(e,r,n,()=>this.#Ee(this.#Se(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)}#se(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.#W(n,a,o,r);return()=>this.#j(n,a,i,r)}recompute(e){return st(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return Ye(this,this.#e(),e)}tagsPick(e){return Ve(this,this.#e(),e)}tagsRemove(e){return Xe(this,this.#e(),e)}nestedAdd(e){return Ze(this,this.#e(),e)}nestedRemove(e){return Qe(this,this.#e(),e)}syncNestedJson(e){return je(this,this.#e(),e)}#Be(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.#ae(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"})}#ae(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.#U();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.#ce(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#le(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.#_e(e,r,i),s=Boolean(n||o),c=(p)=>{if(!s||!p)return;let b=this.#e();if(i.inverse=Ht(this,b,n,r),i.undo.push(...Ut(this,b,o,r)),this.#R())i.resurrect=zt(this,b,n,r)},u=!0;c(!0);let l=()=>this.#he(e,t,i,a),f=()=>this.#M?this.#M.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Je(){return this.#ne("hints")}#ce(e,t,n,r,o,i){this.#W(e,Dc,t,()=>this.#v(n,r,o,e,i))}#W(e,t,n,r){this.#T(e,t);let o=()=>{this.#T(e,t),r()},i=setTimeout(o,n);if(!Un(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)}#ue(){for(let[e,t]of[...this.#f])for(let n of[...t.keys()])this.#T(e,n)}#le(e,t,n,r,o,i){return this.#j(e,n,t,()=>this.#v(n,r,o,e,i))}#j(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()}#fe(){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)}#de(){this.element?.removeAttribute?.("data-reactive-error")}#pe(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#me(){return It()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#B(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#he(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.#Ae(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#B()}:null;await this.#me();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.#Le()};if(!u)h["Content-Type"]="application/json";let d=this.#Oe();if(d)h["X-Pgbus-Connection"]=d;let y=Vo(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(y)h["X-Reactive-Presence"]=y;let A=ec(this.element);if(A)h["X-Reactive-Held"]=A;yi("action"),p=await fetch(this.#Te(),{method:"POST",headers:h,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Re())})}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.#pe(),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.#J(h);if(this.#c=d??this.#c,f)ce(f,h,d);Io(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.#J(g);if(this.#c=v??this.#c,f)ce(f,g,v);if(Io(this.element,g),n.resurrect)queueMicrotask(n.resurrect);return this.#de(),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.#B()-f.started})}}get#c(){return this.#h??this.tokenValue}set#c(e){this.#h=e}tokenValueChanged(){this.#h=void 0}#J(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#ge(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}#ge(e){let t=this.#C;if(t&&t.id===e)return t;let n=ic(e);return this.#C={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}#U(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#y(t)}#be(){let e=this.element.querySelectorAll(Ko);if(e.length===0||[...e].every(Cn))return()=>!0;return(t)=>Yo(t,Ko,this.element)===this.element}#H(){let e={},t=[],n=this.#be(),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]${lc}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#ve(r),a=this.#ye(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("[]")&&!dc(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}}#ve(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}#ye(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#Ae(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.#L(o,this.#A(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#we(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("")}`}#L(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#L(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#L(e,`${t}[${r}]`,o);else e.append(t,String(n))}#we(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{}}}#Se(e){return Jn(e)}#Ee(e){Fn(e,(t)=>this.#N(t),(t,n)=>this.#F(`client op "${t}"`,n))}#O(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#R()}#F(e,t){if(!this.#O())return;jt(this,e,t)}#Ue(e){}#N(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))}#G(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()}#_e(e,t,n){this.#xe(e,t),hi();let r=!1;return()=>{if(r)return;r=!0,this.#ke(e,t),gi();for(let o of n.undo)o()}}#xe(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.#K(e))this.#l(n,e,1)}#ke(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.#K(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(" "))}#K(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#y(n))}#Te(){return this.#Y??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Re(){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}#Le(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Oe(){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)Wo();else document.addEventListener("turbo:load",Wo,{once:!0});Wn();var lu=Ti;export{mi as ACTIVE_ATTR,lc as EDITOR_SELECTOR,fc as EDITOR_TAGS,aa as LATENCY_KEY,vi as REQUESTS_ATTR,sc as checkReactiveRegistration,yi as countReactiveRequest,lu as default,Ur as disableLatencySim,F as editableValue,Jr as enableLatencySim,hi as enterReactiveActivity,ic as escapeRegExp,gi as exitReactiveActivity,eu as loadReactiveFeature,Yc as onReactiveStreamWithoutEffects,Vc as reactiveActivityCount,tu as reactiveFeatureNames,Wo as registerReactiveActions,ja as registerReactiveDefer,Wn as registerReactiveDev,Ja as registerReactiveDismiss,Ja as registerReactiveEffects,Mc as registerReactiveFeature,Zc as registerReactiveFeatureLoader,Ya as registerReactiveImageFallback,Wa as registerReactiveJs,Ka as registerReactiveKeep,Ga as registerReactiveModals,Xa as registerReactiveMorphFocus,nc as registerReactiveOffline,Va as registerReactivePlaintext,Ja as registerReactiveStreamRender,qa as registerReactiveToken,Da as registerReactiveVisit,Xc as resetReactiveActivity,Bn as serverText,Qc as unloadedFeaturesFor};
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var je=new WeakMap;function cr(e){if(e?.hasAttribute?.("data-reactive-editable")&&!je.has(e))je.set(e,D(e))}function ur(e){return cr(e),je.get(e)}function du(e){return fu.has(e.localName)?typeof e.value==="string":!0}var _i=Object.freeze({show:(e,t,n)=>jn(e,!1,t,n),hide:(e,t,n)=>jn(e,!0,t,n),toggle:(e,t,n)=>jn(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(Bn(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Bn(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Bn(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)=>wu(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Hi(e),close_dialog:(e)=>Hc(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{}fs(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)nt(r,t.group,t.checked)},presence:(e,t)=>Mn(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=pu(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)=>mu(e),preview_file:(e,t,n)=>hu(e,t,n),set_value:(e,t)=>ls(e,String(t.value??"")),persist_state:(e,t)=>Ft(e,t.state),persist_clear:(e)=>Mt(e)});function pu(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function mu(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,us(e),e.focus?.()}).catch(()=>{})}var oe=new Map,ie=null;function hu(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return Wn(`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 Wn(`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=gu(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(cs(r),s){let l=URL.createObjectURL(s);oe.set(r,l),r.setAttribute("src",l),bu()}else r.removeAttribute("src");if(Je(r),t.wrap!=null){let l=n({...t,to:t.wrap});if(l.length===0)Wn(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let f of l)s?Ki(f):zi(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 gu(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 Wn(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function cs(e){let t=oe.get(e);if(t===void 0)return;if(oe.delete(e),URL.revokeObjectURL(t),oe.size===0)ie?.disconnect(),ie=null}function bu(){if(ie||typeof MutationObserver!=="function"||!document?.documentElement)return;ie=new MutationObserver(()=>{for(let[e,t]of oe)if(!e.isConnected||e.getAttribute("src")!==t)cs(e)}),ie.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function us(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function ls(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=ki(e);if(e.value=t,ki(e)!==n)us(e)}function ki(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function vu(e,t,n){if(n?.transition)cu(e,n.transition,()=>e.hidden=t);else e.hidden=t}function jn(e,t,n,r){if(vu(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 Bn(e){if(!as(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function fs(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)Je(e);let i=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==i)e.setAttribute("alt",i);return n?i:!1}var yu='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function wu(e){return e.querySelectorAll?.(yu)?.[0]??null}function lr(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 Ti=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"}),Ri=Object.freeze(["meta","ctrl","alt","shift"]);function He(e,t,n){let r=e.split("+");for(let a of Ri)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let o=r.find((a)=>!Ri.includes(a));if(o===void 0||typeof t.key!=="string")return!0;let i=n&&Object.hasOwn(n,o)?n[o]:Object.hasOwn(Ti,o)?Ti[o]:/^[a-z0-9]$/.test(o)?o:null;return typeof i==="string"&&i.toLowerCase()===t.key.toLowerCase()}var Au=(e)=>e&&typeof e==="object"?e.keys:String(e);function Jn(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 He(Au(e).replace(/^mod\+/,`${o}+`),t,n)}function Su(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:lr(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 Li(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)!==fr(t.currentTarget))return!1;return o<0||n===null||He(r.slice(o+1),t,n)}function Eu(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 Oi=new WeakMap;function xu(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,o=Oi.get(e);if(!o)o=new WeakMap,Oi.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 Ni=new WeakMap;function _u(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=Ni.get(e);if(!o)o=new WeakMap,Ni.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 Zn(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[o,i={}]=r;if(!Object.hasOwn(_i,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(_i[o](s,i,t),i?.keep===!0)Gi(s,o,i,t)}}function ku(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 Tu(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Qn(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var Fi='[data-controller~="reactive"]',Ru='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',er=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Qn(e);function Mi(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&er(r))r=r.parentElement?.closest?.(t);return r??null}var Me=new WeakMap,Ce=new WeakMap;function Lu(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 Ou(e){return["show-targets","group-targets","on-complete","filter-input","tags-field","css-vars"].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], [data-reactive-css-vars]")!=null}function Nu(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function Fu(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Mu(e){return Boolean(e.matches?.("[data-reactive-frame],[data-reactive-box],[data-reactive-point]")||e.querySelector?.("[data-reactive-frame],[data-reactive-box],[data-reactive-point]"))}function Ci(e){return e.getAttribute?.("data-reactive-presence")!=null}function Cu(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}function Qu(e,t,n){}function $u(e,t){}function el(e){return[]}function tl(e){return Promise.resolve()}var $i=new Set;function Pu(e,t,n){let r=e+t;if($i.has(r))return;$i.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 nl(){return["persist","defer","form","bindings","compute","sortable","drag","presence","countdown","effects","hints","devtools"]}var Pi=Promise.resolve();var Ii={enter:es,exit:ts,count:os,text:D,served:ur,waiting:new WeakMap},Di=1,Hn=2,Gn=4,Un=8,zn=16,qi=32,Wi=64,ji=128,Bi=256;St(Ii),an(Ii);var se=Symbol.for("phlex-reactive.early"),Iu=1e4,Du=1500,fr=(e)=>e!=null&&(e===globalThis.window||e.window===e),qu="dispatch";function Kn(){return globalThis[se]??={queue:[],connected:new WeakSet},globalThis[se]}function Wu(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Iu}function ju(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 Bu(e,t,n){return{[se]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:ju(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 Be=new WeakMap;function Ju(e,{token:t,type:n,method:r,filter:o,win:i},a){let s=Be.get(e);if(!s)Be.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 Ji(e,t,n,r){if(e?.[se])return!1;let o=fr(e?.currentTarget),i=o?r:e?.currentTarget,a=Gu(e,i,o?`@${t}`:t),s=Be.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&&!He(u.filter,e,n))continue;return u.armed=!1,!0}return a}var De=new WeakMap;function Hu(e,t,n){let r=De.get(e);if(!r)De.set(e,r=new Map),setTimeout(()=>De.delete(e));let o=r.get(t)??{};r.set(t,o),o[n]=(o[n]??0)+1}function Gu(e,t,n){let r=e&&De.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class ds extends Pc{static values={token:String};#h;#f=new Map;#d=new Map;#V;#A;#M;#S=0;#p=new Map;#E=new WeakMap;#r;featuresReady=Pi;#Ne=new Map;#Fe=new Set;#Y=!1;#C=null;#Me=new Map;#Ce=new Map;#$e=new Map;#X=0;#$;#x=0;#o=0;connect(){if(ss=!0,Kn().connected.add(this.element),Me.set(this.element,this),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||Qn(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===$e)this.#I();this.#P(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.($e,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(cr),this.#X++,this.featuresReady=Pi,this.#P(),qe(this.element),this.#Q()}#P(e){this.#t(Di,"persist",Tu,(t)=>Ot(this,t,e)),this.#t(Hn,"defer",Qn,(t)=>dn(this,t,e)),this.#t(Gn,"form",Lu,(t)=>$t(this,t,e)),this.#t(Un,"bindings",Ou,(t)=>Ke(this,t,e)),this.#t(zn,"compute",Nu,(t)=>mt(this,t,e)),this.#t(qi,"sortable",Fu,(t)=>vn(this,t)),this.#t(Bi,"drag",Mu,(t)=>_n(this,t)),this.#t(Wi,"presence",Ci,(t)=>Nn(this,t)),this.#t(ji,"countdown",Cu,(t)=>$n(this,t))}#t(e,t,n,r){if(this.#x&e)return;try{if(!n(this.element))return}catch(o){return this.#D(t,"detect",o)}this.#x|=e;try{r(this.#e()),this.#o|=e}catch(o){this.#D(t,"connect",o)}}#Z(){{let e=this.#o;this.#x=this.#o=0;let t=this.#e();if(e&Di)this.#n("persist",()=>Nt(this,t));if(e&Hn)this.#n("defer",()=>pn(this,t));if(e&Gn)this.#n("form",()=>Pt(this,t));if(e&Un)this.#n("bindings",()=>Ve(this,t));if(e&zn)this.#n("compute",()=>ht(this,t));if(e&qi)this.#n("sortable",()=>yn(this,t));if(e&Bi)this.#n("drag",()=>kn(this,t));if(e&Wi)this.#n("presence",()=>Fn(this,t));if(e&ji)this.#n("countdown",()=>Pn(this,t))}}#n(e,t){try{t()}catch(n){console.error(`[phlex-reactive] the "${e}" feature module failed to disconnect`,n)}}#Pe(e){}#Ie(e,t){}#De(e){}#qe(e,t){}#We(e,t,n,r){}#e(){return this.#$??={emit:(e,t,n)=>this.#s(e,t,n),reseed:()=>this.#I(),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.#H(),opTargets:(e)=>this.#F(e),diagnose:(e,t)=>this.#N(e,t),applyOps:(e,t)=>Zn(e,(n)=>this.#F(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#N(`client op "${n}"`,r)),listnavOptions:(e)=>this.#m(e),collectFields:()=>this.#G(),plain:Xi,text:D,served:ur,copyMedia:fs,setValue:ls,confirm:(e,t)=>Promise.resolve().then(()=>pi(e,t)).catch(()=>!1)},this.#$}#I(){if(this.#o&Gn)It(this);if(this.#o&Un)Ye(this);if(this.#o&zn)gt(this)}#D(e,t,n){if(Pu(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})}#je(){}#Q(){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.#ee();for(let[e,t]of Ce.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Ce.delete(this.element)}#_=new Set;#ee(){let{queue:e}=Kn();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=Wu(),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(Du,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.#te(o)}}#te({event:e,el:t,descs:n,win:r}){let o=Bu(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&&!He(c.filter,e,i))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Ju(s,c,r&&JSON.stringify(o.params)))continue;this.#_.add(s)}if(Hu(e,s,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(o);else this.dispatch(o)}}disconnect(){if(this.#Z(),this.#ue(),this.#fe(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.($e,this.#r);if(Kn().connected.delete(this.element),Me.get(this.element)===this)Me.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#_)Be.delete(e);this.#_.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Si&&this.#re())return this.#oe(e);let t=e.params?.shortcut;if(t!=null&&!Jn(t,e,this.application?.schema?.keyMappings))return;if(Ji(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.#z(l,p))e.preventDefault();if(n===Si){let h=()=>{if(this.#o&Hn)return Ee(this);if(this.tokenValue)return this.#k(p,n,"{}")};return this.#Y?this.featuresReady.then(h):h()}let b=this.#q(a,s),v=()=>this.#k(p,n,r,o,i,l,f);if(!b)return v();if(b instanceof Promise)return b.then((h)=>h?this.#g(h,p,v):v());this.#g(b,p,v)}#g(e,t,n){return Promise.resolve().then(()=>pi(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#q(e,t){if(e)return e;if(!t)return null;return Ze(this,this.#e(),t)}#ne(e){}#re(){return!this.tokenValue&&er(this.element)}#oe(e){let t=Mi(this.element.parentElement,Ru);if(!t){if(this.element.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] "${e.params.action}": no token on this root or above, nothing sent`);return}let n=Me.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:o,optimistic:i}=e.params,a=e.currentTarget??e.target;if((r!=null||!o)&&!this.#z(i,a))e.preventDefault();Ce.set(t,[...Ce.get(t)??[],[e,a]]);let s=t.dataset;if(s.reactiveDormant)s.controller=`${s.controller??""} ${s.reactiveDormant}`.trim(),delete s.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Jn(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Ji(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(_u(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,o=Su(n.ops),i=o.filter((s)=>Li(s,e,null)),a=i.length<=1?i:i.filter((s)=>Li(s,e,this.application?.schema?.keyMappings));if(a.length===0&&o.length>0){if(this.#O())Qt(this,e);return}for(let s of a){if(s.outside&&e[se])continue;if(!Eu(s,e))continue;if(s.shortcut!=null&&!Jn(s.shortcut,e,this.application?.schema?.keyMappings))continue;if(xu(this,e,s))continue;this.#ie(s.legacy?{...n,ops:s.ops,debounce:void 0,throttle:void 0}:s,e,r,o.indexOf(s))}}#ie(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.#q(i,a),f=this.#se(e,r,n,()=>this.#Ee(this.#Se(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)}#se(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.#W(n,a,o,r);return()=>this.#j(n,a,i,r)}recompute(e){return bt(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#m(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return st(this,this.#e(),e)}tagsPick(e){return at(this,this.#e(),e)}tagsRemove(e){return ct(this,this.#e(),e)}nestedAdd(e){return ut(this,this.#e(),e)}nestedRemove(e){return lt(this,this.#e(),e)}syncNestedJson(e){return Xe(this,this.#e(),e)}#Be(e,t){}trackDirty(){he(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.#ae(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"})}#ae(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.#H();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.#ce(e,c,t,n,i,a);let u=Number(o)||0;if(u>0)return this.#le(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.#xe(e,r,i),s=Boolean(n||o),c=(p)=>{if(!s||!p)return;let b=this.#e();if(i.inverse=nn(this,b,n,r),i.undo.push(...tn(this,b,o,r)),this.#R())i.resurrect=rn(this,b,n,r)},u=!0;c(!0);let l=()=>this.#he(e,t,i,a),f=()=>this.#C?this.#C.then(l):l();return this.queue=(this.queue??Promise.resolve()).then(()=>f()),this.queue}#Je(){return this.#ne("hints")}#ce(e,t,n,r,o,i){this.#W(e,qu,t,()=>this.#v(n,r,o,e,i))}#W(e,t,n,r){this.#T(e,t);let o=()=>{this.#T(e,t),r()},i=setTimeout(o,n);if(!fr(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)}#ue(){for(let[e,t]of[...this.#f])for(let n of[...t.keys()])this.#T(e,n)}#le(e,t,n,r,o,i){return this.#j(e,n,t,()=>this.#v(n,r,o,e,i))}#j(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()}#fe(){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)}#de(){this.element?.removeAttribute?.("data-reactive-error")}#pe(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#me(){return Kt()}#R(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#B(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#he(e,t,n,r){let{fields:o,files:i}=this.#G(),a=this.#U(t),s={...o,...a},c=this.#c,u=i.length>0,l=u?this.#we(c,e,s,i):JSON.stringify({token:c,act:e,params:s}),f=this.#R()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(o),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#B()}:null;await this.#me();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#i("offline"),this.#a(e,t,s,{kind:"offline"});return}let p;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Le()};if(!u)m["Content-Type"]="application/json";let d=this.#Oe();if(d)m["X-Pgbus-Connection"]=d;let w=Ci(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(w)m["X-Reactive-Presence"]=w;let A=Qc(this.element);if(A)m["X-Reactive-Held"]=A;os("action"),p=await fetch(this.#Te(),{method:"POST",headers:m,body:l,credentials:"same-origin",signal:AbortSignal.timeout(this.#Re())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#u(n.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#i("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#pe(),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 m=await p.text();if(console.error(`[phlex-reactive] action failed: HTTP ${p.status}`,m),this.#u(n.inverse),(p.headers.get("Content-Type")||"").includes("turbo-stream")){let d=this.#J(m);if(this.#c=d??this.#c,f)be(f,m,d);Ai(this.element,m,!0)}this.#i("http"),this.#a(e,t,s,{kind:"http",status:p.status,body:m});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 v=await p.text(),h=this.#J(v);if(this.#c=h??this.#c,f)be(f,v,h);if(Ai(this.element,v,eu(p)),n.resurrect)queueMicrotask(n.resurrect);return this.#de(),this.#s("reactive:applied",{action:e,params:s,html:v}),v}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)en(this,{...f,ms:this.#B()-f.started})}}get#c(){return this.#h??this.tokenValue}set#c(e){this.#h=e}tokenValueChanged(){this.#h=void 0}#J(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#ge(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}#ge(e){let t=this.#M;if(t&&t.id===e)return t;let n=iu(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}#H(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#y(t)}#be(){let e=this.element.querySelectorAll(Fi);if(e.length===0||[...e].every(er))return()=>!0;return(t)=>Mi(t,Fi,this.element)===this.element}#G(){let e={},t=[],n=this.#be(),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]${lu}`).forEach((s)=>{if(n(s))o.push(s)});let i=this.#ve(r),a=this.#ye(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?D(s):s.value??s.textContent??s.innerHTML??"",l=e[c];if(String(c).endsWith("[]")&&!du(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}}#ve(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}#ye(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#we(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.#w(s)}[]`;for(let l of c)o.append(u,String(l))}else this.#L(o,this.#w(s),c);for(let s of i)o.append("empty_groups[]",s);let a=this.#Ae(r);for(let{name:s,file:c,multiple:u}of r){let f=u||a.has(s)?`${this.#w(s)}[]`:this.#w(s);o.append(f,c,c.name)}return o}#w(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("")}`}#L(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,o)=>this.#L(e,`${t}[${o}]`,r));else if(typeof n==="object")for(let[r,o]of Object.entries(n))this.#L(e,`${t}[${r}]`,o);else e.append(t,String(n))}#Ae(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{}}}#Se(e){return lr(e)}#Ee(e){Zn(e,(t)=>this.#F(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;Zt(this,e,t)}#He(e){}#F(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))}#z(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()}#xe(e,t,n){this.#_e(e,t),es();let r=!1;return()=>{if(r)return;r=!0,this.#ke(e,t),ts();for(let o of n.undo)o()}}#_e(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.#K(e))this.#l(n,e,1)}#ke(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.#K(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(" "))}#K(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#y(n))}#Te(){return this.#V??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#Re(){if(this.#A!=null)return this.#A;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#A=Number.isFinite(t)&&t>0?t:30000}#Le(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Oe(){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)xi();else document.addEventListener("turbo:load",xi,{once:!0});ar();var fl=ds;export{Qi as ACTIVE_ATTR,lu as EDITOR_SELECTOR,fu as EDITOR_TAGS,Ya as LATENCY_KEY,rs as REQUESTS_ATTR,su as checkReactiveRegistration,os as countReactiveRequest,fl as default,fo as disableLatencySim,D as editableValue,lo as enableLatencySim,es as enterReactiveActivity,iu as escapeRegExp,ts as exitReactiveActivity,tl as loadReactiveFeature,Yu as onReactiveStreamWithoutEffects,Xu as reactiveActivityCount,nl as reactiveFeatureNames,xi as registerReactiveActions,Wc as registerReactiveDefer,ar as registerReactiveDev,Bc as registerReactiveDismiss,Bc as registerReactiveEffects,$u as registerReactiveFeature,Qu as registerReactiveFeatureLoader,Kc as registerReactiveImageFallback,qc as registerReactiveJs,zc as registerReactiveKeep,Uc as registerReactiveModals,Yc as registerReactiveMorphFocus,nu as registerReactiveOffline,Vc as registerReactivePlaintext,Bc as registerReactiveStreamRender,Dc as registerReactiveToken,Ic as registerReactiveVisit,Zu as resetReactiveActivity,ur as serverText,el as unloadedFeaturesFor};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=78077FD2C2D197C664756E2164756E21
|
|
9
9
|
//# sourceMappingURL=reactive_controller.min.js.map
|