@glw907/cairn-cms 0.9.0 → 0.11.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 (91) hide show
  1. package/dist/components/ComponentForm.svelte +178 -0
  2. package/dist/components/ComponentForm.svelte.d.ts +20 -0
  3. package/dist/components/ComponentForm.svelte.d.ts.map +1 -0
  4. package/dist/components/ComponentInsertDialog.svelte +92 -0
  5. package/dist/components/ComponentInsertDialog.svelte.d.ts +20 -0
  6. package/dist/components/ComponentInsertDialog.svelte.d.ts.map +1 -0
  7. package/dist/components/EditPage.svelte +6 -3
  8. package/dist/components/EditPage.svelte.d.ts +3 -0
  9. package/dist/components/EditPage.svelte.d.ts.map +1 -1
  10. package/dist/components/IconPicker.svelte +51 -0
  11. package/dist/components/IconPicker.svelte.d.ts +20 -0
  12. package/dist/components/IconPicker.svelte.d.ts.map +1 -0
  13. package/dist/components/index.d.ts +3 -1
  14. package/dist/components/index.d.ts.map +1 -1
  15. package/dist/components/index.js +3 -1
  16. package/dist/content/compose.d.ts.map +1 -1
  17. package/dist/content/compose.js +1 -0
  18. package/dist/content/types.d.ts +5 -0
  19. package/dist/content/types.d.ts.map +1 -1
  20. package/dist/delivery/CairnHead.svelte +36 -0
  21. package/dist/delivery/CairnHead.svelte.d.ts +15 -0
  22. package/dist/delivery/CairnHead.svelte.d.ts.map +1 -0
  23. package/dist/delivery/content-index.d.ts +8 -6
  24. package/dist/delivery/content-index.d.ts.map +1 -1
  25. package/dist/delivery/content-index.js +1 -1
  26. package/dist/delivery/index.d.ts +22 -0
  27. package/dist/delivery/index.d.ts.map +1 -0
  28. package/dist/delivery/index.js +19 -0
  29. package/dist/delivery/json-ld.d.ts +2 -0
  30. package/dist/delivery/json-ld.d.ts.map +1 -0
  31. package/dist/delivery/json-ld.js +16 -0
  32. package/dist/delivery/responses.d.ts +14 -0
  33. package/dist/delivery/responses.d.ts.map +1 -0
  34. package/dist/delivery/responses.js +30 -0
  35. package/dist/delivery/seo.d.ts +4 -0
  36. package/dist/delivery/seo.d.ts.map +1 -1
  37. package/dist/delivery/seo.js +11 -0
  38. package/dist/delivery/site-descriptors.d.ts +5 -0
  39. package/dist/delivery/site-descriptors.d.ts.map +1 -0
  40. package/dist/delivery/site-descriptors.js +9 -0
  41. package/dist/delivery/site-index.d.ts +8 -2
  42. package/dist/delivery/site-index.d.ts.map +1 -1
  43. package/dist/delivery/site-index.js +28 -2
  44. package/dist/index.d.ts +8 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +5 -1
  47. package/dist/render/component-grammar.d.ts +10 -0
  48. package/dist/render/component-grammar.d.ts.map +1 -0
  49. package/dist/render/component-grammar.js +140 -0
  50. package/dist/render/component-insert.d.ts +14 -0
  51. package/dist/render/component-insert.d.ts.map +1 -0
  52. package/dist/render/component-insert.js +9 -0
  53. package/dist/render/component-reference.d.ts +11 -0
  54. package/dist/render/component-reference.d.ts.map +1 -0
  55. package/dist/render/component-reference.js +34 -0
  56. package/dist/render/component-validate.d.ts +10 -0
  57. package/dist/render/component-validate.d.ts.map +1 -0
  58. package/dist/render/component-validate.js +30 -0
  59. package/dist/render/registry.d.ts +45 -1
  60. package/dist/render/registry.d.ts.map +1 -1
  61. package/dist/render/registry.js +13 -0
  62. package/dist/sveltekit/public-routes.d.ts +11 -0
  63. package/dist/sveltekit/public-routes.d.ts.map +1 -1
  64. package/dist/sveltekit/public-routes.js +15 -2
  65. package/package.json +7 -1
  66. package/src/lib/components/ComponentForm.svelte +178 -0
  67. package/src/lib/components/ComponentInsertDialog.svelte +92 -0
  68. package/src/lib/components/EditPage.svelte +6 -3
  69. package/src/lib/components/IconPicker.svelte +51 -0
  70. package/src/lib/components/index.ts +3 -1
  71. package/src/lib/content/compose.ts +1 -0
  72. package/src/lib/content/types.ts +5 -0
  73. package/src/lib/delivery/CairnHead.svelte +36 -0
  74. package/src/lib/delivery/content-index.ts +15 -10
  75. package/src/lib/delivery/index.ts +32 -0
  76. package/src/lib/delivery/json-ld.ts +16 -0
  77. package/src/lib/delivery/responses.ts +34 -0
  78. package/src/lib/delivery/seo.ts +13 -0
  79. package/src/lib/delivery/site-descriptors.ts +12 -0
  80. package/src/lib/delivery/site-index.ts +27 -2
  81. package/src/lib/index.ts +16 -2
  82. package/src/lib/render/component-grammar.ts +167 -0
  83. package/src/lib/render/component-insert.ts +15 -0
  84. package/src/lib/render/component-reference.ts +38 -0
  85. package/src/lib/render/component-validate.ts +36 -0
  86. package/src/lib/render/registry.ts +61 -1
  87. package/src/lib/sveltekit/public-routes.ts +23 -2
  88. package/dist/components/ComponentPalette.svelte +0 -50
  89. package/dist/components/ComponentPalette.svelte.d.ts +0 -16
  90. package/dist/components/ComponentPalette.svelte.d.ts.map +0 -1
  91. package/src/lib/components/ComponentPalette.svelte +0 -50
