@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,325 +1,370 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
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
+ var resolvers_exports = {};
30
+ __export(resolvers_exports, {
31
+ __experimentalGetCurrentGlobalStylesId: () => __experimentalGetCurrentGlobalStylesId,
32
+ __experimentalGetCurrentThemeBaseGlobalStyles: () => __experimentalGetCurrentThemeBaseGlobalStyles,
33
+ __experimentalGetCurrentThemeGlobalStylesVariations: () => __experimentalGetCurrentThemeGlobalStylesVariations,
34
+ canUser: () => canUser,
35
+ canUserEditEntityRecord: () => canUserEditEntityRecord,
36
+ getAuthors: () => getAuthors,
37
+ getAutosave: () => getAutosave,
38
+ getAutosaves: () => getAutosaves,
39
+ getBlockPatternCategories: () => getBlockPatternCategories,
40
+ getBlockPatterns: () => getBlockPatterns,
41
+ getCurrentTheme: () => getCurrentTheme,
42
+ getCurrentThemeGlobalStylesRevisions: () => getCurrentThemeGlobalStylesRevisions,
43
+ getCurrentUser: () => getCurrentUser,
44
+ getDefaultTemplateId: () => getDefaultTemplateId,
45
+ getEditedEntityRecord: () => getEditedEntityRecord,
46
+ getEmbedPreview: () => getEmbedPreview,
47
+ getEntitiesConfig: () => getEntitiesConfig,
48
+ getEntityRecord: () => getEntityRecord,
49
+ getEntityRecords: () => getEntityRecords,
50
+ getEntityRecordsTotalItems: () => getEntityRecordsTotalItems,
51
+ getEntityRecordsTotalPages: () => getEntityRecordsTotalPages,
52
+ getNavigationFallbackId: () => getNavigationFallbackId,
53
+ getRawEntityRecord: () => getRawEntityRecord,
54
+ getRegisteredPostMeta: () => getRegisteredPostMeta,
55
+ getRevision: () => getRevision,
56
+ getRevisions: () => getRevisions,
57
+ getTemplateAutoDraftId: () => getTemplateAutoDraftId,
58
+ getThemeSupports: () => getThemeSupports,
59
+ getUserPatternCategories: () => getUserPatternCategories
6
60
  });
