lostcoords-ui 0.8.1 → 0.8.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 +4 -4
- data/README.md +20 -0
- data/app/assets/tailwind/lostcoords/ui/core.css +1 -1
- data/app/assets/tailwind/lostcoords/ui/dialog.css +3 -0
- data/app/helpers/lostcoords/ui/emoji_picker_helper.rb +5 -2
- data/app/javascript/lostcoords/ui/controllers/lc_nav_controller.js +13 -7
- data/app/javascript/lostcoords/ui/controllers/lc_scroll_keeper_controller.js +53 -0
- 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: aa5ef0cc7f548cfccfe27e49a88e68fea79cd6225b41ee8cb2ff75c744c055e5
|
|
4
|
+
data.tar.gz: 1df3317a043db991a631bd76d94f90a453605e78cfdc716b40b7e99c8374db11
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2469f7423e3a9efafa8ecba6de19a051d68b832e66b8e8859ee604d24102fb7b4594d3911e37a3afac037005c318447c07c6adb21e6ee6ca7794a8a1cc5489d0
|
|
7
|
+
data.tar.gz: 94b26a83e133249ee797542f66fdd365f303f025da5189e8b6398390a3d2b10a4484e5d5f3dee3a15e91c44fa6431d368a9735751ab19e0b2c9d5975896469a8
|
data/README.md
CHANGED
|
@@ -194,6 +194,21 @@ lazyLoadControllersFrom("controllers", application)
|
|
|
194
194
|
`eagerLoadControllersFrom` also works and downloads all of them on every page. A host file with the
|
|
195
195
|
same name, such as `app/javascript/controllers/lc_dialog_controller.js`, replaces the gem's.
|
|
196
196
|
|
|
197
|
+
## Changes in 0.8.2
|
|
198
|
+
|
|
199
|
+
Nothing needs an edit. New options, and one change you may see:
|
|
200
|
+
|
|
201
|
+
- **`lc_emoji_picker` takes `picker_class:`, `trigger_class:` and `popover_class:`.** The gem leaves the desktop
|
|
202
|
+
popover unpainted so the host can match its own floating surfaces; until now that meant rendering the
|
|
203
|
+
`lostcoords/ui/components/emoji_picker` partial directly. Pass the classes to the helper instead.
|
|
204
|
+
- **A dialog slides to a new width.** `.lc-dialog` transitions `inline-size`, so a dialog that widens, such as
|
|
205
|
+
one opening a side panel, animates instead of jumping. A host that restated the dialog's `transition` only to
|
|
206
|
+
add `inline-size` can delete that rule.
|
|
207
|
+
- **`lc-scroll-keeper` keeps a scroll container's position.** Put `data-controller="lc-scroll-keeper"` on a
|
|
208
|
+
sidebar that every page renders again; it restores its scroll across Turbo visits and reloads.
|
|
209
|
+
- **`lc_nav_list` keeps the server's current link after a back visit.** Before: a page restored from Turbo's
|
|
210
|
+
cache showed the link clicked before leaving as current. After: it shows the one the server marked.
|
|
211
|
+
|
|
197
212
|
## Changes in 0.8.1
|
|
198
213
|
|
|
199
214
|
Nothing needs an edit, but these look different:
|
|
@@ -520,6 +535,11 @@ tones; `lc_link_class` styles links you render yourself. `lc_skip_link` targets
|
|
|
520
535
|
Pass `card: true` to `lc_radio` or `lc_checkbox` for selectable tiles; a block adds content, such as a
|
|
521
536
|
preview, under the label.
|
|
522
537
|
|
|
538
|
+
A sidebar that scrolls on its own starts at the top on every page. Put `data-controller="lc-scroll-keeper"`
|
|
539
|
+
on the scroll container to keep its position across Turbo visits and reloads. Containers with the same
|
|
540
|
+
`data-lc-scroll-keeper-key-value` share one position for the browser tab. Without a saved position,
|
|
541
|
+
it scrolls the `aria-current="page"` link into view.
|
|
542
|
+
|
|
523
543
|
This documentation site is built with these components and two copyable blocks: the application
|
|
524
544
|
header and the documentation layout.
|
|
525
545
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
@import "./theme.css";
|
|
6
6
|
@source "../../../../helpers/lostcoords/ui/{badge,button,card,choice,copy_button,description_list,feedback,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_{copy,kbd,nav,selection,shortcut,tabs,toggle}_controller.js";
|
|
8
|
+
@source "../../../../javascript/lostcoords/ui/controllers/lc_{copy,kbd,nav,scroll_keeper,selection,shortcut,tabs,toggle}_controller.js";
|
|
9
9
|
@source "../../../../../lib/lostcoords/ui/parts.rb";
|
|
10
10
|
|
|
11
11
|
@import "./glass.css";
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
overscroll-behavior: contain;
|
|
11
11
|
opacity: 0;
|
|
12
12
|
transform: var(--lc-dialog-from);
|
|
13
|
+
|
|
14
|
+
/* inline-size: a dialog that widens, such as one opening a side panel, slides to its new width. */
|
|
13
15
|
transition:
|
|
14
16
|
opacity var(--lc-dialog-fade) var(--lc-ease-out-expo),
|
|
15
17
|
transform var(--lc-dialog-duration) var(--lc-ease-out-expo),
|
|
18
|
+
inline-size var(--lc-dialog-duration) var(--lc-ease-out-expo),
|
|
16
19
|
display var(--lc-dialog-duration) allow-discrete,
|
|
17
20
|
overlay var(--lc-dialog-duration) allow-discrete;
|
|
18
21
|
|
|
@@ -6,10 +6,13 @@ module Lostcoords::Ui
|
|
|
6
6
|
module EmojiPickerHelper
|
|
7
7
|
include TranslationHelper
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
# popover_class paints the desktop popover: the gem leaves it unpainted so the host can match
|
|
10
|
+
# its floating surfaces. picker_class and trigger_class style the wrapper and its button.
|
|
11
|
+
def lc_emoji_picker(form:, field:, label:, catalog_url:, value: nil, quick: [], recent: [], recent_scope: nil, auto_submit: false, picker_class: nil, trigger_class: nil, popover_class: nil, **attributes)
|
|
10
12
|
lc_label!(label, :label)
|
|
11
13
|
lc_label!(catalog_url, :catalog_url)
|
|
12
|
-
render "lostcoords/ui/components/emoji_picker", form: form, field: field, label: label, catalog_url: catalog_url, value: value, quick: quick, recent: recent, recent_scope: recent_scope, auto_submit: auto_submit,
|
|
14
|
+
render "lostcoords/ui/components/emoji_picker", form: form, field: field, label: label, catalog_url: catalog_url, value: value, quick: quick, recent: recent, recent_scope: recent_scope, auto_submit: auto_submit,
|
|
15
|
+
picker_class: picker_class, trigger_class: trigger_class, popover_class: popover_class, attributes: attributes
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
SEARCH_NAMES_PATH = Lostcoords::Ui.root.join("config/emoji_search_names.yml")
|
|
@@ -9,9 +9,12 @@ export default class extends Controller {
|
|
|
9
9
|
|
|
10
10
|
connect() {
|
|
11
11
|
this.key = this.element.getAttribute("aria-label")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// The link the server marked keeps a data attribute, so a page restored from Turbo's cache
|
|
13
|
+
// marks it again instead of the link clicked before leaving. A click on a link to the same
|
|
14
|
+
// page, such as an anchor, keeps the clicked link current.
|
|
15
|
+
const initial = this.linkTargets.find((link) => link.hasAttribute("data-lc-nav-initial"))
|
|
16
|
+
if (initial) this.mark(initial)
|
|
17
|
+
else this.currentLink?.setAttribute("data-lc-nav-initial", "")
|
|
15
18
|
|
|
16
19
|
// The observer reports once on observe, after the first placement below.
|
|
17
20
|
let observed = false
|
|
@@ -29,17 +32,20 @@ export default class extends Controller {
|
|
|
29
32
|
disconnect() {
|
|
30
33
|
cancelAnimationFrame(this.frame)
|
|
31
34
|
this.observer.disconnect()
|
|
32
|
-
document.removeEventListener("turbo:before-cache", this.restore)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
select(event
|
|
37
|
+
select(event) {
|
|
36
38
|
if (event.button > 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return
|
|
37
39
|
|
|
40
|
+
this.mark(event.currentTarget)
|
|
41
|
+
this.place({ animate: true })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
mark(current) {
|
|
38
45
|
for (const link of this.linkTargets) {
|
|
39
|
-
if (link ===
|
|
46
|
+
if (link === current) link.setAttribute("aria-current", "page")
|
|
40
47
|
else link.removeAttribute("aria-current")
|
|
41
48
|
}
|
|
42
|
-
this.place({ animate })
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
get currentLink() {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
// Keeps a scroll container's position across Turbo visits and reloads, such as
|
|
4
|
+
// a sidebar that every page renders again. Positions live in sessionStorage
|
|
5
|
+
// under the key value, so containers that share a key share a position.
|
|
6
|
+
// Without a saved position, the current link scrolls into view instead.
|
|
7
|
+
export default class extends Controller {
|
|
8
|
+
static values = { key: String }
|
|
9
|
+
|
|
10
|
+
connect() {
|
|
11
|
+
this.save = () => this.store()
|
|
12
|
+
document.addEventListener("turbo:before-render", this.save)
|
|
13
|
+
window.addEventListener("pagehide", this.save)
|
|
14
|
+
|
|
15
|
+
const saved = Number.parseFloat(this.read())
|
|
16
|
+
if (Number.isFinite(saved)) this.element.scrollTop = saved
|
|
17
|
+
else this.reveal(this.element.querySelector('[aria-current="page"]'))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
disconnect() {
|
|
21
|
+
document.removeEventListener("turbo:before-render", this.save)
|
|
22
|
+
window.removeEventListener("pagehide", this.save)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// scrollIntoView would also scroll the page, so only the container moves.
|
|
26
|
+
reveal(link) {
|
|
27
|
+
if (!link) return
|
|
28
|
+
const frame = this.element.getBoundingClientRect()
|
|
29
|
+
const box = link.getBoundingClientRect()
|
|
30
|
+
if (box.top >= frame.top && box.bottom <= frame.bottom) return
|
|
31
|
+
this.element.scrollTop += box.top - frame.top - (frame.height - box.height) / 2
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get storageKey() {
|
|
35
|
+
return `lostcoords-ui:scroll:${this.keyValue || this.element.id || "default"}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
read() {
|
|
39
|
+
try {
|
|
40
|
+
return sessionStorage.getItem(this.storageKey)
|
|
41
|
+
} catch {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
store() {
|
|
47
|
+
// A hidden container reports 0 and would overwrite the visible one's position.
|
|
48
|
+
if (!this.element.offsetParent) return
|
|
49
|
+
try {
|
|
50
|
+
sessionStorage.setItem(this.storageKey, String(this.element.scrollTop))
|
|
51
|
+
} catch {}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -7,6 +7,7 @@ import Kbd from "lostcoords/ui/controllers/lc_kbd_controller"
|
|
|
7
7
|
import Menu from "lostcoords/ui/controllers/lc_menu_controller"
|
|
8
8
|
import Nav from "lostcoords/ui/controllers/lc_nav_controller"
|
|
9
9
|
import Popover from "lostcoords/ui/controllers/lc_popover_controller"
|
|
10
|
+
import ScrollKeeper from "lostcoords/ui/controllers/lc_scroll_keeper_controller"
|
|
10
11
|
import Search from "lostcoords/ui/controllers/lc_search_controller"
|
|
11
12
|
import Selection from "lostcoords/ui/controllers/lc_selection_controller"
|
|
12
13
|
import Sheet from "lostcoords/ui/controllers/lc_sheet_controller"
|
|
@@ -27,6 +28,7 @@ const controllers = {
|
|
|
27
28
|
"lc-menu": Menu,
|
|
28
29
|
"lc-nav": Nav,
|
|
29
30
|
"lc-popover": Popover,
|
|
31
|
+
"lc-scroll-keeper": ScrollKeeper,
|
|
30
32
|
"lc-search": Search,
|
|
31
33
|
"lc-selection": Selection,
|
|
32
34
|
"lc-sheet": Sheet,
|
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.8.
|
|
4
|
+
version: 0.8.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lost Coordinates
|
|
@@ -161,6 +161,7 @@ files:
|
|
|
161
161
|
- app/javascript/lostcoords/ui/controllers/lc_menu_controller.js
|
|
162
162
|
- app/javascript/lostcoords/ui/controllers/lc_nav_controller.js
|
|
163
163
|
- app/javascript/lostcoords/ui/controllers/lc_popover_controller.js
|
|
164
|
+
- app/javascript/lostcoords/ui/controllers/lc_scroll_keeper_controller.js
|
|
164
165
|
- app/javascript/lostcoords/ui/controllers/lc_search_controller.js
|
|
165
166
|
- app/javascript/lostcoords/ui/controllers/lc_selection_controller.js
|
|
166
167
|
- app/javascript/lostcoords/ui/controllers/lc_sheet_controller.js
|