@wordpress/core-data 7.48.1 → 7.49.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 (96) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +0 -1
  3. package/build/actions.cjs +1 -7
  4. package/build/actions.cjs.map +3 -3
  5. package/build/entities.cjs +2 -1
  6. package/build/entities.cjs.map +2 -2
  7. package/build/entity-types/helpers.cjs.map +1 -1
  8. package/build/hooks/use-entity-record.cjs +21 -19
  9. package/build/hooks/use-entity-record.cjs.map +3 -3
  10. package/build/hooks/use-entity-records.cjs +22 -20
  11. package/build/hooks/use-entity-records.cjs.map +3 -3
  12. package/build/hooks/use-post-editor-awareness-state.cjs.map +1 -1
  13. package/build/hooks/use-query-select.cjs +2 -20
  14. package/build/hooks/use-query-select.cjs.map +2 -2
  15. package/build/hooks/utils.cjs +53 -0
  16. package/build/hooks/utils.cjs.map +7 -0
  17. package/build/private-selectors.cjs.map +2 -2
  18. package/build/reducer.cjs +17 -9
  19. package/build/reducer.cjs.map +2 -2
  20. package/build/resolvers.cjs +7 -2
  21. package/build/resolvers.cjs.map +2 -2
  22. package/build/types.cjs.map +1 -1
  23. package/build/utils/clear-unchanged-edits.cjs +51 -0
  24. package/build/utils/clear-unchanged-edits.cjs.map +7 -0
  25. package/build/utils/crdt-blocks.cjs.map +1 -1
  26. package/build/utils/crdt-user-selections.cjs.map +1 -1
  27. package/build/utils/crdt-utils.cjs.map +1 -1
  28. package/build/utils/crdt.cjs.map +1 -1
  29. package/build/utils/index.cjs +3 -0
  30. package/build/utils/index.cjs.map +2 -2
  31. package/build/utils/set-nested-value.cjs.map +1 -1
  32. package/build-module/actions.mjs +2 -8
  33. package/build-module/actions.mjs.map +2 -2
  34. package/build-module/entities.mjs +2 -1
  35. package/build-module/entities.mjs.map +2 -2
  36. package/build-module/hooks/use-entity-record.mjs +21 -19
  37. package/build-module/hooks/use-entity-record.mjs.map +2 -2
  38. package/build-module/hooks/use-entity-records.mjs +20 -18
  39. package/build-module/hooks/use-entity-records.mjs.map +2 -2
  40. package/build-module/hooks/use-post-editor-awareness-state.mjs.map +1 -1
  41. package/build-module/hooks/use-query-select.mjs +2 -20
  42. package/build-module/hooks/use-query-select.mjs.map +2 -2
  43. package/build-module/hooks/utils.mjs +28 -0
  44. package/build-module/hooks/utils.mjs.map +7 -0
  45. package/build-module/private-selectors.mjs.map +2 -2
  46. package/build-module/reducer.mjs +18 -10
  47. package/build-module/reducer.mjs.map +2 -2
  48. package/build-module/resolvers.mjs +7 -2
  49. package/build-module/resolvers.mjs.map +2 -2
  50. package/build-module/utils/clear-unchanged-edits.mjs +20 -0
  51. package/build-module/utils/clear-unchanged-edits.mjs.map +7 -0
  52. package/build-module/utils/crdt-blocks.mjs.map +1 -1
  53. package/build-module/utils/crdt-user-selections.mjs.map +1 -1
  54. package/build-module/utils/crdt-utils.mjs.map +1 -1
  55. package/build-module/utils/crdt.mjs.map +1 -1
  56. package/build-module/utils/index.mjs +22 -20
  57. package/build-module/utils/index.mjs.map +2 -2
  58. package/build-module/utils/set-nested-value.mjs.map +1 -1
  59. package/build-types/actions.d.ts.map +1 -1
  60. package/build-types/entities.d.ts.map +1 -1
  61. package/build-types/hooks/use-entity-record.d.ts +4 -1
  62. package/build-types/hooks/use-entity-record.d.ts.map +1 -1
  63. package/build-types/hooks/use-entity-records.d.ts +5 -1
  64. package/build-types/hooks/use-entity-records.d.ts.map +1 -1
  65. package/build-types/hooks/utils.d.ts +22 -0
  66. package/build-types/hooks/utils.d.ts.map +1 -0
  67. package/build-types/index.d.ts +8 -8
  68. package/build-types/private-actions.d.ts.map +1 -1
  69. package/build-types/private-selectors.d.ts +6 -0
  70. package/build-types/private-selectors.d.ts.map +1 -1
  71. package/build-types/reducer.d.ts.map +1 -1
  72. package/build-types/resolvers.d.ts +9 -4
  73. package/build-types/resolvers.d.ts.map +1 -1
  74. package/build-types/selectors.d.ts +8 -8
  75. package/build-types/selectors.d.ts.map +1 -1
  76. package/build-types/utils/clear-unchanged-edits.d.ts +12 -0
  77. package/build-types/utils/clear-unchanged-edits.d.ts.map +1 -0
  78. package/build-types/utils/index.d.ts +1 -0
  79. package/build-types/utils/index.d.ts.map +1 -1
  80. package/package.json +24 -19
  81. package/src/actions.js +2 -10
  82. package/src/entities.js +5 -0
  83. package/src/hooks/test/use-entity-record.js +5 -1
  84. package/src/hooks/use-entity-record.ts +26 -20
  85. package/src/hooks/use-entity-records.ts +26 -18
  86. package/src/hooks/use-query-select.ts +2 -23
  87. package/src/hooks/utils.ts +40 -0
  88. package/src/private-selectors.ts +6 -0
  89. package/src/reducer.js +22 -11
  90. package/src/resolvers.js +14 -4
  91. package/src/test/entities.js +51 -0
  92. package/src/utils/clear-unchanged-edits.ts +34 -0
  93. package/src/utils/index.js +1 -0
  94. package/src/utils/test/clear-unchanged-edits.js +42 -0
  95. package/build-types/utils/on-sub-key.d.ts +0 -4
  96. package/build-types/utils/on-sub-key.d.ts.map +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/resolvers.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { additionalEntityConfigLoaders, DEFAULT_ENTITY_KEY } from './entities';\nimport { getSyncManager } from './sync';\nimport {\n\tforwardResolver,\n\tgetNormalizedCommaSeparable,\n\tgetUserPermissionCacheKey,\n\tgetUserPermissionsFromAllowHeader,\n\tALLOWED_RESOURCE_ACTIONS,\n\tRECEIVE_INTERMEDIATE_RESULTS,\n\tisNumericID,\n\tnormalizeQueryForResolution,\n\tsaveCRDTDoc,\n} from './utils';\nimport { fetchBlockPatterns } from './fetch';\nimport { restoreSelection, getSelectionHistory } from './utils/crdt-selection';\nimport { parsedBlocksCache, getCacheKey } from './parsed-blocks-cache';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors =\n\t( query ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst path = addQueryArgs(\n\t\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\t\tquery\n\t\t);\n\t\tconst users = await apiFetch( { path } );\n\t\tdispatch.receiveUserQuery( path, users );\n\t};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\t\tdispatch.receiveCurrentUser( currentUser );\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getEntityRecord =\n\t( kind, name, key = '', query ) =>\n\tasync ( { select, dispatch, registry, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, key ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t\t// and without causing `getEntityRecord` resolution to occur.\n\t\t\t\tconst hasRecord = select.hasEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tkey,\n\t\t\t\t\tquery\n\t\t\t\t);\n\t\t\t\tif ( hasRecord ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet { baseURL } = entityConfig;\n\n\t\t\t// For \"string\" IDs, use the old templates endpoint.\n\t\t\tif (\n\t\t\t\tkind === 'postType' &&\n\t\t\t\tname === 'wp_template' &&\n\t\t\t\t( ( key && typeof key === 'string' && ! /^\\d+$/.test( key ) ) ||\n\t\t\t\t\t! window?.__experimentalTemplateActivate )\n\t\t\t) {\n\t\t\t\tbaseURL =\n\t\t\t\t\tbaseURL.slice( 0, baseURL.lastIndexOf( '/' ) ) +\n\t\t\t\t\t'/templates';\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( baseURL + ( key ? '/' + key : '' ), {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\t\t\tconst response = await apiFetch( { path, parse: false } );\n\t\t\tconst record = await response.json();\n\t\t\tconst permissions = getUserPermissionsFromAllowHeader(\n\t\t\t\tresponse.headers?.get( 'allow' )\n\t\t\t);\n\n\t\t\tconst canUserResolutionsArgs = [];\n\t\t\tconst receiveUserPermissionArgs = {};\n\t\t\tfor ( const action of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\t\treceiveUserPermissionArgs[\n\t\t\t\t\tgetUserPermissionCacheKey( action, {\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tid: key,\n\t\t\t\t\t} )\n\t\t\t\t] = permissions[ action ];\n\n\t\t\t\tcanUserResolutionsArgs.push( [\n\t\t\t\t\taction,\n\t\t\t\t\t{ kind, name, id: key },\n\t\t\t\t] );\n\t\t\t}\n\n\t\t\t// Entity supports syncing.\n\t\t\tif ( entityConfig.syncConfig && isNumericID( key ) && ! query ) {\n\t\t\t\tconst objectType = `${ kind }/${ name }`;\n\t\t\t\tconst objectId = key;\n\n\t\t\t\t// Use the new transient \"read/write\" config to compute transients for\n\t\t\t\t// the sync manager. Otherwise these transients are not available\n\t\t\t\t// if / until the record is edited. Use a copy of the record so that\n\t\t\t\t// it does not change the behavior outside this experimental flag.\n\t\t\t\tconst recordWithTransients = { ...record };\n\t\t\t\tObject.entries( entityConfig.transientEdits ?? {} )\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( [ propName, transientConfig ] ) =>\n\t\t\t\t\t\t\tundefined === recordWithTransients[ propName ] &&\n\t\t\t\t\t\t\ttransientConfig &&\n\t\t\t\t\t\t\t'object' === typeof transientConfig &&\n\t\t\t\t\t\t\t'read' in transientConfig &&\n\t\t\t\t\t\t\t'function' === typeof transientConfig.read\n\t\t\t\t\t)\n\t\t\t\t\t.forEach( ( [ propName, transientConfig ] ) => {\n\t\t\t\t\t\trecordWithTransients[ propName ] =\n\t\t\t\t\t\t\ttransientConfig.read( recordWithTransients );\n\t\t\t\t\t} );\n\n\t\t\t\t// Share the parsed blocks with `useEntityBlockEditor` so the\n\t\t\t\t// editor doesn't re-parse the same `content` string.\n\t\t\t\tif (\n\t\t\t\t\trecordWithTransients.blocks &&\n\t\t\t\t\ttypeof recordWithTransients.content?.raw === 'string'\n\t\t\t\t) {\n\t\t\t\t\tparsedBlocksCache.set( getCacheKey( kind, name, key ), {\n\t\t\t\t\t\tcontent: recordWithTransients.content.raw,\n\t\t\t\t\t\tblocks: recordWithTransients.blocks,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\t// Load the entity record for syncing. Do not await promise.\n\t\t\t\tvoid getSyncManager()?.load(\n\t\t\t\t\tentityConfig.syncConfig,\n\t\t\t\t\tobjectType,\n\t\t\t\t\tobjectId,\n\t\t\t\t\trecordWithTransients,\n\t\t\t\t\t{\n\t\t\t\t\t\t// Handle edits sourced from the sync manager.\n\t\t\t\t\t\teditRecord: ( edits, options = {} ) => {\n\t\t\t\t\t\t\tif ( ! Object.keys( edits ).length ) {\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\tdispatch( {\n\t\t\t\t\t\t\t\ttype: 'EDIT_ENTITY_RECORD',\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\trecordId: key,\n\t\t\t\t\t\t\t\tedits,\n\t\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t\tundo: undefined,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// Get the current entity record (with edits)\n\t\t\t\t\t\tgetEditedRecord: async () =>\n\t\t\t\t\t\t\tawait resolveSelect.getEditedEntityRecord(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tkey\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t// Handle sync connection status changes.\n\t\t\t\t\t\tonStatusChange: ( status ) => {\n\t\t\t\t\t\t\tdispatch.setSyncConnectionStatus(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tstatus\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// Refetch the current entity record from the database.\n\t\t\t\t\t\trefetchRecord: async () => {\n\t\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tawait apiFetch( { path, parse: true } ),\n\t\t\t\t\t\t\t\tquery\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// Persist the CRDT document.\n\t\t\t\t\t\t//\n\t\t\t\t\t\t// TODO: Currently, persisted CRDT documents are stored in post meta.\n\t\t\t\t\t\t// This effectively means that only post entities support CRDT\n\t\t\t\t\t\t// persistence. As we add support for syncing additional entity,\n\t\t\t\t\t\t// we'll need to revisit where persisted CRDT documents are stored.\n\t\t\t\t\t\tpersistCRDTDoc: () => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t! entityConfig.syncConfig?.supportsPersistence\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\treturn resolveSelect\n\t\t\t\t\t\t\t\t.getEditedEntityRecord( kind, name, key )\n\t\t\t\t\t\t\t\t.then( async ( editedRecord ) => {\n\t\t\t\t\t\t\t\t\t// Don't persist the CRDT document if the record is still an\n\t\t\t\t\t\t\t\t\t// auto-draft or if the entity does not support meta.\n\t\t\t\t\t\t\t\t\tconst { meta, status } = editedRecord;\n\t\t\t\t\t\t\t\t\tif ( 'auto-draft' === status || ! meta ) {\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tconst entityIdKey =\n\t\t\t\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\t\t\t\t\t\t\tconst entityId =\n\t\t\t\t\t\t\t\t\t\teditedRecord[ entityIdKey ];\n\n\t\t\t\t\t\t\t\t\tawait saveCRDTDoc(\n\t\t\t\t\t\t\t\t\t\t`${ kind }/${ name }`,\n\t\t\t\t\t\t\t\t\t\tentityId\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},\n\t\t\t\t\t\taddUndoMeta: ( ydoc, meta ) => {\n\t\t\t\t\t\t\tconst selectionHistory =\n\t\t\t\t\t\t\t\tgetSelectionHistory( ydoc );\n\n\t\t\t\t\t\t\tif ( selectionHistory ) {\n\t\t\t\t\t\t\t\tmeta.set(\n\t\t\t\t\t\t\t\t\t'selectionHistory',\n\t\t\t\t\t\t\t\t\tselectionHistory\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\tonUndoStackChange: ( undoState ) => {\n\t\t\t\t\t\t\tdispatch.__unstableNotifySyncUndoManagerChange(\n\t\t\t\t\t\t\t\tundoState\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\trestoreUndoMeta: ( ydoc, meta ) => {\n\t\t\t\t\t\t\tconst selectionHistory =\n\t\t\t\t\t\t\t\tmeta.get( 'selectionHistory' );\n\n\t\t\t\t\t\t\tif ( selectionHistory ) {\n\t\t\t\t\t\t\t\t// Because Yjs initiates an undo, we need to\n\t\t\t\t\t\t\t\t// wait until the content is restored before\n\t\t\t\t\t\t\t\t// we can update the selection.\n\t\t\t\t\t\t\t\t// Use setTimeout() to wait until content is\n\t\t\t\t\t\t\t\t// finished updating, and then set the correct\n\t\t\t\t\t\t\t\t// selection.\n\t\t\t\t\t\t\t\tsetTimeout( () => {\n\t\t\t\t\t\t\t\t\trestoreSelection( selectionHistory, ydoc );\n\t\t\t\t\t\t\t\t}, 0 );\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}\n\n\t\t\tregistry.batch( () => {\n\t\t\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t\t\t\tdispatch.receiveUserPermissions( receiveUserPermissionArgs );\n\t\t\t\tdispatch.finishResolutions( 'canUser', canUserResolutionsArgs );\n\t\t\t} );\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n// Whenever a template is saved, the active templates might be updated, so\n// invalidate the site settings when a template is updated or deleted.\ngetEntityRecord.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\tkind === 'root' &&\n\t\tname === 'site' &&\n\t\t( ( action.type === 'RECEIVE_ITEMS' &&\n\t\t\t// Making sure persistedEdits is set seems to be the only way of\n\t\t\t// knowing whether it's an update or fetch. Only an update would\n\t\t\t// have persistedEdits.\n\t\t\taction.persistedEdits &&\n\t\t\taction.persistedEdits.status !== 'auto-draft' ) ||\n\t\t\taction.type === 'REMOVE_ITEMS' ) &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {?Object} query Query Object. If requesting specific fields, fields\n * must always include the ID.\n */\nexport const getEntityRecords =\n\t( kind, name, query = {} ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\t// Keep a copy of the original query for later use in getResolutionsArgs.\n\t\t// The query object may be modified below (for example, when _fields is\n\t\t// specified), but we want to use the original query when marking\n\t\t// resolutions as finished.\n\t\tconst rawQuery = { ...query };\n\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\n\t\tfunction getResolutionsArgs( records, recordsQuery ) {\n\t\t\tconst normalizedQuery = normalizeQueryForResolution( recordsQuery );\n\t\t\treturn records\n\t\t\t\t.filter( ( record ) => record?.[ key ] )\n\t\t\t\t.map( ( record ) => [\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecord[ key ],\n\t\t\t\t\tnormalizedQuery,\n\t\t\t\t] );\n\t\t}\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet { baseURL } = entityConfig;\n\t\t\t// `combinedTemplates` means that we fetch templates from the \"old\"\n\t\t\t// /templates endpoint, which combines active user templates with\n\t\t\t// the registered templates and rewrites IDs in the form of\n\t\t\t// `theme-slug/template-slug`. When turned off, we only fetch\n\t\t\t// database templates (posts). To fetch registered templates without\n\t\t\t// edits applied, use the `registeredTemplate` entity.\n\t\t\tconst { combinedTemplates = true } = query;\n\n\t\t\tif (\n\t\t\t\tkind === 'postType' &&\n\t\t\t\tname === 'wp_template' &&\n\t\t\t\tcombinedTemplates\n\t\t\t) {\n\t\t\t\tbaseURL =\n\t\t\t\t\tbaseURL.slice( 0, baseURL.lastIndexOf( '/' ) ) +\n\t\t\t\t\t'/templates';\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( baseURL, {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\n\t\t\tlet records = [],\n\t\t\t\tmeta;\n\t\t\tif ( entityConfig.supportsPagination && query.per_page !== -1 ) {\n\t\t\t\tconst response = await apiFetch( { path, parse: false } );\n\t\t\t\trecords = Object.values( await response.json() );\n\t\t\t\tmeta = {\n\t\t\t\t\ttotalItems: parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-Total' )\n\t\t\t\t\t),\n\t\t\t\t\ttotalPages: parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-TotalPages' )\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t} else if (\n\t\t\t\tquery.per_page === -1 &&\n\t\t\t\tquery[ RECEIVE_INTERMEDIATE_RESULTS ] === true\n\t\t\t) {\n\t\t\t\tlet page = 1;\n\t\t\t\tlet totalPages;\n\n\t\t\t\tdo {\n\t\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\t\tpath: addQueryArgs( path, { page, per_page: 100 } ),\n\t\t\t\t\t\tparse: false,\n\t\t\t\t\t} );\n\t\t\t\t\tconst pageRecords = Object.values( await response.json() );\n\n\t\t\t\t\ttotalPages = parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-TotalPages' )\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( ! meta ) {\n\t\t\t\t\t\tmeta = {\n\t\t\t\t\t\t\ttotalItems: parseInt(\n\t\t\t\t\t\t\t\tresponse.headers.get( 'X-WP-Total' )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttotalPages: 1,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\trecords.push( ...pageRecords );\n\t\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\trecords,\n\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tmeta\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\t\t\tgetResolutionsArgs( pageRecords, rawQuery )\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t\tpage++;\n\t\t\t\t} while ( page <= totalPages );\n\t\t\t} else {\n\t\t\t\trecords = Object.values( await apiFetch( { path } ) );\n\t\t\t\tmeta = {\n\t\t\t\t\ttotalItems: records.length,\n\t\t\t\t\ttotalPages: 1,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( entityConfig.syncConfig && -1 === query.per_page ) {\n\t\t\t\tconst objectType = `${ kind }/${ name }`;\n\t\t\t\tgetSyncManager()?.loadCollection(\n\t\t\t\t\tentityConfig.syncConfig,\n\t\t\t\t\tobjectType,\n\t\t\t\t\t{\n\t\t\t\t\t\tonStatusChange: ( status ) => {\n\t\t\t\t\t\t\tdispatch.setSyncConnectionStatus(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\tstatus\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\trefetchRecords: async () => {\n\t\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tawait apiFetch( { path, parse: true } ),\n\t\t\t\t\t\t\t\tquery\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}\n\n\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t// explicitly set these fields as \"undefined\"\n\t\t\t// that way we consider the query \"fulfilled\".\n\t\t\tif ( query._fields ) {\n\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn record;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tregistry.batch( () => {\n\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecords,\n\t\t\t\t\tquery,\n\t\t\t\t\tfalse,\n\t\t\t\t\tundefined,\n\t\t\t\t\tmeta\n\t\t\t\t);\n\n\t\t\t\tconst targetHints = records\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( record ) =>\n\t\t\t\t\t\t\t!! record?.[ key ] &&\n\t\t\t\t\t\t\t!! record?._links?.self?.[ 0 ]?.targetHints?.allow\n\t\t\t\t\t)\n\t\t\t\t\t.map( ( record ) => ( {\n\t\t\t\t\t\tid: record[ key ],\n\t\t\t\t\t\tpermissions: getUserPermissionsFromAllowHeader(\n\t\t\t\t\t\t\trecord._links.self[ 0 ].targetHints.allow\n\t\t\t\t\t\t),\n\t\t\t\t\t} ) );\n\n\t\t\t\tconst canUserResolutionsArgs = [];\n\t\t\t\tconst receiveUserPermissionArgs = {};\n\t\t\t\tfor ( const targetHint of targetHints ) {\n\t\t\t\t\tfor ( const action of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\t\t\t\tcanUserResolutionsArgs.push( [\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t{ kind, name, id: targetHint.id },\n\t\t\t\t\t\t] );\n\n\t\t\t\t\t\treceiveUserPermissionArgs[\n\t\t\t\t\t\t\tgetUserPermissionCacheKey( action, {\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tid: targetHint.id,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t] = targetHint.permissions[ action ];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( targetHints.length > 0 ) {\n\t\t\t\t\tdispatch.receiveUserPermissions(\n\t\t\t\t\t\treceiveUserPermissionArgs\n\t\t\t\t\t);\n\t\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t\t'canUser',\n\t\t\t\t\t\tcanUserResolutionsArgs\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\tgetResolutionsArgs( records, rawQuery )\n\t\t\t\t);\n\n\t\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t\t} );\n\t\t} catch {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the total number of entity records.\n */\nexport const getEntityRecordsTotalItems = forwardResolver( 'getEntityRecords' );\n\n/**\n * Requests the number of available pages for the given query.\n */\nexport const getEntityRecordsTotalPages = forwardResolver( 'getEntityRecords' );\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\n\t\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n\t};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview =\n\t( url ) =>\n\tasync ( { dispatch } ) => {\n\t\ttry {\n\t\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t\t} );\n\t\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t\t} catch {\n\t\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\t\tdispatch.receiveEmbedPreview( url, false );\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string|Object} resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser =\n\t( requestedAction, resource, id ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tif ( ! ALLOWED_RESOURCE_ACTIONS.includes( requestedAction ) ) {\n\t\t\tthrow new Error( `'${ requestedAction }' is not a valid action.` );\n\t\t}\n\n\t\tconst { hasStartedResolution } = registry.select( STORE_NAME );\n\n\t\t// Prevent resolving the same resource twice.\n\t\tfor ( const relatedAction of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\tif ( relatedAction === requestedAction ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isAlreadyResolving = hasStartedResolution( 'canUser', [\n\t\t\t\trelatedAction,\n\t\t\t\tresource,\n\t\t\t\tid,\n\t\t\t] );\n\t\t\tif ( isAlreadyResolving ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tlet resourcePath = null;\n\t\tif ( typeof resource === 'object' ) {\n\t\t\tif ( ! resource.kind || ! resource.name ) {\n\t\t\t\tthrow new Error( 'The entity resource object is not valid.' );\n\t\t\t}\n\n\t\t\tconst configs = await resolveSelect.getEntitiesConfig(\n\t\t\t\tresource.kind\n\t\t\t);\n\t\t\tconst entityConfig = configs.find(\n\t\t\t\t( config ) =>\n\t\t\t\t\tconfig.name === resource.name &&\n\t\t\t\t\tconfig.kind === resource.kind\n\t\t\t);\n\t\t\tif ( ! entityConfig ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresourcePath =\n\t\t\t\tentityConfig.baseURL + ( resource.id ? '/' + resource.id : '' );\n\t\t} else {\n\t\t\tresourcePath = `/wp/v2/${ resource }` + ( id ? '/' + id : '' );\n\t\t}\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath: resourcePath,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t\tparse: false,\n\t\t\t} );\n\t\t} catch {\n\t\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional chaining operator is used here because the API requests don't\n\t\t// return the expected result in the React native version. Instead, API requests\n\t\t// only return the result, without including response properties like the headers.\n\t\tconst permissions = getUserPermissionsFromAllowHeader(\n\t\t\tresponse.headers?.get( 'allow' )\n\t\t);\n\t\tconst receiveUserPermissionArgs = {};\n\t\tconst canUserResolutionsArgs = [];\n\t\tfor ( const action of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\treceiveUserPermissionArgs[\n\t\t\t\tgetUserPermissionCacheKey( action, resource, id )\n\t\t\t] = permissions[ action ];\n\n\t\t\t// Mark related action resolutions as finished.\n\t\t\tif ( action !== requestedAction ) {\n\t\t\t\tcanUserResolutionsArgs.push( [ action, resource, id ] );\n\t\t\t}\n\t\t}\n\t\tregistry.batch( () => {\n\t\t\tdispatch.receiveUserPermissions( receiveUserPermissionArgs );\n\t\t\tdispatch.finishResolutions( 'canUser', canUserResolutionsArgs );\n\t\t} );\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} recordId Record's id.\n */\nexport const canUserEditEntityRecord =\n\t( kind, name, recordId ) =>\n\tasync ( { dispatch } ) => {\n\t\tawait dispatch( canUser( 'update', { kind, name, id: recordId } ) );\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves =\n\t( postType, postId ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst {\n\t\t\trest_base: restBase,\n\t\t\trest_namespace: restNamespace = 'wp/v2',\n\t\t\tsupports,\n\t\t} = await resolveSelect.getPostType( postType );\n\t\tif ( ! supports?.autosave ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst autosaves = await apiFetch( {\n\t\t\tpath: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,\n\t\t} );\n\n\t\tif ( autosaves && autosaves.length ) {\n\t\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t\t}\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave =\n\t( postType, postId ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect.getAutosaves( postType, postId );\n\t};\n\nexport const __experimentalGetCurrentGlobalStylesId =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\t\tconst globalStylesURL =\n\t\t\tactiveThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]\n\t\t\t\t?.href;\n\t\tif ( ! globalStylesURL ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Regex matches the ID at the end of a URL or immediately before\n\t\t// the query string.\n\t\tconst matches = globalStylesURL.match( /\\/(\\d+)(?:\\?|$)/ );\n\t\tconst id = matches ? Number( matches[ 1 ] ) : null;\n\n\t\tif ( id ) {\n\t\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId( id );\n\t\t}\n\t};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\t// Please adjust the preloaded requests if this changes!\n\t\tconst themeGlobalStyles = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }?context=view`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tthemeGlobalStyles\n\t\t);\n\t};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\t// Please adjust the preloaded requests if this changes!\n\t\tconst variations = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations?context=view`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tvariations\n\t\t);\n\t};\n\n/**\n * Fetches and returns the revisions of the current global styles theme.\n */\nexport const getCurrentThemeGlobalStylesRevisions =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst globalStylesId =\n\t\t\tawait resolveSelect.__experimentalGetCurrentGlobalStylesId();\n\t\tconst record = globalStylesId\n\t\t\t? await resolveSelect.getEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'globalStyles',\n\t\t\t\t\tglobalStylesId\n\t\t\t )\n\t\t\t: undefined;\n\t\tconst revisionsURL = record?._links?.[ 'version-history' ]?.[ 0 ]?.href;\n\n\t\tif ( revisionsURL ) {\n\t\t\tconst resetRevisions = await apiFetch( {\n\t\t\t\turl: revisionsURL,\n\t\t\t} );\n\t\t\tconst revisions = resetRevisions?.map( ( revision ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( revision ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\t\t\tdispatch.receiveThemeGlobalStyleRevisions(\n\t\t\t\tglobalStylesId,\n\t\t\t\trevisions\n\t\t\t);\n\t\t}\n\t};\n\ngetCurrentThemeGlobalStylesRevisions.shouldInvalidate = ( action ) => {\n\treturn (\n\t\taction.type === 'SAVE_ENTITY_RECORD_FINISH' &&\n\t\taction.kind === 'root' &&\n\t\t! action.error &&\n\t\taction.name === 'globalStyles'\n\t);\n};\n\nexport const getBlockPatterns =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst patterns = await fetchBlockPatterns();\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );\n\t};\n\nexport const getBlockPatternCategories =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst categories = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/categories',\n\t\t} );\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', categories } );\n\t};\n\nexport const getUserPatternCategories =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst patternCategories = await resolveSelect.getEntityRecords(\n\t\t\t'taxonomy',\n\t\t\t'wp_pattern_category',\n\t\t\t{\n\t\t\t\tper_page: -1,\n\t\t\t\t_fields: 'id,name,description,slug',\n\t\t\t\tcontext: 'view',\n\t\t\t}\n\t\t);\n\n\t\tconst mappedPatternCategories =\n\t\t\tpatternCategories?.map( ( userCategory ) => ( {\n\t\t\t\t...userCategory,\n\t\t\t\tlabel: decodeEntities( userCategory.name ),\n\t\t\t\tname: userCategory.slug,\n\t\t\t} ) ) || [];\n\n\t\tdispatch( {\n\t\t\ttype: 'RECEIVE_USER_PATTERN_CATEGORIES',\n\t\t\tpatternCategories: mappedPatternCategories,\n\t\t} );\n\t};\n\nexport const getNavigationFallbackId =\n\t() =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst fallback = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {\n\t\t\t\t_embed: true,\n\t\t\t} ),\n\t\t} );\n\n\t\tconst record = fallback?._embedded?.self;\n\n\t\tregistry.batch( () => {\n\t\t\tdispatch.receiveNavigationFallbackId( fallback?.id );\n\n\t\t\tif ( ! record ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the fallback is already in the store, don't invalidate navigation queries.\n\t\t\t// Otherwise, invalidate the cache for the scenario where there were no Navigation\n\t\t\t// posts in the state and the fallback created one.\n\t\t\tconst existingFallbackEntityRecord = select.getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tfallback.id\n\t\t\t);\n\t\t\tconst invalidateNavigationQueries = ! existingFallbackEntityRecord;\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\trecord,\n\t\t\t\tundefined,\n\t\t\t\tinvalidateNavigationQueries\n\t\t\t);\n\n\t\t\t// Resolve to avoid further network requests.\n\t\t\tdispatch.finishResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tfallback.id,\n\t\t\t] );\n\t\t} );\n\t};\n\nexport const getDefaultTemplateId =\n\t( query ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tconst template = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', query ),\n\t\t} );\n\t\t// Wait for the the entities config to be loaded, otherwise receiving\n\t\t// the template as an entity will not work.\n\t\tawait resolveSelect.getEntitiesConfig( 'postType' );\n\t\t// When active_templates experiment is enabled, use numeric wp_id if it\n\t\t// exists, otherwise fall back to string ID format (theme//slug) as the\n\t\t// frontend expects string IDs for templates.\n\t\tconst id = window?.__experimentalTemplateActivate\n\t\t\t? template?.wp_id || template?.id\n\t\t\t: template?.id;\n\n\t\tregistry.batch( () => {\n\t\t\tdispatch.receiveDefaultTemplateId( query, id || '' );\n\t\t\t// Endpoint may return an empty object if no template is found.\n\t\t\tif ( id ) {\n\t\t\t\ttemplate.id = id;\n\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\ttemplate\n\t\t\t\t);\n\t\t\t\t// Avoid further network requests.\n\t\t\t\tdispatch.finishResolution( 'getEntityRecord', [\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\tid,\n\t\t\t\t] );\n\t\t\t}\n\t\t} );\n\t};\n\ngetDefaultTemplateId.shouldInvalidate = ( action ) => {\n\t// Only invalidate on real saves; `persistedEdits` is absent on\n\t// initial fetches so the kickoff's own site read doesn't wipe\n\t// the just-resolved template id.\n\treturn (\n\t\taction.type === 'RECEIVE_ITEMS' &&\n\t\taction.kind === 'root' &&\n\t\taction.name === 'site' &&\n\t\t!! action.persistedEdits\n\t);\n};\n\n/**\n * Requests an entity's revisions from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getRevisions =\n\t( kind, name, recordKey, query = {} ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rawQuery = { ...query };\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordKey, 'revisions' ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.revisionKey || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.getRevisionsUrl( recordKey ),\n\t\t\t\tquery\n\t\t\t);\n\n\t\t\tlet records, response;\n\t\t\tconst meta = {};\n\t\t\tconst isPaginated =\n\t\t\t\tentityConfig.supportsPagination && query.per_page !== -1;\n\t\t\ttry {\n\t\t\t\tresponse = await apiFetch( { path, parse: ! isPaginated } );\n\t\t\t} catch {\n\t\t\t\t// Do nothing if our request comes back with an API error.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( response ) {\n\t\t\t\tif ( isPaginated ) {\n\t\t\t\t\trecords = Object.values( await response.json() );\n\t\t\t\t\tmeta.totalItems = parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-Total' )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\trecords = Object.values( response );\n\t\t\t\t}\n\n\t\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t\t// explicitly set these fields as \"undefined\"\n\t\t\t\t// that way we consider the query \"fulfilled\".\n\t\t\t\tif ( query._fields ) {\n\t\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\treturn record;\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tdispatch.receiveRevisions(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\trecordKey,\n\t\t\t\t\t\trecords,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tmeta\n\t\t\t\t\t);\n\n\t\t\t\t\t// Mark individual getRevision resolutions as done so that\n\t\t\t\t\t// subsequent getRevision calls skip redundant API fetches.\n\t\t\t\t\tconst key = entityConfig.revisionKey || DEFAULT_ENTITY_KEY;\n\t\t\t\t\tconst normalizedQuery =\n\t\t\t\t\t\tnormalizeQueryForResolution( rawQuery );\n\t\t\t\t\tconst resolutionsArgs = records\n\t\t\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t\t\t.map( ( record ) => [\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\trecordKey,\n\t\t\t\t\t\t\trecord[ key ],\n\t\t\t\t\t\t\tnormalizedQuery,\n\t\t\t\t\t\t] );\n\n\t\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t\t'getRevision',\n\t\t\t\t\t\tresolutionsArgs\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n// Invalidate cache when a new revision is created.\ngetRevisions.shouldInvalidate = ( action, kind, name, recordKey ) =>\n\taction.type === 'SAVE_ENTITY_RECORD_FINISH' &&\n\tname === action.name &&\n\tkind === action.kind &&\n\t! action.error &&\n\trecordKey === action.recordId;\n\n/**\n * Requests a specific Entity revision from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.\n * @param {number|string} revisionKey The revision's key.\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getRevision =\n\t( kind, name, recordKey, revisionKey, query ) =>\n\tasync ( { select, dispatch, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: [\n\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\tentityConfig.revisionKey || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t] ),\n\t\t\t\t].join(),\n\t\t\t};\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[\n\t\t\t\t'entities',\n\t\t\t\t'records',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordKey,\n\t\t\t\t'revisions',\n\t\t\t\trevisionKey,\n\t\t\t],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif (\n\t\t\t\tselect.hasRevision( kind, name, recordKey, revisionKey, query )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.getRevisionsUrl( recordKey, revisionKey ),\n\t\t\t\tquery\n\t\t\t);\n\n\t\t\tlet record;\n\t\t\ttry {\n\t\t\t\trecord = await apiFetch( { path } );\n\t\t\t} catch {\n\t\t\t\t// Do nothing if our request comes back with an API error.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( record ) {\n\t\t\t\tdispatch.receiveRevisions(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordKey,\n\t\t\t\t\trecord,\n\t\t\t\t\tquery\n\t\t\t\t);\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Requests a specific post type options from the REST API.\n *\n * @param {string} postType Post type slug.\n */\nexport const getRegisteredPostMeta =\n\t( postType ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tlet options;\n\t\ttry {\n\t\t\tconst {\n\t\t\t\trest_namespace: restNamespace = 'wp/v2',\n\t\t\t\trest_base: restBase,\n\t\t\t} = ( await resolveSelect.getPostType( postType ) ) || {};\n\t\t\toptions = await apiFetch( {\n\t\t\t\tpath: `${ restNamespace }/${ restBase }/?context=edit`,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t} );\n\t\t} catch {\n\t\t\t// Do nothing if the request comes back with an API error.\n\t\t\treturn;\n\t\t}\n\n\t\tif ( options ) {\n\t\t\tdispatch.receiveRegisteredPostMeta(\n\t\t\t\tpostType,\n\t\t\t\toptions?.schema?.properties?.meta?.properties\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Requests entity configs for the given kind from the REST API.\n *\n * @param {string} kind Entity kind.\n */\nexport const getEntitiesConfig =\n\t( kind ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst loader = additionalEntityConfigLoaders.find(\n\t\t\t( l ) => l.kind === kind\n\t\t);\n\n\t\tif ( ! loader ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst configs = await loader.loadEntities();\n\t\t\tif ( ! configs.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdispatch.addEntities( configs );\n\t\t} catch {\n\t\t\t// Do nothing if the request comes back with an API error.\n\t\t}\n\t};\n\n/**\n * Requests editor settings from the REST API.\n */\nexport const getEditorSettings =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst settings = await apiFetch( {\n\t\t\tpath: '/wp-block-editor/v1/settings',\n\t\t} );\n\t\tdispatch.receiveEditorSettings( settings );\n\t};\n\n/**\n * Requests editor assets from the REST API.\n */\nexport const getEditorAssets =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst assets = await apiFetch( {\n\t\t\tpath: '/wp-block-editor/v1/assets',\n\t\t} );\n\t\tdispatch.receiveEditorAssets( assets );\n\t};\n\n/**\n * Requests view config for a given entity type from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n */\nexport const getViewConfig =\n\t( kind, name ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst config = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/view-config', { kind, name } ),\n\t\t} );\n\t\tdispatch.receiveViewConfig( kind, name, config );\n\t};\n"],
5
- "mappings": ";AAGA,SAAS,iBAAiB;AAK1B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,OAAO,cAAc;AAKrB,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B,0BAA0B;AAClE,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,0BAA0B;AACnC,SAAS,kBAAkB,2BAA2B;AACtD,SAAS,mBAAmB,mBAAmB;AAQxC,IAAM,aACZ,CAAE,UACF,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,OAAO;AAAA,IACZ;AAAA,IACA;AAAA,EACD;AACA,QAAM,QAAQ,MAAM,SAAU,EAAE,KAAK,CAAE;AACvC,WAAS,iBAAkB,MAAM,KAAM;AACxC;AAKM,IAAM,iBACZ,MACA,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,cAAc,MAAM,SAAU,EAAE,MAAM,kBAAkB,CAAE;AAChE,WAAS,mBAAoB,WAAY;AAC1C;AAYM,IAAM,kBACZ,CAAE,MAAM,MAAM,MAAM,IAAI,UACxB,OAAQ,EAAE,QAAQ,UAAU,UAAU,cAAc,MAAO;AAC1D,QAAM,UAAU,MAAM,cAAc,kBAAmB,IAAK;AAC5D,QAAM,eAAe,QAAQ;AAAA,IAC5B,CAAE,WAAY,OAAO,SAAS,QAAQ,OAAO,SAAS;AAAA,EACvD;AACA,MAAK,CAAE,cAAe;AACrB;AAAA,EACD;AAEA,QAAM,OAAO,MAAM,SAAS;AAA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EAAE,SAAS,MAAO;AACzB,QAAM,SAAS,8BAA8B;AAAA,IAC5C,CAAE,MAAO,EAAE,SAAS;AAAA,EACrB;AAEA,MAAK,CAAE,QAAS;AACf;AAAA,EACD;AAEA,MAAI;AACH,UAAM,UAAU,MAAM,OAAO,aAAa;AAC1C,QAAK,CAAE,QAAQ,QAAS;AACvB;AAAA,IACD;AAEA,aAAS,YAAa,OAAQ;AAAA,EAC/B,QAAQ;AAAA,EAER;AACD;AAKM,IAAM,oBACZ,MACA,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,WAAW,MAAM,SAAU;AAAA,IAChC,MAAM;AAAA,EACP,CAAE;AACF,WAAS,sBAAuB,QAAS;AAC1C;AAKM,IAAM,kBACZ,MACA,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,SAAS,MAAM,SAAU;AAAA,IAC9B,MAAM;AAAA,EACP,CAAE;AACF,WAAS,oBAAqB,MAAO;AACtC;AAQM,IAAM,gBACZ,CAAE,MAAM,SACR,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,SAAS,MAAM,SAAU;AAAA,IAC9B,MAAM,aAAc,sBAAsB,EAAE,MAAM,KAAK,CAAE;AAAA,EAC1D,CAAE;AACF,WAAS,kBAAmB,MAAM,MAAM,MAAO;AAChD;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { additionalEntityConfigLoaders, DEFAULT_ENTITY_KEY } from './entities';\nimport { getSyncManager } from './sync';\nimport {\n\tforwardResolver,\n\tgetNormalizedCommaSeparable,\n\tgetUserPermissionCacheKey,\n\tgetUserPermissionsFromAllowHeader,\n\tALLOWED_RESOURCE_ACTIONS,\n\tRECEIVE_INTERMEDIATE_RESULTS,\n\tisNumericID,\n\tnormalizeQueryForResolution,\n\tsaveCRDTDoc,\n} from './utils';\nimport { fetchBlockPatterns } from './fetch';\nimport { restoreSelection, getSelectionHistory } from './utils/crdt-selection';\nimport { parsedBlocksCache, getCacheKey } from './parsed-blocks-cache';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors =\n\t( query ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst path = addQueryArgs(\n\t\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\t\tquery\n\t\t);\n\t\tconst users = await apiFetch( { path } );\n\t\tdispatch.receiveUserQuery( path, users );\n\t};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\t\tdispatch.receiveCurrentUser( currentUser );\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getEntityRecord =\n\t( kind, name, key = '', query ) =>\n\tasync ( { select, dispatch, registry, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, key ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t\t// and without causing `getEntityRecord` resolution to occur.\n\t\t\t\tconst hasRecord = select.hasEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tkey,\n\t\t\t\t\tquery\n\t\t\t\t);\n\t\t\t\tif ( hasRecord ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet { baseURL } = entityConfig;\n\n\t\t\t// For \"string\" IDs, use the old templates endpoint.\n\t\t\tif (\n\t\t\t\tkind === 'postType' &&\n\t\t\t\tname === 'wp_template' &&\n\t\t\t\t( ( key && typeof key === 'string' && ! /^\\d+$/.test( key ) ) ||\n\t\t\t\t\t! window?.__experimentalTemplateActivate )\n\t\t\t) {\n\t\t\t\tbaseURL =\n\t\t\t\t\tbaseURL.slice( 0, baseURL.lastIndexOf( '/' ) ) +\n\t\t\t\t\t'/templates';\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( baseURL + ( key ? '/' + key : '' ), {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\t\t\tconst response = await apiFetch( { path, parse: false } );\n\t\t\tconst record = await response.json();\n\t\t\tconst permissions = getUserPermissionsFromAllowHeader(\n\t\t\t\tresponse.headers?.get( 'allow' )\n\t\t\t);\n\n\t\t\tconst canUserResolutionsArgs = [];\n\t\t\tconst receiveUserPermissionArgs = {};\n\t\t\tfor ( const action of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\t\treceiveUserPermissionArgs[\n\t\t\t\t\tgetUserPermissionCacheKey( action, {\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tid: key,\n\t\t\t\t\t} )\n\t\t\t\t] = permissions[ action ];\n\n\t\t\t\tcanUserResolutionsArgs.push( [\n\t\t\t\t\taction,\n\t\t\t\t\t{ kind, name, id: key },\n\t\t\t\t] );\n\t\t\t}\n\n\t\t\t// Entity supports syncing.\n\t\t\tif ( entityConfig.syncConfig && isNumericID( key ) && ! query ) {\n\t\t\t\tconst objectType = `${ kind }/${ name }`;\n\t\t\t\tconst objectId = key;\n\n\t\t\t\t// Use the new transient \"read/write\" config to compute transients for\n\t\t\t\t// the sync manager. Otherwise these transients are not available\n\t\t\t\t// if / until the record is edited. Use a copy of the record so that\n\t\t\t\t// it does not change the behavior outside this experimental flag.\n\t\t\t\tconst recordWithTransients = { ...record };\n\t\t\t\tObject.entries( entityConfig.transientEdits ?? {} )\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( [ propName, transientConfig ] ) =>\n\t\t\t\t\t\t\tundefined === recordWithTransients[ propName ] &&\n\t\t\t\t\t\t\ttransientConfig &&\n\t\t\t\t\t\t\t'object' === typeof transientConfig &&\n\t\t\t\t\t\t\t'read' in transientConfig &&\n\t\t\t\t\t\t\t'function' === typeof transientConfig.read\n\t\t\t\t\t)\n\t\t\t\t\t.forEach( ( [ propName, transientConfig ] ) => {\n\t\t\t\t\t\trecordWithTransients[ propName ] =\n\t\t\t\t\t\t\ttransientConfig.read( recordWithTransients );\n\t\t\t\t\t} );\n\n\t\t\t\t// Share the parsed blocks with `useEntityBlockEditor` so the\n\t\t\t\t// editor doesn't re-parse the same `content` string.\n\t\t\t\tif (\n\t\t\t\t\trecordWithTransients.blocks &&\n\t\t\t\t\ttypeof recordWithTransients.content?.raw === 'string'\n\t\t\t\t) {\n\t\t\t\t\tparsedBlocksCache.set( getCacheKey( kind, name, key ), {\n\t\t\t\t\t\tcontent: recordWithTransients.content.raw,\n\t\t\t\t\t\tblocks: recordWithTransients.blocks,\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\t// Load the entity record for syncing. Do not await promise.\n\t\t\t\tvoid getSyncManager()?.load(\n\t\t\t\t\tentityConfig.syncConfig,\n\t\t\t\t\tobjectType,\n\t\t\t\t\tobjectId,\n\t\t\t\t\trecordWithTransients,\n\t\t\t\t\t{\n\t\t\t\t\t\t// Handle edits sourced from the sync manager.\n\t\t\t\t\t\teditRecord: ( edits, options = {} ) => {\n\t\t\t\t\t\t\tif ( ! Object.keys( edits ).length ) {\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\tdispatch( {\n\t\t\t\t\t\t\t\ttype: 'EDIT_ENTITY_RECORD',\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\trecordId: key,\n\t\t\t\t\t\t\t\tedits,\n\t\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t\tundo: undefined,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// Get the current entity record (with edits)\n\t\t\t\t\t\tgetEditedRecord: async () =>\n\t\t\t\t\t\t\tawait resolveSelect.getEditedEntityRecord(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tkey\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t// Handle sync connection status changes.\n\t\t\t\t\t\tonStatusChange: ( status ) => {\n\t\t\t\t\t\t\tdispatch.setSyncConnectionStatus(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tstatus\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// Refetch the current entity record from the database.\n\t\t\t\t\t\trefetchRecord: async () => {\n\t\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tawait apiFetch( { path, parse: true } ),\n\t\t\t\t\t\t\t\tquery\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// Persist the CRDT document.\n\t\t\t\t\t\t//\n\t\t\t\t\t\t// TODO: Currently, persisted CRDT documents are stored in post meta.\n\t\t\t\t\t\t// This effectively means that only post entities support CRDT\n\t\t\t\t\t\t// persistence. As we add support for syncing additional entity,\n\t\t\t\t\t\t// we'll need to revisit where persisted CRDT documents are stored.\n\t\t\t\t\t\tpersistCRDTDoc: () => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t! entityConfig.syncConfig?.supportsPersistence\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\treturn resolveSelect\n\t\t\t\t\t\t\t\t.getEditedEntityRecord( kind, name, key )\n\t\t\t\t\t\t\t\t.then( async ( editedRecord ) => {\n\t\t\t\t\t\t\t\t\t// Don't persist the CRDT document if the record is still an\n\t\t\t\t\t\t\t\t\t// auto-draft or if the entity does not support meta.\n\t\t\t\t\t\t\t\t\tconst { meta, status } = editedRecord;\n\t\t\t\t\t\t\t\t\tif ( 'auto-draft' === status || ! meta ) {\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tconst entityIdKey =\n\t\t\t\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\t\t\t\t\t\t\tconst entityId =\n\t\t\t\t\t\t\t\t\t\teditedRecord[ entityIdKey ];\n\n\t\t\t\t\t\t\t\t\tawait saveCRDTDoc(\n\t\t\t\t\t\t\t\t\t\t`${ kind }/${ name }`,\n\t\t\t\t\t\t\t\t\t\tentityId\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},\n\t\t\t\t\t\taddUndoMeta: ( ydoc, meta ) => {\n\t\t\t\t\t\t\tconst selectionHistory =\n\t\t\t\t\t\t\t\tgetSelectionHistory( ydoc );\n\n\t\t\t\t\t\t\tif ( selectionHistory ) {\n\t\t\t\t\t\t\t\tmeta.set(\n\t\t\t\t\t\t\t\t\t'selectionHistory',\n\t\t\t\t\t\t\t\t\tselectionHistory\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\tonUndoStackChange: ( undoState ) => {\n\t\t\t\t\t\t\tdispatch.__unstableNotifySyncUndoManagerChange(\n\t\t\t\t\t\t\t\tundoState\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\trestoreUndoMeta: ( ydoc, meta ) => {\n\t\t\t\t\t\t\tconst selectionHistory =\n\t\t\t\t\t\t\t\tmeta.get( 'selectionHistory' );\n\n\t\t\t\t\t\t\tif ( selectionHistory ) {\n\t\t\t\t\t\t\t\t// Because Yjs initiates an undo, we need to\n\t\t\t\t\t\t\t\t// wait until the content is restored before\n\t\t\t\t\t\t\t\t// we can update the selection.\n\t\t\t\t\t\t\t\t// Use setTimeout() to wait until content is\n\t\t\t\t\t\t\t\t// finished updating, and then set the correct\n\t\t\t\t\t\t\t\t// selection.\n\t\t\t\t\t\t\t\tsetTimeout( () => {\n\t\t\t\t\t\t\t\t\trestoreSelection( selectionHistory, ydoc );\n\t\t\t\t\t\t\t\t}, 0 );\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}\n\n\t\t\tregistry.batch( () => {\n\t\t\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t\t\t\tdispatch.receiveUserPermissions( receiveUserPermissionArgs );\n\t\t\t\tdispatch.finishResolutions( 'canUser', canUserResolutionsArgs );\n\t\t\t} );\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n// Whenever a template is saved, the active templates might be updated, so\n// invalidate the site settings when a template is updated or deleted.\ngetEntityRecord.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\tkind === 'root' &&\n\t\tname === 'site' &&\n\t\t( ( action.type === 'RECEIVE_ITEMS' &&\n\t\t\t// Making sure persistedEdits is set seems to be the only way of\n\t\t\t// knowing whether it's an update or fetch. Only an update would\n\t\t\t// have persistedEdits.\n\t\t\taction.persistedEdits &&\n\t\t\taction.persistedEdits.status !== 'auto-draft' ) ||\n\t\t\taction.type === 'REMOVE_ITEMS' ) &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {?Object} query Query Object. If requesting specific fields, fields\n * must always include the ID.\n */\nexport const getEntityRecords =\n\t( kind, name, query = {} ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\t// Keep a copy of the original query for later use in getResolutionsArgs.\n\t\t// The query object may be modified below (for example, when _fields is\n\t\t// specified), but we want to use the original query when marking\n\t\t// resolutions as finished.\n\t\tconst rawQuery = { ...query };\n\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\n\t\tfunction getResolutionsArgs( records, recordsQuery ) {\n\t\t\tconst normalizedQuery = normalizeQueryForResolution( recordsQuery );\n\t\t\treturn records\n\t\t\t\t.filter( ( record ) => record?.[ key ] )\n\t\t\t\t.map( ( record ) => [\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecord[ key ],\n\t\t\t\t\tnormalizedQuery,\n\t\t\t\t] );\n\t\t}\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet { baseURL } = entityConfig;\n\t\t\t// `combinedTemplates` means that we fetch templates from the \"old\"\n\t\t\t// /templates endpoint, which combines active user templates with\n\t\t\t// the registered templates and rewrites IDs in the form of\n\t\t\t// `theme-slug/template-slug`. When turned off, we only fetch\n\t\t\t// database templates (posts). To fetch registered templates without\n\t\t\t// edits applied, use the `registeredTemplate` entity.\n\t\t\tconst { combinedTemplates = true } = query;\n\n\t\t\tif (\n\t\t\t\tkind === 'postType' &&\n\t\t\t\tname === 'wp_template' &&\n\t\t\t\tcombinedTemplates\n\t\t\t) {\n\t\t\t\tbaseURL =\n\t\t\t\t\tbaseURL.slice( 0, baseURL.lastIndexOf( '/' ) ) +\n\t\t\t\t\t'/templates';\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( baseURL, {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\n\t\t\tlet records = [],\n\t\t\t\tmeta;\n\t\t\tif ( entityConfig.supportsPagination && query.per_page !== -1 ) {\n\t\t\t\tconst response = await apiFetch( { path, parse: false } );\n\t\t\t\trecords = Object.values( await response.json() );\n\t\t\t\tmeta = {\n\t\t\t\t\ttotalItems: parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-Total' )\n\t\t\t\t\t),\n\t\t\t\t\ttotalPages: parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-TotalPages' )\n\t\t\t\t\t),\n\t\t\t\t};\n\t\t\t} else if (\n\t\t\t\tquery.per_page === -1 &&\n\t\t\t\tquery[ RECEIVE_INTERMEDIATE_RESULTS ] === true\n\t\t\t) {\n\t\t\t\tlet page = 1;\n\t\t\t\tlet totalPages;\n\n\t\t\t\tdo {\n\t\t\t\t\tconst response = await apiFetch( {\n\t\t\t\t\t\tpath: addQueryArgs( path, { page, per_page: 100 } ),\n\t\t\t\t\t\tparse: false,\n\t\t\t\t\t} );\n\t\t\t\t\tconst pageRecords = Object.values( await response.json() );\n\n\t\t\t\t\ttotalPages = parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-TotalPages' )\n\t\t\t\t\t);\n\n\t\t\t\t\tif ( ! meta ) {\n\t\t\t\t\t\tmeta = {\n\t\t\t\t\t\t\ttotalItems: parseInt(\n\t\t\t\t\t\t\t\tresponse.headers.get( 'X-WP-Total' )\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\ttotalPages: 1,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\trecords.push( ...pageRecords );\n\t\t\t\t\tregistry.batch( () => {\n\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\trecords,\n\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\tmeta\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\t\t\tgetResolutionsArgs( pageRecords, rawQuery )\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t\tpage++;\n\t\t\t\t} while ( page <= totalPages );\n\t\t\t} else {\n\t\t\t\trecords = Object.values( await apiFetch( { path } ) );\n\t\t\t\tmeta = {\n\t\t\t\t\ttotalItems: records.length,\n\t\t\t\t\ttotalPages: 1,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif ( entityConfig.syncConfig && -1 === query.per_page ) {\n\t\t\t\tconst objectType = `${ kind }/${ name }`;\n\t\t\t\tgetSyncManager()?.loadCollection(\n\t\t\t\t\tentityConfig.syncConfig,\n\t\t\t\t\tobjectType,\n\t\t\t\t\t{\n\t\t\t\t\t\tonStatusChange: ( status ) => {\n\t\t\t\t\t\t\tdispatch.setSyncConnectionStatus(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\tstatus\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t\trefetchRecords: async () => {\n\t\t\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tawait apiFetch( { path, parse: true } ),\n\t\t\t\t\t\t\t\tquery\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}\n\n\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t// explicitly set these fields as \"undefined\"\n\t\t\t// that way we consider the query \"fulfilled\".\n\t\t\tif ( query._fields ) {\n\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn record;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tregistry.batch( () => {\n\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecords,\n\t\t\t\t\tquery,\n\t\t\t\t\tfalse,\n\t\t\t\t\tundefined,\n\t\t\t\t\tmeta\n\t\t\t\t);\n\n\t\t\t\tconst targetHints = records\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( record ) =>\n\t\t\t\t\t\t\t!! record?.[ key ] &&\n\t\t\t\t\t\t\t!! record?._links?.self?.[ 0 ]?.targetHints?.allow\n\t\t\t\t\t)\n\t\t\t\t\t.map( ( record ) => ( {\n\t\t\t\t\t\tid: record[ key ],\n\t\t\t\t\t\tpermissions: getUserPermissionsFromAllowHeader(\n\t\t\t\t\t\t\trecord._links.self[ 0 ].targetHints.allow\n\t\t\t\t\t\t),\n\t\t\t\t\t} ) );\n\n\t\t\t\tconst canUserResolutionsArgs = [];\n\t\t\t\tconst receiveUserPermissionArgs = {};\n\t\t\t\tfor ( const targetHint of targetHints ) {\n\t\t\t\t\tfor ( const action of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\t\t\t\tcanUserResolutionsArgs.push( [\n\t\t\t\t\t\t\taction,\n\t\t\t\t\t\t\t{ kind, name, id: targetHint.id },\n\t\t\t\t\t\t] );\n\n\t\t\t\t\t\treceiveUserPermissionArgs[\n\t\t\t\t\t\t\tgetUserPermissionCacheKey( action, {\n\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tid: targetHint.id,\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t] = targetHint.permissions[ action ];\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif ( targetHints.length > 0 ) {\n\t\t\t\t\tdispatch.receiveUserPermissions(\n\t\t\t\t\t\treceiveUserPermissionArgs\n\t\t\t\t\t);\n\t\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t\t'canUser',\n\t\t\t\t\t\tcanUserResolutionsArgs\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t'getEntityRecord',\n\t\t\t\t\tgetResolutionsArgs( records, rawQuery )\n\t\t\t\t);\n\n\t\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t\t} );\n\t\t} catch {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the total number of entity records.\n */\nexport const getEntityRecordsTotalItems = forwardResolver( 'getEntityRecords' );\n\n/**\n * Requests the number of available pages for the given query.\n */\nexport const getEntityRecordsTotalPages = forwardResolver( 'getEntityRecords' );\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\n\t\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n\t};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview =\n\t( url ) =>\n\tasync ( { dispatch } ) => {\n\t\ttry {\n\t\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t\t} );\n\t\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t\t} catch {\n\t\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\t\tdispatch.receiveEmbedPreview( url, false );\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string|Object} resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser =\n\t( requestedAction, resource, id ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tif ( ! ALLOWED_RESOURCE_ACTIONS.includes( requestedAction ) ) {\n\t\t\tthrow new Error( `'${ requestedAction }' is not a valid action.` );\n\t\t}\n\n\t\tconst { hasStartedResolution } = registry.select( STORE_NAME );\n\n\t\t// Prevent resolving the same resource twice.\n\t\tfor ( const relatedAction of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\tif ( relatedAction === requestedAction ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isAlreadyResolving = hasStartedResolution( 'canUser', [\n\t\t\t\trelatedAction,\n\t\t\t\tresource,\n\t\t\t\tid,\n\t\t\t] );\n\t\t\tif ( isAlreadyResolving ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tlet resourcePath = null;\n\t\tif ( typeof resource === 'object' ) {\n\t\t\tif ( ! resource.kind || ! resource.name ) {\n\t\t\t\tthrow new Error( 'The entity resource object is not valid.' );\n\t\t\t}\n\n\t\t\tconst configs = await resolveSelect.getEntitiesConfig(\n\t\t\t\tresource.kind\n\t\t\t);\n\t\t\tconst entityConfig = configs.find(\n\t\t\t\t( config ) =>\n\t\t\t\t\tconfig.name === resource.name &&\n\t\t\t\t\tconfig.kind === resource.kind\n\t\t\t);\n\t\t\tif ( ! entityConfig ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tresourcePath =\n\t\t\t\tentityConfig.baseURL + ( resource.id ? '/' + resource.id : '' );\n\t\t} else {\n\t\t\tresourcePath = `/wp/v2/${ resource }` + ( id ? '/' + id : '' );\n\t\t}\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath: resourcePath,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t\tparse: false,\n\t\t\t} );\n\t\t} catch {\n\t\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional chaining operator is used here because the API requests don't\n\t\t// return the expected result in the React native version. Instead, API requests\n\t\t// only return the result, without including response properties like the headers.\n\t\tconst permissions = getUserPermissionsFromAllowHeader(\n\t\t\tresponse.headers?.get( 'allow' )\n\t\t);\n\t\tconst receiveUserPermissionArgs = {};\n\t\tconst canUserResolutionsArgs = [];\n\t\tfor ( const action of ALLOWED_RESOURCE_ACTIONS ) {\n\t\t\treceiveUserPermissionArgs[\n\t\t\t\tgetUserPermissionCacheKey( action, resource, id )\n\t\t\t] = permissions[ action ];\n\n\t\t\t// Mark related action resolutions as finished.\n\t\t\tif ( action !== requestedAction ) {\n\t\t\t\tcanUserResolutionsArgs.push( [ action, resource, id ] );\n\t\t\t}\n\t\t}\n\t\tregistry.batch( () => {\n\t\t\tdispatch.receiveUserPermissions( receiveUserPermissionArgs );\n\t\t\tdispatch.finishResolutions( 'canUser', canUserResolutionsArgs );\n\t\t} );\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} recordId Record's id.\n */\nexport const canUserEditEntityRecord =\n\t( kind, name, recordId ) =>\n\tasync ( { dispatch } ) => {\n\t\tawait dispatch( canUser( 'update', { kind, name, id: recordId } ) );\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves =\n\t( postType, postId ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst {\n\t\t\trest_base: restBase,\n\t\t\trest_namespace: restNamespace = 'wp/v2',\n\t\t\tsupports,\n\t\t} = await resolveSelect.getPostType( postType );\n\t\tif ( ! supports?.autosave ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst autosaves = await apiFetch( {\n\t\t\tpath: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,\n\t\t} );\n\n\t\tif ( autosaves && autosaves.length ) {\n\t\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t\t}\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave =\n\t( postType, postId ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect.getAutosaves( postType, postId );\n\t};\n\nexport const __experimentalGetCurrentGlobalStylesId =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\t\tconst globalStylesURL =\n\t\t\tactiveThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]\n\t\t\t\t?.href;\n\t\tif ( ! globalStylesURL ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Regex matches the ID at the end of a URL or immediately before\n\t\t// the query string.\n\t\tconst matches = globalStylesURL.match( /\\/(\\d+)(?:\\?|$)/ );\n\t\tconst id = matches ? Number( matches[ 1 ] ) : null;\n\n\t\tif ( id ) {\n\t\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId( id );\n\t\t}\n\t};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\t// Please adjust the preloaded requests if this changes!\n\t\tconst themeGlobalStyles = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }?context=view`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tthemeGlobalStyles\n\t\t);\n\t};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\t// Please adjust the preloaded requests if this changes!\n\t\tconst variations = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations?context=view`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tvariations\n\t\t);\n\t};\n\n/**\n * Fetches and returns the revisions of the current global styles theme.\n */\nexport const getCurrentThemeGlobalStylesRevisions =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst globalStylesId =\n\t\t\tawait resolveSelect.__experimentalGetCurrentGlobalStylesId();\n\t\tconst record = globalStylesId\n\t\t\t? await resolveSelect.getEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'globalStyles',\n\t\t\t\t\tglobalStylesId\n\t\t\t )\n\t\t\t: undefined;\n\t\tconst revisionsURL = record?._links?.[ 'version-history' ]?.[ 0 ]?.href;\n\n\t\tif ( revisionsURL ) {\n\t\t\tconst resetRevisions = await apiFetch( {\n\t\t\t\turl: revisionsURL,\n\t\t\t} );\n\t\t\tconst revisions = resetRevisions?.map( ( revision ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( revision ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\t\t\tdispatch.receiveThemeGlobalStyleRevisions(\n\t\t\t\tglobalStylesId,\n\t\t\t\trevisions\n\t\t\t);\n\t\t}\n\t};\n\ngetCurrentThemeGlobalStylesRevisions.shouldInvalidate = ( action ) => {\n\treturn (\n\t\taction.type === 'SAVE_ENTITY_RECORD_FINISH' &&\n\t\taction.kind === 'root' &&\n\t\t! action.error &&\n\t\taction.name === 'globalStyles'\n\t);\n};\n\nexport const getBlockPatterns =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst patterns = await fetchBlockPatterns();\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );\n\t};\n\nexport const getBlockPatternCategories =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst categories = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/categories',\n\t\t} );\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', categories } );\n\t};\n\nexport const getUserPatternCategories =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst patternCategories = await resolveSelect.getEntityRecords(\n\t\t\t'taxonomy',\n\t\t\t'wp_pattern_category',\n\t\t\t{\n\t\t\t\tper_page: -1,\n\t\t\t\t_fields: 'id,name,description,slug',\n\t\t\t\tcontext: 'view',\n\t\t\t}\n\t\t);\n\n\t\tconst mappedPatternCategories =\n\t\t\tpatternCategories?.map( ( userCategory ) => ( {\n\t\t\t\t...userCategory,\n\t\t\t\tlabel: decodeEntities( userCategory.name ),\n\t\t\t\tname: userCategory.slug,\n\t\t\t} ) ) || [];\n\n\t\tdispatch( {\n\t\t\ttype: 'RECEIVE_USER_PATTERN_CATEGORIES',\n\t\t\tpatternCategories: mappedPatternCategories,\n\t\t} );\n\t};\n\nexport const getNavigationFallbackId =\n\t() =>\n\tasync ( { dispatch, select, registry } ) => {\n\t\tconst fallback = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {\n\t\t\t\t_embed: true,\n\t\t\t} ),\n\t\t} );\n\n\t\tconst record = fallback?._embedded?.self;\n\n\t\tregistry.batch( () => {\n\t\t\tdispatch.receiveNavigationFallbackId( fallback?.id );\n\n\t\t\tif ( ! record ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the fallback is already in the store, don't invalidate navigation queries.\n\t\t\t// Otherwise, invalidate the cache for the scenario where there were no Navigation\n\t\t\t// posts in the state and the fallback created one.\n\t\t\tconst existingFallbackEntityRecord = select.getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tfallback.id\n\t\t\t);\n\t\t\tconst invalidateNavigationQueries = ! existingFallbackEntityRecord;\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\trecord,\n\t\t\t\tundefined,\n\t\t\t\tinvalidateNavigationQueries\n\t\t\t);\n\n\t\t\t// Resolve to avoid further network requests.\n\t\t\tdispatch.finishResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tfallback.id,\n\t\t\t] );\n\t\t} );\n\t};\n\nexport const getDefaultTemplateId =\n\t( query ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tconst template = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', query ),\n\t\t} );\n\t\t// Wait for the the entities config to be loaded, otherwise receiving\n\t\t// the template as an entity will not work.\n\t\tawait resolveSelect.getEntitiesConfig( 'postType' );\n\t\t// When active_templates experiment is enabled, use numeric wp_id if it\n\t\t// exists, otherwise fall back to string ID format (theme//slug) as the\n\t\t// frontend expects string IDs for templates.\n\t\tconst id = window?.__experimentalTemplateActivate\n\t\t\t? template?.wp_id || template?.id\n\t\t\t: template?.id;\n\n\t\tregistry.batch( () => {\n\t\t\tdispatch.receiveDefaultTemplateId( query, id || '' );\n\t\t\t// Endpoint may return an empty object if no template is found.\n\t\t\tif ( id ) {\n\t\t\t\ttemplate.id = id;\n\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\ttemplate\n\t\t\t\t);\n\t\t\t\t// Avoid further network requests.\n\t\t\t\tdispatch.finishResolution( 'getEntityRecord', [\n\t\t\t\t\t'postType',\n\t\t\t\t\ttemplate.type,\n\t\t\t\t\tid,\n\t\t\t\t] );\n\t\t\t}\n\t\t} );\n\t};\n\ngetDefaultTemplateId.shouldInvalidate = ( action ) => {\n\t// Only invalidate on real saves; `persistedEdits` is absent on\n\t// initial fetches so the kickoff's own site read doesn't wipe\n\t// the just-resolved template id.\n\treturn (\n\t\taction.type === 'RECEIVE_ITEMS' &&\n\t\taction.kind === 'root' &&\n\t\taction.name === 'site' &&\n\t\t!! action.persistedEdits\n\t);\n};\n\n/**\n * Requests an entity's revisions from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getRevisions =\n\t( kind, name, recordKey, query = {} ) =>\n\tasync ( { dispatch, registry, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst rawQuery = { ...query };\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordKey, 'revisions' ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.revisionKey || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.getRevisionsUrl( recordKey ),\n\t\t\t\tquery\n\t\t\t);\n\n\t\t\tlet records, response;\n\t\t\tconst meta = {};\n\t\t\tconst isPaginated =\n\t\t\t\tentityConfig.supportsPagination && query.per_page !== -1;\n\t\t\ttry {\n\t\t\t\tresponse = await apiFetch( { path, parse: ! isPaginated } );\n\t\t\t} catch {\n\t\t\t\t// Do nothing if our request comes back with an API error.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( response ) {\n\t\t\t\tif ( isPaginated ) {\n\t\t\t\t\trecords = Object.values( await response.json() );\n\t\t\t\t\tmeta.totalItems = parseInt(\n\t\t\t\t\t\tresponse.headers.get( 'X-WP-Total' )\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\trecords = Object.values( response );\n\t\t\t\t}\n\n\t\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t\t// explicitly set these fields as \"undefined\"\n\t\t\t\t// that way we consider the query \"fulfilled\".\n\t\t\t\tif ( query._fields ) {\n\t\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\n\t\t\t\t\t\treturn record;\n\t\t\t\t\t} );\n\t\t\t\t}\n\n\t\t\t\tregistry.batch( () => {\n\t\t\t\t\tdispatch.receiveRevisions(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\trecordKey,\n\t\t\t\t\t\trecords,\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tfalse,\n\t\t\t\t\t\tmeta\n\t\t\t\t\t);\n\n\t\t\t\t\t// Mark individual getRevision resolutions as done so that\n\t\t\t\t\t// subsequent getRevision calls skip redundant API fetches.\n\t\t\t\t\tconst key = entityConfig.revisionKey || DEFAULT_ENTITY_KEY;\n\t\t\t\t\tconst normalizedQuery =\n\t\t\t\t\t\tnormalizeQueryForResolution( rawQuery );\n\t\t\t\t\tconst resolutionsArgs = records\n\t\t\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t\t\t.map( ( record ) => [\n\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\trecordKey,\n\t\t\t\t\t\t\trecord[ key ],\n\t\t\t\t\t\t\tnormalizedQuery,\n\t\t\t\t\t\t] );\n\n\t\t\t\t\tdispatch.finishResolutions(\n\t\t\t\t\t\t'getRevision',\n\t\t\t\t\t\tresolutionsArgs\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n// Invalidate cache when a new revision is created.\ngetRevisions.shouldInvalidate = ( action, kind, name, recordKey ) =>\n\taction.type === 'SAVE_ENTITY_RECORD_FINISH' &&\n\tname === action.name &&\n\tkind === action.kind &&\n\t! action.error &&\n\trecordKey === action.recordId;\n\n/**\n * Requests a specific Entity revision from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.\n * @param {number|string} revisionKey The revision's key.\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getRevision =\n\t( kind, name, recordKey, revisionKey, query ) =>\n\tasync ( { select, dispatch, resolveSelect } ) => {\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: [\n\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\tentityConfig.revisionKey || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t] ),\n\t\t\t\t].join(),\n\t\t\t};\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[\n\t\t\t\t'entities',\n\t\t\t\t'records',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordKey,\n\t\t\t\t'revisions',\n\t\t\t\trevisionKey,\n\t\t\t],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif (\n\t\t\t\tselect.hasRevision( kind, name, recordKey, revisionKey, query )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.getRevisionsUrl( recordKey, revisionKey ),\n\t\t\t\tquery\n\t\t\t);\n\n\t\t\tlet record;\n\t\t\ttry {\n\t\t\t\trecord = await apiFetch( { path } );\n\t\t\t} catch {\n\t\t\t\t// Do nothing if our request comes back with an API error.\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( record ) {\n\t\t\t\tdispatch.receiveRevisions(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordKey,\n\t\t\t\t\trecord,\n\t\t\t\t\tquery\n\t\t\t\t);\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Requests a specific post type options from the REST API.\n *\n * @param {string} postType Post type slug.\n */\nexport const getRegisteredPostMeta =\n\t( postType ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tlet options;\n\t\ttry {\n\t\t\tconst {\n\t\t\t\trest_namespace: restNamespace = 'wp/v2',\n\t\t\t\trest_base: restBase,\n\t\t\t} = ( await resolveSelect.getPostType( postType ) ) || {};\n\t\t\toptions = await apiFetch( {\n\t\t\t\tpath: `${ restNamespace }/${ restBase }/?context=edit`,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t} );\n\t\t} catch {\n\t\t\t// Do nothing if the request comes back with an API error.\n\t\t\treturn;\n\t\t}\n\n\t\tif ( options ) {\n\t\t\tdispatch.receiveRegisteredPostMeta(\n\t\t\t\tpostType,\n\t\t\t\toptions?.schema?.properties?.meta?.properties\n\t\t\t);\n\t\t}\n\t};\n\n/**\n * Requests entity configs for the given kind from the REST API.\n *\n * @param {string} kind Entity kind.\n */\nexport const getEntitiesConfig =\n\t( kind ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst loader = additionalEntityConfigLoaders.find(\n\t\t\t( l ) => l.kind === kind\n\t\t);\n\n\t\tif ( ! loader ) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst configs = await loader.loadEntities();\n\t\t\tif ( ! configs.length ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tdispatch.addEntities( configs );\n\t\t} catch {\n\t\t\t// Do nothing if the request comes back with an API error.\n\t\t}\n\t};\n\n/**\n * Requests editor settings from the REST API.\n */\nexport const getEditorSettings =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst settings = await apiFetch( {\n\t\t\tpath: '/wp-block-editor/v1/settings',\n\t\t} );\n\t\tdispatch.receiveEditorSettings( settings );\n\t};\n\n/**\n * Requests editor assets from the REST API.\n */\nexport const getEditorAssets =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst assets = await apiFetch( {\n\t\t\tpath: '/wp-block-editor/v1/assets',\n\t\t} );\n\t\tdispatch.receiveEditorAssets( assets );\n\t};\n\n/**\n * Requests view config for a given entity type from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {?Object} options Optional options.\n * @param {?string[]} options.fields Optional subset of top-level config\n * properties to request, mapped to the REST\n * API `_fields` parameter. When omitted, the\n * full config is requested.\n */\nexport const getViewConfig =\n\t( kind, name, options = {} ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst query = { kind, name };\n\t\tconst fields = getNormalizedCommaSeparable( options.fields );\n\t\tif ( fields?.length ) {\n\t\t\tquery._fields = fields.join( ',' );\n\t\t}\n\t\tconst config = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp/v2/view-config', query ),\n\t\t} );\n\t\tdispatch.receiveViewConfig( kind, name, config );\n\t};\n"],
5
+ "mappings": ";AAGA,SAAS,iBAAiB;AAK1B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,OAAO,cAAc;AAKrB,SAAS,kBAAkB;AAC3B,SAAS,+BAA+B,0BAA0B;AAClE,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,0BAA0B;AACnC,SAAS,kBAAkB,2BAA2B;AACtD,SAAS,mBAAmB,mBAAmB;AAQxC,IAAM,aACZ,CAAE,UACF,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,OAAO;AAAA,IACZ;AAAA,IACA;AAAA,EACD;AACA,QAAM,QAAQ,MAAM,SAAU,EAAE,KAAK,CAAE;AACvC,WAAS,iBAAkB,MAAM,KAAM;AACxC;AAKM,IAAM,iBACZ,MACA,OAAQ,EAAE,SAAS,MAAO;AACzB,QAAM,cAAc,MAAM,SAAU,EAAE,MAAM,kBAAkB,CAAE;AAChE,WAAS,mBAAoB,WAA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,WAAS,kBAAmB,MAAM,MAAM,MAAO;AAChD;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,20 @@
1
+ // packages/core-data/src/utils/clear-unchanged-edits.ts
2
+ import fastDeepEqual from "fast-deep-equal/es6/index.js";
3
+ function clearUnchangedEdits(edits, persistedRecord) {
4
+ if (!persistedRecord) {
5
+ return edits;
6
+ }
7
+ return Object.fromEntries(
8
+ Object.entries(edits).map(([key, value]) => {
9
+ const persisted = persistedRecord[key]?.raw ?? persistedRecord[key];
10
+ return [
11
+ key,
12
+ fastDeepEqual(value, persisted) ? void 0 : value
13
+ ];
14
+ })
15
+ );
16
+ }
17
+ export {
18
+ clearUnchangedEdits as default
19
+ };
20
+ //# sourceMappingURL=clear-unchanged-edits.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/clear-unchanged-edits.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6/index.js';\n\n/**\n * Returns a copy of `edits` where any value equal to its persisted counterpart\n * is set to `undefined`. The edits reducer treats `undefined` as a signal to\n * drop the edit, so the property is no longer considered dirty.\n *\n * @param edits Edits keyed by property name.\n * @param persistedRecord Persisted entity record to compare against.\n *\n * @return Edits with unchanged properties set to `undefined`.\n */\nexport default function clearUnchangedEdits(\n\tedits: Record< string, unknown >,\n\tpersistedRecord: Record< string, any > | undefined\n): Record< string, unknown > {\n\tif ( ! persistedRecord ) {\n\t\treturn edits;\n\t}\n\n\treturn Object.fromEntries(\n\t\tObject.entries( edits ).map( ( [ key, value ] ) => {\n\t\t\tconst persisted =\n\t\t\t\tpersistedRecord[ key ]?.raw ?? persistedRecord[ key ];\n\t\t\treturn [\n\t\t\t\tkey,\n\t\t\t\tfastDeepEqual( value, persisted ) ? undefined : value,\n\t\t\t];\n\t\t} )\n\t);\n}\n"],
5
+ "mappings": ";AAGA,OAAO,mBAAmB;AAYX,SAAR,oBACN,OACA,iBAC4B;AAC5B,MAAK,CAAE,iBAAkB;AACxB,WAAO;AAAA,EACR;AAEA,SAAO,OAAO;AAAA,IACb,OAAO,QAAS,KAAM,EAAE,IAAK,CAAE,CAAE,KAAK,KAAM,MAAO;AAClD,YAAM,YACL,gBAAiB,GAAI,GAAG,OAAO,gBAAiB,GAAI;AACrD,aAAO;AAAA,QACN;AAAA,QACA,cAAe,OAAO,SAAU,IAAI,SAAY;AAAA,MACjD;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
+ "names": []
7
+ }
@@ -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 { getBlockTypes } from '@wordpress/blocks';\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tasRichTextOffset,\n\tcreateYMap,\n\trichTextOffsetToHtmlIndex,\n\ttype HtmlStringIndex,\n\ttype YMapRecord,\n\ttype YMapWrap,\n} from './crdt-utils';\nimport { getCachedRichTextData } from './crdt-text';\nimport { Delta } from '../sync';\nimport { type WPBlockSelection } from '../types';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockAttributeSchema {\n\trole?: string;\n\ttype?: string;\n\tquery?: Record< string, BlockAttributeSchema >;\n}\n\ninterface BlockType {\n\tattributes?: Record< string, BlockAttributeSchema >;\n\tname: 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).\nexport interface 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\ninterface MergeCrdtBlocksOptions {\n\tpreserveClientIds?: boolean;\n}\n\n/**\n * Optional description of where a cursor falls.\n *\n * Used to coordinate shifting of cursor when applying changes\n * to a Y.Doc with RichText instances.\n */\nexport type MergeCursorPosition = WPBlockSelection | null;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\n/**\n * Recursively walk an attribute value and convert any RichTextData instances\n * to their string (HTML) representation. This is necessary for array-type and\n * object-type attributes, which can contain nested RichTextData.\n *\n * @param value The attribute value to serialize.\n * @return The value with all RichTextData instances replaced by strings.\n */\nfunction serializeAttributeValue( value: unknown ): unknown {\n\tif ( value instanceof RichTextData ) {\n\t\treturn value.valueOf();\n\t}\n\n\t// e.g. core/table `body`: [ { cells: [ { content: RichTextData } ] } ]\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.map( serializeAttributeValue );\n\t}\n\n\t// e.g. a single row inside core/table `body`: { cells: [ ... ] }\n\tif ( value && typeof value === 'object' ) {\n\t\tconst result: Record< string, unknown > = {};\n\n\t\tfor ( const [ k, v ] of Object.entries( value ) ) {\n\t\t\tresult[ k ] = serializeAttributeValue( v );\n\t\t}\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\nfunction makeBlockAttributesSerializable(\n\tblockName: string,\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( isLocalAttribute( blockName, key ) ) {\n\t\t\tdelete newAttributes[ key ];\n\t\t\tcontinue;\n\t\t}\n\n\t\tnewAttributes[ key ] = serializeAttributeValue( value );\n\t}\n\treturn newAttributes;\n}\n\n/**\n * Recursively removes properties which cannot be serialized from a list of block objects.\n *\n * @param blocks Eemove unserializable properties from each block object in this set.\n * @return Copies of the provided blocks without the unserializable properties.\n */\nfunction makeBlocksSerializable( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst {\n\t\t\tname,\n\t\t\tinnerBlocks,\n\t\t\tattributes,\n\t\t\t/*\n\t\t\t * Any validation issues discovered when loading a block are appended\n\t\t\t * to the block node with a logging function, which cannot be serialized.\n\t\t\t *\n\t\t\t * @see import(\"@wordpress/blocks/src/api/parser\").parseRawBlock()\n\t\t\t */\n\t\t\tvalidationIssues,\n\t\t\t...rest\n\t\t} = block;\n\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( name, attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * Recursively walk an attribute value and convert any strings that correspond\n * to rich-text schema nodes into RichTextData instances. This is the inverse\n * of serializeAttributeValue and handles nested structures like table cells.\n *\n * @param schema The attribute type definition for this value.\n * @param value The attribute value from CRDT (toJSON).\n * @return The value with rich-text strings replaced by RichTextData.\n */\nfunction deserializeAttributeValue(\n\tschema: BlockAttributeSchema | undefined,\n\tvalue: unknown\n): unknown {\n\tif ( schema?.type === 'rich-text' && typeof value === 'string' ) {\n\t\treturn getCachedRichTextData( value );\n\t}\n\n\t// e.g. core/table `body`: [ { cells: [ { content: RichTextData } ] } ]\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.map( ( item ) =>\n\t\t\tdeserializeAttributeValue( schema, item )\n\t\t);\n\t}\n\n\t// e.g. a single row inside core/table `body`: { cells: [ ... ] }\n\tif ( value && typeof value === 'object' ) {\n\t\tconst result: Record< string, unknown > = {};\n\n\t\tfor ( const [ key, innerValue ] of Object.entries(\n\t\t\tvalue as Record< string, unknown >\n\t\t) ) {\n\t\t\tresult[ key ] = deserializeAttributeValue(\n\t\t\t\tschema?.query?.[ key ],\n\t\t\t\tinnerValue\n\t\t\t);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\n/**\n * Convert blocks from their CRDT-serialized form back to the runtime form\n * expected by the block editor. Rich-text attributes are stored as Y.Text in\n * the CRDT document, which serializes to plain strings via toJSON(). This\n * function restores them to RichTextData instances so that block edit\n * components that rely on RichTextData methods (e.g. `.text`) work correctly.\n *\n * @param blocks Blocks as extracted from the CRDT document via toJSON().\n * @return Blocks with rich-text attributes restored to RichTextData.\n */\nexport function deserializeBlockAttributes( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst { name, innerBlocks, attributes, ...rest } = block;\n\n\t\tconst newAttributes = { ...attributes };\n\n\t\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\t\tconst schema = getBlockAttributeSchema( name, key );\n\n\t\t\tif ( schema ) {\n\t\t\t\tnewAttributes[ key ] = deserializeAttributeValue(\n\t\t\t\t\tschema,\n\t\t\t\t\tvalue\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: newAttributes,\n\t\t\tinnerBlocks: deserializeBlockAttributes( 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 | Y.Array< unknown > | Y.Map< unknown > | unknown {\n\tconst schema = getBlockAttributeSchema( blockName, attributeName );\n\treturn createYValueFromSchema( schema, attributeValue );\n}\n\n/**\n * Recursively create the appropriate Y.js type for a value based on its\n * block-attribute schema.\n *\n * - `rich-text` -> Y.Text\n * - `array` with query -> Y.Array of Y.Maps\n * - `object` with query -> Y.Map\n * - anything else -> plain value (unchanged)\n *\n * @param schema The attribute type definition.\n * @param value The plain JS value to convert.\n * @return A Y.js type or the original value.\n */\nfunction createYValueFromSchema(\n\tschema: BlockAttributeSchema | undefined,\n\tvalue: unknown\n): Y.Text | Y.Array< unknown > | Y.Map< unknown > | unknown {\n\tif ( ! schema ) {\n\t\treturn value;\n\t}\n\n\tif ( schema.type === 'rich-text' ) {\n\t\treturn new Y.Text( value?.toString() ?? '' );\n\t}\n\n\tif ( schema.type === 'array' && schema.query && Array.isArray( value ) ) {\n\t\tconst query = schema.query;\n\t\tconst yArray = new Y.Array< Y.Map< unknown > >();\n\n\t\tyArray.insert(\n\t\t\t0,\n\t\t\tvalue.map( ( item ) => createYMapFromQuery( query, item ) )\n\t\t);\n\n\t\treturn yArray;\n\t}\n\n\tif ( schema.type === 'object' && schema.query && isRecord( value ) ) {\n\t\treturn createYMapFromQuery( schema.query, value );\n\t}\n\n\treturn value;\n}\n\n/**\n * Type guard that narrows `unknown` to `Record< string, unknown >`.\n *\n * @param value Value to check.\n * @return True if `value` is a non-null, non-array object.\n */\nfunction isRecord( value: unknown ): value is Record< string, unknown > {\n\treturn !! value && typeof value === 'object' && ! Array.isArray( value );\n}\n\n/**\n * Create a Y.Map from a plain object, using a query schema to decide which\n * properties should become nested Y.js types (Y.Text, Y.Array, Y.Map).\n *\n * @param query The query schema defining the properties.\n * @param obj The plain object to convert.\n * @return A Y.Map with typed values.\n */\nfunction createYMapFromQuery(\n\tquery: Record< string, BlockAttributeSchema >,\n\tobj: unknown\n): Y.Map< unknown > {\n\tif ( ! isRecord( obj ) ) {\n\t\treturn new Y.Map();\n\t}\n\n\tconst entries: [ string, unknown ][] = Object.entries( obj ).map(\n\t\t( [ key, val ] ): [ string, unknown ] => {\n\t\t\tconst subSchema = query[ key ];\n\t\t\treturn [ key, createYValueFromSchema( subSchema, val ) ];\n\t\t}\n\t);\n\n\treturn new Y.Map( entries );\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 attributeCursor When provided, describes a selection cursor falling within a\n * RichText field associated with a specific block and attribute.\n * Derived from the changes that produced the blocks.\n * @param options Optional settings for the merge operation.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tattributeCursor: MergeCursorPosition,\n\toptions: MergeCrdtBlocksOptions = {}\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\n\tconst incomingBlocksToSync =\n\t\tserializableBlocksCache.get( incomingBlocks ) ?? [];\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\tincomingBlocksToSync.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( incomingBlocksToSync[ 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\tincomingBlocksToSync[ incomingBlocksToSync.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\tincomingBlocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - incomingBlocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst incomingYBlock = incomingBlocksToSync[ left ];\n\t\tconst localYBlock = yblocks.get( left );\n\n\t\tObject.entries( incomingYBlock ).forEach(\n\t\t\t( [ incomingBlockProperty, incomingBlockPropertyValue ] ) => {\n\t\t\t\tswitch ( incomingBlockProperty ) {\n\t\t\t\t\tcase 'attributes': {\n\t\t\t\t\t\tconst localAttributes = localYBlock.get(\n\t\t\t\t\t\t\tincomingBlockProperty\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst incomingAttributes = incomingBlockPropertyValue;\n\n\t\t\t\t\t\t// When the local block has no attributes, adopt the incoming set.\n\t\t\t\t\t\tif ( ! localAttributes ) {\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tcreateNewYAttributeMap(\n\t\t\t\t\t\t\t\t\tincomingYBlock.name,\n\t\t\t\t\t\t\t\t\tincomingAttributes\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Otherwise the attributes need to be merged.\n\t\t\t\t\t\tObject.entries( incomingAttributes ).forEach(\n\t\t\t\t\t\t\t( [\n\t\t\t\t\t\t\t\tincomingAttributeName,\n\t\t\t\t\t\t\t\tincomingAttributeValue,\n\t\t\t\t\t\t\t] ) => {\n\t\t\t\t\t\t\t\tconst currentAttribute = localAttributes?.get(\n\t\t\t\t\t\t\t\t\tincomingAttributeName\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tconst isExpectedType = isExpectedAttributeType(\n\t\t\t\t\t\t\t\t\tincomingYBlock.name,\n\t\t\t\t\t\t\t\t\tincomingAttributeName,\n\t\t\t\t\t\t\t\t\tcurrentAttribute\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Y types (Y.Text, Y.Array, Y.Map) cannot be\n\t\t\t\t\t\t\t\t// compared with fastDeepEqual against plain values.\n\t\t\t\t\t\t\t\t// Delegate to mergeYValue which handles no-op\n\t\t\t\t\t\t\t\t// detection at the edges.\n\t\t\t\t\t\t\t\tconst isYType =\n\t\t\t\t\t\t\t\t\tcurrentAttribute instanceof Y.AbstractType;\n\n\t\t\t\t\t\t\t\tconst isAttributeChanged =\n\t\t\t\t\t\t\t\t\t! isExpectedType ||\n\t\t\t\t\t\t\t\t\tisYType ||\n\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\tcurrentAttribute,\n\t\t\t\t\t\t\t\t\t\tincomingAttributeValue\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif ( isAttributeChanged ) {\n\t\t\t\t\t\t\t\t\tupdateYBlockAttribute(\n\t\t\t\t\t\t\t\t\t\tincomingYBlock.name,\n\t\t\t\t\t\t\t\t\t\tincomingYBlock.clientId,\n\t\t\t\t\t\t\t\t\t\tincomingAttributeName,\n\t\t\t\t\t\t\t\t\t\tincomingAttributeValue,\n\t\t\t\t\t\t\t\t\t\tlocalAttributes,\n\t\t\t\t\t\t\t\t\t\tattributeCursor\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\n\t\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\t\tlocalAttributes.forEach(\n\t\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! incomingBlockPropertyValue.hasOwnProperty(\n\t\t\t\t\t\t\t\t\t\tattrName\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\t\tlocalAttributes.delete( attrName );\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\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\t\tlet yInnerBlocks = localYBlock.get(\n\t\t\t\t\t\t\tincomingBlockProperty\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( ! ( yInnerBlocks instanceof Y.Array ) ) {\n\t\t\t\t\t\t\tyInnerBlocks = new Y.Array< YBlock >();\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tyInnerBlocks\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tmergeCrdtBlocks(\n\t\t\t\t\t\t\tyInnerBlocks,\n\t\t\t\t\t\t\tincomingBlockPropertyValue ?? [],\n\t\t\t\t\t\t\tattributeCursor,\n\t\t\t\t\t\t\toptions\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\tcase 'clientId': {\n\t\t\t\t\t\t// Code Editor changes reparse raw HTML on every\n\t\t\t\t\t\t// keystroke and regenerate fresh clientIds. Keep Y.Doc\n\t\t\t\t\t\t// clientIds stable for the code editor so peers do not\n\t\t\t\t\t\t// remount unchanged blocks on every edit.\n\t\t\t\t\t\tif ( options.preserveClientIds ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Otherwise, accept new clientIds from updates\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tincomingBlockPropertyValue !==\n\t\t\t\t\t\t\tlocalYBlock.get( incomingBlockProperty )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tincomingBlockPropertyValue\n\t\t\t\t\t\t\t);\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\tdefault:\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\tincomingYBlock[ incomingBlockProperty ],\n\t\t\t\t\t\t\t\tlocalYBlock.get( incomingBlockProperty )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tincomingBlockPropertyValue\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\tlocalYBlock.forEach( ( _v, k ) => {\n\t\t\tif ( ! incomingYBlock.hasOwnProperty( k ) ) {\n\t\t\t\tlocalYBlock.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( incomingBlocksToSync[ 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 * Compare a plain array element against a Y.Map element for equality.\n * Used by the left-right sweep diff in mergeYArray.\n *\n * @param newElement The plain object from the incoming array.\n * @param yElement The Y.Map element from the existing Y.Array.\n * @return True if the elements are deeply equal.\n */\nfunction areArrayElementsEqual(\n\tnewElement: unknown,\n\tyElement: unknown\n): boolean {\n\tif ( yElement instanceof Y.Map && isRecord( newElement ) ) {\n\t\treturn fastDeepEqual( newElement, yElement.toJSON() );\n\t}\n\n\treturn fastDeepEqual( newElement, yElement );\n}\n\n/**\n * Merge an incoming plain array into an existing Y.Array in-place.\n *\n * Uses the same left-right sweep diff approach as mergeCrdtBlocks:\n * equal elements are skipped from both ends, then the middle section\n * is updated, deleted, or inserted as needed. This preserves existing\n * Y.Map/Y.Text objects for unchanged elements, so concurrent edits\n * to those elements are not lost.\n *\n * @param yArray The existing Y.Array to update.\n * @param newValue The new plain array to merge into the Y.Array.\n * @param schema The attribute schema (must have `query`).\n * @param cursorPosition The local cursor position for rich-text delta merges.\n * @param cursorScope The selected block attribute scope for rich-text cursor hints.\n */\nfunction mergeYArray(\n\tyArray: Y.Array< unknown >,\n\tnewValue: unknown[],\n\tschema: BlockAttributeSchema,\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope\n): void {\n\tif ( ! schema.query ) {\n\t\treturn;\n\t}\n\n\tconst query = schema.query;\n\tconst numOfCommonEntries = Math.min( newValue.length, yArray.length );\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// Skip equal elements from left.\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareArrayElementsEqual( newValue[ left ], yArray.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// Skip equal elements from right.\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareArrayElementsEqual(\n\t\t\tnewValue[ newValue.length - right - 1 ],\n\t\t\tyArray.get( yArray.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// Updates: merge changed elements in-place.\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++ ) {\n\t\tconst currentElement = yArray.get( left + i );\n\t\tconst newElement = newValue[ left + i ];\n\n\t\tif ( currentElement instanceof Y.Map && isRecord( newElement ) ) {\n\t\t\tmergeYMapValues(\n\t\t\t\tcurrentElement,\n\t\t\t\tnewElement,\n\t\t\t\tquery,\n\t\t\t\tcursorPosition,\n\t\t\t\tcursorScope\n\t\t\t);\n\t\t} else {\n\t\t\t// Element is the wrong type (e.g. partial migration) or the\n\t\t\t// incoming value is not an object. Rebuild the entire array.\n\t\t\tyArray.delete( 0, yArray.length );\n\t\t\tyArray.insert(\n\t\t\t\t0,\n\t\t\t\tnewValue.map( ( item ) => createYMapFromQuery( query, item ) )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Deletes.\n\tconst numOfDeletionsNeeded = Math.max( 0, yArray.length - newValue.length );\n\n\tif ( numOfDeletionsNeeded > 0 ) {\n\t\tyArray.delete( left + numOfUpdatesNeeded, numOfDeletionsNeeded );\n\t}\n\n\t// Inserts.\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tnewValue.length - yArray.length\n\t);\n\n\tif ( numOfInsertionsNeeded > 0 ) {\n\t\tconst insertAt = left + numOfUpdatesNeeded;\n\t\tconst itemsToInsert: Y.Map< unknown >[] = new Array(\n\t\t\tnumOfInsertionsNeeded\n\t\t);\n\n\t\tfor ( let i = 0; i < numOfInsertionsNeeded; i++ ) {\n\t\t\titemsToInsert[ i ] = createYMapFromQuery(\n\t\t\t\tquery,\n\t\t\t\tnewValue[ insertAt + i ]\n\t\t\t);\n\t\t}\n\n\t\tyArray.insert( insertAt, itemsToInsert );\n\t}\n}\n\n/**\n * Merge a single value into a Y.Map entry, using the attribute schema to\n * decide how to merge.\n *\n * If the current value is already a matching Y.js type (Y.Text, Y.Array,\n * Y.Map), the update is merged in-place so concurrent edits are preserved.\n * Otherwise the value is replaced wholesale.\n *\n * @param schema The attribute type definition for this value.\n * @param newVal The new value to merge into the Y.Map entry.\n * @param yMap The Y.Map that owns this entry.\n * @param key The key of this entry in the Y.Map.\n * @param cursorPosition The cursor position for rich-text delta merges from the updated value.\n * @param cursorScope Indicates a specific block and attribute associated with the editor;\n * determines whether the cursor should be updated based on the change.\n */\nfunction mergeYValue(\n\tschema: BlockAttributeSchema | undefined,\n\tnewVal: unknown,\n\tyMap: Y.Map< unknown >,\n\tkey: string,\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope\n): void {\n\tconst currentVal = yMap.get( key );\n\tif (\n\t\tschema?.type === 'rich-text' &&\n\t\ttypeof newVal === 'string' &&\n\t\tcurrentVal instanceof Y.Text\n\t) {\n\t\tmergeRichTextUpdate(\n\t\t\tcurrentVal,\n\t\t\tnewVal,\n\t\t\tresolveRichTextCursorPosition( cursorPosition, cursorScope, newVal )\n\t\t);\n\t} else if (\n\t\tschema?.type === 'array' &&\n\t\tschema.query &&\n\t\tArray.isArray( newVal ) &&\n\t\tcurrentVal instanceof Y.Array\n\t) {\n\t\tmergeYArray( currentVal, newVal, schema, cursorPosition, cursorScope );\n\t} else if (\n\t\tschema?.type === 'object' &&\n\t\tschema.query &&\n\t\tisRecord( newVal ) &&\n\t\tcurrentVal instanceof Y.Map\n\t) {\n\t\tmergeYMapValues(\n\t\t\tcurrentVal,\n\t\t\tnewVal,\n\t\t\tschema.query,\n\t\t\tcursorPosition,\n\t\t\tcursorScope\n\t\t);\n\t} else {\n\t\tconst newYValue = createYValueFromSchema( schema, newVal );\n\n\t\t// If createYValueFromSchema wrapped the value into a Y type, the\n\t\t// current value is the wrong type and needs upgrading. Otherwise,\n\t\t// only replace if the raw value actually changed.\n\t\tif ( newYValue !== newVal || ! fastDeepEqual( currentVal, newVal ) ) {\n\t\t\tyMap.set( key, newYValue );\n\t\t}\n\t}\n}\n\n/**\n * Merge an incoming plain object into an existing Y.Map in-place, using\n * the query schema to decide how each property should be merged.\n *\n * Properties present in the Y.Map but absent from `newObj` are deleted.\n *\n * @param yMap The existing Y.Map to update.\n * @param newObj The new plain object to merge into the Y.Map.\n * @param query The query schema defining property types.\n * @param cursorPosition The local cursor position for rich-text delta merges.\n * @param cursorScope The selected block attribute scope for rich-text cursor hints.\n */\nfunction mergeYMapValues(\n\tyMap: Y.Map< unknown >,\n\tnewObj: Record< string, unknown >,\n\tquery: Record< string, BlockAttributeSchema >,\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope\n): void {\n\tfor ( const [ key, newVal ] of Object.entries( newObj ) ) {\n\t\tmergeYValue(\n\t\t\tquery[ key ],\n\t\t\tnewVal,\n\t\t\tyMap,\n\t\t\tkey,\n\t\t\tcursorPosition,\n\t\t\tcursorScope\n\t\t);\n\t}\n\n\t// Delete properties absent from the incoming object.\n\tfor ( const key of yMap.keys() ) {\n\t\tif ( ! Object.hasOwn( newObj, key ) ) {\n\t\t\tyMap.delete( key );\n\t\t}\n\t}\n}\n\n/**\n * Update a single attribute on a Yjs block attributes map (currentAttributes).\n *\n * @param blockName The block type name, e.g. 'core/paragraph'.\n * @param clientId The local clientId for the block being merged.\n * @param attributeName The name of the attribute to update, e.g. 'content'.\n * @param attributeValue The new value for the attribute.\n * @param currentAttributes The Y.Map holding the block's current attributes.\n * @param newCursorPosition The cursor position for rich-text delta merges from the updated value.\n * Notably, this may not correspond to the attribute being edited and is\n * used to determine if any cursors need shifting in response to the change.\n */\nfunction updateYBlockAttribute(\n\tblockName: string,\n\tclientId: string | undefined,\n\tattributeName: string,\n\tattributeValue: unknown,\n\tcurrentAttributes: YBlockAttributes,\n\tnewCursorPosition: MergeCursorPosition\n): void {\n\tconst schema = getBlockAttributeSchema( blockName, attributeName );\n\n\t/*\n\t * @todo There is a slight discrepancy between the attribute name and key, which might\n\t * show up when working with multiline RichText instances (of which there are no\n\t * more within Core). For those instances, a cursor might never be updated in\n\t * response to changes because its `attributeKey` won\u2019t match any of the block\u2019s\n\t * attribute names, and since updating this attribute is based on the block names,\n\t * no suitable key for the cursor scope will be created. To fix, the updating code\n\t * would need to parse multiline attributes and infer the `attributeKey` being updated.\n\t */\n\tmergeYValue(\n\t\tschema,\n\t\tattributeValue,\n\t\tcurrentAttributes,\n\t\tattributeName,\n\t\tnewCursorPosition,\n\t\t{ attributeKey: attributeName, clientId }\n\t);\n}\n\n/**\n * References the specific block and attribute associated with a RichText component.\n *\n * This is used to associate a cursor with the attribute it\u2019s editing.\n *\n * @see WPBlockSelection\n */\ninterface RichTextCursorScope {\n\tattributeKey: string;\n\tclientId: string | undefined;\n}\n\ninterface DeltaWithOps {\n\tops: Parameters< Y.Text[ 'applyDelta' ] >[ 0 ];\n}\n\n/**\n * When the provided cursor falls within the given block and attribute\u2019s scope,\n * returns an index into the RichText\u2019s serialized HTML where the cursor falls.\n *\n * The cursor scope constrains resolution to ensure that indices are only reported\n * when a cursor falls within the block and attribute being updated, since the\n * attributes being updated may not always be the ones where a cursor presently falls.\n *\n * Returned index measures JS string lengths, thus is counted in UTF-16 code units\n * and contains the syntax characters making up HTML tags, comments, character\n * references, and other non-plaintext content.\n *\n * @param cursorPosition Description of the cursor in the new value.\n * @param cursorScope Cursors should only be updated if they fall within this\n * specific block and attribute.\n * @param updatedValue New RichText value potentially containing cursor.\n * @return String length into serialized HTML for RichText instance where cursor falls.\n */\nfunction resolveRichTextCursorPosition(\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope,\n\tupdatedValue: string\n): HtmlStringIndex | null {\n\treturn cursorPosition &&\n\t\tcursorPosition.clientId === cursorScope.clientId &&\n\t\tcursorPosition.attributeKey === cursorScope.attributeKey &&\n\t\t'number' === typeof cursorPosition.offset &&\n\t\tNumber.isInteger( cursorPosition.offset )\n\t\t? richTextOffsetToHtmlIndex(\n\t\t\t\tupdatedValue,\n\t\t\t\tasRichTextOffset( cursorPosition.offset )\n\t\t )\n\t\t: null;\n}\n\n// Cached block attribute types, populated once from getBlockTypes().\nlet cachedBlockAttributeSchemas: Map<\n\tstring,\n\tMap< string, BlockAttributeSchema >\n>;\n\n/**\n * Get the attribute type definition for a block attribute.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @return The type definition of the attribute.\n */\nfunction getBlockAttributeSchema(\n\tblockName: string,\n\tattributeName: string\n): BlockAttributeSchema | undefined {\n\tif ( ! cachedBlockAttributeSchemas ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedBlockAttributeSchemas = new Map();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tcachedBlockAttributeSchemas.set(\n\t\t\t\tblockType.name,\n\t\t\t\tnew Map< string, BlockAttributeSchema >(\n\t\t\t\t\tObject.entries( blockType.attributes ?? {} ).map(\n\t\t\t\t\t\t( [ name, definition ] ) => {\n\t\t\t\t\t\t\tconst { role, type, query } = definition;\n\t\t\t\t\t\t\treturn [ name, { role, type, query } ];\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\treturn cachedBlockAttributeSchemas.get( blockName )?.get( attributeName );\n}\n\n/**\n * Check if an attribute value is the expected type.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @param attributeValue The current attribute value.\n * @return True if the attribute type is expected, false otherwise.\n */\nfunction isExpectedAttributeType(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): boolean {\n\tconst schema = getBlockAttributeSchema( blockName, attributeName );\n\n\tif ( schema?.type === 'rich-text' ) {\n\t\treturn attributeValue instanceof Y.Text;\n\t}\n\n\tif ( schema?.type === 'string' ) {\n\t\treturn typeof attributeValue === 'string';\n\t}\n\n\tif ( schema?.type === 'array' && schema.query ) {\n\t\treturn attributeValue instanceof Y.Array;\n\t}\n\n\tif ( schema?.type === 'object' && schema.query ) {\n\t\treturn attributeValue instanceof Y.Map;\n\t}\n\n\treturn true;\n}\n\n/**\n * Given a block name and attribute key, return true if the attribute is local\n * and should not be synced.\n *\n * @param blockName The name of the block, e.g. 'core/image'.\n * @param attributeName The name of the attribute to check, e.g. 'blob'.\n * @return True if the attribute is local, false otherwise.\n */\nfunction isLocalAttribute( blockName: string, attributeName: string ): boolean {\n\treturn (\n\t\t'local' === getBlockAttributeSchema( blockName, attributeName )?.role\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 htmlCursorIndex The cursor index in the updated HTML string.\n */\nexport function mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\thtmlCursorIndex: HtmlStringIndex | null = 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\tconst currentValueAsDelta = new Delta( blockYText.toDelta() );\n\tconst updatedValueAsDelta = new Delta( [ { insert: updatedValue } ] );\n\tconst deltaDiff = currentValueAsDelta.diffWithCursor(\n\t\tupdatedValueAsDelta,\n\t\thtmlCursorIndex\n\t);\n\n\t/**\n\t * When there is no cursor involved, or when the diff is able to shuffle properly\n\t * around the cursor then apply that already-computed diff.\n\t *\n\t * However, `diffWithCursor()` currently fails in certain cases, producing corrupted\n\t * output. In these cases, fall back to the raw diff as that will apply cleanly,\n\t * even if it provides a less meaningful diff.\n\t *\n\t * @see Delta.diffWithCursor()\n\t */\n\tconst safeDiff =\n\t\thtmlCursorIndex === null ||\n\t\tisDeltaVerificationMatch( blockYText, deltaDiff, updatedValue )\n\t\t\t? deltaDiff\n\t\t\t: currentValueAsDelta.diff( updatedValueAsDelta );\n\n\tblockYText.applyDelta( safeDiff.ops );\n}\n\n/**\n * Verify that applying a delta to an existing Y.Text object produces the expected\n * output string.\n *\n * A stale, mis-scoped, or corrupted Delta will mutate a text value to the wrong\n * output string. This function applies the given Delta and indicates whether it\n * produces the given expected output string value.\n *\n * @param blockYText The current Y.Text before applying the candidate delta.\n * @param delta The candidate delta.\n * @param expectedValue The exact string expected after applying the delta.\n * @return Whether the candidate delta produces the expected value.\n */\nfunction isDeltaVerificationMatch(\n\tblockYText: Y.Text,\n\tdelta: DeltaWithOps,\n\texpectedValue: string\n): boolean {\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\t// This is an optimization to avoid creating a new Y.Doc on every update.\n\t\tlocalDoc = new Y.Doc();\n\t}\n\n\tconst verificationYText = localDoc.getText( 'verification-text' );\n\n\t// Because this is global, it must be cleared before using.\n\tverificationYText.delete( 0, verificationYText.length );\n\tverificationYText.insert( 0, blockYText.toString() );\n\tverificationYText.applyDelta( delta.ops );\n\n\treturn verificationYText.toString() === expectedValue;\n}\n"],
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 { getBlockTypes } from '@wordpress/blocks';\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tasRichTextOffset,\n\tcreateYMap,\n\trichTextOffsetToHtmlIndex,\n\ttype HtmlStringIndex,\n\ttype YMapRecord,\n\ttype YMapWrap,\n} from './crdt-utils';\nimport { getCachedRichTextData } from './crdt-text';\nimport { Delta } from '../sync';\nimport { type WPBlockSelection } from '../types';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockAttributeSchema {\n\trole?: string;\n\ttype?: string;\n\tquery?: Record< string, BlockAttributeSchema >;\n}\n\ninterface BlockType {\n\tattributes?: Record< string, BlockAttributeSchema >;\n\tname: 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).\nexport interface 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\ninterface MergeCrdtBlocksOptions {\n\tpreserveClientIds?: boolean;\n}\n\n/**\n * Optional description of where a cursor falls.\n *\n * Used to coordinate shifting of cursor when applying changes\n * to a Y.Doc with RichText instances.\n */\nexport type MergeCursorPosition = WPBlockSelection | null;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\n/**\n * Recursively walk an attribute value and convert any RichTextData instances\n * to their string (HTML) representation. This is necessary for array-type and\n * object-type attributes, which can contain nested RichTextData.\n *\n * @param value The attribute value to serialize.\n * @return The value with all RichTextData instances replaced by strings.\n */\nfunction serializeAttributeValue( value: unknown ): unknown {\n\tif ( value instanceof RichTextData ) {\n\t\treturn value.valueOf();\n\t}\n\n\t// e.g. core/table `body`: [ { cells: [ { content: RichTextData } ] } ]\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.map( serializeAttributeValue );\n\t}\n\n\t// e.g. a single row inside core/table `body`: { cells: [ ... ] }\n\tif ( value && typeof value === 'object' ) {\n\t\tconst result: Record< string, unknown > = {};\n\n\t\tfor ( const [ k, v ] of Object.entries( value ) ) {\n\t\t\tresult[ k ] = serializeAttributeValue( v );\n\t\t}\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\nfunction makeBlockAttributesSerializable(\n\tblockName: string,\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( isLocalAttribute( blockName, key ) ) {\n\t\t\tdelete newAttributes[ key ];\n\t\t\tcontinue;\n\t\t}\n\n\t\tnewAttributes[ key ] = serializeAttributeValue( value );\n\t}\n\treturn newAttributes;\n}\n\n/**\n * Recursively removes properties which cannot be serialized from a list of block objects.\n *\n * @param blocks Eemove unserializable properties from each block object in this set.\n * @return Copies of the provided blocks without the unserializable properties.\n */\nfunction makeBlocksSerializable( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst {\n\t\t\tname,\n\t\t\tinnerBlocks,\n\t\t\tattributes,\n\t\t\t/*\n\t\t\t * Any validation issues discovered when loading a block are appended\n\t\t\t * to the block node with a logging function, which cannot be serialized.\n\t\t\t *\n\t\t\t * @see import(\"@wordpress/blocks/src/api/parser\").parseRawBlock()\n\t\t\t */\n\t\t\tvalidationIssues,\n\t\t\t...rest\n\t\t} = block;\n\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( name, attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * Recursively walk an attribute value and convert any strings that correspond\n * to rich-text schema nodes into RichTextData instances. This is the inverse\n * of serializeAttributeValue and handles nested structures like table cells.\n *\n * @param schema The attribute type definition for this value.\n * @param value The attribute value from CRDT (toJSON).\n * @return The value with rich-text strings replaced by RichTextData.\n */\nfunction deserializeAttributeValue(\n\tschema: BlockAttributeSchema | undefined,\n\tvalue: unknown\n): unknown {\n\tif ( schema?.type === 'rich-text' && typeof value === 'string' ) {\n\t\treturn getCachedRichTextData( value );\n\t}\n\n\t// e.g. core/table `body`: [ { cells: [ { content: RichTextData } ] } ]\n\tif ( Array.isArray( value ) ) {\n\t\treturn value.map( ( item ) =>\n\t\t\tdeserializeAttributeValue( schema, item )\n\t\t);\n\t}\n\n\t// e.g. a single row inside core/table `body`: { cells: [ ... ] }\n\tif ( value && typeof value === 'object' ) {\n\t\tconst result: Record< string, unknown > = {};\n\n\t\tfor ( const [ key, innerValue ] of Object.entries(\n\t\t\tvalue as Record< string, unknown >\n\t\t) ) {\n\t\t\tresult[ key ] = deserializeAttributeValue(\n\t\t\t\tschema?.query?.[ key ],\n\t\t\t\tinnerValue\n\t\t\t);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\treturn value;\n}\n\n/**\n * Convert blocks from their CRDT-serialized form back to the runtime form\n * expected by the block editor. Rich-text attributes are stored as Y.Text in\n * the CRDT document, which serializes to plain strings via toJSON(). This\n * function restores them to RichTextData instances so that block edit\n * components that rely on RichTextData methods (e.g. `.text`) work correctly.\n *\n * @param blocks Blocks as extracted from the CRDT document via toJSON().\n * @return Blocks with rich-text attributes restored to RichTextData.\n */\nexport function deserializeBlockAttributes( blocks: Block[] ): Block[] {\n\treturn blocks.map( ( block: Block ) => {\n\t\tconst { name, innerBlocks, attributes, ...rest } = block;\n\n\t\tconst newAttributes = { ...attributes };\n\n\t\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\t\tconst schema = getBlockAttributeSchema( name, key );\n\n\t\t\tif ( schema ) {\n\t\t\t\tnewAttributes[ key ] = deserializeAttributeValue(\n\t\t\t\t\tschema,\n\t\t\t\t\tvalue\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: newAttributes,\n\t\t\tinnerBlocks: deserializeBlockAttributes( 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 | Y.Array< unknown > | Y.Map< unknown > | unknown {\n\tconst schema = getBlockAttributeSchema( blockName, attributeName );\n\treturn createYValueFromSchema( schema, attributeValue );\n}\n\n/**\n * Recursively create the appropriate Y.js type for a value based on its\n * block-attribute schema.\n *\n * - `rich-text` -> Y.Text\n * - `array` with query -> Y.Array of Y.Maps\n * - `object` with query -> Y.Map\n * - anything else -> plain value (unchanged)\n *\n * @param schema The attribute type definition.\n * @param value The plain JS value to convert.\n * @return A Y.js type or the original value.\n */\nfunction createYValueFromSchema(\n\tschema: BlockAttributeSchema | undefined,\n\tvalue: unknown\n): Y.Text | Y.Array< unknown > | Y.Map< unknown > | unknown {\n\tif ( ! schema ) {\n\t\treturn value;\n\t}\n\n\tif ( schema.type === 'rich-text' ) {\n\t\treturn new Y.Text( value?.toString() ?? '' );\n\t}\n\n\tif ( schema.type === 'array' && schema.query && Array.isArray( value ) ) {\n\t\tconst query = schema.query;\n\t\tconst yArray = new Y.Array< Y.Map< unknown > >();\n\n\t\tyArray.insert(\n\t\t\t0,\n\t\t\tvalue.map( ( item ) => createYMapFromQuery( query, item ) )\n\t\t);\n\n\t\treturn yArray;\n\t}\n\n\tif ( schema.type === 'object' && schema.query && isRecord( value ) ) {\n\t\treturn createYMapFromQuery( schema.query, value );\n\t}\n\n\treturn value;\n}\n\n/**\n * Type guard that narrows `unknown` to `Record< string, unknown >`.\n *\n * @param value Value to check.\n * @return True if `value` is a non-null, non-array object.\n */\nfunction isRecord( value: unknown ): value is Record< string, unknown > {\n\treturn !! value && typeof value === 'object' && ! Array.isArray( value );\n}\n\n/**\n * Create a Y.Map from a plain object, using a query schema to decide which\n * properties should become nested Y.js types (Y.Text, Y.Array, Y.Map).\n *\n * @param query The query schema defining the properties.\n * @param obj The plain object to convert.\n * @return A Y.Map with typed values.\n */\nfunction createYMapFromQuery(\n\tquery: Record< string, BlockAttributeSchema >,\n\tobj: unknown\n): Y.Map< unknown > {\n\tif ( ! isRecord( obj ) ) {\n\t\treturn new Y.Map();\n\t}\n\n\tconst entries: [ string, unknown ][] = Object.entries( obj ).map(\n\t\t( [ key, val ] ): [ string, unknown ] => {\n\t\t\tconst subSchema = query[ key ];\n\t\t\treturn [ key, createYValueFromSchema( subSchema, val ) ];\n\t\t}\n\t);\n\n\treturn new Y.Map( entries );\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 attributeCursor When provided, describes a selection cursor falling within a\n * RichText field associated with a specific block and attribute.\n * Derived from the changes that produced the blocks.\n * @param options Optional settings for the merge operation.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tattributeCursor: MergeCursorPosition,\n\toptions: MergeCrdtBlocksOptions = {}\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\n\tconst incomingBlocksToSync =\n\t\tserializableBlocksCache.get( incomingBlocks ) ?? [];\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\tincomingBlocksToSync.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( incomingBlocksToSync[ 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\tincomingBlocksToSync[ incomingBlocksToSync.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\tincomingBlocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - incomingBlocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst incomingYBlock = incomingBlocksToSync[ left ];\n\t\tconst localYBlock = yblocks.get( left );\n\n\t\tObject.entries( incomingYBlock ).forEach(\n\t\t\t( [ incomingBlockProperty, incomingBlockPropertyValue ] ) => {\n\t\t\t\tswitch ( incomingBlockProperty ) {\n\t\t\t\t\tcase 'attributes': {\n\t\t\t\t\t\tconst localAttributes = localYBlock.get(\n\t\t\t\t\t\t\tincomingBlockProperty\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst incomingAttributes = incomingBlockPropertyValue;\n\n\t\t\t\t\t\t// When the local block has no attributes, adopt the incoming set.\n\t\t\t\t\t\tif ( ! localAttributes ) {\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tcreateNewYAttributeMap(\n\t\t\t\t\t\t\t\t\tincomingYBlock.name,\n\t\t\t\t\t\t\t\t\tincomingAttributes\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Otherwise the attributes need to be merged.\n\t\t\t\t\t\tObject.entries( incomingAttributes ).forEach(\n\t\t\t\t\t\t\t( [\n\t\t\t\t\t\t\t\tincomingAttributeName,\n\t\t\t\t\t\t\t\tincomingAttributeValue,\n\t\t\t\t\t\t\t] ) => {\n\t\t\t\t\t\t\t\tconst currentAttribute = localAttributes?.get(\n\t\t\t\t\t\t\t\t\tincomingAttributeName\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tconst isExpectedType = isExpectedAttributeType(\n\t\t\t\t\t\t\t\t\tincomingYBlock.name,\n\t\t\t\t\t\t\t\t\tincomingAttributeName,\n\t\t\t\t\t\t\t\t\tcurrentAttribute\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// Y types (Y.Text, Y.Array, Y.Map) cannot be\n\t\t\t\t\t\t\t\t// compared with fastDeepEqual against plain values.\n\t\t\t\t\t\t\t\t// Delegate to mergeYValue which handles no-op\n\t\t\t\t\t\t\t\t// detection at the edges.\n\t\t\t\t\t\t\t\tconst isYType =\n\t\t\t\t\t\t\t\t\tcurrentAttribute instanceof Y.AbstractType;\n\n\t\t\t\t\t\t\t\tconst isAttributeChanged =\n\t\t\t\t\t\t\t\t\t! isExpectedType ||\n\t\t\t\t\t\t\t\t\tisYType ||\n\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\tcurrentAttribute,\n\t\t\t\t\t\t\t\t\t\tincomingAttributeValue\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\tif ( isAttributeChanged ) {\n\t\t\t\t\t\t\t\t\tupdateYBlockAttribute(\n\t\t\t\t\t\t\t\t\t\tincomingYBlock.name,\n\t\t\t\t\t\t\t\t\t\tincomingYBlock.clientId,\n\t\t\t\t\t\t\t\t\t\tincomingAttributeName,\n\t\t\t\t\t\t\t\t\t\tincomingAttributeValue,\n\t\t\t\t\t\t\t\t\t\tlocalAttributes,\n\t\t\t\t\t\t\t\t\t\tattributeCursor\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\n\t\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\t\tlocalAttributes.forEach(\n\t\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! incomingBlockPropertyValue.hasOwnProperty(\n\t\t\t\t\t\t\t\t\t\tattrName\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\t\tlocalAttributes.delete( attrName );\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\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\t\tlet yInnerBlocks = localYBlock.get(\n\t\t\t\t\t\t\tincomingBlockProperty\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( ! ( yInnerBlocks instanceof Y.Array ) ) {\n\t\t\t\t\t\t\tyInnerBlocks = new Y.Array< YBlock >();\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tyInnerBlocks\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tmergeCrdtBlocks(\n\t\t\t\t\t\t\tyInnerBlocks,\n\t\t\t\t\t\t\tincomingBlockPropertyValue ?? [],\n\t\t\t\t\t\t\tattributeCursor,\n\t\t\t\t\t\t\toptions\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\tcase 'clientId': {\n\t\t\t\t\t\t// Code Editor changes reparse raw HTML on every\n\t\t\t\t\t\t// keystroke and regenerate fresh clientIds. Keep Y.Doc\n\t\t\t\t\t\t// clientIds stable for the code editor so peers do not\n\t\t\t\t\t\t// remount unchanged blocks on every edit.\n\t\t\t\t\t\tif ( options.preserveClientIds ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Otherwise, accept new clientIds from updates\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tincomingBlockPropertyValue !==\n\t\t\t\t\t\t\tlocalYBlock.get( incomingBlockProperty )\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tincomingBlockPropertyValue\n\t\t\t\t\t\t\t);\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\tdefault:\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\tincomingYBlock[ incomingBlockProperty ],\n\t\t\t\t\t\t\t\tlocalYBlock.get( incomingBlockProperty )\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlocalYBlock.set(\n\t\t\t\t\t\t\t\tincomingBlockProperty,\n\t\t\t\t\t\t\t\tincomingBlockPropertyValue\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t\tlocalYBlock.forEach( ( _v, k ) => {\n\t\t\tif ( ! incomingYBlock.hasOwnProperty( k ) ) {\n\t\t\t\tlocalYBlock.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( incomingBlocksToSync[ 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 * Compare a plain array element against a Y.Map element for equality.\n * Used by the left-right sweep diff in mergeYArray.\n *\n * @param newElement The plain object from the incoming array.\n * @param yElement The Y.Map element from the existing Y.Array.\n * @return True if the elements are deeply equal.\n */\nfunction areArrayElementsEqual(\n\tnewElement: unknown,\n\tyElement: unknown\n): boolean {\n\tif ( yElement instanceof Y.Map && isRecord( newElement ) ) {\n\t\treturn fastDeepEqual( newElement, yElement.toJSON() );\n\t}\n\n\treturn fastDeepEqual( newElement, yElement );\n}\n\n/**\n * Merge an incoming plain array into an existing Y.Array in-place.\n *\n * Uses the same left-right sweep diff approach as mergeCrdtBlocks:\n * equal elements are skipped from both ends, then the middle section\n * is updated, deleted, or inserted as needed. This preserves existing\n * Y.Map/Y.Text objects for unchanged elements, so concurrent edits\n * to those elements are not lost.\n *\n * @param yArray The existing Y.Array to update.\n * @param newValue The new plain array to merge into the Y.Array.\n * @param schema The attribute schema (must have `query`).\n * @param cursorPosition The local cursor position for rich-text delta merges.\n * @param cursorScope The selected block attribute scope for rich-text cursor hints.\n */\nfunction mergeYArray(\n\tyArray: Y.Array< unknown >,\n\tnewValue: unknown[],\n\tschema: BlockAttributeSchema,\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope\n): void {\n\tif ( ! schema.query ) {\n\t\treturn;\n\t}\n\n\tconst query = schema.query;\n\tconst numOfCommonEntries = Math.min( newValue.length, yArray.length );\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// Skip equal elements from left.\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareArrayElementsEqual( newValue[ left ], yArray.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// Skip equal elements from right.\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareArrayElementsEqual(\n\t\t\tnewValue[ newValue.length - right - 1 ],\n\t\t\tyArray.get( yArray.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// Updates: merge changed elements in-place.\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++ ) {\n\t\tconst currentElement = yArray.get( left + i );\n\t\tconst newElement = newValue[ left + i ];\n\n\t\tif ( currentElement instanceof Y.Map && isRecord( newElement ) ) {\n\t\t\tmergeYMapValues(\n\t\t\t\tcurrentElement,\n\t\t\t\tnewElement,\n\t\t\t\tquery,\n\t\t\t\tcursorPosition,\n\t\t\t\tcursorScope\n\t\t\t);\n\t\t} else {\n\t\t\t// Element is the wrong type (e.g. partial migration) or the\n\t\t\t// incoming value is not an object. Rebuild the entire array.\n\t\t\tyArray.delete( 0, yArray.length );\n\t\t\tyArray.insert(\n\t\t\t\t0,\n\t\t\t\tnewValue.map( ( item ) => createYMapFromQuery( query, item ) )\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Deletes.\n\tconst numOfDeletionsNeeded = Math.max( 0, yArray.length - newValue.length );\n\n\tif ( numOfDeletionsNeeded > 0 ) {\n\t\tyArray.delete( left + numOfUpdatesNeeded, numOfDeletionsNeeded );\n\t}\n\n\t// Inserts.\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tnewValue.length - yArray.length\n\t);\n\n\tif ( numOfInsertionsNeeded > 0 ) {\n\t\tconst insertAt = left + numOfUpdatesNeeded;\n\t\tconst itemsToInsert: Y.Map< unknown >[] = new Array(\n\t\t\tnumOfInsertionsNeeded\n\t\t);\n\n\t\tfor ( let i = 0; i < numOfInsertionsNeeded; i++ ) {\n\t\t\titemsToInsert[ i ] = createYMapFromQuery(\n\t\t\t\tquery,\n\t\t\t\tnewValue[ insertAt + i ]\n\t\t\t);\n\t\t}\n\n\t\tyArray.insert( insertAt, itemsToInsert );\n\t}\n}\n\n/**\n * Merge a single value into a Y.Map entry, using the attribute schema to\n * decide how to merge.\n *\n * If the current value is already a matching Y.js type (Y.Text, Y.Array,\n * Y.Map), the update is merged in-place so concurrent edits are preserved.\n * Otherwise the value is replaced wholesale.\n *\n * @param schema The attribute type definition for this value.\n * @param newVal The new value to merge into the Y.Map entry.\n * @param yMap The Y.Map that owns this entry.\n * @param key The key of this entry in the Y.Map.\n * @param cursorPosition The cursor position for rich-text delta merges from the updated value.\n * @param cursorScope Indicates a specific block and attribute associated with the editor;\n * determines whether the cursor should be updated based on the change.\n */\nfunction mergeYValue(\n\tschema: BlockAttributeSchema | undefined,\n\tnewVal: unknown,\n\tyMap: Y.Map< unknown >,\n\tkey: string,\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope\n): void {\n\tconst currentVal = yMap.get( key );\n\tif (\n\t\tschema?.type === 'rich-text' &&\n\t\ttypeof newVal === 'string' &&\n\t\tcurrentVal instanceof Y.Text\n\t) {\n\t\tmergeRichTextUpdate(\n\t\t\tcurrentVal,\n\t\t\tnewVal,\n\t\t\tresolveRichTextCursorPosition( cursorPosition, cursorScope, newVal )\n\t\t);\n\t} else if (\n\t\tschema?.type === 'array' &&\n\t\tschema.query &&\n\t\tArray.isArray( newVal ) &&\n\t\tcurrentVal instanceof Y.Array\n\t) {\n\t\tmergeYArray( currentVal, newVal, schema, cursorPosition, cursorScope );\n\t} else if (\n\t\tschema?.type === 'object' &&\n\t\tschema.query &&\n\t\tisRecord( newVal ) &&\n\t\tcurrentVal instanceof Y.Map\n\t) {\n\t\tmergeYMapValues(\n\t\t\tcurrentVal,\n\t\t\tnewVal,\n\t\t\tschema.query,\n\t\t\tcursorPosition,\n\t\t\tcursorScope\n\t\t);\n\t} else {\n\t\tconst newYValue = createYValueFromSchema( schema, newVal );\n\n\t\t// If createYValueFromSchema wrapped the value into a Y type, the\n\t\t// current value is the wrong type and needs upgrading. Otherwise,\n\t\t// only replace if the raw value actually changed.\n\t\tif ( newYValue !== newVal || ! fastDeepEqual( currentVal, newVal ) ) {\n\t\t\tyMap.set( key, newYValue );\n\t\t}\n\t}\n}\n\n/**\n * Merge an incoming plain object into an existing Y.Map in-place, using\n * the query schema to decide how each property should be merged.\n *\n * Properties present in the Y.Map but absent from `newObj` are deleted.\n *\n * @param yMap The existing Y.Map to update.\n * @param newObj The new plain object to merge into the Y.Map.\n * @param query The query schema defining property types.\n * @param cursorPosition The local cursor position for rich-text delta merges.\n * @param cursorScope The selected block attribute scope for rich-text cursor hints.\n */\nfunction mergeYMapValues(\n\tyMap: Y.Map< unknown >,\n\tnewObj: Record< string, unknown >,\n\tquery: Record< string, BlockAttributeSchema >,\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope\n): void {\n\tfor ( const [ key, newVal ] of Object.entries( newObj ) ) {\n\t\tmergeYValue(\n\t\t\tquery[ key ],\n\t\t\tnewVal,\n\t\t\tyMap,\n\t\t\tkey,\n\t\t\tcursorPosition,\n\t\t\tcursorScope\n\t\t);\n\t}\n\n\t// Delete properties absent from the incoming object.\n\tfor ( const key of yMap.keys() ) {\n\t\tif ( ! Object.hasOwn( newObj, key ) ) {\n\t\t\tyMap.delete( key );\n\t\t}\n\t}\n}\n\n/**\n * Update a single attribute on a Yjs block attributes map (currentAttributes).\n *\n * @param blockName The block type name, e.g. 'core/paragraph'.\n * @param clientId The local clientId for the block being merged.\n * @param attributeName The name of the attribute to update, e.g. 'content'.\n * @param attributeValue The new value for the attribute.\n * @param currentAttributes The Y.Map holding the block's current attributes.\n * @param newCursorPosition The cursor position for rich-text delta merges from the updated value.\n * Notably, this may not correspond to the attribute being edited and is\n * used to determine if any cursors need shifting in response to the change.\n */\nfunction updateYBlockAttribute(\n\tblockName: string,\n\tclientId: string | undefined,\n\tattributeName: string,\n\tattributeValue: unknown,\n\tcurrentAttributes: YBlockAttributes,\n\tnewCursorPosition: MergeCursorPosition\n): void {\n\tconst schema = getBlockAttributeSchema( blockName, attributeName );\n\n\t/*\n\t * @todo There is a slight discrepancy between the attribute name and key, which might\n\t * show up when working with multiline RichText instances (of which there are no\n\t * more within Core). For those instances, a cursor might never be updated in\n\t * response to changes because its `attributeKey` won’t match any of the block’s\n\t * attribute names, and since updating this attribute is based on the block names,\n\t * no suitable key for the cursor scope will be created. To fix, the updating code\n\t * would need to parse multiline attributes and infer the `attributeKey` being updated.\n\t */\n\tmergeYValue(\n\t\tschema,\n\t\tattributeValue,\n\t\tcurrentAttributes,\n\t\tattributeName,\n\t\tnewCursorPosition,\n\t\t{ attributeKey: attributeName, clientId }\n\t);\n}\n\n/**\n * References the specific block and attribute associated with a RichText component.\n *\n * This is used to associate a cursor with the attribute it’s editing.\n *\n * @see WPBlockSelection\n */\ninterface RichTextCursorScope {\n\tattributeKey: string;\n\tclientId: string | undefined;\n}\n\ninterface DeltaWithOps {\n\tops: Parameters< Y.Text[ 'applyDelta' ] >[ 0 ];\n}\n\n/**\n * When the provided cursor falls within the given block and attribute’s scope,\n * returns an index into the RichText’s serialized HTML where the cursor falls.\n *\n * The cursor scope constrains resolution to ensure that indices are only reported\n * when a cursor falls within the block and attribute being updated, since the\n * attributes being updated may not always be the ones where a cursor presently falls.\n *\n * Returned index measures JS string lengths, thus is counted in UTF-16 code units\n * and contains the syntax characters making up HTML tags, comments, character\n * references, and other non-plaintext content.\n *\n * @param cursorPosition Description of the cursor in the new value.\n * @param cursorScope Cursors should only be updated if they fall within this\n * specific block and attribute.\n * @param updatedValue New RichText value potentially containing cursor.\n * @return String length into serialized HTML for RichText instance where cursor falls.\n */\nfunction resolveRichTextCursorPosition(\n\tcursorPosition: MergeCursorPosition,\n\tcursorScope: RichTextCursorScope,\n\tupdatedValue: string\n): HtmlStringIndex | null {\n\treturn cursorPosition &&\n\t\tcursorPosition.clientId === cursorScope.clientId &&\n\t\tcursorPosition.attributeKey === cursorScope.attributeKey &&\n\t\t'number' === typeof cursorPosition.offset &&\n\t\tNumber.isInteger( cursorPosition.offset )\n\t\t? richTextOffsetToHtmlIndex(\n\t\t\t\tupdatedValue,\n\t\t\t\tasRichTextOffset( cursorPosition.offset )\n\t\t )\n\t\t: null;\n}\n\n// Cached block attribute types, populated once from getBlockTypes().\nlet cachedBlockAttributeSchemas: Map<\n\tstring,\n\tMap< string, BlockAttributeSchema >\n>;\n\n/**\n * Get the attribute type definition for a block attribute.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @return The type definition of the attribute.\n */\nfunction getBlockAttributeSchema(\n\tblockName: string,\n\tattributeName: string\n): BlockAttributeSchema | undefined {\n\tif ( ! cachedBlockAttributeSchemas ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedBlockAttributeSchemas = new Map();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tcachedBlockAttributeSchemas.set(\n\t\t\t\tblockType.name,\n\t\t\t\tnew Map< string, BlockAttributeSchema >(\n\t\t\t\t\tObject.entries( blockType.attributes ?? {} ).map(\n\t\t\t\t\t\t( [ name, definition ] ) => {\n\t\t\t\t\t\t\tconst { role, type, query } = definition;\n\t\t\t\t\t\t\treturn [ name, { role, type, query } ];\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\treturn cachedBlockAttributeSchemas.get( blockName )?.get( attributeName );\n}\n\n/**\n * Check if an attribute value is the expected type.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute, e.g. 'content'.\n * @param attributeValue The current attribute value.\n * @return True if the attribute type is expected, false otherwise.\n */\nfunction isExpectedAttributeType(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): boolean {\n\tconst schema = getBlockAttributeSchema( blockName, attributeName );\n\n\tif ( schema?.type === 'rich-text' ) {\n\t\treturn attributeValue instanceof Y.Text;\n\t}\n\n\tif ( schema?.type === 'string' ) {\n\t\treturn typeof attributeValue === 'string';\n\t}\n\n\tif ( schema?.type === 'array' && schema.query ) {\n\t\treturn attributeValue instanceof Y.Array;\n\t}\n\n\tif ( schema?.type === 'object' && schema.query ) {\n\t\treturn attributeValue instanceof Y.Map;\n\t}\n\n\treturn true;\n}\n\n/**\n * Given a block name and attribute key, return true if the attribute is local\n * and should not be synced.\n *\n * @param blockName The name of the block, e.g. 'core/image'.\n * @param attributeName The name of the attribute to check, e.g. 'blob'.\n * @return True if the attribute is local, false otherwise.\n */\nfunction isLocalAttribute( blockName: string, attributeName: string ): boolean {\n\treturn (\n\t\t'local' === getBlockAttributeSchema( blockName, attributeName )?.role\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 htmlCursorIndex The cursor index in the updated HTML string.\n */\nexport function mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\thtmlCursorIndex: HtmlStringIndex | null = 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\tconst currentValueAsDelta = new Delta( blockYText.toDelta() );\n\tconst updatedValueAsDelta = new Delta( [ { insert: updatedValue } ] );\n\tconst deltaDiff = currentValueAsDelta.diffWithCursor(\n\t\tupdatedValueAsDelta,\n\t\thtmlCursorIndex\n\t);\n\n\t/**\n\t * When there is no cursor involved, or when the diff is able to shuffle properly\n\t * around the cursor then apply that already-computed diff.\n\t *\n\t * However, `diffWithCursor()` currently fails in certain cases, producing corrupted\n\t * output. In these cases, fall back to the raw diff as that will apply cleanly,\n\t * even if it provides a less meaningful diff.\n\t *\n\t * @see Delta.diffWithCursor()\n\t */\n\tconst safeDiff =\n\t\thtmlCursorIndex === null ||\n\t\tisDeltaVerificationMatch( blockYText, deltaDiff, updatedValue )\n\t\t\t? deltaDiff\n\t\t\t: currentValueAsDelta.diff( updatedValueAsDelta );\n\n\tblockYText.applyDelta( safeDiff.ops );\n}\n\n/**\n * Verify that applying a delta to an existing Y.Text object produces the expected\n * output string.\n *\n * A stale, mis-scoped, or corrupted Delta will mutate a text value to the wrong\n * output string. This function applies the given Delta and indicates whether it\n * produces the given expected output string value.\n *\n * @param blockYText The current Y.Text before applying the candidate delta.\n * @param delta The candidate delta.\n * @param expectedValue The exact string expected after applying the delta.\n * @return Whether the candidate delta produces the expected value.\n */\nfunction isDeltaVerificationMatch(\n\tblockYText: Y.Text,\n\tdelta: DeltaWithOps,\n\texpectedValue: string\n): boolean {\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\t// This is an optimization to avoid creating a new Y.Doc on every update.\n\t\tlocalDoc = new Y.Doc();\n\t}\n\n\tconst verificationYText = localDoc.getText( 'verification-text' );\n\n\t// Because this is global, it must be cleared before using.\n\tverificationYText.delete( 0, verificationYText.length );\n\tverificationYText.insert( 0, blockYText.toString() );\n\tverificationYText.applyDelta( delta.ops );\n\n\treturn verificationYText.toString() === expectedValue;\n}\n"],
5
5
  "mappings": ";AAGA,SAAS,MAAM,cAAc;AAC7B,OAAO,mBAAmB;AAK1B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAKlB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP,SAAS,6BAA6B;AACtC,SAAS,aAAa;AA0DtB,IAAM,0BAA0B,oBAAI,QAA4B;AAUhE,SAAS,wBAAyB,OAA0B;AAC3D,MAAK,iBAAiB,cAAe;AACpC,WAAO,MAAM,QAAQ;AAAA,EACtB;AAGA,MAAK,MAAM,QAAS,KAAM,GAAI;AAC7B,WAAO,MAAM,IAAK,uBAAwB;AAAA,EAC3C;AAGA,MAAK,SAAS,OAAO,UAAU,UAAW;AACzC,UAAM,SAAoC,CAAC;AAE3C,eAAY,CAAE,GAAG,CAAE,KAAK,OAAO,QAAS,KAAM,GAAI;AACjD,aAAQ,CAAE,IAAI,wBAAyB,CAAE;AAAA,IAC1C;AACA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEA,SAAS,gCACR,WACA,YACkB;AAClB,QAAM,gBAAgB,EAAE,GAAG,WAAW;AACtC,aAAY,CAAE,KAAK,KAAM,KAAK,OAAO,QAAS,UAAW,GAAI;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