@wordpress/core-data 4.11.0 → 4.14.1-next.d6164808d3.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 +10 -0
- package/README.md +124 -81
- package/build/actions.js +27 -0
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +3 -15
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +7 -5
- package/build/entities.js.map +1 -1
- package/build/hooks/index.js +14 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-entity-record.js +84 -2
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +53 -6
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -28
- package/build/index.js.map +1 -1
- package/build/resolvers.js +22 -24
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +5 -3
- package/build/selectors.js.map +1 -1
- package/build-module/actions.js +27 -0
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +3 -14
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +7 -6
- package/build-module/entities.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +82 -2
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +49 -5
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -3
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +22 -24
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +6 -4
- package/build-module/selectors.js.map +1 -1
- package/package.json +12 -11
- package/src/actions.js +27 -0
- package/src/batch/create-batch.js +3 -12
- package/src/entities.ts +8 -6
- package/src/entity-types/theme.ts +4 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +9 -1
- package/src/hooks/test/use-resource-permissions.js +28 -36
- package/src/hooks/use-entity-record.ts +99 -2
- package/src/hooks/use-resource-permissions.ts +60 -18
- package/src/index.js +0 -3
- package/src/resolvers.js +41 -36
- package/src/selectors.ts +6 -4
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
4
5
|
import deprecated from '@wordpress/deprecated';
|
|
6
|
+
import { useMemo } from '@wordpress/element';
|
|
5
7
|
/**
|
|
6
8
|
* Internal dependencies
|
|
7
9
|
*/
|
|
@@ -38,6 +40,60 @@ import { store as coreStore } from '../';
|
|
|
38
40
|
* application, the page and the resolution details will be retrieved from
|
|
39
41
|
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
40
42
|
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* import { useDispatch } from '@wordpress/data';
|
|
46
|
+
* import { useCallback } from '@wordpress/element';
|
|
47
|
+
* import { __ } from '@wordpress/i18n';
|
|
48
|
+
* import { TextControl } from '@wordpress/components';
|
|
49
|
+
* import { store as noticeStore } from '@wordpress/notices';
|
|
50
|
+
* import { useEntityRecord } from '@wordpress/core-data';
|
|
51
|
+
*
|
|
52
|
+
* function PageRenameForm( { id } ) {
|
|
53
|
+
* const page = useEntityRecord( 'postType', 'page', id );
|
|
54
|
+
* const { createSuccessNotice, createErrorNotice } =
|
|
55
|
+
* useDispatch( noticeStore );
|
|
56
|
+
*
|
|
57
|
+
* const setTitle = useCallback( ( title ) => {
|
|
58
|
+
* page.edit( { title } );
|
|
59
|
+
* }, [ page.edit ] );
|
|
60
|
+
*
|
|
61
|
+
* if ( page.isResolving ) {
|
|
62
|
+
* return 'Loading...';
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* async function onRename( event ) {
|
|
66
|
+
* event.preventDefault();
|
|
67
|
+
* try {
|
|
68
|
+
* await page.save();
|
|
69
|
+
* createSuccessNotice( __( 'Page renamed.' ), {
|
|
70
|
+
* type: 'snackbar',
|
|
71
|
+
* } );
|
|
72
|
+
* } catch ( error ) {
|
|
73
|
+
* createErrorNotice( error.message, { type: 'snackbar' } );
|
|
74
|
+
* }
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* return (
|
|
78
|
+
* <form onSubmit={ onRename }>
|
|
79
|
+
* <TextControl
|
|
80
|
+
* label={ __( 'Name' ) }
|
|
81
|
+
* value={ page.editedRecord.title }
|
|
82
|
+
* onChange={ setTitle }
|
|
83
|
+
* />
|
|
84
|
+
* <button type="submit">{ __( 'Save' ) }</button>
|
|
85
|
+
* </form>
|
|
86
|
+
* );
|
|
87
|
+
* }
|
|
88
|
+
*
|
|
89
|
+
* // Rendered in the application:
|
|
90
|
+
* // <PageRenameForm id={ 1 } />
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* In the above example, updating and saving the page title is handled
|
|
94
|
+
* via the `edit()` and `save()` mutation helpers provided by
|
|
95
|
+
* `useEntityRecord()`;
|
|
96
|
+
*
|
|
41
97
|
* @return Entity record data.
|
|
42
98
|
* @template RecordType
|
|
43
99
|
*/
|
|
@@ -45,9 +101,30 @@ export default function useEntityRecord(kind, name, recordId) {
|
|
|
45
101
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
46
102
|
enabled: true
|
|
47
103
|
};
|
|
104
|
+
const {
|
|
105
|
+
editEntityRecord,
|
|
106
|
+
saveEditedEntityRecord
|
|
107
|
+
} = useDispatch(coreStore);
|
|
108
|
+
const mutations = useMemo(() => ({
|
|
109
|
+
edit: record => editEntityRecord(kind, name, recordId, record),
|
|
110
|
+
save: function () {
|
|
111
|
+
let saveOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
112
|
+
return saveEditedEntityRecord(kind, name, recordId, {
|
|
113
|
+
throwOnError: true,
|
|
114
|
+
...saveOptions
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}), [recordId]);
|
|
118
|
+
const {
|
|
119
|
+
editedRecord,
|
|
120
|
+
hasEdits
|
|
121
|
+
} = useSelect(select => ({
|
|
122
|
+
editedRecord: select(coreStore).getEditedEntityRecord(),
|
|
123
|
+
hasEdits: select(coreStore).hasEditsForEntityRecord()
|
|
124
|
+
}), [kind, name, recordId]);
|
|
48
125
|
const {
|
|
49
126
|
data: record,
|
|
50
|
-
...
|
|
127
|
+
...querySelectRest
|
|
51
128
|
} = useQuerySelect(query => {
|
|
52
129
|
if (!options.enabled) {
|
|
53
130
|
return null;
|
|
@@ -57,7 +134,10 @@ export default function useEntityRecord(kind, name, recordId) {
|
|
|
57
134
|
}, [kind, name, recordId, options.enabled]);
|
|
58
135
|
return {
|
|
59
136
|
record,
|
|
60
|
-
|
|
137
|
+
editedRecord,
|
|
138
|
+
hasEdits,
|
|
139
|
+
...querySelectRest,
|
|
140
|
+
...mutations
|
|
61
141
|
};
|
|
62
142
|
}
|
|
63
143
|
export function __experimentalUseEntityRecord(kind, name, recordId, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["deprecated","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,SAASC,OAAT,QAAwB,oBAAxB;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;;AA4CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MACLd,WAAW,CAAEM,SAAF,CADZ;AAGA,QAAMS,SAAS,GAAGZ,OAAO,CACxB,OAAQ;AACPa,IAAAA,IAAI,EAAIC,MAAF,IACLJ,gBAAgB,CAAEL,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBO,MAAxB,CAFV;AAGPC,IAAAA,IAAI,EAAE;AAAA,UAAEC,WAAF,uEAAqB,EAArB;AAAA,aACLL,sBAAsB,CAAEN,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwB;AAC7CU,QAAAA,YAAY,EAAE,IAD+B;AAE7C,WAAGD;AAF0C,OAAxB,CADjB;AAAA;AAHC,GAAR,CADwB,EAUxB,CAAET,QAAF,CAVwB,CAAzB;AAaA,QAAM;AAAEW,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,MAA6BrB,SAAS,CACzCsB,MAAF,KAAgB;AACfF,IAAAA,YAAY,EAAEE,MAAM,CAAEjB,SAAF,CAAN,CAAoBkB,qBAApB,EADC;AAEfF,IAAAA,QAAQ,EAAEC,MAAM,CAAEjB,SAAF,CAAN,CAAoBmB,uBAApB;AAFK,GAAhB,CAD2C,EAK3C,CAAEjB,IAAF,EAAQC,IAAR,EAAcC,QAAd,CAL2C,CAA5C;AAQA,QAAM;AAAEgB,IAAAA,IAAI,EAAET,MAAR;AAAgB,OAAGU;AAAnB,MAAuCvB,cAAc,CACxDwB,KAAF,IAAa;AACZ,QAAK,CAAEjB,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOgB,KAAK,CAAEtB,SAAF,CAAL,CAAmBuB,eAAnB,CAAoCrB,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GANyD,EAO1D,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAP0D,CAA3D;AAUA,SAAO;AACNK,IAAAA,MADM;AAENI,IAAAA,YAFM;AAGNC,IAAAA,QAHM;AAIN,OAAGK,eAJG;AAKN,OAAGZ;AALG,GAAP;AAOA;AAED,OAAO,SAASe,6BAAT,CACNtB,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACDT,EAAAA,UAAU,CAAG,uCAAH,EAA2C;AACpD6B,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAA3C,CAAV;AAIA,SAAOzB,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ recordId ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import deprecated from '@wordpress/deprecated';
|
|
1
5
|
/**
|
|
2
6
|
* Internal dependencies
|
|
3
7
|
*/
|
|
8
|
+
|
|
4
9
|
import { store as coreStore } from '../';
|
|
5
10
|
import { Status } from './constants';
|
|
6
11
|
import useQuerySelect from './use-query-select';
|
|
@@ -34,6 +39,36 @@ import useQuerySelect from './use-query-select';
|
|
|
34
39
|
* // <PagesList />
|
|
35
40
|
* ```
|
|
36
41
|
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```js
|
|
44
|
+
* import { useResourcePermissions } from '@wordpress/core-data';
|
|
45
|
+
*
|
|
46
|
+
* function Page({ pageId }) {
|
|
47
|
+
* const {
|
|
48
|
+
* canCreate,
|
|
49
|
+
* canUpdate,
|
|
50
|
+
* canDelete,
|
|
51
|
+
* isResolving
|
|
52
|
+
* } = useResourcePermissions( 'pages', pageId );
|
|
53
|
+
*
|
|
54
|
+
* if ( isResolving ) {
|
|
55
|
+
* return 'Loading ...';
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <div>
|
|
60
|
+
* {canCreate ? (<button>+ Create a new page</button>) : false}
|
|
61
|
+
* {canUpdate ? (<button>Edit page</button>) : false}
|
|
62
|
+
* {canDelete ? (<button>Delete page</button>) : false}
|
|
63
|
+
* // ...
|
|
64
|
+
* </div>
|
|
65
|
+
* );
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* // Rendered in the application:
|
|
69
|
+
* // <Page pageId={ 15 } />
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
37
72
|
* In the above example, when `PagesList` is rendered into an
|
|
38
73
|
* application, the appropriate permissions and the resolution details will be retrieved from
|
|
39
74
|
* the store state using `canUser()`, or resolved if missing.
|
|
@@ -41,7 +76,7 @@ import useQuerySelect from './use-query-select';
|
|
|
41
76
|
* @return Entity records data.
|
|
42
77
|
* @template IdType
|
|
43
78
|
*/
|
|
44
|
-
export default function
|
|
79
|
+
export default function useResourcePermissions(resource, id) {
|
|
45
80
|
return useQuerySelect(resolve => {
|
|
46
81
|
const {
|
|
47
82
|
canUser
|
|
@@ -49,11 +84,12 @@ export default function __experimentalUseResourcePermissions(resource, id) {
|
|
|
49
84
|
const create = canUser('create', resource);
|
|
50
85
|
|
|
51
86
|
if (!id) {
|
|
52
|
-
return
|
|
87
|
+
return {
|
|
53
88
|
status: create.status,
|
|
54
89
|
isResolving: create.isResolving,
|
|
90
|
+
hasResolved: create.hasResolved,
|
|
55
91
|
canCreate: create.hasResolved && create.data
|
|
56
|
-
}
|
|
92
|
+
};
|
|
57
93
|
}
|
|
58
94
|
|
|
59
95
|
const update = canUser('update', resource, id);
|
|
@@ -70,13 +106,21 @@ export default function __experimentalUseResourcePermissions(resource, id) {
|
|
|
70
106
|
status = Status.Success;
|
|
71
107
|
}
|
|
72
108
|
|
|
73
|
-
return
|
|
109
|
+
return {
|
|
74
110
|
status,
|
|
75
111
|
isResolving,
|
|
112
|
+
hasResolved,
|
|
76
113
|
canCreate: hasResolved && create.data,
|
|
77
114
|
canUpdate: hasResolved && update.data,
|
|
78
115
|
canDelete: hasResolved && _delete.data
|
|
79
|
-
}
|
|
116
|
+
};
|
|
80
117
|
}, [resource, id]);
|
|
81
118
|
}
|
|
119
|
+
export function __experimentalUseResourcePermissions(resource, id) {
|
|
120
|
+
deprecated(`wp.data.__experimentalUseResourcePermissions`, {
|
|
121
|
+
alternative: 'wp.data.useResourcePermissions',
|
|
122
|
+
since: '6.1'
|
|
123
|
+
});
|
|
124
|
+
return useResourcePermissions(resource, id);
|
|
125
|
+
}
|
|
82
126
|
//# sourceMappingURL=use-resource-permissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["store","coreStore","Status","useQuerySelect","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["deprecated","store","coreStore","Status","useQuerySelect","useResourcePermissions","resource","id","resolve","canUser","create","status","isResolving","hasResolved","canCreate","data","update","_delete","Idle","Resolving","Success","canUpdate","canDelete","__experimentalUseResourcePermissions","alternative","since"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,KAAnC;AACA,SAASC,MAAT,QAAuB,aAAvB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;;AAiCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SA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;AAMNO,MAAAA,SAAS,EAAET,WAAW,IAAII,OAAO,CAACF;AAN5B,KAAP;AAQA,GAlCmB,EAmCpB,CAAET,QAAF,EAAYC,EAAZ,CAnCoB,CAArB;AAqCA;AAED,OAAO,SAASgB,oCAAT,CACNjB,QADM,EAENC,EAFM,EAGL;AACDP,EAAAA,UAAU,CAAG,8CAAH,EAAkD;AAC3DwB,IAAAA,WAAW,EAAE,gCAD8C;AAE3DC,IAAAA,KAAK,EAAE;AAFoD,GAAlD,CAAV;AAIA,SAAOpB,sBAAsB,CAAEC,QAAF,EAAYC,EAAZ,CAA7B;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {\n\t\t\t\t\tstatus: create.status,\n\t\t\t\t\tisResolving: create.isResolving,\n\t\t\t\t\thasResolved: create.hasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tcreate.isResolving || update.isResolving || _delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tcreate.hasResolved && update.hasResolved && _delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: IdType\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"]}
|
package/build-module/index.js
CHANGED
|
@@ -89,9 +89,6 @@ const storeConfig = () => ({
|
|
|
89
89
|
export const store = createReduxStore(STORE_NAME, storeConfig());
|
|
90
90
|
register(store);
|
|
91
91
|
export { default as EntityProvider } from './entity-provider';
|
|
92
|
-
export { default as useEntityRecord } from './hooks/use-entity-record';
|
|
93
|
-
export { default as useEntityRecords } from './hooks/use-entity-records';
|
|
94
|
-
export { default as __experimentalUseResourcePermissions } from './hooks/use-resource-permissions';
|
|
95
92
|
export * from './entity-provider';
|
|
96
93
|
export * from './entity-types';
|
|
97
94
|
export * from './fetch';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","default","EntityProvider"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveE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d,IAA5B,EAAkCC,IAAlC,EAAwCE,GAAxC,EAA6CC,KAA7C,CADD;;AAEA,SAAON,MAAP;AACA,CAPqB,EAOnB,EAPmB,CAAtB;;AASA,MAAMiB,WAAW,GAAG,OAAQ;AAC3B3B,EAAAA,OAD2B;AAE3BE,EAAAA,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGsB,aAAjB;AAAgC,OAAGpB,kBAAkB;AAArD,GAFkB;AAG3BH,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGO;AAAnB,GAHgB;AAI3BL,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGgB;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMS,KAAK,GAAG9B,gBAAgB,CAAES,UAAF,EAAcoB,WAAW,EAAzB,CAA9B;AAEP5B,QAAQ,CAAE6B,KAAF,CAAR;AAEA,SAASC,OAAO,IAAIC,cAApB,QAA0C,mBAA1C;AACA,cAAc,mBAAd;AACA,cAAc,gBAAd;AACA,cAAc,SAAd;AACA,cAAc,SAAd","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { camelCase
|
|
4
|
+
import { camelCase } from 'change-case';
|
|
5
5
|
/**
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
@@ -52,7 +52,8 @@ export const getCurrentUser = () => async _ref2 => {
|
|
|
52
52
|
* @param {string} name Entity name.
|
|
53
53
|
* @param {number|string} key Record's key
|
|
54
54
|
* @param {Object|undefined} query Optional object of query parameters to
|
|
55
|
-
* include with request.
|
|
55
|
+
* include with request. If requesting specific
|
|
56
|
+
* fields, fields must always include the ID.
|
|
56
57
|
*/
|
|
57
58
|
|
|
58
59
|
export const getEntityRecord = function (kind, name) {
|
|
@@ -64,10 +65,7 @@ export const getEntityRecord = function (kind, name) {
|
|
|
64
65
|
dispatch
|
|
65
66
|
} = _ref3;
|
|
66
67
|
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
67
|
-
const entityConfig = find(
|
|
68
|
-
kind,
|
|
69
|
-
name
|
|
70
|
-
});
|
|
68
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
71
69
|
|
|
72
70
|
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
73
71
|
return;
|
|
@@ -83,7 +81,7 @@ export const getEntityRecord = function (kind, name) {
|
|
|
83
81
|
// records are stored by ID reference. Thus, fields must always include
|
|
84
82
|
// the ID.
|
|
85
83
|
query = { ...query,
|
|
86
|
-
_fields:
|
|
84
|
+
_fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
|
|
87
85
|
};
|
|
88
86
|
} // Disable reason: While true that an early return could leave `path`
|
|
89
87
|
// unused, it's important that path is derived using the query prior to
|
|
@@ -135,7 +133,8 @@ export const getEditedEntityRecord = forwardResolver('getEntityRecord');
|
|
|
135
133
|
*
|
|
136
134
|
* @param {string} kind Entity kind.
|
|
137
135
|
* @param {string} name Entity name.
|
|
138
|
-
* @param {Object?} query Query Object.
|
|
136
|
+
* @param {Object?} query Query Object. If requesting specific fields, fields
|
|
137
|
+
* must always include the ID.
|
|
139
138
|
*/
|
|
140
139
|
|
|
141
140
|
export const getEntityRecords = function (kind, name) {
|
|
@@ -145,10 +144,7 @@ export const getEntityRecords = function (kind, name) {
|
|
|
145
144
|
dispatch
|
|
146
145
|
} = _ref4;
|
|
147
146
|
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
148
|
-
const entityConfig = find(
|
|
149
|
-
kind,
|
|
150
|
-
name
|
|
151
|
-
});
|
|
147
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
152
148
|
|
|
153
149
|
if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
|
|
154
150
|
return;
|
|
@@ -166,7 +162,7 @@ export const getEntityRecords = function (kind, name) {
|
|
|
166
162
|
// records are stored by ID reference. Thus, fields must always include
|
|
167
163
|
// the ID.
|
|
168
164
|
query = { ...query,
|
|
169
|
-
_fields:
|
|
165
|
+
_fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
|
|
170
166
|
};
|
|
171
167
|
}
|
|
172
168
|
|
|
@@ -272,7 +268,7 @@ export const getEmbedPreview = url => async _ref6 => {
|
|
|
272
268
|
*/
|
|
273
269
|
|
|
274
270
|
export const canUser = (action, resource, id) => async _ref7 => {
|
|
275
|
-
var _response$headers;
|
|
271
|
+
var _response$headers, _allowHeader$includes;
|
|
276
272
|
|
|
277
273
|
let {
|
|
278
274
|
dispatch
|
|
@@ -308,8 +304,8 @@ export const canUser = (action, resource, id) => async _ref7 => {
|
|
|
308
304
|
|
|
309
305
|
|
|
310
306
|
const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow');
|
|
311
|
-
const key =
|
|
312
|
-
const isAllowed = includes(allowHeader, method);
|
|
307
|
+
const key = [action, resource, id].filter(Boolean).join('/');
|
|
308
|
+
const isAllowed = (allowHeader === null || allowHeader === void 0 ? void 0 : (_allowHeader$includes = allowHeader.includes) === null || _allowHeader$includes === void 0 ? void 0 : _allowHeader$includes.call(allowHeader, method)) || (allowHeader === null || allowHeader === void 0 ? void 0 : allowHeader.allow) === method;
|
|
313
309
|
dispatch.receiveUserPermission(key, isAllowed);
|
|
314
310
|
};
|
|
315
311
|
/**
|
|
@@ -326,10 +322,7 @@ export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 =>
|
|
|
326
322
|
dispatch
|
|
327
323
|
} = _ref8;
|
|
328
324
|
const configs = await dispatch(getOrLoadEntitiesConfig(kind));
|
|
329
|
-
const entityConfig = find(
|
|
330
|
-
kind,
|
|
331
|
-
name
|
|
332
|
-
});
|
|
325
|
+
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
333
326
|
|
|
334
327
|
if (!entityConfig) {
|
|
335
328
|
return;
|
|
@@ -424,6 +417,8 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
|
424
417
|
};
|
|
425
418
|
|
|
426
419
|
export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
420
|
+
var _activeThemes$, _activeThemes$$_links, _activeThemes$$_links2, _activeThemes$$_links3;
|
|
421
|
+
|
|
427
422
|
let {
|
|
428
423
|
dispatch,
|
|
429
424
|
resolveSelect
|
|
@@ -431,7 +426,7 @@ export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
|
|
|
431
426
|
const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
|
|
432
427
|
status: 'active'
|
|
433
428
|
});
|
|
434
|
-
const globalStylesURL =
|
|
429
|
+
const globalStylesURL = activeThemes === null || activeThemes === void 0 ? void 0 : (_activeThemes$ = activeThemes[0]) === null || _activeThemes$ === void 0 ? void 0 : (_activeThemes$$_links = _activeThemes$._links) === null || _activeThemes$$_links === void 0 ? void 0 : (_activeThemes$$_links2 = _activeThemes$$_links['wp:user-global-styles']) === null || _activeThemes$$_links2 === void 0 ? void 0 : (_activeThemes$$_links3 = _activeThemes$$_links2[0]) === null || _activeThemes$$_links3 === void 0 ? void 0 : _activeThemes$$_links3.href;
|
|
435
430
|
|
|
436
431
|
if (globalStylesURL) {
|
|
437
432
|
const globalStylesObject = await apiFetch({
|
|
@@ -472,16 +467,19 @@ export const getBlockPatterns = () => async _ref16 => {
|
|
|
472
467
|
const restPatterns = await apiFetch({
|
|
473
468
|
path: '/wp/v2/block-patterns/patterns'
|
|
474
469
|
});
|
|
475
|
-
const patterns = map(
|
|
470
|
+
const patterns = restPatterns === null || restPatterns === void 0 ? void 0 : restPatterns.map(pattern => Object.fromEntries(Object.entries(pattern).map(_ref17 => {
|
|
471
|
+
let [key, value] = _ref17;
|
|
472
|
+
return [camelCase(key), value];
|
|
473
|
+
})));
|
|
476
474
|
dispatch({
|
|
477
475
|
type: 'RECEIVE_BLOCK_PATTERNS',
|
|
478
476
|
patterns
|
|
479
477
|
});
|
|
480
478
|
};
|
|
481
|
-
export const getBlockPatternCategories = () => async
|
|
479
|
+
export const getBlockPatternCategories = () => async _ref18 => {
|
|
482
480
|
let {
|
|
483
481
|
dispatch
|
|
484
|
-
} =
|
|
482
|
+
} = _ref18;
|
|
485
483
|
const categories = await apiFetch({
|
|
486
484
|
path: '/wp/v2/block-patterns/categories'
|
|
487
485
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["camelCase","compact","find","get","includes","map","mapKeys","uniq","addQueryArgs","apiFetch","STORE_NAME","getOrLoadEntitiesConfig","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","error","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","rest_namespace","restNamespace","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles","__experimentalGetCurrentThemeGlobalStylesVariations","variations","__experimentalReceiveThemeGlobalStyleVariations","getBlockPatterns","restPatterns","patterns","pattern","value","getBlockPatternCategories","categories"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,SADD,EAECC,OAFD,EAGCC,IAHD,EAICC,GAJD,EAKCC,QALD,EAMCC,GAND,EAOCC,OAPD,EAQCC,IARD,QASO,QATP;AAWA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,uBAAT,EAAkCC,kBAAlC,QAA4D,YAA5D;AACA,SAASC,eAAT,EAA0BC,2BAA1B,QAA6D,SAA7D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GACpBC,KAAF,IACA,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AACzB,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAAF,GAAF,CAA5B;AACAD,EAAAA,QAA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E,UAAY;AAD7B,GAAF,CAAjC;;AAGA3G,EAAAA,QAAQ,CAAC+G,+CAAT,CACCN,YAAY,CAACE,UADd,EAECG,UAFD;AAIA,CAXK;AAaP,OAAO,MAAME,gBAAgB,GAC5B,MACA,gBAA0B;AAAA,MAAlB;AAAEhH,IAAAA;AAAF,GAAkB;AACzB,QAAMiH,YAAY,GAAG,MAAMzH,QAAQ,CAAE;AACpCS,IAAAA,IAAI,EAAE;AAD8B,GAAF,CAAnC;AAGA,QAAMiH,QAAQ,GAAG9H,GAAG,CAAE6H,YAAF,EAAkBE,OAAF,IACnC9H,OAAO,CAAE8H,OAAF,EAAW,CAAEC,KAAF,EAAS1G,GAAT,KAAkB3B,SAAS,CAAE2B,GAAF,CAAtC,CADY,CAApB;AAGAV,EAAAA,QAAQ,CAAE;AAAE0C,IAAAA,IAAI,EAAE,wBAAR;AAAkCwE,IAAAA;AAAlC,GAAF,CAAR;AACA,CAVK;AAYP,OAAO,MAAMG,yBAAyB,GACrC,MACA,gBAA0B;AAAA,MAAlB;AAAErH,IAAAA;AAAF,GAAkB;AACzB,QAAMsH,UAAU,GAAG,MAAM9H,QAAQ,CAAE;AAClCS,IAAAA,IAAI,EAAE;AAD4B,GAAF,CAAjC;AAGAD,EAAAA,QAAQ,CAAE;AAAE0C,IAAAA,IAAI,EAAE,kCAAR;AAA4C4E,IAAAA;AAA5C,GAAF,CAAR;AACA,CAPK","sourcesContent":["/**\n * External dependencies\n */\nimport {\n\tcamelCase,\n\tcompact,\n\tfind,\n\tget,\n\tincludes,\n\tmap,\n\tmapKeys,\n\tuniq,\n} from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors =\n\t( query ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst path = addQueryArgs(\n\t\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\t\tquery\n\t\t);\n\t\tconst users = await apiFetch( { path } );\n\t\tdispatch.receiveUserQuery( path, users );\n\t};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\t\tdispatch.receiveCurrentUser( currentUser );\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getEntityRecord =\n\t( kind, name, key = '', query ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = find( configs, { kind, name } );\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, key ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: uniq( [\n\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t] ).join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Disable reason: While true that an early return could leave `path`\n\t\t\t// unused, it's important that path is derived using the query prior to\n\t\t\t// additional query modifications in the condition below, since those\n\t\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t\t// for how the request is made to the REST API.\n\n\t\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.baseURL + ( key ? '/' + key : '' ),\n\t\t\t\t{\n\t\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t\t...query,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( query !== undefined ) {\n\t\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\t\tif ( hasRecords ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst record = await apiFetch( { path } );\n\t\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport const getEntityRecords =\n\t( kind, name, query = {} ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = find( configs, { kind, name } );\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: uniq( [\n\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t] ).join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( entityConfig.baseURL, {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\n\t\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t// explicitely set these fields as \"undefined\"\n\t\t\t// that way we consider the query \"fullfilled\".\n\t\t\tif ( query._fields ) {\n\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn record;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t\t// When requesting all fields, the list of results can be used to\n\t\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst resolutionsArgs = records\n\t\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\n\t\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n\t};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview =\n\t( url ) =>\n\tasync ( { dispatch } ) => {\n\t\ttry {\n\t\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t\t} );\n\t\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t\t} catch ( error ) {\n\t\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\t\tdispatch.receiveEmbedPreview( url, false );\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser =\n\t( action, resource, id ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst methods = {\n\t\t\tcreate: 'POST',\n\t\t\tread: 'GET',\n\t\t\tupdate: 'PUT',\n\t\t\tdelete: 'DELETE',\n\t\t};\n\n\t\tconst method = methods[ action ];\n\t\tif ( ! method ) {\n\t\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t\t}\n\n\t\tconst path = id\n\t\t\t? `/wp/v2/${ resource }/${ id }`\n\t\t\t: `/wp/v2/${ resource }`;\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t\tparse: false,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional chaining operator is used here because the API requests don't\n\t\t// return the expected result in the native version. Instead, API requests\n\t\t// only return the result, without including response properties like the headers.\n\t\tconst allowHeader = response.headers?.get( 'allow' );\n\t\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\t\tconst isAllowed = includes( allowHeader, method );\n\t\tdispatch.receiveUserPermission( key, isAllowed );\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord =\n\t( kind, name, recordId ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = find( configs, { kind, name } );\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst resource = entityConfig.__unstable_rest_base;\n\t\tawait dispatch( canUser( 'update', resource, recordId ) );\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves =\n\t( postType, postId ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =\n\t\t\tawait resolveSelect.getPostType( postType );\n\t\tconst autosaves = await apiFetch( {\n\t\t\tpath: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,\n\t\t} );\n\n\t\tif ( autosaves && autosaves.length ) {\n\t\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t\t}\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave =\n\t( postType, postId ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect.getAutosaves( postType, postId );\n\t};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink =\n\t( link ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\t// Ideally this should be using an apiFetch call\n\t\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t\t// Also it seems the returned object is not a regular REST API post type.\n\t\tlet template;\n\t\ttry {\n\t\t\ttemplate = await window\n\t\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t\t.then( ( res ) => res.json() )\n\t\t\t\t.then( ( { data } ) => data );\n\t\t} catch ( e ) {\n\t\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t\t}\n\n\t\tif ( ! template ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst record = await resolveSelect.getEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template',\n\t\t\ttemplate.id\n\t\t);\n\n\t\tif ( record ) {\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t[ record ],\n\t\t\t\t{\n\t\t\t\t\t'find-template': link,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\t\tconst globalStylesURL = get( activeThemes, [\n\t\t\t0,\n\t\t\t'_links',\n\t\t\t'wp:user-global-styles',\n\t\t\t0,\n\t\t\t'href',\n\t\t] );\n\t\tif ( globalStylesURL ) {\n\t\t\tconst globalStylesObject = await apiFetch( {\n\t\t\t\turl: globalStylesURL,\n\t\t\t} );\n\t\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\t\tglobalStylesObject.id\n\t\t\t);\n\t\t}\n\t};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst themeGlobalStyles = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tthemeGlobalStyles\n\t\t);\n\t};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst variations = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tvariations\n\t\t);\n\t};\n\nexport const getBlockPatterns =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst restPatterns = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/patterns',\n\t\t} );\n\t\tconst patterns = map( restPatterns, ( pattern ) =>\n\t\t\tmapKeys( pattern, ( value, key ) => camelCase( key ) )\n\t\t);\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );\n\t};\n\nexport const getBlockPatternCategories =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst categories = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/categories',\n\t\t} );\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', categories } );\n\t};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["camelCase","addQueryArgs","apiFetch","STORE_NAME","getOrLoadEntitiesConfig","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","find","config","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","Set","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","error","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","get","Boolean","isAllowed","includes","allow","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","rest_namespace","restNamespace","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","_links","href","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles","__experimentalGetCurrentThemeGlobalStylesVariations","variations","__experimentalReceiveThemeGlobalStyleVariations","getBlockPatterns","restPatterns","patterns","pattern","fromEntries","entries","value","getBlockPatternCategories","categories"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,aAA1B;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,uBAAT,EAAkCC,kBAAlC,QAA4D,YAA5D;AACA,SAASC,eAAT,EAA0BC,2BAA1B,QAA6D,SAA7D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GACpBC,KAAF,IACA,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AACzB,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAAF,GAAF,CAA5B;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CATK;AAWP;AACA;AACA;;AACA,OAAO,MAAME,cAAc,GAC1B,MACA,eAA0B;AAAA,MAAlB;AAAEJ,IAAAA;AAAF,GAAkB;AACzB,QAAMK,WAAW,GAAG,MAAMb,QAAQ,CAAE;AAAES,IAAAA,IAA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n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getOrLoadEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors =\n\t( query ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst path = addQueryArgs(\n\t\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\t\tquery\n\t\t);\n\t\tconst users = await apiFetch( { path } );\n\t\tdispatch.receiveUserQuery( path, users );\n\t};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\t\tdispatch.receiveCurrentUser( currentUser );\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request. If requesting specific\n * fields, fields must always include the ID.\n */\nexport const getEntityRecord =\n\t( kind, name, key = '', query ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, key ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query !== undefined && query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Disable reason: While true that an early return could leave `path`\n\t\t\t// unused, it's important that path is derived using the query prior to\n\t\t\t// additional query modifications in the condition below, since those\n\t\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t\t// for how the request is made to the REST API.\n\n\t\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\t\tconst path = addQueryArgs(\n\t\t\t\tentityConfig.baseURL + ( key ? '/' + key : '' ),\n\t\t\t\t{\n\t\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t\t...query,\n\t\t\t\t}\n\t\t\t);\n\n\t\t\tif ( query !== undefined ) {\n\t\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\t\tif ( hasRecords ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst record = await apiFetch( { path } );\n\t\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object. If requesting specific fields, fields\n * must always include the ID.\n */\nexport const getEntityRecords =\n\t( kind, name, query = {} ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig || entityConfig?.__experimentalNoFetch ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name ],\n\t\t\t{ exclusive: false }\n\t\t);\n\n\t\ttry {\n\t\t\tif ( query._fields ) {\n\t\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t\t// the ID.\n\t\t\t\tquery = {\n\t\t\t\t\t...query,\n\t\t\t\t\t_fields: [\n\t\t\t\t\t\t...new Set( [\n\t\t\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) ||\n\t\t\t\t\t\t\t\t[] ),\n\t\t\t\t\t\t\tentityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t\t\t] ),\n\t\t\t\t\t].join(),\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst path = addQueryArgs( entityConfig.baseURL, {\n\t\t\t\t...entityConfig.baseURLParams,\n\t\t\t\t...query,\n\t\t\t} );\n\n\t\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t\t// If we request fields but the result doesn't contain the fields,\n\t\t\t// explicitely set these fields as \"undefined\"\n\t\t\t// that way we consider the query \"fullfilled\".\n\t\t\tif ( query._fields ) {\n\t\t\t\trecords = records.map( ( record ) => {\n\t\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn record;\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t\t// When requesting all fields, the list of results can be used to\n\t\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\t\tconst key = entityConfig.key || DEFAULT_ENTITY_KEY;\n\t\t\t\tconst resolutionsArgs = records\n\t\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t\tdispatch( {\n\t\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\t\targs: resolutionsArgs,\n\t\t\t\t} );\n\t\t\t}\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\n\t\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n\t};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview =\n\t( url ) =>\n\tasync ( { dispatch } ) => {\n\t\ttry {\n\t\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t\t} );\n\t\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t\t} catch ( error ) {\n\t\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\t\tdispatch.receiveEmbedPreview( url, false );\n\t\t}\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser =\n\t( action, resource, id ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst methods = {\n\t\t\tcreate: 'POST',\n\t\t\tread: 'GET',\n\t\t\tupdate: 'PUT',\n\t\t\tdelete: 'DELETE',\n\t\t};\n\n\t\tconst method = methods[ action ];\n\t\tif ( ! method ) {\n\t\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t\t}\n\n\t\tconst path = id\n\t\t\t? `/wp/v2/${ resource }/${ id }`\n\t\t\t: `/wp/v2/${ resource }`;\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath,\n\t\t\t\tmethod: 'OPTIONS',\n\t\t\t\tparse: false,\n\t\t\t} );\n\t\t} catch ( error ) {\n\t\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\t\treturn;\n\t\t}\n\n\t\t// Optional chaining operator is used here because the API requests don't\n\t\t// return the expected result in the native version. Instead, API requests\n\t\t// only return the result, without including response properties like the headers.\n\t\tconst allowHeader = response.headers?.get( 'allow' );\n\t\tconst key = [ action, resource, id ].filter( Boolean ).join( '/' );\n\t\tconst isAllowed =\n\t\t\tallowHeader?.includes?.( method ) || allowHeader?.allow === method;\n\t\tdispatch.receiveUserPermission( key, isAllowed );\n\t};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord =\n\t( kind, name, recordId ) =>\n\tasync ( { dispatch } ) => {\n\t\tconst configs = await dispatch( getOrLoadEntitiesConfig( kind ) );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.name === name && config.kind === kind\n\t\t);\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst resource = entityConfig.__unstable_rest_base;\n\t\tawait dispatch( canUser( 'update', resource, recordId ) );\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves =\n\t( postType, postId ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst { rest_base: restBase, rest_namespace: restNamespace = 'wp/v2' } =\n\t\t\tawait resolveSelect.getPostType( postType );\n\t\tconst autosaves = await apiFetch( {\n\t\t\tpath: `/${ restNamespace }/${ restBase }/${ postId }/autosaves?context=edit`,\n\t\t} );\n\n\t\tif ( autosaves && autosaves.length ) {\n\t\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t\t}\n\t};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave =\n\t( postType, postId ) =>\n\tasync ( { resolveSelect } ) => {\n\t\tawait resolveSelect.getAutosaves( postType, postId );\n\t};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink =\n\t( link ) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\t// Ideally this should be using an apiFetch call\n\t\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t\t// Also it seems the returned object is not a regular REST API post type.\n\t\tlet template;\n\t\ttry {\n\t\t\ttemplate = await window\n\t\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t\t.then( ( res ) => res.json() )\n\t\t\t\t.then( ( { data } ) => data );\n\t\t} catch ( e ) {\n\t\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t\t}\n\n\t\tif ( ! template ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst record = await resolveSelect.getEntityRecord(\n\t\t\t'postType',\n\t\t\t'wp_template',\n\t\t\ttemplate.id\n\t\t);\n\n\t\tif ( record ) {\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t[ record ],\n\t\t\t\t{\n\t\t\t\t\t'find-template': link,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId =\n\t() =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t\t'root',\n\t\t\t'theme',\n\t\t\t{ status: 'active' }\n\t\t);\n\t\tconst globalStylesURL =\n\t\t\tactiveThemes?.[ 0 ]?._links?.[ 'wp:user-global-styles' ]?.[ 0 ]\n\t\t\t\t?.href;\n\t\tif ( globalStylesURL ) {\n\t\t\tconst globalStylesObject = await apiFetch( {\n\t\t\t\turl: globalStylesURL,\n\t\t\t} );\n\t\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\t\tglobalStylesObject.id\n\t\t\t);\n\t\t}\n\t};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst themeGlobalStyles = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tthemeGlobalStyles\n\t\t);\n\t};\n\nexport const __experimentalGetCurrentThemeGlobalStylesVariations =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\t\tconst variations = await apiFetch( {\n\t\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,\n\t\t} );\n\t\tdispatch.__experimentalReceiveThemeGlobalStyleVariations(\n\t\t\tcurrentTheme.stylesheet,\n\t\t\tvariations\n\t\t);\n\t};\n\nexport const getBlockPatterns =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst restPatterns = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/patterns',\n\t\t} );\n\t\tconst patterns = restPatterns?.map( ( pattern ) =>\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries( pattern ).map( ( [ key, value ] ) => [\n\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\tvalue,\n\t\t\t\t] )\n\t\t\t)\n\t\t);\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERNS', patterns } );\n\t};\n\nexport const getBlockPatternCategories =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst categories = await apiFetch( {\n\t\t\tpath: '/wp/v2/block-patterns/categories',\n\t\t} );\n\t\tdispatch( { type: 'RECEIVE_BLOCK_PATTERN_CATEGORIES', categories } );\n\t};\n"]}
|