sandcms 0.5.3 → 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 (144) hide show
  1. package/README.md +5 -3
  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/NotificationSettings.svelte +2 -2
  23. package/dist/admin/SearchList.svelte +55 -0
  24. package/dist/admin/SearchList.svelte.d.ts +42 -0
  25. package/dist/admin/SelectField.svelte +3 -1
  26. package/dist/admin/SelectField.svelte.d.ts +1 -0
  27. package/dist/admin/Shell.svelte +4 -2
  28. package/dist/admin/UnsavedChanges.svelte +1 -1
  29. package/dist/admin/Users.svelte +11 -5
  30. package/dist/admin/client.js +2 -1
  31. package/dist/admin/generated/admin.css +109 -0
  32. package/dist/admin/types.d.ts +5 -1
  33. package/dist/admin/uploads.js +27 -6
  34. package/dist/blueprints/conditions.d.ts +2 -0
  35. package/dist/blueprints/conditions.js +4 -0
  36. package/dist/blueprints/extends.d.ts +5 -0
  37. package/dist/blueprints/extends.js +76 -0
  38. package/dist/blueprints/files.d.ts +3 -1
  39. package/dist/blueprints/files.js +35 -2
  40. package/dist/blueprints/layout.d.ts +4 -0
  41. package/dist/blueprints/layout.js +12 -0
  42. package/dist/blueprints/load.d.ts +1 -1
  43. package/dist/blueprints/load.js +123 -12
  44. package/dist/blueprints/types.d.ts +35 -1
  45. package/dist/blueprints/validate.js +30 -6
  46. package/dist/cli/cloudflare.js +15 -3
  47. package/dist/cli/doctor.js +6 -3
  48. package/dist/cli/files.js +1 -1
  49. package/dist/cli/scaffold.js +8 -6
  50. package/dist/cli/setup.js +9 -2
  51. package/dist/cli/upgrade.js +2 -1
  52. package/dist/email-failure.d.ts +17 -0
  53. package/dist/email-failure.js +22 -0
  54. package/dist/index.d.ts +2 -1
  55. package/dist/index.js +1 -0
  56. package/dist/link.d.ts +17 -0
  57. package/dist/link.js +44 -0
  58. package/dist/notification-fields.js +1 -1
  59. package/dist/search.d.ts +8 -0
  60. package/dist/search.js +1 -0
  61. package/dist/server/access.d.ts +2 -0
  62. package/dist/server/access.js +59 -23
  63. package/dist/server/admin-load.d.ts +11 -2
  64. package/dist/server/admin-load.js +4 -2
  65. package/dist/server/api-access.d.ts +31 -0
  66. package/dist/server/api-access.js +52 -0
  67. package/dist/server/api-pagination.d.ts +34 -0
  68. package/dist/server/api-pagination.js +87 -0
  69. package/dist/server/api.js +224 -32
  70. package/dist/server/auth.d.ts +1150 -0
  71. package/dist/server/auth.js +11 -1
  72. package/dist/server/cms.d.ts +1208 -4
  73. package/dist/server/cms.js +2 -0
  74. package/dist/server/content.d.ts +17 -2
  75. package/dist/server/content.js +89 -14
  76. package/dist/server/db/migration-data.js +24 -0
  77. package/dist/server/db/migrations/0001_independent_password_resets.sql +3 -0
  78. package/dist/server/db/migrations/0002_email_failure_reason.sql +1 -0
  79. package/dist/server/db/migrations/0003_direct_r2_uploads.sql +10 -0
  80. package/dist/server/db/migrations/0004_agent_api_keys.sql +38 -0
  81. package/dist/server/db/migrations/0005_api_retention_and_pagination.sql +3 -0
  82. package/dist/server/db/migrations/0006_durable_media_deletion.sql +7 -0
  83. package/dist/server/db/migrations/meta/0001_snapshot.json +1197 -0
  84. package/dist/server/db/migrations/meta/0002_snapshot.json +1204 -0
  85. package/dist/server/db/migrations/meta/0003_snapshot.json +1281 -0
  86. package/dist/server/db/migrations/meta/0004_snapshot.json +1546 -0
  87. package/dist/server/db/migrations/meta/0005_snapshot.json +1572 -0
  88. package/dist/server/db/migrations/meta/0006_snapshot.json +1627 -0
  89. package/dist/server/db/migrations/meta/_journal.json +42 -0
  90. package/dist/server/db/schema.d.ts +742 -2
  91. package/dist/server/db/schema.js +77 -5
  92. package/dist/server/email/index.d.ts +11 -1
  93. package/dist/server/email/index.js +69 -6
  94. package/dist/server/forms.js +12 -2
  95. package/dist/server/hooks.d.ts +1 -1
  96. package/dist/server/hooks.js +37 -14
  97. package/dist/server/index.d.ts +1 -1
  98. package/dist/server/index.js +1 -1
  99. package/dist/server/links.d.ts +5 -0
  100. package/dist/server/links.js +44 -0
  101. package/dist/server/media/deletions.d.ts +2 -0
  102. package/dist/server/media/deletions.js +58 -0
  103. package/dist/server/media/presets.d.ts +10 -2
  104. package/dist/server/media/presets.js +14 -2
  105. package/dist/server/media/runner.d.ts +1 -1
  106. package/dist/server/media/runner.js +105 -8
  107. package/dist/server/media/service.d.ts +41 -3
  108. package/dist/server/media/service.js +146 -33
  109. package/dist/server/notifications.d.ts +1 -0
  110. package/dist/server/notifications.js +4 -2
  111. package/dist/server/request.d.ts +2 -0
  112. package/dist/server/request.js +5 -0
  113. package/dist/server/search.d.ts +13 -0
  114. package/dist/server/search.js +97 -0
  115. package/dist/worker/index.d.ts +3 -3
  116. package/dist/worker/index.js +205 -64
  117. package/dist/worker/local.d.ts +5 -0
  118. package/dist/worker/local.js +57 -0
  119. package/dist/worker/source.d.ts +1 -1
  120. package/dist/worker/source.js +2 -2
  121. package/dist/worker/uploads.d.ts +22 -0
  122. package/dist/worker/uploads.js +46 -0
  123. package/docs/api.md +73 -0
  124. package/docs/cloudflare.md +35 -8
  125. package/docs/content.md +162 -4
  126. package/docs/deployment.md +29 -4
  127. package/docs/email.md +11 -7
  128. package/docs/forms.md +3 -1
  129. package/docs/media.md +33 -4
  130. package/docs/package.md +6 -4
  131. package/docs/releases.md +46 -1
  132. package/docs/upgrades.md +55 -3
  133. package/package.json +19 -10
  134. package/templates/hooks.server.ts +2 -2
  135. package/templates/integration.ts +1 -1
  136. package/templates/routes/admin/+page.server.ts +1 -1
  137. package/templates/routes/api/+server.ts +1 -1
  138. package/templates/sandcms/blueprints/collections/projects.yaml +16 -8
  139. package/templates/sandcms/blueprints/fields/seo.yaml +5 -0
  140. package/templates/sandcms/blueprints/files/image.yaml +1 -0
  141. package/templates/sandcms/blueprints/pages/home.yaml +1 -0
  142. package/templates/sandcms/config.yaml +1 -0
  143. package/templates/sandcms/worker/local.ts +1 -0
  144. package/templates/sandcms/worker/wrangler.jsonc +1 -2
