@molecule/app-search-ui-svelte 0.0.0-stage → 0.0.1-stage
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 +10 -2
- package/dist/Highlight.svelte +19 -0
- package/dist/Highlight.svelte.d.ts +5 -0
- package/dist/Highlight.svelte.d.ts.map +1 -0
- package/dist/Kbd.svelte +17 -0
- package/dist/Kbd.svelte.d.ts +5 -0
- package/dist/Kbd.svelte.d.ts.map +1 -0
- package/dist/QuickSearchDialog.svelte +115 -0
- package/dist/QuickSearchDialog.svelte.d.ts +27 -0
- package/dist/QuickSearchDialog.svelte.d.ts.map +1 -0
- package/dist/SearchBox.svelte +208 -0
- package/dist/SearchBox.svelte.d.ts +5 -0
- package/dist/SearchBox.svelte.d.ts.map +1 -0
- package/dist/SearchResults.svelte +136 -0
- package/dist/SearchResults.svelte.d.ts +27 -0
- package/dist/SearchResults.svelte.d.ts.map +1 -0
- package/dist/components.d.ts +12 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +11 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -0
- package/dist/types.d.ts +162 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/package.json +79 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @molecule/app-search-ui-svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Svelte search UI for @molecule/app-client-search — a search box with filter chips and tips, a ranked results list with matched terms marked, and a quick-search dialog; styled through the ClassMap
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @molecule/app-search-ui-svelte
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
|
|
10
|
+
|
|
11
|
+
License: Apache-2.0
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Highlight: the Svelte counterpart of `@molecule/app-search-ui-react`'s
|
|
3
|
+
`Highlight` — text with the matched terms marked, each term marked where it
|
|
4
|
+
starts a word, case-insensitively, through the ClassMap's `resultMark`.
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import { highlightMatches } from '@molecule/app-client-search'
|
|
8
|
+
import { getClassMap } from '@molecule/app-ui'
|
|
9
|
+
|
|
10
|
+
import type { HighlightProps } from './types.js'
|
|
11
|
+
|
|
12
|
+
let { text, terms }: HighlightProps = $props()
|
|
13
|
+
|
|
14
|
+
const cm = $derived(getClassMap())
|
|
15
|
+
const segments = $derived(highlightMatches(text, terms))
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
{#each segments as seg, i (i)}{#if seg.hit}<mark class={cm.resultMark}>{seg.text}</mark
|
|
19
|
+
>{:else}{seg.text}{/if}{/each}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Highlight.svelte.d.ts","sourceRoot":"","sources":["../src/Highlight.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAmBjD,QAAA,MAAM,SAAS,oDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
|
package/dist/Kbd.svelte
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Kbd: the Svelte counterpart of `@molecule/app-search-ui-react`'s `Kbd` —
|
|
3
|
+
a key cap, for shortcut hints (`/` to focus, `↵` to open). The cap shows a
|
|
4
|
+
key name, not prose (a physical key such as `esc` reads the same in every
|
|
5
|
+
language), so it carries HTML's own `translate="no"`.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { getClassMap } from '@molecule/app-ui'
|
|
9
|
+
|
|
10
|
+
import type { KbdProps } from './types.js'
|
|
11
|
+
|
|
12
|
+
let { children, className }: KbdProps = $props()
|
|
13
|
+
|
|
14
|
+
const cm = $derived(getClassMap())
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<kbd class={cm.cn(cm.kbd, className)} translate="no">{@render children?.()}</kbd>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kbd.svelte.d.ts","sourceRoot":"","sources":["../src/Kbd.svelte"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAiB3C,QAAA,MAAM,GAAG,8CAAwC,CAAC;AAClD,KAAK,GAAG,GAAG,UAAU,CAAC,OAAO,GAAG,CAAC,CAAC;AAClC,eAAe,GAAG,CAAC"}
|
|
@@ -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 @@
|
|
|
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,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AC"}
|
|
@@ -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';
|
package/dist/index.d.ts
ADDED
|
@@ -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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Svelte search UI.
|
|
3
|
+
*
|
|
4
|
+
* Prop names are React's, so an app can switch framework by changing only the
|
|
5
|
+
* package name in its imports. Node-valued props (`children`, `afterField`)
|
|
6
|
+
* are snippets; callbacks are plain functions; a render function (`renderLink`,
|
|
7
|
+
* `action`) is a snippet whose argument is the props it would receive.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import type { Snippet } from 'svelte';
|
|
12
|
+
import type { ClientSearchDocument, ClientSearchFilter } from '@molecule/app-client-search';
|
|
13
|
+
import type { SearchSession } from '@molecule/app-client-search-svelte';
|
|
14
|
+
/** Props accepted by {@link Kbd}. */
|
|
15
|
+
export interface KbdProps {
|
|
16
|
+
/** The key or keys shown, e.g. `/`, `↵`, `esc`. */
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
/** Extra classes composed onto the cap. */
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Props for {@link Highlight}. */
|
|
22
|
+
export interface HighlightProps {
|
|
23
|
+
/** The text to show. */
|
|
24
|
+
text: string;
|
|
25
|
+
/** The matched terms to mark (a hit's `terms`). */
|
|
26
|
+
terms: string[];
|
|
27
|
+
}
|
|
28
|
+
/** Props accepted by {@link SearchBox}. */
|
|
29
|
+
export interface SearchBoxProps {
|
|
30
|
+
/** The text. */
|
|
31
|
+
value: string;
|
|
32
|
+
/** Called with the new text on every keystroke. */
|
|
33
|
+
onChange: (value: string) => void;
|
|
34
|
+
/** Key handling for the input (arrows, Enter, Escape), usually a session's `onKeyDown`. */
|
|
35
|
+
onKeyDown?: (event: KeyboardEvent) => void;
|
|
36
|
+
/** A ref to the input, so a shortcut can focus it. */
|
|
37
|
+
inputRef?: {
|
|
38
|
+
current: HTMLInputElement | null;
|
|
39
|
+
};
|
|
40
|
+
/** Placeholder, already translated. Also the accessible name unless `label` is given. */
|
|
41
|
+
placeholder: string;
|
|
42
|
+
/** Accessible name for the input, already translated. Defaults to `placeholder`. */
|
|
43
|
+
label?: string;
|
|
44
|
+
/** How many hits the current text has. Omit to show no count. */
|
|
45
|
+
count?: number;
|
|
46
|
+
/** Active `field:value` filters, shown as removable chips. */
|
|
47
|
+
filters?: ClientSearchFilter[];
|
|
48
|
+
/** Removes the i-th filter. */
|
|
49
|
+
onRemoveFilter?: (index: number) => void;
|
|
50
|
+
/** Clears the text. Shown as an × while there is text. */
|
|
51
|
+
onClear?: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Example tokens for the search tips, e.g. `['category:auth', 'type:bond']`.
|
|
54
|
+
* Given, a help icon sits inside the field and shows the syntax on hover or
|
|
55
|
+
* focus. Omit for no help icon.
|
|
56
|
+
*/
|
|
57
|
+
examples?: string[];
|
|
58
|
+
/** The key that focuses the box, shown as a cap while it is empty. `null` hides it. Defaults to `/`. */
|
|
59
|
+
shortcut?: string | null;
|
|
60
|
+
/** Focus the input on mount. */
|
|
61
|
+
autoFocus?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Rendered directly under the field, before the status row (chips and
|
|
64
|
+
* count), so a consumer can put its own controls — tabs, a scope switch —
|
|
65
|
+
* right below the input.
|
|
66
|
+
*/
|
|
67
|
+
afterField?: Snippet;
|
|
68
|
+
/** `data-mol-id` prefix: `<molId>-input`, `-clear`, `-help`, `-filter`, `-count`. */
|
|
69
|
+
molId?: string;
|
|
70
|
+
/** Extra classes composed onto the field. */
|
|
71
|
+
className?: string;
|
|
72
|
+
}
|
|
73
|
+
/** What the list needs from a hit. A session's hits already have this shape. */
|
|
74
|
+
export interface SearchResultHit<T> {
|
|
75
|
+
id: string;
|
|
76
|
+
doc: T;
|
|
77
|
+
/** The matched terms, marked in the title and description. */
|
|
78
|
+
terms: string[];
|
|
79
|
+
/** Found by meaning rather than by the words typed. */
|
|
80
|
+
related?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** How one hit renders. */
|
|
83
|
+
export interface SearchResultView {
|
|
84
|
+
/** Where the row goes. */
|
|
85
|
+
href: string;
|
|
86
|
+
/** The row's title. */
|
|
87
|
+
title: string;
|
|
88
|
+
/** Under the title, clamped to two lines. */
|
|
89
|
+
description?: string;
|
|
90
|
+
/** Small facts after the title: type, category, source. */
|
|
91
|
+
meta?: string[];
|
|
92
|
+
/** Render the title in monospace (a package name). */
|
|
93
|
+
mono?: boolean;
|
|
94
|
+
/** Opaque data handed to `renderLink` (router state). */
|
|
95
|
+
state?: unknown;
|
|
96
|
+
}
|
|
97
|
+
/** Props the row's link gets; `renderLink` turns them into markup. */
|
|
98
|
+
export interface SearchResultLinkProps {
|
|
99
|
+
href: string;
|
|
100
|
+
className: string;
|
|
101
|
+
children: Snippet;
|
|
102
|
+
onClick: (event: MouseEvent) => void;
|
|
103
|
+
state?: unknown;
|
|
104
|
+
'data-mol-id': string;
|
|
105
|
+
}
|
|
106
|
+
/** Props for {@link SearchResults}. */
|
|
107
|
+
export interface SearchResultsProps<T extends ClientSearchDocument> {
|
|
108
|
+
hits: SearchResultHit<T>[];
|
|
109
|
+
/** How a hit renders. */
|
|
110
|
+
view: (doc: T) => SearchResultView;
|
|
111
|
+
/** The keyboard- or pointer-active row, or `-1`. */
|
|
112
|
+
activeIndex: number;
|
|
113
|
+
/** The pointer moved onto a row. */
|
|
114
|
+
onActivate?: (index: number) => void;
|
|
115
|
+
/** A row was chosen (a plain click, or Enter elsewhere). Navigation is the caller's. */
|
|
116
|
+
onOpen: (doc: T) => void;
|
|
117
|
+
/** The person is about to open a row (hover, focus, touch): warm its page. */
|
|
118
|
+
onPrefetch?: (doc: T) => void;
|
|
119
|
+
/**
|
|
120
|
+
* Renders the row's link. Defaults to a plain `<a>`; pass a router link to
|
|
121
|
+
* keep navigation client-side (spread `props` onto it; `state` is optional).
|
|
122
|
+
*/
|
|
123
|
+
renderLink?: Snippet<[SearchResultLinkProps]>;
|
|
124
|
+
/** Something at the row's end (an action button). */
|
|
125
|
+
action?: Snippet<[T]>;
|
|
126
|
+
/** Shown when there are no hits. */
|
|
127
|
+
emptyText: string;
|
|
128
|
+
/** `data-mol-id` prefix: `<molId>-results`, `-hit`, `-link`, `-related`, `-empty`, `-active`. */
|
|
129
|
+
molId?: string;
|
|
130
|
+
/** Extra classes composed onto the list. */
|
|
131
|
+
className?: string;
|
|
132
|
+
}
|
|
133
|
+
/** Props for {@link QuickSearchDialog}. */
|
|
134
|
+
export interface QuickSearchDialogProps<T extends ClientSearchDocument> {
|
|
135
|
+
/** Whether the dialog is open. Rendered only while open. */
|
|
136
|
+
open: boolean;
|
|
137
|
+
/** Close it (Escape with nothing typed, the overlay, or after opening a hit). */
|
|
138
|
+
onClose: () => void;
|
|
139
|
+
/** The search session (from `useSearchSession`), created with `syncUrl: false` and `onEscape: onClose`. */
|
|
140
|
+
session: SearchSession<T>;
|
|
141
|
+
/** How a hit renders. */
|
|
142
|
+
view: (doc: T) => SearchResultView;
|
|
143
|
+
/** Placeholder for the box, already translated. */
|
|
144
|
+
placeholder: string;
|
|
145
|
+
/** Example tokens for the tips line. */
|
|
146
|
+
examples?: string[];
|
|
147
|
+
/** Shown while the text matches nothing, already translated. */
|
|
148
|
+
emptyText: string;
|
|
149
|
+
/** Shown before anything is typed, already translated. Defaults to the empty text. */
|
|
150
|
+
idleText?: string;
|
|
151
|
+
/** Renders each row's link (a router link keeps navigation client-side). */
|
|
152
|
+
renderLink?: Snippet<[SearchResultLinkProps]>;
|
|
153
|
+
/**
|
|
154
|
+
* The dialog's accessible name, already translated (like `placeholder`, it
|
|
155
|
+
* names nothing visible). Defaults to `t('searchUi.dialogLabel')`
|
|
156
|
+
* ("Search"); the field's placeholder already names the field.
|
|
157
|
+
*/
|
|
158
|
+
label?: string;
|
|
159
|
+
/** `data-mol-id` prefix. Defaults to `quick-search`. */
|
|
160
|
+
molId?: string;
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE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K,CAAC,EAAE,MAAM,CAAA;IACd,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the Svelte search UI.
|
|
3
|
+
*
|
|
4
|
+
* Prop names are React's, so an app can switch framework by changing only the
|
|
5
|
+
* package name in its imports. Node-valued props (`children`, `afterField`)
|
|
6
|
+
* are snippets; callbacks are plain functions; a render function (`renderLink`,
|
|
7
|
+
* `action`) is a snippet whose argument is the props it would receive.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,81 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-search-ui-svelte",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-stage",
|
|
4
|
+
"description": "Svelte search UI for @molecule/app-client-search — a search box with filter chips and tips, a ranked results list with matched terms marked, and a quick-search dialog; styled through the ClassMap",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-search-ui-svelte",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"svelte": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"svelte": "./dist/index.js",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!dist/**/__tests__",
|
|
21
|
+
"!dist/**/*.test.*",
|
|
22
|
+
"!dist/**/*.spec.*",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
|
|
27
|
+
"dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"molecule",
|
|
33
|
+
"search",
|
|
34
|
+
"search-box",
|
|
35
|
+
"results",
|
|
36
|
+
"quick-search",
|
|
37
|
+
"svelte"
|
|
38
|
+
],
|
|
39
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
44
|
+
"directory": "packages/app/features/search-ui-svelte"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20"
|
|
48
|
+
},
|
|
49
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@molecule/app-client-search": "^1.0.0",
|
|
55
|
+
"@molecule/app-client-search-svelte": "^1.0.0",
|
|
56
|
+
"@molecule/app-svelte": "^3.5.0",
|
|
57
|
+
"@molecule/app-ui": "^1.3.3",
|
|
58
|
+
"@molecule/app-ui-svelte": "^1.1.0",
|
|
59
|
+
"svelte": "^5.0.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@molecule/app-client-search": "1.0.4",
|
|
63
|
+
"@molecule/app-client-search-minisearch": "1.0.4",
|
|
64
|
+
"@molecule/app-client-search-svelte": "1.0.0",
|
|
65
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
66
|
+
"@molecule/app-i18n": "1.2.2",
|
|
67
|
+
"@molecule/app-icons": "1.0.4",
|
|
68
|
+
"@molecule/app-svelte": "3.7.2",
|
|
69
|
+
"@molecule/app-ui": "1.4.0",
|
|
70
|
+
"@molecule/app-ui-svelte": "1.1.7",
|
|
71
|
+
"@sveltejs/package": "3.0.2",
|
|
72
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
73
|
+
"@types/node": "26.6.5",
|
|
74
|
+
"jsdom": "30.1.3",
|
|
75
|
+
"svelte": "5.57.2",
|
|
76
|
+
"svelte-check": "4.7.7",
|
|
77
|
+
"typescript": "6.0.3",
|
|
78
|
+
"vite": "8.3.5",
|
|
79
|
+
"vitest": "4.1.12"
|
|
80
|
+
}
|
|
81
|
+
}
|