@farming-labs/theme 0.2.108 → 0.2.110
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/browser.d.mts +0 -5
- package/dist/browser.mjs +2 -23
- package/dist/client-location.mjs +15 -5
- package/dist/docs-page-client.mjs +13 -16
- package/dist/serialize-icon.mjs +1 -2
- package/package.json +2 -2
package/dist/browser.d.mts
CHANGED
|
@@ -8,11 +8,6 @@ type BrowserDocsLayoutProps = Omit<TanstackDocsLayoutProps, "browserRuntime">;
|
|
|
8
8
|
/** Docs layout for framework-neutral browser adapters such as Farm.js. */
|
|
9
9
|
declare function BrowserDocsLayout(props: BrowserDocsLayoutProps): react_jsx_runtime0.JSX.Element;
|
|
10
10
|
type FumadocsProviderProps = ComponentPropsWithoutRef<typeof RootProvider>;
|
|
11
|
-
declare global {
|
|
12
|
-
interface Window {
|
|
13
|
-
__fdBrowserHistoryPatched?: boolean;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
11
|
interface BrowserRootProviderProps extends FumadocsProviderProps {
|
|
17
12
|
/** Path rendered by the server, used to keep hydration deterministic. */
|
|
18
13
|
initialPathname?: string;
|
package/dist/browser.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
+
import { subscribeToWindowLocation } from "./client-location.mjs";
|
|
3
4
|
import { TanstackDocsLayout } from "./tanstack-layout.mjs";
|
|
4
5
|
import { createContext, useCallback, useContext, useMemo, useSyncExternalStore } from "react";
|
|
5
6
|
import { FrameworkProvider } from "fumadocs-core/framework";
|
|
@@ -23,28 +24,6 @@ const defaultBrowserNavigation = {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
const BrowserNavigationContext = createContext(defaultBrowserNavigation);
|
|
26
|
-
function patchHistoryEvents() {
|
|
27
|
-
if (typeof window === "undefined" || window.__fdBrowserHistoryPatched) return;
|
|
28
|
-
for (const method of ["pushState", "replaceState"]) {
|
|
29
|
-
const original = window.history[method];
|
|
30
|
-
window.history[method] = function patchedHistoryMethod(...args) {
|
|
31
|
-
const result = original.apply(this, args);
|
|
32
|
-
window.dispatchEvent(new Event("fd-location-change"));
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
window.__fdBrowserHistoryPatched = true;
|
|
37
|
-
}
|
|
38
|
-
function subscribeToLocation(onStoreChange) {
|
|
39
|
-
if (typeof window === "undefined") return () => {};
|
|
40
|
-
patchHistoryEvents();
|
|
41
|
-
window.addEventListener("popstate", onStoreChange);
|
|
42
|
-
window.addEventListener("fd-location-change", onStoreChange);
|
|
43
|
-
return () => {
|
|
44
|
-
window.removeEventListener("popstate", onStoreChange);
|
|
45
|
-
window.removeEventListener("fd-location-change", onStoreChange);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
27
|
function getBrowserPathname() {
|
|
49
28
|
return typeof window === "undefined" ? "/" : window.location.pathname;
|
|
50
29
|
}
|
|
@@ -95,7 +74,7 @@ function BrowserLink({ prefetch: _prefetch, href, target, download, onClick, ...
|
|
|
95
74
|
}
|
|
96
75
|
/** Framework-neutral provider for server-rendered React documentation adapters. */
|
|
97
76
|
function BrowserRootProvider({ children, search, initialPathname = "/", navigation = defaultBrowserNavigation, ...props }) {
|
|
98
|
-
const useBrowserPathname = () => useSyncExternalStore(
|
|
77
|
+
const useBrowserPathname = () => useSyncExternalStore(subscribeToWindowLocation, getBrowserPathname, () => initialPathname);
|
|
99
78
|
return /* @__PURE__ */ jsx(BrowserNavigationContext.Provider, {
|
|
100
79
|
value: navigation,
|
|
101
80
|
children: /* @__PURE__ */ jsx(FrameworkProvider, {
|
package/dist/client-location.mjs
CHANGED
|
@@ -17,14 +17,24 @@ function patchHistoryEvents() {
|
|
|
17
17
|
wrap("replaceState");
|
|
18
18
|
window.__fdHistoryPatched = true;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function subscribeToWindowLocation(onStoreChange) {
|
|
21
21
|
if (typeof window === "undefined") return () => {};
|
|
22
22
|
patchHistoryEvents();
|
|
23
|
-
|
|
23
|
+
let active = true;
|
|
24
|
+
let notificationQueued = false;
|
|
25
|
+
const notify = () => {
|
|
26
|
+
if (notificationQueued) return;
|
|
27
|
+
notificationQueued = true;
|
|
28
|
+
queueMicrotask(() => {
|
|
29
|
+
notificationQueued = false;
|
|
30
|
+
if (active) onStoreChange();
|
|
31
|
+
});
|
|
32
|
+
};
|
|
24
33
|
window.addEventListener("popstate", notify);
|
|
25
34
|
window.addEventListener("hashchange", notify);
|
|
26
35
|
window.addEventListener("fd-location-change", notify);
|
|
27
36
|
return () => {
|
|
37
|
+
active = false;
|
|
28
38
|
window.removeEventListener("popstate", notify);
|
|
29
39
|
window.removeEventListener("hashchange", notify);
|
|
30
40
|
window.removeEventListener("fd-location-change", notify);
|
|
@@ -39,12 +49,12 @@ function getPathnameSnapshot() {
|
|
|
39
49
|
return window.location.pathname;
|
|
40
50
|
}
|
|
41
51
|
function useWindowSearchParams() {
|
|
42
|
-
const search = useSyncExternalStore(
|
|
52
|
+
const search = useSyncExternalStore(subscribeToWindowLocation, getSearchSnapshot, () => "");
|
|
43
53
|
return new URLSearchParams(search);
|
|
44
54
|
}
|
|
45
55
|
function useWindowPathname() {
|
|
46
|
-
return useSyncExternalStore(
|
|
56
|
+
return useSyncExternalStore(subscribeToWindowLocation, getPathnameSnapshot, () => "");
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
//#endregion
|
|
50
|
-
export { useWindowPathname, useWindowSearchParams };
|
|
60
|
+
export { subscribeToWindowLocation, useWindowPathname, useWindowSearchParams };
|
|
@@ -6,7 +6,7 @@ import { useWindowPathname, useWindowSearchParams } from "./client-location.mjs"
|
|
|
6
6
|
import { DocsFeedback } from "./docs-feedback.mjs";
|
|
7
7
|
import { resolveClientLocale, withLangInUrl } from "./i18n.mjs";
|
|
8
8
|
import { escapeJsonLdForScript } from "./json-ld.mjs";
|
|
9
|
-
import { Children, Fragment, useEffect, useState } from "react";
|
|
9
|
+
import { Children, Fragment, useEffect, useLayoutEffect, useState } from "react";
|
|
10
10
|
import { DocsBody, DocsPage, EditOnGitHub } from "fumadocs-ui/layouts/docs/page";
|
|
11
11
|
import { createPortal } from "react-dom";
|
|
12
12
|
import { usePathname, useRouter } from "fumadocs-core/framework";
|
|
@@ -307,19 +307,16 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
|
|
|
307
307
|
const resolvedReadingTime = !isChangelogRoute ? readingTimeProp !== void 0 ? readingTimeProp : readingTimeEnabled ? matchedReadingTime : void 0 : void 0;
|
|
308
308
|
const effectiveTocEnabled = isChangelogRoute ? false : tocEnabled;
|
|
309
309
|
const effectiveBreadcrumbEnabled = isChangelogRoute ? false : breadcrumbEnabled;
|
|
310
|
-
|
|
310
|
+
useLayoutEffect(() => {
|
|
311
311
|
if (!effectiveTocEnabled) return;
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
})));
|
|
321
|
-
});
|
|
322
|
-
return () => cancelAnimationFrame(timer);
|
|
312
|
+
const container = document.getElementById("nd-page");
|
|
313
|
+
if (!container) return;
|
|
314
|
+
const headings = container.querySelectorAll("h2[id], h3[id], h4[id]");
|
|
315
|
+
setToc(Array.from(headings).map((el) => ({
|
|
316
|
+
title: el.textContent?.replace(/^#\s*/, "") || "",
|
|
317
|
+
url: `#${el.id}`,
|
|
318
|
+
depth: parseInt(el.tagName[1], 10)
|
|
319
|
+
})));
|
|
323
320
|
}, [
|
|
324
321
|
children,
|
|
325
322
|
effectiveTocEnabled,
|
|
@@ -385,7 +382,7 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
|
|
|
385
382
|
const showActionsAboveTitle = showActions && pageActionsPosition === "above-title";
|
|
386
383
|
const showActionsInToc = showActions && pageActionsPosition === "toc";
|
|
387
384
|
const githubFileUrl = editOnGithubUrl ?? (githubUrl ? buildGithubFileUrl(githubUrl, githubBranch, pathname, entry, activeLocale, githubDirectory, contentDir) : void 0);
|
|
388
|
-
|
|
385
|
+
useLayoutEffect(() => {
|
|
389
386
|
if (!showActionsInToc) {
|
|
390
387
|
setTocActionsPortalHost(null);
|
|
391
388
|
return;
|
|
@@ -424,7 +421,7 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
|
|
|
424
421
|
showActionsInToc,
|
|
425
422
|
toc.length
|
|
426
423
|
]);
|
|
427
|
-
|
|
424
|
+
useLayoutEffect(() => {
|
|
428
425
|
if (!showActionsInToc) {
|
|
429
426
|
setTitleControlsPortalHost(null);
|
|
430
427
|
return;
|
|
@@ -509,7 +506,7 @@ function DocsPageClient({ tocEnabled, showLlmsInHeader = false, tocStyle = "defa
|
|
|
509
506
|
}, "below-title") : void 0;
|
|
510
507
|
const decoratedChildren = children;
|
|
511
508
|
const needsTitleDecorationsPortal = !pageTitle && (!!titleDescription || !!belowTitleBlock);
|
|
512
|
-
|
|
509
|
+
useLayoutEffect(() => {
|
|
513
510
|
if (!needsTitleDecorationsPortal) {
|
|
514
511
|
setTitlePortalHost(null);
|
|
515
512
|
return;
|
package/dist/serialize-icon.mjs
CHANGED
|
@@ -5,12 +5,11 @@ import { createRequire } from "node:module";
|
|
|
5
5
|
* Server-only helper to convert a ReactNode icon into an HTML string
|
|
6
6
|
* so it can be safely serialized across the server→client boundary.
|
|
7
7
|
*/
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
9
8
|
function serializeIcon(icon) {
|
|
10
9
|
if (!icon) return void 0;
|
|
11
10
|
if (typeof icon === "string") return icon;
|
|
12
11
|
try {
|
|
13
|
-
const { renderToStaticMarkup } =
|
|
12
|
+
const { renderToStaticMarkup } = createRequire(import.meta.url)("react-dom/server");
|
|
14
13
|
return renderToStaticMarkup(icon);
|
|
15
14
|
} catch {
|
|
16
15
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.110",
|
|
4
4
|
"description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"tsdown": "^0.20.3",
|
|
162
162
|
"typescript": "^5.9.3",
|
|
163
163
|
"vitest": "^4.1.8",
|
|
164
|
-
"@farming-labs/docs": "0.2.
|
|
164
|
+
"@farming-labs/docs": "0.2.110"
|
|
165
165
|
},
|
|
166
166
|
"peerDependencies": {
|
|
167
167
|
"@farming-labs/docs": ">=0.0.1",
|