@wordpress/core-data 6.16.0 → 6.17.1

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 (236) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/actions.js +69 -134
  3. package/build/actions.js.map +1 -1
  4. package/build/batch/create-batch.js +0 -22
  5. package/build/batch/create-batch.js.map +1 -1
  6. package/build/batch/default-processor.js +3 -15
  7. package/build/batch/default-processor.js.map +1 -1
  8. package/build/batch/index.js +0 -3
  9. package/build/batch/index.js.map +1 -1
  10. package/build/entities.js +109 -36
  11. package/build/entities.js.map +1 -1
  12. package/build/entity-provider.js +34 -53
  13. package/build/entity-provider.js.map +1 -1
  14. package/build/entity-types/attachment.js.map +1 -1
  15. package/build/entity-types/base-entity-records.js +0 -3
  16. package/build/entity-types/base-entity-records.js.map +1 -1
  17. package/build/entity-types/comment.js.map +1 -1
  18. package/build/entity-types/helpers.js.map +1 -1
  19. package/build/entity-types/index.js.map +1 -1
  20. package/build/entity-types/menu-location.js.map +1 -1
  21. package/build/entity-types/nav-menu-item.js.map +1 -1
  22. package/build/entity-types/nav-menu.js.map +1 -1
  23. package/build/entity-types/page.js.map +1 -1
  24. package/build/entity-types/plugin.js.map +1 -1
  25. package/build/entity-types/post.js.map +1 -1
  26. package/build/entity-types/settings.js.map +1 -1
  27. package/build/entity-types/sidebar.js.map +1 -1
  28. package/build/entity-types/taxonomy.js.map +1 -1
  29. package/build/entity-types/theme.js.map +1 -1
  30. package/build/entity-types/type.js.map +1 -1
  31. package/build/entity-types/user.js.map +1 -1
  32. package/build/entity-types/widget-type.js.map +1 -1
  33. package/build/entity-types/widget.js.map +1 -1
  34. package/build/entity-types/wp-template-part.js.map +1 -1
  35. package/build/entity-types/wp-template.js.map +1 -1
  36. package/build/fetch/__experimental-fetch-link-suggestions.js +14 -20
  37. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  38. package/build/fetch/__experimental-fetch-url-data.js +4 -13
  39. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  40. package/build/fetch/index.js +0 -3
  41. package/build/fetch/index.js.map +1 -1
  42. package/build/hooks/constants.js +4 -5
  43. package/build/hooks/constants.js.map +1 -1
  44. package/build/hooks/index.js +0 -5
  45. package/build/hooks/index.js.map +1 -1
  46. package/build/hooks/memoize.js +0 -3
  47. package/build/hooks/memoize.js.map +1 -1
  48. package/build/hooks/use-entity-record.js +0 -9
  49. package/build/hooks/use-entity-record.js.map +1 -1
  50. package/build/hooks/use-entity-records.js +2 -9
  51. package/build/hooks/use-entity-records.js.map +1 -1
  52. package/build/hooks/use-query-select.js +1 -13
  53. package/build/hooks/use-query-select.js.map +1 -1
  54. package/build/hooks/use-resource-permissions.js +0 -15
  55. package/build/hooks/use-resource-permissions.js.map +1 -1
  56. package/build/index.js +9 -41
  57. package/build/index.js.map +1 -1
  58. package/build/locks/actions.js +1 -6
  59. package/build/locks/actions.js.map +1 -1
  60. package/build/locks/engine.js +1 -9
  61. package/build/locks/engine.js.map +1 -1
  62. package/build/locks/reducer.js +8 -9
  63. package/build/locks/reducer.js.map +1 -1
  64. package/build/locks/selectors.js +8 -11
  65. package/build/locks/selectors.js.map +1 -1
  66. package/build/locks/utils.js +4 -19
  67. package/build/locks/utils.js.map +1 -1
  68. package/build/name.js +0 -1
  69. package/build/name.js.map +1 -1
  70. package/build/private-apis.js +1 -2
  71. package/build/private-apis.js.map +1 -1
  72. package/build/private-selectors.js +2 -5
  73. package/build/private-selectors.js.map +1 -1
  74. package/build/queried-data/actions.js +4 -6
  75. package/build/queried-data/actions.js.map +1 -1
  76. package/build/queried-data/get-query-parts.js +11 -24
  77. package/build/queried-data/get-query-parts.js.map +1 -1
  78. package/build/queried-data/index.js +0 -6
  79. package/build/queried-data/index.js.map +1 -1
  80. package/build/queried-data/reducer.js +33 -51
  81. package/build/queried-data/reducer.js.map +1 -1
  82. package/build/queried-data/selectors.js +4 -25
  83. package/build/queried-data/selectors.js.map +1 -1
  84. package/build/reducer.js +76 -128
  85. package/build/reducer.js.map +1 -1
  86. package/build/resolvers.js +91 -133
  87. package/build/resolvers.js.map +1 -1
  88. package/build/selectors.js +51 -145
  89. package/build/selectors.js.map +1 -1
  90. package/build/sync.js +19 -0
  91. package/build/sync.js.map +1 -0
  92. package/build/types.js.map +1 -1
  93. package/build/utils/conservative-map-item.js +3 -10
  94. package/build/utils/conservative-map-item.js.map +1 -1
  95. package/build/utils/forward-resolver.js +0 -2
  96. package/build/utils/forward-resolver.js.map +1 -1
  97. package/build/utils/get-normalized-comma-separable.js +0 -3
  98. package/build/utils/get-normalized-comma-separable.js.map +1 -1
  99. package/build/utils/if-matching-action.js +0 -3
  100. package/build/utils/if-matching-action.js.map +1 -1
  101. package/build/utils/index.js +0 -10
  102. package/build/utils/index.js.map +1 -1
  103. package/build/utils/is-raw-attribute.js +0 -1
  104. package/build/utils/is-raw-attribute.js.map +1 -1
  105. package/build/utils/on-sub-key.js +5 -9
  106. package/build/utils/on-sub-key.js.map +1 -1
  107. package/build/utils/replace-action.js +0 -2
  108. package/build/utils/replace-action.js.map +1 -1
  109. package/build/utils/set-nested-value.js +0 -4
  110. package/build/utils/set-nested-value.js.map +1 -1
  111. package/build/utils/with-weak-map-cache.js +3 -6
  112. package/build/utils/with-weak-map-cache.js.map +1 -1
  113. package/build-module/actions.js +72 -95
  114. package/build-module/actions.js.map +1 -1
  115. package/build-module/batch/create-batch.js +1 -20
  116. package/build-module/batch/create-batch.js.map +1 -1
  117. package/build-module/batch/default-processor.js +4 -13
  118. package/build-module/batch/default-processor.js.map +1 -1
  119. package/build-module/batch/index.js.map +1 -1
  120. package/build-module/entities.js +109 -25
  121. package/build-module/entities.js.map +1 -1
  122. package/build-module/entity-provider.js +35 -45
  123. package/build-module/entity-provider.js.map +1 -1
  124. package/build-module/entity-types/attachment.js.map +1 -1
  125. package/build-module/entity-types/base-entity-records.js +0 -2
  126. package/build-module/entity-types/base-entity-records.js.map +1 -1
  127. package/build-module/entity-types/comment.js.map +1 -1
  128. package/build-module/entity-types/helpers.js.map +1 -1
  129. package/build-module/entity-types/index.js.map +1 -1
  130. package/build-module/entity-types/menu-location.js.map +1 -1
  131. package/build-module/entity-types/nav-menu-item.js.map +1 -1
  132. package/build-module/entity-types/nav-menu.js.map +1 -1
  133. package/build-module/entity-types/page.js.map +1 -1
  134. package/build-module/entity-types/plugin.js.map +1 -1
  135. package/build-module/entity-types/post.js.map +1 -1
  136. package/build-module/entity-types/settings.js.map +1 -1
  137. package/build-module/entity-types/sidebar.js.map +1 -1
  138. package/build-module/entity-types/taxonomy.js.map +1 -1
  139. package/build-module/entity-types/theme.js.map +1 -1
  140. package/build-module/entity-types/type.js.map +1 -1
  141. package/build-module/entity-types/user.js.map +1 -1
  142. package/build-module/entity-types/widget-type.js.map +1 -1
  143. package/build-module/entity-types/widget.js.map +1 -1
  144. package/build-module/entity-types/wp-template-part.js.map +1 -1
  145. package/build-module/entity-types/wp-template.js.map +1 -1
  146. package/build-module/fetch/__experimental-fetch-link-suggestions.js +15 -15
  147. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  148. package/build-module/fetch/__experimental-fetch-url-data.js +5 -10
  149. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  150. package/build-module/fetch/index.js.map +1 -1
  151. package/build-module/hooks/constants.js +3 -4
  152. package/build-module/hooks/constants.js.map +1 -1
  153. package/build-module/hooks/index.js.map +1 -1
  154. package/build-module/hooks/memoize.js +2 -1
  155. package/build-module/hooks/memoize.js.map +1 -1
  156. package/build-module/hooks/use-entity-record.js +1 -3
  157. package/build-module/hooks/use-entity-record.js.map +1 -1
  158. package/build-module/hooks/use-entity-records.js +2 -3
  159. package/build-module/hooks/use-entity-records.js.map +1 -1
  160. package/build-module/hooks/use-query-select.js +1 -9
  161. package/build-module/hooks/use-query-select.js.map +1 -1
  162. package/build-module/hooks/use-resource-permissions.js +1 -10
  163. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  164. package/build-module/index.js +11 -19
  165. package/build-module/index.js.map +1 -1
  166. package/build-module/locks/actions.js +0 -3
  167. package/build-module/locks/actions.js.map +1 -1
  168. package/build-module/locks/engine.js +0 -5
  169. package/build-module/locks/engine.js.map +1 -1
  170. package/build-module/locks/reducer.js +7 -7
  171. package/build-module/locks/reducer.js.map +1 -1
  172. package/build-module/locks/selectors.js +7 -8
  173. package/build-module/locks/selectors.js.map +1 -1
  174. package/build-module/locks/utils.js +4 -14
  175. package/build-module/locks/utils.js.map +1 -1
  176. package/build-module/name.js.map +1 -1
  177. package/build-module/private-apis.js.map +1 -1
  178. package/build-module/private-selectors.js +2 -2
  179. package/build-module/private-selectors.js.map +1 -1
  180. package/build-module/queried-data/actions.js +4 -3
  181. package/build-module/queried-data/actions.js.map +1 -1
  182. package/build-module/queried-data/get-query-parts.js +13 -21
  183. package/build-module/queried-data/get-query-parts.js.map +1 -1
  184. package/build-module/queried-data/index.js.map +1 -1
  185. package/build-module/queried-data/reducer.js +33 -42
  186. package/build-module/queried-data/reducer.js.map +1 -1
  187. package/build-module/queried-data/selectors.js +6 -21
  188. package/build-module/queried-data/selectors.js.map +1 -1
  189. package/build-module/reducer.js +79 -104
  190. package/build-module/reducer.js.map +1 -1
  191. package/build-module/resolvers.js +94 -96
  192. package/build-module/resolvers.js.map +1 -1
  193. package/build-module/selectors.js +56 -92
  194. package/build-module/selectors.js.map +1 -1
  195. package/build-module/sync.js +12 -0
  196. package/build-module/sync.js.map +1 -0
  197. package/build-module/types.js.map +1 -1
  198. package/build-module/utils/conservative-map-item.js +4 -8
  199. package/build-module/utils/conservative-map-item.js.map +1 -1
  200. package/build-module/utils/forward-resolver.js +0 -1
  201. package/build-module/utils/forward-resolver.js.map +1 -1
  202. package/build-module/utils/get-normalized-comma-separable.js +0 -2
  203. package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
  204. package/build-module/utils/if-matching-action.js +0 -2
  205. package/build-module/utils/if-matching-action.js.map +1 -1
  206. package/build-module/utils/index.js.map +1 -1
  207. package/build-module/utils/is-raw-attribute.js.map +1 -1
  208. package/build-module/utils/on-sub-key.js +5 -7
  209. package/build-module/utils/on-sub-key.js.map +1 -1
  210. package/build-module/utils/replace-action.js +0 -1
  211. package/build-module/utils/replace-action.js.map +1 -1
  212. package/build-module/utils/set-nested-value.js +0 -3
  213. package/build-module/utils/set-nested-value.js.map +1 -1
  214. package/build-module/utils/with-weak-map-cache.js +3 -5
  215. package/build-module/utils/with-weak-map-cache.js.map +1 -1
  216. package/build-types/actions.d.ts.map +1 -1
  217. package/build-types/entities.d.ts +53 -0
  218. package/build-types/entities.d.ts.map +1 -1
  219. package/build-types/entity-provider.d.ts +1 -1
  220. package/build-types/entity-provider.d.ts.map +1 -1
  221. package/build-types/hooks/memoize.d.ts +1 -1
  222. package/build-types/hooks/memoize.d.ts.map +1 -1
  223. package/build-types/index.d.ts +3 -3
  224. package/build-types/index.d.ts.map +1 -1
  225. package/build-types/resolvers.d.ts.map +1 -1
  226. package/build-types/sync.d.ts +2 -0
  227. package/build-types/sync.d.ts.map +1 -0
  228. package/package.json +17 -15
  229. package/src/actions.js +24 -14
  230. package/src/entities.js +91 -0
  231. package/src/entity-provider.js +11 -2
  232. package/src/resolvers.js +89 -41
  233. package/src/sync.js +18 -0
  234. package/src/test/entity-provider.js +272 -0
  235. package/tsconfig.json +1 -0
  236. package/tsconfig.tsbuildinfo +1 -1
