phlex-reactive 0.16.12 → 0.16.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f176f438a8cddf912348d8c6d0ddf095fa3a6fa1ae2b52b109a8be514a48139
4
- data.tar.gz: 49f4e78d5e21ea343fe5bfb6d77d1a3f58e3cb0d592a018536bc9ae52d5c827d
3
+ metadata.gz: 9162831f7b30044d33bd5819fb62c99ca6c8a2b00774d0addbce7cb44bb5d557
4
+ data.tar.gz: ce660a01d4baeb78132f43a5eab00f33d404cc9af6d0135e68e08404b399d1ad
5
5
  SHA512:
6
- metadata.gz: 6027a094e3dc14403d914c2f9406396b75fef0b4ea68615480b6d1c6a8e6e0b061c5f3e0df4b18ddc7e54642d54a0caf2490b5fe3d088b430864699106de6858
7
- data.tar.gz: 87dd2ef191e0faf521bd869defc0cf645ed25466d1abadfae1db9641f74a6d9c8a6e9ca015834f81a29492e1c14c43eccc21d580478151f6d0d00506fa1473bd
6
+ metadata.gz: 1d805f52e6ffa75afadef14d30f025bcdc9880e27aa0dbfce3eb1733b6ea5427aab120c82e8c95fa362ae3ba16eb721606bb17ea307f8e09b2a3b22e1c2d1c26
7
+ data.tar.gz: a55c772e79bbb8d2f9e11d9c0dbfb09e5ebd8b1c5f1d4105a29af9d09c44f476ff352a392390e6dcf02a24945b56a9bd9bbda498b8f222af62ce4edb6a6a5230
data/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
9
  ### Added
10
10
 
