@docsearch/sidepanel-js 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/esm/index.d.ts +300 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/umd/index.js +7 -0
- package/dist/umd/index.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @docsearch/sidepanel-js
|
|
2
|
+
|
|
3
|
+
JavaScript package for [DocSearch Sidepanel](http://docsearch.algolia.com/), a standalone Ask AI chat panel.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @docsearch/sidepanel-js
|
|
9
|
+
# or
|
|
10
|
+
npm install @docsearch/sidepanel-js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Get started
|
|
14
|
+
|
|
15
|
+
If you don’t want to use a package manager, you can use a standalone endpoint:
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script src="https://cdn.jsdelivr.net/npm/@docsearch/sidepanel-js@4"></script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
To get started, you need a [`container`](https://docsearch.algolia.com/docs/api#container) for your DocSearch Sidepanel component to go in. If you don’t have one already, you can insert one into your markup:
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<div id="docsearch-sidepanel"></div>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then, insert DocSearch Sidepanel into it by calling the [`sidepanel`](https://docsearch.algolia.com/docs/api) function and providing the container. It can be a [CSS selector](https://developer.mozilla.org/en-us/docs/web/css/css_selectors) or an [Element](https://developer.mozilla.org/en-us/docs/web/api/htmlelement).
|
|
28
|
+
|
|
29
|
+
Make sure to provide a [`container`](https://docsearch.algolia.com/docs/api#container) (for example, a `div`).
|
|
30
|
+
|
|
31
|
+
```js app.js
|
|
32
|
+
import sidepanel from '@docsearch/sidepanel-js';
|
|
33
|
+
|
|
34
|
+
import '@docsearch/css/dist/sidepanel.css';
|
|
35
|
+
|
|
36
|
+
sidepanel({
|
|
37
|
+
container: '#docsearch-sidepanel',
|
|
38
|
+
indexName: 'YOUR_INDEX_NAME',
|
|
39
|
+
appId: 'YOUR_APP_ID',
|
|
40
|
+
apiKey: 'YOUR_SEARCH_API_KEY',
|
|
41
|
+
assistantId: 'YOUR_ASSISTANT_ID',
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Documentation
|
|
46
|
+
|
|
47
|
+
[Read documentation →](https://docsearch.algolia.com)
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
interface SidepanelShortcuts {
|
|
2
|
+
/**
|
|
3
|
+
* Enable/disable the Ctrl/Cmd+I shortcut to toggle the DocSearch sidepanel.
|
|
4
|
+
*
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
'Ctrl/Cmd+I'?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type DocSearchTheme = 'dark' | 'light';
|
|
11
|
+
|
|
12
|
+
type AskAiSearchParameters = {
|
|
13
|
+
facetFilters?: string[];
|
|
14
|
+
filters?: string;
|
|
15
|
+
attributesToRetrieve?: string[];
|
|
16
|
+
restrictSearchableAttributes?: string[];
|
|
17
|
+
distinct?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type AlgoliaLogoTranslations = Partial<{
|
|
21
|
+
poweredByText: string;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
type ConversationScreenTranslations = Partial<{
|
|
25
|
+
/**
|
|
26
|
+
* Text shown as an LLM disclaimer.
|
|
27
|
+
*/
|
|
28
|
+
conversationDisclaimer: string;
|
|
29
|
+
/**
|
|
30
|
+
* Text shown while assistant is reasoning.
|
|
31
|
+
*/
|
|
32
|
+
reasoningText: string;
|
|
33
|
+
/**
|
|
34
|
+
* Text show while assistant is thinking.
|
|
35
|
+
*/
|
|
36
|
+
thinkingText: string;
|
|
37
|
+
/**
|
|
38
|
+
* Text shown while assistant is preparing tool call.
|
|
39
|
+
*/
|
|
40
|
+
preToolCallText: string;
|
|
41
|
+
/**
|
|
42
|
+
* Text shown while assistant is performing search tool call.
|
|
43
|
+
*/
|
|
44
|
+
searchingText: string;
|
|
45
|
+
/**
|
|
46
|
+
* Text shown while assistant is finished performing tool call.
|
|
47
|
+
*/
|
|
48
|
+
toolCallResultText: string;
|
|
49
|
+
/**
|
|
50
|
+
* Text shown describing related sources.
|
|
51
|
+
*/
|
|
52
|
+
relatedSourcesText: string;
|
|
53
|
+
/**
|
|
54
|
+
* Message that's shown when user has stopped the streaming of a message.
|
|
55
|
+
*/
|
|
56
|
+
stoppedStreamingText: string;
|
|
57
|
+
/**
|
|
58
|
+
* Text shown for copy button on code snippets.
|
|
59
|
+
**/
|
|
60
|
+
copyButtonText: string;
|
|
61
|
+
/**
|
|
62
|
+
* Message shown after clicking copy.
|
|
63
|
+
**/
|
|
64
|
+
copyButtonCopiedText: string;
|
|
65
|
+
/**
|
|
66
|
+
* Title for thumbs up feedback icon.
|
|
67
|
+
**/
|
|
68
|
+
likeButtonTitle: string;
|
|
69
|
+
/**
|
|
70
|
+
* Title for thumbs down feedback icon.
|
|
71
|
+
**/
|
|
72
|
+
dislikeButtonTitle: string;
|
|
73
|
+
/**
|
|
74
|
+
* Message displayed after feedback action.
|
|
75
|
+
**/
|
|
76
|
+
thanksForFeedbackText: string;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
79
|
+
type NewConversationScreenTranslations = Partial<{
|
|
80
|
+
/**
|
|
81
|
+
* Title to be shown on the new conversation/starting screen.
|
|
82
|
+
**/
|
|
83
|
+
titleText: string;
|
|
84
|
+
/**
|
|
85
|
+
* Introduction text displayed on the new conversation/starting screen.
|
|
86
|
+
**/
|
|
87
|
+
introductionText: string;
|
|
88
|
+
}>;
|
|
89
|
+
|
|
90
|
+
type PromptFormTranslations = Partial<{
|
|
91
|
+
/**
|
|
92
|
+
* Initial placeholder for the prompt input.
|
|
93
|
+
**/
|
|
94
|
+
promptPlaceholderText: string;
|
|
95
|
+
/**
|
|
96
|
+
* Placeholder text for wile a conversation is streaming.
|
|
97
|
+
**/
|
|
98
|
+
promptAnsweringText: string;
|
|
99
|
+
/**
|
|
100
|
+
* Placeholder text for after a question has already been asked.
|
|
101
|
+
**/
|
|
102
|
+
promptAskAnotherQuestionText: string;
|
|
103
|
+
/**
|
|
104
|
+
* Disclaimer text displayed beneath the prompt form.
|
|
105
|
+
**/
|
|
106
|
+
promptDisclaimerText: string;
|
|
107
|
+
promptLabelText: string;
|
|
108
|
+
promptAriaLabelText: string;
|
|
109
|
+
}>;
|
|
110
|
+
|
|
111
|
+
type PanelVariant = 'floating' | 'inline';
|
|
112
|
+
type PanelSide = 'left' | 'right';
|
|
113
|
+
|
|
114
|
+
type HeaderTranslations = Partial<{
|
|
115
|
+
/**
|
|
116
|
+
* The main title text shown on the header.
|
|
117
|
+
**/
|
|
118
|
+
title: string;
|
|
119
|
+
/**
|
|
120
|
+
* The title text shown on the conversation history screen.
|
|
121
|
+
**/
|
|
122
|
+
conversationHistoryTitle: string;
|
|
123
|
+
/**
|
|
124
|
+
* The text shown on the start a conversation button.
|
|
125
|
+
**/
|
|
126
|
+
newConversationText: string;
|
|
127
|
+
/**
|
|
128
|
+
* The text shown on the view conversation history button.
|
|
129
|
+
**/
|
|
130
|
+
viewConversationHistoryText: string;
|
|
131
|
+
}>;
|
|
132
|
+
|
|
133
|
+
type SidepanelTranslations = Partial<{
|
|
134
|
+
/**
|
|
135
|
+
* Translation texts for the Sidepanel header.
|
|
136
|
+
**/
|
|
137
|
+
header: HeaderTranslations;
|
|
138
|
+
/**
|
|
139
|
+
* Translation texts for the prompt form.
|
|
140
|
+
**/
|
|
141
|
+
promptForm: PromptFormTranslations;
|
|
142
|
+
/**
|
|
143
|
+
* Translation texts for the conversation screen.
|
|
144
|
+
**/
|
|
145
|
+
conversationScreen: ConversationScreenTranslations;
|
|
146
|
+
/**
|
|
147
|
+
* Translation texts for the new conversation/starting screen.
|
|
148
|
+
**/
|
|
149
|
+
newConversationScreen: NewConversationScreenTranslations;
|
|
150
|
+
/**
|
|
151
|
+
* Translation text for the Algolia logo.
|
|
152
|
+
**/
|
|
153
|
+
logo: AlgoliaLogoTranslations;
|
|
154
|
+
}>;
|
|
155
|
+
type SidepanelProps$1 = {
|
|
156
|
+
/**
|
|
157
|
+
* Variant of the Sidepanel positioning.
|
|
158
|
+
*
|
|
159
|
+
* - `inline` pushes page content when opened
|
|
160
|
+
* - `floating` is positioned above all other content on page.
|
|
161
|
+
*
|
|
162
|
+
* @default 'floating'
|
|
163
|
+
*/
|
|
164
|
+
variant?: PanelVariant;
|
|
165
|
+
/**
|
|
166
|
+
* Side of the page which the panel will originate from.
|
|
167
|
+
*
|
|
168
|
+
* @default 'right'
|
|
169
|
+
*/
|
|
170
|
+
side?: PanelSide;
|
|
171
|
+
/**
|
|
172
|
+
* The selector of the element to push when Sidepanel opens with `inline` variant.
|
|
173
|
+
*
|
|
174
|
+
* @default `'#root, main, .app, body'`
|
|
175
|
+
*/
|
|
176
|
+
pushSelector?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Width of the Sidepanel (px or any CSS width).
|
|
179
|
+
*
|
|
180
|
+
* @default `360px`
|
|
181
|
+
**/
|
|
182
|
+
width?: number | string;
|
|
183
|
+
/**
|
|
184
|
+
* Width when expanded (px or any CSS width).
|
|
185
|
+
*
|
|
186
|
+
* @default `580px`
|
|
187
|
+
**/
|
|
188
|
+
expandedWidth?: number | string;
|
|
189
|
+
/**
|
|
190
|
+
* The container element where the panel should be portaled to.
|
|
191
|
+
*
|
|
192
|
+
* @default `document.body`
|
|
193
|
+
*/
|
|
194
|
+
portalContainer?: DocumentFragment | Element | null;
|
|
195
|
+
/**
|
|
196
|
+
* Enables displaying suggested questions on new conversation screen.
|
|
197
|
+
*
|
|
198
|
+
* @default false
|
|
199
|
+
*/
|
|
200
|
+
suggestedQuestions?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Translations specific to the Sidepanel panel.
|
|
203
|
+
**/
|
|
204
|
+
translations?: SidepanelTranslations;
|
|
205
|
+
/**
|
|
206
|
+
* Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.
|
|
207
|
+
*
|
|
208
|
+
* @default `{ 'Ctrl/Cmd+I': true }`
|
|
209
|
+
*/
|
|
210
|
+
keyboardShortcuts?: SidepanelShortcuts;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
type SidepanelButtonTranslations = Partial<{
|
|
214
|
+
/**
|
|
215
|
+
* Text to be displayed when button has variant: `inline`.
|
|
216
|
+
*
|
|
217
|
+
* @default 'Ask AI'
|
|
218
|
+
**/
|
|
219
|
+
buttonText: string;
|
|
220
|
+
/**
|
|
221
|
+
* Aria label text for the button.
|
|
222
|
+
*
|
|
223
|
+
* @default 'Ask AI'
|
|
224
|
+
**/
|
|
225
|
+
buttonAriaLabel: string;
|
|
226
|
+
}>;
|
|
227
|
+
type ButtonVariant = 'floating' | 'inline';
|
|
228
|
+
type SidepanelButtonProps = {
|
|
229
|
+
/**
|
|
230
|
+
* Variant of the button positioning and styling.
|
|
231
|
+
*
|
|
232
|
+
* - `inline` displays the button inline where rendered, with extra text
|
|
233
|
+
* - `floating` displays the button floating in bottom right of screen with just icon.
|
|
234
|
+
*
|
|
235
|
+
* @default 'floating'
|
|
236
|
+
**/
|
|
237
|
+
variant?: ButtonVariant;
|
|
238
|
+
/**
|
|
239
|
+
* Translations specific to the Sidepanel button.
|
|
240
|
+
**/
|
|
241
|
+
translations?: SidepanelButtonTranslations;
|
|
242
|
+
/**
|
|
243
|
+
* Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.
|
|
244
|
+
*
|
|
245
|
+
* @default `{ 'Ctrl/Cmd+I': true }`
|
|
246
|
+
*/
|
|
247
|
+
keyboardShortcuts?: SidepanelShortcuts;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
type DocSearchSidepanelProps = {
|
|
251
|
+
/**
|
|
252
|
+
* The assistant ID to use for the ask AI feature.
|
|
253
|
+
*/
|
|
254
|
+
assistantId: string;
|
|
255
|
+
/**
|
|
256
|
+
* Public api key with search permissions for the index.
|
|
257
|
+
*/
|
|
258
|
+
apiKey: string;
|
|
259
|
+
/**
|
|
260
|
+
* Algolia application id used by the search client.
|
|
261
|
+
*/
|
|
262
|
+
appId: string;
|
|
263
|
+
/**
|
|
264
|
+
* The index name to use for the ask AI feature. Your assistant will search this index for relevant documents.
|
|
265
|
+
*/
|
|
266
|
+
indexName: string;
|
|
267
|
+
/**
|
|
268
|
+
* The search parameters to use for the ask AI feature.
|
|
269
|
+
*/
|
|
270
|
+
searchParameters?: AskAiSearchParameters;
|
|
271
|
+
/**
|
|
272
|
+
* Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.
|
|
273
|
+
*
|
|
274
|
+
* @default `{ 'Ctrl/Cmd+I': true }`
|
|
275
|
+
*/
|
|
276
|
+
keyboardShortcuts?: SidepanelShortcuts;
|
|
277
|
+
/**
|
|
278
|
+
* Theme overrides applied to the Sidepanel button and panel.
|
|
279
|
+
*
|
|
280
|
+
* @default 'light'
|
|
281
|
+
*/
|
|
282
|
+
theme?: DocSearchTheme;
|
|
283
|
+
/**
|
|
284
|
+
* Props specific to the Sidepanel button.
|
|
285
|
+
*/
|
|
286
|
+
button?: Omit<SidepanelButtonProps, 'keyboardShortcuts'>;
|
|
287
|
+
/**
|
|
288
|
+
* Props specific to the Sidepanel panel.
|
|
289
|
+
*/
|
|
290
|
+
panel?: Omit<SidepanelProps$1, 'keyboardShortcuts'>;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
type SidepanelProps = DocSearchSidepanelProps & {
|
|
294
|
+
container: HTMLElement | string;
|
|
295
|
+
environment?: typeof window;
|
|
296
|
+
};
|
|
297
|
+
declare function sidepanel(props: SidepanelProps): () => void;
|
|
298
|
+
|
|
299
|
+
export { sidepanel as default };
|
|
300
|
+
export type { SidepanelProps };
|