stimeo-ui 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +163 -0
- data/dist/controllers/accordion_controller.js +10 -0
- data/dist/controllers/alert_dialog_controller.js +318 -0
- data/dist/controllers/breadcrumb_controller.js +225 -13
- data/dist/controllers/calendar_controller.js +89 -22
- data/dist/controllers/carousel_controller.js +313 -0
- data/dist/controllers/clipboard_controller.js +144 -0
- data/dist/controllers/collapsible_controller.js +327 -0
- data/dist/controllers/color_picker_controller.js +252 -0
- data/dist/controllers/combobox_controller.js +162 -23
- data/dist/controllers/command_palette_controller.js +194 -17
- data/dist/controllers/context_menu_controller.js +32 -10
- data/dist/controllers/count_up_controller.js +8 -1
- data/dist/controllers/currency_input_controller.js +147 -0
- data/dist/controllers/data_grid_controller.js +246 -0
- data/dist/controllers/date_range_picker_controller.js +441 -0
- data/dist/controllers/dismissible_controller.js +117 -0
- data/dist/controllers/drawer_controller.js +630 -0
- data/dist/controllers/editable_controller.js +169 -0
- data/dist/controllers/file_dropzone_controller.js +165 -0
- data/dist/controllers/filter_controller.js +86 -0
- data/dist/controllers/flash_controller.js +36 -5
- data/dist/controllers/form_validation_controller.js +1 -1
- data/dist/controllers/highlight_controller.js +6 -4
- data/dist/controllers/intersection_controller.js +67 -19
- data/dist/controllers/lazy_frame_controller.js +54 -11
- data/dist/controllers/listbox_controller.js +257 -53
- data/dist/controllers/local_time_controller.js +2 -2
- data/dist/controllers/masonry_controller.js +142 -0
- data/dist/controllers/menu_controller.js +104 -17
- data/dist/controllers/menubar_controller.js +785 -0
- data/dist/controllers/multi_select_controller.js +755 -0
- data/dist/controllers/navigation_menu_controller.js +511 -0
- data/dist/controllers/number_input_controller.js +7 -0
- data/dist/controllers/otp_controller.js +18 -1
- data/dist/controllers/overflow_indicator_controller.js +246 -27
- data/dist/controllers/overflow_menu_controller.js +381 -57
- data/dist/controllers/pagination_controller.js +163 -32
- data/dist/controllers/password_reveal_controller.js +117 -0
- data/dist/controllers/persist_controller.js +6 -6
- data/dist/controllers/pointer_drag_controller.js +9 -1
- data/dist/controllers/popover_controller.js +2 -2
- data/dist/controllers/radio_group_controller.js +22 -3
- data/dist/controllers/range_slider_controller.js +192 -0
- data/dist/controllers/rating_controller.js +16 -2
- data/dist/controllers/read_more_controller.js +238 -0
- data/dist/controllers/resizable_controller.js +65 -1
- data/dist/controllers/roving_controller.js +17 -2
- data/dist/controllers/scroll_area_controller.js +101 -14
- data/dist/controllers/scroll_restore_controller.js +93 -0
- data/dist/controllers/scroll_visibility_controller.js +40 -6
- data/dist/controllers/scrollspy_controller.js +369 -74
- data/dist/controllers/separator_controller.js +96 -0
- data/dist/controllers/sidebar_controller.js +761 -0
- data/dist/controllers/skeleton_controller.js +1 -1
- data/dist/controllers/slider_controller.js +32 -6
- data/dist/controllers/sortable_controller.js +34 -3
- data/dist/controllers/spinner_controller.js +1 -1
- data/dist/controllers/stepper_controller.js +28 -12
- data/dist/controllers/stick_to_bottom_controller.js +9 -4
- data/dist/controllers/sticky_observer_controller.js +109 -20
- data/dist/controllers/switch_controller.js +1 -0
- data/dist/controllers/tabs_controller.js +26 -3
- data/dist/controllers/tags_input_controller.js +295 -0
- data/dist/controllers/theme_controller.js +42 -13
- data/dist/controllers/time_picker_controller.js +231 -0
- data/dist/controllers/toast_controller.js +40 -14
- data/dist/controllers/toggle_group_controller.js +23 -2
- data/dist/controllers/toolbar_controller.js +230 -31
- data/dist/controllers/transition_controller.js +153 -38
- data/dist/controllers/tree_view_controller.js +691 -0
- data/dist/index.js +4256 -915
- data/lib/stimeo/ui/version.rb +2 -3
- metadata +28 -2
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// src/controllers/tags_input_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/logical_scroll.ts
|
|
6
|
+
function isRtl(element) {
|
|
7
|
+
return window.getComputedStyle(element).direction === "rtl";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/utils/arrow_step.ts
|
|
11
|
+
function logicalArrowKey(key, element) {
|
|
12
|
+
if (key !== "ArrowRight" && key !== "ArrowLeft") return key;
|
|
13
|
+
if (!isRtl(element)) return key;
|
|
14
|
+
return key === "ArrowRight" ? "ArrowLeft" : "ArrowRight";
|
|
15
|
+
}
|
|
16
|
+
function isReservedArrowChord(event, allow = []) {
|
|
17
|
+
if (!event.key.startsWith("Arrow")) return false;
|
|
18
|
+
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/utils/composition_tracker.ts
|
|
22
|
+
var CompositionTracker = class {
|
|
23
|
+
#observedTargets = /* @__PURE__ */ new Set();
|
|
24
|
+
#activeTargets = /* @__PURE__ */ new Set();
|
|
25
|
+
#onStart;
|
|
26
|
+
#onEnd;
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
this.#onStart = options.onStart;
|
|
29
|
+
this.#onEnd = options.onEnd;
|
|
30
|
+
}
|
|
31
|
+
/** Starts lifecycle tracking for `target`; repeated calls are idempotent. */
|
|
32
|
+
observe(target) {
|
|
33
|
+
if (this.#observedTargets.has(target)) return;
|
|
34
|
+
target.addEventListener("compositionstart", this.#handleStart);
|
|
35
|
+
target.addEventListener("compositionend", this.#handleEnd);
|
|
36
|
+
this.#observedTargets.add(target);
|
|
37
|
+
}
|
|
38
|
+
/** Stops tracking one target and clears any active composition it owned. */
|
|
39
|
+
unobserve(target) {
|
|
40
|
+
if (!this.#observedTargets.delete(target)) return;
|
|
41
|
+
target.removeEventListener("compositionstart", this.#handleStart);
|
|
42
|
+
target.removeEventListener("compositionend", this.#handleEnd);
|
|
43
|
+
this.#activeTargets.delete(target);
|
|
44
|
+
}
|
|
45
|
+
/** Releases every listener and clears state so reconnect starts cleanly. */
|
|
46
|
+
disconnect() {
|
|
47
|
+
for (const target of this.#observedTargets) {
|
|
48
|
+
target.removeEventListener("compositionstart", this.#handleStart);
|
|
49
|
+
target.removeEventListener("compositionend", this.#handleEnd);
|
|
50
|
+
}
|
|
51
|
+
this.#observedTargets.clear();
|
|
52
|
+
this.#activeTargets.clear();
|
|
53
|
+
}
|
|
54
|
+
/** True when lifecycle tracking or the current event reports composition. */
|
|
55
|
+
isComposing(event) {
|
|
56
|
+
return this.#activeTargets.size > 0 || event?.isComposing === true;
|
|
57
|
+
}
|
|
58
|
+
#handleStart = (event) => {
|
|
59
|
+
if (event.currentTarget) this.#activeTargets.add(event.currentTarget);
|
|
60
|
+
this.#onStart?.(event);
|
|
61
|
+
};
|
|
62
|
+
#handleEnd = (event) => {
|
|
63
|
+
if (event.currentTarget) this.#activeTargets.delete(event.currentTarget);
|
|
64
|
+
this.#onEnd?.(event);
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/utils/roving_tabindex.ts
|
|
69
|
+
var RovingTabindex = class {
|
|
70
|
+
/** Returns the current ordered item elements; called on every operation. */
|
|
71
|
+
#getItems;
|
|
72
|
+
/**
|
|
73
|
+
* @param getItems - Returns the current ordered item elements. Called on every
|
|
74
|
+
* operation so the live target list is always used.
|
|
75
|
+
*/
|
|
76
|
+
constructor(getItems) {
|
|
77
|
+
this.#getItems = getItems;
|
|
78
|
+
}
|
|
79
|
+
/** Index of the currently tabbable item (`tabindex="0"`), or `-1` if none. */
|
|
80
|
+
get activeIndex() {
|
|
81
|
+
return this.#getItems().findIndex((item) => item.tabIndex === 0);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Makes exactly the item at `index` tabbable (`tabindex="0"`) and removes every
|
|
85
|
+
* other item from the Tab sequence (`tabindex="-1"`). An out-of-range `index`
|
|
86
|
+
* (e.g. `-1`) leaves all items at `-1`, which a controller can use to express
|
|
87
|
+
* "nothing is currently tabbable".
|
|
88
|
+
*
|
|
89
|
+
* @param index - Position of the item to make tabbable.
|
|
90
|
+
* @param options - Pass `{ focus: true }` to also move DOM focus to that item.
|
|
91
|
+
*/
|
|
92
|
+
setActive(index, { focus = false } = {}) {
|
|
93
|
+
const items = this.#getItems();
|
|
94
|
+
items.forEach((item, i) => {
|
|
95
|
+
item.tabIndex = i === index ? 0 : -1;
|
|
96
|
+
});
|
|
97
|
+
if (focus) items[index]?.focus();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/controllers/tags_input_controller.ts
|
|
102
|
+
var TagsInputController = class extends Controller {
|
|
103
|
+
static targets = ["input", "tags", "tag", "tagTemplate", "status", "fields"];
|
|
104
|
+
static values = {
|
|
105
|
+
delimiter: { type: String, default: "," },
|
|
106
|
+
max: { type: Number, default: 0 },
|
|
107
|
+
allowDuplicates: { type: Boolean, default: false },
|
|
108
|
+
name: { type: String, default: "tags[]" }
|
|
109
|
+
};
|
|
110
|
+
static actions = ["onKeydown"];
|
|
111
|
+
static events = ["change", "reject"];
|
|
112
|
+
#roving = new RovingTabindex(() => this.#removeButtons);
|
|
113
|
+
/** Owns IME lifecycle state for commit-key guarding. */
|
|
114
|
+
#composition = new CompositionTracker();
|
|
115
|
+
/** Wires tag-list keyboard navigation and removal, and seeds the single Tab stop. */
|
|
116
|
+
connect() {
|
|
117
|
+
if (this.hasInputTarget) this.#composition.observe(this.inputTarget);
|
|
118
|
+
this.tagsTarget.addEventListener("keydown", this.#onTagKeydown);
|
|
119
|
+
this.tagsTarget.addEventListener("click", this.#onTagClick);
|
|
120
|
+
this.#syncState();
|
|
121
|
+
}
|
|
122
|
+
/** Releases the delegated listeners so no handler outlives the element. */
|
|
123
|
+
disconnect() {
|
|
124
|
+
this.#composition.disconnect();
|
|
125
|
+
this.tagsTarget.removeEventListener("keydown", this.#onTagKeydown);
|
|
126
|
+
this.tagsTarget.removeEventListener("click", this.#onTagClick);
|
|
127
|
+
}
|
|
128
|
+
/** Tracks an input added initially or after connect. */
|
|
129
|
+
inputTargetConnected(input) {
|
|
130
|
+
this.#composition.observe(input);
|
|
131
|
+
}
|
|
132
|
+
/** Removes composition listeners when the active input is replaced or removed. */
|
|
133
|
+
inputTargetDisconnected(input) {
|
|
134
|
+
this.#composition.unobserve(input);
|
|
135
|
+
}
|
|
136
|
+
/** Commits on `Enter`/delimiter and deletes the last tag on empty `Backspace`. */
|
|
137
|
+
onKeydown(event) {
|
|
138
|
+
if (event.defaultPrevented) return;
|
|
139
|
+
if (isReservedArrowChord(event)) return;
|
|
140
|
+
if (this.#composition.isComposing(event)) return;
|
|
141
|
+
if (event.key === "Enter" || event.key === this.delimiterValue) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
this.#commitInput();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (event.key === "Backspace" && this.inputTarget.value === "") {
|
|
147
|
+
const buttons = this.#removeButtons;
|
|
148
|
+
if (buttons.length > 0) {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
this.#removeAt(buttons.length - 1);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (logicalArrowKey(event.key, this.element) === "ArrowLeft" && this.inputTarget.value === "") {
|
|
155
|
+
const buttons = this.#removeButtons;
|
|
156
|
+
if (buttons.length > 0) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
this.#roving.setActive(buttons.length - 1, { focus: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Deletes the tag whose remove button was clicked. Delegated on the tags
|
|
164
|
+
* container (like `#onTagKeydown`) rather than bound per chip via
|
|
165
|
+
* `data-action`, so it works the instant a chip is appended without waiting on
|
|
166
|
+
* Stimulus to wire a freshly created element.
|
|
167
|
+
*/
|
|
168
|
+
#onTagClick = (event) => {
|
|
169
|
+
const button = event.target.closest("button");
|
|
170
|
+
if (!button || !this.tagsTarget.contains(button)) return;
|
|
171
|
+
const index = this.#removeButtons.indexOf(button);
|
|
172
|
+
if (index !== -1) this.#removeAt(index);
|
|
173
|
+
};
|
|
174
|
+
/** Validates and adds the current input value as a tag, then clears the input. */
|
|
175
|
+
#commitInput() {
|
|
176
|
+
const value = this.inputTarget.value.trim();
|
|
177
|
+
if (value === "") {
|
|
178
|
+
this.#reject(value, "empty");
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (this.maxValue > 0 && this.tagTargets.length >= this.maxValue) {
|
|
182
|
+
this.#reject(value, "max");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!this.allowDuplicatesValue && this.#values.includes(value)) {
|
|
186
|
+
this.#reject(value, "duplicate");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.#appendTag(value);
|
|
190
|
+
this.inputTarget.value = "";
|
|
191
|
+
this.#announce(value);
|
|
192
|
+
this.#syncState();
|
|
193
|
+
this.dispatch("change", { detail: { tags: this.#values } });
|
|
194
|
+
}
|
|
195
|
+
/** Builds one chip from the template and appends it to the tag list. */
|
|
196
|
+
#appendTag(value) {
|
|
197
|
+
if (!this.hasTagTemplateTarget) return;
|
|
198
|
+
const fragment = this.tagTemplateTarget.content.cloneNode(true);
|
|
199
|
+
const tag = fragment.querySelector('[data-stimeo--tags-input-target="tag"]');
|
|
200
|
+
const label = fragment.querySelector('[data-tags-input-slot="label"]');
|
|
201
|
+
const button = fragment.querySelector("button");
|
|
202
|
+
if (!tag || !button) return;
|
|
203
|
+
tag.dataset.value = value;
|
|
204
|
+
if (label) label.textContent = value;
|
|
205
|
+
button.setAttribute("aria-label", `Remove ${value}`);
|
|
206
|
+
button.tabIndex = -1;
|
|
207
|
+
this.tagsTarget.appendChild(fragment);
|
|
208
|
+
}
|
|
209
|
+
/** Removes the tag at `index`, then moves focus to a neighbor or the input. */
|
|
210
|
+
#removeAt(index) {
|
|
211
|
+
const tag = this.tagTargets[index];
|
|
212
|
+
if (!tag) return;
|
|
213
|
+
const value = tag.dataset.value ?? "";
|
|
214
|
+
tag.remove();
|
|
215
|
+
this.#announce(value);
|
|
216
|
+
this.#syncState();
|
|
217
|
+
this.dispatch("change", { detail: { tags: this.#values } });
|
|
218
|
+
const remaining = this.#removeButtons;
|
|
219
|
+
if (remaining.length === 0) {
|
|
220
|
+
this.inputTarget.focus();
|
|
221
|
+
} else {
|
|
222
|
+
this.#roving.setActive(Math.min(index, remaining.length - 1), { focus: true });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** Handles arrow navigation and deletion within the chip list (delegated). */
|
|
226
|
+
#onTagKeydown = (event) => {
|
|
227
|
+
if (event.defaultPrevented) return;
|
|
228
|
+
if (isReservedArrowChord(event)) return;
|
|
229
|
+
const button = event.target.closest("button");
|
|
230
|
+
if (!button) return;
|
|
231
|
+
const buttons = this.#removeButtons;
|
|
232
|
+
const index = buttons.indexOf(button);
|
|
233
|
+
if (index === -1) return;
|
|
234
|
+
switch (logicalArrowKey(event.key, this.element)) {
|
|
235
|
+
case "ArrowLeft":
|
|
236
|
+
if (index > 0) {
|
|
237
|
+
event.preventDefault();
|
|
238
|
+
this.#roving.setActive(index - 1, { focus: true });
|
|
239
|
+
}
|
|
240
|
+
break;
|
|
241
|
+
case "ArrowRight":
|
|
242
|
+
event.preventDefault();
|
|
243
|
+
if (index < buttons.length - 1) {
|
|
244
|
+
this.#roving.setActive(index + 1, { focus: true });
|
|
245
|
+
} else {
|
|
246
|
+
this.inputTarget.focus();
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
case "Delete":
|
|
250
|
+
case "Backspace":
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
this.#removeAt(index);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
/** Rebuilds the hidden form fields, the `full` flag, and the roving Tab stop. */
|
|
257
|
+
#syncState() {
|
|
258
|
+
if (this.hasFieldsTarget) {
|
|
259
|
+
this.fieldsTarget.replaceChildren(
|
|
260
|
+
...this.#values.map((value) => {
|
|
261
|
+
const input = document.createElement("input");
|
|
262
|
+
input.type = "hidden";
|
|
263
|
+
input.name = this.nameValue;
|
|
264
|
+
input.value = value;
|
|
265
|
+
return input;
|
|
266
|
+
})
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
const full = this.maxValue > 0 && this.tagTargets.length >= this.maxValue;
|
|
270
|
+
this.element.toggleAttribute("data-stimeo--tags-input-full", full);
|
|
271
|
+
if (this.#removeButtons.length > 0 && this.#roving.activeIndex === -1) {
|
|
272
|
+
this.#roving.setActive(0);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/** Mirrors the changed tag into the live region for assistive tech. */
|
|
276
|
+
#announce(value) {
|
|
277
|
+
if (this.hasStatusTarget) this.statusTarget.textContent = value;
|
|
278
|
+
}
|
|
279
|
+
/** Reports a rejected addition via `stimeo--tags-input:reject`. */
|
|
280
|
+
#reject(value, reason) {
|
|
281
|
+
this.dispatch("reject", { detail: { value, reason } });
|
|
282
|
+
}
|
|
283
|
+
/** The remove buttons in document order (the roving navigation set). */
|
|
284
|
+
get #removeButtons() {
|
|
285
|
+
return Array.from(this.tagsTarget.querySelectorAll("button"));
|
|
286
|
+
}
|
|
287
|
+
/** Current tag values in order. */
|
|
288
|
+
get #values() {
|
|
289
|
+
return this.tagTargets.map((tag) => tag.dataset.value ?? "");
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
export { TagsInputController };
|
|
294
|
+
//# sourceMappingURL=tags_input_controller.js.map
|
|
295
|
+
//# sourceMappingURL=tags_input_controller.js.map
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
+
// src/controllers/theme_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/logical_scroll.ts
|
|
6
|
+
function isRtl(element) {
|
|
7
|
+
return window.getComputedStyle(element).direction === "rtl";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/utils/arrow_step.ts
|
|
11
|
+
function logicalArrowStep(key, element) {
|
|
12
|
+
if (key === "ArrowDown") return 1;
|
|
13
|
+
if (key === "ArrowUp") return -1;
|
|
14
|
+
if (key !== "ArrowRight" && key !== "ArrowLeft") return 0;
|
|
15
|
+
const forward = isRtl(element) ? "ArrowLeft" : "ArrowRight";
|
|
16
|
+
return key === forward ? 1 : -1;
|
|
17
|
+
}
|
|
18
|
+
function isReservedArrowChord(event, allow = []) {
|
|
19
|
+
if (!event.key.startsWith("Arrow")) return false;
|
|
20
|
+
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/utils/safe_storage.ts
|
|
24
|
+
function readLocalStorage(key) {
|
|
25
|
+
try {
|
|
26
|
+
return window.localStorage.getItem(key);
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function writeLocalStorage(key, value) {
|
|
32
|
+
try {
|
|
33
|
+
window.localStorage.setItem(key, value);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
3
38
|
// src/controllers/theme_controller.ts
|
|
4
39
|
var MODES = ["light", "dark", "system"];
|
|
5
40
|
var isMode = (value) => typeof value === "string" && MODES.includes(value);
|
|
@@ -24,6 +59,8 @@ var ThemeController = class extends Controller {
|
|
|
24
59
|
};
|
|
25
60
|
/** Arrow/Home/End navigation for the radiogroup (APG radio pattern). */
|
|
26
61
|
#onKeydown = (event) => {
|
|
62
|
+
if (event.defaultPrevented) return;
|
|
63
|
+
if (isReservedArrowChord(event)) return;
|
|
27
64
|
const options = this.optionTargets;
|
|
28
65
|
if (options.length === 0) return;
|
|
29
66
|
const target = event.target;
|
|
@@ -31,14 +68,13 @@ var ThemeController = class extends Controller {
|
|
|
31
68
|
if (current === -1) return;
|
|
32
69
|
const last = options.length - 1;
|
|
33
70
|
let next = current;
|
|
71
|
+
const step = logicalArrowStep(event.key, this.element);
|
|
34
72
|
switch (event.key) {
|
|
35
73
|
case "ArrowDown":
|
|
36
74
|
case "ArrowRight":
|
|
37
|
-
next = current === last ? 0 : current + 1;
|
|
38
|
-
break;
|
|
39
75
|
case "ArrowUp":
|
|
40
76
|
case "ArrowLeft":
|
|
41
|
-
next = current === 0 ? last : current - 1;
|
|
77
|
+
next = step === 1 ? current === last ? 0 : current + 1 : current === 0 ? last : current - 1;
|
|
42
78
|
break;
|
|
43
79
|
case "Home":
|
|
44
80
|
next = 0;
|
|
@@ -133,19 +169,12 @@ var ThemeController = class extends Controller {
|
|
|
133
169
|
}
|
|
134
170
|
/** Reads a persisted, validated mode from `localStorage` (null when absent/blocked). */
|
|
135
171
|
#readStored() {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return isMode(value) ? value : null;
|
|
139
|
-
} catch {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
172
|
+
const value = readLocalStorage(this.storageKeyValue);
|
|
173
|
+
return isMode(value) ? value : null;
|
|
142
174
|
}
|
|
143
175
|
/** Persists the mode, swallowing storage errors (private mode / quota). */
|
|
144
176
|
#writeStored(mode) {
|
|
145
|
-
|
|
146
|
-
window.localStorage.setItem(this.storageKeyValue, mode);
|
|
147
|
-
} catch {
|
|
148
|
-
}
|
|
177
|
+
writeLocalStorage(this.storageKeyValue, mode);
|
|
149
178
|
}
|
|
150
179
|
};
|
|
151
180
|
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// src/controllers/time_picker_controller.ts
|
|
4
|
+
|
|
5
|
+
// src/utils/logical_scroll.ts
|
|
6
|
+
function isRtl(element) {
|
|
7
|
+
return window.getComputedStyle(element).direction === "rtl";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/utils/arrow_step.ts
|
|
11
|
+
function logicalArrowKey(key, element) {
|
|
12
|
+
if (key !== "ArrowRight" && key !== "ArrowLeft") return key;
|
|
13
|
+
if (!isRtl(element)) return key;
|
|
14
|
+
return key === "ArrowRight" ? "ArrowLeft" : "ArrowRight";
|
|
15
|
+
}
|
|
16
|
+
function isReservedArrowChord(event, allow = []) {
|
|
17
|
+
if (!event.key.startsWith("Arrow")) return false;
|
|
18
|
+
return event.altKey && !allow.includes("alt") || event.ctrlKey && !allow.includes("ctrl") || event.metaKey && !allow.includes("meta") || event.shiftKey && !allow.includes("shift");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/controllers/time_picker_controller.ts
|
|
22
|
+
var AM = 0;
|
|
23
|
+
var PM = 1;
|
|
24
|
+
var TimePickerController = class extends Controller {
|
|
25
|
+
static targets = ["segment", "field"];
|
|
26
|
+
static values = {
|
|
27
|
+
hourCycle: { type: Number, default: 24 },
|
|
28
|
+
step: { type: Number, default: 1 },
|
|
29
|
+
seconds: { type: Boolean, default: false },
|
|
30
|
+
wrap: { type: Boolean, default: true }
|
|
31
|
+
};
|
|
32
|
+
static actions = ["onKeydown"];
|
|
33
|
+
static events = ["change"];
|
|
34
|
+
/** Current numeric value per segment kind (hours are the *displayed* hours). */
|
|
35
|
+
#state = { hour: 0, minute: 0, second: 0, meridiem: AM };
|
|
36
|
+
/** Direct-entry digit buffer and the segment it belongs to. */
|
|
37
|
+
#typeBuffer = "";
|
|
38
|
+
#typeSegment = null;
|
|
39
|
+
/** Last composed field value, to suppress duplicate `change` dispatches. */
|
|
40
|
+
#lastValue = "";
|
|
41
|
+
/** Seeds each segment from its initial `aria-valuenow` and syncs the field. */
|
|
42
|
+
connect() {
|
|
43
|
+
for (const segment of this.segmentTargets) {
|
|
44
|
+
const kind = this.#kindOf(segment);
|
|
45
|
+
if (!kind) continue;
|
|
46
|
+
const now = Number(segment.getAttribute("aria-valuenow"));
|
|
47
|
+
const { min, max } = this.#bounds(kind);
|
|
48
|
+
this.#state[kind] = Number.isFinite(now) ? Math.min(max, Math.max(min, now)) : min;
|
|
49
|
+
}
|
|
50
|
+
for (const segment of this.segmentTargets) this.#renderSegment(segment);
|
|
51
|
+
this.#syncField(false);
|
|
52
|
+
}
|
|
53
|
+
/** Handles stepping, inter-segment focus moves, jumps, and direct entry. */
|
|
54
|
+
onKeydown(event) {
|
|
55
|
+
if (isReservedArrowChord(event)) return;
|
|
56
|
+
const segment = event.target?.closest(
|
|
57
|
+
"[data-stimeo--time-picker-target='segment']"
|
|
58
|
+
);
|
|
59
|
+
const kind = segment ? this.#kindOf(segment) : null;
|
|
60
|
+
if (!segment || !kind) return;
|
|
61
|
+
switch (logicalArrowKey(event.key, this.element)) {
|
|
62
|
+
case "ArrowUp":
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
this.#step(kind, this.#delta(kind));
|
|
65
|
+
break;
|
|
66
|
+
case "ArrowDown":
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
this.#step(kind, -this.#delta(kind));
|
|
69
|
+
break;
|
|
70
|
+
case "ArrowLeft":
|
|
71
|
+
event.preventDefault();
|
|
72
|
+
this.#focusSibling(segment, -1);
|
|
73
|
+
break;
|
|
74
|
+
case "ArrowRight":
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
this.#focusSibling(segment, 1);
|
|
77
|
+
break;
|
|
78
|
+
case "Home":
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
this.#set(kind, this.#bounds(kind).min);
|
|
81
|
+
break;
|
|
82
|
+
case "End":
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
this.#set(kind, this.#bounds(kind).max);
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
if (/^[0-9]$/.test(event.key)) {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
this.#typeDigit(segment, kind, event.key);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.#typeBuffer = "";
|
|
94
|
+
this.#typeSegment = null;
|
|
95
|
+
}
|
|
96
|
+
/** The per-step delta: minutes step by `step`, others by 1, meridiem toggles. */
|
|
97
|
+
#delta(kind) {
|
|
98
|
+
return kind === "minute" ? this.stepValue : 1;
|
|
99
|
+
}
|
|
100
|
+
/** Steps a segment, wrapping at its bounds and carrying over when enabled. */
|
|
101
|
+
#step(kind, delta) {
|
|
102
|
+
if (kind === "meridiem") {
|
|
103
|
+
this.#set("meridiem", this.#state.meridiem === AM ? PM : AM);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const { min, max } = this.#bounds(kind);
|
|
107
|
+
const span = max - min + 1;
|
|
108
|
+
const raw = this.#state[kind] + delta;
|
|
109
|
+
if (raw > max || raw < min) {
|
|
110
|
+
if (!this.wrapValue) {
|
|
111
|
+
this.#set(kind, Math.min(max, Math.max(min, raw)));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const wrapped = ((raw - min) % span + span) % span + min;
|
|
115
|
+
const carry = Math.floor((raw - min) / span);
|
|
116
|
+
this.#set(kind, wrapped);
|
|
117
|
+
this.#carry(kind, carry);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.#set(kind, raw);
|
|
121
|
+
}
|
|
122
|
+
/** Propagates a wrap carry from `kind` into the next larger segment. */
|
|
123
|
+
#carry(kind, amount) {
|
|
124
|
+
if (amount === 0) return;
|
|
125
|
+
if (kind === "second") this.#step("minute", amount);
|
|
126
|
+
else if (kind === "minute") this.#step("hour", amount);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Sets a segment's value (clamped to its `[min, max]` bounds), re-renders it,
|
|
130
|
+
* and resyncs the composed field. Clamping here guards the direct-entry path:
|
|
131
|
+
* typing `0` into a 12-hour hour (min 1) must not commit an out-of-range
|
|
132
|
+
* `aria-valuenow="0"`. The stepping path already passes in-bounds values, so
|
|
133
|
+
* the clamp is a no-op there.
|
|
134
|
+
*/
|
|
135
|
+
#set(kind, value) {
|
|
136
|
+
const { min, max } = this.#bounds(kind);
|
|
137
|
+
this.#state[kind] = Math.min(max, Math.max(min, value));
|
|
138
|
+
const segment = this.segmentTargets.find((s) => this.#kindOf(s) === kind);
|
|
139
|
+
if (segment) this.#renderSegment(segment);
|
|
140
|
+
this.#syncField(true);
|
|
141
|
+
}
|
|
142
|
+
/** Accumulates a typed digit, committing and advancing after two digits. */
|
|
143
|
+
#typeDigit(segment, kind, digit) {
|
|
144
|
+
if (kind === "meridiem") return;
|
|
145
|
+
if (this.#typeSegment !== kind) this.#typeBuffer = "";
|
|
146
|
+
this.#typeSegment = kind;
|
|
147
|
+
const { max } = this.#bounds(kind);
|
|
148
|
+
const candidate = Number(`${this.#typeBuffer}${digit}`);
|
|
149
|
+
if (candidate <= max) this.#typeBuffer = `${this.#typeBuffer}${digit}`;
|
|
150
|
+
else this.#typeBuffer = digit;
|
|
151
|
+
this.#set(kind, Number(this.#typeBuffer));
|
|
152
|
+
if (this.#typeBuffer.length >= 2 || Number(this.#typeBuffer) * 10 > max) {
|
|
153
|
+
this.#typeBuffer = "";
|
|
154
|
+
this.#typeSegment = null;
|
|
155
|
+
this.#focusSibling(segment, 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** Moves focus to the previous/next segment, if one exists. */
|
|
159
|
+
#focusSibling(segment, direction) {
|
|
160
|
+
const index = this.segmentTargets.indexOf(segment);
|
|
161
|
+
const next = this.segmentTargets[index + direction];
|
|
162
|
+
next?.focus();
|
|
163
|
+
}
|
|
164
|
+
/** Reflects a segment's current value onto its ARIA/text representation. */
|
|
165
|
+
#renderSegment(segment) {
|
|
166
|
+
const kind = this.#kindOf(segment);
|
|
167
|
+
if (!kind) return;
|
|
168
|
+
const value = this.#state[kind];
|
|
169
|
+
if (kind === "meridiem") {
|
|
170
|
+
const text2 = value === PM ? "PM" : "AM";
|
|
171
|
+
segment.setAttribute("aria-valuenow", String(value));
|
|
172
|
+
segment.setAttribute("aria-valuetext", text2);
|
|
173
|
+
segment.setAttribute("aria-valuemin", String(AM));
|
|
174
|
+
segment.setAttribute("aria-valuemax", String(PM));
|
|
175
|
+
segment.textContent = text2;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const { min, max } = this.#bounds(kind);
|
|
179
|
+
const text = String(value).padStart(2, "0");
|
|
180
|
+
segment.setAttribute("aria-valuenow", String(value));
|
|
181
|
+
segment.setAttribute("aria-valuetext", text);
|
|
182
|
+
segment.setAttribute("aria-valuemin", String(min));
|
|
183
|
+
segment.setAttribute("aria-valuemax", String(max));
|
|
184
|
+
segment.textContent = text;
|
|
185
|
+
}
|
|
186
|
+
/** Composes `HH:MM[:SS]` (24-hour) into the hidden field; dispatches `change`. */
|
|
187
|
+
#syncField(notify) {
|
|
188
|
+
const h24 = this.#hours24();
|
|
189
|
+
const parts = [pad(h24), pad(this.#state.minute)];
|
|
190
|
+
if (this.secondsValue) parts.push(pad(this.#state.second));
|
|
191
|
+
const value = parts.join(":");
|
|
192
|
+
if (this.hasFieldTarget && this.fieldTarget.value !== value) {
|
|
193
|
+
this.fieldTarget.value = value;
|
|
194
|
+
}
|
|
195
|
+
if (notify && value !== this.#lastValue) this.dispatch("change", { detail: { value } });
|
|
196
|
+
this.#lastValue = value;
|
|
197
|
+
}
|
|
198
|
+
/** Converts the displayed hour (+ meridiem in 12-hour mode) to 24-hour. */
|
|
199
|
+
#hours24() {
|
|
200
|
+
if (this.hourCycleValue !== 12) return this.#state.hour;
|
|
201
|
+
const base = this.#state.hour % 12;
|
|
202
|
+
return base + (this.#state.meridiem === PM ? 12 : 0);
|
|
203
|
+
}
|
|
204
|
+
/** The inclusive `[min, max]` bounds for a segment kind. */
|
|
205
|
+
#bounds(kind) {
|
|
206
|
+
switch (kind) {
|
|
207
|
+
case "hour":
|
|
208
|
+
return this.hourCycleValue === 12 ? { min: 1, max: 12 } : { min: 0, max: 23 };
|
|
209
|
+
case "minute":
|
|
210
|
+
case "second":
|
|
211
|
+
return { min: 0, max: 59 };
|
|
212
|
+
case "meridiem":
|
|
213
|
+
return { min: AM, max: PM };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** Reads a segment's declared kind, or null when absent/invalid. */
|
|
217
|
+
#kindOf(segment) {
|
|
218
|
+
const kind = segment.getAttribute("data-segment");
|
|
219
|
+
if (kind === "hour" || kind === "minute" || kind === "second" || kind === "meridiem") {
|
|
220
|
+
return kind;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
function pad(value) {
|
|
226
|
+
return String(value).padStart(2, "0");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export { TimePickerController };
|
|
230
|
+
//# sourceMappingURL=time_picker_controller.js.map
|
|
231
|
+
//# sourceMappingURL=time_picker_controller.js.map
|
|
@@ -55,6 +55,40 @@ var SafeTimeout = class extends TimerRegistry {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
// src/utils/transition_completion.ts
|
|
59
|
+
function timeMs(value) {
|
|
60
|
+
const trimmed = value.trim();
|
|
61
|
+
const amount = Number.parseFloat(trimmed);
|
|
62
|
+
if (!Number.isFinite(amount)) return 0;
|
|
63
|
+
if (trimmed.endsWith("ms")) return amount;
|
|
64
|
+
if (trimmed.endsWith("s")) return amount * 1e3;
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
function cssList(value) {
|
|
68
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
69
|
+
}
|
|
70
|
+
function transitionTimings(style) {
|
|
71
|
+
const properties = cssList(style.transitionProperty);
|
|
72
|
+
const durations = cssList(style.transitionDuration).map(timeMs);
|
|
73
|
+
const delays = cssList(style.transitionDelay).map(timeMs);
|
|
74
|
+
const effectiveProperties = properties.length > 0 ? properties : Array.from({ length: Math.max(durations.length, delays.length, 1) }, () => "all");
|
|
75
|
+
const effectiveDurations = durations.length > 0 ? durations : [0];
|
|
76
|
+
const effectiveDelays = delays.length > 0 ? delays : [0];
|
|
77
|
+
return effectiveProperties.filter((property) => property !== "none").map((property, index) => ({
|
|
78
|
+
property,
|
|
79
|
+
totalMs: Math.max(
|
|
80
|
+
0,
|
|
81
|
+
(effectiveDurations[index % effectiveDurations.length] ?? 0) + (effectiveDelays[index % effectiveDelays.length] ?? 0)
|
|
82
|
+
)
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
function maxTotalMs(timings) {
|
|
86
|
+
return timings.reduce((max, { totalMs }) => Math.max(max, totalMs), 0);
|
|
87
|
+
}
|
|
88
|
+
function maxTransitionTotalMs(style) {
|
|
89
|
+
return maxTotalMs(transitionTimings(style));
|
|
90
|
+
}
|
|
91
|
+
|
|
58
92
|
// src/controllers/toast_controller.ts
|
|
59
93
|
var DELEGATED_EVENTS = ["click", "focusin", "focusout", "keydown", "mouseover", "mouseout"];
|
|
60
94
|
var ToastController = class extends Controller {
|
|
@@ -304,8 +338,7 @@ var ToastController = class extends Controller {
|
|
|
304
338
|
this.listTarget.removeChild(element);
|
|
305
339
|
this.dispatch("dismiss", { detail: { item: element, reason } });
|
|
306
340
|
};
|
|
307
|
-
const
|
|
308
|
-
const duration = cssTimeToMs(transitions);
|
|
341
|
+
const duration = maxTransitionTotalMs(window.getComputedStyle(element));
|
|
309
342
|
if (duration > 0) {
|
|
310
343
|
this.#timers.set(finalize, duration);
|
|
311
344
|
} else {
|
|
@@ -315,11 +348,10 @@ var ToastController = class extends Controller {
|
|
|
315
348
|
/**
|
|
316
349
|
* Removes the oldest toasts when the list exceeds `maxValue`.
|
|
317
350
|
*
|
|
318
|
-
* Public (not `#private`) as a deterministic
|
|
319
|
-
*
|
|
320
|
-
* MutationObserver
|
|
321
|
-
*
|
|
322
|
-
* NON_ACTION_ALLOWLIST (it is not a user-wired action).
|
|
351
|
+
* Public (not `#private`) as a deterministic seam: enforcement normally runs
|
|
352
|
+
* from `itemTargetConnected`, a Stimulus callback delivered through a
|
|
353
|
+
* MutationObserver, which a DOM-only environment does not reliably fire — so
|
|
354
|
+
* it can also be invoked directly. It is not a user-wired action.
|
|
323
355
|
*/
|
|
324
356
|
enforceMaxLimit() {
|
|
325
357
|
const currentItems = this.itemTargets;
|
|
@@ -377,13 +409,7 @@ var ToastController = class extends Controller {
|
|
|
377
409
|
this.#rafHandles.delete(element);
|
|
378
410
|
}
|
|
379
411
|
};
|
|
380
|
-
function cssTimeToMs(value) {
|
|
381
|
-
const first = value.split(",")[0]?.trim() ?? "";
|
|
382
|
-
const amount = Number.parseFloat(first);
|
|
383
|
-
if (Number.isNaN(amount)) return 0;
|
|
384
|
-
return first.endsWith("ms") ? amount : amount * 1e3;
|
|
385
|
-
}
|
|
386
412
|
|
|
387
|
-
export { ToastController
|
|
413
|
+
export { ToastController };
|
|
388
414
|
//# sourceMappingURL=toast_controller.js.map
|
|
389
415
|
//# sourceMappingURL=toast_controller.js.map
|