@elytracms/studio 0.0.105 → 0.0.106

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 (47) hide show
  1. package/dist/components/builder/builder-store.d.ts +19 -3
  2. package/dist/components/builder/builder-store.js +24 -13
  3. package/dist/components/builder/builder-store.js.map +1 -1
  4. package/dist/components/builder/clipboard-actions.js +6 -5
  5. package/dist/components/builder/clipboard-actions.js.map +1 -1
  6. package/dist/components/builder/composition-field-editor.js +4 -2
  7. package/dist/components/builder/composition-field-editor.js.map +1 -1
  8. package/dist/components/cms/duplicate-document.js +5 -5
  9. package/dist/components/cms/duplicate-document.js.map +1 -1
  10. package/dist/components/cms/rich-text/editor.d.ts +7 -1
  11. package/dist/components/cms/rich-text/editor.js +9 -4
  12. package/dist/components/cms/rich-text/editor.js.map +1 -1
  13. package/dist/components/cms/rich-text/embed-identity.d.ts +36 -0
  14. package/dist/components/cms/rich-text/embed-identity.js +114 -0
  15. package/dist/components/cms/rich-text/embed-identity.js.map +1 -0
  16. package/dist/components/cms/rich-text/extensions.d.ts +7 -1
  17. package/dist/components/cms/rich-text/extensions.js +7 -1
  18. package/dist/components/cms/rich-text/extensions.js.map +1 -1
  19. package/dist/components/cms/rich-text/insert.d.ts +10 -5
  20. package/dist/components/cms/rich-text/insert.js +10 -12
  21. package/dist/components/cms/rich-text/insert.js.map +1 -1
  22. package/dist/components/components/component-preview.d.ts +0 -2
  23. package/dist/components/components/component-preview.js +0 -4
  24. package/dist/components/components/component-preview.js.map +1 -1
  25. package/dist/components/components/transfer-dialog.js +3 -1
  26. package/dist/components/components/transfer-dialog.js.map +1 -1
  27. package/dist/components/components/transfer.d.ts +12 -8
  28. package/dist/components/components/transfer.js +16 -15
  29. package/dist/components/components/transfer.js.map +1 -1
  30. package/dist/lib/ai/translate-document.js +47 -4
  31. package/dist/lib/ai/translate-document.js.map +1 -1
  32. package/dist/lib/ai/writer-form.js +5 -4
  33. package/dist/lib/ai/writer-form.js.map +1 -1
  34. package/dist/lib/engine-version.d.ts +1 -1
  35. package/dist/lib/engine-version.js +1 -1
  36. package/dist/lib/engine-version.js.map +1 -1
  37. package/dist/lib/i18n/messages.de.js +4 -1
  38. package/dist/lib/i18n/messages.de.js.map +1 -1
  39. package/dist/lib/i18n/messages.en.d.ts +3 -0
  40. package/dist/lib/i18n/messages.en.js +4 -1
  41. package/dist/lib/i18n/messages.en.js.map +1 -1
  42. package/dist/lib/persona/labels.js +1 -0
  43. package/dist/lib/persona/labels.js.map +1 -1
  44. package/dist/lib/registry/preview.d.ts +2 -1
  45. package/dist/lib/registry/preview.js +8 -3
  46. package/dist/lib/registry/preview.js.map +1 -1
  47. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"transfer-dialog.js","sourceRoot":"","sources":["../../../src/components/components/transfer-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAKnE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACxF,OAAO,EACL,MAAM,EACN,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,EACL,GAAG,EACH,KAAK,EACL,IAAI,GACL,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACtD,O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AE,QAAQ,EAAE,UAAU,KAAK,IAAI,YAClF,SAAS,CAAC,eAAe,CAAC,GACpB,GACI,IACd,CACJ,CAAA;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,iBAAiB,CAAC,EACzB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,GAQR;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,iBACA,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,EAAE,CACX,gIAAgI,EAChI,QAAQ,IAAI,+BAA+B,CAC5C,aAED,eAAM,SAAS,EAAC,mFAAmF,YAChG,OAAO,CAAC,CAAC,CAAC,KAAC,OAAO,IAAC,SAAS,EAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,IAAI,GACxD,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,QAAQ,EAAC,SAAS,EAAC,yBAAyB,YAChE,KAAK,GACD,IACA,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useMemo, useState } from 'react'\nimport { FilePlus2, FileText, Loader2, Search } from 'lucide-react'\nimport type { ReactNode } from 'react'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport type { CmsDocument, DocumentPatch } from '@elytracms/core/cms-core'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { STUDIO_PROJECT_ROUTE, studioPath, useNavigate } from '@elytracms/studio/router'\nimport {\n Button,\n Code,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Input,\n Row,\n Stack,\n Text,\n} from '@elytracms/studio/ui'\nimport { cn } from '../../lib/utils'\nimport { getStudioRegistry } from '../../lib/registry'\nimport { localizedLabel, translate } from '../../lib/i18n'\nimport { CmsSessionGate } from '../project-session'\nimport { CmsProvider, useCms } from '../cms/cms-store'\nimport { stageDocument } from '../cms/document-staging'\nimport { resolveCmsInitialCollections } from '../app-views/default-modules'\nimport {\n appendToBlockDocument,\n buildBlockDocument,\n canAppendTo,\n collectionsWithBlocks,\n isComponentAllowed,\n} from './transfer'\nimport type { CollectionBlocksTarget } from './transfer'\n\n/** Existing documents offered per target, beyond which the rest are hidden (filter to find them). */\nconst MAX_EXISTING_TARGETS = 8\n\n/**\n * EC-320 (+ 0.0.44 follow-up) — \"Use in document…\". Transfers the current\n * component combination (the live preview {@link ComponentNode}, edited props\n * and all) into a document's blocks field, then opens that document. Each\n * eligible collection+field target offers a NEW draft AND its existing\n * documents to append into.\n *\n * The dialog mounts a CMS session (so it reuses the store's create/save machinery,\n * collision-free ids and persistence) only while open. On confirm it builds the\n * draft or the append (pure {@link buildBlockDocument} / {@link appendToBlockDocument}),\n * saves it and AWAITS the persisted write landing (belt and braces alongside the\n * STAGE for the next CMS mount, see `document-staging` — both matter: staging\n * covers the very next mount regardless of mode, the await guards any later\n * reload), then navigates to the document — focused on its blocks field so it\n * opens on the canvas.\n */\nexport function TransferToDocumentDialog({\n projectId,\n manifest,\n node,\n open,\n onOpenChange,\n}: {\n projectId: string\n manifest: ComponentManifest\n node: ComponentNode\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-md\">\n <DialogHeader>\n <DialogTitle>\n {translate('components.transfer.title', { name: localizedLabel(manifest.title, manifest.id) })}\n </DialogTitle>\n <DialogDescription>{translate('components.transfer.description')}</DialogDescription>\n </DialogHeader>\n {open ? (\n <CmsSessionGate>\n {(cms) => {\n // Delegate to the shared, tested resolver (also used by the CMS/Assets\n // tabs) so this dialog's targets stay in sync with what those tabs show,\n // rather than reimplementing the ladder inline. (EC-479 removed the\n // reason the old inline version was subtly wrong: `CmsProvider` had a\n // `?? sampleFilterableCollections` fixture fallback that an inline `[]`\n // \"suppressed\" — there is no fixture fallback to suppress now, so the\n // distinction between `[]` and `undefined` no longer carries meaning.)\n const collections = resolveCmsInitialCollections(cms)\n return (\n <CmsProvider\n projectId={projectId}\n initialCollections={collections}\n initialDocuments={cms?.documents}\n initialPublishedKeys={cms?.publishedKeys}\n initialRevisions={cms?.revisions}\n // EC-461: hydrated seed (both modes now) supersedes staged docs.\n seedReflectsWrites={cms !== null}\n >\n <TransferPicker projectId={projectId} node={node} onClose={() => onOpenChange(false)} />\n </CmsProvider>\n )\n }}\n </CmsSessionGate>\n ) : null}\n </DialogContent>\n </Dialog>\n )\n}\n\n/** A pending transfer's in-flight target key: `<collectionId>/new` or `<collectionId>/<docId>`. */\nfunction newTargetKey(target: CollectionBlocksTarget): string {\n return `${target.collection.id}/new`\n}\nfunction existingTargetKey(target: CollectionBlocksTarget, doc: CmsDocument): string {\n return `${target.collection.id}/${doc.id}`\n}\n\n/**\n * Exported for the fresh-Convex-project regression test (bug fix,\n * transfer-dialog.test.tsx) — `TransferToDocumentDialog` is otherwise its only\n * caller.\n */\nexport function TransferPicker({\n projectId,\n node,\n onClose,\n}: {\n projectId: string\n node: ComponentNode\n onClose: () => void\n}) {\n const cms = useCms()\n const navigate = useNavigate()\n const [query, setQuery] = useState('')\n // The in-flight target's key while its save is awaited (disables every row\n // + shows a spinner on the clicked one) — `null` when idle.\n const [pendingKey, setPendingKey] = useState<string | null>(null)\n\n // Read the LIVE store schema (`cms.collections`) rather than re-deriving it\n // from the same `resolveCmsInitialCollections` result passed to `CmsProvider`\n // above — `cms.collections` is what the provider actually resolved to, so the\n // targets list can never drift from what the CMS/Assets tabs show for this\n // same session. Allow-gated (0.0.44 follow-up): a target\n // whose field's `allow` vocabulary rejects this component is never offered,\n // new-document or existing-document alike — the validator would flag it.\n const targets = useMemo(\n () =>\n collectionsWithBlocks(cms.collections).filter((t) =>\n isComponentAllowed(t.field, node.componentId, getStudioRegistry().registry.lookup),\n ),\n [cms.collections, node.componentId],\n )\n\n /**\n * Persist (awaited) + stage + navigate — shared by both transfer paths. EC-595 A2: a\n * NEW document is one insert-if-absent create; an EXISTING one gets the transfer's\n * patch (one `insert` of the embed node at the end of its field) — never a\n * whole-document write, so a concurrent edit of that document is never overwritten.\n * EC-647: the patch carries the revision of the document value it was appended to.\n */\n async function persistAndOpen(\n doc: CmsDocument,\n target: CollectionBlocksTarget,\n append?: { patches: readonly DocumentPatch[]; revision: number | undefined },\n ) {\n if (append) {\n await cms.commitPatches(\n { collection: doc.collection, id: doc.id },\n append.patches,\n append.patches.map(() => append.revision),\n )\n } else cms.insertDocument(doc)\n // AWAIT the queued write landing, so a reload of the destination editor — not just\n // its very next mount — finds the document.\n await cms.flushPersistence({ collection: doc.collection, id: doc.id })\n // Cross-mount handoff for the very next `CmsProvider` mount, in EVERY mode (see\n // document-staging.ts): the session's view of the written document.\n stageDocument(projectId, cms.getDocument({ collection: doc.collection, id: doc.id }) ?? doc)\n onClose()\n void navigate({\n to: STUDIO_PROJECT_ROUTE,\n params: { projectId, _splat: studioPath.cmsDocument(target.collection.id, doc.id) },\n search: { field: `values/${target.field.name}` },\n })\n }\n\n async function transferNew(target: CollectionBlocksTarget) {\n const key = newTargetKey(target)\n setPendingKey(key)\n try {\n const doc = buildBlockDocument({\n collection: target.collection,\n blocksField: target.field,\n node,\n newId: cms.newDocumentId,\n locales: cms.localeConfig,\n })\n await persistAndOpen(doc, target)\n } finally {\n setPendingKey(null)\n }\n }\n\n async function transferInto(target: CollectionBlocksTarget, existing: CmsDocument) {\n const key = existingTargetKey(target, existing)\n setPendingKey(key)\n try {\n // The FORCED FLUSH before the transfer reads the document (the ruling).\n await cms.flushPersistence({ collection: existing.collection, id: existing.id })\n const current = cms.getDocument({ collection: existing.collection, id: existing.id }) ?? existing\n const { document: doc, patches } = appendToBlockDocument({\n collection: target.collection,\n document: current,\n blocksField: target.field,\n node,\n locale: cms.activeLocale,\n newId: cms.newDocumentId,\n })\n await persistAndOpen(doc, target, { patches, revision: cms.revisionOfView(current) })\n } finally {\n setPendingKey(null)\n }\n }\n\n if (targets.length === 0) {\n return (\n <Text size=\"sm\" tone=\"muted\" data-testid=\"transfer-no-targets\">\n {translate('components.transfer.noTargets')}\n </Text>\n )\n }\n\n const trimmedQuery = query.trim().toLowerCase()\n const hasAnyExistingDocs = targets.some((t) => cms.documentsOf(t.collection.id).length > 0)\n\n return (\n <>\n {hasAnyExistingDocs ? (\n <div className=\"relative\">\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 value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={translate('common.searchPlaceholder')}\n className=\"pl-8\"\n />\n </div>\n ) : null}\n <Stack gap=\"4\" className=\"max-h-[50vh] overflow-y-auto\">\n {targets.map((target) => {\n const existing = cms\n .documentsOf(target.collection.id)\n .filter((doc) => canAppendTo({ collection: target.collection, document: doc, blocksField: target.field, locale: cms.activeLocale }))\n .filter(\n (doc) =>\n trimmedQuery === '' ||\n cms.titleOf({ collection: target.collection.id, id: doc.id }).toLowerCase().includes(trimmedQuery),\n )\n .slice(0, MAX_EXISTING_TARGETS)\n\n return (\n <Stack key={target.collection.id} gap=\"2\">\n <Stack gap=\"px\">\n <Text size=\"sm\" weight=\"medium\" className=\"truncate\">\n {localizedLabel(target.collection.form?.label, target.collection.id)}\n </Text>\n <Row gap=\"1\" align=\"center\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('components.transfer.intoField')}\n </Text>\n <Code tone=\"muted\">{target.field.name}</Code>\n </Row>\n </Stack>\n <Stack gap=\"1\">\n <TransferTargetRow\n testId=\"transfer-target\"\n icon={<FilePlus2 className=\"size-4\" />}\n label={translate('components.transfer.newDocument', {\n collection: localizedLabel(target.collection.form?.labelSingular, target.collection.id),\n })}\n pending={pendingKey === newTargetKey(target)}\n disabled={pendingKey !== null}\n onClick={() => void transferNew(target)}\n />\n {existing.length > 0 ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-1 pt-1\">\n {translate('components.transfer.orExisting')}\n </Text>\n ) : null}\n {existing.map((doc) => (\n <TransferTargetRow\n key={doc.id}\n testId=\"transfer-target-existing\"\n icon={<FileText className=\"size-4\" />}\n label={cms.titleOf({ collection: target.collection.id, id: doc.id })}\n pending={pendingKey === existingTargetKey(target, doc)}\n disabled={pendingKey !== null}\n onClick={() => void transferInto(target, doc)}\n />\n ))}\n </Stack>\n </Stack>\n )\n })}\n </Stack>\n <DialogFooter>\n <Button type=\"button\" variant=\"ghost\" onClick={onClose} disabled={pendingKey !== null}>\n {translate('common.cancel')}\n </Button>\n </DialogFooter>\n </>\n )\n}\n\n/** One selectable transfer target row — a new draft, or an existing document to append into. */\nfunction TransferTargetRow({\n testId,\n icon,\n label,\n pending,\n disabled,\n onClick,\n}: {\n testId: string\n icon: ReactNode\n label: string\n pending: boolean\n disabled: boolean\n onClick: () => void\n}) {\n return (\n <button\n type=\"button\"\n data-testid={testId}\n disabled={disabled}\n onClick={onClick}\n className={cn(\n 'flex items-center gap-3 rounded-md border border-border p-3 text-left transition-colors hover:border-primary/40 hover:bg-muted',\n disabled && 'cursor-not-allowed opacity-60',\n )}\n >\n <span className=\"grid size-8 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground\">\n {pending ? <Loader2 className=\"size-4 animate-spin\" /> : icon}\n </span>\n <Text size=\"sm\" weight=\"medium\" className=\"min-w-0 flex-1 truncate\">\n {label}\n </Text>\n </button>\n )\n}\n"]}
