@elytracms/studio 0.0.94 → 0.0.96

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.
Files changed (164) hide show
  1. package/convex/asset-alt-migration.test.ts +2 -2
  2. package/convex/asset-meta-patch.test.ts +218 -0
  3. package/convex/asset-replace-delete-race.test.ts +127 -0
  4. package/convex/assets.ts +27 -2
  5. package/convex/cms.ts +124 -8
  6. package/convex/delivery-redirects.test.ts +167 -0
  7. package/convex/delivery.ts +15 -5
  8. package/convex/rail-write-parity.test.ts +6 -6
  9. package/convex/redirects.ts +1 -1
  10. package/convex/schema.ts +6 -0
  11. package/convex/strict-reference-race.test.ts +139 -0
  12. package/dist/addon.d.ts +1 -1
  13. package/dist/addon.js.map +1 -1
  14. package/dist/components/ai/ai-chat-panel.js +15 -2
  15. package/dist/components/ai/ai-chat-panel.js.map +1 -1
  16. package/dist/components/ai/translate-document-action.d.ts +6 -0
  17. package/dist/components/ai/translate-document-action.js.map +1 -1
  18. package/dist/components/ai/translate-document-dialog.d.ts +1 -1
  19. package/dist/components/ai/translate-document-dialog.js +5 -5
  20. package/dist/components/ai/translate-document-dialog.js.map +1 -1
  21. package/dist/components/assets/asset-detail.js +29 -11
  22. package/dist/components/assets/asset-detail.js.map +1 -1
  23. package/dist/components/assets/asset-locale.d.ts +16 -0
  24. package/dist/components/assets/asset-locale.js +30 -0
  25. package/dist/components/assets/asset-locale.js.map +1 -0
  26. package/dist/components/assets/asset-meta-drift-notice.d.ts +13 -0
  27. package/dist/components/assets/asset-meta-drift-notice.js +22 -0
  28. package/dist/components/assets/asset-meta-drift-notice.js.map +1 -0
  29. package/dist/components/assets/asset-meta-label.d.ts +13 -0
  30. package/dist/components/assets/asset-meta-label.js +17 -0
  31. package/dist/components/assets/asset-meta-label.js.map +1 -0
  32. package/dist/components/assets/asset-metadata.d.ts +89 -15
  33. package/dist/components/assets/asset-metadata.js +123 -11
  34. package/dist/components/assets/asset-metadata.js.map +1 -1
  35. package/dist/components/assets/asset-search.d.ts +6 -2
  36. package/dist/components/assets/asset-search.js +19 -3
  37. package/dist/components/assets/asset-search.js.map +1 -1
  38. package/dist/components/assets/asset-thumb.js +6 -2
  39. package/dist/components/assets/asset-thumb.js.map +1 -1
  40. package/dist/components/assets/assets-collection-view-source.d.ts +25 -9
  41. package/dist/components/assets/assets-collection-view-source.js +80 -26
  42. package/dist/components/assets/assets-collection-view-source.js.map +1 -1
  43. package/dist/components/assets/assets-store.js +17 -4
  44. package/dist/components/assets/assets-store.js.map +1 -1
  45. package/dist/components/builder/builder-store.d.ts +21 -0
  46. package/dist/components/builder/builder-store.js +22 -0
  47. package/dist/components/builder/builder-store.js.map +1 -1
  48. package/dist/components/builder/canvas-commit-boundary.d.ts +22 -0
  49. package/dist/components/builder/canvas-commit-boundary.js +27 -0
  50. package/dist/components/builder/canvas-commit-boundary.js.map +1 -0
  51. package/dist/components/builder/canvas-rebase.d.ts +101 -0
  52. package/dist/components/builder/canvas-rebase.js +179 -0
  53. package/dist/components/builder/canvas-rebase.js.map +1 -0
  54. package/dist/components/builder/canvas-render-context.d.ts +6 -3
  55. package/dist/components/builder/canvas-render-context.js +17 -8
  56. package/dist/components/builder/canvas-render-context.js.map +1 -1
  57. package/dist/components/builder/composition-field-editor.d.ts +26 -2
  58. package/dist/components/builder/composition-field-editor.js +46 -27
  59. package/dist/components/builder/composition-field-editor.js.map +1 -1
  60. package/dist/components/builder/node-factory.js +15 -3
  61. package/dist/components/builder/node-factory.js.map +1 -1
  62. package/dist/components/builder/property-inspector.js +3 -1
  63. package/dist/components/builder/property-inspector.js.map +1 -1
  64. package/dist/components/builder/run-inspector.js +10 -6
  65. package/dist/components/builder/run-inspector.js.map +1 -1
  66. package/dist/components/cms/asset-field.d.ts +5 -2
  67. package/dist/components/cms/asset-field.js +34 -17
  68. package/dist/components/cms/asset-field.js.map +1 -1
  69. package/dist/components/cms/asset-picker-core.d.ts +2 -2
  70. package/dist/components/cms/asset-picker-core.js +2 -2
  71. package/dist/components/cms/asset-picker-core.js.map +1 -1
  72. package/dist/components/cms/asset-picker.js +6 -2
  73. package/dist/components/cms/asset-picker.js.map +1 -1
  74. package/dist/components/cms/canvas-commit.d.ts +62 -0
  75. package/dist/components/cms/canvas-commit.js +39 -0
  76. package/dist/components/cms/canvas-commit.js.map +1 -0
  77. package/dist/components/cms/cms-store.d.ts +21 -8
  78. package/dist/components/cms/cms-store.js +19 -10
  79. package/dist/components/cms/cms-store.js.map +1 -1
  80. package/dist/components/cms/collection-table.js +27 -18
  81. package/dist/components/cms/collection-table.js.map +1 -1
  82. package/dist/components/cms/commit-policy.d.ts +6 -2
  83. package/dist/components/cms/commit-policy.js +1 -1
  84. package/dist/components/cms/commit-policy.js.map +1 -1
  85. package/dist/components/cms/detail-editor.js +12 -2
  86. package/dist/components/cms/detail-editor.js.map +1 -1
  87. package/dist/components/cms/draft-commit.d.ts +16 -3
  88. package/dist/components/cms/draft-commit.js +3 -2
  89. package/dist/components/cms/draft-commit.js.map +1 -1
  90. package/dist/components/cms/use-document-draft.d.ts +121 -5
  91. package/dist/components/cms/use-document-draft.js +197 -54
  92. package/dist/components/cms/use-document-draft.js.map +1 -1
  93. package/dist/components/cms/use-live-url.d.ts +6 -1
  94. package/dist/components/cms/use-live-url.js +12 -9
  95. package/dist/components/cms/use-live-url.js.map +1 -1
  96. package/dist/components/collection-view/cms-collection-view-source.js +11 -5
  97. package/dist/components/collection-view/cms-collection-view-source.js.map +1 -1
  98. package/dist/components/components/transfer-dialog.js +6 -4
  99. package/dist/components/components/transfer-dialog.js.map +1 -1
  100. package/dist/components/deployment-setup-gate.js +10 -1
  101. package/dist/components/deployment-setup-gate.js.map +1 -1
  102. package/dist/components/records/record-lens.js +3 -8
  103. package/dist/components/records/record-lens.js.map +1 -1
  104. package/dist/lib/ai/chat-state.d.ts +7 -0
  105. package/dist/lib/ai/chat-state.js.map +1 -1
  106. package/dist/lib/ai/tools.d.ts +8 -0
  107. package/dist/lib/ai/tools.js +4 -0
  108. package/dist/lib/ai/tools.js.map +1 -1
  109. package/dist/lib/assets/upload.d.ts +25 -7
  110. package/dist/lib/assets/upload.js +30 -21
  111. package/dist/lib/assets/upload.js.map +1 -1
  112. package/dist/lib/cms/published-documents.d.ts +24 -6
  113. package/dist/lib/cms/published-documents.js +39 -6
  114. package/dist/lib/cms/published-documents.js.map +1 -1
  115. package/dist/lib/cms-views/view-model.d.ts +25 -105
  116. package/dist/lib/cms-views/view-model.js +36 -103
  117. package/dist/lib/cms-views/view-model.js.map +1 -1
  118. package/dist/lib/collection-view/__fixtures__/document-writes.js +1 -0
  119. package/dist/lib/collection-view/__fixtures__/document-writes.js.map +1 -1
  120. package/dist/lib/collection-view/collection-view-source.d.ts +21 -8
  121. package/dist/lib/collection-view/collection-view-source.js.map +1 -1
  122. package/dist/lib/data/collection-content.js +5 -0
  123. package/dist/lib/data/collection-content.js.map +1 -1
  124. package/dist/lib/engine-version.d.ts +1 -1
  125. package/dist/lib/engine-version.js +1 -1
  126. package/dist/lib/engine-version.js.map +1 -1
  127. package/dist/lib/i18n/messages.de.js +20 -4
  128. package/dist/lib/i18n/messages.de.js.map +1 -1
  129. package/dist/lib/i18n/messages.en.d.ts +16 -1
  130. package/dist/lib/i18n/messages.en.js +22 -5
  131. package/dist/lib/i18n/messages.en.js.map +1 -1
  132. package/dist/lib/operations/cms-persistence.d.ts +80 -35
  133. package/dist/lib/operations/cms-persistence.js +348 -85
  134. package/dist/lib/operations/cms-persistence.js.map +1 -1
  135. package/dist/lib/operations/config-manifest-lookup.d.ts +1 -1
  136. package/dist/lib/operations/config-manifest-lookup.js +3 -3
  137. package/dist/lib/operations/config-manifest-lookup.js.map +1 -1
  138. package/dist/lib/persistence/convex-adapter.js +54 -8
  139. package/dist/lib/persistence/convex-adapter.js.map +1 -1
  140. package/dist/lib/persistence/deployment-readiness.js +14 -11
  141. package/dist/lib/persistence/deployment-readiness.js.map +1 -1
  142. package/dist/lib/persona/labels.js +2 -0
  143. package/dist/lib/persona/labels.js.map +1 -1
  144. package/dist/lib/query/index.d.ts +2 -2
  145. package/dist/lib/query/index.js +1 -1
  146. package/dist/lib/query/index.js.map +1 -1
  147. package/dist/lib/query/operations-query.d.ts +26 -0
  148. package/dist/lib/query/operations-query.js +12 -0
  149. package/dist/lib/query/operations-query.js.map +1 -1
  150. package/dist/lib/registry/index.js +2 -2
  151. package/dist/lib/registry/index.js.map +1 -1
  152. package/dist/lib/registry/preview.d.ts +10 -0
  153. package/dist/lib/registry/preview.js +13 -4
  154. package/dist/lib/registry/preview.js.map +1 -1
  155. package/dist/lib/routes/route-issues.js +6 -3
  156. package/dist/lib/routes/route-issues.js.map +1 -1
  157. package/dist/lib/workspace/workspace-source.js +6 -7
  158. package/dist/lib/workspace/workspace-source.js.map +1 -1
  159. package/dist/previews/entry-node.d.ts +14 -0
  160. package/dist/previews/entry-node.js +22 -0
  161. package/dist/previews/entry-node.js.map +1 -0
  162. package/dist/previews/harness.js +2 -16
  163. package/dist/previews/harness.js.map +1 -1
  164. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"asset-metadata.js","sourceRoot":"","sources":["../../../src/components/assets/asset-metadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAG3D;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IAC9D,UAAU;IACV,KAAK;IACL,aAAa;IACb,UAAU;IACV,OAAO;IACP,QAAQ;IACR,YAAY;IACZ,OAAO;CACR,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAyB;IACzD,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAA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AK,EAAE,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAA;AACH,CAAC;AAMD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAiC,EACjC,SAAiB,EACjB,OAAe,EACf,KAAyB;IAEzB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;QAC1F,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;IACvF,CAAC;AACH,CAAC","sourcesContent":["import type { CollectionDef, FieldDef } from '@elytracms/core/cms-core'\nimport { liftLegacyAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord, AssetRepository, AssetWriteInput } from '@elytracms/core/persistence'\n\n/**\n * Asset metadata editing (EC-152). A patch is applied through the\n * {@link AssetRepository} interface — in the studio that is the EC-141\n * operations facade, so every edit runs the `assets.upsert` command\n * (validate → authorize → mutate → event). Pure orchestration; injectable\n * for tests.\n */\n\n/**\n * System columns the upload pipeline owns — never editable metadata, so they're\n * excluded from the asset collection's schema-driven forms: the image field's\n * options dialog (EC-301, `field-control.tsx`) and the assets rail's detail\n * surface (EC-319, `asset-detail.tsx`) share this ONE reserved set so neither\n * drifts from the other. Everything else a project declares on the `kind:'asset'`\n * collection round-trips through the record's open `meta` bag.\n */\nexport const SYSTEM_ASSET_FIELDS: ReadonlySet<string> = new Set([\n 'filename',\n 'url',\n 'contentType',\n 'byteSize',\n 'width',\n 'height',\n 'storageKey',\n 'title',\n])\n\n/**\n * The asset collection's EDITABLE metadata fields — declared fields minus the\n * system columns above and anything explicitly `readOnly` (EC-301/EC-319).\n */\nexport function assetMetaFieldsOf(collection: CollectionDef): FieldDef[] {\n return collection.fields.filter((f) => !SYSTEM_ASSET_FIELDS.has(f.name) && !f.form?.readOnly)\n}\n\n/** Drop `undefined` values so a persisted meta bag stays JSON/Convex-clean. */\nexport function pruneMeta(meta: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(Object.entries(meta).filter(([, v]) => v !== undefined))\n}\n\n/** Human-readable byte size (`1536` → `1.5 KB`). Shared by the asset grid + detail. */\nexport function formatBytes(byteSize: number): string {\n if (byteSize < 1024) return `${byteSize} B`\n if (byteSize < 1024 * 1024) return `${(byteSize / 1024).toFixed(1)} KB`\n return `${(byteSize / (1024 * 1024)).toFixed(1)} MB`\n}\n\n/**\n * An editor's metadata change, in the EC-577 write rule: an ABSENT key leaves the\n * stored value untouched, `null` clears it, a value sets it.\n */\nexport interface AssetMetadataPatch {\n /** New display title: a value sets (trimmed), `null` or a trimmed-empty string clears. */\n title?: string | null\n /**\n * New focal point (EC-248), the normalized 0–1 hotspot threaded to delivery's\n * `object-position` (EC-230). `{x,y}` sets it, `null` clears it (\"Reset to\n * centre\").\n */\n focalPoint?: { x: number; y: number } | null\n /**\n * Schema-driven asset metadata bag (EC-301): alt, copyright, credit, … keyed by\n * the asset collection's `fields`. An object **replaces** the whole bag (the\n * image options dialog holds the complete edited meta, seeded through\n * {@link assetMetaSeed}); `null` clears it. `meta.alt` is the asset's ONE alt\n * (EC-587) — there is no separate alt key.\n */\n meta?: Record<string, unknown> | null\n}\n\n/**\n * The meta bag an editor starts from (EC-587): the stored `meta` with a legacy `alt`\n * column lifted in (core `liftLegacyAlt`), so a not-yet-migrated asset shows the alt\n * every reader shows — and the save writes it to `meta`, its home.\n */\nexport function assetMetaSeed(record: Pick<AssetRecord, 'alt' | 'meta'>): Record<string, unknown> {\n return liftLegacyAlt(record)?.meta ?? { ...(record.meta ?? {}) }\n}\n\n/** A text column's write: a trimmed value sets, `null`/empty clears. */\nfunction textWrite(value: string | null): string | null {\n const trimmed = value?.trim() ?? ''\n return trimmed.length > 0 ? trimmed : null\n}\n\n/**\n * The asset write for a metadata edit (EC-577): ONLY the keys the editor changed,\n * with `null` for a clear. It deliberately restates nothing else — not the\n * upload-owned columns, and never `thumb`/`lqip`: a stale copy of those would\n * overwrite a preview backfill that finished while the dialog was open, and a\n * clear expressed as an omitted key is exactly what never persisted on Convex.\n *\n * EC-587: a `meta` write also clears the legacy `alt` column. The bag was seeded with\n * that column lifted in ({@link assetMetaSeed}), so the alt the editor saw is in the bag\n * (or was deliberately cleared): the column has nothing left to say, and leaving it\n * would re-surface a cleared alt through the read fallback (ASSETS D21).\n */\nexport function assetMetadataWrite(assetId: string, patch: AssetMetadataPatch): AssetWriteInput {\n return {\n id: assetId,\n ...(patch.title !== undefined ? { title: textWrite(patch.title) } : {}),\n ...(patch.focalPoint !== undefined ? { focalPoint: patch.focalPoint } : {}),\n ...(patch.meta !== undefined ? { meta: patch.meta, alt: null } : {}),\n }\n}\n\nexport type UpdateAssetMetadataResult =\n | { ok: true; asset: AssetRecord }\n | { ok: false; message: string }\n\n/**\n * Persist a metadata edit via the repository (the operations facade in the\n * studio). No read first: the write carries only the change, and the adapter\n * resolves it against the stored record inside its own transaction (EC-577). An\n * asset that no longer exists is refused there (a metadata write cannot create\n * one). Failures come back as a structured result — never a throw the UI has to\n * guess about.\n */\nexport async function updateAssetMetadata(\n deps: { assets: AssetRepository },\n projectId: string,\n assetId: string,\n patch: AssetMetadataPatch,\n): Promise<UpdateAssetMetadataResult> {\n try {\n const asset = await deps.assets.upsertAsset(projectId, assetMetadataWrite(assetId, patch))\n return { ok: true, asset }\n } catch (cause) {\n return { ok: false, message: cause instanceof Error ? cause.message : String(cause) }\n }\n}\n"]}
