@wordpress/core-data 7.32.0 → 7.32.1-next.ff1cebbba.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 (383) hide show
  1. package/build/actions.js +375 -632
  2. package/build/actions.js.map +7 -1
  3. package/build/batch/create-batch.js +49 -62
  4. package/build/batch/create-batch.js.map +7 -1
  5. package/build/batch/default-processor.js +43 -39
  6. package/build/batch/default-processor.js.map +7 -1
  7. package/build/batch/index.js +38 -17
  8. package/build/batch/index.js.map +7 -1
  9. package/build/dynamic-entities.js +30 -32
  10. package/build/dynamic-entities.js.map +7 -1
  11. package/build/entities.js +298 -410
  12. package/build/entities.js.map +7 -1
  13. package/build/entity-context.js +29 -12
  14. package/build/entity-context.js.map +7 -1
  15. package/build/entity-provider.js +38 -46
  16. package/build/entity-provider.js.map +7 -1
  17. package/build/entity-types/attachment.js +16 -5
  18. package/build/entity-types/attachment.js.map +7 -1
  19. package/build/entity-types/base-entity-records.js +16 -42
  20. package/build/entity-types/base-entity-records.js.map +7 -1
  21. package/build/entity-types/base.js +16 -5
  22. package/build/entity-types/base.js.map +7 -1
  23. package/build/entity-types/comment.js +16 -5
  24. package/build/entity-types/comment.js.map +7 -1
  25. package/build/entity-types/global-styles-revision.js +16 -5
  26. package/build/entity-types/global-styles-revision.js.map +7 -1
  27. package/build/entity-types/helpers.js +16 -5
  28. package/build/entity-types/helpers.js.map +7 -1
  29. package/build/entity-types/index.js +16 -5
  30. package/build/entity-types/index.js.map +7 -1
  31. package/build/entity-types/menu-location.js +16 -5
  32. package/build/entity-types/menu-location.js.map +7 -1
  33. package/build/entity-types/nav-menu-item.js +16 -5
  34. package/build/entity-types/nav-menu-item.js.map +7 -1
  35. package/build/entity-types/nav-menu.js +16 -5
  36. package/build/entity-types/nav-menu.js.map +7 -1
  37. package/build/entity-types/page.js +16 -5
  38. package/build/entity-types/page.js.map +7 -1
  39. package/build/entity-types/plugin.js +16 -5
  40. package/build/entity-types/plugin.js.map +7 -1
  41. package/build/entity-types/post-revision.js +16 -5
  42. package/build/entity-types/post-revision.js.map +7 -1
  43. package/build/entity-types/post-status.js +16 -5
  44. package/build/entity-types/post-status.js.map +7 -1
  45. package/build/entity-types/post.js +16 -5
  46. package/build/entity-types/post.js.map +7 -1
  47. package/build/entity-types/settings.js +16 -5
  48. package/build/entity-types/settings.js.map +7 -1
  49. package/build/entity-types/sidebar.js +16 -5
  50. package/build/entity-types/sidebar.js.map +7 -1
  51. package/build/entity-types/taxonomy.js +16 -5
  52. package/build/entity-types/taxonomy.js.map +7 -1
  53. package/build/entity-types/term.js +16 -5
  54. package/build/entity-types/term.js.map +7 -1
  55. package/build/entity-types/theme.js +16 -5
  56. package/build/entity-types/theme.js.map +7 -1
  57. package/build/entity-types/type.js +16 -5
  58. package/build/entity-types/type.js.map +7 -1
  59. package/build/entity-types/user.js +16 -5
  60. package/build/entity-types/user.js.map +7 -1
  61. package/build/entity-types/widget-type.js +16 -5
  62. package/build/entity-types/widget-type.js.map +7 -1
  63. package/build/entity-types/widget.js +16 -5
  64. package/build/entity-types/widget.js.map +7 -1
  65. package/build/entity-types/wp-template-part.js +16 -5
  66. package/build/entity-types/wp-template-part.js.map +7 -1
  67. package/build/entity-types/wp-template.js +16 -5
  68. package/build/entity-types/wp-template.js.map +7 -1
  69. package/build/fetch/__experimental-fetch-link-suggestions.js +141 -154
  70. package/build/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
  71. package/build/fetch/__experimental-fetch-url-data.js +47 -59
  72. package/build/fetch/__experimental-fetch-url-data.js.map +7 -1
  73. package/build/fetch/index.js +53 -32
  74. package/build/fetch/index.js.map +7 -1
  75. package/build/footnotes/get-footnotes-order.js +38 -25
  76. package/build/footnotes/get-footnotes-order.js.map +7 -1
  77. package/build/footnotes/get-rich-text-values-cached.js +26 -27
  78. package/build/footnotes/get-rich-text-values-cached.js.map +7 -1
  79. package/build/footnotes/index.js +68 -55
  80. package/build/footnotes/index.js.map +7 -1
  81. package/build/hooks/constants.js +33 -12
  82. package/build/hooks/constants.js.map +7 -1
  83. package/build/hooks/index.js +59 -68
  84. package/build/hooks/index.js.map +7 -1
  85. package/build/hooks/memoize.js +34 -12
  86. package/build/hooks/memoize.js.map +7 -1
  87. package/build/hooks/use-entity-block-editor.js +111 -119
  88. package/build/hooks/use-entity-block-editor.js.map +7 -1
  89. package/build/hooks/use-entity-id.js +25 -23
  90. package/build/hooks/use-entity-id.js.map +7 -1
  91. package/build/hooks/use-entity-prop.js +59 -60
  92. package/build/hooks/use-entity-prop.js.map +7 -1
  93. package/build/hooks/use-entity-record.js +95 -155
  94. package/build/hooks/use-entity-record.js.map +7 -1
  95. package/build/hooks/use-entity-records.js +131 -139
  96. package/build/hooks/use-entity-records.js.map +7 -1
  97. package/build/hooks/use-query-select.js +65 -84
  98. package/build/hooks/use-query-select.js.map +7 -1
  99. package/build/hooks/use-resource-permissions.js +92 -145
  100. package/build/hooks/use-resource-permissions.js.map +7 -1
  101. package/build/index.js +96 -153
  102. package/build/index.js.map +7 -1
  103. package/build/lock-unlock.js +31 -14
  104. package/build/lock-unlock.js.map +7 -1
  105. package/build/locks/actions.js +36 -19
  106. package/build/locks/actions.js.map +7 -1
  107. package/build/locks/engine.js +48 -47
  108. package/build/locks/engine.js.map +7 -1
  109. package/build/locks/reducer.js +54 -63
  110. package/build/locks/reducer.js.map +7 -1
  111. package/build/locks/selectors.js +35 -30
  112. package/build/locks/selectors.js.map +7 -1
  113. package/build/locks/utils.js +37 -16
  114. package/build/locks/utils.js.map +7 -1
  115. package/build/name.js +27 -12
  116. package/build/name.js.map +7 -1
  117. package/build/private-actions.js +67 -75
  118. package/build/private-actions.js.map +7 -1
  119. package/build/private-apis.js +33 -16
  120. package/build/private-apis.js.map +7 -1
  121. package/build/private-selectors.js +204 -184
  122. package/build/private-selectors.js.map +7 -1
  123. package/build/queried-data/actions.js +32 -41
  124. package/build/queried-data/actions.js.map +7 -1
  125. package/build/queried-data/get-query-parts.js +41 -79
  126. package/build/queried-data/get-query-parts.js.map +7 -1
  127. package/build/queried-data/index.js +39 -36
  128. package/build/queried-data/index.js.map +7 -1
  129. package/build/queried-data/reducer.js +162 -193
  130. package/build/queried-data/reducer.js.map +7 -1
  131. package/build/queried-data/selectors.js +57 -85
  132. package/build/queried-data/selectors.js.map +7 -1
  133. package/build/reducer.js +279 -404
  134. package/build/reducer.js.map +7 -1
  135. package/build/resolvers.js +553 -600
  136. package/build/resolvers.js.map +7 -1
  137. package/build/selectors.js +456 -981
  138. package/build/selectors.js.map +7 -1
  139. package/build/sync.js +34 -22
  140. package/build/sync.js.map +7 -1
  141. package/build/types.js +16 -5
  142. package/build/types.js.map +7 -1
  143. package/build/utils/conservative-map-item.js +34 -27
  144. package/build/utils/conservative-map-item.js.map +7 -1
  145. package/build/utils/crdt-blocks.js +289 -0
  146. package/build/utils/crdt-blocks.js.map +7 -0
  147. package/build/utils/crdt.js +202 -0
  148. package/build/utils/crdt.js.map +7 -0
  149. package/build/utils/forward-resolver.js +24 -16
  150. package/build/utils/forward-resolver.js.map +7 -1
  151. package/build/utils/get-nested-value.js +26 -21
  152. package/build/utils/get-nested-value.js.map +7 -1
  153. package/build/utils/get-normalized-comma-separable.js +25 -17
  154. package/build/utils/get-normalized-comma-separable.js.map +7 -1
  155. package/build/utils/if-matching-action.js +25 -19
  156. package/build/utils/if-matching-action.js.map +7 -1
  157. package/build/utils/index.js +77 -108
  158. package/build/utils/index.js.map +7 -1
  159. package/build/utils/is-numeric-id.js +22 -12
  160. package/build/utils/is-numeric-id.js.map +7 -1
  161. package/build/utils/is-raw-attribute.js +22 -13
  162. package/build/utils/is-raw-attribute.js.map +7 -1
  163. package/build/utils/log-entity-deprecation.js +37 -38
  164. package/build/utils/log-entity-deprecation.js.map +7 -1
  165. package/build/utils/on-sub-key.js +30 -24
  166. package/build/utils/on-sub-key.js.map +7 -1
  167. package/build/utils/receive-intermediate-results.js +29 -6
  168. package/build/utils/receive-intermediate-results.js.map +7 -1
  169. package/build/utils/replace-action.js +24 -17
  170. package/build/utils/replace-action.js.map +7 -1
  171. package/build/utils/set-nested-value.js +25 -30
  172. package/build/utils/set-nested-value.js.map +7 -1
  173. package/build/utils/user-permissions.js +41 -13
  174. package/build/utils/user-permissions.js.map +7 -1
  175. package/build/utils/with-weak-map-cache.js +26 -22
  176. package/build/utils/with-weak-map-cache.js.map +7 -1
  177. package/build-module/actions.js +322 -601
  178. package/build-module/actions.js.map +7 -1
  179. package/build-module/batch/create-batch.js +21 -57
  180. package/build-module/batch/create-batch.js.map +7 -1
  181. package/build-module/batch/default-processor.js +14 -33
  182. package/build-module/batch/default-processor.js.map +7 -1
  183. package/build-module/batch/index.js +7 -3
  184. package/build-module/batch/index.js.map +7 -1
  185. package/build-module/dynamic-entities.js +7 -28
  186. package/build-module/dynamic-entities.js.map +7 -1
  187. package/build-module/entities.js +263 -399
  188. package/build-module/entities.js.map +7 -1
  189. package/build-module/entity-context.js +7 -7
  190. package/build-module/entity-context.js.map +7 -1
  191. package/build-module/entity-provider.js +19 -42
  192. package/build-module/entity-provider.js.map +7 -1
  193. package/build-module/entity-types/attachment.js +1 -2
  194. package/build-module/entity-types/attachment.js.map +7 -1
  195. package/build-module/entity-types/base-entity-records.js +1 -37
  196. package/build-module/entity-types/base-entity-records.js.map +7 -1
  197. package/build-module/entity-types/base.js +1 -2
  198. package/build-module/entity-types/base.js.map +7 -1
  199. package/build-module/entity-types/comment.js +1 -2
  200. package/build-module/entity-types/comment.js.map +7 -1
  201. package/build-module/entity-types/global-styles-revision.js +1 -2
  202. package/build-module/entity-types/global-styles-revision.js.map +7 -1
  203. package/build-module/entity-types/helpers.js +1 -2
  204. package/build-module/entity-types/helpers.js.map +7 -1
  205. package/build-module/entity-types/index.js +1 -2
  206. package/build-module/entity-types/index.js.map +7 -1
  207. package/build-module/entity-types/menu-location.js +1 -2
  208. package/build-module/entity-types/menu-location.js.map +7 -1
  209. package/build-module/entity-types/nav-menu-item.js +1 -2
  210. package/build-module/entity-types/nav-menu-item.js.map +7 -1
  211. package/build-module/entity-types/nav-menu.js +1 -2
  212. package/build-module/entity-types/nav-menu.js.map +7 -1
  213. package/build-module/entity-types/page.js +1 -2
  214. package/build-module/entity-types/page.js.map +7 -1
  215. package/build-module/entity-types/plugin.js +1 -2
  216. package/build-module/entity-types/plugin.js.map +7 -1
  217. package/build-module/entity-types/post-revision.js +1 -2
  218. package/build-module/entity-types/post-revision.js.map +7 -1
  219. package/build-module/entity-types/post-status.js +1 -2
  220. package/build-module/entity-types/post-status.js.map +7 -1
  221. package/build-module/entity-types/post.js +1 -2
  222. package/build-module/entity-types/post.js.map +7 -1
  223. package/build-module/entity-types/settings.js +1 -2
  224. package/build-module/entity-types/settings.js.map +7 -1
  225. package/build-module/entity-types/sidebar.js +1 -2
  226. package/build-module/entity-types/sidebar.js.map +7 -1
  227. package/build-module/entity-types/taxonomy.js +1 -2
  228. package/build-module/entity-types/taxonomy.js.map +7 -1
  229. package/build-module/entity-types/term.js +1 -2
  230. package/build-module/entity-types/term.js.map +7 -1
  231. package/build-module/entity-types/theme.js +1 -2
  232. package/build-module/entity-types/theme.js.map +7 -1
  233. package/build-module/entity-types/type.js +1 -2
  234. package/build-module/entity-types/type.js.map +7 -1
  235. package/build-module/entity-types/user.js +1 -2
  236. package/build-module/entity-types/user.js.map +7 -1
  237. package/build-module/entity-types/widget-type.js +1 -2
  238. package/build-module/entity-types/widget-type.js.map +7 -1
  239. package/build-module/entity-types/widget.js +1 -2
  240. package/build-module/entity-types/widget.js.map +7 -1
  241. package/build-module/entity-types/wp-template-part.js +1 -2
  242. package/build-module/entity-types/wp-template-part.js.map +7 -1
  243. package/build-module/entity-types/wp-template.js +1 -2
  244. package/build-module/entity-types/wp-template.js.map +7 -1
  245. package/build-module/fetch/__experimental-fetch-link-suggestions.js +111 -149
  246. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
  247. package/build-module/fetch/__experimental-fetch-url-data.js +20 -49
  248. package/build-module/fetch/__experimental-fetch-url-data.js.map +7 -1
  249. package/build-module/fetch/index.js +20 -15
  250. package/build-module/fetch/index.js.map +7 -1
  251. package/build-module/footnotes/get-footnotes-order.js +10 -19
  252. package/build-module/footnotes/get-footnotes-order.js.map +7 -1
  253. package/build-module/footnotes/get-rich-text-values-cached.js +8 -23
  254. package/build-module/footnotes/get-rich-text-values-cached.js.map +7 -1
  255. package/build-module/footnotes/index.js +34 -47
  256. package/build-module/footnotes/index.js.map +7 -1
  257. package/build-module/hooks/constants.js +11 -8
  258. package/build-module/hooks/constants.js.map +7 -1
  259. package/build-module/hooks/index.js +27 -15
  260. package/build-module/hooks/index.js.map +7 -1
  261. package/build-module/hooks/memoize.js +6 -8
  262. package/build-module/hooks/memoize.js.map +7 -1
  263. package/build-module/hooks/use-entity-block-editor.js +80 -110
  264. package/build-module/hooks/use-entity-block-editor.js.map +7 -1
  265. package/build-module/hooks/use-entity-id.js +7 -19
  266. package/build-module/hooks/use-entity-id.js.map +7 -1
  267. package/build-module/hooks/use-entity-prop.js +31 -55
  268. package/build-module/hooks/use-entity-prop.js.map +7 -1
  269. package/build-module/hooks/use-entity-record.js +63 -148
  270. package/build-module/hooks/use-entity-record.js.map +7 -1
  271. package/build-module/hooks/use-entity-records.js +98 -131
  272. package/build-module/hooks/use-entity-records.js.map +7 -1
  273. package/build-module/hooks/use-query-select.js +27 -71
  274. package/build-module/hooks/use-query-select.js.map +7 -1
  275. package/build-module/hooks/use-resource-permissions.js +57 -136
  276. package/build-module/hooks/use-resource-permissions.js.map +7 -1
  277. package/build-module/index.js +49 -71
  278. package/build-module/index.js.map +7 -1
  279. package/build-module/lock-unlock.js +8 -7
  280. package/build-module/lock-unlock.js.map +7 -1
  281. package/build-module/locks/actions.js +8 -13
  282. package/build-module/locks/actions.js.map +7 -1
  283. package/build-module/locks/engine.js +17 -38
  284. package/build-module/locks/engine.js.map +7 -1
  285. package/build-module/locks/reducer.js +37 -59
  286. package/build-module/locks/reducer.js.map +7 -1
  287. package/build-module/locks/selectors.js +16 -23
  288. package/build-module/locks/selectors.js.map +7 -1
  289. package/build-module/locks/utils.js +15 -12
  290. package/build-module/locks/utils.js.map +7 -1
  291. package/build-module/name.js +5 -8
  292. package/build-module/name.js.map +7 -1
  293. package/build-module/private-actions.js +35 -69
  294. package/build-module/private-actions.js.map +7 -1
  295. package/build-module/private-apis.js +8 -8
  296. package/build-module/private-apis.js.map +7 -1
  297. package/build-module/private-selectors.js +167 -174
  298. package/build-module/private-selectors.js.map +7 -1
  299. package/build-module/queried-data/actions.js +11 -38
  300. package/build-module/queried-data/actions.js.map +7 -1
  301. package/build-module/queried-data/get-query-parts.js +20 -75
  302. package/build-module/queried-data/get-query-parts.js.map +7 -1
  303. package/build-module/queried-data/index.js +7 -4
  304. package/build-module/queried-data/index.js.map +7 -1
  305. package/build-module/queried-data/reducer.js +134 -185
  306. package/build-module/queried-data/reducer.js.map +7 -1
  307. package/build-module/queried-data/selectors.js +23 -78
  308. package/build-module/queried-data/selectors.js.map +7 -1
  309. package/build-module/reducer.js +243 -393
  310. package/build-module/reducer.js.map +7 -1
  311. package/build-module/resolvers.js +478 -549
  312. package/build-module/resolvers.js.map +7 -1
  313. package/build-module/selectors.js +410 -953
  314. package/build-module/selectors.js.map +7 -1
  315. package/build-module/sync.js +14 -17
  316. package/build-module/sync.js.map +7 -1
  317. package/build-module/types.js +1 -2
  318. package/build-module/types.js.map +7 -1
  319. package/build-module/utils/conservative-map-item.js +6 -22
  320. package/build-module/utils/conservative-map-item.js.map +7 -1
  321. package/build-module/utils/crdt-blocks.js +255 -0
  322. package/build-module/utils/crdt-blocks.js.map +7 -0
  323. package/build-module/utils/crdt.js +167 -0
  324. package/build-module/utils/crdt.js.map +7 -0
  325. package/build-module/utils/forward-resolver.js +6 -12
  326. package/build-module/utils/forward-resolver.js.map +7 -1
  327. package/build-module/utils/get-nested-value.js +9 -18
  328. package/build-module/utils/get-nested-value.js.map +7 -1
  329. package/build-module/utils/get-normalized-comma-separable.js +7 -13
  330. package/build-module/utils/get-normalized-comma-separable.js.map +7 -1
  331. package/build-module/utils/if-matching-action.js +7 -15
  332. package/build-module/utils/if-matching-action.js.map +7 -1
  333. package/build-module/utils/index.js +35 -14
  334. package/build-module/utils/index.js.map +7 -1
  335. package/build-module/utils/is-numeric-id.js +5 -9
  336. package/build-module/utils/is-numeric-id.js.map +7 -1
  337. package/build-module/utils/is-raw-attribute.js +5 -10
  338. package/build-module/utils/is-raw-attribute.js.map +7 -1
  339. package/build-module/utils/log-entity-deprecation.js +8 -31
  340. package/build-module/utils/log-entity-deprecation.js.map +7 -1
  341. package/build-module/utils/on-sub-key.js +8 -19
  342. package/build-module/utils/on-sub-key.js.map +7 -1
  343. package/build-module/utils/receive-intermediate-results.js +7 -2
  344. package/build-module/utils/receive-intermediate-results.js.map +7 -1
  345. package/build-module/utils/replace-action.js +6 -13
  346. package/build-module/utils/replace-action.js.map +7 -1
  347. package/build-module/utils/set-nested-value.js +8 -27
  348. package/build-module/utils/set-nested-value.js.map +7 -1
  349. package/build-module/utils/user-permissions.js +19 -9
  350. package/build-module/utils/user-permissions.js.map +7 -1
  351. package/build-module/utils/with-weak-map-cache.js +8 -18
  352. package/build-module/utils/with-weak-map-cache.js.map +7 -1
  353. package/build-types/actions.d.ts.map +1 -1
  354. package/build-types/entities.d.ts +0 -56
  355. package/build-types/entities.d.ts.map +1 -1
  356. package/build-types/index.d.ts.map +1 -1
  357. package/build-types/private-selectors.d.ts.map +1 -1
  358. package/build-types/resolvers.d.ts +3 -0
  359. package/build-types/resolvers.d.ts.map +1 -1
  360. package/build-types/selectors.d.ts.map +1 -1
  361. package/build-types/sync.d.ts +6 -1
  362. package/build-types/sync.d.ts.map +1 -1
  363. package/build-types/types.d.ts +9 -0
  364. package/build-types/types.d.ts.map +1 -1
  365. package/build-types/utils/crdt-blocks.d.ts +30 -0
  366. package/build-types/utils/crdt-blocks.d.ts.map +1 -0
  367. package/build-types/utils/crdt.d.ts +49 -0
  368. package/build-types/utils/crdt.d.ts.map +1 -0
  369. package/package.json +26 -19
  370. package/src/actions.js +56 -74
  371. package/src/entities.js +59 -113
  372. package/src/private-selectors.ts +32 -7
  373. package/src/resolvers.js +173 -120
  374. package/src/selectors.ts +0 -13
  375. package/src/sync.ts +12 -0
  376. package/src/test/resolvers.js +183 -0
  377. package/src/types.ts +12 -0
  378. package/src/utils/crdt-blocks.ts +503 -0
  379. package/src/utils/crdt.ts +310 -0
  380. package/src/utils/test/crdt-blocks.ts +375 -0
  381. package/src/utils/test/crdt.ts +254 -0
  382. package/tsconfig.tsbuildinfo +1 -1
  383. package/src/sync.js +0 -27
