@radioactive-labs/plutonium 0.48.0 → 0.49.1
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.
- package/package.json +1 -1
- package/src/dist/js/plutonium.js +73 -25
- package/src/dist/js/plutonium.js.map +3 -3
- package/src/dist/js/plutonium.min.js +29 -29
- package/src/dist/js/plutonium.min.js.map +3 -3
- package/src/js/controllers/color_mode_controller.js +41 -34
- package/src/js/controllers/flatpickr_controller.js +23 -0
- package/src/js/controllers/sidebar_controller.js +28 -1
|
@@ -1,66 +1,73 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
|
2
2
|
|
|
3
3
|
// Connects to data-controller="color-mode"
|
|
4
|
+
//
|
|
5
|
+
// Shared theme state across the app. localStorage key 'theme' holds one of:
|
|
6
|
+
// 'auto' — follow prefers-color-scheme (default when unset)
|
|
7
|
+
// 'light' — force light
|
|
8
|
+
// 'dark' — force dark
|
|
9
|
+
const ORDER = ['auto', 'light', 'dark'];
|
|
10
|
+
|
|
4
11
|
export default class extends Controller {
|
|
5
12
|
static values = { current: String };
|
|
6
13
|
|
|
7
14
|
connect() {
|
|
8
|
-
|
|
9
|
-
const mode = localStorage.getItem('theme') || "light";
|
|
10
|
-
this.setMode(mode);
|
|
15
|
+
this.applyMode(this.readMode());
|
|
11
16
|
|
|
12
|
-
// Listen for cross-tab theme changes
|
|
13
17
|
this.handleStorageChange = (e) => {
|
|
14
|
-
|
|
15
|
-
if (e.key === 'theme' && e.newValue) {
|
|
16
|
-
console.log('Updating color-mode theme to:', e.newValue)
|
|
17
|
-
this.setMode(e.newValue);
|
|
18
|
-
}
|
|
18
|
+
if (e.key === 'theme') this.applyMode(this.readMode());
|
|
19
19
|
};
|
|
20
20
|
window.addEventListener('storage', this.handleStorageChange);
|
|
21
|
+
|
|
22
|
+
this.mq = window.matchMedia('(prefers-color-scheme: dark)');
|
|
23
|
+
this.handleMqChange = () => {
|
|
24
|
+
if (this.readMode() === 'auto') this.applyMode('auto');
|
|
25
|
+
};
|
|
26
|
+
this.mq.addEventListener('change', this.handleMqChange);
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
disconnect() {
|
|
24
|
-
// Clean up event listener
|
|
25
30
|
window.removeEventListener('storage', this.handleStorageChange);
|
|
31
|
+
if (this.mq) this.mq.removeEventListener('change', this.handleMqChange);
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
toggleMode() {
|
|
29
|
-
const current = this.
|
|
30
|
-
const next = current
|
|
35
|
+
const current = this.readMode();
|
|
36
|
+
const next = ORDER[(ORDER.indexOf(current) + 1) % ORDER.length];
|
|
31
37
|
this.setMode(next);
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
setMode(mode) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} else {
|
|
39
|
-
document.documentElement.classList.remove("dark");
|
|
40
|
-
}
|
|
41
|
+
localStorage.setItem('theme', mode);
|
|
42
|
+
this.applyMode(mode);
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
|
|
45
|
+
applyMode(mode) {
|
|
46
|
+
const effective = this.effectiveMode(mode);
|
|
47
|
+
document.documentElement.classList.toggle('dark', effective === 'dark');
|
|
43
48
|
this.currentValue = mode;
|
|
44
|
-
|
|
45
|
-
// Show/hide icons
|
|
46
49
|
this.toggleIcons(mode);
|
|
50
|
+
}
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
localStorage.
|
|
52
|
+
readMode() {
|
|
53
|
+
const saved = localStorage.getItem('theme');
|
|
54
|
+
return ORDER.includes(saved) ? saved : 'auto';
|
|
50
55
|
}
|
|
51
56
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
effectiveMode(mode) {
|
|
58
|
+
if (mode === 'light' || mode === 'dark') return mode;
|
|
59
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
60
|
+
}
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
toggleIcons(mode) {
|
|
63
|
+
const icons = {
|
|
64
|
+
auto: this.element.querySelector(".color-mode-icon-auto"),
|
|
65
|
+
light: this.element.querySelector(".color-mode-icon-light"),
|
|
66
|
+
dark: this.element.querySelector(".color-mode-icon-dark"),
|
|
67
|
+
};
|
|
68
|
+
for (const [key, el] of Object.entries(icons)) {
|
|
69
|
+
if (!el) continue;
|
|
70
|
+
el.classList.toggle("hidden", key !== mode);
|
|
64
71
|
}
|
|
65
72
|
}
|
|
66
73
|
}
|
|
@@ -54,7 +54,30 @@ export default class extends Controller {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
if (this.modal) {
|
|
57
|
+
// Inside a <dialog> opened via showModal(), the dialog establishes its
|
|
58
|
+
// own containing block in the top layer. flatpickr's default positioning
|
|
59
|
+
// computes document coordinates but the calendar (appended to the
|
|
60
|
+
// dialog) interprets them relative to the dialog's box, placing the
|
|
61
|
+
// calendar far from the input. Append to the modal and reposition
|
|
62
|
+
// manually relative to the modal's bounding rect.
|
|
57
63
|
options.appendTo = this.modal;
|
|
64
|
+
options.position = (instance) => {
|
|
65
|
+
const input = instance.altInput || instance.input;
|
|
66
|
+
const inputRect = input.getBoundingClientRect();
|
|
67
|
+
const modalRect = this.modal.getBoundingClientRect();
|
|
68
|
+
const cal = instance.calendarContainer;
|
|
69
|
+
const calHeight = cal.offsetHeight;
|
|
70
|
+
const spaceBelow = window.innerHeight - inputRect.bottom;
|
|
71
|
+
const showAbove = spaceBelow < calHeight && inputRect.top > calHeight;
|
|
72
|
+
const top = showAbove
|
|
73
|
+
? inputRect.top - modalRect.top - calHeight - 2
|
|
74
|
+
: inputRect.bottom - modalRect.top + 2;
|
|
75
|
+
cal.style.top = `${top}px`;
|
|
76
|
+
cal.style.left = `${inputRect.left - modalRect.left}px`;
|
|
77
|
+
cal.style.right = "auto";
|
|
78
|
+
cal.classList.toggle("arrowTop", !showAbove);
|
|
79
|
+
cal.classList.toggle("arrowBottom", showAbove);
|
|
80
|
+
};
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
return options;
|
|
@@ -1,3 +1,30 @@
|
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Persists across controller reconnects so the value saved on
|
|
4
|
+
// turbo:before-render is still available on turbo:render, even though
|
|
5
|
+
// the <aside> hosting this controller is replaced during navigation.
|
|
6
|
+
let savedScrollTop = 0;
|
|
7
|
+
|
|
8
|
+
export default class extends Controller {
|
|
9
|
+
static targets = ["scroll"];
|
|
10
|
+
|
|
11
|
+
connect() {
|
|
12
|
+
this.beforeRender = this.beforeRender.bind(this);
|
|
13
|
+
this.afterRender = this.afterRender.bind(this);
|
|
14
|
+
document.addEventListener("turbo:before-render", this.beforeRender);
|
|
15
|
+
document.addEventListener("turbo:render", this.afterRender);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
disconnect() {
|
|
19
|
+
document.removeEventListener("turbo:before-render", this.beforeRender);
|
|
20
|
+
document.removeEventListener("turbo:render", this.afterRender);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
beforeRender() {
|
|
24
|
+
if (this.hasScrollTarget) savedScrollTop = this.scrollTarget.scrollTop;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
afterRender() {
|
|
28
|
+
if (this.hasScrollTarget) this.scrollTarget.scrollTop = savedScrollTop;
|
|
29
|
+
}
|
|
30
|
+
}
|