@farming-labs/theme 0.2.120 → 0.2.122
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/README.md +6 -0
- package/dist/deferred-dialog.mjs +72 -0
- package/dist/docs-ai-features-lazy.mjs +13 -0
- package/dist/docs-ai-features.mjs +75 -57
- package/dist/docs-api.mjs +1 -1
- package/dist/docs-cloud-ai-client.mjs +2 -1
- package/dist/docs-content-reader.mjs +65 -0
- package/dist/docs-layout.mjs +106 -350
- package/dist/docs-page-client.d.mts +8 -0
- package/dist/docs-page-client.mjs +18 -7
- package/dist/page-metadata.d.mts +10 -0
- package/dist/page-metadata.mjs +81 -0
- package/dist/page-structured-data.d.mts +13 -0
- package/dist/page-structured-data.mjs +30 -0
- package/dist/reading-time-options.mjs +1 -1
- package/dist/tanstack-layout.mjs +3 -3
- package/package.json +2 -2
- package/styles/framework.css +1 -0
package/README.md
CHANGED
|
@@ -69,6 +69,12 @@ Available preset subpaths include `default`, `darksharp`, `pixel-border`, `color
|
|
|
69
69
|
|
|
70
70
|
## Main entrypoints
|
|
71
71
|
|
|
72
|
+
`createDocsLayout()` prepares navigation and page metadata together, reading each page once per
|
|
73
|
+
preparation pass. In production, the layout reuses that data across page renders within the same
|
|
74
|
+
layout instance, including static generation during `next build`. Content changes are picked up
|
|
75
|
+
by a new build/process; development renders refresh the data to reflect edits, new pages, and
|
|
76
|
+
deleted pages. No additional configuration is required.
|
|
77
|
+
|
|
72
78
|
| Entrypoint | Purpose |
|
|
73
79
|
| --- | --- |
|
|
74
80
|
| `@farming-labs/theme` | Default theme, `RootProvider`, layout helpers, and React UI |
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Suspense, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/deferred-dialog.tsx
|
|
8
|
+
/** Mount on first use, then retain dialog state across closes. */
|
|
9
|
+
function DeferredDialog({ open, onOpenChange, children }) {
|
|
10
|
+
const [hasOpened, setHasOpened] = useState(open);
|
|
11
|
+
if (open && !hasOpened) setHasOpened(true);
|
|
12
|
+
if (!open && !hasOpened) return null;
|
|
13
|
+
return /* @__PURE__ */ jsx(Suspense, {
|
|
14
|
+
fallback: open ? /* @__PURE__ */ jsx(LoadingDialog, { onOpenChange }) : null,
|
|
15
|
+
children
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function LoadingDialog({ onOpenChange }) {
|
|
19
|
+
const closeButton = useRef(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const previousFocus = document.activeElement;
|
|
22
|
+
const previousOverflow = document.body.style.overflow;
|
|
23
|
+
document.body.style.overflow = "hidden";
|
|
24
|
+
closeButton.current?.focus();
|
|
25
|
+
const onKeyDown = (event) => {
|
|
26
|
+
if (event.key === "Escape") onOpenChange(false);
|
|
27
|
+
if (event.key === "Tab") {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
closeButton.current?.focus();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
document.addEventListener("keydown", onKeyDown);
|
|
33
|
+
return () => {
|
|
34
|
+
document.body.style.overflow = previousOverflow;
|
|
35
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
36
|
+
if (previousFocus instanceof HTMLElement) previousFocus.focus();
|
|
37
|
+
};
|
|
38
|
+
}, [onOpenChange]);
|
|
39
|
+
return createPortal(/* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("div", {
|
|
40
|
+
className: "fd-ai-overlay",
|
|
41
|
+
onClick: () => onOpenChange(false)
|
|
42
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
43
|
+
role: "dialog",
|
|
44
|
+
"aria-modal": "true",
|
|
45
|
+
"aria-label": "Loading dialog",
|
|
46
|
+
"aria-busy": "true",
|
|
47
|
+
className: "fd-ai-dialog",
|
|
48
|
+
style: {
|
|
49
|
+
left: "50%",
|
|
50
|
+
top: "50%",
|
|
51
|
+
transform: "translate(-50%, -50%)",
|
|
52
|
+
width: "min(680px, calc(100vw - 32px))"
|
|
53
|
+
},
|
|
54
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
55
|
+
className: "fd-ai-header",
|
|
56
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
57
|
+
role: "status",
|
|
58
|
+
className: "fd-ai-header-title",
|
|
59
|
+
children: "Loading…"
|
|
60
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
61
|
+
ref: closeButton,
|
|
62
|
+
className: "fd-ai-close-btn",
|
|
63
|
+
onClick: () => onOpenChange(false),
|
|
64
|
+
"aria-label": "Close dialog",
|
|
65
|
+
children: "×"
|
|
66
|
+
})]
|
|
67
|
+
})
|
|
68
|
+
})] }), document.body);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
export { DeferredDialog };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { lazy } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/docs-ai-features-lazy.tsx
|
|
7
|
+
const LazyDocsAIFeatures = lazy(() => import("./docs-ai-features.mjs").then((module) => ({ default: module.DocsAIFeatures })));
|
|
8
|
+
function DocsAIFeatures(props) {
|
|
9
|
+
return /* @__PURE__ */ jsx(LazyDocsAIFeatures, { ...props });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { DocsAIFeatures };
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import { emitClientAnalyticsEvent } from "./client-analytics.mjs";
|
|
4
4
|
import { useWindowSearchParams } from "./client-location.mjs";
|
|
5
5
|
import { resolveClientLocale, withLangInUrl } from "./i18n.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { useEffect, useState } from "react";
|
|
6
|
+
import { DeferredDialog } from "./deferred-dialog.mjs";
|
|
7
|
+
import { Suspense, lazy, useEffect, useState } from "react";
|
|
8
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
|
|
10
10
|
//#region src/docs-ai-features.tsx
|
|
@@ -22,6 +22,9 @@ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
|
22
22
|
* This component is rendered inside the docs layout so the user's root layout
|
|
23
23
|
* never needs to be modified — AI features work purely from `docs.config.ts`.
|
|
24
24
|
*/
|
|
25
|
+
const DocsSearchDialog = lazy(() => import("./ai-search-dialog.mjs").then((module) => ({ default: module.DocsSearchDialog })));
|
|
26
|
+
const AIModalDialog = lazy(() => import("./ai-search-dialog.mjs").then((module) => ({ default: module.AIModalDialog })));
|
|
27
|
+
const FloatingAIChat = lazy(() => import("./ai-search-dialog.mjs").then((module) => ({ default: module.FloatingAIChat })));
|
|
25
28
|
function DocsAIFeatures({ mode, api = "/api/docs", requestMode, requestHeaders, requestStream, locale, position = "bottom-right", floatingStyle = "panel", triggerComponentHtml, suggestedQuestions, aiLabel, loaderVariant, loadingComponentHtml, models, defaultModelId, analytics = false, feedbackEnabled = true }) {
|
|
26
29
|
const localizedApi = withLangInUrl(api, resolveClientLocale(useWindowSearchParams(), locale));
|
|
27
30
|
if (mode === "search") return /* @__PURE__ */ jsx(SearchModeAI, {
|
|
@@ -52,22 +55,25 @@ function DocsAIFeatures({ mode, api = "/api/docs", requestMode, requestHeaders,
|
|
|
52
55
|
analytics,
|
|
53
56
|
feedbackEnabled
|
|
54
57
|
});
|
|
55
|
-
return /* @__PURE__ */ jsx(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
return /* @__PURE__ */ jsx(Suspense, {
|
|
59
|
+
fallback: null,
|
|
60
|
+
children: /* @__PURE__ */ jsx(FloatingAIChat, {
|
|
61
|
+
api: localizedApi,
|
|
62
|
+
requestMode,
|
|
63
|
+
requestHeaders,
|
|
64
|
+
requestStream,
|
|
65
|
+
position,
|
|
66
|
+
floatingStyle,
|
|
67
|
+
triggerComponentHtml,
|
|
68
|
+
suggestedQuestions,
|
|
69
|
+
aiLabel,
|
|
70
|
+
loaderVariant,
|
|
71
|
+
loadingComponentHtml,
|
|
72
|
+
models,
|
|
73
|
+
defaultModelId,
|
|
74
|
+
analytics,
|
|
75
|
+
feedbackEnabled
|
|
76
|
+
})
|
|
71
77
|
});
|
|
72
78
|
}
|
|
73
79
|
function SearchModeAI({ api, requestMode, requestHeaders, requestStream, suggestedQuestions, aiLabel, loaderVariant, loadingComponentHtml, models, defaultModelId, analytics, feedbackEnabled }) {
|
|
@@ -113,21 +119,25 @@ function SearchModeAI({ api, requestMode, requestHeaders, requestStream, suggest
|
|
|
113
119
|
document.addEventListener("click", handler, true);
|
|
114
120
|
return () => document.removeEventListener("click", handler, true);
|
|
115
121
|
}, [analytics]);
|
|
116
|
-
return /* @__PURE__ */ jsx(
|
|
122
|
+
return /* @__PURE__ */ jsx(DeferredDialog, {
|
|
117
123
|
open,
|
|
118
124
|
onOpenChange: setOpen,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
children: /* @__PURE__ */ jsx(DocsSearchDialog, {
|
|
126
|
+
open,
|
|
127
|
+
onOpenChange: setOpen,
|
|
128
|
+
api,
|
|
129
|
+
requestMode,
|
|
130
|
+
requestHeaders,
|
|
131
|
+
requestStream,
|
|
132
|
+
suggestedQuestions,
|
|
133
|
+
aiLabel,
|
|
134
|
+
loaderVariant,
|
|
135
|
+
loadingComponentHtml,
|
|
136
|
+
models,
|
|
137
|
+
defaultModelId,
|
|
138
|
+
analytics,
|
|
139
|
+
feedbackEnabled
|
|
140
|
+
})
|
|
131
141
|
});
|
|
132
142
|
}
|
|
133
143
|
function SidebarIconModeAI({ api, requestMode, requestHeaders, requestStream, suggestedQuestions, aiLabel, loaderVariant, loadingComponentHtml, models, defaultModelId, analytics, feedbackEnabled }) {
|
|
@@ -173,36 +183,44 @@ function SidebarIconModeAI({ api, requestMode, requestHeaders, requestStream, su
|
|
|
173
183
|
window.removeEventListener("fd-open-ai", onAI);
|
|
174
184
|
};
|
|
175
185
|
}, [analytics]);
|
|
176
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(
|
|
186
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(DeferredDialog, {
|
|
177
187
|
open: searchOpen,
|
|
178
188
|
onOpenChange: setSearchOpen,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
189
|
+
children: /* @__PURE__ */ jsx(DocsSearchDialog, {
|
|
190
|
+
open: searchOpen,
|
|
191
|
+
onOpenChange: setSearchOpen,
|
|
192
|
+
api,
|
|
193
|
+
requestMode,
|
|
194
|
+
requestHeaders,
|
|
195
|
+
requestStream,
|
|
196
|
+
suggestedQuestions,
|
|
197
|
+
aiLabel,
|
|
198
|
+
loaderVariant,
|
|
199
|
+
loadingComponentHtml,
|
|
200
|
+
models,
|
|
201
|
+
defaultModelId,
|
|
202
|
+
analytics,
|
|
203
|
+
feedbackEnabled
|
|
204
|
+
})
|
|
205
|
+
}), /* @__PURE__ */ jsx(DeferredDialog, {
|
|
192
206
|
open: aiOpen,
|
|
193
207
|
onOpenChange: setAiOpen,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
208
|
+
children: /* @__PURE__ */ jsx(AIModalDialog, {
|
|
209
|
+
open: aiOpen,
|
|
210
|
+
onOpenChange: setAiOpen,
|
|
211
|
+
api,
|
|
212
|
+
requestMode,
|
|
213
|
+
requestHeaders,
|
|
214
|
+
requestStream,
|
|
215
|
+
suggestedQuestions,
|
|
216
|
+
aiLabel,
|
|
217
|
+
loaderVariant,
|
|
218
|
+
loadingComponentHtml,
|
|
219
|
+
models,
|
|
220
|
+
defaultModelId,
|
|
221
|
+
analytics,
|
|
222
|
+
feedbackEnabled
|
|
223
|
+
})
|
|
206
224
|
})] });
|
|
207
225
|
}
|
|
208
226
|
|
package/dist/docs-api.mjs
CHANGED
|
@@ -3,9 +3,9 @@ import { getNextAppDir } from "./get-app-dir.mjs";
|
|
|
3
3
|
import { BoundedRouteCache } from "./bounded-route-cache.mjs";
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import matter from "gray-matter";
|
|
7
6
|
import { DEFAULT_A2A_AGENT_CARD_ROUTE, DEFAULT_AGENT_SKILLS_ARCHIVE_ROUTE_PATTERN, DEFAULT_AGENT_SKILLS_INDEX_ROUTE, DEFAULT_AGENT_SKILLS_ROUTE_PREFIX, DEFAULT_API_CATALOG_ROUTE, DEFAULT_LEGACY_SKILLS_INDEX_ROUTE, DEFAULT_SITEMAP_MD_DOCS_ROUTE, DOCS_AGENT_MANIFEST_FORMAT, DOCS_AGENT_MANIFEST_SCHEMA_URI, DOCS_AGENT_MANIFEST_VERSION, DOCS_CONTENT_CHANGES_FORMAT, DOCS_CONTENT_CHANGES_RESPONSE_VALUE, DOCS_MARKDOWN_SECTION_INDEX_FORMAT, acceptsDocsMarkdown, buildDocsAskAIContext, buildDocsConfigMap, buildDocsDiagnostics, buildDocsSearchFacets, compactDocsAgentDiscoverySpec, createDocsAgentTraceContext, createDocsAgentTraceId, createDocsCacheableResponse, createDocsContentChangeFeed, createDocsContentChangesHttpResponse, createDocsMarkdownResponse, createDocsRobotsResponse, createDocsSitemapResponse, createDocsStandardsDiscoveryResponse, detectDocsMarkdownAgentRequest, emitDocsAgentTraceEvent, emitDocsAnalyticsEvent, emitDocsTelemetryAgentSurfaceEvent, emitDocsTelemetryProjectEvent, formatDocsAskAIPackageHints, getDocsAgentManifestLinkHeader, getDocsDiscoveryLinkHeader, getDocsLlmsTxtMaxCharsIssue, getDocsMcpProtectedResourceMetadataRoutes, hasDocsMarkdownSignatureAgent, inferDocsTelemetryAgentSurface, isDocsConfigRequest, isDocsContentChangesRequest, isDocsDiagnosticsRequest, normalizeDocsOkfTrustMetadataInput, normalizeDocsRelated, normalizePageAgentFrontmatter, parseDocsAgentFeedbackData, performDocsSearch, performDocsSearchWithMetadata, readDocsJsonBody, renderDocsLlmsTxt, renderDocsMarkdownDocument, resolveAskAISearchRequestConfig, resolveChangelogConfig, resolveDocsAgentContractMcpTools, resolveDocsAudienceMdxContent, resolveDocsContentChangesConfig, resolveDocsI18n, resolveDocsLlmsTxtRequest, resolveDocsLlmsTxtSections, resolveDocsLocale, resolveDocsMetadataBaseUrl, resolveDocsPublishedAgentSkill, resolveDocsRequestApiRoute, resolveDocsRetrievalLastModified, resolveDocsSearchAudience, resolveDocsSearchError, resolveDocsSearchRequest, resolveDocsSitemapConfig, resolveDocsSitemapPageLastmod, resolveDocsStandardsDiscoveryRequest, resolvePageSidebarFolderIndexBehavior, resolveSearchRequestConfig, selectDocsLlmsTxtContent, stripGeneratedAgentProvenance, withDocsOpenApiOperationCounts } from "@farming-labs/docs";
|
|
8
7
|
import { buildApiReferenceOpenApiDocumentAsync, buildApiReferenceOperationPagesAsync, createApiReferenceOperationMarkdownResponse, createDocsMcpHttpHandler, createFilesystemDocsMcpSource, readDocsSitemapManifest, resolveApiReferenceConfig, resolveApiReferenceOpenApiDiscovery, resolveConfiguredAgentSkills, resolveDocsMcpConfig } from "@farming-labs/docs/runtime";
|
|
8
|
+
import matter from "gray-matter";
|
|
9
9
|
|
|
10
10
|
//#region src/docs-api.ts
|
|
11
11
|
/**
|
|
@@ -6,7 +6,8 @@ const FALLBACK_PUBLIC_DOCS_CLOUD_PROJECT_ID_ENV = "NEXT_PUBLIC_DOCS_CLOUD_PROJEC
|
|
|
6
6
|
const DEFAULT_PUBLIC_DOCS_CLOUD_API_KEY_ENV = "PUBLIC_DOCS_CLOUD_API_KEY";
|
|
7
7
|
const FALLBACK_PUBLIC_DOCS_CLOUD_API_KEY_ENV = "NEXT_PUBLIC_DOCS_CLOUD_API_KEY";
|
|
8
8
|
function readRuntimeEnv(name) {
|
|
9
|
-
|
|
9
|
+
if (typeof process === "undefined") return void 0;
|
|
10
|
+
const value = process.env?.[name]?.trim();
|
|
10
11
|
return value ? value : void 0;
|
|
11
12
|
}
|
|
12
13
|
function resolveDocsCloudApiBaseUrl() {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import matter from "gray-matter";
|
|
4
|
+
|
|
5
|
+
//#region src/docs-content-reader.ts
|
|
6
|
+
/**
|
|
7
|
+
* Share filesystem reads between navigation and page metadata preparation.
|
|
8
|
+
* Keep the reader local to one preparation pass: development must see edits,
|
|
9
|
+
* and production only needs to retain the resulting tree and metadata maps.
|
|
10
|
+
*/
|
|
11
|
+
function createDocsContentReader() {
|
|
12
|
+
const directories = /* @__PURE__ */ new Map();
|
|
13
|
+
const pages = /* @__PURE__ */ new Map();
|
|
14
|
+
return {
|
|
15
|
+
directory(dir) {
|
|
16
|
+
const cached = directories.get(dir);
|
|
17
|
+
if (cached) return cached;
|
|
18
|
+
const result = {
|
|
19
|
+
directories: [],
|
|
20
|
+
files: /* @__PURE__ */ new Set()
|
|
21
|
+
};
|
|
22
|
+
if (fs.existsSync(
|
|
23
|
+
/* turbopackIgnore: true */
|
|
24
|
+
dir
|
|
25
|
+
)) for (const entry of fs.readdirSync(
|
|
26
|
+
/* turbopackIgnore: true */
|
|
27
|
+
dir,
|
|
28
|
+
{ withFileTypes: true }
|
|
29
|
+
)) if (entry.isSymbolicLink() ? fs.statSync(
|
|
30
|
+
/* turbopackIgnore: true */
|
|
31
|
+
path.join(
|
|
32
|
+
/* turbopackIgnore: true */
|
|
33
|
+
dir,
|
|
34
|
+
entry.name
|
|
35
|
+
)
|
|
36
|
+
).isDirectory() : entry.isDirectory()) result.directories.push(entry.name);
|
|
37
|
+
else result.files.add(entry.name);
|
|
38
|
+
result.directories.sort();
|
|
39
|
+
directories.set(dir, result);
|
|
40
|
+
return result;
|
|
41
|
+
},
|
|
42
|
+
page(filePath) {
|
|
43
|
+
const cached = pages.get(filePath);
|
|
44
|
+
if (cached) return cached;
|
|
45
|
+
const { data, content } = matter(fs.readFileSync(
|
|
46
|
+
/* turbopackIgnore: true */
|
|
47
|
+
filePath,
|
|
48
|
+
"utf8"
|
|
49
|
+
));
|
|
50
|
+
const page = {
|
|
51
|
+
data,
|
|
52
|
+
content,
|
|
53
|
+
modifiedAt: fs.statSync(
|
|
54
|
+
/* turbopackIgnore: true */
|
|
55
|
+
filePath
|
|
56
|
+
).mtime
|
|
57
|
+
};
|
|
58
|
+
pages.set(filePath, page);
|
|
59
|
+
return page;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { createDocsContentReader };
|