1
+ {"version":3,"file":"transfer-dialog.js","sourceRoot":"","sources":["../../../src/components/components/transfer-dialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAKnE,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACxF,OAAO,EACL,MAAM,EACN,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX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AE,EAAE,CAAC,EACpE,OAAO,EAAE,UAAU,KAAK,iBAAiB,CAAC,MAAM,EAAE,GAAG,CAAC,EACtD,QAAQ,EAAE,UAAU,KAAK,IAAI,EAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,IANxC,GAAG,CAAC,EAAE,CAOX,CACH,CAAC,IACI,KAvCE,MAAM,CAAC,UAAU,CAAC,EAAE,CAwCxB,CACT,CAAA;gBACH,CAAC,CAAC,GACI,EACR,KAAC,YAAY,cACX,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAC,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,KAAK,IAAI,YAClF,SAAS,CAAC,eAAe,CAAC,GACpB,GACI,IACd,CACJ,CAAA;AACH,CAAC;AAED,gGAAgG;AAChG,SAAS,iBAAiB,CAAC,EACzB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,GAQR;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,iBACA,MAAM,EACnB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,EAAE,CACX,gIAAgI,EAChI,QAAQ,IAAI,+BAA+B,CAC5C,aAED,eAAM,SAAS,EAAC,mFAAmF,YAChG,OAAO,CAAC,CAAC,CAAC,KAAC,OAAO,IAAC,SAAS,EAAC,qBAAqB,GAAG,CAAC,CAAC,CAAC,IAAI,GACxD,EACP,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,MAAM,EAAC,QAAQ,EAAC,SAAS,EAAC,yBAAyB,YAChE,KAAK,GACD,IACA,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useMemo, useState } from 'react'\nimport { FilePlus2, FileText, Loader2, Search } from 'lucide-react'\nimport type { ReactNode } from 'react'\nimport type { ComponentManifest } from '@elytracms/core/component-registry'\nimport type { CmsDocument, DocumentPatch } from '@elytracms/core/cms-core'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { STUDIO_PROJECT_ROUTE, studioPath, useNavigate } from '@elytracms/studio/router'\nimport {\n Button,\n Code,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n Input,\n Row,\n Stack,\n Text,\n} from '@elytracms/studio/ui'\nimport { cn } from '../../lib/utils'\nimport { getStudioRegistry, studioManifestLookup } from '../../lib/registry'\nimport { localizedLabel, translate } from '../../lib/i18n'\nimport { CmsSessionGate } from '../project-session'\nimport { CmsProvider, useCms } from '../cms/cms-store'\nimport { stageDocument } from '../cms/document-staging'\nimport { resolveCmsInitialCollections } from '../app-views/default-modules'\nimport {\n appendToBlockDocument,\n buildBlockDocument,\n canAppendTo,\n collectionsWithBlocks,\n isComponentAllowed,\n} from './transfer'\nimport type { CollectionBlocksTarget } from './transfer'\n\n/** Existing documents offered per target, beyond which the rest are hidden (filter to find them). */\nconst MAX_EXISTING_TARGETS = 8\n\n/**\n * EC-320 (+ 0.0.44 follow-up) — \"Use in document…\". Transfers the current\n * component combination (the live preview {@link ComponentNode}, edited props\n * and all) into a document's blocks field, then opens that document. Each\n * eligible collection+field target offers a NEW draft AND its existing\n * documents to append into.\n *\n * The dialog mounts a CMS session (so it reuses the store's create/save machinery,\n * collision-free ids and persistence) only while open. On confirm it builds the\n * draft or the append (pure {@link buildBlockDocument} / {@link appendToBlockDocument}),\n * saves it and AWAITS the persisted write landing (belt and braces alongside the\n * STAGE for the next CMS mount, see `document-staging` — both matter: staging\n * covers the very next mount regardless of mode, the await guards any later\n * reload), then navigates to the document — focused on its blocks field so it\n * opens on the canvas.\n */\nexport function TransferToDocumentDialog({\n projectId,\n manifest,\n node,\n open,\n onOpenChange,\n}: {\n projectId: string\n manifest: ComponentManifest\n node: ComponentNode\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent className=\"max-w-md\">\n <DialogHeader>\n <DialogTitle>\n {translate('components.transfer.title', { name: localizedLabel(manifest.title, manifest.id) })}\n </DialogTitle>\n <DialogDescription>{translate('components.transfer.description')}</DialogDescription>\n </DialogHeader>\n {open ? (\n <CmsSessionGate>\n {(cms) => {\n // Delegate to the shared, tested resolver (also used by the CMS/Assets\n // tabs) so this dialog's targets stay in sync with what those tabs show,\n // rather than reimplementing the ladder inline. (EC-479 removed the\n // reason the old inline version was subtly wrong: `CmsProvider` had a\n // `?? sampleFilterableCollections` fixture fallback that an inline `[]`\n // \"suppressed\" — there is no fixture fallback to suppress now, so the\n // distinction between `[]` and `undefined` no longer carries meaning.)\n const collections = resolveCmsInitialCollections(cms)\n return (\n <CmsProvider\n projectId={projectId}\n initialCollections={collections}\n initialDocuments={cms?.documents}\n initialPublishedKeys={cms?.publishedKeys}\n initialRevisions={cms?.revisions}\n // EC-461: hydrated seed (both modes now) supersedes staged docs.\n seedReflectsWrites={cms !== null}\n >\n <TransferPicker projectId={projectId} node={node} onClose={() => onOpenChange(false)} />\n </CmsProvider>\n )\n }}\n </CmsSessionGate>\n ) : null}\n </DialogContent>\n </Dialog>\n )\n}\n\n/** A pending transfer's in-flight target key: `<collectionId>/new` or `<collectionId>/<docId>`. */\nfunction newTargetKey(target: CollectionBlocksTarget): string {\n return `${target.collection.id}/new`\n}\nfunction existingTargetKey(target: CollectionBlocksTarget, doc: CmsDocument): string {\n return `${target.collection.id}/${doc.id}`\n}\n\n/**\n * Exported for the fresh-Convex-project regression test (bug fix,\n * transfer-dialog.test.tsx) — `TransferToDocumentDialog` is otherwise its only\n * caller.\n */\nexport function TransferPicker({\n projectId,\n node,\n onClose,\n}: {\n projectId: string\n node: ComponentNode\n onClose: () => void\n}) {\n const cms = useCms()\n const navigate = useNavigate()\n const [query, setQuery] = useState('')\n // The in-flight target's key while its save is awaited (disables every row\n // + shows a spinner on the clicked one) — `null` when idle.\n const [pendingKey, setPendingKey] = useState<string | null>(null)\n\n // Read the LIVE store schema (`cms.collections`) rather than re-deriving it\n // from the same `resolveCmsInitialCollections` result passed to `CmsProvider`\n // above — `cms.collections` is what the provider actually resolved to, so the\n // targets list can never drift from what the CMS/Assets tabs show for this\n // same session. Allow-gated (0.0.44 follow-up): a target\n // whose field's `allow` vocabulary rejects this component is never offered,\n // new-document or existing-document alike — the validator would flag it.\n const targets = useMemo(\n () =>\n collectionsWithBlocks(cms.collections).filter((t) =>\n isComponentAllowed(t.field, node.componentId, getStudioRegistry().registry.lookup),\n ),\n [cms.collections, node.componentId],\n )\n\n /**\n * Persist (awaited) + stage + navigate — shared by both transfer paths. EC-595 A2: a\n * NEW document is one insert-if-absent create; an EXISTING one gets the transfer's\n * patch (one `insert` of the embed node at the end of its field) — never a\n * whole-document write, so a concurrent edit of that document is never overwritten.\n * EC-647: the patch carries the revision of the document value it was appended to.\n */\n async function persistAndOpen(\n doc: CmsDocument,\n target: CollectionBlocksTarget,\n append?: { patches: readonly DocumentPatch[]; revision: number | undefined },\n ) {\n if (append) {\n await cms.commitPatches(\n { collection: doc.collection, id: doc.id },\n append.patches,\n append.patches.map(() => append.revision),\n )\n } else cms.insertDocument(doc)\n // AWAIT the queued write landing, so a reload of the destination editor — not just\n // its very next mount — finds the document.\n await cms.flushPersistence({ collection: doc.collection, id: doc.id })\n // Cross-mount handoff for the very next `CmsProvider` mount, in EVERY mode (see\n // document-staging.ts): the session's view of the written document.\n stageDocument(projectId, cms.getDocument({ collection: doc.collection, id: doc.id }) ?? doc)\n onClose()\n void navigate({\n to: STUDIO_PROJECT_ROUTE,\n params: { projectId, _splat: studioPath.cmsDocument(target.collection.id, doc.id) },\n search: { field: `values/${target.field.name}` },\n })\n }\n\n async function transferNew(target: CollectionBlocksTarget) {\n const key = newTargetKey(target)\n setPendingKey(key)\n try {\n const doc = buildBlockDocument({\n collection: target.collection,\n blocksField: target.field,\n node,\n newId: cms.newDocumentId,\n locales: cms.localeConfig,\n lookupManifest: studioManifestLookup(),\n })\n await persistAndOpen(doc, target)\n } finally {\n setPendingKey(null)\n }\n }\n\n async function transferInto(target: CollectionBlocksTarget, existing: CmsDocument) {\n const key = existingTargetKey(target, existing)\n setPendingKey(key)\n try {\n // The FORCED FLUSH before the transfer reads the document (the ruling).\n await cms.flushPersistence({ collection: existing.collection, id: existing.id })\n const current = cms.getDocument({ collection: existing.collection, id: existing.id }) ?? existing\n const { document: doc, patches } = appendToBlockDocument({\n collection: target.collection,\n document: current,\n blocksField: target.field,\n node,\n locale: cms.activeLocale,\n newId: cms.newDocumentId,\n lookupManifest: studioManifestLookup(),\n })\n await persistAndOpen(doc, target, { patches, revision: cms.revisionOfView(current) })\n } finally {\n setPendingKey(null)\n }\n }\n\n if (targets.length === 0) {\n return (\n <Text size=\"sm\" tone=\"muted\" data-testid=\"transfer-no-targets\">\n {translate('components.transfer.noTargets')}\n </Text>\n )\n }\n\n const trimmedQuery = query.trim().toLowerCase()\n const hasAnyExistingDocs = targets.some((t) => cms.documentsOf(t.collection.id).length > 0)\n\n return (\n <>\n {hasAnyExistingDocs ? (\n <div className=\"relative\">\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 value={query}\n onChange={(e) => setQuery(e.target.value)}\n placeholder={translate('common.searchPlaceholder')}\n className=\"pl-8\"\n />\n </div>\n ) : null}\n <Stack gap=\"4\" className=\"max-h-[50vh] overflow-y-auto\">\n {targets.map((target) => {\n const existing = cms\n .documentsOf(target.collection.id)\n .filter((doc) => canAppendTo({ collection: target.collection, document: doc, blocksField: target.field, locale: cms.activeLocale }))\n .filter(\n (doc) =>\n trimmedQuery === '' ||\n cms.titleOf({ collection: target.collection.id, id: doc.id }).toLowerCase().includes(trimmedQuery),\n )\n .slice(0, MAX_EXISTING_TARGETS)\n\n return (\n <Stack key={target.collection.id} gap=\"2\">\n <Stack gap=\"px\">\n <Text size=\"sm\" weight=\"medium\" className=\"truncate\">\n {localizedLabel(target.collection.form?.label, target.collection.id)}\n </Text>\n <Row gap=\"1\" align=\"center\">\n <Text size=\"xs\" tone=\"muted\">\n {translate('components.transfer.intoField')}\n </Text>\n <Code tone=\"muted\">{target.field.name}</Code>\n </Row>\n </Stack>\n <Stack gap=\"1\">\n <TransferTargetRow\n testId=\"transfer-target\"\n icon={<FilePlus2 className=\"size-4\" />}\n label={translate('components.transfer.newDocument', {\n collection: localizedLabel(target.collection.form?.labelSingular, target.collection.id),\n })}\n pending={pendingKey === newTargetKey(target)}\n disabled={pendingKey !== null}\n onClick={() => void transferNew(target)}\n />\n {existing.length > 0 ? (\n <Text size=\"xs\" tone=\"muted\" className=\"px-1 pt-1\">\n {translate('components.transfer.orExisting')}\n </Text>\n ) : null}\n {existing.map((doc) => (\n <TransferTargetRow\n key={doc.id}\n testId=\"transfer-target-existing\"\n icon={<FileText className=\"size-4\" />}\n label={cms.titleOf({ collection: target.collection.id, id: doc.id })}\n pending={pendingKey === existingTargetKey(target, doc)}\n disabled={pendingKey !== null}\n onClick={() => void transferInto(target, doc)}\n />\n ))}\n </Stack>\n </Stack>\n )\n })}\n </Stack>\n <DialogFooter>\n <Button type=\"button\" variant=\"ghost\" onClick={onClose} disabled={pendingKey !== null}>\n {translate('common.cancel')}\n </Button>\n </DialogFooter>\n </>\n )\n}\n\n/** One selectable transfer target row — a new draft, or an existing document to append into. */\nfunction TransferTargetRow({\n testId,\n icon,\n label,\n pending,\n disabled,\n onClick,\n}: {\n testId: string\n icon: ReactNode\n label: string\n pending: boolean\n disabled: boolean\n onClick: () => void\n}) {\n return (\n <button\n type=\"button\"\n data-testid={testId}\n disabled={disabled}\n onClick={onClick}\n className={cn(\n 'flex items-center gap-3 rounded-md border border-border p-3 text-left transition-colors hover:border-primary/40 hover:bg-muted',\n disabled && 'cursor-not-allowed opacity-60',\n )}\n >\n <span className=\"grid size-8 shrink-0 place-items-center rounded-md bg-muted text-muted-foreground\">\n {pending ? <Loader2 className=\"size-4 animate-spin\" /> : icon}\n </span>\n <Text size=\"sm\" weight=\"medium\" className=\"min-w-0 flex-1 truncate\">\n {label}\n </Text>\n </button>\n )\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { BlocksFieldDef, CmsDocument, CollectionDef, DocumentPatch, Locale, LocaleConfig } from '@elytracms/core/cms-core';
1
+ import type { BlocksFieldDef, CmsDocument, CollectionDef, DocumentPatch, Locale, LocaleConfig, PropFieldLookup } from '@elytracms/core/cms-core';
2
2
  import type { ComponentLookup, ComponentNode } from '@elytracms/core/project-graph';
3
3
  import type { IdFactory } from '@elytracms/core/persistence';
4
4
  /**
@@ -43,10 +43,12 @@ export interface BuildBlockDocumentInput {
43
43
  blocksField: BlocksFieldDef;
44
44
  /** The component node — a manifest id + the edited static props (+ slots). */
45
45
  node: ComponentNode;
46
- /** THE id factory (EC-578) — mints the new document's id and the embed's node id. */
46
+ /** THE id factory (EC-578) — mints the new document's id and the embed's node ids. */
47
47
  newId: IdFactory;
48
48
  /** The project's locale config — a new document is written in its default locale (EC-580). */
49
49
  locales: LocaleConfig;
50
+ /** The project's prop declarations (EC-776) — the copy re-mints the nodes the props hold. */
51
+ lookupManifest: PropFieldLookup;
50
52
  }
51
53
  /**
52
54
  * Build the draft document that embeds `node` in the collection's blocks field.
@@ -63,7 +65,7 @@ export interface BuildBlockDocumentInput {
63
65
  * locale — a new document is created in its default bucket, so a localized blocks
64
66
  * field holds the node under `localized[default]`, never on the shared bag.
65
67
  */
66
- export declare function buildBlockDocument({ collection, blocksField, node, newId, locales, }: BuildBlockDocumentInput): CmsDocument;
68
+ export declare function buildBlockDocument({ collection, blocksField, node, newId, locales, lookupManifest, }: BuildBlockDocumentInput): CmsDocument;
67
69
  export interface CanAppendToInput {
68
70
  collection: CollectionDef;
69
71
  document: CmsDocument;
@@ -90,8 +92,10 @@ export interface AppendToBlockDocumentInput {
90
92
  node: ComponentNode;
91
93
  /** The locale being edited (EC-176 ambient active locale) for a localized field. */
92
94
  locale: Locale;
93
- /** THE id factory (EC-578) — mints the embed's node id. */
95
+ /** THE id factory (EC-578) — mints the embed's node ids. */
94
96
  newId: IdFactory;
97
+ /** The project's prop declarations (EC-776) — the copy re-mints the nodes the props hold. */
98
+ lookupManifest: PropFieldLookup;
95
99
  }
96
100
  /** The appended document AND the patch that says so (EC-595: the writer emits its patch at the source). */
97
101
  export interface AppendToBlockDocumentResult {
@@ -119,13 +123,13 @@ export interface AppendToBlockDocumentResult {
119
123
  * blocks field's OTHER locale bundles are never touched, only the edited
120
124
  * locale's.
121
125
  *
122
- * Node-id collision guard: `node` is re-embedded under a fresh id minted past
123
- * every existing root's ids ({@link embedFreshNode}), never a fixed `node-1`
124
- * — a document whose blocks already hold that id would otherwise collide.
126
+ * Node-id collision guard: `node` is embedded as a copy with fresh ids at every
127
+ * depth ({@link embedFreshNode}, EC-776) — a document whose blocks already hold one
128
+ * of its ids (the same preview appended before) would otherwise collide.
125
129
  *
126
130
  * Throws if `blocksField` already holds its declared item limit (`validation.max`,
127
131
  * EC-581) — a defensive invariant guard, not a user-facing
128
132
  * validation path: the caller must pre-filter candidates with
129
133
  * {@link canAppendTo} so this is never reached in that state.
130
134
  */
131
- export declare function appendToBlockDocument({ collection, document, blocksField, node, locale, newId, }: AppendToBlockDocumentInput): AppendToBlockDocumentResult;
135
+ export declare function appendToBlockDocument({ collection, document, blocksField, node, locale, newId, lookupManifest, }: AppendToBlockDocumentInput): AppendToBlockDocumentResult;
@@ -1,6 +1,5 @@
1
- import { fieldAllowList, fieldPath, isBlocksField, isFieldLocalized, isSequenceValue, itemLimit, seedDefaults, writeField, } from '@elytracms/core/cms-core';
1
+ import { fieldAllowList, fieldPath, isBlocksField, isFieldLocalized, isSequenceValue, itemLimit, seedDefaults, withFreshNodeIds, writeField, } from '@elytracms/core/cms-core';
2
2
  import { ANY_COMPONENT, blockRootsOf, editBlockRoots, placementRefusal } from '@elytracms/core/project-graph';
3
- import { embedNodeFrom } from './component-preview.js';
4
3
  /**
5
4
  * Collections that can receive a transferred combination — those declaring a
6
5
  * `blocks` (composition) field. The first blocks field wins (a collection with a
@@ -33,13 +32,15 @@ export function isComponentAllowed(field, componentId, components) {
33
32
  null);
34
33
  }
35
34
  /**
36
- * Re-embed `node` under a fresh id from the injected factory (EC-578 / EC-595 A2): UUIDs
37
- * in the studio, so an embed appended into a document can never collide with an id
38
- * already in the tree — or with one another session appends at the same time (the old
39
- * `node-<n>` counter seeded past the tree's ids minted the same id in both).
35
+ * Embed a COPY of `node` (EC-776): every node of it — the root, its slot children (a preview's
36
+ * fixture children) and the nodes its props hold (a fixture's rich-text embeds) — under fresh
37
+ * ids from the injected factory (EC-578 / EC-595 A2: UUIDs in the studio), so an embed appended
38
+ * into a document can never collide with an id already in it, with the same preview appended
39
+ * twice, or with one another session appends at the same time. (It re-id'd the root only: a
40
+ * preview appended twice stored its fixture child's id twice — the critic's T case.)
40
41
  */
41
- function embedFreshNode(node, newId) {
42
- return embedNodeFrom(node, newId());
42
+ function embedFreshNode(node, newId, lookupManifest) {
43
+ return withFreshNodeIds(node, newId, { lookupManifest });
43
44
  }
44
45
  /**
45
46
  * Build the draft document that embeds `node` in the collection's blocks field.
@@ -56,9 +57,9 @@ function embedFreshNode(node, newId) {
56
57
  * locale — a new document is created in its default bucket, so a localized blocks
57
58
  * field holds the node under `localized[default]`, never on the shared bag.
58
59
  */
59
- export function buildBlockDocument({ collection, blocksField, node, newId, locales, }) {
60
+ export function buildBlockDocument({ collection, blocksField, node, newId, locales, lookupManifest, }) {
60
61
  const seeded = { collection: collection.id, id: newId(), ...seedDefaults(collection, locales) };
61
- return writeField(collection, seeded, blocksField.name, locales.default, editBlockRoots(undefined, () => [embedFreshNode(node, newId)]));
62
+ return writeField(collection, seeded, blocksField.name, locales.default, editBlockRoots(undefined, () => [embedFreshNode(node, newId, lookupManifest)]));
62
63
  }
63
64
  /** The blocks field's current value on `document`, respecting locale (EC-018). */
64
65
  function readBlocksValue(collection, document, blocksField, locale) {
@@ -96,18 +97,18 @@ export function canAppendTo({ collection, document, blocksField, locale }) {
96
97
  * blocks field's OTHER locale bundles are never touched, only the edited
97
98
  * locale's.
98
99
  *
99
- * Node-id collision guard: `node` is re-embedded under a fresh id minted past
100
- * every existing root's ids ({@link embedFreshNode}), never a fixed `node-1`
101
- * — a document whose blocks already hold that id would otherwise collide.
100
+ * Node-id collision guard: `node` is embedded as a copy with fresh ids at every
101
+ * depth ({@link embedFreshNode}, EC-776) — a document whose blocks already hold one
102
+ * of its ids (the same preview appended before) would otherwise collide.
102
103
  *
103
104
  * Throws if `blocksField` already holds its declared item limit (`validation.max`,
104
105
  * EC-581) — a defensive invariant guard, not a user-facing
105
106
  * validation path: the caller must pre-filter candidates with
106
107
  * {@link canAppendTo} so this is never reached in that state.
107
108
  */
108
- export function appendToBlockDocument({ collection, document, blocksField, node, locale, newId, }) {
109
+ export function appendToBlockDocument({ collection, document, blocksField, node, locale, newId, lookupManifest, }) {
109
110
  const current = readBlocksValue(collection, document, blocksField, locale);
110
- const embedded = embedFreshNode(node, newId);
111
+ const embedded = embedFreshNode(node, newId, lookupManifest);
111
112
  let lastRoot;
112
113
  const nextValue = editBlockRoots(current, (existingRoots) => {
113
114
  const limit = itemLimit(blocksField);
@@ -1 +1 @@
1
- {"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../src/components/components/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,YAAY,EACZ,UAAU,GACX,MAAM,0BAA0B,CAAA;AASjC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAG7G,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAoBnD;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAqC;IAErC,MAAM,OAAO,GAA6B,EAAE,CAAA;IAC5C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MA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A;AACH,CAAC","sourcesContent":["import {\n fieldAllowList,\n fieldPath,\n isBlocksField,\n isFieldLocalized,\n isSequenceValue,\n itemLimit,\n seedDefaults,\n writeField,\n} from '@elytracms/core/cms-core'\nimport type {\n BlocksFieldDef,\n CmsDocument,\n CollectionDef,\n DocumentPatch,\n Locale,\n LocaleConfig,\n} from '@elytracms/core/cms-core'\nimport { ANY_COMPONENT, blockRootsOf, editBlockRoots, placementRefusal } from '@elytracms/core/project-graph'\nimport type { ComponentLookup, ComponentNode } from '@elytracms/core/project-graph'\nimport type { IdFactory } from '@elytracms/core/persistence'\nimport { embedNodeFrom } from './component-preview'\n\n/**\n * EC-320 (+ 0.0.44 follow-up) — the \"design guide → real content\" bridge. A\n * component combination the user has arranged in the Components view (a\n * manifest + edited prop values, captured as a {@link ComponentNode}) is\n * transferred into a document's blocks/composition field — either a NEW DRAFT\n * document created for it ({@link buildBlockDocument}) or an EXISTING\n * document's field, appended alongside whatever it already holds\n * ({@link appendToBlockDocument}). Pure so id-minting/embedding/appending are\n * unit-testable; the React dialog owns the picker, persistence, and\n * navigation.\n */\n\nexport interface CollectionBlocksTarget {\n collection: CollectionDef\n /** The (first) blocks field the node lands in. */\n field: BlocksFieldDef\n}\n\n/**\n * Collections that can receive a transferred combination — those declaring a\n * `blocks` (composition) field. The first blocks field wins (a collection with a\n * single canvas is the norm; a second is an unusual edge we don't disambiguate).\n * Callers additionally gate each target through {@link isComponentAllowed} —\n * this only reports which collections HAVE a blocks field, not which ones\n * accept a given component.\n */\nexport function collectionsWithBlocks(\n collections: readonly CollectionDef[],\n): CollectionBlocksTarget[] {\n const targets: CollectionBlocksTarget[] = []\n for (const collection of collections) {\n const field = collection.fields.find(isBlocksField)\n if (field) targets.push({ collection, field })\n }\n return targets\n}\n\n/**\n * Is `componentId` permitted as a top-level block of `field`? EC-584: a READER of the\n * one core placement judge over the field's effective vocabulary (`fieldAllowList` —\n * its `allow`, else the blocks default), the verdict `validateCompositionValue`\n * reaches at the gate — so a target this predicate accepts can never fail its\n * `forbidden-component` / `server-only-component` check. With `components` (the\n * project's manifest lookup) canvas eligibility is judged too. The transfer dialog\n * uses this to hide targets the component isn't allowed into (new AND existing\n * document targets alike); the value-level sinks stay on the gate.\n */\nexport function isComponentAllowed(field: BlocksFieldDef, componentId: string, components?: ComponentLookup): boolean {\n return (\n placementRefusal({ componentId, view: components?.get(componentId), allow: fieldAllowList(field) ?? ANY_COMPONENT }) ===\n null\n )\n}\n\n/**\n * Re-embed `node` under a fresh id from the injected factory (EC-578 / EC-595 A2): UUIDs\n * in the studio, so an embed appended into a document can never collide with an id\n * already in the tree — or with one another session appends at the same time (the old\n * `node-<n>` counter seeded past the tree's ids minted the same id in both).\n */\nfunction embedFreshNode(node: ComponentNode, newId: IdFactory): ComponentNode {\n return embedNodeFrom(node, newId())\n}\n\nexport interface BuildBlockDocumentInput {\n collection: CollectionDef\n /** The blocks field the node lands in (from {@link collectionsWithBlocks}). */\n blocksField: BlocksFieldDef\n /** The component node — a manifest id + the edited static props (+ slots). */\n node: ComponentNode\n /** THE id factory (EC-578) — mints the new document's id and the embed's node id. */\n newId: IdFactory\n /** The project's locale config — a new document is written in its default locale (EC-580). */\n locales: LocaleConfig\n}\n\n/**\n * Build the draft document that embeds `node` in the collection's blocks field.\n * Reuses the CMS create machinery: the injected id factory (EC-578) for the id\n * and {@link seedDefaults} so declared field defaults are present (as a\n * normal `+ New` would be). The field stores the converged v2 sequence holding\n * the one tagged root, written through the core write path (`editBlockRoots`,\n * EC-576) — cardinality is a constraint (`validation.max`), not a shape (EC-500 D2,\n * EC-581). The\n * transferred node REPLACES whatever the field's declared default seeded, as it\n * always has.\n *\n * EC-580: both writes go through core's `writeField` in the project's DEFAULT\n * locale — a new document is created in its default bucket, so a localized blocks\n * field holds the node under `localized[default]`, never on the shared bag.\n */\nexport function buildBlockDocument({\n collection,\n blocksField,\n node,\n newId,\n locales,\n}: BuildBlockDocumentInput): CmsDocument {\n const seeded: CmsDocument = { collection: collection.id, id: newId(), ...seedDefaults(collection, locales) }\n return writeField(\n collection,\n seeded,\n blocksField.name,\n locales.default,\n editBlockRoots(undefined, () => [embedFreshNode(node, newId)]),\n )\n}\n\n/** The blocks field's current value on `document`, respecting locale (EC-018). */\nfunction readBlocksValue(\n collection: CollectionDef,\n document: CmsDocument,\n blocksField: BlocksFieldDef,\n locale: Locale,\n): unknown {\n return isFieldLocalized(collection, blocksField.name)\n ? document.localized?.[locale]?.[blocksField.name]\n : document.values[blocksField.name]\n}\n\nexport interface CanAppendToInput {\n collection: CollectionDef\n document: CmsDocument\n blocksField: BlocksFieldDef\n /** The locale being edited (EC-176 ambient active locale) for a localized field. */\n locale: Locale\n}\n\n/**\n * Can `node` be appended to `document`'s blocks field without destroying\n * existing content? Always true without a declared item limit (an ordered list\n * has room for one more); a field limited by `validation.max` (EC-581: `max: 1` is\n * the single-block field `multiple: false` used to spell) only while it is below\n * the limit — at it, there is no room without overwriting an existing block, so\n * the transfer dialog excludes that document from its offered targets rather than\n * risk data loss.\n */\nexport function canAppendTo({ collection, document, blocksField, locale }: CanAppendToInput): boolean {\n const limit = itemLimit(blocksField)\n if (limit === undefined) return true\n return blockRootsOf(readBlocksValue(collection, document, blocksField, locale)).length < limit\n}\n\nexport interface AppendToBlockDocumentInput {\n collection: CollectionDef\n /** The document to append into (the transfer dialog's \"insert into existing document\"). */\n document: CmsDocument\n blocksField: BlocksFieldDef\n /** The component node to append — not yet re-ided (fresh id minted here). */\n node: ComponentNode\n /** The locale being edited (EC-176 ambient active locale) for a localized field. */\n locale: Locale\n /** THE id factory (EC-578) — mints the embed's node id. */\n newId: IdFactory\n}\n\n/** The appended document AND the patch that says so (EC-595: the writer emits its patch at the source). */\nexport interface AppendToBlockDocumentResult {\n document: CmsDocument\n /**\n * ONE `insert` of the new embed node at the end of the field's top-level sequence,\n * anchored after the last existing component root — what is persisted\n * (`documents.patch`), so a concurrent edit elsewhere in the document (or a\n * concurrent append) is never overwritten by this one.\n */\n patches: DocumentPatch[]\n}\n\n/**\n * Append `node` into an EXISTING document's blocks field (EC-320 follow-up,\n * 0.0.44 — \"insert into existing document\"), leaving everything else about\n * the document untouched: other fields, other locale bundles, and the\n * field's own existing content, which the embed always lands AFTER.\n *\n * Writes through the core write path (`editBlockRoots`,\n * `@elytracms/core/project-graph`, EC-576): the new root is appended after\n * the existing roots, every typography item keeps its place and order, and\n * the value written is the v2 sequence — undefined-safe for a never-set\n * field. Locale-aware writes go through core's `writeField` (the same\n * locale-write every editor uses, EC-580) so a localized\n * blocks field's OTHER locale bundles are never touched, only the edited\n * locale's.\n *\n * Node-id collision guard: `node` is re-embedded under a fresh id minted past\n * every existing root's ids ({@link embedFreshNode}), never a fixed `node-1`\n * — a document whose blocks already hold that id would otherwise collide.\n *\n * Throws if `blocksField` already holds its declared item limit (`validation.max`,\n * EC-581) — a defensive invariant guard, not a user-facing\n * validation path: the caller must pre-filter candidates with\n * {@link canAppendTo} so this is never reached in that state.\n */\nexport function appendToBlockDocument({\n collection,\n document,\n blocksField,\n node,\n locale,\n newId,\n}: AppendToBlockDocumentInput): AppendToBlockDocumentResult {\n const current = readBlocksValue(collection, document, blocksField, locale)\n const embedded = embedFreshNode(node, newId)\n let lastRoot: string | undefined\n const nextValue = editBlockRoots(current, (existingRoots) => {\n const limit = itemLimit(blocksField)\n if (limit !== undefined && existingRoots.length >= limit) {\n throw new Error(\n `Cannot append to blocks field \"${blocksField.name}\": it already holds its limit of ${limit} (caller must gate with canAppendTo).`,\n )\n }\n lastRoot = existingRoots.at(-1)?.id\n return [...existingRoots, embedded]\n })\n const written = writeField(collection, document, blocksField.name, locale, nextValue)\n // The stored node is the canonical one `writeField` wrote (tagged, canonical props).\n const storedValue = readBlocksValue(collection, written, blocksField, locale)\n const storedNode = isSequenceValue(storedValue)\n ? (storedValue.content.find(\n (entry): entry is ComponentNode =>\n typeof entry === 'object' && entry !== null && (entry as ComponentNode).id === embedded.id,\n ) ?? embedded)\n : embedded\n const parent = fieldPath(blocksField.name, isFieldLocalized(collection, blocksField.name) ? locale : undefined)\n const index = isSequenceValue(current) ? current.content.length : 0\n return {\n document: written,\n patches: [\n {\n op: 'insert',\n at: { parent, index, ...(lastRoot !== undefined ? { after: lastRoot } : {}) },\n node: storedNode,\n },\n ],\n }\n}\n"]}
1
+ {"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../src/components/components/transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,UAAU,GACX,MAAM,0BAA0B,CAAA;AAUjC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAsB7G;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,WAAqC;IAErC,MAAM,OAAO,GAA6B,EAAE,CAAA;IAC5C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QACnD,IAAI,KAAK;YAAE,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;IAChD,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAqB,EAAE,WAAmB,EAAE,UAA4B;IACzG,OAAO,CACL,gBAAgB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,aAAa,EAAE,CAAC;QACpH,IAAI,CACL,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,cAAc,CAAC,IAAmB,EAAE,KAAgB,EAAE,cAA+B;IAC5F,OAAO,gBAAgB,CAAC,IAAI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AK,KAAK,IAAI,IAAK,KAAuB,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,CAC7F,IAAI,QAAQ,CAAC;QAChB,CAAC,CAAC,QAAQ,CAAA;IACZ,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,gBAAgB,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IAC/G,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;IACnE,OAAO;QACL,QAAQ,EAAE,OAAO;QACjB,OAAO,EAAE;YACP;gBACE,EAAE,EAAE,QAAQ;gBACZ,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;gBAC7E,IAAI,EAAE,UAAU;aACjB;SACF;KACF,CAAA;AACH,CAAC","sourcesContent":["import {\n fieldAllowList,\n fieldPath,\n isBlocksField,\n isFieldLocalized,\n isSequenceValue,\n itemLimit,\n seedDefaults,\n withFreshNodeIds,\n writeField,\n} from '@elytracms/core/cms-core'\nimport type {\n BlocksFieldDef,\n CmsDocument,\n CollectionDef,\n DocumentPatch,\n Locale,\n LocaleConfig,\n PropFieldLookup,\n} from '@elytracms/core/cms-core'\nimport { ANY_COMPONENT, blockRootsOf, editBlockRoots, placementRefusal } from '@elytracms/core/project-graph'\nimport type { ComponentLookup, ComponentNode } from '@elytracms/core/project-graph'\nimport type { IdFactory } from '@elytracms/core/persistence'\n\n/**\n * EC-320 (+ 0.0.44 follow-up) — the \"design guide → real content\" bridge. A\n * component combination the user has arranged in the Components view (a\n * manifest + edited prop values, captured as a {@link ComponentNode}) is\n * transferred into a document's blocks/composition field — either a NEW DRAFT\n * document created for it ({@link buildBlockDocument}) or an EXISTING\n * document's field, appended alongside whatever it already holds\n * ({@link appendToBlockDocument}). Pure so id-minting/embedding/appending are\n * unit-testable; the React dialog owns the picker, persistence, and\n * navigation.\n */\n\nexport interface CollectionBlocksTarget {\n collection: CollectionDef\n /** The (first) blocks field the node lands in. */\n field: BlocksFieldDef\n}\n\n/**\n * Collections that can receive a transferred combination — those declaring a\n * `blocks` (composition) field. The first blocks field wins (a collection with a\n * single canvas is the norm; a second is an unusual edge we don't disambiguate).\n * Callers additionally gate each target through {@link isComponentAllowed} —\n * this only reports which collections HAVE a blocks field, not which ones\n * accept a given component.\n */\nexport function collectionsWithBlocks(\n collections: readonly CollectionDef[],\n): CollectionBlocksTarget[] {\n const targets: CollectionBlocksTarget[] = []\n for (const collection of collections) {\n const field = collection.fields.find(isBlocksField)\n if (field) targets.push({ collection, field })\n }\n return targets\n}\n\n/**\n * Is `componentId` permitted as a top-level block of `field`? EC-584: a READER of the\n * one core placement judge over the field's effective vocabulary (`fieldAllowList` —\n * its `allow`, else the blocks default), the verdict `validateCompositionValue`\n * reaches at the gate — so a target this predicate accepts can never fail its\n * `forbidden-component` / `server-only-component` check. With `components` (the\n * project's manifest lookup) canvas eligibility is judged too. The transfer dialog\n * uses this to hide targets the component isn't allowed into (new AND existing\n * document targets alike); the value-level sinks stay on the gate.\n */\nexport function isComponentAllowed(field: BlocksFieldDef, componentId: string, components?: ComponentLookup): boolean {\n return (\n placementRefusal({ componentId, view: components?.get(componentId), allow: fieldAllowList(field) ?? ANY_COMPONENT }) ===\n null\n )\n}\n\n/**\n * Embed a COPY of `node` (EC-776): every node of it — the root, its slot children (a preview's\n * fixture children) and the nodes its props hold (a fixture's rich-text embeds) — under fresh\n * ids from the injected factory (EC-578 / EC-595 A2: UUIDs in the studio), so an embed appended\n * into a document can never collide with an id already in it, with the same preview appended\n * twice, or with one another session appends at the same time. (It re-id'd the root only: a\n * preview appended twice stored its fixture child's id twice — the critic's T case.)\n */\nfunction embedFreshNode(node: ComponentNode, newId: IdFactory, lookupManifest: PropFieldLookup): ComponentNode {\n return withFreshNodeIds(node, newId, { lookupManifest })\n}\n\nexport interface BuildBlockDocumentInput {\n collection: CollectionDef\n /** The blocks field the node lands in (from {@link collectionsWithBlocks}). */\n blocksField: BlocksFieldDef\n /** The component node — a manifest id + the edited static props (+ slots). */\n node: ComponentNode\n /** THE id factory (EC-578) — mints the new document's id and the embed's node ids. */\n newId: IdFactory\n /** The project's locale config — a new document is written in its default locale (EC-580). */\n locales: LocaleConfig\n /** The project's prop declarations (EC-776) — the copy re-mints the nodes the props hold. */\n lookupManifest: PropFieldLookup\n}\n\n/**\n * Build the draft document that embeds `node` in the collection's blocks field.\n * Reuses the CMS create machinery: the injected id factory (EC-578) for the id\n * and {@link seedDefaults} so declared field defaults are present (as a\n * normal `+ New` would be). The field stores the converged v2 sequence holding\n * the one tagged root, written through the core write path (`editBlockRoots`,\n * EC-576) — cardinality is a constraint (`validation.max`), not a shape (EC-500 D2,\n * EC-581). The\n * transferred node REPLACES whatever the field's declared default seeded, as it\n * always has.\n *\n * EC-580: both writes go through core's `writeField` in the project's DEFAULT\n * locale — a new document is created in its default bucket, so a localized blocks\n * field holds the node under `localized[default]`, never on the shared bag.\n */\nexport function buildBlockDocument({\n collection,\n blocksField,\n node,\n newId,\n locales,\n lookupManifest,\n}: BuildBlockDocumentInput): CmsDocument {\n const seeded: CmsDocument = { collection: collection.id, id: newId(), ...seedDefaults(collection, locales) }\n return writeField(\n collection,\n seeded,\n blocksField.name,\n locales.default,\n editBlockRoots(undefined, () => [embedFreshNode(node, newId, lookupManifest)]),\n )\n}\n\n/** The blocks field's current value on `document`, respecting locale (EC-018). */\nfunction readBlocksValue(\n collection: CollectionDef,\n document: CmsDocument,\n blocksField: BlocksFieldDef,\n locale: Locale,\n): unknown {\n return isFieldLocalized(collection, blocksField.name)\n ? document.localized?.[locale]?.[blocksField.name]\n : document.values[blocksField.name]\n}\n\nexport interface CanAppendToInput {\n collection: CollectionDef\n document: CmsDocument\n blocksField: BlocksFieldDef\n /** The locale being edited (EC-176 ambient active locale) for a localized field. */\n locale: Locale\n}\n\n/**\n * Can `node` be appended to `document`'s blocks field without destroying\n * existing content? Always true without a declared item limit (an ordered list\n * has room for one more); a field limited by `validation.max` (EC-581: `max: 1` is\n * the single-block field `multiple: false` used to spell) only while it is below\n * the limit — at it, there is no room without overwriting an existing block, so\n * the transfer dialog excludes that document from its offered targets rather than\n * risk data loss.\n */\nexport function canAppendTo({ collection, document, blocksField, locale }: CanAppendToInput): boolean {\n const limit = itemLimit(blocksField)\n if (limit === undefined) return true\n return blockRootsOf(readBlocksValue(collection, document, blocksField, locale)).length < limit\n}\n\nexport interface AppendToBlockDocumentInput {\n collection: CollectionDef\n /** The document to append into (the transfer dialog's \"insert into existing document\"). */\n document: CmsDocument\n blocksField: BlocksFieldDef\n /** The component node to append — not yet re-ided (fresh id minted here). */\n node: ComponentNode\n /** The locale being edited (EC-176 ambient active locale) for a localized field. */\n locale: Locale\n /** THE id factory (EC-578) — mints the embed's node ids. */\n newId: IdFactory\n /** The project's prop declarations (EC-776) — the copy re-mints the nodes the props hold. */\n lookupManifest: PropFieldLookup\n}\n\n/** The appended document AND the patch that says so (EC-595: the writer emits its patch at the source). */\nexport interface AppendToBlockDocumentResult {\n document: CmsDocument\n /**\n * ONE `insert` of the new embed node at the end of the field's top-level sequence,\n * anchored after the last existing component root — what is persisted\n * (`documents.patch`), so a concurrent edit elsewhere in the document (or a\n * concurrent append) is never overwritten by this one.\n */\n patches: DocumentPatch[]\n}\n\n/**\n * Append `node` into an EXISTING document's blocks field (EC-320 follow-up,\n * 0.0.44 — \"insert into existing document\"), leaving everything else about\n * the document untouched: other fields, other locale bundles, and the\n * field's own existing content, which the embed always lands AFTER.\n *\n * Writes through the core write path (`editBlockRoots`,\n * `@elytracms/core/project-graph`, EC-576): the new root is appended after\n * the existing roots, every typography item keeps its place and order, and\n * the value written is the v2 sequence — undefined-safe for a never-set\n * field. Locale-aware writes go through core's `writeField` (the same\n * locale-write every editor uses, EC-580) so a localized\n * blocks field's OTHER locale bundles are never touched, only the edited\n * locale's.\n *\n * Node-id collision guard: `node` is embedded as a copy with fresh ids at every\n * depth ({@link embedFreshNode}, EC-776) — a document whose blocks already hold one\n * of its ids (the same preview appended before) would otherwise collide.\n *\n * Throws if `blocksField` already holds its declared item limit (`validation.max`,\n * EC-581) — a defensive invariant guard, not a user-facing\n * validation path: the caller must pre-filter candidates with\n * {@link canAppendTo} so this is never reached in that state.\n */\nexport function appendToBlockDocument({\n collection,\n document,\n blocksField,\n node,\n locale,\n newId,\n lookupManifest,\n}: AppendToBlockDocumentInput): AppendToBlockDocumentResult {\n const current = readBlocksValue(collection, document, blocksField, locale)\n const embedded = embedFreshNode(node, newId, lookupManifest)\n let lastRoot: string | undefined\n const nextValue = editBlockRoots(current, (existingRoots) => {\n const limit = itemLimit(blocksField)\n if (limit !== undefined && existingRoots.length >= limit) {\n throw new Error(\n `Cannot append to blocks field \"${blocksField.name}\": it already holds its limit of ${limit} (caller must gate with canAppendTo).`,\n )\n }\n lastRoot = existingRoots.at(-1)?.id\n return [...existingRoots, embedded]\n })\n const written = writeField(collection, document, blocksField.name, locale, nextValue)\n // The stored node is the canonical one `writeField` wrote (tagged, canonical props).\n const storedValue = readBlocksValue(collection, written, blocksField, locale)\n const storedNode = isSequenceValue(storedValue)\n ? (storedValue.content.find(\n (entry): entry is ComponentNode =>\n typeof entry === 'object' && entry !== null && (entry as ComponentNode).id === embedded.id,\n ) ?? embedded)\n : embedded\n const parent = fieldPath(blocksField.name, isFieldLocalized(collection, blocksField.name) ? locale : undefined)\n const index = isSequenceValue(current) ? current.content.length : 0\n return {\n document: written,\n patches: [\n {\n op: 'insert',\n at: { parent, index, ...(lastRoot !== undefined ? { after: lastRoot } : {}) },\n node: storedNode,\n },\n ],\n }\n}\n"]}
@@ -45,7 +45,14 @@
45
45
  * - SLUG fields are never model-translated: after the text fills land, each per-locale
46
46
  * slug that still FOLLOWS the base is derived (EC-315 `autoDeriveSlug`) from the
47
47
  * translated source — in both modes: a slug the editor set is never touched (EC-752 — a
48
- * changed slug moves the page's address, and nothing redirects it).
48
+ * changed slug moves the page's address, and nothing redirects it);
49
+ * - the SEO role's CANONICAL is the second address (EC-779, owner 2026-11-04: "a URL is not
50
+ * prose, it should be inferred from the slug and routing rules"): never a unit and never
51
+ * carried from the base, whatever it holds — a re-translation keeps the target's own value
52
+ * (empty stays empty, so delivery infers the page's own localized URL), a fill writes none.
53
+ * It is the collection's `seoField` × `SEO_SUBFIELDS.canonical`, the pair the host's
54
+ * `seoMetadata` reads — no new declaration, the slug role's precedent. Every other
55
+ * URL-shaped value (an image `url`, a link `href`) is locale-neutral and keeps EC-766's rule.
49
56
  *
50
57
  * Batching (improves on the Sanity precedent's context-blind per-block calls): units are
51
58
  * grouped per target locale and chunked into batches; each batch is ONE `generate` call
@@ -53,7 +60,7 @@
53
60
  * translates with cross-block context. Bounded concurrency (default 6) keeps a realistic
54
61
  * document well under the route's per-minute rate limit.
55
62
  */
56
- import { autoDeriveSlug, childPositions, createCollectionRegistry, declarationMayHold, fieldValuePosition, isFieldLocalized, isOpaquePosition, isUrlLike, isWriterLocked, resolveField, slugFieldOf, validateDocument, valuesInLocale, writeField, } from '@elytracms/core/cms-core';
63
+ import { autoDeriveSlug, childPositions, createCollectionRegistry, declarationMayHold, fieldValuePosition, isFieldLocalized, isOpaquePosition, isUrlLike, isWriterLocked, resolveField, SEO_SUBFIELDS, seoFieldOf, slugFieldOf, validateDocument, valuesInLocale, writeField, } from '@elytracms/core/cms-core';
57
64
  import { introducedErrors, warningsOf } from './proposal-validation.js';
58
65
  import { fieldWritePatch } from '../cms/field-patch.js';
59
66
  import { fieldConnection, hasLocaleVariant } from '../locale/index.js';
@@ -78,6 +85,34 @@ function plannedAt(locale, field, key) {
78
85
  function isSlugField(field, collection) {
79
86
  return field.type === 'text' && slugFieldOf(collection)?.name === field.name;
80
87
  }
88
+ /**
89
+ * EC-779 — is this the SEO role's canonical, the page's second ADDRESS? The collection's SEO
90
+ * ROLE field (`seoField`, default `seo` — EC-590) × its contract sub-field `canonical`
91
+ * (`SEO_SUBFIELDS`), a `text` position directly under the object: exactly what the host's
92
+ * `seoMetadata` reads. A `canonical` anywhere else (another object's sub-field, a prop) is a
93
+ * project's own value, and EC-766's rule reads it.
94
+ */
95
+ function isAddressPosition(collection, field, position) {
96
+ return (seoFieldOf(collection)?.name === field.name &&
97
+ position.field.type === 'text' &&
98
+ position.at.length === 1 &&
99
+ position.at[0] === SEO_SUBFIELDS.canonical);
100
+ }
101
+ /**
102
+ * EC-779 — a written SEO object with the TARGET's own canonical, never the base's: the target's
103
+ * stored value (`replace` — it holds one of its own), or none at all (`fill` — it held none, so
104
+ * delivery infers the page's own address). Any other field is returned as it is.
105
+ */
106
+ function withOwnAddress(collection, field, value, own) {
107
+ if (seoFieldOf(collection)?.name !== field.name || !isRecord(value))
108
+ return value;
109
+ const { [SEO_SUBFIELDS.canonical]: _base, ...rest } = value;
110
+ const kept = isRecord(own) ? own[SEO_SUBFIELDS.canonical] : undefined;
111
+ return kept === undefined ? rest : { ...rest, [SEO_SUBFIELDS.canonical]: kept };
112
+ }
113
+ function isRecord(value) {
114
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
115
+ }
81
116
  /** The sibling field a slug derives from (string source / titleField), or null for a fn source. */
82
117
  function slugSourceField(field, collection) {
83
118
  const src = field.slug?.source;
@@ -296,6 +331,11 @@ function planRun(input) {
296
331
  const { value, key } = position;
297
332
  if (value === undefined || value === null)
298
333
  continue;
334
+ // EC-779: the page's address is never a unit — not sent, whatever it holds (a bare
335
+ // domain the URL rule does not read as a URL included), and never judged unreadable:
336
+ // the rebuild writes the target's own value there, never this one.
337
+ if (isAddressPosition(collection, field, position))
338
+ continue;
299
339
  if (position.field.type === 'text') {
300
340
  if (typeof value !== 'string')
301
341
  unreadable(position);
@@ -524,8 +564,11 @@ export async function translateDocument(input) {
524
564
  // never replaced by the base's text: the target keeps its value, the skips say why.
525
565
  if (whole && !complete)
526
566
  continue;
527
- // EC-738: the target's locked positions, by key (judged in the plan).
528
- write(field.name, locale, withLockedFrom(fieldValuePosition(field, value, { locale }), current, positionCtx), kind);
567
+ // EC-738: the target's locked positions, by key (judged in the plan). EC-779: and its own
568
+ // address — a `replace` keeps the canonical it holds, a `fill` (it held none; `current` is
569
+ // the base's, displayed) writes none.
570
+ const kept = withLockedFrom(fieldValuePosition(field, value, { locale }), current, positionCtx);
571
+ write(field.name, locale, withOwnAddress(collection, field, kept, kind === 'replace' ? current : undefined), kind);
529
572
  bump(locale, applied);
530
573
  }
531
574
  // 4. Slugs: derive each per-locale slug that still follows the base from the (now