phlex-reactive 0.4.4 → 0.4.5
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 781352f05403f22ccf974061e325f0066b9809c20de36a881279fcea424c55a5
|
|
4
|
+
data.tar.gz: dfd1747be189e0c451f390f396d535aa5c36f7e0fd8d95f31a331a584537976c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14e5f543ebb18929407b21a90f6851fcbc685954d23c2ef9aa6a37ed770c85bdf7d477bb430799f81837d04a31154ea85343406e6767f128862fecec82aca401
|
|
7
|
+
data.tar.gz: 55d32359caa8bb5aa7be4b8db1c55cdf58651b08361dd4bd5e87e4b7bf50dd4cdb32d3aaede40be35966e28cf994ff8047006c085f17fc9002bc26f9cc3cf4d7
|
|
@@ -168,9 +168,22 @@ export default class extends Controller {
|
|
|
168
168
|
// a per-controller promise makes each dispatch wait for the previous one, so
|
|
169
169
|
// it always uses the freshest token.
|
|
170
170
|
dispatch(event) {
|
|
171
|
-
const { action, params, debounce } = event.params
|
|
171
|
+
const { action, params, debounce, confirm } = event.params
|
|
172
172
|
if (!action) return
|
|
173
173
|
|
|
174
|
+
// Confirmation gate (issue #52). A destructive reactive trigger can't use
|
|
175
|
+
// Hotwire's data-turbo-confirm — this controller preempts the event — so a
|
|
176
|
+
// `confirm:` message threads a data-reactive-confirm-param and we prompt
|
|
177
|
+
// HERE, BEFORE any preventDefault/enqueue/debounce. On decline we still
|
|
178
|
+
// preventDefault (so a `submit`/click can't natively navigate on cancel)
|
|
179
|
+
// and bail — nothing is enqueued, no timer is scheduled. window.confirm is
|
|
180
|
+
// synchronous + screen-reader friendly and keeps the no-dependency default;
|
|
181
|
+
// a richer/async dialog can be layered on additively later.
|
|
182
|
+
if (confirm && !window.confirm(confirm)) {
|
|
183
|
+
event.preventDefault()
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
|
|
174
187
|
// Stop native behavior (button submit / FORM NAVIGATION) HERE, synchronously
|
|
175
188
|
// within the event dispatch. preventDefault() only works while the event is
|
|
176
189
|
// still being handled — deferring it into the request-queue microtask (below)
|
|
@@ -304,13 +304,22 @@ module Phlex
|
|
|
304
304
|
# live-update-as-you-type doesn't POST per keystroke. A blur flushes a
|
|
305
305
|
# pending dispatch so the last edit is never dropped. Omit it for the
|
|
306
306
|
# immediate-dispatch default.
|
|
307
|
+
#
|
|
308
|
+
# `confirm:` (a message string) gates the action behind a confirmation
|
|
309
|
+
# prompt (issue #52). Destructive reactive triggers can't use Hotwire's
|
|
310
|
+
# `data-turbo-confirm` — the reactive controller calls preventDefault and
|
|
311
|
+
# enqueues the POST itself, so Turbo's confirm handling never runs. The
|
|
312
|
+
# client shows window.confirm(message) FIRST and bails before any
|
|
313
|
+
# enqueue/debounce if the user declines (and prevents the native default so
|
|
314
|
+
# a `submit` trigger can't navigate on cancel). Omit it for no prompt.
|
|
315
|
+
# button(**on(:destroy, confirm: "Really delete this item?")) { "Delete" }
|
|
307
316
|
# The verbatim JSON for an empty explicit-params payload. The common
|
|
308
317
|
# trigger (on(:increment), no params) hits this on EVERY render — skipping
|
|
309
318
|
# params.to_json (which re-serializes {} to the same "{}" each time) avoids
|
|
310
319
|
# a per-render allocation while keeping the wire format byte-identical.
|
|
311
320
|
EMPTY_PARAMS_JSON = "{}"
|
|
312
321
|
|
|
313
|
-
def on(action_name, event: "click", debounce: nil, **params)
|
|
322
|
+
def on(action_name, event: "click", debounce: nil, confirm: nil, **params)
|
|
314
323
|
attrs = {
|
|
315
324
|
data: {
|
|
316
325
|
action: "#{event}->reactive#dispatch",
|
|
@@ -319,6 +328,7 @@ module Phlex
|
|
|
319
328
|
}
|
|
320
329
|
}
|
|
321
330
|
attrs[:data][:reactive_debounce_param] = debounce if debounce
|
|
331
|
+
attrs[:data][:reactive_confirm_param] = confirm if confirm
|
|
322
332
|
attrs[:type] = "button" if event == "click"
|
|
323
333
|
attrs
|
|
324
334
|
end
|