@wordpress/core-data 7.37.1-next.v.0 → 7.38.0

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 (55) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/actions.cjs +14 -2
  3. package/build/actions.cjs.map +2 -2
  4. package/build/entities.cjs +35 -45
  5. package/build/entities.cjs.map +2 -2
  6. package/build/private-selectors.cjs +2 -4
  7. package/build/private-selectors.cjs.map +2 -2
  8. package/build/resolvers.cjs +11 -2
  9. package/build/resolvers.cjs.map +2 -2
  10. package/build/types.cjs.map +1 -1
  11. package/build/utils/crdt-blocks.cjs +63 -41
  12. package/build/utils/crdt-blocks.cjs.map +2 -2
  13. package/build/utils/crdt-utils.cjs +44 -0
  14. package/build/utils/crdt-utils.cjs.map +7 -0
  15. package/build/utils/crdt.cjs +33 -37
  16. package/build/utils/crdt.cjs.map +2 -2
  17. package/build-module/actions.mjs +14 -2
  18. package/build-module/actions.mjs.map +2 -2
  19. package/build-module/entities.mjs +35 -47
  20. package/build-module/entities.mjs.map +2 -2
  21. package/build-module/private-selectors.mjs +2 -4
  22. package/build-module/private-selectors.mjs.map +2 -2
  23. package/build-module/resolvers.mjs +11 -2
  24. package/build-module/resolvers.mjs.map +2 -2
  25. package/build-module/utils/crdt-blocks.mjs +64 -42
  26. package/build-module/utils/crdt-blocks.mjs.map +2 -2
  27. package/build-module/utils/crdt-utils.mjs +17 -0
  28. package/build-module/utils/crdt-utils.mjs.map +7 -0
  29. package/build-module/utils/crdt.mjs +37 -37
  30. package/build-module/utils/crdt.mjs.map +2 -2
  31. package/build-types/actions.d.ts.map +1 -1
  32. package/build-types/entities.d.ts.map +1 -1
  33. package/build-types/index.d.ts.map +1 -1
  34. package/build-types/private-selectors.d.ts.map +1 -1
  35. package/build-types/resolvers.d.ts.map +1 -1
  36. package/build-types/types.d.ts +0 -5
  37. package/build-types/types.d.ts.map +1 -1
  38. package/build-types/utils/crdt-blocks.d.ts +14 -5
  39. package/build-types/utils/crdt-blocks.d.ts.map +1 -1
  40. package/build-types/utils/crdt-utils.d.ts +53 -0
  41. package/build-types/utils/crdt-utils.d.ts.map +1 -0
  42. package/build-types/utils/crdt.d.ts +19 -1
  43. package/build-types/utils/crdt.d.ts.map +1 -1
  44. package/package.json +18 -18
  45. package/src/actions.js +13 -2
  46. package/src/entities.js +38 -54
  47. package/src/private-selectors.ts +3 -4
  48. package/src/resolvers.js +15 -7
  49. package/src/test/entities.js +11 -9
  50. package/src/test/resolvers.js +3 -45
  51. package/src/types.ts +0 -6
  52. package/src/utils/crdt-blocks.ts +101 -99
  53. package/src/utils/crdt-utils.ts +77 -0
  54. package/src/utils/crdt.ts +76 -57
  55. package/src/utils/test/crdt.ts +28 -16
@@ -1,9 +1,10 @@
1
1
  // packages/core-data/src/utils/crdt-blocks.ts
2
2
  import { v4 as uuidv4 } from "uuid";
3
3
  import fastDeepEqual from "fast-deep-equal/es6/index.js";
4
- import { RichTextData } from "@wordpress/rich-text";
5
- import { Y } from "@wordpress/sync";
6
4
  import { getBlockTypes } from "@wordpress/blocks";
5
+ import { RichTextData } from "@wordpress/rich-text";
6
+ import { Y, Delta } from "@wordpress/sync";
7
+ import { createYMap } from "./crdt-utils.mjs";
7
8
  var serializableBlocksCache = /* @__PURE__ */ new WeakMap();