@@ -1,4 +1,33 @@
1
1
  import type { Element } from 'hast';
2
+ /** The input types a component attribute or repeatable item field can take. */
3
+ export type FieldType = 'text' | 'select' | 'icon' | 'boolean';
4
+ /** One `{key="value"}` attribute on a component directive, or one field of a repeatable item. */
5
+ export interface AttributeField {
6
+ /** The attribute name as it appears in the directive, e.g. `icon`. */
7
+ key: string;
8
+ /** The form label. */
9
+ label: string;
10
+ type: FieldType;
11
+ required?: boolean;
12
+ /** Initial value; a string for text/select/icon, a boolean for boolean. */
13
+ default?: string | boolean;
14
+ /** Allowed values for `type: 'select'`. */
15
+ options?: string[];
16
+ /** Helper text shown under the field. */
17
+ help?: string;
18
+ }
19
+ export type SlotKind = 'markdown' | 'inline' | 'repeatable';
20
+ /** One named content region of a component. The slots named `title` and `body` are special: `title`
21
+ * serializes to the directive `[label]` and `body` to the unmarked content (see the canonical grammar). */
22
+ export interface SlotDef {
23
+ name: string;
24
+ label: string;
25
+ kind: SlotKind;
26
+ required?: boolean;
27
+ help?: string;
28
+ /** For `kind: 'repeatable'`: the fields composing each list item (v1 uses the first field). */
29
+ itemFields?: AttributeField[];
30
+ }
2
31
  /** A site component: how it inserts (editor) and how it renders (rehype). */
