phlex-reactive 0.19.3 → 0.19.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +47 -1
- data/README.md +53 -1
- data/app/javascript/phlex/reactive/core.min.js +4 -4
- data/app/javascript/phlex/reactive/core.min.js.map +3 -3
- data/app/javascript/phlex/reactive/features/bindings.js +40 -2
- 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/reactive_controller.min.js +4 -4
- data/app/javascript/phlex/reactive/reactive_controller.min.js.map +4 -4
- data/app/javascript/phlex/reactive/runtime.js +137 -25
- data/lib/phlex/reactive/component/helpers.rb +50 -2
- data/lib/phlex/reactive/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 385b76904911734cc396008e7b8b4015c11718c7bbf85c955e75b48bb6ecae73
|
|
4
|
+
data.tar.gz: 521bb57711184cbc4fb7f44ea4033190e8e2800324bd87b2c97a0d5fafc9c191
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cd42ed58146cf11fc6079e4b64bed0f234ba8e9d1e73066b5e397b0a1c3b6f4f3b6a942e353e107b76b2cee93dfbad0ed489297da2b2143b524e12abeb7fd769
|
|
7
|
+
data.tar.gz: c8921cc096e6af2444b6318e1ff5060a6a7fe473b9b96315dd1b76f130b1e1eb9bacdd2ba47c826dbc9a7528afa2f35cc026bc1bbc84748a57a4d5975829232a
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,51 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.19.4] - 2026-12-02
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **`reactive_listnav(highlight: :first)` (#492).** The first navigable option
|
|
14
|
+
stays highlighted whenever none is — at connect, after a `reactive_filter`
|
|
15
|
+
pass, after a morph or a stream into the root — so "type, Enter" opens the
|
|
16
|
+
top match. A highlight moved with the arrows survives while its option is
|
|
17
|
+
visible; a changed query, or a morph that re-renders the options, puts it
|
|
18
|
+
back on the first. Home/End move it while the query is empty
|
|
19
|
+
(`ctrl+Home`/`ctrl+End` always), `meta`/`ctrl`+Enter clicks the option with
|
|
20
|
+
that modifier held (a link opens as a modified click does), and Escape is
|
|
21
|
+
not bound. The highlight is announced: the option gets `aria-selected="true"`
|
|
22
|
+
(one it already carries from the server is left alone) and the input's
|
|
23
|
+
`aria-activedescendant` names its id (generated when missing). Combining it
|
|
24
|
+
with `focus: true`, or any other value, raises. Without it the markup and
|
|
25
|
+
the ARIA are unchanged.
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- **perf: the listnav keypress and the filter keystroke cost a little more
|
|
30
|
+
(#492).** Skipping options under a hidden ancestor, clearing the highlight
|
|
31
|
+
from every option, and probing for a `highlight: :first` input add ~5 µs to
|
|
32
|
+
an Arrow key and a keystroke over 200 options, and ~2–10 µs to a filter
|
|
33
|
+
root's connect (happy-dom, `rake bench:client`, which gains a listnav bench
|
|
34
|
+
and a filter-root connect shape). See the performance page.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- **Listnav skips options under a hidden ancestor (#492).** An option counts
|
|
39
|
+
only when no ancestor up to the root is `hidden`, so the arrows no longer
|
|
40
|
+
walk into, and Enter no longer activates, an option in a group a
|
|
41
|
+
`reactive_show` hid.
|
|
42
|
+
- **A stream into a client-only root re-runs its client bindings (#492).** A
|
|
43
|
+
root without a token had no listener for a stream rendered into it, so its
|
|
44
|
+
`reactive_filter`, show bindings and listnav highlight went stale until the
|
|
45
|
+
next morph or keystroke.
|
|
46
|
+
- **Listnav ignores a key an IME is composing with (#492).** Its Enter commits
|
|
47
|
+
the composition; it no longer picks an option or adds a tag.
|
|
48
|
+
- **One listnav highlight at a time (#492).** Moving the highlight clears it
|
|
49
|
+
from every option the selector matches, so an option highlighted, hidden
|
|
50
|
+
and shown again no longer comes back as a second highlight. Under
|
|
51
|
+
`highlight: :first` a tag picked without a `reactive_filter` moves the
|
|
52
|
+
highlight on too.
|
|
53
|
+
|
|
9
54
|
## [0.19.3] - 2026-12-02
|
|
10
55
|
|
|
11
56
|
### Added
|
|
@@ -4827,7 +4872,8 @@ room for dogfood fixes.
|
|
|
4827
4872
|
scaffolds a reactive component (and an RSpec spec when the app uses RSpec),
|
|
4828
4873
|
state-backed by default or record-backed with `--record`.
|
|
4829
4874
|
|
|
4830
|
-
[Unreleased]: https://github.com/mhenrixon/phlex-reactive/compare/v0.19.
|
|
4875
|
+
[Unreleased]: https://github.com/mhenrixon/phlex-reactive/compare/v0.19.4...HEAD
|
|
4876
|
+
[0.19.4]: https://github.com/mhenrixon/phlex-reactive/compare/v0.19.3...v0.19.4
|
|
4831
4877
|
[0.19.3]: https://github.com/mhenrixon/phlex-reactive/compare/v0.19.2...v0.19.3
|
|
4832
4878
|
[0.19.2]: https://github.com/mhenrixon/phlex-reactive/compare/v0.19.1...v0.19.2
|
|
4833
4879
|
[0.19.1]: https://github.com/mhenrixon/phlex-reactive/compare/v0.19.0...v0.19.1
|
data/README.md
CHANGED
|
@@ -708,7 +708,7 @@ Use in controllers: `render turbo_stream: Counter.replace(counter)`.
|
|
|
708
708
|
| `reactive_persist(key:, ttl: 7.days)` | **Client-only drafts**: spread on the **root** (once) and the generic controller keeps a `localStorage` draft of every **owned** control — debounced write on `input`, immediate on `change`, flushed on disconnect, restored into **blank** controls on the next connect (`restore: :always` lets the draft win), cleared by a successful Turbo submit / `ttl` / `js.persist_clear`. Never hidden/file/password; `reactive_persist_skip` opts a control out; `fields:` narrows; `storage: :session` keeps the draft in this tab's `sessionStorage` instead. See [Client-only drafts](#client-only-drafts-reactive_persist). |
|
|
709
709
|
| `js.persist_state(step: 2)` / `js.persist_clear` | The draft ops (actor-only): merge a flat state bag into the draft (restored as `data-reactive-persist-state` + the `reactive:persist-restored` event) / forget the draft. |
|
|
710
710
|
| `reactive_filter(:field, option: nil, group: nil, empty: nil, match: :substring, fold: false)` | **Client-side option filtering** for a preloaded combobox: spread onto the root and name the **field** that drives it — `reactive_filter(:q)` compiles `:q` to `[name="q"]` (scope-aware) and typing shows/hides the options by their `data-reactive-filter-text` haystack, **zero round trips**. `option:` defaults to `[role=option]`; optional `group:` collapses an all-hidden group header; `empty:` reveals a no-matches node. `match:` is where the query must sit in the haystack — `:substring` (anywhere, the default), `:prefix` (at its start) or `:word_start` (at the start of any word); `fold: true` strips accents (combining marks) on both sides (`"zur"` finds Zürich). `input:` is the escape hatch — a raw CSS selector for a **name-less** driving input (`input: "#tags_query"`), the form-builder case. See [Client-side option filtering](#client-side-option-filtering-reactive_filter). |
|
|
711
|
-
| `reactive_listnav("[role=option]")` | The **standalone** combobox keyboard wiring (Arrow/Enter/Escape) for an input that fires **no action** — the preload-and-filter case. Same behavior as `on(…, listnav:)`, minus the POST. `reactive_listnav(focus: true)` is the **roving-focus** variant for a `role="menu"` container: Arrow Down/Up move real focus among `[role=menuitem]` (wrapping), Home/End jump to the edges; Enter/Space stay native and Escape is yours to bind. |
|
|
711
|
+
| `reactive_listnav("[role=option]")` | The **standalone** combobox keyboard wiring (Arrow/Enter/Escape) for an input that fires **no action** — the preload-and-filter case. Same behavior as `on(…, listnav:)`, minus the POST. `reactive_listnav(focus: true)` is the **roving-focus** variant for a `role="menu"` container: Arrow Down/Up move real focus among `[role=menuitem]` (wrapping), Home/End jump to the edges; Enter/Space stay native and Escape is yours to bind. `reactive_listnav(highlight: :first)` keeps the first visible option highlighted (type, Enter), adds Home/End and a modified Enter, and leaves Escape to you. |
|
|
712
712
|
| `reactive_tags(:tags)` | **Tag-chip input** (the combobox/tags widget): spread onto the root and name the hidden field that stores the **comma-joined** value — the client maintains that field + the chip list entirely client-side (form state, zero round trips), rebuilding chips from your server-owned `<template>`. Composes with `reactive_filter` (type to narrow) and `reactive_listnav` (Enter picks the highlighted option). `name:` is the escape hatch — a **verbatim** wire name (`name: "user[tags]"`, never re-scoped), the form-builder case. See [Tag-chip input](#tag-chip-input-reactive_tags). |
|
|
713
713
|
| `reactive_tags_add` / `reactive_tags_option(tag)` / `reactive_tags_remove(tag)` | The tags triggers, all **client-only**: `reactive_tags_add` on the query input adds the typed text on Enter (mix it **after** `reactive_listnav`; Enter never submits the enclosing form); `reactive_tags_option` makes a preloaded suggestion add its declared tag on click; `reactive_tags_remove` is a chip's remove button (no arg inside the template — the client fills the tag per chip). |
|
|
714
714
|
| `reactive_compute :name, inputs: { title: :string, qty: :number }, outputs:` | **Typed** inputs: a `:string` reaches the JS reducer raw, a `:number` is coerced through `Number`, a `:boolean` is a checkbox's checked state. The array form (`inputs: %i[a b]`) stays all-numeric; the **permit-style** form (`inputs: [:qty, title: :string]`) mixes both — bare symbols default `:number`, a trailing hash types the exceptions. `outputs:` is the field allowlist; a reducer-result key also paints any owned `reactive_text` node by presence and any `mirror:` id, so an `outputs:` entry that exists only to reach a text node is redundant (harmless — a widening). |
|
|
@@ -2945,6 +2945,58 @@ Enter **clicks the highlighted option** — so selection runs through its normal
|
|
|
2945
2945
|
Escape clears the highlight. Only the highlight is client-side — the selection
|
|
2946
2946
|
stays a real signed action, and the highlight is never shipped as trusted state.
|
|
2947
2947
|
|
|
2948
|
+
An option counts only while it **and every ancestor up to the root** are
|
|
2949
|
+
visible: an option in a group a `reactive_show` (or anything else) has
|
|
2950
|
+
`hidden` is skipped by the arrows and never picked by Enter. A key an IME is
|
|
2951
|
+
composing with (its Enter commits the composition) is never a listnav key:
|
|
2952
|
+
not the arrows, not Enter, not Escape.
|
|
2953
|
+
|
|
2954
|
+
**Highlight the first option — `highlight: :first`.** A results list is
|
|
2955
|
+
expected to open its top match on "type, Enter". Opt in and the first
|
|
2956
|
+
navigable option stays highlighted whenever none is — at connect, after every
|
|
2957
|
+
`reactive_filter` pass, and after a morph or a stream changed the root:
|
|
2958
|
+
|
|
2959
|
+
```ruby
|
|
2960
|
+
input(name: "q", role: "combobox", **reactive_listnav(highlight: :first))
|
|
2961
|
+
```
|
|
2962
|
+
|
|
2963
|
+
- A highlight the user moved with the arrows stays while its option is
|
|
2964
|
+
visible. The query **value** having changed sends it back to the first
|
|
2965
|
+
option at the next sync — the `reactive_filter` pass on that keystroke, or
|
|
2966
|
+
the morph or stream a server search answers with (a bare `reactive_listnav`
|
|
2967
|
+
does not listen to the input itself) — and so does a morph that re-renders
|
|
2968
|
+
the options (the server's render does not carry the client's highlight).
|
|
2969
|
+
- The highlight is announced to assistive technology: the option gets
|
|
2970
|
+
`aria-selected="true"` and the input's `aria-activedescendant` names its id
|
|
2971
|
+
(an id is generated when the option has none); both go with the highlight.
|
|
2972
|
+
In this mode the listnav owns `aria-selected` on the options: an option the
|
|
2973
|
+
server rendered with `aria-selected` keeps it, but a list that marks its
|
|
2974
|
+
**picked** option `aria-selected` from a client op (the pick-list recipe
|
|
2975
|
+
above) should mark it another way. Without `highlight:` no ARIA is written
|
|
2976
|
+
or removed.
|
|
2977
|
+
- Home/End move the highlight to the first/last option **while the query is
|
|
2978
|
+
empty**, and move the caret in a filled field; `ctrl+Home`/`ctrl+End` always
|
|
2979
|
+
move the highlight.
|
|
2980
|
+
- `meta+Enter`/`ctrl+Enter` activate the highlighted option with that modifier
|
|
2981
|
+
held (a synthetic modified click), so a link option opens the way a
|
|
2982
|
+
modified click opens it. A button option ignores the modifier.
|
|
2983
|
+
- Escape is not bound: the highlight stays, and closing the list is your own
|
|
2984
|
+
binding.
|
|
2985
|
+
- An automatic highlight never scrolls; only a key move scrolls the option
|
|
2986
|
+
into view.
|
|
2987
|
+
- A list revealed on the client (a `reactive_show` or `js.show` un-hiding
|
|
2988
|
+
the root or the options' group) is not re-highlighted by the reveal itself:
|
|
2989
|
+
the next sync or key move highlights it, and Enter picks the first visible
|
|
2990
|
+
option meanwhile.
|
|
2991
|
+
|
|
2992
|
+
It is opt-in because a search box whose Enter submits a form would otherwise
|
|
2993
|
+
start activating options. With `reactive_tags_add` on the same input, Enter
|
|
2994
|
+
always adds the highlighted suggestion; typed text that matches a suggestion
|
|
2995
|
+
can no longer be added as free text, so leave `highlight:` off a tag input
|
|
2996
|
+
that takes new tags. Without `highlight:` the markup is unchanged.
|
|
2997
|
+
`highlight: :first` with `focus: true` raises (roving focus has no highlight),
|
|
2998
|
+
and so does any other value.
|
|
2999
|
+
|
|
2948
3000
|
### Client-side option filtering (`reactive_filter`)
|
|
2949
3001
|
|
|
2950
3002
|
`listnav:` is the keyboard half of a combobox; `reactive_filter` is the other
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{Controller as dr}from"@hotwired/stimulus";import{confirmResolver as Ze}from"phlex/reactive/confirm";function fr(){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 hr(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),r=this.getAttribute("target");if(!t||!r)return;let n=document.getElementById(r);if(n)n.setAttribute("data-reactive-token-value",t)}}var mr=["focus","focus_first","blur"];function pr(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Ve(this.getAttribute("data-reactive-ops"));if(!t.length)return;let r=this.getAttribute("target"),n=this.getAttribute("data-reactive-verbose")==="true",i=r?document.getElementById(r):null;if(r&&!i){if(n)w("devtools",(s)=>s.missingRoot(r));return}let o=(s)=>De(s,(c)=>En(c,i),n?(c,u)=>w("devtools",(d)=>d.diagnoseStream(c,u,i)):void 0),a=t.findIndex((s)=>mr.includes(s?.[0]));if(a<0||typeof requestAnimationFrame!=="function")return o(t);o(t.slice(0,a)),requestAnimationFrame(()=>o(t.slice(a)))}}function gr(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){w("defer",(t)=>t.streamAction(this))}}var et=!1,Re=null;function br(){if(et)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;et=!0,document.addEventListener("turbo:before-stream-render",(e)=>{if(xr(e),yr(e),wr(e),Re)Re(e,g.get("effects"));else g.get("effects")?.wrap(e)})}var Z="reactive:streamed";function yr(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target,i=n?.getAttribute?.("action"),o=/^(append|prepend|update)$/.test(i);if(typeof r!=="function"||!(o||/^(before|after|replace)$/.test(i)))return;let a=n.getAttribute("target"),s=n.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let d=(o?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(d)c.add(d)}if(c.size===0)return;t.render=async(u)=>{await r(u);for(let d of c)if(d.isConnected)d.dispatchEvent(new Event(Z))}}function qe(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function Be(e){try{return e.matches(":modal")}catch{return!1}}function Ft(e){if(!qe(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||Be(e))return;if(e.open)e.close();e.showModal()}function vr(e){if(qe(e)&&e.open)e.close()}function oe(e){let r=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))r.push(e);for(let n of r)if(n.open&&!Be(n))Ft(n)}function wr(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target;if(typeof r!=="function"||!n?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(i)=>{await r(i),oe(document)}}var tt=!1;function Ar(){if(tt)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;tt=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))oe(t.target)}),document.addEventListener("turbo:morph",()=>oe(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let r=t.target,n=t.detail?.newElement;if(!qe(r)||!n)return;if(n.hasAttribute?.("open"))e.delete(r);else e.add(r)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:r,detail:n}=t;if(n?.attributeName!=="open"||n.mutationType!=="remove")return;if(!e.has(r)||!r.open||!Be(r))return;e.delete(r),t.preventDefault(),r.close()})}var Ne=new WeakMap;function Rt(e,t,r,n){let i=Ne.get(e)??new Map;Ne.set(e,i);let o=(a,s)=>{i.delete(a),i.set(a,s)};if(t.endsWith("_class"))for(let a of r.classes??[])o(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))Yt(r.name)||o(r.name,e.getAttribute(r.name));else if(t==="show"||t==="hide"||t==="toggle"){if(o("hidden",e.getAttribute("hidden")),r.expanded!=null)for(let a of n({...r,to:r.expanded}))Rt(a,"set_attr",{name:"aria-expanded"})}}var rt=!1;function _r(){if(rt)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;rt=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[r,n]of Ne.get(t)??[])if(r[0]===".")t.classList.toggle(r.slice(1),n);else if(n==null)t.removeAttribute(r);else if(t.getAttribute(r)!==n)t.setAttribute(r,n)})}var We="data-reactive-image-fallback",P="data-reactive-image-state",Le="data-reactive-image-hidden",ge=null,xe="data-reactive-wrap-hidden";function Nt(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(xe,"")}function Lt(e){if(!e.hasAttribute(xe))return;e.removeAttribute("hidden"),e.removeAttribute(xe)}function K(e){if(e?.localName!=="img")return null;let t=e.getAttribute(We);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var xt=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function je(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function Ot(e,t){let r=je(e,t.alt);return r&&!r.contains(e)?r:null}function se(e,t,r){if(r==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Le,"");if(t.wrap){let i=je(e,t.wrap);if(i)Nt(i);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let n=Ot(e,t);if(n)n.textContent=e.getAttribute("alt")??"",n.hidden=!1}else he(e,t);e.setAttribute(P,r)}function he(e,t=K(e)){if(!t||e.getAttribute(P)==null)return;if(e.getAttribute(P)==="error"){if(e.hasAttribute(Le))e.removeAttribute("hidden");let r=je(e,t.wrap);if(r)Lt(r);let n=Ot(e,t);if(n)n.hidden=!0}e.removeAttribute(P),e.removeAttribute(Le)}function nt(e){let t=e.target,r=K(t);if(!r)return;if(e.type==="load")se(t,r,"loaded");else if(xt(t))se(t,r,"error");else he(t,r)}function Sr(){if(ge)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;ge={error:nt,load:nt,"turbo:before-morph-element":(t)=>{let r=t.target,n=t.detail?.newElement,i=r?.getAttribute?.(P);if(i==null||!n||!K(r))return;let o=(a)=>r.getAttribute(a)===n.getAttribute?.(a);if(o("src")&&o("srcset"))e.set(r,i)},"turbo:morph-element":(t)=>{let r=t.target,n=e.get(r);if(n===void 0)return;e.delete(r),queueMicrotask(()=>{let i=K(r);if(i)se(r,i,n)})},"turbo:frame-render":(t)=>Y(t.target),"turbo:render":()=>Y(document),"turbo:before-stream-render":(t)=>{let r=t.detail,n=r?.render,i=r?.newStream??t.target;if(typeof n!=="function"||!i?.querySelector?.("template")?.content?.querySelector?.(`img[${We}]`))return;r.render=async(o)=>{await n(o),Y(document)}}};for(let[t,r]of Object.entries(ge))document.addEventListener(t,r,!0);Y(document)}function Y(e){for(let t of e?.querySelectorAll?.(`img[${We}]`)??[]){if(t.getAttribute(P)!=null||!t.complete||!xt(t))continue;let r=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,n=(i)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===r&&se(t,K(t)??{},i);if(t.naturalWidth>0)n("loaded");else if(typeof t.decode==="function")t.decode().then(()=>n("loaded"),()=>n("error"));else n("error")}}function It(e){Re=e}var X,be=null,it="[data-reactive-editable][contenteditable=plaintext-only]";function Pt(){if(X===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",X=e.contentEditable==="plaintext-only"}catch{X=!1}return X}function ee(e){if(e.matches?.(it))e.setAttribute("contenteditable","true");e.querySelectorAll?.(it).forEach(ee)}function Er(){if(be||typeof document>"u"||typeof document.createElement!=="function")return;if(Pt())return;ee(document),be=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")ee(t.target);else t.addedNodes.forEach(ee)}),be.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var ot=!1;function st(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 Tr(){if(ot)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ot=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented)return;let n=st(t);if(n)Fr(t,r);if(t.hasAttribute?.("data-reactive-editable")){if(ce.set(t,R(r)),!n)return;for(let{name:o}of[...t.attributes])if(!r.hasAttribute(o)&&o!=="contenteditable"&&o!==A)t.removeAttribute(o);for(let{name:o,value:a}of r.attributes)if(o!=="contenteditable"&&t.getAttribute(o)!==a)t.setAttribute(o,a);return e.preventDefault()}if(t.localName!=="input"||!n)return;let i=r.getAttribute("value");if(i==null)t.removeAttribute("value");else if(t.getAttribute("value")!==i)t.setAttribute("value",i)}),document.addEventListener("focusin",(e)=>He(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===A)&&st(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(A)&&Je(t)===ze(t))t.removeAttribute(A)})}var A="data-reactive-held",Ue='[data-controller~="reactive"]',te=null,I=new Map;function Je(e){return e.hasAttribute("data-reactive-editable")?R(e):e.value}function ze(e){return e.hasAttribute("data-reactive-editable")?Ge(e):e.defaultValue}function kr(e){if(e.hasAttribute("data-reactive-editable"))return R(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Fr(e,t){let r=e.getAttribute("name");if(!r||/^(checkbox|radio)$/.test(e.type)||I.has(e.closest(Ue)))return;let n=kr(t);if(n===Je(e))return e.removeAttribute(A);if(n===ze(e))return;e.setAttribute(A,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:r,theirs:n}}))}function Rr(e){let t=[];for(let r of e.querySelectorAll(`[${A}]`)){if(r.closest(Ue)!==e)continue;let n=r.getAttribute("name");if(Je(r)===ze(r))r.removeAttribute(A);else if(n&&!t.includes(n))t.push(n)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(r)=>`\\u${r.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Mt(e,t){if(t===!0)return;for(let r of e.querySelectorAll(`[${A}]`))if(r.closest(Ue)===e&&!t?.includes(r.getAttribute("name")))r.removeAttribute(A)}function Nr(e){let t=e.headers.get("X-Reactive-Refused");if(t==="*")return!0;try{let r=JSON.parse(t);return Array.isArray(r)?r:null}catch{return null}}function at(e,t,r=null,n=30000){let i={root:e,streams:0,keep:r,events:[]},o=te;te=i;try{window.Turbo.renderStreamMessage(t)}finally{te=o}if(i.streams===0)Mt(e,r);let a=i.events.filter((d)=>!d.event.defaultPrevented).map((d)=>d.done),s=a.length>0?Promise.all(a).then((d)=>d.find(Boolean)):Lr(),c,u=new Promise((d)=>c=setTimeout(d,n));return Promise.race([s,u]).finally(()=>clearTimeout(c))}function Lr(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function xr(e){let t=te,r=e.detail,n=r?.render;if(!t||typeof n!=="function")return;t.streams++;let i;t.events.push({event:e,done:new Promise((o)=>i=o)}),r.render=async(o)=>{I.set(t.root,(I.get(t.root)||0)+1);let a;try{return await n(o)}catch(s){throw a=s,s}finally{let s=I.get(t.root)-1;if(s)I.set(t.root,s);else I.delete(t.root);Mt(t.root,t.keep),i(a)}}}var ct="__materialize",ut=!1;function Or(){if(ut)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;ut=!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)}var Ir="phlex-reactive:latency";function Ct(){return typeof sessionStorage<"u"&&Boolean(sessionStorage.getItem(Ir))}function Ke(){if(typeof document>"u")return;if(!g.has("devtools")&&!_.get("devtools")[1])return;let e=document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development";if(e||Ct())w("devtools",(t)=>e&&t.attach())}var Dt="data-reactive-active",Oe="data-reactive-errors",v=0,F=[];function $t(){if(v++,v===1)F=[],Bt("reactive:busy")}function W({action:e=null,kind:t,status:r=null,root:n=null}){if(v===0)return;F.push({action:e??null,kind:t,status:r??null,root:n||null})}function qt(){if(v===0)return;if(v--,v===0){let e=F;Bt("reactive:idle"),qr(e)}}function ti(){return v}function ri(){v=0,F=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(Dt),e?.removeAttribute?.(Oe)}function Bt(e){if(typeof document>"u")return;let t=document.documentElement,r=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(Dt,v>0),r&&F.length>0)t.setAttribute(Oe,JSON.stringify(F));else t.removeAttribute(Oe);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let n=r?{count:v,errors:F.slice()}:{count:v};document.dispatchEvent(new CustomEvent(e,{detail:n}))}}var Pr="data-reactive-debouncing",S=new Set,E=[];function Mr(e){if(S.add(e),S.size===1)Wt()}function Cr(e){if(!S.delete(e)||S.size>0)return;Wt(),queueMicrotask(jt)}function Wt(){(typeof document<"u"?document.documentElement:null)?.toggleAttribute?.(Pr,S.size>0)}function ni(){return S.size}function Dr(){for(let e of[...S])if(S.has(e))e()}var me=()=>v===0&&S.size===0;function $r({timeout:e}={}){if(me())return Promise.resolve({count:0,errors:[]});return new Promise((t)=>{let r={resolve:t,errors:[],timer:null};if(Number(e)>0)r.timer=setTimeout(()=>{E=E.filter((n)=>n!==r),t({count:v,errors:r.errors,timedOut:!0})},Number(e));E.push(r)})}function qr(e){if(E.length===0)return;for(let t of E)t.errors.push(...e);jt()}function jt(){if(!me()||E.length===0)return;let e=E;E=[];for(let t of e)clearTimeout(t.timer),t.resolve({count:0,errors:t.errors})}function Ut(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:30000}var lt="data-reactive-await-settled",j="data-reactive-awaiting",ye=new WeakSet,ve=null,ae=0,dt=0,k=(e)=>e?.hasAttribute?.(lt)===!0&&e.getAttribute(lt)!=="false";function Br(e,t){let r=e.getAttribute("id"),n=r?null:e.parentElement?.closest?.("[id]");return()=>{let o=(r?[document.getElementById(r)]:Array.from((n&&document.getElementById(n.getAttribute("id"))?.querySelectorAll(e.tagName))??[])).filter((a)=>a?.tagName===e.tagName&&t(a));return o.length===1?o[0]:null}}var Ie=(e)=>[e.tagName,e.type,e.name,e.value,e.getAttribute("formaction"),e.getAttribute("formmethod")].join("\x00");function ft(e,t,r){if(t.isConnected&&t.form===e&&Ie(t)===r)return t;let n=Array.from(e.elements).filter((i)=>Ie(i)===r);return n.length===1?n[0]:null}function Jt(e,t){let r=ae;return Dr(),$r({timeout:e*2}).then(({errors:n,timedOut:i})=>t(!i&&n.length===0&&r===ae))}function zt(e,t,r,n){if(ye.has(t)||me())return;if(e.preventDefault(),e.stopImmediatePropagation(),t.hasAttribute(j))return;let i=++dt,o=Br(t,r);Jt(Ut(),(a)=>{t.removeAttribute(j);let s=t.isConnected&&r(t)?t:o();if(!a||i!==dt||!s)return;ye.add(s);try{n(s)}finally{ye.delete(s)}}),t.setAttribute(j,"")}function Wr(e){if(e.defaultPrevented)return;let t=e.target;if(t?.tagName!=="FORM")return;let r=e.submitter??null,n=k(t);if(!n&&!k(r))return;let i=(c)=>[c.getAttribute("action"),c.getAttribute("method")].join("\x00"),o=i(t),a=r&&Ie(r);zt(e,t,(c)=>i(c)===o&&(n?k(c):k(ft(c,r,a))),(c)=>{if(!r)return c.requestSubmit();let u=ft(c,r,a);if(u)c.requestSubmit(u)})}function jr(e){if(e.defaultPrevented||e.button!==0)return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.("a[href]");if(!t||!k(t)||t.hasAttribute("download"))return;let r=t.getAttribute("target");if(r&&r!=="_self")return;let n=t.getAttribute("href");zt(e,t,(o)=>o.getAttribute("href")===n&&k(o),(o)=>o.click())}function Ur(){if(ve)return;if(typeof window>"u"||typeof window.addEventListener!=="function")return;let e=()=>ae++;ve={submit:Wr,click:jr,"turbo:before-prefetch":(t)=>k(t.target)&&t.preventDefault(),"turbo:visit":e,"turbo:before-render":e};for(let[t,r]of Object.entries(ve))window.addEventListener(t,r,!0)}var Kt="data-reactive-requests";function Ht(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Jr(t))return;let r=zr(t);r[e]=(Number(r[e])||0)+1,t.setAttribute(Kt,JSON.stringify(r))}function Jr(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function zr(e){try{let t=JSON.parse(e.getAttribute(Kt));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function ht(){fr(),hr(),pr(),gr(),br(),Tr(),Ar(),_r(),on(),Sr(),Ur(),Er(),Or(),Ke()}function Kr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Gt=Symbol.for("phlex-reactive.core");if(globalThis[Gt])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[Gt]=!0;var Vt=!1;function Hr(){if(Vt)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(Hr,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Gr=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Yt(e){let t=String(e).toLowerCase();return t.startsWith("on")||Gr.has(t)}var we=new WeakMap;function Vr(e,t,r){let[n,i,o]=t;we.get(e)?.(),e.classList.add(n,i),r();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(i),e.classList.add(o)}),c=(d)=>{if(a||d&&d.target!==e)return;a=!0,we.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(n,i,o)};we.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Yr(e))}function Yr(e){let t=0;try{let r=getComputedStyle(e);for(let n of["transition","animation"]){let[i,o]=["Duration","Delay"].map((s)=>String(r[n+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(r[n+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<i.length||s<o.length||s<a.length;s++){let c=i[s%i.length]*a[s%a.length]||0;t=Math.max(t,c+o[s%o.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var Xr=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",Qr=new Set(["lexxy-editor","trix-editor"]);function R(e){let t="",r=!1,n=(o)=>{if(r&&t&&!t.endsWith(`
|
|
1
|
+
import{Controller as hr}from"@hotwired/stimulus";import{confirmResolver as tt}from"phlex/reactive/confirm";function mr(){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 pr(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),r=this.getAttribute("target");if(!t||!r)return;let n=document.getElementById(r);if(n)n.setAttribute("data-reactive-token-value",t)}}var gr=["focus","focus_first","blur"];function br(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Xe(this.getAttribute("data-reactive-ops"));if(!t.length)return;let r=this.getAttribute("target"),n=this.getAttribute("data-reactive-verbose")==="true",i=r?document.getElementById(r):null;if(r&&!i){if(n)w("devtools",(s)=>s.missingRoot(r));return}let o=(s)=>qe(s,(c)=>Fn(c,i),n?(c,u)=>w("devtools",(d)=>d.diagnoseStream(c,u,i)):void 0),a=t.findIndex((s)=>gr.includes(s?.[0]));if(a<0||typeof requestAnimationFrame!=="function")return o(t);o(t.slice(0,a)),requestAnimationFrame(()=>o(t.slice(a)))}}function yr(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){w("defer",(t)=>t.streamAction(this))}}var rt=!1,Le=null;function vr(){if(rt)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;rt=!0,document.addEventListener("turbo:before-stream-render",(e)=>{if(Pr(e),Ar(e),Sr(e),Le)Le(e,g.get("effects"));else g.get("effects")?.wrap(e)})}var ee="reactive:streamed",be=new WeakMap,wr=0;function Y(e){return!!e?.isComposing||e?.keyCode===229}function Ar(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target,i=n?.getAttribute?.("action"),o=/^(append|prepend|update)$/.test(i);if(typeof r!=="function"||!(o||/^(before|after|replace)$/.test(i)))return;let a=n.getAttribute("target"),s=n.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:s?document.querySelectorAll(s):[]){let d=(o?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(d)c.add(d)}if(c.size===0)return;t.render=async(u)=>{await r(u);for(let d of c)if(d.isConnected)d.dispatchEvent(new Event(ee))}}function Be(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function je(e){try{return e.matches(":modal")}catch{return!1}}function Nt(e){if(!Be(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||je(e))return;if(e.open)e.close();e.showModal()}function _r(e){if(Be(e)&&e.open)e.close()}function se(e){let r=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))r.push(e);for(let n of r)if(n.open&&!je(n))Nt(n)}function Sr(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target;if(typeof r!=="function"||!n?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(i)=>{await r(i),se(document)}}var nt=!1;function Er(){if(nt)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;nt=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))se(t.target)}),document.addEventListener("turbo:morph",()=>se(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let r=t.target,n=t.detail?.newElement;if(!Be(r)||!n)return;if(n.hasAttribute?.("open"))e.delete(r);else e.add(r)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:r,detail:n}=t;if(n?.attributeName!=="open"||n.mutationType!=="remove")return;if(!e.has(r)||!r.open||!je(r))return;e.delete(r),t.preventDefault(),r.close()})}var xe=new WeakMap;function Lt(e,t,r,n){let i=xe.get(e)??new Map;xe.set(e,i);let o=(a,s)=>{i.delete(a),i.set(a,s)};if(t.endsWith("_class"))for(let a of r.classes??[])o(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))Qt(r.name)||o(r.name,e.getAttribute(r.name));else if(t==="show"||t==="hide"||t==="toggle"){if(o("hidden",e.getAttribute("hidden")),r.expanded!=null)for(let a of n({...r,to:r.expanded}))Lt(a,"set_attr",{name:"aria-expanded"})}}var it=!1;function Tr(){if(it)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;it=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[r,n]of xe.get(t)??[])if(r[0]===".")t.classList.toggle(r.slice(1),n);else if(n==null)t.removeAttribute(r);else if(t.getAttribute(r)!==n)t.setAttribute(r,n)})}var Ue="data-reactive-image-fallback",P="data-reactive-image-state",Oe="data-reactive-image-hidden",ye=null,Ie="data-reactive-wrap-hidden";function xt(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(Ie,"")}function Ot(e){if(!e.hasAttribute(Ie))return;e.removeAttribute("hidden"),e.removeAttribute(Ie)}function z(e){if(e?.localName!=="img")return null;let t=e.getAttribute(Ue);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var It=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Ke(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function Pt(e,t){let r=Ke(e,t.alt);return r&&!r.contains(e)?r:null}function ae(e,t,r){if(r==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(Oe,"");if(t.wrap){let i=Ke(e,t.wrap);if(i)xt(i);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let n=Pt(e,t);if(n)n.textContent=e.getAttribute("alt")??"",n.hidden=!1}else me(e,t);e.setAttribute(P,r)}function me(e,t=z(e)){if(!t||e.getAttribute(P)==null)return;if(e.getAttribute(P)==="error"){if(e.hasAttribute(Oe))e.removeAttribute("hidden");let r=Ke(e,t.wrap);if(r)Ot(r);let n=Pt(e,t);if(n)n.hidden=!0}e.removeAttribute(P),e.removeAttribute(Oe)}function ot(e){let t=e.target,r=z(t);if(!r)return;if(e.type==="load")ae(t,r,"loaded");else if(It(t))ae(t,r,"error");else me(t,r)}function kr(){if(ye)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;ye={error:ot,load:ot,"turbo:before-morph-element":(t)=>{let r=t.target,n=t.detail?.newElement,i=r?.getAttribute?.(P);if(i==null||!n||!z(r))return;let o=(a)=>r.getAttribute(a)===n.getAttribute?.(a);if(o("src")&&o("srcset"))e.set(r,i)},"turbo:morph-element":(t)=>{let r=t.target,n=e.get(r);if(n===void 0)return;e.delete(r),queueMicrotask(()=>{let i=z(r);if(i)ae(r,i,n)})},"turbo:frame-render":(t)=>X(t.target),"turbo:render":()=>X(document),"turbo:before-stream-render":(t)=>{let r=t.detail,n=r?.render,i=r?.newStream??t.target;if(typeof n!=="function"||!i?.querySelector?.("template")?.content?.querySelector?.(`img[${Ue}]`))return;r.render=async(o)=>{await n(o),X(document)}}};for(let[t,r]of Object.entries(ye))document.addEventListener(t,r,!0);X(document)}function X(e){for(let t of e?.querySelectorAll?.(`img[${Ue}]`)??[]){if(t.getAttribute(P)!=null||!t.complete||!It(t))continue;let r=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,n=(i)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===r&&ae(t,z(t)??{},i);if(t.naturalWidth>0)n("loaded");else if(typeof t.decode==="function")t.decode().then(()=>n("loaded"),()=>n("error"));else n("error")}}function Mt(e){Le=e}var Q,ve=null,st="[data-reactive-editable][contenteditable=plaintext-only]";function Ct(){if(Q===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",Q=e.contentEditable==="plaintext-only"}catch{Q=!1}return Q}function te(e){if(e.matches?.(st))e.setAttribute("contenteditable","true");e.querySelectorAll?.(st).forEach(te)}function Fr(){if(ve||typeof document>"u"||typeof document.createElement!=="function")return;if(Ct())return;te(document),ve=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")te(t.target);else t.addedNodes.forEach(te)}),ve.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var at=!1;function ct(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 Rr(){if(at)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;at=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented)return;let n=ct(t);if(n)Lr(t,r);if(t.hasAttribute?.("data-reactive-editable")){if(ue.set(t,R(r)),!n)return;for(let{name:o}of[...t.attributes])if(!r.hasAttribute(o)&&o!=="contenteditable"&&o!==A)t.removeAttribute(o);for(let{name:o,value:a}of r.attributes)if(o!=="contenteditable"&&t.getAttribute(o)!==a)t.setAttribute(o,a);return e.preventDefault()}if(t.localName!=="input"||!n)return;let i=r.getAttribute("value");if(i==null)t.removeAttribute("value");else if(t.getAttribute("value")!==i)t.setAttribute("value",i)}),document.addEventListener("focusin",(e)=>Ve(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===A)&&ct(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(A)&&ze(t)===He(t))t.removeAttribute(A)})}var A="data-reactive-held",Je='[data-controller~="reactive"]',re=null,I=new Map;function ze(e){return e.hasAttribute("data-reactive-editable")?R(e):e.value}function He(e){return e.hasAttribute("data-reactive-editable")?Ye(e):e.defaultValue}function Nr(e){if(e.hasAttribute("data-reactive-editable"))return R(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Lr(e,t){let r=e.getAttribute("name");if(!r||/^(checkbox|radio)$/.test(e.type)||I.has(e.closest(Je)))return;let n=Nr(t);if(n===ze(e))return e.removeAttribute(A);if(n===He(e))return;e.setAttribute(A,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:r,theirs:n}}))}function xr(e){let t=[];for(let r of e.querySelectorAll(`[${A}]`)){if(r.closest(Je)!==e)continue;let n=r.getAttribute("name");if(ze(r)===He(r))r.removeAttribute(A);else if(n&&!t.includes(n))t.push(n)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-]/g,(r)=>`\\u${r.charCodeAt(0).toString(16).padStart(4,"0")}`)}function Dt(e,t){if(t===!0)return;for(let r of e.querySelectorAll(`[${A}]`))if(r.closest(Je)===e&&!t?.includes(r.getAttribute("name")))r.removeAttribute(A)}function Or(e){let t=e.headers.get("X-Reactive-Refused");if(t==="*")return!0;try{let r=JSON.parse(t);return Array.isArray(r)?r:null}catch{return null}}function ut(e,t,r=null,n=30000){let i={root:e,streams:0,keep:r,events:[]},o=re;re=i;try{window.Turbo.renderStreamMessage(t)}finally{re=o}if(i.streams===0)Dt(e,r);let a=i.events.filter((d)=>!d.event.defaultPrevented).map((d)=>d.done),s=a.length>0?Promise.all(a).then((d)=>d.find(Boolean)):Ir(),c,u=new Promise((d)=>c=setTimeout(d,n));return Promise.race([s,u]).finally(()=>clearTimeout(c))}function Ir(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function Pr(e){let t=re,r=e.detail,n=r?.render;if(!t||typeof n!=="function")return;t.streams++;let i;t.events.push({event:e,done:new Promise((o)=>i=o)}),r.render=async(o)=>{I.set(t.root,(I.get(t.root)||0)+1);let a;try{return await n(o)}catch(s){throw a=s,s}finally{let s=I.get(t.root)-1;if(s)I.set(t.root,s);else I.delete(t.root);Dt(t.root,t.keep),i(a)}}}var lt="__materialize",dt=!1;function Mr(){if(dt)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;dt=!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)}var Cr="phlex-reactive:latency";function $t(){return typeof sessionStorage<"u"&&Boolean(sessionStorage.getItem(Cr))}function Ge(){if(typeof document>"u")return;if(!g.has("devtools")&&!_.get("devtools")[1])return;let e=document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development";if(e||$t())w("devtools",(t)=>e&&t.attach())}var qt="data-reactive-active",Pe="data-reactive-errors",v=0,F=[];function Wt(){if(v++,v===1)F=[],jt("reactive:busy")}function B({action:e=null,kind:t,status:r=null,root:n=null}){if(v===0)return;F.push({action:e??null,kind:t,status:r??null,root:n||null})}function Bt(){if(v===0)return;if(v--,v===0){let e=F;jt("reactive:idle"),jr(e)}}function ii(){return v}function oi(){v=0,F=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(qt),e?.removeAttribute?.(Pe)}function jt(e){if(typeof document>"u")return;let t=document.documentElement,r=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(qt,v>0),r&&F.length>0)t.setAttribute(Pe,JSON.stringify(F));else t.removeAttribute(Pe);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let n=r?{count:v,errors:F.slice()}:{count:v};document.dispatchEvent(new CustomEvent(e,{detail:n}))}}var Dr="data-reactive-debouncing",S=new Set,E=[];function $r(e){if(S.add(e),S.size===1)Ut()}function qr(e){if(!S.delete(e)||S.size>0)return;Ut(),queueMicrotask(Kt)}function Ut(){(typeof document<"u"?document.documentElement:null)?.toggleAttribute?.(Dr,S.size>0)}function si(){return S.size}function Wr(){for(let e of[...S])if(S.has(e))e()}var pe=()=>v===0&&S.size===0;function Br({timeout:e}={}){if(pe())return Promise.resolve({count:0,errors:[]});return new Promise((t)=>{let r={resolve:t,errors:[],timer:null};if(Number(e)>0)r.timer=setTimeout(()=>{E=E.filter((n)=>n!==r),t({count:v,errors:r.errors,timedOut:!0})},Number(e));E.push(r)})}function jr(e){if(E.length===0)return;for(let t of E)t.errors.push(...e);Kt()}function Kt(){if(!pe()||E.length===0)return;let e=E;E=[];for(let t of e)clearTimeout(t.timer),t.resolve({count:0,errors:t.errors})}function Jt(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:30000}var ft="data-reactive-await-settled",j="data-reactive-awaiting",we=new WeakSet,Ae=null,ce=0,ht=0,k=(e)=>e?.hasAttribute?.(ft)===!0&&e.getAttribute(ft)!=="false";function Ur(e,t){let r=e.getAttribute("id"),n=r?null:e.parentElement?.closest?.("[id]");return()=>{let o=(r?[document.getElementById(r)]:Array.from((n&&document.getElementById(n.getAttribute("id"))?.querySelectorAll(e.tagName))??[])).filter((a)=>a?.tagName===e.tagName&&t(a));return o.length===1?o[0]:null}}var Me=(e)=>[e.tagName,e.type,e.name,e.value,e.getAttribute("formaction"),e.getAttribute("formmethod")].join("\x00");function mt(e,t,r){if(t.isConnected&&t.form===e&&Me(t)===r)return t;let n=Array.from(e.elements).filter((i)=>Me(i)===r);return n.length===1?n[0]:null}function zt(e,t){let r=ce;return Wr(),Br({timeout:e*2}).then(({errors:n,timedOut:i})=>t(!i&&n.length===0&&r===ce))}function Ht(e,t,r,n){if(we.has(t)||pe())return;if(e.preventDefault(),e.stopImmediatePropagation(),t.hasAttribute(j))return;let i=++ht,o=Ur(t,r);zt(Jt(),(a)=>{t.removeAttribute(j);let s=t.isConnected&&r(t)?t:o();if(!a||i!==ht||!s)return;we.add(s);try{n(s)}finally{we.delete(s)}}),t.setAttribute(j,"")}function Kr(e){if(e.defaultPrevented)return;let t=e.target;if(t?.tagName!=="FORM")return;let r=e.submitter??null,n=k(t);if(!n&&!k(r))return;let i=(c)=>[c.getAttribute("action"),c.getAttribute("method")].join("\x00"),o=i(t),a=r&&Me(r);Ht(e,t,(c)=>i(c)===o&&(n?k(c):k(mt(c,r,a))),(c)=>{if(!r)return c.requestSubmit();let u=mt(c,r,a);if(u)c.requestSubmit(u)})}function Jr(e){if(e.defaultPrevented||e.button!==0)return;if(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.("a[href]");if(!t||!k(t)||t.hasAttribute("download"))return;let r=t.getAttribute("target");if(r&&r!=="_self")return;let n=t.getAttribute("href");Ht(e,t,(o)=>o.getAttribute("href")===n&&k(o),(o)=>o.click())}function zr(){if(Ae)return;if(typeof window>"u"||typeof window.addEventListener!=="function")return;let e=()=>ce++;Ae={submit:Kr,click:Jr,"turbo:before-prefetch":(t)=>k(t.target)&&t.preventDefault(),"turbo:visit":e,"turbo:before-render":e};for(let[t,r]of Object.entries(Ae))window.addEventListener(t,r,!0)}var Gt="data-reactive-requests";function Vt(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!Hr(t))return;let r=Gr(t);r[e]=(Number(r[e])||0)+1,t.setAttribute(Gt,JSON.stringify(r))}function Hr(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function Gr(e){try{let t=JSON.parse(e.getAttribute(Gt));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function pt(){mr(),pr(),br(),yr(),vr(),Rr(),Er(),Tr(),cn(),kr(),zr(),Fr(),Mr(),Ge()}function Vr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Yt=Symbol.for("phlex-reactive.core");if(globalThis[Yt])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[Yt]=!0;var Xt=!1;function Yr(){if(Xt)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(Yr,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var Xr=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Qt(e){let t=String(e).toLowerCase();return t.startsWith("on")||Xr.has(t)}var _e=new WeakMap;function Qr(e,t,r){let[n,i,o]=t;_e.get(e)?.(),e.classList.add(n,i),r();let a=!1,s=requestAnimationFrame(()=>{if(a)return;e.classList.remove(i),e.classList.add(o)}),c=(d)=>{if(a||d&&d.target!==e)return;a=!0,_e.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(s),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(n,i,o)};_e.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,Zr(e))}function Zr(e){let t=0;try{let r=getComputedStyle(e);for(let n of["transition","animation"]){let[i,o]=["Duration","Delay"].map((s)=>String(r[n+s]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(r[n+"IterationCount"]).split(",").map((s)=>/inf/.test(s)?1/0:parseFloat(s)>=0?parseFloat(s):1);for(let s=0;s<i.length||s<o.length||s<a.length;s++){let c=i[s%i.length]*a[s%a.length]||0;t=Math.max(t,c+o[s%o.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var en=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",tn=new Set(["lexxy-editor","trix-editor"]);function R(e){let t="",r=!1,n=(o)=>{if(r&&t&&!t.endsWith(`
|
|
2
2
|
`))t+=`
|
|
3
3
|
`;r=!1,t+=o},i=(o)=>{for(let a of o.childNodes){let s=/^(div|p|li)$/.test(a.localName);if(s)r=!0;if(a.nodeType===3)a.data&&n(a.data);else if(a.localName==="br")n(`
|
|
4
4
|
`);else if(a.nodeType===1)i(a);if(s)r=!0}};return i(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 un(e,t,r){if(r?.transition)Vr(e,r.transition,()=>e.hidden=t);else e.hidden=t}function Ae(e,t,r,n){if(un(e,t,r),r?.expanded==null||typeof n!=="function")return;for(let i of n({...r,to:r.expanded}))i.setAttribute?.("aria-expanded",String(!t))}function _e(e){if(!Yt(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function er(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let r=t?.localName==="img"?t:null,n=r?.getAttribute("src"),i=!1;for(let a of["srcset","src"]){let s=n?r.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))i=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)i=e.setAttribute(a,s)??!0}if(i)he(e);let o=r?.getAttribute("alt")??"";if(e.getAttribute("alt")!==o)e.setAttribute("alt",o);return r?o:!1}var ln='a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([type=hidden]):not([disabled])';function dn(e){return e.querySelectorAll?.(ln)?.[0]??null}function Ve(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 bt=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"}),yt=Object.freeze(["meta","ctrl","alt","shift"]);function M(e,t,r){let n=e.split("+");for(let a of yt)if(n.includes(a)!==Boolean(t[`${a}Key`]))return!1;let i=n.find((a)=>!yt.includes(a));if(i===void 0||typeof t.key!=="string")return!0;let o=r&&Object.hasOwn(r,i)?r[i]:Object.hasOwn(bt,i)?bt[i]:/^[a-z0-9]$/.test(i)?i:null;return typeof o==="string"&&o.toLowerCase()===t.key.toLowerCase()}var fn=(e)=>e&&typeof e==="object"?e.keys:String(e),Ye=()=>ne().prevented??=new WeakSet;function Se(e,t){if(t!=null&&!e.defaultPrevented)Ye().add(e);e.preventDefault()}var tr=(e)=>e?.isContentEditable||/^(input|textarea|select)$/.test(e?.localName);function rr(e,t,r,n){if(r.defaultPrevented&&e?.handled!==!0&&!Ye().has(r))return!1;if(e?.inEditable!==!0&&tr(r.target))return!1;let i=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return M(t.replace(/^mod\+/,`${i}+`),r,n)}var hn=1000,le={strokes:[],done:!1,seen:new WeakSet,listening:!1},Ee=()=>le.done=!0;function nr(e){let t=le;if(t.seen.has(e))return;if(t.seen.add(e),!t.listening)t.listening=!0,globalThis.window?.addEventListener?.("keydown",nr,!0),globalThis.window?.addEventListener?.("blur",Ee),globalThis.document?.addEventListener?.("turbo:before-render",Ee,!0),globalThis.document?.addEventListener?.("focusin",(r)=>tr(r.target)&&Ee(),!0);if(t.done)t.strokes=[],t.done=!1;if(!e.repeat&&!/^(Shift|Control|Alt|AltGraph|Meta|CapsLock|Fn|OS)$/.test(e.key))t.strokes=[...t.strokes.slice(-2),e]}function mn(e,t,r,n){if(r[C])return!1;nr(r);let i=le.strokes.slice(-t.length);if(i.at(-1)!==r||i.length<t.length)return!1;let o=e?.within??hn,a=i.every((s,c)=>rr(e,t[c],s,n)&&(c===0||s.timeStamp-i[c-1].timeStamp<=o));if(a)le.done=!0;return a}function Me(e,t,r){let n=fn(e).split(" ");return n.length>1?mn(e,n,t,r):rr(e,n[0],t,r)}var Ce=/^key(down|up|press)\.([a-z]+\+)*(delete|backspace)$/;function pn(e,t){let{shortcut:r,key:n}=e.params??{};return r!=null&&!Me(r,e,t)||n!=null&&!M(String(n),e,t)}function gn(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:Ve(t),legacy:!0}];let r=[];for(let n of t.split(" ")){if(n==="")continue;let i=null;try{i=JSON.parse(n)}catch{i=null}if(i&&typeof i==="object"&&!Array.isArray(i))r.push(i);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(n)} — skipped`)}return r}function Te(e,t,r){if(e.legacy)return!0;let n=e.on;if(typeof n!=="string"||n==="")return!1;let i=/^key(down|up|press)\./.test(n)?n.indexOf("."):-1;if(t.type!==(i<0?n:n.slice(0,i)))return!1;if(Boolean(e.window)!==Qe(t.currentTarget))return!1;return i<0||r===null&&!Ce.test(n)||M(n.slice(i+1),t,r)}function bn(e,t){let r=e.detail;if(r===void 0)return!0;if(r===null||typeof r!=="object"||Array.isArray(r))return!1;let n=t.detail;if(n===null||typeof n!=="object")return!1;return Object.keys(r).every((i)=>n[i]===r[i])}var vt=new WeakMap;function yn(e,t,r){if(!r.once)return!1;let n=t.currentTarget??e.element,i=vt.get(e);if(!i)i=new WeakMap,vt.set(e,i);let o=i.get(n);if(!o)o=new Set,i.set(n,o);let s=(n===globalThis.window?`${ir(t.params?.ops)}|`:"")+JSON.stringify(r);if(o.has(s))return!0;return o.add(s),!1}var wt=new WeakMap,ir=(e)=>typeof e==="string"?e:JSON.stringify(e??null);function vn(e,t){if(e===null||typeof e!=="object")return!1;let r=ir(e.params?.ops),n=wt.get(e);if(!n)n=new WeakMap,wt.set(e,n);let i=n.get(t);if(!i)i=new Map,n.set(t,i);let o=i.get(e.currentTarget);if(!o)o=new Set,i.set(e.currentTarget,o);if(o.has(r))return!0;return o.add(r),!1}var wn=new Set(["click","focus","focus_first"]);function De(e,t,r){for(let n of e){if(!Array.isArray(n))continue;let[i,o={}]=n;if(!Object.hasOwn(mt,i)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(i)} — skipped`);continue}let a=t(o);if(a.length===0&&r)r(i,o);if(a.length>1&&wn.has(i))a=a.slice(0,1);if(a.length>0)o=_n(i,o,t,r);if(!o)continue;for(let s of a)if(mt[i](s,o,t),o?.keep===!0)Rt(s,i,o,t)}}var An=new Set(["set_value","text","set_attr"]);function _n(e,t,r,n){let i=e==="dispatch",o=i?t.detail_from:An.has(e)&&t.from!=null&&{value:t.attr};if(!o||i&&!Object.keys(o).length)return t;let a=i?t.detail??{}:{};if(typeof a!="object"||Array.isArray(a))return console.warn(`[phlex-reactive] refused client read over detail ${JSON.stringify(a)} — skipped`),null;let s=i?"@trigger":t.from,c;try{c=r({...t,to:s})[0]}catch{}if(!c)return n?.(e,{...t,to:s}),null;let u={...a};for(let[d,f]of Object.entries(o)){let h=Sn(c,f);if(h==null)return null;u[d]=h}return i?{...t,detail:u}:{...t,...u}}function Sn(e,t){if(t==="@text")return e.textContent??"";if(typeof t==="string"&&/^data-[a-z][a-z0-9-]*$/i.test(t))return e.getAttribute(t)??"";return console.warn(`[phlex-reactive] refused client read of ${JSON.stringify(t)} — skipped`),null}function En(e,t){let r=e.to;if(r==="@trigger")return[];if(t){if(r==="@root")return[t];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...t.querySelectorAll(r)]}if(typeof r!=="string"||r===""||r==="@root")return[];return[...document.querySelectorAll(r)]}function Tn(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Xe(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var x='[data-controller~="reactive"]',kn='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',$e=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Xe(e);function B(e,t,r){let n=e?.closest?.(t);while(n&&n!==r&&$e(n))n=n.parentElement?.closest?.(t);return n??null}var O=new WeakMap,ke=new Set,Q=new WeakMap;function Fn(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 Rn(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 Nn(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function Ln(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function xn(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 or(e){return e.getAttribute?.("data-reactive-presence")!=null}function On(e){return e.getAttribute?.("data-reactive-subscribe")!=null}function In(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}var Pn=[["persist",[Tn,null,null,!0]],["defer",[Xe,null]],["form",[Fn,null]],["bindings",[Rn,null,null,!0]],["compute",[Nn,null,null,!0]],["sortable",[Ln,null]],["drag",[xn,null]],["presence",[or,null]],["subscribe",[On,null]],["countdown",[In,null]],["effects",[(e)=>["enter","update","exit"].some((t)=>e.getAttribute?.(`data-reactive-effect-${t}`)!=null),null]],["hints",[(e)=>e.querySelector?.("[data-reactive-optimistic-param], [data-reactive-busy-param], [data-reactive-loading-param]")!=null,null]],["devtools",[(e)=>e.getAttribute?.("data-reactive-debug")==="true",null]]],_=new Map(Pn),At=new Map,g=new Map,Mn=new Map;function y(e,t,r){sr.set(e,[t,r]),Cn(e)}var sr=new Map;function Cn(e){let t=_.get(e),[r,n]=sr.get(e);t[1]=r,t[2]=n}function ii(e,t){t.install?.(H),g.set(e,t),Mn.set(e,t)}function ar(e){let t=[];for(let[r,[n]]of _){if(!n||g.has(r))continue;try{if(e.some((i)=>n(i)))t.push(r)}catch{}}return t}function cr(e){return z(e).catch((t)=>de(e,"load",t))}function z(e){let t=At.get(e);if(!t)t=(_.get(e)[1]??(()=>Promise.reject(Error("this entry has no way to import it"))))().then((n)=>(n.install?.(H),g.set(e,n),n)),At.set(e,t);return t}var _t=new Set;function de(e,t,r){let n=e+t;if(_t.has(n))return;_t.add(n),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,r)}function w(e,t){let r=g.get(e);if(r)return t(r);z(e).then(t,(n)=>de(e,"load",n))}var Dn=1e4;function Fe(){let e=Number(globalThis.document?.head?.querySelector?.('meta[name="phlex-reactive-feature-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:Dn}function oi(){return[..._.keys()]}var St=Promise.resolve();function Et(e,t,r){let n=H.waiting.get(e);if(n&&n[t]===r)delete n[t]}var H={enter:$t,exit:qt,fail:W,count:Ht,text:R,served:Ge,waiting:new WeakMap};var C=Symbol.for("phlex-reactive.early"),$n=1e4,qn=1500,Qe=(e)=>e!=null&&(e===globalThis.window||e.window===e),Bn="dispatch";function ne(){return globalThis[C]??={queue:[],connected:new WeakSet},globalThis[C]}function Wn(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:$n}function jn(e){let t={};for(let{name:r,value:n}of Array.from(e.attributes??[])){let i=/^data-reactive-(.+)-param$/i.exec(r);if(!i)continue;let o;try{o=JSON.parse(n)}catch{o=n}t[i[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=o}return t}function Un(e,t,r){return{[C]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:r?t.ownerDocument.defaultView:t,params:jn(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&&!Ye().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var fe=new WeakMap;function Jn(e,{token:t,type:r,method:n,filter:i,win:o},a){let s=fe.get(e);if(!s)fe.set(e,s=new Map);let c=o?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:r,method:n,filter:i,win:o,params:a,armed:!0}),!0}function Tt(e,t,r,n){if(e?.[C])return!1;let i=Qe(e?.currentTarget),o=i?n:e?.currentTarget,a=i&&JSON.stringify(e.params),s=zn(e,o,i?`@${t}${a}`:t),c=fe.get(o);for(let u of c?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==i)continue;if(i&&u.params!==a)continue;if(u.filter&&!M(u.filter,e,r))continue;return u.armed=!1,!0}return s}var ie=new WeakMap;function kt(e,t,r){let n=ie.get(e);if(!n)ie.set(e,n=new Map),setTimeout(()=>ie.delete(e));let i=n.get(t)??{};n.set(t,i),i[r]=(i[r]??0)+1}function zn(e,t,r){let n=e&&ie.get(e)?.get(t);if(!n?.[r])return!1;return n[r]-=1,!0}class ur extends dr{static values={token:String};#S;#s=new Map;#f=new Map;#oe;#se;#B;#L=0;#h=new Map;#x=new WeakMap;#r;featuresReady=St;#n=new Map;#O=new Set;#m=!1;#i=null;#p=new Map;#E=new Map;#g=new Map;#b=0;#W;#Je=0;#ze=0;connect(){if(Vt=!0,ne().connected.add(this.element),O.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||Xe(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===Z)this.#J();this.#j(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.(Z,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(He),this.#b++,this.featuresReady=St,this.#j(),oe(this.element),this.#le()}#Ke(e){}#He(e,t,r,n){}#Ge(){}#Ve(e,t){}#j(e){{let t=this.#b,r=[];for(let[o,[a]]of _){if(!a||this.#O.has(o))continue;let s=g.get(o);if(s&&!s.connect)continue;try{if(a(this.element))r.push(o)}catch(c){this.#y(o,"detect",c)}}if(r.length===0)return;for(let o of r)this.#O.add(o);if(!this.#m&&r.every((o)=>g.has(o))){for(let o of r)this.#I(t,o,g.get(o),e);return}for(let o of r){let a=this.#ae(t,o),s=[];for(let u of _.keys()){if(u===o)break;if(this.#g.has(u))s.push(this.#g.get(u))}let c=Promise.all(s).then(()=>a).then((u)=>u&&this.#I(t,o,u,e));if(this.#g.set(o,c),_.get(o)[3])this.#i=c}let n=this.#i;n?.then(()=>{if(this.#i===n)this.#i=null}),this.#m=!0;let i=Promise.all(this.#g.values()).then(()=>{if(this.featuresReady===i)this.#m=!1});this.featuresReady=i}}#ae(e,t){{let r=()=>e===this.#b;return this.#ce(t),new Promise((n)=>{let i=!1,o=setTimeout(()=>{if(this.#p.delete(o),i=!0,r())this.#y(t,"timeout",Error(`not loaded after ${Fe()} ms`));n(null)},Fe());this.#p.set(o,n);let a=()=>{clearTimeout(o),this.#p.delete(o)};z(t).then((s)=>{if(a(),i)queueMicrotask(()=>this.#I(e,t,s));else n(s)},(s)=>{if(a(),r())this.#y(t,"load",s);n(null)})})}}#ce(e){{let t=_.get(e)[2];if(!t)return;let r={};try{this.#E.set(e,[t(this.element,r),r]),H.waiting.set(this.element,{...H.waiting.get(this.element),[e]:r})}catch(n){this.#y(e,"detect",n)}}}#U(e,t){{let[r,n]=this.#E.get(e)??[];if(this.#E.delete(e),!t)Et(this.element,e,n);try{r?.()}catch(i){console.error(`[phlex-reactive] the "${e}" feature module failed to stop waiting`,i)}return n}}#I(e,t,r,n){{if(e!==this.#b)return;let i=this.#U(t);try{r.connect?.(this,this.#e(),n,i),this.#n.set(t,r)}catch(o){this.#y(t,"connect",o)}}}#e(){return this.#W??={emit:(e,t,r)=>this.#o(e,t,r),reseed:()=>this.#J(),proceed:(e,t,r,n)=>this.#M(e,t,r,0,0,null,n),forgetToken:()=>{this.#S=void 0},owns:(e)=>this.#u(e),ownership:()=>this.#Z(),bindingOwns:(e)=>this.#ee(e),bindingOwnership:()=>this.#xe(),opTargets:(e)=>this.#q(e),diagnose:(e,t)=>this.#$(e,t),applyOps:(e,t)=>De(e,(r)=>this.#q(t!=null&&r.to==null?{...r,to:t}:r),(r,n)=>this.#$(`client op "${r}"`,n)),listnavOptions:(e)=>this.#w(e),collectFields:()=>this.#te(),plain:Pt,text:R,served:Ge,copyMedia:er,setValue:Zt,confirm:(e,t)=>Promise.resolve().then(()=>Ze(e,t)).catch(()=>!1)},this.#W}#J(){this.#n.get("form")?.reseed(this),this.#n.get("bindings")?.reseed(this),this.#n.get("compute")?.seed(this)}#y(e,t,r){if(de(e,t,r),this.#t("feature"),W({kind:"feature",root:this.element.id}),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#o("reactive:error",{kind:"feature",feature:e,phase:t,error:r})}#ue(){{this.#b++;for(let[t,r]of this.#p)clearTimeout(t),r(null);this.#p.clear();for(let t of[...this.#E.keys()]){let r=this.#U(t,!0),n=this.element;w(t,(i)=>{i.abandon?.(n,r),Et(n,t,r)})}this.#O.clear(),this.#g.clear(),this.#m=!1,this.#i=null;let e=[...this.#n];this.#n.clear();for(let[t,r]of e)try{r.disconnect?.(this,this.#e())}catch(n){console.error(`[phlex-reactive] the "${t}" feature module failed to disconnect`,n)}}}#le(){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.#de();for(let[e,t]of Q.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Q.delete(this.element)}#P=new Set;#de(){let{queue:e}=ne();if(e.length===0)return;let t=[];for(let i=e.length-1;i>=0;i--){let{root:o}=e[i];if(o===this.element||!o.isConnected)t.unshift(...e.splice(i,1))}let r=Wn(),n=new Map;for(let i of t){let o=n.get(i.event)??[new Set,new Set];n.set(i.event,o);let a=o[+!!i.win];if(a.has(i.el))continue;a.add(i.el);let s=i.win?Math.min(qn,r):r,c=i.root!==this.element?"its root left the page before a controller connected":performance.now()-i.at>s?`it is older than the ${s} ms ${i.win?"window-trigger":"early-event"} TTL`:i.el.isConnected&&this.element.contains(i.el)?null:"its element left the root before the controller connected";if(c){if(this.#R())console.warn(`[phlex-reactive] dropped an early "${i.event.type}" trigger: ${c}`);continue}this.#fe(i)}}#fe({event:e,el:t,descs:r,win:n}){let i=Un(e,t,n),o=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=n?this.element:t,c=n?JSON.stringify(i.params):"",u=n?`@runOps${c}`:"runOps",d=!1;for(let f of r){if(!a.includes(f.token))continue;if(f.filter&&!M(f.filter,e,o))continue;if(/#\w+.*:once\b/.test(f.token)){if(!Jn(s,f,n&&JSON.stringify(i.params)))continue;this.#P.add(s)}if(f.method==="runOps")d=!0,this.runOps(i);else kt(e,s,n?`@dispatch${c}`:"dispatch"),this.dispatch(i)}if(d)for(let f of a){let h=/^(?:(key(?:down|up|press))(?:\.([\w+]+))?|([^@>]+))(@window)?->reactive#runOps/.exec(f);if(h&&(h[1]??h[3])===e.type&&!!h[4]===!!n&&(!h[2]||M(h[2],e,o)))kt(e,s,u)}}disconnect(){if(this.#ue(),this.#_e(),this.#Ee(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.(Z,this.#r);if(ne().connected.delete(this.element),O.get(this.element)===this)O.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#P)fe.delete(e);this.#P.clear()}dispatch(e){if(pn(e,this.application?.schema?.keyMappings))return;if(e.params?.action&&e.params.action!==ct&&this.#he())return this.#me(e);let t=e.params?.shortcut;if(Tt(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:r,params:n,debounce:i,throttle:o,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:d,prevent:f,awaitSettled:h}=e.params;if(!r)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let b=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#ne(d,b))Se(e,t);if(r===ct){let L=()=>{{let m=this.#n.get("defer");if(m)return m.materialize(this)}if(this.tokenValue)return this.#M(b,r,"{}")};return this.#m?this.featuresReady.then(L):L()}let T=this.#z(a,s),N=()=>this.#M(b,r,n,i,o,d,p,h);if(!T)return N();if(T instanceof Promise)return T.then((L)=>L?this.#T(L,b,N):N());this.#T(T,b,N)}#T(e,t,r){return Promise.resolve().then(()=>Ze(e,{el:t})).catch(()=>!1).then((n)=>{if(n)r()})}#z(e,t){if(e)return e;if(!t)return null;{let r=g.get("bindings");if(r)return r.confirmMessage(this,this.#e(),t);return this.#K("bindings").then((n)=>n&&n.confirmMessage(this,this.#e(),t))}}#K(e){{let t;return Promise.race([z(e).catch((r)=>(de(e,"load",r),null)),new Promise((r)=>t=setTimeout(()=>r(null),Fe()))]).finally(()=>clearTimeout(t))}}#he(){return!this.tokenValue&&$e(this.element)}#me(e){let t=B(this.element.parentElement,kn);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 r=O.get(t);if(r)return r.dispatch(e);let{shortcut:n,window:i,optimistic:o,prevent:a}=e.params,s=e.currentTarget??e.target;if((n!=null||!i&&a!==!1)&&!this.#ne(o,s))Se(e,n);Q.set(t,[...Q.get(t)??[],[e,s]]);let c=t.dataset;if(c.reactiveDormant)c.controller=`${c.controller??""} ${c.reactiveDormant}`.trim(),delete c.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!Me(t.shortcut,e,this.application?.schema?.keyMappings))return;if(Ce.test(t?.on)&&!Te(t,e,this.application?.schema?.keyMappings))return;if(Tt(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(vn(e,this))return;let r=e.params??{},n=e.currentTarget??e.target,i=gn(r.ops),o=i.some((c)=>Ce.test(c.on)),a=i.filter((c)=>Te(c,e,null)),s=a.length<=1&&!o?a:a.filter((c)=>Te(c,e,this.application?.schema?.keyMappings));if(s.length===0&&i.length>0){if(this.#R()&&!o)this.#_((c)=>c.noBinding(this,e));return}for(let c of s){if(c.outside&&e[C])continue;if(!bn(c,e))continue;let u=c.within==null?n:this.#pe(c.within,e);if(c.within!=null&&!u)continue;if(c.shortcut!=null&&!Me(c.shortcut,e,this.application?.schema?.keyMappings))continue;if(yn(this,e,c))continue;this.#ge(c.legacy?{...r,ops:c.ops,debounce:void 0,throttle:void 0,prevent:void 0}:c,e,u,i.indexOf(c),n)}}#pe(e,t){let r=t.currentTarget,n=null;try{n=t.target?.closest?.(e)}catch{if(this.#R())console.warn(`[phlex-reactive] on_client within: ${JSON.stringify(e)} is not a selector — nothing ran`)}return n&&n!==r&&r?.contains?.(n)&&this.#u(n)?n:null}#ge(e,t,r,n,i=r){let{ops:o,confirm:a,confirmWhen:s,outside:c,window:u,shortcut:d,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(d!=null||!u&&f!==!1)Se(t,d);let h=this.#z(a,s),p=this.#be(e,n,i,()=>this.#De(this.#Ce(o),r));if(!h)return p();if(h instanceof Promise)return h.then((b)=>b?this.#T(b,r,p):p());this.#T(h,r,p)}#be(e,t,r,n){let i=Number(e.debounce)||0,o=Number(e.throttle)||0;if(i<=0&&o<=0)return n;let a=JSON.stringify([t,e]);if(i>0)return()=>this.#H(r,a,i,n);return()=>this.#Y(r,a,o,n)}recompute(e){return g.get("compute")?.recompute(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented)return;if(this.#w(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return this.#v("tagsAdd",e)}tagsPick(e){return this.#v("tagsPick",e)}tagsRemove(e){return this.#v("tagsRemove",e)}nestedAdd(e){return this.#v("nestedAdd",e)}nestedRemove(e){return this.#v("nestedRemove",e)}syncNestedJson(e){return g.get("bindings")?.syncNestedJson(this,this.#e(),e)}#v(e,t){{let r=g.get("bindings");if(r)return r[e](this,this.#e(),t);t?.preventDefault?.();let n={currentTarget:t?.currentTarget??null,target:t?.target??null,preventDefault(){}};return w("bindings",(i)=>i[e](this,this.#e(),n))}}trackDirty(){(this.#n.get("form")??g.get("form"))?.scan(this,this.#e())}listnavNext(e){this.#k(e,(t,r)=>t<0?0:(t+1)%r)}listnavPrev(e){this.#k(e,(t,r)=>t<0?r-1:(t-1+r)%r)}listnavFirst(e){this.#k(e,()=>0)}listnavLast(e){this.#k(e,(t,r)=>r-1)}listnavPick(e){let t=this.#w(e),r=t.findIndex((n)=>n.hasAttribute("data-reactive-highlighted"));if(r<0)return;e.preventDefault(),t[r].click()}listnavClose(e){for(let t of this.#w(e))t.removeAttribute("data-reactive-highlighted")}#k(e,t){let r=this.#w(e);if(!r.length)return;e.preventDefault();let n=this.#ye(e),i=globalThis.document?.activeElement,o=n?r.findIndex((s)=>s===i||i!=null&&s.contains?.(i)):r.findIndex((s)=>s.hasAttribute("data-reactive-highlighted")),a=r[t(o,r.length)];if(n)a.focus?.();else{for(let s of r)s.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ye(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#w(e){let r=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!r)return[];let n=this.#Z();return Array.from(this.element.querySelectorAll(r)).filter((i)=>!i.hidden&&n(i))}#M(e,t,r,n,i,o,a,s){if(this.#o("reactive:before-dispatch",{action:t,params:this.#re(r),element:this.element},{cancelable:!0}).defaultPrevented)return;if(s&&!me())return this.#ve(t,r,e,(f)=>f.#A(t,r,o,e,a));let u=Number(n)||0;if(u>0)return this.#Ae(e,u,t,r,o,a);let d=Number(i)||0;if(d>0)return this.#Se(e,d,t,r,o,a);return this.#A(t,r,o,e,a)}#ve(e,t,r,n){let i=this.element.id,o=`${ae}\x00${i}\x00${e}\x00${typeof t==="string"?t:JSON.stringify(t)}`;if(ke.has(o))return;let a=r?.nodeType===1?r:null,s=Jt(this.#N(),(c)=>{ke.delete(o),a?.removeAttribute(j);let u=this.element.isConnected&&O.get(this.element)===this?this:i&&O.get(document.getElementById(i));if(c&&u)return n(u)});return ke.add(o),a?.setAttribute(j,""),s}#A(e,t,r,n,i){let o={inverse:null,undo:[],resurrect:null},a=this.#$e(e,n,o),s=Boolean(r||i),c=(h)=>{if(!s||!h)return;let p=this.#e();if(o.inverse=h.optimistic(this,p,r,n),o.undo.push(...h.busy(this,p,i,n)),this.#C())o.resurrect=h.resurrection(this,p,r,n)},u=g.get("hints");if(!s||u)c(u);let d=()=>this.#Re(e,t,o,a),f=()=>this.#i?this.#i.then(d):d();return this.queue=(this.queue??Promise.resolve()).then(()=>s&&!u?this.#we().then(c).then(f):f()),this.queue}#we(){return this.#K("hints")}#Ae(e,t,r,n,i,o){this.#H(e,Bn,t,()=>this.#A(r,n,i,e,o))}#H(e,t,r,n){let i=this.#s.get(e)?.get(t),o=()=>{this.#V(e,t),n()},a=setTimeout(o,r);if(!Qe(e))e?.addEventListener?.("blur",o,{once:!0});let s=this.#s.get(e);if(!s)this.#s.set(e,s=new Map);if(s.set(t,{timer:a,flush:o}),Mr(o),i)this.#G(e,i)}#G(e,t){clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),Cr(t.flush)}#V(e,t){let r=this.#s.get(e),n=r?.get(t);if(!n)return;if(this.#G(e,n),r.delete(t),r.size===0)this.#s.delete(e)}#_e(){for(let[e,t]of[...this.#s])for(let r of[...t.keys()])this.#V(e,r)}#Se(e,t,r,n,i,o){return this.#Y(e,r,t,()=>this.#A(r,n,i,e,o))}#Y(e,t,r,n){let i=this.#f.get(e)??new Map;if(i.has(t))return;let o=setTimeout(()=>{if(i.delete(t),i.size===0)this.#f.delete(e)},r);return i.set(t,o),this.#f.set(e,i),n()}#Ee(){for(let e of this.#f.values())for(let t of e.values())clearTimeout(t);this.#f.clear()}#o(e,t,{cancelable:r=!1}={}){let n=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:r,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(n),n}#a(e,t,r,n){let i=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#A(e,t)};W({action:e,kind:n.kind,status:n.status,root:this.element.id}),this.#o("reactive:error",{action:e,params:r,...n,retry:i})}#t(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#Te(){this.element?.removeAttribute?.("data-reactive-error")}#ke(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",r=document.getElementById(t);if(!r)return;r.appendChild(e.content.cloneNode(!0))}#Fe(){{let e=g.get("devtools");if(e)return e.delay();if(Ct())return z("devtools").then((t)=>t.delay(),()=>{})}}#C(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#X(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#Re(e,t,r,n){let{fields:i,files:o}=this.#te(),a=this.#re(t),s={...i,...a},c=this.#c,u=o.length>0,d=u?this.#Pe(c,e,s,o):JSON.stringify({token:c,act:e,params:s}),f=this.#C()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(i),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#X()}:null;await this.#Fe();try{if(navigator.onLine===!1){this.#l(r.inverse),this.#t("offline"),this.#a(e,t,s,{kind:"offline"});return}let h;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#je()};if(!u)m["Content-Type"]="application/json";let q=this.#Ue();if(q)m["X-Pgbus-Connection"]=q;let G=or(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(G)m["X-Reactive-Presence"]=G;let V=Rr(this.element);if(V)m["X-Reactive-Held"]=V;Ht("action"),h=await fetch(this.#We(),{method:"POST",headers:m,body:d,credentials:"same-origin",signal:AbortSignal.timeout(this.#N())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#l(r.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#t("timeout"),this.#a(e,t,s,{kind:"timeout"});return}this.#ke(),this.#t("network"),this.#a(e,t,s,{kind:"network"});return}if(f)f.status=h.status;if(h.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#l(r.inverse),this.#t("redirected"),this.#a(e,t,s,{kind:"redirected",status:h.status});return}if(!h.ok){let m=await h.text();if(console.error(`[phlex-reactive] action failed: HTTP ${h.status}`,m),this.#l(r.inverse),(h.headers.get("Content-Type")||"").includes("turbo-stream")){let q=this.#Q(m);if(this.#c=q??this.#c,f)this.#_((V)=>V.recordBody(f,m,q));let G=at(this.element,m,!0,this.#N());n?.handoff?.(),await G}this.#t("http"),this.#a(e,t,s,{kind:"http",status:h.status,body:m});return}let p=h.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#l(r.inverse),this.#t("content-type"),this.#a(e,t,s,{kind:"content-type",status:h.status});return}let b=await h.text(),T=this.#Q(b);if(this.#c=T??this.#c,f)this.#_((m)=>m.recordBody(f,b,T));let N=at(this.element,b,Nr(h),this.#N());if(r.resurrect)queueMicrotask(r.resurrect);if(this.#Te(),this.#o("reactive:applied",{action:e,params:s,html:b}),n?.handoff?.(),await N)this.#t("apply"),W({action:e,kind:"apply",root:this.element.id}),this.#o("reactive:error",{action:e,params:s,kind:"apply"});return b}catch(h){console.error("[phlex-reactive] action error",h),this.#l(r.inverse),this.#t("apply"),W({action:e,kind:"apply",root:this.element.id}),this.#o("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(n?.(),f)this.#_((h)=>h.trace(this,{...f,ms:this.#X()-f.started}))}}get#c(){return this.#S??this.tokenValue}set#c(e){this.#S=e}tokenValueChanged(){this.#S=void 0}#Q(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:r,self:n}=this.#Ne(t),i=e.match(r);if(i)return i[1];let o=e.match(n);if(o)return o[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#Ne(e){let t=this.#B;if(t&&t.id===e)return t;let r=Kr(e);return this.#B={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${r}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${r}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#u(e){return e.closest('[data-controller~="reactive"]')===this.element}#Z(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#u(t)}#Le(){let e=this.element.querySelectorAll(x);if(e.length===0||[...e].every($e))return()=>!0;return(t)=>{let r=B(t,x,this.element);if(r===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&B(r.parentElement,x,this.element)===this.element}}#ee(e){if(this.#u(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=B(e,x,this.element);return t===this.element||B(t?.parentElement,x,this.element)===this.element}#xe(){if(this.element.querySelectorAll(x).length===0)return()=>!0;return(e)=>this.#ee(e)}#te(){let e={},t=[],r=this.#Le(),n=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!r(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else n.push(s)});let i=[];this.element.querySelectorAll(`[name]${Xr}`).forEach((s)=>{if(r(s))i.push(s)});let o=this.#Oe(n),a=this.#Ie(n);for(let s of n)if(o.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 i.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?R(s):s.value??s.textContent??s.innerHTML??"",d=e[c];if(String(c).endsWith("[]")&&!Zr(s))return;if(String(c).endsWith("[]")&&(d===void 0||Array.isArray(d))){(Array.isArray(d)?d:e[c]=[]).push(u);return}if(d==null||d==="")e[c]=u}),{fields:e,files:t}}#Oe(e){let t=new Set;for(let r of e){if(r.type==="radio")continue;if(String(r.name).endsWith("[]"))t.add(r.name)}return t}#Ie(e){let t=new Set;for(let r of e)if(r.type==="checkbox")t.add(r.name);return t}#Pe(e,t,r,n){let i=new FormData;i.append("token",e),i.append("act",t);let o=[];for(let[s,c]of Object.entries(r))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)o.push(String(s).slice(0,-2));else{let u=`${this.#F(s)}[]`;for(let d of c)i.append(u,String(d))}else this.#D(i,this.#F(s),c);for(let s of o)i.append("empty_groups[]",s);let a=this.#Me(n);for(let{name:s,file:c,multiple:u}of n){let f=u||a.has(s)?`${this.#F(s)}[]`:this.#F(s);i.append(f,c,c.name)}return i}#F(e){let t=String(e),r=t.indexOf("[");if(r===-1)return`params[${t}]`;return`params${[t.slice(0,r),...t.slice(r).match(/[^\[\]]+/g)??[]].map((i)=>`[${i}]`).join("")}`}#D(e,t,r){if(r==null)e.append(t,"");else if(Array.isArray(r))r.forEach((n,i)=>this.#D(e,`${t}[${i}]`,n));else if(typeof r==="object")for(let[n,i]of Object.entries(r))this.#D(e,`${t}[${n}]`,i);else e.append(t,String(r))}#Me(e){let t=new Map;for(let{name:r}of e)t.set(r,(t.get(r)??0)+1);return new Set([...t].filter(([,r])=>r>1).map(([r])=>r))}#re(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Ce(e){return Ve(e)}#De(e,t){De(e,(r)=>this.#q(r,t),(r,n)=>this.#$(`client op "${r}"`,n))}#R(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#C()}#$(e,t){if(!this.#R())return;this.#_((r)=>r.diagnose(this,e,t))}#_(e){w("devtools",e)}#q(e,t){let r=e.to;if(r==="@root")return[this.element];if(r==="@trigger")return t?.nodeType===1?[t]:[];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...this.element.querySelectorAll(r)].filter((n)=>this.#u(n))}#ne(e,t){if(e?.checked!=="keep")return!1;let r=t?.type;return r==="checkbox"||r==="radio"}#l(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#$e(e,t,r){this.#qe(e,t),$t();let n=!1,i=!1,o=()=>{if(n)return;n=!0,this.#Be(e,t);for(let s of r.undo)s()},a=()=>{if(i)return;i=!0,o(),qt()};return a.handoff=o,a}#qe(e,t){if(this.#d(t,e,1),this.#d(this.element,e,1),this.#h.set(e,(this.#h.get(e)??0)+1),this.#L++===0)this.element.setAttribute("aria-busy","true");for(let r of this.#ie(e))this.#d(r,e,1)}#Be(e,t){this.#d(t,e,-1),this.#d(this.element,e,-1);let r=(this.#h.get(e)??1)-1;if(r<=0)this.#h.delete(e);else this.#h.set(e,r);if(--this.#L<=0)this.#L=0,this.element.removeAttribute("aria-busy");for(let n of this.#ie(e))this.#d(n,e,-1)}#d(e,t,r){if(!e||typeof e.getAttribute!=="function")return;let n=this.#x.get(e)??new Map,i=(n.get(t)??0)+r;if(i<=0)n.delete(t);else n.set(t,i);if(n.size===0){this.#x.delete(e),e.removeAttribute("data-reactive-busy");return}this.#x.set(e,n),e.setAttribute("data-reactive-busy",[...n.keys()].join(" "))}#ie(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((r)=>r.getAttribute("data-reactive-busy-on")===e&&this.#u(r))}#We(){return this.#oe??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#N(){return this.#se??=Ut()}#je(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Ue(){let e=this.element.getAttribute?.("data-reactive-subscribe"),t;if(e){for(let r of document.querySelectorAll("pgbus-stream-source[data-reactive-subscribe-source][connection-id]"))if(r.getAttribute("src")===e)t=r.getAttribute("connection-id")}return t||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)ht();else document.addEventListener("turbo:load",ht,{once:!0});y("persist",()=>import("phlex/reactive/features/persist"),Kn);y("defer",()=>import("phlex/reactive/features/defer"));y("form",()=>import("phlex/reactive/features/form"));y("bindings",()=>import("phlex/reactive/features/bindings"));y("compute",()=>import("phlex/reactive/features/compute"),Hn);y("sortable",()=>import("phlex/reactive/features/sortable"));y("drag",()=>import("phlex/reactive/features/drag"));y("presence",()=>import("phlex/reactive/features/presence"));y("subscribe",()=>import("phlex/reactive/features/subscribe"));y("countdown",()=>import("phlex/reactive/features/countdown"));y("effects",()=>import("phlex/reactive/features/effects"));y("hints",()=>import("phlex/reactive/features/hints"));y("devtools",()=>import("phlex/reactive/features/devtools"));Ke();function Kn(e,t){let r=()=>{t.edited=!0},n=(o)=>{let a=o.target;if(o.detail?.success&&a?.tagName==="FORM"&&a.contains?.(e))t.submitted=!0},i=["input","change","lexxy:change","trix-change"];for(let o of i)e.addEventListener?.(o,r);return document.addEventListener("turbo:submit-end",n),()=>{for(let o of i)e.removeEventListener?.(o,r);document.removeEventListener("turbo:submit-end",n)}}function Hn(e,t){let r=()=>{t.edited=!0};return e.addEventListener?.("input",r),e.addEventListener?.("change",r),()=>{e.removeEventListener?.("input",r),e.removeEventListener?.("change",r)}}var Gn=1000,D=null,lr,pe=new Set;function Vn(e){return cr(e).then((t)=>{if(e!=="effects")return;lr=t,t?.sweep()})}It((e,t)=>{let r=e.detail,n=r?.render;if(typeof n!=="function")return;let i=r.newStream??e.target,o=ar(Yn(i)).filter((s)=>!pe.has(s));if(!t&&!pe.has("effects")&&Xn(i))o.push("effects");if(o.length===0&&!D)return t?.wrap(e);if(o.length>0){for(let c of o)pe.add(c);let s=D=Promise.race([Promise.all([D,...o.map(Vn)]),new Promise((c)=>setTimeout(c,Gn))]).then(()=>{if(D!==s)return;D=null,pe.clear()})}let a=D;r.render=async(s)=>{await a;let c={target:e.target,detail:{newStream:r.newStream,render:n}};(t??lr)?.wrap(c),await c.detail.render(s)}});function Yn(e){let t=e?.querySelector?.("template")?.content;if(!t)return[];let r=[...t.querySelectorAll?.('[data-controller~="reactive"]')??[]];for(let n of t.children??[])if(n.matches?.('[data-controller~="reactive"]')&&!r.includes(n))r.unshift(n);return r.push(t),r}function Xn(e){return Boolean(e?.hasAttribute?.("data-reactive-effect")||document.getElementById?.(e?.getAttribute?.("target"))?.matches?.("[data-reactive-effect-update],[data-reactive-effect-exit]")||e?.querySelector?.("template")?.content?.querySelector?.("[data-reactive-effect-enter],[data-reactive-dismiss-after]")||document.querySelector?.("[data-reactive-dismiss-after]:not([data-reactive-dismiss-scheduled])"))}var di=ur;export{Dt as ACTIVE_ATTR,Xr as EDITOR_SELECTOR,Qr as EDITOR_TAGS,Oe as ERRORS_ATTR,Kt as REQUESTS_ATTR,Hr as checkReactiveRegistration,Ht as countReactiveRequest,di as default,R as editableValue,$t as enterReactiveActivity,Kr as escapeRegExp,qt as exitReactiveActivity,Dr as flushReactiveDebounces,cr as loadReactiveFeature,It as onReactiveStreamWithoutEffects,ti as reactiveActivityCount,ni as reactiveDebounceCount,oi as reactiveFeatureNames,$r as reactiveSettled,W as recordReactiveError,ht as registerReactiveActions,Ur as registerReactiveAwaitSettled,gr as registerReactiveDefer,Ke as registerReactiveDev,br as registerReactiveDismiss,br as registerReactiveEffects,ii as registerReactiveFeature,y as registerReactiveFeatureLoader,Sr as registerReactiveImageFallback,pr as registerReactiveJs,_r as registerReactiveKeep,Ar as registerReactiveModals,Tr as registerReactiveMorphFocus,Or as registerReactiveOffline,Er as registerReactivePlaintext,on as registerReactiveRejectedFiles,br as registerReactiveStreamRender,hr as registerReactiveToken,fr as registerReactiveVisit,ri as resetReactiveActivity,Ge as serverText,ar as unloadedFeaturesFor};
|
|
5
|
+
`).replace(/\n$/,""),e.getAttribute("data-reactive-editable")==="multi"?t:t.replace(/\n/g," ")}var ue=new WeakMap;function Ve(e){if(e?.hasAttribute?.("data-reactive-editable")&&!ue.has(e))ue.set(e,R(e))}function Ye(e){return Ve(e),ue.get(e)}function rn(e){return tn.has(e.localName)?typeof e.value==="string":!0}var gt=Object.freeze({show:(e,t,r)=>Se(e,!1,t,r),hide:(e,t,r)=>Se(e,!0,t,r),toggle:(e,t,r)=>Se(e,!e.hidden,t,r),add_class:(e,t)=>e.classList.add(...t.classes??[]),remove_class:(e,t)=>e.classList.remove(...t.classes??[]),toggle_class:(e,t)=>(t.classes??[]).forEach((r)=>e.classList.toggle(r)),set_attr:(e,t)=>{if(Ee(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(Ee(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!Ee(t.name))return;if(Array.isArray(t.values)){let[r,n]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===r?n:r)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>mn(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>Nt(e),close_dialog:(e)=>_r(e),click:(e)=>e.click?.(),text:(e,t)=>{let r=String(t.value??"");if(e.textContent!==r)e.textContent=r},copy_media:(e,t,r)=>{let n=null;try{n=r({...t,to:t.from})[0]??null}catch{}rr(e,n)},check_group:(e,t)=>{let r=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let n of r)w("bindings",(i)=>i.checkGroup(n,t.group,t.checked))},presence:(e,t)=>w("presence",(r)=>r.set(e,t.state)),dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,r)=>{let n=nn(e);if(!n)return;let i=null;if(t?.submitter!=null&&typeof r==="function"){if(i=r({...t,to:t.submitter})[0]??null,!(i?.form===n&&(i.type==="submit"||i.type==="image")))console.warn(`[phlex-reactive] submitter ${t.submitter} is not a submit control of the form — ignored`),i=null}i?n.requestSubmit?.(i):n.requestSubmit?.()},paste_into:(e)=>on(e),preview_file:(e,t,r)=>sn(e,t,r),set_value:(e,t)=>tr(e,String(t.value??"")),persist_state:(e,t)=>w("persist",(r)=>r.writeState(e,t.state)),persist_clear:(e)=>w("persist",(t)=>t.clearRoot(e))});function nn(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function on(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((r)=>{if(!r)return;e.value=r,er(e),e.focus?.()}).catch(()=>{})}var U=new Map,K=null;function sn(e,t,r){if(e?.tagName!=="INPUT"||e.type!=="file")return ne(`reads an input[type=file], not <${e?.localName}>`);let n=typeof r==="function"?r({...t,to:t.into})[0]:null;if(n?.tagName!=="IMG")return ne(`paints an <img>, and ${JSON.stringify(t.into)} is ${n?`a <${n.localName}>`:"not on the page"}`);let i=[...t.valid===!0&&e.validity?.valid===!1?[]:e.files??[]],o=ln(e,t.accept),a=(u)=>Number.isInteger(t.max_bytes)&&u.size>t.max_bytes,s=[],c;if(t.per_file===!0&&e.multiple){let u=i.filter((f,h)=>{let p=typeof f?.type==="string"&&o(f)?a(f)&&"size":"type";if(p)s.push({reason:p,file:f,index:h});return!p}),d=s.length>0&&!un(e,u)?i.length:u.length;for(let f of s)f.remaining=d;c=u.find((f)=>f.type.startsWith("image/"))}else{let u=i.filter((f)=>typeof f?.type==="string"&&o(f));c=u.find((f)=>f.type.startsWith("image/"));let d=i.length>0&&u.length===0?"type":null;if(c&&a(c))d="size";if(d)s.push({reason:d,file:d==="size"?c:i[0]}),c=null}if(Zt(n),c){let u=URL.createObjectURL(c);U.set(n,u),n.setAttribute("src",u),dn()}else n.removeAttribute("src");if(me(n),t.wrap!=null){let u=r({...t,to:t.wrap});if(u.length===0)ne(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let d of u)c?Ot(d):xt(d)}if(t.name!=null)for(let u of r({...t,to:t.name}))u.textContent=c?c.name:"";if(t.rejected!=null)an(e,r({...t,to:t.rejected}),s,t.rejected);for(let u of s)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:u}))}var le="data-reactive-file-rejected";function an(e,t,r,n){if(t.length===0)return Ce(e,`rejected: ${JSON.stringify(n)} is not on the page`);for(let i of t){for(let a of[...i.children])if(a.hasAttribute(le))a.remove();let o=[...i.children].find((a)=>a.localName==="template");if(!o){Ce(e,`rejected: ${JSON.stringify(n)} has no <template> child`);continue}for(let{reason:a,file:s}of r){let c=o.content.cloneNode(!0);for(let u of c.querySelectorAll("[data-reactive-file-reason]"))if(u.getAttribute("data-reactive-file-reason")!==a)u.remove();for(let u of c.querySelectorAll('[data-reactive-file="name"]'))u.textContent=s.name;for(let u of[...c.childNodes]){if(u.nodeType!==1)continue;u.setAttribute(le,""),i.append(u)}}}}var bt=!1;function cn(){if(bt)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;bt=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented||!t.lastElementChild?.hasAttribute(le))return;for(let n of t.children)if(n.hasAttribute(le))r.append(n.cloneNode(!0))})}function un(e,t){if(typeof DataTransfer!=="function")return Ce(e,"per_file: has no DataTransfer to drop the refused files from the input"),!1;let r=new DataTransfer;for(let n of t)r.items.add(n);return e.files=r.files,!0}function ln(e,t){let r=String((t===!0?e.getAttribute("accept"):typeof t==="string"&&t)||"").toLowerCase().split(",").map((n)=>n.trim()).filter(Boolean);if(r.length===0)return(n)=>n.type.startsWith("image/");return(n)=>{let i=n.type.toLowerCase();return r.some((o)=>o[0]==="."?String(n.name).toLowerCase().endsWith(o):o.endsWith("/*")?i.startsWith(o.slice(0,-1)):i===o)}}function ne(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function Ce(e,t){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))ne(t)}function Zt(e){let t=U.get(e);if(t===void 0)return;if(U.delete(e),URL.revokeObjectURL(t),U.size===0)K?.disconnect(),K=null}function dn(){if(K||typeof MutationObserver!=="function"||!document?.documentElement)return;K=new MutationObserver(()=>{for(let[e,t]of U)if(!e.isConnected||e.getAttribute("src")!==t)Zt(e)}),K.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function er(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function tr(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 r=yt(e);if(e.value=t,yt(e)!==r)er(e)}function yt(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
|
|
6
|
+
`):e.value}function fn(e,t,r){if(r?.transition)Qr(e,r.transition,()=>e.hidden=t);else e.hidden=t}function Se(e,t,r,n){if(fn(e,t,r),r?.expanded==null||typeof n!=="function")return;for(let i of n({...r,to:r.expanded}))i.setAttribute?.("aria-expanded",String(!t))}function Ee(e){if(!Qt(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function rr(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let r=t?.localName==="img"?t:null,n=r?.getAttribute("src"),i=!1;for(let a of["srcset","src"]){let s=n?r.getAttribute(a):null;if(s==null){if(e.hasAttribute(a))i=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==s)i=e.setAttribute(a,s)??!0}if(i)me(e);let o=r?.getAttribute("alt")??"";if(e.getAttribute("alt")!==o)e.setAttribute("alt",o);return r?o:!1}var hn='a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"]):not([type=hidden]):not([disabled])';function mn(e){return e.querySelectorAll?.(hn)?.[0]??null}function Xe(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 vt=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"}),wt=Object.freeze(["meta","ctrl","alt","shift"]);function M(e,t,r){let n=e.split("+");for(let a of wt)if(n.includes(a)!==Boolean(t[`${a}Key`]))return!1;let i=n.find((a)=>!wt.includes(a));if(i===void 0||typeof t.key!=="string")return!0;let o=r&&Object.hasOwn(r,i)?r[i]:Object.hasOwn(vt,i)?vt[i]:/^[a-z0-9]$/.test(i)?i:null;return typeof o==="string"&&o.toLowerCase()===t.key.toLowerCase()}var pn=(e)=>e&&typeof e==="object"?e.keys:String(e),Qe=()=>ie().prevented??=new WeakSet;function Te(e,t){if(t!=null&&!e.defaultPrevented)Qe().add(e);e.preventDefault()}var nr=(e)=>e?.isContentEditable||/^(input|textarea|select)$/.test(e?.localName);function ir(e,t,r,n){if(r.defaultPrevented&&e?.handled!==!0&&!Qe().has(r))return!1;if(e?.inEditable!==!0&&nr(r.target))return!1;let i=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return M(t.replace(/^mod\+/,`${i}+`),r,n)}var gn=1000,de={strokes:[],done:!1,seen:new WeakSet,listening:!1},ke=()=>de.done=!0;function or(e){let t=de;if(t.seen.has(e))return;if(t.seen.add(e),!t.listening)t.listening=!0,globalThis.window?.addEventListener?.("keydown",or,!0),globalThis.window?.addEventListener?.("blur",ke),globalThis.document?.addEventListener?.("turbo:before-render",ke,!0),globalThis.document?.addEventListener?.("focusin",(r)=>nr(r.target)&&ke(),!0);if(t.done)t.strokes=[],t.done=!1;if(!e.repeat&&!/^(Shift|Control|Alt|AltGraph|Meta|CapsLock|Fn|OS)$/.test(e.key))t.strokes=[...t.strokes.slice(-2),e]}function bn(e,t,r,n){if(r[C])return!1;or(r);let i=de.strokes.slice(-t.length);if(i.at(-1)!==r||i.length<t.length)return!1;let o=e?.within??gn,a=i.every((s,c)=>ir(e,t[c],s,n)&&(c===0||s.timeStamp-i[c-1].timeStamp<=o));if(a)de.done=!0;return a}function De(e,t,r){let n=pn(e).split(" ");return n.length>1?bn(e,n,t,r):ir(e,n[0],t,r)}var $e=/^key(down|up|press)\.([a-z]+\+)*(delete|backspace)$/;function yn(e,t){let{shortcut:r,key:n}=e.params??{};return r!=null&&!De(r,e,t)||n!=null&&!M(String(n),e,t)}function vn(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:Xe(t),legacy:!0}];let r=[];for(let n of t.split(" ")){if(n==="")continue;let i=null;try{i=JSON.parse(n)}catch{i=null}if(i&&typeof i==="object"&&!Array.isArray(i))r.push(i);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(n)} — skipped`)}return r}function Fe(e,t,r){if(e.legacy)return!0;let n=e.on;if(typeof n!=="string"||n==="")return!1;let i=/^key(down|up|press)\./.test(n)?n.indexOf("."):-1;if(t.type!==(i<0?n:n.slice(0,i)))return!1;if(Boolean(e.window)!==et(t.currentTarget))return!1;return i<0||r===null&&!$e.test(n)||M(n.slice(i+1),t,r)}function wn(e,t){let r=e.detail;if(r===void 0)return!0;if(r===null||typeof r!=="object"||Array.isArray(r))return!1;let n=t.detail;if(n===null||typeof n!=="object")return!1;return Object.keys(r).every((i)=>n[i]===r[i])}var At=new WeakMap;function An(e,t,r){if(!r.once)return!1;let n=t.currentTarget??e.element,i=At.get(e);if(!i)i=new WeakMap,At.set(e,i);let o=i.get(n);if(!o)o=new Set,i.set(n,o);let s=(n===globalThis.window?`${sr(t.params?.ops)}|`:"")+JSON.stringify(r);if(o.has(s))return!0;return o.add(s),!1}var _t=new WeakMap,sr=(e)=>typeof e==="string"?e:JSON.stringify(e??null);function _n(e,t){if(e===null||typeof e!=="object")return!1;let r=sr(e.params?.ops),n=_t.get(e);if(!n)n=new WeakMap,_t.set(e,n);let i=n.get(t);if(!i)i=new Map,n.set(t,i);let o=i.get(e.currentTarget);if(!o)o=new Set,i.set(e.currentTarget,o);if(o.has(r))return!0;return o.add(r),!1}var Sn=new Set(["click","focus","focus_first"]);function qe(e,t,r){for(let n of e){if(!Array.isArray(n))continue;let[i,o={}]=n;if(!Object.hasOwn(gt,i)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(i)} — skipped`);continue}let a=t(o);if(a.length===0&&r)r(i,o);if(a.length>1&&Sn.has(i))a=a.slice(0,1);if(a.length>0)o=Tn(i,o,t,r);if(!o)continue;for(let s of a)if(gt[i](s,o,t),o?.keep===!0)Lt(s,i,o,t)}}var En=new Set(["set_value","text","set_attr"]);function Tn(e,t,r,n){let i=e==="dispatch",o=i?t.detail_from:En.has(e)&&t.from!=null&&{value:t.attr};if(!o||i&&!Object.keys(o).length)return t;let a=i?t.detail??{}:{};if(typeof a!="object"||Array.isArray(a))return console.warn(`[phlex-reactive] refused client read over detail ${JSON.stringify(a)} — skipped`),null;let s=i?"@trigger":t.from,c;try{c=r({...t,to:s})[0]}catch{}if(!c)return n?.(e,{...t,to:s}),null;let u={...a};for(let[d,f]of Object.entries(o)){let h=kn(c,f);if(h==null)return null;u[d]=h}return i?{...t,detail:u}:{...t,...u}}function kn(e,t){if(t==="@text")return e.textContent??"";if(typeof t==="string"&&/^data-[a-z][a-z0-9-]*$/i.test(t))return e.getAttribute(t)??"";return console.warn(`[phlex-reactive] refused client read of ${JSON.stringify(t)} — skipped`),null}function Fn(e,t){let r=e.to;if(r==="@trigger")return[];if(t){if(r==="@root")return[t];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...t.querySelectorAll(r)]}if(typeof r!=="string"||r===""||r==="@root")return[];return[...document.querySelectorAll(r)]}function Rn(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Ze(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var x='[data-controller~="reactive"]',Nn='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',We=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Ze(e);function W(e,t,r){let n=e?.closest?.(t);while(n&&n!==r&&We(n))n=n.parentElement?.closest?.(t);return n??null}var O=new WeakMap,Re=new Set,Z=new WeakMap;function Ln(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 xn(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], [data-reactive-listnav-highlight-param]")!=null}function On(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function In(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Pn(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 ar(e){return e.getAttribute?.("data-reactive-presence")!=null}function Mn(e){return e.getAttribute?.("data-reactive-subscribe")!=null}function Cn(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}var Dn=[["persist",[Rn,null,null,!0]],["defer",[Ze,null]],["form",[Ln,null]],["bindings",[xn,null,null,!0]],["compute",[On,null,null,!0]],["sortable",[In,null]],["drag",[Pn,null]],["presence",[ar,null]],["subscribe",[Mn,null]],["countdown",[Cn,null]],["effects",[(e)=>["enter","update","exit"].some((t)=>e.getAttribute?.(`data-reactive-effect-${t}`)!=null),null]],["hints",[(e)=>e.querySelector?.("[data-reactive-optimistic-param], [data-reactive-busy-param], [data-reactive-loading-param]")!=null,null]],["devtools",[(e)=>e.getAttribute?.("data-reactive-debug")==="true",null]]],_=new Map(Dn),St=new Map,g=new Map,$n=new Map;function y(e,t,r){cr.set(e,[t,r]),qn(e)}var cr=new Map;function qn(e){let t=_.get(e),[r,n]=cr.get(e);t[1]=r,t[2]=n}function ai(e,t){t.install?.(H),g.set(e,t),$n.set(e,t)}function ur(e){let t=[];for(let[r,[n]]of _){if(!n||g.has(r))continue;try{if(e.some((i)=>n(i)))t.push(r)}catch{}}return t}function lr(e){return J(e).catch((t)=>fe(e,"load",t))}function J(e){let t=St.get(e);if(!t)t=(_.get(e)[1]??(()=>Promise.reject(Error("this entry has no way to import it"))))().then((n)=>(n.install?.(H),g.set(e,n),n)),St.set(e,t);return t}var Et=new Set;function fe(e,t,r){let n=e+t;if(Et.has(n))return;Et.add(n),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,r)}function w(e,t){let r=g.get(e);if(r)return t(r);J(e).then(t,(n)=>fe(e,"load",n))}var Wn=1e4;function Ne(){let e=Number(globalThis.document?.head?.querySelector?.('meta[name="phlex-reactive-feature-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:Wn}function ci(){return[..._.keys()]}var Tt=Promise.resolve();function kt(e,t,r){let n=H.waiting.get(e);if(n&&n[t]===r)delete n[t]}var H={enter:Wt,exit:Bt,fail:B,count:Vt,text:R,served:Ye,waiting:new WeakMap};var C=Symbol.for("phlex-reactive.early"),Bn=1e4,jn=1500,et=(e)=>e!=null&&(e===globalThis.window||e.window===e),Un="dispatch";function ie(){return globalThis[C]??={queue:[],connected:new WeakSet},globalThis[C]}function Kn(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Bn}function Jn(e){let t={};for(let{name:r,value:n}of Array.from(e.attributes??[])){let i=/^data-reactive-(.+)-param$/i.exec(r);if(!i)continue;let o;try{o=JSON.parse(n)}catch{o=n}t[i[1].replace(/[-_]([a-z0-9])/g,(a,s)=>s.toUpperCase())]=o}return t}function zn(e,t,r){return{[C]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:r?t.ownerDocument.defaultView:t,params:Jn(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&&!Qe().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var he=new WeakMap;function Hn(e,{token:t,type:r,method:n,filter:i,win:o},a){let s=he.get(e);if(!s)he.set(e,s=new Map);let c=o?`${t} ${a}`:t;if(s.has(c))return!1;return s.set(c,{type:r,method:n,filter:i,win:o,params:a,armed:!0}),!0}function Ft(e,t,r,n){if(e?.[C])return!1;let i=et(e?.currentTarget),o=i?n:e?.currentTarget,a=i&&JSON.stringify(e.params),s=Gn(e,o,i?`@${t}${a}`:t),c=he.get(o);for(let u of c?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==i)continue;if(i&&u.params!==a)continue;if(u.filter&&!M(u.filter,e,r))continue;return u.armed=!1,!0}return s}var oe=new WeakMap;function Rt(e,t,r){let n=oe.get(e);if(!n)oe.set(e,n=new Map),setTimeout(()=>oe.delete(e));let i=n.get(t)??{};n.set(t,i),i[r]=(i[r]??0)+1}function Gn(e,t,r){let n=e&&oe.get(e)?.get(t);if(!n?.[r])return!1;return n[r]-=1,!0}class dr extends hr{static values={token:String};#E;#a=new Map;#h=new Map;#de;#fe;#K;#O=0;#m=new Map;#I=new WeakMap;#r;featuresReady=Tt;#n=new Map;#P=new Set;#p=!1;#i=null;#g=new Map;#T=new Map;#b=new Map;#y=0;#J;#Ye=0;#Xe=0;connect(){if(Xt=!0,ie().connected.add(this.element),O.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||Ze(this.element))this.#r=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===ee)this.#G();this.#z(!0)},this.element.addEventListener?.("turbo:morph-element",this.#r),this.element.addEventListener?.("focusin",this.#r),this.element.addEventListener?.(ee,this.#r);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(Ve),this.#y++,this.featuresReady=Tt,this.#z(),se(this.element),this.#ge()}#Qe(e){}#Ze(e,t,r,n){}#et(){}#tt(e,t){}#z(e){{let t=this.#y,r=[];for(let[o,[a]]of _){if(!a||this.#P.has(o))continue;let s=g.get(o);if(s&&!s.connect)continue;try{if(a(this.element))r.push(o)}catch(c){this.#v(o,"detect",c)}}if(r.length===0)return;for(let o of r)this.#P.add(o);if(!this.#p&&r.every((o)=>g.has(o))){for(let o of r)this.#M(t,o,g.get(o),e);return}for(let o of r){let a=this.#he(t,o),s=[];for(let u of _.keys()){if(u===o)break;if(this.#b.has(u))s.push(this.#b.get(u))}let c=Promise.all(s).then(()=>a).then((u)=>u&&this.#M(t,o,u,e));if(this.#b.set(o,c),_.get(o)[3])this.#i=c}let n=this.#i;n?.then(()=>{if(this.#i===n)this.#i=null}),this.#p=!0;let i=Promise.all(this.#b.values()).then(()=>{if(this.featuresReady===i)this.#p=!1});this.featuresReady=i}}#he(e,t){{let r=()=>e===this.#y;return this.#me(t),new Promise((n)=>{let i=!1,o=setTimeout(()=>{if(this.#g.delete(o),i=!0,r())this.#v(t,"timeout",Error(`not loaded after ${Ne()} ms`));n(null)},Ne());this.#g.set(o,n);let a=()=>{clearTimeout(o),this.#g.delete(o)};J(t).then((s)=>{if(a(),i)queueMicrotask(()=>this.#M(e,t,s));else n(s)},(s)=>{if(a(),r())this.#v(t,"load",s);n(null)})})}}#me(e){{let t=_.get(e)[2];if(!t)return;let r={};try{this.#T.set(e,[t(this.element,r),r]),H.waiting.set(this.element,{...H.waiting.get(this.element),[e]:r})}catch(n){this.#v(e,"detect",n)}}}#H(e,t){{let[r,n]=this.#T.get(e)??[];if(this.#T.delete(e),!t)kt(this.element,e,n);try{r?.()}catch(i){console.error(`[phlex-reactive] the "${e}" feature module failed to stop waiting`,i)}return n}}#M(e,t,r,n){{if(e!==this.#y)return;let i=this.#H(t);try{r.connect?.(this,this.#e(),n,i),this.#n.set(t,r)}catch(o){this.#v(t,"connect",o)}}}#e(){return this.#J??={emit:(e,t,r)=>this.#s(e,t,r),reseed:()=>this.#G(),proceed:(e,t,r,n)=>this.#$(e,t,r,0,0,null,n),forgetToken:()=>{this.#E=void 0},owns:(e)=>this.#l(e),ownership:()=>this.#W(),bindingOwns:(e)=>this.#se(e),bindingOwnership:()=>this.#De(),opTargets:(e)=>this.#U(e),diagnose:(e,t)=>this.#j(e,t),applyOps:(e,t)=>qe(e,(r)=>this.#U(t!=null&&r.to==null?{...r,to:t}:r),(r,n)=>this.#j(`client op "${r}"`,n)),listnavOptions:(e)=>this.#A(e),syncListnav:()=>this.#Ee(),collectFields:()=>this.#ae(),plain:Ct,text:R,served:Ye,copyMedia:rr,setValue:tr,confirm:(e,t)=>Promise.resolve().then(()=>tt(e,t)).catch(()=>!1)},this.#J}#G(){this.#n.get("form")?.reseed(this),this.#n.get("bindings")?.reseed(this),this.#n.get("compute")?.seed(this)}#v(e,t,r){if(fe(e,t,r),this.#t("feature"),B({kind:"feature",root:this.element.id}),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:r})}#pe(){{this.#y++;for(let[t,r]of this.#g)clearTimeout(t),r(null);this.#g.clear();for(let t of[...this.#T.keys()]){let r=this.#H(t,!0),n=this.element;w(t,(i)=>{i.abandon?.(n,r),kt(n,t,r)})}this.#P.clear(),this.#b.clear(),this.#p=!1,this.#i=null;let e=[...this.#n];this.#n.clear();for(let[t,r]of e)try{r.disconnect?.(this,this.#e())}catch(n){console.error(`[phlex-reactive] the "${t}" feature module failed to disconnect`,n)}}}#ge(){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.#be();for(let[e,t]of Z.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}Z.delete(this.element)}#C=new Set;#be(){let{queue:e}=ie();if(e.length===0)return;let t=[];for(let i=e.length-1;i>=0;i--){let{root:o}=e[i];if(o===this.element||!o.isConnected)t.unshift(...e.splice(i,1))}let r=Kn(),n=new Map;for(let i of t){let o=n.get(i.event)??[new Set,new Set];n.set(i.event,o);let a=o[+!!i.win];if(a.has(i.el))continue;a.add(i.el);let s=i.win?Math.min(jn,r):r,c=i.root!==this.element?"its root left the page before a controller connected":performance.now()-i.at>s?`it is older than the ${s} ms ${i.win?"window-trigger":"early-event"} TTL`:i.el.isConnected&&this.element.contains(i.el)?null:"its element left the root before the controller connected";if(c){if(this.#L())console.warn(`[phlex-reactive] dropped an early "${i.event.type}" trigger: ${c}`);continue}this.#ye(i)}}#ye({event:e,el:t,descs:r,win:n}){let i=zn(e,t,n),o=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),s=n?this.element:t,c=n?JSON.stringify(i.params):"",u=n?`@runOps${c}`:"runOps",d=!1;for(let f of r){if(!a.includes(f.token))continue;if(f.filter&&!M(f.filter,e,o))continue;if(/#\w+.*:once\b/.test(f.token)){if(!Hn(s,f,n&&JSON.stringify(i.params)))continue;this.#C.add(s)}if(f.method==="runOps")d=!0,this.runOps(i);else Rt(e,s,n?`@dispatch${c}`:"dispatch"),this.dispatch(i)}if(d)for(let f of a){let h=/^(?:(key(?:down|up|press))(?:\.([\w+]+))?|([^@>]+))(@window)?->reactive#runOps/.exec(f);if(h&&(h[1]??h[3])===e.type&&!!h[4]===!!n&&(!h[2]||M(h[2],e,o)))Rt(e,s,u)}}disconnect(){if(this.#pe(),this.#Re(),this.#Le(),this.#r)this.element.removeEventListener?.("turbo:morph-element",this.#r),this.element.removeEventListener?.("focusin",this.#r),this.element.removeEventListener?.(ee,this.#r);if(ie().connected.delete(this.element),O.get(this.element)===this)O.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#C)he.delete(e);this.#C.clear()}dispatch(e){if(yn(e,this.application?.schema?.keyMappings))return;if(e.params?.action&&e.params.action!==lt&&this.#ve())return this.#we(e);let t=e.params?.shortcut;if(Ft(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:r,params:n,debounce:i,throttle:o,confirm:a,confirmWhen:s,outside:c,window:u,optimistic:d,prevent:f,awaitSettled:h}=e.params;if(!r)return;let p=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let b=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#ue(d,b))Te(e,t);if(r===lt){let L=()=>{{let m=this.#n.get("defer");if(m)return m.materialize(this)}if(this.tokenValue)return this.#$(b,r,"{}")};return this.#p?this.featuresReady.then(L):L()}let T=this.#V(a,s),N=()=>this.#$(b,r,n,i,o,d,p,h);if(!T)return N();if(T instanceof Promise)return T.then((L)=>L?this.#k(L,b,N):N());this.#k(T,b,N)}#k(e,t,r){return Promise.resolve().then(()=>tt(e,{el:t})).catch(()=>!1).then((n)=>{if(n)r()})}#V(e,t){if(e)return e;if(!t)return null;{let r=g.get("bindings");if(r)return r.confirmMessage(this,this.#e(),t);return this.#Y("bindings").then((n)=>n&&n.confirmMessage(this,this.#e(),t))}}#Y(e){{let t;return Promise.race([J(e).catch((r)=>(fe(e,"load",r),null)),new Promise((r)=>t=setTimeout(()=>r(null),Ne()))]).finally(()=>clearTimeout(t))}}#ve(){return!this.tokenValue&&We(this.element)}#we(e){let t=W(this.element.parentElement,Nn);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 r=O.get(t);if(r)return r.dispatch(e);let{shortcut:n,window:i,optimistic:o,prevent:a}=e.params,s=e.currentTarget??e.target;if((n!=null||!i&&a!==!1)&&!this.#ue(o,s))Te(e,n);Z.set(t,[...Z.get(t)??[],[e,s]]);let c=t.dataset;if(c.reactiveDormant)c.controller=`${c.controller??""} ${c.reactiveDormant}`.trim(),delete c.reactiveDormant}runOps(e){let t=e.params?.ops;if(t?.shortcut!=null&&!De(t.shortcut,e,this.application?.schema?.keyMappings))return;if($e.test(t?.on)&&!Fe(t,e,this.application?.schema?.keyMappings))return;if(Ft(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(_n(e,this))return;let r=e.params??{},n=e.currentTarget??e.target,i=vn(r.ops),o=i.some((c)=>$e.test(c.on)),a=i.filter((c)=>Fe(c,e,null)),s=a.length<=1&&!o?a:a.filter((c)=>Fe(c,e,this.application?.schema?.keyMappings));if(s.length===0&&i.length>0){if(this.#L()&&!o)this.#S((c)=>c.noBinding(this,e));return}for(let c of s){if(c.outside&&e[C])continue;if(!wn(c,e))continue;let u=c.within==null?n:this.#Ae(c.within,e);if(c.within!=null&&!u)continue;if(c.shortcut!=null&&!De(c.shortcut,e,this.application?.schema?.keyMappings))continue;if(An(this,e,c))continue;this.#_e(c.legacy?{...r,ops:c.ops,debounce:void 0,throttle:void 0,prevent:void 0}:c,e,u,i.indexOf(c),n)}}#Ae(e,t){let r=t.currentTarget,n=null;try{n=t.target?.closest?.(e)}catch{if(this.#L())console.warn(`[phlex-reactive] on_client within: ${JSON.stringify(e)} is not a selector — nothing ran`)}return n&&n!==r&&r?.contains?.(n)&&this.#l(n)?n:null}#_e(e,t,r,n,i=r){let{ops:o,confirm:a,confirmWhen:s,outside:c,window:u,shortcut:d,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(d!=null||!u&&f!==!1)Te(t,d);let h=this.#V(a,s),p=this.#Se(e,n,i,()=>this.#Ue(this.#je(o),r));if(!h)return p();if(h instanceof Promise)return h.then((b)=>b?this.#k(b,r,p):p());this.#k(h,r,p)}#Se(e,t,r,n){let i=Number(e.debounce)||0,o=Number(e.throttle)||0;if(i<=0&&o<=0)return n;let a=JSON.stringify([t,e]);if(i>0)return()=>this.#ee(r,a,i,n);return()=>this.#ne(r,a,o,n)}recompute(e){return g.get("compute")?.recompute(this,this.#e(),e)}tagsAdd(e){if(e?.defaultPrevented||Y(e))return;if(this.#A(e).some((t)=>t.hasAttribute?.("data-reactive-highlighted")))return;return this.#w("tagsAdd",e)}tagsPick(e){return this.#w("tagsPick",e)}tagsRemove(e){return this.#w("tagsRemove",e)}nestedAdd(e){return this.#w("nestedAdd",e)}nestedRemove(e){return this.#w("nestedRemove",e)}syncNestedJson(e){return g.get("bindings")?.syncNestedJson(this,this.#e(),e)}#w(e,t){{let r=g.get("bindings");if(r)return r[e](this,this.#e(),t);t?.preventDefault?.();let n={currentTarget:t?.currentTarget??null,target:t?.target??null,preventDefault(){}};return w("bindings",(i)=>i[e](this,this.#e(),n))}}trackDirty(){(this.#n.get("form")??g.get("form"))?.scan(this,this.#e())}listnavNext(e){this.#F(e,(t,r)=>t<0?0:(t+1)%r)}listnavPrev(e){this.#F(e,(t,r)=>t<0?r-1:(t-1+r)%r)}listnavFirst(e){if(!this.#Q(e))this.#F(e,()=>0)}listnavLast(e){if(!this.#Q(e))this.#F(e,(t,r)=>r-1)}listnavPick(e){if(Y(e))return;let t=()=>this.#A(e).find((n)=>n.hasAttribute("data-reactive-highlighted")),r=t();if(!r&&this.#o(e).getAttribute?.("data-reactive-listnav-highlight-param")==="first")this.#Z(this.#o(e)),r=t();if(!r)return;if(e.preventDefault(),e.metaKey||e.ctrlKey)r.dispatchEvent(new MouseEvent("click",{metaKey:e.metaKey,ctrlKey:e.ctrlKey,bubbles:!0,cancelable:!0}));else r.click()}listnavClose(e){if(Y(e))return;this.#D(this.#o(e),this.#R(e))}#F(e,t){let r=this.#R(e),n=this.#A(e,r);if(!n.length||Y(e))return;e.preventDefault();let i=this.#X(e),o=globalThis.document?.activeElement,a=i?n.findIndex((c)=>c===o||o!=null&&c.contains?.(o)):n.findIndex((c)=>c.hasAttribute("data-reactive-highlighted")),s=n[t(a,n.length)];if(i)s.focus?.();else this.#D(this.#o(e),r,s);s.scrollIntoView?.({block:"nearest"})}#o(e){return e?.currentTarget??e?.target??this.element}#X(e){return this.#o(e).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#Q(e){return!this.#X(e)&&!e.ctrlKey&&!!this.#o(e).value}#D(e,t,r){let n=e.getAttribute?.("data-reactive-listnav-highlight-param")==="first";for(let i of t){if(i===r)continue;if(i.hasAttribute("data-reactive-highlighted"))i.removeAttribute("data-reactive-highlighted");if(n&&i.hasAttribute("data-reactive-aria-selected"))i.removeAttribute("aria-selected"),i.removeAttribute("data-reactive-aria-selected")}if(r?.setAttribute("data-reactive-highlighted","true"),!n)return;if(!r)return e.removeAttribute("aria-activedescendant");if(!r.hasAttribute("aria-selected"))r.setAttribute("aria-selected","true"),r.setAttribute("data-reactive-aria-selected","");r.id||=`reactive-option-${++wr}`,e.setAttribute("aria-activedescendant",r.id)}#Ee(){if(!this.element.querySelector?.('[data-reactive-listnav-highlight-param="first"]'))return;let t=this.#W();for(let r of this.element.querySelectorAll('[data-reactive-listnav-highlight-param="first"]'))if(t(r))this.#Z(r)}#Z(e){let t={currentTarget:e},r=this.#R(t),n=this.#A(t,r),i=e.value??"",o=n.find((a)=>a.hasAttribute("data-reactive-highlighted"));if(be.has(e)&&be.get(e)!==i)o=void 0;be.set(e,i),this.#D(e,r,o??n[0])}#A(e,t=this.#R(e)){let r=this.element;return t.filter((n)=>{for(let i=n;i;i=i===r?null:i.parentElement)if(i.hidden)return!1;return!0})}#R(e){let r=this.#o(e).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!r)return[];return Array.from(this.element.querySelectorAll(r)).filter(this.#W())}#$(e,t,r,n,i,o,a,s){if(this.#s("reactive:before-dispatch",{action:t,params:this.#ce(r),element:this.element},{cancelable:!0}).defaultPrevented)return;if(s&&!pe())return this.#Te(t,r,e,(f)=>f.#_(t,r,o,e,a));let u=Number(n)||0;if(u>0)return this.#Fe(e,u,t,r,o,a);let d=Number(i)||0;if(d>0)return this.#Ne(e,d,t,r,o,a);return this.#_(t,r,o,e,a)}#Te(e,t,r,n){let i=this.element.id,o=`${ce}\x00${i}\x00${e}\x00${typeof t==="string"?t:JSON.stringify(t)}`;if(Re.has(o))return;let a=r?.nodeType===1?r:null,s=zt(this.#x(),(c)=>{Re.delete(o),a?.removeAttribute(j);let u=this.element.isConnected&&O.get(this.element)===this?this:i&&O.get(document.getElementById(i));if(c&&u)return n(u)});return Re.add(o),a?.setAttribute(j,""),s}#_(e,t,r,n,i){let o={inverse:null,undo:[],resurrect:null},a=this.#Ke(e,n,o),s=Boolean(r||i),c=(h)=>{if(!s||!h)return;let p=this.#e();if(o.inverse=h.optimistic(this,p,r,n),o.undo.push(...h.busy(this,p,i,n)),this.#q())o.resurrect=h.resurrection(this,p,r,n)},u=g.get("hints");if(!s||u)c(u);let d=()=>this.#Pe(e,t,o,a),f=()=>this.#i?this.#i.then(d):d();return this.queue=(this.queue??Promise.resolve()).then(()=>s&&!u?this.#ke().then(c).then(f):f()),this.queue}#ke(){return this.#Y("hints")}#Fe(e,t,r,n,i,o){this.#ee(e,Un,t,()=>this.#_(r,n,i,e,o))}#ee(e,t,r,n){let i=this.#a.get(e)?.get(t),o=()=>{this.#re(e,t),n()},a=setTimeout(o,r);if(!et(e))e?.addEventListener?.("blur",o,{once:!0});let s=this.#a.get(e);if(!s)this.#a.set(e,s=new Map);if(s.set(t,{timer:a,flush:o}),$r(o),i)this.#te(e,i)}#te(e,t){clearTimeout(t.timer),e?.removeEventListener?.("blur",t.flush),qr(t.flush)}#re(e,t){let r=this.#a.get(e),n=r?.get(t);if(!n)return;if(this.#te(e,n),r.delete(t),r.size===0)this.#a.delete(e)}#Re(){for(let[e,t]of[...this.#a])for(let r of[...t.keys()])this.#re(e,r)}#Ne(e,t,r,n,i,o){return this.#ne(e,r,t,()=>this.#_(r,n,i,e,o))}#ne(e,t,r,n){let i=this.#h.get(e)??new Map;if(i.has(t))return;let o=setTimeout(()=>{if(i.delete(t),i.size===0)this.#h.delete(e)},r);return i.set(t,o),this.#h.set(e,i),n()}#Le(){for(let e of this.#h.values())for(let t of e.values())clearTimeout(t);this.#h.clear()}#s(e,t,{cancelable:r=!1}={}){let n=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:r,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(n),n}#c(e,t,r,n){let i=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#_(e,t)};B({action:e,kind:n.kind,status:n.status,root:this.element.id}),this.#s("reactive:error",{action:e,params:r,...n,retry:i})}#t(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#xe(){this.element?.removeAttribute?.("data-reactive-error")}#Oe(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",r=document.getElementById(t);if(!r)return;r.appendChild(e.content.cloneNode(!0))}#Ie(){{let e=g.get("devtools");if(e)return e.delay();if($t())return J("devtools").then((t)=>t.delay(),()=>{})}}#q(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#ie(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#Pe(e,t,r,n){let{fields:i,files:o}=this.#ae(),a=this.#ce(t),s={...i,...a},c=this.#u,u=o.length>0,d=u?this.#We(c,e,s,o):JSON.stringify({token:c,act:e,params:s}),f=this.#q()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(i),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#ie()}:null;await this.#Ie();try{if(navigator.onLine===!1){this.#d(r.inverse),this.#t("offline"),this.#c(e,t,s,{kind:"offline"});return}let h;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#Ge()};if(!u)m["Content-Type"]="application/json";let q=this.#Ve();if(q)m["X-Pgbus-Connection"]=q;let G=ar(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(G)m["X-Reactive-Presence"]=G;let V=xr(this.element);if(V)m["X-Reactive-Held"]=V;Vt("action"),h=await fetch(this.#He(),{method:"POST",headers:m,body:d,credentials:"same-origin",signal:AbortSignal.timeout(this.#x())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#d(r.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#t("timeout"),this.#c(e,t,s,{kind:"timeout"});return}this.#Oe(),this.#t("network"),this.#c(e,t,s,{kind:"network"});return}if(f)f.status=h.status;if(h.redirected){console.error("[phlex-reactive] action was redirected (auth/CSRF?) — no update applied"),this.#d(r.inverse),this.#t("redirected"),this.#c(e,t,s,{kind:"redirected",status:h.status});return}if(!h.ok){let m=await h.text();if(console.error(`[phlex-reactive] action failed: HTTP ${h.status}`,m),this.#d(r.inverse),(h.headers.get("Content-Type")||"").includes("turbo-stream")){let q=this.#oe(m);if(this.#u=q??this.#u,f)this.#S((V)=>V.recordBody(f,m,q));let G=ut(this.element,m,!0,this.#x());n?.handoff?.(),await G}this.#t("http"),this.#c(e,t,s,{kind:"http",status:h.status,body:m});return}let p=h.headers.get("Content-Type")||"";if(!p.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${p}" — no update applied`),this.#d(r.inverse),this.#t("content-type"),this.#c(e,t,s,{kind:"content-type",status:h.status});return}let b=await h.text(),T=this.#oe(b);if(this.#u=T??this.#u,f)this.#S((m)=>m.recordBody(f,b,T));let N=ut(this.element,b,Or(h),this.#x());if(r.resurrect)queueMicrotask(r.resurrect);if(this.#xe(),this.#s("reactive:applied",{action:e,params:s,html:b}),n?.handoff?.(),await N)this.#t("apply"),B({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:s,kind:"apply"});return b}catch(h){console.error("[phlex-reactive] action error",h),this.#d(r.inverse),this.#t("apply"),B({action:e,kind:"apply",root:this.element.id}),this.#s("reactive:error",{action:e,params:s,kind:"apply"})}finally{if(n?.(),f)this.#S((h)=>h.trace(this,{...f,ms:this.#ie()-f.started}))}}get#u(){return this.#E??this.tokenValue}set#u(e){this.#E=e}tokenValueChanged(){this.#E=void 0}#oe(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:r,self:n}=this.#Me(t),i=e.match(r);if(i)return i[1];let o=e.match(n);if(o)return o[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#Me(e){let t=this.#K;if(t&&t.id===e)return t;let r=Vr(e);return this.#K={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${r}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${r}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#l(e){return e.closest('[data-controller~="reactive"]')===this.element}#W(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#l(t)}#Ce(){let e=this.element.querySelectorAll(x);if(e.length===0||[...e].every(We))return()=>!0;return(t)=>{let r=W(t,x,this.element);if(r===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&W(r.parentElement,x,this.element)===this.element}}#se(e){if(this.#l(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=W(e,x,this.element);return t===this.element||W(t?.parentElement,x,this.element)===this.element}#De(){if(this.element.querySelectorAll(x).length===0)return()=>!0;return(e)=>this.#se(e)}#ae(){let e={},t=[],r=this.#Ce(),n=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((s)=>{if(!r(s))return;if(s.type==="file")for(let c of s.files??[])t.push({name:s.name,file:c,multiple:s.multiple});else n.push(s)});let i=[];this.element.querySelectorAll(`[name]${en}`).forEach((s)=>{if(r(s))i.push(s)});let o=this.#$e(n),a=this.#qe(n);for(let s of n)if(o.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 i.forEach((s)=>{let c=s.getAttribute("name");if(!c)return;let u=s.getAttribute("data-reactive-editable")!=null?R(s):s.value??s.textContent??s.innerHTML??"",d=e[c];if(String(c).endsWith("[]")&&!rn(s))return;if(String(c).endsWith("[]")&&(d===void 0||Array.isArray(d))){(Array.isArray(d)?d:e[c]=[]).push(u);return}if(d==null||d==="")e[c]=u}),{fields:e,files:t}}#$e(e){let t=new Set;for(let r of e){if(r.type==="radio")continue;if(String(r.name).endsWith("[]"))t.add(r.name)}return t}#qe(e){let t=new Set;for(let r of e)if(r.type==="checkbox")t.add(r.name);return t}#We(e,t,r,n){let i=new FormData;i.append("token",e),i.append("act",t);let o=[];for(let[s,c]of Object.entries(r))if(Array.isArray(c)&&String(s).endsWith("[]"))if(c.length===0)o.push(String(s).slice(0,-2));else{let u=`${this.#N(s)}[]`;for(let d of c)i.append(u,String(d))}else this.#B(i,this.#N(s),c);for(let s of o)i.append("empty_groups[]",s);let a=this.#Be(n);for(let{name:s,file:c,multiple:u}of n){let f=u||a.has(s)?`${this.#N(s)}[]`:this.#N(s);i.append(f,c,c.name)}return i}#N(e){let t=String(e),r=t.indexOf("[");if(r===-1)return`params[${t}]`;return`params${[t.slice(0,r),...t.slice(r).match(/[^\[\]]+/g)??[]].map((i)=>`[${i}]`).join("")}`}#B(e,t,r){if(r==null)e.append(t,"");else if(Array.isArray(r))r.forEach((n,i)=>this.#B(e,`${t}[${i}]`,n));else if(typeof r==="object")for(let[n,i]of Object.entries(r))this.#B(e,`${t}[${n}]`,i);else e.append(t,String(r))}#Be(e){let t=new Map;for(let{name:r}of e)t.set(r,(t.get(r)??0)+1);return new Set([...t].filter(([,r])=>r>1).map(([r])=>r))}#ce(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#je(e){return Xe(e)}#Ue(e,t){qe(e,(r)=>this.#U(r,t),(r,n)=>this.#j(`client op "${r}"`,n))}#L(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#q()}#j(e,t){if(!this.#L())return;this.#S((r)=>r.diagnose(this,e,t))}#S(e){w("devtools",e)}#U(e,t){let r=e.to;if(r==="@root")return[this.element];if(r==="@trigger")return t?.nodeType===1?[t]:[];if(typeof r!=="string"||r==="")return[];if(e.global)return[...document.querySelectorAll(r)];return[...this.element.querySelectorAll(r)].filter((n)=>this.#l(n))}#ue(e,t){if(e?.checked!=="keep")return!1;let r=t?.type;return r==="checkbox"||r==="radio"}#d(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Ke(e,t,r){this.#Je(e,t),Wt();let n=!1,i=!1,o=()=>{if(n)return;n=!0,this.#ze(e,t);for(let s of r.undo)s()},a=()=>{if(i)return;i=!0,o(),Bt()};return a.handoff=o,a}#Je(e,t){if(this.#f(t,e,1),this.#f(this.element,e,1),this.#m.set(e,(this.#m.get(e)??0)+1),this.#O++===0)this.element.setAttribute("aria-busy","true");for(let r of this.#le(e))this.#f(r,e,1)}#ze(e,t){this.#f(t,e,-1),this.#f(this.element,e,-1);let r=(this.#m.get(e)??1)-1;if(r<=0)this.#m.delete(e);else this.#m.set(e,r);if(--this.#O<=0)this.#O=0,this.element.removeAttribute("aria-busy");for(let n of this.#le(e))this.#f(n,e,-1)}#f(e,t,r){if(!e||typeof e.getAttribute!=="function")return;let n=this.#I.get(e)??new Map,i=(n.get(t)??0)+r;if(i<=0)n.delete(t);else n.set(t,i);if(n.size===0){this.#I.delete(e),e.removeAttribute("data-reactive-busy");return}this.#I.set(e,n),e.setAttribute("data-reactive-busy",[...n.keys()].join(" "))}#le(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((r)=>r.getAttribute("data-reactive-busy-on")===e&&this.#l(r))}#He(){return this.#de??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#x(){return this.#fe??=Jt()}#Ge(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Ve(){let e=this.element.getAttribute?.("data-reactive-subscribe"),t;if(e){for(let r of document.querySelectorAll("pgbus-stream-source[data-reactive-subscribe-source][connection-id]"))if(r.getAttribute("src")===e)t=r.getAttribute("connection-id")}return t||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)pt();else document.addEventListener("turbo:load",pt,{once:!0});y("persist",()=>import("phlex/reactive/features/persist"),Vn);y("defer",()=>import("phlex/reactive/features/defer"));y("form",()=>import("phlex/reactive/features/form"));y("bindings",()=>import("phlex/reactive/features/bindings"));y("compute",()=>import("phlex/reactive/features/compute"),Yn);y("sortable",()=>import("phlex/reactive/features/sortable"));y("drag",()=>import("phlex/reactive/features/drag"));y("presence",()=>import("phlex/reactive/features/presence"));y("subscribe",()=>import("phlex/reactive/features/subscribe"));y("countdown",()=>import("phlex/reactive/features/countdown"));y("effects",()=>import("phlex/reactive/features/effects"));y("hints",()=>import("phlex/reactive/features/hints"));y("devtools",()=>import("phlex/reactive/features/devtools"));Ge();function Vn(e,t){let r=()=>{t.edited=!0},n=(o)=>{let a=o.target;if(o.detail?.success&&a?.tagName==="FORM"&&a.contains?.(e))t.submitted=!0},i=["input","change","lexxy:change","trix-change"];for(let o of i)e.addEventListener?.(o,r);return document.addEventListener("turbo:submit-end",n),()=>{for(let o of i)e.removeEventListener?.(o,r);document.removeEventListener("turbo:submit-end",n)}}function Yn(e,t){let r=()=>{t.edited=!0};return e.addEventListener?.("input",r),e.addEventListener?.("change",r),()=>{e.removeEventListener?.("input",r),e.removeEventListener?.("change",r)}}var Xn=1000,D=null,fr,ge=new Set;function Qn(e){return lr(e).then((t)=>{if(e!=="effects")return;fr=t,t?.sweep()})}Mt((e,t)=>{let r=e.detail,n=r?.render;if(typeof n!=="function")return;let i=r.newStream??e.target,o=ur(Zn(i)).filter((s)=>!ge.has(s));if(!t&&!ge.has("effects")&&ei(i))o.push("effects");if(o.length===0&&!D)return t?.wrap(e);if(o.length>0){for(let c of o)ge.add(c);let s=D=Promise.race([Promise.all([D,...o.map(Qn)]),new Promise((c)=>setTimeout(c,Xn))]).then(()=>{if(D!==s)return;D=null,ge.clear()})}let a=D;r.render=async(s)=>{await a;let c={target:e.target,detail:{newStream:r.newStream,render:n}};(t??fr)?.wrap(c),await c.detail.render(s)}});function Zn(e){let t=e?.querySelector?.("template")?.content;if(!t)return[];let r=[...t.querySelectorAll?.('[data-controller~="reactive"]')??[]];for(let n of t.children??[])if(n.matches?.('[data-controller~="reactive"]')&&!r.includes(n))r.unshift(n);return r.push(t),r}function ei(e){return Boolean(e?.hasAttribute?.("data-reactive-effect")||document.getElementById?.(e?.getAttribute?.("target"))?.matches?.("[data-reactive-effect-update],[data-reactive-effect-exit]")||e?.querySelector?.("template")?.content?.querySelector?.("[data-reactive-effect-enter],[data-reactive-dismiss-after]")||document.querySelector?.("[data-reactive-dismiss-after]:not([data-reactive-dismiss-scheduled])"))}var mi=dr;export{qt as ACTIVE_ATTR,en as EDITOR_SELECTOR,tn as EDITOR_TAGS,Pe as ERRORS_ATTR,Gt as REQUESTS_ATTR,Yr as checkReactiveRegistration,Vt as countReactiveRequest,mi as default,R as editableValue,Wt as enterReactiveActivity,Vr as escapeRegExp,Bt as exitReactiveActivity,Wr as flushReactiveDebounces,lr as loadReactiveFeature,Mt as onReactiveStreamWithoutEffects,ii as reactiveActivityCount,si as reactiveDebounceCount,ci as reactiveFeatureNames,Br as reactiveSettled,B as recordReactiveError,pt as registerReactiveActions,zr as registerReactiveAwaitSettled,yr as registerReactiveDefer,Ge as registerReactiveDev,vr as registerReactiveDismiss,vr as registerReactiveEffects,ai as registerReactiveFeature,y as registerReactiveFeatureLoader,kr as registerReactiveImageFallback,br as registerReactiveJs,Tr as registerReactiveKeep,Er as registerReactiveModals,Rr as registerReactiveMorphFocus,Mr as registerReactiveOffline,Fr as registerReactivePlaintext,cn as registerReactiveRejectedFiles,vr as registerReactiveStreamRender,pr as registerReactiveToken,mr as registerReactiveVisit,oi as resetReactiveActivity,Ye as serverText,ur as unloadedFeaturesFor};
|
|
7
7
|
|
|
8
|
-
//# debugId=
|
|
8
|
+
//# debugId=B02FA08AAA3572AF64756E2164756E21
|
|
9
9
|
//# sourceMappingURL=core.min.js.map
|