@glw907/cairn-cms 0.62.2 → 0.76.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/CHANGELOG.md +216 -0
- package/dist/ambient.d.ts +2 -0
- package/dist/auth/types.d.ts +7 -0
- package/dist/components/CairnAdmin.svelte.d.ts +2 -7
- package/dist/components/ComponentForm.svelte +44 -27
- package/dist/components/ComponentInsertDialog.svelte +22 -11
- package/dist/components/ComponentInsertDialog.svelte.d.ts +2 -6
- package/dist/components/ConceptList.svelte +25 -4
- package/dist/components/EditPage.svelte +29 -107
- package/dist/components/EditPage.svelte.d.ts +2 -7
- package/dist/components/EntryPicker.svelte +117 -0
- package/dist/components/EntryPicker.svelte.d.ts +35 -0
- package/dist/components/FieldInput.svelte +218 -0
- package/dist/components/FieldInput.svelte.d.ts +51 -0
- package/dist/components/IconPicker.svelte +2 -2
- package/dist/components/IconPicker.svelte.d.ts +2 -0
- package/dist/components/LinkPicker.svelte +8 -75
- package/dist/components/LinkPicker.svelte.d.ts +4 -5
- package/dist/components/MediaHeroField.svelte +8 -5
- package/dist/components/MediaHeroField.svelte.d.ts +4 -0
- package/dist/components/ObjectGroupField.svelte +54 -0
- package/dist/components/ObjectGroupField.svelte.d.ts +47 -0
- package/dist/components/ReferenceField.svelte +94 -0
- package/dist/components/ReferenceField.svelte.d.ts +27 -0
- package/dist/components/RepeatableField.svelte +221 -0
- package/dist/components/RepeatableField.svelte.d.ts +53 -0
- package/dist/components/cairn-admin.css +179 -2
- package/dist/components/preview-doc.js +5 -1
- package/dist/components/tidy-validate.js +1 -1
- package/dist/content/adapter.js +18 -0
- package/dist/content/advisories.d.ts +2 -2
- package/dist/content/advisories.js +3 -5
- package/dist/content/compose.d.ts +7 -6
- package/dist/content/compose.js +26 -20
- package/dist/content/concepts.d.ts +21 -15
- package/dist/content/concepts.js +55 -32
- package/dist/content/field-rules.d.ts +15 -0
- package/dist/content/field-rules.js +38 -0
- package/dist/content/fields.d.ts +169 -0
- package/dist/content/fields.js +41 -0
- package/dist/content/fieldset.d.ts +107 -0
- package/dist/content/fieldset.js +386 -0
- package/dist/content/frontmatter-region.d.ts +38 -0
- package/dist/content/frontmatter-region.js +75 -0
- package/dist/content/frontmatter.d.ts +35 -2
- package/dist/content/frontmatter.js +232 -11
- package/dist/content/manifest.d.ts +34 -0
- package/dist/content/manifest.js +80 -4
- package/dist/content/media-refs.d.ts +2 -2
- package/dist/content/media-rewrite.js +1 -69
- package/dist/content/reference-index.d.ts +56 -0
- package/dist/content/reference-index.js +95 -0
- package/dist/content/references.d.ts +40 -0
- package/dist/content/references.js +0 -0
- package/dist/content/standard-schema.d.ts +30 -0
- package/dist/content/standard-schema.js +4 -0
- package/dist/content/types.d.ts +127 -178
- package/dist/delivery/data.d.ts +2 -2
- package/dist/delivery/data.js +1 -1
- package/dist/delivery/public-routes.d.ts +10 -5
- package/dist/delivery/public-routes.js +25 -2
- package/dist/delivery/site-descriptors.d.ts +5 -1
- package/dist/delivery/site-descriptors.js +8 -3
- package/dist/delivery/site-indexes.d.ts +2 -2
- package/dist/delivery/site-resolver.d.ts +25 -0
- package/dist/delivery/site-resolver.js +49 -0
- package/dist/doctor/checks-local.js +6 -11
- package/dist/github/backend.d.ts +83 -0
- package/dist/github/backend.js +76 -0
- package/dist/github/credentials.d.ts +11 -5
- package/dist/github/credentials.js +3 -3
- package/dist/github/repo.d.ts +8 -19
- package/dist/github/repo.js +69 -80
- package/dist/github/types.d.ts +1 -1
- package/dist/github/types.js +4 -4
- package/dist/index.d.ts +18 -10
- package/dist/index.js +9 -5
- package/dist/islands/index.d.ts +12 -0
- package/dist/islands/index.js +83 -0
- package/dist/islands/types.d.ts +7 -0
- package/dist/islands/types.js +1 -0
- package/dist/log/events.d.ts +1 -1
- package/dist/media/index.d.ts +1 -1
- package/dist/media/index.js +1 -1
- package/dist/media/manifest.d.ts +11 -0
- package/dist/media/manifest.js +13 -0
- package/dist/media/rewrite-plan.d.ts +2 -3
- package/dist/media/rewrite-plan.js +2 -3
- package/dist/media/usage.d.ts +2 -2
- package/dist/media/usage.js +3 -5
- package/dist/nav/site-config.d.ts +0 -6
- package/dist/nav/site-config.js +6 -4
- package/dist/render/component-grammar.js +11 -11
- package/dist/render/component-reference.js +5 -3
- package/dist/render/component-validate.d.ts +4 -1
- package/dist/render/component-validate.js +10 -35
- package/dist/render/highlight.d.ts +9 -0
- package/dist/render/highlight.js +206 -0
- package/dist/render/pipeline.d.ts +0 -6
- package/dist/render/pipeline.js +13 -2
- package/dist/render/registry.d.ts +44 -36
- package/dist/render/registry.js +47 -6
- package/dist/render/rehype-dispatch.d.ts +6 -10
- package/dist/render/rehype-dispatch.js +38 -17
- package/dist/render/remark-directives.js +4 -5
- package/dist/render/sanitize-schema.d.ts +10 -0
- package/dist/render/sanitize-schema.js +30 -1
- package/dist/sveltekit/cairn-admin.d.ts +5 -5
- package/dist/sveltekit/cairn-admin.js +3 -4
- package/dist/sveltekit/content-routes.d.ts +10 -8
- package/dist/sveltekit/content-routes.js +269 -181
- package/dist/sveltekit/guard.js +10 -0
- package/dist/sveltekit/health.d.ts +7 -3
- package/dist/sveltekit/health.js +9 -3
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/nav-routes.d.ts +6 -5
- package/dist/sveltekit/nav-routes.js +22 -20
- package/dist/sveltekit/types.d.ts +2 -0
- package/dist/vite/index.d.ts +3 -3
- package/dist/vite/index.js +17 -8
- package/package.json +17 -2
- package/src/lib/ambient.ts +7 -0
- package/src/lib/auth/types.ts +7 -0
- package/src/lib/components/CairnAdmin.svelte +2 -6
- package/src/lib/components/ComponentForm.svelte +48 -27
- package/src/lib/components/ComponentInsertDialog.svelte +26 -14
- package/src/lib/components/ConceptList.svelte +41 -4
- package/src/lib/components/EditPage.svelte +43 -119
- package/src/lib/components/EntryPicker.svelte +154 -0
- package/src/lib/components/FieldInput.svelte +262 -0
- package/src/lib/components/IconPicker.svelte +4 -2
- package/src/lib/components/LinkPicker.svelte +10 -81
- package/src/lib/components/MediaHeroField.svelte +12 -5
- package/src/lib/components/ObjectGroupField.svelte +97 -0
- package/src/lib/components/ReferenceField.svelte +126 -0
- package/src/lib/components/RepeatableField.svelte +310 -0
- package/src/lib/components/preview-doc.ts +5 -1
- package/src/lib/components/tidy-validate.ts +1 -1
- package/src/lib/content/adapter.ts +21 -0
- package/src/lib/content/advisories.ts +4 -7
- package/src/lib/content/compose.ts +30 -23
- package/src/lib/content/concepts.ts +68 -40
- package/src/lib/content/field-rules.ts +39 -0
- package/src/lib/content/fields.ts +178 -0
- package/src/lib/content/fieldset.ts +470 -0
- package/src/lib/content/frontmatter-region.ts +90 -0
- package/src/lib/content/frontmatter.ts +231 -15
- package/src/lib/content/manifest.ts +101 -4
- package/src/lib/content/media-refs.ts +2 -2
- package/src/lib/content/media-rewrite.ts +7 -80
- package/src/lib/content/reference-index.ts +159 -0
- package/src/lib/content/references.ts +0 -0
- package/src/lib/content/standard-schema.ts +25 -0
- package/src/lib/content/types.ts +128 -195
- package/src/lib/delivery/data.ts +2 -2
- package/src/lib/delivery/public-routes.ts +36 -4
- package/src/lib/delivery/site-descriptors.ts +8 -3
- package/src/lib/delivery/site-indexes.ts +2 -2
- package/src/lib/delivery/site-resolver.ts +64 -0
- package/src/lib/doctor/checks-local.ts +6 -14
- package/src/lib/github/backend.ts +161 -0
- package/src/lib/github/credentials.ts +10 -7
- package/src/lib/github/repo.ts +79 -83
- package/src/lib/github/types.ts +5 -5
- package/src/lib/index.ts +40 -18
- package/src/lib/islands/index.ts +84 -0
- package/src/lib/islands/types.ts +11 -0
- package/src/lib/log/events.ts +1 -0
- package/src/lib/media/index.ts +1 -0
- package/src/lib/media/manifest.ts +14 -0
- package/src/lib/media/rewrite-plan.ts +4 -6
- package/src/lib/media/usage.ts +4 -7
- package/src/lib/nav/site-config.ts +8 -9
- package/src/lib/render/component-grammar.ts +10 -10
- package/src/lib/render/component-reference.ts +4 -3
- package/src/lib/render/component-validate.ts +10 -35
- package/src/lib/render/highlight.ts +259 -0
- package/src/lib/render/pipeline.ts +13 -8
- package/src/lib/render/registry.ts +88 -42
- package/src/lib/render/rehype-dispatch.ts +47 -16
- package/src/lib/render/remark-directives.ts +4 -5
- package/src/lib/render/sanitize-schema.ts +32 -1
- package/src/lib/sveltekit/cairn-admin.ts +8 -9
- package/src/lib/sveltekit/content-routes.ts +330 -221
- package/src/lib/sveltekit/guard.ts +15 -0
- package/src/lib/sveltekit/health.ts +13 -6
- package/src/lib/sveltekit/index.ts +2 -2
- package/src/lib/sveltekit/nav-routes.ts +33 -29
- package/src/lib/sveltekit/types.ts +5 -1
- package/src/lib/vite/index.ts +20 -11
- package/dist/content/schema.d.ts +0 -87
- package/dist/content/schema.js +0 -89
- package/dist/content/validate.d.ts +0 -17
- package/dist/content/validate.js +0 -93
- package/src/lib/content/schema.ts +0 -167
- package/src/lib/content/validate.ts +0 -90
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
The leaf-field dispatcher for the edit page's Details panel. It renders one leaf field (a scalar,
|
|
4
|
+
an image, or a reference) as the matching input, picked by `field.type`.
|
|
5
|
+
|
|
6
|
+
It is name-prefixable so a container row can reuse it one level down. The `name` prop is the form
|
|
7
|
+
input name: it defaults to `field.name` at the top level, and a container caller passes a prefixed
|
|
8
|
+
path (`${parent}.${index}` for an array element, `${parent}.${leafKey}` for an object leaf) so the
|
|
9
|
+
nested decode in `frontmatter.ts` reads the value back from the right slot. Each arm reads its value
|
|
10
|
+
from `frontmatter[field.name]`, so a nested caller passes the row or object slice as `frontmatter`
|
|
11
|
+
and the leaf key as `field.name`, leaving the reads unchanged.
|
|
12
|
+
|
|
13
|
+
An `object` field renders a labeled `ObjectGroupField`, and a non-reference `array` renders a
|
|
14
|
+
`RepeatableField`; both recurse one level back through this dispatcher for their leaves, which the
|
|
15
|
+
one-level nesting cap (the declaration guard) bounds so the recursion terminates. An
|
|
16
|
+
`array(reference)` stays on `ReferenceField`.
|
|
17
|
+
-->
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import MediaHeroField from './MediaHeroField.svelte';
|
|
20
|
+
import ReferenceField from './ReferenceField.svelte';
|
|
21
|
+
import ObjectGroupField from './ObjectGroupField.svelte';
|
|
22
|
+
import RepeatableField from './RepeatableField.svelte';
|
|
23
|
+
import IconPicker from './IconPicker.svelte';
|
|
24
|
+
import { isClosedMultiselect } from '../content/frontmatter.js';
|
|
25
|
+
import type { ImageValue, NamedField } from '../content/types.js';
|
|
26
|
+
import type { TextareaField, NumberField, SelectField, MultiselectField } from '../content/fields.js';
|
|
27
|
+
import type { IconSet } from '../render/glyph.js';
|
|
28
|
+
import type { LinkTarget } from '../content/manifest.js';
|
|
29
|
+
import type { MediaEntry } from '../media/manifest.js';
|
|
30
|
+
import type { MediaLibraryEntry } from '../media/library-entry.js';
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
/** The leaf field to render; its `name` is the frontmatter key the arm reads its value from. */
|
|
34
|
+
field: NamedField;
|
|
35
|
+
/** The form input name. Defaults to `field.name`; a container caller passes a prefixed path. */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** The frontmatter slice this field reads from, keyed by `field.name`. */
|
|
38
|
+
frontmatter: Record<string, unknown>;
|
|
39
|
+
/** The site link targets the reference arm offers. */
|
|
40
|
+
targets: LinkTarget[];
|
|
41
|
+
/** Mark the edit form dirty; the image arm wires it to the hero field's commit. */
|
|
42
|
+
markFieldsDirty: () => void;
|
|
43
|
+
/** The merged committed-plus-uploaded media library, keyed by content hash. */
|
|
44
|
+
mediaLibrary: Record<string, MediaLibraryEntry>;
|
|
45
|
+
/** The concept the entry belongs to (the upload action's route param). */
|
|
46
|
+
conceptId: string;
|
|
47
|
+
/** The entry id (the upload action's route param). */
|
|
48
|
+
id: string;
|
|
49
|
+
/** The host's hero-field refs, keyed by the prefixed `name` so two rows do not collide. */
|
|
50
|
+
heroFieldRefs: Record<string, MediaHeroField>;
|
|
51
|
+
/** Called with the server-owned record on a successful upload, so the host merges it. */
|
|
52
|
+
onuploaded: (record: MediaEntry) => void;
|
|
53
|
+
/** Called when a hero's needs-alt status changes, keyed by the prefixed `name`. */
|
|
54
|
+
onheroneedsalt: (name: string, needsAlt: boolean) => void;
|
|
55
|
+
/** The site's icon set, threaded to the icon arm's picker. Absent when the site ships none. */
|
|
56
|
+
icons?: IconSet;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let {
|
|
60
|
+
field,
|
|
61
|
+
name = field.name,
|
|
62
|
+
frontmatter,
|
|
63
|
+
targets,
|
|
64
|
+
markFieldsDirty,
|
|
65
|
+
mediaLibrary,
|
|
66
|
+
conceptId,
|
|
67
|
+
id,
|
|
68
|
+
heroFieldRefs,
|
|
69
|
+
onuploaded,
|
|
70
|
+
onheroneedsalt,
|
|
71
|
+
icons,
|
|
72
|
+
}: Props = $props();
|
|
73
|
+
|
|
74
|
+
function str(v: unknown): string {
|
|
75
|
+
return v == null ? '' : String(v);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// The HTML input type for a plain single-line text input arm (url, email, datetime, and the text
|
|
79
|
+
// fallback). datetime maps to the datetime-local control; everything else carries no type attribute
|
|
80
|
+
// so the browser defaults to a text input.
|
|
81
|
+
function inputType(fieldType: string): 'url' | 'email' | 'datetime-local' | undefined {
|
|
82
|
+
switch (fieldType) {
|
|
83
|
+
case 'url':
|
|
84
|
+
return 'url';
|
|
85
|
+
case 'email':
|
|
86
|
+
return 'email';
|
|
87
|
+
case 'datetime':
|
|
88
|
+
return 'datetime-local';
|
|
89
|
+
default:
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// The built-in hint a date field carries when its adapter sets no description. The control reads as
|
|
95
|
+
// if it might schedule publishing, so this reassures the editor that the date is metadata and that
|
|
96
|
+
// publishing is the separate, deliberate step. A field-level description overrides it.
|
|
97
|
+
const DATE_PUBLISH_HINT = 'Sets the date for this post. Publishing is a separate step you choose.';
|
|
98
|
+
</script>
|
|
99
|
+
|
|
100
|
+
{#snippet fieldHint(hintName: string, text: string)}
|
|
101
|
+
<p id={`${hintName}-hint`} class="fld-hint mt-1 text-sm text-[var(--color-muted)]">
|
|
102
|
+
{text}
|
|
103
|
+
</p>
|
|
104
|
+
{/snippet}
|
|
105
|
+
|
|
106
|
+
{#if field.type === 'textarea'}
|
|
107
|
+
{@const f = field as NamedField & TextareaField}
|
|
108
|
+
<label class="flex flex-col gap-1">
|
|
109
|
+
<span class="text-sm font-medium">{f.label}</span>
|
|
110
|
+
<textarea class="textarea textarea-sm" {name} aria-label={f.label} aria-describedby={f.help ? `${f.name}-hint` : undefined} rows={f.rows ?? 3}>{str(frontmatter[f.name])}</textarea>
|
|
111
|
+
{#if f.help}
|
|
112
|
+
{@render fieldHint(f.name, f.help)}
|
|
113
|
+
{/if}
|
|
114
|
+
</label>
|
|
115
|
+
{:else if field.type === 'number'}
|
|
116
|
+
{@const f = field as NamedField & NumberField}
|
|
117
|
+
<label class="flex flex-col gap-1">
|
|
118
|
+
<span class="text-sm font-medium">{f.label}</span>
|
|
119
|
+
<input
|
|
120
|
+
class="input input-sm"
|
|
121
|
+
type="number"
|
|
122
|
+
{name}
|
|
123
|
+
aria-label={f.label}
|
|
124
|
+
aria-describedby={f.help ? `${f.name}-hint` : undefined}
|
|
125
|
+
min={f.min}
|
|
126
|
+
max={f.max}
|
|
127
|
+
step={f.integer ? 1 : undefined}
|
|
128
|
+
value={str(frontmatter[f.name])}
|
|
129
|
+
required={f.required}
|
|
130
|
+
/>
|
|
131
|
+
{#if f.help}
|
|
132
|
+
{@render fieldHint(f.name, f.help)}
|
|
133
|
+
{/if}
|
|
134
|
+
</label>
|
|
135
|
+
{:else if field.type === 'select'}
|
|
136
|
+
{@const f = field as NamedField & SelectField}
|
|
137
|
+
<label class="flex flex-col gap-1">
|
|
138
|
+
<span class="text-sm font-medium">{f.label}</span>
|
|
139
|
+
<select class="select select-sm" {name} aria-label={f.label} aria-describedby={f.help ? `${f.name}-hint` : undefined} required={f.required}>
|
|
140
|
+
<!-- A leading empty option submits '' (the key is dropped on save); a required select
|
|
141
|
+
leaves it unselected so an unset value fails the required check with a clear message. -->
|
|
142
|
+
<option value="">— none —</option>
|
|
143
|
+
{#each f.options as option (option)}
|
|
144
|
+
<option value={option} selected={str(frontmatter[f.name]) === option}>{option}</option>
|
|
145
|
+
{/each}
|
|
146
|
+
</select>
|
|
147
|
+
{#if f.help}
|
|
148
|
+
{@render fieldHint(f.name, f.help)}
|
|
149
|
+
{/if}
|
|
150
|
+
</label>
|
|
151
|
+
{:else if field.type === 'date'}
|
|
152
|
+
<label class="flex flex-col gap-1">
|
|
153
|
+
<span class="text-sm font-medium">{field.label}</span>
|
|
154
|
+
<!-- A date field always carries a hint: the adapter's help when set, else the
|
|
155
|
+
built-in publish-clarity default. So aria-describedby always points at the paragraph. -->
|
|
156
|
+
<input class="input input-sm" type="date" {name} aria-label={field.label} aria-describedby={`${field.name}-hint`} value={str(frontmatter[field.name])} />
|
|
157
|
+
{@render fieldHint(field.name, field.help || DATE_PUBLISH_HINT)}
|
|
158
|
+
</label>
|
|
159
|
+
{:else if field.type === 'boolean'}
|
|
160
|
+
<div class="flex flex-col gap-1">
|
|
161
|
+
<label class="label cursor-pointer justify-start gap-2">
|
|
162
|
+
<input class="checkbox checkbox-sm" type="checkbox" {name} aria-label={field.label} aria-describedby={field.help ? `${field.name}-hint` : undefined} checked={frontmatter[field.name] === true} />
|
|
163
|
+
<span class="text-sm">{field.label}</span>
|
|
164
|
+
</label>
|
|
165
|
+
{#if field.help}
|
|
166
|
+
{@render fieldHint(field.name, field.help)}
|
|
167
|
+
{/if}
|
|
168
|
+
</div>
|
|
169
|
+
{:else if field.type === 'multiselect' && isClosedMultiselect(field)}
|
|
170
|
+
{@const f = field as NamedField & MultiselectField & { options: readonly string[] }}
|
|
171
|
+
{@const selected = (frontmatter[f.name] ?? []) as string[]}
|
|
172
|
+
<fieldset class="fieldset" aria-describedby={f.help ? `${f.name}-hint` : undefined}>
|
|
173
|
+
<legend class="fieldset-legend">{f.label}</legend>
|
|
174
|
+
{#if f.help}
|
|
175
|
+
{@render fieldHint(f.name, f.help)}
|
|
176
|
+
{/if}
|
|
177
|
+
<div class="flex flex-wrap gap-2">
|
|
178
|
+
{#each f.options as option (option)}
|
|
179
|
+
<label class="label cursor-pointer justify-start gap-2">
|
|
180
|
+
<input
|
|
181
|
+
class="checkbox checkbox-sm"
|
|
182
|
+
type="checkbox"
|
|
183
|
+
{name}
|
|
184
|
+
value={option}
|
|
185
|
+
checked={selected.includes(option)}
|
|
186
|
+
/>
|
|
187
|
+
<span class="text-sm">{option}</span>
|
|
188
|
+
</label>
|
|
189
|
+
{/each}
|
|
190
|
+
</div>
|
|
191
|
+
</fieldset>
|
|
192
|
+
{:else if field.type === 'multiselect'}
|
|
193
|
+
{@const f = field as NamedField & MultiselectField}
|
|
194
|
+
{@const tagValue = ((frontmatter[f.name] ?? []) as string[]).join(', ')}
|
|
195
|
+
<label class="flex flex-col gap-1">
|
|
196
|
+
<span class="text-sm font-medium">{f.label}</span>
|
|
197
|
+
<input
|
|
198
|
+
class="input input-sm"
|
|
199
|
+
{name}
|
|
200
|
+
aria-label={f.label}
|
|
201
|
+
aria-describedby={f.help ? `${f.name}-hint` : undefined}
|
|
202
|
+
placeholder={f.placeholder ?? (f.help ? undefined : 'Separate values with commas')}
|
|
203
|
+
value={tagValue}
|
|
204
|
+
/>
|
|
205
|
+
{#if f.help}
|
|
206
|
+
{@render fieldHint(f.name, f.help)}
|
|
207
|
+
{/if}
|
|
208
|
+
</label>
|
|
209
|
+
{:else if field.type === 'image'}
|
|
210
|
+
{@const heroValue = frontmatter[field.name] as ImageValue | undefined}
|
|
211
|
+
<!-- The binding_property_non_reactive warning this logs is benign: the parent owns the $state
|
|
212
|
+
proxy and mutates it by reference, and the hero-alt focus flow reads the same prefixed key. -->
|
|
213
|
+
<MediaHeroField
|
|
214
|
+
bind:this={heroFieldRefs[name]}
|
|
215
|
+
field={{ name, label: field.label }}
|
|
216
|
+
value={heroValue}
|
|
217
|
+
decorative={heroValue?.decorative ?? false}
|
|
218
|
+
lead={field.type === 'image' && field.seo === true}
|
|
219
|
+
mediaLibrary={mediaLibrary}
|
|
220
|
+
conceptId={conceptId}
|
|
221
|
+
id={id}
|
|
222
|
+
onuploaded={onuploaded}
|
|
223
|
+
ondirty={markFieldsDirty}
|
|
224
|
+
onneedsaltchange={(n) => onheroneedsalt(name, n)}
|
|
225
|
+
/>
|
|
226
|
+
{:else if field.type === 'reference'}
|
|
227
|
+
<ReferenceField {field} value={(frontmatter[field.name] ?? '') as string} {targets} ondirty={markFieldsDirty} />
|
|
228
|
+
{:else if field.type === 'array' && field.item.type === 'reference'}
|
|
229
|
+
<ReferenceField {field} value={(frontmatter[field.name] ?? []) as string[]} {targets} ondirty={markFieldsDirty} />
|
|
230
|
+
{:else if field.type === 'object'}
|
|
231
|
+
<ObjectGroupField {field} {name} frontmatter={(frontmatter[field.name] ?? {}) as Record<string, unknown>} {markFieldsDirty} {mediaLibrary} {conceptId} {id} {heroFieldRefs} {targets} {onuploaded} {onheroneedsalt} {icons} />
|
|
232
|
+
{:else if field.type === 'array' && field.item.type !== 'reference'}
|
|
233
|
+
<RepeatableField {field} {name} rows={(frontmatter[field.name] ?? []) as unknown[]} {markFieldsDirty} {mediaLibrary} {conceptId} {id} {heroFieldRefs} {targets} {onuploaded} {onheroneedsalt} {icons} />
|
|
234
|
+
{:else if field.type === 'icon' && icons}
|
|
235
|
+
<div class="flex flex-col gap-1">
|
|
236
|
+
<span class="text-sm font-medium">{field.label}</span>
|
|
237
|
+
<IconPicker
|
|
238
|
+
{icons}
|
|
239
|
+
label={field.label}
|
|
240
|
+
describedby={field.help ? `${field.name}-hint` : undefined}
|
|
241
|
+
value={typeof frontmatter[field.name] === 'string' ? (frontmatter[field.name] as string) : ''}
|
|
242
|
+
required={field.required ?? false}
|
|
243
|
+
onChange={(glyph) => {
|
|
244
|
+
frontmatter[field.name] = glyph;
|
|
245
|
+
markFieldsDirty();
|
|
246
|
+
}}
|
|
247
|
+
/>
|
|
248
|
+
{#if field.help}
|
|
249
|
+
{@render fieldHint(field.name, field.help)}
|
|
250
|
+
{/if}
|
|
251
|
+
</div>
|
|
252
|
+
{:else}
|
|
253
|
+
<!-- The plain single-line text input arm: url, email, datetime, and the text fallback. They share
|
|
254
|
+
one shape and differ only in the input type inputType() resolves. -->
|
|
255
|
+
<label class="flex flex-col gap-1">
|
|
256
|
+
<span class="text-sm font-medium">{field.label}</span>
|
|
257
|
+
<input class="input input-sm" type={inputType(field.type)} {name} aria-label={field.label} aria-describedby={field.help ? `${field.name}-hint` : undefined} value={str(frontmatter[field.name])} required={field.required} />
|
|
258
|
+
{#if field.help}
|
|
259
|
+
{@render fieldHint(field.name, field.help)}
|
|
260
|
+
{/if}
|
|
261
|
+
</label>
|
|
262
|
+
{/if}
|
|
@@ -21,9 +21,11 @@ IconSet path data, matching the renderer's 256-unit viewBox.
|
|
|
21
21
|
onChange: (name: string) => void;
|
|
22
22
|
/** The group's accessible name, threaded from the field label. Defaults to Icon. */
|
|
23
23
|
label?: string;
|
|
24
|
+
/** The id of a describing element (a field hint), for the radiogroup's `aria-describedby`. */
|
|
25
|
+
describedby?: string;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
let { icons, value, required, onChange, label = 'Icon' }: Props = $props();
|
|
28
|
+
let { icons, value, required, onChange, label = 'Icon', describedby }: Props = $props();
|
|
27
29
|
|
|
28
30
|
// The radiogroup container, used to move focus with the selection per the ARIA radiogroup pattern.
|
|
29
31
|
let group: HTMLDivElement;
|
|
@@ -62,7 +64,7 @@ IconSet path data, matching the renderer's 256-unit viewBox.
|
|
|
62
64
|
}
|
|
63
65
|
</script>
|
|
64
66
|
|
|
65
|
-
<div class="flex flex-wrap gap-2" role="radiogroup" aria-label={label} bind:this={group}>
|
|
67
|
+
<div class="flex flex-wrap gap-2" role="radiogroup" aria-label={label} aria-required={required ? 'true' : undefined} aria-describedby={describedby} bind:this={group}>
|
|
66
68
|
{#if !required}
|
|
67
69
|
<button
|
|
68
70
|
type="button"
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
@component
|
|
3
|
-
The "Link to page" control
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
conventions. The plain-URL link is the toolbar's Web link dialog; this is for an internal target.
|
|
3
|
+
The "Link to page" control. It wraps EntryPicker, the shared search + concept-grouped target list, and
|
|
4
|
+
turns the chosen target into an inline cairn: internal link through the editor's registerInsertLink
|
|
5
|
+
seam. EntryPicker owns the list and search; this component owns the cairn-token meaning and the trigger.
|
|
6
|
+
The plain-URL link is the toolbar's Web link dialog; this is for an internal target.
|
|
8
7
|
-->
|
|
9
8
|
<script lang="ts">
|
|
10
9
|
import type { LinkTarget } from '../content/manifest.js';
|
|
11
10
|
import { formatCairnToken } from '../content/links.js';
|
|
11
|
+
import EntryPicker from './EntryPicker.svelte';
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
/** The site's link targets, from the committed manifest (editLoad ships them). */
|
|
@@ -24,46 +24,16 @@ conventions. The plain-URL link is the toolbar's Web link dialog; this is for an
|
|
|
24
24
|
|
|
25
25
|
let { linkTargets, insert, disabled = false, trigger = true }: Props = $props();
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Group filtered targets by concept, Pages first then Posts then any other concept, so the list
|
|
31
|
-
// reads in a stable order. The filter is a case-insensitive title substring.
|
|
32
|
-
const ORDER: Record<string, number> = { pages: 0, posts: 1 };
|
|
33
|
-
function rank(concept: string): number {
|
|
34
|
-
return ORDER[concept] ?? 2;
|
|
35
|
-
}
|
|
36
|
-
function heading(concept: string): string {
|
|
37
|
-
if (concept === 'pages') return 'Pages';
|
|
38
|
-
if (concept === 'posts') return 'Posts';
|
|
39
|
-
return concept.charAt(0).toUpperCase() + concept.slice(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const groups = $derived.by(() => {
|
|
43
|
-
const q = query.trim().toLowerCase();
|
|
44
|
-
const matched = q ? linkTargets.filter((t) => t.title.toLowerCase().includes(q)) : linkTargets;
|
|
45
|
-
const byConcept = new Map<string, LinkTarget[]>();
|
|
46
|
-
for (const t of matched) {
|
|
47
|
-
const list = byConcept.get(t.concept) ?? [];
|
|
48
|
-
list.push(t);
|
|
49
|
-
byConcept.set(t.concept, list);
|
|
50
|
-
}
|
|
51
|
-
return [...byConcept.entries()]
|
|
52
|
-
.map(([concept, items]) => ({ concept, heading: heading(concept), items }))
|
|
53
|
-
.sort((a, b) => rank(a.concept) - rank(b.concept) || a.heading.localeCompare(b.heading));
|
|
54
|
-
});
|
|
27
|
+
// The headless picker; this component drives it so it can carry the disabled trigger and the
|
|
28
|
+
// cairn-token meaning, while EntryPicker stays ignorant of both.
|
|
29
|
+
let picker = $state<{ open: () => void } | null>(null);
|
|
55
30
|
|
|
56
31
|
/** Open the picker programmatically, for a host that drives it without the trigger. */
|
|
57
32
|
export function open() {
|
|
58
|
-
|
|
59
|
-
dialog?.showModal();
|
|
60
|
-
}
|
|
61
|
-
function close() {
|
|
62
|
-
dialog?.close();
|
|
33
|
+
picker?.open();
|
|
63
34
|
}
|
|
64
35
|
function choose(target: LinkTarget) {
|
|
65
36
|
insert(formatCairnToken(target), target.title);
|
|
66
|
-
close();
|
|
67
37
|
}
|
|
68
38
|
</script>
|
|
69
39
|
|
|
@@ -73,45 +43,4 @@ conventions. The plain-URL link is the toolbar's Web link dialog; this is for an
|
|
|
73
43
|
</button>
|
|
74
44
|
{/if}
|
|
75
45
|
|
|
76
|
-
<
|
|
77
|
-
<div class="modal-box">
|
|
78
|
-
<div class="mb-3 flex items-center justify-between">
|
|
79
|
-
<h2 id="cairn-link-dialog-title" class="text-base font-semibold">Link to a page</h2>
|
|
80
|
-
<button type="button" class="btn btn-ghost btn-sm" aria-label="Close" onclick={close}>✕</button>
|
|
81
|
-
</div>
|
|
82
|
-
|
|
83
|
-
<input
|
|
84
|
-
type="search"
|
|
85
|
-
class="input input-bordered mb-3 w-full"
|
|
86
|
-
placeholder="Search by title"
|
|
87
|
-
aria-label="Search pages and posts"
|
|
88
|
-
bind:value={query}
|
|
89
|
-
/>
|
|
90
|
-
|
|
91
|
-
{#if groups.length === 0}
|
|
92
|
-
<p class="text-sm text-[var(--color-muted)]">No pages or posts to link to.</p>
|
|
93
|
-
{:else}
|
|
94
|
-
{#each groups as group (group.concept)}
|
|
95
|
-
<h3 class="mt-2 mb-1 text-xs font-semibold tracking-wide text-[var(--color-muted)] uppercase">{group.heading}</h3>
|
|
96
|
-
<ul class="menu w-full">
|
|
97
|
-
{#each group.items as target (`${target.concept}/${target.id}`)}
|
|
98
|
-
<li>
|
|
99
|
-
<button type="button" onclick={() => choose(target)}>
|
|
100
|
-
<span class="flex flex-col items-start">
|
|
101
|
-
<span class="font-medium">{target.title}</span>
|
|
102
|
-
<span class="text-xs text-[var(--color-muted)]">
|
|
103
|
-
{#if target.draft}<span class="badge badge-ghost badge-sm mr-1">Draft</span>{/if}
|
|
104
|
-
{#if target.date}{target.date}{/if}
|
|
105
|
-
</span>
|
|
106
|
-
</span>
|
|
107
|
-
</button>
|
|
108
|
-
</li>
|
|
109
|
-
{/each}
|
|
110
|
-
</ul>
|
|
111
|
-
{/each}
|
|
112
|
-
{/if}
|
|
113
|
-
</div>
|
|
114
|
-
<form method="dialog" class="modal-backdrop">
|
|
115
|
-
<button tabindex="-1" aria-label="Close">close</button>
|
|
116
|
-
</form>
|
|
117
|
-
</dialog>
|
|
46
|
+
<EntryPicker bind:this={picker} targets={linkTargets} {choose} trigger={false} />
|
|
@@ -60,6 +60,10 @@ popover's runUpload but resolves to this field, not an editor placeholder.
|
|
|
60
60
|
/** Whether the initial hero is an explicit decorative choice (an empty alt that is not debt).
|
|
61
61
|
* Defaults false; a fresh field with an empty alt reads as needs-alt. */
|
|
62
62
|
decorative?: boolean;
|
|
63
|
+
/** Whether this image leads the page and becomes the social card (a top-level SEO hero). When
|
|
64
|
+
* false (a gallery or nested image item), the empty state drops the hero-only social-card line
|
|
65
|
+
* and the copy reads neutrally. Defaults false. */
|
|
66
|
+
lead?: boolean;
|
|
63
67
|
/** The merged committed-plus-uploaded media library, keyed by content hash. */
|
|
64
68
|
mediaLibrary: Record<string, MediaLibraryEntry>;
|
|
65
69
|
/** The concept the entry belongs to (the upload action's route param). */
|
|
@@ -83,6 +87,7 @@ popover's runUpload but resolves to this field, not an editor placeholder.
|
|
|
83
87
|
field,
|
|
84
88
|
value,
|
|
85
89
|
decorative: decorativeInitial = false,
|
|
90
|
+
lead = false,
|
|
86
91
|
mediaLibrary,
|
|
87
92
|
conceptId,
|
|
88
93
|
id,
|
|
@@ -442,13 +447,15 @@ popover's runUpload but resolves to this field, not an editor placeholder.
|
|
|
442
447
|
<svg class="h-4 w-4" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z" /><circle cx="9" cy="9" r="2" /><path d="m21 15-3.1-3.1a2 2 0 0 0-2.8 0L6 21" /></svg>
|
|
443
448
|
</span>
|
|
444
449
|
<span class="flex min-w-0 flex-col gap-px">
|
|
445
|
-
<span class="text-[0.8125rem] font-medium">Add
|
|
450
|
+
<span class="text-[0.8125rem] font-medium">Add {field.label.toLowerCase()}</span>
|
|
446
451
|
<span class="text-[0.6875rem] text-[var(--color-muted)]">Drop an image here, or pick from the library</span>
|
|
447
452
|
</span>
|
|
448
453
|
</button>
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
454
|
+
{#if lead}
|
|
455
|
+
<p class="text-[0.6875rem] leading-snug text-[var(--color-muted)]">
|
|
456
|
+
This image leads the page, and it is the picture shown when the post is shared.
|
|
457
|
+
</p>
|
|
458
|
+
{/if}
|
|
452
459
|
{/if}
|
|
453
460
|
|
|
454
461
|
<!-- The committed value rides four named hidden inputs the save path's decode arm reads. They sit
|
|
@@ -468,7 +475,7 @@ popover's runUpload but resolves to this field, not an editor placeholder.
|
|
|
468
475
|
<div class="modal-box max-w-md">
|
|
469
476
|
<div class="mb-3 flex items-center justify-between gap-2">
|
|
470
477
|
<h2 id={titleId} class="text-[0.9375rem] font-semibold">
|
|
471
|
-
{view === 'chooser' ?
|
|
478
|
+
{view === 'chooser' ? `Add ${field.label.toLowerCase()}` : field.label}
|
|
472
479
|
</h2>
|
|
473
480
|
<button type="button" class="btn btn-ghost btn-xs btn-square" aria-label="Close" onclick={closeDialog}>
|
|
474
481
|
<svg class="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A labeled group of leaf fields, the editor arm for an `object` container. It renders each leaf one
|
|
4
|
+
level down through `FieldInput`, prefixing the leaf's form name with this group's name
|
|
5
|
+
(`${name}.${leafKey}`) so the nested decode in `frontmatter.ts` reads each value back into the right
|
|
6
|
+
sub-key. The group's value slice (the object, defaulting to `{}`) is passed straight through as the
|
|
7
|
+
leaf dispatcher's `frontmatter`, so a leaf reads `frontmatter[leafKey]` unchanged.
|
|
8
|
+
|
|
9
|
+
The legend uses the object's optional `label`; when the schema omits it (an object inside an array is
|
|
10
|
+
labeled by the array, so it carries no label of its own), a humanized field key stands in. The group
|
|
11
|
+
matches the Details fieldset/legend recipe so it reads as one of the panel's grouped sections.
|
|
12
|
+
-->
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import FieldInput from './FieldInput.svelte';
|
|
15
|
+
import type { NamedField } from '../content/types.js';
|
|
16
|
+
import type { ObjectField } from '../content/fields.js';
|
|
17
|
+
import type { LinkTarget } from '../content/manifest.js';
|
|
18
|
+
import type { MediaEntry } from '../media/manifest.js';
|
|
19
|
+
import type { MediaLibraryEntry } from '../media/library-entry.js';
|
|
20
|
+
import type { IconSet } from '../render/glyph.js';
|
|
21
|
+
import type MediaHeroField from './MediaHeroField.svelte';
|
|
22
|
+
|
|
23
|
+
interface Props {
|
|
24
|
+
/** The object descriptor to render; its `fields` are the leaves this group holds. */
|
|
25
|
+
field: NamedField & ObjectField;
|
|
26
|
+
/** The form name prefix for this group; each leaf renders at `${name}.${leafKey}`. */
|
|
27
|
+
name: string;
|
|
28
|
+
/** The object value slice this group reads from, keyed by leaf sub-key. */
|
|
29
|
+
frontmatter: Record<string, unknown>;
|
|
30
|
+
/** The site link targets the reference arm offers (threaded through to each leaf). */
|
|
31
|
+
targets: LinkTarget[];
|
|
32
|
+
/** Mark the edit form dirty; threaded to each leaf's media or reference arm. */
|
|
33
|
+
markFieldsDirty: () => void;
|
|
34
|
+
/** The merged committed-plus-uploaded media library, keyed by content hash. */
|
|
35
|
+
mediaLibrary: Record<string, MediaLibraryEntry>;
|
|
36
|
+
/** The concept the entry belongs to (the upload action's route param). */
|
|
37
|
+
conceptId: string;
|
|
38
|
+
/** The entry id (the upload action's route param). */
|
|
39
|
+
id: string;
|
|
40
|
+
/** The host's hero-field refs, keyed by the prefixed `name` so two groups do not collide. */
|
|
41
|
+
heroFieldRefs: Record<string, MediaHeroField>;
|
|
42
|
+
/** Called with the server-owned record on a successful upload, so the host merges it. */
|
|
43
|
+
onuploaded: (record: MediaEntry) => void;
|
|
44
|
+
/** Called when a hero's needs-alt status changes, keyed by the prefixed `name`. */
|
|
45
|
+
onheroneedsalt: (name: string, needsAlt: boolean) => void;
|
|
46
|
+
/** The site's icon set, forwarded to each leaf's icon arm. */
|
|
47
|
+
icons?: IconSet;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let {
|
|
51
|
+
field,
|
|
52
|
+
name,
|
|
53
|
+
frontmatter,
|
|
54
|
+
targets,
|
|
55
|
+
markFieldsDirty,
|
|
56
|
+
mediaLibrary,
|
|
57
|
+
conceptId,
|
|
58
|
+
id,
|
|
59
|
+
heroFieldRefs,
|
|
60
|
+
onuploaded,
|
|
61
|
+
onheroneedsalt,
|
|
62
|
+
icons,
|
|
63
|
+
}: Props = $props();
|
|
64
|
+
|
|
65
|
+
// Turn a field key into a sentence-case legend when the object carries no label of its own:
|
|
66
|
+
// 'social_card' -> 'Social card', 'ogImage' -> 'Og image'. The label, when set, wins.
|
|
67
|
+
function humanize(key: string): string {
|
|
68
|
+
const words = key
|
|
69
|
+
.replace(/[_-]+/g, ' ')
|
|
70
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
71
|
+
.trim();
|
|
72
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const legend = $derived(field.label ?? humanize(field.name));
|
|
76
|
+
const leaves = $derived(Object.entries(field.fields));
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<fieldset class="m-0 flex min-w-0 flex-col gap-3 border-0 p-0">
|
|
80
|
+
<legend class="text-sm font-medium">{legend}</legend>
|
|
81
|
+
{#each leaves as [leafKey, leaf] (leafKey)}
|
|
82
|
+
<FieldInput
|
|
83
|
+
field={{ ...leaf, name: leafKey }}
|
|
84
|
+
name={`${name}.${leafKey}`}
|
|
85
|
+
{frontmatter}
|
|
86
|
+
{targets}
|
|
87
|
+
{markFieldsDirty}
|
|
88
|
+
{mediaLibrary}
|
|
89
|
+
{conceptId}
|
|
90
|
+
{id}
|
|
91
|
+
{heroFieldRefs}
|
|
92
|
+
{onuploaded}
|
|
93
|
+
{onheroneedsalt}
|
|
94
|
+
{icons}
|
|
95
|
+
/>
|
|
96
|
+
{/each}
|
|
97
|
+
</fieldset>
|