7
- exports.getUserPatternCategories = exports.getThemeSupports = exports.getTemplateAutoDraftId = exports.getRevisions = exports.getRevision = exports.getRegisteredPostMeta = exports.getRawEntityRecord = exports.getNavigationFallbackId = exports.getEntityRecordsTotalPages = exports.getEntityRecordsTotalItems = exports.getEntityRecords = exports.getEntityRecord = exports.getEntitiesConfig = exports.getEmbedPreview = exports.getEditedEntityRecord = exports.getDefaultTemplateId = exports.getCurrentUser = exports.getCurrentThemeGlobalStylesRevisions = exports.getCurrentTheme = exports.getBlockPatterns = exports.getBlockPatternCategories = exports.getAutosaves = exports.getAutosave = exports.getAuthors = exports.canUserEditEntityRecord = exports.canUser = exports.__experimentalGetCurrentThemeGlobalStylesVariations = exports.__experimentalGetCurrentThemeBaseGlobalStyles = exports.__experimentalGetCurrentGlobalStylesId = void 0;
8
- var _changeCase = require("change-case");
9
- var _url = require("@wordpress/url");
10
- var _htmlEntities = require("@wordpress/html-entities");
11
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
12
- var _name = require("./name");
13
- var _entities = require("./entities");
14
- var _utils = require("./utils");
15
- var _sync = require("./sync");
16
- var _fetch = require("./fetch");
17
- /**
18
- * External dependencies
19
- */
20
-
21
- /**
22
- * WordPress dependencies
23
- */
24
-
25
- /**
26
- * Internal dependencies
27
- */
28
-
29
- /**
30
- * Requests authors from the REST API.
31
- *
32
- * @param {Object|undefined} query Optional object of query parameters to
33
- * include with request.
34
- */
35
- const getAuthors = query => async ({
36
- dispatch
37
- }) => {
38
- const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
39
- const users = await (0, _apiFetch.default)({
40
- path
41
- });
61
+ module.exports = __toCommonJS(resolvers_exports);
62
+ var import_change_case = require("change-case");
63
+ var import_url = require("@wordpress/url");
64
+ var import_html_entities = require("@wordpress/html-entities");
65
+ var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
66
+ var import_name = require("./name");
67
+ var import_entities = require("./entities");
68
+ var import_sync = require("./sync");
69
+ var import_utils = require("./utils");
70
+ var import_fetch = require("./fetch");
71
+ const getAuthors = (query) => async ({ dispatch }) => {
72
+ const path = (0, import_url.addQueryArgs)(
73
+ "/wp/v2/users/?who=authors&per_page=100",
74
+ query
75
+ );
76
+ const users = await (0, import_api_fetch.default)({ path });
42
77
  dispatch.receiveUserQuery(path, users);
43
78
  };
44
-
45
- /**
46
- * Requests the current user from the REST API.
47
- */
48
- exports.getAuthors = getAuthors;
49
- const getCurrentUser = () => async ({
50
- dispatch
51
- }) => {
52
- const currentUser = await (0, _apiFetch.default)({
53
- path: '/wp/v2/users/me'
54
- });
79
+ const getCurrentUser = () => async ({ dispatch }) => {
80
+ const currentUser = await (0, import_api_fetch.default)({ path: "/wp/v2/users/me" });
55
81
  dispatch.receiveCurrentUser(currentUser);
56
82
  };
57
-
58
- /**
59
- * Requests an entity's record from the REST API.
60
- *
61
- * @param {string} kind Entity kind.
62
- * @param {string} name Entity name.
63
- * @param {number|string} key Record's key
64
- * @param {Object|undefined} query Optional object of query parameters to
65
- * include with request. If requesting specific
66
- * fields, fields must always include the ID.
67
- */
68
- exports.getCurrentUser = getCurrentUser;
69
- const getEntityRecord = (kind, name, key = '', query) => async ({
70
- select,
71
- dispatch,
72
- registry,
73
- resolveSelect
74
- }) => {
75
- // For back-compat, we allow querying for static templates through
76
- // wp_template.
77
- if (kind === 'postType' && name === 'wp_template' && typeof key === 'string' &&
78
- // __experimentalGetDirtyEntityRecords always calls getEntityRecord
79
- // with a string key, so we need that it's not a numeric ID.
80
- !/^\d+$/.test(key)) {
81
- name = 'wp_registered_template';
82
- }
83
+ const getEntityRecord = (kind, name, key = "", query) => async ({ select, dispatch, registry, resolveSelect }) => {
83
84
  const configs = await resolveSelect.getEntitiesConfig(kind);
84
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
85
+ const entityConfig = configs.find(
86
+ (config) => config.name === name && config.kind === kind
87
+ );
85
88
  if (!entityConfig) {
86
89
  return;
87
90
  }
88
- const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name, key], {
89
- exclusive: false
90
- });
91
+ const lock = await dispatch.__unstableAcquireStoreLock(
92
+ import_name.STORE_NAME,
93
+ ["entities", "records", kind, name, key],
94
+ { exclusive: false }
95
+ );
91
96
  try {
92
- // Entity supports configs,
93
- // use the sync algorithm instead of the old fetch behavior.
97
+ if (query !== void 0 && query._fields) {
98
+ query = {
99
+ ...query,
100
+ _fields: [
101
+ .../* @__PURE__ */ new Set([
102
+ ...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
103
+ entityConfig.key || import_entities.DEFAULT_ENTITY_KEY
104
+ ])
105
+ ].join()
106
+ };
107
+ }
108
+ if (query !== void 0 && query._fields) {
109
+ const hasRecord = select.hasEntityRecord(
110
+ kind,
111
+ name,
112
+ key,
113
+ query
114
+ );
115
+ if (hasRecord) {
116
+ return;
117
+ }
118
+ }
119
+ let { baseURL } = entityConfig;
120
+ if (kind === "postType" && name === "wp_template" && key && typeof key === "string" && !/^\d+$/.test(key)) {
121
+ baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
122
+ }
123
+ const path = (0, import_url.addQueryArgs)(baseURL + (key ? "/" + key : ""), {
124
+ ...entityConfig.baseURLParams,
125
+ ...query
126
+ });
127
+ const response = await (0, import_api_fetch.default)({ path, parse: false });
128
+ const record = await response.json();
129
+ const permissions = (0, import_utils.getUserPermissionsFromAllowHeader)(
130
+ response.headers?.get("allow")
131
+ );
132
+ const canUserResolutionsArgs = [];
133
+ const receiveUserPermissionArgs = {};
134
+ for (const action of import_utils.ALLOWED_RESOURCE_ACTIONS) {
135
+ receiveUserPermissionArgs[(0, import_utils.getUserPermissionCacheKey)(action, {
136
+ kind,
137
+ name,
138
+ id: key
139
+ })] = permissions[action];
140
+ canUserResolutionsArgs.push([
141
+ action,
142
+ { kind, name, id: key }
143
+ ]);
144
+ }
94
145
  if (window.__experimentalEnableSync && entityConfig.syncConfig && !query) {
95
146
  if (globalThis.IS_GUTENBERG_PLUGIN) {
96
- const objectId = entityConfig.getSyncObjectId(key);
97
-
98
- // Loads the persisted document.
99
- await (0, _sync.getSyncProvider)().bootstrap(entityConfig.syncObjectType, objectId, record => {
100
- dispatch.receiveEntityRecords(kind, name, record, query);
101
- });
102
-
103
- // Bootstraps the edited document as well (and load from peers).
104
- await (0, _sync.getSyncProvider)().bootstrap(entityConfig.syncObjectType + '--edit', objectId, record => {
105
- dispatch({
106
- type: 'EDIT_ENTITY_RECORD',
107
- kind,
108
- name,
109
- recordId: key,
110
- edits: record,
111
- meta: {
112
- undo: undefined
113
- }
114
- });
147
+ const objectType = `${kind}/${name}`;
148
+ const objectId = key;
149
+ const recordWithTransients = { ...record };
150
+ Object.entries(entityConfig.transientEdits ?? {}).filter(
151
+ ([propName, transientConfig]) => void 0 === recordWithTransients[propName] && transientConfig && "object" === typeof transientConfig && "read" in transientConfig && "function" === typeof transientConfig.read
152
+ ).forEach(([propName, transientConfig]) => {
153
+ recordWithTransients[propName] = transientConfig.read(recordWithTransients);
115
154
  });
155
+ await import_sync.syncManager.load(
156
+ entityConfig.syncConfig,
157
+ objectType,
158
+ objectId,
159
+ recordWithTransients,
160
+ {
161
+ // Handle edits sourced from the sync manager.
162
+ editRecord: (edits) => {
163
+ if (!Object.keys(edits).length) {
164
+ return;
165
+ }
166
+ dispatch({
167
+ type: "EDIT_ENTITY_RECORD",
168
+ kind,
169
+ name,
170
+ recordId: key,
171
+ edits,
172
+ meta: {
173
+ undo: void 0
174
+ }
175
+ });
176
+ },
177
+ // Get the current entity record (with edits)
178
+ getEditedRecord: async () => await resolveSelect.getEditedEntityRecord(
179
+ kind,
180
+ name,
181
+ key
182
+ )
183
+ }
184
+ );
116
185
  }
117
- } else {
118
- if (query !== undefined && query._fields) {
119
- // If requesting specific fields, items and query association to said
120
- // records are stored by ID reference. Thus, fields must always include
121
- // the ID.
122
- query = {
123
- ...query,
124
- _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
125
- };
126
- }
127
- if (query !== undefined && query._fields) {
128
- // The resolution cache won't consider query as reusable based on the
129
- // fields, so it's tested here, prior to initiating the REST request,
130
- // and without causing `getEntityRecord` resolution to occur.
131
- const hasRecord = select.hasEntityRecord(kind, name, key, query);
132
- if (hasRecord) {
133
- return;
134
- }
135
- }
136
- const path = (0, _url.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), {
137
- ...entityConfig.baseURLParams,
138
- ...query
139
- });
140
- const response = await (0, _apiFetch.default)({
141
- path,
142
- parse: false
143
- });
144
- const record = await response.json();
145
- const permissions = (0, _utils.getUserPermissionsFromAllowHeader)(response.headers?.get('allow'));
146
- const canUserResolutionsArgs = [];
147
- const receiveUserPermissionArgs = {};
148
- for (const action of _utils.ALLOWED_RESOURCE_ACTIONS) {
149
- receiveUserPermissionArgs[(0, _utils.getUserPermissionCacheKey)(action, {
150
- kind,
151
- name,
152
- id: key
153
- })] = permissions[action];
154
- canUserResolutionsArgs.push([action, {
155
- kind,
156
- name,
157
- id: key
158
- }]);
159
- }
160
- registry.batch(() => {
161
- dispatch.receiveEntityRecords(kind, name, record, query);
162
- dispatch.receiveUserPermissions(receiveUserPermissionArgs);
163
- dispatch.finishResolutions('canUser', canUserResolutionsArgs);
164
- });
165
186
  }
187
+ registry.batch(() => {
188
+ dispatch.receiveEntityRecords(kind, name, record, query);
189
+ dispatch.receiveUserPermissions(receiveUserPermissionArgs);
190
+ dispatch.finishResolutions("canUser", canUserResolutionsArgs);
191
+ });
166
192
  } finally {
167
193
  dispatch.__unstableReleaseStoreLock(lock);
168
194
  }
169
195
  };
170
- exports.getEntityRecord = getEntityRecord;
171
- const getTemplateAutoDraftId = staticTemplateId => async ({
172
- resolveSelect,
173
- dispatch
174
- }) => {
175
- const record = await resolveSelect.getEntityRecord('postType', 'wp_registered_template', staticTemplateId);
176
- const autoDraft = await dispatch.saveEntityRecord('postType', 'wp_template', {
177
- ...record,
178
- id: undefined,
179
- type: 'wp_template',
180
- status: 'auto-draft'
181
- });
182
- await dispatch.receiveTemplateAutoDraftId(staticTemplateId, autoDraft.id);
196
+ getEntityRecord.shouldInvalidate = (action, kind, name) => {
197
+ return kind === "root" && name === "site" && (action.type === "RECEIVE_ITEMS" && // Making sure persistedEdits is set seems to be the only way of
198
+ // knowing whether it's an update or fetch. Only an update would
199
+ // have persistedEdits.
200
+ action.persistedEdits && action.persistedEdits.status !== "auto-draft" || action.type === "REMOVE_ITEMS") && action.kind === "postType" && action.name === "wp_template";
201
+ };
202
+ const getTemplateAutoDraftId = (staticTemplateId) => async ({ resolveSelect, dispatch }) => {
203
+ const record = await resolveSelect.getEntityRecord(
204
+ "postType",
205
+ "wp_registered_template",
206
+ staticTemplateId
207
+ );
208
+ const autoDraft = await dispatch.saveEntityRecord(
209
+ "postType",
210
+ "wp_template",
211
+ {
212
+ ...record,
213
+ id: void 0,
214
+ type: "wp_template",
215
+ status: "auto-draft"
216
+ }
217
+ );
218
+ await dispatch.receiveTemplateAutoDraftId(
219
+ staticTemplateId,
220
+ autoDraft.id
221
+ );
183
222
  };
184
-
185
- /**
186
- * Requests an entity's record from the REST API.
187
- */
188
- exports.getTemplateAutoDraftId = getTemplateAutoDraftId;
189
- const getRawEntityRecord = exports.getRawEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
190
-
191
- /**
192
- * Requests an entity's record from the REST API.
193
- */
194
- const getEditedEntityRecord = exports.getEditedEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
195
-
196
- /**
197
- * Requests the entity's records from the REST API.
198
- *
199
- * @param {string} kind Entity kind.
200
- * @param {string} name Entity name.
201
- * @param {?Object} query Query Object. If requesting specific fields, fields
202
- * must always include the ID.
203
- */
204
- const getEntityRecords = (kind, name, query = {}) => async ({
205
- dispatch,
206
- registry,
207
- resolveSelect
208
- }) => {
223
+ const getRawEntityRecord = (0, import_utils.forwardResolver)("getEntityRecord");
224
+ const getEditedEntityRecord = (0, import_utils.forwardResolver)("getEntityRecord");
225
+ const getEntityRecords = (kind, name, query = {}) => async ({ dispatch, registry, resolveSelect }) => {
209
226
  const configs = await resolveSelect.getEntitiesConfig(kind);
210
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
227
+ const entityConfig = configs.find(
228
+ (config) => config.name === name && config.kind === kind
229
+ );
211
230
  if (!entityConfig) {
212
231
  return;
213
232
  }
214
- const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name], {
215
- exclusive: false
216
- });
217
-
218
- // Keep a copy of the original query for later use in getResolutionsArgs.
219
- // The query object may be modified below (for example, when _fields is
220
- // specified), but we want to use the original query when marking
221
- // resolutions as finished.
222
- const rawQuery = {
223
- ...query
224
- };
225
- const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
233
+ const lock = await dispatch.__unstableAcquireStoreLock(
234
+ import_name.STORE_NAME,
235
+ ["entities", "records", kind, name],
236
+ { exclusive: false }
237
+ );
238
+ const rawQuery = { ...query };
239
+ const key = entityConfig.key || import_entities.DEFAULT_ENTITY_KEY;
226
240
  function getResolutionsArgs(records, recordsQuery) {
227
- const queryArgs = Object.fromEntries(Object.entries(recordsQuery).filter(([k, v]) => {
228
- return ['context', '_fields'].includes(k) && !!v;
229
- }));
230
- return records.filter(record => record?.[key]).map(record => [kind, name, record[key], Object.keys(queryArgs).length > 0 ? queryArgs : undefined]);
241
+ const queryArgs = Object.fromEntries(
242
+ Object.entries(recordsQuery).filter(([k, v]) => {
243
+ return ["context", "_fields"].includes(k) && !!v;
244
+ })
245
+ );
246
+ return records.filter((record) => record?.[key]).map((record) => [
247
+ kind,
248
+ name,
249
+ record[key],
250
+ Object.keys(queryArgs).length > 0 ? queryArgs : void 0
251
+ ]);
231
252
  }
232
253
  try {
233
254
  if (query._fields) {
234
- // If requesting specific fields, items and query association to said
235
- // records are stored by ID reference. Thus, fields must always include
236
- // the ID.
237
255
  query = {
238
256
  ...query,
239
- _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), key])].join()
257
+ _fields: [
258
+ .../* @__PURE__ */ new Set([
259
+ ...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
260
+ key
261
+ ])
262
+ ].join()
240
263
  };
241
264
  }
