@farming-labs/theme 0.1.124 → 0.1.126

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/index.d.mts CHANGED
@@ -13,10 +13,10 @@ import { PageActions } from "./page-actions.mjs";
13
13
  import { withLangInUrl } from "./i18n.mjs";
14
14
  import { HoverLink, HoverLinkProps } from "./hover-link.mjs";
15
15
  import { Prompt, PromptProps } from "./prompt.mjs";
16
- import { Agent } from "./mdx.mjs";
16
+ import { Agent, CodeGroup } from "./mdx.mjs";
17
17
  import { DocsLayout } from "fumadocs-ui/layouts/docs";
18
18
  import { AIConfig, BreadcrumbConfig, ChangelogConfig, ChangelogFrontmatter, CopyMarkdownConfig, DocsConfig, DocsFeedbackData, DocsFeedbackValue, DocsMetadata, DocsNav, DocsTheme, FeedbackConfig, FontStyle, OGConfig, OpenDocsConfig, OpenDocsProvider, PageActionsConfig, PageFrontmatter, SidebarConfig, ThemeToggleConfig, TypographyConfig, UIConfig, createTheme, deepMerge, defineDocs, extendTheme } from "@farming-labs/docs";
19
19
  import { DocsBody, DocsPage } from "fumadocs-ui/layouts/docs/page";
20
20
  import { Tab, Tabs } from "fumadocs-ui/components/tabs";
21
21
  import { CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, Pre } from "fumadocs-ui/components/codeblock";
22
- export { type AIConfig, Agent, type BreadcrumbConfig, type ChangelogConfig, type ChangelogFrontmatter, CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, CommandGridUIDefaults, ConcreteUIDefaults, type CopyMarkdownConfig, DocsBody, DocsClientHooks, DocsCommandSearch, type DocsConfig, DocsFeedback, type DocsFeedbackData, type DocsFeedbackProps, type DocsFeedbackValue, DocsLayout, type DocsMetadata, type DocsNav, DocsPage, DocsPageClient, type DocsTheme, type FeedbackConfig, type FontStyle, DefaultUIDefaults as FumadocsUIDefaults, HardlineUIDefaults, HoverLink, type HoverLinkProps, LedgerUIDefaults, type OGConfig, type OpenDocsConfig, type OpenDocsProvider, PageActions, type PageActionsConfig, type PageFrontmatter, Pre, Prompt, type PromptProps, RootProvider, type SidebarConfig, Tab, Tabs, type ThemeToggleConfig, type TypographyConfig, type UIConfig, commandGrid, concrete, createDocsLayout, createDocsMetadata, createPageMetadata, createTheme, deepMerge, defineDocs, extendTheme, fumadocs, hardline, ledger, withLangInUrl };
22
+ export { type AIConfig, Agent, type BreadcrumbConfig, type ChangelogConfig, type ChangelogFrontmatter, CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, CodeGroup, CommandGridUIDefaults, ConcreteUIDefaults, type CopyMarkdownConfig, DocsBody, DocsClientHooks, DocsCommandSearch, type DocsConfig, DocsFeedback, type DocsFeedbackData, type DocsFeedbackProps, type DocsFeedbackValue, DocsLayout, type DocsMetadata, type DocsNav, DocsPage, DocsPageClient, type DocsTheme, type FeedbackConfig, type FontStyle, DefaultUIDefaults as FumadocsUIDefaults, HardlineUIDefaults, HoverLink, type HoverLinkProps, LedgerUIDefaults, type OGConfig, type OpenDocsConfig, type OpenDocsProvider, PageActions, type PageActionsConfig, type PageFrontmatter, Pre, Prompt, type PromptProps, RootProvider, type SidebarConfig, Tab, Tabs, type ThemeToggleConfig, type TypographyConfig, type UIConfig, commandGrid, concrete, createDocsLayout, createDocsMetadata, createPageMetadata, createTheme, deepMerge, defineDocs, extendTheme, fumadocs, hardline, ledger, withLangInUrl };
package/dist/index.mjs CHANGED
@@ -13,11 +13,11 @@ import { LedgerUIDefaults, ledger } from "./ledger/index.mjs";
13
13
  import { DocsClientHooks } from "./docs-client-hooks.mjs";
14
14
  import { HoverLink } from "./hover-link.mjs";
15
15
  import { Prompt } from "./prompt.mjs";
16
- import { Agent } from "./mdx.mjs";
16
+ import { Agent, CodeGroup } from "./mdx.mjs";
17
17
  import { DocsLayout } from "fumadocs-ui/layouts/docs";
