opin-ui 0.0.1
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 +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/home.css +1 -0
- package/css/generated/notebook.css +1 -0
- package/css/generated/shared.css +1 -0
- package/css/lib/base.css +314 -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 +75 -0
- package/css/style.css +9 -0
- package/css/vitepress.css +65 -0
- package/dist/.translations/index.d.ts +49 -0
- package/dist/.translations/keys.js +49 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/components/accordion.d.ts +23 -0
- package/dist/components/accordion.js +68 -0
- package/dist/components/banner.d.ts +33 -0
- package/dist/components/banner.js +85 -0
- package/dist/components/callout.d.ts +41 -0
- package/dist/components/callout.js +53 -0
- package/dist/components/card.d.ts +19 -0
- package/dist/components/card.js +38 -0
- package/dist/components/codeblock.d.ts +61 -0
- package/dist/components/codeblock.js +173 -0
- package/dist/components/codeblock.rsc.d.ts +20 -0
- package/dist/components/codeblock.rsc.js +22 -0
- package/dist/components/dialog/search-algolia.d.ts +36 -0
- package/dist/components/dialog/search-algolia.js +64 -0
- package/dist/components/dialog/search-default.d.ts +36 -0
- package/dist/components/dialog/search-default.js +58 -0
- package/dist/components/dialog/search-orama.d.ts +43 -0
- package/dist/components/dialog/search-orama.js +69 -0
- package/dist/components/dialog/search.d.ts +112 -0
- package/dist/components/dialog/search.js +350 -0
- package/dist/components/dynamic-codeblock.core.d.ts +34 -0
- package/dist/components/dynamic-codeblock.core.js +51 -0
- package/dist/components/dynamic-codeblock.d.ts +9 -0
- package/dist/components/dynamic-codeblock.js +17 -0
- package/dist/components/files.d.ts +34 -0
- package/dist/components/files.js +40 -0
- package/dist/components/github-info.d.ts +35 -0
- package/dist/components/github-info.js +75 -0
- package/dist/components/heading.d.ts +13 -0
- package/dist/components/heading.js +38 -0
- package/dist/components/image-zoom.d.ts +23 -0
- package/dist/components/image-zoom.js +32 -0
- package/dist/components/image-zoom2.css +71 -0
- package/dist/components/inline-toc.d.ts +14 -0
- package/dist/components/inline-toc.js +28 -0
- package/dist/components/sidebar/base.d.ts +131 -0
- package/dist/components/sidebar/base.js +274 -0
- package/dist/components/sidebar/link-item.d.ts +22 -0
- package/dist/components/sidebar/link-item.js +38 -0
- package/dist/components/sidebar/page-tree.d.ts +28 -0
- package/dist/components/sidebar/page-tree.js +71 -0
- package/dist/components/sidebar/tabs/dropdown.d.ts +16 -0
- package/dist/components/sidebar/tabs/dropdown.js +71 -0
- package/dist/components/sidebar/tabs/index.d.ts +11 -0
- package/dist/components/sidebar/tabs/index.js +46 -0
- package/dist/components/steps.d.ts +15 -0
- package/dist/components/steps.js +16 -0
- package/dist/components/tabs.d.ts +49 -0
- package/dist/components/tabs.js +88 -0
- package/dist/components/toc/clerk.d.ts +20 -0
- package/dist/components/toc/clerk.js +226 -0
- package/dist/components/toc/default.d.ts +23 -0
- package/dist/components/toc/default.js +259 -0
- package/dist/components/toc/index.d.ts +19 -0
- package/dist/components/toc/index.js +45 -0
- package/dist/components/type-table.d.ts +43 -0
- package/dist/components/type-table.js +117 -0
- package/dist/components/ui/accordion.d.ts +30 -0
- package/dist/components/ui/accordion.js +42 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/button.js +20 -0
- package/dist/components/ui/collapsible.d.ts +15 -0
- package/dist/components/ui/collapsible.js +21 -0
- package/dist/components/ui/navigation-menu.d.ts +30 -0
- package/dist/components/ui/navigation-menu.js +41 -0
- package/dist/components/ui/popover.d.ts +15 -0
- package/dist/components/ui/popover.js +20 -0
- package/dist/components/ui/scroll-area.d.ts +22 -0
- package/dist/components/ui/scroll-area.js +34 -0
- package/dist/components/ui/tabs.d.ts +36 -0
- package/dist/components/ui/tabs.js +77 -0
- package/dist/contexts/i18n.d.ts +41 -0
- package/dist/contexts/i18n.js +37 -0
- package/dist/contexts/search.d.ts +73 -0
- package/dist/contexts/search.js +68 -0
- package/dist/contexts/tree.d.ts +20 -0
- package/dist/contexts/tree.js +38 -0
- package/dist/i18n.d.ts +16 -0
- package/dist/i18n.js +38 -0
- package/dist/layouts/docs/client.d.ts +34 -0
- package/dist/layouts/docs/client.js +92 -0
- package/dist/layouts/docs/index.d.ts +44 -0
- package/dist/layouts/docs/index.js +22 -0
- package/dist/layouts/docs/page/index.d.ts +115 -0
- package/dist/layouts/docs/page/index.js +124 -0
- package/dist/layouts/docs/page/slots/breadcrumb.d.ts +13 -0
- package/dist/layouts/docs/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/docs/page/slots/container.d.ts +6 -0
- package/dist/layouts/docs/page/slots/container.js +17 -0
- package/dist/layouts/docs/page/slots/footer.d.ts +22 -0
- package/dist/layouts/docs/page/slots/footer.js +56 -0
- package/dist/layouts/docs/page/slots/toc.d.ts +62 -0
- package/dist/layouts/docs/page/slots/toc.js +182 -0
- package/dist/layouts/docs/slots/container.d.ts +6 -0
- package/dist/layouts/docs/slots/container.js +36 -0
- package/dist/layouts/docs/slots/header.d.ts +6 -0
- package/dist/layouts/docs/slots/header.js +38 -0
- package/dist/layouts/docs/slots/sidebar.d.ts +29 -0
- package/dist/layouts/docs/slots/sidebar.js +326 -0
- package/dist/layouts/flux/index.d.ts +73 -0
- package/dist/layouts/flux/index.js +146 -0
- package/dist/layouts/flux/page/index.d.ts +102 -0
- package/dist/layouts/flux/page/index.js +104 -0
- package/dist/layouts/flux/page/slots/breadcrumb.d.ts +13 -0
- package/dist/layouts/flux/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/flux/page/slots/container.d.ts +6 -0
- package/dist/layouts/flux/page/slots/container.js +17 -0
- package/dist/layouts/flux/page/slots/footer.d.ts +22 -0
- package/dist/layouts/flux/page/slots/footer.js +56 -0
- package/dist/layouts/flux/page/slots/toc.d.ts +38 -0
- package/dist/layouts/flux/page/slots/toc.js +181 -0
- package/dist/layouts/flux/slots/container.d.ts +6 -0
- package/dist/layouts/flux/slots/container.js +13 -0
- package/dist/layouts/flux/slots/sidebar.d.ts +22 -0
- package/dist/layouts/flux/slots/sidebar.js +237 -0
- package/dist/layouts/flux/slots/tab-dropdown.d.ts +16 -0
- package/dist/layouts/flux/slots/tab-dropdown.js +85 -0
- package/dist/layouts/home/index.d.ts +28 -0
- package/dist/layouts/home/index.js +40 -0
- package/dist/layouts/home/navbar.d.ts +10 -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 +6 -0
- package/dist/layouts/home/slots/container.js +13 -0
- package/dist/layouts/home/slots/header.d.ts +9 -0
- package/dist/layouts/home/slots/header.js +239 -0
- package/dist/layouts/notebook/client.d.ts +36 -0
- package/dist/layouts/notebook/client.js +69 -0
- package/dist/layouts/notebook/index.d.ts +37 -0
- package/dist/layouts/notebook/index.js +22 -0
- package/dist/layouts/notebook/page/index.d.ts +115 -0
- package/dist/layouts/notebook/page/index.js +124 -0
- package/dist/layouts/notebook/page/slots/breadcrumb.d.ts +13 -0
- package/dist/layouts/notebook/page/slots/breadcrumb.js +44 -0
- package/dist/layouts/notebook/page/slots/container.d.ts +6 -0
- package/dist/layouts/notebook/page/slots/container.js +17 -0
- package/dist/layouts/notebook/page/slots/footer.d.ts +22 -0
- package/dist/layouts/notebook/page/slots/footer.js +56 -0
- package/dist/layouts/notebook/page/slots/toc.d.ts +62 -0
- package/dist/layouts/notebook/page/slots/toc.js +181 -0
- package/dist/layouts/notebook/slots/container.d.ts +6 -0
- package/dist/layouts/notebook/slots/container.js +38 -0
- package/dist/layouts/notebook/slots/header.d.ts +6 -0
- package/dist/layouts/notebook/slots/header.js +194 -0
- package/dist/layouts/notebook/slots/sidebar.d.ts +30 -0
- package/dist/layouts/notebook/slots/sidebar.js +298 -0
- package/dist/layouts/shared/client.d.ts +44 -0
- package/dist/layouts/shared/client.js +84 -0
- package/dist/layouts/shared/index.d.ts +178 -0
- package/dist/layouts/shared/index.js +98 -0
- package/dist/layouts/shared/page-actions.d.ts +35 -0
- package/dist/layouts/shared/page-actions.js +195 -0
- package/dist/layouts/shared/slots/language-select.d.ts +18 -0
- package/dist/layouts/shared/slots/language-select.js +43 -0
- package/dist/layouts/shared/slots/search-trigger.d.ts +22 -0
- package/dist/layouts/shared/slots/search-trigger.js +53 -0
- package/dist/layouts/shared/slots/theme-switch.d.ts +13 -0
- package/dist/layouts/shared/slots/theme-switch.js +65 -0
- package/dist/legacy/layout.d.ts +36 -0
- package/dist/legacy/layout.js +44 -0
- package/dist/legacy/sidebar.d.ts +17 -0
- package/dist/legacy/sidebar.js +33 -0
- package/dist/mdx.d.ts +45 -0
- package/dist/mdx.js +70 -0
- package/dist/mdx.server.d.ts +15 -0
- package/dist/mdx.server.js +20 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/controlled.d.ts +31 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/controlled.js +461 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/index.d.ts +2 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/uncontrolled.d.ts +7 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/uncontrolled.js +17 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/adjust-svg-ids.js +53 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/compute-positioned-style.js +25 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/element-tests.js +12 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-div-img-style.js +45 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-img-alt.js +8 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-img-object-fit-style.js +55 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-img-regular-style.js +21 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-img-src.js +14 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-modal-img-transform.js +22 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-scale.js +27 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-style-ghost.js +31 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-style-modal-img.js +75 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/get-target-dimension.js +4 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/parse-position.js +7 -0
- package/dist/node_modules/.bun/react-medium-image-zoom@5.4.8_7492c01c6988791b/node_modules/react-medium-image-zoom/dist/utils/test-has-scalable-src.js +5 -0
- package/dist/og/takumi.d.ts +21 -0
- package/dist/og/takumi.js +91 -0
- package/dist/og.d.ts +22 -0
- package/dist/og.js +91 -0
- package/dist/page.d.ts +35 -0
- package/dist/page.js +33 -0
- package/dist/provider/base.d.ts +49 -0
- package/dist/provider/base.js +32 -0
- package/dist/provider/next.d.ts +20 -0
- package/dist/provider/next.js +17 -0
- package/dist/provider/react-router.d.ts +20 -0
- package/dist/provider/react-router.js +17 -0
- package/dist/provider/tanstack.d.ts +20 -0
- package/dist/provider/tanstack.js +17 -0
- package/dist/provider/waku.d.ts +20 -0
- package/dist/provider/waku.js +17 -0
- package/dist/style.css +3534 -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 +6 -0
- package/dist/utils/use-copy-button.js +26 -0
- package/dist/utils/use-footer-items.d.ts +9 -0
- package/dist/utils/use-footer-items.js +24 -0
- package/dist/utils/use-is-scroll-top.d.ts +8 -0
- package/dist/utils/use-is-scroll-top.js +20 -0
- package/package.json +200 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { buttonVariants } from "../ui/button.js";
|
|
4
|
+
import { useRouter } from "fumadocs-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 "fumadocs-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 "fumadocs-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: "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 gap-0.5 p-0.5 rounded-md bg-fd-card text-fd-card-foreground",
|
|
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",
|
|
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 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
|
+
return /* @__PURE__ */ jsx("button", {
|
|
156
|
+
type: "button",
|
|
157
|
+
"aria-label": useTranslations({ note: "search dialog" })("Close Search", { note: "aria-label" }),
|
|
158
|
+
onClick: () => onOpenChange(false),
|
|
159
|
+
className: cn(buttonVariants({
|
|
160
|
+
color: "outline",
|
|
161
|
+
size: "sm",
|
|
162
|
+
className: "font-mono text-fd-muted-foreground"
|
|
163
|
+
}), className),
|
|
164
|
+
...props,
|
|
165
|
+
children
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function SearchDialogFooter(props) {
|
|
169
|
+
return /* @__PURE__ */ jsx("div", {
|
|
170
|
+
...props,
|
|
171
|
+
className: cn("bg-fd-secondary/50 p-3 empty:hidden", props.className)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function SearchDialogOverlay(props) {
|
|
175
|
+
return /* @__PURE__ */ jsx(DialogOverlay, {
|
|
176
|
+
...props,
|
|
177
|
+
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)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function SearchDialogContent({ children, ...props }) {
|
|
181
|
+
const t = useTranslations({ note: "search dialog" });
|
|
182
|
+
return /* @__PURE__ */ jsxs(DialogContent, {
|
|
183
|
+
"aria-describedby": void 0,
|
|
184
|
+
...props,
|
|
185
|
+
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-3xl bg-fd-popover overflow-hidden text-fd-popover-foreground data-[state=closed]:animate-fd-dialog-out data-[state=open]:animate-fd-dialog-in", "*:flex *:flex-col *:gap-0.5!", props.className),
|
|
186
|
+
children: [/* @__PURE__ */ jsx(DialogTitle, {
|
|
187
|
+
className: "hidden",
|
|
188
|
+
children: t("Search")
|
|
189
|
+
}), children]
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function SearchDialogList({ items = null, Empty = () => /* @__PURE__ */ jsx("div", {
|
|
193
|
+
className: "py-12 text-center text-sm text-fd-muted-foreground",
|
|
194
|
+
children: /* @__PURE__ */ jsx(T, {
|
|
195
|
+
text: "No results found",
|
|
196
|
+
note: "search dialog"
|
|
197
|
+
})
|
|
198
|
+
}), Item = (props) => /* @__PURE__ */ jsx(SearchDialogListItem, { ...props }), ...props }) {
|
|
199
|
+
const ref = useRef(null);
|
|
200
|
+
const { onSelect } = useSearch();
|
|
201
|
+
const [active, setActive] = useState(() => items && items.length > 0 ? items[0].id : null);
|
|
202
|
+
const onKey = useEffectEvent((e) => {
|
|
203
|
+
if (!items || e.isComposing) return;
|
|
204
|
+
if (e.key === "ArrowDown" || e.key == "ArrowUp") {
|
|
205
|
+
let idx = items.findIndex((item) => item.id === active);
|
|
206
|
+
if (idx === -1) idx = 0;
|
|
207
|
+
else if (e.key === "ArrowDown") idx++;
|
|
208
|
+
else idx--;
|
|
209
|
+
setActive(items.at(idx % items.length)?.id ?? null);
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
}
|
|
212
|
+
if (e.key === "Enter") {
|
|
213
|
+
const selected = items.find((item) => item.id === active);
|
|
214
|
+
if (selected) onSelect(selected);
|
|
215
|
+
e.preventDefault();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
const element = ref.current;
|
|
220
|
+
if (!element) return;
|
|
221
|
+
const observer = new ResizeObserver(() => {
|
|
222
|
+
const viewport = element.firstElementChild;
|
|
223
|
+
element.style.setProperty("--fd-animated-height", `${viewport.clientHeight}px`);
|
|
224
|
+
});
|
|
225
|
+
const viewport = element.firstElementChild;
|
|
226
|
+
if (viewport) observer.observe(viewport);
|
|
227
|
+
window.addEventListener("keydown", onKey);
|
|
228
|
+
return () => {
|
|
229
|
+
observer.disconnect();
|
|
230
|
+
window.removeEventListener("keydown", onKey);
|
|
231
|
+
};
|
|
232
|
+
}, []);
|
|
233
|
+
useOnChange(items, () => {
|
|
234
|
+
if (items && items.length > 0) setActive(items[0].id);
|
|
235
|
+
});
|
|
236
|
+
return /* @__PURE__ */ jsx("div", {
|
|
237
|
+
...props,
|
|
238
|
+
ref,
|
|
239
|
+
"data-empty": items === null,
|
|
240
|
+
className: cn("overflow-hidden h-(--fd-animated-height) transition-[height]", props.className),
|
|
241
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
242
|
+
className: cn("w-full flex flex-col overflow-y-auto max-h-[460px] p-1", !items && "hidden"),
|
|
243
|
+
children: /* @__PURE__ */ jsxs(ListContext, {
|
|
244
|
+
value: useMemo(() => ({
|
|
245
|
+
active,
|
|
246
|
+
setActive
|
|
247
|
+
}), [active]),
|
|
248
|
+
children: [items?.length === 0 && Empty(), items?.map((item) => /* @__PURE__ */ jsx(Fragment$1, { children: Item({
|
|
249
|
+
item,
|
|
250
|
+
onClick: () => onSelect(item)
|
|
251
|
+
}) }, item.id))]
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function SearchDialogListItem({ item, className, children, renderMarkdown = (s) => /* @__PURE__ */ jsx(mdRenderer.Markdown, {
|
|
257
|
+
components: mdComponents,
|
|
258
|
+
children: s
|
|
259
|
+
}), renderHighlights: _, ...props }) {
|
|
260
|
+
const { active: activeId, setActive } = useSearchList();
|
|
261
|
+
const active = item.id === activeId;
|
|
262
|
+
if (item.type === "action") children ??= item.node;
|
|
263
|
+
else children ??= /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
264
|
+
/* @__PURE__ */ jsx("div", {
|
|
265
|
+
className: "inline-flex items-center text-fd-muted-foreground text-xs empty:hidden",
|
|
266
|
+
children: item.breadcrumbs?.map((item, i) => /* @__PURE__ */ jsxs(Fragment$1, { children: [i > 0 && /* @__PURE__ */ jsx(ChevronRight, { className: "size-4 rtl:rotate-180" }), item] }, i))
|
|
267
|
+
}),
|
|
268
|
+
item.type !== "page" && /* @__PURE__ */ jsx("div", {
|
|
269
|
+
role: "none",
|
|
270
|
+
className: "absolute inset-s-3 inset-y-0 w-px bg-fd-border"
|
|
271
|
+
}),
|
|
272
|
+
item.type === "heading" && /* @__PURE__ */ jsx(Hash, { className: "absolute inset-s-6 top-2.5 size-4 text-fd-muted-foreground" }),
|
|
273
|
+
/* @__PURE__ */ jsx("div", {
|
|
274
|
+
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"),
|
|
275
|
+
children: typeof item.content === "string" ? renderMarkdown(item.content) : item.content
|
|
276
|
+
})
|
|
277
|
+
] });
|
|
278
|
+
return /* @__PURE__ */ jsx("button", {
|
|
279
|
+
type: "button",
|
|
280
|
+
ref: useCallback((element) => {
|
|
281
|
+
if (active && element) scrollIntoView(element, {
|
|
282
|
+
scrollMode: "if-needed",
|
|
283
|
+
block: "nearest",
|
|
284
|
+
boundary: element.parentElement
|
|
285
|
+
});
|
|
286
|
+
}, [active]),
|
|
287
|
+
"aria-selected": active,
|
|
288
|
+
className: cn("relative select-none shrink-0 px-2.5 py-2 text-start text-sm overflow-hidden rounded-2xl", active && "bg-fd-accent text-fd-accent-foreground", className),
|
|
289
|
+
onPointerMove: () => setActive(item.id),
|
|
290
|
+
...props,
|
|
291
|
+
children
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function SearchDialogIcon(props) {
|
|
295
|
+
const { isLoading } = useSearch();
|
|
296
|
+
return /* @__PURE__ */ jsx(SearchIcon, {
|
|
297
|
+
...props,
|
|
298
|
+
className: cn("size-5 text-fd-muted-foreground", isLoading && "animate-pulse duration-400", props.className)
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
const itemVariants = cva("rounded-md bg-fd-secondary 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" } } });
|
|
302
|
+
function TagsList({ tag, onTagChange, allowClear = false, ...props }) {
|
|
303
|
+
const onTagChangeCallback = useRef(onTagChange);
|
|
304
|
+
onTagChangeCallback.current = onTagChange;
|
|
305
|
+
return /* @__PURE__ */ jsx("div", {
|
|
306
|
+
...props,
|
|
307
|
+
className: cn("flex items-center gap-1 flex-wrap", props.className),
|
|
308
|
+
children: /* @__PURE__ */ jsx(TagsListContext, {
|
|
309
|
+
value: useMemo(() => ({
|
|
310
|
+
value: tag,
|
|
311
|
+
onValueChange: (v) => onTagChangeCallback.current(v),
|
|
312
|
+
allowClear
|
|
313
|
+
}), [allowClear, tag]),
|
|
314
|
+
children: props.children
|
|
315
|
+
})
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
function TagsListItem({ value, className, ...props }) {
|
|
319
|
+
const { onValueChange, value: selectedValue, allowClear } = useTagsList();
|
|
320
|
+
const selected = value === selectedValue;
|
|
321
|
+
return /* @__PURE__ */ jsx("button", {
|
|
322
|
+
type: "button",
|
|
323
|
+
"data-active": selected,
|
|
324
|
+
className: cn(itemVariants({
|
|
325
|
+
active: selected,
|
|
326
|
+
className
|
|
327
|
+
})),
|
|
328
|
+
onClick: () => onValueChange(selected && allowClear ? void 0 : value),
|
|
329
|
+
tabIndex: -1,
|
|
330
|
+
...props,
|
|
331
|
+
children: props.children
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
function useSearch() {
|
|
335
|
+
const ctx = use(RootContext);
|
|
336
|
+
if (!ctx) throw new Error("Missing <SearchDialog />");
|
|
337
|
+
return ctx;
|
|
338
|
+
}
|
|
339
|
+
function useTagsList() {
|
|
340
|
+
const ctx = use(TagsListContext);
|
|
341
|
+
if (!ctx) throw new Error("Missing <TagsList />");
|
|
342
|
+
return ctx;
|
|
343
|
+
}
|
|
344
|
+
function useSearchList() {
|
|
345
|
+
const ctx = use(ListContext);
|
|
346
|
+
if (!ctx) throw new Error("Missing <SearchDialogList />");
|
|
347
|
+
return ctx;
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
export { SearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogListItem, SearchDialogOverlay, TagsList, TagsListItem, useSearch, useSearchList, useTagsList };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CodeBlockProps } from "./codeblock.js";
|
|
2
|
+
import { UseShikiOptions } from "fumadocs-core/highlight/shiki/react";
|
|
3
|
+
import { HighlighterCore } from "shiki";
|
|
4
|
+
|
|
5
|
+
//#region src/components/dynamic-codeblock.core.d.ts
|
|
6
|
+
interface DynamicCodeblockProps {
|
|
7
|
+
highlighter: HighlighterCore | (() => HighlighterCore | PromiseLike<HighlighterCore>);
|
|
8
|
+
lang: string;
|
|
9
|
+
code: string;
|
|
10
|
+
/**
|
|
11
|
+
* Extra props for the underlying `<CodeBlock />` component.
|
|
12
|
+
*
|
|
13
|
+
* Ignored if you defined your own `pre` component in `options.components`.
|
|
14
|
+
*/
|
|
15
|
+
codeblock?: CodeBlockProps;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap in React `<Suspense />` and provide a fallback.
|
|
18
|
+
*
|
|
19
|
+
* @defaultValue true
|
|
20
|
+
*/
|
|
21
|
+
wrapInSuspense?: boolean;
|
|
22
|
+
options: DistributiveOmit<UseShikiOptions, 'lang'>;
|
|
23
|
+
}
|
|
24
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
25
|
+
declare function DynamicCodeBlock({
|
|
26
|
+
lang,
|
|
27
|
+
code,
|
|
28
|
+
codeblock,
|
|
29
|
+
options,
|
|
30
|
+
wrapInSuspense,
|
|
31
|
+
highlighter
|
|
32
|
+
}: DynamicCodeblockProps): import("react").JSX.Element;
|
|
33
|
+
//#endregion
|
|
34
|
+
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 "fumadocs-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,9 @@
|
|
|
1
|
+
import { DynamicCodeblockProps as DynamicCodeblockProps$1 } from "./dynamic-codeblock.core.js";
|
|
2
|
+
|
|
3
|
+
//#region src/components/dynamic-codeblock.d.ts
|
|
4
|
+
type DynamicCodeblockProps = Omit<DynamicCodeblockProps$1, 'highlighter' | 'options'> & {
|
|
5
|
+
options?: DynamicCodeblockProps$1['options'];
|
|
6
|
+
};
|
|
7
|
+
declare function DynamicCodeBlock(props: DynamicCodeblockProps): import("react").JSX.Element;
|
|
8
|
+
//#endregion
|
|
9
|
+
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 "fumadocs-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,34 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/components/files.d.ts
|
|
4
|
+
declare function Files({
|
|
5
|
+
className,
|
|
6
|
+
...props
|
|
7
|
+
}: HTMLAttributes<HTMLDivElement>): React.ReactElement;
|
|
8
|
+
interface FileProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
name: string;
|
|
10
|
+
icon?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
interface FolderProps extends HTMLAttributes<HTMLDivElement> {
|
|
13
|
+
name: string;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Open folder by default
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue false
|
|
19
|
+
*/
|
|
20
|
+
defaultOpen?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare function File({
|
|
23
|
+
name,
|
|
24
|
+
icon,
|
|
25
|
+
className,
|
|
26
|
+
...rest
|
|
27
|
+
}: FileProps): React.ReactElement;
|
|
28
|
+
declare function Folder({
|
|
29
|
+
name,
|
|
30
|
+
defaultOpen,
|
|
31
|
+
...props
|
|
32
|
+
}: FolderProps): React.ReactElement;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { File, FileProps, Files, Folder, FolderProps };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "../utils/cn.js";
|
|
3
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible.js";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { FileIcon, FolderIcon, FolderOpen } from "lucide-react";
|
|
6
|
+
import { cva } from "class-variance-authority";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
//#region src/components/files.tsx
|
|
9
|
+
const itemVariants = cva("flex flex-row items-center gap-2 rounded-2xl px-2 py-1.5 text-sm hover:bg-fd-accent hover:text-fd-accent-foreground [&_svg]:size-4");
|
|
10
|
+
function Files({ className, ...props }) {
|
|
11
|
+
return /* @__PURE__ */ jsx("div", {
|
|
12
|
+
className: cn("not-prose rounded-3xl bg-fd-card p-2", className),
|
|
13
|
+
...props,
|
|
14
|
+
children: props.children
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function File({ name, icon = /* @__PURE__ */ jsx(FileIcon, {}), className, ...rest }) {
|
|
18
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
19
|
+
className: cn(itemVariants({ className })),
|
|
20
|
+
...rest,
|
|
21
|
+
children: [icon, name]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function Folder({ name, defaultOpen = false, ...props }) {
|
|
25
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
26
|
+
return /* @__PURE__ */ jsxs(Collapsible, {
|
|
27
|
+
open,
|
|
28
|
+
onOpenChange: setOpen,
|
|
29
|
+
...props,
|
|
30
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
31
|
+
className: cn(itemVariants({ className: "w-full" })),
|
|
32
|
+
children: [open ? /* @__PURE__ */ jsx(FolderOpen, {}) : /* @__PURE__ */ jsx(FolderIcon, {}), name]
|
|
33
|
+
}), /* @__PURE__ */ jsx(CollapsibleContent, { children: /* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: "ms-2 flex flex-col ps-3",
|
|
35
|
+
children: props.children
|
|
36
|
+
}) })]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { File, Files, Folder };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/components/github-info.d.ts
|
|
4
|
+
interface FetchRepositoryInfoOptions {
|
|
5
|
+
owner: string;
|
|
6
|
+
repo: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
fetchOptions?: RequestInit;
|
|
10
|
+
}
|
|
11
|
+
interface RepositoryInfo {
|
|
12
|
+
stars: number;
|
|
13
|
+
forks: number;
|
|
14
|
+
}
|
|
15
|
+
interface GithubInfoProps extends ComponentProps<'a'>, FetchRepositoryInfoOptions {
|
|
16
|
+
locale?: Intl.LocalesArgument;
|
|
17
|
+
}
|
|
18
|
+
declare function fetchRepositoryInfo({
|
|
19
|
+
owner,
|
|
20
|
+
repo,
|
|
21
|
+
token,
|
|
22
|
+
baseUrl,
|
|
23
|
+
fetchOptions
|
|
24
|
+
}: FetchRepositoryInfoOptions): Promise<RepositoryInfo>;
|
|
25
|
+
declare function GithubInfo({
|
|
26
|
+
repo,
|
|
27
|
+
owner,
|
|
28
|
+
token,
|
|
29
|
+
baseUrl,
|
|
30
|
+
fetchOptions,
|
|
31
|
+
locale,
|
|
32
|
+
...props
|
|
33
|
+
}: GithubInfoProps): import("react").JSX.Element;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { FetchRepositoryInfoOptions, GithubInfo, GithubInfoProps, RepositoryInfo, fetchRepositoryInfo };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { cn } from "../utils/cn.js";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { GitFork, Star } from "lucide-react";
|
|
4
|
+
import { use } from "react";
|
|
5
|
+
//#region src/components/github-info.tsx
|
|
6
|
+
async function fetchRepositoryInfo({ owner, repo, token, baseUrl = "https://api.github.com", fetchOptions = { next: { revalidate: 60 } } }) {
|
|
7
|
+
const endpoint = `${baseUrl}/repos/${owner}/${repo}`;
|
|
8
|
+
const headers = new Headers(fetchOptions.headers);
|
|
9
|
+
headers.set("Content-Type", "application/json");
|
|
10
|
+
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
11
|
+
const response = await fetch(endpoint, {
|
|
12
|
+
...fetchOptions,
|
|
13
|
+
headers
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
const message = await response.text();
|
|
17
|
+
throw new Error(`Failed to fetch repository data: ${message}`);
|
|
18
|
+
}
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
return {
|
|
21
|
+
stars: data.stargazers_count,
|
|
22
|
+
forks: data.forks_count
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Uses compact notation (e.g., 1.5K, 2.3M).
|
|
27
|
+
*/
|
|
28
|
+
const formatterOptions = {
|
|
29
|
+
notation: "compact",
|
|
30
|
+
maximumFractionDigits: 1
|
|
31
|
+
};
|
|
32
|
+
const defaultFormatter = new Intl.NumberFormat(void 0, formatterOptions);
|
|
33
|
+
const promises = {};
|
|
34
|
+
function GithubInfo({ repo, owner, token, baseUrl, fetchOptions, locale, ...props }) {
|
|
35
|
+
const options = {
|
|
36
|
+
repo,
|
|
37
|
+
owner,
|
|
38
|
+
token,
|
|
39
|
+
baseUrl,
|
|
40
|
+
fetchOptions
|
|
41
|
+
};
|
|
42
|
+
const { stars, forks } = use(promises[JSON.stringify(options)] ??= fetchRepositoryInfo(options));
|
|
43
|
+
const formatter = locale ? new Intl.NumberFormat(locale, formatterOptions) : defaultFormatter;
|
|
44
|
+
return /* @__PURE__ */ jsxs("a", {
|
|
45
|
+
href: `https://github.com/${owner}/${repo}`,
|
|
46
|
+
rel: "noreferrer noopener",
|
|
47
|
+
target: "_blank",
|
|
48
|
+
...props,
|
|
49
|
+
className: cn("flex flex-col gap-1.5 p-2 rounded-lg text-sm text-fd-foreground/80 transition-colors hover:text-fd-accent-foreground hover:bg-fd-accent", props.className),
|
|
50
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
51
|
+
className: "flex items-center gap-2 truncate",
|
|
52
|
+
children: [
|
|
53
|
+
/* @__PURE__ */ jsxs("svg", {
|
|
54
|
+
fill: "currentColor",
|
|
55
|
+
viewBox: "0 0 24 24",
|
|
56
|
+
className: "size-3.5",
|
|
57
|
+
children: [/* @__PURE__ */ jsx("title", { children: "GitHub" }), /* @__PURE__ */ jsx("path", { d: "M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" })]
|
|
58
|
+
}),
|
|
59
|
+
owner,
|
|
60
|
+
"/",
|
|
61
|
+
repo
|
|
62
|
+
]
|
|
63
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
64
|
+
className: "flex text-xs items-center gap-1 text-fd-muted-foreground",
|
|
65
|
+
children: [
|
|
66
|
+
/* @__PURE__ */ jsx(Star, { className: "size-3" }),
|
|
67
|
+
/* @__PURE__ */ jsx("span", { children: formatter.format(stars) }),
|
|
68
|
+
/* @__PURE__ */ jsx(GitFork, { className: "size-3 ms-2" }),
|
|
69
|
+
/* @__PURE__ */ jsx("span", { children: formatter.format(forks) })
|
|
70
|
+
]
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { GithubInfo, fetchRepositoryInfo };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/components/heading.d.ts
|
|
4
|
+
type Types = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
5
|
+
type HeadingProps<T extends Types> = Omit<ComponentPropsWithoutRef<T>, 'as'> & {
|
|
6
|
+
as?: T;
|
|
7
|
+
};
|
|
8
|
+
declare function Heading<T extends Types = 'h1'>({
|
|
9
|
+
as,
|
|
10
|
+
...props
|
|
11
|
+
}: HeadingProps<T>): import("react").JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { Heading };
|