@contentbit/studio 0.4.1 → 0.5.0

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 CHANGED
@@ -24,10 +24,11 @@ shadcn dashboard with:
24
24
  - document previews, source, stats, outgoing links, backlinks, keywords, and
25
25
  findings
26
26
 
27
- Generic blocks render through `@contentbit/react`. Studio automatically loads
28
- custom React block components from the registry folder when it finds
29
- `components.tsx`, `components.ts`, `preview.tsx`, `preview.ts`, `renderers.tsx`,
30
- or `renderers.ts`.
27
+ Studio automatically loads React block components from the registry folder when
28
+ it finds `components.tsx`, `components.ts`, `preview.tsx`, `preview.ts`,
29
+ `renderers.tsx`, or `renderers.ts`. If you installed the shadcn pack, Studio
30
+ also looks for copied `components/content-blocks/content-renderer.tsx` files and
31
+ uses their exported `styledComponents`.
31
32
 
32
33
  Studio is intentionally read-only in v1. It does not edit source files, write
33
34
  `.contentbit/link-index.json`, or run `contentbit links --fix`.
@@ -39,8 +40,11 @@ contentbit studio <globs...> \
39
40
  --registry ./blocks/registry.ts \
40
41
  --port 4377 \
41
42
  --host 127.0.0.1 \
43
+ --no-generic-blocks \
42
44
  --no-open
