@velastack/cms 0.5.0 → 0.5.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 (99) hide show
  1. package/README.md +66 -43
  2. package/dist/components/admin-bar/admin-bar.css +1 -1
  3. package/dist/components/admin-bar/field-input.svelte +20 -1
  4. package/dist/components/admin-bar/field-input.svelte.d.ts +2 -1
  5. package/dist/components/admin-bar/fields-form.svelte +218 -0
  6. package/dist/components/admin-bar/fields-form.svelte.d.ts +16 -0
  7. package/dist/components/admin-bar/link-input.svelte +102 -0
  8. package/dist/components/admin-bar/link-input.svelte.d.ts +9 -0
  9. package/dist/components/admin-bar/list-field.svelte +93 -0
  10. package/dist/components/admin-bar/list-field.svelte.d.ts +20 -0
  11. package/dist/components/admin-bar/locales-panel.svelte +1 -1
  12. package/dist/components/admin-bar/page-options.d.ts +24 -0
  13. package/dist/components/admin-bar/page-options.js +53 -0
  14. package/dist/components/admin-bar/rich-text-input.svelte +92 -0
  15. package/dist/components/admin-bar/rich-text-input.svelte.d.ts +9 -0
  16. package/dist/components/admin-bar/structured-editor-popover.svelte +15 -6
  17. package/dist/components/cms/cms-collection.svelte +46 -0
  18. package/dist/components/cms/cms-collection.svelte.d.ts +25 -0
  19. package/dist/components/cms/cms-contact.svelte +26 -0
  20. package/dist/components/cms/cms-contact.svelte.d.ts +14 -0
  21. package/dist/components/cms/cms-faq.svelte +22 -0
  22. package/dist/components/cms/cms-faq.svelte.d.ts +15 -0
  23. package/dist/components/cms/cms-gallery.svelte +31 -0
  24. package/dist/components/cms/cms-gallery.svelte.d.ts +16 -0
  25. package/dist/components/cms/cms-hours-editable.svelte +160 -0
  26. package/dist/components/cms/cms-hours-editable.svelte.d.ts +17 -0
  27. package/dist/components/cms/cms-hours.svelte +42 -0
  28. package/dist/components/cms/cms-hours.svelte.d.ts +19 -0
  29. package/dist/components/cms/cms-image.svelte +3 -25
  30. package/dist/components/cms/cms-image.svelte.d.ts +3 -11
  31. package/dist/components/cms/cms-link-editable.svelte +4 -60
  32. package/dist/components/cms/cms-link.svelte +3 -23
  33. package/dist/components/cms/cms-link.svelte.d.ts +3 -10
  34. package/dist/components/cms/cms-logos.svelte +29 -0
  35. package/dist/components/cms/cms-logos.svelte.d.ts +16 -0
  36. package/dist/components/cms/cms-nav.svelte +22 -0
  37. package/dist/components/cms/cms-nav.svelte.d.ts +15 -0
  38. package/dist/components/cms/cms-pricing.svelte +36 -0
  39. package/dist/components/cms/cms-pricing.svelte.d.ts +14 -0
  40. package/dist/components/cms/cms-schedule.svelte +35 -0
  41. package/dist/components/cms/cms-schedule.svelte.d.ts +16 -0
  42. package/dist/components/cms/cms-social-links.svelte +35 -0
  43. package/dist/components/cms/cms-social-links.svelte.d.ts +15 -0
  44. package/dist/components/cms/cms-stats.svelte +31 -0
  45. package/dist/components/cms/cms-stats.svelte.d.ts +16 -0
  46. package/dist/components/cms/cms-steps.svelte +31 -0
  47. package/dist/components/cms/cms-steps.svelte.d.ts +16 -0
  48. package/dist/components/cms/cms-structured-editable.svelte +29 -0
  49. package/dist/components/cms/{cms-repeater-editable.svelte.d.ts → cms-structured-editable.svelte.d.ts} +12 -8
  50. package/dist/components/cms/cms-structured.svelte +50 -0
  51. package/dist/components/cms/cms-structured.svelte.d.ts +49 -0
  52. package/dist/components/cms/cms-team.svelte +22 -0
  53. package/dist/components/cms/cms-team.svelte.d.ts +15 -0
  54. package/dist/components/cms/cms-testimonials.svelte +36 -0
  55. package/dist/components/cms/cms-testimonials.svelte.d.ts +15 -0
  56. package/dist/components/cms/cms-timeline.svelte +35 -0
  57. package/dist/components/cms/cms-timeline.svelte.d.ts +16 -0
  58. package/dist/components/cms/index.d.ts +15 -1
  59. package/dist/components/cms/index.js +15 -1
  60. package/dist/core/shapes/collection.d.ts +60 -0
  61. package/dist/core/shapes/collection.js +194 -0
  62. package/dist/core/shapes/contact.d.ts +70 -0
  63. package/dist/core/shapes/contact.js +214 -0
  64. package/dist/core/shapes/faq.d.ts +12 -0
  65. package/dist/core/shapes/faq.js +48 -0
  66. package/dist/core/shapes/form.d.ts +46 -0
  67. package/dist/core/shapes/form.js +7 -0
  68. package/dist/core/shapes/hours.d.ts +91 -0
  69. package/dist/core/shapes/hours.js +325 -0
  70. package/dist/core/shapes/image.d.ts +15 -0
  71. package/dist/core/shapes/image.js +27 -0
  72. package/dist/core/shapes/index.d.ts +31 -0
  73. package/dist/core/shapes/index.js +13 -0
  74. package/dist/core/shapes/link.d.ts +15 -0
  75. package/dist/core/shapes/link.js +42 -0
  76. package/dist/core/shapes/nav.d.ts +21 -0
  77. package/dist/core/shapes/nav.js +71 -0
  78. package/dist/core/shapes/presets.d.ts +65 -0
  79. package/dist/core/shapes/presets.js +152 -0
  80. package/dist/core/shapes/pricing.d.ts +40 -0
  81. package/dist/core/shapes/pricing.js +115 -0
  82. package/dist/core/shapes/social-links.d.ts +19 -0
  83. package/dist/core/shapes/social-links.js +83 -0
  84. package/dist/core/shapes/team.d.ts +22 -0
  85. package/dist/core/shapes/team.js +70 -0
  86. package/dist/core/shapes/testimonials.d.ts +24 -0
  87. package/dist/core/shapes/testimonials.js +86 -0
  88. package/dist/{components/cms → core}/structured-registry.d.ts +2 -2
  89. package/dist/core/structured.d.ts +33 -10
  90. package/dist/core/structured.js +98 -47
  91. package/dist/editor.d.ts +4 -0
  92. package/dist/editor.js +4 -0
  93. package/dist/index.d.ts +22 -8
  94. package/dist/index.js +24 -5
  95. package/package.json +1 -1
  96. package/dist/components/cms/cms-repeater-editable.svelte +0 -137
  97. package/dist/components/cms/cms-repeater.svelte +0 -52
  98. package/dist/components/cms/cms-repeater.svelte.d.ts +0 -31
  99. /package/dist/{components/cms → core}/structured-registry.js +0 -0
