@backmatter/next 0.0.38 → 0.0.40

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 CHANGED
@@ -190,7 +190,7 @@ function detectSdk(root) {
190
190
  } catch {}
191
191
  return "@backmatter/core/node";
192
192
  }
193
- function renderCachedCmsClient() {
193
+ function renderCachedCmsClient(typeArgs) {
194
194
  return [
195
195
  "const raw = createBackmatter({ ...config, models, sync: false });",
196
196
  "",
@@ -225,12 +225,14 @@ function renderCachedCmsClient() {
225
225
  " ...raw,",
226
226
  " getDoc,",
227
227
  " listDocs,",
228
- ` query: createQuery(models, { getDoc, listDocs }),`,
228
+ ` query: createQuery${typeArgs}(models, { getDoc, listDocs }),`,
229
229
  "};"
230
230
  ];
231
231
  }
232
232
  function renderModelsBarrel(input) {
233
233
  const nextHost = input.sdk === "@backmatter/next";
234
+ const blocks = input.blocks ?? [];
235
+ const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
234
236
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
235
237
  if (nextHost) {
236
238
  lines.push('import { contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
@@ -245,15 +247,21 @@ function renderModelsBarrel(input) {
245
247
  for (const m of input.models) {
246
248
  lines.push(`import ${m.importName} from "${importSpecifier(input.outDir, m.file)}";`);
247
249
  }
250
+ for (const block of blocks) {
251
+ lines.push(`import type ${block.name} from "${importSpecifier(input.outDir, block.file)}";`);
252
+ }
248
253
  lines.push("");
249
254
  lines.push(`export const models = [${input.models.map((m) => m.importName).join(", ")}] as const;`);
250
255
  lines.push("export type Models = typeof models;");
256
+ if (blocks.length > 0) {
257
+ lines.push(`type Blocks = readonly [${blocks.map((block) => `typeof ${block.name}`).join(", ")}];`);
258
+ }
251
259
  lines.push("");
252
260
  if (nextHost) {
253
- lines.push(...renderCachedCmsClient());
261
+ lines.push(...renderCachedCmsClient(typeArgs));
254
262
  } else {
255
263
  lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
256
- lines.push("export const cms = createBackmatter({ ...config, models });");
264
+ lines.push(`export const cms = createBackmatter${typeArgs}({ ...config, models });`);
257
265
  }
258
266
  return `${lines.join(`
259
267
  `)}
@@ -425,7 +433,7 @@ function generate(options) {
425
433
  const configFile = findConfigFile(root);
426
434
  const write = options.write ?? true;
427
435
  const rendered = {
428
- "index.ts": renderModelsBarrel({ outDir, models, configFile, sdk }),
436
+ "index.ts": renderModelsBarrel({ outDir, models, blocks, configFile, sdk }),
429
437
  "blocks.ts": renderBlocksBarrel({ outDir, blocks }),
430
438
  "block-fallbacks.ts": renderBlockFallbacksBarrel({ outDir, fallbacks }),
431
439
  "mdx.ts": renderMdxBarrel({ outDir, mdx }),
package/dist/loader.cjs CHANGED
@@ -183,7 +183,7 @@ function detectSdk(root) {
183
183
  } catch {}
184
184
  return "@backmatter/core/node";
185
185
  }
186
- function renderCachedCmsClient() {
186
+ function renderCachedCmsClient(typeArgs) {
187
187
  return [
188
188
  "const raw = createBackmatter({ ...config, models, sync: false });",
189
189
  "",
@@ -218,12 +218,14 @@ function renderCachedCmsClient() {
218
218
  " ...raw,",
219
219
  " getDoc,",
220
220
  " listDocs,",
221
- ` query: createQuery(models, { getDoc, listDocs }),`,
221
+ ` query: createQuery${typeArgs}(models, { getDoc, listDocs }),`,
222
222
  "};"
223
223
  ];
224
224
  }
225
225
  function renderModelsBarrel(input) {
226
226
  const nextHost = input.sdk === "@backmatter/next";
227
+ const blocks = input.blocks ?? [];
228
+ const typeArgs = blocks.length > 0 ? "<typeof models, Blocks>" : "";
227
229
  const lines = [GENERATED_HEADER, `import { createBackmatter } from "${input.sdk}";`];
228
230
  if (nextHost) {
229
231
  lines.push('import { contentCacheTags, createQuery, listCacheTags } from "@backmatter/core";');
@@ -238,15 +240,21 @@ function renderModelsBarrel(input) {
238
240
  for (const m of input.models) {
239
241
  lines.push(`import ${m.importName} from "${importSpecifier(input.outDir, m.file)}";`);
240
242
  }
243
+ for (const block of blocks) {
244
+ lines.push(`import type ${block.name} from "${importSpecifier(input.outDir, block.file)}";`);
245
+ }
241
246
  lines.push("");
242
247
  lines.push(`export const models = [${input.models.map((m) => m.importName).join(", ")}] as const;`);
243
248
  lines.push("export type Models = typeof models;");
249
+ if (blocks.length > 0) {
250
+ lines.push(`type Blocks = readonly [${blocks.map((block) => `typeof ${block.name}`).join(", ")}];`);
251
+ }
244
252
  lines.push("");
245
253
  if (nextHost) {
246
- lines.push(...renderCachedCmsClient());
254
+ lines.push(...renderCachedCmsClient(typeArgs));
247
255
  } else {
248
256
  lines.push("/** Typed content client: cms.query.{type}, cms.getDoc, cms.listDocs. */");
249
- lines.push("export const cms = createBackmatter({ ...config, models });");
257
+ lines.push(`export const cms = createBackmatter${typeArgs}({ ...config, models });`);
250
258
  }
251
259
  return `${lines.join(`
252
260
  `)}
@@ -418,7 +426,7 @@ function generate(options) {
418
426
  const configFile = findConfigFile(root);
419
427
  const write = options.write ?? true;
420
428
  const rendered = {
421
- "index.ts": renderModelsBarrel({ outDir, models, configFile, sdk }),
429
+ "index.ts": renderModelsBarrel({ outDir, models, blocks, configFile, sdk }),
422
430
  "blocks.ts": renderBlocksBarrel({ outDir, blocks }),
423
431
  "block-fallbacks.ts": renderBlockFallbacksBarrel({ outDir, fallbacks }),
424
432
  "mdx.ts": renderMdxBarrel({ outDir, mdx }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backmatter/next",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
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.29",
50
+ "@backmatter/core": "^0.0.34",
51
51
  "@mdx-js/mdx": "^3.1.1",
52
52
  "remark-gfm": "^4.0.1",
53
- "@backmatter/studio": "^0.0.15"
53
+ "@backmatter/studio": "^0.0.17"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "next": ">=16.3.0",
@@ -0,0 +1,8 @@
1
+ // packages/next/src/brand-icon.ts
2
+ // Same knockout circle as public/icon-black.png, drawn so the Studio
3
+ // document can carry a favicon without a file on the customer host.
4
+ // The asterisk is a hole; tab chrome shows through it.
5
+
6
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 406 406"><style>.disc{fill:#18181b}@media (prefers-color-scheme: dark){.disc{fill:#fafafa}}</style><defs><mask id="m"><rect width="406" height="406" fill="#fff"/><g fill="#000"><rect x="63.5" y="189.5" width="279" height="27" rx="13.5"/><rect x="63.5" y="189.5" width="279" height="27" rx="13.5" transform="rotate(45 203 203)"/><rect x="63.5" y="189.5" width="279" height="27" rx="13.5" transform="rotate(90 203 203)"/><rect x="63.5" y="189.5" width="279" height="27" rx="13.5" transform="rotate(135 203 203)"/></g></mask></defs><circle class="disc" cx="203" cy="203" r="203" mask="url(#m)"/></svg>`;
7
+
8
+ export const brandIconHref = `data:image/svg+xml,${encodeURIComponent(svg)}`;
package/src/routes.ts CHANGED
@@ -385,7 +385,7 @@ export function createCatchAll<Models extends readonly ModelDef[]>(
385
385
  if (!hit) return failFor();
386
386
  const body = await publishedBody(hit.type, hit.slug);
387
387
  if (body == null) return body;
388
- return createElement(Fragment, null, docBridge(hit), body);
388
+ return createElement(Fragment, null, docMarker(hit), docBridge(hit), body);
389
389
  };
390
390
 
391
391
  const PreviewBranch = async ({
@@ -411,12 +411,23 @@ export function createCatchAll<Models extends readonly ModelDef[]>(
411
411
  __html: "[data-backmatter-published]{display:none!important}",
412
412
  },
413
413
  }),
414
+ docMarker(hit),
414
415
  docBridge(hit),
415
416
  await loadPreviewDoc(hit, preview),
416
417
  ),
417
418
  );
418
419
  };
419
420
 
421
+ function docMarker(hit: RouteHit) {
422
+ if (cms.config.workspaceId) return null;
423
+ return createElement("span", {
424
+ hidden: true,
425
+ "data-backmatter-doc": "",
426
+ "data-type": hit.type,
427
+ "data-slug": hit.slug,
428
+ });
429
+ }
430
+
420
431
  function docBridge(hit: RouteHit) {
421
432
  if (!cms.config.workspaceId) return null;
422
433
  return createElement(SiteDocBridge, {
package/src/studio.tsx CHANGED
@@ -23,6 +23,7 @@ import type { BackmatterClient } from "@backmatter/core/node/create-backmatter";
23
23
  import studioPkg from "@backmatter/studio/package.json";
24
24
  import type { StudioDefinition } from "@backmatter/studio/define";
25
25
  import { requestUrlFrom } from "./request-url";
26
+ import { brandIconHref } from "./brand-icon";
26
27
  import { StudioMount, StudioSignedOut } from "./studio-client";
27
28
 
28
29
  export { requestUrlFrom };
@@ -143,6 +144,7 @@ export function StudioLayout({ children }: { children: ReactNode }) {
143
144
  <html lang="en" suppressHydrationWarning>
144
145
  <head>
145
146
  <meta name="robots" content="noindex, nofollow" />
147
+ <link rel="icon" href={brandIconHref} type="image/svg+xml" />
146
148
  <script dangerouslySetInnerHTML={{ __html: THEME_BOOT }} />
147
149
  </head>
148
150
  <body style={{ margin: 0 }}>