@elytracms/studio 0.0.43 → 0.0.45
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 +59 -21
- package/convex/content.ts +6 -3
- package/convex/delivery.ts +8 -5
- package/convex/triggers.ts +8 -1
- package/dist/components/app-views/studio-config.d.ts +12 -0
- package/dist/components/app-views/studio-config.js.map +1 -1
- package/dist/components/assets/assets-collection-view-source.d.ts +13 -1
- package/dist/components/assets/assets-collection-view-source.js +42 -51
- package/dist/components/assets/assets-collection-view-source.js.map +1 -1
- package/dist/components/cms/cms-store.js +9 -11
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/detail-editor.js +110 -338
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/document-staging.d.ts +8 -3
- package/dist/components/cms/document-staging.js +81 -21
- package/dist/components/cms/document-staging.js.map +1 -1
- package/dist/components/cms/use-compare-selection.d.ts +27 -0
- package/dist/components/cms/use-compare-selection.js +29 -0
- package/dist/components/cms/use-compare-selection.js.map +1 -0
- package/dist/components/cms/use-discard-controller.d.ts +44 -0
- package/dist/components/cms/use-discard-controller.js +51 -0
- package/dist/components/cms/use-discard-controller.js.map +1 -0
- package/dist/components/cms/use-embed-inspector-host.d.ts +12 -0
- package/dist/components/cms/use-embed-inspector-host.js +17 -0
- package/dist/components/cms/use-embed-inspector-host.js.map +1 -0
- package/dist/components/cms/use-field-focus.d.ts +38 -0
- package/dist/components/cms/use-field-focus.js +70 -0
- package/dist/components/cms/use-field-focus.js.map +1 -0
- package/dist/components/cms/use-live-url.d.ts +41 -0
- package/dist/components/cms/use-live-url.js +55 -0
- package/dist/components/cms/use-live-url.js.map +1 -0
- package/dist/components/cms/use-publish-controller.d.ts +49 -0
- package/dist/components/cms/use-publish-controller.js +102 -0
- package/dist/components/cms/use-publish-controller.js.map +1 -0
- package/dist/components/cms/use-published-perspective.d.ts +67 -0
- package/dist/components/cms/use-published-perspective.js +67 -0
- package/dist/components/cms/use-published-perspective.js.map +1 -0
- package/dist/components/cms/use-restore-version.d.ts +57 -0
- package/dist/components/cms/use-restore-version.js +66 -0
- package/dist/components/cms/use-restore-version.js.map +1 -0
- package/dist/components/cms/use-save-mode.d.ts +35 -0
- package/dist/components/cms/use-save-mode.js +54 -0
- package/dist/components/cms/use-save-mode.js.map +1 -0
- package/dist/components/cms/version-compare.js +13 -16
- package/dist/components/cms/version-compare.js.map +1 -1
- package/dist/components/cms/versions-pane.js +21 -19
- package/dist/components/cms/versions-pane.js.map +1 -1
- package/dist/components/components/transfer-dialog.d.ts +11 -6
- package/dist/components/components/transfer-dialog.js +98 -25
- package/dist/components/components/transfer-dialog.js.map +1 -1
- package/dist/components/components/transfer.d.ts +74 -8
- package/dist/components/components/transfer.js +87 -2
- package/dist/components/components/transfer.js.map +1 -1
- package/dist/components/rail-store-status.d.ts +7 -5
- package/dist/components/rail-store-status.js +12 -9
- package/dist/components/rail-store-status.js.map +1 -1
- package/dist/components/rail-view-source.d.ts +111 -0
- package/dist/components/rail-view-source.js +139 -0
- package/dist/components/rail-view-source.js.map +1 -0
- package/dist/components/redirects/redirects-collection-view-source.d.ts +13 -1
- package/dist/components/redirects/redirects-collection-view-source.js +42 -70
- package/dist/components/redirects/redirects-collection-view-source.js.map +1 -1
- package/dist/components/section-state.d.ts +12 -3
- package/dist/components/section-state.js +8 -4
- package/dist/components/section-state.js.map +1 -1
- package/dist/components/users/users-collection-view-source.d.ts +13 -1
- package/dist/components/users/users-collection-view-source.js +60 -79
- package/dist/components/users/users-collection-view-source.js.map +1 -1
- package/dist/lib/ai/anthropic-provider.d.ts +29 -0
- package/dist/lib/ai/anthropic-provider.js +59 -0
- package/dist/lib/ai/anthropic-provider.js.map +1 -0
- package/dist/lib/ai/apply-content.d.ts +9 -0
- package/dist/lib/ai/apply-content.js +170 -0
- package/dist/lib/ai/apply-content.js.map +1 -0
- package/dist/lib/ai/config.d.ts +58 -0
- package/dist/lib/ai/config.js +134 -0
- package/dist/lib/ai/config.js.map +1 -0
- package/dist/lib/ai/fake-provider.d.ts +34 -0
- package/dist/lib/ai/fake-provider.js +31 -0
- package/dist/lib/ai/fake-provider.js.map +1 -0
- package/dist/lib/ai/index.d.ts +22 -0
- package/dist/lib/ai/index.js +23 -0
- package/dist/lib/ai/index.js.map +1 -0
- package/dist/lib/ai/knowledge.d.ts +39 -0
- package/dist/lib/ai/knowledge.js +60 -0
- package/dist/lib/ai/knowledge.js.map +1 -0
- package/dist/lib/ai/provenance.d.ts +20 -0
- package/dist/lib/ai/provenance.js +15 -0
- package/dist/lib/ai/provenance.js.map +1 -0
- package/dist/lib/ai/route.d.ts +24 -0
- package/dist/lib/ai/route.js +90 -0
- package/dist/lib/ai/route.js.map +1 -0
- package/dist/lib/ai/shape.d.ts +35 -0
- package/dist/lib/ai/shape.js +113 -0
- package/dist/lib/ai/shape.js.map +1 -0
- package/dist/lib/ai/types.d.ts +227 -0
- package/dist/lib/ai/types.js +2 -0
- package/dist/lib/ai/types.js.map +1 -0
- package/dist/lib/i18n/messages.en.js +4 -2
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/workspace/index.d.ts +9 -0
- package/dist/lib/workspace/index.js +11 -0
- package/dist/lib/workspace/index.js.map +1 -1
- package/package.json +8 -2
package/convex/cms.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { v } from 'convex/values'
|
|
2
|
+
import { foldDocument, unfoldDocument } from '@elytracms/core/cms-core'
|
|
3
|
+
import type { CmsDocument } from '@elytracms/core/cms-core'
|
|
2
4
|
import { mutation, query } from './functions'
|
|
3
5
|
import { requireCapability } from './guard'
|
|
4
6
|
|
|
@@ -9,8 +11,29 @@ import { requireCapability } from './guard'
|
|
|
9
11
|
* table and no schema read/write function here. Collection-membership
|
|
10
12
|
* validation lives in `@elytracms/core/cms-core` `validateDocument` (the studio runs it
|
|
11
13
|
* pre-dispatch); this layer is a pure document store.
|
|
14
|
+
*
|
|
15
|
+
* ## EC-260 depth-budget codec (the storage boundary)
|
|
16
|
+
*
|
|
17
|
+
* Convex caps STORED documents at 16 nesting levels but allows 64 in function
|
|
18
|
+
* args/returns. Ordinary content (deep rich text, nested compositions) trips 16 at
|
|
19
|
+
* rest, so every write here FOLDS over-budget field values into self-describing
|
|
20
|
+
* leaf envelopes immediately before `ctx.db`, and every read UNFOLDS before the
|
|
21
|
+
* value leaves the function. Mutations receive the UNFOLDED value over the wire, so
|
|
22
|
+
* the AD-15 reference walker (in the write-chokepoint trigger, which unfolds first)
|
|
23
|
+
* always sees structured content. The wire never carries an envelope; only raw
|
|
24
|
+
* `ctx.db` reads / the dashboard see the folded storage form.
|
|
12
25
|
*/
|
|
13
26
|
|
|
27
|
+
/** Unfold the `document` blob of a stored row before it leaves the function. */
|
|
28
|
+
function withUnfoldedDocument<R extends { document: unknown }>(row: R): R {
|
|
29
|
+
return { ...row, document: unfoldDocument(row.document as CmsDocument) }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Unfold the `snapshot` blob of a version row before it leaves the function. */
|
|
33
|
+
function withUnfoldedSnapshot<R extends { snapshot: unknown }>(row: R): R {
|
|
34
|
+
return { ...row, snapshot: unfoldDocument(row.snapshot as CmsDocument) }
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
export const upsertDocument = mutation({
|
|
15
38
|
args: {
|
|
16
39
|
collection: v.string(),
|
|
@@ -21,6 +44,10 @@ export const upsertDocument = mutation({
|
|
|
21
44
|
},
|
|
22
45
|
handler: async (ctx, args) => {
|
|
23
46
|
await requireCapability(ctx, 'content.write') // EC-150
|
|
47
|
+
// EC-260: fold for storage. `args.document` arrives UNFOLDED over the 64-level
|
|
48
|
+
// arg wire; the trigger unfolds before extracting references, so folding here
|
|
49
|
+
// (strictly before the `ctx.db` write) never hides a reference from the walker.
|
|
50
|
+
const stored = { ...args, document: foldDocument(args.document as CmsDocument) }
|
|
24
51
|
const existing = await ctx.db
|
|
25
52
|
.query('cmsDocuments')
|
|
26
53
|
.withIndex('by_doc', (q) => q.eq('collection', args.collection).eq('docId', args.docId))
|
|
@@ -28,17 +55,19 @@ export const upsertDocument = mutation({
|
|
|
28
55
|
if (existing) {
|
|
29
56
|
// EC-153 parity: updates preserve `createdAt`, exactly like in-memory.
|
|
30
57
|
// EC-286: the write-chokepoint trigger reindexes references in-transaction.
|
|
31
|
-
const patch = { ...
|
|
58
|
+
const patch = { ...stored, createdAt: existing.createdAt }
|
|
32
59
|
await ctx.db.patch(existing._id, patch)
|
|
33
60
|
// EC-322: return the merged row directly instead of re-reading the full
|
|
34
61
|
// (up-to-~20 KB) document body via `ctx.db.get`. `patch` only overwrites the
|
|
35
62
|
// supplied fields, so `{ ...existing, ...patch }` is byte-identical to the
|
|
36
63
|
// stored row (system fields + untouched `publishedVersion` carried from
|
|
37
64
|
// `existing`) — cutting one full-document read off the hottest write path.
|
|
38
|
-
|
|
65
|
+
// EC-260: unfold the folded body back to structured form for the return.
|
|
66
|
+
return withUnfoldedDocument({ ...existing, ...patch })
|
|
39
67
|
}
|
|
40
|
-
const id = await ctx.db.insert('cmsDocuments',
|
|
41
|
-
|
|
68
|
+
const id = await ctx.db.insert('cmsDocuments', stored)
|
|
69
|
+
const row = await ctx.db.get(id)
|
|
70
|
+
return row ? withUnfoldedDocument(row) : row
|
|
42
71
|
},
|
|
43
72
|
})
|
|
44
73
|
|
|
@@ -46,10 +75,11 @@ export const getDocument = query({
|
|
|
46
75
|
args: { collection: v.string(), docId: v.string() },
|
|
47
76
|
handler: async (ctx, args) => {
|
|
48
77
|
await requireCapability(ctx, 'content.read') // EC-150
|
|
49
|
-
|
|
78
|
+
const row = await ctx.db
|
|
50
79
|
.query('cmsDocuments')
|
|
51
80
|
.withIndex('by_doc', (q) => q.eq('collection', args.collection).eq('docId', args.docId))
|
|
52
81
|
.first()
|
|
82
|
+
return row ? withUnfoldedDocument(row) : row // EC-260: unfold before returning
|
|
53
83
|
},
|
|
54
84
|
})
|
|
55
85
|
|
|
@@ -57,14 +87,13 @@ export const listDocuments = query({
|
|
|
57
87
|
args: { collection: v.optional(v.string()) },
|
|
58
88
|
handler: async (ctx, args) => {
|
|
59
89
|
await requireCapability(ctx, 'content.read') // EC-150
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return ctx.db.query('cmsDocuments').collect()
|
|
90
|
+
const rows = args.collection
|
|
91
|
+
? await ctx.db
|
|
92
|
+
.query('cmsDocuments')
|
|
93
|
+
.withIndex('by_collection', (q) => q.eq('collection', args.collection as string))
|
|
94
|
+
.collect()
|
|
95
|
+
: await ctx.db.query('cmsDocuments').collect()
|
|
96
|
+
return rows.map(withUnfoldedDocument) // EC-260: unfold before returning
|
|
68
97
|
},
|
|
69
98
|
})
|
|
70
99
|
|
|
@@ -113,8 +142,12 @@ export const saveDocumentVersion = mutation({
|
|
|
113
142
|
.order('desc')
|
|
114
143
|
.first()
|
|
115
144
|
const version = (latest?.version ?? 0) + 1
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
// EC-260: the snapshot embeds the CmsDocument at draft depth, so it folds at rest
|
|
146
|
+
// identically. `documentVersions` has no trigger — no walker to keep structured.
|
|
147
|
+
const stored = { ...args, snapshot: foldDocument(args.snapshot as CmsDocument), version }
|
|
148
|
+
const id = await ctx.db.insert('documentVersions', stored)
|
|
149
|
+
const row = await ctx.db.get(id)
|
|
150
|
+
return row ? withUnfoldedSnapshot(row) : row
|
|
118
151
|
},
|
|
119
152
|
})
|
|
120
153
|
|
|
@@ -127,7 +160,7 @@ export const listDocumentVersions = query({
|
|
|
127
160
|
.withIndex('by_doc', (q) => q.eq('collection', args.collection).eq('docId', args.docId))
|
|
128
161
|
.collect()
|
|
129
162
|
// Newest first (parity with the in-memory `listDocumentVersions`).
|
|
130
|
-
return rows.sort((a, b) => b.version - a.version)
|
|
163
|
+
return rows.sort((a, b) => b.version - a.version).map(withUnfoldedSnapshot) // EC-260
|
|
131
164
|
},
|
|
132
165
|
})
|
|
133
166
|
|
|
@@ -138,12 +171,13 @@ export const getDocumentVersion = query({
|
|
|
138
171
|
// EC-307: address the row directly via `by_doc_version` instead of collecting
|
|
139
172
|
// the whole — unbounded — per-document history and finding in JS. `version` is
|
|
140
173
|
// unique per (collection, docId), so `.unique()` both fetches and asserts that.
|
|
141
|
-
|
|
174
|
+
const row = await ctx.db
|
|
142
175
|
.query('documentVersions')
|
|
143
176
|
.withIndex('by_doc_version', (q) =>
|
|
144
177
|
q.eq('collection', args.collection).eq('docId', args.docId).eq('version', args.version),
|
|
145
178
|
)
|
|
146
179
|
.unique()
|
|
180
|
+
return row ? withUnfoldedSnapshot(row) : row // EC-260: unfold before returning
|
|
147
181
|
},
|
|
148
182
|
})
|
|
149
183
|
|
|
@@ -175,7 +209,8 @@ export const listPublishedDocuments = query({
|
|
|
175
209
|
q.eq('collection', doc.collection).eq('docId', doc.docId).eq('version', version),
|
|
176
210
|
)
|
|
177
211
|
.unique()
|
|
178
|
-
|
|
212
|
+
// EC-260: unfold the pinned snapshot before it leaves the function.
|
|
213
|
+
if (pinned) snapshots.push(unfoldDocument(pinned.snapshot as CmsDocument))
|
|
179
214
|
}
|
|
180
215
|
return snapshots
|
|
181
216
|
},
|
|
@@ -186,7 +221,8 @@ export const listAllDocumentVersions = query({
|
|
|
186
221
|
args: {},
|
|
187
222
|
handler: async (ctx) => {
|
|
188
223
|
await requireCapability(ctx, 'content.read') // EC-150
|
|
189
|
-
|
|
224
|
+
const rows = await ctx.db.query('documentVersions').collect()
|
|
225
|
+
return rows.map(withUnfoldedSnapshot) // EC-260: unfold before returning
|
|
190
226
|
},
|
|
191
227
|
})
|
|
192
228
|
|
|
@@ -208,7 +244,8 @@ export const publishDocumentVersion = mutation({
|
|
|
208
244
|
// write-chokepoint trigger sees — it reindexes the published reference rows
|
|
209
245
|
// and fires host revalidation (EC-146 instant publish). No manual calls here.
|
|
210
246
|
await ctx.db.patch(doc._id, { publishedVersion: args.version, updatedAt: args.updatedAt })
|
|
211
|
-
|
|
247
|
+
const row = await ctx.db.get(doc._id)
|
|
248
|
+
return row ? withUnfoldedDocument(row) : row // EC-260: unfold before returning
|
|
212
249
|
},
|
|
213
250
|
})
|
|
214
251
|
|
|
@@ -225,6 +262,7 @@ export const unpublishDocument = mutation({
|
|
|
225
262
|
// EC-286: clearing the pin is a change the write-chokepoint trigger sees — it
|
|
226
263
|
// drops the published index rows and revalidates the host. No manual calls.
|
|
227
264
|
await ctx.db.patch(doc._id, { publishedVersion: undefined, updatedAt: args.updatedAt })
|
|
228
|
-
|
|
265
|
+
const row = await ctx.db.get(doc._id)
|
|
266
|
+
return row ? withUnfoldedDocument(row) : row // EC-260: unfold before returning
|
|
229
267
|
},
|
|
230
268
|
})
|
package/convex/content.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { documentKey, documentSchema } from '@elytracms/core/cms-core'
|
|
1
|
+
import { documentKey, documentSchema, unfoldValue } from '@elytracms/core/cms-core'
|
|
2
2
|
import type {
|
|
3
3
|
CmsDocument,
|
|
4
4
|
CmsValidationIssue,
|
|
@@ -157,7 +157,9 @@ export async function createContent(
|
|
|
157
157
|
// a published read can serve the *pinned* version rather than the live draft.
|
|
158
158
|
const versionsByKey = new Map<string, Map<number, CmsDocument>>()
|
|
159
159
|
for (const row of await ctx.db.query('documentVersions').collect()) {
|
|
160
|
-
|
|
160
|
+
// EC-260: unfold the folded storage form before parsing — the kit resolves over
|
|
161
|
+
// STRUCTURED values, exactly like the Next-side snapshot (byte-equivalence).
|
|
162
|
+
const parsed = documentSchema.safeParse(unfoldValue(row.snapshot))
|
|
161
163
|
if (!parsed.success) continue
|
|
162
164
|
const key = `${row.collection}:${row.docId}`
|
|
163
165
|
let byVersion = versionsByKey.get(key)
|
|
@@ -176,7 +178,8 @@ export async function createContent(
|
|
|
176
178
|
// resolves exactly as before.
|
|
177
179
|
const parsedSources: { key: string; source: ContentDocumentSource }[] = []
|
|
178
180
|
for (const row of documentRows) {
|
|
179
|
-
|
|
181
|
+
// EC-260: unfold the folded storage form before parsing (see the versions loop).
|
|
182
|
+
const parsed = documentSchema.safeParse(unfoldValue(row.document))
|
|
180
183
|
if (!parsed.success) {
|
|
181
184
|
loadIssues.push({
|
|
182
185
|
code: 'invalid-stored-document',
|
package/convex/delivery.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { v } from 'convex/values'
|
|
2
|
+
import { unfoldValue } from '@elytracms/core/cms-core'
|
|
2
3
|
import { dataSourceSchema } from '@elytracms/core/data-binding'
|
|
3
4
|
import { query } from './functions'
|
|
4
5
|
import type { QueryCtx } from './functions'
|
|
@@ -134,6 +135,10 @@ export async function loadSnapshot(
|
|
|
134
135
|
const { projectId } = args
|
|
135
136
|
|
|
136
137
|
const documentRows = await ctx.db.query('cmsDocuments').collect()
|
|
138
|
+
// EC-260: the stored `document`/`snapshot` blobs are folded; unfold every one
|
|
139
|
+
// before it enters the delivery snapshot so the host receives STRUCTURED content
|
|
140
|
+
// (no client ever sees an envelope). `unfoldValue` is identity on legacy data.
|
|
141
|
+
const unfoldDraft = (row: { document: unknown }): unknown => unfoldValue(row.document)
|
|
137
142
|
// THE published-content invariant (the trust boundary): the public snapshot
|
|
138
143
|
// ships ONLY published content — never a draft. Under the EC-224 pointer model
|
|
139
144
|
// a published row is served as its *pinned version snapshot* (decoupled from
|
|
@@ -142,7 +147,7 @@ export async function loadSnapshot(
|
|
|
142
147
|
// fallback (the `state` field is gone).
|
|
143
148
|
let documents: unknown[]
|
|
144
149
|
if (perspective === 'draft') {
|
|
145
|
-
documents = documentRows.map(
|
|
150
|
+
documents = documentRows.map(unfoldDraft)
|
|
146
151
|
} else {
|
|
147
152
|
documents = []
|
|
148
153
|
for (const row of documentRows) {
|
|
@@ -160,7 +165,7 @@ export async function loadSnapshot(
|
|
|
160
165
|
q.eq('collection', row.collection).eq('docId', row.docId).eq('version', version),
|
|
161
166
|
)
|
|
162
167
|
.unique()
|
|
163
|
-
if (pinned) documents.push(pinned.snapshot
|
|
168
|
+
if (pinned) documents.push(unfoldValue(pinned.snapshot))
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
|
|
@@ -202,9 +207,7 @@ export async function loadSnapshot(
|
|
|
202
207
|
// extracted from every stored row (independent of publish state) — published
|
|
203
208
|
// bindings must always resolve their definitions, even when the defining
|
|
204
209
|
// `cms-data-sources` row is not itself "published".
|
|
205
|
-
const sources = dataSourcesFromSystemCollection(
|
|
206
|
-
documentRows.map((row) => row.document as unknown),
|
|
207
|
-
)
|
|
210
|
+
const sources = dataSourcesFromSystemCollection(documentRows.map(unfoldDraft))
|
|
208
211
|
|
|
209
212
|
// Editorial redirects (EC-303): only ENABLED entries serve — a disabled redirect
|
|
210
213
|
// is stored but never live, in either perspective. Projected to the routing
|
package/convex/triggers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unfoldDocument } from '@elytracms/core/cms-core'
|
|
1
2
|
import type { CmsDocument } from '@elytracms/core/cms-core'
|
|
2
3
|
import { Triggers } from 'convex-helpers/server/triggers'
|
|
3
4
|
import type { DataModel } from './functions'
|
|
@@ -42,11 +43,17 @@ triggers.register('cmsDocuments', async (ctx, change) => {
|
|
|
42
43
|
return
|
|
43
44
|
}
|
|
44
45
|
const doc = change.newDoc
|
|
46
|
+
// EC-260: the stored `document` is FOLDED (deep field values collapsed to leaf
|
|
47
|
+
// envelopes). Unfold it here so `extractReferences` walks the STRUCTURED value and
|
|
48
|
+
// still finds references buried inside a folded field — this is the write chokepoint
|
|
49
|
+
// (EC-286), so every writer's references are derived from structured content by
|
|
50
|
+
// construction, regardless of the folded storage form. `unfoldDocument` is identity
|
|
51
|
+
// on already-structural data, so a legacy unfolded row costs nothing.
|
|
45
52
|
await maintainDocumentReferences(
|
|
46
53
|
ctx,
|
|
47
54
|
doc.collection,
|
|
48
55
|
doc.docId,
|
|
49
|
-
doc.document as CmsDocument,
|
|
56
|
+
unfoldDocument(doc.document as CmsDocument),
|
|
50
57
|
doc.publishedVersion !== undefined,
|
|
51
58
|
)
|
|
52
59
|
const before = change.oldDoc?.publishedVersion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { FieldDef } from '@elytracms/core/cms-core';
|
|
3
3
|
import type { StudioI18nConfig } from '@elytracms/studio/lib/i18n';
|
|
4
|
+
import type { StudioAiConfig } from '@elytracms/studio/lib/ai';
|
|
4
5
|
import type { SidebarNode } from './module';
|
|
5
6
|
/**
|
|
6
7
|
* EC-236 — the studio customization config: the single, studio-only home for
|
|
@@ -47,6 +48,17 @@ export interface StudioConfig {
|
|
|
47
48
|
* `LocalizedString` on the field/collection def.
|
|
48
49
|
*/
|
|
49
50
|
i18n?: StudioI18nConfig;
|
|
51
|
+
/**
|
|
52
|
+
* AI platform (EC-331): provider, project knowledge, and soft limits. The block's
|
|
53
|
+
* PRESENCE enables the AI feature; its ABSENCE means the feature is fully absent —
|
|
54
|
+
* no AI UI and no AI dependencies on the critical path (the runtime lives behind a
|
|
55
|
+
* lazy boundary in `@elytracms/studio/lib/ai`, only reached when configured).
|
|
56
|
+
* `enabled: false` is a temporary kill-switch. Studio-only live code (holds the
|
|
57
|
+
* provider adapter + knowledge functions) — never reaches the delivery bundle.
|
|
58
|
+
* Validated at load by `resolveAiConfig` (capability gate: tool calling + structured
|
|
59
|
+
* output required, fail-loud).
|
|
60
|
+
*/
|
|
61
|
+
ai?: StudioAiConfig;
|
|
50
62
|
}
|
|
51
63
|
/** The props a custom field renderer receives — identical to the built-in control. */
|
|
52
64
|
export interface CustomFieldRendererProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio-config.js","sourceRoot":"","sources":["../../../src/components/app-views/studio-config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"studio-config.js","sourceRoot":"","sources":["../../../src/components/app-views/studio-config.ts"],"names":[],"mappings":"AA0EA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB;IAC/C,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import type { ReactNode } from 'react'\nimport type { FieldDef } from '@elytracms/core/cms-core'\nimport type { StudioI18nConfig } from '@elytracms/studio/lib/i18n'\nimport type { StudioAiConfig } from '@elytracms/studio/lib/ai'\nimport type { SidebarNode } from './module'\n\n/**\n * EC-236 — the studio customization config: the single, studio-only home for\n * everything a consuming repo customizes about the builder UI.\n *\n * This is the \"separate studio-only config solution\": it lives in the consumer's\n * `studio.config.tsx`, is `defineStudio({...})`-typed, and is passed to\n * `createStudio(config, studioConfig)` at the mount — NEVER mixed into the shared\n * `elytra.config.ts`, so the live React it carries (views, icons, field renderers,\n * future branding) never reaches the `frontend/` delivery bundle.\n *\n * The customization PRINCIPLE it embodies: customization is **code passed\n * directly**, not data referenced by a string key. Every field here holds live\n * values/components by reference — `sidebar` is built from `nav.*` view objects,\n * `fieldRenderers` maps a control name to a component. The only string indirection\n * in the whole surface is `fieldRenderers`' key, and ONLY because its other end\n * (`form.control` on a field) lives in the delivery-shared serializable schema and\n * cannot import studio code. This config grows by adding direct-value keys\n * (branding/logo/panels/theme), never by adding registries.\n */\nexport interface StudioConfig {\n /**\n * The section rail (EC-237) as an ordered list of `nav.*` nodes — views, groups,\n * and separators. Omitted → the studio derives the default rail from its built-in\n * views. A rail node carries its view object directly; there are no string ids to\n * keep in sync.\n */\n sidebar?: SidebarNode[]\n /**\n * Custom field renderers (EC-238) keyed by CONTROL name (`form.control`), each a\n * React component replacing the built-in document-editor control. A field opts in\n * per-field via `form: { control: '<name>' }` — so a renderer targets exactly the\n * fields that ask for it, not every field of a datatype. This is the one\n * boundary-crossing seam: the field names its control by string in the shared\n * schema, this map binds that name to a studio-only component.\n */\n fieldRenderers?: Record<string, CustomFieldRenderer>\n /**\n * Studio-UI localization (EC-241): the default locale + imported translation\n * catalogs. English is the built-in source; a consumer adds e.g.\n * `i18n: { locales: { de: deMessages } }` and the studio chrome renders in the\n * browser's preferred locale (no persisted selector in v1). Studio-only — never\n * reaches the delivery bundle. Schema labels localize separately, via a\n * `LocalizedString` on the field/collection def.\n */\n i18n?: StudioI18nConfig\n /**\n * AI platform (EC-331): provider, project knowledge, and soft limits. The block's\n * PRESENCE enables the AI feature; its ABSENCE means the feature is fully absent —\n * no AI UI and no AI dependencies on the critical path (the runtime lives behind a\n * lazy boundary in `@elytracms/studio/lib/ai`, only reached when configured).\n * `enabled: false` is a temporary kill-switch. Studio-only live code (holds the\n * provider adapter + knowledge functions) — never reaches the delivery bundle.\n * Validated at load by `resolveAiConfig` (capability gate: tool calling + structured\n * output required, fail-loud).\n */\n ai?: StudioAiConfig\n}\n\n/** The props a custom field renderer receives — identical to the built-in control. */\nexport interface CustomFieldRendererProps {\n field: FieldDef\n value: unknown\n onChange: (value: unknown) => void\n readOnly: boolean\n id: string\n}\nexport type CustomFieldRenderer = (props: CustomFieldRendererProps) => ReactNode\n\n/**\n * Typed identity helper for `studio.config.tsx` — keeps the config declarative\n * (like {@link import('@elytracms/core/studio-core').defineElytraConfig}). No\n * validation here; the studio resolves + validates the sidebar and field renderers\n * through the EC-236 seam at mount, surfacing every issue visibly (never throws).\n *\n * @example\n * ```tsx\n * // studio.config.tsx\n * import { defineStudio, nav } from '@elytracms/studio/customization'\n * import { ColorField } from './fields/color'\n *\n * export default defineStudio({\n * sidebar: [\n * nav.cms({ label: 'Content' }),\n * nav.group('Catalog', [\n * nav.cms({ label: 'Catalog', collections: ['product', 'productCategory'] }),\n * nav.cms({ label: 'Categories', collection: 'productCategory' }),\n * ]),\n * nav.separator(),\n * nav.assets(),\n * nav.settings(),\n * ],\n * fieldRenderers: { color: ColorField },\n * })\n * ```\n */\nexport function defineStudio(config: StudioConfig): StudioConfig {\n return config\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { CmsDocument, CollectionDef } from '@elytracms/core/cms-core';
|
|
2
2
|
import type { AssetRecord } from '@elytracms/core/persistence';
|
|
3
|
-
import type {
|
|
3
|
+
import type { OperationError } from '@elytracms/core/operations';
|
|
4
|
+
import type { DeleteAssetResult } from '@elytracms/studio/lib/assets';
|
|
5
|
+
import type { CollectionViewSource, CollectionViewCapabilities } from '@elytracms/studio/lib/collection-view/collection-view-source';
|
|
4
6
|
/**
|
|
5
7
|
* The capability profile of the assets rail (EC-319). Hoisted to a module-level
|
|
6
8
|
* constant (no prop/state dependency) so it's both the value the hook returns
|
|
@@ -38,6 +40,12 @@ export declare function assetToDocument(collection: CollectionDef, record: Asset
|
|
|
38
40
|
* never written here.
|
|
39
41
|
*/
|
|
40
42
|
export declare function documentToAssetMetaPatch(collection: CollectionDef, doc: CmsDocument): Record<string, unknown>;
|
|
43
|
+
/** Assets' `remove()` returns an `outcome`-discriminated {@link DeleteAssetResult}
|
|
44
|
+
* (not the `{ ok }` shape users/redirects use, EC-327): only `'error'` is a
|
|
45
|
+
* failure the shell surfaces via `lastError`. `'blocked'`/`'not-found'` are
|
|
46
|
+
* unreached from this rail's UI (`capabilities.remove === false`) but handled
|
|
47
|
+
* soundly regardless, matching the pre-EC-327 behaviour exactly. */
|
|
48
|
+
export declare function normalizeAssetRemoveResult(result: DeleteAssetResult): OperationError | null;
|
|
41
49
|
/**
|
|
42
50
|
* Assemble a {@link CollectionViewSource} for the **assets rail** (EC-319) — the
|
|
43
51
|
* portable list surface over the existing asset library store instead of a
|
|
@@ -50,5 +58,9 @@ export declare function documentToAssetMetaPatch(collection: CollectionDef, doc:
|
|
|
50
58
|
*
|
|
51
59
|
* Must be mounted under an `<AssetsProvider>` (for {@link useAssets}) — already
|
|
52
60
|
* ambient at the project level (EC-195), so callers rarely mount their own.
|
|
61
|
+
*
|
|
62
|
+
* The shared scaffold (`useRailViewSource`, EC-327) owns `viewState`/`lastError`
|
|
63
|
+
* plumbing and the assembled source; this hook supplies only the asset-store
|
|
64
|
+
* reads/writes, the capability profile, and the projections above.
|
|
53
65
|
*/
|
|
54
66
|
export declare function useAssetsCollectionViewSource(projectId: string, schema: CollectionDef): CollectionViewSource;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useCallback, useMemo
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { createCollectionRegistry, validateDocument } from '@elytracms/core/cms-core';
|
|
3
3
|
import { studioPath } from '@elytracms/studio/router';
|
|
4
|
-
import { defaultViewState } from '@elytracms/studio/lib/cms-views';
|
|
5
4
|
import { useAssets } from './assets-store';
|
|
6
5
|
import { SYSTEM_ASSET_FIELDS } from './asset-metadata';
|
|
6
|
+
import { normalizeOkResult, useRailViewSource } from '../rail-view-source';
|
|
7
7
|
/** The assets rail is not localized in v1 (EC-301: asset metadata is non-localized). */
|
|
8
8
|
const ASSETS_LOCALE = 'en';
|
|
9
9
|
const ASSETS_LOCALE_CONFIG = {
|
|
@@ -105,6 +105,19 @@ export function documentToAssetMetaPatch(collection, doc) {
|
|
|
105
105
|
}
|
|
106
106
|
return meta;
|
|
107
107
|
}
|
|
108
|
+
/** `create` when `capabilities.create === false` — never reached from the UI
|
|
109
|
+
* (list/detail never call it); an explicit throw rather than a silent no-op. */
|
|
110
|
+
function createUnsupported() {
|
|
111
|
+
throw new Error('assets are created by upload, not the assets rail');
|
|
112
|
+
}
|
|
113
|
+
/** Assets' `remove()` returns an `outcome`-discriminated {@link DeleteAssetResult}
|
|
114
|
+
* (not the `{ ok }` shape users/redirects use, EC-327): only `'error'` is a
|
|
115
|
+
* failure the shell surfaces via `lastError`. `'blocked'`/`'not-found'` are
|
|
116
|
+
* unreached from this rail's UI (`capabilities.remove === false`) but handled
|
|
117
|
+
* soundly regardless, matching the pre-EC-327 behaviour exactly. */
|
|
118
|
+
export function normalizeAssetRemoveResult(result) {
|
|
119
|
+
return result.outcome === 'error' ? { code: 'unknown', message: result.message } : null;
|
|
120
|
+
}
|
|
108
121
|
/**
|
|
109
122
|
* Assemble a {@link CollectionViewSource} for the **assets rail** (EC-319) — the
|
|
110
123
|
* portable list surface over the existing asset library store instead of a
|
|
@@ -117,11 +130,13 @@ export function documentToAssetMetaPatch(collection, doc) {
|
|
|
117
130
|
*
|
|
118
131
|
* Must be mounted under an `<AssetsProvider>` (for {@link useAssets}) — already
|
|
119
132
|
* ambient at the project level (EC-195), so callers rarely mount their own.
|
|
133
|
+
*
|
|
134
|
+
* The shared scaffold (`useRailViewSource`, EC-327) owns `viewState`/`lastError`
|
|
135
|
+
* plumbing and the assembled source; this hook supplies only the asset-store
|
|
136
|
+
* reads/writes, the capability profile, and the projections above.
|
|
120
137
|
*/
|
|
121
138
|
export function useAssetsCollectionViewSource(projectId, schema) {
|
|
122
139
|
const store = useAssets();
|
|
123
|
-
const [viewState, setViewStateRaw] = useState(() => defaultViewState(schema));
|
|
124
|
-
const [lastError, setLastError] = useState(null);
|
|
125
140
|
const registry = useMemo(() => createCollectionRegistry([schema]), [schema]);
|
|
126
141
|
const documents = useCallback(() => store.assets.map((record) => assetToDocument(schema, record)), [store.assets, schema]);
|
|
127
142
|
const get = useCallback((ref) => {
|
|
@@ -132,55 +147,31 @@ export function useAssetsCollectionViewSource(projectId, schema) {
|
|
|
132
147
|
const record = store.assets.find((a) => a.id === ref.id);
|
|
133
148
|
return record?.title ?? record?.filename ?? ref.id;
|
|
134
149
|
}, [store.assets]);
|
|
135
|
-
const
|
|
136
|
-
|
|
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]);
|
|
150
|
+
const validate = useCallback((doc) => validateDocument(registry, doc, { localeConfig: ASSETS_LOCALE_CONFIG }), [registry]);
|
|
151
|
+
const save = useCallback((doc) => store.updateMetadata(doc.id, { meta: documentToAssetMetaPatch(schema, doc) }), [schema, store]);
|
|
145
152
|
// Unreached from the UI (`capabilities.remove === false`); implemented soundly
|
|
146
153
|
// (the same checked delete the store always runs) in case anything ever calls
|
|
147
154
|
// it directly, rather than throwing.
|
|
148
|
-
const remove = useCallback((ref) =>
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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]);
|
|
155
|
+
const remove = useCallback((ref) => store.remove(ref.id), [store]);
|
|
156
|
+
return useRailViewSource({
|
|
157
|
+
projectId,
|
|
158
|
+
schema,
|
|
159
|
+
capabilities: ASSET_COLLECTION_CAPABILITIES,
|
|
160
|
+
localeConfig: ASSETS_LOCALE_CONFIG,
|
|
161
|
+
documents,
|
|
162
|
+
get,
|
|
163
|
+
titleOf,
|
|
164
|
+
// No `referenceCandidates`/`collections`/`isFieldReadOnly` override: assets carry
|
|
165
|
+
// no relation/asset fields of their own (v1) — nothing cross-collection to
|
|
166
|
+
// resolve — and read-only follows the factory's default `form.readOnly` check.
|
|
167
|
+
detailPath: (id) => studioPath.asset(id),
|
|
168
|
+
listPath: studioPath.assets(),
|
|
169
|
+
validate,
|
|
170
|
+
create: createUnsupported,
|
|
171
|
+
save,
|
|
172
|
+
remove,
|
|
173
|
+
normalizeSaveResult: normalizeOkResult,
|
|
174
|
+
normalizeRemoveResult: normalizeAssetRemoveResult,
|
|
175
|
+
});
|
|
185
176
|
}
|
|
186
177
|
//# sourceMappingURL=assets-collection-view-source.js.map
|
|
@@ -1 +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,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,KAAK;IACjB,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK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,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"]}
|
|
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,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAGrF,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAGrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE1E,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,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,KAAK;IACjB,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,KAAK;IACX,OAAO,EAAE,KAAK;IACd,SAAS,EAAE,KAAK;IAChB,YAAY,EAAE,KAAK;IACnB,SAAS,EAAE,KAAK;CACjB,CAAA;AAED,4EAA4E;AAC5E,SAAS,gBAAgB,CAAC,MAAmB,EAAE,IAAY;IACzD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,UAAU;YACb,OAAO,MAAM,CAAC,QAAQ,CAAA;QACxB,KAAK,KAAK;YACR,OAAO,MAAM,CAAC,GA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AqC;IACrC,MAAM,MAAM,GAAG,WAAW,CAAC,CAAC,GAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAE/E,OAAO,iBAAiB,CAAC;QACvB,SAAS;QACT,MAAM;QACN,YAAY,EAAE,6BAA6B;QAC3C,YAAY,EAAE,oBAAoB;QAClC,SAAS;QACT,GAAG;QACH,OAAO;QACP,kFAAkF;QAClF,2EAA2E;QAC3E,+EAA+E;QAC/E,UAAU,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,QAAQ,EAAE,UAAU,CAAC,MAAM,EAAE;QAC7B,QAAQ;QACR,MAAM,EAAE,iBAAiB;QACzB,IAAI;QACJ,MAAM;QACN,mBAAmB,EAAE,iBAAiB;QACtC,qBAAqB,EAAE,0BAA0B;KAClD,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { useCallback, useMemo } from 'react'\nimport type { CmsDocument, CollectionDef, DocumentRef, Locale, LocaleConfig } 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 type { DeleteAssetResult } from '@elytracms/studio/lib/assets'\nimport type { CollectionViewSource, CollectionViewCapabilities } from '@elytracms/studio/lib/collection-view/collection-view-source'\nimport { useAssets } from './assets-store'\nimport { SYSTEM_ASSET_FIELDS } from './asset-metadata'\nimport { normalizeOkResult, useRailViewSource } from '../rail-view-source'\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/** `create` when `capabilities.create === false` — never reached from the UI\n * (list/detail never call it); an explicit throw rather than a silent no-op. */\nfunction createUnsupported(): DocumentRef {\n throw new Error('assets are created by upload, not the assets rail')\n}\n\n/** Assets' `remove()` returns an `outcome`-discriminated {@link DeleteAssetResult}\n * (not the `{ ok }` shape users/redirects use, EC-327): only `'error'` is a\n * failure the shell surfaces via `lastError`. `'blocked'`/`'not-found'` are\n * unreached from this rail's UI (`capabilities.remove === false`) but handled\n * soundly regardless, matching the pre-EC-327 behaviour exactly. */\nexport function normalizeAssetRemoveResult(result: DeleteAssetResult): OperationError | null {\n return result.outcome === 'error' ? { code: 'unknown', message: result.message } : null\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 *\n * The shared scaffold (`useRailViewSource`, EC-327) owns `viewState`/`lastError`\n * plumbing and the assembled source; this hook supplies only the asset-store\n * reads/writes, the capability profile, and the projections above.\n */\nexport function useAssetsCollectionViewSource(\n projectId: string,\n schema: CollectionDef,\n): CollectionViewSource {\n const store = useAssets()\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 validate = useCallback(\n (doc: CmsDocument) => validateDocument(registry, doc, { localeConfig: ASSETS_LOCALE_CONFIG }),\n [registry],\n )\n const save = useCallback(\n (doc: CmsDocument) => store.updateMetadata(doc.id, { meta: documentToAssetMetaPatch(schema, doc) }),\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((ref: DocumentRef) => store.remove(ref.id), [store])\n\n return useRailViewSource({\n projectId,\n schema,\n capabilities: ASSET_COLLECTION_CAPABILITIES,\n localeConfig: ASSETS_LOCALE_CONFIG,\n documents,\n get,\n titleOf,\n // No `referenceCandidates`/`collections`/`isFieldReadOnly` override: assets carry\n // no relation/asset fields of their own (v1) — nothing cross-collection to\n // resolve — and read-only follows the factory's default `form.readOnly` check.\n detailPath: (id: string) => studioPath.asset(id),\n listPath: studioPath.assets(),\n validate,\n create: createUnsupported,\n save,\n remove,\n normalizeSaveResult: normalizeOkResult,\n normalizeRemoveResult: normalizeAssetRemoveResult,\n })\n}\n"]}
|
|
@@ -11,7 +11,7 @@ import { createRequiredContext } from '@elytracms/studio/lib/required-context';
|
|
|
11
11
|
import { createCmsPersister, getStudioOperations } from '@elytracms/studio/lib/operations';
|
|
12
12
|
import { ALL_VIEW_ID, canonicalViewState, configViewsFor, defaultViewState, viewStatesEqual, } from '@elytracms/studio/lib/cms-views';
|
|
13
13
|
import { useOptionalAssets } from '../assets/assets-store';
|
|
14
|
-
import {
|
|
14
|
+
import { consumeStagedDocuments } from './document-staging';
|
|
15
15
|
import { applyCellValue, commitCellEdit } from './cell-edit';
|
|
16
16
|
import { runBulkAction } from './bulk-actions';
|
|
17
17
|
const { Context: CmsContext, useRequired: useCms } = createRequiredContext('Cms');
|
|
@@ -83,16 +83,14 @@ function defaultView(collection) {
|
|
|
83
83
|
export function CmsProvider({ children, projectId, initialCollections, initialDocuments, initialPublishedKeys, initialLocaleConfig, }) {
|
|
84
84
|
const [documents, setDocuments] = useState(() => {
|
|
85
85
|
const seeded = (initialDocuments ?? sampleDocuments).map((d) => structuredClone(d));
|
|
86
|
-
// EC-320: merge any documents STAGED by the
|
|
87
|
-
// transfer
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
byKey.set(`${d.collection}/${d.id}`, d);
|
|
95
|
-
return [...byKey.values()];
|
|
86
|
+
// EC-320 (0.0.44 follow-up): merge any documents STAGED by the
|
|
87
|
+
// Components-view "Use in document…" transfer — a cross-mount handoff in
|
|
88
|
+
// EVERY mode now (see document-staging.ts), not just the playground. The
|
|
89
|
+
// merge rule itself stays mode-aware there: playground's seeded set is a
|
|
90
|
+
// static baseline that never reflects a write (staged always wins);
|
|
91
|
+
// Convex's is a fresh per-mount hydration query (staged fills gaps only,
|
|
92
|
+
// dropped once the seeded set actually carries the key).
|
|
93
|
+
return consumeStagedDocuments(projectId, seeded);
|
|
96
94
|
});
|
|
97
95
|
// Published-ness as the version POINTER (EC-224), decoupled from the flat
|
|
98
96
|
// `state` enum: seeded from hydration's pointer set, or — when none is supplied
|