@viewstem/ui 0.0.0-stage → 0.1.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +47 -0
  3. package/README.md +60 -2
  4. package/dist/BASECOAT-LICENSE.md +21 -0
  5. package/dist/basecoat-contracts.d.ts +2 -0
  6. package/dist/basecoat-contracts.js +358 -0
  7. package/dist/basecoat-controllers.js +1612 -0
  8. package/dist/behaviors.d.ts +29 -0
  9. package/dist/behaviors.js +1475 -0
  10. package/dist/browser.d.ts +2 -0
  11. package/dist/browser.js +2 -0
  12. package/dist/catalog-meta.d.ts +26 -0
  13. package/dist/catalog-meta.js +130 -0
  14. package/dist/component-context.d.ts +7 -0
  15. package/dist/component-context.js +10 -0
  16. package/dist/components.d.ts +2 -0
  17. package/dist/components.js +532 -0
  18. package/dist/data-table.d.ts +2 -0
  19. package/dist/data-table.js +231 -0
  20. package/dist/date-calendar.d.ts +4 -0
  21. package/dist/date-calendar.js +512 -0
  22. package/dist/dynamic-catalog.d.ts +2 -0
  23. package/dist/dynamic-catalog.js +118 -0
  24. package/dist/form-scroll-families.d.ts +7 -0
  25. package/dist/form-scroll-families.js +895 -0
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.js +12 -0
  28. package/dist/markup-families.d.ts +10 -0
  29. package/dist/markup-families.js +492 -0
  30. package/dist/menus.d.ts +8 -0
  31. package/dist/menus.js +427 -0
  32. package/dist/shadcn.d.ts +13 -0
  33. package/dist/shadcn.js +8 -0
  34. package/dist/slider-values.d.ts +9 -0
  35. package/dist/slider-values.js +43 -0
  36. package/dist/slider.d.ts +2 -0
  37. package/dist/slider.js +148 -0
  38. package/dist/static-catalog.d.ts +2 -0
  39. package/dist/static-catalog.js +87 -0
  40. package/dist/style-scope.d.ts +2 -0
  41. package/dist/style-scope.js +3 -0
  42. package/dist/styles.css +9573 -0
  43. package/dist/styles.css.d.ts +1 -0
  44. package/dist/support.json +1 -0
  45. package/dist/widget-families.d.ts +6 -0
  46. package/dist/widget-families.js +739 -0
  47. package/package.json +59 -4
