@elytracms/studio 0.0.38 → 0.0.40
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/convex/cms.ts +8 -2
- package/dist/components/app-views/default-modules.d.ts +60 -5
- package/dist/components/app-views/default-modules.js +53 -15
- package/dist/components/app-views/default-modules.js.map +1 -1
- package/dist/components/app-views/module.d.ts +2 -0
- package/dist/components/app-views/module.js +8 -0
- package/dist/components/app-views/module.js.map +1 -1
- package/dist/components/assets/asset-detail.d.ts +24 -0
- package/dist/components/assets/asset-detail.js +163 -0
- package/dist/components/assets/asset-detail.js.map +1 -0
- package/dist/components/assets/asset-grid.d.ts +28 -0
- package/dist/components/assets/asset-grid.js +68 -0
- package/dist/components/assets/asset-grid.js.map +1 -0
- package/dist/components/assets/asset-metadata.d.ts +19 -0
- package/dist/components/assets/asset-metadata.js +44 -0
- package/dist/components/assets/asset-metadata.js.map +1 -1
- package/dist/components/assets/assets-collection-view-source.d.ts +54 -0
- package/dist/components/assets/assets-collection-view-source.js +186 -0
- package/dist/components/assets/assets-collection-view-source.js.map +1 -0
- package/dist/components/assets/assets-module.d.ts +18 -0
- package/dist/components/assets/assets-module.js +94 -0
- package/dist/components/assets/assets-module.js.map +1 -0
- package/dist/components/assets/assets-store.js +2 -7
- package/dist/components/assets/assets-store.js.map +1 -1
- package/dist/components/assets/assets-view-preference.d.ts +15 -0
- package/dist/components/assets/assets-view-preference.js +22 -0
- package/dist/components/assets/assets-view-preference.js.map +1 -0
- package/dist/components/builder/builder-store.d.ts +12 -0
- package/dist/components/builder/builder-store.js +18 -16
- package/dist/components/builder/builder-store.js.map +1 -1
- package/dist/components/builder/clipboard-actions.js +5 -14
- package/dist/components/builder/clipboard-actions.js.map +1 -1
- package/dist/components/builder/composition-field-editor-lazy.d.ts +19 -0
- package/dist/components/builder/composition-field-editor-lazy.js +29 -0
- package/dist/components/builder/composition-field-editor-lazy.js.map +1 -0
- package/dist/components/builder/composition-field-editor.js +1 -4
- package/dist/components/builder/composition-field-editor.js.map +1 -1
- package/dist/components/builder/insert-context.d.ts +8 -0
- package/dist/components/builder/insert-context.js +1 -3
- package/dist/components/builder/insert-context.js.map +1 -1
- package/dist/components/builder/page-tree.js +1 -3
- package/dist/components/builder/page-tree.js.map +1 -1
- package/dist/components/builder/property-inspector.js +7 -134
- package/dist/components/builder/property-inspector.js.map +1 -1
- package/dist/components/cms/cms-store.d.ts +15 -4
- package/dist/components/cms/cms-store.js +42 -24
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.d.ts +8 -1
- package/dist/components/cms/collection-table.js +75 -11
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/column-width.d.ts +25 -0
- package/dist/components/cms/column-width.js +47 -0
- package/dist/components/cms/column-width.js.map +1 -0
- package/dist/components/cms/detail-editor.js +143 -79
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/details-pane.d.ts +21 -8
- package/dist/components/cms/details-pane.js +31 -11
- package/dist/components/cms/details-pane.js.map +1 -1
- package/dist/components/cms/discard-draft.d.ts +32 -0
- package/dist/components/cms/discard-draft.js +13 -0
- package/dist/components/cms/discard-draft.js.map +1 -0
- package/dist/components/cms/document-staging.d.ts +7 -0
- package/dist/components/cms/document-staging.js +44 -0
- package/dist/components/cms/document-staging.js.map +1 -0
- package/dist/components/cms/field-connection.d.ts +22 -0
- package/dist/components/cms/field-connection.js +37 -0
- package/dist/components/cms/field-connection.js.map +1 -0
- package/dist/components/cms/field-control.js +167 -34
- package/dist/components/cms/field-control.js.map +1 -1
- package/dist/components/cms/prop-fields.d.ts +43 -0
- package/dist/components/cms/prop-fields.js +154 -0
- package/dist/components/cms/prop-fields.js.map +1 -0
- package/dist/components/cms/rich-text/component-embed.d.ts +17 -3
- package/dist/components/cms/rich-text/component-embed.js +29 -7
- package/dist/components/cms/rich-text/component-embed.js.map +1 -1
- package/dist/components/cms/rich-text/embed-props.d.ts +49 -0
- package/dist/components/cms/rich-text/embed-props.js +106 -0
- package/dist/components/cms/rich-text/embed-props.js.map +1 -0
- package/dist/components/cms/rich-text/index.d.ts +6 -1
- package/dist/components/cms/rich-text/index.js +6 -1
- package/dist/components/cms/rich-text/index.js.map +1 -1
- package/dist/components/cms/rich-text/lazy.d.ts +19 -0
- package/dist/components/cms/rich-text/lazy.js +26 -0
- package/dist/components/cms/rich-text/lazy.js.map +1 -0
- package/dist/components/cms/rich-text/link-control.js +3 -1
- package/dist/components/cms/rich-text/link-control.js.map +1 -1
- package/dist/components/cms/rich-text/toolbar-state.d.ts +45 -0
- package/dist/components/cms/rich-text/toolbar-state.js +66 -0
- package/dist/components/cms/rich-text/toolbar-state.js.map +1 -0
- package/dist/components/cms/rich-text/toolbar.js +7 -15
- package/dist/components/cms/rich-text/toolbar.js.map +1 -1
- package/dist/components/cms/row-actions.d.ts +28 -0
- package/dist/components/cms/row-actions.js +20 -0
- package/dist/components/cms/row-actions.js.map +1 -0
- package/dist/components/cms/use-document-versions.d.ts +8 -1
- package/dist/components/cms/use-document-versions.js +31 -4
- package/dist/components/cms/use-document-versions.js.map +1 -1
- package/dist/components/cms/version-compare-lazy.d.ts +1 -0
- package/dist/components/cms/version-compare-lazy.js +23 -0
- package/dist/components/cms/version-compare-lazy.js.map +1 -0
- package/dist/components/cms/version-compare-text.d.ts +46 -0
- package/dist/components/cms/version-compare-text.js +78 -0
- package/dist/components/cms/version-compare-text.js.map +1 -1
- package/dist/components/cms/version-compare.d.ts +9 -5
- package/dist/components/cms/version-compare.js +217 -64
- package/dist/components/cms/version-compare.js.map +1 -1
- package/dist/components/cms/versions-pane.js +10 -4
- package/dist/components/cms/versions-pane.js.map +1 -1
- package/dist/components/components/component-detail.d.ts +5 -3
- package/dist/components/components/component-detail.js +41 -8
- package/dist/components/components/component-detail.js.map +1 -1
- package/dist/components/components/component-preview.d.ts +97 -0
- package/dist/components/components/component-preview.js +202 -0
- package/dist/components/components/component-preview.js.map +1 -0
- package/dist/components/components/components-index.d.ts +5 -3
- package/dist/components/components/components-index.js +19 -24
- package/dist/components/components/components-index.js.map +1 -1
- package/dist/components/components/registry-browser.d.ts +7 -0
- package/dist/components/components/registry-browser.js +20 -36
- package/dist/components/components/registry-browser.js.map +1 -1
- package/dist/components/components/taxonomy.d.ts +51 -0
- package/dist/components/components/taxonomy.js +73 -0
- package/dist/components/components/taxonomy.js.map +1 -0
- package/dist/components/components/transfer-dialog.d.ts +20 -0
- package/dist/components/components/transfer-dialog.js +64 -0
- package/dist/components/components/transfer-dialog.js.map +1 -0
- package/dist/components/components/transfer.d.ts +43 -0
- package/dist/components/components/transfer.js +31 -0
- package/dist/components/components/transfer.js.map +1 -0
- package/dist/components/project-list.js +3 -4
- package/dist/components/project-list.js.map +1 -1
- package/dist/components/project-switcher.js +3 -2
- package/dist/components/project-switcher.js.map +1 -1
- package/dist/components/rail-store-status.d.ts +21 -0
- package/dist/components/rail-store-status.js +21 -0
- package/dist/components/rail-store-status.js.map +1 -0
- package/dist/components/redirects/redirects-module.js +4 -8
- package/dist/components/redirects/redirects-module.js.map +1 -1
- package/dist/components/redirects/redirects-store.js +2 -7
- package/dist/components/redirects/redirects-store.js.map +1 -1
- package/dist/components/sign-in-needed-badge.d.ts +6 -0
- package/dist/components/sign-in-needed-badge.js +13 -0
- package/dist/components/sign-in-needed-badge.js.map +1 -0
- package/dist/components/studio-project-screen.js +1 -4
- package/dist/components/studio-project-screen.js.map +1 -1
- package/dist/components/studio-shell.js +1 -4
- package/dist/components/studio-shell.js.map +1 -1
- package/dist/components/users/users-module.js +5 -7
- package/dist/components/users/users-module.js.map +1 -1
- package/dist/components/users/users-store.js +2 -7
- package/dist/components/users/users-store.js.map +1 -1
- package/dist/lib/auth/index.js +1 -1
- package/dist/lib/auth/index.js.map +1 -1
- package/dist/lib/clipboard/paste-target.js +1 -3
- package/dist/lib/clipboard/paste-target.js.map +1 -1
- package/dist/lib/cms-views/view-model.d.ts +0 -2
- package/dist/lib/cms-views/view-model.js +0 -7
- package/dist/lib/cms-views/view-model.js.map +1 -1
- package/dist/lib/diff-view-preference.d.ts +7 -0
- package/dist/lib/diff-view-preference.js +21 -0
- package/dist/lib/diff-view-preference.js.map +1 -0
- package/dist/lib/i18n/messages.en.js +94 -33
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/local-preference.d.ts +11 -0
- package/dist/lib/local-preference.js +26 -0
- package/dist/lib/local-preference.js.map +1 -0
- package/dist/lib/locale/fallback.d.ts +45 -0
- package/dist/lib/locale/fallback.js +85 -0
- package/dist/lib/locale/fallback.js.map +1 -1
- package/dist/lib/persona/labels.d.ts +6 -0
- package/dist/lib/persona/labels.js +8 -0
- package/dist/lib/persona/labels.js.map +1 -1
- package/dist/lib/query/index.d.ts +1 -1
- package/dist/lib/query/index.js +1 -1
- package/dist/lib/query/index.js.map +1 -1
- package/dist/lib/query/operations-query.d.ts +14 -2
- package/dist/lib/query/operations-query.js +11 -6
- package/dist/lib/query/operations-query.js.map +1 -1
- package/dist/lib/rail.d.ts +0 -6
- package/dist/lib/rail.js +6 -25
- package/dist/lib/rail.js.map +1 -1
- package/dist/lib/theme.d.ts +0 -6
- package/dist/lib/theme.js +10 -13
- package/dist/lib/theme.js.map +1 -1
- package/dist/router/match.d.ts +1 -0
- package/dist/router/match.js +4 -0
- package/dist/router/match.js.map +1 -1
- package/dist/ui/button.d.ts +1 -1
- package/package.json +22 -25
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { createCollectionRegistry, validateDocument } from '@elytracms/core/cms-core';
|
|
3
|
+
import { studioPath } from '@elytracms/studio/router';
|
|
4
|
+
import { defaultViewState } from '@elytracms/studio/lib/cms-views';
|
|
5
|
+
import { useAssets } from './assets-store';
|
|
6
|
+
import { SYSTEM_ASSET_FIELDS } from './asset-metadata';
|
|
7
|
+
/** The assets rail is not localized in v1 (EC-301: asset metadata is non-localized). */
|
|
8
|
+
const ASSETS_LOCALE = 'en';
|
|
9
|
+
const ASSETS_LOCALE_CONFIG = {
|
|
10
|
+
default: ASSETS_LOCALE,
|
|
11
|
+
locales: [ASSETS_LOCALE],
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The capability profile of the assets rail (EC-319). Hoisted to a module-level
|
|
15
|
+
* constant (no prop/state dependency) so it's both the value the hook returns
|
|
16
|
+
* AND independently unit-testable.
|
|
17
|
+
*
|
|
18
|
+
* `create` is off — a new asset comes from an upload, never a blank draft.
|
|
19
|
+
* `remove` is off DELIBERATELY, even though the store can safely delete one
|
|
20
|
+
* (EC-202): the universal table's generic row/bulk delete runs through
|
|
21
|
+
* `ReferenceConfirmDialog`, which enumerates inbound references as
|
|
22
|
+
* `{ type: 'document' }` targets — the wrong index shape for an asset (indexed
|
|
23
|
+
* as `{ type: 'asset' }`, see `loadInboundAssetReferenceViews`). Wiring
|
|
24
|
+
* `remove: true` here would silently show "not referenced" for an asset that
|
|
25
|
+
* IS referenced. Deletion instead stays on the asset detail surface
|
|
26
|
+
* (`asset-detail.tsx`), which keeps calling the asset-specific reference check.
|
|
27
|
+
* Nothing else applies to assets: no publish/versions/locales/inline-edit/bulk/
|
|
28
|
+
* live-URL/hierarchy/import-export.
|
|
29
|
+
*/
|
|
30
|
+
export const ASSET_COLLECTION_CAPABILITIES = {
|
|
31
|
+
publish: false,
|
|
32
|
+
versions: false,
|
|
33
|
+
locales: false,
|
|
34
|
+
inlineEdit: false,
|
|
35
|
+
create: false,
|
|
36
|
+
remove: false,
|
|
37
|
+
bulk: false,
|
|
38
|
+
liveUrl: false,
|
|
39
|
+
hierarchy: false,
|
|
40
|
+
importExport: false,
|
|
41
|
+
adminOnly: false,
|
|
42
|
+
};
|
|
43
|
+
/** Read one of the record's fixed, upload-managed columns by field name. */
|
|
44
|
+
function systemFieldValue(record, name) {
|
|
45
|
+
switch (name) {
|
|
46
|
+
case 'filename':
|
|
47
|
+
return record.filename;
|
|
48
|
+
case 'url':
|
|
49
|
+
return record.url;
|
|
50
|
+
case 'contentType':
|
|
51
|
+
return record.contentType;
|
|
52
|
+
case 'byteSize':
|
|
53
|
+
return record.byteSize;
|
|
54
|
+
case 'width':
|
|
55
|
+
return record.width;
|
|
56
|
+
case 'height':
|
|
57
|
+
return record.height;
|
|
58
|
+
case 'storageKey':
|
|
59
|
+
return record.storageKey;
|
|
60
|
+
case 'title':
|
|
61
|
+
return record.title;
|
|
62
|
+
default:
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Project a stored asset record into the lens's `values` shape (EC-319), reading
|
|
68
|
+
* only the schema's DECLARED fields — the same "schema is a lens" projection the
|
|
69
|
+
* redirects/users rails use. A system column (`filename`, `url`, dimensions, …)
|
|
70
|
+
* reads straight off the record; everything else — the built-in `alt`, a
|
|
71
|
+
* project's own `copyright`/`credit`, or an EC-311 additive field — round-trips
|
|
72
|
+
* through the record's open `meta` bag (EC-301). `alt` is schema-driven but ALSO
|
|
73
|
+
* has a legacy record column: the meta value wins, falling back to the column
|
|
74
|
+
* (matches delivery's `meta.alt ?? record.alt` read and the image field's
|
|
75
|
+
* options dialog).
|
|
76
|
+
*/
|
|
77
|
+
export function assetToDocument(collection, record) {
|
|
78
|
+
const values = {};
|
|
79
|
+
for (const field of collection.fields) {
|
|
80
|
+
if (field.name === 'alt') {
|
|
81
|
+
const metaAlt = typeof record.meta?.alt === 'string' ? record.meta.alt : undefined;
|
|
82
|
+
values.alt = metaAlt ?? record.alt;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
values[field.name] = SYSTEM_ASSET_FIELDS.has(field.name)
|
|
86
|
+
? systemFieldValue(record, field.name)
|
|
87
|
+
: record.meta?.[field.name];
|
|
88
|
+
}
|
|
89
|
+
return { collection: collection.id, id: record.id, values };
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The inverse of {@link assetToDocument}: the schema-driven meta bag a save
|
|
93
|
+
* writes back — every declared field OUTSIDE the system set (EC-301/EC-311),
|
|
94
|
+
* keyed exactly as the record stores it. System columns are upload-managed and
|
|
95
|
+
* never written here.
|
|
96
|
+
*/
|
|
97
|
+
export function documentToAssetMetaPatch(collection, doc) {
|
|
98
|
+
const values = doc.values ?? {};
|
|
99
|
+
const meta = {};
|
|
100
|
+
for (const field of collection.fields) {
|
|
101
|
+
if (SYSTEM_ASSET_FIELDS.has(field.name))
|
|
102
|
+
continue;
|
|
103
|
+
if (field.name in values)
|
|
104
|
+
meta[field.name] = values[field.name];
|
|
105
|
+
}
|
|
106
|
+
return meta;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Assemble a {@link CollectionViewSource} for the **assets rail** (EC-319) — the
|
|
110
|
+
* portable list surface over the existing asset library store instead of a
|
|
111
|
+
* bespoke listing. `schema` is the DEPLOYMENT-resolved `kind:'asset'` collection
|
|
112
|
+
* (EC-311: a project's own declared fields, or a mount's `nav.assets({ fields })`
|
|
113
|
+
* override merged over it — see `resolveAssetsSchema` in `app-views/default-modules.tsx`),
|
|
114
|
+
* never a hardcoded engine default — so a project's `copyright`/`credit`/… fields
|
|
115
|
+
* (and any EC-311 override) drive the list's columns/filters exactly as they
|
|
116
|
+
* drive the image field's options dialog.
|
|
117
|
+
*
|
|
118
|
+
* Must be mounted under an `<AssetsProvider>` (for {@link useAssets}) — already
|
|
119
|
+
* ambient at the project level (EC-195), so callers rarely mount their own.
|
|
120
|
+
*/
|
|
121
|
+
export function useAssetsCollectionViewSource(projectId, schema) {
|
|
122
|
+
const store = useAssets();
|
|
123
|
+
const [viewState, setViewStateRaw] = useState(() => defaultViewState(schema));
|
|
124
|
+
const [lastError, setLastError] = useState(null);
|
|
125
|
+
const registry = useMemo(() => createCollectionRegistry([schema]), [schema]);
|
|
126
|
+
const documents = useCallback(() => store.assets.map((record) => assetToDocument(schema, record)), [store.assets, schema]);
|
|
127
|
+
const get = useCallback((ref) => {
|
|
128
|
+
const record = store.assets.find((a) => a.id === ref.id);
|
|
129
|
+
return record ? assetToDocument(schema, record) : undefined;
|
|
130
|
+
}, [store.assets, schema]);
|
|
131
|
+
const titleOf = useCallback((ref) => {
|
|
132
|
+
const record = store.assets.find((a) => a.id === ref.id);
|
|
133
|
+
return record?.title ?? record?.filename ?? ref.id;
|
|
134
|
+
}, [store.assets]);
|
|
135
|
+
const setViewState = useCallback((update) => {
|
|
136
|
+
setViewStateRaw((prev) => (typeof update === 'function' ? update(prev) : update));
|
|
137
|
+
}, []);
|
|
138
|
+
const save = useCallback((doc) => {
|
|
139
|
+
const meta = documentToAssetMetaPatch(schema, doc);
|
|
140
|
+
void store.updateMetadata(doc.id, { meta }).then((result) => {
|
|
141
|
+
if (!result.ok)
|
|
142
|
+
setLastError({ code: 'unknown', message: result.message });
|
|
143
|
+
});
|
|
144
|
+
}, [schema, store]);
|
|
145
|
+
// Unreached from the UI (`capabilities.remove === false`); implemented soundly
|
|
146
|
+
// (the same checked delete the store always runs) in case anything ever calls
|
|
147
|
+
// it directly, rather than throwing.
|
|
148
|
+
const remove = useCallback((ref) => {
|
|
149
|
+
void store.remove(ref.id).then((result) => {
|
|
150
|
+
if (result.outcome === 'error')
|
|
151
|
+
setLastError({ code: 'unknown', message: result.message });
|
|
152
|
+
});
|
|
153
|
+
}, [store]);
|
|
154
|
+
return useMemo(() => {
|
|
155
|
+
const source = {
|
|
156
|
+
collectionId: schema.id,
|
|
157
|
+
schema,
|
|
158
|
+
capabilities: ASSET_COLLECTION_CAPABILITIES,
|
|
159
|
+
projectId,
|
|
160
|
+
localeConfig: ASSETS_LOCALE_CONFIG,
|
|
161
|
+
activeLocale: ASSETS_LOCALE,
|
|
162
|
+
documents,
|
|
163
|
+
get,
|
|
164
|
+
titleOf,
|
|
165
|
+
// Assets carry no relation/asset fields of their own (v1) — nothing cross-collection to resolve.
|
|
166
|
+
referenceCandidates: () => [],
|
|
167
|
+
collections: [schema],
|
|
168
|
+
detailPath: (id) => studioPath.asset(id),
|
|
169
|
+
listPath: studioPath.assets(),
|
|
170
|
+
isFieldReadOnly: (field) => field.form?.readOnly ?? false,
|
|
171
|
+
validate: (doc) => validateDocument(registry, doc, { localeConfig: ASSETS_LOCALE_CONFIG }),
|
|
172
|
+
lastError,
|
|
173
|
+
clearLastError: () => setLastError(null),
|
|
174
|
+
viewState: () => viewState,
|
|
175
|
+
setViewState,
|
|
176
|
+
// create is gated off (capabilities.create === false); never reached.
|
|
177
|
+
create: () => {
|
|
178
|
+
throw new Error('assets are created by upload, not the assets rail');
|
|
179
|
+
},
|
|
180
|
+
save,
|
|
181
|
+
remove,
|
|
182
|
+
};
|
|
183
|
+
return source;
|
|
184
|
+
}, [projectId, schema, registry, documents, get, titleOf, setViewState, save, remove, viewState, lastError]);
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=assets-collection-view-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets-collection-view-source.js","sourceRoot":"","sources":["../../../src/components/assets/assets-collection-view-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAStD,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAGrF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAMlE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAEtD,wFAAwF;AACxF,MAAM,aAAa,GAAW,IAAI,CAAA;AAClC,MAAM,oBAAoB,GAAiB;IACzC,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE,CAAC,aAAa,CAAC;CACzB,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAA+B;IACvE,OAAO,EAAE,KAAK;IACd,QAAQ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iGAAiG;YACjG,mBAAmB,EAAE,GAAG,EAAE,CAAC,EAAE;YAC7B,WAAW,EAAE,CAAC,MAAM,CAAC;YACrB,UAAU,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE;YAC7B,eAAe,EAAE,CAAC,KAAe,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,IAAI,KAAK;YACnE,QAAQ,EAAE,CAAC,GAAgB,EAAE,EAAE,CAC7B,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,oBAAoB,EAAE,CAAC;YACzE,SAAS;YACT,cAAc,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC;YACxC,SAAS,EAAE,GAAG,EAAE,CAAC,SAAS;YAC1B,YAAY;YACZ,sEAAsE;YACtE,MAAM,EAAE,GAAG,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;YACtE,CAAC;YACD,IAAI;YACJ,MAAM;SACP,CAAA;QACD,OAAO,MAAM,CAAA;IACf,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;AAC9G,CAAC","sourcesContent":["import { useCallback, useMemo, useState } from 'react'\nimport type {\n CmsDocument,\n CollectionDef,\n DocumentRef,\n FieldDef,\n Locale,\n LocaleConfig,\n} from '@elytracms/core/cms-core'\nimport { createCollectionRegistry, validateDocument } from '@elytracms/core/cms-core'\nimport type { AssetRecord } from '@elytracms/core/persistence'\nimport type { OperationError } from '@elytracms/core/operations'\nimport { studioPath } from '@elytracms/studio/router'\nimport { defaultViewState } from '@elytracms/studio/lib/cms-views'\nimport type { TableViewState } from '@elytracms/studio/lib/cms-views'\nimport type {\n CollectionViewCapabilities,\n CollectionViewSource,\n} from '@elytracms/studio/lib/collection-view/collection-view-source'\nimport { useAssets } from './assets-store'\nimport { SYSTEM_ASSET_FIELDS } from './asset-metadata'\n\n/** The assets rail is not localized in v1 (EC-301: asset metadata is non-localized). */\nconst ASSETS_LOCALE: Locale = 'en'\nconst ASSETS_LOCALE_CONFIG: LocaleConfig = {\n default: ASSETS_LOCALE,\n locales: [ASSETS_LOCALE],\n}\n\n/**\n * The capability profile of the assets rail (EC-319). Hoisted to a module-level\n * constant (no prop/state dependency) so it's both the value the hook returns\n * AND independently unit-testable.\n *\n * `create` is off — a new asset comes from an upload, never a blank draft.\n * `remove` is off DELIBERATELY, even though the store can safely delete one\n * (EC-202): the universal table's generic row/bulk delete runs through\n * `ReferenceConfirmDialog`, which enumerates inbound references as\n * `{ type: 'document' }` targets — the wrong index shape for an asset (indexed\n * as `{ type: 'asset' }`, see `loadInboundAssetReferenceViews`). Wiring\n * `remove: true` here would silently show \"not referenced\" for an asset that\n * IS referenced. Deletion instead stays on the asset detail surface\n * (`asset-detail.tsx`), which keeps calling the asset-specific reference check.\n * Nothing else applies to assets: no publish/versions/locales/inline-edit/bulk/\n * live-URL/hierarchy/import-export.\n */\nexport const ASSET_COLLECTION_CAPABILITIES: CollectionViewCapabilities = {\n publish: false,\n versions: false,\n locales: false,\n inlineEdit: false,\n create: false,\n remove: false,\n bulk: false,\n liveUrl: false,\n hierarchy: false,\n importExport: false,\n adminOnly: false,\n}\n\n/** Read one of the record's fixed, upload-managed columns by field name. */\nfunction systemFieldValue(record: AssetRecord, name: string): unknown {\n switch (name) {\n case 'filename':\n return record.filename\n case 'url':\n return record.url\n case 'contentType':\n return record.contentType\n case 'byteSize':\n return record.byteSize\n case 'width':\n return record.width\n case 'height':\n return record.height\n case 'storageKey':\n return record.storageKey\n case 'title':\n return record.title\n default:\n return undefined\n }\n}\n\n/**\n * Project a stored asset record into the lens's `values` shape (EC-319), reading\n * only the schema's DECLARED fields — the same \"schema is a lens\" projection the\n * redirects/users rails use. A system column (`filename`, `url`, dimensions, …)\n * reads straight off the record; everything else — the built-in `alt`, a\n * project's own `copyright`/`credit`, or an EC-311 additive field — round-trips\n * through the record's open `meta` bag (EC-301). `alt` is schema-driven but ALSO\n * has a legacy record column: the meta value wins, falling back to the column\n * (matches delivery's `meta.alt ?? record.alt` read and the image field's\n * options dialog).\n */\nexport function assetToDocument(collection: CollectionDef, record: AssetRecord): CmsDocument {\n const values: Record<string, unknown> = {}\n for (const field of collection.fields) {\n if (field.name === 'alt') {\n const metaAlt = typeof record.meta?.alt === 'string' ? record.meta.alt : undefined\n values.alt = metaAlt ?? record.alt\n continue\n }\n values[field.name] = SYSTEM_ASSET_FIELDS.has(field.name)\n ? systemFieldValue(record, field.name)\n : record.meta?.[field.name]\n }\n return { collection: collection.id, id: record.id, values }\n}\n\n/**\n * The inverse of {@link assetToDocument}: the schema-driven meta bag a save\n * writes back — every declared field OUTSIDE the system set (EC-301/EC-311),\n * keyed exactly as the record stores it. System columns are upload-managed and\n * never written here.\n */\nexport function documentToAssetMetaPatch(\n collection: CollectionDef,\n doc: CmsDocument,\n): Record<string, unknown> {\n const values = doc.values ?? {}\n const meta: Record<string, unknown> = {}\n for (const field of collection.fields) {\n if (SYSTEM_ASSET_FIELDS.has(field.name)) continue\n if (field.name in values) meta[field.name] = values[field.name]\n }\n return meta\n}\n\n/**\n * Assemble a {@link CollectionViewSource} for the **assets rail** (EC-319) — the\n * portable list surface over the existing asset library store instead of a\n * bespoke listing. `schema` is the DEPLOYMENT-resolved `kind:'asset'` collection\n * (EC-311: a project's own declared fields, or a mount's `nav.assets({ fields })`\n * override merged over it — see `resolveAssetsSchema` in `app-views/default-modules.tsx`),\n * never a hardcoded engine default — so a project's `copyright`/`credit`/… fields\n * (and any EC-311 override) drive the list's columns/filters exactly as they\n * drive the image field's options dialog.\n *\n * Must be mounted under an `<AssetsProvider>` (for {@link useAssets}) — already\n * ambient at the project level (EC-195), so callers rarely mount their own.\n */\nexport function useAssetsCollectionViewSource(\n projectId: string,\n schema: CollectionDef,\n): CollectionViewSource {\n const store = useAssets()\n const [viewState, setViewStateRaw] = useState<TableViewState>(() => defaultViewState(schema))\n const [lastError, setLastError] = useState<OperationError | null>(null)\n const registry = useMemo(() => createCollectionRegistry([schema]), [schema])\n\n const documents = useCallback(\n () => store.assets.map((record) => assetToDocument(schema, record)),\n [store.assets, schema],\n )\n const get = useCallback(\n (ref: DocumentRef): CmsDocument | undefined => {\n const record = store.assets.find((a) => a.id === ref.id)\n return record ? assetToDocument(schema, record) : undefined\n },\n [store.assets, schema],\n )\n const titleOf = useCallback(\n (ref: DocumentRef): string => {\n const record = store.assets.find((a) => a.id === ref.id)\n return record?.title ?? record?.filename ?? ref.id\n },\n [store.assets],\n )\n const setViewState = useCallback<CollectionViewSource['setViewState']>((update) => {\n setViewStateRaw((prev) => (typeof update === 'function' ? update(prev) : update))\n }, [])\n\n const save = useCallback(\n (doc: CmsDocument) => {\n const meta = documentToAssetMetaPatch(schema, doc)\n void store.updateMetadata(doc.id, { meta }).then((result) => {\n if (!result.ok) setLastError({ code: 'unknown', message: result.message })\n })\n },\n [schema, store],\n )\n // Unreached from the UI (`capabilities.remove === false`); implemented soundly\n // (the same checked delete the store always runs) in case anything ever calls\n // it directly, rather than throwing.\n const remove = useCallback(\n (ref: DocumentRef) => {\n void store.remove(ref.id).then((result) => {\n if (result.outcome === 'error') setLastError({ code: 'unknown', message: result.message })\n })\n },\n [store],\n )\n\n return useMemo(() => {\n const source: CollectionViewSource = {\n collectionId: schema.id,\n schema,\n capabilities: ASSET_COLLECTION_CAPABILITIES,\n projectId,\n localeConfig: ASSETS_LOCALE_CONFIG,\n activeLocale: ASSETS_LOCALE,\n documents,\n get,\n titleOf,\n // Assets carry no relation/asset fields of their own (v1) — nothing cross-collection to resolve.\n referenceCandidates: () => [],\n collections: [schema],\n detailPath: (id: string) => studioPath.asset(id),\n listPath: studioPath.assets(),\n isFieldReadOnly: (field: FieldDef) => field.form?.readOnly ?? false,\n validate: (doc: CmsDocument) =>\n validateDocument(registry, doc, { localeConfig: ASSETS_LOCALE_CONFIG }),\n lastError,\n clearLastError: () => setLastError(null),\n viewState: () => viewState,\n setViewState,\n // create is gated off (capabilities.create === false); never reached.\n create: () => {\n throw new Error('assets are created by upload, not the assets rail')\n },\n save,\n remove,\n }\n return source\n }, [projectId, schema, registry, documents, get, titleOf, setViewState, save, remove, viewState, lastError])\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CollectionDef } from '@elytracms/core/cms-core';
|
|
2
|
+
/**
|
|
3
|
+
* The studio Assets module (EC-319). The reuse proof (alongside users/redirects)
|
|
4
|
+
* that the portable list surface serves a rail with an entirely different
|
|
5
|
+
* backend (the asset library store, not `cmsDocuments`): `assetId === null` is
|
|
6
|
+
* the universal list — list mode is `LoadedCollectionTable`, grid mode is
|
|
7
|
+
* `AssetGridView`, a **transient personal** toggle (EC-317-style, localStorage) —
|
|
8
|
+
* over the SAME {@link useAssetsCollectionViewSource}; `assetId` set opens the
|
|
9
|
+
* bespoke asset detail surface (`asset-detail.tsx`).
|
|
10
|
+
*
|
|
11
|
+
* Must be mounted where an `<AssetsProvider>` is ambient — already true at the
|
|
12
|
+
* project level (EC-195), so this never mounts its own.
|
|
13
|
+
*/
|
|
14
|
+
export declare function AssetsModule({ projectId, assetId, schema, }: {
|
|
15
|
+
projectId: string;
|
|
16
|
+
assetId?: string | null;
|
|
17
|
+
schema: CollectionDef;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { LayoutGrid, List, RotateCcw, Upload, X } from 'lucide-react';
|
|
4
|
+
import { Badge, Button, Panel, PanelBody, PanelHeader, Row, Stack, Text } from '@elytracms/studio/ui';
|
|
5
|
+
import { translate } from '@elytracms/studio/lib/i18n';
|
|
6
|
+
import { cn } from '@elytracms/studio/lib/utils';
|
|
7
|
+
import { useAssets } from './assets-store';
|
|
8
|
+
import { useAssetsCollectionViewSource } from './assets-collection-view-source';
|
|
9
|
+
import { CollectionViewProvider } from '../collection-view/collection-view-context';
|
|
10
|
+
import { RailStoreStatus } from '../rail-store-status';
|
|
11
|
+
import { LoadedCollectionTable } from '../cms/collection-table';
|
|
12
|
+
import { AssetGridView } from './asset-grid';
|
|
13
|
+
import { AssetDetail } from './asset-detail';
|
|
14
|
+
import { readAssetsViewMode, storeAssetsViewMode, } from './assets-view-preference';
|
|
15
|
+
/**
|
|
16
|
+
* The studio Assets module (EC-319). The reuse proof (alongside users/redirects)
|
|
17
|
+
* that the portable list surface serves a rail with an entirely different
|
|
18
|
+
* backend (the asset library store, not `cmsDocuments`): `assetId === null` is
|
|
19
|
+
* the universal list — list mode is `LoadedCollectionTable`, grid mode is
|
|
20
|
+
* `AssetGridView`, a **transient personal** toggle (EC-317-style, localStorage) —
|
|
21
|
+
* over the SAME {@link useAssetsCollectionViewSource}; `assetId` set opens the
|
|
22
|
+
* bespoke asset detail surface (`asset-detail.tsx`).
|
|
23
|
+
*
|
|
24
|
+
* Must be mounted where an `<AssetsProvider>` is ambient — already true at the
|
|
25
|
+
* project level (EC-195), so this never mounts its own.
|
|
26
|
+
*/
|
|
27
|
+
export function AssetsModule({ projectId, assetId = null, schema, }) {
|
|
28
|
+
const store = useAssets();
|
|
29
|
+
const source = useAssetsCollectionViewSource(projectId, schema);
|
|
30
|
+
if (store.status !== 'ready') {
|
|
31
|
+
return (_jsx(RailStoreStatus, { store: store, errorLabel: translate('assets.error.loadFailed'), loadingLabel: translate('assets.loading'), errorTestId: "assets-error" }));
|
|
32
|
+
}
|
|
33
|
+
return (_jsx(CollectionViewProvider, { source: source, children: assetId !== null ? (_jsx(AssetDetail, { projectId: projectId, assetId: assetId }, assetId)) : (_jsx(AssetsListSurface, { projectId: projectId })) }));
|
|
34
|
+
}
|
|
35
|
+
/** The list surface: upload + the grid/list toggle in a shared toolbar, over
|
|
36
|
+
* either the universal table or the thumbnail grid — same source, same rows. */
|
|
37
|
+
function AssetsListSurface({ projectId }) {
|
|
38
|
+
const store = useAssets();
|
|
39
|
+
const [mode, setMode] = useState(() => readAssetsViewMode());
|
|
40
|
+
const [dragging, setDragging] = useState(false);
|
|
41
|
+
const fileInputRef = useRef(null);
|
|
42
|
+
function setModeAndPersist(next) {
|
|
43
|
+
setMode(next);
|
|
44
|
+
storeAssetsViewMode(next);
|
|
45
|
+
}
|
|
46
|
+
function onPick(event) {
|
|
47
|
+
if (event.target.files)
|
|
48
|
+
store.upload([...event.target.files]);
|
|
49
|
+
event.target.value = '';
|
|
50
|
+
}
|
|
51
|
+
function onDrop(event) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
setDragging(false);
|
|
54
|
+
if (event.dataTransfer.files.length > 0)
|
|
55
|
+
store.upload([...event.dataTransfer.files]);
|
|
56
|
+
}
|
|
57
|
+
const toolbarExtra = (_jsxs(Row, { gap: "2", align: "center", children: [_jsx("input", { ref: fileInputRef, type: "file", multiple: true, className: "hidden", onChange: onPick, "data-testid": "asset-file-input" }), _jsxs(Button, { size: "sm", variant: "outline", onClick: () => fileInputRef.current?.click(), "data-testid": "asset-upload", children: [_jsx(Upload, {}), " ", translate('common.upload')] }), _jsx(AssetsViewToggle, { mode: mode, onChange: setModeAndPersist })] }));
|
|
58
|
+
return (_jsxs("div", { className: "relative flex h-full min-h-0 flex-col", onDragOver: (event) => {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
setDragging(true);
|
|
61
|
+
}, onDragLeave: () => setDragging(false), onDrop: onDrop, children: [store.uploads.length > 0 ? _jsx(UploadQueue, {}) : null, mode === 'grid' ? (_jsx(AssetGridView, { projectId: projectId, toolbarExtra: toolbarExtra })) : (_jsx(LoadedCollectionTable, { projectId: projectId, toolbarExtra: toolbarExtra })), dragging ? (_jsx("div", { className: "pointer-events-none absolute inset-0 z-10 grid place-items-center rounded-xl border-2 border-dashed border-primary bg-background/85", "data-testid": "asset-drop-overlay", children: _jsxs(Row, { gap: "2", align: "center", children: [_jsx(Upload, { className: "size-5 text-primary" }), _jsx(Text, { className: "font-medium", children: translate('cms.asset.dropToUpload') })] }) })) : null] }));
|
|
62
|
+
}
|
|
63
|
+
/** The grid/list toggle (EC-319, EC-317-style transient view pref). */
|
|
64
|
+
function AssetsViewToggle({ mode, onChange, }) {
|
|
65
|
+
return (_jsxs(Row, { gap: "px", className: "rounded-md bg-muted/50 p-0.5", role: "group", "aria-label": translate('assets.viewToggle.groupLabel'), children: [_jsx(ToggleButton, { active: mode === 'list', label: translate('assets.viewToggle.list'), icon: _jsx(List, { className: "size-3.5" }), onClick: () => onChange('list'), testId: "assets-view-list" }), _jsx(ToggleButton, { active: mode === 'grid', label: translate('assets.viewToggle.grid'), icon: _jsx(LayoutGrid, { className: "size-3.5" }), onClick: () => onChange('grid'), testId: "assets-view-grid" })] }));
|
|
66
|
+
}
|
|
67
|
+
function ToggleButton({ active, label, icon, onClick, testId, }) {
|
|
68
|
+
return (_jsx("button", { type: "button", "aria-pressed": active, "aria-label": label, title: label, onClick: onClick, "data-testid": testId, className: cn('inline-flex items-center rounded-[5px] px-2 py-1 transition-colors', active ? 'bg-background text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground'), children: icon }));
|
|
69
|
+
}
|
|
70
|
+
/** Upload phase → the `assets.upload.phase.*` catalog key suffix (idle → queued). */
|
|
71
|
+
const PHASE_KEY = {
|
|
72
|
+
idle: 'queued',
|
|
73
|
+
preparing: 'preparing',
|
|
74
|
+
uploading: 'uploading',
|
|
75
|
+
confirming: 'confirming',
|
|
76
|
+
done: 'done',
|
|
77
|
+
failed: 'failed',
|
|
78
|
+
};
|
|
79
|
+
/** The in-flight upload panel: progress while transferring, explicit failure + retry. */
|
|
80
|
+
function UploadQueue() {
|
|
81
|
+
const store = useAssets();
|
|
82
|
+
return (_jsxs(Panel, { className: "m-4 mb-0 sm:mx-6", "data-testid": "upload-queue", children: [_jsx(PanelHeader, { children: _jsx(Text, { size: "xs", weight: "semibold", tone: "muted", children: translate('assets.uploads.heading') }) }), _jsx(PanelBody, { className: "divide-y divide-border p-0", children: store.uploads.map((entry) => (_jsx(UploadRow, { entry: entry, onRetry: () => store.retryUpload(entry.id), onDismiss: () => store.dismissUpload(entry.id) }, entry.id))) })] }));
|
|
83
|
+
}
|
|
84
|
+
function UploadRow({ entry, onRetry, onDismiss, }) {
|
|
85
|
+
const { state } = entry;
|
|
86
|
+
const failed = state.phase === 'failed';
|
|
87
|
+
return (_jsxs(Stack, { gap: "1", className: "px-3 py-2", "data-testid": "upload-row", children: [_jsxs(Row, { gap: "2", children: [_jsx(Text, { size: "sm", weight: "medium", className: "min-w-0 flex-1 truncate", children: entry.filename }), _jsxs(Badge, { variant: failed ? 'error' : state.phase === 'done' ? 'success' : 'info', children: [translate('assets.upload.phase.' + PHASE_KEY[state.phase]), state.attempt > 1
|
|
88
|
+
? ' · ' + translate('assets.upload.attempt', { count: state.attempt })
|
|
89
|
+
: ''] }), failed ? (_jsxs(_Fragment, { children: [state.failure?.retryable !== false ? (_jsxs(Button, { variant: "outline", size: "sm", onClick: onRetry, "data-testid": "upload-retry", children: [_jsx(RotateCcw, {}), " Retry"] })) : null, _jsx(Button, { variant: "ghost", size: "icon-sm", onClick: onDismiss, "aria-label": translate('assets.upload.dismissLabel'), children: _jsx(X, {}) })] })) : null] }), failed ? (_jsxs(Text, { size: "xs", tone: "muted", "data-testid": "upload-error", children: [state.failure?.stage, ": ", state.failure?.message] })) : (_jsx(ProgressBar, { value: state.progress }))] }));
|
|
90
|
+
}
|
|
91
|
+
function ProgressBar({ value }) {
|
|
92
|
+
return (_jsx("span", { className: "block h-1.5 w-full overflow-hidden rounded-full bg-muted", children: _jsx("span", { className: "block h-full rounded-full bg-primary transition-[width]", style: { width: `${Math.round(value * 100)}%` } }) }));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=assets-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets-module.js","sourceRoot":"","sources":["../../../src/components/assets/assets-module.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAExC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAErE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AACrG,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,EAAE,EAAE,EAAE,MAAM,6BAA6B,CAAA;AAEhD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAEL,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,0BAA0B,CAAA;AAEjC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,OAAO,GAAG,IAAI,EACd,MAAM,GAKP;IACC,MAAM,KAAK,GAAG,SAAS,EAAE,CAAA;IACzB,MAAM,MAAM,GAAG,6BAA6B,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAE/D,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,EAA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GACE,IACR,CACJ,CAAC,CAAC,CAAC,IAAI,IACJ,EACL,MAAM,CAAC,CAAC,CAAC,CACR,MAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,OAAO,iBAAa,cAAc,aACpD,KAAK,CAAC,OAAO,EAAE,KAAK,QAAI,KAAK,CAAC,OAAO,EAAE,OAAO,IAC1C,CACR,CAAC,CAAC,CAAC,CACF,KAAC,WAAW,IAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,GAAI,CACvC,IACK,CACT,CAAA;AACH,CAAC;AAED,SAAS,WAAW,CAAC,EAAE,KAAK,EAAqB;IAC/C,OAAO,CACL,eAAM,SAAS,EAAC,0DAA0D,YACxE,eACE,SAAS,EAAC,yDAAyD,EACnE,KAAK,EAAE,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,EAAE,GAC/C,GACG,CACR,CAAA;AACH,CAAC","sourcesContent":["import { useRef, useState } from 'react'\nimport type { ChangeEvent, DragEvent, ReactNode } from 'react'\nimport { LayoutGrid, List, RotateCcw, Upload, X } from 'lucide-react'\nimport type { CollectionDef } from '@elytracms/core/cms-core'\nimport { Badge, Button, Panel, PanelBody, PanelHeader, Row, Stack, Text } from '@elytracms/studio/ui'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport { cn } from '@elytracms/studio/lib/utils'\nimport type { UploadState } from '@elytracms/studio/lib/assets'\nimport { useAssets } from './assets-store'\nimport type { UploadEntry } from './assets-store'\nimport { useAssetsCollectionViewSource } from './assets-collection-view-source'\nimport { CollectionViewProvider } from '../collection-view/collection-view-context'\nimport { RailStoreStatus } from '../rail-store-status'\nimport { LoadedCollectionTable } from '../cms/collection-table'\nimport { AssetGridView } from './asset-grid'\nimport { AssetDetail } from './asset-detail'\nimport {\n type AssetsViewMode,\n readAssetsViewMode,\n storeAssetsViewMode,\n} from './assets-view-preference'\n\n/**\n * The studio Assets module (EC-319). The reuse proof (alongside users/redirects)\n * that the portable list surface serves a rail with an entirely different\n * backend (the asset library store, not `cmsDocuments`): `assetId === null` is\n * the universal list — list mode is `LoadedCollectionTable`, grid mode is\n * `AssetGridView`, a **transient personal** toggle (EC-317-style, localStorage) —\n * over the SAME {@link useAssetsCollectionViewSource}; `assetId` set opens the\n * bespoke asset detail surface (`asset-detail.tsx`).\n *\n * Must be mounted where an `<AssetsProvider>` is ambient — already true at the\n * project level (EC-195), so this never mounts its own.\n */\nexport function AssetsModule({\n projectId,\n assetId = null,\n schema,\n}: {\n projectId: string\n assetId?: string | null\n schema: CollectionDef\n}) {\n const store = useAssets()\n const source = useAssetsCollectionViewSource(projectId, schema)\n\n if (store.status !== 'ready') {\n return (\n <RailStoreStatus\n store={store}\n errorLabel={translate('assets.error.loadFailed')}\n loadingLabel={translate('assets.loading')}\n errorTestId=\"assets-error\"\n />\n )\n }\n\n return (\n <CollectionViewProvider source={source}>\n {assetId !== null ? (\n <AssetDetail key={assetId} projectId={projectId} assetId={assetId} />\n ) : (\n <AssetsListSurface projectId={projectId} />\n )}\n </CollectionViewProvider>\n )\n}\n\n/** The list surface: upload + the grid/list toggle in a shared toolbar, over\n * either the universal table or the thumbnail grid — same source, same rows. */\nfunction AssetsListSurface({ projectId }: { projectId: string }) {\n const store = useAssets()\n const [mode, setMode] = useState<AssetsViewMode>(() => readAssetsViewMode())\n const [dragging, setDragging] = useState(false)\n const fileInputRef = useRef<HTMLInputElement | null>(null)\n\n function setModeAndPersist(next: AssetsViewMode) {\n setMode(next)\n storeAssetsViewMode(next)\n }\n\n function onPick(event: ChangeEvent<HTMLInputElement>) {\n if (event.target.files) store.upload([...event.target.files])\n event.target.value = ''\n }\n\n function onDrop(event: DragEvent) {\n event.preventDefault()\n setDragging(false)\n if (event.dataTransfer.files.length > 0) store.upload([...event.dataTransfer.files])\n }\n\n const toolbarExtra = (\n <Row gap=\"2\" align=\"center\">\n <input\n ref={fileInputRef}\n type=\"file\"\n multiple\n className=\"hidden\"\n onChange={onPick}\n data-testid=\"asset-file-input\"\n />\n <Button size=\"sm\" variant=\"outline\" onClick={() => fileInputRef.current?.click()} data-testid=\"asset-upload\">\n <Upload /> {translate('common.upload')}\n </Button>\n <AssetsViewToggle mode={mode} onChange={setModeAndPersist} />\n </Row>\n )\n\n return (\n <div\n className=\"relative flex h-full min-h-0 flex-col\"\n onDragOver={(event) => {\n event.preventDefault()\n setDragging(true)\n }}\n onDragLeave={() => setDragging(false)}\n onDrop={onDrop}\n >\n {store.uploads.length > 0 ? <UploadQueue /> : null}\n\n {mode === 'grid' ? (\n <AssetGridView projectId={projectId} toolbarExtra={toolbarExtra} />\n ) : (\n <LoadedCollectionTable projectId={projectId} toolbarExtra={toolbarExtra} />\n )}\n\n {dragging ? (\n <div\n className=\"pointer-events-none absolute inset-0 z-10 grid place-items-center rounded-xl border-2 border-dashed border-primary bg-background/85\"\n data-testid=\"asset-drop-overlay\"\n >\n <Row gap=\"2\" align=\"center\">\n <Upload className=\"size-5 text-primary\" />\n <Text className=\"font-medium\">{translate('cms.asset.dropToUpload')}</Text>\n </Row>\n </div>\n ) : null}\n </div>\n )\n}\n\n/** The grid/list toggle (EC-319, EC-317-style transient view pref). */\nfunction AssetsViewToggle({\n mode,\n onChange,\n}: {\n mode: AssetsViewMode\n onChange: (mode: AssetsViewMode) => void\n}) {\n return (\n <Row\n gap=\"px\"\n className=\"rounded-md bg-muted/50 p-0.5\"\n role=\"group\"\n aria-label={translate('assets.viewToggle.groupLabel')}\n >\n <ToggleButton\n active={mode === 'list'}\n label={translate('assets.viewToggle.list')}\n icon={<List className=\"size-3.5\" />}\n onClick={() => onChange('list')}\n testId=\"assets-view-list\"\n />\n <ToggleButton\n active={mode === 'grid'}\n label={translate('assets.viewToggle.grid')}\n icon={<LayoutGrid className=\"size-3.5\" />}\n onClick={() => onChange('grid')}\n testId=\"assets-view-grid\"\n />\n </Row>\n )\n}\n\nfunction ToggleButton({\n active,\n label,\n icon,\n onClick,\n testId,\n}: {\n active: boolean\n label: string\n icon: ReactNode\n onClick: () => void\n testId: string\n}) {\n return (\n <button\n type=\"button\"\n aria-pressed={active}\n aria-label={label}\n title={label}\n onClick={onClick}\n data-testid={testId}\n className={cn(\n 'inline-flex items-center rounded-[5px] px-2 py-1 transition-colors',\n active ? 'bg-background text-foreground shadow-sm' : 'text-muted-foreground hover:text-foreground',\n )}\n >\n {icon}\n </button>\n )\n}\n\n/** Upload phase → the `assets.upload.phase.*` catalog key suffix (idle → queued). */\nconst PHASE_KEY: Record<UploadState['phase'], string> = {\n idle: 'queued',\n preparing: 'preparing',\n uploading: 'uploading',\n confirming: 'confirming',\n done: 'done',\n failed: 'failed',\n}\n\n/** The in-flight upload panel: progress while transferring, explicit failure + retry. */\nfunction UploadQueue() {\n const store = useAssets()\n return (\n <Panel className=\"m-4 mb-0 sm:mx-6\" data-testid=\"upload-queue\">\n <PanelHeader>\n <Text size=\"xs\" weight=\"semibold\" tone=\"muted\">\n {translate('assets.uploads.heading')}\n </Text>\n </PanelHeader>\n <PanelBody className=\"divide-y divide-border p-0\">\n {store.uploads.map((entry) => (\n <UploadRow\n key={entry.id}\n entry={entry}\n onRetry={() => store.retryUpload(entry.id)}\n onDismiss={() => store.dismissUpload(entry.id)}\n />\n ))}\n </PanelBody>\n </Panel>\n )\n}\n\nfunction UploadRow({\n entry,\n onRetry,\n onDismiss,\n}: {\n entry: UploadEntry\n onRetry: () => void\n onDismiss: () => void\n}) {\n const { state } = entry\n const failed = state.phase === 'failed'\n return (\n <Stack gap=\"1\" className=\"px-3 py-2\" data-testid=\"upload-row\">\n <Row gap=\"2\">\n <Text size=\"sm\" weight=\"medium\" className=\"min-w-0 flex-1 truncate\">\n {entry.filename}\n </Text>\n <Badge variant={failed ? 'error' : state.phase === 'done' ? 'success' : 'info'}>\n {translate('assets.upload.phase.' + PHASE_KEY[state.phase])}\n {state.attempt > 1\n ? ' · ' + translate('assets.upload.attempt', { count: state.attempt })\n : ''}\n </Badge>\n {failed ? (\n <>\n {state.failure?.retryable !== false ? (\n <Button variant=\"outline\" size=\"sm\" onClick={onRetry} data-testid=\"upload-retry\">\n <RotateCcw /> Retry\n </Button>\n ) : null}\n <Button\n variant=\"ghost\"\n size=\"icon-sm\"\n onClick={onDismiss}\n aria-label={translate('assets.upload.dismissLabel')}\n >\n <X />\n </Button>\n </>\n ) : null}\n </Row>\n {failed ? (\n <Text size=\"xs\" tone=\"muted\" data-testid=\"upload-error\">\n {state.failure?.stage}: {state.failure?.message}\n </Text>\n ) : (\n <ProgressBar value={state.progress} />\n )}\n </Stack>\n )\n}\n\nfunction ProgressBar({ value }: { value: number }) {\n return (\n <span className=\"block h-1.5 w-full overflow-hidden rounded-full bg-muted\">\n <span\n className=\"block h-full rounded-full bg-primary transition-[width]\"\n style={{ width: `${Math.round(value * 100)}%` }}\n />\n </span>\n )\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { createContext, useCallback, useContext, useMemo, useRef, useState } fro
|
|
|
3
3
|
import { deleteAsset, runUpload, xhrUploadTransport } from '@elytracms/studio/lib/assets';
|
|
4
4
|
import { loadInboundAssetReferenceViews } from '@elytracms/studio/lib/references';
|
|
5
5
|
import { getStudioOperations, operationsAssetRepository } from '@elytracms/studio/lib/operations';
|
|
6
|
-
import { useOperationCache, useOperationQuery } from '@elytracms/studio/lib/query';
|
|
6
|
+
import { listStoreState, useOperationCache, useOperationQuery } from '@elytracms/studio/lib/query';
|
|
7
7
|
import { updateAssetMetadata } from './asset-metadata';
|
|
8
8
|
const AssetsContext = createContext(null);
|
|
9
9
|
const EMPTY_ASSETS = [];
|
|
@@ -39,12 +39,7 @@ export function AssetsProvider({ projectId, children, }) {
|
|
|
39
39
|
const cache = useOperationCache();
|
|
40
40
|
const refetch = query.refetch;
|
|
41
41
|
const assets = query.data ?? EMPTY_ASSETS;
|
|
42
|
-
const status = query
|
|
43
|
-
? 'loading'
|
|
44
|
-
: query.isError
|
|
45
|
-
? 'error'
|
|
46
|
-
: 'ready';
|
|
47
|
-
const errorMessage = query.isError && query.error instanceof Error ? query.error.message : undefined;
|
|
42
|
+
const { status, errorMessage } = listStoreState(query);
|
|
48
43
|
/** Re-list from the backend (the public escape hatch + post-upload reconcile). */
|
|
49
44
|
const refresh = useCallback(async () => {
|
|
50
45
|
await refetch();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets-store.js","sourceRoot":"","sources":["../../../src/components/assets/assets-store.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGzF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEzF,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AAEjF,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAEjG,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAA;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAuCtD,MAAM,aAAa,GAAG,aAAa,CAAqB,IAAI,CAAC,CAAA;AAE7D,MAAM,YAAY,GAA2B,EAAE,CAAA;AAE/C,qFAAqF;AACrF,SAAS,cAAc,CAAC,SAAiB;IACvC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AAC9B,CAAC;AAED;kEACkE;AAClE,KAAK,UAAU,UAAU,CAAC,UAA4B,EAAE,SAAiB;IACvE,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAAA;IAC1D,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACrD,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,C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SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM;QACN,OAAO;QACP,MAAM;QACN,WAAW;QACX,aAAa;QACb,QAAQ;QACR,MAAM;QACN,cAAc;QACd,OAAO;KACR,CAAC,EACF;QACE,SAAS;QACT,MAAM;QACN,YAAY;QACZ,MAAM;QACN,OAAO;QACP,MAAM;QACN,WAAW;QACX,aAAa;QACb,QAAQ;QACR,MAAM;QACN,cAAc;QACd,OAAO;KACR,CACF,CAAA;IAED,OAAO,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA0B,CAAA;AAClF,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACjF,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport type { AssetRecord, AssetRepository } from '@elytracms/core/persistence'\nimport { deleteAsset, runUpload, xhrUploadTransport } from '@elytracms/studio/lib/assets'\nimport type { DeleteAssetResult, UploadState, UploadableFile } from '@elytracms/studio/lib/assets'\nimport { loadInboundAssetReferenceViews } from '@elytracms/studio/lib/references'\nimport type { ReferenceEntryView } from '@elytracms/studio/lib/references'\nimport { getStudioOperations, operationsAssetRepository } from '@elytracms/studio/lib/operations'\nimport type { OperationsClient, StudioOperations } from '@elytracms/studio/lib/operations'\nimport { useOperationCache, useOperationQuery } from '@elytracms/studio/lib/query'\nimport { updateAssetMetadata } from './asset-metadata'\nimport type { AssetMetadataPatch, UpdateAssetMetadataResult } from './asset-metadata'\n\n/**\n * Asset library store (EC-151, EC-141). Asset *metadata* mutations go through\n * the shared operations client (`assets.*` commands — validate → authorize →\n * mutate → event); blob *bytes* ride on `adapter.blobs`, which is transport,\n * not domain. The UI works identically against the in-memory seed and a live\n * Convex deployment.\n */\n\nexport interface UploadEntry {\n id: string\n filename: string\n state: UploadState\n}\n\nexport interface AssetsStore {\n /** The active project (e.g. for reference deep links, EC-202). */\n projectId: string\n status: 'loading' | 'ready' | 'error'\n errorMessage?: string\n assets: readonly AssetRecord[]\n uploads: readonly UploadEntry[]\n upload(files: Iterable<UploadableFile>): void\n retryUpload(uploadId: string): void\n dismissUpload(uploadId: string): void\n /**\n * Index-accurate inbound references of an asset (EC-202): the \"used by\"\n * pre-flight of the block-or-confirm delete dialog, read from the EC-155\n * reference index (not the retired string scan).\n */\n usagesOf(assetId: string): Promise<ReferenceEntryView[]>\n remove(assetId: string, options?: { confirmInUse?: boolean }): Promise<DeleteAssetResult>\n /** Edit alt/title (EC-152); persists through the operations asset facade. */\n updateMetadata(assetId: string, patch: AssetMetadataPatch): Promise<UpdateAssetMetadataResult>\n refresh(): Promise<void>\n}\n\nconst AssetsContext = createContext<AssetsStore | null>(null)\n\nconst EMPTY_ASSETS: readonly AssetRecord[] = []\n\n/** Cache key for a project's asset library (shared by the query and its patches). */\nfunction assetsQueryKey(projectId: string): readonly [string, string] {\n return ['assets', projectId]\n}\n\n/** Load a project's asset library (pure over the operations client). A list\n * failure throws so the query surfaces it as an error status. */\nasync function loadAssets(operations: OperationsClient, projectId: string): Promise<AssetRecord[]> {\n const result = await operations.assets.list({ projectId })\n if (!result.ok) throw new Error(result.error.message)\n return [...result.value]\n}\n\nexport function AssetsProvider({\n projectId,\n children,\n}: {\n projectId: string\n children: ReactNode\n}) {\n const uploadFilesRef = useRef(new Map<string, UploadableFile>())\n const uploadSeq = useRef(0)\n const [uploads, setUploads] = useState<readonly UploadEntry[]>([])\n\n /** The shared studio operations bundle + the metadata-write facade over it. */\n const studio = useCallback(async (): Promise<\n StudioOperations & { assetRepo: AssetRepository }\n > => {\n const bundle = await getStudioOperations()\n return { ...bundle, assetRepo: operationsAssetRepository(bundle.operations) }\n }, [])\n\n // The library list, read through the one operations-backed query cache\n // (EC-308/AD-17). No `invalidateOn`: this provider is the sole writer of its\n // project's assets, so its own mutations patch the cache in place (the EC-301\n // rule — a metadata or focal-point edit must never trigger a full re-list).\n const query = useOperationQuery<AssetRecord[]>({\n queryKey: assetsQueryKey(projectId),\n loader: (operations) => loadAssets(operations, projectId),\n })\n const cache = useOperationCache()\n const refetch = query.refetch\n const assets = query.data ?? EMPTY_ASSETS\n const status: AssetsStore['status'] = query.isPending\n ? 'loading'\n : query.isError\n ? 'error'\n : 'ready'\n const errorMessage =\n query.isError && query.error instanceof Error ? query.error.message : undefined\n\n /** Re-list from the backend (the public escape hatch + post-upload reconcile). */\n const refresh = useCallback(async () => {\n await refetch()\n }, [refetch])\n\n const setUploadState = useCallback((uploadId: string, state: UploadState) => {\n setUploads((prev) => prev.map((u) => (u.id === uploadId ? { ...u, state } : u)))\n }, [])\n\n const runEntry = useCallback(\n async (uploadId: string, file: UploadableFile, previous?: UploadState) => {\n const { adapter, assetRepo } = await studio()\n const result = await runUpload(\n {\n // Bytes ride on blob storage (transport); the metadata record is\n // confirmed through the `assets.upsert` operation command.\n blobs: adapter.blobs,\n assets: assetRepo,\n ...(typeof XMLHttpRequest !== 'undefined' ? { transport: xhrUploadTransport } : {}),\n },\n {\n projectId,\n file,\n onState: (state) => setUploadState(uploadId, state),\n },\n previous,\n )\n if (result.ok) {\n // Completed uploads leave the queue; the asset appears in the library.\n uploadFilesRef.current.delete(uploadId)\n setUploads((prev) => prev.filter((u) => u.id !== uploadId))\n await refresh()\n }\n },\n [studio, projectId, refresh, setUploadState],\n )\n\n const upload = useCallback(\n (files: Iterable<UploadableFile>) => {\n for (const file of files) {\n uploadSeq.current += 1\n const uploadId = `upload-${uploadSeq.current}`\n uploadFilesRef.current.set(uploadId, file)\n setUploads((prev) => [\n ...prev,\n { id: uploadId, filename: file.name, state: { phase: 'idle', progress: 0, attempt: 0 } },\n ])\n void runEntry(uploadId, file)\n }\n },\n [runEntry],\n )\n\n const retryUpload = useCallback(\n (uploadId: string) => {\n const file = uploadFilesRef.current.get(uploadId)\n const entry = uploads.find((u) => u.id === uploadId)\n if (!file || !entry || entry.state.phase !== 'failed') return\n void runEntry(uploadId, file, entry.state)\n },\n [runEntry, uploads],\n )\n\n const dismissUpload = useCallback((uploadId: string) => {\n uploadFilesRef.current.delete(uploadId)\n setUploads((prev) => prev.filter((u) => u.id !== uploadId))\n }, [])\n\n const usagesOf = useCallback(\n // Index-accurate (EC-202): inbound references from the EC-155 index via the\n // operations queries — the same machinery the References panel uses.\n async (assetId: string) => loadInboundAssetReferenceViews(projectId, assetId),\n [projectId],\n )\n\n const remove = useCallback(\n async (assetId: string, options?: { confirmInUse?: boolean }) => {\n const { adapter, assetRepo } = await studio()\n // Metadata removal goes through the `assets.remove` command (via the\n // facade); blob byte deletion stays on the adapter; the usage gate reads\n // the EC-155 reference index (`adapter.references`, EC-202).\n const result = await deleteAsset(\n { assets: assetRepo, blobs: adapter.blobs, references: adapter.references },\n projectId,\n assetId,\n options,\n )\n // Drop the one removed record from the cache rather than re-listing the whole\n // library (EC-301 perf, mirrors updateMetadata) — a delete must not trigger a full\n // `assets.list` round-trip on top of the deletion itself.\n if (result.outcome === 'deleted' || result.outcome === 'not-found') {\n cache.patch<AssetRecord[]>(assetsQueryKey(projectId), (prev) =>\n (prev ?? []).filter((a) => a.id !== assetId),\n )\n }\n return result\n },\n [studio, projectId, cache],\n )\n\n const updateMetadata = useCallback(\n async (assetId: string, patch: AssetMetadataPatch) => {\n // Metadata writes go through the `assets.upsert` command via the\n // operations facade (EC-141) — never straight at a repository.\n const { assetRepo } = await studio()\n const result = await updateAssetMetadata({ assets: assetRepo }, projectId, assetId, patch)\n if (result.ok) {\n // Patch the one updated record into the cache rather than re-listing the\n // whole library (EC-301). A focal-point or alt edit must not trigger a full\n // `assets.list` round-trip — that re-list (plus the marker only moving once\n // it returned) was the focal-point picker's lag and query storm.\n const updated = result.asset\n cache.patch<AssetRecord[]>(assetsQueryKey(projectId), (prev) =>\n (prev ?? []).map((a) => (a.id === assetId ? updated : a)),\n )\n }\n return result\n },\n [studio, projectId, cache],\n )\n\n const store = useMemo<AssetsStore>(\n () => ({\n projectId,\n status,\n ...(errorMessage !== undefined ? { errorMessage } : {}),\n assets,\n uploads,\n upload,\n retryUpload,\n dismissUpload,\n usagesOf,\n remove,\n updateMetadata,\n refresh,\n }),\n [\n projectId,\n status,\n errorMessage,\n assets,\n uploads,\n upload,\n retryUpload,\n dismissUpload,\n usagesOf,\n remove,\n updateMetadata,\n refresh,\n ],\n )\n\n return <AssetsContext.Provider value={store}>{children}</AssetsContext.Provider>\n}\n\nexport function useAssets(): AssetsStore {\n const store = useContext(AssetsContext)\n if (!store) throw new Error('useAssets must be used within an <AssetsProvider>.')\n return store\n}\n\n/**\n * The assets store when an `<AssetsProvider>` is mounted above, else `null`.\n * Lets surfaces outside the Assets section (the CMS asset picker, EC-152)\n * reuse an ambient provider or mount their own.\n */\nexport function useOptionalAssets(): AssetsStore | null {\n return useContext(AssetsContext)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"assets-store.js","sourceRoot":"","sources":["../../../src/components/assets/assets-store.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAGzF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEzF,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AAEjF,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAEjG,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CA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,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC1D,CAAA;QACH,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,EACD,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAC3B,CAAA;IAED,MAAM,KAAK,GAAG,OAAO,CACnB,GAAG,EAAE,CAAC,CAAC;QACL,SAAS;QACT,MAAM;QACN,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,MAAM;QACN,OAAO;QACP,MAAM;QACN,WAAW;QACX,aAAa;QACb,QAAQ;QACR,MAAM;QACN,cAAc;QACd,OAAO;KACR,CAAC,EACF;QACE,SAAS;QACT,MAAM;QACN,YAAY;QACZ,MAAM;QACN,OAAO;QACP,MAAM;QACN,WAAW;QACX,aAAa;QACb,QAAQ;QACR,MAAM;QACN,cAAc;QACd,OAAO;KACR,CACF,CAAA;IAED,OAAO,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA0B,CAAA;AAClF,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,CAAC,CAAA;IACvC,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;IACjF,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC,aAAa,CAAC,CAAA;AAClC,CAAC","sourcesContent":["import { createContext, useCallback, useContext, useMemo, useRef, useState } from 'react'\nimport type { ReactNode } from 'react'\nimport type { AssetRecord, AssetRepository } from '@elytracms/core/persistence'\nimport { deleteAsset, runUpload, xhrUploadTransport } from '@elytracms/studio/lib/assets'\nimport type { DeleteAssetResult, UploadState, UploadableFile } from '@elytracms/studio/lib/assets'\nimport { loadInboundAssetReferenceViews } from '@elytracms/studio/lib/references'\nimport type { ReferenceEntryView } from '@elytracms/studio/lib/references'\nimport { getStudioOperations, operationsAssetRepository } from '@elytracms/studio/lib/operations'\nimport type { OperationsClient, StudioOperations } from '@elytracms/studio/lib/operations'\nimport { listStoreState, useOperationCache, useOperationQuery } from '@elytracms/studio/lib/query'\nimport { updateAssetMetadata } from './asset-metadata'\nimport type { AssetMetadataPatch, UpdateAssetMetadataResult } from './asset-metadata'\n\n/**\n * Asset library store (EC-151, EC-141). Asset *metadata* mutations go through\n * the shared operations client (`assets.*` commands — validate → authorize →\n * mutate → event); blob *bytes* ride on `adapter.blobs`, which is transport,\n * not domain. The UI works identically against the in-memory seed and a live\n * Convex deployment.\n */\n\nexport interface UploadEntry {\n id: string\n filename: string\n state: UploadState\n}\n\nexport interface AssetsStore {\n /** The active project (e.g. for reference deep links, EC-202). */\n projectId: string\n status: 'loading' | 'ready' | 'error'\n errorMessage?: string\n assets: readonly AssetRecord[]\n uploads: readonly UploadEntry[]\n upload(files: Iterable<UploadableFile>): void\n retryUpload(uploadId: string): void\n dismissUpload(uploadId: string): void\n /**\n * Index-accurate inbound references of an asset (EC-202): the \"used by\"\n * pre-flight of the block-or-confirm delete dialog, read from the EC-155\n * reference index (not the retired string scan).\n */\n usagesOf(assetId: string): Promise<ReferenceEntryView[]>\n remove(assetId: string, options?: { confirmInUse?: boolean }): Promise<DeleteAssetResult>\n /** Edit alt/title (EC-152); persists through the operations asset facade. */\n updateMetadata(assetId: string, patch: AssetMetadataPatch): Promise<UpdateAssetMetadataResult>\n refresh(): Promise<void>\n}\n\nconst AssetsContext = createContext<AssetsStore | null>(null)\n\nconst EMPTY_ASSETS: readonly AssetRecord[] = []\n\n/** Cache key for a project's asset library (shared by the query and its patches). */\nfunction assetsQueryKey(projectId: string): readonly [string, string] {\n return ['assets', projectId]\n}\n\n/** Load a project's asset library (pure over the operations client). A list\n * failure throws so the query surfaces it as an error status. */\nasync function loadAssets(operations: OperationsClient, projectId: string): Promise<AssetRecord[]> {\n const result = await operations.assets.list({ projectId })\n if (!result.ok) throw new Error(result.error.message)\n return [...result.value]\n}\n\nexport function AssetsProvider({\n projectId,\n children,\n}: {\n projectId: string\n children: ReactNode\n}) {\n const uploadFilesRef = useRef(new Map<string, UploadableFile>())\n const uploadSeq = useRef(0)\n const [uploads, setUploads] = useState<readonly UploadEntry[]>([])\n\n /** The shared studio operations bundle + the metadata-write facade over it. */\n const studio = useCallback(async (): Promise<\n StudioOperations & { assetRepo: AssetRepository }\n > => {\n const bundle = await getStudioOperations()\n return { ...bundle, assetRepo: operationsAssetRepository(bundle.operations) }\n }, [])\n\n // The library list, read through the one operations-backed query cache\n // (EC-308/AD-17). No `invalidateOn`: this provider is the sole writer of its\n // project's assets, so its own mutations patch the cache in place (the EC-301\n // rule — a metadata or focal-point edit must never trigger a full re-list).\n const query = useOperationQuery<AssetRecord[]>({\n queryKey: assetsQueryKey(projectId),\n loader: (operations) => loadAssets(operations, projectId),\n })\n const cache = useOperationCache()\n const refetch = query.refetch\n const assets = query.data ?? EMPTY_ASSETS\n const { status, errorMessage } = listStoreState(query)\n\n /** Re-list from the backend (the public escape hatch + post-upload reconcile). */\n const refresh = useCallback(async () => {\n await refetch()\n }, [refetch])\n\n const setUploadState = useCallback((uploadId: string, state: UploadState) => {\n setUploads((prev) => prev.map((u) => (u.id === uploadId ? { ...u, state } : u)))\n }, [])\n\n const runEntry = useCallback(\n async (uploadId: string, file: UploadableFile, previous?: UploadState) => {\n const { adapter, assetRepo } = await studio()\n const result = await runUpload(\n {\n // Bytes ride on blob storage (transport); the metadata record is\n // confirmed through the `assets.upsert` operation command.\n blobs: adapter.blobs,\n assets: assetRepo,\n ...(typeof XMLHttpRequest !== 'undefined' ? { transport: xhrUploadTransport } : {}),\n },\n {\n projectId,\n file,\n onState: (state) => setUploadState(uploadId, state),\n },\n previous,\n )\n if (result.ok) {\n // Completed uploads leave the queue; the asset appears in the library.\n uploadFilesRef.current.delete(uploadId)\n setUploads((prev) => prev.filter((u) => u.id !== uploadId))\n await refresh()\n }\n },\n [studio, projectId, refresh, setUploadState],\n )\n\n const upload = useCallback(\n (files: Iterable<UploadableFile>) => {\n for (const file of files) {\n uploadSeq.current += 1\n const uploadId = `upload-${uploadSeq.current}`\n uploadFilesRef.current.set(uploadId, file)\n setUploads((prev) => [\n ...prev,\n { id: uploadId, filename: file.name, state: { phase: 'idle', progress: 0, attempt: 0 } },\n ])\n void runEntry(uploadId, file)\n }\n },\n [runEntry],\n )\n\n const retryUpload = useCallback(\n (uploadId: string) => {\n const file = uploadFilesRef.current.get(uploadId)\n const entry = uploads.find((u) => u.id === uploadId)\n if (!file || !entry || entry.state.phase !== 'failed') return\n void runEntry(uploadId, file, entry.state)\n },\n [runEntry, uploads],\n )\n\n const dismissUpload = useCallback((uploadId: string) => {\n uploadFilesRef.current.delete(uploadId)\n setUploads((prev) => prev.filter((u) => u.id !== uploadId))\n }, [])\n\n const usagesOf = useCallback(\n // Index-accurate (EC-202): inbound references from the EC-155 index via the\n // operations queries — the same machinery the References panel uses.\n async (assetId: string) => loadInboundAssetReferenceViews(projectId, assetId),\n [projectId],\n )\n\n const remove = useCallback(\n async (assetId: string, options?: { confirmInUse?: boolean }) => {\n const { adapter, assetRepo } = await studio()\n // Metadata removal goes through the `assets.remove` command (via the\n // facade); blob byte deletion stays on the adapter; the usage gate reads\n // the EC-155 reference index (`adapter.references`, EC-202).\n const result = await deleteAsset(\n { assets: assetRepo, blobs: adapter.blobs, references: adapter.references },\n projectId,\n assetId,\n options,\n )\n // Drop the one removed record from the cache rather than re-listing the whole\n // library (EC-301 perf, mirrors updateMetadata) — a delete must not trigger a full\n // `assets.list` round-trip on top of the deletion itself.\n if (result.outcome === 'deleted' || result.outcome === 'not-found') {\n cache.patch<AssetRecord[]>(assetsQueryKey(projectId), (prev) =>\n (prev ?? []).filter((a) => a.id !== assetId),\n )\n }\n return result\n },\n [studio, projectId, cache],\n )\n\n const updateMetadata = useCallback(\n async (assetId: string, patch: AssetMetadataPatch) => {\n // Metadata writes go through the `assets.upsert` command via the\n // operations facade (EC-141) — never straight at a repository.\n const { assetRepo } = await studio()\n const result = await updateAssetMetadata({ assets: assetRepo }, projectId, assetId, patch)\n if (result.ok) {\n // Patch the one updated record into the cache rather than re-listing the\n // whole library (EC-301). A focal-point or alt edit must not trigger a full\n // `assets.list` round-trip — that re-list (plus the marker only moving once\n // it returned) was the focal-point picker's lag and query storm.\n const updated = result.asset\n cache.patch<AssetRecord[]>(assetsQueryKey(projectId), (prev) =>\n (prev ?? []).map((a) => (a.id === assetId ? updated : a)),\n )\n }\n return result\n },\n [studio, projectId, cache],\n )\n\n const store = useMemo<AssetsStore>(\n () => ({\n projectId,\n status,\n ...(errorMessage !== undefined ? { errorMessage } : {}),\n assets,\n uploads,\n upload,\n retryUpload,\n dismissUpload,\n usagesOf,\n remove,\n updateMetadata,\n refresh,\n }),\n [\n projectId,\n status,\n errorMessage,\n assets,\n uploads,\n upload,\n retryUpload,\n dismissUpload,\n usagesOf,\n remove,\n updateMetadata,\n refresh,\n ],\n )\n\n return <AssetsContext.Provider value={store}>{children}</AssetsContext.Provider>\n}\n\nexport function useAssets(): AssetsStore {\n const store = useContext(AssetsContext)\n if (!store) throw new Error('useAssets must be used within an <AssetsProvider>.')\n return store\n}\n\n/**\n * The assets store when an `<AssetsProvider>` is mounted above, else `null`.\n * Lets surfaces outside the Assets section (the CMS asset picker, EC-152)\n * reuse an ambient provider or mount their own.\n */\nexport function useOptionalAssets(): AssetsStore | null {\n return useContext(AssetsContext)\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assets list/grid view-mode preference (EC-319). The same class of transient,
|
|
3
|
+
* personal-local UI preference as the version-compare view mode (EC-317,
|
|
4
|
+
* `lib/diff-view-preference.ts`), the theme, and rail-collapse: it never touches
|
|
5
|
+
* the project graph or any document, so it rides `localStorage` best-effort
|
|
6
|
+
* instead of a new persistence mechanism. Unavailable storage (SSR, privacy
|
|
7
|
+
* mode) degrades to the default every session — never a crash.
|
|
8
|
+
*/
|
|
9
|
+
export type AssetsViewMode = 'list' | 'grid';
|
|
10
|
+
export declare const ASSETS_VIEW_STORAGE_KEY = "elytra-assets-view-mode";
|
|
11
|
+
export declare const DEFAULT_ASSETS_VIEW_MODE: AssetsViewMode;
|
|
12
|
+
/** Read the persisted preference, or the default when unset/unavailable/invalid. */
|
|
13
|
+
export declare function readAssetsViewMode(): AssetsViewMode;
|
|
14
|
+
/** Persist the preference (best-effort; storage may be unavailable). */
|
|
15
|
+
export declare function storeAssetsViewMode(mode: AssetsViewMode): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const ASSETS_VIEW_STORAGE_KEY = 'elytra-assets-view-mode';
|
|
2
|
+
export const DEFAULT_ASSETS_VIEW_MODE = 'list';
|
|
3
|
+
/** Read the persisted preference, or the default when unset/unavailable/invalid. */
|
|
4
|
+
export function readAssetsViewMode() {
|
|
5
|
+
try {
|
|
6
|
+
const value = localStorage.getItem(ASSETS_VIEW_STORAGE_KEY);
|
|
7
|
+
return value === 'list' || value === 'grid' ? value : DEFAULT_ASSETS_VIEW_MODE;
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return DEFAULT_ASSETS_VIEW_MODE;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Persist the preference (best-effort; storage may be unavailable). */
|
|
14
|
+
export function storeAssetsViewMode(mode) {
|
|
15
|
+
try {
|
|
16
|
+
localStorage.setItem(ASSETS_VIEW_STORAGE_KEY, mode);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// ignore — preference simply won't persist this session
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=assets-view-preference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assets-view-preference.js","sourceRoot":"","sources":["../../../src/components/assets/assets-view-preference.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,uBAAuB,GAAG,yBAAyB,CAAA;AAChE,MAAM,CAAC,MAAM,wBAAwB,GAAmB,MAAM,CAAA;AAE9D,oFAAoF;AACpF,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAA;QAC3D,OAAO,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAA;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,wBAAwB,CAAA;IACjC,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,mBAAmB,CAAC,IAAoB;IACtD,IAAI,CAAC;QACH,YAAY,CAAC,OAAO,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAA;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,wDAAwD;IAC1D,CAAC;AACH,CAAC","sourcesContent":["/**\n * Assets list/grid view-mode preference (EC-319). The same class of transient,\n * personal-local UI preference as the version-compare view mode (EC-317,\n * `lib/diff-view-preference.ts`), the theme, and rail-collapse: it never touches\n * the project graph or any document, so it rides `localStorage` best-effort\n * instead of a new persistence mechanism. Unavailable storage (SSR, privacy\n * mode) degrades to the default every session — never a crash.\n */\nexport type AssetsViewMode = 'list' | 'grid'\n\nexport const ASSETS_VIEW_STORAGE_KEY = 'elytra-assets-view-mode'\nexport const DEFAULT_ASSETS_VIEW_MODE: AssetsViewMode = 'list'\n\n/** Read the persisted preference, or the default when unset/unavailable/invalid. */\nexport function readAssetsViewMode(): AssetsViewMode {\n try {\n const value = localStorage.getItem(ASSETS_VIEW_STORAGE_KEY)\n return value === 'list' || value === 'grid' ? value : DEFAULT_ASSETS_VIEW_MODE\n } catch {\n return DEFAULT_ASSETS_VIEW_MODE\n }\n}\n\n/** Persist the preference (best-effort; storage may be unavailable). */\nexport function storeAssetsViewMode(mode: AssetsViewMode): void {\n try {\n localStorage.setItem(ASSETS_VIEW_STORAGE_KEY, mode)\n } catch {\n // ignore — preference simply won't persist this session\n }\n}\n"]}
|
|
@@ -103,6 +103,18 @@ export interface BuilderState {
|
|
|
103
103
|
lastCoalesceKey: string | null;
|
|
104
104
|
}
|
|
105
105
|
type Action = BuilderAction;
|
|
106
|
+
export interface Counter {
|
|
107
|
+
genId: () => string;
|
|
108
|
+
count: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The single fresh-node-id counter (`node-<n>`), shared by the reducer's structural
|
|
112
|
+
* actions AND the clipboard paste path (`clipboard-actions.tsx`) so the paste-issue
|
|
113
|
+
* deep links can mirror the exact ids the reducer will mint — one implementation,
|
|
114
|
+
* no drift. `count` mutates as `genId` is called, so the caller reads it afterward
|
|
115
|
+
* to advance `nodeSeq`.
|
|
116
|
+
*/
|
|
117
|
+
export declare function makeNodeIdCounter(start: number): Counter;
|
|
106
118
|
/**
|
|
107
119
|
* The pure state transition. Exported (with `initialBuilderState`) for unit
|
|
108
120
|
* tests — gesture determinism and normalization lockstep are reducer-level
|