@@ -8,6 +8,13 @@ export const rootEntitiesConfig: ({
8
8
  _fields: string;
9
9
  context?: undefined;
10
10
  };
11
+ syncConfig: {
12
+ fetch: () => Promise<any>;
13
+ applyChangesToDoc: (doc: any, changes: any) => void;
14
+ fromCRDTDoc: (doc: any) => any;
15
+ };
16
+ syncObjectType: string;
17
+ getSyncObjectId: () => string;
11
18
  getTitle?: undefined;
12
19
  key?: undefined;
13
20
  plural?: undefined;
@@ -19,6 +26,13 @@ export const rootEntitiesConfig: ({
19
26
  kind: string;
20
27
  baseURL: string;
21
28
  getTitle: (record: any) => any;
29
+ syncConfig: {
30
+ fetch: () => Promise<any>;
31
+ applyChangesToDoc: (doc: any, changes: any) => void;
32
+ fromCRDTDoc: (doc: any) => any;
33
+ };
34
+ syncObjectType: string;
35
+ getSyncObjectId: () => string;
22
36
  baseURLParams?: undefined;
23
37
  key?: undefined;
24
38
  plural?: undefined;
@@ -34,6 +48,13 @@ export const rootEntitiesConfig: ({
34
48
  context: string;
35
49
  _fields?: undefined;
36
50
  };
51
+ syncConfig: {
52
+ fetch: (id: any) => Promise<any>;
53
+ applyChangesToDoc: (doc: any, changes: any) => void;
54
+ fromCRDTDoc: (doc: any) => any;
55
+ };
56
+ syncObjectType: string;
57
+ getSyncObjectId: (id: any) => any;
37
58
  getTitle?: undefined;
38
59
  plural?: undefined;
39
60
  rawAttributes?: undefined;
@@ -49,6 +70,9 @@ export const rootEntitiesConfig: ({
49
70
  plural: string;
50
71
  label: string;
51
72
  rawAttributes: string[];
73
+ syncConfig?: undefined;
74
+ syncObjectType?: undefined;
75
+ getSyncObjectId?: undefined;
52
76
  getTitle?: undefined;
53
77
  key?: undefined;
54
78
  transientEdits?: undefined;
@@ -63,6 +87,9 @@ export const rootEntitiesConfig: ({
63
87
  };
64
88
  plural: string;
65
89
  label: string;
90
+ syncConfig?: undefined;
91
+ syncObjectType?: undefined;
92
+ getSyncObjectId?: undefined;
66
93
  getTitle?: undefined;
67
94
  rawAttributes?: undefined;
68
95
  transientEdits?: undefined;
@@ -79,6 +106,9 @@ export const rootEntitiesConfig: ({
79
106
  blocks: boolean;
80
107
  };
81
108
  label: string;
109
+ syncConfig?: undefined;
110
+ syncObjectType?: undefined;
111
+ getSyncObjectId?: undefined;
82
112
  getTitle?: undefined;
83
113
  key?: undefined;
84
114
  rawAttributes?: undefined;
@@ -92,6 +122,9 @@ export const rootEntitiesConfig: ({
92
122
  };
93
123
  plural: string;
94
124
  label: string;
125
+ syncConfig?: undefined;
126
+ syncObjectType?: undefined;
127
+ getSyncObjectId?: undefined;
95
128
  getTitle?: undefined;
96
129
  key?: undefined;
97
130
  rawAttributes?: undefined;
@@ -107,9 +140,29 @@ export const rootEntitiesConfig: ({
107
140
  };
108
141
  plural: string;
109
142
  getTitle: (record: any) => any;
143
+ syncConfig?: undefined;
144
+ syncObjectType?: undefined;
145
+ getSyncObjectId?: undefined;
110
146
  key?: undefined;
111
147
  rawAttributes?: undefined;
112
148
  transientEdits?: undefined;
149
+ } | {
150
+ label: string;
151
+ name: string;
152
+ kind: string;
153
+ baseURL: string;
154
+ baseURLParams: {
155
+ context: string;
156
+ _fields?: undefined;
157
+ };
158
+ key: string;
159
+ syncConfig?: undefined;
160
+ syncObjectType?: undefined;
161
+ getSyncObjectId?: undefined;
162
+ getTitle?: undefined;
163
+ plural?: undefined;
164
+ rawAttributes?: undefined;
165
+ transientEdits?: undefined;
113
166
  })[];
114
167
  export const additionalEntityConfigLoaders: {
115
168
  kind: string;
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAgBA,sCAAuC;AAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoJE;AAEF;;;IAGE;AASK,0EAqBN;AAgFM,oCAPI,MAAM,QACN,MAAM,WACN,MAAM,cACN,OAAO,GAEN,MAAM,CAkBjB;AASM,8CAJI,MAAM,eAEO,MAAM,KAAK,cAAc,CAqB/C;AA1HF;;;;GAIG;AACH,sDA+BC"}
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAiBA,sCAAuC;AAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4ME;AAEF;;;IAGE;AASK,0EAqBN;AAuGM,oCAPI,MAAM,QACN,MAAM,WACN,MAAM,cACN,OAAO,GAEN,MAAM,CAkBjB;AAkBM,8CAJI,MAAM,eAEO,MAAM,KAAK,cAAc,CAuB/C;AA5JF;;;;GAIG;AACH,sDAsDC"}
@@ -50,7 +50,7 @@ export function useEntityProp(kind: string, name: string, prop: string, _id?: st
50
50
  * The return value has the shape `[ blocks, onInput, onChange ]`.
51
51
  * `onInput` is for block changes that don't create undo levels
52
52
  * or dirty the post, non-persistent changes, and `onChange` is for
53
- * peristent changes. They map directly to the props of a
53
+ * persistent changes. They map directly to the props of a
54
54
  * `BlockEditorProvider` and are intended to be used with it,
55
55
  * or similar components or hooks.
56
56
  *
@@ -1 +1 @@
1
- {"version":3,"file":"entity-provider.d.ts","sourceRoot":"","sources":["../src/entity-provider.js"],"names":[],"mappings":"AA2DA;;;;;;;;;;;;GAYG;AACH;IARyB,IAAI,EAAlB,MAAM;IACQ,IAAI,EAAlB,MAAM;IACQ,EAAE,EAAhB,MAAM;IACQ,QAAQ;QAQhC;AAED;;;;;;GAMG;AACH,kCAHW,MAAM,QACN,MAAM,OAIhB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,oCAZW,MAAM,QACN,MAAM,QACN,MAAM,6BAGL,oBAAgB,CAqC3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,2CAPW,MAAM,QACN,MAAM;IAEW,EAAE;IAElB,CAAC,OAAO,EAAE,qBAAqB,CAsM1C"}
1
+ {"version":3,"file":"entity-provider.d.ts","sourceRoot":"","sources":["../src/entity-provider.js"],"names":[],"mappings":"AA2DA;;;;;;;;;;;;GAYG;AACH;IARyB,IAAI,EAAlB,MAAM;IACQ,IAAI,EAAlB,MAAM;IACQ,EAAE,EAAhB,MAAM;IACQ,QAAQ;QAQhC;AAED;;;;;;GAMG;AACH,kCAHW,MAAM,QACN,MAAM,OAIhB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,oCAZW,MAAM,QACN,MAAM,QACN,MAAM,6BAGL,oBAAgB,CAqC3B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,2CAPW,MAAM,QACN,MAAM;IAEW,EAAE;IAElB,CAAC,OAAO,EAAE,qBAAqB,CA+M1C"}
@@ -1,3 +1,3 @@
1
1
  export default memoize;
2
- import memoize from "memize";
2
+ import memoize from 'memize';
3
3
  //# sourceMappingURL=memoize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/hooks/memoize.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../src/hooks/memoize.js"],"names":[],"mappings":";oBAGoB,QAAQ"}
@@ -63,7 +63,7 @@ export const store: import("@wordpress/data/build-types/types").StoreDescriptor<
63
63
  }, {
64
64
  getAuthors(state: selectors.State, query?: {
65
65
  [x: string]: any;
66
- } | undefined): import("./entity-types").User<"edit">[];
66
+ } | undefined): import("./entity-types").User[];
67
67
  getCurrentUser(state: selectors.State): import("./entity-types").User<"edit">;
68
68
  getEntitiesByKind(state: selectors.State, kind: string): any[];
69
69
  getEntitiesConfig(state: selectors.State, kind: string): any[];
@@ -93,7 +93,7 @@ export const store: import("@wordpress/data/build-types/types").StoreDescriptor<
93
93
  canUserEditEntityRecord(state: selectors.State, kind: string, name: string, recordId: string | number): boolean | undefined;
94
94
  getAutosaves(state: selectors.State, postType: string, postId: string | number): any[] | undefined;
95
95
  getAutosave<EntityRecord_1 extends import("./entity-types").Attachment<any> | import("./entity-types").Comment<any> | import("./entity-types").MenuLocation<any> | import("./entity-types").NavMenu<any> | import("./entity-types").NavMenuItem<any> | import("./entity-types").Page<any> | import("./entity-types").Plugin<any> | import("./entity-types").Post<any> | import("./entity-types").Settings<any> | import("./entity-types").Sidebar<any> | import("./entity-types").Taxonomy<any> | import("./entity-types").Theme<any> | import("./entity-types").User<any> | import("./entity-types").Type<any> | import("./entity-types").Widget<any> | import("./entity-types").WidgetType<any> | import("./entity-types").WpTemplate<any> | import("./entity-types").WpTemplatePart<any>>(state: selectors.State, postType: string, postId: string | number, authorId: string | number): EntityRecord_1 | undefined;
96
- __experimentalGetTemplateForLink(state: selectors.State, link: string): (import("./entity-types").Updatable<import("./entity-types").WpTemplate<"edit">> | undefined) | null;
96
+ __experimentalGetTemplateForLink(state: selectors.State, link: string): (import("./entity-types").Updatable<import("./entity-types").WpTemplate> | undefined) | null;
97
97
  __experimentalGetCurrentThemeBaseGlobalStyles(state: selectors.State): any;
98
98
  __experimentalGetCurrentThemeGlobalStylesVariations(state: selectors.State): string | null;
99
99
  getBlockPatterns(state: selectors.State): any[];
@@ -126,5 +126,5 @@ export * from "./entity-provider";
126
126
  export * from "./entity-types";
127
127
  export * from "./fetch";
128
128
  export * from "./hooks";
129
- import * as selectors from "./selectors";
129
+ import * as selectors from './selectors';
130
130
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA4DA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAmE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AA4DA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAmE;;;;;;2BAxDxC,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../src/resolvers.js"],"names":[],"mappings":"AAwBO,kCAHI,MAAO,SAAS;;oBAYzB;AAKK;;oBAKL;AAYK,sCAPI,MAAM,QACN,MAAM,2CAEN,MAAO,SAAS;;;oBAsEzB;AAEF;;GAEG;AACH,0CAAuE;AAEvE;;GAEG;AACH,6CAA0E;AAUnE,uCALI,MAAM,QACN,MAAM;;oBAoFf;;IAEF,kEAOC;;AAKM;;;oBAUL;AAEF;;GAEG;AACH,wCAAqE;AAO9D,qCAFI,MAAM;;oBAcf;AAWK,yCALI,MAAM,YAEN,MAAM,MACL,MAAM;;;oBAiEhB;AAUK,8CAJI,MAAM,QACN,MAAM,YACN,MAAM;;oBAef;AAQK,uCAHI,MAAM,UACN,MAAM;;;oBAcf;AAWK,sCAHI,MAAM,UACN,MAAM;;oBAMf;AAOK,uDAFI,MAAM;;;oBAsCf;;IAEF,4CAOC;;AAEM;;;oBAmBL;AAEK;;;oBAWL;AAEK;;;oBAWL;AAKK;;;oBA+BL;;IAEF,gDAOC;;AAEM;;oBAeL;AAEK;;oBAOL;AAEK;;;oBAsCL"}
1
+ {"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../src/resolvers.js"],"names":[],"mappings":"AAyBO,kCAHI,MAAO,SAAS;;oBAYzB;AAKK;;oBAKL;AAYK,sCAPI,MAAM,QACN,MAAM,2CAEN,MAAO,SAAS;;;oBAqHzB;AAEF;;GAEG;AACH,0CAAuE;AAEvE;;GAEG;AACH,6CAA0E;AAUnE,uCALI,MAAM,QACN,MAAM;;oBAoFf;;IAEF,kEAOC;;AAKM;;;oBAUL;AAEF;;GAEG;AACH,wCAAqE;AAO9D,qCAFI,MAAM;;oBAcf;AAWK,yCALI,MAAM,YAEN,MAAM,MACL,MAAM;;;oBAiEhB;AAUK,8CAJI,MAAM,QACN,MAAM,YACN,MAAM;;oBAef;AAQK,uCAHI,MAAM,UACN,MAAM;;;oBAcf;AAWK,sCAHI,MAAM,UACN,MAAM;;oBAMf;AAOK,uDAFI,MAAM;;;oBAsCf;;IAEF,4CAOC;;AAEM;;;oBAmBL;AAEK;;;oBAWL;AAEK;;;oBAWL;AAKK;;;oBA+BL;;IAEF,gDAOC;;AAEM;;oBAeL;AAEK;;oBAOL;AAEK;;;oBAsCL"}
@@ -0,0 +1,2 @@
1
+ export function getSyncProvider(): any;
2
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.js"],"names":[],"mappings":"AAWA,uCAMC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/core-data",
3
- "version": "6.16.0",
3
+ "version": "6.17.1",
4
4
  "description": "Access to and manipulation of core WordPress entities.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -31,18 +31,19 @@
31
31
  ],
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.16.0",
34
- "@wordpress/api-fetch": "^6.36.0",
35
- "@wordpress/block-editor": "^12.7.0",
36
- "@wordpress/blocks": "^12.16.0",
37
- "@wordpress/compose": "^6.16.0",
38
- "@wordpress/data": "^9.9.0",
39
- "@wordpress/deprecated": "^3.39.0",
40
- "@wordpress/element": "^5.16.0",
41
- "@wordpress/html-entities": "^3.39.0",
42
- "@wordpress/i18n": "^4.39.0",
43
- "@wordpress/is-shallow-equal": "^4.39.0",
44
- "@wordpress/private-apis": "^0.21.0",
45
- "@wordpress/url": "^3.40.0",
34
+ "@wordpress/api-fetch": "^6.37.1",
35
+ "@wordpress/block-editor": "^12.8.1",
36
+ "@wordpress/blocks": "^12.17.1",
37
+ "@wordpress/compose": "^6.17.1",
38
+ "@wordpress/data": "^9.10.1",
39
+ "@wordpress/deprecated": "^3.40.1",
40
+ "@wordpress/element": "^5.17.1",
41
+ "@wordpress/html-entities": "^3.40.1",
42
+ "@wordpress/i18n": "^4.40.1",
43
+ "@wordpress/is-shallow-equal": "^4.40.1",
44
+ "@wordpress/private-apis": "^0.22.1",
45
+ "@wordpress/sync": "^0.2.1",
46
+ "@wordpress/url": "^3.41.1",
46
47
  "change-case": "^4.1.2",
47
48
  "equivalent-key-map": "^0.2.2",
48
49
  "fast-deep-equal": "^3.1.3",
@@ -51,10 +52,11 @@
51
52
  "uuid": "^8.3.0"
52
53
  },
53
54
  "peerDependencies": {
54
- "react": "^18.0.0"
55
+ "react": "^18.0.0",
56
+ "react-dom": "^18.0.0"
55
57
  },
56
58
  "publishConfig": {
57
59
  "access": "public"
58
60
  },
59
- "gitHead": "b898cf1dc8e70841d1647ea0994ac6278acc18a7"
61
+ "gitHead": "bb1fbf87bb0f451744530fc6a85de2dff1263bed"
60
62
  }
package/src/actions.js CHANGED
@@ -18,6 +18,7 @@ import { receiveItems, removeItems, receiveQueriedItems } from './queried-data';
18
18
  import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
19
19
  import { createBatch } from './batch';
20
20
  import { STORE_NAME } from './name';
21
+ import { getSyncProvider } from './sync';
21
22
 
22
23
  /**
23
24
  * Returns an action object used in signalling that authors have been received.
@@ -382,21 +383,30 @@ export const editEntityRecord =
382
383
  return acc;
383
384
  }, {} ),
384
385
  };
385
- dispatch( {
386
- type: 'EDIT_ENTITY_RECORD',
387
- ...edit,
388
- meta: {
389
- undo: ! options.undoIgnore && {
390
- ...edit,
391
- // Send the current values for things like the first undo stack entry.
392
- edits: Object.keys( edits ).reduce( ( acc, key ) => {
393
- acc[ key ] = editedRecord[ key ];
394
- return acc;
395
- }, {} ),
396
- isCached: options.isCached,
386
+ if ( window.__experimentalEnableSync && entityConfig.syncConfig ) {
387
+ const objectId = entityConfig.getSyncObjectId( recordId );
388
+ getSyncProvider().update(
389
+ entityConfig.syncObjectType + '--edit',
390
+ objectId,
391
+ edit.edits
392
+ );
393
+ } else {
394
+ dispatch( {
395
+ type: 'EDIT_ENTITY_RECORD',
396
+ ...edit,
397
+ meta: {
398
+ undo: ! options.undoIgnore && {
399
+ ...edit,
400
+ // Send the current values for things like the first undo stack entry.
401
+ edits: Object.keys( edits ).reduce( ( acc, key ) => {
402
+ acc[ key ] = editedRecord[ key ];
403
+ return acc;
404
+ }, {} ),
405
+ isCached: options.isCached,
406
+ },
397
407
  },
398
- },
399
- } );
408
+ } );
409
+ }
400
410
  };
401
411
 
402
412
  /**
package/src/entities.js CHANGED
@@ -13,6 +13,7 @@ import { __ } from '@wordpress/i18n';
13
13
  * Internal dependencies
14
14
  */
15
15
  import { addEntities } from './actions';
16
+ import { getSyncProvider } from './sync';
16
17
 
17
18
  export const DEFAULT_ENTITY_KEY = 'id';
18
19
 
@@ -37,6 +38,24 @@ export const rootEntitiesConfig = [
37
38
  'url',
38
39
  ].join( ',' ),
39
40
  },
41
+ syncConfig: {
42
+ fetch: async () => {
43
+ return apiFetch( { path: '/' } );
44
+ },
45
+ applyChangesToDoc: ( doc, changes ) => {
46
+ const document = doc.getMap( 'document' );
47
+ Object.entries( changes ).forEach( ( [ key, value ] ) => {
48
+ if ( document.get( key ) !== value ) {
49
+ document.set( key, value );
50
+ }
51
+ } );
52
+ },
53
+ fromCRDTDoc: ( doc ) => {
54
+ return doc.getMap( 'document' ).toJSON();
55
+ },
56
+ },
57
+ syncObjectType: 'root/base',
58
+ getSyncObjectId: () => 'index',
40
59
  },
41
60
  {
42
61
  label: __( 'Site' ),
@@ -46,6 +65,24 @@ export const rootEntitiesConfig = [
46
65
  getTitle: ( record ) => {
47
66
  return record?.title ?? __( 'Site Title' );
48
67
  },
68
+ syncConfig: {
69
+ fetch: async () => {
70
+ return apiFetch( { path: '/wp/v2/settings' } );
71
+ },
72
+ applyChangesToDoc: ( doc, changes ) => {
73
+ const document = doc.getMap( 'document' );
74
+ Object.entries( changes ).forEach( ( [ key, value ] ) => {
75
+ if ( document.get( key ) !== value ) {
76
+ document.set( key, value );
77
+ }
78
+ } );
79
+ },
80
+ fromCRDTDoc: ( doc ) => {
81
+ return doc.getMap( 'document' ).toJSON();
82
+ },
83
+ },
84
+ syncObjectType: 'root/site',
85
+ getSyncObjectId: () => 'index',
49
86
  },
50
87
  {
51
88
  label: __( 'Post Type' ),
@@ -54,6 +91,26 @@ export const rootEntitiesConfig = [
54
91
  key: 'slug',
55
92
  baseURL: '/wp/v2/types',
56
93
  baseURLParams: { context: 'edit' },
94
+ syncConfig: {
95
+ fetch: async ( id ) => {
96
+ return apiFetch( {
97
+ path: `/wp/v2/types/${ id }?context=edit`,
98
+ } );
99
+ },
100
+ applyChangesToDoc: ( doc, changes ) => {
101
+ const document = doc.getMap( 'document' );
102
+ Object.entries( changes ).forEach( ( [ key, value ] ) => {
103
+ if ( document.get( key ) !== value ) {
104
+ document.set( key, value );
105
+ }
106
+ } );
107
+ },
108
+ fromCRDTDoc: ( doc ) => {
109
+ return doc.getMap( 'document' ).toJSON();
110
+ },
111
+ },
112
+ syncObjectType: 'root/postType',
113
+ getSyncObjectId: ( id ) => id,
57
114
  },
58
115
  {
59
116
  name: 'media',
@@ -237,6 +294,29 @@ async function loadPostTypeEntities() {
237
294
  : String( record.id ) ),
238
295
  __unstablePrePersist: isTemplate ? undefined : prePersistPostType,
239
296
  __unstable_rest_base: postType.rest_base,
297
+ syncConfig: {
298
+ fetch: async ( id ) => {
299
+ return apiFetch( {
300
+ path: `/${ namespace }/${ postType.rest_base }/${ id }?context=edit`,
301
+ } );
302
+ },
303
+ applyChangesToDoc: ( doc, changes ) => {
304
+ const document = doc.getMap( 'document' );
305
+ Object.entries( changes ).forEach( ( [ key, value ] ) => {
306
+ if (
307
+ document.get( key ) !== value &&
308
+ typeof value !== 'function'
309
+ ) {
310
+ document.set( key, value );
311
+ }
312
+ } );
313
+ },
314
+ fromCRDTDoc: ( doc ) => {
315
+ return doc.getMap( 'document' ).toJSON();
316
+ },
317
+ },
318
+ syncObjectType: 'postType/' + postType.name,
319
+ getSyncObjectId: ( id ) => id,
240
320
  };
241
321
  } );
242
322
  }
@@ -299,6 +379,15 @@ export const getMethodName = (
299
379
  return `${ prefix }${ kindPrefix }${ suffix }`;
300
380
  };
301
381
 
382
+ function registerSyncConfigs( configs ) {
383
+ configs.forEach( ( { syncObjectType, syncConfig } ) => {
384
+ getSyncProvider().register( syncObjectType, syncConfig );
385
+ const editSyncConfig = { ...syncConfig };
386
+ delete editSyncConfig.fetch;
387
+ getSyncProvider().register( syncObjectType + '--edit', editSyncConfig );
388
+ } );
389
+ }
390
+
302
391
  /**
303
392
  * Loads the kind entities into the store.
304
393
  *
@@ -311,6 +400,7 @@ export const getOrLoadEntitiesConfig =
311
400
  async ( { select, dispatch } ) => {
312
401
  let configs = select.getEntitiesConfig( kind );
313
402
  if ( configs && configs.length !== 0 ) {
403
+ registerSyncConfigs( configs );
314
404
  return configs;
315
405
  }
316
406
 
@@ -322,6 +412,7 @@ export const getOrLoadEntitiesConfig =
322
412
  }
323
413
 
324
414
  configs = await loader.loadEntities();
415
+ registerSyncConfigs( configs );
325
416
  dispatch( addEntities( configs ) );
326
417
 
327
418
  return configs;
@@ -142,7 +142,7 @@ export function useEntityProp( kind, name, prop, _id ) {
142
142
  * The return value has the shape `[ blocks, onInput, onChange ]`.
143
143
  * `onInput` is for block changes that don't create undo levels
144
144
  * or dirty the post, non-persistent changes, and `onChange` is for
145
- * peristent changes. They map directly to the props of a
145
+ * persistent changes. They map directly to the props of a
146
146
  * `BlockEditorProvider` and are intended to be used with it,
147
147
  * or similar components or hooks.
148
148
  *
@@ -221,6 +221,15 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
221
221
  );
222
222
 
223
223
  function updateAttributes( attributes ) {
224
+ // Only attempt to update attributes, if attributes is an object.
225
+ if (
226
+ ! attributes ||
227
+ Array.isArray( attributes ) ||
228
+ typeof attributes !== 'object'
229
+ ) {
230
+ return attributes;
231
+ }
232
+
224
233
  attributes = { ...attributes };
225
234
 
226
235
  for ( const key in attributes ) {
@@ -281,7 +290,7 @@ export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
281
290
  } );
282
291
  }
283
292
 
284
- // We need to go through all block attributs deeply and update the
293
+ // We need to go through all block attributes deeply and update the
285
294
  // footnote anchor numbering (textContent) to match the new order.
286
295
  const newBlocks = updateBlocksAttributes( _blocks );
287
296
 
package/src/resolvers.js CHANGED
@@ -15,6 +15,7 @@ import apiFetch from '@wordpress/api-fetch';
15
15
  import { STORE_NAME } from './name';
16
16
  import { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
17
17
  import { forwardResolver, getNormalizedCommaSeparable } from './utils';
18
+ import { getSyncProvider } from './sync';
18
19
 
19
20
  /**
20
21
  * Requests authors from the REST API.
@@ -71,51 +72,98 @@ export const getEntityRecord =
71
72
  );
72
73
 
73
74
  try {
74
- if ( query !== undefined && query._fields ) {
75
- // If requesting specific fields, items and query association to said
76
- // records are stored by ID reference. Thus, fields must always include
77
- // the ID.
78
- query = {
79
- ...query,
80
- _fields: [
81
- ...new Set( [
82
- ...( getNormalizedCommaSeparable( query._fields ) ||
83
- [] ),
84
- entityConfig.key || DEFAULT_ENTITY_KEY,
85
- ] ),
86
- ].join(),
87
- };
88
- }
89
-
90
- // Disable reason: While true that an early return could leave `path`
91
- // unused, it's important that path is derived using the query prior to
92
- // additional query modifications in the condition below, since those
93
- // modifications are relevant to how the data is tracked in state, and not
94
- // for how the request is made to the REST API.
95
-
96
- // eslint-disable-next-line @wordpress/no-unused-vars-before-return
97
- const path = addQueryArgs(
98
- entityConfig.baseURL + ( key ? '/' + key : '' ),
99
- {
100
- ...entityConfig.baseURLParams,
101
- ...query,
75
+ // Entity supports configs,
76
+ // use the sync algorithm instead of the old fetch behavior.
77
+ if (
78
+ window.__experimentalEnableSync &&
79
+ entityConfig.syncConfig &&
80
+ ! query
81
+ ) {
82
+ const objectId = entityConfig.getSyncObjectId( key );
83
+
84
+ // Loads the persisted document.
85
+ await getSyncProvider().bootstrap(
86
+ entityConfig.syncObjectType,
87
+ objectId,
88
+ ( record ) => {
89
+ dispatch.receiveEntityRecords(
90
+ kind,
91
+ name,
92
+ record,
93
+ query
94
+ );
95
+ }
96
+ );
97
+
98
+ // Boostraps the edited document as well (and load from peers).
99
+ await getSyncProvider().bootstrap(
100
+ entityConfig.syncObjectType + '--edit',
101
+ objectId,
102
+ ( record ) => {
103
+ dispatch( {
104
+ type: 'EDIT_ENTITY_RECORD',
105
+ kind,
106
+ name,
107
+ recordId: key,
108
+ edits: record,
109
+ meta: {
110
+ undo: undefined,
111
+ },
112
+ } );
113
+ }
114
+ );
115
+ } else {
116
+ if ( query !== undefined && query._fields ) {
117
+ // If requesting specific fields, items and query association to said
118
+ // records are stored by ID reference. Thus, fields must always include
119
+ // the ID.
120
+ query = {
121
+ ...query,
122
+ _fields: [
123
+ ...new Set( [
124
+ ...( getNormalizedCommaSeparable(
125
+ query._fields
126
+ ) || [] ),
127
+ entityConfig.key || DEFAULT_ENTITY_KEY,
128
+ ] ),
129
+ ].join(),
130
+ };
102
131
  }
103
- );
104
-
105
- if ( query !== undefined ) {
106
- query = { ...query, include: [ key ] };
107
132
 
108
- // The resolution cache won't consider query as reusable based on the
109
- // fields, so it's tested here, prior to initiating the REST request,
110
- // and without causing `getEntityRecords` resolution to occur.
111
- const hasRecords = select.hasEntityRecords( kind, name, query );
112
- if ( hasRecords ) {
113
- return;
133
+ // Disable reason: While true that an early return could leave `path`
134
+ // unused, it's important that path is derived using the query prior to
135
+ // additional query modifications in the condition below, since those
136
+ // modifications are relevant to how the data is tracked in state, and not
137
+ // for how the request is made to the REST API.
138
+
139
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
140
+ const path = addQueryArgs(
141
+ entityConfig.baseURL + ( key ? '/' + key : '' ),
142
+ {
143
+ ...entityConfig.baseURLParams,
144
+ ...query,
145
+ }
146
+ );
147
+
148
+ if ( query !== undefined ) {
149
+ query = { ...query, include: [ key ] };
150
+
151
+ // The resolution cache won't consider query as reusable based on the
152
+ // fields, so it's tested here, prior to initiating the REST request,
153
+ // and without causing `getEntityRecords` resolution to occur.
154
+ const hasRecords = select.hasEntityRecords(
155
+ kind,
156
+ name,
157
+ query
158
+ );
159
+ if ( hasRecords ) {
160
+ return;
161
+ }
114
162
  }
115
- }
116
163
 
117
- const record = await apiFetch( { path } );
118
- dispatch.receiveEntityRecords( kind, name, record, query );
164
+ const record = await apiFetch( { path } );
165
+ dispatch.receiveEntityRecords( kind, name, record, query );
166
+ }
119
167
  } finally {
120
168
  dispatch.__unstableReleaseStoreLock( lock );
121
169
  }
package/src/sync.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ createSyncProvider,
6
+ connectIndexDb,
7
+ connectWebRTC,
8
+ } from '@wordpress/sync';
9
+
10
+ let syncProvider;
11
+
12
+ export function getSyncProvider() {
13
+ if ( ! syncProvider ) {
14
+ syncProvider = createSyncProvider( connectIndexDb, connectWebRTC );
15
+ }
16
+
17
+ return syncProvider;
18
+ }