@getdom/studio 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.
- package/LICENSE.md +109 -0
- package/README.md +44 -0
- package/SKILL.md +83 -0
- package/package.json +73 -0
- package/public/llms.txt +57 -0
- package/public/skills.sh +11 -0
- package/src/pages/_layout/componentCatalog.generated.js +4514 -0
- package/src/pages/_layout/componentInspector.js +60 -0
- package/src/pages/_layout/componentManager.js +192 -0
- package/src/pages/_layout/componentRuntimeRecords.js +49 -0
- package/src/pages/_layout/inspector/componentRegistry.js +639 -0
- package/src/pages/_layout/inspector/serialize.js +134 -0
- package/src/pages/_layout/inspector/useInspector.js +293 -0
- package/src/pages/components/accordion/DomAccordion.vue +39 -0
- package/src/pages/components/breadcrumbs/DomBreadcrumbs.vue +347 -0
- package/src/pages/components/button/DomButton.vue +132 -0
- package/src/pages/components/command-palette/DomCommandPalette.vue +482 -0
- package/src/pages/components/context-menu/DomContextMenu.vue +178 -0
- package/src/pages/components/dialog/DomDialog.vue +271 -0
- package/src/pages/components/dialog/DomDialogSchemaForm.vue +72 -0
- package/src/pages/components/dialog/DomDialogStack.vue +289 -0
- package/src/pages/components/dialog/useDialogs.js +253 -0
- package/src/pages/components/drawer/DomDrawer.vue +159 -0
- package/src/pages/components/dropdown/DomDropdown.vue +261 -0
- package/src/pages/components/icon-button/DomIconButton.vue +155 -0
- package/src/pages/components/lightbox/DomLightbox.vue +1561 -0
- package/src/pages/components/menu/DomMenu.vue +359 -0
- package/src/pages/components/menu/DomMenuItem.vue +233 -0
- package/src/pages/components/menu/DomMenuLabel.vue +19 -0
- package/src/pages/components/menu/DomMenuSeparator.vue +14 -0
- package/src/pages/components/menu/menuContext.js +11 -0
- package/src/pages/components/menu/menuPlacement.js +26 -0
- package/src/pages/components/menu/submenu.js +58 -0
- package/src/pages/components/pagination/DomPagination.vue +265 -0
- package/src/pages/components/playground/DomRenderer.vue +48 -0
- package/src/pages/components/popover/DomPopover.vue +244 -0
- package/src/pages/components/profile-menu/DomProfileMenu.vue +408 -0
- package/src/pages/components/profile-menu/DomProfileMenuItemContent.vue +45 -0
- package/src/pages/components/scroll-menu/DomScrollMenu.vue +430 -0
- package/src/pages/components/scroll-menu/DomScrollMenuItem.vue +212 -0
- package/src/pages/components/scroll-menu/scrollMenuContext.js +22 -0
- package/src/pages/components/splitter-panel/DomSplitterPanel.vue +283 -0
- package/src/pages/components/stepper/DomStepper.vue +386 -0
- package/src/pages/components/tabs/DomTabs.vue +149 -0
- package/src/pages/components/theme-switcher/DomThemeSwitcher.vue +226 -0
- package/src/pages/components/toast/DomToastItem.vue +52 -0
- package/src/pages/components/toast/DomToastStack.vue +768 -0
- package/src/pages/components/toast/useToasts.js +237 -0
- package/src/pages/components/toolbar/DomToolbar.vue +158 -0
- package/src/pages/components/tooltip/DomTooltip.vue +69 -0
- package/src/pages/components/tooltip/vDomTooltip.js +106 -0
- package/src/pages/components/tree-view/DomTreeView.vue +961 -0
- package/src/pages/components/tree-view/treeSchemas.js +129 -0
- package/src/pages/components/tree-view/treeUtils.js +228 -0
- package/src/pages/data/_shared/calculateVirtualWindow.js +101 -0
- package/src/pages/data/_shared/resourceRecord.js +29 -0
- package/src/pages/data/activity-timeline/DomActivityTimeline.vue +417 -0
- package/src/pages/data/agent-chat/DomAgentChatShell.vue +565 -0
- package/src/pages/data/agent-chat/DomAgentConversation.vue +737 -0
- package/src/pages/data/agent-chat/DomAgentConversationList.vue +319 -0
- package/src/pages/data/agent-chat/examples/agentChatMockApi.js +620 -0
- package/src/pages/data/agent-chat/examples/useAgentChatDemoStore.js +730 -0
- package/src/pages/data/data-grid/DataGridVirtualRows.vue +220 -0
- package/src/pages/data/data-grid/DomDataGrid.vue +1643 -0
- package/src/pages/data/document-editor/DomDocumentEditor.vue +3030 -0
- package/src/pages/data/document-editor/documentEditorCodeBlock.js +282 -0
- package/src/pages/data/document-editor/examples/documentEditorMockApi.js +272 -0
- package/src/pages/data/document-editor/examples/useDocumentEditorDemoStore.js +284 -0
- package/src/pages/data/filter-bar/DomFilterBar.vue +533 -0
- package/src/pages/data/kanban/DomKanban.vue +1703 -0
- package/src/pages/data/kanban/kanbanApi.js +80 -0
- package/src/pages/data/media-browser/DomMediaBrowser.vue +2344 -0
- package/src/pages/data/media-browser/examples/mediaBrowserMockApi.js +653 -0
- package/src/pages/data/media-browser/examples/useMediaBrowserDemoStore.js +1157 -0
- package/src/pages/data/month-calendar/DomMonthCalendar.vue +1718 -0
- package/src/pages/data/week-planner/DomWeekPlanner.vue +2308 -0
- package/src/pages/dev/code-block/DomCodeBlock.vue +263 -0
- package/src/pages/dev/json-viewer/DomJsonViewer.vue +962 -0
- package/src/pages/forms/_shared/DomFieldLoadingSpinner.vue +12 -0
- package/src/pages/forms/_shared/options.js +61 -0
- package/src/pages/forms/_shared/useOptionMenu.js +59 -0
- package/src/pages/forms/autocomplete/DomAutocomplete.vue +180 -0
- package/src/pages/forms/calendar/DomCalendar.vue +442 -0
- package/src/pages/forms/checkbox/DomCheckbox.vue +69 -0
- package/src/pages/forms/class-toggle-input/DomClassToggleInput.vue +316 -0
- package/src/pages/forms/code-input/DomCodeInput.vue +202 -0
- package/src/pages/forms/color-input/DomColorInput.vue +118 -0
- package/src/pages/forms/combobox/DomCombobox.vue +237 -0
- package/src/pages/forms/confirmation-code-input/DomConfirmationCodeInput.vue +345 -0
- package/src/pages/forms/date-picker/DomDatePicker.vue +299 -0
- package/src/pages/forms/date-time-picker/DomDateTimePicker.vue +630 -0
- package/src/pages/forms/email-input/DomEmailInput.vue +55 -0
- package/src/pages/forms/field/DomField.vue +267 -0
- package/src/pages/forms/field/fieldLayout.js +1 -0
- package/src/pages/forms/field/fieldProps.js +114 -0
- package/src/pages/forms/field/layouts/DomGridFieldLayout.vue +38 -0
- package/src/pages/forms/field/useField.js +343 -0
- package/src/pages/forms/field/validators.js +364 -0
- package/src/pages/forms/file-upload/DomFileUpload.vue +361 -0
- package/src/pages/forms/form/DomForm.vue +985 -0
- package/src/pages/forms/form/adapters/fieldBuilder.js +45 -0
- package/src/pages/forms/form/adapters/jsonSchema.js +264 -0
- package/src/pages/forms/form/adapters/shared.js +53 -0
- package/src/pages/forms/form/adapters/zod.js +235 -0
- package/src/pages/forms/form/formApi.js +38 -0
- package/src/pages/forms/form/formDefinition.js +392 -0
- package/src/pages/forms/form/schemaAdapter.js +54 -0
- package/src/pages/forms/icon-selector/DomIconSelector.vue +460 -0
- package/src/pages/forms/icon-selector/iconSelectorItems.js +490 -0
- package/src/pages/forms/input-group/DomInputGroup.vue +232 -0
- package/src/pages/forms/json-input/DomJsonInput.vue +227 -0
- package/src/pages/forms/json-list-input/DomJsonListInput.vue +206 -0
- package/src/pages/forms/listbox/DomListbox.vue +105 -0
- package/src/pages/forms/money-input/DomMoneyInput.vue +147 -0
- package/src/pages/forms/native-select/DomNativeSelect.vue +67 -0
- package/src/pages/forms/number-input/DomNumberInput.vue +47 -0
- package/src/pages/forms/password-input/DomPasswordInput.vue +218 -0
- package/src/pages/forms/password-input/pwnedPasswords.js +47 -0
- package/src/pages/forms/password-strength/DomPasswordStrength.vue +128 -0
- package/src/pages/forms/password-strength/passwordStrength.js +92 -0
- package/src/pages/forms/position-input/DomPositionInput.vue +83 -0
- package/src/pages/forms/radio-group/DomRadioGroup.vue +102 -0
- package/src/pages/forms/range-input/DomRangeInput.vue +296 -0
- package/src/pages/forms/select/DomSelect.vue +479 -0
- package/src/pages/forms/select-input/DomSelectInput.vue +155 -0
- package/src/pages/forms/tag-combobox/DomTagCombobox.vue +358 -0
- package/src/pages/forms/text-input/DomTextInput.vue +48 -0
- package/src/pages/forms/textarea-composer/DomTextareaComposer.vue +234 -0
- package/src/pages/forms/textarea-input/DomTextareaInput.vue +86 -0
- package/src/pages/forms/textarea-input/useTextareaAutosize.js +147 -0
- package/src/pages/forms/time-selector/DomTimeSelector.vue +389 -0
- package/src/pages/forms/time-selector/timeUtils.js +194 -0
- package/src/pages/forms/toggle/DomToggle.vue +158 -0
- package/src/pages/forms/toggle-button/DomToggleButton.vue +88 -0
- package/src/pages/forms/toggle-button-group/DomToggleButtonGroup.vue +340 -0
- package/src/pages/forms/url-input/DomUrlInput.vue +55 -0
- package/src/pages/forms/wysiwyg/DomWysiwyg.vue +204 -0
- package/src/pages/lib/css/color.js +245 -0
- package/src/pages/lib/headless/accordion.d.ts +7 -0
- package/src/pages/lib/headless/accordion.js +246 -0
- package/src/pages/lib/headless/autocomplete.d.ts +4 -0
- package/src/pages/lib/headless/autocomplete.js +33 -0
- package/src/pages/lib/headless/base.d.ts +25 -0
- package/src/pages/lib/headless/base.js +127 -0
- package/src/pages/lib/headless/checkbox.d.ts +19 -0
- package/src/pages/lib/headless/checkbox.js +99 -0
- package/src/pages/lib/headless/combobox.d.ts +7 -0
- package/src/pages/lib/headless/combobox.js +488 -0
- package/src/pages/lib/headless/dialog.d.ts +23 -0
- package/src/pages/lib/headless/dialog.js +384 -0
- package/src/pages/lib/headless/drawer.d.ts +21 -0
- package/src/pages/lib/headless/drawer.js +682 -0
- package/src/pages/lib/headless/dropdown.d.ts +19 -0
- package/src/pages/lib/headless/dropdown.js +412 -0
- package/src/pages/lib/headless/floating-effect.js +118 -0
- package/src/pages/lib/headless/floating.d.ts +34 -0
- package/src/pages/lib/headless/floating.js +382 -0
- package/src/pages/lib/headless/index.d.ts +19 -0
- package/src/pages/lib/headless/index.js +19 -0
- package/src/pages/lib/headless/listbox.d.ts +19 -0
- package/src/pages/lib/headless/listbox.js +126 -0
- package/src/pages/lib/headless/menu.d.ts +18 -0
- package/src/pages/lib/headless/menu.js +117 -0
- package/src/pages/lib/headless/popover-panel.d.ts +18 -0
- package/src/pages/lib/headless/popover-panel.js +309 -0
- package/src/pages/lib/headless/popover.d.ts +19 -0
- package/src/pages/lib/headless/popover.js +391 -0
- package/src/pages/lib/headless/radio-group.d.ts +19 -0
- package/src/pages/lib/headless/radio-group.js +100 -0
- package/src/pages/lib/headless/tabs.d.ts +18 -0
- package/src/pages/lib/headless/tabs.js +119 -0
- package/src/pages/lib/headless/toast.d.ts +13 -0
- package/src/pages/lib/headless/toast.js +65 -0
- package/src/pages/lib/headless/toggle.d.ts +19 -0
- package/src/pages/lib/headless/toggle.js +162 -0
- package/src/pages/lib/headless/tooltip-controller.d.ts +22 -0
- package/src/pages/lib/headless/tooltip-controller.js +549 -0
- package/src/pages/lib/headless/tooltip.d.ts +19 -0
- package/src/pages/lib/headless/tooltip.js +153 -0
- package/src/pages/lib/headless/transitions.d.ts +5 -0
- package/src/pages/lib/headless/transitions.js +89 -0
- package/src/pages/lib/vue/_internal/DomLiquidGlassSurface.vue +310 -0
- package/src/pages/lib/vue/_internal/liquidGlass.js +112 -0
- package/src/pages/lib/vue/_internal/liquidGlassConfig.js +10 -0
- package/src/pages/lib/vue/codeHighlighter.js +132 -0
- package/src/pages/lib/vue/floatingTeleportTarget.js +23 -0
- package/src/pages/lib/vue/index.d.ts +6806 -0
- package/src/pages/lib/vue/index.js +218 -0
- package/src/pages/lib/vue/useTheme.js +116 -0
- package/src/pages/mobile/action-sheet/DomActionSheet.vue +186 -0
- package/src/pages/mobile/bottom-nav/DomAppBottomNav.vue +94 -0
- package/src/pages/mobile/list-item/DomAppListItem.vue +90 -0
- package/src/pages/mobile/safe-area/DomSafeArea.vue +39 -0
- package/src/pages/mobile/shell/DomAppShell.vue +51 -0
- package/src/pages/mobile/stack/AppStackScreen.vue +63 -0
- package/src/pages/mobile/stack/DomAppStack.vue +711 -0
- package/src/pages/mobile/top-bar/DomAppTopBar.vue +67 -0
- package/src/pages/visual/alert/DomAlert.vue +363 -0
- package/src/pages/visual/avatar/DomAvatar.vue +110 -0
- package/src/pages/visual/avatar-stack/DomAvatarStack.vue +89 -0
- package/src/pages/visual/badge/DomBadge.vue +105 -0
- package/src/pages/visual/card/DomCard.vue +65 -0
- package/src/pages/visual/card-rail/DomCardRail.vue +99 -0
- package/src/pages/visual/empty-state/DomEmptyState.vue +88 -0
- package/src/pages/visual/progress/DomProgress.vue +212 -0
- package/src/pages/visual/progress/DomRadialProgress.vue +186 -0
- package/src/pages/visual/progress/DomSegmentedProgress.vue +350 -0
- package/src/pages/visual/skeleton/DomSkeleton.vue +174 -0
- package/src/pages/visual/spinner/DomSpinner.vue +122 -0
- package/src/pages/visual/status-pill/DomStatusPill.vue +75 -0
- package/src/pages/visual/text-diff/DomTextDiff.vue +577 -0
- package/src/pages/visual/text-diff/textDiff.js +300 -0
- package/src/style.css +446 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span
|
|
3
|
+
class="inline-flex size-7 shrink-0 items-center justify-center rounded-full text-muted-fg"
|
|
4
|
+
role="status"
|
|
5
|
+
aria-label="Loading options"
|
|
6
|
+
>
|
|
7
|
+
<svg viewBox="0 0 20 20" class="size-4 animate-spin" fill="none" aria-hidden="true">
|
|
8
|
+
<circle cx="10" cy="10" r="7" stroke="currentColor" stroke-width="2" opacity="0.25" />
|
|
9
|
+
<path d="M17 10a7 7 0 0 0-7-7" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
|
10
|
+
</svg>
|
|
11
|
+
</span>
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function booleanProp(value, defaultValue = false) {
|
|
2
|
+
if (value === undefined || value === null) return defaultValue;
|
|
3
|
+
if (value === '' || value === true) return true;
|
|
4
|
+
if (value === false) return false;
|
|
5
|
+
return !['false', '0', 'no', 'off'].includes(String(value).toLowerCase());
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function normalizeOption(option, options = {}) {
|
|
9
|
+
const { stringifyValue = false, allowEmptyValue = false } = options;
|
|
10
|
+
if (option == null) return null;
|
|
11
|
+
if (typeof option === 'string' || typeof option === 'number') {
|
|
12
|
+
const value = stringifyValue ? String(option) : option;
|
|
13
|
+
return { value, label: String(option) };
|
|
14
|
+
}
|
|
15
|
+
const rawValue = option.value ?? option.label;
|
|
16
|
+
if (rawValue == null || (!allowEmptyValue && rawValue === '')) return null;
|
|
17
|
+
const value = stringifyValue ? String(rawValue) : rawValue;
|
|
18
|
+
return {
|
|
19
|
+
...option,
|
|
20
|
+
value,
|
|
21
|
+
label: option.label ?? String(value),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function optionKey(value) {
|
|
26
|
+
return String(value ?? '').toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function searchableText(option, keys = ['label', 'value', 'description', 'group']) {
|
|
30
|
+
return keys
|
|
31
|
+
.map((key) => option?.[key])
|
|
32
|
+
.filter(Boolean)
|
|
33
|
+
.join(' ')
|
|
34
|
+
.toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function uniqueValues(values, options = {}) {
|
|
38
|
+
const { transform = (value) => value, key = optionKey } = options;
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
const out = [];
|
|
41
|
+
for (const value of values || []) {
|
|
42
|
+
const nextValue = transform(value);
|
|
43
|
+
if (nextValue == null || nextValue === '') continue;
|
|
44
|
+
const nextKey = key(nextValue);
|
|
45
|
+
if (seen.has(nextKey)) continue;
|
|
46
|
+
seen.add(nextKey);
|
|
47
|
+
out.push(nextValue);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function splitTokens(value, separators = [' ', ',']) {
|
|
53
|
+
const activeSeparators = separators.length ? separators : [' ', ','];
|
|
54
|
+
const escaped = activeSeparators
|
|
55
|
+
.map((separator) => String(separator).replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
56
|
+
.join('');
|
|
57
|
+
return String(value || '')
|
|
58
|
+
.split(new RegExp(`[${escaped}\\n\\r\\t]+`))
|
|
59
|
+
.map((token) => token.trim())
|
|
60
|
+
.filter(Boolean);
|
|
61
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { computed, ref, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
export function useOptionMenu(items, options = {}) {
|
|
4
|
+
const {
|
|
5
|
+
emitQuery,
|
|
6
|
+
openOnQuery = true,
|
|
7
|
+
closeDelay = 120,
|
|
8
|
+
query: queryRef,
|
|
9
|
+
} = options;
|
|
10
|
+
const query = queryRef || ref('');
|
|
11
|
+
const isOpen = ref(false);
|
|
12
|
+
const activeIndex = ref(0);
|
|
13
|
+
const trimmedQuery = computed(() => query.value.trim());
|
|
14
|
+
|
|
15
|
+
watch(query, (value) => {
|
|
16
|
+
emitQuery?.(value);
|
|
17
|
+
activeIndex.value = 0;
|
|
18
|
+
if (openOnQuery && value) isOpen.value = true;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
watch(items, () => {
|
|
22
|
+
if (activeIndex.value >= items.value.length) {
|
|
23
|
+
activeIndex.value = Math.max(0, items.value.length - 1);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
function wrapIndex(index) {
|
|
28
|
+
if (!items.value.length) return 0;
|
|
29
|
+
return (index + items.value.length) % items.value.length;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function move(delta) {
|
|
33
|
+
isOpen.value = true;
|
|
34
|
+
activeIndex.value = wrapIndex(activeIndex.value + delta);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function reset() {
|
|
38
|
+
query.value = '';
|
|
39
|
+
isOpen.value = false;
|
|
40
|
+
activeIndex.value = 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function closeSoon() {
|
|
44
|
+
window.setTimeout(() => {
|
|
45
|
+
isOpen.value = false;
|
|
46
|
+
}, closeDelay);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
query,
|
|
51
|
+
isOpen,
|
|
52
|
+
activeIndex,
|
|
53
|
+
trimmedQuery,
|
|
54
|
+
wrapIndex,
|
|
55
|
+
move,
|
|
56
|
+
reset,
|
|
57
|
+
closeSoon,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, onMounted, ref, shallowRef, useId, watch } from 'vue';
|
|
3
|
+
import { resolveFloatingTeleportTarget } from '../../lib/vue/floatingTeleportTarget.js';
|
|
4
|
+
import DomFieldLoadingSpinner from '../_shared/DomFieldLoadingSpinner.vue';
|
|
5
|
+
import { booleanProp, normalizeOption } from '../_shared/options.js';
|
|
6
|
+
import DomField from '../field/DomField.vue';
|
|
7
|
+
import { fieldProps } from '../field/fieldProps.js';
|
|
8
|
+
import { useField } from '../field/useField.js';
|
|
9
|
+
|
|
10
|
+
const listId = `dom-autocomplete-${useId()}`;
|
|
11
|
+
|
|
12
|
+
defineOptions({
|
|
13
|
+
__doc: {
|
|
14
|
+
name: 'Autocomplete',
|
|
15
|
+
tag: '<DomAutocomplete>',
|
|
16
|
+
description: 'Free-text autocomplete with optional suggestions, floating positioning, keyboard navigation, and query events for async lookups.',
|
|
17
|
+
slots: [
|
|
18
|
+
{ name: 'item', payload: '{ item, index }', description: 'Replaces the rendering of each suggestion.' },
|
|
19
|
+
],
|
|
20
|
+
events: [
|
|
21
|
+
{ name: 'query', payload: '(query: string)', description: 'Fired as the user types. Use it to fetch or replace suggestions.' },
|
|
22
|
+
{ name: 'select', payload: '({ item, value, label, text, query })', description: 'Fired when a suggestion is chosen. item is the original option object.' },
|
|
23
|
+
{ name: 'commit', payload: '({ value, label, custom })', description: 'Fired when the current text is committed with Enter.' },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const props = defineProps({
|
|
29
|
+
...fieldProps,
|
|
30
|
+
modelValue: {
|
|
31
|
+
type: String,
|
|
32
|
+
default: '',
|
|
33
|
+
_edit: { group: 'Control props', description: 'Current text value.' },
|
|
34
|
+
},
|
|
35
|
+
options: {
|
|
36
|
+
type: Array,
|
|
37
|
+
default: () => [],
|
|
38
|
+
_edit: {
|
|
39
|
+
component: 'DomJsonListInput',
|
|
40
|
+
description: 'Suggestions. May be replaced by async lookup results.',
|
|
41
|
+
props: {
|
|
42
|
+
compact: true,
|
|
43
|
+
addLabel: '+ Add suggestion',
|
|
44
|
+
schema: [
|
|
45
|
+
{ key: 'label', label: 'Label', placeholder: 'Suggestion label', default: (index) => `Suggestion ${index + 1}` },
|
|
46
|
+
{ key: 'value', label: 'Value', placeholder: 'suggestion-value', default: (index) => `suggestion-${index + 1}` },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
placeholder: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: 'Search...',
|
|
54
|
+
_edit: { group: 'Control props', description: 'Placeholder shown when the input is empty.' },
|
|
55
|
+
},
|
|
56
|
+
placement: {
|
|
57
|
+
type: String,
|
|
58
|
+
default: 'bottom',
|
|
59
|
+
_edit: { group: 'Control props', options: ['bottom', 'top', 'right', 'left'], description: 'Preferred side before collision handling.' },
|
|
60
|
+
},
|
|
61
|
+
floatingMode: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: 'viewport',
|
|
64
|
+
_edit: { group: 'Control props', options: ['viewport', 'anchor'], description: 'viewport keeps suggestions inside the browser; anchor keeps them attached while scrolling.' },
|
|
65
|
+
},
|
|
66
|
+
loading: {
|
|
67
|
+
type: [Boolean, String],
|
|
68
|
+
default: false,
|
|
69
|
+
_edit: { group: 'Control props', description: 'Show an inline spinner while async suggestions are being fetched.' },
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const emit = defineEmits(['update:modelValue', 'query', 'select', 'commit', 'focus', 'blur']);
|
|
73
|
+
|
|
74
|
+
const root = ref(null);
|
|
75
|
+
const inputEl = ref(null);
|
|
76
|
+
const isMounted = ref(false);
|
|
77
|
+
const teleportTarget = shallowRef(null);
|
|
78
|
+
const currentText = ref('');
|
|
79
|
+
const field = useField(props, emit, { idPrefix: 'dom-autocomplete' });
|
|
80
|
+
const isLoading = computed(() => booleanProp(props.loading, false));
|
|
81
|
+
|
|
82
|
+
const items = computed(() => props.options.map((option) => normalizeOption(option)).filter(Boolean));
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Synchronize the free-text input from the Vue model value.
|
|
86
|
+
*
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
function syncInputFromModel() {
|
|
90
|
+
currentText.value = field.value.value ?? '';
|
|
91
|
+
if (inputEl.value) inputEl.value.value = field.value.value ?? '';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onMounted(async () => {
|
|
95
|
+
teleportTarget.value = resolveFloatingTeleportTarget(root.value);
|
|
96
|
+
isMounted.value = true;
|
|
97
|
+
await import('../../lib/headless/autocomplete.js');
|
|
98
|
+
syncInputFromModel();
|
|
99
|
+
root.value?.addEventListener('dom:input', (event) => {
|
|
100
|
+
currentText.value = event.detail.value;
|
|
101
|
+
field.onInput(event.detail.value);
|
|
102
|
+
});
|
|
103
|
+
root.value?.addEventListener('dom:query', (event) => emit('query', event.detail.query));
|
|
104
|
+
root.value?.addEventListener('dom:select', (event) => {
|
|
105
|
+
const index = Number(event.detail.option?.dataset.index);
|
|
106
|
+
const item = Number.isFinite(index) ? items.value[index] : null;
|
|
107
|
+
const text = event.detail.label ?? event.detail.value ?? '';
|
|
108
|
+
field.onInput(text);
|
|
109
|
+
emit('select', {
|
|
110
|
+
item,
|
|
111
|
+
value: event.detail.value,
|
|
112
|
+
label: event.detail.label,
|
|
113
|
+
text,
|
|
114
|
+
query: currentText.value,
|
|
115
|
+
option: event.detail.option,
|
|
116
|
+
});
|
|
117
|
+
currentText.value = text;
|
|
118
|
+
});
|
|
119
|
+
root.value?.addEventListener('dom:change', (event) => emit('commit', event.detail));
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
watch(field.value, syncInputFromModel);
|
|
123
|
+
|
|
124
|
+
</script>
|
|
125
|
+
|
|
126
|
+
<template>
|
|
127
|
+
<DomField v-bind="field.fieldAttrs.value" :chrome="chrome">
|
|
128
|
+
<dom-autocomplete
|
|
129
|
+
ref="root"
|
|
130
|
+
:data-menu-id="listId"
|
|
131
|
+
:value="field.value.value ?? null"
|
|
132
|
+
:placement="placement"
|
|
133
|
+
:floating-mode="floatingMode"
|
|
134
|
+
class="relative block"
|
|
135
|
+
>
|
|
136
|
+
<input
|
|
137
|
+
v-bind="field.inputAttrs.value"
|
|
138
|
+
ref="inputEl"
|
|
139
|
+
slot="input"
|
|
140
|
+
type="text"
|
|
141
|
+
class="skin-input h-10 pr-10"
|
|
142
|
+
:class="isLoading ? 'pr-20' : ''"
|
|
143
|
+
@focus="field.onFocus"
|
|
144
|
+
@blur="field.onBlur"
|
|
145
|
+
/>
|
|
146
|
+
<DomFieldLoadingSpinner
|
|
147
|
+
v-if="isLoading"
|
|
148
|
+
class="absolute right-9 top-1"
|
|
149
|
+
/>
|
|
150
|
+
<button
|
|
151
|
+
slot="toggle"
|
|
152
|
+
type="button"
|
|
153
|
+
class="absolute right-1 top-1 inline-flex size-8 items-center justify-center rounded-md text-muted-fg transition hover:text-canvas-fg focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 disabled:cursor-not-allowed disabled:opacity-50"
|
|
154
|
+
aria-label="Show suggestions"
|
|
155
|
+
:disabled="props.disabled || props.readOnly || undefined"
|
|
156
|
+
>
|
|
157
|
+
<svg viewBox="0 0 20 20" class="size-4" fill="none" aria-hidden="true">
|
|
158
|
+
<path d="M6 8l4 4 4-4" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" />
|
|
159
|
+
</svg>
|
|
160
|
+
</button>
|
|
161
|
+
<Teleport :to="teleportTarget || 'body'" :disabled="!isMounted || !teleportTarget">
|
|
162
|
+
<ul
|
|
163
|
+
:id="listId"
|
|
164
|
+
class="dom-floating-transition skin-popover z-50 max-h-[min(15rem,var(--dom-floating-available-height))] overflow-auto rounded-2xl p-1"
|
|
165
|
+
>
|
|
166
|
+
<li
|
|
167
|
+
v-for="(option, index) in items"
|
|
168
|
+
:key="option.value ?? index"
|
|
169
|
+
:data-value="option.value"
|
|
170
|
+
:data-label="option.label"
|
|
171
|
+
:data-index="index"
|
|
172
|
+
class="cursor-pointer rounded-xl px-3 py-2 text-sm text-canvas-fg transition hover:bg-accent hover:text-accent-fg data-[active]:bg-accent data-[active]:text-accent-fg aria-selected:bg-accent aria-selected:text-accent-fg"
|
|
173
|
+
>
|
|
174
|
+
<slot name="item" :item="option" :index="index">{{ option.label }}</slot>
|
|
175
|
+
</li>
|
|
176
|
+
</ul>
|
|
177
|
+
</Teleport>
|
|
178
|
+
</dom-autocomplete>
|
|
179
|
+
</DomField>
|
|
180
|
+
</template>
|