@wordpress/core-data 7.41.2-next.v.202603102151.0 → 7.42.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 (166) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +19 -0
  3. package/build/actions.cjs +17 -25
  4. package/build/actions.cjs.map +2 -2
  5. package/build/awareness/post-editor-awareness.cjs +46 -6
  6. package/build/awareness/post-editor-awareness.cjs.map +2 -2
  7. package/build/awareness/types.cjs.map +1 -1
  8. package/build/entities.cjs +33 -7
  9. package/build/entities.cjs.map +2 -2
  10. package/build/hooks/use-entity-prop.cjs +2 -1
  11. package/build/hooks/use-entity-prop.cjs.map +2 -2
  12. package/build/hooks/use-post-editor-awareness-state.cjs +84 -3
  13. package/build/hooks/use-post-editor-awareness-state.cjs.map +2 -2
  14. package/build/index.cjs +3 -0
  15. package/build/index.cjs.map +2 -2
  16. package/build/private-apis.cjs +3 -1
  17. package/build/private-apis.cjs.map +2 -2
  18. package/build/queried-data/get-query-parts.cjs +7 -0
  19. package/build/queried-data/get-query-parts.cjs.map +2 -2
  20. package/build/queried-data/selectors.cjs +19 -5
  21. package/build/queried-data/selectors.cjs.map +2 -2
  22. package/build/reducer.cjs +6 -0
  23. package/build/reducer.cjs.map +2 -2
  24. package/build/resolvers.cjs +110 -74
  25. package/build/resolvers.cjs.map +2 -2
  26. package/build/selectors.cjs +29 -0
  27. package/build/selectors.cjs.map +2 -2
  28. package/build/sync.cjs +3 -0
  29. package/build/sync.cjs.map +2 -2
  30. package/build/types.cjs +16 -0
  31. package/build/types.cjs.map +3 -3
  32. package/build/utils/block-selection-history.cjs +1 -1
  33. package/build/utils/block-selection-history.cjs.map +2 -2
  34. package/build/utils/crdt-blocks.cjs +17 -3
  35. package/build/utils/crdt-blocks.cjs.map +2 -2
  36. package/build/utils/crdt-selection.cjs +4 -1
  37. package/build/utils/crdt-selection.cjs.map +2 -2
  38. package/build/utils/crdt-user-selections.cjs +9 -6
  39. package/build/utils/crdt-user-selections.cjs.map +2 -2
  40. package/build/utils/crdt-utils.cjs +54 -2
  41. package/build/utils/crdt-utils.cjs.map +2 -2
  42. package/build/utils/crdt.cjs +4 -23
  43. package/build/utils/crdt.cjs.map +2 -2
  44. package/build/utils/index.cjs +3 -0
  45. package/build/utils/index.cjs.map +2 -2
  46. package/build/utils/normalize-query-for-resolution.cjs +35 -0
  47. package/build/utils/normalize-query-for-resolution.cjs.map +7 -0
  48. package/build-module/actions.mjs +17 -25
  49. package/build-module/actions.mjs.map +2 -2
  50. package/build-module/awareness/post-editor-awareness.mjs +46 -6
  51. package/build-module/awareness/post-editor-awareness.mjs.map +2 -2
  52. package/build-module/entities.mjs +33 -7
  53. package/build-module/entities.mjs.map +2 -2
  54. package/build-module/hooks/use-entity-prop.mjs +2 -1
  55. package/build-module/hooks/use-entity-prop.mjs.map +2 -2
  56. package/build-module/hooks/use-post-editor-awareness-state.mjs +81 -2
  57. package/build-module/hooks/use-post-editor-awareness-state.mjs.map +2 -2
  58. package/build-module/index.mjs +2 -0
  59. package/build-module/index.mjs.map +2 -2
  60. package/build-module/private-apis.mjs +6 -2
  61. package/build-module/private-apis.mjs.map +2 -2
  62. package/build-module/queried-data/get-query-parts.mjs +7 -0
  63. package/build-module/queried-data/get-query-parts.mjs.map +2 -2
  64. package/build-module/queried-data/selectors.mjs +19 -5
  65. package/build-module/queried-data/selectors.mjs.map +2 -2
  66. package/build-module/reducer.mjs +6 -0
  67. package/build-module/reducer.mjs.map +2 -2
  68. package/build-module/resolvers.mjs +112 -75
  69. package/build-module/resolvers.mjs.map +2 -2
  70. package/build-module/selectors.mjs +28 -0
  71. package/build-module/selectors.mjs.map +2 -2
  72. package/build-module/sync.mjs +2 -0
  73. package/build-module/sync.mjs.map +2 -2
  74. package/build-module/types.mjs +9 -0
  75. package/build-module/types.mjs.map +4 -4
  76. package/build-module/utils/block-selection-history.mjs +5 -2
  77. package/build-module/utils/block-selection-history.mjs.map +2 -2
  78. package/build-module/utils/crdt-blocks.mjs +17 -3
  79. package/build-module/utils/crdt-blocks.mjs.map +2 -2
  80. package/build-module/utils/crdt-selection.mjs +8 -2
  81. package/build-module/utils/crdt-selection.mjs.map +2 -2
  82. package/build-module/utils/crdt-user-selections.mjs +10 -7
  83. package/build-module/utils/crdt-user-selections.mjs.map +2 -2
  84. package/build-module/utils/crdt-utils.mjs +51 -1
  85. package/build-module/utils/crdt-utils.mjs.map +2 -2
  86. package/build-module/utils/crdt.mjs +4 -23
  87. package/build-module/utils/crdt.mjs.map +2 -2
  88. package/build-module/utils/index.mjs +2 -0
  89. package/build-module/utils/index.mjs.map +2 -2
  90. package/build-module/utils/normalize-query-for-resolution.mjs +14 -0
  91. package/build-module/utils/normalize-query-for-resolution.mjs.map +7 -0
  92. package/build-types/actions.d.ts.map +1 -1
  93. package/build-types/awareness/post-editor-awareness.d.ts +2 -2
  94. package/build-types/awareness/post-editor-awareness.d.ts.map +1 -1
  95. package/build-types/awareness/types.d.ts +1 -1
  96. package/build-types/awareness/types.d.ts.map +1 -1
  97. package/build-types/entities.d.ts +1 -1
  98. package/build-types/entities.d.ts.map +1 -1
  99. package/build-types/hooks/use-entity-prop.d.ts.map +1 -1
  100. package/build-types/hooks/use-post-editor-awareness-state.d.ts +34 -10
  101. package/build-types/hooks/use-post-editor-awareness-state.d.ts.map +1 -1
  102. package/build-types/index.d.ts +2 -0
  103. package/build-types/index.d.ts.map +1 -1
  104. package/build-types/private-apis.d.ts.map +1 -1
  105. package/build-types/queried-data/get-query-parts.d.ts +7 -0
  106. package/build-types/queried-data/get-query-parts.d.ts.map +1 -1
  107. package/build-types/queried-data/selectors.d.ts.map +1 -1
  108. package/build-types/reducer.d.ts.map +1 -1
  109. package/build-types/resolvers.d.ts +2 -1
  110. package/build-types/resolvers.d.ts.map +1 -1
  111. package/build-types/selectors.d.ts +17 -0
  112. package/build-types/selectors.d.ts.map +1 -1
  113. package/build-types/sync.d.ts +2 -2
  114. package/build-types/sync.d.ts.map +1 -1
  115. package/build-types/types.d.ts +18 -1
  116. package/build-types/types.d.ts.map +1 -1
  117. package/build-types/utils/block-selection-history.d.ts.map +1 -1
  118. package/build-types/utils/crdt-blocks.d.ts.map +1 -1
  119. package/build-types/utils/crdt-selection.d.ts.map +1 -1
  120. package/build-types/utils/crdt-user-selections.d.ts +9 -5
  121. package/build-types/utils/crdt-user-selections.d.ts.map +1 -1
  122. package/build-types/utils/crdt-utils.d.ts +20 -0
  123. package/build-types/utils/crdt-utils.d.ts.map +1 -1
  124. package/build-types/utils/crdt.d.ts +6 -7
  125. package/build-types/utils/crdt.d.ts.map +1 -1
  126. package/build-types/utils/index.d.ts +1 -0
  127. package/build-types/utils/normalize-query-for-resolution.d.ts +12 -0
  128. package/build-types/utils/normalize-query-for-resolution.d.ts.map +1 -0
  129. package/build-types/utils/test/crdt-utils.d.ts +2 -0
  130. package/build-types/utils/test/crdt-utils.d.ts.map +1 -0
  131. package/package.json +18 -18
  132. package/src/actions.js +25 -40
  133. package/src/awareness/post-editor-awareness.ts +106 -7
  134. package/src/awareness/test/post-editor-awareness.ts +50 -10
  135. package/src/awareness/types.ts +1 -1
  136. package/src/entities.js +38 -6
  137. package/src/hooks/test/use-post-editor-awareness-state.ts +446 -3
  138. package/src/hooks/use-entity-prop.js +2 -0
  139. package/src/hooks/use-post-editor-awareness-state.ts +160 -8
  140. package/src/index.js +1 -0
  141. package/src/private-apis.js +6 -2
  142. package/src/queried-data/get-query-parts.js +13 -0
  143. package/src/queried-data/selectors.js +33 -8
  144. package/src/queried-data/test/get-query-parts.js +34 -0
  145. package/src/queried-data/test/selectors.js +183 -0
  146. package/src/reducer.js +11 -0
  147. package/src/resolvers.js +136 -88
  148. package/src/selectors.ts +56 -0
  149. package/src/sync.ts +2 -0
  150. package/src/test/entities.js +185 -1
  151. package/src/test/resolvers.js +64 -11
  152. package/src/test/selectors.js +150 -0
  153. package/src/test/store.js +66 -0
  154. package/src/types.ts +26 -1
  155. package/src/utils/block-selection-history.ts +5 -2
  156. package/src/utils/crdt-blocks.ts +32 -3
  157. package/src/utils/crdt-selection.ts +8 -2
  158. package/src/utils/crdt-user-selections.ts +20 -8
  159. package/src/utils/crdt-utils.ts +99 -0
  160. package/src/utils/crdt.ts +8 -32
  161. package/src/utils/index.js +1 -0
  162. package/src/utils/normalize-query-for-resolution.js +23 -0
  163. package/src/utils/test/crdt-blocks.ts +146 -0
  164. package/src/utils/test/crdt-user-selections.ts +5 -0
  165. package/src/utils/test/crdt-utils.ts +387 -0
  166. package/src/utils/test/crdt.ts +120 -53
