@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,399 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { formatLabel, useUiLabels } from '@noix-dev/brix-core';
|
|
3
|
+
import { computed, ref, useId, watch } from 'vue';
|
|
4
|
+
import { DialogSurface } from '../dialog';
|
|
5
|
+
import { SearchIcon } from '../icon';
|
|
6
|
+
import { Input } from '../input';
|
|
7
|
+
import { Keycap } from '../keycap';
|
|
8
|
+
import { splitMatches, type ResultRow, type ResultSection } from './results';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The window a product opens to search and jump: a field, grouped rows with the match
|
|
12
|
+
* highlighted, an empty state, a failure state and a keyboard contract, on the published
|
|
13
|
+
* `DialogSurface`. Sections arrive as a prop; a selection leaves as `select`, carrying what the
|
|
14
|
+
* row opens. Nothing here ranks, filters or knows what a record is.
|
|
15
|
+
*
|
|
16
|
+
* - **It is a result window and not a search**, by name, because of two numbers: the product
|
|
17
|
+
* knowledge that produces a result list is 565 lines across three files in the model this
|
|
18
|
+
* replaces, and the window that displays it is 367. A family called "search" promises help with
|
|
19
|
+
* the first number and delivers help with the second.
|
|
20
|
+
* - **`pending` exists because of one keystroke.** Enter while a query is still in flight must not
|
|
21
|
+
* open the row on screen from the previous answer: a fast typist would open the wrong record.
|
|
22
|
+
* The model awaits its own request, which this package cannot, because owning a request is what
|
|
23
|
+
* it must not do. So Enter is held while `pending` is true and the selection is emitted once it
|
|
24
|
+
* clears. A callback prop returning a promise was rejected: it type-checks, and it is the
|
|
25
|
+
* component reaching into the application's transport through a side door (decision 0017).
|
|
26
|
+
* A held Enter does not open anything if the answer failed.
|
|
27
|
+
* - **The selection is remembered by what the row opens** (`ResultRow.opens`), not by its index,
|
|
28
|
+
* so a refreshed answer that still holds the target keeps it selected. Rows that open the same
|
|
29
|
+
* thing are told apart by the position the selection held: the nearest one wins. When the
|
|
30
|
+
* target is gone it falls to the first row of the first section that has rows. A section with no
|
|
31
|
+
* rows draws no heading and is skipped by the selection. Arrow keys wrap.
|
|
32
|
+
* - **The match is highlighted from `query`, longest term first, in the label and in the
|
|
33
|
+
* secondary line.** The model matches on both and highlights only the label, so a row could match
|
|
34
|
+
* on something never shown as matching. The highlight is built from text segments rendered as
|
|
35
|
+
* nodes: there is no `v-html`, so a query containing markup is drawn as the characters typed.
|
|
36
|
+
* The mark is bold and underlined and names no colour, so it holds on the selected row's wash.
|
|
37
|
+
* - **The expanded state is derived**, from whether there are rows to show, not hardcoded (the
|
|
38
|
+
* model's was). The field is a combobox over a listbox with grouped options.
|
|
39
|
+
* - **One polite `role="status"` element changes its text**: the result count, the headings when
|
|
40
|
+
* they changed since the last answer (a scope change), the empty state, or the failure. The
|
|
41
|
+
* window renders only while it is open, so the element is inserted already holding text at open,
|
|
42
|
+
* which is announced unreliably; what a screen reader reliably gets is a CHANGE while the window
|
|
43
|
+
* stays open, such as a new count or a failure, and that is the valuable half. Two answers with
|
|
44
|
+
* the same count and the same scope announce nothing, because the text does not change. Nothing
|
|
45
|
+
* is announced while `pending`, so a stale answer is not repeated.
|
|
46
|
+
* - **Choosing a row closes the window.** A selection emits `select` and `update:open` with
|
|
47
|
+
* `false` together, as Escape and an outside press already emit `update:open`, so a consumer that
|
|
48
|
+
* binds `v-model:open` is correct without handling the selection to close. The component is
|
|
49
|
+
* controlled: a consumer that wants it to stay open does not act on that event.
|
|
50
|
+
* - **Row and heading ids are built from position, never from `ResultRow.id`.** An id is a
|
|
51
|
+
* consumer's string and need not be unique across sections or free of whitespace, and
|
|
52
|
+
* `aria-activedescendant` is one IDREF: a duplicate resolves to the first element and a space
|
|
53
|
+
* names none. `id` stays the render key only.
|
|
54
|
+
* - **The only slot is `magnifier`**, with a drawn default (decision 0013). There is no row slot:
|
|
55
|
+
* highlighting both lines is this family's job and a row slot would hand it to the caller.
|
|
56
|
+
*
|
|
57
|
+
* COPY comes from the label contract (`resultWindow*`) and none of it is a prop.
|
|
58
|
+
*/
|
|
59
|
+
const props = withDefaults(
|
|
60
|
+
defineProps<{
|
|
61
|
+
open: boolean;
|
|
62
|
+
sections: ResultSection[];
|
|
63
|
+
query: string;
|
|
64
|
+
/** While true, Enter is held: it must not open a row from the previous answer. */
|
|
65
|
+
pending?: boolean;
|
|
66
|
+
failed?: boolean;
|
|
67
|
+
}>(),
|
|
68
|
+
{ pending: false, failed: false },
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const emit = defineEmits<{
|
|
72
|
+
(e: 'update:open', open: boolean): void;
|
|
73
|
+
(e: 'update:query', query: string): void;
|
|
74
|
+
(e: 'select', opens: string): void;
|
|
75
|
+
}>();
|
|
76
|
+
|
|
77
|
+
defineSlots<{ magnifier?: () => unknown }>();
|
|
78
|
+
|
|
79
|
+
const labels = useUiLabels();
|
|
80
|
+
const uid = useId();
|
|
81
|
+
const listId = `${uid}-list`;
|
|
82
|
+
// Built from position, never from a consumer string (see the docblock).
|
|
83
|
+
const rowId = (sectionIndex: number, rowIndex: number): string =>
|
|
84
|
+
`${uid}-row-${sectionIndex}-${rowIndex}`;
|
|
85
|
+
const headingId = (sectionIndex: number): string => `${uid}-heading-${sectionIndex}`;
|
|
86
|
+
|
|
87
|
+
/** Only the sections with rows: an empty one has no heading and no place in the selection. */
|
|
88
|
+
const visible = computed(() => props.sections.filter((section) => section.rows.length > 0));
|
|
89
|
+
const flat = computed(() => visible.value.flatMap((section) => section.rows));
|
|
90
|
+
/** Where each flat row sits: its section and its position inside it, for ids. */
|
|
91
|
+
const places = computed(() =>
|
|
92
|
+
visible.value.flatMap((section, sectionIndex) =>
|
|
93
|
+
section.rows.map((_, rowIndex) => ({ sectionIndex, rowIndex })),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
/** The flat index of each visible section's first row, so a row in the template can name its own. */
|
|
97
|
+
const starts = computed(() => {
|
|
98
|
+
let next = 0;
|
|
99
|
+
return visible.value.map((section) => {
|
|
100
|
+
const start = next;
|
|
101
|
+
next += section.rows.length;
|
|
102
|
+
return start;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
function flatIndex(sectionIndex: number, rowIndex: number): number {
|
|
106
|
+
return (starts.value[sectionIndex] ?? 0) + rowIndex;
|
|
107
|
+
}
|
|
108
|
+
function idAt(index: number): string | undefined {
|
|
109
|
+
const place = places.value[index];
|
|
110
|
+
return place === undefined ? undefined : rowId(place.sectionIndex, place.rowIndex);
|
|
111
|
+
}
|
|
112
|
+
const total = computed(() => flat.value.length);
|
|
113
|
+
const expanded = computed(() => total.value > 0 && !props.failed);
|
|
114
|
+
|
|
115
|
+
const remembered = ref<string | null>(null);
|
|
116
|
+
/** The flat position the remembered row held: it picks between rows that open the same thing. */
|
|
117
|
+
const rememberedAt = ref(0);
|
|
118
|
+
const currentIndex = computed<number>(() => {
|
|
119
|
+
let best = -1;
|
|
120
|
+
flat.value.forEach((row, index) => {
|
|
121
|
+
if (
|
|
122
|
+
row.opens === remembered.value &&
|
|
123
|
+
(best === -1 ||
|
|
124
|
+
Math.abs(index - rememberedAt.value) < Math.abs(best - rememberedAt.value))
|
|
125
|
+
) {
|
|
126
|
+
best = index;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return best === -1 && flat.value.length > 0 ? 0 : best;
|
|
130
|
+
});
|
|
131
|
+
const current = computed<ResultRow | null>(() => flat.value[currentIndex.value] ?? null);
|
|
132
|
+
// Settle the memory on what is actually selected, so a target that returns later does not pull
|
|
133
|
+
// the selection back from where the fallback put it. An empty answer keeps the memory.
|
|
134
|
+
watch(
|
|
135
|
+
[current, currentIndex],
|
|
136
|
+
([row, index]) => {
|
|
137
|
+
if (row !== null) {
|
|
138
|
+
remembered.value = row.opens;
|
|
139
|
+
rememberedAt.value = index;
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
{ immediate: true },
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
function select(index: number): void {
|
|
146
|
+
const row = flat.value[index];
|
|
147
|
+
if (row !== undefined) {
|
|
148
|
+
remembered.value = row.opens;
|
|
149
|
+
rememberedAt.value = index;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function move(step: 1 | -1): void {
|
|
154
|
+
const count = flat.value.length;
|
|
155
|
+
if (count === 0) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const next = (Math.max(currentIndex.value, 0) + step + count) % count;
|
|
159
|
+
select(next);
|
|
160
|
+
const id = idAt(next);
|
|
161
|
+
if (id !== undefined) {
|
|
162
|
+
// Focus stays in the field, so nothing else scrolls the row into view.
|
|
163
|
+
document.getElementById(id)?.scrollIntoView?.({ block: 'nearest' });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const enterHeld = ref(false);
|
|
168
|
+
|
|
169
|
+
function choose(): void {
|
|
170
|
+
if (current.value !== null) {
|
|
171
|
+
emit('select', current.value.opens);
|
|
172
|
+
emit('update:open', false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** A pointer choice: the same emission as Enter, for the row under the pointer. */
|
|
177
|
+
function choosePointed(index: number): void {
|
|
178
|
+
select(index);
|
|
179
|
+
choose();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function onKeydown(event: KeyboardEvent): void {
|
|
183
|
+
// Enter that commits an IME composition belongs to the composition, not to the list.
|
|
184
|
+
if (event.isComposing) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
move(event.key === 'ArrowDown' ? 1 : -1);
|
|
190
|
+
} else if (event.key === 'Enter') {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
if (props.pending) {
|
|
193
|
+
enterHeld.value = true;
|
|
194
|
+
} else {
|
|
195
|
+
choose();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
watch(
|
|
201
|
+
() => props.pending,
|
|
202
|
+
(pending) => {
|
|
203
|
+
if (!pending && enterHeld.value) {
|
|
204
|
+
enterHeld.value = false;
|
|
205
|
+
if (!props.failed) {
|
|
206
|
+
choose();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
watch(
|
|
213
|
+
() => props.open,
|
|
214
|
+
(open) => {
|
|
215
|
+
if (!open) {
|
|
216
|
+
enterHeld.value = false;
|
|
217
|
+
lastScope = null;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const scope = computed(() => visible.value.map((section) => section.heading).join(', '));
|
|
223
|
+
let lastScope: string | null = null;
|
|
224
|
+
const announcement = ref('');
|
|
225
|
+
|
|
226
|
+
watch(
|
|
227
|
+
[() => props.failed, () => props.pending, total, scope],
|
|
228
|
+
() => {
|
|
229
|
+
if (props.failed) {
|
|
230
|
+
announcement.value = labels.value.resultWindowFailed;
|
|
231
|
+
} else if (props.pending) {
|
|
232
|
+
return;
|
|
233
|
+
} else if (total.value === 0) {
|
|
234
|
+
announcement.value = labels.value.resultWindowEmpty;
|
|
235
|
+
} else {
|
|
236
|
+
const count = formatLabel(labels.value.resultWindowCount, { count: total.value });
|
|
237
|
+
announcement.value =
|
|
238
|
+
lastScope !== null && lastScope !== scope.value
|
|
239
|
+
? `${count}. ${formatLabel(labels.value.resultWindowScope, { scope: scope.value })}`
|
|
240
|
+
: count;
|
|
241
|
+
lastScope = scope.value;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{ immediate: true },
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
function onInput(value: string | number): void {
|
|
248
|
+
emit('update:query', String(value));
|
|
249
|
+
}
|
|
250
|
+
</script>
|
|
251
|
+
|
|
252
|
+
<template>
|
|
253
|
+
<DialogSurface
|
|
254
|
+
:open="open"
|
|
255
|
+
:label="labels.resultWindowName"
|
|
256
|
+
:described="false"
|
|
257
|
+
class="flex flex-col overflow-hidden p-0"
|
|
258
|
+
@update:open="emit('update:open', $event)"
|
|
259
|
+
>
|
|
260
|
+
<div class="border-border flex items-center gap-2 border-b px-3 py-2">
|
|
261
|
+
<span data-testid="result-magnifier" class="text-muted-foreground inline-flex shrink-0">
|
|
262
|
+
<slot name="magnifier"><SearchIcon class="size-4" /></slot>
|
|
263
|
+
</span>
|
|
264
|
+
<Input
|
|
265
|
+
:model-value="query"
|
|
266
|
+
role="combobox"
|
|
267
|
+
autocomplete="off"
|
|
268
|
+
:placeholder="labels.resultWindowPlaceholder"
|
|
269
|
+
:aria-label="labels.resultWindowField"
|
|
270
|
+
:aria-expanded="expanded ? 'true' : 'false'"
|
|
271
|
+
:aria-controls="expanded ? listId : undefined"
|
|
272
|
+
:aria-activedescendant="expanded ? idAt(currentIndex) : undefined"
|
|
273
|
+
aria-autocomplete="list"
|
|
274
|
+
aria-haspopup="listbox"
|
|
275
|
+
@update:model-value="onInput"
|
|
276
|
+
@keydown="onKeydown"
|
|
277
|
+
/>
|
|
278
|
+
</div>
|
|
279
|
+
|
|
280
|
+
<p role="status" aria-live="polite" data-testid="result-status" class="sr-only">
|
|
281
|
+
{{ announcement }}
|
|
282
|
+
</p>
|
|
283
|
+
|
|
284
|
+
<div class="min-h-0 flex-1 overflow-y-auto">
|
|
285
|
+
<p
|
|
286
|
+
v-if="failed"
|
|
287
|
+
data-testid="result-failed"
|
|
288
|
+
aria-hidden="true"
|
|
289
|
+
class="text-destructive px-4 py-6 text-center text-sm"
|
|
290
|
+
>
|
|
291
|
+
{{ labels.resultWindowFailed }}
|
|
292
|
+
</p>
|
|
293
|
+
<p
|
|
294
|
+
v-else-if="total === 0"
|
|
295
|
+
data-testid="result-empty"
|
|
296
|
+
aria-hidden="true"
|
|
297
|
+
class="text-muted-foreground px-4 py-6 text-center text-sm"
|
|
298
|
+
>
|
|
299
|
+
{{ labels.resultWindowEmpty }}
|
|
300
|
+
</p>
|
|
301
|
+
<div
|
|
302
|
+
v-else
|
|
303
|
+
:id="listId"
|
|
304
|
+
role="listbox"
|
|
305
|
+
:aria-label="labels.resultWindowField"
|
|
306
|
+
:aria-busy="pending ? 'true' : undefined"
|
|
307
|
+
class="p-1"
|
|
308
|
+
>
|
|
309
|
+
<div
|
|
310
|
+
v-for="(section, sectionIndex) in visible"
|
|
311
|
+
:key="section.key"
|
|
312
|
+
role="group"
|
|
313
|
+
:aria-labelledby="headingId(sectionIndex)"
|
|
314
|
+
>
|
|
315
|
+
<div
|
|
316
|
+
:id="headingId(sectionIndex)"
|
|
317
|
+
data-slot="result-heading"
|
|
318
|
+
class="text-muted-foreground px-3 pt-2 pb-1 text-xs font-semibold"
|
|
319
|
+
>
|
|
320
|
+
{{ section.heading }}
|
|
321
|
+
</div>
|
|
322
|
+
<div
|
|
323
|
+
v-for="(row, rowIndex) in section.rows"
|
|
324
|
+
:id="rowId(sectionIndex, rowIndex)"
|
|
325
|
+
:key="row.id"
|
|
326
|
+
role="option"
|
|
327
|
+
data-slot="result-row"
|
|
328
|
+
:aria-selected="
|
|
329
|
+
flatIndex(sectionIndex, rowIndex) === currentIndex ? 'true' : 'false'
|
|
330
|
+
"
|
|
331
|
+
:class="[
|
|
332
|
+
'flex min-w-0 cursor-pointer flex-col rounded-md px-3 py-1.5 text-sm',
|
|
333
|
+
flatIndex(sectionIndex, rowIndex) === currentIndex
|
|
334
|
+
? 'bg-accent text-accent-foreground'
|
|
335
|
+
: 'text-popover-foreground',
|
|
336
|
+
]"
|
|
337
|
+
@pointermove="select(flatIndex(sectionIndex, rowIndex))"
|
|
338
|
+
@click="choosePointed(flatIndex(sectionIndex, rowIndex))"
|
|
339
|
+
>
|
|
340
|
+
<span data-slot="result-label" class="truncate">
|
|
341
|
+
<template
|
|
342
|
+
v-for="(part, index) in splitMatches(row.label, query)"
|
|
343
|
+
:key="index"
|
|
344
|
+
>
|
|
345
|
+
<mark
|
|
346
|
+
v-if="part.match"
|
|
347
|
+
class="bg-transparent font-bold text-inherit underline"
|
|
348
|
+
>{{ part.text }}</mark><template v-else>{{
|
|
349
|
+
part.text
|
|
350
|
+
}}</template>
|
|
351
|
+
</template>
|
|
352
|
+
</span>
|
|
353
|
+
<span
|
|
354
|
+
v-if="row.secondary"
|
|
355
|
+
data-slot="result-secondary"
|
|
356
|
+
:class="[
|
|
357
|
+
'truncate text-xs',
|
|
358
|
+
flatIndex(sectionIndex, rowIndex) === currentIndex
|
|
359
|
+
? 'text-accent-foreground'
|
|
360
|
+
: 'text-muted-foreground',
|
|
361
|
+
]"
|
|
362
|
+
>
|
|
363
|
+
<template
|
|
364
|
+
v-for="(part, index) in splitMatches(row.secondary, query)"
|
|
365
|
+
:key="index"
|
|
366
|
+
>
|
|
367
|
+
<mark
|
|
368
|
+
v-if="part.match"
|
|
369
|
+
class="bg-transparent font-bold text-inherit underline"
|
|
370
|
+
>{{ part.text }}</mark><template v-else>{{
|
|
371
|
+
part.text
|
|
372
|
+
}}</template>
|
|
373
|
+
</template>
|
|
374
|
+
</span>
|
|
375
|
+
</div>
|
|
376
|
+
</div>
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
|
|
380
|
+
<div
|
|
381
|
+
data-testid="result-hints"
|
|
382
|
+
class="border-border text-muted-foreground flex items-center gap-4 border-t px-3 py-2 text-xs"
|
|
383
|
+
>
|
|
384
|
+
<span class="inline-flex items-center gap-1.5">
|
|
385
|
+
<Keycap :keys="['↑']" />
|
|
386
|
+
<Keycap :keys="['↓']" />
|
|
387
|
+
{{ labels.resultWindowHintMove }}
|
|
388
|
+
</span>
|
|
389
|
+
<span class="inline-flex items-center gap-1.5">
|
|
390
|
+
<Keycap :keys="['↵']" />
|
|
391
|
+
{{ labels.resultWindowHintOpen }}
|
|
392
|
+
</span>
|
|
393
|
+
<span class="inline-flex items-center gap-1.5">
|
|
394
|
+
<Keycap :keys="['Esc']" />
|
|
395
|
+
{{ labels.resultWindowHintClose }}
|
|
396
|
+
</span>
|
|
397
|
+
</div>
|
|
398
|
+
</DialogSurface>
|
|
399
|
+
</template>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One row of the result window. `opens` is what the row leads to, and what a selection is
|
|
3
|
+
* remembered by.
|
|
4
|
+
*/
|
|
5
|
+
export interface ResultRow {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** A second line, matched and highlighted like the label. */
|
|
9
|
+
secondary?: string;
|
|
10
|
+
/** What choosing the row opens: a route, a record key, a command name. The consumer's own. */
|
|
11
|
+
opens: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A headed group of rows. A section with no rows draws no heading and is skipped by the
|
|
16
|
+
* selection.
|
|
17
|
+
*/
|
|
18
|
+
export interface ResultSection {
|
|
19
|
+
key: string;
|
|
20
|
+
heading: string;
|
|
21
|
+
rows: ResultRow[];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A run of text, and whether the query matched it. */
|
|
25
|
+
export interface MatchSegment {
|
|
26
|
+
text: string;
|
|
27
|
+
match: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Splits `text` into the runs the query matches and the runs it does not, longest term first.
|
|
32
|
+
*
|
|
33
|
+
* The query is split on whitespace into terms; the terms are tried longest first so that `ab abc`
|
|
34
|
+
* against `abcd` marks `abc`, not `ab`. Matching is case-insensitive and the terms are escaped, so
|
|
35
|
+
* a query of `(` is the character it is. The result is plain text segments: nothing here builds
|
|
36
|
+
* markup, so a query that contains markup is drawn as the characters the user typed.
|
|
37
|
+
*/
|
|
38
|
+
export function splitMatches(text: string, query: string): MatchSegment[] {
|
|
39
|
+
const seen = new Set<string>();
|
|
40
|
+
const terms = query
|
|
41
|
+
.split(/\s+/)
|
|
42
|
+
.filter((term) => term !== '')
|
|
43
|
+
.filter((term) => {
|
|
44
|
+
const folded = term.toLowerCase();
|
|
45
|
+
if (seen.has(folded)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
seen.add(folded);
|
|
49
|
+
return true;
|
|
50
|
+
})
|
|
51
|
+
.sort((a, b) => b.length - a.length);
|
|
52
|
+
|
|
53
|
+
if (terms.length === 0 || text === '') {
|
|
54
|
+
return [{ text, match: false }];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const pattern = new RegExp(
|
|
58
|
+
terms.map((term) => term.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|'),
|
|
59
|
+
'gi',
|
|
60
|
+
);
|
|
61
|
+
const segments: MatchSegment[] = [];
|
|
62
|
+
let cursor = 0;
|
|
63
|
+
for (const found of text.matchAll(pattern)) {
|
|
64
|
+
const start = found.index;
|
|
65
|
+
if (start > cursor) {
|
|
66
|
+
segments.push({ text: text.slice(cursor, start), match: false });
|
|
67
|
+
}
|
|
68
|
+
segments.push({ text: found[0], match: true });
|
|
69
|
+
cursor = start + found[0].length;
|
|
70
|
+
}
|
|
71
|
+
if (cursor < text.length) {
|
|
72
|
+
segments.push({ text: text.slice(cursor), match: false });
|
|
73
|
+
}
|
|
74
|
+
return segments.length > 0 ? segments : [{ text, match: false }];
|
|
75
|
+
}
|