1
+ {"version":3,"file":"asset-metadata.js","sourceRoot":"","sources":["../../../src/components/assets/asset-metadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AASrH;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IAC9D,UAAU;IACV,KAAK;IACL,aAAa;IACb,UAAU;IACV,OAAO;IACP,QAAQ;IACR,YAAY;IACZ,OAAO;CACR,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAyB;IACzD,OAAO,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;AAC/F,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CAAC,IAA6B;IACrD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAA;AACpF,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,IAAI,QAAQ,GAAG,IAAI;QAAE,OAAO,GAAG,QAAQ,IAAI,CA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C,EAAE,CAAC;QAC3E,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,GAAG,CAAC,kBAAkB,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClH,CAAA;AACH,CAAC;AAMD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAiC,EACjC,SAAiB,EACjB,OAAe,EACf,KAAyB;IAEzB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAA;QAC1F,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAA;IACvF,CAAC;AACH,CAAC","sourcesContent":["import type { CollectionDef, FieldDef } from '@elytracms/core/cms-core'\nimport { assetMetaIsLocalized, assetMetaValueAt, liftLegacyAlt, metaPatchBetween } from '@elytracms/core/persistence'\nimport type {\n AssetMetaDrift,\n AssetReadLocale,\n AssetRecord,\n AssetRepository,\n AssetWriteInput,\n} from '@elytracms/core/persistence'\n\n/**\n * Asset metadata editing (EC-152). A patch is applied through the\n * {@link AssetRepository} interface — in the studio that is the EC-141\n * operations facade, so every edit runs the `assets.upsert` command\n * (validate → authorize → mutate → event). Pure orchestration; injectable\n * for tests.\n */\n\n/**\n * System columns the upload pipeline owns — never editable metadata, so they're\n * excluded from the asset collection's schema-driven forms: the image field's\n * options dialog (EC-301, `field-control.tsx`) and the assets rail's detail\n * surface (EC-319, `asset-detail.tsx`) share this ONE reserved set so neither\n * drifts from the other. Everything else a project declares on the `kind:'asset'`\n * collection round-trips through the record's open `meta` bag.\n */\nexport const SYSTEM_ASSET_FIELDS: ReadonlySet<string> = new Set([\n 'filename',\n 'url',\n 'contentType',\n 'byteSize',\n 'width',\n 'height',\n 'storageKey',\n 'title',\n])\n\n/**\n * The asset collection's EDITABLE metadata fields — declared fields minus the\n * system columns above and anything explicitly `readOnly` (EC-301/EC-319).\n */\nexport function assetMetaFieldsOf(collection: CollectionDef): FieldDef[] {\n return collection.fields.filter((f) => !SYSTEM_ASSET_FIELDS.has(f.name) && !f.form?.readOnly)\n}\n\n/** Drop `undefined` values so a persisted meta bag stays JSON/Convex-clean. */\nexport function pruneMeta(meta: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(Object.entries(meta).filter(([, v]) => v !== undefined))\n}\n\n/** Human-readable byte size (`1536` → `1.5 KB`). Shared by the asset grid + detail. */\nexport function formatBytes(byteSize: number): string {\n if (byteSize < 1024) return `${byteSize} B`\n if (byteSize < 1024 * 1024) return `${(byteSize / 1024).toFixed(1)} KB`\n return `${(byteSize / (1024 * 1024)).toFixed(1)} MB`\n}\n\n/**\n * An editor's metadata change, in the EC-577 write rule: an ABSENT key leaves the\n * stored value untouched, `null` clears it, a value sets it.\n */\nexport interface AssetMetadataPatch {\n /** New display title: a value sets (trimmed), `null` or a trimmed-empty string clears. */\n title?: string | null\n /**\n * New focal point (EC-248), the normalized 0–1 hotspot threaded to delivery's\n * `object-position` (EC-230). `{x,y}` sets it, `null` clears it (\"Reset to\n * centre\").\n */\n focalPoint?: { x: number; y: number } | null\n /**\n * A per-key change to the schema-driven metadata bag (EC-301 → EC-634): alt,\n * copyright, credit, … keyed by the asset collection's `fields`. A key with a value\n * sets it, `null` removes it, a key the patch does not name keeps its STORED value —\n * applied to the bag as stored, inside the write (core `resolveAssetWrite`), so an\n * editor never writes back a stale copy of a key another session changed. Build it\n * with {@link assetMetaDraftPatch} from the draft the editor opened and the one it holds.\n * `meta.alt` is the asset's ONE shared alt (EC-587) — there is no separate alt key. There\n * is no whole-bag form here: every studio editor of an asset's metadata patches per key.\n */\n metaPatch?: Record<string, unknown>\n /**\n * EC-632 — the same per-key change to the per-locale buckets of the asset collection's\n * `localized: true` fields: `{ [locale]: { [field]: value | null } }`, applied per locale\n * and key to the stored buckets inside the write.\n */\n localizedMetaPatch?: Record<string, Record<string, unknown>>\n}\n\n/**\n * An asset's metadata as an editor holds it (EC-632) — the DOCUMENT shape, so editing it\n * is the mechanism documents use: the shared bag (a document's `values`) and the\n * per-locale buckets of the `localized: true` fields (its `localized`). The form reads and\n * writes one field in one locale ({@link assetMetaFieldValue} / {@link setAssetMetaField});\n * the save is a structural diff of the whole draft ({@link assetMetaDraftPatch}), so it\n * needs no config and never writes a key or a locale the editor did not change.\n */\nexport interface AssetMetaDraft {\n readonly meta: Readonly<Record<string, unknown>>\n readonly localizedMeta: Readonly<Record<string, Readonly<Record<string, unknown>>>>\n}\n\n/**\n * The fields of the asset collection an editor edits by — only the name matters here.\n * EC-659: whether a field is edited per locale is the read locale's LENS (`at.lens`, the\n * project's asset collection as declared now — the one delivery reads by), never the\n * form's own copy of the field: a mount's rail override cannot make the editor write a\n * translation delivery would not read.\n */\ntype MetaField = Pick<FieldDef, 'name'>\n\n/**\n * The draft an editor opens (EC-587 + EC-632): the stored bags, with a legacy `alt` column\n * lifted into the shared one (core `liftLegacyAlt`), so a not-yet-migrated asset shows the\n * alt every reader shows — and its first save moves it home.\n */\nexport function assetMetaDraft(record: Pick<AssetRecord, 'alt' | 'meta' | 'localizedMeta'>): AssetMetaDraft {\n const localizedMeta: Record<string, Record<string, unknown>> = {}\n for (const [locale, bucket] of Object.entries(record.localizedMeta ?? {})) localizedMeta[locale] = { ...bucket }\n return { meta: liftLegacyAlt(record)?.meta ?? { ...(record.meta ?? {}) }, localizedMeta }\n}\n\nconst hasOwn = (bag: Readonly<Record<string, unknown>> | undefined, key: string): boolean =>\n bag !== undefined && Object.prototype.hasOwnProperty.call(bag, key)\n\n/**\n * What the form shows for one field (EC-632) — read by THE positional rule delivery's view\n * reads by (core `assetMetaValueAt`, EC-659), with the editor's fallback (`'own'`): a field\n * the lens localizes shows the editor's locale's own value (an untranslated locale shows\n * empty — it falls back to the default locale on delivery); the default locale also shows a\n * value written before the field was localized (the shared bag — delivery's last-resort\n * fallback, so it IS that locale's value). Any other field the shared value — a translation\n * left from a former localization is drift, shown by no reader. Without a locale config,\n * the shared value.\n */\nexport function assetMetaFieldValue(draft: AssetMetaDraft, field: MetaField, at: AssetReadLocale | null): unknown {\n const read = assetMetaValueAt(draft, field.name, at, 'own')\n return read.found ? read.value : undefined\n}\n\n/**\n * Write one field of the draft (EC-632) — `undefined` removes the value. Where it goes is\n * the lens's answer (EC-659, `assetMetaIsLocalized` — the rule every reader reads by):\n * - a field the lens localizes goes into the editor's locale's bucket; in the DEFAULT\n * locale a value written before the field was localized leaves the shared bag — the\n * default bucket is its home now, so a clear there really clears it;\n * - any other field goes into the shared bag, and a value a former localization left in a\n * bucket is removed (one home per key — the stale value is drift, read by nobody; this\n * edit is how an editor clears it);\n * - without a locale config (`at` null) there is no lens: the shared bag, and every\n * bucket left alone — a translation is never removed on a guess.\n */\nexport function setAssetMetaField(\n draft: AssetMetaDraft,\n field: MetaField,\n at: AssetReadLocale | null,\n value: unknown,\n): AssetMetaDraft {\n const name = field.name\n const withValue = (bag: Readonly<Record<string, unknown>> | undefined): Record<string, unknown> => {\n const next = { ...(bag ?? {}) }\n if (value === undefined) delete next[name]\n else next[name] = value\n return next\n }\n const without = (bag: Readonly<Record<string, unknown>>): Record<string, unknown> => {\n const next = { ...bag }\n delete next[name]\n return next\n }\n // No locale config installed yet (no lens): the shared bag, the buckets left untouched.\n if (at === null) return { meta: withValue(draft.meta), localizedMeta: draft.localizedMeta }\n if (assetMetaIsLocalized(at, name)) {\n const bucket = withValue(draft.localizedMeta[at.locale])\n const localizedMeta = { ...draft.localizedMeta, [at.locale]: bucket }\n const meta = at.locale === at.default && hasOwn(draft.meta, name) ? without(draft.meta) : draft.meta\n return { meta, localizedMeta }\n }\n const localizedMeta: Record<string, Readonly<Record<string, unknown>>> = {}\n for (const [locale, bucket] of Object.entries(draft.localizedMeta)) {\n localizedMeta[locale] = hasOwn(bucket, name) ? without(bucket) : bucket\n }\n return { meta: withValue(draft.meta), localizedMeta }\n}\n\n/**\n * The per-key, per-locale patch of a metadata edit (EC-634 × EC-632): what changed between\n * the draft the editor OPENED ({@link assetMetaDraft} at open, or the draft of its last\n * successful save) and the draft it holds — `undefined` values pruned, a removed key\n * `null`, a locale it did not touch absent. Every asset metadata editor (the image options\n * dialog, the asset library's detail, the assets rail) sends this instead of its buffer.\n */\nexport function assetMetaDraftPatch(\n opened: AssetMetaDraft,\n edited: AssetMetaDraft,\n): Pick<AssetMetadataPatch, 'metaPatch' | 'localizedMetaPatch'> {\n const metaPatch = metaPatchBetween(pruneMeta({ ...opened.meta }), pruneMeta({ ...edited.meta }))\n const localizedMetaPatch: Record<string, Record<string, unknown>> = {}\n for (const locale of new Set([...Object.keys(opened.localizedMeta), ...Object.keys(edited.localizedMeta)])) {\n const patch = metaPatchBetween(\n pruneMeta({ ...(opened.localizedMeta[locale] ?? {}) }),\n pruneMeta({ ...(edited.localizedMeta[locale] ?? {}) }),\n )\n if (Object.keys(patch).length > 0) localizedMetaPatch[locale] = patch\n }\n return {\n ...(Object.keys(metaPatch).length > 0 ? { metaPatch } : {}),\n ...(Object.keys(localizedMetaPatch).length > 0 ? { localizedMetaPatch } : {}),\n }\n}\n\n/**\n * The asset detail's drift notice, as data (EC-659): the stored translations the lens does\n * not read (core `assetMetaDrift`), grouped by reason, each field listed with the locales\n * holding one — `alt (de, fr)`. Empty when there is none. Pure.\n */\nexport function assetMetaDriftSummary(\n drift: readonly AssetMetaDrift[],\n): Array<{ reason: AssetMetaDrift['reason']; fields: string }> {\n const lines: Array<{ reason: AssetMetaDrift['reason']; fields: string }> = []\n for (const reason of ['not-localized', 'undeclared'] as const) {\n const byField = new Map<string, string[]>()\n for (const entry of drift) {\n if (entry.reason !== reason) continue\n byField.set(entry.field, [...(byField.get(entry.field) ?? []), entry.locale])\n }\n if (byField.size === 0) continue\n const fields = [...byField.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([field, locales]) => `${field} (${locales.join(', ')})`)\n .join(', ')\n lines.push({ reason, fields })\n }\n return lines\n}\n\n/** The form's flat view of a draft in one locale — `{ [field]: value }` for the given fields. */\nexport function assetMetaFormValues(\n draft: AssetMetaDraft,\n fields: readonly MetaField[],\n at: AssetReadLocale | null,\n): Record<string, unknown> {\n return Object.fromEntries(fields.map((field) => [field.name, assetMetaFieldValue(draft, field, at)]))\n}\n\n/** A text column's write: a trimmed value sets, `null`/empty clears. */\nfunction textWrite(value: string | null): string | null {\n const trimmed = value?.trim() ?? ''\n return trimmed.length > 0 ? trimmed : null\n}\n\n/**\n * The asset write for a metadata edit (EC-577): ONLY the keys the editor changed,\n * with `null` for a clear. It deliberately restates nothing else — not the\n * upload-owned columns, and never `thumb`/`lqip`: a stale copy of those would\n * overwrite a preview backfill that finished while the dialog was open, and a\n * clear expressed as an omitted key is exactly what never persisted on Convex.\n *\n * EC-634: `meta` travels as the per-key `metaPatch` — never the whole bag, which would\n * carry a stale copy of every key the editor did not change. An empty patch is not sent.\n * The legacy `alt` column (EC-587) is lifted into the stored bag and cleared by the write\n * rule itself, in the same transaction, whenever a patch is applied — so an alt the editor\n * did not touch survives, and one the editor cleared stays cleared (ASSETS D21).\n */\nexport function assetMetadataWrite(assetId: string, patch: AssetMetadataPatch): AssetWriteInput {\n const metaPatch = patch.metaPatch\n const localizedMetaPatch = patch.localizedMetaPatch\n return {\n id: assetId,\n ...(patch.title !== undefined ? { title: textWrite(patch.title) } : {}),\n ...(patch.focalPoint !== undefined ? { focalPoint: patch.focalPoint } : {}),\n ...(metaPatch !== undefined && Object.keys(metaPatch).length > 0 ? { metaPatch } : {}),\n ...(localizedMetaPatch !== undefined && Object.keys(localizedMetaPatch).length > 0 ? { localizedMetaPatch } : {}),\n }\n}\n\nexport type UpdateAssetMetadataResult =\n | { ok: true; asset: AssetRecord }\n | { ok: false; message: string }\n\n/**\n * Persist a metadata edit via the repository (the operations facade in the\n * studio). No read first: the write carries only the change, and the adapter\n * resolves it against the stored record inside its own transaction (EC-577). An\n * asset that no longer exists is refused there (a metadata write cannot create\n * one). Failures come back as a structured result — never a throw the UI has to\n * guess about.\n */\nexport async function updateAssetMetadata(\n deps: { assets: AssetRepository },\n projectId: string,\n assetId: string,\n patch: AssetMetadataPatch,\n): Promise<UpdateAssetMetadataResult> {\n try {\n const asset = await deps.assets.upsertAsset(projectId, assetMetadataWrite(assetId, patch))\n return { ok: true, asset }\n } catch (cause) {\n return { ok: false, message: cause instanceof Error ? cause.message : String(cause) }\n }\n}\n"]}
@@ -1,7 +1,11 @@
1
- import type { AssetRecord } from '@elytracms/core/persistence';
1
+ import type { AssetReadLocale, AssetRecord } from '@elytracms/core/persistence';
2
2
  /**
3
3
  * Client-side asset search (EC-152): case-insensitive substring match over
4
4
  * filename, alt text, and title. Pure and deterministic — input order is
5
5
  * preserved; an empty/whitespace query matches everything.
6
+ *
7
+ * EC-659: the alts searched are the ones the readers show — through `at`'s lens (the
8
+ * project's asset collection as declared now), so a translation the schema no longer
9
+ * reads (drift) does not make an asset match.
6
10
  */
7
- export declare function filterAssets(assets: readonly AssetRecord[], query: string): AssetRecord[];
11
+ export declare function filterAssets(assets: readonly AssetRecord[], query: string, at: AssetReadLocale | null): AssetRecord[];
@@ -3,13 +3,29 @@ import { assetAlt } from '@elytracms/core/persistence';
3
3
  * Client-side asset search (EC-152): case-insensitive substring match over
4
4
  * filename, alt text, and title. Pure and deterministic — input order is
5
5
  * preserved; an empty/whitespace query matches everything.
6
+ *
7
+ * EC-659: the alts searched are the ones the readers show — through `at`'s lens (the
8
+ * project's asset collection as declared now), so a translation the schema no longer
9
+ * reads (drift) does not make an asset match.
6
10
  */
7
- export function filterAssets(assets, query) {
11
+ export function filterAssets(assets, query, at) {
8
12
  const q = query.trim().toLowerCase();
9
13
  if (q.length === 0)
10
14
  return [...assets];
11
15
  return assets.filter((asset) =>
12
- // EC-587 (ASSETS D20): the asset's alt through THE reader (`meta.alt`, its home).
13
- [asset.filename, assetAlt(asset), asset.title].some((value) => value != null && value.toLowerCase().includes(q)));
16
+ // EC-587 (ASSETS D20): the asset's alt through THE reader (`meta.alt`, its home) —
17
+ // EC-632: in every locale it is translated into, so a search finds it from any tab.
18
+ [asset.filename, ...searchableAlts(asset, at), asset.title].some((value) => value != null && value.toLowerCase().includes(q)));
19
+ }
20
+ /**
21
+ * An asset's alt in the shared bag and in each locale it holds a bucket for (EC-632),
22
+ * through THE reader — each locale read on its own (its bucket, else the shared value),
23
+ * with `at`'s lens deciding whether a bucket is read at all (EC-659).
24
+ */
25
+ function searchableAlts(asset, at) {
26
+ if (at === null)
27
+ return [assetAlt(asset, null)];
28
+ const locales = Object.keys(asset.localizedMeta ?? {});
29
+ return [assetAlt(asset, null), ...locales.map((locale) => assetAlt(asset, { ...at, locale, default: locale }))];
14
30
  }
15
31
  //# sourceMappingURL=asset-search.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset-search.js","sourceRoot":"","sources":["../../../src/components/assets/asset-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAGtD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAA8B,EAAE,KAAa;IACxE,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACpC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAA;IACtC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;IAC7B,kFAAkF;IAClF,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CACjD,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC5D,CACF,CAAA;AACH,CAAC","sourcesContent":["import { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord } from '@elytracms/core/persistence'\n\n/**\n * Client-side asset search (EC-152): case-insensitive substring match over\n * filename, alt text, and title. Pure and deterministic — input order is\n * preserved; an empty/whitespace query matches everything.\n */\nexport function filterAssets(assets: readonly AssetRecord[], query: string): AssetRecord[] {\n const q = query.trim().toLowerCase()\n if (q.length === 0) return [...assets]\n return assets.filter((asset) =>\n // EC-587 (ASSETS D20): the asset's alt through THE reader (`meta.alt`, its home).\n [asset.filename, assetAlt(asset), asset.title].some(\n (value) => value != null && value.toLowerCase().includes(q),\n ),\n )\n}\n"]}
1
+ {"version":3,"file":"asset-search.js","sourceRoot":"","sources":["../../../src/components/assets/asset-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAGtD;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,MAA8B,EAAE,KAAa,EAAE,EAA0B;IACpG,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACpC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,GAAG,MAAM,CAAC,CAAA;IACtC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;IAC7B,mFAAmF;IACnF,oFAAoF;IACpF,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAC9D,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,IAAI,IAAI,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAC5D,CACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,KAAkB,EAAE,EAA0B;IACpE,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAA;IACtD,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;AACjH,CAAC","sourcesContent":["import { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetReadLocale, AssetRecord } from '@elytracms/core/persistence'\n\n/**\n * Client-side asset search (EC-152): case-insensitive substring match over\n * filename, alt text, and title. Pure and deterministic — input order is\n * preserved; an empty/whitespace query matches everything.\n *\n * EC-659: the alts searched are the ones the readers show — through `at`'s lens (the\n * project's asset collection as declared now), so a translation the schema no longer\n * reads (drift) does not make an asset match.\n */\nexport function filterAssets(assets: readonly AssetRecord[], query: string, at: AssetReadLocale | null): AssetRecord[] {\n const q = query.trim().toLowerCase()\n if (q.length === 0) return [...assets]\n return assets.filter((asset) =>\n // EC-587 (ASSETS D20): the asset's alt through THE reader (`meta.alt`, its home) —\n // EC-632: in every locale it is translated into, so a search finds it from any tab.\n [asset.filename, ...searchableAlts(asset, at), asset.title].some(\n (value) => value != null && value.toLowerCase().includes(q),\n ),\n )\n}\n\n/**\n * An asset's alt in the shared bag and in each locale it holds a bucket for (EC-632),\n * through THE reader — each locale read on its own (its bucket, else the shared value),\n * with `at`'s lens deciding whether a bucket is read at all (EC-659).\n */\nfunction searchableAlts(asset: AssetRecord, at: AssetReadLocale | null): (string | null)[] {\n if (at === null) return [assetAlt(asset, null)]\n const locales = Object.keys(asset.localizedMeta ?? {})\n return [assetAlt(asset, null), ...locales.map((locale) => assetAlt(asset, { ...at, locale, default: locale }))]\n}\n"]}
@@ -6,6 +6,7 @@ import { Text } from '@elytracms/studio/ui';
6
6
  import { translate } from '../../lib/i18n/index.js';
7
7
  import { cn } from '../../lib/utils.js';
8
8
  import { useOptionalAssets } from './assets-store.js';
9
+ import { useAssetReadLocale } from './asset-locale.js';
9
10
  import { isDisplayableAssetUrl } from '../../lib/assets/index.js';
10
11
  import { CENTER_FOCAL_POINT, focalPointFromPoint, focalPointObjectPosition, } from './focal-point.js';
11
12
  /** Resolve an asset record by id from the ambient library, if one is mounted. */
@@ -53,8 +54,10 @@ function thumbnailSrc(record) {
53
54
  */
54
55
  export function AssetThumb({ record, className, alt, }) {
55
56
  const src = thumbnailSrc(record);
57
+ // EC-632: the alt in the studio's locale (a localized alt shows the open locale's).
58
+ const at = useAssetReadLocale();
56
59
  if (record && src) {
57
- return (_jsx("img", { src: src, alt: alt ?? assetAlt(record) ?? record.title ?? record.filename, loading: "lazy", style: { objectPosition: focalPointObjectPosition(record.focalPoint) }, className: cn('rounded border border-border bg-muted object-cover', className) }));
60
+ return (_jsx("img", { src: src, alt: alt ?? assetAlt(record, at) ?? record.title ?? record.filename, loading: "lazy", style: { objectPosition: focalPointObjectPosition(record.focalPoint) }, className: cn('rounded border border-border bg-muted object-cover', className) }));
58
61
  }
59
62
  return (_jsx("div", { className: cn('flex items-center justify-center rounded border border-border bg-muted text-muted-foreground', className), children: _jsx(Image, { className: "size-4", "aria-hidden": true }) }));
60
63
  }
@@ -70,6 +73,7 @@ export function FocalPointPicker({ record, point, onChange, onPreview, disabled,
70
73
  const marker = point ?? CENTER_FOCAL_POINT;
71
74
  const dragging = useRef(false);
72
75
  const [loaded, setLoaded] = useState(false);
76
+ const at = useAssetReadLocale(); // EC-632: the alt in the studio's locale
73
77
  if (!isResolvableImage(record)) {
74
78
  return (_jsx(Text, { size: "xs", tone: "subtle", children: translate('assets.focalPoint.noPreview') }));
75
79
  }
@@ -93,7 +97,7 @@ export function FocalPointPicker({ record, point, onChange, onPreview, disabled,
93
97
  e.currentTarget.releasePointerCapture(e.pointerId);
94
98
  onChange(pointFrom(e)); // commit on release only
95
99
  }
96
- return (_jsxs("button", { type: "button", "aria-label": translate('assets.focalPoint.setLabel'), disabled: disabled, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, className: cn('relative block w-full touch-none select-none overflow-hidden rounded border border-border bg-muted', 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40', disabled ? 'cursor-default opacity-60' : 'cursor-crosshair'), children: [_jsx("img", { src: record.url, alt: assetAlt(record) ?? record.filename, draggable: false, onLoad: () => setLoaded(true), className: cn('block h-auto w-full select-none transition-opacity', loaded ? 'opacity-100' : 'opacity-0') }), !loaded ? (_jsx("span", { className: "absolute inset-0 grid aspect-video place-items-center bg-muted", children: _jsx(Image, { className: "size-6 animate-pulse text-muted-foreground", "aria-hidden": true }) })) : (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1.5px_rgba(0,0,0,0.55)] ring-1 ring-black/40", style: { left: `${marker.x * 100}%`, top: `${marker.y * 100}%` } }))] }));
100
+ return (_jsxs("button", { type: "button", "aria-label": translate('assets.focalPoint.setLabel'), disabled: disabled, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: onPointerUp, className: cn('relative block w-full touch-none select-none overflow-hidden rounded border border-border bg-muted', 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40', disabled ? 'cursor-default opacity-60' : 'cursor-crosshair'), children: [_jsx("img", { src: record.url, alt: assetAlt(record, at) ?? record.filename, draggable: false, onLoad: () => setLoaded(true), className: cn('block h-auto w-full select-none transition-opacity', loaded ? 'opacity-100' : 'opacity-0') }), !loaded ? (_jsx("span", { className: "absolute inset-0 grid aspect-video place-items-center bg-muted", children: _jsx(Image, { className: "size-6 animate-pulse text-muted-foreground", "aria-hidden": true }) })) : (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1.5px_rgba(0,0,0,0.55)] ring-1 ring-black/40", style: { left: `${marker.x * 100}%`, top: `${marker.y * 100}%` } }))] }));
97
101
  }
98
102
  /** Common crop aspect ratios shown as focal-aware previews (EC-301). */
99
103
  const FOCAL_CROP_RATIOS = [
@@ -1 +1 @@
1
- {"version":3,"file":"asset-thumb.js","sourceRoot":"","sources":["../../../src/components/assets/asset-thumb.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AACxD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,eAAe,CAAA;AAGtB,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,OAAkC;IAC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,EAAE,EACzB,SAAS,EAAC,4BAA4B,GACtC,GACE,EACN,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,YAC1B,KAAK,CAAC,KAAK,GACP,KAZC,KAAK,CAAC,KAAK,CAaf,CACP,CAAC,GACE,CACP,CAAA;AACH,CAAC","sourcesContent":["import { useMemo, useRef, useState } from 'react'\nimport { Image } from 'lucide-react'\nimport { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord } from '@elytracms/core/persistence'\nimport { Text } from '@elytracms/studio/ui'\nimport { translate } from '../../lib/i18n'\nimport { cn } from '../../lib/utils'\nimport { useOptionalAssets } from './assets-store'\nimport { isDisplayableAssetUrl } from '../../lib/assets'\nimport {\n CENTER_FOCAL_POINT,\n focalPointFromPoint,\n focalPointObjectPosition,\n} from './focal-point'\nimport type { FocalPoint } from './focal-point'\n\n/** Resolve an asset record by id from the ambient library, if one is mounted. */\nexport function useAssetRecord(assetId: string | null | undefined): AssetRecord | undefined {\n const store = useOptionalAssets()\n return useMemo(() => {\n if (!assetId || !store || store.status !== 'ready') return undefined\n return store.assets.find((a) => a.id === assetId)\n }, [assetId, store])\n}\n\n/** True when the record is an image with a browser-displayable URL (EC-212, EC-459). */\nfunction isResolvableImage(record: AssetRecord | undefined): record is AssetRecord & { url: string } {\n return (\n record !== undefined &&\n record.contentType.startsWith('image/') &&\n isDisplayableAssetUrl(record.url)\n )\n}\n\n/**\n * The best studio thumbnail src for an image record (EC-400): prefer the stored\n * downscaled `thumb` variant when it is browser-displayable, else fall back to\n * the full original `url` (EC-459: `http(s)`, `blob:`, and `data:` all qualify —\n * an opaque backend locator like `memory://` does not). A missing/broken thumb\n * therefore degrades to the original — never a broken tile (scope §4). Non-image\n * / unresolvable records yield `undefined` (the icon placeholder). Focal-point\n * editing + the canvas keep the original elsewhere (delivery fidelity) — this\n * preference is thumbnail-only.\n */\nfunction thumbnailSrc(record: AssetRecord | undefined): string | undefined {\n if (!record || !record.contentType.startsWith('image/')) return undefined\n const thumbUrl = record.thumb?.url\n if (isDisplayableAssetUrl(thumbUrl)) return thumbUrl\n if (isDisplayableAssetUrl(record.url)) return record.url\n return undefined\n}\n\n/**\n * A read-only image thumbnail honouring the asset's focal point (EC-248): the\n * preview crops with the same `object-position` delivery uses (EC-230), so the\n * editor sees exactly what a focal-point change does. Prefers the EC-400\n * downscaled `thumb` variant (light egress) and falls back to the original.\n * Non-image / unresolvable assets fall back to the labelled icon, matching the\n * table cell's preview.\n */\nexport function AssetThumb({\n record,\n className,\n alt,\n}: {\n record: AssetRecord | undefined\n className?: string\n alt?: string\n}) {\n const src = thumbnailSrc(record)\n if (record && src) {\n return (\n <img\n src={src}\n alt={alt ?? assetAlt(record) ?? record.title ?? record.filename}\n loading=\"lazy\"\n style={{ objectPosition: focalPointObjectPosition(record.focalPoint) }}\n className={cn('rounded border border-border bg-muted object-cover', className)}\n />\n )\n }\n return (\n <div\n className={cn(\n 'flex items-center justify-center rounded border border-border bg-muted text-muted-foreground',\n className,\n )}\n >\n <Image className=\"size-4\" aria-hidden />\n </div>\n )\n}\n\n/**\n * The focal-point picker (EC-248/EC-301): click or **drag** anywhere on the image\n * to place the normalized 0–1 hotspot delivery threads to `object-position`\n * (EC-230). The marker follows the pointer live while dragging and only commits on\n * release (`onPreview` updates the marker, `onChange` commits). `onChange(null)`\n * resets to centre. Shows a placeholder until the image loads; renders a muted note\n * when the asset has no resolvable image.\n */\nexport function FocalPointPicker({\n record,\n point,\n onChange,\n onPreview,\n disabled,\n}: {\n record: AssetRecord | undefined\n point: FocalPoint | undefined\n onChange: (point: FocalPoint | null) => void\n /** Called continuously while dragging to move the marker without committing. */\n onPreview?: (point: FocalPoint) => void\n disabled?: boolean\n}) {\n const marker = point ?? CENTER_FOCAL_POINT\n const dragging = useRef(false)\n const [loaded, setLoaded] = useState(false)\n\n if (!isResolvableImage(record)) {\n return (\n <Text size=\"xs\" tone=\"subtle\">\n {translate('assets.focalPoint.noPreview')}\n </Text>\n )\n }\n\n const pointFrom = (e: React.PointerEvent<HTMLElement>): FocalPoint =>\n focalPointFromPoint(e.currentTarget.getBoundingClientRect(), e.clientX, e.clientY)\n\n function onPointerDown(e: React.PointerEvent<HTMLButtonElement>) {\n if (disabled) return\n dragging.current = true\n e.currentTarget.setPointerCapture(e.pointerId)\n ;(onPreview ?? onChange)(pointFrom(e))\n }\n function onPointerMove(e: React.PointerEvent<HTMLButtonElement>) {\n if (disabled || !dragging.current) return\n ;(onPreview ?? onChange)(pointFrom(e))\n }\n function onPointerUp(e: React.PointerEvent<HTMLButtonElement>) {\n if (disabled || !dragging.current) return\n dragging.current = false\n e.currentTarget.releasePointerCapture(e.pointerId)\n onChange(pointFrom(e)) // commit on release only\n }\n\n return (\n <button\n type=\"button\"\n aria-label={translate('assets.focalPoint.setLabel')}\n disabled={disabled}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n className={cn(\n 'relative block w-full touch-none select-none overflow-hidden rounded border border-border bg-muted',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40',\n disabled ? 'cursor-default opacity-60' : 'cursor-crosshair',\n )}\n >\n {/* Width-constrained, natural aspect (no object-fit), so the button wraps\n the image tightly and the bounding rect equals the image box — the\n normalized pointer coordinates are then exact, with no letterbox offset. */}\n <img\n src={record.url}\n alt={assetAlt(record) ?? record.filename}\n draggable={false}\n onLoad={() => setLoaded(true)}\n className={cn('block h-auto w-full select-none transition-opacity', loaded ? 'opacity-100' : 'opacity-0')}\n />\n {!loaded ? (\n <span className=\"absolute inset-0 grid aspect-video place-items-center bg-muted\">\n <Image className=\"size-6 animate-pulse text-muted-foreground\" aria-hidden />\n </span>\n ) : (\n <span\n aria-hidden\n className=\"pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1.5px_rgba(0,0,0,0.55)] ring-1 ring-black/40\"\n style={{ left: `${marker.x * 100}%`, top: `${marker.y * 100}%` }}\n />\n )}\n </button>\n )\n}\n\n/** Common crop aspect ratios shown as focal-aware previews (EC-301). */\nconst FOCAL_CROP_RATIOS = [\n { label: '9:16', className: 'aspect-[9/16]' },\n { label: '3:4', className: 'aspect-[3/4]' },\n { label: '1:1', className: 'aspect-square' },\n { label: '4:3', className: 'aspect-[4/3]' },\n { label: '16:9', className: 'aspect-video' },\n] as const\n\n/**\n * A row of common-ratio crop previews (EC-301), each cropping the image with the\n * same `object-position` delivery uses — so the editor sees how the focal point\n * holds the subject across portrait/square/landscape crops. Updates live as the\n * point is dragged.\n */\nexport function FocalCropPreviews({\n record,\n point,\n}: {\n record: AssetRecord | undefined\n point: FocalPoint | undefined\n}) {\n if (!isResolvableImage(record)) return null\n const objectPosition = focalPointObjectPosition(point)\n return (\n <div className=\"flex items-end gap-2\">\n {FOCAL_CROP_RATIOS.map((ratio) => (\n <div key={ratio.label} className=\"flex min-w-0 flex-col items-center gap-1\">\n <div className={cn('h-14 overflow-hidden rounded border border-border bg-muted', ratio.className)}>\n <img\n src={record.url}\n alt=\"\"\n draggable={false}\n style={{ objectPosition }}\n className=\"h-full w-full object-cover\"\n />\n </div>\n <Text size=\"xs\" tone=\"subtle\">\n {ratio.label}\n </Text>\n </div>\n ))}\n </div>\n )\n}\n"]}
1
+ {"version":3,"file":"asset-thumb.js","sourceRoot":"","sources":["../../../src/components/assets/asset-thumb.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAEtD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,iBAAi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;QAAE,OAAO,IAAI,CAAA;IAC3C,MAAM,cAAc,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAA;IACtD,OAAO,CACL,cAAK,SAAS,EAAC,sBAAsB,YAClC,iBAAiB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAChC,eAAuB,SAAS,EAAC,0CAA0C,aACzE,cAAK,SAAS,EAAE,EAAE,CAAC,4DAA4D,EAAE,KAAK,CAAC,SAAS,CAAC,YAC/F,cACE,GAAG,EAAE,MAAM,CAAC,GAAG,EACf,GAAG,EAAC,EAAE,EACN,SAAS,EAAE,KAAK,EAChB,KAAK,EAAE,EAAE,cAAc,EAAE,EACzB,SAAS,EAAC,4BAA4B,GACtC,GACE,EACN,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,QAAQ,YAC1B,KAAK,CAAC,KAAK,GACP,KAZC,KAAK,CAAC,KAAK,CAaf,CACP,CAAC,GACE,CACP,CAAA;AACH,CAAC","sourcesContent":["import { useMemo, useRef, useState } from 'react'\nimport { Image } from 'lucide-react'\nimport { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord } from '@elytracms/core/persistence'\nimport { Text } from '@elytracms/studio/ui'\nimport { translate } from '../../lib/i18n'\nimport { cn } from '../../lib/utils'\nimport { useOptionalAssets } from './assets-store'\nimport { useAssetReadLocale } from './asset-locale'\nimport { isDisplayableAssetUrl } from '../../lib/assets'\nimport {\n CENTER_FOCAL_POINT,\n focalPointFromPoint,\n focalPointObjectPosition,\n} from './focal-point'\nimport type { FocalPoint } from './focal-point'\n\n/** Resolve an asset record by id from the ambient library, if one is mounted. */\nexport function useAssetRecord(assetId: string | null | undefined): AssetRecord | undefined {\n const store = useOptionalAssets()\n return useMemo(() => {\n if (!assetId || !store || store.status !== 'ready') return undefined\n return store.assets.find((a) => a.id === assetId)\n }, [assetId, store])\n}\n\n/** True when the record is an image with a browser-displayable URL (EC-212, EC-459). */\nfunction isResolvableImage(record: AssetRecord | undefined): record is AssetRecord & { url: string } {\n return (\n record !== undefined &&\n record.contentType.startsWith('image/') &&\n isDisplayableAssetUrl(record.url)\n )\n}\n\n/**\n * The best studio thumbnail src for an image record (EC-400): prefer the stored\n * downscaled `thumb` variant when it is browser-displayable, else fall back to\n * the full original `url` (EC-459: `http(s)`, `blob:`, and `data:` all qualify —\n * an opaque backend locator like `memory://` does not). A missing/broken thumb\n * therefore degrades to the original — never a broken tile (scope §4). Non-image\n * / unresolvable records yield `undefined` (the icon placeholder). Focal-point\n * editing + the canvas keep the original elsewhere (delivery fidelity) — this\n * preference is thumbnail-only.\n */\nfunction thumbnailSrc(record: AssetRecord | undefined): string | undefined {\n if (!record || !record.contentType.startsWith('image/')) return undefined\n const thumbUrl = record.thumb?.url\n if (isDisplayableAssetUrl(thumbUrl)) return thumbUrl\n if (isDisplayableAssetUrl(record.url)) return record.url\n return undefined\n}\n\n/**\n * A read-only image thumbnail honouring the asset's focal point (EC-248): the\n * preview crops with the same `object-position` delivery uses (EC-230), so the\n * editor sees exactly what a focal-point change does. Prefers the EC-400\n * downscaled `thumb` variant (light egress) and falls back to the original.\n * Non-image / unresolvable assets fall back to the labelled icon, matching the\n * table cell's preview.\n */\nexport function AssetThumb({\n record,\n className,\n alt,\n}: {\n record: AssetRecord | undefined\n className?: string\n alt?: string\n}) {\n const src = thumbnailSrc(record)\n // EC-632: the alt in the studio's locale (a localized alt shows the open locale's).\n const at = useAssetReadLocale()\n if (record && src) {\n return (\n <img\n src={src}\n alt={alt ?? assetAlt(record, at) ?? record.title ?? record.filename}\n loading=\"lazy\"\n style={{ objectPosition: focalPointObjectPosition(record.focalPoint) }}\n className={cn('rounded border border-border bg-muted object-cover', className)}\n />\n )\n }\n return (\n <div\n className={cn(\n 'flex items-center justify-center rounded border border-border bg-muted text-muted-foreground',\n className,\n )}\n >\n <Image className=\"size-4\" aria-hidden />\n </div>\n )\n}\n\n/**\n * The focal-point picker (EC-248/EC-301): click or **drag** anywhere on the image\n * to place the normalized 0–1 hotspot delivery threads to `object-position`\n * (EC-230). The marker follows the pointer live while dragging and only commits on\n * release (`onPreview` updates the marker, `onChange` commits). `onChange(null)`\n * resets to centre. Shows a placeholder until the image loads; renders a muted note\n * when the asset has no resolvable image.\n */\nexport function FocalPointPicker({\n record,\n point,\n onChange,\n onPreview,\n disabled,\n}: {\n record: AssetRecord | undefined\n point: FocalPoint | undefined\n onChange: (point: FocalPoint | null) => void\n /** Called continuously while dragging to move the marker without committing. */\n onPreview?: (point: FocalPoint) => void\n disabled?: boolean\n}) {\n const marker = point ?? CENTER_FOCAL_POINT\n const dragging = useRef(false)\n const [loaded, setLoaded] = useState(false)\n const at = useAssetReadLocale() // EC-632: the alt in the studio's locale\n\n if (!isResolvableImage(record)) {\n return (\n <Text size=\"xs\" tone=\"subtle\">\n {translate('assets.focalPoint.noPreview')}\n </Text>\n )\n }\n\n const pointFrom = (e: React.PointerEvent<HTMLElement>): FocalPoint =>\n focalPointFromPoint(e.currentTarget.getBoundingClientRect(), e.clientX, e.clientY)\n\n function onPointerDown(e: React.PointerEvent<HTMLButtonElement>) {\n if (disabled) return\n dragging.current = true\n e.currentTarget.setPointerCapture(e.pointerId)\n ;(onPreview ?? onChange)(pointFrom(e))\n }\n function onPointerMove(e: React.PointerEvent<HTMLButtonElement>) {\n if (disabled || !dragging.current) return\n ;(onPreview ?? onChange)(pointFrom(e))\n }\n function onPointerUp(e: React.PointerEvent<HTMLButtonElement>) {\n if (disabled || !dragging.current) return\n dragging.current = false\n e.currentTarget.releasePointerCapture(e.pointerId)\n onChange(pointFrom(e)) // commit on release only\n }\n\n return (\n <button\n type=\"button\"\n aria-label={translate('assets.focalPoint.setLabel')}\n disabled={disabled}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n className={cn(\n 'relative block w-full touch-none select-none overflow-hidden rounded border border-border bg-muted',\n 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40',\n disabled ? 'cursor-default opacity-60' : 'cursor-crosshair',\n )}\n >\n {/* Width-constrained, natural aspect (no object-fit), so the button wraps\n the image tightly and the bounding rect equals the image box — the\n normalized pointer coordinates are then exact, with no letterbox offset. */}\n <img\n src={record.url}\n alt={assetAlt(record, at) ?? record.filename}\n draggable={false}\n onLoad={() => setLoaded(true)}\n className={cn('block h-auto w-full select-none transition-opacity', loaded ? 'opacity-100' : 'opacity-0')}\n />\n {!loaded ? (\n <span className=\"absolute inset-0 grid aspect-video place-items-center bg-muted\">\n <Image className=\"size-6 animate-pulse text-muted-foreground\" aria-hidden />\n </span>\n ) : (\n <span\n aria-hidden\n className=\"pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1.5px_rgba(0,0,0,0.55)] ring-1 ring-black/40\"\n style={{ left: `${marker.x * 100}%`, top: `${marker.y * 100}%` }}\n />\n )}\n </button>\n )\n}\n\n/** Common crop aspect ratios shown as focal-aware previews (EC-301). */\nconst FOCAL_CROP_RATIOS = [\n { label: '9:16', className: 'aspect-[9/16]' },\n { label: '3:4', className: 'aspect-[3/4]' },\n { label: '1:1', className: 'aspect-square' },\n { label: '4:3', className: 'aspect-[4/3]' },\n { label: '16:9', className: 'aspect-video' },\n] as const\n\n/**\n * A row of common-ratio crop previews (EC-301), each cropping the image with the\n * same `object-position` delivery uses — so the editor sees how the focal point\n * holds the subject across portrait/square/landscape crops. Updates live as the\n * point is dragged.\n */\nexport function FocalCropPreviews({\n record,\n point,\n}: {\n record: AssetRecord | undefined\n point: FocalPoint | undefined\n}) {\n if (!isResolvableImage(record)) return null\n const objectPosition = focalPointObjectPosition(point)\n return (\n <div className=\"flex items-end gap-2\">\n {FOCAL_CROP_RATIOS.map((ratio) => (\n <div key={ratio.label} className=\"flex min-w-0 flex-col items-center gap-1\">\n <div className={cn('h-14 overflow-hidden rounded border border-border bg-muted', ratio.className)}>\n <img\n src={record.url}\n alt=\"\"\n draggable={false}\n style={{ objectPosition }}\n className=\"h-full w-full object-cover\"\n />\n </div>\n <Text size=\"xs\" tone=\"subtle\">\n {ratio.label}\n </Text>\n </div>\n ))}\n </div>\n )\n}\n"]}
@@ -1,8 +1,9 @@
1
1
  import type { CmsDocument, CollectionDef, DocumentRef } from '@elytracms/core/cms-core';
2
- import type { AssetRecord, ReferenceTarget } from '@elytracms/core/persistence';
2
+ import type { AssetReadLocale, AssetRecord, ReferenceTarget } from '@elytracms/core/persistence';
3
3
  import type { OperationError } from '@elytracms/core/operations';
4
4
  import type { DeleteAssetResult } from '../../lib/assets/index.js';
5
5
  import type { CollectionViewSource, CollectionViewCapabilities } from '../../lib/collection-view/collection-view-source.js';
6
+ import type { AssetMetadataPatch } from './asset-metadata.js';
6
7
  /**
7
8
  * The capability profile of the assets rail (EC-319, EC-433). Hoisted to a
8
9
  * module-level constant (no prop/state dependency) so it's both the value the
@@ -32,18 +33,33 @@ export declare const ASSET_COLLECTION_CAPABILITIES: CollectionViewCapabilities;
32
33
  * record, and `alt` reads through THE reader (`assetAlt`, EC-587 — `meta.alt`, with a
33
34
  * not-yet-migrated legacy column lifted in), exactly what delivery and the image
34
35
  * field's options dialog show.
36
+ *
37
+ * EC-632: the values are the metadata's view in `at` (the studio's locale) — a
38
+ * `localized: true` field shows that locale's value, with delivery's fallback, held in
39
+ * the lens's one locale bucket (`localized[at.locale]`, the rail's locale), so the table
40
+ * reads it as that locale's value rather than as a fallback. EC-659: "localized" is
41
+ * `at`'s lens (the project's asset collection as declared now — what delivery reads by),
42
+ * so the rail never shows a translation delivery does not serve.
35
43
  */
36
- export declare function assetToDocument(collection: CollectionDef, record: AssetRecord): CmsDocument;
44
+ export declare function assetToDocument(collection: CollectionDef, record: AssetRecord, at: AssetReadLocale | null): CmsDocument;
37
45
  /**
38
- * The inverse of {@link assetToDocument}: the meta bag a save writes back — every
46
+ * The inverse of {@link assetToDocument}: the meta bag a lens document holds — every
39
47
  * value outside the system set (EC-301/EC-311), declared or not, through the ONE
40
- * value-keyed projection the users/redirects rails share (EC-577, RESIDUE-3d).
41
- * `meta` is written whole (it replaces the stored bag), so a key the lens never
42
- * declared must be in it: the schema-driven projection this replaced dropped them
43
- * on every rail save (D22), while the options dialog and asset detail kept them.
44
- * System columns are upload-managed and never written here.
48
+ * value-keyed projection the users/redirects rails share (EC-577, RESIDUE-3d). A key
49
+ * the lens never declared is in it (the schema-driven projection this replaced dropped
50
+ * them, D22). System columns are upload-managed and never written here.
51
+ */
52
+ export declare function documentToAssetMeta(doc: CmsDocument): Record<string, unknown>;
53
+ /**
54
+ * The rail save's metadata write (EC-634 × EC-632): only the keys whose value differs
55
+ * between the document as the editor OPENED it (`base`, forwarded by the edit shell —
56
+ * EC-616) and the one it saves, each written where its field lives — a field `at`'s lens
57
+ * localizes into `at`'s bucket, any other into the shared bag (`setAssetMetaField`, the
58
+ * editors' one rule) — as the per-key, per-locale patch against the record as stored. A
59
+ * key this editor did not change is never written. Without a base every key of the saved
60
+ * bag is set and none is removed.
45
61
  */
46
- export declare function documentToAssetMetaPatch(doc: CmsDocument): Record<string, unknown>;
62
+ export declare function assetRailMetaPatch(collection: CollectionDef, record: AssetRecord, at: AssetReadLocale | null, doc: CmsDocument, base?: CmsDocument): Pick<AssetMetadataPatch, 'metaPatch' | 'localizedMetaPatch'>;
47
63
  /** Assets' `remove()` returns an `outcome`-discriminated {@link DeleteAssetResult}
48
64
  * (not the `{ ok }` shape users/redirects use, EC-327). `'error'` surfaces as-is;
49
65
  * `'blocked'` (the unconfirmed usage gate fired — nothing was removed) surfaces
@@ -1,17 +1,23 @@
1
1
  import { useCallback, useMemo } from 'react';
2
- import { createCollectionRegistry, validateDocument } from '@elytracms/core/cms-core';
3
- import { assetAlt } from '@elytracms/core/persistence';
2
+ import { createCollectionRegistry, semanticValueEqual, validateDocument } from '@elytracms/core/cms-core';
3
+ import { assetAlt, assetMetaIsLocalized, assetMetaView } from '@elytracms/core/persistence';
4
4
  import { studioPath } from '@elytracms/studio/router';
5
5
  import { useAssets } from './assets-store.js';
6
- import { SYSTEM_ASSET_FIELDS, pruneMeta } from './asset-metadata.js';
6
+ import { SYSTEM_ASSET_FIELDS, assetMetaDraft, assetMetaDraftPatch, pruneMeta, setAssetMetaField } from './asset-metadata.js';
7
+ import { useAssetReadLocale } from './asset-locale.js';
7
8
  import { metaBagProjection, normalizeOkResult, useRailViewSource } from '../rail-view-source.js';
8
9
  import { parseLocaleConfig } from '@elytracms/core/cms-core';
9
- /** The assets rail is not localized in v1 (EC-301: asset metadata is non-localized). */
10
+ /**
11
+ * The assets rail has no locale switcher of its own (capability `locales: false`): it
12
+ * reads in ONE locale — the studio's (EC-632), a localized field's value in that locale —
13
+ * so its lens is a one-locale document in that locale. Before a project's locales are
14
+ * installed, the engine's neutral `en` (shared metadata only: nothing is localized then).
15
+ */
10
16
  const ASSETS_LOCALE = 'en';
11
- const ASSETS_LOCALE_CONFIG = parseLocaleConfig({
12
- default: ASSETS_LOCALE,
13
- locales: [ASSETS_LOCALE],
14
- });
17
+ function railLocaleConfig(at) {
18
+ const locale = at?.locale ?? ASSETS_LOCALE;
19
+ return parseLocaleConfig({ default: locale, locales: [locale] });
20
+ }
15
21
  /**
16
22
  * The capability profile of the assets rail (EC-319, EC-433). Hoisted to a
17
23
  * module-level constant (no prop/state dependency) so it's both the value the
@@ -77,12 +83,19 @@ function systemFieldValue(record, name) {
77
83
  * record, and `alt` reads through THE reader (`assetAlt`, EC-587 — `meta.alt`, with a
78
84
  * not-yet-migrated legacy column lifted in), exactly what delivery and the image
79
85
  * field's options dialog show.
86
+ *
87
+ * EC-632: the values are the metadata's view in `at` (the studio's locale) — a
88
+ * `localized: true` field shows that locale's value, with delivery's fallback, held in
89
+ * the lens's one locale bucket (`localized[at.locale]`, the rail's locale), so the table
90
+ * reads it as that locale's value rather than as a fallback. EC-659: "localized" is
91
+ * `at`'s lens (the project's asset collection as declared now — what delivery reads by),
92
+ * so the rail never shows a translation delivery does not serve.
80
93
  */
81
- export function assetToDocument(collection, record) {
82
- const values = { ...(record.meta ?? {}) };
94
+ export function assetToDocument(collection, record, at) {
95
+ const values = assetMetaView(record, at);
83
96
  for (const field of collection.fields) {
84
97
  if (field.name === 'alt') {
85
- const alt = assetAlt(record);
98
+ const alt = assetAlt(record, at);
86
99
  if (alt !== null)
87
100
  values.alt = alt;
88
101
  else
@@ -92,19 +105,52 @@ export function assetToDocument(collection, record) {
92
105
  values[field.name] = systemFieldValue(record, field.name);
93
106
  }
94
107
  }
95
- return { collection: collection.id, id: record.id, values };
108
+ if (at === null)
109
+ return { collection: collection.id, id: record.id, values };
110
+ const bucket = {};
111
+ for (const field of collection.fields) {
112
+ if (!assetMetaIsLocalized(at, field.name) || !Object.prototype.hasOwnProperty.call(values, field.name))
113
+ continue;
114
+ bucket[field.name] = values[field.name];
115
+ delete values[field.name];
116
+ }
117
+ return Object.keys(bucket).length > 0
118
+ ? { collection: collection.id, id: record.id, values, localized: { [at.locale]: bucket } }
119
+ : { collection: collection.id, id: record.id, values };
96
120
  }
97
121
  /**
98
- * The inverse of {@link assetToDocument}: the meta bag a save writes back — every
122
+ * The inverse of {@link assetToDocument}: the meta bag a lens document holds — every
99
123
  * value outside the system set (EC-301/EC-311), declared or not, through the ONE
100
- * value-keyed projection the users/redirects rails share (EC-577, RESIDUE-3d).
101
- * `meta` is written whole (it replaces the stored bag), so a key the lens never
102
- * declared must be in it: the schema-driven projection this replaced dropped them
103
- * on every rail save (D22), while the options dialog and asset detail kept them.
104
- * System columns are upload-managed and never written here.
124
+ * value-keyed projection the users/redirects rails share (EC-577, RESIDUE-3d). A key
125
+ * the lens never declared is in it (the schema-driven projection this replaced dropped
126
+ * them, D22). System columns are upload-managed and never written here.
105
127
  */
106
- export function documentToAssetMetaPatch(doc) {
107
- return pruneMeta(metaBagProjection(doc.values ?? {}, SYSTEM_ASSET_FIELDS));
128
+ export function documentToAssetMeta(doc) {
129
+ // EC-632: the lens's one locale bucket (a localized field's value) reads beside `values`.
130
+ const localized = Object.values(doc.localized ?? {}).reduce((all, bag) => ({ ...all, ...bag }), {});
131
+ return pruneMeta(metaBagProjection({ ...(doc.values ?? {}), ...localized }, SYSTEM_ASSET_FIELDS));
132
+ }
133
+ /**
134
+ * The rail save's metadata write (EC-634 × EC-632): only the keys whose value differs
135
+ * between the document as the editor OPENED it (`base`, forwarded by the edit shell —
136
+ * EC-616) and the one it saves, each written where its field lives — a field `at`'s lens
137
+ * localizes into `at`'s bucket, any other into the shared bag (`setAssetMetaField`, the
138
+ * editors' one rule) — as the per-key, per-locale patch against the record as stored. A
139
+ * key this editor did not change is never written. Without a base every key of the saved
140
+ * bag is set and none is removed.
141
+ */
142
+ export function assetRailMetaPatch(collection, record, at, doc, base) {
143
+ const before = base ? documentToAssetMeta(base) : {};
144
+ const after = documentToAssetMeta(doc);
145
+ const opened = assetMetaDraft(record);
146
+ let edited = opened;
147
+ for (const name of new Set([...Object.keys(before), ...Object.keys(after)])) {
148
+ if (semanticValueEqual(before[name], after[name]))
149
+ continue;
150
+ const field = collection.fields.find((f) => f.name === name) ?? { name };
151
+ edited = setAssetMetaField(edited, field, at, after[name]);
152
+ }
153
+ return assetMetaDraftPatch(opened, edited);
108
154
  }
109
155
  /** `create` when `capabilities.create === false` — never reached from the UI
110
156
  * (list/detail never call it); an explicit throw rather than a silent no-op. */
@@ -159,17 +205,25 @@ export function assetReferenceTarget(ref) {
159
205
  export function useAssetsCollectionViewSource(projectId, schema) {
160
206
  const store = useAssets();
161
207
  const registry = useMemo(() => createCollectionRegistry([schema]), [schema]);
162
- const documents = useCallback(() => store.assets.map((record) => assetToDocument(schema, record)), [store.assets, schema]);
208
+ // EC-632: the rail reads (and a save writes) a localized field in the studio's locale.
209
+ const at = useAssetReadLocale();
210
+ const documents = useCallback(() => store.assets.map((record) => assetToDocument(schema, record, at)), [store.assets, schema, at]);
163
211
  const get = useCallback((ref) => {
164
212
  const record = store.assets.find((a) => a.id === ref.id);
165
- return record ? assetToDocument(schema, record) : undefined;
166
- }, [store.assets, schema]);
213
+ return record ? assetToDocument(schema, record, at) : undefined;
214
+ }, [store.assets, schema, at]);
167
215
  const titleOf = useCallback((ref) => {
168
216
  const record = store.assets.find((a) => a.id === ref.id);
169
217
  return record?.title ?? record?.filename ?? ref.id;
170
218
  }, [store.assets]);
171
- const validate = useCallback((doc) => validateDocument(registry, doc, { localeConfig: ASSETS_LOCALE_CONFIG }), [registry]);
172
- const save = useCallback((doc) => store.updateMetadata(doc.id, { meta: documentToAssetMetaPatch(doc) }), [store]);
219
+ const localeConfig = useMemo(() => railLocaleConfig(at), [at]);
220
+ const validate = useCallback((doc) => validateDocument(registry, doc, { localeConfig }), [registry, localeConfig]);
221
+ const save = useCallback(async (doc, base) => {
222
+ const record = store.assets.find((a) => a.id === doc.id);
223
+ if (!record)
224
+ return { ok: false, message: `No asset “${doc.id}” is loaded.` };
225
+ return store.updateMetadata(doc.id, assetRailMetaPatch(schema, record, at, doc, base));
226
+ }, [store, schema, at]);
173
227
  // The unconfirmed delete (the store's usage gate still applies — a referenced
174
228
  // asset comes back `blocked`, surfaced via `lastError`). The UI's delete paths
175
229
  // never land here: row/bulk deletes confirm through the reference dialog and
@@ -184,7 +238,7 @@ export function useAssetsCollectionViewSource(projectId, schema) {
184
238
  projectId,
185
239
  schema,
186
240
  capabilities: ASSET_COLLECTION_CAPABILITIES,
187
- localeConfig: ASSETS_LOCALE_CONFIG,
241
+ localeConfig,
188
242
  documents,
189
243
  get,
190
244
  titleOf,
@@ -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,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AACrF,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAGrD,OAA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AM,UAAU,GAAG,WAAW,CAC5B,CAAC,GAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,EAClE,CAAC,KAAK,CAAC,CACR,CAAA;IAED,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,sEAAsE;QACtE,yEAAyE;QACzE,0BAA0B;QAC1B,eAAe,EAAE,oBAAoB;QACrC,QAAQ;QACR,MAAM,EAAE,iBAAiB;QACzB,IAAI;QACJ,MAAM;QACN,UAAU;QACV,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 { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord, ReferenceTarget } from '@elytracms/core/persistence'\nimport type { OperationError } from '@elytracms/core/operations'\nimport { studioPath } from '@elytracms/studio/router'\nimport type { DeleteAssetResult } from '../../lib/assets'\nimport type { CollectionViewSource, CollectionViewCapabilities } from '../../lib/collection-view/collection-view-source'\nimport { useAssets } from './assets-store'\nimport { SYSTEM_ASSET_FIELDS, pruneMeta } from './asset-metadata'\nimport { metaBagProjection, normalizeOkResult, useRailViewSource } from '../rail-view-source'\nimport { parseLocaleConfig } from '@elytracms/core/cms-core'\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 = parseLocaleConfig({\n default: ASSETS_LOCALE,\n locales: [ASSETS_LOCALE],\n})\n\n/**\n * The capability profile of the assets rail (EC-319, EC-433). Hoisted to a\n * module-level constant (no prop/state dependency) so it's both the value the\n * hook returns AND independently unit-testable.\n *\n * `create` is off — a new asset comes from an upload, never a blank draft.\n * `remove` + `bulk` are ON since EC-433: the list's row/bulk delete used to be\n * off deliberately because the generic `ReferenceConfirmDialog` enumerated\n * inbound references as `{ type: 'document' }` targets — the wrong index shape\n * for an asset — which would have shown \"not referenced\" for an asset that IS\n * referenced. That pre-flight now queries the shape THIS source declares via\n * {@link assetReferenceTarget} (`{ type: 'asset' }`, the same lookup the\n * detail surface runs), and the confirmed delete dispatches the SAME checked\n * store delete the detail surface uses (`deleteAsset`: original + EC-400 thumb\n * blobs, then the record — EC-420 lqips ride on the record). Nothing else\n * applies to assets: no publish/versions/locales/inline-edit/live-URL/\n * 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 duplicate: false, // EC-442: blob duplication is a different feature, out of scope\n remove: true,\n bulk: true,\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) — the\n * value-keyed projection the redirects/users rails use (EC-577, RESIDUE-3d): EVERY\n * key of the record's open `meta` bag (EC-301) rides in `values`, declared by the\n * schema or not, so a save hands the bag back whole (D22). Declared fields then\n * take their canonical reading on top — a column never loses to a same-named meta\n * key: a system column (`filename`, `url`, dimensions, …) reads straight off the\n * record, and `alt` reads through THE reader (`assetAlt`, EC-587 — `meta.alt`, with a\n * not-yet-migrated legacy column lifted in), exactly what delivery and the image\n * field's options dialog show.\n */\nexport function assetToDocument(collection: CollectionDef, record: AssetRecord): CmsDocument {\n const values: Record<string, unknown> = { ...(record.meta ?? {}) }\n for (const field of collection.fields) {\n if (field.name === 'alt') {\n const alt = assetAlt(record)\n if (alt !== null) values.alt = alt\n else delete values.alt\n } else if (SYSTEM_ASSET_FIELDS.has(field.name)) {\n values[field.name] = systemFieldValue(record, field.name)\n }\n }\n return { collection: collection.id, id: record.id, values }\n}\n\n/**\n * The inverse of {@link assetToDocument}: the meta bag a save writes back — every\n * value outside the system set (EC-301/EC-311), declared or not, through the ONE\n * value-keyed projection the users/redirects rails share (EC-577, RESIDUE-3d).\n * `meta` is written whole (it replaces the stored bag), so a key the lens never\n * declared must be in it: the schema-driven projection this replaced dropped them\n * on every rail save (D22), while the options dialog and asset detail kept them.\n * System columns are upload-managed and never written here.\n */\nexport function documentToAssetMetaPatch(doc: CmsDocument): Record<string, unknown> {\n return pruneMeta(metaBagProjection(doc.values ?? {}, SYSTEM_ASSET_FIELDS))\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). `'error'` surfaces as-is;\n * `'blocked'` (the unconfirmed usage gate fired — nothing was removed) surfaces\n * as an explicit failure too (EC-433): a delete that left the asset in place\n * must NEVER look like success. It is unreachable from this rail's UI — every\n * delete path confirms through the reference dialog and dispatches with\n * `confirmInUse` — but stays honest for any direct caller. `'not-found'` maps\n * to success (idempotent delete: the desired end state — gone — holds). */\nexport function normalizeAssetRemoveResult(result: DeleteAssetResult): OperationError | null {\n if (result.outcome === 'error') return { code: 'unknown', message: result.message }\n if (result.outcome === 'blocked') {\n return {\n code: 'unknown',\n message: `Asset is referenced in ${result.usageCount} ${result.usageCount === 1 ? 'place' : 'places'} and was not deleted.`,\n }\n }\n return null\n}\n\n/**\n * How an asset row is addressed in the EC-155 reference index (EC-433):\n * `{ type: 'asset' }`, never the document shape — so the delete confirmation's\n * inbound pre-flight counts the SAME references `loadInboundAssetReferenceViews`\n * (the detail surface's check) does.\n */\nexport function assetReferenceTarget(ref: DocumentRef): ReferenceTarget {\n return { type: 'asset', id: ref.id }\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(doc) }),\n [store],\n )\n // The unconfirmed delete (the store's usage gate still applies — a referenced\n // asset comes back `blocked`, surfaced via `lastError`). The UI's delete paths\n // never land here: row/bulk deletes confirm through the reference dialog and\n // dispatch `bulkRemove` below.\n const remove = useCallback((ref: DocumentRef) => store.remove(ref.id), [store])\n // The CONFIRMED delete the bulk/row path dispatches (EC-433): the reference\n // dialog has already enumerated inbound usages (asset-shaped, see\n // `assetReferenceTarget`), so this passes `confirmInUse` exactly like the\n // detail surface's confirmed delete — same blob + thumb + cache handling.\n const bulkRemove = useCallback(\n (ref: DocumentRef) => store.remove(ref.id, { confirmInUse: true }),\n [store],\n )\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 // EC-433: the delete confirmation must enumerate ASSET-shaped inbound\n // references — the document-shaped default would report \"not referenced\"\n // for a referenced asset.\n referenceTarget: assetReferenceTarget,\n validate,\n create: createUnsupported,\n save,\n remove,\n bulkRemove,\n normalizeSaveResult: normalizeOkResult,\n normalizeRemoveResult: normalizeAssetRemoveResult,\n })\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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R,MAAM,EAAE,iBAAiB;QACzB,IAAI;QACJ,MAAM;QACN,UAAU;QACV,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, semanticValueEqual, validateDocument } from '@elytracms/core/cms-core'\nimport { assetAlt, assetMetaIsLocalized, assetMetaView } from '@elytracms/core/persistence'\nimport type { AssetReadLocale, AssetRecord, ReferenceTarget } from '@elytracms/core/persistence'\nimport type { OperationError } from '@elytracms/core/operations'\nimport { studioPath } from '@elytracms/studio/router'\nimport type { DeleteAssetResult } from '../../lib/assets'\nimport type { CollectionViewSource, CollectionViewCapabilities } from '../../lib/collection-view/collection-view-source'\nimport { useAssets } from './assets-store'\nimport { SYSTEM_ASSET_FIELDS, assetMetaDraft, assetMetaDraftPatch, pruneMeta, setAssetMetaField } from './asset-metadata'\nimport type { AssetMetadataPatch } from './asset-metadata'\nimport { useAssetReadLocale } from './asset-locale'\nimport { metaBagProjection, normalizeOkResult, useRailViewSource } from '../rail-view-source'\nimport { parseLocaleConfig } from '@elytracms/core/cms-core'\n\n/**\n * The assets rail has no locale switcher of its own (capability `locales: false`): it\n * reads in ONE locale — the studio's (EC-632), a localized field's value in that locale —\n * so its lens is a one-locale document in that locale. Before a project's locales are\n * installed, the engine's neutral `en` (shared metadata only: nothing is localized then).\n */\nconst ASSETS_LOCALE: Locale = 'en'\nfunction railLocaleConfig(at: AssetReadLocale | null): LocaleConfig {\n const locale = at?.locale ?? ASSETS_LOCALE\n return parseLocaleConfig({ default: locale, locales: [locale] })\n}\n\n/**\n * The capability profile of the assets rail (EC-319, EC-433). Hoisted to a\n * module-level constant (no prop/state dependency) so it's both the value the\n * hook returns AND independently unit-testable.\n *\n * `create` is off — a new asset comes from an upload, never a blank draft.\n * `remove` + `bulk` are ON since EC-433: the list's row/bulk delete used to be\n * off deliberately because the generic `ReferenceConfirmDialog` enumerated\n * inbound references as `{ type: 'document' }` targets — the wrong index shape\n * for an asset — which would have shown \"not referenced\" for an asset that IS\n * referenced. That pre-flight now queries the shape THIS source declares via\n * {@link assetReferenceTarget} (`{ type: 'asset' }`, the same lookup the\n * detail surface runs), and the confirmed delete dispatches the SAME checked\n * store delete the detail surface uses (`deleteAsset`: original + EC-400 thumb\n * blobs, then the record — EC-420 lqips ride on the record). Nothing else\n * applies to assets: no publish/versions/locales/inline-edit/live-URL/\n * 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 duplicate: false, // EC-442: blob duplication is a different feature, out of scope\n remove: true,\n bulk: true,\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) — the\n * value-keyed projection the redirects/users rails use (EC-577, RESIDUE-3d): EVERY\n * key of the record's open `meta` bag (EC-301) rides in `values`, declared by the\n * schema or not, so a save hands the bag back whole (D22). Declared fields then\n * take their canonical reading on top — a column never loses to a same-named meta\n * key: a system column (`filename`, `url`, dimensions, …) reads straight off the\n * record, and `alt` reads through THE reader (`assetAlt`, EC-587 — `meta.alt`, with a\n * not-yet-migrated legacy column lifted in), exactly what delivery and the image\n * field's options dialog show.\n *\n * EC-632: the values are the metadata's view in `at` (the studio's locale) — a\n * `localized: true` field shows that locale's value, with delivery's fallback, held in\n * the lens's one locale bucket (`localized[at.locale]`, the rail's locale), so the table\n * reads it as that locale's value rather than as a fallback. EC-659: \"localized\" is\n * `at`'s lens (the project's asset collection as declared now — what delivery reads by),\n * so the rail never shows a translation delivery does not serve.\n */\nexport function assetToDocument(collection: CollectionDef, record: AssetRecord, at: AssetReadLocale | null): CmsDocument {\n const values: Record<string, unknown> = assetMetaView(record, at)\n for (const field of collection.fields) {\n if (field.name === 'alt') {\n const alt = assetAlt(record, at)\n if (alt !== null) values.alt = alt\n else delete values.alt\n } else if (SYSTEM_ASSET_FIELDS.has(field.name)) {\n values[field.name] = systemFieldValue(record, field.name)\n }\n }\n if (at === null) return { collection: collection.id, id: record.id, values }\n const bucket: Record<string, unknown> = {}\n for (const field of collection.fields) {\n if (!assetMetaIsLocalized(at, field.name) || !Object.prototype.hasOwnProperty.call(values, field.name)) continue\n bucket[field.name] = values[field.name]\n delete values[field.name]\n }\n return Object.keys(bucket).length > 0\n ? { collection: collection.id, id: record.id, values, localized: { [at.locale]: bucket } }\n : { collection: collection.id, id: record.id, values }\n}\n\n/**\n * The inverse of {@link assetToDocument}: the meta bag a lens document holds — every\n * value outside the system set (EC-301/EC-311), declared or not, through the ONE\n * value-keyed projection the users/redirects rails share (EC-577, RESIDUE-3d). A key\n * the lens never declared is in it (the schema-driven projection this replaced dropped\n * them, D22). System columns are upload-managed and never written here.\n */\nexport function documentToAssetMeta(doc: CmsDocument): Record<string, unknown> {\n // EC-632: the lens's one locale bucket (a localized field's value) reads beside `values`.\n const localized = Object.values(doc.localized ?? {}).reduce<Record<string, unknown>>((all, bag) => ({ ...all, ...bag }), {})\n return pruneMeta(metaBagProjection({ ...(doc.values ?? {}), ...localized }, SYSTEM_ASSET_FIELDS))\n}\n\n/**\n * The rail save's metadata write (EC-634 × EC-632): only the keys whose value differs\n * between the document as the editor OPENED it (`base`, forwarded by the edit shell —\n * EC-616) and the one it saves, each written where its field lives — a field `at`'s lens\n * localizes into `at`'s bucket, any other into the shared bag (`setAssetMetaField`, the\n * editors' one rule) — as the per-key, per-locale patch against the record as stored. A\n * key this editor did not change is never written. Without a base every key of the saved\n * bag is set and none is removed.\n */\nexport function assetRailMetaPatch(\n collection: CollectionDef,\n record: AssetRecord,\n at: AssetReadLocale | null,\n doc: CmsDocument,\n base?: CmsDocument,\n): Pick<AssetMetadataPatch, 'metaPatch' | 'localizedMetaPatch'> {\n const before = base ? documentToAssetMeta(base) : {}\n const after = documentToAssetMeta(doc)\n const opened = assetMetaDraft(record)\n let edited = opened\n for (const name of new Set([...Object.keys(before), ...Object.keys(after)])) {\n if (semanticValueEqual(before[name], after[name])) continue\n const field = collection.fields.find((f) => f.name === name) ?? { name }\n edited = setAssetMetaField(edited, field, at, after[name])\n }\n return assetMetaDraftPatch(opened, edited)\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). `'error'` surfaces as-is;\n * `'blocked'` (the unconfirmed usage gate fired — nothing was removed) surfaces\n * as an explicit failure too (EC-433): a delete that left the asset in place\n * must NEVER look like success. It is unreachable from this rail's UI — every\n * delete path confirms through the reference dialog and dispatches with\n * `confirmInUse` — but stays honest for any direct caller. `'not-found'` maps\n * to success (idempotent delete: the desired end state — gone — holds). */\nexport function normalizeAssetRemoveResult(result: DeleteAssetResult): OperationError | null {\n if (result.outcome === 'error') return { code: 'unknown', message: result.message }\n if (result.outcome === 'blocked') {\n return {\n code: 'unknown',\n message: `Asset is referenced in ${result.usageCount} ${result.usageCount === 1 ? 'place' : 'places'} and was not deleted.`,\n }\n }\n return null\n}\n\n/**\n * How an asset row is addressed in the EC-155 reference index (EC-433):\n * `{ type: 'asset' }`, never the document shape — so the delete confirmation's\n * inbound pre-flight counts the SAME references `loadInboundAssetReferenceViews`\n * (the detail surface's check) does.\n */\nexport function assetReferenceTarget(ref: DocumentRef): ReferenceTarget {\n return { type: 'asset', id: ref.id }\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 // EC-632: the rail reads (and a save writes) a localized field in the studio's locale.\n const at = useAssetReadLocale()\n\n const documents = useCallback(\n () => store.assets.map((record) => assetToDocument(schema, record, at)),\n [store.assets, schema, at],\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, at) : undefined\n },\n [store.assets, schema, at],\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 localeConfig = useMemo(() => railLocaleConfig(at), [at])\n const validate = useCallback(\n (doc: CmsDocument) => validateDocument(registry, doc, { localeConfig }),\n [registry, localeConfig],\n )\n const save = useCallback(\n async (doc: CmsDocument, base?: CmsDocument) => {\n const record = store.assets.find((a) => a.id === doc.id)\n if (!record) return { ok: false as const, message: `No asset “${doc.id}” is loaded.` }\n return store.updateMetadata(doc.id, assetRailMetaPatch(schema, record, at, doc, base))\n },\n [store, schema, at],\n )\n // The unconfirmed delete (the store's usage gate still applies — a referenced\n // asset comes back `blocked`, surfaced via `lastError`). The UI's delete paths\n // never land here: row/bulk deletes confirm through the reference dialog and\n // dispatch `bulkRemove` below.\n const remove = useCallback((ref: DocumentRef) => store.remove(ref.id), [store])\n // The CONFIRMED delete the bulk/row path dispatches (EC-433): the reference\n // dialog has already enumerated inbound usages (asset-shaped, see\n // `assetReferenceTarget`), so this passes `confirmInUse` exactly like the\n // detail surface's confirmed delete — same blob + thumb + cache handling.\n const bulkRemove = useCallback(\n (ref: DocumentRef) => store.remove(ref.id, { confirmInUse: true }),\n [store],\n )\n\n return useRailViewSource({\n projectId,\n schema,\n capabilities: ASSET_COLLECTION_CAPABILITIES,\n localeConfig,\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 // EC-433: the delete confirmation must enumerate ASSET-shaped inbound\n // references — the document-shaped default would report \"not referenced\"\n // for a referenced asset.\n referenceTarget: assetReferenceTarget,\n validate,\n create: createUnsupported,\n save,\n remove,\n bulkRemove,\n normalizeSaveResult: normalizeOkResult,\n normalizeRemoveResult: normalizeAssetRemoveResult,\n })\n}\n"]}