@@ -210,7 +210,8 @@ var rootEntitiesConfig = [
210
210
  baseURL: "/wp/v2/font-collections",
211
211
  baseURLParams: { context: "view" },
212
212
  plural: "fontCollections",
213
- key: "slug"
213
+ key: "slug",
214
+ supportsPagination: true
214
215
  },
215
216
  {
216
217
  label: __("Icons"),
@@ -276,14 +277,35 @@ var prePersistPostType = async (persistedRecord, edits, name, isTemplate) => {
276
277
  return newEdits;
277
278
  };
278
279
  async function loadPostTypeEntities() {
279
- const postTypes = await apiFetch({
280
- path: "/wp/v2/types?context=view"
281
- });
280
+ const postTypesPromise = apiFetch({ path: "/wp/v2/types?context=view" });
281
+ const taxonomiesPromise = window._wpCollaborationEnabled ? apiFetch({ path: "/wp/v2/taxonomies?context=view" }) : Promise.resolve({});
282
+ const [postTypes, taxonomies] = await Promise.all([
283
+ postTypesPromise,
284
+ taxonomiesPromise
285
+ ]);
282
286
  return Object.entries(postTypes ?? {}).map(([name, postType]) => {
283
287
  const isTemplate = ["wp_template", "wp_template_part"].includes(
284
288
  name
285
289
  );
286
290
  const namespace = postType?.rest_namespace ?? "wp/v2";
291
+ const syncedProperties = /* @__PURE__ */ new Set([
292
+ "author",
293
+ "blocks",
294
+ "content",
295
+ "comment_status",
296
+ "date",
297
+ "excerpt",
298
+ "featured_media",
299
+ "format",
300
+ "meta",
301
+ "ping_status",
302
+ "slug",
303
+ "status",
304
+ "sticky",
305
+ "template",
306
+ "title",
307
+ ...postType.taxonomies?.map((taxonomy) => taxonomies?.[taxonomy]?.rest_base)?.filter(Boolean) ?? []
308
+ ]);
287
309
  const entity = {
288
310
  kind: "postType",
289
311
  baseURL: `/${namespace}/${postType.rest_base}`,
@@ -312,7 +334,7 @@ async function loadPostTypeEntities() {
312
334
  * @param {Partial< import('@wordpress/sync').ObjectData >} changes
313
335
  * @return {void}
314
336
  */
315
- applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes, postType),
337
+ applyChangesToCRDTDoc: (crdtDoc, changes) => applyPostChangesToCRDTDoc(crdtDoc, changes, syncedProperties),
316
338
  /**
317
339
  * Create the awareness instance for the entity's CRDT document.
318
340
  *
@@ -333,7 +355,11 @@ async function loadPostTypeEntities() {
333
355
  * @param {import('@wordpress/sync').ObjectData} editedRecord
334
356
  * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
335
357
  */
336
- getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(crdtDoc, editedRecord, postType),
358
+ getChangesFromCRDTDoc: (crdtDoc, editedRecord) => getPostChangesFromCRDTDoc(
359
+ crdtDoc,
360
+ editedRecord,
361
+ syncedProperties
362
+ ),
337
363
  /**
338
364
  * Extract changes from a CRDT document that can be used to update the
339
365
  * local editor state.
@@ -342,7 +368,7 @@ async function loadPostTypeEntities() {
342
368
  * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record
343
369
  */
344
370
  getPersistedCRDTDoc: (record) => {
345
- return record?.meta[POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE] || null;
371
+ return record?.meta?.[POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE] || null;
346
372
  }
347
373
  };
348
374
  return entity;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/entities.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __unstableSerializeAndClean, parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PostEditorAwareness } from './awareness/post-editor-awareness';\nimport { getSyncManager } from './sync';\nimport {\n\tapplyPostChangesToCRDTDoc,\n\tdefaultSyncConfig,\n\tgetPostChangesFromCRDTDoc,\n\tPOST_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\n} from './utils/crdt';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nconst blocksTransientEdits = {\n\tblocks: {\n\t\tread: ( record ) => parse( record.content?.raw ?? '' ),\n\t\twrite: ( record ) => ( {\n\t\t\tcontent: __unstableSerializeAndClean( record.blocks ),\n\t\t} ),\n\t},\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t// Please also change the preload path when changing this.\n\t\t\t// @see lib/compat/wordpress-7.0/preload.php\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'image_sizes',\n\t\t\t\t'image_size_threshold',\n\t\t\t\t'image_output_formats',\n\t\t\t\t'jpeg_interlaced',\n\t\t\t\t'png_interlaced',\n\t\t\t\t'gif_interlaced',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t\t'page_for_posts',\n\t\t\t\t'page_on_front',\n\t\t\t\t'show_on_front',\n\t\t\t].join( ',' ),\n\t\t},\n\t\t// The entity doesn't support selecting multiple records.\n\t\t// The property is maintained for backward compatibility.\n\t\tplural: '__unstableBases',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'postTypes',\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tgetTitle: ( record ) => record?.name || record?.slug,\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: () => __( 'Custom Styles' ),\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'themes',\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'plugins',\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Registered Templates' ),\n\t\tname: 'registeredTemplate',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/registered-templates',\n\t\tkey: 'id',\n\t},\n\t{\n\t\tlabel: __( 'Font Collections' ),\n\t\tname: 'fontCollection',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/font-collections',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'fontCollections',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Icons' ),\n\t\tname: 'icon',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/icons',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'icons',\n\t\tkey: 'name',\n\t},\n].map( ( entity ) => {\n\tconst syncEnabledRootEntities = new Set( [ 'comment' ] );\n\n\tif ( syncEnabledRootEntities.has( entity.name ) ) {\n\t\tentity.syncConfig = defaultSyncConfig;\n\t}\n\treturn entity;\n} );\n\nexport const deprecatedEntities = {\n\troot: {\n\t\tmedia: {\n\t\t\tsince: '6.9',\n\t\t\talternative: {\n\t\t\t\tkind: 'postType',\n\t\t\t\tname: 'attachment',\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n\t{\n\t\tkind: 'root',\n\t\tname: 'site',\n\t\tplural: 'sites',\n\t\tloadEntities: loadSiteEntity,\n\t},\n];\n\n/**\n * Apply extra edits before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @param {string} name Post type name.\n * @param {boolean} isTemplate Whether the post type is a template.\n * @return {Promise< Object >} Updated edits.\n */\nexport const prePersistPostType = async (\n\tpersistedRecord,\n\tedits,\n\tname,\n\tisTemplate\n) => {\n\tconst newEdits = {};\n\n\tif ( ! isTemplate && persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\t// Add meta for persisted CRDT document.\n\tif ( persistedRecord ) {\n\t\tconst objectType = `postType/${ name }`;\n\t\tconst objectId = persistedRecord.id;\n\t\tconst serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(\n\t\t\tobjectType,\n\t\t\tobjectId\n\t\t);\n\n\t\tif ( serializedDoc ) {\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ]: serializedDoc,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\n\t\tconst entity = {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\t...blocksTransientEdits,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: ( persistedRecord, edits ) =>\n\t\t\t\tprePersistPostType( persistedRecord, edits, name, isTemplate ),\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey:\n\t\t\t\tisTemplate && ! window?.__experimentalTemplateActivate\n\t\t\t\t\t? 'wp_id'\n\t\t\t\t\t: DEFAULT_ENTITY_KEY,\n\t\t};\n\n\t\t/**\n\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t */\n\t\tentity.syncConfig = {\n\t\t\t/**\n\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t * @return {void}\n\t\t\t */\n\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, postType ),\n\n\t\t\t/**\n\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t * @return {import('@wordpress/sync').Awareness} Awareness instance\n\t\t\t */\n\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\tconst kind = 'postType';\n\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\tgetPostChangesFromCRDTDoc( crdtDoc, editedRecord, postType ),\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').ObjectData} record\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetPersistedCRDTDoc: ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\trecord?.meta[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ] ||\n\t\t\t\t\tnull\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\tconst entity = {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t\tgetTitle: ( record ) => record?.name,\n\t\t\tsupportsPagination: true,\n\t\t};\n\n\t\tentity.syncConfig = defaultSyncConfig;\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the Site entity.\n *\n * @return {Promise} Entity promise\n */\nasync function loadSiteEntity() {\n\tconst entity = {\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tbaseURL: '/wp/v2/settings',\n\t\tmeta: {},\n\t};\n\n\tconst site = await apiFetch( {\n\t\tpath: entity.baseURL,\n\t\tmethod: 'OPTIONS',\n\t} );\n\n\tconst labels = {};\n\tObject.entries( site?.schema?.properties ?? {} ).forEach(\n\t\t( [ key, value ] ) => {\n\t\t\t// Ignore properties `title` and `type` keys.\n\t\t\tif ( typeof value === 'object' && value.title ) {\n\t\t\t\tlabels[ key ] = value.title;\n\t\t\t}\n\t\t}\n\t);\n\n\treturn [ { ...entity, meta: { labels } } ];\n}\n\n/**\n * Returns the entity's getter method name given its kind and name or plural name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'themes', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name or plural name.\n * @param {string} prefix Function prefix.\n *\n * @return {string} Method name\n */\nexport const getMethodName = ( kind, name, prefix = 'get' ) => {\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst suffix = pascalCase( name );\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n"],
5
- "mappings": ";AAGA,SAAS,aAAa,kBAAkB;AAKxC,OAAO,cAAc;AACrB,SAAS,6BAA6B,aAAa;AACnD,SAAS,UAAU;AAKnB,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B;AAAA,EACC;AAAA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,SAAS;AAAA,IACd,OAAO,GAAI,MAAO;AAAA,IAClB,MAAM;AAAA,IACN,MAAM;AAAA,IACN,KAAK;AAAA,IACL,SAAS;AAAA,IACT,MAAM,CAAC;AAAA,EACR;AAEA,QAAM,OAAO,MAAM,SAAU;AAAA,IAC5B,MAAM,OAAO;AAAA,IACb,QAAQ;AAAA,EACT,CAAE;AAEF,QAAM,SAAS,CAAC;AAChB,SAAO,QAAS,MAAM,QAAQ,cAAc,CAAC,CAAE,EAAE;AAAA,IAChD,CAAE,CAAE,KAAK,KAAM,MAAO;AAErB,UAAK,OAAO,UAAU,YAAY,MAAM,OAAQ;AAC/C,eAAQ,GAAI,IAAI,MAAM;AAAA,MACvB;AAAA,IACD;AAAA,EACD;AAEA,SAAO,CAAE,EAAE,GAAG,QAAQ,MAAM,EAAE,OAAO,EAAE,CAAE;AAC1C;AAoBO,IAAM,gBAAgB,CAAE,MAAM,MAAM,SAAS,UAAW;AAC9D,QAAM,aAAa,SAAS,SAAS,KAAK,WAAY,IAAK;AAC3D,QAAM,SAAS,WAAY,IAAK;AAChC,SAAO,GAAI,MAAO,GAAI,UAAW,GAAI,MAAO;AAC7C;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __unstableSerializeAndClean, parse } from '@wordpress/blocks';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { PostEditorAwareness } from './awareness/post-editor-awareness';\nimport { getSyncManager } from './sync';\nimport {\n\tapplyPostChangesToCRDTDoc,\n\tdefaultSyncConfig,\n\tgetPostChangesFromCRDTDoc,\n\tPOST_META_KEY_FOR_CRDT_DOC_PERSISTENCE,\n} from './utils/crdt';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\nconst blocksTransientEdits = {\n\tblocks: {\n\t\tread: ( record ) => parse( record.content?.raw ?? '' ),\n\t\twrite: ( record ) => ( {\n\t\t\tcontent: __unstableSerializeAndClean( record.blocks ),\n\t\t} ),\n\t},\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t// Please also change the preload path when changing this.\n\t\t\t// @see lib/compat/wordpress-7.0/preload.php\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'image_sizes',\n\t\t\t\t'image_size_threshold',\n\t\t\t\t'image_output_formats',\n\t\t\t\t'jpeg_interlaced',\n\t\t\t\t'png_interlaced',\n\t\t\t\t'gif_interlaced',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t\t'page_for_posts',\n\t\t\t\t'page_on_front',\n\t\t\t\t'show_on_front',\n\t\t\t].join( ',' ),\n\t\t},\n\t\t// The entity doesn't support selecting multiple records.\n\t\t// The property is maintained for backward compatibility.\n\t\tplural: '__unstableBases',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'postTypes',\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tgetTitle: ( record ) => record?.name || record?.slug,\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: () => __( 'Custom Styles' ),\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'themes',\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'plugins',\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n\t{\n\t\tlabel: __( 'Registered Templates' ),\n\t\tname: 'registeredTemplate',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/registered-templates',\n\t\tkey: 'id',\n\t},\n\t{\n\t\tlabel: __( 'Font Collections' ),\n\t\tname: 'fontCollection',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/font-collections',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'fontCollections',\n\t\tkey: 'slug',\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Icons' ),\n\t\tname: 'icon',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/icons',\n\t\tbaseURLParams: { context: 'view' },\n\t\tplural: 'icons',\n\t\tkey: 'name',\n\t},\n].map( ( entity ) => {\n\tconst syncEnabledRootEntities = new Set( [ 'comment' ] );\n\n\tif ( syncEnabledRootEntities.has( entity.name ) ) {\n\t\tentity.syncConfig = defaultSyncConfig;\n\t}\n\treturn entity;\n} );\n\nexport const deprecatedEntities = {\n\troot: {\n\t\tmedia: {\n\t\t\tsince: '6.9',\n\t\t\talternative: {\n\t\t\t\tkind: 'postType',\n\t\t\t\tname: 'attachment',\n\t\t\t},\n\t\t},\n\t},\n};\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n\t{\n\t\tkind: 'root',\n\t\tname: 'site',\n\t\tplural: 'sites',\n\t\tloadEntities: loadSiteEntity,\n\t},\n];\n\n/**\n * Apply extra edits before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @param {string} name Post type name.\n * @param {boolean} isTemplate Whether the post type is a template.\n * @return {Promise< Object >} Updated edits.\n */\nexport const prePersistPostType = async (\n\tpersistedRecord,\n\tedits,\n\tname,\n\tisTemplate\n) => {\n\tconst newEdits = {};\n\n\tif ( ! isTemplate && persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\t// Add meta for persisted CRDT document.\n\tif ( persistedRecord ) {\n\t\tconst objectType = `postType/${ name }`;\n\t\tconst objectId = persistedRecord.id;\n\t\tconst serializedDoc = await getSyncManager()?.createPersistedCRDTDoc(\n\t\t\tobjectType,\n\t\t\tobjectId\n\t\t);\n\n\t\tif ( serializedDoc ) {\n\t\t\tnewEdits.meta = {\n\t\t\t\t...edits.meta,\n\t\t\t\t[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ]: serializedDoc,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypesPromise = apiFetch( { path: '/wp/v2/types?context=view' } );\n\tconst taxonomiesPromise = window._wpCollaborationEnabled\n\t\t? apiFetch( { path: '/wp/v2/taxonomies?context=view' } )\n\t\t: Promise.resolve( {} );\n\tconst [ postTypes, taxonomies ] = await Promise.all( [\n\t\tpostTypesPromise,\n\t\ttaxonomiesPromise,\n\t] );\n\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\n\t\tconst syncedProperties = new Set( [\n\t\t\t'author',\n\t\t\t'blocks',\n\t\t\t'content',\n\t\t\t'comment_status',\n\t\t\t'date',\n\t\t\t'excerpt',\n\t\t\t'featured_media',\n\t\t\t'format',\n\t\t\t'meta',\n\t\t\t'ping_status',\n\t\t\t'slug',\n\t\t\t'status',\n\t\t\t'sticky',\n\t\t\t'template',\n\t\t\t'title',\n\t\t\t...( postType.taxonomies\n\t\t\t\t?.map( ( taxonomy ) => taxonomies?.[ taxonomy ]?.rest_base )\n\t\t\t\t?.filter( Boolean ) ?? [] ),\n\t\t] );\n\n\t\tconst entity = {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\t...blocksTransientEdits,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: ( persistedRecord, edits ) =>\n\t\t\t\tprePersistPostType( persistedRecord, edits, name, isTemplate ),\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey:\n\t\t\t\tisTemplate && ! window?.__experimentalTemplateActivate\n\t\t\t\t\t? 'wp_id'\n\t\t\t\t\t: DEFAULT_ENTITY_KEY,\n\t\t};\n\n\t\t/**\n\t\t * @type {import('@wordpress/sync').SyncConfig}\n\t\t */\n\t\tentity.syncConfig = {\n\t\t\t/**\n\t\t\t * Apply changes from the local editor to the local CRDT document so\n\t\t\t * that those changes can be synced to other peers (via the provider).\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {Partial< import('@wordpress/sync').ObjectData >} changes\n\t\t\t * @return {void}\n\t\t\t */\n\t\t\tapplyChangesToCRDTDoc: ( crdtDoc, changes ) =>\n\t\t\t\tapplyPostChangesToCRDTDoc( crdtDoc, changes, syncedProperties ),\n\n\t\t\t/**\n\t\t\t * Create the awareness instance for the entity's CRDT document.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} ydoc\n\t\t\t * @param {import('@wordpress/sync').ObjectID} objectId\n\t\t\t * @return {import('@wordpress/sync').Awareness} Awareness instance\n\t\t\t */\n\t\t\tcreateAwareness: ( ydoc, objectId ) => {\n\t\t\t\tconst kind = 'postType';\n\t\t\t\tconst id = parseInt( objectId, 10 );\n\t\t\t\treturn new PostEditorAwareness( ydoc, kind, name, id );\n\t\t\t},\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').CRDTDoc} crdtDoc\n\t\t\t * @param {import('@wordpress/sync').ObjectData} editedRecord\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetChangesFromCRDTDoc: ( crdtDoc, editedRecord ) =>\n\t\t\t\tgetPostChangesFromCRDTDoc(\n\t\t\t\t\tcrdtDoc,\n\t\t\t\t\teditedRecord,\n\t\t\t\t\tsyncedProperties\n\t\t\t\t),\n\n\t\t\t/**\n\t\t\t * Extract changes from a CRDT document that can be used to update the\n\t\t\t * local editor state.\n\t\t\t *\n\t\t\t * @param {import('@wordpress/sync').ObjectData} record\n\t\t\t * @return {Partial< import('@wordpress/sync').ObjectData >} Changes to record\n\t\t\t */\n\t\t\tgetPersistedCRDTDoc: ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\trecord?.meta?.[ POST_META_KEY_FOR_CRDT_DOC_PERSISTENCE ] ||\n\t\t\t\t\tnull\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\tconst entity = {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t\tgetTitle: ( record ) => record?.name,\n\t\t\tsupportsPagination: true,\n\t\t};\n\n\t\tentity.syncConfig = defaultSyncConfig;\n\n\t\treturn entity;\n\t} );\n}\n\n/**\n * Returns the Site entity.\n *\n * @return {Promise} Entity promise\n */\nasync function loadSiteEntity() {\n\tconst entity = {\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tkey: false,\n\t\tbaseURL: '/wp/v2/settings',\n\t\tmeta: {},\n\t};\n\n\tconst site = await apiFetch( {\n\t\tpath: entity.baseURL,\n\t\tmethod: 'OPTIONS',\n\t} );\n\n\tconst labels = {};\n\tObject.entries( site?.schema?.properties ?? {} ).forEach(\n\t\t( [ key, value ] ) => {\n\t\t\t// Ignore properties `title` and `type` keys.\n\t\t\tif ( typeof value === 'object' && value.title ) {\n\t\t\t\tlabels[ key ] = value.title;\n\t\t\t}\n\t\t}\n\t);\n\n\treturn [ { ...entity, meta: { labels } } ];\n}\n\n/**\n * Returns the entity's getter method name given its kind and name or plural name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'themes', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name or plural name.\n * @param {string} prefix Function prefix.\n *\n * @return {string} Method name\n */\nexport const getMethodName = ( kind, name, prefix = 'get' ) => {\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst suffix = pascalCase(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AE,EAAE,GAAG,QAAQ,MAAM,EAAE,OAAO,EAAE,CAAE;AAC1C;AAoBO,IAAM,gBAAgB,CAAE,MAAM,MAAM,SAAS,UAAW;AAC9D,QAAM,aAAa,SAAS,SAAS,KAAK,WAAY,IAAK;AAC3D,QAAM,SAAS,WAAY,IAAK;AAChC,SAAO,GAAI,MAAO,GAAI,UAAW,GAAI,MAAO;AAC7C;",
6
6
  "names": []
7
7
  }
@@ -19,7 +19,8 @@ function useEntityProp(kind, name, prop, _id) {
19
19
  id,
20
20
  {
21
21
  per_page: -1,
22
- context: "edit"
22
+ context: "edit",
23
+ _fields: "id,date,author,meta,title.raw,excerpt.raw,content.raw"
23
24
  }
24
25
  );
25
26
  const entityConfig = select(STORE_NAME).getEntityConfig(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-entity-prop.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useContext } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport { EntityContext } from '../entity-context';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst context = useContext( EntityContext );\n\tconst revisionId = context?.revisionId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( revisionId ) {\n\t\t\t\t// Use getRevisions (not getRevision) to read from the\n\t\t\t\t// already-cached collection. Using getRevision would\n\t\t\t\t// trigger a redundant single-revision API fetch that\n\t\t\t\t// can wipe the collection due to a race condition.\n\t\t\t\t// See https://github.com/WordPress/gutenberg/pull/76043.\n\t\t\t\tconst revisions = select( STORE_NAME ).getRevisions(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tcontext: 'edit',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tconst entityConfig = select( STORE_NAME ).getEntityConfig(\n\t\t\t\t\tkind,\n\t\t\t\t\tname\n\t\t\t\t);\n\t\t\t\tconst revKey = entityConfig?.revisionKey || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst revision = revisions?.find(\n\t\t\t\t\t( r ) => r[ revKey ] === revisionId\n\t\t\t\t);\n\t\t\t\treturn revision\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tvalue: revision[ prop ],\n\t\t\t\t\t\t\tfullValue: revision[ prop ],\n\t\t\t\t\t }\n\t\t\t\t\t: {};\n\t\t\t}\n\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop, revisionId ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\tif ( revisionId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\teditEntityRecord( kind, name, id, {\n\t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AAM,IAAI,MAAM,UAAW;AAAA,EACpC;AACA,QAAM,EAAE,iBAAiB,IAAI,YAAa,UAAW;AACrD,QAAM,WAAW;AAAA,IAChB,CAAE,aAAc;AACf,UAAK,YAAa;AACjB;AAAA,MACD;AACA,uBAAkB,MAAM,MAAM,IAAI;AAAA,QACjC,CAAE,IAAK,GAAG;AAAA,MACX,CAAE;AAAA,IACH;AAAA,IACA,CAAE,kBAAkB,MAAM,MAAM,IAAI,MAAM,UAAW;AAAA,EACtD;AAEA,SAAO,CAAE,OAAO,UAAU,SAAU;AACrC;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useContext } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport { EntityContext } from '../entity-context';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst context = useContext( EntityContext );\n\tconst revisionId = context?.revisionId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( revisionId ) {\n\t\t\t\t// Use getRevisions (not getRevision) to read from the\n\t\t\t\t// already-cached collection. Using getRevision would\n\t\t\t\t// trigger a redundant single-revision API fetch that\n\t\t\t\t// can wipe the collection due to a race condition.\n\t\t\t\t// See https://github.com/WordPress/gutenberg/pull/76043.\n\t\t\t\tconst revisions = select( STORE_NAME ).getRevisions(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t\t{\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t\tcontext: 'edit',\n\t\t\t\t\t\t_fields:\n\t\t\t\t\t\t\t'id,date,author,meta,title.raw,excerpt.raw,content.raw',\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t\tconst entityConfig = select( STORE_NAME ).getEntityConfig(\n\t\t\t\t\tkind,\n\t\t\t\t\tname\n\t\t\t\t);\n\t\t\t\tconst revKey = entityConfig?.revisionKey || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst revision = revisions?.find(\n\t\t\t\t\t( r ) => r[ revKey ] === revisionId\n\t\t\t\t);\n\t\t\t\treturn revision\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tvalue: revision[ prop ],\n\t\t\t\t\t\t\tfullValue: revision[ prop ],\n\t\t\t\t\t }\n\t\t\t\t\t: {};\n\t\t\t}\n\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop, revisionId ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\tif ( revisionId ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop, revisionId ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n"],
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ChB,CAAE,aAAc;AACf,UAAK,YAAa;AACjB;AAAA,MACD;AACA,uBAAkB,MAAM,MAAM,IAAI;AAAA,QACjC,CAAE,IAAK,GAAG;AAAA,MACX,CAAE;AAAA,IACH;AAAA,IACA,CAAE,kBAAkB,MAAM,MAAM,IAAI,MAAM,UAAW;AAAA,EACtD;AAEA,SAAO,CAAE,OAAO,UAAU,SAAU;AACrC;",
6
6
  "names": []
7
7
  }
@@ -1,8 +1,9 @@
1
1
  // packages/core-data/src/hooks/use-post-editor-awareness-state.ts
2
+ import { usePrevious } from "@wordpress/compose";
2
3
  import { useEffect, useState } from "@wordpress/element";
3
4
  import { getSyncManager } from "../sync.mjs";
4
5
  var defaultResolvedSelection = {
5
- textIndex: null,
6
+ richTextOffset: null,
6
7
  localClientId: null
7
8
  };
8
9
  var defaultState = {
@@ -100,11 +101,89 @@ function useLastPostSave(postId, postType) {
100
101
  }, [postId, postType]);
101
102
  return lastSave;
102
103
  }
104
+ function useOnCollaboratorJoin(postId, postType, callback) {
105
+ const { activeCollaborators } = usePostEditorAwarenessState(
106
+ postId,
107
+ postType
108
+ );
109
+ const prevCollaborators = usePrevious(activeCollaborators);
110
+ useEffect(() => {
111
+ if (!prevCollaborators || prevCollaborators.length === 0) {
112
+ return;
113
+ }
114
+ const prevMap = new Map(
115
+ prevCollaborators.map((collaborator) => [
116
+ collaborator.clientId,
117
+ collaborator
118
+ ])
119
+ );
120
+ const me = activeCollaborators.find(
121
+ (collaborator) => collaborator.isMe
122
+ );
123
+ for (const collaborator of activeCollaborators) {
124
+ if (!prevMap.has(collaborator.clientId) && !collaborator.isMe) {
125
+ callback(collaborator, me);
126
+ }
127
+ }
128
+ }, [activeCollaborators, prevCollaborators, callback]);
129
+ }
130
+ function useOnCollaboratorLeave(postId, postType, callback) {
131
+ const { activeCollaborators } = usePostEditorAwarenessState(
132
+ postId,
133
+ postType
134
+ );
135
+ const prevCollaborators = usePrevious(activeCollaborators);
136
+ useEffect(() => {
137
+ if (!prevCollaborators || prevCollaborators.length === 0) {
138
+ return;
139
+ }
140
+ const newMap = new Map(
141
+ activeCollaborators.map((collaborator) => [
142
+ collaborator.clientId,
143
+ collaborator
144
+ ])
145
+ );
146
+ for (const prevCollab of prevCollaborators) {
147
+ if (prevCollab.isMe || !prevCollab.isConnected) {
148
+ continue;
149
+ }
150
+ const newCollab = newMap.get(prevCollab.clientId);
151
+ if (!newCollab?.isConnected) {
152
+ callback(prevCollab);
153
+ }
154
+ }
155
+ }, [activeCollaborators, prevCollaborators, callback]);
156
+ }
157
+ function useOnPostSave(postId, postType, callback) {
158
+ const { activeCollaborators } = usePostEditorAwarenessState(
159
+ postId,
160
+ postType
161
+ );
162
+ const lastPostSave = useLastPostSave(postId, postType);
163
+ const prevPostSave = usePrevious(lastPostSave);
164
+ useEffect(() => {
165
+ if (!lastPostSave) {
166
+ return;
167
+ }
168
+ if (prevPostSave && lastPostSave.savedAt === prevPostSave.savedAt) {
169
+ return;
170
+ }
171
+ const saver = activeCollaborators.find(
172
+ (collaborator) => collaborator.clientId === lastPostSave.savedByClientId && !collaborator.isMe
173
+ );
174
+ if (!saver) {
175
+ return;
176
+ }
177
+ callback(lastPostSave, saver, prevPostSave ?? null);
178
+ }, [lastPostSave, prevPostSave, activeCollaborators, callback]);
179
+ }
103
180
  export {
104
181
  useActiveCollaborators,
105
182
  useGetDebugData,
106
183
  useIsDisconnected,
107
- useLastPostSave,
184
+ useOnCollaboratorJoin,
185
+ useOnCollaboratorLeave,
186
+ useOnPostSave,
108
187
  useResolvedSelection
109
188
  };
110
189
  //# sourceMappingURL=use-post-editor-awareness-state.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/use-post-editor-awareness-state.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport type { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { getSyncManager } from '../sync';\nimport type {\n\tPostEditorAwarenessState as ActiveCollaborator,\n\tPostSaveEvent,\n\tYDocDebugData,\n} from '../awareness/types';\nimport type { SelectionState } from '../types';\nimport type { PostEditorAwareness } from '../awareness/post-editor-awareness';\n\ninterface ResolvedSelection {\n\ttextIndex: number | null;\n\tlocalClientId: string | null;\n}\n\ninterface AwarenessState {\n\tactiveCollaborators: ActiveCollaborator[];\n\tresolveSelection: ( selection: SelectionState ) => ResolvedSelection;\n\tgetDebugData: () => YDocDebugData;\n\tisCurrentCollaboratorDisconnected: boolean;\n}\n\nconst defaultResolvedSelection: ResolvedSelection = {\n\ttextIndex: null,\n\tlocalClientId: null,\n};\n\nconst defaultState: AwarenessState = {\n\tactiveCollaborators: [],\n\tresolveSelection: () => defaultResolvedSelection,\n\tgetDebugData: () => ( {\n\t\tdoc: {},\n\t\tclients: {},\n\t\tcollaboratorMap: {},\n\t} ),\n\tisCurrentCollaboratorDisconnected: false,\n};\n\nfunction getAwarenessState(\n\tawareness: PostEditorAwareness,\n\tnewState?: ActiveCollaborator[]\n): AwarenessState {\n\tconst activeCollaborators = newState ?? awareness.getCurrentState();\n\n\treturn {\n\t\tactiveCollaborators,\n\t\tresolveSelection: ( selection: SelectionState ) =>\n\t\t\tawareness.convertSelectionStateToAbsolute( selection ),\n\t\tgetDebugData: () => awareness.getDebugData(),\n\t\tisCurrentCollaboratorDisconnected:\n\t\t\tactiveCollaborators.find( ( collaborator ) => collaborator.isMe )\n\t\t\t\t?.isConnected === false,\n\t};\n}\n\nfunction usePostEditorAwarenessState(\n\tpostId: number | null,\n\tpostType: string | null\n): AwarenessState {\n\tconst [ state, setState ] = useState< AwarenessState >( defaultState );\n\n\tuseEffect( () => {\n\t\tif ( null === postId || null === postType ) {\n\t\t\tsetState( defaultState );\n\t\t\treturn;\n\t\t}\n\n\t\tconst objectType = `postType/${ postType }`;\n\t\tconst objectId = postId.toString();\n\t\tconst awareness = getSyncManager()?.getAwareness< PostEditorAwareness >(\n\t\t\tobjectType,\n\t\t\tobjectId\n\t\t);\n\n\t\tif ( ! awareness ) {\n\t\t\tsetState( defaultState );\n\t\t\treturn;\n\t\t}\n\n\t\tawareness.setUp();\n\n\t\t// Initialize with current awareness state.\n\t\tsetState( getAwarenessState( awareness ) );\n\n\t\tconst unsubscribe = awareness?.onStateChange(\n\t\t\t( newState: ActiveCollaborator[] ) => {\n\t\t\t\tsetState( getAwarenessState( awareness, newState ) );\n\t\t\t}\n\t\t);\n\n\t\treturn unsubscribe;\n\t}, [ postId, postType ] );\n\n\treturn state;\n}\n\n/**\n * Hook to get the active collaborators for a post editor.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return {ActiveCollaborator[]} The active collaborators.\n */\nexport function useActiveCollaborators(\n\tpostId: number | null,\n\tpostType: string | null\n): ActiveCollaborator[] {\n\treturn usePostEditorAwarenessState( postId, postType ).activeCollaborators;\n}\n\n/**\n * Hook to resolve a selection state to a text index and block client ID.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return A function that resolves a selection to its text index and block client ID.\n */\nexport function useResolvedSelection(\n\tpostId: number | null,\n\tpostType: string | null\n): ( selection: SelectionState ) => ResolvedSelection {\n\treturn usePostEditorAwarenessState( postId, postType ).resolveSelection;\n}\n\n/**\n * Hook to get data for debugging, using the awareness state.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return {YDocDebugData} The debug data.\n */\nexport function useGetDebugData(\n\tpostId: number | null,\n\tpostType: string | null\n): YDocDebugData {\n\treturn usePostEditorAwarenessState( postId, postType ).getDebugData();\n}\n\n/**\n * Hook to check if the current collaborator is disconnected.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return {boolean} Whether the current collaborator is disconnected.\n */\nexport function useIsDisconnected(\n\tpostId: number | null,\n\tpostType: string | null\n): boolean {\n\treturn usePostEditorAwarenessState( postId, postType )\n\t\t.isCurrentCollaboratorDisconnected;\n}\n\n/**\n * Hook that subscribes to the CRDT state map and returns the most recent\n * save event (timestamp + client ID). The state map is updated by\n * `markEntityAsSaved` in `@wordpress/sync`\n *\n * @param postId The ID of the post.\n * @param postType The type of the post.\n */\nexport function useLastPostSave(\n\tpostId: number | null,\n\tpostType: string | null\n): PostSaveEvent | null {\n\tconst [ lastSave, setLastSave ] = useState< PostSaveEvent | null >( null );\n\n\tuseEffect( () => {\n\t\tif ( null === postId || null === postType ) {\n\t\t\tsetLastSave( null );\n\t\t\treturn;\n\t\t}\n\n\t\tconst awareness = getSyncManager()?.getAwareness< PostEditorAwareness >(\n\t\t\t`postType/${ postType }`,\n\t\t\tpostId.toString()\n\t\t);\n\n\t\tif ( ! awareness ) {\n\t\t\tsetLastSave( null );\n\t\t\treturn;\n\t\t}\n\n\t\tawareness.setUp();\n\n\t\tconst stateMap = awareness.doc.getMap( 'state' );\n\t\tconst recordMap = awareness.doc.getMap( 'document' );\n\n\t\t// Only notify for saves that occur after the observer is\n\t\t// set up. This prevents false notifications when the Y.Doc\n\t\t// syncs historical state on page load or peer reconnect.\n\t\tconst setupTime = Date.now();\n\n\t\tconst observer = ( event: Y.YMapEvent< unknown > ) => {\n\t\t\tif ( event.keysChanged.has( 'savedAt' ) ) {\n\t\t\t\tconst savedAt = stateMap.get( 'savedAt' ) as number;\n\t\t\t\tconst savedByClientId = stateMap.get( 'savedBy' ) as number;\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof savedAt === 'number' &&\n\t\t\t\t\ttypeof savedByClientId === 'number' &&\n\t\t\t\t\tsavedAt > setupTime\n\t\t\t\t) {\n\t\t\t\t\tconst postStatus = recordMap.get( 'status' ) as\n\t\t\t\t\t\t| string\n\t\t\t\t\t\t| undefined;\n\t\t\t\t\tsetLastSave( { savedAt, savedByClientId, postStatus } );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tstateMap.observe( observer );\n\n\t\treturn () => {\n\t\t\tstateMap.unobserve( observer );\n\t\t};\n\t}, [ postId, postType ] );\n\n\treturn lastSave;\n}\n"],
5
- "mappings": ";AAGA,SAAS,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AE;AACxD;AASO,SAAS,qBACf,QACA,UACqD;AACrD,SAAO,4BAA6B,QAAQ,QAAS,EAAE;AACxD;AASO,SAAS,gBACf,QACA,UACgB;AAChB,SAAO,4BAA6B,QAAQ,QAAS,EAAE,aAAa;AACrE;AASO,SAAS,kBACf,QACA,UACU;AACV,SAAO,4BAA6B,QAAQ,QAAS,EACnD;AACH;AAUO,SAAS,gBACf,QACA,UACuB;AACvB,QAAM,CAAE,UAAU,WAAY,IAAI,SAAkC,IAAK;AAEzE,YAAW,MAAM;AAChB,QAAK,SAAS,UAAU,SAAS,UAAW;AAC3C,kBAAa,IAAK;AAClB;AAAA,IACD;AAEA,UAAM,YAAY,eAAe,GAAG;AAAA,MACnC,YAAa,QAAS;AAAA,MACtB,OAAO,SAAS;AAAA,IACjB;AAEA,QAAK,CAAE,WAAY;AAClB,kBAAa,IAAK;AAClB;AAAA,IACD;AAEA,cAAU,MAAM;AAEhB,UAAM,WAAW,UAAU,IAAI,OAAQ,OAAQ;AAC/C,UAAM,YAAY,UAAU,IAAI,OAAQ,UAAW;AAKnD,UAAM,YAAY,KAAK,IAAI;AAE3B,UAAM,WAAW,CAAE,UAAmC;AACrD,UAAK,MAAM,YAAY,IAAK,SAAU,GAAI;AACzC,cAAM,UAAU,SAAS,IAAK,SAAU;AACxC,cAAM,kBAAkB,SAAS,IAAK,SAAU;AAEhD,YACC,OAAO,YAAY,YACnB,OAAO,oBAAoB,YAC3B,UAAU,WACT;AACD,gBAAM,aAAa,UAAU,IAAK,QAAS;AAG3C,sBAAa,EAAE,SAAS,iBAAiB,WAAW,CAAE;AAAA,QACvD;AAAA,MACD;AAAA,IACD;AAEA,aAAS,QAAS,QAAS;AAE3B,WAAO,MAAM;AACZ,eAAS,UAAW,QAAS;AAAA,IAC9B;AAAA,EACD,GAAG,CAAE,QAAQ,QAAS,CAAE;AAExB,SAAO;AACR;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { usePrevious } from '@wordpress/compose';\nimport { useEffect, useState } from '@wordpress/element';\nimport type { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { getSyncManager } from '../sync';\nimport type {\n\tPostEditorAwarenessState as ActiveCollaborator,\n\tPostSaveEvent,\n\tYDocDebugData,\n} from '../awareness/types';\nimport type { SelectionState, ResolvedSelection } from '../types';\nimport type { PostEditorAwareness } from '../awareness/post-editor-awareness';\n\ninterface AwarenessState {\n\tactiveCollaborators: ActiveCollaborator[];\n\tresolveSelection: ( selection: SelectionState ) => ResolvedSelection;\n\tgetDebugData: () => YDocDebugData;\n\tisCurrentCollaboratorDisconnected: boolean;\n}\n\nconst defaultResolvedSelection: ResolvedSelection = {\n\trichTextOffset: null,\n\tlocalClientId: null,\n};\n\nconst defaultState: AwarenessState = {\n\tactiveCollaborators: [],\n\tresolveSelection: () => defaultResolvedSelection,\n\tgetDebugData: () => ( {\n\t\tdoc: {},\n\t\tclients: {},\n\t\tcollaboratorMap: {},\n\t} ),\n\tisCurrentCollaboratorDisconnected: false,\n};\n\nfunction getAwarenessState(\n\tawareness: PostEditorAwareness,\n\tnewState?: ActiveCollaborator[]\n): AwarenessState {\n\tconst activeCollaborators = newState ?? awareness.getCurrentState();\n\n\treturn {\n\t\tactiveCollaborators,\n\t\tresolveSelection: ( selection: SelectionState ) =>\n\t\t\tawareness.convertSelectionStateToAbsolute( selection ),\n\t\tgetDebugData: () => awareness.getDebugData(),\n\t\tisCurrentCollaboratorDisconnected:\n\t\t\tactiveCollaborators.find( ( collaborator ) => collaborator.isMe )\n\t\t\t\t?.isConnected === false,\n\t};\n}\n\nfunction usePostEditorAwarenessState(\n\tpostId: number | null,\n\tpostType: string | null\n): AwarenessState {\n\tconst [ state, setState ] = useState< AwarenessState >( defaultState );\n\n\tuseEffect( () => {\n\t\tif ( null === postId || null === postType ) {\n\t\t\tsetState( defaultState );\n\t\t\treturn;\n\t\t}\n\n\t\tconst objectType = `postType/${ postType }`;\n\t\tconst objectId = postId.toString();\n\t\tconst awareness = getSyncManager()?.getAwareness< PostEditorAwareness >(\n\t\t\tobjectType,\n\t\t\tobjectId\n\t\t);\n\n\t\tif ( ! awareness ) {\n\t\t\tsetState( defaultState );\n\t\t\treturn;\n\t\t}\n\n\t\tawareness.setUp();\n\n\t\t// Initialize with current awareness state.\n\t\tsetState( getAwarenessState( awareness ) );\n\n\t\tconst unsubscribe = awareness?.onStateChange(\n\t\t\t( newState: ActiveCollaborator[] ) => {\n\t\t\t\tsetState( getAwarenessState( awareness, newState ) );\n\t\t\t}\n\t\t);\n\n\t\treturn unsubscribe;\n\t}, [ postId, postType ] );\n\n\treturn state;\n}\n\n/**\n * Hook to get the active collaborators for a post editor.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return {ActiveCollaborator[]} The active collaborators.\n */\nexport function useActiveCollaborators(\n\tpostId: number | null,\n\tpostType: string | null\n): ActiveCollaborator[] {\n\treturn usePostEditorAwarenessState( postId, postType ).activeCollaborators;\n}\n\n/**\n * Hook to resolve a selection state to a text index and block client ID.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return A function that resolves a selection to its text index and block client ID.\n */\nexport function useResolvedSelection(\n\tpostId: number | null,\n\tpostType: string | null\n): ( selection: SelectionState ) => ResolvedSelection {\n\treturn usePostEditorAwarenessState( postId, postType ).resolveSelection;\n}\n\n/**\n * Hook to get data for debugging, using the awareness state.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return {YDocDebugData} The debug data.\n */\nexport function useGetDebugData(\n\tpostId: number | null,\n\tpostType: string | null\n): YDocDebugData {\n\treturn usePostEditorAwarenessState( postId, postType ).getDebugData();\n}\n\n/**\n * Hook to check if the current collaborator is disconnected.\n *\n * @param postId - The ID of the post.\n * @param postType - The type of the post.\n * @return {boolean} Whether the current collaborator is disconnected.\n */\nexport function useIsDisconnected(\n\tpostId: number | null,\n\tpostType: string | null\n): boolean {\n\treturn usePostEditorAwarenessState( postId, postType )\n\t\t.isCurrentCollaboratorDisconnected;\n}\n\n/**\n * Hook that subscribes to the CRDT state map and returns the most recent\n * save event (timestamp + client ID). The state map is updated by\n * `markEntityAsSaved` in `@wordpress/sync`\n *\n * @param postId The ID of the post.\n * @param postType The type of the post.\n */\nfunction useLastPostSave(\n\tpostId: number | null,\n\tpostType: string | null\n): PostSaveEvent | null {\n\tconst [ lastSave, setLastSave ] = useState< PostSaveEvent | null >( null );\n\n\tuseEffect( () => {\n\t\tif ( null === postId || null === postType ) {\n\t\t\tsetLastSave( null );\n\t\t\treturn;\n\t\t}\n\n\t\tconst awareness = getSyncManager()?.getAwareness< PostEditorAwareness >(\n\t\t\t`postType/${ postType }`,\n\t\t\tpostId.toString()\n\t\t);\n\n\t\tif ( ! awareness ) {\n\t\t\tsetLastSave( null );\n\t\t\treturn;\n\t\t}\n\n\t\tawareness.setUp();\n\n\t\tconst stateMap = awareness.doc.getMap( 'state' );\n\t\tconst recordMap = awareness.doc.getMap( 'document' );\n\n\t\t// Only notify for saves that occur after the observer is\n\t\t// set up. This prevents false notifications when the Y.Doc\n\t\t// syncs historical state on page load or peer reconnect.\n\t\tconst setupTime = Date.now();\n\n\t\tconst observer = ( event: Y.YMapEvent< unknown > ) => {\n\t\t\tif ( event.keysChanged.has( 'savedAt' ) ) {\n\t\t\t\tconst savedAt = stateMap.get( 'savedAt' ) as number;\n\t\t\t\tconst savedByClientId = stateMap.get( 'savedBy' ) as number;\n\n\t\t\t\tif (\n\t\t\t\t\ttypeof savedAt === 'number' &&\n\t\t\t\t\ttypeof savedByClientId === 'number' &&\n\t\t\t\t\tsavedAt > setupTime\n\t\t\t\t) {\n\t\t\t\t\tconst postStatus = recordMap.get( 'status' ) as\n\t\t\t\t\t\t| string\n\t\t\t\t\t\t| undefined;\n\t\t\t\t\tsetLastSave( { savedAt, savedByClientId, postStatus } );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tstateMap.observe( observer );\n\n\t\treturn () => {\n\t\t\tstateMap.unobserve( observer );\n\t\t};\n\t}, [ postId, postType ] );\n\n\treturn lastSave;\n}\n\n/**\n * Hook that fires a callback when a new collaborator joins the post.\n * Handles initial hydration and state diffing internally\u2014consumers\n * only receive \"join\" events for collaborators that appear after the\n * initial state has loaded.\n *\n * The callback receives the joining collaborator and, when available,\n * the current user's state (useful for comparing `enteredAt` timestamps).\n *\n * @param postId The ID of the post.\n * @param postType The type of the post.\n * @param callback Invoked for each collaborator that joins.\n */\nexport function useOnCollaboratorJoin(\n\tpostId: number | null,\n\tpostType: string | null,\n\tcallback: (\n\t\tcollaborator: ActiveCollaborator,\n\t\tme?: ActiveCollaborator\n\t) => void\n): void {\n\tconst { activeCollaborators } = usePostEditorAwarenessState(\n\t\tpostId,\n\t\tpostType\n\t);\n\tconst prevCollaborators = usePrevious( activeCollaborators );\n\n\tuseEffect( () => {\n\t\t/*\n\t\t * On first render usePrevious returns undefined. On subsequent\n\t\t * renders the list may still be empty while the store hydrates.\n\t\t * In both cases, skip to avoid spurious \"joined\" callbacks for\n\t\t * users already present.\n\t\t */\n\t\tif ( ! prevCollaborators || prevCollaborators.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst prevMap = new Map< number, ActiveCollaborator >(\n\t\t\tprevCollaborators.map( ( collaborator ) => [\n\t\t\t\tcollaborator.clientId,\n\t\t\t\tcollaborator,\n\t\t\t] )\n\t\t);\n\t\tconst me = activeCollaborators.find(\n\t\t\t( collaborator ) => collaborator.isMe\n\t\t);\n\n\t\tfor ( const collaborator of activeCollaborators ) {\n\t\t\tif (\n\t\t\t\t! prevMap.has( collaborator.clientId ) &&\n\t\t\t\t! collaborator.isMe\n\t\t\t) {\n\t\t\t\tcallback( collaborator, me );\n\t\t\t}\n\t\t}\n\t}, [ activeCollaborators, prevCollaborators, callback ] );\n}\n\n/**\n * Hook that fires a callback when a collaborator leaves the post.\n * A \"leave\" is detected when a previously-connected collaborator either\n * transitions to `isConnected = false` or disappears from the list\n * entirely while still connected. Already-disconnected collaborators\n * that are later removed from the list are silently ignored.\n *\n * @param postId The ID of the post.\n * @param postType The type of the post.\n * @param callback Invoked for each collaborator that leaves.\n */\nexport function useOnCollaboratorLeave(\n\tpostId: number | null,\n\tpostType: string | null,\n\tcallback: ( collaborator: ActiveCollaborator ) => void\n): void {\n\tconst { activeCollaborators } = usePostEditorAwarenessState(\n\t\tpostId,\n\t\tpostType\n\t);\n\tconst prevCollaborators = usePrevious( activeCollaborators );\n\n\tuseEffect( () => {\n\t\tif ( ! prevCollaborators || prevCollaborators.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst newMap = new Map< number, ActiveCollaborator >(\n\t\t\tactiveCollaborators.map( ( collaborator ) => [\n\t\t\t\tcollaborator.clientId,\n\t\t\t\tcollaborator,\n\t\t\t] )\n\t\t);\n\n\t\tfor ( const prevCollab of prevCollaborators ) {\n\t\t\tif ( prevCollab.isMe || ! prevCollab.isConnected ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst newCollab = newMap.get( prevCollab.clientId );\n\t\t\tif ( ! newCollab?.isConnected ) {\n\t\t\t\tcallback( prevCollab );\n\t\t\t}\n\t\t}\n\t}, [ activeCollaborators, prevCollaborators, callback ] );\n}\n\n/**\n * Hook that fires a callback when a remote collaborator saves the post.\n * Only fires for saves by other collaborators (not the current user).\n * Deduplicates by `savedAt` timestamp so the same save event is never\n * reported twice.\n *\n * @param postId The ID of the post.\n * @param postType The type of the post.\n * @param callback Invoked with the save event, the collaborator who saved,\n * and the previous save event (if any) for transition detection.\n */\nexport function useOnPostSave(\n\tpostId: number | null,\n\tpostType: string | null,\n\tcallback: (\n\t\tevent: PostSaveEvent,\n\t\tsaver: ActiveCollaborator,\n\t\tprevEvent: PostSaveEvent | null\n\t) => void\n): void {\n\tconst { activeCollaborators } = usePostEditorAwarenessState(\n\t\tpostId,\n\t\tpostType\n\t);\n\tconst lastPostSave = useLastPostSave( postId, postType );\n\tconst prevPostSave = usePrevious( lastPostSave );\n\n\tuseEffect( () => {\n\t\tif ( ! lastPostSave ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( prevPostSave && lastPostSave.savedAt === prevPostSave.savedAt ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst saver = activeCollaborators.find(\n\t\t\t( collaborator ) =>\n\t\t\t\tcollaborator.clientId === lastPostSave.savedByClientId &&\n\t\t\t\t! collaborator.isMe\n\t\t);\n\n\t\tif ( ! saver ) {\n\t\t\treturn;\n\t\t}\n\n\t\tcallback( lastPostSave, saver, prevPostSave ?? null );\n\t}, [ lastPostSave, prevPostSave, activeCollaborators, callback ] );\n}\n"],
5
+ "mappings": ";AAGA,SAAS,mBAAmB;AAC5B,SAAS,WAAW,gBAAgB;AAMpC,SAAS,sBAAsB;AAgB/B,IAAM,2BAA8C;AAAA,EACnD,gBAAgB;AAAA,EAChB,eAAe;AAChB;AAEA,IAAM,eAA+B;AAAA,EACpC,qBAAqB,CAAC;AAAA,EACtB,kBAAkB,MAAM;AAAA,EACxB,cAAc,OAAQ;AAAA,IACrB,KAAK,CAAC;AAAA,IACN,SAAS,CAAC;AAAA,IACV,iBAAiB,CAAC;AAAA,EACnB;AAAA,EACA,mCAAmC;AACpC;AAEA,SAAS,kBACR,WACA,UACiB;AACjB,QAAM,sBAAsB,YAAY,UAAU,gBAAgB;AAElE,SAAO;AAAA,IACN;AAAA,IACA,kBAAkB,CAAE,cACnB,UAAU,gCAAiC,SAAU;AAAA,IACtD,cAAc,MAAM,UAAU,aAAa;AAAA,IAC3C,mCACC,oBAAoB,KAAM,CAAE,iBAAkB,aAAa,IAAK,GAC7D,gBAAgB;AAAA,EACrB;AACD;AAEA,SAAS,4BACR,QACA,UACiB;AACjB,QAAM,CAAE,OAAO,QAAS,IAAI,SAA4B,YAAa;AAErE,YAAW,MAAM;AAChB,QAAK,SAAS,UAAU,SAAS,UAAW;AAC3C,eAAU,YAAa;AACvB;AAAA,IACD;AAEA,UAAM,aAAa,YAAa,QAAS;AACzC,UAAM,WAAW,OAAO,SAAS;AACjC,UAAM,YA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AAAA,QAC5C,aAAa;AAAA,QACb;AAAA,MACD,CAAE;AAAA,IACH;AAEA,eAAY,cAAc,mBAAoB;AAC7C,UAAK,WAAW,QAAQ,CAAE,WAAW,aAAc;AAClD;AAAA,MACD;AAEA,YAAM,YAAY,OAAO,IAAK,WAAW,QAAS;AAClD,UAAK,CAAE,WAAW,aAAc;AAC/B,iBAAU,UAAW;AAAA,MACtB;AAAA,IACD;AAAA,EACD,GAAG,CAAE,qBAAqB,mBAAmB,QAAS,CAAE;AACzD;AAaO,SAAS,cACf,QACA,UACA,UAKO;AACP,QAAM,EAAE,oBAAoB,IAAI;AAAA,IAC/B;AAAA,IACA;AAAA,EACD;AACA,QAAM,eAAe,gBAAiB,QAAQ,QAAS;AACvD,QAAM,eAAe,YAAa,YAAa;AAE/C,YAAW,MAAM;AAChB,QAAK,CAAE,cAAe;AACrB;AAAA,IACD;AAEA,QAAK,gBAAgB,aAAa,YAAY,aAAa,SAAU;AACpE;AAAA,IACD;AAEA,UAAM,QAAQ,oBAAoB;AAAA,MACjC,CAAE,iBACD,aAAa,aAAa,aAAa,mBACvC,CAAE,aAAa;AAAA,IACjB;AAEA,QAAK,CAAE,OAAQ;AACd;AAAA,IACD;AAEA,aAAU,cAAc,OAAO,gBAAgB,IAAK;AAAA,EACrD,GAAG,CAAE,cAAc,cAAc,qBAAqB,QAAS,CAAE;AAClE;",
6
6
  "names": []
7
7
  }