43
45
  ```
44
46
 
45
47
  The CLI binds `127.0.0.1` by default, starts at port `4377` and lets Vite choose
46
48
  the next free port, and opens the browser unless `--no-open` is passed.
49
+ Studio loads the generic block definitions by default; pass `--no-generic-blocks`
50
+ when your registry should own the full block set.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,MAAM,CAAA;AAI5F,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,YAAY,CAAA;AAEnE,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEhE,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;CACpB;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuDpF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAqD,KAAK,aAAa,EAAE,MAAM,MAAM,CAAA;AAI5F,OAAO,KAAK,EAAE,kBAAkB,EAAiB,MAAM,YAAY,CAAA;AAEnE,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,aAAa,GACd,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEhE,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;CACpB;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAwDpF"}
@@ -25,6 +25,7 @@ export async function startStudio(options) {
25
25
  globs: options.globs,
26
26
  cwd,
27
27
  registryPath: options.registryPath,
28
+ includeGenericBlocks: options.includeGenericBlocks,
28
29
  linkOptions: options.linkOptions,
29
30
  minSectionWords: options.minSectionWords,
30
31
  };
@@ -59,15 +60,26 @@ export async function startStudio(options) {
59
60
  };
60
61
  }
61
62
  async function loadProjectComponents(vite, options) {
63
+ const merged = {};
62
64
  for (const candidate of componentCandidates(options)) {
63
- if (!existsSync(candidate))
65
+ if (!existsSync(candidate.path))
64
66
  continue;
65
- const mod = (await vite.ssrLoadModule(candidate));
66
- const components = mod.blockComponents ?? mod.components ?? mod.default;
67
- if (components && typeof components === 'object')
68
- return components;
67
+ let mod;
68
+ try {
69
+ mod = (await vite.ssrLoadModule(candidate.path));
70
+ }
71
+ catch {
72
+ if (!candidate.bestEffort)
73
+ throw new Error(`Failed to load block components: ${candidate.path}`);
74
+ continue;
75
+ }
76
+ const maps = [mod.styledComponents, mod.blockComponents, mod.components, mod.default];
77
+ for (const components of maps) {
78
+ if (components && typeof components === 'object')
79
+ Object.assign(merged, components);
80
+ }
69
81
  }
70
- return undefined;
82
+ return Object.keys(merged).length > 0 ? merged : undefined;
71
83
  }
72
84
  function componentCandidates(options) {
73
85
  const dirs = new Set();
@@ -78,14 +90,19 @@ function componentCandidates(options) {
78
90
  dirs.add(dirname(registryPath));
79
91
  }
80
92
  dirs.add(join(options.cwd, 'blocks'));
81
- return [...dirs].flatMap((dir) => [
93
+ const rendererCandidates = [
94
+ join(options.cwd, 'components/content-blocks/content-renderer.tsx'),
95
+ join(options.cwd, 'src/components/content-blocks/content-renderer.tsx'),
96
+ ].map((path) => ({ path, bestEffort: true }));
97
+ const blockComponentCandidates = [...dirs].flatMap((dir) => [
82
98
  join(dir, 'components.tsx'),
83
99
  join(dir, 'components.ts'),
84
100
  join(dir, 'preview.tsx'),
85
101
  join(dir, 'preview.ts'),
86
102
  join(dir, 'renderers.tsx'),
87
103
  join(dir, 'renderers.ts'),
88
- ]);
104
+ ].map((path) => ({ path, bestEffort: false })));
105
+ return [...rendererCandidates, ...blockComponentCandidates];
89
106
  }
90
107
  function studioApiPlugin(options) {
91
108
  return {
@@ -1,4 +1,6 @@
1
1
  import type { BlockComponent } from '@contentbit/react';
2
- import type { DocumentNode } from '@contentbit/core';
3
- export declare function renderStudioPreview(document: DocumentNode, components?: Record<string, BlockComponent>): string;
2
+ import type { ValidatedDocumentNode } from '@contentbit/core';
3
+ export declare function renderStudioPreview(document: ValidatedDocumentNode, components?: Record<string, BlockComponent>, _options?: {
4
+ includeGenericComponents?: boolean;
5
+ }): string;
4
6
  //# sourceMappingURL=preview.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/server/preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAcpD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,YAAY,EACtB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAM,GAC9C,MAAM,CASR"}
1
+ {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/server/preview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAc7D,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,qBAAqB,EAC/B,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAM,EAC/C,QAAQ,GAAE;IAAE,wBAAwB,CAAC,EAAE,OAAO,CAAA;CAAO,GACpD,MAAM,CASR"}
@@ -3,7 +3,7 @@ import { createElement } from 'react';
3
3
  import { renderToStaticMarkup } from 'react-dom/server';
4
4
  import ReactMarkdown from 'react-markdown';
5
5
  import remarkGfm from 'remark-gfm';
6
- export function renderStudioPreview(document, components = {}) {
6
+ export function renderStudioPreview(document, components = {}, _options = {}) {
7
7
  return renderToStaticMarkup(createElement(ContentBlocks, {
8
8
  document,
9
9
  components,
@@ -1 +1 @@
1
- {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/server/scan.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,cAAc,EAGd,WAAW,EAIX,aAAa,EACb,aAAa,EAEd,MAAM,YAAY,CAAA;AAgBnB,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CA6ChF;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,aAAa,EACtB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAgChC;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAoD5E"}
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/server/scan.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,cAAc,EAGd,WAAW,EAIX,aAAa,EACb,aAAa,EAEd,MAAM,YAAY,CAAA;AAUnB,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CA6ChF;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,aAAa,EACtB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAgChC;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CAoD5E"}
@@ -1,12 +1,10 @@
1
1
  import { genericBlocks } from '@contentbit/blocks';
2
- import { analyzeDocument, buildLinkIndex, createBlockRegistry, extractFrontmatter, parseDocument, stripFrontmatter, validateDocument, validateLinks, } from '@contentbit/core';
2
+ import { createBlockRegistry, scanContentProject, } from '@contentbit/core';
3
3
  import { readFile } from 'node:fs/promises';
4
4
  import { basename, isAbsolute, join, relative } from 'node:path';
5
5
  import { pathToFileURL } from 'node:url';
6
6
  import { glob } from 'tinyglobby';
7
7
  import { renderStudioPreview } from './preview.js';
8
- const DEFAULT_MIN_SECTION_WORDS = 25;
9
- const BLOCKLESS_WORDS = 250;
10
8
  export async function scanProject(options) {
11
9
  const context = await scanContext(options);
12
10
  const blockUsage = {};
@@ -49,7 +47,7 @@ export async function scanProject(options) {
49
47
  withPrimary,
50
48
  withSecondary,
51
49
  },
52
- ...(context.index ? { linkGraph: graphSummary(context.index) } : {}),
50
+ ...(context.scan.linkGraph ? { linkGraph: context.scan.linkGraph } : {}),
53
51
  findings: context.findings,
54
52
  };
55
53
  }
@@ -58,21 +56,21 @@ export async function scanDocument(options, requestedPath) {
58
56
  const file = findAllowedFile(context, options.cwd ?? process.cwd(), requestedPath);
59
57
  if (!file)
60
58
  return null;
61
- const source = context.sources.get(file);
59
+ const scanned = context.scan.files.find((item) => item.path === file);
60
+ if (!scanned)
61
+ return null;
62
62
  const summary = context.summaries.find((item) => item.path === file);
63
63
  if (!summary)
64
64
  return null;
65
- const validation = validateDocument(parseDocument(stripFrontmatter(source)), context.registry);
66
- const previewHtml = renderStudioPreview(validation.document, (await options.previewComponents?.()) ?? {});
67
- const stats = analyzeDocument(source, { path: file });
65
+ const previewHtml = renderStudioPreview(scanned.validation.document, (await options.previewComponents?.()) ?? {}, { includeGenericComponents: options.includeGenericBlocks !== false });
68
66
  const page = context.index
69
67
  ? [...context.index.pages.values()].find((entry) => entry.path === file)
70
68
  : undefined;
71
69
  return {
72
70
  file: summary,
73
- source,
74
- frontmatter: context.frontmatter.get(file) ?? {},
75
- stats,
71
+ source: scanned.source,
72
+ frontmatter: scanned.frontmatter,
73
+ stats: scanned.stats,
76
74
  findings: context.findings.filter((finding) => finding.file === file),
77
75
  linksTo: page ? (page.linkRefs.length > 0 ? page.linkRefs : page.linksTo) : [],
78
76
  linkedFrom: page
@@ -139,39 +137,24 @@ async function scanContext(options) {
139
137
  const files = (await glob(options.globs, { absolute: true, cwd })).sort();
140
138
  if (files.length === 0)
141
139
  throw new Error(`studio: no files matched ${options.globs.join(' ')}`);
142
- const registry = await loadStudioRegistry(options.registryPath, cwd);
143
- const sources = new Map();
144
- const frontmatter = new Map();
145
- const findings = [];
146
- const summaries = [];
147
- const linkInputs = [];
148
- for (const file of files) {
149
- const source = await readFile(file, 'utf8');
150
- const fm = extractFrontmatter(source)?.data ?? {};
151
- sources.set(file, source);
152
- frontmatter.set(file, fm);
153
- linkInputs.push({ path: file, data: fm });
154
- const validation = validateDocument(parseDocument(stripFrontmatter(source)), registry);
155
- for (const diagnostic of validation.diagnostics) {
156
- findings.push(findingFromDiagnostic('validation', file, cwd, diagnostic));
157
- }
158
- const stats = analyzeDocument(source, { path: file });
159
- findings.push(...statsFindings(file, cwd, stats, options.minSectionWords ?? DEFAULT_MIN_SECTION_WORDS));
160
- summaries.push(fileSummary(file, cwd, fm, stats, findings.filter((finding) => finding.file === file), options));
161
- }
162
- let index;
163
- if (hasLinkFrontmatter(linkInputs, options.linkOptions?.slugField)) {
164
- for (const { file, diagnostic } of validateLinks(linkInputs, options.linkOptions)) {
165
- findings.push(findingFromDiagnostic('links', file, cwd, diagnostic));
166
- }
167
- index = buildLinkIndex(linkInputs, options.linkOptions);
168
- refreshSummaryFindings(summaries, findings);
169
- }
140
+ const registry = await loadStudioRegistry(options.registryPath, cwd, options.includeGenericBlocks);
141
+ const sourceFiles = await Promise.all(files.map(async (file) => ({ path: file, source: await readFile(file, 'utf8') })));
142
+ const scan = scanContentProject(sourceFiles, registry, {
143
+ linkOptions: options.linkOptions,
144
+ minSectionWords: options.minSectionWords,
145
+ });
146
+ const findings = scan.findings
147
+ .map((finding) => findingFromProjectFinding(finding, cwd))
148
+ .sort(compareFindings);
149
+ const summaries = scan.files.map((file) => fileSummary(file.path, cwd, file.frontmatter, file.stats, findings.filter((finding) => finding.file === file.path), options));
150
+ const index = scan.linkIndex;
170
151
  findings.sort(compareFindings);
171
- return { files, registry, sources, frontmatter, findings, summaries, linkInputs, index };
152
+ return { files, scan, findings, summaries, index };
172
153
  }
173
- async function loadStudioRegistry(registryPath, cwd = process.cwd()) {
174
- const registry = createBlockRegistry().use(genericBlocks());
154
+ async function loadStudioRegistry(registryPath, cwd = process.cwd(), includeGenericBlocks = true) {
155
+ const registry = createBlockRegistry();
156
+ if (includeGenericBlocks)
157
+ registry.use(genericBlocks());
175
158
  if (!registryPath)
176
159
  return registry;
177
160
  const resolvedPath = isAbsolute(registryPath) ? registryPath : join(cwd, registryPath);
@@ -182,58 +165,17 @@ async function loadStudioRegistry(registryPath, cwd = process.cwd()) {
182
165
  registry.use(mod.default);
183
166
  return registry;
184
167
  }
185
- function statsFindings(file, cwd, stats, minSectionWords) {
186
- const findings = [];
187
- for (const section of stats.outline) {
188
- if (section.words < minSectionWords) {
189
- findings.push({
190
- severity: 'info',
191
- source: 'stats',
192
- code: 'CB_THIN_SECTION',
193
- file,
194
- relativePath: relativePath(cwd, file),
195
- line: section.line,
196
- column: 1,
197
- message: `section "${section.text}" has ${section.words} words`,
198
- hint: `Add detail or merge it with a nearby section. Threshold: ${minSectionWords} words.`,
199
- });
200
- }
201
- }
202
- if (stats.length.words >= BLOCKLESS_WORDS && stats.blocks.total === 0) {
203
- findings.push({
204
- severity: 'info',
205
- source: 'stats',
206
- code: 'CB_BLOCKLESS_DOCUMENT',
207
- file,
208
- relativePath: relativePath(cwd, file),
209
- message: `document has ${stats.length.words} words and no structured blocks`,
210
- hint: 'Consider a callout, steps, comparison, FAQ, or another registered block if it clarifies the page.',
211
- });
212
- }
213
- if (stats.images.missingAlt > 0) {
214
- findings.push({
215
- severity: 'info',
216
- source: 'stats',
217
- code: 'CB_IMAGE_ALT_MISSING',
218
- file,
219
- relativePath: relativePath(cwd, file),
220
- message: `${stats.images.missingAlt} image(s) are missing alt text`,
221
- hint: 'Add descriptive alt text for meaningful images; use empty alt only for decorative images.',
222
- });
223
- }
224
- return findings;
225
- }
226
- function findingFromDiagnostic(source, file, cwd, diagnostic) {
168
+ function findingFromProjectFinding(finding, cwd) {
227
169
  return {
228
- severity: diagnostic.severity,
229
- source,
230
- code: diagnostic.code,
231
- file,
232
- relativePath: relativePath(cwd, file),
233
- line: diagnostic.position.start.line,
234
- column: diagnostic.position.start.column,
235
- message: diagnostic.message,
236
- ...(diagnostic.hint ? { hint: diagnostic.hint } : {}),
170
+ severity: finding.severity,
171
+ source: finding.source,
172
+ code: finding.code,
173
+ file: finding.file,
174
+ relativePath: relativePath(cwd, finding.file),
175
+ ...(finding.line !== undefined ? { line: finding.line } : {}),
176
+ ...(finding.column !== undefined ? { column: finding.column } : {}),
177
+ message: finding.message,
178
+ ...(finding.hint ? { hint: finding.hint } : {}),
237
179
  };
238
180
  }
239
181
  function fileSummary(file, cwd, frontmatter, stats, findings, options) {
@@ -261,12 +203,6 @@ function fileSummary(file, cwd, frontmatter, stats, findings, options) {
261
203
  status: statusFor(counts),
262
204
  };
263
205
  }
264
- function refreshSummaryFindings(summaries, findings) {
265
- for (const summary of summaries) {
266
- summary.findings = summarize(findings.filter((finding) => finding.file === summary.path));
267
- summary.status = statusFor(summary.findings);
268
- }
269
- }
270
206
  function titleFor(file, frontmatter, stats) {
271
207
  return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file);
272
208
  }
@@ -298,20 +234,6 @@ function statusFor(findings) {
298
234
  return 'suggestion';
299
235
  return 'healthy';
300
236
  }
301
- function graphSummary(index) {
302
- let links = 0;
303
- for (const page of index.pages.values())
304
- links += page.linksTo.length;
305
- return {
306
- pages: index.pages.size,
307
- links,
308
- orphans: [...index.pages.values()].filter((page) => page.linkedFrom.length === 0).length,
309
- };
310
- }
311
- function hasLinkFrontmatter(inputs, configuredSlugField) {
312
- const slugField = configuredSlugField ?? 'slug';
313
- return inputs.some((input) => Object.prototype.hasOwnProperty.call(input.data, slugField));
314
- }
315
237
  function findAllowedFile(context, cwd, requestedPath) {
316
238
  return (context.files.find((file) => file === requestedPath || relativePath(cwd, file) === requestedPath) ?? null);
317
239
  }
@@ -98,6 +98,7 @@ export interface StudioGraph {
98
98
  export interface StudioOptions {
99
99
  globs: string[];
100
100
  registryPath?: string;
101
+ includeGenericBlocks?: boolean;
101
102
  cwd?: string;
102
103
  linkOptions?: LinkResolverOptions;
103
104
  minSectionWords?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","s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W,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,cAAc,GAAG,MAAM,CAAA;CAC5D;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,KAAK,EAAE,eAAe,EAAE,CAAA;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,mBAAmB,CAAA;IACjC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,iBAAiB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,SAAS,CAAC,CAAA;CAC9E;AAED,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,OAAO,CAAA;CACf"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentbit/studio",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Local read-only content studio for contentbit projects.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -48,10 +48,9 @@
48
48
  "tinyglobby": "^0.2.10",
49
49
  "tw-animate-css": "^1.4.0",
50
50
  "vite": "^8",
51
- "@contentbit/blocks": "0.4.1",
52
- "@contentbit/core": "0.4.1",
53
- "@contentbit/html": "0.4.1",
54
- "@contentbit/react": "0.4.1"
51
+ "@contentbit/blocks": "0.5.0",
52
+ "@contentbit/core": "0.5.0",
53
+ "@contentbit/react": "0.5.0"
55
54
  },
56
55
  "devDependencies": {
57
56
  "@testing-library/dom": "^10.4.1",
@@ -45,6 +45,7 @@ export async function startStudio(options: StartStudioOptions): Promise<StudioSe
45
45
  globs: options.globs,
46
46
  cwd,
47
47
  registryPath: options.registryPath,
48
+ includeGenericBlocks: options.includeGenericBlocks,
48
49
  linkOptions: options.linkOptions,
49
50
  minSectionWords: options.minSectionWords,
50
51
  }
@@ -86,20 +87,39 @@ async function loadProjectComponents(
86
87
  vite: ViteDevServer,
87
88
  options: { cwd: string; registryPath?: string },
88
89
  ): Promise<Record<string, BlockComponent> | undefined> {
90
+ const merged: Record<string, BlockComponent> = {}
89
91
  for (const candidate of componentCandidates(options)) {
90
- if (!existsSync(candidate)) continue
91
- const mod = (await vite.ssrLoadModule(candidate)) as {
92
+ if (!existsSync(candidate.path)) continue
93
+ let mod: {
94
+ styledComponents?: Record<string, BlockComponent>
92
95
  blockComponents?: Record<string, BlockComponent>
93
96
  components?: Record<string, BlockComponent>
94
97
  default?: Record<string, BlockComponent>
95
98
  }
96
- const components = mod.blockComponents ?? mod.components ?? mod.default
97
- if (components && typeof components === 'object') return components
99
+ try {
100
+ mod = (await vite.ssrLoadModule(candidate.path)) as typeof mod
101
+ } catch {
102
+ if (!candidate.bestEffort)
103
+ throw new Error(`Failed to load block components: ${candidate.path}`)
104
+ continue
105
+ }
106
+ const maps = [mod.styledComponents, mod.blockComponents, mod.components, mod.default]
107
+ for (const components of maps) {
108
+ if (components && typeof components === 'object') Object.assign(merged, components)
109
+ }
98
110
  }
99
- return undefined
111
+ return Object.keys(merged).length > 0 ? merged : undefined
112
+ }
113
+
114
+ interface ComponentCandidate {
115
+ path: string
116
+ bestEffort: boolean
100
117
  }
101
118
 
102
- function componentCandidates(options: { cwd: string; registryPath?: string }): string[] {
119
+ function componentCandidates(options: {
120
+ cwd: string
121
+ registryPath?: string
122
+ }): ComponentCandidate[] {
103
123
  const dirs = new Set<string>()
104
124
  if (options.registryPath) {
105
125
  const registryPath = isAbsolute(options.registryPath)
@@ -109,14 +129,21 @@ function componentCandidates(options: { cwd: string; registryPath?: string }): s
109
129
  }
110
130
  dirs.add(join(options.cwd, 'blocks'))
111
131
 
112
- return [...dirs].flatMap((dir) => [
113
- join(dir, 'components.tsx'),
114
- join(dir, 'components.ts'),
115
- join(dir, 'preview.tsx'),
116
- join(dir, 'preview.ts'),
117
- join(dir, 'renderers.tsx'),
118
- join(dir, 'renderers.ts'),
119
- ])
132
+ const rendererCandidates = [
133
+ join(options.cwd, 'components/content-blocks/content-renderer.tsx'),
134
+ join(options.cwd, 'src/components/content-blocks/content-renderer.tsx'),
135
+ ].map((path) => ({ path, bestEffort: true }))
136
+ const blockComponentCandidates = [...dirs].flatMap((dir) =>
137
+ [
138
+ join(dir, 'components.tsx'),
139
+ join(dir, 'components.ts'),
140
+ join(dir, 'preview.tsx'),
141
+ join(dir, 'preview.ts'),
142
+ join(dir, 'renderers.tsx'),
143
+ join(dir, 'renderers.ts'),
144
+ ].map((path) => ({ path, bestEffort: false })),
145
+ )
146
+ return [...rendererCandidates, ...blockComponentCandidates]
120
147
  }
121
148
 
122
149
  function studioApiPlugin(options: StudioOptions): Plugin {
@@ -1,5 +1,5 @@
1
1
  import type { BlockComponent } from '@contentbit/react'
2
- import type { DocumentNode } from '@contentbit/core'
2
+ import type { ValidatedDocumentNode } from '@contentbit/core'
3
3
  import type { ComponentType } from 'react'
4
4
 
5
5
  import { ContentBlocks } from '@contentbit/react'
@@ -14,8 +14,9 @@ interface FallbackProps {
14
14
  }
15
15
 
16
16
  export function renderStudioPreview(
17
- document: DocumentNode,
17
+ document: ValidatedDocumentNode,
18
18
  components: Record<string, BlockComponent> = {},
19
+ _options: { includeGenericComponents?: boolean } = {},
19
20
  ): string {
20
21
  return renderToStaticMarkup(
21
22
  createElement(ContentBlocks, {
@@ -152,6 +152,48 @@ Custom block content for the local registry.
152
152
  expect(document?.previewHtml).toContain('<p>Custom block content for the local registry.</p>')
153
153
  })
154
154
 
155
+ test('scanDocument can let a project registry own generic block names', async () => {
156
+ const dir = await fixture({
157
+ 'blocks/registry.mjs': `import { defineBlock, markdownBody } from '@contentbit/core'
158
+ import { z } from 'zod'
159
+
160
+ const quickRef = defineBlock({
161
+ name: 'quick-ref',
162
+ props: z.object({}),
163
+ content: markdownBody({ minLength: 3 }),
164
+ })
165
+
166
+ export default [quickRef]
167
+ `,
168
+ 'content/a.md': `---
169
+ slug: alpha
170
+ ---
171
+
172
+ # Alpha
173
+
174
+ :::quick-ref
175
+ Project-owned quick reference content.
176
+ :::
177
+ `,
178
+ })
179
+ await linkContentbitCore(dir)
180
+
181
+ const document = await scanDocument(
182
+ {
183
+ globs: ['content/*.md'],
184
+ cwd: dir,
185
+ registryPath: 'blocks/registry.mjs',
186
+ includeGenericBlocks: false,
187
+ minSectionWords: 0,
188
+ },
189
+ 'content/a.md',
190
+ )
191
+
192
+ expect(document?.findings.filter((finding) => finding.source === 'validation')).toEqual([])
193
+ expect(document?.file.blockNames['quick-ref']).toBe(1)
194
+ expect(document?.previewHtml).toContain('data-cb-custom="quick-ref"')
195
+ })
196
+
155
197
  test('scanGraph returns resolved and unresolved edges', async () => {
156
198
  const dir = await fixture({
157
199
  'content/a.md': '---\nslug: alpha\nlinksTo:\n - beta\n - missing\n---\n\n# Alpha\n\nBody.',
@@ -1,17 +1,12 @@
1
1
  import { genericBlocks } from '@contentbit/blocks'
2
2
  import {
3
- analyzeDocument,
4
- buildLinkIndex,
5
3
  createBlockRegistry,
6
- extractFrontmatter,
7
- parseDocument,
8
- stripFrontmatter,
9
- validateDocument,
10
- validateLinks,
4
+ scanContentProject,
11
5
  type BlockDefinition,
12
6
  type BlockRegistry,
13
- type Diagnostic,
14
- type LinkInput,
7
+ type ContentProjectFinding,
8
+ type ContentProjectScan,
9
+ type DocumentStats,
15
10
  } from '@contentbit/core'
16
11
  import { readFile } from 'node:fs/promises'
17
12
  import { basename, isAbsolute, join, relative } from 'node:path'
@@ -32,18 +27,12 @@ import type {
32
27
  StudioStatus,
33
28
  } from './types.js'
34
29
 
35
- const DEFAULT_MIN_SECTION_WORDS = 25
36
- const BLOCKLESS_WORDS = 250
37
-
38
30
  interface ScanContext {
39
31
  files: string[]
40
- registry: BlockRegistry
41
- sources: Map<string, string>
42
- frontmatter: Map<string, Record<string, unknown>>
32
+ scan: ContentProjectScan
43
33
  findings: StudioFinding[]
44
34
  summaries: StudioFileSummary[]
45
- linkInputs: LinkInput[]
46
- index?: ReturnType<typeof buildLinkIndex>
35
+ index?: ContentProjectScan['linkIndex']
47
36
  }
48
37
 
49
38
  export async function scanProject(options: StudioOptions): Promise<StudioProject> {
@@ -88,7 +77,7 @@ export async function scanProject(options: StudioOptions): Promise<StudioProject
88
77
  withPrimary,
89
78
  withSecondary,
90
79
  },
91
- ...(context.index ? { linkGraph: graphSummary(context.index) } : {}),
80
+ ...(context.scan.linkGraph ? { linkGraph: context.scan.linkGraph } : {}),
92
81
  findings: context.findings,
93
82
  }
94
83
  }
@@ -100,25 +89,25 @@ export async function scanDocument(
100
89
  const context = await scanContext(options)
101
90
  const file = findAllowedFile(context, options.cwd ?? process.cwd(), requestedPath)
102
91
  if (!file) return null
103
- const source = context.sources.get(file)!
92
+ const scanned = context.scan.files.find((item) => item.path === file)
93
+ if (!scanned) return null
104
94
  const summary = context.summaries.find((item) => item.path === file)
105
95
  if (!summary) return null
106
96
 
107
- const validation = validateDocument(parseDocument(stripFrontmatter(source)), context.registry)
108
97
  const previewHtml = renderStudioPreview(
109
- validation.document,
98
+ scanned.validation.document,
110
99
  (await options.previewComponents?.()) ?? {},
100
+ { includeGenericComponents: options.includeGenericBlocks !== false },
111
101
  )
112
- const stats = analyzeDocument(source, { path: file })
113
102
  const page = context.index
114
103
  ? [...context.index.pages.values()].find((entry) => entry.path === file)
115
104
  : undefined
116
105
 
117
106
  return {
118
107
  file: summary,
119
- source,
120
- frontmatter: context.frontmatter.get(file) ?? {},
121
- stats,
108
+ source: scanned.source,
109
+ frontmatter: scanned.frontmatter,
110
+ stats: scanned.stats,
122
111
  findings: context.findings.filter((finding) => finding.file === file),
123
112
  linksTo: page ? (page.linkRefs.length > 0 ? page.linkRefs : page.linksTo) : [],
124
113
  linkedFrom: page
@@ -190,59 +179,40 @@ async function scanContext(options: StudioOptions): Promise<ScanContext> {
190
179
  const files = (await glob(options.globs, { absolute: true, cwd })).sort()
191
180
  if (files.length === 0) throw new Error(`studio: no files matched ${options.globs.join(' ')}`)
192
181
 
193
- const registry = await loadStudioRegistry(options.registryPath, cwd)
194
- const sources = new Map<string, string>()
195
- const frontmatter = new Map<string, Record<string, unknown>>()
196
- const findings: StudioFinding[] = []
197
- const summaries: StudioFileSummary[] = []
198
- const linkInputs: LinkInput[] = []
199
-
200
- for (const file of files) {
201
- const source = await readFile(file, 'utf8')
202
- const fm = extractFrontmatter(source)?.data ?? {}
203
- sources.set(file, source)
204
- frontmatter.set(file, fm)
205
- linkInputs.push({ path: file, data: fm })
206
-
207
- const validation = validateDocument(parseDocument(stripFrontmatter(source)), registry)
208
- for (const diagnostic of validation.diagnostics) {
209
- findings.push(findingFromDiagnostic('validation', file, cwd, diagnostic))
210
- }
211
-
212
- const stats = analyzeDocument(source, { path: file })
213
- findings.push(
214
- ...statsFindings(file, cwd, stats, options.minSectionWords ?? DEFAULT_MIN_SECTION_WORDS),
215
- )
216
- summaries.push(
217
- fileSummary(
218
- file,
219
- cwd,
220
- fm,
221
- stats,
222
- findings.filter((finding) => finding.file === file),
223
- options,
224
- ),
225
- )
226
- }
227
-
228
- let index: ScanContext['index']
229
- if (hasLinkFrontmatter(linkInputs, options.linkOptions?.slugField)) {
230
- for (const { file, diagnostic } of validateLinks(linkInputs, options.linkOptions)) {
231
- findings.push(findingFromDiagnostic('links', file, cwd, diagnostic))
232
- }
233
- index = buildLinkIndex(linkInputs, options.linkOptions)
234
- refreshSummaryFindings(summaries, findings)
235
- }
182
+ const registry = await loadStudioRegistry(options.registryPath, cwd, options.includeGenericBlocks)
183
+ const sourceFiles = await Promise.all(
184
+ files.map(async (file) => ({ path: file, source: await readFile(file, 'utf8') })),
185
+ )
186
+ const scan = scanContentProject(sourceFiles, registry, {
187
+ linkOptions: options.linkOptions,
188
+ minSectionWords: options.minSectionWords,
189
+ })
190
+ const findings = scan.findings
191
+ .map((finding) => findingFromProjectFinding(finding, cwd))
192
+ .sort(compareFindings)
193
+ const summaries = scan.files.map((file) =>
194
+ fileSummary(
195
+ file.path,
196
+ cwd,
197
+ file.frontmatter,
198
+ file.stats,
199
+ findings.filter((finding) => finding.file === file.path),
200
+ options,
201
+ ),
202
+ )
236
203
 
204
+ const index = scan.linkIndex
237
205
  findings.sort(compareFindings)
238
- return { files, registry, sources, frontmatter, findings, summaries, linkInputs, index }
206
+ return { files, scan, findings, summaries, index }
239
207
  }
240
208
 
241
209
  async function loadStudioRegistry(
242
210
  registryPath?: string,
243
211
  cwd = process.cwd(),
212
+ includeGenericBlocks = true,
244
213
  ): Promise<BlockRegistry> {
245
- const registry = createBlockRegistry().use(genericBlocks())
214
+ const registry = createBlockRegistry()
215
+ if (includeGenericBlocks) registry.use(genericBlocks())
246
216
  if (!registryPath) return registry
247
217
 
248
218
  const resolvedPath = isAbsolute(registryPath) ? registryPath : join(cwd, registryPath)
@@ -258,69 +228,17 @@ async function loadStudioRegistry(
258
228
  return registry
259
229
  }
260
230
 
261
- function statsFindings(
262
- file: string,
263
- cwd: string,
264
- stats: ReturnType<typeof analyzeDocument>,
265
- minSectionWords: number,
266
- ): StudioFinding[] {
267
- const findings: StudioFinding[] = []
268
- for (const section of stats.outline) {
269
- if (section.words < minSectionWords) {
270
- findings.push({
271
- severity: 'info',
272
- source: 'stats',
273
- code: 'CB_THIN_SECTION',
274
- file,
275
- relativePath: relativePath(cwd, file),
276
- line: section.line,
277
- column: 1,
278
- message: `section "${section.text}" has ${section.words} words`,
279
- hint: `Add detail or merge it with a nearby section. Threshold: ${minSectionWords} words.`,
280
- })
281
- }
282
- }
283
- if (stats.length.words >= BLOCKLESS_WORDS && stats.blocks.total === 0) {
284
- findings.push({
285
- severity: 'info',
286
- source: 'stats',
287
- code: 'CB_BLOCKLESS_DOCUMENT',
288
- file,
289
- relativePath: relativePath(cwd, file),
290
- message: `document has ${stats.length.words} words and no structured blocks`,
291
- hint: 'Consider a callout, steps, comparison, FAQ, or another registered block if it clarifies the page.',
292
- })
293
- }
294
- if (stats.images.missingAlt > 0) {
295
- findings.push({
296
- severity: 'info',
297
- source: 'stats',
298
- code: 'CB_IMAGE_ALT_MISSING',
299
- file,
300
- relativePath: relativePath(cwd, file),
301
- message: `${stats.images.missingAlt} image(s) are missing alt text`,
302
- hint: 'Add descriptive alt text for meaningful images; use empty alt only for decorative images.',
303
- })
304
- }
305
- return findings
306
- }
307
-
308
- function findingFromDiagnostic(
309
- source: 'validation' | 'links',
310
- file: string,
311
- cwd: string,
312
- diagnostic: Diagnostic,
313
- ): StudioFinding {
231
+ function findingFromProjectFinding(finding: ContentProjectFinding, cwd: string): StudioFinding {
314
232
  return {
315
- severity: diagnostic.severity,
316
- source,
317
- code: diagnostic.code,
318
- file,
319
- relativePath: relativePath(cwd, file),
320
- line: diagnostic.position.start.line,
321
- column: diagnostic.position.start.column,
322
- message: diagnostic.message,
323
- ...(diagnostic.hint ? { hint: diagnostic.hint } : {}),
233
+ severity: finding.severity,
234
+ source: finding.source,
235
+ code: finding.code,
236
+ file: finding.file,
237
+ relativePath: relativePath(cwd, finding.file),
238
+ ...(finding.line !== undefined ? { line: finding.line } : {}),
239
+ ...(finding.column !== undefined ? { column: finding.column } : {}),
240
+ message: finding.message,
241
+ ...(finding.hint ? { hint: finding.hint } : {}),
324
242
  }
325
243
  }
326
244
 
@@ -328,7 +246,7 @@ function fileSummary(
328
246
  file: string,
329
247
  cwd: string,
330
248
  frontmatter: Record<string, unknown>,
331
- stats: ReturnType<typeof analyzeDocument>,
249
+ stats: DocumentStats,
332
250
  findings: StudioFinding[],
333
251
  options: StudioOptions,
334
252
  ): StudioFileSummary {
@@ -357,17 +275,10 @@ function fileSummary(
357
275
  }
358
276
  }
359
277
 
360
- function refreshSummaryFindings(summaries: StudioFileSummary[], findings: StudioFinding[]): void {
361
- for (const summary of summaries) {
362
- summary.findings = summarize(findings.filter((finding) => finding.file === summary.path))
363
- summary.status = statusFor(summary.findings)
364
- }
365
- }
366
-
367
278
  function titleFor(
368
279
  file: string,
369
280
  frontmatter: Record<string, unknown>,
370
- stats: ReturnType<typeof analyzeDocument>,
281
+ stats: DocumentStats,
371
282
  ): string {
372
283
  return stringValue(frontmatter.title) ?? stats.outline[0]?.text ?? basename(file)
373
284
  }
@@ -399,21 +310,6 @@ function statusFor(findings: StudioFileSummary['findings']): StudioStatus {
399
310
  return 'healthy'
400
311
  }
401
312
 
402
- function graphSummary(index: NonNullable<ScanContext['index']>): StudioProject['linkGraph'] {
403
- let links = 0
404
- for (const page of index.pages.values()) links += page.linksTo.length
405
- return {
406
- pages: index.pages.size,
407
- links,
408
- orphans: [...index.pages.values()].filter((page) => page.linkedFrom.length === 0).length,
409
- }
410
- }
411
-
412
- function hasLinkFrontmatter(inputs: LinkInput[], configuredSlugField: string | undefined): boolean {
413
- const slugField = configuredSlugField ?? 'slug'
414
- return inputs.some((input) => Object.prototype.hasOwnProperty.call(input.data, slugField))
415
- }
416
-
417
313
  function findAllowedFile(context: ScanContext, cwd: string, requestedPath: string): string | null {
418
314
  return (
419
315
  context.files.find(
@@ -96,6 +96,7 @@ export interface StudioGraph {
96
96
  export interface StudioOptions {
97
97
  globs: string[]
98
98
  registryPath?: string
99
+ includeGenericBlocks?: boolean
99
100
  cwd?: string
100
101
  linkOptions?: LinkResolverOptions
101
102
  minSectionWords?: number
package/vite.config.ts CHANGED
@@ -2,9 +2,14 @@ import { defineConfig } from 'vite'
2
2
  import { tanstackStart } from '@tanstack/react-start/plugin/vite'
3
3
  import viteReact from '@vitejs/plugin-react'
4
4
  import tailwindcss from '@tailwindcss/vite'
5
+ import { fileURLToPath } from 'node:url'
5
6
 
6
7
  const config = defineConfig({
7
- resolve: { tsconfigPaths: true },
8
+ resolve: {
9
+ alias: {
10
+ '@': fileURLToPath(new URL('./src', import.meta.url)),
11
+ },
12
+ },
8
13
  plugins: [tailwindcss(), tanstackStart(), viteReact()],
9
14
  })
10
15