@wordpress/core-data 6.12.0 → 6.12.2
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/README.md +1 -1
- package/build/entity-provider.js +63 -7
- package/build/entity-provider.js.map +1 -1
- package/build/hooks/use-entity-record.js +4 -2
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +1 -1
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/private-apis.js +19 -0
- package/build/private-apis.js.map +1 -0
- package/build/resolvers.js +2 -1
- package/build/resolvers.js.map +1 -1
- package/build-module/entity-provider.js +59 -5
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +4 -2
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +1 -1
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/private-apis.js +9 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/resolvers.js +2 -1
- package/build-module/resolvers.js.map +1 -1
- package/build-types/entity-provider.d.ts.map +1 -1
- package/build-types/entity-types/wp-template.d.ts +4 -0
- package/build-types/entity-types/wp-template.d.ts.map +1 -1
- package/build-types/hooks/use-entity-record.d.ts.map +1 -1
- package/build-types/hooks/use-entity-records.d.ts +1 -1
- package/build-types/private-apis.d.ts +3 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/package.json +14 -12
- package/src/entity-provider.js +72 -5
- package/src/entity-types/wp-template.ts +4 -0
- package/src/hooks/use-entity-record.ts +4 -2
- package/src/hooks/use-entity-records.ts +1 -1
- package/src/private-apis.js +10 -0
- package/src/resolvers.js +5 -1
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -859,7 +859,7 @@ Resolves the specified entity records.
|
|
|
859
859
|
_Usage_
|
|
860
860
|
|
|
861
861
|
```js
|
|
862
|
-
import {
|
|
862
|
+
import { useEntityRecords } from '@wordpress/core-data';
|
|
863
863
|
|
|
864
864
|
function PageTitlesList() {
|
|
865
865
|
const { records, isResolving } = useEntityRecords( 'postType', 'page' );
|
package/build/entity-provider.js
CHANGED
|
@@ -12,10 +12,14 @@ var _element = require("@wordpress/element");
|
|
|
12
12
|
|
|
13
13
|
var _data = require("@wordpress/data");
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _blocks2 = require("@wordpress/blocks");
|
|
16
|
+
|
|
17
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
16
18
|
|
|
17
19
|
var _name = require("./name");
|
|
18
20
|
|
|
21
|
+
var _privateApis = require("./private-apis");
|
|
22
|
+
|
|
19
23
|
var _entities = require("./entities");
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -28,6 +32,7 @@ var _entities = require("./entities");
|
|
|
28
32
|
|
|
29
33
|
/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
|
|
30
34
|
const EMPTY_ARRAY = [];
|
|
35
|
+
let oldFootnotes = {};
|
|
31
36
|
/**
|
|
32
37
|
* Internal dependencies
|
|
33
38
|
*/
|
|
@@ -170,6 +175,8 @@ function useEntityProp(kind, name, prop, _id) {
|
|
|
170
175
|
function useEntityBlockEditor(kind, name, {
|
|
171
176
|
id: _id
|
|
172
177
|
} = {}) {
|
|
178
|
+
const [meta, updateMeta] = useEntityProp(kind, name, 'meta', _id);
|
|
179
|
+
const registry = (0, _data.useRegistry)();
|
|
173
180
|
const providerId = useEntityId(kind, name);
|
|
174
181
|
const id = _id !== null && _id !== void 0 ? _id : providerId;
|
|
175
182
|
const {
|
|
@@ -194,7 +201,7 @@ function useEntityBlockEditor(kind, name, {
|
|
|
194
201
|
// Guard against other instances that might have
|
|
195
202
|
// set content to a function already or the blocks are already in state.
|
|
196
203
|
if (content && typeof content !== 'function' && !blocks) {
|
|
197
|
-
const parsedContent = (0,
|
|
204
|
+
const parsedContent = (0, _blocks2.parse)(content);
|
|
198
205
|
editEntityRecord(kind, name, id, {
|
|
199
206
|
blocks: parsedContent
|
|
200
207
|
}, {
|
|
@@ -202,6 +209,49 @@ function useEntityBlockEditor(kind, name, {
|
|
|
202
209
|
});
|
|
203
210
|
}
|
|
204
211
|
}, [content]);
|
|
212
|
+
const updateFootnotes = (0, _element.useCallback)(_blocks => {
|
|
213
|
+
if (!meta) return; // If meta.footnotes is empty, it means the meta is not registered.
|
|
214
|
+
|
|
215
|
+
if (meta.footnotes === undefined) return;
|
|
216
|
+
const {
|
|
217
|
+
getRichTextValues
|
|
218
|
+
} = (0, _privateApis.unlock)(_blockEditor.privateApis);
|
|
219
|
+
|
|
220
|
+
const _content = getRichTextValues(_blocks).join('') || '';
|
|
221
|
+
|
|
222
|
+
const newOrder = []; // This can be avoided when
|
|
223
|
+
// https://github.com/WordPress/gutenberg/pull/43204 lands. We can then
|
|
224
|
+
// get the order directly from the rich text values.
|
|
225
|
+
|
|
226
|
+
if (_content.indexOf('data-fn') !== -1) {
|
|
227
|
+
const regex = /data-fn="([^"]+)"/g;
|
|
228
|
+
let match;
|
|
229
|
+
|
|
230
|
+
while ((match = regex.exec(_content)) !== null) {
|
|
231
|
+
newOrder.push(match[1]);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const footnotes = meta.footnotes ? JSON.parse(meta.footnotes) : [];
|
|
236
|
+
const currentOrder = footnotes.map(fn => fn.id);
|
|
237
|
+
if (currentOrder.join('') === newOrder.join('')) return;
|
|
238
|
+
const newFootnotes = newOrder.map(fnId => footnotes.find(fn => fn.id === fnId) || oldFootnotes[fnId] || {
|
|
239
|
+
id: fnId,
|
|
240
|
+
content: ''
|
|
241
|
+
});
|
|
242
|
+
oldFootnotes = { ...oldFootnotes,
|
|
243
|
+
...footnotes.reduce((acc, fn) => {
|
|
244
|
+
if (!newOrder.includes(fn.id)) {
|
|
245
|
+
acc[fn.id] = fn;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return acc;
|
|
249
|
+
}, {})
|
|
250
|
+
};
|
|
251
|
+
updateMeta({ ...meta,
|
|
252
|
+
footnotes: JSON.stringify(newFootnotes)
|
|
253
|
+
});
|
|
254
|
+
}, [meta, updateMeta]);
|
|
205
255
|
const onChange = (0, _element.useCallback)((newBlocks, options) => {
|
|
206
256
|
const {
|
|
207
257
|
selection
|
|
@@ -221,10 +271,13 @@ function useEntityBlockEditor(kind, name, {
|
|
|
221
271
|
|
|
222
272
|
edits.content = ({
|
|
223
273
|
blocks: blocksForSerialization = []
|
|
224
|
-
}) => (0,
|
|
274
|
+
}) => (0, _blocks2.__unstableSerializeAndClean)(blocksForSerialization);
|
|
225
275
|
|
|
226
|
-
|
|
227
|
-
|
|
276
|
+
registry.batch(() => {
|
|
277
|
+
updateFootnotes(edits.blocks);
|
|
278
|
+
editEntityRecord(kind, name, id, edits);
|
|
279
|
+
});
|
|
280
|
+
}, [kind, name, id, blocks, updateFootnotes]);
|
|
228
281
|
const onInput = (0, _element.useCallback)((newBlocks, options) => {
|
|
229
282
|
const {
|
|
230
283
|
selection
|
|
@@ -233,8 +286,11 @@ function useEntityBlockEditor(kind, name, {
|
|
|
233
286
|
blocks: newBlocks,
|
|
234
287
|
selection
|
|
235
288
|
};
|
|
236
|
-
|
|
237
|
-
|
|
289
|
+
registry.batch(() => {
|
|
290
|
+
updateFootnotes(edits.blocks);
|
|
291
|
+
editEntityRecord(kind, name, id, edits);
|
|
292
|
+
});
|
|
293
|
+
}, [kind, name, id, updateFootnotes]);
|
|
238
294
|
return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange];
|
|
239
295
|
}
|
|
240
296
|
//# sourceMappingURL=entity-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AAKA;;AASA;;AAxBA;AACA;AACA;;AAUA;AACA;AACA;;AAGA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AACnCC,MAAAA,OAAO,EAAE,4BAAeC,SAAf;AAD0B,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB;AAUtB,KAAGM,wCAA8BP,MAA9B,CAAsC,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAC3DD,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA,WAAOF,GAAP;AACA,GAHE,EAGA,EAHA;AAVmB,CAAvB;;AAeA,MAAMO,gBAAgB,GAAG,CAAEL,IAAF,EAAQC,IAAR,KAAkB;AAC1C,MAAK,CAAEN,cAAc,CAAEK,IAAF,CAArB,EAAgC;AAC/B,UAAM,IAAIM,KAAJ,CAAY,mCAAmCN,IAAM,GAArD,CAAN;AACA;;AAED,MAAK,CAAEL,cAAc,CAAEK,IAAF,CAAd,CAAwBC,IAAxB,CAAP,EAAwC;AACvCN,IAAAA,cAAc,CAAEK,IAAF,CA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6BA,sBAA7B,CADD;;AAGAf,IAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkB6B,KAAlB,CAAhB;AACA,GAjBe,EAkBhB,CAAEtC,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBqB,MAAlB,CAlBgB,CAAjB;AAqBA,QAAMW,OAAO,GAAG,0BACf,CAAEN,SAAF,EAAaC,OAAb,KAA0B;AACzB,UAAM;AAAEC,MAAAA;AAAF,QAAgBD,OAAtB;AACA,UAAME,KAAK,GAAG;AAAER,MAAAA,MAAM,EAAEK,SAAV;AAAqBE,MAAAA;AAArB,KAAd;AACAZ,IAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkB6B,KAAlB,CAAhB;AACA,GALc,EAMf,CAAEtC,IAAF,EAAQC,IAAR,EAAcQ,EAAd,CANe,CAAhB;AASA,SAAO,CAAEqB,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYpC,WAAZ,EAAyB+C,OAAzB,EAAkCP,QAAlC,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\n\t\t\tconst noChange = blocks === edits.blocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tedits.content = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t},\n\t\t[ kind, name, id, blocks ]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/entity-provider.js"],"names":["EMPTY_ARRAY","oldFootnotes","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","useEntityId","useEntityProp","prop","_id","providerId","value","fullValue","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","setValue","newValue","useEntityBlockEditor","meta","updateMeta","registry","content","blocks","__unstableCreateUndoLevel","parsedContent","undoIgnore","updateFootnotes","_blocks","footnotes","getRichTextValues","blockEditorPrivateApis","_content","join","newOrder","indexOf","regex","match","exec","push","JSON","parse","currentOrder","map","fn","newFootnotes","fnId","find","includes","stringify","onChange","newBlocks","options","selection","edits","noChange","blocksForSerialization","batch","onInput"],"mappings":";;;;;;;;;;AAGA;;AAMA;;AACA;;AACA;;AAKA;;AACA;;AAWA;;AA5BA;AACA;AACA;;AAWA;AACA;AACA;;AAIA;AAEA,MAAMA,WAAW,GAAG,EAApB;AAEA,IAAIC,YAAY,GAAG,EAAnB;AAEA;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG,EACtB,GAAGC,6BAAmBC,MAAnB,CAA2B,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAChD,QAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAV,EAA4B;AAC3BF,MAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA;;AACDF,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,CAAoBD,MAAM,CAACE,IAA3B,IAAoC;AACnCC,MAAAA,OAAO,EAAE,4BAAeC,SAAf;AAD0B,KAApC;AAGA,WAAOL,GAAP;AACA,GARE,EAQA,EARA,CADmB;AAUtB,KAAGM,wCAA8BP,MAA9B,CAAsC,CAAEC,GAAF,EAAOC,MAAP,KAAmB;AAC3DD,IAAAA,GAAG,CAAEC,MAAM,CAACC,IAAT,CAAH,GAAqB,EAArB;AACA,WAAOF,GAAP;AACA,GAHE,EAGA,EAHA;AAVmB,CAAvB;;AAeA,MAAMO,gBAAgB,GAAG,CAAEL,IAAF,EAAQC,IAAR,KAAkB;AAC1C,MAAK,CAAEN,cAAc,CAAEK,IAAF,CAArB,EAAgC;AAC/B,UAAM,IAAIM,KAAJ,CAAY,mCAAmCN,IAAM,GAArD,CAAN;AACA;;AAED,MAAK,CAAEL,cAAc,CAAEK,IAAF,CAAd,CAAwBC,IAAxB,CAAP,EA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AqBE,MAAAA;AAArB,KAAd;AACAhC,IAAAA,QAAQ,CAACoC,KAAT,CAAgB,MAAM;AACrB9B,MAAAA,eAAe,CAAE2B,KAAK,CAAC/B,MAAR,CAAf;AACAR,MAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBuD,KAAlB,CAAhB;AACA,KAHD;AAIA,GARc,EASf,CAAEhE,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkB4B,eAAlB,CATe,CAAhB;AAYA,SAAO,CAAEJ,MAAF,aAAEA,MAAF,cAAEA,MAAF,GAAYxC,WAAZ,EAAyB2E,OAAzB,EAAkCR,QAAlC,CAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseEffect,\n} from '@wordpress/element';\nimport { useSelect, useDispatch, useRegistry } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\nlet oldFootnotes = {};\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * peristent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst [ meta, updateMeta ] = useEntityProp( kind, name, 'meta', _id );\n\tconst registry = useRegistry();\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, blocks } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\tblocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tuseEffect( () => {\n\t\t// Load the blocks from the content if not already in state\n\t\t// Guard against other instances that might have\n\t\t// set content to a function already or the blocks are already in state.\n\t\tif ( content && typeof content !== 'function' && ! blocks ) {\n\t\t\tconst parsedContent = parse( content );\n\t\t\teditEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\tblocks: parsedContent,\n\t\t\t\t},\n\t\t\t\t{ undoIgnore: true }\n\t\t\t);\n\t\t}\n\t}, [ content ] );\n\n\tconst updateFootnotes = useCallback(\n\t\t( _blocks ) => {\n\t\t\tif ( ! meta ) return;\n\t\t\t// If meta.footnotes is empty, it means the meta is not registered.\n\t\t\tif ( meta.footnotes === undefined ) return;\n\n\t\t\tconst { getRichTextValues } = unlock( blockEditorPrivateApis );\n\t\t\tconst _content = getRichTextValues( _blocks ).join( '' ) || '';\n\t\t\tconst newOrder = [];\n\n\t\t\t// This can be avoided when\n\t\t\t// https://github.com/WordPress/gutenberg/pull/43204 lands. We can then\n\t\t\t// get the order directly from the rich text values.\n\t\t\tif ( _content.indexOf( 'data-fn' ) !== -1 ) {\n\t\t\t\tconst regex = /data-fn=\"([^\"]+)\"/g;\n\t\t\t\tlet match;\n\t\t\t\twhile ( ( match = regex.exec( _content ) ) !== null ) {\n\t\t\t\t\tnewOrder.push( match[ 1 ] );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst footnotes = meta.footnotes\n\t\t\t\t? JSON.parse( meta.footnotes )\n\t\t\t\t: [];\n\t\t\tconst currentOrder = footnotes.map( ( fn ) => fn.id );\n\n\t\t\tif ( currentOrder.join( '' ) === newOrder.join( '' ) ) return;\n\n\t\t\tconst newFootnotes = newOrder.map(\n\t\t\t\t( fnId ) =>\n\t\t\t\t\tfootnotes.find( ( fn ) => fn.id === fnId ) ||\n\t\t\t\t\toldFootnotes[ fnId ] || {\n\t\t\t\t\t\tid: fnId,\n\t\t\t\t\t\tcontent: '',\n\t\t\t\t\t}\n\t\t\t);\n\n\t\t\toldFootnotes = {\n\t\t\t\t...oldFootnotes,\n\t\t\t\t...footnotes.reduce( ( acc, fn ) => {\n\t\t\t\t\tif ( ! newOrder.includes( fn.id ) ) {\n\t\t\t\t\t\tacc[ fn.id ] = fn;\n\t\t\t\t\t}\n\t\t\t\t\treturn acc;\n\t\t\t\t}, {} ),\n\t\t\t};\n\n\t\t\tupdateMeta( {\n\t\t\t\t...meta,\n\t\t\t\tfootnotes: JSON.stringify( newFootnotes ),\n\t\t\t} );\n\t\t},\n\t\t[ meta, updateMeta ]\n\t);\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\n\t\t\tconst noChange = blocks === edits.blocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tedits.content = ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t__unstableSerializeAndClean( blocksForSerialization );\n\n\t\t\tregistry.batch( () => {\n\t\t\t\tupdateFootnotes( edits.blocks );\n\t\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, blocks, updateFootnotes ]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst edits = { blocks: newBlocks, selection };\n\t\t\tregistry.batch( () => {\n\t\t\t\tupdateFootnotes( edits.blocks );\n\t\t\t\teditEntityRecord( kind, name, id, edits );\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, updateFootnotes ]\n\t);\n\n\treturn [ blocks ?? EMPTY_ARRAY, onInput, onChange ];\n}\n"]}
|
|
@@ -127,7 +127,7 @@ function useEntityRecord(kind, name, recordId, options = {
|
|
|
127
127
|
throwOnError: true,
|
|
128
128
|
...saveOptions
|
|
129
129
|
})
|
|
130
|
-
}), [recordId]);
|
|
130
|
+
}), [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]);
|
|
131
131
|
const {
|
|
132
132
|
editedRecord,
|
|
133
133
|
hasEdits
|
|
@@ -140,7 +140,9 @@ function useEntityRecord(kind, name, recordId, options = {
|
|
|
140
140
|
...querySelectRest
|
|
141
141
|
} = (0, _useQuerySelect.default)(query => {
|
|
142
142
|
if (!options.enabled) {
|
|
143
|
-
return
|
|
143
|
+
return {
|
|
144
|
+
data: null
|
|
145
|
+
};
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
return query(_.store).getEntityRecord(kind, name, recordId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","coreStore","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AA8CA;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;AACA;AACe,SAASA,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAIdC,OAAgB,GAAG;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAJL,EAKyB;AACvC,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MACL,uBAAaC,OAAb,CADD;AAGA,QAAMC,SAAS,GAAG,sBACjB,OAAQ;AACPC,IAAAA,IAAI,EAAIC,MAAF,IACLL,gBAAgB,CAAEL,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBQ,MAAxB,CAFV;AAGPC,IAAAA,IAAI,EAAE,CAAEC,WAAgB,GAAG,EAArB,KACLN,sBAAsB,CAAEN,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwB;AAC7CW,MAAAA,YAAY,EAAE,IAD+B;AAE7C,SAAGD;AAF0C,KAAxB;AAJhB,GAAR,CADiB,EAUjB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","coreStore","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AA8CA;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;AACA;AACe,SAASA,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAIdC,OAAgB,GAAG;AAAEC,EAAAA,OAAO,EAAE;AAA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,EAS5C,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAT4C,CAA7C;AAYA,SAAO;AACNM,IAAAA,MADM;AAENI,IAAAA,YAFM;AAGNC,IAAAA,QAHM;AAIN,OAAGK,eAJG;AAKN,OAAGZ;AALG,GAAP;AAOA;;AAEM,SAASe,6BAAT,CACNvB,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACD,2BAAa,uCAAb,EAAqD;AACpDqB,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAArD;AAIA,SAAO1B,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 * @since 6.1.0 Introduced in WordPress core.\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[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\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 {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\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"]}
|
|
@@ -35,7 +35,7 @@ const EMPTY_ARRAY = [];
|
|
|
35
35
|
* @param options Optional hook options.
|
|
36
36
|
* @example
|
|
37
37
|
* ```js
|
|
38
|
-
* import {
|
|
38
|
+
* import { useEntityRecords } from '@wordpress/core-data';
|
|
39
39
|
*
|
|
40
40
|
* function PageTitlesList() {
|
|
41
41
|
* const { records, isResolving } = useEntityRecords( 'postType', 'page' );
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAwBA,MAAMA,WAAW,GAAG,EAApB;AAEA;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;;AACe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,SAAoC,GAAG,EAHzB,EAIdC,OAAgB,GAAG;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAJL,EAK0B;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GATiC,EAUlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVkC,CAAnC;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;;AAEM,SAASI,8BAAT,CACNZ,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACD,2BAAa,wCAAb,EAAsD;AACrDU,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAAtD;AAIA,SAAOf,gBAAgB,CAAEC,IAAF,EAAQC,IAAR,EAAcC,SAAd,EAAyBC,OAAzB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options } from './use-entity-record';\nimport type { Status } from './constants';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: 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\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\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 queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import {
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"names":["EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","coreStore","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAVA;AACA;AACA;;AAIA;AACA;AACA;AAwBA,MAAMA,WAAW,GAAG,EAApB;AAEA;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;;AACe,SAASC,gBAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,SAAoC,GAAG,EAHzB,EAIdC,OAAgB,GAAG;AAAEC,EAAAA,OAAO,EAAE;AAAX,CAJL,EAK0B;AACxC;AACA;AACA;AACA;AACA,QAAMC,aAAa,GAAG,uBAAc,EAAd,EAAkBH,SAAlB,CAAtB;AAEA,QAAM;AAAEI,IAAAA,IAAI,EAAEC,OAAR;AAAiB,OAAGC;AAApB,MAA6B,6BAChCC,KAAF,IAAa;AACZ,QAAK,CAAEN,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO;AACN;AACAE,QAAAA,IAAI,EAAER;AAFA,OAAP;AAIA;;AACD,WAAOW,KAAK,CAAEC,OAAF,CAAL,CAAmBC,gBAAnB,CAAqCX,IAArC,EAA2CC,IAA3C,EAAiDC,SAAjD,CAAP;AACA,GATiC,EAUlC,CAAEF,IAAF,EAAQC,IAAR,EAAcI,aAAd,EAA6BF,OAAO,CAACC,OAArC,CAVkC,CAAnC;AAaA,SAAO;AACNG,IAAAA,OADM;AAEN,OAAGC;AAFG,GAAP;AAIA;;AAEM,SAASI,8BAAT,CACNZ,IADM,EAENC,IAFM,EAGNC,SAHM,EAINC,OAJM,EAKL;AACD,2BAAa,wCAAb,EAAsD;AACrDU,IAAAA,WAAW,EAAE,0BADwC;AAErDC,IAAAA,KAAK,EAAE;AAF8C,GAAtD;AAIA,SAAOf,gBAAgB,CAAEC,IAAF,EAAQC,IAAR,EAAcC,SAAd,EAAyBC,OAAzB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options } from './use-entity-record';\nimport type { Status } from './constants';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: 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\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\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 queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecords } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unlock = exports.lock = void 0;
|
|
7
|
+
|
|
8
|
+
var _privateApis = require("@wordpress/private-apis");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* WordPress dependencies
|
|
12
|
+
*/
|
|
13
|
+
const {
|
|
14
|
+
lock,
|
|
15
|
+
unlock
|
|
16
|
+
} = (0, _privateApis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.', '@wordpress/core-data');
|
|
17
|
+
exports.unlock = unlock;
|
|
18
|
+
exports.lock = lock;
|
|
19
|
+
//# sourceMappingURL=private-apis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/private-apis.js"],"names":["lock","unlock"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,MAAM;AAAEA,EAAAA,IAAF;AAAQC,EAAAA;AAAR,IACZ,mEACC,8GADD,EAEC,sBAFD,CADM","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I know using unstable features means my plugin or theme will inevitably break on the next WordPress release.',\n\t\t'@wordpress/core-data'\n\t);\n"]}
|
package/build/resolvers.js
CHANGED
|
@@ -580,7 +580,8 @@ const getNavigationFallbackId = () => async ({
|
|
|
580
580
|
dispatch.receiveNavigationFallbackId(fallback?.id);
|
|
581
581
|
|
|
582
582
|
if (record) {
|
|
583
|
-
|
|
583
|
+
const invalidateNavigationQueries = true;
|
|
584
|
+
dispatch.receiveEntityRecords('postType', 'wp_navigation', record, undefined, invalidateNavigationQueries); // Resolve to avoid further network requests.
|
|
584
585
|
|
|
585
586
|
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback?.id]);
|
|
586
587
|
}
|
package/build/resolvers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","find","config","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","Set","DEFAULT_ENTITY_KEY","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","requestedAction","resource","id","registry","hasStartedResolution","resourcePath","retrievedActions","includes","Error","relatedAction","isAlreadyResolving","response","method","parse","allowHeader","headers","get","allowedMethods","allow","permissions","methods","create","read","update","delete","actionName","methodName","entries","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","rest_namespace","restNamespace","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","then","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","_links","href","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles","__experimentalGetCurrentThemeGlobalStylesVariations","variations","__experimentalReceiveThemeGlobalStyleVariations","getCurrentThemeGlobalStylesRevisions","globalStylesId","revisionsURL","resetRevisions","revisions","revision","fromEntries","value","receiveThemeGlobalStyleRevisions","getBlockPatterns","restPatterns","patterns","pattern","getBlockPatternCategories","categories","getNavigationFallbackId","fallback","_embed","_embedded","self","receiveNavigationFallbackId","finishResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GACpBC,KAAF,IACA,OAAQ;AAAEC,EAAA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C,GAAF,CAAR;AACA,CAPK;;;;AASA,MAAMC,uBAAuB,GACnC,MACA,OAAQ;AAAEjJ,EAAAA;AAAF,CAAR,KAA0B;AACzB,QAAMkJ,QAAQ,GAAG,MAAM,uBAAU;AAChCjJ,IAAAA,IAAI,EAAE,uBAAc,yCAAd,EAAyD;AAC9DkJ,MAAAA,MAAM,EAAE;AADsD,KAAzD;AAD0B,GAAV,CAAvB;AAMA,QAAMpH,MAAM,GAAGmH,QAAQ,EAAEE,SAAV,EAAqBC,IAApC;AAEArJ,EAAAA,QAAQ,CAACsJ,2BAAT,CAAsCJ,QAAQ,EAAE9E,EAAhD;;AAEA,MAAKrC,MAAL,EAAc;AACb/B,IAAAA,QAAQ,CAACgC,oBAAT,CACC,UADD,EAEC,eAFD,EAGCD,MAHD,EADa,CAOb;;AACA/B,IAAAA,QAAQ,CAACuJ,gBAAT,CAA2B,iBAA3B,EAA8C,CAC7C,UAD6C,EAE7C,eAF6C,EAG7CL,QAAQ,EAAE9E,EAHmC,CAA9C;AAKA;AACD,CA3BK","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\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. 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// explicitly 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} requestedAction 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( requestedAction, resource, id ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst { hasStartedResolution } = registry.select( STORE_NAME );\n\n\t\tconst resourcePath = id ? `${ resource }/${ id }` : resource;\n\t\tconst retrievedActions = [ 'create', 'read', 'update', 'delete' ];\n\n\t\tif ( ! retrievedActions.includes( requestedAction ) ) {\n\t\t\tthrow new Error( `'${ requestedAction }' is not a valid action.` );\n\t\t}\n\n\t\t// Prevent resolving the same resource twice.\n\t\tfor ( const relatedAction of retrievedActions ) {\n\t\t\tif ( relatedAction === requestedAction ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isAlreadyResolving = hasStartedResolution( 'canUser', [\n\t\t\t\trelatedAction,\n\t\t\t\tresource,\n\t\t\t\tid,\n\t\t\t] );\n\t\t\tif ( isAlreadyResolving ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath: `/wp/v2/${ resourcePath }`,\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 allowedMethods = allowHeader?.allow || allowHeader || '';\n\n\t\tconst permissions = {};\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\t\tfor ( const [ actionName, methodName ] of Object.entries( methods ) ) {\n\t\t\tpermissions[ actionName ] = allowedMethods.includes( methodName );\n\t\t}\n\n\t\tfor ( const action of retrievedActions ) {\n\t\t\tdispatch.receiveUserPermission(\n\t\t\t\t`${ action }/${ resourcePath }`,\n\t\t\t\tpermissions[ action ]\n\t\t\t);\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} 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\tlet template;\n\t\ttry {\n\t\t\t// This is NOT calling a REST endpoint but rather ends up with a response from\n\t\t\t// an Ajax function which has a different shape from a WP_REST_Response.\n\t\t\ttemplate = await apiFetch( {\n\t\t\t\turl: addQueryArgs( link, {\n\t\t\t\t\t'_wp-find-template': true,\n\t\t\t\t} ),\n\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\n/**\n * Fetches and returns the revisions of the current global styles theme.\n */\nexport const getCurrentThemeGlobalStylesRevisions =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst globalStylesId =\n\t\t\tawait resolveSelect.__experimentalGetCurrentGlobalStylesId();\n\t\tconst record = globalStylesId\n\t\t\t? await resolveSelect.getEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'globalStyles',\n\t\t\t\t\tglobalStylesId\n\t\t\t )\n\t\t\t: undefined;\n\t\tconst revisionsURL = record?._links?.[ 'version-history' ]?.[ 0 ]?.href;\n\n\t\tif ( revisionsURL ) {\n\t\t\tconst resetRevisions = await apiFetch( {\n\t\t\t\turl: revisionsURL,\n\t\t\t} );\n\t\t\tconst revisions = resetRevisions?.map( ( revision ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( revision ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\t\t\tdispatch.receiveThemeGlobalStyleRevisions(\n\t\t\t\tglobalStylesId,\n\t\t\t\trevisions\n\t\t\t);\n\t\t}\n\t};\n\ngetCurrentThemeGlobalStylesRevisions.shouldInvalidate = ( action ) => {\n\treturn (\n\t\taction.type === 'SAVE_ENTITY_RECORD_FINISH' &&\n\t\taction.kind === 'root' &&\n\t\t! action.error &&\n\t\taction.name === 'globalStyles'\n\t);\n};\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\nexport const getNavigationFallbackId =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst fallback = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {\n\t\t\t\t_embed: true,\n\t\t\t} ),\n\t\t} );\n\n\t\tconst record = fallback?._embedded?.self;\n\n\t\tdispatch.receiveNavigationFallbackId( fallback?.id );\n\n\t\tif ( record ) {\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\trecord\n\t\t\t);\n\n\t\t\t// Resolve to avoid further network requests.\n\t\t\tdispatch.finishResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tfallback?.id,\n\t\t\t] );\n\t\t}\n\t};\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","configs","entityConfig","find","config","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","Set","DEFAULT_ENTITY_KEY","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","requestedAction","resource","id","registry","hasStartedResolution","resourcePath","retrievedActions","includes","Error","relatedAction","isAlreadyResolving","response","method","parse","allowHeader","headers","get","allowedMethods","allow","permissions","methods","create","read","update","delete","actionName","methodName","entries","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","rest_namespace","restNamespace","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","then","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","_links","href","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles","__experimentalGetCurrentThemeGlobalStylesVariations","variations","__experimentalReceiveThemeGlobalStyleVariations","getCurrentThemeGlobalStylesRevisions","globalStylesId","revisionsURL","resetRevisions","revisions","revision","fromEntries","value","receiveThemeGlobalStyleRevisions","getBlockPatterns","restPatterns","patterns","pattern","getBlockPatternCategories","categories","getNavigationFallbackId","fallback","_embed","_embedded","self","receiveNavigationFallbackId","invalidateNavigationQueries","finishResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GACpBC,KAAF,IACA,OAAQ;AAAEC,EAAAA;AAAF,CAAR,KAA0B;AACzB,QAAMC,IAAI,GAAG,uBACZ,wCADY,EAEZF,KAFY,CAAb;AAIA,QAAMG,KAAK,GAAG,MAAM,uBAAU;AAAED,IAAAA;AAAF,GAAV,CAApB;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CATK;AAWP;AACA;AACA;;;;;AACO,MAAME,cAAc,GAC1B,MACA,OAAQ;AAAEJ,EAAAA;AAAF,CAAR,KAA0B;AACzB,QAAMK,WAAW,GAAG,MAAM,uBAAU;AAAEJ,IAAAA,IAAI,EAAE;AAAR,GAAV,CAA1B;AACAD,EAAAA,QAAQ,CAACM,kBAAT,CAA6BD,WAA7B;AACA,CALK;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAME,eAAe,GAC3B,CAAEC,IAAF,EAAQC,IAAR,EAAcC,GAAG,GAAG,EAApB,EAAwBX,KAAxB,KACA,OAAQ;AAAEY,EAAAA,MAAF;AAAUX,EAAAA;AAAV,CAAR,KAAkC;AACjC,QAAMY,OAAO,GAAG,MAAMZ,QAAQ,CAAE,uCAAyBQ,IAAzB,CAAF,CAA9B;AACA,QAAMK,YAAY,GAAGD,OAAO,CAACE,IAAR,CAClBC,MAAF,IAAcA,MAAM,CAACN,IAAP,KAAgBA,IAAhB,IAAwBM,MAAM,CAACP,IAAP,KAAgBA,IADlC,CAArB;;AAGA,MAAK,CAAEK,YAAF,IAAkBA,YAAY,EAAEG,qBAArC,EAA6D;AAC5D;AACA;;AAED,Q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AfK;;;;AAiBA,MAAME,yBAAyB,GACrC,MACA,OAAQ;AAAE/I,EAAAA;AAAF,CAAR,KAA0B;AACzB,QAAMgJ,UAAU,GAAG,MAAM,uBAAU;AAClC/I,IAAAA,IAAI,EAAE;AAD4B,GAAV,CAAzB;AAGAD,EAAAA,QAAQ,CAAE;AAAEgD,IAAAA,IAAI,EAAE,kCAAR;AAA4CgG,IAAAA;AAA5C,GAAF,CAAR;AACA,CAPK;;;;AASA,MAAMC,uBAAuB,GACnC,MACA,OAAQ;AAAEjJ,EAAAA;AAAF,CAAR,KAA0B;AACzB,QAAMkJ,QAAQ,GAAG,MAAM,uBAAU;AAChCjJ,IAAAA,IAAI,EAAE,uBAAc,yCAAd,EAAyD;AAC9DkJ,MAAAA,MAAM,EAAE;AADsD,KAAzD;AAD0B,GAAV,CAAvB;AAMA,QAAMpH,MAAM,GAAGmH,QAAQ,EAAEE,SAAV,EAAqBC,IAApC;AAEArJ,EAAAA,QAAQ,CAACsJ,2BAAT,CAAsCJ,QAAQ,EAAE9E,EAAhD;;AAEA,MAAKrC,MAAL,EAAc;AACb,UAAMwH,2BAA2B,GAAG,IAApC;AAEAvJ,IAAAA,QAAQ,CAACgC,oBAAT,CACC,UADD,EAEC,eAFD,EAGCD,MAHD,EAICV,SAJD,EAKCkI,2BALD,EAHa,CAWb;;AACAvJ,IAAAA,QAAQ,CAACwJ,gBAAT,CAA2B,iBAA3B,EAA8C,CAC7C,UAD6C,EAE7C,eAF6C,EAG7CN,QAAQ,EAAE9E,EAHmC,CAA9C;AAKA;AACD,CA/BK","sourcesContent":["/**\n * External dependencies\n */\nimport { camelCase } from 'change-case';\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. 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// explicitly 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} requestedAction 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( requestedAction, resource, id ) =>\n\tasync ( { dispatch, registry } ) => {\n\t\tconst { hasStartedResolution } = registry.select( STORE_NAME );\n\n\t\tconst resourcePath = id ? `${ resource }/${ id }` : resource;\n\t\tconst retrievedActions = [ 'create', 'read', 'update', 'delete' ];\n\n\t\tif ( ! retrievedActions.includes( requestedAction ) ) {\n\t\t\tthrow new Error( `'${ requestedAction }' is not a valid action.` );\n\t\t}\n\n\t\t// Prevent resolving the same resource twice.\n\t\tfor ( const relatedAction of retrievedActions ) {\n\t\t\tif ( relatedAction === requestedAction ) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst isAlreadyResolving = hasStartedResolution( 'canUser', [\n\t\t\t\trelatedAction,\n\t\t\t\tresource,\n\t\t\t\tid,\n\t\t\t] );\n\t\t\tif ( isAlreadyResolving ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tlet response;\n\t\ttry {\n\t\t\tresponse = await apiFetch( {\n\t\t\t\tpath: `/wp/v2/${ resourcePath }`,\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 allowedMethods = allowHeader?.allow || allowHeader || '';\n\n\t\tconst permissions = {};\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\t\tfor ( const [ actionName, methodName ] of Object.entries( methods ) ) {\n\t\t\tpermissions[ actionName ] = allowedMethods.includes( methodName );\n\t\t}\n\n\t\tfor ( const action of retrievedActions ) {\n\t\t\tdispatch.receiveUserPermission(\n\t\t\t\t`${ action }/${ resourcePath }`,\n\t\t\t\tpermissions[ action ]\n\t\t\t);\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} 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\tlet template;\n\t\ttry {\n\t\t\t// This is NOT calling a REST endpoint but rather ends up with a response from\n\t\t\t// an Ajax function which has a different shape from a WP_REST_Response.\n\t\t\ttemplate = await apiFetch( {\n\t\t\t\turl: addQueryArgs( link, {\n\t\t\t\t\t'_wp-find-template': true,\n\t\t\t\t} ),\n\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\n/**\n * Fetches and returns the revisions of the current global styles theme.\n */\nexport const getCurrentThemeGlobalStylesRevisions =\n\t() =>\n\tasync ( { resolveSelect, dispatch } ) => {\n\t\tconst globalStylesId =\n\t\t\tawait resolveSelect.__experimentalGetCurrentGlobalStylesId();\n\t\tconst record = globalStylesId\n\t\t\t? await resolveSelect.getEntityRecord(\n\t\t\t\t\t'root',\n\t\t\t\t\t'globalStyles',\n\t\t\t\t\tglobalStylesId\n\t\t\t )\n\t\t\t: undefined;\n\t\tconst revisionsURL = record?._links?.[ 'version-history' ]?.[ 0 ]?.href;\n\n\t\tif ( revisionsURL ) {\n\t\t\tconst resetRevisions = await apiFetch( {\n\t\t\t\turl: revisionsURL,\n\t\t\t} );\n\t\t\tconst revisions = resetRevisions?.map( ( revision ) =>\n\t\t\t\tObject.fromEntries(\n\t\t\t\t\tObject.entries( revision ).map( ( [ key, value ] ) => [\n\t\t\t\t\t\tcamelCase( key ),\n\t\t\t\t\t\tvalue,\n\t\t\t\t\t] )\n\t\t\t\t)\n\t\t\t);\n\t\t\tdispatch.receiveThemeGlobalStyleRevisions(\n\t\t\t\tglobalStylesId,\n\t\t\t\trevisions\n\t\t\t);\n\t\t}\n\t};\n\ngetCurrentThemeGlobalStylesRevisions.shouldInvalidate = ( action ) => {\n\treturn (\n\t\taction.type === 'SAVE_ENTITY_RECORD_FINISH' &&\n\t\taction.kind === 'root' &&\n\t\t! action.error &&\n\t\taction.name === 'globalStyles'\n\t);\n};\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\nexport const getNavigationFallbackId =\n\t() =>\n\tasync ( { dispatch } ) => {\n\t\tconst fallback = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/wp-block-editor/v1/navigation-fallback', {\n\t\t\t\t_embed: true,\n\t\t\t} ),\n\t\t} );\n\n\t\tconst record = fallback?._embedded?.self;\n\n\t\tdispatch.receiveNavigationFallbackId( fallback?.id );\n\n\t\tif ( record ) {\n\t\t\tconst invalidateNavigationQueries = true;\n\n\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\trecord,\n\t\t\t\tundefined,\n\t\t\t\tinvalidateNavigationQueries\n\t\t\t);\n\n\t\t\t// Resolve to avoid further network requests.\n\t\t\tdispatch.finishResolution( 'getEntityRecord', [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tfallback?.id,\n\t\t\t] );\n\t\t}\n\t};\n"]}
|
|
@@ -4,16 +4,19 @@ import { createElement } from "@wordpress/element";
|
|
|
4
4
|
* WordPress dependencies
|
|
5
5
|
*/
|
|
6
6
|
import { createContext, useContext, useCallback, useEffect } from '@wordpress/element';
|
|
7
|
-
import { useSelect, useDispatch } from '@wordpress/data';
|
|
7
|
+
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
|
|
8
8
|
import { parse, __unstableSerializeAndClean } from '@wordpress/blocks';
|
|
9
|
+
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { STORE_NAME } from './name';
|
|
15
|
+
import { unlock } from './private-apis';
|
|
14
16
|
/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */
|
|
15
17
|
|
|
16
18
|
const EMPTY_ARRAY = [];
|
|
19
|
+
let oldFootnotes = {};
|
|
17
20
|
/**
|
|
18
21
|
* Internal dependencies
|
|
19
22
|
*/
|
|
@@ -154,6 +157,8 @@ export function useEntityProp(kind, name, prop, _id) {
|
|
|
154
157
|
export function useEntityBlockEditor(kind, name, {
|
|
155
158
|
id: _id
|
|
156
159
|
} = {}) {
|
|
160
|
+
const [meta, updateMeta] = useEntityProp(kind, name, 'meta', _id);
|
|
161
|
+
const registry = useRegistry();
|
|
157
162
|
const providerId = useEntityId(kind, name);
|
|
158
163
|
const id = _id !== null && _id !== void 0 ? _id : providerId;
|
|
159
164
|
const {
|
|
@@ -186,6 +191,49 @@ export function useEntityBlockEditor(kind, name, {
|
|
|
186
191
|
});
|
|
187
192
|
}
|
|
188
193
|
}, [content]);
|
|
194
|
+
const updateFootnotes = useCallback(_blocks => {
|
|
195
|
+
if (!meta) return; // If meta.footnotes is empty, it means the meta is not registered.
|
|
196
|
+
|
|
197
|
+
if (meta.footnotes === undefined) return;
|
|
198
|
+
const {
|
|
199
|
+
getRichTextValues
|
|
200
|
+
} = unlock(blockEditorPrivateApis);
|
|
201
|
+
|
|
202
|
+
const _content = getRichTextValues(_blocks).join('') || '';
|
|
203
|
+
|
|
204
|
+
const newOrder = []; // This can be avoided when
|
|
205
|
+
// https://github.com/WordPress/gutenberg/pull/43204 lands. We can then
|
|
206
|
+
// get the order directly from the rich text values.
|
|
207
|
+
|
|
208
|
+
if (_content.indexOf('data-fn') !== -1) {
|
|
209
|
+
const regex = /data-fn="([^"]+)"/g;
|
|
210
|
+
let match;
|
|
211
|
+
|
|
212
|
+
while ((match = regex.exec(_content)) !== null) {
|
|
213
|
+
newOrder.push(match[1]);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const footnotes = meta.footnotes ? JSON.parse(meta.footnotes) : [];
|
|
218
|
+
const currentOrder = footnotes.map(fn => fn.id);
|
|
219
|
+
if (currentOrder.join('') === newOrder.join('')) return;
|
|
220
|
+
const newFootnotes = newOrder.map(fnId => footnotes.find(fn => fn.id === fnId) || oldFootnotes[fnId] || {
|
|
221
|
+
id: fnId,
|
|
222
|
+
content: ''
|
|
223
|
+
});
|
|
224
|
+
oldFootnotes = { ...oldFootnotes,
|
|
225
|
+
...footnotes.reduce((acc, fn) => {
|
|
226
|
+
if (!newOrder.includes(fn.id)) {
|
|
227
|
+
acc[fn.id] = fn;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return acc;
|
|
231
|
+
}, {})
|
|
232
|
+
};
|
|
233
|
+
updateMeta({ ...meta,
|
|
234
|
+
footnotes: JSON.stringify(newFootnotes)
|
|
235
|
+
});
|
|
236
|
+
}, [meta, updateMeta]);
|
|
189
237
|
const onChange = useCallback((newBlocks, options) => {
|
|
190
238
|
const {
|
|
191
239
|
selection
|
|
@@ -207,8 +255,11 @@ export function useEntityBlockEditor(kind, name, {
|
|
|
207
255
|
blocks: blocksForSerialization = []
|
|
208
256
|
}) => __unstableSerializeAndClean(blocksForSerialization);
|
|
209
257
|
|
|
210
|
-
|
|
211
|
-
|
|
258
|
+
registry.batch(() => {
|
|
259
|
+
updateFootnotes(edits.blocks);
|
|
260
|
+
editEntityRecord(kind, name, id, edits);
|
|
261
|
+
});
|
|
262
|
+
}, [kind, name, id, blocks, updateFootnotes]);
|
|
212
263
|
const onInput = useCallback((newBlocks, options) => {
|
|
213
264
|
const {
|
|
214
265
|
selection
|
|
@@ -217,8 +268,11 @@ export function useEntityBlockEditor(kind, name, {
|
|
|
217
268
|
blocks: newBlocks,
|
|
218
269
|
selection
|
|
219
270
|
};
|
|
220
|
-
|
|
221
|
-
|
|
271
|
+
registry.batch(() => {
|
|
272
|
+
updateFootnotes(edits.blocks);
|
|
273
|
+
editEntityRecord(kind, name, id, edits);
|
|
274
|
+
});
|
|
275
|
+
}, [kind, name, id, updateFootnotes]);
|
|
222
276
|
return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange];
|
|
223
277
|
}
|
|
224
278
|
//# sourceMappingURL=entity-provider.js.map
|