@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,81 +1,41 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useCallback, useMemo } from '@wordpress/element';
5
- import { useDispatch, useSelect } from '@wordpress/data';
6
- import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import { STORE_NAME } from '../name';
12
- import useEntityId from './use-entity-id';
13
- import { updateFootnotesFromMeta } from '../footnotes';
1
+ import { useCallback, useMemo } from "@wordpress/element";
2
+ import { useDispatch, useSelect } from "@wordpress/data";
3
+ import { parse, __unstableSerializeAndClean } from "@wordpress/blocks";
4
+ import { STORE_NAME } from "../name";
5
+ import useEntityId from "./use-entity-id";
6
+ import { updateFootnotesFromMeta } from "../footnotes";
14
7
  const EMPTY_ARRAY = [];
15
- const parsedBlocksCache = new WeakMap();
16
-
17
- /**
18
- * Hook that returns block content getters and setters for
19
- * the nearest provided entity of the specified type.
20
- *
21
- * The return value has the shape `[ blocks, onInput, onChange ]`.
22
- * `onInput` is for block changes that don't create undo levels
23
- * or dirty the post, non-persistent changes, and `onChange` is for
24
- * persistent changes. They map directly to the props of a
25
- * `BlockEditorProvider` and are intended to be used with it,
26
- * or similar components or hooks.
27
- *
28
- * @param {string} kind The entity kind.
29
- * @param {string} name The entity name.
30
- * @param {Object} options
31
- * @param {string} [options.id] An entity ID to use instead of the context-provided one.
32
- *
33
- * @return {[unknown[], Function, Function]} The block array and setters.
34
- */
35
- export default function useEntityBlockEditor(kind, name, {
36
- id: _id
37
- } = {}) {
8
+ const parsedBlocksCache = /* @__PURE__ */ new WeakMap();
9
+ function useEntityBlockEditor(kind, name, { id: _id } = {}) {
38
10
  const providerId = useEntityId(kind, name);
39
- const id = _id !== null && _id !== void 0 ? _id : providerId;
40
- const {
41
- getEntityRecord,
42
- getEntityRecordEdits
43
- } = useSelect(STORE_NAME);
44
- const {
45
- content,
46
- editedBlocks,
47
- meta
48
- } = useSelect(select => {
49
- if (!id) {
50
- return {};
51
- }
52
- const {
53
- getEditedEntityRecord
54
- } = select(STORE_NAME);
55
- const editedRecord = getEditedEntityRecord(kind, name, id);
56
- return {
57
- editedBlocks: editedRecord.blocks,
58
- content: editedRecord.content,
59
- meta: editedRecord.meta
60
- };
61
- }, [kind, name, id]);
62
- const {
63
- __unstableCreateUndoLevel,
64
- editEntityRecord
65
- } = useDispatch(STORE_NAME);
11
+ const id = _id ?? providerId;
12
+ const { getEntityRecord, getEntityRecordEdits } = useSelect(STORE_NAME);
13
+ const { content, editedBlocks, meta } = useSelect(
14
+ (select) => {
15
+ if (!id) {
16
+ return {};
17
+ }
18
+ const { getEditedEntityRecord } = select(STORE_NAME);
19
+ const editedRecord = getEditedEntityRecord(kind, name, id);
20
+ return {
21
+ editedBlocks: editedRecord.blocks,
22
+ content: editedRecord.content,
23
+ meta: editedRecord.meta
24
+ };
25
+ },
26
+ [kind, name, id]
27
+ );
28
+ const { __unstableCreateUndoLevel, editEntityRecord } = useDispatch(STORE_NAME);
66
29
  const blocks = useMemo(() => {
67
30
  if (!id) {
68
- return undefined;
31
+ return void 0;
69
32
  }
70
33
  if (editedBlocks) {
71
34
  return editedBlocks;
72
35
  }
73
- if (!content || typeof content !== 'string') {
36
+ if (!content || typeof content !== "string") {
74
37
  return EMPTY_ARRAY;
75
38
  }
76
-
77
- // If there's an edit, cache the parsed blocks by the edit.
78
- // If not, cache by the original entity record.
79
39
  const edits = getEntityRecordEdits(kind, name, id);
80
40
  const isUnedited = !edits || !Object.keys(edits).length;
81
41
  const cackeKey = isUnedited ? getEntityRecord(kind, name, id) : edits;
@@ -85,47 +45,57 @@ export default function useEntityBlockEditor(kind, name, {
85
45
  parsedBlocksCache.set(cackeKey, _blocks);
86
46
  }
87
47
  return _blocks;
88
- }, [kind, name, id, editedBlocks, content, getEntityRecord, getEntityRecordEdits]);
89
- const onChange = useCallback((newBlocks, options) => {
90
- const noChange = blocks === newBlocks;
91
- if (noChange) {
92
- return __unstableCreateUndoLevel(kind, name, id);
93
- }
94
- const {
95
- selection,
96
- ...rest
97
- } = options;
98
-
99
- // We create a new function here on every persistent edit
100
- // to make sure the edit makes the post dirty and creates
101
- // a new undo level.
102
- const edits = {
103
- selection,
104
- content: ({
105
- blocks: blocksForSerialization = []
106
- }) => __unstableSerializeAndClean(blocksForSerialization),
107
- ...updateFootnotesFromMeta(newBlocks, meta)
108
- };
109
- editEntityRecord(kind, name, id, edits, {
110
- isCached: false,
111
- ...rest
112
- });
113
- }, [kind, name, id, blocks, meta, __unstableCreateUndoLevel, editEntityRecord]);
114
- const onInput = useCallback((newBlocks, options) => {
115
- const {
116
- selection,
117
- ...rest
118
- } = options;
119
- const footnotesChanges = updateFootnotesFromMeta(newBlocks, meta);
120
- const edits = {
121
- selection,
122
- ...footnotesChanges
123
- };
124
- editEntityRecord(kind, name, id, edits, {
125
- isCached: true,
126
- ...rest
127
- });
128
- }, [kind, name, id, meta, editEntityRecord]);
48
+ }, [
49
+ kind,
50
+ name,
51
+ id,
52
+ editedBlocks,
53
+ content,
54
+ getEntityRecord,
55
+ getEntityRecordEdits
56
+ ]);
57
+ const onChange = useCallback(
58
+ (newBlocks, options) => {
59
+ const noChange = blocks === newBlocks;
60
+ if (noChange) {
61
+ return __unstableCreateUndoLevel(kind, name, id);
62
+ }
63
+ const { selection, ...rest } = options;
64
+ const edits = {
65
+ selection,
66
+ content: ({ blocks: blocksForSerialization = [] }) => __unstableSerializeAndClean(blocksForSerialization),
67
+ ...updateFootnotesFromMeta(newBlocks, meta)
68
+ };
69
+ editEntityRecord(kind, name, id, edits, {
70
+ isCached: false,
71
+ ...rest
72
+ });
73
+ },
74
+ [
75
+ kind,
76
+ name,
77
+ id,
78
+ blocks,
79
+ meta,
80
+ __unstableCreateUndoLevel,
81
+ editEntityRecord
82
+ ]
83
+ );
84
+ const onInput = useCallback(
85
+ (newBlocks, options) => {
86
+ const { selection, ...rest } = options;
87
+ const footnotesChanges = updateFootnotesFromMeta(newBlocks, meta);
88
+ const edits = { selection, ...footnotesChanges };
89
+ editEntityRecord(kind, name, id, edits, {
90
+ isCached: true,
91
+ ...rest
92
+ });
93
+ },
94
+ [kind, name, id, meta, editEntityRecord]
95
+ );
129
96
  return [blocks, onInput, onChange];
130
97
  }
131
- //# sourceMappingURL=use-entity-block-editor.js.map
98
+ export {
99
+ useEntityBlockEditor as default
100
+ };
101
+ //# sourceMappingURL=use-entity-block-editor.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useCallback","useMemo","useDispatch","useSelect","parse","__unstableSerializeAndClean","STORE_NAME","useEntityId","updateFootnotesFromMeta","EMPTY_ARRAY","parsedBlocksCache","WeakMap","useEntityBlockEditor","kind","name","id","_id","providerId","getEntityRecord","getEntityRecordEdits","content","editedBlocks","meta","select","getEditedEntityRecord","editedRecord","blocks","__unstableCreateUndoLevel","editEntityRecord","undefined","edits","isUnedited","Object","keys","length","cackeKey","_blocks","get","set","onChange","newBlocks","options","noChange","selection","rest","blocksForSerialization","isCached","onInput","footnotesChanges"],"sources":["@wordpress/core-data/src/hooks/use-entity-block-editor.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\nimport { updateFootnotesFromMeta } from '../footnotes';\n\nconst EMPTY_ARRAY = [];\nconst parsedBlocksCache = new WeakMap();\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[unknown[], Function, Function]} The block array and setters.\n */\nexport default function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME );\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( ! id ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\tif ( ! content || typeof content !== 'string' ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\t// If there's an edit, cache the parsed blocks by the edit.\n\t\t// If not, cache by the original entity record.\n\t\tconst edits = getEntityRecordEdits( kind, name, id );\n\t\tconst isUnedited = ! edits || ! Object.keys( edits ).length;\n\t\tconst cackeKey = isUnedited ? getEntityRecord( kind, name, id ) : edits;\n\t\tlet _blocks = parsedBlocksCache.get( cackeKey );\n\n\t\tif ( ! _blocks ) {\n\t\t\t_blocks = parse( content );\n\t\t\tparsedBlocksCache.set( cackeKey, _blocks );\n\t\t}\n\n\t\treturn _blocks;\n\t}, [\n\t\tkind,\n\t\tname,\n\t\tid,\n\t\teditedBlocks,\n\t\tcontent,\n\t\tgetEntityRecord,\n\t\tgetEntityRecordEdits,\n\t] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection, ...rest } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotesFromMeta( newBlocks, meta ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: false,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tmeta,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection, ...rest } = options;\n\t\t\tconst footnotesChanges = updateFootnotesFromMeta( newBlocks, meta );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: true,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, meta, editEntityRecord ]\n\t);\n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ources": ["../../src/hooks/use-entity-block-editor.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\nimport { updateFootnotesFromMeta } from '../footnotes';\n\nconst EMPTY_ARRAY = [];\nconst parsedBlocksCache = new WeakMap();\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[unknown[], Function, Function]} The block array and setters.\n */\nexport default function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME );\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( ! id ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\tif ( ! content || typeof content !== 'string' ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\t// If there's an edit, cache the parsed blocks by the edit.\n\t\t// If not, cache by the original entity record.\n\t\tconst edits = getEntityRecordEdits( kind, name, id );\n\t\tconst isUnedited = ! edits || ! Object.keys( edits ).length;\n\t\tconst cackeKey = isUnedited ? getEntityRecord( kind, name, id ) : edits;\n\t\tlet _blocks = parsedBlocksCache.get( cackeKey );\n\n\t\tif ( ! _blocks ) {\n\t\t\t_blocks = parse( content );\n\t\t\tparsedBlocksCache.set( cackeKey, _blocks );\n\t\t}\n\n\t\treturn _blocks;\n\t}, [\n\t\tkind,\n\t\tname,\n\t\tid,\n\t\teditedBlocks,\n\t\tcontent,\n\t\tgetEntityRecord,\n\t\tgetEntityRecordEdits,\n\t] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection, ...rest } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotesFromMeta( newBlocks, meta ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: false,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tmeta,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection, ...rest } = options;\n\t\t\tconst footnotesChanges = updateFootnotesFromMeta( newBlocks, meta );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: true,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, meta, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],
5
+ "mappings": "AAGA,SAAS,aAAa,eAAe;AACrC,SAAS,aAAa,iBAAiB;AACvC,SAAS,OAAO,mCAAmC;AAKnD,SAAS,kBAAkB;AAC3B,OAAO,iBAAiB;AACxB,SAAS,+BAA+B;AAExC,MAAM,cAAc,CAAC;AACrB,MAAM,oBAAoB,oBAAI,QAAQ;AAoBvB,SAAR,qBAAuC,MAAM,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,GAAI;AAC5E,QAAM,aAAa,YAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OAAO;AAClB,QAAM,EAAE,iBAAiB,qBAAqB,IAAI,UAAW,UAAW;AACxE,QAAM,EAAE,SAAS,cAAc,KAAK,IAAI;AAAA,IACvC,CAAE,WAAY;AACb,UAAK,CAAE,IAAK;AACX,eAAO,CAAC;AAAA,MACT;AACA,YAAM,EAAE,sBAAsB,IAAI,OAAQ,UAAW;AACrD,YAAM,eAAe,sBAAuB,MAAM,MAAM,EAAG;AAC3D,aAAO;AAAA,QACN,cAAc,aAAa;AAAA,QAC3B,SAAS,aAAa;AAAA,QACtB,MAAM,aAAa;AAAA,MACpB;AAAA,IACD;AAAA,IACA,CAAE,MAAM,MAAM,EAAG;AAAA,EAClB;AACA,QAAM,EAAE,2BAA2B,iBAAiB,IACnD,YAAa,UAAW;AAEzB,QAAM,SAAS,QAAS,MAAM;AAC7B,QAAK,CAAE,IAAK;AACX,aAAO;AAAA,IACR;AAEA,QAAK,cAAe;AACnB,aAAO;AAAA,IACR;AAEA,QAAK,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M,IAAI,OAAO;AAAA,QACxC,UAAU;AAAA,QACV,GAAG;AAAA,MACJ,CAAE;AAAA,IACH;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,MAAM,gBAAiB;AAAA,EAC1C;AAEA,SAAO,CAAE,QAAQ,SAAS,QAAS;AACpC;",
6
+ "names": []
7
+ }
@@ -1,22 +1,10 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useContext } from '@wordpress/element';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { EntityContext } from '../entity-context';
10
-
11
- /**
12
- * Hook that returns the ID for the nearest
13
- * provided entity of the specified type.
14
- *
15
- * @param {string} kind The entity kind.
16
- * @param {string} name The entity name.
17
- */
18
- export default function useEntityId(kind, name) {
1
+ import { useContext } from "@wordpress/element";
2
+ import { EntityContext } from "../entity-context";
3
+ function useEntityId(kind, name) {
19
4
  const context = useContext(EntityContext);
20
5
  return context?.[kind]?.[name];
21
6
  }
22
- //# sourceMappingURL=use-entity-id.js.map
7
+ export {
8
+ useEntityId as default
9
+ };
10
+ //# sourceMappingURL=use-entity-id.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useContext","EntityContext","useEntityId","kind","name","context"],"sources":["@wordpress/core-data/src/hooks/use-entity-id.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { EntityContext } from '../entity-context';\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport default function useEntityId( kind, name ) {\n\tconst context = useContext( EntityContext );\n\treturn context?.[ kind ]?.[ name ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,aAAa,QAAQ,mBAAmB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,WAAWA,CAAEC,IAAI,EAAEC,IAAI,EAAG;EACjD,MAAMC,OAAO,GAAGL,UAAU,CAAEC,aAAc,CAAC;EAC3C,OAAOI,OAAO,GAAIF,IAAI,CAAE,GAAIC,IAAI,CAAE;AACnC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/use-entity-id.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { EntityContext } from '../entity-context';\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport default function useEntityId( kind, name ) {\n\tconst context = useContext( EntityContext );\n\treturn context?.[ kind ]?.[ name ];\n}\n"],
5
+ "mappings": "AAGA,SAAS,kBAAkB;AAK3B,SAAS,qBAAqB;AASf,SAAR,YAA8B,MAAM,MAAO;AACjD,QAAM,UAAU,WAAY,aAAc;AAC1C,SAAO,UAAW,IAAK,IAAK,IAAK;AAClC;",
6
+ "names": []
7
+ }
@@ -1,58 +1,34 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useCallback } from '@wordpress/element';
5
- import { useDispatch, useSelect } from '@wordpress/data';
6
-
7
- /**
8
- * Internal dependencies
9
- */
10
- import { STORE_NAME } from '../name';
11
- import useEntityId from './use-entity-id';
12
-
13
- /**
14
- * Hook that returns the value and a setter for the
15
- * specified property of the nearest provided
16
- * entity of the specified type.
17
- *
18
- * @param {string} kind The entity kind.
19
- * @param {string} name The entity name.
20
- * @param {string} prop The property name.
21
- * @param {number|string} [_id] An entity ID to use instead of the context-provided one.
22
- *
23
- * @return {[*, Function, *]} An array where the first item is the
24
- * property value, the second is the
25
- * setter and the third is the full value
26
- * object from REST API containing more
27
- * information like `raw`, `rendered` and
28
- * `protected` props.
29
- */
30
- export default function useEntityProp(kind, name, prop, _id) {
1
+ import { useCallback } from "@wordpress/element";
2
+ import { useDispatch, useSelect } from "@wordpress/data";
3
+ import { STORE_NAME } from "../name";
4
+ import useEntityId from "./use-entity-id";
5
+ function useEntityProp(kind, name, prop, _id) {
31
6
  const providerId = useEntityId(kind, name);
32
- const id = _id !== null && _id !== void 0 ? _id : providerId;
33
- const {
34
- value,
35
- fullValue
36
- } = useSelect(select => {
37
- const {
38
- getEntityRecord,
39
- getEditedEntityRecord
40
- } = select(STORE_NAME);
41
- const record = getEntityRecord(kind, name, id); // Trigger resolver.
42
- const editedRecord = getEditedEntityRecord(kind, name, id);
43
- return record && editedRecord ? {
44
- value: editedRecord[prop],
45
- fullValue: record[prop]
46
- } : {};
47
- }, [kind, name, id, prop]);
48
- const {
49
- editEntityRecord
50
- } = useDispatch(STORE_NAME);
51
- const setValue = useCallback(newValue => {
52
- editEntityRecord(kind, name, id, {
53
- [prop]: newValue
54
- });
55
- }, [editEntityRecord, kind, name, id, prop]);
7
+ const id = _id ?? providerId;
8
+ const { value, fullValue } = useSelect(
9
+ (select) => {
10
+ const { getEntityRecord, getEditedEntityRecord } = select(STORE_NAME);
11
+ const record = getEntityRecord(kind, name, id);
12
+ const editedRecord = getEditedEntityRecord(kind, name, id);
13
+ return record && editedRecord ? {
14
+ value: editedRecord[prop],
15
+ fullValue: record[prop]
16
+ } : {};
17
+ },
18
+ [kind, name, id, prop]
19
+ );
20
+ const { editEntityRecord } = useDispatch(STORE_NAME);
21
+ const setValue = useCallback(
22
+ (newValue) => {
23
+ editEntityRecord(kind, name, id, {
24
+ [prop]: newValue
25
+ });
26
+ },
27
+ [editEntityRecord, kind, name, id, prop]
28
+ );
56
29
  return [value, setValue, fullValue];
57
30
  }
58
- //# sourceMappingURL=use-entity-prop.js.map
31
+ export {
32
+ useEntityProp as default
33
+ };
34
+ //# sourceMappingURL=use-entity-prop.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useCallback","useDispatch","useSelect","STORE_NAME","useEntityId","useEntityProp","kind","name","prop","_id","providerId","id","value","fullValue","select","getEntityRecord","getEditedEntityRecord","record","editedRecord","editEntityRecord","setValue","newValue"],"sources":["@wordpress/core-data/src/hooks/use-entity-prop.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,QAAQ,oBAAoB;AAChD,SAASC,WAAW,EA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B,EAAEb,IAAI,EAAEC,IAAI,EAAEI,EAAE,EAAEH,IAAI,CACzC,CAAC;EAED,OAAO,CAAEI,KAAK,EAAEQ,QAAQ,EAAEP,SAAS,CAAE;AACtC","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/use-entity-prop.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {number|string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport default function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n"],
5
+ "mappings": "AAGA,SAAS,mBAAmB;AAC5B,SAAS,aAAa,iBAAiB;AAKvC,SAAS,kBAAkB;AAC3B,OAAO,iBAAiB;AAmBT,SAAR,cAAgC,MAAM,MAAM,MAAM,KAAM;AAC9D,QAAM,aAAa,YAAa,MAAM,IAAK;AAC3C,QAAM,KAAK,OAAO;AAElB,QAAM,EAAE,OAAO,UAAU,IAAI;AAAA,IAC5B,CAAE,WAAY;AACb,YAAM,EAAE,iBAAiB,sBAAsB,IAC9C,OAAQ,UAAW;AACpB,YAAM,SAAS,gBAAiB,MAAM,MAAM,EAAG;AAC/C,YAAM,eAAe,sBAAuB,MAAM,MAAM,EAAG;AAC3D,aAAO,UAAU,eACd;AAAA,QACA,OAAO,aAAc,IAAK;AAAA,QAC1B,WAAW,OAAQ,IAAK;AAAA,MACxB,IACA,CAAC;AAAA,IACL;AAAA,IACA,CAAE,MAAM,MAAM,IAAI,IAAK;AAAA,EACxB;AACA,QAAM,EAAE,iBAAiB,IAAI,YAAa,UAAW;AACrD,QAAM,WAAW;AAAA,IAChB,CAAE,aAAc;AACf,uBAAkB,MAAM,MAAM,IAAI;AAAA,QACjC,CAAE,IAAK,GAAG;AAAA,MACX,CAAE;AAAA,IACH;AAAA,IACA,CAAE,kBAAkB,MAAM,MAAM,IAAI,IAAK;AAAA,EAC1C;AAEA,SAAO,CAAE,OAAO,UAAU,SAAU;AACrC;",
6
+ "names": []
7
+ }
@@ -1,150 +1,61 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useDispatch, useSelect } from '@wordpress/data';
5
- import deprecated from '@wordpress/deprecated';
6
- import { useMemo } from '@wordpress/element';
7
-
8
- /**
9
- * Internal dependencies
10
- */
11
- import useQuerySelect from './use-query-select';
12
- import { store as coreStore } from '../';
1
+ import { useDispatch, useSelect } from "@wordpress/data";
2
+ import deprecated from "@wordpress/deprecated";
3
+ import { useMemo } from "@wordpress/element";
4
+ import useQuerySelect from "./use-query-select";
5
+ import { store as coreStore } from "../";
13
6
  const EMPTY_OBJECT = {};
