fumadocs-ui 14.2.1 → 14.3.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/dist/components/accordion.d.ts +4 -7
- package/dist/components/accordion.d.ts.map +1 -0
- package/dist/components/accordion.js +32 -104
- package/dist/components/api.d.ts +4 -13
- package/dist/components/api.d.ts.map +1 -0
- package/dist/components/api.js +3 -16
- package/dist/components/banner.d.ts +3 -5
- package/dist/components/banner.d.ts.map +1 -0
- package/dist/components/banner.js +53 -120
- package/dist/components/callout.d.ts +4 -7
- package/dist/components/callout.d.ts.map +1 -0
- package/dist/components/callout.js +13 -9
- package/dist/components/card.d.ts +5 -7
- package/dist/components/card.d.ts.map +1 -0
- package/dist/components/card.js +10 -10
- package/dist/components/codeblock.d.ts +6 -9
- package/dist/components/codeblock.d.ts.map +1 -0
- package/dist/components/codeblock.js +41 -15
- package/dist/components/dialog/search-algolia.d.ts +7 -11
- package/dist/components/dialog/search-algolia.d.ts.map +1 -0
- package/dist/components/dialog/search-algolia.js +19 -79
- package/dist/components/dialog/search-default.d.ts +6 -10
- package/dist/components/dialog/search-default.d.ts.map +1 -0
- package/dist/components/dialog/search-default.js +24 -73
- package/dist/components/dialog/search-orama.d.ts +7 -11
- package/dist/components/dialog/search-orama.d.ts.map +1 -0
- package/dist/components/dialog/search-orama.js +22 -79
- package/dist/components/dialog/search.d.ts +7 -9
- package/dist/components/dialog/search.d.ts.map +1 -0
- package/dist/components/dialog/search.js +98 -13
- package/dist/components/dialog/tag-list.d.ts +13 -0
- package/dist/components/dialog/tag-list.d.ts.map +1 -0
- package/dist/components/dialog/tag-list.js +20 -0
- package/dist/components/files.d.ts +7 -9
- package/dist/components/files.d.ts.map +1 -0
- package/dist/components/files.js +15 -63
- package/dist/components/heading.d.ts +4 -5
- package/dist/components/heading.d.ts.map +1 -0
- package/dist/components/heading.js +9 -9
- package/dist/components/image-zoom.d.ts +7 -8
- package/dist/components/image-zoom.d.ts.map +1 -0
- package/dist/components/image-zoom.js +16 -40
- package/dist/components/inline-toc.d.ts +4 -6
- package/dist/components/inline-toc.d.ts.map +1 -0
- package/dist/components/inline-toc.js +8 -46
- package/dist/components/layout/breadcrumb.d.ts +11 -0
- package/dist/components/layout/breadcrumb.d.ts.map +1 -0
- package/dist/components/layout/breadcrumb.js +20 -0
- package/dist/components/layout/language-toggle.d.ts +5 -7
- package/dist/components/layout/language-toggle.d.ts.map +1 -0
- package/dist/components/layout/language-toggle.js +24 -14
- package/dist/components/layout/nav.d.ts +28 -0
- package/dist/components/layout/nav.d.ts.map +1 -0
- package/dist/components/layout/nav.js +29 -0
- package/dist/components/layout/root-toggle.d.ts +5 -7
- package/dist/components/layout/root-toggle.d.ts.map +1 -0
- package/dist/components/layout/root-toggle.js +28 -13
- package/dist/components/layout/search-toggle.d.ts +4 -0
- package/dist/components/layout/search-toggle.d.ts.map +1 -0
- package/dist/components/layout/search-toggle.js +24 -0
- package/dist/components/layout/theme-toggle.d.ts +3 -0
- package/dist/components/layout/theme-toggle.d.ts.map +1 -0
- package/dist/components/layout/theme-toggle.js +21 -0
- package/dist/components/layout/toc-clerk.d.ts +6 -0
- package/dist/components/layout/toc-clerk.d.ts.map +1 -0
- package/dist/components/layout/toc-clerk.js +76 -0
- package/dist/components/layout/toc-popover.d.ts +8 -0
- package/dist/components/layout/toc-popover.d.ts.map +1 -0
- package/dist/components/layout/toc-popover.js +20 -0
- package/dist/components/layout/toc-thumb.d.ts +6 -0
- package/dist/components/layout/toc-thumb.d.ts.map +1 -0
- package/dist/components/layout/toc-thumb.js +53 -0
- package/dist/components/layout/toc.d.ts +19 -0
- package/dist/components/layout/toc.d.ts.map +1 -0
- package/dist/components/layout/toc.js +25 -0
- package/dist/components/registry.d.ts +3 -0
- package/dist/components/registry.d.ts.map +1 -0
- package/dist/components/registry.js +70 -0
- package/dist/components/steps.d.ts +4 -6
- package/dist/components/steps.d.ts.map +1 -0
- package/dist/components/steps.js +5 -16
- package/dist/components/tabs.d.ts +7 -21
- package/dist/components/tabs.d.ts.map +1 -0
- package/dist/components/tabs.js +61 -171
- package/dist/components/type-table.d.ts +5 -6
- package/dist/components/type-table.d.ts.map +1 -0
- package/dist/components/type-table.js +18 -59
- package/dist/components/ui/button.d.ts +5 -0
- package/dist/components/ui/button.d.ts.map +1 -0
- package/dist/components/ui/button.js +14 -0
- package/dist/components/ui/collapsible.d.ts +6 -0
- package/dist/components/ui/collapsible.d.ts.map +1 -0
- package/dist/components/ui/collapsible.js +12 -0
- package/dist/components/ui/navigation-menu.d.ts +11 -0
- package/dist/components/ui/navigation-menu.d.ts.map +1 -0
- package/dist/components/ui/navigation-menu.js +15 -0
- package/dist/components/ui/popover.d.ts +8 -0
- package/dist/components/ui/popover.d.ts.map +1 -0
- package/dist/components/ui/popover.js +11 -0
- package/dist/components/ui/scroll-area.d.ts +7 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -0
- package/dist/components/ui/scroll-area.js +11 -0
- package/dist/components/ui/tabs.d.ts +8 -0
- package/dist/components/ui/tabs.d.ts.map +1 -0
- package/dist/components/ui/tabs.js +16 -0
- package/dist/{i18n-Db2HAPOu.d.ts → contexts/i18n.d.ts} +9 -5
- package/dist/contexts/i18n.d.ts.map +1 -0
- package/dist/contexts/i18n.js +23 -0
- package/dist/contexts/search.d.ts +50 -0
- package/dist/contexts/search.d.ts.map +1 -0
- package/dist/contexts/search.js +50 -0
- package/dist/contexts/sidebar.d.ts +18 -0
- package/dist/contexts/sidebar.d.ts.map +1 -0
- package/dist/contexts/sidebar.js +31 -0
- package/dist/contexts/tree.d.ts +13 -0
- package/dist/contexts/tree.d.ts.map +1 -0
- package/dist/contexts/tree.js +25 -0
- package/dist/i18n.d.ts +5 -6
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +31 -49
- package/dist/layouts/docs/navbar.d.ts +4 -0
- package/dist/layouts/docs/navbar.d.ts.map +1 -0
- package/dist/layouts/docs/navbar.js +22 -0
- package/dist/layouts/docs/sidebar.d.ts +40 -0
- package/dist/layouts/docs/sidebar.d.ts.map +1 -0
- package/dist/layouts/docs/sidebar.js +146 -0
- package/dist/layouts/docs.client.d.ts +14 -25
- package/dist/layouts/docs.client.d.ts.map +1 -0
- package/dist/layouts/docs.client.js +53 -195
- package/dist/layouts/docs.d.ts +34 -19
- package/dist/layouts/docs.d.ts.map +1 -0
- package/dist/layouts/docs.js +67 -202
- package/dist/layouts/home/menu.d.ts +6 -0
- package/dist/layouts/home/menu.d.ts.map +1 -0
- package/dist/layouts/home/menu.js +33 -0
- package/dist/layouts/home/navbar.d.ts +16 -0
- package/dist/layouts/home/navbar.d.ts.map +1 -0
- package/dist/layouts/home/navbar.js +48 -0
- package/dist/layouts/home.d.ts +5 -7
- package/dist/layouts/home.d.ts.map +1 -0
- package/dist/layouts/home.js +51 -59
- package/dist/layouts/links.d.ts +80 -0
- package/dist/layouts/links.d.ts.map +1 -0
- package/dist/layouts/links.js +14 -0
- package/dist/layouts/shared.d.ts +48 -2
- package/dist/layouts/shared.d.ts.map +1 -0
- package/dist/layouts/shared.js +27 -9
- package/dist/mdx.client.d.ts +3 -6
- package/dist/mdx.client.d.ts.map +1 -0
- package/dist/mdx.client.js +12 -19
- package/dist/mdx.d.ts +18 -20
- package/dist/mdx.d.ts.map +1 -0
- package/dist/mdx.js +47 -56
- package/dist/og.d.ts +6 -7
- package/dist/og.d.ts.map +1 -0
- package/dist/og.js +43 -102
- package/dist/page.client.d.ts +8 -41
- package/dist/page.client.d.ts.map +1 -0
- package/dist/page.client.js +71 -261
- package/dist/page.d.ts +28 -30
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +80 -168
- package/dist/provider.d.ts +12 -72
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +19 -55
- package/dist/style.css +1 -1
- package/dist/tailwind-plugin.d.ts +9 -20
- package/dist/tailwind-plugin.d.ts.map +1 -0
- package/dist/tailwind-plugin.js +191 -699
- package/dist/theme/animations.d.ts +170 -0
- package/dist/theme/animations.d.ts.map +1 -0
- package/dist/theme/animations.js +95 -0
- package/dist/theme/colors.d.ts +11 -0
- package/dist/theme/colors.d.ts.map +1 -0
- package/dist/theme/colors.js +327 -0
- package/dist/theme/typography.d.ts +70 -0
- package/dist/theme/typography.d.ts.map +1 -0
- package/dist/theme/typography.js +71 -0
- package/dist/utils/cn.d.ts +2 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/cn.js +1 -0
- package/dist/utils/get-sidebar-tabs.d.ts +7 -0
- package/dist/utils/get-sidebar-tabs.d.ts.map +1 -0
- package/dist/utils/get-sidebar-tabs.js +20 -0
- package/dist/utils/is-active.d.ts +2 -0
- package/dist/utils/is-active.d.ts.map +1 -0
- package/dist/utils/is-active.js +3 -0
- package/dist/utils/use-copy-button.d.ts +3 -0
- package/dist/utils/use-copy-button.d.ts.map +1 -0
- package/dist/utils/use-copy-button.js +25 -0
- package/package.json +9 -9
- package/dist/chunk-27HFSL7N.js +0 -53
- package/dist/chunk-2FLZOPQN.js +0 -54
- package/dist/chunk-2KMKNVSN.js +0 -29
- package/dist/chunk-AFMXKA2S.js +0 -125
- package/dist/chunk-CDPVENXR.js +0 -8
- package/dist/chunk-CLF6ZVYS.js +0 -259
- package/dist/chunk-DGKCMOIC.js +0 -56
- package/dist/chunk-DN6Z5VW6.js +0 -61
- package/dist/chunk-E3VO2QQT.js +0 -29
- package/dist/chunk-EFMHXXHW.js +0 -24
- package/dist/chunk-F534DZID.js +0 -43
- package/dist/chunk-GHOAONNQ.js +0 -48
- package/dist/chunk-IL64LMKR.js +0 -82
- package/dist/chunk-ILBYBJ5C.js +0 -38
- package/dist/chunk-IVBHRX3O.js +0 -31
- package/dist/chunk-J6XGK6ZG.js +0 -212
- package/dist/chunk-KZTWSBYY.js +0 -68
- package/dist/chunk-MCX7E6ZW.js +0 -57
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-QKOA6KEZ.js +0 -22
- package/dist/chunk-TK3TM3MR.js +0 -6
- package/dist/chunk-TQJ6YPJ3.js +0 -31
- package/dist/chunk-UUGCW3UP.js +0 -84
- package/dist/chunk-VPJMNIJX.js +0 -542
- package/dist/chunk-W36BQGMB.js +0 -69
- package/dist/chunk-YL3MZH7N.js +0 -66
- package/dist/chunk-ZBOI25UW.js +0 -139
- package/dist/components/api.client.d.ts +0 -5
- package/dist/components/api.client.js +0 -8
- package/dist/dynamic-sidebar-SYEETGZL.js +0 -129
- package/dist/edit-on-github-FIYOWWPQ.js +0 -49
- package/dist/layouts/home.client.d.ts +0 -11
- package/dist/layouts/home.client.js +0 -274
- package/dist/shared-SScCiV7b.d.ts +0 -152
- package/dist/sidebar-CQ4HmzQl.d.ts +0 -50
- package/dist/tag-list-BsEgfE3x.d.ts +0 -6
- package/dist/toc-clerk-SKE4LBT7.js +0 -158
- package/dist/tree-06ley65N.d.ts +0 -21
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as Primitive from 'fumadocs-core/toc';
|
|
4
|
+
import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { cn } from '../../utils/cn';
|
|
6
|
+
import { useI18n } from '../../contexts/i18n';
|
|
7
|
+
import { TocThumb } from '../../components/layout/toc-thumb';
|
|
8
|
+
import { ScrollArea, ScrollViewport } from '../ui/scroll-area';
|
|
9
|
+
export default function ClerkTOCItems({ items, isMenu = false, }) {
|
|
10
|
+
const { text } = useI18n();
|
|
11
|
+
const viewRef = useRef(null);
|
|
12
|
+
const containerRef = useRef(null);
|
|
13
|
+
const [svg, setSvg] = useState();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!containerRef.current)
|
|
16
|
+
return;
|
|
17
|
+
const container = containerRef.current;
|
|
18
|
+
function onResize() {
|
|
19
|
+
if (container.clientHeight === 0)
|
|
20
|
+
return;
|
|
21
|
+
let w = 0, h = 0;
|
|
22
|
+
const d = [];
|
|
23
|
+
for (let i = 0; i < items.length; i++) {
|
|
24
|
+
const element = container.querySelector(`a[href="#${items[i].url.slice(1)}"]`);
|
|
25
|
+
if (!element)
|
|
26
|
+
continue;
|
|
27
|
+
const styles = getComputedStyle(element);
|
|
28
|
+
const offset = getLineOffset(items[i].depth) + 1, top = element.offsetTop + parseFloat(styles.paddingTop), bottom = element.offsetTop +
|
|
29
|
+
element.clientHeight -
|
|
30
|
+
parseFloat(styles.paddingBottom);
|
|
31
|
+
w = Math.max(offset, w);
|
|
32
|
+
h = Math.max(h, bottom);
|
|
33
|
+
d.push(`${i === 0 ? 'M' : 'L'}${offset} ${top}`);
|
|
34
|
+
d.push(`L${offset} ${bottom}`);
|
|
35
|
+
}
|
|
36
|
+
setSvg({
|
|
37
|
+
path: d.join(' '),
|
|
38
|
+
width: w + 1,
|
|
39
|
+
height: h,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const observer = new ResizeObserver(onResize);
|
|
43
|
+
onResize();
|
|
44
|
+
observer.observe(container);
|
|
45
|
+
return () => {
|
|
46
|
+
observer.disconnect();
|
|
47
|
+
};
|
|
48
|
+
}, [items]);
|
|
49
|
+
if (items.length === 0)
|
|
50
|
+
return (_jsx("div", { className: "rounded-lg border bg-fd-card p-3 text-xs text-fd-muted-foreground", children: text.tocNoHeadings }));
|
|
51
|
+
return (_jsx(ScrollArea, { className: cn('flex flex-col', isMenu && '-ms-3'), children: _jsxs(ScrollViewport, { className: "relative min-h-0", ref: viewRef, children: [svg ? (_jsx("div", { className: "absolute start-0 top-0 rtl:-scale-x-100", style: {
|
|
52
|
+
width: svg.width,
|
|
53
|
+
height: svg.height,
|
|
54
|
+
maskImage: `url("data:image/svg+xml,${
|
|
55
|
+
// Inline SVG
|
|
56
|
+
encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${svg.width} ${svg.height}"><path d="${svg.path}" stroke="black" stroke-width="1" fill="none" /></svg>`)}")`,
|
|
57
|
+
}, children: _jsx(TocThumb, { containerRef: containerRef, className: "mt-[var(--fd-top)] h-[var(--fd-height)] bg-fd-primary transition-all" }) })) : null, _jsx(Primitive.ScrollProvider, { containerRef: viewRef, children: _jsx("div", { className: "flex flex-col", ref: containerRef, children: items.map((item, i) => (_jsx(TOCItem, { item: item, upper: items[i - 1]?.depth, lower: items[i + 1]?.depth }, item.url))) }) })] }) }));
|
|
58
|
+
}
|
|
59
|
+
function getItemOffset(depth) {
|
|
60
|
+
if (depth <= 2)
|
|
61
|
+
return 16;
|
|
62
|
+
if (depth === 3)
|
|
63
|
+
return 32;
|
|
64
|
+
return 48;
|
|
65
|
+
}
|
|
66
|
+
function getLineOffset(depth) {
|
|
67
|
+
return depth >= 3 ? 12 : 0;
|
|
68
|
+
}
|
|
69
|
+
function TOCItem({ item, upper = item.depth, lower = item.depth, }) {
|
|
70
|
+
const offset = getLineOffset(item.depth), upperOffset = getLineOffset(upper), lowerOffset = getLineOffset(lower);
|
|
71
|
+
return (_jsxs(Primitive.TOCItem, { href: item.url, style: {
|
|
72
|
+
paddingInlineStart: getItemOffset(item.depth),
|
|
73
|
+
}, className: "prose relative py-2 text-sm text-fd-muted-foreground transition-colors [overflow-wrap:anywhere] first:pt-0 last:pb-0 data-[active=true]:text-fd-primary", children: [offset !== upperOffset ? (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", className: "absolute -top-2 start-0 size-4 rtl:-scale-x-100", children: _jsx("line", { x1: upperOffset, y1: "0", x2: offset, y2: "16", className: "stroke-fd-foreground/10", strokeWidth: "1" }) })) : null, _jsx("div", { className: cn('absolute inset-y-0 w-px bg-fd-foreground/10', offset !== upperOffset && 'top-2', offset !== lowerOffset && 'bottom-2'), style: {
|
|
74
|
+
insetInlineStart: offset,
|
|
75
|
+
} }), item.title] }));
|
|
76
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TOCItemType } from 'fumadocs-core/server';
|
|
2
|
+
import type { PopoverContentProps, PopoverTriggerProps } from '@radix-ui/react-popover';
|
|
3
|
+
export declare const TocPopover: import("react").FC<import("@radix-ui/react-popover").PopoverProps>;
|
|
4
|
+
export declare function TocPopoverTrigger({ items, ...props }: PopoverTriggerProps & {
|
|
5
|
+
items: TOCItemType[];
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function TocPopoverContent(props: PopoverContentProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=toc-popover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-popover.d.ts","sourceRoot":"","sources":["../../../src/components/layout/toc-popover.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AASxD,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAEjC,eAAO,MAAM,UAAU,oEAAU,CAAC;AAElC,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,GAAG,KAAK,EACT,EAAE,mBAAmB,GAAG;IAAE,KAAK,EAAE,WAAW,EAAE,CAAA;CAAE,2CAyBhD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,2CAiB3D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { cn } from '../../utils/cn';
|
|
5
|
+
import { useI18n } from '../../contexts/i18n';
|
|
6
|
+
import * as Primitive from 'fumadocs-core/toc';
|
|
7
|
+
import { ChevronRight, Text } from 'lucide-react';
|
|
8
|
+
import { Popover, PopoverContent, PopoverTrigger, } from '../../components/ui/popover';
|
|
9
|
+
export const TocPopover = Popover;
|
|
10
|
+
export function TocPopoverTrigger({ items, ...props }) {
|
|
11
|
+
const { text } = useI18n();
|
|
12
|
+
const active = Primitive.useActiveAnchor();
|
|
13
|
+
const current = useMemo(() => {
|
|
14
|
+
return items.find((item) => active === item.url.slice(1))?.title;
|
|
15
|
+
}, [items, active]);
|
|
16
|
+
return (_jsxs(PopoverTrigger, { ...props, className: cn('inline-flex items-center gap-2 text-nowrap px-4 py-2 text-start md:px-3', props.className), children: [_jsx(Text, { className: "size-4 shrink-0" }), text.toc, current ? (_jsxs(_Fragment, { children: [_jsx(ChevronRight, { className: "-mx-1.5 size-4 shrink-0 text-fd-muted-foreground" }), _jsx("span", { className: "truncate text-fd-muted-foreground", children: current })] })) : null] }));
|
|
17
|
+
}
|
|
18
|
+
export function TocPopoverContent(props) {
|
|
19
|
+
return (_jsx(PopoverContent, { hideWhenDetached: true, alignOffset: 16, align: "start", side: "bottom", "data-toc-popover": "", ...props, className: cn('flex max-h-[var(--radix-popover-content-available-height)] w-[260px] flex-col gap-4 p-3', props.className), children: props.children }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type HTMLAttributes, type ReactNode, type RefObject } from 'react';
|
|
2
|
+
export type TOCThumb = [top: number, height: number];
|
|
3
|
+
export declare function TocThumb({ containerRef, ...props }: HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
containerRef: RefObject<HTMLElement>;
|
|
5
|
+
}): ReactNode;
|
|
6
|
+
//# sourceMappingURL=toc-thumb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc-thumb.d.ts","sourceRoot":"","sources":["../../../src/components/layout/toc-thumb.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAIf,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAgCrD,wBAAgB,QAAQ,CAAC,EACvB,YAAY,EACZ,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG;IAClC,YAAY,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;CACtC,GAAG,SAAS,CAgCZ"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, } from 'react';
|
|
3
|
+
import * as Primitive from 'fumadocs-core/toc';
|
|
4
|
+
import { useOnChange } from 'fumadocs-core/utils/use-on-change';
|
|
5
|
+
function calc(container, active) {
|
|
6
|
+
if (active.length === 0 || container.clientHeight === 0) {
|
|
7
|
+
return [0, 0];
|
|
8
|
+
}
|
|
9
|
+
let upper = Number.MAX_VALUE, lower = 0;
|
|
10
|
+
for (const item of active) {
|
|
11
|
+
const element = container.querySelector(`a[href="#${item}"]`);
|
|
12
|
+
if (!element)
|
|
13
|
+
continue;
|
|
14
|
+
const styles = getComputedStyle(element);
|
|
15
|
+
upper = Math.min(upper, element.offsetTop + parseFloat(styles.paddingTop));
|
|
16
|
+
lower = Math.max(lower, element.offsetTop +
|
|
17
|
+
element.clientHeight -
|
|
18
|
+
parseFloat(styles.paddingBottom));
|
|
19
|
+
}
|
|
20
|
+
return [upper, lower - upper];
|
|
21
|
+
}
|
|
22
|
+
function update(element, info) {
|
|
23
|
+
element.style.setProperty('--fd-top', `${info[0]}px`);
|
|
24
|
+
element.style.setProperty('--fd-height', `${info[1]}px`);
|
|
25
|
+
}
|
|
26
|
+
export function TocThumb({ containerRef, ...props }) {
|
|
27
|
+
const active = Primitive.useActiveAnchors();
|
|
28
|
+
const thumbRef = useRef(null);
|
|
29
|
+
const activeRef = useRef(active);
|
|
30
|
+
activeRef.current = active;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!containerRef.current)
|
|
33
|
+
return;
|
|
34
|
+
const container = containerRef.current;
|
|
35
|
+
const onResize = () => {
|
|
36
|
+
if (!thumbRef.current)
|
|
37
|
+
return;
|
|
38
|
+
update(thumbRef.current, calc(container, activeRef.current));
|
|
39
|
+
};
|
|
40
|
+
onResize();
|
|
41
|
+
const observer = new ResizeObserver(onResize);
|
|
42
|
+
observer.observe(container);
|
|
43
|
+
return () => {
|
|
44
|
+
observer.disconnect();
|
|
45
|
+
};
|
|
46
|
+
}, [containerRef]);
|
|
47
|
+
useOnChange(active, () => {
|
|
48
|
+
if (!containerRef.current || !thumbRef.current)
|
|
49
|
+
return;
|
|
50
|
+
update(thumbRef.current, calc(containerRef.current, active));
|
|
51
|
+
});
|
|
52
|
+
return _jsx("div", { ref: thumbRef, role: "none", ...props });
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TOCItemType } from 'fumadocs-core/server';
|
|
2
|
+
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
3
|
+
export interface TOCProps {
|
|
4
|
+
/**
|
|
5
|
+
* Custom content in TOC container, before the main TOC
|
|
6
|
+
*/
|
|
7
|
+
header?: ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Custom content in TOC container, after the main TOC
|
|
10
|
+
*/
|
|
11
|
+
footer?: ReactNode;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export declare function Toc(props: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function TOCItems({ items, isMenu, }: {
|
|
16
|
+
items: TOCItemType[];
|
|
17
|
+
isMenu?: boolean;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=toc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../../src/components/layout/toc.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAMpE,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IAEnB;;OAEG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;IAEnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAoBxD;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,MAAc,GACf,EAAE;IACD,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,2CAmCA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as Primitive from 'fumadocs-core/toc';
|
|
4
|
+
import { useRef } from 'react';
|
|
5
|
+
import { cn } from '../../utils/cn';
|
|
6
|
+
import { useI18n } from '../../contexts/i18n';
|
|
7
|
+
import { TocThumb } from '../../components/layout/toc-thumb';
|
|
8
|
+
import { ScrollArea, ScrollViewport } from '../ui/scroll-area';
|
|
9
|
+
export function Toc(props) {
|
|
10
|
+
return (_jsx("div", { ...props, "data-toc": "", className: cn('sticky top-fd-layout-top h-[var(--fd-toc-height)] flex-1 pb-2 pe-2 pt-12 max-lg:hidden', props.className), style: {
|
|
11
|
+
...props.style,
|
|
12
|
+
'--fd-toc-height': 'calc(100dvh - var(--fd-banner-height) - var(--fd-nav-height))',
|
|
13
|
+
}, children: props.children }));
|
|
14
|
+
}
|
|
15
|
+
export function TOCItems({ items, isMenu = false, }) {
|
|
16
|
+
const { text } = useI18n();
|
|
17
|
+
const containerRef = useRef(null);
|
|
18
|
+
const viewRef = useRef(null);
|
|
19
|
+
if (items.length === 0)
|
|
20
|
+
return (_jsx("div", { className: "rounded-lg border bg-fd-card p-3 text-xs text-fd-muted-foreground", children: text.tocNoHeadings }));
|
|
21
|
+
return (_jsx(ScrollArea, { className: cn('flex flex-col', isMenu && '-ms-3'), children: _jsx(Primitive.ScrollProvider, { containerRef: viewRef, children: _jsxs(ScrollViewport, { className: "relative min-h-0 text-sm", ref: viewRef, children: [_jsx(TocThumb, { containerRef: containerRef, className: "absolute start-0 mt-[var(--fd-top)] h-[var(--fd-height)] w-px bg-fd-primary transition-all" }), _jsx("div", { ref: containerRef, className: cn('flex flex-col', !isMenu && 'border-s border-fd-foreground/10'), children: items.map((item) => (_jsx(TOCItem, { item: item }, item.url))) })] }) }) }));
|
|
22
|
+
}
|
|
23
|
+
function TOCItem({ item }) {
|
|
24
|
+
return (_jsx(Primitive.TOCItem, { href: item.url, className: cn('prose py-1.5 text-sm text-fd-muted-foreground transition-colors [overflow-wrap:anywhere] first:pt-0 last:pb-0 data-[active=true]:text-fd-primary', item.depth <= 2 && 'ps-3.5', item.depth === 3 && 'ps-6', item.depth >= 4 && 'ps-8'), children: item.title }));
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/components/registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AASpD,eAAO,MAAM,QAAQ,EAAE,QA8DtB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
const contextsMap = {
|
|
3
|
+
'../contexts/sidebar.tsx': 'fumadocs-ui/provider',
|
|
4
|
+
'../contexts/search.tsx': 'fumadocs-ui/provider',
|
|
5
|
+
'../contexts/tree.tsx': 'fumadocs-ui/provider',
|
|
6
|
+
'../contexts/i18n.tsx': 'fumadocs-ui/provider',
|
|
7
|
+
};
|
|
8
|
+
export const registry = {
|
|
9
|
+
path: fileURLToPath(import.meta.url),
|
|
10
|
+
rootDir: '../../',
|
|
11
|
+
namespaces: {
|
|
12
|
+
'': 'components',
|
|
13
|
+
'../utils': 'lib',
|
|
14
|
+
'../layouts': 'components',
|
|
15
|
+
},
|
|
16
|
+
components: [
|
|
17
|
+
{
|
|
18
|
+
name: 'layout/root-toggle',
|
|
19
|
+
files: ['layout/root-toggle.tsx'],
|
|
20
|
+
mapImportPath: contextsMap,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'layout/language-toggle',
|
|
24
|
+
files: ['layout/language-toggle.tsx'],
|
|
25
|
+
mapImportPath: contextsMap,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'layouts/docs',
|
|
29
|
+
files: ['../layouts/docs.tsx'],
|
|
30
|
+
mapImportPath: contextsMap,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'layouts/home',
|
|
34
|
+
files: ['../layouts/home.tsx'],
|
|
35
|
+
mapImportPath: contextsMap,
|
|
36
|
+
},
|
|
37
|
+
{ name: 'accordion', files: ['accordion.tsx'] },
|
|
38
|
+
{ name: 'banner', files: ['banner.tsx'] },
|
|
39
|
+
{ name: 'callout', files: ['callout.tsx'] },
|
|
40
|
+
{ name: 'card', files: ['card.tsx'] },
|
|
41
|
+
{ name: 'codeblock', files: ['codeblock.tsx'] },
|
|
42
|
+
{ name: 'files', files: ['files.tsx'] },
|
|
43
|
+
{ name: 'heading', files: ['heading.tsx'] },
|
|
44
|
+
{
|
|
45
|
+
name: 'image-zoom',
|
|
46
|
+
description: 'Zoomable Image',
|
|
47
|
+
files: ['image-zoom.tsx', 'image-zoom.css'],
|
|
48
|
+
},
|
|
49
|
+
{ name: 'inline-toc', files: ['inline-toc.tsx'] },
|
|
50
|
+
{ name: 'steps', files: ['steps.tsx'] },
|
|
51
|
+
{ name: 'tabs', files: ['tabs.tsx'] },
|
|
52
|
+
{ name: 'type-table', files: ['type-table.tsx'] },
|
|
53
|
+
{
|
|
54
|
+
name: 'button',
|
|
55
|
+
unlisted: true,
|
|
56
|
+
files: ['ui/button.tsx'],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
dependencies: {
|
|
60
|
+
'fumadocs-core': {
|
|
61
|
+
type: 'runtime',
|
|
62
|
+
},
|
|
63
|
+
'fumadocs-ui': {
|
|
64
|
+
type: 'runtime',
|
|
65
|
+
},
|
|
66
|
+
next: {
|
|
67
|
+
type: 'runtime',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
declare function Steps({ children, }: {
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export declare function Steps({ children, }: {
|
|
4
3
|
children: ReactNode;
|
|
5
4
|
}): React.ReactElement;
|
|
6
|
-
declare function Step({ children, }: {
|
|
5
|
+
export declare function Step({ children, }: {
|
|
7
6
|
children: ReactNode;
|
|
8
7
|
}): React.ReactElement;
|
|
9
|
-
|
|
10
|
-
export { Step, Steps };
|
|
8
|
+
//# sourceMappingURL=steps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.d.ts","sourceRoot":"","sources":["../../src/components/steps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,wBAAgB,KAAK,CAAC,EACpB,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,KAAK,CAAC,YAAY,CAErB;AAED,wBAAgB,IAAI,CAAC,EACnB,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,KAAK,CAAC,YAAY,CAErB"}
|
package/dist/components/steps.js
CHANGED
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import "
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
function Steps({
|
|
6
|
-
children
|
|
7
|
-
}) {
|
|
8
|
-
return /* @__PURE__ */ jsx("div", { className: "steps", children });
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function Steps({ children, }) {
|
|
3
|
+
return _jsx("div", { className: "steps", children: children });
|
|
9
4
|
}
|
|
10
|
-
function Step({
|
|
11
|
-
|
|
12
|
-
}) {
|
|
13
|
-
return /* @__PURE__ */ jsx("div", { className: "step", children });
|
|
5
|
+
export function Step({ children, }) {
|
|
6
|
+
return _jsx("div", { className: "step", children: children });
|
|
14
7
|
}
|
|
15
|
-
export {
|
|
16
|
-
Step,
|
|
17
|
-
Steps
|
|
18
|
-
};
|
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const Tabs$1: react.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsProps & react.RefAttributes<HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
6
|
-
declare const TabsList: react.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsListProps & react.RefAttributes<HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
7
|
-
declare const TabsTrigger: react.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsTriggerProps & react.RefAttributes<HTMLButtonElement>, "ref"> & react.RefAttributes<HTMLButtonElement>>;
|
|
8
|
-
declare const TabsContent: react.ForwardRefExoticComponent<Omit<TabsPrimitive.TabsContentProps & react.RefAttributes<HTMLDivElement>, "ref"> & react.RefAttributes<HTMLDivElement>>;
|
|
9
|
-
|
|
10
|
-
declare const tabs_TabsContent: typeof TabsContent;
|
|
11
|
-
declare const tabs_TabsList: typeof TabsList;
|
|
12
|
-
declare const tabs_TabsTrigger: typeof TabsTrigger;
|
|
13
|
-
declare namespace tabs {
|
|
14
|
-
export { Tabs$1 as Tabs, tabs_TabsContent as TabsContent, tabs_TabsList as TabsList, tabs_TabsTrigger as TabsTrigger };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface TabsProps extends TabsProps$1 {
|
|
1
|
+
import type { TabsContentProps, TabsProps as BaseProps } from '@radix-ui/react-tabs';
|
|
2
|
+
import * as Primitive from './ui/tabs';
|
|
3
|
+
export { Primitive };
|
|
4
|
+
export interface TabsProps extends BaseProps {
|
|
18
5
|
/**
|
|
19
6
|
* Identifier for Sharing value of tabs
|
|
20
7
|
*/
|
|
@@ -29,7 +16,6 @@ interface TabsProps extends TabsProps$1 {
|
|
|
29
16
|
defaultIndex?: number;
|
|
30
17
|
items?: string[];
|
|
31
18
|
}
|
|
32
|
-
declare function Tabs({ groupId, items, persist, defaultIndex, ...props }: TabsProps): React.ReactElement;
|
|
33
|
-
declare function Tab({ value, className, ...props }: TabsContentProps): React.ReactElement;
|
|
34
|
-
|
|
35
|
-
export { tabs as Primitive, Tab, Tabs, type TabsProps };
|
|
19
|
+
export declare function Tabs({ groupId, items, persist, defaultIndex, ...props }: TabsProps): React.ReactElement;
|
|
20
|
+
export declare function Tab({ value, className, ...props }: TabsContentProps): React.ReactElement;
|
|
21
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/components/tabs.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,IAAI,SAAS,EACvB,MAAM,sBAAsB,CAAC;AAY9B,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,CAAC;AAmBrB,MAAM,WAAW,SAAU,SAAQ,SAAS;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAID,wBAAgB,IAAI,CAAC,EACnB,OAAO,EACP,KAAU,EACV,OAAe,EACf,YAAgB,EAChB,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,KAAK,CAAC,YAAY,CA2DhC;AAMD,wBAAgB,GAAG,CAAC,EAClB,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE,gBAAgB,GAAG,KAAK,CAAC,YAAY,CAsBvC"}
|
package/dist/components/tabs.js
CHANGED
|
@@ -1,179 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// src/components/tabs.tsx
|
|
10
|
-
import {
|
|
11
|
-
useMemo,
|
|
12
|
-
useState,
|
|
13
|
-
useCallback,
|
|
14
|
-
createContext,
|
|
15
|
-
useContext,
|
|
16
|
-
useRef,
|
|
17
|
-
useLayoutEffect,
|
|
18
|
-
useEffect
|
|
19
|
-
} from "react";
|
|
20
|
-
|
|
21
|
-
// src/components/ui/tabs.tsx
|
|
22
|
-
var tabs_exports = {};
|
|
23
|
-
__export(tabs_exports, {
|
|
24
|
-
Tabs: () => Tabs,
|
|
25
|
-
TabsContent: () => TabsContent,
|
|
26
|
-
TabsList: () => TabsList,
|
|
27
|
-
TabsTrigger: () => TabsTrigger
|
|
28
|
-
});
|
|
29
|
-
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
30
|
-
import * as React from "react";
|
|
31
|
-
import { jsx } from "react/jsx-runtime";
|
|
32
|
-
var Tabs = React.forwardRef((props, ref) => {
|
|
33
|
-
return /* @__PURE__ */ jsx(
|
|
34
|
-
TabsPrimitive.Root,
|
|
35
|
-
{
|
|
36
|
-
ref,
|
|
37
|
-
...props,
|
|
38
|
-
className: twMerge(
|
|
39
|
-
"flex flex-col overflow-hidden rounded-xl border bg-fd-card",
|
|
40
|
-
props.className
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
Tabs.displayName = "Tabs";
|
|
46
|
-
var TabsList = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
47
|
-
TabsPrimitive.List,
|
|
48
|
-
{
|
|
49
|
-
ref,
|
|
50
|
-
...props,
|
|
51
|
-
className: twMerge(
|
|
52
|
-
"flex flex-row items-end gap-4 overflow-x-auto bg-fd-secondary px-4 text-fd-muted-foreground",
|
|
53
|
-
props.className
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
));
|
|
57
|
-
TabsList.displayName = "TabsList";
|
|
58
|
-
var TabsTrigger = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
59
|
-
TabsPrimitive.Trigger,
|
|
60
|
-
{
|
|
61
|
-
ref,
|
|
62
|
-
...props,
|
|
63
|
-
className: twMerge(
|
|
64
|
-
"whitespace-nowrap border-b border-transparent py-2 text-sm font-medium transition-colors hover:text-fd-accent-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=active]:border-fd-primary data-[state=active]:text-fd-primary",
|
|
65
|
-
props.className
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
));
|
|
69
|
-
TabsTrigger.displayName = "TabsTrigger";
|
|
70
|
-
var TabsContent = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(
|
|
71
|
-
TabsPrimitive.Content,
|
|
72
|
-
{
|
|
73
|
-
ref,
|
|
74
|
-
...props,
|
|
75
|
-
className: twMerge("p-4", props.className)
|
|
76
|
-
}
|
|
77
|
-
));
|
|
78
|
-
TabsContent.displayName = "TabsContent";
|
|
79
|
-
|
|
80
|
-
// src/components/tabs.tsx
|
|
81
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
82
|
-
var listeners = /* @__PURE__ */ new Map();
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState, useCallback, createContext, useContext, useRef, useLayoutEffect, useEffect, } from 'react';
|
|
4
|
+
import { cn } from '../utils/cn';
|
|
5
|
+
import * as Primitive from './ui/tabs';
|
|
6
|
+
export { Primitive };
|
|
7
|
+
const listeners = new Map();
|
|
83
8
|
function addChangeListener(id, listener) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
9
|
+
const list = listeners.get(id) ?? [];
|
|
10
|
+
list.push(listener);
|
|
11
|
+
listeners.set(id, list);
|
|
87
12
|
}
|
|
88
13
|
function removeChangeListener(id, listener) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
id,
|
|
92
|
-
list.filter((item) => item !== listener)
|
|
93
|
-
);
|
|
14
|
+
const list = listeners.get(id) ?? [];
|
|
15
|
+
listeners.set(id, list.filter((item) => item !== listener));
|
|
94
16
|
}
|
|
95
|
-
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
[groupId, persist]
|
|
132
|
-
|
|
133
|
-
return /* @__PURE__ */ jsxs(
|
|
134
|
-
Tabs,
|
|
135
|
-
{
|
|
136
|
-
value,
|
|
137
|
-
onValueChange,
|
|
138
|
-
...props,
|
|
139
|
-
className: twMerge("my-4", props.className),
|
|
140
|
-
children: [
|
|
141
|
-
/* @__PURE__ */ jsx2(TabsList, { children: values.map((v, i) => /* @__PURE__ */ jsx2(TabsTrigger, { value: v, children: items[i] }, v)) }),
|
|
142
|
-
/* @__PURE__ */ jsx2(ValueChangeContext.Provider, { value: onValueChange, children: props.children })
|
|
143
|
-
]
|
|
144
|
-
}
|
|
145
|
-
);
|
|
17
|
+
const ValueChangeContext = createContext(() => undefined);
|
|
18
|
+
export function Tabs({ groupId, items = [], persist = false, defaultIndex = 0, ...props }) {
|
|
19
|
+
const values = useMemo(() => items.map((item) => toValue(item)), [items]);
|
|
20
|
+
const [value, setValue] = useState(values[defaultIndex]);
|
|
21
|
+
const valuesRef = useRef(values);
|
|
22
|
+
valuesRef.current = values;
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
if (!groupId)
|
|
25
|
+
return;
|
|
26
|
+
const onUpdate = (v) => {
|
|
27
|
+
if (valuesRef.current.includes(v))
|
|
28
|
+
setValue(v);
|
|
29
|
+
};
|
|
30
|
+
const previous = persist
|
|
31
|
+
? localStorage.getItem(groupId)
|
|
32
|
+
: sessionStorage.getItem(groupId);
|
|
33
|
+
if (previous)
|
|
34
|
+
onUpdate(previous);
|
|
35
|
+
addChangeListener(groupId, onUpdate);
|
|
36
|
+
return () => {
|
|
37
|
+
removeChangeListener(groupId, onUpdate);
|
|
38
|
+
};
|
|
39
|
+
}, [groupId, persist]);
|
|
40
|
+
const onValueChange = useCallback((v) => {
|
|
41
|
+
if (groupId) {
|
|
42
|
+
listeners.get(groupId)?.forEach((item) => {
|
|
43
|
+
item(v);
|
|
44
|
+
});
|
|
45
|
+
if (persist)
|
|
46
|
+
localStorage.setItem(groupId, v);
|
|
47
|
+
else
|
|
48
|
+
sessionStorage.setItem(groupId, v);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
setValue(v);
|
|
52
|
+
}
|
|
53
|
+
}, [groupId, persist]);
|
|
54
|
+
return (_jsxs(Primitive.Tabs, { value: value, onValueChange: onValueChange, ...props, className: cn('my-4', props.className), children: [_jsx(Primitive.TabsList, { children: values.map((v, i) => (_jsx(Primitive.TabsTrigger, { value: v, children: items[i] }, v))) }), _jsx(ValueChangeContext.Provider, { value: onValueChange, children: props.children })] }));
|
|
146
55
|
}
|
|
147
56
|
function toValue(v) {
|
|
148
|
-
|
|
57
|
+
return v.toLowerCase().replace(/\s/, '-');
|
|
149
58
|
}
|
|
150
|
-
function Tab({
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
onValueChange(v);
|
|
161
|
-
}
|
|
162
|
-
}, [onValueChange, props.id, v]);
|
|
163
|
-
return /* @__PURE__ */ jsx2(
|
|
164
|
-
TabsContent,
|
|
165
|
-
{
|
|
166
|
-
value: v,
|
|
167
|
-
className: twMerge(
|
|
168
|
-
"prose-no-margin [&>figure:only-child]:-m-4 [&>figure:only-child]:rounded-none [&>figure:only-child]:border-none",
|
|
169
|
-
className
|
|
170
|
-
),
|
|
171
|
-
...props
|
|
172
|
-
}
|
|
173
|
-
);
|
|
59
|
+
export function Tab({ value, className, ...props }) {
|
|
60
|
+
const v = toValue(value);
|
|
61
|
+
const onValueChange = useContext(ValueChangeContext);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const hash = window.location.hash.slice(1);
|
|
64
|
+
if (hash === props.id) {
|
|
65
|
+
onValueChange(v);
|
|
66
|
+
}
|
|
67
|
+
}, [onValueChange, props.id, v]);
|
|
68
|
+
return (_jsx(Primitive.TabsContent, { value: v, className: cn('prose-no-margin [&>figure:only-child]:-m-4 [&>figure:only-child]:rounded-none [&>figure:only-child]:border-none', className), ...props }));
|
|
174
69
|
}
|
|
175
|
-
export {
|
|
176
|
-
tabs_exports as Primitive,
|
|
177
|
-
Tab,
|
|
178
|
-
Tabs2 as Tabs
|
|
179
|
-
};
|