@wordpress/core-data 7.2.0 → 7.4.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 +54 -6
- package/build/actions.js +6 -6
- package/build/actions.js.map +1 -1
- package/build/entity-context.js +13 -0
- package/build/entity-context.js.map +1 -0
- package/build/entity-provider.js +4 -189
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/menu-location.js.map +1 -1
- package/build/entity-types/settings.js.map +1 -1
- package/build/entity-types/theme.js.map +1 -1
- package/build/entity-types/widget-type.js.map +1 -1
- package/build/hooks/index.js +22 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-entity-block-editor.js +140 -0
- package/build/hooks/use-entity-block-editor.js.map +1 -0
- package/build/hooks/use-entity-id.js +28 -0
- package/build/hooks/use-entity-id.js.map +1 -0
- package/build/hooks/use-entity-prop.js +65 -0
- package/build/hooks/use-entity-prop.js.map +1 -0
- package/build/hooks/use-resource-permissions.js +25 -8
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/resolvers.js +81 -70
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +23 -9
- package/build/selectors.js.map +1 -1
- package/build/utils/index.js +19 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/user-permissions.js +32 -0
- package/build/utils/user-permissions.js.map +1 -0
- package/build-module/actions.js +6 -6
- package/build-module/actions.js.map +1 -1
- package/build-module/entity-context.js +6 -0
- package/build-module/entity-context.js.map +1 -0
- package/build-module/entity-provider.js +3 -185
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/menu-location.js.map +1 -1
- package/build-module/entity-types/settings.js.map +1 -1
- package/build-module/entity-types/theme.js.map +1 -1
- package/build-module/entity-types/widget-type.js.map +1 -1
- package/build-module/hooks/index.js +3 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-entity-block-editor.js +132 -0
- package/build-module/hooks/use-entity-block-editor.js.map +1 -0
- package/build-module/hooks/use-entity-id.js +22 -0
- package/build-module/hooks/use-entity-id.js.map +1 -0
- package/build-module/hooks/use-entity-prop.js +58 -0
- package/build-module/hooks/use-entity-prop.js.map +1 -0
- package/build-module/hooks/use-resource-permissions.js +25 -8
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/resolvers.js +82 -71
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +24 -10
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/user-permissions.js +24 -0
- package/build-module/utils/user-permissions.js.map +1 -0
- package/build-types/actions.d.ts +3 -3
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/batch/create-batch.d.ts.map +1 -1
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-context.d.ts +2 -0
- package/build-types/entity-context.d.ts.map +1 -0
- package/build-types/entity-provider.d.ts +0 -48
- package/build-types/entity-provider.d.ts.map +1 -1
- package/build-types/entity-types/menu-location.d.ts.map +1 -1
- package/build-types/entity-types/settings.d.ts.map +1 -1
- package/build-types/entity-types/theme.d.ts.map +1 -1
- package/build-types/entity-types/widget-type.d.ts.map +1 -1
- package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -1
- package/build-types/hooks/index.d.ts +3 -0
- package/build-types/hooks/index.d.ts.map +1 -1
- package/build-types/hooks/use-entity-block-editor.d.ts +22 -0
- package/build-types/hooks/use-entity-block-editor.d.ts.map +1 -0
- package/build-types/hooks/use-entity-id.d.ts +9 -0
- package/build-types/hooks/use-entity-id.d.ts.map +1 -0
- package/build-types/hooks/use-entity-prop.d.ts +19 -0
- package/build-types/hooks/use-entity-prop.d.ts.map +1 -0
- package/build-types/hooks/use-resource-permissions.d.ts +8 -70
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -1
- package/build-types/index.d.ts +35 -32
- package/build-types/index.d.ts.map +1 -1
- package/build-types/locks/reducer.d.ts +1 -1
- package/build-types/locks/reducer.d.ts.map +1 -1
- package/build-types/queried-data/actions.d.ts +1 -1
- package/build-types/queried-data/actions.d.ts.map +1 -1
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -1
- package/build-types/queried-data/reducer.d.ts +1 -1
- package/build-types/queried-data/reducer.d.ts.map +1 -1
- package/build-types/queried-data/selectors.d.ts +0 -1
- package/build-types/queried-data/selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts +13 -13
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -2
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts +11 -6
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/utils/get-nested-value.d.ts.map +1 -1
- package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -1
- package/build-types/utils/if-matching-action.d.ts +1 -1
- package/build-types/utils/index.d.ts +1 -0
- package/build-types/utils/on-sub-key.d.ts +1 -1
- package/build-types/utils/replace-action.d.ts +1 -1
- package/build-types/utils/set-nested-value.d.ts.map +1 -1
- package/build-types/utils/user-permissions.d.ts +4 -0
- package/build-types/utils/user-permissions.d.ts.map +1 -0
- package/package.json +18 -17
- package/src/actions.js +6 -6
- package/src/entity-context.js +6 -0
- package/src/entity-provider.js +2 -211
- package/src/entity-types/menu-location.ts +1 -0
- package/src/entity-types/settings.ts +1 -0
- package/src/entity-types/theme.ts +1 -0
- package/src/entity-types/widget-type.ts +1 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/test/use-entity-record.js +5 -3
- package/src/hooks/test/use-resource-permissions.js +96 -5
- package/src/hooks/use-entity-block-editor.js +148 -0
- package/src/hooks/use-entity-id.js +21 -0
- package/src/hooks/use-entity-prop.js +60 -0
- package/src/hooks/use-resource-permissions.ts +46 -9
- package/src/resolvers.js +102 -78
- package/src/selectors.ts +24 -9
- package/src/test/entity-provider.js +6 -2
- package/src/test/resolvers.js +221 -50
- package/src/test/selectors.js +18 -55
- package/src/utils/index.js +5 -0
- package/src/utils/user-permissions.js +39 -0
- package/tsconfig.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAM3D,MAAM,WAAW,KAAK;IACrB,SAAS,EAAE,MAAM,CAAE,MAAM,GAAG,MAAM,EAAE,KAAK,CAAE,OAAO,CAAE,CAAE,CAAC;IACvD,aAAa,EAAE,KAAK,CAAE,OAAO,CAAE,CAAC;IAChC,sBAAsB,EAAE,KAAK,CAAE,OAAO,CAAE,CAAC;IACzC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,EAAE,CAAC,IAAI,CAAE,MAAM,CAAE,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAE,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAE,CAAC;IAClD,QAAQ,EAAE,aAAa,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IAChD,0BAA0B,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IACrD,yBAAyB,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IACpD,WAAW,EAAE,WAAW,CAAC;IACzB,eAAe,EAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;IAC3C,KAAK,EAAE,SAAS,CAAC;IACjB,oBAAoB,EAAE,eAAe,CAAC;IACtC,qBAAqB,EAAE,KAAK,CAAE,mBAAmB,CAAE,CAAC;IACpD,gBAAgB,EAA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yB,CAAE,KAAK,EAAE,KAAK,GAAI,KAAK,CAAE,GAAG,CAAE,CAEtE;AAED;;;;;;GAMG;AAEH,wBAAgB,wBAAwB,CACvC,KAAK,EAAE,KAAK,GACV,KAAK,CAAE,mBAAmB,CAAE,CAE9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,oCAAoC,CACnD,KAAK,EAAE,KAAK,GACV,KAAK,CAAE,MAAM,CAAE,GAAG,IAAI,CAcxB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,aAAa,GAClB,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,UACjB,KAAK,QACN,MAAM,QACN,MAAM,aACD,eAAe,UAClB,mBAAmB,KACzB,cAAc,EAAE,GAAG,IAQrB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,WAAW,WAEf,KAAK,QACN,MAAM,QACN,MAAM,aACD,eAAe,eACb,eAAe,UACpB,mBAAmB,KACzB,cAAc,GAAG,MAAM,CAAE,WAAW,EAAE,KAAK,CAAE,GAAG,SAAS,qCAiD5D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-nested-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-nested-value.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,0DAJW,MAAM,QAAM,
|
|
1
|
+
{"version":3,"file":"get-nested-value.d.ts","sourceRoot":"","sources":["../../src/utils/get-nested-value.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,0DAJW,MAAM,QAAM,gBACZ,GAAC,GACA,GAAC,CAgBZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-normalized-comma-separable.d.ts","sourceRoot":"","sources":["../../src/utils/get-normalized-comma-separable.js"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AACH,oDAJW,MAAM,GAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"get-normalized-comma-separable.d.ts","sourceRoot":"","sources":["../../src/utils/get-normalized-comma-separable.js"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AACH,oDAJW,MAAM,GAAC,MAAM,EAAE,GAAC,GAAC,GAEf,CAAC,MAAM,EAAE,CAAC,OAAA,CAUtB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default ifMatchingAction;
|
|
2
|
-
export type AnyFunction = import(
|
|
2
|
+
export type AnyFunction = import("../types").AnyFunction;
|
|
3
3
|
/** @typedef {import('../types').AnyFunction} AnyFunction */
|
|
4
4
|
/**
|
|
5
5
|
* A higher-order reducer creator which invokes the original reducer only if
|
|
@@ -9,4 +9,5 @@ export { default as isRawAttribute } from "./is-raw-attribute";
|
|
|
9
9
|
export { default as setNestedValue } from "./set-nested-value";
|
|
10
10
|
export { default as getNestedValue } from "./get-nested-value";
|
|
11
11
|
export { default as isNumericID } from "./is-numeric-id";
|
|
12
|
+
export { getUserPermissionCacheKey, getUserPermissionsFromResponse, ALLOWED_RESOURCE_ACTIONS } from "./user-permissions";
|
|
12
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default replaceAction;
|
|
2
|
-
export type AnyFunction = import(
|
|
2
|
+
export type AnyFunction = import("../types").AnyFunction;
|
|
3
3
|
/** @typedef {import('../types').AnyFunction} AnyFunction */
|
|
4
4
|
/**
|
|
5
5
|
* Higher-order reducer creator which substitutes the action object before
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-nested-value.d.ts","sourceRoot":"","sources":["../../src/utils/set-nested-value.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,0DAHW,QAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"set-nested-value.d.ts","sourceRoot":"","sources":["../../src/utils/set-nested-value.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,0DAHW,QAAM,MAAM,SACZ,GAAC,OAwBX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-permissions.d.ts","sourceRoot":"","sources":["../../src/utils/user-permissions.js"],"names":[],"mappings":"AAOA,kEAmBC;AAED,uFAUC;AAtCD,gDAKE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.4.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",
|
|
@@ -32,21 +32,22 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.16.0",
|
|
35
|
-
"@wordpress/api-fetch": "^7.
|
|
36
|
-
"@wordpress/block-editor": "^13.
|
|
37
|
-
"@wordpress/blocks": "^13.
|
|
38
|
-
"@wordpress/compose": "^7.
|
|
39
|
-
"@wordpress/data": "^10.
|
|
40
|
-
"@wordpress/deprecated": "^4.
|
|
41
|
-
"@wordpress/element": "^6.
|
|
42
|
-
"@wordpress/html-entities": "^4.
|
|
43
|
-
"@wordpress/i18n": "^5.
|
|
44
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
45
|
-
"@wordpress/private-apis": "^1.
|
|
46
|
-
"@wordpress/rich-text": "^7.
|
|
47
|
-
"@wordpress/sync": "^1.
|
|
48
|
-
"@wordpress/undo-manager": "^1.
|
|
49
|
-
"@wordpress/url": "^4.
|
|
35
|
+
"@wordpress/api-fetch": "^7.4.0",
|
|
36
|
+
"@wordpress/block-editor": "^13.4.0",
|
|
37
|
+
"@wordpress/blocks": "^13.4.0",
|
|
38
|
+
"@wordpress/compose": "^7.4.0",
|
|
39
|
+
"@wordpress/data": "^10.4.0",
|
|
40
|
+
"@wordpress/deprecated": "^4.4.0",
|
|
41
|
+
"@wordpress/element": "^6.4.0",
|
|
42
|
+
"@wordpress/html-entities": "^4.4.0",
|
|
43
|
+
"@wordpress/i18n": "^5.4.0",
|
|
44
|
+
"@wordpress/is-shallow-equal": "^5.4.0",
|
|
45
|
+
"@wordpress/private-apis": "^1.4.0",
|
|
46
|
+
"@wordpress/rich-text": "^7.4.0",
|
|
47
|
+
"@wordpress/sync": "^1.4.0",
|
|
48
|
+
"@wordpress/undo-manager": "^1.4.0",
|
|
49
|
+
"@wordpress/url": "^4.4.0",
|
|
50
|
+
"@wordpress/warning": "^3.4.0",
|
|
50
51
|
"change-case": "^4.1.2",
|
|
51
52
|
"equivalent-key-map": "^0.2.2",
|
|
52
53
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -60,5 +61,5 @@
|
|
|
60
61
|
"publishConfig": {
|
|
61
62
|
"access": "public"
|
|
62
63
|
},
|
|
63
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "363edb39b8dda8727f652e42cbb8497732693ed2"
|
|
64
65
|
}
|
package/src/actions.js
CHANGED
|
@@ -292,7 +292,7 @@ export const deleteEntityRecord =
|
|
|
292
292
|
);
|
|
293
293
|
let error;
|
|
294
294
|
let deletedRecord = false;
|
|
295
|
-
if ( ! entityConfig
|
|
295
|
+
if ( ! entityConfig ) {
|
|
296
296
|
return;
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -507,7 +507,7 @@ export const saveEntityRecord =
|
|
|
507
507
|
const entityConfig = configs.find(
|
|
508
508
|
( config ) => config.kind === kind && config.name === name
|
|
509
509
|
);
|
|
510
|
-
if ( ! entityConfig
|
|
510
|
+
if ( ! entityConfig ) {
|
|
511
511
|
return;
|
|
512
512
|
}
|
|
513
513
|
const entityIdKey = entityConfig.key || DEFAULT_ENTITY_KEY;
|
|
@@ -773,10 +773,10 @@ export const __experimentalBatch =
|
|
|
773
773
|
/**
|
|
774
774
|
* Action triggered to save an entity record's edits.
|
|
775
775
|
*
|
|
776
|
-
* @param {string}
|
|
777
|
-
* @param {string}
|
|
778
|
-
* @param {Object}
|
|
779
|
-
* @param {Object} options Saving options.
|
|
776
|
+
* @param {string} kind Kind of the entity.
|
|
777
|
+
* @param {string} name Name of the entity.
|
|
778
|
+
* @param {Object} recordId ID of the record.
|
|
779
|
+
* @param {Object=} options Saving options.
|
|
780
780
|
*/
|
|
781
781
|
export const saveEditedEntityRecord =
|
|
782
782
|
( kind, name, recordId, options ) =>
|
package/src/entity-provider.js
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
createContext,
|
|
6
|
-
useContext,
|
|
7
|
-
useCallback,
|
|
8
|
-
useMemo,
|
|
9
|
-
} from '@wordpress/element';
|
|
10
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
11
|
-
import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
4
|
+
import { useContext, useMemo } from '@wordpress/element';
|
|
12
5
|
|
|
13
6
|
/**
|
|
14
7
|
* Internal dependencies
|
|
15
8
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import { updateFootnotesFromMeta } from './footnotes';
|
|
18
|
-
|
|
19
|
-
/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
|
|
20
|
-
|
|
21
|
-
const EMPTY_ARRAY = [];
|
|
22
|
-
|
|
23
|
-
const EntityContext = createContext( {} );
|
|
9
|
+
import { EntityContext } from './entity-context';
|
|
24
10
|
|
|
25
11
|
/**
|
|
26
12
|
* Context provider component for providing
|
|
@@ -53,198 +39,3 @@ export default function EntityProvider( { kind, type: name, id, children } ) {
|
|
|
53
39
|
</EntityContext.Provider>
|
|
54
40
|
);
|
|
55
41
|
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Hook that returns the ID for the nearest
|
|
59
|
-
* provided entity of the specified type.
|
|
60
|
-
*
|
|
61
|
-
* @param {string} kind The entity kind.
|
|
62
|
-
* @param {string} name The entity name.
|
|
63
|
-
*/
|
|
64
|
-
export function useEntityId( kind, name ) {
|
|
65
|
-
const context = useContext( EntityContext );
|
|
66
|
-
return context?.[ kind ]?.[ name ];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Hook that returns the value and a setter for the
|
|
71
|
-
* specified property of the nearest provided
|
|
72
|
-
* entity of the specified type.
|
|
73
|
-
*
|
|
74
|
-
* @param {string} kind The entity kind.
|
|
75
|
-
* @param {string} name The entity name.
|
|
76
|
-
* @param {string} prop The property name.
|
|
77
|
-
* @param {string} [_id] An entity ID to use instead of the context-provided one.
|
|
78
|
-
*
|
|
79
|
-
* @return {[*, Function, *]} An array where the first item is the
|
|
80
|
-
* property value, the second is the
|
|
81
|
-
* setter and the third is the full value
|
|
82
|
-
* object from REST API containing more
|
|
83
|
-
* information like `raw`, `rendered` and
|
|
84
|
-
* `protected` props.
|
|
85
|
-
*/
|
|
86
|
-
export function useEntityProp( kind, name, prop, _id ) {
|
|
87
|
-
const providerId = useEntityId( kind, name );
|
|
88
|
-
const id = _id ?? providerId;
|
|
89
|
-
|
|
90
|
-
const { value, fullValue } = useSelect(
|
|
91
|
-
( select ) => {
|
|
92
|
-
const { getEntityRecord, getEditedEntityRecord } =
|
|
93
|
-
select( STORE_NAME );
|
|
94
|
-
const record = getEntityRecord( kind, name, id ); // Trigger resolver.
|
|
95
|
-
const editedRecord = getEditedEntityRecord( kind, name, id );
|
|
96
|
-
return record && editedRecord
|
|
97
|
-
? {
|
|
98
|
-
value: editedRecord[ prop ],
|
|
99
|
-
fullValue: record[ prop ],
|
|
100
|
-
}
|
|
101
|
-
: {};
|
|
102
|
-
},
|
|
103
|
-
[ kind, name, id, prop ]
|
|
104
|
-
);
|
|
105
|
-
const { editEntityRecord } = useDispatch( STORE_NAME );
|
|
106
|
-
const setValue = useCallback(
|
|
107
|
-
( newValue ) => {
|
|
108
|
-
editEntityRecord( kind, name, id, {
|
|
109
|
-
[ prop ]: newValue,
|
|
110
|
-
} );
|
|
111
|
-
},
|
|
112
|
-
[ editEntityRecord, kind, name, id, prop ]
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
return [ value, setValue, fullValue ];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const parsedBlocksCache = new WeakMap();
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Hook that returns block content getters and setters for
|
|
122
|
-
* the nearest provided entity of the specified type.
|
|
123
|
-
*
|
|
124
|
-
* The return value has the shape `[ blocks, onInput, onChange ]`.
|
|
125
|
-
* `onInput` is for block changes that don't create undo levels
|
|
126
|
-
* or dirty the post, non-persistent changes, and `onChange` is for
|
|
127
|
-
* persistent changes. They map directly to the props of a
|
|
128
|
-
* `BlockEditorProvider` and are intended to be used with it,
|
|
129
|
-
* or similar components or hooks.
|
|
130
|
-
*
|
|
131
|
-
* @param {string} kind The entity kind.
|
|
132
|
-
* @param {string} name The entity name.
|
|
133
|
-
* @param {Object} options
|
|
134
|
-
* @param {string} [options.id] An entity ID to use instead of the context-provided one.
|
|
135
|
-
*
|
|
136
|
-
* @return {[WPBlock[], Function, Function]} The block array and setters.
|
|
137
|
-
*/
|
|
138
|
-
export function useEntityBlockEditor( kind, name, { id: _id } = {} ) {
|
|
139
|
-
const providerId = useEntityId( kind, name );
|
|
140
|
-
const id = _id ?? providerId;
|
|
141
|
-
const { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME );
|
|
142
|
-
const { content, editedBlocks, meta } = useSelect(
|
|
143
|
-
( select ) => {
|
|
144
|
-
if ( ! id ) {
|
|
145
|
-
return {};
|
|
146
|
-
}
|
|
147
|
-
const { getEditedEntityRecord } = select( STORE_NAME );
|
|
148
|
-
const editedRecord = getEditedEntityRecord( kind, name, id );
|
|
149
|
-
return {
|
|
150
|
-
editedBlocks: editedRecord.blocks,
|
|
151
|
-
content: editedRecord.content,
|
|
152
|
-
meta: editedRecord.meta,
|
|
153
|
-
};
|
|
154
|
-
},
|
|
155
|
-
[ kind, name, id ]
|
|
156
|
-
);
|
|
157
|
-
const { __unstableCreateUndoLevel, editEntityRecord } =
|
|
158
|
-
useDispatch( STORE_NAME );
|
|
159
|
-
|
|
160
|
-
const blocks = useMemo( () => {
|
|
161
|
-
if ( ! id ) {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if ( editedBlocks ) {
|
|
166
|
-
return editedBlocks;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if ( ! content || typeof content !== 'string' ) {
|
|
170
|
-
return EMPTY_ARRAY;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// If there's an edit, cache the parsed blocks by the edit.
|
|
174
|
-
// If not, cache by the original enity record.
|
|
175
|
-
const edits = getEntityRecordEdits( kind, name, id );
|
|
176
|
-
const isUnedited = ! edits || ! Object.keys( edits ).length;
|
|
177
|
-
const cackeKey = isUnedited ? getEntityRecord( kind, name, id ) : edits;
|
|
178
|
-
let _blocks = parsedBlocksCache.get( cackeKey );
|
|
179
|
-
|
|
180
|
-
if ( ! _blocks ) {
|
|
181
|
-
_blocks = parse( content );
|
|
182
|
-
parsedBlocksCache.set( cackeKey, _blocks );
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return _blocks;
|
|
186
|
-
}, [
|
|
187
|
-
kind,
|
|
188
|
-
name,
|
|
189
|
-
id,
|
|
190
|
-
editedBlocks,
|
|
191
|
-
content,
|
|
192
|
-
getEntityRecord,
|
|
193
|
-
getEntityRecordEdits,
|
|
194
|
-
] );
|
|
195
|
-
|
|
196
|
-
const updateFootnotes = useCallback(
|
|
197
|
-
( _blocks ) => updateFootnotesFromMeta( _blocks, meta ),
|
|
198
|
-
[ meta ]
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
const onChange = useCallback(
|
|
202
|
-
( newBlocks, options ) => {
|
|
203
|
-
const noChange = blocks === newBlocks;
|
|
204
|
-
if ( noChange ) {
|
|
205
|
-
return __unstableCreateUndoLevel( kind, name, id );
|
|
206
|
-
}
|
|
207
|
-
const { selection, ...rest } = options;
|
|
208
|
-
|
|
209
|
-
// We create a new function here on every persistent edit
|
|
210
|
-
// to make sure the edit makes the post dirty and creates
|
|
211
|
-
// a new undo level.
|
|
212
|
-
const edits = {
|
|
213
|
-
selection,
|
|
214
|
-
content: ( { blocks: blocksForSerialization = [] } ) =>
|
|
215
|
-
__unstableSerializeAndClean( blocksForSerialization ),
|
|
216
|
-
...updateFootnotes( newBlocks ),
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
editEntityRecord( kind, name, id, edits, {
|
|
220
|
-
isCached: false,
|
|
221
|
-
...rest,
|
|
222
|
-
} );
|
|
223
|
-
},
|
|
224
|
-
[
|
|
225
|
-
kind,
|
|
226
|
-
name,
|
|
227
|
-
id,
|
|
228
|
-
blocks,
|
|
229
|
-
updateFootnotes,
|
|
230
|
-
__unstableCreateUndoLevel,
|
|
231
|
-
editEntityRecord,
|
|
232
|
-
]
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
const onInput = useCallback(
|
|
236
|
-
( newBlocks, options ) => {
|
|
237
|
-
const { selection, ...rest } = options;
|
|
238
|
-
const footnotesChanges = updateFootnotes( newBlocks );
|
|
239
|
-
const edits = { selection, ...footnotesChanges };
|
|
240
|
-
|
|
241
|
-
editEntityRecord( kind, name, id, edits, {
|
|
242
|
-
isCached: true,
|
|
243
|
-
...rest,
|
|
244
|
-
} );
|
|
245
|
-
},
|
|
246
|
-
[ kind, name, id, updateFootnotes, editEntityRecord ]
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
return [ blocks, onInput, onChange ];
|
|
250
|
-
}
|
|
@@ -7,6 +7,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco
|
|
|
7
7
|
|
|
8
8
|
declare module './base-entity-records' {
|
|
9
9
|
export namespace BaseEntityRecords {
|
|
10
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
10
11
|
export interface MenuLocation< C extends Context > {
|
|
11
12
|
/**
|
|
12
13
|
* The name of the menu location.
|
|
@@ -12,6 +12,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco
|
|
|
12
12
|
|
|
13
13
|
declare module './base-entity-records' {
|
|
14
14
|
export namespace BaseEntityRecords {
|
|
15
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
15
16
|
export interface Settings< C extends Context > {
|
|
16
17
|
/**
|
|
17
18
|
* What to show on the front page
|
|
@@ -7,6 +7,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco
|
|
|
7
7
|
|
|
8
8
|
declare module './base-entity-records' {
|
|
9
9
|
export namespace BaseEntityRecords {
|
|
10
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
10
11
|
export interface Theme< C extends Context > {
|
|
11
12
|
/**
|
|
12
13
|
* The theme's stylesheet. This uniquely identifies the theme.
|
|
@@ -7,6 +7,7 @@ import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-reco
|
|
|
7
7
|
|
|
8
8
|
declare module './base-entity-records' {
|
|
9
9
|
export namespace BaseEntityRecords {
|
|
10
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
10
11
|
export interface WidgetType< C extends Context > {
|
|
11
12
|
/**
|
|
12
13
|
* Unique slug identifying the widget type.
|
package/src/hooks/index.ts
CHANGED
|
@@ -10,3 +10,6 @@ export {
|
|
|
10
10
|
default as useResourcePermissions,
|
|
11
11
|
__experimentalUseResourcePermissions,
|
|
12
12
|
} from './use-resource-permissions';
|
|
13
|
+
export { default as useEntityBlockEditor } from './use-entity-block-editor';
|
|
14
|
+
export { default as useEntityId } from './use-entity-id';
|
|
15
|
+
export { default as useEntityProp } from './use-entity-prop';
|
|
@@ -27,10 +27,11 @@ describe( 'useEntityRecord', () => {
|
|
|
27
27
|
} );
|
|
28
28
|
|
|
29
29
|
const TEST_RECORD = { id: 1, hello: 'world' };
|
|
30
|
+
const TEST_RECORD_RESPONSE = { json: () => Promise.resolve( TEST_RECORD ) };
|
|
30
31
|
|
|
31
32
|
it( 'resolves the entity record when missing from the state', async () => {
|
|
32
33
|
// Provide response
|
|
33
|
-
triggerFetch.mockImplementation( () =>
|
|
34
|
+
triggerFetch.mockImplementation( () => TEST_RECORD_RESPONSE );
|
|
34
35
|
|
|
35
36
|
let data;
|
|
36
37
|
const TestComponent = () => {
|
|
@@ -60,6 +61,7 @@ describe( 'useEntityRecord', () => {
|
|
|
60
61
|
await waitFor( () =>
|
|
61
62
|
expect( triggerFetch ).toHaveBeenCalledWith( {
|
|
62
63
|
path: '/wp/v2/widgets/1?context=edit',
|
|
64
|
+
parse: false,
|
|
63
65
|
} )
|
|
64
66
|
);
|
|
65
67
|
|
|
@@ -79,7 +81,7 @@ describe( 'useEntityRecord', () => {
|
|
|
79
81
|
|
|
80
82
|
it( 'applies edits to the entity record', async () => {
|
|
81
83
|
// Provide response
|
|
82
|
-
triggerFetch.mockImplementation( () =>
|
|
84
|
+
triggerFetch.mockImplementation( () => TEST_RECORD_RESPONSE );
|
|
83
85
|
|
|
84
86
|
let widget;
|
|
85
87
|
const TestComponent = () => {
|
|
@@ -119,7 +121,7 @@ describe( 'useEntityRecord', () => {
|
|
|
119
121
|
} );
|
|
120
122
|
|
|
121
123
|
it( 'does not resolve entity record when disabled via options', async () => {
|
|
122
|
-
triggerFetch.mockImplementation( () =>
|
|
124
|
+
triggerFetch.mockImplementation( () => TEST_RECORD_RESPONSE );
|
|
123
125
|
|
|
124
126
|
let data;
|
|
125
127
|
const TestComponent = ( { enabled } ) => {
|
|
@@ -24,11 +24,9 @@ describe( 'useResourcePermissions', () => {
|
|
|
24
24
|
registry.register( coreDataStore );
|
|
25
25
|
|
|
26
26
|
triggerFetch.mockImplementation( () => ( {
|
|
27
|
-
headers: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} ),
|
|
31
|
-
},
|
|
27
|
+
headers: new Headers( {
|
|
28
|
+
allow: 'POST',
|
|
29
|
+
} ),
|
|
32
30
|
} ) );
|
|
33
31
|
} );
|
|
34
32
|
|
|
@@ -95,4 +93,97 @@ describe( 'useResourcePermissions', () => {
|
|
|
95
93
|
} )
|
|
96
94
|
);
|
|
97
95
|
} );
|
|
96
|
+
|
|
97
|
+
it( 'retrieves the relevant permissions for a id-less entity', async () => {
|
|
98
|
+
let data;
|
|
99
|
+
const TestComponent = () => {
|
|
100
|
+
data = useResourcePermissions( {
|
|
101
|
+
kind: 'root',
|
|
102
|
+
name: 'media',
|
|
103
|
+
} );
|
|
104
|
+
return <div />;
|
|
105
|
+
};
|
|
106
|
+
render(
|
|
107
|
+
<RegistryProvider value={ registry }>
|
|
108
|
+
<TestComponent />
|
|
109
|
+
</RegistryProvider>
|
|
110
|
+
);
|
|
111
|
+
expect( data ).toEqual( {
|
|
112
|
+
status: 'IDLE',
|
|
113
|
+
isResolving: false,
|
|
114
|
+
hasResolved: false,
|
|
115
|
+
canCreate: false,
|
|
116
|
+
canRead: false,
|
|
117
|
+
} );
|
|
118
|
+
|
|
119
|
+
await waitFor( () =>
|
|
120
|
+
expect( data ).toEqual( {
|
|
121
|
+
status: 'SUCCESS',
|
|
122
|
+
isResolving: false,
|
|
123
|
+
hasResolved: true,
|
|
124
|
+
canCreate: true,
|
|
125
|
+
canRead: false,
|
|
126
|
+
} )
|
|
127
|
+
);
|
|
128
|
+
} );
|
|
129
|
+
|
|
130
|
+
it( 'retrieves the relevant permissions for an entity', async () => {
|
|
131
|
+
let data;
|
|
132
|
+
const TestComponent = () => {
|
|
133
|
+
data = useResourcePermissions( {
|
|
134
|
+
kind: 'root',
|
|
135
|
+
name: 'media',
|
|
136
|
+
id: 1,
|
|
137
|
+
} );
|
|
138
|
+
return <div />;
|
|
139
|
+
};
|
|
140
|
+
render(
|
|
141
|
+
<RegistryProvider value={ registry }>
|
|
142
|
+
<TestComponent />
|
|
143
|
+
</RegistryProvider>
|
|
144
|
+
);
|
|
145
|
+
expect( data ).toEqual( {
|
|
146
|
+
status: 'IDLE',
|
|
147
|
+
isResolving: false,
|
|
148
|
+
hasResolved: false,
|
|
149
|
+
canCreate: false,
|
|
150
|
+
canRead: false,
|
|
151
|
+
canUpdate: false,
|
|
152
|
+
canDelete: false,
|
|
153
|
+
} );
|
|
154
|
+
|
|
155
|
+
await waitFor( () =>
|
|
156
|
+
expect( data ).toEqual( {
|
|
157
|
+
status: 'SUCCESS',
|
|
158
|
+
isResolving: false,
|
|
159
|
+
hasResolved: true,
|
|
160
|
+
canCreate: true,
|
|
161
|
+
canRead: false,
|
|
162
|
+
canUpdate: false,
|
|
163
|
+
canDelete: false,
|
|
164
|
+
} )
|
|
165
|
+
);
|
|
166
|
+
} );
|
|
167
|
+
|
|
168
|
+
it( 'should warn when called with incorrect arguments signature', () => {
|
|
169
|
+
const TestComponent = () => {
|
|
170
|
+
useResourcePermissions(
|
|
171
|
+
{
|
|
172
|
+
kind: 'root',
|
|
173
|
+
name: 'media',
|
|
174
|
+
},
|
|
175
|
+
1
|
|
176
|
+
);
|
|
177
|
+
return null;
|
|
178
|
+
};
|
|
179
|
+
render(
|
|
180
|
+
<RegistryProvider value={ registry }>
|
|
181
|
+
<TestComponent />
|
|
182
|
+
</RegistryProvider>
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
expect( console ).toHaveWarnedWith(
|
|
186
|
+
`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`
|
|
187
|
+
);
|
|
188
|
+
} );
|
|
98
189
|
} );
|