3
32
  export interface ComponentDef {
4
33
  /** Directive name, e.g. 'card' (matches `:::card`). */
@@ -8,13 +37,19 @@ export interface ComponentDef {
8
37
  /** Palette description. */
9
38
  description: string;
10
39
  /** Markdown scaffold inserted at the cursor by the editor palette. */
11
- insertTemplate: string;
40
+ insertTemplate?: string;
12
41
  /** Build the final hast element from the stamped directive element. The engine
13
42
  * stamps the entrance-stagger ordinal (`data-rise`) on the top-level result, so a
14
43
  * build fn stays free of any motion concern. */
15
44
  build: (node: Element) => Element;
16
45
  /** Optional role-to-default-icon, e.g. `{ caution: 'warning' }`. */
17
46
  defaultIconByRole?: Record<string, string>;
47
+ /** One line on when to reach for this component; feeds the picker and the reference file. */
48
+ use?: string;
49
+ /** The `{key="value"}` attributes this component accepts. */
50
+ attributes?: AttributeField[];
51
+ /** The named content regions this component accepts. */
52
+ slots?: SlotDef[];
18
53
  }
19
54
  export interface ComponentRegistry {
20
55
  defs: ComponentDef[];
@@ -29,4 +64,13 @@ export interface ComponentRegistry {
29
64
  export declare function defineRegistry({ components }: {
30
65
  components: ComponentDef[];
31
66
  }): ComponentRegistry;
67
+ /** Guided-form values for one component: attribute values keyed by attribute key, slot values keyed
68
+ * by slot name (a string, or a string list for a repeatable slot). */
69
+ export interface ComponentValues {
70
+ attributes: Record<string, string | boolean>;
71
+ slots: Record<string, string | string[]>;
72
+ }
73
+ /** Seed an empty {@link ComponentValues} from a component's schema: attribute defaults (or '' / false)
74
+ * and empty slot values ([] for repeatable, '' otherwise). */
75
+ export declare function emptyValues(def: ComponentDef): ComponentValues;
32
76
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/lib/render/registry.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAA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G;AACH,wBAAgB,cAAc,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,YAAY,EAAE,CAAA;CAAE,GAAG,iBAAiB,CAQhG;AAED;uEACuE;AACvE,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC7C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC1C;AAED;+DAC+D;AAC/D,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,eAAe,CAU9D"}
@@ -11,3 +11,16 @@ export function defineRegistry({ components }) {
11
11
  defaultIcon: (name, role) => (role ? byName.get(name)?.defaultIconByRole?.[role] : undefined),
12
12
  };
13
13
  }
14
+ /** Seed an empty {@link ComponentValues} from a component's schema: attribute defaults (or '' / false)
15
+ * and empty slot values ([] for repeatable, '' otherwise). */
16
+ export function emptyValues(def) {
17
+ const attributes = {};
18
+ for (const field of def.attributes ?? []) {
19
+ attributes[field.key] = field.default ?? (field.type === 'boolean' ? false : '');
20
+ }
21
+ const slots = {};
22
+ for (const slot of def.slots ?? []) {
23
+ slots[slot.name] = slot.kind === 'repeatable' ? [] : '';
24
+ }
25
+ return { attributes, slots };
26
+ }
@@ -1,5 +1,6 @@
1
1
  import type { ContentSummary, ContentEntry } from '../delivery/content-index.js';
2
2
  import type { SiteIndex } from '../delivery/site-index.js';
3
+ import type { SeoMeta } from '../delivery/seo.js';
3
4
  /** Injected dependencies for the public loaders. */
4
5
  export interface PublicRoutesDeps {
5
6
  site: SiteIndex;
@@ -7,6 +8,15 @@ export interface PublicRoutesDeps {
7
8
  stagger?: boolean;
8
9
  }) => string | Promise<string>;
9
10
  origin: string;
11
+ /** Site name for og:site_name and the SEO head. */
12
+ siteName: string;
13
+ /** Default description used when an entry has none. */
14
+ description: string;
15
+ /** Absolute feed URLs for the head's autodiscovery links. */
16
+ feeds?: {
17
+ rss?: string;
18
+ json?: string;
19
+ };
10
20
  }
11
21
  /** The archive and tag list data: summaries the template renders. */
12
22
  export interface ListData {
@@ -28,6 +38,7 @@ export interface EntryData {
28
38
  entry: ContentEntry;
29
39
  html: string;
30
40
  canonicalUrl: string;
41
+ seo: SeoMeta;
31
42
  newer?: ContentSummary;
32
43
  older?: ContentSummary;
33
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"public-routes.d.ts","sourceRoot":"","sources":["../../src/lib/sveltekit/public-routes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/E,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qEAAqE;AACrE,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,cAAc,EAAE,CAAC;CAC3B;AAED,uDAAuD;AACvD,MAAM,WAAW,OAAQ,SAAQ,QAAQ;IACvC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACxC;AAED,oFAAoF;AACpF,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,cAAc,CAAC;CAC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Q;IACvC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CACxC;AAED,oFAAoF;AACpF,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,2DAA2D;AAC3D,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB;uBAWvB;QAAE,GAAG,EAAE,GAAG,CAAA;KAAE,KAAG,OAAO,CAAC,SAAS,CAAC;6BAoBjC,MAAM,KAAG,QAAQ;8BAKhB,MAAM,KAAG,YAAY;yBAK1B,MAAM,SAAS;QAAE,MAAM,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,KAAG,OAAO;mBAO5D;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE;EAKvC"}
@@ -4,9 +4,10 @@
4
4
  // and tag-index loaders stay concept-scoped, keyed by concept id. The index is built in site code
5
5
  // from globs, so it stays in the prerender graph and out of the runtime Worker.
6
6
  import { error } from '@sveltejs/kit';
7
+ import { buildSeoMeta } from '../delivery/seo.js';
7
8
  /** Build the public loaders for a site's unified index. */
8
9
  export function createPublicRoutes(deps) {
9
- const { site, render, origin } = deps;
10
+ const { site, render, origin, siteName, description, feeds } = deps;
10
11
  /** Resolve one concept's index by id, or a 404 (the route names an unconfigured concept). */
11
12
  function indexOf(conceptId) {
12
13
  const index = site.concept(conceptId);
@@ -20,7 +21,19 @@ export function createPublicRoutes(deps) {
20
21
  if (!entry)
21
22
  throw error(404, `Not found: ${event.url.pathname}`);
22
23
  const { newer, older } = site.adjacent(entry);
23
- return { entry, html: await render(entry.body, { stagger: true }), canonicalUrl: origin + entry.permalink, newer, older };
24
+ const canonicalUrl = origin + entry.permalink;
25
+ // A dated entry is an article; an undated one (a page) is a website.
26
+ const seo = buildSeoMeta({
27
+ title: entry.title,
28
+ description: entry.frontmatter.description || entry.excerpt || description,
29
+ canonicalUrl,
30
+ siteName,
31
+ type: entry.date ? 'article' : 'website',
32
+ ...(entry.date ? { published: entry.date } : {}),
33
+ ...(entry.updated ? { modified: entry.updated } : {}),
34
+ feeds,
35
+ });
36
+ return { entry, html: await render(entry.body, { stagger: true }), canonicalUrl, seo, newer, older };
24
37
  }
25
38
  /** The chronological archive for one concept: every non-draft summary, newest-first. */
26
39
  function archiveLoad(conceptId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glw907/cairn-cms",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Embedded, magic-link, GitHub-committing CMS for SvelteKit/Cloudflare sites.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -48,6 +48,11 @@
48
48
  "svelte": "./dist/components/index.js",
49
49
  "default": "./dist/components/index.js"
50
50
  },
51
+ "./delivery": {
52
+ "types": "./dist/delivery/index.d.ts",
53
+ "svelte": "./dist/delivery/index.js",
54
+ "default": "./dist/delivery/index.js"
55
+ },
51
56
  "./package.json": "./package.json"
52
57
  },
53
58
  "files": [
@@ -79,6 +84,7 @@
79
84
  "remark-gfm": "^4",
80
85
  "remark-parse": "^11.0.0",
81
86
  "remark-rehype": "^11.1.2",
87
+ "remark-stringify": "^11.0.0",
82
88
  "unified": "^11.0.5",
83
89
  "unist-util-visit": "^5.1.0",
84
90
  "yaml": "^2"
@@ -0,0 +1,178 @@
1
+ <!--
2
+ @component
3
+ The schema-driven fill form for one component. It holds the working ComponentValues, seeded from
4
+ emptyValues(def), and renders attribute fields and the title/body and other non-repeatable slots.
5
+ Submit (Task 6) serializes and validates through buildComponentInsert and calls onInsert with the
6
+ markdown. Back returns to the picker. This is not a nested HTML form; Insert calls a callback.
7
+ -->
8
+ <script lang="ts">
9
+ import { untrack } from 'svelte';
10
+ import { emptyValues, type ComponentDef } from '../render/registry.js';
11
+ import { buildComponentInsert } from '../render/component-insert.js';
12
+ import type { IconSet } from '../render/glyph.js';
13
+ import IconPicker from './IconPicker.svelte';
14
+
15
+ interface Props {
16
+ def: ComponentDef;
17
+ icons?: IconSet;
18
+ /** Called with the serialized markdown when the form validates. */
19
+ onInsert: (markdown: string) => void;
20
+ /** Return to the picker. */
21
+ onBack: () => void;
22
+ }
23
+
24
+ let { def, icons, onInsert, onBack }: Props = $props();
25
+
26
+ // Working values, seeded once from the schema. $state makes the nested records deeply reactive.
27
+ // untrack marks the seed as a deliberate one-time read of the initial def, not a reactive miss.
28
+ let values = $state(untrack(() => emptyValues(def)));
29
+
30
+ const attributes = $derived(def.attributes ?? []);
31
+ // Non-repeatable slots render here; the repeatable list is handled separately.
32
+ const flatSlots = $derived((def.slots ?? []).filter((s) => s.kind !== 'repeatable'));
33
+ const repeatableSlots = $derived((def.slots ?? []).filter((s) => s.kind === 'repeatable'));
34
+
35
+ // The live $state proxy array for a repeatable slot, so push/splice stay reactive.
36
+ function slotItems(name: string): string[] {
37
+ const v = values.slots[name];
38
+ return Array.isArray(v) ? v : [];
39
+ }
40
+
41
+ // Typed accessors over the unions so explicit value targets stay sound.
42
+ function asString(key: string): string {
43
+ const v = values.attributes[key];
44
+ return typeof v === 'string' ? v : '';
45
+ }
46
+ function asBool(key: string): boolean {
47
+ return values.attributes[key] === true;
48
+ }
49
+ function slotString(name: string): string {
50
+ const v = values.slots[name];
51
+ return typeof v === 'string' ? v : '';
52
+ }
53
+
54
+ // Field-keyed validation errors from the last submit, keyed by attribute key or slot name.
55
+ let errors = $state<Record<string, string>>({});
56
+
57
+ // Serialize and validate through the pure helper. On success clear errors and emit the markdown;
58
+ // on failure keep the field-keyed errors so each field can show its message and insert nothing.
59
+ async function submit() {
60
+ const result = await buildComponentInsert(def, values);
61
+ if (result.ok) {
62
+ errors = {};
63
+ onInsert(result.markdown);
64
+ } else {
65
+ errors = result.errors;
66
+ }
67
+ }
68
+ </script>
69
+
70
+ <div class="flex flex-col gap-3">
71
+ <div class="flex items-center justify-between">
72
+ <h3 class="text-sm font-semibold">{def.label}</h3>
73
+ <button type="button" class="btn btn-ghost btn-xs" onclick={onBack}>Back</button>
74
+ </div>
75
+
76
+ {#each attributes as field (field.key)}
77
+ {#if field.type === 'boolean'}
78
+ <label class="label cursor-pointer justify-start gap-2">
79
+ <input
80
+ class="checkbox checkbox-sm"
81
+ type="checkbox"
82
+ aria-label={field.label}
83
+ aria-invalid={Boolean(errors[field.key])}
84
+ aria-describedby={errors[field.key] ? `err-${field.key}` : undefined}
85
+ checked={asBool(field.key)}
86
+ onchange={(e) => (values.attributes[field.key] = e.currentTarget.checked)}
87
+ />
88
+ <span class="text-sm">{field.label}</span>
89
+ </label>
90
+ {:else if field.type === 'select'}
91
+ <label class="flex flex-col gap-1">
92
+ <span class="text-sm font-medium">{field.label}</span>
93
+ <select
94
+ class="select"
95
+ aria-label={field.label}
96
+ aria-invalid={Boolean(errors[field.key])}
97
+ aria-describedby={errors[field.key] ? `err-${field.key}` : undefined}
98
+ value={asString(field.key)}
99
+ onchange={(e) => (values.attributes[field.key] = e.currentTarget.value)}
100
+ >
101
+ {#if !field.required}<option value="">—</option>{/if}
102
+ {#each field.options ?? [] as opt (opt)}<option value={opt}>{opt}</option>{/each}
103
+ </select>
104
+ </label>
105
+ {:else if field.type === 'icon' && icons}
106
+ <div class="flex flex-col gap-1">
107
+ <span class="text-sm font-medium">{field.label}</span>
108
+ <IconPicker
109
+ {icons}
110
+ value={asString(field.key)}
111
+ required={field.required ?? false}
112
+ onChange={(name) => (values.attributes[field.key] = name)}
113
+ />
114
+ </div>
115
+ {:else}
116
+ <label class="flex flex-col gap-1">
117
+ <span class="text-sm font-medium">{field.label}</span>
118
+ <input
119
+ class="input"
120
+ aria-label={field.label}
121
+ aria-invalid={Boolean(errors[field.key])}
122
+ aria-describedby={errors[field.key] ? `err-${field.key}` : undefined}
123
+ value={asString(field.key)}
124
+ oninput={(e) => (values.attributes[field.key] = e.currentTarget.value)}
125
+ />
126
+ </label>
127
+ {/if}
128
+ {#if errors[field.key]}<span id={`err-${field.key}`} role="alert" class="text-error text-xs">{errors[field.key]}</span>{/if}
129
+ {/each}
130
+
131
+ {#each flatSlots as slot (slot.name)}
132
+ {#if slot.kind === 'markdown'}
133
+ <label class="flex flex-col gap-1">
134
+ <span class="text-sm font-medium">{slot.label}</span>
135
+ <textarea
136
+ class="textarea"
137
+ aria-label={slot.label}
138
+ aria-invalid={Boolean(errors[slot.name])}
139
+ aria-describedby={errors[slot.name] ? `err-${slot.name}` : undefined}
140
+ rows={3}
141
+ value={slotString(slot.name)}
142
+ oninput={(e) => (values.slots[slot.name] = e.currentTarget.value)}
143
+ ></textarea>
144
+ </label>
145
+ {:else}
146
+ <label class="flex flex-col gap-1">
147
+ <span class="text-sm font-medium">{slot.label}</span>
148
+ <input
149
+ class="input"
150
+ aria-label={slot.label}
151
+ aria-invalid={Boolean(errors[slot.name])}
152
+ aria-describedby={errors[slot.name] ? `err-${slot.name}` : undefined}
153
+ value={slotString(slot.name)}
154
+ oninput={(e) => (values.slots[slot.name] = e.currentTarget.value)}
155
+ />
156
+ </label>
157
+ {/if}
158
+ {#if errors[slot.name]}<span id={`err-${slot.name}`} role="alert" class="text-error text-xs">{errors[slot.name]}</span>{/if}
159
+ {/each}
160
+
161
+ {#each repeatableSlots as slot (slot.name)}
162
+ {@const items = slotItems(slot.name)}
163
+ <fieldset class="rounded-box border border-base-300 flex flex-col gap-2 p-2">
164
+ <legend class="text-sm font-medium">{slot.label}</legend>
165
+ <!-- Index key is deliberate: items are bare strings with no stable id, so the value bindings and splice/push are index-based by design. -->
166
+ {#each items as _, i (i)}
167
+ <div class="flex items-center gap-2">
168
+ <input class="input input-sm flex-1" aria-label={`${slot.label} item`} bind:value={items[i]} />
169
+ <button type="button" class="btn btn-ghost btn-sm" aria-label={`Remove item ${i + 1}`} onclick={() => items.splice(i, 1)}>✕</button>
170
+ </div>
171
+ {/each}
172
+ <button type="button" class="btn btn-sm self-start" onclick={() => items.push('')}>Add item</button>
173
+ {#if errors[slot.name]}<span id={`err-${slot.name}`} role="alert" class="text-error text-xs">{errors[slot.name]}</span>{/if}
174
+ </fieldset>
175
+ {/each}
176
+
177
+ <button type="button" class="btn btn-primary btn-sm mt-2" onclick={submit}>Insert</button>
178
+ </div>
@@ -0,0 +1,92 @@
1
+ <!--
2
+ @component
3
+ The Insert control and its modal. The picker lists each actionable component with its description and
4
+ intended use. A component with a schema opens the guided ComponentForm; a template-only component
5
+ inserts directly; a component with neither is not listed. Built on a native <dialog> for focus
6
+ trapping and Escape, following the dropdown's a11y conventions used elsewhere in the admin.
7
+ -->
8
+ <script lang="ts">
9
+ import type { ComponentRegistry, ComponentDef } from '../render/registry.js';
10
+ import type { IconSet } from '../render/glyph.js';
11
+ import ComponentForm from './ComponentForm.svelte';
12
+
13
+ interface Props {
14
+ /** The site's component registry. */
15
+ registry?: ComponentRegistry;
16
+ /** Insert markdown at the editor cursor. */
17
+ insert: (text: string) => void;
18
+ /** The site's icon set, for icon fields. */
19
+ icons?: IconSet;
20
+ }
21
+
22
+ let { registry, insert, icons }: Props = $props();
23
+
24
+ let dialog = $state<HTMLDialogElement | null>(null);
25
+ let picked = $state<ComponentDef | null>(null);
26
+
27
+ function hasSchema(def: ComponentDef): boolean {
28
+ return (def.attributes?.length ?? 0) > 0 || (def.slots?.length ?? 0) > 0;
29
+ }
30
+ function actionable(def: ComponentDef): boolean {
31
+ return hasSchema(def) || Boolean(def.insertTemplate);
32
+ }
33
+
34
+ const defs = $derived((registry?.defs ?? []).filter(actionable));
35
+
36
+ function open() {
37
+ picked = null;
38
+ dialog?.showModal();
39
+ }
40
+ function close() {
41
+ picked = null;
42
+ dialog?.close();
43
+ }
44
+ function choose(def: ComponentDef) {
45
+ if (hasSchema(def)) {
46
+ picked = def;
47
+ } else {
48
+ insert(def.insertTemplate ?? '');
49
+ close();
50
+ }
51
+ }
52
+ function onInsert(markdown: string) {
53
+ insert(markdown);
54
+ close();
55
+ }
56
+ </script>
57
+
58
+ {#if defs.length > 0}
59
+ <button type="button" class="btn btn-sm btn-ghost" aria-haspopup="dialog" aria-label="Insert component" onclick={open}>Insert</button>
60
+
61
+ <dialog class="modal" aria-labelledby="cairn-insert-dialog-title" bind:this={dialog} onclose={() => (picked = null)}>
62
+ <div class="modal-box">
63
+ <div class="mb-3 flex items-center justify-between">
64
+ <h2 id="cairn-insert-dialog-title" class="text-base font-semibold">Insert component</h2>
65
+ <button type="button" class="btn btn-ghost btn-sm" aria-label="Close" onclick={close}>✕</button>
66
+ </div>
67
+
68
+ {#if picked}
69
+ {#key picked}
70
+ <ComponentForm def={picked} {icons} {onInsert} onBack={() => (picked = null)} />
71
+ {/key}
72
+ {:else}
73
+ <ul class="menu w-full">
74
+ {#each defs as def (def.name)}
75
+ <li>
76
+ <button type="button" onclick={() => choose(def)}>
77
+ <span class="flex flex-col items-start">
78
+ <span class="font-medium">{def.label}</span>
79
+ {#if def.description}<span class="text-xs text-[var(--color-muted)]">{def.description}</span>{/if}
80
+ {#if def.use}<span class="text-xs text-[var(--color-muted)]">{def.use}</span>{/if}
81
+ </span>
82
+ </button>
83
+ </li>
84
+ {/each}
85
+ </ul>
86
+ {/if}
87
+ </div>
88
+ <form method="dialog" class="modal-backdrop">
89
+ <button tabindex="-1" aria-label="Close">close</button>
90
+ </form>
91
+ </dialog>
92
+ {/if}
@@ -7,8 +7,9 @@ markdown editor and a live, design-accurate preview. The whole surface is one fo
7
7
  <script lang="ts">
8
8
  import { untrack } from 'svelte';
9
9
  import MarkdownEditor from './MarkdownEditor.svelte';
10
- import ComponentPalette from './ComponentPalette.svelte';
10
+ import ComponentInsertDialog from './ComponentInsertDialog.svelte';
11
11
  import type { ComponentRegistry } from '../render/registry.js';
12
+ import type { IconSet } from '../render/glyph.js';
12
13
  import type { EditData } from '../sveltekit/content-routes.js';
13
14
  import type { TextareaField, TagsField, FreeTagsField } from '../content/types.js';
14
15
  import { sanitizePreviewHtml } from '../render/sanitize.js';
@@ -20,9 +21,11 @@ markdown editor and a live, design-accurate preview. The whole surface is one fo
20
21
  registry?: ComponentRegistry;
21
22
  /** The site's design-accurate render pipeline; the preview pane sanitizes its output. */
22
23
  render?: (md: string, opts?: { stagger?: boolean }) => string | Promise<string>;
24
+ /** The site's icon set, for the guided form's icon fields. */
25
+ icons?: IconSet;
23
26
  }
24
27
 
25
- let { data, registry, render }: Props = $props();
28
+ let { data, registry, render, icons }: Props = $props();
26
29
 
27
30
  // `body` is local editor state seeded once from the prop; it diverges as the user types.
28
31
  // untrack() captures the initial value without subscribing to future prop changes.
@@ -76,7 +79,7 @@ markdown editor and a live, design-accurate preview. The whole surface is one fo
76
79
  <p class="text-xs text-[var(--color-muted)]">{data.label}: {data.id}</p>
77
80
  </div>
78
81
  <div class="flex items-center gap-2">
79
- <ComponentPalette {registry} {insert} />
82
+ <ComponentInsertDialog {registry} {insert} {icons} />
80
83
  <button
81
84
  type="button"
82
85
  class="btn btn-sm btn-ghost"
@@ -0,0 +1,51 @@
1
+ <!--
2
+ @component
3
+ A visual icon choice over the site's IconSet. Each glyph is a toggle button; the selected one carries
4
+ aria-pressed. When the field is optional, a None button clears the value. The glyph renders inline from
5
+ the IconSet path data, matching the renderer's 256-unit viewBox.
6
+ -->
7
+ <script lang="ts">
8
+ import type { IconSet } from '../render/glyph.js';
9
+
10
+ interface Props {
11
+ /** The site's glyph name to SVG path-data map. */
12
+ icons: IconSet;
13
+ /** The currently selected glyph name, or '' for none. */
14
+ value: string;
15
+ /** When false, a None choice is offered. */
16
+ required: boolean;
17
+ /** Called with the new glyph name (or '' for none). */
18
+ onChange: (name: string) => void;
19
+ }
20
+
21
+ let { icons, value, required, onChange }: Props = $props();
22
+
23
+ const names = $derived(Object.keys(icons));
24
+ </script>
25
+
26
+ <div class="flex flex-wrap gap-2" role="group" aria-label="Icon">
27
+ {#if !required}
28
+ <button
29
+ type="button"
30
+ class="btn btn-sm"
31
+ class:btn-primary={value === ''}
32
+ aria-pressed={value === ''}
33
+ onclick={() => onChange('')}
34
+ >None</button>
35
+ {/if}
36
+ {#each names as name (name)}
37
+ <button
38
+ type="button"
39
+ class="btn btn-sm gap-1"
40
+ class:btn-primary={value === name}
41
+ aria-pressed={value === name}
42
+ aria-label={name}
43
+ onclick={() => onChange(name)}
44
+ >
45
+ <svg class="ec-glyph" viewBox="0 0 256 256" fill="currentColor" aria-hidden="true" width="16" height="16">
46
+ <path d={icons[name]} />
47
+ </svg>
48
+ <span class="text-xs">{name}</span>
49
+ </button>
50
+ {/each}
51
+ </div>
@@ -7,5 +7,7 @@ export { default as ConceptList } from './ConceptList.svelte';
7
7
  export { default as EditPage } from './EditPage.svelte';
8
8
  export { default as ManageEditors } from './ManageEditors.svelte';
9
9
  export { default as MarkdownEditor } from './MarkdownEditor.svelte';
10
- export { default as ComponentPalette } from './ComponentPalette.svelte';
10
+ export { default as ComponentInsertDialog } from './ComponentInsertDialog.svelte';
11
+ export { default as ComponentForm } from './ComponentForm.svelte';
12
+ export { default as IconPicker } from './IconPicker.svelte';
11
13
  export { default as NavTree } from './NavTree.svelte';
@@ -32,6 +32,7 @@ export function composeRuntime(
32
32
  sender: adapter.sender,
33
33
  render: adapter.render,
34
34
  registry: adapter.registry,
35
+ icons: adapter.icons,
35
36
  navMenu: adapter.navMenu,
36
37
  assets: adapter.assets,
37
38
  adminPanels,
@@ -8,6 +8,7 @@
8
8
  // descriptors are plain data so a `load` function can hand them across the server-to-client
9
9
  // boundary to the editor form.
10
10
  import type { ComponentRegistry } from '../render/registry.js';
11
+ import type { IconSet } from '../render/glyph.js';
11
12
  import type { DatePrefix } from './ids.js';
12
13
 
13
14
  /** Common to every frontmatter field: the frontmatter key, the form label, and whether it is required. */
@@ -151,6 +152,8 @@ export interface CairnAdapter {
151
152
  render(md: string, opts?: { stagger?: boolean }): string | Promise<string>;
152
153
  /** Directive component registry; the renderer and the future palette derive from it (seam 3). */
153
154
  registry?: ComponentRegistry;
155
+ /** The site's glyph name to SVG path-data map, for the admin icon picker and the renderer. */
156
+ icons?: IconSet;
154
157
  navMenu?: NavMenuConfig;
155
158
  assets?: AssetConfig;
156
159
  }
@@ -243,6 +246,8 @@ export interface CairnRuntime {
243
246
  /** The site's one renderer: the editor preview and every public page call it (design decision 4). */
244
247
  render(md: string, opts?: { stagger?: boolean }): string | Promise<string>;
245
248
  registry?: ComponentRegistry;
249
+ /** The site's glyph name to SVG path-data map, for the admin icon picker and the renderer. */
250
+ icons?: IconSet;
246
251
  navMenu?: NavMenuConfig;
247
252
  assets?: AssetConfig;
248
253
  /** Admin panels contributed by extensions (Mode 2). Empty until Plan 09 wires the dispatch route. */
@@ -0,0 +1,36 @@
1
+ <!--
2
+ @component
3
+ Renders a page's SEO head from a SeoMeta object into <svelte:head>: a title, meta tags, link
4
+ tags, and one escaped JSON-LD script. The title renders from seo.title by default; title={false}
5
+ lets the site own the <title>, and a string overrides it. It carries no CSS, so it pulls in no
6
+ admin styles.
7
+ -->
8
+ <script lang="ts">
9
+ import type { SeoMeta } from './seo.js';
10
+ import { jsonLdScript } from './json-ld.js';
11
+
12
+ let {
13
+ /** The plain-data head to render. */
14
+ seo,
15
+ /** Title override: a string replaces seo.title, false lets the site own <title>. */
16
+ title,
17
+ }: { seo: SeoMeta; title?: string | false } = $props();
18
+ const titleText = $derived(title === undefined ? seo.title : title);
19
+ </script>
20
+
21
+ <svelte:head>
22
+ {#if titleText !== false}
23
+ <title>{titleText}</title>
24
+ {/if}
25
+ {#each seo.meta as m}
26
+ {#if m.name}
27
+ <meta name={m.name} content={m.content} />
28
+ {:else if m.property}
29
+ <meta property={m.property} content={m.content} />
30
+ {/if}
31
+ {/each}
32
+ {#each seo.links as l}
33
+ <link rel={l.rel} type={l.type} href={l.href} title={l.title} />
34
+ {/each}
35
+ {@html jsonLdScript(seo.jsonLd)}
36
+ </svelte:head>