@wordpress/core-data 4.2.1 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +68 -11
- package/build/actions.js +61 -41
- package/build/actions.js.map +1 -1
- package/build/batch/default-processor.js +1 -1
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +36 -23
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +46 -44
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/{base-entity-types.js → base-entity-records.js} +9 -9
- package/build/entity-types/base-entity-records.js.map +1 -0
- package/build/fetch/__experimental-fetch-link-suggestions.js +48 -11
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +1 -1
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/hooks/use-entity-record.js +15 -5
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +14 -2
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/index.js +9 -21
- package/build/index.js.map +1 -1
- package/build/queried-data/actions.js +4 -4
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +7 -3
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/reducer.js +8 -6
- package/build/queried-data/reducer.js.map +1 -1
- package/build/reducer.js +77 -25
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +60 -24
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +122 -55
- package/build/selectors.js.map +1 -1
- package/build/types.js +6 -0
- package/build/types.js.map +1 -0
- package/build/utils/conservative-map-item.js +1 -1
- package/build/utils/conservative-map-item.js.map +1 -1
- package/build/utils/if-matching-action.js +4 -2
- package/build/utils/if-matching-action.js.map +1 -1
- package/build/utils/is-raw-attribute.js +1 -1
- package/build/utils/is-raw-attribute.js.map +1 -1
- package/build/utils/on-sub-key.js +3 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/replace-action.js +4 -2
- package/build/utils/replace-action.js.map +1 -1
- package/build-module/actions.js +62 -42
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/default-processor.js +1 -1
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +32 -19
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +47 -45
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/{base-entity-types.js → base-entity-records.js} +7 -7
- package/build-module/entity-types/base-entity-records.js.map +1 -0
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +48 -11
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +15 -5
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +14 -2
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/index.js +10 -22
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/actions.js +4 -4
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +7 -3
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/reducer.js +8 -6
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/reducer.js +75 -26
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +55 -25
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +114 -55
- package/build-module/selectors.js.map +1 -1
- package/build-module/types.js +2 -0
- package/build-module/types.js.map +1 -0
- package/build-module/utils/conservative-map-item.js +1 -1
- package/build-module/utils/conservative-map-item.js.map +1 -1
- package/build-module/utils/if-matching-action.js +4 -2
- package/build-module/utils/if-matching-action.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js +1 -1
- package/build-module/utils/is-raw-attribute.js.map +1 -1
- package/build-module/utils/on-sub-key.js +3 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/replace-action.js +4 -2
- package/build-module/utils/replace-action.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.js +62 -42
- package/src/batch/default-processor.js +1 -0
- package/src/{entities.js → entities.ts} +50 -21
- package/src/entity-provider.js +50 -44
- package/src/entity-types/attachment.ts +5 -5
- package/src/entity-types/{base-entity-types.ts → base-entity-records.ts} +5 -5
- package/src/entity-types/comment.ts +5 -5
- package/src/entity-types/helpers.ts +1 -1
- package/src/entity-types/index.ts +4 -4
- package/src/entity-types/menu-location.ts +5 -5
- package/src/entity-types/nav-menu-item.ts +10 -5
- package/src/entity-types/nav-menu.ts +5 -5
- package/src/entity-types/navigation-area.ts +5 -5
- package/src/entity-types/page.ts +5 -5
- package/src/entity-types/plugin.ts +10 -5
- package/src/entity-types/post.ts +5 -5
- package/src/entity-types/settings.ts +10 -5
- package/src/entity-types/sidebar.ts +6 -7
- package/src/entity-types/taxonomy.ts +5 -5
- package/src/entity-types/theme.ts +5 -5
- package/src/entity-types/type.ts +5 -5
- package/src/entity-types/user.ts +10 -5
- package/src/entity-types/widget-type.ts +5 -5
- package/src/entity-types/widget.ts +5 -5
- package/src/entity-types/wp-template-part.ts +5 -5
- package/src/entity-types/wp-template.ts +5 -5
- package/src/fetch/__experimental-fetch-link-suggestions.js +56 -20
- package/src/fetch/__experimental-fetch-url-data.js +1 -0
- package/src/fetch/test/__experimental-fetch-link-suggestions.js +39 -1
- package/src/hooks/use-entity-record.ts +19 -8
- package/src/hooks/use-entity-records.ts +23 -6
- package/src/hooks/use-query-select.ts +12 -7
- package/src/index.js +10 -15
- package/src/locks/test/selectors.js +4 -4
- package/src/queried-data/actions.js +4 -4
- package/src/queried-data/get-query-parts.js +5 -5
- package/src/queried-data/reducer.js +6 -6
- package/src/reducer.js +67 -24
- package/src/resolvers.js +52 -31
- package/src/{selectors.js → selectors.ts} +118 -57
- package/src/test/actions.js +138 -33
- package/src/test/entities.js +11 -11
- package/src/test/reducer.js +4 -4
- package/src/test/resolvers.js +5 -5
- package/src/test/selectors.js +22 -22
- package/src/types.ts +3 -0
- package/src/utils/conservative-map-item.js +1 -1
- package/src/utils/if-matching-action.js +4 -2
- package/src/utils/is-raw-attribute.js +1 -1
- package/src/utils/on-sub-key.js +3 -1
- package/src/utils/replace-action.js +4 -2
- package/src/utils/test/is-raw-attribute.js +4 -4
- package/build/entity-types/base-entity-types.js.map +0 -1
- package/build-module/entity-types/base-entity-types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["useSelect","memoize","Status","META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Resolving","Success","Error","Idle"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,SAASC,MAAT,QAAuB,aAAvB;AAEA,OAAO,MAAMC,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,4BAAT,CAAuCC,cAAvC,EAAuDC,IAAvD,EAA8D;AAC5E,SAAON,SAAS,CAAE,CAAEO,MAAF,EAAUC,QAAV,KAAwB;AACzC,UAAMC,OAAO,GAAKC,KAAF,IAAaC,eAAe,CAAEJ,MAAM,CAAEG,KAAF,CAAR,CAA5C;;AACA,WAAOL,cAAc,CAAEI,OAAF,EAAWD,QAAX,CAArB;AACA,GAHe,EAGbF,IAHa,CAAhB;AAIA;;
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"names":["useSelect","memoize","Status","META_SELECTORS","__experimentalUseQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","getIsResolving","hasFinishedResolution","args","isResolving","hasResolved","data","status","Resolving","Success","Error","Idle"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,iBAA1B;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,SAASC,MAAT,QAAuB,aAAvB;AAEA,OAAO,MAAMC,cAAc,GAAG,CAC7B,gBAD6B,EAE7B,sBAF6B,EAG7B,uBAH6B,EAI7B,aAJ6B,EAK7B,oBAL6B,CAAvB;;AAsBP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,4BAAT,CAAuCC,cAAvC,EAAuDC,IAAvD,EAA8D;AAC5E,SAAON,SAAS,CAAE,CAAEO,MAAF,EAAUC,QAAV,KAAwB;AACzC,UAAMC,OAAO,GAAKC,KAAF,IAAaC,eAAe,CAAEJ,MAAM,CAAEG,KAAF,CAAR,CAA5C;;AACA,WAAOL,cAAc,CAAEI,OAAF,EAAWD,QAAX,CAArB;AACA,GAHe,EAGbF,IAHa,CAAhB;AAIA;;AAYD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMK,eAAe,GAAGV,OAAO,CAAMW,SAAF,IAAiB;AACnD,QAAMC,SAAS,GAAG,EAAlB;;AACA,OAAM,MAAMC,YAAZ,IAA4BF,SAA5B,EAAwC;AACvC,QAAKT,cAAc,CAACY,QAAf,CAAyBD,YAAzB,CAAL,EAA+C;AAC9C;AACA;;AACDE,IAAAA,MAAM,CAACC,cAAP,CAAuBJ,SAAvB,EAAkCC,YAAlC,EAAgD;AAC/CI,MAAAA,GAAG,EAAE,MAAM,YAA0B;AACpC,cAAM;AAAEC,UAAAA,cAAF;AAAkBC,UAAAA;AAAlB,YAA4CR,SAAlD;;AADoC,0CAArBS,IAAqB;AAArBA,UAAAA,IAAqB;AAAA;;AAEpC,cAAMC,WAAW,GAAG,CAAC,CAAEH,cAAc,CAAEL,YAAF,EAAgBO,IAAhB,CAArC;AACA,cAAME,WAAW,GAChB,CAAED,WAAF,IACAF,qBAAqB,CAAEN,YAAF,EAAgBO,IAAhB,CAFtB;AAGA,cAAMG,IAAI,GAAGZ,SAAS,CAAEE,YAAF,CAAT,CAA2B,GAAGO,IAA9B,CAAb;AAEA,YAAII,MAAJ;;AACA,YAAKH,WAAL,EAAmB;AAClBG,UAAAA,MAAM,GAAGvB,MAAM,CAACwB,SAAhB;AACA,SAFD,MAEO,IAAKH,WAAL,EAAmB;AACzB,cAAKC,IAAL,EAAY;AACXC,YAAAA,MAAM,GAAGvB,MAAM,CAACyB,OAAhB;AACA,WAFD,MAEO;AACNF,YAAAA,MAAM,GAAGvB,MAAM,CAAC0B,KAAhB;AACA;AACD,SANM,MAMA;AACNH,UAAAA,MAAM,GAAGvB,MAAM,CAAC2B,IAAhB;AACA;;AAED,eAAO;AACNL,UAAAA,IADM;AAENC,UAAAA,MAFM;AAGNH,UAAAA,WAHM;AAINC,UAAAA;AAJM,SAAP;AAMA;AA5B8C,KAAhD;AA8BA;;AACD,SAAOV,SAAP;AACA,CAtC8B,CAA/B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `getIsResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function __experimentalUseQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget: () => ( ...args: unknown[] ) => {\n\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\tconst hasResolved =\n\t\t\t\t\t! isResolving &&\n\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\tlet status;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tdata,\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t};\n\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"]}
|
package/build-module/index.js
CHANGED
|
@@ -11,13 +11,13 @@ import * as selectors from './selectors';
|
|
|
11
11
|
import * as actions from './actions';
|
|
12
12
|
import * as resolvers from './resolvers';
|
|
13
13
|
import createLocksActions from './locks/actions';
|
|
14
|
-
import {
|
|
14
|
+
import { rootEntitiesConfig, getMethodName } from './entities';
|
|
15
15
|
import { STORE_NAME } from './name'; // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
|
|
16
|
-
// (getEntityRecord, getEntityRecords, updateEntityRecord,
|
|
17
|
-
// Instead of getEntityRecord, the consumer could use more user-
|
|
16
|
+
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
|
|
17
|
+
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
|
|
18
18
|
// The "kind" and the "name" of the entity are combined to generate these shortcuts.
|
|
19
19
|
|
|
20
|
-
const entitySelectors =
|
|
20
|
+
const entitySelectors = rootEntitiesConfig.reduce((result, entity) => {
|
|
21
21
|
const {
|
|
22
22
|
kind,
|
|
23
23
|
name
|
|
@@ -25,17 +25,11 @@ const entitySelectors = defaultEntities.reduce((result, entity) => {
|
|
|
25
25
|
|
|
26
26
|
result[getMethodName(kind, name)] = (state, key, query) => selectors.getEntityRecord(state, kind, name, key, query);
|
|
27
27
|
|
|
28
|
-
result[getMethodName(kind, name, 'get', true)] =
|
|
29
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
30
|
-
args[_key - 1] = arguments[_key];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return selectors.getEntityRecords(state, kind, name, ...args);
|
|
34
|
-
};
|
|
28
|
+
result[getMethodName(kind, name, 'get', true)] = (state, query) => selectors.getEntityRecords(state, kind, name, query);
|
|
35
29
|
|
|
36
30
|
return result;
|
|
37
31
|
}, {});
|
|
38
|
-
const entityResolvers =
|
|
32
|
+
const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
|
|
39
33
|
const {
|
|
40
34
|
kind,
|
|
41
35
|
name
|
|
@@ -46,24 +40,18 @@ const entityResolvers = defaultEntities.reduce((result, entity) => {
|
|
|
46
40
|
const pluralMethodName = getMethodName(kind, name, 'get', true);
|
|
47
41
|
|
|
48
42
|
result[pluralMethodName] = function () {
|
|
49
|
-
for (var
|
|
50
|
-
args[
|
|
43
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
44
|
+
args[_key] = arguments[_key];
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
return resolvers.getEntityRecords(kind, name, ...args);
|
|
54
48
|
};
|
|
55
49
|
|
|
56
|
-
result[pluralMethodName].shouldInvalidate =
|
|
57
|
-
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
58
|
-
args[_key3 - 1] = arguments[_key3];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return resolvers.getEntityRecords.shouldInvalidate(action, kind, name, ...args);
|
|
62
|
-
};
|
|
50
|
+
result[pluralMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
63
51
|
|
|
64
52
|
return result;
|
|
65
53
|
}, {});
|
|
66
|
-
const entityActions =
|
|
54
|
+
const entityActions = rootEntitiesConfig.reduce((result, entity) => {
|
|
67
55
|
const {
|
|
68
56
|
kind,
|
|
69
57
|
name
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","default","EntityProvider","__experimentalUseEntityRecord","__experimentalUseEntityRecords"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,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,OAAO,EAAE,EAAE,GAAGA,OAAL;AAAc,OAAGsB,aAAjB;AAAgC,OAAGpB,kBAAkB;AAArD,GAFkB;AAG3BH,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGO;AAAnB,GAHgB;AAI3BL,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGgB;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMS,KAAK,GAAG9B,gBAAgB,CAAES,UAAF,EAAcoB,WAAW,EAAzB,CAA9B;AAEP5B,QAAQ,CAAE6B,KAAF,CAAR;AAEA,SAASC,OAAO,IAAIC,cAApB,QAA0C,mBAA1C;AACA,SAASD,OAAO,IAAIE,6BAApB,QAAyD,2BAAzD;AACA,SAASF,OAAO,IAAIG,8BAApB,QAA0D,4BAA1D;AACA,cAAc,mBAAd;AACA,cAAc,SAAd;AACA,cAAc,gBAAd","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport { default as __experimentalUseEntityRecord } from './hooks/use-entity-record';\nexport { default as __experimentalUseEntityRecords } from './hooks/use-entity-records';\nexport * from './entity-provider';\nexport * from './fetch';\nexport * from './entity-types';\n"]}
|
|
@@ -22,10 +22,10 @@ export function receiveItems(items, edits) {
|
|
|
22
22
|
* Returns an action object used in signalling that entity records have been
|
|
23
23
|
* deleted and they need to be removed from entities state.
|
|
24
24
|
*
|
|
25
|
-
* @param {string}
|
|
26
|
-
* @param {string}
|
|
27
|
-
* @param {Array|number} records Record IDs of the removed entities.
|
|
28
|
-
* @param {boolean}
|
|
25
|
+
* @param {string} kind Kind of the removed entities.
|
|
26
|
+
* @param {string} name Name of the removed entities.
|
|
27
|
+
* @param {Array|number|string} records Record IDs of the removed entities.
|
|
28
|
+
* @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
|
|
29
29
|
* @return {Object} Action object.
|
|
30
30
|
*/
|
|
31
31
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/actions.js"],"names":["castArray","receiveItems","items","edits","type","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CAAuBC,KAAvB,EAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,KAAK,EAAEF,SAAS,CAAEE,KAAF,CAFV;AAGNG,IAAAA,cAAc,EAAEF;AAHV,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,WAAT,CAAsBC,IAAtB,EAA4BC,IAA5B,EAAkCC,OAAlC,EAAqE;AAAA,MAA1BC,eAA0B,uEAAR,KAAQ;AAC3E,SAAO;AACNN,IAAAA,IAAI,EAAE,cADA;AAENO,IAAAA,OAAO,EAAEX,SAAS,CAAES,OAAF,CAFZ;AAGNF,IAAAA,IAHM;AAINC,IAAAA,IAJM;AAKNE,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,mBAAT,CAA8BV,KAA9B,EAAyD;AAAA,MAApBW,KAAoB,uEAAZ,EAAY;AAAA,MAARV,KAAQ;AAC/D,SAAO,EACN,GAAGF,YAAY,CAAEC,KAAF,EAASC,KAAT,CADT;AAENU,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { castArray } from 'lodash';\n\n/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: castArray( items ),\n\t\tpersistedEdits: edits,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/actions.js"],"names":["castArray","receiveItems","items","edits","type","persistedEdits","removeItems","kind","name","records","invalidateCache","itemIds","receiveQueriedItems","query"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAT,QAA0B,QAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CAAuBC,KAAvB,EAA8BC,KAA9B,EAAsC;AAC5C,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAENF,IAAAA,KAAK,EAAEF,SAAS,CAAEE,KAAF,CAFV;AAGNG,IAAAA,cAAc,EAAEF;AAHV,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,WAAT,CAAsBC,IAAtB,EAA4BC,IAA5B,EAAkCC,OAAlC,EAAqE;AAAA,MAA1BC,eAA0B,uEAAR,KAAQ;AAC3E,SAAO;AACNN,IAAAA,IAAI,EAAE,cADA;AAENO,IAAAA,OAAO,EAAEX,SAAS,CAAES,OAAF,CAFZ;AAGNF,IAAAA,IAHM;AAINC,IAAAA,IAJM;AAKNE,IAAAA;AALM,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,mBAAT,CAA8BV,KAA9B,EAAyD;AAAA,MAApBW,KAAoB,uEAAZ,EAAY;AAAA,MAARV,KAAQ;AAC/D,SAAO,EACN,GAAGF,YAAY,CAAEC,KAAF,EAASC,KAAT,CADT;AAENU,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * External dependencies\n */\nimport { castArray } from 'lodash';\n\n/**\n * Returns an action object used in signalling that items have been received.\n *\n * @param {Array} items Items received.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveItems( items, edits ) {\n\treturn {\n\t\ttype: 'RECEIVE_ITEMS',\n\t\titems: castArray( items ),\n\t\tpersistedEdits: edits,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that entity records have been\n * deleted and they need to be removed from entities state.\n *\n * @param {string} kind Kind of the removed entities.\n * @param {string} name Name of the removed entities.\n * @param {Array|number|string} records Record IDs of the removed entities.\n * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.\n * @return {Object} Action object.\n */\nexport function removeItems( kind, name, records, invalidateCache = false ) {\n\treturn {\n\t\ttype: 'REMOVE_ITEMS',\n\t\titemIds: castArray( records ),\n\t\tkind,\n\t\tname,\n\t\tinvalidateCache,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that queried data has been\n * received.\n *\n * @param {Array} items Queried items received.\n * @param {?Object} query Optional query object.\n * @param {?Object} edits Optional edits to reset.\n *\n * @return {Object} Action object.\n */\nexport function receiveQueriedItems( items, query = {}, edits ) {\n\treturn {\n\t\t...receiveItems( items, edits ),\n\t\tquery,\n\t};\n}\n"]}
|
|
@@ -69,17 +69,21 @@ export function getQueryParts(query) {
|
|
|
69
69
|
// While in theory, we could exclude "_fields" from the stableKey
|
|
70
70
|
// because two request with different fields have the same results
|
|
71
71
|
// We're not able to ensure that because the server can decide to omit
|
|
72
|
-
// fields from the response even if we
|
|
72
|
+
// fields from the response even if we explicitly asked for it.
|
|
73
73
|
// Example: Asking for titles in posts without title support.
|
|
74
74
|
if (key === '_fields') {
|
|
75
|
-
|
|
75
|
+
var _getNormalizedCommaSe;
|
|
76
|
+
|
|
77
|
+
parts.fields = (_getNormalizedCommaSe = getNormalizedCommaSeparable(value)) !== null && _getNormalizedCommaSe !== void 0 ? _getNormalizedCommaSe : []; // Make sure to normalize value for `stableKey`
|
|
76
78
|
|
|
77
79
|
value = parts.fields.join();
|
|
78
80
|
} // Two requests with different include values cannot have same results.
|
|
79
81
|
|
|
80
82
|
|
|
81
83
|
if (key === 'include') {
|
|
82
|
-
|
|
84
|
+
var _getNormalizedCommaSe2;
|
|
85
|
+
|
|
86
|
+
parts.include = ((_getNormalizedCommaSe2 = getNormalizedCommaSeparable(value)) !== null && _getNormalizedCommaSe2 !== void 0 ? _getNormalizedCommaSe2 : []).map(Number); // Normalize value for `stableKey`.
|
|
83
87
|
|
|
84
88
|
value = parts.include.join();
|
|
85
89
|
} // While it could be any deterministic string, for simplicity's
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","map","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,2BAA3B,QAA8D,UAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBC,KAAxB,EAAgC;AACtC;AACD;AACA;AACC,QAAMC,KAAK,GAAG;AACbC,IAAAA,SAAS,EAAE,EADE;AAEbC,IAAAA,IAAI,EAAE,CAFO;AAGbC,IAAAA,OAAO,EAAE,EAHI;AAIbC,IAAAA,MAAM,EAAE,IAJK;AAKbC,IAAAA,OAAO,EAAE,IALI;AAMbC,IAAAA,OAAO,EAAE;AANI,GAAd,CAJsC,CAatC;;AACA,QAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAaR,KAAb,EAAqBU,IAArB,EAAb;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,GAAG,GAAGL,IAAI,CAAEG,CAAF,CAAhB;AACA,QAAIG,KAAK,GAAGd,KAAK,CAAEa,GAAF,CAAjB;;AAEA,YAASA,GAAT;AACC,WAAK,MAAL;AACCZ,QAAAA,KAAK,CAAEY,GAAF,CAAL,GAAeE,MAAM,CAAED,KAAF,CAArB;AACA;;AAED,WAAK,UAAL;AACCb,QAAAA,KAAK,CAACG,OAAN,GAAgBW,MAAM,CAAED,KAAF,CAAtB;AACA;;AAED,WAAK,SAAL;AACCb,QAAAA,KAAK,CAACM,OAAN,GAAgBO,KAAhB;AACA;;AAED;AACC;AACA;AACA;AACA;AACA;AACA,YAAKD,GAAG,KAAK,SAAb,EAAyB;AACxBZ,UAAAA,KAAK,CAACI,MAAN,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","map","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,2BAA3B,QAA8D,UAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBC,KAAxB,EAAgC;AACtC;AACD;AACA;AACC,QAAMC,KAAK,GAAG;AACbC,IAAAA,SAAS,EAAE,EADE;AAEbC,IAAAA,IAAI,EAAE,CAFO;AAGbC,IAA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;AACA;AACA;AACA;;;AACAf,QAAAA,KAAK,CAACC,SAAN,IACC,CAAED,KAAK,CAACC,SAAN,GAAkB,GAAlB,GAAwB,EAA1B,IACAN,YAAY,CAAE,EAAF,EAAM;AAAE,WAAEiB,GAAF,GAASC;AAAX,SAAN,CAAZ,CAAuCI,KAAvC,CAA8C,CAA9C,CAFD;AAzCF;AA6CA;;AAED,SAAOjB,KAAP;AACA;AAED,eAAeJ,gBAAgB,CAAEE,aAAF,CAA/B","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 {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * 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\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 '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\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"]}
|
|
@@ -41,6 +41,8 @@ function getContextFromAction(action) {
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
export function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
|
|
44
|
+
var _itemIds$length;
|
|
45
|
+
|
|
44
46
|
const receivedAllIds = page === 1 && perPage === -1;
|
|
45
47
|
|
|
46
48
|
if (receivedAllIds) {
|
|
@@ -50,14 +52,14 @@ export function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
|
|
|
50
52
|
const nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known
|
|
51
53
|
// size of the existing array, else calculate as extending the existing.
|
|
52
54
|
|
|
53
|
-
const size = Math.max(itemIds.length, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
|
|
55
|
+
const size = Math.max((_itemIds$length = itemIds === null || itemIds === void 0 ? void 0 : itemIds.length) !== null && _itemIds$length !== void 0 ? _itemIds$length : 0, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
|
|
54
56
|
|
|
55
57
|
const mergedItemIds = new Array(size);
|
|
56
58
|
|
|
57
59
|
for (let i = 0; i < size; i++) {
|
|
58
60
|
// Preserve existing item ID except for subset of range of next items.
|
|
59
61
|
const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length;
|
|
60
|
-
mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds[i];
|
|
62
|
+
mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds === null || itemIds === void 0 ? void 0 : itemIds[i];
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
return mergedItemIds;
|
|
@@ -107,10 +109,10 @@ export function items() {
|
|
|
107
109
|
* In such cases, completeness is used as an indication of whether it would be
|
|
108
110
|
* safe to use queried data for a non-`_fields`-limited request.
|
|
109
111
|
*
|
|
110
|
-
* @param {Object<string,boolean
|
|
111
|
-
* @param {Object}
|
|
112
|
+
* @param {Object<string,Object<string,boolean>>} state Current state.
|
|
113
|
+
* @param {Object} action Dispatched action.
|
|
112
114
|
*
|
|
113
|
-
* @return {Object<string,boolean
|
|
115
|
+
* @return {Object<string,Object<string,boolean>>} Next state.
|
|
114
116
|
*/
|
|
115
117
|
|
|
116
118
|
export function itemIsComplete() {
|
|
@@ -127,7 +129,7 @@ export function itemIsComplete() {
|
|
|
127
129
|
} = action; // An item is considered complete if it is received without an associated
|
|
128
130
|
// fields query. Ideally, this would be implemented in such a way where the
|
|
129
131
|
// complete aggregate of all fields would satisfy completeness. Since the
|
|
130
|
-
// fields are not consistent across all
|
|
132
|
+
// fields are not consistent across all entities, this would require
|
|
131
133
|
// introspection on the REST schema for each entity to know which fields
|
|
132
134
|
// compose a complete item for that entity.
|
|
133
135
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"names":["map","flowRight","omit","filter","mapValues","combineReducers","conservativeMapItem","ifMatchingAction","replaceAction","onSubKey","DEFAULT_ENTITY_KEY","getQueryParts","getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","items","state","type","key","reduce","accumulator","value","itemId","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","queries","removedItems","contextQueries","queryItems","queryId"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,EAAcC,SAAd,EAAyBC,IAAzB,EAA+BC,MAA/B,EAAuCC,SAAvC,QAAwD,QAAxD;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;;AACA,SACCC,mBADD,EAECC,gBAFD,EAGCC,aAHD,EAICC,QAJD,QAKO,UALP;AAMA,SAASC,kBAAT,QAAmC,aAAnC;AACA,OAAOC,aAAP,MAA0B,mBAA1B;;AAEA,SAASC,oBAAT,CAA+BC,MAA/B,EAAwC;AACvC,QAAM;AAAEC,IAAAA;AAAF,MAAYD,MAAlB;;AACA,MAAK,CAAEC,KAAP,EAAe;AACd,WAAO,SAAP;AACA;;AAED,QAAMC,UAAU,GAAGJ,aAAa,CAAEG,KAAF,CAAhC;A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ourcesContent":["/**\n * External dependencies\n */\nimport { map, flowRight, omit, filter, mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\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 {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( 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\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds[ i ];\n\t}\n\n\treturn mergedItemIds;\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\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...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value[ key ];\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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,boolean>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {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\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 entity types, 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...action.items.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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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 = flowRight( [\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 = null, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn getMergedItemIds(\n\t\tstate || [],\n\t\tmap( action.items, key ),\n\t\tpage,\n\t\tperPage\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 mapValues( state, ( contextQueries ) => {\n\t\t\t\treturn mapValues( contextQueries, ( queryItems ) => {\n\t\t\t\t\treturn filter( queryItems, ( queryId ) => {\n\t\t\t\t\t\treturn ! removedItems[ queryId ];\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"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"names":["map","flowRight","omit","filter","mapValues","combineReducers","conservativeMapItem","ifMatchingAction","replaceAction","onSubKey","DEFAULT_ENTITY_KEY","getQueryParts","getContextFromAction","action","query","queryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","items","state","type","key","reduce","accumulator","value","itemId","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","queries","removedItems","contextQueries","queryItems","queryId"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,EAAcC,SAAd,E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ACjEM,QAAAA,MAAM,CAAEN,MAAF,CAAN,GAAmB,IAAnB;AACA,eAAOM,MAAP;AACA,OAHoB,EAGlB,EAHkB,CAArB;AAKA,aAAOzC,SAAS,CAAE6B,KAAF,EAAWiB,cAAF,IAAsB;AAC9C,eAAO9C,SAAS,CAAE8C,cAAF,EAAoBC,UAAF,IAAkB;AACnD,iBAAOhD,MAAM,CAAEgD,UAAF,EAAgBC,OAAF,IAAe;AACzC,mBAAO,CAAEH,YAAY,CAAEG,OAAF,CAArB;AACA,WAFY,CAAb;AAGA,SAJe,CAAhB;AAKA,OANe,CAAhB;;AAOD;AACC,aAAOnB,KAAP;AAjBF;AAmBA,CApBD;;AAsBA,eAAe5B,eAAe,CAAE;AAC/B2B,EAAAA,KAD+B;AAE/BS,EAAAA,cAF+B;AAG/BO,EAAAA;AAH+B,CAAF,CAA9B","sourcesContent":["/**\n * External dependencies\n */\nimport { map, flowRight, omit, filter, mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\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 {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( 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 ?? 0,\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\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\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\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...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value[ key ];\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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\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...action.items.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 mapValues( state, ( contextState ) =>\n\t\t\t\tomit( contextState, action.itemIds )\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 = flowRight( [\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 = null, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn getMergedItemIds(\n\t\tstate || [],\n\t\tmap( action.items, key ),\n\t\tpage,\n\t\tperPage\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 mapValues( state, ( contextQueries ) => {\n\t\t\t\treturn mapValues( contextQueries, ( queryItems ) => {\n\t\t\t\t\treturn filter( queryItems, ( queryId ) => {\n\t\t\t\t\t\treturn ! removedItems[ queryId ];\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"]}
|
package/build-module/reducer.js
CHANGED
|
@@ -14,7 +14,9 @@ import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
|
14
14
|
|
|
15
15
|
import { ifMatchingAction, replaceAction } from './utils';
|
|
16
16
|
import { reducer as queriedDataReducer } from './queried-data';
|
|
17
|
-
import {
|
|
17
|
+
import { rootEntitiesConfig, DEFAULT_ENTITY_KEY } from './entities';
|
|
18
|
+
/** @typedef {import('./types').AnyFunction} AnyFunction */
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* Reducer managing terms state. Keyed by taxonomy slug, the value is either
|
|
20
22
|
* undefined (if no request has been made for given taxonomy), null (if a
|
|
@@ -113,10 +115,10 @@ export function taxonomies() {
|
|
|
113
115
|
/**
|
|
114
116
|
* Reducer managing the current theme.
|
|
115
117
|
*
|
|
116
|
-
* @param {string} state Current state.
|
|
117
|
-
* @param {Object}
|
|
118
|
+
* @param {string|undefined} state Current state.
|
|
119
|
+
* @param {Object} action Dispatched action.
|
|
118
120
|
*
|
|
119
|
-
* @return {string} Updated state.
|
|
121
|
+
* @return {string|undefined} Updated state.
|
|
120
122
|
*/
|
|
121
123
|
|
|
122
124
|
export function currentTheme() {
|
|
@@ -133,10 +135,10 @@ export function currentTheme() {
|
|
|
133
135
|
/**
|
|
134
136
|
* Reducer managing the current global styles id.
|
|
135
137
|
*
|
|
136
|
-
* @param {string} state Current state.
|
|
137
|
-
* @param {Object}
|
|
138
|
+
* @param {string|undefined} state Current state.
|
|
139
|
+
* @param {Object} action Dispatched action.
|
|
138
140
|
*
|
|
139
|
-
* @return {string} Updated state.
|
|
141
|
+
* @return {string|undefined} Updated state.
|
|
140
142
|
*/
|
|
141
143
|
|
|
142
144
|
export function currentGlobalStylesId() {
|
|
@@ -153,10 +155,10 @@ export function currentGlobalStylesId() {
|
|
|
153
155
|
/**
|
|
154
156
|
* Reducer managing the theme base global styles.
|
|
155
157
|
*
|
|
156
|
-
* @param {string} state Current state.
|
|
157
|
-
* @param {Object}
|
|
158
|
+
* @param {Record<string, object>} state Current state.
|
|
159
|
+
* @param {Object} action Dispatched action.
|
|
158
160
|
*
|
|
159
|
-
* @return {string} Updated state.
|
|
161
|
+
* @return {Record<string, object>} Updated state.
|
|
160
162
|
*/
|
|
161
163
|
|
|
162
164
|
export function themeBaseGlobalStyles() {
|
|
@@ -175,10 +177,10 @@ export function themeBaseGlobalStyles() {
|
|
|
175
177
|
/**
|
|
176
178
|
* Reducer managing the theme global styles variations.
|
|
177
179
|
*
|
|
178
|
-
* @param {string} state Current state.
|
|
179
|
-
* @param {Object}
|
|
180
|
+
* @param {Record<string, object>} state Current state.
|
|
181
|
+
* @param {Object} action Dispatched action.
|
|
180
182
|
*
|
|
181
|
-
* @return {string} Updated state.
|
|
183
|
+
* @return {Record<string, object>} Updated state.
|
|
182
184
|
*/
|
|
183
185
|
|
|
184
186
|
export function themeGlobalStyleVariations() {
|
|
@@ -203,7 +205,7 @@ export function themeGlobalStyleVariations() {
|
|
|
203
205
|
*
|
|
204
206
|
* @param {Object} entityConfig Entity config.
|
|
205
207
|
*
|
|
206
|
-
* @return {
|
|
208
|
+
* @return {AnyFunction} Reducer.
|
|
207
209
|
*/
|
|
208
210
|
|
|
209
211
|
function entity(entityConfig) {
|
|
@@ -331,7 +333,7 @@ function entity(entityConfig) {
|
|
|
331
333
|
|
|
332
334
|
|
|
333
335
|
export function entitiesConfig() {
|
|
334
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
336
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : rootEntitiesConfig;
|
|
335
337
|
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
336
338
|
|
|
337
339
|
switch (action.type) {
|
|
@@ -369,30 +371,48 @@ export const entities = function () {
|
|
|
369
371
|
}, {}));
|
|
370
372
|
}
|
|
371
373
|
|
|
372
|
-
const newData = entitiesDataReducer(state.
|
|
374
|
+
const newData = entitiesDataReducer(state.records, action);
|
|
373
375
|
|
|
374
|
-
if (newData === state.
|
|
376
|
+
if (newData === state.records && newConfig === state.config && entitiesDataReducer === state.reducer) {
|
|
375
377
|
return state;
|
|
376
378
|
}
|
|
377
379
|
|
|
378
380
|
return {
|
|
379
381
|
reducer: entitiesDataReducer,
|
|
380
|
-
|
|
382
|
+
records: newData,
|
|
381
383
|
config: newConfig
|
|
382
384
|
};
|
|
383
385
|
};
|
|
384
386
|
/**
|
|
385
|
-
*
|
|
387
|
+
* @typedef {Object} UndoStateMeta
|
|
386
388
|
*
|
|
387
|
-
* @
|
|
388
|
-
* @
|
|
389
|
+
* @property {number} offset Where in the undo stack we are.
|
|
390
|
+
* @property {Object} [flattenedUndo] Flattened form of undo stack.
|
|
391
|
+
*/
|
|
392
|
+
|
|
393
|
+
/** @typedef {Array<Object> & UndoStateMeta} UndoState */
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @type {UndoState}
|
|
389
397
|
*
|
|
390
|
-
* @
|
|
398
|
+
* @todo Given how we use this we might want to make a custom class for it.
|
|
391
399
|
*/
|
|
392
400
|
|
|
393
|
-
const UNDO_INITIAL_STATE = []
|
|
394
|
-
|
|
401
|
+
const UNDO_INITIAL_STATE = Object.assign([], {
|
|
402
|
+
offset: 0
|
|
403
|
+
});
|
|
404
|
+
/** @type {Object} */
|
|
405
|
+
|
|
395
406
|
let lastEditAction;
|
|
407
|
+
/**
|
|
408
|
+
* Reducer keeping track of entity edit undo history.
|
|
409
|
+
*
|
|
410
|
+
* @param {UndoState} state Current state.
|
|
411
|
+
* @param {Object} action Dispatched action.
|
|
412
|
+
*
|
|
413
|
+
* @return {UndoState} Updated state.
|
|
414
|
+
*/
|
|
415
|
+
|
|
396
416
|
export function undo() {
|
|
397
417
|
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UNDO_INITIAL_STATE;
|
|
398
418
|
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
@@ -419,10 +439,13 @@ export function undo() {
|
|
|
419
439
|
};
|
|
420
440
|
}
|
|
421
441
|
}
|
|
442
|
+
/** @type {UndoState} */
|
|
443
|
+
|
|
422
444
|
|
|
423
445
|
let nextState;
|
|
424
446
|
|
|
425
447
|
if (isUndoOrRedo) {
|
|
448
|
+
// @ts-ignore we might consider using Object.assign({}, state)
|
|
426
449
|
nextState = [...state];
|
|
427
450
|
nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1);
|
|
428
451
|
|
|
@@ -458,6 +481,7 @@ export function undo() {
|
|
|
458
481
|
|
|
459
482
|
|
|
460
483
|
if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) {
|
|
484
|
+
// @ts-ignore we might consider using Object.assign({}, state)
|
|
461
485
|
nextState = [...state];
|
|
462
486
|
nextState.flattenedUndo = { ...state.flattenedUndo,
|
|
463
487
|
...action.edits
|
|
@@ -467,7 +491,8 @@ export function undo() {
|
|
|
467
491
|
} // Clear potential redos, because this only supports linear history.
|
|
468
492
|
|
|
469
493
|
|
|
470
|
-
nextState =
|
|
494
|
+
nextState = // @ts-ignore this needs additional cleanup, probably involving code-level changes
|
|
495
|
+
nextState || state.slice(0, state.offset || undefined);
|
|
471
496
|
nextState.offset = nextState.offset || 0;
|
|
472
497
|
nextState.pop();
|
|
473
498
|
|
|
@@ -578,6 +603,28 @@ export function autosaves() {
|
|
|
578
603
|
|
|
579
604
|
return state;
|
|
580
605
|
}
|
|
606
|
+
export function blockPatterns() {
|
|
607
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
608
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
609
|
+
|
|
610
|
+
switch (action.type) {
|
|
611
|
+
case 'RECEIVE_BLOCK_PATTERNS':
|
|
612
|
+
return action.patterns;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return state;
|
|
616
|
+
}
|
|
617
|
+
export function blockPatternCategories() {
|
|
618
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
619
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
620
|
+
|
|
621
|
+
switch (action.type) {
|
|
622
|
+
case 'RECEIVE_BLOCK_PATTERN_CATEGORIES':
|
|
623
|
+
return action.categories;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return state;
|
|
627
|
+
}
|
|
581
628
|
export default combineReducers({
|
|
582
629
|
terms,
|
|
583
630
|
users,
|
|
@@ -591,6 +638,8 @@ export default combineReducers({
|
|
|
591
638
|
undo,
|
|
592
639
|
embedPreviews,
|
|
593
640
|
userPermissions,
|
|
594
|
-
autosaves
|
|
641
|
+
autosaves,
|
|
642
|
+
blockPatterns,
|
|
643
|
+
blockPatternCategories
|
|
595
644
|
});
|
|
596
645
|
//# sourceMappingURL=reducer.js.map
|