14
-
15
- /**
16
- * Resolves the specified entity record.
17
- *
18
- * @since 6.1.0 Introduced in WordPress core.
19
- *
20
- * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
21
- * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
22
- * @param recordId ID of the requested entity record.
23
- * @param options Optional hook options.
24
- * @example
25
- * ```js
26
- * import { useEntityRecord } from '@wordpress/core-data';
27
- *
28
- * function PageTitleDisplay( { id } ) {
29
- * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );
30
- *
31
- * if ( isResolving ) {
32
- * return 'Loading...';
33
- * }
34
- *
35
- * return record.title;
36
- * }
37
- *
38
- * // Rendered in the application:
39
- * // <PageTitleDisplay id={ 1 } />
40
- * ```
41
- *
42
- * In the above example, when `PageTitleDisplay` is rendered into an
43
- * application, the page and the resolution details will be retrieved from
44
- * the store state using `getEntityRecord()`, or resolved if missing.
45
- *
46
- * @example
47
- * ```js
48
- * import { useCallback } from 'react';
49
- * import { useDispatch } from '@wordpress/data';
50
- * import { __ } from '@wordpress/i18n';
51
- * import { TextControl } from '@wordpress/components';
52
- * import { store as noticeStore } from '@wordpress/notices';
53
- * import { useEntityRecord } from '@wordpress/core-data';
54
- *
55
- * function PageRenameForm( { id } ) {
56
- * const page = useEntityRecord( 'postType', 'page', id );
57
- * const { createSuccessNotice, createErrorNotice } =
58
- * useDispatch( noticeStore );
59
- *
60
- * const setTitle = useCallback( ( title ) => {
61
- * page.edit( { title } );
62
- * }, [ page.edit ] );
63
- *
64
- * if ( page.isResolving ) {
65
- * return 'Loading...';
66
- * }
67
- *
68
- * async function onRename( event ) {
69
- * event.preventDefault();
70
- * try {
71
- * await page.save();
72
- * createSuccessNotice( __( 'Page renamed.' ), {
73
- * type: 'snackbar',
74
- * } );
75
- * } catch ( error ) {
76
- * createErrorNotice( error.message, { type: 'snackbar' } );
77
- * }
78
- * }
79
- *
80
- * return (
81
- * <form onSubmit={ onRename }>
82
- * <TextControl
83
- * __nextHasNoMarginBottom
84
- * __next40pxDefaultSize
85
- * label={ __( 'Name' ) }
86
- * value={ page.editedRecord.title }
87
- * onChange={ setTitle }
88
- * />
89
- * <button type="submit">{ __( 'Save' ) }</button>
90
- * </form>
91
- * );
92
- * }
93
- *
94
- * // Rendered in the application:
95
- * // <PageRenameForm id={ 1 } />
96
- * ```
97
- *
98
- * In the above example, updating and saving the page title is handled
99
- * via the `edit()` and `save()` mutation helpers provided by
100
- * `useEntityRecord()`;
101
- *
102
- * @return Entity record data.
103
- * @template RecordType
104
- */
105
- export default function useEntityRecord(kind, name, recordId, options = {
106
- enabled: true
107
- }) {
108
- const {
109
- editEntityRecord,
110
- saveEditedEntityRecord
111
- } = useDispatch(coreStore);
112
- const mutations = useMemo(() => ({
113
- edit: (record, editOptions = {}) => editEntityRecord(kind, name, recordId, record, editOptions),
114
- save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
115
- throwOnError: true,
116
- ...saveOptions
117
- })
118
- }), [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]);
119
- const {
120
- editedRecord,
121
- hasEdits,
122
- edits
123
- } = useSelect(select => {
124
- if (!options.enabled) {
125
- return {
126
- editedRecord: EMPTY_OBJECT,
127
- hasEdits: false,
128
- edits: EMPTY_OBJECT
129
- };
130
- }
131
- return {
132
- editedRecord: select(coreStore).getEditedEntityRecord(kind, name, recordId),
133
- hasEdits: select(coreStore).hasEditsForEntityRecord(kind, name, recordId),
134
- edits: select(coreStore).getEntityRecordNonTransientEdits(kind, name, recordId)
135
- };
136
- }, [kind, name, recordId, options.enabled]);
137
- const {
138
- data: record,
139
- ...querySelectRest
140
- } = useQuerySelect(query => {
141
- if (!options.enabled) {
7
+ function useEntityRecord(kind, name, recordId, options = { enabled: true }) {
8
+ const { editEntityRecord, saveEditedEntityRecord } = useDispatch(coreStore);
9
+ const mutations = useMemo(
10
+ () => ({
11
+ edit: (record2, editOptions = {}) => editEntityRecord(kind, name, recordId, record2, editOptions),
12
+ save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
13
+ throwOnError: true,
14
+ ...saveOptions
15
+ })
16
+ }),
17
+ [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]
18
+ );
19
+ const { editedRecord, hasEdits, edits } = useSelect(
20
+ (select) => {
21
+ if (!options.enabled) {
22
+ return {
23
+ editedRecord: EMPTY_OBJECT,
24
+ hasEdits: false,
25
+ edits: EMPTY_OBJECT
26
+ };
27
+ }
142
28
  return {
143
- data: null
29
+ editedRecord: select(coreStore).getEditedEntityRecord(
30
+ kind,
31
+ name,
32
+ recordId
33
+ ),
34
+ hasEdits: select(coreStore).hasEditsForEntityRecord(
35
+ kind,
36
+ name,
37
+ recordId
38
+ ),
39
+ edits: select(coreStore).getEntityRecordNonTransientEdits(
40
+ kind,
41
+ name,
42
+ recordId
43
+ )
144
44
  };
145
- }
146
- return query(coreStore).getEntityRecord(kind, name, recordId);
147
- }, [kind, name, recordId, options.enabled]);
45
+ },
46
+ [kind, name, recordId, options.enabled]
47
+ );
48
+ const { data: record, ...querySelectRest } = useQuerySelect(
49
+ (query) => {
50
+ if (!options.enabled) {
51
+ return {
52
+ data: null
53
+ };
54
+ }
55
+ return query(coreStore).getEntityRecord(kind, name, recordId);
56
+ },
57
+ [kind, name, recordId, options.enabled]
58
+ );
148
59
  return {
149
60
  record,
150
61
  editedRecord,
@@ -154,11 +65,15 @@ export default function useEntityRecord(kind, name, recordId, options = {
154
65
  ...mutations
155
66
  };
156
67
  }
157
- export function __experimentalUseEntityRecord(kind, name, recordId, options) {
68
+ function __experimentalUseEntityRecord(kind, name, recordId, options) {
158
69
  deprecated(`wp.data.__experimentalUseEntityRecord`, {
159
- alternative: 'wp.data.useEntityRecord',
160
- since: '6.1'
70
+ alternative: "wp.data.useEntityRecord",
71
+ since: "6.1"
161
72
  });
162
73
  return useEntityRecord(kind, name, recordId, options);
163
74
  }
164
- //# sourceMappingURL=use-entity-record.js.map
75
+ export {
76
+ __experimentalUseEntityRecord,
77
+ useEntityRecord as default
78
+ };
79
+ //# sourceMappingURL=use-entity-record.js.map