lostcoords-ui 0.12.1 → 0.12.2
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: 8826e4a226e995babe0ca3b5c0b8acc0814e018e992e685d2792f73d499df817
|
|
4
|
+
data.tar.gz: 9b567d198b078a9dc9e07c4fcddc5ab8271febae59bc088c556e9bb2616f46b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87f135447441e6fa94670fe213ae19c3e9e04d377c174aa9ce27df733b130dfbd8e1c92fd461d663fbbb8d3dfe957ce89d9b3752b9cacc17e9b1a7a501e8fb60
|
|
7
|
+
data.tar.gz: 720a4d496cb092ee008ec9d7580606804feb1f72d1b1086e5e7cbad0f972755b32df1d13d882a2ac3c470b7de855f9d2f36771314d58f1ee008538967675dfbf
|
data/README.md
CHANGED
|
@@ -170,6 +170,15 @@ Omit `only` to register every library controller. Unknown identifiers raise befo
|
|
|
170
170
|
registered, and repeated calls on the same application keep later overrides, so register defaults
|
|
171
171
|
before application overrides.
|
|
172
172
|
|
|
173
|
+
## Changes in 0.12.2
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit. Fixed:
|
|
176
|
+
|
|
177
|
+
- **Back no longer brings a dialog back half open.** Turbo snapshots a page with its open dialogs, and
|
|
178
|
+
restoring one kept the `open` attribute without the top layer: no backdrop, focus trap or Escape, and the
|
|
179
|
+
page stayed pinned by the scroll lock. A dialog joined through `registerDialog` now comes back closed and
|
|
180
|
+
the page unpinned; a controller that reopens its dialog on connect shows it as a real modal again.
|
|
181
|
+
|
|
173
182
|
## Changes in 0.12.1
|
|
174
183
|
|
|
175
184
|
Nothing needs an edit. Changed:
|
|
@@ -2,6 +2,22 @@ import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
|
2
2
|
|
|
3
3
|
const registrations = new WeakMap()
|
|
4
4
|
|
|
5
|
+
// Turbo snapshots a page for Back with its open dialogs, and restoring one brings back the open
|
|
6
|
+
// attribute but not the top layer: the dialog shows inline, with no backdrop, focus trap or
|
|
7
|
+
// Escape. A dialog registered when the snapshot was taken is marked, so it comes back closed.
|
|
8
|
+
const MARK = "lcDialog"
|
|
9
|
+
document.addEventListener("turbo:before-render", ({ detail: { newBody } }) => {
|
|
10
|
+
for (const dialog of newBody.querySelectorAll("dialog[data-lc-dialog]")) {
|
|
11
|
+
dialog.removeAttribute("open")
|
|
12
|
+
delete dialog.dataset[MARK]
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
// A same-URL refresh morphs the page against server HTML, which never carries the mark.
|
|
16
|
+
document.addEventListener("turbo:before-morph-attribute", (event) => {
|
|
17
|
+
if (event.detail.attributeName === "data-lc-dialog" && registrations.has(event.target))
|
|
18
|
+
event.preventDefault()
|
|
19
|
+
})
|
|
20
|
+
|
|
5
21
|
// Shows a modal <dialog> with focus on the dialog itself rather than its first control: a close
|
|
6
22
|
// button would draw the focus ring after a tap that focused nothing, and a first field would raise
|
|
7
23
|
// a phone's keyboard. A control marked autofocus still takes focus, and Tab reaches every control.
|
|
@@ -53,12 +69,14 @@ export function registerDialog(
|
|
|
53
69
|
const unregister = () => {
|
|
54
70
|
if (registrations.get(dialog) !== unregister) return
|
|
55
71
|
registrations.delete(dialog)
|
|
72
|
+
delete dialog.dataset[MARK]
|
|
56
73
|
dialog.removeEventListener("close", unregisterOnClose)
|
|
57
74
|
dialog.removeEventListener("click", closeOnBackdrop)
|
|
58
75
|
unregisterDismissable()
|
|
59
76
|
}
|
|
60
77
|
|
|
61
78
|
registrations.set(dialog, unregister)
|
|
79
|
+
dialog.dataset[MARK] = ""
|
|
62
80
|
dialog.addEventListener("close", unregisterOnClose)
|
|
63
81
|
dialog.addEventListener("click", closeOnBackdrop)
|
|
64
82
|
return unregister
|
|
@@ -167,12 +167,22 @@ function unlockDocumentScroll() {
|
|
|
167
167
|
const body = document.body
|
|
168
168
|
if (body?.dataset.modalScrollLock !== "true") return
|
|
169
169
|
|
|
170
|
+
releaseScrollLock(body)
|
|
171
|
+
window.scrollTo({ top: lockedScrollY, behavior: "instant" })
|
|
172
|
+
lockedScrollY = 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function releaseScrollLock(body) {
|
|
170
176
|
body.style.position = ""
|
|
171
177
|
body.style.inset = ""
|
|
172
178
|
body.style.top = ""
|
|
173
179
|
body.style.removeProperty("--lc-scroll-lock-y")
|
|
174
180
|
body.style.inlineSize = ""
|
|
175
181
|
delete body.dataset.modalScrollLock
|
|
176
|
-
window.scrollTo({ top: lockedScrollY, behavior: "instant" })
|
|
177
|
-
lockedScrollY = 0
|
|
178
182
|
}
|
|
183
|
+
|
|
184
|
+
// A page snapshotted for Back while a dialog held the lock comes back pinned; the dialog
|
|
185
|
+
// that held it comes back closed (helpers/dialog), so the restored page is free to scroll.
|
|
186
|
+
document.addEventListener("turbo:before-render", ({ detail: { newBody } }) => {
|
|
187
|
+
if (newBody.dataset.modalScrollLock === "true") releaseScrollLock(newBody)
|
|
188
|
+
})
|