@farming-labs/theme 0.0.9-beta.1 → 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.
@@ -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 };
@@ -452,54 +452,58 @@ function createDocsLayout(config) {
452
452
  collapsible: sidebarProps.collapsible !== false,
453
453
  flat: !!sidebarFlat
454
454
  });
455
- return /* @__PURE__ */ jsxs(DocsLayout, {
456
- tree,
457
- nav: {
458
- title: navTitle,
459
- url: navUrl
460
- },
461
- themeSwitch,
462
- sidebar: finalSidebarProps,
463
- ...aiMode === "sidebar-icon" && aiEnabled ? { searchToggle: { components: { lg: /* @__PURE__ */ jsx(SidebarSearchWithAI, {}) } } } : {},
464
- children: [
465
- /* @__PURE__ */ jsx(ColorStyle, { colors }),
466
- /* @__PURE__ */ jsx(TypographyStyle, { typography }),
467
- /* @__PURE__ */ jsx(LayoutStyle, { layout: layoutDimensions }),
468
- forcedTheme && /* @__PURE__ */ jsx(ForcedThemeScript, { theme: forcedTheme }),
469
- !staticExport && /* @__PURE__ */ jsx(DocsCommandSearch, {}),
470
- aiEnabled && /* @__PURE__ */ jsx(DocsAIFeatures, {
471
- mode: aiMode,
472
- position: aiPosition,
473
- floatingStyle: aiFloatingStyle,
474
- triggerComponentHtml: aiTriggerComponentHtml,
475
- suggestedQuestions: aiSuggestedQuestions,
476
- aiLabel,
477
- loaderVariant: aiLoaderVariant,
478
- loadingComponentHtml: aiLoadingComponentHtml,
479
- models: aiModels,
480
- defaultModelId: aiDefaultModelId
481
- }),
482
- /* @__PURE__ */ jsx(DocsPageClient, {
483
- tocEnabled,
484
- tocStyle,
485
- breadcrumbEnabled,
486
- entry: config.entry,
487
- copyMarkdown: copyMarkdownEnabled,
488
- openDocs: openDocsEnabled,
489
- openDocsProviders,
490
- pageActionsPosition,
491
- pageActionsAlignment,
492
- githubUrl,
493
- githubBranch,
494
- githubDirectory,
495
- lastModifiedMap,
496
- lastUpdatedEnabled,
497
- lastUpdatedPosition,
498
- llmsTxtEnabled,
499
- descriptionMap,
500
- children
501
- })
502
- ]
455
+ return /* @__PURE__ */ jsx("div", {
456
+ id: "nd-docs-layout",
457
+ style: { display: "contents" },
458
+ children: /* @__PURE__ */ jsxs(DocsLayout, {
459
+ tree,
460
+ nav: {
461
+ title: navTitle,
462
+ url: navUrl
463
+ },
464
+ themeSwitch,
465
+ sidebar: finalSidebarProps,
466
+ ...aiMode === "sidebar-icon" && aiEnabled ? { searchToggle: { components: { lg: /* @__PURE__ */ jsx(SidebarSearchWithAI, {}) } } } : {},
467
+ children: [
468
+ /* @__PURE__ */ jsx(ColorStyle, { colors }),
469
+ /* @__PURE__ */ jsx(TypographyStyle, { typography }),
470
+ /* @__PURE__ */ jsx(LayoutStyle, { layout: layoutDimensions }),
471
+ forcedTheme && /* @__PURE__ */ jsx(ForcedThemeScript, { theme: forcedTheme }),
472
+ !staticExport && /* @__PURE__ */ jsx(DocsCommandSearch, {}),
473
+ aiEnabled && /* @__PURE__ */ jsx(DocsAIFeatures, {
474
+ mode: aiMode,
475
+ position: aiPosition,
476
+ floatingStyle: aiFloatingStyle,
477
+ triggerComponentHtml: aiTriggerComponentHtml,
478
+ suggestedQuestions: aiSuggestedQuestions,
479
+ aiLabel,
480
+ loaderVariant: aiLoaderVariant,
481
+ loadingComponentHtml: aiLoadingComponentHtml,
482
+ models: aiModels,
483
+ defaultModelId: aiDefaultModelId
484
+ }),
485
+ /* @__PURE__ */ jsx(DocsPageClient, {
486
+ tocEnabled,
487
+ tocStyle,
488
+ breadcrumbEnabled,
489
+ entry: config.entry,
490
+ copyMarkdown: copyMarkdownEnabled,
491
+ openDocs: openDocsEnabled,
492
+ openDocsProviders,
493
+ pageActionsPosition,
494
+ pageActionsAlignment,
495
+ githubUrl,
496
+ githubBranch,
497
+ githubDirectory,
498
+ lastModifiedMap,
499
+ lastUpdatedEnabled,
500
+ lastUpdatedPosition,
501
+ llmsTxtEnabled,
502
+ descriptionMap,
503
+ children
504
+ })
505
+ ]
506
+ })
503
507
  });
504
508
  };
505
509
  }
