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,147 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { emit, init, on } from "./core.js";
|
|
4
|
+
|
|
5
|
+
const FOLLOW_THRESHOLD = 24;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {object} ScrollerState
|
|
9
|
+
* @property {boolean} following
|
|
10
|
+
* @property {MutationObserver} observer
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** @type {WeakMap<HTMLElement, ScrollerState>} */
|
|
14
|
+
const states = new WeakMap();
|
|
15
|
+
|
|
16
|
+
/** @param {HTMLElement} viewport */
|
|
17
|
+
function distance(viewport) {
|
|
18
|
+
return viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @param {HTMLElement} viewport */
|
|
22
|
+
function atBottom(viewport) {
|
|
23
|
+
return distance(viewport) <= FOLLOW_THRESHOLD;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** @param {HTMLElement} scroller */
|
|
27
|
+
function parts(scroller) {
|
|
28
|
+
const viewport = scroller.querySelector(".message-scroller-viewport");
|
|
29
|
+
const content = scroller.querySelector("[data-slot='content']");
|
|
30
|
+
const jump = scroller.querySelector("[data-slot='jump']");
|
|
31
|
+
return {
|
|
32
|
+
viewport: viewport instanceof HTMLElement ? viewport : null,
|
|
33
|
+
content: content instanceof HTMLElement ? content : null,
|
|
34
|
+
jump: jump instanceof HTMLElement ? jump : null
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {HTMLElement} scroller
|
|
40
|
+
* @param {ScrollerState} state
|
|
41
|
+
* @param {HTMLElement} viewport
|
|
42
|
+
*/
|
|
43
|
+
function update(scroller, state, viewport) {
|
|
44
|
+
const following = atBottom(viewport);
|
|
45
|
+
const { jump } = parts(scroller);
|
|
46
|
+
if (jump) jump.hidden = following;
|
|
47
|
+
if (following === state.following) return;
|
|
48
|
+
|
|
49
|
+
state.following = following;
|
|
50
|
+
emit(scroller, "change", { following });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @param {HTMLElement} scroller
|
|
55
|
+
* @param {ScrollerState} state
|
|
56
|
+
* @param {HTMLElement} viewport
|
|
57
|
+
*/
|
|
58
|
+
function handleMutation(scroller, state, viewport) {
|
|
59
|
+
// Appended messages do not move scrollTop, so the reading position is kept
|
|
60
|
+
// when the user is not following. Native scroll anchoring handles prepends.
|
|
61
|
+
if (state.following) {
|
|
62
|
+
requestAnimationFrame(() => {
|
|
63
|
+
if (scroller.isConnected && state.following) {
|
|
64
|
+
viewport.scrollTop = viewport.scrollHeight;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** @param {HTMLElement} scroller */
|
|
71
|
+
function ensure(scroller) {
|
|
72
|
+
const existing = states.get(scroller);
|
|
73
|
+
if (existing) return existing;
|
|
74
|
+
|
|
75
|
+
const { viewport, content, jump } = parts(scroller);
|
|
76
|
+
if (!viewport || !content) return null;
|
|
77
|
+
|
|
78
|
+
/** @type {ScrollerState} */
|
|
79
|
+
const state = {
|
|
80
|
+
following: atBottom(viewport),
|
|
81
|
+
observer: new MutationObserver(() => {
|
|
82
|
+
if (!scroller.isConnected) {
|
|
83
|
+
state.observer.disconnect();
|
|
84
|
+
states.delete(scroller);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
handleMutation(scroller, state, viewport);
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
state.observer.observe(content, { childList: true, subtree: true });
|
|
92
|
+
states.set(scroller, state);
|
|
93
|
+
if (jump) jump.hidden = state.following;
|
|
94
|
+
return state;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Mounts every message scroller under a root. The entry module calls this for
|
|
99
|
+
* the initial document; consumers can call it for a late-mounted subtree.
|
|
100
|
+
* @param {Document | Element} root
|
|
101
|
+
*/
|
|
102
|
+
export function mount(root = document) {
|
|
103
|
+
for (const scroller of root.querySelectorAll(".message-scroller")) {
|
|
104
|
+
if (scroller instanceof HTMLElement) ensure(scroller);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
on("scroll", ".message-scroller-viewport", (_event, element) => {
|
|
109
|
+
if (!(element instanceof HTMLElement)) return;
|
|
110
|
+
const scroller = element.closest(".message-scroller");
|
|
111
|
+
if (!(scroller instanceof HTMLElement)) return;
|
|
112
|
+
const state = ensure(scroller);
|
|
113
|
+
if (state) update(scroller, state, element);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
on("click", ".message-scroller [data-slot='jump']", (event, element) => {
|
|
117
|
+
if (!(element instanceof HTMLElement)) return;
|
|
118
|
+
const scroller = element.closest(".message-scroller");
|
|
119
|
+
if (!(scroller instanceof HTMLElement)) return;
|
|
120
|
+
const { viewport } = parts(scroller);
|
|
121
|
+
if (!viewport) return;
|
|
122
|
+
|
|
123
|
+
const state = ensure(scroller);
|
|
124
|
+
if (!state) return;
|
|
125
|
+
|
|
126
|
+
element.hidden = true;
|
|
127
|
+
viewport.scrollTo({ top: viewport.scrollHeight, behavior: "auto" });
|
|
128
|
+
if (!state.following) {
|
|
129
|
+
state.following = true;
|
|
130
|
+
emit(scroller, "change", { following: true });
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
return true;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (typeof document !== "undefined") {
|
|
138
|
+
if (document.readyState === "loading") {
|
|
139
|
+
document.addEventListener("DOMContentLoaded", () => mount(document), {
|
|
140
|
+
once: true
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
mount(document);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
init();
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
emit,
|
|
5
|
+
focusWhenVisible,
|
|
6
|
+
init,
|
|
7
|
+
on,
|
|
8
|
+
onDocument,
|
|
9
|
+
panelFor,
|
|
10
|
+
setOpen
|
|
11
|
+
} from "./core.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} OpenPopover
|
|
15
|
+
* @property {HTMLElement} trigger
|
|
16
|
+
* @property {HTMLElement} panel
|
|
17
|
+
* @property {Element} root
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** @type {OpenPopover[]} */
|
|
21
|
+
const openPopovers = [];
|
|
22
|
+
|
|
23
|
+
/** Tracks panels that start open in markup, such as a date picker. */
|
|
24
|
+
function syncOpenPopovers() {
|
|
25
|
+
if (typeof document === "undefined") return;
|
|
26
|
+
for (const panel of document.querySelectorAll("[data-popover][aria-hidden='false']")) {
|
|
27
|
+
if (!(panel instanceof HTMLElement)) continue;
|
|
28
|
+
if (openPopovers.some((entry) => entry.panel === panel)) continue;
|
|
29
|
+
const root = panel.closest(".popover");
|
|
30
|
+
if (!root) continue;
|
|
31
|
+
|
|
32
|
+
const trigger = [...root.querySelectorAll("[aria-haspopup='dialog'][aria-controls]")].find(
|
|
33
|
+
(candidate) =>
|
|
34
|
+
(candidate.getAttribute("aria-controls") ?? "")
|
|
35
|
+
.split(/\s+/)
|
|
36
|
+
.includes(panel.id)
|
|
37
|
+
);
|
|
38
|
+
if (trigger instanceof HTMLElement) {
|
|
39
|
+
openPopovers.push({ trigger, panel, root });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @param {OpenPopover} entry @param {boolean} focusTrigger */
|
|
45
|
+
function closePopover(entry, focusTrigger) {
|
|
46
|
+
const index = openPopovers.indexOf(entry);
|
|
47
|
+
if (index !== -1) openPopovers.splice(index, 1);
|
|
48
|
+
setOpen(entry.trigger, entry.panel, false);
|
|
49
|
+
emit(entry.root, "toggle", { open: false });
|
|
50
|
+
if (focusTrigger) entry.trigger.focus();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @param {HTMLElement} trigger @param {HTMLElement} panel @param {Element} root */
|
|
54
|
+
function openPopover(trigger, panel, root) {
|
|
55
|
+
for (const entry of [...openPopovers]) {
|
|
56
|
+
if (entry.panel.contains(panel)) continue;
|
|
57
|
+
closePopover(entry, false);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const entry = { trigger, panel, root };
|
|
61
|
+
openPopovers.push(entry);
|
|
62
|
+
setOpen(trigger, panel, true);
|
|
63
|
+
emit(root, "toggle", { open: true });
|
|
64
|
+
|
|
65
|
+
if (panel.getAttribute("role") === "dialog") {
|
|
66
|
+
focusWhenVisible(panel);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
on("click", ".popover [aria-haspopup='dialog'][aria-controls]", (event, target) => {
|
|
71
|
+
const trigger = /** @type {HTMLElement} */ (target);
|
|
72
|
+
const panel = panelFor(trigger);
|
|
73
|
+
const root = trigger.closest(".popover");
|
|
74
|
+
if (!(panel instanceof HTMLElement) || !panel.matches("[data-popover]") || !root) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const existing = openPopovers.find((entry) => entry.trigger === trigger);
|
|
79
|
+
const visible = panel.getAttribute("aria-hidden") === "false";
|
|
80
|
+
if (existing) {
|
|
81
|
+
closePopover(existing, true);
|
|
82
|
+
} else if (visible) {
|
|
83
|
+
// Markup may start open, e.g. a date picker panel.
|
|
84
|
+
closePopover({ trigger, panel, root }, true);
|
|
85
|
+
} else {
|
|
86
|
+
openPopover(trigger, panel, root);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
return true;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
onDocument("pointerdown", (event) => {
|
|
94
|
+
if (!(event.target instanceof Node)) return;
|
|
95
|
+
syncOpenPopovers();
|
|
96
|
+
for (const entry of [...openPopovers]) {
|
|
97
|
+
if (entry.root.contains(event.target) || entry.panel.contains(event.target)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
closePopover(entry, false);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
onDocument(
|
|
105
|
+
"keydown",
|
|
106
|
+
(event) => {
|
|
107
|
+
if (!(event instanceof KeyboardEvent) || event.key !== "Escape") return;
|
|
108
|
+
syncOpenPopovers();
|
|
109
|
+
const entry = openPopovers[openPopovers.length - 1];
|
|
110
|
+
if (!entry) return;
|
|
111
|
+
closePopover(entry, true);
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
20
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
on("focusout", ".popover", (event, root) => {
|
|
119
|
+
if (!(event instanceof FocusEvent)) return;
|
|
120
|
+
const next = event.relatedTarget;
|
|
121
|
+
if (next === null) return;
|
|
122
|
+
if (next instanceof Node && root.contains(next)) return;
|
|
123
|
+
const entry = openPopovers.find((candidate) => candidate.root === root);
|
|
124
|
+
if (entry) closePopover(entry, false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
init();
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { emit, focusWhenVisible, init, on } from "./core.js";
|
|
4
|
+
|
|
5
|
+
/** @param {HTMLElement} root */
|
|
6
|
+
function readSteps(root) {
|
|
7
|
+
const steps = [...root.querySelectorAll("[data-slot='item']")].filter(
|
|
8
|
+
(step) => step instanceof HTMLElement
|
|
9
|
+
);
|
|
10
|
+
let index = steps.findIndex(
|
|
11
|
+
(step) => step.getAttribute("aria-current") === "step"
|
|
12
|
+
);
|
|
13
|
+
if (index === -1) {
|
|
14
|
+
index = steps.findIndex((step) => !step.hasAttribute("hidden"));
|
|
15
|
+
}
|
|
16
|
+
return { steps, index: index >= 0 ? index : 0 };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {HTMLElement} root
|
|
21
|
+
* @param {HTMLElement[]} steps
|
|
22
|
+
* @param {number} index
|
|
23
|
+
*/
|
|
24
|
+
function go(root, steps, index) {
|
|
25
|
+
if (steps.length === 0) return;
|
|
26
|
+
const next = Math.max(0, Math.min(index, steps.length - 1));
|
|
27
|
+
|
|
28
|
+
steps.forEach((step, cursor) => {
|
|
29
|
+
step.hidden = cursor !== next;
|
|
30
|
+
if (cursor === next) {
|
|
31
|
+
step.setAttribute("aria-current", "step");
|
|
32
|
+
} else {
|
|
33
|
+
step.removeAttribute("aria-current");
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const progress = root.querySelector("progress");
|
|
38
|
+
if (progress instanceof HTMLProgressElement) {
|
|
39
|
+
progress.max = steps.length;
|
|
40
|
+
progress.value = next + 1;
|
|
41
|
+
progress.textContent = `${next + 1} of ${steps.length}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const label = root.querySelector("[data-slot='progress-label']");
|
|
45
|
+
if (label) {
|
|
46
|
+
label.textContent = `Question ${next + 1} of ${steps.length}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const previous = root.querySelector("[data-slot='previous']");
|
|
50
|
+
if (previous instanceof HTMLButtonElement) {
|
|
51
|
+
previous.disabled = next === 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const forward = root.querySelector("[data-slot='next']");
|
|
55
|
+
if (forward instanceof HTMLButtonElement) {
|
|
56
|
+
forward.disabled = next === steps.length - 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const control = steps[next]?.querySelector(
|
|
60
|
+
"input, button, select, textarea"
|
|
61
|
+
);
|
|
62
|
+
if (control instanceof HTMLElement && !control.matches(":disabled")) {
|
|
63
|
+
focusWhenVisible(control);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
emit(root, "change", { step: next + 1, total: steps.length });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
on(
|
|
70
|
+
"click",
|
|
71
|
+
".questionnaire [data-slot='previous'], .questionnaire [data-slot='next']",
|
|
72
|
+
(event, element) => {
|
|
73
|
+
if (!(element instanceof HTMLElement)) return;
|
|
74
|
+
const root = element.closest(".questionnaire");
|
|
75
|
+
if (!(root instanceof HTMLElement)) return;
|
|
76
|
+
|
|
77
|
+
const { steps, index } = readSteps(root);
|
|
78
|
+
const direction = element.getAttribute("data-slot") === "next" ? 1 : -1;
|
|
79
|
+
const next = index + direction;
|
|
80
|
+
if (next < 0 || next >= steps.length) {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
go(root, steps, next);
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
init();
|