@blogmcp/mdx-schema 0.1.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.
Files changed (41) hide show
  1. package/dist/checkPin.d.ts +48 -0
  2. package/dist/checkPin.js +139 -0
  3. package/dist/checkPin.js.map +1 -0
  4. package/dist/composables/useMdxParsing.d.ts +71 -0
  5. package/dist/composables/useMdxParsing.js +239 -0
  6. package/dist/composables/useMdxParsing.js.map +1 -0
  7. package/dist/index.d.ts +21 -0
  8. package/dist/index.js +22 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/metadata/customComponents.d.ts +128 -0
  11. package/dist/metadata/customComponents.js +301 -0
  12. package/dist/metadata/customComponents.js.map +1 -0
  13. package/dist/metadata/index.d.ts +24 -0
  14. package/dist/metadata/index.js +427 -0
  15. package/dist/metadata/index.js.map +1 -0
  16. package/dist/metadata/validate.d.ts +46 -0
  17. package/dist/metadata/validate.js +95 -0
  18. package/dist/metadata/validate.js.map +1 -0
  19. package/dist/prepareProps.d.ts +42 -0
  20. package/dist/prepareProps.js +177 -0
  21. package/dist/prepareProps.js.map +1 -0
  22. package/dist/styles/index.d.ts +203 -0
  23. package/dist/styles/index.js +162 -0
  24. package/dist/styles/index.js.map +1 -0
  25. package/dist/types/index.d.ts +421 -0
  26. package/dist/types/index.js +25 -0
  27. package/dist/types/index.js.map +1 -0
  28. package/dist/version.d.ts +23 -0
  29. package/dist/version.js +23 -0
  30. package/dist/version.js.map +1 -0
  31. package/package.json +80 -0
  32. package/src/checkPin.ts +163 -0
  33. package/src/composables/useMdxParsing.ts +248 -0
  34. package/src/index.ts +22 -0
  35. package/src/metadata/customComponents.ts +360 -0
  36. package/src/metadata/index.ts +437 -0
  37. package/src/metadata/validate.ts +153 -0
  38. package/src/prepareProps.ts +219 -0
  39. package/src/styles/index.ts +196 -0
  40. package/src/types/index.ts +469 -0
  41. package/src/version.ts +24 -0
