@wordpress/core-data 6.11.0 → 6.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +5 -1
- package/build/actions.js +252 -276
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +8 -16
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +1 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +16 -25
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +74 -23
- package/build/entity-provider.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +2 -6
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +1 -2
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/hooks/use-entity-record.js +11 -13
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +4 -6
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +1 -6
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/index.js +1 -7
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +3 -4
- package/build/locks/actions.js.map +1 -1
- package/build/locks/reducer.js +1 -4
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +3 -4
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +3 -5
- package/build/locks/utils.js.map +1 -1
- package/build/private-apis.js +19 -0
- package/build/private-apis.js.map +1 -0
- package/build/private-selectors.js +37 -0
- package/build/private-selectors.js.map +1 -0
- package/build/queried-data/actions.js +2 -5
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/reducer.js +17 -47
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -11
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +167 -194
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +175 -220
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +53 -61
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js +4 -11
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js +1 -3
- package/build/utils/on-sub-key.js.map +1 -1
- package/build-module/actions.js +251 -276
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +8 -16
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +1 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +16 -25
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +71 -22
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -6
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +1 -2
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +11 -13
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +4 -6
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +1 -6
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/index.js +1 -7
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +3 -4
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/reducer.js +1 -4
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +3 -4
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +3 -5
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/private-apis.js +9 -0
- package/build-module/private-apis.js.map +1 -0
- package/build-module/private-selectors.js +28 -0
- package/build-module/private-selectors.js.map +1 -0
- package/build-module/queried-data/actions.js +2 -5
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/reducer.js +17 -47
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +4 -11
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +168 -194
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +175 -220
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +55 -61
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js +4 -11
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js +1 -3
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/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/private-selectors.d.ts +25 -0
- package/build-types/private-selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +6 -2
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/selectors.d.ts +16 -4
- package/build-types/selectors.d.ts.map +1 -1
- package/package.json +14 -12
- package/src/actions.js +9 -8
- 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/index.js +0 -1
- package/src/private-apis.js +10 -0
- package/src/private-selectors.ts +30 -0
- package/src/reducer.js +130 -104
- package/src/selectors.ts +33 -13
- package/src/test/reducer.js +89 -54
- package/src/test/selectors.js +8 -8
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
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
|
*/
|
|
@@ -76,13 +81,12 @@ const getEntityContext = (kind, name) => {
|
|
|
76
81
|
*/
|
|
77
82
|
|
|
78
83
|
|
|
79
|
-
function EntityProvider(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} = _ref;
|
|
84
|
+
function EntityProvider({
|
|
85
|
+
kind,
|
|
86
|
+
type: name,
|
|
87
|
+
id,
|
|
88
|
+
children
|
|
89
|
+
}) {
|
|
86
90
|
const Provider = getEntityContext(kind, name).Provider;
|
|
87
91
|
return (0, _element.createElement)(Provider, {
|
|
88
92
|
value: id
|
|
@@ -168,10 +172,11 @@ function useEntityProp(kind, name, prop, _id) {
|
|
|
168
172
|
*/
|
|
169
173
|
|
|
170
174
|
|
|
171
|
-
function useEntityBlockEditor(kind, name
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
+
function useEntityBlockEditor(kind, name, {
|
|
176
|
+
id: _id
|
|
177
|
+
} = {}) {
|
|
178
|
+
const [meta, updateMeta] = useEntityProp(kind, name, 'meta', _id);
|
|
179
|
+
const registry = (0, _data.useRegistry)();
|
|
175
180
|
const providerId = useEntityId(kind, name);
|
|
176
181
|
const id = _id !== null && _id !== void 0 ? _id : providerId;
|
|
177
182
|
const {
|
|
@@ -196,7 +201,7 @@ function useEntityBlockEditor(kind, name) {
|
|
|
196
201
|
// Guard against other instances that might have
|
|
197
202
|
// set content to a function already or the blocks are already in state.
|
|
198
203
|
if (content && typeof content !== 'function' && !blocks) {
|
|
199
|
-
const parsedContent = (0,
|
|
204
|
+
const parsedContent = (0, _blocks2.parse)(content);
|
|
200
205
|
editEntityRecord(kind, name, id, {
|
|
201
206
|
blocks: parsedContent
|
|
202
207
|
}, {
|
|
@@ -204,6 +209,49 @@ function useEntityBlockEditor(kind, name) {
|
|
|
204
209
|
});
|
|
205
210
|
}
|
|
206
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]);
|
|
207
255
|
const onChange = (0, _element.useCallback)((newBlocks, options) => {
|
|
208
256
|
const {
|
|
209
257
|
selection
|
|
@@ -221,15 +269,15 @@ function useEntityBlockEditor(kind, name) {
|
|
|
221
269
|
// a new undo level.
|
|
222
270
|
|
|
223
271
|
|
|
224
|
-
edits.content =
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
} = _ref2;
|
|
228
|
-
return (0, _blocks.__unstableSerializeAndClean)(blocksForSerialization);
|
|
229
|
-
};
|
|
272
|
+
edits.content = ({
|
|
273
|
+
blocks: blocksForSerialization = []
|
|
274
|
+
}) => (0, _blocks2.__unstableSerializeAndClean)(blocksForSerialization);
|
|
230
275
|
|
|
231
|
-
|
|
232
|
-
|
|
276
|
+
registry.batch(() => {
|
|
277
|
+
updateFootnotes(edits.blocks);
|
|
278
|
+
editEntityRecord(kind, name, id, edits);
|
|
279
|
+
});
|
|
280
|
+
}, [kind, name, id, blocks, updateFootnotes]);
|
|
233
281
|
const onInput = (0, _element.useCallback)((newBlocks, options) => {
|
|
234
282
|
const {
|
|
235
283
|
selection
|
|
@@ -238,8 +286,11 @@ function useEntityBlockEditor(kind, name) {
|
|
|
238
286
|
blocks: newBlocks,
|
|
239
287
|
selection
|
|
240
288
|
};
|
|
241
|
-
|
|
242
|
-
|
|
289
|
+
registry.batch(() => {
|
|
290
|
+
updateFootnotes(edits.blocks);
|
|
291
|
+
editEntityRecord(kind, name, id, edits);
|
|
292
|
+
});
|
|
293
|
+
}, [kind, name, id, updateFootnotes]);
|
|
243
294
|
return [blocks !== null && blocks !== void 0 ? blocks : EMPTY_ARRAY, onInput, onChange];
|
|
244
295
|
}
|
|
245
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,WAAO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AER,MAAAA,MAAM,EAAEK,SAAV;AAAqBE,MAAAA;AAArB,KAAd;AAEA,UAAME,QAAQ,GAAGT,MAAM,KAAKQ,KAAK,CAACR,MAAlC;;AACA,QAAKS,QAAL,EAAgB;AACf,aAAOR,yBAAyB,CAAE/B,IAAF,EAAQC,IAAR,EAAcQ,EAAd,CAAhC;AACA,KAPwB,CASzB;AACA;AACA;;;AACA6B,IAAAA,KAAK,CAACT,OAAN,GAAgB;AAAA,UAAE;AAAEC,QAAAA,MAAM,EAAEU,sBAAsB,GAAG;AAAnC,OAAF;AAAA,aACf,yCAA6BA,sBAA7B,CADe;AAAA,KAAhB;;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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,MAAAA,gBAAgB,CAAEzB,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBuD,KAAlB,CAAhB;AACA,KAHD;AAIA,GApBe,EAqBhB,CAAEhE,IAAF,EAAQC,IAAR,EAAcQ,EAAd,EAAkBwB,MAAlB,EAA0BI,eAA1B,CArBgB,CAAjB;AAwBA,QAAM+B,OAAO,GAAG,0BACf,CAAEP,SAAF,EAAaC,OAAb,KAA0B;AACzB,UAAM;AAAEC,MAAAA;AAAF,QAAgBD,OAAtB;AACA,UAAME,KAAK,GAAG;AAAE/B,MAAAA,MAAM,EAAE4B,SAAV;AAAqBE,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"]}
|
|
@@ -91,9 +91,7 @@ var _i18n = require("@wordpress/i18n");
|
|
|
91
91
|
* ```
|
|
92
92
|
* @return {Promise< WPLinkSearchResult[] >} List of search suggestions
|
|
93
93
|
*/
|
|
94
|
-
const fetchLinkSuggestions = async
|
|
95
|
-
let searchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
96
|
-
let settings = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
94
|
+
const fetchLinkSuggestions = async (search, searchOptions = {}, settings = {}) => {
|
|
97
95
|
const {
|
|
98
96
|
isInitialSuggestions = false,
|
|
99
97
|
type = undefined,
|
|
@@ -206,8 +204,6 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
206
204
|
}).slice(0, perPage).map((
|
|
207
205
|
/** @type {WPLinkSearchResultAugmented} */
|
|
208
206
|
result) => {
|
|
209
|
-
var _result$meta;
|
|
210
|
-
|
|
211
207
|
const isMedia = result.type === 'attachment';
|
|
212
208
|
return {
|
|
213
209
|
id: result.id,
|
|
@@ -216,7 +212,7 @@ const fetchLinkSuggestions = async function (search) {
|
|
|
216
212
|
title: (0, _htmlEntities.decodeEntities)(isMedia ? // @ts-ignore fix when we make this a TS file
|
|
217
213
|
result.title.rendered : result.title || '') || (0, _i18n.__)('(no title)'),
|
|
218
214
|
type: result.subtype || result.type,
|
|
219
|
-
kind: result
|
|
215
|
+
kind: result?.meta?.kind
|
|
220
216
|
};
|
|
221
217
|
});
|
|
222
218
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["fetchLinkSuggestions","search","searchOptions","settings","isInitialSuggestions","type","undefined","subtype","page","perPage","disablePostFormats","queries","push","path","per_page","then","results","map","result","meta","kind","catch","Promise","all","reduce","accumulator","current","concat","filter","id","slice","isMedia","url","source_url","title","rendered"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,oBAAoB,GAAG,gBAC5BC,MAD4B,EAIxB;AAAA,MAFJC,aAEI,uEAFY,EAEZ;AAAA,MADJC,QACI,uEADO,EACP;AACJ,QAAM;AACLC,IAAAA,oBAAoB,GAAG,KADlB;AAELC,IAAAA,IAAI,GAAGC,SAFF;AAGLC,IAAAA,OAAO,GAAGD,SAHL;AAILE,IAAAA,IAAI,GAAGF,SAJF;AAKLG,IAAAA,OAAO,GAAGL,oBAAoB,GAAG,CAAH,GAAO;AALhC,MAMFF,aANJ;AAQA,QAAM;AAAEQ,IAAAA,kBAAkB,GAAG;AAAvB,MAAiCP,QAAvC;AAEA;;AACA,QAAMQ,OAAO,GAAG,EAAhB;;AAEA,MAAK,CAAEN,IAAF,IAAUA,IAAI,KAAK,MAAxB,EAAiC;AAChCM,IAAAA,OAAO,CAACC,IAAR,CACC,uBAAU;AACTC,MAAAA,IAAI,EAAE,uBAAc,eAAd,EAA+B;AACpCZ,QAAAA,MADoC;AAEpCO,QAAAA,IAFoC;AAGpCM,QAAAA,QAAQ,EAAEL,OAH0B;AAIpCJ,QAAAA,IAAI,EAAE,MAJ8B;AAKpCE,QAAAA;AALoC,OAA/B;AADG,KAAV,EASEQ,IATF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7C,KAAyD;AAAA;;AAC9D,YAAMa,OAAO,GAAGb,MAAM,CAACb,IAAP,KAAgB,YAAhC;AAEA,aAAO;AACNwB,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAEN;AACAG,QAAAA,GAAG,EAAED,OAAO,GAAGb,MAAM,CAACe,UAAV,GAAuBf,MAAM,CAACc,GAHpC;AAINE,QAAAA,KAAK,EACJ,kCACCH,OAAO,GACJ;AACAb,QAAAA,MAAM,CAACgB,KAAP,CAAaC,QAFT,GAGJjB,MAAM,CAACgB,KAAP,IAAgB,EAJpB,KAKK,cAAI,YAAJ,CAVA;AAWN7B,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IAXzB;AAYNe,QAAAA,IAAI,EAAEF,MAAF,aAAEA,MAAF,uCAAEA,MAAM,CAAEC,IAAV,iDAAE,aAAcC;AAZd,OAAP;AAcA,KAhCK,CAAP;AAiCA,GAlCM,CAAP;AAmCA,CA/ID;;eAiJepB,oB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Filters the search by type\n *\n * @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType\n */\n\n/**\n * A link with an id may be of kind post-type or taxonomy\n *\n * @typedef { 'post-type' | 'taxonomy' } WPKind\n */\n\n/**\n * @typedef WPLinkSearchOptions\n *\n * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.\n * @property {WPLinkSearchType} [type] Filters by search type.\n * @property {string} [subtype] Slug of the post-type or taxonomy.\n * @property {number} [page] Which page of results to return.\n * @property {number} [perPage] Search results per page.\n */\n\n/**\n * @typedef WPLinkSearchResult\n *\n * @property {number} id Post or term id.\n * @property {string} url Link url.\n * @property {string} title Title of the link.\n * @property {string} type The taxonomy or post type slug or type URL.\n * @property {WPKind} [kind] Link kind of post-type or taxonomy\n */\n\n/**\n * @typedef WPLinkSearchResultAugments\n *\n * @property {{kind: WPKind}} [meta] Contains kind information.\n * @property {WPKind} [subtype] Optional subtype if it exists.\n */\n\n/**\n * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented\n */\n\n/**\n * @typedef WPEditorSettings\n *\n * @property {boolean} [ disablePostFormats ] Disables post formats, when true.\n */\n\n/**\n * Fetches link suggestions from the API.\n *\n * @async\n * @param {string} search\n * @param {WPLinkSearchOptions} [searchOptions]\n * @param {WPEditorSettings} [settings]\n *\n * @example\n * ```js\n * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchLinkSuggestions = (\n * search,\n * searchOptions\n * ) => fetchLinkSuggestions( search, searchOptions, settings );\n * ```\n * @return {Promise< WPLinkSearchResult[] >} List of search suggestions\n */\nconst fetchLinkSuggestions = async (\n\tsearch,\n\tsearchOptions = {},\n\tsettings = {}\n) => {\n\tconst {\n\t\tisInitialSuggestions = false,\n\t\ttype = undefined,\n\t\tsubtype = undefined,\n\t\tpage = undefined,\n\t\tperPage = isInitialSuggestions ? 3 : 20,\n\t} = searchOptions;\n\n\tconst { disablePostFormats = false } = settings;\n\n\t/** @type {Promise<WPLinkSearchResult>[]} */\n\tconst queries = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'post-type', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'term' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'term',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post-format',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'media' },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( /** @type {WPLinkSearchResult[]} */ accumulator, current ) =>\n\t\t\t\t\taccumulator.concat( current ), // Flatten list.\n\t\t\t\t[]\n\t\t\t)\n\t\t\t.filter(\n\t\t\t\t/**\n\t\t\t\t * @param {{ id: number }} result\n\t\t\t\t */\n\t\t\t\t( result ) => {\n\t\t\t\t\treturn !! result.id;\n\t\t\t\t}\n\t\t\t)\n\t\t\t.slice( 0, perPage )\n\t\t\t.map( ( /** @type {WPLinkSearchResultAugmented} */ result ) => {\n\t\t\t\tconst isMedia = result.type === 'attachment';\n\n\t\t\t\treturn {\n\t\t\t\t\tid: result.id,\n\t\t\t\t\t// @ts-ignore fix when we make this a TS file\n\t\t\t\t\turl: isMedia ? result.source_url : result.url,\n\t\t\t\t\ttitle:\n\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\tisMedia\n\t\t\t\t\t\t\t\t? // @ts-ignore fix when we make this a TS file\n\t\t\t\t\t\t\t\t result.title.rendered\n\t\t\t\t\t\t\t\t: result.title || ''\n\t\t\t\t\t\t) || __( '(no title)' ),\n\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t};\n\t\t\t} );\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-link-suggestions.js"],"names":["fetchLinkSuggestions","search","searchOptions","settings","isInitialSuggestions","type","undefined","subtype","page","perPage","disablePostFormats","queries","push","path","per_page","then","results","map","result","meta","kind","catch","Promise","all","reduce","accumulator","current","concat","filter","id","slice","isMedia","url","source_url","title","rendered"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,oBAAoB,GAAG,OAC5BC,MAD4B,EAE5BC,aAAa,GAAG,EAFY,EAG5BC,QAAQ,GAAG,EAHiB,KAIxB;AACJ,QAAM;AACLC,IAAAA,oBAAoB,GAAG,KADlB;AAELC,IAAAA,IAAI,GAAGC,SAFF;AAGLC,IAAAA,OAAO,GAAGD,SAHL;AAILE,IAAAA,IAAI,GAAGF,SAJF;AAKLG,IAAAA,OAAO,GAAGL,oBAAoB,GAAG,CAAH,GAAO;AALhC,MAMFF,aANJ;AAQA,QAAM;AAAEQ,IAAAA,kBAAkB,GAAG;AAAvB,MAAiCP,QAAvC;AAEA;;AACA,QAAMQ,OAAO,GAAG,EAAhB;;AAEA,MAAK,CAAEN,IAAF,IAAUA,IAAI,KAAK,MAAxB,EAAiC;AAChCM,IAAAA,OAAO,CAACC,IAAR,CACC,uBAAU;AACTC,MAAAA,IAAI,EAAE,uBAAc,eAAd,EAA+B;AACpCZ,QAAAA,MADoC;AAEpCO,QAAAA,IAFoC;AAGpCM,QAAAA,QAAQ,EAAEL,OAH0B;AAIpCJ,QAAAA,IAAI,EAAE,MAJ8B;AAKpCE,QAAAA;AALoC,OAA/B;AADG,KAAV,E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AAAA,MAA7C,KAAyD;AAC9D,YAAMa,OAAO,GAAGb,MAAM,CAACb,IAAP,KAAgB,YAAhC;AAEA,aAAO;AACNwB,QAAAA,EAAE,EAAEX,MAAM,CAACW,EADL;AAEN;AACAG,QAAAA,GAAG,EAAED,OAAO,GAAGb,MAAM,CAACe,UAAV,GAAuBf,MAAM,CAACc,GAHpC;AAINE,QAAAA,KAAK,EACJ,kCACCH,OAAO,GACJ;AACAb,QAAAA,MAAM,CAACgB,KAAP,CAAaC,QAFT,GAGJjB,MAAM,CAACgB,KAAP,IAAgB,EAJpB,KAKK,cAAI,YAAJ,CAVA;AAWN7B,QAAAA,IAAI,EAAEa,MAAM,CAACX,OAAP,IAAkBW,MAAM,CAACb,IAXzB;AAYNe,QAAAA,IAAI,EAAEF,MAAM,EAAEC,IAAR,EAAcC;AAZd,OAAP;AAcA,KAhCK,CAAP;AAiCA,GAlCM,CAAP;AAmCA,CA/ID;;eAiJepB,oB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Filters the search by type\n *\n * @typedef { 'attachment' | 'post' | 'term' | 'post-format' } WPLinkSearchType\n */\n\n/**\n * A link with an id may be of kind post-type or taxonomy\n *\n * @typedef { 'post-type' | 'taxonomy' } WPKind\n */\n\n/**\n * @typedef WPLinkSearchOptions\n *\n * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.\n * @property {WPLinkSearchType} [type] Filters by search type.\n * @property {string} [subtype] Slug of the post-type or taxonomy.\n * @property {number} [page] Which page of results to return.\n * @property {number} [perPage] Search results per page.\n */\n\n/**\n * @typedef WPLinkSearchResult\n *\n * @property {number} id Post or term id.\n * @property {string} url Link url.\n * @property {string} title Title of the link.\n * @property {string} type The taxonomy or post type slug or type URL.\n * @property {WPKind} [kind] Link kind of post-type or taxonomy\n */\n\n/**\n * @typedef WPLinkSearchResultAugments\n *\n * @property {{kind: WPKind}} [meta] Contains kind information.\n * @property {WPKind} [subtype] Optional subtype if it exists.\n */\n\n/**\n * @typedef {WPLinkSearchResult & WPLinkSearchResultAugments} WPLinkSearchResultAugmented\n */\n\n/**\n * @typedef WPEditorSettings\n *\n * @property {boolean} [ disablePostFormats ] Disables post formats, when true.\n */\n\n/**\n * Fetches link suggestions from the API.\n *\n * @async\n * @param {string} search\n * @param {WPLinkSearchOptions} [searchOptions]\n * @param {WPEditorSettings} [settings]\n *\n * @example\n * ```js\n * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchLinkSuggestions = (\n * search,\n * searchOptions\n * ) => fetchLinkSuggestions( search, searchOptions, settings );\n * ```\n * @return {Promise< WPLinkSearchResult[] >} List of search suggestions\n */\nconst fetchLinkSuggestions = async (\n\tsearch,\n\tsearchOptions = {},\n\tsettings = {}\n) => {\n\tconst {\n\t\tisInitialSuggestions = false,\n\t\ttype = undefined,\n\t\tsubtype = undefined,\n\t\tpage = undefined,\n\t\tperPage = isInitialSuggestions ? 3 : 20,\n\t} = searchOptions;\n\n\tconst { disablePostFormats = false } = settings;\n\n\t/** @type {Promise<WPLinkSearchResult>[]} */\n\tconst queries = [];\n\n\tif ( ! type || type === 'post' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'post-type', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'term' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'term',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! disablePostFormats && ( ! type || type === 'post-format' ) ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/search', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t\ttype: 'post-format',\n\t\t\t\t\tsubtype,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'taxonomy', subtype },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\tif ( ! type || type === 'attachment' ) {\n\t\tqueries.push(\n\t\t\tapiFetch( {\n\t\t\t\tpath: addQueryArgs( '/wp/v2/media', {\n\t\t\t\t\tsearch,\n\t\t\t\t\tpage,\n\t\t\t\t\tper_page: perPage,\n\t\t\t\t} ),\n\t\t\t} )\n\t\t\t\t.then( ( results ) => {\n\t\t\t\t\treturn results.map( ( result ) => {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\tmeta: { kind: 'media' },\n\t\t\t\t\t\t};\n\t\t\t\t\t} );\n\t\t\t\t} )\n\t\t\t\t.catch( () => [] ) // Fail by returning no results.\n\t\t);\n\t}\n\n\treturn Promise.all( queries ).then( ( results ) => {\n\t\treturn results\n\t\t\t.reduce(\n\t\t\t\t( /** @type {WPLinkSearchResult[]} */ accumulator, current ) =>\n\t\t\t\t\taccumulator.concat( current ), // Flatten list.\n\t\t\t\t[]\n\t\t\t)\n\t\t\t.filter(\n\t\t\t\t/**\n\t\t\t\t * @param {{ id: number }} result\n\t\t\t\t */\n\t\t\t\t( result ) => {\n\t\t\t\t\treturn !! result.id;\n\t\t\t\t}\n\t\t\t)\n\t\t\t.slice( 0, perPage )\n\t\t\t.map( ( /** @type {WPLinkSearchResultAugmented} */ result ) => {\n\t\t\t\tconst isMedia = result.type === 'attachment';\n\n\t\t\t\treturn {\n\t\t\t\t\tid: result.id,\n\t\t\t\t\t// @ts-ignore fix when we make this a TS file\n\t\t\t\t\turl: isMedia ? result.source_url : result.url,\n\t\t\t\t\ttitle:\n\t\t\t\t\t\tdecodeEntities(\n\t\t\t\t\t\t\tisMedia\n\t\t\t\t\t\t\t\t? // @ts-ignore fix when we make this a TS file\n\t\t\t\t\t\t\t\t result.title.rendered\n\t\t\t\t\t\t\t\t: result.title || ''\n\t\t\t\t\t\t) || __( '(no title)' ),\n\t\t\t\t\ttype: result.subtype || result.type,\n\t\t\t\t\tkind: result?.meta?.kind,\n\t\t\t\t};\n\t\t\t} );\n\t} );\n};\n\nexport default fetchLinkSuggestions;\n"]}
|
|
@@ -49,8 +49,7 @@ const CACHE = new Map();
|
|
|
49
49
|
* @return {Promise< WPRemoteUrlData[] >} Remote URL data.
|
|
50
50
|
*/
|
|
51
51
|
|
|
52
|
-
const fetchUrlData = async
|
|
53
|
-
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
52
|
+
const fetchUrlData = async (url, options = {}) => {
|
|
54
53
|
const endpoint = '/wp-block-editor/v1/url-details';
|
|
55
54
|
const args = {
|
|
56
55
|
url: (0, _url.prependHTTP)(url)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/fetch/__experimental-fetch-url-data.js"],"names":["CACHE","Map","fetchUrlData","url","options","endpoint","args","Promise","reject","protocol","startsWith","test","has","get","path","then","res","set"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAUA;AACA;AACA;AACA;AACA;AACA,MAAMA,KAAK,GAAG,IAAIC,GAAJ,EAAd;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAG,OAAQC,GAAR,EAAaC,OAAO,GAAG,EAAvB,KAA+B;AACnD,QAAMC,QAAQ,GAAG,iCAAjB;AAEA,QAAMC,IAAI,GAAG;AACZH,IAAAA,GAAG,EAAE,sBAAaA,GAAb;AADO,GAAb;;AAIA,MAAK,CAAE,gBAAOA,GAAP,CAAP,EAAsB;AACrB,WAAOI,OAAO,CAACC,MAAR,CAAiB,GAAGL,GAAK,sBAAzB,CAAP;AACA,GATkD,CAWnD;AACA;;;AACA,QAAMM,QAAQ,GAAG,sBAAaN,GAAb,CAAjB;;AAEA,MACC,CAAEM,QAAF,IACA,CAAE,0BAAiBA,QAAjB,CADF,IAEA,CAAEA,QAAQ,CAACC,UAAT,CAAqB,MAArB,CAFF,IAGA,CAAE,uBAAuBC,IAAvB,CAA6BR,GAA7B,CAJH,EAKE;AACD,WAAOI,OAAO,CAACC,MAAR,CACL,GAAGL,GAAK,4DADH,CAAP;AAGA;;AAED,MAAKH,KAAK,CAACY,GAAN,CAAWT,GAAX,CAAL,EAAwB;AACvB,WAAOH,KAAK,CAACa,GAAN,CAAWV,GAAX,CAAP;AACA;;AAED,SAAO,uBAAU;AAChBW,IAAAA,IAAI,EAAE,uBAAcT,QAAd,EAAwBC,IAAxB,CADU;AAEhB,OAAGF;AAFa,GAAV,EAGHW,IAHG,CAGKC,GAAF,IAAW;AACpBhB,IAAAA,KAAK,CAACiB,GAAN,CAAWd,GAAX,EAAgBa,GAAhB;AACA,WAAOA,GAAP;AACA,GANM,CAAP;AAOA,CArCD;;eAuCed,Y","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport {\n\taddQueryArgs,\n\tprependHTTP,\n\tisURL,\n\tgetProtocol,\n\tisValidProtocol,\n} from '@wordpress/url';\n\n/**\n * A simple in-memory cache for requests.\n * This avoids repeat HTTP requests which may be beneficial\n * for those wishing to preserve low-bandwidth.\n */\nconst CACHE = new Map();\n\n/**\n * @typedef WPRemoteUrlData\n *\n * @property {string} title contents of the remote URL's `<title>` tag.\n */\n\n/**\n * Fetches data about a remote URL.\n * eg: <title> tag, favicon...etc.\n *\n * @async\n * @param {string} url the URL to request details from.\n * @param {Object?} options any options to pass to the underlying fetch.\n * @example\n * ```js\n * import { __experimentalFetchUrlData as fetchUrlData } from '@wordpress/core-data';\n *\n * //...\n *\n * export function initialize( id, settings ) {\n *\n * settings.__experimentalFetchUrlData = (\n * url\n * ) => fetchUrlData( url );\n * ```\n * @return {Promise< WPRemoteUrlData[] >} Remote URL data.\n */\nconst fetchUrlData = async ( url, options = {} ) => {\n\tconst endpoint = '/wp-block-editor/v1/url-details';\n\n\tconst args = {\n\t\turl: prependHTTP( url ),\n\t};\n\n\tif ( ! isURL( url ) ) {\n\t\treturn Promise.reject( `${ url } is not a valid URL.` );\n\t}\n\n\t// Test for \"http\" based URL as it is possible for valid\n\t// yet unusable URLs such as `tel:123456` to be passed.\n\tconst protocol = getProtocol( url );\n\n\tif (\n\t\t! protocol ||\n\t\t! isValidProtocol( protocol ) ||\n\t\t! protocol.startsWith( 'http' ) ||\n\t\t! /^https?:\\/\\/[^\\/\\s]/i.test( url )\n\t) {\n\t\treturn Promise.reject(\n\t\t\t`${ url } does not have a valid protocol. URLs must be \"http\" based`\n\t\t);\n\t}\n\n\tif ( CACHE.has( url ) ) {\n\t\treturn CACHE.get( url );\n\t}\n\n\treturn apiFetch( {\n\t\tpath: addQueryArgs( endpoint, args ),\n\t\t...options,\n\t} ).then( ( res ) => {\n\t\tCACHE.set( url, res );\n\t\treturn res;\n\t} );\n};\n\nexport default fetchUrlData;\n"]}
|
|
@@ -114,24 +114,20 @@ var _ = require("../");
|
|
|
114
114
|
* @return Entity record data.
|
|
115
115
|
* @template RecordType
|
|
116
116
|
*/
|
|
117
|
-
function useEntityRecord(kind, name, recordId
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
117
|
+
function useEntityRecord(kind, name, recordId, options = {
|
|
118
|
+
enabled: true
|
|
119
|
+
}) {
|
|
121
120
|
const {
|
|
122
121
|
editEntityRecord,
|
|
123
122
|
saveEditedEntityRecord
|
|
124
123
|
} = (0, _data.useDispatch)(_.store);
|
|
125
124
|
const mutations = (0, _element.useMemo)(() => ({
|
|
126
125
|
edit: record => editEntityRecord(kind, name, recordId, record),
|
|
127
|
-
save:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}), [recordId]);
|
|
126
|
+
save: (saveOptions = {}) => saveEditedEntityRecord(kind, name, recordId, {
|
|
127
|
+
throwOnError: true,
|
|
128
|
+
...saveOptions
|
|
129
|
+
})
|
|
130
|
+
}), [editEntityRecord, kind, name, recordId, saveEditedEntityRecord]);
|
|
135
131
|
const {
|
|
136
132
|
editedRecord,
|
|
137
133
|
hasEdits
|
|
@@ -144,7 +140,9 @@ function useEntityRecord(kind, name, recordId) {
|
|
|
144
140
|
...querySelectRest
|
|
145
141
|
} = (0, _useQuerySelect.default)(query => {
|
|
146
142
|
if (!options.enabled) {
|
|
147
|
-
return
|
|
143
|
+
return {
|
|
144
|
+
data: null
|
|
145
|
+
};
|
|
148
146
|
}
|
|
149
147
|
|
|
150
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,
|
|
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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ASe,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' );
|
|
@@ -65,11 +65,9 @@ const EMPTY_ARRAY = [];
|
|
|
65
65
|
* @template RecordType
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
-
function useEntityRecords(kind, name
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
enabled: true
|
|
72
|
-
};
|
|
68
|
+
function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
69
|
+
enabled: true
|
|
70
|
+
}) {
|
|
73
71
|
// Serialize queryArgs to a string that can be safely used as a React dep.
|
|
74
72
|
// We can't just pass queryArgs as one of the deps, because if it is passed
|
|
75
73
|
// as an object literal, then it will be a different object on each call even
|
|
@@ -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,
|
|
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"]}
|
|
@@ -91,16 +91,11 @@ const enrichSelectors = (0, _memoize.default)(selectors => {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
Object.defineProperty(resolvers, selectorName, {
|
|
94
|
-
get: () =>
|
|
94
|
+
get: () => (...args) => {
|
|
95
95
|
const {
|
|
96
96
|
getIsResolving,
|
|
97
97
|
hasFinishedResolution
|
|
98
98
|
} = selectors;
|
|
99
|
-
|
|
100
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
101
|
-
args[_key] = arguments[_key];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
99
|
const isResolving = !!getIsResolving(selectorName, args);
|
|
105
100
|
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
|
|
106
101
|
const data = selectors[selectorName](...args);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","args","getIsResolving","hasFinishedResolution","isResolving","hasResolved","data","status","Status","Resolving","Success","Error","Idle"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;AAIO,MAAMA,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,cAAT,CAAyBC,cAAzB,EAAyCC,IAAzC,EAAgD;AAC9D,SAAO,qBAAW,CAAEC,MAAF,EAAUC,QAAV,KAAwB;AACzC,UAAMC,OAAO,GAAKC,KAAF,IAAaC,eAAe,CAAEJ,MAAM,CAAEG,KAAF,CAAR,CAA5C;;AACA,WAAOL,cAAc,CAAEI,OAAF,EAAWD,QAAX,CAArB;AACA,GAHM,EAGJF,IAHI,CAAP;AAIA;;AAYD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,eAAe,GAAG,sBAAaC,SAAF,IAAiB;AACnD,QAAMC,SAAS,GAAG,EAAlB;;AACA,OAAM,MAAMC,YAAZ,IAA4BF,SAA5B,EAAwC;AACvC,QAAKT,cAAc,CAACY,QAAf,CAAyBD,YAAzB,CAAL,EAA+C;AAC9C;AACA;;AACDE,IAAAA,MAAM,CAACC,cAAP,CAAuBJ,SAAvB,EAAkCC,YAAlC,EAAgD;AAC/CI,MAAAA,GAAG,EACF,MACA,CAAE,GAAGC,IAAL,KAA0B;AACzB,cAAM;AAAEC,UAAAA,cAAF;AAAkBC,UAAAA;AAAlB,YAA4CT,SAAlD;AACA,cAAMU,WAAW,GAAG,CAAC,CAAEF,cAAc,CAAEN,YAAF,EAAgBK,IAAhB,CAArC;AACA,cAAMI,WAAW,GAChB,CAAED,WAAF,IACAD,qBAAqB,CAAEP,YAAF,EAAgBK,IAAhB,CAFtB;AAGA,cAAMK,IAAI,GAAGZ,SAAS,CAAEE,YAAF,CAAT,CAA2B,GAAGK,IAA9B,CAAb;AAEA,YAAIM,MAAJ;;AACA,YAAKH,WAAL,EAAmB;AAClBG,UAAAA,MAAM,GAAGC,kBAAOC,SAAhB;AACA,SAFD,MAEO,IAAKJ,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGC,kBAAOE,OAAhB;AACA,WAFD,MAEO;AACNH,YAAAA,MAAM,GAAGC,kBAAOG,KAAhB;AACA;AACD,SANM,MAMA;AACNJ,UAAAA,MAAM,GAAGC,kBAAOI,IAAhB;AACA;;AAED,eAAO;AACNN,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA9B6C,KAAhD;AAgCA;;AACD,SAAOV,SAAP;AACA,CAxCuB,CAAxB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `getIsResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @since 6.1.0 Introduced in WordPress core.\n * @private\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\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 the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function useQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"]}
|
package/build/index.js
CHANGED
|
@@ -127,13 +127,7 @@ const entityResolvers = _entities.rootEntitiesConfig.reduce((result, entity) =>
|
|
|
127
127
|
|
|
128
128
|
const pluralMethodName = (0, _entities.getMethodName)(kind, name, 'get', true);
|
|
129
129
|
|
|
130
|
-
result[pluralMethodName] =
|
|
131
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
132
|
-
args[_key] = arguments[_key];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return resolvers.getEntityRecords(kind, name, ...args);
|
|
136
|
-
};
|
|
130
|
+
result[pluralMethodName] = (...args) => resolvers.getEntityRecords(kind, name, ...args);
|
|
137
131
|
|
|
138
132
|
result[pluralMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
139
133
|
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAoDA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;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ACA;AACA;AACA;AACA;;;AACO,MAAMY,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AACP,oBAAUE,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
|
package/build/locks/actions.js
CHANGED
|
@@ -15,10 +15,9 @@ var _engine = _interopRequireDefault(require("./engine"));
|
|
|
15
15
|
function createLocksActions() {
|
|
16
16
|
const locks = (0, _engine.default)();
|
|
17
17
|
|
|
18
|
-
function __unstableAcquireStoreLock(store, path,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} = _ref;
|
|
18
|
+
function __unstableAcquireStoreLock(store, path, {
|
|
19
|
+
exclusive
|
|
20
|
+
}) {
|
|
22
21
|
return () => locks.acquire(store, path, exclusive);
|
|
23
22
|
}
|
|
24
23
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAG,sBAAd;;AAEA,WAASC,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGe,SAASA,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAG,sBAAd;;AAEA,WAASC,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,EAAkD;AAAEC,IAAAA;AAAF,GAAlD,EAAkE;AACjE,WAAO,MAAMJ,KAAK,CAACK,OAAN,CAAeH,KAAf,EAAsBC,IAAtB,EAA4BC,SAA5B,CAAb;AACA;;AAED,WAASE,0BAAT,CAAqCC,IAArC,EAA4C;AAC3C,WAAO,MAAMP,KAAK,CAACQ,OAAN,CAAeD,IAAf,CAAb;AACA;;AAED,SAAO;AAAEN,IAAAA,0BAAF;AAA8BK,IAAAA;AAA9B,GAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"]}
|