@wordpress/core-data 6.4.0 → 6.6.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/README.md +1 -1
- package/build/entities.js +7 -7
- package/build/entities.js.map +1 -1
- package/build/queried-data/selectors.js +7 -4
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +3 -1
- package/build/reducer.js.map +1 -1
- package/build/selectors.js +43 -22
- package/build/selectors.js.map +1 -1
- package/build/utils/index.js +8 -0
- package/build/utils/index.js.map +1 -1
- package/build/utils/set-nested-value.js +46 -0
- package/build/utils/set-nested-value.js.map +1 -0
- package/build-module/entities.js +7 -6
- package/build-module/entities.js.map +1 -1
- package/build-module/queried-data/selectors.js +6 -3
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +4 -2
- package/build-module/reducer.js.map +1 -1
- package/build-module/selectors.js +44 -22
- 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/set-nested-value.js +39 -0
- package/build-module/utils/set-nested-value.js.map +1 -0
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-types/attachment.d.ts +1 -1
- package/build-types/entity-types/attachment.d.ts.map +1 -1
- package/build-types/entity-types/comment.d.ts +2 -2
- package/build-types/entity-types/comment.d.ts.map +1 -1
- package/build-types/entity-types/helpers.d.ts +9 -9
- package/build-types/entity-types/helpers.d.ts.map +1 -1
- package/build-types/entity-types/index.d.ts +1 -1
- package/build-types/entity-types/index.d.ts.map +1 -1
- package/build-types/entity-types/menu-location.d.ts +1 -1
- package/build-types/entity-types/menu-location.d.ts.map +1 -1
- package/build-types/entity-types/nav-menu-item.d.ts +4 -4
- package/build-types/entity-types/nav-menu-item.d.ts.map +1 -1
- package/build-types/entity-types/nav-menu.d.ts +1 -1
- package/build-types/entity-types/nav-menu.d.ts.map +1 -1
- package/build-types/entity-types/page.d.ts +1 -1
- package/build-types/entity-types/page.d.ts.map +1 -1
- package/build-types/entity-types/plugin.d.ts +2 -2
- package/build-types/entity-types/plugin.d.ts.map +1 -1
- package/build-types/entity-types/post.d.ts +1 -1
- package/build-types/entity-types/post.d.ts.map +1 -1
- package/build-types/entity-types/settings.d.ts +1 -1
- package/build-types/entity-types/settings.d.ts.map +1 -1
- package/build-types/entity-types/sidebar.d.ts +2 -2
- package/build-types/entity-types/sidebar.d.ts.map +1 -1
- package/build-types/entity-types/taxonomy.d.ts +1 -1
- package/build-types/entity-types/taxonomy.d.ts.map +1 -1
- package/build-types/entity-types/theme.d.ts +1 -1
- package/build-types/entity-types/theme.d.ts.map +1 -1
- package/build-types/entity-types/type.d.ts +1 -1
- package/build-types/entity-types/type.d.ts.map +1 -1
- package/build-types/entity-types/user.d.ts +1 -1
- package/build-types/entity-types/user.d.ts.map +1 -1
- package/build-types/entity-types/widget-type.d.ts +1 -1
- package/build-types/entity-types/widget-type.d.ts.map +1 -1
- package/build-types/entity-types/widget.d.ts +1 -1
- package/build-types/entity-types/widget.d.ts.map +1 -1
- package/build-types/entity-types/wp-template-part.d.ts +1 -1
- package/build-types/entity-types/wp-template-part.d.ts.map +1 -1
- package/build-types/entity-types/wp-template.d.ts +1 -1
- package/build-types/entity-types/wp-template.d.ts.map +1 -1
- package/build-types/hooks/use-resource-permissions.d.ts +2 -2
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -1
- package/build-types/queried-data/get-query-parts.d.ts +1 -1
- package/build-types/queried-data/reducer.d.ts +1 -1
- package/build-types/queried-data/selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts +1 -1
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/selectors.d.ts +19 -6
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/utils/index.d.ts +1 -0
- package/build-types/utils/set-nested-value.d.ts +18 -0
- package/build-types/utils/set-nested-value.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/entities.js +1 -2
- package/src/locks/test/engine.js +0 -2
- package/src/queried-data/selectors.js +7 -3
- package/src/reducer.js +2 -6
- package/src/selectors.ts +63 -104
- package/src/utils/index.js +1 -0
- package/src/utils/set-nested-value.js +37 -0
- package/src/utils/test/set-nested-value.js +72 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/reducer.js"],"names":["fastDeepEqual","groupBy","get","compose","combineReducers","isShallowEqual","ifMatchingAction","replaceAction","reducer","queriedDataReducer","rootEntitiesConfig","DEFAULT_ENTITY_KEY","terms","state","action","type","taxonomy","users","byId","queries","reduce","newUsers","user","id","queryID","map","currentUser","taxonomies","currentTheme","undefined","stylesheet","currentGlobalStylesId","themeBaseGlobalStyles","globalStyles","themeGlobalStyleVariations","variations","entity","entityConfig","name","kind","key","queriedData","edits","context","query","nextState","record","items","recordId","nextEdits","Object","keys","acc","persistedEdits","length","forEach","saving","pending","error","isAutosave","deleting","entitiesConfig","entities","newConfig","config","entitiesDataReducer","entitiesByKind","entries","memo","subEntities","kindReducer","kindMemo","newData","records","UNDO_INITIAL_STATE","assign","offset","lastEditAction","undo","isCreateUndoLevel","isUndoOrRedo","meta","isUndo","isRedo","some","transientEdits","flattenedUndo","slice","pop","push","comparisonUndoEdits","values","filter","edit","comparisonEdits","embedPreviews","url","preview","userPermissions","isAllowed","autosaves","postId","autosavesData","blockPatterns","patterns","blockPatternCategories","categories"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAP,MAA0B,qBAA1B;AACA,SAASC,OAAT,EAAkBC,GAAlB,QAA6B,QAA7B;AAEA;AACA;AACA;;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,eAAT,QAAgC,iBAAhC;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,aAA3B,QAAgD,SAAhD;AACA,SAASC,OAAO,IAAIC,kBAApB,QAA8C,gBAA9C;AACA,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,QAAAA,SAAS,EAAEE;AAArB,UAAuCxF,MAA7C;AAEA,aAAO,EACN,GAAGD,KADG;AAEN,SAAEwF,MAAF,GAAYC;AAFN,OAAP;AAJF;;AAUA,SAAOzF,KAAP;AACA;AAED,OAAO,SAAS0F,aAAT,GAA6C;AAAA,MAArB1F,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AACnD,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,wBAAL;AACC,aAAOD,MAAM,CAAC0F,QAAd;AAFF;;AAKA,SAAO3F,KAAP;AACA;AAED,OAAO,SAAS4F,sBAAT,GAAsD;AAAA,MAArB5F,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AAC5D,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,kCAAL;AACC,aAAOD,MAAM,CAAC4F,UAAd;AAFF;;AAKA,SAAO7F,KAAP;AACA;AAED,eAAeT,eAAe,CAAE;AAC/BQ,EAAAA,KAD+B;AAE/BK,EAAAA,KAF+B;AAG/BW,EAAAA,YAH+B;AAI/BG,EAAAA,qBAJ+B;AAK/BL,EAAAA,WAL+B;AAM/BQ,EAAAA,0BAN+B;AAO/BF,EAAAA,qBAP+B;AAQ/BL,EAAAA,UAR+B;AAS/BmC,EAAAA,QAT+B;AAU/BgB,EAAAA,IAV+B;AAW/BiB,EAAAA,aAX+B;AAY/BG,EAAAA,eAZ+B;AAa/BE,EAAAA,SAb+B;AAc/BG,EAAAA,aAd+B;AAe/BE,EAAAA;AAf+B,CAAF,CAA9B","sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\nimport { groupBy, get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\nimport { combineReducers } from '@wordpress/data';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport { ifMatchingAction, replaceAction } from './utils';\nimport { reducer as queriedDataReducer } from './queried-data';\nimport { rootEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\n\n/** @typedef {import('./types').AnyFunction} AnyFunction */\n\n/**\n * Reducer managing terms state. Keyed by taxonomy slug, the value is either\n * undefined (if no request has been made for given taxonomy), null (if a\n * request is in-flight for given taxonomy), or the array of terms for the\n * taxonomy.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function terms( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_TERMS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.taxonomy ]: action.terms,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing authors state. Keyed by id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function users( state = { byId: {}, queries: {} }, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_QUERY':\n\t\t\treturn {\n\t\t\t\tbyId: {\n\t\t\t\t\t...state.byId,\n\t\t\t\t\t// Key users by their ID.\n\t\t\t\t\t...action.users.reduce(\n\t\t\t\t\t\t( newUsers, user ) => ( {\n\t\t\t\t\t\t\t...newUsers,\n\t\t\t\t\t\t\t[ user.id ]: user,\n\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\tqueries: {\n\t\t\t\t\t...state.queries,\n\t\t\t\t\t[ action.queryID ]: action.users.map( ( user ) => user.id ),\n\t\t\t\t},\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing current user state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function currentUser( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_USER':\n\t\t\treturn action.currentUser;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing taxonomies.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function taxonomies( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_TAXONOMIES':\n\t\t\treturn action.taxonomies;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current theme.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentTheme( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_THEME':\n\t\t\treturn action.currentTheme.stylesheet;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current global styles id.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentGlobalStylesId( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':\n\t\t\treturn action.id;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme base global styles.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeBaseGlobalStyles( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLES':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.globalStyles,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme global styles variations.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeGlobalStyleVariations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.variations,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Higher Order Reducer for a given entity config. It supports:\n *\n * - Fetching\n * - Editing\n * - Saving\n *\n * @param {Object} entityConfig Entity config.\n *\n * @return {AnyFunction} Reducer.\n */\nfunction entity( entityConfig ) {\n\treturn compose( [\n\t\t// Limit to matching action type so we don't attempt to replace action on\n\t\t// an unhandled action.\n\t\tifMatchingAction(\n\t\t\t( action ) =>\n\t\t\t\taction.name &&\n\t\t\t\taction.kind &&\n\t\t\t\taction.name === entityConfig.name &&\n\t\t\t\taction.kind === entityConfig.kind\n\t\t),\n\n\t\t// Inject the entity config into the action.\n\t\treplaceAction( ( action ) => {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\tkey: entityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t};\n\t\t} ),\n\t] )(\n\t\tcombineReducers( {\n\t\t\tqueriedData: queriedDataReducer,\n\n\t\t\tedits: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'RECEIVE_ITEMS':\n\t\t\t\t\t\tconst context = action?.query?.context ?? 'default';\n\t\t\t\t\t\tif ( context !== 'default' ) {\n\t\t\t\t\t\t\treturn state;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst nextState = { ...state };\n\n\t\t\t\t\t\tfor ( const record of action.items ) {\n\t\t\t\t\t\t\tconst recordId = record[ action.key ];\n\t\t\t\t\t\t\tconst edits = nextState[ recordId ];\n\t\t\t\t\t\t\tif ( ! edits ) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst nextEdits = Object.keys( edits ).reduce(\n\t\t\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\t\t\t// If the edited value is still different to the persisted value,\n\t\t\t\t\t\t\t\t\t// keep the edited value in edits.\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t// Edits are the \"raw\" attribute values, but records may have\n\t\t\t\t\t\t\t\t\t\t// objects with more properties, so we use `get` here for the\n\t\t\t\t\t\t\t\t\t\t// comparison.\n\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\tget(\n\t\t\t\t\t\t\t\t\t\t\t\trecord[ key ],\n\t\t\t\t\t\t\t\t\t\t\t\t'raw',\n\t\t\t\t\t\t\t\t\t\t\t\trecord[ key ]\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t\t\t// Sometimes the server alters the sent value which means\n\t\t\t\t\t\t\t\t\t\t// we need to also remove the edits before the api request.\n\t\t\t\t\t\t\t\t\t\t( ! action.persistedEdits ||\n\t\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\t\taction.persistedEdits[ key ]\n\t\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\t\tacc[ key ] = edits[ key ];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn acc;\n\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\n\t\t\t\t\t\t\tif ( Object.keys( nextEdits ).length ) {\n\t\t\t\t\t\t\t\tnextState[ recordId ] = nextEdits;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tdelete nextState[ recordId ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nextState;\n\n\t\t\t\t\tcase 'EDIT_ENTITY_RECORD':\n\t\t\t\t\t\tconst nextEdits = {\n\t\t\t\t\t\t\t...state[ action.recordId ],\n\t\t\t\t\t\t\t...action.edits,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tObject.keys( nextEdits ).forEach( ( key ) => {\n\t\t\t\t\t\t\t// Delete cleared edits so that the properties\n\t\t\t\t\t\t\t// are not considered dirty.\n\t\t\t\t\t\t\tif ( nextEdits[ key ] === undefined ) {\n\t\t\t\t\t\t\t\tdelete nextEdits[ key ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: nextEdits,\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tsaving: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type === 'SAVE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t\tisAutosave: action.isAutosave,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tdeleting: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type ===\n\t\t\t\t\t\t\t\t\t'DELETE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\t\t} )\n\t);\n}\n\n/**\n * Reducer keeping track of the registered entities.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function entitiesConfig( state = rootEntitiesConfig, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_ENTITIES':\n\t\t\treturn [ ...state, ...action.entities ];\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer keeping track of the registered entities config and data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const entities = ( state = {}, action ) => {\n\tconst newConfig = entitiesConfig( state.config, action );\n\n\t// Generates a dynamic reducer for the entities.\n\tlet entitiesDataReducer = state.reducer;\n\tif ( ! entitiesDataReducer || newConfig !== state.config ) {\n\t\tconst entitiesByKind = groupBy( newConfig, 'kind' );\n\t\tentitiesDataReducer = combineReducers(\n\t\t\tObject.entries( entitiesByKind ).reduce(\n\t\t\t\t( memo, [ kind, subEntities ] ) => {\n\t\t\t\t\tconst kindReducer = combineReducers(\n\t\t\t\t\t\tsubEntities.reduce(\n\t\t\t\t\t\t\t( kindMemo, entityConfig ) => ( {\n\t\t\t\t\t\t\t\t...kindMemo,\n\t\t\t\t\t\t\t\t[ entityConfig.name ]: entity( entityConfig ),\n\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\n\t\t\t\t\tmemo[ kind ] = kindReducer;\n\t\t\t\t\treturn memo;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t)\n\t\t);\n\t}\n\n\tconst newData = entitiesDataReducer( state.records, action );\n\n\tif (\n\t\tnewData === state.records &&\n\t\tnewConfig === state.config &&\n\t\tentitiesDataReducer === state.reducer\n\t) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\treducer: entitiesDataReducer,\n\t\trecords: newData,\n\t\tconfig: newConfig,\n\t};\n};\n\n/**\n * @typedef {Object} UndoStateMeta\n *\n * @property {number} offset Where in the undo stack we are.\n * @property {Object} [flattenedUndo] Flattened form of undo stack.\n */\n\n/** @typedef {Array<Object> & UndoStateMeta} UndoState */\n\n/**\n * @type {UndoState}\n *\n * @todo Given how we use this we might want to make a custom class for it.\n */\nconst UNDO_INITIAL_STATE = Object.assign( [], { offset: 0 } );\n\n/** @type {Object} */\nlet lastEditAction;\n\n/**\n * Reducer keeping track of entity edit undo history.\n *\n * @param {UndoState} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {UndoState} Updated state.\n */\nexport function undo( state = UNDO_INITIAL_STATE, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'EDIT_ENTITY_RECORD':\n\t\tcase 'CREATE_UNDO_LEVEL':\n\t\t\tlet isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL';\n\t\t\tconst isUndoOrRedo =\n\t\t\t\t! isCreateUndoLevel &&\n\t\t\t\t( action.meta.isUndo || action.meta.isRedo );\n\t\t\tif ( isCreateUndoLevel ) {\n\t\t\t\taction = lastEditAction;\n\t\t\t} else if ( ! isUndoOrRedo ) {\n\t\t\t\t// Don't lose the last edit cache if the new one only has transient edits.\n\t\t\t\t// Transient edits don't create new levels so updating the cache would make\n\t\t\t\t// us skip an edit later when creating levels explicitly.\n\t\t\t\tif (\n\t\t\t\t\tObject.keys( action.edits ).some(\n\t\t\t\t\t\t( key ) => ! action.transientEdits[ key ]\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tlastEditAction = action;\n\t\t\t\t} else {\n\t\t\t\t\tlastEditAction = {\n\t\t\t\t\t\t...action,\n\t\t\t\t\t\tedits: {\n\t\t\t\t\t\t\t...( lastEditAction && lastEditAction.edits ),\n\t\t\t\t\t\t\t...action.edits,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/** @type {UndoState} */\n\t\t\tlet nextState;\n\n\t\t\tif ( isUndoOrRedo ) {\n\t\t\t\t// @ts-ignore we might consider using Object.assign({}, state)\n\t\t\t\tnextState = [ ...state ];\n\t\t\t\tnextState.offset =\n\t\t\t\t\tstate.offset + ( action.meta.isUndo ? -1 : 1 );\n\n\t\t\t\tif ( state.flattenedUndo ) {\n\t\t\t\t\t// The first undo in a sequence of undos might happen while we have\n\t\t\t\t\t// flattened undos in state. If this is the case, we want execution\n\t\t\t\t\t// to continue as if we were creating an explicit undo level. This\n\t\t\t\t\t// will result in an extra undo level being appended with the flattened\n\t\t\t\t\t// undo values.\n\t\t\t\t\t// We also have to take into account if the `lastEditAction` had opted out\n\t\t\t\t\t// of being tracked in undo history, like the action that persists the latest\n\t\t\t\t\t// content right before saving. In that case we have to update the `lastEditAction`\n\t\t\t\t\t// to avoid returning early before applying the existing flattened undos.\n\t\t\t\t\tisCreateUndoLevel = true;\n\t\t\t\t\tif ( ! lastEditAction.meta.undo ) {\n\t\t\t\t\t\tlastEditAction.meta.undo = {\n\t\t\t\t\t\t\tedits: {},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\taction = lastEditAction;\n\t\t\t\t} else {\n\t\t\t\t\treturn nextState;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! action.meta.undo ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\t// Transient edits don't create an undo level, but are\n\t\t\t// reachable in the next meaningful edit to which they\n\t\t\t// are merged. They are defined in the entity's config.\n\t\t\tif (\n\t\t\t\t! isCreateUndoLevel &&\n\t\t\t\t! Object.keys( action.edits ).some(\n\t\t\t\t\t( key ) => ! action.transientEdits[ key ]\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// @ts-ignore we might consider using Object.assign({}, state)\n\t\t\t\tnextState = [ ...state ];\n\t\t\t\tnextState.flattenedUndo = {\n\t\t\t\t\t...state.flattenedUndo,\n\t\t\t\t\t...action.edits,\n\t\t\t\t};\n\t\t\t\tnextState.offset = state.offset;\n\t\t\t\treturn nextState;\n\t\t\t}\n\n\t\t\t// Clear potential redos, because this only supports linear history.\n\t\t\tnextState =\n\t\t\t\t// @ts-ignore this needs additional cleanup, probably involving code-level changes\n\t\t\t\tnextState || state.slice( 0, state.offset || undefined );\n\t\t\tnextState.offset = nextState.offset || 0;\n\t\t\tnextState.pop();\n\t\t\tif ( ! isCreateUndoLevel ) {\n\t\t\t\tnextState.push( {\n\t\t\t\t\tkind: action.meta.undo.kind,\n\t\t\t\t\tname: action.meta.undo.name,\n\t\t\t\t\trecordId: action.meta.undo.recordId,\n\t\t\t\t\tedits: {\n\t\t\t\t\t\t...state.flattenedUndo,\n\t\t\t\t\t\t...action.meta.undo.edits,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\t// When an edit is a function it's an optimization to avoid running some expensive operation.\n\t\t\t// We can't rely on the function references being the same so we opt out of comparing them here.\n\t\t\tconst comparisonUndoEdits = Object.values(\n\t\t\t\taction.meta.undo.edits\n\t\t\t).filter( ( edit ) => typeof edit !== 'function' );\n\t\t\tconst comparisonEdits = Object.values( action.edits ).filter(\n\t\t\t\t( edit ) => typeof edit !== 'function'\n\t\t\t);\n\t\t\tif ( ! isShallowEqual( comparisonUndoEdits, comparisonEdits ) ) {\n\t\t\t\tnextState.push( {\n\t\t\t\t\tkind: action.kind,\n\t\t\t\t\tname: action.name,\n\t\t\t\t\trecordId: action.recordId,\n\t\t\t\t\tedits: isCreateUndoLevel\n\t\t\t\t\t\t? { ...state.flattenedUndo, ...action.edits }\n\t\t\t\t\t\t: action.edits,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing embed preview data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function embedPreviews( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EMBED_PREVIEW':\n\t\t\tconst { url, preview } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ url ]: preview,\n\t\t\t};\n\t}\n\treturn state;\n}\n\n/**\n * State which tracks whether the user can perform an action on a REST\n * resource.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function userPermissions( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_PERMISSION':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.key ]: action.isAllowed,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning autosaves keyed by their parent's post id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function autosaves( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_AUTOSAVES':\n\t\t\tconst { postId, autosaves: autosavesData } = action;\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ postId ]: autosavesData,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nexport function blockPatterns( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERNS':\n\t\t\treturn action.patterns;\n\t}\n\n\treturn state;\n}\n\nexport function blockPatternCategories( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERN_CATEGORIES':\n\t\t\treturn action.categories;\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tterms,\n\tusers,\n\tcurrentTheme,\n\tcurrentGlobalStylesId,\n\tcurrentUser,\n\tthemeGlobalStyleVariations,\n\tthemeBaseGlobalStyles,\n\ttaxonomies,\n\tentities,\n\tundo,\n\tembedPreviews,\n\tuserPermissions,\n\tautosaves,\n\tblockPatterns,\n\tblockPatternCategories,\n} );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/reducer.js"],"names":["fastDeepEqual","groupBy","compose","combineReducers","isShallowEqual","ifMatchingAction","replaceAction","reducer","queriedDataReducer","rootEntitiesConfig","DEFAULT_ENTITY_KEY","terms","state","action","type","taxonomy","users","byId","queries","reduce","newUsers","user","id","queryID","map","currentUser","taxonomies","currentTheme","undefined","stylesheet","currentGlobalStylesId","themeBaseGlobalStyles","globalStyles","themeGlobalStyleVariations","variations","entity","entityConfig","name","kind","key","queriedData","edits","context","query","nextState","record","items","recordId","nextEdits","Object","keys","acc","raw","persistedEdits","length","forEach","saving","pending","error","isAutosave","deleting","entitiesConfig","entities","newConfig","config","entitiesDataReducer","entitiesByKind","entries","memo","subEntities","kindReducer","kindMemo","newData","records","UNDO_INITIAL_STATE","assign","offset","lastEditAction","undo","isCreateUndoLevel","isUndoOrRedo","meta","isUndo","isRedo","some","transientEdits","flattenedUndo","slice","pop","push","comparisonUndoEdits","values","filter","edit","comparisonEdits","embedPreviews","url","preview","userPermissions","isAllowed","autosaves","postId","autosavesData","blockPatterns","patterns","blockPatternCategories","categories"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAP,MAA0B,qBAA1B;AACA,SAASC,OAAT,QAAwB,QAAxB;AAEA;AACA;AACA;;AACA,SAASC,OAAT,QAAwB,oBAAxB;AACA,SAASC,eAAT,QAAgC,iBAAhC;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,aAA3B,QAAgD,SAAhD;AACA,SAASC,OAAO,IAAIC,kBAApB,QAA8C,gBAA9C;AACA,SAASC,kBAAT,EAA6BC,kBAA7B,QAAuD,YAAvD;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,KAAT,GAAqC;AAAA,MAArBC,KAAqB,uEAAb,EAAa;AAAA,MAATC,MAAS;;AAC3C,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,eAAL;AACC,aAAO,EACN,GAAGF,KADG;AAEN,SAAEC,MAAM,CAACE,QAAT,GAAqBF,MAAM,CAACF;AAFtB,OAAP;AAFF;;AAQA,SAAOC,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,KAAT,GAA4D;AAAA,MAA5CJ,KAA4C,uEAAp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IAAhB;AACC,SAAK,kCAAL;AACC,aAAOD,MAAM,CAAC6F,UAAd;AAFF;;AAKA,SAAO9F,KAAP;AACA;AAED,eAAeT,eAAe,CAAE;AAC/BQ,EAAAA,KAD+B;AAE/BK,EAAAA,KAF+B;AAG/BW,EAAAA,YAH+B;AAI/BG,EAAAA,qBAJ+B;AAK/BL,EAAAA,WAL+B;AAM/BQ,EAAAA,0BAN+B;AAO/BF,EAAAA,qBAP+B;AAQ/BL,EAAAA,UAR+B;AAS/BoC,EAAAA,QAT+B;AAU/BgB,EAAAA,IAV+B;AAW/BiB,EAAAA,aAX+B;AAY/BG,EAAAA,eAZ+B;AAa/BE,EAAAA,SAb+B;AAc/BG,EAAAA,aAd+B;AAe/BE,EAAAA;AAf+B,CAAF,CAA9B","sourcesContent":["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\nimport { groupBy } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { compose } from '@wordpress/compose';\nimport { combineReducers } from '@wordpress/data';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport { ifMatchingAction, replaceAction } from './utils';\nimport { reducer as queriedDataReducer } from './queried-data';\nimport { rootEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';\n\n/** @typedef {import('./types').AnyFunction} AnyFunction */\n\n/**\n * Reducer managing terms state. Keyed by taxonomy slug, the value is either\n * undefined (if no request has been made for given taxonomy), null (if a\n * request is in-flight for given taxonomy), or the array of terms for the\n * taxonomy.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function terms( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_TERMS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.taxonomy ]: action.terms,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing authors state. Keyed by id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function users( state = { byId: {}, queries: {} }, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_QUERY':\n\t\t\treturn {\n\t\t\t\tbyId: {\n\t\t\t\t\t...state.byId,\n\t\t\t\t\t// Key users by their ID.\n\t\t\t\t\t...action.users.reduce(\n\t\t\t\t\t\t( newUsers, user ) => ( {\n\t\t\t\t\t\t\t...newUsers,\n\t\t\t\t\t\t\t[ user.id ]: user,\n\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\tqueries: {\n\t\t\t\t\t...state.queries,\n\t\t\t\t\t[ action.queryID ]: action.users.map( ( user ) => user.id ),\n\t\t\t\t},\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing current user state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function currentUser( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_USER':\n\t\t\treturn action.currentUser;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing taxonomies.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function taxonomies( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_TAXONOMIES':\n\t\t\treturn action.taxonomies;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current theme.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentTheme( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_THEME':\n\t\t\treturn action.currentTheme.stylesheet;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the current global styles id.\n *\n * @param {string|undefined} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {string|undefined} Updated state.\n */\nexport function currentGlobalStylesId( state = undefined, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':\n\t\t\treturn action.id;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme base global styles.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeBaseGlobalStyles( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLES':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.globalStyles,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing the theme global styles variations.\n *\n * @param {Record<string, object>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Record<string, object>} Updated state.\n */\nexport function themeGlobalStyleVariations( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_THEME_GLOBAL_STYLE_VARIATIONS':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.stylesheet ]: action.variations,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Higher Order Reducer for a given entity config. It supports:\n *\n * - Fetching\n * - Editing\n * - Saving\n *\n * @param {Object} entityConfig Entity config.\n *\n * @return {AnyFunction} Reducer.\n */\nfunction entity( entityConfig ) {\n\treturn compose( [\n\t\t// Limit to matching action type so we don't attempt to replace action on\n\t\t// an unhandled action.\n\t\tifMatchingAction(\n\t\t\t( action ) =>\n\t\t\t\taction.name &&\n\t\t\t\taction.kind &&\n\t\t\t\taction.name === entityConfig.name &&\n\t\t\t\taction.kind === entityConfig.kind\n\t\t),\n\n\t\t// Inject the entity config into the action.\n\t\treplaceAction( ( action ) => {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\tkey: entityConfig.key || DEFAULT_ENTITY_KEY,\n\t\t\t};\n\t\t} ),\n\t] )(\n\t\tcombineReducers( {\n\t\t\tqueriedData: queriedDataReducer,\n\n\t\t\tedits: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'RECEIVE_ITEMS':\n\t\t\t\t\t\tconst context = action?.query?.context ?? 'default';\n\t\t\t\t\t\tif ( context !== 'default' ) {\n\t\t\t\t\t\t\treturn state;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst nextState = { ...state };\n\n\t\t\t\t\t\tfor ( const record of action.items ) {\n\t\t\t\t\t\t\tconst recordId = record[ action.key ];\n\t\t\t\t\t\t\tconst edits = nextState[ recordId ];\n\t\t\t\t\t\t\tif ( ! edits ) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst nextEdits = Object.keys( edits ).reduce(\n\t\t\t\t\t\t\t\t( acc, key ) => {\n\t\t\t\t\t\t\t\t\t// If the edited value is still different to the persisted value,\n\t\t\t\t\t\t\t\t\t// keep the edited value in edits.\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t// Edits are the \"raw\" attribute values, but records may have\n\t\t\t\t\t\t\t\t\t\t// objects with more properties, so we use `get` here for the\n\t\t\t\t\t\t\t\t\t\t// comparison.\n\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\trecord[ key ]?.raw ?? record[ key ]\n\t\t\t\t\t\t\t\t\t\t) &&\n\t\t\t\t\t\t\t\t\t\t// Sometimes the server alters the sent value which means\n\t\t\t\t\t\t\t\t\t\t// we need to also remove the edits before the api request.\n\t\t\t\t\t\t\t\t\t\t( ! action.persistedEdits ||\n\t\t\t\t\t\t\t\t\t\t\t! fastDeepEqual(\n\t\t\t\t\t\t\t\t\t\t\t\tedits[ key ],\n\t\t\t\t\t\t\t\t\t\t\t\taction.persistedEdits[ key ]\n\t\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\t\tacc[ key ] = edits[ key ];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn acc;\n\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\n\t\t\t\t\t\t\tif ( Object.keys( nextEdits ).length ) {\n\t\t\t\t\t\t\t\tnextState[ recordId ] = nextEdits;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tdelete nextState[ recordId ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn nextState;\n\n\t\t\t\t\tcase 'EDIT_ENTITY_RECORD':\n\t\t\t\t\t\tconst nextEdits = {\n\t\t\t\t\t\t\t...state[ action.recordId ],\n\t\t\t\t\t\t\t...action.edits,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tObject.keys( nextEdits ).forEach( ( key ) => {\n\t\t\t\t\t\t\t// Delete cleared edits so that the properties\n\t\t\t\t\t\t\t// are not considered dirty.\n\t\t\t\t\t\t\tif ( nextEdits[ key ] === undefined ) {\n\t\t\t\t\t\t\t\tdelete nextEdits[ key ];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} );\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: nextEdits,\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tsaving: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'SAVE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type === 'SAVE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t\tisAutosave: action.isAutosave,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\n\t\t\tdeleting: ( state = {}, action ) => {\n\t\t\t\tswitch ( action.type ) {\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_START':\n\t\t\t\t\tcase 'DELETE_ENTITY_RECORD_FINISH':\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...state,\n\t\t\t\t\t\t\t[ action.recordId ]: {\n\t\t\t\t\t\t\t\tpending:\n\t\t\t\t\t\t\t\t\taction.type ===\n\t\t\t\t\t\t\t\t\t'DELETE_ENTITY_RECORD_START',\n\t\t\t\t\t\t\t\terror: action.error,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn state;\n\t\t\t},\n\t\t} )\n\t);\n}\n\n/**\n * Reducer keeping track of the registered entities.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function entitiesConfig( state = rootEntitiesConfig, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ADD_ENTITIES':\n\t\t\treturn [ ...state, ...action.entities ];\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer keeping track of the registered entities config and data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const entities = ( state = {}, action ) => {\n\tconst newConfig = entitiesConfig( state.config, action );\n\n\t// Generates a dynamic reducer for the entities.\n\tlet entitiesDataReducer = state.reducer;\n\tif ( ! entitiesDataReducer || newConfig !== state.config ) {\n\t\tconst entitiesByKind = groupBy( newConfig, 'kind' );\n\t\tentitiesDataReducer = combineReducers(\n\t\t\tObject.entries( entitiesByKind ).reduce(\n\t\t\t\t( memo, [ kind, subEntities ] ) => {\n\t\t\t\t\tconst kindReducer = combineReducers(\n\t\t\t\t\t\tsubEntities.reduce(\n\t\t\t\t\t\t\t( kindMemo, entityConfig ) => ( {\n\t\t\t\t\t\t\t\t...kindMemo,\n\t\t\t\t\t\t\t\t[ entityConfig.name ]: entity( entityConfig ),\n\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\n\t\t\t\t\tmemo[ kind ] = kindReducer;\n\t\t\t\t\treturn memo;\n\t\t\t\t},\n\t\t\t\t{}\n\t\t\t)\n\t\t);\n\t}\n\n\tconst newData = entitiesDataReducer( state.records, action );\n\n\tif (\n\t\tnewData === state.records &&\n\t\tnewConfig === state.config &&\n\t\tentitiesDataReducer === state.reducer\n\t) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\treducer: entitiesDataReducer,\n\t\trecords: newData,\n\t\tconfig: newConfig,\n\t};\n};\n\n/**\n * @typedef {Object} UndoStateMeta\n *\n * @property {number} offset Where in the undo stack we are.\n * @property {Object} [flattenedUndo] Flattened form of undo stack.\n */\n\n/** @typedef {Array<Object> & UndoStateMeta} UndoState */\n\n/**\n * @type {UndoState}\n *\n * @todo Given how we use this we might want to make a custom class for it.\n */\nconst UNDO_INITIAL_STATE = Object.assign( [], { offset: 0 } );\n\n/** @type {Object} */\nlet lastEditAction;\n\n/**\n * Reducer keeping track of entity edit undo history.\n *\n * @param {UndoState} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {UndoState} Updated state.\n */\nexport function undo( state = UNDO_INITIAL_STATE, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'EDIT_ENTITY_RECORD':\n\t\tcase 'CREATE_UNDO_LEVEL':\n\t\t\tlet isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL';\n\t\t\tconst isUndoOrRedo =\n\t\t\t\t! isCreateUndoLevel &&\n\t\t\t\t( action.meta.isUndo || action.meta.isRedo );\n\t\t\tif ( isCreateUndoLevel ) {\n\t\t\t\taction = lastEditAction;\n\t\t\t} else if ( ! isUndoOrRedo ) {\n\t\t\t\t// Don't lose the last edit cache if the new one only has transient edits.\n\t\t\t\t// Transient edits don't create new levels so updating the cache would make\n\t\t\t\t// us skip an edit later when creating levels explicitly.\n\t\t\t\tif (\n\t\t\t\t\tObject.keys( action.edits ).some(\n\t\t\t\t\t\t( key ) => ! action.transientEdits[ key ]\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tlastEditAction = action;\n\t\t\t\t} else {\n\t\t\t\t\tlastEditAction = {\n\t\t\t\t\t\t...action,\n\t\t\t\t\t\tedits: {\n\t\t\t\t\t\t\t...( lastEditAction && lastEditAction.edits ),\n\t\t\t\t\t\t\t...action.edits,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/** @type {UndoState} */\n\t\t\tlet nextState;\n\n\t\t\tif ( isUndoOrRedo ) {\n\t\t\t\t// @ts-ignore we might consider using Object.assign({}, state)\n\t\t\t\tnextState = [ ...state ];\n\t\t\t\tnextState.offset =\n\t\t\t\t\tstate.offset + ( action.meta.isUndo ? -1 : 1 );\n\n\t\t\t\tif ( state.flattenedUndo ) {\n\t\t\t\t\t// The first undo in a sequence of undos might happen while we have\n\t\t\t\t\t// flattened undos in state. If this is the case, we want execution\n\t\t\t\t\t// to continue as if we were creating an explicit undo level. This\n\t\t\t\t\t// will result in an extra undo level being appended with the flattened\n\t\t\t\t\t// undo values.\n\t\t\t\t\t// We also have to take into account if the `lastEditAction` had opted out\n\t\t\t\t\t// of being tracked in undo history, like the action that persists the latest\n\t\t\t\t\t// content right before saving. In that case we have to update the `lastEditAction`\n\t\t\t\t\t// to avoid returning early before applying the existing flattened undos.\n\t\t\t\t\tisCreateUndoLevel = true;\n\t\t\t\t\tif ( ! lastEditAction.meta.undo ) {\n\t\t\t\t\t\tlastEditAction.meta.undo = {\n\t\t\t\t\t\t\tedits: {},\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\taction = lastEditAction;\n\t\t\t\t} else {\n\t\t\t\t\treturn nextState;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! action.meta.undo ) {\n\t\t\t\treturn state;\n\t\t\t}\n\n\t\t\t// Transient edits don't create an undo level, but are\n\t\t\t// reachable in the next meaningful edit to which they\n\t\t\t// are merged. They are defined in the entity's config.\n\t\t\tif (\n\t\t\t\t! isCreateUndoLevel &&\n\t\t\t\t! Object.keys( action.edits ).some(\n\t\t\t\t\t( key ) => ! action.transientEdits[ key ]\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\t// @ts-ignore we might consider using Object.assign({}, state)\n\t\t\t\tnextState = [ ...state ];\n\t\t\t\tnextState.flattenedUndo = {\n\t\t\t\t\t...state.flattenedUndo,\n\t\t\t\t\t...action.edits,\n\t\t\t\t};\n\t\t\t\tnextState.offset = state.offset;\n\t\t\t\treturn nextState;\n\t\t\t}\n\n\t\t\t// Clear potential redos, because this only supports linear history.\n\t\t\tnextState =\n\t\t\t\t// @ts-ignore this needs additional cleanup, probably involving code-level changes\n\t\t\t\tnextState || state.slice( 0, state.offset || undefined );\n\t\t\tnextState.offset = nextState.offset || 0;\n\t\t\tnextState.pop();\n\t\t\tif ( ! isCreateUndoLevel ) {\n\t\t\t\tnextState.push( {\n\t\t\t\t\tkind: action.meta.undo.kind,\n\t\t\t\t\tname: action.meta.undo.name,\n\t\t\t\t\trecordId: action.meta.undo.recordId,\n\t\t\t\t\tedits: {\n\t\t\t\t\t\t...state.flattenedUndo,\n\t\t\t\t\t\t...action.meta.undo.edits,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t\t// When an edit is a function it's an optimization to avoid running some expensive operation.\n\t\t\t// We can't rely on the function references being the same so we opt out of comparing them here.\n\t\t\tconst comparisonUndoEdits = Object.values(\n\t\t\t\taction.meta.undo.edits\n\t\t\t).filter( ( edit ) => typeof edit !== 'function' );\n\t\t\tconst comparisonEdits = Object.values( action.edits ).filter(\n\t\t\t\t( edit ) => typeof edit !== 'function'\n\t\t\t);\n\t\t\tif ( ! isShallowEqual( comparisonUndoEdits, comparisonEdits ) ) {\n\t\t\t\tnextState.push( {\n\t\t\t\t\tkind: action.kind,\n\t\t\t\t\tname: action.name,\n\t\t\t\t\trecordId: action.recordId,\n\t\t\t\t\tedits: isCreateUndoLevel\n\t\t\t\t\t\t? { ...state.flattenedUndo, ...action.edits }\n\t\t\t\t\t\t: action.edits,\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer managing embed preview data.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function embedPreviews( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_EMBED_PREVIEW':\n\t\t\tconst { url, preview } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ url ]: preview,\n\t\t\t};\n\t}\n\treturn state;\n}\n\n/**\n * State which tracks whether the user can perform an action on a REST\n * resource.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function userPermissions( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_USER_PERMISSION':\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ action.key ]: action.isAllowed,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer returning autosaves keyed by their parent's post id.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport function autosaves( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_AUTOSAVES':\n\t\t\tconst { postId, autosaves: autosavesData } = action;\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ postId ]: autosavesData,\n\t\t\t};\n\t}\n\n\treturn state;\n}\n\nexport function blockPatterns( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERNS':\n\t\t\treturn action.patterns;\n\t}\n\n\treturn state;\n}\n\nexport function blockPatternCategories( state = [], action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_BLOCK_PATTERN_CATEGORIES':\n\t\t\treturn action.categories;\n\t}\n\n\treturn state;\n}\n\nexport default combineReducers( {\n\tterms,\n\tusers,\n\tcurrentTheme,\n\tcurrentGlobalStylesId,\n\tcurrentUser,\n\tthemeGlobalStyleVariations,\n\tthemeBaseGlobalStyles,\n\ttaxonomies,\n\tentities,\n\tundo,\n\tembedPreviews,\n\tuserPermissions,\n\tautosaves,\n\tblockPatterns,\n\tblockPatternCategories,\n} );\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
|
-
import { set, get } from 'lodash';
|
|
6
5
|
/**
|
|
7
6
|
* WordPress dependencies
|
|
8
7
|
*/
|
|
@@ -17,7 +16,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
17
16
|
import { STORE_NAME } from './name';
|
|
18
17
|
import { getQueriedItems } from './queried-data';
|
|
19
18
|
import { DEFAULT_ENTITY_KEY } from './entities';
|
|
20
|
-
import { getNormalizedCommaSeparable, isRawAttribute } from './utils';
|
|
19
|
+
import { getNormalizedCommaSeparable, isRawAttribute, setNestedValue } from './utils';
|
|
21
20
|
|
|
22
21
|
/**
|
|
23
22
|
* Shared reference to an empty object for cases where it is important to avoid
|
|
@@ -187,9 +186,9 @@ export function getEntityConfig(state, kind, name) {
|
|
|
187
186
|
* @return Record.
|
|
188
187
|
*/
|
|
189
188
|
export const getEntityRecord = createSelector((state, kind, name, key, query) => {
|
|
190
|
-
var _query$context, _queriedState$items$c;
|
|
189
|
+
var _state$entities$recor, _state$entities$recor2, _state$entities$recor3, _query$context, _queriedState$items$c;
|
|
191
190
|
|
|
192
|
-
const queriedState =
|
|
191
|
+
const queriedState = (_state$entities$recor = state.entities.records) === null || _state$entities$recor === void 0 ? void 0 : (_state$entities$recor2 = _state$entities$recor[kind]) === null || _state$entities$recor2 === void 0 ? void 0 : (_state$entities$recor3 = _state$entities$recor2[name]) === null || _state$entities$recor3 === void 0 ? void 0 : _state$entities$recor3.queriedData;
|
|
193
192
|
|
|
194
193
|
if (!queriedState) {
|
|
195
194
|
return undefined;
|
|
@@ -218,8 +217,11 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
|
|
|
218
217
|
|
|
219
218
|
for (let f = 0; f < fields.length; f++) {
|
|
220
219
|
const field = fields[f].split('.');
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
let value = item;
|
|
221
|
+
field.forEach(fieldName => {
|
|
222
|
+
value = value[fieldName];
|
|
223
|
+
});
|
|
224
|
+
setNestedValue(filteredItem, field, value);
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
return filteredItem;
|
|
@@ -227,10 +229,10 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
|
|
|
227
229
|
|
|
228
230
|
return item;
|
|
229
231
|
}, (state, kind, name, recordId, query) => {
|
|
230
|
-
var _query$context2;
|
|
232
|
+
var _query$context2, _state$entities$recor4, _state$entities$recor5, _state$entities$recor6, _state$entities$recor7, _state$entities$recor8, _state$entities$recor9, _state$entities$recor10, _state$entities$recor11, _state$entities$recor12, _state$entities$recor13;
|
|
231
233
|
|
|
232
234
|
const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
233
|
-
return [
|
|
235
|
+
return [(_state$entities$recor4 = state.entities.records) === null || _state$entities$recor4 === void 0 ? void 0 : (_state$entities$recor5 = _state$entities$recor4[kind]) === null || _state$entities$recor5 === void 0 ? void 0 : (_state$entities$recor6 = _state$entities$recor5[name]) === null || _state$entities$recor6 === void 0 ? void 0 : (_state$entities$recor7 = _state$entities$recor6.queriedData) === null || _state$entities$recor7 === void 0 ? void 0 : (_state$entities$recor8 = _state$entities$recor7.items[context]) === null || _state$entities$recor8 === void 0 ? void 0 : _state$entities$recor8[recordId], (_state$entities$recor9 = state.entities.records) === null || _state$entities$recor9 === void 0 ? void 0 : (_state$entities$recor10 = _state$entities$recor9[kind]) === null || _state$entities$recor10 === void 0 ? void 0 : (_state$entities$recor11 = _state$entities$recor10[name]) === null || _state$entities$recor11 === void 0 ? void 0 : (_state$entities$recor12 = _state$entities$recor11.queriedData) === null || _state$entities$recor12 === void 0 ? void 0 : (_state$entities$recor13 = _state$entities$recor12.itemIsComplete[context]) === null || _state$entities$recor13 === void 0 ? void 0 : _state$entities$recor13[recordId]];
|
|
234
236
|
});
|
|
235
237
|
/**
|
|
236
238
|
* Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
|
|
@@ -262,10 +264,12 @@ export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
|
262
264
|
const record = getEntityRecord(state, kind, name, key);
|
|
263
265
|
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
264
266
|
if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
|
|
267
|
+
var _record$_key$raw, _record$_key;
|
|
268
|
+
|
|
265
269
|
// Because edits are the "raw" attribute values,
|
|
266
270
|
// we return those from record selectors to make rendering,
|
|
267
271
|
// comparisons, and joins with edits easier.
|
|
268
|
-
accumulator[_key] =
|
|
272
|
+
accumulator[_key] = (_record$_key$raw = (_record$_key = record[_key]) === null || _record$_key === void 0 ? void 0 : _record$_key.raw) !== null && _record$_key$raw !== void 0 ? _record$_key$raw : record[_key];
|
|
269
273
|
} else {
|
|
270
274
|
accumulator[_key] = record[_key];
|
|
271
275
|
}
|
|
@@ -273,10 +277,10 @@ export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
|
273
277
|
return accumulator;
|
|
274
278
|
}, {});
|
|
275
279
|
}, (state, kind, name, recordId, query) => {
|
|
276
|
-
var _query$context3;
|
|
280
|
+
var _query$context3, _state$entities$recor14, _state$entities$recor15, _state$entities$recor16, _state$entities$recor17, _state$entities$recor18, _state$entities$recor19, _state$entities$recor20, _state$entities$recor21, _state$entities$recor22, _state$entities$recor23;
|
|
277
281
|
|
|
278
282
|
const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
|
|
279
|
-
return [state.entities.config,
|
|
283
|
+
return [state.entities.config, (_state$entities$recor14 = state.entities.records) === null || _state$entities$recor14 === void 0 ? void 0 : (_state$entities$recor15 = _state$entities$recor14[kind]) === null || _state$entities$recor15 === void 0 ? void 0 : (_state$entities$recor16 = _state$entities$recor15[name]) === null || _state$entities$recor16 === void 0 ? void 0 : (_state$entities$recor17 = _state$entities$recor16.queriedData) === null || _state$entities$recor17 === void 0 ? void 0 : (_state$entities$recor18 = _state$entities$recor17.items[context]) === null || _state$entities$recor18 === void 0 ? void 0 : _state$entities$recor18[recordId], (_state$entities$recor19 = state.entities.records) === null || _state$entities$recor19 === void 0 ? void 0 : (_state$entities$recor20 = _state$entities$recor19[kind]) === null || _state$entities$recor20 === void 0 ? void 0 : (_state$entities$recor21 = _state$entities$recor20[name]) === null || _state$entities$recor21 === void 0 ? void 0 : (_state$entities$recor22 = _state$entities$recor21.queriedData) === null || _state$entities$recor22 === void 0 ? void 0 : (_state$entities$recor23 = _state$entities$recor22.itemIsComplete[context]) === null || _state$entities$recor23 === void 0 ? void 0 : _state$entities$recor23[recordId]];
|
|
280
284
|
});
|
|
281
285
|
/**
|
|
282
286
|
* Returns true if records have been received for the given set of parameters,
|
|
@@ -314,9 +318,11 @@ export function hasEntityRecords(state, kind, name, query) {
|
|
|
314
318
|
* @return Records.
|
|
315
319
|
*/
|
|
316
320
|
export const getEntityRecords = (state, kind, name, query) => {
|
|
321
|
+
var _state$entities$recor24, _state$entities$recor25, _state$entities$recor26;
|
|
322
|
+
|
|
317
323
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
318
324
|
// assigned for the given parameters, then it is known to not exist.
|
|
319
|
-
const queriedState =
|
|
325
|
+
const queriedState = (_state$entities$recor24 = state.entities.records) === null || _state$entities$recor24 === void 0 ? void 0 : (_state$entities$recor25 = _state$entities$recor24[kind]) === null || _state$entities$recor25 === void 0 ? void 0 : (_state$entities$recor26 = _state$entities$recor25[name]) === null || _state$entities$recor26 === void 0 ? void 0 : _state$entities$recor26.queriedData;
|
|
320
326
|
|
|
321
327
|
if (!queriedState) {
|
|
322
328
|
return null;
|
|
@@ -416,7 +422,9 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
|
|
|
416
422
|
*/
|
|
417
423
|
|
|
418
424
|
export function getEntityRecordEdits(state, kind, name, recordId) {
|
|
419
|
-
|
|
425
|
+
var _state$entities$recor27, _state$entities$recor28, _state$entities$recor29, _state$entities$recor30;
|
|
426
|
+
|
|
427
|
+
return (_state$entities$recor27 = state.entities.records) === null || _state$entities$recor27 === void 0 ? void 0 : (_state$entities$recor28 = _state$entities$recor27[kind]) === null || _state$entities$recor28 === void 0 ? void 0 : (_state$entities$recor29 = _state$entities$recor28[name]) === null || _state$entities$recor29 === void 0 ? void 0 : (_state$entities$recor30 = _state$entities$recor29.edits) === null || _state$entities$recor30 === void 0 ? void 0 : _state$entities$recor30[recordId];
|
|
420
428
|
}
|
|
421
429
|
/**
|
|
422
430
|
* Returns the specified entity record's non transient edits.
|
|
@@ -450,7 +458,11 @@ export const getEntityRecordNonTransientEdits = createSelector((state, kind, nam
|
|
|
450
458
|
|
|
451
459
|
return acc;
|
|
452
460
|
}, {});
|
|
453
|
-
}, (state, kind, name, recordId) =>
|
|
461
|
+
}, (state, kind, name, recordId) => {
|
|
462
|
+
var _state$entities$recor31, _state$entities$recor32, _state$entities$recor33, _state$entities$recor34;
|
|
463
|
+
|
|
464
|
+
return [state.entities.config, (_state$entities$recor31 = state.entities.records) === null || _state$entities$recor31 === void 0 ? void 0 : (_state$entities$recor32 = _state$entities$recor31[kind]) === null || _state$entities$recor32 === void 0 ? void 0 : (_state$entities$recor33 = _state$entities$recor32[name]) === null || _state$entities$recor33 === void 0 ? void 0 : (_state$entities$recor34 = _state$entities$recor33.edits) === null || _state$entities$recor34 === void 0 ? void 0 : _state$entities$recor34[recordId]];
|
|
465
|
+
});
|
|
454
466
|
/**
|
|
455
467
|
* Returns true if the specified entity record has edits,
|
|
456
468
|
* and false otherwise.
|
|
@@ -480,10 +492,10 @@ export function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
480
492
|
export const getEditedEntityRecord = createSelector((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
481
493
|
...getEntityRecordEdits(state, kind, name, recordId)
|
|
482
494
|
}), (state, kind, name, recordId, query) => {
|
|
483
|
-
var _query$context4;
|
|
495
|
+
var _query$context4, _state$entities$recor35, _state$entities$recor36, _state$entities$recor37, _state$entities$recor38, _state$entities$recor39, _state$entities$recor40, _state$entities$recor41, _state$entities$recor42, _state$entities$recor43, _state$entities$recor44, _state$entities$recor45, _state$entities$recor46;
|
|
484
496
|
|
|
485
497
|
const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
|
|
486
|
-
return [state.entities.config,
|
|
498
|
+
return [state.entities.config, (_state$entities$recor35 = state.entities.records) === null || _state$entities$recor35 === void 0 ? void 0 : (_state$entities$recor36 = _state$entities$recor35[kind]) === null || _state$entities$recor36 === void 0 ? void 0 : (_state$entities$recor37 = _state$entities$recor36[name]) === null || _state$entities$recor37 === void 0 ? void 0 : (_state$entities$recor38 = _state$entities$recor37.queriedData.items[context]) === null || _state$entities$recor38 === void 0 ? void 0 : _state$entities$recor38[recordId], (_state$entities$recor39 = state.entities.records) === null || _state$entities$recor39 === void 0 ? void 0 : (_state$entities$recor40 = _state$entities$recor39[kind]) === null || _state$entities$recor40 === void 0 ? void 0 : (_state$entities$recor41 = _state$entities$recor40[name]) === null || _state$entities$recor41 === void 0 ? void 0 : (_state$entities$recor42 = _state$entities$recor41.queriedData.itemIsComplete[context]) === null || _state$entities$recor42 === void 0 ? void 0 : _state$entities$recor42[recordId], (_state$entities$recor43 = state.entities.records) === null || _state$entities$recor43 === void 0 ? void 0 : (_state$entities$recor44 = _state$entities$recor43[kind]) === null || _state$entities$recor44 === void 0 ? void 0 : (_state$entities$recor45 = _state$entities$recor44[name]) === null || _state$entities$recor45 === void 0 ? void 0 : (_state$entities$recor46 = _state$entities$recor45.edits) === null || _state$entities$recor46 === void 0 ? void 0 : _state$entities$recor46[recordId]];
|
|
487
499
|
});
|
|
488
500
|
/**
|
|
489
501
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
@@ -497,10 +509,12 @@ export const getEditedEntityRecord = createSelector((state, kind, name, recordId
|
|
|
497
509
|
*/
|
|
498
510
|
|
|
499
511
|
export function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
512
|
+
var _state$entities$recor47, _state$entities$recor48, _state$entities$recor49, _state$entities$recor50, _state$entities$recor51;
|
|
513
|
+
|
|
500
514
|
const {
|
|
501
515
|
pending,
|
|
502
516
|
isAutosave
|
|
503
|
-
} =
|
|
517
|
+
} = (_state$entities$recor47 = (_state$entities$recor48 = state.entities.records) === null || _state$entities$recor48 === void 0 ? void 0 : (_state$entities$recor49 = _state$entities$recor48[kind]) === null || _state$entities$recor49 === void 0 ? void 0 : (_state$entities$recor50 = _state$entities$recor49[name]) === null || _state$entities$recor50 === void 0 ? void 0 : (_state$entities$recor51 = _state$entities$recor50.saving) === null || _state$entities$recor51 === void 0 ? void 0 : _state$entities$recor51[recordId]) !== null && _state$entities$recor47 !== void 0 ? _state$entities$recor47 : {};
|
|
504
518
|
return Boolean(pending && isAutosave);
|
|
505
519
|
}
|
|
506
520
|
/**
|
|
@@ -515,7 +529,9 @@ export function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
|
515
529
|
*/
|
|
516
530
|
|
|
517
531
|
export function isSavingEntityRecord(state, kind, name, recordId) {
|
|
518
|
-
|
|
532
|
+
var _state$entities$recor52, _state$entities$recor53, _state$entities$recor54, _state$entities$recor55, _state$entities$recor56, _state$entities$recor57;
|
|
533
|
+
|
|
534
|
+
return (_state$entities$recor52 = (_state$entities$recor53 = state.entities.records) === null || _state$entities$recor53 === void 0 ? void 0 : (_state$entities$recor54 = _state$entities$recor53[kind]) === null || _state$entities$recor54 === void 0 ? void 0 : (_state$entities$recor55 = _state$entities$recor54[name]) === null || _state$entities$recor55 === void 0 ? void 0 : (_state$entities$recor56 = _state$entities$recor55.saving) === null || _state$entities$recor56 === void 0 ? void 0 : (_state$entities$recor57 = _state$entities$recor56[recordId]) === null || _state$entities$recor57 === void 0 ? void 0 : _state$entities$recor57.pending) !== null && _state$entities$recor52 !== void 0 ? _state$entities$recor52 : false;
|
|
519
535
|
}
|
|
520
536
|
/**
|
|
521
537
|
* Returns true if the specified entity record is deleting, and false otherwise.
|
|
@@ -529,7 +545,9 @@ export function isSavingEntityRecord(state, kind, name, recordId) {
|
|
|
529
545
|
*/
|
|
530
546
|
|
|
531
547
|
export function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
532
|
-
|
|
548
|
+
var _state$entities$recor58, _state$entities$recor59, _state$entities$recor60, _state$entities$recor61, _state$entities$recor62, _state$entities$recor63;
|
|
549
|
+
|
|
550
|
+
return (_state$entities$recor58 = (_state$entities$recor59 = state.entities.records) === null || _state$entities$recor59 === void 0 ? void 0 : (_state$entities$recor60 = _state$entities$recor59[kind]) === null || _state$entities$recor60 === void 0 ? void 0 : (_state$entities$recor61 = _state$entities$recor60[name]) === null || _state$entities$recor61 === void 0 ? void 0 : (_state$entities$recor62 = _state$entities$recor61.deleting) === null || _state$entities$recor62 === void 0 ? void 0 : (_state$entities$recor63 = _state$entities$recor62[recordId]) === null || _state$entities$recor63 === void 0 ? void 0 : _state$entities$recor63.pending) !== null && _state$entities$recor58 !== void 0 ? _state$entities$recor58 : false;
|
|
533
551
|
}
|
|
534
552
|
/**
|
|
535
553
|
* Returns the specified entity record's last save error.
|
|
@@ -543,7 +561,9 @@ export function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
|
543
561
|
*/
|
|
544
562
|
|
|
545
563
|
export function getLastEntitySaveError(state, kind, name, recordId) {
|
|
546
|
-
|
|
564
|
+
var _state$entities$recor64, _state$entities$recor65, _state$entities$recor66, _state$entities$recor67, _state$entities$recor68;
|
|
565
|
+
|
|
566
|
+
return (_state$entities$recor64 = state.entities.records) === null || _state$entities$recor64 === void 0 ? void 0 : (_state$entities$recor65 = _state$entities$recor64[kind]) === null || _state$entities$recor65 === void 0 ? void 0 : (_state$entities$recor66 = _state$entities$recor65[name]) === null || _state$entities$recor66 === void 0 ? void 0 : (_state$entities$recor67 = _state$entities$recor66.saving) === null || _state$entities$recor67 === void 0 ? void 0 : (_state$entities$recor68 = _state$entities$recor67[recordId]) === null || _state$entities$recor68 === void 0 ? void 0 : _state$entities$recor68.error;
|
|
547
567
|
}
|
|
548
568
|
/**
|
|
549
569
|
* Returns the specified entity record's last delete error.
|
|
@@ -557,7 +577,9 @@ export function getLastEntitySaveError(state, kind, name, recordId) {
|
|
|
557
577
|
*/
|
|
558
578
|
|
|
559
579
|
export function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
560
|
-
|
|
580
|
+
var _state$entities$recor69, _state$entities$recor70, _state$entities$recor71, _state$entities$recor72, _state$entities$recor73;
|
|
581
|
+
|
|
582
|
+
return (_state$entities$recor69 = state.entities.records) === null || _state$entities$recor69 === void 0 ? void 0 : (_state$entities$recor70 = _state$entities$recor69[kind]) === null || _state$entities$recor70 === void 0 ? void 0 : (_state$entities$recor71 = _state$entities$recor70[name]) === null || _state$entities$recor71 === void 0 ? void 0 : (_state$entities$recor72 = _state$entities$recor71.deleting) === null || _state$entities$recor72 === void 0 ? void 0 : (_state$entities$recor73 = _state$entities$recor72[recordId]) === null || _state$entities$recor73 === void 0 ? void 0 : _state$entities$recor73.error;
|
|
561
583
|
}
|
|
562
584
|
/**
|
|
563
585
|
* Returns the current undo offset for the
|
|
@@ -713,7 +735,7 @@ export function isPreviewEmbedFallback(state, url) {
|
|
|
713
735
|
|
|
714
736
|
export function canUser(state, action, resource, id) {
|
|
715
737
|
const key = [action, resource, id].filter(Boolean).join('/');
|
|
716
|
-
return
|
|
738
|
+
return state.userPermissions[key];
|
|
717
739
|
}
|
|
718
740
|
/**
|
|
719
741
|
* Returns whether the current user can edit the given entity.
|