@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,198 +1,191 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { createSelector, createRegistrySelector } from '@wordpress/data';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { getDefaultTemplateId, getEntityRecord } from './selectors';
10
- import { STORE_NAME } from './name';
11
- import { unlock } from './lock-unlock';
12
- import logEntityDeprecation from './utils/log-entity-deprecation';
13
- /**
14
- * Returns the previous edit from the current undo offset
15
- * for the entity records edits history, if any.
16
- *
17
- * @param state State tree.
18
- *
19
- * @return The undo manager.
20
- */
21
- export function getUndoManager(state) {
1
+ import { createSelector, createRegistrySelector } from "@wordpress/data";
2
+ import { getDefaultTemplateId, getEntityRecord } from "./selectors";
3
+ import { STORE_NAME } from "./name";
4
+ import { unlock } from "./lock-unlock";
5
+ import logEntityDeprecation from "./utils/log-entity-deprecation";
6
+ function getUndoManager(state) {
22
7
  return state.undoManager;
23
8
  }
24
-
25
- /**
26
- * Retrieve the fallback Navigation.
27
- *
28
- * @param state Data state.
29
- * @return The ID for the fallback Navigation post.
30
- */
31
- export function getNavigationFallbackId(state) {
9
+ function getNavigationFallbackId(state) {
32
10
  return state.navigationFallbackId;
33
11
  }
34
- export const getBlockPatternsForPostType = createRegistrySelector(select => createSelector((state, postType) => select(STORE_NAME).getBlockPatterns().filter(({
35
- postTypes
36
- }) => !postTypes || Array.isArray(postTypes) && postTypes.includes(postType)), () => [select(STORE_NAME).getBlockPatterns()]));
37
-
38
- /**
39
- * Returns the entity records permissions for the given entity record ids.
40
- */
41
- export const getEntityRecordsPermissions = createRegistrySelector(select => createSelector((state, kind, name, ids) => {
42
- const normalizedIds = Array.isArray(ids) ? ids : [ids];
43
- return normalizedIds.map(id => ({
44
- delete: select(STORE_NAME).canUser('delete', {
45
- kind,
46
- name,
47
- id
48
- }),
49
- update: select(STORE_NAME).canUser('update', {
50
- kind,
51
- name,
52
- id
53
- })
54
- }));
55
- }, state => [state.userPermissions]));
56
-
57
- /**
58
- * Returns the entity record permissions for the given entity record id.
59
- *
60
- * @param state Data state.
61
- * @param kind Entity kind.
62
- * @param name Entity name.
63
- * @param id Entity record id.
64
- *
65
- * @return The entity record permissions.
66
- */
67
- export function getEntityRecordPermissions(state, kind, name, id) {
68
- logEntityDeprecation(kind, name, 'getEntityRecordPermissions');
12
+ const getBlockPatternsForPostType = createRegistrySelector(
13
+ (select) => createSelector(
14
+ (state, postType) => select(STORE_NAME).getBlockPatterns().filter(
15
+ ({ postTypes }) => !postTypes || Array.isArray(postTypes) && postTypes.includes(postType)
16
+ ),
17
+ () => [select(STORE_NAME).getBlockPatterns()]
18
+ )
19
+ );
20
+ const getEntityRecordsPermissions = createRegistrySelector(
21
+ (select) => createSelector(
22
+ (state, kind, name, ids) => {
23
+ const normalizedIds = Array.isArray(ids) ? ids : [ids];
24
+ return normalizedIds.map((id) => ({
25
+ delete: select(STORE_NAME).canUser("delete", {
26
+ kind,
27
+ name,
28
+ id
29
+ }),
30
+ update: select(STORE_NAME).canUser("update", {
31
+ kind,
32
+ name,
33
+ id
34
+ })
35
+ }));
36
+ },
37
+ (state) => [state.userPermissions]
38
+ )
39
+ );
40
+ function getEntityRecordPermissions(state, kind, name, id) {
41
+ logEntityDeprecation(kind, name, "getEntityRecordPermissions");
69
42
  return getEntityRecordsPermissions(state, kind, name, id)[0];
70
43
  }
71
-
72
- /**
73
- * Returns the registered post meta fields for a given post type.
74
- *
75
- * @param state Data state.
76
- * @param postType Post type.
77
- *
78
- * @return Registered post meta fields.
79
- */
80
- export function getRegisteredPostMeta(state, postType) {
81
- var _state$registeredPost;
82
- return (_state$registeredPost = state.registeredPostMeta?.[postType]) !== null && _state$registeredPost !== void 0 ? _state$registeredPost : {};
44
+ function getRegisteredPostMeta(state, postType) {
45
+ return state.registeredPostMeta?.[postType] ?? {};
83
46
  }
84
47
  function normalizePageId(value) {
85
- if (!value || !['number', 'string'].includes(typeof value)) {
48
+ if (!value || !["number", "string"].includes(typeof value)) {
86
49
  return null;
87
50
  }
88
-
89
- // We also need to check if it's not zero (`'0'`).
90
51
  if (Number(value) === 0) {
91
52
  return null;
92
53
  }
93
54
  return value.toString();
94
55
  }
95
- export const getHomePage = createRegistrySelector(select => createSelector(() => {
96
- const siteData = select(STORE_NAME).getEntityRecord('root', '__unstableBase');
97
- // Still resolving getEntityRecord.
98
- if (!siteData) {
99
- return null;
100
- }
101
- const homepageId = siteData?.show_on_front === 'page' ? normalizePageId(siteData.page_on_front) : null;
102
- if (homepageId) {
103
- return {
104
- postType: 'page',
105
- postId: homepageId
106
- };
107
- }
108
- const frontPageTemplateId = select(STORE_NAME).getDefaultTemplateId({
109
- slug: 'front-page'
110
- });
111
- // Still resolving getDefaultTemplateId.
112
- if (!frontPageTemplateId) {
113
- return null;
114
- }
115
- return {
116
- postType: 'wp_template',
117
- postId: frontPageTemplateId
118
- };
119
- }, state => [
120
- // Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,
121
- // it doesn't seem to invalidate this cache, I'm not sure why.
122
- getEntityRecord(state, 'root', 'site'), getEntityRecord(state, 'root', '__unstableBase'), getDefaultTemplateId(state, {
123
- slug: 'front-page'
124
- })]));
125
- export const getPostsPageId = createRegistrySelector(select => () => {
126
- const siteData = select(STORE_NAME).getEntityRecord('root', '__unstableBase');
127
- return siteData?.show_on_front === 'page' ? normalizePageId(siteData.page_for_posts) : null;
56
+ const getHomePage = createRegistrySelector(
57
+ (select) => createSelector(
58
+ () => {
59
+ const siteData = select(STORE_NAME).getEntityRecord(
60
+ "root",
61
+ "__unstableBase"
62
+ );
63
+ if (!siteData) {
64
+ return null;
65
+ }
66
+ const homepageId = siteData?.show_on_front === "page" ? normalizePageId(siteData.page_on_front) : null;
67
+ if (homepageId) {
68
+ return { postType: "page", postId: homepageId };
69
+ }
70
+ const frontPageTemplateId = select(
71
+ STORE_NAME
72
+ ).getDefaultTemplateId({
73
+ slug: "front-page"
74
+ });
75
+ if (!frontPageTemplateId) {
76
+ return null;
77
+ }
78
+ return { postType: "wp_template", postId: frontPageTemplateId };
79
+ },
80
+ (state) => [
81
+ // Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,
82
+ // it doesn't seem to invalidate this cache, I'm not sure why.
83
+ getEntityRecord(state, "root", "site"),
84
+ getEntityRecord(state, "root", "__unstableBase"),
85
+ getDefaultTemplateId(state, {
86
+ slug: "front-page"
87
+ })
88
+ ]
89
+ )
90
+ );
91
+ const getPostsPageId = createRegistrySelector((select) => () => {
92
+ const siteData = select(STORE_NAME).getEntityRecord(
93
+ "root",
94
+ "__unstableBase"
95
+ );
96
+ return siteData?.show_on_front === "page" ? normalizePageId(siteData.page_for_posts) : null;
128
97
  });
129
- export const getTemplateId = createRegistrySelector(select => (state, postType, postId) => {
130
- const homepage = unlock(select(STORE_NAME)).getHomePage();
131
- if (!homepage) {
132
- return;
133
- }
134
-
135
- // For the front page, we always use the front page template if existing.
136
- if (postType === 'page' && postType === homepage?.postType && postId.toString() === homepage?.postId) {
137
- // The /lookup endpoint cannot currently handle a lookup
138
- // when a page is set as the front page, so specifically in
139
- // that case, we want to check if there is a front page
140
- // template, and instead of falling back to the home
141
- // template, we want to fall back to the page template.
142
- const templates = select(STORE_NAME).getEntityRecords('postType', 'wp_template', {
143
- per_page: -1
144
- });
145
- if (!templates) {
98
+ const getTemplateId = createRegistrySelector(
99
+ (select) => (state, postType, postId) => {
100
+ const homepage = unlock(select(STORE_NAME)).getHomePage();
101
+ if (!homepage) {
146
102
  return;
147
103
  }
148
- const id = templates.find(({
149
- slug
150
- }) => slug === 'front-page')?.id;
151
- if (id) {
152
- return id;
104
+ if (postType === "page" && postType === homepage?.postType && postId.toString() === homepage?.postId) {
105
+ const templates = select(STORE_NAME).getEntityRecords(
106
+ "postType",
107
+ "wp_template",
108
+ {
109
+ per_page: -1
110
+ }
111
+ );
112
+ if (!templates) {
113
+ return;
114
+ }
115
+ const id = templates.find(({ slug }) => slug === "front-page")?.id;
116
+ if (id) {
117
+ return id;
118
+ }
119
+ }
120
+ const editedEntity = select(STORE_NAME).getEditedEntityRecord(
121
+ "postType",
122
+ postType,
123
+ postId
124
+ );
125
+ if (!editedEntity) {
126
+ return;
127
+ }
128
+ const postsPageId = unlock(select(STORE_NAME)).getPostsPageId();
129
+ if (postType === "page" && postsPageId === postId.toString()) {
130
+ return select(STORE_NAME).getDefaultTemplateId({
131
+ slug: "home"
132
+ });
133
+ }
134
+ const currentTemplateSlug = editedEntity.template;
135
+ if (currentTemplateSlug) {
136
+ const userTemplates = select(STORE_NAME).getEntityRecords(
137
+ "postType",
138
+ "wp_template",
139
+ { per_page: -1 }
140
+ );
141
+ if (!userTemplates) {
142
+ return;
143
+ }
144
+ const userTemplateWithSlug = userTemplates.find(
145
+ ({ slug }) => slug === currentTemplateSlug
146
+ );
147
+ if (userTemplateWithSlug) {
148
+ return userTemplateWithSlug.id;
149
+ }
150
+ const registeredTemplates = select(STORE_NAME).getEntityRecords(
151
+ "postType",
152
+ "wp_registered_template",
153
+ { per_page: -1 }
154
+ );
155
+ if (!registeredTemplates) {
156
+ return;
157
+ }
158
+ const registeredTemplateWithSlug = registeredTemplates.find(
159
+ ({ slug }) => slug === currentTemplateSlug
160
+ );
161
+ if (registeredTemplateWithSlug) {
162
+ return registeredTemplateWithSlug.id;
163
+ }
164
+ }
165
+ let slugToCheck;
166
+ if (editedEntity.slug) {
167
+ slugToCheck = postType === "page" ? `${postType}-${editedEntity.slug}` : `single-${postType}-${editedEntity.slug}`;
168
+ } else {
169
+ slugToCheck = postType === "page" ? "page" : `single-${postType}`;
153
170
  }
154
- // If no front page template is found, continue with the
155
- // logic below (fetching the page template).
156
- }
157
- const editedEntity = select(STORE_NAME).getEditedEntityRecord('postType', postType, postId);
158
- if (!editedEntity) {
159
- return;
160
- }
161
- const postsPageId = unlock(select(STORE_NAME)).getPostsPageId();
162
- // Check if the current page is the posts page.
163
- if (postType === 'page' && postsPageId === postId.toString()) {
164
171
  return select(STORE_NAME).getDefaultTemplateId({
165
- slug: 'home'
172
+ slug: slugToCheck
166
173
  });
167
174
  }
168
- // First see if the post/page has an assigned template and fetch it.
169
- const currentTemplateSlug = editedEntity.template;
170
- if (currentTemplateSlug) {
171
- const currentTemplate = select(STORE_NAME).getEntityRecords('postType', 'wp_template', {
172
- per_page: -1
173
- })?.find(({
174
- slug
175
- }) => slug === currentTemplateSlug);
176
- if (currentTemplate) {
177
- return currentTemplate.id;
178
- }
179
- }
180
- // If no template is assigned, use the default template.
181
- let slugToCheck;
182
- // In `draft` status we might not have a slug available, so we use the `single`
183
- // post type templates slug(ex page, single-post, single-product etc..).
184
- // Pages do not need the `single` prefix in the slug to be prioritized
185
- // through template hierarchy.
186
- if (editedEntity.slug) {
187
- slugToCheck = postType === 'page' ? `${postType}-${editedEntity.slug}` : `single-${postType}-${editedEntity.slug}`;
188
- } else {
189
- slugToCheck = postType === 'page' ? 'page' : `single-${postType}`;
190
- }
191
- return select(STORE_NAME).getDefaultTemplateId({
192
- slug: slugToCheck
193
- });
194
- });
195
- export function getTemplateAutoDraftId(state, staticTemplateId) {
175
+ );
176
+ function getTemplateAutoDraftId(state, staticTemplateId) {
196
177
  return state.templateAutoDraftId[staticTemplateId];
197
178
  }
198
- //# sourceMappingURL=private-selectors.js.map
179
+ export {
180
+ getBlockPatternsForPostType,
181
+ getEntityRecordPermissions,
182
+ getEntityRecordsPermissions,
183
+ getHomePage,
184
+ getNavigationFallbackId,
185
+ getPostsPageId,
186
+ getRegisteredPostMeta,
187
+ getTemplateAutoDraftId,
188
+ getTemplateId,
189
+ getUndoManager
190
+ };
191
+ //# sourceMappingURL=private-selectors.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["createSelector","createRegistrySelector","getDefaultTemplateId","getEntityRecord","STORE_NAME","unlock","logEntityDeprecation","getUndoManager","state","undoManager","getNavigationFallbackId","navigationFallbackId","getBlockPatternsForPostType","select","postType","getBlockPatterns","filter","postTypes","Array","isArray","includes","getEntityRecordsPermissions","kind","name","ids","normalizedIds","map","id","delete","canUser","update","userPermissions","getEntityRecordPermissions","getRegisteredPostMeta","_state$registeredPost","registeredPostMeta","normalizePageId","value","Number","toString","getHomePage","siteData","homepageId","show_on_front","page_on_front","postId","frontPageTemplateId","slug","getPostsPageId","page_for_posts","getTemplateId","homepage","templates","getEntityRecords","per_page","find","editedEntity","getEditedEntityRecord","postsPageId","currentTemplateSlug","template","currentTemplate","slugToCheck","getTemplateAutoDraftId","staticTemplateId","templateAutoDraftId"],"sources":["@wordpress/core-data/src/private-selectors.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getDefaultTemplateId, getEntityRecord, type State } from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t(\n\t\t\tstate: State,\n\t\t\tkind: string,\n\t\t\tname: string,\n\t\t\tids: string | string[]\n\t\t) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\tlogEntityDeprecation( kind, name, 'getEntityRecordPermissions' );\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'__unstableBase'\n\t\t\t) as SiteData | undefined;\n\t\t\t// Still resolving getEntityRecord.\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\t// Still resolving getDefaultTemplateId.\n\t\t\tif ( ! frontPageTemplateId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn { postType: 'wp_template', postId: frontPageTemplateId };\n\t\t},\n\t\t( state ) => [\n\t\t\t// Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,\n\t\t\t// it doesn't seem to invalidate this cache, I'm not sure why.\n\t\t\tgetEntityRecord( state, 'root', 'site' ),\n\t\t\tgetEntityRecord( state, 'root', '__unstableBase' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t'root',\n\t\t'__unstableBase'\n\t) as SiteData | undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst currentTemplate = select( STORE_NAME )\n\t\t\t\t.getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} )\n\t\t\t\t?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\tif ( currentTemplate ) {\n\t\t\t\treturn currentTemplate.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n\nexport function getTemplateAutoDraftId(\n\tstate: State,\n\tstaticTemplateId: string\n) {\n\treturn state.templateAutoDraftId[ staticTemplateId ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,EAAEC,sBAAsB,QAAQ,iBAAiB;;AAExE;AACA;AACA;AACA,SAASC,oBAAoB,EAAEC,eAAe,QAAoB,aAAa;AAC/E,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,MAAM,QAAQ,eAAe;AACtC,OAAOC,oBAAoB,MAAM,gCAAgC;AAIjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAEC,KAAY,EAAG;EAC9C,OAAOA,KAAK,CAACC,WAAW;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACA;A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T,IAAI,EAAG;IACxBe,WAAW,GACVhD,QAAQ,KAAK,MAAM,GAChB,GAAIA,QAAQ,IAAM0C,YAAY,CAACT,IAAI,EAAG,GACtC,UAAWjC,QAAQ,IAAM0C,YAAY,CAACT,IAAI,EAAG;EAClD,CAAC,MAAM;IACNe,WAAW,GAAGhD,QAAQ,KAAK,MAAM,GAAG,MAAM,GAAG,UAAWA,QAAQ,EAAG;EACpE;EACA,OAAOD,MAAM,CAAET,UAAW,CAAC,CAACF,oBAAoB,CAAE;IACjD6C,IAAI,EAAEe;EACP,CAAE,CAAC;AACJ,CACD,CAAC;AAED,OAAO,SAASC,sBAAsBA,CACrCvD,KAAY,EACZwD,gBAAwB,EACvB;EACD,OAAOxD,KAAK,CAACyD,mBAAmB,CAAED,gBAAgB,CAAE;AACrD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/private-selectors.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getDefaultTemplateId, getEntityRecord, type State } from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\treturn state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t(\n\t\t\tstate: State,\n\t\t\tkind: string,\n\t\t\tname: string,\n\t\t\tids: string | string[]\n\t\t) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\tlogEntityDeprecation( kind, name, 'getEntityRecordPermissions' );\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'__unstableBase'\n\t\t\t) as SiteData | undefined;\n\t\t\t// Still resolving getEntityRecord.\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\t// Still resolving getDefaultTemplateId.\n\t\t\tif ( ! frontPageTemplateId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn { postType: 'wp_template', postId: frontPageTemplateId };\n\t\t},\n\t\t( state ) => [\n\t\t\t// Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,\n\t\t\t// it doesn't seem to invalidate this cache, I'm not sure why.\n\t\t\tgetEntityRecord( state, 'root', 'site' ),\n\t\t\tgetEntityRecord( state, 'root', '__unstableBase' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t'root',\n\t\t'__unstableBase'\n\t) as SiteData | undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst userTemplates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{ per_page: -1 }\n\t\t\t);\n\t\t\tif ( ! userTemplates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst userTemplateWithSlug = userTemplates.find(\n\t\t\t\t( { slug } ) => slug === currentTemplateSlug\n\t\t\t);\n\n\t\t\tif ( userTemplateWithSlug ) {\n\t\t\t\treturn userTemplateWithSlug.id;\n\t\t\t}\n\n\t\t\tconst registeredTemplates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_registered_template',\n\t\t\t\t{ per_page: -1 }\n\t\t\t);\n\n\t\t\tif ( ! registeredTemplates ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst registeredTemplateWithSlug = registeredTemplates.find(\n\t\t\t\t( { slug } ) => slug === currentTemplateSlug\n\t\t\t);\n\n\t\t\tif ( registeredTemplateWithSlug ) {\n\t\t\t\treturn registeredTemplateWithSlug.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n\nexport function getTemplateAutoDraftId(\n\tstate: State,\n\tstaticTemplateId: string\n) {\n\treturn state.templateAutoDraftId[ staticTemplateId ];\n}\n"],
5
+ "mappings": "AAGA,SAAS,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AAEA,UAAK,4BAA6B;AACjC,eAAO,2BAA2B;AAAA,MACnC;AAAA,IACD;AAEA,QAAI;AAKJ,QAAK,aAAa,MAAO;AACxB,oBACC,aAAa,SACV,GAAI,QAAS,IAAK,aAAa,IAAK,KACpC,UAAW,QAAS,IAAK,aAAa,IAAK;AAAA,IAChD,OAAO;AACN,oBAAc,aAAa,SAAS,SAAS,UAAW,QAAS;AAAA,IAClE;AACA,WAAO,OAAQ,UAAW,EAAE,qBAAsB;AAAA,MACjD,MAAM;AAAA,IACP,CAAE;AAAA,EACH;AACD;AAEO,SAAS,uBACf,OACA,kBACC;AACD,SAAO,MAAM,oBAAqB,gBAAiB;AACpD;",
6
+ "names": []
7
+ }
@@ -1,56 +1,29 @@
1
- /**
2
- * Returns an action object used in signalling that items have been received.
3
- *
4
- * @param {Array} items Items received.
5
- * @param {?Object} edits Optional edits to reset.
6
- * @param {?Object} meta Meta information about pagination.
7
- *
8
- * @return {Object} Action object.
9
- */
10
- export function receiveItems(items, edits, meta) {
1
+ function receiveItems(items, edits, meta) {
11
2
  return {
12
- type: 'RECEIVE_ITEMS',
3
+ type: "RECEIVE_ITEMS",
13
4
  items: Array.isArray(items) ? items : [items],
14
5
  persistedEdits: edits,
15
6
  meta
16
7
  };
17
8
  }
18
-
19
- /**
20
- * Returns an action object used in signalling that entity records have been
21
- * deleted and they need to be removed from entities state.
22
- *
23
- * @param {string} kind Kind of the removed entities.
24
- * @param {string} name Name of the removed entities.
25
- * @param {Array|number|string} records Record IDs of the removed entities.
26
- * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
27
- * @return {Object} Action object.
28
- */
29
- export function removeItems(kind, name, records, invalidateCache = false) {
9
+ function removeItems(kind, name, records, invalidateCache = false) {
30
10
  return {
31
- type: 'REMOVE_ITEMS',
11
+ type: "REMOVE_ITEMS",
32
12
  itemIds: Array.isArray(records) ? records : [records],
33
13
  kind,
34
14
  name,
35
15
  invalidateCache
36
16
  };
37
17
  }
38
-
39
- /**
40
- * Returns an action object used in signalling that queried data has been
41
- * received.
42
- *
43
- * @param {Array} items Queried items received.
44
- * @param {?Object} query Optional query object.
45
- * @param {?Object} edits Optional edits to reset.
46
- * @param {?Object} meta Meta information about pagination.
47
- *
48
- * @return {Object} Action object.
49
- */
50
- export function receiveQueriedItems(items, query = {}, edits, meta) {
18
+ function receiveQueriedItems(items, query = {}, edits, meta) {
51
19
  return {
52
20
  ...receiveItems(items, edits, meta),
53
21
  query
54
22
  };
55
23
  }
56
- //# sourceMappingURL=actions.js.map
24
+ export {
25
+ receiveItems,
26
+ receiveQueriedItems,
27
+ removeItems
28
+ };
29
+ //# sourceMappingURL=actions.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["receiveItems","items","edits","meta","type","Array","isArray","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"sources":["@wordpress/core-data/src/queried-data/actions.js"],"sourcesContent":["/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n * @param {?Object} meta Meta information about pagination.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits, meta ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: Array.isArray( items ) ? items : [ items ],\n\t\tpersistedEdits: edits,\n\t\tmeta,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string} kind Kind of the removed entities.\n * @param {string} name Name of the removed entities.\n * @param {Array|number|string} records Record IDs of the removed entities.\n * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.\n * @return {Object} Action object.\n */\nexport function removeItems( kind, name, records, invalidateCache = false ) {\n\treturn {\n\t\ttype: 'REMOVE_ITEMS',\n\t\titemIds: Array.isArray( records ) ? records : [ records ],\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that queried data has been\n * received.\n *\n * @param {Array} items Queried items received.\n * @param {?Object} query Optional query object.\n * @param {?Object} edits Optional edits to reset.\n * @param {?Object} meta Meta information about pagination.\n *\n * @return {Object} Action object.\n */\nexport function receiveQueriedItems( items, query = {}, edits, meta ) {\n\treturn {\n\t\t...receiveItems( items, edits, meta ),\n\t\tquery,\n\t};\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,YAAYA,CAAEC,KAAK,EAAEC,KAAK,EAAEC,IAAI,EAAG;EAClD,OAAO;IACNC,IAAI,EAAE,eAAe;IACrBH,KAAK,EAAEI,KAAK,CAACC,OAAO,CAAEL,KAAM,CAAC,GAAGA,KAAK,GAAG,CAAEA,KAAK,CAAE;IACjDM,cAAc,EAAEL,KAAK;IACrBC;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,WAAWA,CAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,eAAe,GAAG,KAAK,EAAG;EAC3E,OAAO;IACNR,IAAI,EAAE,cAAc;IACpBS,OAAO,EAAER,KAAK,CAACC,OAAO,CAAEK,OAAQ,CAAC,GAAGA,OAAO,GAAG,CAAEA,OAAO,CAAE;IACzDF,IAAI;IACJC,IAAI;IACJE;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,mBAAmBA,CAAEb,KAAK,EAAEc,KAAK,GAAG,CAAC,CAAC,EAAEb,KAAK,EAAEC,IAAI,EAAG;EACrE,OAAO;IACN,GAAGH,YAAY,CAAEC,KAAK,EAAEC,KAAK,EAAEC,IAAK,CAAC;IACrCY;EACD,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/queried-data/actions.js"],
4
+ "sourcesContent": ["/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n * @param {?Object} meta Meta information about pagination.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits, meta ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: Array.isArray( items ) ? items : [ items ],\n\t\tpersistedEdits: edits,\n\t\tmeta,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string} kind Kind of the removed entities.\n * @param {string} name Name of the removed entities.\n * @param {Array|number|string} records Record IDs of the removed entities.\n * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.\n * @return {Object} Action object.\n */\nexport function removeItems( kind, name, records, invalidateCache = false ) {\n\treturn {\n\t\ttype: 'REMOVE_ITEMS',\n\t\titemIds: Array.isArray( records ) ? records : [ records ],\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that queried data has been\n * received.\n *\n * @param {Array} items Queried items received.\n * @param {?Object} query Optional query object.\n * @param {?Object} edits Optional edits to reset.\n * @param {?Object} meta Meta information about pagination.\n *\n * @return {Object} Action object.\n */\nexport function receiveQueriedItems( items, query = {}, edits, meta ) {\n\treturn {\n\t\t...receiveItems( items, edits, meta ),\n\t\tquery,\n\t};\n}\n"],
5
+ "mappings": "AASO,SAAS,aAAc,OAAO,OAAO,MAAO;AAClD,SAAO;AAAA,IACN,MAAM;AAAA,IACN,OAAO,MAAM,QAAS,KAAM,IAAI,QAAQ,CAAE,KAAM;AAAA,IAChD,gBAAgB;AAAA,IAChB;AAAA,EACD;AACD;AAYO,SAAS,YAAa,MAAM,MAAM,SAAS,kBAAkB,OAAQ;AAC3E,SAAO;AAAA,IACN,MAAM;AAAA,IACN,SAAS,MAAM,QAAS,OAAQ,IAAI,UAAU,CAAE,OAAQ;AAAA,IACxD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAaO,SAAS,oBAAqB,OAAO,QAAQ,CAAC,GAAG,OAAO,MAAO;AACrE,SAAO;AAAA,IACN,GAAG,aAAc,OAAO,OAAO,IAAK;AAAA,IACpC;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -1,103 +1,48 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { addQueryArgs } from '@wordpress/url';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
- import { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';
10
-
11
- /**
12
- * An object of properties describing a specific query.
13
- *
14
- * @typedef {Object} WPQueriedDataQueryParts
15
- *
16
- * @property {number} page The query page (1-based index, default 1).
17
- * @property {number} perPage Items per page for query (default 10).
18
- * @property {string} stableKey An encoded stable string of all non-
19
- * pagination, non-fields query parameters.
20
- * @property {?(string[])} fields Target subset of fields to derive from
21
- * item objects.
22
- * @property {?(number[])} include Specific item IDs to include.
23
- * @property {string} context Scope under which the request is made;
24
- * determines returned fields in response.
25
- */
26
-
27
- /**
28
- * Given a query object, returns an object of parts, including pagination
29
- * details (`page` and `perPage`, or default values). All other properties are
30
- * encoded into a stable (idempotent) `stableKey` value.
31
- *
32
- * @param {Object} query Optional query object.
33
- *
34
- * @return {WPQueriedDataQueryParts} Query parts.
35
- */
36
- export function getQueryParts(query) {
37
- /**
38
- * @type {WPQueriedDataQueryParts}
39
- */
1
+ import { addQueryArgs } from "@wordpress/url";
2
+ import { withWeakMapCache, getNormalizedCommaSeparable } from "../utils";
3
+ function getQueryParts(query) {
40
4
  const parts = {
41
- stableKey: '',
5
+ stableKey: "",
42
6
  page: 1,
43
7
  perPage: 10,
44
8
  fields: null,
45
9
  include: null,
46
- context: 'default'
10
+ context: "default"
47
11
  };
48
-
49
- // Ensure stable key by sorting keys. Also more efficient for iterating.
50
12
  const keys = Object.keys(query).sort();
51
13
  for (let i = 0; i < keys.length; i++) {
52
14
  const key = keys[i];
53
15
  let value = query[key];
54
16
  switch (key) {
55
- case 'page':
17
+ case "page":
56
18
  parts[key] = Number(value);
57
19
  break;
58
- case 'per_page':
20
+ case "per_page":
59
21
  parts.perPage = Number(value);
60
22
  break;
61
- case 'context':
23
+ case "context":
62
24
  parts.context = value;
63
25
  break;
64
26
  default:
65
- // While in theory, we could exclude "_fields" from the stableKey
66
- // because two request with different fields have the same results
67
- // We're not able to ensure that because the server can decide to omit
68
- // fields from the response even if we explicitly asked for it.
69
- // Example: Asking for titles in posts without title support.
70
- if (key === '_fields') {
71
- var _getNormalizedCommaSe;
72
- parts.fields = (_getNormalizedCommaSe = getNormalizedCommaSeparable(value)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : [];
73
- // Make sure to normalize value for `stableKey`
27
+ if (key === "_fields") {
28
+ parts.fields = getNormalizedCommaSeparable(value) ?? [];
74
29
  value = parts.fields.join();
75
30
  }
76
-
77
- // Two requests with different include values cannot have same results.
78
- if (key === 'include') {
79
- var _getNormalizedCommaSe2;
80
- if (typeof value === 'number') {
31
+ if (key === "include") {
32
+ if (typeof value === "number") {
81
33
  value = value.toString();
82
34
  }
83
- parts.include = ((_getNormalizedCommaSe2 = getNormalizedCommaSeparable(value)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []).map(Number);
84
- // Normalize value for `stableKey`.
35
+ parts.include = (getNormalizedCommaSeparable(value) ?? []).map(Number);
85
36
  value = parts.include.join();
86
37
  }
87
-
88
- // While it could be any deterministic string, for simplicity's
89
- // sake mimic querystring encoding for stable key.
90
- //
91
- // TODO: For consistency with PHP implementation, addQueryArgs
92
- // should accept a key value pair, which may optimize its
93
- // implementation for our use here, vs. iterating an object
94
- // with only a single key.
95
- parts.stableKey += (parts.stableKey ? '&' : '') + addQueryArgs('', {
96
- [key]: value
97
- }).slice(1);
38
+ parts.stableKey += (parts.stableKey ? "&" : "") + addQueryArgs("", { [key]: value }).slice(1);
98
39
  }
99
40
  }
100
41
  return parts;
101
42
  }
102
- export default withWeakMapCache(getQueryParts);
103
- //# sourceMappingURL=get-query-parts.js.map
43
+ var get_query_parts_default = withWeakMapCache(getQueryParts);
44
+ export {
45
+ get_query_parts_default as default,
46
+ getQueryParts
47
+ };
48
+ //# sourceMappingURL=get-query-parts.js.map