@radioactive-labs/plutonium 0.49.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.
@@ -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
- export default class extends Controller {}
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
+ }