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.
- package/README.md +6 -4
- package/dist/admin/Account.svelte +4 -1
- package/dist/admin/ApiKeys.svelte +159 -0
- package/dist/admin/ApiKeys.svelte.d.ts +3 -0
- package/dist/admin/AssetAttachment.svelte +6 -4
- package/dist/admin/BlueprintFields.svelte +86 -0
- package/dist/admin/BlueprintFields.svelte.d.ts +15 -0
- package/dist/admin/Collection.svelte +40 -7
- package/dist/admin/Editor.svelte +57 -17
- package/dist/admin/Fields.svelte +217 -144
- package/dist/admin/Fields.svelte.d.ts +1 -0
- package/dist/admin/FocusPicker.svelte +136 -0
- package/dist/admin/FocusPicker.svelte.d.ts +11 -0
- package/dist/admin/Gallery.svelte +40 -34
- package/dist/admin/GlobalSearch.svelte +56 -0
- package/dist/admin/GlobalSearch.svelte.d.ts +3 -0
- package/dist/admin/Inbox.svelte +8 -5
- package/dist/admin/LinkField.svelte +116 -0
- package/dist/admin/LinkField.svelte.d.ts +17 -0
- package/dist/admin/MediaLibrary.svelte +41 -14
- package/dist/admin/MediaPicker.svelte +12 -2
- package/dist/admin/Navigation.svelte +62 -0
- package/dist/admin/Navigation.svelte.d.ts +7 -0
- package/dist/admin/NotificationSettings.svelte +2 -2
- package/dist/admin/SearchList.svelte +55 -0
- package/dist/admin/SearchList.svelte.d.ts +42 -0
- package/dist/admin/SelectField.svelte +3 -1
- package/dist/admin/SelectField.svelte.d.ts +1 -0
- package/dist/admin/Shell.svelte +16 -24
- package/dist/admin/UnsavedChanges.svelte +1 -1
- package/dist/admin/Users.svelte +11 -5
- package/dist/admin/client.js +2 -1
- package/dist/admin/generated/admin.css +145 -0
- package/dist/admin/navigation.d.ts +7 -0
- package/dist/admin/navigation.js +25 -0
- package/dist/admin/types.d.ts +5 -1
- package/dist/admin/uploads.js +27 -6
- package/dist/blueprints/conditions.d.ts +2 -0
- package/dist/blueprints/conditions.js +4 -0
- package/dist/blueprints/extends.d.ts +5 -0
- package/dist/blueprints/extends.js +76 -0
- package/dist/blueprints/files.d.ts +3 -1
- package/dist/blueprints/files.js +35 -2
- package/dist/blueprints/layout.d.ts +4 -0
- package/dist/blueprints/layout.js +12 -0
- package/dist/blueprints/load.d.ts +1 -1
- package/dist/blueprints/load.js +127 -12
- package/dist/blueprints/types.d.ts +38 -1
- package/dist/blueprints/validate.js +30 -6
- package/dist/cli/cloudflare.js +15 -3
- package/dist/cli/doctor.js +6 -3
- package/dist/cli/files.js +1 -1
- package/dist/cli/scaffold.js +8 -6
- package/dist/cli/setup.js +9 -2
- package/dist/cli/upgrade.js +2 -1
- package/dist/email-failure.d.ts +17 -0
- package/dist/email-failure.js +22 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/link.d.ts +17 -0
- package/dist/link.js +44 -0
- package/dist/notification-fields.js +1 -1
- package/dist/search.d.ts +8 -0
- package/dist/search.js +1 -0
- package/dist/server/access.d.ts +2 -0
- package/dist/server/access.js +59 -23
- package/dist/server/admin-load.d.ts +29 -2
- package/dist/server/admin-load.js +4 -2
- package/dist/server/api-access.d.ts +31 -0
- package/dist/server/api-access.js +52 -0
- package/dist/server/api-pagination.d.ts +34 -0
- package/dist/server/api-pagination.js +87 -0
- package/dist/server/api.js +224 -32
- package/dist/server/auth.d.ts +1150 -0
- package/dist/server/auth.js +11 -1
- package/dist/server/cms.d.ts +1208 -4
- package/dist/server/cms.js +2 -0
- package/dist/server/content.d.ts +17 -2
- package/dist/server/content.js +89 -14
- package/dist/server/db/migration-data.js +24 -0
- package/dist/server/db/migrations/0001_independent_password_resets.sql +3 -0
- package/dist/server/db/migrations/0002_email_failure_reason.sql +1 -0
- package/dist/server/db/migrations/0003_direct_r2_uploads.sql +10 -0
- package/dist/server/db/migrations/0004_agent_api_keys.sql +38 -0
- package/dist/server/db/migrations/0005_api_retention_and_pagination.sql +3 -0
- package/dist/server/db/migrations/0006_durable_media_deletion.sql +7 -0
- package/dist/server/db/migrations/meta/0001_snapshot.json +1197 -0
- package/dist/server/db/migrations/meta/0002_snapshot.json +1204 -0
- package/dist/server/db/migrations/meta/0003_snapshot.json +1281 -0
- package/dist/server/db/migrations/meta/0004_snapshot.json +1546 -0
- package/dist/server/db/migrations/meta/0005_snapshot.json +1572 -0
- package/dist/server/db/migrations/meta/0006_snapshot.json +1627 -0
- package/dist/server/db/migrations/meta/_journal.json +42 -0
- package/dist/server/db/schema.d.ts +742 -2
- package/dist/server/db/schema.js +77 -5
- package/dist/server/email/index.d.ts +11 -1
- package/dist/server/email/index.js +69 -6
- package/dist/server/forms.js +12 -2
- package/dist/server/hooks.d.ts +1 -1
- package/dist/server/hooks.js +37 -14
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/links.d.ts +5 -0
- package/dist/server/links.js +44 -0
- package/dist/server/media/deletions.d.ts +2 -0
- package/dist/server/media/deletions.js +58 -0
- package/dist/server/media/presets.d.ts +10 -2
- package/dist/server/media/presets.js +14 -2
- package/dist/server/media/runner.d.ts +1 -1
- package/dist/server/media/runner.js +105 -8
- package/dist/server/media/service.d.ts +41 -3
- package/dist/server/media/service.js +146 -33
- package/dist/server/notifications.d.ts +1 -0
- package/dist/server/notifications.js +4 -2
- package/dist/server/request.d.ts +2 -0
- package/dist/server/request.js +5 -0
- package/dist/server/search.d.ts +13 -0
- package/dist/server/search.js +97 -0
- package/dist/worker/index.d.ts +3 -3
- package/dist/worker/index.js +205 -64
- package/dist/worker/local.d.ts +5 -0
- package/dist/worker/local.js +57 -0
- package/dist/worker/source.d.ts +1 -1
- package/dist/worker/source.js +2 -2
- package/dist/worker/uploads.d.ts +22 -0
- package/dist/worker/uploads.js +46 -0
- package/docs/acceptance.md +1 -1
- package/docs/api.md +73 -0
- package/docs/cloudflare.md +35 -8
- package/docs/content.md +181 -5
- package/docs/deployment.md +29 -4
- package/docs/email.md +14 -10
- package/docs/forms.md +3 -1
- package/docs/media.md +34 -5
- package/docs/package.md +7 -5
- package/docs/releases.md +56 -1
- package/docs/upgrades.md +59 -3
- package/package.json +19 -10
- package/templates/hooks.server.ts +3 -3
- package/templates/integration.ts +2 -2
- package/templates/routes/admin/+page.server.ts +2 -2
- package/templates/routes/admin/+page.svelte +1 -1
- package/templates/routes/api/+server.ts +2 -2
- package/templates/sandcms/blueprints/collections/projects.yaml +16 -8
- package/templates/sandcms/blueprints/fields/seo.yaml +5 -0
- package/templates/sandcms/blueprints/files/image.yaml +1 -0
- package/templates/sandcms/blueprints/pages/home.yaml +3 -0
- package/templates/sandcms/config.yaml +1 -0
- package/templates/sandcms/worker/index.ts +1 -1
- package/templates/sandcms/worker/local.ts +1 -0
- 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
|
-
{
|
|
79
|
-
|
|
80
|
-
<div class="cms-
|
|
81
|
-
<
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
115
|
+
onchange={(next) => set(i, key, next[key] ?? empty(definition))}
|
|
116
|
+
/>
|
|
117
|
+
{/if}
|
|
92
118
|
</div>
|
|
93
|
-
|
|
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>
|
package/dist/admin/Inbox.svelte
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
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
|
-
|
|
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 {
|
|
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)
|
|
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
|
|
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
|
|
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
|
-
{
|
|
143
|
-
|
|
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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
|
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={() =>
|
|
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
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { afterNavigate } from '$app/navigation';
|
|
3
|
+
import { page } from '$app/state';
|
|
4
|
+
import { Icon } from '@lucide/svelte';
|
|
5
|
+
import Folder from '@lucide/svelte/icons/folder';
|
|
6
|
+
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
|
7
|
+
import type { AdminData } from './types.js';
|
|
8
|
+
import { blueprintHref, navigationGroups, navigationSelected } from './navigation.js';
|
|
9
|
+
|
|
10
|
+
let { blueprints }: { blueprints: NonNullable<AdminData['blueprints']> } = $props();
|
|
11
|
+
const id = $props.id();
|
|
12
|
+
const items = $derived(navigationGroups(blueprints));
|
|
13
|
+
let expanded = $state(new Map<string, boolean>());
|
|
14
|
+
const active = (b: (typeof blueprints)[number]) =>
|
|
15
|
+
navigationSelected(page.url.pathname, blueprintHref(b));
|
|
16
|
+
afterNavigate(() => {
|
|
17
|
+
for (const item of items) {
|
|
18
|
+
if (item.group !== false && item.blueprints.some(active)) {
|
|
19
|
+
expanded = new Map(expanded).set(item.group, true);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
{#snippet links(entries: typeof blueprints)}
|
|
26
|
+
{#each entries as b (b.id)}
|
|
27
|
+
<a
|
|
28
|
+
href={blueprintHref(b)}
|
|
29
|
+
class:active={active(b)}
|
|
30
|
+
aria-current={active(b) ? 'page' : undefined}
|
|
31
|
+
>
|
|
32
|
+
<Icon icon={b.navigationIcon} size={17} />{b.label}
|
|
33
|
+
</a>
|
|
34
|
+
{/each}
|
|
35
|
+
{/snippet}
|
|
36
|
+
|
|
37
|
+
{#each items as item, index}
|
|
38
|
+
{#if item.group === false}
|
|
39
|
+
{@render links(item.blueprints)}
|
|
40
|
+
{:else}
|
|
41
|
+
{@const group = item.group}
|
|
42
|
+
{@const isActive = item.blueprints.some(active)}
|
|
43
|
+
{@const isExpanded = expanded.get(group) ?? isActive}
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
class="cms-nav-group"
|
|
47
|
+
class:cms-nav-group-active={isActive}
|
|
48
|
+
aria-expanded={isExpanded}
|
|
49
|
+
aria-controls={`${id}-${index}`}
|
|
50
|
+
onclick={() => (expanded = new Map(expanded).set(group, !isExpanded))}
|
|
51
|
+
>
|
|
52
|
+
<Folder size={17} />{group}
|
|
53
|
+
<ChevronRight
|
|
54
|
+
size={14}
|
|
55
|
+
class={isExpanded ? 'cms-nav-chevron cms-nav-chevron-open' : 'cms-nav-chevron'}
|
|
56
|
+
/>
|
|
57
|
+
</button>
|
|
58
|
+
<div id={`${id}-${index}`} class="cms-nav-children" hidden={!isExpanded}>
|
|
59
|
+
{@render links(item.blueprints)}
|
|
60
|
+
</div>
|
|
61
|
+
{/if}
|
|
62
|
+
{/each}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AdminData } from './types.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
blueprints: NonNullable<AdminData['blueprints']>;
|
|
4
|
+
};
|
|
5
|
+
declare const Navigation: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type Navigation = ReturnType<typeof Navigation>;
|
|
7
|
+
export default Navigation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
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
|
|
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>
|