@@ -0,0 +1,218 @@
1
+ <script lang="ts">
2
+ /**
3
+ * The generic structured form: one input per `FormField`, grouped into
4
+ * tabs when fields name a `group`, `half` fields sharing a row with the
5
+ * next one, and `list` fields rendered as cards through `ListField`.
6
+ * Works over a local draft: every change emits a new whole object.
7
+ */
8
+ import type { FormField } from '../../core/shapes/form.js';
9
+ import type { CmsImageValue } from '../../core/shapes/image.js';
10
+ import type { CmsLinkValue } from '../../core/shapes/link.js';
11
+ import { get, type Tree } from '../../core/path.js';
12
+ import { setIn } from '../../core/structured.js';
13
+ import FieldInput from './field-input.svelte';
14
+ import LinkInput from './link-input.svelte';
15
+ import RichTextInput from './rich-text-input.svelte';
16
+ import ListField from './list-field.svelte';
17
+ import { Button } from './ui/button/index.js';
18
+ import { Textarea } from './ui/textarea/index.js';
19
+ import * as Tabs from './ui/tabs/index.js';
20
+
21
+ type Props = {
22
+ fields: readonly FormField[];
23
+ value: Tree;
24
+ onChange: (next: Tree) => void;
25
+ };
26
+ let { fields, value, onChange }: Props = $props();
27
+
28
+ const GENERAL = 'General';
29
+
30
+ // Tabs: named groups in first-seen order; ungrouped fields share a
31
+ // "General" tab that comes first. One group means no tabs at all.
32
+ const groups = $derived.by(() => {
33
+ const names: string[] = [];
34
+ for (const f of fields) {
35
+ const g = f.group ?? GENERAL;
36
+ if (!names.includes(g)) names.push(g);
37
+ }
38
+ if (names.includes(GENERAL)) {
39
+ names.splice(names.indexOf(GENERAL), 1);
40
+ names.unshift(GENERAL);
41
+ }
42
+ return names.map((name) => ({
43
+ name,
44
+ rows: pairRows(fields.filter((f) => (f.group ?? GENERAL) === name))
45
+ }));
46
+ });
47
+ let tab = $state('');
48
+ $effect(() => {
49
+ if (!groups.some((g) => g.name === tab)) tab = groups[0]?.name ?? '';
50
+ });
51
+
52
+ /** A `half` field shares its row with the field after it. */
53
+ const pairRows = (list: readonly FormField[]): FormField[][] => {
54
+ const rows: FormField[][] = [];
55
+ for (let i = 0; i < list.length; i++) {
56
+ const f = list[i];
57
+ if (f.half && i + 1 < list.length && list[i + 1].type !== 'list') {
58
+ rows.push([f, list[i + 1]]);
59
+ i++;
60
+ } else rows.push([f]);
61
+ }
62
+ return rows;
63
+ };
64
+
65
+ const read = (key: string): unknown => get(value, key);
66
+ const write = (key: string, next: unknown) => onChange(setIn(value, key, next));
67
+
68
+ const str = (v: unknown): string => (typeof v === 'string' ? v : '');
69
+ const strings = (v: unknown): string[] =>
70
+ Array.isArray(v) ? v.map((s) => (typeof s === 'string' ? s : '')) : [];
71
+ const images = (v: unknown): CmsImageValue[] =>
72
+ Array.isArray(v) ? (v.filter((i) => i && typeof i === 'object') as CmsImageValue[]) : [];
73
+ const rating = (v: unknown): number => (typeof v === 'number' ? v : 0);
74
+ const asObject = (v: unknown): Tree => (v && typeof v === 'object' ? (v as Tree) : { url: null });
75
+ </script>
76
+
77
+ {#snippet input(f: FormField)}
78
+ {#if f.type === 'html'}
79
+ <RichTextInput
80
+ value={str(read(f.key))}
81
+ label={f.label}
82
+ onChange={(html) => write(f.key, html)}
83
+ />
84
+ {:else if f.type === 'link'}
85
+ <LinkInput
86
+ value={(read(f.key) as CmsLinkValue | null) ?? null}
87
+ label={f.label}
88
+ onChange={(next) => write(f.key, next)}
89
+ />
90
+ {:else if f.type === 'strings'}
91
+ <label class="vela:flex vela:flex-col vela:gap-1.5">
92
+ <span class="vela:text-[12px] vela:text-bar-text-secondary">{f.label}</span>
93
+ <Textarea
94
+ value={strings(read(f.key)).join('\n')}
95
+ placeholder={f.placeholder ?? 'One per line'}
96
+ oninput={(e) => write(f.key, e.currentTarget.value.split('\n'))}
97
+ />
98
+ </label>
99
+ {:else if f.type === 'rating'}
100
+ <div class="vela:flex vela:flex-col vela:gap-1.5">
101
+ <span class="vela:text-[12px] vela:text-bar-text-secondary">{f.label}</span>
102
+ <div class="vela:flex vela:gap-0.5" role="radiogroup" aria-label={f.label}>
103
+ {#each [1, 2, 3, 4, 5] as n (n)}
104
+ <button
105
+ type="button"
106
+ role="radio"
107
+ aria-checked={rating(read(f.key)) === n}
108
+ aria-label={`${n} of 5`}
109
+ class="vela:cursor-pointer vela:text-[18px] vela:leading-none {n <= rating(read(f.key))
110
+ ? 'vela:text-[var(--cms-status-warn-text)]'
111
+ : 'vela:text-bar-text-tertiary'}"
112
+ onclick={() => write(f.key, rating(read(f.key)) === n ? null : n)}
113
+ >
114
+ ★
115
+ </button>
116
+ {/each}
117
+ </div>
118
+ </div>
119
+ {:else if f.type === 'images'}
120
+ {@const list = images(read(f.key))}
121
+ <div class="vela:flex vela:flex-col vela:gap-2">
122
+ <span class="vela:text-[12px] vela:text-bar-text-secondary">{f.label}</span>
123
+ {#each list as img, i (i)}
124
+ <div class="vela:flex vela:items-start vela:gap-2">
125
+ <FieldInput
126
+ type="image"
127
+ value={img}
128
+ onChange={(next) =>
129
+ write(
130
+ f.key,
131
+ list.map((x, j) => (j === i ? next : x))
132
+ )}
133
+ class="vela:flex-1"
134
+ />
135
+ <Button
136
+ size="icon"
137
+ variant="ghost"
138
+ class="vela:h-9 vela:w-6 vela:shrink-0 vela:text-[var(--cms-status-error-text-base)]"
139
+ aria-label="Remove image"
140
+ onclick={() =>
141
+ write(
142
+ f.key,
143
+ list.filter((_, j) => j !== i)
144
+ )}
145
+ >
146
+ ×
147
+ </Button>
148
+ </div>
149
+ {/each}
150
+ <Button
151
+ variant="outline"
152
+ size="pill"
153
+ class="vela:self-start"
154
+ onclick={() => write(f.key, [...list, { url: null }])}
155
+ >
156
+ + Add image
157
+ </Button>
158
+ </div>
159
+ {:else if f.type === 'image'}
160
+ <FieldInput
161
+ type="image"
162
+ label={f.label}
163
+ value={asObject(read(f.key))}
164
+ placeholder={f.placeholder}
165
+ onChange={(next) => write(f.key, next)}
166
+ />
167
+ {:else if f.type === 'list'}
168
+ <ListField
169
+ label={f.label}
170
+ itemLabel={f.itemLabel ?? 'item'}
171
+ titleKey={f.titleKey}
172
+ fields={f.fields ?? []}
173
+ blank={f.blank ?? (() => ({}))}
174
+ items={(read(f.key) as Tree[] | undefined) ?? []}
175
+ onChange={(items) => write(f.key, items)}
176
+ />
177
+ {:else}
178
+ <FieldInput
179
+ type={f.type}
180
+ label={f.label}
181
+ value={read(f.key)}
182
+ placeholder={f.placeholder}
183
+ values={f.values}
184
+ names={f.names}
185
+ onChange={(next) => write(f.key, next)}
186
+ />
187
+ {/if}
188
+ {/snippet}
189
+
190
+ {#snippet rows(list: FormField[][])}
191
+ {#each list as row, i (i)}
192
+ {#if row.length === 2}
193
+ <div class="vela:grid vela:grid-cols-2 vela:gap-2 vela:items-start">
194
+ {@render input(row[0])}
195
+ {@render input(row[1])}
196
+ </div>
197
+ {:else}
198
+ {@render input(row[0])}
199
+ {/if}
200
+ {/each}
201
+ {/snippet}
202
+
203
+ {#if groups.length > 1}
204
+ <Tabs.Root bind:value={tab}>
205
+ <Tabs.List aria-label="Sections">
206
+ {#each groups as g (g.name)}
207
+ <Tabs.Trigger value={g.name}>{g.name}</Tabs.Trigger>
208
+ {/each}
209
+ </Tabs.List>
210
+ {#each groups as g (g.name)}
211
+ <Tabs.Content value={g.name} class="vela:flex vela:flex-col vela:gap-3 vela:pt-3">
212
+ {@render rows(g.rows)}
213
+ </Tabs.Content>
214
+ {/each}
215
+ </Tabs.Root>
216
+ {:else if groups.length === 1}
217
+ {@render rows(groups[0].rows)}
218
+ {/if}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The generic structured form: one input per `FormField`, grouped into
3
+ * tabs when fields name a `group`, `half` fields sharing a row with the
4
+ * next one, and `list` fields rendered as cards through `ListField`.
5
+ * Works over a local draft: every change emits a new whole object.
6
+ */
7
+ import type { FormField } from '../../core/shapes/form.js';
8
+ import { type Tree } from '../../core/path.js';
9
+ type Props = {
10
+ fields: readonly FormField[];
11
+ value: Tree;
12
+ onChange: (next: Tree) => void;
13
+ };
14
+ declare const FieldsForm: import("svelte").Component<Props, {}, "">;
15
+ type FieldsForm = ReturnType<typeof FieldsForm>;
16
+ export default FieldsForm;
@@ -0,0 +1,102 @@
1
+ <script lang="ts">
2
+ /**
3
+ * A link field inside a structured editor: a page from the site or an
4
+ * external URL, plus "open in a new tab". `value` is a `CmsLinkValue`
5
+ * or `null`; `onChange(null)` clears it.
6
+ */
7
+ import { untrack } from 'svelte';
8
+ import { page } from '$app/state';
9
+ import type { CmsLinkValue } from '../../core/shapes/link.js';
10
+ import { fetchPageOptions, pageOptionValue, type PageOption } from './page-options.js';
11
+ import { Input } from './ui/input/index.js';
12
+ import { Checkbox } from './ui/checkbox/index.js';
13
+
14
+ type Props = {
15
+ value: CmsLinkValue | null;
16
+ onChange: (next: CmsLinkValue | null) => void;
17
+ label?: string;
18
+ };
19
+ let { value, onChange, label }: Props = $props();
20
+
21
+ const endpoint = $derived(page.data.cms?.endpoint ?? '/api/cms');
22
+ const selectClass =
23
+ 'vela:flex vela:h-9 vela:w-full vela:rounded-md vela:border vela:border-[var(--cms-bar-divider)]' +
24
+ ' vela:bg-[var(--cms-bar-bg-hover)] vela:px-3 vela:py-1 vela:text-[13px] vela:text-bar-text' +
25
+ ' vela:focus:outline-none vela:focus:ring-2 vela:focus:ring-[var(--cms-accent)]';
26
+
27
+ let mode = $state<'page' | 'url'>(
28
+ untrack(() => (value?.href && !value.routeId ? 'url' : 'page'))
29
+ );
30
+ let options = $state<PageOption[] | null>(null);
31
+ $effect(() => {
32
+ if (mode === 'page' && options === null) {
33
+ void fetchPageOptions(endpoint).then((o) => (options = o));
34
+ }
35
+ });
36
+
37
+ const selected = $derived(
38
+ value?.routeId ? pageOptionValue(value.routeId, value.params ?? {}) : ''
39
+ );
40
+ const newTab = $derived(value?.newTab === true);
41
+
42
+ const emit = (next: CmsLinkValue) => {
43
+ onChange(next.href || next.routeId ? next : null);
44
+ };
45
+ const choosePage = (key: string) => {
46
+ const opt = options?.find((o) => o.value === key);
47
+ if (!opt) return emit({ newTab });
48
+ emit({ routeId: opt.routeId, params: opt.params, newTab });
49
+ };
50
+ const setUrl = (href: string) => emit({ href: href.trim(), newTab });
51
+ const setNewTab = (checked: boolean) => {
52
+ if (value) emit({ ...value, newTab: checked });
53
+ };
54
+ </script>
55
+
56
+ <div class="vela:flex vela:flex-col vela:gap-1.5">
57
+ <div class="vela:flex vela:items-center vela:justify-between">
58
+ <span class="vela:text-[12px] vela:text-bar-text-secondary">{label ?? 'Link'}</span>
59
+ <span
60
+ class="vela:inline-flex vela:rounded-md vela:border vela:border-[var(--cms-bar-divider)] vela:p-0.5 vela:text-[11px]"
61
+ role="radiogroup"
62
+ aria-label="Link type"
63
+ >
64
+ {#each [['page', 'Page'], ['url', 'URL']] as const as [key, name] (key)}
65
+ <button
66
+ type="button"
67
+ role="radio"
68
+ aria-checked={mode === key}
69
+ class="vela:rounded vela:px-2 vela:py-0.5 vela:cursor-pointer vela:text-bar-text-secondary aria-checked:vela:bg-[var(--cms-bar-bg-hover)] aria-checked:vela:text-bar-text"
70
+ onclick={() => (mode = key)}
71
+ >
72
+ {name}
73
+ </button>
74
+ {/each}
75
+ </span>
76
+ </div>
77
+ {#if mode === 'page'}
78
+ <select
79
+ class={selectClass}
80
+ value={selected}
81
+ onchange={(e) => choosePage(e.currentTarget.value)}
82
+ >
83
+ <option value="">{options === null ? 'Loading…' : '— No link —'}</option>
84
+ {#each options ?? [] as opt (opt.value)}
85
+ <option value={opt.value}>{opt.label}</option>
86
+ {/each}
87
+ </select>
88
+ {:else}
89
+ <Input
90
+ type="url"
91
+ value={value?.href ?? ''}
92
+ placeholder="https://…"
93
+ oninput={(e) => setUrl(e.currentTarget.value)}
94
+ />
95
+ {/if}
96
+ <label
97
+ class="vela:flex vela:items-center vela:gap-2 vela:text-[12px] vela:text-bar-text-secondary"
98
+ >
99
+ <Checkbox checked={newTab} onCheckedChange={(c) => setNewTab(c === true)} disabled={!value} />
100
+ Open in a new tab
101
+ </label>
102
+ </div>
@@ -0,0 +1,9 @@
1
+ import type { CmsLinkValue } from '../../core/shapes/link.js';
2
+ type Props = {
3
+ value: CmsLinkValue | null;
4
+ onChange: (next: CmsLinkValue | null) => void;
5
+ label?: string;
6
+ };
7
+ declare const LinkInput: import("svelte").Component<Props, {}, "">;
8
+ type LinkInput = ReturnType<typeof LinkInput>;
9
+ export default LinkInput;
@@ -0,0 +1,93 @@
1
+ <script lang="ts">
2
+ /**
3
+ * A list of items inside a structured form: one collapsible card per
4
+ * item, up/down/remove buttons, and an add button. Every item carries a
5
+ * stable `id` (new ones get a random one), so translations and reorders
6
+ * never lose track of an item.
7
+ */
8
+ import type { FormField } from '../../core/shapes/form.js';
9
+ import type { Tree } from '../../core/path.js';
10
+ import { moveItem, newItemId } from '../../core/structured.js';
11
+ import FieldsForm from './fields-form.svelte';
12
+ import ReorderButtons from './reorder-buttons.svelte';
13
+ import ChevronDownIcon from './icons/chevron-down.svelte';
14
+ import ChevronRightIcon from './icons/chevron-right.svelte';
15
+ import { Button } from './ui/button/index.js';
16
+
17
+ type Props = {
18
+ label: string;
19
+ itemLabel: string;
20
+ titleKey?: string;
21
+ fields: readonly FormField[];
22
+ blank: () => Tree;
23
+ items: Tree[];
24
+ onChange: (items: Tree[]) => void;
25
+ };
26
+ let { label, itemLabel, titleKey, fields, blank, items, onChange }: Props = $props();
27
+
28
+ let open = $state(new Set<string>());
29
+ const toggle = (id: string) => {
30
+ const next = new Set(open);
31
+ if (next.has(id)) next.delete(id);
32
+ else next.add(id);
33
+ open = next;
34
+ };
35
+
36
+ const idOf = (item: Tree, i: number): string =>
37
+ typeof item.id === 'string' && item.id !== '' ? item.id : `item-${i}`;
38
+
39
+ const titleOf = (item: Tree, i: number): string => {
40
+ const t = titleKey ? item[titleKey] : undefined;
41
+ if (typeof t === 'string' && t.trim() !== '') return t;
42
+ return `${itemLabel[0].toUpperCase()}${itemLabel.slice(1)} ${i + 1}`;
43
+ };
44
+
45
+ const add = () => {
46
+ const id = newItemId();
47
+ onChange([...items, { id, ...blank() }]);
48
+ open = new Set([...open, id]);
49
+ };
50
+ const replace = (i: number, next: Tree) => onChange(items.map((it, j) => (j === i ? next : it)));
51
+ </script>
52
+
53
+ <div class="vela:flex vela:flex-col vela:gap-2">
54
+ <span class="vela:text-[12px] vela:text-bar-text-secondary">{label}</span>
55
+ {#each items as item, i (idOf(item, i))}
56
+ {@const id = idOf(item, i)}
57
+ {@const expanded = open.has(id)}
58
+ <div class="vela:rounded-md vela:border vela:border-[var(--cms-bar-divider)]">
59
+ <div class="vela:flex vela:items-center vela:gap-1 vela:pl-1 vela:pr-1.5 vela:py-1">
60
+ <button
61
+ type="button"
62
+ class="vela:flex vela:flex-1 vela:min-w-0 vela:items-center vela:gap-1.5 vela:cursor-pointer vela:text-left vela:text-[13px] vela:text-bar-text"
63
+ aria-expanded={expanded}
64
+ onclick={() => toggle(id)}
65
+ >
66
+ {#if expanded}
67
+ <ChevronDownIcon class="vela:size-3.5 vela:shrink-0 vela:text-bar-text-tertiary" />
68
+ {:else}
69
+ <ChevronRightIcon class="vela:size-3.5 vela:shrink-0 vela:text-bar-text-tertiary" />
70
+ {/if}
71
+ <span class="vela:truncate">{titleOf(item, i)}</span>
72
+ </button>
73
+ <ReorderButtons
74
+ index={i}
75
+ count={items.length}
76
+ label={itemLabel}
77
+ onMove={(from, to) => onChange(moveItem(items, from, to))}
78
+ onRemove={(idx) => onChange(items.filter((_, j) => j !== idx))}
79
+ />
80
+ </div>
81
+ {#if expanded}
82
+ <div
83
+ class="vela:flex vela:flex-col vela:gap-3 vela:border-t vela:border-[var(--cms-bar-divider)] vela:p-3"
84
+ >
85
+ <FieldsForm {fields} value={item} onChange={(next) => replace(i, next)} />
86
+ </div>
87
+ {/if}
88
+ </div>
89
+ {/each}
90
+ <Button variant="outline" size="pill" class="vela:self-start" onclick={add}>
91
+ + Add {itemLabel}
92
+ </Button>
93
+ </div>
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A list of items inside a structured form: one collapsible card per
3
+ * item, up/down/remove buttons, and an add button. Every item carries a
4
+ * stable `id` (new ones get a random one), so translations and reorders
5
+ * never lose track of an item.
6
+ */
7
+ import type { FormField } from '../../core/shapes/form.js';
8
+ import type { Tree } from '../../core/path.js';
9
+ type Props = {
10
+ label: string;
11
+ itemLabel: string;
12
+ titleKey?: string;
13
+ fields: readonly FormField[];
14
+ blank: () => Tree;
15
+ items: Tree[];
16
+ onChange: (items: Tree[]) => void;
17
+ };
18
+ declare const ListField: import("svelte").Component<Props, {}, "">;
19
+ type ListField = ReturnType<typeof ListField>;
20
+ export default ListField;
@@ -2,7 +2,7 @@
2
2
  import { page } from '$app/state';
3
3
  import { cmsStore, type ReleaseItem } from '../cms/cms-store.svelte.js';
4
4
  import type { CmsPayload } from '../cms/scope.js';
5
- import { getStructured } from '../cms/structured-registry.js';
5
+ import { getStructured } from '../../core/structured-registry.js';
6
6
  import { countTranslations, extractTranslations } from '../../core/structured.js';
7
7
  import PanelFooter from './panel-footer.svelte';
8
8
  import PanelHeader from './panel-header.svelte';
@@ -0,0 +1,24 @@
1
+ type PageEntry = {
2
+ params: Record<string, string>;
3
+ isDraft: boolean;
4
+ isDeletePending: boolean;
5
+ redirectTo?: string;
6
+ gone?: boolean;
7
+ };
8
+ type PageRoute = {
9
+ routeId: string;
10
+ ownedParams: string[];
11
+ entries: PageEntry[];
12
+ };
13
+ export type PageOption = {
14
+ /** `routeId::{params}` — stable key for a select. */
15
+ value: string;
16
+ /** The resolved URL, shown to the editor. */
17
+ label: string;
18
+ routeId: string;
19
+ params: Record<string, string>;
20
+ };
21
+ export declare const pageOptionValue: (routeId: string, params: Record<string, string>) => string;
22
+ export declare const toPageOptions: (routes: PageRoute[]) => PageOption[];
23
+ export declare const fetchPageOptions: (endpoint: string) => Promise<PageOption[]>;
24
+ export {};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The site's pages as link targets, for the page picker in link editors.
3
+ * Fetched once per endpoint and shared by every picker on the page.
4
+ */
5
+ import { resolveRouteUrl } from './resolve-route.js';
6
+ export const pageOptionValue = (routeId, params) => `${routeId}::${JSON.stringify(params)}`;
7
+ export const toPageOptions = (routes) => {
8
+ const opts = [];
9
+ for (const r of routes) {
10
+ const entries = r.entries.length > 0
11
+ ? r.entries
12
+ : [{ params: {}, isDraft: false, isDeletePending: false }];
13
+ for (const ent of entries) {
14
+ // Tombstones (redirected / gone) aren't real link targets.
15
+ if (ent.redirectTo || ent.gone)
16
+ continue;
17
+ let url;
18
+ try {
19
+ url = resolveRouteUrl(r.routeId, ent.params);
20
+ }
21
+ catch {
22
+ continue;
23
+ }
24
+ opts.push({
25
+ value: pageOptionValue(r.routeId, ent.params),
26
+ label: url,
27
+ routeId: r.routeId,
28
+ params: ent.params
29
+ });
30
+ }
31
+ }
32
+ opts.sort((a, b) => a.label.localeCompare(b.label));
33
+ return opts;
34
+ };
35
+ const cache = new Map();
36
+ export const fetchPageOptions = (endpoint) => {
37
+ let p = cache.get(endpoint);
38
+ if (!p) {
39
+ p = fetch(`${endpoint}/pages`, { credentials: 'include' })
40
+ .then(async (res) => {
41
+ if (!res.ok)
42
+ return [];
43
+ const data = (await res.json());
44
+ return toPageOptions(data.routes);
45
+ })
46
+ .catch(() => {
47
+ cache.delete(endpoint);
48
+ return [];
49
+ });
50
+ cache.set(endpoint, p);
51
+ }
52
+ return p;
53
+ };
@@ -0,0 +1,92 @@
1
+ <script lang="ts">
2
+ /**
3
+ * A rich text field inside a structured editor: the same TipTap setup as
4
+ * the inline `CmsRichText` editor, bound to a local value instead of a
5
+ * CMS path.
6
+ */
7
+ import { onDestroy, onMount, untrack } from 'svelte';
8
+ import { Editor } from '@tiptap/core';
9
+ import StarterKit from '@tiptap/starter-kit';
10
+ import Toolbar from '../cms/cms-rich-text-toolbar.svelte';
11
+
12
+ type Props = {
13
+ value: string;
14
+ onChange: (html: string) => void;
15
+ label?: string;
16
+ placeholder?: string;
17
+ };
18
+ let { value, onChange, label }: Props = $props();
19
+
20
+ let host = $state<HTMLDivElement>();
21
+ let wrap = $state<HTMLDivElement>();
22
+ let editor = $state<Editor>();
23
+ let focused = $state(false);
24
+ let tick = $state(0);
25
+
26
+ onMount(() => {
27
+ editor = new Editor({
28
+ element: host,
29
+ extensions: [StarterKit.configure({ heading: { levels: [2, 3] } })],
30
+ content: value,
31
+ editorProps: { attributes: { class: 'cms-rich-text-input-pm' } },
32
+ onUpdate: ({ editor }) => onChange(editor.isEmpty ? '' : editor.getHTML()),
33
+ onTransaction: () => {
34
+ tick++;
35
+ }
36
+ });
37
+ });
38
+ onDestroy(() => editor?.destroy());
39
+
40
+ $effect(() => {
41
+ if (!editor || focused) return;
42
+ const next = value;
43
+ untrack(() => {
44
+ if (editor && editor.getHTML() !== next) {
45
+ editor.commands.setContent(next, { emitUpdate: false });
46
+ }
47
+ });
48
+ });
49
+ </script>
50
+
51
+ <div class="vela:flex vela:flex-col vela:gap-1.5">
52
+ {#if label}<span class="vela:text-[12px] vela:text-bar-text-secondary">{label}</span>{/if}
53
+ <div
54
+ class="cms-rich-text-input vela:relative vela:rounded-md vela:border vela:border-[var(--cms-bar-divider)] vela:px-3 vela:py-2 vela:text-[13px] vela:text-bar-text"
55
+ class:focused
56
+ bind:this={wrap}
57
+ onfocusin={() => (focused = true)}
58
+ onfocusout={(e) => {
59
+ const next = e.relatedTarget as Node | null;
60
+ if (next && wrap?.contains(next)) return;
61
+ focused = false;
62
+ }}
63
+ >
64
+ {#if editor && focused}
65
+ <div class="vela:mb-2">
66
+ <Toolbar {editor} {tick} />
67
+ </div>
68
+ {/if}
69
+ <div bind:this={host}></div>
70
+ </div>
71
+ </div>
72
+
73
+ <style>
74
+ .cms-rich-text-input.focused {
75
+ border-color: var(--cms-accent, #534ab7);
76
+ }
77
+ .cms-rich-text-input :global(.cms-rich-text-input-pm) {
78
+ outline: none;
79
+ min-height: 3em;
80
+ line-height: 1.5;
81
+ }
82
+ .cms-rich-text-input :global(.cms-rich-text-input-pm > :first-child) {
83
+ margin-top: 0;
84
+ }
85
+ .cms-rich-text-input :global(.cms-rich-text-input-pm > :last-child) {
86
+ margin-bottom: 0;
87
+ }
88
+ .cms-rich-text-input :global(.cms-rich-text-input-pm ul),
89
+ .cms-rich-text-input :global(.cms-rich-text-input-pm ol) {
90
+ padding-left: 1.25em;
91
+ }
92
+ </style>
@@ -0,0 +1,9 @@
1
+ type Props = {
2
+ value: string;
3
+ onChange: (html: string) => void;
4
+ label?: string;
5
+ placeholder?: string;
6
+ };
7
+ declare const RichTextInput: import("svelte").Component<Props, {}, "">;
8
+ type RichTextInput = ReturnType<typeof RichTextInput>;
9
+ export default RichTextInput;
@@ -24,6 +24,7 @@
24
24
  import PencilIcon from './icons/pencil.svelte';
25
25
  import { Button } from './ui/button/index.js';
26
26
  import { Input } from './ui/input/index.js';
27
+ import { Textarea } from './ui/textarea/index.js';
27
28
  import * as Popover from './ui/popover/index.js';
28
29
  import * as Sheet from './ui/sheet/index.js';
29
30
  import * as Tabs from './ui/tabs/index.js';
@@ -155,12 +156,20 @@
155
156
  <span class="vela:text-[12px] vela:text-bar-text-secondary vela:truncate">
156
157
  {f.source}
157
158
  </span>
158
- <Input
159
- type="text"
160
- value={translationValue(tab, f)}
161
- placeholder={f.source}
162
- oninput={(e) => setTranslation(tab, f, e.currentTarget.value)}
163
- />
159
+ {#if f.source.length > 80 || f.source.includes('<')}
160
+ <Textarea
161
+ value={translationValue(tab, f)}
162
+ placeholder={f.source}
163
+ oninput={(e) => setTranslation(tab, f, e.currentTarget.value)}
164
+ />
165
+ {:else}
166
+ <Input
167
+ type="text"
168
+ value={translationValue(tab, f)}
169
+ placeholder={f.source}
170
+ oninput={(e) => setTranslation(tab, f, e.currentTarget.value)}
171
+ />
172
+ {/if}
164
173
  </label>
165
174
  {/each}
166
175
  {/if}