-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docusaurus plugins (v2 & v3) with new React searchbox (0.0.26) (…
- Loading branch information
Showing
59 changed files
with
16,537 additions
and
15,834 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 62 additions & 61 deletions
123
packages/plugin-docusaurus-v3/src/theme/SearchBar/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,74 @@ | ||
// @ts-nocheck | ||
import React from 'react' | ||
import { useLocation } from '@docusaurus/router' | ||
import { useActiveVersion, useVersions } from '@docusaurus/plugin-content-docs/client' | ||
import { useDocsPreferredVersion } from '@docusaurus/theme-common' | ||
import { usePluginData } from '@docusaurus/useGlobalData' | ||
import { SearchBox, SearchButton } from '@orama/searchbox' | ||
import { useOrama } from './useOrama' | ||
|
||
interface PluginData { | ||
searchData: { | ||
current: { data: ArrayBuffer } | null | ||
} | ||
endpoint: { url: string; key: string } | null | ||
analytics: { apiKey: string; indexId: string; enabled: boolean } | null | ||
docsInstances: string[] | ||
} | ||
import React from "react" | ||
import { useLocation } from "@docusaurus/router" | ||
import { useActiveVersion, useVersions } from "@docusaurus/plugin-content-docs/client" | ||
import { useDocsPreferredVersion } from "@docusaurus/theme-common" | ||
import { usePluginData } from "@docusaurus/useGlobalData" | ||
import { OramaSearchBox, OramaSearchButton } from "@orama/react-components" | ||
import { useOrama, PluginData } from "./useOrama" | ||
|
||
export function OramaSearchNoDocs() { | ||
const { searchBoxConfig, colorMode } = useOrama() | ||
const { searchBoxConfig, colorMode } = useOrama() | ||
|
||
return ( | ||
<div> | ||
<SearchButton colorScheme={colorMode} className="DocSearch-Button" /> | ||
{searchBoxConfig && ( | ||
<SearchBox | ||
{...searchBoxConfig} | ||
colorScheme={colorMode} | ||
searchParams={{ | ||
where: { | ||
version: { eq: 'current' } | ||
} | ||
}} | ||
facetProperty="category" | ||
/> | ||
)} | ||
</div> | ||
) | ||
return ( | ||
<div> | ||
<OramaSearchButton colorScheme={colorMode} className="DocSearch-Button" /> | ||
{searchBoxConfig.basic && ( | ||
<OramaSearchBox | ||
{...searchBoxConfig.basic} | ||
{...searchBoxConfig.custom} | ||
colorScheme={colorMode} | ||
searchParams={{ | ||
where: { | ||
version: { eq: "current" } | ||
} | ||
}} | ||
facetProperty="category" | ||
/> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export function OramaSearchWithDocs({ pluginId }: { pluginId: string }) { | ||
const versions = useVersions(pluginId) | ||
const activeVersion = useActiveVersion(pluginId) | ||
const { preferredVersion } = useDocsPreferredVersion(pluginId) | ||
const currentVersion = activeVersion || preferredVersion || versions[0] | ||
const { searchBoxConfig, colorMode } = useOrama() | ||
const searchParams = { | ||
...(currentVersion && { | ||
where: { | ||
version: { eq: currentVersion.name } | ||
} | ||
}) | ||
} | ||
const versions = useVersions(pluginId) | ||
const activeVersion = useActiveVersion(pluginId) | ||
const { preferredVersion } = useDocsPreferredVersion(pluginId) | ||
const currentVersion = activeVersion || preferredVersion || versions[0] | ||
const { searchBoxConfig, colorMode } = useOrama() | ||
|
||
const searchParams = { | ||
...(currentVersion && { | ||
where: { | ||
version: { eq: currentVersion.name } | ||
} | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
<SearchButton colorScheme={colorMode} className="DocSearch-Button" /> | ||
{searchBoxConfig && ( | ||
<SearchBox {...searchBoxConfig} colorScheme={colorMode} searchParams={searchParams} facetProperty="category" /> | ||
)} | ||
</div> | ||
) | ||
return ( | ||
<div> | ||
<OramaSearchButton colorScheme={colorMode} className="DocSearch-Button" /> | ||
{searchBoxConfig.basic && ( | ||
<OramaSearchBox | ||
{...searchBoxConfig.basic} | ||
{...searchBoxConfig.custom} | ||
colorScheme={colorMode} | ||
searchParams={searchParams} | ||
facetProperty="category" | ||
/> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default function OramaSearchWrapper() { | ||
const { pathname } = useLocation() | ||
const { docsInstances }: PluginData = usePluginData('@orama/plugin-docusaurus-v3') as PluginData | ||
const pluginId = docsInstances.filter((id: string) => pathname.includes(id))[0] || docsInstances[0] | ||
if (!pluginId) { | ||
return <OramaSearchNoDocs /> | ||
} | ||
return <OramaSearchWithDocs pluginId={pluginId} /> | ||
const { pathname } = useLocation() | ||
const { docsInstances }: PluginData = usePluginData("@orama/plugin-docusaurus-v3") as PluginData | ||
const pluginId = docsInstances.filter((id: string) => pathname.includes(id))[0] || docsInstances[0] | ||
|
||
if (!pluginId) { | ||
return <OramaSearchNoDocs /> | ||
} | ||
|
||
return <OramaSearchWithDocs pluginId={pluginId} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.