18
18
  import { createTheme, deepMerge, defineDocs, extendTheme } from "@farming-labs/docs";
19
19
  import { DocsBody, DocsPage } from "fumadocs-ui/layouts/docs/page";
20
20
  import { Tab, Tabs } from "fumadocs-ui/components/tabs";
21
21
  import { CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, Pre } from "fumadocs-ui/components/codeblock";
22
22
 
23
- export { Agent, CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, CommandGridUIDefaults, ConcreteUIDefaults, DocsBody, DocsClientHooks, DocsCommandSearch, DocsFeedback, DocsLayout, DocsPage, DocsPageClient, DefaultUIDefaults as FumadocsUIDefaults, HardlineUIDefaults, HoverLink, LedgerUIDefaults, PageActions, Pre, Prompt, RootProvider, Tab, Tabs, commandGrid, concrete, createDocsLayout, createDocsMetadata, createPageMetadata, createTheme, deepMerge, defineDocs, extendTheme, fumadocs, hardline, ledger, withLangInUrl };
23
+ export { Agent, CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, CodeGroup, CommandGridUIDefaults, ConcreteUIDefaults, DocsBody, DocsClientHooks, DocsCommandSearch, DocsFeedback, DocsLayout, DocsPage, DocsPageClient, DefaultUIDefaults as FumadocsUIDefaults, HardlineUIDefaults, HoverLink, LedgerUIDefaults, PageActions, Pre, Prompt, RootProvider, Tab, Tabs, commandGrid, concrete, createDocsLayout, createDocsMetadata, createPageMetadata, createTheme, deepMerge, defineDocs, extendTheme, fumadocs, hardline, ledger, withLangInUrl };
package/dist/mdx.d.mts CHANGED
@@ -5,8 +5,9 @@ import React from "react";
5
5
  import { CodeBlockCopyData, DocsTheme } from "@farming-labs/docs";
6
6
  import * as react_jsx_runtime0 from "react/jsx-runtime";
7
7
  import { Tab, Tabs } from "fumadocs-ui/components/tabs";
8
- import * as fumadocs_ui_components_codeblock0 from "fumadocs-ui/components/codeblock";
8
+ import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger } from "fumadocs-ui/components/codeblock";
9
9
  import defaultMdxComponents from "fumadocs-ui/mdx";
10
+ import * as fumadocs_ui_components_ui_tabs0 from "fumadocs-ui/components/ui/tabs";
10
11
  import * as fumadocs_ui_components_card0 from "fumadocs-ui/components/card";
11
12
  import * as fumadocs_ui_components_callout0 from "fumadocs-ui/components/callout";
12
13
 
@@ -17,18 +18,37 @@ declare function Table(props: React.ComponentPropsWithoutRef<"table">): React.De
17
18
  declare function Agent(_props: {
18
19
  children?: React.ReactNode;
19
20
  }): null;
