loseta 0.17.0 → 0.19.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.
- package/README.md +37 -8
- package/dist/commands/add.d.ts +8 -0
- package/dist/commands/add.js +60 -15
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -1
- package/dist/imports.d.ts +4 -0
- package/dist/imports.js +30 -2
- package/dist/imports.js.map +1 -1
- package/dist/install.d.ts +23 -3
- package/dist/install.js +84 -5
- package/dist/install.js.map +1 -1
- package/dist/style-switch.js +2 -1
- package/dist/style-switch.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/ui.js +4 -1
- package/dist/ui.js.map +1 -1
- package/package.json +4 -3
- package/registry/behaviors/calendar.js +855 -0
- package/registry/behaviors/carousel.js +280 -0
- package/registry/behaviors/code-block.js +106 -0
- package/registry/behaviors/combobox.js +237 -0
- package/registry/behaviors/command.js +105 -0
- package/registry/behaviors/core.js +302 -0
- package/registry/behaviors/dialog.js +97 -0
- package/registry/behaviors/hover-overlay.js +180 -0
- package/registry/behaviors/listbox.js +135 -0
- package/registry/behaviors/menu.js +586 -0
- package/registry/behaviors/message-scroller.js +147 -0
- package/registry/behaviors/popover.js +127 -0
- package/registry/behaviors/questionnaire.js +91 -0
- package/registry/behaviors/resizable.js +463 -0
- package/registry/behaviors/select.js +196 -0
- package/registry/behaviors/tabs.js +95 -0
- package/registry/behaviors/toast.js +137 -0
- package/registry/components/carousel.css +1 -0
- package/registry/components/code-block.css +19 -0
- package/registry/components/hover-card.css +2 -2
- package/registry/components/resizable.css +49 -0
- package/registry/components/tooltip.css +4 -1
- package/registry/examples/alert-dialog.html +21 -21
- package/registry/examples/button-group.html +3 -3
- package/registry/examples/calendar.html +387 -326
- package/registry/examples/carousel.html +80 -2
- package/registry/examples/code-block.html +10 -4
- package/registry/examples/combobox.html +2 -0
- package/registry/examples/command.html +17 -17
- package/registry/examples/context-menu.html +18 -18
- package/registry/examples/dialog.html +15 -15
- package/registry/examples/drawer.html +22 -22
- package/registry/examples/questionnaire.html +2 -2
- package/registry/examples/resizable.html +88 -15
- package/registry/examples/select.html +7 -0
- package/registry/examples/sheet.html +23 -23
- package/registry/examples/sidebar.html +11 -11
- package/registry/examples/toast.html +11 -0
- package/registry/primitives/dialog-shell.css +5 -0
- package/registry/registry.json +280 -1
- package/registry/schema.json +17 -0
- package/registry/styles/luma/resizable.css +10 -0
- package/registry/styles/lyra/resizable.css +10 -0
- package/registry/styles/maia/resizable.css +10 -0
- package/registry/styles/mira/resizable.css +10 -0
- package/registry/styles/nova/resizable.css +10 -0
- package/registry/styles/rhea/resizable.css +10 -0
- package/registry/styles/sera/resizable.css +10 -0
- package/registry/styles/vega/resizable.css +10 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { labelOf, uniqueId } from "./core.js";
|
|
4
|
+
|
|
5
|
+
const OPTION_SELECTOR = "[role='option']";
|
|
6
|
+
|
|
7
|
+
/** @param {Element} panel */
|
|
8
|
+
export function listboxIn(panel) {
|
|
9
|
+
if (panel.matches("[role='listbox']")) return /** @type {HTMLElement} */ (panel);
|
|
10
|
+
const listbox = panel.querySelector("[role='listbox']");
|
|
11
|
+
return listbox instanceof HTMLElement ? listbox : null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** @param {Element} listbox */
|
|
15
|
+
export function optionsOf(listbox) {
|
|
16
|
+
return [...listbox.querySelectorAll(OPTION_SELECTOR)].filter(
|
|
17
|
+
(option) => option.closest("[role='listbox']") === listbox
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @param {Element} listbox */
|
|
22
|
+
export function visibleOptions(listbox) {
|
|
23
|
+
return optionsOf(listbox).filter(
|
|
24
|
+
(option) =>
|
|
25
|
+
!option.hasAttribute("hidden") && !option.hasAttribute("aria-disabled")
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @param {Element} listbox @param {string} query */
|
|
30
|
+
export function filterOptions(listbox, query) {
|
|
31
|
+
const normalized = query.trim().toLowerCase();
|
|
32
|
+
let visible = 0;
|
|
33
|
+
|
|
34
|
+
for (const option of optionsOf(listbox)) {
|
|
35
|
+
const match =
|
|
36
|
+
normalized === "" || labelOf(option).toLowerCase().includes(normalized);
|
|
37
|
+
option.toggleAttribute("hidden", !match);
|
|
38
|
+
if (match) visible += 1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const group of listbox.querySelectorAll("[role='group']")) {
|
|
42
|
+
if (group.closest("[role='listbox']") !== listbox) continue;
|
|
43
|
+
const options = [...group.querySelectorAll(OPTION_SELECTOR)].filter(
|
|
44
|
+
(option) => option.closest("[role='listbox']") === listbox
|
|
45
|
+
);
|
|
46
|
+
const hasVisible = options.some((option) => !option.hasAttribute("hidden"));
|
|
47
|
+
group.toggleAttribute("hidden", !hasVisible);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const separator of listbox.querySelectorAll("[role='separator']")) {
|
|
51
|
+
if (separator.closest("[role='listbox']") !== listbox) continue;
|
|
52
|
+
const previous = separator.previousElementSibling;
|
|
53
|
+
const next = separator.nextElementSibling;
|
|
54
|
+
const surrounded =
|
|
55
|
+
previous !== null &&
|
|
56
|
+
next !== null &&
|
|
57
|
+
!previous.hasAttribute("hidden") &&
|
|
58
|
+
!next.hasAttribute("hidden");
|
|
59
|
+
separator.toggleAttribute("hidden", !surrounded);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const empty = listbox.querySelector("[data-slot='empty']");
|
|
63
|
+
if (empty instanceof HTMLElement) empty.hidden = visible > 0;
|
|
64
|
+
|
|
65
|
+
return visible;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** @param {Element} listbox @param {Element | null} option @param {Element | null} control */
|
|
69
|
+
export function highlight(listbox, option, control) {
|
|
70
|
+
for (const candidate of optionsOf(listbox)) {
|
|
71
|
+
candidate.removeAttribute("data-highlighted");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!option) {
|
|
75
|
+
control?.removeAttribute("aria-activedescendant");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!option.id) option.id = uniqueId("loseta-option");
|
|
80
|
+
if (control) control.setAttribute("aria-activedescendant", option.id);
|
|
81
|
+
option.setAttribute("data-highlighted", "");
|
|
82
|
+
option.scrollIntoView({ block: "nearest" });
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @param {Element} listbox */
|
|
86
|
+
export function selectedOptions(listbox) {
|
|
87
|
+
return optionsOf(listbox).filter(
|
|
88
|
+
(option) => option.getAttribute("aria-selected") === "true"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** @param {Element} listbox */
|
|
93
|
+
export function selectedValues(listbox) {
|
|
94
|
+
return selectedOptions(listbox).map((option) => labelOf(option));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** @param {Element} listbox @param {Element} option @param {boolean} multiple */
|
|
98
|
+
export function selectOption(listbox, option, multiple) {
|
|
99
|
+
if (multiple) {
|
|
100
|
+
const selected = option.getAttribute("aria-selected") === "true";
|
|
101
|
+
option.setAttribute("aria-selected", String(!selected));
|
|
102
|
+
} else {
|
|
103
|
+
for (const candidate of optionsOf(listbox)) {
|
|
104
|
+
candidate.setAttribute("aria-selected", String(candidate === option));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return selectedValues(listbox);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @param {Element} listbox @param {number} direction */
|
|
111
|
+
export function moveHighlight(listbox, direction) {
|
|
112
|
+
const options = visibleOptions(listbox);
|
|
113
|
+
const current =
|
|
114
|
+
options.find((option) => option.hasAttribute("data-highlighted")) ?? null;
|
|
115
|
+
if (options.length === 0) return null;
|
|
116
|
+
const index = current ? options.indexOf(current) : -1;
|
|
117
|
+
const next = index + direction;
|
|
118
|
+
return options[(next + options.length) % options.length] ?? null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** @param {Element} listbox */
|
|
122
|
+
export function firstOption(listbox) {
|
|
123
|
+
return visibleOptions(listbox)[0] ?? null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** @param {Element} listbox */
|
|
127
|
+
export function lastOption(listbox) {
|
|
128
|
+
const options = visibleOptions(listbox);
|
|
129
|
+
return options[options.length - 1] ?? null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** @param {Element} listbox */
|
|
133
|
+
export function resetFilter(listbox) {
|
|
134
|
+
return filterOptions(listbox, "");
|
|
135
|
+
}
|