@luxalgo/vela-ui 0.0.0-stage → 0.2.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/CHANGELOG.md +91 -0
- package/LICENSE +201 -0
- package/NOTICE +28 -0
- package/README.md +86 -3
- package/cli/engine.mjs +282 -0
- package/cli/index.mjs +154 -0
- package/dist/badge.d.ts +26 -0
- package/dist/badge.js +44 -0
- package/dist/bar-chart.d.ts +40 -0
- package/dist/bar-chart.js +105 -0
- package/dist/button.d.ts +55 -0
- package/dist/button.js +11 -0
- package/dist/calendar.d.ts +24 -0
- package/dist/calendar.js +1 -0
- package/dist/callout-bubble.d.ts +103 -0
- package/dist/callout-bubble.js +177 -0
- package/dist/chart.d.ts +30 -0
- package/dist/chart.js +1 -0
- package/dist/checkbox.d.ts +60 -0
- package/dist/checkbox.js +12 -0
- package/dist/chunk-2GQIZM5Z.js +28 -0
- package/dist/chunk-3Q32K4PE.js +85 -0
- package/dist/chunk-6QCILIT2.js +52 -0
- package/dist/chunk-7VMN7NKJ.js +133 -0
- package/dist/chunk-A2FJ7Y7D.js +55 -0
- package/dist/chunk-A72NWYNP.js +26 -0
- package/dist/chunk-B5ZSRUDQ.js +227 -0
- package/dist/chunk-BXMWQIBO.js +66 -0
- package/dist/chunk-C3ICYMI3.js +25 -0
- package/dist/chunk-CC3DDNFC.js +117 -0
- package/dist/chunk-E2FE6V2N.js +81 -0
- package/dist/chunk-FN2BUFNM.js +10 -0
- package/dist/chunk-FVH6L7FM.js +18 -0
- package/dist/chunk-G7IQLY3A.js +183 -0
- package/dist/chunk-GVRX3UAV.js +82 -0
- package/dist/chunk-J2QJATCD.js +12 -0
- package/dist/chunk-LZWZV2ZS.js +18 -0
- package/dist/chunk-MJ4RUGX7.js +403 -0
- package/dist/chunk-MMTMOV6R.js +31 -0
- package/dist/chunk-P4MTEMT7.js +23 -0
- package/dist/chunk-Q6WTDVH6.js +31 -0
- package/dist/chunk-S7USVSYP.js +50 -0
- package/dist/chunk-TAKSIV57.js +90 -0
- package/dist/chunk-U3EH42YY.js +72 -0
- package/dist/chunk-V2Q4MRMS.js +573 -0
- package/dist/chunk-VMCR3S2A.js +22 -0
- package/dist/chunk-WBGSYCV2.js +101 -0
- package/dist/chunk-WGULXRWD.js +351 -0
- package/dist/chunk-WXH3EFV5.js +219 -0
- package/dist/chunk-X66RJAIS.js +14 -0
- package/dist/chunk-XBEL4K33.js +142 -0
- package/dist/chunk-Z5PINFQO.js +280 -0
- package/dist/collapsible.d.ts +49 -0
- package/dist/collapsible.js +106 -0
- package/dist/color-picker.d.ts +103 -0
- package/dist/color-picker.js +19 -0
- package/dist/color.d.ts +24 -0
- package/dist/color.js +1 -0
- package/dist/context-menu.d.ts +72 -0
- package/dist/context-menu.js +161 -0
- package/dist/css.d.ts +17 -0
- package/dist/css.js +4 -0
- package/dist/data-table.d.ts +40 -0
- package/dist/data-table.js +88 -0
- package/dist/date-picker.d.ts +90 -0
- package/dist/date-picker.js +257 -0
- package/dist/define-D5u3F5Dj.d.ts +21 -0
- package/dist/dialog.d.ts +89 -0
- package/dist/dialog.js +258 -0
- package/dist/dispose.d.ts +9 -0
- package/dist/dispose.js +2 -0
- package/dist/donut.d.ts +27 -0
- package/dist/donut.js +67 -0
- package/dist/drawer.d.ts +119 -0
- package/dist/drawer.js +326 -0
- package/dist/dropdown-menu.d.ts +114 -0
- package/dist/dropdown-menu.js +18 -0
- package/dist/empty.d.ts +21 -0
- package/dist/empty.js +38 -0
- package/dist/field.d.ts +147 -0
- package/dist/field.js +328 -0
- package/dist/glyph-select.d.ts +57 -0
- package/dist/glyph-select.js +17 -0
- package/dist/h-Bl37qUis.d.ts +24 -0
- package/dist/headless.d.ts +6 -0
- package/dist/headless.js +9 -0
- package/dist/hover-card.d.ts +43 -0
- package/dist/hover-card.js +97 -0
- package/dist/i18n.d.ts +20 -0
- package/dist/i18n.js +1 -0
- package/dist/icons.d.ts +20 -0
- package/dist/icons.js +2 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +13 -0
- package/dist/input-group.d.ts +57 -0
- package/dist/input-group.js +87 -0
- package/dist/input.d.ts +54 -0
- package/dist/input.js +9 -0
- package/dist/item.d.ts +72 -0
- package/dist/item.js +131 -0
- package/dist/kbd.d.ts +19 -0
- package/dist/kbd.js +8 -0
- package/dist/kit-text.d.ts +8 -0
- package/dist/kit-text.js +2 -0
- package/dist/line-chart.d.ts +32 -0
- package/dist/line-chart.js +120 -0
- package/dist/manifest.json +4508 -0
- package/dist/month-grid.d.ts +45 -0
- package/dist/month-grid.js +157 -0
- package/dist/number-input.d.ts +99 -0
- package/dist/number-input.js +14 -0
- package/dist/page.d.ts +7 -0
- package/dist/page.js +1 -0
- package/dist/palette.d.ts +55 -0
- package/dist/palette.js +1 -0
- package/dist/placement.d.ts +98 -0
- package/dist/placement.js +1 -0
- package/dist/popover.d.ts +107 -0
- package/dist/popover.js +15 -0
- package/dist/scatter-chart.d.ts +32 -0
- package/dist/scatter-chart.js +121 -0
- package/dist/select.d.ts +112 -0
- package/dist/select.js +19 -0
- package/dist/slider.d.ts +46 -0
- package/dist/slider.js +111 -0
- package/dist/sort-button.d.ts +41 -0
- package/dist/sort-button.js +88 -0
- package/dist/sparkline.d.ts +22 -0
- package/dist/sparkline.js +72 -0
- package/dist/stat.d.ts +29 -0
- package/dist/stat.js +41 -0
- package/dist/styles.d.ts +22 -0
- package/dist/styles.js +2 -0
- package/dist/surface-events.d.ts +17 -0
- package/dist/surface-events.js +1 -0
- package/dist/surface-exit.d.ts +25 -0
- package/dist/surface-exit.js +1 -0
- package/dist/switch.d.ts +54 -0
- package/dist/switch.js +92 -0
- package/dist/t.d.ts +89 -0
- package/dist/t.js +1 -0
- package/dist/tabs.d.ts +65 -0
- package/dist/tabs.js +155 -0
- package/dist/text-area.d.ts +54 -0
- package/dist/text-area.js +9 -0
- package/dist/theme.d.ts +199 -0
- package/dist/theme.js +8 -0
- package/dist/theme.schema.json +1994 -0
- package/dist/themes/dark.css +3 -0
- package/dist/themes/light.css +3 -0
- package/dist/toggle-group.d.ts +56 -0
- package/dist/toggle-group.js +130 -0
- package/dist/tokens.d.ts +16 -0
- package/dist/tokens.js +3 -0
- package/dist/tooltip.d.ts +47 -0
- package/dist/tooltip.js +74 -0
- package/dist/variants-B4stUBnY.d.ts +16 -0
- package/dist/zag.d.ts +19 -0
- package/dist/zag.js +2 -0
- package/docs/theming.md +217 -0
- package/docs/what-to-change.md +20 -0
- package/docs/writing-a-component.md +250 -0
- package/llms.txt +71 -0
- package/package.json +90 -6
- package/registry/badge.ts +119 -0
- package/registry/bar-chart.ts +215 -0
- package/registry/button.ts +379 -0
- package/registry/callout-bubble.ts +347 -0
- package/registry/checkbox.ts +234 -0
- package/registry/collapsible.ts +271 -0
- package/registry/color-picker.ts +582 -0
- package/registry/context-menu.ts +208 -0
- package/registry/data-table.ts +215 -0
- package/registry/date-picker.ts +483 -0
- package/registry/dialog.ts +535 -0
- package/registry/donut.ts +145 -0
- package/registry/drawer.ts +636 -0
- package/registry/dropdown-menu.ts +762 -0
- package/registry/empty.ts +91 -0
- package/registry/field.ts +585 -0
- package/registry/glyph-select.ts +268 -0
- package/registry/hover-card.ts +222 -0
- package/registry/input-group.ts +229 -0
- package/registry/input.ts +181 -0
- package/registry/item.ts +376 -0
- package/registry/kbd.ts +64 -0
- package/registry/line-chart.ts +218 -0
- package/registry/month-grid.ts +328 -0
- package/registry/number-input.ts +443 -0
- package/registry/popover.ts +368 -0
- package/registry/scatter-chart.ts +221 -0
- package/registry/select.ts +620 -0
- package/registry/slider.ts +259 -0
- package/registry/sort-button.ts +189 -0
- package/registry/sparkline.ts +114 -0
- package/registry/stat.ts +96 -0
- package/registry/switch.ts +205 -0
- package/registry/tabs.ts +426 -0
- package/registry/text-area.ts +186 -0
- package/registry/toggle-group.ts +295 -0
- package/registry/tooltip.ts +156 -0
- package/skills/theming-vela-ui/SKILL.md +137 -0
- package/skills/using-vela-ui-components/SKILL.md +137 -0
- package/skills/writing-vela-ui-components/SKILL.md +163 -0
- package/src/components/badge.ts +119 -0
- package/src/components/bar-chart.ts +215 -0
- package/src/components/button.ts +379 -0
- package/src/components/callout-bubble.ts +347 -0
- package/src/components/checkbox.ts +234 -0
- package/src/components/collapsible.ts +271 -0
- package/src/components/color-picker.ts +582 -0
- package/src/components/context-menu.ts +208 -0
- package/src/components/data-table.ts +215 -0
- package/src/components/date-picker.ts +483 -0
- package/src/components/dialog.ts +535 -0
- package/src/components/donut.ts +145 -0
- package/src/components/drawer.ts +636 -0
- package/src/components/dropdown-menu.ts +762 -0
- package/src/components/empty.ts +91 -0
- package/src/components/field.ts +585 -0
- package/src/components/glyph-select.ts +268 -0
- package/src/components/hover-card.ts +222 -0
- package/src/components/input-group.ts +229 -0
- package/src/components/input.ts +181 -0
- package/src/components/item.ts +376 -0
- package/src/components/kbd.ts +64 -0
- package/src/components/line-chart.ts +218 -0
- package/src/components/month-grid.ts +328 -0
- package/src/components/number-input.ts +443 -0
- package/src/components/popover.ts +368 -0
- package/src/components/scatter-chart.ts +221 -0
- package/src/components/select.ts +620 -0
- package/src/components/slider.ts +259 -0
- package/src/components/sort-button.ts +189 -0
- package/src/components/sparkline.ts +114 -0
- package/src/components/stat.ts +96 -0
- package/src/components/switch.ts +205 -0
- package/src/components/tabs.ts +426 -0
- package/src/components/text-area.ts +186 -0
- package/src/components/toggle-group.ts +295 -0
- package/src/components/tooltip.ts +156 -0
- package/src/index.ts +24 -0
- package/src/lib/calendar.ts +117 -0
- package/src/lib/chart.ts +72 -0
- package/src/lib/color.ts +89 -0
- package/src/lib/component-index.ts +151 -0
- package/src/lib/css.ts +48 -0
- package/src/lib/define.ts +45 -0
- package/src/lib/dispose.ts +36 -0
- package/src/lib/h.ts +55 -0
- package/src/lib/headless.ts +16 -0
- package/src/lib/i18n.ts +30 -0
- package/src/lib/icons.ts +237 -0
- package/src/lib/kit-text.ts +26 -0
- package/src/lib/page.ts +24 -0
- package/src/lib/palette.ts +81 -0
- package/src/lib/placement.ts +188 -0
- package/src/lib/scope.ts +135 -0
- package/src/lib/styles.ts +53 -0
- package/src/lib/surface-events.ts +31 -0
- package/src/lib/surface-exit.ts +87 -0
- package/src/lib/t.ts +68 -0
- package/src/lib/theme.ts +664 -0
- package/src/lib/tokens.ts +111 -0
- package/src/lib/variants.ts +32 -0
- package/src/lib/zag.ts +46 -0
- package/stylelint/index.mjs +60 -0
- package/stylelint/lint.mjs +81 -0
- package/stylelint/plugin.mjs +115 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { calendarSettings, monthNames, yearLabel, weekdayNames, yearBeforeMonth, plainInteger } from './chunk-GVRX3UAV.js';
|
|
2
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
3
|
+
import { msg, textOf } from './chunk-FN2BUFNM.js';
|
|
4
|
+
import { h } from './chunk-Q6WTDVH6.js';
|
|
5
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
6
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
7
|
+
import './chunk-2GQIZM5Z.js';
|
|
8
|
+
import './chunk-BXMWQIBO.js';
|
|
9
|
+
import './chunk-X66RJAIS.js';
|
|
10
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
11
|
+
|
|
12
|
+
// src/components/date-picker.ts
|
|
13
|
+
var NAV = {
|
|
14
|
+
prevMonth: msg("ui.datePicker.previousMonth", "Previous month"),
|
|
15
|
+
nextMonth: msg("ui.datePicker.nextMonth", "Next month"),
|
|
16
|
+
prevYear: msg("ui.datePicker.previousYear", "Previous year"),
|
|
17
|
+
nextYear: msg("ui.datePicker.nextYear", "Next year"),
|
|
18
|
+
prevDecade: msg("ui.datePicker.previousDecade", "Previous decade"),
|
|
19
|
+
nextDecade: msg("ui.datePicker.nextDecade", "Next decade")
|
|
20
|
+
};
|
|
21
|
+
function isoDate(d) {
|
|
22
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
23
|
+
}
|
|
24
|
+
function normalizeDateInput(raw) {
|
|
25
|
+
const m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(raw.trim());
|
|
26
|
+
if (!m) return null;
|
|
27
|
+
const y = Number(m[1]);
|
|
28
|
+
const mo = Number(m[2]);
|
|
29
|
+
const d = Number(m[3]);
|
|
30
|
+
const dt = new Date(y, mo - 1, d);
|
|
31
|
+
if (dt.getFullYear() !== y || dt.getMonth() !== mo - 1 || dt.getDate() !== d) return null;
|
|
32
|
+
return isoDate(dt);
|
|
33
|
+
}
|
|
34
|
+
function parseIsoDate(raw) {
|
|
35
|
+
const iso = raw ? normalizeDateInput(raw) : null;
|
|
36
|
+
if (!iso) return null;
|
|
37
|
+
const [y, mo, d] = iso.split("-").map(Number);
|
|
38
|
+
return new Date(y, mo - 1, d);
|
|
39
|
+
}
|
|
40
|
+
function datePickerController(opts = {}) {
|
|
41
|
+
const today = opts.today ?? /* @__PURE__ */ new Date();
|
|
42
|
+
let selected = parseIsoDate(opts.value);
|
|
43
|
+
let year = selected?.getFullYear() ?? today.getFullYear();
|
|
44
|
+
let month = selected?.getMonth() ?? today.getMonth();
|
|
45
|
+
let panel = "date";
|
|
46
|
+
const i18n = opts.i18n ?? null;
|
|
47
|
+
const settings = calendarSettings(i18n);
|
|
48
|
+
const weekStart = opts.i18n?.weekStart ?? 0;
|
|
49
|
+
const monthsLong = monthNames(settings, "long");
|
|
50
|
+
const monthsShort = monthNames(settings, "short");
|
|
51
|
+
const num = (n) => plainInteger(settings, n);
|
|
52
|
+
const decade = () => Math.floor(year / 10) * 10;
|
|
53
|
+
return {
|
|
54
|
+
get panel() {
|
|
55
|
+
return panel;
|
|
56
|
+
},
|
|
57
|
+
get year() {
|
|
58
|
+
return year;
|
|
59
|
+
},
|
|
60
|
+
get month() {
|
|
61
|
+
return month;
|
|
62
|
+
},
|
|
63
|
+
get value() {
|
|
64
|
+
return selected ? isoDate(selected) : null;
|
|
65
|
+
},
|
|
66
|
+
yearFirst: yearBeforeMonth(settings),
|
|
67
|
+
weekdays() {
|
|
68
|
+
const names = weekdayNames(settings);
|
|
69
|
+
return Array.from({ length: 7 }, (_, i) => names[(weekStart + i) % 7]);
|
|
70
|
+
},
|
|
71
|
+
header() {
|
|
72
|
+
return {
|
|
73
|
+
month: monthsLong[month] ?? "",
|
|
74
|
+
monthVisible: panel === "date",
|
|
75
|
+
year: panel === "year" ? `${num(decade())}-${num(decade() + 9)}` : yearLabel(settings, year),
|
|
76
|
+
yearDisabled: panel === "year"
|
|
77
|
+
// in the decade panel the year reads as its title
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
navLabels() {
|
|
81
|
+
if (panel === "date") return { prev: textOf(i18n, NAV.prevMonth), next: textOf(i18n, NAV.nextMonth) };
|
|
82
|
+
if (panel === "month") return { prev: textOf(i18n, NAV.prevYear), next: textOf(i18n, NAV.nextYear) };
|
|
83
|
+
return { prev: textOf(i18n, NAV.prevDecade), next: textOf(i18n, NAV.nextDecade) };
|
|
84
|
+
},
|
|
85
|
+
cells() {
|
|
86
|
+
const out = [];
|
|
87
|
+
if (panel === "date") {
|
|
88
|
+
const startPad = (new Date(year, month, 1).getDay() - weekStart + 7) % 7;
|
|
89
|
+
const days = new Date(year, month + 1, 0).getDate();
|
|
90
|
+
const todayIso = isoDate(today);
|
|
91
|
+
const selectedIso = selected ? isoDate(selected) : "";
|
|
92
|
+
for (let i = 0; i < startPad; i++) out.push({ label: "", value: "", checked: false, today: false, blank: true });
|
|
93
|
+
for (let day = 1; day <= days; day++) {
|
|
94
|
+
const iso = `${year}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
|
|
95
|
+
out.push({ label: num(day), value: iso, checked: iso === selectedIso, today: iso === todayIso });
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
if (panel === "month") {
|
|
100
|
+
for (let m = 0; m < 12; m++) {
|
|
101
|
+
out.push({
|
|
102
|
+
label: monthsShort[m] ?? "",
|
|
103
|
+
value: m,
|
|
104
|
+
checked: selected?.getFullYear() === year && selected.getMonth() === m,
|
|
105
|
+
today: today.getFullYear() === year && today.getMonth() === m
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
const d = decade();
|
|
111
|
+
for (let y = d - 1; y <= d + 10; y++) {
|
|
112
|
+
out.push({ label: num(y), value: y, checked: selected?.getFullYear() === y, today: today.getFullYear() === y, outside: y < d || y > d + 9 });
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
},
|
|
116
|
+
step(dir) {
|
|
117
|
+
if (panel === "date") {
|
|
118
|
+
month += dir;
|
|
119
|
+
if (month < 0) {
|
|
120
|
+
month = 11;
|
|
121
|
+
year -= 1;
|
|
122
|
+
}
|
|
123
|
+
if (month > 11) {
|
|
124
|
+
month = 0;
|
|
125
|
+
year += 1;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
year += panel === "month" ? dir : dir * 10;
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
showMonths() {
|
|
132
|
+
panel = "month";
|
|
133
|
+
},
|
|
134
|
+
showYears() {
|
|
135
|
+
panel = "year";
|
|
136
|
+
},
|
|
137
|
+
choose(cell) {
|
|
138
|
+
if (cell.blank) return null;
|
|
139
|
+
if (panel === "date") {
|
|
140
|
+
selected = parseIsoDate(String(cell.value));
|
|
141
|
+
return selected ? isoDate(selected) : null;
|
|
142
|
+
}
|
|
143
|
+
if (panel === "month") {
|
|
144
|
+
month = Number(cell.value);
|
|
145
|
+
panel = "date";
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
year = Number(cell.value);
|
|
149
|
+
panel = "month";
|
|
150
|
+
return null;
|
|
151
|
+
},
|
|
152
|
+
setValue(value) {
|
|
153
|
+
selected = parseIsoDate(value);
|
|
154
|
+
if (selected) {
|
|
155
|
+
year = selected.getFullYear();
|
|
156
|
+
month = selected.getMonth();
|
|
157
|
+
}
|
|
158
|
+
panel = "date";
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
var datePickerDef = defineComponent({
|
|
163
|
+
name: "date-picker",
|
|
164
|
+
parts: ["root", "head", "title", "switch", "nav", "week", "grid", "cells", "blank", "day", "cell"],
|
|
165
|
+
settings: { radius: t.radius.sm, "today-ring": `inset 0 0 0 1px ${t.border.strong}` }
|
|
166
|
+
});
|
|
167
|
+
var CHOOSE_MONTH = msg("ui.datePicker.chooseMonth", "Choose month");
|
|
168
|
+
var CHOOSE_YEAR = msg("ui.datePicker.chooseYear", "Choose year");
|
|
169
|
+
var injectStyles = defineStyles(
|
|
170
|
+
"vela-date-picker-styles",
|
|
171
|
+
css`@layer vela.ui{[data-slot=date-picker]{color:${t.fg};font:14px ${t.font};-webkit-user-select:none;user-select:none}[data-slot=date-picker-head]{justify-content:space-between;align-items:center;gap:8px;margin-bottom:8px;display:flex}[data-slot=date-picker-title]{flex:1;justify-content:center;align-items:center;gap:2px;min-width:0;display:flex}[data-slot=date-picker-switch]{color:${t.fg.bright};font:inherit;border-radius:${datePickerDef.vars.radius};cursor:pointer;background:0 0;border:none;padding:2px 6px;font-size:14px;font-weight:600}[data-slot=date-picker-switch]:disabled{cursor:default}[data-slot=date-picker-switch]:not(:disabled):hover{background:${t.hover}}[data-slot=date-picker-nav]{width:24px;height:24px;color:${t.fg.muted};border-radius:${datePickerDef.vars.radius};cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:0;font-size:14px;display:inline-flex}[data-slot=date-picker-nav]:hover{background:${t.hover};color:${t.fg.bright}}[data-slot=date-picker-week],[data-slot=date-picker-grid]{grid-template-columns:repeat(7,28px);gap:2px}[data-slot=date-picker-week]:where(:not([hidden])),[data-slot=date-picker-grid]{display:grid}[data-slot=date-picker-week]{color:${t.fg.muted};text-align:center;margin-bottom:4px;font-size:11px}[data-slot=date-picker-week]>span{line-height:20px}[data-slot=date-picker-blank]{width:28px;height:28px}[data-slot=date-picker-day]{width:28px;height:28px;color:inherit;border-radius:${datePickerDef.vars.radius};cursor:pointer;font:inherit;background:0 0;border:none;padding:0;font-size:14px}[data-slot=date-picker-day]:hover{background:${t.hover}}[data-slot=date-picker-day][data-checked]{background:${t.hover.strong};color:${t.fg.bright}}[data-slot=date-picker-day][data-today]:not([data-checked]){box-shadow:${datePickerDef.vars["today-ring"]}}[data-slot=date-picker-cells]{grid-template-columns:repeat(3,1fr);gap:4px;width:208px;display:grid}[data-slot=date-picker-cell]{height:36px;color:inherit;border-radius:${datePickerDef.vars.radius};cursor:pointer;font:inherit;background:0 0;border:none;padding:0 4px;font-size:14px}[data-slot=date-picker-cell]:hover{background:${t.hover}}[data-slot=date-picker-cell][data-checked]{background:${t.hover.strong};color:${t.fg.bright}}[data-slot=date-picker-cell][data-today]:not([data-checked]){box-shadow:${datePickerDef.vars["today-ring"]}}[data-slot=date-picker-cell][data-outside]{opacity:.45}}`
|
|
172
|
+
);
|
|
173
|
+
var DatePicker = class {
|
|
174
|
+
constructor(opts = {}) {
|
|
175
|
+
this.opts = opts;
|
|
176
|
+
const doc = document;
|
|
177
|
+
injectStyles(doc);
|
|
178
|
+
this.ctrl = datePickerController(opts);
|
|
179
|
+
const button = (className, part) => h("button", { className, slot: part, attrs: { type: "button" } });
|
|
180
|
+
this.prev = button("vela-date-picker-nav", datePickerDef.slot("nav"));
|
|
181
|
+
this.prev.append(iconEl("chevron-left", doc));
|
|
182
|
+
this.next = button("vela-date-picker-nav", datePickerDef.slot("nav"));
|
|
183
|
+
this.next.append(iconEl("chevron-right", doc));
|
|
184
|
+
const i18n = opts.i18n ?? null;
|
|
185
|
+
this.monthBtn = button("vela-date-picker-switch", datePickerDef.slot("switch"));
|
|
186
|
+
this.monthBtn.setAttribute("aria-label", textOf(i18n, CHOOSE_MONTH));
|
|
187
|
+
this.yearBtn = button("vela-date-picker-switch", datePickerDef.slot("switch"));
|
|
188
|
+
this.yearBtn.setAttribute("aria-label", textOf(i18n, CHOOSE_YEAR));
|
|
189
|
+
const title = h("div", { className: "vela-date-picker-title", slot: datePickerDef.slot("title") }, this.ctrl.yearFirst ? [this.yearBtn, this.monthBtn] : [this.monthBtn, this.yearBtn]);
|
|
190
|
+
const head = h("div", { className: "vela-date-picker-head", slot: datePickerDef.slot("head") }, this.prev, title, this.next);
|
|
191
|
+
this.week = h(
|
|
192
|
+
"div",
|
|
193
|
+
{ className: "vela-date-picker-week", slot: datePickerDef.slot("week") },
|
|
194
|
+
this.ctrl.weekdays().map((d) => h("span", { text: d }))
|
|
195
|
+
);
|
|
196
|
+
this.grid = h("div");
|
|
197
|
+
const on = (el, run) => el.addEventListener("click", (e) => {
|
|
198
|
+
e.stopPropagation();
|
|
199
|
+
run();
|
|
200
|
+
this.paint();
|
|
201
|
+
});
|
|
202
|
+
on(this.prev, () => this.ctrl.step(-1));
|
|
203
|
+
on(this.next, () => this.ctrl.step(1));
|
|
204
|
+
on(this.monthBtn, () => this.ctrl.showMonths());
|
|
205
|
+
on(this.yearBtn, () => this.ctrl.showYears());
|
|
206
|
+
this.el = h("div", { className: "vela-date-picker", slot: datePickerDef.slot("root") }, head, this.week, this.grid);
|
|
207
|
+
this.paint();
|
|
208
|
+
}
|
|
209
|
+
get value() {
|
|
210
|
+
return this.ctrl.value;
|
|
211
|
+
}
|
|
212
|
+
/** Rewrite the selection without emitting (the calendar opens on its month). */
|
|
213
|
+
setValue(value) {
|
|
214
|
+
this.ctrl.setValue(value);
|
|
215
|
+
this.paint();
|
|
216
|
+
}
|
|
217
|
+
destroy() {
|
|
218
|
+
}
|
|
219
|
+
paint() {
|
|
220
|
+
const doc = this.el.ownerDocument;
|
|
221
|
+
const head = this.ctrl.header();
|
|
222
|
+
this.monthBtn.hidden = !head.monthVisible;
|
|
223
|
+
this.monthBtn.textContent = head.month;
|
|
224
|
+
this.yearBtn.textContent = head.year;
|
|
225
|
+
this.yearBtn.disabled = head.yearDisabled;
|
|
226
|
+
const nav = this.ctrl.navLabels();
|
|
227
|
+
this.prev.setAttribute("aria-label", nav.prev);
|
|
228
|
+
this.next.setAttribute("aria-label", nav.next);
|
|
229
|
+
const dates = this.ctrl.panel === "date";
|
|
230
|
+
this.week.hidden = !dates;
|
|
231
|
+
this.grid.className = dates ? "vela-date-picker-grid" : "vela-date-picker-cells";
|
|
232
|
+
this.grid.setAttribute("data-slot", datePickerDef.slot(dates ? "grid" : "cells"));
|
|
233
|
+
this.grid.replaceChildren(...this.ctrl.cells().map((cell) => this.cellEl(doc, cell, dates)));
|
|
234
|
+
}
|
|
235
|
+
cellEl(doc, cell, dates) {
|
|
236
|
+
if (cell.blank) return h("span", { className: "vela-date-picker-blank", slot: datePickerDef.slot("blank") });
|
|
237
|
+
const b = h("button", {
|
|
238
|
+
className: dates ? "vela-date-picker-day" : "vela-date-picker-cell",
|
|
239
|
+
slot: datePickerDef.slot(dates ? "day" : "cell"),
|
|
240
|
+
attrs: { type: "button" },
|
|
241
|
+
data: { checked: cell.checked ? "1" : null, today: cell.today ? "1" : null, outside: cell.outside ? "1" : null },
|
|
242
|
+
text: cell.label
|
|
243
|
+
});
|
|
244
|
+
b.addEventListener("click", (e) => {
|
|
245
|
+
e.stopPropagation();
|
|
246
|
+
const picked = this.ctrl.choose(cell);
|
|
247
|
+
if (picked) this.opts.onPick?.(picked);
|
|
248
|
+
else this.paint();
|
|
249
|
+
});
|
|
250
|
+
return b;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
function createDatePicker(props = {}) {
|
|
254
|
+
return new DatePicker(props);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export { DatePicker, createDatePicker, datePickerController, datePickerDef, isoDate, normalizeDateInput };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Token } from './t.js';
|
|
2
|
+
|
|
3
|
+
interface ComponentDef<N extends string, P extends string, S extends string> {
|
|
4
|
+
readonly name: N;
|
|
5
|
+
readonly parts: readonly P[];
|
|
6
|
+
/** A part's `data-slot`: the bare name for `root`, `name-part` otherwise. */
|
|
7
|
+
slot(part: P): string;
|
|
8
|
+
/** Each setting as `var(--vela-<name>-<setting>, <default>)`, for the component's CSS. */
|
|
9
|
+
readonly vars: {
|
|
10
|
+
readonly [K in S]: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
declare function defineComponent<const N extends string, const P extends string, const S extends string = never>(def: {
|
|
14
|
+
name: N;
|
|
15
|
+
parts: readonly P[];
|
|
16
|
+
settings?: {
|
|
17
|
+
readonly [K in S]: Token | string;
|
|
18
|
+
};
|
|
19
|
+
}): ComponentDef<N, P, S>;
|
|
20
|
+
|
|
21
|
+
export { type ComponentDef as C, defineComponent as d };
|
package/dist/dialog.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
|
+
import * as dialog from '@zag-js/dialog';
|
|
3
|
+
import './t.js';
|
|
4
|
+
|
|
5
|
+
interface DialogControllerOptions {
|
|
6
|
+
/** Trap focus + backdrop (default true). Non-modal = floating panel. */
|
|
7
|
+
modal?: boolean;
|
|
8
|
+
closeOnEscape?: boolean;
|
|
9
|
+
closeOnInteractOutside?: boolean;
|
|
10
|
+
/** Element to focus on open (default: the machine's first-tabbable pick). */
|
|
11
|
+
initialFocusEl?: () => HTMLElement | null;
|
|
12
|
+
onOpenChange?: (open: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
type DialogService = dialog.Service;
|
|
15
|
+
type DialogApi = dialog.Api;
|
|
16
|
+
interface DialogController {
|
|
17
|
+
machine: typeof dialog.machine;
|
|
18
|
+
props: Partial<dialog.Props>;
|
|
19
|
+
connect(service: DialogService): DialogApi;
|
|
20
|
+
}
|
|
21
|
+
/** Zag's dialog machine with the options mapped onto it, for any view layer. */
|
|
22
|
+
declare function dialogController(opts?: DialogControllerOptions): DialogController;
|
|
23
|
+
declare const dialogDef: ComponentDef<"dialog", "backdrop" | "body" | "footer" | "header" | "title" | "close" | "content" | "positioner", "radius">;
|
|
24
|
+
type DialogVariant = 'default' | 'settings' | 'form';
|
|
25
|
+
interface DialogOptions extends DialogControllerOptions {
|
|
26
|
+
title?: string;
|
|
27
|
+
content?: Node | ((body: HTMLElement) => void);
|
|
28
|
+
host?: HTMLElement;
|
|
29
|
+
/** Drag the dialog by its header (the reference dialogs move; search stays fixed). */
|
|
30
|
+
draggable?: boolean;
|
|
31
|
+
/** Darken the page behind the dialog (default false — the chart stays readable while
|
|
32
|
+
* dialogs edit live content). Pass true for a dimming scrim; the backdrop still
|
|
33
|
+
* catches interact-outside dismissal either way. */
|
|
34
|
+
dimBackdrop?: boolean;
|
|
35
|
+
/** Vertical placement of the card. Default `top` (current 10vh pad). */
|
|
36
|
+
align?: 'top' | 'center';
|
|
37
|
+
/** Pin the overlay to `host` (absolute) instead of the viewport (fixed). */
|
|
38
|
+
contained?: boolean;
|
|
39
|
+
/** Footer pinned below the scrollable body. */
|
|
40
|
+
footer?: Node | ((el: HTMLElement) => void);
|
|
41
|
+
/** Extra nodes before the title (e.g. a mobile section burger). */
|
|
42
|
+
headerStart?: Node;
|
|
43
|
+
/** Skip default body padding — the caller owns the body layout. */
|
|
44
|
+
flush?: boolean;
|
|
45
|
+
/** `settings`: the chart settings card; `form`: the indicator and drawing settings card. */
|
|
46
|
+
variant?: DialogVariant;
|
|
47
|
+
/** Extra class on the panel. */
|
|
48
|
+
className?: string;
|
|
49
|
+
/** Close when the backdrop itself is pressed (not when a portaled popover is). */
|
|
50
|
+
closeOnBackdrop?: boolean;
|
|
51
|
+
}
|
|
52
|
+
type DialogProps = DialogOptions;
|
|
53
|
+
declare class Dialog {
|
|
54
|
+
/** Caller-owned content area — append your form/panel here. */
|
|
55
|
+
readonly body: HTMLElement;
|
|
56
|
+
readonly panel: HTMLElement;
|
|
57
|
+
readonly titleEl: HTMLElement;
|
|
58
|
+
readonly positioner: HTMLElement;
|
|
59
|
+
readonly backdrop: HTMLElement;
|
|
60
|
+
readonly footer: HTMLElement | null;
|
|
61
|
+
private readonly handle;
|
|
62
|
+
private readonly ctrl;
|
|
63
|
+
constructor(opts?: DialogOptions);
|
|
64
|
+
private opener;
|
|
65
|
+
private wasOpen;
|
|
66
|
+
/** The panel and scrim's exit animation after a close; a reopen cancels it. */
|
|
67
|
+
private exit;
|
|
68
|
+
private destroyed;
|
|
69
|
+
private setShown;
|
|
70
|
+
/** Keep the just-closed dialog up through its exit animation, then hide it — or
|
|
71
|
+
* remove it, when it was destroyed meanwhile. `spreadProps` re-applies the close
|
|
72
|
+
* props' `hidden` only when its value changes, so lifting it keeps the panel and
|
|
73
|
+
* scrim up until the exit ends. The positioner spans the viewport: inert, it lets
|
|
74
|
+
* clicks through to the page while the panel animates out. */
|
|
75
|
+
private holdExit;
|
|
76
|
+
private detach;
|
|
77
|
+
/** Closing hands focus back to whatever opened it (Escape, the ✕, hide(), or a
|
|
78
|
+
* teardown that outruns the machine's close notification). */
|
|
79
|
+
private restoreOpener;
|
|
80
|
+
private announce;
|
|
81
|
+
get open(): boolean;
|
|
82
|
+
show(): void;
|
|
83
|
+
hide(): void;
|
|
84
|
+
contains(node: Node | null): boolean;
|
|
85
|
+
destroy(): void;
|
|
86
|
+
}
|
|
87
|
+
declare function createDialog(props?: DialogProps): Dialog;
|
|
88
|
+
|
|
89
|
+
export { Dialog, type DialogApi, type DialogController, type DialogControllerOptions, type DialogOptions, type DialogProps, type DialogService, type DialogVariant, createDialog, dialogController, dialogDef };
|
package/dist/dialog.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { iconEl } from './chunk-G7IQLY3A.js';
|
|
2
|
+
import { isPopoverOpen, eventDismissedPopover, closeOpenPopovers } from './chunk-B5ZSRUDQ.js';
|
|
3
|
+
import { announceSurface } from './chunk-J2QJATCD.js';
|
|
4
|
+
import { holdForExit } from './chunk-S7USVSYP.js';
|
|
5
|
+
import './chunk-V2Q4MRMS.js';
|
|
6
|
+
import './chunk-TAKSIV57.js';
|
|
7
|
+
import './chunk-MMTMOV6R.js';
|
|
8
|
+
import './chunk-3Q32K4PE.js';
|
|
9
|
+
import { disposeWithin } from './chunk-A72NWYNP.js';
|
|
10
|
+
import { normalizeProps, nextUid, runMachine, spreadProps } from './chunk-P4MTEMT7.js';
|
|
11
|
+
import './chunk-Q6WTDVH6.js';
|
|
12
|
+
import { defineComponent } from './chunk-VMCR3S2A.js';
|
|
13
|
+
import { defineStyles, css } from './chunk-XBEL4K33.js';
|
|
14
|
+
import { injectStyles } from './chunk-2GQIZM5Z.js';
|
|
15
|
+
import './chunk-BXMWQIBO.js';
|
|
16
|
+
import './chunk-X66RJAIS.js';
|
|
17
|
+
import { t } from './chunk-6QCILIT2.js';
|
|
18
|
+
import * as dialog from '@zag-js/dialog';
|
|
19
|
+
|
|
20
|
+
function dialogController(opts = {}) {
|
|
21
|
+
return {
|
|
22
|
+
machine: dialog.machine,
|
|
23
|
+
props: {
|
|
24
|
+
id: nextUid("vela-dialog"),
|
|
25
|
+
modal: opts.modal ?? true,
|
|
26
|
+
closeOnEscape: opts.closeOnEscape ?? true,
|
|
27
|
+
closeOnInteractOutside: opts.closeOnInteractOutside ?? false,
|
|
28
|
+
initialFocusEl: opts.initialFocusEl,
|
|
29
|
+
onOpenChange: (d) => opts.onOpenChange?.(d.open)
|
|
30
|
+
},
|
|
31
|
+
connect: (service) => dialog.connect(service, normalizeProps)
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var dialogDef = defineComponent({
|
|
35
|
+
name: "dialog",
|
|
36
|
+
parts: ["backdrop", "positioner", "content", "header", "title", "close", "body", "footer"],
|
|
37
|
+
settings: { radius: t.radius.lg }
|
|
38
|
+
});
|
|
39
|
+
var injectStyles2 = defineStyles(
|
|
40
|
+
"vela-ui-dialog-5",
|
|
41
|
+
css`@layer vela.ui{[data-slot=dialog-backdrop]{background:${t.backdrop};z-index:${t.z.dialog};position:fixed;inset:0}[data-slot=dialog-backdrop][data-clear]{background:0 0}[data-slot=dialog-backdrop][data-contained],[data-slot=dialog-backdrop]:is([data-layout=mobile] *){position:absolute}[data-slot=dialog-positioner]{z-index:${t.z.dialog};justify-content:center;align-items:flex-start;padding-top:10vh;display:flex;position:fixed;inset:0}[data-slot=dialog-positioner][data-contained]{position:absolute}[data-slot=dialog-positioner][data-align=center]{align-items:center;padding-top:0}[data-slot=dialog-positioner]:is([data-layout=mobile] *){align-items:stretch;padding:0;position:absolute}[data-slot=dialog-header]{border-bottom:1px solid ${t.border};-webkit-user-select:none;user-select:none;align-items:center;padding-block:9px;padding-inline:16px 9px;display:flex}[data-slot=dialog-title]{letter-spacing:.2px;color:${t.fg.bright};flex:1;font-size:17px;font-weight:600}[data-slot=dialog-close]{all:unset;cursor:pointer;border-radius:${t.radius.sm};width:30px;height:30px;color:${t.fg.muted};justify-content:center;align-items:center;font-size:15px;line-height:1;display:flex}[data-slot=dialog-close]:hover{background:${t.hover};color:${t.fg.bright}}[data-slot=dialog-close]:is([data-layout=mobile] *){width:40px;height:40px}[data-slot=dialog-body]{padding:${t.space[4]};flex:auto;min-height:0;overflow:auto}[data-slot=dialog-body][data-flush]{flex-direction:column;padding:0;display:flex;overflow:hidden}[data-slot=dialog-body]:is([data-layout=mobile] *){padding-bottom:calc(${t.space[4]} + env(safe-area-inset-bottom,0px))}[data-slot=dialog-footer]{flex:none}[data-slot=dialog-content]{background:${t.surface};color:${t.fg};border:1px solid ${t.border.strong};border-radius:${dialogDef.vars.radius};box-shadow:${t.shadow.dialog};outline:2px solid #0000;flex-direction:column;min-width:300px;max-width:min(92vw,560px);max-height:70vh;font-size:13px;display:flex;overflow:hidden}[data-slot=dialog-content][data-state=open]{animation:vela-dialog-in ${t.dur.med} ${t.ease}}[data-slot=dialog-content][data-variant=default] [data-slot=dialog-footer]{justify-content:flex-end;gap:${t.space[2]};padding:0 ${t.space[4]} ${t.space[4]};display:flex}[data-slot=dialog-content][data-variant=settings]{cursor:default;width:fit-content;min-width:min(560px,94vw);max-width:min(720px,94vw);max-height:70vh;font-size:13px}[data-slot=dialog-content][data-variant=form]{width:fit-content;min-width:min(380px,90%);max-width:min(640px,94%);max-height:82%;font-size:14px}[data-slot=dialog-content][data-variant=form] [data-slot=dialog-header]{border-bottom:none;align-items:flex-start;padding:16px 20px 20px}[data-slot=dialog-content][data-variant=form] [data-slot=dialog-title]{font-size:20px;line-height:28px}[data-slot=dialog-content][data-variant=form] [data-slot=dialog-footer]{border-top:1px solid ${t.border};justify-content:flex-end;gap:12px;padding:16px 20px;display:flex}[data-slot=dialog-content]:is([data-layout=mobile] *){border:none;border-radius:0;flex:auto;width:100%;min-width:0;max-width:none;max-height:none}@keyframes vela-dialog-in{0%{opacity:0;transform:translateY(6px)scale(.98)}to{opacity:1;transform:translateY(0)scale(1)}}}`
|
|
42
|
+
);
|
|
43
|
+
var MOBILE_DRAG_CSS = "[data-layout='mobile'] .vela-dialog { transform: none !important; }";
|
|
44
|
+
var VARIANT_CLASSES = { "vela-dialog--settings": "settings", "vela-dialog--form": "form" };
|
|
45
|
+
var Dialog = class {
|
|
46
|
+
constructor(opts = {}) {
|
|
47
|
+
this.opener = null;
|
|
48
|
+
this.wasOpen = false;
|
|
49
|
+
/** The panel and scrim's exit animation after a close; a reopen cancels it. */
|
|
50
|
+
this.exit = null;
|
|
51
|
+
this.destroyed = false;
|
|
52
|
+
const doc = (opts.host ?? document.body).ownerDocument;
|
|
53
|
+
injectStyles2(doc);
|
|
54
|
+
injectStyles("vela-ui-dialog-mobile", MOBILE_DRAG_CSS, doc);
|
|
55
|
+
const host = opts.host ?? doc.body;
|
|
56
|
+
const part = (el, name) => {
|
|
57
|
+
el.dataset.slot = dialogDef.slot(name);
|
|
58
|
+
return el;
|
|
59
|
+
};
|
|
60
|
+
this.backdrop = part(doc.createElement("div"), "backdrop");
|
|
61
|
+
this.backdrop.className = "vela-dialog-backdrop vela-ui-layer";
|
|
62
|
+
if (opts.dimBackdrop !== true) {
|
|
63
|
+
this.backdrop.classList.add("vela-dialog-backdrop--clear");
|
|
64
|
+
this.backdrop.dataset.clear = "";
|
|
65
|
+
}
|
|
66
|
+
this.positioner = part(doc.createElement("div"), "positioner");
|
|
67
|
+
this.positioner.className = "vela-dialog-positioner vela-ui-layer";
|
|
68
|
+
if (opts.contained) {
|
|
69
|
+
this.backdrop.dataset.contained = "";
|
|
70
|
+
this.positioner.dataset.contained = "";
|
|
71
|
+
}
|
|
72
|
+
this.positioner.dataset.align = opts.align ?? "top";
|
|
73
|
+
this.panel = part(doc.createElement("div"), "content");
|
|
74
|
+
this.panel.className = "vela-dialog";
|
|
75
|
+
const classes = (opts.className ?? "").split(/\s+/).filter(Boolean);
|
|
76
|
+
const variant = opts.variant ?? classes.map((c) => VARIANT_CLASSES[c]).find((v) => v !== void 0) ?? "default";
|
|
77
|
+
this.panel.dataset.variant = variant;
|
|
78
|
+
if (variant !== "default") this.panel.classList.add(`vela-dialog--${variant}`);
|
|
79
|
+
for (const c of classes) this.panel.classList.add(c);
|
|
80
|
+
this.panel.tabIndex = -1;
|
|
81
|
+
this.panel.addEventListener("keydown", (e) => {
|
|
82
|
+
if (e.key !== "Escape") e.stopPropagation();
|
|
83
|
+
});
|
|
84
|
+
const header = part(doc.createElement("div"), "header");
|
|
85
|
+
header.className = "vela-dialog-header";
|
|
86
|
+
if (opts.draggable) {
|
|
87
|
+
header.style.cursor = "move";
|
|
88
|
+
let sx = 0;
|
|
89
|
+
let sy = 0;
|
|
90
|
+
let ox = 0;
|
|
91
|
+
let oy = 0;
|
|
92
|
+
let dragging = false;
|
|
93
|
+
header.addEventListener("pointerdown", (e) => {
|
|
94
|
+
if (e.target.closest(".vela-dialog-close")) return;
|
|
95
|
+
dragging = true;
|
|
96
|
+
sx = e.clientX - ox;
|
|
97
|
+
sy = e.clientY - oy;
|
|
98
|
+
header.setPointerCapture(e.pointerId);
|
|
99
|
+
});
|
|
100
|
+
header.addEventListener("pointermove", (e) => {
|
|
101
|
+
if (!dragging) return;
|
|
102
|
+
ox = e.clientX - sx;
|
|
103
|
+
oy = e.clientY - sy;
|
|
104
|
+
this.panel.style.transform = `translate(${ox}px, ${oy}px)`;
|
|
105
|
+
});
|
|
106
|
+
header.addEventListener("pointerup", () => dragging = false);
|
|
107
|
+
}
|
|
108
|
+
if (opts.headerStart) header.appendChild(opts.headerStart);
|
|
109
|
+
const title = part(doc.createElement("div"), "title");
|
|
110
|
+
title.className = "vela-dialog-title";
|
|
111
|
+
title.textContent = opts.title ?? "";
|
|
112
|
+
this.titleEl = title;
|
|
113
|
+
const close = part(doc.createElement("button"), "close");
|
|
114
|
+
close.className = "vela-dialog-close";
|
|
115
|
+
close.appendChild(iconEl("close", doc));
|
|
116
|
+
header.append(title, close);
|
|
117
|
+
this.body = part(doc.createElement("div"), "body");
|
|
118
|
+
this.body.className = "vela-dialog-body";
|
|
119
|
+
if (opts.flush) this.body.dataset.flush = "";
|
|
120
|
+
if (opts.content instanceof Node) this.body.appendChild(opts.content);
|
|
121
|
+
else if (typeof opts.content === "function") opts.content(this.body);
|
|
122
|
+
this.panel.append(header, this.body);
|
|
123
|
+
if (opts.footer) {
|
|
124
|
+
const foot = part(doc.createElement("div"), "footer");
|
|
125
|
+
foot.className = "vela-dialog-footer";
|
|
126
|
+
if (opts.footer instanceof Node) foot.appendChild(opts.footer);
|
|
127
|
+
else opts.footer(foot);
|
|
128
|
+
this.panel.appendChild(foot);
|
|
129
|
+
this.footer = foot;
|
|
130
|
+
} else {
|
|
131
|
+
this.footer = null;
|
|
132
|
+
}
|
|
133
|
+
this.positioner.appendChild(this.panel);
|
|
134
|
+
host.append(this.backdrop, this.positioner);
|
|
135
|
+
if (opts.closeOnBackdrop) {
|
|
136
|
+
const closeOn = (e) => {
|
|
137
|
+
if (e.target !== this.backdrop && e.target !== this.positioner) return;
|
|
138
|
+
if (isPopoverOpen() || eventDismissedPopover(e)) {
|
|
139
|
+
closeOpenPopovers();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this.hide();
|
|
143
|
+
};
|
|
144
|
+
this.backdrop.addEventListener("pointerdown", closeOn);
|
|
145
|
+
this.positioner.addEventListener("pointerdown", closeOn);
|
|
146
|
+
}
|
|
147
|
+
this.ctrl = dialogController({
|
|
148
|
+
...opts,
|
|
149
|
+
// Mobile chrome (fullscreen presentation): opening must never land focus on
|
|
150
|
+
// an input — that pops the on-screen keyboard over the just-opened dialog.
|
|
151
|
+
// Focus goes to the panel; a caller that WANTS the keyboard focuses its
|
|
152
|
+
// input explicitly. Desktop keeps the caller's pick, else the machine's
|
|
153
|
+
// first-tabbable default.
|
|
154
|
+
initialFocusEl: () => {
|
|
155
|
+
if (this.positioner.closest('[data-layout="mobile"]')) return this.panel;
|
|
156
|
+
return opts.initialFocusEl?.() ?? null;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
const mid = String(this.ctrl.props.id);
|
|
160
|
+
this.handle = runMachine(this.ctrl.machine, this.ctrl.props, (service) => {
|
|
161
|
+
const api = this.ctrl.connect(service);
|
|
162
|
+
const closing = this.wasOpen && !api.open;
|
|
163
|
+
if (closing) this.announce(false);
|
|
164
|
+
spreadProps(this.backdrop, api.getBackdropProps(), mid);
|
|
165
|
+
spreadProps(this.positioner, api.getPositionerProps(), mid);
|
|
166
|
+
spreadProps(this.panel, api.getContentProps(), mid);
|
|
167
|
+
spreadProps(title, api.getTitleProps(), mid);
|
|
168
|
+
spreadProps(close, api.getCloseTriggerProps(), mid);
|
|
169
|
+
if (api.open) {
|
|
170
|
+
this.exit?.cancel();
|
|
171
|
+
this.exit = null;
|
|
172
|
+
this.setShown(true);
|
|
173
|
+
} else if (closing) {
|
|
174
|
+
this.holdExit();
|
|
175
|
+
} else if (!this.exit) {
|
|
176
|
+
this.setShown(false);
|
|
177
|
+
}
|
|
178
|
+
if (api.open && !this.wasOpen) this.announce(true);
|
|
179
|
+
if (this.wasOpen && !api.open) this.restoreOpener();
|
|
180
|
+
this.wasOpen = api.open;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
setShown(shown) {
|
|
184
|
+
this.backdrop.style.display = shown ? "" : "none";
|
|
185
|
+
this.positioner.style.display = shown ? "" : "none";
|
|
186
|
+
}
|
|
187
|
+
/** Keep the just-closed dialog up through its exit animation, then hide it — or
|
|
188
|
+
* remove it, when it was destroyed meanwhile. `spreadProps` re-applies the close
|
|
189
|
+
* props' `hidden` only when its value changes, so lifting it keeps the panel and
|
|
190
|
+
* scrim up until the exit ends. The positioner spans the viewport: inert, it lets
|
|
191
|
+
* clicks through to the page while the panel animates out. */
|
|
192
|
+
holdExit() {
|
|
193
|
+
const held = [this.panel, this.backdrop];
|
|
194
|
+
for (const el of held) el.hidden = false;
|
|
195
|
+
this.exit = holdForExit(
|
|
196
|
+
held,
|
|
197
|
+
() => {
|
|
198
|
+
this.exit = null;
|
|
199
|
+
if (this.destroyed) {
|
|
200
|
+
this.detach();
|
|
201
|
+
} else if (!this.open) {
|
|
202
|
+
for (const el of held) el.hidden = true;
|
|
203
|
+
this.setShown(false);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
{ inert: [this.positioner] }
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
detach() {
|
|
210
|
+
this.backdrop.remove();
|
|
211
|
+
this.positioner.remove();
|
|
212
|
+
}
|
|
213
|
+
/** Closing hands focus back to whatever opened it (Escape, the ✕, hide(), or a
|
|
214
|
+
* teardown that outruns the machine's close notification). */
|
|
215
|
+
restoreOpener() {
|
|
216
|
+
const opener = this.opener;
|
|
217
|
+
this.opener = null;
|
|
218
|
+
if (opener?.isConnected) opener.focus({ preventScroll: true });
|
|
219
|
+
}
|
|
220
|
+
announce(open) {
|
|
221
|
+
const opener = this.opener === this.panel.ownerDocument.body ? null : this.opener;
|
|
222
|
+
announceSurface(this.panel, open, "dialog", opener);
|
|
223
|
+
}
|
|
224
|
+
get open() {
|
|
225
|
+
return this.ctrl.connect(this.handle.service).open;
|
|
226
|
+
}
|
|
227
|
+
show() {
|
|
228
|
+
this.opener = this.panel.ownerDocument.activeElement;
|
|
229
|
+
this.ctrl.connect(this.handle.service).setOpen(true);
|
|
230
|
+
}
|
|
231
|
+
hide() {
|
|
232
|
+
this.ctrl.connect(this.handle.service).setOpen(false);
|
|
233
|
+
}
|
|
234
|
+
contains(node) {
|
|
235
|
+
if (node == null) return false;
|
|
236
|
+
if (this.panel.contains(node) || this.backdrop.contains(node) || this.positioner.contains(node)) return true;
|
|
237
|
+
const el = node instanceof Element ? node : node.parentElement;
|
|
238
|
+
return el?.closest(".vela-popover, .vela-menu") != null;
|
|
239
|
+
}
|
|
240
|
+
destroy() {
|
|
241
|
+
if (this.wasOpen && !this.open) this.handle.flush();
|
|
242
|
+
if (this.open) this.hide();
|
|
243
|
+
this.handle.stop();
|
|
244
|
+
this.destroyed = true;
|
|
245
|
+
if (this.wasOpen) {
|
|
246
|
+
this.wasOpen = false;
|
|
247
|
+
this.announce(false);
|
|
248
|
+
}
|
|
249
|
+
this.restoreOpener();
|
|
250
|
+
disposeWithin(this.panel);
|
|
251
|
+
if (!this.exit) this.detach();
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
function createDialog(props = {}) {
|
|
255
|
+
return new Dialog(props);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { Dialog, createDialog, dialogController, dialogDef };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Tie `teardown` to `el` and return its release, which runs it once: a control's `destroy()`
|
|
2
|
+
* calls the release, and so does {@link disposeWithin} on any of its ancestors. */
|
|
3
|
+
declare function ownTeardown(el: Element, teardown: () => void): () => void;
|
|
4
|
+
/** Release every kit control inside `root`, `root` included. Call it on a subtree you are
|
|
5
|
+
* discarding: a dialog body you rebuild, a row you remove. A released control no longer
|
|
6
|
+
* responds, so never call it on content you will show again. */
|
|
7
|
+
declare function disposeWithin(root: Element | DocumentFragment | null | undefined): void;
|
|
8
|
+
|
|
9
|
+
export { disposeWithin, ownTeardown };
|
package/dist/dispose.js
ADDED
package/dist/donut.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { C as ComponentDef } from './define-D5u3F5Dj.js';
|
|
2
|
+
import './t.js';
|
|
3
|
+
|
|
4
|
+
declare const donutDef: ComponentDef<"donut", "root" | "caption" | "figure" | "label" | "legend" | "track" | "swatch" | "value" | "ring" | "segment" | "item", "swatch-radius">;
|
|
5
|
+
interface DonutSegment {
|
|
6
|
+
value: number;
|
|
7
|
+
label: string;
|
|
8
|
+
/** The segment's ink: a token's `var()` (`t.profit.var`) or a color. */
|
|
9
|
+
color: string;
|
|
10
|
+
}
|
|
11
|
+
interface DonutProps {
|
|
12
|
+
segments: readonly DonutSegment[];
|
|
13
|
+
/** The figure in the middle. */
|
|
14
|
+
center: string;
|
|
15
|
+
/** A line under the figure. */
|
|
16
|
+
caption?: string;
|
|
17
|
+
/** Extra class names (layout hooks). */
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
interface DonutHandle {
|
|
21
|
+
readonly el: HTMLElement;
|
|
22
|
+
set(segments: readonly DonutSegment[], center: string, caption?: string): void;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
declare function createDonut(props: DonutProps): DonutHandle;
|
|
26
|
+
|
|
27
|
+
export { type DonutHandle, type DonutProps, type DonutSegment, createDonut, donutDef };
|