@wordpress/core-data 7.37.1-next.v.0 → 7.38.1-next.v.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 (92) 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/awareness/config.cjs +34 -0
  5. package/build/awareness/config.cjs.map +7 -0
  6. package/build/awareness/post-editor-awareness.cjs +144 -0
  7. package/build/awareness/post-editor-awareness.cjs.map +7 -0
  8. package/build/awareness/types.cjs +19 -0
  9. package/build/awareness/types.cjs.map +7 -0
  10. package/build/awareness/utils.cjs +116 -0
  11. package/build/awareness/utils.cjs.map +7 -0
  12. package/build/entities.cjs +48 -45
  13. package/build/entities.cjs.map +2 -2
  14. package/build/private-selectors.cjs +2 -4
  15. package/build/private-selectors.cjs.map +2 -2
  16. package/build/resolvers.cjs +14 -4
  17. package/build/resolvers.cjs.map +2 -2
  18. package/build/types.cjs.map +1 -1
  19. package/build/utils/crdt-blocks.cjs +63 -41
  20. package/build/utils/crdt-blocks.cjs.map +2 -2
  21. package/build/utils/crdt-user-selections.cjs +171 -0
  22. package/build/utils/crdt-user-selections.cjs.map +7 -0
  23. package/build/utils/crdt-utils.cjs +44 -0
  24. package/build/utils/crdt-utils.cjs.map +7 -0
  25. package/build/utils/crdt.cjs +33 -37
  26. package/build/utils/crdt.cjs.map +2 -2
  27. package/build-module/actions.mjs +14 -2
  28. package/build-module/actions.mjs.map +2 -2
  29. package/build-module/awareness/config.mjs +8 -0
  30. package/build-module/awareness/config.mjs.map +7 -0
  31. package/build-module/awareness/post-editor-awareness.mjs +125 -0
  32. package/build-module/awareness/post-editor-awareness.mjs.map +7 -0
  33. package/build-module/awareness/types.mjs +1 -0
  34. package/build-module/awareness/types.mjs.map +7 -0
  35. package/build-module/awareness/utils.mjs +90 -0
  36. package/build-module/awareness/utils.mjs.map +7 -0
  37. package/build-module/entities.mjs +48 -47
  38. package/build-module/entities.mjs.map +2 -2
  39. package/build-module/private-selectors.mjs +2 -4
  40. package/build-module/private-selectors.mjs.map +2 -2
  41. package/build-module/resolvers.mjs +14 -4
  42. package/build-module/resolvers.mjs.map +2 -2
  43. package/build-module/utils/crdt-blocks.mjs +64 -42
  44. package/build-module/utils/crdt-blocks.mjs.map +2 -2
  45. package/build-module/utils/crdt-user-selections.mjs +144 -0
  46. package/build-module/utils/crdt-user-selections.mjs.map +7 -0
  47. package/build-module/utils/crdt-utils.mjs +17 -0
  48. package/build-module/utils/crdt-utils.mjs.map +7 -0
  49. package/build-module/utils/crdt.mjs +37 -37
  50. package/build-module/utils/crdt.mjs.map +2 -2
  51. package/build-types/actions.d.ts.map +1 -1
  52. package/build-types/awareness/config.d.ts +9 -0
  53. package/build-types/awareness/config.d.ts.map +1 -0
  54. package/build-types/awareness/post-editor-awareness.d.ts +39 -0
  55. package/build-types/awareness/post-editor-awareness.d.ts.map +1 -0
  56. package/build-types/awareness/types.d.ts +32 -0
  57. package/build-types/awareness/types.d.ts.map +1 -0
  58. package/build-types/awareness/utils.d.ts +22 -0
  59. package/build-types/awareness/utils.d.ts.map +1 -0
  60. package/build-types/entities.d.ts.map +1 -1
  61. package/build-types/index.d.ts.map +1 -1
  62. package/build-types/private-selectors.d.ts.map +1 -1
  63. package/build-types/resolvers.d.ts.map +1 -1
  64. package/build-types/types.d.ts +0 -5
  65. package/build-types/types.d.ts.map +1 -1
  66. package/build-types/utils/crdt-blocks.d.ts +14 -5
  67. package/build-types/utils/crdt-blocks.d.ts.map +1 -1
  68. package/build-types/utils/crdt-user-selections.d.ts +66 -0
  69. package/build-types/utils/crdt-user-selections.d.ts.map +1 -0
  70. package/build-types/utils/crdt-utils.d.ts +53 -0
  71. package/build-types/utils/crdt-utils.d.ts.map +1 -0
  72. package/build-types/utils/crdt.d.ts +19 -1
  73. package/build-types/utils/crdt.d.ts.map +1 -1
  74. package/package.json +19 -18
  75. package/src/actions.js +13 -2
  76. package/src/awareness/config.ts +9 -0
  77. package/src/awareness/post-editor-awareness.ts +187 -0
  78. package/src/awareness/types.ts +38 -0
  79. package/src/awareness/utils.ts +159 -0
  80. package/src/entities.js +52 -54
  81. package/src/private-selectors.ts +3 -4
  82. package/src/resolvers.js +17 -8
  83. package/src/test/entities.js +11 -9
  84. package/src/test/entity-provider.js +2 -0
  85. package/src/test/resolvers.js +3 -45
  86. package/src/types.ts +0 -6
  87. package/src/utils/crdt-blocks.ts +101 -99
  88. package/src/utils/crdt-user-selections.ts +332 -0
  89. package/src/utils/crdt-utils.ts +77 -0
  90. package/src/utils/crdt.ts +76 -57
  91. package/src/utils/test/crdt-blocks.ts +11 -4
  92. package/src/utils/test/crdt.ts +28 -16
