@molecule/app-search-ui-vue 0.0.0-stage → 1.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 +202 -0
- package/README.md +663 -2
- package/dist/Highlight.d.ts +34 -0
- package/dist/Highlight.d.ts.map +1 -0
- package/dist/Highlight.js +30 -0
- package/dist/Highlight.js.map +1 -0
- package/dist/Kbd.d.ts +22 -0
- package/dist/Kbd.d.ts.map +1 -0
- package/dist/Kbd.js +44 -0
- package/dist/Kbd.js.map +1 -0
- package/dist/QuickSearchDialog.d.ts +119 -0
- package/dist/QuickSearchDialog.d.ts.map +1 -0
- package/dist/QuickSearchDialog.js +150 -0
- package/dist/QuickSearchDialog.js.map +1 -0
- package/dist/SearchBox.d.ts +152 -0
- package/dist/SearchBox.d.ts.map +1 -0
- package/dist/SearchBox.js +217 -0
- package/dist/SearchBox.js.map +1 -0
- package/dist/SearchResults.d.ts +111 -0
- package/dist/SearchResults.d.ts.map +1 -0
- package/dist/SearchResults.js +179 -0
- package/dist/SearchResults.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +163 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -4
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue search field — the counterpart of `@molecule/app-search-ui-react`'s
|
|
3
|
+
* `SearchBox`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { defineComponent, h, onMounted, ref, watch, } from 'vue';
|
|
8
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
9
|
+
import { Icon, Tooltip } from '@molecule/app-ui-vue';
|
|
10
|
+
import { useTranslation } from '@molecule/app-vue';
|
|
11
|
+
import { Kbd } from './Kbd.js';
|
|
12
|
+
/**
|
|
13
|
+
* Resolves a node-valued prop that may also arrive as a same-named slot: the
|
|
14
|
+
* slot wins, and an absent pair contributes nothing.
|
|
15
|
+
*
|
|
16
|
+
* @param slot - The slot render function, when the caller passed the slot.
|
|
17
|
+
* @param prop - The prop value, when the caller passed the prop.
|
|
18
|
+
* @returns The children to render.
|
|
19
|
+
*/
|
|
20
|
+
const nodeOrSlot = (slot, prop) => {
|
|
21
|
+
if (slot)
|
|
22
|
+
return slot();
|
|
23
|
+
if (prop === undefined || prop === null || prop === false)
|
|
24
|
+
return [];
|
|
25
|
+
return Array.isArray(prop) ? prop : [prop];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A search field: a leading icon, the input, a help icon that shows the
|
|
29
|
+
* syntax on hover, an × to clear, and the shortcut cap; under it, whatever
|
|
30
|
+
* `afterField` holds, then the active filters as removable chips and the
|
|
31
|
+
* hit count. The field stays mounted, and its text with it, across searches.
|
|
32
|
+
*
|
|
33
|
+
* @param props - See {@link SearchBoxProps}.
|
|
34
|
+
* @returns The field component.
|
|
35
|
+
*/
|
|
36
|
+
export const SearchBox = defineComponent({
|
|
37
|
+
name: 'SearchBox',
|
|
38
|
+
props: {
|
|
39
|
+
value: { type: String, required: true },
|
|
40
|
+
onChange: { type: Function, required: true },
|
|
41
|
+
onKeyDown: {
|
|
42
|
+
type: Function,
|
|
43
|
+
default: undefined,
|
|
44
|
+
},
|
|
45
|
+
inputRef: {
|
|
46
|
+
type: Object,
|
|
47
|
+
default: undefined,
|
|
48
|
+
},
|
|
49
|
+
placeholder: { type: String, required: true },
|
|
50
|
+
label: { type: String, default: undefined },
|
|
51
|
+
count: { type: Number, default: undefined },
|
|
52
|
+
filters: { type: Array, default: () => [] },
|
|
53
|
+
onRemoveFilter: {
|
|
54
|
+
type: Function,
|
|
55
|
+
default: undefined,
|
|
56
|
+
},
|
|
57
|
+
onClear: { type: Function, default: undefined },
|
|
58
|
+
examples: { type: Array, default: undefined },
|
|
59
|
+
shortcut: { type: null, default: '/' },
|
|
60
|
+
autoFocus: { type: Boolean, default: false },
|
|
61
|
+
afterField: null,
|
|
62
|
+
molId: { type: String, default: 'search' },
|
|
63
|
+
className: String,
|
|
64
|
+
},
|
|
65
|
+
setup(props, { slots }) {
|
|
66
|
+
const cm = getClassMap();
|
|
67
|
+
const { t } = useTranslation();
|
|
68
|
+
const focused = ref(false);
|
|
69
|
+
// Focus the input on mount and whenever the ask (or the ref) changes, the
|
|
70
|
+
// way React's effect keyed on `autoFocus` and `inputRef` does.
|
|
71
|
+
const focusInput = () => {
|
|
72
|
+
if (props.autoFocus)
|
|
73
|
+
props.inputRef?.current?.focus();
|
|
74
|
+
};
|
|
75
|
+
onMounted(focusInput);
|
|
76
|
+
watch([() => props.autoFocus, () => props.inputRef], focusInput);
|
|
77
|
+
/**
|
|
78
|
+
* Assigns the input element into `inputRef` so a shortcut can focus it,
|
|
79
|
+
* and so the consumer reads the element React's `ref` would hand over.
|
|
80
|
+
*
|
|
81
|
+
* @param el - The input element, or `null` as it unmounts.
|
|
82
|
+
*/
|
|
83
|
+
const inputRefFn = (el) => {
|
|
84
|
+
if (props.inputRef)
|
|
85
|
+
props.inputRef.current = el ?? null;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Reports the typed text, then restores the field to the value the props
|
|
89
|
+
* still hold, the way React's controlled input renders it back when the
|
|
90
|
+
* caller keeps the old one.
|
|
91
|
+
*
|
|
92
|
+
* @param event - The input event.
|
|
93
|
+
*/
|
|
94
|
+
const onInput = (event) => {
|
|
95
|
+
const el = event.target;
|
|
96
|
+
props.onChange(el.value);
|
|
97
|
+
el.value = props.value;
|
|
98
|
+
};
|
|
99
|
+
/** Clears the text and puts focus back in the field, as React's button does. */
|
|
100
|
+
const onClearClick = () => {
|
|
101
|
+
props.onClear?.();
|
|
102
|
+
props.inputRef?.current?.focus();
|
|
103
|
+
};
|
|
104
|
+
return () => {
|
|
105
|
+
const value = props.value;
|
|
106
|
+
const showCount = props.count !== undefined && value.trim().length > 0;
|
|
107
|
+
const showHelp = Boolean(props.examples?.length);
|
|
108
|
+
const hasStatus = props.filters.length > 0 || showCount;
|
|
109
|
+
// The tooltip's content class keeps short labels on one line; the tips
|
|
110
|
+
// are a sentence or two, so the inner block wraps on its own.
|
|
111
|
+
const help = showHelp
|
|
112
|
+
? h('div', { class: cm.searchTips, style: { whiteSpace: 'normal', maxWidth: '360px' } }, [
|
|
113
|
+
t('searchUi.syntax', undefined, {
|
|
114
|
+
defaultValue: 'Narrow with a field, quote a phrase, or exclude a word:',
|
|
115
|
+
}),
|
|
116
|
+
' ',
|
|
117
|
+
...[
|
|
118
|
+
...(props.examples ?? []),
|
|
119
|
+
t('searchUi.examplePhrase', undefined, { defaultValue: '"exact phrase"' }),
|
|
120
|
+
t('searchUi.exampleExcluded', undefined, { defaultValue: '-word' }),
|
|
121
|
+
].map((ex, i) => h('span', { key: ex }, [i > 0 ? ' · ' : '', h('code', null, [ex])])),
|
|
122
|
+
' · ',
|
|
123
|
+
h(Kbd, () => ['↑']),
|
|
124
|
+
' ',
|
|
125
|
+
h(Kbd, () => ['↓']),
|
|
126
|
+
' ',
|
|
127
|
+
h(Kbd, () => ['↵']),
|
|
128
|
+
' ',
|
|
129
|
+
t('searchUi.keys', undefined, {
|
|
130
|
+
defaultValue: 'The arrow keys move through the results and Enter opens one.',
|
|
131
|
+
}),
|
|
132
|
+
])
|
|
133
|
+
: null;
|
|
134
|
+
const input = h('input', {
|
|
135
|
+
ref: inputRefFn,
|
|
136
|
+
type: 'search',
|
|
137
|
+
value,
|
|
138
|
+
onInput,
|
|
139
|
+
onKeydown: props.onKeyDown ?? undefined,
|
|
140
|
+
onFocusin: () => {
|
|
141
|
+
focused.value = true;
|
|
142
|
+
},
|
|
143
|
+
onFocusout: () => {
|
|
144
|
+
focused.value = false;
|
|
145
|
+
},
|
|
146
|
+
placeholder: props.placeholder,
|
|
147
|
+
'aria-label': props.label ?? props.placeholder,
|
|
148
|
+
autocomplete: 'off',
|
|
149
|
+
autocorrect: 'off',
|
|
150
|
+
spellcheck: 'false',
|
|
151
|
+
enterkeyhint: 'search',
|
|
152
|
+
class: cm.searchFieldInput,
|
|
153
|
+
'data-mol-id': `${props.molId}-input`,
|
|
154
|
+
});
|
|
155
|
+
const actions = [
|
|
156
|
+
help
|
|
157
|
+
? h(Tooltip, { content: help, placement: 'bottom-end' }, {
|
|
158
|
+
default: () => [
|
|
159
|
+
h('button', {
|
|
160
|
+
type: 'button',
|
|
161
|
+
'aria-label': t('searchUi.help', undefined, { defaultValue: 'Search tips' }),
|
|
162
|
+
class: cm.searchFieldClear,
|
|
163
|
+
'data-mol-id': `${props.molId}-help`,
|
|
164
|
+
}, [h(Icon, { name: 'question', size: 16 })]),
|
|
165
|
+
],
|
|
166
|
+
})
|
|
167
|
+
: null,
|
|
168
|
+
value && props.onClear
|
|
169
|
+
? h('button', {
|
|
170
|
+
type: 'button',
|
|
171
|
+
onClick: onClearClick,
|
|
172
|
+
'aria-label': t('searchUi.clear', undefined, { defaultValue: 'Clear search' }),
|
|
173
|
+
class: cm.searchFieldClear,
|
|
174
|
+
'data-mol-id': `${props.molId}-clear`,
|
|
175
|
+
}, [h('span', { 'aria-hidden': 'true' }, ['×'])])
|
|
176
|
+
: null,
|
|
177
|
+
props.shortcut && !value && !focused.value ? h(Kbd, () => [props.shortcut]) : null,
|
|
178
|
+
];
|
|
179
|
+
const statusRow = hasStatus
|
|
180
|
+
? h('div', { class: cm.searchStatusRow }, [
|
|
181
|
+
...props.filters.map((f, i) => {
|
|
182
|
+
const text = `${f.negate ? '−' : ''}${f.field}: ${f.values.join(', ')}`;
|
|
183
|
+
return h('button', {
|
|
184
|
+
key: `${f.field}:${f.values.join(',')}:${i}`,
|
|
185
|
+
type: 'button',
|
|
186
|
+
onClick: () => props.onRemoveFilter?.(i),
|
|
187
|
+
'aria-label': t('searchUi.removeFilter', { filter: text }, {
|
|
188
|
+
defaultValue: 'Remove filter {{filter}}',
|
|
189
|
+
}),
|
|
190
|
+
class: cm.cn(cm.filterChip, f.negate && cm.filterChipNegated),
|
|
191
|
+
'data-mol-id': `${props.molId}-filter`,
|
|
192
|
+
'data-filter-field': f.field,
|
|
193
|
+
}, [text, h('span', { class: cm.filterChipRemove, 'aria-hidden': 'true' }, ['×'])]);
|
|
194
|
+
}),
|
|
195
|
+
h('span', { class: cm.mxAuto }),
|
|
196
|
+
showCount
|
|
197
|
+
? h('span', { 'data-mol-id': `${props.molId}-count` }, [
|
|
198
|
+
t('searchUi.count', { count: props.count }, { defaultValue: '{{count}} results' }),
|
|
199
|
+
])
|
|
200
|
+
: null,
|
|
201
|
+
])
|
|
202
|
+
: null;
|
|
203
|
+
return h('div', { 'data-mol-id': `${props.molId}-box` }, [
|
|
204
|
+
h('div', { class: cm.cn(cm.searchField, props.className) }, [
|
|
205
|
+
h('span', { class: cm.searchFieldIcon, 'aria-hidden': 'true' }, [
|
|
206
|
+
h(Icon, { name: 'search', size: 18 }),
|
|
207
|
+
]),
|
|
208
|
+
input,
|
|
209
|
+
h('span', { class: cm.searchFieldActions }, actions),
|
|
210
|
+
]),
|
|
211
|
+
...nodeOrSlot(slots.afterField, props.afterField),
|
|
212
|
+
statusRow,
|
|
213
|
+
]);
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
//# sourceMappingURL=SearchBox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchBox.js","sourceRoot":"","sources":["../src/SearchBox.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,CAAC,EACD,SAAS,EAET,GAAG,EAGH,KAAK,GACN,MAAM,KAAK,CAAA;AAGZ,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAA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Results`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type PropType, type VNodeChild } from 'vue';
|
|
8
|
+
import type { SearchResultHit, SearchResultLinkProps, SearchResultView } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* The ranked hits: title and description with the matched terms marked, the
|
|
11
|
+
* meta line, hover making a row active and warming its page. The whole row is
|
|
12
|
+
* the link, so the list is a plain list of links (no listbox roles: an
|
|
13
|
+
* option's children are presentational and would hide the row's link and
|
|
14
|
+
* action); the active row is marked with `aria-current` on its `<li>` and
|
|
15
|
+
* announced through a polite, visually hidden status region after the list.
|
|
16
|
+
*
|
|
17
|
+
* @param props - See {@link SearchResultsProps}.
|
|
18
|
+
* @returns The results component.
|
|
19
|
+
*/
|
|
20
|
+
export declare const SearchResults: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
21
|
+
hits: {
|
|
22
|
+
type: PropType<SearchResultHit<unknown>[]>;
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
view: {
|
|
26
|
+
type: PropType<(doc: unknown) => SearchResultView>;
|
|
27
|
+
required: true;
|
|
28
|
+
};
|
|
29
|
+
activeIndex: {
|
|
30
|
+
type: NumberConstructor;
|
|
31
|
+
required: true;
|
|
32
|
+
};
|
|
33
|
+
onActivate: {
|
|
34
|
+
type: PropType<((index: number) => void) | undefined>;
|
|
35
|
+
default: undefined;
|
|
36
|
+
};
|
|
37
|
+
onOpen: {
|
|
38
|
+
type: PropType<(doc: unknown) => void>;
|
|
39
|
+
required: true;
|
|
40
|
+
};
|
|
41
|
+
onPrefetch: {
|
|
42
|
+
type: PropType<((doc: unknown) => void) | undefined>;
|
|
43
|
+
default: undefined;
|
|
44
|
+
};
|
|
45
|
+
renderLink: {
|
|
46
|
+
type: PropType<((linkProps: SearchResultLinkProps) => VNodeChild) | undefined>;
|
|
47
|
+
default: undefined;
|
|
48
|
+
};
|
|
49
|
+
action: {
|
|
50
|
+
type: PropType<((doc: unknown) => VNodeChild) | undefined>;
|
|
51
|
+
default: undefined;
|
|
52
|
+
};
|
|
53
|
+
emptyText: {
|
|
54
|
+
type: StringConstructor;
|
|
55
|
+
required: true;
|
|
56
|
+
};
|
|
57
|
+
molId: {
|
|
58
|
+
type: StringConstructor;
|
|
59
|
+
default: string;
|
|
60
|
+
};
|
|
61
|
+
className: StringConstructor;
|
|
62
|
+
}>, () => VNodeChild, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
63
|
+
hits: {
|
|
64
|
+
type: PropType<SearchResultHit<unknown>[]>;
|
|
65
|
+
required: true;
|
|
66
|
+
};
|
|
67
|
+
view: {
|
|
68
|
+
type: PropType<(doc: unknown) => SearchResultView>;
|
|
69
|
+
required: true;
|
|
70
|
+
};
|
|
71
|
+
activeIndex: {
|
|
72
|
+
type: NumberConstructor;
|
|
73
|
+
required: true;
|
|
74
|
+
};
|
|
75
|
+
onActivate: {
|
|
76
|
+
type: PropType<((index: number) => void) | undefined>;
|
|
77
|
+
default: undefined;
|
|
78
|
+
};
|
|
79
|
+
onOpen: {
|
|
80
|
+
type: PropType<(doc: unknown) => void>;
|
|
81
|
+
required: true;
|
|
82
|
+
};
|
|
83
|
+
onPrefetch: {
|
|
84
|
+
type: PropType<((doc: unknown) => void) | undefined>;
|
|
85
|
+
default: undefined;
|
|
86
|
+
};
|
|
87
|
+
renderLink: {
|
|
88
|
+
type: PropType<((linkProps: SearchResultLinkProps) => VNodeChild) | undefined>;
|
|
89
|
+
default: undefined;
|
|
90
|
+
};
|
|
91
|
+
action: {
|
|
92
|
+
type: PropType<((doc: unknown) => VNodeChild) | undefined>;
|
|
93
|
+
default: undefined;
|
|
94
|
+
};
|
|
95
|
+
emptyText: {
|
|
96
|
+
type: StringConstructor;
|
|
97
|
+
required: true;
|
|
98
|
+
};
|
|
99
|
+
molId: {
|
|
100
|
+
type: StringConstructor;
|
|
101
|
+
default: string;
|
|
102
|
+
};
|
|
103
|
+
className: StringConstructor;
|
|
104
|
+
}>> & Readonly<{}>, {
|
|
105
|
+
molId: string;
|
|
106
|
+
onActivate: ((index: number) => void) | undefined;
|
|
107
|
+
onPrefetch: ((doc: unknown) => void) | undefined;
|
|
108
|
+
renderLink: ((linkProps: SearchResultLinkProps) => VNodeChild) | undefined;
|
|
109
|
+
action: ((doc: unknown) => VNodeChild) | undefined;
|
|
110
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
111
|
+
//# sourceMappingURL=SearchResults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchResults.d.ts","sourceRoot":"","sources":["../src/SearchResults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAA;AAOxE,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAc1F;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa;;cAGC,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;;;;cAEvC,QAAQ,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,gBAAgB,CAAC;;;;;;;;cAK5C,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;;;;cAGvC,QAAQ,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;;;;cAExC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;;;;cAI9C,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,qBAAqB,KAAK,UAAU,CAAC,GAAG,SAAS,CAAC;;;;cAIxE,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;UA6B7D,UAAU;;cAjDE,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;;;;cAEvC,QAAQ,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,gBAAgB,CAAC;;;;;;;;cAK5C,QAAQ,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;;;;cAGvC,QAAQ,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;;;;cAExC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;;;;cAI9C,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,qBAAqB,KAAK,UAAU,CAAC,GAAG,SAAS,CAAC;;;;cAIxE,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,UAAU,CAAC,GAAG,SAAS,CAAC;;;;;;;;;;;;;;yBAblC,MAAM,KAAK,IAAI;uBAKjB,OAAO,KAAK,IAAI;6BAIV,qBAAqB,KAAK,UAAU;mBAI1C,OAAO,KAAK,UAAU;4EAmJ5D,CAAA"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue ranked search results — the counterpart of
|
|
3
|
+
* `@molecule/app-search-ui-react`'s `SearchResults`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { defineComponent, h } from 'vue';
|
|
8
|
+
import { onMounted, ref, watch } from 'vue';
|
|
9
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
10
|
+
import { useTranslation } from '@molecule/app-vue';
|
|
11
|
+
import { Highlight } from './Highlight.js';
|
|
12
|
+
/**
|
|
13
|
+
* The default row link: a plain anchor. Apps pass a router link instead; the
|
|
14
|
+
* opaque `state` is theirs to consume and never reaches the DOM.
|
|
15
|
+
*
|
|
16
|
+
* @param linkProps - The link props.
|
|
17
|
+
* @returns The anchor.
|
|
18
|
+
*/
|
|
19
|
+
const defaultLink = (linkProps) => {
|
|
20
|
+
const { state: _state, children, className, ...rest } = linkProps;
|
|
21
|
+
return h('a', { ...rest, class: className }, Array.isArray(children) ? children : [children]);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The ranked hits: title and description with the matched terms marked, the
|
|
25
|
+
* meta line, hover making a row active and warming its page. The whole row is
|
|
26
|
+
* the link, so the list is a plain list of links (no listbox roles: an
|
|
27
|
+
* option's children are presentational and would hide the row's link and
|
|
28
|
+
* action); the active row is marked with `aria-current` on its `<li>` and
|
|
29
|
+
* announced through a polite, visually hidden status region after the list.
|
|
30
|
+
*
|
|
31
|
+
* @param props - See {@link SearchResultsProps}.
|
|
32
|
+
* @returns The results component.
|
|
33
|
+
*/
|
|
34
|
+
export const SearchResults = defineComponent({
|
|
35
|
+
name: 'SearchResults',
|
|
36
|
+
props: {
|
|
37
|
+
hits: { type: Array, required: true },
|
|
38
|
+
view: {
|
|
39
|
+
type: Function,
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
activeIndex: { type: Number, required: true },
|
|
43
|
+
onActivate: {
|
|
44
|
+
type: Function,
|
|
45
|
+
default: undefined,
|
|
46
|
+
},
|
|
47
|
+
onOpen: { type: Function, required: true },
|
|
48
|
+
onPrefetch: {
|
|
49
|
+
type: Function,
|
|
50
|
+
default: undefined,
|
|
51
|
+
},
|
|
52
|
+
renderLink: {
|
|
53
|
+
type: Function,
|
|
54
|
+
default: undefined,
|
|
55
|
+
},
|
|
56
|
+
action: {
|
|
57
|
+
type: Function,
|
|
58
|
+
default: undefined,
|
|
59
|
+
},
|
|
60
|
+
emptyText: { type: String, required: true },
|
|
61
|
+
molId: { type: String, default: 'search' },
|
|
62
|
+
className: String,
|
|
63
|
+
},
|
|
64
|
+
setup(props) {
|
|
65
|
+
const cm = getClassMap();
|
|
66
|
+
const { t } = useTranslation();
|
|
67
|
+
const listRef = ref(null);
|
|
68
|
+
// Keep the keyboard-active row in view.
|
|
69
|
+
const keepInView = (index) => {
|
|
70
|
+
if (index < 0)
|
|
71
|
+
return;
|
|
72
|
+
const el = listRef.value?.querySelector(`[data-index="${index}"]`);
|
|
73
|
+
el?.scrollIntoView?.({ block: 'nearest' });
|
|
74
|
+
};
|
|
75
|
+
onMounted(() => keepInView(props.activeIndex));
|
|
76
|
+
watch(() => props.activeIndex, (index) => keepInView(index));
|
|
77
|
+
/** Assigns the list element into `listRef`, as React's `ref` does. */
|
|
78
|
+
const listRefFn = (el) => {
|
|
79
|
+
listRef.value = el ?? null;
|
|
80
|
+
};
|
|
81
|
+
return () => {
|
|
82
|
+
if (!props.hits.length) {
|
|
83
|
+
return [
|
|
84
|
+
h('p', { class: cm.resultEmpty, 'data-mol-id': `${props.molId}-empty` }, [
|
|
85
|
+
props.emptyText,
|
|
86
|
+
]),
|
|
87
|
+
// The status region exists before results arrive, so it is live.
|
|
88
|
+
h('p', { role: 'status', class: cm.srOnly, 'data-mol-id': `${props.molId}-active` }),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
// The active row's announcement; empty when no row is keyboard-active.
|
|
92
|
+
const activeHit = props.activeIndex >= 0 ? props.hits[props.activeIndex] : undefined;
|
|
93
|
+
const activeText = activeHit
|
|
94
|
+
? t('searchUi.activeResult', {
|
|
95
|
+
title: props.view(activeHit.doc).title,
|
|
96
|
+
position: props.activeIndex + 1,
|
|
97
|
+
count: props.hits.length,
|
|
98
|
+
}, { defaultValue: '{{title}}, {{position}} of {{count}}' })
|
|
99
|
+
: '';
|
|
100
|
+
const listItems = props.hits.map((hit, i) => {
|
|
101
|
+
const v = props.view(hit.doc);
|
|
102
|
+
const active = i === props.activeIndex;
|
|
103
|
+
const meta = [...(v.meta ?? [])];
|
|
104
|
+
const body = [
|
|
105
|
+
h('span', { class: cm.flex({ align: 'baseline', wrap: 'wrap', gap: 2 }) }, [
|
|
106
|
+
h('span', { class: cm.cn(cm.resultTitle, v.mono && cm.resultTitleMono) }, [
|
|
107
|
+
h(Highlight, { text: v.title, terms: hit.terms }),
|
|
108
|
+
]),
|
|
109
|
+
meta.length ? h('span', { class: cm.resultMeta }, [meta.join(' · ')]) : null,
|
|
110
|
+
hit.related
|
|
111
|
+
? h('span', {
|
|
112
|
+
class: cm.resultMeta,
|
|
113
|
+
'data-mol-id': `${props.molId}-related`,
|
|
114
|
+
title: t('searchUi.relatedTitle', undefined, {
|
|
115
|
+
defaultValue: 'Matches the meaning of your search, not its words',
|
|
116
|
+
}),
|
|
117
|
+
}, [t('searchUi.related', undefined, { defaultValue: 'related' })])
|
|
118
|
+
: null,
|
|
119
|
+
]),
|
|
120
|
+
v.description
|
|
121
|
+
? h('span', { class: cm.cn(cm.resultDescription, cm.displayBlock) }, [
|
|
122
|
+
h(Highlight, { text: v.description, terms: hit.terms }),
|
|
123
|
+
])
|
|
124
|
+
: null,
|
|
125
|
+
];
|
|
126
|
+
const linkProps = {
|
|
127
|
+
href: v.href,
|
|
128
|
+
state: v.state,
|
|
129
|
+
className: cm.resultBody,
|
|
130
|
+
'data-mol-id': `${props.molId}-link`,
|
|
131
|
+
children: body,
|
|
132
|
+
onClick: (event) => {
|
|
133
|
+
// A modified click opens a new tab; the router handles the rest.
|
|
134
|
+
if (event.metaKey ||
|
|
135
|
+
event.ctrlKey ||
|
|
136
|
+
event.shiftKey ||
|
|
137
|
+
event.altKey ||
|
|
138
|
+
event.button !== 0)
|
|
139
|
+
return;
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
props.onOpen(hit.doc);
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
const link = props.renderLink ? props.renderLink(linkProps) : defaultLink(linkProps);
|
|
145
|
+
return h('li', {
|
|
146
|
+
key: hit.id,
|
|
147
|
+
'aria-current': active ? 'true' : undefined,
|
|
148
|
+
'data-index': i,
|
|
149
|
+
'data-mol-id': `${props.molId}-hit`,
|
|
150
|
+
'data-hit-id': hit.id,
|
|
151
|
+
class: cm.cn(cm.resultItem, active && cm.resultItemActive),
|
|
152
|
+
onPointerover: () => {
|
|
153
|
+
props.onActivate?.(i);
|
|
154
|
+
props.onPrefetch?.(hit.doc);
|
|
155
|
+
},
|
|
156
|
+
onFocusin: () => props.onPrefetch?.(hit.doc),
|
|
157
|
+
onTouchstart: () => props.onPrefetch?.(hit.doc),
|
|
158
|
+
}, [
|
|
159
|
+
link,
|
|
160
|
+
props.action ? h('span', { class: cm.resultAction }, [props.action(hit.doc)]) : null,
|
|
161
|
+
]);
|
|
162
|
+
});
|
|
163
|
+
// React's root is a fragment: the list, then the status region that
|
|
164
|
+
// announces the keyboard-active row to screen readers.
|
|
165
|
+
return [
|
|
166
|
+
h('ul', {
|
|
167
|
+
ref: listRefFn,
|
|
168
|
+
'aria-label': t('searchUi.results', undefined, { defaultValue: 'Search results' }),
|
|
169
|
+
class: cm.cn(cm.resultList, props.className),
|
|
170
|
+
'data-mol-id': `${props.molId}-results`,
|
|
171
|
+
}, listItems),
|
|
172
|
+
h('p', { role: 'status', class: cm.srOnly, 'data-mol-id': `${props.molId}-active` }, [
|
|
173
|
+
activeText,
|
|
174
|
+
]),
|
|
175
|
+
];
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
//# sourceMappingURL=SearchResults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchResults.js","sourceRoot":"","sources":["../src/SearchResults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAAkC,MAAM,KAAK,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAG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AAC,GAAG,CAAC;iBAChD,EACD;oBACE,IAAI;oBACJ,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;iBACrF,CACF,CAAA;YACH,CAAC,CAAC,CAAA;YAEF,oEAAoE;YACpE,uDAAuD;YACvD,OAAO;gBACL,CAAC,CACC,IAAI,EACJ;oBACE,GAAG,EAAE,SAAS;oBACd,YAAY,EAAE,CAAC,CAAC,kBAAkB,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC;oBAClF,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;oBAC5C,aAAa,EAAE,GAAG,KAAK,CAAC,KAAK,UAAU;iBACxC,EACD,SAAS,CACV;gBACD,CAAC,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC,KAAK,SAAS,EAAE,EAAE;oBACnF,UAAU;iBACX,CAAC;aACH,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue search UI for `@molecule/app-client-search`.
|
|
3
|
+
*
|
|
4
|
+
* The Vue counterpart of `@molecule/app-search-ui-react` — the same props
|
|
5
|
+
* (React names) and the same DOM for the same input. Three pieces that fit a
|
|
6
|
+
* `useSearchSession` from `@molecule/app-client-search-vue`:
|
|
7
|
+
* {@link SearchBox} (the field, its clear button and shortcut cap, a help icon
|
|
8
|
+
* whose tooltip shows the search syntax, an `afterField` slot for the
|
|
9
|
+
* consumer's own tabs, the active filter chips and the hit count),
|
|
10
|
+
* {@link SearchResults} (ranked rows with the matched terms marked, hover
|
|
11
|
+
* prefetch, an optional action per row; the keyboard-active row is marked with
|
|
12
|
+
* `aria-current` and announced through a polite status region), and
|
|
13
|
+
* {@link QuickSearchDialog} (both in a `mod+k` dialog named for screen readers
|
|
14
|
+
* by its `label`, "Search" by default). Every class comes from
|
|
15
|
+
* the ClassMap's search tokens (`searchField`, `resultList`, …), so a UI bond
|
|
16
|
+
* restyles all of it at once.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { defineComponent, h } from 'vue'
|
|
21
|
+
* import { Link } from '@molecule/app-vue'
|
|
22
|
+
* import { useSearchSession } from '@molecule/app-client-search-vue'
|
|
23
|
+
* import { SearchBox, SearchResults } from '@molecule/app-search-ui-vue'
|
|
24
|
+
* import { useTranslation } from '@molecule/app-vue'
|
|
25
|
+
* import type { SearchResultLinkProps } from '@molecule/app-search-ui-vue'
|
|
26
|
+
*
|
|
27
|
+
* const Catalog = defineComponent({
|
|
28
|
+
* setup() {
|
|
29
|
+
* const { t } = useTranslation()
|
|
30
|
+
* const session = useSearchSession({
|
|
31
|
+
* docs: packages,
|
|
32
|
+
* options: PACKAGE_INDEX_OPTIONS,
|
|
33
|
+
* rememberKey: 'catalog.search',
|
|
34
|
+
* onOpen: (p) => router.push(`/packages/${p.name}`),
|
|
35
|
+
* })
|
|
36
|
+
* const renderLink = (p: SearchResultLinkProps) =>
|
|
37
|
+
* h(
|
|
38
|
+
* Link,
|
|
39
|
+
* { to: p.href, state: p.state, class: p.className, onClick: p.onClick, 'data-mol-id': p['data-mol-id'] },
|
|
40
|
+
* () => [p.children],
|
|
41
|
+
* )
|
|
42
|
+
* return () => [
|
|
43
|
+
* h(SearchBox, {
|
|
44
|
+
* value: session.query.value,
|
|
45
|
+
* onChange: session.setQuery,
|
|
46
|
+
* onKeyDown: session.onKeyDown,
|
|
47
|
+
* inputRef: session.inputRef,
|
|
48
|
+
* placeholder: t('catalog.search', undefined, { defaultValue: 'Search packages' }),
|
|
49
|
+
* count: session.hits.value.length,
|
|
50
|
+
* filters: session.parsed.value.filters,
|
|
51
|
+
* onRemoveFilter: session.removeFilter,
|
|
52
|
+
* onClear: session.clear,
|
|
53
|
+
* examples: ['category:auth', 'type:bond'],
|
|
54
|
+
* }),
|
|
55
|
+
* h(SearchResults, {
|
|
56
|
+
* hits: session.hits.value,
|
|
57
|
+
* view: (p) => ({ href: `/packages/${p.name}`, title: `@molecule/${p.name}`, description: p.description, meta: [p.type, p.category], mono: true }),
|
|
58
|
+
* activeIndex: session.activeIndex.value,
|
|
59
|
+
* onActivate: session.setActiveIndex,
|
|
60
|
+
* onOpen: session.open,
|
|
61
|
+
* onPrefetch: session.prefetch,
|
|
62
|
+
* renderLink,
|
|
63
|
+
* emptyText: t('catalog.empty', undefined, { defaultValue: 'Nothing matches' }),
|
|
64
|
+
* }),
|
|
65
|
+
* ]
|
|
66
|
+
* },
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* (`searchPlaceholder` and `nothingMatches` are the app's own translated strings.)
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* - **Pass a router link through `renderLink`**, or every row is a full page
|
|
74
|
+
* load: the list renders a plain `<a>` by default because it does not know
|
|
75
|
+
* your router. A plain click calls `onOpen` (which the session turns into
|
|
76
|
+
* navigation); a modified click is left to the browser so "open in new tab" works.
|
|
77
|
+
* - The box does not own the text: bind `value`/`onChange` to a session (or
|
|
78
|
+
* any state) and it stays mounted, with its text, across searches. Do not
|
|
79
|
+
* remount it per search.
|
|
80
|
+
* - `placeholder`, `emptyText` and the like are already-translated strings
|
|
81
|
+
* from the app; the package translates only its own chrome ("Clear
|
|
82
|
+
* search", "{{count}} results", "Search tips") through `@molecule/app-locales-search-ui`.
|
|
83
|
+
* - The quick dialog needs a session created with `syncUrl: false` and
|
|
84
|
+
* `onEscape: onClose`; the page's own session keeps the URL.
|
|
85
|
+
* - Node-valued props (`afterField`, `Kbd`'s `children`) arrive as a prop AND
|
|
86
|
+
* a same-named slot; components accept either.
|
|
87
|
+
*
|
|
88
|
+
* @module
|
|
89
|
+
*/
|
|
90
|
+
export * from './Highlight.js';
|
|
91
|
+
export * from './Kbd.js';
|
|
92
|
+
export * from './QuickSearchDialog.js';
|
|
93
|
+
export * from './SearchBox.js';
|
|
94
|
+
export * from './SearchResults.js';
|
|
95
|
+
export * from './types.js';
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,UAAU,CAAA;AACxB,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA"}
|