sandcms 0.5.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- 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/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 +4 -2
- 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 +109 -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 +123 -12
- package/dist/blueprints/types.d.ts +35 -1
- package/dist/blueprints/validate.js +30 -6
- package/dist/cli/cloudflare.js +17 -5
- 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 +11 -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 +1210 -4
- package/dist/server/cms.js +12 -0
- package/dist/server/content.d.ts +17 -2
- package/dist/server/content.js +89 -14
- package/dist/server/db/auto-migrate.d.ts +12 -0
- package/dist/server/db/auto-migrate.js +23 -0
- 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/db/store.js +24 -9
- 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 +2 -1
- package/dist/server/index.js +2 -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 +4 -4
- package/dist/worker/index.js +208 -67
- 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 +48 -0
- package/docs/api.md +73 -0
- package/docs/cloudflare.md +37 -10
- package/docs/content.md +162 -4
- package/docs/deployment.md +33 -4
- package/docs/email.md +11 -7
- package/docs/forms.md +3 -1
- package/docs/media.md +33 -4
- package/docs/package.md +6 -4
- package/docs/releases.md +54 -1
- package/docs/upgrades.md +91 -3
- package/package.json +19 -10
- package/templates/hooks.server.ts +2 -2
- package/templates/integration.ts +3 -2
- package/templates/routes/admin/+page.server.ts +1 -1
- package/templates/routes/api/+server.ts +1 -1
- 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 +1 -0
- package/templates/sandcms/config.yaml +1 -0
- package/templates/sandcms/worker/local.ts +1 -0
- package/templates/sandcms/worker/wrangler.jsonc +1 -2
package/dist/admin/Shell.svelte
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { Button } from './components/ui/button/index.js';
|
|
8
8
|
import * as Avatar from './components/ui/avatar/index.js';
|
|
9
9
|
import Navigation from './Navigation.svelte';
|
|
10
|
+
import GlobalSearch from './GlobalSearch.svelte';
|
|
10
11
|
import Layers from '@lucide/svelte/icons/layers';
|
|
11
12
|
import LayoutDashboard from '@lucide/svelte/icons/layout-dashboard';
|
|
12
13
|
import Image from '@lucide/svelte/icons/image';
|
|
@@ -26,7 +27,8 @@
|
|
|
26
27
|
}
|
|
27
28
|
</script>
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
<!-- Singleton editor loads create drafts, so wait for navigation before loading data. -->
|
|
31
|
+
<div class="cms-shell" data-sveltekit-preload-data={false}>
|
|
30
32
|
<aside class:cms-open={open} class="cms-sidebar">
|
|
31
33
|
<a href="/admin" class="cms-wordmark"
|
|
32
34
|
><Layers size={23} /> SandCMS <span class="cms-version">V1</span></a
|
|
@@ -87,7 +89,7 @@
|
|
|
87
89
|
}[data.screen] ??
|
|
88
90
|
'Overview'}</strong
|
|
89
91
|
></span
|
|
90
|
-
|
|
92
|
+
>{#if !data.user?.mustChangePassword}<GlobalSearch />{/if}<a href="/" target="_blank" rel="noreferrer" class="cms-live"
|
|
91
93
|
><span></span> View website <ArrowUpRight size={14} /></a
|
|
92
94
|
>
|
|
93
95
|
</header>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { beforeNavigate, goto } from '$app/navigation';
|
|
3
|
-
import type { BeforeNavigate } from '
|
|
3
|
+
import type { BeforeNavigate } from '$app/navigation';
|
|
4
4
|
import * as AlertDialog from './components/ui/alert-dialog/index.js';
|
|
5
5
|
let { dirty }: { dirty: boolean } = $props();
|
|
6
6
|
let open = $state(false);
|
package/dist/admin/Users.svelte
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { emailFailureMessage } from '../email-failure.js';
|
|
2
3
|
import * as Table from './components/ui/table/index.js';
|
|
3
4
|
import * as Card from './components/ui/card/index.js';
|
|
4
|
-
import {
|
|
5
|
+
import { refreshAll } from '$app/navigation';
|
|
5
6
|
import type { AdminData } from './types.js';
|
|
6
7
|
import { api, message } from './client.js';
|
|
7
8
|
import { Button } from './components/ui/button/index.js';
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
error = '';
|
|
17
18
|
try {
|
|
18
19
|
await api(path, { id });
|
|
19
|
-
await
|
|
20
|
+
await refreshAll();
|
|
20
21
|
} catch (e) {
|
|
21
22
|
error = message(e);
|
|
22
23
|
} finally {
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
password = '';
|
|
40
41
|
name = '';
|
|
41
42
|
email = '';
|
|
42
|
-
await
|
|
43
|
+
await refreshAll();
|
|
43
44
|
} catch (e) {
|
|
44
45
|
error = message(e);
|
|
45
46
|
} finally {
|
|
@@ -92,7 +93,7 @@
|
|
|
92
93
|
{#if data.invitations?.length}
|
|
93
94
|
<h2>Pending invitations</h2>
|
|
94
95
|
<p class="cms-muted">
|
|
95
|
-
|
|
96
|
+
Mail server acceptance does not confirm inbox delivery or invitation acceptance.
|
|
96
97
|
</p>
|
|
97
98
|
{#each data.invitations as invitation}
|
|
98
99
|
<Card.Root
|
|
@@ -104,8 +105,13 @@
|
|
|
104
105
|
: 'Expires ' + new Date(invitation.expiresAt).toLocaleString()} · Email: {invitation.status ===
|
|
105
106
|
'sending'
|
|
106
107
|
? 'Sending or outcome unknown'
|
|
107
|
-
: invitation.status
|
|
108
|
+
: invitation.status === 'accepted'
|
|
109
|
+
? 'Accepted by mail server'
|
|
110
|
+
: 'Failed'}
|
|
108
111
|
</p>
|
|
112
|
+
{#if invitation.status === 'failed'}<p class="cms-error">
|
|
113
|
+
{emailFailureMessage(invitation.failureReason)}
|
|
114
|
+
</p>{/if}
|
|
109
115
|
<div class="flex gap-2">
|
|
110
116
|
<Button
|
|
111
117
|
variant="outline"
|
package/dist/admin/client.js
CHANGED
|
@@ -24,6 +24,7 @@ export async function api(path, body) {
|
|
|
24
24
|
}
|
|
25
25
|
export const message = (e) => e instanceof Error ? e.message : 'Something went wrong. Please try again.';
|
|
26
26
|
export function assetUrl(asset, _workerUrl) {
|
|
27
|
-
|
|
27
|
+
const preview = asset.variants.find((v) => v.preset === 'sandcms-preview') ?? asset.variants[0];
|
|
28
|
+
return preview ? '/api/cms/media/' + preview.key : '';
|
|
28
29
|
}
|
|
29
30
|
export const date = (timestamp) => new Intl.DateTimeFormat('en', { month: 'short', day: 'numeric', year: 'numeric' }).format(timestamp);
|
|
@@ -824,6 +824,9 @@
|
|
|
824
824
|
.max-h-\(--bits-select-content-available-height\) {
|
|
825
825
|
max-height: var(--bits-select-content-available-height);
|
|
826
826
|
}
|
|
827
|
+
.max-h-\[80vh\] {
|
|
828
|
+
max-height: 80vh;
|
|
829
|
+
}
|
|
827
830
|
.max-h-\[85vh\] {
|
|
828
831
|
max-height: 85vh;
|
|
829
832
|
}
|
|
@@ -943,6 +946,9 @@
|
|
|
943
946
|
.cursor-default {
|
|
944
947
|
cursor: default;
|
|
945
948
|
}
|
|
949
|
+
.resize {
|
|
950
|
+
resize: both;
|
|
951
|
+
}
|
|
946
952
|
.snap-x {
|
|
947
953
|
scroll-snap-type: x var(--sandcms-tw-scroll-snap-strictness);
|
|
948
954
|
}
|
|
@@ -2678,6 +2684,37 @@
|
|
|
2678
2684
|
display: flex;
|
|
2679
2685
|
gap: 8px;
|
|
2680
2686
|
}
|
|
2687
|
+
.cms-input-control {
|
|
2688
|
+
display: flex;
|
|
2689
|
+
flex: 1;
|
|
2690
|
+
min-width: 0;
|
|
2691
|
+
align-items: center;
|
|
2692
|
+
}
|
|
2693
|
+
.cms-input-affix {
|
|
2694
|
+
display: flex;
|
|
2695
|
+
align-items: center;
|
|
2696
|
+
align-self: stretch;
|
|
2697
|
+
border: 1px solid var(--sandcms-input);
|
|
2698
|
+
background: var(--sandcms-muted);
|
|
2699
|
+
padding: 0 10px;
|
|
2700
|
+
font-size: 12px;
|
|
2701
|
+
overflow-wrap: anywhere;
|
|
2702
|
+
}
|
|
2703
|
+
.cms-field-helpers {
|
|
2704
|
+
display: flex;
|
|
2705
|
+
flex-wrap: wrap;
|
|
2706
|
+
gap: 4px 12px;
|
|
2707
|
+
font-size: 11px;
|
|
2708
|
+
color: var(--sandcms-muted-foreground);
|
|
2709
|
+
}
|
|
2710
|
+
.cms-field-help {
|
|
2711
|
+
flex: 1;
|
|
2712
|
+
min-width: 0;
|
|
2713
|
+
overflow-wrap: anywhere;
|
|
2714
|
+
}
|
|
2715
|
+
.cms-field-counter {
|
|
2716
|
+
margin-left: auto;
|
|
2717
|
+
}
|
|
2681
2718
|
.cms-checkbox {
|
|
2682
2719
|
display: flex;
|
|
2683
2720
|
gap: 8px;
|
|
@@ -2779,6 +2816,57 @@
|
|
|
2779
2816
|
font-size: 12px;
|
|
2780
2817
|
overflow-wrap: anywhere;
|
|
2781
2818
|
}
|
|
2819
|
+
.cms-editor-fields {
|
|
2820
|
+
container-type: inline-size;
|
|
2821
|
+
min-width: 0;
|
|
2822
|
+
}
|
|
2823
|
+
.cms-fields, .cms-blueprint-columns {
|
|
2824
|
+
display: grid;
|
|
2825
|
+
grid-template-columns: repeat(12, minmax(0, 1fr));
|
|
2826
|
+
gap: 22px;
|
|
2827
|
+
align-items: start;
|
|
2828
|
+
}
|
|
2829
|
+
.cms-fields > .cms-field, .cms-blueprint-column {
|
|
2830
|
+
grid-column: span var(--sandcms-cms-span, 12);
|
|
2831
|
+
}
|
|
2832
|
+
.cms-blueprint-column, .cms-blueprint-section {
|
|
2833
|
+
display: grid;
|
|
2834
|
+
gap: 22px;
|
|
2835
|
+
min-width: 0;
|
|
2836
|
+
}
|
|
2837
|
+
.cms-blueprint-section h2 {
|
|
2838
|
+
font-size: 16px;
|
|
2839
|
+
font-weight: 550;
|
|
2840
|
+
}
|
|
2841
|
+
.cms-blueprint-tabs {
|
|
2842
|
+
display: flex;
|
|
2843
|
+
flex-wrap: wrap;
|
|
2844
|
+
gap: 8px;
|
|
2845
|
+
border-bottom: 1px solid var(--sandcms-border);
|
|
2846
|
+
margin-bottom: 22px;
|
|
2847
|
+
}
|
|
2848
|
+
.cms-blueprint-tab {
|
|
2849
|
+
padding: 10px 12px;
|
|
2850
|
+
border-bottom: 2px solid transparent;
|
|
2851
|
+
cursor: pointer;
|
|
2852
|
+
}
|
|
2853
|
+
.cms-blueprint-tab[data-state='active'] {
|
|
2854
|
+
border-bottom-color: var(--sandcms-foreground);
|
|
2855
|
+
}
|
|
2856
|
+
.cms-blueprint-tab:focus-visible {
|
|
2857
|
+
outline: 2px solid var(--sandcms-ring);
|
|
2858
|
+
outline-offset: -2px;
|
|
2859
|
+
}
|
|
2860
|
+
@container (max-width: 560px) {
|
|
2861
|
+
.cms-fields > .cms-field, .cms-blueprint-column {
|
|
2862
|
+
grid-column: span 12;
|
|
2863
|
+
}
|
|
2864
|
+
}
|
|
2865
|
+
@media (max-width: 640px) {
|
|
2866
|
+
.cms-fields > .cms-field, .cms-blueprint-column {
|
|
2867
|
+
grid-column: span 12;
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2782
2870
|
.cms-media-grid {
|
|
2783
2871
|
display: grid;
|
|
2784
2872
|
grid-template-columns: repeat(auto-fill, minmax(205px, 1fr));
|
|
@@ -2952,6 +3040,19 @@
|
|
|
2952
3040
|
transition: none;
|
|
2953
3041
|
}
|
|
2954
3042
|
}
|
|
3043
|
+
.cms-search-result {
|
|
3044
|
+
display: flex;
|
|
3045
|
+
flex-direction: column;
|
|
3046
|
+
gap: 0.25rem;
|
|
3047
|
+
padding: 0.75rem;
|
|
3048
|
+
border: 1px solid var(--sandcms-border);
|
|
3049
|
+
border-radius: 0.5rem;
|
|
3050
|
+
overflow-wrap: anywhere;
|
|
3051
|
+
}
|
|
3052
|
+
.cms-search-result:focus-visible {
|
|
3053
|
+
outline: 2px solid currentColor;
|
|
3054
|
+
outline-offset: 2px;
|
|
3055
|
+
}
|
|
2955
3056
|
.cms-account-grid {
|
|
2956
3057
|
display: grid;
|
|
2957
3058
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
@@ -3141,6 +3242,14 @@ a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible
|
|
|
3141
3242
|
height: 130px;
|
|
3142
3243
|
}
|
|
3143
3244
|
}
|
|
3245
|
+
@media (max-width: 640px) {
|
|
3246
|
+
.cms-search-trigger {
|
|
3247
|
+
padding: 0.5rem;
|
|
3248
|
+
}
|
|
3249
|
+
.cms-search-trigger span, .cms-search-trigger kbd {
|
|
3250
|
+
display: none;
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3144
3253
|
:scope {
|
|
3145
3254
|
--sandcms-background: oklch(1 0 0);
|
|
3146
3255
|
--sandcms-foreground: oklch(0.147 0.004 49.25);
|
package/dist/admin/types.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { EmailFailureReason } from '../email-failure.js';
|
|
1
2
|
import type { Blueprint, FileBlueprint } from '../blueprints/types.js';
|
|
2
3
|
import type { LucideIconData } from '@lucide/svelte';
|
|
3
4
|
import type { documents, media, submissions, NotificationSettings } from '../server/db/schema.js';
|
|
4
5
|
import type { CmsUser } from '../server/auth.js';
|
|
5
6
|
export type Entry = typeof documents.$inferSelect;
|
|
6
|
-
export type Asset = typeof media.$inferSelect
|
|
7
|
+
export type Asset = typeof media.$inferSelect & {
|
|
8
|
+
expectedVersion?: string;
|
|
9
|
+
};
|
|
7
10
|
export type Submission = typeof submissions.$inferSelect;
|
|
8
11
|
export type Relations = Record<string, {
|
|
9
12
|
id: string;
|
|
@@ -19,6 +22,7 @@ export interface AdminData {
|
|
|
19
22
|
role: string;
|
|
20
23
|
expiresAt: number;
|
|
21
24
|
status: string;
|
|
25
|
+
failureReason?: EmailFailureReason | null;
|
|
22
26
|
}[];
|
|
23
27
|
notificationSettings?: NotificationSettings;
|
|
24
28
|
notificationsEnabled?: boolean;
|
package/dist/admin/uploads.js
CHANGED
|
@@ -2,15 +2,36 @@ import { api, message } from './client.js';
|
|
|
2
2
|
export async function uploadImages(files, onAsset, onProgress, blueprint, onState) {
|
|
3
3
|
const failures = [];
|
|
4
4
|
onProgress(0, files.length, 0);
|
|
5
|
-
//
|
|
5
|
+
// Transfer one file at a time directly to private R2 staging.
|
|
6
6
|
for (const [index, file] of files.entries()) {
|
|
7
7
|
onState?.(index, 'uploading');
|
|
8
8
|
try {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const signed = await api('media/upload', {
|
|
10
|
+
name: file.name,
|
|
11
|
+
type: file.type,
|
|
12
|
+
size: file.size,
|
|
13
|
+
blueprint
|
|
14
|
+
});
|
|
15
|
+
const response = await fetch(signed.url, {
|
|
16
|
+
method: 'PUT',
|
|
17
|
+
headers: signed.headers,
|
|
18
|
+
body: file
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok)
|
|
21
|
+
throw new Error('Upload failed. Please try again.');
|
|
22
|
+
// Completion is idempotent; retry a lost response without transferring the file again.
|
|
23
|
+
let asset;
|
|
24
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
25
|
+
try {
|
|
26
|
+
asset = await api('media/upload/complete', { id: signed.id });
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (attempt === 2)
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
onAsset(asset);
|
|
14
35
|
onState?.(index, 'done');
|
|
15
36
|
}
|
|
16
37
|
catch (error) {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute, join, relative, resolve } from 'node:path';
|
|
3
|
+
const mapping = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
4
|
+
// Arrays and scalar settings replace defaults; mappings retain inherited keys and order.
|
|
5
|
+
function merge(base, local) {
|
|
6
|
+
return Object.fromEntries([...new Set([...Object.keys(base), ...Object.keys(local)])].map((key) => [
|
|
7
|
+
key,
|
|
8
|
+
Object.hasOwn(local, key)
|
|
9
|
+
? mapping(base[key]) && mapping(local[key])
|
|
10
|
+
? merge(base[key], local[key])
|
|
11
|
+
: local[key]
|
|
12
|
+
: base[key]
|
|
13
|
+
]));
|
|
14
|
+
}
|
|
15
|
+
export function createFieldResolver(directory, read) {
|
|
16
|
+
const sharedDirectory = resolve(directory, 'fields');
|
|
17
|
+
const cache = new Map();
|
|
18
|
+
const active = [];
|
|
19
|
+
function shared(path) {
|
|
20
|
+
const canonical = realpathSync(path);
|
|
21
|
+
const within = relative(realpathSync(sharedDirectory), canonical);
|
|
22
|
+
if (within.startsWith('..') || isAbsolute(within))
|
|
23
|
+
throw new Error(`${path}: shared fields must stay inside ${sharedDirectory}`);
|
|
24
|
+
if (active.includes(canonical))
|
|
25
|
+
throw new Error(`Circular field extends: ${[...active, canonical].join(' -> ')}`);
|
|
26
|
+
const cached = cache.get(canonical);
|
|
27
|
+
if (cached)
|
|
28
|
+
return structuredClone(cached);
|
|
29
|
+
active.push(canonical);
|
|
30
|
+
try {
|
|
31
|
+
const value = read(path, (value) => field(value, path));
|
|
32
|
+
cache.set(canonical, value);
|
|
33
|
+
return structuredClone(value);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
active.pop();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function field(value, location) {
|
|
40
|
+
if (!mapping(value))
|
|
41
|
+
return value;
|
|
42
|
+
let result = value;
|
|
43
|
+
if (Object.hasOwn(value, 'extends')) {
|
|
44
|
+
const reference = value.extends;
|
|
45
|
+
if (typeof reference !== 'string' ||
|
|
46
|
+
!/^fields\/[a-zA-Z0-9_-]+(?:\/[a-zA-Z0-9_-]+)*$/.test(reference))
|
|
47
|
+
throw new Error(`${location}.extends: Use a reference such as fields/seo without an extension`);
|
|
48
|
+
const candidates = ['.yaml', '.yml'].map((extension) => join(directory, reference + extension));
|
|
49
|
+
const matches = candidates.filter(existsSync);
|
|
50
|
+
if (matches.length !== 1)
|
|
51
|
+
throw new Error(`${location}.extends: ${matches.length ? 'Ambiguous' : 'Unknown'} shared field ${reference}`);
|
|
52
|
+
const base = shared(matches[0]);
|
|
53
|
+
const local = Object.fromEntries(Object.entries(value).filter(([key]) => key !== 'extends'));
|
|
54
|
+
// Resolve explicit nested references before merging, so their defaults override
|
|
55
|
+
// the corresponding field in the inherited parent definition.
|
|
56
|
+
result = merge({ ...base }, nested(local, location));
|
|
57
|
+
}
|
|
58
|
+
return nested(result, location);
|
|
59
|
+
}
|
|
60
|
+
function nested(value, location) {
|
|
61
|
+
return mapping(value.fields)
|
|
62
|
+
? { ...value, fields: fields(value.fields, `${location}.fields`) }
|
|
63
|
+
: value;
|
|
64
|
+
}
|
|
65
|
+
function fields(value, location) {
|
|
66
|
+
return Object.fromEntries(Object.entries(value).map(([key, value]) => [key, field(value, `${location}.${key}`)]));
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
shared,
|
|
70
|
+
blueprint(value, path) {
|
|
71
|
+
return mapping(value) && mapping(value.fields)
|
|
72
|
+
? { ...value, fields: fields(value.fields, `${path}: fields`) }
|
|
73
|
+
: value;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { Field, FileBlueprint, Payload, SiteDefinition } from './types.js';
|
|
1
|
+
import type { Field, FileBlueprint, FocusPoint, Payload, SiteDefinition } from './types.js';
|
|
2
2
|
export declare const imageMimeTypes: string[];
|
|
3
3
|
export declare function fileBlueprints(definition: SiteDefinition): FileBlueprint[];
|
|
4
4
|
export declare function getFileBlueprint(definition: SiteDefinition, id?: string | null): FileBlueprint;
|
|
5
5
|
export declare function effectiveMetadata(defaults: Payload, overrides: Payload, fields: Record<string, Field>): Payload;
|
|
6
6
|
export declare function publicMetadata(fields: Record<string, Field>, values: Payload): Payload;
|
|
7
7
|
export declare function configureFileFields(definition: SiteDefinition): SiteDefinition;
|
|
8
|
+
export declare function isFocusPoint(value: unknown): value is FocusPoint;
|
|
9
|
+
export declare function fileFocus(blueprint: FileBlueprint, metadata: Payload): FocusPoint | undefined;
|
package/dist/blueprints/files.js
CHANGED
|
@@ -64,6 +64,8 @@ export function publicMetadata(fields, values) {
|
|
|
64
64
|
return result;
|
|
65
65
|
}
|
|
66
66
|
export function configureFileFields(definition) {
|
|
67
|
+
if (definition.config.media.presets['sandcms-preview'])
|
|
68
|
+
throw new Error('sandcms-preview is reserved for the focal point picker');
|
|
67
69
|
const blueprints = fileBlueprints(definition);
|
|
68
70
|
const ids = new Set();
|
|
69
71
|
for (const blueprint of blueprints) {
|
|
@@ -74,15 +76,25 @@ export function configureFileFields(definition) {
|
|
|
74
76
|
throw new Error(`${blueprint.id}: only supported image MIME types can be accepted for now`);
|
|
75
77
|
if (blueprint.fields.image)
|
|
76
78
|
throw new Error(`${blueprint.id}: image is reserved for gallery references`);
|
|
77
|
-
|
|
79
|
+
if (Object.values(blueprint.fields).filter((f) => f.type === 'focus').length > 1)
|
|
80
|
+
throw new Error(`${blueprint.id}: only one focus field is supported`);
|
|
81
|
+
const check = (fields, nested = false) => {
|
|
78
82
|
for (const field of Object.values(fields)) {
|
|
83
|
+
if (nested && field.type === 'focus')
|
|
84
|
+
throw new Error(`${blueprint.id}: focus must be a top-level file field`);
|
|
79
85
|
if (['media', 'media-list', 'gallery'].includes(field.type))
|
|
80
86
|
throw new Error(`${blueprint.id}: file metadata cannot contain media fields`);
|
|
81
87
|
if (field.type === 'relation' &&
|
|
82
88
|
!definition.blueprints.some((b) => b.kind === 'collection' && b.id === field.collection))
|
|
83
89
|
throw new Error(`${blueprint.id}: unknown relation collection ${field.collection}`);
|
|
90
|
+
if (field.type === 'link' &&
|
|
91
|
+
field.collection &&
|
|
92
|
+
!definition.blueprints.some((b) => b.kind === 'collection' && b.id === field.collection))
|
|
93
|
+
throw new Error(`${blueprint.id}: unknown relation collection ${field.collection}`);
|
|
94
|
+
if (field.type === 'link' && field.fileBlueprint)
|
|
95
|
+
getFileBlueprint(definition, field.fileBlueprint);
|
|
84
96
|
if (field.fields)
|
|
85
|
-
check(field.fields);
|
|
97
|
+
check(field.fields, true);
|
|
86
98
|
}
|
|
87
99
|
};
|
|
88
100
|
check(blueprint.fields);
|
|
@@ -91,6 +103,8 @@ export function configureFileFields(definition) {
|
|
|
91
103
|
getFileBlueprint(definition);
|
|
92
104
|
const visit = (fields) => {
|
|
93
105
|
for (const field of Object.values(fields)) {
|
|
106
|
+
if (field.type === 'focus')
|
|
107
|
+
throw new Error('Focus requires a file blueprint');
|
|
94
108
|
if (['media', 'media-list', 'gallery'].includes(field.type)) {
|
|
95
109
|
const file = getFileBlueprint(definition, field.fileBlueprint);
|
|
96
110
|
field.fileBlueprint = file.id;
|
|
@@ -99,10 +113,14 @@ export function configureFileFields(definition) {
|
|
|
99
113
|
for (const key of field.overrides ?? []) {
|
|
100
114
|
if (!file.fields[key])
|
|
101
115
|
throw new Error(`Unknown override ${key} in file blueprint ${file.id}`);
|
|
116
|
+
if (file.fields[key].type === 'focus')
|
|
117
|
+
throw new Error('Focus is shared file metadata and cannot be overridden');
|
|
102
118
|
field.fields[key] = { ...file.fields[key], required: false };
|
|
103
119
|
}
|
|
104
120
|
}
|
|
105
121
|
}
|
|
122
|
+
if (field.type === 'link' && field.fileBlueprint)
|
|
123
|
+
getFileBlueprint(definition, field.fileBlueprint);
|
|
106
124
|
if (field.fields)
|
|
107
125
|
visit(field.fields);
|
|
108
126
|
}
|
|
@@ -110,3 +128,18 @@ export function configureFileFields(definition) {
|
|
|
110
128
|
definition.blueprints.forEach((blueprint) => visit(blueprint.fields));
|
|
111
129
|
return definition;
|
|
112
130
|
}
|
|
131
|
+
export function isFocusPoint(value) {
|
|
132
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
133
|
+
return false;
|
|
134
|
+
const point = value;
|
|
135
|
+
return (Object.keys(point).length === 2 &&
|
|
136
|
+
['x', 'y'].every((key) => typeof point[key] === 'number' &&
|
|
137
|
+
Number.isFinite(point[key]) &&
|
|
138
|
+
point[key] >= 0 &&
|
|
139
|
+
point[key] <= 1));
|
|
140
|
+
}
|
|
141
|
+
export function fileFocus(blueprint, metadata) {
|
|
142
|
+
const key = Object.keys(blueprint.fields).find((key) => blueprint.fields[key].type === 'focus');
|
|
143
|
+
const value = key ? metadata[key] : undefined;
|
|
144
|
+
return isFocusPoint(value) ? { x: value.x, y: value.y } : undefined;
|
|
145
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BlueprintTab, FieldWidth } from './types.js';
|
|
2
|
+
export declare function widthSpan(width?: FieldWidth): number;
|
|
3
|
+
export declare function tabFields(tab: BlueprintTab): string[];
|
|
4
|
+
export declare function tabErrorCount(tab: BlueprintTab, errors: Record<string, string>): number;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function widthSpan(width = '1/1') {
|
|
2
|
+
const [numerator, denominator] = width.split('/').map(Number);
|
|
3
|
+
return (12 * numerator) / denominator;
|
|
4
|
+
}
|
|
5
|
+
export function tabFields(tab) {
|
|
6
|
+
return (tab.fields ??
|
|
7
|
+
tab.columns.flatMap((column) => Object.values(column.sections).flatMap((section) => section.fields)));
|
|
8
|
+
}
|
|
9
|
+
export function tabErrorCount(tab, errors) {
|
|
10
|
+
const fields = new Set(tabFields(tab));
|
|
11
|
+
return Object.keys(errors).filter((path) => fields.has(path.split('.')[0])).length;
|
|
12
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { Blueprint, Field, SiteDefinition } from './types.js';
|
|
3
|
-
export declare function yamlFile<T>(path: string, schema: z.ZodType<T
|
|
3
|
+
export declare function yamlFile<T>(path: string, schema: z.ZodType<T>, transform?: (value: unknown) => unknown): T;
|
|
4
4
|
export declare function loadDefinition(root?: string): SiteDefinition;
|
|
5
5
|
export declare function visitFields(fields: Record<string, Field>, visit: (field: Field, key: string) => void): void;
|
|
6
6
|
export declare function validateDefinitions(defs: Blueprint[]): void;
|