@@ -1,281 +1,130 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createSelector, createRegistrySelector } from '@wordpress/data';
5
- import { addQueryArgs } from '@wordpress/url';
6
- import deprecated from '@wordpress/deprecated';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { STORE_NAME } from './name';
12
- import { getQueriedItems, getQueriedTotalItems, getQueriedTotalPages } from './queried-data';
13
- import { DEFAULT_ENTITY_KEY } from './entities';
14
- import { getNormalizedCommaSeparable, isRawAttribute, setNestedValue, isNumericID, getUserPermissionCacheKey } from './utils';
15
- import logEntityDeprecation from './utils/log-entity-deprecation';
16
-
17
- // This is an incomplete, high-level approximation of the State type.
18
- // It makes the selectors slightly more safe, but is intended to evolve
19
- // into a more detailed representation over time.
20
- // See https://github.com/WordPress/gutenberg/pull/40025#discussion_r865410589 for more context.
21
-
22
- /**
23
- * HTTP Query parameters sent with the API request to fetch the entity records.
24
- */
25
-
26
- /**
27
- * Arguments for EntityRecord selectors.
28
- */
29
-
30
- /**
31
- * Shared reference to an empty object for cases where it is important to avoid
32
- * returning a new object reference on every invocation, as in a connected or
33
- * other pure component which performs `shouldComponentUpdate` check on props.
34
- * This should be used as a last resort, since the normalized data should be
35
- * maintained by the reducer result in state.
36
- */
1
+ import { createSelector, createRegistrySelector } from "@wordpress/data";
2
+ import { addQueryArgs } from "@wordpress/url";
3
+ import deprecated from "@wordpress/deprecated";
4
+ import { STORE_NAME } from "./name";
5
+ import {
6
+ getQueriedItems,
7
+ getQueriedTotalItems,
8
+ getQueriedTotalPages
9
+ } from "./queried-data";
10
+ import { DEFAULT_ENTITY_KEY } from "./entities";
11
+ import {
12
+ getNormalizedCommaSeparable,
13
+ isRawAttribute,
14
+ setNestedValue,
15
+ isNumericID,
16
+ getUserPermissionCacheKey
17
+ } from "./utils";
18
+ import logEntityDeprecation from "./utils/log-entity-deprecation";
37
19
  const EMPTY_OBJECT = {};
