@wordpress/core-data 7.51.0 → 7.53.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 (494) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +1 -0
  3. package/build/actions.cjs +64 -2
  4. package/build/actions.cjs.map +3 -3
  5. package/build/awareness/awareness-state.cjs.map +2 -2
  6. package/build/awareness/base-awareness.cjs.map +2 -2
  7. package/build/awareness/block-lookup.cjs.map +2 -2
  8. package/build/awareness/post-editor-awareness.cjs +7 -0
  9. package/build/awareness/post-editor-awareness.cjs.map +2 -2
  10. package/build/awareness/typed-awareness.cjs.map +2 -2
  11. package/build/awareness/types.cjs.map +1 -1
  12. package/build/awareness/utils.cjs.map +2 -2
  13. package/build/batch/create-batch.cjs.map +2 -2
  14. package/build/batch/default-processor.cjs.map +2 -2
  15. package/build/components/entities-saved-states/entity-record-item.cjs +67 -0
  16. package/build/components/entities-saved-states/entity-record-item.cjs.map +7 -0
  17. package/build/components/entities-saved-states/entity-type-list.cjs +135 -0
  18. package/build/components/entities-saved-states/entity-type-list.cjs.map +7 -0
  19. package/build/components/entities-saved-states/hooks/use-is-dirty.cjs +101 -0
  20. package/build/components/entities-saved-states/hooks/use-is-dirty.cjs.map +7 -0
  21. package/build/components/entities-saved-states/index.cjs +215 -0
  22. package/build/components/entities-saved-states/index.cjs.map +7 -0
  23. package/build/dynamic-entities.cjs.map +2 -2
  24. package/build/entities.cjs +2 -0
  25. package/build/entities.cjs.map +2 -2
  26. package/build/entity-context.cjs.map +2 -2
  27. package/build/entity-provider.cjs.map +2 -2
  28. package/build/entity-types/attachment.cjs.map +1 -1
  29. package/build/entity-types/base.cjs.map +1 -1
  30. package/build/entity-types/comment.cjs.map +1 -1
  31. package/build/entity-types/font-collection.cjs.map +1 -1
  32. package/build/entity-types/font-family.cjs.map +1 -1
  33. package/build/entity-types/global-styles-revision.cjs.map +1 -1
  34. package/build/entity-types/helpers.cjs.map +1 -1
  35. package/build/entity-types/icon.cjs.map +1 -1
  36. package/build/entity-types/index.cjs.map +1 -1
  37. package/build/entity-types/menu-location.cjs.map +1 -1
  38. package/build/entity-types/nav-menu-item.cjs.map +1 -1
  39. package/build/entity-types/nav-menu.cjs.map +1 -1
  40. package/build/entity-types/page.cjs.map +1 -1
  41. package/build/entity-types/plugin.cjs.map +1 -1
  42. package/build/entity-types/post-revision.cjs.map +1 -1
  43. package/build/entity-types/post-status.cjs.map +1 -1
  44. package/build/entity-types/post.cjs.map +1 -1
  45. package/build/entity-types/settings.cjs.map +1 -1
  46. package/build/entity-types/sidebar.cjs.map +1 -1
  47. package/build/entity-types/taxonomy.cjs.map +1 -1
  48. package/build/entity-types/term.cjs.map +1 -1
  49. package/build/entity-types/theme.cjs.map +1 -1
  50. package/build/entity-types/type.cjs.map +1 -1
  51. package/build/entity-types/user.cjs.map +1 -1
  52. package/build/entity-types/widget-type.cjs.map +1 -1
  53. package/build/entity-types/widget.cjs.map +1 -1
  54. package/build/entity-types/wp-template-part.cjs.map +1 -1
  55. package/build/entity-types/wp-template.cjs.map +1 -1
  56. package/build/fetch/__experimental-fetch-link-suggestions.cjs.map +2 -2
  57. package/build/fetch/__experimental-fetch-url-data.cjs.map +2 -2
  58. package/build/fetch/index.cjs.map +2 -2
  59. package/build/footnotes/get-footnotes-order.cjs.map +2 -2
  60. package/build/footnotes/get-rich-text-values-cached.cjs.map +2 -2
  61. package/build/footnotes/index.cjs +12 -1
  62. package/build/footnotes/index.cjs.map +3 -3
  63. package/build/hooks/index.cjs.map +2 -2
  64. package/build/hooks/use-entity-block-editor.cjs.map +2 -2
  65. package/build/hooks/use-entity-id.cjs.map +2 -2
  66. package/build/hooks/use-entity-prop.cjs.map +2 -2
  67. package/build/hooks/use-entity-record.cjs.map +2 -2
  68. package/build/hooks/use-entity-records.cjs +2 -2
  69. package/build/hooks/use-entity-records.cjs.map +2 -2
  70. package/build/hooks/use-post-editor-awareness-state.cjs.map +2 -2
  71. package/build/hooks/use-query-select.cjs.map +2 -2
  72. package/build/hooks/use-resource-permissions.cjs.map +2 -2
  73. package/build/hooks/utils.cjs.map +2 -2
  74. package/build/index.cjs.map +2 -2
  75. package/build/lock-unlock.cjs.map +2 -2
  76. package/build/locks/actions.cjs.map +2 -2
  77. package/build/locks/engine.cjs.map +2 -2
  78. package/build/locks/reducer.cjs.map +2 -2
  79. package/build/locks/selectors.cjs.map +2 -2
  80. package/build/private-actions.cjs +132 -0
  81. package/build/private-actions.cjs.map +3 -3
  82. package/build/private-apis.cjs +22 -0
  83. package/build/private-apis.cjs.map +3 -3
  84. package/build/private-selectors.cjs +5 -0
  85. package/build/private-selectors.cjs.map +2 -2
  86. package/build/queried-data/get-query-parts.cjs.map +2 -2
  87. package/build/queried-data/reducer.cjs.map +2 -2
  88. package/build/queried-data/selectors.cjs.map +2 -2
  89. package/build/reducer.cjs.map +2 -2
  90. package/build/resolvers.cjs +21 -26
  91. package/build/resolvers.cjs.map +2 -2
  92. package/build/selectors.cjs.map +2 -2
  93. package/build/sync.cjs +26 -0
  94. package/build/sync.cjs.map +2 -2
  95. package/build/types.cjs.map +1 -1
  96. package/build/utils/block-selection-history.cjs.map +2 -2
  97. package/build/utils/clear-unchanged-edits.cjs.map +2 -2
  98. package/build/utils/conservative-map-item.cjs.map +2 -2
  99. package/build/utils/crdt-blocks.cjs.map +2 -2
  100. package/build/utils/crdt-selection.cjs.map +2 -2
  101. package/build/utils/crdt-text.cjs.map +2 -2
  102. package/build/utils/crdt-user-selections.cjs +43 -16
  103. package/build/utils/crdt-user-selections.cjs.map +3 -3
  104. package/build/utils/crdt-utils.cjs.map +2 -2
  105. package/build/utils/crdt.cjs +4 -2
  106. package/build/utils/crdt.cjs.map +2 -2
  107. package/build/utils/get-template-info.cjs +53 -0
  108. package/build/utils/get-template-info.cjs.map +7 -0
  109. package/build/utils/get-template-part-icon.cjs +43 -0
  110. package/build/utils/get-template-part-icon.cjs.map +7 -0
  111. package/build/utils/log-entity-deprecation.cjs.map +2 -2
  112. package/build/utils/save-crdt-doc.cjs.map +2 -2
  113. package/build-module/actions.mjs +68 -2
  114. package/build-module/actions.mjs.map +2 -2
  115. package/build-module/awareness/awareness-state.mjs.map +2 -2
  116. package/build-module/awareness/base-awareness.mjs.map +2 -2
  117. package/build-module/awareness/block-lookup.mjs.map +2 -2
  118. package/build-module/awareness/post-editor-awareness.mjs +7 -0
  119. package/build-module/awareness/post-editor-awareness.mjs.map +2 -2
  120. package/build-module/awareness/typed-awareness.mjs.map +2 -2
  121. package/build-module/awareness/utils.mjs.map +2 -2
  122. package/build-module/batch/create-batch.mjs.map +2 -2
  123. package/build-module/batch/default-processor.mjs.map +2 -2
  124. package/build-module/components/entities-saved-states/entity-record-item.mjs +46 -0
  125. package/build-module/components/entities-saved-states/entity-record-item.mjs.map +7 -0
  126. package/build-module/components/entities-saved-states/entity-type-list.mjs +104 -0
  127. package/build-module/components/entities-saved-states/entity-type-list.mjs.map +7 -0
  128. package/build-module/components/entities-saved-states/hooks/use-is-dirty.mjs +76 -0
  129. package/build-module/components/entities-saved-states/hooks/use-is-dirty.mjs.map +7 -0
  130. package/build-module/components/entities-saved-states/index.mjs +187 -0
  131. package/build-module/components/entities-saved-states/index.mjs.map +7 -0
  132. package/build-module/dynamic-entities.mjs.map +2 -2
  133. package/build-module/entities.mjs +2 -0
  134. package/build-module/entities.mjs.map +2 -2
  135. package/build-module/entity-context.mjs.map +2 -2
  136. package/build-module/entity-provider.mjs.map +2 -2
  137. package/build-module/fetch/__experimental-fetch-link-suggestions.mjs.map +2 -2
  138. package/build-module/fetch/__experimental-fetch-url-data.mjs.map +2 -2
  139. package/build-module/fetch/index.mjs.map +2 -2
  140. package/build-module/footnotes/get-footnotes-order.mjs.map +2 -2
  141. package/build-module/footnotes/get-rich-text-values-cached.mjs.map +2 -2
  142. package/build-module/footnotes/index.mjs +12 -1
  143. package/build-module/footnotes/index.mjs.map +2 -2
  144. package/build-module/hooks/index.mjs.map +2 -2
  145. package/build-module/hooks/use-entity-block-editor.mjs.map +2 -2
  146. package/build-module/hooks/use-entity-id.mjs.map +2 -2
  147. package/build-module/hooks/use-entity-prop.mjs.map +2 -2
  148. package/build-module/hooks/use-entity-record.mjs.map +2 -2
  149. package/build-module/hooks/use-entity-records.mjs +2 -2
  150. package/build-module/hooks/use-entity-records.mjs.map +2 -2
  151. package/build-module/hooks/use-post-editor-awareness-state.mjs.map +2 -2
  152. package/build-module/hooks/use-query-select.mjs.map +2 -2
  153. package/build-module/hooks/use-resource-permissions.mjs.map +2 -2
  154. package/build-module/hooks/utils.mjs.map +2 -2
  155. package/build-module/index.mjs.map +2 -2
  156. package/build-module/lock-unlock.mjs.map +2 -2
  157. package/build-module/locks/actions.mjs.map +2 -2
  158. package/build-module/locks/engine.mjs.map +2 -2
  159. package/build-module/locks/reducer.mjs.map +2 -2
  160. package/build-module/locks/selectors.mjs.map +2 -2
  161. package/build-module/private-actions.mjs +131 -0
  162. package/build-module/private-actions.mjs.map +2 -2
  163. package/build-module/private-apis.mjs +21 -1
  164. package/build-module/private-apis.mjs.map +2 -2
  165. package/build-module/private-selectors.mjs +4 -0
  166. package/build-module/private-selectors.mjs.map +2 -2
  167. package/build-module/queried-data/get-query-parts.mjs.map +2 -2
  168. package/build-module/queried-data/reducer.mjs.map +2 -2
  169. package/build-module/queried-data/selectors.mjs.map +2 -2
  170. package/build-module/reducer.mjs.map +2 -2
  171. package/build-module/resolvers.mjs +21 -26
  172. package/build-module/resolvers.mjs.map +2 -2
  173. package/build-module/selectors.mjs.map +2 -2
  174. package/build-module/sync.mjs +23 -0
  175. package/build-module/sync.mjs.map +2 -2
  176. package/build-module/utils/block-selection-history.mjs.map +2 -2
  177. package/build-module/utils/clear-unchanged-edits.mjs.map +2 -2
  178. package/build-module/utils/conservative-map-item.mjs.map +2 -2
  179. package/build-module/utils/crdt-blocks.mjs.map +2 -2
  180. package/build-module/utils/crdt-selection.mjs.map +2 -2
  181. package/build-module/utils/crdt-text.mjs.map +2 -2
  182. package/build-module/utils/crdt-user-selections.mjs +43 -16
  183. package/build-module/utils/crdt-user-selections.mjs.map +3 -3
  184. package/build-module/utils/crdt-utils.mjs.map +2 -2
  185. package/build-module/utils/crdt.mjs +2 -1
  186. package/build-module/utils/crdt.mjs.map +2 -2
  187. package/build-module/utils/get-template-info.mjs +28 -0
  188. package/build-module/utils/get-template-info.mjs.map +7 -0
  189. package/build-module/utils/get-template-part-icon.mjs +24 -0
  190. package/build-module/utils/get-template-part-icon.mjs.map +7 -0
  191. package/build-module/utils/log-entity-deprecation.mjs.map +2 -2
  192. package/build-module/utils/save-crdt-doc.mjs.map +2 -2
  193. package/build-types/actions.d.ts +4 -0
  194. package/build-types/actions.d.ts.map +1 -1
  195. package/build-types/awareness/awareness-state.d.ts.map +1 -1
  196. package/build-types/awareness/base-awareness.d.ts +0 -3
  197. package/build-types/awareness/base-awareness.d.ts.map +1 -1
  198. package/build-types/awareness/block-lookup.d.ts +0 -3
  199. package/build-types/awareness/block-lookup.d.ts.map +1 -1
  200. package/build-types/awareness/post-editor-awareness.d.ts +0 -3
  201. package/build-types/awareness/post-editor-awareness.d.ts.map +1 -1
  202. package/build-types/awareness/typed-awareness.d.ts +0 -3
  203. package/build-types/awareness/typed-awareness.d.ts.map +1 -1
  204. package/build-types/awareness/types.d.ts +0 -6
  205. package/build-types/awareness/types.d.ts.map +1 -1
  206. package/build-types/awareness/utils.d.ts +0 -3
  207. package/build-types/awareness/utils.d.ts.map +1 -1
  208. package/build-types/batch/create-batch.d.ts.map +1 -1
  209. package/build-types/batch/default-processor.d.ts.map +1 -1
  210. package/build-types/components/entities-saved-states/entity-record-item.d.ts +6 -0
  211. package/build-types/components/entities-saved-states/entity-record-item.d.ts.map +1 -0
  212. package/build-types/components/entities-saved-states/entity-type-list.d.ts +6 -0
  213. package/build-types/components/entities-saved-states/entity-type-list.d.ts.map +1 -0
  214. package/build-types/components/entities-saved-states/hooks/use-is-dirty.d.ts +11 -0
  215. package/build-types/components/entities-saved-states/hooks/use-is-dirty.d.ts.map +1 -0
  216. package/build-types/components/entities-saved-states/index.d.ts +49 -0
  217. package/build-types/components/entities-saved-states/index.d.ts.map +1 -0
  218. package/build-types/dynamic-entities.d.ts +0 -3
  219. package/build-types/dynamic-entities.d.ts.map +1 -1
  220. package/build-types/entities.d.ts.map +1 -1
  221. package/build-types/entity-context.d.ts.map +1 -1
  222. package/build-types/entity-provider.d.ts.map +1 -1
  223. package/build-types/entity-types/attachment.d.ts +0 -3
  224. package/build-types/entity-types/attachment.d.ts.map +1 -1
  225. package/build-types/entity-types/base.d.ts +0 -3
  226. package/build-types/entity-types/base.d.ts.map +1 -1
  227. package/build-types/entity-types/comment.d.ts +0 -3
  228. package/build-types/entity-types/comment.d.ts.map +1 -1
  229. package/build-types/entity-types/font-collection.d.ts +0 -3
  230. package/build-types/entity-types/font-collection.d.ts.map +1 -1
  231. package/build-types/entity-types/font-family.d.ts +0 -3
  232. package/build-types/entity-types/font-family.d.ts.map +1 -1
  233. package/build-types/entity-types/global-styles-revision.d.ts +0 -3
  234. package/build-types/entity-types/global-styles-revision.d.ts.map +1 -1
  235. package/build-types/entity-types/helpers.d.ts +0 -3
  236. package/build-types/entity-types/helpers.d.ts.map +1 -1
  237. package/build-types/entity-types/icon.d.ts +0 -3
  238. package/build-types/entity-types/icon.d.ts.map +1 -1
  239. package/build-types/entity-types/index.d.ts +0 -3
  240. package/build-types/entity-types/index.d.ts.map +1 -1
  241. package/build-types/entity-types/menu-location.d.ts +0 -3
  242. package/build-types/entity-types/menu-location.d.ts.map +1 -1
  243. package/build-types/entity-types/nav-menu-item.d.ts +0 -3
  244. package/build-types/entity-types/nav-menu-item.d.ts.map +1 -1
  245. package/build-types/entity-types/nav-menu.d.ts +0 -3
  246. package/build-types/entity-types/nav-menu.d.ts.map +1 -1
  247. package/build-types/entity-types/page.d.ts +0 -3
  248. package/build-types/entity-types/page.d.ts.map +1 -1
  249. package/build-types/entity-types/plugin.d.ts +0 -3
  250. package/build-types/entity-types/plugin.d.ts.map +1 -1
  251. package/build-types/entity-types/post-revision.d.ts +0 -3
  252. package/build-types/entity-types/post-revision.d.ts.map +1 -1
  253. package/build-types/entity-types/post-status.d.ts +0 -3
  254. package/build-types/entity-types/post-status.d.ts.map +1 -1
  255. package/build-types/entity-types/post.d.ts +0 -3
  256. package/build-types/entity-types/post.d.ts.map +1 -1
  257. package/build-types/entity-types/settings.d.ts +0 -3
  258. package/build-types/entity-types/settings.d.ts.map +1 -1
  259. package/build-types/entity-types/sidebar.d.ts +0 -3
  260. package/build-types/entity-types/sidebar.d.ts.map +1 -1
  261. package/build-types/entity-types/taxonomy.d.ts +0 -3
  262. package/build-types/entity-types/taxonomy.d.ts.map +1 -1
  263. package/build-types/entity-types/term.d.ts +0 -3
  264. package/build-types/entity-types/term.d.ts.map +1 -1
  265. package/build-types/entity-types/test/attachment.test.d.ts +0 -8
  266. package/build-types/entity-types/test/attachment.test.d.ts.map +1 -1
  267. package/build-types/entity-types/theme.d.ts +0 -3
  268. package/build-types/entity-types/theme.d.ts.map +1 -1
  269. package/build-types/entity-types/type.d.ts +0 -3
  270. package/build-types/entity-types/type.d.ts.map +1 -1
  271. package/build-types/entity-types/user.d.ts +0 -3
  272. package/build-types/entity-types/user.d.ts.map +1 -1
  273. package/build-types/entity-types/widget-type.d.ts +0 -3
  274. package/build-types/entity-types/widget-type.d.ts.map +1 -1
  275. package/build-types/entity-types/widget.d.ts +0 -3
  276. package/build-types/entity-types/widget.d.ts.map +1 -1
  277. package/build-types/entity-types/wp-template-part.d.ts +0 -3
  278. package/build-types/entity-types/wp-template-part.d.ts.map +1 -1
  279. package/build-types/entity-types/wp-template.d.ts +0 -3
  280. package/build-types/entity-types/wp-template.d.ts.map +1 -1
  281. package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -1
  282. package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -1
  283. package/build-types/fetch/index.d.ts.map +1 -1
  284. package/build-types/footnotes/get-footnotes-order.d.ts.map +1 -1
  285. package/build-types/footnotes/get-rich-text-values-cached.d.ts.map +1 -1
  286. package/build-types/footnotes/index.d.ts.map +1 -1
  287. package/build-types/hooks/index.d.ts +0 -3
  288. package/build-types/hooks/index.d.ts.map +1 -1
  289. package/build-types/hooks/use-entity-block-editor.d.ts.map +1 -1
  290. package/build-types/hooks/use-entity-id.d.ts.map +1 -1
  291. package/build-types/hooks/use-entity-prop.d.ts.map +1 -1
  292. package/build-types/hooks/use-entity-record.d.ts.map +1 -1
  293. package/build-types/hooks/use-entity-records.d.ts.map +1 -1
  294. package/build-types/hooks/use-post-editor-awareness-state.d.ts.map +1 -1
  295. package/build-types/hooks/use-query-select.d.ts.map +1 -1
  296. package/build-types/hooks/use-resource-permissions.d.ts.map +1 -1
  297. package/build-types/hooks/utils.d.ts +0 -6
  298. package/build-types/hooks/utils.d.ts.map +1 -1
  299. package/build-types/index.d.ts +1 -0
  300. package/build-types/index.d.ts.map +1 -1
  301. package/build-types/lock-unlock.d.ts.map +1 -1
  302. package/build-types/locks/actions.d.ts.map +1 -1
  303. package/build-types/locks/engine.d.ts.map +1 -1
  304. package/build-types/locks/reducer.d.ts.map +1 -1
  305. package/build-types/locks/selectors.d.ts.map +1 -1
  306. package/build-types/private-actions.d.ts +19 -0
  307. package/build-types/private-actions.d.ts.map +1 -1
  308. package/build-types/private-apis.d.ts +13 -3
  309. package/build-types/private-apis.d.ts.map +1 -1
  310. package/build-types/private-selectors.d.ts +12 -3
  311. package/build-types/private-selectors.d.ts.map +1 -1
  312. package/build-types/queried-data/get-query-parts.d.ts.map +1 -1
  313. package/build-types/queried-data/reducer.d.ts.map +1 -1
  314. package/build-types/queried-data/selectors.d.ts.map +1 -1
  315. package/build-types/reducer.d.ts.map +1 -1
  316. package/build-types/resolvers.d.ts +1 -2
  317. package/build-types/resolvers.d.ts.map +1 -1
  318. package/build-types/selectors.d.ts.map +1 -1
  319. package/build-types/sync.d.ts +31 -3
  320. package/build-types/sync.d.ts.map +1 -1
  321. package/build-types/types.d.ts +9 -8
  322. package/build-types/types.d.ts.map +1 -1
  323. package/build-types/utils/block-selection-history.d.ts +0 -6
  324. package/build-types/utils/block-selection-history.d.ts.map +1 -1
  325. package/build-types/utils/clear-unchanged-edits.d.ts.map +1 -1
  326. package/build-types/utils/conservative-map-item.d.ts.map +1 -1
  327. package/build-types/utils/crdt-blocks.d.ts +0 -3
  328. package/build-types/utils/crdt-blocks.d.ts.map +1 -1
  329. package/build-types/utils/crdt-selection.d.ts +0 -3
  330. package/build-types/utils/crdt-selection.d.ts.map +1 -1
  331. package/build-types/utils/crdt-text.d.ts +0 -3
  332. package/build-types/utils/crdt-text.d.ts.map +1 -1
  333. package/build-types/utils/crdt-user-selections.d.ts.map +1 -1
  334. package/build-types/utils/crdt-utils.d.ts +0 -6
  335. package/build-types/utils/crdt-utils.d.ts.map +1 -1
  336. package/build-types/utils/crdt.d.ts +8 -0
  337. package/build-types/utils/crdt.d.ts.map +1 -1
  338. package/build-types/utils/get-template-info.d.ts +13 -0
  339. package/build-types/utils/get-template-info.d.ts.map +1 -0
  340. package/build-types/utils/get-template-part-icon.d.ts +9 -0
  341. package/build-types/utils/get-template-part-icon.d.ts.map +1 -0
  342. package/build-types/utils/log-entity-deprecation.d.ts.map +1 -1
  343. package/build-types/utils/save-crdt-doc.d.ts.map +1 -1
  344. package/package.json +28 -22
  345. package/src/actions.js +120 -13
  346. package/src/awareness/awareness-state.ts +0 -3
  347. package/src/awareness/base-awareness.ts +0 -8
  348. package/src/awareness/block-lookup.ts +1 -8
  349. package/src/awareness/post-editor-awareness.ts +13 -10
  350. package/src/awareness/test/awareness-state.ts +0 -11
  351. package/src/awareness/test/base-awareness.ts +0 -7
  352. package/src/awareness/test/block-lookup.ts +0 -8
  353. package/src/awareness/test/post-editor-awareness.ts +0 -7
  354. package/src/awareness/test/typed-awareness.ts +0 -11
  355. package/src/awareness/test/utils.ts +0 -3
  356. package/src/awareness/typed-awareness.ts +0 -7
  357. package/src/awareness/types.ts +0 -7
  358. package/src/awareness/utils.ts +0 -3
  359. package/src/batch/create-batch.js +0 -3
  360. package/src/batch/default-processor.js +0 -4
  361. package/src/batch/test/create-batch.js +0 -3
  362. package/src/batch/test/default-processor.js +0 -7
  363. package/src/components/entities-saved-states/entity-record-item.js +53 -0
  364. package/src/components/entities-saved-states/entity-type-list.js +123 -0
  365. package/src/components/entities-saved-states/hooks/use-is-dirty.js +98 -0
  366. package/src/components/entities-saved-states/index.js +231 -0
  367. package/src/components/entities-saved-states/style.scss +70 -0
  368. package/src/components/entities-saved-states/test/use-is-dirty.js +147 -0
  369. package/src/dynamic-entities.ts +0 -3
  370. package/src/entities.js +2 -11
  371. package/src/entity-context.js +0 -3
  372. package/src/entity-provider.js +0 -7
  373. package/src/entity-types/attachment.ts +0 -4
  374. package/src/entity-types/base.ts +0 -3
  375. package/src/entity-types/comment.ts +0 -3
  376. package/src/entity-types/font-collection.ts +0 -3
  377. package/src/entity-types/font-family.ts +0 -3
  378. package/src/entity-types/global-styles-revision.ts +0 -4
  379. package/src/entity-types/helpers.ts +0 -3
  380. package/src/entity-types/icon.ts +0 -4
  381. package/src/entity-types/index.ts +0 -3
  382. package/src/entity-types/menu-location.ts +0 -4
  383. package/src/entity-types/nav-menu-item.ts +0 -4
  384. package/src/entity-types/nav-menu.ts +0 -4
  385. package/src/entity-types/page.ts +0 -4
  386. package/src/entity-types/plugin.ts +0 -4
  387. package/src/entity-types/post-revision.ts +0 -4
  388. package/src/entity-types/post-status.ts +0 -3
  389. package/src/entity-types/post.ts +0 -4
  390. package/src/entity-types/settings.ts +0 -4
  391. package/src/entity-types/sidebar.ts +0 -4
  392. package/src/entity-types/taxonomy.ts +0 -4
  393. package/src/entity-types/term.ts +0 -4
  394. package/src/entity-types/test/attachment.test.ts +0 -4
  395. package/src/entity-types/theme.ts +0 -4
  396. package/src/entity-types/type.ts +0 -4
  397. package/src/entity-types/user.ts +0 -4
  398. package/src/entity-types/widget-type.ts +0 -4
  399. package/src/entity-types/widget.ts +0 -4
  400. package/src/entity-types/wp-template-part.ts +0 -4
  401. package/src/entity-types/wp-template.ts +0 -4
  402. package/src/fetch/__experimental-fetch-link-suggestions.ts +0 -3
  403. package/src/fetch/__experimental-fetch-url-data.js +0 -3
  404. package/src/fetch/index.js +0 -7
  405. package/src/fetch/test/__experimental-fetch-link-suggestions.js +0 -3
  406. package/src/fetch/test/__experimental-fetch-url-data.js +1 -7
  407. package/src/footnotes/get-footnotes-order.js +0 -3
  408. package/src/footnotes/get-rich-text-values-cached.js +0 -7
  409. package/src/footnotes/index.js +21 -8
  410. package/src/footnotes/test/index.js +57 -0
  411. package/src/hooks/index.ts +0 -3
  412. package/src/hooks/test/use-entity-record.js +0 -12
  413. package/src/hooks/test/use-entity-records.js +0 -12
  414. package/src/hooks/test/use-post-editor-awareness-state.ts +0 -7
  415. package/src/hooks/test/use-query-select.js +0 -11
  416. package/src/hooks/test/use-resource-permissions.js +0 -12
  417. package/src/hooks/use-entity-block-editor.js +0 -7
  418. package/src/hooks/use-entity-id.js +0 -7
  419. package/src/hooks/use-entity-prop.js +0 -7
  420. package/src/hooks/use-entity-record.ts +0 -7
  421. package/src/hooks/use-entity-records.ts +2 -9
  422. package/src/hooks/use-post-editor-awareness-state.ts +0 -7
  423. package/src/hooks/use-query-select.ts +0 -7
  424. package/src/hooks/use-resource-permissions.ts +0 -7
  425. package/src/hooks/utils.ts +0 -7
  426. package/src/index.js +0 -7
  427. package/src/lock-unlock.ts +0 -3
  428. package/src/locks/actions.js +0 -3
  429. package/src/locks/engine.js +0 -3
  430. package/src/locks/reducer.js +0 -3
  431. package/src/locks/selectors.js +0 -3
  432. package/src/locks/test/engine.js +0 -3
  433. package/src/locks/test/reducer.js +0 -7
  434. package/src/locks/test/selectors.js +0 -7
  435. package/src/locks/test/utils.js +0 -7
  436. package/src/private-actions.js +182 -7
  437. package/src/private-apis.ts +21 -4
  438. package/src/private-selectors.ts +22 -7
  439. package/src/queried-data/get-query-parts.js +0 -7
  440. package/src/queried-data/reducer.js +0 -7
  441. package/src/queried-data/selectors.js +0 -7
  442. package/src/queried-data/test/actions.js +0 -3
  443. package/src/queried-data/test/get-query-parts.js +0 -3
  444. package/src/queried-data/test/reducer.js +0 -7
  445. package/src/queried-data/test/selectors.js +0 -3
  446. package/src/reducer.js +0 -11
  447. package/src/resolvers.js +23 -40
  448. package/src/selectors.ts +0 -7
  449. package/src/style.scss +1 -0
  450. package/src/sync.ts +64 -7
  451. package/src/test/actions.js +843 -8
  452. package/src/test/deprecated-entity-logging.js +0 -7
  453. package/src/test/entities.js +0 -8
  454. package/src/test/entity-provider.js +0 -11
  455. package/src/test/private-actions.js +297 -7
  456. package/src/test/private-selectors.js +0 -3
  457. package/src/test/reducer.js +0 -7
  458. package/src/test/resolvers.js +0 -12
  459. package/src/test/rtc-rich-text-offset-space.test.js +0 -12
  460. package/src/test/selectors.js +0 -7
  461. package/src/test/store.js +8 -15
  462. package/src/types.ts +14 -12
  463. package/src/utils/block-selection-history.ts +0 -10
  464. package/src/utils/clear-unchanged-edits.ts +0 -3
  465. package/src/utils/conservative-map-item.js +0 -3
  466. package/src/utils/crdt-blocks.ts +0 -11
  467. package/src/utils/crdt-selection.ts +0 -7
  468. package/src/utils/crdt-text.ts +0 -3
  469. package/src/utils/crdt-user-selections.ts +85 -23
  470. package/src/utils/crdt-utils.ts +0 -7
  471. package/src/utils/crdt.ts +1 -12
  472. package/src/utils/get-template-info.js +46 -0
  473. package/src/utils/get-template-part-icon.js +27 -0
  474. package/src/utils/log-entity-deprecation.ts +0 -7
  475. package/src/utils/save-crdt-doc.js +0 -7
  476. package/src/utils/test/block-selection-history.test.ts +0 -7
  477. package/src/utils/test/clear-unchanged-edits.js +0 -3
  478. package/src/utils/test/conservative-map-item.js +0 -3
  479. package/src/utils/test/crdt-blocks.ts +0 -17
  480. package/src/utils/test/crdt-user-selections.ts +107 -30
  481. package/src/utils/test/crdt-utils.ts +0 -7
  482. package/src/utils/test/crdt.ts +0 -16
  483. package/src/utils/test/get-nested-value.js +0 -3
  484. package/src/utils/test/get-normalized-comma-separable.js +0 -3
  485. package/src/utils/test/get-template-info.js +218 -0
  486. package/src/utils/test/if-matching-action.js +0 -7
  487. package/src/utils/test/is-numeric-id.js +0 -3
  488. package/src/utils/test/log-entity-deprecation.js +0 -7
  489. package/src/utils/test/replace-action.js +0 -3
  490. package/src/utils/test/rtc-rich-text-cursor-scope.test.js +0 -14
  491. package/src/utils/test/rtc-rich-text-offset-space.test.js +0 -14
  492. package/src/utils/test/save-crdt-doc.js +0 -7
  493. package/src/utils/test/set-nested-value.js +0 -3
  494. package/src/utils/test/with-weak-map-cache.js +0 -3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/awareness/post-editor-awareness.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { dispatch, select, subscribe } from '@wordpress/data';\nimport { Y } from '@wordpress/sync';\n// @ts-ignore No exported types for block editor store selectors.\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { BaseAwarenessState, baseEqualityFieldChecks } from './base-awareness';\nimport {\n\tgetBlockPathInYdoc,\n\tgetContainingBlockYMap,\n\tresolveBlockClientIdByPath,\n} from './block-lookup';\nimport {\n\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS,\n\tLOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS,\n} from './config';\nimport { STORE_NAME as coreStore } from '../name';\nimport {\n\tasHtmlStringIndex,\n\thtmlIndexToRichTextOffset,\n} from '../utils/crdt-utils';\nimport {\n\tareSelectionsStatesEqual,\n\tgetSelectionState,\n\tSelectionType,\n\tSelectionDirection,\n} from '../utils/crdt-user-selections';\n\nimport type {\n\tResolvedSelection,\n\tSelectionState,\n\tWPBlockSelection,\n} from '../types';\nimport type { YBlocks } from '../utils/crdt-blocks';\nimport type { EditorStoreBlock } from './block-lookup';\nimport type {\n\tDebugCollaboratorData,\n\tEditorState,\n\tPostEditorState,\n\tSerializableYItem,\n\tYDocDebugData,\n} from './types';\n\nexport class PostEditorAwareness extends BaseAwarenessState< PostEditorState > {\n\tprotected equalityFieldChecks = {\n\t\t...baseEqualityFieldChecks,\n\t\teditorState: this.areEditorStatesEqual,\n\t};\n\n\tpublic constructor(\n\t\tdoc: Y.Doc,\n\t\tprivate kind: string,\n\t\tprivate name: string,\n\t\tprivate postId: number\n\t) {\n\t\tsuper( doc );\n\t}\n\n\tprotected onSetUp(): void {\n\t\tsuper.onSetUp();\n\n\t\tthis.subscribeToCollaboratorSelectionChanges();\n\t}\n\n\t/**\n\t * Subscribe to collaborator selection changes and update the selection state.\n\t */\n\tprivate subscribeToCollaboratorSelectionChanges(): void {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t} = select( blockEditorStore );\n\n\t\t// Keep track of the current selection in the outer scope so we can compare\n\t\t// in the subscription.\n\t\tlet selectionStart = getSelectionStart();\n\t\tlet selectionEnd = getSelectionEnd();\n\t\tlet localCursorTimeout: NodeJS.Timeout | null = null;\n\n\t\t// During rapid selection changes (e.g. undo restoring content and\n\t\t// selection), the debounce discards intermediate events. If we use the\n\t\t// last intermediate state instead of the overall change it can produce\n\t\t// the wrong direction.\n\t\t// Use selectionBeforeDebounce to capture the selection state from\n\t\t// before the debounce window so that direction is computed across the\n\t\t// full window when it fires.\n\t\tlet selectionBeforeDebounce: {\n\t\t\tstart: WPBlockSelection;\n\t\t\tend: WPBlockSelection;\n\t\t} | null = null;\n\n\t\tsubscribe( () => {\n\t\t\tconst newSelectionStart = getSelectionStart();\n\t\t\tconst newSelectionEnd = getSelectionEnd();\n\n\t\t\tif (\n\t\t\t\tnewSelectionStart === selectionStart &&\n\t\t\t\tnewSelectionEnd === selectionEnd\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// On the first change of a debounce window, snapshot the state\n\t\t\t// we're moving away from.\n\t\t\tif ( ! selectionBeforeDebounce ) {\n\t\t\t\tselectionBeforeDebounce = {\n\t\t\t\t\tstart: selectionStart,\n\t\t\t\t\tend: selectionEnd,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tselectionStart = newSelectionStart;\n\t\t\tselectionEnd = newSelectionEnd;\n\n\t\t\t// Typically selection position is only persisted after typing in a block, which\n\t\t\t// can cause selection position to be reset by other users making block updates.\n\t\t\t// Ensure we update the controlled selection right away, persisting our cursor position locally.\n\t\t\tconst initialPosition = getSelectedBlocksInitialCaretPosition();\n\t\t\tvoid this.updateSelectionInEntityRecord(\n\t\t\t\tselectionStart,\n\t\t\t\tselectionEnd,\n\t\t\t\tinitialPosition\n\t\t\t);\n\n\t\t\t// We receive two selection changes in quick succession\n\t\t\t// from local selection events:\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: undefined }\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: 554 }\n\t\t\t// Add a short debounce to avoid sending the first selection change.\n\t\t\tif ( localCursorTimeout ) {\n\t\t\t\tclearTimeout( localCursorTimeout );\n\t\t\t}\n\n\t\t\tlocalCursorTimeout = setTimeout( () => {\n\t\t\t\t// Compute direction across the full debounce window.\n\t\t\t\tconst selectionStateOptions: {\n\t\t\t\t\tselectionDirection?: SelectionDirection;\n\t\t\t\t} = {};\n\n\t\t\t\tif ( selectionBeforeDebounce ) {\n\t\t\t\t\tselectionStateOptions.selectionDirection =\n\t\t\t\t\t\tdetectSelectionDirection(\n\t\t\t\t\t\t\tselectionBeforeDebounce.start,\n\t\t\t\t\t\t\tselectionBeforeDebounce.end,\n\t\t\t\t\t\t\tselectionStart,\n\t\t\t\t\t\t\tselectionEnd\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// Reset debounced selection state.\n\t\t\t\t\tselectionBeforeDebounce = null;\n\t\t\t\t}\n\n\t\t\t\tconst selectionState = getSelectionState(\n\t\t\t\t\tselectionStart,\n\t\t\t\t\tselectionEnd,\n\t\t\t\t\tthis.doc,\n\t\t\t\t\tselectionStateOptions\n\t\t\t\t);\n\n\t\t\t\tthis.setThrottledLocalStateField(\n\t\t\t\t\t'editorState',\n\t\t\t\t\t{ selection: selectionState },\n\t\t\t\t\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS\n\t\t\t\t);\n\t\t\t}, LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS );\n\t\t} );\n\t}\n\n\t/**\n\t * Update the entity record with the current collaborator's selection.\n\t *\n\t * @param selectionStart - The start position of the selection.\n\t * @param selectionEnd - The end position of the selection.\n\t * @param initialPosition - The initial position of the selection.\n\t */\n\tprivate async updateSelectionInEntityRecord(\n\t\tselectionStart: WPBlockSelection,\n\t\tselectionEnd: WPBlockSelection,\n\t\tinitialPosition: number | null\n\t): Promise< void > {\n\t\t// Send an entityRecord `selection` update if we have a selection.\n\t\t//\n\t\t// Normally WordPress updates the `selection` property of the post when changes are made to blocks.\n\t\t// In a multi-user setup, block changes can occur from other users. When an entity is updated from another\n\t\t// user's changes, useBlockSync() in Gutenberg will reset the user's selection to the last saved selection.\n\t\t//\n\t\t// Manually adding an edit for each movement ensures that other user's changes to the document will\n\t\t// not cause the local user's selection to reset to the last local change location.\n\t\tconst edits = {\n\t\t\tselection: { selectionStart, selectionEnd, initialPosition },\n\t\t};\n\n\t\tconst options = {\n\t\t\tundoIgnore: true,\n\t\t};\n\n\t\t// @ts-ignore Types are not provided when using store name instead of store instance.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\tthis.kind,\n\t\t\tthis.name,\n\t\t\tthis.postId,\n\t\t\tedits,\n\t\t\toptions\n\t\t);\n\t}\n\n\t/**\n\t * Check if two editor states are equal.\n\t *\n\t * @param state1 - The first editor state.\n\t * @param state2 - The second editor state.\n\t * @return True if the editor states are equal, false otherwise.\n\t */\n\tprivate areEditorStatesEqual(\n\t\tstate1?: EditorState,\n\t\tstate2?: EditorState\n\t): boolean {\n\t\tif ( ! state1 || ! state2 ) {\n\t\t\treturn state1 === state2;\n\t\t}\n\n\t\tif ( ! state1.selection || ! state2.selection ) {\n\t\t\treturn state1.selection === state2.selection;\n\t\t}\n\n\t\treturn areSelectionsStatesEqual( state1.selection, state2.selection );\n\t}\n\n\t/**\n\t * Resolve a selection state to a text index and block client ID.\n\t *\n\t * For text-based selections, navigates up from the resolved Y.Text via\n\t * AbstractType.parent to find the containing block, then resolves the\n\t * local clientId via the block's tree path.\n\t * For WholeBlock selections, resolves the block's relative position and\n\t * then finds the local clientId via tree path.\n\t *\n\t * Tree-path resolution is used instead of reading the clientId directly\n\t * from the Yjs block because the local block-editor store may use different\n\t * clientIds (e.g. in \"Show Template\" mode where blocks are cloned).\n\t *\n\t * @param selection - The selection state.\n\t * @param blocks - The tree of block-editor store post content blocks.\n\t * @return The rich-text offset and block client ID, or nulls if not resolvable.\n\t */\n\tpublic convertSelectionStateToAbsolute(\n\t\tselection: SelectionState,\n\t\tblocks: EditorStoreBlock[]\n\t): ResolvedSelection {\n\t\tif ( selection.type === SelectionType.None ) {\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId: null,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\tif ( selection.type === SelectionType.WholeBlock ) {\n\t\t\tconst absolutePos = Y.createAbsolutePositionFromRelativePosition(\n\t\t\t\tselection.blockPosition,\n\t\t\t\tthis.doc\n\t\t\t);\n\n\t\t\tlet localClientId: string | null = null;\n\n\t\t\tif ( absolutePos && absolutePos.type instanceof Y.Array ) {\n\t\t\t\tconst parentArray = absolutePos.type as YBlocks;\n\t\t\t\tconst block = parentArray.get( absolutePos.index );\n\n\t\t\t\tif ( block instanceof Y.Map ) {\n\t\t\t\t\tconst path = getBlockPathInYdoc( block );\n\t\t\t\t\tlocalClientId = path\n\t\t\t\t\t\t? resolveBlockClientIdByPath( path, blocks )\n\t\t\t\t\t\t: null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\t// Text-based selections: resolve cursor position and navigate up.\n\t\tconst cursorPos =\n\t\t\t'cursorPosition' in selection\n\t\t\t\t? selection.cursorPosition\n\t\t\t\t: selection.cursorStartPosition;\n\n\t\tconst absolutePosition = Y.createAbsolutePositionFromRelativePosition(\n\t\t\tcursorPos.relativePosition,\n\t\t\tthis.doc\n\t\t);\n\n\t\tif ( ! absolutePosition ) {\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId: null,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\tconst yType = getContainingBlockYMap( absolutePosition.type );\n\t\tconst path = yType ? getBlockPathInYdoc( yType ) : null;\n\t\tconst localClientId = path\n\t\t\t? resolveBlockClientIdByPath( path, blocks )\n\t\t\t: null;\n\n\t\treturn {\n\t\t\trichTextOffset: htmlIndexToRichTextOffset(\n\t\t\t\tabsolutePosition.type.toString(),\n\t\t\t\tasHtmlStringIndex( absolutePosition.index )\n\t\t\t),\n\t\t\tlocalClientId,\n\t\t\tattributeKey: cursorPos.attributeKey ?? null,\n\t\t};\n\t}\n\n\t/**\n\t * Type guard to check if a struct is a Y.Item (not Y.GC)\n\t * @param struct - The struct to check.\n\t * @return True if the struct is a Y.Item, false otherwise.\n\t */\n\tprivate isYItem( struct: Y.Item | Y.GC ): struct is Y.Item {\n\t\treturn 'content' in struct;\n\t}\n\n\t/**\n\t * Get data for debugging, using the awareness state.\n\t *\n\t * @return {YDocDebugData} The debug data.\n\t */\n\tpublic getDebugData(): YDocDebugData {\n\t\tconst ydoc = this.doc;\n\n\t\t// Manually extract doc data to avoid deprecated toJSON method\n\t\tconst docData: Record< string, unknown > = Object.fromEntries(\n\t\t\tArray.from( ydoc.share, ( [ key, value ] ) => [\n\t\t\t\tkey,\n\t\t\t\tvalue.toJSON(),\n\t\t\t] )\n\t\t);\n\n\t\t// Build collaboratorMap from awareness store (all collaborators seen this session)\n\t\tconst collaboratorMapData = new Map< string, DebugCollaboratorData >(\n\t\t\tArray.from( this.getSeenStates().entries() ).map(\n\t\t\t\t( [ clientId, collaboratorState ] ) => [\n\t\t\t\t\tString( clientId ),\n\t\t\t\t\t{\n\t\t\t\t\t\tname: collaboratorState.collaboratorInfo.name,\n\t\t\t\t\t\twpUserId: collaboratorState.collaboratorInfo.id,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t)\n\t\t);\n\n\t\t// Serialize Yjs client items to avoid deep nesting\n\t\tconst serializableClientItems: Record<\n\t\t\tnumber,\n\t\t\tArray< SerializableYItem >\n\t\t> = {};\n\n\t\tydoc.store.clients.forEach( ( structs, clientId ) => {\n\t\t\t// Filter for Y.Item only (skip Y.GC garbage collection structs)\n\t\t\tconst items = structs.filter( this.isYItem );\n\n\t\t\tserializableClientItems[ clientId ] = items.map( ( item ) => {\n\t\t\t\tconst { left, right, ...rest } = item;\n\n\t\t\t\treturn {\n\t\t\t\t\t...rest,\n\t\t\t\t\tleft: left\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: left.id,\n\t\t\t\t\t\t\t\tlength: left.length,\n\t\t\t\t\t\t\t\torigin: left.origin,\n\t\t\t\t\t\t\t\tcontent: left.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t\tright: right\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: right.id,\n\t\t\t\t\t\t\t\tlength: right.length,\n\t\t\t\t\t\t\t\torigin: right.origin,\n\t\t\t\t\t\t\t\tcontent: right.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t} );\n\t\t} );\n\n\t\treturn {\n\t\t\tdoc: docData,\n\t\t\tclients: serializableClientItems,\n\t\t\tcollaboratorMap: Object.fromEntries( collaboratorMapData ),\n\t\t};\n\t}\n}\n\n/**\n * Detect the direction of a selection change by comparing old and new edges.\n *\n * When the user extends a selection backward (e.g. Shift+Left), the\n * selectionStart edge moves while selectionEnd stays fixed, so the caret\n * is at the start. The reverse is true for forward extension.\n *\n * @param prevStart - The previous selectionStart.\n * @param prevEnd - The previous selectionEnd.\n * @param newStart - The new selectionStart.\n * @param newEnd - The new selectionEnd.\n * @return The detected direction, defaulting to Forward when indeterminate.\n */\nfunction detectSelectionDirection(\n\tprevStart: WPBlockSelection,\n\tprevEnd: WPBlockSelection,\n\tnewStart: WPBlockSelection,\n\tnewEnd: WPBlockSelection\n): SelectionDirection {\n\tconst startMoved = ! areBlockSelectionsEqual( prevStart, newStart );\n\tconst endMoved = ! areBlockSelectionsEqual( prevEnd, newEnd );\n\n\tif ( startMoved && ! endMoved ) {\n\t\treturn SelectionDirection.Backward;\n\t}\n\n\treturn SelectionDirection.Forward;\n}\n\n/**\n * Compare two WPBlockSelection objects by value.\n *\n * @param a - First selection.\n * @param b - Second selection.\n * @return True if all fields are equal.\n */\nfunction areBlockSelectionsEqual(\n\ta: WPBlockSelection,\n\tb: WPBlockSelection\n): boolean {\n\treturn (\n\t\ta.clientId === b.clientId &&\n\t\ta.attributeKey === b.attributeKey &&\n\t\ta.offset === b.offset\n\t);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4C;AAC5C,kBAAkB;AAElB,0BAA0C;AAK1C,4BAA4D;AAC5D,0BAIO;AACP,oBAGO;AACP,kBAAwC;AACxC,wBAGO;AACP,kCAKO;AAiBA,IAAM,sBAAN,cAAkC,yCAAsC;AAAA,EAMvE,YACN,KACQ,MACA,MACA,QACP;AACD,UAAO,GAAI;AAJH;AACA;AACA;AAAA,EAGT;AAAA,EAZU,sBAAsB;AAAA,IAC/B,GAAG;AAAA,IACH,aAAa,KAAK;AAAA,EACnB;AAAA,EAWU,UAAgB;AACzB,UAAM,QAAQ;AAEd,SAAK,wCAAwC;AAAA,EAC9C;AAAA;AAAA;AAAA;AAAA,EAKQ,0CAAgD;AACvD,U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AAE,MAAM,OAAO,GAAG,KAAK,IAAI;AAEjC,eAAO;AAAA,UACN,GAAG;AAAA,UACH,MAAM,OACH;AAAA,YACA,IAAI,KAAK;AAAA,YACT,QAAQ,KAAK;AAAA,YACb,QAAQ,KAAK;AAAA,YACb,SAAS,KAAK;AAAA,UACd,IACA;AAAA,UACH,OAAO,QACJ;AAAA,YACA,IAAI,MAAM;AAAA,YACV,QAAQ,MAAM;AAAA,YACd,QAAQ,MAAM;AAAA,YACd,SAAS,MAAM;AAAA,UACf,IACA;AAAA,QACJ;AAAA,MACD,CAAE;AAAA,IACH,CAAE;AAEF,WAAO;AAAA,MACN,KAAK;AAAA,MACL,SAAS;AAAA,MACT,iBAAiB,OAAO,YAAa,mBAAoB;AAAA,IAC1D;AAAA,EACD;AACD;AAeA,SAAS,yBACR,WACA,SACA,UACA,QACqB;AACrB,QAAM,aAAa,CAAE,wBAAyB,WAAW,QAAS;AAClE,QAAM,WAAW,CAAE,wBAAyB,SAAS,MAAO;AAE5D,MAAK,cAAc,CAAE,UAAW;AAC/B,WAAO,+CAAmB;AAAA,EAC3B;AAEA,SAAO,+CAAmB;AAC3B;AASA,SAAS,wBACR,GACA,GACU;AACV,SACC,EAAE,aAAa,EAAE,YACjB,EAAE,iBAAiB,EAAE,gBACrB,EAAE,WAAW,EAAE;AAEjB;",
