@wordpress/core-data 7.42.0 → 7.43.2-next.v.202604091042.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 +9 -1
- package/build/entities.cjs +28 -20
- package/build/entities.cjs.map +2 -2
- package/build/hooks/index.cjs +3 -3
- package/build/hooks/index.cjs.map +1 -1
- package/build/hooks/use-entity-record.cjs +4 -4
- package/build/hooks/use-entity-record.cjs.map +2 -2
- package/build/hooks/use-entity-records.cjs +3 -3
- package/build/hooks/use-entity-records.cjs.map +2 -2
- package/build/hooks/use-query-select.cjs +2 -2
- package/build/hooks/use-query-select.cjs.map +2 -2
- package/build/hooks/use-resource-permissions.cjs +4 -4
- package/build/hooks/use-resource-permissions.cjs.map +2 -2
- package/build/private-actions.cjs +10 -0
- package/build/private-actions.cjs.map +2 -2
- package/build/private-selectors.cjs +20 -3
- package/build/private-selectors.cjs.map +2 -2
- package/build/queried-data/get-query-parts.cjs +8 -7
- package/build/queried-data/get-query-parts.cjs.map +2 -2
- package/build/queried-data/reducer.cjs +15 -9
- package/build/queried-data/reducer.cjs.map +2 -2
- package/build/queried-data/selectors.cjs +23 -22
- package/build/queried-data/selectors.cjs.map +2 -2
- package/build/reducer.cjs +16 -3
- package/build/reducer.cjs.map +2 -2
- package/build/resolvers.cjs +22 -14
- package/build/resolvers.cjs.map +2 -2
- package/build/selectors.cjs +20 -10
- package/build/selectors.cjs.map +2 -2
- package/build/utils/crdt-blocks.cjs +170 -31
- package/build/utils/crdt-blocks.cjs.map +2 -2
- package/build/utils/crdt-text.cjs +52 -0
- package/build/utils/crdt-text.cjs.map +7 -0
- package/build/utils/crdt.cjs +13 -0
- package/build/utils/crdt.cjs.map +2 -2
- package/build/utils/index.cjs +0 -3
- package/build/utils/index.cjs.map +2 -2
- package/build-module/entities.mjs +29 -20
- package/build-module/entities.mjs.map +2 -2
- package/build-module/hooks/index.mjs +6 -6
- package/build-module/hooks/index.mjs.map +2 -2
- package/build-module/hooks/use-entity-record.mjs +3 -3
- package/build-module/hooks/use-entity-record.mjs.map +2 -2
- package/build-module/hooks/use-entity-records.mjs +2 -2
- package/build-module/hooks/use-entity-records.mjs.map +2 -2
- package/build-module/hooks/use-query-select.mjs +1 -1
- package/build-module/hooks/use-query-select.mjs.map +1 -1
- package/build-module/hooks/use-resource-permissions.mjs +3 -3
- package/build-module/hooks/use-resource-permissions.mjs.map +2 -2
- package/build-module/private-actions.mjs +9 -0
- package/build-module/private-actions.mjs.map +2 -2
- package/build-module/private-selectors.mjs +19 -3
- package/build-module/private-selectors.mjs.map +2 -2
- package/build-module/queried-data/get-query-parts.mjs +8 -7
- package/build-module/queried-data/get-query-parts.mjs.map +2 -2
- package/build-module/queried-data/reducer.mjs +15 -9
- package/build-module/queried-data/reducer.mjs.map +2 -2
- package/build-module/queried-data/selectors.mjs +23 -22
- package/build-module/queried-data/selectors.mjs.map +2 -2
- package/build-module/reducer.mjs +14 -2
- package/build-module/reducer.mjs.map +2 -2
- package/build-module/resolvers.mjs +20 -13
- package/build-module/resolvers.mjs.map +2 -2
- package/build-module/selectors.mjs +20 -11
- package/build-module/selectors.mjs.map +2 -2
- package/build-module/utils/crdt-blocks.mjs +169 -31
- package/build-module/utils/crdt-blocks.mjs.map +2 -2
- package/build-module/utils/crdt-text.mjs +26 -0
- package/build-module/utils/crdt-text.mjs.map +7 -0
- package/build-module/utils/crdt.mjs +13 -0
- package/build-module/utils/crdt.mjs.map +2 -2
- package/build-module/utils/index.mjs +8 -10
- package/build-module/utils/index.mjs.map +2 -2
- package/build-types/entities.d.ts +51 -32
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/hooks/index.d.ts +3 -3
- package/build-types/hooks/index.d.ts.map +1 -1
- package/build-types/hooks/use-entity-record.d.ts +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/hooks/use-entity-records.d.ts.map +1 -1
- package/build-types/hooks/use-resource-permissions.d.ts +1 -1
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/private-actions.d.ts +10 -0
- package/build-types/private-actions.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts +11 -4
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/queried-data/get-query-parts.d.ts +11 -19
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -1
- package/build-types/queried-data/reducer.d.ts +11 -5
- package/build-types/queried-data/reducer.d.ts.map +1 -1
- package/build-types/queried-data/selectors.d.ts +5 -3
- package/build-types/queried-data/selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts +11 -0
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts +1 -0
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts +11 -0
- package/build-types/utils/crdt-blocks.d.ts.map +1 -1
- package/build-types/utils/crdt-text.d.ts +16 -0
- package/build-types/utils/crdt-text.d.ts.map +1 -0
- package/build-types/utils/crdt.d.ts +7 -0
- package/build-types/utils/crdt.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +0 -1
- package/package.json +18 -18
- package/src/entities.js +16 -8
- package/src/hooks/index.ts +3 -3
- package/src/hooks/test/use-entity-records.js +1 -1
- package/src/hooks/use-entity-record.ts +1 -1
- package/src/hooks/use-entity-records.ts +1 -1
- package/src/hooks/use-query-select.ts +1 -1
- package/src/hooks/use-resource-permissions.ts +1 -1
- package/src/private-actions.js +18 -0
- package/src/private-selectors.ts +37 -4
- package/src/queried-data/get-query-parts.js +14 -20
- package/src/queried-data/reducer.js +28 -15
- package/src/queried-data/selectors.js +34 -38
- package/src/queried-data/test/get-query-parts.js +11 -11
- package/src/queried-data/test/reducer.js +78 -8
- package/src/queried-data/test/selectors.js +52 -30
- package/src/reducer.js +20 -0
- package/src/resolvers.js +29 -13
- package/src/selectors.ts +28 -21
- package/src/utils/crdt-blocks.ts +348 -60
- package/src/utils/crdt-text.ts +43 -0
- package/src/utils/crdt.ts +25 -0
- package/src/utils/index.js +0 -1
- package/src/utils/test/crdt-blocks.ts +838 -6
- package/src/utils/test/crdt.ts +147 -1
- package/build/hooks/memoize.cjs +0 -38
- package/build/hooks/memoize.cjs.map +0 -7
- package/build/utils/is-raw-attribute.cjs +0 -29
- package/build/utils/is-raw-attribute.cjs.map +0 -7
- package/build-module/hooks/memoize.mjs +0 -7
- package/build-module/hooks/memoize.mjs.map +0 -7
- package/build-module/utils/is-raw-attribute.mjs +0 -8
- package/build-module/utils/is-raw-attribute.mjs.map +0 -7
- package/build-types/hooks/memoize.d.ts +0 -3
- package/build-types/hooks/memoize.d.ts.map +0 -1
- package/build-types/utils/is-raw-attribute.d.ts +0 -10
- package/build-types/utils/is-raw-attribute.d.ts.map +0 -1
- package/src/hooks/memoize.js +0 -7
- package/src/utils/is-raw-attribute.js +0 -11
- package/src/utils/test/is-raw-attribute.js +0 -22
|
@@ -34,6 +34,7 @@ __export(private_actions_exports, {
|
|
|
34
34
|
receiveEditorAssets: () => receiveEditorAssets,
|
|
35
35
|
receiveEditorSettings: () => receiveEditorSettings,
|
|
36
36
|
receiveRegisteredPostMeta: () => receiveRegisteredPostMeta,
|
|
37
|
+
receiveViewConfig: () => receiveViewConfig,
|
|
37
38
|
setCollaborationSupported: () => setCollaborationSupported
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(private_actions_exports);
|
|
@@ -129,12 +130,21 @@ function receiveEditorAssets(assets) {
|
|
|
129
130
|
var setCollaborationSupported = (supported) => ({ dispatch }) => {
|
|
130
131
|
dispatch({ type: "SET_COLLABORATION_SUPPORTED", supported });
|
|
131
132
|
};
|
|
133
|
+
function receiveViewConfig(kind, name, config) {
|
|
134
|
+
return {
|
|
135
|
+
type: "RECEIVE_VIEW_CONFIG",
|
|
136
|
+
kind,
|
|
137
|
+
name,
|
|
138
|
+
config
|
|
139
|
+
};
|
|
140
|
+
}
|
|
132
141
|
// Annotate the CommonJS export names for ESM import in node:
|
|
133
142
|
0 && (module.exports = {
|
|
134
143
|
editMediaEntity,
|
|
135
144
|
receiveEditorAssets,
|
|
136
145
|
receiveEditorSettings,
|
|
137
146
|
receiveRegisteredPostMeta,
|
|
147
|
+
receiveViewConfig,
|
|
138
148
|
setCollaborationSupported
|
|
139
149
|
});
|
|
140
150
|
//# sourceMappingURL=private-actions.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/private-actions.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\n/**\n * Returns an action object used in signalling that the registered post meta\n * fields for a post type have been received.\n *\n * @param {string} postType Post type slug.\n * @param {Object} registeredPostMeta Registered post meta.\n *\n * @return {Object} Action object.\n */\nexport function receiveRegisteredPostMeta( postType, registeredPostMeta ) {\n\treturn {\n\t\ttype: 'RECEIVE_REGISTERED_POST_META',\n\t\tpostType,\n\t\tregisteredPostMeta,\n\t};\n}\n\n/**\n * @typedef {Object} Modifier\n * @property {string} [type] - The type of modifier.\n * @property {Object} [args] - The arguments of the modifier.\n */\n\n/**\n * @typedef {Object} Edits\n * @property {string} [src] - The URL of the media item.\n * @property {Modifier[]} [modifiers] - The modifiers to apply to the media item.\n */\n\n/**\n * Duplicates a media (attachment) entity record and, optionally, modifies it.\n *\n * @param {string} recordId Entity record ID.\n * @param {Edits} edits Edits to apply to the record.\n * @param {Object} options Options object.\n * @param {Function} options.__unstableFetch Custom fetch function.\n * @param {boolean} options.throwOnError Whether to throw an error if the request fails.\n *\n * @return {Promise} Promise resolving to the updated record.\n */\nexport const editMediaEntity =\n\t(\n\t\trecordId,\n\t\tedits = {},\n\t\t{ __unstableFetch = apiFetch, throwOnError = false } = {}\n\t) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tif ( ! recordId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst kind = 'postType';\n\t\tconst name = 'attachment';\n\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordId ],\n\t\t\t{ exclusive: true }\n\t\t);\n\n\t\tlet updatedRecord;\n\t\tlet error;\n\t\tlet hasError = false;\n\n\t\ttry {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_START',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t} );\n\n\t\t\ttry {\n\t\t\t\tconst path = `${ entityConfig.baseURL }/${ recordId }/edit`;\n\t\t\t\tconst newRecord = await __unstableFetch( {\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t...edits,\n\t\t\t\t\t},\n\t\t\t\t} );\n\n\t\t\t\tif ( newRecord ) {\n\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tnewRecord,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tundefined\n\t\t\t\t\t);\n\t\t\t\t\tupdatedRecord = newRecord;\n\t\t\t\t}\n\t\t\t} catch ( e ) {\n\t\t\t\terror = e;\n\t\t\t\thasError = true;\n\t\t\t}\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_FINISH',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\terror,\n\t\t\t} );\n\n\t\t\tif ( hasError && throwOnError ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn updatedRecord;\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Returns an action object used to receive editor settings.\n *\n * @param {Object} settings Editor settings object.\n *\n * @return {Object} Action object.\n */\nexport function receiveEditorSettings( settings ) {\n\treturn {\n\t\ttype: 'RECEIVE_EDITOR_SETTINGS',\n\t\tsettings,\n\t};\n}\n\n/**\n * Returns an action object used to receive editor assets.\n *\n * @param {Object} assets Editor assets object.\n *\n * @return {Object} Action object.\n */\nexport function receiveEditorAssets( assets ) {\n\treturn {\n\t\ttype: 'RECEIVE_EDITOR_ASSETS',\n\t\tassets,\n\t};\n}\n\n/**\n * Returns an action object used to set whether collaboration is supported.\n *\n * @param {boolean} supported Whether collaboration is supported.\n *\n * @return {Object} Action object.\n */\nexport const setCollaborationSupported =\n\t( supported ) =>\n\t( { dispatch } ) => {\n\t\tdispatch( { type: 'SET_COLLABORATION_SUPPORTED', supported } );\n\t};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAKrB,kBAA2B;AAWpB,SAAS,0BAA2B,UAAU,oBAAqB;AACzE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAyBO,IAAM,kBACZ,CACC,UACA,QAAQ,CAAC,GACT,EAAE,kBAAkB,iBAAAA,SAAU,eAAe,MAAM,IAAI,CAAC,MAEzD,OAAQ,EAAE,UAAU,cAAc,MAAO;AACxC,MAAK,CAAE,UAAW;AACjB;AAAA,EACD;AAEA,QAAM,OAAO;AACb,QAAM,OAAO;AAEb,QAAM,UAAU,MAAM,cAAc,kBAAmB,IAAK;AAC5D,QAAM,eAAe,QAAQ;AAAA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",
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\n\n/**\n * Returns an action object used in signalling that the registered post meta\n * fields for a post type have been received.\n *\n * @param {string} postType Post type slug.\n * @param {Object} registeredPostMeta Registered post meta.\n *\n * @return {Object} Action object.\n */\nexport function receiveRegisteredPostMeta( postType, registeredPostMeta ) {\n\treturn {\n\t\ttype: 'RECEIVE_REGISTERED_POST_META',\n\t\tpostType,\n\t\tregisteredPostMeta,\n\t};\n}\n\n/**\n * @typedef {Object} Modifier\n * @property {string} [type] - The type of modifier.\n * @property {Object} [args] - The arguments of the modifier.\n */\n\n/**\n * @typedef {Object} Edits\n * @property {string} [src] - The URL of the media item.\n * @property {Modifier[]} [modifiers] - The modifiers to apply to the media item.\n */\n\n/**\n * Duplicates a media (attachment) entity record and, optionally, modifies it.\n *\n * @param {string} recordId Entity record ID.\n * @param {Edits} edits Edits to apply to the record.\n * @param {Object} options Options object.\n * @param {Function} options.__unstableFetch Custom fetch function.\n * @param {boolean} options.throwOnError Whether to throw an error if the request fails.\n *\n * @return {Promise} Promise resolving to the updated record.\n */\nexport const editMediaEntity =\n\t(\n\t\trecordId,\n\t\tedits = {},\n\t\t{ __unstableFetch = apiFetch, throwOnError = false } = {}\n\t) =>\n\tasync ( { dispatch, resolveSelect } ) => {\n\t\tif ( ! recordId ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst kind = 'postType';\n\t\tconst name = 'attachment';\n\n\t\tconst configs = await resolveSelect.getEntitiesConfig( kind );\n\t\tconst entityConfig = configs.find(\n\t\t\t( config ) => config.kind === kind && config.name === name\n\t\t);\n\n\t\tif ( ! entityConfig ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\t\tSTORE_NAME,\n\t\t\t[ 'entities', 'records', kind, name, recordId ],\n\t\t\t{ exclusive: true }\n\t\t);\n\n\t\tlet updatedRecord;\n\t\tlet error;\n\t\tlet hasError = false;\n\n\t\ttry {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_START',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t} );\n\n\t\t\ttry {\n\t\t\t\tconst path = `${ entityConfig.baseURL }/${ recordId }/edit`;\n\t\t\t\tconst newRecord = await __unstableFetch( {\n\t\t\t\t\tpath,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\t...edits,\n\t\t\t\t\t},\n\t\t\t\t} );\n\n\t\t\t\tif ( newRecord ) {\n\t\t\t\t\tdispatch.receiveEntityRecords(\n\t\t\t\t\t\tkind,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tnewRecord,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tundefined\n\t\t\t\t\t);\n\t\t\t\t\tupdatedRecord = newRecord;\n\t\t\t\t}\n\t\t\t} catch ( e ) {\n\t\t\t\terror = e;\n\t\t\t\thasError = true;\n\t\t\t}\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'SAVE_ENTITY_RECORD_FINISH',\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId,\n\t\t\t\terror,\n\t\t\t} );\n\n\t\t\tif ( hasError && throwOnError ) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn updatedRecord;\n\t\t} finally {\n\t\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t\t}\n\t};\n\n/**\n * Returns an action object used to receive editor settings.\n *\n * @param {Object} settings Editor settings object.\n *\n * @return {Object} Action object.\n */\nexport function receiveEditorSettings( settings ) {\n\treturn {\n\t\ttype: 'RECEIVE_EDITOR_SETTINGS',\n\t\tsettings,\n\t};\n}\n\n/**\n * Returns an action object used to receive editor assets.\n *\n * @param {Object} assets Editor assets object.\n *\n * @return {Object} Action object.\n */\nexport function receiveEditorAssets( assets ) {\n\treturn {\n\t\ttype: 'RECEIVE_EDITOR_ASSETS',\n\t\tassets,\n\t};\n}\n\n/**\n * Returns an action object used to set whether collaboration is supported.\n *\n * @param {boolean} supported Whether collaboration is supported.\n *\n * @return {Object} Action object.\n */\nexport const setCollaborationSupported =\n\t( supported ) =>\n\t( { dispatch } ) => {\n\t\tdispatch( { type: 'SET_COLLABORATION_SUPPORTED', supported } );\n\t};\n\n/**\n * Returns an action object used to receive view config.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object} config View config object.\n *\n * @return {Object} Action object.\n */\nexport function receiveViewConfig( kind, name, config ) {\n\treturn {\n\t\ttype: 'RECEIVE_VIEW_CONFIG',\n\t\tkind,\n\t\tname,\n\t\tconfig,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAKrB,kBAA2B;AAWpB,SAAS,0BAA2B,UAAU,oBAAqB;AACzE,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACD;AACD;AAyBO,IAAM,kBACZ,CACC,UACA,QAAQ,CAAC,GACT,EAAE,kBAAkB,iBAAAA,SAAU,eAAe,MAAM,IAAI,CAAC,MAEzD,OAAQ,EAAE,UAAU,cAAc,MAAO;AACxC,MAAK,CAAE,UAAW;AACjB;AAAA,EACD;AAEA,QAAM,OAAO;AACb,QAAM,OAAO;AAEb,QAAM,UAAU,MAAM,cAAc,kBAAmB,IAAK;AAC5D,QAAM,eAAe,QAAQ;AAAA,IAC5B,CAAE,WAAY,OAAO,SAAS,QAAQ,OAAO,SAAS;AAAA,EACvD;AAEA,MAAK,CAAE,cAAe;AACrB;AAAA,EACD;AAEA,QAAM,OAAO,MAAM,SAAS;AAAA,IAC3B;AAAA,IACA,CAAE,YAAY,WAAW,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,7 @@ __export(private_selectors_exports, {
|
|
|
41
41
|
getRegisteredPostMeta: () => getRegisteredPostMeta,
|
|
42
42
|
getTemplateId: () => getTemplateId,
|
|
43
43
|
getUndoManager: () => getUndoManager,
|
|
44
|
+
getViewConfig: () => getViewConfig,
|
|
44
45
|
isCollaborationSupported: () => isCollaborationSupported
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(private_selectors_exports);
|
|
@@ -50,6 +51,7 @@ var import_name = require("./name.cjs");
|
|
|
50
51
|
var import_lock_unlock = require("./lock-unlock.cjs");
|
|
51
52
|
var import_sync = require("./sync.cjs");
|
|
52
53
|
var import_log_entity_deprecation = __toESM(require("./utils/log-entity-deprecation.cjs"));
|
|
54
|
+
var EMPTY_OBJECT = {};
|
|
53
55
|
function getUndoManager(state) {
|
|
54
56
|
return (0, import_sync.getSyncManager)()?.undoManager ?? state.undoManager;
|
|
55
57
|
}
|
|
@@ -119,10 +121,16 @@ var getHomePage = (0, import_data.createRegistrySelector)(
|
|
|
119
121
|
).getDefaultTemplateId({
|
|
120
122
|
slug: "front-page"
|
|
121
123
|
});
|
|
122
|
-
if (
|
|
123
|
-
return
|
|
124
|
+
if (frontPageTemplateId) {
|
|
125
|
+
return {
|
|
126
|
+
postType: "wp_template",
|
|
127
|
+
postId: frontPageTemplateId
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (frontPageTemplateId === "") {
|
|
131
|
+
return EMPTY_OBJECT;
|
|
124
132
|
}
|
|
125
|
-
return
|
|
133
|
+
return null;
|
|
126
134
|
},
|
|
127
135
|
(state) => [
|
|
128
136
|
// Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,
|
|
@@ -207,6 +215,14 @@ function getEditorAssets(state) {
|
|
|
207
215
|
function isCollaborationSupported(state) {
|
|
208
216
|
return state.collaborationSupported;
|
|
209
217
|
}
|
|
218
|
+
function getViewConfig(state, kind, name) {
|
|
219
|
+
return state.viewConfigs?.[`${kind}/${name}`] ?? {
|
|
220
|
+
default_view: void 0,
|
|
221
|
+
default_layouts: void 0,
|
|
222
|
+
view_list: void 0,
|
|
223
|
+
form: void 0
|
|
224
|
+
};
|
|
225
|
+
}
|
|
210
226
|
// Annotate the CommonJS export names for ESM import in node:
|
|
211
227
|
0 && (module.exports = {
|
|
212
228
|
getBlockPatternsForPostType,
|
|
@@ -220,6 +236,7 @@ function isCollaborationSupported(state) {
|
|
|
220
236
|
getRegisteredPostMeta,
|
|
221
237
|
getTemplateId,
|
|
222
238
|
getUndoManager,
|
|
239
|
+
getViewConfig,
|
|
223
240
|
isCollaborationSupported
|
|
224
241
|
});
|
|
225
242
|
//# sourceMappingURL=private-selectors.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/private-selectors.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getDefaultTemplateId, getEntityRecord, type State } from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { getSyncManager } from './sync';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\ntype EntityRecordKey = string | number;\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * Known Issue: Every-time state.undoManager changes, the getUndoManager\n * private selector is called (if used within useSelect and things like that)\n * which ensures the UI is always properly reactive. But, it's not the case with\n * the custom \"sync\" undo manager.\n *\n * Assumption: When an undo/redo is created, other parts of the core-data state\n * are likely changing simultaneously, which will trigger the selectors again.\n *\n * This issue is acceptable based on the assumption above.\n *\n * @see https://github.com/WordPress/gutenberg/pull/72407/files#r2580214235 for more details.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\t// undoManager is undefined until the first sync-enabled entity is loaded.\n\treturn getSyncManager()?.undoManager ?? state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t(\n\t\t\tstate: State,\n\t\t\tkind: string,\n\t\t\tname: string,\n\t\t\tids: string | string[]\n\t\t) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\tlogEntityDeprecation( kind, name, 'getEntityRecordPermissions' );\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'__unstableBase'\n\t\t\t) as SiteData | undefined;\n\t\t\t// Still resolving getEntityRecord.\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\t// Still resolving getDefaultTemplateId.\n\t\t\tif ( ! frontPageTemplateId ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn { postType: 'wp_template', postId: frontPageTemplateId };\n\t\t},\n\t\t( state ) => [\n\t\t\t// Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,\n\t\t\t// it doesn't seem to invalidate this cache, I'm not sure why.\n\t\t\tgetEntityRecord( state, 'root', 'site' ),\n\t\t\tgetEntityRecord( state, 'root', '__unstableBase' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t'root',\n\t\t'__unstableBase'\n\t) as SiteData | undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst currentTemplate = select( STORE_NAME )\n\t\t\t\t.getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} )\n\t\t\t\t?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\tif ( currentTemplate ) {\n\t\t\t\treturn currentTemplate.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n\n/**\n * Returns the editor settings.\n *\n * @param state Data state.\n * @return Editor settings object or null if not loaded.\n */\nexport function getEditorSettings(\n\tstate: State\n): Record< string, any > | null {\n\treturn state.editorSettings;\n}\n\n/**\n * Returns the editor assets.\n *\n * @param state Data state.\n * @return Editor assets object or null if not loaded.\n */\nexport function getEditorAssets( state: State ): Record< string, any > | null {\n\treturn state.editorAssets;\n}\n\n/**\n * Returns whether collaboration is supported.\n *\n * @param state Data state.\n * @return Whether collaboration is supported.\n */\nexport function isCollaborationSupported( state: State ): boolean {\n\treturn state.collaborationSupported;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuD;AAKvD,uBAAkE;AAClE,kBAA2B;AAC3B,yBAAuB;AACvB,kBAA+B;AAC/B,oCAAiC;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createSelector, createRegistrySelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { getDefaultTemplateId, getEntityRecord, type State } from './selectors';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { getSyncManager } from './sync';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\n\ntype EntityRecordKey = string | number;\n\nconst EMPTY_OBJECT = {};\n\n/**\n * Returns the previous edit from the current undo offset\n * for the entity records edits history, if any.\n *\n * Known Issue: Every-time state.undoManager changes, the getUndoManager\n * private selector is called (if used within useSelect and things like that)\n * which ensures the UI is always properly reactive. But, it's not the case with\n * the custom \"sync\" undo manager.\n *\n * Assumption: When an undo/redo is created, other parts of the core-data state\n * are likely changing simultaneously, which will trigger the selectors again.\n *\n * This issue is acceptable based on the assumption above.\n *\n * @see https://github.com/WordPress/gutenberg/pull/72407/files#r2580214235 for more details.\n *\n * @param state State tree.\n *\n * @return The undo manager.\n */\nexport function getUndoManager( state: State ) {\n\t// undoManager is undefined until the first sync-enabled entity is loaded.\n\treturn getSyncManager()?.undoManager ?? state.undoManager;\n}\n\n/**\n * Retrieve the fallback Navigation.\n *\n * @param state Data state.\n * @return The ID for the fallback Navigation post.\n */\nexport function getNavigationFallbackId(\n\tstate: State\n): EntityRecordKey | undefined {\n\treturn state.navigationFallbackId;\n}\n\nexport const getBlockPatternsForPostType = createRegistrySelector(\n\t( select: any ) =>\n\t\tcreateSelector(\n\t\t\t( state, postType ) =>\n\t\t\t\tselect( STORE_NAME )\n\t\t\t\t\t.getBlockPatterns()\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t( { postTypes } ) =>\n\t\t\t\t\t\t\t! postTypes ||\n\t\t\t\t\t\t\t( Array.isArray( postTypes ) &&\n\t\t\t\t\t\t\t\tpostTypes.includes( postType ) )\n\t\t\t\t\t),\n\t\t\t() => [ select( STORE_NAME ).getBlockPatterns() ]\n\t\t)\n);\n\n/**\n * Returns the entity records permissions for the given entity record ids.\n */\nexport const getEntityRecordsPermissions = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t(\n\t\t\tstate: State,\n\t\t\tkind: string,\n\t\t\tname: string,\n\t\t\tids: string | string[]\n\t\t) => {\n\t\t\tconst normalizedIds = Array.isArray( ids ) ? ids : [ ids ];\n\t\t\treturn normalizedIds.map( ( id ) => ( {\n\t\t\t\tdelete: select( STORE_NAME ).canUser( 'delete', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t\tupdate: select( STORE_NAME ).canUser( 'update', {\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\tid,\n\t\t\t\t} ),\n\t\t\t} ) );\n\t\t},\n\t\t( state ) => [ state.userPermissions ]\n\t)\n);\n\n/**\n * Returns the entity record permissions for the given entity record id.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n * @param id Entity record id.\n *\n * @return The entity record permissions.\n */\nexport function getEntityRecordPermissions(\n\tstate: State,\n\tkind: string,\n\tname: string,\n\tid: string\n) {\n\tlogEntityDeprecation( kind, name, 'getEntityRecordPermissions' );\n\treturn getEntityRecordsPermissions( state, kind, name, id )[ 0 ];\n}\n\n/**\n * Returns the registered post meta fields for a given post type.\n *\n * @param state Data state.\n * @param postType Post type.\n *\n * @return Registered post meta fields.\n */\nexport function getRegisteredPostMeta( state: State, postType: string ) {\n\treturn state.registeredPostMeta?.[ postType ] ?? {};\n}\n\nfunction normalizePageId( value: number | string | undefined ): string | null {\n\tif ( ! value || ! [ 'number', 'string' ].includes( typeof value ) ) {\n\t\treturn null;\n\t}\n\n\t// We also need to check if it's not zero (`'0'`).\n\tif ( Number( value ) === 0 ) {\n\t\treturn null;\n\t}\n\n\treturn value.toString();\n}\n\ninterface SiteData {\n\tshow_on_front?: string;\n\tpage_on_front?: string | number;\n\tpage_for_posts?: string | number;\n}\n\nexport const getHomePage = createRegistrySelector( ( select ) =>\n\tcreateSelector(\n\t\t() => {\n\t\t\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t\t\t'root',\n\t\t\t\t'__unstableBase'\n\t\t\t) as SiteData | undefined;\n\t\t\t// Still resolving getEntityRecord.\n\t\t\tif ( ! siteData ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst homepageId =\n\t\t\t\tsiteData?.show_on_front === 'page'\n\t\t\t\t\t? normalizePageId( siteData.page_on_front )\n\t\t\t\t\t: null;\n\t\t\tif ( homepageId ) {\n\t\t\t\treturn { postType: 'page', postId: homepageId };\n\t\t\t}\n\t\t\tconst frontPageTemplateId = select(\n\t\t\t\tSTORE_NAME\n\t\t\t).getDefaultTemplateId( {\n\t\t\t\tslug: 'front-page',\n\t\t\t} );\n\t\t\tif ( frontPageTemplateId ) {\n\t\t\t\treturn {\n\t\t\t\t\tpostType: 'wp_template',\n\t\t\t\t\tpostId: frontPageTemplateId,\n\t\t\t\t};\n\t\t\t}\n\t\t\t// Resolution is finished and no front-page template exists.\n\t\t\tif ( frontPageTemplateId === '' ) {\n\t\t\t\treturn EMPTY_OBJECT;\n\t\t\t}\n\t\t\t// Still resolving getDefaultTemplateId.\n\t\t\treturn null;\n\t\t},\n\t\t( state ) => [\n\t\t\t// Even though getDefaultTemplateId.shouldInvalidate returns true when root/site changes,\n\t\t\t// it doesn't seem to invalidate this cache, I'm not sure why.\n\t\t\tgetEntityRecord( state, 'root', 'site' ),\n\t\t\tgetEntityRecord( state, 'root', '__unstableBase' ),\n\t\t\tgetDefaultTemplateId( state, {\n\t\t\t\tslug: 'front-page',\n\t\t\t} ),\n\t\t]\n\t)\n);\n\nexport const getPostsPageId = createRegistrySelector( ( select ) => () => {\n\tconst siteData = select( STORE_NAME ).getEntityRecord(\n\t\t'root',\n\t\t'__unstableBase'\n\t) as SiteData | undefined;\n\treturn siteData?.show_on_front === 'page'\n\t\t? normalizePageId( siteData.page_for_posts )\n\t\t: null;\n} );\n\nexport const getTemplateId = createRegistrySelector(\n\t( select ) => ( state, postType, postId ) => {\n\t\tconst homepage = unlock( select( STORE_NAME ) ).getHomePage();\n\n\t\tif ( ! homepage ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// For the front page, we always use the front page template if existing.\n\t\tif (\n\t\t\tpostType === 'page' &&\n\t\t\tpostType === homepage?.postType &&\n\t\t\tpostId.toString() === homepage?.postId\n\t\t) {\n\t\t\t// The /lookup endpoint cannot currently handle a lookup\n\t\t\t// when a page is set as the front page, so specifically in\n\t\t\t// that case, we want to check if there is a front page\n\t\t\t// template, and instead of falling back to the home\n\t\t\t// template, we want to fall back to the page template.\n\t\t\tconst templates = select( STORE_NAME ).getEntityRecords(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t}\n\t\t\t);\n\t\t\tif ( ! templates ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst id = templates.find( ( { slug } ) => slug === 'front-page' )\n\t\t\t\t?.id;\n\t\t\tif ( id ) {\n\t\t\t\treturn id;\n\t\t\t}\n\t\t\t// If no front page template is found, continue with the\n\t\t\t// logic below (fetching the page template).\n\t\t}\n\n\t\tconst editedEntity = select( STORE_NAME ).getEditedEntityRecord(\n\t\t\t'postType',\n\t\t\tpostType,\n\t\t\tpostId\n\t\t);\n\t\tif ( ! editedEntity ) {\n\t\t\treturn;\n\t\t}\n\t\tconst postsPageId = unlock( select( STORE_NAME ) ).getPostsPageId();\n\t\t// Check if the current page is the posts page.\n\t\tif ( postType === 'page' && postsPageId === postId.toString() ) {\n\t\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\t\tslug: 'home',\n\t\t\t} );\n\t\t}\n\t\t// First see if the post/page has an assigned template and fetch it.\n\t\tconst currentTemplateSlug = editedEntity.template;\n\t\tif ( currentTemplateSlug ) {\n\t\t\tconst currentTemplate = select( STORE_NAME )\n\t\t\t\t.getEntityRecords( 'postType', 'wp_template', {\n\t\t\t\t\tper_page: -1,\n\t\t\t\t} )\n\t\t\t\t?.find( ( { slug } ) => slug === currentTemplateSlug );\n\t\t\tif ( currentTemplate ) {\n\t\t\t\treturn currentTemplate.id;\n\t\t\t}\n\t\t}\n\t\t// If no template is assigned, use the default template.\n\t\tlet slugToCheck;\n\t\t// In `draft` status we might not have a slug available, so we use the `single`\n\t\t// post type templates slug(ex page, single-post, single-product etc..).\n\t\t// Pages do not need the `single` prefix in the slug to be prioritized\n\t\t// through template hierarchy.\n\t\tif ( editedEntity.slug ) {\n\t\t\tslugToCheck =\n\t\t\t\tpostType === 'page'\n\t\t\t\t\t? `${ postType }-${ editedEntity.slug }`\n\t\t\t\t\t: `single-${ postType }-${ editedEntity.slug }`;\n\t\t} else {\n\t\t\tslugToCheck = postType === 'page' ? 'page' : `single-${ postType }`;\n\t\t}\n\t\treturn select( STORE_NAME ).getDefaultTemplateId( {\n\t\t\tslug: slugToCheck,\n\t\t} );\n\t}\n);\n\n/**\n * Returns the editor settings.\n *\n * @param state Data state.\n * @return Editor settings object or null if not loaded.\n */\nexport function getEditorSettings(\n\tstate: State\n): Record< string, any > | null {\n\treturn state.editorSettings;\n}\n\n/**\n * Returns the editor assets.\n *\n * @param state Data state.\n * @return Editor assets object or null if not loaded.\n */\nexport function getEditorAssets( state: State ): Record< string, any > | null {\n\treturn state.editorAssets;\n}\n\n/**\n * Returns whether collaboration is supported.\n *\n * @param state Data state.\n * @return Whether collaboration is supported.\n */\nexport function isCollaborationSupported( state: State ): boolean {\n\treturn state.collaborationSupported;\n}\n\n/**\n * Returns the view configuration for the given entity type.\n *\n * @param state Data state.\n * @param kind Entity kind.\n * @param name Entity name.\n *\n * @return The view configuration or undefined if not loaded.\n */\nexport function getViewConfig(\n\tstate: State,\n\tkind: string,\n\tname: string\n): Record< string, any > | undefined {\n\treturn (\n\t\tstate.viewConfigs?.[ `${ kind }/${ name }` ] ?? {\n\t\t\tdefault_view: undefined,\n\t\t\tdefault_layouts: undefined,\n\t\t\tview_list: undefined,\n\t\t\tform: undefined,\n\t\t}\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAuD;AAKvD,uBAAkE;AAClE,kBAA2B;AAC3B,yBAAuB;AACvB,kBAA+B;AAC/B,oCAAiC;AAIjC,IAAM,eAAe,CAAC;AAsBf,SAAS,eAAgB,OAAe;AAE9C,aAAO,4BAAe,GAAG,eAAe,MAAM;AAC/C;AAQO,SAAS,wBACf,OAC8B;AAC9B,SAAO,MAAM;AACd;AAEO,IAAM,kCAA8B;AAAA,EAC1C,CAAE,eACD;AAAA,IACC,CAAE,OAAO,aACR,OAAQ,sBAAW,EACjB,iBAAiB,EACjB;AAAA,MACA,CAAE,EAAE,UAAU,MACb,CAAE,aACA,MAAM,QAAS,SAAU,KAC1B,UAAU,SAAU,QAAS;AAAA,IAChC;AAAA,IACF,MAAM,CAAE,OAAQ,sBAAW,EAAE,iBAAiB,CAAE;AAAA,EACjD;AACF;AAKO,IAAM,kCAA8B;AAAA,EAAwB,CAAE,eACpE;AAAA,IACC,CACC,OACA,MACA,MACA,QACI;AACJ,YAAM,gBAAgB,MAAM,QAAS,GAAI,IAAI,MAAM,CAAE,GAAI;AACzD,aAAO,cAAc,IA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,GAAI;AAC/D,aAAO,OAAQ,sBAAW,EAAE,qBAAsB;AAAA,QACjD,MAAM;AAAA,MACP,CAAE;AAAA,IACH;AAEA,UAAM,sBAAsB,aAAa;AACzC,QAAK,qBAAsB;AAC1B,YAAM,kBAAkB,OAAQ,sBAAW,EACzC,iBAAkB,YAAY,eAAe;AAAA,QAC7C,UAAU;AAAA,MACX,CAAE,GACA,KAAM,CAAE,EAAE,KAAK,MAAO,SAAS,mBAAoB;AACtD,UAAK,iBAAkB;AACtB,eAAO,gBAAgB;AAAA,MACxB;AAAA,IACD;AAEA,QAAI;AAKJ,QAAK,aAAa,MAAO;AACxB,oBACC,aAAa,SACV,GAAI,QAAS,IAAK,aAAa,IAAK,KACpC,UAAW,QAAS,IAAK,aAAa,IAAK;AAAA,IAChD,OAAO;AACN,oBAAc,aAAa,SAAS,SAAS,UAAW,QAAS;AAAA,IAClE;AACA,WAAO,OAAQ,sBAAW,EAAE,qBAAsB;AAAA,MACjD,MAAM;AAAA,IACP,CAAE;AAAA,EACH;AACD;AAQO,SAAS,kBACf,OAC+B;AAC/B,SAAO,MAAM;AACd;AAQO,SAAS,gBAAiB,OAA6C;AAC7E,SAAO,MAAM;AACd;AAQO,SAAS,yBAA0B,OAAwB;AACjE,SAAO,MAAM;AACd;AAWO,SAAS,cACf,OACA,MACA,MACoC;AACpC,SACC,MAAM,cAAe,GAAI,IAAK,IAAK,IAAK,EAAG,KAAK;AAAA,IAC/C,cAAc;AAAA,IACd,iBAAiB;AAAA,IACjB,WAAW;AAAA,IACX,MAAM;AAAA,EACP;AAEF;",
|
|
6
6
|
"names": ["logEntityDeprecation"]
|
|
7
7
|
}
|
|
@@ -31,7 +31,7 @@ function getQueryParts(query) {
|
|
|
31
31
|
stableKey: "",
|
|
32
32
|
page: 1,
|
|
33
33
|
perPage: 10,
|
|
34
|
-
offset:
|
|
34
|
+
offset: null,
|
|
35
35
|
fields: null,
|
|
36
36
|
include: null,
|
|
37
37
|
context: "default"
|
|
@@ -47,16 +47,17 @@ function getQueryParts(query) {
|
|
|
47
47
|
case "per_page":
|
|
48
48
|
parts.perPage = Number(value);
|
|
49
49
|
break;
|
|
50
|
+
case "offset": {
|
|
51
|
+
const numericOffset = Number(value);
|
|
52
|
+
if (Number.isFinite(numericOffset)) {
|
|
53
|
+
parts.offset = numericOffset;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
50
57
|
case "context":
|
|
51
58
|
parts.context = value;
|
|
52
59
|
break;
|
|
53
60
|
default:
|
|
54
|
-
if (key === "offset") {
|
|
55
|
-
const numericOffset = Number(value);
|
|
56
|
-
if (Number.isFinite(numericOffset)) {
|
|
57
|
-
parts.offset = numericOffset;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
61
|
if (key === "_fields") {
|
|
61
62
|
parts.fields = (0, import_utils.getNormalizedCommaSeparable)(value) ?? [];
|
|
62
63
|
value = parts.fields.join();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/queried-data/get-query-parts.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {number}
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA6B;AAK7B,mBAA8D;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {?number} offset Absolute item offset (default null).\n * @property {string} stableKey An encoded stable string of all non-pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from item objects (default null).\n * @property {?(number[])} include Specific item IDs to include (default null).\n * @property {string} context Scope under which the request is made; determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\toffset: null,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'offset': {\n\t\t\t\tconst numericOffset = Number( value );\n\t\t\t\tif ( Number.isFinite( numericOffset ) ) {\n\t\t\t\t\tparts.offset = numericOffset;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitly asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value ) ?? [];\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tif ( typeof value === 'number' ) {\n\t\t\t\t\t\tvalue = value.toString();\n\t\t\t\t\t}\n\t\t\t\t\tparts.include = (\n\t\t\t\t\t\tgetNormalizedCommaSeparable( value ) ?? []\n\t\t\t\t\t).map( Number );\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA6B;AAK7B,mBAA8D;AAyBvD,SAAS,cAAe,OAAQ;AAItC,QAAM,QAAQ;AAAA,IACb,WAAW;AAAA,IACX,MAAM;AAAA,IACN,SAAS;AAAA,IACT,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,EACV;AAGA,QAAM,OAAO,OAAO,KAAM,KAAM,EAAE,KAAK;AAEvC,WAAU,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAM;AACvC,UAAM,MAAM,KAAM,CAAE;AACpB,QAAI,QAAQ,MAAO,GAAI;AAEvB,YAAS,KAAM;AAAA,MACd,KAAK;AACJ,cAAO,GAAI,IAAI,OAAQ,KAAM;AAC7B;AAAA,MAED,KAAK;AACJ,cAAM,UAAU,OAAQ,KAAM;AAC9B;AAAA,MAED,KAAK,UAAU;AACd,cAAM,gBAAgB,OAAQ,KAAM;AACpC,YAAK,OAAO,SAAU,aAAc,GAAI;AACvC,gBAAM,SAAS;AAAA,QAChB;AACA;AAAA,MACD;AAAA,MAEA,KAAK;AACJ,cAAM,UAAU;AAChB;AAAA,MAED;AAMC,YAAK,QAAQ,WAAY;AACxB,gBAAM,aAAS,0CAA6B,KAAM,KAAK,CAAC;AAExD,kBAAQ,MAAM,OAAO,KAAK;AAAA,QAC3B;AAGA,YAAK,QAAQ,WAAY;AACxB,cAAK,OAAO,UAAU,UAAW;AAChC,oBAAQ,MAAM,SAAS;AAAA,UACxB;AACA,gBAAM,eACL,0CAA6B,KAAM,KAAK,CAAC,GACxC,IAAK,MAAO;AAEd,kBAAQ,MAAM,QAAQ,KAAK;AAAA,QAC5B;AASA,cAAM,cACH,MAAM,YAAY,MAAM,UAC1B,yBAAc,IAAI,EAAE,CAAE,GAAI,GAAG,MAAM,CAAE,EAAE,MAAO,CAAE;AAAA,IACnD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,IAAO,8BAAQ,+BAAkB,aAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -49,20 +49,23 @@ function getContextFromAction(action) {
|
|
|
49
49
|
const queryParts = (0, import_get_query_parts.default)(query);
|
|
50
50
|
return queryParts.context;
|
|
51
51
|
}
|
|
52
|
-
function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
|
|
53
|
-
|
|
54
|
-
if (receivedAllIds) {
|
|
52
|
+
function getMergedItemIds(itemIds = [], nextItemIds, { page = 1, offset, perPage = 10 } = {}) {
|
|
53
|
+
if (perPage === -1) {
|
|
55
54
|
return nextItemIds;
|
|
56
55
|
}
|
|
57
|
-
const nextItemIdsStartIndex = (page - 1) * perPage;
|
|
56
|
+
const nextItemIdsStartIndex = offset ?? (page - 1) * perPage;
|
|
58
57
|
const size = Math.max(
|
|
59
|
-
itemIds
|
|
58
|
+
itemIds.length,
|
|
60
59
|
nextItemIdsStartIndex + nextItemIds.length
|
|
61
60
|
);
|
|
62
61
|
const mergedItemIds = new Array(size);
|
|
63
62
|
for (let i = 0; i < size; i++) {
|
|
64
63
|
const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;
|
|
65
|
-
|
|
64
|
+
if (isInNextItemsRange) {
|
|
65
|
+
mergedItemIds[i] = nextItemIds[i - nextItemIdsStartIndex];
|
|
66
|
+
} else {
|
|
67
|
+
mergedItemIds[i] = itemIds[i];
|
|
68
|
+
}
|
|
66
69
|
}
|
|
67
70
|
return mergedItemIds;
|
|
68
71
|
}
|
|
@@ -168,10 +171,13 @@ var receiveQueries = (0, import_compose.compose)([
|
|
|
168
171
|
const key = action.key ?? import_entities.DEFAULT_ENTITY_KEY;
|
|
169
172
|
return {
|
|
170
173
|
itemIds: getMergedItemIds(
|
|
171
|
-
state
|
|
174
|
+
state.itemIds,
|
|
172
175
|
action.items.map((item) => item?.[key]).filter(Boolean),
|
|
173
|
-
|
|
174
|
-
|
|
176
|
+
{
|
|
177
|
+
page: action.page,
|
|
178
|
+
offset: action.offset,
|
|
179
|
+
perPage: action.perPage
|
|
180
|
+
}
|
|
175
181
|
),
|
|
176
182
|
meta: action.meta
|
|
177
183
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/queried-data/reducer.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAgC;AAChC,qBAAwB;AAKxB,mBAKO;AACP,sBAAmC;AACnC,6BAA0B;AAE1B,SAAS,qBAAsB,QAAS;AACvC,QAAM,EAAE,MAAM,IAAI;AAClB,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,iBAAa,uBAAAA,SAAe,KAAM;AACxC,SAAO,WAAW;AACnB;
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {number[]|undefined} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {Object} options Options object.\n * @param {number} [options.page] Page of items merged.\n * @param {number} [options.offset] Offset of items merged.\n * @param {number} options.perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds(\n\titemIds = [],\n\tnextItemIds,\n\t// The defaults for `page` and `perPage` are the same as in `getQueryParts`.\n\t{ page = 1, offset, perPage = 10 } = {}\n) {\n\t// If the query is unbounded, then `nextItemIds` is a complete replacement.\n\tif ( perPage === -1 ) {\n\t\treturn nextItemIds;\n\t}\n\n\tconst nextItemIdsStartIndex = offset ?? ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds.length,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;\n\t\tif ( isInNextItemsRange ) {\n\t\t\tmergedItemIds[ i ] = nextItemIds[ i - nextItemIdsStartIndex ];\n\t\t} else {\n\t\t\tmergedItemIds[ i ] = itemIds[ i ];\n\t\t}\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t? action.items\n\t\t\t\t: [ action.items ];\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...Object.fromEntries(\n\t\t\t\t\t\titemsList.map( ( item ) => [\n\t\t\t\t\t\t\titem?.[ key ],\n\t\t\t\t\t\t\tconservativeMapItem(\n\t\t\t\t\t\t\t\tstate?.[ context ]?.[ item?.[ key ] ],\n\t\t\t\t\t\t\t\titem\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t] )\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\t\t\tconst itemsList = Array.isArray( action.items )\n\t\t\t\t? action.items\n\t\t\t\t: [ action.items ];\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...itemsList.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item?.[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tif ( action.type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\t// Single items don't have page or total count metadata\n\t// (only collection query responses do), so skip updating itemIds.\n\tif ( ! Array.isArray( action.items ) ) {\n\t\treturn state;\n\t}\n\n\tconst key = action.key ?? DEFAULT_ENTITY_KEY;\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate.itemIds,\n\t\t\taction.items.map( ( item ) => item?.[ key ] ).filter( Boolean ),\n\t\t\t{\n\t\t\t\tpage: action.page,\n\t\t\t\toffset: action.offset,\n\t\t\t\tperPage: action.perPage,\n\t\t\t}\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,\n\titemIsComplete,\n\tqueries,\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAgC;AAChC,qBAAwB;AAKxB,mBAKO;AACP,sBAAmC;AACnC,6BAA0B;AAE1B,SAAS,qBAAsB,QAAS;AACvC,QAAM,EAAE,MAAM,IAAI;AAClB,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,iBAAa,uBAAAA,SAAe,KAAM;AACxC,SAAO,WAAW;AACnB;AAeO,SAAS,iBACf,UAAU,CAAC,GACX,aAEA,EAAE,OAAO,GAAG,QAAQ,UAAU,GAAG,IAAI,CAAC,GACrC;AAED,MAAK,YAAY,IAAK;AACrB,WAAO;AAAA,EACR;AAEA,QAAM,wBAAwB,WAAY,OAAO,KAAM;AAIvD,QAAM,OAAO,KAAK;AAAA,IACjB,QAAQ;AAAA,IACR,wBAAwB,YAAY;AAAA,EACrC;AAGA,QAAM,gBAAgB,IAAI,MAAO,IAAK;AAEtC,WAAU,IAAI,GAAG,IAAI,MAAM,KAAM;AAIhC,UAAM,qBACL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A,IAAO,sBAAQ,6BAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACD,CAAE;",
|
|
6
6
|
"names": ["getQueryParts"]
|
|
7
7
|
}
|
|
@@ -40,7 +40,8 @@ var import_data = require("@wordpress/data");
|
|
|
40
40
|
var import_get_query_parts = __toESM(require("./get-query-parts.cjs"));
|
|
41
41
|
var import_utils = require("../utils/index.cjs");
|
|
42
42
|
var queriedItemsCacheByState = /* @__PURE__ */ new WeakMap();
|
|
43
|
-
function getQueriedItemsUncached(state, query) {
|
|
43
|
+
function getQueriedItemsUncached(state, query, options = {}) {
|
|
44
|
+
const { supportsPagination = true } = options;
|
|
44
45
|
const {
|
|
45
46
|
stableKey,
|
|
46
47
|
page,
|
|
@@ -54,15 +55,13 @@ function getQueriedItemsUncached(state, query) {
|
|
|
54
55
|
if (!itemIds) {
|
|
55
56
|
return null;
|
|
56
57
|
}
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
58
|
+
const isPaginated = supportsPagination && perPage !== -1;
|
|
59
|
+
const startOffset = isPaginated ? queryOffset ?? (page - 1) * perPage : 0;
|
|
60
|
+
const endOffset = isPaginated ? Math.min(startOffset + perPage, itemIds.length) : itemIds.length;
|
|
61
|
+
if (isPaginated && itemIds.length < startOffset + perPage) {
|
|
60
62
|
const totalItems = state.queries[context][stableKey].meta?.totalItems;
|
|
61
|
-
if (Number.isFinite(totalItems)) {
|
|
62
|
-
|
|
63
|
-
if (itemIds.length < effectiveTotal) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
63
|
+
if (Number.isFinite(totalItems) && itemIds.length < totalItems) {
|
|
64
|
+
return null;
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
const items = [];
|
|
@@ -99,21 +98,23 @@ function getQueriedItemsUncached(state, query) {
|
|
|
99
98
|
}
|
|
100
99
|
return items;
|
|
101
100
|
}
|
|
102
|
-
var getQueriedItems = (0, import_data.createSelector)(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
var getQueriedItems = (0, import_data.createSelector)(
|
|
102
|
+
(state, query = {}, options = {}) => {
|
|
103
|
+
let queriedItemsCache = queriedItemsCacheByState.get(state);
|
|
104
|
+
if (queriedItemsCache) {
|
|
105
|
+
const queriedItems = queriedItemsCache.get(query);
|
|
106
|
+
if (queriedItems !== void 0) {
|
|
107
|
+
return queriedItems;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
queriedItemsCache = new import_equivalent_key_map.default();
|
|
111
|
+
queriedItemsCacheByState.set(state, queriedItemsCache);
|
|
108
112
|
}
|
|
109
|
-
|
|
110
|
-
queriedItemsCache
|
|
111
|
-
|
|
113
|
+
const items = getQueriedItemsUncached(state, query, options);
|
|
114
|
+
queriedItemsCache.set(query, items);
|
|
115
|
+
return items;
|
|
112
116
|
}
|
|
113
|
-
|
|
114
|
-
queriedItemsCache.set(query, items);
|
|
115
|
-
return items;
|
|
116
|
-
});
|
|
117
|
+
);
|
|
117
118
|
function getQueriedTotalItems(state, query = {}) {
|
|
118
119
|
const { stableKey, context } = (0, import_get_query_parts.default)(query);
|
|
119
120
|
return state.queries?.[context]?.[stableKey]?.meta?.totalItems ?? null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/queried-data/selectors.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,gCAA6B;AAK7B,kBAA+B;AAK/B,6BAA0B;AAC1B,mBAA+B;AAS/B,IAAM,2BAA2B,oBAAI,QAAQ;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport { createSelector } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n * @param {?Object} options Optional pagination options.\n * @param {boolean} options.supportsPagination Whether the entity supports pagination. Default true.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query, options = {} ) {\n\tconst { supportsPagination = true } = options;\n\tconst {\n\t\tstableKey,\n\t\tpage,\n\t\tperPage,\n\t\toffset: queryOffset,\n\t\tinclude,\n\t\tfields,\n\t\tcontext,\n\t} = getQueryParts( query );\n\n\tconst itemIds = state.queries?.[ context ]?.[ stableKey ]?.itemIds;\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst isPaginated = supportsPagination && perPage !== -1;\n\tconst startOffset = isPaginated ? queryOffset ?? ( page - 1 ) * perPage : 0;\n\tconst endOffset = isPaginated\n\t\t? Math.min( startOffset + perPage, itemIds.length )\n\t\t: itemIds.length;\n\n\t// If the requested page range exceeds the stored itemIds, the data for\n\t// this specific pagination window may not have been fetched yet. Return\n\t// null unless totalItems confirms we already have all available items.\n\tif ( isPaginated && itemIds.length < startOffset + perPage ) {\n\t\tconst totalItems =\n\t\t\tstate.queries[ context ][ stableKey ].meta?.totalItems;\n\t\tif ( Number.isFinite( totalItems ) && itemIds.length < totalItems ) {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( itemId === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tlet value = item;\n\t\t\t\tfield.forEach( ( fieldName ) => {\n\t\t\t\t\tvalue = value?.[ fieldName ];\n\t\t\t\t} );\n\n\t\t\t\tsetNestedValue( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n * @param {?Object} options Optional pagination options.\n * @param {boolean} options.supportsPagination Whether the entity supports pagination. Default true.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector(\n\t( state, query = {}, options = {} ) => {\n\t\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\t\tif ( queriedItemsCache ) {\n\t\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\t\tif ( queriedItems !== undefined ) {\n\t\t\t\treturn queriedItems;\n\t\t\t}\n\t\t} else {\n\t\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t\t}\n\n\t\tconst items = getQueriedItemsUncached( state, query, options );\n\t\tqueriedItemsCache.set( query, items );\n\t\treturn items;\n\t}\n);\n\nexport function getQueriedTotalItems( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalItems ?? null;\n}\n\nexport function getQueriedTotalPages( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalPages ?? null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,gCAA6B;AAK7B,kBAA+B;AAK/B,6BAA0B;AAC1B,mBAA+B;AAS/B,IAAM,2BAA2B,oBAAI,QAAQ;AAY7C,SAAS,wBAAyB,OAAO,OAAO,UAAU,CAAC,GAAI;AAC9D,QAAM,EAAE,qBAAqB,KAAK,IAAI;AACtC,QAAM;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,EACD,QAAI,uBAAAA,SAAe,KAAM;AAEzB,QAAM,UAAU,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG;AAC3D,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAEA,QAAM,cAAc,sBAAsB,YAAY;AACtD,QAAM,cAAc,cA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;AACtC,QAAI,oBAAoB,yBAAyB,IAAK,KAAM;AAC5D,QAAK,mBAAoB;AACxB,YAAM,eAAe,kBAAkB,IAAK,KAAM;AAClD,UAAK,iBAAiB,QAAY;AACjC,eAAO;AAAA,MACR;AAAA,IACD,OAAO;AACN,0BAAoB,IAAI,0BAAAC,QAAiB;AACzC,+BAAyB,IAAK,OAAO,iBAAkB;AAAA,IACxD;AAEA,UAAM,QAAQ,wBAAyB,OAAO,OAAO,OAAQ;AAC7D,sBAAkB,IAAK,OAAO,KAAM;AACpC,WAAO;AAAA,EACR;AACD;AAEO,SAAS,qBAAsB,OAAO,QAAQ,CAAC,GAAI;AACzD,QAAM,EAAE,WAAW,QAAQ,QAAI,uBAAAD,SAAe,KAAM;AAEpD,SAAO,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG,MAAM,cAAc;AACvE;AAEO,SAAS,qBAAsB,OAAO,QAAQ,CAAC,GAAI;AACzD,QAAM,EAAE,WAAW,QAAQ,QAAI,uBAAAA,SAAe,KAAM;AAEpD,SAAO,MAAM,UAAW,OAAQ,IAAK,SAAU,GAAG,MAAM,cAAc;AACvE;",
|
|
6
6
|
"names": ["getQueryParts", "EquivalentKeyMap"]
|
|
7
7
|
}
|
package/build/reducer.cjs
CHANGED
|
@@ -54,7 +54,8 @@ __export(reducer_exports, {
|
|
|
54
54
|
undoManager: () => undoManager,
|
|
55
55
|
userPatternCategories: () => userPatternCategories,
|
|
56
56
|
userPermissions: () => userPermissions,
|
|
57
|
-
users: () => users
|
|
57
|
+
users: () => users,
|
|
58
|
+
viewConfigs: () => viewConfigs
|
|
58
59
|
});
|
|
59
60
|
module.exports = __toCommonJS(reducer_exports);
|
|
60
61
|
var import_es6 = __toESM(require("fast-deep-equal/es6/index.js"));
|
|
@@ -487,6 +488,16 @@ function collaborationSupported(state = true, action) {
|
|
|
487
488
|
}
|
|
488
489
|
return state;
|
|
489
490
|
}
|
|
491
|
+
function viewConfigs(state = {}, action) {
|
|
492
|
+
switch (action.type) {
|
|
493
|
+
case "RECEIVE_VIEW_CONFIG":
|
|
494
|
+
return {
|
|
495
|
+
...state,
|
|
496
|
+
[`${action.kind}/${action.name}`]: action.config
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
return state;
|
|
500
|
+
}
|
|
490
501
|
var reducer_default = (0, import_data.combineReducers)({
|
|
491
502
|
users,
|
|
492
503
|
currentTheme,
|
|
@@ -510,7 +521,8 @@ var reducer_default = (0, import_data.combineReducers)({
|
|
|
510
521
|
editorSettings,
|
|
511
522
|
editorAssets,
|
|
512
523
|
syncConnectionStatuses,
|
|
513
|
-
collaborationSupported
|
|
524
|
+
collaborationSupported,
|
|
525
|
+
viewConfigs
|
|
514
526
|
});
|
|
515
527
|
// Annotate the CommonJS export names for ESM import in node:
|
|
516
528
|
0 && (module.exports = {
|
|
@@ -537,6 +549,7 @@ var reducer_default = (0, import_data.combineReducers)({
|
|
|
537
549
|
undoManager,
|
|
538
550
|
userPatternCategories,
|
|
539
551
|
userPermissions,
|
|
540
|
-
users
|
|
552
|
+
users,
|
|
553
|
+
viewConfigs
|
|
541
554
|
});
|
|
542
555
|
//# sourceMappingURL=reducer.cjs.map
|