diff --git a/models/document/package.json b/models/document/package.json index 14319dd6de..40867b7e9b 100644 --- a/models/document/package.json +++ b/models/document/package.json @@ -49,6 +49,7 @@ "@hcengineering/tags": "^0.6.12", "@hcengineering/time": "^0.6.0", "@hcengineering/document": "^0.6.0", - "@hcengineering/document-resources": "^0.6.0" + "@hcengineering/document-resources": "^0.6.0", + "@hcengineering/collaboration": "^0.6.0" } } diff --git a/models/document/src/migration.ts b/models/document/src/migration.ts index 88c78b36ca..c6490ebf78 100644 --- a/models/document/src/migration.ts +++ b/models/document/src/migration.ts @@ -14,7 +14,14 @@ // import { type Attachment } from '@hcengineering/attachment' -import { DOMAIN_TX, getCollaborativeDoc, type Class, type Doc, type Ref } from '@hcengineering/core' +import { + DOMAIN_TX, + getCollaborativeDoc, + MeasureMetricsContext, + type Class, + type Doc, + type Ref +} from '@hcengineering/core' import { type Document, type Teamspace } from '@hcengineering/document' import { tryMigrate, @@ -27,6 +34,7 @@ import core, { DOMAIN_SPACE } from '@hcengineering/model-core' import { type Asset } from '@hcengineering/platform' import document, { documentId, DOMAIN_DOCUMENT } from './index' +import { loadCollaborativeDoc, saveCollaborativeDoc, yDocCopyXmlField } from '@hcengineering/collaboration' async function migrateCollaborativeContent (client: MigrationClient): Promise { const attachedFiles = await client.find(DOMAIN_ATTACHMENT, { @@ -265,6 +273,36 @@ async function migrateTeamspacesMixins (client: MigrationClient): Promise ) } +async function migrateContentField (client: MigrationClient): Promise { + const ctx = new MeasureMetricsContext('migrate_content_field', {}) + + const storage = client.storageAdapter + if (storage === undefined) { + return + } + + const documents = await client.find(DOMAIN_DOCUMENT, { + content: { $exists: true } + }) + + for (const document of documents) { + try { + const ydoc = await loadCollaborativeDoc(storage, client.workspaceId, document.content, ctx) + if (ydoc === undefined) { + continue + } + + if (!ydoc.share.has('')) { + continue + } + + yDocCopyXmlField(ydoc, '', 'content') + + await saveCollaborativeDoc(storage, client.workspaceId, document.content, ydoc, ctx) + } catch {} + } +} + export const documentOperation: MigrateOperation = { async migrate (client: MigrationClient): Promise { await tryMigrate(client, documentId, [ @@ -296,15 +334,15 @@ export const documentOperation: MigrateOperation = { }, { state: 'migrate-timespaces', - func: async (client) => { - await migrateTeamspaces(client) - } + func: migrateTeamspaces }, { state: 'migrate-teamspaces-mixins', - func: async (client) => { - await migrateTeamspacesMixins(client) - } + func: migrateTeamspacesMixins + }, + { + state: 'migrateContentField', + func: migrateContentField } ]) }, diff --git a/packages/text-editor/src/components/CollaborativeTextEditor.svelte b/packages/text-editor/src/components/CollaborativeTextEditor.svelte index eb61c24ce5..50ca74c1cc 100644 --- a/packages/text-editor/src/components/CollaborativeTextEditor.svelte +++ b/packages/text-editor/src/components/CollaborativeTextEditor.svelte @@ -75,7 +75,7 @@ export let collaborativeDoc: CollaborativeDoc export let initialCollaborativeDoc: CollaborativeDoc | undefined = undefined - export let field: string | undefined = undefined + export let field: string export let objectClass: Ref> | undefined export let objectId: Ref | undefined diff --git a/packages/text-editor/src/components/CollaboratorEditor.svelte b/packages/text-editor/src/components/CollaboratorEditor.svelte index 9b396a33ae..4e9b8d8538 100644 --- a/packages/text-editor/src/components/CollaboratorEditor.svelte +++ b/packages/text-editor/src/components/CollaboratorEditor.svelte @@ -30,7 +30,7 @@ export let collaborativeDoc: CollaborativeDoc export let initialCollaborativeDoc: CollaborativeDoc | undefined = undefined - export let field: string | undefined = undefined + export let field: string export let objectClass: Ref> | undefined = undefined export let objectId: Ref | undefined = undefined diff --git a/plugins/document-resources/src/components/DocumentEditor.svelte b/plugins/document-resources/src/components/DocumentEditor.svelte index 4cc892ddb7..e2387abee0 100644 --- a/plugins/document-resources/src/components/DocumentEditor.svelte +++ b/plugins/document-resources/src/components/DocumentEditor.svelte @@ -93,6 +93,7 @@ objectClass={object._class} objectId={object._id} objectAttr="content" + field="content" {user} {userComponent} {focusIndex}