@@ -1,6 +1,8 @@
1
1
  <script lang="ts">
2
2
  import type { Field, FileBlueprint, Json, Payload } from '../blueprints/types.js';
3
3
  import { selectGalleryImages } from '../blueprints/gallery.js';
4
+ import { fieldVisible } from '../blueprints/conditions.js';
5
+ import { effectiveMetadata } from '../blueprints/files.js';
4
6
  import type { Asset, Relations } from './types.js';
5
7
  import { assetUrl } from './client.js';
6
8
  import Fields from './Fields.svelte';
@@ -36,6 +38,7 @@
36
38
  if (field.type === 'boolean') return false;
37
39
  if (['repeatable', 'multiselect'].includes(field.type)) return [];
38
40
  if (field.type === 'group') return {};
41
+ if (field.type === 'link') return { type: 'url', value: '' };
39
42
  if (field.type === 'richtext') return { type: 'doc', content: [] };
40
43
  return '';
41
44
  }
@@ -59,6 +62,7 @@
59
62
  {#snippet children(row, i)}
60
63
  {@const asset = all.find((a) => a.id === row.image)}
61
64
  {@const metadata = asset ? asset.metadata : {}}
65
+ {@const effective = effectiveMetadata(metadata, row, field.fields ?? {})}
62
66
  <div class="cms-stack">
63
67
  <div class="cms-selected-image">
64
68
  {#if asset && assetUrl(asset, workerUrl)}<img
@@ -75,42 +79,44 @@
75
79
  </div>
76
80
  {#if errors[i + '.image']}<p class="cms-error" role="alert">{errors[i + '.image']}</p>{/if}
77
81
  {#each Object.entries(field.fields ?? {}) as [key, definition]}
78
- {@const label = definition.label ?? key.charAt(0).toUpperCase() + key.slice(1)}
79
- <div class="cms-field">
80
- <div class="cms-checkbox">
81
- <Checkbox
82
- id={`${id}-${i}-inherit-${key}`}
83
- checked={row[key] == null}
84
- onCheckedChange={(checked) =>
85
- set(
86
- i,
87
- key,
88
- checked ? undefined : structuredClone(metadata[key] ?? empty(definition))
82
+ {#if fieldVisible(definition, effective)}
83
+ {@const label = definition.label ?? key.charAt(0).toUpperCase() + key.slice(1)}
84
+ <div class="cms-field">
85
+ <div class="cms-checkbox">
86
+ <Checkbox
87
+ id={`${id}-${i}-inherit-${key}`}
88
+ checked={row[key] == null}
89
+ onCheckedChange={(checked) =>
90
+ set(
91
+ i,
92
+ key,
93
+ checked ? undefined : structuredClone(metadata[key] ?? empty(definition))
94
+ )}
95
+ />
96
+ <Label for={`${id}-${i}-inherit-${key}`}>Use asset {label.toLowerCase()}</Label>
97
+ </div>
98
+ {#if row[key] == null}<p class="cms-muted">
99
+ {label}: {inherited(definition, metadata[key])}
100
+ </p>
101
+ {:else}
102
+ <Fields
103
+ fields={{ [key]: definition }}
104
+ value={effective}
105
+ {assets}
106
+ {relations}
107
+ {workerUrl}
108
+ {fileBlueprints}
109
+ prefix={`${id}-${i}`}
110
+ errors={Object.fromEntries(
111
+ Object.entries(errors)
112
+ .filter(([path]) => path.startsWith(`${i}.`))
113
+ .map(([path, error]) => [path.slice(String(i).length + 1), error])
89
114
  )}
90
- />
91
- <Label for={`${id}-${i}-inherit-${key}`}>Use asset {label.toLowerCase()}</Label>
115
+ onchange={(next) => set(i, key, next[key] ?? empty(definition))}
116
+ />
117
+ {/if}
92
118
  </div>
93
- {#if row[key] == null}<p class="cms-muted">
94
- {label}: {inherited(definition, metadata[key])}
95
- </p>
96
- {:else}
97
- <Fields
98
- fields={{ [key]: definition }}
99
- value={{ [key]: row[key] }}
100
- {assets}
101
- {relations}
102
- {workerUrl}
103
- {fileBlueprints}
104
- prefix={`${id}-${i}`}
105
- errors={Object.fromEntries(
106
- Object.entries(errors)
107
- .filter(([path]) => path.startsWith(`${i}.`))
108
- .map(([path, error]) => [path.slice(String(i).length + 1), error])
109
- )}
110
- onchange={(next) => set(i, key, next[key] ?? empty(definition))}
111
- />
112
- {/if}
113
- </div>
119
+ {/if}
114
120
  {/each}
115
121
  </div>
116
122
  {/snippet}
@@ -0,0 +1,56 @@
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte';
3
+ import { afterNavigate } from '$app/navigation';
4
+ import type { SearchResult } from '../search.js';
5
+ import SearchList from './SearchList.svelte';
6
+ import * as Dialog from './components/ui/dialog/index.js';
7
+ import { Button } from './components/ui/button/index.js';
8
+ import Search from '@lucide/svelte/icons/search';
9
+ let open = $state(false);
10
+ let container: HTMLDivElement;
11
+ afterNavigate(() => open = false);
12
+ onMount(() => {
13
+ const shortcut = (event: KeyboardEvent) => {
14
+ if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k') {
15
+ event.preventDefault(); open = !open;
16
+ }
17
+ };
18
+ window.addEventListener('keydown', shortcut);
19
+ return () => window.removeEventListener('keydown', shortcut);
20
+ });
21
+ function navigateResults(event: KeyboardEvent) {
22
+ if (!open || !container?.contains(document.activeElement) || !['ArrowDown', 'ArrowUp'].includes(event.key)) return;
23
+ const links = Array.from(container.querySelectorAll<HTMLAnchorElement>('a'));
24
+ if (!links.length) return;
25
+ const index = links.indexOf(document.activeElement as HTMLAnchorElement);
26
+ event.preventDefault();
27
+ links[index < 0 ? (event.key === 'ArrowDown' ? 0 : links.length - 1) : (index + (event.key === 'ArrowDown' ? 1 : -1) + links.length) % links.length].focus();
28
+ }
29
+ </script>
30
+
31
+ <svelte:window onkeydown={navigateResults} />
32
+ <Dialog.Root bind:open>
33
+ <Dialog.Trigger>{#snippet child({ props })}<Button {...props} variant="outline" class="cms-search-trigger" aria-label="Search admin">
34
+ <Search size={16} /> <span>Search</span> <kbd>⌘ / Ctrl K</kbd>
35
+ </Button>{/snippet}</Dialog.Trigger>
36
+ <Dialog.Content portalProps={{ disabled: true }} class="max-h-[80vh] overflow-y-auto">
37
+ <Dialog.Header><Dialog.Title>Search admin</Dialog.Title>
38
+ <Dialog.Description>Find pages, saved content, and media.</Dialog.Description></Dialog.Header>
39
+ <div bind:this={container} role="group" aria-label="Search results">
40
+ {#if open}<SearchList path="search" initial={[] as SearchResult[]} label="Search pages, content, and media">
41
+ {#snippet children(items)}
42
+ {#each ['page', 'content', 'media'] as kind}
43
+ {@const matches = items.filter((item) => item.kind === kind)}
44
+ {#if matches.length}<div class="cms-stack">
45
+ <h3>{kind === 'page' ? 'Pages' : kind === 'content' ? 'Content' : 'Media'}</h3>
46
+ {#each matches as item (item.id)}<a class="cms-search-result" href={item.href} onclick={() => open = false}>
47
+ <strong>{item.title}</strong><span class="cms-muted">{item.label}</span>
48
+ {#if item.excerpt}<span class="cms-muted">{item.excerpt}</span>{/if}
49
+ </a>{/each}
50
+ </div>{/if}
51
+ {/each}
52
+ {/snippet}
53
+ </SearchList>{/if}
54
+ </div>
55
+ </Dialog.Content>
56
+ </Dialog.Root>
@@ -0,0 +1,3 @@
1
+ declare const GlobalSearch: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type GlobalSearch = ReturnType<typeof GlobalSearch>;
3
+ export default GlobalSearch;
@@ -1,9 +1,10 @@
1
1
  <script lang="ts">
2
+ import { emailFailureMessage } from '../email-failure.js';
2
3
  import NotificationSettings from './NotificationSettings.svelte';
3
4
  import { onMount } from 'svelte';
4
5
  import * as Table from './components/ui/table/index.js';
5
6
  import * as Card from './components/ui/card/index.js';
6
- import { invalidateAll } from '$app/navigation';
7
+ import { refreshAll } from '$app/navigation';
7
8
  import type { AdminData, Submission } from './types.js';
8
9
  import { api, date, message } from './client.js';
9
10
  import { Button } from './components/ui/button/index.js';
@@ -32,7 +33,7 @@
32
33
  error = '';
33
34
  try {
34
35
  await api(path, body);
35
- await invalidateAll();
36
+ await refreshAll();
36
37
  } catch (e) {
37
38
  error = message(e);
38
39
  }
@@ -113,16 +114,18 @@
113
114
  {outcome.to}: {outcome.status === 'sending'
114
115
  ? 'Sending or outcome unknown'
115
116
  : outcome.status === 'accepted'
116
- ? 'Accepted by email provider'
117
+ ? 'Accepted by mail server'
117
118
  : 'Failed'}
119
+ {#if outcome.status === 'failed'}
120
+ — {emailFailureMessage(outcome.failureReason)}{/if}
118
121
  </p>{/each}
119
122
  {#if !current.notification.outcomes.length}<p>
120
123
  No recipients are currently available. Ask an admin to update notification settings.
121
124
  </p>{/if}
122
125
  {:else}<p>No email attempt recorded.</p>{/if}
123
126
  <p class="cms-muted">
124
- Emails send directly without automatic retries. Resending uses current settings and can
125
- produce duplicates.
127
+ Mail server acceptance does not confirm inbox delivery. Emails send directly without
128
+ automatic retries. Resending uses current settings and can produce duplicates.
126
129
  </p>
127
130
  {#if data.emailEnabled && data.notificationsEnabled}<Button
128
131
  variant="outline"
@@ -0,0 +1,116 @@
1
+ <script lang="ts">
2
+ import type { Field, FileBlueprint, Json } from '../blueprints/types.js';
3
+ import { linkTypes, type LinkType, type LinkValue } from '../link.js';
4
+ import type { Asset, Relations } from './types.js';
5
+ import { Input } from './components/ui/input/index.js';
6
+ import { Label } from './components/ui/label/index.js';
7
+ import { Button } from './components/ui/button/index.js';
8
+ import { Switch } from './components/ui/switch/index.js';
9
+ import SelectField from './SelectField.svelte';
10
+ import MediaPicker from './MediaPicker.svelte';
11
+ let {
12
+ id,
13
+ field,
14
+ value,
15
+ assets,
16
+ relations,
17
+ workerUrl,
18
+ fileBlueprints,
19
+ invalid = false,
20
+ onchange
21
+ }: {
22
+ id: string;
23
+ field: Field;
24
+ value?: Json;
25
+ assets: Asset[];
26
+ relations: Relations;
27
+ workerUrl: string;
28
+ fileBlueprints: FileBlueprint[];
29
+ invalid?: boolean;
30
+ onchange: (value: LinkValue | null) => void;
31
+ } = $props();
32
+ const titles: Record<LinkType, string> = {
33
+ url: 'URL',
34
+ entry: 'Internal entry',
35
+ file: 'File',
36
+ email: 'Email',
37
+ phone: 'Phone'
38
+ };
39
+ const link: LinkValue = $derived((value as LinkValue | null) ?? { type: 'url', value: '' });
40
+ const entries = $derived(
41
+ Object.entries(relations)
42
+ .filter(([collection]) => !field.collection || field.collection === collection)
43
+ .flatMap(([collection, items]) =>
44
+ items.map((item) => ({
45
+ value: item.id,
46
+ label: field.collection ? item.label : `${collection}: ${item.label}`
47
+ }))
48
+ )
49
+ );
50
+ function set(updates: Partial<LinkValue>) {
51
+ onchange({ ...link, ...updates });
52
+ }
53
+ </script>
54
+
55
+ <div class="cms-stack">
56
+ <div class="cms-field">
57
+ <Label for={id + '-type'}>Link type</Label>
58
+ <SelectField
59
+ id={id + '-type'}
60
+ value={link.type}
61
+ clearable={false}
62
+ options={linkTypes.map((type) => ({ value: type, label: titles[type] }))}
63
+ onchange={(type) => set({ type: type as LinkType, value: '' })}
64
+ />
65
+ </div>
66
+ {#if link.type === 'entry'}
67
+ <SelectField
68
+ {id}
69
+ value={link.value}
70
+ options={entries}
71
+ {invalid}
72
+ placeholder="Choose an entry"
73
+ onchange={(value) => set({ value })}
74
+ />
75
+ {:else if link.type === 'file'}
76
+ <MediaPicker
77
+ {id}
78
+ value={link.value || null}
79
+ {assets}
80
+ {workerUrl}
81
+ fileBlueprint={fileBlueprints.find((b) => b.id === field.fileBlueprint)}
82
+ onchange={(value) => set({ value: typeof value === 'string' ? value : '' })}
83
+ />
84
+ {:else}
85
+ <Input
86
+ {id}
87
+ value={link.value}
88
+ aria-invalid={invalid}
89
+ type={link.type === 'email' ? 'email' : link.type === 'phone' ? 'tel' : 'text'}
90
+ placeholder={link.type === 'email'
91
+ ? 'hello@example.com'
92
+ : link.type === 'phone'
93
+ ? '+15551234567'
94
+ : 'https://example.com or /path'}
95
+ oninput={(event) => set({ value: event.currentTarget.value })}
96
+ />
97
+ {/if}
98
+ <div class="cms-field">
99
+ <Label for={id + '-label'}>Link text</Label>
100
+ <Input
101
+ id={id + '-label'}
102
+ value={link.label ?? ''}
103
+ placeholder="Optional"
104
+ oninput={(event) => set({ label: event.currentTarget.value })}
105
+ />
106
+ </div>
107
+ <div class="cms-checkbox">
108
+ <Switch
109
+ id={id + '-new-tab'}
110
+ checked={link.newTab ?? false}
111
+ onCheckedChange={(newTab) => set({ newTab })}
112
+ />
113
+ <Label for={id + '-new-tab'}>Open in new tab</Label>
114
+ </div>
115
+ {#if value}<Button variant="outline" onclick={() => onchange(null)}>Clear link</Button>{/if}
116
+ </div>
@@ -0,0 +1,17 @@
1
+ import type { Field, FileBlueprint, Json } from '../blueprints/types.js';
2
+ import { type LinkValue } from '../link.js';
3
+ import type { Asset, Relations } from './types.js';
4
+ type $$ComponentProps = {
5
+ id: string;
6
+ field: Field;
7
+ value?: Json;
8
+ assets: Asset[];
9
+ relations: Relations;
10
+ workerUrl: string;
11
+ fileBlueprints: FileBlueprint[];
12
+ invalid?: boolean;
13
+ onchange: (value: LinkValue | null) => void;
14
+ };
15
+ declare const LinkField: import("svelte").Component<$$ComponentProps, {}, "">;
16
+ type LinkField = ReturnType<typeof LinkField>;
17
+ export default LinkField;
@@ -1,5 +1,7 @@
1
1
  <script lang="ts">
2
- import { invalidateAll } from '$app/navigation';
2
+ import { refreshAll, afterNavigate } from '$app/navigation';
3
+ import { page } from '$app/state';
4
+ import SearchList from './SearchList.svelte';
3
5
  import { onMount, untrack } from 'svelte';
4
6
  import type { Payload } from '../blueprints/types.js';
5
7
  import Fields from './Fields.svelte';
@@ -34,11 +36,22 @@
34
36
  uploaded = $state(0),
35
37
  batchBlueprint = $state<string | undefined>(),
36
38
  confirmDelete = $state(false);
39
+ let openedLink = $state('');
40
+ afterNavigate(() => openedLink = '');
41
+ $effect(() => {
42
+ const id = page.url.searchParams.get('asset');
43
+ if (!id) { openedLink = ''; return; }
44
+ const asset = data.assets?.find((asset) => asset.id === id);
45
+ if (asset && openedLink !== id) {
46
+ openedLink = id; active = asset; metadata = structuredClone(asset.metadata); confirmDelete = false;
47
+ }
48
+ });
37
49
  const isPublic = (id: string) =>
38
50
  data.usages?.[id]?.some((usage) => usage.snapshot === 'published') ?? false;
39
51
  onMount(() => {
40
52
  const timer = setInterval(() => {
41
- if (data.assets?.some((a) => a.status === 'processing') && !busy) void invalidateAll();
53
+ if (data.assets?.some((a) => a.status === 'processing' || a.status === 'deleting') && !busy)
54
+ void refreshAll();
42
55
  }, 3000);
43
56
  return () => clearInterval(timer);
44
57
  });
@@ -80,7 +93,7 @@
80
93
  }
81
94
  );
82
95
  error = failures.map((failure) => failure.message).join('\n');
83
- await invalidateAll();
96
+ await refreshAll();
84
97
  } catch (e) {
85
98
  error = message(e);
86
99
  } finally {
@@ -94,7 +107,7 @@
94
107
  await api(path, body);
95
108
  active = null;
96
109
  confirmDelete = false;
97
- await invalidateAll();
110
+ await refreshAll();
98
111
  } catch (e) {
99
112
  error = message(e);
100
113
  } finally {
@@ -139,8 +152,10 @@
139
152
  >Up to {(data.uploadLimit ?? 0) / 1_000_000} MB per image · SVG up to 1 MB</span
140
153
  >
141
154
  </div>
142
- {#if data.assets?.length}<div class="cms-media-grid">
143
- {#each data.assets as asset (asset.id)}
155
+ <SearchList path="media/list" initial={data.assets ?? []} label="Search media" refreshKey={JSON.stringify(data.assets)}>
156
+ {#snippet children(assets)}
157
+ {#if assets.length}<div class="cms-media-grid">
158
+ {#each assets as asset (asset.id)}
144
159
  <AssetAttachment
145
160
  {asset}
146
161
  workerUrl={data.workerUrl!}
@@ -153,12 +168,14 @@
153
168
  }}
154
169
  />
155
170
  {/each}
156
- </div>{:else}<Card.Root class="cms-empty">
171
+ </div>{:else if !data.assets?.length}<Card.Root class="cms-empty">
157
172
  <Image size={36} />
158
173
  <h2>A home for your images</h2>
159
174
  <p>Upload your first image to start building your library.</p>
160
175
  <p class="cms-muted">Images are prepared for your website automatically.</p>
161
176
  </Card.Root>{/if}
177
+ {/snippet}
178
+ </SearchList>
162
179
  <Dialog.Root
163
180
  open={!!active}
164
181
  onOpenChange={(v) => {
@@ -171,7 +188,7 @@
171
188
  ></Dialog.Header
172
189
  >{#if active}{@const blueprint = data.fileBlueprints?.find((b) => b.id === active!.blueprint)}
173
190
  <div class="cms-stack">
174
- {#if assetUrl(active, data.workerUrl!)}<img
191
+ {#if !Object.values(blueprint?.fields ?? {}).some((field) => field.type === 'focus') && assetUrl(active, data.workerUrl!)}<img
175
192
  class="cms-asset-preview"
176
193
  src={assetUrl(active, data.workerUrl!)}
177
194
  alt={String(active.metadata.alt ?? '')}
@@ -183,6 +200,11 @@
183
200
  </p>
184
201
  {#if blueprint}<p class="cms-muted">{blueprint.label}</p>
185
202
  <Fields
203
+ imageUrl={active.variants.some(
204
+ (v) => v.preset === 'sandcms-preview' || v.format === 'svg'
205
+ )
206
+ ? assetUrl(active, data.workerUrl!)
207
+ : undefined}
186
208
  fields={blueprint.fields}
187
209
  value={metadata}
188
210
  onchange={(next) => {
@@ -194,12 +216,17 @@
194
216
  fileBlueprints={data.fileBlueprints}
195
217
  prefix="media"
196
218
  />{/if}
219
+ {#if active.status === 'deleting'}<p role="status">
220
+ This image is being deleted. Storage cleanup retries automatically.
221
+ </p>{/if}
197
222
  {#if active.error}<p class="cms-error">{active.error}</p>
198
- <Button
199
- variant="outline"
200
- disabled={busy}
201
- onclick={() => action('media/retry', { id: active!.id })}>Retry processing</Button
202
- >{/if}
223
+ {#if active.status !== 'deleting'}
224
+ <Button
225
+ variant="outline"
226
+ disabled={busy}
227
+ onclick={() => action('media/retry', { id: active!.id })}>Retry processing</Button
228
+ >{/if}
229
+ {/if}
203
230
  <div>
204
231
  <h3>Used in {(data.usages?.[active.id] ?? []).length} content references</h3>
205
232
  {#each data.usages?.[active.id] ?? [] as usage}<a
@@ -221,7 +248,7 @@
221
248
  <div class="cms-actions">
222
249
  <Button variant="destructive" onclick={() => (confirmDelete = true)}>Delete</Button
223
250
  ><Button
224
- disabled={busy}
251
+ disabled={busy || active.status === 'deleting'}
225
252
  onclick={() => action('media/update', { id: active!.id, metadata })}
226
253
  >Save details</Button
227
254
  >
@@ -1,4 +1,5 @@
1
1
  <script lang="ts">
2
+ import SearchList from './SearchList.svelte';
2
3
  import type { FileBlueprint } from '../blueprints/types.js';
3
4
  import type { Asset } from './types.js';
4
5
  import * as Dialog from './components/ui/dialog/index.js';
@@ -237,16 +238,24 @@
237
238
  </p>{/if}{#if error}<p role="alert" class="cms-error">
238
239
  {error}
239
240
  </p>{/if}
241
+ {#if open}<SearchList
242
+ path={'media/list' + (fileBlueprint ? '?' + new URLSearchParams([['blueprint', fileBlueprint.id], ...fileBlueprint.accept.map((mime): [string, string] => ['mime', mime])]).toString() : '')}
243
+ initial={all.filter((a) => !fileBlueprint || (a.blueprint === fileBlueprint.id && fileBlueprint.accept.includes(a.mime)))}
244
+ label="Search media" refreshKey={JSON.stringify(all)}>
245
+ {#snippet children(matches)}
240
246
  <div class="cms-picker-drop-area" bind:this={dropArea}>
241
247
  <div class="cms-picker-grid">
242
248
  <UploadButton tile {busy} {multiple} accept={accept.join(',')} onchange={upload} />
243
- {#each all.filter((a) => !fileBlueprint || (a.blueprint === fileBlueprint.id && fileBlueprint.accept.includes(a.mime))) as asset (asset.id)}
249
+ {#each matches.filter((a) => a.status !== 'deleting') as asset (asset.id)}
244
250
  <AssetAttachment
245
251
  {asset}
246
252
  {workerUrl}
247
253
  class="cms-picker-item"
248
254
  selected={selected.some((a) => a.id === asset.id)}
249
- onopen={() => select(asset.id)}
255
+ onopen={() => {
256
+ if (!all.some((a) => a.id === asset.id)) { extra = [...extra, asset]; onasset?.(asset); }
257
+ select(asset.id);
258
+ }}
250
259
  />
251
260
  {/each}
252
261
  </div>
@@ -266,6 +275,7 @@
266
275
  >
267
276
  </div>
268
277
  </div>
278
+ {/snippet}</SearchList>{/if}
269
279
  {#if multiple}<div class="flex justify-end">
270
280
  <Button onclick={() => (open = false)}>Done</Button>
271
281
  </div>{/if}</Dialog.Content
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { invalidateAll } from '$app/navigation';
2
+ import { refreshAll } from '$app/navigation';
3
3
  import type { AdminData } from './types.js';
4
4
  import { notificationFields } from '../notification-fields.js';
5
5
  import { api, message } from './client.js';
@@ -60,7 +60,7 @@
60
60
  replyToField
61
61
  }
62
62
  });
63
- await invalidateAll();
63
+ await refreshAll();
64
64
  open = false;
65
65
  } catch (cause) {
66
66
  error = message(cause);
@@ -0,0 +1,55 @@
1
+ <script lang="ts" generics="T extends { id: string }">
2
+ import type { Snippet } from 'svelte';
3
+ import { Input } from './components/ui/input/index.js';
4
+ import { Button } from './components/ui/button/index.js';
5
+ import { message } from './client.js';
6
+ let { path, initial, label, children, empty = 'No matches found.', refreshKey = '' }: {
7
+ path: string; initial: T[]; label: string; children: Snippet<[T[]]>; empty?: string; refreshKey?: string;
8
+ } = $props();
9
+ let query = $state(''), results = $state<T[]>([]), cursor = $state<string | null>(null),
10
+ loading = $state(false), error = $state('');
11
+ let controller: AbortController | undefined;
12
+ const searching = $derived(!!query.trim());
13
+ const items = $derived(searching ? results : initial);
14
+ async function request(signal: AbortSignal, next?: string) {
15
+ const url = new URL('/api/cms/' + path, window.location.origin);
16
+ url.searchParams.set('q', query);
17
+ url.searchParams.set('limit', '100');
18
+ if (next) url.searchParams.set('cursor', next);
19
+ try {
20
+ const response = await fetch(url, { signal });
21
+ const data = await response.json();
22
+ if (!response.ok) throw new Error(data.error ?? data.message ?? 'Search failed');
23
+ if (signal.aborted) return;
24
+ results = next ? [...results, ...data.items] : data.items;
25
+ cursor = data.nextCursor ?? null;
26
+ } catch (cause) {
27
+ if (!signal.aborted) error = message(cause);
28
+ } finally {
29
+ if (!signal.aborted) loading = false;
30
+ }
31
+ }
32
+ $effect(() => {
33
+ const current = query, route = path, revision = refreshKey;
34
+ controller?.abort();
35
+ controller = new AbortController();
36
+ const active = controller;
37
+ results = []; cursor = null; error = ''; loading = !!current.trim();
38
+ if (!current.trim()) return () => active.abort();
39
+ const timer = setTimeout(() => void request(active.signal), 200);
40
+ return () => { clearTimeout(timer); active.abort(); };
41
+ });
42
+ </script>
43
+
44
+ <div class="cms-stack">
45
+ <Input aria-label={label} placeholder={label} type="search" maxlength={200} bind:value={query} />
46
+ {#if loading}<p role="status" class="cms-muted">Searching…</p>{/if}
47
+ {#if error}<p role="alert" class="cms-error">{error}</p><Button variant="outline" onclick={() => {
48
+ error = ''; loading = true; void request(controller!.signal);
49
+ }}>Retry search</Button>{/if}
50
+ {#if searching && !loading && !error && !items.length}<p role="status" class="cms-muted">{empty}</p>{/if}
51
+ {@render children(items)}
52
+ {#if searching && cursor}<Button variant="outline" disabled={loading} onclick={() => {
53
+ loading = true; error = ''; void request(controller!.signal, cursor!);
54
+ }}>Load more results</Button>{/if}
55
+ </div>
@@ -0,0 +1,42 @@
1
+ import type { Snippet } from 'svelte';
2
+ declare function $$render<T extends {
3
+ id: string;
4
+ }>(): {
5
+ props: {
6
+ path: string;
7
+ initial: T[];
8
+ label: string;
9
+ children: Snippet<[T[]]>;
10
+ empty?: string;
11
+ refreshKey?: string;
12
+ };
13
+ exports: {};
14
+ bindings: "";
15
+ slots: {};
16
+ events: {};
17
+ };
18
+ declare class __sveltets_Render<T extends {
19
+ id: string;
20
+ }> {
21
+ props(): ReturnType<typeof $$render<T>>['props'];
22
+ events(): ReturnType<typeof $$render<T>>['events'];
23
+ slots(): ReturnType<typeof $$render<T>>['slots'];
24
+ bindings(): "";
25
+ exports(): {};
26
+ }
27
+ interface $$IsomorphicComponent {
28
+ new <T extends {
29
+ id: string;
30
+ }>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
31
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
32
+ } & ReturnType<__sveltets_Render<T>['exports']>;
33
+ <T extends {
34
+ id: string;
35
+ }>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
36
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
37
+ }
38
+ declare const SearchList: $$IsomorphicComponent;
39
+ type SearchList<T extends {
40
+ id: string;
41
+ }> = InstanceType<typeof SearchList<T>>;
42
+ export default SearchList;
@@ -7,6 +7,7 @@
7
7
  placeholder = 'Select…',
8
8
  clearable = true,
9
9
  invalid = false,
10
+ describedBy,
10
11
  onchange
11
12
  }: {
12
13
  id: string;
@@ -15,6 +16,7 @@
15
16
  placeholder?: string;
16
17
  clearable?: boolean;
17
18
  invalid?: boolean;
19
+ describedBy?: string;
18
20
  onchange?: (value: string) => void;
19
21
  } = $props();
20
22
  const label = $derived(options.find((option) => option.value === value)?.label ?? placeholder);
@@ -29,7 +31,7 @@
29
31
  onchange?.(next);
30
32
  }}
31
33
  >
32
- <Select.Trigger {id} class="w-full" aria-invalid={invalid}
34
+ <Select.Trigger {id} class="w-full" aria-invalid={invalid} aria-describedby={describedBy}
33
35
  ><span data-slot="select-value">{label}</span></Select.Trigger
34
36
  >
35
37
  <Select.Content portalProps={{ disabled: true }}>
@@ -8,6 +8,7 @@ type $$ComponentProps = {
8
8
  placeholder?: string;
9
9
  clearable?: boolean;
10
10
  invalid?: boolean;
11
+ describedBy?: string;
11
12
  onchange?: (value: string) => void;
12
13
  };
13
14
  declare const SelectField: import("svelte").Component<$$ComponentProps, {}, "value">;