@glw907/cairn-cms 0.56.2 → 0.57.1

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 (173) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/dist/components/AdminLayout.svelte +3 -0
  3. package/dist/components/CairnAdmin.svelte +8 -1
  4. package/dist/components/CairnAdmin.svelte.d.ts +2 -0
  5. package/dist/components/CairnMediaLibrary.svelte +949 -0
  6. package/dist/components/CairnMediaLibrary.svelte.d.ts +37 -0
  7. package/dist/components/EditPage.svelte +348 -7
  8. package/dist/components/EditPage.svelte.d.ts +2 -0
  9. package/dist/components/MarkdownEditor.svelte +283 -1
  10. package/dist/components/MarkdownEditor.svelte.d.ts +37 -1
  11. package/dist/components/MediaCaptureCard.svelte +135 -0
  12. package/dist/components/MediaCaptureCard.svelte.d.ts +40 -0
  13. package/dist/components/MediaFigureControl.svelte +247 -0
  14. package/dist/components/MediaFigureControl.svelte.d.ts +40 -0
  15. package/dist/components/MediaHeroField.svelte +578 -0
  16. package/dist/components/MediaHeroField.svelte.d.ts +75 -0
  17. package/dist/components/MediaInsertPopover.svelte +449 -0
  18. package/dist/components/MediaInsertPopover.svelte.d.ts +58 -0
  19. package/dist/components/MediaPicker.svelte +257 -0
  20. package/dist/components/MediaPicker.svelte.d.ts +41 -0
  21. package/dist/components/admin-icons.d.ts +12 -0
  22. package/dist/components/admin-icons.js +12 -0
  23. package/dist/components/cairn-admin.css +901 -9
  24. package/dist/components/client-ingest.d.ts +142 -0
  25. package/dist/components/client-ingest.js +297 -0
  26. package/dist/components/editor-media.d.ts +11 -0
  27. package/dist/components/editor-media.js +206 -0
  28. package/dist/components/editor-placeholder.d.ts +26 -0
  29. package/dist/components/editor-placeholder.js +166 -0
  30. package/dist/components/index.d.ts +1 -0
  31. package/dist/components/index.js +1 -0
  32. package/dist/components/markdown-directives.d.ts +12 -0
  33. package/dist/components/markdown-directives.js +42 -0
  34. package/dist/components/markdown-format.d.ts +89 -0
  35. package/dist/components/markdown-format.js +255 -0
  36. package/dist/components/media-upload-outcome.d.ts +52 -0
  37. package/dist/components/media-upload-outcome.js +48 -0
  38. package/dist/content/compose.js +3 -0
  39. package/dist/content/frontmatter.js +22 -0
  40. package/dist/content/manifest.d.ts +4 -0
  41. package/dist/content/manifest.js +41 -1
  42. package/dist/content/media-refs.d.ts +7 -0
  43. package/dist/content/media-refs.js +52 -0
  44. package/dist/content/schema.d.ts +5 -2
  45. package/dist/content/schema.js +17 -0
  46. package/dist/content/types.d.ts +64 -11
  47. package/dist/content/validate.js +31 -0
  48. package/dist/delivery/public-routes.d.ts +16 -0
  49. package/dist/delivery/public-routes.js +46 -3
  50. package/dist/delivery/seo-fields.js +7 -1
  51. package/dist/delivery/seo.d.ts +2 -0
  52. package/dist/delivery/seo.js +3 -0
  53. package/dist/doctor/checks-local.d.ts +1 -0
  54. package/dist/doctor/checks-local.js +21 -0
  55. package/dist/doctor/index.d.ts +3 -1
  56. package/dist/doctor/index.js +11 -2
  57. package/dist/doctor/types.d.ts +3 -0
  58. package/dist/doctor/wrangler-config.d.ts +3 -0
  59. package/dist/doctor/wrangler-config.js +20 -0
  60. package/dist/env.d.ts +19 -0
  61. package/dist/env.js +26 -0
  62. package/dist/index.d.ts +1 -1
  63. package/dist/log/events.d.ts +1 -1
  64. package/dist/media/config.d.ts +24 -0
  65. package/dist/media/config.js +69 -0
  66. package/dist/media/delivery-bucket.d.ts +34 -0
  67. package/dist/media/delivery-bucket.js +10 -0
  68. package/dist/media/index.d.ts +6 -0
  69. package/dist/media/index.js +13 -0
  70. package/dist/media/library-entry.d.ts +30 -0
  71. package/dist/media/library-entry.js +17 -0
  72. package/dist/media/manifest.d.ts +44 -0
  73. package/dist/media/manifest.js +105 -0
  74. package/dist/media/naming.d.ts +18 -0
  75. package/dist/media/naming.js +112 -0
  76. package/dist/media/reconcile.d.ts +36 -0
  77. package/dist/media/reconcile.js +45 -0
  78. package/dist/media/reference.d.ts +12 -0
  79. package/dist/media/reference.js +33 -0
  80. package/dist/media/sniff.d.ts +18 -0
  81. package/dist/media/sniff.js +106 -0
  82. package/dist/media/store.d.ts +25 -0
  83. package/dist/media/store.js +16 -0
  84. package/dist/media/transform-url.d.ts +26 -0
  85. package/dist/media/transform-url.js +38 -0
  86. package/dist/media/usage.d.ts +48 -0
  87. package/dist/media/usage.js +90 -0
  88. package/dist/render/pipeline.d.ts +2 -0
  89. package/dist/render/pipeline.js +13 -2
  90. package/dist/render/registry.js +3 -0
  91. package/dist/render/remark-figure.d.ts +4 -0
  92. package/dist/render/remark-figure.js +103 -0
  93. package/dist/render/resolve-media.d.ts +34 -0
  94. package/dist/render/resolve-media.js +78 -0
  95. package/dist/render/sanitize-schema.d.ts +4 -2
  96. package/dist/render/sanitize-schema.js +5 -3
  97. package/dist/sveltekit/admin-dispatch.d.ts +2 -0
  98. package/dist/sveltekit/admin-dispatch.js +5 -0
  99. package/dist/sveltekit/cairn-admin.d.ts +8 -1
  100. package/dist/sveltekit/cairn-admin.js +10 -2
  101. package/dist/sveltekit/content-routes.d.ts +77 -2
  102. package/dist/sveltekit/content-routes.js +470 -10
  103. package/dist/sveltekit/csrf.d.ts +16 -0
  104. package/dist/sveltekit/csrf.js +18 -0
  105. package/dist/sveltekit/guard.js +10 -3
  106. package/dist/sveltekit/index.d.ts +2 -1
  107. package/dist/sveltekit/index.js +1 -0
  108. package/dist/sveltekit/media-route.d.ts +12 -0
  109. package/dist/sveltekit/media-route.js +137 -0
  110. package/dist/vite/index.d.ts +3 -0
  111. package/dist/vite/index.js +7 -2
  112. package/package.json +7 -1
  113. package/src/lib/components/AdminLayout.svelte +3 -0
  114. package/src/lib/components/CairnAdmin.svelte +8 -1
  115. package/src/lib/components/CairnMediaLibrary.svelte +949 -0
  116. package/src/lib/components/EditPage.svelte +348 -7
  117. package/src/lib/components/MarkdownEditor.svelte +283 -1
  118. package/src/lib/components/MediaCaptureCard.svelte +135 -0
  119. package/src/lib/components/MediaFigureControl.svelte +247 -0
  120. package/src/lib/components/MediaHeroField.svelte +578 -0
  121. package/src/lib/components/MediaInsertPopover.svelte +449 -0
  122. package/src/lib/components/MediaPicker.svelte +257 -0
  123. package/src/lib/components/admin-icons.ts +12 -0
  124. package/src/lib/components/cairn-admin.css +37 -0
  125. package/src/lib/components/client-ingest.ts +380 -0
  126. package/src/lib/components/editor-media.ts +248 -0
  127. package/src/lib/components/editor-placeholder.ts +213 -0
  128. package/src/lib/components/index.ts +1 -0
  129. package/src/lib/components/markdown-directives.ts +46 -0
  130. package/src/lib/components/markdown-format.ts +307 -1
  131. package/src/lib/components/media-upload-outcome.ts +83 -0
  132. package/src/lib/content/compose.ts +3 -0
  133. package/src/lib/content/frontmatter.ts +20 -1
  134. package/src/lib/content/manifest.ts +44 -1
  135. package/src/lib/content/media-refs.ts +58 -0
  136. package/src/lib/content/schema.ts +31 -7
  137. package/src/lib/content/types.ts +80 -13
  138. package/src/lib/content/validate.ts +29 -1
  139. package/src/lib/delivery/public-routes.ts +52 -3
  140. package/src/lib/delivery/seo-fields.ts +6 -1
  141. package/src/lib/delivery/seo.ts +5 -0
  142. package/src/lib/doctor/checks-local.ts +22 -0
  143. package/src/lib/doctor/index.ts +21 -3
  144. package/src/lib/doctor/types.ts +3 -0
  145. package/src/lib/doctor/wrangler-config.ts +23 -0
  146. package/src/lib/env.ts +28 -0
  147. package/src/lib/index.ts +2 -0
  148. package/src/lib/log/events.ts +8 -1
  149. package/src/lib/media/config.ts +103 -0
  150. package/src/lib/media/delivery-bucket.ts +41 -0
  151. package/src/lib/media/index.ts +22 -0
  152. package/src/lib/media/library-entry.ts +58 -0
  153. package/src/lib/media/manifest.ts +122 -0
  154. package/src/lib/media/naming.ts +130 -0
  155. package/src/lib/media/reconcile.ts +79 -0
  156. package/src/lib/media/reference.ts +40 -0
  157. package/src/lib/media/sniff.ts +114 -0
  158. package/src/lib/media/store.ts +57 -0
  159. package/src/lib/media/transform-url.ts +58 -0
  160. package/src/lib/media/usage.ts +152 -0
  161. package/src/lib/render/pipeline.ts +17 -3
  162. package/src/lib/render/registry.ts +5 -0
  163. package/src/lib/render/remark-figure.ts +132 -0
  164. package/src/lib/render/resolve-media.ts +96 -0
  165. package/src/lib/render/sanitize-schema.ts +5 -3
  166. package/src/lib/sveltekit/admin-dispatch.ts +6 -1
  167. package/src/lib/sveltekit/cairn-admin.ts +13 -3
  168. package/src/lib/sveltekit/content-routes.ts +589 -12
  169. package/src/lib/sveltekit/csrf.ts +18 -0
  170. package/src/lib/sveltekit/guard.ts +12 -3
  171. package/src/lib/sveltekit/index.ts +6 -0
  172. package/src/lib/sveltekit/media-route.ts +158 -0
  173. package/src/lib/vite/index.ts +9 -2
