@vx-oss/docs-react 1.0.3
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 +21 -0
- package/README.md +5 -0
- package/css/aspen.css +39 -0
- package/css/black.css +39 -0
- package/css/catppuccin.css +49 -0
- package/css/dusk.css +47 -0
- package/css/emerald.css +39 -0
- package/css/generated/docs.css +1 -0
- package/css/generated/flux.css +1 -0
- package/css/generated/glass.css +1 -0
- package/css/generated/home.css +1 -0
- package/css/generated/notebook.css +1 -0
- package/css/generated/shared.css +1 -0
- package/css/lib/base.css +296 -0
- package/css/lib/default-colors.css +51 -0
- package/css/lib/shiki.css +108 -0
- package/css/neutral.css +7 -0
- package/css/ocean.css +44 -0
- package/css/preset-legacy.css +43 -0
- package/css/preset.css +11 -0
- package/css/purple.css +39 -0
- package/css/ruby.css +39 -0
- package/css/shadcn.css +36 -0
- package/css/solar.css +65 -0
- package/css/style.css +9 -0
- package/css/vitepress.css +72 -0
- package/dist/.translations/index.d.ts +55 -0
- package/dist/.translations/keys.js +55 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/accordion.d.ts +10 -0
- package/dist/components/accordion.js +68 -0
- package/dist/components/banner.d.ts +25 -0
- package/dist/components/banner.js +85 -0
- package/dist/components/callout.d.ts +21 -0
- package/dist/components/callout.js +60 -0
- package/dist/components/card.d.ts +13 -0
- package/dist/components/card.js +39 -0
- package/dist/components/codeblock.d.ts +45 -0
- package/dist/components/codeblock.js +126 -0
- package/dist/components/codeblock.rsc.d.ts +15 -0
- package/dist/components/codeblock.rsc.js +22 -0
- package/dist/components/dialog/search-algolia.d.ts +27 -0
- package/dist/components/dialog/search-algolia.js +64 -0
- package/dist/components/dialog/search-default.d.ts +29 -0
- package/dist/components/dialog/search-default.js +66 -0
- package/dist/components/dialog/search-orama.d.ts +32 -0
- package/dist/components/dialog/search-orama.js +69 -0
- package/dist/components/dialog/search.d.ts +76 -0
- package/dist/components/dialog/search.js +351 -0
- package/dist/components/dynamic-codeblock.core.d.ts +26 -0
- package/dist/components/dynamic-codeblock.core.js +51 -0
- package/dist/components/dynamic-codeblock.d.ts +8 -0
- package/dist/components/dynamic-codeblock.js +17 -0
- package/dist/components/files.d.ts +21 -0
- package/dist/components/files.js +40 -0
- package/dist/components/github-info.d.ts +20 -0
- package/dist/components/github-info.js +75 -0
- package/dist/components/heading.d.ts +9 -0
- package/dist/components/heading.js +38 -0
- package/dist/components/image-zoom.d.ts +18 -0
- package/dist/components/image-zoom.js +32 -0
- package/dist/components/image-zoom2.css +71 -0
- package/dist/components/inline-toc.d.ts +10 -0
- package/dist/components/inline-toc.js +28 -0
- package/dist/components/sidebar/base.d.ts +85 -0
- package/dist/components/sidebar/base.js +277 -0
- package/dist/components/sidebar/link-item.d.ts +12 -0
- package/dist/components/sidebar/link-item.js +37 -0
- package/dist/components/sidebar/page-tree.d.ts +20 -0
- package/dist/components/sidebar/page-tree.js +69 -0
- package/dist/components/sidebar/tabs/dropdown.d.ts +15 -0
- package/dist/components/sidebar/tabs/dropdown.js +83 -0
- package/dist/components/sidebar/tabs/index.d.ts +8 -0
- package/dist/components/sidebar/tabs/index.js +46 -0
- package/dist/components/steps.d.ts +10 -0
- package/dist/components/steps.js +16 -0
- package/dist/components/tabs.d.ts +33 -0
- package/dist/components/tabs.js +95 -0
- package/dist/components/toc/clerk.d.ts +11 -0
- package/dist/components/toc/clerk.js +227 -0
- package/dist/components/toc/default.d.ts +13 -0
- package/dist/components/toc/default.js +260 -0
- package/dist/components/toc/index.d.ts +10 -0
- package/dist/components/toc/index.js +45 -0
- package/dist/components/type-table.d.ts +37 -0
- package/dist/components/type-table.js +117 -0
- package/dist/components/ui/accordion.d.ts +10 -0
- package/dist/components/ui/accordion.js +42 -0
- package/dist/components/ui/button.d.ts +10 -0
- package/dist/components/ui/button.js +20 -0
- package/dist/components/ui/collapsible.d.ts +11 -0
- package/dist/components/ui/collapsible.js +21 -0
- package/dist/components/ui/navigation-menu.d.ts +14 -0
- package/dist/components/ui/navigation-menu.js +41 -0
- package/dist/components/ui/popover.d.ts +9 -0
- package/dist/components/ui/popover.js +20 -0
- package/dist/components/ui/scroll-area.d.ts +9 -0
- package/dist/components/ui/scroll-area.js +34 -0
- package/dist/components/ui/tabs.d.ts +23 -0
- package/dist/components/ui/tabs.js +102 -0
- package/dist/contexts/i18n.d.ts +34 -0
- package/dist/contexts/i18n.js +37 -0
- package/dist/contexts/search.d.ts +64 -0
- package/dist/contexts/search.js +68 -0
- package/dist/contexts/tree.d.ts +29 -0
- package/dist/contexts/tree.js +91 -0
- package/dist/i18n.d.ts +15 -0
- package/dist/i18n.js +38 -0
- package/dist/layouts/docs/client.d.ts +33 -0
- package/dist/layouts/docs/client.js +94 -0
- package/dist/layouts/docs/index.d.ts +32 -0
- package/dist/layouts/docs/index.js +23 -0
- package/dist/layouts/docs/page/index.d.ts +76 -0
- package/dist/layouts/docs/page/index.js +124 -0
- package/dist/layouts/docs/page/slots/breadcrumb.d.ts +7 -0
- package/dist/layouts/docs/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/docs/page/slots/container.d.ts +5 -0
- package/dist/layouts/docs/page/slots/container.js +22 -0
- package/dist/layouts/docs/page/slots/footer.d.ts +16 -0
- package/dist/layouts/docs/page/slots/footer.js +56 -0
- package/dist/layouts/docs/page/slots/toc.d.ts +47 -0
- package/dist/layouts/docs/page/slots/toc.js +182 -0
- package/dist/layouts/docs/slots/container.d.ts +5 -0
- package/dist/layouts/docs/slots/container.js +36 -0
- package/dist/layouts/docs/slots/header.d.ts +5 -0
- package/dist/layouts/docs/slots/header.js +38 -0
- package/dist/layouts/docs/slots/sidebar.d.ts +22 -0
- package/dist/layouts/docs/slots/sidebar.js +268 -0
- package/dist/layouts/flux/index.d.ts +61 -0
- package/dist/layouts/flux/index.js +146 -0
- package/dist/layouts/flux/page/index.d.ts +67 -0
- package/dist/layouts/flux/page/index.js +104 -0
- package/dist/layouts/flux/page/slots/breadcrumb.d.ts +7 -0
- package/dist/layouts/flux/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/flux/page/slots/container.d.ts +5 -0
- package/dist/layouts/flux/page/slots/container.js +22 -0
- package/dist/layouts/flux/page/slots/footer.d.ts +16 -0
- package/dist/layouts/flux/page/slots/footer.js +56 -0
- package/dist/layouts/flux/page/slots/toc.d.ts +29 -0
- package/dist/layouts/flux/page/slots/toc.js +181 -0
- package/dist/layouts/flux/slots/container.d.ts +5 -0
- package/dist/layouts/flux/slots/container.js +13 -0
- package/dist/layouts/flux/slots/sidebar.d.ts +16 -0
- package/dist/layouts/flux/slots/sidebar.js +243 -0
- package/dist/layouts/flux/slots/tab-dropdown.d.ts +10 -0
- package/dist/layouts/flux/slots/tab-dropdown.js +88 -0
- package/dist/layouts/glass/index.d.ts +39 -0
- package/dist/layouts/glass/index.js +70 -0
- package/dist/layouts/glass/layout-tabs.js +54 -0
- package/dist/layouts/glass/page/index.d.ts +31 -0
- package/dist/layouts/glass/page/index.js +92 -0
- package/dist/layouts/glass/page/slots/breadcrumb.d.ts +7 -0
- package/dist/layouts/glass/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/glass/page/slots/footer.d.ts +16 -0
- package/dist/layouts/glass/page/slots/footer.js +56 -0
- package/dist/layouts/glass/page/slots/toc.d.ts +19 -0
- package/dist/layouts/glass/page/slots/toc.js +108 -0
- package/dist/layouts/glass/slots/header.d.ts +6 -0
- package/dist/layouts/glass/slots/header.js +68 -0
- package/dist/layouts/glass/slots/sidebar.d.ts +21 -0
- package/dist/layouts/glass/slots/sidebar.js +267 -0
- package/dist/layouts/home/index.d.ts +27 -0
- package/dist/layouts/home/index.js +40 -0
- package/dist/layouts/home/navbar.d.ts +9 -0
- package/dist/layouts/home/navbar.js +34 -0
- package/dist/layouts/home/not-found.d.ts +7 -0
- package/dist/layouts/home/not-found.js +41 -0
- package/dist/layouts/home/slots/container.d.ts +5 -0
- package/dist/layouts/home/slots/container.js +13 -0
- package/dist/layouts/home/slots/header.d.ts +8 -0
- package/dist/layouts/home/slots/header.js +239 -0
- package/dist/layouts/notebook/client.d.ts +35 -0
- package/dist/layouts/notebook/client.js +69 -0
- package/dist/layouts/notebook/index.d.ts +26 -0
- package/dist/layouts/notebook/index.js +23 -0
- package/dist/layouts/notebook/page/index.d.ts +76 -0
- package/dist/layouts/notebook/page/index.js +124 -0
- package/dist/layouts/notebook/page/slots/breadcrumb.d.ts +7 -0
- package/dist/layouts/notebook/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/notebook/page/slots/container.d.ts +5 -0
- package/dist/layouts/notebook/page/slots/container.js +22 -0
- package/dist/layouts/notebook/page/slots/footer.d.ts +16 -0
- package/dist/layouts/notebook/page/slots/footer.js +56 -0
- package/dist/layouts/notebook/page/slots/toc.d.ts +47 -0
- package/dist/layouts/notebook/page/slots/toc.js +181 -0
- package/dist/layouts/notebook/slots/container.d.ts +5 -0
- package/dist/layouts/notebook/slots/container.js +38 -0
- package/dist/layouts/notebook/slots/header.d.ts +5 -0
- package/dist/layouts/notebook/slots/header.js +204 -0
- package/dist/layouts/notebook/slots/sidebar.d.ts +23 -0
- package/dist/layouts/notebook/slots/sidebar.js +240 -0
- package/dist/layouts/shared/client.d.ts +37 -0
- package/dist/layouts/shared/client.js +85 -0
- package/dist/layouts/shared/index.d.ts +169 -0
- package/dist/layouts/shared/index.js +98 -0
- package/dist/layouts/shared/page-actions.d.ts +27 -0
- package/dist/layouts/shared/page-actions.js +199 -0
- package/dist/layouts/shared/slots/language-select.d.ts +12 -0
- package/dist/layouts/shared/slots/language-select.js +43 -0
- package/dist/layouts/shared/slots/search-trigger.d.ts +13 -0
- package/dist/layouts/shared/slots/search-trigger.js +53 -0
- package/dist/layouts/shared/slots/theme-switch.d.ts +8 -0
- package/dist/layouts/shared/slots/theme-switch.js +70 -0
- package/dist/legacy/layout.d.ts +29 -0
- package/dist/legacy/layout.js +44 -0
- package/dist/legacy/sidebar.d.ts +14 -0
- package/dist/legacy/sidebar.js +34 -0
- package/dist/mdx.d.ts +44 -0
- package/dist/mdx.js +70 -0
- package/dist/mdx.server.d.ts +14 -0
- package/dist/mdx.server.js +20 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/controlled.d.ts +30 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/controlled.js +461 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/index.d.ts +3 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/uncontrolled.d.ts +6 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/uncontrolled.js +17 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/adjust-svg-ids.js +53 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/compute-positioned-style.js +25 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/element-tests.js +12 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-div-img-style.js +45 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-img-alt.js +10 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-img-object-fit-style.js +57 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-img-regular-style.js +21 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-img-src.js +14 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-modal-img-transform.js +22 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-scale.js +27 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-style-ghost.js +31 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-style-modal-img.js +75 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/get-target-dimension.js +4 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/parse-position.js +7 -0
- package/dist/node_modules/.pnpm/react-medium-image-zoom@5.4.9_react-dom@19.2.8_react@19.2.8__react@19.2.8/node_modules/react-medium-image-zoom/dist/utils/test-has-scalable-src.js +5 -0
- package/dist/og/takumi.d.ts +15 -0
- package/dist/og/takumi.js +91 -0
- package/dist/og.d.ts +16 -0
- package/dist/og.js +91 -0
- package/dist/page.d.ts +29 -0
- package/dist/page.js +33 -0
- package/dist/provider/astro.d.ts +29 -0
- package/dist/provider/astro.js +20 -0
- package/dist/provider/base.d.ts +48 -0
- package/dist/provider/base.js +73 -0
- package/dist/provider/next.d.ts +16 -0
- package/dist/provider/next.js +17 -0
- package/dist/provider/react-router.d.ts +16 -0
- package/dist/provider/react-router.js +17 -0
- package/dist/provider/tanstack.d.ts +16 -0
- package/dist/provider/tanstack.js +17 -0
- package/dist/provider/waku.d.ts +16 -0
- package/dist/provider/waku.js +17 -0
- package/dist/style.css +3640 -0
- package/dist/tailwind/typography.d.ts +2 -0
- package/dist/tailwind/typography.js +2 -0
- package/dist/utils/cn.js +2 -0
- package/dist/utils/merge-refs.js +11 -0
- package/dist/utils/urls.js +15 -0
- package/dist/utils/use-copy-button.d.ts +5 -0
- package/dist/utils/use-copy-button.js +26 -0
- package/dist/utils/use-footer-items.d.ts +8 -0
- package/dist/utils/use-footer-items.js +24 -0
- package/dist/utils/use-is-scroll-top.d.ts +6 -0
- package/dist/utils/use-is-scroll-top.js +20 -0
- package/package.json +212 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SearchLink, SharedProps, TagItem } from "../../contexts/search.js";
|
|
2
|
+
import "./search.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import { OramaCloudOptions } from "@vx-oss/docs-core/search/client";
|
|
5
|
+
//#region src/components/dialog/search-orama.d.ts
|
|
6
|
+
interface OramaSearchDialogProps extends SharedProps {
|
|
7
|
+
links?: SearchLink[];
|
|
8
|
+
client: OramaCloudOptions['client'];
|
|
9
|
+
searchOptions?: OramaCloudOptions['params'];
|
|
10
|
+
index?: OramaCloudOptions['index'];
|
|
11
|
+
footer?: ReactNode;
|
|
12
|
+
defaultTag?: string;
|
|
13
|
+
tags?: TagItem[];
|
|
14
|
+
/**
|
|
15
|
+
* Add the "Powered by Orama" label
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue true
|
|
18
|
+
*/
|
|
19
|
+
showOrama?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Allow to clear tag filters
|
|
22
|
+
*
|
|
23
|
+
* @defaultValue false
|
|
24
|
+
*/
|
|
25
|
+
allowClear?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Orama Cloud integration
|
|
29
|
+
*/
|
|
30
|
+
declare function OramaSearchDialog({ client, searchOptions, tags, defaultTag, showOrama, allowClear, index, footer, links, ...props }: OramaSearchDialogProps): import("react").JSX.Element;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { OramaSearchDialogProps, OramaSearchDialog as default };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useI18n } from "../../contexts/i18n.js";
|
|
3
|
+
import { SearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogOverlay, TagsList, TagsListItem } from "./search.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { useMemo, useState } from "react";
|
|
6
|
+
import { useOnChange } from "@vx-oss/docs-core/utils/use-on-change";
|
|
7
|
+
import { useDocsSearch } from "@vx-oss/docs-core/search/client";
|
|
8
|
+
import { oramaCloudClient } from "@vx-oss/docs-core/search/client/orama-cloud";
|
|
9
|
+
//#region src/components/dialog/search-orama.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Orama Cloud integration
|
|
12
|
+
*/
|
|
13
|
+
function OramaSearchDialog({ client, searchOptions, tags = [], defaultTag, showOrama = true, allowClear = false, index, footer, links = [], ...props }) {
|
|
14
|
+
const { locale } = useI18n();
|
|
15
|
+
const [tag, setTag] = useState(defaultTag);
|
|
16
|
+
const { search, setSearch, query } = useDocsSearch({ client: oramaCloudClient({
|
|
17
|
+
client,
|
|
18
|
+
index,
|
|
19
|
+
params: searchOptions,
|
|
20
|
+
locale,
|
|
21
|
+
tag
|
|
22
|
+
}) });
|
|
23
|
+
const defaultItems = useMemo(() => {
|
|
24
|
+
if (links.length === 0) return null;
|
|
25
|
+
return links.map(([name, link]) => ({
|
|
26
|
+
type: "page",
|
|
27
|
+
id: name,
|
|
28
|
+
content: name,
|
|
29
|
+
url: link
|
|
30
|
+
}));
|
|
31
|
+
}, [links]);
|
|
32
|
+
useOnChange(defaultTag, (v) => {
|
|
33
|
+
setTag(v);
|
|
34
|
+
});
|
|
35
|
+
const label = showOrama && /* @__PURE__ */ jsx(Label, {});
|
|
36
|
+
return /* @__PURE__ */ jsxs(SearchDialog, {
|
|
37
|
+
search,
|
|
38
|
+
onSearchChange: setSearch,
|
|
39
|
+
isLoading: query.isLoading,
|
|
40
|
+
...props,
|
|
41
|
+
children: [/* @__PURE__ */ jsx(SearchDialogOverlay, {}), /* @__PURE__ */ jsxs(SearchDialogContent, { children: [
|
|
42
|
+
/* @__PURE__ */ jsxs(SearchDialogHeader, { children: [
|
|
43
|
+
/* @__PURE__ */ jsx(SearchDialogIcon, {}),
|
|
44
|
+
/* @__PURE__ */ jsx(SearchDialogInput, {}),
|
|
45
|
+
/* @__PURE__ */ jsx(SearchDialogClose, {})
|
|
46
|
+
] }),
|
|
47
|
+
/* @__PURE__ */ jsx(SearchDialogList, { items: query.data !== "empty" ? query.data : defaultItems }),
|
|
48
|
+
/* @__PURE__ */ jsxs(SearchDialogFooter, { children: [tags.length > 0 ? /* @__PURE__ */ jsxs(TagsList, {
|
|
49
|
+
tag,
|
|
50
|
+
onTagChange: setTag,
|
|
51
|
+
allowClear,
|
|
52
|
+
children: [tags.map((tag) => /* @__PURE__ */ jsx(TagsListItem, {
|
|
53
|
+
value: tag.value,
|
|
54
|
+
children: tag.name
|
|
55
|
+
}, tag.value)), label]
|
|
56
|
+
}) : label, footer] })
|
|
57
|
+
] })]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function Label() {
|
|
61
|
+
return /* @__PURE__ */ jsx("a", {
|
|
62
|
+
href: "https://orama.com",
|
|
63
|
+
rel: "noreferrer noopener",
|
|
64
|
+
className: "ms-auto text-xs text-fd-muted-foreground",
|
|
65
|
+
children: "Search powered by Orama"
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
export { OramaSearchDialog as default };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SharedProps } from "../../contexts/search.js";
|
|
2
|
+
import { ComponentProps, ReactNode } from "react";
|
|
3
|
+
import { DialogContent, DialogOverlay } from "@radix-ui/react-dialog";
|
|
4
|
+
import { HighlightedText, ReactSortedResult } from "@vx-oss/docs-core/search";
|
|
5
|
+
//#region src/components/dialog/search.d.ts
|
|
6
|
+
type SearchItemType = (ReactSortedResult & {
|
|
7
|
+
external?: boolean;
|
|
8
|
+
}) | {
|
|
9
|
+
id: string;
|
|
10
|
+
type: 'action';
|
|
11
|
+
node: ReactNode;
|
|
12
|
+
onSelect: () => void;
|
|
13
|
+
};
|
|
14
|
+
interface SearchDialogProps extends SharedProps {
|
|
15
|
+
search: string;
|
|
16
|
+
onSearchChange: (v: string) => void;
|
|
17
|
+
onSelect?: (item: SearchItemType) => void;
|
|
18
|
+
isLoading?: boolean;
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
declare function SearchDialog({ open, onOpenChange, search, onSearchChange, isLoading, onSelect: onSelectProp, children }: SearchDialogProps): import("react").JSX.Element;
|
|
22
|
+
declare function SearchDialogHeader(props: ComponentProps<'div'>): import("react").JSX.Element;
|
|
23
|
+
declare function SearchDialogInput(props: ComponentProps<'input'>): import("react").JSX.Element;
|
|
24
|
+
declare function SearchDialogClose({ children, className, ...props }: ComponentProps<'button'>): import("react").JSX.Element;
|
|
25
|
+
declare function SearchDialogFooter(props: ComponentProps<'div'>): import("react").JSX.Element;
|
|
26
|
+
declare function SearchDialogOverlay(props: ComponentProps<typeof DialogOverlay>): import("react").JSX.Element;
|
|
27
|
+
declare function SearchDialogContent({ children, ...props }: ComponentProps<typeof DialogContent>): import("react").JSX.Element;
|
|
28
|
+
declare function SearchDialogList({ items, Empty, Item, ...props }: Omit<ComponentProps<'div'>, 'children'> & {
|
|
29
|
+
items: SearchItemType[] | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Renderer for empty list UI
|
|
32
|
+
*/
|
|
33
|
+
Empty?: () => ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* Renderer for items
|
|
36
|
+
*/
|
|
37
|
+
Item?: (props: {
|
|
38
|
+
item: SearchItemType;
|
|
39
|
+
onClick: () => void;
|
|
40
|
+
}) => ReactNode;
|
|
41
|
+
}): import("react").JSX.Element;
|
|
42
|
+
declare function SearchDialogListItem({ item, className, children, renderMarkdown, renderHighlights: _, ...props }: ComponentProps<'button'> & {
|
|
43
|
+
renderMarkdown?: (v: string) => ReactNode;
|
|
44
|
+
/** @deprecated highlight blocks is now wrapped in `<mark />`, use `renderMarkdown` to handle instead. */
|
|
45
|
+
renderHighlights?: (blocks: HighlightedText<ReactNode>[]) => ReactNode;
|
|
46
|
+
item: SearchItemType;
|
|
47
|
+
}): import("react").JSX.Element;
|
|
48
|
+
declare function SearchDialogIcon(props: ComponentProps<'svg'>): import("react").JSX.Element;
|
|
49
|
+
interface TagsListProps extends ComponentProps<'div'> {
|
|
50
|
+
tag?: string;
|
|
51
|
+
onTagChange: (tag: string | undefined) => void;
|
|
52
|
+
allowClear?: boolean;
|
|
53
|
+
}
|
|
54
|
+
declare function TagsList({ tag, onTagChange, allowClear, ...props }: TagsListProps): import("react").JSX.Element;
|
|
55
|
+
declare function TagsListItem({ value, className, ...props }: ComponentProps<'button'> & {
|
|
56
|
+
value: string;
|
|
57
|
+
}): import("react").JSX.Element;
|
|
58
|
+
declare function useSearch(): {
|
|
59
|
+
open: boolean;
|
|
60
|
+
onOpenChange: (open: boolean) => void;
|
|
61
|
+
search: string;
|
|
62
|
+
onSearchChange: (v: string) => void;
|
|
63
|
+
onSelect: (item: SearchItemType) => void;
|
|
64
|
+
isLoading: boolean;
|
|
65
|
+
};
|
|
66
|
+
declare function useTagsList(): {
|
|
67
|
+
value?: string;
|
|
68
|
+
onValueChange: (value: string | undefined) => void;
|
|
69
|
+
allowClear: boolean;
|
|
70
|
+
};
|
|
71
|
+
declare function useSearchList(): {
|
|
72
|
+
active: string | null;
|
|
73
|
+
setActive: (v: string | null) => void;
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { SearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogListItem, SearchDialogOverlay, SearchDialogProps, SearchItemType, type SharedProps, TagsList, TagsListItem, TagsListProps, useSearch, useSearchList, useTagsList };
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { buttonVariants } from "../ui/button.js";
|
|
4
|
+
import { useRouter } from "@vx-oss/docs-core/framework";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { ChevronRight, Hash, SearchIcon } from "lucide-react";
|
|
7
|
+
import { cva } from "class-variance-authority";
|
|
8
|
+
import { Fragment as Fragment$1, createContext, use, useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
|
|
9
|
+
import { T, useTranslations } from "@fuma-translate/react";
|
|
10
|
+
import { useOnChange } from "@vx-oss/docs-core/utils/use-on-change";
|
|
11
|
+
import scrollIntoView from "scroll-into-view-if-needed";
|
|
12
|
+
import { Dialog, DialogContent, DialogOverlay, DialogTitle } from "@radix-ui/react-dialog";
|
|
13
|
+
import { createMarkdownRenderer } from "@vx-oss/docs-core/content/md";
|
|
14
|
+
import rehypeRaw from "rehype-raw";
|
|
15
|
+
import { visit } from "unist-util-visit";
|
|
16
|
+
//#region src/components/dialog/search.tsx
|
|
17
|
+
const RootContext = createContext(null);
|
|
18
|
+
const ListContext = createContext(null);
|
|
19
|
+
const TagsListContext = createContext(null);
|
|
20
|
+
const PreContext = createContext(false);
|
|
21
|
+
const mdRenderer = createMarkdownRenderer({
|
|
22
|
+
remarkRehypeOptions: { allowDangerousHtml: true },
|
|
23
|
+
rehypePlugins: [rehypeRaw, rehypeCustomElements]
|
|
24
|
+
});
|
|
25
|
+
const mdComponents = {
|
|
26
|
+
mark(props) {
|
|
27
|
+
return /* @__PURE__ */ jsx("span", {
|
|
28
|
+
...props,
|
|
29
|
+
className: "text-fd-primary underline"
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
a: "span",
|
|
33
|
+
p(props) {
|
|
34
|
+
return /* @__PURE__ */ jsx("p", {
|
|
35
|
+
...props,
|
|
36
|
+
className: "min-w-0"
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
strong(props) {
|
|
40
|
+
return /* @__PURE__ */ jsx("strong", {
|
|
41
|
+
...props,
|
|
42
|
+
className: "text-fd-accent-foreground font-medium"
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
code(props) {
|
|
46
|
+
if (use(PreContext)) return /* @__PURE__ */ jsx("code", {
|
|
47
|
+
...props,
|
|
48
|
+
className: "mask-[linear-gradient(to_bottom,white,white_30px,transparent_80px)]"
|
|
49
|
+
});
|
|
50
|
+
return /* @__PURE__ */ jsx("code", {
|
|
51
|
+
...props,
|
|
52
|
+
className: "border rounded-md px-px bg-fd-secondary text-fd-secondary-foreground"
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
custom({ _tagName = "fragment", children, ...rest }) {
|
|
56
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
57
|
+
className: "inline-flex max-w-full items-center border p-0.5 rounded-md bg-fd-card text-fd-card-foreground divide-x divide-fd-border",
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx("code", {
|
|
60
|
+
className: "rounded-sm px-0.5 me-1 bg-fd-primary font-medium text-xs text-fd-primary-foreground border-none",
|
|
61
|
+
children: _tagName
|
|
62
|
+
}),
|
|
63
|
+
Object.entries(rest).map(([k, v]) => {
|
|
64
|
+
if (typeof v !== "string") return;
|
|
65
|
+
return /* @__PURE__ */ jsxs("code", {
|
|
66
|
+
className: "truncate text-xs text-fd-muted-foreground px-1",
|
|
67
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
68
|
+
className: "text-fd-card-foreground",
|
|
69
|
+
children: [k, ": "]
|
|
70
|
+
}), v]
|
|
71
|
+
}, k);
|
|
72
|
+
}),
|
|
73
|
+
children && /* @__PURE__ */ jsx("span", {
|
|
74
|
+
className: "ps-1",
|
|
75
|
+
children
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
pre(props) {
|
|
81
|
+
return /* @__PURE__ */ jsx("pre", {
|
|
82
|
+
...props,
|
|
83
|
+
className: cn("flex flex-col border rounded-md my-0.5 p-2 bg-fd-secondary text-fd-secondary-foreground max-h-20 overflow-hidden", props.className),
|
|
84
|
+
children: /* @__PURE__ */ jsx(PreContext, {
|
|
85
|
+
value: true,
|
|
86
|
+
children: props.children
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function rehypeCustomElements() {
|
|
92
|
+
return (tree) => {
|
|
93
|
+
visit(tree, (node) => {
|
|
94
|
+
if (node.type === "element" && document.createElement(node.tagName) instanceof HTMLUnknownElement) {
|
|
95
|
+
node.properties._tagName = node.tagName;
|
|
96
|
+
node.tagName = "custom";
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function SearchDialog({ open, onOpenChange, search, onSearchChange, isLoading = false, onSelect: onSelectProp, children }) {
|
|
102
|
+
const router = useRouter();
|
|
103
|
+
const onOpenChangeCallback = useRef(onOpenChange);
|
|
104
|
+
onOpenChangeCallback.current = onOpenChange;
|
|
105
|
+
const onSearchChangeCallback = useRef(onSearchChange);
|
|
106
|
+
onSearchChangeCallback.current = onSearchChange;
|
|
107
|
+
const onSelect = (item) => {
|
|
108
|
+
if (item.type === "action") item.onSelect();
|
|
109
|
+
else if (item.external) window.open(item.url, "_blank")?.focus();
|
|
110
|
+
else router.push(item.url);
|
|
111
|
+
onOpenChange(false);
|
|
112
|
+
onSelectProp?.(item);
|
|
113
|
+
};
|
|
114
|
+
const onSelectCallback = useRef(onSelect);
|
|
115
|
+
onSelectCallback.current = onSelect;
|
|
116
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
117
|
+
open,
|
|
118
|
+
onOpenChange,
|
|
119
|
+
children: /* @__PURE__ */ jsx(RootContext, {
|
|
120
|
+
value: useMemo(() => ({
|
|
121
|
+
open,
|
|
122
|
+
search,
|
|
123
|
+
isLoading,
|
|
124
|
+
onOpenChange: (v) => onOpenChangeCallback.current(v),
|
|
125
|
+
onSearchChange: (v) => onSearchChangeCallback.current(v),
|
|
126
|
+
onSelect: (v) => onSelectCallback.current(v)
|
|
127
|
+
}), [
|
|
128
|
+
isLoading,
|
|
129
|
+
open,
|
|
130
|
+
search
|
|
131
|
+
]),
|
|
132
|
+
children
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function SearchDialogHeader(props) {
|
|
137
|
+
return /* @__PURE__ */ jsx("div", {
|
|
138
|
+
...props,
|
|
139
|
+
className: cn("flex flex-row items-center gap-2 p-3", props.className)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function SearchDialogInput(props) {
|
|
143
|
+
const t = useTranslations({ note: "search dialog" });
|
|
144
|
+
const { search, onSearchChange } = useSearch();
|
|
145
|
+
return /* @__PURE__ */ jsx("input", {
|
|
146
|
+
...props,
|
|
147
|
+
value: search,
|
|
148
|
+
onChange: (e) => onSearchChange(e.target.value),
|
|
149
|
+
placeholder: t("Search"),
|
|
150
|
+
className: "w-0 flex-1 bg-transparent text-lg placeholder:text-fd-muted-foreground focus-visible:outline-none"
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function SearchDialogClose({ children = "ESC", className, ...props }) {
|
|
154
|
+
const { onOpenChange } = useSearch();
|
|
155
|
+
const t = useTranslations({ note: "search dialog" });
|
|
156
|
+
return /* @__PURE__ */ jsx("button", {
|
|
157
|
+
type: "button",
|
|
158
|
+
"aria-label": t("Close Search", { note: "aria-label" }),
|
|
159
|
+
onClick: () => onOpenChange(false),
|
|
160
|
+
className: cn(buttonVariants({
|
|
161
|
+
color: "outline",
|
|
162
|
+
size: "sm",
|
|
163
|
+
className: "font-mono text-fd-muted-foreground"
|
|
164
|
+
}), className),
|
|
165
|
+
...props,
|
|
166
|
+
children
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function SearchDialogFooter(props) {
|
|
170
|
+
return /* @__PURE__ */ jsx("div", {
|
|
171
|
+
...props,
|
|
172
|
+
className: cn("bg-fd-secondary/50 p-3 empty:hidden", props.className)
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function SearchDialogOverlay(props) {
|
|
176
|
+
return /* @__PURE__ */ jsx(DialogOverlay, {
|
|
177
|
+
...props,
|
|
178
|
+
className: cn("fixed inset-0 z-50 backdrop-blur-xs bg-fd-overlay data-[state=open]:animate-fd-fade-in data-[state=closed]:animate-fd-fade-out", props.className)
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function SearchDialogContent({ children, ...props }) {
|
|
182
|
+
const t = useTranslations({ note: "search dialog" });
|
|
183
|
+
return /* @__PURE__ */ jsxs(DialogContent, {
|
|
184
|
+
"aria-describedby": void 0,
|
|
185
|
+
...props,
|
|
186
|
+
className: cn("fixed left-1/2 top-4 md:top-[calc(50%-250px)] z-50 w-[calc(100%-1rem)] max-w-screen-sm -translate-x-1/2 rounded-xl border bg-fd-popover text-fd-popover-foreground shadow-2xl shadow-black/50 overflow-hidden data-[state=closed]:animate-fd-dialog-out data-[state=open]:animate-fd-dialog-in", "*:border-b *:has-[+:last-child[data-empty=true]]:border-b-0 *:data-[empty=true]:border-b-0 *:last:border-b-0", props.className),
|
|
187
|
+
children: [/* @__PURE__ */ jsx(DialogTitle, {
|
|
188
|
+
className: "hidden",
|
|
189
|
+
children: t("Search")
|
|
190
|
+
}), children]
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
function SearchDialogList({ items = null, Empty = () => /* @__PURE__ */ jsx("div", {
|
|
194
|
+
className: "py-12 text-center text-sm text-fd-muted-foreground",
|
|
195
|
+
children: /* @__PURE__ */ jsx(T, {
|
|
196
|
+
text: "No results found",
|
|
197
|
+
note: "search dialog"
|
|
198
|
+
})
|
|
199
|
+
}), Item = (props) => /* @__PURE__ */ jsx(SearchDialogListItem, { ...props }), ...props }) {
|
|
200
|
+
const ref = useRef(null);
|
|
201
|
+
const { onSelect } = useSearch();
|
|
202
|
+
const [active, setActive] = useState(() => items && items.length > 0 ? items[0].id : null);
|
|
203
|
+
const onKey = useEffectEvent((e) => {
|
|
204
|
+
if (!items || e.isComposing || e.keyCode === 229) return;
|
|
205
|
+
if (e.key === "ArrowDown" || e.key == "ArrowUp") {
|
|
206
|
+
let idx = items.findIndex((item) => item.id === active);
|
|
207
|
+
if (idx === -1) idx = 0;
|
|
208
|
+
else if (e.key === "ArrowDown") idx++;
|
|
209
|
+
else idx--;
|
|
210
|
+
setActive(items.at(idx % items.length)?.id ?? null);
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
}
|
|
213
|
+
if (e.key === "Enter") {
|
|
214
|
+
const selected = items.find((item) => item.id === active);
|
|
215
|
+
if (selected) onSelect(selected);
|
|
216
|
+
e.preventDefault();
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
const element = ref.current;
|
|
221
|
+
if (!element) return;
|
|
222
|
+
const observer = new ResizeObserver(() => {
|
|
223
|
+
const viewport = element.firstElementChild;
|
|
224
|
+
element.style.setProperty("--fd-animated-height", `${viewport.clientHeight}px`);
|
|
225
|
+
});
|
|
226
|
+
const viewport = element.firstElementChild;
|
|
227
|
+
if (viewport) observer.observe(viewport);
|
|
228
|
+
window.addEventListener("keydown", onKey);
|
|
229
|
+
return () => {
|
|
230
|
+
observer.disconnect();
|
|
231
|
+
window.removeEventListener("keydown", onKey);
|
|
232
|
+
};
|
|
233
|
+
}, []);
|
|
234
|
+
useOnChange(items, () => {
|
|
235
|
+
if (items && items.length > 0) setActive(items[0].id);
|
|
236
|
+
});
|
|
237
|
+
return /* @__PURE__ */ jsx("div", {
|
|
238
|
+
...props,
|
|
239
|
+
ref,
|
|
240
|
+
"data-empty": items === null,
|
|
241
|
+
className: cn("overflow-hidden h-(--fd-animated-height) transition-[height]", props.className),
|
|
242
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
243
|
+
className: cn("w-full flex flex-col overflow-y-auto max-h-[460px] p-1", !items && "hidden"),
|
|
244
|
+
children: /* @__PURE__ */ jsxs(ListContext, {
|
|
245
|
+
value: useMemo(() => ({
|
|
246
|
+
active,
|
|
247
|
+
setActive
|
|
248
|
+
}), [active]),
|
|
249
|
+
children: [items?.length === 0 && Empty(), items?.map((item) => /* @__PURE__ */ jsx(Fragment$1, { children: Item({
|
|
250
|
+
item,
|
|
251
|
+
onClick: () => onSelect(item)
|
|
252
|
+
}) }, item.id))]
|
|
253
|
+
})
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function SearchDialogListItem({ item, className, children, renderMarkdown = (s) => /* @__PURE__ */ jsx(mdRenderer.Markdown, {
|
|
258
|
+
components: mdComponents,
|
|
259
|
+
children: s
|
|
260
|
+
}), renderHighlights: _, ...props }) {
|
|
261
|
+
const { active: activeId, setActive } = useSearchList();
|
|
262
|
+
const active = item.id === activeId;
|
|
263
|
+
if (item.type === "action") children ??= item.node;
|
|
264
|
+
else children ??= /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
265
|
+
/* @__PURE__ */ jsx("div", {
|
|
266
|
+
className: "inline-flex items-center text-fd-muted-foreground text-xs empty:hidden",
|
|
267
|
+
children: item.breadcrumbs?.map((item, i) => /* @__PURE__ */ jsxs(Fragment$1, { children: [i > 0 && /* @__PURE__ */ jsx(ChevronRight, { className: "size-4 rtl:rotate-180" }), item] }, i))
|
|
268
|
+
}),
|
|
269
|
+
item.type !== "page" && /* @__PURE__ */ jsx("div", {
|
|
270
|
+
role: "none",
|
|
271
|
+
className: "absolute inset-s-3 inset-y-0 w-px bg-fd-border"
|
|
272
|
+
}),
|
|
273
|
+
item.type === "heading" && /* @__PURE__ */ jsx(Hash, { className: "absolute inset-s-6 top-2.5 size-4 text-fd-muted-foreground" }),
|
|
274
|
+
/* @__PURE__ */ jsx("div", {
|
|
275
|
+
className: cn("min-w-0", item.type === "text" && "ps-4", item.type === "heading" && "ps-8", item.type === "page" || item.type === "heading" ? "font-medium" : "text-fd-popover-foreground/80"),
|
|
276
|
+
children: typeof item.content === "string" ? renderMarkdown(item.content) : item.content
|
|
277
|
+
})
|
|
278
|
+
] });
|
|
279
|
+
return /* @__PURE__ */ jsx("button", {
|
|
280
|
+
type: "button",
|
|
281
|
+
ref: useCallback((element) => {
|
|
282
|
+
if (active && element) scrollIntoView(element, {
|
|
283
|
+
scrollMode: "if-needed",
|
|
284
|
+
block: "nearest",
|
|
285
|
+
boundary: element.parentElement
|
|
286
|
+
});
|
|
287
|
+
}, [active]),
|
|
288
|
+
"aria-selected": active,
|
|
289
|
+
className: cn("relative select-none shrink-0 px-2.5 py-2 text-start text-sm overflow-hidden rounded-lg", active && "bg-fd-accent text-fd-accent-foreground", className),
|
|
290
|
+
onPointerMove: () => setActive(item.id),
|
|
291
|
+
...props,
|
|
292
|
+
children
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function SearchDialogIcon(props) {
|
|
296
|
+
const { isLoading } = useSearch();
|
|
297
|
+
return /* @__PURE__ */ jsx(SearchIcon, {
|
|
298
|
+
...props,
|
|
299
|
+
className: cn("size-5 text-fd-muted-foreground", isLoading && "animate-pulse duration-400", props.className)
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
const itemVariants = cva("rounded-md border px-2 py-0.5 text-xs font-medium text-fd-muted-foreground transition-colors", { variants: { active: { true: "bg-fd-accent text-fd-accent-foreground" } } });
|
|
303
|
+
function TagsList({ tag, onTagChange, allowClear = false, ...props }) {
|
|
304
|
+
const onTagChangeCallback = useRef(onTagChange);
|
|
305
|
+
onTagChangeCallback.current = onTagChange;
|
|
306
|
+
return /* @__PURE__ */ jsx("div", {
|
|
307
|
+
...props,
|
|
308
|
+
className: cn("flex items-center gap-1 flex-wrap", props.className),
|
|
309
|
+
children: /* @__PURE__ */ jsx(TagsListContext, {
|
|
310
|
+
value: useMemo(() => ({
|
|
311
|
+
value: tag,
|
|
312
|
+
onValueChange: (v) => onTagChangeCallback.current(v),
|
|
313
|
+
allowClear
|
|
314
|
+
}), [allowClear, tag]),
|
|
315
|
+
children: props.children
|
|
316
|
+
})
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
function TagsListItem({ value, className, ...props }) {
|
|
320
|
+
const { onValueChange, value: selectedValue, allowClear } = useTagsList();
|
|
321
|
+
const selected = value === selectedValue;
|
|
322
|
+
return /* @__PURE__ */ jsx("button", {
|
|
323
|
+
type: "button",
|
|
324
|
+
"data-active": selected,
|
|
325
|
+
className: cn(itemVariants({
|
|
326
|
+
active: selected,
|
|
327
|
+
className
|
|
328
|
+
})),
|
|
329
|
+
onClick: () => onValueChange(selected && allowClear ? void 0 : value),
|
|
330
|
+
tabIndex: -1,
|
|
331
|
+
...props,
|
|
332
|
+
children: props.children
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function useSearch() {
|
|
336
|
+
const ctx = use(RootContext);
|
|
337
|
+
if (!ctx) throw new Error("Missing <SearchDialog />");
|
|
338
|
+
return ctx;
|
|
339
|
+
}
|
|
340
|
+
function useTagsList() {
|
|
341
|
+
const ctx = use(TagsListContext);
|
|
342
|
+
if (!ctx) throw new Error("Missing <TagsList />");
|
|
343
|
+
return ctx;
|
|
344
|
+
}
|
|
345
|
+
function useSearchList() {
|
|
346
|
+
const ctx = use(ListContext);
|
|
347
|
+
if (!ctx) throw new Error("Missing <SearchDialogList />");
|
|
348
|
+
return ctx;
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
export { SearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogListItem, SearchDialogOverlay, TagsList, TagsListItem, useSearch, useSearchList, useTagsList };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CodeBlockProps } from "./codeblock.js";
|
|
2
|
+
import { UseShikiOptions } from "@vx-oss/docs-core/highlight/shiki/react";
|
|
3
|
+
import { HighlighterCore } from "shiki";
|
|
4
|
+
//#region src/components/dynamic-codeblock.core.d.ts
|
|
5
|
+
interface DynamicCodeblockProps {
|
|
6
|
+
highlighter: HighlighterCore | (() => HighlighterCore | PromiseLike<HighlighterCore>);
|
|
7
|
+
lang: string;
|
|
8
|
+
code: string;
|
|
9
|
+
/**
|
|
10
|
+
* Extra props for the underlying `<CodeBlock />` component.
|
|
11
|
+
*
|
|
12
|
+
* Ignored if you defined your own `pre` component in `options.components`.
|
|
13
|
+
*/
|
|
14
|
+
codeblock?: CodeBlockProps;
|
|
15
|
+
/**
|
|
16
|
+
* Wrap in React `<Suspense />` and provide a fallback.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue true
|
|
19
|
+
*/
|
|
20
|
+
wrapInSuspense?: boolean;
|
|
21
|
+
options: DistributiveOmit<UseShikiOptions, 'lang'>;
|
|
22
|
+
}
|
|
23
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
24
|
+
declare function DynamicCodeBlock({ lang, code, codeblock, options, wrapInSuspense, highlighter }: DynamicCodeblockProps): import("react").JSX.Element;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { DynamicCodeBlock, DynamicCodeblockProps };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../utils/cn.js";
|
|
3
|
+
import { CodeBlock, Pre } from "./codeblock.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { createContext, use, useId } from "react";
|
|
6
|
+
import { useShikiDynamic } from "@vx-oss/docs-core/highlight/shiki/react";
|
|
7
|
+
//#region src/components/dynamic-codeblock.core.tsx
|
|
8
|
+
const PropsContext = createContext(void 0);
|
|
9
|
+
function DefaultPre(props) {
|
|
10
|
+
const extraProps = use(PropsContext);
|
|
11
|
+
return /* @__PURE__ */ jsx(CodeBlock, {
|
|
12
|
+
...props,
|
|
13
|
+
...extraProps,
|
|
14
|
+
className: cn("my-0", props.className, extraProps?.className),
|
|
15
|
+
children: /* @__PURE__ */ jsx(Pre, { children: props.children })
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function DynamicCodeBlock({ lang, code, codeblock, options, wrapInSuspense = true, highlighter }) {
|
|
19
|
+
const id = useId();
|
|
20
|
+
const shikiOptions = {
|
|
21
|
+
lang,
|
|
22
|
+
defaultColor: false,
|
|
23
|
+
...options,
|
|
24
|
+
components: {
|
|
25
|
+
pre: DefaultPre,
|
|
26
|
+
...options?.components
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
let node = useShikiDynamic(highlighter, code, shikiOptions, [
|
|
30
|
+
id,
|
|
31
|
+
lang,
|
|
32
|
+
code
|
|
33
|
+
]);
|
|
34
|
+
if (wrapInSuspense) node ??= /* @__PURE__ */ jsx(Placeholder, {
|
|
35
|
+
code,
|
|
36
|
+
components: shikiOptions.components
|
|
37
|
+
});
|
|
38
|
+
return /* @__PURE__ */ jsx(PropsContext, {
|
|
39
|
+
value: codeblock,
|
|
40
|
+
children: node
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function Placeholder({ code, components = {} }) {
|
|
44
|
+
const { pre: Pre = "pre", code: Code = "code" } = components;
|
|
45
|
+
return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code.split("\n").map((line, i) => /* @__PURE__ */ jsx("span", {
|
|
46
|
+
className: "line",
|
|
47
|
+
children: line
|
|
48
|
+
}, i)) }) });
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { DynamicCodeBlock };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicCodeblockProps as DynamicCodeblockProps$1 } from "./dynamic-codeblock.core.js";
|
|
2
|
+
//#region src/components/dynamic-codeblock.d.ts
|
|
3
|
+
type DynamicCodeblockProps = Omit<DynamicCodeblockProps$1, 'highlighter' | 'options'> & {
|
|
4
|
+
options?: DynamicCodeblockProps$1['options'];
|
|
5
|
+
};
|
|
6
|
+
declare function DynamicCodeBlock(props: DynamicCodeblockProps): import("react").JSX.Element;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { DynamicCodeBlock, DynamicCodeblockProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { DynamicCodeBlock as DynamicCodeBlock$1 } from "./dynamic-codeblock.core.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { defaultShikiFactory } from "@vx-oss/docs-core/highlight/shiki/full";
|
|
5
|
+
//#region src/components/dynamic-codeblock.tsx
|
|
6
|
+
function DynamicCodeBlock(props) {
|
|
7
|
+
return /* @__PURE__ */ jsx(DynamicCodeBlock$1, {
|
|
8
|
+
highlighter: () => defaultShikiFactory.getOrInit(),
|
|
9
|
+
options: { themes: {
|
|
10
|
+
light: "github-light",
|
|
11
|
+
dark: "github-dark"
|
|
12
|
+
} },
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { DynamicCodeBlock };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
//#region src/components/files.d.ts
|
|
3
|
+
declare function Files({ className, ...props }: HTMLAttributes<HTMLDivElement>): React.ReactElement;
|
|
4
|
+
interface FileProps extends HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
name: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
interface FolderProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
name: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Open folder by default
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue false
|
|
15
|
+
*/
|
|
16
|
+
defaultOpen?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare function File({ name, icon, className, ...rest }: FileProps): React.ReactElement;
|
|
19
|
+
declare function Folder({ name, defaultOpen, ...props }: FolderProps): React.ReactElement;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { File, FileProps, Files, Folder, FolderProps };
|