38
-
39
- /**
40
- * Returns true if a request is in progress for embed preview data, or false
41
- * otherwise.
42
- *
43
- * @param state Data state.
44
- * @param url URL the preview would be for.
45
- *
46
- * @return Whether a request is in progress for an embed preview.
47
- */
48
- export const isRequestingEmbedPreview = createRegistrySelector(select => (state, url) => {
49
- return select(STORE_NAME).isResolving('getEmbedPreview', [url]);
50
- });
51
-
52
- /**
53
- * Returns all available authors.
54
- *
55
- * @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
56
- *
57
- * @param state Data state.
58
- * @param query Optional object of query parameters to
59
- * include with request. For valid query parameters see the [Users page](https://developer.wordpress.org/rest-api/reference/users/) in the REST API Handbook and see the arguments for [List Users](https://developer.wordpress.org/rest-api/reference/users/#list-users) and [Retrieve a User](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user).
60
- * @return Authors list.
61
- */
62
- export function getAuthors(state, query) {
20
+ const isRequestingEmbedPreview = createRegistrySelector(
21
+ (select) => (state, url) => {
22
+ return select(STORE_NAME).isResolving("getEmbedPreview", [
23
+ url
24
+ ]);
25
+ }
26
+ );
27
+ function getAuthors(state, query) {
63
28
  deprecated("select( 'core' ).getAuthors()", {
64
- since: '5.9',
29
+ since: "5.9",
65
30
  alternative: "select( 'core' ).getUsers({ who: 'authors' })"
66
31
  });
67
- const path = addQueryArgs('/wp/v2/users/?who=authors&per_page=100', query);
32
+ const path = addQueryArgs(
33
+ "/wp/v2/users/?who=authors&per_page=100",
34
+ query
35
+ );
68
36
  return getUserQueryResults(state, path);
69
37
  }
70
-
71
- /**
72
- * Returns the current user.
73
- *
74
- * @param state Data state.
75
- *
76
- * @return Current user object.
77
- */
78
- export function getCurrentUser(state) {
38
+ function getCurrentUser(state) {
79
39
  return state.currentUser;
80
40
  }
81
-
82
- /**
83
- * Returns all the users returned by a query ID.
84
- *
85
- * @param state Data state.
86
- * @param queryID Query ID.
87
- *
88
- * @return Users list.
89
- */
90
- export const getUserQueryResults = createSelector((state, queryID) => {
91
- var _state$users$queries$;
92
- const queryResults = (_state$users$queries$ = state.users.queries[queryID]) !== null && _state$users$queries$ !== void 0 ? _state$users$queries$ : [];
93
- return queryResults.map(id => state.users.byId[id]);
94
- }, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
95
-
96
- /**
97
- * Returns the loaded entities for the given kind.
98
- *
99
- * @deprecated since WordPress 6.0. Use getEntitiesConfig instead
100
- * @param state Data state.
101
- * @param kind Entity kind.
102
- *
103
- * @return Array of entities with config matching kind.
104
- */
105
- export function getEntitiesByKind(state, kind) {
41
+ const getUserQueryResults = createSelector(
42
+ (state, queryID) => {
43
+ const queryResults = state.users.queries[queryID] ?? [];
44
+ return queryResults.map((id) => state.users.byId[id]);
45
+ },
46
+ (state, queryID) => [
47
+ state.users.queries[queryID],
48
+ state.users.byId
49
+ ]
50
+ );
51
+ function getEntitiesByKind(state, kind) {
106
52
  deprecated("wp.data.select( 'core' ).getEntitiesByKind()", {
107
- since: '6.0',
53
+ since: "6.0",
108
54
  alternative: "wp.data.select( 'core' ).getEntitiesConfig()"
109
55
  });
110
56
  return getEntitiesConfig(state, kind);
111
57
  }
112
-
113
- /**
114
- * Returns the loaded entities for the given kind.
115
- *
116
- * @param state Data state.
117
- * @param kind Entity kind.
118
- *
119
- * @return Array of entities with config matching kind.
120
- */
121
- export const getEntitiesConfig = createSelector((state, kind) => state.entities.config.filter(entity => entity.kind === kind), /* eslint-disable @typescript-eslint/no-unused-vars */
122
- (state, kind) => state.entities.config
123
- /* eslint-enable @typescript-eslint/no-unused-vars */);
124
- /**
125
- * Returns the entity config given its kind and name.
126
- *
127
- * @deprecated since WordPress 6.0. Use getEntityConfig instead
128
- * @param state Data state.
129
- * @param kind Entity kind.
130
- * @param name Entity name.
131
- *
132
- * @return Entity config
133
- */
134
- export function getEntity(state, kind, name) {
58
+ const getEntitiesConfig = createSelector(
59
+ (state, kind) => state.entities.config.filter((entity) => entity.kind === kind),
60
+ /* eslint-disable @typescript-eslint/no-unused-vars */
61
+ (state, kind) => state.entities.config
62
+ /* eslint-enable @typescript-eslint/no-unused-vars */
63
+ );
64
+ function getEntity(state, kind, name) {
135
65
  deprecated("wp.data.select( 'core' ).getEntity()", {
136
- since: '6.0',
66
+ since: "6.0",
137
67
  alternative: "wp.data.select( 'core' ).getEntityConfig()"
138
68
  });
139
69
  return getEntityConfig(state, kind, name);
140
70
  }
141
-
142
- /**
143
- * Returns the entity config given its kind and name.
144
- *
145
- * @param state Data state.
146
- * @param kind Entity kind.
147
- * @param name Entity name.
148
- *
149
- * @return Entity config
150
- */
151
- export function getEntityConfig(state, kind, name) {
152
- logEntityDeprecation(kind, name, 'getEntityConfig');
153
- return state.entities.config?.find(config => config.kind === kind && config.name === name);
154
- }
155
-
156
- /**
157
- * GetEntityRecord is declared as a *callable interface* with
158
- * two signatures to work around the fact that TypeScript doesn't
159
- * allow currying generic functions:
160
- *
161
- * ```ts
162
- * type CurriedState = F extends ( state: any, ...args: infer P ) => infer R
163
- * ? ( ...args: P ) => R
164
- * : F;
165
- * type Selector = <K extends string | number>(
166
- * state: any,
167
- * kind: K,
168
- * key: K extends string ? 'string value' : false
169
- * ) => K;
170
- * type BadlyInferredSignature = CurriedState< Selector >
171
- * // BadlyInferredSignature evaluates to:
172
- * // (kind: string number, key: false | "string value") => string number
173
- * ```
174
- *
175
- * The signature without the state parameter shipped as CurriedSignature
176
- * is used in the return value of `select( coreStore )`.
177
- *
178
- * See https://github.com/WordPress/gutenberg/pull/41578 for more details.
179
- */
180
-
181
- /**
182
- * Returns the Entity's record object by key. Returns `null` if the value is not
183
- * yet received, undefined if the value entity is known to not exist, or the
184
- * entity object if it exists and is received.
185
- *
186
- * @param state State tree
187
- * @param kind Entity kind.
188
- * @param name Entity name.
189
- * @param key Optional record's key. If requesting a global record (e.g. site settings), the key can be omitted. If requesting a specific item, the key must always be included.
190
- * @param query Optional query. If requesting specific
191
- * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available "Retrieve a [Entity kind]".
192
- *
193
- * @return Record.
194
- */
195
- export const getEntityRecord = createSelector((state, kind, name, key, query) => {
196
- var _query$context, _getNormalizedCommaSe;
197
- logEntityDeprecation(kind, name, 'getEntityRecord');
198
-
199
- // For back-compat, we allow querying for static templates through
200
- // wp_template.
201
- if (kind === 'postType' && name === 'wp_template' && typeof key === 'string' &&
202
- // __experimentalGetDirtyEntityRecords always calls getEntityRecord
203
- // with a string key, so we need that it's not a numeric ID.
204
- !/^\d+$/.test(key)) {
205
- name = 'wp_registered_template';
206
- }
207
- const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
208
- if (!queriedState) {
209
- return undefined;
210
- }
211
- const context = (_query$context = query?.context) !== null && _query$context !== void 0 ? _query$context : 'default';
212
- if (!query || !query._fields) {
213
- // If expecting a complete item, validate that completeness.
214
- if (!queriedState.itemIsComplete[context]?.[key]) {
215
- return undefined;
71
+ function getEntityConfig(state, kind, name) {
72
+ logEntityDeprecation(kind, name, "getEntityConfig");
73
+ return state.entities.config?.find(
74
+ (config) => config.kind === kind && config.name === name
75
+ );
76
+ }
77
+ const getEntityRecord = createSelector(
78
+ ((state, kind, name, key, query) => {
79
+ logEntityDeprecation(kind, name, "getEntityRecord");
80
+ const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
81
+ if (!queriedState) {
82
+ return void 0;
216
83
  }
217
- return queriedState.items[context][key];
218
- }
219
- const item = queriedState.items[context]?.[key];
220
- if (!item) {
221
- return item;
222
- }
223
- const filteredItem = {};
224
- const fields = (_getNormalizedCommaSe = getNormalizedCommaSeparable(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : [];
225
- for (let f = 0; f < fields.length; f++) {
226
- const field = fields[f].split('.');
227
- let value = item;
228
- field.forEach(fieldName => {
229
- value = value?.[fieldName];
230
- });
231
- setNestedValue(filteredItem, field, value);
84
+ const context = query?.context ?? "default";
85
+ if (!query || !query._fields) {
86
+ if (!queriedState.itemIsComplete[context]?.[key]) {
87
+ return void 0;
88
+ }
89
+ return queriedState.items[context][key];
90
+ }
91
+ const item = queriedState.items[context]?.[key];
92
+ if (!item) {
93
+ return item;
94
+ }
95
+ const filteredItem = {};
96
+ const fields = getNormalizedCommaSeparable(query._fields) ?? [];
97
+ for (let f = 0; f < fields.length; f++) {
98
+ const field = fields[f].split(".");
99
+ let value = item;
100
+ field.forEach((fieldName) => {
101
+ value = value?.[fieldName];
102
+ });
103
+ setNestedValue(filteredItem, field, value);
104
+ }
105
+ return filteredItem;
106
+ }),
107
+ (state, kind, name, recordId, query) => {
108
+ const context = query?.context ?? "default";
109
+ const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
110
+ return [
111
+ queriedState?.items[context]?.[recordId],
112
+ queriedState?.itemIsComplete[context]?.[recordId]
113
+ ];
232
114
  }
233
- return filteredItem;
234
- }, (state, kind, name, recordId, query) => {
235
- var _query$context2;
236
- const context = (_query$context2 = query?.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
237
- const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
238
- return [queriedState?.items[context]?.[recordId], queriedState?.itemIsComplete[context]?.[recordId]];
239
- });
240
-
241
- /**
242
- * Normalizes `recordKey`s that look like numeric IDs to numbers.
243
- *
244
- * @param args EntityRecordArgs the selector arguments.
245
- * @return EntityRecordArgs the normalized arguments.
246
- */
247
- getEntityRecord.__unstableNormalizeArgs = args => {
115
+ );
116
+ getEntityRecord.__unstableNormalizeArgs = (args) => {
248
117
  const newArgs = [...args];
249
118
  const recordKey = newArgs?.[2];
250
-
251
- // If recordKey looks to be a numeric ID then coerce to number.
252
119
  newArgs[2] = isNumericID(recordKey) ? Number(recordKey) : recordKey;
253
120
  return newArgs;
254
121
  };
255
-
256
- /**
257
- * Returns true if a record has been received for the given set of parameters, or false otherwise.
258
- *
259
- * Note: This action does not trigger a request for the entity record from the API
260
- * if it's not available in the local state.
261
- *
262
- * @param state State tree
263
- * @param kind Entity kind.
264
- * @param name Entity name.
265
- * @param key Record's key.
266
- * @param query Optional query.
267
- *
268
- * @return Whether an entity record has been received.
269
- */
270
- export function hasEntityRecord(state, kind, name, key, query) {
271
- var _query$context3, _getNormalizedCommaSe2;
122
+ function hasEntityRecord(state, kind, name, key, query) {
272
123
  const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
273
124
  if (!queriedState) {
274
125
  return false;
275
126
  }
276
- const context = (_query$context3 = query?.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
277
-
278
- // If expecting a complete item, validate that completeness.
127
+ const context = query?.context ?? "default";
279
128
  if (!query || !query._fields) {
280
129
  return !!queriedState.itemIsComplete[context]?.[key];
281
130
  }
@@ -283,12 +132,9 @@ export function hasEntityRecord(state, kind, name, key, query) {
283
132
  if (!item) {
284
133
  return false;
285
134
  }
286
-
287
- // When `query._fields` is provided, check that each requested field exists,
288
- // including any nested paths, on the item; return false if any part is missing.
289
- const fields = (_getNormalizedCommaSe2 = getNormalizedCommaSeparable(query._fields)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : [];
135
+ const fields = getNormalizedCommaSeparable(query._fields) ?? [];
290
136
  for (let i = 0; i < fields.length; i++) {
291
- const path = fields[i].split('.');
137
+ const path = fields[i].split(".");
292
138
  let value = item;
293
139
  for (let p = 0; p < path.length; p++) {
294
140
  const part = path[p];
@@ -300,139 +146,58 @@ export function hasEntityRecord(state, kind, name, key, query) {
300
146
  }
301
147
  return true;
302
148
  }
303
-
304
- /**
305
- * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
306
- *
307
- * @param state State tree
308
- * @param kind Entity kind.
309
- * @param name Entity name.
310
- * @param key Record's key
311
- *
312
- * @return Record.
313
- */
314
- export function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
149
+ function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
315
150
  return getEntityRecord(state, kind, name, key);
316
151
  }
317
-
318
- /**
319
- * Returns the entity's record object by key,
320
- * with its attributes mapped to their raw values.
321
- *
322
- * @param state State tree.
323
- * @param kind Entity kind.
324
- * @param name Entity name.
325
- * @param key Record's key.
326
- *
327
- * @return Object with the entity's raw attributes.
328
- */
329
- export const getRawEntityRecord = createSelector((state, kind, name, key) => {
330
- logEntityDeprecation(kind, name, 'getRawEntityRecord');
331
- const record = getEntityRecord(state, kind, name, key);
332
- return record && Object.keys(record).reduce((accumulator, _key) => {
333
- if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
334
- // Because edits are the "raw" attribute values,
335
- // we return those from record selectors to make rendering,
336
- // comparisons, and joins with edits easier.
337
- accumulator[_key] = record[_key]?.raw !== undefined ? record[_key]?.raw : record[_key];
338
- } else {
339
- accumulator[_key] = record[_key];
340
- }
341
- return accumulator;
342
- }, {});
343
- }, (state, kind, name, recordId, query) => {
344
- var _query$context4;
345
- const context = (_query$context4 = query?.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
346
- return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]];
347
- });
348
-
349
- /**
350
- * Returns true if records have been received for the given set of parameters,
351
- * or false otherwise.
352
- *
353
- * @param state State tree
354
- * @param kind Entity kind.
355
- * @param name Entity name.
356
- * @param query Optional terms query. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
357
- *
358
- * @return Whether entity records have been received.
359
- */
360
- export function hasEntityRecords(state, kind, name, query) {
361
- logEntityDeprecation(kind, name, 'hasEntityRecords');
152
+ const getRawEntityRecord = createSelector(
153
+ (state, kind, name, key) => {
154
+ logEntityDeprecation(kind, name, "getRawEntityRecord");
155
+ const record = getEntityRecord(
156
+ state,
157
+ kind,
158
+ name,
159
+ key
160
+ );
161
+ return record && Object.keys(record).reduce((accumulator, _key) => {
162
+ if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
163
+ accumulator[_key] = record[_key]?.raw !== void 0 ? record[_key]?.raw : record[_key];
164
+ } else {
165
+ accumulator[_key] = record[_key];
166
+ }
167
+ return accumulator;
168
+ }, {});
169
+ },
170
+ (state, kind, name, recordId, query) => {
171
+ const context = query?.context ?? "default";
172
+ return [
173
+ state.entities.config,
174
+ state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId],
175
+ state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]
176
+ ];
177
+ }
178
+ );
179
+ function hasEntityRecords(state, kind, name, query) {
180
+ logEntityDeprecation(kind, name, "hasEntityRecords");
362
181
  return Array.isArray(getEntityRecords(state, kind, name, query));
363
182
  }
364
-
365
- /**
366
- * GetEntityRecord is declared as a *callable interface* with
367
- * two signatures to work around the fact that TypeScript doesn't
368
- * allow currying generic functions.
369
- *
370
- * @see GetEntityRecord
371
- * @see https://github.com/WordPress/gutenberg/pull/41578
372
- */
373
-
374
- /**
375
- * Returns the Entity's records.
376
- *
377
- * @param state State tree
378
- * @param kind Entity kind.
379
- * @param name Entity name.
380
- * @param query Optional terms query. If requesting specific
381
- * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
382
- *
383
- * @return Records.
384
- */
385
- export const getEntityRecords = (state, kind, name, query) => {
386
- logEntityDeprecation(kind, name, 'getEntityRecords');
387
-
388
- // Queried data state is prepopulated for all known entities. If this is not
389
- // assigned for the given parameters, then it is known to not exist.
183
+ const getEntityRecords = ((state, kind, name, query) => {
184
+ logEntityDeprecation(kind, name, "getEntityRecords");
390
185
  const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
391
186
  if (!queriedState) {
392
187
  return null;
393
188
  }
394
189
  return getQueriedItems(queriedState, query);
395
- };
396
-
397
- /**
398
- * Returns the Entity's total available records for a given query (ignoring pagination).
399
- *
400
- * @param state State tree
401
- * @param kind Entity kind.
402
- * @param name Entity name.
403
- * @param query Optional terms query. If requesting specific
404
- * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
405
- *
406
- * @return number | null.
407
- */
408
- export const getEntityRecordsTotalItems = (state, kind, name, query) => {
409
- logEntityDeprecation(kind, name, 'getEntityRecordsTotalItems');
410
-
411
- // Queried data state is prepopulated for all known entities. If this is not
412
- // assigned for the given parameters, then it is known to not exist.
190
+ });
191
+ const getEntityRecordsTotalItems = (state, kind, name, query) => {
192
+ logEntityDeprecation(kind, name, "getEntityRecordsTotalItems");
413
193
  const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
414
194
  if (!queriedState) {
415
195
  return null;
416
196
  }
417
197
  return getQueriedTotalItems(queriedState, query);
418
198
  };
419
-
420
- /**
421
- * Returns the number of available pages for the given query.
422
- *
423
- * @param state State tree
424
- * @param kind Entity kind.
425
- * @param name Entity name.
426
- * @param query Optional terms query. If requesting specific
427
- * fields, fields must always include the ID. For valid query parameters see the [Reference](https://developer.wordpress.org/rest-api/reference/) in the REST API Handbook and select the entity kind. Then see the arguments available for "List [Entity kind]s".
428
- *
429
- * @return number | null.
430
- */
431
- export const getEntityRecordsTotalPages = (state, kind, name, query) => {
432
- logEntityDeprecation(kind, name, 'getEntityRecordsTotalPages');
433
-
434
- // Queried data state is prepopulated for all known entities. If this is not
435
- // assigned for the given parameters, then it is known to not exist.
199
+ const getEntityRecordsTotalPages = (state, kind, name, query) => {
200
+ logEntityDeprecation(kind, name, "getEntityRecordsTotalPages");
436
201
  const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
437
202
  if (!queriedState) {
438
203
  return null;
@@ -444,597 +209,269 @@ export const getEntityRecordsTotalPages = (state, kind, name, query) => {
444
209
  if (!totalItems) {
445
210
  return totalItems;
446
211
  }
447
- // If `per_page` is not set and the query relies on the defaults of the
448
- // REST endpoint, get the info from query's meta.
449
212
  if (!query?.per_page) {
450
213
  return getQueriedTotalPages(queriedState, query);
451
214
  }
452
215
  return Math.ceil(totalItems / query.per_page);
453
216
  };
454
- /**
455
- * Returns the list of dirty entity records.
456
- *
457
- * @param state State tree.
458
- *
459
- * @return The list of updated records
460
- */
461
- export const __experimentalGetDirtyEntityRecords = createSelector(state => {
462
- const {
463
- entities: {
464
- records
465
- }
466
- } = state;
467
- const dirtyRecords = [];
468
- Object.keys(records).forEach(kind => {
469
- Object.keys(records[kind]).forEach(name => {
470
- const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey =>
471
- // The entity record must exist (not be deleted),
472
- // and it must have edits.
473
- getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey));
474
- if (primaryKeys.length) {
475
- const entityConfig = getEntityConfig(state, kind, name);
476
- primaryKeys.forEach(primaryKey => {
477
- const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
478
- dirtyRecords.push({
479
- // We avoid using primaryKey because it's transformed into a string
480
- // when it's used as an object key.
481
- key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : undefined,
482
- title: entityConfig?.getTitle?.(entityRecord) || '',
483
- name,
484
- kind
217
+ const __experimentalGetDirtyEntityRecords = createSelector(
218
+ (state) => {
219
+ const {
220
+ entities: { records }
221
+ } = state;
222
+ const dirtyRecords = [];
223
+ Object.keys(records).forEach((kind) => {
224
+ Object.keys(records[kind]).forEach((name) => {
225
+ const primaryKeys = Object.keys(records[kind][name].edits).filter(
226
+ (primaryKey) => (
227
+ // The entity record must exist (not be deleted),
228
+ // and it must have edits.
229
+ getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey)
230
+ )
231
+ );
232
+ if (primaryKeys.length) {
233
+ const entityConfig = getEntityConfig(state, kind, name);
234
+ primaryKeys.forEach((primaryKey) => {
235
+ const entityRecord = getEditedEntityRecord(
236
+ state,
237
+ kind,
238
+ name,
239
+ primaryKey
240
+ );
241
+ dirtyRecords.push({
242
+ // We avoid using primaryKey because it's transformed into a string
243
+ // when it's used as an object key.
244
+ key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : void 0,
245
+ title: entityConfig?.getTitle?.(entityRecord) || "",
246
+ name,
247
+ kind
248
+ });
485
249
  });
486
- });
487
- }
250
+ }
251
+ });
488
252
  });
489
- });
490
- return dirtyRecords;
491
- }, state => [state.entities.records]);
492
-
493
- /**
494
- * Returns the list of entities currently being saved.
495
- *
496
- * @param state State tree.
497
- *
498
- * @return The list of records being saved.
499
- */
500
- export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
501
- const {
502
- entities: {
503
- records
504
- }
505
- } = state;
506
- const recordsBeingSaved = [];
507
- Object.keys(records).forEach(kind => {
508
- Object.keys(records[kind]).forEach(name => {
509
- const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
510
- if (primaryKeys.length) {
511
- const entityConfig = getEntityConfig(state, kind, name);
512
- primaryKeys.forEach(primaryKey => {
513
- const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
514
- recordsBeingSaved.push({
515
- // We avoid using primaryKey because it's transformed into a string
516
- // when it's used as an object key.
517
- key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : undefined,
518
- title: entityConfig?.getTitle?.(entityRecord) || '',
519
- name,
520
- kind
253
+ return dirtyRecords;
254
+ },
255
+ (state) => [state.entities.records]
256
+ );
257
+ const __experimentalGetEntitiesBeingSaved = createSelector(
258
+ (state) => {
259
+ const {
260
+ entities: { records }
261
+ } = state;
262
+ const recordsBeingSaved = [];
263
+ Object.keys(records).forEach((kind) => {
264
+ Object.keys(records[kind]).forEach((name) => {
265
+ const primaryKeys = Object.keys(records[kind][name].saving).filter(
266
+ (primaryKey) => isSavingEntityRecord(state, kind, name, primaryKey)
267
+ );
268
+ if (primaryKeys.length) {
269
+ const entityConfig = getEntityConfig(state, kind, name);
270
+ primaryKeys.forEach((primaryKey) => {
271
+ const entityRecord = getEditedEntityRecord(
272
+ state,
273
+ kind,
274
+ name,
275
+ primaryKey
276
+ );
277
+ recordsBeingSaved.push({
278
+ // We avoid using primaryKey because it's transformed into a string
279
+ // when it's used as an object key.
280
+ key: entityRecord ? entityRecord[entityConfig.key || DEFAULT_ENTITY_KEY] : void 0,
281
+ title: entityConfig?.getTitle?.(entityRecord) || "",
282
+ name,
283
+ kind
284
+ });
521
285
  });
522
- });
523
- }
286
+ }
287
+ });
524
288
  });
525
- });
526
- return recordsBeingSaved;
527
- }, state => [state.entities.records]);
528
-
529
- /**
530
- * Returns the specified entity record's edits.
531
- *
532
- * @param state State tree.
533
- * @param kind Entity kind.
534
- * @param name Entity name.
535
- * @param recordId Record ID.
536
- *
537
- * @return The entity record's edits.
538
- */
539
- export function getEntityRecordEdits(state, kind, name, recordId) {
540
- logEntityDeprecation(kind, name, 'getEntityRecordEdits');
289
+ return recordsBeingSaved;
290
+ },
291
+ (state) => [state.entities.records]
292
+ );
293
+ function getEntityRecordEdits(state, kind, name, recordId) {
294
+ logEntityDeprecation(kind, name, "getEntityRecordEdits");
541
295
  return state.entities.records?.[kind]?.[name]?.edits?.[recordId];
542
296
  }
543
-
544
- /**
545
- * Returns the specified entity record's non transient edits.
546
- *
547
- * Transient edits don't create an undo level, and
548
- * are not considered for change detection.
549
- * They are defined in the entity's config.
550
- *
551
- * @param state State tree.
552
- * @param kind Entity kind.
553
- * @param name Entity name.
554
- * @param recordId Record ID.
555
- *
556
- * @return The entity record's non transient edits.
557
- */
558
- export const getEntityRecordNonTransientEdits = createSelector((state, kind, name, recordId) => {
559
- logEntityDeprecation(kind, name, 'getEntityRecordNonTransientEdits');
560
- const {
561
- transientEdits
562
- } = getEntityConfig(state, kind, name) || {};
563
- const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
564
- if (!transientEdits) {
565
- return edits;
566
- }
567
- return Object.keys(edits).reduce((acc, key) => {
568
- if (!transientEdits[key]) {
569
- acc[key] = edits[key];
297
+ const getEntityRecordNonTransientEdits = createSelector(
298
+ (state, kind, name, recordId) => {
299
+ logEntityDeprecation(kind, name, "getEntityRecordNonTransientEdits");
300
+ const { transientEdits } = getEntityConfig(state, kind, name) || {};
301
+ const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
302
+ if (!transientEdits) {
303
+ return edits;
570
304
  }
571
- return acc;
572
- }, {});
573
- }, (state, kind, name, recordId) => [state.entities.config, state.entities.records?.[kind]?.[name]?.edits?.[recordId]]);
574
-
575
- /**
576
- * Returns true if the specified entity record has edits,
577
- * and false otherwise.
578
- *
579
- * @param state State tree.
580
- * @param kind Entity kind.
581
- * @param name Entity name.
582
- * @param recordId Record ID.
583
- *
584
- * @return Whether the entity record has edits or not.
585
- */
586
- export function hasEditsForEntityRecord(state, kind, name, recordId) {
587
- logEntityDeprecation(kind, name, 'hasEditsForEntityRecord');
588
- return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0;
589
- }
590
-
591
- /**
592
- * Returns the specified entity record, merged with its edits.
593
- *
594
- * @param state State tree.
595
- * @param kind Entity kind.
596
- * @param name Entity name.
597
- * @param recordId Record ID.
598
- *
599
- * @return The entity record, merged with its edits.
600
- */
601
- export const getEditedEntityRecord = createSelector((state, kind, name, recordId) => {
602
- logEntityDeprecation(kind, name, 'getEditedEntityRecord');
603
- const raw = getRawEntityRecord(state, kind, name, recordId);
604
- const edited = getEntityRecordEdits(state, kind, name, recordId);
605
- // Never return a non-falsy empty object. Unfortunately we can't return
606
- // undefined or null because we were previously returning an empty
607
- // object, so trying to read properties from the result would throw.
608
- // Using false here is a workaround to avoid breaking changes.
609
- if (!raw && !edited) {
610
- return false;
305
+ return Object.keys(edits).reduce((acc, key) => {
306
+ if (!transientEdits[key]) {
307
+ acc[key] = edits[key];
308
+ }
309
+ return acc;
310
+ }, {});
311
+ },
312
+ (state, kind, name, recordId) => [
313
+ state.entities.config,
314
+ state.entities.records?.[kind]?.[name]?.edits?.[recordId]
315
+ ]
316
+ );
317
+ function hasEditsForEntityRecord(state, kind, name, recordId) {
318
+ logEntityDeprecation(kind, name, "hasEditsForEntityRecord");
319
+ return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(
320
+ getEntityRecordNonTransientEdits(state, kind, name, recordId)
321
+ ).length > 0;
322
+ }
323
+ const getEditedEntityRecord = createSelector(
324
+ (state, kind, name, recordId) => {
325
+ logEntityDeprecation(kind, name, "getEditedEntityRecord");
326
+ const raw = getRawEntityRecord(state, kind, name, recordId);
327
+ const edited = getEntityRecordEdits(state, kind, name, recordId);
328
+ if (!raw && !edited) {
329
+ return false;
330
+ }
331
+ return {
332
+ ...raw,
333
+ ...edited
334
+ };
335
+ },
336
+ (state, kind, name, recordId, query) => {
337
+ const context = query?.context ?? "default";
338
+ return [
339
+ state.entities.config,
340
+ state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId],
341
+ state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId],
342
+ state.entities.records?.[kind]?.[name]?.edits?.[recordId]
343
+ ];
611
344
  }
612
- return {
613
- ...raw,
614
- ...edited
615
- };
616
- }, (state, kind, name, recordId, query) => {
617
- var _query$context5;
618
- const context = (_query$context5 = query?.context) !== null && _query$context5 !== void 0 ? _query$context5 : 'default';
619
- return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId], state.entities.records?.[kind]?.[name]?.edits?.[recordId]];
620
- });
621
-
622
- /**
623
- * Returns true if the specified entity record is autosaving, and false otherwise.
624
- *
625
- * @param state State tree.
626
- * @param kind Entity kind.
627
- * @param name Entity name.
628
- * @param recordId Record ID.
629
- *
630
- * @return Whether the entity record is autosaving or not.
631
- */
632
- export function isAutosavingEntityRecord(state, kind, name, recordId) {
633
- var _state$entities$recor;
634
- logEntityDeprecation(kind, name, 'isAutosavingEntityRecord');
635
- const {
636
- pending,
637
- isAutosave
638
- } = (_state$entities$recor = state.entities.records?.[kind]?.[name]?.saving?.[recordId]) !== null && _state$entities$recor !== void 0 ? _state$entities$recor : {};
345
+ );
346
+ function isAutosavingEntityRecord(state, kind, name, recordId) {
347
+ logEntityDeprecation(kind, name, "isAutosavingEntityRecord");
348
+ const { pending, isAutosave } = state.entities.records?.[kind]?.[name]?.saving?.[recordId] ?? {};
639
349
  return Boolean(pending && isAutosave);
640
350
  }
641
-
642
- /**
643
- * Returns true if the specified entity record is saving, and false otherwise.
644
- *
645
- * @param state State tree.
646
- * @param kind Entity kind.
647
- * @param name Entity name.
648
- * @param recordId Record ID.
649
- *
650
- * @return Whether the entity record is saving or not.
651
- */
652
- export function isSavingEntityRecord(state, kind, name, recordId) {
653
- var _state$entities$recor2;
654
- logEntityDeprecation(kind, name, 'isSavingEntityRecord');
655
- return (_state$entities$recor2 = state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending) !== null && _state$entities$recor2 !== void 0 ? _state$entities$recor2 : false;
351
+ function isSavingEntityRecord(state, kind, name, recordId) {
352
+ logEntityDeprecation(kind, name, "isSavingEntityRecord");
353
+ return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending ?? false;
656
354
  }
657
-
658
- /**
659
- * Returns true if the specified entity record is deleting, and false otherwise.
660
- *
661
- * @param state State tree.
662
- * @param kind Entity kind.
663
- * @param name Entity name.
664
- * @param recordId Record ID.
665
- *
666
- * @return Whether the entity record is deleting or not.
667
- */
668
- export function isDeletingEntityRecord(state, kind, name, recordId) {
669
- var _state$entities$recor3;
670
- logEntityDeprecation(kind, name, 'isDeletingEntityRecord');
671
- return (_state$entities$recor3 = state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending) !== null && _state$entities$recor3 !== void 0 ? _state$entities$recor3 : false;
355
+ function isDeletingEntityRecord(state, kind, name, recordId) {
356
+ logEntityDeprecation(kind, name, "isDeletingEntityRecord");
357
+ return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending ?? false;
672
358
  }
673
-
674
- /**
675
- * Returns the specified entity record's last save error.
676
- *
677
- * @param state State tree.
678
- * @param kind Entity kind.
679
- * @param name Entity name.
680
- * @param recordId Record ID.
681
- *
682
- * @return The entity record's save error.
683
- */
684
- export function getLastEntitySaveError(state, kind, name, recordId) {
685
- logEntityDeprecation(kind, name, 'getLastEntitySaveError');
359
+ function getLastEntitySaveError(state, kind, name, recordId) {
360
+ logEntityDeprecation(kind, name, "getLastEntitySaveError");
686
361
  return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.error;
687
362
  }
688
-
689
- /**
690
- * Returns the specified entity record's last delete error.
691
- *
692
- * @param state State tree.
693
- * @param kind Entity kind.
694
- * @param name Entity name.
695
- * @param recordId Record ID.
696
- *
697
- * @return The entity record's save error.
698
- */
699
- export function getLastEntityDeleteError(state, kind, name, recordId) {
700
- logEntityDeprecation(kind, name, 'getLastEntityDeleteError');
363
+ function getLastEntityDeleteError(state, kind, name, recordId) {
364
+ logEntityDeprecation(kind, name, "getLastEntityDeleteError");
701
365
  return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.error;
702
366
  }
703
-
704
- /* eslint-disable @typescript-eslint/no-unused-vars */
705
- /**
706
- * Returns the previous edit from the current undo offset
707
- * for the entity records edits history, if any.
708
- *
709
- * @deprecated since 6.3
710
- *
711
- * @param state State tree.
712
- *
713
- * @return The edit.
714
- */
715
- export function getUndoEdit(state) {
367
+ function getUndoEdit(state) {
716
368
  deprecated("select( 'core' ).getUndoEdit()", {
717
- since: '6.3'
369
+ since: "6.3"
718
370
  });
719
- return undefined;
371
+ return void 0;
720
372
  }
721
- /* eslint-enable @typescript-eslint/no-unused-vars */
722
-
723
- /* eslint-disable @typescript-eslint/no-unused-vars */
724
- /**
725
- * Returns the next edit from the current undo offset
726
- * for the entity records edits history, if any.
727
- *
728
- * @deprecated since 6.3
729
- *
730
- * @param state State tree.
731
- *
732
- * @return The edit.
733
- */
734
- export function getRedoEdit(state) {
373
+ function getRedoEdit(state) {
735
374
  deprecated("select( 'core' ).getRedoEdit()", {
736
- since: '6.3'
375
+ since: "6.3"
737
376
  });
738
- return undefined;
377
+ return void 0;
739
378
  }
740
- /* eslint-enable @typescript-eslint/no-unused-vars */
741
-
742
- /**
743
- * Returns true if there is a previous edit from the current undo offset
744
- * for the entity records edits history, and false otherwise.
745
- *
746
- * @param state State tree.
747
- *
748
- * @return Whether there is a previous edit or not.
749
- */
750
- export function hasUndo(state) {
379
+ function hasUndo(state) {
751
380
  return state.undoManager.hasUndo();
752
381
  }
753
-
754
- /**
755
- * Returns true if there is a next edit from the current undo offset
756
- * for the entity records edits history, and false otherwise.
757
- *
758
- * @param state State tree.
759
- *
760
- * @return Whether there is a next edit or not.
761
- */
762
- export function hasRedo(state) {
382
+ function hasRedo(state) {
763
383
  return state.undoManager.hasRedo();
764
384
  }
765
-
766
- /**
767
- * Return the current theme.
768
- *
769
- * @param state Data state.
770
- *
771
- * @return The current theme.
772
- */
773
- export function getCurrentTheme(state) {
385
+ function getCurrentTheme(state) {
774
386
  if (!state.currentTheme) {
775
387
  return null;
776
388
  }
777
- return getEntityRecord(state, 'root', 'theme', state.currentTheme);
389
+ return getEntityRecord(state, "root", "theme", state.currentTheme);
778
390
  }
779
-
780
- /**
781
- * Return the ID of the current global styles object.
782
- *
783
- * @param state Data state.
784
- *
785
- * @return The current global styles ID.
786
- */
787
- export function __experimentalGetCurrentGlobalStylesId(state) {
391
+ function __experimentalGetCurrentGlobalStylesId(state) {
788
392
  return state.currentGlobalStylesId;
789
393
  }
790
-
791
- /**
792
- * Return theme supports data in the index.
793
- *
794
- * @param state Data state.
795
- *
796
- * @return Index data.
797
- */
798
- export function getThemeSupports(state) {
799
- var _getCurrentTheme$them;
800
- return (_getCurrentTheme$them = getCurrentTheme(state)?.theme_supports) !== null && _getCurrentTheme$them !== void 0 ? _getCurrentTheme$them : EMPTY_OBJECT;
394
+ function getThemeSupports(state) {
395
+ return getCurrentTheme(state)?.theme_supports ?? EMPTY_OBJECT;
801
396
  }
802
-
803
- /**
804
- * Returns the embed preview for the given URL.
805
- *
806
- * @param state Data state.
807
- * @param url Embedded URL.
808
- *
809
- * @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
810
- */
811
- export function getEmbedPreview(state, url) {
397
+ function getEmbedPreview(state, url) {
812
398
  return state.embedPreviews[url];
813
399
  }
814
-
815
- /**
816
- * Determines if the returned preview is an oEmbed link fallback.
817
- *
818
- * WordPress can be configured to return a simple link to a URL if it is not embeddable.
819
- * We need to be able to determine if a URL is embeddable or not, based on what we
820
- * get back from the oEmbed preview API.
821
- *
822
- * @param state Data state.
823
- * @param url Embedded URL.
824
- *
825
- * @return Is the preview for the URL an oEmbed link fallback.
826
- */
827
- export function isPreviewEmbedFallback(state, url) {
400
+ function isPreviewEmbedFallback(state, url) {
828
401
  const preview = state.embedPreviews[url];
829
- const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>';
402
+ const oEmbedLinkCheck = '<a href="' + url + '">' + url + "</a>";
830
403
  if (!preview) {
831
404
  return false;
832
405
  }
833
406
  return preview.html === oEmbedLinkCheck;
834
407
  }
835
-
836
- /**
837
- * Returns whether the current user can perform the given action on the given
838
- * REST resource.
839
- *
840
- * Calling this may trigger an OPTIONS request to the REST API via the
841
- * `canUser()` resolver.
842
- *
843
- * https://developer.wordpress.org/rest-api/reference/
844
- *
845
- * @param state Data state.
846
- * @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
847
- * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
848
- * or REST base as a string - `media`.
849
- * @param id Optional ID of the rest resource to check.
850
- *
851
- * @return Whether or not the user can perform the action,
852
- * or `undefined` if the OPTIONS request is still being made.
853
- */
854
- export function canUser(state, action, resource, id) {
855
- const isEntity = typeof resource === 'object';
408
+ function canUser(state, action, resource, id) {
409
+ const isEntity = typeof resource === "object";
856
410
  if (isEntity && (!resource.kind || !resource.name)) {
857
411
  return false;
858
412
  }
859
413
  if (isEntity) {
860
- logEntityDeprecation(resource.kind, resource.name, 'canUser');
414
+ logEntityDeprecation(resource.kind, resource.name, "canUser");
861
415
  }
862
416
  const key = getUserPermissionCacheKey(action, resource, id);
863
417
  return state.userPermissions[key];
864
418
  }
865
-
866
- /**
867
- * Returns whether the current user can edit the given entity.
868
- *
869
- * Calling this may trigger an OPTIONS request to the REST API via the
870
- * `canUser()` resolver.
871
- *
872
- * https://developer.wordpress.org/rest-api/reference/
873
- *
874
- * @param state Data state.
875
- * @param kind Entity kind.
876
- * @param name Entity name.
877
- * @param recordId Record's id.
878
- * @return Whether or not the user can edit,
879
- * or `undefined` if the OPTIONS request is still being made.
880
- */
881
- export function canUserEditEntityRecord(state, kind, name, recordId) {
419
+ function canUserEditEntityRecord(state, kind, name, recordId) {
882
420
  deprecated(`wp.data.select( 'core' ).canUserEditEntityRecord()`, {
883
- since: '6.7',
421
+ since: "6.7",
884
422
  alternative: `wp.data.select( 'core' ).canUser( 'update', { kind, name, id } )`
885
423
  });
886
- return canUser(state, 'update', {
887
- kind,
888
- name,
889
- id: recordId
890
- });
424
+ return canUser(state, "update", { kind, name, id: recordId });
891
425
  }
892
-
893
- /**
894
- * Returns the latest autosaves for the post.
895
- *
896
- * May return multiple autosaves since the backend stores one autosave per
897
- * author for each post.
898
- *
899
- * @param state State tree.
900
- * @param postType The type of the parent post.
901
- * @param postId The id of the parent post.
902
- *
903
- * @return An array of autosaves for the post, or undefined if there is none.
904
- */
905
- export function getAutosaves(state, postType, postId) {
426
+ function getAutosaves(state, postType, postId) {
906
427
  return state.autosaves[postId];
907
428
  }
908
-
909
- /**
910
- * Returns the autosave for the post and author.
911
- *
912
- * @param state State tree.
913
- * @param postType The type of the parent post.
914
- * @param postId The id of the parent post.
915
- * @param authorId The id of the author.
916
- *
917
- * @return The autosave for the post and author.
918
- */
919
- export function getAutosave(state, postType, postId, authorId) {
920
- if (authorId === undefined) {
429
+ function getAutosave(state, postType, postId, authorId) {
430
+ if (authorId === void 0) {
921
431
  return;
922
432
  }
923
433
  const autosaves = state.autosaves[postId];
924
- return autosaves?.find(autosave => autosave.author === authorId);
925
- }
926
-
927
- /**
928
- * Returns true if the REST request for autosaves has completed.
929
- *
930
- * @param state State tree.
931
- * @param postType The type of the parent post.
932
- * @param postId The id of the parent post.
933
- *
934
- * @return True if the REST request was completed. False otherwise.
935
- */
936
- export const hasFetchedAutosaves = createRegistrySelector(select => (state, postType, postId) => {
937
- return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]);
938
- });
939
-
940
- /**
941
- * Returns a new reference when edited values have changed. This is useful in
942
- * inferring where an edit has been made between states by comparison of the
943
- * return values using strict equality.
944
- *
945
- * @example
946
- *
947
- * ```
948
- * const hasEditOccurred = (
949
- * getReferenceByDistinctEdits( beforeState ) !==
950
- * getReferenceByDistinctEdits( afterState )
951
- * );
952
- * ```
953
- *
954
- * @param state Editor state.
955
- *
956
- * @return A value whose reference will change only when an edit occurs.
957
- */
958
- export function getReferenceByDistinctEdits(state) {
434
+ return autosaves?.find(
435
+ (autosave) => autosave.author === authorId
436
+ );
437
+ }
438
+ const hasFetchedAutosaves = createRegistrySelector(
439
+ (select) => (state, postType, postId) => {
440
+ return select(STORE_NAME).hasFinishedResolution("getAutosaves", [
441
+ postType,
442
+ postId
443
+ ]);
444
+ }
445
+ );
446
+ function getReferenceByDistinctEdits(state) {
959
447
  return state.editsReference;
960
448
  }
961
-
962
- /**
963
- * Retrieve the current theme's base global styles
964
- *
965
- * @param state Editor state.
966
- *
967
- * @return The Global Styles object.
968
- */
969
- export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
449
+ function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
970
450
  const currentTheme = getCurrentTheme(state);
971
451
  if (!currentTheme) {
972
452
  return null;
973
453
  }
974
454
  return state.themeBaseGlobalStyles[currentTheme.stylesheet];
975
455
  }
976
-
977
- /**
978
- * Return the ID of the current global styles object.
979
- *
980
- * @param state Data state.
981
- *
982
- * @return The current global styles ID.
983
- */
984
- export function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
456
+ function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
985
457
  const currentTheme = getCurrentTheme(state);
986
458
  if (!currentTheme) {
987
459
  return null;
988
460
  }
989
461
  return state.themeGlobalStyleVariations[currentTheme.stylesheet];
990
462
  }
991
-
992
- /**
993
- * Retrieve the list of registered block patterns.
994
- *
995
- * @param state Data state.
996
- *
997
- * @return Block pattern list.
998
- */
999
- export function getBlockPatterns(state) {
463
+ function getBlockPatterns(state) {
1000
464
  return state.blockPatterns;
1001
465
  }
1002
-
1003
- /**
1004
- * Retrieve the list of registered block pattern categories.
1005
- *
1006
- * @param state Data state.
1007
- *
1008
- * @return Block pattern category list.
1009
- */
1010
- export function getBlockPatternCategories(state) {
466
+ function getBlockPatternCategories(state) {
1011
467
  return state.blockPatternCategories;
1012
468
  }
1013
-
1014
- /**
1015
- * Retrieve the registered user pattern categories.
1016
- *
1017
- * @param state Data state.
1018
- *
1019
- * @return User patterns category array.
1020
- */
1021
-
1022
- export function getUserPatternCategories(state) {
469
+ function getUserPatternCategories(state) {
1023
470
  return state.userPatternCategories;
1024
471
  }
1025
-
1026
- /**
1027
- * Returns the revisions of the current global styles theme.
1028
- *
1029
- * @deprecated since WordPress 6.5.0. Callers should use `select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )` instead, where `recordKey` is the id of the global styles parent post.
1030
- *
1031
- * @param state Data state.
1032
- *
1033
- * @return The current global styles.
1034
- */
1035
- export function getCurrentThemeGlobalStylesRevisions(state) {
472
+ function getCurrentThemeGlobalStylesRevisions(state) {
1036
473
  deprecated("select( 'core' ).getCurrentThemeGlobalStylesRevisions()", {
1037
- since: '6.5.0',
474
+ since: "6.5.0",
1038
475
  alternative: "select( 'core' ).getRevisions( 'root', 'globalStyles', ${ recordKey } )"
1039
476
  });
1040
477
  const currentGlobalStylesId = __experimentalGetCurrentGlobalStylesId(state);
@@ -1043,87 +480,107 @@ export function getCurrentThemeGlobalStylesRevisions(state) {
1043
480
  }
1044
481
  return state.themeGlobalStyleRevisions[currentGlobalStylesId];
1045
482
  }
1046
-
1047
- /**
1048
- * Returns the default template use to render a given query.
1049
- *
1050
- * @param state Data state.
1051
- * @param query Query.
1052
- *
1053
- * @return The default template id for the given query.
1054
- */
1055
- export function getDefaultTemplateId(state, query) {
483
+ function getDefaultTemplateId(state, query) {
1056
484
  return state.defaultTemplates[JSON.stringify(query)];
1057
485
  }
1058
-
1059
- /**
1060
- * Returns an entity's revisions.
1061
- *
1062
- * @param state State tree
1063
- * @param kind Entity kind.
1064
- * @param name Entity name.
1065
- * @param recordKey The key of the entity record whose revisions you want to fetch.
1066
- * @param query Optional query. If requesting specific
1067
- * fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [Entity kind]".
1068
- *
1069
- * @return Record.
1070
- */
1071
- export const getRevisions = (state, kind, name, recordKey, query) => {
1072
- logEntityDeprecation(kind, name, 'getRevisions');
486
+ const getRevisions = (state, kind, name, recordKey, query) => {
487
+ logEntityDeprecation(kind, name, "getRevisions");
1073
488
  const queriedStateRevisions = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
1074
489
  if (!queriedStateRevisions) {
1075
490
  return null;
1076
491
  }
1077
492
  return getQueriedItems(queriedStateRevisions, query);
1078
493
  };
1079
-
1080
- /**
1081
- * Returns a single, specific revision of a parent entity.
1082
- *
1083
- * @param state State tree
1084
- * @param kind Entity kind.
1085
- * @param name Entity name.
1086
- * @param recordKey The key of the entity record whose revisions you want to fetch.
1087
- * @param revisionKey The revision's key.
1088
- * @param query Optional query. If requesting specific
1089
- * fields, fields must always include the ID. For valid query parameters see revisions schema in [the REST API Handbook](https://developer.wordpress.org/rest-api/reference/). Then see the arguments available "Retrieve a [entity kind]".
1090
- *
1091
- * @return Record.
1092
- */
1093
- export const getRevision = createSelector((state, kind, name, recordKey, revisionKey, query) => {
1094
- var _query$context6, _getNormalizedCommaSe3;
1095
- logEntityDeprecation(kind, name, 'getRevision');
1096
- const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
1097
- if (!queriedState) {
1098
- return undefined;
1099
- }
1100
- const context = (_query$context6 = query?.context) !== null && _query$context6 !== void 0 ? _query$context6 : 'default';
1101
- if (!query || !query._fields) {
1102
- // If expecting a complete item, validate that completeness.
1103
- if (!queriedState.itemIsComplete[context]?.[revisionKey]) {
1104
- return undefined;
494
+ const getRevision = createSelector(
495
+ (state, kind, name, recordKey, revisionKey, query) => {
496
+ logEntityDeprecation(kind, name, "getRevision");
497
+ const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
498
+ if (!queriedState) {
499
+ return void 0;
1105
500
  }
1106
- return queriedState.items[context][revisionKey];
1107
- }
1108
- const item = queriedState.items[context]?.[revisionKey];
1109
- if (!item) {
1110
- return item;
1111
- }
1112
- const filteredItem = {};
1113
- const fields = (_getNormalizedCommaSe3 = getNormalizedCommaSeparable(query._fields)) !== null && _getNormalizedCommaSe3 !== void 0 ? _getNormalizedCommaSe3 : [];
1114
- for (let f = 0; f < fields.length; f++) {
1115
- const field = fields[f].split('.');
1116
- let value = item;
1117
- field.forEach(fieldName => {
1118
- value = value?.[fieldName];
1119
- });
1120
- setNestedValue(filteredItem, field, value);
501
+ const context = query?.context ?? "default";
502
+ if (!query || !query._fields) {
503
+ if (!queriedState.itemIsComplete[context]?.[revisionKey]) {
504
+ return void 0;
505
+ }
506
+ return queriedState.items[context][revisionKey];
507
+ }
508
+ const item = queriedState.items[context]?.[revisionKey];
509
+ if (!item) {
510
+ return item;
511
+ }
512
+ const filteredItem = {};
513
+ const fields = getNormalizedCommaSeparable(query._fields) ?? [];
514
+ for (let f = 0; f < fields.length; f++) {
515
+ const field = fields[f].split(".");
516
+ let value = item;
517
+ field.forEach((fieldName) => {
518
+ value = value?.[fieldName];
519
+ });
520
+ setNestedValue(filteredItem, field, value);
521
+ }
522
+ return filteredItem;
523
+ },
524
+ (state, kind, name, recordKey, revisionKey, query) => {
525
+ const context = query?.context ?? "default";
526
+ const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
527
+ return [
528
+ queriedState?.items?.[context]?.[revisionKey],
529
+ queriedState?.itemIsComplete?.[context]?.[revisionKey]
530
+ ];
1121
531
  }
1122
- return filteredItem;
1123
- }, (state, kind, name, recordKey, revisionKey, query) => {
1124
- var _query$context7;
1125
- const context = (_query$context7 = query?.context) !== null && _query$context7 !== void 0 ? _query$context7 : 'default';
1126
- const queriedState = state.entities.records?.[kind]?.[name]?.revisions?.[recordKey];
1127
- return [queriedState?.items?.[context]?.[revisionKey], queriedState?.itemIsComplete?.[context]?.[revisionKey]];
1128
- });
1129
- //# sourceMappingURL=selectors.js.map
532
+ );
533
+ export {
534
+ __experimentalGetCurrentGlobalStylesId,
535
+ __experimentalGetCurrentThemeBaseGlobalStyles,
536
+ __experimentalGetCurrentThemeGlobalStylesVariations,
537
+ __experimentalGetDirtyEntityRecords,
538
+ __experimentalGetEntitiesBeingSaved,
539
+ __experimentalGetEntityRecordNoResolver,
540
+ canUser,
541
+ canUserEditEntityRecord,
542
+ getAuthors,
543
+ getAutosave,
544
+ getAutosaves,
545
+ getBlockPatternCategories,
546
+ getBlockPatterns,
547
+ getCurrentTheme,
548
+ getCurrentThemeGlobalStylesRevisions,
549
+ getCurrentUser,
550
+ getDefaultTemplateId,
551
+ getEditedEntityRecord,
552
+ getEmbedPreview,
553
+ getEntitiesByKind,
554
+ getEntitiesConfig,
555
+ getEntity,
556
+ getEntityConfig,
557
+ getEntityRecord,
558
+ getEntityRecordEdits,
559
+ getEntityRecordNonTransientEdits,
560
+ getEntityRecords,
561
+ getEntityRecordsTotalItems,
562
+ getEntityRecordsTotalPages,
563
+ getLastEntityDeleteError,
564
+ getLastEntitySaveError,
565
+ getRawEntityRecord,
566
+ getRedoEdit,
567
+ getReferenceByDistinctEdits,
568
+ getRevision,
569
+ getRevisions,
570
+ getThemeSupports,
571
+ getUndoEdit,
572
+ getUserPatternCategories,
573
+ getUserQueryResults,
574
+ hasEditsForEntityRecord,
575
+ hasEntityRecord,
576
+ hasEntityRecords,
577
+ hasFetchedAutosaves,
578
+ hasRedo,
579
+ hasUndo,
580
+ isAutosavingEntityRecord,
581
+ isDeletingEntityRecord,
582
+ isPreviewEmbedFallback,
583
+ isRequestingEmbedPreview,
584
+ isSavingEntityRecord
585
+ };
586
+ //# sourceMappingURL=selectors.js.map