@@ -11,7 +11,9 @@ import type { Schema } from 'hast-util-sanitize';
11
11
  import { VFile } from 'vfile';
12
12
  import { buildSanitizeSchema, rehypeAnchorRel, rehypeSinkGuard } from './sanitize-schema.js';
13
13
  import { remarkDirectiveStamp } from './remark-directives.js';
14
+ import { remarkFigure } from './remark-figure.js';
14
15
  import { remarkResolveCairnLinks, CAIRN_RESOLVE } from './resolve-links.js';
16
+ import { remarkResolveMedia, MEDIA_RESOLVE, type MediaResolve } from './resolve-media.js';
15
17
  import { rehypeDispatch } from './rehype-dispatch.js';
16
18
  import { defineRegistry, type ComponentRegistry } from './registry.js';
17
19
  import type { LinkResolve } from '../content/links.js';
@@ -43,7 +45,13 @@ export function createRenderer(
43
45
  registry: ComponentRegistry = defineRegistry({ components: [] }),
44
46
  options: RendererOptions = {},
45
47
  ) {
46
- const remarkPlugins: PluggableList = [remarkDirective, [remarkDirectiveStamp, registry], remarkResolveCairnLinks];
48
+ const remarkPlugins: PluggableList = [
49
+ remarkDirective,
50
+ [remarkDirectiveStamp, registry],
51
+ remarkResolveCairnLinks,
52
+ remarkFigure,
53
+ remarkResolveMedia,
54
+ ];
47
55
  // The sanitize floor runs after rehype-raw (so author raw HTML is parsed, then cleaned) and
48
56
  // before the dispatch (so the site's trusted build() output and its inline SVG icons are never
49
57
  // sanitized). The anchor-rel hardening runs last so it also covers component-built anchors.
@@ -71,8 +79,14 @@ export function createRenderer(
71
79
  return {
72
80
  remarkPlugins,
73
81
  rehypePlugins,
74
- renderMarkdown: async (content: string, opts: { resolve?: LinkResolve } = {}): Promise<string> => {
75
- const file = new VFile({ value: content, data: { [CAIRN_RESOLVE]: opts.resolve } });
82
+ renderMarkdown: async (
83
+ content: string,
84
+ opts: { resolve?: LinkResolve; resolveMedia?: MediaResolve } = {},
85
+ ): Promise<string> => {
86
+ const file = new VFile({
87
+ value: content,
88
+ data: { [CAIRN_RESOLVE]: opts.resolve, [MEDIA_RESOLVE]: opts.resolveMedia },
89
+ });
76
90
  return String(await processor.process(file));
77
91
  },
78
92
  };
@@ -127,6 +127,11 @@ function findIconField(def: ComponentDef): AttributeField | undefined {
127
127
  */
128
128
  export function defineRegistry({ components }: { components: ComponentDef[] }): ComponentRegistry {
129
129
  for (const c of components) {
130
+ if (c.name === 'figure') {
131
+ throw new Error(
132
+ `cairn: component "${c.name}" uses "figure", a reserved directive name handled by the engine render step: remove it if the engine's built-in figure now covers your use, or rename it otherwise`,
133
+ );
134
+ }
130
135
  if (c.defaultIconByRole && Object.keys(c.defaultIconByRole).length > 0 && !findIconField(c)) {
131
136
  throw new Error(
132
137
  `cairn: component "${c.name}" sets defaultIconByRole but declares no type:'icon' attribute, so the default icon can never render`,
@@ -0,0 +1,132 @@
1
+ // cairn-cms: the figure render step, an mdast step in the shared render pipeline. It rewrites the
2
+ // cairn-reserved `figure` container directive into a <figure><img><figcaption> structure. The
3
+ // directive wraps a real media image (`![alt](media:slug.hash)`), so the image stays a child node
4
+ // and remarkResolveMedia resolves it untouched, exactly as a bare inline image. The caption is the
5
+ // directive's body text, and the placement role rides the directive's class attribute as a value
6
+ // from a closed set. This step runs before remarkResolveMedia and before remark-rehype flattens the
7
+ // tree. It is engine-internal and reserved, the sibling of resolveMedia and resolveLinks, exported
8
+ // from no public subpath. A site cannot register a component named `figure`, so it cannot shadow it.
9
+ import type { Root, Paragraph, PhrasingContent } from 'mdast';
10
+ import type { ContainerDirective } from 'mdast-util-directive';
11
+ import { visit } from 'unist-util-visit';
12
+ import { parseMediaToken } from '../media/reference.js';
13
+
14
+ // The directive's children are block content. The unwrap lifts the media image to a direct child of
15
+ // the figure, which is a phrasing node in block position: legal in the rendered <figure> and handled
16
+ // by mdast-util-to-hast, but outside mdast's block-content union. This alias names that child slot.
17
+ type FigureChild = ContainerDirective['children'][number];
18
+
19
+ /** The closed placement role set. A class outside this set is ignored, never passed through. */
20
+ const ROLES = new Set(['center', 'wide', 'full']);
21
+
22
+ // mdast-util-to-hast reads hName/hProperties off node.data to override the element. The shipped
23
+ // mdast Data type does not carry them, so this mirrors the local cast idiom in remark-directives.ts.
24
+ interface HastData {
25
+ hName?: string;
26
+ hProperties?: Record<string, unknown>;
27
+ }
28
+
29
+ function setData(node: { data?: unknown }, patch: HastData): void {
30
+ const data = (node.data ?? (node.data = {})) as HastData;
31
+ Object.assign(data, patch);
32
+ }
33
+
34
+ // A node whose subtree carries non-whitespace text is a caption candidate.
35
+ function hasText(node: FigureChild): boolean {
36
+ let found = false;
37
+ visit(node, 'text', (text) => {
38
+ if (text.value.trim() !== '') found = true;
39
+ });
40
+ return found;
41
+ }
42
+
43
+ // Find the first descendant image node whose url is a media: reference, with its enclosing direct
44
+ // child of the directive (the paragraph holding it) and that child's index.
45
+ function findMediaImage(
46
+ directive: ContainerDirective,
47
+ ): { image: PhrasingContent; childIndex: number } | null {
48
+ for (let i = 0; i < directive.children.length; i++) {
49
+ const child = directive.children[i];
50
+ if (child.type !== 'paragraph') continue;
51
+ const image = child.children.find(
52
+ (n) => n.type === 'image' && parseMediaToken(n.url) !== null,
53
+ );
54
+ if (image) return { image, childIndex: i };
55
+ }
56
+ return null;
57
+ }
58
+
59
+ // Strip a leading newline or all-whitespace prefix from the first phrasing child, so a caption
60
+ // split off the image line reads cleanly without a stray softbreak.
61
+ function trimLeadingNewline(children: PhrasingContent[]): PhrasingContent[] {
62
+ if (children.length === 0) return children;
63
+ const [first, ...rest] = children;
64
+ if (first.type === 'text') {
65
+ const trimmed = first.value.replace(/^\s+/, '');
66
+ if (trimmed === '') return rest;
67
+ return [{ ...first, value: trimmed }, ...rest];
68
+ }
69
+ return children;
70
+ }
71
+
72
+ /** Rewrite the reserved `figure` container directive into a placed <figure>. Every other directive
73
+ * is left to remarkDirectiveStamp, which already skips unregistered names. */
74
+ export function remarkFigure() {
75
+ return (tree: Root): void => {
76
+ visit(tree, 'containerDirective', (node: ContainerDirective) => {
77
+ if (node.name !== 'figure') return;
78
+
79
+ // The role rides the class attribute, kept only when it is exactly one closed-set value.
80
+ const className = node.attributes?.class ?? undefined;
81
+ const role = className && ROLES.has(className) ? className : undefined;
82
+ setData(node, {
83
+ hName: 'figure',
84
+ ...(role ? { hProperties: { className: ['cairn-place-' + role] } } : {}),
85
+ });
86
+
87
+ const found = findMediaImage(node);
88
+ // A figure with no media image is a degraded authoring state: leave its children, invent no
89
+ // image, never throw. The hName is already set, so it still renders as a <figure>.
90
+ if (!found) return;
91
+
92
+ const { image, childIndex } = found;
93
+ const paragraph = node.children[childIndex] as Paragraph;
94
+
95
+ // The image lifts into block position (the unwrap), so it carries the FigureChild slot type.
96
+ const imageChild = image as FigureChild;
97
+
98
+ // Unwrap the image to a direct child of the directive, handling both paragraph forms.
99
+ let captionNode: FigureChild | undefined;
100
+ if (paragraph.children.length === 1) {
101
+ // Blank-line form: the image is alone in its paragraph. The bare image replaces it; a
102
+ // separate following text-bearing paragraph is the caption.
103
+ node.children.splice(childIndex, 1, imageChild);
104
+ } else {
105
+ // No-blank-line form: the image and the caption share one paragraph. Split it into the bare
106
+ // image followed by a paragraph holding the remaining children as the caption.
107
+ const imageIndex = paragraph.children.indexOf(image);
108
+ const rest = trimLeadingNewline(paragraph.children.slice(imageIndex + 1));
109
+ const replacement: FigureChild[] = [imageChild];
110
+ if (rest.length > 0) {
111
+ const captionParagraph: Paragraph = { type: 'paragraph', children: rest };
112
+ replacement.push(captionParagraph);
113
+ captionNode = captionParagraph;
114
+ }
115
+ node.children.splice(childIndex, 1, ...replacement);
116
+ }
117
+
118
+ // The caption is the first text-bearing block after the image. In the split case it is the
119
+ // paragraph just appended; otherwise scan the blocks following the image.
120
+ const imagePos = node.children.indexOf(imageChild);
121
+ if (!captionNode) {
122
+ for (let i = imagePos + 1; i < node.children.length; i++) {
123
+ if (hasText(node.children[i])) {
124
+ captionNode = node.children[i];
125
+ break;
126
+ }
127
+ }
128
+ }
129
+ if (captionNode) setData(captionNode, { hName: 'figcaption' });
130
+ });
131
+ };
132
+ }
@@ -0,0 +1,96 @@
1
+ // cairn-cms: the media: reference resolver, an mdast step in the render pipeline. It mirrors the
2
+ // cairn: link resolver in ./resolve-links.ts: it runs before remark-rehype, so the rewritten src
3
+ // passes through the sanitize floor exactly as any other image. The per-call resolver is read off
4
+ // the VFile (set by renderMarkdown), so the processor is still built once. A miss either marks the
5
+ // image broken (preview) or throws (build), decided by the injected resolver.
6
+ import { visit } from 'unist-util-visit';
7
+ import type { VFile } from 'vfile';
8
+ import { parseMediaToken, type MediaRef } from '../media/reference.js';
9
+ import { findByHash, type MediaManifest } from '../media/manifest.js';
10
+ import { publicPath } from '../media/naming.js';
11
+ import { presetUrl } from '../media/transform-url.js';
12
+ import type { ResolvedAssetConfig } from '../media/config.js';
13
+ import { log } from '../log/index.js';
14
+
15
+ /** The VFile data key the renderer sets the per-call media resolver under. */
16
+ export const MEDIA_RESOLVE = 'mediaResolve';
17
+
18
+ /** Resolve a media reference to its delivery URL. `undefined` is a preview miss (the plugin marks
19
+ * the image broken); a resolver that throws is the build backstop (the error propagates out of
20
+ * render and fails the build), exactly like LinkResolve. */
21
+ export type MediaResolve = (ref: MediaRef) => string | undefined;
22
+
23
+ /** Build the per-call media resolver, closing over the manifest and the resolved config. The
24
+ * returned resolver looks a ref's content hash up in the manifest and builds the canonical delivery
25
+ * path from the manifest entry's slug and ext, not the token's, so a rename never breaks the
26
+ * reference. With a preset and zone transformations on it returns the variant URL; without a preset,
27
+ * or when transformations are off, it returns the bare full-size path so a fresh zone with Image
28
+ * Transformations disabled serves correct thumbnails rather than dead /cdn-cgi/image URLs. It returns
29
+ * undefined when media is off or no entry carries the hash (the preview-miss backstop). */
30
+ export function makeMediaResolver(
31
+ manifest: MediaManifest,
32
+ resolved: ResolvedAssetConfig,
33
+ opts?: { preset?: string },
34
+ ): MediaResolve {
35
+ return (ref: MediaRef): string | undefined => {
36
+ if (!resolved.enabled) return undefined;
37
+ const entry = findByHash(manifest, ref.hash);
38
+ if (!entry) {
39
+ // A real miss: media is on but the hash has no manifest row, the broken-reference case. The
40
+ // media-off path above stays silent, since an unresolved token there is expected, not a fault.
41
+ log.warn('media.resolve_missing', { hash: ref.hash });
42
+ return undefined;
43
+ }
44
+ const path = publicPath(entry.slug, entry.hash, entry.ext, resolved.urlForm, resolved.publicBase);
45
+ if (opts?.preset && resolved.transformations) {
46
+ return presetUrl(path, opts.preset, resolved.variants);
47
+ }
48
+ return path;
49
+ };
50
+ }
51
+
52
+ /** A resolver backed by the lean `mediaTargets` projection, for the admin preview. It mirrors
53
+ * manifestLinkResolver: a hash present in the projection builds the slug delivery path
54
+ * (`/media/<slug>.<hash>.<ext>`); a miss returns undefined, so the render step marks the image
55
+ * broken rather than throwing. Pure over the projection, with no manifest and no config, so the
56
+ * edit page reaches it with the data it actually has. */
57
+ export function manifestMediaResolver(
58
+ targets: Record<string, { slug: string; ext: string; contentType: string }>,
59
+ ): MediaResolve {
60
+ return (ref: MediaRef): string | undefined => {
61
+ const entry = targets[ref.hash];
62
+ if (!entry) return undefined;
63
+ return publicPath(entry.slug, ref.hash, entry.ext, 'slug');
64
+ };
65
+ }
66
+
67
+ interface ImageNode {
68
+ url: string;
69
+ data?: { hProperties?: Record<string, unknown> };
70
+ }
71
+
72
+ /** Resolve media: image nodes against the VFile's resolver. A non-media src and a malformed token
73
+ * pass through. A missing target is marked with the cairn-broken-media class (the resolver returns
74
+ * undefined) or, when the resolver throws, the error propagates and fails the build. */
75
+ export function remarkResolveMedia() {
76
+ return (tree: unknown, file: VFile): void => {
77
+ const resolve = file.data[MEDIA_RESOLVE] as MediaResolve | undefined;
78
+ if (!resolve) return;
79
+ visit(tree as Parameters<typeof visit>[0], 'image', (node: ImageNode) => {
80
+ const ref = parseMediaToken(node.url);
81
+ if (!ref) return;
82
+ const url = resolve(ref); // may throw (build backstop); propagates out of render
83
+ if (url) {
84
+ node.url = url;
85
+ return;
86
+ }
87
+ // Missing asset in the preview: mark it broken and neutralize the src, keeping the alt.
88
+ node.url = '#';
89
+ node.data = node.data ?? {};
90
+ const props = (node.data.hProperties = node.data.hProperties ?? {});
91
+ const existing = Array.isArray(props.className) ? (props.className as string[]) : [];
92
+ props.className = [...existing, 'cairn-broken-media'];
93
+ props.title = 'Missing media asset';
94
+ });
95
+ };
96
+ }
@@ -13,8 +13,10 @@ const FIXED_MARKERS = ['dataPrimitive', 'dataSlot', 'dataRole', 'dataRise'];
13
13
  * then adds exactly what cairn's render needs. The directive markers (the fixed ones plus the
14
14
  * dataAttr<Key> markers derived from the registry) survive so the dispatch reads its stamps after
15
15
  * the floor. The benign author tags real content uses (nav, details, summary) and class/target/rel
16
- * on anchors are admitted. A site extends the result through `extend`, always starting from this
17
- * safe base, so it can add to the allowlist but not weaken the core strip.
16
+ * on anchors are admitted. figure/figcaption join the base so the engine's placed figure survives
17
+ * the floor on every site, including one that supplies its own `sanitizeSchema` extension. A site
18
+ * extends the result through `extend`, always starting from this safe base, so it can add to the
19
+ * allowlist but not weaken the core strip.
18
20
  */
19
21
  export function buildSanitizeSchema(
20
22
  registry: ComponentRegistry,
@@ -36,7 +38,7 @@ export function buildSanitizeSchema(
36
38
  const protocols = defaultSchema.protocols ?? {};
37
39
  const schema: Schema = {
38
40
  ...defaultSchema,
39
- tagNames: [...(defaultSchema.tagNames ?? []), 'nav', 'details', 'summary'],
41
+ tagNames: [...(defaultSchema.tagNames ?? []), 'nav', 'details', 'summary', 'figure', 'figcaption'],
40
42
  attributes: {
41
43
  ...attributes,
42
44
  '*': [...(attributes['*'] ?? []), 'className', ...markers],
@@ -15,7 +15,8 @@ export type AdminView =
15
15
  | { view: 'list'; concept: ConceptDescriptor }
16
16
  | { view: 'edit'; concept: ConceptDescriptor; id: string }
17
17
  | { view: 'editors' }
18
- | { view: 'nav' };
18
+ | { view: 'nav' }
19
+ | { view: 'media' };
19
20
 
20
21
  /**
21
22
  * Fixed first segments that never resolve as concepts. The engine only allows posts and pages
@@ -57,6 +58,10 @@ export function parseAdminPath(
57
58
  if (head === 'login') return { view: 'login' };
58
59
  if (head === 'editors') return { view: 'editors' };
59
60
  if (head === 'nav') return { view: 'nav' };
61
+ // media is its own view, a peer of editors and nav, so it is decided here, not added to the
62
+ // reserved-no-view set. /admin/media/<anything> 404s naturally (media is not a configured
63
+ // concept), which is the correct shape.
64
+ if (head === 'media') return { view: 'media' };
60
65
  if (RESERVED_SEGMENTS.has(head)) return null;
61
66
  const concept = findConcept(concepts, head);
62
67
  return concept ? { view: 'list', concept } : null;
@@ -14,6 +14,7 @@ import {
14
14
  type LayoutData,
15
15
  type ListData,
16
16
  type EditData,
17
+ type MediaLibraryData,
17
18
  } from './content-routes.js';
18
19
  import { createEditorRoutes } from './editors-routes.js';
19
20
  import { createNavRoutes, type NavLoadData } from './nav-routes.js';
@@ -53,7 +54,8 @@ export type AdminData =
53
54
  | { view: 'list'; layout: LayoutData; page: ListData }
54
55
  | { view: 'edit'; layout: LayoutData; page: EditData }
55
56
  | { view: 'editors'; layout: LayoutData; page: { editors: Editor[]; self: string } }
56
- | { view: 'nav'; layout: LayoutData; page: NavLoadData };
57
+ | { view: 'nav'; layout: LayoutData; page: NavLoadData }
58
+ | { view: 'media'; layout: LayoutData; page: MediaLibraryData };
57
59
 
58
60
  export function createCairnAdmin(runtime: CairnRuntime, deps: CairnAdminDeps = {}) {
59
61
  // The runtime already composes the site name and the sender identity, so the magic-link
@@ -122,6 +124,11 @@ export function createCairnAdmin(runtime: CairnRuntime, deps: CairnAdminDeps = {
122
124
  const [layout, page] = await Promise.all([content.layoutLoad(delegated), nav.navLoad(delegated)]);
123
125
  return { view: 'nav', layout, page };
124
126
  }
127
+ case 'media': {
128
+ const delegated = contentEvent(event, {});
129
+ const [layout, page] = await Promise.all([content.layoutLoad(delegated), content.mediaLibraryLoad(delegated)]);
130
+ return { view: 'media', layout, page };
131
+ }
125
132
  }
126
133
  }
127
134
 
@@ -141,9 +148,9 @@ export function createCairnAdmin(runtime: CairnRuntime, deps: CairnAdminDeps = {
141
148
  }
142
149
 
143
150
  // The topbar posts publishAll from every authed admin page; login and confirm may not.
144
- const authedViews = ['list', 'edit', 'editors', 'nav'] as const;
151
+ const authedViews = ['list', 'edit', 'editors', 'nav', 'media'] as const;
145
152
  // An editor signs out from wherever they are, so logout accepts any parsed view.
146
- const anyView = ['index', 'login', 'confirm', 'list', 'edit', 'editors', 'nav'] as const;
153
+ const anyView = ['index', 'login', 'confirm', 'list', 'edit', 'editors', 'nav', 'media'] as const;
147
154
 
148
155
  /** The full admin action vocabulary, one named async function per action, so a site's
149
156
  * catch-all route exports `admin.actions` directly. Each wrapper stays thin: parse,
@@ -159,6 +166,7 @@ export function createCairnAdmin(runtime: CairnRuntime, deps: CairnAdminDeps = {
159
166
  if (!nav) throw error(404, 'Not found');
160
167
  return nav.navSave(contentEvent(event, {}));
161
168
  }),
169
+ upload: viewAction(['edit'], (event, view) => content.uploadAction(contentEvent(event, { concept: view.concept.id, id: view.id }))),
162
170
  publish: viewAction(['edit'], (event, view) => content.publishAction(contentEvent(event, { concept: view.concept.id, id: view.id }))),
163
171
  discard: viewAction(['edit'], (event, view) => content.discardAction(contentEvent(event, { concept: view.concept.id, id: view.id }))),
164
172
  rename: viewAction(['edit'], (event, view) => content.renameAction(contentEvent(event, { concept: view.concept.id, id: view.id }))),
@@ -167,6 +175,8 @@ export function createCairnAdmin(runtime: CairnRuntime, deps: CairnAdminDeps = {
167
175
  ? content.deleteAction(contentEvent(event, { concept: view.concept.id, id: view.id }))
168
176
  : content.listDeleteAction(contentEvent(event, { concept: view.concept.id })),
169
177
  ),
178
+ mediaDelete: viewAction(['media'], (event) => content.mediaDeleteAction(contentEvent(event, {}))),
179
+ mediaUpdate: viewAction(['media'], (event) => content.mediaUpdateAction(contentEvent(event, {}))),
170
180
  publishAll: viewAction(authedViews, (event) => content.publishAllAction(contentEvent(event, {}))),
171
181
  addEditor: viewAction(['editors'], (event) => editors.addEditorAction(event)),
172
182
  removeEditor: viewAction(['editors'], (event) => editors.removeEditorAction(event)),