@noix-dev/brix-vue 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/LICENSE +21 -0
- package/README.md +74 -2
- package/package.json +117 -3
- package/src/components/address-field/AddressField.vue +337 -0
- package/src/components/address-field/index.ts +1 -0
- package/src/components/appearance-picker/AppearancePicker.vue +502 -0
- package/src/components/appearance-picker/AppearanceSegment.vue +175 -0
- package/src/components/appearance-picker/index.ts +44 -0
- package/src/components/autofill/AutoFillDialog.vue +264 -0
- package/src/components/autofill/index.ts +1 -0
- package/src/components/badge/Badge.vue +23 -0
- package/src/components/badge/index.ts +106 -0
- package/src/components/build-stamp/BuildStamp.vue +62 -0
- package/src/components/build-stamp/index.ts +1 -0
- package/src/components/button/Button.vue +31 -0
- package/src/components/button/index.ts +122 -0
- package/src/components/card/Card.vue +29 -0
- package/src/components/card/CardAction.vue +17 -0
- package/src/components/card/CardContent.vue +14 -0
- package/src/components/card/CardDescription.vue +14 -0
- package/src/components/card/CardFooter.vue +22 -0
- package/src/components/card/CardHeader.vue +22 -0
- package/src/components/card/CardTitle.vue +29 -0
- package/src/components/card/index.ts +47 -0
- package/src/components/chart/BarChart.vue +123 -0
- package/src/components/chart/StackedBarChart.vue +149 -0
- package/src/components/chart/appearanceRevision.ts +22 -0
- package/src/components/chart/chartColor.ts +59 -0
- package/src/components/chart/index.ts +6 -0
- package/src/components/checkbox/Checkbox.vue +61 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/code-editor/CodeEditor.vue +352 -0
- package/src/components/code-editor/index.ts +9 -0
- package/src/components/code-editor/syntaxTheme.ts +110 -0
- package/src/components/colour-picker/ColourPicker.vue +421 -0
- package/src/components/colour-picker/index.ts +1 -0
- package/src/components/combobox/Combobox.vue +337 -0
- package/src/components/combobox/index.ts +1 -0
- package/src/components/comments/CommentComposer.vue +302 -0
- package/src/components/comments/CommentMessage.vue +259 -0
- package/src/components/comments/CommentThread.vue +250 -0
- package/src/components/comments/commentBody.ts +185 -0
- package/src/components/comments/commentLevels.ts +139 -0
- package/src/components/comments/commentNode.ts +35 -0
- package/src/components/comments/composer.ts +20 -0
- package/src/components/comments/index.ts +29 -0
- package/src/components/confirm-dialog/ConfirmDialog.vue +153 -0
- package/src/components/confirm-dialog/index.ts +1 -0
- package/src/components/containers/Box.vue +42 -0
- package/src/components/containers/Section.vue +88 -0
- package/src/components/containers/SectionAction.vue +17 -0
- package/src/components/containers/SectionContent.vue +14 -0
- package/src/components/containers/SectionDescription.vue +14 -0
- package/src/components/containers/SectionHeader.vue +22 -0
- package/src/components/containers/SectionTitle.vue +17 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/data-table/ColumnMenu.vue +241 -0
- package/src/components/data-table/DataTable.vue +447 -0
- package/src/components/data-table/ExpandCaret.vue +34 -0
- package/src/components/data-table/SortableHead.vue +184 -0
- package/src/components/data-table/TableLoadingRow.vue +13 -0
- package/src/components/data-table/TableProgressRow.vue +26 -0
- package/src/components/data-table/columns.ts +13 -0
- package/src/components/data-table/index.ts +3 -0
- package/src/components/data-table/pinned.ts +19 -0
- package/src/components/data-table/rowActivation.ts +14 -0
- package/src/components/data-table/sort.ts +13 -0
- package/src/components/data-table/types.ts +23 -0
- package/src/components/date-picker/CalendarPanel.vue +432 -0
- package/src/components/date-picker/DateField.vue +293 -0
- package/src/components/date-picker/DatePicker.vue +147 -0
- package/src/components/date-picker/UntilDatePicker.vue +96 -0
- package/src/components/date-picker/dateFieldGuard.ts +87 -0
- package/src/components/date-picker/index.ts +4 -0
- package/src/components/date-picker/useDateField.ts +37 -0
- package/src/components/date-range-picker/DateRangePicker.vue +247 -0
- package/src/components/date-range-picker/index.ts +1 -0
- package/src/components/date-time-picker/DateTimePicker.vue +291 -0
- package/src/components/date-time-picker/index.ts +1 -0
- package/src/components/dialog/Dialog.vue +250 -0
- package/src/components/dialog/DialogSurface.vue +214 -0
- package/src/components/dialog/dialogEdges.ts +65 -0
- package/src/components/dialog/dialogSizes.ts +35 -0
- package/src/components/dialog/index.ts +12 -0
- package/src/components/dialog/toastHost.ts +18 -0
- package/src/components/dropdown/Dropdown.vue +101 -0
- package/src/components/dropdown/DropdownItems.vue +154 -0
- package/src/components/dropdown/dropdown.ts +64 -0
- package/src/components/dropdown/index.ts +2 -0
- package/src/components/file-preview/FilePreview.vue +78 -0
- package/src/components/file-preview/index.ts +1 -0
- package/src/components/file-upload/FileUpload.vue +234 -0
- package/src/components/file-upload/index.ts +1 -0
- package/src/components/filter-check-menu/FilterCheckMenu.vue +562 -0
- package/src/components/filter-check-menu/filterCheckOption.ts +10 -0
- package/src/components/filter-check-menu/index.ts +2 -0
- package/src/components/form-field/FormField.vue +74 -0
- package/src/components/form-field/index.ts +2 -0
- package/src/components/form-field/types.ts +5 -0
- package/src/components/frames/FrameCentred.vue +137 -0
- package/src/components/frames/FrameSidebar.vue +113 -0
- package/src/components/frames/FrameSplit.vue +109 -0
- package/src/components/frames/index.ts +3 -0
- package/src/components/icon/BellIcon.vue +27 -0
- package/src/components/icon/BoldIcon.vue +31 -0
- package/src/components/icon/CalendarDaysIcon.vue +33 -0
- package/src/components/icon/CheckIcon.vue +31 -0
- package/src/components/icon/ChevronDownIcon.vue +30 -0
- package/src/components/icon/ChevronLeftIcon.vue +31 -0
- package/src/components/icon/ChevronRightIcon.vue +31 -0
- package/src/components/icon/ChevronUpIcon.vue +30 -0
- package/src/components/icon/CircleAlertIcon.vue +29 -0
- package/src/components/icon/ClockIcon.vue +31 -0
- package/src/components/icon/Columns3Icon.vue +32 -0
- package/src/components/icon/FlipHorizontalIcon.vue +29 -0
- package/src/components/icon/ItalicIcon.vue +28 -0
- package/src/components/icon/LinkIcon.vue +27 -0
- package/src/components/icon/ListIcon.vue +29 -0
- package/src/components/icon/ListOrderedIcon.vue +28 -0
- package/src/components/icon/PenLineIcon.vue +31 -0
- package/src/components/icon/PlusIcon.vue +28 -0
- package/src/components/icon/RotateCcwIcon.vue +28 -0
- package/src/components/icon/RotateCwIcon.vue +28 -0
- package/src/components/icon/SearchIcon.vue +31 -0
- package/src/components/icon/StarIcon.vue +29 -0
- package/src/components/icon/TriangleAlertIcon.vue +29 -0
- package/src/components/icon/UnderlineIcon.vue +27 -0
- package/src/components/icon/Undo2Icon.vue +28 -0
- package/src/components/icon/XIcon.vue +31 -0
- package/src/components/icon/ZoomInIcon.vue +30 -0
- package/src/components/icon/ZoomOutIcon.vue +29 -0
- package/src/components/icon/index.ts +37 -0
- package/src/components/icon-picker/IconPicker.vue +560 -0
- package/src/components/icon-picker/index.ts +1 -0
- package/src/components/image-crop-dialog/CropRatioRow.vue +132 -0
- package/src/components/image-crop-dialog/CropVariantStrip.vue +277 -0
- package/src/components/image-crop-dialog/ImageCropDialog.vue +1541 -0
- package/src/components/image-crop-dialog/index.ts +16 -0
- package/src/components/image-upload/ImageUpload.vue +345 -0
- package/src/components/image-upload/index.ts +2 -0
- package/src/components/input/Input.vue +48 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/keycap/Keycap.vue +49 -0
- package/src/components/keycap/index.ts +1 -0
- package/src/components/label/Label.vue +26 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/menu/MenuCheckboxItem.vue +63 -0
- package/src/components/menu/MenuContent.vue +45 -0
- package/src/components/menu/MenuGroup.vue +22 -0
- package/src/components/menu/MenuItem.vue +34 -0
- package/src/components/menu/MenuLabel.vue +22 -0
- package/src/components/menu/MenuRadioGroup.vue +22 -0
- package/src/components/menu/MenuRadioItem.vue +50 -0
- package/src/components/menu/MenuRoot.vue +25 -0
- package/src/components/menu/MenuSeparator.vue +27 -0
- package/src/components/menu/MenuSub.vue +29 -0
- package/src/components/menu/MenuSubContent.vue +48 -0
- package/src/components/menu/MenuSubTrigger.vue +49 -0
- package/src/components/menu/MenuTrigger.vue +22 -0
- package/src/components/menu/index.ts +20 -0
- package/src/components/menu/menuClasses.ts +74 -0
- package/src/components/morph-select/MorphSelect.vue +150 -0
- package/src/components/morph-select/index.ts +1 -0
- package/src/components/nav/NavFlyout.vue +343 -0
- package/src/components/nav/NavGroup.vue +306 -0
- package/src/components/nav/NavItem.vue +243 -0
- package/src/components/nav/NavNodes.ts +66 -0
- package/src/components/nav/NavSection.vue +105 -0
- package/src/components/nav/NavSidebar.vue +137 -0
- package/src/components/nav/index.ts +5 -0
- package/src/components/nav/navChain.ts +112 -0
- package/src/components/nav/navClasses.ts +229 -0
- package/src/components/nav/navNode.ts +10 -0
- package/src/components/nav/navRegistry.ts +24 -0
- package/src/components/notification-list/NotificationList.vue +314 -0
- package/src/components/notification-list/index.ts +2 -0
- package/src/components/notification-list/notifications.ts +21 -0
- package/src/components/pagination/Pagination.vue +296 -0
- package/src/components/pagination/index.ts +1 -0
- package/src/components/pin-field/PinField.vue +332 -0
- package/src/components/pin-field/index.ts +1 -0
- package/src/components/popover-panel/PopoverPanel.vue +115 -0
- package/src/components/popover-panel/index.ts +5 -0
- package/src/components/rating/Rating.vue +201 -0
- package/src/components/rating/index.ts +1 -0
- package/src/components/record-avatar/RecordAvatar.vue +76 -0
- package/src/components/record-avatar/index.ts +1 -0
- package/src/components/result-window/ResultWindow.vue +399 -0
- package/src/components/result-window/index.ts +2 -0
- package/src/components/result-window/results.ts +75 -0
- package/src/components/rich-editor/RichEditor.vue +370 -0
- package/src/components/rich-editor/RichEditorLinkDialog.vue +133 -0
- package/src/components/rich-editor/index.ts +8 -0
- package/src/components/row-actions/RowActions.vue +262 -0
- package/src/components/row-actions/index.ts +2 -0
- package/src/components/row-actions/rowActions.ts +44 -0
- package/src/components/search-select/SearchSelect.vue +599 -0
- package/src/components/search-select/index.ts +2 -0
- package/src/components/search-select/types.ts +14 -0
- package/src/components/segmented-choice/SegmentedChoice.vue +136 -0
- package/src/components/segmented-choice/index.ts +2 -0
- package/src/components/segmented-choice/segmentedOption.ts +6 -0
- package/src/components/select/Select.vue +18 -0
- package/src/components/select/SelectContent.vue +73 -0
- package/src/components/select/SelectGroup.vue +21 -0
- package/src/components/select/SelectItem.vue +47 -0
- package/src/components/select/SelectItemText.vue +12 -0
- package/src/components/select/SelectLabel.vue +17 -0
- package/src/components/select/SelectScrollDownButton.vue +36 -0
- package/src/components/select/SelectScrollUpButton.vue +36 -0
- package/src/components/select/SelectSeparator.vue +19 -0
- package/src/components/select/SelectTrigger.vue +52 -0
- package/src/components/select/SelectValue.vue +12 -0
- package/src/components/select/index.ts +11 -0
- package/src/components/session/IdleTimer.vue +71 -0
- package/src/components/session/SessionDialogs.vue +177 -0
- package/src/components/session/index.ts +2 -0
- package/src/components/split-button/SplitButton.vue +122 -0
- package/src/components/split-button/index.ts +2 -0
- package/src/components/split-button/splitButtonItem.ts +7 -0
- package/src/components/switch/Switch.vue +60 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/table/Table.vue +51 -0
- package/src/components/table/TableBody.vue +14 -0
- package/src/components/table/TableCaption.vue +17 -0
- package/src/components/table/TableCell.vue +22 -0
- package/src/components/table/TableEmpty.vue +72 -0
- package/src/components/table/TableFooter.vue +17 -0
- package/src/components/table/TableHead.vue +22 -0
- package/src/components/table/TableHeader.vue +14 -0
- package/src/components/table/TableRow.vue +22 -0
- package/src/components/table/index.ts +9 -0
- package/src/components/tabs/Tabs.vue +173 -0
- package/src/components/tabs/index.ts +2 -0
- package/src/components/tabs/tabItem.ts +12 -0
- package/src/components/textarea/LimitedTextarea.vue +81 -0
- package/src/components/textarea/TextLimitCounter.vue +107 -0
- package/src/components/textarea/Textarea.vue +42 -0
- package/src/components/textarea/index.ts +4 -0
- package/src/components/textarea/textLimit.ts +43 -0
- package/src/components/time-picker/TimePicker.vue +522 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/toast/ToastHost.vue +276 -0
- package/src/components/toast/index.ts +1 -0
- package/src/components/update-notice/UpdateNotice.vue +103 -0
- package/src/components/update-notice/index.ts +1 -0
- package/src/components/user-menu/UserMenu.vue +154 -0
- package/src/components/user-menu/index.ts +1 -0
- package/src/index.ts +182 -0
- package/src/lib/cn.ts +21 -0
- package/src/lib/panelFocus.ts +65 -0
- package/src/lib/sessionMonitor.ts +390 -0
- package/src/lib/slotContent.ts +17 -0
- package/src/lib/updateCheck.ts +133 -0
- package/src/styles.css +82 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { formatLabel, useUiLabels } from '@noix-dev/brix-core';
|
|
3
|
+
import { onClickOutside, useDebounceFn } from '@vueuse/core';
|
|
4
|
+
import { computed, nextTick, onBeforeUnmount, ref, useId, watch } from 'vue';
|
|
5
|
+
import type { CSSProperties, HTMLAttributes } from 'vue';
|
|
6
|
+
import { cn } from '../../lib/cn';
|
|
7
|
+
import { ChevronDownIcon, SearchIcon, XIcon } from '../icon';
|
|
8
|
+
import type { SearchSelectOption } from './types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A button that opens a searchable list and picks one entry from it. Matching is local unless
|
|
12
|
+
* `serverFilter` is set, in which case typing emits a debounced `search` and `options` is
|
|
13
|
+
* whatever the caller answers with.
|
|
14
|
+
*
|
|
15
|
+
* The control is two focusable things side by side, never one inside the other: the trigger
|
|
16
|
+
* (`role="combobox"`, which carries `id` and `aria-describedby`, so a `FormField` names it) and,
|
|
17
|
+
* while a value is chosen, a real clear button. Opening moves focus into the search field.
|
|
18
|
+
* From there: ArrowDown and ArrowUp move and stop at the ends (ArrowUp with nothing
|
|
19
|
+
* highlighted enters at the last row), Home and End jump, Enter chooses the
|
|
20
|
+
* highlighted entry, Escape closes, and Tab closes and carries on from the trigger. Whatever
|
|
21
|
+
* closes it from the keyboard or from a click inside it puts focus back on the trigger, so the
|
|
22
|
+
* keyboard is never left on a field that has just been removed.
|
|
23
|
+
*
|
|
24
|
+
* `class` lands on the outer box, which is what the panel is measured against.
|
|
25
|
+
*/
|
|
26
|
+
const props = withDefaults(
|
|
27
|
+
defineProps<{
|
|
28
|
+
modelValue: string | number | null;
|
|
29
|
+
options: SearchSelectOption[];
|
|
30
|
+
id?: string;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
/** Overrides the label contract's `search` for this control's search field. */
|
|
33
|
+
searchPlaceholder?: string;
|
|
34
|
+
/** Overrides the label contract's `noMatches` for this control's empty list. */
|
|
35
|
+
emptyText?: string;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
clearable?: boolean;
|
|
38
|
+
loading?: boolean;
|
|
39
|
+
creatable?: boolean;
|
|
40
|
+
// When true the component stops filtering locally and defers to the parent,
|
|
41
|
+
// which reacts to `search` and feeds back a pre-filtered `options` list.
|
|
42
|
+
serverFilter?: boolean;
|
|
43
|
+
class?: HTMLAttributes['class'];
|
|
44
|
+
}>(),
|
|
45
|
+
{
|
|
46
|
+
placeholder: 'Select…',
|
|
47
|
+
searchPlaceholder: undefined,
|
|
48
|
+
emptyText: undefined,
|
|
49
|
+
disabled: false,
|
|
50
|
+
clearable: true,
|
|
51
|
+
loading: false,
|
|
52
|
+
creatable: false,
|
|
53
|
+
serverFilter: false,
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const emit = defineEmits<{
|
|
58
|
+
(e: 'update:modelValue', value: string | number | null): void;
|
|
59
|
+
(e: 'create', term: string): void;
|
|
60
|
+
(e: 'search', term: string): void;
|
|
61
|
+
}>();
|
|
62
|
+
|
|
63
|
+
defineSlots<{
|
|
64
|
+
/** The arrow at the trigger's end. Defaults to the package's own chevron. */
|
|
65
|
+
'chevron-icon'?: () => unknown;
|
|
66
|
+
/** The glyph beside the search field. Defaults to the package's own magnifier. */
|
|
67
|
+
'search-icon'?: () => unknown;
|
|
68
|
+
/** The glyph on the clear button. Defaults to the package's own cross. */
|
|
69
|
+
'clear-icon'?: () => unknown;
|
|
70
|
+
}>();
|
|
71
|
+
|
|
72
|
+
defineOptions({ inheritAttrs: false });
|
|
73
|
+
|
|
74
|
+
const labels = useUiLabels();
|
|
75
|
+
|
|
76
|
+
const listId = useId();
|
|
77
|
+
const root = ref<HTMLElement | null>(null);
|
|
78
|
+
const triggerEl = ref<HTMLButtonElement | null>(null);
|
|
79
|
+
const searchEl = ref<HTMLInputElement | null>(null);
|
|
80
|
+
const open = ref(false);
|
|
81
|
+
const term = ref('');
|
|
82
|
+
const activeIndex = ref(-1);
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The strings around the list come from the shared label contract, which is this package's
|
|
86
|
+
* only i18n mechanism; `searchPlaceholder` and `emptyText` beat it for one call site. The
|
|
87
|
+
* create row's wording is a template rather than a prefix the component glues the query
|
|
88
|
+
* onto: the quotation marks and the word order differ by language, and only the catalogue
|
|
89
|
+
* knows them — the German wording puts the query first.
|
|
90
|
+
*/
|
|
91
|
+
const searchText = computed(() => props.searchPlaceholder ?? labels.value.search);
|
|
92
|
+
const emptyMessage = computed(() => props.emptyText ?? labels.value.noMatches);
|
|
93
|
+
const createText = computed(() =>
|
|
94
|
+
formatLabel(labels.value.createOption, { term: term.value.trim() }),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const selectedLabel = computed(
|
|
98
|
+
() => props.options.find((o) => o.value === props.modelValue)?.label ?? '',
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const filtered = computed(() => {
|
|
102
|
+
if (props.serverFilter || term.value.trim() === '') {
|
|
103
|
+
return props.options;
|
|
104
|
+
}
|
|
105
|
+
const needle = term.value.trim().toLowerCase();
|
|
106
|
+
return props.options.filter((o) => o.label.toLowerCase().includes(needle));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const showCreate = computed(() => {
|
|
110
|
+
const value = term.value.trim();
|
|
111
|
+
if (!props.creatable || value === '') {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const needle = value.toLowerCase();
|
|
115
|
+
return !props.options.some((o) => o.label.toLowerCase() === needle);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Row count spans the options plus the optional quick-create row, so keyboard
|
|
119
|
+
// navigation can land on either.
|
|
120
|
+
// While loading, no row is rendered at all, so none can be counted or pointed at.
|
|
121
|
+
const rowCount = computed(() =>
|
|
122
|
+
props.loading ? 0 : filtered.value.length + (showCreate.value ? 1 : 0),
|
|
123
|
+
);
|
|
124
|
+
const createIndex = computed(() => (showCreate.value ? filtered.value.length : -1));
|
|
125
|
+
|
|
126
|
+
function rowId(index: number): string {
|
|
127
|
+
return `${listId}-row-${index}`;
|
|
128
|
+
}
|
|
129
|
+
const activeDescendant = computed(() =>
|
|
130
|
+
open.value && activeIndex.value >= 0 && activeIndex.value < rowCount.value
|
|
131
|
+
? rowId(activeIndex.value)
|
|
132
|
+
: undefined,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const emitSearch = useDebounceFn((value: string) => emit('search', value), 250);
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The panel is `fixed` and positioned against the viewport rather than sitting beside the
|
|
139
|
+
* trigger, so no scrolling ancestor can clip it: inside a dialog, an absolutely positioned
|
|
140
|
+
* panel is cut off at the dialog body's edge. It stays in the root's subtree, though, so a
|
|
141
|
+
* `transform` above it (a dialog centred with a translate) makes that ancestor the containing
|
|
142
|
+
* block instead of the viewport; `position` measures where the panel landed and corrects for it.
|
|
143
|
+
*/
|
|
144
|
+
const panelEl = ref<HTMLElement | null>(null);
|
|
145
|
+
const placed = ref({ left: 0, top: 0, width: 0 });
|
|
146
|
+
|
|
147
|
+
const panelStyle = computed<CSSProperties>(() => ({
|
|
148
|
+
left: `${placed.value.left}px`,
|
|
149
|
+
top: `${placed.value.top}px`,
|
|
150
|
+
width: `${placed.value.width}px`,
|
|
151
|
+
}));
|
|
152
|
+
|
|
153
|
+
/** The gap between the trigger and the panel. */
|
|
154
|
+
const GAP = 4;
|
|
155
|
+
|
|
156
|
+
function position(): void {
|
|
157
|
+
const box = root.value;
|
|
158
|
+
if (box === null) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const rect = box.getBoundingClientRect();
|
|
163
|
+
const panel = panelEl.value;
|
|
164
|
+
const height = panel?.offsetHeight ?? 0;
|
|
165
|
+
|
|
166
|
+
const below = window.innerHeight - rect.bottom;
|
|
167
|
+
const flipUp = height > 0 && below < height + GAP && rect.top > below;
|
|
168
|
+
|
|
169
|
+
const wantLeft = rect.left;
|
|
170
|
+
const wantTop = flipUp ? rect.top - height - GAP : rect.bottom + GAP;
|
|
171
|
+
|
|
172
|
+
// Measure where the panel actually landed and shift by the difference. Guarded on a real
|
|
173
|
+
// measurement: jsdom reports every box as zero, and an unguarded correction would read that
|
|
174
|
+
// as a huge offset and walk the panel further away on each call.
|
|
175
|
+
let shiftX = 0;
|
|
176
|
+
let shiftY = 0;
|
|
177
|
+
const landed = panel?.getBoundingClientRect();
|
|
178
|
+
if (landed !== undefined && landed.width > 0) {
|
|
179
|
+
shiftX = placed.value.left - landed.left;
|
|
180
|
+
shiftY = placed.value.top - landed.top;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
placed.value = {
|
|
184
|
+
left: wantLeft + shiftX,
|
|
185
|
+
top: wantTop + shiftY,
|
|
186
|
+
width: rect.width,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Capture, so a scroll inside a dialog body moves the panel too, not just a scroll of the page.
|
|
191
|
+
const TRACK = { capture: true, passive: true } as const;
|
|
192
|
+
|
|
193
|
+
function track(): void {
|
|
194
|
+
window.addEventListener('scroll', position, TRACK);
|
|
195
|
+
window.addEventListener('resize', position);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function untrack(): void {
|
|
199
|
+
window.removeEventListener('scroll', position, TRACK);
|
|
200
|
+
window.removeEventListener('resize', position);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function openMenu(): void {
|
|
204
|
+
if (props.disabled) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
open.value = true;
|
|
208
|
+
term.value = '';
|
|
209
|
+
// Open over a value and the highlight starts on it, so the keyboard and the screen reader
|
|
210
|
+
// begin where the choice is.
|
|
211
|
+
activeIndex.value = props.options.findIndex((o) => o.value === props.modelValue);
|
|
212
|
+
position();
|
|
213
|
+
track();
|
|
214
|
+
void nextTick(() => {
|
|
215
|
+
// Again after the panel exists: opening can shift the trigger itself,
|
|
216
|
+
// for instance when a dialog stops scrolling.
|
|
217
|
+
position();
|
|
218
|
+
searchEl.value?.focus();
|
|
219
|
+
scrollActiveIntoView();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Closes the list. `restoreFocus` is for closes the keyboard or a click inside the list made. */
|
|
224
|
+
function closeMenu(restoreFocus = false): void {
|
|
225
|
+
open.value = false;
|
|
226
|
+
term.value = '';
|
|
227
|
+
activeIndex.value = -1;
|
|
228
|
+
untrack();
|
|
229
|
+
if (restoreFocus) {
|
|
230
|
+
triggerEl.value?.focus();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
onBeforeUnmount(untrack);
|
|
235
|
+
|
|
236
|
+
function toggle(): void {
|
|
237
|
+
if (open.value) {
|
|
238
|
+
closeMenu(true);
|
|
239
|
+
} else {
|
|
240
|
+
openMenu();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function onInput(event: Event): void {
|
|
245
|
+
term.value = (event.target as HTMLInputElement).value;
|
|
246
|
+
activeIndex.value = -1;
|
|
247
|
+
if (props.serverFilter) {
|
|
248
|
+
void emitSearch(term.value);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function pick(option: SearchSelectOption): void {
|
|
253
|
+
if (option.disabled) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
emit('update:modelValue', option.value);
|
|
257
|
+
closeMenu(true);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function create(): void {
|
|
261
|
+
emit('create', term.value.trim());
|
|
262
|
+
closeMenu(true);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function clear(): void {
|
|
266
|
+
emit('update:modelValue', null);
|
|
267
|
+
// The button disappears with the value; keep the keyboard where it was.
|
|
268
|
+
triggerEl.value?.focus();
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function isSkipped(index: number): boolean {
|
|
272
|
+
return index !== createIndex.value && filtered.value[index]?.disabled === true;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function scrollActiveIntoView(): void {
|
|
276
|
+
if (activeIndex.value < 0) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
document.getElementById(rowId(activeIndex.value))?.scrollIntoView?.({ block: 'nearest' });
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The first row at or past `from` in the direction of `delta` that is not disabled, or -1
|
|
284
|
+
* when the list ends first. `delta` is always one step, so the bounds check terminates it.
|
|
285
|
+
*/
|
|
286
|
+
function nextIndex(from: number, delta: 1 | -1): number {
|
|
287
|
+
const count = rowCount.value;
|
|
288
|
+
let next = from;
|
|
289
|
+
for (;;) {
|
|
290
|
+
next += delta;
|
|
291
|
+
if (next < 0 || next > count - 1) {
|
|
292
|
+
return -1;
|
|
293
|
+
}
|
|
294
|
+
if (!isSkipped(next)) {
|
|
295
|
+
return next;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function highlight(index: number): void {
|
|
301
|
+
if (index < 0) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
activeIndex.value = index;
|
|
305
|
+
void nextTick(scrollActiveIntoView);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Moves the highlight by `delta`, passing over disabled options and **stopping** at either
|
|
310
|
+
* end rather than wrapping. The clamp is deliberate: CLAUDE.md's control-state recipe says a
|
|
311
|
+
* listbox-shaped control clamps, `Combobox` clamps, and a user moves between the two
|
|
312
|
+
* interchangeably.
|
|
313
|
+
*/
|
|
314
|
+
function move(delta: 1 | -1): void {
|
|
315
|
+
highlight(nextIndex(activeIndex.value, delta));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function jump(to: 'first' | 'last'): void {
|
|
319
|
+
// Start one step outside the end, so the first stop is the end itself.
|
|
320
|
+
highlight(to === 'first' ? nextIndex(-1, 1) : nextIndex(rowCount.value, -1));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Enter acts on the **active** row and on nothing else, so on a list narrowed to one entry it
|
|
325
|
+
* does nothing until ArrowDown highlights it. That is the ARIA combobox pattern rather than an
|
|
326
|
+
* oversight: a list with no highlight has no selection to confirm, and autoselecting the sole
|
|
327
|
+
* match would commit a value the user has not looked at. `Combobox` agrees, and a user moves
|
|
328
|
+
* between the two. The cost is one ArrowDown.
|
|
329
|
+
*/
|
|
330
|
+
function confirmActive(): void {
|
|
331
|
+
if (activeIndex.value < 0 || activeIndex.value >= rowCount.value) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (activeIndex.value === createIndex.value) {
|
|
335
|
+
create();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const option = filtered.value[activeIndex.value];
|
|
339
|
+
if (option) {
|
|
340
|
+
pick(option);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function onSearchKeydown(event: KeyboardEvent): void {
|
|
345
|
+
switch (event.key) {
|
|
346
|
+
case 'ArrowDown':
|
|
347
|
+
event.preventDefault();
|
|
348
|
+
move(1);
|
|
349
|
+
break;
|
|
350
|
+
case 'ArrowUp':
|
|
351
|
+
event.preventDefault();
|
|
352
|
+
// Entering the list from no highlight at all is not an end, so this one case
|
|
353
|
+
// reaches across: ArrowUp opens at the last row, the way `Combobox` does.
|
|
354
|
+
if (activeIndex.value < 0) {
|
|
355
|
+
jump('last');
|
|
356
|
+
} else {
|
|
357
|
+
move(-1);
|
|
358
|
+
}
|
|
359
|
+
break;
|
|
360
|
+
case 'Home':
|
|
361
|
+
event.preventDefault();
|
|
362
|
+
jump('first');
|
|
363
|
+
break;
|
|
364
|
+
case 'End':
|
|
365
|
+
event.preventDefault();
|
|
366
|
+
jump('last');
|
|
367
|
+
break;
|
|
368
|
+
case 'Enter':
|
|
369
|
+
// An open list owns Enter, so it never submits the form around it by accident.
|
|
370
|
+
event.preventDefault();
|
|
371
|
+
confirmActive();
|
|
372
|
+
break;
|
|
373
|
+
case 'Escape':
|
|
374
|
+
// The innermost dismissable consumes the key: inside a dialog, one Escape closes
|
|
375
|
+
// this list and leaves the dialog (and what was typed in it) alone. This handler
|
|
376
|
+
// only runs while the list is open, so an Escape on a closed control still
|
|
377
|
+
// reaches whatever is outside.
|
|
378
|
+
event.preventDefault();
|
|
379
|
+
event.stopPropagation();
|
|
380
|
+
closeMenu(true);
|
|
381
|
+
break;
|
|
382
|
+
case 'Tab':
|
|
383
|
+
// Focus goes back to the trigger first and the browser's own Tab then moves on from
|
|
384
|
+
// there (Shift+Tab backwards), instead of from a field that is about to be removed.
|
|
385
|
+
closeMenu(true);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function onTriggerKeydown(event: KeyboardEvent): void {
|
|
391
|
+
if ((event.key === 'ArrowDown' || event.key === 'ArrowUp') && !open.value) {
|
|
392
|
+
event.preventDefault();
|
|
393
|
+
openMenu();
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Keep the highlight on the same entry when new results arrive, and drop it if it is gone.
|
|
398
|
+
watch(filtered, (next, previous) => {
|
|
399
|
+
// The create row sits one past the last option, so its index moves with the list. Left
|
|
400
|
+
// alone, a highlight on it became a highlight on whichever option took that index — under
|
|
401
|
+
// `serverFilter` with `creatable`, a late result list could leave the keyboard on a real
|
|
402
|
+
// option the user never highlighted, and Enter would choose it instead of creating.
|
|
403
|
+
if (activeIndex.value === previous.length) {
|
|
404
|
+
activeIndex.value = showCreate.value ? next.length : -1;
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
const kept = previous[activeIndex.value]?.value;
|
|
408
|
+
if (activeIndex.value >= 0 && activeIndex.value < previous.length) {
|
|
409
|
+
activeIndex.value = next.findIndex((o) => o.value === kept);
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
watch(
|
|
414
|
+
() => props.modelValue,
|
|
415
|
+
() => {
|
|
416
|
+
// A programmatic reset (e.g. form clear) should not leave a stale term.
|
|
417
|
+
if (!open.value) {
|
|
418
|
+
term.value = '';
|
|
419
|
+
}
|
|
420
|
+
},
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
onClickOutside(root, () => closeMenu());
|
|
424
|
+
</script>
|
|
425
|
+
|
|
426
|
+
<template>
|
|
427
|
+
<div ref="root" data-slot="search-select" :class="cn('relative w-full', props.class)">
|
|
428
|
+
<!-- The trigger is a DIRECT child of the slot element, and has to stay one: the
|
|
429
|
+
compact and dense height rules in `packages/tokens/src/density.css` select
|
|
430
|
+
`[data-slot='search-select'] > button`, which is the shape five other slots
|
|
431
|
+
already satisfy. A wrapper around it breaks all four rules with no error and no
|
|
432
|
+
failing test. The root carries `relative`, so the absolutely positioned clear
|
|
433
|
+
button has its containing block here.
|
|
434
|
+
|
|
435
|
+
`aria-controls` is gated on the open state because the `<ul>` it names is
|
|
436
|
+
`v-if`-gated: pointed at an absent id it is a dangling IDREF, which is invalid
|
|
437
|
+
ARIA. The search field's own `aria-controls` needs no gate — that field only
|
|
438
|
+
exists while the list does. -->
|
|
439
|
+
<button
|
|
440
|
+
:id="props.id"
|
|
441
|
+
ref="triggerEl"
|
|
442
|
+
type="button"
|
|
443
|
+
data-testid="search-select-trigger"
|
|
444
|
+
role="combobox"
|
|
445
|
+
aria-haspopup="listbox"
|
|
446
|
+
:aria-expanded="open"
|
|
447
|
+
:aria-controls="open ? listId : undefined"
|
|
448
|
+
:disabled="props.disabled"
|
|
449
|
+
v-bind="$attrs"
|
|
450
|
+
class="flex h-8 w-full items-center gap-1.5 rounded-lg border border-muted-foreground bg-transparent px-2.5 py-1 text-sm transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30 dark:aria-invalid:ring-destructive/40"
|
|
451
|
+
@click="toggle"
|
|
452
|
+
@keydown="onTriggerKeydown"
|
|
453
|
+
>
|
|
454
|
+
<span
|
|
455
|
+
:class="
|
|
456
|
+
cn(
|
|
457
|
+
'min-w-0 flex-1 truncate text-left',
|
|
458
|
+
!selectedLabel && 'text-muted-foreground',
|
|
459
|
+
props.clearable && props.modelValue !== null && 'pr-6',
|
|
460
|
+
)
|
|
461
|
+
"
|
|
462
|
+
>
|
|
463
|
+
{{ selectedLabel || props.placeholder }}
|
|
464
|
+
</span>
|
|
465
|
+
<span class="shrink-0 text-muted-foreground">
|
|
466
|
+
<slot name="chevron-icon">
|
|
467
|
+
<ChevronDownIcon />
|
|
468
|
+
</slot>
|
|
469
|
+
</span>
|
|
470
|
+
</button>
|
|
471
|
+
<button
|
|
472
|
+
v-if="props.clearable && props.modelValue !== null && !props.disabled"
|
|
473
|
+
type="button"
|
|
474
|
+
:aria-label="labels.clearSelection"
|
|
475
|
+
class="absolute top-1/2 right-8 -translate-y-1/2 rounded text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
|
476
|
+
@click="clear"
|
|
477
|
+
>
|
|
478
|
+
<slot name="clear-icon">
|
|
479
|
+
<XIcon />
|
|
480
|
+
</slot>
|
|
481
|
+
</button>
|
|
482
|
+
|
|
483
|
+
<div
|
|
484
|
+
v-if="open"
|
|
485
|
+
ref="panelEl"
|
|
486
|
+
data-testid="search-select-panel"
|
|
487
|
+
:style="panelStyle"
|
|
488
|
+
class="fixed z-50 overflow-hidden rounded-md border border-border bg-popover shadow-lg"
|
|
489
|
+
>
|
|
490
|
+
<div class="flex items-center gap-2 border-b border-border px-2.5 py-2">
|
|
491
|
+
<span class="shrink-0 text-muted-foreground">
|
|
492
|
+
<slot name="search-icon">
|
|
493
|
+
<SearchIcon />
|
|
494
|
+
</slot>
|
|
495
|
+
</span>
|
|
496
|
+
<input
|
|
497
|
+
ref="searchEl"
|
|
498
|
+
data-testid="search-select-search"
|
|
499
|
+
type="text"
|
|
500
|
+
autocomplete="off"
|
|
501
|
+
aria-autocomplete="list"
|
|
502
|
+
:aria-label="searchText"
|
|
503
|
+
:aria-controls="listId"
|
|
504
|
+
:aria-activedescendant="activeDescendant"
|
|
505
|
+
:value="term"
|
|
506
|
+
:placeholder="searchText"
|
|
507
|
+
class="min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"
|
|
508
|
+
@input="onInput"
|
|
509
|
+
@keydown="onSearchKeydown"
|
|
510
|
+
/>
|
|
511
|
+
</div>
|
|
512
|
+
<!-- The list never takes focus: mousedown is held so a click cannot move it, and
|
|
513
|
+
tabindex -1 keeps a scrolling list from being a tab stop in Chrome. -->
|
|
514
|
+
<ul
|
|
515
|
+
:id="listId"
|
|
516
|
+
role="listbox"
|
|
517
|
+
tabindex="-1"
|
|
518
|
+
class="max-h-56 overflow-auto p-1"
|
|
519
|
+
@mousedown.prevent
|
|
520
|
+
>
|
|
521
|
+
<li v-if="props.loading" class="px-2 py-1.5 text-xs text-muted-foreground">
|
|
522
|
+
{{ labels.loadingResults }}
|
|
523
|
+
</li>
|
|
524
|
+
<template v-else>
|
|
525
|
+
<li
|
|
526
|
+
v-for="(option, index) in filtered"
|
|
527
|
+
:id="rowId(index)"
|
|
528
|
+
:key="option.value"
|
|
529
|
+
:data-testid="`search-select-option-${option.value}`"
|
|
530
|
+
:data-active="index === activeIndex ? '' : undefined"
|
|
531
|
+
role="option"
|
|
532
|
+
:aria-selected="option.value === props.modelValue"
|
|
533
|
+
:aria-disabled="option.disabled ? true : undefined"
|
|
534
|
+
:class="
|
|
535
|
+
cn(
|
|
536
|
+
'cursor-pointer rounded px-2 py-1.5 text-sm hover:bg-muted',
|
|
537
|
+
option.value === props.modelValue && 'bg-muted font-semibold',
|
|
538
|
+
option.disabled && 'cursor-not-allowed opacity-50',
|
|
539
|
+
// The wash alone is 1.1-1.3:1 against the list, too faint to be the
|
|
540
|
+
// only sign of where the keyboard is, so the highlighted entry also
|
|
541
|
+
// takes the focus colour.
|
|
542
|
+
index === activeIndex &&
|
|
543
|
+
'bg-accent text-accent-foreground ring-2 ring-ring ring-inset',
|
|
544
|
+
)
|
|
545
|
+
"
|
|
546
|
+
@click="pick(option)"
|
|
547
|
+
@mousemove="!option.disabled && (activeIndex = index)"
|
|
548
|
+
>
|
|
549
|
+
{{ option.label }}
|
|
550
|
+
</li>
|
|
551
|
+
<li
|
|
552
|
+
v-if="filtered.length === 0 && !showCreate"
|
|
553
|
+
class="px-2 py-1.5 text-xs text-muted-foreground"
|
|
554
|
+
>
|
|
555
|
+
{{ emptyMessage }}
|
|
556
|
+
</li>
|
|
557
|
+
<li
|
|
558
|
+
v-if="showCreate"
|
|
559
|
+
:id="rowId(createIndex)"
|
|
560
|
+
data-testid="search-select-create"
|
|
561
|
+
:data-active="createIndex === activeIndex ? '' : undefined"
|
|
562
|
+
role="option"
|
|
563
|
+
aria-selected="false"
|
|
564
|
+
:class="
|
|
565
|
+
cn(
|
|
566
|
+
// `--primary-on-wash` is the role that means ink on a wash,
|
|
567
|
+
// which is what this row draws: measured over a 5% wash of
|
|
568
|
+
// `--primary` on `--popover` it is 5.40-10.94 in the six
|
|
569
|
+
// theme/mode pairs, and 5.03-9.80 on the 10% wash the
|
|
570
|
+
// highlight uses. The panel's own instrument cannot see this
|
|
571
|
+
// row — it is `v-if`-gated, so it is outside the walk — which
|
|
572
|
+
// is why the figures are here.
|
|
573
|
+
//
|
|
574
|
+
// `border-primary/35` is a **deviation from the control-state
|
|
575
|
+
// recipe**'s no-halved-edges rule, named as one in CLAUDE.md's
|
|
576
|
+
// recipe section, and it stays: measured against the row's own
|
|
577
|
+
// wash it is 1.69-2.53:1 (1.65-1.99 on the 10% highlight wash,
|
|
578
|
+
// 1.81-2.80 against the popover beyond the row), under the 3:1
|
|
579
|
+
// an edge needs. It is decoration on a row whose *text* carries
|
|
580
|
+
// the state at 5.40-10.94:1, and it is dashed, which is the
|
|
581
|
+
// shape cue. Nothing here depends on it being seen; an edge
|
|
582
|
+
// that did would be at full strength.
|
|
583
|
+
'm-1 flex cursor-pointer items-center gap-2 rounded border border-dashed border-primary/35 bg-primary/5 px-2.5 py-2 text-sm font-medium text-primary-on-wash',
|
|
584
|
+
createIndex === activeIndex &&
|
|
585
|
+
'bg-primary/10 ring-2 ring-ring ring-inset',
|
|
586
|
+
)
|
|
587
|
+
"
|
|
588
|
+
@click="create"
|
|
589
|
+
@mousemove="activeIndex = createIndex"
|
|
590
|
+
>
|
|
591
|
+
<!-- Text, not an icon, so it has no slot; hidden so it is not read as part of the name. -->
|
|
592
|
+
<span aria-hidden="true" class="font-bold">+</span>
|
|
593
|
+
<span>{{ createText }}</span>
|
|
594
|
+
</li>
|
|
595
|
+
</template>
|
|
596
|
+
</ul>
|
|
597
|
+
</div>
|
|
598
|
+
</div>
|
|
599
|
+
</template>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One entry of a `SearchSelect`'s list.
|
|
3
|
+
*
|
|
4
|
+
* It lives in a plain module rather than inside the SFC because the `exports` map is this
|
|
5
|
+
* package's public API (invariant 9): a type resolved out of a `.vue` file needs the Vue
|
|
6
|
+
* TypeScript plugin on the consumer's side, and every other family puts its public type in a
|
|
7
|
+
* `.ts` of its own.
|
|
8
|
+
*/
|
|
9
|
+
export interface SearchSelectOption {
|
|
10
|
+
/** The value emitted when this one is chosen. */
|
|
11
|
+
value: string | number;
|
|
12
|
+
label: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|