@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
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -48,25 +47,15 @@ exports.isDeletingEntityRecord = isDeletingEntityRecord;
48
47
  exports.isPreviewEmbedFallback = isPreviewEmbedFallback;
49
48
  exports.isRequestingEmbedPreview = void 0;
50
49
  exports.isSavingEntityRecord = isSavingEntityRecord;
51
-
52
50
  var _rememo = _interopRequireDefault(require("rememo"));
53
-
54
51
  var _data = require("@wordpress/data");
55
-
56
52
  var _url = require("@wordpress/url");
57
-
58
53
  var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
59
-
60
54
  var _name = require("./name");
61
-
62
55
  var _queriedData = require("./queried-data");
63
-
64
56
  var _entities = require("./entities");
65
-
66
57
  var _utils = require("./utils");
67
-
68
58
  var _privateSelectors = require("./private-selectors");
69
-
70
59
  /**
71
60
  * External dependencies
72
61
  */
@@ -87,6 +76,7 @@ var _privateSelectors = require("./private-selectors");
87
76
  * maintained by the reducer result in state.
88
77
  */
89
78
  const EMPTY_OBJECT = {};
79
+
90
80
  /**
91
81
  * Returns true if a request is in progress for embed preview data, or false
92
82
  * otherwise.
@@ -96,10 +86,10 @@ const EMPTY_OBJECT = {};
96
86
  *
97
87
  * @return Whether a request is in progress for an embed preview.
98
88
  */
99
-
100
89
  const isRequestingEmbedPreview = (0, _data.createRegistrySelector)(select => (state, url) => {
101
90
  return select(_name.STORE_NAME).isResolving('getEmbedPreview', [url]);
102
91
  });
92
+
103
93
  /**
104
94
  * Returns all available authors.
105
95
  *
@@ -110,9 +100,7 @@ const isRequestingEmbedPreview = (0, _data.createRegistrySelector)(select => (st
110
100
  * include with request. For valid query parameters see the [Users page](https://developer.wordpress.org/rest-api/reference/users/) in the REST API Handbook and see the arguments for [List Users](https://developer.wordpress.org/rest-api/reference/users/#list-users) and [Retrieve a User](https://developer.wordpress.org/rest-api/reference/users/#retrieve-a-user).
111
101
  * @return Authors list.
112
102
  */
113
-
114
103
  exports.isRequestingEmbedPreview = isRequestingEmbedPreview;
