@wordpress/core-data 7.27.0 → 7.27.1-next.46f643fa0.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/build/entities.js +3 -1
- package/build/entities.js.map +1 -1
- package/build/private-actions.js +99 -0
- package/build/private-actions.js.map +1 -1
- package/build-module/entities.js +3 -1
- package/build-module/entities.js.map +1 -1
- package/build-module/private-actions.js +96 -0
- package/build-module/private-actions.js.map +1 -1
- package/build-types/entities.d.ts +18 -18
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/private-actions.d.ts +24 -0
- package/build-types/private-actions.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts +1 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts +3 -3
- package/build-types/reducer.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/entities.js +2 -0
- package/src/private-actions.js +118 -0
- package/src/test/private-actions.js +213 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const DEFAULT_ENTITY_KEY: "id";
|
|
2
2
|
export const rootEntitiesConfig: ({
|
|
3
|
-
label: import("@wordpress/i18n
|
|
3
|
+
label: import("@wordpress/i18n").TranslatableText<"Base">;
|
|
4
4
|
kind: string;
|
|
5
5
|
name: string;
|
|
6
6
|
baseURL: string;
|
|
@@ -23,7 +23,7 @@ export const rootEntitiesConfig: ({
|
|
|
23
23
|
getTitle?: undefined;
|
|
24
24
|
getRevisionsUrl?: undefined;
|
|
25
25
|
} | {
|
|
26
|
-
label: import("@wordpress/i18n
|
|
26
|
+
label: import("@wordpress/i18n").TranslatableText<"Post Type">;
|
|
27
27
|
name: string;
|
|
28
28
|
kind: string;
|
|
29
29
|
key: string;
|
|
@@ -54,7 +54,7 @@ export const rootEntitiesConfig: ({
|
|
|
54
54
|
_fields?: undefined;
|
|
55
55
|
};
|
|
56
56
|
plural: string;
|
|
57
|
-
label: import("@wordpress/i18n
|
|
57
|
+
label: import("@wordpress/i18n").TranslatableText<"Media">;
|
|
58
58
|
rawAttributes: string[];
|
|
59
59
|
supportsPagination: boolean;
|
|
60
60
|
syncConfig?: undefined;
|
|
@@ -74,7 +74,7 @@ export const rootEntitiesConfig: ({
|
|
|
74
74
|
_fields?: undefined;
|
|
75
75
|
};
|
|
76
76
|
plural: string;
|
|
77
|
-
label: import("@wordpress/i18n
|
|
77
|
+
label: import("@wordpress/i18n").TranslatableText<"Taxonomy">;
|
|
78
78
|
syncConfig?: undefined;
|
|
79
79
|
syncObjectType?: undefined;
|
|
80
80
|
getSyncObjectId?: undefined;
|
|
@@ -95,7 +95,7 @@ export const rootEntitiesConfig: ({
|
|
|
95
95
|
transientEdits: {
|
|
96
96
|
blocks: boolean;
|
|
97
97
|
};
|
|
98
|
-
label: import("@wordpress/i18n
|
|
98
|
+
label: import("@wordpress/i18n").TranslatableText<"Widget areas">;
|
|
99
99
|
syncConfig?: undefined;
|
|
100
100
|
syncObjectType?: undefined;
|
|
101
101
|
getSyncObjectId?: undefined;
|
|
@@ -116,7 +116,7 @@ export const rootEntitiesConfig: ({
|
|
|
116
116
|
transientEdits: {
|
|
117
117
|
blocks: boolean;
|
|
118
118
|
};
|
|
119
|
-
label: import("@wordpress/i18n
|
|
119
|
+
label: import("@wordpress/i18n").TranslatableText<"Widgets">;
|
|
120
120
|
syncConfig?: undefined;
|
|
121
121
|
syncObjectType?: undefined;
|
|
122
122
|
getSyncObjectId?: undefined;
|
|
@@ -134,7 +134,7 @@ export const rootEntitiesConfig: ({
|
|
|
134
134
|
_fields?: undefined;
|
|
135
135
|
};
|
|
136
136
|
plural: string;
|
|
137
|
-
label: import("@wordpress/i18n
|
|
137
|
+
label: import("@wordpress/i18n").TranslatableText<"Widget types">;
|
|
138
138
|
syncConfig?: undefined;
|
|
139
139
|
syncObjectType?: undefined;
|
|
140
140
|
getSyncObjectId?: undefined;
|
|
@@ -145,10 +145,11 @@ export const rootEntitiesConfig: ({
|
|
|
145
145
|
getTitle?: undefined;
|
|
146
146
|
getRevisionsUrl?: undefined;
|
|
147
147
|
} | {
|
|
148
|
-
label: import("@wordpress/i18n
|
|
148
|
+
label: import("@wordpress/i18n").TranslatableText<"User">;
|
|
149
149
|
name: string;
|
|
150
150
|
kind: string;
|
|
151
151
|
baseURL: string;
|
|
152
|
+
getTitle: (record: any) => any;
|
|
152
153
|
baseURLParams: {
|
|
153
154
|
context: string;
|
|
154
155
|
_fields?: undefined;
|
|
@@ -161,7 +162,6 @@ export const rootEntitiesConfig: ({
|
|
|
161
162
|
rawAttributes?: undefined;
|
|
162
163
|
supportsPagination?: undefined;
|
|
163
164
|
transientEdits?: undefined;
|
|
164
|
-
getTitle?: undefined;
|
|
165
165
|
getRevisionsUrl?: undefined;
|
|
166
166
|
} | {
|
|
167
167
|
name: string;
|
|
@@ -172,7 +172,7 @@ export const rootEntitiesConfig: ({
|
|
|
172
172
|
_fields?: undefined;
|
|
173
173
|
};
|
|
174
174
|
plural: string;
|
|
175
|
-
label: import("@wordpress/i18n
|
|
175
|
+
label: import("@wordpress/i18n").TranslatableText<"Comment">;
|
|
176
176
|
syncConfig?: undefined;
|
|
177
177
|
syncObjectType?: undefined;
|
|
178
178
|
getSyncObjectId?: undefined;
|
|
@@ -191,7 +191,7 @@ export const rootEntitiesConfig: ({
|
|
|
191
191
|
_fields?: undefined;
|
|
192
192
|
};
|
|
193
193
|
plural: string;
|
|
194
|
-
label: import("@wordpress/i18n
|
|
194
|
+
label: import("@wordpress/i18n").TranslatableText<"Menu">;
|
|
195
195
|
syncConfig?: undefined;
|
|
196
196
|
syncObjectType?: undefined;
|
|
197
197
|
getSyncObjectId?: undefined;
|
|
@@ -210,7 +210,7 @@ export const rootEntitiesConfig: ({
|
|
|
210
210
|
_fields?: undefined;
|
|
211
211
|
};
|
|
212
212
|
plural: string;
|
|
213
|
-
label: import("@wordpress/i18n
|
|
213
|
+
label: import("@wordpress/i18n").TranslatableText<"Menu Item">;
|
|
214
214
|
rawAttributes: string[];
|
|
215
215
|
syncConfig?: undefined;
|
|
216
216
|
syncObjectType?: undefined;
|
|
@@ -229,7 +229,7 @@ export const rootEntitiesConfig: ({
|
|
|
229
229
|
_fields?: undefined;
|
|
230
230
|
};
|
|
231
231
|
plural: string;
|
|
232
|
-
label: import("@wordpress/i18n
|
|
232
|
+
label: import("@wordpress/i18n").TranslatableText<"Menu Location">;
|
|
233
233
|
key: string;
|
|
234
234
|
syncConfig?: undefined;
|
|
235
235
|
syncObjectType?: undefined;
|
|
@@ -240,7 +240,7 @@ export const rootEntitiesConfig: ({
|
|
|
240
240
|
getTitle?: undefined;
|
|
241
241
|
getRevisionsUrl?: undefined;
|
|
242
242
|
} | {
|
|
243
|
-
label: import("@wordpress/i18n
|
|
243
|
+
label: import("@wordpress/i18n").TranslatableText<"Global Styles">;
|
|
244
244
|
name: string;
|
|
245
245
|
kind: string;
|
|
246
246
|
baseURL: string;
|
|
@@ -249,7 +249,7 @@ export const rootEntitiesConfig: ({
|
|
|
249
249
|
_fields?: undefined;
|
|
250
250
|
};
|
|
251
251
|
plural: string;
|
|
252
|
-
getTitle: () => import("@wordpress/i18n
|
|
252
|
+
getTitle: () => import("@wordpress/i18n").TranslatableText<"Custom Styles">;
|
|
253
253
|
getRevisionsUrl: (parentId: any, revisionId: any) => string;
|
|
254
254
|
supportsPagination: boolean;
|
|
255
255
|
syncConfig?: undefined;
|
|
@@ -259,7 +259,7 @@ export const rootEntitiesConfig: ({
|
|
|
259
259
|
rawAttributes?: undefined;
|
|
260
260
|
transientEdits?: undefined;
|
|
261
261
|
} | {
|
|
262
|
-
label: import("@wordpress/i18n
|
|
262
|
+
label: import("@wordpress/i18n").TranslatableText<"Themes">;
|
|
263
263
|
name: string;
|
|
264
264
|
kind: string;
|
|
265
265
|
baseURL: string;
|
|
@@ -278,7 +278,7 @@ export const rootEntitiesConfig: ({
|
|
|
278
278
|
getTitle?: undefined;
|
|
279
279
|
getRevisionsUrl?: undefined;
|
|
280
280
|
} | {
|
|
281
|
-
label: import("@wordpress/i18n
|
|
281
|
+
label: import("@wordpress/i18n").TranslatableText<"Plugins">;
|
|
282
282
|
name: string;
|
|
283
283
|
kind: string;
|
|
284
284
|
baseURL: string;
|
|
@@ -297,7 +297,7 @@ export const rootEntitiesConfig: ({
|
|
|
297
297
|
getTitle?: undefined;
|
|
298
298
|
getRevisionsUrl?: undefined;
|
|
299
299
|
} | {
|
|
300
|
-
label: import("@wordpress/i18n
|
|
300
|
+
label: import("@wordpress/i18n").TranslatableText<"Status">;
|
|
301
301
|
name: string;
|
|
302
302
|
kind: string;
|
|
303
303
|
baseURL: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAYA,iCAAkC,IAAI,CAAC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.js"],"names":[],"mappings":"AAYA,iCAAkC,IAAI,CAAC;AAGvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA4ME;AAEF;;;;;;;;;;KASE;AASK,0EAqBN;AAmMM,oCANI,MAAM,QACN,MAAM,WACN,MAAM,GAEL,MAAM,CAMjB;AA9KD;;;;GAIG;AACH,sDAyEC;AAwBD;;;;GAIG;AACH,gDA2CC"}
|
|
@@ -8,4 +8,28 @@
|
|
|
8
8
|
* @return {Object} Action object.
|
|
9
9
|
*/
|
|
10
10
|
export function receiveRegisteredPostMeta(postType: string, registeredPostMeta: any): any;
|
|
11
|
+
export function editMediaEntity(recordId: string, edits?: Edits, { __unstableFetch, throwOnError }?: {
|
|
12
|
+
__unstableFetch: Function;
|
|
13
|
+
throwOnError: boolean;
|
|
14
|
+
}): Promise<any>;
|
|
15
|
+
export type Modifier = {
|
|
16
|
+
/**
|
|
17
|
+
* - The type of modifier.
|
|
18
|
+
*/
|
|
19
|
+
type?: string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* - The arguments of the modifier.
|
|
22
|
+
*/
|
|
23
|
+
args?: any;
|
|
24
|
+
};
|
|
25
|
+
export type Edits = {
|
|
26
|
+
/**
|
|
27
|
+
* - The URL of the media item.
|
|
28
|
+
*/
|
|
29
|
+
src?: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* - The modifiers to apply to the media item.
|
|
32
|
+
*/
|
|
33
|
+
modifiers?: Modifier[] | undefined;
|
|
34
|
+
};
|
|
11
35
|
//# sourceMappingURL=private-actions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-actions.d.ts","sourceRoot":"","sources":["../src/private-actions.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"private-actions.d.ts","sourceRoot":"","sources":["../src/private-actions.js"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,oDALW,MAAM,gCAWhB;AAyBM,0CARI,MAAM,UACN,KAAK,sCAEb;IAA0B,eAAe;IACf,YAAY,EAA9B,OAAO;CAEf,gBAqFD"}
|
|
@@ -11,7 +11,7 @@ type EntityRecordKey = string | number;
|
|
|
11
11
|
*
|
|
12
12
|
* @return The undo manager.
|
|
13
13
|
*/
|
|
14
|
-
export declare function getUndoManager(state: State): import("@wordpress/undo-manager
|
|
14
|
+
export declare function getUndoManager(state: State): import("@wordpress/undo-manager").UndoManager;
|
|
15
15
|
/**
|
|
16
16
|
* Retrieve the fallback Navigation.
|
|
17
17
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAIhF,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"private-selectors.d.ts","sourceRoot":"","sources":["../src/private-selectors.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,EAAyC,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAIhF,KAAK,eAAe,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAE,KAAK,EAAE,KAAK,iDAE3C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,KAAK,GACV,eAAe,GAAG,SAAS,CAE7B;AAED,eAAO,MAAM,2BAA2B;;;;CAcvC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B;;;;;;;CAwBvC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM;;;EAGV;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,UAEpE;AAqBD,eAAO,MAAM,WAAW;;;;;;;CAoCvB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;CAQxB,CAAC;AAEJ,eAAO,MAAM,aAAa;;;;CAmFzB,CAAC"}
|
package/build-types/reducer.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ export function entitiesConfig(state: any, action: any): any;
|
|
|
86
86
|
/**
|
|
87
87
|
* @type {UndoManager}
|
|
88
88
|
*/
|
|
89
|
-
export function undoManager(state?: import("@wordpress/undo-manager
|
|
89
|
+
export function undoManager(state?: import("@wordpress/undo-manager").UndoManager<unknown>): import("@wordpress/undo-manager").UndoManager<unknown>;
|
|
90
90
|
export function editsReference(state: {} | undefined, action: any): {};
|
|
91
91
|
/**
|
|
92
92
|
* Reducer managing embed preview data.
|
|
@@ -160,7 +160,7 @@ declare const _default: import("redux").Reducer<{
|
|
|
160
160
|
taxonomies: any;
|
|
161
161
|
entities: any;
|
|
162
162
|
editsReference: {};
|
|
163
|
-
undoManager: import("@wordpress/undo-manager
|
|
163
|
+
undoManager: import("@wordpress/undo-manager").UndoManager<unknown>;
|
|
164
164
|
embedPreviews: any;
|
|
165
165
|
userPermissions: any;
|
|
166
166
|
autosaves: any;
|
|
@@ -182,7 +182,7 @@ declare const _default: import("redux").Reducer<{
|
|
|
182
182
|
taxonomies: any;
|
|
183
183
|
entities: any;
|
|
184
184
|
editsReference: {} | undefined;
|
|
185
|
-
undoManager: import("@wordpress/undo-manager
|
|
185
|
+
undoManager: import("@wordpress/undo-manager").UndoManager<unknown> | undefined;
|
|
186
186
|
embedPreviews: any;
|
|
187
187
|
userPermissions: any;
|
|
188
188
|
autosaves: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.js"],"names":[],"mappings":"AAmBA,2DAA2D;AAE3D;;;;;;;;;;GAUG;AACH,oDAUC;AAED;;;;;;;GAOG;AACH,oDAuBC;AAED;;;;;;;GAOG;AACH,0DAOC;AAED;;;;;;;GAOG;AACH,yDAOC;AAED;;;;;;;GAOG;AACH,oCALW,MAAM,GAAC,SAAS,gBAGf,MAAM,GAAC,SAAS,CAS3B;AAED;;;;;;;GAOG;AACH,6CALW,MAAM,GAAC,SAAS,gBAGf,MAAM,GAAC,SAAS,CAS3B;AAED;;;;;;;GAOG;AACH,6CALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,4BAGrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYjC;AAED;;;;;;;GAOG;AACH,kDALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,4BAGrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYjC;AAiND;;;;;;;GAOG;AACH,6DAOC;AA+DD;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.js"],"names":[],"mappings":"AAmBA,2DAA2D;AAE3D;;;;;;;;;;GAUG;AACH,oDAUC;AAED;;;;;;;GAOG;AACH,oDAuBC;AAED;;;;;;;GAOG;AACH,0DAOC;AAED;;;;;;;GAOG;AACH,yDAOC;AAED;;;;;;;GAOG;AACH,oCALW,MAAM,GAAC,SAAS,gBAGf,MAAM,GAAC,SAAS,CAS3B;AAED;;;;;;;GAOG;AACH,6CALW,MAAM,GAAC,SAAS,gBAGf,MAAM,GAAC,SAAS,CAS3B;AAED;;;;;;;GAOG;AACH,6CALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,4BAGrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYjC;AAED;;;;;;;GAOG;AACH,kDALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,4BAGrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYjC;AAiND;;;;;;;GAOG;AACH,6DAOC;AA+DD;;GAEG;AACH,oJAEC;AAED,uEAQC;AAED;;;;;;;GAOG;AACH,4DAUC;AAED;;;;;;;;GAQG;AACH,8DAeC;AAED;;;;;;;GAOG;AACH,wDAYC;AAED,0EAOC;AAED,mFAOC;AAED,kFAMC;AAED,gFAOC;AAED;;;;;;;GAOG;AACH,iDALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,4BAGrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYjC;AAED;;;;;;;GAOG;AACH,wCALW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,4BAGrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAYjC;AAED;;;;;;;GAOG;AACH,iEASC;AAtOM,uDAmDN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAjca,OAAO,SAAS,EAAE,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.27.0",
|
|
3
|
+
"version": "7.27.1-next.46f643fa0.0",
|
|
4
4
|
"description": "Access to and manipulation of core WordPress entities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/runtime": "7.25.7",
|
|
36
|
-
"@wordpress/api-fetch": "^7.27.0",
|
|
37
|
-
"@wordpress/block-editor": "^15.0.0",
|
|
38
|
-
"@wordpress/blocks": "^15.0.0",
|
|
39
|
-
"@wordpress/compose": "^7.27.0",
|
|
40
|
-
"@wordpress/data": "^10.27.0",
|
|
41
|
-
"@wordpress/deprecated": "^4.27.0",
|
|
42
|
-
"@wordpress/element": "^6.27.0",
|
|
43
|
-
"@wordpress/html-entities": "^4.27.0",
|
|
44
|
-
"@wordpress/i18n": "^6.0.0",
|
|
45
|
-
"@wordpress/is-shallow-equal": "^5.27.0",
|
|
46
|
-
"@wordpress/private-apis": "^1.27.0",
|
|
47
|
-
"@wordpress/rich-text": "^7.27.0",
|
|
48
|
-
"@wordpress/sync": "^1.27.0",
|
|
49
|
-
"@wordpress/undo-manager": "^1.27.0",
|
|
50
|
-
"@wordpress/url": "^4.27.0",
|
|
51
|
-
"@wordpress/warning": "^3.27.0",
|
|
36
|
+
"@wordpress/api-fetch": "^7.27.1-next.46f643fa0.0",
|
|
37
|
+
"@wordpress/block-editor": "^15.0.1-next.46f643fa0.0",
|
|
38
|
+
"@wordpress/blocks": "^15.0.1-next.46f643fa0.0",
|
|
39
|
+
"@wordpress/compose": "^7.27.1-next.46f643fa0.0",
|
|
40
|
+
"@wordpress/data": "^10.27.1-next.46f643fa0.0",
|
|
41
|
+
"@wordpress/deprecated": "^4.27.1-next.46f643fa0.0",
|
|
42
|
+
"@wordpress/element": "^6.27.1-next.46f643fa0.0",
|
|
43
|
+
"@wordpress/html-entities": "^4.27.1-next.46f643fa0.0",
|
|
44
|
+
"@wordpress/i18n": "^6.0.1-next.46f643fa0.0",
|
|
45
|
+
"@wordpress/is-shallow-equal": "^5.27.1-next.46f643fa0.0",
|
|
46
|
+
"@wordpress/private-apis": "^1.27.1-next.46f643fa0.0",
|
|
47
|
+
"@wordpress/rich-text": "^7.27.1-next.46f643fa0.0",
|
|
48
|
+
"@wordpress/sync": "^1.27.1-next.46f643fa0.0",
|
|
49
|
+
"@wordpress/undo-manager": "^1.27.1-next.46f643fa0.0",
|
|
50
|
+
"@wordpress/url": "^4.27.1-next.46f643fa0.0",
|
|
51
|
+
"@wordpress/warning": "^3.27.1-next.46f643fa0.0",
|
|
52
52
|
"change-case": "^4.1.2",
|
|
53
53
|
"equivalent-key-map": "^0.2.2",
|
|
54
54
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "17e600e091675c5e3d809adfea23ac456bbeae19"
|
|
66
66
|
}
|
package/src/entities.js
CHANGED
|
@@ -138,6 +138,7 @@ export const rootEntitiesConfig = [
|
|
|
138
138
|
name: 'user',
|
|
139
139
|
kind: 'root',
|
|
140
140
|
baseURL: '/wp/v2/users',
|
|
141
|
+
getTitle: ( record ) => record?.name || record?.slug,
|
|
141
142
|
baseURLParams: { context: 'edit' },
|
|
142
143
|
plural: 'users',
|
|
143
144
|
},
|
|
@@ -379,6 +380,7 @@ async function loadTaxonomyEntities() {
|
|
|
379
380
|
baseURLParams: { context: 'edit' },
|
|
380
381
|
name,
|
|
381
382
|
label: taxonomy.name,
|
|
383
|
+
getTitle: ( record ) => record?.name,
|
|
382
384
|
};
|
|
383
385
|
} );
|
|
384
386
|
}
|
package/src/private-actions.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { STORE_NAME } from './name';
|
|
10
|
+
|
|
1
11
|
/**
|
|
2
12
|
* Returns an action object used in signalling that the registered post meta
|
|
3
13
|
* fields for a post type have been received.
|
|
@@ -14,3 +24,111 @@ export function receiveRegisteredPostMeta( postType, registeredPostMeta ) {
|
|
|
14
24
|
registeredPostMeta,
|
|
15
25
|
};
|
|
16
26
|
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {Object} Modifier
|
|
30
|
+
* @property {string} [type] - The type of modifier.
|
|
31
|
+
* @property {Object} [args] - The arguments of the modifier.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {Object} Edits
|
|
36
|
+
* @property {string} [src] - The URL of the media item.
|
|
37
|
+
* @property {Modifier[]} [modifiers] - The modifiers to apply to the media item.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Duplicates a media (attachment) entity record and, optionally, modifies it.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} recordId Entity record ID.
|
|
44
|
+
* @param {Edits} edits Edits to apply to the record.
|
|
45
|
+
* @param {Object} options Options object.
|
|
46
|
+
* @param {Function} options.__unstableFetch Custom fetch function.
|
|
47
|
+
* @param {boolean} options.throwOnError Whether to throw an error if the request fails.
|
|
48
|
+
*
|
|
49
|
+
* @return {Promise} Promise resolving to the updated record.
|
|
50
|
+
*/
|
|
51
|
+
export const editMediaEntity =
|
|
52
|
+
(
|
|
53
|
+
recordId,
|
|
54
|
+
edits = {},
|
|
55
|
+
{ __unstableFetch = apiFetch, throwOnError = false } = {}
|
|
56
|
+
) =>
|
|
57
|
+
async ( { dispatch, resolveSelect } ) => {
|
|
58
|
+
if ( ! recordId ) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const kind = 'root';
|
|
63
|
+
const name = 'media';
|
|
64
|
+
|
|
65
|
+
const configs = await resolveSelect.getEntitiesConfig( kind );
|
|
66
|
+
const entityConfig = configs.find(
|
|
67
|
+
( config ) => config.kind === kind && config.name === name
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if ( ! entityConfig ) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const lock = await dispatch.__unstableAcquireStoreLock(
|
|
75
|
+
STORE_NAME,
|
|
76
|
+
[ 'entities', 'records', kind, name, recordId ],
|
|
77
|
+
{ exclusive: true }
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
let updatedRecord;
|
|
81
|
+
let error;
|
|
82
|
+
let hasError = false;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
dispatch( {
|
|
86
|
+
type: 'SAVE_ENTITY_RECORD_START',
|
|
87
|
+
kind,
|
|
88
|
+
name,
|
|
89
|
+
recordId,
|
|
90
|
+
} );
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const path = `${ entityConfig.baseURL }/${ recordId }/edit`;
|
|
94
|
+
const newRecord = await __unstableFetch( {
|
|
95
|
+
path,
|
|
96
|
+
method: 'POST',
|
|
97
|
+
data: {
|
|
98
|
+
...edits,
|
|
99
|
+
},
|
|
100
|
+
} );
|
|
101
|
+
|
|
102
|
+
if ( newRecord ) {
|
|
103
|
+
dispatch.receiveEntityRecords(
|
|
104
|
+
kind,
|
|
105
|
+
name,
|
|
106
|
+
[ newRecord ],
|
|
107
|
+
undefined,
|
|
108
|
+
true,
|
|
109
|
+
undefined,
|
|
110
|
+
undefined
|
|
111
|
+
);
|
|
112
|
+
updatedRecord = newRecord;
|
|
113
|
+
}
|
|
114
|
+
} catch ( e ) {
|
|
115
|
+
error = e;
|
|
116
|
+
hasError = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
dispatch( {
|
|
120
|
+
type: 'SAVE_ENTITY_RECORD_FINISH',
|
|
121
|
+
kind,
|
|
122
|
+
name,
|
|
123
|
+
recordId,
|
|
124
|
+
error,
|
|
125
|
+
} );
|
|
126
|
+
|
|
127
|
+
if ( hasError && throwOnError ) {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
return updatedRecord;
|
|
131
|
+
} finally {
|
|
132
|
+
dispatch.__unstableReleaseStoreLock( lock );
|
|
133
|
+
}
|
|
134
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import apiFetch from '@wordpress/api-fetch';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { editMediaEntity } from '../private-actions';
|
|
10
|
+
|
|
11
|
+
jest.mock( '@wordpress/api-fetch' );
|
|
12
|
+
|
|
13
|
+
describe( 'editMediaEntity', () => {
|
|
14
|
+
let dispatch;
|
|
15
|
+
let resolveSelect;
|
|
16
|
+
|
|
17
|
+
beforeEach( () => {
|
|
18
|
+
apiFetch.mockReset();
|
|
19
|
+
dispatch = Object.assign( jest.fn(), {
|
|
20
|
+
receiveEntityRecords: jest.fn(),
|
|
21
|
+
__unstableAcquireStoreLock: jest.fn( () => 'test-lock' ),
|
|
22
|
+
__unstableReleaseStoreLock: jest.fn(),
|
|
23
|
+
} );
|
|
24
|
+
resolveSelect = {
|
|
25
|
+
getEntitiesConfig: jest.fn( () => [
|
|
26
|
+
{
|
|
27
|
+
kind: 'root',
|
|
28
|
+
name: 'media',
|
|
29
|
+
baseURL: '/wp/v2/media',
|
|
30
|
+
},
|
|
31
|
+
] ),
|
|
32
|
+
};
|
|
33
|
+
} );
|
|
34
|
+
|
|
35
|
+
it( 'should return early when recordId is not provided', async () => {
|
|
36
|
+
const result = await editMediaEntity( null )( {
|
|
37
|
+
dispatch,
|
|
38
|
+
resolveSelect,
|
|
39
|
+
} );
|
|
40
|
+
|
|
41
|
+
expect( result ).toBeUndefined();
|
|
42
|
+
expect( dispatch.__unstableAcquireStoreLock ).not.toHaveBeenCalled();
|
|
43
|
+
expect( apiFetch ).not.toHaveBeenCalled();
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
it( 'should return early when entity config is not found', async () => {
|
|
47
|
+
resolveSelect.getEntitiesConfig.mockReturnValue( [] );
|
|
48
|
+
|
|
49
|
+
const result = await editMediaEntity( 123 )( {
|
|
50
|
+
dispatch,
|
|
51
|
+
resolveSelect,
|
|
52
|
+
} );
|
|
53
|
+
|
|
54
|
+
expect( result ).toBeUndefined();
|
|
55
|
+
expect( dispatch.__unstableAcquireStoreLock ).not.toHaveBeenCalled();
|
|
56
|
+
expect( apiFetch ).not.toHaveBeenCalled();
|
|
57
|
+
} );
|
|
58
|
+
|
|
59
|
+
it( 'should successfully edit a media entity', async () => {
|
|
60
|
+
const recordId = 123;
|
|
61
|
+
const edits = {
|
|
62
|
+
src: 'https://example.com/image.jpg',
|
|
63
|
+
modifiers: [
|
|
64
|
+
{ type: 'resize', args: { width: 300, height: 200 } },
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
const updatedRecord = {
|
|
68
|
+
id: recordId,
|
|
69
|
+
src: 'https://example.com/image.jpg',
|
|
70
|
+
modified: true,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
apiFetch.mockResolvedValue( updatedRecord );
|
|
74
|
+
|
|
75
|
+
const result = await editMediaEntity(
|
|
76
|
+
recordId,
|
|
77
|
+
edits
|
|
78
|
+
)( {
|
|
79
|
+
dispatch,
|
|
80
|
+
resolveSelect,
|
|
81
|
+
} );
|
|
82
|
+
|
|
83
|
+
expect( dispatch.__unstableAcquireStoreLock ).toHaveBeenCalledWith(
|
|
84
|
+
'core',
|
|
85
|
+
[ 'entities', 'records', 'root', 'media', recordId ],
|
|
86
|
+
{ exclusive: true }
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect( dispatch ).toHaveBeenCalledWith( {
|
|
90
|
+
type: 'SAVE_ENTITY_RECORD_START',
|
|
91
|
+
kind: 'root',
|
|
92
|
+
name: 'media',
|
|
93
|
+
recordId,
|
|
94
|
+
} );
|
|
95
|
+
|
|
96
|
+
expect( apiFetch ).toHaveBeenCalledWith( {
|
|
97
|
+
path: '/wp/v2/media/123/edit',
|
|
98
|
+
method: 'POST',
|
|
99
|
+
data: edits,
|
|
100
|
+
} );
|
|
101
|
+
|
|
102
|
+
expect( dispatch.receiveEntityRecords ).toHaveBeenCalledWith(
|
|
103
|
+
'root',
|
|
104
|
+
'media',
|
|
105
|
+
[ updatedRecord ],
|
|
106
|
+
undefined,
|
|
107
|
+
true,
|
|
108
|
+
undefined,
|
|
109
|
+
undefined
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect( dispatch ).toHaveBeenCalledWith( {
|
|
113
|
+
type: 'SAVE_ENTITY_RECORD_FINISH',
|
|
114
|
+
kind: 'root',
|
|
115
|
+
name: 'media',
|
|
116
|
+
recordId,
|
|
117
|
+
error: undefined,
|
|
118
|
+
} );
|
|
119
|
+
|
|
120
|
+
expect( dispatch.__unstableReleaseStoreLock ).toHaveBeenCalledWith(
|
|
121
|
+
'test-lock'
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
expect( result ).toBe( updatedRecord );
|
|
125
|
+
} );
|
|
126
|
+
|
|
127
|
+
it( 'should handle API errors when throwOnError is false', async () => {
|
|
128
|
+
const recordId = 123;
|
|
129
|
+
const edits = { src: 'https://example.com/image.jpg' };
|
|
130
|
+
const apiError = new Error( 'API error' );
|
|
131
|
+
|
|
132
|
+
apiFetch.mockRejectedValue( apiError );
|
|
133
|
+
|
|
134
|
+
const result = await editMediaEntity( recordId, edits, {
|
|
135
|
+
throwOnError: false,
|
|
136
|
+
} )( { dispatch, resolveSelect } );
|
|
137
|
+
|
|
138
|
+
expect( dispatch ).toHaveBeenCalledWith( {
|
|
139
|
+
type: 'SAVE_ENTITY_RECORD_START',
|
|
140
|
+
kind: 'root',
|
|
141
|
+
name: 'media',
|
|
142
|
+
recordId,
|
|
143
|
+
} );
|
|
144
|
+
|
|
145
|
+
expect( dispatch ).toHaveBeenCalledWith( {
|
|
146
|
+
type: 'SAVE_ENTITY_RECORD_FINISH',
|
|
147
|
+
kind: 'root',
|
|
148
|
+
name: 'media',
|
|
149
|
+
recordId,
|
|
150
|
+
error: apiError,
|
|
151
|
+
} );
|
|
152
|
+
|
|
153
|
+
expect( dispatch.__unstableReleaseStoreLock ).toHaveBeenCalledWith(
|
|
154
|
+
'test-lock'
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
expect( result ).toBeUndefined();
|
|
158
|
+
} );
|
|
159
|
+
|
|
160
|
+
it( 'should throw errors when throwOnError is true', async () => {
|
|
161
|
+
const recordId = 123;
|
|
162
|
+
const edits = { src: 'https://example.com/image.jpg' };
|
|
163
|
+
const apiError = new Error( 'API error' );
|
|
164
|
+
|
|
165
|
+
apiFetch.mockRejectedValue( apiError );
|
|
166
|
+
|
|
167
|
+
await expect(
|
|
168
|
+
editMediaEntity( recordId, edits, { throwOnError: true } )( {
|
|
169
|
+
dispatch,
|
|
170
|
+
resolveSelect,
|
|
171
|
+
} )
|
|
172
|
+
).rejects.toEqual( apiError );
|
|
173
|
+
|
|
174
|
+
expect( dispatch.__unstableReleaseStoreLock ).toHaveBeenCalledWith(
|
|
175
|
+
'test-lock'
|
|
176
|
+
);
|
|
177
|
+
} );
|
|
178
|
+
|
|
179
|
+
it( 'should use custom fetch function when provided', async () => {
|
|
180
|
+
const recordId = 123;
|
|
181
|
+
const edits = { src: 'https://example.com/image.jpg' };
|
|
182
|
+
const customFetch = jest.fn().mockResolvedValue( { id: recordId } );
|
|
183
|
+
|
|
184
|
+
await editMediaEntity( recordId, edits, {
|
|
185
|
+
__unstableFetch: customFetch,
|
|
186
|
+
} )( { dispatch, resolveSelect } );
|
|
187
|
+
|
|
188
|
+
expect( customFetch ).toHaveBeenCalledWith( {
|
|
189
|
+
path: '/wp/v2/media/123/edit',
|
|
190
|
+
method: 'POST',
|
|
191
|
+
data: edits,
|
|
192
|
+
} );
|
|
193
|
+
expect( apiFetch ).not.toHaveBeenCalled();
|
|
194
|
+
} );
|
|
195
|
+
|
|
196
|
+
it( 'should handle null response from API', async () => {
|
|
197
|
+
const recordId = 123;
|
|
198
|
+
const edits = { src: 'https://example.com/image.jpg' };
|
|
199
|
+
|
|
200
|
+
apiFetch.mockResolvedValue( null );
|
|
201
|
+
|
|
202
|
+
const result = await editMediaEntity(
|
|
203
|
+
recordId,
|
|
204
|
+
edits
|
|
205
|
+
)( {
|
|
206
|
+
dispatch,
|
|
207
|
+
resolveSelect,
|
|
208
|
+
} );
|
|
209
|
+
|
|
210
|
+
expect( dispatch.receiveEntityRecords ).not.toHaveBeenCalled();
|
|
211
|
+
expect( result ).toBeUndefined();
|
|
212
|
+
} );
|
|
213
|
+
} );
|