242
- const path = (0, _url.addQueryArgs)(entityConfig.baseURL, {
265
+ let { baseURL } = entityConfig;
266
+ const { combinedTemplates = true } = query;
267
+ if (kind === "postType" && name === "wp_template" && combinedTemplates) {
268
+ baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
269
+ }
270
+ const path = (0, import_url.addQueryArgs)(baseURL, {
243
271
  ...entityConfig.baseURLParams,
244
272
  ...query
245
273
  });
246
- let records = [],
247
- meta;
274
+ let records = [], meta;
248
275
  if (entityConfig.supportsPagination && query.per_page !== -1) {
249
- const response = await (0, _apiFetch.default)({
250
- path,
251
- parse: false
252
- });
276
+ const response = await (0, import_api_fetch.default)({ path, parse: false });
253
277
  records = Object.values(await response.json());
254
278
  meta = {
255
- totalItems: parseInt(response.headers.get('X-WP-Total')),
256
- totalPages: parseInt(response.headers.get('X-WP-TotalPages'))
279
+ totalItems: parseInt(
280
+ response.headers.get("X-WP-Total")
281
+ ),
282
+ totalPages: parseInt(
283
+ response.headers.get("X-WP-TotalPages")
284
+ )
257
285
  };
258
- } else if (query.per_page === -1 && query[_utils.RECEIVE_INTERMEDIATE_RESULTS] === true) {
286
+ } else if (query.per_page === -1 && query[import_utils.RECEIVE_INTERMEDIATE_RESULTS] === true) {
259
287
  let page = 1;
260
288
  let totalPages;
261
289
  do {
262
- const response = await (0, _apiFetch.default)({
263
- path: (0, _url.addQueryArgs)(path, {
264
- page,
265
- per_page: 100
266
- }),
290
+ const response = await (0, import_api_fetch.default)({
291
+ path: (0, import_url.addQueryArgs)(path, { page, per_page: 100 }),
267
292
  parse: false
268
293
  });
269
294
  const pageRecords = Object.values(await response.json());
270
- totalPages = parseInt(response.headers.get('X-WP-TotalPages'));
295
+ totalPages = parseInt(
296
+ response.headers.get("X-WP-TotalPages")
297
+ );
271
298
  if (!meta) {
272
299
  meta = {
273
- totalItems: parseInt(response.headers.get('X-WP-Total')),
300
+ totalItems: parseInt(
301
+ response.headers.get("X-WP-Total")
302
+ ),
274
303
  totalPages: 1
275
304
  };
276
305
  }
277
306
  records.push(...pageRecords);
278
307
  registry.batch(() => {
279
- dispatch.receiveEntityRecords(kind, name, records, query, false, undefined, meta);
280
- dispatch.finishResolutions('getEntityRecord', getResolutionsArgs(pageRecords, rawQuery));
308
+ dispatch.receiveEntityRecords(
309
+ kind,
310
+ name,
311
+ records,
312
+ query,
313
+ false,
314
+ void 0,
315
+ meta
316
+ );
317
+ dispatch.finishResolutions(
318
+ "getEntityRecord",
319
+ getResolutionsArgs(pageRecords, rawQuery)
320
+ );
281
321
  });
282
322
  page++;
283
323
  } while (page <= totalPages);
284
324
  } else {
285
- records = Object.values(await (0, _apiFetch.default)({
286
- path
287
- }));
325
+ records = Object.values(await (0, import_api_fetch.default)({ path }));
288
326
  meta = {
289
327
  totalItems: records.length,
290
328
  totalPages: 1
291
329
  };
292
330
  }
293
-
294
- // If we request fields but the result doesn't contain the fields,
295
- // explicitly set these fields as "undefined"
296
- // that way we consider the query "fulfilled".
297
331
  if (query._fields) {
298
- records = records.map(record => {
299
- query._fields.split(',').forEach(field => {
332
+ records = records.map((record) => {
333
+ query._fields.split(",").forEach((field) => {
300
334
  if (!record.hasOwnProperty(field)) {
301
- record[field] = undefined;
335
+ record[field] = void 0;
302
336
  }
303
337
  });
304
338
  return record;
305
339
  });
306
340
  }
307
341
  registry.batch(() => {
308
- dispatch.receiveEntityRecords(kind, name, records, query, false, undefined, meta);
309
- const targetHints = records.filter(record => !!record?.[key] && !!record?._links?.self?.[0]?.targetHints?.allow).map(record => ({
342
+ dispatch.receiveEntityRecords(
343
+ kind,
344
+ name,
345
+ records,
346
+ query,
347
+ false,
348
+ void 0,
349
+ meta
350
+ );
351
+ const targetHints = records.filter(
352
+ (record) => !!record?.[key] && !!record?._links?.self?.[0]?.targetHints?.allow
353
+ ).map((record) => ({
310
354
  id: record[key],
311
- permissions: (0, _utils.getUserPermissionsFromAllowHeader)(record._links.self[0].targetHints.allow)
355
+ permissions: (0, import_utils.getUserPermissionsFromAllowHeader)(
356
+ record._links.self[0].targetHints.allow
357
+ )
312
358
  }));
313
359
  const canUserResolutionsArgs = [];
314
360
  const receiveUserPermissionArgs = {};
315
361
  for (const targetHint of targetHints) {
316
- for (const action of _utils.ALLOWED_RESOURCE_ACTIONS) {
317
- canUserResolutionsArgs.push([action, {
318
- kind,
319
- name,
320
- id: targetHint.id
321
- }]);
322
- receiveUserPermissionArgs[(0, _utils.getUserPermissionCacheKey)(action, {
362
+ for (const action of import_utils.ALLOWED_RESOURCE_ACTIONS) {
363
+ canUserResolutionsArgs.push([
364
+ action,
365
+ { kind, name, id: targetHint.id }
366
+ ]);
367
+ receiveUserPermissionArgs[(0, import_utils.getUserPermissionCacheKey)(action, {
323
368
  kind,
324
369
  name,
325
370
  id: targetHint.id
@@ -327,327 +372,231 @@ const getEntityRecords = (kind, name, query = {}) => async ({
327
372
  }
328
373
  }
329
374
  if (targetHints.length > 0) {
330
- dispatch.receiveUserPermissions(receiveUserPermissionArgs);
331
- dispatch.finishResolutions('canUser', canUserResolutionsArgs);
375
+ dispatch.receiveUserPermissions(
376
+ receiveUserPermissionArgs
377
+ );
378
+ dispatch.finishResolutions(
379
+ "canUser",
380
+ canUserResolutionsArgs
381
+ );
332
382
  }
333
- dispatch.finishResolutions('getEntityRecord', getResolutionsArgs(records, rawQuery));
383
+ dispatch.finishResolutions(
384
+ "getEntityRecord",
385
+ getResolutionsArgs(records, rawQuery)
386
+ );
334
387
  dispatch.__unstableReleaseStoreLock(lock);
335
388
  });
336
389
  } catch (e) {
337
390
  dispatch.__unstableReleaseStoreLock(lock);
338
391
  }
339
392
  };
340
- exports.getEntityRecords = getEntityRecords;
341
393
  getEntityRecords.shouldInvalidate = (action, kind, name) => {
342
- return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name;
394
+ return (action.type === "RECEIVE_ITEMS" || action.type === "REMOVE_ITEMS") && action.invalidateCache && kind === action.kind && name === action.name;
343
395
  };
344
-
345
- /**
346
- * Requests the total number of entity records.
347
- */
348
- const getEntityRecordsTotalItems = exports.getEntityRecordsTotalItems = (0, _utils.forwardResolver)('getEntityRecords');
349
-
350
- /**
351
- * Requests the number of available pages for the given query.
352
- */
353
- const getEntityRecordsTotalPages = exports.getEntityRecordsTotalPages = (0, _utils.forwardResolver)('getEntityRecords');
354
-
355
- /**
356
- * Requests the current theme.
357
- */
358
- const getCurrentTheme = () => async ({
359
- dispatch,
360
- resolveSelect
361
- }) => {
362
- const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
363
- status: 'active'
364
- });
396
+ const getEntityRecordsTotalItems = (0, import_utils.forwardResolver)("getEntityRecords");
397
+ const getEntityRecordsTotalPages = (0, import_utils.forwardResolver)("getEntityRecords");
398
+ const getCurrentTheme = () => async ({ dispatch, resolveSelect }) => {
399
+ const activeThemes = await resolveSelect.getEntityRecords(
400
+ "root",
401
+ "theme",
402
+ { status: "active" }
403
+ );
365
404
  dispatch.receiveCurrentTheme(activeThemes[0]);
366
405
  };
367
-
368
- /**
369
- * Requests theme supports data from the index.
370
- */
371
- exports.getCurrentTheme = getCurrentTheme;
372
- const getThemeSupports = exports.getThemeSupports = (0, _utils.forwardResolver)('getCurrentTheme');
373
-
374
- /**
375
- * Requests a preview from the Embed API.
376
- *
377
- * @param {string} url URL to get the preview for.
378
- */
379
- const getEmbedPreview = url => async ({
380
- dispatch
381
- }) => {
406
+ const getThemeSupports = (0, import_utils.forwardResolver)("getCurrentTheme");
407
+ const getEmbedPreview = (url) => async ({ dispatch }) => {
382
408
  try {
383
- const embedProxyResponse = await (0, _apiFetch.default)({
384
- path: (0, _url.addQueryArgs)('/oembed/1.0/proxy', {
385
- url
386
- })
409
+ const embedProxyResponse = await (0, import_api_fetch.default)({
410
+ path: (0, import_url.addQueryArgs)("/oembed/1.0/proxy", { url })
387
411
  });
388
412
  dispatch.receiveEmbedPreview(url, embedProxyResponse);
389
413
  } catch (error) {
390
- // Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.
391
414
  dispatch.receiveEmbedPreview(url, false);
392
415
  }
393
416
  };
394
-
395
- /**
396
- * Checks whether the current user can perform the given action on the given
397
- * REST resource.
398
- *
399
- * @param {string} requestedAction Action to check. One of: 'create', 'read', 'update',
400
- * 'delete'.
401
- * @param {string|Object} resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
402
- * or REST base as a string - `media`.
403
- * @param {?string} id ID of the rest resource to check.
404
- */
405
- exports.getEmbedPreview = getEmbedPreview;
406
- const canUser = (requestedAction, resource, id) => async ({
407
- dispatch,
408
- registry,
409
- resolveSelect
410
- }) => {
411
- if (!_utils.ALLOWED_RESOURCE_ACTIONS.includes(requestedAction)) {
417
+ const canUser = (requestedAction, resource, id) => async ({ dispatch, registry, resolveSelect }) => {
418
+ if (!import_utils.ALLOWED_RESOURCE_ACTIONS.includes(requestedAction)) {
412
419
  throw new Error(`'${requestedAction}' is not a valid action.`);
413
420
  }
414
- const {
415
- hasStartedResolution
416
- } = registry.select(_name.STORE_NAME);
417
-
418
- // Prevent resolving the same resource twice.
419
- for (const relatedAction of _utils.ALLOWED_RESOURCE_ACTIONS) {
421
+ const { hasStartedResolution } = registry.select(import_name.STORE_NAME);
422
+ for (const relatedAction of import_utils.ALLOWED_RESOURCE_ACTIONS) {
420
423
  if (relatedAction === requestedAction) {
421
424
  continue;
422
425
  }
423
- const isAlreadyResolving = hasStartedResolution('canUser', [relatedAction, resource, id]);
426
+ const isAlreadyResolving = hasStartedResolution("canUser", [
427
+ relatedAction,
428
+ resource,
429
+ id
430
+ ]);
424
431
  if (isAlreadyResolving) {
425
432
  return;
426
433
  }
427
434
  }
428
435
  let resourcePath = null;
429
- if (typeof resource === 'object') {
436
+ if (typeof resource === "object") {
430
437
  if (!resource.kind || !resource.name) {
431
- throw new Error('The entity resource object is not valid.');
438
+ throw new Error("The entity resource object is not valid.");
432
439
  }
433
- const configs = await resolveSelect.getEntitiesConfig(resource.kind);
434
- const entityConfig = configs.find(config => config.name === resource.name && config.kind === resource.kind);
440
+ const configs = await resolveSelect.getEntitiesConfig(
441
+ resource.kind
442
+ );
443
+ const entityConfig = configs.find(
444
+ (config) => config.name === resource.name && config.kind === resource.kind
445
+ );
435
446
  if (!entityConfig) {
436
447
  return;
437
448
  }
438
- resourcePath = entityConfig.baseURL + (resource.id ? '/' + resource.id : '');
449
+ resourcePath = entityConfig.baseURL + (resource.id ? "/" + resource.id : "");
439
450
  } else {
440
- resourcePath = `/wp/v2/${resource}` + (id ? '/' + id : '');
451
+ resourcePath = `/wp/v2/${resource}` + (id ? "/" + id : "");
441
452
  }
442
453
  let response;
443
454
  try {
444
- response = await (0, _apiFetch.default)({
455
+ response = await (0, import_api_fetch.default)({
445
456
  path: resourcePath,
446
- method: 'OPTIONS',
457
+ method: "OPTIONS",
447
458
  parse: false
448
459
  });
449
460
  } catch (error) {
450
- // Do nothing if our OPTIONS request comes back with an API error (4xx or
451
- // 5xx). The previously determined isAllowed value will remain in the store.
452
461
  return;
453
462
  }
454
-
455
- // Optional chaining operator is used here because the API requests don't
456
- // return the expected result in the React native version. Instead, API requests
457
- // only return the result, without including response properties like the headers.
458
- const permissions = (0, _utils.getUserPermissionsFromAllowHeader)(response.headers?.get('allow'));
463
+ const permissions = (0, import_utils.getUserPermissionsFromAllowHeader)(
464
+ response.headers?.get("allow")
465
+ );
459
466
  registry.batch(() => {
460
- for (const action of _utils.ALLOWED_RESOURCE_ACTIONS) {
461
- const key = (0, _utils.getUserPermissionCacheKey)(action, resource, id);
467
+ for (const action of import_utils.ALLOWED_RESOURCE_ACTIONS) {
468
+ const key = (0, import_utils.getUserPermissionCacheKey)(action, resource, id);
462
469
  dispatch.receiveUserPermission(key, permissions[action]);
463
-
464
- // Mark related action resolutions as finished.
465
470
  if (action !== requestedAction) {
466
- dispatch.finishResolution('canUser', [action, resource, id]);
471
+ dispatch.finishResolution("canUser", [
472
+ action,
473
+ resource,
474
+ id
475
+ ]);
467
476
  }
468
477
  }
469
478
  });
470
479
  };
471
-
472
- /**
473
- * Checks whether the current user can perform the given action on the given
474
- * REST resource.
475
- *
476
- * @param {string} kind Entity kind.
477
- * @param {string} name Entity name.
478
- * @param {number|string} recordId Record's id.
479
- */
480
- exports.canUser = canUser;
481
- const canUserEditEntityRecord = (kind, name, recordId) => async ({
482
- dispatch
483
- }) => {
484
- await dispatch(canUser('update', {
485
- kind,
486
- name,
487
- id: recordId
488
- }));
480
+ const canUserEditEntityRecord = (kind, name, recordId) => async ({ dispatch }) => {
481
+ await dispatch(canUser("update", { kind, name, id: recordId }));
489
482
  };
490
-
491
- /**
492
- * Request autosave data from the REST API.
493
- *
494
- * @param {string} postType The type of the parent post.
495
- * @param {number} postId The id of the parent post.
496
- */
497
- exports.canUserEditEntityRecord = canUserEditEntityRecord;
498
- const getAutosaves = (postType, postId) => async ({
499
- dispatch,
500
- resolveSelect
501
- }) => {
483
+ const getAutosaves = (postType, postId) => async ({ dispatch, resolveSelect }) => {
502
484
  const {
503
485
  rest_base: restBase,
504
- rest_namespace: restNamespace = 'wp/v2',
486
+ rest_namespace: restNamespace = "wp/v2",
505
487
  supports
506
488
  } = await resolveSelect.getPostType(postType);
507
489
  if (!supports?.autosave) {
508
490
  return;
509
491
  }
510
- const autosaves = await (0, _apiFetch.default)({
492
+ const autosaves = await (0, import_api_fetch.default)({
511
493
  path: `/${restNamespace}/${restBase}/${postId}/autosaves?context=edit`
512
494
  });
513
495
  if (autosaves && autosaves.length) {
514
496
  dispatch.receiveAutosaves(postId, autosaves);
515
497
  }
516
498
  };
517
-
518
- /**
519
- * Request autosave data from the REST API.
520
- *
521
- * This resolver exists to ensure the underlying autosaves are fetched via
522
- * `getAutosaves` when a call to the `getAutosave` selector is made.
523
- *
524
- * @param {string} postType The type of the parent post.
525
- * @param {number} postId The id of the parent post.
526
- */
527
- exports.getAutosaves = getAutosaves;
528
- const getAutosave = (postType, postId) => async ({
529
- resolveSelect
530
- }) => {
499
+ const getAutosave = (postType, postId) => async ({ resolveSelect }) => {
531
500
  await resolveSelect.getAutosaves(postType, postId);
532
501
  };
533
- exports.getAutosave = getAutosave;
534
- const __experimentalGetCurrentGlobalStylesId = () => async ({
535
- dispatch,
536
- resolveSelect
537
- }) => {
538
- const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
539
- status: 'active'
540
- });
541
- const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href;
502
+ const __experimentalGetCurrentGlobalStylesId = () => async ({ dispatch, resolveSelect }) => {
503
+ const activeThemes = await resolveSelect.getEntityRecords(
504
+ "root",
505
+ "theme",
506
+ { status: "active" }
507
+ );
508
+ const globalStylesURL = activeThemes?.[0]?._links?.["wp:user-global-styles"]?.[0]?.href;
542
509
  if (!globalStylesURL) {
543
510
  return;
544
511
  }
545
-
546
- // Regex matches the ID at the end of a URL or immediately before
547
- // the query string.
548
512
  const matches = globalStylesURL.match(/\/(\d+)(?:\?|$)/);
549
513
  const id = matches ? Number(matches[1]) : null;
550
514
  if (id) {
551
515
  dispatch.__experimentalReceiveCurrentGlobalStylesId(id);
552
516
  }
553
517
  };
554
- exports.__experimentalGetCurrentGlobalStylesId = __experimentalGetCurrentGlobalStylesId;
555
- const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
556
- resolveSelect,
557
- dispatch
558
- }) => {
518
+ const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({ resolveSelect, dispatch }) => {
559
519
  const currentTheme = await resolveSelect.getCurrentTheme();
560
- // Please adjust the preloaded requests if this changes!
561
- const themeGlobalStyles = await (0, _apiFetch.default)({
520
+ const themeGlobalStyles = await (0, import_api_fetch.default)({
562
521
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}?context=view`
563
522
  });
564
- dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles);
523
+ dispatch.__experimentalReceiveThemeBaseGlobalStyles(
524
+ currentTheme.stylesheet,
525
+ themeGlobalStyles
526
+ );
565
527
  };
566
- exports.__experimentalGetCurrentThemeBaseGlobalStyles = __experimentalGetCurrentThemeBaseGlobalStyles;
567
- const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
568
- resolveSelect,
569
- dispatch
570
- }) => {
528
+ const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({ resolveSelect, dispatch }) => {
571
529
  const currentTheme = await resolveSelect.getCurrentTheme();
572
- // Please adjust the preloaded requests if this changes!
573
- const variations = await (0, _apiFetch.default)({
530
+ const variations = await (0, import_api_fetch.default)({
574
531
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations?context=view`
575
532
  });
576
- dispatch.__experimentalReceiveThemeGlobalStyleVariations(currentTheme.stylesheet, variations);
533
+ dispatch.__experimentalReceiveThemeGlobalStyleVariations(
534
+ currentTheme.stylesheet,
535
+ variations
536
+ );
577
537
  };
578
-
579
- /**
580
- * Fetches and returns the revisions of the current global styles theme.
581
- */
582
- exports.__experimentalGetCurrentThemeGlobalStylesVariations = __experimentalGetCurrentThemeGlobalStylesVariations;
583
- const getCurrentThemeGlobalStylesRevisions = () => async ({
584
- resolveSelect,
585
- dispatch
586
- }) => {
538
+ const getCurrentThemeGlobalStylesRevisions = () => async ({ resolveSelect, dispatch }) => {
587
539
  const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId();
588
- const record = globalStylesId ? await resolveSelect.getEntityRecord('root', 'globalStyles', globalStylesId) : undefined;
589
- const revisionsURL = record?._links?.['version-history']?.[0]?.href;
540
+ const record = globalStylesId ? await resolveSelect.getEntityRecord(
541
+ "root",
542
+ "globalStyles",
543
+ globalStylesId
544
+ ) : void 0;
545
+ const revisionsURL = record?._links?.["version-history"]?.[0]?.href;
590
546
  if (revisionsURL) {
591
- const resetRevisions = await (0, _apiFetch.default)({
547
+ const resetRevisions = await (0, import_api_fetch.default)({
592
548
  url: revisionsURL
593
549
  });
594
- const revisions = resetRevisions?.map(revision => Object.fromEntries(Object.entries(revision).map(([key, value]) => [(0, _changeCase.camelCase)(key), value])));
595
- dispatch.receiveThemeGlobalStyleRevisions(globalStylesId, revisions);
550
+ const revisions = resetRevisions?.map(
551
+ (revision) => Object.fromEntries(
552
+ Object.entries(revision).map(([key, value]) => [
553
+ (0, import_change_case.camelCase)(key),
554
+ value
555
+ ])
556
+ )
557
+ );
558
+ dispatch.receiveThemeGlobalStyleRevisions(
559
+ globalStylesId,
560
+ revisions
561
+ );
596
562
  }
597
563
  };
598
- exports.getCurrentThemeGlobalStylesRevisions = getCurrentThemeGlobalStylesRevisions;
599
- getCurrentThemeGlobalStylesRevisions.shouldInvalidate = action => {
600
- return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles';
564
+ getCurrentThemeGlobalStylesRevisions.shouldInvalidate = (action) => {
565
+ return action.type === "SAVE_ENTITY_RECORD_FINISH" && action.kind === "root" && !action.error && action.name === "globalStyles";
601
566
  };
602
- const getBlockPatterns = () => async ({
603
- dispatch
604
- }) => {
605
- const patterns = await (0, _fetch.fetchBlockPatterns)();
606
- dispatch({
607
- type: 'RECEIVE_BLOCK_PATTERNS',
608
- patterns
609
- });
567
+ const getBlockPatterns = () => async ({ dispatch }) => {
568
+ const patterns = await (0, import_fetch.fetchBlockPatterns)();
569
+ dispatch({ type: "RECEIVE_BLOCK_PATTERNS", patterns });
610
570
  };
611
- exports.getBlockPatterns = getBlockPatterns;
612
- const getBlockPatternCategories = () => async ({
613
- dispatch
614
- }) => {
615
- const categories = await (0, _apiFetch.default)({
616
- path: '/wp/v2/block-patterns/categories'
617
- });
618
- dispatch({
619
- type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES',
620
- categories
571
+ const getBlockPatternCategories = () => async ({ dispatch }) => {
572
+ const categories = await (0, import_api_fetch.default)({
573
+ path: "/wp/v2/block-patterns/categories"
621
574
  });
575
+ dispatch({ type: "RECEIVE_BLOCK_PATTERN_CATEGORIES", categories });
622
576
  };
623
- exports.getBlockPatternCategories = getBlockPatternCategories;
624
- const getUserPatternCategories = () => async ({
625
- dispatch,
626
- resolveSelect
627
- }) => {
628
- const patternCategories = await resolveSelect.getEntityRecords('taxonomy', 'wp_pattern_category', {
629
- per_page: -1,
630
- _fields: 'id,name,description,slug',
631
- context: 'view'
632
- });
633
- const mappedPatternCategories = patternCategories?.map(userCategory => ({
577
+ const getUserPatternCategories = () => async ({ dispatch, resolveSelect }) => {
578
+ const patternCategories = await resolveSelect.getEntityRecords(
579
+ "taxonomy",
580
+ "wp_pattern_category",
581
+ {
582
+ per_page: -1,
583
+ _fields: "id,name,description,slug",
584
+ context: "view"
585
+ }
586
+ );
587
+ const mappedPatternCategories = patternCategories?.map((userCategory) => ({
634
588
  ...userCategory,
635
- label: (0, _htmlEntities.decodeEntities)(userCategory.name),
589
+ label: (0, import_html_entities.decodeEntities)(userCategory.name),
636
590
  name: userCategory.slug
637
591
  })) || [];
638
592
  dispatch({
639
- type: 'RECEIVE_USER_PATTERN_CATEGORIES',
593
+ type: "RECEIVE_USER_PATTERN_CATEGORIES",
640
594
  patternCategories: mappedPatternCategories
641
595
  });
642
596
  };
643
- exports.getUserPatternCategories = getUserPatternCategories;
644
- const getNavigationFallbackId = () => async ({
645
- dispatch,
646
- select,
647
- registry
648
- }) => {
649
- const fallback = await (0, _apiFetch.default)({
650
- path: (0, _url.addQueryArgs)('/wp-block-editor/v1/navigation-fallback', {
597
+ const getNavigationFallbackId = () => async ({ dispatch, select, registry }) => {
598
+ const fallback = await (0, import_api_fetch.default)({
599
+ path: (0, import_url.addQueryArgs)("/wp-block-editor/v1/navigation-fallback", {
651
600
  _embed: true
652
601
  })
653
602
  });
@@ -657,212 +606,186 @@ const getNavigationFallbackId = () => async ({
657
606
  if (!record) {
658
607
  return;
659
608
  }
660
-
661
- // If the fallback is already in the store, don't invalidate navigation queries.
662
- // Otherwise, invalidate the cache for the scenario where there were no Navigation
663
- // posts in the state and the fallback created one.
664
- const existingFallbackEntityRecord = select.getEntityRecord('postType', 'wp_navigation', fallback.id);
609
+ const existingFallbackEntityRecord = select.getEntityRecord(
610
+ "postType",
611
+ "wp_navigation",
612
+ fallback.id
613
+ );
665
614
  const invalidateNavigationQueries = !existingFallbackEntityRecord;
666
- dispatch.receiveEntityRecords('postType', 'wp_navigation', record, undefined, invalidateNavigationQueries);
667
-
668
- // Resolve to avoid further network requests.
669
- dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback.id]);
615
+ dispatch.receiveEntityRecords(
616
+ "postType",
617
+ "wp_navigation",
618
+ record,
619
+ void 0,
620
+ invalidateNavigationQueries
621
+ );
622
+ dispatch.finishResolution("getEntityRecord", [
623
+ "postType",
624
+ "wp_navigation",
625
+ fallback.id
626
+ ]);
670
627
  });
671
628
  };
672
- exports.getNavigationFallbackId = getNavigationFallbackId;
673
- const getDefaultTemplateId = query => async ({
674
- dispatch,
675
- registry,
676
- resolveSelect
677
- }) => {
678
- const template = await (0, _apiFetch.default)({
679
- path: (0, _url.addQueryArgs)('/wp/v2/templates/lookup', query)
629
+ const getDefaultTemplateId = (query) => async ({ dispatch, registry, resolveSelect }) => {
630
+ const template = await (0, import_api_fetch.default)({
631
+ path: (0, import_url.addQueryArgs)("/wp/v2/templates/lookup", query)
680
632
  });
681
- // Wait for the the entities config to be loaded, otherwise receiving
682
- // the template as an entity will not work.
683
- await resolveSelect.getEntitiesConfig('postType');
633
+ await resolveSelect.getEntitiesConfig("postType");
684
634
  const id = template?.wp_id || template?.id;
685
- // Endpoint may return an empty object if no template is found.
686
635
  if (id) {
687
636
  template.id = id;
688
- template.type = typeof id === 'string' ? 'wp_registered_template' : 'wp_template';
637
+ template.type = typeof id === "string" ? "wp_registered_template" : "wp_template";
689
638
  registry.batch(() => {
690
639
  dispatch.receiveDefaultTemplateId(query, id);
691
- dispatch.receiveEntityRecords('postType', template.type, [template]);
692
- // Avoid further network requests.
693
- dispatch.finishResolution('getEntityRecord', ['postType', template.type, id]);
640
+ dispatch.receiveEntityRecords("postType", template.type, [
641
+ template
642
+ ]);
643
+ dispatch.finishResolution("getEntityRecord", [
644
+ "postType",
645
+ template.type,
646
+ id
647
+ ]);
694
648
  });
695
649
  }
696
650
  };
697
- exports.getDefaultTemplateId = getDefaultTemplateId;
698
- getDefaultTemplateId.shouldInvalidate = action => {
699
- return action.type === 'EDIT_ENTITY_RECORD' && action.kind === 'root' && action.name === 'site';
651
+ getDefaultTemplateId.shouldInvalidate = (action) => {
652
+ return action.type === "RECEIVE_ITEMS" && action.kind === "root" && action.name === "site";
700
653
  };
701
-
702
- /**
703
- * Requests an entity's revisions from the REST API.
704
- *
705
- * @param {string} kind Entity kind.
706
- * @param {string} name Entity name.
707
- * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.
708
- * @param {Object|undefined} query Optional object of query parameters to
709
- * include with request. If requesting specific
710
- * fields, fields must always include the ID.
711
- */
712
- const getRevisions = (kind, name, recordKey, query = {}) => async ({
713
- dispatch,
714
- registry,
715
- resolveSelect
716
- }) => {
654
+ const getRevisions = (kind, name, recordKey, query = {}) => async ({ dispatch, registry, resolveSelect }) => {
717
655
  const configs = await resolveSelect.getEntitiesConfig(kind);
718
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
656
+ const entityConfig = configs.find(
657
+ (config) => config.name === name && config.kind === kind
658
+ );
719
659
  if (!entityConfig) {
720
660
  return;
721
661
  }
722
662
  if (query._fields) {
723
- // If requesting specific fields, items and query association to said
724
- // records are stored by ID reference. Thus, fields must always include
725
- // the ID.
726
663
  query = {
727
664
  ...query,
728
- _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.revisionKey || _entities.DEFAULT_ENTITY_KEY])].join()
665
+ _fields: [
666
+ .../* @__PURE__ */ new Set([
667
+ ...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
668
+ entityConfig.revisionKey || import_entities.DEFAULT_ENTITY_KEY
669
+ ])
670
+ ].join()
729
671
  };
730
672
  }
731
- const path = (0, _url.addQueryArgs)(entityConfig.getRevisionsUrl(recordKey), query);
673
+ const path = (0, import_url.addQueryArgs)(
674
+ entityConfig.getRevisionsUrl(recordKey),
675
+ query
676
+ );
732
677
  let records, response;
733
678
  const meta = {};
734
679
  const isPaginated = entityConfig.supportsPagination && query.per_page !== -1;
735
680
  try {
736
- response = await (0, _apiFetch.default)({
737
- path,
738
- parse: !isPaginated
739
- });
681
+ response = await (0, import_api_fetch.default)({ path, parse: !isPaginated });
740
682
  } catch (error) {
741
- // Do nothing if our request comes back with an API error.
742
683
  return;
743
684
  }
744
685
  if (response) {
745
686
  if (isPaginated) {
746
687
  records = Object.values(await response.json());
747
- meta.totalItems = parseInt(response.headers.get('X-WP-Total'));
688
+ meta.totalItems = parseInt(
689
+ response.headers.get("X-WP-Total")
690
+ );
748
691
  } else {
749
692
  records = Object.values(response);
750
693
  }
751
-
752
- // If we request fields but the result doesn't contain the fields,
753
- // explicitly set these fields as "undefined"
754
- // that way we consider the query "fulfilled".
755
694
  if (query._fields) {
756
- records = records.map(record => {
757
- query._fields.split(',').forEach(field => {
695
+ records = records.map((record) => {
696
+ query._fields.split(",").forEach((field) => {
758
697
  if (!record.hasOwnProperty(field)) {
759
- record[field] = undefined;
698
+ record[field] = void 0;
760
699
  }
761
700
  });
762
701
  return record;
763
702
  });
764
703
  }
765
704
  registry.batch(() => {
766
- dispatch.receiveRevisions(kind, name, recordKey, records, query, false, meta);
767
-
768
- // When requesting all fields, the list of results can be used to
769
- // resolve the `getRevision` selector in addition to `getRevisions`.
705
+ dispatch.receiveRevisions(
706
+ kind,
707
+ name,
708
+ recordKey,
709
+ records,
710
+ query,
711
+ false,
712
+ meta
713
+ );
770
714
  if (!query?._fields && !query.context) {
771
- const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
772
- const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, recordKey, record[key]]);
773
- dispatch.finishResolutions('getRevision', resolutionsArgs);
715
+ const key = entityConfig.key || import_entities.DEFAULT_ENTITY_KEY;
716
+ const resolutionsArgs = records.filter((record) => record[key]).map((record) => [
717
+ kind,
718
+ name,
719
+ recordKey,
720
+ record[key]
721
+ ]);
722
+ dispatch.finishResolutions(
723
+ "getRevision",
724
+ resolutionsArgs
725
+ );
774
726
  }
775
727
  });
776
728
  }
777
729
  };
778
-
779
- // Invalidate cache when a new revision is created.
780
- exports.getRevisions = getRevisions;
781
- getRevisions.shouldInvalidate = (action, kind, name, recordKey) => action.type === 'SAVE_ENTITY_RECORD_FINISH' && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId;
782
-
783
- /**
784
- * Requests a specific Entity revision from the REST API.
785
- *
786
- * @param {string} kind Entity kind.
787
- * @param {string} name Entity name.
788
- * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.
789
- * @param {number|string} revisionKey The revision's key.
790
- * @param {Object|undefined} query Optional object of query parameters to
791
- * include with request. If requesting specific
792
- * fields, fields must always include the ID.
793
- */
794
- const getRevision = (kind, name, recordKey, revisionKey, query) => async ({
795
- dispatch,
796
- resolveSelect
797
- }) => {
730
+ getRevisions.shouldInvalidate = (action, kind, name, recordKey) => action.type === "SAVE_ENTITY_RECORD_FINISH" && name === action.name && kind === action.kind && !action.error && recordKey === action.recordId;
731
+ const getRevision = (kind, name, recordKey, revisionKey, query) => async ({ dispatch, resolveSelect }) => {
798
732
  const configs = await resolveSelect.getEntitiesConfig(kind);
799
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
733
+ const entityConfig = configs.find(
734
+ (config) => config.name === name && config.kind === kind
735
+ );
800
736
  if (!entityConfig) {
801
737
  return;
802
738
  }
803
- if (query !== undefined && query._fields) {
804
- // If requesting specific fields, items and query association to said
805
- // records are stored by ID reference. Thus, fields must always include
806
- // the ID.
739
+ if (query !== void 0 && query._fields) {
807
740
  query = {
808
741
  ...query,
809
- _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.revisionKey || _entities.DEFAULT_ENTITY_KEY])].join()
742
+ _fields: [
743
+ .../* @__PURE__ */ new Set([
744
+ ...(0, import_utils.getNormalizedCommaSeparable)(query._fields) || [],
745
+ entityConfig.revisionKey || import_entities.DEFAULT_ENTITY_KEY
746
+ ])
747
+ ].join()
810
748
  };
811
749
  }
812
- const path = (0, _url.addQueryArgs)(entityConfig.getRevisionsUrl(recordKey, revisionKey), query);
750
+ const path = (0, import_url.addQueryArgs)(
751
+ entityConfig.getRevisionsUrl(recordKey, revisionKey),
752
+ query
753
+ );
813
754
  let record;
814
755
  try {
815
- record = await (0, _apiFetch.default)({
816
- path
817
- });
756
+ record = await (0, import_api_fetch.default)({ path });
818
757
  } catch (error) {
819
- // Do nothing if our request comes back with an API error.
820
758
  return;
821
759
  }
822
760
  if (record) {
823
761
  dispatch.receiveRevisions(kind, name, recordKey, record, query);
824
762
  }
825
763
  };
826
-
827
- /**
828
- * Requests a specific post type options from the REST API.
829
- *
830
- * @param {string} postType Post type slug.
831
- */
832
- exports.getRevision = getRevision;
833
- const getRegisteredPostMeta = postType => async ({
834
- dispatch,
835
- resolveSelect
836
- }) => {
764
+ const getRegisteredPostMeta = (postType) => async ({ dispatch, resolveSelect }) => {
837
765
  let options;
838
766
  try {
839
767
  const {
840
- rest_namespace: restNamespace = 'wp/v2',
768
+ rest_namespace: restNamespace = "wp/v2",
841
769
  rest_base: restBase
842
- } = (await resolveSelect.getPostType(postType)) || {};
843
- options = await (0, _apiFetch.default)({
770
+ } = await resolveSelect.getPostType(postType) || {};
771
+ options = await (0, import_api_fetch.default)({
844
772
  path: `${restNamespace}/${restBase}/?context=edit`,
845
- method: 'OPTIONS'
773
+ method: "OPTIONS"
846
774
  });
847
775
  } catch (error) {
848
- // Do nothing if the request comes back with an API error.
849
776
  return;
850
777
  }
851
778
  if (options) {
852
- dispatch.receiveRegisteredPostMeta(postType, options?.schema?.properties?.meta?.properties);
779
+ dispatch.receiveRegisteredPostMeta(
780
+ postType,
781
+ options?.schema?.properties?.meta?.properties
782
+ );
853
783
  }
854
784
  };
855
-
856
- /**
857
- * Requests entity configs for the given kind from the REST API.
858
- *
859
- * @param {string} kind Entity kind.
860
- */
861
- exports.getRegisteredPostMeta = getRegisteredPostMeta;
862
- const getEntitiesConfig = kind => async ({
863
- dispatch
864
- }) => {
865
- const loader = _entities.additionalEntityConfigLoaders.find(l => l.kind === kind);
785
+ const getEntitiesConfig = (kind) => async ({ dispatch }) => {
786
+ const loader = import_entities.additionalEntityConfigLoaders.find(
787
+ (l) => l.kind === kind
788
+ );
866
789
  if (!loader) {
867
790
  return;
868
791
  }
@@ -873,8 +796,38 @@ const getEntitiesConfig = kind => async ({
873
796
  }
874
797
  dispatch.addEntities(configs);
875
798
  } catch {
876
- // Do nothing if the request comes back with an API error.
877
799
  }
878
800
  };
879
- exports.getEntitiesConfig = getEntitiesConfig;
880
- //# sourceMappingURL=resolvers.js.map
801
+ // Annotate the CommonJS export names for ESM import in node:
802
+ 0 && (module.exports = {
803
+ __experimentalGetCurrentGlobalStylesId,
804
+ __experimentalGetCurrentThemeBaseGlobalStyles,
805
+ __experimentalGetCurrentThemeGlobalStylesVariations,
806
+ canUser,
807
+ canUserEditEntityRecord,
808
+ getAuthors,
809
+ getAutosave,
810
+ getAutosaves,
811
+ getBlockPatternCategories,
812
+ getBlockPatterns,
813
+ getCurrentTheme,
814
+ getCurrentThemeGlobalStylesRevisions,
815
+ getCurrentUser,
816
+ getDefaultTemplateId,
817
+ getEditedEntityRecord,
818
+ getEmbedPreview,
819
+ getEntitiesConfig,
820
+ getEntityRecord,
821
+ getEntityRecords,
822
+ getEntityRecordsTotalItems,
823
+ getEntityRecordsTotalPages,
824
+ getNavigationFallbackId,
825
+ getRawEntityRecord,
826
+ getRegisteredPostMeta,
827
+ getRevision,
828
+ getRevisions,
829
+ getTemplateAutoDraftId,
830
+ getThemeSupports,
831
+ getUserPatternCategories
832
+ });
833
+ //# sourceMappingURL=resolvers.js.map