4
+ "sourcesContent": ["import { dispatch, select, subscribe } from '@wordpress/data';\nimport { Y } from '@wordpress/sync';\n// @ts-expect-error `@wordpress/block-editor` does not expose type declarations for its entry point.\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { BaseAwarenessState, baseEqualityFieldChecks } from './base-awareness';\nimport {\n\tgetBlockPathInYdoc,\n\tgetContainingBlockYMap,\n\tresolveBlockClientIdByPath,\n} from './block-lookup';\nimport {\n\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS,\n\tLOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS,\n} from './config';\nimport { STORE_NAME as coreStore } from '../name';\nimport {\n\tasHtmlStringIndex,\n\thtmlIndexToRichTextOffset,\n} from '../utils/crdt-utils';\nimport {\n\tareSelectionsStatesEqual,\n\tgetSelectionState,\n\tSelectionType,\n\tSelectionDirection,\n} from '../utils/crdt-user-selections';\nimport type {\n\tResolvedSelection,\n\tSelectionState,\n\tWPBlockSelection,\n} from '../types';\nimport type { YBlocks } from '../utils/crdt-blocks';\nimport type { EditorStoreBlock } from './block-lookup';\nimport type {\n\tDebugCollaboratorData,\n\tEditorState,\n\tPostEditorState,\n\tSerializableYItem,\n\tYDocDebugData,\n} from './types';\n\nexport class PostEditorAwareness extends BaseAwarenessState< PostEditorState > {\n\tprotected equalityFieldChecks = {\n\t\t...baseEqualityFieldChecks,\n\t\teditorState: this.areEditorStatesEqual,\n\t};\n\n\tpublic constructor(\n\t\tdoc: Y.Doc,\n\t\tprivate kind: string,\n\t\tprivate name: string,\n\t\tprivate postId: number\n\t) {\n\t\tsuper( doc );\n\t}\n\n\tprotected onSetUp(): void {\n\t\tsuper.onSetUp();\n\n\t\tthis.subscribeToCollaboratorSelectionChanges();\n\t}\n\n\t/**\n\t * Subscribe to collaborator selection changes and update the selection state.\n\t */\n\tprivate subscribeToCollaboratorSelectionChanges(): void {\n\t\tconst {\n\t\t\tgetSelectionStart,\n\t\t\tgetSelectionEnd,\n\t\t\tgetSelectedBlocksInitialCaretPosition,\n\t\t} = select( blockEditorStore );\n\n\t\t// Keep track of the current selection in the outer scope so we can compare\n\t\t// in the subscription.\n\t\tlet selectionStart = getSelectionStart();\n\t\tlet selectionEnd = getSelectionEnd();\n\t\tlet localCursorTimeout: NodeJS.Timeout | null = null;\n\n\t\t// During rapid selection changes (e.g. undo restoring content and\n\t\t// selection), the debounce discards intermediate events. If we use the\n\t\t// last intermediate state instead of the overall change it can produce\n\t\t// the wrong direction.\n\t\t// Use selectionBeforeDebounce to capture the selection state from\n\t\t// before the debounce window so that direction is computed across the\n\t\t// full window when it fires.\n\t\tlet selectionBeforeDebounce: {\n\t\t\tstart: WPBlockSelection;\n\t\t\tend: WPBlockSelection;\n\t\t} | null = null;\n\n\t\tsubscribe( () => {\n\t\t\tconst newSelectionStart = getSelectionStart();\n\t\t\tconst newSelectionEnd = getSelectionEnd();\n\n\t\t\tif (\n\t\t\t\tnewSelectionStart === selectionStart &&\n\t\t\t\tnewSelectionEnd === selectionEnd\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// On the first change of a debounce window, snapshot the state\n\t\t\t// we're moving away from.\n\t\t\tif ( ! selectionBeforeDebounce ) {\n\t\t\t\tselectionBeforeDebounce = {\n\t\t\t\t\tstart: selectionStart,\n\t\t\t\t\tend: selectionEnd,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tselectionStart = newSelectionStart;\n\t\t\tselectionEnd = newSelectionEnd;\n\n\t\t\t// Typically selection position is only persisted after typing in a block, which\n\t\t\t// can cause selection position to be reset by other users making block updates.\n\t\t\t// Ensure we update the controlled selection right away, persisting our cursor position locally.\n\t\t\tconst initialPosition = getSelectedBlocksInitialCaretPosition();\n\t\t\tvoid this.updateSelectionInEntityRecord(\n\t\t\t\tselectionStart,\n\t\t\t\tselectionEnd,\n\t\t\t\tinitialPosition\n\t\t\t);\n\n\t\t\t// We receive two selection changes in quick succession\n\t\t\t// from local selection events:\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: undefined }\n\t\t\t// { clientId: \"123...\", attributeKey: \"content\", offset: 554 }\n\t\t\t// Add a short debounce to avoid sending the first selection change.\n\t\t\tif ( localCursorTimeout ) {\n\t\t\t\tclearTimeout( localCursorTimeout );\n\t\t\t}\n\n\t\t\tlocalCursorTimeout = setTimeout( () => {\n\t\t\t\t// Compute direction across the full debounce window.\n\t\t\t\tconst selectionStateOptions: {\n\t\t\t\t\tselectionDirection?: SelectionDirection;\n\t\t\t\t} = {};\n\n\t\t\t\tif ( selectionBeforeDebounce ) {\n\t\t\t\t\tselectionStateOptions.selectionDirection =\n\t\t\t\t\t\tdetectSelectionDirection(\n\t\t\t\t\t\t\tselectionBeforeDebounce.start,\n\t\t\t\t\t\t\tselectionBeforeDebounce.end,\n\t\t\t\t\t\t\tselectionStart,\n\t\t\t\t\t\t\tselectionEnd\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// Reset debounced selection state.\n\t\t\t\t\tselectionBeforeDebounce = null;\n\t\t\t\t}\n\n\t\t\t\tconst selectionState = getSelectionState(\n\t\t\t\t\tselectionStart,\n\t\t\t\t\tselectionEnd,\n\t\t\t\t\tthis.doc,\n\t\t\t\t\tselectionStateOptions\n\t\t\t\t);\n\n\t\t\t\tthis.setThrottledLocalStateField(\n\t\t\t\t\t'editorState',\n\t\t\t\t\t{ selection: selectionState },\n\t\t\t\t\tAWARENESS_CURSOR_UPDATE_THROTTLE_IN_MS\n\t\t\t\t);\n\t\t\t}, LOCAL_CURSOR_UPDATE_DEBOUNCE_IN_MS );\n\t\t} );\n\t}\n\n\t/**\n\t * Update the entity record with the current collaborator's selection.\n\t *\n\t * @param selectionStart - The start position of the selection.\n\t * @param selectionEnd - The end position of the selection.\n\t * @param initialPosition - The initial position of the selection.\n\t */\n\tprivate async updateSelectionInEntityRecord(\n\t\tselectionStart: WPBlockSelection,\n\t\tselectionEnd: WPBlockSelection,\n\t\tinitialPosition: number | null\n\t): Promise< void > {\n\t\t// Send an entityRecord `selection` update if we have a selection.\n\t\t//\n\t\t// Normally WordPress updates the `selection` property of the post when changes are made to blocks.\n\t\t// In a multi-user setup, block changes can occur from other users. When an entity is updated from another\n\t\t// user's changes, useBlockSync() in Gutenberg will reset the user's selection to the last saved selection.\n\t\t//\n\t\t// Manually adding an edit for each movement ensures that other user's changes to the document will\n\t\t// not cause the local user's selection to reset to the last local change location.\n\t\tconst edits = {\n\t\t\tselection: { selectionStart, selectionEnd, initialPosition },\n\t\t};\n\n\t\tconst options = {\n\t\t\tundoIgnore: true,\n\t\t};\n\n\t\t// @ts-expect-error Types are not provided when using the store name instead of the store instance.\n\t\tdispatch( coreStore ).editEntityRecord(\n\t\t\tthis.kind,\n\t\t\tthis.name,\n\t\t\tthis.postId,\n\t\t\tedits,\n\t\t\toptions\n\t\t);\n\t}\n\n\t/**\n\t * Check if two editor states are equal.\n\t *\n\t * @param state1 - The first editor state.\n\t * @param state2 - The second editor state.\n\t * @return True if the editor states are equal, false otherwise.\n\t */\n\tprivate areEditorStatesEqual(\n\t\tstate1?: EditorState,\n\t\tstate2?: EditorState\n\t): boolean {\n\t\tif ( ! state1 || ! state2 ) {\n\t\t\treturn state1 === state2;\n\t\t}\n\n\t\tif ( ! state1.selection || ! state2.selection ) {\n\t\t\treturn state1.selection === state2.selection;\n\t\t}\n\n\t\treturn areSelectionsStatesEqual( state1.selection, state2.selection );\n\t}\n\n\t/**\n\t * Resolve a selection state to a text index and block client ID.\n\t *\n\t * For text-based selections, navigates up from the resolved Y.Text via\n\t * AbstractType.parent to find the containing block, then resolves the\n\t * local clientId via the block's tree path.\n\t * For WholeBlock selections, resolves the block's relative position and\n\t * then finds the local clientId via tree path.\n\t *\n\t * Tree-path resolution is used instead of reading the clientId directly\n\t * from the Yjs block because the local block-editor store may use different\n\t * clientIds (e.g. in \"Show Template\" mode where blocks are cloned).\n\t *\n\t * @param selection - The selection state.\n\t * @param blocks - The tree of block-editor store post content blocks.\n\t * @return The rich-text offset and block client ID, or nulls if not resolvable.\n\t */\n\tpublic convertSelectionStateToAbsolute(\n\t\tselection: SelectionState,\n\t\tblocks: EditorStoreBlock[]\n\t): ResolvedSelection {\n\t\tif ( selection.type === SelectionType.None ) {\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId: null,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\tif ( selection.type === SelectionType.WholeBlock ) {\n\t\t\tconst absolutePos = Y.createAbsolutePositionFromRelativePosition(\n\t\t\t\tselection.blockPosition,\n\t\t\t\tthis.doc\n\t\t\t);\n\n\t\t\tlet localClientId: string | null = null;\n\n\t\t\tif ( absolutePos && absolutePos.type instanceof Y.Array ) {\n\t\t\t\tconst parentArray = absolutePos.type as YBlocks;\n\t\t\t\tconst block = parentArray.get( absolutePos.index );\n\n\t\t\t\tif ( block instanceof Y.Map ) {\n\t\t\t\t\tconst path = getBlockPathInYdoc( block );\n\t\t\t\t\tlocalClientId = path\n\t\t\t\t\t\t? resolveBlockClientIdByPath( path, blocks )\n\t\t\t\t\t\t: null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\t// SelectionInMultipleBlocks is decomposed by the caller into per-endpoint\n\t\t// Cursor / WholeBlock calls and should never arrive here directly.\n\t\tif ( selection.type === SelectionType.SelectionInMultipleBlocks ) {\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId: null,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\t// Text-based selections: resolve cursor position and navigate up.\n\t\t// SelectionCursor → cursorPosition; SelectionInOneBlock → cursorStartPosition.\n\t\tconst cursorPos =\n\t\t\t'cursorPosition' in selection\n\t\t\t\t? selection.cursorPosition\n\t\t\t\t: selection.cursorStartPosition;\n\n\t\tconst absolutePosition = Y.createAbsolutePositionFromRelativePosition(\n\t\t\tcursorPos.relativePosition,\n\t\t\tthis.doc\n\t\t);\n\n\t\tif ( ! absolutePosition ) {\n\t\t\treturn {\n\t\t\t\trichTextOffset: null,\n\t\t\t\tlocalClientId: null,\n\t\t\t\tattributeKey: null,\n\t\t\t};\n\t\t}\n\n\t\tconst yType = getContainingBlockYMap( absolutePosition.type );\n\t\tconst path = yType ? getBlockPathInYdoc( yType ) : null;\n\t\tconst localClientId = path\n\t\t\t? resolveBlockClientIdByPath( path, blocks )\n\t\t\t: null;\n\n\t\treturn {\n\t\t\trichTextOffset: htmlIndexToRichTextOffset(\n\t\t\t\tabsolutePosition.type.toString(),\n\t\t\t\tasHtmlStringIndex( absolutePosition.index )\n\t\t\t),\n\t\t\tlocalClientId,\n\t\t\tattributeKey: cursorPos.attributeKey ?? null,\n\t\t};\n\t}\n\n\t/**\n\t * Type guard to check if a struct is a Y.Item (not Y.GC)\n\t * @param struct - The struct to check.\n\t * @return True if the struct is a Y.Item, false otherwise.\n\t */\n\tprivate isYItem( struct: Y.Item | Y.GC ): struct is Y.Item {\n\t\treturn 'content' in struct;\n\t}\n\n\t/**\n\t * Get data for debugging, using the awareness state.\n\t *\n\t * @return {YDocDebugData} The debug data.\n\t */\n\tpublic getDebugData(): YDocDebugData {\n\t\tconst ydoc = this.doc;\n\n\t\t// Manually extract doc data to avoid deprecated toJSON method\n\t\tconst docData: Record< string, unknown > = Object.fromEntries(\n\t\t\tArray.from( ydoc.share, ( [ key, value ] ) => [\n\t\t\t\tkey,\n\t\t\t\tvalue.toJSON(),\n\t\t\t] )\n\t\t);\n\n\t\t// Build collaboratorMap from awareness store (all collaborators seen this session)\n\t\tconst collaboratorMapData = new Map< string, DebugCollaboratorData >(\n\t\t\tArray.from( this.getSeenStates().entries() ).map(\n\t\t\t\t( [ clientId, collaboratorState ] ) => [\n\t\t\t\t\tString( clientId ),\n\t\t\t\t\t{\n\t\t\t\t\t\tname: collaboratorState.collaboratorInfo.name,\n\t\t\t\t\t\twpUserId: collaboratorState.collaboratorInfo.id,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t)\n\t\t);\n\n\t\t// Serialize Yjs client items to avoid deep nesting\n\t\tconst serializableClientItems: Record<\n\t\t\tnumber,\n\t\t\tArray< SerializableYItem >\n\t\t> = {};\n\n\t\tydoc.store.clients.forEach( ( structs, clientId ) => {\n\t\t\t// Filter for Y.Item only (skip Y.GC garbage collection structs)\n\t\t\tconst items = structs.filter( this.isYItem );\n\n\t\t\tserializableClientItems[ clientId ] = items.map( ( item ) => {\n\t\t\t\tconst { left, right, ...rest } = item;\n\n\t\t\t\treturn {\n\t\t\t\t\t...rest,\n\t\t\t\t\tleft: left\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: left.id,\n\t\t\t\t\t\t\t\tlength: left.length,\n\t\t\t\t\t\t\t\torigin: left.origin,\n\t\t\t\t\t\t\t\tcontent: left.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t\tright: right\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tid: right.id,\n\t\t\t\t\t\t\t\tlength: right.length,\n\t\t\t\t\t\t\t\torigin: right.origin,\n\t\t\t\t\t\t\t\tcontent: right.content,\n\t\t\t\t\t\t }\n\t\t\t\t\t\t: null,\n\t\t\t\t};\n\t\t\t} );\n\t\t} );\n\n\t\treturn {\n\t\t\tdoc: docData,\n\t\t\tclients: serializableClientItems,\n\t\t\tcollaboratorMap: Object.fromEntries( collaboratorMapData ),\n\t\t};\n\t}\n}\n\n/**\n * Detect the direction of a selection change by comparing old and new edges.\n *\n * When the user extends a selection backward (e.g. Shift+Left), the\n * selectionStart edge moves while selectionEnd stays fixed, so the caret\n * is at the start. The reverse is true for forward extension.\n *\n * @param prevStart - The previous selectionStart.\n * @param prevEnd - The previous selectionEnd.\n * @param newStart - The new selectionStart.\n * @param newEnd - The new selectionEnd.\n * @return The detected direction, defaulting to Forward when indeterminate.\n */\nfunction detectSelectionDirection(\n\tprevStart: WPBlockSelection,\n\tprevEnd: WPBlockSelection,\n\tnewStart: WPBlockSelection,\n\tnewEnd: WPBlockSelection\n): SelectionDirection {\n\tconst startMoved = ! areBlockSelectionsEqual( prevStart, newStart );\n\tconst endMoved = ! areBlockSelectionsEqual( prevEnd, newEnd );\n\n\tif ( startMoved && ! endMoved ) {\n\t\treturn SelectionDirection.Backward;\n\t}\n\n\treturn SelectionDirection.Forward;\n}\n\n/**\n * Compare two WPBlockSelection objects by value.\n *\n * @param a - First selection.\n * @param b - Second selection.\n * @return True if all fields are equal.\n */\nfunction areBlockSelectionsEqual(\n\ta: WPBlockSelection,\n\tb: WPBlockSelection\n): boolean {\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A,SACA,UACA,QACqB;AACrB,QAAM,aAAa,CAAE,wBAAyB,WAAW,QAAS;AAClE,QAAM,WAAW,CAAE,wBAAyB,SAAS,MAAO;AAE5D,MAAK,cAAc,CAAE,UAAW;AAC/B,WAAO,+CAAmB;AAAA,EAC3B;AAEA,SAAO,+CAAmB;AAC3B;AASA,SAAS,wBACR,GACA,GACU;AACV,SACC,EAAE,aAAa,EAAE,YACjB,EAAE,iBAAiB,EAAE,gBACrB,EAAE,WAAW,EAAE;AAEjB;",
6
6
  "names": ["blockEditorStore", "coreStore", "localClientId", "path"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/awareness/typed-awareness.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport { Awareness } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport { getRecordValue } from './utils';\n\n/**\n * Extended Awareness class with typed state accessors.\n */\nexport class TypedAwareness< State extends object > extends Awareness {\n\t/**\n\t * Get the states from an awareness document.\n\t */\n\tpublic getStates(): Map< number, State > {\n\t\treturn super.getStates() as Map< number, State >;\n\t}\n\n\t/**\n\t * Get a local state field from an awareness document.\n\t * @param field\n\t */\n\tpublic getLocalStateField< FieldName extends keyof State >(\n\t\tfield: FieldName\n\t): State[ FieldName ] | null {\n\t\tconst state: State | null = this.getLocalState() as State | null;\n\t\treturn getRecordValue< State, FieldName >( state, field );\n\t}\n\n\t/**\n\t * Set a local state field on an awareness document.\n\t * @param field\n\t * @param value\n\t */\n\tpublic setLocalStateField< FieldName extends string & keyof State >(\n\t\tfield: FieldName,\n\t\tvalue: State[ FieldName ]\n\t): void {\n\t\tsuper.setLocalStateField( field, value );\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAK1B,mBAA+B;AAKxB,IAAM,iBAAN,cAAqD,sBAAU;AAAA;AAAA;AAAA;AAAA,EAI9D,YAAkC;AACxC,WAAO,MAAM,UAAU;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,mBACN,OAC4B;AAC5B,UAAM,QAAsB,KAAK,cAAc;AAC/C,eAAO,6BAAoC,OAAO,KAAM;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,mBACN,OACA,OACO;AACP,UAAM,mBAAoB,OAAO,KAAM;AAAA,EACxC;AACD;",
4
+ "sourcesContent": ["import { Awareness } from '@wordpress/sync';\nimport { getRecordValue } from './utils';\n\n/**\n * Extended Awareness class with typed state accessors.\n */\nexport class TypedAwareness< State extends object > extends Awareness {\n\t/**\n\t * Get the states from an awareness document.\n\t */\n\tpublic getStates(): Map< number, State > {\n\t\treturn super.getStates() as Map< number, State >;\n\t}\n\n\t/**\n\t * Get a local state field from an awareness document.\n\t * @param field\n\t */\n\tpublic getLocalStateField< FieldName extends keyof State >(\n\t\tfield: FieldName\n\t): State[ FieldName ] | null {\n\t\tconst state: State | null = this.getLocalState() as State | null;\n\t\treturn getRecordValue< State, FieldName >( state, field );\n\t}\n\n\t/**\n\t * Set a local state field on an awareness document.\n\t * @param field\n\t * @param value\n\t */\n\tpublic setLocalStateField< FieldName extends string & keyof State >(\n\t\tfield: FieldName,\n\t\tvalue: State[ FieldName ]\n\t): void {\n\t\tsuper.setLocalStateField( field, value );\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,mBAA+B;AAKxB,IAAM,iBAAN,cAAqD,sBAAU;AAAA;AAAA;AAAA;AAAA,EAI9D,YAAkC;AACxC,WAAO,MAAM,UAAU;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,mBACN,OAC4B;AAC5B,UAAM,QAAsB,KAAK,cAAc;AAC/C,eAAO,6BAAoC,OAAO,KAAM;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,mBACN,OACA,OACO;AACP,UAAM,mBAAoB,OAAO,KAAM;AAAA,EACxC;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/awareness/types.ts"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport type { SelectionState } from '../types';\nimport type { User } from '../entity-types';\n\nexport type CollaboratorInfo = Pick<\n\tUser< 'view' >,\n\t'id' | 'name' | 'slug' | 'avatar_urls'\n> & {\n\tbrowserType: string;\n\tenteredAt: number;\n};\n\n/**\n * This base state represents the presence of the collaborator. We expect it to be\n * extended to include additional state describing the collaborator's current activity.\n * This state must be serializable and compact.\n */\nexport interface BaseState {\n\tcollaboratorInfo: CollaboratorInfo;\n}\n\n/**\n * The editor state includes information about the collaborator's current selection.\n */\nexport interface EditorState {\n\tselection?: SelectionState;\n}\n\n/**\n * The post editor state extends the base state with information used to render\n * presence indicators in the post editor.\n */\nexport interface PostEditorState extends BaseState {\n\teditorState?: EditorState;\n}\n\n/**\n * An enhanced state includes additional metadata about the collaborator's connection.\n */\nexport type EnhancedState< State > = State & {\n\tclientId: number;\n\tisConnected: boolean;\n\tisMe: boolean;\n};\n\n/**\n * An enhanced post editor awareness state includes additional metadata about\n * the collaborator and their connection.\n */\nexport type PostEditorAwarenessState = EnhancedState< PostEditorState >;\n\n// WordPress collaborator info for debug export (subset of CollaboratorInfo)\nexport type DebugCollaboratorData = Pick< CollaboratorInfo, 'name' > & {\n\twpUserId: CollaboratorInfo[ 'id' ];\n};\n\nexport interface YDocDebugData {\n\tdoc: Record< string, unknown >;\n\tclients: Record< number, Array< SerializableYItem > >;\n\tcollaboratorMap: Record< string, DebugCollaboratorData >;\n}\n\n// Type for serializable left/right item references to avoid deep nesting\nexport type SerializableYItemRef = Pick<\n\tY.Item,\n\t'id' | 'length' | 'origin' | 'content'\n>;\n\n// Serializable Y.Item - only includes data properties with shallow left/right references\nexport type SerializableYItem = Pick<\n\tY.Item,\n\t| 'id'\n\t| 'length'\n\t| 'origin'\n\t| 'rightOrigin'\n\t| 'parent'\n\t| 'parentSub'\n\t| 'redone'\n\t| 'content'\n\t| 'info'\n> & {\n\tleft: SerializableYItemRef | null;\n\tright: SerializableYItemRef | null;\n};\n\nexport type EqualityFieldCheck< State, FieldName extends keyof State > = (\n\tvalue1?: State[ FieldName ],\n\tvalue2?: State[ FieldName ]\n) => boolean;\n\nexport interface PostSaveEvent {\n\tsavedAt: number;\n\tsavedByClientId: number;\n\tpostStatus: string | undefined;\n}\n"],
4
+ "sourcesContent": ["import type { Y } from '@wordpress/sync';\nimport type { SelectionState } from '../types';\nimport type { User } from '../entity-types';\n\nexport type CollaboratorInfo = Pick<\n\tUser< 'view' >,\n\t'id' | 'name' | 'slug' | 'avatar_urls'\n> & {\n\tbrowserType: string;\n\tenteredAt: number;\n};\n\n/**\n * This base state represents the presence of the collaborator. We expect it to be\n * extended to include additional state describing the collaborator's current activity.\n * This state must be serializable and compact.\n */\nexport interface BaseState {\n\tcollaboratorInfo: CollaboratorInfo;\n}\n\n/**\n * The editor state includes information about the collaborator's current selection.\n */\nexport interface EditorState {\n\tselection?: SelectionState;\n}\n\n/**\n * The post editor state extends the base state with information used to render\n * presence indicators in the post editor.\n */\nexport interface PostEditorState extends BaseState {\n\teditorState?: EditorState;\n}\n\n/**\n * An enhanced state includes additional metadata about the collaborator's connection.\n */\nexport type EnhancedState< State > = State & {\n\tclientId: number;\n\tisConnected: boolean;\n\tisMe: boolean;\n};\n\n/**\n * An enhanced post editor awareness state includes additional metadata about\n * the collaborator and their connection.\n */\nexport type PostEditorAwarenessState = EnhancedState< PostEditorState >;\n\n// WordPress collaborator info for debug export (subset of CollaboratorInfo)\nexport type DebugCollaboratorData = Pick< CollaboratorInfo, 'name' > & {\n\twpUserId: CollaboratorInfo[ 'id' ];\n};\n\nexport interface YDocDebugData {\n\tdoc: Record< string, unknown >;\n\tclients: Record< number, Array< SerializableYItem > >;\n\tcollaboratorMap: Record< string, DebugCollaboratorData >;\n}\n\n// Type for serializable left/right item references to avoid deep nesting\nexport type SerializableYItemRef = Pick<\n\tY.Item,\n\t'id' | 'length' | 'origin' | 'content'\n>;\n\n// Serializable Y.Item - only includes data properties with shallow left/right references\nexport type SerializableYItem = Pick<\n\tY.Item,\n\t| 'id'\n\t| 'length'\n\t| 'origin'\n\t| 'rightOrigin'\n\t| 'parent'\n\t| 'parentSub'\n\t| 'redone'\n\t| 'content'\n\t| 'info'\n> & {\n\tleft: SerializableYItemRef | null;\n\tright: SerializableYItemRef | null;\n};\n\nexport type EqualityFieldCheck< State, FieldName extends keyof State > = (\n\tvalue1?: State[ FieldName ],\n\tvalue2?: State[ FieldName ]\n) => boolean;\n\nexport interface PostSaveEvent {\n\tsavedAt: number;\n\tsavedByClientId: number;\n\tpostStatus: string | undefined;\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/awareness/utils.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { User } from '../entity-types';\nimport type { CollaboratorInfo } from './types';\n\n/**\n * Get the browser name from the user agent.\n * @return The browser name.\n */\nfunction getBrowserName(): string {\n\tconst userAgent = window.navigator.userAgent;\n\tlet browserName = 'Unknown';\n\n\tif ( userAgent.includes( 'Firefox' ) ) {\n\t\tbrowserName = 'Firefox';\n\t} else if ( userAgent.includes( 'Edg' ) ) {\n\t\tbrowserName = 'Microsoft Edge';\n\t} else if (\n\t\tuserAgent.includes( 'Chrome' ) &&\n\t\t! userAgent.includes( 'Edg' )\n\t) {\n\t\tbrowserName = 'Chrome';\n\t} else if (\n\t\tuserAgent.includes( 'Safari' ) &&\n\t\t! userAgent.includes( 'Chrome' )\n\t) {\n\t\tbrowserName = 'Safari';\n\t} else if (\n\t\tuserAgent.includes( 'MSIE' ) ||\n\t\tuserAgent.includes( 'Trident' )\n\t) {\n\t\tbrowserName = 'Internet Explorer';\n\t} else if ( userAgent.includes( 'Opera' ) || userAgent.includes( 'OPR' ) ) {\n\t\tbrowserName = 'Opera';\n\t}\n\n\treturn browserName;\n}\n\nexport function areMapsEqual< Key, Value >(\n\tmap1: Map< Key, Value >,\n\tmap2: Map< Key, Value >,\n\tcomparatorFn: ( value1: Value, value2: Value ) => boolean\n): boolean {\n\tif ( map1.size !== map2.size ) {\n\t\treturn false;\n\t}\n\n\tfor ( const [ key, value1 ] of map1.entries() ) {\n\t\tif ( ! map2.has( key ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( ! comparatorFn( value1, map2.get( key )! ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Check if two collaborator infos are equal.\n *\n * @param collaboratorInfo1 - The first collaborator info.\n * @param collaboratorInfo2 - The second collaborator info.\n * @return True if the collaborator infos are equal, false otherwise.\n */\nexport function areCollaboratorInfosEqual(\n\tcollaboratorInfo1?: CollaboratorInfo,\n\tcollaboratorInfo2?: CollaboratorInfo\n): boolean {\n\tif ( ! collaboratorInfo1 || ! collaboratorInfo2 ) {\n\t\treturn collaboratorInfo1 === collaboratorInfo2;\n\t}\n\n\tif (\n\t\tObject.keys( collaboratorInfo1 ).length !==\n\t\tObject.keys( collaboratorInfo2 ).length\n\t) {\n\t\treturn false;\n\t}\n\n\treturn Object.entries( collaboratorInfo1 ).every( ( [ key, value ] ) => {\n\t\t// Update this function with any non-primitive fields added to CollaboratorInfo.\n\t\treturn value === collaboratorInfo2[ key as keyof CollaboratorInfo ];\n\t} );\n}\n\n/**\n * Generate a collaborator info object from a current collaborator.\n *\n * @param currentCollaborator - The current collaborator.\n * @return The collaborator info object.\n */\nexport function generateCollaboratorInfo(\n\tcurrentCollaborator: User< 'view' >\n): CollaboratorInfo {\n\t// eslint-disable-next-line camelcase\n\tconst { avatar_urls, id, name, slug } = currentCollaborator;\n\treturn {\n\t\tavatar_urls, // eslint-disable-line camelcase\n\t\tbrowserType: getBrowserName(),\n\t\tenteredAt: Date.now(),\n\t\tid,\n\t\tname,\n\t\tslug,\n\t};\n}\n\nexport function getRecordValue< RecordType, Key extends keyof RecordType >(\n\tobj: unknown,\n\tkey: Key\n): RecordType[ Key ] | null {\n\tif ( 'object' === typeof obj && null !== obj && key in obj ) {\n\t\treturn ( obj as RecordType )[ key ];\n\t}\n\n\treturn null;\n}\n\nexport function getTypedKeys< T extends object >( obj: T ): Array< keyof T > {\n\treturn Object.keys( obj ) as Array< keyof T >;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,SAAS,iBAAyB;AACjC,QAAM,YAAY,OAAO,UAAU;AACnC,MAAI,cAAc;AAElB,MAAK,UAAU,SAAU,SAAU,GAAI;AACtC,kBAAc;AAAA,EACf,WAAY,UAAU,SAAU,KAAM,GAAI;AACzC,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,QAAS,KAC7B,CAAE,UAAU,SAAU,KAAM,GAC3B;AACD,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,QAAS,KAC7B,CAAE,UAAU,SAAU,QAAS,GAC9B;AACD,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,MAAO,KAC3B,UAAU,SAAU,SAAU,GAC7B;AACD,kBAAc;AAAA,EACf,WAAY,UAAU,SAAU,OAAQ,KAAK,UAAU,SAAU,KAAM,GAAI;AAC1E,kBAAc;AAAA,EACf;AAEA,SAAO;AACR;AAEO,SAAS,aACf,MACA,MACA,cACU;AACV,MAAK,KAAK,SAAS,KAAK,MAAO;AAC9B,WAAO;AAAA,EACR;AAEA,aAAY,CAAE,KAAK,MAAO,KAAK,KAAK,QAAQ,GAAI;AAC/C,QAAK,CAAE,KAAK,IAAK,GAAI,GAAI;AACxB,aAAO;AAAA,IACR;AAEA,QAAK,CAAE,aAAc,QAAQ,KAAK,IAAK,GAAI,CAAG,GAAI;AACjD,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AASO,SAAS,0BACf,mBACA,mBACU;AACV,MAAK,CAAE,qBAAqB,CAAE,mBAAoB;AACjD,WAAO,sBAAsB;AAAA,EAC9B;AAEA,MACC,OAAO,KAAM,iBAAkB,EAAE,WACjC,OAAO,KAAM,iBAAkB,EAAE,QAChC;AACD,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,QAAS,iBAAkB,EAAE,MAAO,CAAE,CAAE,KAAK,KAAM,MAAO;AAEvE,WAAO,UAAU,kBAAmB,GAA8B;AAAA,EACnE,CAAE;AACH;AAQO,SAAS,yBACf,qBACmB;AAEnB,QAAM,EAAE,aAAa,IAAI,MAAM,KAAK,IAAI;AACxC,SAAO;AAAA,IACN;AAAA;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,WAAW,KAAK,IAAI;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,SAAS,eACf,KACA,KAC2B;AAC3B,MAAK,aAAa,OAAO,OAAO,SAAS,OAAO,OAAO,KAAM;AAC5D,WAAS,IAAqB,GAAI;AAAA,EACnC;AAEA,SAAO;AACR;AAEO,SAAS,aAAkC,KAA2B;AAC5E,SAAO,OAAO,KAAM,GAAI;AACzB;",
4
+ "sourcesContent": ["import type { User } from '../entity-types';\nimport type { CollaboratorInfo } from './types';\n\n/**\n * Get the browser name from the user agent.\n * @return The browser name.\n */\nfunction getBrowserName(): string {\n\tconst userAgent = window.navigator.userAgent;\n\tlet browserName = 'Unknown';\n\n\tif ( userAgent.includes( 'Firefox' ) ) {\n\t\tbrowserName = 'Firefox';\n\t} else if ( userAgent.includes( 'Edg' ) ) {\n\t\tbrowserName = 'Microsoft Edge';\n\t} else if (\n\t\tuserAgent.includes( 'Chrome' ) &&\n\t\t! userAgent.includes( 'Edg' )\n\t) {\n\t\tbrowserName = 'Chrome';\n\t} else if (\n\t\tuserAgent.includes( 'Safari' ) &&\n\t\t! userAgent.includes( 'Chrome' )\n\t) {\n\t\tbrowserName = 'Safari';\n\t} else if (\n\t\tuserAgent.includes( 'MSIE' ) ||\n\t\tuserAgent.includes( 'Trident' )\n\t) {\n\t\tbrowserName = 'Internet Explorer';\n\t} else if ( userAgent.includes( 'Opera' ) || userAgent.includes( 'OPR' ) ) {\n\t\tbrowserName = 'Opera';\n\t}\n\n\treturn browserName;\n}\n\nexport function areMapsEqual< Key, Value >(\n\tmap1: Map< Key, Value >,\n\tmap2: Map< Key, Value >,\n\tcomparatorFn: ( value1: Value, value2: Value ) => boolean\n): boolean {\n\tif ( map1.size !== map2.size ) {\n\t\treturn false;\n\t}\n\n\tfor ( const [ key, value1 ] of map1.entries() ) {\n\t\tif ( ! map2.has( key ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( ! comparatorFn( value1, map2.get( key )! ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n\n/**\n * Check if two collaborator infos are equal.\n *\n * @param collaboratorInfo1 - The first collaborator info.\n * @param collaboratorInfo2 - The second collaborator info.\n * @return True if the collaborator infos are equal, false otherwise.\n */\nexport function areCollaboratorInfosEqual(\n\tcollaboratorInfo1?: CollaboratorInfo,\n\tcollaboratorInfo2?: CollaboratorInfo\n): boolean {\n\tif ( ! collaboratorInfo1 || ! collaboratorInfo2 ) {\n\t\treturn collaboratorInfo1 === collaboratorInfo2;\n\t}\n\n\tif (\n\t\tObject.keys( collaboratorInfo1 ).length !==\n\t\tObject.keys( collaboratorInfo2 ).length\n\t) {\n\t\treturn false;\n\t}\n\n\treturn Object.entries( collaboratorInfo1 ).every( ( [ key, value ] ) => {\n\t\t// Update this function with any non-primitive fields added to CollaboratorInfo.\n\t\treturn value === collaboratorInfo2[ key as keyof CollaboratorInfo ];\n\t} );\n}\n\n/**\n * Generate a collaborator info object from a current collaborator.\n *\n * @param currentCollaborator - The current collaborator.\n * @return The collaborator info object.\n */\nexport function generateCollaboratorInfo(\n\tcurrentCollaborator: User< 'view' >\n): CollaboratorInfo {\n\t// eslint-disable-next-line camelcase\n\tconst { avatar_urls, id, name, slug } = currentCollaborator;\n\treturn {\n\t\tavatar_urls, // eslint-disable-line camelcase\n\t\tbrowserType: getBrowserName(),\n\t\tenteredAt: Date.now(),\n\t\tid,\n\t\tname,\n\t\tslug,\n\t};\n}\n\nexport function getRecordValue< RecordType, Key extends keyof RecordType >(\n\tobj: unknown,\n\tkey: Key\n): RecordType[ Key ] | null {\n\tif ( 'object' === typeof obj && null !== obj && key in obj ) {\n\t\treturn ( obj as RecordType )[ key ];\n\t}\n\n\treturn null;\n}\n\nexport function getTypedKeys< T extends object >( obj: T ): Array< keyof T > {\n\treturn Object.keys( obj ) as Array< keyof T >;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,SAAS,iBAAyB;AACjC,QAAM,YAAY,OAAO,UAAU;AACnC,MAAI,cAAc;AAElB,MAAK,UAAU,SAAU,SAAU,GAAI;AACtC,kBAAc;AAAA,EACf,WAAY,UAAU,SAAU,KAAM,GAAI;AACzC,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,QAAS,KAC7B,CAAE,UAAU,SAAU,KAAM,GAC3B;AACD,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,QAAS,KAC7B,CAAE,UAAU,SAAU,QAAS,GAC9B;AACD,kBAAc;AAAA,EACf,WACC,UAAU,SAAU,MAAO,KAC3B,UAAU,SAAU,SAAU,GAC7B;AACD,kBAAc;AAAA,EACf,WAAY,UAAU,SAAU,OAAQ,KAAK,UAAU,SAAU,KAAM,GAAI;AAC1E,kBAAc;AAAA,EACf;AAEA,SAAO;AACR;AAEO,SAAS,aACf,MACA,MACA,cACU;AACV,MAAK,KAAK,SAAS,KAAK,MAAO;AAC9B,WAAO;AAAA,EACR;AAEA,aAAY,CAAE,KAAK,MAAO,KAAK,KAAK,QAAQ,GAAI;AAC/C,QAAK,CAAE,KAAK,IAAK,GAAI,GAAI;AACxB,aAAO;AAAA,IACR;AAEA,QAAK,CAAE,aAAc,QAAQ,KAAK,IAAK,GAAI,CAAG,GAAI;AACjD,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AASO,SAAS,0BACf,mBACA,mBACU;AACV,MAAK,CAAE,qBAAqB,CAAE,mBAAoB;AACjD,WAAO,sBAAsB;AAAA,EAC9B;AAEA,MACC,OAAO,KAAM,iBAAkB,EAAE,WACjC,OAAO,KAAM,iBAAkB,EAAE,QAChC;AACD,WAAO;AAAA,EACR;AAEA,SAAO,OAAO,QAAS,iBAAkB,EAAE,MAAO,CAAE,CAAE,KAAK,KAAM,MAAO;AAEvE,WAAO,UAAU,kBAAmB,GAA8B;AAAA,EACnE,CAAE;AACH;AAQO,SAAS,yBACf,qBACmB;AAEnB,QAAM,EAAE,aAAa,IAAI,MAAM,KAAK,IAAI;AACxC,SAAO;AAAA,IACN;AAAA;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,WAAW,KAAK,IAAI;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,SAAS,eACf,KACA,KAC2B;AAC3B,MAAK,aAAa,OAAO,OAAO,SAAS,OAAO,OAAO,KAAM;AAC5D,WAAS,IAAqB,GAAI;AAAA,EACnC;AAEA,SAAO;AACR;AAEO,SAAS,aAAkC,KAA2B;AAC5E,SAAO,OAAO,KAAM,GAAI;AACzB;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/batch/create-batch.js"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultProcessor from './default-processor';\n\n/**\n * Creates a batch, which can be used to combine multiple API requests into one\n * API request using the WordPress batch processing API (/v1/batch).\n *\n * ```\n * const batch = createBatch();\n * const dunePromise = batch.add( {\n * path: '/v1/books',\n * method: 'POST',\n * data: { title: 'Dune' }\n * } );\n * const lotrPromise = batch.add( {\n * path: '/v1/books',\n * method: 'POST',\n * data: { title: 'Lord of the Rings' }\n * } );\n * const isSuccess = await batch.run(); // Sends one POST to /v1/batch.\n * if ( isSuccess ) {\n * console.log(\n * 'Saved two books:',\n * await dunePromise,\n * await lotrPromise\n * );\n * }\n * ```\n *\n * @param {Function} [processor] Processor function. Can be used to replace the\n * default functionality which is to send an API\n * request to /v1/batch. Is given an array of\n * inputs and must return a promise that\n * resolves to an array of objects containing\n * either `output` or `error`.\n */\nexport default function createBatch( processor = defaultProcessor ) {\n\tlet lastId = 0;\n\t/** @type {Array<{ input: any; resolve: ( value: any ) => void; reject: ( error: any ) => void }>} */\n\tlet queue = [];\n\tconst pending = new ObservableSet();\n\n\treturn {\n\t\t/**\n\t\t * Adds an input to the batch and returns a promise that is resolved or\n\t\t * rejected when the input is processed by `batch.run()`.\n\t\t *\n\t\t * You may also pass a thunk which allows inputs to be added\n\t\t * asynchronously.\n\t\t *\n\t\t * ```\n\t\t * // Both are allowed:\n\t\t * batch.add( { path: '/v1/books', ... } );\n\t\t * batch.add( ( add ) => add( { path: '/v1/books', ... } ) );\n\t\t * ```\n\t\t *\n\t\t * If a thunk is passed, `batch.run()` will pause until either:\n\t\t *\n\t\t * - The thunk calls its `add` argument, or;\n\t\t * - The thunk returns a promise and that promise resolves, or;\n\t\t * - The thunk returns a non-promise.\n\t\t *\n\t\t * @param {any|Function} inputOrThunk Input to add or thunk to execute.\n\t\t *\n\t\t * @return {Promise|any} If given an input, returns a promise that\n\t\t * is resolved or rejected when the batch is\n\t\t * processed. If given a thunk, returns the return\n\t\t * value of that thunk.\n\t\t */\n\t\tadd( inputOrThunk ) {\n\t\t\tconst id = ++lastId;\n\t\t\tpending.add( id );\n\n\t\t\tconst add = ( input ) =>\n\t\t\t\tnew Promise( ( resolve, reject ) => {\n\t\t\t\t\tqueue.push( {\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\tresolve,\n\t\t\t\t\t\treject,\n\t\t\t\t\t} );\n\t\t\t\t\tpending.delete( id );\n\t\t\t\t} );\n\n\t\t\tif ( typeof inputOrThunk === 'function' ) {\n\t\t\t\treturn Promise.resolve( inputOrThunk( add ) ).finally( () => {\n\t\t\t\t\tpending.delete( id );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn add( inputOrThunk );\n\t\t},\n\n\t\t/**\n\t\t * Runs the batch. This calls `batchProcessor` and resolves or rejects\n\t\t * all promises returned by `add()`.\n\t\t *\n\t\t * @return {Promise<boolean>} A promise that resolves to a boolean that is true\n\t\t * if the processor returned no errors.\n\t\t */\n\t\tasync run() {\n\t\t\tif ( pending.size ) {\n\t\t\t\tawait new Promise( ( resolve ) => {\n\t\t\t\t\tconst unsubscribe = pending.subscribe( () => {\n\t\t\t\t\t\tif ( ! pending.size ) {\n\t\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\t\tresolve( undefined );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tlet results;\n\n\t\t\ttry {\n\t\t\t\tresults = await processor(\n\t\t\t\t\tqueue.map( ( { input } ) => input )\n\t\t\t\t);\n\n\t\t\t\tif ( results.length !== queue.length ) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'run: Array returned by processor must be same size as input array.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tfor ( const { reject } of queue ) {\n\t\t\t\t\treject( error );\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tlet isSuccess = true;\n\n\t\t\tresults.forEach( ( result, key ) => {\n\t\t\t\tconst queueItem = queue[ key ];\n\n\t\t\t\tif ( result?.error ) {\n\t\t\t\t\tqueueItem?.reject( result.error );\n\t\t\t\t\tisSuccess = false;\n\t\t\t\t} else {\n\t\t\t\t\tqueueItem?.resolve( result?.output ?? result );\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\tqueue = [];\n\n\t\t\treturn isSuccess;\n\t\t},\n\t};\n}\n\nclass ObservableSet {\n\tconstructor( ...args ) {\n\t\tthis.set = new Set( ...args );\n\t\tthis.subscribers = new Set();\n\t}\n\n\tget size() {\n\t\treturn this.set.size;\n\t}\n\n\tadd( value ) {\n\t\tthis.set.add( value );\n\t\tthis.subscribers.forEach( ( subscriber ) => subscriber() );\n\t\treturn this;\n\t}\n\n\tdelete( value ) {\n\t\tconst isSuccess = this.set.delete( value );\n\t\tthis.subscribers.forEach( ( subscriber ) => subscriber() );\n\t\treturn isSuccess;\n\t}\n\n\tsubscribe( subscriber ) {\n\t\tthis.subscribers.add( subscriber );\n\t\treturn () => {\n\t\t\tthis.subscribers.delete( subscriber );\n\t\t};\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,+BAA6B;AAmCd,SAAR,YAA8B,YAAY,yBAAAA,SAAmB;AACnE,MAAI,SAAS;AAEb,MAAI,QAAQ,CAAC;AACb,QAAM,UAAU,IAAI,cAAc;AAElC,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IA2BN,IAAK,cAAe;AACnB,YAAM,KAAK,EAAE;AACb,cAAQ,IAAK,EAAG;AAEhB,YAAM,MAAM,CAAE,UACb,IAAI,QAAS,CAAE,SAAS,WAAY;AACnC,cAAM,KAAM;AAAA,UACX;AAAA,UACA;AAAA,UACA;AAAA,QACD,CAAE;AACF,gBAAQ,OAAQ,EAAG;AAAA,MACpB,CAAE;AAEH,UAAK,OAAO,iBAAiB,YAAa;AACzC,eAAO,QAAQ,QAAS,aAAc,GAAI,CAAE,EAAE,QAAS,MAAM;AAC5D,kBAAQ,OAAQ,E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,SAAK,YAAY,QAAS,CAAE,eAAgB,WAAW,CAAE;AACzD,WAAO;AAAA,EACR;AAAA,EAEA,OAAQ,OAAQ;AACf,UAAM,YAAY,KAAK,IAAI,OAAQ,KAAM;AACzC,SAAK,YAAY,QAAS,CAAE,eAAgB,WAAW,CAAE;AACzD,WAAO;AAAA,EACR;AAAA,EAEA,UAAW,YAAa;AACvB,SAAK,YAAY,IAAK,UAAW;AACjC,WAAO,MAAM;AACZ,WAAK,YAAY,OAAQ,UAAW;AAAA,IACrC;AAAA,EACD;AACD;",
4
+ "sourcesContent": ["import defaultProcessor from './default-processor';\n\n/**\n * Creates a batch, which can be used to combine multiple API requests into one\n * API request using the WordPress batch processing API (/v1/batch).\n *\n * ```\n * const batch = createBatch();\n * const dunePromise = batch.add( {\n * path: '/v1/books',\n * method: 'POST',\n * data: { title: 'Dune' }\n * } );\n * const lotrPromise = batch.add( {\n * path: '/v1/books',\n * method: 'POST',\n * data: { title: 'Lord of the Rings' }\n * } );\n * const isSuccess = await batch.run(); // Sends one POST to /v1/batch.\n * if ( isSuccess ) {\n * console.log(\n * 'Saved two books:',\n * await dunePromise,\n * await lotrPromise\n * );\n * }\n * ```\n *\n * @param {Function} [processor] Processor function. Can be used to replace the\n * default functionality which is to send an API\n * request to /v1/batch. Is given an array of\n * inputs and must return a promise that\n * resolves to an array of objects containing\n * either `output` or `error`.\n */\nexport default function createBatch( processor = defaultProcessor ) {\n\tlet lastId = 0;\n\t/** @type {Array<{ input: any; resolve: ( value: any ) => void; reject: ( error: any ) => void }>} */\n\tlet queue = [];\n\tconst pending = new ObservableSet();\n\n\treturn {\n\t\t/**\n\t\t * Adds an input to the batch and returns a promise that is resolved or\n\t\t * rejected when the input is processed by `batch.run()`.\n\t\t *\n\t\t * You may also pass a thunk which allows inputs to be added\n\t\t * asynchronously.\n\t\t *\n\t\t * ```\n\t\t * // Both are allowed:\n\t\t * batch.add( { path: '/v1/books', ... } );\n\t\t * batch.add( ( add ) => add( { path: '/v1/books', ... } ) );\n\t\t * ```\n\t\t *\n\t\t * If a thunk is passed, `batch.run()` will pause until either:\n\t\t *\n\t\t * - The thunk calls its `add` argument, or;\n\t\t * - The thunk returns a promise and that promise resolves, or;\n\t\t * - The thunk returns a non-promise.\n\t\t *\n\t\t * @param {any|Function} inputOrThunk Input to add or thunk to execute.\n\t\t *\n\t\t * @return {Promise|any} If given an input, returns a promise that\n\t\t * is resolved or rejected when the batch is\n\t\t * processed. If given a thunk, returns the return\n\t\t * value of that thunk.\n\t\t */\n\t\tadd( inputOrThunk ) {\n\t\t\tconst id = ++lastId;\n\t\t\tpending.add( id );\n\n\t\t\tconst add = ( input ) =>\n\t\t\t\tnew Promise( ( resolve, reject ) => {\n\t\t\t\t\tqueue.push( {\n\t\t\t\t\t\tinput,\n\t\t\t\t\t\tresolve,\n\t\t\t\t\t\treject,\n\t\t\t\t\t} );\n\t\t\t\t\tpending.delete( id );\n\t\t\t\t} );\n\n\t\t\tif ( typeof inputOrThunk === 'function' ) {\n\t\t\t\treturn Promise.resolve( inputOrThunk( add ) ).finally( () => {\n\t\t\t\t\tpending.delete( id );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\treturn add( inputOrThunk );\n\t\t},\n\n\t\t/**\n\t\t * Runs the batch. This calls `batchProcessor` and resolves or rejects\n\t\t * all promises returned by `add()`.\n\t\t *\n\t\t * @return {Promise<boolean>} A promise that resolves to a boolean that is true\n\t\t * if the processor returned no errors.\n\t\t */\n\t\tasync run() {\n\t\t\tif ( pending.size ) {\n\t\t\t\tawait new Promise( ( resolve ) => {\n\t\t\t\t\tconst unsubscribe = pending.subscribe( () => {\n\t\t\t\t\t\tif ( ! pending.size ) {\n\t\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\t\tresolve( undefined );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tlet results;\n\n\t\t\ttry {\n\t\t\t\tresults = await processor(\n\t\t\t\t\tqueue.map( ( { input } ) => input )\n\t\t\t\t);\n\n\t\t\t\tif ( results.length !== queue.length ) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t'run: Array returned by processor must be same size as input array.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch ( error ) {\n\t\t\t\tfor ( const { reject } of queue ) {\n\t\t\t\t\treject( error );\n\t\t\t\t}\n\n\t\t\t\tthrow error;\n\t\t\t}\n\n\t\t\tlet isSuccess = true;\n\n\t\t\tresults.forEach( ( result, key ) => {\n\t\t\t\tconst queueItem = queue[ key ];\n\n\t\t\t\tif ( result?.error ) {\n\t\t\t\t\tqueueItem?.reject( result.error );\n\t\t\t\t\tisSuccess = false;\n\t\t\t\t} else {\n\t\t\t\t\tqueueItem?.resolve( result?.output ?? result );\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\tqueue = [];\n\n\t\t\treturn isSuccess;\n\t\t},\n\t};\n}\n\nclass ObservableSet {\n\tconstructor( ...args ) {\n\t\tthis.set = new Set( ...args );\n\t\tthis.subscribers = new Set();\n\t}\n\n\tget size() {\n\t\treturn this.set.size;\n\t}\n\n\tadd( value ) {\n\t\tthis.set.add( value );\n\t\tthis.subscribers.forEach( ( subscriber ) => subscriber() );\n\t\treturn this;\n\t}\n\n\tdelete( value ) {\n\t\tconst isSuccess = this.set.delete( value );\n\t\tthis.subscribers.forEach( ( subscriber ) => subscriber() );\n\t\treturn isSuccess;\n\t}\n\n\tsubscribe( subscriber ) {\n\t\tthis.subscribers.add( subscriber );\n\t\treturn () => {\n\t\t\tthis.subscribers.delete( subscriber );\n\t\t};\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAA6B;AAmCd,SAAR,YAA8B,YAAY,yBAAAA,SAAmB;AACnE,MAAI,SAAS;AAEb,MAAI,QAAQ,CAAC;AACb,QAAM,UAAU,IAAI,cAAc;AAElC,SAAO;AAAA;AAAA;AAAA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AACnC,cAAM,YAAY,MAAO,GAAI;AAE7B,YAAK,QAAQ,OAAQ;AACpB,qBAAW,OAAQ,OAAO,KAAM;AAChC,sBAAY;AAAA,QACb,OAAO;AACN,qBAAW,QAAS,QAAQ,UAAU,MAAO;AAAA,QAC9C;AAAA,MACD,CAAE;AAEF,cAAQ,CAAC;AAET,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAM,gBAAN,MAAoB;AAAA,EACnB,eAAgB,MAAO;AACtB,SAAK,MAAM,IAAI,IAAK,GAAG,IAAK;AAC5B,SAAK,cAAc,oBAAI,IAAI;AAAA,EAC5B;AAAA,EAEA,IAAI,OAAO;AACV,WAAO,KAAK,IAAI;AAAA,EACjB;AAAA,EAEA,IAAK,OAAQ;AACZ,SAAK,IAAI,IAAK,KAAM;AACpB,SAAK,YAAY,QAAS,CAAE,eAAgB,WAAW,CAAE;AACzD,WAAO;AAAA,EACR;AAAA,EAEA,OAAQ,OAAQ;AACf,UAAM,YAAY,KAAK,IAAI,OAAQ,KAAM;AACzC,SAAK,YAAY,QAAS,CAAE,eAAgB,WAAW,CAAE;AACzD,WAAO;AAAA,EACR;AAAA,EAEA,UAAW,YAAa;AACvB,SAAK,YAAY,IAAK,UAAW;AACjC,WAAO,MAAM;AACZ,WAAK,YAAY,OAAQ,UAAW;AAAA,IACrC;AAAA,EACD;AACD;",
6
6
  "names": ["defaultProcessor"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/batch/default-processor.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Maximum number of requests to place in a single batch request. Obtained by\n * sending a preflight OPTIONS request to /batch/v1/.\n *\n * @type {number?}\n */\nlet maxItems = null;\n\nfunction chunk( arr, chunkSize ) {\n\tconst tmp = [ ...arr ];\n\tconst cache = [];\n\twhile ( tmp.length ) {\n\t\tcache.push( tmp.splice( 0, chunkSize ) );\n\t}\n\n\treturn cache;\n}\n\n/**\n * Default batch processor. Sends its input requests to /batch/v1.\n *\n * @param {Array} requests List of API requests to perform at once.\n *\n * @return {Promise} Promise that resolves to a list of objects containing\n * either `output` (if that request was successful) or `error`\n * (if not ).\n */\nexport default async function defaultProcessor( requests ) {\n\tif ( maxItems === null ) {\n\t\tconst preflightResponse = await apiFetch( {\n\t\t\tpath: '/batch/v1',\n\t\t\tmethod: 'OPTIONS',\n\t\t} );\n\t\tmaxItems = preflightResponse.endpoints[ 0 ].args.requests.maxItems;\n\t}\n\n\tconst results = [];\n\n\t// @ts-ignore We would have crashed or never gotten to this point if we hadn't received the maxItems count.\n\tfor ( const batchRequests of chunk( requests, maxItems ) ) {\n\t\tconst batchResponse = await apiFetch( {\n\t\t\tpath: '/batch/v1',\n\t\t\tmethod: 'POST',\n\t\t\tdata: {\n\t\t\t\tvalidation: 'require-all-validate',\n\t\t\t\trequests: batchRequests.map( ( request ) => ( {\n\t\t\t\t\tpath: request.path,\n\t\t\t\t\tbody: request.data, // Rename 'data' to 'body'.\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\theaders: request.headers,\n\t\t\t\t} ) ),\n\t\t\t},\n\t\t} );\n\n\t\tlet batchResults;\n\n\t\tif ( batchResponse.failed ) {\n\t\t\tbatchResults = batchResponse.responses.map( ( response ) => ( {\n\t\t\t\terror: response?.body,\n\t\t\t} ) );\n\t\t} else {\n\t\t\tbatchResults = batchResponse.responses.map( ( response ) => {\n\t\t\t\tconst result = {};\n\t\t\t\tif ( response.status >= 200 && response.status < 300 ) {\n\t\t\t\t\tresult.output = response.body;\n\t\t\t\t} else {\n\t\t\t\t\tresult.error = response.body;\n\t\t\t\t}\n\t\t\t\treturn result;\n\t\t\t} );\n\t\t}\n\n\t\tresults.push( ...batchResults );\n\t}\n\n\treturn results;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAQr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;",
4
+ "sourcesContent": ["import apiFetch from '@wordpress/api-fetch';\n\n/**\n * Maximum number of requests to place in a single batch request. Obtained by\n * sending a preflight OPTIONS request to /batch/v1/.\n *\n * @type {number?}\n */\nlet maxItems = null;\n\nfunction chunk( arr, chunkSize ) {\n\tconst tmp = [ ...arr ];\n\tconst cache = [];\n\twhile ( tmp.length ) {\n\t\tcache.push( tmp.splice( 0, chunkSize ) );\n\t}\n\n\treturn cache;\n}\n\n/**\n * Default batch processor. Sends its input requests to /batch/v1.\n *\n * @param {Array} requests List of API requests to perform at once.\n *\n * @return {Promise} Promise that resolves to a list of objects containing\n * either `output` (if that request was successful) or `error`\n * (if not ).\n */\nexport default async function defaultProcessor( requests ) {\n\tif ( maxItems === null ) {\n\t\tconst preflightResponse = await apiFetch( {\n\t\t\tpath: '/batch/v1',\n\t\t\tmethod: 'OPTIONS',\n\t\t} );\n\t\tmaxItems = preflightResponse.endpoints[ 0 ].args.requests.maxItems;\n\t}\n\n\tconst results = [];\n\n\tfor ( const batchRequests of chunk( requests, maxItems ) ) {\n\t\tconst batchResponse = await apiFetch( {\n\t\t\tpath: '/batch/v1',\n\t\t\tmethod: 'POST',\n\t\t\tdata: {\n\t\t\t\tvalidation: 'require-all-validate',\n\t\t\t\trequests: batchRequests.map( ( request ) => ( {\n\t\t\t\t\tpath: request.path,\n\t\t\t\t\tbody: request.data, // Rename 'data' to 'body'.\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\theaders: request.headers,\n\t\t\t\t} ) ),\n\t\t\t},\n\t\t} );\n\n\t\tlet batchResults;\n\n\t\tif ( batchResponse.failed ) {\n\t\t\tbatchResults = batchResponse.responses.map( ( response ) => ( {\n\t\t\t\terror: response?.body,\n\t\t\t} ) );\n\t\t} else {\n\t\t\tbatchResults = batchResponse.responses.map( ( response ) => {\n\t\t\t\tconst result = {};\n\t\t\t\tif ( response.status >= 200 && response.status < 300 ) {\n\t\t\t\t\tresult.output = response.body;\n\t\t\t\t} else {\n\t\t\t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AAS,UAAU,OAAO,SAAS,SAAS,KAAM;AACtD,iBAAO,SAAS,SAAS;AAAA,QAC1B,OAAO;AACN,iBAAO,QAAQ,SAAS;AAAA,QACzB;AACA,eAAO;AAAA,MACR,CAAE;AAAA,IACH;AAEA,YAAQ,KAAM,GAAG,YAAa;AAAA,EAC/B;AAEA,SAAO;AACR;",
6
6
  "names": ["apiFetch"]
7
7
  }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/core-data/src/components/entities-saved-states/entity-record-item.js
21
+ var entity_record_item_exports = {};
22
+ __export(entity_record_item_exports, {
23
+ default: () => EntityRecordItem
24
+ });
25
+ module.exports = __toCommonJS(entity_record_item_exports);
26
+ var import_components = require("@wordpress/components");
27
+ var import_i18n = require("@wordpress/i18n");
28
+ var import_data = require("@wordpress/data");
29
+ var import_html_entities = require("@wordpress/html-entities");
30
+ var import_name = require("../../name.cjs");
31
+ var import_get_template_info = require("../../utils/get-template-info.cjs");
32
+ var import_jsx_runtime = require("react/jsx-runtime");
33
+ function EntityRecordItem({ record, checked, onChange }) {
34
+ const { name, kind, title, key } = record;
35
+ const { entityRecordTitle } = (0, import_data.useSelect)(
36
+ (select) => {
37
+ if ("postType" !== kind || "wp_template" !== name) {
38
+ return {
39
+ entityRecordTitle: title
40
+ };
41
+ }
42
+ const template = select(import_name.STORE_NAME).getEditedEntityRecord(
43
+ kind,
44
+ name,
45
+ key
46
+ );
47
+ const { default_template_types: templateTypes = [] } = select(import_name.STORE_NAME).getCurrentTheme() ?? {};
48
+ return {
49
+ entityRecordTitle: (0, import_get_template_info.getTemplateInfo)({
50
+ template,
51
+ templateTypes
52
+ }).title
53
+ };
54
+ },
55
+ [name, kind, title, key]
56
+ );
57
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.PanelRow, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
58
+ import_components.CheckboxControl,
59
+ {
60
+ label: (0, import_html_entities.decodeEntities)(entityRecordTitle) || (0, import_i18n.__)("Untitled"),
61
+ checked,
62
+ onChange,
63
+ className: "entities-saved-states__change-control"
64
+ }
65
+ ) }) });
66
+ }
67
+ //# sourceMappingURL=entity-record-item.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/entities-saved-states/entity-record-item.js"],
4
+ "sourcesContent": ["import { CheckboxControl, PanelRow } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { STORE_NAME } from '../../name';\nimport { getTemplateInfo } from '../../utils/get-template-info';\n\nexport default function EntityRecordItem( { record, checked, onChange } ) {\n\tconst { name, kind, title, key } = record;\n\n\t// Handle templates that might use default descriptive titles.\n\tconst { entityRecordTitle } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( 'postType' !== kind || 'wp_template' !== name ) {\n\t\t\t\treturn {\n\t\t\t\t\tentityRecordTitle: title,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst template = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tkey\n\t\t\t);\n\n\t\t\tconst { default_template_types: templateTypes = [] } =\n\t\t\t\tselect( STORE_NAME ).getCurrentTheme() ?? {};\n\n\t\t\treturn {\n\t\t\t\tentityRecordTitle: getTemplateInfo( {\n\t\t\t\t\ttemplate,\n\t\t\t\t\ttemplateTypes,\n\t\t\t\t} ).title,\n\t\t\t};\n\t\t},\n\t\t[ name, kind, title, key ]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<PanelRow>\n\t\t\t\t<CheckboxControl\n\t\t\t\t\tlabel={\n\t\t\t\t\t\tdecodeEntities( entityRecordTitle ) || __( 'Untitled' )\n\t\t\t\t\t}\n\t\t\t\t\tchecked={ checked }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tclassName=\"entities-saved-states__change-control\"\n\t\t\t\t/>\n\t\t\t</PanelRow>\n\t\t</>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0C;AAC1C,kBAAmB;AACnB,kBAA0B;AAC1B,2BAA+B;AAC/B,kBAA2B;AAC3B,+BAAgC;AAkC9B;AAhCa,SAAR,iBAAmC,EAAE,QAAQ,SAAS,SAAS,GAAI;AACzE,QAAM,EAAE,MAAM,MAAM,OAAO,IAAI,IAAI;AAGnC,QAAM,EAAE,kBAAkB,QAAI;AAAA,IAC7B,CAAE,WAAY;AACb,UAAK,eAAe,QAAQ,kBAAkB,MAAO;AACpD,eAAO;AAAA,UACN,mBAAmB;AAAA,QACpB;AAAA,MACD;AAEA,YAAM,WAAW,OAAQ,sBAAW,EAAE;AAAA,QACrC;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAEA,YAAM,EAAE,wBAAwB,gBAAgB,CAAC,EAAE,IAClD,OAAQ,sBAAW,EAAE,gBAAgB,KAAK,CAAC;AAE5C,aAAO;AAAA,QACN,uBAAmB,0CAAiB;AAAA,UACnC;AAAA,UACA;AAAA,QACD,CAAE,EAAE;AAAA,MACL;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,OAAO,GAAI;AAAA,EAC1B;AAEA,SACC,2EACC,sDAAC,8BACA;AAAA,IAAC;AAAA;AAAA,MACA,WACC,qCAAgB,iBAAkB,SAAK,gBAAI,UAAW;AAAA,MAEvD;AAAA,MACA;AAAA,MACA,WAAU;AAAA;AAAA,EACX,GACD,GACD;AAEF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/core-data/src/components/entities-saved-states/entity-type-list.js
31
+ var entity_type_list_exports = {};
32
+ __export(entity_type_list_exports, {
33
+ default: () => EntityTypeList
34
+ });
35
+ module.exports = __toCommonJS(entity_type_list_exports);
36
+ var import_i18n = require("@wordpress/i18n");
37
+ var import_data = require("@wordpress/data");
38
+ var import_components = require("@wordpress/components");
39
+ var import_global_styles_engine = require("@wordpress/global-styles-engine");
40
+ var import_entity_record_item = __toESM(require("./entity-record-item.cjs"));
41
+ var import_name = require("../../name.cjs");
42
+ var import_jsx_runtime = require("react/jsx-runtime");
43
+ function getEntityDescription(entity, count) {
44
+ switch (entity) {
45
+ case "site":
46
+ return 1 === count ? (0, import_i18n.__)("This change will affect your whole site.") : (0, import_i18n.__)("These changes will affect your whole site.");
47
+ case "wp_template":
48
+ return (0, import_i18n.__)(
49
+ "This change will affect other parts of your site that use this template."
50
+ );
51
+ case "page":
52
+ case "post":
53
+ return (0, import_i18n.__)("The following has been modified.");
54
+ }
55
+ }
56
+ function GlobalStylesDescription({ record }) {
57
+ const { editedRecord, savedRecord } = (0, import_data.useSelect)(
58
+ (select) => {
59
+ const { getEditedEntityRecord, getEntityRecord } = select(import_name.STORE_NAME);
60
+ return {
61
+ editedRecord: getEditedEntityRecord(
62
+ record.kind,
63
+ record.name,
64
+ record.key
65
+ ),
66
+ savedRecord: getEntityRecord(
67
+ record.kind,
68
+ record.name,
69
+ record.key
70
+ )
71
+ };
72
+ },
73
+ [record.kind, record.name, record.key]
74
+ );
75
+ const globalStylesChanges = (0, import_global_styles_engine.getGlobalStylesChanges)(
76
+ editedRecord,
77
+ savedRecord,
78
+ {
79
+ maxResults: 10
80
+ }
81
+ );
82
+ return globalStylesChanges.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "entities-saved-states__changes", children: globalStylesChanges.map((change) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: change }, change)) }) : null;
83
+ }
84
+ function EntityDescription({ record, count }) {
85
+ if ("globalStyles" === record?.name) {
86
+ return null;
87
+ }
88
+ const description = getEntityDescription(record?.name, count);
89
+ return description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.PanelRow, { children: description }) : null;
90
+ }
91
+ function EntityTypeList({
92
+ list,
93
+ unselectedEntities,
94
+ setUnselectedEntities
95
+ }) {
96
+ const count = list.length;
97
+ const firstRecord = list[0];
98
+ const entityConfig = (0, import_data.useSelect)(
99
+ (select) => select(import_name.STORE_NAME).getEntityConfig(
100
+ firstRecord.kind,
101
+ firstRecord.name
102
+ ),
103
+ [firstRecord.kind, firstRecord.name]
104
+ );
105
+ let entityLabel = entityConfig.label;
106
+ if (firstRecord?.name === "wp_template_part") {
107
+ entityLabel = 1 === count ? (0, import_i18n.__)("Template Part") : (0, import_i18n.__)("Template Parts");
108
+ }
109
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
110
+ import_components.PanelBody,
111
+ {
112
+ title: entityLabel,
113
+ initialOpen: true,
114
+ className: "entities-saved-states__panel-body",
115
+ children: [
116
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EntityDescription, { record: firstRecord, count }),
117
+ list.map((record) => {
118
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
119
+ import_entity_record_item.default,
120
+ {
121
+ record,
122
+ checked: !unselectedEntities.some(
123
+ (elt) => elt.kind === record.kind && elt.name === record.name && elt.key === record.key && elt.property === record.property
124
+ ),
125
+ onChange: (value) => setUnselectedEntities(record, value)
126
+ },
127
+ record.key || record.property
128
+ );
129
+ }),
130
+ "globalStyles" === firstRecord?.name && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GlobalStylesDescription, { record: firstRecord })
131
+ ]
132
+ }
133
+ );
134
+ }
135
+ //# sourceMappingURL=entity-type-list.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/entities-saved-states/entity-type-list.js"],
4
+ "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useSelect } from '@wordpress/data';\nimport { PanelBody, PanelRow } from '@wordpress/components';\nimport { getGlobalStylesChanges } from '@wordpress/global-styles-engine';\nimport EntityRecordItem from './entity-record-item';\nimport { STORE_NAME } from '../../name';\n\nfunction getEntityDescription( entity, count ) {\n\tswitch ( entity ) {\n\t\tcase 'site':\n\t\t\treturn 1 === count\n\t\t\t\t? __( 'This change will affect your whole site.' )\n\t\t\t\t: __( 'These changes will affect your whole site.' );\n\t\tcase 'wp_template':\n\t\t\treturn __(\n\t\t\t\t'This change will affect other parts of your site that use this template.'\n\t\t\t);\n\t\tcase 'page':\n\t\tcase 'post':\n\t\t\treturn __( 'The following has been modified.' );\n\t}\n}\n\nfunction GlobalStylesDescription( { record } ) {\n\tconst { editedRecord, savedRecord } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord, getEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\treturn {\n\t\t\t\teditedRecord: getEditedEntityRecord(\n\t\t\t\t\trecord.kind,\n\t\t\t\t\trecord.name,\n\t\t\t\t\trecord.key\n\t\t\t\t),\n\t\t\t\tsavedRecord: getEntityRecord(\n\t\t\t\t\trecord.kind,\n\t\t\t\t\trecord.name,\n\t\t\t\t\trecord.key\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ record.kind, record.name, record.key ]\n\t);\n\n\tconst globalStylesChanges = getGlobalStylesChanges(\n\t\teditedRecord,\n\t\tsavedRecord,\n\t\t{\n\t\t\tmaxResults: 10,\n\t\t}\n\t);\n\treturn globalStylesChanges.length ? (\n\t\t<ul className=\"entities-saved-states__changes\">\n\t\t\t{ globalStylesChanges.map( ( change ) => (\n\t\t\t\t<li key={ change }>{ change }</li>\n\t\t\t) ) }\n\t\t</ul>\n\t) : null;\n}\n\nfunction EntityDescription( { record, count } ) {\n\tif ( 'globalStyles' === record?.name ) {\n\t\treturn null;\n\t}\n\tconst description = getEntityDescription( record?.name, count );\n\treturn description ? <PanelRow>{ description }</PanelRow> : null;\n}\n\nexport default function EntityTypeList( {\n\tlist,\n\tunselectedEntities,\n\tsetUnselectedEntities,\n} ) {\n\tconst count = list.length;\n\tconst firstRecord = list[ 0 ];\n\tconst entityConfig = useSelect(\n\t\t( select ) =>\n\t\t\tselect( STORE_NAME ).getEntityConfig(\n\t\t\t\tfirstRecord.kind,\n\t\t\t\tfirstRecord.name\n\t\t\t),\n\t\t[ firstRecord.kind, firstRecord.name ]\n\t);\n\n\tlet entityLabel = entityConfig.label;\n\tif ( firstRecord?.name === 'wp_template_part' ) {\n\t\tentityLabel =\n\t\t\t1 === count ? __( 'Template Part' ) : __( 'Template Parts' );\n\t}\n\n\treturn (\n\t\t<PanelBody\n\t\t\ttitle={ entityLabel }\n\t\t\tinitialOpen\n\t\t\tclassName=\"entities-saved-states__panel-body\"\n\t\t>\n\t\t\t<EntityDescription record={ firstRecord } count={ count } />\n\t\t\t{ list.map( ( record ) => {\n\t\t\t\treturn (\n\t\t\t\t\t<EntityRecordItem\n\t\t\t\t\t\tkey={ record.key || record.property }\n\t\t\t\t\t\trecord={ record }\n\t\t\t\t\t\tchecked={\n\t\t\t\t\t\t\t! unselectedEntities.some(\n\t\t\t\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\t\t\t\telt.kind === record.kind &&\n\t\t\t\t\t\t\t\t\telt.name === record.name &&\n\t\t\t\t\t\t\t\t\telt.key === record.key &&\n\t\t\t\t\t\t\t\t\telt.property === record.property\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tonChange={ ( value ) =>\n\t\t\t\t\t\t\tsetUnselectedEntities( record, value )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t} ) }\n\t\t\t{ 'globalStyles' === firstRecord?.name && (\n\t\t\t\t<GlobalStylesDescription record={ firstRecord } />\n\t\t\t) }\n\t\t</PanelBody>\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AACnB,kBAA0B;AAC1B,wBAAoC;AACpC,kCAAuC;AACvC,gCAA6B;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Ac,KAAM,CAAE;AAC5B,QAAM,mBAAe;AAAA,IACpB,CAAE,WACD,OAAQ,sBAAW,EAAE;AAAA,MACpB,YAAY;AAAA,MACZ,YAAY;AAAA,IACb;AAAA,IACD,CAAE,YAAY,MAAM,YAAY,IAAK;AAAA,EACtC;AAEA,MAAI,cAAc,aAAa;AAC/B,MAAK,aAAa,SAAS,oBAAqB;AAC/C,kBACC,MAAM,YAAQ,gBAAI,eAAgB,QAAI,gBAAI,gBAAiB;AAAA,EAC7D;AAEA,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAQ;AAAA,MACR,aAAW;AAAA,MACX,WAAU;AAAA,MAEV;AAAA,oDAAC,qBAAkB,QAAS,aAAc,OAAgB;AAAA,QACxD,KAAK,IAAK,CAAE,WAAY;AACzB,iBACC;AAAA,YAAC,0BAAAA;AAAA,YAAA;AAAA,cAEA;AAAA,cACA,SACC,CAAE,mBAAmB;AAAA,gBACpB,CAAE,QACD,IAAI,SAAS,OAAO,QACpB,IAAI,SAAS,OAAO,QACpB,IAAI,QAAQ,OAAO,OACnB,IAAI,aAAa,OAAO;AAAA,cAC1B;AAAA,cAED,UAAW,CAAE,UACZ,sBAAuB,QAAQ,KAAM;AAAA;AAAA,YAZhC,OAAO,OAAO,OAAO;AAAA,UAc5B;AAAA,QAEF,CAAE;AAAA,QACA,mBAAmB,aAAa,QACjC,4CAAC,2BAAwB,QAAS,aAAc;AAAA;AAAA;AAAA,EAElD;AAEF;",
6
+ "names": ["EntityRecordItem"]
7
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/core-data/src/components/entities-saved-states/hooks/use-is-dirty.js
21
+ var use_is_dirty_exports = {};
22
+ __export(use_is_dirty_exports, {
23
+ useIsDirty: () => useIsDirty
24
+ });
25
+ module.exports = __toCommonJS(use_is_dirty_exports);
26
+ var import_data = require("@wordpress/data");
27
+ var import_element = require("@wordpress/element");
28
+ var import_name = require("../../../name.cjs");
29
+ var useIsDirty = () => {
30
+ const { editedEntities, siteEdits, siteEntityConfig } = (0, import_data.useSelect)(
31
+ (select) => {
32
+ const {
33
+ __experimentalGetDirtyEntityRecords,
34
+ getEntityRecordEdits,
35
+ getEntityConfig
36
+ } = select(import_name.STORE_NAME);
37
+ return {
38
+ editedEntities: __experimentalGetDirtyEntityRecords(),
39
+ siteEdits: getEntityRecordEdits("root", "site"),
40
+ siteEntityConfig: getEntityConfig("root", "site")
41
+ };
42
+ },
43
+ []
44
+ );
45
+ const dirtyEntityRecords = (0, import_element.useMemo)(() => {
46
+ const editedEntitiesWithoutSite = editedEntities.filter(
47
+ (record) => !(record.kind === "root" && record.name === "site")
48
+ );
49
+ const siteEntityLabels = siteEntityConfig?.meta?.labels ?? {};
50
+ const {
51
+ title: siteTitleEdit,
52
+ description: siteDescriptionEdit,
53
+ site_logo: siteLogoEdit,
54
+ site_icon: siteIconEdit,
55
+ ...otherSiteEdits
56
+ } = siteEdits ?? {};
57
+ const orderedSiteProperties = [
58
+ siteTitleEdit !== void 0 && "title",
59
+ siteDescriptionEdit !== void 0 && "description",
60
+ siteLogoEdit !== void 0 && "site_logo",
61
+ siteIconEdit !== void 0 && "site_icon",
62
+ ...Object.keys(otherSiteEdits)
63
+ ].filter(Boolean);
64
+ const editedSiteEntities = orderedSiteProperties.map(
65
+ (property) => ({
66
+ kind: "root",
67
+ name: "site",
68
+ title: siteEntityLabels[property] || property,
69
+ property
70
+ })
71
+ );
72
+ return [...editedEntitiesWithoutSite, ...editedSiteEntities];
73
+ }, [editedEntities, siteEdits, siteEntityConfig]);
74
+ const [unselectedEntities, _setUnselectedEntities] = (0, import_element.useState)([]);
75
+ const setUnselectedEntities = ({ kind, name, key, property }, checked) => {
76
+ if (checked) {
77
+ _setUnselectedEntities(
78
+ unselectedEntities.filter(
79
+ (elt) => elt.kind !== kind || elt.name !== name || elt.key !== key || elt.property !== property
80
+ )
81
+ );
82
+ } else {
83
+ _setUnselectedEntities([
84
+ ...unselectedEntities,
85
+ { kind, name, key, property }
86
+ ]);
87
+ }
88
+ };
89
+ const isDirty = dirtyEntityRecords.length - unselectedEntities.length > 0;
90
+ return {
91
+ dirtyEntityRecords,
92
+ isDirty,
93
+ setUnselectedEntities,
94
+ unselectedEntities
95
+ };
96
+ };
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ useIsDirty
100
+ });
101
+ //# sourceMappingURL=use-is-dirty.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/components/entities-saved-states/hooks/use-is-dirty.js"],
4
+ "sourcesContent": ["import { useSelect } from '@wordpress/data';\nimport { useMemo, useState } from '@wordpress/element';\nimport { STORE_NAME } from '../../../name';\n\n/**\n * Custom hook that determines if any entities are dirty (edited) and provides a way to manage selected/unselected entities.\n *\n * @return {Object} An object containing the following properties:\n * - dirtyEntityRecords: An array of dirty entity records.\n * - isDirty: A boolean indicating if there are any dirty entity records.\n * - setUnselectedEntities: A function to set the unselected entities.\n * - unselectedEntities: An array of unselected entities.\n */\nexport const useIsDirty = () => {\n\tconst { editedEntities, siteEdits, siteEntityConfig } = useSelect(\n\t\t( select ) => {\n\t\t\tconst {\n\t\t\t\t__experimentalGetDirtyEntityRecords,\n\t\t\t\tgetEntityRecordEdits,\n\t\t\t\tgetEntityConfig,\n\t\t\t} = select( STORE_NAME );\n\n\t\t\treturn {\n\t\t\t\teditedEntities: __experimentalGetDirtyEntityRecords(),\n\t\t\t\tsiteEdits: getEntityRecordEdits( 'root', 'site' ),\n\t\t\t\tsiteEntityConfig: getEntityConfig( 'root', 'site' ),\n\t\t\t};\n\t\t},\n\t\t[]\n\t);\n\n\tconst dirtyEntityRecords = useMemo( () => {\n\t\t// Remove site object and decouple into its edited pieces.\n\t\tconst editedEntitiesWithoutSite = editedEntities.filter(\n\t\t\t( record ) => ! ( record.kind === 'root' && record.name === 'site' )\n\t\t);\n\n\t\tconst siteEntityLabels = siteEntityConfig?.meta?.labels ?? {};\n\t\tconst {\n\t\t\ttitle: siteTitleEdit,\n\t\t\tdescription: siteDescriptionEdit,\n\t\t\tsite_logo: siteLogoEdit,\n\t\t\tsite_icon: siteIconEdit,\n\t\t\t...otherSiteEdits\n\t\t} = siteEdits ?? {};\n\t\tconst orderedSiteProperties = [\n\t\t\tsiteTitleEdit !== undefined && 'title',\n\t\t\tsiteDescriptionEdit !== undefined && 'description',\n\t\t\tsiteLogoEdit !== undefined && 'site_logo',\n\t\t\tsiteIconEdit !== undefined && 'site_icon',\n\t\t\t...Object.keys( otherSiteEdits ),\n\t\t].filter( Boolean );\n\t\tconst editedSiteEntities = orderedSiteProperties.map(\n\t\t\t( property ) => ( {\n\t\t\t\tkind: 'root',\n\t\t\t\tname: 'site',\n\t\t\t\ttitle: siteEntityLabels[ property ] || property,\n\t\t\t\tproperty,\n\t\t\t} )\n\t\t);\n\n\t\treturn [ ...editedEntitiesWithoutSite, ...editedSiteEntities ];\n\t}, [ editedEntities, siteEdits, siteEntityConfig ] );\n\n\t// Unchecked entities to be ignored by save function.\n\tconst [ unselectedEntities, _setUnselectedEntities ] = useState( [] );\n\n\tconst setUnselectedEntities = (\n\t\t{ kind, name, key, property },\n\t\tchecked\n\t) => {\n\t\tif ( checked ) {\n\t\t\t_setUnselectedEntities(\n\t\t\t\tunselectedEntities.filter(\n\t\t\t\t\t( elt ) =>\n\t\t\t\t\t\telt.kind !== kind ||\n\t\t\t\t\t\telt.name !== name ||\n\t\t\t\t\t\telt.key !== key ||\n\t\t\t\t\t\telt.property !== property\n\t\t\t\t)\n\t\t\t);\n\t\t} else {\n\t\t\t_setUnselectedEntities( [\n\t\t\t\t...unselectedEntities,\n\t\t\t\t{ kind, name, key, property },\n\t\t\t] );\n\t\t}\n\t};\n\n\tconst isDirty = dirtyEntityRecords.length - unselectedEntities.length > 0;\n\n\treturn {\n\t\tdirtyEntityRecords,\n\t\tisDirty,\n\t\tsetUnselectedEntities,\n\t\tunselectedEntities,\n\t};\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAC1B,qBAAkC;AAClC,kBAA2B;AAWpB,IAAM,aAAa,MAAM;AAC/B,QAAM,EAAE,gBAAgB,WAAW,iBAAiB,QAAI;AAAA,IACvD,CAAE,WAAY;AACb,YAAM;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD,IAAI,OAAQ,sBAAW;AAEvB,aAAO;AAAA,QACN,gBAAgB,oCAAoC;AAAA,QACpD,WAAW,qBAAsB,QAAQ,MAAO;AAAA,QAChD,kBAAkB,gBAAiB,QAAQ,MAAO;AAAA,MACnD;AAAA,IACD;AAAA,IACA,CAAC;AAAA,EACF;AAEA,QAAM,yBAAqB,wBAAS,MAAM;AAEzC,UAAM,4BAA4B,eAAe;AAAA,MAChD,CAAE,WAAY,EAAI,OAAO,SAAS,UAAU,OAAO,SAAS;AAAA,IAC7D;AAEA,UAAM,mBAAmB,kBAAkB,MAAM,UAAU,CAAC;AAC5D,UAAM;AAAA,MACL,OAAO;AAAA,MACP,aAAa;AAAA,MACb,WAAW;AAAA,MACX,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,IAAI,aAAa,CAAC;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