@@ -0,0 +1,469 @@
1
+ /**
2
+ * Shared Types for MDX Components
3
+ *
4
+ * These types are used by both edit and render components.
5
+ */
6
+
7
+ /**
8
+ * Callout component types
9
+ */
10
+ export type CalloutType = 'info' | 'warning' | 'tip' | 'danger'
11
+
12
+ export interface CalloutProps {
13
+ /** The callout type determines styling and icon */
14
+ type?: CalloutType
15
+ }
16
+
17
+ /**
18
+ * CodeBlock component types
19
+ */
20
+ export interface CodeBlockProps {
21
+ /** Programming language for syntax highlighting */
22
+ language?: string
23
+ /** Optional file name/title displayed in header */
24
+ title?: string
25
+ /** Whether to show line numbers (not implemented in all variants) */
26
+ showLineNumbers?: boolean
27
+ }
28
+
29
+ /**
30
+ * Gallery component types
31
+ */
32
+ export interface MediaObject {
33
+ src: string
34
+ alt: string
35
+ description?: string
36
+ title?: string
37
+ type?: 'image' | 'video'
38
+ width?: number
39
+ height?: number
40
+ }
41
+
42
+ export type GalleryImage = string | MediaObject
43
+
44
+ /** How a gallery image fills its tile. */
45
+ export type GalleryFit = 'cover' | 'contain'
46
+
47
+ export interface GalleryProps {
48
+ /** Array of image URLs or MediaObjects to display */
49
+ images: GalleryImage[]
50
+ /** Number of columns (1-4) */
51
+ columns?: 1 | 2 | 3 | 4
52
+ /** Gap between images (Tailwind scale) */
53
+ gap?: number
54
+ /**
55
+ * CSS aspect-ratio for each tile (e.g. "1", "16/9", "775/308"), controlling
56
+ * tile height. The literal "auto" drops the fixed box so images render at
57
+ * their natural height (full width, proportional). Default "1" (square).
58
+ */
59
+ aspectRatio?: string
60
+ /**
61
+ * How the image fills its tile: "cover" crops to fill (default), "contain"
62
+ * shows the whole image letterboxed (no crop). Ignored when aspectRatio="auto".
63
+ */
64
+ fit?: GalleryFit
65
+ /**
66
+ * CSS object-position selecting the region of interest shown when cropping
67
+ * (e.g. "center", "top", "50% 30%"). Only meaningful with fit="cover" and a
68
+ * fixed aspect-ratio. Default "center".
69
+ */
70
+ position?: string
71
+ }
72
+
73
+ /**
74
+ * YouTube component types
75
+ */
76
+ export interface YouTubeProps {
77
+ /** YouTube video ID */
78
+ id: string
79
+ /** Optional video title displayed below embed */
80
+ title?: string
81
+ }
82
+
83
+ /**
84
+ * AudioPlayer component types
85
+ */
86
+ export interface AudioPlayerProps {
87
+ /** Media slug — resolves to /api/media/file/{slug} */
88
+ slug: string
89
+ /** Displayed title */
90
+ title?: string
91
+ /** Show collapsible transcript */
92
+ showTranscription?: boolean
93
+ }
94
+
95
+ /**
96
+ * Common component variant type
97
+ */
98
+ export type ComponentVariant = 'default' | 'minimal' | 'accent' | string
99
+
100
+ /**
101
+ * Blog configuration types
102
+ */
103
+ export interface ComponentStyleConfig {
104
+ [key: string]: string | number | boolean
105
+ }
106
+
107
+ export interface ComponentConfig {
108
+ /** Which render variant to use */
109
+ variant: ComponentVariant
110
+ /** Style overrides passed as props */
111
+ styles?: ComponentStyleConfig
112
+ }
113
+
114
+ export interface BlogComponentsConfig {
115
+ callout?: ComponentConfig
116
+ codeblock?: ComponentConfig
117
+ gallery?: ComponentConfig
118
+ youtube?: ComponentConfig
119
+ audioplayer?: ComponentConfig
120
+ }
121
+
122
+ export interface BlogContentTranslation {
123
+ [locale: string]: string
124
+ }
125
+
126
+ /**
127
+ * How readers browse the blog's content. Two organization models, the
128
+ * customer's choice (see docs: concepts/organizing-content):
129
+ * - `menu` — hierarchy only: the curated navigation menu (docs-style sidebar).
130
+ * One home per article. Best for knowledge bases / docs.
131
+ * - `tags` — flat only: many-to-many tags + `/topics/<slug>` archives.
132
+ * Best for blogs/news where articles span multiple themes.
133
+ * - `both` — show both browses (default for the reference blog).
134
+ */
135
+ export type ContentOrganizationMode = 'menu' | 'tags' | 'both'
136
+
137
+ export interface BlogOrganizationConfig {
138
+ /** Reader-facing browse model. Defaults to `both` when unset. */
139
+ mode?: ContentOrganizationMode
140
+ }
141
+
142
+ export interface BlogConfig {
143
+ components: BlogComponentsConfig
144
+ theme?: {
145
+ accent?: string
146
+ accentHover?: string
147
+ accentLight?: string
148
+ [key: string]: string | undefined
149
+ }
150
+ content?: Record<string, BlogContentTranslation>
151
+ /** Which content-organization model the reader-facing blog presents. */
152
+ organization?: BlogOrganizationConfig
153
+ }
154
+
155
+ /**
156
+ * MDX parsed content types (for MdxPreview)
157
+ */
158
+ export interface ParsedHtmlContent {
159
+ type: 'html'
160
+ content: string
161
+ }
162
+
163
+ export interface ParsedComponentContent {
164
+ type: 'component'
165
+ name: string
166
+ props: Record<string, unknown>
167
+ children?: string
168
+ }
169
+
170
+ export type ParsedContent = ParsedHtmlContent | ParsedComponentContent
171
+
172
+ /**
173
+ * Snapshot of a prop's shape captured on a `propRemoved` deprecation
174
+ * entry at removal time. Lets a codemod author working months later
175
+ * reconstruct the prop's original contract without spelunking baseline
176
+ * history. CI-validated against the baseline shape via the
177
+ * `propRemovedShapeMismatch` rule — drift is rejected.
178
+ *
179
+ * Intentionally a structural subset of `PropMetadata` rather than a
180
+ * full clone — fields like `name` and `addedIn` are already implied by
181
+ * the entry's `prop` field and the SCHEMA_VERSION at which the prop
182
+ * existed, so omitting them avoids redundancy.
183
+ */
184
+ export interface RemovedPropShape {
185
+ type: string
186
+ required: boolean
187
+ default?: string
188
+ enum?: string[]
189
+ numericRange?: [number, number]
190
+ description?: string
191
+ }
192
+
193
+ /**
194
+ * Schema-version metadata for a single component-level change.
195
+ *
196
+ * Each entry is a tagged discriminated union; the `kind` field selects
197
+ * the shape. The classifier in `test/compat.spec.ts` consumes these
198
+ * entries when matching a baseline-vs-current diff against the
199
+ * 3-tier rubric.
200
+ *
201
+ * - `propRename` — Tier 2 (soft, shimmable). Old prop name is
202
+ * silently aliased to the new name at render time
203
+ * by `prepareProps`. Removed at `removeIn`.
204
+ * - `enumValueRename` — Tier 2 (soft, shimmable). Old enum values are
205
+ * rewritten to new ones via the `valueAliases`
206
+ * map by `prepareProps`. Removed at `removeIn`.
207
+ * - `propRemoved` — Tier 3 (hard). A codemod under `codemod` must
208
+ * already have rewritten stored content; the
209
+ * entry exists for tracking + debug logging when
210
+ * the prop is still present on rendered nodes
211
+ * (signals a tenant on a stale `schema_version`).
212
+ * Carries `removedShape` — a snapshot of the
213
+ * prop's metadata at removal time so codemod
214
+ * authors months later don't have to spelunk
215
+ * baseline history to reconstruct the original
216
+ * contract. CI validates the snapshot against
217
+ * the baseline shape.
218
+ * - `propBecameRequired` — Tier 3 (hard). Used both when a NEW required
219
+ * prop is added and when an existing optional
220
+ * prop flips to required. A backfill codemod
221
+ * under `codemod` populates stored content;
222
+ * `defaultValue` is the runtime fallback the
223
+ * shim injects when stored content omits the
224
+ * prop (e.g. legacy article not yet migrated).
225
+ * Replaces the historical overload of
226
+ * `propRemoved` for required-flips, which had
227
+ * time-bomb semantics (the propRemoved arm
228
+ * logged on every render of a still-present
229
+ * prop).
230
+ * - `defaultChangeAccepted` — Tier 1 release-notes-only acknowledgement
231
+ * that a prop default changed and authors have
232
+ * opted to accept silent visual drift (no codemod
233
+ * is technically required — articles that omitted
234
+ * the prop will render with the new default).
235
+ * Replaces the historical `codemod:
236
+ * 'release-notes-only'` magic string on
237
+ * `propRemoved`.
238
+ * - `componentStructureChange` — Tier 3 acknowledgement that a
239
+ * component's `hasChildren` or `selfClosing`
240
+ * flipped. Authors MUST point at a codemod (or
241
+ * `releaseNotesOnly: true` if they explicitly
242
+ * accept the break) — the rewrite converts
243
+ * `<X />` ↔ `<X></X>` in stored MDX.
244
+ *
245
+ * All kinds carry `message` — the human-readable explanation
246
+ * shipped to dev-mode console logs. All kinds use `removeIn`
247
+ * (not `removedIn`) for naming consistency — the field marks the
248
+ * SCHEMA_VERSION at which the artefact disappears from the live
249
+ * schema. CI-enforced by the `removeInMissed` rule.
250
+ */
251
+ export type DeprecationEntry =
252
+ | {
253
+ kind: 'propRename'
254
+ /** SCHEMA_VERSION at which the rename was introduced */
255
+ since: string
256
+ /** SCHEMA_VERSION at which the alias must disappear (CI-enforced by `removeInMissed`) */
257
+ removeIn: string
258
+ /** Old prop name as it appears in stored MDX content */
259
+ prop: string
260
+ /** Current prop name in the component */
261
+ aliasFor: string
262
+ /** Human-readable message logged once per process in dev mode */
263
+ message: string
264
+ }
265
+ | {
266
+ kind: 'enumValueRename'
267
+ since: string
268
+ removeIn: string
269
+ /** Prop whose enum values are being remapped */
270
+ prop: string
271
+ /** Map of old → new enum values. Values not in the map pass through unchanged. */
272
+ valueAliases: Record<string, string>
273
+ message: string
274
+ }
275
+ | {
276
+ kind: 'propRemoved'
277
+ since: string
278
+ /**
279
+ * SCHEMA_VERSION at which the prop was removed from the component.
280
+ * Renamed from `removedIn` for naming consistency with all other
281
+ * deprecation kinds (CI-enforced by `removeInMissed`).
282
+ */
283
+ removeIn: string
284
+ /** Removed prop name (used by `prepareProps` to detect stale content + log) */
285
+ prop: string
286
+ /**
287
+ * Snapshot of the prop's shape at the time of removal. Six months
288
+ * after removal a codemod author can read this directly instead of
289
+ * spelunking baseline history. The CI classifier validates that
290
+ * this snapshot matches the baseline shape — drift is rejected by
291
+ * the `propRemovedShapeMismatch` rule.
292
+ */
293
+ removedShape: RemovedPropShape
294
+ /** Path under `packages/mdx-codemods/migrations/` to the migration that rewrites stored content */
295
+ codemod: string
296
+ message: string
297
+ }
298
+ | {
299
+ kind: 'propBecameRequired'
300
+ /**
301
+ * SCHEMA_VERSION at which the prop became (or was introduced as)
302
+ * required. Used to satisfy both `propAdded_required` (brand-new
303
+ * required prop) and `propRequiredFlipped` (existing optional →
304
+ * required) classifier rules.
305
+ */
306
+ since: string
307
+ /**
308
+ * SCHEMA_VERSION at which the shim's safety-net default stops
309
+ * being injected. Usually == `since` for a one-step rollout, or
310
+ * one major later for a grace period. CI-enforced by
311
+ * `removeInMissed`.
312
+ */
313
+ removeIn: string
314
+ /** Prop name (must match a prop in the component's `props[]`) */
315
+ prop: string
316
+ /** Path under `packages/mdx-codemods/migrations/` to the backfill codemod */
317
+ codemod: string
318
+ /**
319
+ * Runtime value injected by `prepareProps` when stored content
320
+ * omits the prop (e.g. a legacy article that the codemod hasn't
321
+ * touched yet, or a tenant lagging on `schema_version`). Must be
322
+ * a JSON-serializable value the receiving component can render.
323
+ */
324
+ defaultValue: unknown
325
+ message: string
326
+ }
327
+ | {
328
+ kind: 'defaultChangeAccepted'
329
+ /** SCHEMA_VERSION at which the default change was accepted */
330
+ since: string
331
+ /** Prop whose default changed */
332
+ prop: string
333
+ /** Human-readable explanation of the visual drift, surfaces in release notes */
334
+ message: string
335
+ }
336
+ | {
337
+ kind: 'componentStructureChange'
338
+ /** SCHEMA_VERSION at which the structure flipped */
339
+ since: string
340
+ /**
341
+ * Which structural field flipped — used by the classifier to
342
+ * match the diff. `hasChildren` covers true↔false, `selfClosing`
343
+ * covers true↔false, `both` covers a paired flip in one bump.
344
+ */
345
+ field: 'hasChildren' | 'selfClosing' | 'both'
346
+ /**
347
+ * Path under `packages/mdx-codemods/migrations/` to the rewrite
348
+ * that converts stored `<X />` ↔ `<X></X>`. Mutually exclusive
349
+ * with `releaseNotesOnly`.
350
+ */
351
+ codemod?: string
352
+ /**
353
+ * If true, authors explicitly accept the structural drift and no
354
+ * codemod is required. Use sparingly — stored MDX may stop
355
+ * rendering until articles are re-saved.
356
+ */
357
+ releaseNotesOnly?: boolean
358
+ message: string
359
+ }
360
+
361
+ /** Type-guard helpers — used by `prepareProps` and the CI classifier. */
362
+ export function isPropRenameEntry(
363
+ entry: DeprecationEntry,
364
+ ): entry is Extract<DeprecationEntry, { kind: 'propRename' }> {
365
+ return entry.kind === 'propRename'
366
+ }
367
+
368
+ export function isEnumValueRenameEntry(
369
+ entry: DeprecationEntry,
370
+ ): entry is Extract<DeprecationEntry, { kind: 'enumValueRename' }> {
371
+ return entry.kind === 'enumValueRename'
372
+ }
373
+
374
+ export function isPropRemovedEntry(
375
+ entry: DeprecationEntry,
376
+ ): entry is Extract<DeprecationEntry, { kind: 'propRemoved' }> {
377
+ return entry.kind === 'propRemoved'
378
+ }
379
+
380
+ export function isPropBecameRequiredEntry(
381
+ entry: DeprecationEntry,
382
+ ): entry is Extract<DeprecationEntry, { kind: 'propBecameRequired' }> {
383
+ return entry.kind === 'propBecameRequired'
384
+ }
385
+
386
+ export function isDefaultChangeAcceptedEntry(
387
+ entry: DeprecationEntry,
388
+ ): entry is Extract<DeprecationEntry, { kind: 'defaultChangeAccepted' }> {
389
+ return entry.kind === 'defaultChangeAccepted'
390
+ }
391
+
392
+ export function isComponentStructureChangeEntry(
393
+ entry: DeprecationEntry,
394
+ ): entry is Extract<DeprecationEntry, { kind: 'componentStructureChange' }> {
395
+ return entry.kind === 'componentStructureChange'
396
+ }
397
+
398
+ /**
399
+ * Hand-curated description of one prop on a component.
400
+ *
401
+ * `addedIn` is optional; when omitted, `checkPin()` and the md-editor
402
+ * pin gate treat the prop as having been introduced at the component's
403
+ * `addedIn` (i.e. the prop has always existed on the component). Set
404
+ * `addedIn` explicitly only when the prop was added in a later
405
+ * SCHEMA_VERSION than the component itself.
406
+ *
407
+ * The classifier's `propAdded` rules REQUIRE explicit `addedIn` on any
408
+ * prop that did not exist in the previous baseline — omission of the
409
+ * field for a brand-new prop is rejected to prevent silently bypassing
410
+ * the tenant pin gate.
411
+ */
412
+ export interface PropMetadata {
413
+ name: string
414
+ type: string
415
+ required: boolean
416
+ default?: string
417
+ description: string
418
+ enum?: string[]
419
+ numericRange?: [number, number]
420
+ /**
421
+ * SCHEMA_VERSION at which this prop first appeared on the component.
422
+ * Defaults at lookup time to the parent component's `addedIn`.
423
+ * Immutable — decreasing this value is rejected by the
424
+ * `addedInRegressed` CI rule.
425
+ */
426
+ addedIn?: string
427
+ }
428
+
429
+ /**
430
+ * Hand-curated description of one MDX component, used by:
431
+ * - MCP `editor_list_mdx_components` tool (agent-facing)
432
+ * - `validateComponent` / `validateMarkdownComponents`
433
+ * - md-editor slash command picker UX
434
+ * - `prepareProps()` render-time shim
435
+ * - `checkPin()` write-time pin enforcement
436
+ *
437
+ * Both `addedIn` and `deprecated` are mandatory for the CI compat
438
+ * classifier — every entry in `componentMetadata` carries them, even
439
+ * if `deprecated` is `[]`. Use `'0.1.0'` for the existing 11
440
+ * components; bump by the rubric in `.claude/skills/mdx-component-versioning/SKILL.md`
441
+ * when a new component lands.
442
+ */
443
+ export interface ComponentMetadata {
444
+ name: string
445
+ description: string
446
+ icon: string
447
+ /** Component category for slash command grouping (e.g., 'content', 'media', 'code') */
448
+ category?: string
449
+ aliases: string[]
450
+ props: PropMetadata[]
451
+ hasChildren: boolean
452
+ selfClosing: boolean
453
+ defaultProps: string
454
+ defaultChildren: string
455
+ example: string
456
+ /**
457
+ * SCHEMA_VERSION at which this component first appeared. Immutable —
458
+ * decreasing this value is rejected by the `addedInRegressed` CI rule.
459
+ * Existing 11 components are stamped '0.1.0'.
460
+ */
461
+ addedIn: string
462
+ /**
463
+ * Schema-version-bearing deprecation entries. Empty array when the
464
+ * component has no soft/hard breaks in flight. Walked by
465
+ * `prepareProps()` at render time and by the CI classifier at
466
+ * compat-check time.
467
+ */
468
+ deprecated: DeprecationEntry[]
469
+ }
package/src/version.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * SCHEMA_VERSION — the content-schema generation this build of
3
+ * `@blogmcp/mdx-schema` understands and emits.
4
+ *
5
+ * Distinct from the package version (in package.json) — the package
6
+ * version tracks the library's API surface (a non-breaking JS API tweak
7
+ * might bump the package patch without touching SCHEMA_VERSION; a
8
+ * Tier-2 / Tier-3 component schema change bumps SCHEMA_VERSION MAJOR
9
+ * without necessarily touching the JS API).
10
+ *
11
+ * Bump rubric (full table in `.claude/skills/mdx-component-versioning/SKILL.md`):
12
+ * Tier 0 — non-content edits, JSDoc → no SCHEMA_VERSION change
13
+ * Tier 1 — additive (new opt prop / variant / etc) → MINOR
14
+ * Tier 2 — soft-breaking + shim → MAJOR
15
+ * Tier 3 — hard-breaking + codemod → MAJOR
16
+ *
17
+ * The CI compat test (`test/compat.spec.ts`) enforces these bumps. After
18
+ * any change here, regenerate the baseline:
19
+ *
20
+ * npm run baseline:regen --workspace=@blogmcp/mdx-schema
21
+ */
22
+ export const SCHEMA_VERSION = '0.2.0' as const
23
+
24
+ export type SchemaVersion = typeof SCHEMA_VERSION