@elytracms/studio 0.0.95 → 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.
- package/convex/cms.ts +124 -8
- package/convex/strict-reference-race.test.ts +139 -0
- package/dist/components/ai/ai-chat-panel.js +15 -2
- package/dist/components/ai/ai-chat-panel.js.map +1 -1
- package/dist/components/ai/translate-document-action.d.ts +6 -0
- package/dist/components/ai/translate-document-action.js.map +1 -1
- package/dist/components/ai/translate-document-dialog.d.ts +1 -1
- package/dist/components/ai/translate-document-dialog.js +5 -5
- package/dist/components/ai/translate-document-dialog.js.map +1 -1
- package/dist/components/assets/asset-detail.js +5 -2
- package/dist/components/assets/asset-detail.js.map +1 -1
- package/dist/components/assets/asset-locale.d.ts +7 -0
- package/dist/components/assets/asset-locale.js +16 -2
- package/dist/components/assets/asset-locale.js.map +1 -1
- package/dist/components/assets/asset-meta-drift-notice.d.ts +13 -0
- package/dist/components/assets/asset-meta-drift-notice.js +22 -0
- package/dist/components/assets/asset-meta-drift-notice.js.map +1 -0
- package/dist/components/assets/asset-meta-label.d.ts +2 -1
- package/dist/components/assets/asset-meta-label.js +4 -2
- package/dist/components/assets/asset-meta-label.js.map +1 -1
- package/dist/components/assets/asset-metadata.d.ts +33 -13
- package/dist/components/assets/asset-metadata.js +46 -22
- package/dist/components/assets/asset-metadata.js.map +1 -1
- package/dist/components/assets/asset-search.d.ts +6 -2
- package/dist/components/assets/asset-search.js +15 -5
- package/dist/components/assets/asset-search.js.map +1 -1
- package/dist/components/assets/assets-collection-view-source.d.ts +5 -3
- package/dist/components/assets/assets-collection-view-source.js +7 -5
- package/dist/components/assets/assets-collection-view-source.js.map +1 -1
- package/dist/components/builder/canvas-rebase.d.ts +36 -12
- package/dist/components/builder/canvas-rebase.js +13 -3
- package/dist/components/builder/canvas-rebase.js.map +1 -1
- package/dist/components/builder/canvas-render-context.js +5 -4
- package/dist/components/builder/canvas-render-context.js.map +1 -1
- package/dist/components/builder/composition-field-editor.d.ts +12 -6
- package/dist/components/builder/composition-field-editor.js +6 -5
- package/dist/components/builder/composition-field-editor.js.map +1 -1
- package/dist/components/cms/asset-picker-core.d.ts +2 -2
- package/dist/components/cms/asset-picker-core.js +2 -2
- package/dist/components/cms/asset-picker-core.js.map +1 -1
- package/dist/components/cms/asset-picker.js +3 -1
- package/dist/components/cms/asset-picker.js.map +1 -1
- package/dist/components/cms/canvas-commit.d.ts +6 -0
- package/dist/components/cms/canvas-commit.js +5 -1
- package/dist/components/cms/canvas-commit.js.map +1 -1
- package/dist/components/cms/cms-store.d.ts +21 -8
- package/dist/components/cms/cms-store.js +19 -10
- package/dist/components/cms/cms-store.js.map +1 -1
- package/dist/components/cms/collection-table.js +4 -11
- package/dist/components/cms/collection-table.js.map +1 -1
- package/dist/components/cms/detail-editor.js +2 -2
- package/dist/components/cms/detail-editor.js.map +1 -1
- package/dist/components/cms/draft-commit.d.ts +16 -3
- package/dist/components/cms/draft-commit.js +3 -2
- package/dist/components/cms/draft-commit.js.map +1 -1
- package/dist/components/cms/use-document-draft.d.ts +67 -9
- package/dist/components/cms/use-document-draft.js +112 -39
- package/dist/components/cms/use-document-draft.js.map +1 -1
- package/dist/components/collection-view/cms-collection-view-source.js +6 -4
- package/dist/components/collection-view/cms-collection-view-source.js.map +1 -1
- package/dist/components/components/transfer-dialog.js +6 -4
- package/dist/components/components/transfer-dialog.js.map +1 -1
- package/dist/lib/ai/chat-state.d.ts +7 -0
- package/dist/lib/ai/chat-state.js.map +1 -1
- package/dist/lib/ai/tools.d.ts +8 -0
- package/dist/lib/ai/tools.js +4 -0
- package/dist/lib/ai/tools.js.map +1 -1
- package/dist/lib/cms-views/view-model.d.ts +15 -8
- package/dist/lib/cms-views/view-model.js +19 -5
- package/dist/lib/cms-views/view-model.js.map +1 -1
- package/dist/lib/collection-view/__fixtures__/document-writes.js +1 -0
- package/dist/lib/collection-view/__fixtures__/document-writes.js.map +1 -1
- package/dist/lib/collection-view/collection-view-source.d.ts +15 -7
- package/dist/lib/collection-view/collection-view-source.js.map +1 -1
- package/dist/lib/data/collection-content.js +5 -0
- package/dist/lib/data/collection-content.js.map +1 -1
- package/dist/lib/engine-version.d.ts +1 -1
- package/dist/lib/engine-version.js +1 -1
- package/dist/lib/engine-version.js.map +1 -1
- package/dist/lib/i18n/messages.de.js +13 -1
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +11 -0
- package/dist/lib/i18n/messages.en.js +14 -1
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/operations/cms-persistence.d.ts +80 -35
- package/dist/lib/operations/cms-persistence.js +348 -85
- package/dist/lib/operations/cms-persistence.js.map +1 -1
- package/dist/lib/persistence/convex-adapter.js +54 -8
- package/dist/lib/persistence/convex-adapter.js.map +1 -1
- package/dist/lib/persona/labels.js +1 -0
- package/dist/lib/persona/labels.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-picker-core.js","sourceRoot":"","sources":["../../../src/components/cms/asset-picker-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,GAChB,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAe,CAAA;AAExD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA8B,EAC9B,KAAa,EACb,MAAqC;IAErC,OAAO,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;AACzF,CAAC;AAED;;;;;;GAMG;AACH,MAAM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GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,QAAkB,EAClB,EAAE,YAAY,EAAE,YAAY,EAAoB;IAEhD,YAAY,CAAC,QAAQ,CAAC,CAAA;IACtB,YAAY,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC;AAgBD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA4D,EAC5D,KAAc,EACd,KAA8B;IAE9B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;IAC/B,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC;QAC/C,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,QAAQ;QACR,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QACzE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,MAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzG,CAAA;AACH,CAAC","sourcesContent":["import type { AssetFieldDef } from '@elytracms/core/cms-core'\nimport type { AssetRecord } from '@elytracms/core/persistence'\nimport { assetMatchesAccept } from '@elytracms/core/cms-core'\nimport { filterAssets } from '../assets/asset-search'\nimport {\n appendAssetSelections,\n applyAssetSelection,\n singleAssetIdOf,\n} from '../assets/asset-selection'\n\n/**\n * Pure selection/filter core for the asset picker (EC-432). DOM-free and\n * side-effect-free so the media browser's \"what shows\", \"what an upload may send\" and\n * \"what a pick/upload commits\" are unit-testable without a browser — the picker\n * component is just the stage shell around these.\n *\n * EC-588: the picker takes the field's STRUCTURED `accept` list — the one shape the\n * schema declares — and derives everything from it here or in core: the grid filter\n * ({@link visiblePickerAssets}), the drop/upload split ({@link splitByAccept}), the\n * file-input attribute (`assetAcceptAttr`, core), and the commit filter\n * ({@link uploadBatchProgress}). An absent `accept` is unrestricted everywhere; there is\n * no hidden `image/*` default.\n */\n\n/**\n * The stage width preset the media browser mounts with (EC-432 / EC-431 AD-A):\n * the roomy `grid` measure (`min(1240px, 94vw)`) — browsing assets is spatial.\n * Exported so the geometry contract is pinnable without rendering the portal\n * (which is `null` in the node test env).\n */\nexport const ASSET_PICKER_STAGE_PRESET = 'grid' as const\n\n/**\n * The assets shown in the picker grid: the shipped search filter (EC-152) then\n * the `accept` filter (EC-432) — an image field's picker browses only images,\n * never the project's PDFs. Order follows the library.\n */\nexport function visiblePickerAssets(\n assets: readonly AssetRecord[],\n query: string,\n accept: readonly string[] | undefined,\n): AssetRecord[] {\n return filterAssets(assets, query).filter((asset) => assetMatchesAccept(asset, accept))\n}\n\n/**\n * THE drop rule (EC-301 → EC-588): split files about to be uploaded into the ones the\n * field's `accept` admits and the NAMES of the ones it refuses. A drag-drop bypasses\n * the file dialog's soft filter, so every upload path — the field's drop zone, a drop\n * into the open picker, the picker's Upload dialog — passes through this, and the\n * caller names the refused files in a visible notice instead of uploading them.\n */\nexport function splitByAccept<F extends { name: string; type: string }>(\n files: readonly F[],\n accept: readonly string[] | undefined,\n): { accepted: F[]; rejected: string[] } {\n const accepted: F[] = []\n const rejected: string[] = []\n for (const file of files) {\n if (assetMatchesAccept({ contentType: file.type, filename: file.name }, accept)) accepted.push(file)\n else rejected.push(file.name)\n }\n return { accepted, rejected }\n}\n\n/**\n * One upload BATCH (EC-460): the upload-queue ids THIS interaction started.\n *\n * EC-588 A7: it used to be a pre-upload library snapshot, and whatever the library\n * gained since was committed — so an upload from another tab (re-listed with ours) or\n * from a sibling field's drop could land in this field. A batch now names exactly its\n * own uploads, and the store reports which asset each one landed as.\n */\nexport interface UploadBatch {\n uploadIds: readonly string[]\n}\n\n/** What batch progress reads from the assets store (`AssetsStore` satisfies it). */\nexport interface UploadSource {\n assets: readonly AssetRecord[]\n uploads: readonly { id: string; state: { phase: string } }[]\n /** The asset id an upload landed as, once its record is confirmed. */\n landedAssetId(uploadId: string): string | undefined\n}\n\nexport interface UploadBatchProgress {\n /** The batch's landed asset ids that the field accepts, in upload order. */\n added: string[]\n /**\n * The batch is finished: none of its uploads is still running, and every one that\n * landed is in the library. A failed (or dismissed) upload is terminal — it stays in\n * the queue for retry and is never awaited forever. Commit/attach decisions happen\n * only once settled for `many` targets; a single-select target commits on the first\n * arrival.\n */\n settled: boolean\n}\n\n/**\n * Where a batch stands. An upload is in one of four states: running (in the queue,\n * not failed), landed-but-not-listed (the store confirmed it, the library re-list has\n * not arrived), landed (attachable), or terminal (failed / dismissed). Only landed\n * uploads whose RECORD satisfies `accept` are `added` (A7: the commit is filtered,\n * not just the dialog). Pure — the picker and the asset field both drive their\n * effects with this.\n */\nexport function uploadBatchProgress(\n batch: UploadBatch,\n source: UploadSource,\n accept: readonly string[] | undefined,\n): UploadBatchProgress {\n const running = new Set(source.uploads.filter((u) => u.state.phase !== 'failed').map((u) => u.id))\n const library = new Map(source.assets.map((asset) => [asset.id, asset]))\n const added: string[] = []\n let pending = false\n for (const uploadId of batch.uploadIds) {\n if (running.has(uploadId)) {\n pending = true\n continue\n }\n const assetId = source.landedAssetId(uploadId)\n if (assetId === undefined) continue // failed or dismissed — terminal\n const record = library.get(assetId)\n if (!record) {\n pending = true // confirmed, but the library re-list has not landed yet\n continue\n }\n if (assetMatchesAccept(record, accept)) added.push(assetId)\n }\n return { added, settled: !pending }\n}\n\n/**\n * THE batch-attach rule (EC-588, ratified 2i: N files → N uploads → N placements\n * APPENDED, in the order the files were given), for every surface that uploads into a\n * field — the field's own drop zone and the picker's Upload / drop. What to attach now,\n * and whether the batch is done (disarm):\n * - a `many` target attaches nothing until the batch settles, then every landed upload\n * the field accepts, in upload order ({@link uploadBatchProgress}'s `added`). The\n * field's drop used to attach each arrival as it landed, so a second file landing\n * before the first was appended first (measured on the base: `[a2, a1]`);\n * - a single target takes the first accepted arrival at once (the rest stay in the\n * library, where they are visible), and disarms when the batch ends with none.\n */\nexport function batchAttachment(\n progress: UploadBatchProgress,\n many: boolean,\n): { attach: string[]; disarm: boolean } {\n if (many) return progress.settled ? { attach: progress.added, disarm: true } : { attach: [], disarm: false }\n const first = progress.added[0]\n if (first !== undefined) return { attach: [first], disarm: true }\n return { attach: [], disarm: progress.settled }\n}\n\n/** The picker's commit callbacks — a pick fires `onChange` then closes the stage. */\nexport interface PickerCommit {\n onChange: (assetId: string | null) => void\n onOpenChange: (open: boolean) => void\n}\n\n/**\n * Commit a picked asset (or a clear, `assetId === null`) and close the picker —\n * the selection semantic (click = pick, fire `onChange`, close). Both the grid\n * card and the Clear affordance route through this.\n */\nexport function commitPickerSelection(assetId: string | null, { onChange, onOpenChange }: PickerCommit): void {\n onChange(assetId)\n onOpenChange(false)\n}\n\n/** The multi-commit callbacks (EC-460): a settled upload batch on a `many` field. */\nexport interface PickerCommitMany {\n onChangeMany: (assetIds: string[]) => void\n onOpenChange: (open: boolean) => void\n}\n\n/**\n * Commit EVERY asset a settled upload batch added (EC-460) and close the picker —\n * the `many`-field counterpart of {@link commitPickerSelection}, so selecting N\n * files in one picker interaction attaches all N, not just the first to land.\n */\nexport function commitPickerSelectionMany(\n assetIds: string[],\n { onChangeMany, onOpenChange }: PickerCommitMany,\n): void {\n onChangeMany(assetIds)\n onOpenChange(false)\n}\n\n/**\n * The picker props a field's value position needs, derived from the field alone\n * (EC-570 #1 → EC-588): the selected id, the field's structured `accept`, whether it\n * holds many, and the commits — a pick through the carry rule (EC-558), a settled\n * upload batch appended for a `many` field (EC-460).\n */\nexport interface AssetPickerBinding {\n value: string | null\n accept?: readonly string[]\n multiple: boolean\n onChange: (assetId: string | null) => void\n onChangeMany?: (assetIds: string[]) => void\n}\n\n/**\n * ONE picker configuration for every surface that edits an asset field — the detail\n * editor and the table cell — so the two cannot drift. Before, the cell opened the\n * picker with no `accept`, no `multiple` and no batch commit: its grid offered PDFs to\n * an image field and an N-file upload attached one (EC-570 #1). `write` receives the\n * next stored value; the caller decides how to land it (form state, cell commit).\n */\nexport function assetPickerBinding(\n field: Pick<AssetFieldDef, 'multiple' | 'accept' | 'fields'>,\n value: unknown,\n write: (next: unknown) => void,\n): AssetPickerBinding {\n const multiple = field.multiple\n return {\n value: multiple ? null : singleAssetIdOf(value),\n ...(field.accept ? { accept: field.accept } : {}),\n multiple,\n onChange: (picked) => write(applyAssetSelection(value, picked, multiple)),\n ...(multiple ? { onChangeMany: (picked: string[]) => write(appendAssetSelections(value, picked)) } : {}),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"asset-picker-core.js","sourceRoot":"","sources":["../../../src/components/cms/asset-picker-core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,GAChB,MAAM,2BAA2B,CAAA;AAElC;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAe,CAAA;AAExD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA8B,EAC9B,KAAa,EACb,MAAqC,EACrC,EAA0B;IAE1B,OAAO,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;AAC7F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAC3B,KAAmB,EACnB,MAAqC;IAErC,MAAM,QAAQ,GAAQ,EAAE,CAAA;IACxB,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B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tB,YAAY,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC;AAgBD;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA4D,EAC5D,KAAc,EACd,KAA8B;IAE9B,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;IAC/B,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC;QAC/C,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,QAAQ;QACR,QAAQ,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;QACzE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,MAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzG,CAAA;AACH,CAAC","sourcesContent":["import type { AssetFieldDef } from '@elytracms/core/cms-core'\nimport type { AssetReadLocale, AssetRecord } from '@elytracms/core/persistence'\nimport { assetMatchesAccept } from '@elytracms/core/cms-core'\nimport { filterAssets } from '../assets/asset-search'\nimport {\n appendAssetSelections,\n applyAssetSelection,\n singleAssetIdOf,\n} from '../assets/asset-selection'\n\n/**\n * Pure selection/filter core for the asset picker (EC-432). DOM-free and\n * side-effect-free so the media browser's \"what shows\", \"what an upload may send\" and\n * \"what a pick/upload commits\" are unit-testable without a browser — the picker\n * component is just the stage shell around these.\n *\n * EC-588: the picker takes the field's STRUCTURED `accept` list — the one shape the\n * schema declares — and derives everything from it here or in core: the grid filter\n * ({@link visiblePickerAssets}), the drop/upload split ({@link splitByAccept}), the\n * file-input attribute (`assetAcceptAttr`, core), and the commit filter\n * ({@link uploadBatchProgress}). An absent `accept` is unrestricted everywhere; there is\n * no hidden `image/*` default.\n */\n\n/**\n * The stage width preset the media browser mounts with (EC-432 / EC-431 AD-A):\n * the roomy `grid` measure (`min(1240px, 94vw)`) — browsing assets is spatial.\n * Exported so the geometry contract is pinnable without rendering the portal\n * (which is `null` in the node test env).\n */\nexport const ASSET_PICKER_STAGE_PRESET = 'grid' as const\n\n/**\n * The assets shown in the picker grid: the shipped search filter (EC-152) then\n * the `accept` filter (EC-432) — an image field's picker browses only images,\n * never the project's PDFs. Order follows the library.\n */\nexport function visiblePickerAssets(\n assets: readonly AssetRecord[],\n query: string,\n accept: readonly string[] | undefined,\n at: AssetReadLocale | null,\n): AssetRecord[] {\n return filterAssets(assets, query, at).filter((asset) => assetMatchesAccept(asset, accept))\n}\n\n/**\n * THE drop rule (EC-301 → EC-588): split files about to be uploaded into the ones the\n * field's `accept` admits and the NAMES of the ones it refuses. A drag-drop bypasses\n * the file dialog's soft filter, so every upload path — the field's drop zone, a drop\n * into the open picker, the picker's Upload dialog — passes through this, and the\n * caller names the refused files in a visible notice instead of uploading them.\n */\nexport function splitByAccept<F extends { name: string; type: string }>(\n files: readonly F[],\n accept: readonly string[] | undefined,\n): { accepted: F[]; rejected: string[] } {\n const accepted: F[] = []\n const rejected: string[] = []\n for (const file of files) {\n if (assetMatchesAccept({ contentType: file.type, filename: file.name }, accept)) accepted.push(file)\n else rejected.push(file.name)\n }\n return { accepted, rejected }\n}\n\n/**\n * One upload BATCH (EC-460): the upload-queue ids THIS interaction started.\n *\n * EC-588 A7: it used to be a pre-upload library snapshot, and whatever the library\n * gained since was committed — so an upload from another tab (re-listed with ours) or\n * from a sibling field's drop could land in this field. A batch now names exactly its\n * own uploads, and the store reports which asset each one landed as.\n */\nexport interface UploadBatch {\n uploadIds: readonly string[]\n}\n\n/** What batch progress reads from the assets store (`AssetsStore` satisfies it). */\nexport interface UploadSource {\n assets: readonly AssetRecord[]\n uploads: readonly { id: string; state: { phase: string } }[]\n /** The asset id an upload landed as, once its record is confirmed. */\n landedAssetId(uploadId: string): string | undefined\n}\n\nexport interface UploadBatchProgress {\n /** The batch's landed asset ids that the field accepts, in upload order. */\n added: string[]\n /**\n * The batch is finished: none of its uploads is still running, and every one that\n * landed is in the library. A failed (or dismissed) upload is terminal — it stays in\n * the queue for retry and is never awaited forever. Commit/attach decisions happen\n * only once settled for `many` targets; a single-select target commits on the first\n * arrival.\n */\n settled: boolean\n}\n\n/**\n * Where a batch stands. An upload is in one of four states: running (in the queue,\n * not failed), landed-but-not-listed (the store confirmed it, the library re-list has\n * not arrived), landed (attachable), or terminal (failed / dismissed). Only landed\n * uploads whose RECORD satisfies `accept` are `added` (A7: the commit is filtered,\n * not just the dialog). Pure — the picker and the asset field both drive their\n * effects with this.\n */\nexport function uploadBatchProgress(\n batch: UploadBatch,\n source: UploadSource,\n accept: readonly string[] | undefined,\n): UploadBatchProgress {\n const running = new Set(source.uploads.filter((u) => u.state.phase !== 'failed').map((u) => u.id))\n const library = new Map(source.assets.map((asset) => [asset.id, asset]))\n const added: string[] = []\n let pending = false\n for (const uploadId of batch.uploadIds) {\n if (running.has(uploadId)) {\n pending = true\n continue\n }\n const assetId = source.landedAssetId(uploadId)\n if (assetId === undefined) continue // failed or dismissed — terminal\n const record = library.get(assetId)\n if (!record) {\n pending = true // confirmed, but the library re-list has not landed yet\n continue\n }\n if (assetMatchesAccept(record, accept)) added.push(assetId)\n }\n return { added, settled: !pending }\n}\n\n/**\n * THE batch-attach rule (EC-588, ratified 2i: N files → N uploads → N placements\n * APPENDED, in the order the files were given), for every surface that uploads into a\n * field — the field's own drop zone and the picker's Upload / drop. What to attach now,\n * and whether the batch is done (disarm):\n * - a `many` target attaches nothing until the batch settles, then every landed upload\n * the field accepts, in upload order ({@link uploadBatchProgress}'s `added`). The\n * field's drop used to attach each arrival as it landed, so a second file landing\n * before the first was appended first (measured on the base: `[a2, a1]`);\n * - a single target takes the first accepted arrival at once (the rest stay in the\n * library, where they are visible), and disarms when the batch ends with none.\n */\nexport function batchAttachment(\n progress: UploadBatchProgress,\n many: boolean,\n): { attach: string[]; disarm: boolean } {\n if (many) return progress.settled ? { attach: progress.added, disarm: true } : { attach: [], disarm: false }\n const first = progress.added[0]\n if (first !== undefined) return { attach: [first], disarm: true }\n return { attach: [], disarm: progress.settled }\n}\n\n/** The picker's commit callbacks — a pick fires `onChange` then closes the stage. */\nexport interface PickerCommit {\n onChange: (assetId: string | null) => void\n onOpenChange: (open: boolean) => void\n}\n\n/**\n * Commit a picked asset (or a clear, `assetId === null`) and close the picker —\n * the selection semantic (click = pick, fire `onChange`, close). Both the grid\n * card and the Clear affordance route through this.\n */\nexport function commitPickerSelection(assetId: string | null, { onChange, onOpenChange }: PickerCommit): void {\n onChange(assetId)\n onOpenChange(false)\n}\n\n/** The multi-commit callbacks (EC-460): a settled upload batch on a `many` field. */\nexport interface PickerCommitMany {\n onChangeMany: (assetIds: string[]) => void\n onOpenChange: (open: boolean) => void\n}\n\n/**\n * Commit EVERY asset a settled upload batch added (EC-460) and close the picker —\n * the `many`-field counterpart of {@link commitPickerSelection}, so selecting N\n * files in one picker interaction attaches all N, not just the first to land.\n */\nexport function commitPickerSelectionMany(\n assetIds: string[],\n { onChangeMany, onOpenChange }: PickerCommitMany,\n): void {\n onChangeMany(assetIds)\n onOpenChange(false)\n}\n\n/**\n * The picker props a field's value position needs, derived from the field alone\n * (EC-570 #1 → EC-588): the selected id, the field's structured `accept`, whether it\n * holds many, and the commits — a pick through the carry rule (EC-558), a settled\n * upload batch appended for a `many` field (EC-460).\n */\nexport interface AssetPickerBinding {\n value: string | null\n accept?: readonly string[]\n multiple: boolean\n onChange: (assetId: string | null) => void\n onChangeMany?: (assetIds: string[]) => void\n}\n\n/**\n * ONE picker configuration for every surface that edits an asset field — the detail\n * editor and the table cell — so the two cannot drift. Before, the cell opened the\n * picker with no `accept`, no `multiple` and no batch commit: its grid offered PDFs to\n * an image field and an N-file upload attached one (EC-570 #1). `write` receives the\n * next stored value; the caller decides how to land it (form state, cell commit).\n */\nexport function assetPickerBinding(\n field: Pick<AssetFieldDef, 'multiple' | 'accept' | 'fields'>,\n value: unknown,\n write: (next: unknown) => void,\n): AssetPickerBinding {\n const multiple = field.multiple\n return {\n value: multiple ? null : singleAssetIdOf(value),\n ...(field.accept ? { accept: field.accept } : {}),\n multiple,\n onChange: (picked) => write(applyAssetSelection(value, picked, multiple)),\n ...(multiple ? { onChangeMany: (picked: string[]) => write(appendAssetSelections(value, picked)) } : {}),\n }\n}\n"]}
|
|
@@ -85,7 +85,9 @@ export function AssetPickerBrowser({ store, value, onOpenChange, onChange, onCha
|
|
|
85
85
|
// child boundaries — the same per-element dragenter/dragleave flicker the field
|
|
86
86
|
// fixes. Only hide when the count returns to zero.
|
|
87
87
|
const dragDepth = useRef(0);
|
|
88
|
-
|
|
88
|
+
// EC-659: the search reads the alts the picker shows — through the studio's asset lens.
|
|
89
|
+
const searchLocale = useAssetReadLocale();
|
|
90
|
+
const assets = visiblePickerAssets(store.assets, query, accept, searchLocale);
|
|
89
91
|
// Auto-select what an in-picker upload added, then close. A `many` consumer
|
|
90
92
|
// (multiple + onChangeMany) waits for the batch to SETTLE and commits every
|
|
91
93
|
// added id — uploading 2 files attaches 2 (EC-460); a single consumer keeps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asset-picker.js","sourceRoot":"","sources":["../../../src/components/cms/asset-picker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAEtD,OAAO,EAC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5D,QAAQ,CAAC,CAAC,CAAC,CACV,eAAM,SAAS,EAAC,8GAA8G,YAC5H,KAAC,KAAK,IAAC,SAAS,EAAC,QAAQ,GAAG,GACvB,CACR,CAAC,CAAC,CAAC,IAAI,IACH,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAC,8BAA8B,YACrD,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,GACzB,EAGP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAC,UAAU,YACjE,GAAG,IAAI,SAAS,CAAC,qBAAqB,CAAC,GACnC,IACA,CACV,CAAA;AACH,CAAC","sourcesContent":["import { AlertTriangle, Check, ImageIcon, Search, Upload } from 'lucide-react'\nimport { useEffect, useRef, useState } from 'react'\nimport { assetAcceptAttr, describeAccept } from '@elytracms/core/cms-core'\nimport { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord } from '@elytracms/core/persistence'\nimport {\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n ExpandableSurface,\n Input,\n Row,\n Spacer,\n Text,\n} from '@elytracms/studio/ui'\nimport { cn } from '../../lib/utils'\nimport { translate } from '../../lib/i18n'\nimport { AssetThumb } from '../assets/asset-thumb'\nimport { useAssetReadLocale } from '../assets/asset-locale'\nimport { AssetsProvider, useAssets, useOptionalAssets } from '../assets/assets-store'\nimport type { AssetsStore } from '../assets/assets-store'\nimport { useCollectionView } from '../collection-view/collection-view-context'\nimport {\n ASSET_PICKER_STAGE_PRESET,\n commitPickerSelection,\n batchAttachment,\n commitPickerSelectionMany,\n splitByAccept,\n uploadBatchProgress,\n visiblePickerAssets,\n} from './asset-picker-core'\nimport type { UploadBatch } from './asset-picker-core'\n\n/** The picker's props — see {@link AssetPicker}. */\nexport interface AssetPickerProps {\n value: string | null\n open: boolean\n onOpenChange: (open: boolean) => void\n onChange: (assetId: string | null) => void\n /** EC-460: commit a whole settled upload batch (a `many` field passes this). */\n onChangeMany?: (assetIds: string[]) => void\n /** Whether the consuming field holds many assets (enables batch commit). */\n multiple?: boolean\n /** The field's `accept` list (EC-588) — absent means any file. */\n accept?: readonly string[]\n}\n\n/**\n * Pick an asset for a CMS `asset` field (brief §8.4, §8.6, EC-075 → EC-152).\n * Backed by the *real* asset library (the assets store over the operations\n * client) — the same records the Assets section lists — not by fixture\n * documents. Selecting stores the asset id on the document field.\n *\n * EC-432 (AD-C): the picker is a real MEDIA BROWSER on the {@link ExpandableSurface}\n * `stage` (`grid` preset — `min(1240px, 94vw)`, near-full height), replacing the\n * old `max-w-md` (448px) Dialog. It reuses the shipped assets-rail machinery: the\n * assets store, the EC-152 search, the EC-400 thumb tile ({@link AssetThumb}), and\n * the upload-then-select path. It is a SELECTION browser, not a form — click = pick\n * (fires `onChange`, closes) plus the shipped clear/cancel affordances; the\n * forms-never-modal rule governs document forms and is untouched. Opened from the\n * expanded rich-text stage toolbar it rides ABOVE that stage on the EC-392 layer\n * stack — Escape closes the browser first, the rich-text stage stays.\n *\n * The component CONTRACT (`{ open, onOpenChange, value, accept, onChange }`) serves\n * every call site — asset fields, rich-text image insertion, editable cells. EC-460\n * adds an OPTIONAL multi-commit pair (`multiple` + `onChangeMany`): a `many` asset\n * field passes both so uploading N files in ONE picker interaction attaches ALL N\n * (the old flow committed the first upload to land and closed — the rest reached the\n * library but never the field, silent partial data loss). Grid clicks stay\n * single-pick-and-close in every mode.\n *\n * EC-588: `accept` is the field's STRUCTURED list (it was a file-input string that the\n * core re-split — two shapes for one fact). The grid filter, the file-input attribute\n * and the drop/upload split all derive from it, and an absent `accept` is unrestricted\n * everywhere (the Upload dialog used to fall back to `image/*`). A field-backed caller\n * passes `assetPickerBinding`'s output (`asset-picker-core`) rather than wiring props\n * by hand.\n */\nexport function AssetPicker({\n value,\n open,\n onOpenChange,\n onChange,\n onChangeMany,\n multiple = false,\n accept,\n}: AssetPickerProps) {\n const source = useCollectionView()\n const ambient = useOptionalAssets()\n // Mount nothing while closed: the self-provided assets store would\n // otherwise load the library eagerly for every asset field on the form.\n if (!open) return null\n if (ambient) {\n return (\n <AssetPickerStage\n value={value}\n onOpenChange={onOpenChange}\n onChange={onChange}\n {...(onChangeMany ? { onChangeMany } : {})}\n multiple={multiple}\n accept={accept}\n />\n )\n }\n if (source.projectId === undefined) {\n // No project scope (fixture-only CMS session): the library is\n // unreachable — say so instead of silently showing nothing.\n return (\n <Dialog open onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-md\">\n <DialogHeader>\n <DialogTitle>{translate('cms.asset.pickTitle')}</DialogTitle>\n <DialogDescription>{translate('cms.asset.pickDescription')}</DialogDescription>\n </DialogHeader>\n <Row gap=\"2\" data-testid=\"asset-picker-no-project\">\n <AlertTriangle className=\"size-4 text-warning\" />\n <Text size=\"sm\" tone=\"muted\">\n {translate('cms.asset.noProject')}\n </Text>\n </Row>\n </DialogContent>\n </Dialog>\n )\n }\n return (\n <AssetsProvider projectId={source.projectId}>\n <AssetPickerStage\n value={value}\n onOpenChange={onOpenChange}\n onChange={onChange}\n {...(onChangeMany ? { onChangeMany } : {})}\n multiple={multiple}\n accept={accept}\n />\n </AssetsProvider>\n )\n}\n\n/** The open media-browser stage over a mounted assets store. */\nfunction AssetPickerStage(props: Omit<AssetPickerProps, 'open'>) {\n const store = useAssets()\n return (\n <ExpandableSurface\n title={translate('cms.asset.pickTitle')}\n closeLabel={translate('common.close')}\n variant=\"stage\"\n preset={ASSET_PICKER_STAGE_PRESET}\n onDismiss={() => props.onOpenChange(false)}\n headerLeading={<ImageIcon className=\"size-4 text-muted-foreground\" aria-hidden />}\n >\n <AssetPickerBrowser store={store} {...props} />\n </ExpandableSurface>\n )\n}\n\n/** The slice of the assets store the browser reads and drives. */\nexport type AssetPickerStore = Pick<\n AssetsStore,\n 'status' | 'errorMessage' | 'assets' | 'uploads' | 'upload' | 'landedAssetId'\n>\n\n/**\n * The media browser itself — search, Upload, the grid, the drop zone — rendered inside\n * the stage. A named component of its own (EC-588) so its markup is reachable by a\n * node-env smoke render (the stage portal is `null` there): the file input's `accept`\n * attribute and the grid's filter are pinned against the field's `accept`.\n */\nexport function AssetPickerBrowser({\n store,\n value,\n onOpenChange,\n onChange,\n onChangeMany,\n multiple = false,\n accept,\n}: Omit<AssetPickerProps, 'open'> & { store: AssetPickerStore }) {\n // Fresh per open: the picker unmounts entirely while closed.\n const [query, setQuery] = useState('')\n const [dragging, setDragging] = useState(false)\n // Names of files a drop/upload refused against the field's `accept` (EC-588) — shown\n // as a visible notice and never uploaded. Cleared by the next upload attempt.\n const [rejected, setRejected] = useState<string[]>([])\n const fileInputRef = useRef<HTMLInputElement>(null)\n // The active upload BATCH (EC-460): exactly the upload ids this interaction started\n // (EC-588 A7), so the effect below attaches this batch's uploads and nothing else.\n const pendingRef = useRef<UploadBatch | null>(null)\n // Drag depth (EC-301): keeps the drop overlay steady as the pointer crosses\n // child boundaries — the same per-element dragenter/dragleave flicker the field\n // fixes. Only hide when the count returns to zero.\n const dragDepth = useRef(0)\n const assets = visiblePickerAssets(store.assets, query, accept)\n\n // Auto-select what an in-picker upload added, then close. A `many` consumer\n // (multiple + onChangeMany) waits for the batch to SETTLE and commits every\n // added id — uploading 2 files attaches 2 (EC-460); a single consumer keeps\n // the first-to-land commit. Only uploads whose record satisfies `accept` commit.\n useEffect(() => {\n const batch = pendingRef.current\n if (!batch) return\n // EC-588 2i: the one batch-attach rule the field's own drop zone runs too.\n const many = multiple === true && onChangeMany !== undefined\n const { attach, disarm } = batchAttachment(uploadBatchProgress(batch, store, accept), many)\n if (disarm) pendingRef.current = null\n if (attach.length === 0) return\n if (many) commitPickerSelectionMany(attach, { onChangeMany, onOpenChange })\n else commitPickerSelection(attach[0]!, { onChange, onOpenChange })\n }, [store, accept, multiple, onChange, onChangeMany, onOpenChange])\n\n function handleUpload(files: File[]) {\n if (files.length === 0) return\n // EC-588: the drop rule — the same split the field's drop zone uses. A drop\n // bypasses the dialog's soft filter; refused files are named, never uploaded.\n const { accepted, rejected: refused } = splitByAccept(files, accept)\n setRejected(refused)\n if (accepted.length === 0) return\n pendingRef.current = { uploadIds: store.upload(accepted) }\n }\n // The stage portals to document.body, but React synthetic events still bubble up\n // the COMPONENT tree — and this picker is rendered as a child of the asset field,\n // which has its own drag-to-upload handlers. Without stopPropagation a drop inside\n // the stage would fire BOTH the picker's and the field's `onDrop`, uploading the\n // file twice. Stop every DnD event here so the picker owns its drop entirely.\n function onDragEnter(e: React.DragEvent) {\n e.preventDefault()\n e.stopPropagation()\n dragDepth.current += 1\n if (!dragging) setDragging(true)\n }\n function onDragOver(e: React.DragEvent) {\n e.preventDefault()\n e.stopPropagation()\n }\n function onDragLeave(e: React.DragEvent) {\n e.stopPropagation()\n dragDepth.current -= 1\n if (dragDepth.current <= 0) {\n dragDepth.current = 0\n setDragging(false)\n }\n }\n function onDrop(e: React.DragEvent) {\n e.preventDefault()\n e.stopPropagation()\n dragDepth.current = 0\n setDragging(false)\n handleUpload(Array.from(e.dataTransfer.files))\n }\n\n return (\n <div\n className=\"relative flex min-h-0 flex-1 flex-col gap-3 p-4\"\n onDragEnter={onDragEnter}\n onDragOver={onDragOver}\n onDragLeave={onDragLeave}\n onDrop={onDrop}\n >\n <Row gap=\"2\" align=\"center\">\n <span className=\"relative flex-1\">\n <Search className=\"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground\" />\n <Input\n autoFocus\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={translate('cms.asset.searchPlaceholder')}\n className=\"pl-8\"\n data-testid=\"asset-picker-search\"\n />\n </span>\n <Button variant=\"outline\" size=\"sm\" onClick={() => fileInputRef.current?.click()}>\n <Upload /> {translate('common.upload')}\n </Button>\n <input\n ref={fileInputRef}\n type=\"file\"\n multiple\n accept={assetAcceptAttr(accept)}\n className=\"hidden\"\n data-testid=\"asset-picker-file-input\"\n onChange={(e) => {\n handleUpload(Array.from(e.target.files ?? []))\n e.target.value = ''\n }}\n />\n </Row>\n\n <AssetRejectedNotice rejected={rejected} accept={accept} />\n\n <div\n className=\"grid min-h-0 flex-1 auto-rows-min grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5\"\n data-testid=\"asset-picker-grid\"\n >\n {store.status === 'loading' ? (\n <Text size=\"sm\" tone=\"muted\" className=\"col-span-full p-3\">\n {translate('cms.asset.loading')}\n </Text>\n ) : store.status === 'error' ? (\n <Row gap=\"2\" className=\"col-span-full p-3\" data-testid=\"asset-picker-error\">\n <AlertTriangle className=\"size-4 text-destructive\" />\n <Text size=\"sm\" tone=\"muted\">\n {store.errorMessage ?? translate('cms.asset.loadError')}\n </Text>\n </Row>\n ) : assets.length === 0 ? (\n <Text size=\"sm\" tone=\"muted\" className=\"col-span-full p-3\">\n {query.trim() ? translate('cms.asset.noMatches') : translate('cms.asset.empty')}\n </Text>\n ) : (\n assets.map((asset) => (\n <AssetPickerCard\n key={asset.id}\n asset={asset}\n selected={asset.id === value}\n onPick={() => commitPickerSelection(asset.id, { onChange, onOpenChange })}\n />\n ))\n )}\n </div>\n\n <Row gap=\"2\">\n <Spacer />\n {value ? (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => commitPickerSelection(null, { onChange, onOpenChange })}\n >\n {translate('common.clear')}\n </Button>\n ) : null}\n </Row>\n\n {dragging ? (\n <div className=\"pointer-events-none absolute inset-0 z-10 grid place-items-center rounded-lg border-2 border-dashed border-primary bg-background/85\">\n <Row gap=\"2\" align=\"center\">\n <Upload className=\"size-5 text-primary\" />\n <Text className=\"font-medium\">{translate('cms.asset.dropToUpload')}</Text>\n </Row>\n </div>\n ) : null}\n </div>\n )\n}\n\n/**\n * The visible notice for files an upload path refused against the field's `accept`\n * (EC-301 → EC-588): named, never silently dropped. Shared by the field's drop zone and\n * the picker, which apply the same rule. Renders nothing when nothing was refused.\n */\nexport function AssetRejectedNotice({\n rejected,\n accept,\n}: {\n rejected: readonly string[]\n accept: readonly string[] | undefined\n}) {\n if (rejected.length === 0) return null\n return (\n <Row gap=\"2\" align=\"center\" data-testid=\"asset-rejected-notice\">\n <AlertTriangle className=\"size-4 shrink-0 text-warning\" />\n <Text size=\"xs\" tone=\"muted\">\n {rejected.length === 1\n ? translate('cms.asset.rejected.one', { name: rejected[0]!, types: describeAccept(accept) })\n : translate('cms.asset.rejected.other', {\n count: rejected.length,\n types: describeAccept(accept),\n })}\n </Text>\n </Row>\n )\n}\n\n/** One selectable asset: EC-400 thumb tile + title/filename + alt text. The\n * internal asset id is intentionally not shown — it's noise to editors (EC-301). */\nfunction AssetPickerCard({\n asset,\n selected,\n onPick,\n}: {\n asset: AssetRecord\n selected: boolean\n onPick: () => void\n}) {\n const alt = assetAlt(asset, useAssetReadLocale())\n return (\n <button\n type=\"button\"\n onClick={onPick}\n className={cn(\n 'flex flex-col gap-1.5 rounded-lg border p-2 text-left transition-colors',\n selected ? 'border-primary bg-primary/5' : 'border-border hover:bg-muted',\n )}\n data-testid=\"asset-picker-card\"\n aria-pressed={selected}\n >\n <span className=\"relative block\">\n <AssetThumb record={asset} className=\"aspect-video w-full\" />\n {selected ? (\n <span className=\"absolute right-1 top-1 grid size-5 place-items-center rounded-full bg-primary text-primary-foreground shadow\">\n <Check className=\"size-3\" />\n </span>\n ) : null}\n </span>\n <Text size=\"xs\" className=\"min-w-0 truncate font-medium\">\n {asset.title ?? asset.filename}\n </Text>\n {/* EC-587 (ASSETS D20): the asset's alt through THE reader, as delivery serves it —\n EC-632: in the studio's locale. */}\n <Text size=\"xs\" tone={alt ? 'muted' : 'subtle'} className=\"truncate\">\n {alt || translate('cms.asset.noAltText')}\n </Text>\n </button>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"asset-picker.js","sourceRoot":"","sources":["../../../src/components/cms/asset-picker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,KAA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kB,EAAE,CAAC,CAAA;IACjD,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,EACb,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,EAAE,CACX,yEAAyE,EACzE,QAAQ,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,8BAA8B,CAC1E,iBACW,mBAAmB,kBACjB,QAAQ,aAEtB,gBAAM,SAAS,EAAC,gBAAgB,aAC9B,KAAC,UAAU,IAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAC,qBAAqB,GAAG,EAC5D,QAAQ,CAAC,CAAC,CAAC,CACV,eAAM,SAAS,EAAC,8GAA8G,YAC5H,KAAC,KAAK,IAAC,SAAS,EAAC,QAAQ,GAAG,GACvB,CACR,CAAC,CAAC,CAAC,IAAI,IACH,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAC,8BAA8B,YACrD,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,QAAQ,GACzB,EAGP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAC,UAAU,YACjE,GAAG,IAAI,SAAS,CAAC,qBAAqB,CAAC,GACnC,IACA,CACV,CAAA;AACH,CAAC","sourcesContent":["import { AlertTriangle, Check, ImageIcon, Search, Upload } from 'lucide-react'\nimport { useEffect, useRef, useState } from 'react'\nimport { assetAcceptAttr, describeAccept } from '@elytracms/core/cms-core'\nimport { assetAlt } from '@elytracms/core/persistence'\nimport type { AssetRecord } from '@elytracms/core/persistence'\nimport {\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogHeader,\n DialogTitle,\n ExpandableSurface,\n Input,\n Row,\n Spacer,\n Text,\n} from '@elytracms/studio/ui'\nimport { cn } from '../../lib/utils'\nimport { translate } from '../../lib/i18n'\nimport { AssetThumb } from '../assets/asset-thumb'\nimport { useAssetReadLocale } from '../assets/asset-locale'\nimport { AssetsProvider, useAssets, useOptionalAssets } from '../assets/assets-store'\nimport type { AssetsStore } from '../assets/assets-store'\nimport { useCollectionView } from '../collection-view/collection-view-context'\nimport {\n ASSET_PICKER_STAGE_PRESET,\n commitPickerSelection,\n batchAttachment,\n commitPickerSelectionMany,\n splitByAccept,\n uploadBatchProgress,\n visiblePickerAssets,\n} from './asset-picker-core'\nimport type { UploadBatch } from './asset-picker-core'\n\n/** The picker's props — see {@link AssetPicker}. */\nexport interface AssetPickerProps {\n value: string | null\n open: boolean\n onOpenChange: (open: boolean) => void\n onChange: (assetId: string | null) => void\n /** EC-460: commit a whole settled upload batch (a `many` field passes this). */\n onChangeMany?: (assetIds: string[]) => void\n /** Whether the consuming field holds many assets (enables batch commit). */\n multiple?: boolean\n /** The field's `accept` list (EC-588) — absent means any file. */\n accept?: readonly string[]\n}\n\n/**\n * Pick an asset for a CMS `asset` field (brief §8.4, §8.6, EC-075 → EC-152).\n * Backed by the *real* asset library (the assets store over the operations\n * client) — the same records the Assets section lists — not by fixture\n * documents. Selecting stores the asset id on the document field.\n *\n * EC-432 (AD-C): the picker is a real MEDIA BROWSER on the {@link ExpandableSurface}\n * `stage` (`grid` preset — `min(1240px, 94vw)`, near-full height), replacing the\n * old `max-w-md` (448px) Dialog. It reuses the shipped assets-rail machinery: the\n * assets store, the EC-152 search, the EC-400 thumb tile ({@link AssetThumb}), and\n * the upload-then-select path. It is a SELECTION browser, not a form — click = pick\n * (fires `onChange`, closes) plus the shipped clear/cancel affordances; the\n * forms-never-modal rule governs document forms and is untouched. Opened from the\n * expanded rich-text stage toolbar it rides ABOVE that stage on the EC-392 layer\n * stack — Escape closes the browser first, the rich-text stage stays.\n *\n * The component CONTRACT (`{ open, onOpenChange, value, accept, onChange }`) serves\n * every call site — asset fields, rich-text image insertion, editable cells. EC-460\n * adds an OPTIONAL multi-commit pair (`multiple` + `onChangeMany`): a `many` asset\n * field passes both so uploading N files in ONE picker interaction attaches ALL N\n * (the old flow committed the first upload to land and closed — the rest reached the\n * library but never the field, silent partial data loss). Grid clicks stay\n * single-pick-and-close in every mode.\n *\n * EC-588: `accept` is the field's STRUCTURED list (it was a file-input string that the\n * core re-split — two shapes for one fact). The grid filter, the file-input attribute\n * and the drop/upload split all derive from it, and an absent `accept` is unrestricted\n * everywhere (the Upload dialog used to fall back to `image/*`). A field-backed caller\n * passes `assetPickerBinding`'s output (`asset-picker-core`) rather than wiring props\n * by hand.\n */\nexport function AssetPicker({\n value,\n open,\n onOpenChange,\n onChange,\n onChangeMany,\n multiple = false,\n accept,\n}: AssetPickerProps) {\n const source = useCollectionView()\n const ambient = useOptionalAssets()\n // Mount nothing while closed: the self-provided assets store would\n // otherwise load the library eagerly for every asset field on the form.\n if (!open) return null\n if (ambient) {\n return (\n <AssetPickerStage\n value={value}\n onOpenChange={onOpenChange}\n onChange={onChange}\n {...(onChangeMany ? { onChangeMany } : {})}\n multiple={multiple}\n accept={accept}\n />\n )\n }\n if (source.projectId === undefined) {\n // No project scope (fixture-only CMS session): the library is\n // unreachable — say so instead of silently showing nothing.\n return (\n <Dialog open onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-md\">\n <DialogHeader>\n <DialogTitle>{translate('cms.asset.pickTitle')}</DialogTitle>\n <DialogDescription>{translate('cms.asset.pickDescription')}</DialogDescription>\n </DialogHeader>\n <Row gap=\"2\" data-testid=\"asset-picker-no-project\">\n <AlertTriangle className=\"size-4 text-warning\" />\n <Text size=\"sm\" tone=\"muted\">\n {translate('cms.asset.noProject')}\n </Text>\n </Row>\n </DialogContent>\n </Dialog>\n )\n }\n return (\n <AssetsProvider projectId={source.projectId}>\n <AssetPickerStage\n value={value}\n onOpenChange={onOpenChange}\n onChange={onChange}\n {...(onChangeMany ? { onChangeMany } : {})}\n multiple={multiple}\n accept={accept}\n />\n </AssetsProvider>\n )\n}\n\n/** The open media-browser stage over a mounted assets store. */\nfunction AssetPickerStage(props: Omit<AssetPickerProps, 'open'>) {\n const store = useAssets()\n return (\n <ExpandableSurface\n title={translate('cms.asset.pickTitle')}\n closeLabel={translate('common.close')}\n variant=\"stage\"\n preset={ASSET_PICKER_STAGE_PRESET}\n onDismiss={() => props.onOpenChange(false)}\n headerLeading={<ImageIcon className=\"size-4 text-muted-foreground\" aria-hidden />}\n >\n <AssetPickerBrowser store={store} {...props} />\n </ExpandableSurface>\n )\n}\n\n/** The slice of the assets store the browser reads and drives. */\nexport type AssetPickerStore = Pick<\n AssetsStore,\n 'status' | 'errorMessage' | 'assets' | 'uploads' | 'upload' | 'landedAssetId'\n>\n\n/**\n * The media browser itself — search, Upload, the grid, the drop zone — rendered inside\n * the stage. A named component of its own (EC-588) so its markup is reachable by a\n * node-env smoke render (the stage portal is `null` there): the file input's `accept`\n * attribute and the grid's filter are pinned against the field's `accept`.\n */\nexport function AssetPickerBrowser({\n store,\n value,\n onOpenChange,\n onChange,\n onChangeMany,\n multiple = false,\n accept,\n}: Omit<AssetPickerProps, 'open'> & { store: AssetPickerStore }) {\n // Fresh per open: the picker unmounts entirely while closed.\n const [query, setQuery] = useState('')\n const [dragging, setDragging] = useState(false)\n // Names of files a drop/upload refused against the field's `accept` (EC-588) — shown\n // as a visible notice and never uploaded. Cleared by the next upload attempt.\n const [rejected, setRejected] = useState<string[]>([])\n const fileInputRef = useRef<HTMLInputElement>(null)\n // The active upload BATCH (EC-460): exactly the upload ids this interaction started\n // (EC-588 A7), so the effect below attaches this batch's uploads and nothing else.\n const pendingRef = useRef<UploadBatch | null>(null)\n // Drag depth (EC-301): keeps the drop overlay steady as the pointer crosses\n // child boundaries — the same per-element dragenter/dragleave flicker the field\n // fixes. Only hide when the count returns to zero.\n const dragDepth = useRef(0)\n // EC-659: the search reads the alts the picker shows — through the studio's asset lens.\n const searchLocale = useAssetReadLocale()\n const assets = visiblePickerAssets(store.assets, query, accept, searchLocale)\n\n // Auto-select what an in-picker upload added, then close. A `many` consumer\n // (multiple + onChangeMany) waits for the batch to SETTLE and commits every\n // added id — uploading 2 files attaches 2 (EC-460); a single consumer keeps\n // the first-to-land commit. Only uploads whose record satisfies `accept` commit.\n useEffect(() => {\n const batch = pendingRef.current\n if (!batch) return\n // EC-588 2i: the one batch-attach rule the field's own drop zone runs too.\n const many = multiple === true && onChangeMany !== undefined\n const { attach, disarm } = batchAttachment(uploadBatchProgress(batch, store, accept), many)\n if (disarm) pendingRef.current = null\n if (attach.length === 0) return\n if (many) commitPickerSelectionMany(attach, { onChangeMany, onOpenChange })\n else commitPickerSelection(attach[0]!, { onChange, onOpenChange })\n }, [store, accept, multiple, onChange, onChangeMany, onOpenChange])\n\n function handleUpload(files: File[]) {\n if (files.length === 0) return\n // EC-588: the drop rule — the same split the field's drop zone uses. A drop\n // bypasses the dialog's soft filter; refused files are named, never uploaded.\n const { accepted, rejected: refused } = splitByAccept(files, accept)\n setRejected(refused)\n if (accepted.length === 0) return\n pendingRef.current = { uploadIds: store.upload(accepted) }\n }\n // The stage portals to document.body, but React synthetic events still bubble up\n // the COMPONENT tree — and this picker is rendered as a child of the asset field,\n // which has its own drag-to-upload handlers. Without stopPropagation a drop inside\n // the stage would fire BOTH the picker's and the field's `onDrop`, uploading the\n // file twice. Stop every DnD event here so the picker owns its drop entirely.\n function onDragEnter(e: React.DragEvent) {\n e.preventDefault()\n e.stopPropagation()\n dragDepth.current += 1\n if (!dragging) setDragging(true)\n }\n function onDragOver(e: React.DragEvent) {\n e.preventDefault()\n e.stopPropagation()\n }\n function onDragLeave(e: React.DragEvent) {\n e.stopPropagation()\n dragDepth.current -= 1\n if (dragDepth.current <= 0) {\n dragDepth.current = 0\n setDragging(false)\n }\n }\n function onDrop(e: React.DragEvent) {\n e.preventDefault()\n e.stopPropagation()\n dragDepth.current = 0\n setDragging(false)\n handleUpload(Array.from(e.dataTransfer.files))\n }\n\n return (\n <div\n className=\"relative flex min-h-0 flex-1 flex-col gap-3 p-4\"\n onDragEnter={onDragEnter}\n onDragOver={onDragOver}\n onDragLeave={onDragLeave}\n onDrop={onDrop}\n >\n <Row gap=\"2\" align=\"center\">\n <span className=\"relative flex-1\">\n <Search className=\"pointer-events-none absolute left-2.5 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground\" />\n <Input\n autoFocus\n value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={translate('cms.asset.searchPlaceholder')}\n className=\"pl-8\"\n data-testid=\"asset-picker-search\"\n />\n </span>\n <Button variant=\"outline\" size=\"sm\" onClick={() => fileInputRef.current?.click()}>\n <Upload /> {translate('common.upload')}\n </Button>\n <input\n ref={fileInputRef}\n type=\"file\"\n multiple\n accept={assetAcceptAttr(accept)}\n className=\"hidden\"\n data-testid=\"asset-picker-file-input\"\n onChange={(e) => {\n handleUpload(Array.from(e.target.files ?? []))\n e.target.value = ''\n }}\n />\n </Row>\n\n <AssetRejectedNotice rejected={rejected} accept={accept} />\n\n <div\n className=\"grid min-h-0 flex-1 auto-rows-min grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5\"\n data-testid=\"asset-picker-grid\"\n >\n {store.status === 'loading' ? (\n <Text size=\"sm\" tone=\"muted\" className=\"col-span-full p-3\">\n {translate('cms.asset.loading')}\n </Text>\n ) : store.status === 'error' ? (\n <Row gap=\"2\" className=\"col-span-full p-3\" data-testid=\"asset-picker-error\">\n <AlertTriangle className=\"size-4 text-destructive\" />\n <Text size=\"sm\" tone=\"muted\">\n {store.errorMessage ?? translate('cms.asset.loadError')}\n </Text>\n </Row>\n ) : assets.length === 0 ? (\n <Text size=\"sm\" tone=\"muted\" className=\"col-span-full p-3\">\n {query.trim() ? translate('cms.asset.noMatches') : translate('cms.asset.empty')}\n </Text>\n ) : (\n assets.map((asset) => (\n <AssetPickerCard\n key={asset.id}\n asset={asset}\n selected={asset.id === value}\n onPick={() => commitPickerSelection(asset.id, { onChange, onOpenChange })}\n />\n ))\n )}\n </div>\n\n <Row gap=\"2\">\n <Spacer />\n {value ? (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => commitPickerSelection(null, { onChange, onOpenChange })}\n >\n {translate('common.clear')}\n </Button>\n ) : null}\n </Row>\n\n {dragging ? (\n <div className=\"pointer-events-none absolute inset-0 z-10 grid place-items-center rounded-lg border-2 border-dashed border-primary bg-background/85\">\n <Row gap=\"2\" align=\"center\">\n <Upload className=\"size-5 text-primary\" />\n <Text className=\"font-medium\">{translate('cms.asset.dropToUpload')}</Text>\n </Row>\n </div>\n ) : null}\n </div>\n )\n}\n\n/**\n * The visible notice for files an upload path refused against the field's `accept`\n * (EC-301 → EC-588): named, never silently dropped. Shared by the field's drop zone and\n * the picker, which apply the same rule. Renders nothing when nothing was refused.\n */\nexport function AssetRejectedNotice({\n rejected,\n accept,\n}: {\n rejected: readonly string[]\n accept: readonly string[] | undefined\n}) {\n if (rejected.length === 0) return null\n return (\n <Row gap=\"2\" align=\"center\" data-testid=\"asset-rejected-notice\">\n <AlertTriangle className=\"size-4 shrink-0 text-warning\" />\n <Text size=\"xs\" tone=\"muted\">\n {rejected.length === 1\n ? translate('cms.asset.rejected.one', { name: rejected[0]!, types: describeAccept(accept) })\n : translate('cms.asset.rejected.other', {\n count: rejected.length,\n types: describeAccept(accept),\n })}\n </Text>\n </Row>\n )\n}\n\n/** One selectable asset: EC-400 thumb tile + title/filename + alt text. The\n * internal asset id is intentionally not shown — it's noise to editors (EC-301). */\nfunction AssetPickerCard({\n asset,\n selected,\n onPick,\n}: {\n asset: AssetRecord\n selected: boolean\n onPick: () => void\n}) {\n const alt = assetAlt(asset, useAssetReadLocale())\n return (\n <button\n type=\"button\"\n onClick={onPick}\n className={cn(\n 'flex flex-col gap-1.5 rounded-lg border p-2 text-left transition-colors',\n selected ? 'border-primary bg-primary/5' : 'border-border hover:bg-muted',\n )}\n data-testid=\"asset-picker-card\"\n aria-pressed={selected}\n >\n <span className=\"relative block\">\n <AssetThumb record={asset} className=\"aspect-video w-full\" />\n {selected ? (\n <span className=\"absolute right-1 top-1 grid size-5 place-items-center rounded-full bg-primary text-primary-foreground shadow\">\n <Check className=\"size-3\" />\n </span>\n ) : null}\n </span>\n <Text size=\"xs\" className=\"min-w-0 truncate font-medium\">\n {asset.title ?? asset.filename}\n </Text>\n {/* EC-587 (ASSETS D20): the asset's alt through THE reader, as delivery serves it —\n EC-632: in the studio's locale. */}\n <Text size=\"xs\" tone={alt ? 'muted' : 'subtle'} className=\"truncate\">\n {alt || translate('cms.asset.noAltText')}\n </Text>\n </button>\n )\n}\n"]}
|
|
@@ -46,11 +46,17 @@ export declare function isCanvasControlKey(key: string): boolean;
|
|
|
46
46
|
* Anything else — a canvas action, a discrete control, an edit with no control focused —
|
|
47
47
|
* commits now (`committed`), after any canvas position still uncommitted, so positions
|
|
48
48
|
* reach the persister in the order the editor made them.
|
|
49
|
+
*
|
|
50
|
+
* EC-647: `revision` is the revision of the canvas value the write was authored on (its
|
|
51
|
+
* lift's) — the deferred position's base on its first keystroke, as `commitNow`'s caller
|
|
52
|
+
* pairs it with the patches it sends; never the draft's (which may be newer).
|
|
49
53
|
*/
|
|
50
54
|
export declare function routeCanvasWrite(input: {
|
|
51
55
|
patches: readonly DocumentPatch[];
|
|
52
56
|
/** The focused canvas control, if focus is on one. */
|
|
53
57
|
focused: CanvasControl | undefined;
|
|
54
58
|
committer: DraftCommitter;
|
|
59
|
+
/** The revision the write was authored against (the canvas lift's). */
|
|
60
|
+
revision: number | undefined;
|
|
55
61
|
commitNow: (patches: readonly DocumentPatch[]) => void;
|
|
56
62
|
}): 'deferred' | 'committed';
|
|
@@ -20,11 +20,15 @@ function writesExactly(patch, path) {
|
|
|
20
20
|
* Anything else — a canvas action, a discrete control, an edit with no control focused —
|
|
21
21
|
* commits now (`committed`), after any canvas position still uncommitted, so positions
|
|
22
22
|
* reach the persister in the order the editor made them.
|
|
23
|
+
*
|
|
24
|
+
* EC-647: `revision` is the revision of the canvas value the write was authored on (its
|
|
25
|
+
* lift's) — the deferred position's base on its first keystroke, as `commitNow`'s caller
|
|
26
|
+
* pairs it with the patches it sends; never the draft's (which may be newer).
|
|
23
27
|
*/
|
|
24
28
|
export function routeCanvasWrite(input) {
|
|
25
29
|
const { patches, focused, committer } = input;
|
|
26
30
|
if (focused && focused.policy !== 'change' && patches.length === 1 && writesExactly(patches[0], focused.path)) {
|
|
27
|
-
committer.edited(focused.key, focused.path);
|
|
31
|
+
committer.edited(focused.key, focused.path, { base: input.revision });
|
|
28
32
|
return 'deferred';
|
|
29
33
|
}
|
|
30
34
|
if (committer.uncommitted().some((position) => isCanvasControlKey(position.field)))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-commit.js","sourceRoot":"","sources":["../../../src/components/cms/canvas-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAqC1D,6GAA6G;AAC7G,MAAM,UAAU,aAAa,CAAC,KAAgB,EAAE,QAA+B,EAAE,MAAoB;IACnG,MAAM,IAAI,GACR,MAAM,IAAI,QAAQ;QAChB,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxF,CAAC,CAAC,KAAK,CAAA;IACX,OAAO,EAAE,GAAG,EAAE,UAAU,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AACjE,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,OAAO,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;AAClC,CAAC;AAED,SAAS,aAAa,CAAC,KAAoB,EAAE,IAAe;IAC1D,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,KAAK,CAAC,EAAE,KAAK,OAAO,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,K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AC,OAAO,CAAC,CAAC,CAAE,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/G,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;QACrE,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAAE,SAAS,CAAC,SAAS,EAAE,CAAA;IACzG,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACxB,OAAO,WAAW,CAAA;AACpB,CAAC","sourcesContent":["import { formatValuePath } from '@elytracms/core/cms-core'\nimport type { DocumentPatch, ValuePath } from '@elytracms/core/cms-core'\nimport type { CommitPolicy } from './commit-policy'\nimport type { DraftCommitter } from './draft-commit'\n\n/**\n * EC-630 — the canvas inspector commits like every other editor: on its control kind's\n * quiescence policy (`commit-policy.ts`, EC-595 A2), never per keystroke (pure; the house\n * pattern).\n *\n * The canvas lifts every store change into the draft at once (live validation reads it).\n * A burst of typing in an inspector control used to be committed per keystroke too —\n * every canvas write went straight to the persister under the canvas's `change` policy:\n * 13 revisions for one typography-run edit, measured live (wave-0094), and one per\n * keystroke on any text prop. The canvas's own actions (insert, move, delete, undo, a\n * discrete control) ARE discrete commits; a control's typing is not. So the inspector\n * controls stand inside a commit boundary (focus / blur / Enter, the form's\n * `FieldCommitBoundary`) at a POSITION — a node's prop, or a typography run, which is\n * the field itself (prose is one position, EC-595 binding point 3) — with the policy\n * THE declaration gives that control kind (`commitPolicyOf`), and THE committer\n * (`draft-commit.ts`, shared with the form fields) holds the burst as that position's\n * uncommitted edit: committed on blur, Enter or the idle pause, with the base revision\n * of its first keystroke, overlaid on every rebase meanwhile, and in every forced flush.\n */\n\n/** Where a canvas inspector control writes: a node's prop, or a typography run (the field). */\nexport type CanvasControlPosition = { readonly node: string; readonly prop: string } | { readonly run: number }\n\n/** A focused canvas inspector control, as the committer knows it. */\nexport interface CanvasControl {\n /** The committer's key for it (never a field name — those carry no `:`). */\n readonly key: string\n /** The position it writes. */\n readonly path: ValuePath\n readonly policy: CommitPolicy\n}\n\n/** The control at `position` of the canvas field at `field` (the field's position path, locale included). */\nexport function canvasControl(field: ValuePath, position: CanvasControlPosition, policy: CommitPolicy): CanvasControl {\n const path: ValuePath =\n 'node' in position\n ? [...field, { kind: 'node', id: position.node }, { kind: 'prop', name: position.prop }]\n : field\n return { key: `canvas:${formatValuePath(path)}`, path, policy }\n}\n\n/** Whether a committer key names a canvas control. */\nexport function isCanvasControlKey(key: string): boolean {\n return key.startsWith('canvas:')\n}\n\nfunction writesExactly(patch: DocumentPatch, path: ValuePath): boolean {\n return (patch.op === 'set' || patch.op === 'unset') && formatValuePath(patch.path) === formatValuePath(path)\n}\n\n/**\n * Route one canvas write's patches. When they are exactly the focused control's value\n * write at its position and its policy waits for quiescence, the write is that control's\n * uncommitted position (`deferred` — the committer commits the latest value later).\n * Anything else — a canvas action, a discrete control, an edit with no control focused —\n * commits now (`committed`), after any canvas position still uncommitted, so positions\n * reach the persister in the order the editor made them.\n *\n * EC-647: `revision` is the revision of the canvas value the write was authored on (its\n * lift's) — the deferred position's base on its first keystroke, as `commitNow`'s caller\n * pairs it with the patches it sends; never the draft's (which may be newer).\n */\nexport function routeCanvasWrite(input: {\n patches: readonly DocumentPatch[]\n /** The focused canvas control, if focus is on one. */\n focused: CanvasControl | undefined\n committer: DraftCommitter\n /** The revision the write was authored against (the canvas lift's). */\n revision: number | undefined\n commitNow: (patches: readonly DocumentPatch[]) => void\n}): 'deferred' | 'committed' {\n const { patches, focused, committer } = input\n if (focused && focused.policy !== 'change' && patches.length === 1 && writesExactly(patches[0]!, focused.path)) {\n committer.edited(focused.key, focused.path, { base: input.revision })\n return 'deferred'\n }\n if (committer.uncommitted().some((position) => isCanvasControlKey(position.field))) committer.commitAll()\n input.commitNow(patches)\n return 'committed'\n}\n"]}
|
|
@@ -57,14 +57,24 @@ export interface CmsStore {
|
|
|
57
57
|
/**
|
|
58
58
|
* EC-595 A2 — commit the patches a writer made to a document (the form's field
|
|
59
59
|
* paths, the canvas's node patches, an AI proposal's changes, …): the session's view
|
|
60
|
-
* updates at once and the patches persist through `documents.patch` against
|
|
61
|
-
* revision the view
|
|
62
|
-
*
|
|
63
|
-
*
|
|
60
|
+
* updates at once and the patches persist through `documents.patch` against `bases` —
|
|
61
|
+
* REQUIRED, per patch: the revision of the view the writer authored it on (EC-647: a
|
|
62
|
+
* row's {@link revisionOfView}, the draft's revision, the read an AI proposal was built
|
|
63
|
+
* from — never the session's current one by default). A refused path becomes a
|
|
64
|
+
* per-field conflict ({@link documentConflicts}); a failure, {@link persistError}.
|
|
65
|
+
* Resolves with the commit's outcome once acknowledged (fixture sessions: applied
|
|
66
|
+
* locally, at once).
|
|
64
67
|
*/
|
|
65
|
-
commitPatches(ref: DocumentRef, patches: readonly DocumentPatch[], bases
|
|
66
|
-
/** EC-595 A2 — the revision the session's view of a document is at
|
|
68
|
+
commitPatches(ref: DocumentRef, patches: readonly DocumentPatch[], bases: readonly (number | undefined)[]): Promise<CommitOutcome | undefined>;
|
|
69
|
+
/** EC-595 A2 — the revision the session's view of a document is at now. */
|
|
67
70
|
revisionOf(ref: DocumentRef): number | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* EC-647 — the revision a document value this session SHOWED is at (a list row, the
|
|
73
|
+
* editor's `doc`): the value and its revision travel together, so a writer authoring
|
|
74
|
+
* from what it displayed names that revision. `undefined` for a value the session never
|
|
75
|
+
* showed (a fixture session, a copy) or a provisional one (a create in flight).
|
|
76
|
+
*/
|
|
77
|
+
revisionOfView(view: CmsDocument): number | undefined;
|
|
68
78
|
/**
|
|
69
79
|
* EC-595 A2 / EC-578 — create a document from a whole value (duplicate, import of a
|
|
70
80
|
* new row, an AI create, a transfer, a reuse promote): insert-if-absent
|
|
@@ -105,8 +115,11 @@ export interface CmsStore {
|
|
|
105
115
|
clearPresence(ref: DocumentRef): void;
|
|
106
116
|
/** This tab's presence id. */
|
|
107
117
|
presenceSessionId: string;
|
|
108
|
-
/**
|
|
109
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Write a whole document at `revision` — the revision of the view its snapshot was
|
|
120
|
+
* authored on (EC-647; a document-level key — the alias).
|
|
121
|
+
*/
|
|
122
|
+
replaceDocument(doc: CmsDocument, revision: number | undefined): void;
|
|
110
123
|
deleteDocument(ref: DocumentRef): void;
|
|
111
124
|
/**
|
|
112
125
|
* Is this document currently published? Sourced from the version POINTER
|
|
@@ -329,8 +329,10 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
329
329
|
return next;
|
|
330
330
|
}),
|
|
331
331
|
});
|
|
332
|
-
// The base every hydrated document's patches are made against (EC-595 A2)
|
|
333
|
-
|
|
332
|
+
// The base every hydrated document's patches are made against (EC-595 A2) — tracked
|
|
333
|
+
// with the very objects the session shows (EC-647: a shown value carries its
|
|
334
|
+
// revision; the seed is cloned into state, so the originals would not be the rows).
|
|
335
|
+
for (const doc of documentsRef.current) {
|
|
334
336
|
const revision = initialRevisions?.[documentKey(doc)];
|
|
335
337
|
if (revision !== undefined)
|
|
336
338
|
persisterRef.current.track({ document: doc, revision });
|
|
@@ -389,7 +391,7 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
389
391
|
}
|
|
390
392
|
return Promise.resolve(undefined);
|
|
391
393
|
}
|
|
392
|
-
return persister.commit(ref, patches,
|
|
394
|
+
return persister.commit(ref, patches, bases, current);
|
|
393
395
|
}, [stampUpdatedAt]);
|
|
394
396
|
const insertDocument = useCallback((doc) => {
|
|
395
397
|
stampUpdatedAt(doc); // EC-445: a fresh document's $updatedAt starts at creation
|
|
@@ -428,9 +430,10 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
428
430
|
? {
|
|
429
431
|
// EC-595 A2: ONE field patch through the persister's queue — at the
|
|
430
432
|
// revision the row was at — never a whole-document side channel.
|
|
433
|
+
// EC-647: the row the table SHOWED names that revision.
|
|
431
434
|
dispatch: async (next) => {
|
|
432
435
|
const patch = fieldWritePatch(input.collection, next, input.field.name, input.locale);
|
|
433
|
-
const outcome = await persister.commit(ref, [patch], input.doc);
|
|
436
|
+
const outcome = await persister.commit(ref, [patch], [persister.revisionOfView(input.doc)], input.doc);
|
|
434
437
|
if (outcome.status === 'applied')
|
|
435
438
|
return { ok: true, value: outcome.record };
|
|
436
439
|
if (outcome.status === 'failed')
|
|
@@ -728,15 +731,18 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
728
731
|
// entry for its ref.
|
|
729
732
|
// EC-595 A2: a row new to the store is CREATED (insert-if-absent); a row the
|
|
730
733
|
// session already holds is REPLACED at the revision it was loaded at — an import
|
|
731
|
-
// never overwrites a change made since.
|
|
734
|
+
// never overwrites a change made since. EC-647: "loaded at" is the revision of
|
|
735
|
+
// the row the session SHOWED when the import was accepted (the one it judged).
|
|
732
736
|
const persister = persisterRef.current;
|
|
733
737
|
if (!persister)
|
|
734
738
|
setDocuments((prev) => accepted.reduce((acc, doc) => upsertDoc(acc, doc), prev));
|
|
735
739
|
for (const doc of accepted) {
|
|
736
740
|
if (!persister)
|
|
737
741
|
continue;
|
|
738
|
-
|
|
739
|
-
|
|
742
|
+
const shown = documents.find((d) => matchesRef(d, doc));
|
|
743
|
+
if (persister.revisionOf(doc) !== undefined) {
|
|
744
|
+
persister.replace(doc, shown ? persister.revisionOfView(shown) : undefined);
|
|
745
|
+
}
|
|
740
746
|
else
|
|
741
747
|
persister.create(doc);
|
|
742
748
|
}
|
|
@@ -866,7 +872,9 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
866
872
|
});
|
|
867
873
|
}
|
|
868
874
|
const written = setFieldDoc(current);
|
|
869
|
-
|
|
875
|
+
// EC-647: authored from the row the session holds — its revision, never the
|
|
876
|
+
// tracked one (a colleague's change the user never saw is refused, visibly).
|
|
877
|
+
const outcome = await persister.commit(ref, [fieldWritePatch(collection, written, setField.field, activeLocale)], [persister.revisionOfView(current)], current);
|
|
870
878
|
if (outcome.status === 'applied')
|
|
871
879
|
return { ok: true, value: outcome.record };
|
|
872
880
|
if (outcome.status === 'failed')
|
|
@@ -985,10 +993,10 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
985
993
|
.then((studio) => studio.clearPresence(projectId, ref, PRESENCE_SESSION_ID))
|
|
986
994
|
.catch(() => { });
|
|
987
995
|
}, [projectId]);
|
|
988
|
-
const replaceDocument = useCallback((doc) => {
|
|
996
|
+
const replaceDocument = useCallback((doc, revision) => {
|
|
989
997
|
const persister = persisterRef.current;
|
|
990
998
|
if (persister)
|
|
991
|
-
persister.replace(doc);
|
|
999
|
+
persister.replace(doc, revision);
|
|
992
1000
|
else
|
|
993
1001
|
setDocuments((prev) => replaceDoc(prev, doc));
|
|
994
1002
|
}, []);
|
|
@@ -1003,6 +1011,7 @@ function CmsSession({ children, projectId, initialCollections, initialDocuments,
|
|
|
1003
1011
|
titleOf,
|
|
1004
1012
|
commitPatches,
|
|
1005
1013
|
revisionOf: (ref) => persisterRef.current?.revisionOf(ref),
|
|
1014
|
+
revisionOfView: (view) => persisterRef.current?.revisionOfView(view),
|
|
1006
1015
|
insertDocument,
|
|
1007
1016
|
newDocumentId: newId,
|
|
1008
1017
|
commitFieldEdit,
|