@@ -17,6 +17,7 @@ import { unlock } from "./lock-unlock.mjs";
17
17
  import { dynamicActions, dynamicSelectors } from "./dynamic-entities.mjs";
18
18
  import logEntityDeprecation from "./utils/log-entity-deprecation.mjs";
19
19
  import { SelectionType } from "./utils/crdt-user-selections.mjs";
20
+ import { SelectionDirection } from "./types.mjs";
20
21
  import { default as default2 } from "./entity-provider.mjs";
21
22
  export * from "./entity-provider.mjs";
22
23
  export * from "./entity-types/index.mjs";
@@ -115,6 +116,7 @@ unlock(store).registerPrivateActions(privateActions);
115
116
  register(store);
116
117
  export {
117
118
  default2 as EntityProvider,
119
+ SelectionDirection,
118
120
  SelectionType,
119
121
  store
120
122
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( state, key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn selectors.getEntityRecord( state, kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( state, query ) => {\n\t\t\tlogEntityDeprecation( kind, name, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn selectors.getEntityRecords( state, kind, name, query );\n\t\t};\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn resolvers.getEntityRecord( kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( ...args ) => {\n\t\t\tlogEntityDeprecation( kind, plural, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn resolvers.getEntityRecords( kind, name, ...args );\n\t\t};\n\t\tresult[ getEntityRecordsMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\n\tconst saveEntityRecordMethodName = getMethodName( kind, name, 'save' );\n\tresult[ saveEntityRecordMethodName ] = ( record, options ) => {\n\t\tlogEntityDeprecation( kind, name, saveEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'saveEntityRecord',\n\t\t} );\n\t\treturn actions.saveEntityRecord( kind, name, record, options );\n\t};\n\n\tconst deleteEntityRecordMethodName = getMethodName( kind, name, 'delete' );\n\tresult[ deleteEntityRecordMethodName ] = ( key, query, options ) => {\n\t\tlogEntityDeprecation( kind, name, deleteEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'deleteEntityRecord',\n\t\t} );\n\t\treturn actions.deleteEntityRecord( kind, name, key, query, options );\n\t};\n\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nunlock( store ).registerPrivateActions( privateActions );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\n/**\n * Enums cannot be exported private without losing the ability to narrow types\n * based on their values (they blur to string type).\n */\nexport { SelectionType } from './utils/crdt-user-selections';\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './awareness/types';\nexport * from './fetch';\nexport * from './hooks';\nexport * from './private-apis';\nexport * from './types';\n"],
5
- "mappings": ";AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,aAAa;AACzB,YAAY,oBAAoB;AAChC,YAAY,eAAe;AAC3B,OAAO,wBAAwB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,gBAAgB,wBAAwB;AACjD,OAAO,0BAA0B;AAoHjC,SAAS,qBAAqB;AAE9B,SAAoB,WAAXA,gBAAiC;AAC1C,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd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,KAAM,EAAE,yBAA0B,gBAAiB;AAC3D,OAAQ,KAAM,EAAE,uBAAwB,cAAe;AACvD,SAAU,KAAM;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( state, key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn selectors.getEntityRecord( state, kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( state, query ) => {\n\t\t\tlogEntityDeprecation( kind, name, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn selectors.getEntityRecords( state, kind, name, query );\n\t\t};\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn resolvers.getEntityRecord( kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( ...args ) => {\n\t\t\tlogEntityDeprecation( kind, plural, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn resolvers.getEntityRecords( kind, name, ...args );\n\t\t};\n\t\tresult[ getEntityRecordsMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\n\tconst saveEntityRecordMethodName = getMethodName( kind, name, 'save' );\n\tresult[ saveEntityRecordMethodName ] = ( record, options ) => {\n\t\tlogEntityDeprecation( kind, name, saveEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'saveEntityRecord',\n\t\t} );\n\t\treturn actions.saveEntityRecord( kind, name, record, options );\n\t};\n\n\tconst deleteEntityRecordMethodName = getMethodName( kind, name, 'delete' );\n\tresult[ deleteEntityRecordMethodName ] = ( key, query, options ) => {\n\t\tlogEntityDeprecation( kind, name, deleteEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'deleteEntityRecord',\n\t\t} );\n\t\treturn actions.deleteEntityRecord( kind, name, key, query, options );\n\t};\n\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nunlock( store ).registerPrivateActions( privateActions );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\n/**\n * Enums cannot be exported private without losing the ability to narrow types\n * based on their values (they blur to string type).\n */\nexport { SelectionType } from './utils/crdt-user-selections';\nexport { SelectionDirection } from './types';\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './awareness/types';\nexport * from './fetch';\nexport * from './hooks';\nexport * from './private-apis';\nexport * from './types';\n"],
5
+ "mappings": ";AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,aAAa;AACzB,YAAY,oBAAoB;AAChC,YAAY,eAAe;AAC3B,OAAO,wBAAwB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,gBAAgB,wBAAwB;AACjD,OAAO,0BAA0B;AAoHjC,SAAS,qBAAqB;AAC9B,SAAS,0BAA0B;AAEnC,SAAoB,WAAXA,gBAAiC;AAC1C,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cA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,OAAQ,KAAM,EAAE,yBAA0B,gBAAiB;AAC3D,OAAQ,KAAM,EAAE,uBAAwB,cAAe;AACvD,SAAU,KAAM;",
6
6
  "names": ["default"]
7
7
  }
@@ -4,7 +4,9 @@ import { RECEIVE_INTERMEDIATE_RESULTS } from "./utils/index.mjs";
4
4
  import {
5
5
  useActiveCollaborators,
6
6
  useResolvedSelection,
7
- useLastPostSave
7
+ useOnCollaboratorJoin,
8
+ useOnCollaboratorLeave,
9
+ useOnPostSave
8
10
  } from "./hooks/use-post-editor-awareness-state.mjs";
9
11
  import { lock } from "./lock-unlock.mjs";
10
12
  import { retrySyncConnection } from "./sync.mjs";
@@ -15,7 +17,9 @@ lock(privateApis, {
15
17
  retrySyncConnection,
16
18
  useActiveCollaborators,
17
19
  useResolvedSelection,
18
- useLastPostSave
20
+ useOnCollaboratorJoin,
21
+ useOnCollaboratorLeave,
22
+ useOnPostSave
19
23
  });
20
24
  export {
21
25
  privateApis
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/private-apis.js"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { useEntityRecordsWithPermissions } from './hooks/use-entity-records';\nimport { RECEIVE_INTERMEDIATE_RESULTS } from './utils';\nimport {\n\tuseActiveCollaborators,\n\tuseResolvedSelection,\n\tuseLastPostSave,\n} from './hooks/use-post-editor-awareness-state';\nimport { lock } from './lock-unlock';\nimport { retrySyncConnection } from './sync';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseEntityRecordsWithPermissions,\n\tRECEIVE_INTERMEDIATE_RESULTS,\n\tretrySyncConnection,\n\tuseActiveCollaborators,\n\tuseResolvedSelection,\n\tuseLastPostSave,\n} );\n"],
5
- "mappings": ";AAGA,SAAS,uCAAuC;AAChD,SAAS,oCAAoC;AAC7C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,YAAY;AACrB,SAAS,2BAA2B;AAE7B,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { useEntityRecordsWithPermissions } from './hooks/use-entity-records';\nimport { RECEIVE_INTERMEDIATE_RESULTS } from './utils';\nimport {\n\tuseActiveCollaborators,\n\tuseResolvedSelection,\n\tuseOnCollaboratorJoin,\n\tuseOnCollaboratorLeave,\n\tuseOnPostSave,\n} from './hooks/use-post-editor-awareness-state';\nimport { lock } from './lock-unlock';\nimport { retrySyncConnection } from './sync';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseEntityRecordsWithPermissions,\n\tRECEIVE_INTERMEDIATE_RESULTS,\n\tretrySyncConnection,\n\tuseActiveCollaborators,\n\tuseResolvedSelection,\n\tuseOnCollaboratorJoin,\n\tuseOnCollaboratorLeave,\n\tuseOnPostSave,\n} );\n"],
5
+ "mappings": ";AAGA,SAAS,uCAAuC;AAChD,SAAS,oCAAoC;AAC7C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,YAAY;AACrB,SAAS,2BAA2B;AAE7B,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
6
6
  "names": []
7
7
  }
@@ -6,6 +6,7 @@ function getQueryParts(query) {
6
6
  stableKey: "",
7
7
  page: 1,
8
8
  perPage: 10,
9
+ offset: void 0,
9
10
  fields: null,
10
11
  include: null,
11
12
  context: "default"
@@ -25,6 +26,12 @@ function getQueryParts(query) {
25
26
  parts.context = value;
26
27
  break;
27
28
  default:
29
+ if (key === "offset") {
30
+ const numericOffset = Number(value);
31
+ if (Number.isFinite(numericOffset)) {
32
+ parts.offset = numericOffset;
33
+ }
34
+ }
28
35
  if (key === "_fields") {
29
36
  parts.fields = getNormalizedCommaSeparable(value) ?? [];
30
37
  value = parts.fields.join();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/queried-data/get-query-parts.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],
5
- "mappings": ";AAGA,SAAS,oBAAoB;AAK7B,SAAS,kBAAkB,mCAAmC;AA2BvD,SAAS,cAAe,OAAQ;AAItC,QAAM,QAAQ;AAAA,IACb,WAAW;AAAA,IACX,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACV;AAGA,QAAM,OAAO,OAAO,KAAM,KAAM,EAAE,KAAK;AAEvC,WAAU,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAM;AACvC,UAAM,MAAM,KAAM,CAAE;AACpB,QAAI,QAAQ,MAAO,GAAI;AAEvB,YAAS,KAAM;AAAA,MACd,KAAK;AACJ,cAAO,GAAI,IAAI,OAAQ,KAAM;AAC7B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU,OAAQ,KAAM;AAC9B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU;AAChB;AAAA,MAED;AAMC,YAAK,QAAQ,WAAY;AACxB,gBAAM,SAAS,4BAA6B,KAAM,KAAK,CAAC;AAExD,kBAAQ,MAAM,OAAO,KAAK;AAAA,QAC3B;AAGA,YAAK,QAAQ,WAAY;AACxB,cAAK,OAAO,UAAU,UAAW;AAChC,oBAAQ,MAAM,SAAS;AAAA,UACxB;AACA,gBAAM,WACL,4BAA6B,KAAM,KAAK,CAAC,GACxC,IAAK,MAAO;AAEd,kBAAQ,MAAM,QAAQ,KAAK;AAAA,QAC5B;AASA,cAAM,cACH,MAAM,YAAY,MAAM,MAC1B,aAAc,IAAI,EAAE,CAAE,GAAI,GAAG,MAAM,CAAE,EAAE,MAAO,CAAE;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,0BAAQ,iBAAkB,aAAc;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {number} offset Absolute item offset (default undefined).\n * When present, also encoded into stableKey.\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\toffset: undefined,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// Extract offset for use in pagination calculations while\n\t\t\t\t// still including it in the stableKey (different offsets\n\t\t\t\t// produce different result sets).\n\t\t\t\tif ( key === 'offset' ) {\n\t\t\t\t\tconst numericOffset = Number( value );\n\t\t\t\t\tif ( Number.isFinite( numericOffset ) ) {\n\t\t\t\t\t\tparts.offset = numericOffset;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],
5
+ "mappings": ";AAGA,SAAS,oBAAoB;AAK7B,SAAS,kBAAkB,mCAAmC;AA6BvD,SAAS,cAAe,OAAQ;AAItC,QAAM,QAAQ;AAAA,IACb,WAAW;AAAA,IACX,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACV;AAGA,QAAM,OAAO,OAAO,KAAM,KAAM,EAAE,KAAK;AAEvC,WAAU,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAM;AACvC,UAAM,MAAM,KAAM,CAAE;AACpB,QAAI,QAAQ,MAAO,GAAI;AAEvB,YAAS,KAAM;AAAA,MACd,KAAK;AACJ,cAAO,GAAI,IAAI,OAAQ,KAAM;AAC7B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU,OAAQ,KAAM;AAC9B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU;AAChB;AAAA,MAED;AAIC,YAAK,QAAQ,UAAW;AACvB,gBAAM,gBAAgB,OAAQ,KAAM;AACpC,cAAK,OAAO,SAAU,aAAc,GAAI;AACvC,kBAAM,SAAS;AAAA,UAChB;AAAA,QACD;AAOA,YAAK,QAAQ,WAAY;AACxB,gBAAM,SAAS,4BAA6B,KAAM,KAAK,CAAC;AAExD,kBAAQ,MAAM,OAAO,KAAK;AAAA,QAC3B;AAGA,YAAK,QAAQ,WAAY;AACxB,cAAK,OAAO,UAAU,UAAW;AAChC,oBAAQ,MAAM,SAAS;AAAA,UACxB;AACA,gBAAM,WACL,4BAA6B,KAAM,KAAK,CAAC,GACxC,IAAK,MAAO;AAEd,kBAAQ,MAAM,QAAQ,KAAK;AAAA,QAC5B;AASA,cAAM,cACH,MAAM,YAAY,MAAM,MAC1B,aAAc,IAAI,EAAE,CAAE,GAAI,GAAG,MAAM,CAAE,EAAE,MAAO,CAAE;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,0BAAQ,iBAAkB,aAAc;",
6
6
  "names": []
7
7
  }
@@ -5,16 +5,30 @@ import getQueryParts from "./get-query-parts.mjs";
5
5
  import { setNestedValue } from "../utils/index.mjs";
6
6
  var queriedItemsCacheByState = /* @__PURE__ */ new WeakMap();
7
7
  function getQueriedItemsUncached(state, query) {
8
- const { stableKey, page, perPage, include, fields, context } = getQueryParts(query);
9
- let itemIds;
10
- if (state.queries?.[context]?.[stableKey]) {
11
- itemIds = state.queries[context][stableKey].itemIds;
12
- }
8
+ const {
9
+ stableKey,
10
+ page,
11
+ perPage,
12
+ offset: queryOffset,
13
+ include,
14
+ fields,
15
+ context
16
+ } = getQueryParts(query);
17
+ const itemIds = state.queries?.[context]?.[stableKey]?.itemIds;
13
18
  if (!itemIds) {
14
19
  return null;
15
20
  }
16
21
  const startOffset = perPage === -1 ? 0 : (page - 1) * perPage;
17
22
  const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length);
23
+ if (perPage !== -1 && itemIds.length < startOffset + perPage) {
24
+ const totalItems = state.queries[context][stableKey].meta?.totalItems;
25
+ if (Number.isFinite(totalItems)) {
26
+ const effectiveTotal = queryOffset !== void 0 ? totalItems - queryOffset : totalItems;
27
+ if (itemIds.length < effectiveTotal) {
28
+ return null;
29
+ }
30
+ }
31
+ }
18
32
  const items = [];
19
33
  for (let i = startOffset; i < endOffset; i++) {
20
34
  const itemId = itemIds[i];