21
+ interface CodeGroupProps extends Omit<React.ComponentPropsWithoutRef<typeof CodeBlockTabs>, "children"> {
22
+ children?: React.ReactNode;
23
+ /**
24
+ * Mintlify-compatible prop. The current renderer keeps the same code tab UI
25
+ * and exposes this as a data attribute for theme overrides.
26
+ */
27
+ dropdown?: boolean;
28
+ }
29
+ declare function CodeGroup({
30
+ children,
31
+ defaultValue,
32
+ dropdown,
33
+ className,
34
+ ...props
35
+ }: CodeGroupProps): React.ReactElement<Omit<fumadocs_ui_components_ui_tabs0.TabsProps, "ref"> & {
36
+ "data-dropdown"?: string;
37
+ "data-fd-code-group"?: string;
38
+ }, string | React.JSXElementConstructor<any>> | null;
20
39
  declare const extendedMdxComponents: {
21
40
  img: typeof MDXImg;
22
41
  table: typeof Table;
23
42
  Agent: typeof Agent;
43
+ CodeGroup: typeof CodeGroup;
24
44
  HoverLink: typeof HoverLink;
25
45
  Prompt: typeof Prompt;
26
46
  Tab: typeof Tab;
27
47
  Tabs: typeof Tabs;
28
- CodeBlockTab: typeof fumadocs_ui_components_codeblock0.CodeBlockTab;
29
- CodeBlockTabs: typeof fumadocs_ui_components_codeblock0.CodeBlockTabs;
30
- CodeBlockTabsList: typeof fumadocs_ui_components_codeblock0.CodeBlockTabsList;
31
- CodeBlockTabsTrigger: typeof fumadocs_ui_components_codeblock0.CodeBlockTabsTrigger;
48
+ CodeBlockTab: typeof CodeBlockTab;
49
+ CodeBlockTabs: typeof CodeBlockTabs;
50
+ CodeBlockTabsList: typeof CodeBlockTabsList;
51
+ CodeBlockTabsTrigger: typeof CodeBlockTabsTrigger;
32
52
  pre: (props: React.HTMLAttributes<HTMLPreElement>) => react_jsx_runtime0.JSX.Element;
33
53
  Card: typeof fumadocs_ui_components_card0.Card;
34
54
  Cards: typeof fumadocs_ui_components_card0.Cards;
@@ -56,4 +76,4 @@ interface GetMDXComponentsOptions {
56
76
  }
57
77
  declare function getMDXComponents<T extends Record<string, unknown> = Record<string, unknown>>(overrides?: T, options?: GetMDXComponentsOptions): typeof extendedMdxComponents & T;
58
78
  //#endregion
59
- export { Agent, GetMDXComponentsOptions, HoverLink, Prompt, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
79
+ export { Agent, CodeGroup, CodeGroupProps, GetMDXComponentsOptions, HoverLink, Prompt, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
package/dist/mdx.mjs CHANGED
@@ -6,6 +6,7 @@ import { extractPromptText } from "./prompt-text.mjs";
6
6
  import { Prompt } from "./prompt.mjs";
7
7
  import React from "react";
8
8
  import { Tab, Tabs } from "fumadocs-ui/components/tabs";
9
+ import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger } from "fumadocs-ui/components/codeblock";
9
10
  import defaultMdxComponents from "fumadocs-ui/mdx";
10
11
 
11
12
  //#region src/mdx.ts
@@ -33,11 +34,132 @@ function Table(props) {
33
34
  function Agent(_props) {
34
35
  return null;
35
36
  }
37
+ const codeGroupLabelProps = [
38
+ "title",
39
+ "filename",
40
+ "file",
41
+ "name",
42
+ "label",
43
+ "value",
44
+ "data-title",
45
+ "data-filename",
46
+ "data-file"
47
+ ];
48
+ function cx(...values) {
49
+ return values.filter(Boolean).join(" ") || void 0;
50
+ }
51
+ function getElementProps(node) {
52
+ if (!React.isValidElement(node)) return void 0;
53
+ return node.props && typeof node.props === "object" ? node.props : void 0;
54
+ }
55
+ function readStringProp(props, key) {
56
+ const value = props?.[key];
57
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
58
+ }
59
+ function parseCodeMetaLabel(meta) {
60
+ if (!meta) return void 0;
61
+ const trimmed = meta.trim();
62
+ if (!trimmed) return void 0;
63
+ const namedMatch = trimmed.match(/\b(?:title|filename|file|name|label)=["']([^"']+)["']/);
64
+ if (namedMatch?.[1]?.trim()) return namedMatch[1].trim();
65
+ const language = trimmed.split(/\s+/, 1)[0] ?? "";
66
+ const rest = trimmed.slice(language.length).trim();
67
+ if (!rest) return void 0;
68
+ return rest.replace(/\{[^}]*\}/g, " ").split(/\s+/).find((part) => part && !part.includes("="))?.replace(/^["']|["']$/g, "");
69
+ }
70
+ function parseLanguageFromProps(props) {
71
+ const language = readStringProp(props, "language");
72
+ if (language) return language;
73
+ return (readStringProp(props, "className")?.match(/language-([^\s]+)/))?.[1];
74
+ }
75
+ function getCodeGroupLabelFromNode(node) {
76
+ const props = getElementProps(node);
77
+ if (!props) return void 0;
78
+ for (const key of codeGroupLabelProps) {
79
+ const value = readStringProp(props, key);
80
+ if (value) return value;
81
+ }
82
+ const metaLabel = parseCodeMetaLabel(readStringProp(props, "metastring") ?? readStringProp(props, "meta") ?? readStringProp(props, "data-meta"));
83
+ if (metaLabel) return metaLabel;
84
+ const nestedLabel = getCodeGroupLabelFromNode(React.Children.toArray(props.children).find((child) => {
85
+ return getCodeGroupLabelFromNode(child) !== void 0;
86
+ }));
87
+ if (nestedLabel) return nestedLabel;
88
+ return parseLanguageFromProps(props);
89
+ }
90
+ function getCodeGroupItems(children) {
91
+ const items = [];
92
+ React.Children.forEach(children, (child) => {
93
+ if (child === null || child === void 0 || typeof child === "boolean") return;
94
+ if (typeof child === "string" && child.trim() === "") return;
95
+ const props = getElementProps(child);
96
+ if (props && React.isValidElement(child) && child.type === React.Fragment) {
97
+ items.push(...getCodeGroupItems(props.children));
98
+ return;
99
+ }
100
+ items.push(child);
101
+ });
102
+ return items;
103
+ }
104
+ function toTabValue(label, index, used) {
105
+ const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || `code-${index + 1}`;
106
+ let value = slug;
107
+ let suffix = 2;
108
+ while (used.has(value)) {
109
+ value = `${slug}-${suffix}`;
110
+ suffix += 1;
111
+ }
112
+ used.add(value);
113
+ return value;
114
+ }
115
+ function stripCodeGroupLabelProps(child) {
116
+ if (!React.isValidElement(child)) return child;
117
+ return React.cloneElement(child, {
118
+ title: void 0,
119
+ filename: void 0,
120
+ file: void 0,
121
+ name: void 0,
122
+ label: void 0,
123
+ value: void 0,
124
+ "data-title": void 0,
125
+ "data-filename": void 0,
126
+ "data-file": void 0
127
+ });
128
+ }
129
+ function CodeGroup({ children, defaultValue, dropdown = false, className, ...props }) {
130
+ const usedValues = /* @__PURE__ */ new Set();
131
+ const items = getCodeGroupItems(children).map((child, index) => {
132
+ const label = getCodeGroupLabelFromNode(child) ?? `Code ${index + 1}`;
133
+ return {
134
+ child: stripCodeGroupLabelProps(child),
135
+ label,
136
+ value: toTabValue(label, index, usedValues)
137
+ };
138
+ });
139
+ if (items.length === 0) return null;
140
+ const CodeBlockTabsComponent = CodeBlockTabs;
141
+ return React.createElement(CodeBlockTabsComponent, {
142
+ ...props,
143
+ "data-fd-code-group": "",
144
+ "data-dropdown": dropdown ? "" : void 0,
145
+ className: cx("fd-code-group", dropdown && "fd-code-group-dropdown", className),
146
+ defaultValue: defaultValue ?? items[0]?.value
147
+ }, React.createElement(CodeBlockTabsList, null, items.map((item) => React.createElement(CodeBlockTabsTrigger, {
148
+ key: item.value,
149
+ value: item.value
150
+ }, item.label))), items.map((item) => React.createElement(CodeBlockTab, {
151
+ key: item.value,
152
+ value: item.value,
153
+ forceMount: true,
154
+ className: "fd-code-group-panel"
155
+ }, item.child)));
156
+ }
36
157
  const extendedMdxComponents = {
37
158
  ...defaultMdxComponents,
38
159
  img: MDXImg,
39
160
  table: Table,
40
161
  Agent,
162
+ CodeGroup,
41
163
  HoverLink,
42
164
  Prompt,
43
165
  Tab,
@@ -118,4 +240,4 @@ function getMDXComponents(overrides, options) {
118
240
  }
119
241
 
120
242
  //#endregion
121
- export { Agent, HoverLink, Prompt, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
243
+ export { Agent, CodeGroup, HoverLink, Prompt, Tab, Tabs, defaultMdxComponents, extendedMdxComponents, getMDXComponents };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.1.124",
3
+ "version": "0.1.126",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -139,7 +139,7 @@
139
139
  "tsdown": "^0.20.3",
140
140
  "typescript": "^5.9.3",
141
141
  "vitest": "^3.2.4",
142
- "@farming-labs/docs": "0.1.124"
142
+ "@farming-labs/docs": "0.1.126"
143
143
  },
144
144
  "peerDependencies": {
145
145
  "@farming-labs/docs": ">=0.0.1",
package/styles/base.css CHANGED
@@ -175,6 +175,14 @@ figure.shiki pre > code > [data-line] {
175
175
  padding: 0 0.25rem;
176
176
  }
177
177
 
178
+ .fd-code-group-panel[data-state="inactive"] {
179
+ display: none;
180
+ }
181
+
182
+ .fd-code-group-panel[data-state="active"] {
183
+ display: block;
184
+ }
185
+
178
186
  /* Titled code blocks: diagonal stripe background on the title bar */
179
187
  figure.shiki:has(figcaption) > div:first-child {
180
188
  position: relative;