11
+ - **`js.click(to = :trigger)` (#471).** A client op that activates an element
12
+ the way a user click does: `HTMLElement#click()` on the first match, so a link
13
+ follows its `href` (through Turbo Drive, with its own `data-turbo-*`
14
+ attributes), a submit button submits its form and a checkbox toggles.
15
+ `js.dispatch("click")` sends a `CustomEvent`, which carries no activation. A
16
+ list row drawn as one link now answers Space with
17
+ `on_client("keydown.space", js.click)`. The server never pushes it:
18
+ `reply.js`, a settle's `js` and `broadcast_to(js:)` refuse it.
19
+ `on_client(:click, js.click)` on its own trigger raises at render (the
20
+ synthetic click re-enters its own binding, which prevents its default).
11
21
  - **`:strict_integer` and `:strict_float` param types (#460).** `:integer` and
12
22
  `:float` cast with `to_i`/`to_f`, so a cleared number field reaches the action
13
23
  as `0` and `"12abc"` as `12`, and an action cannot tell a blank field from a
@@ -19,9 +29,75 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
19
29
  as well as a string,
20
30
  and work in nested and array schemas, where a dropped element follows the
21
31
  existing array rule. `:integer` and `:float` are unchanged.
32
+ - **`reactive_nested_add(clear: :reset)` (#466).** `clear: true` empties every
33
+ fill-then-add source after an add, so a checkbox that renders ticked was
34
+ unticked for every row after the first. `clear: :reset` puts each source back
35
+ to what the server rendered, the way a form reset would: a checkbox to its
36
+ `checked` attribute, a text input or textarea to its `value`, a select to its
37
+ `selected` option (else a single select to its first enabled one; a multiple
38
+ select to exactly its `selected` options). Each reset source dispatches one
39
+ bubbling `input`, as `clear: true` does, and a source that several `from:`
40
+ keys name is cleared once. `clear: true` is otherwise unchanged.
41
+
42
+ ### Changed
43
+
44
+ - **BREAKING (minor release): `reactive_editable(on_enter:)` raises on an op
45
+ that names `:trigger` (#471).** The Enter runs its ops with no trigger element, so an op such as
46
+ `js.blur(:trigger)`, `js.add_class(:trigger, …)` or a bare `js.click` did
47
+ nothing; it now raises `ArgumentError` at render. Name the element with a
48
+ CSS selector.
49
+
50
+ - **`reactive_nested_add(clear:)` raises on an unknown value (#466).** It takes
51
+ `true`, `false`, `nil` or `:reset`; anything else (a truthy string such as
52
+ `clear: "yes"`, which used to act as `true`) now raises `ArgumentError` at
53
+ render. Pass `clear: true`.
54
+
55
+ - **`reactive:idle` reports what failed (#464).** Each busy window (from the
56
+ `reactive:busy` edge to the `reactive:idle` edge) collects every failure raised
57
+ inside it: a dispatch that failed (`http`, `timeout`, `network`, `offline`,
58
+ `redirected`, `content-type`, `apply`), a feature that could not load, a
59
+ deferred render that failed. `reactive:idle`'s detail gains
60
+ `errors: [{ action, kind, status, root }]` (`[]` after a clean window), and
61
+ when that list is not empty `<html data-reactive-errors>` holds it as JSON from
62
+ that idle edge until the next busy edge (a clean window leaves the attribute
63
+ absent). A stream of the reply that throws while Turbo renders it is listed as
64
+ `apply` too (after `reactive:applied`; the drawn rest of the reply is not
65
+ reverted). A render still running when the action timeout cuts the wait off
66
+ is not recorded.
67
+
68
+ ### Changed
69
+
70
+ - **BREAKING (minor release): `wait_for_reactive` raises when the round trip
71
+ failed (#464).** It used to return after a 500, a timeout or a redirect just as
72
+ after a rendered reply, and the next assertion failed a full Capybara wait
73
+ later with no word of the failure. It now raises
74
+ `Phlex::Reactive::TestHelpers::System::ReactiveReplyError`, naming each failed
75
+ action, kind and status (`reactive action "increment" failed (http 500) on
76
+ #flaky-counter`); `#errors` returns the list. A test that expects the failure
77
+ passes `wait_for_reactive(allow_error: true)`, which only waits, as in 0.16.
78
+ A failure a `reactive:error` listener retries stays in the window the retry
79
+ extends, so it is still listed even when the retry succeeds.
80
+ - **The next queued action starts after the previous reply is drawn (#464).** A
81
+ root's request queue used to move on as soon as Turbo had been handed the
82
+ reply's streams, a repaint before they rendered. It now waits for them, so a
83
+ queued action reads the DOM (and the token) the previous reply left. A non-OK
84
+ turbo-stream reply (an error flash) is drawn before its `data-reactive-error`
85
+ and `reactive:error`, so a listener sees the rendered error. The busy markers
86
+ and a busy hint's undo still revert when the reply is handed to Turbo, so an
87
+ in-place morph's server state (a trigger it renders disabled) still wins.
22
88
 
23
89
  ### Fixed
24
90
 
91
+ - **`reactive:idle` fired before the reply rendered (#464).** The dispatch lane
92
+ left the activity counter when the fetch settled, at least one animation frame
93
+ before Turbo applied the reply's streams, so a one-shot read after
94
+ `wait_for_reactive` could see the old DOM. It now leaves once every stream of
95
+ the root's own reply has rendered; a reply with no stream, or one whose render
96
+ a listener prevented, settles after one repaint, and a render that never
97
+ finishes is cut off at the action timeout so it cannot wedge the queue.
98
+ - **A client-side apply failure now marks the root (#464).** The `kind: "apply"`
99
+ error emitted `reactive:error` but never set `data-reactive-error`; it now sets
100
+ `data-reactive-error="apply"` like every other failure kind.
25
101
  - **The docs now say what `:integer` and `:float` do (#460).** The Actions &
26
102
  events guide and the counter example said a non-numeric value is dropped; it
27
103
  never was. Both pages, and the README, now describe `to_i`/`to_f` and point at
data/README.md CHANGED
@@ -689,7 +689,7 @@ Use in controllers: `render turbo_stream: Counter.replace(counter)`.
689
689
  | `on(:action, once: true)` | Fire at most once, then unbind (Stimulus's native `:once`). |
690
690
  | `on(:track, event: "drop", prevent: false)` | Keep the event's **native default** on an element-bound trigger: the client skips its `preventDefault`. See [Keep the native default](#keep-the-native-default--prevent-false). |
691
691
  | `on_client(:click, js.toggle("#menu"))` | **Client-only** trigger: applies declared DOM ops with ZERO round trip — no token, no POST, ever. Takes the same `window:`/`once:`/`outside:` modifiers, `debounce:`/`throttle:` waits (ms) and `prevent: false` as `on`, plus `detail:` (run only when `event.detail` carries the listed values). See [Client-only ops](#client-only-ops-on_client--js--zero-round-trips). |
692
- | `js` | The immutable op builder behind `on_client`: `show`/`hide`/`toggle` (the `hidden` attribute, with an optional `transition:` and `expanded:`), `add_class`/`remove_class`/`toggle_class`, `set_attr`/`remove_attr`/`toggle_attr` (allowlisted names; `toggle_attr` also flips between two values), `focus`/`focus_first`/`blur`, `show_modal`/`close_dialog` (a real modal `<dialog>`), `copy_media` (copy `src`/`srcset`/`alt` from a server-rendered `<img>`, no URL argument), `text` (set `textContent` — XSS-safe), `set_value` (set a field's live `.value` and dispatch `input`), `dispatch`, `submit` (requestSubmit the target's own form, optionally through a `submitter:`), `paste_into` (read the clipboard into a field, gesture-gated), `preview_file` (paint a chosen image file onto an `img` through an object URL the client makes and revokes), `check_group` (tick or untick a checkbox group, then re-sync its bindings), and `persist_state`/`persist_clear` (the `reactive_persist` draft) — chainable. `keep: true` on the visibility, class and attr ops makes their result survive a morph. |
692
+ | `js` | The immutable op builder behind `on_client`: `show`/`hide`/`toggle` (the `hidden` attribute, with an optional `transition:` and `expanded:`), `add_class`/`remove_class`/`toggle_class`, `set_attr`/`remove_attr`/`toggle_attr` (allowlisted names; `toggle_attr` also flips between two values), `focus`/`focus_first`/`blur`, `show_modal`/`close_dialog` (a real modal `<dialog>`), `copy_media` (copy `src`/`srcset`/`alt` from a server-rendered `<img>`, no URL argument), `text` (set `textContent` — XSS-safe), `set_value` (set a field's live `.value` and dispatch `input`), `dispatch`, `submit` (requestSubmit the target's own form, optionally through a `submitter:`), `click` (the browser's own activation of the first match: a link visits, a submit button submits; never server-pushed), `paste_into` (read the clipboard into a field, gesture-gated), `preview_file` (paint a chosen image file onto an `img` through an object URL the client makes and revokes), `check_group` (tick or untick a checkbox group, then re-sync its bindings), and `persist_state`/`persist_clear` (the `reactive_persist` draft) — chainable. `keep: true` on the visibility, class and attr ops makes their result survive a morph. |
693
693
  | `reactive_field(:param, **attrs)` | The attribute hash that binds a control to an action param (no magic `name:`) — spread onto any control: `input(**reactive_field(:value, value: @record.name))`, `select(**reactive_field(:status)) { … }`. |
694
694
  | `reactive_shared_field(name:, value: nil, **attrs)` | A control inside a **nested** component that its host's actions post too (#434): `input(type: "hidden", **reactive_shared_field(name: "item[choice]", value: @choice))`. Collected by its own component and by the next server component above it, one level only, and read by that host's client bindings (`reactive_show`, `disable: true`, `reactive_enable`, show targets, computes; #440); `name:` is the host's param, verbatim (never re-scoped); a blank name raises at render. See *Nested reactive components compose* below. |
695
695
  | `reactive_editable(:name, multiline: false, placeholder: nil, on_enter: nil, on_escape: :revert, spellcheck: true)` | A plain-text **editable element** as a field (issue #351): `h3(**reactive_editable(:title)) { @card.title }`. Its text travels under the scope-aware `name`: with `multiline: true` its line breaks are sent as `\n`; a single-line field (the default) folds them to spaces; a morph keeps the focused element's text and caret (attributes still morph); paste is plain text; Enter runs `on_enter:` (a single-line field swallows it); Escape reverts. `reactive_dirty` and `reactive_persist` treat it like an input. See the [Editable text](https://phlex-reactive.zoolutions.llc/docs/editable-text) page. |
@@ -714,7 +714,7 @@ Use in controllers: `render turbo_stream: Counter.replace(counter)`.
714
714
  | `reactive_dirty` / `reactive_dirty warn_unsaved: true` / `reactive_dirty only: %i[...]` | **Dirty tracking**, declared once at the class level, against the DOM's own `defaultValue`/`defaultChecked`/`defaultSelected` — no client state. Marks changed fields + the root `data-reactive-dirty`; `warn_unsaved:` arms a `beforeunload`/`turbo:before-visit` guard; `only:` scopes tracking to named fields. Style with `[data-reactive-dirty]`. See [Dirty-field tracking](#dirty-field-tracking-reactive_dirty). |
715
715
  | `nested_update!(:assoc, attrs)` | Map a nested param onto `<assoc>_attributes` with id preservation; update the record. |
716
716
  | `reactive_nested_list(:assoc, as: :attributes \| :json)` / `reactive_nested_template(:assoc)` / `reactive_nested_row` | **Draft nested-attribute rows** (the "new parent + child rows" form): the container rows land in, the `<template>` holding ONE row's markup, and the row wrapper marker — all **client-only** form state, keyed by association (several collections per root). `as: :json` (default `:attributes`) serializes the rows into ONE hidden JSON field instead of posting `accepts_nested_attributes_for` names — for an app whose controller `JSON.parse`s a serialized param; `name:` names that hidden field **verbatim** (`name: "order[todos]"`, never re-scoped — the form-builder escape hatch, JSON mode only). See [Draft rows for a new parent](#draft-rows-for-a-new-parent-reactive_nested_). |
717
- | `reactive_nested_add(:assoc, from:, clear:)` / `reactive_nested_remove(confirm:)` | The row triggers, client-only (zero round trips): add clones the template and renumbers its placeholder index; remove deletes a draft row from the DOM, or `_destroy`-marks + hides a persisted row (a hidden `[_destroy]` input present). **Fill-then-add**: `from: { row_field => "#source-selector" }` seeds the new row from add controls that live OUTSIDE it (a preset select, a typeahead), and `clear: true` resets them — composes with `as: :attributes` AND `as: :json`. **Confirm on remove**: `reactive_nested_remove(confirm: "Really delete this row?")` gates the remove behind the same overridable `confirmResolver` as `on`/`on_client` (a per-row string, or the conditional `{ when:, message: }` Hash). See [Draft rows for a new parent](#draft-rows-for-a-new-parent-reactive_nested_). |
717
+ | `reactive_nested_add(:assoc, from:, clear:)` / `reactive_nested_remove(confirm:)` | The row triggers, client-only (zero round trips): add clones the template and renumbers its placeholder index; remove deletes a draft row from the DOM, or `_destroy`-marks + hides a persisted row (a hidden `[_destroy]` input present). **Fill-then-add**: `from: { row_field => "#source-selector" }` seeds the new row from add controls that live OUTSIDE it (a preset select, a typeahead), and `clear: true` empties them (`clear: :reset` puts them back to their rendered defaults) — composes with `as: :attributes` AND `as: :json`. **Confirm on remove**: `reactive_nested_remove(confirm: "Really delete this row?")` gates the remove behind the same overridable `confirmResolver` as `on`/`on_client` (a per-row string, or the conditional `{ when:, message: }` Hash). See [Draft rows for a new parent](#draft-rows-for-a-new-parent-reactive_nested_). |
718
718
  | `nested_field_name(:assoc, :field, index: nil)` | The Rails `accepts_nested_attributes_for` wire name for one row field — `order[line_items_attributes][NEW_ROW][quantity]` (the template placeholder) by default, a real index when given. Scope-aware under `reactive_scope`; `scope:` overrides it **per call** (`scope: "order"`, verbatim — the form-builder escape hatch). |
719
719
  | `reactive_collection :name, item:, container:, count:, empty:, size:` | Declare an add/remove-row list once; actions call `reply.append`/`prepend`/`remove`. See [Reactive collections](#reactive-collections-addremove-rows--count--empty-state). |
720
720
  | `reply.replace` / `.morph` / `.update` / `.remove` / `.redirect(url)` / `.with(*)` / `.js(ops)` | Return from an action to control the reply (flash, remove, redirect, multi-stream, server-pushed client ops). See [Controlling the action's reply](#reply--controlling-the-actions-reply). |
@@ -1483,6 +1483,16 @@ button(**on_client(:click, js
1483
1483
  inside it, so Escape ends a menu's `:focus-within`
1484
1484
  (`on_client("keydown.esc", js.blur("#menu"))`); focus elsewhere on the page is
1485
1485
  left alone. Actor-only like focus: refused in broadcasts.
1486
+ - **`click(to = :trigger, global: false)`** (#471) calls `HTMLElement#click()`
1487
+ on the first match (`global: true` resolves the selector document-wide): the browser's own activation, so a link follows its `href` (through
1488
+ Turbo Drive, with its own `data-turbo-*` attributes), a submit button submits,
1489
+ a checkbox toggles — what `dispatch("click")`'s `CustomEvent` cannot do. A row
1490
+ link that answers Space: `on_client("keydown.space", js.click)`. The synthetic
1491
+ click bubbles, so a `:click` binding on the target or an ancestor prevents its
1492
+ default unless bound with `prevent: false`, and `on_client(:click, js.click)` on
1493
+ its own trigger raises at render. **Never server-pushed**: `reply.js`, a
1494
+ settle's `js` and `broadcast_to(js:)` all refuse it (use `reply.redirect` for a
1495
+ visit). A held key repeats its `keydown`, and each repeat clicks again.
1486
1496
  - **`show_modal(to)`** / **`close_dialog(to)`** (#365) call
1487
1497
  `HTMLDialogElement#showModal()` / `#close()`: the top layer, a focus trap,
1488
1498
  `::backdrop`, Escape to close and focus back on the opener — all the
@@ -3039,6 +3049,25 @@ still adds — never a throw). It composes with **both** wire modes: the seeded
3039
3049
  values ride the renumbered `_attributes` names on submit (`:attributes`) and the
3040
3050
  end-of-add JSON sync serializes them (`as: :json`), with no extra wiring.
3041
3051
 
3052
+ `clear: true` empties every source: a checkbox unticks, a text input or select
3053
+ goes to `""`. When a source renders a default the next entry should start from —
3054
+ a "gift wrap" box that is ticked by default, a quantity of `1`, a preselected
3055
+ option — pass `clear: :reset` instead: each source goes back to what the server
3056
+ rendered, the way a form reset would (a checkbox to its `checked`
3057
+ attribute, a text input or textarea to its `value`, a select to its `selected`
3058
+ option or, with none, a single select its first enabled one and a multiple
3059
+ select none), with the same dispatched `input`. Any other
3060
+ `clear:` value raises at render.
3061
+
3062
+ ```ruby
3063
+ input(id: "item-qty", type: "number", value: "1")
3064
+ input(id: "item-gift", type: "checkbox", checked: true)
3065
+
3066
+ button(**reactive_nested_add(:line_items,
3067
+ from: { quantity: "#item-qty", gift: "#item-gift" },
3068
+ clear: :reset)) { "Add item" } # after each add: quantity 1, gift ticked again
3069
+ ```
3070
+
3042
3071
  Relatedly, a **draft parent can now run real server actions too** (issue #208):
3043
3072
  an unsaved record signs a gid-less `{c, state}` token, and the endpoint rebuilds
3044
3073
  the component through the record kwarg's **initialize default** —
@@ -3579,11 +3608,12 @@ Notifications::Badge.broadcast_to(user, :alerts,
3579
3608
  ```
3580
3609
 
3581
3610
  `broadcast_to` with `js:` **refuses the actor-only ops** (`focus`/`focus_first`/`blur`/
3582
- `show_modal`/`close_dialog`/`submit`/`paste_into`/`preview_file`/`persist_state`/`persist_clear`/`check_group`/`set_value` raise
3611
+ `show_modal`/`close_dialog`/`submit`/`click`/`paste_into`/`preview_file`/`persist_state`/`persist_clear`/`check_group`/`set_value` raise
3583
3612
  `ArgumentError`): broadcasting focus (or a modal) would steal it in every subscriber's tab, a
3584
3613
  broadcast submit would force-submit every subscriber's form, and a broadcast
3585
3614
  clipboard read, draft write, selection change or field write would be hostile — these
3586
- belong to the actor's own reply or gesture. It refuses `keep: true` on any op
3615
+ belong to the actor's own reply or gesture (`click` to the gesture alone: `reply.js` refuses
3616
+ it too). It refuses `keep: true` on any op
3587
3617
  too (#369): kept state belongs to the tab that ran the op. Everything else is a fair broadcast
3588
3618
  (class and attribute toggles, `text`, `dispatch`). As with `on_client`, the ops are
3589
3619
  whitelist-interpreted client-side — an unknown op warns and is skipped — and the
@@ -3681,8 +3711,11 @@ is cleared, so it does not shimmer forever) while a `reactive_lazy(on:)` shell
3681
3711
  still loads through the plain action. The 10 s is
3682
3712
  `<meta name="phlex-reactive-feature-timeout" content="ms">` in `<head>`.
3683
3713
 
3684
- `apply` covers a throw in the controller's own post-fetch code — not a
3685
- throwing listener on `reactive:applied` itself. Per the DOM spec,
3714
+ `apply` covers a throw in the controller's own post-fetch code, and a stream of
3715
+ the root's own reply that throws while Turbo renders it — not a throwing
3716
+ listener on `reactive:applied` itself. The stream case comes a repaint after
3717
+ `reactive:applied`, so one round trip can fire both; the rest of the reply is
3718
+ already drawn, so nothing reverts. Per the DOM spec,
3686
3719
  `EventTarget#dispatchEvent` never propagates a listener's exception back to
3687
3720
  its caller (it's reported to the console instead), so a listener that throws
3688
3721
  can't surface as `reactive:error` at all — it just logs and the round trip is
@@ -4787,6 +4820,30 @@ find("#open-panel").click
4787
4820
  expect(page).to have_reactive_requests(1)
4788
4821
  ```
4789
4822
 
4823
+ `wait_for_reactive` returns once every reply is drawn, not when its fetch
4824
+ resolves, so a one-shot read right after it sees the morph. It also **raises**
4825
+ `Phlex::Reactive::TestHelpers::System::ReactiveReplyError` when the busy window
4826
+ it waited on had a failure (an HTTP error, a timeout, a redirect, a
4827
+ non-turbo-stream reply, a client-side apply error, a feature or deferred render
4828
+ that failed). The message names each one, e.g.
4829
+ `reactive action "increment" failed (http 500) on #flaky-counter`, and `#errors`
4830
+ returns the list. A failure that a `reactive:error` listener retries is still
4831
+ listed, even when the retry succeeds. Pass `allow_error: true` to a test that
4832
+ expects the failure:
4833
+
4834
+ ```ruby
4835
+ click_on "Add"
4836
+ wait_for_reactive # raises if the round trip failed
4837
+ click_on "Break it"
4838
+ wait_for_reactive(allow_error: true) # waits only, as in 0.16
4839
+ ```
4840
+
4841
+ It reads what the client records: `reactive:idle`'s detail carries `errors`
4842
+ (`[{ action, kind, status, root }]`, `[]` after a clean window), and
4843
+ when that list is not empty `<html data-reactive-errors>` holds it as JSON from
4844
+ that idle edge until the next `reactive:busy` edge. A clean window leaves the
4845
+ attribute absent.
4846
+
4790
4847
  > `verbose_errors` defaults ON in test (it changes only an error BODY, never a
4791
4848
  > status). Asserting an empty failure body? Set
4792
4849
  > `Phlex::Reactive.verbose_errors = false` in your setup.
@@ -1,9 +1,9 @@
1
- import{Controller as It}from"@hotwired/stimulus";import{confirmResolver as Ie}from"phlex/reactive/confirm";function Mt(){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 Ct(){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 Dt=["focus","focus_first","blur"];function $t(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Le(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)v("devtools",(o)=>o.missingRoot(r));return}let s=(o)=>be(o,(c)=>Nr(c,i),n?(c,u)=>v("devtools",(d)=>d.diagnoseStream(c,u,i)):void 0),a=t.findIndex((o)=>Dt.includes(o?.[0]));if(a<0||typeof requestAnimationFrame!=="function")return s(t);s(t.slice(0,a)),requestAnimationFrame(()=>s(t.slice(a)))}}function qt(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){v("defer",(t)=>t.streamAction(this))}}var Me=!1,fe=null;function Wt(){if(Me)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Me=!0,document.addEventListener("turbo:before-stream-render",(e)=>{if(Zt(e),Bt(e),Jt(e),fe)fe(e,g.get("effects"));else g.get("effects")?.wrap(e)})}var U="reactive:streamed";function Bt(e){let t=e.detail,r=t?.render,n=t?.newStream??e.target,i=n?.getAttribute?.("action"),s=/^(append|prepend|update)$/.test(i);if(typeof r!=="function"||!(s||/^(before|after|replace)$/.test(i)))return;let a=n.getAttribute("target"),o=n.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:o?document.querySelectorAll(o):[]){let d=(s?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(U))}}function ve(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function we(e){try{return e.matches(":modal")}catch{return!1}}function ot(e){if(!ve(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||we(e))return;if(e.open)e.close();e.showModal()}function jt(e){if(ve(e)&&e.open)e.close()}function Y(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&&!we(n))ot(n)}function Jt(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),Y(document)}}var Ce=!1;function Ut(){if(Ce)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ce=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))Y(t.target)}),document.addEventListener("turbo:morph",()=>Y(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let r=t.target,n=t.detail?.newElement;if(!ve(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||!we(r))return;e.delete(r),t.preventDefault(),r.close()})}var he=new WeakMap;function st(e,t,r,n){let i=he.get(e)??new Map;he.set(e,i);let s=(a,o)=>{i.delete(a),i.set(a,o)};if(t.endsWith("_class"))for(let a of r.classes??[])s(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))St(r.name)||s(r.name,e.getAttribute(r.name));else if(t==="show"||t==="hide"||t==="toggle"){if(s("hidden",e.getAttribute("hidden")),r.expanded!=null)for(let a of n({...r,to:r.expanded}))st(a,"set_attr",{name:"aria-expanded"})}}var De=!1;function zt(){if(De)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;De=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[r,n]of he.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 _e="data-reactive-image-fallback",x="data-reactive-image-state",me="data-reactive-image-hidden",oe=null,pe="data-reactive-wrap-hidden";function at(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(pe,"")}function ct(e){if(!e.hasAttribute(pe))return;e.removeAttribute("hidden"),e.removeAttribute(pe)}function I(e){if(e?.localName!=="img")return null;let t=e.getAttribute(_e);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var ut=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Ae(e,t){if(typeof t!=="string"||!t)return null;try{return e.closest('[data-controller~="reactive"]')?.querySelector(t)??null}catch{return null}}function lt(e,t){let r=Ae(e,t.alt);return r&&!r.contains(e)?r:null}function X(e,t,r){if(r==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(me,"");if(t.wrap){let i=Ae(e,t.wrap);if(i)at(i);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let n=lt(e,t);if(n)n.textContent=e.getAttribute("alt")??"",n.hidden=!1}else re(e,t);e.setAttribute(x,r)}function re(e,t=I(e)){if(!t||e.getAttribute(x)==null)return;if(e.getAttribute(x)==="error"){if(e.hasAttribute(me))e.removeAttribute("hidden");let r=Ae(e,t.wrap);if(r)ct(r);let n=lt(e,t);if(n)n.hidden=!0}e.removeAttribute(x),e.removeAttribute(me)}function $e(e){let t=e.target,r=I(t);if(!r)return;if(e.type==="load")X(t,r,"loaded");else if(ut(t))X(t,r,"error");else re(t,r)}function Ht(){if(oe)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;oe={error:$e,load:$e,"turbo:before-morph-element":(t)=>{let r=t.target,n=t.detail?.newElement,i=r?.getAttribute?.(x);if(i==null||!n||!I(r))return;let s=(a)=>r.getAttribute(a)===n.getAttribute?.(a);if(s("src")&&s("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=I(r);if(i)X(r,i,n)})},"turbo:frame-render":(t)=>q(t.target),"turbo:render":()=>q(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[${_e}]`))return;r.render=async(s)=>{await n(s),q(document)}}};for(let[t,r]of Object.entries(oe))document.addEventListener(t,r,!0);q(document)}function q(e){for(let t of e?.querySelectorAll?.(`img[${_e}]`)??[]){if(t.getAttribute(x)!=null||!t.complete||!ut(t))continue;let r=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,n=(i)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===r&&X(t,I(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 dt(e){fe=e}var W,se=null,qe="[data-reactive-editable][contenteditable=plaintext-only]";function ft(){if(W===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",W=e.contentEditable==="plaintext-only"}catch{W=!1}return W}function z(e){if(e.matches?.(qe))e.setAttribute("contenteditable","true");e.querySelectorAll?.(qe).forEach(z)}function Kt(){if(se||typeof document>"u"||typeof document.createElement!=="function")return;if(ft())return;z(document),se=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")z(t.target);else t.addedNodes.forEach(z)}),se.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var We=!1;function Be(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 Vt(){if(We)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;We=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented)return;let n=Be(t);if(n)Yt(t,r);if(t.hasAttribute?.("data-reactive-editable")){if(Q.set(t,T(r)),!n)return;for(let{name:s}of[...t.attributes])if(!r.hasAttribute(s)&&s!=="contenteditable"&&s!==w)t.removeAttribute(s);for(let{name:s,value:a}of r.attributes)if(s!=="contenteditable"&&t.getAttribute(s)!==a)t.setAttribute(s,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)=>ke(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===w)&&Be(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(w)&&Ee(t)===Te(t))t.removeAttribute(w)})}var w="data-reactive-held",Se='[data-controller~="reactive"]',H=null,k=new Map;function Ee(e){return e.hasAttribute("data-reactive-editable")?T(e):e.value}function Te(e){return e.hasAttribute("data-reactive-editable")?xe(e):e.defaultValue}function Gt(e){if(e.hasAttribute("data-reactive-editable"))return T(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function Yt(e,t){let r=e.getAttribute("name");if(!r||/^(checkbox|radio)$/.test(e.type)||k.has(e.closest(Se)))return;let n=Gt(t);if(n===Ee(e))return e.removeAttribute(w);if(n===Te(e))return;e.setAttribute(w,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:r,theirs:n}}))}function Xt(e){let t=[];for(let r of e.querySelectorAll(`[${w}]`)){if(r.closest(Se)!==e)continue;let n=r.getAttribute("name");if(Ee(r)===Te(r))r.removeAttribute(w);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 ht(e,t){if(t===!0)return;for(let r of e.querySelectorAll(`[${w}]`))if(r.closest(Se)===e&&!t?.includes(r.getAttribute("name")))r.removeAttribute(w)}function Qt(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 je(e,t,r=null){let n={root:e,streams:0,keep:r},i=H;H=n;try{window.Turbo.renderStreamMessage(t)}finally{H=i}if(n.streams===0)ht(e,r)}function Zt(e){let t=H,r=e.detail,n=r?.render;if(!t||typeof n!=="function")return;t.streams++,r.render=async(i)=>{k.set(t.root,(k.get(t.root)||0)+1);try{return await n(i)}finally{let s=k.get(t.root)-1;if(s)k.set(t.root,s);else k.delete(t.root);ht(t.root,t.keep)}}}var Je="__materialize",Ue=!1;function er(){if(Ue)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Ue=!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 tr="phlex-reactive:latency";function mt(){return typeof sessionStorage<"u"&&Boolean(sessionStorage.getItem(tr))}function Fe(){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||mt())v("devtools",(t)=>e&&t.attach())}var pt="data-reactive-active",A=0;function gt(){if(A++,A===1)yt("reactive:busy")}function bt(){if(A===0)return;if(A--,A===0)yt("reactive:idle")}function un(){return A}function ln(){A=0,(typeof document<"u"?document.documentElement:null)?.removeAttribute?.(pt)}function yt(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.toggleAttribute==="function")t.toggleAttribute(pt,A>0);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function")document.dispatchEvent(new CustomEvent(e,{detail:{count:A}}))}var vt="data-reactive-requests";function wt(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!rr(t))return;let r=nr(t);r[e]=(Number(r[e])||0)+1,t.setAttribute(vt,JSON.stringify(r))}function rr(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function nr(e){try{let t=JSON.parse(e.getAttribute(vt));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function ze(){Mt(),Ct(),$t(),qt(),Wt(),Vt(),Ut(),zt(),gr(),Ht(),Kt(),er(),Fe()}function ir(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var _t=Symbol.for("phlex-reactive.core");if(globalThis[_t])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[_t]=!0;var At=!1;function or(){if(At)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(or,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var sr=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function St(e){let t=String(e).toLowerCase();return t.startsWith("on")||sr.has(t)}var ae=new WeakMap;function ar(e,t,r){let[n,i,s]=t;ae.get(e)?.(),e.classList.add(n,i),r();let a=!1,o=requestAnimationFrame(()=>{if(a)return;e.classList.remove(i),e.classList.add(s)}),c=(d)=>{if(a||d&&d.target!==e)return;a=!0,ae.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(o),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(n,i,s)};ae.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,cr(e))}function cr(e){let t=0;try{let r=getComputedStyle(e);for(let n of["transition","animation"]){let[i,s]=["Duration","Delay"].map((o)=>String(r[n+o]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(r[n+"IterationCount"]).split(",").map((o)=>/inf/.test(o)?1/0:parseFloat(o)>=0?parseFloat(o):1);for(let o=0;o<i.length||o<s.length||o<a.length;o++){let c=i[o%i.length]*a[o%a.length]||0;t=Math.max(t,c+s[o%s.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var ur=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",lr=new Set(["lexxy-editor","trix-editor"]);function T(e){let t="",r=!1,n=(s)=>{if(r&&t&&!t.endsWith(`
1
+ import{Controller as qt}from"@hotwired/stimulus";import{confirmResolver as qe}from"phlex/reactive/confirm";function Wt(){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 Bt(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:token"])return;e["reactive:token"]=function(){let t=this.getAttribute("data-reactive-token-value"),n=this.getAttribute("target");if(!t||!n)return;let r=document.getElementById(n);if(r)r.setAttribute("data-reactive-token-value",t)}}var jt=["focus","focus_first","blur"];function Jt(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:js"])return;e["reactive:js"]=function(){let t=Me(this.getAttribute("data-reactive-ops"));if(!t.length)return;let n=this.getAttribute("target"),r=this.getAttribute("data-reactive-verbose")==="true",i=n?document.getElementById(n):null;if(n&&!i){if(r)v("devtools",(o)=>o.missingRoot(n));return}let s=(o)=>Se(o,(c)=>qn(c,i),r?(c,u)=>v("devtools",(d)=>d.diagnoseStream(c,u,i)):void 0),a=t.findIndex((o)=>jt.includes(o?.[0]));if(a<0||typeof requestAnimationFrame!=="function")return s(t);s(t.slice(0,a)),requestAnimationFrame(()=>s(t.slice(a)))}}function Ut(){let e=window.Turbo?.StreamActions;if(!e||e["reactive:defer"])return;e["reactive:defer"]=function(){v("defer",(t)=>t.streamAction(this))}}var We=!1,be=null;function zt(){if(We)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;We=!0,document.addEventListener("turbo:before-stream-render",(e)=>{if(sn(e),Ht(e),Vt(e),be)be(e,g.get("effects"));else g.get("effects")?.wrap(e)})}var V="reactive:streamed";function Ht(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target,i=r?.getAttribute?.("action"),s=/^(append|prepend|update)$/.test(i);if(typeof n!=="function"||!(s||/^(before|after|replace)$/.test(i)))return;let a=r.getAttribute("target"),o=r.getAttribute("targets"),c=new Set;for(let u of a?[document.getElementById(a)]:o?document.querySelectorAll(o):[]){let d=(s?u:u?.parentElement)?.closest?.('[data-controller~="reactive"]');if(d)c.add(d)}if(c.size===0)return;t.render=async(u)=>{await n(u);for(let d of c)if(d.isConnected)d.dispatchEvent(new Event(V))}}function Te(e){return e?.tagName==="DIALOG"&&typeof e.showModal==="function"}function Fe(e){try{return e.matches(":modal")}catch{return!1}}function lt(e){if(!Te(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||Fe(e))return;if(e.open)e.close();e.showModal()}function Kt(e){if(Te(e)&&e.open)e.close()}function ee(e){let n=[...e?.querySelectorAll?.("dialog[data-reactive-modal]")??[]];if(e?.matches?.("dialog[data-reactive-modal]"))n.push(e);for(let r of n)if(r.open&&!Fe(r))lt(r)}function Vt(e){let t=e.detail,n=t?.render,r=t?.newStream??e.target;if(typeof n!=="function"||!r?.querySelector?.("template")?.content?.querySelector?.("dialog"))return;t.render=async(i)=>{await n(i),ee(document)}}var Be=!1;function Gt(){if(Be)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Be=!0,document.addEventListener("turbo:morph-element",(t)=>{if(t.target?.matches?.('[data-controller~="reactive"]'))ee(t.target)}),document.addEventListener("turbo:morph",()=>ee(document));let e=new WeakSet;document.addEventListener("turbo:before-morph-element",(t)=>{let n=t.target,r=t.detail?.newElement;if(!Te(n)||!r)return;if(r.hasAttribute?.("open"))e.delete(n);else e.add(n)}),document.addEventListener("turbo:before-morph-attribute",(t)=>{let{target:n,detail:r}=t;if(r?.attributeName!=="open"||r.mutationType!=="remove")return;if(!e.has(n)||!n.open||!Fe(n))return;e.delete(n),t.preventDefault(),n.close()})}var ye=new WeakMap;function dt(e,t,n,r){let i=ye.get(e)??new Map;ye.set(e,i);let s=(a,o)=>{i.delete(a),i.set(a,o)};if(t.endsWith("_class"))for(let a of n.classes??[])s(`.${a}`,e.classList.contains(a));else if(t.endsWith("_attr"))Rt(n.name)||s(n.name,e.getAttribute(n.name));else if(t==="show"||t==="hide"||t==="toggle"){if(s("hidden",e.getAttribute("hidden")),n.expanded!=null)for(let a of r({...n,to:n.expanded}))dt(a,"set_attr",{name:"aria-expanded"})}}var je=!1;function Yt(){if(je)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;je=!0,document.addEventListener("turbo:morph-element",(e)=>{let t=e.target;for(let[n,r]of ye.get(t)??[])if(n[0]===".")t.classList.toggle(n.slice(1),r);else if(r==null)t.removeAttribute(n);else if(t.getAttribute(n)!==r)t.setAttribute(n,r)})}var ke="data-reactive-image-fallback",R="data-reactive-image-state",ve="data-reactive-image-hidden",le=null,we="data-reactive-wrap-hidden";function ft(e){if(e.hasAttribute("hidden"))return;e.setAttribute("hidden",""),e.setAttribute(we,"")}function ht(e){if(!e.hasAttribute(we))return;e.removeAttribute("hidden"),e.removeAttribute(we)}function D(e){if(e?.localName!=="img")return null;let t=e.getAttribute(ke);if(t==null)return null;try{return JSON.parse(t)||{}}catch{return{}}}var mt=(e)=>e.getAttribute("src")||e.getAttribute("srcset");function Re(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 n=Re(e,t.alt);return n&&!n.contains(e)?n:null}function te(e,t,n){if(n==="error"){if(t.hide&&!e.hasAttribute("hidden"))e.setAttribute("hidden",""),e.setAttribute(ve,"");if(t.wrap){let i=Re(e,t.wrap);if(i)ft(i);else console.warn(`[phlex-reactive] reactive_image_fallback wrap: ${JSON.stringify(t.wrap)} is not in the root — skipped`)}let r=pt(e,t);if(r)r.textContent=e.getAttribute("alt")??"",r.hidden=!1}else se(e,t);e.setAttribute(R,n)}function se(e,t=D(e)){if(!t||e.getAttribute(R)==null)return;if(e.getAttribute(R)==="error"){if(e.hasAttribute(ve))e.removeAttribute("hidden");let n=Re(e,t.wrap);if(n)ht(n);let r=pt(e,t);if(r)r.hidden=!0}e.removeAttribute(R),e.removeAttribute(ve)}function Je(e){let t=e.target,n=D(t);if(!n)return;if(e.type==="load")te(t,n,"loaded");else if(mt(t))te(t,n,"error");else se(t,n)}function Xt(){if(le)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;let e=new WeakMap;le={error:Je,load:Je,"turbo:before-morph-element":(t)=>{let n=t.target,r=t.detail?.newElement,i=n?.getAttribute?.(R);if(i==null||!r||!D(n))return;let s=(a)=>n.getAttribute(a)===r.getAttribute?.(a);if(s("src")&&s("srcset"))e.set(n,i)},"turbo:morph-element":(t)=>{let n=t.target,r=e.get(n);if(r===void 0)return;e.delete(n),queueMicrotask(()=>{let i=D(n);if(i)te(n,i,r)})},"turbo:frame-render":(t)=>J(t.target),"turbo:render":()=>J(document),"turbo:before-stream-render":(t)=>{let n=t.detail,r=n?.render,i=n?.newStream??t.target;if(typeof r!=="function"||!i?.querySelector?.("template")?.content?.querySelector?.(`img[${ke}]`))return;n.render=async(s)=>{await r(s),J(document)}}};for(let[t,n]of Object.entries(le))document.addEventListener(t,n,!0);J(document)}function J(e){for(let t of e?.querySelectorAll?.(`img[${ke}]`)??[]){if(t.getAttribute(R)!=null||!t.complete||!mt(t))continue;let n=`${t.getAttribute("src")} ${t.getAttribute("srcset")}`,r=(i)=>`${t.getAttribute("src")} ${t.getAttribute("srcset")}`===n&&te(t,D(t)??{},i);if(t.naturalWidth>0)r("loaded");else if(typeof t.decode==="function")t.decode().then(()=>r("loaded"),()=>r("error"));else r("error")}}function gt(e){be=e}var U,de=null,Ue="[data-reactive-editable][contenteditable=plaintext-only]";function bt(){if(U===void 0)try{let e=document.createElement("div");e.contentEditable="plaintext-only",U=e.contentEditable==="plaintext-only"}catch{U=!1}return U}function G(e){if(e.matches?.(Ue))e.setAttribute("contenteditable","true");e.querySelectorAll?.(Ue).forEach(G)}function Qt(){if(de||typeof document>"u"||typeof document.createElement!=="function")return;if(bt())return;G(document),de=new MutationObserver((e)=>{for(let t of e)if(t.type==="attributes")G(t.target);else t.addedNodes.forEach(G)}),de.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["contenteditable","data-reactive-editable"]})}var ze=!1;function He(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 Zt(){if(ze)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;ze=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented)return;let r=He(t);if(r)tn(t,n);if(t.hasAttribute?.("data-reactive-editable")){if(ne.set(t,T(n)),!r)return;for(let{name:s}of[...t.attributes])if(!n.hasAttribute(s)&&s!=="contenteditable"&&s!==_)t.removeAttribute(s);for(let{name:s,value:a}of n.attributes)if(s!=="contenteditable"&&t.getAttribute(s)!==a)t.setAttribute(s,a);return e.preventDefault()}if(t.localName!=="input"||!r)return;let i=n.getAttribute("value");if(i==null)t.removeAttribute("value");else if(t.getAttribute("value")!==i)t.setAttribute("value",i)}),document.addEventListener("focusin",(e)=>Pe(e.target)),document.addEventListener("turbo:before-morph-attribute",(e)=>{let t=e.detail?.attributeName;if((t==="value"||t===_)&&He(e.target))e.preventDefault()}),document.addEventListener("input",(e)=>{let t=e.target;if(t?.hasAttribute?.(_)&&Le(t)===Ne(t))t.removeAttribute(_)})}var _="data-reactive-held",xe='[data-controller~="reactive"]',Y=null,k=new Map;function Le(e){return e.hasAttribute("data-reactive-editable")?T(e):e.value}function Ne(e){return e.hasAttribute("data-reactive-editable")?Ie(e):e.defaultValue}function en(e){if(e.hasAttribute("data-reactive-editable"))return T(e);return e.localName==="textarea"?e.textContent:e.getAttribute("value")??""}function tn(e,t){let n=e.getAttribute("name");if(!n||/^(checkbox|radio)$/.test(e.type)||k.has(e.closest(xe)))return;let r=en(t);if(r===Le(e))return e.removeAttribute(_);if(r===Ne(e))return;e.setAttribute(_,""),e.dispatchEvent(new CustomEvent("reactive:held",{bubbles:!0,detail:{name:n,theirs:r}}))}function nn(e){let t=[];for(let n of e.querySelectorAll(`[${_}]`)){if(n.closest(xe)!==e)continue;let r=n.getAttribute("name");if(Le(n)===Ne(n))n.removeAttribute(_);else if(r&&!t.includes(r))t.push(r)}if(t.length===0)return null;return JSON.stringify(t).replace(/[\u007f-￿]/g,(n)=>`\\u${n.charCodeAt(0).toString(16).padStart(4,"0")}`)}function yt(e,t){if(t===!0)return;for(let n of e.querySelectorAll(`[${_}]`))if(n.closest(xe)===e&&!t?.includes(n.getAttribute("name")))n.removeAttribute(_)}function rn(e){let t=e.headers.get("X-Reactive-Refused");if(t==="*")return!0;try{let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ke(e,t,n=null,r=30000){let i={root:e,streams:0,keep:n,events:[]},s=Y;Y=i;try{window.Turbo.renderStreamMessage(t)}finally{Y=s}if(i.streams===0)yt(e,n);let a=i.events.filter((d)=>!d.event.defaultPrevented).map((d)=>d.done),o=a.length>0?Promise.all(a).then((d)=>d.find(Boolean)):on(),c,u=new Promise((d)=>c=setTimeout(d,r));return Promise.race([o,u]).finally(()=>clearTimeout(c))}function on(){return new Promise((e)=>{if(document.visibilityState==="hidden"||typeof requestAnimationFrame!=="function")setTimeout(e,0);else requestAnimationFrame(()=>e())})}function sn(e){let t=Y,n=e.detail,r=n?.render;if(!t||typeof r!=="function")return;t.streams++;let i;t.events.push({event:e,done:new Promise((s)=>i=s)}),n.render=async(s)=>{k.set(t.root,(k.get(t.root)||0)+1);let a;try{return await r(s)}catch(o){throw a=o,o}finally{let o=k.get(t.root)-1;if(o)k.set(t.root,o);else k.delete(t.root);yt(t.root,t.keep),i(a)}}}var Ve="__materialize",Ge=!1;function an(){if(Ge)return;if(typeof window>"u"||typeof document>"u")return;if(typeof window.addEventListener!=="function")return;Ge=!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 cn="phlex-reactive:latency";function vt(){return typeof sessionStorage<"u"&&Boolean(sessionStorage.getItem(cn))}function Oe(){if(typeof document>"u")return;if(!g.has("devtools")&&!A.get("devtools")[1])return;let e=document.querySelector?.('meta[name="phlex-reactive-env"]')?.content==="development";if(e||vt())v("devtools",(t)=>e&&t.attach())}var wt="data-reactive-active",_e="data-reactive-errors",w=0,x=[];function _t(){if(w++,w===1)x=[],St("reactive:busy")}function P({action:e=null,kind:t,status:n=null,root:r=null}){if(w===0)return;x.push({action:e??null,kind:t,status:n??null,root:r||null})}function At(){if(w===0)return;if(w--,w===0)St("reactive:idle")}function gr(){return w}function br(){w=0,x=[];let e=typeof document<"u"?document.documentElement:null;e?.removeAttribute?.(wt),e?.removeAttribute?.(_e)}function St(e){if(typeof document>"u")return;let t=document.documentElement,n=e==="reactive:idle";if(typeof t?.toggleAttribute==="function")if(t.toggleAttribute(wt,w>0),n&&x.length>0)t.setAttribute(_e,JSON.stringify(x));else t.removeAttribute(_e);if(typeof document.dispatchEvent==="function"&&typeof CustomEvent==="function"){let r=n?{count:w,errors:x.slice()}:{count:w};document.dispatchEvent(new CustomEvent(e,{detail:r}))}}var Et="data-reactive-requests";function Tt(e){if(typeof document>"u")return;let t=document.documentElement;if(typeof t?.setAttribute!=="function"||!un(t))return;let n=ln(t);n[e]=(Number(n[e])||0)+1,t.setAttribute(Et,JSON.stringify(n))}function un(e){return e.hasAttribute?.("data-reactive-verbose")||!!document.querySelector?.('[data-reactive-verbose="true"]')}function ln(e){try{let t=JSON.parse(e.getAttribute(Et));if(t&&typeof t==="object")return{action:0,defer:0,...t}}catch{}return{action:0,defer:0}}function Ye(){Wt(),Bt(),Jt(),Ut(),zt(),Zt(),Gt(),Yt(),Sn(),Xt(),Qt(),an(),Oe()}function dn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Ft=Symbol.for("phlex-reactive.core");if(globalThis[Ft])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[Ft]=!0;var kt=!1;function fn(){if(kt)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(fn,0);if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",e,{once:!0});else e()}var hn=new Set(["href","src","srcset","srcdoc","action","formaction","xlink:href","style"]);function Rt(e){let t=String(e).toLowerCase();return t.startsWith("on")||hn.has(t)}var fe=new WeakMap;function mn(e,t,n){let[r,i,s]=t;fe.get(e)?.(),e.classList.add(r,i),n();let a=!1,o=requestAnimationFrame(()=>{if(a)return;e.classList.remove(i),e.classList.add(s)}),c=(d)=>{if(a||d&&d.target!==e)return;a=!0,fe.delete(e),clearTimeout(u),globalThis.cancelAnimationFrame?.(o),e.removeEventListener("animationend",c),e.removeEventListener("transitionend",c),e.classList.remove(r,i,s)};fe.set(e,c),e.addEventListener("animationend",c),e.addEventListener("transitionend",c);let u=setTimeout(c,pn(e))}function pn(e){let t=0;try{let n=getComputedStyle(e);for(let r of["transition","animation"]){let[i,s]=["Duration","Delay"].map((o)=>String(n[r+o]).split(",").map((c)=>parseFloat(c)*(/ms/.test(c)?1:1000)||0)),a=String(n[r+"IterationCount"]).split(",").map((o)=>/inf/.test(o)?1/0:parseFloat(o)>=0?parseFloat(o):1);for(let o=0;o<i.length||o<s.length||o<a.length;o++){let c=i[o%i.length]*a[o%a.length]||0;t=Math.max(t,c+s[o%s.length])}}}catch{}return Math.min(Math.max(t+50,350),5000)}var gn=":is(lexxy-editor, trix-editor, [contenteditable=''], [contenteditable=true], [contenteditable=plaintext-only])",bn=new Set(["lexxy-editor","trix-editor"]);function T(e){let t="",n=!1,r=(s)=>{if(n&&t&&!t.endsWith(`
2
2
  `))t+=`
3
- `;r=!1,t+=s},i=(s)=>{for(let a of s.childNodes){let o=/^(div|p|li)$/.test(a.localName);if(o)r=!0;if(a.nodeType===3)a.data&&n(a.data);else if(a.localName==="br")n(`
4
- `);else if(a.nodeType===1)i(a);if(o)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 Q=new WeakMap;function ke(e){if(e?.hasAttribute?.("data-reactive-editable")&&!Q.has(e))Q.set(e,T(e))}function xe(e){return ke(e),Q.get(e)}function dr(e){return lr.has(e.localName)?typeof e.value==="string":!0}var He=Object.freeze({show:(e,t,r)=>ce(e,!1,t,r),hide:(e,t,r)=>ce(e,!0,t,r),toggle:(e,t,r)=>ce(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(ue(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(ue(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!ue(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)=>Ar(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>ot(e),close_dialog:(e)=>jt(e),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{}kt(e,n)},check_group:(e,t)=>{let r=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let n of r)v("bindings",(i)=>i.checkGroup(n,t.group,t.checked))},presence:(e,t)=>v("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=fr(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)=>hr(e),preview_file:(e,t,r)=>mr(e,t,r),set_value:(e,t)=>Ft(e,String(t.value??"")),persist_state:(e,t)=>v("persist",(r)=>r.writeState(e,t.state)),persist_clear:(e)=>v("persist",(t)=>t.clearRoot(e))});function fr(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function hr(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((r)=>{if(!r)return;e.value=r,Tt(e),e.focus?.()}).catch(()=>{})}var N=new Map,O=null;function mr(e,t,r){if(e?.tagName!=="INPUT"||e.type!=="file")return K(`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 K(`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??[]],s=yr(e,t.accept),a=(u)=>Number.isInteger(t.max_bytes)&&u.size>t.max_bytes,o=[],c;if(t.per_file===!0&&e.multiple){let u=i.filter((f,h)=>{let p=typeof f?.type==="string"&&s(f)?a(f)&&"size":"type";if(p)o.push({reason:p,file:f,index:h});return!p}),d=o.length>0&&!br(e,u)?i.length:u.length;for(let f of o)f.remaining=d;c=u.find((f)=>f.type.startsWith("image/"))}else{let u=i.filter((f)=>typeof f?.type==="string"&&s(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)o.push({reason:d,file:d==="size"?c:i[0]}),c=null}if(Et(n),c){let u=URL.createObjectURL(c);N.set(n,u),n.setAttribute("src",u),vr()}else n.removeAttribute("src");if(re(n),t.wrap!=null){let u=r({...t,to:t.wrap});if(u.length===0)K(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let d of u)c?ct(d):at(d)}if(t.name!=null)for(let u of r({...t,to:t.name}))u.textContent=c?c.name:"";if(t.rejected!=null)pr(e,r({...t,to:t.rejected}),o,t.rejected);for(let u of o)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:u}))}var Z="data-reactive-file-rejected";function pr(e,t,r,n){if(t.length===0)return ge(e,`rejected: ${JSON.stringify(n)} is not on the page`);for(let i of t){for(let a of[...i.children])if(a.hasAttribute(Z))a.remove();let s=[...i.children].find((a)=>a.localName==="template");if(!s){ge(e,`rejected: ${JSON.stringify(n)} has no <template> child`);continue}for(let{reason:a,file:o}of r){let c=s.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=o.name;for(let u of[...c.childNodes]){if(u.nodeType!==1)continue;u.setAttribute(Z,""),i.append(u)}}}}var Ke=!1;function gr(){if(Ke)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Ke=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,r=e.detail?.newElement;if(!r||e.defaultPrevented||!t.lastElementChild?.hasAttribute(Z))return;for(let n of t.children)if(n.hasAttribute(Z))r.append(n.cloneNode(!0))})}function br(e,t){if(typeof DataTransfer!=="function")return ge(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 yr(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((s)=>s[0]==="."?String(n.name).toLowerCase().endsWith(s):s.endsWith("/*")?i.startsWith(s.slice(0,-1)):i===s)}}function K(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function ge(e,t){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))K(t)}function Et(e){let t=N.get(e);if(t===void 0)return;if(N.delete(e),URL.revokeObjectURL(t),N.size===0)O?.disconnect(),O=null}function vr(){if(O||typeof MutationObserver!=="function"||!document?.documentElement)return;O=new MutationObserver(()=>{for(let[e,t]of N)if(!e.isConnected||e.getAttribute("src")!==t)Et(e)}),O.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function Tt(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Ft(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=Ve(e);if(e.value=t,Ve(e)!==r)Tt(e)}function Ve(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
6
- `):e.value}function wr(e,t,r){if(r?.transition)ar(e,r.transition,()=>e.hidden=t);else e.hidden=t}function ce(e,t,r,n){if(wr(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 ue(e){if(!St(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function kt(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 o=n?r.getAttribute(a):null;if(o==null){if(e.hasAttribute(a))i=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==o)i=e.setAttribute(a,o)??!0}if(i)re(e);let s=r?.getAttribute("alt")??"";if(e.getAttribute("alt")!==s)e.setAttribute("alt",s);return r?s:!1}var _r='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ar(e){return e.querySelectorAll?.(_r)?.[0]??null}function Le(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 Ge=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"}),Ye=Object.freeze(["meta","ctrl","alt","shift"]);function ne(e,t,r){let n=e.split("+");for(let a of Ye)if(n.includes(a)!==Boolean(t[`${a}Key`]))return!1;let i=n.find((a)=>!Ye.includes(a));if(i===void 0||typeof t.key!=="string")return!0;let s=r&&Object.hasOwn(r,i)?r[i]:Object.hasOwn(Ge,i)?Ge[i]:/^[a-z0-9]$/.test(i)?i:null;return typeof s==="string"&&s.toLowerCase()===t.key.toLowerCase()}var Sr=(e)=>e&&typeof e==="object"?e.keys:String(e),Re=()=>V().prevented??=new WeakSet;function le(e,t){if(t!=null&&!e.defaultPrevented)Re().add(e);e.preventDefault()}function B(e,t,r){if(t.defaultPrevented&&e?.handled!==!0&&!Re().has(t))return!1;let n=t.target;if(e?.inEditable!==!0&&(n?.isContentEditable||/^(input|textarea|select)$/.test(n?.localName)))return!1;let i=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return ne(Sr(e).replace(/^mod\+/,`${i}+`),t,r)}function Er(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:Le(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 Xe(e,t,r){if(e.legacy)return!0;let n=e.on;if(typeof n!=="string"||n==="")return!1;let i=n.indexOf(".");if(t.type!==(i<0?n:n.slice(0,i)))return!1;if(Boolean(e.window)!==Oe(t.currentTarget))return!1;return i<0||r===null||ne(n.slice(i+1),t,r)}function Tr(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 Qe=new WeakMap;function Fr(e,t,r){if(!r.once)return!1;let n=t.currentTarget??e.element,i=Qe.get(e);if(!i)i=new WeakMap,Qe.set(e,i);let s=i.get(n);if(!s)s=new Set,i.set(n,s);let a=t.params?.ops,c=(n===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(r);if(s.has(c))return!0;return s.add(c),!1}var Ze=new WeakMap;function kr(e,t){if(e===null||typeof e!=="object")return!1;let r=e.params?.ops,n=typeof r==="string"?r:JSON.stringify(r??null),i=Ze.get(e);if(!i)i=new WeakMap,Ze.set(e,i);let s=i.get(t);if(!s)s=new Map,i.set(t,s);let a=s.get(e.currentTarget);if(!a)a=new Set,s.set(e.currentTarget,a);if(a.has(n))return!0;return a.add(n),!1}function be(e,t,r){for(let n of e){if(!Array.isArray(n))continue;let[i,s={}]=n;if(!Object.hasOwn(He,i)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(i)} — skipped`);continue}let a=t(s);if(a.length===0&&r)r(i,s);if(a.length>0)s=Lr(i,s,t,r);if(!s)continue;for(let o of a)if(He[i](o,s,t),s?.keep===!0)st(o,i,s,t)}}var xr=new Set(["set_value","text","set_attr"]);function Lr(e,t,r,n){let i=e==="dispatch",s=i?t.detail_from:xr.has(e)&&t.from!=null&&{value:t.attr};if(!s||i&&!Object.keys(s).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 o=i?"@trigger":t.from,c;try{c=r({...t,to:o})[0]}catch{}if(!c)return n?.(e,{...t,to:o}),null;let u={...a};for(let[d,f]of Object.entries(s)){let h=Rr(c,f);if(h==null)return null;u[d]=h}return i?{...t,detail:u}:{...t,...u}}function Rr(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 Nr(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 Or(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function Ne(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var F='[data-controller~="reactive"]',Pr='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',ye=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!Ne(e);function R(e,t,r){let n=e?.closest?.(t);while(n&&n!==r&&ye(n))n=n.parentElement?.closest?.(t);return n??null}var j=new WeakMap,J=new WeakMap;function Ir(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 Mr(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 Cr(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function Dr(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function $r(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 xt(e){return e.getAttribute?.("data-reactive-presence")!=null}function qr(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}var Wr=[["persist",[Or,null,null,!0]],["defer",[Ne,null]],["form",[Ir,null]],["bindings",[Mr,null,null,!0]],["compute",[Cr,null,null,!0]],["sortable",[Dr,null]],["drag",[$r,null]],["presence",[xt,null]],["countdown",[qr,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(Wr),et=new Map,g=new Map,Br=new Map;function y(e,t,r){Lt.set(e,[t,r]),jr(e)}var Lt=new Map;function jr(e){let t=_.get(e),[r,n]=Lt.get(e);t[1]=r,t[2]=n}function dn(e,t){t.install?.(M),g.set(e,t),Br.set(e,t)}function Rt(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 Nt(e){return P(e).catch((t)=>ee(e,"load",t))}function P(e){let t=et.get(e);if(!t)t=(_.get(e)[1]??(()=>Promise.reject(Error("this entry has no way to import it"))))().then((n)=>(n.install?.(M),g.set(e,n),n)),et.set(e,t);return t}var tt=new Set;function ee(e,t,r){let n=e+t;if(tt.has(n))return;tt.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 v(e,t){let r=g.get(e);if(r)return t(r);P(e).then(t,(n)=>ee(e,"load",n))}var Jr=1e4;function de(){let e=Number(globalThis.document?.head?.querySelector?.('meta[name="phlex-reactive-feature-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:Jr}function fn(){return[..._.keys()]}var rt=Promise.resolve();function nt(e,t,r){let n=M.waiting.get(e);if(n&&n[t]===r)delete n[t]}var M={enter:gt,exit:bt,count:wt,text:T,served:xe,waiting:new WeakMap};var C=Symbol.for("phlex-reactive.early"),Ur=1e4,zr=1500,Oe=(e)=>e!=null&&(e===globalThis.window||e.window===e),Hr="dispatch";function V(){return globalThis[C]??={queue:[],connected:new WeakSet},globalThis[C]}function Kr(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Ur}function Vr(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 s;try{s=JSON.parse(n)}catch{s=n}t[i[1].replace(/[-_]([a-z0-9])/g,(a,o)=>o.toUpperCase())]=s}return t}function Gr(e,t,r){return{[C]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:r?t.ownerDocument.defaultView:t,params:Vr(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&&!Re().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var te=new WeakMap;function Yr(e,{token:t,type:r,method:n,filter:i,win:s},a){let o=te.get(e);if(!o)te.set(e,o=new Map);let c=s?`${t} ${a}`:t;if(o.has(c))return!1;return o.set(c,{type:r,method:n,filter:i,win:s,params:a,armed:!0}),!0}function it(e,t,r,n){if(e?.[C])return!1;let i=Oe(e?.currentTarget),s=i?n:e?.currentTarget,a=Qr(e,s,i?`@${t}`:t),o=te.get(s),c=i&&JSON.stringify(e.params);for(let u of o?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==i)continue;if(i&&u.params!==c)continue;if(u.filter&&!ne(u.filter,e,r))continue;return u.armed=!1,!0}return a}var G=new WeakMap;function Xr(e,t,r){let n=G.get(e);if(!n)G.set(e,n=new Map),setTimeout(()=>G.delete(e));let i=n.get(t)??{};n.set(t,i),i[r]=(i[r]??0)+1}function Qr(e,t,r){let n=e&&G.get(e)?.get(t);if(!n?.[r])return!1;return n[r]-=1,!0}class Ot extends It{static values={token:String};#A;#d=new Map;#f=new Map;#ie;#L;#B;#R=0;#h=new Map;#N=new WeakMap;#t;featuresReady=rt;#r=new Map;#O=new Set;#m=!1;#n=null;#p=new Map;#S=new Map;#g=new Map;#b=0;#j;#je=0;#Je=0;connect(){if(At=!0,V().connected.add(this.element),j.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||Ne(this.element))this.#t=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===U)this.#z();this.#J(!0)},this.element.addEventListener?.("turbo:morph-element",this.#t),this.element.addEventListener?.("focusin",this.#t),this.element.addEventListener?.(U,this.#t);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(ke),this.#b++,this.featuresReady=rt,this.#J(),Y(this.element),this.#ce()}#Ue(e){}#ze(e,t,r,n){}#He(){}#Ke(e,t){}#J(e){{let t=this.#b,r=[];for(let[s,[a]]of _){if(!a||this.#O.has(s))continue;let o=g.get(s);if(o&&!o.connect)continue;try{if(a(this.element))r.push(s)}catch(c){this.#y(s,"detect",c)}}if(r.length===0)return;for(let s of r)this.#O.add(s);if(!this.#m&&r.every((s)=>g.has(s))){for(let s of r)this.#P(t,s,g.get(s),e);return}for(let s of r){let a=this.#oe(t,s),o=[];for(let u of _.keys()){if(u===s)break;if(this.#g.has(u))o.push(this.#g.get(u))}let c=Promise.all(o).then(()=>a).then((u)=>u&&this.#P(t,s,u,e));if(this.#g.set(s,c),_.get(s)[3])this.#n=c}let n=this.#n;n?.then(()=>{if(this.#n===n)this.#n=null}),this.#m=!0;let i=Promise.all(this.#g.values()).then(()=>{if(this.featuresReady===i)this.#m=!1});this.featuresReady=i}}#oe(e,t){{let r=()=>e===this.#b;return this.#se(t),new Promise((n)=>{let i=!1,s=setTimeout(()=>{if(this.#p.delete(s),i=!0,r())this.#y(t,"timeout",Error(`not loaded after ${de()} ms`));n(null)},de());this.#p.set(s,n);let a=()=>{clearTimeout(s),this.#p.delete(s)};P(t).then((o)=>{if(a(),i)queueMicrotask(()=>this.#P(e,t,o));else n(o)},(o)=>{if(a(),r())this.#y(t,"load",o);n(null)})})}}#se(e){{let t=_.get(e)[2];if(!t)return;let r={};try{this.#S.set(e,[t(this.element,r),r]),M.waiting.set(this.element,{...M.waiting.get(this.element),[e]:r})}catch(n){this.#y(e,"detect",n)}}}#U(e,t){{let[r,n]=this.#S.get(e)??[];if(this.#S.delete(e),!t)nt(this.element,e,n);try{r?.()}catch(i){console.error(`[phlex-reactive] the "${e}" feature module failed to stop waiting`,i)}return n}}#P(e,t,r,n){{if(e!==this.#b)return;let i=this.#U(t);try{r.connect?.(this,this.#e(),n,i),this.#r.set(t,r)}catch(s){this.#y(t,"connect",s)}}}#e(){return this.#j??={emit:(e,t,r)=>this.#o(e,t,r),reseed:()=>this.#z(),proceed:(e,t,r,n)=>this.#M(e,t,r,0,0,null,n),forgetToken:()=>{this.#A=void 0},owns:(e)=>this.#c(e),ownership:()=>this.#Q(),bindingOwns:(e)=>this.#Z(e),bindingOwnership:()=>this.#xe(),opTargets:(e)=>this.#W(e),diagnose:(e,t)=>this.#q(e,t),applyOps:(e,t)=>be(e,(r)=>this.#W(t!=null&&r.to==null?{...r,to:t}:r),(r,n)=>this.#q(`client op "${r}"`,n)),listnavOptions:(e)=>this.#w(e),collectFields:()=>this.#ee(),plain:ft,text:T,served:xe,copyMedia:kt,setValue:Ft,confirm:(e,t)=>Promise.resolve().then(()=>Ie(e,t)).catch(()=>!1)},this.#j}#z(){this.#r.get("form")?.reseed(this),this.#r.get("bindings")?.reseed(this),this.#r.get("compute")?.seed(this)}#y(e,t,r){if(ee(e,t,r),this.#i("feature"),t==="load"&&this.element.getAttribute?.("data-reactive-defer-pending"))this.element.removeAttribute("data-reactive-defer-pending"),this.element.removeAttribute("aria-busy");this.#o("reactive:error",{kind:"feature",feature:e,phase:t,error:r})}#ae(){{this.#b++;for(let[t,r]of this.#p)clearTimeout(t),r(null);this.#p.clear();for(let t of[...this.#S.keys()]){let r=this.#U(t,!0),n=this.element;v(t,(i)=>{i.abandon?.(n,r),nt(n,t,r)})}this.#O.clear(),this.#g.clear(),this.#m=!1,this.#n=null;let e=[...this.#r];this.#r.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)}}}#ce(){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.#ue();for(let[e,t]of J.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}J.delete(this.element)}#I=new Set;#ue(){let{queue:e}=V();if(e.length===0)return;let t=[];for(let i=e.length-1;i>=0;i--){let{root:s}=e[i];if(s===this.element||!s.isConnected)t.unshift(...e.splice(i,1))}let r=Kr(),n=new Map;for(let i of t){let s=n.get(i.event)??[new Set,new Set];n.set(i.event,s);let a=s[+!!i.win];if(a.has(i.el))continue;a.add(i.el);let o=i.win?Math.min(zr,r):r,c=i.root!==this.element?"its root left the page before a controller connected":performance.now()-i.at>o?`it is older than the ${o} 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.#x())console.warn(`[phlex-reactive] dropped an early "${i.event.type}" trigger: ${c}`);continue}this.#le(i)}}#le({event:e,el:t,descs:r,win:n}){let i=Gr(e,t,n),s=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),o=n?this.element:t;for(let c of r){if(!a.includes(c.token))continue;if(c.filter&&!ne(c.filter,e,s))continue;if(/#\w+.*:once\b/.test(c.token)){if(!Yr(o,c,n&&JSON.stringify(i.params)))continue;this.#I.add(o)}if(Xr(e,o,n?`@${c.method}`:c.method),c.method==="runOps")this.runOps(i);else this.dispatch(i)}}disconnect(){if(this.#ae(),this.#ve(),this.#_e(),this.#t)this.element.removeEventListener?.("turbo:morph-element",this.#t),this.element.removeEventListener?.("focusin",this.#t),this.element.removeEventListener?.(U,this.#t);if(V().connected.delete(this.element),j.get(this.element)===this)j.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#I)te.delete(e);this.#I.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Je&&this.#de())return this.#fe(e);let t=e.params?.shortcut;if(t!=null&&!B(t,e,this.application?.schema?.keyMappings))return;if(it(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:r,params:n,debounce:i,throttle:s,confirm:a,confirmWhen:o,outside:c,window:u,optimistic:d,prevent:f}=e.params;if(!r)return;let h=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let p=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#re(d,p))le(e,t);if(r===Je){let m=()=>{{let S=this.#r.get("defer");if(S)return S.materialize(this)}if(this.tokenValue)return this.#M(p,r,"{}")};return this.#m?this.featuresReady.then(m):m()}let b=this.#H(a,o),E=()=>this.#M(p,r,n,i,s,d,h);if(!b)return E();if(b instanceof Promise)return b.then((m)=>m?this.#E(m,p,E):E());this.#E(b,p,E)}#E(e,t,r){return Promise.resolve().then(()=>Ie(e,{el:t})).catch(()=>!1).then((n)=>{if(n)r()})}#H(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([P(e).catch((r)=>(ee(e,"load",r),null)),new Promise((r)=>t=setTimeout(()=>r(null),de()))]).finally(()=>clearTimeout(t))}}#de(){return!this.tokenValue&&ye(this.element)}#fe(e){let t=R(this.element.parentElement,Pr);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=j.get(t);if(r)return r.dispatch(e);let{shortcut:n,window:i,optimistic:s,prevent:a}=e.params;if(n!=null&&!B(n,e,this.application?.schema?.keyMappings))return;let o=e.currentTarget??e.target;if((n!=null||!i&&a!==!1)&&!this.#re(s,o))le(e,n);J.set(t,[...J.get(t)??[],[e,o]]);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&&!B(t.shortcut,e,this.application?.schema?.keyMappings))return;if(it(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(kr(e,this))return;let r=e.params??{},n=e.currentTarget??e.target,i=Er(r.ops),s=i.filter((o)=>Xe(o,e,null)),a=s.length<=1?s:s.filter((o)=>Xe(o,e,this.application?.schema?.keyMappings));if(a.length===0&&i.length>0){if(this.#x())this.#_((o)=>o.noBinding(this,e));return}for(let o of a){if(o.outside&&e[C])continue;if(!Tr(o,e))continue;let c=o.within==null?n:this.#he(o.within,e);if(o.within!=null&&!c)continue;if(o.shortcut!=null&&!B(o.shortcut,e,this.application?.schema?.keyMappings))continue;if(Fr(this,e,o))continue;this.#me(o.legacy?{...r,ops:o.ops,debounce:void 0,throttle:void 0,prevent:void 0}:o,e,c,i.indexOf(o),n)}}#he(e,t){let r=t.currentTarget,n=null;try{n=t.target?.closest?.(e)}catch{if(this.#x())console.warn(`[phlex-reactive] on_client within: ${JSON.stringify(e)} is not a selector — nothing ran`)}return n&&n!==r&&r?.contains?.(n)&&this.#c(n)?n:null}#me(e,t,r,n,i=r){let{ops:s,confirm:a,confirmWhen:o,outside:c,window:u,shortcut:d,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(d!=null||!u&&f!==!1)le(t,d);let h=this.#H(a,o),p=this.#pe(e,n,i,()=>this.#Ie(this.#Pe(s),r));if(!h)return p();if(h instanceof Promise)return h.then((b)=>b?this.#E(b,r,p):p());this.#E(h,r,p)}#pe(e,t,r,n){let i=Number(e.debounce)||0,s=Number(e.throttle)||0;if(i<=0&&s<=0)return n;let a=JSON.stringify([t,e]);if(i>0)return()=>this.#V(r,a,i,n);return()=>this.#G(r,a,s,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 v("bindings",(i)=>i[e](this,this.#e(),n))}}trackDirty(){(this.#r.get("form")??g.get("form"))?.scan(this,this.#e())}listnavNext(e){this.#T(e,(t,r)=>t<0?0:(t+1)%r)}listnavPrev(e){this.#T(e,(t,r)=>t<0?r-1:(t-1+r)%r)}listnavFirst(e){this.#T(e,()=>0)}listnavLast(e){this.#T(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")}#T(e,t){let r=this.#w(e);if(!r.length)return;e.preventDefault();let n=this.#ge(e),i=globalThis.document?.activeElement,s=n?r.findIndex((o)=>o===i||i!=null&&o.contains?.(i)):r.findIndex((o)=>o.hasAttribute("data-reactive-highlighted")),a=r[t(s,r.length)];if(n)a.focus?.();else{for(let o of r)o.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#ge(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.#Q();return Array.from(this.element.querySelectorAll(r)).filter((i)=>!i.hidden&&n(i))}#M(e,t,r,n,i,s,a){if(this.#o("reactive:before-dispatch",{action:t,params:this.#te(r),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(n)||0;if(c>0)return this.#ye(e,c,t,r,s,a);let u=Number(i)||0;if(u>0)return this.#we(e,u,t,r,s,a);return this.#F(t,r,s,e,a)}#F(e,t,r,n,i){let s={inverse:null,undo:[],resurrect:null},a=this.#Me(e,n,s),o=Boolean(r||i),c=(h)=>{if(!o||!h)return;let p=this.#e();if(s.inverse=h.optimistic(this,p,r,n),s.undo.push(...h.busy(this,p,i,n)),this.#D())s.resurrect=h.resurrection(this,p,r,n)},u=g.get("hints");if(!o||u)c(u);let d=()=>this.#Te(e,t,s,a),f=()=>this.#n?this.#n.then(d):d();return this.queue=(this.queue??Promise.resolve()).then(()=>o&&!u?this.#be().then(c).then(f):f()),this.queue}#be(){return this.#K("hints")}#ye(e,t,r,n,i,s){this.#V(e,Hr,t,()=>this.#F(r,n,i,e,s))}#V(e,t,r,n){this.#C(e,t);let i=()=>{this.#C(e,t),n()},s=setTimeout(i,r);if(!Oe(e))e?.addEventListener?.("blur",i,{once:!0});let a=this.#d.get(e);if(!a)this.#d.set(e,a=new Map);a.set(t,{timer:s,flush:i})}#C(e,t){let r=this.#d.get(e),n=r?.get(t);if(!n)return;if(clearTimeout(n.timer),e?.removeEventListener?.("blur",n.flush),r.delete(t),r.size===0)this.#d.delete(e)}#ve(){for(let[e,t]of[...this.#d])for(let r of[...t.keys()])this.#C(e,r)}#we(e,t,r,n,i,s){return this.#G(e,r,t,()=>this.#F(r,n,i,e,s))}#G(e,t,r,n){let i=this.#f.get(e)??new Map;if(i.has(t))return;let s=setTimeout(()=>{if(i.delete(t),i.size===0)this.#f.delete(e)},r);return i.set(t,s),this.#f.set(e,i),n()}#_e(){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}#s(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.#F(e,t)};this.#o("reactive:error",{action:e,params:r,...n,retry:i})}#i(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#Ae(){this.element?.removeAttribute?.("data-reactive-error")}#Se(){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))}#Ee(){{let e=g.get("devtools");if(e)return e.delay();if(mt())return P("devtools").then((t)=>t.delay(),()=>{})}}#D(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#Y(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#Te(e,t,r,n){let{fields:i,files:s}=this.#ee(),a=this.#te(t),o={...i,...a},c=this.#a,u=s.length>0,d=u?this.#Ne(c,e,o,s):JSON.stringify({token:c,act:e,params:o}),f=this.#D()?{action:e,paramNames:Object.keys(a),fieldNames:Object.keys(i),encoding:u?"multipart":"json",status:null,streams:[],tokenRefreshed:!1,started:this.#Y()}:null;await this.#Ee();try{if(navigator.onLine===!1){this.#u(r.inverse),this.#i("offline"),this.#s(e,t,o,{kind:"offline"});return}let h;try{let m={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#We()};if(!u)m["Content-Type"]="application/json";let S=this.#Be();if(S)m["X-Pgbus-Connection"]=S;let D=xt(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(D)m["X-Reactive-Presence"]=D;let Pe=Xt(this.element);if(Pe)m["X-Reactive-Held"]=Pe;wt("action"),h=await fetch(this.#$e(),{method:"POST",headers:m,body:d,credentials:"same-origin",signal:AbortSignal.timeout(this.#qe())})}catch(m){if(console.error("[phlex-reactive] action error",m),this.#u(r.inverse),m?.name==="TimeoutError"||m?.name==="AbortError"){this.#i("timeout"),this.#s(e,t,o,{kind:"timeout"});return}this.#Se(),this.#i("network"),this.#s(e,t,o,{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.#u(r.inverse),this.#i("redirected"),this.#s(e,t,o,{kind:"redirected",status:h.status});return}if(!h.ok){let m=await h.text();if(console.error(`[phlex-reactive] action failed: HTTP ${h.status}`,m),this.#u(r.inverse),(h.headers.get("Content-Type")||"").includes("turbo-stream")){let S=this.#X(m);if(this.#a=S??this.#a,f)this.#_((D)=>D.recordBody(f,m,S));je(this.element,m,!0)}this.#i("http"),this.#s(e,t,o,{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.#u(r.inverse),this.#i("content-type"),this.#s(e,t,o,{kind:"content-type",status:h.status});return}let b=await h.text(),E=this.#X(b);if(this.#a=E??this.#a,f)this.#_((m)=>m.recordBody(f,b,E));if(je(this.element,b,Qt(h)),r.resurrect)queueMicrotask(r.resurrect);return this.#Ae(),this.#o("reactive:applied",{action:e,params:o,html:b}),b}catch(h){console.error("[phlex-reactive] action error",h),this.#u(r.inverse),this.#o("reactive:error",{action:e,params:o,kind:"apply"})}finally{if(n?.(),f)this.#_((h)=>h.trace(this,{...f,ms:this.#Y()-f.started}))}}get#a(){return this.#A??this.tokenValue}set#a(e){this.#A=e}tokenValueChanged(){this.#A=void 0}#X(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:r,self:n}=this.#Fe(t),i=e.match(r);if(i)return i[1];let s=e.match(n);if(s)return s[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#Fe(e){let t=this.#B;if(t&&t.id===e)return t;let r=ir(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>`)}}#c(e){return e.closest('[data-controller~="reactive"]')===this.element}#Q(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#c(t)}#ke(){let e=this.element.querySelectorAll(F);if(e.length===0||[...e].every(ye))return()=>!0;return(t)=>{let r=R(t,F,this.element);if(r===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&R(r.parentElement,F,this.element)===this.element}}#Z(e){if(this.#c(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=R(e,F,this.element);return t===this.element||R(t?.parentElement,F,this.element)===this.element}#xe(){if(this.element.querySelectorAll(F).length===0)return()=>!0;return(e)=>this.#Z(e)}#ee(){let e={},t=[],r=this.#ke(),n=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((o)=>{if(!r(o))return;if(o.type==="file")for(let c of o.files??[])t.push({name:o.name,file:c,multiple:o.multiple});else n.push(o)});let i=[];this.element.querySelectorAll(`[name]${ur}`).forEach((o)=>{if(r(o))i.push(o)});let s=this.#Le(n),a=this.#Re(n);for(let o of n)if(s.has(o.name)){let c=e[o.name]??(e[o.name]=[]);if(o.type==="checkbox"||o.type==="radio"){if(o.checked)c.push(o.value)}else if(o.type==="hidden"){if(!a.has(o.name))c.push(o.value)}else if(o.multiple&&o.options){for(let u of o.options)if(u.selected)c.push(u.value)}else c.push(o.value)}else if(o.type==="checkbox")e[o.name]=o.checked;else if(o.type==="radio"){if(o.checked)e[o.name]=o.value}else e[o.name]=o.value;return i.forEach((o)=>{let c=o.getAttribute("name");if(!c)return;let u=o.getAttribute("data-reactive-editable")!=null?T(o):o.value??o.textContent??o.innerHTML??"",d=e[c];if(String(c).endsWith("[]")&&!dr(o))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}}#Le(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}#Re(e){let t=new Set;for(let r of e)if(r.type==="checkbox")t.add(r.name);return t}#Ne(e,t,r,n){let i=new FormData;i.append("token",e),i.append("act",t);let s=[];for(let[o,c]of Object.entries(r))if(Array.isArray(c)&&String(o).endsWith("[]"))if(c.length===0)s.push(String(o).slice(0,-2));else{let u=`${this.#k(o)}[]`;for(let d of c)i.append(u,String(d))}else this.#$(i,this.#k(o),c);for(let o of s)i.append("empty_groups[]",o);let a=this.#Oe(n);for(let{name:o,file:c,multiple:u}of n){let f=u||a.has(o)?`${this.#k(o)}[]`:this.#k(o);i.append(f,c,c.name)}return i}#k(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("")}`}#$(e,t,r){if(r==null)e.append(t,"");else if(Array.isArray(r))r.forEach((n,i)=>this.#$(e,`${t}[${i}]`,n));else if(typeof r==="object")for(let[n,i]of Object.entries(r))this.#$(e,`${t}[${n}]`,i);else e.append(t,String(r))}#Oe(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))}#te(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Pe(e){return Le(e)}#Ie(e,t){be(e,(r)=>this.#W(r,t),(r,n)=>this.#q(`client op "${r}"`,n))}#x(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#D()}#q(e,t){if(!this.#x())return;this.#_((r)=>r.diagnose(this,e,t))}#_(e){v("devtools",e)}#W(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.#c(n))}#re(e,t){if(e?.checked!=="keep")return!1;let r=t?.type;return r==="checkbox"||r==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Me(e,t,r){this.#Ce(e,t),gt();let n=!1;return()=>{if(n)return;n=!0,this.#De(e,t),bt();for(let i of r.undo)i()}}#Ce(e,t){if(this.#l(t,e,1),this.#l(this.element,e,1),this.#h.set(e,(this.#h.get(e)??0)+1),this.#R++===0)this.element.setAttribute("aria-busy","true");for(let r of this.#ne(e))this.#l(r,e,1)}#De(e,t){this.#l(t,e,-1),this.#l(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.#R<=0)this.#R=0,this.element.removeAttribute("aria-busy");for(let n of this.#ne(e))this.#l(n,e,-1)}#l(e,t,r){if(!e||typeof e.getAttribute!=="function")return;let n=this.#N.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.#N.delete(e),e.removeAttribute("data-reactive-busy");return}this.#N.set(e,n),e.setAttribute("data-reactive-busy",[...n.keys()].join(" "))}#ne(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((r)=>r.getAttribute("data-reactive-busy-on")===e&&this.#c(r))}#$e(){return this.#ie??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#qe(){if(this.#L!=null)return this.#L;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#L=Number.isFinite(t)&&t>0?t:30000}#We(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Be(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)ze();else document.addEventListener("turbo:load",ze,{once:!0});y("persist",()=>import("phlex/reactive/features/persist"),Zr);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"),en);y("sortable",()=>import("phlex/reactive/features/sortable"));y("drag",()=>import("phlex/reactive/features/drag"));y("presence",()=>import("phlex/reactive/features/presence"));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"));Fe();function Zr(e,t){let r=()=>{t.edited=!0},n=(s)=>{let a=s.target;if(s.detail?.success&&a?.tagName==="FORM"&&a.contains?.(e))t.submitted=!0},i=["input","change","lexxy:change","trix-change"];for(let s of i)e.addEventListener?.(s,r);return document.addEventListener("turbo:submit-end",n),()=>{for(let s of i)e.removeEventListener?.(s,r);document.removeEventListener("turbo:submit-end",n)}}function en(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 tn=1000,L=null,Pt,ie=new Set;function rn(e){return Nt(e).then((t)=>{if(e!=="effects")return;Pt=t,t?.sweep()})}dt((e,t)=>{let r=e.detail,n=r?.render;if(typeof n!=="function")return;let i=r.newStream??e.target,s=Rt(nn(i)).filter((o)=>!ie.has(o));if(!t&&!ie.has("effects")&&on(i))s.push("effects");if(s.length===0&&!L)return t?.wrap(e);if(s.length>0){for(let c of s)ie.add(c);let o=L=Promise.race([Promise.all([L,...s.map(rn)]),new Promise((c)=>setTimeout(c,tn))]).then(()=>{if(L!==o)return;L=null,ie.clear()})}let a=L;r.render=async(o)=>{await a;let c={target:e.target,detail:{newStream:r.newStream,render:n}};(t??Pt)?.wrap(c),await c.detail.render(o)}});function nn(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 on(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 yn=Ot;export{pt as ACTIVE_ATTR,ur as EDITOR_SELECTOR,lr as EDITOR_TAGS,vt as REQUESTS_ATTR,or as checkReactiveRegistration,wt as countReactiveRequest,yn as default,T as editableValue,gt as enterReactiveActivity,ir as escapeRegExp,bt as exitReactiveActivity,Nt as loadReactiveFeature,dt as onReactiveStreamWithoutEffects,un as reactiveActivityCount,fn as reactiveFeatureNames,ze as registerReactiveActions,qt as registerReactiveDefer,Fe as registerReactiveDev,Wt as registerReactiveDismiss,Wt as registerReactiveEffects,dn as registerReactiveFeature,y as registerReactiveFeatureLoader,Ht as registerReactiveImageFallback,$t as registerReactiveJs,zt as registerReactiveKeep,Ut as registerReactiveModals,Vt as registerReactiveMorphFocus,er as registerReactiveOffline,Kt as registerReactivePlaintext,gr as registerReactiveRejectedFiles,Wt as registerReactiveStreamRender,Ct as registerReactiveToken,Mt as registerReactiveVisit,ln as resetReactiveActivity,xe as serverText,Rt as unloadedFeaturesFor};
3
+ `;n=!1,t+=s},i=(s)=>{for(let a of s.childNodes){let o=/^(div|p|li)$/.test(a.localName);if(o)n=!0;if(a.nodeType===3)a.data&&r(a.data);else if(a.localName==="br")r(`
4
+ `);else if(a.nodeType===1)i(a);if(o)n=!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 ne=new WeakMap;function Pe(e){if(e?.hasAttribute?.("data-reactive-editable")&&!ne.has(e))ne.set(e,T(e))}function Ie(e){return Pe(e),ne.get(e)}function yn(e){return bn.has(e.localName)?typeof e.value==="string":!0}var Xe=Object.freeze({show:(e,t,n)=>he(e,!1,t,n),hide:(e,t,n)=>he(e,!0,t,n),toggle:(e,t,n)=>he(e,!e.hidden,t,n),add_class:(e,t)=>e.classList.add(...t.classes??[]),remove_class:(e,t)=>e.classList.remove(...t.classes??[]),toggle_class:(e,t)=>(t.classes??[]).forEach((n)=>e.classList.toggle(n)),set_attr:(e,t)=>{if(me(t.name))e.setAttribute(t.name,t.value??"")},remove_attr:(e,t)=>{if(me(t.name))e.removeAttribute(t.name)},toggle_attr:(e,t)=>{if(!me(t.name))return;if(Array.isArray(t.values)){let[n,r]=t.values;e.setAttribute(t.name,e.getAttribute(t.name)===n?r:n)}else if(e.hasAttribute(t.name))e.removeAttribute(t.name);else e.setAttribute(t.name,"")},focus:(e)=>e.focus?.(),focus_first:(e)=>xn(e)?.focus?.(),blur:(e)=>{let t=e.ownerDocument?.activeElement??globalThis.document?.activeElement;if(t&&(t===e||e.contains?.(t)))t.blur?.()},show_modal:(e)=>lt(e),close_dialog:(e)=>Kt(e),click:(e)=>e.click?.(),text:(e,t)=>{let n=String(t.value??"");if(e.textContent!==n)e.textContent=n},copy_media:(e,t,n)=>{let r=null;try{r=n({...t,to:t.from})[0]??null}catch{}Ot(e,r)},check_group:(e,t)=>{let n=t.global?document.querySelectorAll('[data-controller~="reactive"]'):[e];for(let r of n)v("bindings",(i)=>i.checkGroup(r,t.group,t.checked))},presence:(e,t)=>v("presence",(n)=>n.set(e,t.state)),dispatch:(e,t)=>{e.dispatchEvent(new CustomEvent(t.name,{bubbles:!0,composed:!0,detail:t.detail??{}}))},submit:(e,t,n)=>{let r=vn(e);if(!r)return;let i=null;if(t?.submitter!=null&&typeof n==="function"){if(i=n({...t,to:t.submitter})[0]??null,!(i?.form===r&&(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?r.requestSubmit?.(i):r.requestSubmit?.()},paste_into:(e)=>wn(e),preview_file:(e,t,n)=>_n(e,t,n),set_value:(e,t)=>Nt(e,String(t.value??"")),persist_state:(e,t)=>v("persist",(n)=>n.writeState(e,t.state)),persist_clear:(e)=>v("persist",(t)=>t.clearRoot(e))});function vn(e){if(e?.tagName==="FORM")return e;return e?.form??e?.closest?.("form")??null}function wn(e){let t=globalThis.navigator?.clipboard;if(typeof t?.readText!=="function")return;t.readText().then((n)=>{if(!n)return;e.value=n,Lt(e),e.focus?.()}).catch(()=>{})}var I=new Map,M=null;function _n(e,t,n){if(e?.tagName!=="INPUT"||e.type!=="file")return X(`reads an input[type=file], not <${e?.localName}>`);let r=typeof n==="function"?n({...t,to:t.into})[0]:null;if(r?.tagName!=="IMG")return X(`paints an <img>, and ${JSON.stringify(t.into)} is ${r?`a <${r.localName}>`:"not on the page"}`);let i=[...t.valid===!0&&e.validity?.valid===!1?[]:e.files??[]],s=Tn(e,t.accept),a=(u)=>Number.isInteger(t.max_bytes)&&u.size>t.max_bytes,o=[],c;if(t.per_file===!0&&e.multiple){let u=i.filter((f,h)=>{let m=typeof f?.type==="string"&&s(f)?a(f)&&"size":"type";if(m)o.push({reason:m,file:f,index:h});return!m}),d=o.length>0&&!En(e,u)?i.length:u.length;for(let f of o)f.remaining=d;c=u.find((f)=>f.type.startsWith("image/"))}else{let u=i.filter((f)=>typeof f?.type==="string"&&s(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)o.push({reason:d,file:d==="size"?c:i[0]}),c=null}if(xt(r),c){let u=URL.createObjectURL(c);I.set(r,u),r.setAttribute("src",u),Fn()}else r.removeAttribute("src");if(se(r),t.wrap!=null){let u=n({...t,to:t.wrap});if(u.length===0)X(`wrap: ${JSON.stringify(t.wrap)} is not on the page`);for(let d of u)c?ht(d):ft(d)}if(t.name!=null)for(let u of n({...t,to:t.name}))u.textContent=c?c.name:"";if(t.rejected!=null)An(e,n({...t,to:t.rejected}),o,t.rejected);for(let u of o)e.dispatchEvent(new CustomEvent("reactive:file-rejected",{bubbles:!0,detail:u}))}var re="data-reactive-file-rejected";function An(e,t,n,r){if(t.length===0)return Ae(e,`rejected: ${JSON.stringify(r)} is not on the page`);for(let i of t){for(let a of[...i.children])if(a.hasAttribute(re))a.remove();let s=[...i.children].find((a)=>a.localName==="template");if(!s){Ae(e,`rejected: ${JSON.stringify(r)} has no <template> child`);continue}for(let{reason:a,file:o}of n){let c=s.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=o.name;for(let u of[...c.childNodes]){if(u.nodeType!==1)continue;u.setAttribute(re,""),i.append(u)}}}}var Qe=!1;function Sn(){if(Qe)return;if(typeof document>"u"||typeof document.addEventListener!=="function")return;Qe=!0,document.addEventListener("turbo:before-morph-element",(e)=>{let t=e.target,n=e.detail?.newElement;if(!n||e.defaultPrevented||!t.lastElementChild?.hasAttribute(re))return;for(let r of t.children)if(r.hasAttribute(re))n.append(r.cloneNode(!0))})}function En(e,t){if(typeof DataTransfer!=="function")return Ae(e,"per_file: has no DataTransfer to drop the refused files from the input"),!1;let n=new DataTransfer;for(let r of t)n.items.add(r);return e.files=n.files,!0}function Tn(e,t){let n=String((t===!0?e.getAttribute("accept"):typeof t==="string"&&t)||"").toLowerCase().split(",").map((r)=>r.trim()).filter(Boolean);if(n.length===0)return(r)=>r.type.startsWith("image/");return(r)=>{let i=r.type.toLowerCase();return n.some((s)=>s[0]==="."?String(r.name).toLowerCase().endsWith(s):s.endsWith("/*")?i.startsWith(s.slice(0,-1)):i===s)}}function X(e){console.warn(`[phlex-reactive] preview_file ${e} — skipped`)}function Ae(e,t){if(e.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))X(t)}function xt(e){let t=I.get(e);if(t===void 0)return;if(I.delete(e),URL.revokeObjectURL(t),I.size===0)M?.disconnect(),M=null}function Fn(){if(M||typeof MutationObserver!=="function"||!document?.documentElement)return;M=new MutationObserver(()=>{for(let[e,t]of I)if(!e.isConnected||e.getAttribute("src")!==t)xt(e)}),M.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}function Lt(e){if(typeof e.dispatchEvent==="function")e.dispatchEvent(new Event("input",{bubbles:!0}))}function Nt(e,t){if(!/^(input|textarea|select)$/.test(e.localName)||e.type==="file"&&t!==""){console.warn("[phlex-reactive] set_value skipped: not a field it can write",e);return}let n=Ze(e);if(e.value=t,Ze(e)!==n)Lt(e)}function Ze(e){return e.type==="select-multiple"?[...e.selectedOptions].map((t)=>t.value).join(`
6
+ `):e.value}function kn(e,t,n){if(n?.transition)mn(e,n.transition,()=>e.hidden=t);else e.hidden=t}function he(e,t,n,r){if(kn(e,t,n),n?.expanded==null||typeof r!=="function")return;for(let i of r({...n,to:n.expanded}))i.setAttribute?.("aria-expanded",String(!t))}function me(e){if(!Rt(e))return!0;return console.warn(`[phlex-reactive] refused client attr op on ${JSON.stringify(e)} — skipped`),!1}function Ot(e,t){if(e?.localName!=="img")return console.warn(`[phlex-reactive] copy_media targets an <img>, not <${e?.localName}> — skipped`),null;let n=t?.localName==="img"?t:null,r=n?.getAttribute("src"),i=!1;for(let a of["srcset","src"]){let o=r?n.getAttribute(a):null;if(o==null){if(e.hasAttribute(a))i=e.removeAttribute(a)??!0}else if(e.getAttribute(a)!==o)i=e.setAttribute(a,o)??!0}if(i)se(e);let s=n?.getAttribute("alt")??"";if(e.getAttribute("alt")!==s)e.setAttribute("alt",s);return n?s:!1}var Rn='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';function xn(e){return e.querySelectorAll?.(Rn)?.[0]??null}function Me(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 et=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"}),tt=Object.freeze(["meta","ctrl","alt","shift"]);function ae(e,t,n){let r=e.split("+");for(let a of tt)if(r.includes(a)!==Boolean(t[`${a}Key`]))return!1;let i=r.find((a)=>!tt.includes(a));if(i===void 0||typeof t.key!=="string")return!0;let s=n&&Object.hasOwn(n,i)?n[i]:Object.hasOwn(et,i)?et[i]:/^[a-z0-9]$/.test(i)?i:null;return typeof s==="string"&&s.toLowerCase()===t.key.toLowerCase()}var Ln=(e)=>e&&typeof e==="object"?e.keys:String(e),Ce=()=>Q().prevented??=new WeakSet;function pe(e,t){if(t!=null&&!e.defaultPrevented)Ce().add(e);e.preventDefault()}function z(e,t,n){if(t.defaultPrevented&&e?.handled!==!0&&!Ce().has(t))return!1;let r=t.target;if(e?.inEditable!==!0&&(r?.isContentEditable||/^(input|textarea|select)$/.test(r?.localName)))return!1;let i=/[Mm]ac|iP/.test(navigator.userAgentData?.platform??navigator.platform)?"meta":"ctrl";return ae(Ln(e).replace(/^mod\+/,`${i}+`),t,n)}function Nn(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:Me(t),legacy:!0}];let n=[];for(let r of t.split(" ")){if(r==="")continue;let i=null;try{i=JSON.parse(r)}catch{i=null}if(i&&typeof i==="object"&&!Array.isArray(i))n.push(i);else console.warn(`[phlex-reactive] malformed on_client binding record ${JSON.stringify(r)} — skipped`)}return n}function nt(e,t,n){if(e.legacy)return!0;let r=e.on;if(typeof r!=="string"||r==="")return!1;let i=r.indexOf(".");if(t.type!==(i<0?r:r.slice(0,i)))return!1;if(Boolean(e.window)!==$e(t.currentTarget))return!1;return i<0||n===null||ae(r.slice(i+1),t,n)}function On(e,t){let n=e.detail;if(n===void 0)return!0;if(n===null||typeof n!=="object"||Array.isArray(n))return!1;let r=t.detail;if(r===null||typeof r!=="object")return!1;return Object.keys(n).every((i)=>r[i]===n[i])}var rt=new WeakMap;function Pn(e,t,n){if(!n.once)return!1;let r=t.currentTarget??e.element,i=rt.get(e);if(!i)i=new WeakMap,rt.set(e,i);let s=i.get(r);if(!s)s=new Set,i.set(r,s);let a=t.params?.ops,c=(r===globalThis.window?`${typeof a==="string"?a:JSON.stringify(a??null)}|`:"")+JSON.stringify(n);if(s.has(c))return!0;return s.add(c),!1}var it=new WeakMap;function In(e,t){if(e===null||typeof e!=="object")return!1;let n=e.params?.ops,r=typeof n==="string"?n:JSON.stringify(n??null),i=it.get(e);if(!i)i=new WeakMap,it.set(e,i);let s=i.get(t);if(!s)s=new Map,i.set(t,s);let a=s.get(e.currentTarget);if(!a)a=new Set,s.set(e.currentTarget,a);if(a.has(r))return!0;return a.add(r),!1}var Mn=new Set(["click"]);function Se(e,t,n){for(let r of e){if(!Array.isArray(r))continue;let[i,s={}]=r;if(!Object.hasOwn(Xe,i)){console.warn(`[phlex-reactive] unknown client op ${JSON.stringify(i)} — skipped`);continue}let a=t(s);if(a.length===0&&n)n(i,s);if(a.length>1&&Mn.has(i))a=a.slice(0,1);if(a.length>0)s=Dn(i,s,t,n);if(!s)continue;for(let o of a)if(Xe[i](o,s,t),s?.keep===!0)dt(o,i,s,t)}}var Cn=new Set(["set_value","text","set_attr"]);function Dn(e,t,n,r){let i=e==="dispatch",s=i?t.detail_from:Cn.has(e)&&t.from!=null&&{value:t.attr};if(!s||i&&!Object.keys(s).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 o=i?"@trigger":t.from,c;try{c=n({...t,to:o})[0]}catch{}if(!c)return r?.(e,{...t,to:o}),null;let u={...a};for(let[d,f]of Object.entries(s)){let h=$n(c,f);if(h==null)return null;u[d]=h}return i?{...t,detail:u}:{...t,...u}}function $n(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 qn(e,t){let n=e.to;if(n==="@trigger")return[];if(t){if(n==="@root")return[t];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...t.querySelectorAll(n)]}if(typeof n!=="string"||n===""||n==="@root")return[];return[...document.querySelectorAll(n)]}function Wn(e){let t=e.getAttribute?.("data-reactive-persist");return Boolean(t)&&t!=="off"}function De(e){return["defer-token","defer-src","lazy-on","lazy-visible"].some((t)=>e.getAttribute?.(`data-reactive-${t}`)!=null)}var F='[data-controller~="reactive"]',Bn='[data-controller~="reactive"],[data-reactive-dormant~="reactive"]',Ee=(e)=>e.getAttribute?.("data-reactive-token-value")==null&&!De(e);function O(e,t,n){let r=e?.closest?.(t);while(r&&r!==n&&Ee(r))r=r.parentElement?.closest?.(t);return r??null}var H=new WeakMap,K=new WeakMap;function jn(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 Jn(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 Un(e){return e.getAttribute?.("data-reactive-compute-inputs-param")!=null}function zn(e){return Boolean(e.matches?.("[data-reactive-sortable],[data-reactive-sortable-source]")||e.querySelector?.("[data-reactive-sortable],[data-reactive-sortable-source]"))}function Hn(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 Pt(e){return e.getAttribute?.("data-reactive-presence")!=null}function Kn(e){return Boolean(e.matches?.("[data-reactive-countdown]")||e.querySelector?.("[data-reactive-countdown]"))}var Vn=[["persist",[Wn,null,null,!0]],["defer",[De,null]],["form",[jn,null]],["bindings",[Jn,null,null,!0]],["compute",[Un,null,null,!0]],["sortable",[zn,null]],["drag",[Hn,null]],["presence",[Pt,null]],["countdown",[Kn,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]]],A=new Map(Vn),ot=new Map,g=new Map,Gn=new Map;function y(e,t,n){It.set(e,[t,n]),Yn(e)}var It=new Map;function Yn(e){let t=A.get(e),[n,r]=It.get(e);t[1]=n,t[2]=r}function yr(e,t){t.install?.(q),g.set(e,t),Gn.set(e,t)}function Mt(e){let t=[];for(let[n,[r]]of A){if(!r||g.has(n))continue;try{if(e.some((i)=>r(i)))t.push(n)}catch{}}return t}function Ct(e){return C(e).catch((t)=>ie(e,"load",t))}function C(e){let t=ot.get(e);if(!t)t=(A.get(e)[1]??(()=>Promise.reject(Error("this entry has no way to import it"))))().then((r)=>(r.install?.(q),g.set(e,r),r)),ot.set(e,t);return t}var st=new Set;function ie(e,t,n){let r=e+t;if(st.has(r))return;st.add(r),console.error(`[phlex-reactive] the "${e}" feature module (phlex/reactive/features/${e}) is unavailable: ${t}. If you bundle or vendor the client, alias or pin phlex/reactive/features/* (README: esbuild / webpack / bun).`,n)}function v(e,t){let n=g.get(e);if(n)return t(n);C(e).then(t,(r)=>ie(e,"load",r))}var Xn=1e4;function ge(){let e=Number(globalThis.document?.head?.querySelector?.('meta[name="phlex-reactive-feature-timeout"]')?.content);return Number.isFinite(e)&&e>0?e:Xn}function vr(){return[...A.keys()]}var at=Promise.resolve();function ct(e,t,n){let r=q.waiting.get(e);if(r&&r[t]===n)delete r[t]}var q={enter:_t,exit:At,fail:P,count:Tt,text:T,served:Ie,waiting:new WeakMap};var W=Symbol.for("phlex-reactive.early"),Qn=1e4,Zn=1500,$e=(e)=>e!=null&&(e===globalThis.window||e.window===e),er="dispatch";function Q(){return globalThis[W]??={queue:[],connected:new WeakSet},globalThis[W]}function tr(){let e=Number(globalThis.document?.querySelector?.('meta[name="phlex-reactive-early-ttl"]')?.content);return Number.isFinite(e)&&e>0?e:Qn}function nr(e){let t={};for(let{name:n,value:r}of Array.from(e.attributes??[])){let i=/^data-reactive-(.+)-param$/i.exec(n);if(!i)continue;let s;try{s=JSON.parse(r)}catch{s=r}t[i[1].replace(/[-_]([a-z0-9])/g,(a,o)=>o.toUpperCase())]=s}return t}function rr(e,t,n){return{[W]:!0,type:e.type,detail:e.detail,target:e.target,currentTarget:n?t.ownerDocument.defaultView:t,params:nr(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&&!Ce().has(e),preventDefault(){},stopPropagation(){},stopImmediatePropagation(){}}}var oe=new WeakMap;function ir(e,{token:t,type:n,method:r,filter:i,win:s},a){let o=oe.get(e);if(!o)oe.set(e,o=new Map);let c=s?`${t} ${a}`:t;if(o.has(c))return!1;return o.set(c,{type:n,method:r,filter:i,win:s,params:a,armed:!0}),!0}function ut(e,t,n,r){if(e?.[W])return!1;let i=$e(e?.currentTarget),s=i?r:e?.currentTarget,a=sr(e,s,i?`@${t}`:t),o=oe.get(s),c=i&&JSON.stringify(e.params);for(let u of o?.values()??[]){if(!u.armed||u.method!==t||u.type!==e.type||Boolean(u.win)!==i)continue;if(i&&u.params!==c)continue;if(u.filter&&!ae(u.filter,e,n))continue;return u.armed=!1,!0}return a}var Z=new WeakMap;function or(e,t,n){let r=Z.get(e);if(!r)Z.set(e,r=new Map),setTimeout(()=>Z.delete(e));let i=r.get(t)??{};r.set(t,i),i[n]=(i[n]??0)+1}function sr(e,t,n){let r=e&&Z.get(e)?.get(t);if(!r?.[n])return!1;return r[n]-=1,!0}class Dt extends qt{static values={token:String};#A;#d=new Map;#f=new Map;#oe;#x;#j;#L=0;#h=new Map;#N=new WeakMap;#n;featuresReady=at;#r=new Map;#O=new Set;#m=!1;#i=null;#p=new Map;#S=new Map;#g=new Map;#b=0;#J;#je=0;#Je=0;connect(){if(kt=!0,Q().connected.add(this.element),H.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||De(this.element))this.#n=(e)=>{if(e.type==="focusin"?!e.target.hasAttribute?.("data-reactive-editable"):e.target!==this.element)return;if(e.type===V)this.#H();this.#U(!0)},this.element.addEventListener?.("turbo:morph-element",this.#n),this.element.addEventListener?.("focusin",this.#n),this.element.addEventListener?.(V,this.#n);this.element.querySelectorAll?.("[data-reactive-editable]").forEach(Pe),this.#b++,this.featuresReady=at,this.#U(),ee(this.element),this.#ue()}#Ue(e){}#ze(e,t,n,r){}#He(){}#Ke(e,t){}#U(e){{let t=this.#b,n=[];for(let[s,[a]]of A){if(!a||this.#O.has(s))continue;let o=g.get(s);if(o&&!o.connect)continue;try{if(a(this.element))n.push(s)}catch(c){this.#y(s,"detect",c)}}if(n.length===0)return;for(let s of n)this.#O.add(s);if(!this.#m&&n.every((s)=>g.has(s))){for(let s of n)this.#P(t,s,g.get(s),e);return}for(let s of n){let a=this.#se(t,s),o=[];for(let u of A.keys()){if(u===s)break;if(this.#g.has(u))o.push(this.#g.get(u))}let c=Promise.all(o).then(()=>a).then((u)=>u&&this.#P(t,s,u,e));if(this.#g.set(s,c),A.get(s)[3])this.#i=c}let r=this.#i;r?.then(()=>{if(this.#i===r)this.#i=null}),this.#m=!0;let i=Promise.all(this.#g.values()).then(()=>{if(this.featuresReady===i)this.#m=!1});this.featuresReady=i}}#se(e,t){{let n=()=>e===this.#b;return this.#ae(t),new Promise((r)=>{let i=!1,s=setTimeout(()=>{if(this.#p.delete(s),i=!0,n())this.#y(t,"timeout",Error(`not loaded after ${ge()} ms`));r(null)},ge());this.#p.set(s,r);let a=()=>{clearTimeout(s),this.#p.delete(s)};C(t).then((o)=>{if(a(),i)queueMicrotask(()=>this.#P(e,t,o));else r(o)},(o)=>{if(a(),n())this.#y(t,"load",o);r(null)})})}}#ae(e){{let t=A.get(e)[2];if(!t)return;let n={};try{this.#S.set(e,[t(this.element,n),n]),q.waiting.set(this.element,{...q.waiting.get(this.element),[e]:n})}catch(r){this.#y(e,"detect",r)}}}#z(e,t){{let[n,r]=this.#S.get(e)??[];if(this.#S.delete(e),!t)ct(this.element,e,r);try{n?.()}catch(i){console.error(`[phlex-reactive] the "${e}" feature module failed to stop waiting`,i)}return r}}#P(e,t,n,r){{if(e!==this.#b)return;let i=this.#z(t);try{n.connect?.(this,this.#e(),r,i),this.#r.set(t,n)}catch(s){this.#y(t,"connect",s)}}}#e(){return this.#J??={emit:(e,t,n)=>this.#o(e,t,n),reseed:()=>this.#H(),proceed:(e,t,n,r)=>this.#M(e,t,n,0,0,null,r),forgetToken:()=>{this.#A=void 0},owns:(e)=>this.#c(e),ownership:()=>this.#Z(),bindingOwns:(e)=>this.#ee(e),bindingOwnership:()=>this.#xe(),opTargets:(e)=>this.#W(e),diagnose:(e,t)=>this.#q(e,t),applyOps:(e,t)=>Se(e,(n)=>this.#W(t!=null&&n.to==null?{...n,to:t}:n),(n,r)=>this.#q(`client op "${n}"`,r)),listnavOptions:(e)=>this.#w(e),collectFields:()=>this.#te(),plain:bt,text:T,served:Ie,copyMedia:Ot,setValue:Nt,confirm:(e,t)=>Promise.resolve().then(()=>qe(e,t)).catch(()=>!1)},this.#J}#H(){this.#r.get("form")?.reseed(this),this.#r.get("bindings")?.reseed(this),this.#r.get("compute")?.seed(this)}#y(e,t,n){if(ie(e,t,n),this.#t("feature"),P({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:n})}#ce(){{this.#b++;for(let[t,n]of this.#p)clearTimeout(t),n(null);this.#p.clear();for(let t of[...this.#S.keys()]){let n=this.#z(t,!0),r=this.element;v(t,(i)=>{i.abandon?.(r,n),ct(r,t,n)})}this.#O.clear(),this.#g.clear(),this.#m=!1,this.#i=null;let e=[...this.#r];this.#r.clear();for(let[t,n]of e)try{n.disconnect?.(this,this.#e())}catch(r){console.error(`[phlex-reactive] the "${t}" feature module failed to disconnect`,r)}}}#ue(){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.#le();for(let[e,t]of K.get(this.element)??[]){if(e.currentTarget!==t)Object.defineProperty(e,"currentTarget",{value:t,configurable:!0});this.dispatch(e)}K.delete(this.element)}#I=new Set;#le(){let{queue:e}=Q();if(e.length===0)return;let t=[];for(let i=e.length-1;i>=0;i--){let{root:s}=e[i];if(s===this.element||!s.isConnected)t.unshift(...e.splice(i,1))}let n=tr(),r=new Map;for(let i of t){let s=r.get(i.event)??[new Set,new Set];r.set(i.event,s);let a=s[+!!i.win];if(a.has(i.el))continue;a.add(i.el);let o=i.win?Math.min(Zn,n):n,c=i.root!==this.element?"its root left the page before a controller connected":performance.now()-i.at>o?`it is older than the ${o} 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.#de(i)}}#de({event:e,el:t,descs:n,win:r}){let i=rr(e,t,r),s=this.application?.schema?.keyMappings,a=(t.getAttribute("data-action")??"").split(/\s+/),o=r?this.element:t;for(let c of n){if(!a.includes(c.token))continue;if(c.filter&&!ae(c.filter,e,s))continue;if(/#\w+.*:once\b/.test(c.token)){if(!ir(o,c,r&&JSON.stringify(i.params)))continue;this.#I.add(o)}if(or(e,o,r?`@${c.method}`:c.method),c.method==="runOps")this.runOps(i);else this.dispatch(i)}}disconnect(){if(this.#ce(),this.#we(),this.#Ae(),this.#n)this.element.removeEventListener?.("turbo:morph-element",this.#n),this.element.removeEventListener?.("focusin",this.#n),this.element.removeEventListener?.(V,this.#n);if(Q().connected.delete(this.element),H.get(this.element)===this)H.delete(this.element);this.element.removeAttribute?.("data-reactive-connected");for(let e of this.#I)oe.delete(e);this.#I.clear()}dispatch(e){if(e.params?.action&&e.params.action!==Ve&&this.#fe())return this.#he(e);let t=e.params?.shortcut;if(t!=null&&!z(t,e,this.application?.schema?.keyMappings))return;if(ut(e,"dispatch",this.application?.schema?.keyMappings,this.element))return;let{action:n,params:r,debounce:i,throttle:s,confirm:a,confirmWhen:o,outside:c,window:u,optimistic:d,prevent:f}=e.params;if(!n)return;let h=e.params.busy??e.params.loading;if(c&&this.element.contains(e.target))return;let m=e.currentTarget??e.target;if((t!=null||!u&&f!==!1)&&!this.#re(d,m))pe(e,t);if(n===Ve){let E=()=>{{let ue=this.#r.get("defer");if(ue)return ue.materialize(this)}if(this.tokenValue)return this.#M(m,n,"{}")};return this.#m?this.featuresReady.then(E):E()}let b=this.#K(a,o),S=()=>this.#M(m,n,r,i,s,d,h);if(!b)return S();if(b instanceof Promise)return b.then((E)=>E?this.#E(E,m,S):S());this.#E(b,m,S)}#E(e,t,n){return Promise.resolve().then(()=>qe(e,{el:t})).catch(()=>!1).then((r)=>{if(r)n()})}#K(e,t){if(e)return e;if(!t)return null;{let n=g.get("bindings");if(n)return n.confirmMessage(this,this.#e(),t);return this.#V("bindings").then((r)=>r&&r.confirmMessage(this,this.#e(),t))}}#V(e){{let t;return Promise.race([C(e).catch((n)=>(ie(e,"load",n),null)),new Promise((n)=>t=setTimeout(()=>n(null),ge()))]).finally(()=>clearTimeout(t))}}#fe(){return!this.tokenValue&&Ee(this.element)}#he(e){let t=O(this.element.parentElement,Bn);if(!t){if(this.element.closest?.('[data-reactive-verbose="true"], [data-reactive-debug="true"]'))console.warn(`[phlex-reactive] "${e.params.action}": no token on this root or above, nothing sent`);return}let n=H.get(t);if(n)return n.dispatch(e);let{shortcut:r,window:i,optimistic:s,prevent:a}=e.params;if(r!=null&&!z(r,e,this.application?.schema?.keyMappings))return;let o=e.currentTarget??e.target;if((r!=null||!i&&a!==!1)&&!this.#re(s,o))pe(e,r);K.set(t,[...K.get(t)??[],[e,o]]);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&&!z(t.shortcut,e,this.application?.schema?.keyMappings))return;if(ut(e,"runOps",this.application?.schema?.keyMappings,this.element))return;if(In(e,this))return;let n=e.params??{},r=e.currentTarget??e.target,i=Nn(n.ops),s=i.filter((o)=>nt(o,e,null)),a=s.length<=1?s:s.filter((o)=>nt(o,e,this.application?.schema?.keyMappings));if(a.length===0&&i.length>0){if(this.#R())this.#_((o)=>o.noBinding(this,e));return}for(let o of a){if(o.outside&&e[W])continue;if(!On(o,e))continue;let c=o.within==null?r:this.#me(o.within,e);if(o.within!=null&&!c)continue;if(o.shortcut!=null&&!z(o.shortcut,e,this.application?.schema?.keyMappings))continue;if(Pn(this,e,o))continue;this.#pe(o.legacy?{...n,ops:o.ops,debounce:void 0,throttle:void 0,prevent:void 0}:o,e,c,i.indexOf(o),r)}}#me(e,t){let n=t.currentTarget,r=null;try{r=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 r&&r!==n&&n?.contains?.(r)&&this.#c(r)?r:null}#pe(e,t,n,r,i=n){let{ops:s,confirm:a,confirmWhen:o,outside:c,window:u,shortcut:d,prevent:f}=e;if(c&&this.element.contains(t.target))return;if(d!=null||!u&&f!==!1)pe(t,d);let h=this.#K(a,o),m=this.#ge(e,r,i,()=>this.#Me(this.#Ie(s),n));if(!h)return m();if(h instanceof Promise)return h.then((b)=>b?this.#E(b,n,m):m());this.#E(h,n,m)}#ge(e,t,n,r){let i=Number(e.debounce)||0,s=Number(e.throttle)||0;if(i<=0&&s<=0)return r;let a=JSON.stringify([t,e]);if(i>0)return()=>this.#G(n,a,i,r);return()=>this.#Y(n,a,s,r)}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 n=g.get("bindings");if(n)return n[e](this,this.#e(),t);t?.preventDefault?.();let r={currentTarget:t?.currentTarget??null,target:t?.target??null,preventDefault(){}};return v("bindings",(i)=>i[e](this,this.#e(),r))}}trackDirty(){(this.#r.get("form")??g.get("form"))?.scan(this,this.#e())}listnavNext(e){this.#T(e,(t,n)=>t<0?0:(t+1)%n)}listnavPrev(e){this.#T(e,(t,n)=>t<0?n-1:(t-1+n)%n)}listnavFirst(e){this.#T(e,()=>0)}listnavLast(e){this.#T(e,(t,n)=>n-1)}listnavPick(e){let t=this.#w(e),n=t.findIndex((r)=>r.hasAttribute("data-reactive-highlighted"));if(n<0)return;e.preventDefault(),t[n].click()}listnavClose(e){for(let t of this.#w(e))t.removeAttribute("data-reactive-highlighted")}#T(e,t){let n=this.#w(e);if(!n.length)return;e.preventDefault();let r=this.#be(e),i=globalThis.document?.activeElement,s=r?n.findIndex((o)=>o===i||i!=null&&o.contains?.(i)):n.findIndex((o)=>o.hasAttribute("data-reactive-highlighted")),a=n[t(s,n.length)];if(r)a.focus?.();else{for(let o of n)o.removeAttribute("data-reactive-highlighted");a.setAttribute("data-reactive-highlighted","true")}a.scrollIntoView?.({block:"nearest"})}#be(e){return(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-focus-param")==="true"}#w(e){let n=(e?.currentTarget??e?.target??this.element).getAttribute?.("data-reactive-listnav-option-param")??this.element.getAttribute("data-reactive-listnav-option-param");if(!n)return[];let r=this.#Z();return Array.from(this.element.querySelectorAll(n)).filter((i)=>!i.hidden&&r(i))}#M(e,t,n,r,i,s,a){if(this.#o("reactive:before-dispatch",{action:t,params:this.#ne(n),element:this.element},{cancelable:!0}).defaultPrevented)return;let c=Number(r)||0;if(c>0)return this.#ve(e,c,t,n,s,a);let u=Number(i)||0;if(u>0)return this.#_e(e,u,t,n,s,a);return this.#F(t,n,s,e,a)}#F(e,t,n,r,i){let s={inverse:null,undo:[],resurrect:null},a=this.#Ce(e,r,s),o=Boolean(n||i),c=(h)=>{if(!o||!h)return;let m=this.#e();if(s.inverse=h.optimistic(this,m,n,r),s.undo.push(...h.busy(this,m,i,r)),this.#D())s.resurrect=h.resurrection(this,m,n,r)},u=g.get("hints");if(!o||u)c(u);let d=()=>this.#Fe(e,t,s,a),f=()=>this.#i?this.#i.then(d):d();return this.queue=(this.queue??Promise.resolve()).then(()=>o&&!u?this.#ye().then(c).then(f):f()),this.queue}#ye(){return this.#V("hints")}#ve(e,t,n,r,i,s){this.#G(e,er,t,()=>this.#F(n,r,i,e,s))}#G(e,t,n,r){this.#C(e,t);let i=()=>{this.#C(e,t),r()},s=setTimeout(i,n);if(!$e(e))e?.addEventListener?.("blur",i,{once:!0});let a=this.#d.get(e);if(!a)this.#d.set(e,a=new Map);a.set(t,{timer:s,flush:i})}#C(e,t){let n=this.#d.get(e),r=n?.get(t);if(!r)return;if(clearTimeout(r.timer),e?.removeEventListener?.("blur",r.flush),n.delete(t),n.size===0)this.#d.delete(e)}#we(){for(let[e,t]of[...this.#d])for(let n of[...t.keys()])this.#C(e,n)}#_e(e,t,n,r,i,s){return this.#Y(e,n,t,()=>this.#F(n,r,i,e,s))}#Y(e,t,n,r){let i=this.#f.get(e)??new Map;if(i.has(t))return;let s=setTimeout(()=>{if(i.delete(t),i.size===0)this.#f.delete(e)},n);return i.set(t,s),this.#f.set(e,i),r()}#Ae(){for(let e of this.#f.values())for(let t of e.values())clearTimeout(t);this.#f.clear()}#o(e,t,{cancelable:n=!1}={}){let r=new CustomEvent(e,{bubbles:!0,composed:!0,cancelable:n,detail:t});return(this.element.isConnected?this.element:document).dispatchEvent(r),r}#s(e,t,n,r){let i=()=>{if(!this.element.isConnected){console.warn("[phlex-reactive] retry() ignored — the reactive root left the DOM");return}return this.#F(e,t)};P({action:e,kind:r.kind,status:r.status,root:this.element.id}),this.#o("reactive:error",{action:e,params:n,...r,retry:i})}#t(e){if(this.element?.isConnected===!1)return;this.element?.setAttribute?.("data-reactive-error",e)}#Se(){this.element?.removeAttribute?.("data-reactive-error")}#Ee(){let e=document.querySelector("[data-reactive-error-flash]");if(!e?.content)return;let t=e.getAttribute("data-reactive-error-flash")||"flash",n=document.getElementById(t);if(!n)return;n.appendChild(e.content.cloneNode(!0))}#Te(){{let e=g.get("devtools");if(e)return e.delay();if(vt())return C("devtools").then((t)=>t.delay(),()=>{})}}#D(){return this.element?.getAttribute?.("data-reactive-debug")==="true"}#X(){return typeof performance<"u"&&typeof performance.now==="function"?performance.now():Date.now()}async#Fe(e,t,n,r){let{fields:i,files:s}=this.#te(),a=this.#ne(t),o={...i,...a},c=this.#a,u=s.length>0,d=u?this.#Oe(c,e,o,s):JSON.stringify({token:c,act:e,params:o}),f=this.#D()?{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.#Te();try{if(navigator.onLine===!1){this.#u(n.inverse),this.#t("offline"),this.#s(e,t,o,{kind:"offline"});return}let h;try{let p={Accept:"text/vnd.turbo-stream.html","X-CSRF-Token":this.#We()};if(!u)p["Content-Type"]="application/json";let N=this.#Be();if(N)p["X-Pgbus-Connection"]=N;let B=Pt(this.element)&&document.getElementById(`reactive-presence-src-${this.element.id}`)?.getAttribute("connection-id");if(B)p["X-Reactive-Presence"]=B;let j=nn(this.element);if(j)p["X-Reactive-Held"]=j;Tt("action"),h=await fetch(this.#qe(),{method:"POST",headers:p,body:d,credentials:"same-origin",signal:AbortSignal.timeout(this.#B())})}catch(p){if(console.error("[phlex-reactive] action error",p),this.#u(n.inverse),p?.name==="TimeoutError"||p?.name==="AbortError"){this.#t("timeout"),this.#s(e,t,o,{kind:"timeout"});return}this.#Ee(),this.#t("network"),this.#s(e,t,o,{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.#u(n.inverse),this.#t("redirected"),this.#s(e,t,o,{kind:"redirected",status:h.status});return}if(!h.ok){let p=await h.text();if(console.error(`[phlex-reactive] action failed: HTTP ${h.status}`,p),this.#u(n.inverse),(h.headers.get("Content-Type")||"").includes("turbo-stream")){let N=this.#Q(p);if(this.#a=N??this.#a,f)this.#_((j)=>j.recordBody(f,p,N));let B=Ke(this.element,p,!0,this.#B());r?.handoff?.(),await B}this.#t("http"),this.#s(e,t,o,{kind:"http",status:h.status,body:p});return}let m=h.headers.get("Content-Type")||"";if(!m.includes("turbo-stream")){console.error(`[phlex-reactive] expected a turbo-stream, got "${m}" — no update applied`),this.#u(n.inverse),this.#t("content-type"),this.#s(e,t,o,{kind:"content-type",status:h.status});return}let b=await h.text(),S=this.#Q(b);if(this.#a=S??this.#a,f)this.#_((p)=>p.recordBody(f,b,S));let E=Ke(this.element,b,rn(h),this.#B());if(n.resurrect)queueMicrotask(n.resurrect);if(this.#Se(),this.#o("reactive:applied",{action:e,params:o,html:b}),r?.handoff?.(),await E)this.#t("apply"),P({action:e,kind:"apply",root:this.element.id}),this.#o("reactive:error",{action:e,params:o,kind:"apply"});return b}catch(h){console.error("[phlex-reactive] action error",h),this.#u(n.inverse),this.#t("apply"),P({action:e,kind:"apply",root:this.element.id}),this.#o("reactive:error",{action:e,params:o,kind:"apply"})}finally{if(r?.(),f)this.#_((h)=>h.trace(this,{...f,ms:this.#X()-f.started}))}}get#a(){return this.#A??this.tokenValue}set#a(e){this.#A=e}tokenValueChanged(){this.#A=void 0}#Q(e){let t=this.element.id;if(!t)return e.match(/data-reactive-token-value="([^"]+)"/)?.[1];let{token:n,self:r}=this.#ke(t),i=e.match(n);if(i)return i[1];let s=e.match(r);if(s)return s[1].match(/data-reactive-token-value="([^"]+)"/)?.[1];return}#ke(e){let t=this.#j;if(t&&t.id===e)return t;let n=dn(e);return this.#j={id:e,token:new RegExp(`<turbo-stream\\b[^>]*\\baction="reactive:token"[^>]*\\btarget="${n}"[^>]*\\bdata-reactive-token-value="([^"]+)"`),self:new RegExp(`<turbo-stream\\b[^>]*\\baction="(?:replace|update)"[^>]*\\btarget="${n}"[^>]*>([\\s\\S]*?)</turbo-stream>`)}}#c(e){return e.closest('[data-controller~="reactive"]')===this.element}#Z(){if(this.element.querySelectorAll('[data-controller~="reactive"]').length===0)return()=>!0;return(t)=>this.#c(t)}#Re(){let e=this.element.querySelectorAll(F);if(e.length===0||[...e].every(Ee))return()=>!0;return(t)=>{let n=O(t,F,this.element);if(n===this.element)return!0;return t.getAttribute("data-reactive-shared-field")!=null&&O(n.parentElement,F,this.element)===this.element}}#ee(e){if(this.#c(e))return!0;if(e.getAttribute?.("data-reactive-shared-field")==null)return!1;let t=O(e,F,this.element);return t===this.element||O(t?.parentElement,F,this.element)===this.element}#xe(){if(this.element.querySelectorAll(F).length===0)return()=>!0;return(e)=>this.#ee(e)}#te(){let e={},t=[],n=this.#Re(),r=[];this.element.querySelectorAll("input[name], select[name], textarea[name]").forEach((o)=>{if(!n(o))return;if(o.type==="file")for(let c of o.files??[])t.push({name:o.name,file:c,multiple:o.multiple});else r.push(o)});let i=[];this.element.querySelectorAll(`[name]${gn}`).forEach((o)=>{if(n(o))i.push(o)});let s=this.#Le(r),a=this.#Ne(r);for(let o of r)if(s.has(o.name)){let c=e[o.name]??(e[o.name]=[]);if(o.type==="checkbox"||o.type==="radio"){if(o.checked)c.push(o.value)}else if(o.type==="hidden"){if(!a.has(o.name))c.push(o.value)}else if(o.multiple&&o.options){for(let u of o.options)if(u.selected)c.push(u.value)}else c.push(o.value)}else if(o.type==="checkbox")e[o.name]=o.checked;else if(o.type==="radio"){if(o.checked)e[o.name]=o.value}else e[o.name]=o.value;return i.forEach((o)=>{let c=o.getAttribute("name");if(!c)return;let u=o.getAttribute("data-reactive-editable")!=null?T(o):o.value??o.textContent??o.innerHTML??"",d=e[c];if(String(c).endsWith("[]")&&!yn(o))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}}#Le(e){let t=new Set;for(let n of e){if(n.type==="radio")continue;if(String(n.name).endsWith("[]"))t.add(n.name)}return t}#Ne(e){let t=new Set;for(let n of e)if(n.type==="checkbox")t.add(n.name);return t}#Oe(e,t,n,r){let i=new FormData;i.append("token",e),i.append("act",t);let s=[];for(let[o,c]of Object.entries(n))if(Array.isArray(c)&&String(o).endsWith("[]"))if(c.length===0)s.push(String(o).slice(0,-2));else{let u=`${this.#k(o)}[]`;for(let d of c)i.append(u,String(d))}else this.#$(i,this.#k(o),c);for(let o of s)i.append("empty_groups[]",o);let a=this.#Pe(r);for(let{name:o,file:c,multiple:u}of r){let f=u||a.has(o)?`${this.#k(o)}[]`:this.#k(o);i.append(f,c,c.name)}return i}#k(e){let t=String(e),n=t.indexOf("[");if(n===-1)return`params[${t}]`;return`params${[t.slice(0,n),...t.slice(n).match(/[^\[\]]+/g)??[]].map((i)=>`[${i}]`).join("")}`}#$(e,t,n){if(n==null)e.append(t,"");else if(Array.isArray(n))n.forEach((r,i)=>this.#$(e,`${t}[${i}]`,r));else if(typeof n==="object")for(let[r,i]of Object.entries(n))this.#$(e,`${t}[${r}]`,i);else e.append(t,String(n))}#Pe(e){let t=new Map;for(let{name:n}of e)t.set(n,(t.get(n)??0)+1);return new Set([...t].filter(([,n])=>n>1).map(([n])=>n))}#ne(e){if(!e)return{};try{return typeof e==="string"?JSON.parse(e):e}catch{return{}}}#Ie(e){return Me(e)}#Me(e,t){Se(e,(n)=>this.#W(n,t),(n,r)=>this.#q(`client op "${n}"`,r))}#R(){return this.element?.getAttribute?.("data-reactive-verbose")==="true"||this.#D()}#q(e,t){if(!this.#R())return;this.#_((n)=>n.diagnose(this,e,t))}#_(e){v("devtools",e)}#W(e,t){let n=e.to;if(n==="@root")return[this.element];if(n==="@trigger")return t?.nodeType===1?[t]:[];if(typeof n!=="string"||n==="")return[];if(e.global)return[...document.querySelectorAll(n)];return[...this.element.querySelectorAll(n)].filter((r)=>this.#c(r))}#re(e,t){if(e?.checked!=="keep")return!1;let n=t?.type;return n==="checkbox"||n==="radio"}#u(e){if(!e)return;if(!this.element.isConnected)return;for(let t of e)t()}#Ce(e,t,n){this.#De(e,t),_t();let r=!1,i=!1,s=()=>{if(r)return;r=!0,this.#$e(e,t);for(let o of n.undo)o()},a=()=>{if(i)return;i=!0,s(),At()};return a.handoff=s,a}#De(e,t){if(this.#l(t,e,1),this.#l(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 n of this.#ie(e))this.#l(n,e,1)}#$e(e,t){this.#l(t,e,-1),this.#l(this.element,e,-1);let n=(this.#h.get(e)??1)-1;if(n<=0)this.#h.delete(e);else this.#h.set(e,n);if(--this.#L<=0)this.#L=0,this.element.removeAttribute("aria-busy");for(let r of this.#ie(e))this.#l(r,e,-1)}#l(e,t,n){if(!e||typeof e.getAttribute!=="function")return;let r=this.#N.get(e)??new Map,i=(r.get(t)??0)+n;if(i<=0)r.delete(t);else r.set(t,i);if(r.size===0){this.#N.delete(e),e.removeAttribute("data-reactive-busy");return}this.#N.set(e,r),e.setAttribute("data-reactive-busy",[...r.keys()].join(" "))}#ie(e){return[...this.element.querySelectorAll?.("[data-reactive-busy-on]")??[]].filter((n)=>n.getAttribute("data-reactive-busy-on")===e&&this.#c(n))}#qe(){return this.#oe??=document.querySelector('meta[name="phlex-reactive-action-path"]')?.content||"/reactive/actions"}#B(){if(this.#x!=null)return this.#x;let e=document.querySelector('meta[name="phlex-reactive-timeout"]')?.content,t=Number(e);return this.#x=Number.isFinite(t)&&t>0?t:30000}#We(){return document.querySelector('meta[name="csrf-token"]')?.content??""}#Be(){return document.querySelector("pgbus-stream-source[connection-id]")?.getAttribute("connection-id")||document.querySelector('meta[name="pgbus-connection-id"]')?.content||null}}if(typeof window<"u")if(window.Turbo)Ye();else document.addEventListener("turbo:load",Ye,{once:!0});y("persist",()=>import("phlex/reactive/features/persist"),ar);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"),cr);y("sortable",()=>import("phlex/reactive/features/sortable"));y("drag",()=>import("phlex/reactive/features/drag"));y("presence",()=>import("phlex/reactive/features/presence"));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"));Oe();function ar(e,t){let n=()=>{t.edited=!0},r=(s)=>{let a=s.target;if(s.detail?.success&&a?.tagName==="FORM"&&a.contains?.(e))t.submitted=!0},i=["input","change","lexxy:change","trix-change"];for(let s of i)e.addEventListener?.(s,n);return document.addEventListener("turbo:submit-end",r),()=>{for(let s of i)e.removeEventListener?.(s,n);document.removeEventListener("turbo:submit-end",r)}}function cr(e,t){let n=()=>{t.edited=!0};return e.addEventListener?.("input",n),e.addEventListener?.("change",n),()=>{e.removeEventListener?.("input",n),e.removeEventListener?.("change",n)}}var ur=1000,L=null,$t,ce=new Set;function lr(e){return Ct(e).then((t)=>{if(e!=="effects")return;$t=t,t?.sweep()})}gt((e,t)=>{let n=e.detail,r=n?.render;if(typeof r!=="function")return;let i=n.newStream??e.target,s=Mt(dr(i)).filter((o)=>!ce.has(o));if(!t&&!ce.has("effects")&&fr(i))s.push("effects");if(s.length===0&&!L)return t?.wrap(e);if(s.length>0){for(let c of s)ce.add(c);let o=L=Promise.race([Promise.all([L,...s.map(lr)]),new Promise((c)=>setTimeout(c,ur))]).then(()=>{if(L!==o)return;L=null,ce.clear()})}let a=L;n.render=async(o)=>{await a;let c={target:e.target,detail:{newStream:n.newStream,render:r}};(t??$t)?.wrap(c),await c.detail.render(o)}});function dr(e){let t=e?.querySelector?.("template")?.content;if(!t)return[];let n=[...t.querySelectorAll?.('[data-controller~="reactive"]')??[]];for(let r of t.children??[])if(r.matches?.('[data-controller~="reactive"]')&&!n.includes(r))n.unshift(r);return n.push(t),n}function fr(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 Tr=Dt;export{wt as ACTIVE_ATTR,gn as EDITOR_SELECTOR,bn as EDITOR_TAGS,_e as ERRORS_ATTR,Et as REQUESTS_ATTR,fn as checkReactiveRegistration,Tt as countReactiveRequest,Tr as default,T as editableValue,_t as enterReactiveActivity,dn as escapeRegExp,At as exitReactiveActivity,Ct as loadReactiveFeature,gt as onReactiveStreamWithoutEffects,gr as reactiveActivityCount,vr as reactiveFeatureNames,P as recordReactiveError,Ye as registerReactiveActions,Ut as registerReactiveDefer,Oe as registerReactiveDev,zt as registerReactiveDismiss,zt as registerReactiveEffects,yr as registerReactiveFeature,y as registerReactiveFeatureLoader,Xt as registerReactiveImageFallback,Jt as registerReactiveJs,Yt as registerReactiveKeep,Gt as registerReactiveModals,Zt as registerReactiveMorphFocus,an as registerReactiveOffline,Qt as registerReactivePlaintext,Sn as registerReactiveRejectedFiles,zt as registerReactiveStreamRender,Bt as registerReactiveToken,Wt as registerReactiveVisit,br as resetReactiveActivity,Ie as serverText,Mt as unloadedFeaturesFor};
7
7
 
8
- //# debugId=461386F5E173C8F964756E2164756E21
8
+ //# debugId=FF0BCD9F1847675464756E2164756E21
9
9
  //# sourceMappingURL=core.min.js.map