@conloca/cms-spa 0.2.3 → 0.2.4
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/dist/spa/main.css +6 -0
- package/dist/ts/.build-inputs.json +36 -27
- package/dist/ts/components/CMSDashboard.d.ts.map +1 -1
- package/dist/ts/components/CMSDashboard.js +2 -1
- package/dist/ts/components/CMSDashboard.js.map +1 -1
- package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts +6 -1
- package/dist/ts/components/dialogs/DeleteConfirmDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/DeleteConfirmDialog.js +2 -2
- package/dist/ts/components/dialogs/DeleteConfirmDialog.js.map +1 -1
- package/dist/ts/components/dialogs/MakePagesEditableDialog.d.ts +10 -0
- package/dist/ts/components/dialogs/MakePagesEditableDialog.d.ts.map +1 -0
- package/dist/ts/components/dialogs/MakePagesEditableDialog.js +35 -0
- package/dist/ts/components/dialogs/MakePagesEditableDialog.js.map +1 -0
- package/dist/ts/components/dialogs/MoveFolderDialog.d.ts +6 -1
- package/dist/ts/components/dialogs/MoveFolderDialog.d.ts.map +1 -1
- package/dist/ts/components/dialogs/MoveFolderDialog.js +3 -3
- package/dist/ts/components/dialogs/MoveFolderDialog.js.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/CMSMDXEditor.js +9 -9
- package/dist/ts/components/editor/CMSMDXEditor.js.map +1 -1
- package/dist/ts/components/editor/DocsPreviewButton.d.ts +6 -0
- package/dist/ts/components/editor/DocsPreviewButton.d.ts.map +1 -0
- package/dist/ts/components/editor/DocsPreviewButton.js +15 -0
- package/dist/ts/components/editor/DocsPreviewButton.js.map +1 -0
- package/dist/ts/components/editor/ImagePickerDialog.js +2 -2
- package/dist/ts/components/editor/ImagePickerDialog.js.map +1 -1
- package/dist/ts/components/editor/MdxPageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/MdxPageEditor.js +2 -1
- package/dist/ts/components/editor/MdxPageEditor.js.map +1 -1
- package/dist/ts/components/editor/PageEditor.d.ts.map +1 -1
- package/dist/ts/components/editor/PageEditor.js +1 -2
- package/dist/ts/components/editor/PageEditor.js.map +1 -1
- package/dist/ts/components/editor/draft-media-config.d.ts +20 -8
- package/dist/ts/components/editor/draft-media-config.d.ts.map +1 -1
- package/dist/ts/components/editor/draft-media-config.js +124 -60
- package/dist/ts/components/editor/draft-media-config.js.map +1 -1
- package/dist/ts/components/editor/preview-availability.d.ts +2 -0
- package/dist/ts/components/editor/preview-availability.d.ts.map +1 -1
- package/dist/ts/components/editor/preview-availability.js +2 -0
- package/dist/ts/components/editor/preview-availability.js.map +1 -1
- package/dist/ts/components/editors/DataEditor.d.ts +6 -2
- package/dist/ts/components/editors/DataEditor.d.ts.map +1 -1
- package/dist/ts/components/editors/DataEditor.js +46 -19
- package/dist/ts/components/editors/DataEditor.js.map +1 -1
- package/dist/ts/components/fields/ImageField.js +2 -2
- package/dist/ts/components/fields/ImageField.js.map +1 -1
- package/dist/ts/components/media/AssetCard.d.ts.map +1 -1
- package/dist/ts/components/media/AssetCard.js +3 -3
- package/dist/ts/components/media/AssetCard.js.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.d.ts.map +1 -1
- package/dist/ts/components/media/AssetDetailSidebar.js +6 -3
- package/dist/ts/components/media/AssetDetailSidebar.js.map +1 -1
- package/dist/ts/components/media/AssetUsageList.d.ts +13 -0
- package/dist/ts/components/media/AssetUsageList.d.ts.map +1 -0
- package/dist/ts/components/media/AssetUsageList.js +35 -0
- package/dist/ts/components/media/AssetUsageList.js.map +1 -0
- package/dist/ts/components/media/MediaLibrary.d.ts.map +1 -1
- package/dist/ts/components/media/MediaLibrary.js +6 -4
- package/dist/ts/components/media/MediaLibrary.js.map +1 -1
- package/dist/ts/components/media/index.d.ts +1 -0
- package/dist/ts/components/media/index.d.ts.map +1 -1
- package/dist/ts/components/media/index.js +1 -0
- package/dist/ts/components/media/index.js.map +1 -1
- package/dist/ts/components/pages/DataList.d.ts.map +1 -1
- package/dist/ts/components/pages/DataList.js +48 -31
- package/dist/ts/components/pages/DataList.js.map +1 -1
- package/dist/ts/components/pages/MediaPage.d.ts.map +1 -1
- package/dist/ts/components/pages/MediaPage.js +7 -5
- package/dist/ts/components/pages/MediaPage.js.map +1 -1
- package/dist/ts/components/pages/NoPagesYet.d.ts +5 -0
- package/dist/ts/components/pages/NoPagesYet.d.ts.map +1 -0
- package/dist/ts/components/pages/NoPagesYet.js +16 -0
- package/dist/ts/components/pages/NoPagesYet.js.map +1 -0
- package/dist/ts/components/pages/PageList.d.ts.map +1 -1
- package/dist/ts/components/pages/PageList.js +9 -4
- package/dist/ts/components/pages/PageList.js.map +1 -1
- package/dist/ts/components/sandbox/ContentSandbox.js +3 -3
- package/dist/ts/components/sandbox/ContentSandbox.js.map +1 -1
- package/dist/ts/convert-pages.d.ts +30 -0
- package/dist/ts/convert-pages.d.ts.map +1 -0
- package/dist/ts/convert-pages.js +85 -0
- package/dist/ts/convert-pages.js.map +1 -0
- package/dist/ts/frame/editor-frame.d.ts +1 -1
- package/dist/ts/frame/editor-frame.d.ts.map +1 -1
- package/dist/ts/frame/editor-frame.js +7 -2
- package/dist/ts/frame/editor-frame.js.map +1 -1
- package/dist/ts/frame/media-cache.d.ts +13 -2
- package/dist/ts/frame/media-cache.d.ts.map +1 -1
- package/dist/ts/frame/media-cache.js +24 -9
- package/dist/ts/frame/media-cache.js.map +1 -1
- package/dist/ts/frame/protocol.d.ts +9 -1
- package/dist/ts/frame/protocol.d.ts.map +1 -1
- package/dist/ts/frame/protocol.js +5 -0
- package/dist/ts/frame/protocol.js.map +1 -1
- package/dist/ts/hooks/index.d.ts +2 -0
- package/dist/ts/hooks/index.d.ts.map +1 -1
- package/dist/ts/hooks/index.js +1 -0
- package/dist/ts/hooks/index.js.map +1 -1
- package/dist/ts/hooks/usePageConversion.d.ts +11 -0
- package/dist/ts/hooks/usePageConversion.d.ts.map +1 -0
- package/dist/ts/hooks/usePageConversion.js +47 -0
- package/dist/ts/hooks/usePageConversion.js.map +1 -0
- package/dist/ts/hooks/useUploadFlow.d.ts.map +1 -1
- package/dist/ts/hooks/useUploadFlow.js +41 -7
- package/dist/ts/hooks/useUploadFlow.js.map +1 -1
- package/dist/ts/index.d.ts +2 -0
- package/dist/ts/index.d.ts.map +1 -1
- package/dist/ts/index.js +3 -0
- package/dist/ts/index.js.map +1 -1
- package/dist/ts/media/prepare-image-upload.d.ts +19 -0
- package/dist/ts/media/prepare-image-upload.d.ts.map +1 -0
- package/dist/ts/media/prepare-image-upload.js +93 -0
- package/dist/ts/media/prepare-image-upload.js.map +1 -0
- package/dist/ts/media/use-asset-serve-src.d.ts +7 -0
- package/dist/ts/media/use-asset-serve-src.d.ts.map +1 -0
- package/dist/ts/media/use-asset-serve-src.js +17 -0
- package/dist/ts/media/use-asset-serve-src.js.map +1 -0
- package/dist/ts/ui-config.d.ts +13 -3
- package/dist/ts/ui-config.d.ts.map +1 -1
- package/dist/ts/ui-config.js +14 -0
- package/dist/ts/ui-config.js.map +1 -1
- package/dist/ts/utils/asset-url.d.ts +3 -0
- package/dist/ts/utils/asset-url.d.ts.map +1 -1
- package/dist/ts/utils/asset-url.js +4 -0
- package/dist/ts/utils/asset-url.js.map +1 -1
- package/dist/ts/utils/data-entry-validation.d.ts +11 -0
- package/dist/ts/utils/data-entry-validation.d.ts.map +1 -0
- package/dist/ts/utils/data-entry-validation.js +15 -0
- package/dist/ts/utils/data-entry-validation.js.map +1 -0
- package/package.json +4 -5
- package/src/components/CMSDashboard.tsx +16 -8
- package/src/components/dialogs/DeleteConfirmDialog.tsx +14 -1
- package/src/components/dialogs/MakePagesEditableDialog.tsx +112 -0
- package/src/components/dialogs/MoveFolderDialog.tsx +9 -2
- package/src/components/editor/CMSMDXEditor.tsx +9 -9
- package/src/components/editor/DocsPreviewButton.tsx +25 -0
- package/src/components/editor/ImagePickerDialog.tsx +2 -2
- package/src/components/editor/MdxPageEditor.tsx +2 -0
- package/src/components/editor/PageEditor.tsx +1 -5
- package/src/components/editor/draft-media-config.ts +121 -65
- package/src/components/editor/preview-availability.ts +3 -0
- package/src/components/editors/DataEditor.tsx +65 -32
- package/src/components/fields/ImageField.tsx +2 -2
- package/src/components/media/AssetCard.tsx +4 -4
- package/src/components/media/AssetDetailSidebar.tsx +34 -21
- package/src/components/media/AssetUsageList.tsx +84 -0
- package/src/components/media/MediaLibrary.tsx +6 -4
- package/src/components/media/index.ts +1 -0
- package/src/components/pages/DataList.tsx +53 -29
- package/src/components/pages/MediaPage.tsx +14 -5
- package/src/components/pages/NoPagesYet.tsx +41 -0
- package/src/components/pages/PageList.tsx +28 -23
- package/src/components/sandbox/ContentSandbox.tsx +3 -3
- package/src/convert-pages.ts +110 -0
- package/src/frame/editor-frame.ts +6 -2
- package/src/frame/media-cache.ts +28 -15
- package/src/frame/protocol.ts +10 -1
- package/src/hooks/index.ts +2 -0
- package/src/hooks/usePageConversion.ts +55 -0
- package/src/hooks/useUploadFlow.ts +44 -7
- package/src/index.ts +3 -0
- package/src/media/prepare-image-upload.ts +118 -0
- package/src/media/use-asset-serve-src.ts +22 -0
- package/src/ui-config.ts +23 -3
- package/src/utils/asset-url.ts +6 -0
- package/src/utils/data-entry-validation.ts +16 -0
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type DataCollectionEntry,
|
|
3
|
+
getContentAPIClient,
|
|
4
|
+
useLocalizedContent,
|
|
5
|
+
useUpdateLocalized,
|
|
6
|
+
} from '@conloca/content-api-client';
|
|
2
7
|
import { AlertCircle, Code2, Loader2, Save } from 'lucide-react';
|
|
3
8
|
import { useEffect, useRef, useState } from 'react';
|
|
4
|
-
import type
|
|
9
|
+
import { type HostSchema, isHostSchema } from '../../host-schema.js';
|
|
5
10
|
import { contentFailureMessage } from '../../utils/content-failure.js';
|
|
11
|
+
import { validateEntryData } from '../../utils/data-entry-validation.js';
|
|
6
12
|
import { UnsavedChangesDialog } from '../dialogs/UnsavedChangesDialog.js';
|
|
7
13
|
import { LocaleSelector } from '../editor/LocaleSelector.js';
|
|
8
14
|
import { SchemaForm } from '../forms/SchemaForm.js';
|
|
9
15
|
|
|
10
16
|
interface DataEditorProps {
|
|
17
|
+
/** The entry's id, or '' for a new entry, which `create` writes on the first Save. */
|
|
11
18
|
id: string;
|
|
12
19
|
collection: string;
|
|
13
20
|
initialLocale: string;
|
|
14
21
|
existingLocales: string[];
|
|
15
22
|
schema: HostSchema | null;
|
|
23
|
+
/** Writes a new entry holding `data`; resolves true once it is created. */
|
|
24
|
+
create?: (data: DataCollectionEntry['data']) => Promise<boolean>;
|
|
16
25
|
onSave?: () => void;
|
|
17
26
|
onCancel?: () => void;
|
|
18
27
|
}
|
|
@@ -28,6 +37,7 @@ export function DataEditor({
|
|
|
28
37
|
initialLocale,
|
|
29
38
|
existingLocales,
|
|
30
39
|
schema,
|
|
40
|
+
create,
|
|
31
41
|
onSave,
|
|
32
42
|
onCancel,
|
|
33
43
|
}: DataEditorProps) {
|
|
@@ -47,6 +57,8 @@ export function DataEditor({
|
|
|
47
57
|
const [values, setValues] = useState<Record<string, unknown>>({});
|
|
48
58
|
const [hasChanges, setHasChanges] = useState(false);
|
|
49
59
|
const [saveError, setSaveError] = useState<string | null>(null);
|
|
60
|
+
const [saving, setSaving] = useState(false);
|
|
61
|
+
const isNew = id === '';
|
|
50
62
|
|
|
51
63
|
// Initialize form values and etag when entry loads
|
|
52
64
|
useEffect(() => {
|
|
@@ -67,28 +79,46 @@ export function DataEditor({
|
|
|
67
79
|
setHasChanges(true);
|
|
68
80
|
};
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Writes the form once it passes the schema, as the build validates the entry; resolves whether it
|
|
84
|
+
* was written.
|
|
85
|
+
*/
|
|
86
|
+
const handleSave = async (): Promise<boolean> => {
|
|
87
|
+
if (saving || !isHostSchema(schema)) return false;
|
|
88
|
+
const invalid = validateEntryData(schema, values);
|
|
89
|
+
setSaveError(invalid);
|
|
90
|
+
if (invalid) return false;
|
|
73
91
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
92
|
+
setSaving(true);
|
|
93
|
+
try {
|
|
94
|
+
if (isNew) {
|
|
95
|
+
const created = (await create?.(values)) ?? false;
|
|
96
|
+
if (created) onSave?.();
|
|
97
|
+
return created;
|
|
98
|
+
}
|
|
82
99
|
|
|
83
|
-
|
|
100
|
+
const result = await updateLocalized.mutateAsync({
|
|
101
|
+
id,
|
|
102
|
+
locale: currentLocale,
|
|
103
|
+
data: {
|
|
104
|
+
content: { data: values },
|
|
105
|
+
},
|
|
106
|
+
etag: currentEtag,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (!result.success) {
|
|
110
|
+
setSaveError(contentFailureMessage(result, 'Failed to save data'));
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
84
113
|
setHasChanges(false);
|
|
85
114
|
savedValuesRef.current = values;
|
|
86
115
|
if (result.etag) {
|
|
87
116
|
setCurrentEtag(result.etag);
|
|
88
117
|
}
|
|
89
118
|
onSave?.();
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
return true;
|
|
120
|
+
} finally {
|
|
121
|
+
setSaving(false);
|
|
92
122
|
}
|
|
93
123
|
};
|
|
94
124
|
|
|
@@ -131,11 +161,12 @@ export function DataEditor({
|
|
|
131
161
|
const handleUnsavedDialogSave = async () => {
|
|
132
162
|
if (!pendingLocaleSwitch) return;
|
|
133
163
|
|
|
134
|
-
// Save current content first
|
|
164
|
+
// Save current content first; a refused save keeps the locale and the edits, with the reason shown.
|
|
135
165
|
try {
|
|
136
|
-
await handleSave();
|
|
166
|
+
const saved = await handleSave();
|
|
137
167
|
setShowUnsavedDialog(false);
|
|
138
|
-
await switchLocale(pendingLocaleSwitch);
|
|
168
|
+
if (saved) await switchLocale(pendingLocaleSwitch);
|
|
169
|
+
else setPendingLocaleSwitch(null);
|
|
139
170
|
} catch (error) {
|
|
140
171
|
// Don't switch if save failed
|
|
141
172
|
console.error('Failed to save before locale switch:', error);
|
|
@@ -196,15 +227,17 @@ export function DataEditor({
|
|
|
196
227
|
return (
|
|
197
228
|
<>
|
|
198
229
|
<div className="space-y-6">
|
|
199
|
-
{/* Locale selector header - only show existing locales */}
|
|
200
|
-
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
230
|
+
{/* Locale selector header - only show existing locales; a new entry has one, the one it is created in */}
|
|
231
|
+
{!isNew && (
|
|
232
|
+
<div className="flex items-center gap-3 pb-4 border-b border-grey-09 dark:border-grey-03">
|
|
233
|
+
<span className="text-sm text-grey-04 dark:text-grey-07">Locale:</span>
|
|
234
|
+
<LocaleSelector
|
|
235
|
+
currentLocale={currentLocale}
|
|
236
|
+
availableLocales={existingLocales}
|
|
237
|
+
onChange={handleLocaleChange}
|
|
238
|
+
/>
|
|
239
|
+
</div>
|
|
240
|
+
)}
|
|
208
241
|
|
|
209
242
|
<SchemaForm schema={schema} values={values} onChange={handleChange} />
|
|
210
243
|
|
|
@@ -220,7 +253,7 @@ export function DataEditor({
|
|
|
220
253
|
{hasChanges ? (
|
|
221
254
|
<span className="text-yellow-05 dark:text-yellow-07">Unsaved changes</span>
|
|
222
255
|
) : (
|
|
223
|
-
<span>No changes</span>
|
|
256
|
+
<span>{isNew ? 'Not saved yet' : 'No changes'}</span>
|
|
224
257
|
)}
|
|
225
258
|
</div>
|
|
226
259
|
|
|
@@ -229,7 +262,7 @@ export function DataEditor({
|
|
|
229
262
|
<button
|
|
230
263
|
type="button"
|
|
231
264
|
onClick={onCancel}
|
|
232
|
-
disabled={
|
|
265
|
+
disabled={saving}
|
|
233
266
|
className="px-4 py-2 border border-grey-09 dark:border-grey-03 rounded-md hover:bg-grey-11 dark:hover:bg-grey-03 transition-colors disabled:opacity-50"
|
|
234
267
|
>
|
|
235
268
|
Cancel
|
|
@@ -238,10 +271,10 @@ export function DataEditor({
|
|
|
238
271
|
<button
|
|
239
272
|
type="button"
|
|
240
273
|
onClick={handleSave}
|
|
241
|
-
disabled={!hasChanges ||
|
|
274
|
+
disabled={(!hasChanges && !isNew) || saving || !isHostSchema(schema)}
|
|
242
275
|
className="px-4 py-2 bg-azure-04 text-white rounded-md hover:bg-azure-03 transition-colors disabled:opacity-50 disabled:cursor-not-allowed inline-flex items-center gap-2"
|
|
243
276
|
>
|
|
244
|
-
{
|
|
277
|
+
{saving ? (
|
|
245
278
|
<>
|
|
246
279
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
247
280
|
Saving...
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FolderOpen } from 'lucide-react';
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
3
|
import type { AssetEntry } from '../../hooks/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { assetRefOf } from '../../utils/asset-url.js';
|
|
5
5
|
import { ImagePicker } from '../media/ImagePicker.js';
|
|
6
6
|
import { Input } from '../ui/index.js';
|
|
7
7
|
|
|
@@ -33,7 +33,7 @@ export function ImageFieldRender({ value, onChange, inputId }: ImageFieldRenderP
|
|
|
33
33
|
}, [value]);
|
|
34
34
|
|
|
35
35
|
const handleSelect = (asset: AssetEntry) => {
|
|
36
|
-
const assetPath =
|
|
36
|
+
const assetPath = assetRefOf(asset);
|
|
37
37
|
onChange(assetPath);
|
|
38
38
|
setLocalValue(assetPath);
|
|
39
39
|
setModalOpen(false);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useAssetServeSrc } from '../../frame/media-cache.js';
|
|
2
1
|
import type { AssetEntry } from '../../hooks/index.js';
|
|
3
2
|
import { AssetScopePill } from '../../media/AssetScopePill.js';
|
|
4
3
|
import { MediaIssueBadge } from '../../media/MediaIssueBadge.js';
|
|
5
4
|
import { useAssetScope } from '../../media/use-asset-scope.js';
|
|
5
|
+
import { useAssetServeSrc } from '../../media/use-asset-serve-src.js';
|
|
6
6
|
import { useMediaIssue } from '../../media/use-media-issue.js';
|
|
7
7
|
import { cn } from '../../utils/cn.js';
|
|
8
8
|
|
|
@@ -33,7 +33,7 @@ export function AssetCard({
|
|
|
33
33
|
// reports. Returns null when the host has no opinion — surfaces
|
|
34
34
|
// degrade exactly like the scope pill in standalone mounts.
|
|
35
35
|
const issue = useMediaIssue(asset.filename, asset.folder);
|
|
36
|
-
const src = useAssetServeSrc(assetsBasePath, asset
|
|
36
|
+
const src = useAssetServeSrc(assetsBasePath, asset);
|
|
37
37
|
|
|
38
38
|
const handleClick = () => {
|
|
39
39
|
onClick?.();
|
|
@@ -78,8 +78,8 @@ export function AssetCard({
|
|
|
78
78
|
|
|
79
79
|
{/* Info - filename only */}
|
|
80
80
|
<div className="px-2 py-1.5">
|
|
81
|
-
<p className="text-xs text-grey-01 dark:text-grey-12 truncate" title={asset.
|
|
82
|
-
{asset.
|
|
81
|
+
<p className="text-xs text-grey-01 dark:text-grey-12 truncate" title={asset.filename}>
|
|
82
|
+
{asset.filename}
|
|
83
83
|
</p>
|
|
84
84
|
</div>
|
|
85
85
|
</button>
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { formatFileSize } from '@conloca/content-api-client';
|
|
2
2
|
import { FolderInput, Loader2, Trash2, X } from 'lucide-react';
|
|
3
3
|
import { useMemo, useState } from 'react';
|
|
4
|
-
import { useAssetServeSrc } from '../../frame/media-cache.js';
|
|
5
4
|
import type { AssetEntry } from '../../hooks/index.js';
|
|
6
5
|
import { useAssetUsage, useDeleteAsset, useMoveAssets, useUpdateAssetMetadata } from '../../hooks/index.js';
|
|
7
6
|
import { AssetScopePill } from '../../media/AssetScopePill.js';
|
|
8
7
|
import { MediaIssueBadge } from '../../media/MediaIssueBadge.js';
|
|
9
8
|
import { useAssetScope } from '../../media/use-asset-scope.js';
|
|
9
|
+
import { useAssetServeSrc } from '../../media/use-asset-serve-src.js';
|
|
10
10
|
import { useMediaIssue } from '../../media/use-media-issue.js';
|
|
11
11
|
import { buildAssetPath } from '../../utils/asset-url.js';
|
|
12
12
|
import { MoveFolderDialog } from '../dialogs/index.js';
|
|
13
13
|
import { Button, IconButton, Input } from '../ui/index.js';
|
|
14
|
+
import { AssetUsageList } from './AssetUsageList.js';
|
|
14
15
|
|
|
15
16
|
function formatDate(dateString: string): string {
|
|
16
17
|
const date = new Date(dateString);
|
|
@@ -48,6 +49,8 @@ export function AssetDetailSidebar({
|
|
|
48
49
|
const [storedTags, setStoredTags] = useState<string[]>(asset.tags ?? []);
|
|
49
50
|
const [confirmDelete, setConfirmDelete] = useState(false);
|
|
50
51
|
const [showMoveDialog, setShowMoveDialog] = useState(false);
|
|
52
|
+
// Whether the pages using this image are known, so a move or delete cannot be confirmed before they are shown.
|
|
53
|
+
const [usageSettled, setUsageSettled] = useState(false);
|
|
51
54
|
// Only with a host bridge: branch vs published scope. Returns null
|
|
52
55
|
// when no host bridge is installed, so the pill is naturally hidden
|
|
53
56
|
// in astro-cms / local dev.
|
|
@@ -56,7 +59,7 @@ export function AssetDetailSidebar({
|
|
|
56
59
|
// Returns null when the host has no opinion or the asset is
|
|
57
60
|
// healthy; the badge collapses to nothing in either case.
|
|
58
61
|
const issue = useMediaIssue(asset.filename, asset.folder);
|
|
59
|
-
const src = useAssetServeSrc(assetsBasePath, asset
|
|
62
|
+
const src = useAssetServeSrc(assetsBasePath, asset);
|
|
60
63
|
// Folder + filename is the asset identity used by metadata, usage and delete routes.
|
|
61
64
|
const path = useMemo(() => buildAssetPath(asset.folder, asset.filename), [asset.folder, asset.filename]);
|
|
62
65
|
|
|
@@ -158,8 +161,8 @@ export function AssetDetailSidebar({
|
|
|
158
161
|
{/* Header */}
|
|
159
162
|
<div className="flex items-start justify-between gap-3 px-4 py-3 border-b border-line">
|
|
160
163
|
<div className="flex-1 min-w-0 flex flex-col gap-1">
|
|
161
|
-
<h3 className="font-semibold text-grey-01 dark:text-grey-12 truncate" title={asset.
|
|
162
|
-
{asset.
|
|
164
|
+
<h3 className="font-semibold text-grey-01 dark:text-grey-12 truncate" title={asset.filename}>
|
|
165
|
+
{asset.filename}
|
|
163
166
|
</h3>
|
|
164
167
|
{/* Scope pill — `md` variant here (vs `sm` on AssetCard
|
|
165
168
|
corners). Sits below the filename so the branch
|
|
@@ -190,22 +193,28 @@ export function AssetDetailSidebar({
|
|
|
190
193
|
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Filename</dt>
|
|
191
194
|
<dd className="text-sm text-grey-01 dark:text-grey-12 break-all">{asset.filename}</dd>
|
|
192
195
|
</div>
|
|
193
|
-
|
|
196
|
+
{(asset.size > 0 || dimensions) && (
|
|
197
|
+
<div className="grid grid-cols-2 gap-3">
|
|
198
|
+
{asset.size > 0 && (
|
|
199
|
+
<div>
|
|
200
|
+
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Size</dt>
|
|
201
|
+
<dd className="text-sm text-grey-01 dark:text-grey-12">{formatFileSize(asset.size)}</dd>
|
|
202
|
+
</div>
|
|
203
|
+
)}
|
|
204
|
+
{dimensions && (
|
|
205
|
+
<div>
|
|
206
|
+
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Dimensions</dt>
|
|
207
|
+
<dd className="text-sm text-grey-01 dark:text-grey-12">{dimensions}</dd>
|
|
208
|
+
</div>
|
|
209
|
+
)}
|
|
210
|
+
</div>
|
|
211
|
+
)}
|
|
212
|
+
{asset.uploadedAt && (
|
|
194
213
|
<div>
|
|
195
|
-
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">
|
|
196
|
-
<dd className="text-sm text-grey-01 dark:text-grey-12">{
|
|
214
|
+
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Uploaded</dt>
|
|
215
|
+
<dd className="text-sm text-grey-01 dark:text-grey-12">{formatDate(asset.uploadedAt)}</dd>
|
|
197
216
|
</div>
|
|
198
|
-
|
|
199
|
-
<div>
|
|
200
|
-
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Dimensions</dt>
|
|
201
|
-
<dd className="text-sm text-grey-01 dark:text-grey-12">{dimensions}</dd>
|
|
202
|
-
</div>
|
|
203
|
-
)}
|
|
204
|
-
</div>
|
|
205
|
-
<div>
|
|
206
|
-
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Uploaded</dt>
|
|
207
|
-
<dd className="text-sm text-grey-01 dark:text-grey-12">{formatDate(asset.uploadedAt)}</dd>
|
|
208
|
-
</div>
|
|
217
|
+
)}
|
|
209
218
|
{asset.mimeType && (
|
|
210
219
|
<div>
|
|
211
220
|
<dt className="text-xs text-grey-04 dark:text-grey-07 uppercase tracking-wide">Type</dt>
|
|
@@ -290,14 +299,15 @@ export function AssetDetailSidebar({
|
|
|
290
299
|
{/* Delete section */}
|
|
291
300
|
<div className="p-4">
|
|
292
301
|
{confirmDelete ? (
|
|
293
|
-
<div className="space-y-2">
|
|
302
|
+
<div className="space-y-2" data-testid="asset-delete-confirm">
|
|
294
303
|
<p className="text-sm text-red-04 dark:text-red-08">Delete this asset permanently?</p>
|
|
304
|
+
<AssetUsageList paths={[path]} onSettled={setUsageSettled} />
|
|
295
305
|
<div className="flex gap-2">
|
|
296
306
|
<Button
|
|
297
307
|
variant="destructive"
|
|
298
308
|
size="sm"
|
|
299
309
|
onClick={handleDelete}
|
|
300
|
-
disabled={deleteAsset.isPending}
|
|
310
|
+
disabled={deleteAsset.isPending || !usageSettled}
|
|
301
311
|
className="flex-1"
|
|
302
312
|
>
|
|
303
313
|
{deleteAsset.isPending ? 'Deleting...' : 'Yes, Delete'}
|
|
@@ -328,7 +338,10 @@ export function AssetDetailSidebar({
|
|
|
328
338
|
onMove={handleMove}
|
|
329
339
|
onCancel={() => setShowMoveDialog(false)}
|
|
330
340
|
isMoving={moveAssets.isPending}
|
|
331
|
-
|
|
341
|
+
confirmDisabled={!usageSettled}
|
|
342
|
+
>
|
|
343
|
+
<AssetUsageList paths={[path]} onSettled={setUsageSettled} />
|
|
344
|
+
</MoveFolderDialog>
|
|
332
345
|
</div>
|
|
333
346
|
</>
|
|
334
347
|
);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Loader2 } from 'lucide-react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useAssetUsage } from '../../hooks/index.js';
|
|
4
|
+
import { Button } from '../ui/index.js';
|
|
5
|
+
|
|
6
|
+
type UsageState = 'pending' | 'error' | 'unused' | 'used';
|
|
7
|
+
|
|
8
|
+
interface AssetUsageListProps {
|
|
9
|
+
/** The images about to be moved or deleted, each by its path from the media root. */
|
|
10
|
+
paths: string[];
|
|
11
|
+
/** Told whether every image's usage is known, so the caller can hold its confirm button until it is. */
|
|
12
|
+
onSettled: (settled: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The pages that link any of `paths`, shown before a move or delete: nothing rewrites those links, so the person
|
|
17
|
+
* sees which pages will show a broken image. Renders nothing once it knows no page uses them.
|
|
18
|
+
*/
|
|
19
|
+
export function AssetUsageList({ paths, onSettled }: AssetUsageListProps) {
|
|
20
|
+
const [states, setStates] = useState<Record<string, UsageState>>({});
|
|
21
|
+
const [retry, setRetry] = useState(0);
|
|
22
|
+
const report = useCallback((path: string, state: UsageState) => {
|
|
23
|
+
setStates((previous) => (previous[path] === state ? previous : { ...previous, [path]: state }));
|
|
24
|
+
}, []);
|
|
25
|
+
const shown = paths.map((path) => states[path] ?? 'pending');
|
|
26
|
+
const settled = shown.every((state) => state === 'used' || state === 'unused');
|
|
27
|
+
useEffect(() => onSettled(settled), [settled, onSettled]);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className="mb-4 text-sm">
|
|
31
|
+
{shown.includes('pending') ? (
|
|
32
|
+
<p className="flex items-center gap-2 text-grey-04 dark:text-grey-07">
|
|
33
|
+
<Loader2 className="w-4 h-4 animate-spin" />
|
|
34
|
+
<span>Checking which pages use this image…</span>
|
|
35
|
+
</p>
|
|
36
|
+
) : shown.includes('error') ? (
|
|
37
|
+
<div className="flex items-center gap-2">
|
|
38
|
+
<p className="text-red-04 dark:text-red-08">Could not check which pages use this image.</p>
|
|
39
|
+
<Button variant="outline" size="sm" onClick={() => setRetry((count) => count + 1)}>
|
|
40
|
+
Retry
|
|
41
|
+
</Button>
|
|
42
|
+
</div>
|
|
43
|
+
) : shown.includes('used') ? (
|
|
44
|
+
<p className="text-grey-01 dark:text-grey-12">
|
|
45
|
+
These pages use this image. Their links are not changed; they will show a broken image until you update them.
|
|
46
|
+
</p>
|
|
47
|
+
) : null}
|
|
48
|
+
<ul className="mt-2 space-y-1">
|
|
49
|
+
{paths.map((path) => (
|
|
50
|
+
<UsageRows key={path} path={path} retry={retry} onState={report} />
|
|
51
|
+
))}
|
|
52
|
+
</ul>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function UsageRows({
|
|
58
|
+
path,
|
|
59
|
+
retry,
|
|
60
|
+
onState,
|
|
61
|
+
}: {
|
|
62
|
+
path: string;
|
|
63
|
+
retry: number;
|
|
64
|
+
onState: (path: string, state: UsageState) => void;
|
|
65
|
+
}) {
|
|
66
|
+
const { data, isError, refetch } = useAssetUsage(path);
|
|
67
|
+
const state: UsageState = data ? (data.length > 0 ? 'used' : 'unused') : isError ? 'error' : 'pending';
|
|
68
|
+
useEffect(() => onState(path, state), [path, state, onState]);
|
|
69
|
+
// Asked again once per Retry click, never on a re-render.
|
|
70
|
+
const asked = useRef(retry);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (retry === asked.current) return;
|
|
73
|
+
asked.current = retry;
|
|
74
|
+
void refetch();
|
|
75
|
+
}, [retry, refetch]);
|
|
76
|
+
return (
|
|
77
|
+
data?.map((usage) => (
|
|
78
|
+
<li key={`${usage.page}-${usage.field}`} className="text-grey-01 dark:text-grey-12">
|
|
79
|
+
<span className="font-medium">{usage.page}</span>
|
|
80
|
+
<span className="text-grey-04 dark:text-grey-07"> – {usage.field}</span>
|
|
81
|
+
</li>
|
|
82
|
+
)) ?? null
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -94,19 +94,21 @@ export function MediaLibrary({
|
|
|
94
94
|
// Sort assets
|
|
95
95
|
const sortedAssets = useMemo(() => {
|
|
96
96
|
const sorted = [...filteredAssets];
|
|
97
|
+
// An image with no known upload date sorts as the oldest.
|
|
98
|
+
const time = (asset: AssetEntry) => Date.parse(asset.uploadedAt) || 0;
|
|
97
99
|
|
|
98
100
|
switch (sort) {
|
|
99
101
|
case 'date-newest':
|
|
100
|
-
sorted.sort((a, b) =>
|
|
102
|
+
sorted.sort((a, b) => time(b) - time(a));
|
|
101
103
|
break;
|
|
102
104
|
case 'date-oldest':
|
|
103
|
-
sorted.sort((a, b) =>
|
|
105
|
+
sorted.sort((a, b) => time(a) - time(b));
|
|
104
106
|
break;
|
|
105
107
|
case 'name-asc':
|
|
106
|
-
sorted.sort((a, b) => a.
|
|
108
|
+
sorted.sort((a, b) => a.filename.localeCompare(b.filename));
|
|
107
109
|
break;
|
|
108
110
|
case 'name-desc':
|
|
109
|
-
sorted.sort((a, b) => b.
|
|
111
|
+
sorted.sort((a, b) => b.filename.localeCompare(a.filename));
|
|
110
112
|
break;
|
|
111
113
|
case 'size-largest':
|
|
112
114
|
sorted.sort((a, b) => b.size - a.size);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { AssetCard } from './AssetCard.js';
|
|
2
2
|
export { AssetDetailSidebar } from './AssetDetailSidebar.js';
|
|
3
|
+
export { AssetUsageList } from './AssetUsageList.js';
|
|
3
4
|
export { BulkActionBar } from './BulkActionBar.js';
|
|
4
5
|
export { FolderNav } from './FolderNav.js';
|
|
5
6
|
export { FolderTreeSidebar } from './FolderTreeSidebar.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DataEditable } from '@conloca/content-api-client';
|
|
1
|
+
import type { DataCollectionEntry, DataEditable } from '@conloca/content-api-client';
|
|
2
2
|
import {
|
|
3
3
|
APIClientError,
|
|
4
4
|
type ContentManifest,
|
|
@@ -73,13 +73,14 @@ export function DataList({ dataSchemas }: DataListProps) {
|
|
|
73
73
|
locale: '',
|
|
74
74
|
existingLocales: [] as string[],
|
|
75
75
|
name: '',
|
|
76
|
+
description: '',
|
|
76
77
|
});
|
|
77
78
|
|
|
78
79
|
const { showError, showStaleWriteError, errorModalProps } = useErrorModal();
|
|
79
80
|
|
|
80
81
|
const createContent = useCreateContent();
|
|
81
|
-
// From the Create click until the
|
|
82
|
-
//
|
|
82
|
+
// From the Create click until the collection's names are read: a second click meanwhile would open
|
|
83
|
+
// a second editor.
|
|
83
84
|
const [creating, setCreating] = useState(false);
|
|
84
85
|
const deleteContent = useDeleteContent();
|
|
85
86
|
const updateLocalized = useUpdateLocalized();
|
|
@@ -165,23 +166,59 @@ export function DataList({ dataSchemas }: DataListProps) {
|
|
|
165
166
|
);
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
// Opens the editor on a new entry; `createEntry` writes it once the author saves valid data.
|
|
168
170
|
const handleCreateEntry = async (collection: string, values: Record<string, unknown>) => {
|
|
169
171
|
const title = ((values.title as string) || '').trim();
|
|
170
172
|
if (!title || !collection) return;
|
|
171
173
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
let name = slugify(title);
|
|
175
|
+
const description = typeof values.description === 'string' ? values.description.trim() : '';
|
|
176
|
+
|
|
177
|
+
let items: ContentManifest[];
|
|
178
|
+
setCreating(true);
|
|
179
|
+
try {
|
|
180
|
+
items = (await getContentAPIClient().getData(collection)).items;
|
|
181
|
+
} catch (loadError) {
|
|
182
|
+
showError('Failed to create data entry. Please try again.', loadError);
|
|
183
|
+
return;
|
|
184
|
+
} finally {
|
|
185
|
+
setCreating(false);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// A title with no a–z or 0–9 (Фото, 照片) makes no name: take an untitled one no entry has.
|
|
189
|
+
name ||= untitledName(items);
|
|
190
|
+
// Names that differ only in letter case share one file on a case-insensitive disk.
|
|
191
|
+
const nameTaken = items.some((entry) =>
|
|
192
|
+
Array.from(localesOf(entry)).some((locale) => locale.name?.toLowerCase() === name.toLowerCase()),
|
|
193
|
+
);
|
|
194
|
+
if (nameTaken) {
|
|
195
|
+
showError(`Data name ${name} already exists in collection ${collection}`);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
closeCreateDialog();
|
|
200
|
+
openEditDataDialog({
|
|
201
|
+
entryId: '',
|
|
202
|
+
entryTitle: title,
|
|
203
|
+
collection,
|
|
204
|
+
locale: newEntryLocale,
|
|
205
|
+
existingLocales: [newEntryLocale],
|
|
206
|
+
name,
|
|
207
|
+
description,
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/** Writes the new entry the editor is open on, holding `entryData`; resolves true once it is created. */
|
|
212
|
+
const createEntry = async (entryData: DataCollectionEntry['data']) => {
|
|
213
|
+
const { collection, entryTitle: title, locale, name } = editDataDialog;
|
|
214
|
+
const description = editDataDialog.description || undefined;
|
|
175
215
|
// The author never typed a name made up for a title with none to give: when that name is refused
|
|
176
216
|
// as taken, say where it came from. Any other failure is not about the name.
|
|
177
217
|
const withNameNote = (message: string, nameTaken: boolean) =>
|
|
178
|
-
|
|
218
|
+
slugify(title) || !nameTaken ? message : `${untitledNameNote(name)} ${message}`;
|
|
179
219
|
|
|
180
220
|
let result: Awaited<ReturnType<typeof createContent.mutateAsync>>;
|
|
181
|
-
setCreating(true);
|
|
182
221
|
try {
|
|
183
|
-
// A title with no a–z or 0–9 (Фото, 照片) makes no name: take an untitled one no entry has.
|
|
184
|
-
name ||= untitledName((await getContentAPIClient().getData(collection)).items);
|
|
185
222
|
result = await createContent.mutateAsync({
|
|
186
223
|
kind: 'data',
|
|
187
224
|
collection,
|
|
@@ -192,14 +229,12 @@ export function DataList({ dataSchemas }: DataListProps) {
|
|
|
192
229
|
description,
|
|
193
230
|
},
|
|
194
231
|
locales: {
|
|
195
|
-
[
|
|
232
|
+
[locale]: {
|
|
196
233
|
meta: {
|
|
197
234
|
title,
|
|
198
235
|
description,
|
|
199
236
|
},
|
|
200
|
-
content: {
|
|
201
|
-
data: {},
|
|
202
|
-
},
|
|
237
|
+
content: { data: entryData },
|
|
203
238
|
},
|
|
204
239
|
},
|
|
205
240
|
});
|
|
@@ -216,26 +251,14 @@ export function DataList({ dataSchemas }: DataListProps) {
|
|
|
216
251
|
),
|
|
217
252
|
error,
|
|
218
253
|
);
|
|
219
|
-
return;
|
|
220
|
-
} finally {
|
|
221
|
-
setCreating(false);
|
|
254
|
+
return false;
|
|
222
255
|
}
|
|
223
256
|
|
|
224
|
-
if (result.success
|
|
225
|
-
closeCreateDialog();
|
|
226
|
-
// Auto-open the editor so user can fill in schema fields
|
|
227
|
-
openEditDataDialog({
|
|
228
|
-
entryId: result.id,
|
|
229
|
-
entryTitle: title,
|
|
230
|
-
collection,
|
|
231
|
-
locale: newEntryLocale,
|
|
232
|
-
existingLocales: [newEntryLocale],
|
|
233
|
-
name,
|
|
234
|
-
});
|
|
235
|
-
} else if (!result.success) {
|
|
257
|
+
if (!result.success) {
|
|
236
258
|
const nameTaken = result.reason === 'name_taken' || result.reason === 'already_exists';
|
|
237
259
|
showError(withNameNote(contentFailureMessage(result, 'Failed to create data entry'), nameTaken), result.error);
|
|
238
260
|
}
|
|
261
|
+
return result.success;
|
|
239
262
|
};
|
|
240
263
|
|
|
241
264
|
const handleDeleteEntry = (entryId: string) => {
|
|
@@ -484,6 +507,7 @@ export function DataList({ dataSchemas }: DataListProps) {
|
|
|
484
507
|
initialLocale={editDataDialog.locale}
|
|
485
508
|
existingLocales={editDataDialog.existingLocales}
|
|
486
509
|
schema={dataSchemas[editDataDialog.collection] ?? null}
|
|
510
|
+
create={createEntry}
|
|
487
511
|
onSave={closeEditDataDialog}
|
|
488
512
|
onCancel={closeEditDataDialog}
|
|
489
513
|
/>
|