@molecule/app-search-ui-svelte 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.
@@ -0,0 +1,115 @@
1
+ <!--
2
+ QuickSearchDialog: the Svelte counterpart of
3
+ `@molecule/app-search-ui-react`'s `QuickSearchDialog` — the box on top with
4
+ focus, the hits below in a scrolling pane, and the key hints in the footer.
5
+ Before anything is typed the pane shows `idleText` rather than a browse list.
6
+ The dialog is named for screen readers through `label` (or the translated
7
+ "Search" default).
8
+ -->
9
+ <script lang="ts" generics="T extends ClientSearchDocument">
10
+ import type { ClientSearchDocument } from '@molecule/app-client-search'
11
+ import { useTranslation } from '@molecule/app-svelte'
12
+ import { getClassMap } from '@molecule/app-ui'
13
+ import { Modal } from '@molecule/app-ui-svelte'
14
+
15
+ import Kbd from './Kbd.svelte'
16
+ import SearchBox from './SearchBox.svelte'
17
+ import SearchResults from './SearchResults.svelte'
18
+ import type { QuickSearchDialogProps } from './types.js'
19
+
20
+ let {
21
+ open,
22
+ onClose,
23
+ session,
24
+ view,
25
+ placeholder,
26
+ examples,
27
+ emptyText,
28
+ idleText,
29
+ renderLink,
30
+ label,
31
+ molId = 'quick-search',
32
+ }: QuickSearchDialogProps<T> = $props()
33
+
34
+ const cm = $derived(getClassMap())
35
+ const { t } = useTranslation()
36
+
37
+ // The single space React renders between the key hints and their sentence.
38
+ const space = ' '
39
+
40
+ // The dialog pattern: focus moves into the field when it opens. The input is
41
+ // mounted only while open, and effects run after the field exists.
42
+ $effect(() => {
43
+ if (open) session.inputRef.current?.focus()
44
+ })
45
+
46
+ // React's Modal portals its chrome into document.body and removes it on
47
+ // close. The UI kit's Svelte Modal moves its overlay and wrapper with an
48
+ // action that has no teardown, so once the nodes are in `document.body` the
49
+ // `{#if}` teardown — which walks siblings beside the anchor they were
50
+ // created at — never reaches them, and a closed dialog would leave them
51
+ // behind. Snapshot the body just before the chrome is created, and on close
52
+ // take back whatever appeared: the portaled chrome, and only that.
53
+ let bodyBeforeOpen: Element[] = []
54
+ $effect.pre(() => {
55
+ if (open) bodyBeforeOpen = [...document.body.children]
56
+ })
57
+ $effect(() => {
58
+ if (!open) return
59
+ return () => {
60
+ for (const node of [...document.body.children]) {
61
+ if (!bodyBeforeOpen.includes(node)) node.remove()
62
+ }
63
+ }
64
+ })
65
+ </script>
66
+
67
+ {#if open}
68
+ <Modal
69
+ {open}
70
+ {onClose}
71
+ size="lg"
72
+ closeOnEscape={false}
73
+ showCloseButton={false}
74
+ closeLabel={t('searchUi.close', undefined, { defaultValue: 'Close' })}
75
+ aria-label={label ?? t('searchUi.dialogLabel', undefined, { defaultValue: 'Search' })}
76
+ data-mol-id={molId}
77
+ >
78
+ <SearchBox
79
+ value={session.query}
80
+ onChange={session.setQuery}
81
+ onKeyDown={session.onKeyDown}
82
+ inputRef={session.inputRef}
83
+ {placeholder}
84
+ count={session.active ? session.hits.length : undefined}
85
+ filters={session.parsed.filters}
86
+ onRemoveFilter={session.removeFilter}
87
+ onClear={session.clear}
88
+ {examples}
89
+ shortcut={null}
90
+ {molId}
91
+ />
92
+ <div class={cm.dialogBody} data-mol-id={`${molId}-pane`}>
93
+ <SearchResults
94
+ hits={session.active ? session.hits : []}
95
+ {view}
96
+ activeIndex={session.activeIndex}
97
+ onActivate={session.setActiveIndex}
98
+ onOpen={session.open}
99
+ onPrefetch={session.prefetch}
100
+ {renderLink}
101
+ emptyText={session.active ? emptyText : (idleText ?? emptyText)}
102
+ {molId}
103
+ />
104
+ </div>
105
+ <p class={cm.cn(cm.dialogFooter, cm.resultMeta)} data-mol-id={`${molId}-keys`}>
106
+ <Kbd>↑</Kbd>
107
+ <Kbd>↓</Kbd>
108
+ <Kbd>↵</Kbd>
109
+ <Kbd>esc</Kbd>{space}
110
+ {t('searchUi.dialogKeys', undefined, {
111
+ defaultValue: 'The arrow keys move through the results, Enter opens one, Escape closes.',
112
+ })}
113
+ </p>
114
+ </Modal>
115
+ {/if}
@@ -0,0 +1,27 @@
1
+ import type { ClientSearchDocument } from '@molecule/app-client-search';
2
+ import type { QuickSearchDialogProps } from './types.js';
3
+ declare function $$render<T extends ClientSearchDocument>(): {
4
+ props: QuickSearchDialogProps<T>;
5
+ exports: {};
6
+ bindings: "";
7
+ slots: {};
8
+ events: {};
9
+ };
10
+ declare class __sveltets_Render<T extends ClientSearchDocument> {
11
+ props(): ReturnType<typeof $$render<T>>['props'];
12
+ events(): ReturnType<typeof $$render<T>>['events'];
13
+ slots(): ReturnType<typeof $$render<T>>['slots'];
14
+ bindings(): "";
15
+ exports(): {};
16
+ }
17
+ interface $$IsomorphicComponent {
18
+ new <T extends ClientSearchDocument>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
20
+ } & ReturnType<__sveltets_Render<T>['exports']>;
21
+ <T extends ClientSearchDocument>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
23
+ }
24
+ declare const QuickSearchDialog: $$IsomorphicComponent;
25
+ type QuickSearchDialog<T extends ClientSearchDocument> = InstanceType<typeof QuickSearchDialog<T>>;
26
+ export default QuickSearchDialog;
27
+ //# sourceMappingURL=QuickSearchDialog.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuickSearchDialog.svelte.d.ts","sourceRoot":"","sources":["../src/QuickSearchDialog.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAQvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,iBAAS,QAAQ,CAAC,CAAC,SAAS,oBAAoB;WA+EnB,sBAAsB,CAAC,CAAC,CAAC;;;;;EAA4E;AAClI,cAAM,iBAAiB,CAAC,CAAC,SAAS,oBAAoB;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,QAAQ;IACR,OAAO;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,CAAC,SAAS,oBAAoB,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACzZ,CAAC,CAAC,SAAS,oBAAoB,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACxJ,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,iBAAiB,EAAE,qBAAmC,CAAC;AAC3C,KAAK,iBAAiB,CAAC,CAAC,SAAS,oBAAoB,IAAI,YAAY,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AACrG,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,208 @@
1
+ <!--
2
+ SearchBox: the Svelte counterpart of `@molecule/app-search-ui-react`'s
3
+ `SearchBox` — the field with its clear button and shortcut cap, a help icon
4
+ whose tooltip shows the search syntax, an afterField slot for the consumer's
5
+ own tabs, the active filter chips and the hit count.
6
+ -->
7
+ <script lang="ts">
8
+ import type { ClientSearchFilter } from '@molecule/app-client-search'
9
+ import { useTranslation } from '@molecule/app-svelte'
10
+ import { getClassMap } from '@molecule/app-ui'
11
+ import { Icon, Tooltip } from '@molecule/app-ui-svelte'
12
+
13
+ import Kbd from './Kbd.svelte'
14
+ import type { SearchBoxProps } from './types.js'
15
+
16
+ let {
17
+ value,
18
+ onChange,
19
+ onKeyDown,
20
+ inputRef,
21
+ placeholder,
22
+ label,
23
+ count,
24
+ filters = [],
25
+ onRemoveFilter,
26
+ onClear,
27
+ examples,
28
+ shortcut = '/',
29
+ autoFocus = false,
30
+ afterField,
31
+ molId = 'search',
32
+ className,
33
+ }: SearchBoxProps = $props()
34
+
35
+ const cm = $derived(getClassMap())
36
+ const { t } = useTranslation()
37
+
38
+ let focused = $state(false)
39
+ let inputEl: HTMLInputElement | null = $state(null)
40
+
41
+ /**
42
+ * The chip's text: a negation mark, the field and the accepted values, as
43
+ * React builds it.
44
+ *
45
+ * @param f - The filter.
46
+ * @returns The chip text.
47
+ */
48
+ const chipText = (f: ClientSearchFilter): string =>
49
+ `${f.negate ? '−' : ''}${f.field}: ${f.values.join(', ')}`
50
+
51
+ // Assign the input element into `inputRef` (React's `ref`), then focus it on
52
+ // mount and whenever the ask changes, the way React's effect keyed on
53
+ // `autoFocus` and `inputRef` does.
54
+ $effect(() => {
55
+ if (inputRef) inputRef.current = inputEl
56
+ })
57
+ $effect(() => {
58
+ if (autoFocus) inputRef?.current?.focus()
59
+ })
60
+
61
+ // React keeps a controlled input's content attribute in sync with the
62
+ // rendered value; Svelte's `value` writes only the API value.
63
+ $effect(() => {
64
+ if (inputEl) inputEl.setAttribute('value', value)
65
+ })
66
+
67
+ const showCount = $derived(count !== undefined && value.trim().length > 0)
68
+ const showHelp = $derived(Boolean(examples?.length))
69
+ const hasStatus = $derived(filters.length > 0 || showCount)
70
+ // The branch above only renders while a count was given, so the fallback
71
+ // never shows; it satisfies the translation values' type.
72
+ const countText = $derived(
73
+ t('searchUi.count', { count: count ?? 0 }, { defaultValue: '{{count}} results' }),
74
+ )
75
+ const syntaxText = $derived(
76
+ t('searchUi.syntax', undefined, {
77
+ defaultValue: 'Narrow with a field, quote a phrase, or exclude a word:',
78
+ }),
79
+ )
80
+ const keysText = $derived(
81
+ t('searchUi.keys', undefined, {
82
+ defaultValue: 'The arrow keys move through the results and Enter opens one.',
83
+ }),
84
+ )
85
+ // The caller's example tokens, then the two built-in ones (their own words, translated).
86
+ const examplesText = $derived([
87
+ ...(examples ?? []),
88
+ t('searchUi.examplePhrase', undefined, { defaultValue: '"exact phrase"' }),
89
+ t('searchUi.exampleExcluded', undefined, { defaultValue: '-word' }),
90
+ ])
91
+ const dot = ' · '
92
+ const space = ' '
93
+
94
+ /**
95
+ * Reports the typed text, then restores the field to the value the props
96
+ * still hold, the way React's controlled input renders it back when the
97
+ * caller keeps the old one.
98
+ *
99
+ * @param event - The input event.
100
+ */
101
+ const onInput = (event: Event): void => {
102
+ const el = event.currentTarget as HTMLInputElement
103
+ onChange(el.value)
104
+ el.value = value
105
+ el.setAttribute('value', value)
106
+ }
107
+
108
+ /** Clears the text and puts focus back in the field, as React's button does. */
109
+ const onClearClick = (): void => {
110
+ onClear?.()
111
+ inputRef?.current?.focus()
112
+ }
113
+ </script>
114
+
115
+ <div data-mol-id={`${molId}-box`}>
116
+ <div class={cm.cn(cm.searchField, className)}>
117
+ <span class={cm.searchFieldIcon} aria-hidden="true">
118
+ <Icon name="search" size={18} />
119
+ </span>
120
+ <input
121
+ bind:this={inputEl}
122
+ type="search"
123
+ {value}
124
+ oninput={onInput}
125
+ onkeydown={(event) => onKeyDown?.(event)}
126
+ onfocusin={() => (focused = true)}
127
+ onfocusout={() => (focused = false)}
128
+ {placeholder}
129
+ aria-label={label ?? placeholder}
130
+ autocomplete="off"
131
+ autocorrect="off"
132
+ spellcheck="false"
133
+ enterkeyhint="search"
134
+ class={cm.searchFieldInput}
135
+ data-mol-id={`${molId}-input`}
136
+ />
137
+ <span class={cm.searchFieldActions}>
138
+ {#if showHelp}
139
+ <Tooltip content={helpTips} placement="bottom-end">
140
+ <button
141
+ type="button"
142
+ aria-label={t('searchUi.help', undefined, { defaultValue: 'Search tips' })}
143
+ class={cm.searchFieldClear}
144
+ data-mol-id={`${molId}-help`}
145
+ >
146
+ <Icon name="question" size={16} />
147
+ </button>
148
+ </Tooltip>
149
+ {/if}
150
+ {#if value && onClear}
151
+ <button
152
+ type="button"
153
+ onclick={onClearClick}
154
+ aria-label={t('searchUi.clear', undefined, { defaultValue: 'Clear search' })}
155
+ class={cm.searchFieldClear}
156
+ data-mol-id={`${molId}-clear`}
157
+ >
158
+ <span aria-hidden="true">×</span>
159
+ </button>
160
+ {/if}
161
+ {#if shortcut && !value && !focused}<Kbd>{shortcut}</Kbd>{/if}
162
+ </span>
163
+ </div>
164
+ {#if afterField}{@render afterField()}{/if}
165
+ {#if hasStatus}
166
+ <div class={cm.searchStatusRow}>
167
+ {#each filters as f, i (`${f.field}:${f.values.join(',')}:${i}`)}
168
+ <button
169
+ type="button"
170
+ onclick={() => onRemoveFilter?.(i)}
171
+ aria-label={t(
172
+ 'searchUi.removeFilter',
173
+ { filter: chipText(f) },
174
+ {
175
+ defaultValue: 'Remove filter {{filter}}',
176
+ },
177
+ )}
178
+ class={cm.cn(cm.filterChip, f.negate && cm.filterChipNegated)}
179
+ data-mol-id={`${molId}-filter`}
180
+ data-filter-field={f.field}
181
+ >
182
+ {chipText(f)}
183
+ <span class={cm.filterChipRemove} aria-hidden="true">×</span>
184
+ </button>
185
+ {/each}
186
+ <span class={cm.mxAuto}></span>
187
+ {#if showCount}
188
+ <span data-mol-id={`${molId}-count`}>{countText}</span>
189
+ {/if}
190
+ </div>
191
+ {/if}
192
+ </div>
193
+
194
+ {#snippet helpTips()}
195
+ <!-- The tooltip's content class keeps short labels on one line; the tips are
196
+ a sentence or two, so the inner block wraps on its own. -->
197
+ <div class={cm.searchTips} style="white-space: normal; max-width: 360px">
198
+ {syntaxText}
199
+ {#each examplesText as ex, i (i)}
200
+ <span>{i > 0 ? ' · ' : ''}<code>{ex}</code></span>
201
+ {/each}
202
+ {dot}
203
+ <Kbd>↑</Kbd>
204
+ <Kbd>↓</Kbd>
205
+ <Kbd>↵</Kbd>{space}
206
+ {keysText}
207
+ </div>
208
+ {/snippet}
@@ -0,0 +1,5 @@
1
+ import type { SearchBoxProps } from './types.js';
2
+ declare const SearchBox: import("svelte").Component<SearchBoxProps, {}, "">;
3
+ type SearchBox = ReturnType<typeof SearchBox>;
4
+ export default SearchBox;
5
+ //# sourceMappingURL=SearchBox.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchBox.svelte.d.ts","sourceRoot":"","sources":["../src/SearchBox.svelte"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA6KjD,QAAA,MAAM,SAAS,oDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
@@ -0,0 +1,136 @@
1
+ <!--
2
+ SearchResults: the Svelte counterpart of `@molecule/app-search-ui-react`'s
3
+ `SearchResults` — the ranked hits with the matched terms marked, hover
4
+ prefetch, and an optional action per row. The whole row is the link, so the
5
+ list is a plain list of links (no listbox roles); the active row is marked
6
+ with `aria-current` on its `li` and announced through a polite, visually
7
+ hidden status region after the list. Apps pass a router link through
8
+ `renderLink`.
9
+ -->
10
+ <script lang="ts" generics="T extends ClientSearchDocument">
11
+ import type { ClientSearchDocument } from '@molecule/app-client-search'
12
+ import { useTranslation } from '@molecule/app-svelte'
13
+ import { getClassMap } from '@molecule/app-ui'
14
+
15
+ import Highlight from './Highlight.svelte'
16
+ import type { SearchResultLinkProps, SearchResultsProps } from './types.js'
17
+
18
+ let {
19
+ hits,
20
+ view,
21
+ activeIndex,
22
+ onActivate,
23
+ onOpen,
24
+ onPrefetch,
25
+ renderLink,
26
+ action,
27
+ emptyText,
28
+ molId = 'search',
29
+ className,
30
+ }: SearchResultsProps<T> = $props()
31
+
32
+ const cm = $derived(getClassMap())
33
+ const { t } = useTranslation()
34
+
35
+ let listEl: HTMLUListElement | null = $state(null)
36
+
37
+ // Keep the keyboard-active row in view.
38
+ $effect(() => {
39
+ if (activeIndex < 0) return
40
+ const el = listEl?.querySelector<HTMLElement>(`[data-index="${activeIndex}"]`)
41
+ el?.scrollIntoView?.({ block: 'nearest' })
42
+ })
43
+
44
+ // The active row's announcement; empty when no row is keyboard-active.
45
+ const activeHitText = (): string => {
46
+ const hit = activeIndex >= 0 ? hits[activeIndex] : undefined
47
+ if (!hit) return ''
48
+ return t(
49
+ 'searchUi.activeResult',
50
+ { title: view(hit.doc).title, position: activeIndex + 1, count: hits.length },
51
+ { defaultValue: '{{title}}, {{position}} of {{count}}' },
52
+ )
53
+ }
54
+ </script>
55
+
56
+ {#if hits.length === 0}
57
+ <p class={cm.resultEmpty} data-mol-id={`${molId}-empty`}>{emptyText}</p>
58
+ <!-- The status region exists before results arrive, so it is live. -->
59
+ <p role="status" class={cm.srOnly} data-mol-id={`${molId}-active`}></p>
60
+ {:else}
61
+ <ul
62
+ bind:this={listEl}
63
+ aria-label={t('searchUi.results', undefined, { defaultValue: 'Search results' })}
64
+ class={cm.cn(cm.resultList, className)}
65
+ data-mol-id={`${molId}-results`}
66
+ >
67
+ {#each hits as hit, i (hit.id)}
68
+ {@const v = view(hit.doc)}
69
+ {@const active = i === activeIndex}
70
+ {#snippet rowBody()}
71
+ <!-- React's JSX keeps no text nodes between these spans, so every
72
+ element and block here sits directly beside its neighbor. -->
73
+ <span class={cm.flex({ align: 'baseline', wrap: 'wrap', gap: 2 })}
74
+ ><span class={cm.cn(cm.resultTitle, v.mono && cm.resultTitleMono)}>
75
+ <Highlight text={v.title} terms={hit.terms} />
76
+ </span>{#if v.meta && v.meta.length}<span class={cm.resultMeta}>{v.meta.join(' · ')}</span
77
+ >{/if}{#if hit.related}<span
78
+ class={cm.resultMeta}
79
+ data-mol-id={`${molId}-related`}
80
+ title={t('searchUi.relatedTitle', undefined, {
81
+ defaultValue: 'Matches the meaning of your search, not its words',
82
+ })}
83
+ >
84
+ {t('searchUi.related', undefined, { defaultValue: 'related' })}
85
+ </span>{/if}</span
86
+ >{#if v.description}
87
+ <span class={cm.cn(cm.resultDescription, cm.displayBlock)}>
88
+ <Highlight text={v.description} terms={hit.terms} />
89
+ </span>
90
+ {/if}
91
+ {/snippet}
92
+ {@const linkProps: SearchResultLinkProps = {
93
+ href: v.href,
94
+ state: v.state,
95
+ className: cm.resultBody,
96
+ 'data-mol-id': `${molId}-link`,
97
+ children: rowBody,
98
+ onClick: (event: MouseEvent) => {
99
+ // A modified click opens a new tab; the router handles the rest.
100
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0)
101
+ return
102
+ event.preventDefault()
103
+ onOpen(hit.doc)
104
+ },
105
+ }}
106
+ <li
107
+ aria-current={active ? 'true' : undefined}
108
+ data-index={i}
109
+ data-mol-id={`${molId}-hit`}
110
+ data-hit-id={hit.id}
111
+ class={cm.cn(cm.resultItem, active && cm.resultItemActive)}
112
+ onpointerover={() => {
113
+ onActivate?.(i)
114
+ onPrefetch?.(hit.doc)
115
+ }}
116
+ onfocusin={() => onPrefetch?.(hit.doc)}
117
+ ontouchstart={() => onPrefetch?.(hit.doc)}
118
+ >
119
+ {#if renderLink}
120
+ {@render renderLink(linkProps)}
121
+ {:else}
122
+ <a
123
+ href={linkProps.href}
124
+ class={linkProps.className}
125
+ data-mol-id={linkProps['data-mol-id']}
126
+ onclick={linkProps.onClick}>{@render linkProps.children()}</a
127
+ >
128
+ {/if}
129
+ {#if action}
130
+ <span class={cm.resultAction}>{@render action(hit.doc)}</span>
131
+ {/if}
132
+ </li>
133
+ {/each}
134
+ </ul>
135
+ <p role="status" class={cm.srOnly} data-mol-id={`${molId}-active`}>{activeHitText()}</p>
136
+ {/if}
@@ -0,0 +1,27 @@
1
+ import type { ClientSearchDocument } from '@molecule/app-client-search';
2
+ import type { SearchResultsProps } from './types.js';
3
+ declare function $$render<T extends ClientSearchDocument>(): {
4
+ props: SearchResultsProps<T>;
5
+ exports: {};
6
+ bindings: "";
7
+ slots: {};
8
+ events: {};
9
+ };
10
+ declare class __sveltets_Render<T extends ClientSearchDocument> {
11
+ props(): ReturnType<typeof $$render<T>>['props'];
12
+ events(): ReturnType<typeof $$render<T>>['events'];
13
+ slots(): ReturnType<typeof $$render<T>>['slots'];
14
+ bindings(): "";
15
+ exports(): {};
16
+ }
17
+ interface $$IsomorphicComponent {
18
+ new <T extends ClientSearchDocument>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
19
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
20
+ } & ReturnType<__sveltets_Render<T>['exports']>;
21
+ <T extends ClientSearchDocument>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
22
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
23
+ }
24
+ declare const SearchResults: $$IsomorphicComponent;
25
+ type SearchResults<T extends ClientSearchDocument> = InstanceType<typeof SearchResults<T>>;
26
+ export default SearchResults;
27
+ //# sourceMappingURL=SearchResults.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchResults.svelte.d.ts","sourceRoot":"","sources":["../src/SearchResults.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAKvE,OAAO,KAAK,EAAyB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC5E,iBAAS,QAAQ,CAAC,CAAC,SAAS,oBAAoB;WAwGnB,kBAAkB,CAAC,CAAC,CAAC;;;;;EAA4E;AAC9H,cAAM,iBAAiB,CAAC,CAAC,SAAS,oBAAoB;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,MAAM,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAClD,KAAK,IAAI,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAChD,QAAQ;IACR,OAAO;CACV;AAED,UAAU,qBAAqB;IAC3B,KAAK,CAAC,SAAS,oBAAoB,EAAE,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;KAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACzZ,CAAC,CAAC,SAAS,oBAAoB,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IACxJ,YAAY,CAAC,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CACjE;AACD,QAAA,MAAM,aAAa,EAAE,qBAAmC,CAAC;AACvC,KAAK,aAAa,CAAC,CAAC,SAAS,oBAAoB,IAAI,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F,eAAe,aAAa,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The package's components: one Svelte 5 component per React component in
3
+ * `@molecule/app-search-ui-react`, under the same React name.
4
+ *
5
+ * @module
6
+ */
7
+ export { default as Highlight } from './Highlight.svelte';
8
+ export { default as Kbd } from './Kbd.svelte';
9
+ export { default as QuickSearchDialog } from './QuickSearchDialog.svelte';
10
+ export { default as SearchBox } from './SearchBox.svelte';
11
+ export { default as SearchResults } from './SearchResults.svelte';
12
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AACzE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The package's components: one Svelte 5 component per React component in
3
+ * `@molecule/app-search-ui-react`, under the same React name.
4
+ *
5
+ * @module
6
+ */
7
+ export { default as Highlight } from './Highlight.svelte';
8
+ export { default as Kbd } from './Kbd.svelte';
9
+ export { default as QuickSearchDialog } from './QuickSearchDialog.svelte';
10
+ export { default as SearchBox } from './SearchBox.svelte';
11
+ export { default as SearchResults } from './SearchResults.svelte';
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Svelte search UI for `@molecule/app-client-search`.
3
+ *
4
+ * The Svelte 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-svelte`:
7
+ * {@link SearchBox} (the field, its clear button and shortcut cap, a help icon
8
+ * whose tooltip shows the search syntax, an `afterField` snippet 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
+ * ```svelte
20
+ * <script lang="ts">
21
+ * import { Link, useTranslation } from '@molecule/app-svelte'
22
+ * import { useSearchSession } from '@molecule/app-client-search-svelte'
23
+ * import { SearchBox, SearchResults } from '@molecule/app-search-ui-svelte'
24
+ * import type { SearchResultLinkProps } from '@molecule/app-search-ui-svelte'
25
+ *
26
+ * const { t } = useTranslation()
27
+ * const session = useSearchSession({
28
+ * docs: packages,
29
+ * options: PACKAGE_INDEX_OPTIONS,
30
+ * rememberKey: 'catalog.search',
31
+ * onOpen: (p) => goto(`/packages/${p.name}`),
32
+ * })
33
+ *
34
+ * {#snippet renderLink(p: SearchResultLinkProps)}
35
+ * <Link to={p.href} state={p.state} className={p.className} onClick={p.onClick} data-mol-id={p['data-mol-id']}>
36
+ * <!-- the row's body -->
37
+ * </Link>
38
+ * {/snippet}
39
+ * </script>
40
+ *
41
+ * <SearchBox
42
+ * value={session.query}
43
+ * onChange={session.setQuery}
44
+ * onKeyDown={session.onKeyDown}
45
+ * inputRef={session.inputRef}
46
+ * placeholder={t('catalog.search', undefined, { defaultValue: 'Search packages' })}
47
+ * count={session.hits.length}
48
+ * filters={session.parsed.filters}
49
+ * onRemoveFilter={session.removeFilter}
50
+ * onClear={session.clear}
51
+ * examples={['category:auth', 'type:bond']}
52
+ * />
53
+ * <SearchResults
54
+ * hits={session.hits}
55
+ * view={(p) => ({ href: `/packages/${p.name}`, title: `@molecule/${p.name}`, description: p.description, meta: [p.type, p.category], mono: true })}
56
+ * activeIndex={session.activeIndex}
57
+ * onActivate={session.setActiveIndex}
58
+ * onOpen={session.open}
59
+ * onPrefetch={session.prefetch}
60
+ * {renderLink}
61
+ * emptyText={t('catalog.empty', undefined, { defaultValue: 'Nothing matches' })}
62
+ * />
63
+ * ```
64
+ *
65
+ * (`searchPlaceholder` and `nothingMatches` are the app's own translated strings.)
66
+ *
67
+ * @remarks
68
+ * - **Pass a router link through `renderLink`**, or every row is a full page
69
+ * load: the list renders a plain `<a>` by default because it does not know
70
+ * your router. A plain click calls `onOpen` (which the session turns into
71
+ * navigation); a modified click is left to the browser so "open in new tab" works.
72
+ * - The box does not own the text: bind `value`/`onChange` to a session (or
73
+ * any state) and it stays mounted, with its text, across searches. Do not
74
+ * remount it per search.
75
+ * - `placeholder`, `emptyText` and the like are already-translated strings
76
+ * from the app; the package translates only its own chrome ("Clear
77
+ * search", "{{count}} results", "Search tips") through `@molecule/app-locales-search-ui`.
78
+ * - The quick dialog needs a session created with `syncUrl: false` and
79
+ * `onEscape: onClose`; the page's own session keeps the URL.
80
+ * - React render props (`renderLink`, `action`) and node props (`afterField`,
81
+ * `Kbd`'s `children`) are snippets.
82
+ *
83
+ * @module
84
+ */
85
+ export * from './components.js';
86
+ export * from './types.js';
87
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmFG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA"}