UNPKG

@wordpress/core-data

Version:
8 lines (7 loc) 18.6 kB
{ "version": 3, "sources": ["../../src/utils/crdt.ts"], "sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\n// @ts-expect-error No exported types.\nimport { __unstableSerializeAndClean } from '@wordpress/blocks';\nimport {\n\ttype CRDTDoc,\n\ttype ObjectData,\n\ttype SyncConfig,\n\tY,\n} from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { BaseAwareness } from '../awareness/base-awareness';\nimport {\n\tmergeCrdtBlocks,\n\tmergeRichTextUpdate,\n\ttype Block,\n\ttype YBlock,\n\ttype YBlocks,\n} from './crdt-blocks';\nimport { type Post } from '../entity-types/post';\nimport { type Type } from '../entity-types';\nimport {\n\tCRDT_DOC_META_PERSISTENCE_KEY,\n\tCRDT_RECORD_MAP_KEY,\n\tWORDPRESS_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\n} from '../sync';\nimport type { WPSelection } from '../types';\nimport { updateSelectionHistory } from './crdt-selection';\nimport {\n\tcreateYMap,\n\tgetRootMap,\n\tisYMap,\n\ttype YMapRecord,\n\ttype YMapWrap,\n} from './crdt-utils';\n\n// Changes that can be applied to a post entity record.\nexport type PostChanges = Partial< Post > & {\n\tblocks?: Block[];\n\tcontent?: Post[ 'content' ] | string;\n\texcerpt?: Post[ 'excerpt' ] | string;\n\tselection?: WPSelection;\n\ttitle?: Post[ 'title' ] | string;\n};\n\n// A post record as represented in the CRDT document (Y.Map).\nexport interface YPostRecord extends YMapRecord {\n\tauthor: number;\n\t// Blocks are undefined when they need to be re-parsed from content.\n\tblocks: YBlocks | undefined;\n\tcontent: Y.Text;\n\tcategories: number[];\n\tcomment_status: string;\n\tdate: string | null;\n\texcerpt: Y.Text;\n\tfeatured_media: number;\n\tformat: string;\n\tmeta: YMapWrap< YMapRecord >;\n\tping_status: string;\n\tslug: string;\n\tstatus: string;\n\tsticky: boolean;\n\ttags: number[];\n\ttemplate: string;\n\ttitle: Y.Text;\n}\n\n// Properties that are allowed to be synced for a post.\nconst allowedPostProperties = new Set< string >( [\n\t'author',\n\t'blocks',\n\t'content',\n\t'categories',\n\t'comment_status',\n\t'date',\n\t'excerpt',\n\t'featured_media',\n\t'format',\n\t'meta',\n\t'ping_status',\n\t'slug',\n\t'status',\n\t'sticky',\n\t'tags',\n\t'template',\n\t'title',\n] );\n\n// Post meta keys that should *not* be synced.\nconst disallowedPostMetaKeys = new Set< string >( [\n\tWORDPRESS_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\n] );\n\n/**\n * Given a set of local changes to a generic entity record, apply those changes\n * to the local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {Partial< ObjectData >} changes\n * @return {void}\n */\nfunction defaultApplyChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: ObjectData\n): void {\n\tconst ymap = getRootMap( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t}\n\t\t}\n\t} );\n}\n\n/**\n * Given a set of local changes to a post record, apply those changes to the\n * local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {PostChanges} changes\n * @param {Type} _postType\n * @return {void}\n */\nexport function applyPostChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: PostChanges,\n\t_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): void {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tObject.keys( changes ).forEach( ( key ) => {\n\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newValue = changes[ key ];\n\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\tcase 'blocks': {\n\t\t\t\t// Blocks are undefined when they need to be re-parsed from content.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\t// Set to undefined instead of deleting the key. This is important\n\t\t\t\t\t// since we iterate over the Y.Map keys in getPostChangesFromCRDTDoc.\n\t\t\t\t\tymap.set( key, undefined );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tlet currentBlocks = ymap.get( key );\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! ( currentBlocks instanceof Y.Array ) ) {\n\t\t\t\t\tcurrentBlocks = new Y.Array< YBlock >();\n\t\t\t\t\tymap.set( key, currentBlocks );\n\t\t\t\t}\n\n\t\t\t\t// Block changes from typing are bundled with a 'selection' update.\n\t\t\t\t// Pass the resulting cursor position to the mergeCrdtBlocks function.\n\t\t\t\tconst cursorPosition =\n\t\t\t\t\tchanges.selection?.selectionStart?.offset ?? null;\n\n\t\t\t\t// Merge blocks does not need `setValue` because it is operating on a\n\t\t\t\t// Yjs type that is already in the Y.Doc.\n\t\t\t\tmergeCrdtBlocks( currentBlocks, newValue, cursorPosition );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'content':\n\t\t\tcase 'excerpt':\n\t\t\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tlet rawValue = getRawValue( newValue );\n\n\t\t\t\t// Copy logic from prePersistPostType to ensure that the \"Auto\n\t\t\t\t// Draft\" template title is not synced.\n\t\t\t\tif (\n\t\t\t\t\tkey === 'title' &&\n\t\t\t\t\t! currentValue?.toString() &&\n\t\t\t\t\t'Auto Draft' === rawValue\n\t\t\t\t) {\n\t\t\t\t\trawValue = '';\n\t\t\t\t}\n\n\t\t\t\tif ( currentValue instanceof Y.Text ) {\n\t\t\t\t\tmergeRichTextUpdate( currentValue, rawValue ?? '' );\n\t\t\t\t} else {\n\t\t\t\t\tconst newYText = new Y.Text( rawValue ?? '' );\n\t\t\t\t\tymap.set( key, newYText );\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// \"Meta\" is overloaded term; here, it refers to post meta.\n\t\t\tcase 'meta': {\n\t\t\t\tlet metaMap = ymap.get( 'meta' );\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! isYMap( metaMap ) ) {\n\t\t\t\t\tmetaMap = createYMap< YMapRecord >();\n\t\t\t\t\tymap.set( 'meta', metaMap );\n\t\t\t\t}\n\n\t\t\t\t// Iterate over each meta property in the new value and merge it if it\n\t\t\t\t// should be synced.\n\t\t\t\tObject.entries( newValue ?? {} ).forEach(\n\t\t\t\t\t( [ metaKey, metaValue ] ) => {\n\t\t\t\t\t\tif ( disallowedPostMetaKeys.has( metaKey ) ) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tupdateMapValue(\n\t\t\t\t\t\t\tmetaMap,\n\t\t\t\t\t\t\tmetaKey,\n\t\t\t\t\t\t\tmetaMap.get( metaKey ), // current value in CRDT\n\t\t\t\t\t\t\tmetaValue // new value from changes\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'slug': {\n\t\t\t\t// Do not sync an empty slug. This indicates that the post is using\n\t\t\t\t// the default auto-generated slug.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Add support for additional properties here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tupdateMapValue( ymap, key, currentValue, newValue );\n\t\t\t}\n\t\t}\n\t} );\n\n\t// Process changes that we don't want to persist to the CRDT document.\n\tif ( changes.selection ) {\n\t\tconst selection = changes.selection;\n\t\t// Persist selection changes at the end of the current event loop.\n\t\t// This allows undo meta to be saved with the current selection before\n\t\t// it is overwritten by the new selection from Gutenberg.\n\t\t// Without this, selection history will already contain the latest\n\t\t// selection (after this change) when the undo stack is saved.\n\t\tsetTimeout( () => {\n\t\t\tupdateSelectionHistory( ydoc, selection );\n\t\t}, 0 );\n\t}\n}\n\nfunction defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {\n\treturn getRootMap( crdtDoc, CRDT_RECORD_MAP_KEY ).toJSON();\n}\n\n/**\n * Given a local Y.Doc that *may* contain changes from remote peers, compare\n * against the local record and determine if there are changes (edits) we want\n * to dispatch.\n *\n * @param {CRDTDoc} ydoc\n * @param {Post} editedRecord\n * @param {Type} _postType\n * @return {Partial<PostChanges>} The changes that should be applied to the local record.\n */\nexport function getPostChangesFromCRDTDoc(\n\tydoc: CRDTDoc,\n\teditedRecord: Post,\n\t_postType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): PostChanges {\n\tconst ymap = getRootMap< YPostRecord >( ydoc, CRDT_RECORD_MAP_KEY );\n\n\tlet allowedMetaChanges: Post[ 'meta' ] = {};\n\n\tconst changes = Object.fromEntries(\n\t\tObject.entries( ymap.toJSON() ).filter( ( [ key, newValue ] ) => {\n\t\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst currentValue = editedRecord[ key ];\n\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\t// When we are passed a persisted CRDT document, make a special\n\t\t\t\t\t// comparison of the content and blocks.\n\t\t\t\t\t//\n\t\t\t\t\t// When other fields (besides `blocks`) are mutated outside the block\n\t\t\t\t\t// editor, the change is caught by an equality check (see other cases\n\t\t\t\t\t// in this `switch` statement). As a transient property, `blocks`\n\t\t\t\t\t// cannot be directly mutated outside the block editor -- only\n\t\t\t\t\t// `content` can.\n\t\t\t\t\t//\n\t\t\t\t\t// Therefore, for this special comparison, we serialize the `blocks`\n\t\t\t\t\t// from the persisted CRDT document and compare that to the content\n\t\t\t\t\t// from the persisted record. If they differ, we know that the content\n\t\t\t\t\t// in the database has changed, and therefore the blocks have changed.\n\t\t\t\t\t//\n\t\t\t\t\t// We cannot directly compare the `blocks` from the CRDT document to\n\t\t\t\t\t// the `blocks` derived from the `content` in the persisted record,\n\t\t\t\t\t// because the latter will have different client IDs.\n\t\t\t\t\tif (\n\t\t\t\t\t\tydoc.meta?.get( CRDT_DOC_META_PERSISTENCE_KEY ) &&\n\t\t\t\t\t\teditedRecord.content\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst blocksJson = ymap.get( 'blocks' )?.toJSON() ?? [];\n\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t__unstableSerializeAndClean( blocksJson ).trim() !==\n\t\t\t\t\t\t\tgetRawValue( editedRecord.content )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\t// The consumers of blocks have memoization that renders optimization\n\t\t\t\t\t// here unnecessary.\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tcase 'date': {\n\t\t\t\t\t// Do not overwrite a \"floating\" date. Borrowing logic from the\n\t\t\t\t\t// isEditedPostDateFloating selector.\n\t\t\t\t\tconst currentDateIsFloating =\n\t\t\t\t\t\t[ 'draft', 'auto-draft', 'pending' ].includes(\n\t\t\t\t\t\t\tymap.get( 'status' ) as string\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\t( null === currentValue ||\n\t\t\t\t\t\t\teditedRecord.modified === currentValue );\n\n\t\t\t\t\tif ( currentDateIsFloating ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'meta': {\n\t\t\t\t\tallowedMetaChanges = Object.fromEntries(\n\t\t\t\t\t\tObject.entries( newValue ?? {} ).filter(\n\t\t\t\t\t\t\t( [ metaKey ] ) =>\n\t\t\t\t\t\t\t\t! disallowedPostMetaKeys.has( metaKey )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\t// Merge the allowed meta changes with the current meta values since\n\t\t\t\t\t// not all meta properties are synced.\n\t\t\t\t\tconst mergedValue = {\n\t\t\t\t\t\t...( currentValue as PostChanges[ 'meta' ] ),\n\t\t\t\t\t\t...allowedMetaChanges,\n\t\t\t\t\t};\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, mergedValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'status': {\n\t\t\t\t\t// Do not sync an invalid status.\n\t\t\t\t\tif ( 'auto-draft' === newValue ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'content':\n\t\t\t\tcase 'excerpt':\n\t\t\t\tcase 'title': {\n\t\t\t\t\treturn haveValuesChanged(\n\t\t\t\t\t\tgetRawValue( currentValue ),\n\t\t\t\t\t\tnewValue\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Add support for additional data types here.\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\t\t\t}\n\t\t} )\n\t);\n\n\t// Meta changes must be merged with the edited record since not all meta\n\t// properties are synced.\n\tif ( 'object' === typeof changes.meta ) {\n\t\tchanges.meta = {\n\t\t\t...editedRecord.meta,\n\t\t\t...allowedMetaChanges,\n\t\t};\n\t}\n\n\treturn changes;\n}\n\n/**\n * This default sync config can be used for entities that are flat maps of\n * primitive values and do not require custom logic to merge changes.\n */\nexport const defaultSyncConfig: SyncConfig = {\n\tapplyChangesToCRDTDoc: defaultApplyChangesToCRDTDoc,\n\tcreateAwareness: ( ydoc: CRDTDoc ) => new BaseAwareness( ydoc ),\n\tgetChangesFromCRDTDoc: defaultGetChangesFromCRDTDoc,\n};\n\n/**\n * Extract the raw string value from a property that may be a string or an object\n * with a `raw` property (`RenderedText`).\n *\n * @param {unknown} value The value to extract from.\n * @return {string|undefined} The raw string value, or undefined if it could not be determined.\n */\nfunction getRawValue( value?: unknown ): string | undefined {\n\t// Value may be a string property or a nested object with a `raw` property.\n\tif ( 'string' === typeof value ) {\n\t\treturn value;\n\t}\n\n\tif (\n\t\tvalue &&\n\t\t'object' === typeof value &&\n\t\t'raw' in value &&\n\t\t'string' === typeof value.raw\n\t) {\n\t\treturn value.raw;\n\t}\n\n\treturn undefined;\n}\n\nfunction haveValuesChanged< ValueType >(\n\tcurrentValue: ValueType | undefined,\n\tnewValue: ValueType | undefined\n): boolean {\n\treturn ! fastDeepEqual( currentValue, newValue );\n}\n\nfunction updateMapValue< T extends YMapRecord, K extends keyof T >(\n\tmap: YMapWrap< T >,\n\tkey: K,\n\tcurrentValue: T[ K ] | undefined,\n\tnewValue: T[ K ] | undefined\n): void {\n\tif ( undefined === newValue ) {\n\t\tmap.delete( key );\n\t\treturn;\n\t}\n\n\tif ( haveValuesChanged< T[ K ] >( currentValue, newValue ) ) {\n\t\tmap.set( key, newValue );\n\t}\n}\n"], "mappings": ";AAGA,OAAO,mBAAmB;AAM1B,SAAS,mCAAmC;AAC5C;AAAA,EAIC;AAAA,OACM;AAKP,SAAS,qBAAqB;AAC9B;AAAA,EACC;AAAA,EACA;AAAA,OAIM;AAGP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,8BAA8B;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AAkCP,IAAM,wBAAwB,oBAAI,IAAe;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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