@backmatter/next 0.0.59 → 0.0.61
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/config.cjs +6 -3
- package/dist/loader.cjs +6 -3
- package/package.json +3 -3
- package/src/block-gallery-client.tsx +22 -3
- package/src/preview-live.tsx +3 -2
- package/src/site-doc-bridge.tsx +4 -2
package/dist/config.cjs
CHANGED
|
@@ -464,16 +464,19 @@ function renderCachedCmsClient(typeArgs) {
|
|
|
464
464
|
return [
|
|
465
465
|
"const raw = createBackmatter({ ...config, models, sync: false });",
|
|
466
466
|
"",
|
|
467
|
+
"// Next types cacheLife against this host's profile names; the config may name any of them.",
|
|
468
|
+
"const contentCacheLife = cacheLife as (profile: CacheLifeProfile) => void;",
|
|
469
|
+
"",
|
|
467
470
|
"async function cachedGetDoc(type: string, slug: string) {",
|
|
468
471
|
' "use cache";',
|
|
469
|
-
"
|
|
472
|
+
" contentCacheLife(cacheLifeProfile(config));",
|
|
470
473
|
" cacheTag(...contentCacheTags(type, slug));",
|
|
471
474
|
" return raw.getDoc(type, slug);",
|
|
472
475
|
"}",
|
|
473
476
|
"",
|
|
474
477
|
"async function cachedListDocs(filter?: { type?: string }) {",
|
|
475
478
|
' "use cache";',
|
|
476
|
-
"
|
|
479
|
+
" contentCacheLife(cacheLifeProfile(config));",
|
|
477
480
|
" cacheTag(...listCacheTags(filter?.type));",
|
|
478
481
|
" return raw.listDocs(filter);",
|
|
479
482
|
"}",
|
|
@@ -505,7 +508,7 @@ function renderModelsBarrel(input) {
|
|
|
505
508
|
const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
|
|
506
509
|
const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
|
|
507
510
|
if (nextHost) {
|
|
508
|
-
lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
|
|
511
|
+
lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags, type CacheLifeProfile } from "@backmatter/core";');
|
|
509
512
|
lines.push('import { currentPreviewContent } from "@backmatter/next/preview-content";');
|
|
510
513
|
lines.push('import { cacheLife, cacheTag } from "next/cache";');
|
|
511
514
|
}
|
package/dist/loader.cjs
CHANGED
|
@@ -457,16 +457,19 @@ function renderCachedCmsClient(typeArgs) {
|
|
|
457
457
|
return [
|
|
458
458
|
"const raw = createBackmatter({ ...config, models, sync: false });",
|
|
459
459
|
"",
|
|
460
|
+
"// Next types cacheLife against this host's profile names; the config may name any of them.",
|
|
461
|
+
"const contentCacheLife = cacheLife as (profile: CacheLifeProfile) => void;",
|
|
462
|
+
"",
|
|
460
463
|
"async function cachedGetDoc(type: string, slug: string) {",
|
|
461
464
|
' "use cache";',
|
|
462
|
-
"
|
|
465
|
+
" contentCacheLife(cacheLifeProfile(config));",
|
|
463
466
|
" cacheTag(...contentCacheTags(type, slug));",
|
|
464
467
|
" return raw.getDoc(type, slug);",
|
|
465
468
|
"}",
|
|
466
469
|
"",
|
|
467
470
|
"async function cachedListDocs(filter?: { type?: string }) {",
|
|
468
471
|
' "use cache";',
|
|
469
|
-
"
|
|
472
|
+
" contentCacheLife(cacheLifeProfile(config));",
|
|
470
473
|
" cacheTag(...listCacheTags(filter?.type));",
|
|
471
474
|
" return raw.listDocs(filter);",
|
|
472
475
|
"}",
|
|
@@ -498,7 +501,7 @@ function renderModelsBarrel(input) {
|
|
|
498
501
|
const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
|
|
499
502
|
const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
|
|
500
503
|
if (nextHost) {
|
|
501
|
-
lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
|
|
504
|
+
lines.push('import { cacheLifeProfile, contentCacheTags, createQuery, listCacheTags, type CacheLifeProfile } from "@backmatter/core";');
|
|
502
505
|
lines.push('import { currentPreviewContent } from "@backmatter/next/preview-content";');
|
|
503
506
|
lines.push('import { cacheLife, cacheTag } from "next/cache";');
|
|
504
507
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backmatter/next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "Experimental Next.js adapter for Backmatter. APIs will break. Not ready for production.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"test": "bun test"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@backmatter/core": "^0.0.
|
|
50
|
+
"@backmatter/core": "^0.0.48",
|
|
51
51
|
"@mdx-js/mdx": "^3.1.1",
|
|
52
52
|
"remark-gfm": "^4.0.1",
|
|
53
|
-
"@backmatter/studio": "^0.0.
|
|
53
|
+
"@backmatter/studio": "^0.0.38"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"next": ">=16.3.0",
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
// Client side of the block gallery. The shell covers the host's layout (its
|
|
5
5
|
// header, footer and dev bar) with a scrolling panel, so only blocks show
|
|
6
6
|
// while the site's CSS still applies. It takes live props from Studio and
|
|
7
|
-
// reports which example the editor wants to open.
|
|
7
|
+
// reports which example the editor wants to open. The single view reports its
|
|
8
|
+
// height so Studio can size the frame to the block. Each block is boxed so a
|
|
8
9
|
// fixed or full-height block stays in its own frame, and a block that throws
|
|
9
10
|
// shows a note instead of breaking the page.
|
|
10
|
-
import { Component, useEffect, useState, startTransition, type ReactNode } from "react";
|
|
11
|
+
import { Component, useEffect, useRef, useState, startTransition, type ReactNode } from "react";
|
|
11
12
|
import { useRouter } from "next/navigation";
|
|
12
13
|
import {
|
|
13
14
|
BLOCK_GALLERY_OPEN_MESSAGE,
|
|
15
|
+
BLOCK_GALLERY_SIZE_MESSAGE,
|
|
14
16
|
blockGalleryPath,
|
|
15
17
|
isBlockGalleryPropsMessage,
|
|
16
18
|
readBlockGalleryQuery,
|
|
@@ -40,6 +42,7 @@ export function BlockGalleryShell({
|
|
|
40
42
|
}) {
|
|
41
43
|
const router = useRouter();
|
|
42
44
|
const [background, setBackground] = useState("#fff");
|
|
45
|
+
const content = useRef<HTMLDivElement>(null);
|
|
43
46
|
|
|
44
47
|
useEffect(() => {
|
|
45
48
|
const color = getComputedStyle(document.body).backgroundColor;
|
|
@@ -65,6 +68,22 @@ export function BlockGalleryShell({
|
|
|
65
68
|
return () => window.removeEventListener("message", onMessage);
|
|
66
69
|
}, [single, dashboardOrigins, router]);
|
|
67
70
|
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const el = content.current;
|
|
73
|
+
if (!single || !el || typeof ResizeObserver === "undefined") return;
|
|
74
|
+
let last = -1;
|
|
75
|
+
const report = () => {
|
|
76
|
+
const height = Math.ceil(el.getBoundingClientRect().height);
|
|
77
|
+
if (height === last) return;
|
|
78
|
+
last = height;
|
|
79
|
+
postToStudio({ type: BLOCK_GALLERY_SIZE_MESSAGE, height });
|
|
80
|
+
};
|
|
81
|
+
const observer = new ResizeObserver(report);
|
|
82
|
+
observer.observe(el);
|
|
83
|
+
report();
|
|
84
|
+
return () => observer.disconnect();
|
|
85
|
+
}, [single]);
|
|
86
|
+
|
|
68
87
|
return (
|
|
69
88
|
<div
|
|
70
89
|
data-backmatter-block-gallery=""
|
|
@@ -77,7 +96,7 @@ export function BlockGalleryShell({
|
|
|
77
96
|
background,
|
|
78
97
|
}}
|
|
79
98
|
>
|
|
80
|
-
{children}
|
|
99
|
+
<div ref={content}>{children}</div>
|
|
81
100
|
</div>
|
|
82
101
|
);
|
|
83
102
|
}
|
package/src/preview-live.tsx
CHANGED
|
@@ -58,9 +58,10 @@ export function PreviewBody({
|
|
|
58
58
|
}) {
|
|
59
59
|
const [body, setBody] = useState<string | null>(null);
|
|
60
60
|
const [, setFrontmatter] = useState(doc.frontmatter);
|
|
61
|
+
const { type, slug } = doc;
|
|
61
62
|
|
|
62
63
|
useEffect(() => {
|
|
63
|
-
const source = new EventSource(streamUrl(
|
|
64
|
+
const source = new EventSource(streamUrl({ type, slug }));
|
|
64
65
|
const onMessage = (ev: MessageEvent) => {
|
|
65
66
|
try {
|
|
66
67
|
const data = JSON.parse(String(ev.data)) as PreviewChangeEvent;
|
|
@@ -75,7 +76,7 @@ export function PreviewBody({
|
|
|
75
76
|
source.removeEventListener("change", onMessage as EventListener);
|
|
76
77
|
source.close();
|
|
77
78
|
};
|
|
78
|
-
}, [
|
|
79
|
+
}, [type, slug]);
|
|
79
80
|
|
|
80
81
|
if (body === null) return children ?? <MdxBody source={doc.body} components={components} />;
|
|
81
82
|
return <MdxBody source={body} components={components} />;
|
package/src/site-doc-bridge.tsx
CHANGED
|
@@ -33,9 +33,11 @@ export function subscribeSiteDoc(listener: (doc: SiteDocRef) => void): () => voi
|
|
|
33
33
|
|
|
34
34
|
/** Rendered by the CMS page so the bar hears the document for the current route. */
|
|
35
35
|
export function SiteDocBridge({ doc }: { doc: SiteDocRef }) {
|
|
36
|
+
// Each server render passes a new object; only the fields name the document.
|
|
37
|
+
const { type, slug, workspaceId } = doc;
|
|
36
38
|
useEffect(() => {
|
|
37
|
-
publishSiteDoc(
|
|
38
|
-
}, [
|
|
39
|
+
publishSiteDoc({ type, slug, workspaceId });
|
|
40
|
+
}, [type, slug, workspaceId]);
|
|
39
41
|
|
|
40
42
|
return (
|
|
41
43
|
<span
|