115
-
116
104
  function getAuthors(state, query) {
117
105
  (0, _deprecated.default)("select( 'core' ).getAuthors()", {
118
106
  since: '5.9',
@@ -121,6 +109,7 @@ function getAuthors(state, query) {
121
109
  const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
122
110
  return getUserQueryResults(state, path);
123
111
  }
112
+
124
113
  /**
125
114
  * Returns the current user.
126
115
  *
@@ -128,11 +117,10 @@ function getAuthors(state, query) {
128
117
  *
129
118
  * @return Current user object.
130
119
  */
131
-
132
-
133
120
  function getCurrentUser(state) {
134
121
  return state.currentUser;
135
122
  }
123
+
136
124
  /**
137
125
  * Returns all the users returned by a query ID.
138
126
  *
@@ -141,14 +129,12 @@ function getCurrentUser(state) {
141
129
  *
142
130
  * @return Users list.
143
131
  */
144
-
145
-
146
132
  const getUserQueryResults = (0, _rememo.default)((state, queryID) => {
147
133
  var _state$users$queries$;
148
-
149
134
  const queryResults = (_state$users$queries$ = state.users.queries[queryID]) !== null && _state$users$queries$ !== void 0 ? _state$users$queries$ : [];
150
135
  return queryResults.map(id => state.users.byId[id]);
151
136
  }, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
137
+
152
138
  /**
153
139
  * Returns the loaded entities for the given kind.
154
140
  *
@@ -158,9 +144,7 @@ const getUserQueryResults = (0, _rememo.default)((state, queryID) => {
158
144
  *
159
145
  * @return Array of entities with config matching kind.
160
146
  */
161
-
162
147
  exports.getUserQueryResults = getUserQueryResults;
163
-
164
148
  function getEntitiesByKind(state, kind) {
165
149
  (0, _deprecated.default)("wp.data.select( 'core' ).getEntitiesByKind()", {
166
150
  since: '6.0',
@@ -168,6 +152,7 @@ function getEntitiesByKind(state, kind) {
168
152
  });
169
153
  return getEntitiesConfig(state, kind);
170
154
  }
155
+
171
156
  /**
172
157
  * Returns the loaded entities for the given kind.
173
158
  *
@@ -176,11 +161,10 @@ function getEntitiesByKind(state, kind) {
176
161
  *
177
162
  * @return Array of entities with config matching kind.
178
163
  */
179
-
180
-
181
164
  function getEntitiesConfig(state, kind) {
182
165
  return state.entities.config.filter(entity => entity.kind === kind);
183
166
  }
167
+
184
168
  /**
185
169
  * Returns the entity config given its kind and name.
186
170
  *
@@ -191,8 +175,6 @@ function getEntitiesConfig(state, kind) {
191
175
  *
192
176
  * @return Entity config
193
177
  */
194
-
195
-
196
178
  function getEntity(state, kind, name) {
197
179
  (0, _deprecated.default)("wp.data.select( 'core' ).getEntity()", {
198
180
  since: '6.0',
@@ -200,6 +182,7 @@ function getEntity(state, kind, name) {
200
182
  });
201
183
  return getEntityConfig(state, kind, name);
202
184
  }
185
+
203
186
  /**
204
187
  * Returns the entity config given its kind and name.
205
188
  *
@@ -209,11 +192,10 @@ function getEntity(state, kind, name) {
209
192
  *
210
193
  * @return Entity config
211
194
  */
212
-
213
-
214
195
  function getEntityConfig(state, kind, name) {
215
196
  return state.entities.config?.find(config => config.kind === kind && config.name === name);
216
197
  }
198
+
217
199
  /**
218
200
  * GetEntityRecord is declared as a *callable interface* with
219
201
  * two signatures to work around the fact that TypeScript doesn't
@@ -239,7 +221,6 @@ function getEntityConfig(state, kind, name) {
239
221
  * See https://github.com/WordPress/gutenberg/pull/41578 for more details.
240
222
  */
241
223
 
242
-
243
224
  /**
244
225
  * Returns the Entity's record object by key. Returns `null` if the value is not
245
226
  * yet received, undefined if the value entity is known to not exist, or the
@@ -256,32 +237,23 @@ function getEntityConfig(state, kind, name) {
256
237
  */
257
238
  const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) => {
258
239
  var _query$context;
259
-
260
240
  const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
261
-
262
241
  if (!queriedState) {
263
242
  return undefined;
264
243
  }
265
-
266
244
  const context = (_query$context = query?.context) !== null && _query$context !== void 0 ? _query$context : 'default';
267
-
268
245
  if (query === undefined) {
269
246
  // If expecting a complete item, validate that completeness.
270
247
  if (!queriedState.itemIsComplete[context]?.[key]) {
271
248
  return undefined;
272
249
  }
273
-
274
250
  return queriedState.items[context][key];
275
251
  }
276
-
277
252
  const item = queriedState.items[context]?.[key];
278
-
279
253
  if (item && query._fields) {
280
254
  var _getNormalizedCommaSe;
281
-
282
255
  const filteredItem = {};
283
256
  const fields = (_getNormalizedCommaSe = (0, _utils.getNormalizedCommaSeparable)(query._fields)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : [];
284
-
285
257
  for (let f = 0; f < fields.length; f++) {
286
258
  const field = fields[f].split('.');
287
259
  let value = item;
@@ -290,17 +262,15 @@ const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) =>
290
262
  });
291
263
  (0, _utils.setNestedValue)(filteredItem, field, value);
292
264
  }
293
-
294
265
  return filteredItem;
295
266
  }
296
-
297
267
  return item;
298
268
  }, (state, kind, name, recordId, query) => {
299
269
  var _query$context2;
300
-
301
270
  const context = (_query$context2 = query?.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
302
271
  return [state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]];
303
272
  });
273
+
304
274
  /**
305
275
  * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
306
276
  *
@@ -311,12 +281,11 @@ const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) =>
311
281
  *
312
282
  * @return Record.
313
283
  */
314
-
315
284
  exports.getEntityRecord = getEntityRecord;
316
-
317
285
  function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
318
286
  return getEntityRecord(state, kind, name, key);
319
287
  }
288
+
320
289
  /**
321
290
  * Returns the entity's record object by key,
322
291
  * with its attributes mapped to their raw values.
@@ -328,14 +297,11 @@ function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
328
297
  *
329
298
  * @return Object with the entity's raw attributes.
330
299
  */
331
-
332
-
333
300
  const getRawEntityRecord = (0, _rememo.default)((state, kind, name, key) => {
334
301
  const record = getEntityRecord(state, kind, name, key);
335
302
  return record && Object.keys(record).reduce((accumulator, _key) => {
336
303
  if ((0, _utils.isRawAttribute)(getEntityConfig(state, kind, name), _key)) {
337
304
  var _record$_key$raw;
338
-
339
305
  // Because edits are the "raw" attribute values,
340
306
  // we return those from record selectors to make rendering,
341
307
  // comparisons, and joins with edits easier.
@@ -343,15 +309,14 @@ const getRawEntityRecord = (0, _rememo.default)((state, kind, name, key) => {
343
309
  } else {
344
310
  accumulator[_key] = record[_key];
345
311
  }
346
-
347
312
  return accumulator;
348
313
  }, {});
349
314
  }, (state, kind, name, recordId, query) => {
350
315
  var _query$context3;
351
-
352
316
  const context = (_query$context3 = query?.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
353
317
  return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData?.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData?.itemIsComplete[context]?.[recordId]];
354
318
  });
319
+
355
320
  /**
356
321
  * Returns true if records have been received for the given set of parameters,
357
322
  * or false otherwise.
@@ -363,12 +328,11 @@ const getRawEntityRecord = (0, _rememo.default)((state, kind, name, key) => {
363
328
  *
364
329
  * @return Whether entity records have been received.
365
330
  */
366
-
367
331
  exports.getRawEntityRecord = getRawEntityRecord;
368
-
369
332
  function hasEntityRecords(state, kind, name, query) {
370
333
  return Array.isArray(getEntityRecords(state, kind, name, query));
371
334
  }
335
+
372
336
  /**
373
337
  * GetEntityRecord is declared as a *callable interface* with
374
338
  * two signatures to work around the fact that TypeScript doesn't
@@ -378,7 +342,6 @@ function hasEntityRecords(state, kind, name, query) {
378
342
  * @see https://github.com/WordPress/gutenberg/pull/41578
379
343
  */
380
344
 
381
-
382
345
  /**
383
346
  * Returns the Entity's records.
384
347
  *
@@ -394,16 +357,12 @@ const getEntityRecords = (state, kind, name, query) => {
394
357
  // Queried data state is prepopulated for all known entities. If this is not
395
358
  // assigned for the given parameters, then it is known to not exist.
396
359
  const queriedState = state.entities.records?.[kind]?.[name]?.queriedData;
397
-
398
360
  if (!queriedState) {
399
361
  return null;
400
362
  }
401
-
402
363
  return (0, _queriedData.getQueriedItems)(queriedState, query);
403
364
  };
404
-
405
365
  exports.getEntityRecords = getEntityRecords;
406
-
407
366
  /**
408
367
  * Returns the list of dirty entity records.
409
368
  *
@@ -420,10 +379,10 @@ const __experimentalGetDirtyEntityRecords = (0, _rememo.default)(state => {
420
379
  const dirtyRecords = [];
421
380
  Object.keys(records).forEach(kind => {
422
381
  Object.keys(records[kind]).forEach(name => {
423
- const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey => // The entity record must exist (not be deleted),
382
+ const primaryKeys = Object.keys(records[kind][name].edits).filter(primaryKey =>
383
+ // The entity record must exist (not be deleted),
424
384
  // and it must have edits.
425
385
  getEntityRecord(state, kind, name, primaryKey) && hasEditsForEntityRecord(state, kind, name, primaryKey));
426
-
427
386
  if (primaryKeys.length) {
428
387
  const entityConfig = getEntityConfig(state, kind, name);
429
388
  primaryKeys.forEach(primaryKey => {
@@ -442,6 +401,7 @@ const __experimentalGetDirtyEntityRecords = (0, _rememo.default)(state => {
442
401
  });
443
402
  return dirtyRecords;
444
403
  }, state => [state.entities.records]);
404
+
445
405
  /**
446
406
  * Returns the list of entities currently being saved.
447
407
  *
@@ -449,10 +409,7 @@ const __experimentalGetDirtyEntityRecords = (0, _rememo.default)(state => {
449
409
  *
450
410
  * @return The list of records being saved.
451
411
  */
452
-
453
-
454
412
  exports.__experimentalGetDirtyEntityRecords = __experimentalGetDirtyEntityRecords;
455
-
456
413
  const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
457
414
  const {
458
415
  entities: {
@@ -463,7 +420,6 @@ const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
463
420
  Object.keys(records).forEach(kind => {
464
421
  Object.keys(records[kind]).forEach(name => {
465
422
  const primaryKeys = Object.keys(records[kind][name].saving).filter(primaryKey => isSavingEntityRecord(state, kind, name, primaryKey));
466
-
467
423
  if (primaryKeys.length) {
468
424
  const entityConfig = getEntityConfig(state, kind, name);
469
425
  primaryKeys.forEach(primaryKey => {
@@ -482,6 +438,7 @@ const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
482
438
  });
483
439
  return recordsBeingSaved;
484
440
  }, state => [state.entities.records]);
441
+
485
442
  /**
486
443
  * Returns the specified entity record's edits.
487
444
  *
@@ -492,13 +449,11 @@ const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
492
449
  *
493
450
  * @return The entity record's edits.
494
451
  */
495
-
496
-
497
452
  exports.__experimentalGetEntitiesBeingSaved = __experimentalGetEntitiesBeingSaved;
498
-
499
453
  function getEntityRecordEdits(state, kind, name, recordId) {
500
454
  return state.entities.records?.[kind]?.[name]?.edits?.[recordId];
501
455
  }
456
+
502
457
  /**
503
458
  * Returns the specified entity record's non transient edits.
504
459
  *
@@ -513,26 +468,22 @@ function getEntityRecordEdits(state, kind, name, recordId) {
513
468
  *
514
469
  * @return The entity record's non transient edits.
515
470
  */
516
-
517
-
518
471
  const getEntityRecordNonTransientEdits = (0, _rememo.default)((state, kind, name, recordId) => {
519
472
  const {
520
473
  transientEdits
521
474
  } = getEntityConfig(state, kind, name) || {};
522
475
  const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
523
-
524
476
  if (!transientEdits) {
525
477
  return edits;
526
478
  }
527
-
528
479
  return Object.keys(edits).reduce((acc, key) => {
529
480
  if (!transientEdits[key]) {
530
481
  acc[key] = edits[key];
531
482
  }
532
-
533
483
  return acc;
534
484
  }, {});
535
485
  }, (state, kind, name, recordId) => [state.entities.config, state.entities.records?.[kind]?.[name]?.edits?.[recordId]]);
486
+
536
487
  /**
537
488
  * Returns true if the specified entity record has edits,
538
489
  * and false otherwise.
@@ -544,12 +495,11 @@ const getEntityRecordNonTransientEdits = (0, _rememo.default)((state, kind, name
544
495
  *
545
496
  * @return Whether the entity record has edits or not.
546
497
  */
547
-
548
498
  exports.getEntityRecordNonTransientEdits = getEntityRecordNonTransientEdits;
549
-
550
499
  function hasEditsForEntityRecord(state, kind, name, recordId) {
551
500
  return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0;
552
501
  }
502
+
553
503
  /**
554
504
  * Returns the specified entity record, merged with its edits.
555
505
  *
@@ -560,16 +510,15 @@ function hasEditsForEntityRecord(state, kind, name, recordId) {
560
510
  *
561
511
  * @return The entity record, merged with its edits.
562
512
  */
563
-
564
-
565
- const getEditedEntityRecord = (0, _rememo.default)((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
513
+ const getEditedEntityRecord = (0, _rememo.default)((state, kind, name, recordId) => ({
514
+ ...getRawEntityRecord(state, kind, name, recordId),
566
515
  ...getEntityRecordEdits(state, kind, name, recordId)
567
516
  }), (state, kind, name, recordId, query) => {
568
517
  var _query$context4;
569
-
570
518
  const context = (_query$context4 = query?.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
571
519
  return [state.entities.config, state.entities.records?.[kind]?.[name]?.queriedData.items[context]?.[recordId], state.entities.records?.[kind]?.[name]?.queriedData.itemIsComplete[context]?.[recordId], state.entities.records?.[kind]?.[name]?.edits?.[recordId]];
572
520
  });
521
+
573
522
  /**
574
523
  * Returns true if the specified entity record is autosaving, and false otherwise.
575
524
  *
@@ -580,18 +529,16 @@ const getEditedEntityRecord = (0, _rememo.default)((state, kind, name, recordId)
580
529
  *
581
530
  * @return Whether the entity record is autosaving or not.
582
531
  */
583
-
584
532
  exports.getEditedEntityRecord = getEditedEntityRecord;
585
-
586
533
  function isAutosavingEntityRecord(state, kind, name, recordId) {
587
534
  var _state$entities$recor;
588
-
589
535
  const {
590
536
  pending,
591
537
  isAutosave
592
538
  } = (_state$entities$recor = state.entities.records?.[kind]?.[name]?.saving?.[recordId]) !== null && _state$entities$recor !== void 0 ? _state$entities$recor : {};
593
539
  return Boolean(pending && isAutosave);
594
540
  }
541
+
595
542
  /**
596
543
  * Returns true if the specified entity record is saving, and false otherwise.
597
544
  *
@@ -602,13 +549,11 @@ function isAutosavingEntityRecord(state, kind, name, recordId) {
602
549
  *
603
550
  * @return Whether the entity record is saving or not.
604
551
  */
605
-
606
-
607
552
  function isSavingEntityRecord(state, kind, name, recordId) {
608
553
  var _state$entities$recor2;
609
-
610
554
  return (_state$entities$recor2 = state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.pending) !== null && _state$entities$recor2 !== void 0 ? _state$entities$recor2 : false;
611
555
  }
556
+
612
557
  /**
613
558
  * Returns true if the specified entity record is deleting, and false otherwise.
614
559
  *
@@ -619,13 +564,11 @@ function isSavingEntityRecord(state, kind, name, recordId) {
619
564
  *
620
565
  * @return Whether the entity record is deleting or not.
621
566
  */
622
-
623
-
624
567
  function isDeletingEntityRecord(state, kind, name, recordId) {
625
568
  var _state$entities$recor3;
626
-
627
569
  return (_state$entities$recor3 = state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.pending) !== null && _state$entities$recor3 !== void 0 ? _state$entities$recor3 : false;
628
570
  }
571
+
629
572
  /**
630
573
  * Returns the specified entity record's last save error.
631
574
  *
@@ -636,11 +579,10 @@ function isDeletingEntityRecord(state, kind, name, recordId) {
636
579
  *
637
580
  * @return The entity record's save error.
638
581
  */
639
-
640
-
641
582
  function getLastEntitySaveError(state, kind, name, recordId) {
642
583
  return state.entities.records?.[kind]?.[name]?.saving?.[recordId]?.error;
643
584
  }
585
+
644
586
  /**
645
587
  * Returns the specified entity record's last delete error.
646
588
  *
@@ -651,11 +593,10 @@ function getLastEntitySaveError(state, kind, name, recordId) {
651
593
  *
652
594
  * @return The entity record's save error.
653
595
  */
654
-
655
-
656
596
  function getLastEntityDeleteError(state, kind, name, recordId) {
657
597
  return state.entities.records?.[kind]?.[name]?.deleting?.[recordId]?.error;
658
598
  }
599
+
659
600
  /**
660
601
  * Returns the current undo offset for the
661
602
  * entity records edits history. The offset
@@ -667,11 +608,10 @@ function getLastEntityDeleteError(state, kind, name, recordId) {
667
608
  *
668
609
  * @return The current undo offset.
669
610
  */
670
-
671
-
672
611
  function getCurrentUndoOffset(state) {
673
612
  return state.undo.offset;
674
613
  }
614
+
675
615
  /**
676
616
  * Returns the previous edit from the current undo offset
677
617
  * for the entity records edits history, if any.
@@ -682,14 +622,13 @@ function getCurrentUndoOffset(state) {
682
622
  *
683
623
  * @return The edit.
684
624
  */
685
-
686
-
687
625
  function getUndoEdit(state) {
688
626
  (0, _deprecated.default)("select( 'core' ).getUndoEdit()", {
689
627
  since: '6.3'
690
628
  });
691
629
  return state.undo.list[state.undo.list.length - 2 + getCurrentUndoOffset(state)]?.[0];
692
630
  }
631
+
693
632
  /**
694
633
  * Returns the next edit from the current undo offset
695
634
  * for the entity records edits history, if any.
@@ -700,14 +639,13 @@ function getUndoEdit(state) {
700
639
  *
701
640
  * @return The edit.
702
641
  */
703
-
704
-
705
642
  function getRedoEdit(state) {
706
643
  (0, _deprecated.default)("select( 'core' ).getRedoEdit()", {
707
644
  since: '6.3'
708
645
  });
709
646
  return state.undo.list[state.undo.list.length + getCurrentUndoOffset(state)]?.[0];
710
647
  }
648
+
711
649
  /**
712
650
  * Returns true if there is a previous edit from the current undo offset
713
651
  * for the entity records edits history, and false otherwise.
@@ -716,11 +654,10 @@ function getRedoEdit(state) {
716
654
  *
717
655
  * @return Whether there is a previous edit or not.
718
656
  */
719
-
720
-
721
657
  function hasUndo(state) {
722
658
  return Boolean((0, _privateSelectors.getUndoEdits)(state));
723
659
  }
660
+
724
661
  /**
725
662
  * Returns true if there is a next edit from the current undo offset
726
663
  * for the entity records edits history, and false otherwise.
@@ -729,11 +666,10 @@ function hasUndo(state) {
729
666
  *
730
667
  * @return Whether there is a next edit or not.
731
668
  */
732
-
733
-
734
669
  function hasRedo(state) {
735
670
  return Boolean((0, _privateSelectors.getRedoEdits)(state));
736
671
  }
672
+
737
673
  /**
738
674
  * Return the current theme.
739
675
  *
@@ -741,11 +677,10 @@ function hasRedo(state) {
741
677
  *
742
678
  * @return The current theme.
743
679
  */
744
-
745
-
746
680
  function getCurrentTheme(state) {
747
681
  return getEntityRecord(state, 'root', 'theme', state.currentTheme);
748
682
  }
683
+
749
684
  /**
750
685
  * Return the ID of the current global styles object.
751
686
  *
@@ -753,11 +688,10 @@ function getCurrentTheme(state) {
753
688
  *
754
689
  * @return The current global styles ID.
755
690
  */
756
-
757
-
758
691
  function __experimentalGetCurrentGlobalStylesId(state) {
759
692
  return state.currentGlobalStylesId;
760
693
  }
694
+
761
695
  /**
762
696
  * Return theme supports data in the index.
763
697
  *
@@ -765,13 +699,11 @@ function __experimentalGetCurrentGlobalStylesId(state) {
765
699
  *
766
700
  * @return Index data.
767
701
  */
768
-
769
-
770
702
  function getThemeSupports(state) {
771
703
  var _getCurrentTheme$them;
772
-
773
704
  return (_getCurrentTheme$them = getCurrentTheme(state)?.theme_supports) !== null && _getCurrentTheme$them !== void 0 ? _getCurrentTheme$them : EMPTY_OBJECT;
774
705
  }
706
+
775
707
  /**
776
708
  * Returns the embed preview for the given URL.
777
709
  *
@@ -780,11 +712,10 @@ function getThemeSupports(state) {
780
712
  *
781
713
  * @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
782
714
  */
783
-
784
-
785
715
  function getEmbedPreview(state, url) {
786
716
  return state.embedPreviews[url];
787
717
  }
718
+
788
719
  /**
789
720
  * Determines if the returned preview is an oEmbed link fallback.
790
721
  *
@@ -797,18 +728,15 @@ function getEmbedPreview(state, url) {
797
728
  *
798
729
  * @return Is the preview for the URL an oEmbed link fallback.
799
730
  */
800
-
801
-
802
731
  function isPreviewEmbedFallback(state, url) {
803
732
  const preview = state.embedPreviews[url];
804
733
  const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>';
805
-
806
734
  if (!preview) {
807
735
  return false;
808
736
  }
809
-
810
737
  return preview.html === oEmbedLinkCheck;
811
738
  }
739
+
812
740
  /**
813
741
  * Returns whether the current user can perform the given action on the given
814
742
  * REST resource.
@@ -826,12 +754,11 @@ function isPreviewEmbedFallback(state, url) {
826
754
  * @return Whether or not the user can perform the action,
827
755
  * or `undefined` if the OPTIONS request is still being made.
828
756
  */
829
-
830
-
831
757
  function canUser(state, action, resource, id) {
832
758
  const key = [action, resource, id].filter(Boolean).join('/');
833
759
  return state.userPermissions[key];
834
760
  }
761
+
835
762
  /**
836
763
  * Returns whether the current user can edit the given entity.
837
764
  *
@@ -847,18 +774,15 @@ function canUser(state, action, resource, id) {
847
774
  * @return Whether or not the user can edit,
848
775
  * or `undefined` if the OPTIONS request is still being made.
849
776
  */
850
-
851
-
852
777
  function canUserEditEntityRecord(state, kind, name, recordId) {
853
778
  const entityConfig = getEntityConfig(state, kind, name);
854
-
855
779
  if (!entityConfig) {
856
780
  return false;
857
781
  }
858
-
859
782
  const resource = entityConfig.__unstable_rest_base;
860
783
  return canUser(state, 'update', resource, recordId);
861
784
  }
785
+
862
786
  /**
863
787
  * Returns the latest autosaves for the post.
864
788
  *
@@ -871,11 +795,10 @@ function canUserEditEntityRecord(state, kind, name, recordId) {
871
795
  *
872
796
  * @return An array of autosaves for the post, or undefined if there is none.
873
797
  */
874
-
875
-
876
798
  function getAutosaves(state, postType, postId) {
877
799
  return state.autosaves[postId];
878
800
  }
801
+
879
802
  /**
880
803
  * Returns the autosave for the post and author.
881
804
  *
@@ -886,16 +809,14 @@ function getAutosaves(state, postType, postId) {
886
809
  *
887
810
  * @return The autosave for the post and author.
888
811
  */
889
-
890
-
891
812
  function getAutosave(state, postType, postId, authorId) {
892
813
  if (authorId === undefined) {
893
814
  return;
894
815
  }
895
-
896
816
  const autosaves = state.autosaves[postId];
897
817
  return autosaves?.find(autosave => autosave.author === authorId);
898
818
  }
819
+
899
820
  /**
900
821
  * Returns true if the REST request for autosaves has completed.
901
822
  *
@@ -905,11 +826,10 @@ function getAutosave(state, postType, postId, authorId) {
905
826
  *
906
827
  * @return True if the REST request was completed. False otherwise.
907
828
  */
908
-
909
-
910
829
  const hasFetchedAutosaves = (0, _data.createRegistrySelector)(select => (state, postType, postId) => {
911
830
  return select(_name.STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]);
912
831
  });
832
+
913
833
  /**
914
834
  * Returns a new reference when edited values have changed. This is useful in
915
835
  * inferring where an edit has been made between states by comparison of the
@@ -928,10 +848,11 @@ const hasFetchedAutosaves = (0, _data.createRegistrySelector)(select => (state,
928
848
  *
929
849
  * @return A value whose reference will change only when an edit occurs.
930
850
  */
931
-
932
851
  exports.hasFetchedAutosaves = hasFetchedAutosaves;
933
- const getReferenceByDistinctEdits = (0, _rememo.default)( // This unused state argument is listed here for the documentation generating tool (docgen).
852
+ const getReferenceByDistinctEdits = (0, _rememo.default)(
853
+ // This unused state argument is listed here for the documentation generating tool (docgen).
934
854
  state => [], state => [state.undo.list.length, state.undo.offset]);
855
+
935
856
  /**
936
857
  * Retrieve the frontend template used for a given link.
937
858
  *
@@ -940,20 +861,17 @@ state => [], state => [state.undo.list.length, state.undo.offset]);
940
861
  *
941
862
  * @return The template record.
942
863
  */
943
-
944
864
  exports.getReferenceByDistinctEdits = getReferenceByDistinctEdits;
945
-
946
865
  function __experimentalGetTemplateForLink(state, link) {
947
866
  const records = getEntityRecords(state, 'postType', 'wp_template', {
948
867
  'find-template': link
949
868
  });
950
-
951
869
  if (records?.length) {
952
870
  return getEditedEntityRecord(state, 'postType', 'wp_template', records[0].id);
953
871
  }
954
-
955
872
  return null;
956
873
  }
874
+
957
875
  /**
958
876
  * Retrieve the current theme's base global styles
959
877
  *
@@ -961,17 +879,14 @@ function __experimentalGetTemplateForLink(state, link) {
961
879
  *
962
880
  * @return The Global Styles object.
963
881
  */
964
-
965
-
966
882
  function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
967
883
  const currentTheme = getCurrentTheme(state);
968
-
969
884
  if (!currentTheme) {
970
885
  return null;
971
886
  }
972
-
973
887
  return state.themeBaseGlobalStyles[currentTheme.stylesheet];
974
888
  }
889
+
975
890
  /**
976
891
  * Return the ID of the current global styles object.
977
892
  *
@@ -979,17 +894,14 @@ function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
979
894
  *
980
895
  * @return The current global styles ID.
981
896
  */
982
-
983
-
984
897
  function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
985
898
  const currentTheme = getCurrentTheme(state);
986
-
987
899
  if (!currentTheme) {
988
900
  return null;
989
901
  }
990
-
991
902
  return state.themeGlobalStyleVariations[currentTheme.stylesheet];
992
903
  }
904
+
993
905
  /**
994
906
  * Retrieve the list of registered block patterns.
995
907
  *
@@ -997,11 +909,10 @@ function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
997
909
  *
998
910
  * @return Block pattern list.
999
911
  */
1000
-
1001
-
1002
912
  function getBlockPatterns(state) {
1003
913
  return state.blockPatterns;
1004
914
  }
915
+
1005
916
  /**
1006
917
  * Retrieve the list of registered block pattern categories.
1007
918
  *
@@ -1009,11 +920,10 @@ function getBlockPatterns(state) {
1009
920
  *
1010
921
  * @return Block pattern category list.
1011
922
  */
1012
-
1013
-
1014
923
  function getBlockPatternCategories(state) {
1015
924
  return state.blockPatternCategories;
1016
925
  }
926
+
1017
927
  /**
1018
928
  * Returns the revisions of the current global styles theme.
1019
929
  *
@@ -1021,15 +931,11 @@ function getBlockPatternCategories(state) {
1021
931
  *
1022
932
  * @return The current global styles.
1023
933
  */
1024
-
1025
-
1026
934
  function getCurrentThemeGlobalStylesRevisions(state) {
1027
935
  const currentGlobalStylesId = __experimentalGetCurrentGlobalStylesId(state);
1028
-
1029
936
  if (!currentGlobalStylesId) {
1030
937
  return null;
1031
938
  }
1032
-
1033
939
  return state.themeGlobalStyleRevisions[currentGlobalStylesId];
1034
940
  }
1035
941
  //# sourceMappingURL=selectors.js.map