feat(js): Document JS based hybrid mode, fix JS packages (#2916)
* feat(js): Document JS based hybrid mode, fix JS packages * update: add model onOpen to docs
This commit is contained in:
parent
fb31580edc
commit
40ca749cf4
4 changed files with 87 additions and 13 deletions
|
|
@ -30,7 +30,10 @@ function logSidepanelState(instance: SidepanelInstance, label: string): void {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const sidepanelInstance = sidepanel({
|
let docsearchInstance: DocSearchInstance | undefined = undefined;
|
||||||
|
let sidepanelInstance: SidepanelInstance | undefined = undefined;
|
||||||
|
|
||||||
|
sidepanelInstance = sidepanel({
|
||||||
container: '#docsearch-sidepanel',
|
container: '#docsearch-sidepanel',
|
||||||
indexName: 'docsearch',
|
indexName: 'docsearch',
|
||||||
appId: 'PMZUYBQDAK',
|
appId: 'PMZUYBQDAK',
|
||||||
|
|
@ -43,6 +46,7 @@ const sidepanelInstance = sidepanel({
|
||||||
onOpen: () => {
|
onOpen: () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('[demo-js] sidepanel onOpen()');
|
console.log('[demo-js] sidepanel onOpen()');
|
||||||
|
docsearchInstance?.close();
|
||||||
},
|
},
|
||||||
onClose: () => {
|
onClose: () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|
@ -63,13 +67,13 @@ console.log('[demo-js] sidepanel try:', {
|
||||||
});
|
});
|
||||||
logSidepanelState(sidepanelInstance, 'sidepanel initial state');
|
logSidepanelState(sidepanelInstance, 'sidepanel initial state');
|
||||||
|
|
||||||
const docsearchInstance = docsearch({
|
docsearchInstance = docsearch({
|
||||||
container: '#docsearch',
|
container: '#docsearch',
|
||||||
indexName: 'docsearch',
|
indexName: 'docsearch',
|
||||||
appId: 'PMZUYBQDAK',
|
appId: 'PMZUYBQDAK',
|
||||||
apiKey: '24b09689d5b4223813d9b8e48563c8f6',
|
apiKey: '24b09689d5b4223813d9b8e48563c8f6',
|
||||||
interceptAskAiEvent: (initialMessage: InitialAskAiMessage) => {
|
interceptAskAiEvent: (initialMessage: InitialAskAiMessage) => {
|
||||||
docsearchInstance.close();
|
docsearchInstance?.close();
|
||||||
sidepanelInstance.open(initialMessage);
|
sidepanelInstance.open(initialMessage);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
@ -80,6 +84,7 @@ const docsearchInstance = docsearch({
|
||||||
onOpen: () => {
|
onOpen: () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('[demo-js] docsearch onOpen()');
|
console.log('[demo-js] docsearch onOpen()');
|
||||||
|
sidepanelInstance.close();
|
||||||
},
|
},
|
||||||
onClose: () => {
|
onClose: () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ const sharedConfig: UserConfig = {
|
||||||
js: '.js',
|
js: '.js',
|
||||||
}),
|
}),
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
noExternal: ['@docsearch/react', '@docsearch/core'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ const sharedConfig: UserConfig = {
|
||||||
js: '.js',
|
js: '.js',
|
||||||
}),
|
}),
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
|
noExternal: ['@docsearch/react', '@docsearch/core'],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ title: Hybrid Mode
|
||||||
import Tabs from '@theme/Tabs';
|
import Tabs from '@theme/Tabs';
|
||||||
import TabItem from '@theme/TabItem';
|
import TabItem from '@theme/TabItem';
|
||||||
|
|
||||||
:::info
|
|
||||||
Currently Hybrid Mode is only available when using the React usage approach. Hybrid Mode is not available in the JavaScript-only (vanilla) integration.
|
|
||||||
:::
|
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Sidepanel can run alongside the DocSearch Modal through what we call "Hybrid Mode." When a user initiates an Ask AI action from within
|
Sidepanel can run alongside the DocSearch Modal through what we call "Hybrid Mode." When a user initiates an Ask AI action from within
|
||||||
|
|
@ -20,15 +16,19 @@ the continuation of the conversation.
|
||||||
To set up the Hybrid Mode experience, you will need the following:
|
To set up the Hybrid Mode experience, you will need the following:
|
||||||
|
|
||||||
- [DocSearch Modal][1] packages installed
|
- [DocSearch Modal][1] packages installed
|
||||||
- Sidepanel Component package installed
|
- [Sidepanel Component][2] package installed
|
||||||
|
|
||||||
The Sidepanel Component package can be installed as follows:
|
The needed packages can be installed as follows:
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value="npm">
|
<TabItem value="npm">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install @docsearch/sidepanel
|
npm install @docsearch/css @docsearch/modal @docsearch/sidepanel
|
||||||
|
|
||||||
|
# Or if using JS based packages
|
||||||
|
|
||||||
|
npm install @docsearch/css @docsearch/js @docsearch/sidepanel-js
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
@ -36,7 +36,11 @@ npm install @docsearch/sidepanel
|
||||||
<TabItem value="yarn">
|
<TabItem value="yarn">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
yarn add @docsearch/sidepanel
|
yarn add @docsearch/css @docsearch/modal @docsearch/sidepanel
|
||||||
|
|
||||||
|
# Or if using JS based packages
|
||||||
|
|
||||||
|
yarn add @docsearch/css @docsearch/js @docsearch/sidepanel-js
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
@ -44,7 +48,11 @@ yarn add @docsearch/sidepanel
|
||||||
<TabItem value="pnpm">
|
<TabItem value="pnpm">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm add @docsearch/sidepanel
|
pnpm add @docsearch/css @docsearch/modal @docsearch/sidepanel
|
||||||
|
|
||||||
|
# Or if using JS based packages
|
||||||
|
|
||||||
|
pnpm add @docsearch/css @docsearch/js @docsearch/sidepanel-js
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
@ -52,7 +60,11 @@ pnpm add @docsearch/sidepanel
|
||||||
<TabItem value="bun">
|
<TabItem value="bun">
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bun add @docsearch/sidepanel
|
bun add @docsearch/css @docsearch/modal @docsearch/sidepanel
|
||||||
|
|
||||||
|
# Or if using JS based packages
|
||||||
|
|
||||||
|
bun add @docsearch/css @docsearch/js @docsearch/sidepanel-js
|
||||||
```
|
```
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
@ -64,6 +76,9 @@ bun add @docsearch/sidepanel
|
||||||
|
|
||||||
Once everything is installed, you can set up Hybrid Mode as such:
|
Once everything is installed, you can set up Hybrid Mode as such:
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<TabItem value="React">
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
import { DocSearch } from '@docsearch/core';
|
import { DocSearch } from '@docsearch/core';
|
||||||
import { DocSearchButton, DocSearchModal } from '@docsearch/modal';
|
import { DocSearchButton, DocSearchModal } from '@docsearch/modal';
|
||||||
|
|
@ -97,4 +112,56 @@ function HybridMode() {
|
||||||
|
|
||||||
There is no manual opt-in for Hybrid Mode to work. When both the Modal and Sidepanel are rendered inside the same `<DocSearch>` context, Hybrid Mode is enabled automatically. No additional configuration is required.
|
There is no manual opt-in for Hybrid Mode to work. When both the Modal and Sidepanel are rendered inside the same `<DocSearch>` context, Hybrid Mode is enabled automatically. No additional configuration is required.
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
|
||||||
|
<TabItem value="JavaScript">
|
||||||
|
|
||||||
|
```html
|
||||||
|
<div id="docsearch"></div>
|
||||||
|
<div id="sidepanel"></div>
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
import docsearch from '@docsearch/js';
|
||||||
|
import sidepanel from '@docsearch/sidepanel-js';
|
||||||
|
|
||||||
|
import '@docsearch/css/dist/style.css';
|
||||||
|
import '@docsearch/css/dist/sidepanel.css';
|
||||||
|
|
||||||
|
let docsearchInstance = undefined;
|
||||||
|
let sidepanelInstance = undefined;
|
||||||
|
|
||||||
|
sidepanelInstance = sidepanel({
|
||||||
|
container: "#sidepanel",
|
||||||
|
indexName: "YOUR_INDEX_NAME",
|
||||||
|
appId: "YOUR_APP_ID",
|
||||||
|
apiKey: "YOUR_SEARCH_API_KEY",
|
||||||
|
assistantId: "YOUR_ASSISTANT_ID",
|
||||||
|
onOpen: () => {
|
||||||
|
docsearchInstance?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
docsearchInstance = docsearch({
|
||||||
|
container: "#docsearch",
|
||||||
|
indexName: "YOUR_INDEX_NAME",
|
||||||
|
appId: "YOUR_APP_ID",
|
||||||
|
apiKey: "YOUR_SEARCH_API_KEY",
|
||||||
|
askAi: "YOUR_ASSISTANT_ID", // Or configuration object
|
||||||
|
interceptAskAiEvent: (initialMessage) => {
|
||||||
|
docsearchInstance?.close();
|
||||||
|
sidepanelInstance.open(initialMessage);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
onOpen: () => {
|
||||||
|
sidepanelInstance?.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
</TabItem>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
[1]: /docs/docsearch#installation
|
[1]: /docs/docsearch#installation
|
||||||
|
[2]: /docs/sidepanel/getting-started#installation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue