@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
|
@@ -22,10 +22,9 @@ import { forwardResolver, getNormalizedCommaSeparable } from './utils';
|
|
|
22
22
|
* include with request.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
export const getAuthors = query => async
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = _ref;
|
|
25
|
+
export const getAuthors = query => async ({
|
|
26
|
+
dispatch
|
|
27
|
+
}) => {
|
|
29
28
|
const path = addQueryArgs('/wp/v2/users/?who=authors&per_page=100', query);
|
|
30
29
|
const users = await apiFetch({
|
|
31
30
|
path
|
|
@@ -36,10 +35,9 @@ export const getAuthors = query => async _ref => {
|
|
|
36
35
|
* Requests the current user from the REST API.
|
|
37
36
|
*/
|
|
38
37
|
|
|
39
|
-
export const getCurrentUser = () => async
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} = _ref2;
|
|
38
|
+
export const getCurrentUser = () => async ({
|
|
39
|
+
dispatch
|
|
40
|
+
}) => {
|
|
43
41
|
const currentUser = await apiFetch({
|
|
44
42
|
path: '/wp/v2/users/me'
|
|
45
43
|
});
|
|
@@ -56,67 +54,62 @@ export const getCurrentUser = () => async _ref2 => {
|
|
|
56
54
|
* fields, fields must always include the ID.
|
|
57
55
|
*/
|
|
58
56
|
|
|
59
|
-
export const getEntityRecord =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
dispatch
|
|
66
|
-
} = _ref3;
|
|
67
|
-
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
68
|
-
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
69
|
-
|
|
70
|
-
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
57
|
+
export const getEntityRecord = (kind, name, key = '', query) => async ({
|
|
58
|
+
select,
|
|
59
|
+
dispatch
|
|
60
|
+
}) => {
|
|
61
|
+
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
62
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
73
63
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
if (!entityConfig || entityConfig?.__experimentalNoFetch) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
77
67
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// records are stored by ID reference. Thus, fields must always include
|
|
82
|
-
// the ID.
|
|
83
|
-
query = { ...query,
|
|
84
|
-
_fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
|
|
85
|
-
};
|
|
86
|
-
} // Disable reason: While true that an early return could leave `path`
|
|
87
|
-
// unused, it's important that path is derived using the query prior to
|
|
88
|
-
// additional query modifications in the condition below, since those
|
|
89
|
-
// modifications are relevant to how the data is tracked in state, and not
|
|
90
|
-
// for how the request is made to the REST API.
|
|
91
|
-
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const path = addQueryArgs(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
|
|
95
|
-
...query
|
|
96
|
-
});
|
|
68
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], {
|
|
69
|
+
exclusive: false
|
|
70
|
+
});
|
|
97
71
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
72
|
+
try {
|
|
73
|
+
if (query !== undefined && query._fields) {
|
|
74
|
+
// If requesting specific fields, items and query association to said
|
|
75
|
+
// records are stored by ID reference. Thus, fields must always include
|
|
76
|
+
// the ID.
|
|
77
|
+
query = { ...query,
|
|
78
|
+
_fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
|
|
79
|
+
};
|
|
80
|
+
} // Disable reason: While true that an early return could leave `path`
|
|
81
|
+
// unused, it's important that path is derived using the query prior to
|
|
82
|
+
// additional query modifications in the condition below, since those
|
|
83
|
+
// modifications are relevant to how the data is tracked in state, and not
|
|
84
|
+
// for how the request is made to the REST API.
|
|
85
|
+
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
const path = addQueryArgs(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
|
|
89
|
+
...query
|
|
90
|
+
});
|
|
104
91
|
|
|
105
|
-
|
|
92
|
+
if (query !== undefined) {
|
|
93
|
+
query = { ...query,
|
|
94
|
+
include: [key]
|
|
95
|
+
}; // The resolution cache won't consider query as reusable based on the
|
|
96
|
+
// fields, so it's tested here, prior to initiating the REST request,
|
|
97
|
+
// and without causing `getEntityRecords` resolution to occur.
|
|
106
98
|
|
|
107
|
-
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
99
|
+
const hasRecords = select.hasEntityRecords(kind, name, query);
|
|
111
100
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
116
|
-
} finally {
|
|
117
|
-
dispatch.__unstableReleaseStoreLock(lock);
|
|
101
|
+
if (hasRecords) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
118
104
|
}
|
|
119
|
-
|
|
105
|
+
|
|
106
|
+
const record = await apiFetch({
|
|
107
|
+
path
|
|
108
|
+
});
|
|
109
|
+
dispatch.receiveEntityRecords(kind, name, record, query);
|
|
110
|
+
} finally {
|
|
111
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
112
|
+
}
|
|
120
113
|
};
|
|
121
114
|
/**
|
|
122
115
|
* Requests an entity's record from the REST API.
|
|
@@ -137,78 +130,72 @@ export const getEditedEntityRecord = forwardResolver('getEntityRecord');
|
|
|
137
130
|
* must always include the ID.
|
|
138
131
|
*/
|
|
139
132
|
|
|
140
|
-
export const getEntityRecords =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
} = _ref4;
|
|
146
|
-
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
147
|
-
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
133
|
+
export const getEntityRecords = (kind, name, query = {}) => async ({
|
|
134
|
+
dispatch
|
|
135
|
+
}) => {
|
|
136
|
+
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
137
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
148
138
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
139
|
+
if (!entityConfig || entityConfig?.__experimentalNoFetch) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
152
142
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
143
|
+
const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
|
|
144
|
+
exclusive: false
|
|
145
|
+
});
|
|
156
146
|
|
|
157
|
-
|
|
158
|
-
|
|
147
|
+
try {
|
|
148
|
+
if (query._fields) {
|
|
149
|
+
// If requesting specific fields, items and query association to said
|
|
150
|
+
// records are stored by ID reference. Thus, fields must always include
|
|
151
|
+
// the ID.
|
|
152
|
+
query = { ...query,
|
|
153
|
+
_fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
|
|
154
|
+
};
|
|
155
|
+
}
|
|
159
156
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
157
|
+
const path = addQueryArgs(entityConfig.baseURL, { ...entityConfig.baseURLParams,
|
|
158
|
+
...query
|
|
159
|
+
});
|
|
160
|
+
let records = Object.values(await apiFetch({
|
|
161
|
+
path
|
|
162
|
+
})); // If we request fields but the result doesn't contain the fields,
|
|
163
|
+
// explicitly set these fields as "undefined"
|
|
164
|
+
// that way we consider the query "fullfilled".
|
|
165
|
+
|
|
166
|
+
if (query._fields) {
|
|
167
|
+
records = records.map(record => {
|
|
168
|
+
query._fields.split(',').forEach(field => {
|
|
169
|
+
if (!record.hasOwnProperty(field)) {
|
|
170
|
+
record[field] = undefined;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
168
173
|
|
|
169
|
-
|
|
170
|
-
...query
|
|
174
|
+
return record;
|
|
171
175
|
});
|
|
172
|
-
|
|
173
|
-
path
|
|
174
|
-
})); // If we request fields but the result doesn't contain the fields,
|
|
175
|
-
// explicitly set these fields as "undefined"
|
|
176
|
-
// that way we consider the query "fullfilled".
|
|
177
|
-
|
|
178
|
-
if (query._fields) {
|
|
179
|
-
records = records.map(record => {
|
|
180
|
-
query._fields.split(',').forEach(field => {
|
|
181
|
-
if (!record.hasOwnProperty(field)) {
|
|
182
|
-
record[field] = undefined;
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
return record;
|
|
187
|
-
});
|
|
188
|
-
}
|
|
176
|
+
}
|
|
189
177
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
} finally {
|
|
209
|
-
dispatch.__unstableReleaseStoreLock(lock);
|
|
178
|
+
dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
|
|
179
|
+
// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
|
|
180
|
+
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
181
|
+
|
|
182
|
+
if (!query?._fields && !query.context) {
|
|
183
|
+
const key = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
184
|
+
const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
|
|
185
|
+
dispatch({
|
|
186
|
+
type: 'START_RESOLUTIONS',
|
|
187
|
+
selectorName: 'getEntityRecord',
|
|
188
|
+
args: resolutionsArgs
|
|
189
|
+
});
|
|
190
|
+
dispatch({
|
|
191
|
+
type: 'FINISH_RESOLUTIONS',
|
|
192
|
+
selectorName: 'getEntityRecord',
|
|
193
|
+
args: resolutionsArgs
|
|
194
|
+
});
|
|
210
195
|
}
|
|
211
|
-
}
|
|
196
|
+
} finally {
|
|
197
|
+
dispatch.__unstableReleaseStoreLock(lock);
|
|
198
|
+
}
|
|
212
199
|
};
|
|
213
200
|
|
|
214
201
|
getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
@@ -219,11 +206,10 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
|
|
|
219
206
|
*/
|
|
220
207
|
|
|
221
208
|
|
|
222
|
-
export const getCurrentTheme = () => async
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
} = _ref5;
|
|
209
|
+
export const getCurrentTheme = () => async ({
|
|
210
|
+
dispatch,
|
|
211
|
+
resolveSelect
|
|
212
|
+
}) => {
|
|
227
213
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
228
214
|
status: 'active'
|
|
229
215
|
});
|
|
@@ -240,11 +226,9 @@ export const getThemeSupports = forwardResolver('getCurrentTheme');
|
|
|
240
226
|
* @param {string} url URL to get the preview for.
|
|
241
227
|
*/
|
|
242
228
|
|
|
243
|
-
export const getEmbedPreview = url => async
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
} = _ref6;
|
|
247
|
-
|
|
229
|
+
export const getEmbedPreview = url => async ({
|
|
230
|
+
dispatch
|
|
231
|
+
}) => {
|
|
248
232
|
try {
|
|
249
233
|
const embedProxyResponse = await apiFetch({
|
|
250
234
|
path: addQueryArgs('/oembed/1.0/proxy', {
|
|
@@ -267,13 +251,10 @@ export const getEmbedPreview = url => async _ref6 => {
|
|
|
267
251
|
* @param {?string} id ID of the rest resource to check.
|
|
268
252
|
*/
|
|
269
253
|
|
|
270
|
-
export const canUser = (requestedAction, resource, id) => async
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
dispatch,
|
|
275
|
-
registry
|
|
276
|
-
} = _ref7;
|
|
254
|
+
export const canUser = (requestedAction, resource, id) => async ({
|
|
255
|
+
dispatch,
|
|
256
|
+
registry
|
|
257
|
+
}) => {
|
|
277
258
|
const {
|
|
278
259
|
hasStartedResolution
|
|
279
260
|
} = registry.select(STORE_NAME);
|
|
@@ -314,8 +295,8 @@ export const canUser = (requestedAction, resource, id) => async _ref7 => {
|
|
|
314
295
|
// only return the result, without including response properties like the headers.
|
|
315
296
|
|
|
316
297
|
|
|
317
|
-
const allowHeader =
|
|
318
|
-
const allowedMethods =
|
|
298
|
+
const allowHeader = response.headers?.get('allow');
|
|
299
|
+
const allowedMethods = allowHeader?.allow || allowHeader || '';
|
|
319
300
|
const permissions = {};
|
|
320
301
|
const methods = {
|
|
321
302
|
create: 'POST',
|
|
@@ -341,10 +322,9 @@ export const canUser = (requestedAction, resource, id) => async _ref7 => {
|
|
|
341
322
|
* @param {string} recordId Record's id.
|
|
342
323
|
*/
|
|
343
324
|
|
|
344
|
-
export const canUserEditEntityRecord = (kind, name, recordId) => async
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
} = _ref8;
|
|
325
|
+
export const canUserEditEntityRecord = (kind, name, recordId) => async ({
|
|
326
|
+
dispatch
|
|
327
|
+
}) => {
|
|
348
328
|
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
349
329
|
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
350
330
|
|
|
@@ -362,11 +342,10 @@ export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 =>
|
|
|
362
342
|
* @param {number} postId The id of the parent post.
|
|
363
343
|
*/
|
|
364
344
|
|
|
365
|
-
export const getAutosaves = (postType, postId) => async
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
} = _ref9;
|
|
345
|
+
export const getAutosaves = (postType, postId) => async ({
|
|
346
|
+
dispatch,
|
|
347
|
+
resolveSelect
|
|
348
|
+
}) => {
|
|
370
349
|
const {
|
|
371
350
|
rest_base: restBase,
|
|
372
351
|
rest_namespace: restNamespace = 'wp/v2'
|
|
@@ -389,10 +368,9 @@ export const getAutosaves = (postType, postId) => async _ref9 => {
|
|
|
389
368
|
* @param {number} postId The id of the parent post.
|
|
390
369
|
*/
|
|
391
370
|
|
|
392
|
-
export const getAutosave = (postType, postId) => async
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
} = _ref10;
|
|
371
|
+
export const getAutosave = (postType, postId) => async ({
|
|
372
|
+
resolveSelect
|
|
373
|
+
}) => {
|
|
396
374
|
await resolveSelect.getAutosaves(postType, postId);
|
|
397
375
|
};
|
|
398
376
|
/**
|
|
@@ -401,11 +379,10 @@ export const getAutosave = (postType, postId) => async _ref10 => {
|
|
|
401
379
|
* @param {string} link Link.
|
|
402
380
|
*/
|
|
403
381
|
|
|
404
|
-
export const __experimentalGetTemplateForLink = link => async
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
} = _ref11;
|
|
382
|
+
export const __experimentalGetTemplateForLink = link => async ({
|
|
383
|
+
dispatch,
|
|
384
|
+
resolveSelect
|
|
385
|
+
}) => {
|
|
409
386
|
let template;
|
|
410
387
|
|
|
411
388
|
try {
|
|
@@ -415,12 +392,9 @@ export const __experimentalGetTemplateForLink = link => async _ref11 => {
|
|
|
415
392
|
url: addQueryArgs(link, {
|
|
416
393
|
'_wp-find-template': true
|
|
417
394
|
})
|
|
418
|
-
}).then(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
} = _ref12;
|
|
422
|
-
return data;
|
|
423
|
-
});
|
|
395
|
+
}).then(({
|
|
396
|
+
data
|
|
397
|
+
}) => data);
|
|
424
398
|
} catch (e) {// For non-FSE themes, it is possible that this request returns an error.
|
|
425
399
|
}
|
|
426
400
|
|
|
@@ -441,17 +415,14 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
|
441
415
|
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
442
416
|
};
|
|
443
417
|
|
|
444
|
-
export const __experimentalGetCurrentGlobalStylesId = () => async
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
dispatch,
|
|
449
|
-
resolveSelect
|
|
450
|
-
} = _ref13;
|
|
418
|
+
export const __experimentalGetCurrentGlobalStylesId = () => async ({
|
|
419
|
+
dispatch,
|
|
420
|
+
resolveSelect
|
|
421
|
+
}) => {
|
|
451
422
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
452
423
|
status: 'active'
|
|
453
424
|
});
|
|
454
|
-
const globalStylesURL = activeThemes
|
|
425
|
+
const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href;
|
|
455
426
|
|
|
456
427
|
if (globalStylesURL) {
|
|
457
428
|
const globalStylesObject = await apiFetch({
|
|
@@ -461,11 +432,10 @@ export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
|
461
432
|
dispatch.__experimentalReceiveCurrentGlobalStylesId(globalStylesObject.id);
|
|
462
433
|
}
|
|
463
434
|
};
|
|
464
|
-
export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
} = _ref14;
|
|
435
|
+
export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
|
|
436
|
+
resolveSelect,
|
|
437
|
+
dispatch
|
|
438
|
+
}) => {
|
|
469
439
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
470
440
|
const themeGlobalStyles = await apiFetch({
|
|
471
441
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
|
|
@@ -473,11 +443,10 @@ export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14
|
|
|
473
443
|
|
|
474
444
|
dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles);
|
|
475
445
|
};
|
|
476
|
-
export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
} = _ref15;
|
|
446
|
+
export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
|
|
447
|
+
resolveSelect,
|
|
448
|
+
dispatch
|
|
449
|
+
}) => {
|
|
481
450
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
482
451
|
const variations = await apiFetch({
|
|
483
452
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations`
|
|
@@ -489,25 +458,19 @@ export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async _
|
|
|
489
458
|
* Fetches and returns the revisions of the current global styles theme.
|
|
490
459
|
*/
|
|
491
460
|
|
|
492
|
-
export const getCurrentThemeGlobalStylesRevisions = () => async
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
resolveSelect,
|
|
497
|
-
dispatch
|
|
498
|
-
} = _ref16;
|
|
461
|
+
export const getCurrentThemeGlobalStylesRevisions = () => async ({
|
|
462
|
+
resolveSelect,
|
|
463
|
+
dispatch
|
|
464
|
+
}) => {
|
|
499
465
|
const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId();
|
|
500
466
|
const record = globalStylesId ? await resolveSelect.getEntityRecord('root', 'globalStyles', globalStylesId) : undefined;
|
|
501
|
-
const revisionsURL = record
|
|
467
|
+
const revisionsURL = record?._links?.['version-history']?.[0]?.href;
|
|
502
468
|
|
|
503
469
|
if (revisionsURL) {
|
|
504
470
|
const resetRevisions = await apiFetch({
|
|
505
471
|
url: revisionsURL
|
|
506
472
|
});
|
|
507
|
-
const revisions = resetRevisions
|
|
508
|
-
let [key, value] = _ref17;
|
|
509
|
-
return [camelCase(key), value];
|
|
510
|
-
})));
|
|
473
|
+
const revisions = resetRevisions?.map(revision => Object.fromEntries(Object.entries(revision).map(([key, value]) => [camelCase(key), value])));
|
|
511
474
|
dispatch.receiveThemeGlobalStyleRevisions(globalStylesId, revisions);
|
|
512
475
|
}
|
|
513
476
|
};
|
|
@@ -516,26 +479,21 @@ getCurrentThemeGlobalStylesRevisions.shouldInvalidate = action => {
|
|
|
516
479
|
return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles';
|
|
517
480
|
};
|
|
518
481
|
|
|
519
|
-
export const getBlockPatterns = () => async
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
} = _ref18;
|
|
482
|
+
export const getBlockPatterns = () => async ({
|
|
483
|
+
dispatch
|
|
484
|
+
}) => {
|
|
523
485
|
const restPatterns = await apiFetch({
|
|
524
486
|
path: '/wp/v2/block-patterns/patterns'
|
|
525
487
|
});
|
|
526
|
-
const patterns = restPatterns
|
|
527
|
-
let [key, value] = _ref19;
|
|
528
|
-
return [camelCase(key), value];
|
|
529
|
-
})));
|
|
488
|
+
const patterns = restPatterns?.map(pattern => Object.fromEntries(Object.entries(pattern).map(([key, value]) => [camelCase(key), value])));
|
|
530
489
|
dispatch({
|
|
531
490
|
type: 'RECEIVE_BLOCK_PATTERNS',
|
|
532
491
|
patterns
|
|
533
492
|
});
|
|
534
493
|
};
|
|
535
|
-
export const getBlockPatternCategories = () => async
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
} = _ref20;
|
|
494
|
+
export const getBlockPatternCategories = () => async ({
|
|
495
|
+
dispatch
|
|
496
|
+
}) => {
|
|
539
497
|
const categories = await apiFetch({
|
|
540
498
|
path: '/wp/v2/block-patterns/categories'
|
|
541
499
|
});
|
|
@@ -544,24 +502,21 @@ export const getBlockPatternCategories = () => async _ref20 => {
|
|
|
544
502
|
categories
|
|
545
503
|
});
|
|
546
504
|
};
|
|
547
|
-
export const getNavigationFallbackId = () => async
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
let {
|
|
551
|
-
dispatch
|
|
552
|
-
} = _ref21;
|
|
505
|
+
export const getNavigationFallbackId = () => async ({
|
|
506
|
+
dispatch
|
|
507
|
+
}) => {
|
|
553
508
|
const fallback = await apiFetch({
|
|
554
509
|
path: addQueryArgs('/wp-block-editor/v1/navigation-fallback', {
|
|
555
510
|
_embed: true
|
|
556
511
|
})
|
|
557
512
|
});
|
|
558
|
-
const record = fallback
|
|
559
|
-
dispatch.receiveNavigationFallbackId(fallback
|
|
513
|
+
const record = fallback?._embedded?.self;
|
|
514
|
+
dispatch.receiveNavigationFallbackId(fallback?.id);
|
|
560
515
|
|
|
561
516
|
if (record) {
|
|
562
517
|
dispatch.receiveEntityRecords('postType', 'wp_navigation', record); // Resolve to avoid further network requests.
|
|
563
518
|
|
|
564
|
-
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback
|
|
519
|
+
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback?.id]);
|
|
565
520
|
}
|
|
566
521
|
};
|
|
567
522
|
//# sourceMappingURL=resolvers.js.map
|