8
9
  function makeBlockAttributesSerializable(attributes) {
9
10
  const newAttributes = { ...attributes };
@@ -16,10 +17,8 @@ function makeBlockAttributesSerializable(attributes) {
16
17
  }
17
18
  function makeBlocksSerializable(blocks) {
18
19
  return blocks.map((block) => {
19
- const blockAsJson = block instanceof Y.Map ? block.toJSON() : block;
20
- const { name, innerBlocks, attributes, ...rest } = blockAsJson;
20
+ const { name, innerBlocks, attributes, ...rest } = block;
21
21
  delete rest.validationIssues;
22
- delete rest.originalContent;
23
22
  return {
24
23
  ...rest,
25
24
  name,
@@ -40,7 +39,7 @@ function areBlocksEqual(gblock, yblock) {
40
39
  );
41
40
  const inners = gblock.innerBlocks || [];
42
41
  const yinners = yblock.get("innerBlocks");
43
- return res && inners.length === yinners.length && inners.every(
42
+ return res && inners.length === yinners?.length && inners.every(
44
43
  (block, i) => areBlocksEqual(block, yinners.get(i))
45
44
  );
46
45
  }
@@ -68,32 +67,37 @@ function createNewYAttributeValue(blockName, attributeName, attributeValue) {
68
67
  return attributeValue;
69
68
  }
70
69
  function createNewYBlock(block) {
71
- return new Y.Map(
72
- Object.entries(block).map(([key, value]) => {
73
- switch (key) {
74
- case "attributes": {
75
- return [key, createNewYAttributeMap(block.name, value)];
76
- }
77
- case "innerBlocks": {
78
- const innerBlocks = new Y.Array();
79
- if (!Array.isArray(value)) {
70
+ return createYMap(
71
+ Object.fromEntries(
72
+ Object.entries(block).map(([key, value]) => {
73
+ switch (key) {
74
+ case "attributes": {
75
+ return [
76
+ key,
77
+ createNewYAttributeMap(block.name, value)
78
+ ];
79
+ }
80
+ case "innerBlocks": {
81
+ const innerBlocks = new Y.Array();
82
+ if (!Array.isArray(value)) {
83
+ return [key, innerBlocks];
84
+ }
85
+ innerBlocks.insert(
86
+ 0,
87
+ value.map(
88
+ (innerBlock) => createNewYBlock(innerBlock)
89
+ )
90
+ );
80
91
  return [key, innerBlocks];
81
92
  }
82
- innerBlocks.insert(
83
- 0,
84
- value.map(
85
- (innerBlock) => createNewYBlock(innerBlock)
86
- )
87
- );
88
- return [key, innerBlocks];
93
+ default:
94
+ return [key, value];
89
95
  }
90
- default:
91
- return [key, value];
92
- }
93
- })
96
+ })
97
+ )
94
98
  );
95
99
  }
96
- function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
100
+ function mergeCrdtBlocks(yblocks, incomingBlocks, cursorPosition) {
97
101
  if (!serializableBlocksCache.has(incomingBlocks)) {
98
102
  serializableBlocksCache.set(
99
103
  incomingBlocks,
@@ -132,9 +136,7 @@ function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
132
136
  Object.entries(block).forEach(([key, value]) => {
133
137
  switch (key) {
134
138
  case "attributes": {
135
- const currentAttributes = yblock.get(
136
- key
137
- );
139
+ const currentAttributes = yblock.get(key);
138
140
  if (!currentAttributes) {
139
141
  yblock.set(
140
142
  key,
@@ -150,19 +152,16 @@ function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
150
152
  )) {
151
153
  return;
152
154
  }
155
+ const currentAttribute = currentAttributes.get(attributeName);
153
156
  const isRichText = isRichTextAttribute(
154
157
  block.name,
155
158
  attributeName
156
159
  );
157
- if (isRichText && "string" === typeof attributeValue && currentAttributes.has(attributeName) && currentAttributes.get(
158
- attributeName
159
- ) instanceof Y.Text) {
160
+ if (isRichText && "string" === typeof attributeValue && currentAttributes.has(attributeName) && currentAttribute instanceof Y.Text) {
160
161
  mergeRichTextUpdate(
161
- currentAttributes.get(
162
- attributeName
163
- ),
162
+ currentAttribute,
164
163
  attributeValue,
165
- lastSelection
164
+ cursorPosition
166
165
  );
167
166
  } else {
168
167
  currentAttributes.set(
@@ -186,8 +185,16 @@ function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
186
185
  break;
187
186
  }
188
187
  case "innerBlocks": {
189
- const yInnerBlocks = yblock.get(key);
190
- mergeCrdtBlocks(yInnerBlocks, value ?? [], lastSelection);
188
+ let yInnerBlocks = yblock.get(key);
189
+ if (!(yInnerBlocks instanceof Y.Array)) {
190
+ yInnerBlocks = new Y.Array();
191
+ yblock.set(key, yInnerBlocks);
192
+ }
193
+ mergeCrdtBlocks(
194
+ yInnerBlocks,
195
+ value ?? [],
196
+ cursorPosition
197
+ );
191
198
  break;
192
199
  }
193
200
  default:
@@ -211,6 +218,9 @@ function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
211
218
  for (let j = 0; j < yblocks.length; j++) {
212
219
  const yblock = yblocks.get(j);
213
220
  let clientId = yblock.get("clientId");
221
+ if (!clientId) {
222
+ continue;
223
+ }
214
224
  if (knownClientIds.has(clientId)) {
215
225
  clientId = uuidv4();
216
226
  yblock.set("clientId", clientId);
@@ -247,9 +257,21 @@ function isRichTextAttribute(blockName, attributeName) {
247
257
  }
248
258
  return cachedRichTextAttributes.get(blockName)?.has(attributeName) ?? false;
249
259
  }
250
- function mergeRichTextUpdate(blockYText, updatedValue, lastSelection) {
251
- blockYText.delete(0, blockYText.toString().length);
252
- blockYText.insert(0, updatedValue);
260
+ var localDoc;
261
+ function mergeRichTextUpdate(blockYText, updatedValue, cursorPosition) {
262
+ if (!localDoc) {
263
+ localDoc = new Y.Doc();
264
+ }
265
+ const localYText = localDoc.getText("temporary-text");
266
+ localYText.delete(0, localYText.length);
267
+ localYText.insert(0, updatedValue);
268
+ const currentValueAsDelta = new Delta(blockYText.toDelta());
269
+ const updatedValueAsDelta = new Delta(localYText.toDelta());
270
+ const deltaDiff = currentValueAsDelta.diffWithCursor(
271
+ updatedValueAsDelta,
272
+ cursorPosition
273
+ );
274
+ blockYText.applyDelta(deltaDiff.ops);
253
275
  }
254
276
  export {
255
277
  mergeCrdtBlocks
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/crdt-blocks.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuidv4 } from 'uuid';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n// @ts-expect-error No exported types.\nimport { getBlockTypes } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport type { WPBlockSelection } from '../types';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockType {\n\tname: string;\n\tattributes?: Record< string, { type?: string } >;\n}\n\nexport interface Block {\n\tattributes: BlockAttributes;\n\tclientId?: string;\n\tinnerBlocks: Block[];\n\toriginalContent?: string; // unserializable\n\tvalidationIssues?: string[]; // unserializable\n\tname: string;\n}\n\nexport type YBlock = Y.Map<\n\t/* name, clientId, and originalContent are strings. */\n\t| string\n\t/* validationIssues? is an array of strings. */\n\t| string[]\n\t/* attributes is a Y.Map< unknown >. */\n\t| YBlockAttributes\n\t/* innerBlocks is a Y.Array< YBlock >. */\n\t| YBlocks\n>;\n\nexport type YBlocks = Y.Array< YBlock >;\nexport type YBlockAttributes = Y.Map< Y.Text | unknown >;\n\n// The Y.Map type is not easy to work with. The generic type it accepts represents\n// the possible values of the map, which are varied in our case. This type is\n// accurate, but will require aggressive type narrowing when the map values are\n// accessed -- or type casting with `as`.\n// export type YBlock = Y.Map< Block[ keyof Block ] >;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\nfunction makeBlockAttributesSerializable(\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( value instanceof RichTextData ) {\n\t\t\tnewAttributes[ key ] = value.valueOf();\n\t\t}\n\t}\n\treturn newAttributes;\n}\n\nfunction makeBlocksSerializable( blocks: Block[] | YBlocks ): Block[] {\n\treturn blocks.map( ( block: Block | YBlock ) => {\n\t\tconst blockAsJson = block instanceof Y.Map ? block.toJSON() : block;\n\t\tconst { name, innerBlocks, attributes, ...rest } = blockAsJson;\n\t\tdelete rest.validationIssues;\n\t\tdelete rest.originalContent;\n\t\t// delete rest.isValid\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * @param {any} gblock\n * @param {Y.Map} yblock\n */\nfunction areBlocksEqual( gblock: Block, yblock: YBlock ): boolean {\n\tconst yblockAsJson = yblock.toJSON();\n\n\t// we must not sync clientId, as this can't be generated consistently and\n\t// hence will lead to merge conflicts.\n\tconst overwrites = {\n\t\tinnerBlocks: null,\n\t\tclientId: null,\n\t};\n\tconst res = fastDeepEqual(\n\t\tObject.assign( {}, gblock, overwrites ),\n\t\tObject.assign( {}, yblockAsJson, overwrites )\n\t);\n\tconst inners = gblock.innerBlocks || [];\n\tconst yinners = yblock.get( 'innerBlocks' ) as YBlocks;\n\treturn (\n\t\tres &&\n\t\tinners.length === yinners.length &&\n\t\tinners.every( ( block: Block, i: number ) =>\n\t\t\tareBlocksEqual( block, yinners.get( i ) )\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeMap(\n\tblockName: string,\n\tattributes: BlockAttributes\n): YBlockAttributes {\n\treturn new Y.Map(\n\t\tObject.entries( attributes ).map(\n\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\treturn [\n\t\t\t\t\tattributeName,\n\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tattributeValue\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeValue(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): Y.Text | unknown {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\n\tif ( isRichText ) {\n\t\treturn new Y.Text( attributeValue?.toString() ?? '' );\n\t}\n\n\treturn attributeValue;\n}\n\nfunction createNewYBlock( block: Block ): YBlock {\n\treturn new Y.Map(\n\t\tObject.entries( block ).map( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\treturn [ key, createNewYAttributeMap( block.name, value ) ];\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\tconst innerBlocks = new Y.Array();\n\n\t\t\t\t\t// If not an array, set to empty Y.Array.\n\t\t\t\t\tif ( ! Array.isArray( value ) ) {\n\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t}\n\n\t\t\t\t\tinnerBlocks.insert(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tvalue.map( ( innerBlock: Block ) =>\n\t\t\t\t\t\t\tcreateNewYBlock( innerBlock )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\treturn [ key, value ];\n\t\t\t}\n\t\t} )\n\t);\n}\n\n/**\n * Merge incoming block data into the local Y.Doc.\n * This function is called to sync local block changes to a shared Y.Doc.\n *\n * @param yblocks The blocks in the local Y.Doc.\n * @param incomingBlocks Gutenberg blocks being synced, either from a peer or from the local editor.\n * @param lastSelection The last cursor position, used for hinting the diff algorithm.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tlastSelection: WPBlockSelection | null\n): void {\n\t// Ensure we are working with serializable block data.\n\tif ( ! serializableBlocksCache.has( incomingBlocks ) ) {\n\t\tserializableBlocksCache.set(\n\t\t\tincomingBlocks,\n\t\t\tmakeBlocksSerializable( incomingBlocks )\n\t\t);\n\t}\n\tconst allBlocks = serializableBlocksCache.get( incomingBlocks ) ?? [];\n\n\t// Ensure we skip blocks that we don't want to sync at the moment\n\tconst blocksToSync = allBlocks.filter( ( block ) =>\n\t\tshouldBlockBeSynced( block )\n\t);\n\n\t// This is a rudimentary diff implementation similar to the y-prosemirror diffing\n\t// approach.\n\t// A better implementation would also diff the textual content and represent it\n\t// using a Y.Text type.\n\t// However, at this time it makes more sense to keep this algorithm generic to\n\t// support all kinds of block types.\n\t// Ideally, we ensure that block data structure have a consistent data format.\n\t// E.g.:\n\t// - textual content (using rich-text formatting?) may always be stored under `block.text`\n\t// - local information that shouldn't be shared (e.g. clientId or isDragging) is stored under `block.private`\n\t//\n\t// @credit Kevin Jahns (dmonad)\n\t// @link https://github.com/WordPress/gutenberg/pull/68483\n\tconst numOfCommonEntries = Math.min(\n\t\tblocksToSync.length ?? 0,\n\t\tyblocks.length\n\t);\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// skip equal blocks from left\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareBlocksEqual( blocksToSync[ left ], yblocks.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// skip equal blocks from right\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareBlocksEqual(\n\t\t\tblocksToSync[ blocksToSync.length - right - 1 ],\n\t\t\tyblocks.get( yblocks.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tblocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - blocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst block = blocksToSync[ left ];\n\t\tconst yblock = yblocks.get( left );\n\t\tObject.entries( block ).forEach( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\tconst currentAttributes = yblock.get(\n\t\t\t\t\t\tkey\n\t\t\t\t\t) as YBlockAttributes;\n\n\t\t\t\t\t// If attributes are not set on the yblock, use the new values.\n\t\t\t\t\tif ( ! currentAttributes ) {\n\t\t\t\t\t\tyblock.set(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tObject.entries( value ).forEach(\n\t\t\t\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\tcurrentAttributes?.get( attributeName ),\n\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst isRichText = isRichTextAttribute(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tisRichText &&\n\t\t\t\t\t\t\t\t'string' === typeof attributeValue &&\n\t\t\t\t\t\t\t\tcurrentAttributes.has( attributeName ) &&\n\t\t\t\t\t\t\t\tcurrentAttributes.get(\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t) instanceof Y.Text\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// Rich text values are stored as persistent Y.Text instances.\n\t\t\t\t\t\t\t\t// Update the value with a delta in place.\n\t\t\t\t\t\t\t\tmergeRichTextUpdate(\n\t\t\t\t\t\t\t\t\tcurrentAttributes.get(\n\t\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t\t) as Y.Text,\n\t\t\t\t\t\t\t\t\tattributeValue,\n\t\t\t\t\t\t\t\t\tlastSelection\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentAttributes.set(\n\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\tcurrentAttributes.forEach(\n\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\tif ( ! value.hasOwnProperty( attrName ) ) {\n\t\t\t\t\t\t\t\tcurrentAttributes.delete( attrName );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\tconst yInnerBlocks = yblock.get( key ) as Y.Array< YBlock >;\n\t\t\t\t\tmergeCrdtBlocks( yInnerBlocks, value ?? [], lastSelection );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tif ( ! fastDeepEqual( block[ key ], yblock.get( key ) ) ) {\n\t\t\t\t\t\tyblock.set( key, value );\n\t\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tyblock.forEach( ( _v, k ) => {\n\t\t\tif ( ! block.hasOwnProperty( k ) ) {\n\t\t\t\tyblock.delete( k );\n\t\t\t}\n\t\t} );\n\t}\n\n\t// deletes\n\tyblocks.delete( left, numOfDeletionsNeeded );\n\n\t// inserts\n\tfor ( let i = 0; i < numOfInsertionsNeeded; i++, left++ ) {\n\t\tconst newBlock = [ createNewYBlock( blocksToSync[ left ] ) ];\n\n\t\tyblocks.insert( left, newBlock );\n\t}\n\n\t// remove duplicate clientids\n\tconst knownClientIds = new Set< string >();\n\tfor ( let j = 0; j < yblocks.length; j++ ) {\n\t\tconst yblock: YBlock = yblocks.get( j );\n\n\t\tlet clientId: string = yblock.get( 'clientId' ) as string;\n\n\t\tif ( knownClientIds.has( clientId ) ) {\n\t\t\tclientId = uuidv4();\n\t\t\tyblock.set( 'clientId', clientId );\n\t\t}\n\t\tknownClientIds.add( clientId );\n\t}\n}\n\n/**\n * Determine if a block should be synced.\n *\n * Ex: A gallery block should not be synced until the images have been\n * uploaded to WordPress, and their url is available. Before that,\n * it's not possible to access the blobs on a client as those are\n * local.\n *\n * @param block The block to check.\n * @return True if the block should be synced, false otherwise.\n */\nfunction shouldBlockBeSynced( block: Block ): boolean {\n\t// Verify that the gallery block is ready to be synced.\n\t// This means that, all images have had their blobs converted to full URLs.\n\t// Checking for only the blobs ensures that blocks that have just been inserted work as well.\n\tif ( 'core/gallery' === block.name ) {\n\t\treturn ! block.innerBlocks.some(\n\t\t\t( innerBlock ) =>\n\t\t\t\tinnerBlock.attributes && innerBlock.attributes.blob\n\t\t);\n\t}\n\n\t// Allow all other blocks to be synced.\n\treturn true;\n}\n\n// Cache rich-text attributes for all block types.\nlet cachedRichTextAttributes: Map< string, Map< string, true > >;\n\n/**\n * Given a block name and attribute key, return true if the attribute is rich-text typed.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to check, e.g. 'content'.\n * @return True if the attribute is rich-text typed, false otherwise.\n */\nfunction isRichTextAttribute(\n\tblockName: string,\n\tattributeName: string\n): boolean {\n\tif ( ! cachedRichTextAttributes ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedRichTextAttributes = new Map< string, Map< string, true > >();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tconst richTextAttributeMap = new Map< string, true >();\n\n\t\t\tfor ( const [ name, definition ] of Object.entries(\n\t\t\t\tblockType.attributes ?? {}\n\t\t\t) ) {\n\t\t\t\tif ( 'rich-text' === definition.type ) {\n\t\t\t\t\trichTextAttributeMap.set( name, true );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcachedRichTextAttributes.set(\n\t\t\t\tblockType.name,\n\t\t\t\trichTextAttributeMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\tcachedRichTextAttributes.get( blockName )?.has( attributeName ) ?? false\n\t);\n}\n\n/**\n * Given a Y.Text object and an updated string value, diff the new value and\n * apply the delta to the Y.Text.\n *\n * @param blockYText The Y.Text to update.\n * @param updatedValue The updated value.\n * @param lastSelection The last cursor position before this update, used to hint the diff algorithm.\n */\nfunction mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tlastSelection: WPBlockSelection | null\n): void {\n\t// TODO\n\t// ====\n\t// Gutenberg does not use Yjs shared types natively, so we can only subscribe\n\t// to changes from store and apply them to Yjs types that we create and\n\t// manage. Crucially, for rich-text attributes, we do not receive granular\n\t// string updates; we get the new full string value on each change, even when\n\t// only a single character changed.\n\t//\n\t// The code below allows us to compute a delta between the current and new\n\t// value, then apply it to the Y.Text. However, it relies on a library\n\t// (quill-delta) with a licensing issue that we are working to resolve.\n\t//\n\t// For now, we simply replace the full text content on each change.\n\t//\n\t// if ( ! localDoc ) {\n\t// \t// Y.Text must be attached to a Y.Doc to be able to do operations on it.\n\t// \t// Create a temporary Y.Text attached to a local Y.Doc for delta computation.\n\t// \tlocalDoc = new Y.Doc();\n\t// }\n\n\t// const localYText = localDoc.getText( 'temporary-text' );\n\t// localYText.delete( 0, localYText.length );\n\t// localYText.insert( 0, updatedValue );\n\n\t// const currentValueAsDelta = new Delta( blockYText.toDelta() );\n\t// const updatedValueAsDelta = new Delta( localYText.toDelta() );\n\n\t// const deltaDiff = currentValueAsDelta.diff(\n\t// \tupdatedValueAsDelta,\n\t// \tlastSelection?.offset\n\t// );\n\n\t// blockYText.applyDelta( deltaDiff.ops );\n\n\tblockYText.delete( 0, blockYText.toString().length );\n\tblockYText.insert( 0, updatedValue );\n}\n"],
5
- "mappings": ";AAGA,SAAS,MAAM,cAAc;AAC7B,OAAO,mBAAmB;AAK1B,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAGlB,SAAS,qBAAqB;AA6C9B,IAAM,0BAA0B,oBAAI,QAA4B;AAEhE,SAAS,gCACR,YACkB;AAClB,QAAM,gBAAgB,EAAE,GAAG,WAAW;AACtC,aAAY,CAAE,KAAK,KAAM,KAAK,OAAO,QAAS,UAAW,GAAI;AAC5D,QAAK,iBAAiB,cAAe;AACpC,oBAAe,GAAI,IAAI,MAAM,QAAQ;AAAA,IACtC;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,uBAAwB,QAAqC;AACrE,SAAO,OAAO,IAAK,CAAE,UAA2B;AAC/C,UAAM,cAAc,i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MAAK,CAAE,0BAA2B;AAEjC,+BAA2B,oBAAI,IAAmC;AAElE,eAAY,aAAa,cAAc,GAAmB;AACzD,YAAM,uBAAuB,oBAAI,IAAoB;AAErD,iBAAY,CAAE,MAAM,UAAW,KAAK,OAAO;AAAA,QAC1C,UAAU,cAAc,CAAC;AAAA,MAC1B,GAAI;AACH,YAAK,gBAAgB,WAAW,MAAO;AACtC,+BAAqB,IAAK,MAAM,IAAK;AAAA,QACtC;AAAA,MACD;AAEA,+BAAyB;AAAA,QACxB,UAAU;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SACC,yBAAyB,IAAK,SAAU,GAAG,IAAK,aAAc,KAAK;AAErE;AAUA,SAAS,oBACR,YACA,cAEA,eACO;AAmCP,aAAW,OAAQ,GAAG,WAAW,SAAS,EAAE,MAAO;AACnD,aAAW,OAAQ,GAAG,YAAa;AACpC;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuidv4 } from 'uuid';\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * WordPress dependencies\n */\n// @ts-expect-error No exported types.\nimport { getBlockTypes } from '@wordpress/blocks';\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y, Delta } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { createYMap, type YMapRecord, type YMapWrap } from './crdt-utils';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockType {\n\tname: string;\n\tattributes?: Record< string, { type?: string } >;\n}\n\n// A block as represented in Gutenberg's data store.\nexport interface Block {\n\tattributes: BlockAttributes;\n\tclientId?: string;\n\tinnerBlocks: Block[];\n\tisValid?: boolean;\n\tname: string;\n\toriginalContent?: string;\n\tvalidationIssues?: string[]; // unserializable\n}\n\n// A block as represented in the CRDT document (Y.Map).\ninterface YBlockRecord extends YMapRecord {\n\tattributes: YBlockAttributes;\n\tclientId: string;\n\tinnerBlocks: YBlocks;\n\tisValid?: boolean;\n\toriginalContent?: string;\n\tname: string;\n}\n\nexport type YBlock = YMapWrap< YBlockRecord >;\nexport type YBlocks = Y.Array< YBlock >;\n\n// Block attribute schema cannot be known at compile time, so we use Y.Map.\n// Attribute values will be typed as the union of `Y.Text` and `unknown`.\nexport type YBlockAttributes = Y.Map< Y.Text | unknown >;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\nfunction makeBlockAttributesSerializable(\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( value instanceof RichTextData ) {\n\t\t\tnewAttributes[ key ] = value.valueOf();\n\t\t}\n\t}\n\treturn newAttributes;\n}\n\nfunction makeBlocksSerializable( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst { name, innerBlocks, attributes, ...rest } = block;\n\t\tdelete rest.validationIssues;\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * @param {any} gblock\n * @param {Y.Map} yblock\n */\nfunction areBlocksEqual( gblock: Block, yblock: YBlock ): boolean {\n\tconst yblockAsJson = yblock.toJSON();\n\n\t// we must not sync clientId, as this can't be generated consistently and\n\t// hence will lead to merge conflicts.\n\tconst overwrites = {\n\t\tinnerBlocks: null,\n\t\tclientId: null,\n\t};\n\tconst res = fastDeepEqual(\n\t\tObject.assign( {}, gblock, overwrites ),\n\t\tObject.assign( {}, yblockAsJson, overwrites )\n\t);\n\tconst inners = gblock.innerBlocks || [];\n\tconst yinners = yblock.get( 'innerBlocks' );\n\treturn (\n\t\tres &&\n\t\tinners.length === yinners?.length &&\n\t\tinners.every( ( block: Block, i: number ) =>\n\t\t\tareBlocksEqual( block, yinners.get( i ) )\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeMap(\n\tblockName: string,\n\tattributes: BlockAttributes\n): YBlockAttributes {\n\treturn new Y.Map(\n\t\tObject.entries( attributes ).map(\n\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\treturn [\n\t\t\t\t\tattributeName,\n\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tattributeValue\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeValue(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): Y.Text | unknown {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\n\tif ( isRichText ) {\n\t\treturn new Y.Text( attributeValue?.toString() ?? '' );\n\t}\n\n\treturn attributeValue;\n}\n\nfunction createNewYBlock( block: Block ): YBlock {\n\treturn createYMap< YBlockRecord >(\n\t\tObject.fromEntries(\n\t\t\tObject.entries( block ).map( ( [ key, value ] ) => {\n\t\t\t\tswitch ( key ) {\n\t\t\t\t\tcase 'attributes': {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value ),\n\t\t\t\t\t\t];\n\t\t\t\t\t}\n\n\t\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t\tconst innerBlocks = new Y.Array();\n\n\t\t\t\t\t\t// If not an array, set to empty Y.Array.\n\t\t\t\t\t\tif ( ! Array.isArray( value ) ) {\n\t\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tinnerBlocks.insert(\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\tvalue.map( ( innerBlock: Block ) =>\n\t\t\t\t\t\t\t\tcreateNewYBlock( innerBlock )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t}\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\treturn [ key, value ];\n\t\t\t\t}\n\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Merge incoming block data into the local Y.Doc.\n * This function is called to sync local block changes to a shared Y.Doc.\n *\n * @param yblocks The blocks in the local Y.Doc.\n * @param incomingBlocks Gutenberg blocks being synced.\n * @param cursorPosition The position of the cursor after the change occurs.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tcursorPosition: number | null\n): void {\n\t// Ensure we are working with serializable block data.\n\tif ( ! serializableBlocksCache.has( incomingBlocks ) ) {\n\t\tserializableBlocksCache.set(\n\t\t\tincomingBlocks,\n\t\t\tmakeBlocksSerializable( incomingBlocks )\n\t\t);\n\t}\n\tconst allBlocks = serializableBlocksCache.get( incomingBlocks ) ?? [];\n\n\t// Ensure we skip blocks that we don't want to sync at the moment\n\tconst blocksToSync = allBlocks.filter( ( block ) =>\n\t\tshouldBlockBeSynced( block )\n\t);\n\n\t// This is a rudimentary diff implementation similar to the y-prosemirror diffing\n\t// approach.\n\t// A better implementation would also diff the textual content and represent it\n\t// using a Y.Text type.\n\t// However, at this time it makes more sense to keep this algorithm generic to\n\t// support all kinds of block types.\n\t// Ideally, we ensure that block data structure have a consistent data format.\n\t// E.g.:\n\t// - textual content (using rich-text formatting?) may always be stored under `block.text`\n\t// - local information that shouldn't be shared (e.g. clientId or isDragging) is stored under `block.private`\n\t//\n\t// @credit Kevin Jahns (dmonad)\n\t// @link https://github.com/WordPress/gutenberg/pull/68483\n\tconst numOfCommonEntries = Math.min(\n\t\tblocksToSync.length ?? 0,\n\t\tyblocks.length\n\t);\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// skip equal blocks from left\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareBlocksEqual( blocksToSync[ left ], yblocks.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// skip equal blocks from right\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareBlocksEqual(\n\t\t\tblocksToSync[ blocksToSync.length - right - 1 ],\n\t\t\tyblocks.get( yblocks.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tblocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - blocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst block = blocksToSync[ left ];\n\t\tconst yblock = yblocks.get( left );\n\t\tObject.entries( block ).forEach( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\tconst currentAttributes = yblock.get( key );\n\n\t\t\t\t\t// If attributes are not set on the yblock, use the new values.\n\t\t\t\t\tif ( ! currentAttributes ) {\n\t\t\t\t\t\tyblock.set(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tObject.entries( value ).forEach(\n\t\t\t\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\tcurrentAttributes?.get( attributeName ),\n\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst currentAttribute =\n\t\t\t\t\t\t\t\tcurrentAttributes.get( attributeName );\n\t\t\t\t\t\t\tconst isRichText = isRichTextAttribute(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tisRichText &&\n\t\t\t\t\t\t\t\t'string' === typeof attributeValue &&\n\t\t\t\t\t\t\t\tcurrentAttributes.has( attributeName ) &&\n\t\t\t\t\t\t\t\tcurrentAttribute instanceof Y.Text\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// Rich text values are stored as persistent Y.Text instances.\n\t\t\t\t\t\t\t\t// Update the value with a delta in place.\n\t\t\t\t\t\t\t\tmergeRichTextUpdate(\n\t\t\t\t\t\t\t\t\tcurrentAttribute,\n\t\t\t\t\t\t\t\t\tattributeValue,\n\t\t\t\t\t\t\t\t\tcursorPosition\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentAttributes.set(\n\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\tcurrentAttributes.forEach(\n\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\tif ( ! value.hasOwnProperty( attrName ) ) {\n\t\t\t\t\t\t\t\tcurrentAttributes.delete( attrName );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\tlet yInnerBlocks = yblock.get( key );\n\n\t\t\t\t\tif ( ! ( yInnerBlocks instanceof Y.Array ) ) {\n\t\t\t\t\t\tyInnerBlocks = new Y.Array< YBlock >();\n\t\t\t\t\t\tyblock.set( key, yInnerBlocks );\n\t\t\t\t\t}\n\n\t\t\t\t\tmergeCrdtBlocks(\n\t\t\t\t\t\tyInnerBlocks,\n\t\t\t\t\t\tvalue ?? [],\n\t\t\t\t\t\tcursorPosition\n\t\t\t\t\t);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tif ( ! fastDeepEqual( block[ key ], yblock.get( key ) ) ) {\n\t\t\t\t\t\tyblock.set( key, value );\n\t\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tyblock.forEach( ( _v, k ) => {\n\t\t\tif ( ! block.hasOwnProperty( k ) ) {\n\t\t\t\tyblock.delete( k );\n\t\t\t}\n\t\t} );\n\t}\n\n\t// deletes\n\tyblocks.delete( left, numOfDeletionsNeeded );\n\n\t// inserts\n\tfor ( let i = 0; i < numOfInsertionsNeeded; i++, left++ ) {\n\t\tconst newBlock = [ createNewYBlock( blocksToSync[ left ] ) ];\n\n\t\tyblocks.insert( left, newBlock );\n\t}\n\n\t// remove duplicate clientids\n\tconst knownClientIds = new Set< string >();\n\tfor ( let j = 0; j < yblocks.length; j++ ) {\n\t\tconst yblock: YBlock = yblocks.get( j );\n\n\t\tlet clientId = yblock.get( 'clientId' );\n\n\t\tif ( ! clientId ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tif ( knownClientIds.has( clientId ) ) {\n\t\t\tclientId = uuidv4();\n\t\t\tyblock.set( 'clientId', clientId );\n\t\t}\n\t\tknownClientIds.add( clientId );\n\t}\n}\n\n/**\n * Determine if a block should be synced.\n *\n * Ex: A gallery block should not be synced until the images have been\n * uploaded to WordPress, and their url is available. Before that,\n * it's not possible to access the blobs on a client as those are\n * local.\n *\n * @param block The block to check.\n * @return True if the block should be synced, false otherwise.\n */\nfunction shouldBlockBeSynced( block: Block ): boolean {\n\t// Verify that the gallery block is ready to be synced.\n\t// This means that, all images have had their blobs converted to full URLs.\n\t// Checking for only the blobs ensures that blocks that have just been inserted work as well.\n\tif ( 'core/gallery' === block.name ) {\n\t\treturn ! block.innerBlocks.some(\n\t\t\t( innerBlock ) =>\n\t\t\t\tinnerBlock.attributes && innerBlock.attributes.blob\n\t\t);\n\t}\n\n\t// Allow all other blocks to be synced.\n\treturn true;\n}\n\n// Cache rich-text attributes for all block types.\nlet cachedRichTextAttributes: Map< string, Map< string, true > >;\n\n/**\n * Given a block name and attribute key, return true if the attribute is rich-text typed.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to check, e.g. 'content'.\n * @return True if the attribute is rich-text typed, false otherwise.\n */\nfunction isRichTextAttribute(\n\tblockName: string,\n\tattributeName: string\n): boolean {\n\tif ( ! cachedRichTextAttributes ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedRichTextAttributes = new Map< string, Map< string, true > >();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tconst richTextAttributeMap = new Map< string, true >();\n\n\t\t\tfor ( const [ name, definition ] of Object.entries(\n\t\t\t\tblockType.attributes ?? {}\n\t\t\t) ) {\n\t\t\t\tif ( 'rich-text' === definition.type ) {\n\t\t\t\t\trichTextAttributeMap.set( name, true );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcachedRichTextAttributes.set(\n\t\t\t\tblockType.name,\n\t\t\t\trichTextAttributeMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\tcachedRichTextAttributes.get( blockName )?.has( attributeName ) ?? false\n\t);\n}\n\nlet localDoc: Y.Doc;\n\n/**\n * Given a Y.Text object and an updated string value, diff the new value and\n * apply the delta to the Y.Text.\n *\n * @param blockYText The Y.Text to update.\n * @param updatedValue The updated value.\n * @param cursorPosition The position of the cursor after the change occurs.\n */\nfunction mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\tcursorPosition: number | null\n): void {\n\t// Gutenberg does not use Yjs shared types natively, so we can only subscribe\n\t// to changes from store and apply them to Yjs types that we create and\n\t// manage. Crucially, for rich-text attributes, we do not receive granular\n\t// string updates; we get the new full string value on each change, even when\n\t// only a single character changed.\n\t//\n\t// The code below allows us to compute a delta between the current and new\n\t// value, then apply it to the Y.Text.\n\n\tif ( ! localDoc ) {\n\t\t// Y.Text must be attached to a Y.Doc to be able to do operations on it.\n\t\t// Create a temporary Y.Text attached to a local Y.Doc for delta computation.\n\t\tlocalDoc = new Y.Doc();\n\t}\n\n\tconst localYText = localDoc.getText( 'temporary-text' );\n\tlocalYText.delete( 0, localYText.length );\n\tlocalYText.insert( 0, updatedValue );\n\n\tconst currentValueAsDelta = new Delta( blockYText.toDelta() );\n\tconst updatedValueAsDelta = new Delta( localYText.toDelta() );\n\tconst deltaDiff = currentValueAsDelta.diffWithCursor(\n\t\tupdatedValueAsDelta,\n\t\tcursorPosition\n\t);\n\n\tblockYText.applyDelta( deltaDiff.ops );\n}\n"],
5
+ "mappings": ";AAGA,SAAS,MAAM,cAAc;AAC7B,OAAO,mBAAmB;AAM1B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,GAAG,aAAa;AAKzB,SAAS,kBAAkD;AAuC3D,IAAM,0BAA0B,oBAAI,QAA4B;AAEhE,SAAS,gCACR,YACkB;AAClB,QAAM,gBAAgB,EAAE,GAAG,WAAW;AACtC,aAAY,CAAE,KAAK,KAAM,KAAK,OAAO,QAAS,UAAW,GAAI;AAC5D,QAAK,iBAAiB,cAAe;AACpC,oBAAe,GAAI,IAAI,MAAM,QAAQ;AAAA,IACtC;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,uBAAwB,QAA2B;AAC3D,SAAO,OAAO,IAAK,CAAE,UAAkB;AACtC,UAAM,EAAE,MAAM,aAAa,YAAY,GAAG,KAAK,IAAI;AACnD,WAAO,KAAK;AACZ,WAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA,YAAY,gCAAiC,UAAW;AAAA,MACxD,aAAa,uBAAwB,W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eAAY,aAAa,cAAc,GAAmB;AACzD,YAAM,uBAAuB,oBAAI,IAAoB;AAErD,iBAAY,CAAE,MAAM,UAAW,KAAK,OAAO;AAAA,QAC1C,UAAU,cAAc,CAAC;AAAA,MAC1B,GAAI;AACH,YAAK,gBAAgB,WAAW,MAAO;AACtC,+BAAqB,IAAK,MAAM,IAAK;AAAA,QACtC;AAAA,MACD;AAEA,+BAAyB;AAAA,QACxB,UAAU;AAAA,QACV;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SACC,yBAAyB,IAAK,SAAU,GAAG,IAAK,aAAc,KAAK;AAErE;AAEA,IAAI;AAUJ,SAAS,oBACR,YACA,cACA,gBACO;AAUP,MAAK,CAAE,UAAW;AAGjB,eAAW,IAAI,EAAE,IAAI;AAAA,EACtB;AAEA,QAAM,aAAa,SAAS,QAAS,gBAAiB;AACtD,aAAW,OAAQ,GAAG,WAAW,MAAO;AACxC,aAAW,OAAQ,GAAG,YAAa;AAEnC,QAAM,sBAAsB,IAAI,MAAO,WAAW,QAAQ,CAAE;AAC5D,QAAM,sBAAsB,IAAI,MAAO,WAAW,QAAQ,CAAE;AAC5D,QAAM,YAAY,oBAAoB;AAAA,IACrC;AAAA,IACA;AAAA,EACD;AAEA,aAAW,WAAY,UAAU,GAAI;AACtC;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,17 @@
1
+ // packages/core-data/src/utils/crdt-utils.ts
2
+ import { Y } from "@wordpress/sync";
3
+ function getRootMap(doc, key) {
4
+ return doc.getMap(key);
5
+ }
6
+ function createYMap(partial = {}) {
7
+ return new Y.Map(Object.entries(partial));
8
+ }
9
+ function isYMap(value) {
10
+ return value instanceof Y.Map;
11
+ }
12
+ export {
13
+ createYMap,
14
+ getRootMap,
15
+ isYMap
16
+ };
17
+ //# sourceMappingURL=crdt-utils.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/crdt-utils.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Y } from '@wordpress/sync';\n\n/**\n * A YMapRecord represents the shape of the data stored in a Y.Map.\n */\nexport type YMapRecord = Record< string, unknown >;\n\n/**\n * A wrapper around Y.Map to provide type safety. The generic type accepted by\n * Y.Map represents the union of possible values of the map, which are varied in\n * many cases. This type is accurate, but its non-specificity requires aggressive\n * type narrowing or type casting / destruction with `as`.\n *\n * This type provides type enhancements so that the correct value type can be\n * inferred based on the provided key. It is just a type wrap / overlay, and\n * does not change the runtime behavior of Y.Map.\n *\n * This interface cannot extend Y.Map directly due to the limitations of\n * TypeScript's structural typing. One negative consequence of this is that\n * `instanceof` checks against Y.Map continue to work at runtime but will blur\n * the type at compile time. To navigate this, use the `isYMap` function below.\n */\nexport interface YMapWrap< T extends YMapRecord > extends Y.AbstractType< T > {\n\tdelete: < K extends keyof T >( key: K ) => void;\n\tforEach: (\n\t\tcallback: (\n\t\t\tvalue: T[ keyof T ],\n\t\t\tkey: keyof T,\n\t\t\tmap: YMapWrap< T >\n\t\t) => void\n\t) => void;\n\thas: < K extends keyof T >( key: K ) => boolean;\n\tget: < K extends keyof T >( key: K ) => T[ K ] | undefined;\n\tset: < K extends keyof T >( key: K, value: T[ K ] ) => void;\n\ttoJSON: () => T;\n\t// add types for other Y.Map methods as needed\n}\n\n/**\n * Get or create a root-level Map for the given Y.Doc. Use this instead of\n * doc.getMap() for additional type safety.\n *\n * @param doc Y.Doc\n * @param key Map key\n */\nexport function getRootMap< T extends YMapRecord >(\n\tdoc: Y.Doc,\n\tkey: string\n): YMapWrap< T > {\n\treturn doc.getMap< T >( key ) as unknown as YMapWrap< T >;\n}\n\n/**\n * Create a new Y.Map (provided with YMapWrap type), optionally initialized with\n * data. Use this instead of `new Y.Map()` for additional type safety.\n *\n * @param partial Partial data to initialize the map with.\n */\nexport function createYMap< T extends YMapRecord >(\n\tpartial: Partial< T > = {}\n): YMapWrap< T > {\n\treturn new Y.Map( Object.entries( partial ) ) as unknown as YMapWrap< T >;\n}\n\n/**\n * Type guard to check if a value is a Y.Map without losing type information.\n *\n * @param value Value to check.\n */\nexport function isYMap< T extends YMapRecord >(\n\tvalue: YMapWrap< T > | undefined\n): value is YMapWrap< T > {\n\treturn value instanceof Y.Map;\n}\n"],
5
+ "mappings": ";AAGA,SAAS,SAAS;AA6CX,SAAS,WACf,KACA,KACgB;AAChB,SAAO,IAAI,OAAa,GAAI;AAC7B;AAQO,SAAS,WACf,UAAwB,CAAC,GACT;AAChB,SAAO,IAAI,EAAE,IAAK,OAAO,QAAS,OAAQ,CAAE;AAC7C;AAOO,SAAS,OACf,OACyB;AACzB,SAAO,iBAAiB,EAAE;AAC3B;",
6
+ "names": []
7
+ }
@@ -10,7 +10,11 @@ import {
10
10
  CRDT_RECORD_MAP_KEY,
11
11
  WORDPRESS_META_KEY_FOR_CRDT_DOC_PERSISTENCE
12
12
  } from "../sync.mjs";
13
- var lastSelection = null;
13
+ import {
14
+ createYMap,
15
+ getRootMap,
16
+ isYMap
17
+ } from "./crdt-utils.mjs";
14
18
  var allowedPostProperties = /* @__PURE__ */ new Set([
15
19
  "author",
16
20
  "blocks",
@@ -19,8 +23,8 @@ var allowedPostProperties = /* @__PURE__ */ new Set([
19
23
  "excerpt",
20
24
  "featured_media",
21
25
  "format",
22
- "ping_status",
23
26
  "meta",
27
+ "ping_status",
24
28
  "slug",
25
29
  "status",
26
30
  "sticky",
@@ -32,72 +36,67 @@ var disallowedPostMetaKeys = /* @__PURE__ */ new Set([
32
36
  WORDPRESS_META_KEY_FOR_CRDT_DOC_PERSISTENCE
33
37
  ]);
34
38
  function defaultApplyChangesToCRDTDoc(ydoc, changes) {
35
- const ymap = ydoc.getMap(CRDT_RECORD_MAP_KEY);
39
+ const ymap = getRootMap(ydoc, CRDT_RECORD_MAP_KEY);
36
40
  Object.entries(changes).forEach(([key, newValue]) => {
37
41
  if ("function" === typeof newValue) {
38
42
  return;
39
43
  }
40
- function setValue(updatedValue) {
41
- ymap.set(key, updatedValue);
42
- }
43
44
  switch (key) {
44
45
  // Add support for additional data types here.
45
46
  default: {
46
47
  const currentValue = ymap.get(key);
47
- mergeValue(currentValue, newValue, setValue);
48
+ updateMapValue(ymap, key, currentValue, newValue);
48
49
  }
49
50
  }
50
51
  });
51
52
  }
52
53
  function applyPostChangesToCRDTDoc(ydoc, changes, _postType) {
53
- const ymap = ydoc.getMap(CRDT_RECORD_MAP_KEY);
54
- Object.entries(changes).forEach(([key, newValue]) => {
54
+ const ymap = getRootMap(ydoc, CRDT_RECORD_MAP_KEY);
55
+ Object.keys(changes).forEach((key) => {
55
56
  if (!allowedPostProperties.has(key)) {
56
57
  return;
57
58
  }
59
+ const newValue = changes[key];
58
60
  if ("function" === typeof newValue) {
59
61
  return;
60
62
  }
61
- function setValue(updatedValue) {
62
- ymap.set(key, updatedValue);
63
- }
64
63
  switch (key) {
65
64
  case "blocks": {
66
- let currentBlocks = ymap.get("blocks");
65
+ let currentBlocks = ymap.get(key);
67
66
  if (!(currentBlocks instanceof Y.Array)) {
68
67
  currentBlocks = new Y.Array();
69
- setValue(currentBlocks);
68
+ ymap.set(key, currentBlocks);
70
69
  }
71
70
  const newBlocks = newValue ?? [];
72
- mergeCrdtBlocks(currentBlocks, newBlocks, lastSelection);
71
+ const cursorPosition = changes.selection?.selectionStart?.offset ?? null;
72
+ mergeCrdtBlocks(currentBlocks, newBlocks, cursorPosition);
73
73
  break;
74
74
  }
75
75
  case "excerpt": {
76
76
  const currentValue = ymap.get("excerpt");
77
77
  const rawNewValue = getRawValue(newValue);
78
- mergeValue(currentValue, rawNewValue, setValue);
78
+ updateMapValue(ymap, key, currentValue, rawNewValue);
79
79
  break;
80
80
  }
81
81
  // "Meta" is overloaded term; here, it refers to post meta.
82
82
  case "meta": {
83
83
  let metaMap = ymap.get("meta");
84
- if (!(metaMap instanceof Y.Map)) {
85
- metaMap = new Y.Map();
86
- setValue(metaMap);
84
+ if (!isYMap(metaMap)) {
85
+ metaMap = createYMap();
86
+ ymap.set("meta", metaMap);
87
87
  }
88
88
  Object.entries(newValue ?? {}).forEach(
89
89
  ([metaKey, metaValue]) => {
90
90
  if (disallowedPostMetaKeys.has(metaKey)) {
91
91
  return;
92
92
  }
93
- mergeValue(
93
+ updateMapValue(
94
+ metaMap,
95
+ metaKey,
94
96
  metaMap.get(metaKey),
95
97
  // current value in CRDT
96
- metaValue,
98
+ metaValue
97
99
  // new value from changes
98
- (updatedMetaValue) => {
99
- metaMap.set(metaKey, updatedMetaValue);
100
- }
101
100
  );
102
101
  }
103
102
  );
@@ -107,35 +106,32 @@ function applyPostChangesToCRDTDoc(ydoc, changes, _postType) {
107
106
  if (!newValue) {
108
107
  break;
109
108
  }
110
- const currentValue = ymap.get("slug");
111
- mergeValue(currentValue, newValue, setValue);
109
+ const currentValue = ymap.get(key);
110
+ updateMapValue(ymap, key, currentValue, newValue);
112
111
  break;
113
112
  }
114
113
  case "title": {
115
- const currentValue = ymap.get("title");
114
+ const currentValue = ymap.get(key);
116
115
  let rawNewValue = getRawValue(newValue);
117
116
  if (!currentValue && "Auto Draft" === rawNewValue) {
118
117
  rawNewValue = "";
119
118
  }
120
- mergeValue(currentValue, rawNewValue, setValue);
119
+ updateMapValue(ymap, key, currentValue, rawNewValue);
121
120
  break;
122
121
  }
123
- // Add support for additional data types here.
122
+ // Add support for additional properties here.
124
123
  default: {
125
124
  const currentValue = ymap.get(key);
126
- mergeValue(currentValue, newValue, setValue);
125
+ updateMapValue(ymap, key, currentValue, newValue);
127
126
  }
128
127
  }
129
128
  });
130
- if ("selection" in changes) {
131
- lastSelection = changes.selection?.selectionStart ?? null;
132
- }
133
129
  }
134
130
  function defaultGetChangesFromCRDTDoc(crdtDoc) {
135
- return crdtDoc.getMap(CRDT_RECORD_MAP_KEY).toJSON();
131
+ return getRootMap(crdtDoc, CRDT_RECORD_MAP_KEY).toJSON();
136
132
  }
137
133
  function getPostChangesFromCRDTDoc(ydoc, editedRecord, _postType) {
138
- const ymap = ydoc.getMap(CRDT_RECORD_MAP_KEY);
134
+ const ymap = getRootMap(ydoc, CRDT_RECORD_MAP_KEY);
139
135
  let allowedMetaChanges = {};
140
136
  const changes = Object.fromEntries(
141
137
  Object.entries(ymap.toJSON()).filter(([key, newValue]) => {
@@ -214,9 +210,13 @@ function getRawValue(value) {
214
210
  function haveValuesChanged(currentValue, newValue) {
215
211
  return !fastDeepEqual(currentValue, newValue);
216
212
  }
217
- function mergeValue(currentValue, newValue, setValue) {
213
+ function updateMapValue(map, key, currentValue, newValue) {
214
+ if (void 0 === newValue) {
215
+ map.delete(key);
216
+ return;
217
+ }
218
218
  if (haveValuesChanged(currentValue, newValue)) {
219
- setValue(newValue);
219
+ map.set(key, newValue);
220
220
  }
221
221
  }
222
222
  export {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/crdt.ts"],
4
- "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 { type CRDTDoc, type ObjectData, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tmergeCrdtBlocks,\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 { WPBlockSelection, WPSelection } from '../types';\n\nexport type PostChanges = Partial< Post > & {\n\tblocks?: Block[];\n\texcerpt?: Post[ 'excerpt' ] | string;\n\tselection?: WPSelection;\n\ttitle?: Post[ 'title' ] | string;\n};\n\n// Hold a reference to the last known selection to help compute Y.Text deltas.\nlet lastSelection: WPBlockSelection | null = null;\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'comment_status',\n\t'date',\n\t'excerpt',\n\t'featured_media',\n\t'format',\n\t'ping_status',\n\t'meta',\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 */\nexport function defaultApplyChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: ObjectData\n): void {\n\tconst ymap = ydoc.getMap( 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\t// Set the value in the root document.\n\t\tfunction setValue< T = unknown >( updatedValue: T ): void {\n\t\t\tymap.set( key, updatedValue );\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\tmergeValue( currentValue, newValue, setValue );\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 = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\treturn;\n\t\t}\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\t// Set the value in the root document.\n\t\tfunction setValue< T = unknown >( updatedValue: T ): void {\n\t\t\tymap.set( key, updatedValue );\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\tcase 'blocks': {\n\t\t\t\tlet currentBlocks = ymap.get( 'blocks' ) as YBlocks;\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\tsetValue( currentBlocks );\n\t\t\t\t}\n\n\t\t\t\t// Block[] from local changes.\n\t\t\t\tconst newBlocks = ( newValue as PostChanges[ 'blocks' ] ) ?? [];\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, newBlocks, lastSelection );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'excerpt': {\n\t\t\t\tconst currentValue = ymap.get( 'excerpt' ) as\n\t\t\t\t\t| string\n\t\t\t\t\t| undefined;\n\t\t\t\tconst rawNewValue = getRawValue( newValue );\n\n\t\t\t\tmergeValue( currentValue, rawNewValue, setValue );\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' ) as Y.Map< unknown >;\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! ( metaMap instanceof Y.Map ) ) {\n\t\t\t\t\tmetaMap = new Y.Map();\n\t\t\t\t\tsetValue( 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\tmergeValue(\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\t( updatedMetaValue: unknown ): void => {\n\t\t\t\t\t\t\t\tmetaMap.set( metaKey, updatedMetaValue );\n\t\t\t\t\t\t\t}\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( 'slug' ) as string;\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( 'title' ) as string | undefined;\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\tlet rawNewValue = getRawValue( newValue );\n\t\t\t\tif ( ! currentValue && 'Auto Draft' === rawNewValue ) {\n\t\t\t\t\trawNewValue = '';\n\t\t\t\t}\n\n\t\t\t\tmergeValue( currentValue, rawNewValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\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\tmergeValue( currentValue, newValue, setValue );\n\t\t\t}\n\t\t}\n\t} );\n\n\t// Update the lastSelection for use in computing Y.Text deltas.\n\tif ( 'selection' in changes ) {\n\t\tlastSelection = changes.selection?.selectionStart ?? null;\n\t}\n}\n\nexport function defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {\n\treturn crdtDoc.getMap( 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 = ydoc.getMap( 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 blocks = ymap.get( 'blocks' ) as YBlocks;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t__unstableSerializeAndClean(\n\t\t\t\t\t\t\t\tblocks.toJSON()\n\t\t\t\t\t\t\t).trim() !== editedRecord.content.raw.trim()\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 '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 * 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 = any >(\n\tcurrentValue: ValueType,\n\tnewValue: ValueType\n): boolean {\n\treturn ! fastDeepEqual( currentValue, newValue );\n}\n\nfunction mergeValue< ValueType = any >(\n\tcurrentValue: ValueType,\n\tnewValue: ValueType,\n\tsetValue: ( value: ValueType ) => void\n): void {\n\tif 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cAChC,CAAE,CAAE,OAAQ,MACX,CAAE,uBAAuB,IAAK,OAAQ;AAAA,YACxC;AAAA,UACD;AAIA,gBAAM,cAAc;AAAA,YACnB,GAAK;AAAA,YACL,GAAG;AAAA,UACJ;AAEA,iBAAO,kBAAmB,cAAc,WAAY;AAAA,QACrD;AAAA,QAEA,KAAK,UAAU;AAEd,cAAK,iBAAiB,UAAW;AAChC,mBAAO;AAAA,UACR;AAEA,iBAAO,kBAAmB,cAAc,QAAS;AAAA,QAClD;AAAA,QAEA,KAAK;AAAA,QACL,KAAK,SAAS;AACb,iBAAO;AAAA,YACN,YAAa,YAAa;AAAA,YAC1B;AAAA,UACD;AAAA,QACD;AAAA;AAAA,QAIA,SAAS;AACR,iBAAO,kBAAmB,cAAc,QAAS;AAAA,QAClD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH;AAIA,MAAK,aAAa,OAAO,QAAQ,MAAO;AACvC,YAAQ,OAAO;AAAA,MACd,GAAG,aAAa;AAAA,MAChB,GAAG;AAAA,IACJ;AAAA,EACD;AAEA,SAAO;AACR;AASA,SAAS,YAAa,OAAsC;AAE3D,MAAK,aAAa,OAAO,OAAQ;AAChC,WAAO;AAAA,EACR;AAEA,MACC,SACA,aAAa,OAAO,SACpB,SAAS,SACT,aAAa,OAAO,MAAM,KACzB;AACD,WAAO,MAAM;AAAA,EACd;AAEA,SAAO;AACR;AAEA,SAAS,kBACR,cACA,UACU;AACV,SAAO,CAAE,cAAe,cAAc,QAAS;AAChD;AAEA,SAAS,WACR,cACA,UACA,UACO;AACP,MAAK,kBAAgC,cAAc,QAAS,GAAI;AAC/D,aAAU,QAAS;AAAA,EACpB;AACD;",
4
+ "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 { type CRDTDoc, type ObjectData, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tmergeCrdtBlocks,\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 {\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\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\tblocks: YBlocks;\n\tcomment_status: string;\n\tdate: string | null;\n\texcerpt: string;\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: string;\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'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 */\nexport function 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\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[] from local changes.\n\t\t\t\tconst newBlocks = ( newValue as PostChanges[ 'blocks' ] ) ?? [];\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, newBlocks, cursorPosition );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'excerpt': {\n\t\t\t\tconst currentValue = ymap.get( 'excerpt' );\n\t\t\t\tconst rawNewValue = getRawValue( newValue );\n\n\t\t\t\tupdateMapValue( ymap, key, currentValue, rawNewValue );\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\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( key );\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\tlet rawNewValue = getRawValue( newValue );\n\t\t\t\tif ( ! currentValue && 'Auto Draft' === rawNewValue ) {\n\t\t\t\t\trawNewValue = '';\n\t\t\t\t}\n\n\t\t\t\tupdateMapValue( ymap, key, currentValue, rawNewValue );\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\nexport function 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 blocks = ymap.get( 'blocks' ) as YBlocks;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t__unstableSerializeAndClean(\n\t\t\t\t\t\t\t\tblocks.toJSON()\n\t\t\t\t\t\t\t).trim() !== editedRecord.content.raw.trim()\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 '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 * 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"],
5
+ "mappings": ";AAGA,OAAO,mBAAmB;AAM1B,SAAS,mCAAmC;AAC5C,SAAwC,SAAS;AAKjD;AAAA,EACC;AAAA,OAIM;AAGP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AA8BP,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;AAAA,EACA;AAAA,EACA;AACD,CAAE;AAGF,IAAM,yBAAyB,oBAA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AAA,EACD;AAEA,SAAO;AACR;AASA,SAAS,YAAa,OAAsC;AAE3D,MAAK,aAAa,OAAO,OAAQ;AAChC,WAAO;AAAA,EACR;AAEA,MACC,SACA,aAAa,OAAO,SACpB,SAAS,SACT,aAAa,OAAO,MAAM,KACzB;AACD,WAAO,MAAM;AAAA,EACd;AAEA,SAAO;AACR;AAEA,SAAS,kBACR,cACA,UACU;AACV,SAAO,CAAE,cAAe,cAAc,QAAS;AAChD;AAEA,SAAS,eACR,KACA,KACA,cACA,UACO;AACP,MAAK,WAAc,UAAW;AAC7B,QAAI,OAAQ,GAAI;AAChB;AAAA,EACD;AAEA,MAAK,kBAA6B,cAAc,QAAS,GAAI;AAC5D,QAAI,IAAK,KAAK,QAAS;AAAA,EACxB;AACD;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;GAUG;AACH,0CALW,MAAM,SACN,WAAY,OAUtB;AAED;;;;;;;;;GASG;AACH,0DAKC;AAED;;;;;;GAMG;AACH,kDAKC;AAED;;;;;;;;;;;GAWG;AACH,2CATW,MAAM,QACN,MAAM,WACN,WAAY,UACZ,UAAO,oBACN,OAAO,OAAA,UACR,UAAO,SACP,UAAO,OAmCjB;AAED;;;;;;;;;GASG;AACH,4DAKC;AAED;;;;;;;;;GASG;AACH,kFAJW,MAAM,OAWhB;AAED;;;;;;;;;;GAUG;AACH,uEALW,MAAM,0BAchB;AAED;;;;;;;;;;GAUG;AACH,4EALW,MAAM,0BAchB;AAED;;;;;;GAMG;AACH,4CAQC;AAED;;;;;;;;;;;;GAYG;AACH,4DALW,MAAM,yBAkBhB;AAED;;;;;;;;;;;GAWG;AACH,yCALW,MAAM,WACN,GAAC,OAUX;AA+mBD;;;;;;;;GAQG;AACH,+DAJW,OAAO,OAWjB;AAED;;;;;;;;;;;GAWG;AACH,2CALW,MAAM,aACN,OAAO,OAUjB;AAED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AY,SACZ,UAAO,oBACN,OAAO,OAAA,qBACR,UAAO,IAIT;;;CAA2B,mBAsBlC"}
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAuBA,iCAAkC,IAAI,CAAC;AAYvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2LE;;;;;;;;;;;;AAcF;;;;;;;;;;KASE;AAWK,2EAJI,MAAM,cACN,OAAO,OA0CjB;AAyLM,oCANI,MAAM,QACN,MAAM,WACN,MAAM,GAEL,MAAM,CAMjB;AA3LD;;;;GAIG;AACH,sDA0FC;AAyBD;;;;GAIG;AACH,gDAsCC"}
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAqBA,iCAAkC,IAAI,CAAC;AAYvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2LE;;;;;;;;;;;;AAcF;;;;;;;;;;KASE;AAWK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3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAMhF,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,6FAO3C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,eAAO,MAAM,2BAA2B;;;;CAcvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;;CAwBvC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM;;;EAIV;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAEpE;AAqBD,eAAO,MAAM,WAAW;;;;;;;CAuCvB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;CAQxB,CAAC;AAEJ,eAAO,MAAM,aAAa;;;;CAmFzB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,KAAK,GACV,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,GAAG,IAAI,CAE9B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAE,KAAK,EAAE,KAAK,GAAI,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,GAAG,IAAI,CAE5E"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../src/resolvers.js"],"names":[],"mappings":"AAmCO,kCAHI,MAAO,SAAS,IAKlB;;CAAY,mBAOnB;AAKK,mCAEE;;C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