sandcms 0.5.2 → 0.6.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 (151) hide show
  1. package/README.md +6 -4
  2. package/dist/admin/Account.svelte +4 -1
  3. package/dist/admin/ApiKeys.svelte +159 -0
  4. package/dist/admin/ApiKeys.svelte.d.ts +3 -0
  5. package/dist/admin/AssetAttachment.svelte +6 -4
  6. package/dist/admin/BlueprintFields.svelte +86 -0
  7. package/dist/admin/BlueprintFields.svelte.d.ts +15 -0
  8. package/dist/admin/Collection.svelte +40 -7
  9. package/dist/admin/Editor.svelte +57 -17
  10. package/dist/admin/Fields.svelte +217 -144
  11. package/dist/admin/Fields.svelte.d.ts +1 -0
  12. package/dist/admin/FocusPicker.svelte +136 -0
  13. package/dist/admin/FocusPicker.svelte.d.ts +11 -0
  14. package/dist/admin/Gallery.svelte +40 -34
  15. package/dist/admin/GlobalSearch.svelte +56 -0
  16. package/dist/admin/GlobalSearch.svelte.d.ts +3 -0
  17. package/dist/admin/Inbox.svelte +8 -5
  18. package/dist/admin/LinkField.svelte +116 -0
  19. package/dist/admin/LinkField.svelte.d.ts +17 -0
  20. package/dist/admin/MediaLibrary.svelte +41 -14
  21. package/dist/admin/MediaPicker.svelte +12 -2
  22. package/dist/admin/Navigation.svelte +62 -0
  23. package/dist/admin/Navigation.svelte.d.ts +7 -0
  24. package/dist/admin/NotificationSettings.svelte +2 -2
  25. package/dist/admin/SearchList.svelte +55 -0
  26. package/dist/admin/SearchList.svelte.d.ts +42 -0
  27. package/dist/admin/SelectField.svelte +3 -1
  28. package/dist/admin/SelectField.svelte.d.ts +1 -0
  29. package/dist/admin/Shell.svelte +16 -24
  30. package/dist/admin/UnsavedChanges.svelte +1 -1
  31. package/dist/admin/Users.svelte +11 -5
  32. package/dist/admin/client.js +2 -1
  33. package/dist/admin/generated/admin.css +145 -0
  34. package/dist/admin/navigation.d.ts +7 -0
  35. package/dist/admin/navigation.js +25 -0
  36. package/dist/admin/types.d.ts +5 -1
  37. package/dist/admin/uploads.js +27 -6
  38. package/dist/blueprints/conditions.d.ts +2 -0
  39. package/dist/blueprints/conditions.js +4 -0
  40. package/dist/blueprints/extends.d.ts +5 -0
  41. package/dist/blueprints/extends.js +76 -0
  42. package/dist/blueprints/files.d.ts +3 -1
  43. package/dist/blueprints/files.js +35 -2
  44. package/dist/blueprints/layout.d.ts +4 -0
  45. package/dist/blueprints/layout.js +12 -0
  46. package/dist/blueprints/load.d.ts +1 -1
  47. package/dist/blueprints/load.js +127 -12
  48. package/dist/blueprints/types.d.ts +38 -1
  49. package/dist/blueprints/validate.js +30 -6
  50. package/dist/cli/cloudflare.js +15 -3
  51. package/dist/cli/doctor.js +6 -3
  52. package/dist/cli/files.js +1 -1
  53. package/dist/cli/scaffold.js +8 -6
  54. package/dist/cli/setup.js +9 -2
  55. package/dist/cli/upgrade.js +2 -1
  56. package/dist/email-failure.d.ts +17 -0
  57. package/dist/email-failure.js +22 -0
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +1 -0
  60. package/dist/link.d.ts +17 -0
  61. package/dist/link.js +44 -0
  62. package/dist/notification-fields.js +1 -1
  63. package/dist/search.d.ts +8 -0
  64. package/dist/search.js +1 -0
  65. package/dist/server/access.d.ts +2 -0
  66. package/dist/server/access.js +59 -23
  67. package/dist/server/admin-load.d.ts +29 -2
  68. package/dist/server/admin-load.js +4 -2
  69. package/dist/server/api-access.d.ts +31 -0
  70. package/dist/server/api-access.js +52 -0
  71. package/dist/server/api-pagination.d.ts +34 -0
  72. package/dist/server/api-pagination.js +87 -0
  73. package/dist/server/api.js +224 -32
  74. package/dist/server/auth.d.ts +1150 -0
  75. package/dist/server/auth.js +11 -1
  76. package/dist/server/cms.d.ts +1208 -4
  77. package/dist/server/cms.js +2 -0
  78. package/dist/server/content.d.ts +17 -2
  79. package/dist/server/content.js +89 -14
  80. package/dist/server/db/migration-data.js +24 -0
  81. package/dist/server/db/migrations/0001_independent_password_resets.sql +3 -0
  82. package/dist/server/db/migrations/0002_email_failure_reason.sql +1 -0
  83. package/dist/server/db/migrations/0003_direct_r2_uploads.sql +10 -0
  84. package/dist/server/db/migrations/0004_agent_api_keys.sql +38 -0
  85. package/dist/server/db/migrations/0005_api_retention_and_pagination.sql +3 -0
  86. package/dist/server/db/migrations/0006_durable_media_deletion.sql +7 -0
  87. package/dist/server/db/migrations/meta/0001_snapshot.json +1197 -0
  88. package/dist/server/db/migrations/meta/0002_snapshot.json +1204 -0
  89. package/dist/server/db/migrations/meta/0003_snapshot.json +1281 -0
  90. package/dist/server/db/migrations/meta/0004_snapshot.json +1546 -0
  91. package/dist/server/db/migrations/meta/0005_snapshot.json +1572 -0
  92. package/dist/server/db/migrations/meta/0006_snapshot.json +1627 -0
  93. package/dist/server/db/migrations/meta/_journal.json +42 -0
  94. package/dist/server/db/schema.d.ts +742 -2
  95. package/dist/server/db/schema.js +77 -5
  96. package/dist/server/email/index.d.ts +11 -1
  97. package/dist/server/email/index.js +69 -6
  98. package/dist/server/forms.js +12 -2
  99. package/dist/server/hooks.d.ts +1 -1
  100. package/dist/server/hooks.js +37 -14
  101. package/dist/server/index.d.ts +1 -1
  102. package/dist/server/index.js +1 -1
  103. package/dist/server/links.d.ts +5 -0
  104. package/dist/server/links.js +44 -0
  105. package/dist/server/media/deletions.d.ts +2 -0
  106. package/dist/server/media/deletions.js +58 -0
  107. package/dist/server/media/presets.d.ts +10 -2
  108. package/dist/server/media/presets.js +14 -2
  109. package/dist/server/media/runner.d.ts +1 -1
  110. package/dist/server/media/runner.js +105 -8
  111. package/dist/server/media/service.d.ts +41 -3
  112. package/dist/server/media/service.js +146 -33
  113. package/dist/server/notifications.d.ts +1 -0
  114. package/dist/server/notifications.js +4 -2
  115. package/dist/server/request.d.ts +2 -0
  116. package/dist/server/request.js +5 -0
  117. package/dist/server/search.d.ts +13 -0
  118. package/dist/server/search.js +97 -0
  119. package/dist/worker/index.d.ts +3 -3
  120. package/dist/worker/index.js +205 -64
  121. package/dist/worker/local.d.ts +5 -0
  122. package/dist/worker/local.js +57 -0
  123. package/dist/worker/source.d.ts +1 -1
  124. package/dist/worker/source.js +2 -2
  125. package/dist/worker/uploads.d.ts +22 -0
  126. package/dist/worker/uploads.js +46 -0
  127. package/docs/acceptance.md +1 -1
  128. package/docs/api.md +73 -0
  129. package/docs/cloudflare.md +35 -8
  130. package/docs/content.md +181 -5
  131. package/docs/deployment.md +29 -4
  132. package/docs/email.md +14 -10
  133. package/docs/forms.md +3 -1
  134. package/docs/media.md +34 -5
  135. package/docs/package.md +7 -5
  136. package/docs/releases.md +56 -1
  137. package/docs/upgrades.md +59 -3
  138. package/package.json +19 -10
  139. package/templates/hooks.server.ts +3 -3
  140. package/templates/integration.ts +2 -2
  141. package/templates/routes/admin/+page.server.ts +2 -2
  142. package/templates/routes/admin/+page.svelte +1 -1
  143. package/templates/routes/api/+server.ts +2 -2
  144. package/templates/sandcms/blueprints/collections/projects.yaml +16 -8
  145. package/templates/sandcms/blueprints/fields/seo.yaml +5 -0
  146. package/templates/sandcms/blueprints/files/image.yaml +1 -0
  147. package/templates/sandcms/blueprints/pages/home.yaml +3 -0
  148. package/templates/sandcms/config.yaml +1 -0
  149. package/templates/sandcms/worker/index.ts +1 -1
  150. package/templates/sandcms/worker/local.ts +1 -0
  151. package/templates/sandcms/worker/wrangler.jsonc +1 -2
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # SandCMS
2
2
 
