@wordpress/core-data 7.10.0 → 7.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/actions.js +13 -9
- package/build/actions.js.map +1 -1
- package/build/entities.js +3 -63
- package/build/entities.js.map +1 -1
- package/build/entity-types/attachment.js.map +1 -1
- package/build/entity-types/settings.js.map +1 -1
- package/build/hooks/use-entity-block-editor.js +4 -5
- package/build/hooks/use-entity-block-editor.js.map +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +3 -1
- package/build/private-apis.js.map +1 -1
- package/build/resolvers.js +98 -68
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +0 -19
- package/build/selectors.js.map +1 -1
- package/build/utils/index.js +7 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/receive-intermediate-results.js +8 -0
- package/build/utils/receive-intermediate-results.js.map +1 -0
- package/build-module/actions.js +14 -10
- package/build-module/actions.js.map +1 -1
- package/build-module/entities.js +2 -61
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-types/attachment.js.map +1 -1
- package/build-module/entity-types/settings.js.map +1 -1
- package/build-module/hooks/use-entity-block-editor.js +4 -5
- package/build-module/hooks/use-entity-block-editor.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js +3 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/resolvers.js +98 -68
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +0 -18
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/index.js +1 -0
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/receive-intermediate-results.js +2 -0
- package/build-module/utils/receive-intermediate-results.js.map +1 -0
- package/build-types/actions.d.ts +8 -4
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +0 -1
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-types/attachment.d.ts +36 -1
- package/build-types/entity-types/attachment.d.ts.map +1 -1
- package/build-types/entity-types/settings.d.ts +4 -0
- package/build-types/entity-types/settings.d.ts.map +1 -1
- package/build-types/hooks/use-entity-block-editor.d.ts.map +1 -1
- package/build-types/index.d.ts +8 -5
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +1 -2
- package/build-types/lock-unlock.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/queried-data/reducer.d.ts +10 -2
- package/build-types/reducer.d.ts +24 -2
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +16 -13
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts +0 -9
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -0
- package/build-types/utils/receive-intermediate-results.d.ts +2 -0
- package/build-types/utils/receive-intermediate-results.d.ts.map +1 -0
- package/package.json +19 -18
- package/src/actions.js +10 -10
- package/src/entities.js +2 -64
- package/src/entity-types/attachment.ts +35 -1
- package/src/entity-types/settings.ts +4 -0
- package/src/hooks/test/use-entity-record.js +9 -2
- package/src/hooks/use-entity-block-editor.js +4 -9
- package/src/private-apis.js +2 -0
- package/src/resolvers.js +125 -90
- package/src/selectors.ts +0 -32
- package/src/test/actions.js +24 -39
- package/src/test/entities.js +0 -80
- package/src/test/resolvers.js +89 -35
- package/src/utils/index.js +1 -0
- package/src/utils/receive-intermediate-results.js +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- /package/src/{lock-unlock.js → lock-unlock.ts} +0 -0
|
@@ -94,7 +94,6 @@ function useEntityBlockEditor(kind, name, {
|
|
|
94
94
|
}
|
|
95
95
|
return _blocks;
|
|
96
96
|
}, [kind, name, id, editedBlocks, content, getEntityRecord, getEntityRecordEdits]);
|
|
97
|
-
const updateFootnotes = (0, _element.useCallback)(_blocks => (0, _footnotes.updateFootnotesFromMeta)(_blocks, meta), [meta]);
|
|
98
97
|
const onChange = (0, _element.useCallback)((newBlocks, options) => {
|
|
99
98
|
const noChange = blocks === newBlocks;
|
|
100
99
|
if (noChange) {
|
|
@@ -113,19 +112,19 @@ function useEntityBlockEditor(kind, name, {
|
|
|
113
112
|
content: ({
|
|
114
113
|
blocks: blocksForSerialization = []
|
|
115
114
|
}) => (0, _blocks2.__unstableSerializeAndClean)(blocksForSerialization),
|
|
116
|
-
...
|
|
115
|
+
...(0, _footnotes.updateFootnotesFromMeta)(newBlocks, meta)
|
|
117
116
|
};
|
|
118
117
|
editEntityRecord(kind, name, id, edits, {
|
|
119
118
|
isCached: false,
|
|
120
119
|
...rest
|
|
121
120
|
});
|
|
122
|
-
}, [kind, name, id, blocks,
|
|
121
|
+
}, [kind, name, id, blocks, meta, __unstableCreateUndoLevel, editEntityRecord]);
|
|
123
122
|
const onInput = (0, _element.useCallback)((newBlocks, options) => {
|
|
124
123
|
const {
|
|
125
124
|
selection,
|
|
126
125
|
...rest
|
|
127
126
|
} = options;
|
|
128
|
-
const footnotesChanges =
|
|
127
|
+
const footnotesChanges = (0, _footnotes.updateFootnotesFromMeta)(newBlocks, meta);
|
|
129
128
|
const edits = {
|
|
130
129
|
selection,
|
|
131
130
|
...footnotesChanges
|
|
@@ -134,7 +133,7 @@ function useEntityBlockEditor(kind, name, {
|
|
|
134
133
|
isCached: true,
|
|
135
134
|
...rest
|
|
136
135
|
});
|
|
137
|
-
}, [kind, name, id,
|
|
136
|
+
}, [kind, name, id, meta, editEntityRecord]);
|
|
138
137
|
return [blocks, onInput, onChange];
|
|
139
138
|
}
|
|
140
139
|
//# sourceMappingURL=use-entity-block-editor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_data","_blocks2","_name","_useEntityId","_interopRequireDefault","_footnotes","EMPTY_ARRAY","parsedBlocksCache","WeakMap","useEntityBlockEditor","kind","name","id","_id","providerId","useEntityId","getEntityRecord","getEntityRecordEdits","useSelect","STORE_NAME","content","editedBlocks","meta","select","getEditedEntityRecord","editedRecord","blocks","__unstableCreateUndoLevel","editEntityRecord","useDispatch","useMemo","undefined","edits","isUnedited","Object","keys","length","cackeKey","_blocks","get","parse","set","
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_blocks2","_name","_useEntityId","_interopRequireDefault","_footnotes","EMPTY_ARRAY","parsedBlocksCache","WeakMap","useEntityBlockEditor","kind","name","id","_id","providerId","useEntityId","getEntityRecord","getEntityRecordEdits","useSelect","STORE_NAME","content","editedBlocks","meta","select","getEditedEntityRecord","editedRecord","blocks","__unstableCreateUndoLevel","editEntityRecord","useDispatch","useMemo","undefined","edits","isUnedited","Object","keys","length","cackeKey","_blocks","get","parse","set","onChange","useCallback","newBlocks","options","noChange","selection","rest","blocksForSerialization","__unstableSerializeAndClean","updateFootnotesFromMeta","isCached","onInput","footnotesChanges"],"sources":["@wordpress/core-data/src/hooks/use-entity-block-editor.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\nimport useEntityId from './use-entity-id';\nimport { updateFootnotesFromMeta } from '../footnotes';\n\nconst EMPTY_ARRAY = [];\nconst parsedBlocksCache = new WeakMap();\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 * persistent 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 {[unknown[], Function, Function]} The block array and setters.\n */\nexport default function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { getEntityRecord, getEntityRecordEdits } = useSelect( STORE_NAME );\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {};\n\t\t\t}\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\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\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\tconst blocks = useMemo( () => {\n\t\tif ( ! id ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\tif ( ! content || typeof content !== 'string' ) {\n\t\t\treturn EMPTY_ARRAY;\n\t\t}\n\n\t\t// If there's an edit, cache the parsed blocks by the edit.\n\t\t// If not, cache by the original enity record.\n\t\tconst edits = getEntityRecordEdits( kind, name, id );\n\t\tconst isUnedited = ! edits || ! Object.keys( edits ).length;\n\t\tconst cackeKey = isUnedited ? getEntityRecord( kind, name, id ) : edits;\n\t\tlet _blocks = parsedBlocksCache.get( cackeKey );\n\n\t\tif ( ! _blocks ) {\n\t\t\t_blocks = parse( content );\n\t\t\tparsedBlocksCache.set( cackeKey, _blocks );\n\t\t}\n\n\t\treturn _blocks;\n\t}, [\n\t\tkind,\n\t\tname,\n\t\tid,\n\t\teditedBlocks,\n\t\tcontent,\n\t\tgetEntityRecord,\n\t\tgetEntityRecordEdits,\n\t] );\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection, ...rest } = options;\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\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotesFromMeta( newBlocks, meta ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: false,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tmeta,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection, ...rest } = options;\n\t\t\tconst footnotesChanges = updateFootnotesFromMeta( newBlocks, meta );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, {\n\t\t\t\tisCached: true,\n\t\t\t\t...rest,\n\t\t\t} );\n\t\t},\n\t\t[ kind, name, id, meta, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAC,sBAAA,CAAAL,OAAA;AACA,IAAAM,UAAA,GAAAN,OAAA;AAZA;AACA;AACA;;AAKA;AACA;AACA;;AAKA,MAAMO,WAAW,GAAG,EAAE;AACtB,MAAMC,iBAAiB,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAEvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,oBAAoBA,CA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AAE,KAAK;MACf,GAAGJ;IACJ,CAAE,CAAC;EACJ,CAAC,EACD,CACCtC,IAAI,EACJC,IAAI,EACJC,EAAE,EACFc,MAAM,EACNJ,IAAI,EACJK,yBAAyB,EACzBC,gBAAgB,CAElB,CAAC;EAED,MAAMyB,OAAO,GAAG,IAAAV,oBAAW,EAC1B,CAAEC,SAAS,EAAEC,OAAO,KAAM;IACzB,MAAM;MAAEE,SAAS;MAAE,GAAGC;IAAK,CAAC,GAAGH,OAAO;IACtC,MAAMS,gBAAgB,GAAG,IAAAH,kCAAuB,EAAEP,SAAS,EAAEtB,IAAK,CAAC;IACnE,MAAMU,KAAK,GAAG;MAAEe,SAAS;MAAE,GAAGO;IAAiB,CAAC;IAEhD1B,gBAAgB,CAAElB,IAAI,EAAEC,IAAI,EAAEC,EAAE,EAAEoB,KAAK,EAAE;MACxCoB,QAAQ,EAAE,IAAI;MACd,GAAGJ;IACJ,CAAE,CAAC;EACJ,CAAC,EACD,CAAEtC,IAAI,EAAEC,IAAI,EAAEC,EAAE,EAAEU,IAAI,EAAEM,gBAAgB,CACzC,CAAC;EAED,OAAO,CAAEF,MAAM,EAAE2B,OAAO,EAAEX,QAAQ,CAAE;AACrC","ignoreList":[]}
|
package/build/lock-unlock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_privateApis","require","lock","unlock","__dangerousOptInToUnstableAPIsOnlyForCoreModules","exports"],"sources":["@wordpress/core-data/src/lock-unlock.
|
|
1
|
+
{"version":3,"names":["_privateApis","require","lock","unlock","__dangerousOptInToUnstableAPIsOnlyForCoreModules","exports"],"sources":["@wordpress/core-data/src/lock-unlock.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/core-data'\n\t);\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAM;EAAEC,IAAI;EAAEC;AAAO,CAAC,GAC5B,IAAAC,6DAAgD,EAC/C,+HAA+H,EAC/H,sBACD,CAAC;AAACC,OAAA,CAAAF,MAAA,GAAAA,MAAA;AAAAE,OAAA,CAAAH,IAAA,GAAAA,IAAA","ignoreList":[]}
|
package/build/private-apis.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.privateApis = void 0;
|
|
7
7
|
var _useEntityRecords = require("./hooks/use-entity-records");
|
|
8
|
+
var _utils = require("./utils");
|
|
8
9
|
var _lockUnlock = require("./lock-unlock");
|
|
9
10
|
/**
|
|
10
11
|
* Internal dependencies
|
|
@@ -12,6 +13,7 @@ var _lockUnlock = require("./lock-unlock");
|
|
|
12
13
|
|
|
13
14
|
const privateApis = exports.privateApis = {};
|
|
14
15
|
(0, _lockUnlock.lock)(privateApis, {
|
|
15
|
-
useEntityRecordsWithPermissions: _useEntityRecords.useEntityRecordsWithPermissions
|
|
16
|
+
useEntityRecordsWithPermissions: _useEntityRecords.useEntityRecordsWithPermissions,
|
|
17
|
+
RECEIVE_INTERMEDIATE_RESULTS: _utils.RECEIVE_INTERMEDIATE_RESULTS
|
|
16
18
|
});
|
|
17
19
|
//# sourceMappingURL=private-apis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useEntityRecords","require","_lockUnlock","privateApis","exports","lock","useEntityRecordsWithPermissions"],"sources":["@wordpress/core-data/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useEntityRecordsWithPermissions } from './hooks/use-entity-records';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseEntityRecordsWithPermissions,\n} );\n"],"mappings":";;;;;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,
|
|
1
|
+
{"version":3,"names":["_useEntityRecords","require","_utils","_lockUnlock","privateApis","exports","lock","useEntityRecordsWithPermissions","RECEIVE_INTERMEDIATE_RESULTS"],"sources":["@wordpress/core-data/src/private-apis.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useEntityRecordsWithPermissions } from './hooks/use-entity-records';\nimport { RECEIVE_INTERMEDIATE_RESULTS } from './utils';\nimport { lock } from './lock-unlock';\n\nexport const privateApis = {};\nlock( privateApis, {\n\tuseEntityRecordsWithPermissions,\n\tRECEIVE_INTERMEDIATE_RESULTS,\n} );\n"],"mappings":";;;;;;AAGA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AALA;AACA;AACA;;AAKO,MAAMG,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG,CAAC,CAAC;AAC7B,IAAAE,gBAAI,EAAEF,WAAW,EAAE;EAClBG,+BAA+B,EAA/BA,iDAA+B;EAC/BC,4BAA4B,EAA5BA;AACD,CAAE,CAAC","ignoreList":[]}
|
package/build/resolvers.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.getUserPatternCategories = exports.getThemeSupports = exports.getRevisions = exports.getRevision = exports.getRegisteredPostMeta = exports.getRawEntityRecord = exports.getNavigationFallbackId = exports.getEntityRecords = exports.getEntityRecord = exports.getEmbedPreview = exports.getEditedEntityRecord = exports.getDefaultTemplateId = exports.getCurrentUser = exports.getCurrentThemeGlobalStylesRevisions = exports.getCurrentTheme = exports.getBlockPatterns = exports.getBlockPatternCategories = exports.getAutosaves = exports.getAutosave = exports.getAuthors = exports.canUserEditEntityRecord = exports.canUser = exports.
|
|
8
|
+
exports.getUserPatternCategories = exports.getThemeSupports = exports.getRevisions = exports.getRevision = exports.getRegisteredPostMeta = exports.getRawEntityRecord = exports.getNavigationFallbackId = exports.getEntityRecords = exports.getEntityRecord = exports.getEntitiesConfig = exports.getEmbedPreview = exports.getEditedEntityRecord = exports.getDefaultTemplateId = exports.getCurrentUser = exports.getCurrentThemeGlobalStylesRevisions = exports.getCurrentTheme = exports.getBlockPatterns = exports.getBlockPatternCategories = exports.getAutosaves = exports.getAutosave = exports.getAuthors = exports.canUserEditEntityRecord = exports.canUser = exports.__experimentalGetCurrentThemeGlobalStylesVariations = exports.__experimentalGetCurrentThemeBaseGlobalStyles = exports.__experimentalGetCurrentGlobalStylesId = void 0;
|
|
9
9
|
var _changeCase = require("change-case");
|
|
10
10
|
var _url = require("@wordpress/url");
|
|
11
11
|
var _htmlEntities = require("@wordpress/html-entities");
|
|
@@ -70,9 +70,10 @@ exports.getCurrentUser = getCurrentUser;
|
|
|
70
70
|
const getEntityRecord = (kind, name, key = '', query) => async ({
|
|
71
71
|
select,
|
|
72
72
|
dispatch,
|
|
73
|
-
registry
|
|
73
|
+
registry,
|
|
74
|
+
resolveSelect
|
|
74
75
|
}) => {
|
|
75
|
-
const configs = await
|
|
76
|
+
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
76
77
|
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
77
78
|
if (!entityConfig) {
|
|
78
79
|
return;
|
|
@@ -194,9 +195,10 @@ const getEditedEntityRecord = exports.getEditedEntityRecord = (0, _utils.forward
|
|
|
194
195
|
*/
|
|
195
196
|
const getEntityRecords = (kind, name, query = {}) => async ({
|
|
196
197
|
dispatch,
|
|
197
|
-
registry
|
|
198
|
+
registry,
|
|
199
|
+
resolveSelect
|
|
198
200
|
}) => {
|
|
199
|
-
const configs = await
|
|
201
|
+
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
200
202
|
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
201
203
|
if (!entityConfig) {
|
|
202
204
|
return;
|
|
@@ -204,6 +206,10 @@ const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
204
206
|
const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name], {
|
|
205
207
|
exclusive: false
|
|
206
208
|
});
|
|
209
|
+
const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
|
|
210
|
+
function getResolutionsArgs(records) {
|
|
211
|
+
return records.filter(record => record?.[key]).map(record => [kind, name, record[key]]);
|
|
212
|
+
}
|
|
207
213
|
try {
|
|
208
214
|
if (query._fields) {
|
|
209
215
|
// If requesting specific fields, items and query association to said
|
|
@@ -218,7 +224,8 @@ const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
218
224
|
...entityConfig.baseURLParams,
|
|
219
225
|
...query
|
|
220
226
|
});
|
|
221
|
-
let records,
|
|
227
|
+
let records = [],
|
|
228
|
+
meta;
|
|
222
229
|
if (entityConfig.supportsPagination && query.per_page !== -1) {
|
|
223
230
|
const response = await (0, _apiFetch.default)({
|
|
224
231
|
path,
|
|
@@ -229,6 +236,30 @@ const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
229
236
|
totalItems: parseInt(response.headers.get('X-WP-Total')),
|
|
230
237
|
totalPages: parseInt(response.headers.get('X-WP-TotalPages'))
|
|
231
238
|
};
|
|
239
|
+
} else if (query.per_page === -1 && query[_utils.RECEIVE_INTERMEDIATE_RESULTS] === true) {
|
|
240
|
+
let page = 1;
|
|
241
|
+
let totalPages;
|
|
242
|
+
do {
|
|
243
|
+
const response = await (0, _apiFetch.default)({
|
|
244
|
+
path: (0, _url.addQueryArgs)(path, {
|
|
245
|
+
page,
|
|
246
|
+
per_page: 100
|
|
247
|
+
}),
|
|
248
|
+
parse: false
|
|
249
|
+
});
|
|
250
|
+
const pageRecords = Object.values(await response.json());
|
|
251
|
+
totalPages = parseInt(response.headers.get('X-WP-TotalPages'));
|
|
252
|
+
records.push(...pageRecords);
|
|
253
|
+
registry.batch(() => {
|
|
254
|
+
dispatch.receiveEntityRecords(kind, name, records, query);
|
|
255
|
+
dispatch.finishResolutions('getEntityRecord', getResolutionsArgs(pageRecords));
|
|
256
|
+
});
|
|
257
|
+
page++;
|
|
258
|
+
} while (page <= totalPages);
|
|
259
|
+
meta = {
|
|
260
|
+
totalItems: records.length,
|
|
261
|
+
totalPages: 1
|
|
262
|
+
};
|
|
232
263
|
} else {
|
|
233
264
|
records = Object.values(await (0, _apiFetch.default)({
|
|
234
265
|
path
|
|
@@ -260,8 +291,6 @@ const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
260
291
|
// See https://github.com/WordPress/gutenberg/pull/26575
|
|
261
292
|
// See https://github.com/WordPress/gutenberg/pull/64504
|
|
262
293
|
if (!query?._fields && !query.context) {
|
|
263
|
-
const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
|
|
264
|
-
const resolutionsArgs = records.filter(record => record?.[key]).map(record => [kind, name, record[key]]);
|
|
265
294
|
const targetHints = records.filter(record => record?.[key]).map(record => ({
|
|
266
295
|
id: record[key],
|
|
267
296
|
permissions: (0, _utils.getUserPermissionsFromAllowHeader)(record?._links?.self?.[0].targetHints.allow)
|
|
@@ -283,7 +312,7 @@ const getEntityRecords = (kind, name, query = {}) => async ({
|
|
|
283
312
|
}
|
|
284
313
|
}
|
|
285
314
|
dispatch.receiveUserPermissions(receiveUserPermissionArgs);
|
|
286
|
-
dispatch.finishResolutions('getEntityRecord',
|
|
315
|
+
dispatch.finishResolutions('getEntityRecord', getResolutionsArgs(records));
|
|
287
316
|
dispatch.finishResolutions('canUser', canUserResolutionsArgs);
|
|
288
317
|
}
|
|
289
318
|
dispatch.__unstableReleaseStoreLock(lock);
|
|
@@ -350,25 +379,12 @@ const getEmbedPreview = url => async ({
|
|
|
350
379
|
exports.getEmbedPreview = getEmbedPreview;
|
|
351
380
|
const canUser = (requestedAction, resource, id) => async ({
|
|
352
381
|
dispatch,
|
|
353
|
-
registry
|
|
382
|
+
registry,
|
|
383
|
+
resolveSelect
|
|
354
384
|
}) => {
|
|
355
385
|
if (!_utils.ALLOWED_RESOURCE_ACTIONS.includes(requestedAction)) {
|
|
356
386
|
throw new Error(`'${requestedAction}' is not a valid action.`);
|
|
357
387
|
}
|
|
358
|
-
let resourcePath = null;
|
|
359
|
-
if (typeof resource === 'object') {
|
|
360
|
-
if (!resource.kind || !resource.name) {
|
|
361
|
-
throw new Error('The entity resource object is not valid.');
|
|
362
|
-
}
|
|
363
|
-
const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(resource.kind, resource.name));
|
|
364
|
-
const entityConfig = configs.find(config => config.name === resource.name && config.kind === resource.kind);
|
|
365
|
-
if (!entityConfig) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
resourcePath = entityConfig.baseURL + (resource.id ? '/' + resource.id : '');
|
|
369
|
-
} else {
|
|
370
|
-
resourcePath = `/wp/v2/${resource}` + (id ? '/' + id : '');
|
|
371
|
-
}
|
|
372
388
|
const {
|
|
373
389
|
hasStartedResolution
|
|
374
390
|
} = registry.select(_name.STORE_NAME);
|
|
@@ -383,6 +399,20 @@ const canUser = (requestedAction, resource, id) => async ({
|
|
|
383
399
|
return;
|
|
384
400
|
}
|
|
385
401
|
}
|
|
402
|
+
let resourcePath = null;
|
|
403
|
+
if (typeof resource === 'object') {
|
|
404
|
+
if (!resource.kind || !resource.name) {
|
|
405
|
+
throw new Error('The entity resource object is not valid.');
|
|
406
|
+
}
|
|
407
|
+
const configs = await resolveSelect.getEntitiesConfig(resource.kind);
|
|
408
|
+
const entityConfig = configs.find(config => config.name === resource.name && config.kind === resource.kind);
|
|
409
|
+
if (!entityConfig) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
resourcePath = entityConfig.baseURL + (resource.id ? '/' + resource.id : '');
|
|
413
|
+
} else {
|
|
414
|
+
resourcePath = `/wp/v2/${resource}` + (id ? '/' + id : '');
|
|
415
|
+
}
|
|
386
416
|
let response;
|
|
387
417
|
try {
|
|
388
418
|
response = await (0, _apiFetch.default)({
|
|
@@ -470,45 +500,7 @@ const getAutosave = (postType, postId) => async ({
|
|
|
470
500
|
}) => {
|
|
471
501
|
await resolveSelect.getAutosaves(postType, postId);
|
|
472
502
|
};
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Retrieve the frontend template used for a given link.
|
|
476
|
-
*
|
|
477
|
-
* @param {string} link Link.
|
|
478
|
-
*/
|
|
479
503
|
exports.getAutosave = getAutosave;
|
|
480
|
-
const __experimentalGetTemplateForLink = link => async ({
|
|
481
|
-
dispatch,
|
|
482
|
-
resolveSelect
|
|
483
|
-
}) => {
|
|
484
|
-
let template;
|
|
485
|
-
try {
|
|
486
|
-
// This is NOT calling a REST endpoint but rather ends up with a response from
|
|
487
|
-
// an Ajax function which has a different shape from a WP_REST_Response.
|
|
488
|
-
template = await (0, _apiFetch.default)({
|
|
489
|
-
url: (0, _url.addQueryArgs)(link, {
|
|
490
|
-
'_wp-find-template': true
|
|
491
|
-
})
|
|
492
|
-
}).then(({
|
|
493
|
-
data
|
|
494
|
-
}) => data);
|
|
495
|
-
} catch (e) {
|
|
496
|
-
// For non-FSE themes, it is possible that this request returns an error.
|
|
497
|
-
}
|
|
498
|
-
if (!template) {
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const record = await resolveSelect.getEntityRecord('postType', 'wp_template', template.id);
|
|
502
|
-
if (record) {
|
|
503
|
-
dispatch.receiveEntityRecords('postType', 'wp_template', [record], {
|
|
504
|
-
'find-template': link
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
exports.__experimentalGetTemplateForLink = __experimentalGetTemplateForLink;
|
|
509
|
-
__experimentalGetTemplateForLink.shouldInvalidate = action => {
|
|
510
|
-
return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
|
|
511
|
-
};
|
|
512
504
|
const __experimentalGetCurrentGlobalStylesId = () => async ({
|
|
513
505
|
dispatch,
|
|
514
506
|
resolveSelect
|
|
@@ -535,6 +527,7 @@ const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
|
|
|
535
527
|
dispatch
|
|
536
528
|
}) => {
|
|
537
529
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
530
|
+
// Please adjust the preloaded requests if this changes!
|
|
538
531
|
const themeGlobalStyles = await (0, _apiFetch.default)({
|
|
539
532
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}?context=view`
|
|
540
533
|
});
|
|
@@ -546,6 +539,7 @@ const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
|
|
|
546
539
|
dispatch
|
|
547
540
|
}) => {
|
|
548
541
|
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
542
|
+
// Please adjust the preloaded requests if this changes!
|
|
549
543
|
const variations = await (0, _apiFetch.default)({
|
|
550
544
|
path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations?context=view`
|
|
551
545
|
});
|
|
@@ -647,14 +641,24 @@ const getNavigationFallbackId = () => async ({
|
|
|
647
641
|
};
|
|
648
642
|
exports.getNavigationFallbackId = getNavigationFallbackId;
|
|
649
643
|
const getDefaultTemplateId = query => async ({
|
|
650
|
-
dispatch
|
|
644
|
+
dispatch,
|
|
645
|
+
registry,
|
|
646
|
+
resolveSelect
|
|
651
647
|
}) => {
|
|
652
648
|
const template = await (0, _apiFetch.default)({
|
|
653
649
|
path: (0, _url.addQueryArgs)('/wp/v2/templates/lookup', query)
|
|
654
650
|
});
|
|
651
|
+
// Wait for the the entities config to be loaded, otherwise receiving
|
|
652
|
+
// the template as an entity will not work.
|
|
653
|
+
await resolveSelect.getEntitiesConfig('postType');
|
|
655
654
|
// Endpoint may return an empty object if no template is found.
|
|
656
655
|
if (template?.id) {
|
|
657
|
-
|
|
656
|
+
registry.batch(() => {
|
|
657
|
+
dispatch.receiveDefaultTemplateId(query, template.id);
|
|
658
|
+
dispatch.receiveEntityRecords('postType', 'wp_template', [template]);
|
|
659
|
+
// Avoid further network requests.
|
|
660
|
+
dispatch.finishResolution('getEntityRecord', ['postType', 'wp_template', template.id]);
|
|
661
|
+
});
|
|
658
662
|
}
|
|
659
663
|
};
|
|
660
664
|
|
|
@@ -671,9 +675,10 @@ const getDefaultTemplateId = query => async ({
|
|
|
671
675
|
exports.getDefaultTemplateId = getDefaultTemplateId;
|
|
672
676
|
const getRevisions = (kind, name, recordKey, query = {}) => async ({
|
|
673
677
|
dispatch,
|
|
674
|
-
registry
|
|
678
|
+
registry,
|
|
679
|
+
resolveSelect
|
|
675
680
|
}) => {
|
|
676
|
-
const configs = await
|
|
681
|
+
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
677
682
|
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
678
683
|
if (!entityConfig) {
|
|
679
684
|
return;
|
|
@@ -751,9 +756,10 @@ getRevisions.shouldInvalidate = (action, kind, name, recordKey) => action.type =
|
|
|
751
756
|
* fields, fields must always include the ID.
|
|
752
757
|
*/
|
|
753
758
|
const getRevision = (kind, name, recordKey, revisionKey, query) => async ({
|
|
754
|
-
dispatch
|
|
759
|
+
dispatch,
|
|
760
|
+
resolveSelect
|
|
755
761
|
}) => {
|
|
756
|
-
const configs = await
|
|
762
|
+
const configs = await resolveSelect.getEntitiesConfig(kind);
|
|
757
763
|
const entityConfig = configs.find(config => config.name === name && config.kind === kind);
|
|
758
764
|
if (!entityConfig) {
|
|
759
765
|
return;
|
|
@@ -810,5 +816,29 @@ const getRegisteredPostMeta = postType => async ({
|
|
|
810
816
|
dispatch.receiveRegisteredPostMeta(postType, options?.schema?.properties?.meta?.properties);
|
|
811
817
|
}
|
|
812
818
|
};
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Requests entity configs for the given kind from the REST API.
|
|
822
|
+
*
|
|
823
|
+
* @param {string} kind Entity kind.
|
|
824
|
+
*/
|
|
813
825
|
exports.getRegisteredPostMeta = getRegisteredPostMeta;
|
|
826
|
+
const getEntitiesConfig = kind => async ({
|
|
827
|
+
dispatch
|
|
828
|
+
}) => {
|
|
829
|
+
const loader = _entities.additionalEntityConfigLoaders.find(l => l.kind === kind);
|
|
830
|
+
if (!loader) {
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
try {
|
|
834
|
+
const configs = await loader.loadEntities();
|
|
835
|
+
if (!configs.length) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
dispatch.addEntities(configs);
|
|
839
|
+
} catch {
|
|
840
|
+
// Do nothing if the request comes back with an API error.
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
exports.getEntitiesConfig = getEntitiesConfig;
|
|
814
844
|
//# sourceMappingURL=resolvers.js.map
|