@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,105 +1,44 @@
1
- /**
2
- * External dependencies
3
- */
4
- import fastDeepEqual from 'fast-deep-equal/es6';
5
- import { v4 as uuid } from 'uuid';
6
-
7
- /**
8
- * WordPress dependencies
9
- */
10
- import apiFetch from '@wordpress/api-fetch';
11
- import { addQueryArgs } from '@wordpress/url';
12
- import deprecated from '@wordpress/deprecated';
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
- import { getNestedValue, setNestedValue } from './utils';
18
- import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
19
- import { DEFAULT_ENTITY_KEY } from './entities';
20
- import { createBatch } from './batch';
21
- import { STORE_NAME } from './name';
22
- import { getSyncProvider } from './sync';
23
- import logEntityDeprecation from './utils/log-entity-deprecation';
24
-
25
- /**
26
- * Returns an action object used in signalling that authors have been received.
27
- * Ignored from documentation as it's internal to the data store.
28
- *
29
- * @ignore
30
- *
31
- * @param {string} queryID Query ID.
32
- * @param {Array|Object} users Users received.
33
- *
34
- * @return {Object} Action object.
35
- */
36
- export function receiveUserQuery(queryID, users) {
1
+ import fastDeepEqual from "fast-deep-equal/es6";
2
+ import { v4 as uuid } from "uuid";
3
+ import apiFetch from "@wordpress/api-fetch";
4
+ import { addQueryArgs } from "@wordpress/url";
5
+ import deprecated from "@wordpress/deprecated";
6
+ import { getNestedValue, setNestedValue } from "./utils";
7
+ import { receiveItems, removeItems, receiveQueriedItems } from "./queried-data";
8
+ import { DEFAULT_ENTITY_KEY } from "./entities";
9
+ import { createBatch } from "./batch";
10
+ import { STORE_NAME } from "./name";
11
+ import { LOCAL_EDITOR_ORIGIN, syncManager } from "./sync";
12
+ import logEntityDeprecation from "./utils/log-entity-deprecation";
13
+ function receiveUserQuery(queryID, users) {
37
14
  return {
38
- type: 'RECEIVE_USER_QUERY',
15
+ type: "RECEIVE_USER_QUERY",
39
16
  users: Array.isArray(users) ? users : [users],
40
17
  queryID
41
18
  };
42
19
  }
43
-
44
- /**
45
- * Returns an action used in signalling that the current user has been received.
46
- * Ignored from documentation as it's internal to the data store.
47
- *
48
- * @ignore
49
- *
50
- * @param {Object} currentUser Current user object.
51
- *
52
- * @return {Object} Action object.
53
- */
54
- export function receiveCurrentUser(currentUser) {
20
+ function receiveCurrentUser(currentUser) {
55
21
  return {
56
- type: 'RECEIVE_CURRENT_USER',
22
+ type: "RECEIVE_CURRENT_USER",
57
23
  currentUser
58
24
  };
59
25
  }
60
-
61
- /**
62
- * Returns an action object used in adding new entities.
63
- *
64
- * @param {Array} entities Entities received.
65
- *
66
- * @return {Object} Action object.
67
- */
68
- export function addEntities(entities) {
26
+ function addEntities(entities) {
69
27
  return {
70
- type: 'ADD_ENTITIES',
28
+ type: "ADD_ENTITIES",
71
29
  entities
72
30
  };
73
31
  }
74
-
75
- /**
76
- * Returns an action object used in signalling that entity records have been received.
77
- *
78
- * @param {string} kind Kind of the received entity record.
79
- * @param {string} name Name of the received entity record.
80
- * @param {Array|Object} records Records received.
81
- * @param {?Object} query Query Object.
82
- * @param {?boolean} invalidateCache Should invalidate query caches.
83
- * @param {?Object} edits Edits to reset.
84
- * @param {?Object} meta Meta information about pagination.
85
- * @return {Object} Action object.
86
- */
87
- export function receiveEntityRecords(kind, name, records, query, invalidateCache = false, edits, meta) {
88
- // If we receive an auto-draft template, pretend it's already published.
89
- if (kind === 'postType' && name === 'wp_template') {
90
- records = (Array.isArray(records) ? records : [records]).map(record => record.status === 'auto-draft' ? {
91
- ...record,
92
- status: 'publish'
93
- } : record);
32
+ function receiveEntityRecords(kind, name, records, query, invalidateCache = false, edits, meta) {
33
+ if (kind === "postType" && name === "wp_template") {
34
+ records = (Array.isArray(records) ? records : [records]).map(
35
+ (record) => record.status === "auto-draft" ? { ...record, status: "publish" } : record
36
+ );
94
37
  }
95
-
96
- // Auto drafts should not have titles, but some plugins rely on them so we can't filter this
97
- // on the server.
98
- if (kind === 'postType') {
99
- records = (Array.isArray(records) ? records : [records]).map(record => record.status === 'auto-draft' ? {
100
- ...record,
101
- title: ''
102
- } : record);
38
+ if (kind === "postType") {
39
+ records = (Array.isArray(records) ? records : [records]).map(
40
+ (record) => record.status === "auto-draft" ? { ...record, title: "" } : record
41
+ );
103
42
  }
104
43
  let action;
105
44
  if (query) {
@@ -114,189 +53,97 @@ export function receiveEntityRecords(kind, name, records, query, invalidateCache
114
53
  invalidateCache
115
54
  };
116
55
  }
117
-
118
- /**
119
- * Returns an action object used in signalling that the current theme has been received.
120
- * Ignored from documentation as it's internal to the data store.
121
- *
122
- * @ignore
123
- *
124
- * @param {Object} currentTheme The current theme.
125
- *
126
- * @return {Object} Action object.
127
- */
128
- export function receiveCurrentTheme(currentTheme) {
56
+ function receiveCurrentTheme(currentTheme) {
129
57
  return {
130
- type: 'RECEIVE_CURRENT_THEME',
58
+ type: "RECEIVE_CURRENT_THEME",
131
59
  currentTheme
132
60
  };
133
61
  }
134
-
135
- /**
136
- * Returns an action object used in signalling that the current global styles id has been received.
137
- * Ignored from documentation as it's internal to the data store.
138
- *
139
- * @ignore
140
- *
141
- * @param {string} currentGlobalStylesId The current global styles id.
142
- *
143
- * @return {Object} Action object.
144
- */
145
- export function __experimentalReceiveCurrentGlobalStylesId(currentGlobalStylesId) {
62
+ function __experimentalReceiveCurrentGlobalStylesId(currentGlobalStylesId) {
146
63
  return {
147
- type: 'RECEIVE_CURRENT_GLOBAL_STYLES_ID',
64
+ type: "RECEIVE_CURRENT_GLOBAL_STYLES_ID",
148
65
  id: currentGlobalStylesId
149
66
  };
150
67
  }
151
-
152
- /**
153
- * Returns an action object used in signalling that the theme base global styles have been received
154
- * Ignored from documentation as it's internal to the data store.
155
- *
156
- * @ignore
157
- *
158
- * @param {string} stylesheet The theme's identifier
159
- * @param {Object} globalStyles The global styles object.
160
- *
161
- * @return {Object} Action object.
162
- */
163
- export function __experimentalReceiveThemeBaseGlobalStyles(stylesheet, globalStyles) {
68
+ function __experimentalReceiveThemeBaseGlobalStyles(stylesheet, globalStyles) {
164
69
  return {
165
- type: 'RECEIVE_THEME_GLOBAL_STYLES',
70
+ type: "RECEIVE_THEME_GLOBAL_STYLES",
166
71
  stylesheet,
167
72
  globalStyles
168
73
  };
169
74
  }
170
-
171
- /**
172
- * Returns an action object used in signalling that the theme global styles variations have been received.
173
- * Ignored from documentation as it's internal to the data store.
174
- *
175
- * @ignore
176
- *
177
- * @param {string} stylesheet The theme's identifier
178
- * @param {Array} variations The global styles variations.
179
- *
180
- * @return {Object} Action object.
181
- */
182
- export function __experimentalReceiveThemeGlobalStyleVariations(stylesheet, variations) {
75
+ function __experimentalReceiveThemeGlobalStyleVariations(stylesheet, variations) {
183
76
  return {
184
- type: 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS',
77
+ type: "RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS",
185
78
  stylesheet,
186
79
  variations
187
80
  };
188
81
  }
189
-
190
- /**
191
- * Returns an action object used in signalling that the index has been received.
192
- *
193
- * @deprecated since WP 5.9, this is not useful anymore, use the selector directly.
194
- *
195
- * @return {Object} Action object.
196
- */
197
- export function receiveThemeSupports() {
82
+ function receiveThemeSupports() {
198
83
  deprecated("wp.data.dispatch( 'core' ).receiveThemeSupports", {
199
- since: '5.9'
84
+ since: "5.9"
200
85
  });
201
86
  return {
202
- type: 'DO_NOTHING'
87
+ type: "DO_NOTHING"
203
88
  };
204
89
  }
205
-
206
- /**
207
- * Returns an action object used in signalling that the theme global styles CPT post revisions have been received.
208
- * Ignored from documentation as it's internal to the data store.
209
- *
210
- * @deprecated since WordPress 6.5.0. Callers should use `dispatch( 'core' ).receiveRevision` instead.
211
- *
212
- * @ignore
213
- *
214
- * @param {number} currentId The post id.
215
- * @param {Array} revisions The global styles revisions.
216
- *
217
- * @return {Object} Action object.
218
- */
219
- export function receiveThemeGlobalStyleRevisions(currentId, revisions) {
220
- deprecated("wp.data.dispatch( 'core' ).receiveThemeGlobalStyleRevisions()", {
221
- since: '6.5.0',
222
- alternative: "wp.data.dispatch( 'core' ).receiveRevisions"
223
- });
90
+ function receiveThemeGlobalStyleRevisions(currentId, revisions) {
91
+ deprecated(
92
+ "wp.data.dispatch( 'core' ).receiveThemeGlobalStyleRevisions()",
93
+ {
94
+ since: "6.5.0",
95
+ alternative: "wp.data.dispatch( 'core' ).receiveRevisions"
96
+ }
97
+ );
224
98
  return {
225
- type: 'RECEIVE_THEME_GLOBAL_STYLE_REVISIONS',
99
+ type: "RECEIVE_THEME_GLOBAL_STYLE_REVISIONS",
226
100
  currentId,
227
101
  revisions
228
102
  };
229
103
  }
230
-
231
- /**
232
- * Returns an action object used in signalling that the preview data for
233
- * a given URl has been received.
234
- * Ignored from documentation as it's internal to the data store.
235
- *
236
- * @ignore
237
- *
238
- * @param {string} url URL to preview the embed for.
239
- * @param {*} preview Preview data.
240
- *
241
- * @return {Object} Action object.
242
- */
243
- export function receiveEmbedPreview(url, preview) {
104
+ function receiveEmbedPreview(url, preview) {
244
105
  return {
245
- type: 'RECEIVE_EMBED_PREVIEW',
106
+ type: "RECEIVE_EMBED_PREVIEW",
246
107
  url,
247
108
  preview
248
109
  };
249
110
  }
250
-
251
- /**
252
- * Action triggered to delete an entity record.
253
- *
254
- * @param {string} kind Kind of the deleted entity.
255
- * @param {string} name Name of the deleted entity.
256
- * @param {number|string} recordId Record ID of the deleted entity.
257
- * @param {?Object} query Special query parameters for the
258
- * DELETE API call.
259
- * @param {Object} [options] Delete options.
260
- * @param {Function} [options.__unstableFetch] Internal use only. Function to
261
- * call instead of `apiFetch()`.
262
- * Must return a promise.
263
- * @param {boolean} [options.throwOnError=false] If false, this action suppresses all
264
- * the exceptions. Defaults to false.
265
- */
266
- export const deleteEntityRecord = (kind, name, recordId, query, {
267
- __unstableFetch = apiFetch,
268
- throwOnError = false
269
- } = {}) => async ({
270
- dispatch,
271
- resolveSelect
272
- }) => {
273
- logEntityDeprecation(kind, name, 'deleteEntityRecord');
111
+ const deleteEntityRecord = (kind, name, recordId, query, { __unstableFetch = apiFetch, throwOnError = false } = {}) => async ({ dispatch, resolveSelect }) => {
112
+ logEntityDeprecation(kind, name, "deleteEntityRecord");
274
113
  const configs = await resolveSelect.getEntitiesConfig(kind);
275
- const entityConfig = configs.find(config => config.kind === kind && config.name === name);
114
+ const entityConfig = configs.find(
115
+ (config) => config.kind === kind && config.name === name
116
+ );
276
117
  let error;
277
118
  let deletedRecord = false;
278
119
  if (!entityConfig) {
279
120
  return;
280
121
  }
281
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId], {
282
- exclusive: true
283
- });
122
+ const lock = await dispatch.__unstableAcquireStoreLock(
123
+ STORE_NAME,
124
+ ["entities", "records", kind, name, recordId],
125
+ { exclusive: true }
126
+ );
284
127
  try {
285
128
  dispatch({
286
- type: 'DELETE_ENTITY_RECORD_START',
129
+ type: "DELETE_ENTITY_RECORD_START",
287
130
  kind,
288
131
  name,
289
132
  recordId
290
133
  });
291
134
  let hasError = false;
135
+ let { baseURL } = entityConfig;
136
+ if (kind === "postType" && name === "wp_template" && recordId && typeof recordId === "string" && !/^\d+$/.test(recordId)) {
137
+ baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
138
+ }
292
139
  try {
293
- let path = `${entityConfig.baseURL}/${recordId}`;
140
+ let path = `${baseURL}/${recordId}`;
294
141
  if (query) {
295
142
  path = addQueryArgs(path, query);
296
143
  }
297
144
  deletedRecord = await __unstableFetch({
298
145
  path,
299
- method: 'DELETE'
146
+ method: "DELETE"
300
147
  });
301
148
  await dispatch(removeItems(kind, name, recordId, true));
302
149
  } catch (_error) {
@@ -304,7 +151,7 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
304
151
  error = _error;
305
152
  }
306
153
  dispatch({
307
- type: 'DELETE_ENTITY_RECORD_FINISH',
154
+ type: "DELETE_ENTITY_RECORD_FINISH",
308
155
  kind,
309
156
  name,
310
157
  recordId,
@@ -318,34 +165,21 @@ export const deleteEntityRecord = (kind, name, recordId, query, {
318
165
  dispatch.__unstableReleaseStoreLock(lock);
319
166
  }
320
167
  };
321
-
322
- /**
323
- * Returns an action object that triggers an
324
- * edit to an entity record.
325
- *
326
- * @param {string} kind Kind of the edited entity record.
327
- * @param {string} name Name of the edited entity record.
328
- * @param {number|string} recordId Record ID of the edited entity record.
329
- * @param {Object} edits The edits.
330
- * @param {Object} options Options for the edit.
331
- * @param {boolean} [options.undoIgnore] Whether to ignore the edit in undo history or not.
332
- *
333
- * @return {Object} Action object.
334
- */
335
- export const editEntityRecord = (kind, name, recordId, edits, options = {}) => ({
336
- select,
337
- dispatch
338
- }) => {
339
- logEntityDeprecation(kind, name, 'editEntityRecord');
168
+ const editEntityRecord = (kind, name, recordId, edits, options = {}) => ({ select, dispatch }) => {
169
+ logEntityDeprecation(kind, name, "editEntityRecord");
340
170
  const entityConfig = select.getEntityConfig(kind, name);
341
171
  if (!entityConfig) {
342
- throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
172
+ throw new Error(
173
+ `The entity being edited (${kind}, ${name}) does not have a loaded config.`
174
+ );
343
175
  }
344
- const {
345
- mergedEdits = {}
346
- } = entityConfig;
176
+ const { mergedEdits = {} } = entityConfig;
347
177
  const record = select.getRawEntityRecord(kind, name, recordId);
348
- const editedRecord = select.getEditedEntityRecord(kind, name, recordId);
178
+ const editedRecord = select.getEditedEntityRecord(
179
+ kind,
180
+ name,
181
+ recordId
182
+ );
349
183
  const edit = {
350
184
  kind,
351
185
  name,
@@ -355,164 +189,108 @@ export const editEntityRecord = (kind, name, recordId, edits, options = {}) => (
355
189
  edits: Object.keys(edits).reduce((acc, key) => {
356
190
  const recordValue = record[key];
357
191
  const editedRecordValue = editedRecord[key];
358
- const value = mergedEdits[key] ? {
359
- ...editedRecordValue,
360
- ...edits[key]
361
- } : edits[key];
362
- acc[key] = fastDeepEqual(recordValue, value) ? undefined : value;
192
+ const value = mergedEdits[key] ? { ...editedRecordValue, ...edits[key] } : edits[key];
193
+ acc[key] = fastDeepEqual(recordValue, value) ? void 0 : value;
363
194
  return acc;
364
195
  }, {})
365
196
  };
366
197
  if (window.__experimentalEnableSync && entityConfig.syncConfig) {
367
198
  if (globalThis.IS_GUTENBERG_PLUGIN) {
368
- const objectId = entityConfig.getSyncObjectId(recordId);
369
- getSyncProvider().update(entityConfig.syncObjectType + '--edit', objectId, edit.edits);
199
+ const objectType = `${kind}/${name}`;
200
+ const objectId = recordId;
201
+ syncManager.update(
202
+ objectType,
203
+ objectId,
204
+ edit.edits,
205
+ LOCAL_EDITOR_ORIGIN
206
+ );
370
207
  }
371
- } else {
372
- if (!options.undoIgnore) {
373
- select.getUndoManager().addRecord([{
374
- id: {
375
- kind,
376
- name,
377
- recordId
378
- },
379
- changes: Object.keys(edits).reduce((acc, key) => {
380
- acc[key] = {
381
- from: editedRecord[key],
382
- to: edits[key]
383
- };
384
- return acc;
385
- }, {})
386
- }], options.isCached);
387
- }
388
- dispatch({
389
- type: 'EDIT_ENTITY_RECORD',
390
- ...edit
391
- });
392
208
  }
209
+ if (!options.undoIgnore) {
210
+ select.getUndoManager().addRecord(
211
+ [
212
+ {
213
+ id: { kind, name, recordId },
214
+ changes: Object.keys(edits).reduce((acc, key) => {
215
+ acc[key] = {
216
+ from: editedRecord[key],
217
+ to: edits[key]
218
+ };
219
+ return acc;
220
+ }, {})
221
+ }
222
+ ],
223
+ options.isCached
224
+ );
225
+ }
226
+ dispatch({
227
+ type: "EDIT_ENTITY_RECORD",
228
+ ...edit
229
+ });
393
230
  };
394
-
395
- /**
396
- * Action triggered to undo the last edit to
397
- * an entity record, if any.
398
- */
399
- export const undo = () => ({
400
- select,
401
- dispatch
402
- }) => {
231
+ const undo = () => ({ select, dispatch }) => {
403
232
  const undoRecord = select.getUndoManager().undo();
404
233
  if (!undoRecord) {
405
234
  return;
406
235
  }
407
236
  dispatch({
408
- type: 'UNDO',
237
+ type: "UNDO",
409
238
  record: undoRecord
410
239
  });
411
240
  };
412
-
413
- /**
414
- * Action triggered to redo the last undone
415
- * edit to an entity record, if any.
416
- */
417
- export const redo = () => ({
418
- select,
419
- dispatch
420
- }) => {
241
+ const redo = () => ({ select, dispatch }) => {
421
242
  const redoRecord = select.getUndoManager().redo();
422
243
  if (!redoRecord) {
423
244
  return;
424
245
  }
425
246
  dispatch({
426
- type: 'REDO',
247
+ type: "REDO",
427
248
  record: redoRecord
428
249
  });
429
250
  };
430
-
431
- /**
432
- * Forces the creation of a new undo level.
433
- *
434
- * @return {Object} Action object.
435
- */
436
- export const __unstableCreateUndoLevel = () => ({
437
- select
438
- }) => {
251
+ const __unstableCreateUndoLevel = () => ({ select }) => {
439
252
  select.getUndoManager().addRecord();
440
253
  };
441
-
442
- /**
443
- * Action triggered to save an entity record.
444
- *
445
- * @param {string} kind Kind of the received entity.
446
- * @param {string} name Name of the received entity.
447
- * @param {Object} record Record to be saved.
448
- * @param {Object} options Saving options.
449
- * @param {boolean} [options.isAutosave=false] Whether this is an autosave.
450
- * @param {Function} [options.__unstableFetch] Internal use only. Function to
451
- * call instead of `apiFetch()`.
452
- * Must return a promise.
453
- * @param {boolean} [options.throwOnError=false] If false, this action suppresses all
454
- * the exceptions. Defaults to false.
455
- */
456
- export const saveEntityRecord = (kind, name, record, {
254
+ const saveEntityRecord = (kind, name, record, {
457
255
  isAutosave = false,
458
256
  __unstableFetch = apiFetch,
459
257
  throwOnError = false
460
- } = {}) => async ({
461
- select,
462
- resolveSelect,
463
- dispatch
464
- }) => {
465
- logEntityDeprecation(kind, name, 'saveEntityRecord');
258
+ } = {}) => async ({ select, resolveSelect, dispatch }) => {
259
+ logEntityDeprecation(kind, name, "saveEntityRecord");
466
260
  const configs = await resolveSelect.getEntitiesConfig(kind);
467
- const entityConfig = configs.find(config => config.kind === kind && config.name === name);
261
+ const entityConfig = configs.find(
262
+ (config) => config.kind === kind && config.name === name
263
+ );
468
264
  if (!entityConfig) {
469
265
  return;
470
266
  }
471
267
  const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
472
268
  const recordId = record[entityIdKey];
473
-
474
- // When called with a theme template ID, trigger the compatibility
475
- // logic.
476
- if (kind === 'postType' && name === 'wp_template' && typeof recordId === 'string' && !/^\d+$/.test(recordId)) {
477
- // Get the theme template.
478
- const template = await select.getEntityRecord('postType', 'wp_registered_template', recordId);
479
- // Duplicate the theme template and make the edit.
480
- const newTemplate = await dispatch.saveEntityRecord('postType', 'wp_template', {
481
- ...template,
482
- ...record,
483
- id: undefined,
484
- type: 'wp_template',
485
- status: 'publish'
486
- });
487
- // Make the new template active.
488
- const activeTemplates = await select.getEntityRecord('root', 'site');
489
- await dispatch.saveEntityRecord('root', 'site', {
490
- active_templates: {
491
- ...activeTemplates.active_templates,
492
- [newTemplate.slug]: newTemplate.id
493
- }
494
- });
495
- return newTemplate;
496
- }
497
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, recordId || uuid()], {
498
- exclusive: true
499
- });
269
+ const lock = await dispatch.__unstableAcquireStoreLock(
270
+ STORE_NAME,
271
+ ["entities", "records", kind, name, recordId || uuid()],
272
+ { exclusive: true }
273
+ );
500
274
  try {
501
- // Evaluate optimized edits.
502
- // (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
503
275
  for (const [key, value] of Object.entries(record)) {
504
- if (typeof value === 'function') {
505
- const evaluatedValue = value(select.getEditedEntityRecord(kind, name, recordId));
506
- dispatch.editEntityRecord(kind, name, recordId, {
507
- [key]: evaluatedValue
508
- }, {
509
- undoIgnore: true
510
- });
276
+ if (typeof value === "function") {
277
+ const evaluatedValue = value(
278
+ select.getEditedEntityRecord(kind, name, recordId)
279
+ );
280
+ dispatch.editEntityRecord(
281
+ kind,
282
+ name,
283
+ recordId,
284
+ {
285
+ [key]: evaluatedValue
286
+ },
287
+ { undoIgnore: true }
288
+ );
511
289
  record[key] = evaluatedValue;
512
290
  }
513
291
  }
514
292
  dispatch({
515
- type: 'SAVE_ENTITY_RECORD_START',
293
+ type: "SAVE_ENTITY_RECORD_START",
516
294
  kind,
517
295
  name,
518
296
  recordId,
@@ -521,97 +299,123 @@ export const saveEntityRecord = (kind, name, record, {
521
299
  let updatedRecord;
522
300
  let error;
523
301
  let hasError = false;
302
+ let { baseURL } = entityConfig;
303
+ if (kind === "postType" && name === "wp_template" && recordId && typeof recordId === "string" && !/^\d+$/.test(recordId)) {
304
+ baseURL = baseURL.slice(0, baseURL.lastIndexOf("/")) + "/templates";
305
+ }
524
306
  try {
525
- const path = `${entityConfig.baseURL}${recordId ? '/' + recordId : ''}`;
526
- const persistedRecord = select.getRawEntityRecord(kind, name, recordId);
307
+ const path = `${baseURL}${recordId ? "/" + recordId : ""}`;
308
+ const persistedRecord = select.getRawEntityRecord(
309
+ kind,
310
+ name,
311
+ recordId
312
+ );
527
313
  if (isAutosave) {
528
- // Most of this autosave logic is very specific to posts.
529
- // This is fine for now as it is the only supported autosave,
530
- // but ideally this should all be handled in the back end,
531
- // so the client just sends and receives objects.
532
314
  const currentUser = select.getCurrentUser();
533
- const currentUserId = currentUser ? currentUser.id : undefined;
534
- const autosavePost = await resolveSelect.getAutosave(persistedRecord.type, persistedRecord.id, currentUserId);
535
- // Autosaves need all expected fields to be present.
536
- // So we fallback to the previous autosave and then
537
- // to the actual persisted entity if the edits don't
538
- // have a value.
315
+ const currentUserId = currentUser ? currentUser.id : void 0;
316
+ const autosavePost = await resolveSelect.getAutosave(
317
+ persistedRecord.type,
318
+ persistedRecord.id,
319
+ currentUserId
320
+ );
539
321
  let data = {
540
322
  ...persistedRecord,
541
323
  ...autosavePost,
542
324
  ...record
543
325
  };
544
- data = Object.keys(data).reduce((acc, key) => {
545
- if (['title', 'excerpt', 'content', 'meta'].includes(key)) {
546
- acc[key] = data[key];
326
+ data = Object.keys(data).reduce(
327
+ (acc, key) => {
328
+ if ([
329
+ "title",
330
+ "excerpt",
331
+ "content",
332
+ "meta"
333
+ ].includes(key)) {
334
+ acc[key] = data[key];
335
+ }
336
+ return acc;
337
+ },
338
+ {
339
+ // Do not update the `status` if we have edited it when auto saving.
340
+ // It's very important to let the user explicitly save this change,
341
+ // because it can lead to unexpected results. An example would be to
342
+ // have a draft post and change the status to publish.
343
+ status: data.status === "auto-draft" ? "draft" : void 0
547
344
  }
548
- return acc;
549
- }, {
550
- // Do not update the `status` if we have edited it when auto saving.
551
- // It's very important to let the user explicitly save this change,
552
- // because it can lead to unexpected results. An example would be to
553
- // have a draft post and change the status to publish.
554
- status: data.status === 'auto-draft' ? 'draft' : undefined
555
- });
345
+ );
556
346
  updatedRecord = await __unstableFetch({
557
347
  path: `${path}/autosaves`,
558
- method: 'POST',
348
+ method: "POST",
559
349
  data
560
350
  });
561
-
562
- // An autosave may be processed by the server as a regular save
563
- // when its update is requested by the author and the post had
564
- // draft or auto-draft status.
565
351
  if (persistedRecord.id === updatedRecord.id) {
566
352
  let newRecord = {
567
353
  ...persistedRecord,
568
354
  ...data,
569
355
  ...updatedRecord
570
356
  };
571
- newRecord = Object.keys(newRecord).reduce((acc, key) => {
572
- // These properties are persisted in autosaves.
573
- if (['title', 'excerpt', 'content'].includes(key)) {
574
- acc[key] = newRecord[key];
575
- } else if (key === 'status') {
576
- // Status is only persisted in autosaves when going from
577
- // "auto-draft" to "draft".
578
- acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status;
579
- } else {
580
- // These properties are not persisted in autosaves.
581
- acc[key] = persistedRecord[key];
582
- }
583
- return acc;
584
- }, {});
585
- dispatch.receiveEntityRecords(kind, name, newRecord, undefined, true);
357
+ newRecord = Object.keys(newRecord).reduce(
358
+ (acc, key) => {
359
+ if (["title", "excerpt", "content"].includes(
360
+ key
361
+ )) {
362
+ acc[key] = newRecord[key];
363
+ } else if (key === "status") {
364
+ acc[key] = persistedRecord.status === "auto-draft" && newRecord.status === "draft" ? newRecord.status : persistedRecord.status;
365
+ } else {
366
+ acc[key] = persistedRecord[key];
367
+ }
368
+ return acc;
369
+ },
370
+ {}
371
+ );
372
+ dispatch.receiveEntityRecords(
373
+ kind,
374
+ name,
375
+ newRecord,
376
+ void 0,
377
+ true
378
+ );
586
379
  } else {
587
- dispatch.receiveAutosaves(persistedRecord.id, updatedRecord);
380
+ dispatch.receiveAutosaves(
381
+ persistedRecord.id,
382
+ updatedRecord
383
+ );
588
384
  }
589
385
  } else {
590
386
  let edits = record;
591
387
  if (entityConfig.__unstablePrePersist) {
592
388
  edits = {
593
389
  ...edits,
594
- ...entityConfig.__unstablePrePersist(persistedRecord, edits)
390
+ ...entityConfig.__unstablePrePersist(
391
+ persistedRecord,
392
+ edits
393
+ )
595
394
  };
596
395
  }
597
- // Unless there is no persisted record, set the status to
598
- // publish.
599
- if (name === 'wp_template' && persistedRecord) {
600
- edits.status = 'publish';
396
+ if (name === "wp_template" && persistedRecord) {
397
+ edits.status = "publish";
601
398
  }
602
399
  updatedRecord = await __unstableFetch({
603
400
  path,
604
- method: recordId ? 'PUT' : 'POST',
401
+ method: recordId ? "PUT" : "POST",
605
402
  data: edits
606
403
  });
607
- dispatch.receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
404
+ dispatch.receiveEntityRecords(
405
+ kind,
406
+ name,
407
+ updatedRecord,
408
+ void 0,
409
+ true,
410
+ edits
411
+ );
608
412
  }
609
413
  } catch (_error) {
610
414
  hasError = true;
611
415
  error = _error;
612
416
  }
613
417
  dispatch({
614
- type: 'SAVE_ENTITY_RECORD_FINISH',
418
+ type: "SAVE_ENTITY_RECORD_FINISH",
615
419
  kind,
616
420
  name,
617
421
  recordId,
@@ -626,256 +430,144 @@ export const saveEntityRecord = (kind, name, record, {
626
430
  dispatch.__unstableReleaseStoreLock(lock);
627
431
  }
628
432
  };
629
-
630
- /**
631
- * Runs multiple core-data actions at the same time using one API request.
632
- *
633
- * Example:
634
- *
635
- * ```
636
- * const [ savedRecord, updatedRecord, deletedRecord ] =
637
- * await dispatch( 'core' ).__experimentalBatch( [
638
- * ( { saveEntityRecord } ) => saveEntityRecord( 'root', 'widget', widget ),
639
- * ( { saveEditedEntityRecord } ) => saveEntityRecord( 'root', 'widget', 123 ),
640
- * ( { deleteEntityRecord } ) => deleteEntityRecord( 'root', 'widget', 123, null ),
641
- * ] );
642
- * ```
643
- *
644
- * @param {Array} requests Array of functions which are invoked simultaneously.
645
- * Each function is passed an object containing
646
- * `saveEntityRecord`, `saveEditedEntityRecord`, and
647
- * `deleteEntityRecord`.
648
- *
649
- * @return {(thunkArgs: Object) => Promise} A promise that resolves to an array containing the return
650
- * values of each function given in `requests`.
651
- */
652
- export const __experimentalBatch = requests => async ({
653
- dispatch
654
- }) => {
433
+ const __experimentalBatch = (requests) => async ({ dispatch }) => {
655
434
  const batch = createBatch();
656
435
  const api = {
657
436
  saveEntityRecord(kind, name, record, options) {
658
- return batch.add(add => dispatch.saveEntityRecord(kind, name, record, {
659
- ...options,
660
- __unstableFetch: add
661
- }));
437
+ return batch.add(
438
+ (add) => dispatch.saveEntityRecord(kind, name, record, {
439
+ ...options,
440
+ __unstableFetch: add
441
+ })
442
+ );
662
443
  },
663
444
  saveEditedEntityRecord(kind, name, recordId, options) {
664
- return batch.add(add => dispatch.saveEditedEntityRecord(kind, name, recordId, {
665
- ...options,
666
- __unstableFetch: add
667
- }));
445
+ return batch.add(
446
+ (add) => dispatch.saveEditedEntityRecord(kind, name, recordId, {
447
+ ...options,
448
+ __unstableFetch: add
449
+ })
450
+ );
668
451
  },
669
452
  deleteEntityRecord(kind, name, recordId, query, options) {
670
- return batch.add(add => dispatch.deleteEntityRecord(kind, name, recordId, query, {
671
- ...options,
672
- __unstableFetch: add
673
- }));
453
+ return batch.add(
454
+ (add) => dispatch.deleteEntityRecord(kind, name, recordId, query, {
455
+ ...options,
456
+ __unstableFetch: add
457
+ })
458
+ );
674
459
  }
675
460
  };
676
- const resultPromises = requests.map(request => request(api));
677
- const [, ...results] = await Promise.all([batch.run(), ...resultPromises]);
461
+ const resultPromises = requests.map((request) => request(api));
462
+ const [, ...results] = await Promise.all([
463
+ batch.run(),
464
+ ...resultPromises
465
+ ]);
678
466
  return results;
679
467
  };
680
-
681
- /**
682
- * Action triggered to save an entity record's edits.
683
- *
684
- * @param {string} kind Kind of the entity.
685
- * @param {string} name Name of the entity.
686
- * @param {Object} recordId ID of the record.
687
- * @param {Object=} options Saving options.
688
- */
689
- export const saveEditedEntityRecord = (kind, name, recordId, options) => async ({
690
- select,
691
- dispatch,
692
- resolveSelect
693
- }) => {
694
- logEntityDeprecation(kind, name, 'saveEditedEntityRecord');
468
+ const saveEditedEntityRecord = (kind, name, recordId, options) => async ({ select, dispatch, resolveSelect }) => {
469
+ logEntityDeprecation(kind, name, "saveEditedEntityRecord");
695
470
  if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
696
471
  return;
697
472
  }
698
473
  const configs = await resolveSelect.getEntitiesConfig(kind);
699
- const entityConfig = configs.find(config => config.kind === kind && config.name === name);
474
+ const entityConfig = configs.find(
475
+ (config) => config.kind === kind && config.name === name
476
+ );
700
477
  if (!entityConfig) {
701
478
  return;
702
479
  }
703
480
  const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
704
- const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
705
- const record = {
706
- [entityIdKey]: recordId,
707
- ...edits
708
- };
481
+ const edits = select.getEntityRecordNonTransientEdits(
482
+ kind,
483
+ name,
484
+ recordId
485
+ );
486
+ const record = { [entityIdKey]: recordId, ...edits };
709
487
  return await dispatch.saveEntityRecord(kind, name, record, options);
710
488
  };
711
-
712
- /**
713
- * Action triggered to save only specified properties for the entity.
714
- *
715
- * @param {string} kind Kind of the entity.
716
- * @param {string} name Name of the entity.
717
- * @param {number|string} recordId ID of the record.
718
- * @param {Array} itemsToSave List of entity properties or property paths to save.
719
- * @param {Object} options Saving options.
720
- */
721
- export const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({
722
- select,
723
- dispatch,
724
- resolveSelect
725
- }) => {
726
- logEntityDeprecation(kind, name, '__experimentalSaveSpecifiedEntityEdits');
489
+ const __experimentalSaveSpecifiedEntityEdits = (kind, name, recordId, itemsToSave, options) => async ({ select, dispatch, resolveSelect }) => {
490
+ logEntityDeprecation(
491
+ kind,
492
+ name,
493
+ "__experimentalSaveSpecifiedEntityEdits"
494
+ );
727
495
  if (!select.hasEditsForEntityRecord(kind, name, recordId)) {
728
496
  return;
729
497
  }
730
- const edits = select.getEntityRecordNonTransientEdits(kind, name, recordId);
498
+ const edits = select.getEntityRecordNonTransientEdits(
499
+ kind,
500
+ name,
501
+ recordId
502
+ );
731
503
  const editsToSave = {};
732
504
  for (const item of itemsToSave) {
733
505
  setNestedValue(editsToSave, item, getNestedValue(edits, item));
734
506
  }
735
507
  const configs = await resolveSelect.getEntitiesConfig(kind);
736
- const entityConfig = configs.find(config => config.kind === kind && config.name === name);
508
+ const entityConfig = configs.find(
509
+ (config) => config.kind === kind && config.name === name
510
+ );
737
511
  const entityIdKey = entityConfig?.key || DEFAULT_ENTITY_KEY;
738
-
739
- // If a record key is provided then update the existing record.
740
- // This necessitates providing `recordKey` to saveEntityRecord as part of the
741
- // `record` argument (here called `editsToSave`) to stop that action creating
742
- // a new record and instead cause it to update the existing record.
743
512
  if (recordId) {
744
513
  editsToSave[entityIdKey] = recordId;
745
514
  }
746
- return await dispatch.saveEntityRecord(kind, name, editsToSave, options);
515
+ return await dispatch.saveEntityRecord(
516
+ kind,
517
+ name,
518
+ editsToSave,
519
+ options
520
+ );
747
521
  };
748
-
749
- /**
750
- * Returns an action object used in signalling that Upload permissions have been received.
751
- *
752
- * @deprecated since WP 5.9, use receiveUserPermission instead.
753
- *
754
- * @param {boolean} hasUploadPermissions Does the user have permission to upload files?
755
- *
756
- * @return {Object} Action object.
757
- */
758
- export function receiveUploadPermissions(hasUploadPermissions) {
522
+ function receiveUploadPermissions(hasUploadPermissions) {
759
523
  deprecated("wp.data.dispatch( 'core' ).receiveUploadPermissions", {
760
- since: '5.9',
761
- alternative: 'receiveUserPermission'
524
+ since: "5.9",
525
+ alternative: "receiveUserPermission"
762
526
  });
763
- return receiveUserPermission('create/media', hasUploadPermissions);
527
+ return receiveUserPermission("create/media", hasUploadPermissions);
764
528
  }
765
-
766
- /**
767
- * Returns an action object used in signalling that the current user has
768
- * permission to perform an action on a REST resource.
769
- * Ignored from documentation as it's internal to the data store.
770
- *
771
- * @ignore
772
- *
773
- * @param {string} key A key that represents the action and REST resource.
774
- * @param {boolean} isAllowed Whether or not the user can perform the action.
775
- *
776
- * @return {Object} Action object.
777
- */
778
- export function receiveUserPermission(key, isAllowed) {
529
+ function receiveUserPermission(key, isAllowed) {
779
530
  return {
780
- type: 'RECEIVE_USER_PERMISSION',
531
+ type: "RECEIVE_USER_PERMISSION",
781
532
  key,
782
533
  isAllowed
783
534
  };
784
535
  }
785
-
786
- /**
787
- * Returns an action object used in signalling that the current user has
788
- * permission to perform an action on a REST resource. Ignored from
789
- * documentation as it's internal to the data store.
790
- *
791
- * @ignore
792
- *
793
- * @param {Object<string, boolean>} permissions An object where keys represent
794
- * actions and REST resources, and
795
- * values indicate whether the user
796
- * is allowed to perform the
797
- * action.
798
- *
799
- * @return {Object} Action object.
800
- */
801
- export function receiveUserPermissions(permissions) {
536
+ function receiveUserPermissions(permissions) {
802
537
  return {
803
- type: 'RECEIVE_USER_PERMISSIONS',
538
+ type: "RECEIVE_USER_PERMISSIONS",
804
539
  permissions
805
540
  };
806
541
  }
807
-
808
- /**
809
- * Returns an action object used in signalling that the autosaves for a
810
- * post have been received.
811
- * Ignored from documentation as it's internal to the data store.
812
- *
813
- * @ignore
814
- *
815
- * @param {number} postId The id of the post that is parent to the autosave.
816
- * @param {Array|Object} autosaves An array of autosaves or singular autosave object.
817
- *
818
- * @return {Object} Action object.
819
- */
820
- export function receiveAutosaves(postId, autosaves) {
542
+ function receiveAutosaves(postId, autosaves) {
821
543
  return {
822
- type: 'RECEIVE_AUTOSAVES',
544
+ type: "RECEIVE_AUTOSAVES",
823
545
  postId,
824
546
  autosaves: Array.isArray(autosaves) ? autosaves : [autosaves]
825
547
  };
826
548
  }
827
-
828
- /**
829
- * Returns an action object signalling that the fallback Navigation
830
- * Menu id has been received.
831
- *
832
- * @param {integer} fallbackId the id of the fallback Navigation Menu
833
- * @return {Object} Action object.
834
- */
835
- export function receiveNavigationFallbackId(fallbackId) {
549
+ function receiveNavigationFallbackId(fallbackId) {
836
550
  return {
837
- type: 'RECEIVE_NAVIGATION_FALLBACK_ID',
551
+ type: "RECEIVE_NAVIGATION_FALLBACK_ID",
838
552
  fallbackId
839
553
  };
840
554
  }
841
-
842
- /**
843
- * Returns an action object used to set the template for a given query.
844
- *
845
- * @param {Object} query The lookup query.
846
- * @param {string} templateId The resolved template id.
847
- *
848
- * @return {Object} Action object.
849
- */
850
- export function receiveDefaultTemplateId(query, templateId) {
555
+ function receiveDefaultTemplateId(query, templateId) {
851
556
  return {
852
- type: 'RECEIVE_DEFAULT_TEMPLATE',
557
+ type: "RECEIVE_DEFAULT_TEMPLATE",
853
558
  query,
854
559
  templateId
855
560
  };
856
561
  }
857
-
858
- /**
859
- * Action triggered to receive revision items.
860
- *
861
- * @param {string} kind Kind of the received entity record revisions.
862
- * @param {string} name Name of the received entity record revisions.
863
- * @param {number|string} recordKey The key of the entity record whose revisions you want to fetch.
864
- * @param {Array|Object} records Revisions received.
865
- * @param {?Object} query Query Object.
866
- * @param {?boolean} invalidateCache Should invalidate query caches.
867
- * @param {?Object} meta Meta information about pagination.
868
- */
869
- export const receiveRevisions = (kind, name, recordKey, records, query, invalidateCache = false, meta) => async ({
870
- dispatch,
871
- resolveSelect
872
- }) => {
873
- logEntityDeprecation(kind, name, 'receiveRevisions');
562
+ const receiveRevisions = (kind, name, recordKey, records, query, invalidateCache = false, meta) => async ({ dispatch, resolveSelect }) => {
563
+ logEntityDeprecation(kind, name, "receiveRevisions");
874
564
  const configs = await resolveSelect.getEntitiesConfig(kind);
875
- const entityConfig = configs.find(config => config.kind === kind && config.name === name);
565
+ const entityConfig = configs.find(
566
+ (config) => config.kind === kind && config.name === name
567
+ );
876
568
  const key = entityConfig && entityConfig?.revisionKey ? entityConfig.revisionKey : DEFAULT_ENTITY_KEY;
877
569
  dispatch({
878
- type: 'RECEIVE_ITEM_REVISIONS',
570
+ type: "RECEIVE_ITEM_REVISIONS",
879
571
  key,
880
572
  items: Array.isArray(records) ? records : [records],
881
573
  recordKey,
@@ -886,4 +578,33 @@ export const receiveRevisions = (kind, name, recordKey, records, query, invalida
886
578
  invalidateCache
887
579
  });
888
580
  };
889
- //# sourceMappingURL=actions.js.map
581
+ export {
582
+ __experimentalBatch,
583
+ __experimentalReceiveCurrentGlobalStylesId,
584
+ __experimentalReceiveThemeBaseGlobalStyles,
585
+ __experimentalReceiveThemeGlobalStyleVariations,
586
+ __experimentalSaveSpecifiedEntityEdits,
587
+ __unstableCreateUndoLevel,
588
+ addEntities,
589
+ deleteEntityRecord,
590
+ editEntityRecord,
591
+ receiveAutosaves,
592
+ receiveCurrentTheme,
593
+ receiveCurrentUser,
594
+ receiveDefaultTemplateId,
595
+ receiveEmbedPreview,
596
+ receiveEntityRecords,
597
+ receiveNavigationFallbackId,
598
+ receiveRevisions,
599
+ receiveThemeGlobalStyleRevisions,
600
+ receiveThemeSupports,
601
+ receiveUploadPermissions,
602
+ receiveUserPermission,
603
+ receiveUserPermissions,
604
+ receiveUserQuery,
605
+ redo,
606
+ saveEditedEntityRecord,
607
+ saveEntityRecord,
608
+ undo
609
+ };
610
+ //# sourceMappingURL=actions.js.map