@@ -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 ( haveValuesChanged< ValueType >( currentValue, newValue ) ) {\n\t\tsetValue( 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;AAWP,IAAI,gBAAyC;AAG7C,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,oBAAI,IAAe;AAAA,EACjD;AACD,CAAE;AAUK,SAAS,6BACf,MACA,SACO;AACP,QAAM,OAAO,KAAK,OAAQ,mBAAoB;AAE9C,SAAO,QAAS,OAAQ,EAAE,QAAS,CAAE,CAAE,KAAK,QAAS,MAAO;AAE3D,QAAK,eAAe,OAAO,UAAW;AACrC;AAAA,IACD;AAGA,aAAS,SAAyB,cAAwB;AACzD,WAAK,IAAK,KAAK,YAAa;AAAA,IAC7B;AAEA,YAAS,KAAM;AAAA;AAAA,MAGd,SAAS;AACR,cAAM,eAAe,KAAK,IAAK,GAAI;AACnC,mBAAY,cAAc,UAAU,QAAS;AAAA,MAC9C;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAWO,SAAS,0BACf,MACA,SACA,WACO;AACP,QAAM,OAAO,KAAK,OAAQ,mBAAoB;AAE9C,SAAO,QAAS,OAAQ,EAAE,QAAS,CAAE,CAAE,KAAK,QAAS,MAAO;AAC3D,QAAK,CAAE,sBAAsB,IAAK,GAAI,GAAI;AACzC;AAAA,IACD;AAGA,QAAK,eAAe,OAAO,UAAW;AACrC;AAAA,IACD;AAGA,aAAS,SAAyB,cAAwB;AACzD,WAAK,IAAK,KA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C,CAAE,EAAE;AAAA,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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,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,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,a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,GAAC,MAAM,WACb,WAAY,SACZ,UAAO,oBACN,OAAO,OAAA,qBACR,UAAO,IAIT;;;CAA2B,mBAsBlC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Delay in milliseconds before throttling the cursor position updates.
3
+ */
4
+ export declare const AWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS = 100;
5
+ /**
6
+ * Delay in milliseconds before updating the cursor position.
7
+ */
8
+ export declare const LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS = 5;
9
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/awareness/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,kCAAkC,IAAI,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { AwarenessState, type Y } from '@wordpress/sync';
2
+ import { areUserInfosEqual } from './utils';
3
+ import type { EditorState, PostEditorState } from './types';
4
+ export declare class PostEditorAwareness extends AwarenessState<PostEditorState> {
5
+ private kind;
6
+ private name;
7
+ private postId;
8
+ protected equalityFieldChecks: {
9
+ editorState: (state1?: EditorState, state2?: EditorState) => boolean;
10
+ userInfo: typeof areUserInfosEqual;
11
+ };
12
+ constructor(doc: Y.Doc, kind: string, name: string, postId: number);
13
+ setUp(): void;
14
+ /**
15
+ * Set the current user info in the local state.
16
+ */
17
+ private setCurrentUserInfo;
18
+ /**
19
+ * Subscribe to user selection changes and update the selection state.
20
+ */
21
+ private subscribeToUserSelectionChanges;
22
+ /**
23
+ * Update the entity record with the current user's selection.
24
+ *
25
+ * @param selectionStart - The start position of the selection.
26
+ * @param selectionEnd - The end position of the selection.
27
+ * @param initialPosition - The initial position of the selection.
28
+ */
29
+ private updateSelectionInEntityRecord;
30
+ /**
31
+ * Check if two editor states are equal.
32
+ *
33
+ * @param state1 - The first editor state.
34
+ * @param state2 - The second editor state.
35
+ * @return True if the editor states are equal, false otherwise.
36
+ */
37
+ private areEditorStatesEqual;
38
+ }
39
+ //# sourceMappingURL=post-editor-awareness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-editor-awareness.d.ts","sourceRoot":"","sources":["../../src/awareness/post-editor-awareness.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAYzD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAO9D,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE5D,qBAAa,mBAAoB,SAAQ,cAAc,CAAE,eAAe,CAAE;IAQxE,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM;IATf,SAAS,CAAC,mBAAmB;+BAuJnB,WAAW,WACX,WAAW,KAClB,OAAO;;MAtJR;gBAGD,GAAG,EAAE,CAAC,CAAC,GAAG,EACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM;IAKhB,KAAK,IAAI,IAAI;IAOpB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;OAEG;IACH,OAAO,CAAC,+BAA+B;IA8DvC;;;;;;OAMG;YACW,6BAA6B;IA+B3C;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;CAU5B"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { SelectionState } from '../utils/crdt-user-selections';
5
+ import type { User } from '../entity-types';
6
+ export type UserInfo = Pick<User<'view'>, 'id' | 'name' | 'slug' | 'avatar_urls'> & {
7
+ browserType: string;
8
+ color: string;
9
+ enteredAt: number;
10
+ };
11
+ /**
12
+ * This base state represents the presence of the user. We expect it to be
13
+ * extended to include additional state describing the user's current activity.
14
+ * This state must be serializable and compact.
15
+ */
16
+ export interface BaseState {
17
+ userInfo: UserInfo;
18
+ }
19
+ /**
20
+ * The editor state includes information about the user's current selection.
21
+ */
22
+ export interface EditorState {
23
+ selection: SelectionState;
24
+ }
25
+ /**
26
+ * The post editor state extends the base state with information used to render
27
+ * presence indicators in the post editor.
28
+ */
29
+ export interface PostEditorState extends BaseState {
30
+ editorState?: EditorState;
31
+ }
32
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/awareness/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,MAAM,QAAQ,GAAG,IAAI,CAC1B,IAAI,CAAE,MAAM,CAAE,EACd,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,aAAa,CACtC,GAAG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,QAAQ,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,SAAS,EAAE,cAAc,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,SAAS;IACjD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC1B"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { User } from '../entity-types';
5
+ import type { UserInfo } from './types';
6
+ /**
7
+ * Check if two user infos are equal.
8
+ *
9
+ * @param userInfo1 - The first user info.
10
+ * @param userInfo2 - The second user info.
11
+ * @return True if the user infos are equal, false otherwise.
12
+ */
13
+ export declare function areUserInfosEqual(userInfo1?: UserInfo, userInfo2?: UserInfo): boolean;
14
+ /**
15
+ * Generate a user info object from a current user and a list of existing colors.
16
+ *
17
+ * @param currentUser - The current user.
18
+ * @param existingColors - The existing colors.
19
+ * @return The user info object.
20
+ */
21
+ export declare function generateUserInfo(currentUser: User<'view'>, existingColors: string[]): UserInfo;
22
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/awareness/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAgHxC;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,CAAC,EAAE,QAAQ,EACpB,SAAS,CAAC,EAAE,QAAQ,GAClB,OAAO,CAaT;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,WAAW,EAAE,IAAI,CAAE,MAAM,CAAE,EAC3B,cAAc,EAAE,MAAM,EAAE,GACtB,QAAQ,CAOV"}
@@ -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":"AAsBA,iCAAkC,IAAI,CAAC;AAYvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA2LE;;;;;;;;;;;;AAcF;;;;;;;;;;KASE;AAWK,2EAJI,MAAM,cACN,OAAO,OA0CjB;AAwLM,oCANI,MAAM,QACN,MAAM,WACN,MAAM,GAEL,MAAM,CAMjB;AA1LD;;;;GAIG;AACH,sDAqGC;AAyBD;;;;GAIG;AACH,gDA0BC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA6HA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;4CAWyvqB,OAAO;;yBAArklB,YAAO,EAAC,YAAO,EAAC,yBAAW,EAAC,iBAAQ,EAAC;;;KAA4D,MAAe;;;KAA4B;uBAA8oE,YAAK,EAAC,YAAK,EAAC,yBAAS,EAAC,UAAM,EAAC;;KAAa;iBAA41D;;;KAAqB;iBAA4R;;;KAAqB;;uBAAutC,YAAO,EAAC,YAAO,EAAC,WAAS,EAAC;;;;KAA4F,MAAe;;;;KAAoC;0BAAmqN,eAAS;6BAAgtC,YAAK,EAAC,YAAK,EAAC,aAAS,EAAC,yBAAQ,MAAc;;;;KAAoC;6CAAslC,YAAK,EAAC,YAAK,EAA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,IAIR;;CAAY,mBAUnB;AAYK,yCANI,MAAM,YAEN,MAAM,MAAO,MAEZ,MAAM,OAAA,IAIT;;;;CAAqC,mBAiF5C;AAUK,8CAJI,MAAM,QACN,MAAM,YACN,MAAM,GAAC,MAAM,IAIf;;CAAY,mBAEnB;AAQK,uCAHI,MAAM,UACN,MAAM,IAIR;;;CAA2B,mBAiBlC;AAWK,sCAHI,MAAM,UACN,MAAM,IAIR;;CAAiB,mBAExB;AAEK,2DAEE;;;CAA2B,mBAqBlC;AAEK,kEAEE;;;CAA2B,mBAUlC;AAEK,wEAEE;;;CAA2B,mBAUlC;AAKK,yDAEE;;;CAA2B,mBA6BlC;;IAEF,gDAOC;;AAEM,qCAEE;;CAAY,mBAGnB;AAEK,8CAEE;;CAAY,mBAKnB;AAEK,6CAEE;;;CAA2B,mBAsBlC;AAEK,4CAEE;;;;CAA8B,mBAwCrC;AAEK,mDAEE;;;;CAAqC,mBA6B5C;;IAEF,gDAMC;;AAYM,mCAPI,MAAM,QACN,MAAM,aACN,MAAM,GAAC,MAAM,UACb,MAAO,SAAS,IAMlB;;;;CAAqC,mBAkG5C;;IAGF,sFAK8B;;AAavB,kCARI,MAAM,QACN,MAAM,aACN,MAAM,GAAC,MAAM,eACb,MAAM,GAAC,MAAM,SACb,MAAO,SAAS,IAMlB;;;CAA2B,mBAyClC;AAOK,gDAFI,MAAM,IAIR;;;CAA2B,mBAsBlC;AAOK,wCAFI,MAAM,IAIR;;CAAY,mBAmBnB;AAKK,sCAEE;;CAAY,mBAKnB;AAKK,oCAEE;;CAAY,mBAKnB"}
@@ -1,8 +1,3 @@
1
- declare global {
2
- interface Window {
3
- __experimentalEnableSync?: boolean;
4
- }
5
- }
6
1
  export interface AnyFunction {
7
2
  (...args: any[]): any;
8
3
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,MAAM;QACf,wBAAwB,CAAC,EAAE,OAAO,CAAC;KACnC;CACD;AAED,MAAM,WAAW,WAAW;IAC3B,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAI,GAAG,CAAC;CACxB;AAGD,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC3B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,cAAc,EAAE,gBAAgB,CAAC;CACjC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC3B,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAI,GAAG,CAAC;CACxB;AAGD,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC3B,YAAY,EAAE,gBAAgB,CAAC;IAC/B,cAAc,EAAE,gBAAgB,CAAC;CACjC"}
@@ -2,7 +2,7 @@ import { Y } from '@wordpress/sync';
2
2
  /**
3
3
  * Internal dependencies
4
4
  */
5
- import type { WPBlockSelection } from '../types';
5
+ import { type YMapRecord, type YMapWrap } from './crdt-utils';
6
6
  interface BlockAttributes {
7
7
  [key: string]: unknown;
8
8
  }
@@ -10,11 +10,20 @@ export interface Block {
10
10
  attributes: BlockAttributes;
11
11
  clientId?: string;
12
12
  innerBlocks: Block[];
13
+ isValid?: boolean;
14
+ name: string;
13
15
  originalContent?: string;
14
16
  validationIssues?: string[];
17
+ }
18
+ interface YBlockRecord extends YMapRecord {
19
+ attributes: YBlockAttributes;
20
+ clientId: string;
21
+ innerBlocks: YBlocks;
22
+ isValid?: boolean;
23
+ originalContent?: string;
15
24
  name: string;
16
25
  }
17
- export type YBlock = Y.Map<string | string[] | YBlockAttributes | YBlocks>;
26
+ export type YBlock = YMapWrap<YBlockRecord>;
18
27
  export type YBlocks = Y.Array<YBlock>;
19
28
  export type YBlockAttributes = Y.Map<Y.Text | unknown>;
20
29
  /**
@@ -22,9 +31,9 @@ export type YBlockAttributes = Y.Map<Y.Text | unknown>;
22
31
  * This function is called to sync local block changes to a shared Y.Doc.
23
32
  *
24
33
  * @param yblocks The blocks in the local Y.Doc.
25
- * @param incomingBlocks Gutenberg blocks being synced, either from a peer or from the local editor.
26
- * @param lastSelection The last cursor position, used for hinting the diff algorithm.
34
+ * @param incomingBlocks Gutenberg blocks being synced.
35
+ * @param cursorPosition The position of the cursor after the change occurs.
27
36
  */
28
- export declare function mergeCrdtBlocks(yblocks: YBlocks, incomingBlocks: Block[], lastSelection: WPBlockSelection | null): void;
37
+ export declare function mergeCrdtBlocks(yblocks: YBlocks, incomingBlocks: Block[], cursorPosition: number | null): void;
29
38
  export {};
30
39
  //# sourceMappingURL=crdt-blocks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crdt-blocks.d.ts","sourceRoot":"","sources":["../../src/utils/crdt-blocks.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAKpC;;GAEG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,UAAU,eAAe;IACxB,CAAE,GAAG,EAAE,MAAM,GAAI,OAAO,CAAC;CACzB;AAOD,MAAM,WAAW,KAAK;IACrB,UAAU,EAAE,eAAe,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,KAAK,EAAE,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,GAAG,CAEvB,MAAM,GAEN,MAA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AAE,CAAC;AAC9C,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAE,MAAM,CAAE,CAAC;AAIxC,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,GAAG,CAAE,CAAC,CAAC,IAAI,GAAG,OAAO,CAAE,CAAC;AAiIzD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC9B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,KAAK,EAAE,EACvB,cAAc,EAAE,MAAM,GAAG,IAAI,GAC3B,IAAI,CAwMN"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { Y } from '@wordpress/sync';
5
+ import type { WPBlockSelection } from '../types';
6
+ /**
7
+ * The type of selection.
8
+ */
9
+ export declare enum SelectionType {
10
+ None = "none",
11
+ Cursor = "cursor",
12
+ SelectionInOneBlock = "selection-in-one-block",
13
+ SelectionInMultipleBlocks = "selection-in-multiple-blocks",
14
+ WholeBlock = "whole-block"
15
+ }
16
+ /**
17
+ * The position of the cursor.
18
+ */
19
+ export type CursorPosition = {
20
+ relativePosition: Y.RelativePosition;
21
+ absoluteOffset: number;
22
+ };
23
+ export type SelectionNone = {
24
+ type: SelectionType.None;
25
+ };
26
+ export type SelectionCursor = {
27
+ type: SelectionType.Cursor;
28
+ blockId: string;
29
+ cursorPosition: CursorPosition;
30
+ };
31
+ export type SelectionInOneBlock = {
32
+ type: SelectionType.SelectionInOneBlock;
33
+ blockId: string;
34
+ cursorStartPosition: CursorPosition;
35
+ cursorEndPosition: CursorPosition;
36
+ };
37
+ export type SelectionInMultipleBlocks = {
38
+ type: SelectionType.SelectionInMultipleBlocks;
39
+ blockStartId: string;
40
+ blockEndId: string;
41
+ cursorStartPosition: CursorPosition;
42
+ cursorEndPosition: CursorPosition;
43
+ };
44
+ export type SelectionWholeBlock = {
45
+ type: SelectionType.WholeBlock;
46
+ blockId: string;
47
+ };
48
+ export type SelectionState = SelectionNone | SelectionCursor | SelectionInOneBlock | SelectionInMultipleBlocks | SelectionWholeBlock;
49
+ /**
50
+ * Converts WordPress block editor selection to a SelectionState.
51
+ *
52
+ * @param selectionStart - The start position of the selection
53
+ * @param selectionEnd - The end position of the selection
54
+ * @param yDoc - The Yjs document
55
+ * @return The SelectionState
56
+ */
57
+ export declare function getSelectionState(selectionStart: WPBlockSelection, selectionEnd: WPBlockSelection, yDoc: Y.Doc): SelectionState;
58
+ /**
59
+ * Check if two selection states are equal.
60
+ *
61
+ * @param selection1 - The first selection state.
62
+ * @param selection2 - The second selection state.
63
+ * @return True if the selection states are equal, false otherwise.
64
+ */
65
+ export declare function areSelectionsStatesEqual(selection1: SelectionState, selection2: SelectionState): boolean;
66
+ //# sourceMappingURL=crdt-user-selections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crdt-user-selections.d.ts","sourceRoot":"","sources":["../../src/utils/crdt-user-selections.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAuB,MAAM,iBAAiB,CAAC;AAQzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD;;GAEG;AACH,oBAAY,aAAa;IACxB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,mBAAmB,2BAA2B;IAC9C,yBAAyB,iCAAiC;IAC1D,UAAU,gBAAgB;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC5B,gBAAgB,EAAE,CAAC,CAAC,gBAAgB,CAAC;IAYrC,cAAc,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAE3B,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAE7B,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAEjC,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,cAAc,CAAC;IACpC,iBAAiB,EAAE,cAAc,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IAEvC,IAAI,EAAE,aAAa,CAAC,yBAAyB,CAAC;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,cAAc,CAAC;IACpC,iBAAiB,EAAE,cAAc,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAEjC,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,cAAc,GACvB,aAAa,GACb,eAAe,GACf,mBAAmB,GACnB,yBAAyB,GACzB,mBAAmB,CAAC;AAEvB;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAChC,cAAc,EAAE,gBAAgB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,IAAI,EAAE,CAAC,CAAC,GAAG,GACT,cAAc,CAgFhB;AA8DD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,cAAc,GACxB,OAAO,CA2DT"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Y } from '@wordpress/sync';
5
+ /**
6
+ * A YMapRecord represents the shape of the data stored in a Y.Map.
7
+ */
8
+ export type YMapRecord = Record<string, unknown>;
9
+ /**
10
+ * A wrapper around Y.Map to provide type safety. The generic type accepted by
11
+ * Y.Map represents the union of possible values of the map, which are varied in
12
+ * many cases. This type is accurate, but its non-specificity requires aggressive
13
+ * type narrowing or type casting / destruction with `as`.
14
+ *
15
+ * This type provides type enhancements so that the correct value type can be
16
+ * inferred based on the provided key. It is just a type wrap / overlay, and
17
+ * does not change the runtime behavior of Y.Map.
18
+ *
19
+ * This interface cannot extend Y.Map directly due to the limitations of
20
+ * TypeScript's structural typing. One negative consequence of this is that
21
+ * `instanceof` checks against Y.Map continue to work at runtime but will blur
22
+ * the type at compile time. To navigate this, use the `isYMap` function below.
23
+ */
24
+ export interface YMapWrap<T extends YMapRecord> extends Y.AbstractType<T> {
25
+ delete: <K extends keyof T>(key: K) => void;
26
+ forEach: (callback: (value: T[keyof T], key: keyof T, map: YMapWrap<T>) => void) => void;
27
+ has: <K extends keyof T>(key: K) => boolean;
28
+ get: <K extends keyof T>(key: K) => T[K] | undefined;
29
+ set: <K extends keyof T>(key: K, value: T[K]) => void;
30
+ toJSON: () => T;
31
+ }
32
+ /**
33
+ * Get or create a root-level Map for the given Y.Doc. Use this instead of
34
+ * doc.getMap() for additional type safety.
35
+ *
36
+ * @param doc Y.Doc
37
+ * @param key Map key
38
+ */
39
+ export declare function getRootMap<T extends YMapRecord>(doc: Y.Doc, key: string): YMapWrap<T>;
40
+ /**
41
+ * Create a new Y.Map (provided with YMapWrap type), optionally initialized with
42
+ * data. Use this instead of `new Y.Map()` for additional type safety.
43
+ *
44
+ * @param partial Partial data to initialize the map with.
45
+ */
46
+ export declare function createYMap<T extends YMapRecord>(partial?: Partial<T>): YMapWrap<T>;
47
+ /**
48
+ * Type guard to check if a value is a Y.Map without losing type information.
49
+ *
50
+ * @param value Value to check.
51
+ */
52
+ export declare function isYMap<T extends YMapRecord>(value: YMapWrap<T> | undefined): value is YMapWrap<T>;
53
+ //# sourceMappingURL=crdt-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crdt-utils.d.ts","sourceRoot":"","sources":["../../src/utils/crdt-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAC;AAEpC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;AAEnD;;;;;;;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