@viewstem/ui 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.ko.md +47 -0
- package/README.md +60 -2
- package/dist/BASECOAT-LICENSE.md +21 -0
- package/dist/basecoat-contracts.d.ts +2 -0
- package/dist/basecoat-contracts.js +358 -0
- package/dist/basecoat-controllers.js +1612 -0
- package/dist/behaviors.d.ts +29 -0
- package/dist/behaviors.js +1475 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +2 -0
- package/dist/catalog-meta.d.ts +26 -0
- package/dist/catalog-meta.js +130 -0
- package/dist/component-context.d.ts +7 -0
- package/dist/component-context.js +10 -0
- package/dist/components.d.ts +2 -0
- package/dist/components.js +536 -0
- package/dist/data-table.d.ts +2 -0
- package/dist/data-table.js +260 -0
- package/dist/date-calendar.d.ts +4 -0
- package/dist/date-calendar.js +512 -0
- package/dist/dynamic-catalog.d.ts +2 -0
- package/dist/dynamic-catalog.js +118 -0
- package/dist/form-scroll-families.d.ts +7 -0
- package/dist/form-scroll-families.js +895 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -0
- package/dist/markup-families.d.ts +10 -0
- package/dist/markup-families.js +492 -0
- package/dist/menus.d.ts +8 -0
- package/dist/menus.js +427 -0
- package/dist/shadcn.d.ts +13 -0
- package/dist/shadcn.js +8 -0
- package/dist/slider-values.d.ts +9 -0
- package/dist/slider-values.js +43 -0
- package/dist/slider.d.ts +2 -0
- package/dist/slider.js +148 -0
- package/dist/static-catalog.d.ts +2 -0
- package/dist/static-catalog.js +87 -0
- package/dist/style-scope.d.ts +2 -0
- package/dist/style-scope.js +3 -0
- package/dist/styles.css +9573 -0
- package/dist/styles.css.d.ts +1 -0
- package/dist/support.json +1 -0
- package/dist/widget-families.d.ts +6 -0
- package/dist/widget-families.js +739 -0
- package/package.json +59 -4
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { attributes, components, domEvents, support } from './shadcn.js';
|
|
2
|
+
import { chart, combobox, command, commandDialog, disclosure, group, modal, notifications, popover, range, scopeChartColor, select, tabs, tooltip, uniqueId } from './behaviors.js';
|
|
3
|
+
import { dateCalendar } from './date-calendar.js';
|
|
4
|
+
import { multiSlider } from './slider.js';
|
|
5
|
+
import { dataTable } from './data-table.js';
|
|
6
|
+
import { bindComponent, emitFrom, readInputs } from './component-context.js';
|
|
7
|
+
import { menus } from './menus.js';
|
|
8
|
+
import { markupBehavior, markupTag } from './markup-families.js';
|
|
9
|
+
import { widgetBehavior } from './widget-families.js';
|
|
10
|
+
import { formScrollBehavior, formScrollHost } from './form-scroll-families.js';
|
|
11
|
+
import { styleScope } from './style-scope.js';
|
|
12
|
+
const contracts = new Map(support.map(spec => [spec.id, spec]));
|
|
13
|
+
const detailsGroup = new Set(['RadioGroup.Root', 'Pagination.Root', 'Sidebar.Provider']);
|
|
14
|
+
const modalRoots = /^(?:Dialog|AlertDialog|Drawer|Sheet)\.(?:Root|NestedRoot)$/;
|
|
15
|
+
const modalParts = /^(?:Dialog|AlertDialog|Drawer|Sheet)\.(Trigger|Close|Content|Title|Description|Action|Cancel|Overlay)$/;
|
|
16
|
+
const labelledMenuParts = /^(?:Command\.(?:Item|LinkItem)|(?:ContextMenu|DropdownMenu|Menubar)\.Item)$/;
|
|
17
|
+
function domEvent(event, target) {
|
|
18
|
+
const payload = { type: event.type };
|
|
19
|
+
for (const key of ['value', 'checked']) {
|
|
20
|
+
const value = target[key];
|
|
21
|
+
if (typeof value === 'boolean' || typeof value === 'string')
|
|
22
|
+
payload[key] = value;
|
|
23
|
+
}
|
|
24
|
+
const source = event;
|
|
25
|
+
for (const key of ['key', 'code', 'button', 'buttons', 'altKey', 'ctrlKey', 'metaKey', 'shiftKey']) {
|
|
26
|
+
const value = source[key];
|
|
27
|
+
if (typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number')
|
|
28
|
+
payload[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return payload;
|
|
31
|
+
}
|
|
32
|
+
function setAttribute(element, key, value, fallback) {
|
|
33
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
34
|
+
const boolean = ['disabled', 'required', 'readonly', 'multiple', 'hidden', 'inert', 'selected'];
|
|
35
|
+
if (boolean.includes(key) && typeof value === 'boolean')
|
|
36
|
+
element.toggleAttribute(key, value);
|
|
37
|
+
else if (element.getAttribute(key) !== String(value))
|
|
38
|
+
element.setAttribute(key, String(value));
|
|
39
|
+
}
|
|
40
|
+
else if (fallback !== undefined)
|
|
41
|
+
element.setAttribute(key, fallback);
|
|
42
|
+
else if (element.hasAttribute(key))
|
|
43
|
+
element.removeAttribute(key);
|
|
44
|
+
}
|
|
45
|
+
function safeUrl(element, value, allowCsvDownload = false) {
|
|
46
|
+
if (typeof value !== 'string')
|
|
47
|
+
return undefined;
|
|
48
|
+
try {
|
|
49
|
+
if (allowCsvDownload && /^data:text\/csv(?:;charset=utf-8)?(?:;base64)?,/i.test(value))
|
|
50
|
+
return value;
|
|
51
|
+
const protocol = new URL(value, element.ownerDocument.baseURI).protocol;
|
|
52
|
+
return ['http:', 'https:', 'mailto:', 'tel:', 'blob:'].includes(protocol) ? value : undefined;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function disposeEntry(entry) {
|
|
59
|
+
entry.events.abort();
|
|
60
|
+
entry.behavior?.dispose?.();
|
|
61
|
+
entry.element.remove();
|
|
62
|
+
}
|
|
63
|
+
function behavior(name, element, send, signal) {
|
|
64
|
+
if (name === 'Calendar.Root' || name === 'RangeCalendar.Root' || name === 'DatePicker')
|
|
65
|
+
return dateCalendar(element, name, send, signal);
|
|
66
|
+
if (name === 'DataTable')
|
|
67
|
+
return dataTable(element, send, signal);
|
|
68
|
+
if (modalRoots.test(name))
|
|
69
|
+
return modal(element, send, signal);
|
|
70
|
+
if (name === 'Accordion.Root' || name === 'Collapsible.Root')
|
|
71
|
+
return disclosure(element, name, send, signal);
|
|
72
|
+
if (name === 'Tabs.Root')
|
|
73
|
+
return tabs(element, send, signal);
|
|
74
|
+
if (name === 'Select.Root')
|
|
75
|
+
return select(element, send, signal);
|
|
76
|
+
if (name === 'Popover.Root')
|
|
77
|
+
return popover(element, send, signal);
|
|
78
|
+
if (name === 'DropdownMenu.Root' || name === 'ContextMenu.Root' || name === 'Menubar.Root') {
|
|
79
|
+
const family = name.slice(0, -5);
|
|
80
|
+
return menus(element, family, send, signal);
|
|
81
|
+
}
|
|
82
|
+
if (name === 'Tooltip.Root')
|
|
83
|
+
return tooltip(element, send, signal);
|
|
84
|
+
if (name === 'Combobox')
|
|
85
|
+
return combobox(element, send, signal);
|
|
86
|
+
if (name === 'Command.Root')
|
|
87
|
+
return command(element, send, signal);
|
|
88
|
+
if (name === 'Slider')
|
|
89
|
+
return element.localName === 'input'
|
|
90
|
+
? range(element, send, signal) : multiSlider(element, send, signal);
|
|
91
|
+
if (detailsGroup.has(name))
|
|
92
|
+
return group(element, name, send, signal);
|
|
93
|
+
if (name === 'Notifications')
|
|
94
|
+
return notifications(element, send);
|
|
95
|
+
if (name === 'Chart')
|
|
96
|
+
return chart(element);
|
|
97
|
+
return markupBehavior(name, element, send, signal) ??
|
|
98
|
+
widgetBehavior(name, element, send, signal) ??
|
|
99
|
+
formScrollBehavior(name, element, send, signal);
|
|
100
|
+
}
|
|
101
|
+
export function catalogComponent(name) {
|
|
102
|
+
return { mount(context) {
|
|
103
|
+
const doc = context.parent.ownerDocument;
|
|
104
|
+
function createEntry(node) {
|
|
105
|
+
const definition = components.get(name);
|
|
106
|
+
const markup = name === 'Slider' && node.inputs.type === 'multiple'
|
|
107
|
+
? ['div', 'vs-slider-group', { role: 'group' }]
|
|
108
|
+
: definition ?? ['div', ''];
|
|
109
|
+
const tag = markupTag(name, node.inputs) ?? markup[0];
|
|
110
|
+
const defaults = markup[2];
|
|
111
|
+
const part = modalParts.exec(name)?.[1]?.toLowerCase();
|
|
112
|
+
const childAction = !!node.slots.child?.length && !!part;
|
|
113
|
+
const childTrigger = !!node.slots.child?.length && (/^(?:DropdownMenu|HoverCard|Tooltip|Popover)\.Trigger$/.test(name) || name === 'Popover.Close');
|
|
114
|
+
const control = styleScope.createElement(doc, childAction || childTrigger ? 'span' : tag);
|
|
115
|
+
if (defaults)
|
|
116
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
117
|
+
if (name !== 'Button' || tag !== 'a' || key !== 'type')
|
|
118
|
+
control.setAttribute(key, value);
|
|
119
|
+
}
|
|
120
|
+
let element = control;
|
|
121
|
+
let host = formScrollHost(name, control) ?? control;
|
|
122
|
+
if (name === 'Carousel.Content' || name === 'HoverCard.Content' || name === 'AspectRatio') {
|
|
123
|
+
element = styleScope.createElement(doc, 'div');
|
|
124
|
+
element.className = name === 'Carousel.Content' ? 'vs-carousel-viewport' : name === 'HoverCard.Content' ? 'vs-hover-positioner' : 'vs-ui-aspect-frame';
|
|
125
|
+
element.append(control);
|
|
126
|
+
}
|
|
127
|
+
else if (name === 'CodeBlock.Content') {
|
|
128
|
+
host = styleScope.createElement(doc, 'code');
|
|
129
|
+
control.append(host);
|
|
130
|
+
}
|
|
131
|
+
else if (name === 'Command.Input') {
|
|
132
|
+
element = styleScope.createElement(doc, 'header');
|
|
133
|
+
element.append(control);
|
|
134
|
+
}
|
|
135
|
+
else if (name === 'Table.Root') {
|
|
136
|
+
element = styleScope.createElement(doc, 'div');
|
|
137
|
+
element.className = 'table-container';
|
|
138
|
+
element.append(control);
|
|
139
|
+
}
|
|
140
|
+
else if (tag === 'dialog') {
|
|
141
|
+
host = styleScope.createElement(doc, 'div');
|
|
142
|
+
control.append(host);
|
|
143
|
+
}
|
|
144
|
+
else if (name === 'Sidebar.Root') {
|
|
145
|
+
host = styleScope.createElement(doc, 'nav');
|
|
146
|
+
control.append(host);
|
|
147
|
+
}
|
|
148
|
+
else if (name === 'Field.Separator' || name === 'Command.Group') {
|
|
149
|
+
host = styleScope.createElement(doc, name === 'Field.Separator' ? 'span' : 'div');
|
|
150
|
+
control.append(host);
|
|
151
|
+
}
|
|
152
|
+
else if (/^(?:DropdownMenu|ContextMenu|Menubar)\.(?:Sub)?Content$/.test(name)) {
|
|
153
|
+
element = styleScope.createElement(doc, 'div');
|
|
154
|
+
element.dataset.vsMenuPositioner = '';
|
|
155
|
+
control.setAttribute('aria-hidden', 'true');
|
|
156
|
+
element.append(control);
|
|
157
|
+
}
|
|
158
|
+
else if (name === 'Select.Content') {
|
|
159
|
+
host = styleScope.createElement(doc, 'div');
|
|
160
|
+
host.setAttribute('role', 'listbox');
|
|
161
|
+
control.append(host);
|
|
162
|
+
}
|
|
163
|
+
if (childAction || childTrigger)
|
|
164
|
+
control.className = 'vs-ui-transparent';
|
|
165
|
+
control.dataset.vsComponent = name;
|
|
166
|
+
control.dataset.vsPart = !definition ? 'group' : name === 'Card.Root' ? 'card' : name.startsWith('Card.') ? name.replace('Card.', 'card-').toLowerCase() : modalRoots.test(name) ? 'dialog-root' : part ? 'dialog-' + part : name.split('.').at(-1).toLowerCase();
|
|
167
|
+
if (part === 'trigger')
|
|
168
|
+
control.dataset.vsModalAction = 'open';
|
|
169
|
+
if (part === 'close' || part === 'cancel')
|
|
170
|
+
control.dataset.vsModalAction = 'close';
|
|
171
|
+
const label = doc.createTextNode('');
|
|
172
|
+
if (!['input', 'img', 'hr'].includes(tag))
|
|
173
|
+
host.prepend(label);
|
|
174
|
+
const entry = { node, name, element, control, host, label, markup, composing: false, events: new AbortController() };
|
|
175
|
+
const { signal } = entry.events;
|
|
176
|
+
if (name === 'Avatar.Image') {
|
|
177
|
+
let pendingStatus;
|
|
178
|
+
const reportImageStatus = (status) => {
|
|
179
|
+
pendingStatus?.disconnect();
|
|
180
|
+
control.toggleAttribute('data-vs-loaded', status === 'loaded');
|
|
181
|
+
const avatar = control.closest('[data-vs-component="Avatar.Root"]');
|
|
182
|
+
if (!avatar)
|
|
183
|
+
return;
|
|
184
|
+
const hover = avatar.closest('[data-vs-component="HoverCard.Content"]');
|
|
185
|
+
const src = control.getAttribute('src');
|
|
186
|
+
const publish = () => {
|
|
187
|
+
if (control.getAttribute('src') === src)
|
|
188
|
+
emitFrom(avatar, 'loadingStatusChange', { value: status });
|
|
189
|
+
};
|
|
190
|
+
if (!hover || hover.dataset.state === 'open' || readInputs(hover).forceMount === true) {
|
|
191
|
+
publish();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
pendingStatus = new doc.defaultView.MutationObserver(() => {
|
|
195
|
+
if (hover.dataset.state !== 'open')
|
|
196
|
+
return;
|
|
197
|
+
pendingStatus?.disconnect();
|
|
198
|
+
publish();
|
|
199
|
+
});
|
|
200
|
+
pendingStatus.observe(hover, { attributes: true, attributeFilter: ['data-state'] });
|
|
201
|
+
};
|
|
202
|
+
signal.addEventListener('abort', () => pendingStatus?.disconnect(), { once: true });
|
|
203
|
+
control.addEventListener('load', () => reportImageStatus('loaded'), { signal });
|
|
204
|
+
control.addEventListener('error', () => reportImageStatus('error'), { signal });
|
|
205
|
+
}
|
|
206
|
+
const events = contracts.get(node.componentRef ?? '')?.events ?? {};
|
|
207
|
+
const send = (event, payload) => {
|
|
208
|
+
if (!Object.hasOwn(events, event))
|
|
209
|
+
return;
|
|
210
|
+
const source = entry.node;
|
|
211
|
+
// Controllers finish their native event stack before an Action can replace the DOM.
|
|
212
|
+
queueMicrotask(() => {
|
|
213
|
+
if (!signal.aborted && !context.signal.aborted && source.generation === entry.node.generation) {
|
|
214
|
+
void context.emit(event, payload).catch(() => { });
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
bindComponent(control, () => entry.node.inputs, send);
|
|
219
|
+
if (childAction || (childTrigger && name === 'Popover.Trigger'))
|
|
220
|
+
control.addEventListener('click', event => {
|
|
221
|
+
if (entry.node.inputs.disabled !== true)
|
|
222
|
+
return;
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
event.stopImmediatePropagation();
|
|
225
|
+
}, { capture: true, signal });
|
|
226
|
+
for (const [eventName, nativeName] of Object.entries(domEvents)) {
|
|
227
|
+
if (!Object.hasOwn(events, eventName))
|
|
228
|
+
continue;
|
|
229
|
+
control.addEventListener(nativeName, event => {
|
|
230
|
+
if (nativeName === 'submit')
|
|
231
|
+
event.preventDefault();
|
|
232
|
+
if (nativeName === 'input' && (entry.composing || event.isComposing))
|
|
233
|
+
return;
|
|
234
|
+
send(eventName, domEvent(event, control));
|
|
235
|
+
}, { signal });
|
|
236
|
+
}
|
|
237
|
+
if (Object.hasOwn(events, 'input') && ['input', 'textarea'].includes(tag)) {
|
|
238
|
+
control.addEventListener('compositionstart', () => { entry.composing = true; }, { signal });
|
|
239
|
+
control.addEventListener('compositionend', event => {
|
|
240
|
+
entry.composing = false;
|
|
241
|
+
send('input', { ...domEvent(event, control), type: 'input' });
|
|
242
|
+
}, { signal });
|
|
243
|
+
}
|
|
244
|
+
if (name === 'Checkbox' || name === 'Switch') {
|
|
245
|
+
const input = control;
|
|
246
|
+
input.addEventListener('change', () => {
|
|
247
|
+
send('checkedChange', { value: input.checked });
|
|
248
|
+
if (entry.node.inputs.indeterminate === true && !input.indeterminate)
|
|
249
|
+
send('indeterminateChange', { value: false });
|
|
250
|
+
}, { signal });
|
|
251
|
+
}
|
|
252
|
+
if (name === 'Collapsible.Trigger' && node.slots.child?.length) {
|
|
253
|
+
control.addEventListener('click', event => {
|
|
254
|
+
if (event.target.closest('button, a, input, select, textarea')) {
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
const details = control.closest('details');
|
|
257
|
+
if (details)
|
|
258
|
+
details.open = !details.open;
|
|
259
|
+
}
|
|
260
|
+
}, { signal });
|
|
261
|
+
}
|
|
262
|
+
if (name === 'InputGroup.Addon') {
|
|
263
|
+
control.addEventListener('click', event => {
|
|
264
|
+
if (!event.defaultPrevented && !event.target.closest('button, a[href]')) {
|
|
265
|
+
control.parentElement?.querySelector(':scope > input')?.focus();
|
|
266
|
+
}
|
|
267
|
+
}, { signal });
|
|
268
|
+
}
|
|
269
|
+
if (name === 'Command.Item' || name === 'Command.LinkItem') {
|
|
270
|
+
control.addEventListener('click', event => {
|
|
271
|
+
if (entry.node.inputs.disabled !== true) {
|
|
272
|
+
send('select', { value: null });
|
|
273
|
+
}
|
|
274
|
+
}, { signal });
|
|
275
|
+
}
|
|
276
|
+
if (name === 'Progress' || name === 'Field.Separator' || name === 'Command.Group') {
|
|
277
|
+
const auxiliary = styleScope.createElement(doc, name === 'Field.Separator' ? 'hr' : 'span');
|
|
278
|
+
if (name === 'Field.Separator')
|
|
279
|
+
auxiliary.setAttribute('role', 'separator');
|
|
280
|
+
if (name === 'Command.Group')
|
|
281
|
+
auxiliary.setAttribute('role', 'heading');
|
|
282
|
+
control.prepend(auxiliary);
|
|
283
|
+
entry.auxiliary = auxiliary;
|
|
284
|
+
}
|
|
285
|
+
if (name === 'Dialog.Content' || name === 'Sheet.Content') {
|
|
286
|
+
const close = styleScope.createElement(doc, 'button');
|
|
287
|
+
close.type = 'button';
|
|
288
|
+
close.className = 'btn vs-dialog-dismiss';
|
|
289
|
+
close.dataset.variant = 'ghost';
|
|
290
|
+
close.dataset.size = 'icon-sm';
|
|
291
|
+
close.dataset.vsModalAction = 'close';
|
|
292
|
+
close.setAttribute('aria-label', 'Close');
|
|
293
|
+
host.append(close);
|
|
294
|
+
entry.auxiliary = close;
|
|
295
|
+
}
|
|
296
|
+
if (name === 'Drawer.Content') {
|
|
297
|
+
const handle = styleScope.createElement(doc, 'div');
|
|
298
|
+
handle.className = 'vs-drawer-handle';
|
|
299
|
+
handle.setAttribute('aria-hidden', 'true');
|
|
300
|
+
host.append(handle);
|
|
301
|
+
}
|
|
302
|
+
const enhancement = name === 'Command.Dialog'
|
|
303
|
+
? commandDialog(control, host, send, signal)
|
|
304
|
+
: behavior(name, control, send, signal);
|
|
305
|
+
if (enhancement)
|
|
306
|
+
entry.behavior = enhancement;
|
|
307
|
+
return entry;
|
|
308
|
+
}
|
|
309
|
+
function update(entry, node) {
|
|
310
|
+
entry.node = node;
|
|
311
|
+
const { control, host, label, name, markup, auxiliary } = entry;
|
|
312
|
+
const { inputs } = node;
|
|
313
|
+
const descendants = components.has(name) ? node.slots.child?.length ? node.slots.child : node.slots.default ?? [] : node.children;
|
|
314
|
+
const defaultText = name === 'Breadcrumb.Ellipsis' || name === 'Pagination.Ellipsis' ? '…'
|
|
315
|
+
: name === 'Breadcrumb.Separator' ? '›'
|
|
316
|
+
: name === 'Pagination.NextButton' || name === 'Pagination.Next' ? 'Next'
|
|
317
|
+
: name === 'Pagination.PrevButton' || name === 'Pagination.Previous' ? 'Previous'
|
|
318
|
+
: name === 'Pagination.Link' && inputs.page && typeof inputs.page === 'object' && 'value' in inputs.page ? String(inputs.page.value)
|
|
319
|
+
: name === 'Select.Value' && typeof inputs.placeholder === 'string' ? inputs.placeholder : '';
|
|
320
|
+
const shortcutRef = labelledMenuParts.test(name) ? 'shadcn.' + name.split('.')[0] + '.Shortcut' : undefined;
|
|
321
|
+
const replacesLabel = descendants.length && (!shortcutRef || descendants.some(child => child.componentRef !== shortcutRef));
|
|
322
|
+
const content = replacesLabel ? ''
|
|
323
|
+
: typeof inputs.text === 'string' ? inputs.text : defaultText;
|
|
324
|
+
if (label.data !== content)
|
|
325
|
+
label.data = content;
|
|
326
|
+
const [, className, defaults] = markup;
|
|
327
|
+
const activeCommand = (name === 'Command.Item' || name === 'Command.LinkItem') && control.classList.contains('active');
|
|
328
|
+
const combined = [node.slots.child?.length && (modalParts.test(name) || (/^(?:DropdownMenu|HoverCard|Tooltip|Popover)\.Trigger$/.test(name) || name === 'Popover.Close')) ? 'vs-ui-transparent' : className,
|
|
329
|
+
inputs.class, activeCommand && 'active'].filter(Boolean).join(' ');
|
|
330
|
+
if (control.className !== combined)
|
|
331
|
+
control.className = combined;
|
|
332
|
+
const managed = [];
|
|
333
|
+
for (const key of attributes) {
|
|
334
|
+
if (key === 'class' || !Object.hasOwn(inputs, key))
|
|
335
|
+
continue;
|
|
336
|
+
managed.push(key);
|
|
337
|
+
const value = key === 'href' || key === 'src' ? safeUrl(control, inputs[key], name === 'Attachment.Action' && key === 'href' && (inputs.download === true || typeof inputs.download === 'string')) : inputs[key];
|
|
338
|
+
if (name === 'Avatar.Image' && key === 'src' && control.getAttribute('src') !== value)
|
|
339
|
+
delete control.dataset.vsLoaded;
|
|
340
|
+
setAttribute(control, key, value, defaults?.[key]);
|
|
341
|
+
}
|
|
342
|
+
const nextManaged = managed.join(' '), previousManaged = control.dataset.vsManaged;
|
|
343
|
+
if (previousManaged !== nextManaged) {
|
|
344
|
+
for (const key of previousManaged?.split(' ') ?? []) {
|
|
345
|
+
if (key !== 'class' && attributes.has(key) && !Object.hasOwn(inputs, key)) {
|
|
346
|
+
setAttribute(control, key, undefined, defaults?.[key]);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
control.dataset.vsManaged = nextManaged;
|
|
350
|
+
}
|
|
351
|
+
if (control.localName === 'button') {
|
|
352
|
+
const button = control;
|
|
353
|
+
button.type = inputs.type === 'submit' || inputs.type === 'reset' ? inputs.type : 'button';
|
|
354
|
+
if (control.dataset.vsModalAction === 'open')
|
|
355
|
+
button.setAttribute('aria-haspopup', 'dialog');
|
|
356
|
+
}
|
|
357
|
+
for (const key of ['variant', 'size', 'orientation', 'align']) {
|
|
358
|
+
const value = key === 'variant' && inputs.variant === 'default' && (name === 'Button' || name === 'InputGroup.Button') ? 'primary'
|
|
359
|
+
: key === 'size' && inputs.size === 'default' ? undefined : inputs[key];
|
|
360
|
+
setAttribute(control, 'data-' + key, value, defaults?.['data-' + key]);
|
|
361
|
+
}
|
|
362
|
+
if (typeof inputs.value === 'string' && !['input', 'select', 'textarea', 'option'].includes(control.localName)) {
|
|
363
|
+
control.dataset.value = inputs.value;
|
|
364
|
+
}
|
|
365
|
+
else
|
|
366
|
+
delete control.dataset.value;
|
|
367
|
+
if (name === 'Select.Item')
|
|
368
|
+
setAttribute(control, 'data-label', inputs.label);
|
|
369
|
+
if (name === 'Command.Item' || name === 'Command.LinkItem') {
|
|
370
|
+
setAttribute(control, 'data-keywords', Array.isArray(inputs.keywords) ? inputs.keywords.join(',') : undefined);
|
|
371
|
+
}
|
|
372
|
+
if (name === 'Command.Group' && auxiliary) {
|
|
373
|
+
auxiliary.textContent = typeof inputs.heading === 'string' ? inputs.heading : '';
|
|
374
|
+
auxiliary.hidden = !auxiliary.textContent;
|
|
375
|
+
}
|
|
376
|
+
if (name === 'Sidebar.MenuButton' || name === 'Sidebar.MenuSubButton') {
|
|
377
|
+
setAttribute(control, 'data-active', inputs.isActive);
|
|
378
|
+
}
|
|
379
|
+
if (typeof inputs.disabled === 'boolean' && ['summary', 'details', 'div'].includes(control.localName)) {
|
|
380
|
+
control.setAttribute('aria-disabled', String(inputs.disabled));
|
|
381
|
+
}
|
|
382
|
+
if (control.localName === 'span' && (control.dataset.vsModalAction || name === 'Popover.Trigger')) {
|
|
383
|
+
control.inert = inputs.disabled === true || inputs.inert === true;
|
|
384
|
+
if (inputs.disabled === true)
|
|
385
|
+
control.setAttribute('aria-disabled', 'true');
|
|
386
|
+
else if (inputs['aria-disabled'] === undefined)
|
|
387
|
+
control.removeAttribute('aria-disabled');
|
|
388
|
+
}
|
|
389
|
+
const fieldValue = inputs.value === null ? '' : typeof inputs.value === 'number' ? String(inputs.value) : inputs.value;
|
|
390
|
+
if (control.localName === 'input') {
|
|
391
|
+
const input = control;
|
|
392
|
+
if (name === 'Checkbox' || name === 'Switch' || name === 'RadioGroup.Item') {
|
|
393
|
+
if (typeof inputs.checked === 'boolean')
|
|
394
|
+
input.checked = inputs.checked;
|
|
395
|
+
if (name === 'Checkbox')
|
|
396
|
+
input.indeterminate = inputs.indeterminate === true;
|
|
397
|
+
setAttribute(input, 'value', inputs.value);
|
|
398
|
+
}
|
|
399
|
+
else if (name !== 'Slider') {
|
|
400
|
+
const type = typeof inputs.type === 'string' ? inputs.type : 'text';
|
|
401
|
+
if (input.type !== type)
|
|
402
|
+
input.type = type;
|
|
403
|
+
if (!entry.composing && typeof fieldValue === 'string' && input.value !== fieldValue && type !== 'file')
|
|
404
|
+
input.value = fieldValue;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (control.localName === 'textarea' && !entry.composing && typeof fieldValue === 'string') {
|
|
408
|
+
const textarea = control;
|
|
409
|
+
if (textarea.value !== fieldValue)
|
|
410
|
+
textarea.value = fieldValue;
|
|
411
|
+
}
|
|
412
|
+
if (control.localName === 'option') {
|
|
413
|
+
setAttribute(control, 'value', inputs.value);
|
|
414
|
+
setAttribute(control, 'selected', inputs.selected);
|
|
415
|
+
}
|
|
416
|
+
if (name === 'Card.Title' || name.endsWith('Dialog.Title') || name === 'Drawer.Title')
|
|
417
|
+
control.dataset.title = '';
|
|
418
|
+
if (name === 'Card.Description' || name.endsWith('Dialog.Description') || name === 'Drawer.Description')
|
|
419
|
+
control.dataset.description = '';
|
|
420
|
+
if (name === 'Pagination.Link' && inputs.page && typeof inputs.page === 'object') {
|
|
421
|
+
control.dataset.vsPage = String(inputs.page.value);
|
|
422
|
+
}
|
|
423
|
+
if (/^Pagination\.(Next|Prev)/.test(name))
|
|
424
|
+
control.dataset.vsPage ||= '1';
|
|
425
|
+
if (name === 'Separator') {
|
|
426
|
+
setAttribute(control, 'role', inputs.decorative === false ? 'separator' : 'none');
|
|
427
|
+
}
|
|
428
|
+
if (name === 'Sonner' || name === 'Notifications')
|
|
429
|
+
setAttribute(control, 'aria-label', inputs.containerAriaLabel);
|
|
430
|
+
if (name === 'Sidebar.Root')
|
|
431
|
+
setAttribute(control, 'data-collapsible', inputs.collapsible);
|
|
432
|
+
if (name === 'Field.Separator')
|
|
433
|
+
host.hidden = !content && !descendants.length;
|
|
434
|
+
if ((name === 'Dialog.Content' || name === 'Sheet.Content') && auxiliary)
|
|
435
|
+
auxiliary.hidden = inputs.showCloseButton === false;
|
|
436
|
+
if (name === 'Sheet.Content')
|
|
437
|
+
control.dataset.side = typeof inputs.side === 'string' ? inputs.side : 'right';
|
|
438
|
+
if (name === 'Progress' && auxiliary) {
|
|
439
|
+
const value = Number(inputs.value ?? 0);
|
|
440
|
+
const max = Number(inputs.max ?? 100);
|
|
441
|
+
setAttribute(control, 'aria-valuemax', max);
|
|
442
|
+
setAttribute(control, 'aria-valuenow', value);
|
|
443
|
+
auxiliary.style.width = `${Math.max(0, Math.min(100, value / (max || 1) * 100))}%`;
|
|
444
|
+
}
|
|
445
|
+
if (name === 'Chart.Container' && inputs.config && typeof inputs.config === 'object') {
|
|
446
|
+
const config = inputs.config;
|
|
447
|
+
for (const key of Array.from(control.style))
|
|
448
|
+
if (key.startsWith('--color-'))
|
|
449
|
+
control.style.removeProperty(key);
|
|
450
|
+
for (const [key, { color }] of Object.entries(config)) {
|
|
451
|
+
if (/^[\w-]+$/.test(key) && color && doc.defaultView?.CSS.supports('color', color)) {
|
|
452
|
+
control.style.setProperty('--color-' + key, scopeChartColor(color));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function afterChildren(entry) {
|
|
458
|
+
const { control, name, node: { inputs } } = entry;
|
|
459
|
+
if (name === 'Tooltip.Root') {
|
|
460
|
+
const trigger = control.querySelector('[data-vs-component="Tooltip.Trigger"]');
|
|
461
|
+
const tooltip = control.querySelector('[data-vs-component="Tooltip.Content"]');
|
|
462
|
+
if (trigger && tooltip) {
|
|
463
|
+
tooltip.id ||= uniqueId();
|
|
464
|
+
(trigger.classList.contains('vs-ui-transparent') ? trigger.querySelector(':scope > *') ?? trigger : trigger).setAttribute('aria-describedby', tooltip.id);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (name === 'NativeSelect.Root' && inputs.value !== undefined) {
|
|
468
|
+
const select = control;
|
|
469
|
+
const values = (Array.isArray(inputs.value) ? inputs.value : [inputs.value])
|
|
470
|
+
.filter(value => typeof value === 'string' || typeof value === 'number').map(String);
|
|
471
|
+
if (select.multiple) {
|
|
472
|
+
for (const option of select.options)
|
|
473
|
+
option.selected = values.includes(option.value);
|
|
474
|
+
}
|
|
475
|
+
else
|
|
476
|
+
select.selectedIndex = Array.from(select.options).findIndex(option => values.includes(option.value));
|
|
477
|
+
}
|
|
478
|
+
entry.behavior?.sync(inputs);
|
|
479
|
+
}
|
|
480
|
+
let entry;
|
|
481
|
+
let withdraw;
|
|
482
|
+
let slotName;
|
|
483
|
+
const release = () => {
|
|
484
|
+
withdraw?.();
|
|
485
|
+
withdraw = undefined;
|
|
486
|
+
slotName = undefined;
|
|
487
|
+
if (entry)
|
|
488
|
+
disposeEntry(entry);
|
|
489
|
+
entry = undefined;
|
|
490
|
+
};
|
|
491
|
+
function render(node) {
|
|
492
|
+
if (/\.Portal$/.test(name)) {
|
|
493
|
+
if (!withdraw && Object.hasOwn(node.slots, 'default'))
|
|
494
|
+
withdraw = context.provideSlot('default', context.parent);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const nextTag = markupTag(name, node.inputs);
|
|
498
|
+
if (entry && (!!entry.node.slots.child?.length !== !!node.slots.child?.length
|
|
499
|
+
|| (nextTag !== undefined && !entry.node.slots.child?.length && entry.control.localName !== nextTag)))
|
|
500
|
+
release();
|
|
501
|
+
if (!entry) {
|
|
502
|
+
entry = createEntry(node);
|
|
503
|
+
context.parent.insertBefore(entry.element, context.anchor);
|
|
504
|
+
}
|
|
505
|
+
const nextSlot = node.slots.child?.length ? 'child'
|
|
506
|
+
: Object.hasOwn(node.slots, 'default') ? 'default' : undefined;
|
|
507
|
+
if (slotName !== nextSlot) {
|
|
508
|
+
withdraw?.();
|
|
509
|
+
slotName = nextSlot;
|
|
510
|
+
withdraw = nextSlot === undefined ? undefined : context.provideSlot(nextSlot, entry.host, entry.host.firstElementChild);
|
|
511
|
+
}
|
|
512
|
+
update(entry, node);
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
render(context.node);
|
|
516
|
+
}
|
|
517
|
+
catch (cause) {
|
|
518
|
+
release();
|
|
519
|
+
throw cause;
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
update: render,
|
|
523
|
+
setPending(pending) {
|
|
524
|
+
if (!entry)
|
|
525
|
+
return;
|
|
526
|
+
if (pending)
|
|
527
|
+
entry.element.setAttribute('aria-busy', 'true');
|
|
528
|
+
else
|
|
529
|
+
entry.element.removeAttribute('aria-busy');
|
|
530
|
+
},
|
|
531
|
+
afterChildren() { if (entry)
|
|
532
|
+
afterChildren(entry); },
|
|
533
|
+
dispose: release,
|
|
534
|
+
};
|
|
535
|
+
} };
|
|
536
|
+
}
|