@wordpress/core-data 6.10.0 → 6.12.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.
- package/CHANGELOG.md +4 -0
- package/README.md +4 -0
- package/build/actions.js +252 -276
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +8 -16
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +1 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +16 -25
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +12 -17
- package/build/entity-provider.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -6
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +1 -2
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/hooks/use-entity-record.js +7 -11
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +3 -5
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +1 -6
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/index.js +1 -7
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +3 -4
- package/build/locks/actions.js.map +1 -1
- package/build/locks/reducer.js +1 -4
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +3 -4
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +3 -5
- package/build/locks/utils.js.map +1 -1
- package/build/private-selectors.js +37 -0
- package/build/private-selectors.js.map +1 -0
- package/build/queried-data/actions.js +2 -5
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/reducer.js +17 -47
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -11
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +167 -194
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +175 -220
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +53 -61
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js +4 -11
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js +1 -3
- package/build/utils/on-sub-key.js.map +1 -1
- package/build-module/actions.js +251 -276
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +8 -16
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +1 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +16 -25
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +12 -17
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -6
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +1 -2
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +7 -11
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +3 -5
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +1 -6
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/index.js +1 -7
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +3 -4
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/reducer.js +1 -4
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +3 -4
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +3 -5
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/private-selectors.js +28 -0
- package/build-module/private-selectors.js.map +1 -0
- package/build-module/queried-data/actions.js +2 -5
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/reducer.js +17 -47
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +4 -11
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +168 -194
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +175 -220
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +55 -61
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js +4 -11
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js +1 -3
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts +25 -0
- package/build-types/private-selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +6 -2
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/selectors.d.ts +16 -4
- package/build-types/selectors.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/actions.js +9 -8
- package/src/index.js +0 -1
- package/src/private-selectors.ts +30 -0
- package/src/reducer.js +130 -104
- package/src/selectors.ts +33 -13
- package/src/test/reducer.js +89 -54
- package/src/test/selectors.js +8 -8
- package/tsconfig.tsbuildinfo +1 -1
package/build/resolvers.js
CHANGED
|
@@ -37,10 +37,9 @@ var _utils = require("./utils");
|
|
|
37
37
|
* @param {Object|undefined} query Optional object of query parameters to
|
|
38
38
|
* include with request.
|
|
39
39
|
*/
|
|
40
|
-
const getAuthors = query => async
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} = _ref;
|
|
40
|
+
const getAuthors = query => async ({
|
|
41
|
+
dispatch
|
|
42
|
+
}) => {
|
|
44
43
|
const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
|
|
45
44
|
const users = await (0, _apiFetch.default)({
|
|
46
45
|
path
|
|
@@ -54,10 +53,9 @@ const getAuthors = query => async _ref => {
|
|
|
54
53
|
|
|
55
54
|
exports.getAuthors = getAuthors;
|
|
56
55
|
|
|
57
|
-
const getCurrentUser = () => async
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} = _ref2;
|
|
56
|
+
const getCurrentUser = () => async ({
|
|
57
|
+
dispatch
|
|
58
|
+
}) => {
|
|
61
59
|
const currentUser = await (0, _apiFetch.default)({
|
|
62
60
|
path: '/wp/v2/users/me'
|
|
63
61
|
});
|
|
@@ -77,67 +75,62 @@ const getCurrentUser = () => async _ref2 => {
|
|
|
77
75
|
|
|
78
76
|
exports.getCurrentUser = getCurrentUser;
|
|
79
77
|
|
|
80
|
-
const getEntityRecord =
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
dispatch
|
|
87
|
-
} = _ref3;
|
|
88
|
-
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
89
|
-
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
90
|
-
|
|
91
|
-
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
78
|
+
const getEntityRecord = (kind, name, key = '', query) => async ({
|
|
79
|
+
select,
|
|
80
|
+
dispatch
|
|
81
|
+
}) => {
|
|
82
|
+
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
83
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
94
84
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
85
|
+
if (!entityConfig || entityConfig?.__experimentalNoFetch) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
98
88
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
103
|
-
// the ID.
|
|
104
|
-
query = { ...query,
|
|
105
|
-
_fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
|
|
106
|
-
};
|
|
107
|
-
} // Disable reason: While true that an early return could leave `path`
|
|
108
|
-
// unused, it's important that path is derived using the query prior to
|
|
109
|
-
// additional query modifications in the condition below, since those
|
|
110
|
-
// modifications are relevant to how the data is tracked in state, and not
|
|
111
|
-
// for how the request is made to the REST API.
|
|
112
|
-
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const path = (0, _url.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
|
|
116
|
-
...query
|
|
117
|
-
});
|
|
89
|
+
const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name, key], {
|
|
90
|
+
exclusive: false
|
|
91
|
+
});
|
|
118
92
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
93
|
+
try {
|
|
94
|
+
if (query !== undefined && query._fields) {
|
|
95
|
+
// If requesting specific fields, items and query association to said
|
|
96
|
+
// records are stored by ID reference. Thus, fields must always include
|
|
97
|
+
// the ID.
|
|
98
|
+
query = { ...query,
|
|
99
|
+
_fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
|
|
100
|
+
};
|
|
101
|
+
} // Disable reason: While true that an early return could leave `path`
|
|
102
|
+
// unused, it's important that path is derived using the query prior to
|
|
103
|
+
// additional query modifications in the condition below, since those
|
|
104
|
+
// modifications are relevant to how the data is tracked in state, and not
|
|
105
|
+
// for how the request is made to the REST API.
|
|
106
|
+
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
const path = (0, _url.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
|
|
110
|
+
...query
|
|
111
|
+
});
|
|
125
112
|
|
|
126
|
-
|
|
113
|
+
if (query !== undefined) {
|
|
114
|
+
query = { ...query,
|
|
115
|
+
include: [key]
|
|
116
|
+
}; // The resolution cache won't consider query as reusable based on the
|
|
117
|
+
// fields, so it's tested here, prior to initiating the REST request,
|
|
118
|
+
// and without causing `getEntityRecords` resolution to occur.
|
|
127
119
|
|
|
128
|
-
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
120
|
+
const hasRecords = select.hasEntityRecords(kind, name, query);
|
|
132
121
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
137
|
-
} finally {
|
|
138
|
-
dispatch.__unstableReleaseStoreLock(lock);
|
|
122
|
+
if (hasRecords) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
139
125
|
}
|
|
140
|
-
|
|
126
|
+
|
|
127
|
+
const record = await (0, _apiFetch.default)({
|
|
128
|
+
path
|
|
129
|
+
});
|
|
130
|
+
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
131
|
+
} finally {
|
|
132
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
133
|
+
}
|
|
141
134
|
};
|
|
142
135
|
/**
|
|
143
136
|
* Requests an entity's record from the REST API.
|
|
@@ -163,78 +156,72 @@ const getEditedEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
|
|
|
163
156
|
|
|
164
157
|
exports.getEditedEntityRecord = getEditedEntityRecord;
|
|
165
158
|
|
|
166
|
-
const getEntityRecords =
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
} = _ref4;
|
|
172
|
-
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
173
|
-
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
159
|
+
const getEntityRecords = (kind, name, query = {}) => async ({
|
|
160
|
+
dispatch
|
|
161
|
+
}) => {
|
|
162
|
+
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
163
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
174
164
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
165
|
+
if (!entityConfig || entityConfig?.__experimentalNoFetch) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
178
168
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
169
|
+
const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name], {
|
|
170
|
+
exclusive: false
|
|
171
|
+
});
|
|
182
172
|
|
|
183
|
-
|
|
184
|
-
|
|
173
|
+
try {
|
|
174
|
+
if (query._fields) {
|
|
175
|
+
// If requesting specific fields, items and query association to said
|
|
176
|
+
// records are stored by ID reference. Thus, fields must always include
|
|
177
|
+
// the ID.
|
|
178
|
+
query = { ...query,
|
|
179
|
+
_fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
|
|
180
|
+
};
|
|
181
|
+
}
|
|
185
182
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
const path = (0, _url.addQueryArgs)(entityConfig.baseURL, { ...entityConfig.baseURLParams,
|
|
184
|
+
...query
|
|
185
|
+
});
|
|
186
|
+
let records = Object.values(await (0, _apiFetch.default)({
|
|
187
|
+
path
|
|
188
|
+
})); // If we request fields but the result doesn't contain the fields,
|
|
189
|
+
// explicitly set these fields as "undefined"
|
|
190
|
+
// that way we consider the query "fullfilled".
|
|
191
|
+
|
|
192
|
+
if (query._fields) {
|
|
193
|
+
records = records.map(record => {
|
|
194
|
+
query._fields.split(',').forEach(field => {
|
|
195
|
+
if (!record.hasOwnProperty(field)) {
|
|
196
|
+
record[field] = undefined;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
194
199
|
|
|
195
|
-
|
|
196
|
-
...query
|
|
200
|
+
return record;
|
|
197
201
|
});
|
|
198
|
-
|
|
199
|
-
path
|
|
200
|
-
})); // If we request fields but the result doesn't contain the fields,
|
|
201
|
-
// explicitly set these fields as "undefined"
|
|
202
|
-
// that way we consider the query "fullfilled".
|
|
203
|
-
|
|
204
|
-
if (query._fields) {
|
|
205
|
-
records = records.map(record => {
|
|
206
|
-
query._fields.split(',').forEach(field => {
|
|
207
|
-
if (!record.hasOwnProperty(field)) {
|
|
208
|
-
record[field] = undefined;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
return record;
|
|
213
|
-
});
|
|
214
|
-
}
|
|
202
|
+
}
|
|
215
203
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
} finally {
|
|
235
|
-
dispatch.__unstableReleaseStoreLock(lock);
|
|
204
|
+
dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
|
|
205
|
+
// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
|
|
206
|
+
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
207
|
+
|
|
208
|
+
if (!query?._fields && !query.context) {
|
|
209
|
+
const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
|
|
210
|
+
const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
|
|
211
|
+
dispatch({
|
|
212
|
+
type: 'START_RESOLUTIONS',
|
|
213
|
+
selectorName: 'getEntityRecord',
|
|
214
|
+
args: resolutionsArgs
|
|
215
|
+
});
|
|
216
|
+
dispatch({
|
|
217
|
+
type: 'FINISH_RESOLUTIONS',
|
|
218
|
+
selectorName: 'getEntityRecord',
|
|
219
|
+
args: resolutionsArgs
|
|
220
|
+
});
|
|
236
221
|
}
|
|
237
|
-
}
|
|
222
|
+
} finally {
|
|
223
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
224
|
+
}
|
|
238
225
|
};
|
|
239
226
|
|
|
240
227
|
exports.getEntityRecords = getEntityRecords;
|
|
@@ -247,11 +234,10 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
|
247
234
|
*/
|
|
248
235
|
|
|
249
236
|
|
|
250
|
-
const getCurrentTheme = () => async
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
} = _ref5;
|
|
237
|
+
const getCurrentTheme = () => async ({
|
|
238
|
+
dispatch,
|
|
239
|
+
resolveSelect
|
|
240
|
+
}) => {
|
|
255
241
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
256
242
|
status: 'active'
|
|
257
243
|
});
|
|
@@ -272,11 +258,9 @@ const getThemeSupports = (0, _utils.forwardResolver)('getCurrentTheme');
|
|
|
272
258
|
|
|
273
259
|
exports.getThemeSupports = getThemeSupports;
|
|
274
260
|
|
|
275
|
-
const getEmbedPreview = url => async
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
} = _ref6;
|
|
279
|
-
|
|
261
|
+
const getEmbedPreview = url => async ({
|
|
262
|
+
dispatch
|
|
263
|
+
}) => {
|
|
280
264
|
try {
|
|
281
265
|
const embedProxyResponse = await (0, _apiFetch.default)({
|
|
282
266
|
path: (0, _url.addQueryArgs)('/oembed/1.0/proxy', {
|
|
@@ -302,13 +286,10 @@ const getEmbedPreview = url => async _ref6 => {
|
|
|
302
286
|
|
|
303
287
|
exports.getEmbedPreview = getEmbedPreview;
|
|
304
288
|
|
|
305
|
-
const canUser = (requestedAction, resource, id) => async
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
dispatch,
|
|
310
|
-
registry
|
|
311
|
-
} = _ref7;
|
|
289
|
+
const canUser = (requestedAction, resource, id) => async ({
|
|
290
|
+
dispatch,
|
|
291
|
+
registry
|
|
292
|
+
}) => {
|
|
312
293
|
const {
|
|
313
294
|
hasStartedResolution
|
|
314
295
|
} = registry.select(_name.STORE_NAME);
|
|
@@ -349,8 +330,8 @@ const canUser = (requestedAction, resource, id) => async _ref7 => {
|
|
|
349
330
|
// only return the result, without including response properties like the headers.
|
|
350
331
|
|
|
351
332
|
|
|
352
|
-
const allowHeader =
|
|
353
|
-
const allowedMethods =
|
|
333
|
+
const allowHeader = response.headers?.get('allow');
|
|
334
|
+
const allowedMethods = allowHeader?.allow || allowHeader || '';
|
|
354
335
|
const permissions = {};
|
|
355
336
|
const methods = {
|
|
356
337
|
create: 'POST',
|
|
@@ -379,10 +360,9 @@ const canUser = (requestedAction, resource, id) => async _ref7 => {
|
|
|
379
360
|
|
|
380
361
|
exports.canUser = canUser;
|
|
381
362
|
|
|
382
|
-
const canUserEditEntityRecord = (kind, name, recordId) => async
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
} = _ref8;
|
|
363
|
+
const canUserEditEntityRecord = (kind, name, recordId) => async ({
|
|
364
|
+
dispatch
|
|
365
|
+
}) => {
|
|
386
366
|
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
|
|
387
367
|
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
388
368
|
|
|
@@ -403,11 +383,10 @@ const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
|
|
|
403
383
|
|
|
404
384
|
exports.canUserEditEntityRecord = canUserEditEntityRecord;
|
|
405
385
|
|
|
406
|
-
const getAutosaves = (postType, postId) => async
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
} = _ref9;
|
|
386
|
+
const getAutosaves = (postType, postId) => async ({
|
|
387
|
+
dispatch,
|
|
388
|
+
resolveSelect
|
|
389
|
+
}) => {
|
|
411
390
|
const {
|
|
412
391
|
rest_base: restBase,
|
|
413
392
|
rest_namespace: restNamespace = 'wp/v2'
|
|
@@ -433,10 +412,9 @@ const getAutosaves = (postType, postId) => async _ref9 => {
|
|
|
433
412
|
|
|
434
413
|
exports.getAutosaves = getAutosaves;
|
|
435
414
|
|
|
436
|
-
const getAutosave = (postType, postId) => async
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
} = _ref10;
|
|
415
|
+
const getAutosave = (postType, postId) => async ({
|
|
416
|
+
resolveSelect
|
|
417
|
+
}) => {
|
|
440
418
|
await resolveSelect.getAutosaves(postType, postId);
|
|
441
419
|
};
|
|
442
420
|
/**
|
|
@@ -448,11 +426,10 @@ const getAutosave = (postType, postId) => async _ref10 => {
|
|
|
448
426
|
|
|
449
427
|
exports.getAutosave = getAutosave;
|
|
450
428
|
|
|
451
|
-
const __experimentalGetTemplateForLink = link => async
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
} = _ref11;
|
|
429
|
+
const __experimentalGetTemplateForLink = link => async ({
|
|
430
|
+
dispatch,
|
|
431
|
+
resolveSelect
|
|
432
|
+
}) => {
|
|
456
433
|
let template;
|
|
457
434
|
|
|
458
435
|
try {
|
|
@@ -462,12 +439,9 @@ const __experimentalGetTemplateForLink = link => async _ref11 => {
|
|
|
462
439
|
url: (0, _url.addQueryArgs)(link, {
|
|
463
440
|
'_wp-find-template': true
|
|
464
441
|
})
|
|
465
|
-
}).then(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
} = _ref12;
|
|
469
|
-
return data;
|
|
470
|
-
});
|
|
442
|
+
}).then(({
|
|
443
|
+
data
|
|
444
|
+
}) => data);
|
|
471
445
|
} catch (e) {// For non-FSE themes, it is possible that this request returns an error.
|
|
472
446
|
}
|
|
473
447
|
|
|
@@ -490,17 +464,14 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
|
490
464
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
491
465
|
};
|
|
492
466
|
|
|
493
|
-
const __experimentalGetCurrentGlobalStylesId = () => async
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
dispatch,
|
|
498
|
-
resolveSelect
|
|
499
|
-
} = _ref13;
|
|
467
|
+
const __experimentalGetCurrentGlobalStylesId = () => async ({
|
|
468
|
+
dispatch,
|
|
469
|
+
resolveSelect
|
|
470
|
+
}) => {
|
|
500
471
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
501
472
|
status: 'active'
|
|
502
473
|
});
|
|
503
|
-
const globalStylesURL = activeThemes
|
|
474
|
+
const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href;
|
|
504
475
|
|
|
505
476
|
if (globalStylesURL) {
|
|
506
477
|
const globalStylesObject = await (0, _apiFetch.default)({
|
|
@@ -513,11 +484,10 @@ const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
|
513
484
|
|
|
514
485
|
exports.__experimentalGetCurrentGlobalStylesId = __experimentalGetCurrentGlobalStylesId;
|
|
515
486
|
|
|
516
|
-
const __experimentalGetCurrentThemeBaseGlobalStyles = () => async
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
} = _ref14;
|
|
487
|
+
const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
|
|
488
|
+
resolveSelect,
|
|
489
|
+
dispatch
|
|
490
|
+
}) => {
|
|
521
491
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
522
492
|
const themeGlobalStyles = await (0, _apiFetch.default)({
|
|
523
493
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
|
|
@@ -528,11 +498,10 @@ const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
|
|
|
528
498
|
|
|
529
499
|
exports.__experimentalGetCurrentThemeBaseGlobalStyles = __experimentalGetCurrentThemeBaseGlobalStyles;
|
|
530
500
|
|
|
531
|
-
const __experimentalGetCurrentThemeGlobalStylesVariations = () => async
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
} = _ref15;
|
|
501
|
+
const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
|
|
502
|
+
resolveSelect,
|
|
503
|
+
dispatch
|
|
504
|
+
}) => {
|
|
536
505
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
537
506
|
const variations = await (0, _apiFetch.default)({
|
|
538
507
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations`
|
|
@@ -547,25 +516,19 @@ const __experimentalGetCurrentThemeGlobalStylesVariations = () => async _ref15 =
|
|
|
547
516
|
|
|
548
517
|
exports.__experimentalGetCurrentThemeGlobalStylesVariations = __experimentalGetCurrentThemeGlobalStylesVariations;
|
|
549
518
|
|
|
550
|
-
const getCurrentThemeGlobalStylesRevisions = () => async
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
resolveSelect,
|
|
555
|
-
dispatch
|
|
556
|
-
} = _ref16;
|
|
519
|
+
const getCurrentThemeGlobalStylesRevisions = () => async ({
|
|
520
|
+
resolveSelect,
|
|
521
|
+
dispatch
|
|
522
|
+
}) => {
|
|
557
523
|
const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId();
|
|
558
524
|
const record = globalStylesId ? await resolveSelect.getEntityRecord('root', 'globalStyles', globalStylesId) : undefined;
|
|
559
|
-
const revisionsURL = record
|
|
525
|
+
const revisionsURL = record?._links?.['version-history']?.[0]?.href;
|
|
560
526
|
|
|
561
527
|
if (revisionsURL) {
|
|
562
528
|
const resetRevisions = await (0, _apiFetch.default)({
|
|
563
529
|
url: revisionsURL
|
|
564
530
|
});
|
|
565
|
-
const revisions = resetRevisions
|
|
566
|
-
let [key, value] = _ref17;
|
|
567
|
-
return [(0, _changeCase.camelCase)(key), value];
|
|
568
|
-
})));
|
|
531
|
+
const revisions = resetRevisions?.map(revision => Object.fromEntries(Object.entries(revision).map(([key, value]) => [(0, _changeCase.camelCase)(key), value])));
|
|
569
532
|
dispatch.receiveThemeGlobalStyleRevisions(globalStylesId, revisions);
|
|
570
533
|
}
|
|
571
534
|
};
|
|
@@ -576,17 +539,13 @@ getCurrentThemeGlobalStylesRevisions.shouldInvalidate = action => {
|
|
|
576
539
|
return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles';
|
|
577
540
|
};
|
|
578
541
|
|
|
579
|
-
const getBlockPatterns = () => async
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
} = _ref18;
|
|
542
|
+
const getBlockPatterns = () => async ({
|
|
543
|
+
dispatch
|
|
544
|
+
}) => {
|
|
583
545
|
const restPatterns = await (0, _apiFetch.default)({
|
|
584
546
|
path: '/wp/v2/block-patterns/patterns'
|
|
585
547
|
});
|
|
586
|
-
const patterns = restPatterns
|
|
587
|
-
let [key, value] = _ref19;
|
|
588
|
-
return [(0, _changeCase.camelCase)(key), value];
|
|
589
|
-
})));
|
|
548
|
+
const patterns = restPatterns?.map(pattern => Object.fromEntries(Object.entries(pattern).map(([key, value]) => [(0, _changeCase.camelCase)(key), value])));
|
|
590
549
|
dispatch({
|
|
591
550
|
type: 'RECEIVE_BLOCK_PATTERNS',
|
|
592
551
|
patterns
|
|
@@ -595,10 +554,9 @@ const getBlockPatterns = () => async _ref18 => {
|
|
|
595
554
|
|
|
596
555
|
exports.getBlockPatterns = getBlockPatterns;
|
|
597
556
|
|
|
598
|
-
const getBlockPatternCategories = () => async
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
} = _ref20;
|
|
557
|
+
const getBlockPatternCategories = () => async ({
|
|
558
|
+
dispatch
|
|
559
|
+
}) => {
|
|
602
560
|
const categories = await (0, _apiFetch.default)({
|
|
603
561
|
path: '/wp/v2/block-patterns/categories'
|
|
604
562
|
});
|
|
@@ -610,24 +568,21 @@ const getBlockPatternCategories = () => async _ref20 => {
|
|
|
610
568
|
|
|
611
569
|
exports.getBlockPatternCategories = getBlockPatternCategories;
|
|
612
570
|
|
|
613
|
-
const getNavigationFallbackId = () => async
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
let {
|
|
617
|
-
dispatch
|
|
618
|
-
} = _ref21;
|
|
571
|
+
const getNavigationFallbackId = () => async ({
|
|
572
|
+
dispatch
|
|
573
|
+
}) => {
|
|
619
574
|
const fallback = await (0, _apiFetch.default)({
|
|
620
575
|
path: (0, _url.addQueryArgs)('/wp-block-editor/v1/navigation-fallback', {
|
|
621
576
|
_embed: true
|
|
622
577
|
})
|
|
623
578
|
});
|
|
624
|
-
const record = fallback
|
|
625
|
-
dispatch.receiveNavigationFallbackId(fallback
|
|
579
|
+
const record = fallback?._embedded?.self;
|
|
580
|
+
dispatch.receiveNavigationFallbackId(fallback?.id);
|
|
626
581
|
|
|
627
582
|
if (record) {
|
|
628
583
|
dispatch.receiveEntityRecords('postType', 'wp_navigation', record); // Resolve to avoid further network requests.
|
|
629
584
|
|
|
630
|
-
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback
|
|
585
|
+
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback?.id]);
|
|
631
586
|
}
|
|
632
587
|
};
|
|
633
588
|
|