package/dist/mdx.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { MDXImg } from "./mdx-img.mjs";
2
- import * as react from "react";
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: react.HTMLAttributes<HTMLPreElement>) => react_jsx_runtime0.JSX.Element;
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: react.FC<react.AnchorHTMLAttributes<HTMLAnchorElement>>;
23
- h1: (props: react.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
24
- h2: (props: react.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
25
- h3: (props: react.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
26
- h4: (props: react.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
27
- h5: (props: react.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
28
- h6: (props: react.HTMLAttributes<HTMLHeadingElement>) => react_jsx_runtime0.JSX.Element;
29
- table: (props: react.TableHTMLAttributes<HTMLTableElement>) => react_jsx_runtime0.JSX.Element;
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
- declare function getMDXComponents<T extends Record<string, unknown> = Record<string, unknown>>(overrides?: T): typeof extendedMdxComponents & T;
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 ![alt](url) 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
- return {
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.9-beta.1",
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.9-beta.1"
106
+ "@farming-labs/docs": "0.0.10"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@farming-labs/docs": ">=0.0.1",
package/styles/base.css CHANGED
@@ -290,7 +290,9 @@ figure.shiki:has(figcaption) figcaption {
290
290
  border-color 0.15s;
291
291
  user-select: none;
292
292
  }
293
-
293
+ .fd-ai-fm-msg-content .fd-ai-code-block pre {
294
+ padding:10px !important;
295
+ }
294
296
  .fd-page-action-btn:hover {
295
297
  color: var(--color-fd-accent-foreground);
296
298
  background: var(--color-fd-accent);
@@ -139,14 +139,19 @@ code:not(pre code) {
139
139
  * ═══════════════════════════════════════════════════════════════════ */
140
140
 
141
141
  /* ─── Wider content area on desktop ──────────────────────────────── */
142
- /* :root {
143
- --fd-layout-width: 1400px;
144
- } */
145
142
 
146
- /* ─── Docs grid: pin sidebar left, TOC right, content fills middle ── */
143
+ @media (min-width: 1024px) {
144
+ :root {
145
+ --fd-layout-width: 1400px;
146
+ }
147
+ }
148
+
149
+ /* ─── Docs grid: sidebar | content | TOC — with gap and constrained TOC ── */
147
150
  @media (min-width: 768px) {
148
- #nd-docs-layout {
149
- grid-template-columns: var(--fd-sidebar-col, 0px) 1fr min-content !important;
151
+ #nd-docs-layout,
152
+ [style*="fd-sidebar-col"] {
153
+ grid-template-columns: var(--fd-sidebar-col, 0px) minmax(0, 1fr) min(var(--fd-toc-width, 260px), 260px) !important;
154
+ gap: 24px !important;
150
155
  }
151
156
  }
152
157