@farming-labs/theme 0.2.16 → 0.2.18

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.
@@ -791,6 +791,8 @@ function createDocsLayout(config, options) {
791
791
  publicPath: localeContext.publicPath,
792
792
  locale: activeLocale,
793
793
  copyMarkdown: copyMarkdownEnabled,
794
+ copyMarkdownFormat: copyMarkdownConfig?.format,
795
+ copyMarkdownIncludeTitle: copyMarkdownConfig?.includeTitle,
794
796
  copyMarkdownLabel: copyMarkdownConfig?.label,
795
797
  copyMarkdownCopiedLabel: copyMarkdownConfig?.copiedLabel,
796
798
  openDocs: openDocsEnabled,
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from "react";
2
- import { DocsFeedbackData, ReadingTimeFormat } from "@farming-labs/docs";
2
+ import { CopyMarkdownFormat, DocsFeedbackData, ReadingTimeFormat } from "@farming-labs/docs";
3
3
  import * as react_jsx_runtime0 from "react/jsx-runtime";
4
4
 
5
5
  //#region src/docs-page-client.d.ts
@@ -23,6 +23,8 @@ interface DocsPageClientProps {
23
23
  /** Active locale (used for llms.txt links) */
24
24
  locale?: string;
25
25
  copyMarkdown?: boolean;
26
+ copyMarkdownFormat?: CopyMarkdownFormat;
27
+ copyMarkdownIncludeTitle?: boolean;
26
28
  copyMarkdownLabel?: string;
27
29
  copyMarkdownCopiedLabel?: string;
28
30
  openDocs?: boolean;
@@ -93,6 +95,8 @@ declare function DocsPageClient({
93
95
  publicPath,
94
96
  locale,
95
97
  copyMarkdown,
98
+ copyMarkdownFormat,
99
+ copyMarkdownIncludeTitle,
96
100
  copyMarkdownLabel,
97
101
  copyMarkdownCopiedLabel,
98
102
  openDocs,
@@ -255,7 +255,7 @@ function findThreadlineTocActionsContainer() {
255
255
  }
256
256
  return toc.parentElement ?? toc;
257
257
  }
258
- function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled = true, changelogBasePath, entry = "docs", publicPath, locale, copyMarkdown = false, copyMarkdownLabel, copyMarkdownCopiedLabel, openDocs = false, openDocsProviders, openDocsTarget, openDocsPrompt, pageActionsPosition = "below-title", pageActionsAlignment = "left", githubUrl, contentDir, githubBranch = "main", githubDirectory, editOnGithubUrl, lastModifiedMap, lastModified: lastModifiedProp, readingTimeMap, readingTime: readingTimeProp, readingTimeFormat = "long", structuredDataMap, structuredData: structuredDataProp, readingTimeEnabled = false, lastUpdatedEnabled = true, lastUpdatedPosition = "footer", llmsTxtEnabled = false, descriptionMap, description, feedbackEnabled = false, feedbackQuestion, feedbackPlaceholder, feedbackRequireComment, feedbackPositiveLabel, feedbackNegativeLabel, feedbackSubmitLabel, feedbackOnFeedback, analytics = false, children }) {
258
+ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled = true, changelogBasePath, entry = "docs", publicPath, locale, copyMarkdown = false, copyMarkdownFormat, copyMarkdownIncludeTitle, copyMarkdownLabel, copyMarkdownCopiedLabel, openDocs = false, openDocsProviders, openDocsTarget, openDocsPrompt, pageActionsPosition = "below-title", pageActionsAlignment = "left", githubUrl, contentDir, githubBranch = "main", githubDirectory, editOnGithubUrl, lastModifiedMap, lastModified: lastModifiedProp, readingTimeMap, readingTime: readingTimeProp, readingTimeFormat = "long", structuredDataMap, structuredData: structuredDataProp, readingTimeEnabled = false, lastUpdatedEnabled = true, lastUpdatedPosition = "footer", llmsTxtEnabled = false, descriptionMap, description, feedbackEnabled = false, feedbackQuestion, feedbackPlaceholder, feedbackRequireComment, feedbackPositiveLabel, feedbackNegativeLabel, feedbackSubmitLabel, feedbackOnFeedback, analytics = false, children }) {
259
259
  const fdTocStyle = tocStyle === "directional" ? "clerk" : void 0;
260
260
  const [toc, setToc] = useState([]);
261
261
  const [titlePortalHost, setTitlePortalHost] = useState(null);
@@ -465,6 +465,8 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
465
465
  "data-actions-alignment": pageActionsAlignment,
466
466
  children: /* @__PURE__ */ jsx(PageActions, {
467
467
  copyMarkdown,
468
+ copyMarkdownFormat,
469
+ copyMarkdownIncludeTitle,
468
470
  copyMarkdownLabel,
469
471
  copyMarkdownCopiedLabel,
470
472
  openDocs,
@@ -510,6 +512,8 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
510
512
  className: "fd-actions-toc-portal not-prose",
511
513
  children: /* @__PURE__ */ jsx(PageActions, {
512
514
  copyMarkdown,
515
+ copyMarkdownFormat,
516
+ copyMarkdownIncludeTitle,
513
517
  copyMarkdownLabel,
514
518
  copyMarkdownCopiedLabel,
515
519
  openDocs,
@@ -564,6 +568,8 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
564
568
  "data-actions-alignment": pageActionsAlignment,
565
569
  children: /* @__PURE__ */ jsx(PageActions, {
566
570
  copyMarkdown,
571
+ copyMarkdownFormat,
572
+ copyMarkdownIncludeTitle,
567
573
  copyMarkdownLabel,
568
574
  copyMarkdownCopiedLabel,
569
575
  openDocs,
package/dist/index.d.mts CHANGED
@@ -16,8 +16,8 @@ import { HoverLink, HoverLinkProps } from "./hover-link.mjs";
16
16
  import { Prompt, PromptProps } from "./prompt.mjs";
17
17
  import { Agent, CodeGroup } from "./mdx.mjs";
18
18
  import { DocsLayout } from "fumadocs-ui/layouts/docs";
19
- 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
+ import { AIConfig, BreadcrumbConfig, ChangelogConfig, ChangelogFrontmatter, CopyMarkdownConfig, CopyMarkdownFormat, 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";
20
20
  import { DocsBody, DocsPage } from "fumadocs-ui/layouts/docs/page";
21
21
  import { Tab, Tabs } from "fumadocs-ui/components/tabs";
22
22
  import { CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, Pre } from "fumadocs-ui/components/codeblock";
23
- 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, ThreadlineUIDefaults, type TypographyConfig, type UIConfig, commandGrid, concrete, createDocsLayout, createDocsMetadata, createPageMetadata, createTheme, deepMerge, defineDocs, extendTheme, fumadocs, hardline, ledger, threadline, threadlinePageActions, withLangInUrl };
23
+ export { type AIConfig, Agent, type BreadcrumbConfig, type ChangelogConfig, type ChangelogFrontmatter, CodeBlock, CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, CodeGroup, CommandGridUIDefaults, ConcreteUIDefaults, type CopyMarkdownConfig, type CopyMarkdownFormat, 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, ThreadlineUIDefaults, type TypographyConfig, type UIConfig, commandGrid, concrete, createDocsLayout, createDocsMetadata, createPageMetadata, createTheme, deepMerge, defineDocs, extendTheme, fumadocs, hardline, ledger, threadline, threadlinePageActions, withLangInUrl };
@@ -1,3 +1,4 @@
1
+ import { CopyMarkdownFormat } from "@farming-labs/docs";
1
2
  import * as react_jsx_runtime0 from "react/jsx-runtime";
2
3
 
3
4
  //#region src/page-actions.d.ts
@@ -11,6 +12,8 @@ interface SerializedProvider {
11
12
  }
12
13
  interface PageActionsProps {
13
14
  copyMarkdown?: boolean;
15
+ copyMarkdownFormat?: CopyMarkdownFormat;
16
+ copyMarkdownIncludeTitle?: boolean;
14
17
  copyMarkdownLabel?: string;
15
18
  copyMarkdownCopiedLabel?: string;
16
19
  openDocs?: boolean;
@@ -23,8 +26,16 @@ interface PageActionsProps {
23
26
  githubFileUrl?: string | null;
24
27
  analytics?: boolean;
25
28
  }
29
+ declare function formatCopyMarkdownContent(params: {
30
+ content: string;
31
+ format: CopyMarkdownFormat;
32
+ includeTitle?: boolean;
33
+ title?: string | null;
34
+ }): string;
26
35
  declare function PageActions({
27
36
  copyMarkdown,
37
+ copyMarkdownFormat,
38
+ copyMarkdownIncludeTitle,
28
39
  copyMarkdownLabel,
29
40
  copyMarkdownCopiedLabel,
30
41
  openDocs,
@@ -37,4 +48,4 @@ declare function PageActions({
37
48
  analytics
38
49
  }: PageActionsProps): react_jsx_runtime0.JSX.Element | null;
39
50
  //#endregion
40
- export { PageActions };
51
+ export { PageActions, formatCopyMarkdownContent };
@@ -132,7 +132,26 @@ function pageUrlToMarkdownUrl(pageUrl) {
132
132
  function fillPromptTemplate(template, values) {
133
133
  return template.replace(/\{pageUrl\}/g, values.pageUrl).replace(/\{markdownUrl\}/g, values.markdownUrl).replace(/\{sourceUrl\}/g, values.sourceUrl).replace(/\{mdxUrl\}/g, values.sourceUrl).replace(/\{githubUrl\}/g, values.githubUrl).replace(/\{url\}/g, values.url);
134
134
  }
135
- function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdownCopiedLabel = "Copied!", openDocs, providers, openDocsTarget = DEFAULT_OPEN_DOCS_TARGET, openDocsPrompt = DEFAULT_OPEN_DOCS_PROMPT, alignment = "left", variant = "default", githubFileUrl, analytics = false }) {
135
+ function firstContentLine(content) {
136
+ return content.split(/\r?\n/).map((line) => line.trim()).find(Boolean);
137
+ }
138
+ function formatCopyMarkdownContent(params) {
139
+ const title = params.title?.trim();
140
+ if (!params.includeTitle || !title) return params.content;
141
+ const firstLine = firstContentLine(params.content);
142
+ if (params.format === "markdown") {
143
+ const heading = `# ${title}`;
144
+ if (firstLine === heading || firstLine === title) return params.content;
145
+ return `${heading}\n\n${params.content.trimStart()}`;
146
+ }
147
+ if (firstLine === title) return params.content;
148
+ return `${title}\n\n${params.content.trimStart()}`;
149
+ }
150
+ function currentPageTitle() {
151
+ const title = document.querySelector("#nd-page h1") ?? document.querySelector("article h1") ?? document.querySelector("h1");
152
+ return title?.innerText?.trim() || title?.textContent?.trim() || "";
153
+ }
154
+ function PageActions({ copyMarkdown, copyMarkdownFormat = "markdown", copyMarkdownIncludeTitle = false, copyMarkdownLabel = "Copy page", copyMarkdownCopiedLabel = "Copied!", openDocs, providers, openDocsTarget = DEFAULT_OPEN_DOCS_TARGET, openDocsPrompt = DEFAULT_OPEN_DOCS_PROMPT, alignment = "left", variant = "default", githubFileUrl, analytics = false }) {
136
155
  const [copied, setCopied] = useState(false);
137
156
  const [dropdownOpen, setDropdownOpen] = useState(false);
138
157
  const dropdownRef = useRef(null);
@@ -143,17 +162,25 @@ function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdo
143
162
  const handleCopyMarkdown = useCallback(async () => {
144
163
  try {
145
164
  let content = "";
146
- try {
165
+ if (copyMarkdownFormat === "markdown") try {
147
166
  const response = await fetch(markdownHref, { headers: { Accept: "text/markdown" } });
148
167
  if (response.ok) content = await response.text();
149
168
  } catch {}
150
169
  if (!content) content = document.querySelector("article")?.innerText || "";
151
170
  if (!content) return;
171
+ content = formatCopyMarkdownContent({
172
+ content,
173
+ format: copyMarkdownFormat,
174
+ includeTitle: copyMarkdownIncludeTitle,
175
+ title: currentPageTitle()
176
+ });
152
177
  await navigator.clipboard.writeText(content);
153
178
  if (analytics) emitClientAnalyticsEvent({
154
179
  type: "page_action_copy_markdown",
155
180
  properties: {
156
181
  contentLength: content.length,
182
+ format: copyMarkdownFormat,
183
+ includeTitle: copyMarkdownIncludeTitle,
157
184
  pathname
158
185
  }
159
186
  });
@@ -162,6 +189,8 @@ function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdo
162
189
  } catch {}
163
190
  }, [
164
191
  analytics,
192
+ copyMarkdownFormat,
193
+ copyMarkdownIncludeTitle,
165
194
  markdownHref,
166
195
  pathname
167
196
  ]);
@@ -238,6 +267,8 @@ function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdo
238
267
  onClick: handleCopyMarkdown,
239
268
  className: "fd-page-action-btn",
240
269
  "data-copied": copied,
270
+ "data-copy-markdown-format": copyMarkdownFormat,
271
+ "data-copy-markdown-include-title": copyMarkdownIncludeTitle || void 0,
241
272
  children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? copyMarkdownCopiedLabel : copyMarkdownLabel })]
242
273
  }),
243
274
  openDocs && /* @__PURE__ */ jsxs("a", {
@@ -271,6 +302,8 @@ function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdo
271
302
  onClick: handleCopyMarkdown,
272
303
  className: "fd-page-action-btn",
273
304
  "data-copied": copied,
305
+ "data-copy-markdown-format": copyMarkdownFormat,
306
+ "data-copy-markdown-include-title": copyMarkdownIncludeTitle || void 0,
274
307
  children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? copyMarkdownCopiedLabel : copyMarkdownLabel })]
275
308
  }), openDocs && resolvedProviders.length > 0 && /* @__PURE__ */ jsxs("div", {
276
309
  ref: dropdownRef,
@@ -320,4 +353,4 @@ function PageActions({ copyMarkdown, copyMarkdownLabel = "Copy page", copyMarkdo
320
353
  }
321
354
 
322
355
  //#endregion
323
- export { PageActions };
356
+ export { PageActions, formatCopyMarkdownContent };
@@ -357,6 +357,8 @@ function TanstackDocsLayout({ config, tree, locale, description, readingTime, la
357
357
  entry: config.entry ?? "docs",
358
358
  locale,
359
359
  copyMarkdown: copyMarkdownEnabled,
360
+ copyMarkdownFormat: copyMarkdownConfig?.format,
361
+ copyMarkdownIncludeTitle: copyMarkdownConfig?.includeTitle,
360
362
  copyMarkdownLabel: copyMarkdownConfig?.label,
361
363
  copyMarkdownCopiedLabel: copyMarkdownConfig?.copiedLabel,
362
364
  openDocs: openDocsEnabled,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -145,7 +145,7 @@
145
145
  "tsdown": "^0.20.3",
146
146
  "typescript": "^5.9.3",
147
147
  "vitest": "^4.1.8",
148
- "@farming-labs/docs": "0.2.16"
148
+ "@farming-labs/docs": "0.2.18"
149
149
  },
150
150
  "peerDependencies": {
151
151
  "@farming-labs/docs": ">=0.0.1",