@radioactive-labs/plutonium 0.49.0 → 0.50.0

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.
@@ -0,0 +1,16 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Connects to data-controller="table-header"
4
+ // Routes column-header clicks: shift-click navigates to multi-href instead of href,
5
+ // adding the column to the existing sort stack (multi-sort).
6
+ // Plain click lets the default link navigation happen, which replaces all sorts.
7
+ export default class extends Controller {
8
+ headerClick(event) {
9
+ if (!event.shiftKey) return // plain click: let the link navigate normally
10
+ const link = event.currentTarget
11
+ const multiHref = link.dataset.tableHeaderMultiHref
12
+ if (!multiHref) return
13
+ event.preventDefault()
14
+ Turbo.visit(multiHref)
15
+ }
16
+ }
@@ -0,0 +1,29 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ // Connects to data-controller="view-switcher"
4
+ // Persists the user's chosen index view in a cookie so the server can
5
+ // render the right shape on next request. Reload after writing so the
6
+ // page comes back with everything (toolbar, filters, table/grid)
7
+ // matching the new view.
8
+ export default class extends Controller {
9
+ static values = { cookieName: String, cookiePath: { type: String, default: "/" } }
10
+
11
+ select(event) {
12
+ const view = event.params.view
13
+ if (!view || !this.cookieNameValue) return
14
+
15
+ // 1 year, scoped to the portal's mount path so different portals
16
+ // can hold different view preferences for the same resource.
17
+ // SameSite=Lax keeps it on top-level navigations but blocks
18
+ // cross-site requests from carrying it along.
19
+ const maxAge = 60 * 60 * 24 * 365
20
+ const path = this.cookiePathValue || "/"
21
+ document.cookie = `${this.cookieNameValue}=${encodeURIComponent(view)}; Path=${path}; Max-Age=${maxAge}; SameSite=Lax`
22
+
23
+ // Strip any legacy `?view=` param so the cookie is the source of
24
+ // truth from now on.
25
+ const url = new URL(window.location.href)
26
+ url.searchParams.delete("view")
27
+ window.location.href = url.toString()
28
+ }
29
+ }