@farming-labs/theme 0.2.17 → 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.
@@ -792,6 +792,7 @@ function createDocsLayout(config, options) {
792
792
  locale: activeLocale,
793
793
  copyMarkdown: copyMarkdownEnabled,
794
794
  copyMarkdownFormat: copyMarkdownConfig?.format,
795
+ copyMarkdownIncludeTitle: copyMarkdownConfig?.includeTitle,
795
796
  copyMarkdownLabel: copyMarkdownConfig?.label,
796
797
  copyMarkdownCopiedLabel: copyMarkdownConfig?.copiedLabel,
797
798
  openDocs: openDocsEnabled,
@@ -24,6 +24,7 @@ interface DocsPageClientProps {
24
24
  locale?: string;
25
25
  copyMarkdown?: boolean;
26
26
  copyMarkdownFormat?: CopyMarkdownFormat;
27
+ copyMarkdownIncludeTitle?: boolean;
27
28
  copyMarkdownLabel?: string;
28
29
  copyMarkdownCopiedLabel?: string;
29
30
  openDocs?: boolean;
@@ -95,6 +96,7 @@ declare function DocsPageClient({
95
96
  locale,
96
97
  copyMarkdown,
97
98
  copyMarkdownFormat,
99
+ copyMarkdownIncludeTitle,
98
100
  copyMarkdownLabel,
99
101
  copyMarkdownCopiedLabel,
100
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, copyMarkdownFormat, 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);
@@ -466,6 +466,7 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
466
466
  children: /* @__PURE__ */ jsx(PageActions, {
467
467
  copyMarkdown,
468
468
  copyMarkdownFormat,
469
+ copyMarkdownIncludeTitle,
469
470
  copyMarkdownLabel,
470
471
  copyMarkdownCopiedLabel,
471
472
  openDocs,
@@ -512,6 +513,7 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
512
513
  children: /* @__PURE__ */ jsx(PageActions, {
513
514
  copyMarkdown,
514
515
  copyMarkdownFormat,
516
+ copyMarkdownIncludeTitle,
515
517
  copyMarkdownLabel,
516
518
  copyMarkdownCopiedLabel,
517
519
  openDocs,
@@ -567,6 +569,7 @@ function DocsPageClient({ tocEnabled, tocStyle = "default", breadcrumbEnabled =
567
569
  children: /* @__PURE__ */ jsx(PageActions, {
568
570
  copyMarkdown,
569
571
  copyMarkdownFormat,
572
+ copyMarkdownIncludeTitle,
570
573
  copyMarkdownLabel,
571
574
  copyMarkdownCopiedLabel,
572
575
  openDocs,
@@ -13,6 +13,7 @@ interface SerializedProvider {
13
13
  interface PageActionsProps {
14
14
  copyMarkdown?: boolean;
15
15
  copyMarkdownFormat?: CopyMarkdownFormat;
16
+ copyMarkdownIncludeTitle?: boolean;
16
17
  copyMarkdownLabel?: string;
17
18
  copyMarkdownCopiedLabel?: string;
18
19
  openDocs?: boolean;
@@ -25,9 +26,16 @@ interface PageActionsProps {
25
26
  githubFileUrl?: string | null;
26
27
  analytics?: boolean;
27
28
  }
29
+ declare function formatCopyMarkdownContent(params: {
30
+ content: string;
31
+ format: CopyMarkdownFormat;
32
+ includeTitle?: boolean;
33
+ title?: string | null;
34
+ }): string;
28
35
  declare function PageActions({
29
36
  copyMarkdown,
30
37
  copyMarkdownFormat,
38
+ copyMarkdownIncludeTitle,
31
39
  copyMarkdownLabel,
32
40
  copyMarkdownCopiedLabel,
33
41
  openDocs,
@@ -40,4 +48,4 @@ declare function PageActions({
40
48
  analytics
41
49
  }: PageActionsProps): react_jsx_runtime0.JSX.Element | null;
42
50
  //#endregion
43
- 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, copyMarkdownFormat = "markdown", 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);
@@ -149,12 +168,19 @@ function PageActions({ copyMarkdown, copyMarkdownFormat = "markdown", copyMarkdo
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,
157
182
  format: copyMarkdownFormat,
183
+ includeTitle: copyMarkdownIncludeTitle,
158
184
  pathname
159
185
  }
160
186
  });
@@ -164,6 +190,7 @@ function PageActions({ copyMarkdown, copyMarkdownFormat = "markdown", copyMarkdo
164
190
  }, [
165
191
  analytics,
166
192
  copyMarkdownFormat,
193
+ copyMarkdownIncludeTitle,
167
194
  markdownHref,
168
195
  pathname
169
196
  ]);
@@ -241,6 +268,7 @@ function PageActions({ copyMarkdown, copyMarkdownFormat = "markdown", copyMarkdo
241
268
  className: "fd-page-action-btn",
242
269
  "data-copied": copied,
243
270
  "data-copy-markdown-format": copyMarkdownFormat,
271
+ "data-copy-markdown-include-title": copyMarkdownIncludeTitle || void 0,
244
272
  children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? copyMarkdownCopiedLabel : copyMarkdownLabel })]
245
273
  }),
246
274
  openDocs && /* @__PURE__ */ jsxs("a", {
@@ -275,6 +303,7 @@ function PageActions({ copyMarkdown, copyMarkdownFormat = "markdown", copyMarkdo
275
303
  className: "fd-page-action-btn",
276
304
  "data-copied": copied,
277
305
  "data-copy-markdown-format": copyMarkdownFormat,
306
+ "data-copy-markdown-include-title": copyMarkdownIncludeTitle || void 0,
278
307
  children: [copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}), /* @__PURE__ */ jsx("span", { children: copied ? copyMarkdownCopiedLabel : copyMarkdownLabel })]
279
308
  }), openDocs && resolvedProviders.length > 0 && /* @__PURE__ */ jsxs("div", {
280
309
  ref: dropdownRef,
@@ -324,4 +353,4 @@ function PageActions({ copyMarkdown, copyMarkdownFormat = "markdown", copyMarkdo
324
353
  }
325
354
 
326
355
  //#endregion
327
- 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.17",
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.17"
148
+ "@farming-labs/docs": "0.2.18"
149
149
  },
150
150
  "peerDependencies": {
151
151
  "@farming-labs/docs": ">=0.0.1",