lostcoords-ui 0.14.12 → 0.14.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 +4 -4
- data/README.md +42 -3
- data/app/assets/tailwind/lostcoords/ui/core.css +1 -1
- data/app/assets/tailwind/lostcoords/ui/dialog.css +12 -0
- data/app/assets/tailwind/lostcoords/ui/popover.css +5 -3
- data/app/assets/tailwind/lostcoords/ui/sheet.css +6 -0
- data/app/helpers/lostcoords/ui/render_attributes_helper.rb +10 -1
- data/app/javascript/lostcoords/ui/controllers/lc_light_dismiss_controller.js +72 -0
- data/app/javascript/lostcoords/ui/controllers/lc_sheet_controller.js +102 -10
- data/app/javascript/lostcoords/ui/helpers/confirm.js +8 -3
- data/app/javascript/lostcoords/ui/helpers/dialog.js +11 -0
- data/app/javascript/lostcoords/ui/helpers/sheet_motion.js +3 -4
- data/app/javascript/lostcoords/ui/helpers/top_layer.js +48 -3
- data/app/javascript/lostcoords/ui/index.js +2 -0
- data/lib/lostcoords/ui/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dd77dbe9de01d08ee1a49ee39764c0e4de02307ea2be5a2f7eebe000aca2b0c4
|
|
4
|
+
data.tar.gz: 80ca196ac506c0a6410dc7b1d761517c4935b855f24b729d153f468bc752b1b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7458a749f77b100455d279d532b5ab6933aa7c6b10bedf399ed6910e84dbf813baec8058bd3c2e73b722c20e6f2362f2810cc657886f7c2e661bde49cdfbbe1a
|
|
7
|
+
data.tar.gz: '0324502035085506805b9c0fd65c985404061a52f3cf9a115851954a6b9e66cd01e34d49073da26a674381bae30c78ced352d3f21747b2139a9245aea67e2968'
|
data/README.md
CHANGED
|
@@ -170,6 +170,38 @@ 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.14.14
|
|
174
|
+
|
|
175
|
+
Nothing needs an edit; a host that waits on a dialog's animations after `close()` before clearing up can
|
|
176
|
+
use `closeDialog` instead. Added:
|
|
177
|
+
|
|
178
|
+
- **`closeDialog(dialog)`** in `lostcoords/ui/helpers/dialog` closes a dialog and settles once it has left.
|
|
179
|
+
In Safari `close()` now returns while the dialog is still open for its exit, so code that checked
|
|
180
|
+
`dialog.open` after its animations could find it open.
|
|
181
|
+
- **The `lc-light-dismiss` controller** comes with every `popover: true` or `popover: "auto"` an lc builder
|
|
182
|
+
renders. It closes the popover itself on a tap outside, Escape or a `popovertarget` hide, with its exit:
|
|
183
|
+
Safari dropped a native popover in the frame the browser closed it.
|
|
184
|
+
- **`data-lc-popover-close`** on a link or button inside such a popover closes it, with its exit, so an
|
|
185
|
+
in-page link in a menu needs no controller of its own.
|
|
186
|
+
- **`hidePopoverAfterExit(popover)`** in `lostcoords/ui/helpers/top_layer` hides a popover from your code
|
|
187
|
+
with its exit.
|
|
188
|
+
|
|
189
|
+
## Changes in 0.14.13
|
|
190
|
+
|
|
191
|
+
Nothing needs an edit. Fixed:
|
|
192
|
+
|
|
193
|
+
- **Overlays animate out in Safari.** WebKit can't transition `overlay` or `display`, so a closing dialog,
|
|
194
|
+
phone sheet, menu, popover or tooltip left the screen in the frame it closed; a sheet released halfway
|
|
195
|
+
down vanished mid-slide. `lc-sheet` now holds a closing dialog in its exit pose (`[data-closing]`) until
|
|
196
|
+
the slide or fade ends, whether `close()`, Escape, the backdrop, a swipe or a `method="dialog"` form
|
|
197
|
+
closed it, and a lifted panel stays in the top layer, shown as it was, until its exit ends. Chrome keeps
|
|
198
|
+
its native exit. Where the exit is held, `close` fires when it ends; `lc-sheet:exit` fires as it starts,
|
|
199
|
+
and the confirm sheet answers then.
|
|
200
|
+
- **A sheet held still before lifting settles back.** It kept the finger's speed from before the pause,
|
|
201
|
+
so a slow drag, a pause and a lift could dismiss it.
|
|
202
|
+
- **A released sheet carries on at the finger's speed**, shortening its slide (to 240ms at least) instead
|
|
203
|
+
of always taking the full 500ms.
|
|
204
|
+
|
|
173
205
|
## Changes in 0.14.12
|
|
174
206
|
|
|
175
207
|
Needs an edit only if you import component entries one by one: `emoji-picker` now also needs `dialog`,
|
|
@@ -657,7 +689,10 @@ your own controls with the `lc-disabled:` and `lc-pending:` variants, which tell
|
|
|
657
689
|
|
|
658
690
|
Use native attributes for application behavior, `class:` to merge additional Tailwind utilities, and
|
|
659
691
|
theme tokens to restyle the library. `popover: true` renders `popover="auto"`, as a bare `popover`
|
|
660
|
-
attribute does
|
|
692
|
+
attribute does, with the `lc-light-dismiss` controller: it makes the popover manual once it connects and
|
|
693
|
+
closes it itself on a tap outside, Escape, a `popovertarget` button that hides it, or a click on an
|
|
694
|
+
element inside marked `data-lc-popover-close`, so its exit plays in Safari too. Without JavaScript it stays
|
|
695
|
+
a native auto popover. `lc_field` yields the input's `id` and validation attributes so
|
|
661
696
|
labels, hints and errors stay connected. Linked cards use `lc_card(href: ...)`; cards containing
|
|
662
697
|
buttons or fields remain ordinary containers.
|
|
663
698
|
|
|
@@ -1173,7 +1208,9 @@ it, and the page stops scrolling behind it.
|
|
|
1173
1208
|
`registerDialog(dialog, { close, priority, restoreFocus, lockScroll })`: `close` may return `false` to keep the dialog open, such as while it asks to discard changes; `priority` ranks it against panels open in
|
|
1174
1209
|
it (a dialog is 10, a panel 20); `restoreFocus` runs after a close; `lockScroll: false` leaves the page
|
|
1175
1210
|
scrollable. It returns the unregister function and ends when the dialog closes; a click on the dialog's own
|
|
1176
|
-
padding does not close it.
|
|
1211
|
+
padding does not close it. `closeDialog(dialog, returnValue)` closes it and returns a promise that settles
|
|
1212
|
+
once it has left, closed and with its exit over; clear up after a dialog (empty its frame, remove it) when
|
|
1213
|
+
that settles, not when `close()` returns, since Safari keeps a dialog open while its exit plays.
|
|
1177
1214
|
|
|
1178
1215
|
```erb
|
|
1179
1216
|
<button type="button" popovertarget="filters">Filters</button>
|
|
@@ -1181,7 +1218,9 @@ padding does not close it.
|
|
|
1181
1218
|
data: { action: "lc-sheet:dismiss->filters#reset" } do %>…<% end %>
|
|
1182
1219
|
```
|
|
1183
1220
|
|
|
1184
|
-
`lc-popover-shell` gives a native `[popover]` menu the same enter and exit as FloatingPanel panels
|
|
1221
|
+
`lc-popover-shell` gives a native `[popover]` menu the same enter and exit as FloatingPanel panels;
|
|
1222
|
+
`hidePopoverAfterExit(popover)` from `lostcoords/ui/helpers/top_layer` hides one from your own code with
|
|
1223
|
+
its exit, as `lc-light-dismiss` does. Set
|
|
1185
1224
|
`--lc-popover-from` to change the closed pose and an `origin-*` utility for where it grows from.
|
|
1186
1225
|
|
|
1187
1226
|
`lc_hovercard` previews what a link points to, such as a profile over a name, with the `lc-hovercard`
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
@import "./theme.css";
|
|
6
6
|
@source "../../../../helpers/lostcoords/ui/{avatar_badge,badge,button,card,choice,copy_button,description_list,feedback,file_drop,form,glass,icon,layout,list_group,navigation,primitives,render_attributes,structures,tailwind,translation,typography}_helper.rb";
|
|
7
7
|
@source "../../../../javascript/lostcoords/ui/helpers/*.js";
|
|
8
|
-
@source "../../../../javascript/lostcoords/ui/controllers/lc_{char_counter,copy,kbd,nav,scroll_keeper,selection,shortcut,tabs,toc,toggle}_controller.js";
|
|
8
|
+
@source "../../../../javascript/lostcoords/ui/controllers/lc_{char_counter,copy,kbd,light_dismiss,nav,scroll_keeper,selection,shortcut,tabs,toc,toggle}_controller.js";
|
|
9
9
|
@source "../../../../../lib/lostcoords/ui/parts.rb";
|
|
10
10
|
|
|
11
11
|
@import "./glass.css";
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/* Where `overlay` can't transition, lc-sheet holds a closing dialog open in its exit pose. */
|
|
33
|
+
&[open][data-closing] {
|
|
34
|
+
opacity: 0;
|
|
35
|
+
transform: var(--lc-dialog-from);
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
/* Fades the tint and the blur, not opacity: Chrome applies a backdrop-filter
|
|
33
39
|
under opacity < 1 to only some of the page's layers. */
|
|
34
40
|
&::backdrop {
|
|
@@ -73,6 +79,12 @@
|
|
|
73
79
|
backdrop-filter: none;
|
|
74
80
|
}
|
|
75
81
|
|
|
82
|
+
/* After the context scrim, which it must outrank. */
|
|
83
|
+
&[open][data-closing]::backdrop {
|
|
84
|
+
background: transparent;
|
|
85
|
+
backdrop-filter: blur(0);
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
/* The dialog still fades; it no longer moves or grows. */
|
|
77
89
|
@media (prefers-reduced-motion: reduce) {
|
|
78
90
|
transform: none;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Closed is the exit pose, so closing animates too; allow-discrete holds
|
|
2
2
|
display/overlay until it ends. Open is FloatingPanel's [data-open] or a
|
|
3
|
-
native [popover]'s :popover-open
|
|
3
|
+
native [popover]'s :popover-open; a panel lifted to the top layer
|
|
4
|
+
([data-lc-lifted]) follows [data-open] alone, and a popover playing its
|
|
5
|
+
exit before it hides ([data-closing], see hidePopoverAfterExit) is closed. --lc-popover-from sets the closed pose;
|
|
4
6
|
origin-* utilities set where it grows from. */
|
|
5
7
|
@utility lc-popover-shell {
|
|
6
8
|
opacity: 0;
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
display var(--lc-motion-feedback) allow-discrete,
|
|
13
15
|
overlay var(--lc-motion-feedback) allow-discrete;
|
|
14
16
|
|
|
15
|
-
&:is([data-open], :popover-open) {
|
|
17
|
+
&:is([data-open], :popover-open:not([data-lc-lifted])):not([data-closing]) {
|
|
16
18
|
opacity: 1;
|
|
17
19
|
transform: translateY(0) scale(1);
|
|
18
20
|
pointer-events: auto;
|
|
@@ -28,7 +30,7 @@
|
|
|
28
30
|
/* stylelint-disable-next-line no-invalid-position-declaration -- an @utility body nests like a rule */
|
|
29
31
|
transform: none;
|
|
30
32
|
|
|
31
|
-
&:is([data-open], :popover-open) {
|
|
33
|
+
&:is([data-open], :popover-open:not([data-lc-lifted])):not([data-closing]) {
|
|
32
34
|
@starting-style { transform: none; }
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -65,6 +65,10 @@
|
|
|
65
65
|
@starting-style { transform: translateY(var(--lc-sheet-offscreen)); }
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/* Where `overlay` can't transition, a closing dialog or popover stays
|
|
69
|
+
open in its exit pose until the slide ends. */
|
|
70
|
+
&:is([open], :popover-open)[data-closing] { transform: translateY(var(--lc-sheet-offscreen)); }
|
|
71
|
+
|
|
68
72
|
&::backdrop {
|
|
69
73
|
background: var(--lc-scrim-sheet);
|
|
70
74
|
backdrop-filter: none;
|
|
@@ -81,6 +85,8 @@
|
|
|
81
85
|
@starting-style { opacity: 0; }
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
&:is([open], :popover-open)[data-closing]::backdrop { opacity: 0; }
|
|
89
|
+
|
|
84
90
|
/* The sheet appears in place; lc-sheet's own slides already skip under reduced motion. */
|
|
85
91
|
@media (prefers-reduced-motion: reduce) {
|
|
86
92
|
transition: none;
|
|
@@ -20,7 +20,16 @@ module Lostcoords::Ui
|
|
|
20
20
|
merged[:data] ||= {}
|
|
21
21
|
merged[:data][key] = [ defaults[:data][key], attributes.dig(:data, key) ].join(" ").split.uniq.join(" ")
|
|
22
22
|
end
|
|
23
|
-
merged
|
|
23
|
+
lc_light_dismiss(merged)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# An auto popover's closes are lc-light-dismiss's, so its exit plays in Safari too.
|
|
27
|
+
def lc_light_dismiss(attributes)
|
|
28
|
+
return attributes unless attributes[:popover] == "auto"
|
|
29
|
+
|
|
30
|
+
data = attributes[:data].is_a?(Hash) ? attributes[:data] : {}
|
|
31
|
+
controller = [ data[:controller], "lc-light-dismiss" ].compact.join(" ").split.uniq.join(" ")
|
|
32
|
+
attributes.merge(data: data.merge(controller: controller))
|
|
24
33
|
end
|
|
25
34
|
|
|
26
35
|
def lc_normalize_attributes(attributes)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
import { registerDismissable } from "lostcoords/ui/helpers/dismiss_stack"
|
|
3
|
+
import { hidePopoverAfterExit } from "lostcoords/ui/helpers/top_layer"
|
|
4
|
+
|
|
5
|
+
// A popover the gem rendered as popover="auto", made manual when it connects so that every close is
|
|
6
|
+
// the gem's and plays the exit, which Safari skips when the browser closes a popover itself: a tap
|
|
7
|
+
// outside, Escape, a popovertarget button that hides it and a [data-lc-popover-close] element in it.
|
|
8
|
+
// Without JavaScript it stays a native auto popover.
|
|
9
|
+
export default class extends Controller {
|
|
10
|
+
connect() {
|
|
11
|
+
if (!this.element.matches(":popover-open")) this.element.popover = "manual"
|
|
12
|
+
this.onToggle = (event) => (event.newState === "open" ? this.opened() : this.closed())
|
|
13
|
+
this.onPointerDown = this.onPointerDown.bind(this)
|
|
14
|
+
this.onClick = this.onClick.bind(this)
|
|
15
|
+
this.element.addEventListener("toggle", this.onToggle)
|
|
16
|
+
if (this.element.matches(":popover-open")) this.opened()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
disconnect() {
|
|
20
|
+
this.element.removeEventListener("toggle", this.onToggle)
|
|
21
|
+
this.closed()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
hide() {
|
|
25
|
+
return hidePopoverAfterExit(this.element)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
opened() {
|
|
29
|
+
this.element.removeAttribute("data-closing")
|
|
30
|
+
if (this.unregister) return
|
|
31
|
+
document.addEventListener("pointerdown", this.onPointerDown, true)
|
|
32
|
+
document.addEventListener("click", this.onClick, true)
|
|
33
|
+
this.unregister = registerDismissable({
|
|
34
|
+
element: this.element,
|
|
35
|
+
type: "popover",
|
|
36
|
+
close: () => this.hide(),
|
|
37
|
+
isOpen: () => this.element.matches(":popover-open:not([data-closing])"),
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
closed() {
|
|
42
|
+
document.removeEventListener("pointerdown", this.onPointerDown, true)
|
|
43
|
+
document.removeEventListener("click", this.onClick, true)
|
|
44
|
+
this.unregister?.()
|
|
45
|
+
this.unregister = null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The popover's own buttons toggle it on click, so a press on one is not a press outside.
|
|
49
|
+
onPointerDown(event) {
|
|
50
|
+
if (this.element.contains(event.target) || this.invoker(event.target)) return
|
|
51
|
+
this.hide()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onClick(event) {
|
|
55
|
+
const invoker = this.invoker(event.target)
|
|
56
|
+
if (invoker) {
|
|
57
|
+
if (invoker.getAttribute("popovertargetaction") === "show") return
|
|
58
|
+
event.preventDefault()
|
|
59
|
+
this.hide()
|
|
60
|
+
} else if (
|
|
61
|
+
event.target.closest?.("[data-lc-popover-close]") &&
|
|
62
|
+
this.element.contains(event.target)
|
|
63
|
+
) {
|
|
64
|
+
this.hide()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
invoker(target) {
|
|
69
|
+
const button = target.closest?.("[popovertarget]")
|
|
70
|
+
return button?.popoverTargetElement === this.element ? button : null
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -8,6 +8,16 @@ const MEDIUM_FRACTION = 0.5
|
|
|
8
8
|
const NO_DRAG = "input[type=range], [data-lc-sheet-no-drag]"
|
|
9
9
|
const DRAG_ZONE = 28
|
|
10
10
|
const KEYBOARD_FREE = 0.5
|
|
11
|
+
// A finger held still this long before lifting has no fling left in it.
|
|
12
|
+
const STILL_MS = 80
|
|
13
|
+
// --lc-ease-sheet, cubic-bezier(0.32, 0.72, 0, 1), starts at 0.72 / 0.32 = 2.25×
|
|
14
|
+
// its average speed. Change both together.
|
|
15
|
+
const EASE_START = 0.72 / 0.32
|
|
16
|
+
const FASTEST_MS = 240
|
|
17
|
+
// Safari and Firefox can't transition `overlay`, so a closing <dialog> leaves
|
|
18
|
+
// the top layer at once and vanishes mid-slide. There the controller plays the
|
|
19
|
+
// exit pose ([data-closing]) first and closes when it ends.
|
|
20
|
+
const EXITS_NATIVELY = CSS.supports("overlay", "auto")
|
|
11
21
|
|
|
12
22
|
export default class extends Controller {
|
|
13
23
|
static values = { detents: { type: String, default: "fit" } }
|
|
@@ -25,6 +35,7 @@ export default class extends Controller {
|
|
|
25
35
|
this.element.addEventListener("touchend", this.onTouchEnd)
|
|
26
36
|
this.element.addEventListener("touchcancel", this.onTouchEnd)
|
|
27
37
|
this.element.addEventListener("pointerdown", this.onPointerDown)
|
|
38
|
+
if (this.isDialog && !EXITS_NATIVELY) this.holdClose()
|
|
28
39
|
|
|
29
40
|
this.sync = this.sync.bind(this)
|
|
30
41
|
this.shown = false
|
|
@@ -52,6 +63,7 @@ export default class extends Controller {
|
|
|
52
63
|
this.element.removeEventListener("touchend", this.onTouchEnd)
|
|
53
64
|
this.element.removeEventListener("touchcancel", this.onTouchEnd)
|
|
54
65
|
this.element.removeEventListener("pointerdown", this.onPointerDown)
|
|
66
|
+
this.releaseClose()
|
|
55
67
|
this.stopMouseTracking()
|
|
56
68
|
clearTimeout(this.settleTimer)
|
|
57
69
|
clearTimeout(this.transitionTimer)
|
|
@@ -113,7 +125,7 @@ export default class extends Controller {
|
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
onTouchEnd(event) {
|
|
116
|
-
if (this.gesture?.dragging) this.release()
|
|
128
|
+
if (this.gesture?.dragging) this.release(event?.timeStamp ?? performance.now())
|
|
117
129
|
else if (this.gesture && event?.type === "touchend") this.focusInPlace(event)
|
|
118
130
|
this.gesture = null
|
|
119
131
|
}
|
|
@@ -156,7 +168,8 @@ export default class extends Controller {
|
|
|
156
168
|
onPointerUp(event) {
|
|
157
169
|
this.stopMouseTracking()
|
|
158
170
|
if (this.gesture && Math.abs(event.clientY - this.gesture.startY) > 4) swallowNextClick()
|
|
159
|
-
this.
|
|
171
|
+
if (this.gesture?.dragging) this.release(event.timeStamp)
|
|
172
|
+
this.gesture = null
|
|
160
173
|
}
|
|
161
174
|
|
|
162
175
|
stopMouseTracking() {
|
|
@@ -212,18 +225,37 @@ export default class extends Controller {
|
|
|
212
225
|
)
|
|
213
226
|
}
|
|
214
227
|
|
|
215
|
-
release() {
|
|
216
|
-
const { detents,
|
|
217
|
-
const
|
|
228
|
+
release(time) {
|
|
229
|
+
const { detents, lastT } = this.gesture
|
|
230
|
+
const velocity = time - lastT > STILL_MS ? 0 : this.gesture.velocity
|
|
231
|
+
const visible = this.visibleHeight()
|
|
232
|
+
const projected = visible - velocity * PROJECTION_MS
|
|
218
233
|
|
|
219
|
-
if (velocity >= 0 && projected < detents[0].height * 0.6)
|
|
234
|
+
if (velocity >= 0 && projected < detents[0].height * 0.6) {
|
|
235
|
+
this.pace(visible + this.offscreenGap, velocity)
|
|
236
|
+
return this.dismiss()
|
|
237
|
+
}
|
|
220
238
|
|
|
221
239
|
const target = detents.reduce((best, detent) =>
|
|
222
240
|
Math.abs(detent.height - projected) < Math.abs(best.height - projected) ? detent : best,
|
|
223
241
|
)
|
|
242
|
+
// A fling away from the target, or a lift in place, gets the full beat.
|
|
243
|
+
const toward = Math.sign(visible - target.height) === Math.sign(velocity)
|
|
244
|
+
this.pace(visible - target.height, toward ? velocity : 0)
|
|
224
245
|
this.settle(target, detents)
|
|
225
246
|
}
|
|
226
247
|
|
|
248
|
+
// UIKit hands a released sheet on at the finger's speed. The sheet curve opens
|
|
249
|
+
// at EASE_START times its average speed, so a beat of EASE_START × distance ÷
|
|
250
|
+
// speed carries the fling on without a jolt; a slow lift keeps the full beat.
|
|
251
|
+
pace(distance, velocity) {
|
|
252
|
+
const full = sheetDuration()
|
|
253
|
+
const speed = Math.abs(velocity)
|
|
254
|
+
if (!full || !speed) return this.element.style.removeProperty("--lc-sheet-duration")
|
|
255
|
+
const ms = Math.min(full, Math.max(FASTEST_MS, (EASE_START * Math.abs(distance)) / speed))
|
|
256
|
+
this.element.style.setProperty("--lc-sheet-duration", `${Math.round(ms)}ms`)
|
|
257
|
+
}
|
|
258
|
+
|
|
227
259
|
settle(detent, detents = this.detents()) {
|
|
228
260
|
this.detent = detent
|
|
229
261
|
this.transition()
|
|
@@ -242,15 +274,69 @@ export default class extends Controller {
|
|
|
242
274
|
})
|
|
243
275
|
}
|
|
244
276
|
|
|
277
|
+
// The cancel may close the dialog, or keep it open (a listener asking to
|
|
278
|
+
// discard changes): then the sheet settles back.
|
|
245
279
|
dismissDialog() {
|
|
280
|
+
this.transition()
|
|
246
281
|
const cancel = new Event("cancel", { cancelable: true })
|
|
247
282
|
this.element.dispatchEvent(cancel)
|
|
248
283
|
if (!cancel.defaultPrevented) this.element.close()
|
|
249
284
|
|
|
250
|
-
if (this.element.open) return this.settle(this.detent || this.detents()[0])
|
|
285
|
+
if (this.element.open && !this.closing) return this.settle(this.detent || this.detents()[0])
|
|
286
|
+
this.element.style.transform = ""
|
|
287
|
+
}
|
|
251
288
|
|
|
252
|
-
|
|
289
|
+
// Every close() then goes through the exit, whoever calls it, and so does a
|
|
290
|
+
// method=dialog form, which the browser would close at once. A native Escape
|
|
291
|
+
// on a dialog no dismiss stack handles still closes at once.
|
|
292
|
+
holdClose() {
|
|
293
|
+
const close = HTMLDialogElement.prototype.close
|
|
294
|
+
this.closeNow = (value) => close.call(this.element, value)
|
|
295
|
+
this.element.close = (value) => this.closeAfterExit(value)
|
|
296
|
+
this.onDialogSubmit = (event) => {
|
|
297
|
+
const method = event.submitter?.getAttribute("formmethod") || event.target.method
|
|
298
|
+
if (method !== "dialog" || event.target.closest("dialog") !== this.element) return
|
|
299
|
+
event.preventDefault()
|
|
300
|
+
this.element.close(event.submitter?.value)
|
|
301
|
+
}
|
|
302
|
+
this.element.addEventListener("submit", this.onDialogSubmit)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
releaseClose() {
|
|
306
|
+
if (!this.closeNow) return
|
|
307
|
+
delete this.element.close
|
|
308
|
+
this.element.removeEventListener("submit", this.onDialogSubmit)
|
|
309
|
+
clearTimeout(this.exitTimer)
|
|
310
|
+
if (this.closing) this.finishClose()
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
closeAfterExit(value) {
|
|
314
|
+
if (!this.element.open || this.closing) return
|
|
315
|
+
this.closing = { value }
|
|
316
|
+
if (value !== undefined) this.element.returnValue = value
|
|
317
|
+
this.element.toggleAttribute("data-closing", true)
|
|
318
|
+
// close fires once the slide ends; lc-sheet:exit tells a caller waiting on the answer now.
|
|
319
|
+
this.dispatch("exit", { bubbles: false })
|
|
253
320
|
this.element.style.transform = ""
|
|
321
|
+
this.exitTimer = setTimeout(() => this.finishClose(), this.exitDuration())
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
finishClose() {
|
|
325
|
+
const { value } = this.closing
|
|
326
|
+
this.closing = null
|
|
327
|
+
this.closeNow(value)
|
|
328
|
+
this.element.removeAttribute("data-closing")
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
exitDuration() {
|
|
332
|
+
const { transitionDuration, transitionDelay } = getComputedStyle(this.element)
|
|
333
|
+
const ms = (list) =>
|
|
334
|
+
list.split(",").map((time) => parseFloat(time) * (time.trim().endsWith("ms") ? 1 : 1000))
|
|
335
|
+
const delays = ms(transitionDelay)
|
|
336
|
+
return Math.max(
|
|
337
|
+
0,
|
|
338
|
+
...ms(transitionDuration).map((duration, i) => duration + (delays[i % delays.length] || 0)),
|
|
339
|
+
)
|
|
254
340
|
}
|
|
255
341
|
|
|
256
342
|
detents() {
|
|
@@ -324,12 +410,17 @@ export default class extends Controller {
|
|
|
324
410
|
this.transitionTimer = setTimeout(() => {
|
|
325
411
|
this.element.style.transition = ""
|
|
326
412
|
this.element.style.willChange = ""
|
|
327
|
-
|
|
413
|
+
this.element.style.removeProperty("--lc-sheet-duration")
|
|
414
|
+
}, sheetDuration(this.element))
|
|
328
415
|
}
|
|
329
416
|
|
|
330
417
|
later(callback) {
|
|
331
418
|
clearTimeout(this.settleTimer)
|
|
332
|
-
this.settleTimer = setTimeout(callback, sheetDuration())
|
|
419
|
+
this.settleTimer = setTimeout(callback, sheetDuration(this.element))
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
get offscreenGap() {
|
|
423
|
+
return parseFloat(getComputedStyle(document.documentElement).fontSize) * 2
|
|
333
424
|
}
|
|
334
425
|
|
|
335
426
|
resetSurface() {
|
|
@@ -339,6 +430,7 @@ export default class extends Controller {
|
|
|
339
430
|
style.willChange = ""
|
|
340
431
|
style.blockSize = ""
|
|
341
432
|
style.removeProperty("--lc-sheet-floor")
|
|
433
|
+
style.removeProperty("--lc-sheet-duration")
|
|
342
434
|
}
|
|
343
435
|
|
|
344
436
|
scrollerFor(target) {
|
|
@@ -44,9 +44,14 @@ export function ask(
|
|
|
44
44
|
|
|
45
45
|
return new Promise((resolve) => {
|
|
46
46
|
dialog.returnValue = ""
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// lc-sheet:exit comes first where the sheet holds its close for the exit slide.
|
|
48
|
+
const answer = () => {
|
|
49
|
+
dialog.removeEventListener("close", answer)
|
|
50
|
+
dialog.removeEventListener("lc-sheet:exit", answer)
|
|
51
|
+
resolve(dialog.returnValue === "confirm")
|
|
52
|
+
}
|
|
53
|
+
dialog.addEventListener("close", answer)
|
|
54
|
+
dialog.addEventListener("lc-sheet:exit", answer)
|
|
50
55
|
dialog.style.removeProperty("--lc-dialog-origin")
|
|
51
56
|
showContextDialog(dialog, anchor)
|
|
52
57
|
registerDialog(dialog, { lockScroll: false })
|
|
@@ -30,6 +30,17 @@ export function showDialog(dialog) {
|
|
|
30
30
|
dialog.focus({ preventScroll: true })
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
// Closes a dialog and settles once it has left: closed, with its exit transition over. Where the
|
|
34
|
+
// browser can't transition a closing dialog (Safari), lc-sheet holds it open for its exit and closes
|
|
35
|
+
// it when that ends, so code that clears up after a dialog waits for this, not for close().
|
|
36
|
+
export function closeDialog(dialog, returnValue) {
|
|
37
|
+
if (!dialog.open) return Promise.resolve()
|
|
38
|
+
const closed = new Promise((resolve) => dialog.addEventListener("close", resolve, { once: true }))
|
|
39
|
+
dialog.close(returnValue)
|
|
40
|
+
const exits = dialog.getAnimations().map((animation) => animation.finished)
|
|
41
|
+
return Promise.allSettled([dialog.open ? closed : null, ...exits]).then(() => {})
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
// Joins a <dialog> to the dismiss stack: Escape, the backdrop and a swipe call close, which may
|
|
34
45
|
// return false to keep it open, such as while it asks whether to discard changes. priority ranks
|
|
35
46
|
// it against panels open in it (a dialog is 10, a panel 20); restoreFocus runs after a close;
|
|
@@ -4,10 +4,9 @@ import { prefersReducedMotion } from "lostcoords/ui/helpers/viewport"
|
|
|
4
4
|
// directly; timers need the duration in milliseconds.
|
|
5
5
|
export const SHEET_TIMING = "var(--lc-sheet-duration) var(--lc-ease-sheet)"
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// A released sheet sets its own --lc-sheet-duration; pass it to read that beat.
|
|
8
|
+
export function sheetDuration(element = document.documentElement) {
|
|
8
9
|
if (prefersReducedMotion()) return 0
|
|
9
|
-
const value = getComputedStyle(
|
|
10
|
-
.getPropertyValue("--lc-sheet-duration")
|
|
11
|
-
.trim()
|
|
10
|
+
const value = getComputedStyle(element).getPropertyValue("--lc-sheet-duration").trim()
|
|
12
11
|
return value.endsWith("ms") ? parseFloat(value) : parseFloat(value) * 1000
|
|
13
12
|
}
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
// pinned to a trigger, and onPageLeave to close them before Turbo caches a page.
|
|
15
15
|
|
|
16
16
|
const MARGIN = 8
|
|
17
|
+
// Safari and Firefox can't transition `overlay`: a hidden popover leaves the top
|
|
18
|
+
// layer, and the screen, at once. WebKit doesn't hold `display` for an exit
|
|
19
|
+
// either. There a lifted panel stays in the top layer, shown as it was, until
|
|
20
|
+
// its exit transition ends.
|
|
21
|
+
const EXITS_NATIVELY = CSS.supports("overlay", "auto")
|
|
17
22
|
const PAGE_LEAVES = ["turbo:before-cache", "turbo:before-visit", "turbo:before-render"]
|
|
18
23
|
|
|
19
24
|
export const supportsTopLayer = () => typeof HTMLElement.prototype.showPopover === "function"
|
|
@@ -31,6 +36,28 @@ export function hideTopLayer(element) {
|
|
|
31
36
|
if (supportsTopLayer() && element.matches(":popover-open")) element.hidePopover()
|
|
32
37
|
}
|
|
33
38
|
|
|
39
|
+
// Hides a popover once its exit has played, and settles when it is hidden. Where `overlay` can't
|
|
40
|
+
// transition, the popover stays open in its exit pose ([data-closing]) until the exit ends.
|
|
41
|
+
export function hidePopoverAfterExit(element) {
|
|
42
|
+
if (!supportsTopLayer() || !element.matches(":popover-open")) return Promise.resolve()
|
|
43
|
+
if (EXITS_NATIVELY) {
|
|
44
|
+
element.hidePopover()
|
|
45
|
+
return exitOf(element)
|
|
46
|
+
}
|
|
47
|
+
if (element.hasAttribute("data-closing")) return exitOf(element)
|
|
48
|
+
|
|
49
|
+
element.toggleAttribute("data-closing", true)
|
|
50
|
+
return exitOf(element).then(() => {
|
|
51
|
+
// Shown again meanwhile: the exit was called off.
|
|
52
|
+
if (!element.hasAttribute("data-closing")) return
|
|
53
|
+
element.removeAttribute("data-closing")
|
|
54
|
+
hideTopLayer(element)
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const exitOf = (element) =>
|
|
59
|
+
Promise.allSettled(element.getAnimations().map((animation) => animation.finished)).then(() => {})
|
|
60
|
+
|
|
34
61
|
// Calls close before Turbo snapshots or leaves the page, so a cached page never
|
|
35
62
|
// keeps an open overlay. Returns a function that removes the listeners.
|
|
36
63
|
export function onPageLeave(close) {
|
|
@@ -41,7 +68,16 @@ export function onPageLeave(close) {
|
|
|
41
68
|
window.removeEventListener("pagehide", close)
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
|
-
const PLACEMENT = [
|
|
71
|
+
const PLACEMENT = [
|
|
72
|
+
"position",
|
|
73
|
+
"inset",
|
|
74
|
+
"top",
|
|
75
|
+
"left",
|
|
76
|
+
"margin",
|
|
77
|
+
"translate",
|
|
78
|
+
"inlineSize",
|
|
79
|
+
"display",
|
|
80
|
+
]
|
|
45
81
|
|
|
46
82
|
const lifts = new WeakMap()
|
|
47
83
|
const pinned = new WeakSet()
|
|
@@ -60,8 +96,12 @@ export function liftToTopLayer(panel, trigger) {
|
|
|
60
96
|
// other panel flips above when it would leave the bottom.
|
|
61
97
|
const above = placed.bottom <= anchor.top + 1
|
|
62
98
|
const gap = above ? anchor.top - placed.bottom : placed.top - anchor.bottom
|
|
99
|
+
const shown = getComputedStyle(panel).display
|
|
63
100
|
|
|
64
101
|
showTopLayer(panel)
|
|
102
|
+
// A lifted panel is open while [data-open], not while :popover-open, so it can
|
|
103
|
+
// play its exit pose before it leaves the top layer.
|
|
104
|
+
panel.toggleAttribute("data-lc-lifted", true)
|
|
65
105
|
Object.assign(panel.style, {
|
|
66
106
|
position: "fixed",
|
|
67
107
|
inset: "auto",
|
|
@@ -114,10 +154,14 @@ export function liftToTopLayer(panel, trigger) {
|
|
|
114
154
|
|
|
115
155
|
// Keep the pinned spot while the closing transition plays out, then hand
|
|
116
156
|
// the panel back to its stylesheet unless it has been lifted again.
|
|
117
|
-
|
|
157
|
+
// The caller has just hidden the panel and no style has been read since, so
|
|
158
|
+
// holding its display here starts the exit transition from the open pose.
|
|
159
|
+
if (!EXITS_NATIVELY) panel.style.display = shown
|
|
160
|
+
const exits = panel.getAnimations().map((animation) => animation.finished)
|
|
161
|
+
if (EXITS_NATIVELY) hideTopLayer(panel)
|
|
162
|
+
Promise.allSettled(exits).then(() => {
|
|
118
163
|
if (!lifts.has(panel)) reset(panel)
|
|
119
164
|
})
|
|
120
|
-
hideTopLayer(panel)
|
|
121
165
|
}
|
|
122
166
|
lifts.set(panel, release)
|
|
123
167
|
return release
|
|
@@ -127,6 +171,7 @@ function reset(panel) {
|
|
|
127
171
|
pinned.delete(panel)
|
|
128
172
|
hideTopLayer(panel)
|
|
129
173
|
panel.removeAttribute("popover")
|
|
174
|
+
panel.removeAttribute("data-lc-lifted")
|
|
130
175
|
for (const property of PLACEMENT) panel.style[property] = ""
|
|
131
176
|
}
|
|
132
177
|
|
|
@@ -8,6 +8,7 @@ import Dock from "lostcoords/ui/controllers/lc_dock_controller"
|
|
|
8
8
|
import EmojiPicker from "lostcoords/ui/controllers/lc_emoji_picker_controller"
|
|
9
9
|
import Hovercard from "lostcoords/ui/controllers/lc_hovercard_controller"
|
|
10
10
|
import Kbd from "lostcoords/ui/controllers/lc_kbd_controller"
|
|
11
|
+
import LightDismiss from "lostcoords/ui/controllers/lc_light_dismiss_controller"
|
|
11
12
|
import Menu from "lostcoords/ui/controllers/lc_menu_controller"
|
|
12
13
|
import Nav from "lostcoords/ui/controllers/lc_nav_controller"
|
|
13
14
|
import Popover from "lostcoords/ui/controllers/lc_popover_controller"
|
|
@@ -35,6 +36,7 @@ const controllers = {
|
|
|
35
36
|
"lc-emoji-picker": EmojiPicker,
|
|
36
37
|
"lc-hovercard": Hovercard,
|
|
37
38
|
"lc-kbd": Kbd,
|
|
39
|
+
"lc-light-dismiss": LightDismiss,
|
|
38
40
|
"lc-menu": Menu,
|
|
39
41
|
"lc-nav": Nav,
|
|
40
42
|
"lc-popover": Popover,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lostcoords-ui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.14.
|
|
4
|
+
version: 0.14.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lost Coordinates
|
|
@@ -171,6 +171,7 @@ files:
|
|
|
171
171
|
- app/javascript/lostcoords/ui/controllers/lc_emoji_picker_controller.js
|
|
172
172
|
- app/javascript/lostcoords/ui/controllers/lc_hovercard_controller.js
|
|
173
173
|
- app/javascript/lostcoords/ui/controllers/lc_kbd_controller.js
|
|
174
|
+
- app/javascript/lostcoords/ui/controllers/lc_light_dismiss_controller.js
|
|
174
175
|
- app/javascript/lostcoords/ui/controllers/lc_menu_controller.js
|
|
175
176
|
- app/javascript/lostcoords/ui/controllers/lc_nav_controller.js
|
|
176
177
|
- app/javascript/lostcoords/ui/controllers/lc_popover_controller.js
|