@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
@@ -0,0 +1,255 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ import fastDeepEqual from "fast-deep-equal/es6";
3
+ import { RichTextData } from "@wordpress/rich-text";
4
+ import { Y } from "@wordpress/sync";
5
+ import { getBlockTypes } from "@wordpress/blocks";
6
+ const serializableBlocksCache = /* @__PURE__ */ new WeakMap();
7
+ function makeBlockAttributesSerializable(attributes) {
8
+ const newAttributes = { ...attributes };
9
+ for (const [key, value] of Object.entries(attributes)) {
10
+ if (value instanceof RichTextData) {
11
+ newAttributes[key] = value.valueOf();
12
+ }
13
+ }
14
+ return newAttributes;
15
+ }
16
+ function makeBlocksSerializable(blocks) {
17
+ return blocks.map((block) => {
18
+ const blockAsJson = block instanceof Y.Map ? block.toJSON() : block;
19
+ const { name, innerBlocks, attributes, ...rest } = blockAsJson;
20
+ delete rest.validationIssues;
21
+ delete rest.originalContent;
22
+ return {
23
+ ...rest,
24
+ name,
25
+ attributes: makeBlockAttributesSerializable(attributes),
26
+ innerBlocks: makeBlocksSerializable(innerBlocks)
27
+ };
28
+ });
29
+ }
30
+ function areBlocksEqual(gblock, yblock) {
31
+ const yblockAsJson = yblock.toJSON();
32
+ const overwrites = {
33
+ innerBlocks: null,
34
+ clientId: null
35
+ };
36
+ const res = fastDeepEqual(
37
+ Object.assign({}, gblock, overwrites),
38
+ Object.assign({}, yblockAsJson, overwrites)
39
+ );
40
+ const inners = gblock.innerBlocks || [];
41
+ const yinners = yblock.get("innerBlocks");
42
+ return res && inners.length === yinners.length && inners.every(
43
+ (block, i) => areBlocksEqual(block, yinners.get(i))
44
+ );
45
+ }
46
+ function createNewYAttributeMap(blockName, attributes) {
47
+ return new Y.Map(
48
+ Object.entries(attributes).map(
49
+ ([attributeName, attributeValue]) => {
50
+ return [
51
+ attributeName,
52
+ createNewYAttributeValue(
53
+ blockName,
54
+ attributeName,
55
+ attributeValue
56
+ )
57
+ ];
58
+ }
59
+ )
60
+ );
61
+ }
62
+ function createNewYAttributeValue(blockName, attributeName, attributeValue) {
63
+ const isRichText = isRichTextAttribute(blockName, attributeName);
64
+ if (isRichText) {
65
+ return new Y.Text(attributeValue?.toString() ?? "");
66
+ }
67
+ return attributeValue;
68
+ }
69
+ function createNewYBlock(block) {
70
+ return new Y.Map(
71
+ Object.entries(block).map(([key, value]) => {
72
+ switch (key) {
73
+ case "attributes": {
74
+ return [key, createNewYAttributeMap(block.name, value)];
75
+ }
76
+ case "innerBlocks": {
77
+ const innerBlocks = new Y.Array();
78
+ if (!Array.isArray(value)) {
79
+ return [key, innerBlocks];
80
+ }
81
+ innerBlocks.insert(
82
+ 0,
83
+ value.map(
84
+ (innerBlock) => createNewYBlock(innerBlock)
85
+ )
86
+ );
87
+ return [key, innerBlocks];
88
+ }
89
+ default:
90
+ return [key, value];
91
+ }
92
+ })
93
+ );
94
+ }
95
+ function mergeCrdtBlocks(yblocks, incomingBlocks, lastSelection) {
96
+ if (!serializableBlocksCache.has(incomingBlocks)) {
97
+ serializableBlocksCache.set(
98
+ incomingBlocks,
99
+ makeBlocksSerializable(incomingBlocks)
100
+ );
101
+ }
102
+ const allBlocks = serializableBlocksCache.get(incomingBlocks) ?? [];
103
+ const blocksToSync = allBlocks.filter(
104
+ (block) => shouldBlockBeSynced(block)
105
+ );
106
+ const numOfCommonEntries = Math.min(
107
+ blocksToSync.length ?? 0,
108
+ yblocks.length
109
+ );
110
+ let left = 0;
111
+ let right = 0;
112
+ for (; left < numOfCommonEntries && areBlocksEqual(blocksToSync[left], yblocks.get(left)); left++) {
113
+ }
114
+ for (; right < numOfCommonEntries - left && areBlocksEqual(
115
+ blocksToSync[blocksToSync.length - right - 1],
116
+ yblocks.get(yblocks.length - right - 1)
117
+ ); right++) {
118
+ }
119
+ const numOfUpdatesNeeded = numOfCommonEntries - left - right;
120
+ const numOfInsertionsNeeded = Math.max(
121
+ 0,
122
+ blocksToSync.length - yblocks.length
123
+ );
124
+ const numOfDeletionsNeeded = Math.max(
125
+ 0,
126
+ yblocks.length - blocksToSync.length
127
+ );
128
+ for (let i = 0; i < numOfUpdatesNeeded; i++, left++) {
129
+ const block = blocksToSync[left];
130
+ const yblock = yblocks.get(left);
131
+ Object.entries(block).forEach(([key, value]) => {
132
+ switch (key) {
133
+ case "attributes": {
134
+ const currentAttributes = yblock.get(
135
+ key
136
+ );
137
+ if (!currentAttributes) {
138
+ yblock.set(
139
+ key,
140
+ createNewYAttributeMap(block.name, value)
141
+ );
142
+ break;
143
+ }
144
+ Object.entries(value).forEach(
145
+ ([attributeName, attributeValue]) => {
146
+ if (fastDeepEqual(
147
+ currentAttributes?.get(attributeName),
148
+ attributeValue
149
+ )) {
150
+ return;
151
+ }
152
+ const isRichText = isRichTextAttribute(
153
+ block.name,
154
+ attributeName
155
+ );
156
+ if (isRichText && "string" === typeof attributeValue) {
157
+ const blockYText = currentAttributes.get(
158
+ attributeName
159
+ );
160
+ mergeRichTextUpdate(
161
+ blockYText,
162
+ attributeValue,
163
+ lastSelection
164
+ );
165
+ } else {
166
+ currentAttributes.set(
167
+ attributeName,
168
+ createNewYAttributeValue(
169
+ block.name,
170
+ attributeName,
171
+ attributeValue
172
+ )
173
+ );
174
+ }
175
+ }
176
+ );
177
+ currentAttributes.forEach(
178
+ (_attrValue, attrName) => {
179
+ if (!value.hasOwnProperty(attrName)) {
180
+ currentAttributes.delete(attrName);
181
+ }
182
+ }
183
+ );
184
+ break;
185
+ }
186
+ case "innerBlocks": {
187
+ const yInnerBlocks = yblock.get(key);
188
+ mergeCrdtBlocks(yInnerBlocks, value ?? [], lastSelection);
189
+ break;
190
+ }
191
+ default:
192
+ if (!fastDeepEqual(block[key], yblock.get(key))) {
193
+ yblock.set(key, value);
194
+ }
195
+ }
196
+ });
197
+ yblock.forEach((_v, k) => {
198
+ if (!block.hasOwnProperty(k)) {
199
+ yblock.delete(k);
200
+ }
201
+ });
202
+ }
203
+ yblocks.delete(left, numOfDeletionsNeeded);
204
+ for (let i = 0; i < numOfInsertionsNeeded; i++, left++) {
205
+ const newBlock = [createNewYBlock(blocksToSync[left])];
206
+ yblocks.insert(left, newBlock);
207
+ }
208
+ const knownClientIds = /* @__PURE__ */ new Set();
209
+ for (let j = 0; j < yblocks.length; j++) {
210
+ const yblock = yblocks.get(j);
211
+ let clientId = yblock.get("clientId");
212
+ if (knownClientIds.has(clientId)) {
213
+ clientId = uuidv4();
214
+ yblock.set("clientId", clientId);
215
+ }
216
+ knownClientIds.add(clientId);
217
+ }
218
+ }
219
+ function shouldBlockBeSynced(block) {
220
+ if ("core/gallery" === block.name) {
221
+ return !block.innerBlocks.some(
222
+ (innerBlock) => innerBlock.attributes && innerBlock.attributes.blob
223
+ );
224
+ }
225
+ return true;
226
+ }
227
+ let cachedRichTextAttributes;
228
+ function isRichTextAttribute(blockName, attributeName) {
229
+ if (!cachedRichTextAttributes) {
230
+ cachedRichTextAttributes = /* @__PURE__ */ new Map();
231
+ for (const blockType of getBlockTypes()) {
232
+ const richTextAttributeMap = /* @__PURE__ */ new Map();
233
+ for (const [name, definition] of Object.entries(
234
+ blockType.attributes ?? {}
235
+ )) {
236
+ if ("rich-text" === definition.type) {
237
+ richTextAttributeMap.set(name, true);
238
+ }
239
+ }
240
+ cachedRichTextAttributes.set(
241
+ blockType.name,
242
+ richTextAttributeMap
243
+ );
244
+ }
245
+ }
246
+ return cachedRichTextAttributes.get(blockName)?.has(attributeName) ?? false;
247
+ }
248
+ function mergeRichTextUpdate(blockYText, updatedValue, lastSelection) {
249
+ blockYText.delete(0, blockYText.toString().length);
250
+ blockYText.insert(0, updatedValue);
251
+ }
252
+ export {
253
+ mergeCrdtBlocks
254
+ };
255
+ //# sourceMappingURL=crdt-blocks.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/crdt-blocks.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { v4 as uuidv4 } from 'uuid';\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { RichTextData } from '@wordpress/rich-text';\nimport { Y } from '@wordpress/sync';\n\n// @ts-expect-error No exported types.\nimport { getBlockTypes } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport type { WPBlockSelection } from '../types';\n\ninterface BlockAttributes {\n\t[ key: string ]: unknown;\n}\n\ninterface BlockType {\n\tname: string;\n\tattributes?: Record< string, { type?: string } >;\n}\n\nexport interface Block {\n\tattributes: BlockAttributes;\n\tclientId?: string;\n\tinnerBlocks: Block[];\n\toriginalContent?: string; // unserializable\n\tvalidationIssues?: string[]; // unserializable\n\tname: string;\n}\n\nexport type YBlock = Y.Map<\n\t/* name, clientId, and originalContent are strings. */\n\t| string\n\t/* validationIssues? is an array of strings. */\n\t| string[]\n\t/* attributes is a Y.Map< unknown >. */\n\t| YBlockAttributes\n\t/* innerBlocks is a Y.Array< YBlock >. */\n\t| YBlocks\n>;\n\nexport type YBlocks = Y.Array< YBlock >;\nexport type YBlockAttributes = Y.Map< Y.Text | unknown >;\n\n// The Y.Map type is not easy to work with. The generic type it accepts represents\n// the possible values of the map, which are varied in our case. This type is\n// accurate, but will require aggressive type narrowing when the map values are\n// accessed -- or type casting with `as`.\n// export type YBlock = Y.Map< Block[ keyof Block ] >;\n\nconst serializableBlocksCache = new WeakMap< WeakKey, Block[] >();\n\nfunction makeBlockAttributesSerializable(\n\tattributes: BlockAttributes\n): BlockAttributes {\n\tconst newAttributes = { ...attributes };\n\tfor ( const [ key, value ] of Object.entries( attributes ) ) {\n\t\tif ( value instanceof RichTextData ) {\n\t\t\tnewAttributes[ key ] = value.valueOf();\n\t\t}\n\t}\n\treturn newAttributes;\n}\n\nfunction makeBlocksSerializable( blocks: Block[] | YBlocks ): Block[] {\n\treturn blocks.map( ( block: Block | YBlock ) => {\n\t\tconst blockAsJson = block instanceof Y.Map ? block.toJSON() : block;\n\t\tconst { name, innerBlocks, attributes, ...rest } = blockAsJson;\n\t\tdelete rest.validationIssues;\n\t\tdelete rest.originalContent;\n\t\t// delete rest.isValid\n\t\treturn {\n\t\t\t...rest,\n\t\t\tname,\n\t\t\tattributes: makeBlockAttributesSerializable( attributes ),\n\t\t\tinnerBlocks: makeBlocksSerializable( innerBlocks ),\n\t\t};\n\t} );\n}\n\n/**\n * @param {any} gblock\n * @param {Y.Map} yblock\n */\nfunction areBlocksEqual( gblock: Block, yblock: YBlock ): boolean {\n\tconst yblockAsJson = yblock.toJSON();\n\n\t// we must not sync clientId, as this can't be generated consistently and\n\t// hence will lead to merge conflicts.\n\tconst overwrites = {\n\t\tinnerBlocks: null,\n\t\tclientId: null,\n\t};\n\tconst res = fastDeepEqual(\n\t\tObject.assign( {}, gblock, overwrites ),\n\t\tObject.assign( {}, yblockAsJson, overwrites )\n\t);\n\tconst inners = gblock.innerBlocks || [];\n\tconst yinners = yblock.get( 'innerBlocks' ) as YBlocks;\n\treturn (\n\t\tres &&\n\t\tinners.length === yinners.length &&\n\t\tinners.every( ( block: Block, i: number ) =>\n\t\t\tareBlocksEqual( block, yinners.get( i ) )\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeMap(\n\tblockName: string,\n\tattributes: BlockAttributes\n): YBlockAttributes {\n\treturn new Y.Map(\n\t\tObject.entries( attributes ).map(\n\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\treturn [\n\t\t\t\t\tattributeName,\n\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\tblockName,\n\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\tattributeValue\n\t\t\t\t\t),\n\t\t\t\t];\n\t\t\t}\n\t\t)\n\t);\n}\n\nfunction createNewYAttributeValue(\n\tblockName: string,\n\tattributeName: string,\n\tattributeValue: unknown\n): Y.Text | unknown {\n\tconst isRichText = isRichTextAttribute( blockName, attributeName );\n\n\tif ( isRichText ) {\n\t\treturn new Y.Text( attributeValue?.toString() ?? '' );\n\t}\n\n\treturn attributeValue;\n}\n\nfunction createNewYBlock( block: Block ): YBlock {\n\treturn new Y.Map(\n\t\tObject.entries( block ).map( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\treturn [ key, createNewYAttributeMap( block.name, value ) ];\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\tconst innerBlocks = new Y.Array();\n\n\t\t\t\t\t// If not an array, set to empty Y.Array.\n\t\t\t\t\tif ( ! Array.isArray( value ) ) {\n\t\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t\t}\n\n\t\t\t\t\tinnerBlocks.insert(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tvalue.map( ( innerBlock: Block ) =>\n\t\t\t\t\t\t\tcreateNewYBlock( innerBlock )\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\n\t\t\t\t\treturn [ key, innerBlocks ];\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\treturn [ key, value ];\n\t\t\t}\n\t\t} )\n\t);\n}\n\n/**\n * Merge incoming block data into the local Y.Doc.\n * This function is called to sync local block changes to a shared Y.Doc.\n *\n * @param yblocks The blocks in the local Y.Doc.\n * @param incomingBlocks Gutenberg blocks being synced, either from a peer or from the local editor.\n * @param lastSelection The last cursor position, used for hinting the diff algorithm.\n */\nexport function mergeCrdtBlocks(\n\tyblocks: YBlocks,\n\tincomingBlocks: Block[],\n\tlastSelection: WPBlockSelection | null\n): void {\n\t// Ensure we are working with serializable block data.\n\tif ( ! serializableBlocksCache.has( incomingBlocks ) ) {\n\t\tserializableBlocksCache.set(\n\t\t\tincomingBlocks,\n\t\t\tmakeBlocksSerializable( incomingBlocks )\n\t\t);\n\t}\n\tconst allBlocks = serializableBlocksCache.get( incomingBlocks ) ?? [];\n\n\t// Ensure we skip blocks that we don't want to sync at the moment\n\tconst blocksToSync = allBlocks.filter( ( block ) =>\n\t\tshouldBlockBeSynced( block )\n\t);\n\n\t// This is a rudimentary diff implementation similar to the y-prosemirror diffing\n\t// approach.\n\t// A better implementation would also diff the textual content and represent it\n\t// using a Y.Text type.\n\t// However, at this time it makes more sense to keep this algorithm generic to\n\t// support all kinds of block types.\n\t// Ideally, we ensure that block data structure have a consistent data format.\n\t// E.g.:\n\t// - textual content (using rich-text formatting?) may always be stored under `block.text`\n\t// - local information that shouldn't be shared (e.g. clientId or isDragging) is stored under `block.private`\n\t//\n\t// @credit Kevin Jahns (dmonad)\n\t// @link https://github.com/WordPress/gutenberg/pull/68483\n\tconst numOfCommonEntries = Math.min(\n\t\tblocksToSync.length ?? 0,\n\t\tyblocks.length\n\t);\n\n\tlet left = 0;\n\tlet right = 0;\n\n\t// skip equal blocks from left\n\tfor (\n\t\t;\n\t\tleft < numOfCommonEntries &&\n\t\tareBlocksEqual( blocksToSync[ left ], yblocks.get( left ) );\n\t\tleft++\n\t) {\n\t\t/* nop */\n\t}\n\n\t// skip equal blocks from right\n\tfor (\n\t\t;\n\t\tright < numOfCommonEntries - left &&\n\t\tareBlocksEqual(\n\t\t\tblocksToSync[ blocksToSync.length - right - 1 ],\n\t\t\tyblocks.get( yblocks.length - right - 1 )\n\t\t);\n\t\tright++\n\t) {\n\t\t/* nop */\n\t}\n\n\tconst numOfUpdatesNeeded = numOfCommonEntries - left - right;\n\tconst numOfInsertionsNeeded = Math.max(\n\t\t0,\n\t\tblocksToSync.length - yblocks.length\n\t);\n\tconst numOfDeletionsNeeded = Math.max(\n\t\t0,\n\t\tyblocks.length - blocksToSync.length\n\t);\n\n\t// updates\n\tfor ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {\n\t\tconst block = blocksToSync[ left ];\n\t\tconst yblock = yblocks.get( left );\n\t\tObject.entries( block ).forEach( ( [ key, value ] ) => {\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'attributes': {\n\t\t\t\t\tconst currentAttributes = yblock.get(\n\t\t\t\t\t\tkey\n\t\t\t\t\t) as YBlockAttributes;\n\n\t\t\t\t\t// If attributes are not set on the yblock, use the new values.\n\t\t\t\t\tif ( ! currentAttributes ) {\n\t\t\t\t\t\tyblock.set(\n\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\tcreateNewYAttributeMap( block.name, value )\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\n\t\t\t\t\tObject.entries( value ).forEach(\n\t\t\t\t\t\t( [ attributeName, attributeValue ] ) => {\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tfastDeepEqual(\n\t\t\t\t\t\t\t\t\tcurrentAttributes?.get( attributeName ),\n\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst isRichText = isRichTextAttribute(\n\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tisRichText &&\n\t\t\t\t\t\t\t\t'string' === typeof attributeValue\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t// Rich text values are stored as persistent Y.Text instances.\n\t\t\t\t\t\t\t\t// Update the value with a delta in place.\n\t\t\t\t\t\t\t\tconst blockYText = currentAttributes.get(\n\t\t\t\t\t\t\t\t\tattributeName\n\t\t\t\t\t\t\t\t) as Y.Text;\n\n\t\t\t\t\t\t\t\tmergeRichTextUpdate(\n\t\t\t\t\t\t\t\t\tblockYText,\n\t\t\t\t\t\t\t\t\tattributeValue,\n\t\t\t\t\t\t\t\t\tlastSelection\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tcurrentAttributes.set(\n\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\tcreateNewYAttributeValue(\n\t\t\t\t\t\t\t\t\t\tblock.name,\n\t\t\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\t\t\tattributeValue\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\t// Delete any attributes that are no longer present.\n\t\t\t\t\tcurrentAttributes.forEach(\n\t\t\t\t\t\t( _attrValue: unknown, attrName: string ) => {\n\t\t\t\t\t\t\tif ( ! value.hasOwnProperty( attrName ) ) {\n\t\t\t\t\t\t\t\tcurrentAttributes.delete( attrName );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase 'innerBlocks': {\n\t\t\t\t\t// Recursively merge innerBlocks\n\t\t\t\t\tconst yInnerBlocks = yblock.get( key ) as Y.Array< YBlock >;\n\t\t\t\t\tmergeCrdtBlocks( yInnerBlocks, value ?? [], lastSelection );\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault:\n\t\t\t\t\tif ( ! fastDeepEqual( block[ key ], yblock.get( key ) ) ) {\n\t\t\t\t\t\tyblock.set( key, value );\n\t\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t\tyblock.forEach( ( _v, k ) => {\n\t\t\tif ( ! block.hasOwnProperty( k ) ) {\n\t\t\t\tyblock.delete( k );\n\t\t\t}\n\t\t} );\n\t}\n\n\t// deletes\n\tyblocks.delete( left, numOfDeletionsNeeded );\n\n\t// inserts\n\tfor ( let i = 0; i < numOfInsertionsNeeded; i++, left++ ) {\n\t\tconst newBlock = [ createNewYBlock( blocksToSync[ left ] ) ];\n\n\t\tyblocks.insert( left, newBlock );\n\t}\n\n\t// remove duplicate clientids\n\tconst knownClientIds = new Set< string >();\n\tfor ( let j = 0; j < yblocks.length; j++ ) {\n\t\tconst yblock: YBlock = yblocks.get( j );\n\n\t\tlet clientId: string = yblock.get( 'clientId' ) as string;\n\n\t\tif ( knownClientIds.has( clientId ) ) {\n\t\t\tclientId = uuidv4();\n\t\t\tyblock.set( 'clientId', clientId );\n\t\t}\n\t\tknownClientIds.add( clientId );\n\t}\n}\n\n/**\n * Determine if a block should be synced.\n *\n * Ex: A gallery block should not be synced until the images have been\n * uploaded to WordPress, and their url is available. Before that,\n * it's not possible to access the blobs on a client as those are\n * local.\n *\n * @param block The block to check.\n * @return True if the block should be synced, false otherwise.\n */\nfunction shouldBlockBeSynced( block: Block ): boolean {\n\t// Verify that the gallery block is ready to be synced.\n\t// This means that, all images have had their blobs converted to full URLs.\n\t// Checking for only the blobs ensures that blocks that have just been inserted work as well.\n\tif ( 'core/gallery' === block.name ) {\n\t\treturn ! block.innerBlocks.some(\n\t\t\t( innerBlock ) =>\n\t\t\t\tinnerBlock.attributes && innerBlock.attributes.blob\n\t\t);\n\t}\n\n\t// Allow all other blocks to be synced.\n\treturn true;\n}\n\n// Cache rich-text attributes for all block types.\nlet cachedRichTextAttributes: Map< string, Map< string, true > >;\n\n/**\n * Given a block name and attribute key, return true if the attribute is rich-text typed.\n *\n * @param blockName The name of the block, e.g. 'core/paragraph'.\n * @param attributeName The name of the attribute to check, e.g. 'content'.\n * @return True if the attribute is rich-text typed, false otherwise.\n */\nfunction isRichTextAttribute(\n\tblockName: string,\n\tattributeName: string\n): boolean {\n\tif ( ! cachedRichTextAttributes ) {\n\t\t// Parse the attributes for all blocks once.\n\t\tcachedRichTextAttributes = new Map< string, Map< string, true > >();\n\n\t\tfor ( const blockType of getBlockTypes() as BlockType[] ) {\n\t\t\tconst richTextAttributeMap = new Map< string, true >();\n\n\t\t\tfor ( const [ name, definition ] of Object.entries(\n\t\t\t\tblockType.attributes ?? {}\n\t\t\t) ) {\n\t\t\t\tif ( 'rich-text' === definition.type ) {\n\t\t\t\t\trichTextAttributeMap.set( name, true );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tcachedRichTextAttributes.set(\n\t\t\t\tblockType.name,\n\t\t\t\trichTextAttributeMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn (\n\t\tcachedRichTextAttributes.get( blockName )?.has( attributeName ) ?? false\n\t);\n}\n\n/**\n * Given a Y.Text object and an updated string value, diff the new value and\n * apply the delta to the Y.Text.\n *\n * @param blockYText The Y.Text to update.\n * @param updatedValue The updated value.\n * @param lastSelection The last cursor position before this update, used to hint the diff algorithm.\n */\nfunction mergeRichTextUpdate(\n\tblockYText: Y.Text,\n\tupdatedValue: string,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tlastSelection: WPBlockSelection | null\n): void {\n\t// TODO\n\t// ====\n\t// Gutenberg does not use Yjs shared types natively, so we can only subscribe\n\t// to changes from store and apply them to Yjs types that we create and\n\t// manage. Crucially, for rich-text attributes, we do not receive granular\n\t// string updates; we get the new full string value on each change, even when\n\t// only a single character changed.\n\t//\n\t// The code below allows us to compute a delta between the current and new\n\t// value, then apply it to the Y.Text. However, it relies on a library\n\t// (quill-delta) with a licensing issue that we are working to resolve.\n\t//\n\t// For now, we simply replace the full text content on each change.\n\t//\n\t// if ( ! localDoc ) {\n\t// \t// Y.Text must be attached to a Y.Doc to be able to do operations on it.\n\t// \t// Create a temporary Y.Text attached to a local Y.Doc for delta computation.\n\t// \tlocalDoc = new Y.Doc();\n\t// }\n\n\t// const localYText = localDoc.getText( 'temporary-text' );\n\t// localYText.delete( 0, localYText.length );\n\t// localYText.insert( 0, updatedValue );\n\n\t// const currentValueAsDelta = new Delta( blockYText.toDelta() );\n\t// const updatedValueAsDelta = new Delta( localYText.toDelta() );\n\n\t// const deltaDiff = currentValueAsDelta.diff(\n\t// \tupdatedValueAsDelta,\n\t// \tlastSelection?.offset\n\t// );\n\n\t// blockYText.applyDelta( deltaDiff.ops );\n\n\tblockYText.delete( 0, blockYText.toString().length );\n\tblockYText.insert( 0, updatedValue );\n}\n"],
5
+ "mappings": "AAGA,SAAS,MAAM,cAAc;AAC7B,OAAO,mBAAmB;AAK1B,SAAS,oBAAoB;AAC7B,SAAS,SAAS;AAGlB,SAAS,qBAAqB;AA6C9B,MAAM,0BAA0B,oBAAI,QAA4B;AAEhE,SAAS,gCACR,YACkB;AAClB,QAAM,gBAAgB,EAAE,GAAG,WAAW;AACtC,aAAY,CAAE,KAAK,KAAM,KAAK,OAAO,QAAS,UAAW,GAAI;AAC5D,QAAK,iBAAiB,cAAe;AACpC,oBAAe,GAAI,IAAI,MAAM,QAAQ;AAAA,IACtC;AAAA,EACD;AACA,SAAO;AACR;AAEA,SAAS,uBAAwB,QAAqC;AACrE,SAAO,OAAO,IAAK,CAAE,UAA2B;AAC/C,UAAM,cAAc,iBAAiB,EAAE,MAAM,MAAM,OAAO,IAAI;AAC9D,UAAM,EAAE,MAAM,aAAa,YAAY,GAAG,KAAK,IAAI;AACnD,WAAO,KAAK;AACZ,WAAO,KAAK;AAEZ,WAAO;AAAA,MACN,GAAG;AAAA,MACH;AAAA,MACA,YAAY,gCAAiC,UAAW;AAAA,MACxD,aAAa,uBAAwB,WAAY;AAAA,IAClD;AAAA,EACD,CAAE;AACH;AAMA,SAAS,eAAgB,QAAe,QAA0B;AACjE,QAAM,eAAe,OAAO,OAAO;AAInC,QAAM,aAAa;AAAA,IAClB,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACA,QAAM,MAAM;AAAA,IACX,OAAO,OAAQ,CAAC,GAAG,QAAQ,UAAW;AAAA,IACtC,OAAO,OAAQ,CAAC,GAAG,cAAc,UAAW;AAAA,EAC7C;AACA,QAAM,SAAS,OAAO,eAAe,CAAC;AACtC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ep-equal/es6";
2
+ import { Y } from "@wordpress/sync";
3
+ import {
4
+ mergeCrdtBlocks
5
+ } from "./crdt-blocks";
6
+ import { CRDT_RECORD_MAP_KEY } from "../sync";
7
+ let lastSelection = null;
8
+ const allowedPostProperties = /* @__PURE__ */ new Set([
9
+ "author",
10
+ "blocks",
11
+ "comment_status",
12
+ "date",
13
+ "excerpt",
14
+ "featured_media",
15
+ "format",
16
+ "ping_status",
17
+ "slug",
18
+ "status",
19
+ "sticky",
20
+ "tags",
21
+ "template",
22
+ "title"
23
+ ]);
24
+ function defaultApplyChangesToCRDTDoc(ydoc, changes) {
25
+ const ymap = ydoc.getMap(CRDT_RECORD_MAP_KEY);
26
+ Object.entries(changes).forEach(([key, newValue]) => {
27
+ if ("function" === typeof newValue) {
28
+ return;
29
+ }
30
+ function setValue(updatedValue) {
31
+ ymap.set(key, updatedValue);
32
+ }
33
+ switch (key) {
34
+ // Add support for additional data types here.
35
+ default: {
36
+ const currentValue = ymap.get(key);
37
+ mergeValue(currentValue, newValue, setValue);
38
+ }
39
+ }
40
+ });
41
+ }
42
+ function applyPostChangesToCRDTDoc(ydoc, changes, postType) {
43
+ const ymap = ydoc.getMap(CRDT_RECORD_MAP_KEY);
44
+ Object.entries(changes).forEach(([key, newValue]) => {
45
+ if (!allowedPostProperties.has(key)) {
46
+ return;
47
+ }
48
+ if ("function" === typeof newValue) {
49
+ return;
50
+ }
51
+ function setValue(updatedValue) {
52
+ ymap.set(key, updatedValue);
53
+ }
54
+ switch (key) {
55
+ case "blocks": {
56
+ let currentBlocks = ymap.get("blocks");
57
+ if (!(currentBlocks instanceof Y.Array)) {
58
+ currentBlocks = new Y.Array();
59
+ setValue(currentBlocks);
60
+ }
61
+ const newBlocks = newValue ?? [];
62
+ mergeCrdtBlocks(currentBlocks, newBlocks, lastSelection);
63
+ break;
64
+ }
65
+ case "excerpt": {
66
+ const currentValue = ymap.get("excerpt");
67
+ const rawNewValue = getRawValue(newValue);
68
+ mergeValue(currentValue, rawNewValue, setValue);
69
+ break;
70
+ }
71
+ case "slug": {
72
+ if (!newValue) {
73
+ break;
74
+ }
75
+ const currentValue = ymap.get("slug");
76
+ mergeValue(currentValue, newValue, setValue);
77
+ break;
78
+ }
79
+ case "title": {
80
+ const currentValue = ymap.get("title");
81
+ let rawNewValue = getRawValue(newValue);
82
+ if (!currentValue && "Auto Draft" === rawNewValue) {
83
+ rawNewValue = "";
84
+ }
85
+ mergeValue(currentValue, rawNewValue, setValue);
86
+ break;
87
+ }
88
+ // Add support for additional data types here.
89
+ default: {
90
+ const currentValue = ymap.get(key);
91
+ mergeValue(currentValue, newValue, setValue);
92
+ }
93
+ }
94
+ });
95
+ if ("selection" in changes) {
96
+ lastSelection = changes.selection?.selectionStart ?? null;
97
+ }
98
+ }
99
+ function defaultGetChangesFromCRDTDoc(crdtDoc) {
100
+ return crdtDoc.getMap(CRDT_RECORD_MAP_KEY).toJSON();
101
+ }
102
+ function getPostChangesFromCRDTDoc(ydoc, editedRecord, postType) {
103
+ const ymap = ydoc.getMap(CRDT_RECORD_MAP_KEY);
104
+ return Object.fromEntries(
105
+ Object.entries(ymap.toJSON()).filter(([key, newValue]) => {
106
+ if (!allowedPostProperties.has(key)) {
107
+ return false;
108
+ }
109
+ const currentValue = editedRecord[key];
110
+ switch (key) {
111
+ case "blocks": {
112
+ return true;
113
+ }
114
+ case "date": {
115
+ const currentDateIsFloating = ["draft", "auto-draft", "pending"].includes(
116
+ ymap.get("status")
117
+ ) && (null === currentValue || editedRecord.modified === currentValue);
118
+ if (!newValue && currentDateIsFloating) {
119
+ return false;
120
+ }
121
+ return haveValuesChanged(currentValue, newValue);
122
+ }
123
+ case "status": {
124
+ if ("auto-draft" === newValue) {
125
+ return false;
126
+ }
127
+ return haveValuesChanged(currentValue, newValue);
128
+ }
129
+ case "excerpt":
130
+ case "title": {
131
+ return haveValuesChanged(
132
+ getRawValue(currentValue),
133
+ newValue
134
+ );
135
+ }
136
+ // Add support for additional data types here.
137
+ default: {
138
+ return haveValuesChanged(currentValue, newValue);
139
+ }
140
+ }
141
+ })
142
+ );
143
+ }
144
+ function getRawValue(value) {
145
+ if ("string" === typeof value) {
146
+ return value;
147
+ }
148
+ if (value && "object" === typeof value && "raw" in value && "string" === typeof value.raw) {
149
+ return value.raw;
150
+ }
151
+ return void 0;
152
+ }
153
+ function haveValuesChanged(currentValue, newValue) {
154
+ return !fastDeepEqual(currentValue, newValue);
155
+ }
156
+ function mergeValue(currentValue, newValue, setValue) {
157
+ if (haveValuesChanged(currentValue, newValue)) {
158
+ setValue(newValue);
159
+ }
160
+ }
161
+ export {
162
+ applyPostChangesToCRDTDoc,
163
+ defaultApplyChangesToCRDTDoc,
164
+ defaultGetChangesFromCRDTDoc,
165
+ getPostChangesFromCRDTDoc
166
+ };
167
+ //# sourceMappingURL=crdt.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/crdt.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { type CRDTDoc, type ObjectData, Y } from '@wordpress/sync';\n\n/**\n * Internal dependencies\n */\nimport {\n\tmergeCrdtBlocks,\n\ttype Block,\n\ttype YBlock,\n\ttype YBlocks,\n} from './crdt-blocks';\nimport { type Post } from '../entity-types/post';\nimport { type Type } from '../entity-types';\nimport { CRDT_RECORD_MAP_KEY } from '../sync';\nimport type { WPBlockSelection, WPSelection } from '../types';\n\nexport type PostChanges = Partial< Post > & {\n\tblocks?: Block[];\n\texcerpt?: Post[ 'excerpt' ] | string;\n\tselection?: WPSelection;\n\ttitle?: Post[ 'title' ] | string;\n};\n\n// Hold a reference to the last known selection to help compute Y.Text deltas.\nlet lastSelection: WPBlockSelection | null = null;\n\n// Properties that are allowed to be synced for a post.\nconst allowedPostProperties = new Set< string >( [\n\t'author',\n\t'blocks',\n\t'comment_status',\n\t'date',\n\t'excerpt',\n\t'featured_media',\n\t'format',\n\t'ping_status',\n\t'slug',\n\t'status',\n\t'sticky',\n\t'tags',\n\t'template',\n\t'title',\n] );\n\n/**\n * Given a set of local changes to a generic entity record, apply those changes\n * to the local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {Partial< ObjectData >} changes\n * @return {void}\n */\nexport function defaultApplyChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: ObjectData\n): void {\n\tconst ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Set the value in the root document.\n\t\tfunction setValue< T = unknown >( updatedValue: T ): void {\n\t\t\tymap.set( key, updatedValue );\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t}\n\t\t}\n\t} );\n}\n\n/**\n * Given a set of local changes to a post record, apply those changes to the\n * local Y.Doc.\n *\n * @param {CRDTDoc} ydoc\n * @param {PostChanges} changes\n * @param {Type} postType\n * @return {void}\n */\nexport function applyPostChangesToCRDTDoc(\n\tydoc: CRDTDoc,\n\tchanges: PostChanges,\n\tpostType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): void {\n\tconst ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\tObject.entries( changes ).forEach( ( [ key, newValue ] ) => {\n\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Cannot serialize function values, so cannot sync them.\n\t\tif ( 'function' === typeof newValue ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Set the value in the root document.\n\t\tfunction setValue< T = unknown >( updatedValue: T ): void {\n\t\t\tymap.set( key, updatedValue );\n\t\t}\n\n\t\tswitch ( key ) {\n\t\t\tcase 'blocks': {\n\t\t\t\tlet currentBlocks = ymap.get( 'blocks' ) as YBlocks;\n\n\t\t\t\t// Initialize.\n\t\t\t\tif ( ! ( currentBlocks instanceof Y.Array ) ) {\n\t\t\t\t\tcurrentBlocks = new Y.Array< YBlock >();\n\t\t\t\t\tsetValue( currentBlocks );\n\t\t\t\t}\n\n\t\t\t\t// Block[] from local changes.\n\t\t\t\tconst newBlocks = ( newValue as PostChanges[ 'blocks' ] ) ?? [];\n\n\t\t\t\t// Merge blocks does not need `setValue` because it is operating on a\n\t\t\t\t// Yjs type that is already in the Y.Doc.\n\t\t\t\tmergeCrdtBlocks( currentBlocks, newBlocks, lastSelection );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'excerpt': {\n\t\t\t\tconst currentValue = ymap.get( 'excerpt' ) as\n\t\t\t\t\t| string\n\t\t\t\t\t| undefined;\n\t\t\t\tconst rawNewValue = getRawValue( newValue );\n\n\t\t\t\tmergeValue( currentValue, rawNewValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'slug': {\n\t\t\t\t// Do not sync an empty slug. This indicates that the post is using\n\t\t\t\t// the default auto-generated slug.\n\t\t\t\tif ( ! newValue ) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst currentValue = ymap.get( 'slug' ) as string;\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'title': {\n\t\t\t\tconst currentValue = ymap.get( 'title' ) as string | undefined;\n\n\t\t\t\t// Copy logic from prePersistPostType to ensure that the \"Auto\n\t\t\t\t// Draft\" template title is not synced.\n\t\t\t\tlet rawNewValue = getRawValue( newValue );\n\t\t\t\tif ( ! currentValue && 'Auto Draft' === rawNewValue ) {\n\t\t\t\t\trawNewValue = '';\n\t\t\t\t}\n\n\t\t\t\tmergeValue( currentValue, rawNewValue, setValue );\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// Add support for additional data types here.\n\n\t\t\tdefault: {\n\t\t\t\tconst currentValue = ymap.get( key );\n\t\t\t\tmergeValue( currentValue, newValue, setValue );\n\t\t\t}\n\t\t}\n\t} );\n\n\t// Update the lastSelection for use in computing Y.Text deltas.\n\tif ( 'selection' in changes ) {\n\t\tlastSelection = changes.selection?.selectionStart ?? null;\n\t}\n}\n\nexport function defaultGetChangesFromCRDTDoc( crdtDoc: CRDTDoc ): ObjectData {\n\treturn crdtDoc.getMap( CRDT_RECORD_MAP_KEY ).toJSON();\n}\n\n/**\n * Given a local Y.Doc that *may* contain changes from remote peers, compare\n * against the local record and determine if there are changes (edits) we want\n * to dispatch.\n *\n * @param {CRDTDoc} ydoc\n * @param {Post} editedRecord\n * @param {Type} postType\n * @return {Partial<PostChanges>} The changes that should be applied to the local record.\n */\nexport function getPostChangesFromCRDTDoc(\n\tydoc: CRDTDoc,\n\teditedRecord: Post,\n\tpostType: Type // eslint-disable-line @typescript-eslint/no-unused-vars\n): PostChanges {\n\tconst ymap = ydoc.getMap( CRDT_RECORD_MAP_KEY );\n\n\treturn Object.fromEntries(\n\t\tObject.entries( ymap.toJSON() ).filter( ( [ key, newValue ] ) => {\n\t\t\tif ( ! allowedPostProperties.has( key ) ) {\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tconst currentValue = editedRecord[ key ];\n\n\t\t\tswitch ( key ) {\n\t\t\t\tcase 'blocks': {\n\t\t\t\t\t// The consumers of blocks have memoization that renders optimization\n\t\t\t\t\t// here unnecessary.\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tcase 'date': {\n\t\t\t\t\t// Do not sync an empty date if our current value is a \"floating\" date.\n\t\t\t\t\t// Borrowing logic from the isEditedPostDateFloating selector.\n\t\t\t\t\tconst currentDateIsFloating =\n\t\t\t\t\t\t[ 'draft', 'auto-draft', 'pending' ].includes(\n\t\t\t\t\t\t\tymap.get( 'status' ) as string\n\t\t\t\t\t\t) &&\n\t\t\t\t\t\t( null === currentValue ||\n\t\t\t\t\t\t\teditedRecord.modified === currentValue );\n\n\t\t\t\t\tif ( ! newValue && currentDateIsFloating ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'status': {\n\t\t\t\t\t// Do not sync an invalid status.\n\t\t\t\t\tif ( 'auto-draft' === newValue ) {\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\n\t\t\t\tcase 'excerpt':\n\t\t\t\tcase 'title': {\n\t\t\t\t\treturn haveValuesChanged(\n\t\t\t\t\t\tgetRawValue( currentValue ),\n\t\t\t\t\t\tnewValue\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Add support for additional data types here.\n\n\t\t\t\tdefault: {\n\t\t\t\t\treturn haveValuesChanged( currentValue, newValue );\n\t\t\t\t}\n\t\t\t}\n\t\t} )\n\t);\n}\n\n/**\n * Extract the raw string value from a property that may be a string or an object\n * with a `raw` property (`RenderedText`).\n *\n * @param {unknown} value The value to extract from.\n * @return {string|undefined} The raw string value, or undefined if it could not be determined.\n */\nfunction getRawValue( value?: unknown ): string | undefined {\n\t// Value may be a string property or a nested object with a `raw` property.\n\tif ( 'string' === typeof value ) {\n\t\treturn value;\n\t}\n\n\tif (\n\t\tvalue &&\n\t\t'object' === typeof value &&\n\t\t'raw' in value &&\n\t\t'string' === typeof value.raw\n\t) {\n\t\treturn value.raw;\n\t}\n\n\treturn undefined;\n}\n\nfunction haveValuesChanged< ValueType = any >(\n\tcurrentValue: ValueType,\n\tnewValue: ValueType\n): boolean {\n\treturn ! fastDeepEqual( currentValue, newValue );\n}\n\nfunction mergeValue< ValueType = any >(\n\tcurrentValue: ValueType,\n\tnewValue: ValueType,\n\tsetValue: ( value: ValueType ) => void\n): void {\n\tif ( haveValuesChanged< ValueType >( currentValue, newValue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BAAO;AAAA,QACR;AAAA,QAEA,KAAK,QAAQ;AAGZ,gBAAM,wBACL,CAAE,SAAS,cAAc,SAAU,EAAE;AAAA,YACpC,KAAK,IAAK,QAAS;AAAA,UACpB,MACE,SAAS,gBACV,aAAa,aAAa;AAE5B,cAAK,CAAE,YAAY,uBAAwB;AAC1C,mBAAO;AAAA,UACR;AAEA,iBAAO,kBAAmB,cAAc,QAAS;AAAA,QAClD;AAAA,QAEA,KAAK,UAAU;AAEd,cAAK,iBAAiB,UAAW;AAChC,mBAAO;AAAA,UACR;AAEA,iBAAO,kBAAmB,cAAc,QAAS;AAAA,QAClD;AAAA,QAEA,KAAK;AAAA,QACL,KAAK,SAAS;AACb,iBAAO;AAAA,YACN,YAAa,YAAa;AAAA,YAC1B;AAAA,UACD;AAAA,QACD;AAAA;AAAA,QAIA,SAAS;AACR,iBAAO,kBAAmB,cAAc,QAAS;AAAA,QAClD;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH;AACD;AASA,SAAS,YAAa,OAAsC;AAE3D,MAAK,aAAa,OAAO,OAAQ;AAChC,WAAO;AAAA,EACR;AAEA,MACC,SACA,aAAa,OAAO,SACpB,SAAS,SACT,aAAa,OAAO,MAAM,KACzB;AACD,WAAO,MAAM;AAAA,EACd;AAEA,SAAO;AACR;AAEA,SAAS,kBACR,cACA,UACU;AACV,SAAO,CAAE,cAAe,cAAc,QAAS;AAChD;AAEA,SAAS,WACR,cACA,UACA,UACO;AACP,MAAK,kBAAgC,cAAc,QAAS,GAAI;AAC/D,aAAU,QAAS;AAAA,EACpB;AACD;",
6
+ "names": []
7
+ }
@@ -1,14 +1,8 @@
1
- /**
2
- * Higher-order function which forward the resolution to another resolver with the same arguments.
3
- *
4
- * @param {string} resolverName forwarded resolver.
5
- *
6
- * @return {Function} Enhanced resolver.
7
- */
8
- const forwardResolver = resolverName => (...args) => async ({
9
- resolveSelect
10
- }) => {
1
+ const forwardResolver = (resolverName) => (...args) => async ({ resolveSelect }) => {
11
2
  await resolveSelect[resolverName](...args);
12
3
  };
13
- export default forwardResolver;
14
- //# sourceMappingURL=forward-resolver.js.map
4
+ var forward_resolver_default = forwardResolver;
5
+ export {
6
+ forward_resolver_default as default
7
+ };
8
+ //# sourceMappingURL=forward-resolver.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["forwardResolver","resolverName","args","resolveSelect"],"sources":["@wordpress/core-data/src/utils/forward-resolver.js"],"sourcesContent":["/**\n * Higher-order function which forward the resolution to another resolver with the same arguments.\n *\n * @param {string} resolverName forwarded resolver.\n *\n * @return {Function} Enhanced resolver.\n */\nconst forwardResolver =\n\t( resolverName ) =>\n\t( ...args ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect[ resolverName ]( ...args );\n\t};\n\nexport default forwardResolver;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAClBC,YAAY,IACd,CAAE,GAAGC,IAAI,KACT,OAAQ;EAAEC;AAAc,CAAC,KAAM;EAC9B,MAAMA,aAAa,CAAEF,YAAY,CAAE,CAAE,GAAGC,IAAK,CAAC;AAC/C,CAAC;AAEF,eAAeF,eAAe","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/forward-resolver.js"],
4
+ "sourcesContent": ["/**\n * Higher-order function which forward the resolution to another resolver with the same arguments.\n *\n * @param {string} resolverName forwarded resolver.\n *\n * @return {Function} Enhanced resolver.\n */\nconst forwardResolver =\n\t( resolverName ) =>\n\t( ...args ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect[ resolverName ]( ...args );\n\t};\n\nexport default forwardResolver;\n"],
5
+ "mappings": "AAOA,MAAM,kBACL,CAAE,iBACF,IAAK,SACL,OAAQ,EAAE,cAAc,MAAO;AAC9B,QAAM,cAAe,YAAa,EAAG,GAAG,IAAK;AAC9C;AAED,IAAO,2BAAQ;",
6
+ "names": []
7
+ }
@@ -1,24 +1,15 @@
1
- /**
2
- * Helper util to return a value from a certain path of the object.
3
- * Path is specified as either:
4
- * - a string of properties, separated by dots, for example: "x.y".
5
- * - an array of properties, for example `[ 'x', 'y' ]`.
6
- * You can also specify a default value in case the result is nullish.
7
- *
8
- * @param {Object} object Input object.
9
- * @param {string|Array} path Path to the object property.
10
- * @param {*} defaultValue Default value if the value at the specified path is undefined.
11
- * @return {*} Value of the object property at the specified path.
12
- */
13
- export default function getNestedValue(object, path, defaultValue) {
14
- if (!object || typeof object !== 'object' || typeof path !== 'string' && !Array.isArray(path)) {
1
+ function getNestedValue(object, path, defaultValue) {
2
+ if (!object || typeof object !== "object" || typeof path !== "string" && !Array.isArray(path)) {
15
3
  return object;
16
4
  }
17
- const normalizedPath = Array.isArray(path) ? path : path.split('.');
5
+ const normalizedPath = Array.isArray(path) ? path : path.split(".");
18
6
  let value = object;
19
- normalizedPath.forEach(fieldName => {
7
+ normalizedPath.forEach((fieldName) => {
20
8
  value = value?.[fieldName];
21
9
  });
22
- return value !== undefined ? value : defaultValue;
10
+ return value !== void 0 ? value : defaultValue;
23
11
  }
24
- //# sourceMappingURL=get-nested-value.js.map
12
+ export {
13
+ getNestedValue as default
14
+ };
15
+ //# sourceMappingURL=get-nested-value.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["getNestedValue","object","path","defaultValue","Array","isArray","normalizedPath","split","value","forEach","fieldName","undefined"],"sources":["@wordpress/core-data/src/utils/get-nested-value.js"],"sourcesContent":["/**\n * Helper util to return a value from a certain path of the object.\n * Path is specified as either:\n * - a string of properties, separated by dots, for example: \"x.y\".\n * - an array of properties, for example `[ 'x', 'y' ]`.\n * You can also specify a default value in case the result is nullish.\n *\n * @param {Object} object Input object.\n * @param {string|Array} path Path to the object property.\n * @param {*} defaultValue Default value if the value at the specified path is undefined.\n * @return {*} Value of the object property at the specified path.\n */\nexport default function getNestedValue( object, path, defaultValue ) {\n\tif (\n\t\t! object ||\n\t\ttypeof object !== 'object' ||\n\t\t( typeof path !== 'string' && ! Array.isArray( path ) )\n\t) {\n\t\treturn object;\n\t}\n\tconst normalizedPath = Array.isArray( path ) ? path : path.split( '.' );\n\tlet value = object;\n\tnormalizedPath.forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value !== undefined ? value : defaultValue;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,cAAcA,CAAEC,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAG;EACpE,IACC,CAAEF,MAAM,IACR,OAAOA,MAAM,KAAK,QAAQ,IACxB,OAAOC,IAAI,KAAK,QAAQ,IAAI,CAAEE,KAAK,CAACC,OAAO,CAAEH,IAAK,CAAG,EACtD;IACD,OAAOD,MAAM;EACd;EACA,MAAMK,cAAc,GAAGF,KAAK,CAACC,OAAO,CAAEH,IAAK,CAAC,GAAGA,IAAI,GAAGA,IAAI,CAACK,KAAK,CAAE,GAAI,CAAC;EACvE,IAAIC,KAAK,GAAGP,MAAM;EAClBK,cAAc,CAACG,OAAO,CAAIC,SAAS,IAAM;IACxCF,KAAK,GAAGA,KAAK,GAAIE,SAAS,CAAE;EAC7B,CAAE,CAAC;EACH,OAAOF,KAAK,KAAKG,SAAS,GAAGH,KAAK,GAAGL,YAAY;AAClD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/get-nested-value.js"],
4
+ "sourcesContent": ["/**\n * Helper util to return a value from a certain path of the object.\n * Path is specified as either:\n * - a string of properties, separated by dots, for example: \"x.y\".\n * - an array of properties, for example `[ 'x', 'y' ]`.\n * You can also specify a default value in case the result is nullish.\n *\n * @param {Object} object Input object.\n * @param {string|Array} path Path to the object property.\n * @param {*} defaultValue Default value if the value at the specified path is undefined.\n * @return {*} Value of the object property at the specified path.\n */\nexport default function getNestedValue( object, path, defaultValue ) {\n\tif (\n\t\t! object ||\n\t\ttypeof object !== 'object' ||\n\t\t( typeof path !== 'string' && ! Array.isArray( path ) )\n\t) {\n\t\treturn object;\n\t}\n\tconst normalizedPath = Array.isArray( path ) ? path : path.split( '.' );\n\tlet value = object;\n\tnormalizedPath.forEach( ( fieldName ) => {\n\t\tvalue = value?.[ fieldName ];\n\t} );\n\treturn value !== undefined ? value : defaultValue;\n}\n"],
5
+ "mappings": "AAYe,SAAR,eAAiC,QAAQ,MAAM,cAAe;AACpE,MACC,CAAE,UACF,OAAO,WAAW,YAChB,OAAO,SAAS,YAAY,CAAE,MAAM,QAAS,IAAK,GACnD;AACD,WAAO;AAAA,EACR;AACA,QAAM,iBAAiB,MAAM,QAAS,IAAK,IAAI,OAAO,KAAK,MAAO,GAAI;AACtE,MAAI,QAAQ;AACZ,iBAAe,QAAS,CAAE,cAAe;AACxC,YAAQ,QAAS,SAAU;AAAA,EAC5B,CAAE;AACF,SAAO,UAAU,SAAY,QAAQ;AACtC;",
6
+ "names": []
7
+ }
@@ -1,19 +1,13 @@
1
- /**
2
- * Given a value which can be specified as one or the other of a comma-separated
3
- * string or an array, returns a value normalized to an array of strings, or
4
- * null if the value cannot be interpreted as either.
5
- *
6
- * @param {string|string[]|*} value
7
- *
8
- * @return {?(string[])} Normalized field value.
9
- */
10
1
  function getNormalizedCommaSeparable(value) {
11
- if (typeof value === 'string') {
12
- return value.split(',');
2
+ if (typeof value === "string") {
3
+ return value.split(",");
13
4
  } else if (Array.isArray(value)) {
14
5
  return value;
15
6
  }
16
7
  return null;
17
8
  }
18
- export default getNormalizedCommaSeparable;
19
- //# sourceMappingURL=get-normalized-comma-separable.js.map
9
+ var get_normalized_comma_separable_default = getNormalizedCommaSeparable;
10
+ export {
11
+ get_normalized_comma_separable_default as default
12
+ };
13
+ //# sourceMappingURL=get-normalized-comma-separable.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["getNormalizedCommaSeparable","value","split","Array","isArray"],"sources":["@wordpress/core-data/src/utils/get-normalized-comma-separable.js"],"sourcesContent":["/**\n * Given a value which can be specified as one or the other of a comma-separated\n * string or an array, returns a value normalized to an array of strings, or\n * null if the value cannot be interpreted as either.\n *\n * @param {string|string[]|*} value\n *\n * @return {?(string[])} Normalized field value.\n */\nfunction getNormalizedCommaSeparable( value ) {\n\tif ( typeof value === 'string' ) {\n\t\treturn value.split( ',' );\n\t} else if ( Array.isArray( value ) ) {\n\t\treturn value;\n\t}\n\n\treturn null;\n}\n\nexport default getNormalizedCommaSeparable;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,2BAA2BA,CAAEC,KAAK,EAAG;EAC7C,IAAK,OAAOA,KAAK,KAAK,QAAQ,EAAG;IAChC,OAAOA,KAAK,CAACC,KAAK,CAAE,GAAI,CAAC;EAC1B,CAAC,MAAM,IAAKC,KAAK,CAACC,OAAO,CAAEH,KAAM,CAAC,EAAG;IACpC,OAAOA,KAAK;EACb;EAEA,OAAO,IAAI;AACZ;AAEA,eAAeD,2BAA2B","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/get-normalized-comma-separable.js"],
4
+ "sourcesContent": ["/**\n * Given a value which can be specified as one or the other of a comma-separated\n * string or an array, returns a value normalized to an array of strings, or\n * null if the value cannot be interpreted as either.\n *\n * @param {string|string[]|*} value\n *\n * @return {?(string[])} Normalized field value.\n */\nfunction getNormalizedCommaSeparable( value ) {\n\tif ( typeof value === 'string' ) {\n\t\treturn value.split( ',' );\n\t} else if ( Array.isArray( value ) ) {\n\t\treturn value;\n\t}\n\n\treturn null;\n}\n\nexport default getNormalizedCommaSeparable;\n"],
5
+ "mappings": "AASA,SAAS,4BAA6B,OAAQ;AAC7C,MAAK,OAAO,UAAU,UAAW;AAChC,WAAO,MAAM,MAAO,GAAI;AAAA,EACzB,WAAY,MAAM,QAAS,KAAM,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAEA,IAAO,yCAAQ;",
6
+ "names": []
7
+ }
@@ -1,19 +1,11 @@
1
- /** @typedef {import('../types').AnyFunction} AnyFunction */
2
-
3
- /**
4
- * A higher-order reducer creator which invokes the original reducer only if
5
- * the dispatching action matches the given predicate, **OR** if state is
6
- * initializing (undefined).
7
- *
8
- * @param {AnyFunction} isMatch Function predicate for allowing reducer call.
9
- *
10
- * @return {AnyFunction} Higher-order reducer.
11
- */
12
- const ifMatchingAction = isMatch => reducer => (state, action) => {
13
- if (state === undefined || isMatch(action)) {
1
+ const ifMatchingAction = (isMatch) => (reducer) => (state, action) => {
2
+ if (state === void 0 || isMatch(action)) {
14
3
  return reducer(state, action);
15
4
  }
16
5
  return state;
17
6
  };
18
- export default ifMatchingAction;
19
- //# sourceMappingURL=if-matching-action.js.map
7
+ var if_matching_action_default = ifMatchingAction;
8
+ export {
9
+ if_matching_action_default as default
10
+ };
11
+ //# sourceMappingURL=if-matching-action.js.map