@@ -0,0 +1,512 @@
1
+ import { DateFormatter, parseDate } from '@internationalized/date';
2
+ import { connect, machine } from '@zag-js/date-picker';
3
+ import { normalizeProps, spreadProps, VanillaMachine } from '@zag-js/vanilla';
4
+ import { uniqueId } from './behaviors.js';
5
+ import { styleScope } from './style-scope.js';
6
+ const getApi = (service) => connect(service.service, normalizeProps);
7
+ function date(value) {
8
+ if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value))
9
+ return undefined;
10
+ try {
11
+ const parsed = parseDate(value);
12
+ return parsed.toString() === value ? parsed : undefined;
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ }
18
+ function dates(input, kind, mode) {
19
+ if (mode === 'range') {
20
+ const value = (kind === 'DatePicker' ? input.range : input.value);
21
+ const start = date(value?.start);
22
+ const end = date(value?.end);
23
+ return start ? end && start.compare(end) <= 0 ? [start, end] : [start] : [];
24
+ }
25
+ const values = Array.isArray(input.value) ? input.value : [input.value];
26
+ return values.map(date).filter((value) => value !== undefined);
27
+ }
28
+ function locale(input) {
29
+ try {
30
+ return Intl.DateTimeFormat.supportedLocalesOf(String(input.locale ?? 'en-US'))[0] ?? 'en-US';
31
+ }
32
+ catch {
33
+ return 'en-US';
34
+ }
35
+ }
36
+ function getMode(kind, input) {
37
+ if (kind === 'RangeCalendar.Root' || (kind === 'DatePicker' && (input.mode === 'range' || (input.mode === undefined && input.range !== undefined))))
38
+ return 'range';
39
+ return input.type === 'multiple' ? 'multiple' : 'single';
40
+ }
41
+ function iso(value) { return value?.toString() ?? null; }
42
+ const keyOf = (values) => values.map(iso).join(',');
43
+ export function dateCalendar(element, kind, send, signal) {
44
+ const doc = element.ownerDocument;
45
+ const view = doc.defaultView;
46
+ const picker = kind === 'DatePicker';
47
+ const id = uniqueId();
48
+ const root = styleScope.createElement(doc, 'div');
49
+ root.className = 'vs-date-calendar';
50
+ if (picker)
51
+ root.dataset.picker = '';
52
+ const control = styleScope.createElement(doc, 'div');
53
+ const trigger = styleScope.createElement(doc, 'button');
54
+ trigger.className = 'btn vs-date-trigger';
55
+ trigger.dataset.variant = 'outline';
56
+ const positioner = styleScope.createElement(doc, 'div');
57
+ const panel = styleScope.createElement(doc, 'div');
58
+ panel.className = 'vs-date-panel';
59
+ const navigation = styleScope.createElement(doc, 'div');
60
+ navigation.className = 'vs-date-navigation';
61
+ const previous = styleScope.createElement(doc, 'button');
62
+ const next = styleScope.createElement(doc, 'button');
63
+ previous.className = next.className = 'btn';
64
+ previous.dataset.variant = next.dataset.variant = 'ghost';
65
+ navigation.append(previous, next);
66
+ const months = styleScope.createElement(doc, 'div');
67
+ months.className = 'vs-date-months';
68
+ panel.append(navigation, months);
69
+ if (picker) {
70
+ control.append(trigger);
71
+ positioner.append(panel);
72
+ root.append(control, positioner);
73
+ }
74
+ else
75
+ root.append(panel);
76
+ element.append(root);
77
+ let inputs = {};
78
+ let mode = 'single';
79
+ let current = [];
80
+ const createService = () => new VanillaMachine(machine, machineProps);
81
+ let service;
82
+ let unsubscribe;
83
+ let previousExternal;
84
+ let previousPlaceholder = null;
85
+ let publishedPlaceholder = null;
86
+ let pageAnchor;
87
+ let silentFocus = null;
88
+ let clearedDate;
89
+ let dateFocus = false;
90
+ let wasOpen = false;
91
+ let pickerCloseTimer;
92
+ let initialYear;
93
+ let closed = false;
94
+ let grids = [];
95
+ const bindings = new Map();
96
+ let needsRender = false;
97
+ if (picker)
98
+ doc.addEventListener('click', event => {
99
+ if (!service || event.composedPath().includes(root))
100
+ return;
101
+ const api = getApi(service);
102
+ if (!api.open)
103
+ return;
104
+ // The deferred Zag listener can miss a click immediately after opening.
105
+ api.setOpen(false);
106
+ if (doc.activeElement === doc.body || panel.contains(doc.activeElement))
107
+ trigger.focus({ preventScroll: true });
108
+ }, { capture: true, signal });
109
+ function bind(node, props) {
110
+ bindings.set(node, spreadProps(node, props, id));
111
+ }
112
+ function removeBindings(within) {
113
+ for (const [node, cleanup] of bindings) {
114
+ if (within && !within.contains(node))
115
+ continue;
116
+ cleanup();
117
+ bindings.delete(node);
118
+ }
119
+ }
120
+ function requestRender() {
121
+ if (needsRender || signal.aborted || closed)
122
+ return;
123
+ needsRender = true;
124
+ queueMicrotask(() => {
125
+ needsRender = false;
126
+ if (!signal.aborted && !closed)
127
+ render();
128
+ });
129
+ }
130
+ function selectionFocus(values) {
131
+ return mode === 'range' ? values[0] : values.at(-1);
132
+ }
133
+ function publishPlaceholder(focused) {
134
+ const value = iso(focused);
135
+ if (picker || !value || value === publishedPlaceholder)
136
+ return;
137
+ publishedPlaceholder = value;
138
+ send('placeholderChange', { value });
139
+ }
140
+ function applyValue(nextValues) {
141
+ const previous = current;
142
+ let next = nextValues;
143
+ if (mode === 'range' && next[0] && next[1] && kind === 'RangeCalendar.Root') {
144
+ const span = Math.round((next[1].toDate('UTC').getTime() - next[0].toDate('UTC').getTime()) / 86_400_000) + 1;
145
+ const min = Number(inputs.minDays ?? 0);
146
+ const max = Number(inputs.maxDays ?? Infinity);
147
+ if (span < min || span > max) {
148
+ const selected = next.find(value => iso(value) !== iso(previous[0]));
149
+ next = selected ? [selected] : [next[0]];
150
+ }
151
+ }
152
+ if (keyOf(previous) === keyOf(next))
153
+ return;
154
+ current = next;
155
+ if (mode === 'range') {
156
+ const range = { start: iso(next[0]), end: iso(next[1]) };
157
+ if (kind === 'RangeCalendar.Root') {
158
+ if (range.start !== iso(previous[0]))
159
+ send('startValueChange', { value: range.start });
160
+ if (range.end !== iso(previous[1]))
161
+ send('endValueChange', { value: range.end });
162
+ }
163
+ send(picker ? 'rangeChange' : 'valueChange', { value: range });
164
+ if (next.length === 1 && nextValues.length === 2)
165
+ queueMicrotask(() => { if (!closed)
166
+ service?.service.context.set('activeIndex', 1); });
167
+ }
168
+ else
169
+ send('valueChange', { value: mode === 'multiple' ? next.map(iso) : iso(next[0]) });
170
+ publishPlaceholder(selectionFocus(next) ?? clearedDate);
171
+ clearedDate = undefined;
172
+ if (picker && (mode === 'single' || next.length === 2) && service) {
173
+ getApi(service).setOpen(false);
174
+ queueMicrotask(() => { if (!closed)
175
+ trigger.focus({ preventScroll: true }); });
176
+ }
177
+ requestRender();
178
+ }
179
+ function machineProps() {
180
+ const min = date(picker ? inputs.min : inputs.minValue);
181
+ const max = date(picker ? inputs.max : inputs.maxValue);
182
+ const focused = date(picker ? undefined : inputs.placeholder);
183
+ const count = Number(inputs.numberOfMonths ?? 1);
184
+ return {
185
+ id,
186
+ getRootNode: () => {
187
+ const owner = element.getRootNode();
188
+ // Zag can finish a queued focus or dismissable task after the element is detached.
189
+ return owner instanceof view.ShadowRoot ? owner : doc;
190
+ },
191
+ selectionMode: mode,
192
+ value: current,
193
+ min,
194
+ max,
195
+ ...(focused && { defaultFocusedValue: focused }),
196
+ disabled: inputs.disabled === true,
197
+ readOnly: inputs.readonly === true,
198
+ locale: locale(inputs),
199
+ dir: inputs.dir === 'rtl' ? 'rtl' : 'ltr',
200
+ timeZone: 'UTC',
201
+ numOfMonths: Number.isFinite(count) ? Math.max(1, Math.trunc(count)) : 1,
202
+ startOfWeek: typeof inputs.weekStartsOn === 'number' ? inputs.weekStartsOn : undefined,
203
+ fixedWeeks: inputs.fixedWeeks === true,
204
+ outsideDaySelectable: inputs.disableDaysOutsideMonth !== true,
205
+ maxSelectedDates: typeof inputs.maxDays === 'number' && mode === 'multiple' ? inputs.maxDays : undefined,
206
+ inline: !picker,
207
+ closeOnSelect: false,
208
+ positioning: { placement: 'bottom-start', gutter: 4 },
209
+ onValueChange({ value }) { if (!closed)
210
+ applyValue(value); },
211
+ onFocusChange({ focusedValue }) {
212
+ // Zag queues its machine actions, so use the action's actual origin.
213
+ const origin = service?.service.event.type;
214
+ if (!closed && origin !== 'CELL.POINTER_MOVE' && origin !== 'CELL.CLICK' && origin !== 'TABLE.ENTER' &&
215
+ iso(focusedValue) !== silentFocus)
216
+ publishPlaceholder(focusedValue);
217
+ silentFocus = null;
218
+ },
219
+ };
220
+ }
221
+ function makeGrid() {
222
+ const wrapper = styleScope.createElement(doc, 'section');
223
+ const caption = styleScope.createElement(doc, 'div');
224
+ caption.className = 'vs-date-caption';
225
+ const month = styleScope.createElement(doc, 'select');
226
+ const year = styleScope.createElement(doc, 'select');
227
+ month.className = year.className = 'select';
228
+ const table = styleScope.createElement(doc, 'table');
229
+ const head = styleScope.mark(table.createTHead());
230
+ const headRow = styleScope.mark(head.insertRow());
231
+ const headings = Array.from({ length: 7 }, () => {
232
+ const heading = styleScope.createElement(doc, 'th');
233
+ heading.scope = 'col';
234
+ headRow.append(heading);
235
+ return heading;
236
+ });
237
+ styleScope.mark(table.createTBody());
238
+ const heading = styleScope.createElement(doc, 'div');
239
+ heading.className = 'vs-date-heading';
240
+ heading.append(caption, month, year);
241
+ wrapper.append(heading, table);
242
+ months.append(wrapper);
243
+ return { table, caption, month, year, headings };
244
+ }
245
+ function setOptions(select, values, format, selected) {
246
+ const options = values.map(value => [String(value), format(value)]);
247
+ if (options.length !== select.options.length || options.some(([value, label], index) => select.options[index]?.value !== value || select.options[index]?.textContent !== label)) {
248
+ select.replaceChildren(...options.map(([value, label]) => {
249
+ const option = styleScope.createElement(doc, 'option');
250
+ option.value = value;
251
+ option.textContent = label;
252
+ return option;
253
+ }));
254
+ }
255
+ select.value = String(selected);
256
+ }
257
+ function deselect(api, value) {
258
+ if (picker || inputs.disabled === true || inputs.readonly === true || inputs.preventDeselect === true || mode === 'multiple')
259
+ return false;
260
+ const selected = mode === 'range' ? current.at(-1) : current[0];
261
+ if (iso(selected) !== iso(value))
262
+ return false;
263
+ clearedDate = value;
264
+ api.setValue([]);
265
+ service?.service.context.set('activeIndex', 0);
266
+ service?.service.context.set('hoveredValue', null);
267
+ return true;
268
+ }
269
+ function keepSelection(value) {
270
+ return mode === 'multiple' && inputs.preventDeselect === true && current.some(item => item.compare(value) === 0);
271
+ }
272
+ function render() {
273
+ if (!service || closed || signal.aborted)
274
+ return;
275
+ const api = getApi(service);
276
+ const language = locale(inputs);
277
+ const monthFormat = (inputs.monthFormat ?? (String(inputs.captionLayout).startsWith('dropdown') ? 'short' : 'long'));
278
+ const yearFormat = (inputs.yearFormat ?? 'numeric');
279
+ const monthName = new DateFormatter(language, { timeZone: 'UTC', month: monthFormat });
280
+ const yearName = new DateFormatter(language, { timeZone: 'UTC', year: yearFormat });
281
+ const labels = new DateFormatter(language, { timeZone: 'UTC', dateStyle: 'long' });
282
+ const active = doc.activeElement;
283
+ if (picker) {
284
+ if (api.open) {
285
+ if (!wasOpen)
286
+ dateFocus = true;
287
+ view.clearTimeout(pickerCloseTimer);
288
+ pickerCloseTimer = undefined;
289
+ }
290
+ else if (wasOpen && !view.matchMedia('(prefers-reduced-motion: reduce)').matches) {
291
+ pickerCloseTimer = view.setTimeout(() => {
292
+ pickerCloseTimer = undefined;
293
+ requestRender();
294
+ }, 100);
295
+ }
296
+ wasOpen = api.open;
297
+ bind(control, api.getControlProps());
298
+ bind(positioner, api.getPositionerProps());
299
+ const label = current.map(value => labels.format(value.toDate('UTC'))).join(' – ') || String(inputs.placeholder ?? 'Pick a date');
300
+ bind(trigger, { ...api.getTriggerProps(), 'aria-label': label, 'aria-haspopup': 'dialog' });
301
+ trigger.textContent = label;
302
+ }
303
+ bind(root, api.getRootProps());
304
+ bind(panel, {
305
+ ...api.getContentProps(),
306
+ ...(picker ? {
307
+ role: 'dialog',
308
+ hidden: !api.open && pickerCloseTimer === undefined,
309
+ inert: !api.open,
310
+ 'aria-hidden': !api.open,
311
+ } : { hidden: false }),
312
+ });
313
+ const first = api.visibleRange.start;
314
+ if (pageAnchor?.year !== first.year || pageAnchor.month !== first.month) {
315
+ pageAnchor = api.focusedValue.year === first.year && api.focusedValue.month === first.month ? api.focusedValue : first;
316
+ }
317
+ const initialPlaceholderYear = initialYear ??= first.year;
318
+ const step = inputs.pagedNavigation === true ? api.numOfMonths : 1;
319
+ bind(previous, { ...api.getPrevTriggerProps(), ...((!picker || step !== api.numOfMonths) && {
320
+ onclick: () => navigate(-step),
321
+ }) });
322
+ bind(next, { ...api.getNextTriggerProps(), ...((!picker || step !== api.numOfMonths) && {
323
+ onclick: () => navigate(step),
324
+ }) });
325
+ function navigate(amount) {
326
+ // Paging keeps the original view's day even if a different cell was selected.
327
+ const focused = (picker ? first : pageAnchor ?? first).add({ months: amount });
328
+ pageAnchor = focused;
329
+ service?.service.context.set('startValue', first.add({ months: amount }));
330
+ api.setFocusedValue(focused);
331
+ }
332
+ while (grids.length < api.numOfMonths)
333
+ grids.push(makeGrid());
334
+ while (grids.length > api.numOfMonths) {
335
+ const removed = grids.pop().table.parentElement;
336
+ removeBindings(removed);
337
+ removed.remove();
338
+ }
339
+ let focusTarget;
340
+ grids.forEach((grid, index) => {
341
+ const start = first.add({ months: index });
342
+ const weeks = api.getMonthWeeks(start);
343
+ const tableProps = api.getTableProps({ id: String(index) });
344
+ bind(grid.table, { ...tableProps,
345
+ ...(inputs['aria-label'] || inputs.calendarLabel ? { 'aria-label': inputs['aria-label'] ?? inputs.calendarLabel } : {}),
346
+ onkeydown(event) {
347
+ if ((event.key === 'Enter' || event.key === ' ') && (keepSelection(api.focusedValue) || deselect(api, api.focusedValue)))
348
+ event.preventDefault();
349
+ else
350
+ tableProps.onkeydown?.(event);
351
+ },
352
+ });
353
+ const startDate = start.toDate('UTC');
354
+ const layout = inputs.captionLayout;
355
+ grid.month.hidden = index !== 0 || (layout !== 'dropdown' && layout !== 'dropdown-months');
356
+ grid.year.hidden = index !== 0 || (layout !== 'dropdown' && layout !== 'dropdown-years');
357
+ grid.caption.hidden = !grid.month.hidden && !grid.year.hidden;
358
+ grid.caption.textContent = grid.month.hidden && grid.year.hidden
359
+ ? `${monthName.format(startDate)} ${yearName.format(startDate)}`
360
+ : grid.month.hidden ? monthName.format(startDate) : yearName.format(startDate);
361
+ if (!grid.month.hidden) {
362
+ const options = Array.isArray(inputs.months) ? inputs.months : Array.from({ length: 12 }, (_, i) => i + 1);
363
+ bind(grid.month, {
364
+ ...api.getMonthSelectProps(),
365
+ ...(!picker && {
366
+ oninput: undefined,
367
+ onchange: () => api.setFocusedValue((date(publishedPlaceholder) ?? api.focusedValue).set({ month: Number(grid.month.value) })),
368
+ }),
369
+ });
370
+ setOptions(grid.month, options, value => monthName.format(start.set({ month: value }).toDate('UTC')), start.month);
371
+ }
372
+ if (!grid.year.hidden) {
373
+ const latest = Math.max(initialPlaceholderYear, new Date().getFullYear());
374
+ const earliest = initialPlaceholderYear < latest - 100 ? initialPlaceholderYear - 10 : latest - 100;
375
+ const min = machineProps().min?.year ?? Math.min(start.year, earliest);
376
+ const max = machineProps().max?.year ?? Math.max(start.year, latest + 10);
377
+ const options = Array.isArray(inputs.years) ? inputs.years : Array.from({ length: Math.max(0, max - min + 1) }, (_, i) => min + i);
378
+ bind(grid.year, {
379
+ ...api.getYearSelectProps(),
380
+ ...(!picker && {
381
+ oninput: undefined,
382
+ onchange: () => api.setFocusedValue((date(publishedPlaceholder) ?? api.focusedValue).set({ year: Number(grid.year.value) })),
383
+ }),
384
+ });
385
+ setOptions(grid.year, options, value => yearName.format(start.set({ year: value }).toDate('UTC')), start.year);
386
+ }
387
+ const weekday = (inputs.weekdayFormat ?? 'short');
388
+ grid.headings.forEach((heading, day) => { heading.textContent = api.weekDays[day]?.[weekday] ?? ''; });
389
+ const body = grid.table.tBodies[0];
390
+ while (body.rows.length > weeks.length) {
391
+ const row = body.rows[body.rows.length - 1];
392
+ removeBindings(row);
393
+ row.remove();
394
+ }
395
+ while (body.rows.length < weeks.length) {
396
+ const row = styleScope.mark(body.insertRow());
397
+ for (let day = 0; day < 7; day++) {
398
+ const cell = styleScope.mark(row.insertCell());
399
+ const button = styleScope.createElement(doc, 'button');
400
+ button.type = 'button';
401
+ button.className = 'btn vs-date-day';
402
+ cell.append(button);
403
+ }
404
+ }
405
+ const end = start.add({ months: 1 }).subtract({ days: 1 });
406
+ weeks.forEach((week, row) => week.forEach((value, day) => {
407
+ const cell = body.rows[row].cells[day];
408
+ const button = cell.firstElementChild;
409
+ const inMonth = start.month === value.month && start.year === value.year;
410
+ const duplicate = !inMonth && first.compare(value) <= 0 && api.visibleRange.end.compare(value) >= 0;
411
+ const args = { value, visibleRange: { start, end } };
412
+ const props = api.getDayTableCellTriggerProps(args);
413
+ bind(cell, api.getDayTableCellProps(args));
414
+ bind(button, { ...props, id: duplicate ? undefined : props.id, hidden: duplicate, 'data-date': iso(value),
415
+ 'aria-invalid': undefined, 'data-outside-month': !inMonth || undefined,
416
+ 'data-variant': inputs.buttonVariant === 'default' ? 'primary' : inputs.buttonVariant ?? 'ghost',
417
+ onfocus() {
418
+ if (duplicate || !service)
419
+ return;
420
+ const activeApi = getApi(service);
421
+ if (iso(activeApi.focusedValue) !== iso(value)) {
422
+ // DOM focus and the public placeholder differ when a range's end is clicked.
423
+ if (!picker)
424
+ silentFocus = iso(value);
425
+ activeApi.setFocusedValue(value);
426
+ }
427
+ },
428
+ onclick(event) { if (!keepSelection(value) && !deselect(api, value))
429
+ props.onclick?.(event); },
430
+ });
431
+ button.textContent = String(value.day);
432
+ if (!duplicate && iso(value) === iso(api.focusedValue))
433
+ focusTarget = button;
434
+ }));
435
+ });
436
+ if (focusTarget && (!picker || api.open) && (dateFocus || (active && panel.contains(active) && active.getAttribute('data-date') !== null))) {
437
+ focusTarget.focus({ preventScroll: true });
438
+ dateFocus = false;
439
+ }
440
+ }
441
+ return {
442
+ sync(next) {
443
+ inputs = next;
444
+ const selectionMode = getMode(kind, inputs);
445
+ const value = picker && selectionMode === 'range' ? inputs.range : inputs.value;
446
+ const suppliedDates = dates(inputs, kind, selectionMode);
447
+ const min = picker ? date(inputs.min) : undefined;
448
+ const max = picker ? date(inputs.max) : undefined;
449
+ const constrain = (value) => {
450
+ const lower = min && value.compare(min) < 0 ? min : value;
451
+ return max && lower.compare(max) > 0 ? max : lower;
452
+ };
453
+ const nextValues = picker ? suppliedDates.map(constrain) : suppliedDates;
454
+ const signature = value === undefined ? undefined : picker
455
+ ? JSON.stringify([keyOf(suppliedDates), keyOf(nextValues)]) : keyOf(suppliedDates);
456
+ const placeholder = picker ? null : iso(date(inputs.placeholder));
457
+ if (!service || mode !== selectionMode) {
458
+ unsubscribe?.();
459
+ service?.stop();
460
+ mode = selectionMode;
461
+ current = nextValues;
462
+ previousExternal = signature;
463
+ previousPlaceholder = placeholder;
464
+ pageAnchor = date(placeholder) ?? selectionFocus(nextValues);
465
+ publishedPlaceholder = iso(pageAnchor);
466
+ dateFocus = !picker && inputs.initialFocus === true;
467
+ service = createService();
468
+ unsubscribe = service.subscribe(requestRender);
469
+ render();
470
+ // Zag appends its announcer to the document body synchronously at startup.
471
+ const lastChild = doc.body?.lastElementChild;
472
+ service.start();
473
+ const liveRegion = doc.body?.lastElementChild;
474
+ if (liveRegion !== lastChild && liveRegion?.matches('span[data-live-announcer="true"]')) {
475
+ styleScope.mark(liveRegion);
476
+ }
477
+ if (mode === 'range' && current.length === 1)
478
+ service.service.context.set('activeIndex', 1);
479
+ }
480
+ else {
481
+ const changed = signature !== previousExternal && signature !== undefined;
482
+ const projected = changed ? nextValues : picker ? current.map(constrain) : current;
483
+ const externalSelection = keyOf(current) !== keyOf(projected);
484
+ current = projected;
485
+ let nextFocus = placeholder !== previousPlaceholder ? date(placeholder) : externalSelection ? selectionFocus(projected) : undefined;
486
+ previousExternal = signature;
487
+ previousPlaceholder = placeholder;
488
+ service.updateProps({});
489
+ const api = getApi(service);
490
+ if (picker && !nextFocus) {
491
+ const boundedFocus = constrain(api.focusedValue);
492
+ if (boundedFocus.compare(api.focusedValue) !== 0)
493
+ nextFocus = boundedFocus;
494
+ }
495
+ if ((changed || externalSelection) && mode === 'range')
496
+ service.service.context.set('activeIndex', current.length === 1 ? 1 : 0);
497
+ if (nextFocus) {
498
+ silentFocus = publishedPlaceholder = iso(nextFocus);
499
+ api.setFocusedValue(nextFocus);
500
+ }
501
+ render();
502
+ }
503
+ },
504
+ dispose() {
505
+ closed = true;
506
+ view.clearTimeout(pickerCloseTimer);
507
+ unsubscribe?.();
508
+ service?.stop();
509
+ removeBindings();
510
+ },
511
+ };
512
+ }
@@ -0,0 +1,2 @@
1
+ export type Markup = readonly [tag: keyof HTMLElementTagNameMap, className: string, attrs?: Record<string, string>];
2
+ export declare const dynamicCatalog: Record<string, Markup>;
@@ -0,0 +1,118 @@
1
+ export const dynamicCatalog = {
2
+ 'Calendar.Root': ['div', ''],
3
+ 'RangeCalendar.Root': ['div', ''],
4
+ DatePicker: ['div', ''],
5
+ DataTable: ['div', 'vs-data-table'],
6
+ 'Accordion.Root': ['div', 'accordion'],
7
+ 'Accordion.Item': ['details', ''],
8
+ 'Accordion.Trigger': ['summary', ''],
9
+ 'Accordion.Content': ['section', ''],
10
+ 'Collapsible.Root': ['details', 'collapsible'],
11
+ 'Collapsible.Trigger': ['summary', ''],
12
+ 'Collapsible.Content': ['div', ''],
13
+ Combobox: ['div', 'combobox'],
14
+ 'Command.Root': ['div', 'command'],
15
+ 'Command.Dialog': ['dialog', 'dialog'],
16
+ 'Command.Input': ['input', ''],
17
+ 'Command.List': ['div', '', { role: 'menu' }],
18
+ 'Command.Empty': ['p', '', { 'data-empty': '' }],
19
+ 'Command.Group': ['div', '', { role: 'group' }],
20
+ 'Command.Item': ['button', '', { role: 'menuitem' }],
21
+ 'Command.LinkItem': ['a', '', { role: 'menuitem' }],
22
+ 'Command.Loading': ['p', ''],
23
+ 'Command.Separator': ['hr', '', { role: 'separator' }],
24
+ 'Command.Shortcut': ['span', '', { 'data-shortcut': '' }],
25
+ 'Popover.Root': ['div', 'popover'],
26
+ 'Popover.Trigger': ['button', 'btn', { 'aria-expanded': 'false' }],
27
+ 'Popover.Content': ['div', '', { 'data-popover': '', 'aria-hidden': 'true' }],
28
+ 'Popover.Close': ['button', 'btn'],
29
+ 'Popover.Description': ['p', ''],
30
+ 'Popover.Header': ['header', ''],
31
+ 'Popover.Portal': ['div', 'vs-ui-transparent'],
32
+ 'Popover.Title': ['h3', ''],
33
+ 'Select.Root': ['div', 'select'],
34
+ 'Select.Trigger': ['button', '', { 'aria-haspopup': 'listbox', 'aria-expanded': 'false' }],
35
+ 'Select.Value': ['span', ''],
36
+ 'Select.Content': ['div', '', { 'data-popover': '', 'aria-hidden': 'true' }],
37
+ 'Select.Group': ['div', '', { role: 'group' }],
38
+ 'Select.GroupHeading': ['div', '', { role: 'heading' }],
39
+ 'Select.Item': ['div', '', { role: 'option' }],
40
+ 'Select.Label': ['div', '', { role: 'heading' }],
41
+ 'Select.Portal': ['div', 'vs-ui-transparent'],
42
+ 'Select.Separator': ['hr', '', { role: 'separator' }],
43
+ 'Tabs.Root': ['div', 'tabs'],
44
+ 'Tabs.List': ['div', '', { role: 'tablist' }],
45
+ 'Tabs.Trigger': ['button', '', { role: 'tab', 'aria-selected': 'false' }],
46
+ 'Tabs.Content': ['div', '', { role: 'tabpanel' }],
47
+ 'Tooltip.Provider': ['div', 'vs-ui-transparent'],
48
+ 'Tooltip.Root': ['span', 'vs-ui-tooltip'],
49
+ 'Tooltip.Trigger': ['button', 'btn'],
50
+ 'Tooltip.Portal': ['div', 'vs-ui-transparent'],
51
+ 'Tooltip.Content': ['span', 'vs-ui-tooltip-content', { role: 'tooltip' }],
52
+ 'Sidebar.Provider': ['div', 'vs-ui-sidebar-provider'],
53
+ 'Sidebar.Root': ['aside', 'sidebar'],
54
+ 'Sidebar.Header': ['header', ''],
55
+ 'Sidebar.Content': ['section', ''],
56
+ 'Sidebar.Footer': ['footer', ''],
57
+ 'Sidebar.Group': ['section', '', { role: 'group' }],
58
+ 'Sidebar.GroupAction': ['button', 'btn', { 'data-variant': 'ghost', 'data-size': 'icon-sm' }],
59
+ 'Sidebar.GroupContent': ['div', ''],
60
+ 'Sidebar.GroupLabel': ['h3', ''],
61
+ 'Sidebar.Input': ['input', 'input'],
62
+ 'Sidebar.Inset': ['main', 'vs-ui-sidebar-inset'],
63
+ 'Sidebar.Menu': ['ul', ''],
64
+ 'Sidebar.MenuItem': ['li', ''],
65
+ 'Sidebar.MenuButton': ['button', ''],
66
+ 'Sidebar.MenuAction': ['button', 'btn', { 'data-variant': 'ghost', 'data-size': 'icon-sm' }],
67
+ 'Sidebar.MenuBadge': ['span', ''],
68
+ 'Sidebar.MenuSkeleton': ['div', 'skeleton'],
69
+ 'Sidebar.MenuSub': ['ul', ''],
70
+ 'Sidebar.MenuSubItem': ['li', ''],
71
+ 'Sidebar.MenuSubButton': ['a', ''],
72
+ 'Sidebar.Rail': ['button', '', { 'aria-label': 'Toggle Sidebar', tabindex: '-1' }],
73
+ 'Sidebar.Separator': ['hr', '', { role: 'separator' }],
74
+ 'Sidebar.Trigger': ['button', 'btn', { 'aria-label': 'Toggle Sidebar', 'data-variant': 'ghost', 'data-size': 'icon-sm' }],
75
+ Sonner: ['div', 'toaster vs-ui-toasts', { 'aria-live': 'polite' }],
76
+ Notifications: ['div', 'toaster vs-ui-toasts', { 'aria-live': 'polite' }],
77
+ 'Chart.Container': ['div', 'chart'],
78
+ Chart: ['div', 'chart'],
79
+ };
80
+ for (const family of ['Dialog', 'AlertDialog', 'Drawer', 'Sheet']) {
81
+ const prefix = family === 'Sheet' ? 'dialog vs-sheet' : family === 'Drawer' ? 'drawer' : family === 'AlertDialog' ? 'alert-dialog' : 'dialog';
82
+ const modal = {
83
+ Root: ['div', 'vs-ui-modal'],
84
+ Trigger: ['button', ''],
85
+ Close: ['button', ''],
86
+ Content: ['dialog', prefix, family === 'AlertDialog' ? { role: 'alertdialog' } : {}],
87
+ Header: ['header', ''],
88
+ Title: ['h2', ''],
89
+ Description: ['p', ''],
90
+ Footer: ['footer', ''],
91
+ Portal: ['div', 'vs-ui-transparent'],
92
+ Overlay: ['span', 'vs-ui-modal-overlay', { hidden: '' }],
93
+ };
94
+ if (family === 'AlertDialog') {
95
+ delete modal.Close;
96
+ modal.Action = ['button', 'btn'];
97
+ modal.Cancel = ['button', 'btn', { 'data-variant': 'outline' }];
98
+ modal.Media = ['figure', ''];
99
+ }
100
+ if (family === 'Drawer')
101
+ modal.NestedRoot = ['div', 'vs-ui-modal'];
102
+ for (const [part, markup] of Object.entries(modal))
103
+ dynamicCatalog[`${family}.${part}`] = markup;
104
+ }
105
+ Object.assign(dynamicCatalog, {
106
+ 'Pagination.Root': ['nav', 'vs-ui-pagination', { 'aria-label': 'Pagination' }],
107
+ 'Pagination.Content': ['ul', 'vs-ui-pagination-list'],
108
+ 'Pagination.Item': ['li', ''],
109
+ 'Pagination.Link': ['button', 'btn', { 'data-variant': 'ghost', 'data-size': 'icon' }],
110
+ 'Pagination.Ellipsis': ['span', '', { 'aria-hidden': 'true' }],
111
+ 'Pagination.Next': ['button', 'btn', { 'data-variant': 'ghost', 'aria-label': 'Go to next page' }],
112
+ 'Pagination.NextButton': ['button', 'btn', { 'data-variant': 'ghost', 'aria-label': 'Go to next page' }],
113
+ 'Pagination.Previous': ['button', 'btn', { 'data-variant': 'ghost', 'aria-label': 'Go to previous page' }],
114
+ 'Pagination.PrevButton': ['button', 'btn', { 'data-variant': 'ghost', 'aria-label': 'Go to previous page' }],
115
+ Separator: ['hr', 'vs-ui-separator'],
116
+ Spinner: ['span', 'vs-ui-spinner', { role: 'status' }],
117
+ 'Kbd.Group': ['span', 'vs-ui-kbd-group'],
118
+ });
@@ -0,0 +1,7 @@
1
+ import { type Behavior, type Send } from './behaviors.js';
2
+ import type { Markup } from './dynamic-catalog.js';
3
+ export declare const formScrollCatalog: Record<string, Markup>;
4
+ export declare const formScrollPorts: Record<string, string>;
5
+ export declare const formScrollEvents: Record<string, string>;
6
+ export declare function formScrollHost(name: string, control: HTMLElement): HTMLElement | undefined;
7
+ export declare function formScrollBehavior(name: string, element: HTMLElement, send: Send, signal: AbortSignal): Behavior | undefined;