3
- **0.5.1** adds raster uploads up to 100 MB and images up to 100 MP using remote image transformations. Upgrade the website and protocol-3 media Worker together. Existing configured upload limits are preserved, and no database migration is required from 0.5.0. See the [0.5.1 release notes](docs/releases.md#051), [upgrade workflow](docs/upgrades.md) and [agent instructions](AGENTS.md).
3
+ **0.6.0** adds admin search, entry duplication, reusable and conditional blueprint fields, editor layouts, link fields, image focal points, and agent API keys. It also upgrades to SvelteKit 3 and introduces direct R2 uploads and durable media deletion. Existing supported data and project-owned YAML are preserved; upgrading requires retained migrations, framework configuration changes, and the protocol-5 media Worker. See the [0.6.0 release notes](docs/releases.md#060), [upgrade workflow](docs/upgrades.md#060-upgrade-checklist) and [agent instructions](AGENTS.md).
4
4
 
5
5
  SandCMS embeds a content workspace into a SvelteKit website. Developers own YAML blueprints and public routes; editors manage drafts, publication, images, and form submissions at `/admin`.
6
6
 
7
- This repository contains the `@sandquist-group/sandcms` package and a working example website. The private npm package includes the CMS, the `sandcms` CLI, and a minimal SvelteKit starter. See [publishing from macOS](docs/package.md#publish-from-macos) for release commands.
7
+ This repository contains the `sandcms` package and a working example website. The private npm package includes the CMS, the `sandcms` CLI, and a minimal SvelteKit starter. See [publishing from macOS](docs/package.md#publish-from-macos) for release commands.
8
8
 
9
9
  ## Run locally
10
10
 
@@ -31,7 +31,7 @@ bun run build
31
31
  bun run preview:network 10.123.59.34 # Use this machine's assigned ZeroTier IPv4 address.
32
32
  ```
33
33
 
34
- Open `https://10.123.59.34:5443/admin` and accept the local certificate prompt. HTTP port 5410 redirects to it. The helper keeps the configured origin, secure cookies, and media delivery on the same HTTPS address, with the website backend bound to loopback. Start the local Worker on port 8787 for images. Certificates are generated under ignored `data/preview-tls`; production uses the host's trusted HTTPS certificate. The ordinary localhost environment remains unchanged.
34
+ Open `https://10.123.59.34:5443/admin` and accept the local certificate prompt. HTTP port 5410 redirects to it. The helper keeps the configured origin, secure cookies, and media delivery on the same HTTPS address, with the website backend bound to loopback. For uploads from another device, set `SANDCMS_WORKER_URL` to a deployed staging Worker and allow the preview HTTPS origin in staging bucket CORS. The loopback local Worker is intended for localhost development. Certificates are generated under ignored `data/preview-tls`; production uses the host's trusted HTTPS certificate. The ordinary localhost environment remains unchanged.
35
35
 
36
36
  ## Included
37
37
 
@@ -39,7 +39,7 @@ Open `https://10.123.59.34:5443/admin` and accept the local certificate prompt.
39
39
  - Validated YAML pages, site settings, collections, and form metadata. All planned field types, nested groups, ordered repeatable groups, stable relations, and focused Tiptap rich text.
40
40
  - Independent draft/published snapshots, conflict detection, authenticated draft preview, required-field validation, and media readiness gates.
41
41
  - Better Auth password sign-in, optional TOTP and recovery codes, temporary-password changes, two roles, and operator recovery. No public registration or email services.
42
- - Durable SQLite upload spool and variant jobs, private originals, named versioned variants, sanitized SVG, global media selection, credits, usage warnings, and rebuilds.
42
+ - Direct presigned R2 uploads with durable SQLite finalization and variant jobs, private originals, named versioned variants, sanitized SVG, global media selection, credits, usage warnings, and rebuilds.
43
43
  - Developer-owned form actions, honeypot/rate limiting, schema snapshots, read/unread inbox, deletion, and safe CSV exports.
44
44
  - Safe setup/upgrade manifests, a frozen SQL baseline and incremental migration runner, doctor, Worker deployment commands, verified live backups, and guarded offline restores.
45
45
 
@@ -82,3 +82,5 @@ Stop the dev server before building. Browser tests use the production Bun server
82
82
  SandCMS is licensed under the [PolyForm Strict License 1.0.0](LICENSE). See the license for permitted uses and terms.
83
83
 
84
84
  Source is organized into `src/lib/blueprints`, `server`, `admin`, `worker`, and `cli`. `src/routes/(site)` demonstrates developer-owned pages; `(sandcms)` is the thin integration layer. Never commit content databases, secrets, or bootstrap passwords.
85
+
86
+ Agents can discover blueprints and map existing site content through the [authenticated content API](docs/api.md), with expiring Better Auth API keys and idempotent content writes.
@@ -1,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import * as Card from './components/ui/card/index.js';
3
3
  import Notice from './Notice.svelte';
4
+ import ApiKeys from './ApiKeys.svelte';
4
5
  import { untrack } from 'svelte';
5
6
  import type { AdminData } from './types.js';
6
7
  import { authClient, message } from './client.js';
@@ -35,7 +36,7 @@
35
36
  current = '';
36
37
  password = '';
37
38
  confirmation = '';
38
- notice = 'Password changed. Other sessions were signed out.';
39
+ notice = 'Password changed. Other sessions were signed out and API keys were revoked.';
39
40
  }
40
41
  } catch (e) {
41
42
  error = message(e);
@@ -188,3 +189,5 @@
188
189
  </div>{/if}
189
190
  </Card.Root>{/if}
190
191
  </div>
192
+
193
+ {#if data.user?.role === 'admin' && !data.user.mustChangePassword}<ApiKeys />{/if}
@@ -0,0 +1,159 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { api, message } from './client.js';
4
+ import Notice from './Notice.svelte';
5
+ import * as Card from './components/ui/card/index.js';
6
+ import { Button } from './components/ui/button/index.js';
7
+ import { Input } from './components/ui/input/index.js';
8
+ import { Label } from './components/ui/label/index.js';
9
+ import SelectField from './SelectField.svelte';
10
+ type Key = {
11
+ id: string;
12
+ name: string;
13
+ start: string;
14
+ prefix: string;
15
+ owner: string;
16
+ lastRequest: string | null;
17
+ expiresAt: string;
18
+ permissions: { cms?: string[] };
19
+ };
20
+ let keys = $state<Key[]>([]),
21
+ name = $state(''),
22
+ scope = $state('read'),
23
+ days = $state(30);
24
+ let secret = $state(''),
25
+ error = $state(''),
26
+ notice = $state(''),
27
+ busy = $state(true);
28
+ async function refresh() {
29
+ const response = await fetch('/api/cms/keys/list');
30
+ const data = await response.json();
31
+ if (!response.ok) throw new Error(data.error ?? data.message ?? 'Unable to load API keys');
32
+ keys = data.apiKeys;
33
+ }
34
+ onMount(() => {
35
+ refresh()
36
+ .catch((e) => {
37
+ error = message(e);
38
+ })
39
+ .finally(() => {
40
+ busy = false;
41
+ });
42
+ });
43
+ async function create() {
44
+ busy = true;
45
+ error = '';
46
+ notice = '';
47
+ secret = '';
48
+ try {
49
+ const result = await api<{ key: string }>('keys/create', {
50
+ name,
51
+ scope,
52
+ expiresIn: days * 86400
53
+ });
54
+ secret = result.key;
55
+ name = '';
56
+ await refresh();
57
+ } catch (e) {
58
+ error = message(e);
59
+ } finally {
60
+ busy = false;
61
+ }
62
+ }
63
+ async function revoke(id: string) {
64
+ busy = true;
65
+ error = '';
66
+ notice = '';
67
+ try {
68
+ await api('keys/delete', { id });
69
+ secret = '';
70
+ notice = 'API key revoked.';
71
+ await refresh();
72
+ } catch (e) {
73
+ error = message(e);
74
+ } finally {
75
+ busy = false;
76
+ }
77
+ }
78
+ </script>
79
+
80
+ <Card.Root class="cms-detail-card">
81
+ <h2>API keys</h2>
82
+ <p class="cms-muted">
83
+ Give agents access to content and media. Administrators can review and revoke keys for every
84
+ account. Keys cannot manage users or read form submissions.
85
+ </p>
86
+ {#if error}<Notice error>{error}</Notice>{/if}
87
+ {#if notice}<Notice>{notice}</Notice>{/if}
88
+ {#if secret}
89
+ <div class="cms-stack">
90
+ <p>Copy this key now. It will only be shown once.</p>
91
+ <Label for="api-key-secret">New API key</Label>
92
+ <Input id="api-key-secret" value={secret} readonly />
93
+ <Button
94
+ variant="outline"
95
+ onclick={() => {
96
+ secret = '';
97
+ }}>Dismiss key</Button
98
+ >
99
+ </div>
100
+ {/if}
101
+ <form
102
+ class="cms-stack"
103
+ onsubmit={(event) => {
104
+ event.preventDefault();
105
+ create();
106
+ }}
107
+ >
108
+ <div class="cms-field">
109
+ <Label for="api-key-name">Key name</Label>
110
+ <Input id="api-key-name" bind:value={name} required maxlength={100} />
111
+ </div>
112
+ <div class="cms-field">
113
+ <Label for="api-key-scope">Access</Label>
114
+ <SelectField
115
+ id="api-key-scope"
116
+ bind:value={scope}
117
+ clearable={false}
118
+ onchange={(value) => {
119
+ days = value === 'write' ? 7 : 30;
120
+ }}
121
+ options={[
122
+ { value: 'read', label: 'Read' },
123
+ { value: 'write', label: 'Write' }
124
+ ]}
125
+ />
126
+ <p class="cms-muted">
127
+ Write access includes reading, editing, publishing, and deleting content and media.
128
+ </p>
129
+ </div>
130
+ <div class="cms-field">
131
+ <Label for="api-key-days">Expires in days</Label>
132
+ <Input
133
+ id="api-key-days"
134
+ type="number"
135
+ bind:value={days}
136
+ min={1}
137
+ max={365}
138
+ step={1}
139
+ required
140
+ />
141
+ </div>
142
+ <Button type="submit" disabled={busy}>Create API key</Button>
143
+ </form>
144
+ {#each keys as key (key.id)}
145
+ <div class="cms-stack">
146
+ <p>
147
+ <strong>{key.name}</strong> · {key.permissions?.cms?.includes('write') ? 'Write' : 'Read'} · expires
148
+ {new Date(key.expiresAt).toLocaleDateString()}
149
+ </p>
150
+ <p class="cms-muted">
151
+ Owner: {key.owner} · Prefix: {key.prefix ?? ''} · Starts with: {key.start ?? ''} · Last used:
152
+ {key.lastRequest ? new Date(key.lastRequest).toLocaleString() : 'Never'}
153
+ </p>
154
+ <Button variant="outline" disabled={busy} onclick={() => revoke(key.id)}
155
+ >Revoke {key.name}</Button
156
+ >
157
+ </div>
158
+ {/each}
159
+ </Card.Root>
@@ -0,0 +1,3 @@
1
+ declare const ApiKeys: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type ApiKeys = ReturnType<typeof ApiKeys>;
3
+ export default ApiKeys;
@@ -30,7 +30,7 @@
30
30
  <Attachment.Root
31
31
  state={asset.status === 'failed'
32
32
  ? 'error'
33
- : asset.status === 'processing'
33
+ : asset.status === 'processing' || asset.status === 'deleting'
34
34
  ? 'processing'
35
35
  : 'done'}
36
36
  {orientation}
@@ -55,9 +55,11 @@
55
55
  <Attachment.Description class={asset.status === 'failed' ? 'whitespace-normal' : undefined}>
56
56
  {asset.status === 'failed'
57
57
  ? asset.error || 'Image processing failed.'
58
- : asset.status === 'processing'
59
- ? 'Processing image'
60
- : 'Ready'}
58
+ : asset.status === 'deleting'
59
+ ? 'Deleting image'
60
+ : asset.status === 'processing'
61
+ ? 'Processing image'
62
+ : 'Ready'}
61
63
  </Attachment.Description>
62
64
  </Attachment.Content>
63
65
  {#if onremove}
@@ -0,0 +1,86 @@
1
+ <script lang="ts">
2
+ import { untrack } from 'svelte';
3
+ import { Tabs } from 'bits-ui';
4
+ import type { Blueprint, Payload, FileBlueprint } from '../blueprints/types.js';
5
+ import type { Asset, Relations } from './types.js';
6
+ import { tabErrorCount, widthSpan } from '../blueprints/layout.js';
7
+ import Fields from './Fields.svelte';
8
+ let {
9
+ blueprint,
10
+ value,
11
+ onchange,
12
+ assets,
13
+ relations,
14
+ workerUrl,
15
+ fileBlueprints,
16
+ errors = {}
17
+ }: {
18
+ blueprint: Blueprint;
19
+ value: Payload;
20
+ onchange: (value: Payload) => void;
21
+ assets: Asset[];
22
+ relations: Relations;
23
+ workerUrl: string;
24
+ fileBlueprints?: FileBlueprint[];
25
+ errors?: Record<string, string>;
26
+ } = $props();
27
+ let active = $state(untrack(() => Object.keys(blueprint.tabs ?? {})[0] ?? ''));
28
+ const tabs = $derived(Object.entries(blueprint.tabs ?? {}));
29
+ $effect(() => {
30
+ if (!tabs.some(([id]) => id === active)) active = tabs[0]?.[0] ?? '';
31
+ });
32
+ $effect(() => {
33
+ const first = tabs.find(([, tab]) => tabErrorCount(tab, errors) > 0);
34
+ if (first) active = first[0];
35
+ });
36
+ </script>
37
+
38
+ {#snippet fields(keys: string[])}
39
+ <Fields
40
+ fields={Object.fromEntries(keys.map((key) => [key, blueprint.fields[key]]))}
41
+ {value}
42
+ {onchange}
43
+ {assets}
44
+ {relations}
45
+ {workerUrl}
46
+ {fileBlueprints}
47
+ {errors}
48
+ />
49
+ {/snippet}
50
+
51
+ {#if tabs.length}
52
+ <Tabs.Root bind:value={active}>
53
+ <Tabs.List class="cms-blueprint-tabs" aria-label="Content tabs">
54
+ {#each tabs as [id, tab]}
55
+ {@const count = tabErrorCount(tab, errors)}
56
+ <Tabs.Trigger value={id} class="cms-blueprint-tab">
57
+ {tab.label ?? id}{#if count}{' '}<span class="cms-error">
58
+ ({count} {count === 1 ? 'error' : 'errors'})</span
59
+ >{/if}
60
+ </Tabs.Trigger>
61
+ {/each}
62
+ </Tabs.List>
63
+ {#each tabs as [id, tab]}
64
+ <Tabs.Content value={id}>
65
+ {#if tab.fields}
66
+ {@render fields(tab.fields)}
67
+ {:else if tab.columns}
68
+ <div class="cms-blueprint-columns">
69
+ {#each tab.columns as column}
70
+ <div class="cms-blueprint-column" style:--sandcms-cms-span={widthSpan(column.width)}>
71
+ {#each Object.entries(column.sections) as [sectionId, section]}
72
+ <section class="cms-blueprint-section" aria-label={section.label ?? sectionId}>
73
+ {#if section.label}<h2>{section.label}</h2>{/if}
74
+ {@render fields(section.fields)}
75
+ </section>
76
+ {/each}
77
+ </div>
78
+ {/each}
79
+ </div>
80
+ {/if}
81
+ </Tabs.Content>
82
+ {/each}
83
+ </Tabs.Root>
84
+ {:else}
85
+ {@render fields(Object.keys(blueprint.fields))}
86
+ {/if}
@@ -0,0 +1,15 @@
1
+ import type { Blueprint, Payload, FileBlueprint } from '../blueprints/types.js';
2
+ import type { Asset, Relations } from './types.js';
3
+ type $$ComponentProps = {
4
+ blueprint: Blueprint;
5
+ value: Payload;
6
+ onchange: (value: Payload) => void;
7
+ assets: Asset[];
8
+ relations: Relations;
9
+ workerUrl: string;
10
+ fileBlueprints?: FileBlueprint[];
11
+ errors?: Record<string, string>;
12
+ };
13
+ declare const BlueprintFields: import("svelte").Component<$$ComponentProps, {}, "">;
14
+ type BlueprintFields = ReturnType<typeof BlueprintFields>;
15
+ export default BlueprintFields;
@@ -1,13 +1,31 @@
1
1
  <script lang="ts">
2
2
  import * as Table from './components/ui/table/index.js';
3
3
  import * as Card from './components/ui/card/index.js';
4
- import type { AdminData } from './types.js';
5
- import { date } from './client.js';
4
+ import { goto } from '$app/navigation';
5
+ import type { AdminData, Entry } from './types.js';
6
+ import { api, date, message } from './client.js';
7
+ import Notice from './Notice.svelte';
6
8
  import { Button } from './components/ui/button/index.js';
7
9
  import { Badge } from './components/ui/badge/index.js';
8
10
  import Plus from '@lucide/svelte/icons/plus';
9
11
  import Folder from '@lucide/svelte/icons/folder';
12
+ import SearchList from './SearchList.svelte';
10
13
  let { data }: { data: AdminData } = $props();
14
+ let duplicating = $state<string | null>(null),
15
+ error = $state('');
16
+ async function duplicate(entry: Entry) {
17
+ if (duplicating) return;
18
+ duplicating = entry.id;
19
+ error = '';
20
+ try {
21
+ const copy = await api<Entry>('content/duplicate', { id: entry.id, version: entry.version });
22
+ await goto('/admin/content/' + copy.blueprint + '/' + copy.id);
23
+ } catch (e) {
24
+ error = message(e);
25
+ } finally {
26
+ duplicating = null;
27
+ }
28
+ }
11
29
  </script>
12
30
 
13
31
  <div class="cms-page-heading">
@@ -21,17 +39,20 @@
21
39
  <Button href={'/admin/content/' + data.blueprint?.id + '/new'}><Plus size={16} />New entry</Button
22
40
  >
23
41
  </div>
42
+ {#if error}<Notice error>{error}</Notice>{/if}
43
+ <SearchList path={'content/list?blueprint=' + encodeURIComponent(data.blueprint!.id)} initial={data.entries ?? []} label="Search this collection" refreshKey={JSON.stringify(data.entries)}>
44
+ {#snippet children(entries)}
24
45
  <Card.Root class="gap-0 py-0">
25
- {#if data.entries?.length}
46
+ {#if entries.length}
26
47
  <Table.Root>
27
48
  <Table.Header
28
49
  ><Table.Row
29
50
  ><Table.Head>Title</Table.Head><Table.Head>Status</Table.Head><Table.Head
30
51
  >Last updated</Table.Head
31
- ></Table.Row
52
+ ><Table.Head><span class="sr-only">Actions</span></Table.Head></Table.Row
32
53
  ></Table.Header
33
54
  ><Table.Body
34
- >{#each data.entries as entry}<Table.Row
55
+ >{#each entries as entry}<Table.Row
35
56
  ><Table.Cell
36
57
  ><a class="cms-entry-link" href={'/admin/content/' + entry.blueprint + '/' + entry.id}
37
58
  >{String(entry.draft.title ?? 'Untitled')}</a
@@ -40,13 +61,25 @@
40
61
  ><Badge variant="outline">{entry.published ? 'Published' : 'Draft'}</Badge
41
62
  >{#if entry.published && JSON.stringify(entry.draft) !== JSON.stringify(entry.published)}
42
63
  <span class="cms-muted">Changes saved</span>{/if}</Table.Cell
43
- ><Table.Cell class="cms-muted">{date(entry.updatedAt)}</Table.Cell></Table.Row
64
+ ><Table.Cell class="cms-muted">{date(entry.updatedAt)}</Table.Cell><Table.Cell
65
+ ><Button
66
+ variant="outline"
67
+ size="sm"
68
+ disabled={duplicating !== null}
69
+ aria-label={'Duplicate ' + String(entry.draft.title ?? 'Untitled')}
70
+ onclick={() => duplicate(entry)}
71
+ >{duplicating === entry.id ? 'Duplicating…' : 'Duplicate'}</Button
72
+ ></Table.Cell
73
+ ></Table.Row
44
74
  >{/each}</Table.Body
45
75
  >
46
- </Table.Root>{:else}<div class="cms-empty">
76
+ </Table.Root>{:else if !data.entries?.length}<div class="cms-empty">
47
77
  <Folder size={32} />
48
78
  <h2>A fresh collection</h2>
49
79
  <p>Add your first entry to {data.blueprint?.label.toLowerCase()}.</p>
50
80
  <Button href={'/admin/content/' + data.blueprint?.id + '/new'}>Create an entry</Button>
51
81
  </div>{/if}
52
82
  </Card.Root>
83
+
84
+ {/snippet}
85
+ </SearchList>
@@ -1,14 +1,15 @@
1
1
  <script lang="ts">
2
2
  import { untrack, onMount } from 'svelte';
3
- import { goto, invalidateAll } from '$app/navigation';
3
+ import { goto, refreshAll } from '$app/navigation';
4
4
  import type { AdminData, Entry } from './types.js';
5
5
  import type { Payload } from '../blueprints/types.js';
6
6
  import { api, ApiError, message, date } from './client.js';
7
7
  import { Button } from './components/ui/button/index.js';
8
8
  import { Badge } from './components/ui/badge/index.js';
9
9
  import * as Dialog from './components/ui/dialog/index.js';
10
+ import { isLinkValue } from '../link.js';
10
11
  import { walkValues } from '../blueprints/validate.js';
11
- import Fields from './Fields.svelte';
12
+ import BlueprintFields from './BlueprintFields.svelte';
12
13
  import UnsavedChanges from './UnsavedChanges.svelte';
13
14
  import Notice from './Notice.svelte';
14
15
  import * as Card from './components/ui/card/index.js';
@@ -24,23 +25,36 @@
24
25
  const mediaState = $derived.by(() => {
25
26
  let pending = false,
26
27
  failed = false,
28
+ deleting = false,
27
29
  outdated = false;
28
30
  walkValues(data.blueprint!.fields, value, (field, v) => {
29
- if (field.type === 'media' || field.type === 'media-list')
30
- for (const id of Array.isArray(v) ? v : [v])
31
+ if (
32
+ field.type === 'media' ||
33
+ field.type === 'media-list' ||
34
+ (field.type === 'link' && isLinkValue(v) && v.type === 'file')
35
+ )
36
+ for (const id of field.type === 'link' && isLinkValue(v)
37
+ ? [v.value]
38
+ : Array.isArray(v)
39
+ ? v
40
+ : [v])
31
41
  if (id) {
32
42
  const asset = data.assets?.find((a) => a.id === id);
33
- if (asset?.status === 'failed') failed = true;
43
+ if (asset?.status === 'deleting') deleting = true;
44
+ else if (asset?.status === 'failed') failed = true;
34
45
  else if (!asset || asset.status === 'processing') pending = true;
35
- else if (asset.activeVersion !== data.mediaVersion) outdated = true;
46
+ else if (asset.activeVersion !== (asset.expectedVersion ?? data.mediaVersion))
47
+ outdated = true;
36
48
  }
37
49
  });
38
- return { pending, failed, outdated };
50
+ return { pending, failed, deleting, outdated };
39
51
  });
40
- const processing = $derived(mediaState.pending || mediaState.failed || mediaState.outdated);
52
+ const processing = $derived(
53
+ mediaState.pending || mediaState.failed || mediaState.deleting || mediaState.outdated
54
+ );
41
55
  onMount(() => {
42
56
  const timer = setInterval(() => {
43
- if (processing && !busy) void invalidateAll();
57
+ if (processing && !busy) void refreshAll();
44
58
  }, 3000);
45
59
  return () => clearInterval(timer);
46
60
  });
@@ -67,7 +81,7 @@
67
81
  notice = publish ? 'Published. Your website is up to date.' : 'Draft saved.';
68
82
  if (!data.entry && data.blueprint!.kind === 'collection')
69
83
  await goto('/admin/content/' + data.blueprint!.id + '/' + saved.id);
70
- else await invalidateAll();
84
+ else await refreshAll();
71
85
  } catch (e) {
72
86
  error = message(e);
73
87
  if (e instanceof ApiError) errors = e.fields;
@@ -88,6 +102,19 @@
88
102
  confirmDelete = false;
89
103
  }
90
104
  }
105
+ async function duplicate() {
106
+ if (!entry || busy || dirty) return;
107
+ busy = true;
108
+ error = '';
109
+ try {
110
+ const copy = await api<Entry>('content/duplicate', { id: entry.id, version: entry.version });
111
+ await goto('/admin/content/' + copy.blueprint + '/' + copy.id);
112
+ } catch (e) {
113
+ error = message(e);
114
+ } finally {
115
+ busy = false;
116
+ }
117
+ }
91
118
  const preview = $derived(
92
119
  entry && data.blueprint?.preview
93
120
  ? data.blueprint.preview
@@ -125,7 +152,8 @@
125
152
  </div>
126
153
  </div>
127
154
  {#if processing}<Notice>
128
- {#if mediaState.failed}An image failed to process. Open the media library to retry it.
155
+ {#if mediaState.deleting}An image is being deleted. Remove or replace it before publishing.
156
+ {:else if mediaState.failed}An image failed to process. Open the media library to retry it.
129
157
  {:else if mediaState.outdated}Image settings have changed. Ask your website developer to rebuild
130
158
  the media variants.
131
159
  {:else}Images are still processing. You can save your draft while they finish.{/if}
@@ -133,9 +161,9 @@
133
161
  {#if error}<Notice error>{error}</Notice>{/if}{#if notice}<Notice>{notice}</Notice>{/if}
134
162
  <div class="cms-editor-layout">
135
163
  <Card.Root class="cms-editor-fields">
136
- <Fields
164
+ <BlueprintFields
137
165
  fileBlueprints={data.fileBlueprints}
138
- fields={data.blueprint!.fields}
166
+ blueprint={data.blueprint!}
139
167
  {value}
140
168
  onchange={(v) => {
141
169
  value = v;
@@ -158,19 +186,31 @@
158
186
  variant="outline"
159
187
  disabled={busy}
160
188
  onclick={async () => {
189
+ busy = true;
190
+ error = '';
191
+ notice = '';
161
192
  try {
162
- entry = await api<Entry>('content/unpublish', { id: entry!.id });
193
+ entry = await api<Entry>('content/unpublish', {
194
+ id: entry!.id,
195
+ version: entry!.version
196
+ });
163
197
  notice = 'Entry unpublished.';
164
- await invalidateAll();
198
+ await refreshAll();
165
199
  } catch (e) {
166
200
  error = message(e);
201
+ } finally {
202
+ busy = false;
167
203
  }
168
204
  }}>Unpublish</Button
169
205
  >{/if}
170
206
  </Card.Root>
171
207
  {#if entry && data.blueprint?.kind === 'collection'}<Button
172
- variant="destructive"
173
- onclick={() => (confirmDelete = true)}>Delete entry</Button
208
+ variant="outline"
209
+ disabled={busy || dirty}
210
+ onclick={duplicate}>Duplicate entry</Button
211
+ >
212
+ {#if dirty}<p class="cms-muted">Save your changes before duplicating.</p>{/if}
213
+ <Button variant="destructive" onclick={() => (confirmDelete = true)}>Delete entry</Button
174
214
  >{/if}
175
215
  </aside>
176
216
  </div>