@farming-labs/theme 0.0.9 → 0.0.10
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/code-block-copy-wrapper.d.mts +13 -0
- package/dist/code-block-copy-wrapper.mjs +50 -0
- package/dist/mdx.d.mts +17 -12
- package/dist/mdx.mjs +8 -13
- package/package.json +2 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
import { CodeBlockCopyData } from "@farming-labs/docs";
|
|
3
|
+
|
|
4
|
+
//#region src/code-block-copy-wrapper.d.ts
|
|
5
|
+
type PreProps = React$1.ComponentPropsWithoutRef<"pre">;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a wrapper around the default MDX `pre` component that calls
|
|
8
|
+
* `onCopyClick` when the user clicks the code block's copy button.
|
|
9
|
+
* The actual copy-to-clipboard is still done by the default component.
|
|
10
|
+
*/
|
|
11
|
+
declare function createPreWithCopyCallback(DefaultPre: React$1.ComponentType<PreProps> | "pre", onCopyClick?: (data: CodeBlockCopyData) => void): React$1.ComponentType<PreProps>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { createPreWithCopyCallback };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React$1 from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/code-block-copy-wrapper.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Creates a wrapper around the default MDX `pre` component that calls
|
|
9
|
+
* `onCopyClick` when the user clicks the code block's copy button.
|
|
10
|
+
* The actual copy-to-clipboard is still done by the default component.
|
|
11
|
+
*/
|
|
12
|
+
function createPreWithCopyCallback(DefaultPre, onCopyClick) {
|
|
13
|
+
if (!onCopyClick) return typeof DefaultPre === "string" ? DefaultPre : DefaultPre;
|
|
14
|
+
function PreWithCopyCallback(props) {
|
|
15
|
+
const ref = React$1.useRef(null);
|
|
16
|
+
React$1.useEffect(() => {
|
|
17
|
+
const wrapper = ref.current;
|
|
18
|
+
if (!wrapper) return;
|
|
19
|
+
const figure = wrapper.closest("figure");
|
|
20
|
+
if (!figure) return;
|
|
21
|
+
const handleClick = (e) => {
|
|
22
|
+
if (!e.target.closest?.("button")) return;
|
|
23
|
+
const code = figure.querySelector("pre")?.querySelector("code");
|
|
24
|
+
if (!code) return;
|
|
25
|
+
const content = code.textContent ?? "";
|
|
26
|
+
const url = typeof window !== "undefined" ? window.location.href : "";
|
|
27
|
+
const language = code.getAttribute("data-language") ?? figure.getAttribute("data-language") ?? void 0;
|
|
28
|
+
onCopyClick({
|
|
29
|
+
title: figure.querySelector("[data-title]")?.textContent?.trim() ?? figure.querySelector(".fd-codeblock-title-text")?.textContent?.trim() ?? void 0,
|
|
30
|
+
content,
|
|
31
|
+
url,
|
|
32
|
+
language
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
figure.addEventListener("click", handleClick, true);
|
|
36
|
+
return () => figure.removeEventListener("click", handleClick, true);
|
|
37
|
+
}, [onCopyClick]);
|
|
38
|
+
const Pre = DefaultPre;
|
|
39
|
+
return /* @__PURE__ */ jsx("div", {
|
|
40
|
+
ref,
|
|
41
|
+
"data-fd-copy-wrapper": true,
|
|
42
|
+
style: { display: "contents" },
|
|
43
|
+
children: typeof Pre === "string" ? /* @__PURE__ */ jsx("pre", { ...props }) : /* @__PURE__ */ jsx(Pre, { ...props })
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return PreWithCopyCallback;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { createPreWithCopyCallback };
|
package/dist/mdx.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MDXImg } from "./mdx-img.mjs";
|
|
2
|
-
import
|
|
2
|
+
import React from "react";
|
|
3
3
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
|
+
import { CodeBlockCopyData } from "@farming-labs/docs";
|
|
4
5
|
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
|
5
6
|
import * as fumadocs_ui_components_codeblock0 from "fumadocs-ui/components/codeblock";
|
|
6
7
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
@@ -16,22 +17,26 @@ declare const extendedMdxComponents: {
|
|
|
16
17
|
CodeBlockTabs: typeof fumadocs_ui_components_codeblock0.CodeBlockTabs;
|
|
17
18
|
CodeBlockTabsList: typeof fumadocs_ui_components_codeblock0.CodeBlockTabsList;
|
|
18
19
|
CodeBlockTabsTrigger: typeof fumadocs_ui_components_codeblock0.CodeBlockTabsTrigger;
|
|
19
|
-
pre: (props:
|
|
20
|
+
pre: (props: React.HTMLAttributes<HTMLPreElement>) => react_jsx_runtime0.JSX.Element;
|
|
20
21
|
Card: typeof fumadocs_ui_components_card0.Card;
|
|
21
22
|
Cards: typeof fumadocs_ui_components_card0.Cards;
|
|
22
|
-
a:
|
|
23
|
-
h1: (props:
|
|
24
|
-
h2: (props:
|
|
25
|
-
h3: (props:
|
|
26
|
-
h4: (props:
|
|
27
|
-
h5: (props:
|
|
28
|
-
h6: (props:
|
|
29
|
-
table: (props:
|
|
23
|
+
a: React.FC<React.AnchorHTMLAttributes<HTMLAnchorElement>>;
|
|
24
|
+
h1: (props: React.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
|
|
25
|
+
h2: (props: React.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
|
|
26
|
+
h3: (props: React.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
|
|
27
|
+
h4: (props: React.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
|
|
28
|
+
h5: (props: React.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
|
|
29
|
+
h6: (props: React.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
|
|
30
|
+
table: (props: React.TableHTMLAttributes<HTMLTableElement>) => react_jsx_runtime0.JSX.Element;
|
|
30
31
|
Callout: typeof fumadocs_ui_components_callout0.Callout;
|
|
31
32
|
CalloutContainer: typeof fumadocs_ui_components_callout0.CalloutContainer;
|
|
32
33
|
CalloutTitle: typeof fumadocs_ui_components_callout0.CalloutTitle;
|
|
33
34
|
CalloutDescription: typeof fumadocs_ui_components_callout0.CalloutDescription;
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
+
interface GetMDXComponentsOptions {
|
|
37
|
+
/** Called when the user clicks the copy button on a code block (in addition to the default copy). */
|
|
38
|
+
onCopyClick?: (data: CodeBlockCopyData) => void;
|
|
39
|
+
}
|
|
40
|
+
declare function getMDXComponents<T extends Record<string, unknown> = Record<string, unknown>>(overrides?: T, options?: GetMDXComponentsOptions): typeof extendedMdxComponents & T;
|
|
36
41
|
//#endregion
|
|
37
|
-
export { Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
|
|
42
|
+
export { GetMDXComponentsOptions, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
|
package/dist/mdx.mjs
CHANGED
|
@@ -1,30 +1,25 @@
|
|
|
1
|
+
import { createPreWithCopyCallback } from "./code-block-copy-wrapper.mjs";
|
|
1
2
|
import { MDXImg } from "./mdx-img.mjs";
|
|
2
3
|
import { Tab, Tabs } from "fumadocs-ui/components/tabs";
|
|
3
4
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
4
5
|
|
|
5
6
|
//#region src/mdx.ts
|
|
6
|
-
/**
|
|
7
|
-
* Re-export fumadocs-ui MDX components.
|
|
8
|
-
*
|
|
9
|
-
* Includes all default MDX components (headings, code blocks, callouts, cards)
|
|
10
|
-
* plus Tabs/Tab for tabbed content and InstallTabs for package manager tabs.
|
|
11
|
-
* Overrides `img` so that  in markdown works without width/height
|
|
12
|
-
* (uses Next Image with unoptimized + default dimensions for external URLs).
|
|
13
|
-
*
|
|
14
|
-
* Usage in mdx-components.tsx:
|
|
15
|
-
* import { getMDXComponents } from "@farming-labs/theme/mdx";
|
|
16
|
-
*/
|
|
17
7
|
const extendedMdxComponents = {
|
|
18
8
|
...defaultMdxComponents,
|
|
19
9
|
img: MDXImg,
|
|
20
10
|
Tab,
|
|
21
11
|
Tabs
|
|
22
12
|
};
|
|
23
|
-
function getMDXComponents(overrides) {
|
|
24
|
-
|
|
13
|
+
function getMDXComponents(overrides, options) {
|
|
14
|
+
const base = {
|
|
25
15
|
...extendedMdxComponents,
|
|
26
16
|
...overrides
|
|
27
17
|
};
|
|
18
|
+
if (options?.onCopyClick) {
|
|
19
|
+
const DefaultPre = defaultMdxComponents.pre;
|
|
20
|
+
if (DefaultPre) base.pre = createPreWithCopyCallback(DefaultPre, options.onCopyClick);
|
|
21
|
+
}
|
|
22
|
+
return base;
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"next": ">=14.0.0",
|
|
104
104
|
"tsdown": "^0.20.3",
|
|
105
105
|
"typescript": "^5.9.3",
|
|
106
|
-
"@farming-labs/docs": "0.0.
|
|
106
|
+
"@farming-labs/docs": "0.0.10"
|
|
107
107
|
},
|
|
108
108
|
"peerDependencies": {
|
|
109
109
|
"@farming-labs/docs": ">=0.0.1",
|