@wordpress/data 6.1.3 → 6.1.4

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.
Files changed (53) hide show
  1. package/build/components/async-mode-provider/context.js +1 -1
  2. package/build/components/async-mode-provider/index.js +8 -6
  3. package/build/components/async-mode-provider/index.js.map +1 -1
  4. package/build/components/registry-provider/index.js +8 -6
  5. package/build/components/registry-provider/index.js.map +1 -1
  6. package/build/components/use-dispatch/use-dispatch-with-map.js +3 -1
  7. package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
  8. package/build/controls.js +38 -19
  9. package/build/controls.js.map +1 -1
  10. package/build/factory.js +4 -2
  11. package/build/factory.js.map +1 -1
  12. package/build/index.js +35 -33
  13. package/build/index.js.map +1 -1
  14. package/build/plugins/persistence/index.js +2 -1
  15. package/build/plugins/persistence/index.js.map +1 -1
  16. package/build/redux-store/index.js +47 -19
  17. package/build/redux-store/index.js.map +1 -1
  18. package/build/redux-store/metadata/actions.js +2 -2
  19. package/build/redux-store/metadata/reducer.js +8 -2
  20. package/build/redux-store/metadata/reducer.js.map +1 -1
  21. package/build/redux-store/metadata/selectors.js +8 -5
  22. package/build/redux-store/metadata/selectors.js.map +1 -1
  23. package/build/redux-store/metadata/utils.js +5 -5
  24. package/build/redux-store/metadata/utils.js.map +1 -1
  25. package/build/registry.js +7 -2
  26. package/build/registry.js.map +1 -1
  27. package/build/resolvers-cache-middleware.js +2 -1
  28. package/build/resolvers-cache-middleware.js.map +1 -1
  29. package/build/store/index.js +10 -2
  30. package/build/store/index.js.map +1 -1
  31. package/build/types.js +4 -0
  32. package/build-module/components/use-dispatch/use-dispatch-with-map.js +3 -1
  33. package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
  34. package/build-module/controls.js +37 -18
  35. package/build-module/controls.js.map +1 -1
  36. package/build-module/factory.js +3 -1
  37. package/build-module/factory.js.map +1 -1
  38. package/build-module/redux-store/index.js +43 -17
  39. package/build-module/redux-store/index.js.map +1 -1
  40. package/build-module/redux-store/metadata/reducer.js +8 -2
  41. package/build-module/redux-store/metadata/reducer.js.map +1 -1
  42. package/build-module/redux-store/metadata/selectors.js +6 -3
  43. package/build-module/redux-store/metadata/selectors.js.map +1 -1
  44. package/build-module/redux-store/metadata/utils.js +5 -5
  45. package/build-module/redux-store/metadata/utils.js.map +1 -1
  46. package/build-module/registry.js +7 -2
  47. package/build-module/registry.js.map +1 -1
  48. package/build-module/resolvers-cache-middleware.js +2 -1
  49. package/build-module/resolvers-cache-middleware.js.map +1 -1
  50. package/build-module/store/index.js +10 -2
  51. package/build-module/store/index.js.map +1 -1
  52. package/build-module/types.js +1 -1
  53. package/package.json +9 -9
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.AsyncModeConsumer = exports.Context = void 0;
6
+ exports.default = exports.Context = exports.AsyncModeConsumer = void 0;
7
7
 
8
8
  var _element = require("@wordpress/element");
9
9
 
@@ -1,16 +1,14 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
- Object.defineProperty(exports, "useAsyncMode", {
8
+ Object.defineProperty(exports, "AsyncModeConsumer", {
11
9
  enumerable: true,
12
10
  get: function () {
13
- return _useAsyncMode.default;
11
+ return _context.AsyncModeConsumer;
14
12
  }
15
13
  });
16
14
  Object.defineProperty(exports, "AsyncModeProvider", {
@@ -19,14 +17,18 @@ Object.defineProperty(exports, "AsyncModeProvider", {
19
17
  return _context.default;
20
18
  }
21
19
  });
22
- Object.defineProperty(exports, "AsyncModeConsumer", {
20
+ Object.defineProperty(exports, "useAsyncMode", {
23
21
  enumerable: true,
24
22
  get: function () {
25
- return _context.AsyncModeConsumer;
23
+ return _useAsyncMode.default;
26
24
  }
27
25
  });
28
26
 
29
27
  var _useAsyncMode = _interopRequireDefault(require("./use-async-mode"));
30
28
 
31
29
  var _context = _interopRequireWildcard(require("./context"));
30
+
31
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
32
+
33
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
32
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { default as useAsyncMode } from './use-async-mode';\nexport { default as AsyncModeProvider, AsyncModeConsumer } from './context';\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { default as useAsyncMode } from './use-async-mode';\nexport { default as AsyncModeProvider, AsyncModeConsumer } from './context';\n"]}
@@ -2,21 +2,19 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
6
-
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
- Object.defineProperty(exports, "RegistryProvider", {
8
+ Object.defineProperty(exports, "RegistryConsumer", {
11
9
  enumerable: true,
12
10
  get: function () {
13
- return _context.default;
11
+ return _context.RegistryConsumer;
14
12
  }
15
13
  });
16
- Object.defineProperty(exports, "RegistryConsumer", {
14
+ Object.defineProperty(exports, "RegistryProvider", {
17
15
  enumerable: true,
18
16
  get: function () {
19
- return _context.RegistryConsumer;
17
+ return _context.default;
20
18
  }
21
19
  });
22
20
  Object.defineProperty(exports, "useRegistry", {
@@ -29,4 +27,8 @@ Object.defineProperty(exports, "useRegistry", {
29
27
  var _context = _interopRequireWildcard(require("./context"));
30
28
 
31
29
  var _useRegistry = _interopRequireDefault(require("./use-registry"));
30
+
31
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
32
+
33
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
32
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/registry-provider/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { default as RegistryProvider, RegistryConsumer } from './context';\nexport { default as useRegistry } from './use-registry';\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/registry-provider/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["export { default as RegistryProvider, RegistryConsumer } from './context';\nexport { default as useRegistry } from './use-registry';\n"]}
@@ -55,7 +55,9 @@ const useDispatchWithMap = (dispatchMap, deps) => {
55
55
  console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`);
56
56
  }
57
57
 
58
- return (...args) => currentDispatchMap.current(registry.dispatch, registry)[propName](...args);
58
+ return function () {
59
+ return currentDispatchMap.current(registry.dispatch, registry)[propName](...arguments);
60
+ };
59
61
  });
60
62
  }, [registry, ...deps]);
61
63
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"names":["useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","dispatcher","propName","console","warn","args"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACnD,QAAMC,QAAQ,GAAG,2BAAjB;AACA,QAAMC,kBAAkB,GAAG,qBAAQH,WAAR,CAA3B;AAEA,0CAA2B,MAAM;AAChCG,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BJ,WAA7B;AACA,GAFD;AAIA,SAAO,sBAAS,MAAM;AACrB,UAAMK,oBAAoB,GAAGF,kBAAkB,CAACC,OAAnB,CAC5BF,QAAQ,CAACI,QADmB,EAE5BJ,QAF4B,CAA7B;AAIA,WAAO,uBAAWG,oBAAX,EAAiC,CAAEE,UAAF,EAAcC,QAAd,KAA4B;AACnE,UAAK,OAAOD,UAAP,KAAsB,UAA3B,EAAwC;AACvC;AACAE,QAAAA,OAAO,CAACC,IAAR,CACE,YAAYF,QAAU,sEADxB;AAGA;;AACD,aAAO,CAAE,GAAGG,IAAL,KACNR,kBAAkB,CAChBC,OADF,CACWF,QAAQ,CAACI,QADpB,EAC8BJ,QAD9B,EAEGM,QAFH,EAEe,GAAGG,IAFlB,CADD;AAIA,KAXM,CAAP;AAYA,GAjBM,EAiBJ,CAAET,QAAF,EAAY,GAAGD,IAAf,CAjBI,CAAP;AAkBA,CA1BD;;eA4BeF,kB","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * Custom react hook for returning aggregate dispatch actions using the provided\n * dispatchMap.\n *\n * Currently this is an internal api only and is implemented by `withDispatch`\n *\n * @param {Function} dispatchMap Receives the `registry.dispatch` function as\n * the first argument and the `registry` object\n * as the second argument. Should return an\n * object mapping props to functions.\n * @param {Array} deps An array of dependencies for the hook.\n * @return {Object} An object mapping props to functions created by the passed\n * in dispatchMap.\n */\nconst useDispatchWithMap = ( dispatchMap, deps ) => {\n\tconst registry = useRegistry();\n\tconst currentDispatchMap = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMap.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMap.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn mapValues( currentDispatchProps, ( dispatcher, propName ) => {\n\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn ( ...args ) =>\n\t\t\t\tcurrentDispatchMap\n\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t[ propName ]( ...args );\n\t\t} );\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"names":["useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","dispatcher","propName","console","warn"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,kBAAkB,GAAG,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACnD,QAAMC,QAAQ,GAAG,2BAAjB;AACA,QAAMC,kBAAkB,GAAG,qBAAQH,WAAR,CAA3B;AAEA,0CAA2B,MAAM;AAChCG,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BJ,WAA7B;AACA,GAFD;AAIA,SAAO,sBAAS,MAAM;AACrB,UAAMK,oBAAoB,GAAGF,kBAAkB,CAACC,OAAnB,CAC5BF,QAAQ,CAACI,QADmB,EAE5BJ,QAF4B,CAA7B;AAIA,WAAO,uBAAWG,oBAAX,EAAiC,CAAEE,UAAF,EAAcC,QAAd,KAA4B;AACnE,UAAK,OAAOD,UAAP,KAAsB,UAA3B,EAAwC;AACvC;AACAE,QAAAA,OAAO,CAACC,IAAR,CACE,YAAYF,QAAU,sEADxB;AAGA;;AACD,aAAO;AAAA,eACNL,kBAAkB,CAChBC,OADF,CACWF,QAAQ,CAACI,QADpB,EAC8BJ,QAD9B,EAEGM,QAFH,EAEe,YAFf,CADM;AAAA,OAAP;AAIA,KAXM,CAAP;AAYA,GAjBM,EAiBJ,CAAEN,QAAF,EAAY,GAAGD,IAAf,CAjBI,CAAP;AAkBA,CA1BD;;eA4BeF,kB","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * Custom react hook for returning aggregate dispatch actions using the provided\n * dispatchMap.\n *\n * Currently this is an internal api only and is implemented by `withDispatch`\n *\n * @param {Function} dispatchMap Receives the `registry.dispatch` function as\n * the first argument and the `registry` object\n * as the second argument. Should return an\n * object mapping props to functions.\n * @param {Array} deps An array of dependencies for the hook.\n * @return {Object} An object mapping props to functions created by the passed\n * in dispatchMap.\n */\nconst useDispatchWithMap = ( dispatchMap, deps ) => {\n\tconst registry = useRegistry();\n\tconst currentDispatchMap = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMap.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMap.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn mapValues( currentDispatchProps, ( dispatcher, propName ) => {\n\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn ( ...args ) =>\n\t\t\t\tcurrentDispatchMap\n\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t[ propName ]( ...args );\n\t\t} );\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"]}
package/build/controls.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.builtinControls = exports.controls = void 0;
6
+ exports.controls = exports.builtinControls = void 0;
7
7
 
8
8
  var _lodash = require("lodash");
9
9
 
@@ -45,7 +45,11 @@ const DISPATCH = '@@data/DISPATCH';
45
45
  * @return {Object} The control descriptor.
46
46
  */
47
47
 
48
- function select(storeNameOrDefinition, selectorName, ...args) {
48
+ function select(storeNameOrDefinition, selectorName) {
49
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
50
+ args[_key - 2] = arguments[_key];
51
+ }
52
+
49
53
  return {
50
54
  type: SELECT,
51
55
  storeKey: (0, _lodash.isObject)(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition,
@@ -79,7 +83,11 @@ function select(storeNameOrDefinition, selectorName, ...args) {
79
83
  */
80
84
 
81
85
 
82
- function resolveSelect(storeNameOrDefinition, selectorName, ...args) {
86
+ function resolveSelect(storeNameOrDefinition, selectorName) {
87
+ for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
88
+ args[_key2 - 2] = arguments[_key2];
89
+ }
90
+
83
91
  return {
84
92
  type: RESOLVE_SELECT,
85
93
  storeKey: (0, _lodash.isObject)(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition,
@@ -109,7 +117,11 @@ function resolveSelect(storeNameOrDefinition, selectorName, ...args) {
109
117
  */
110
118
 
111
119
 
112
- function dispatch(storeNameOrDefinition, actionName, ...args) {
120
+ function dispatch(storeNameOrDefinition, actionName) {
121
+ for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
122
+ args[_key3 - 2] = arguments[_key3];
123
+ }
124
+
113
125
  return {
114
126
  type: DISPATCH,
115
127
  storeKey: (0, _lodash.isObject)(storeNameOrDefinition) ? storeNameOrDefinition.name : storeNameOrDefinition,
@@ -125,24 +137,31 @@ const controls = {
125
137
  };
126
138
  exports.controls = controls;
127
139
  const builtinControls = {
128
- [SELECT]: (0, _factory.createRegistryControl)(registry => ({
129
- storeKey,
130
- selectorName,
131
- args
132
- }) => registry.select(storeKey)[selectorName](...args)),
133
- [RESOLVE_SELECT]: (0, _factory.createRegistryControl)(registry => ({
134
- storeKey,
135
- selectorName,
136
- args
137
- }) => {
140
+ [SELECT]: (0, _factory.createRegistryControl)(registry => _ref => {
141
+ let {
142
+ storeKey,
143
+ selectorName,
144
+ args
145
+ } = _ref;
146
+ return registry.select(storeKey)[selectorName](...args);
147
+ }),
148
+ [RESOLVE_SELECT]: (0, _factory.createRegistryControl)(registry => _ref2 => {
149
+ let {
150
+ storeKey,
151
+ selectorName,
152
+ args
153
+ } = _ref2;
138
154
  const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select';
139
155
  return registry[method](storeKey)[selectorName](...args);
140
156
  }),
141
- [DISPATCH]: (0, _factory.createRegistryControl)(registry => ({
142
- storeKey,
143
- actionName,
144
- args
145
- }) => registry.dispatch(storeKey)[actionName](...args))
157
+ [DISPATCH]: (0, _factory.createRegistryControl)(registry => _ref3 => {
158
+ let {
159
+ storeKey,
160
+ actionName,
161
+ args
162
+ } = _ref3;
163
+ return registry.dispatch(storeKey)[actionName](...args);
164
+ })
146
165
  };
147
166
  exports.builtinControls = builtinControls;
148
167
  //# sourceMappingURL=controls.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDefinition","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AAEA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;AAEA;A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,MAAF,GAAY,oCACTe,QAAF,IAAgB,CAAE;AAAEP,IAAAA,QAAF;AAAYH,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAAF,KACfS,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EAA6C,GAAGC,IAAhD,CAFU,CADkB;AAK9B,GAAEL,cAAF,GAAoB,oCACjBc,QAAF,IAAgB,CAAE;AAAEP,IAAAA,QAAF;AAAYH,IAAAA,YAAZ;AAA0BC,IAAAA;AAA1B,GAAF,KAAwC;AACvD,UAAMU,MAAM,GAAGD,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EACbY,WADa,GAEZ,eAFY,GAGZ,QAHH;AAIA,WAAOF,QAAQ,CAAEC,MAAF,CAAR,CAAoBR,QAApB,EAAgCH,YAAhC,EAAgD,GAAGC,IAAnD,CAAP;AACA,GAPkB,CALU;AAc9B,GAAEJ,QAAF,GAAc,oCACXa,QAAF,IAAgB,CAAE;AAAEP,IAAAA,QAAF;AAAYI,IAAAA,UAAZ;AAAwBN,IAAAA;AAAxB,GAAF,KACfS,QAAQ,CAACJ,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CAFY;AAdgB,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport { isObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDefinition, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDefinition, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDefinition, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) =>\n\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) => {\n\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t.hasResolver\n\t\t\t\t? 'resolveSelect'\n\t\t\t\t: 'select';\n\t\t\treturn registry[ method ]( storeKey )[ selectorName ]( ...args );\n\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, actionName, args } ) =>\n\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDefinition","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AAEA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,MAAT,CAAiBC,qBAAjB,EAAwCC,YAAxC,EAAgE;AAAA,oCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAC/D,SAAO;AACNC,IAAAA,IAAI,E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EAA6BH,YAA7B,EAA6C,GAAGC,IAAhD,CADe;AAAA,GADL,CADkB;AAK9B,GAAEL,cAAF,GAAoB,oCACjBc,QAAF,IAAgB,SAAwC;AAAA,QAAtC;AAAEP,MAAAA,QAAF;AAAYH,MAAAA,YAAZ;AAA0BC,MAAAA;AAA1B,KAAsC;AACvD,UAAMU,MAAM,GAAGD,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EACbY,WADa,GAEZ,eAFY,GAGZ,QAHH;AAIA,WAAOF,QAAQ,CAAEC,MAAF,CAAR,CAAoBR,QAApB,EAAgCH,YAAhC,EAAgD,GAAGC,IAAnD,CAAP;AACA,GAPkB,CALU;AAc9B,GAAEJ,QAAF,GAAc,oCACXa,QAAF,IAAgB;AAAA,QAAE;AAAEP,MAAAA,QAAF;AAAYI,MAAAA,UAAZ;AAAwBN,MAAAA;AAAxB,KAAF;AAAA,WACfS,QAAQ,CAACJ,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CADe;AAAA,GADH;AAdgB,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport { isObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDefinition, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDefinition, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDefinition, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDefinition )\n\t\t\t? storeNameOrDefinition.name\n\t\t\t: storeNameOrDefinition,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) =>\n\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) => {\n\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t.hasResolver\n\t\t\t\t? 'resolveSelect'\n\t\t\t\t: 'select';\n\t\t\treturn registry[ method ]( storeKey )[ selectorName ]( ...args );\n\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, actionName, args } ) =>\n\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
package/build/factory.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createRegistrySelector = createRegistrySelector;
7
6
  exports.createRegistryControl = createRegistryControl;
7
+ exports.createRegistrySelector = createRegistrySelector;
8
8
 
9
9
  /**
10
10
  * Creates a selector function that takes additional curried argument with the
@@ -47,7 +47,9 @@ function createRegistrySelector(registrySelector) {
47
47
  // create a selector function that is bound to the registry referenced by `selector.registry`
48
48
  // and that has the same API as a regular selector. Binding it in such a way makes it
49
49
  // possible to call the selector directly from another selector.
50
- const selector = (...args) => registrySelector(selector.registry.select)(...args);
50
+ const selector = function () {
51
+ return registrySelector(selector.registry.select)(...arguments);
52
+ };
51
53
  /**
52
54
  * Flag indicating that the selector is a registry selector that needs the correct registry
53
55
  * reference to be assigned to `selecto.registry` to make it work correctly.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","args","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":";;;;;;;;AAAA;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;AACO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG,CAAE,GAAGC,IAAL,KAChBF,gBAAgB,CAAEC,QAAQ,CAACE,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,GAAGF,IAAjD,CADD;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCD,EAAAA,QAAQ,CAACI,kBAAT,GAA8B,IAA9B;AAEA,SAAOJ,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":";;;;;;;;AAAA;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;AACO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG;AAAA,WAChBD,gBAAgB,CAAEC,QAAQ,CAACC,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,YAA9C,CADgB;AAAA,GAAjB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCF,EAAAA,QAAQ,CAACG,kBAAT,GAA8B,IAA9B;AAEA,SAAOH,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
package/build/index.js CHANGED
@@ -1,103 +1,101 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
4
-
5
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
6
4
 
7
5
  Object.defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
- Object.defineProperty(exports, "combineReducers", {
8
+ Object.defineProperty(exports, "AsyncModeProvider", {
11
9
  enumerable: true,
12
10
  get: function () {
13
- return _turboCombineReducers.default;
11
+ return _asyncModeProvider.AsyncModeProvider;
14
12
  }
15
13
  });
16
- Object.defineProperty(exports, "withSelect", {
14
+ Object.defineProperty(exports, "RegistryConsumer", {
17
15
  enumerable: true,
18
16
  get: function () {
19
- return _withSelect.default;
17
+ return _registryProvider.RegistryConsumer;
20
18
  }
21
19
  });
22
- Object.defineProperty(exports, "withDispatch", {
20
+ Object.defineProperty(exports, "RegistryProvider", {
23
21
  enumerable: true,
24
22
  get: function () {
25
- return _withDispatch.default;
23
+ return _registryProvider.RegistryProvider;
26
24
  }
27
25
  });
28
- Object.defineProperty(exports, "withRegistry", {
26
+ Object.defineProperty(exports, "combineReducers", {
29
27
  enumerable: true,
30
28
  get: function () {
31
- return _withRegistry.default;
29
+ return _turboCombineReducers.default;
32
30
  }
33
31
  });
34
- Object.defineProperty(exports, "RegistryProvider", {
32
+ Object.defineProperty(exports, "controls", {
35
33
  enumerable: true,
36
34
  get: function () {
37
- return _registryProvider.RegistryProvider;
35
+ return _controls.controls;
38
36
  }
39
37
  });
40
- Object.defineProperty(exports, "RegistryConsumer", {
38
+ Object.defineProperty(exports, "createReduxStore", {
41
39
  enumerable: true,
42
40
  get: function () {
43
- return _registryProvider.RegistryConsumer;
41
+ return _reduxStore.default;
44
42
  }
45
43
  });
46
- Object.defineProperty(exports, "useRegistry", {
44
+ Object.defineProperty(exports, "createRegistry", {
47
45
  enumerable: true,
48
46
  get: function () {
49
- return _registryProvider.useRegistry;
47
+ return _registry.createRegistry;
50
48
  }
51
49
  });
52
- Object.defineProperty(exports, "useSelect", {
50
+ Object.defineProperty(exports, "createRegistryControl", {
53
51
  enumerable: true,
54
52
  get: function () {
55
- return _useSelect.default;
53
+ return _factory.createRegistryControl;
56
54
  }
57
55
  });
58
- Object.defineProperty(exports, "useDispatch", {
56
+ Object.defineProperty(exports, "createRegistrySelector", {
59
57
  enumerable: true,
60
58
  get: function () {
61
- return _useDispatch.useDispatch;
59
+ return _factory.createRegistrySelector;
62
60
  }
63
61
  });
64
- Object.defineProperty(exports, "AsyncModeProvider", {
62
+ exports.use = exports.subscribe = exports.select = exports.resolveSelect = exports.registerStore = exports.registerGenericStore = exports.register = exports.plugins = exports.dispatch = void 0;
63
+ Object.defineProperty(exports, "useDispatch", {
65
64
  enumerable: true,
66
65
  get: function () {
67
- return _asyncModeProvider.AsyncModeProvider;
66
+ return _useDispatch.useDispatch;
68
67
  }
69
68
  });
70
- Object.defineProperty(exports, "createRegistry", {
69
+ Object.defineProperty(exports, "useRegistry", {
71
70
  enumerable: true,
72
71
  get: function () {
73
- return _registry.createRegistry;
72
+ return _registryProvider.useRegistry;
74
73
  }
75
74
  });
76
- Object.defineProperty(exports, "createRegistrySelector", {
75
+ Object.defineProperty(exports, "useSelect", {
77
76
  enumerable: true,
78
77
  get: function () {
79
- return _factory.createRegistrySelector;
78
+ return _useSelect.default;
80
79
  }
81
80
  });
82
- Object.defineProperty(exports, "createRegistryControl", {
81
+ Object.defineProperty(exports, "withDispatch", {
83
82
  enumerable: true,
84
83
  get: function () {
85
- return _factory.createRegistryControl;
84
+ return _withDispatch.default;
86
85
  }
87
86
  });
88
- Object.defineProperty(exports, "controls", {
87
+ Object.defineProperty(exports, "withRegistry", {
89
88
  enumerable: true,
90
89
  get: function () {
91
- return _controls.controls;
90
+ return _withRegistry.default;
92
91
  }
93
92
  });
94
- Object.defineProperty(exports, "createReduxStore", {
93
+ Object.defineProperty(exports, "withSelect", {
95
94
  enumerable: true,
96
95
  get: function () {
97
- return _reduxStore.default;
96
+ return _withSelect.default;
98
97
  }
99
98
  });
100
- exports.plugins = exports.register = exports.use = exports.registerStore = exports.registerGenericStore = exports.subscribe = exports.dispatch = exports.resolveSelect = exports.select = void 0;
101
99
 
102
100
  var _turboCombineReducers = _interopRequireDefault(require("turbo-combine-reducers"));
103
101
 
@@ -129,6 +127,10 @@ var _controls = require("./controls");
129
127
 
130
128
  var _reduxStore = _interopRequireDefault(require("./redux-store"));
131
129
 
130
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
131
+
132
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
133
+
132
134
  /**
133
135
  * External dependencies
134
136
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/index.js"],"names":["select","defaultRegistry","resolveSelect","dispatch","subscribe","registerGenericStore","registerStore","use","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;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;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAM,GAAGC,yBAAgBD,MAA/B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,aAAa,GAAGD,yBAAgBC,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGF,yBAAgBE,QAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,SAAS,GAAGH,yBAAgBG,SAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,oBAAoB,GAAGJ,yBAAgBI,oBAA7C;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGL,yBAAgBK,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,GAAG,GAAGN,yBAAgBM,GAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGP,yBAAgBO,QAAjC","sourcesContent":["/**\n * External dependencies\n */\nimport combineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport { default as useSelect } from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport { combineReducers };\n\n/**\n * Given the name or definition of a registered store, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * or the store definition.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n *\n * select( 'my-shop' ).getPrice( 'hammer' );\n * ```\n *\n * @return {Object} Object containing the store's selectors.\n */\nexport const select = defaultRegistry.select;\n\n/**\n * Given the name of a registered store, returns an object containing the store's\n * selectors pre-bound to state so that you only need to supply additional arguments,\n * and modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * or the store definition.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n *\n * resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given the name of a registered store, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * or the store definition.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n *\n * dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );\n * ```\n * @return {Object} Object containing the action creators.\n */\nexport const dispatch = defaultRegistry.dispatch;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. This function returns a `unsubscribe`\n * function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} key Store registry key.\n * @param {Object} config Configuration (getSelectors, getActions, subscribe).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store definition.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {WPDataStore} store Store definition.\n */\nexport const register = defaultRegistry.register;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/index.js"],"names":["select","defaultRegistry","resolveSelect","dispatch","subscribe","registerGenericStore","registerStore","use","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;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;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAM,GAAGC,yBAAgBD,MAA/B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,aAAa,GAAGD,yBAAgBC,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGF,yBAAgBE,QAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,SAAS,GAAGH,yBAAgBG,SAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,oBAAoB,GAAGJ,yBAAgBI,oBAA7C;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGL,yBAAgBK,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,GAAG,GAAGN,yBAAgBM,GAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGP,yBAAgBO,QAAjC","sourcesContent":["/**\n * External dependencies\n */\nimport combineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport { default as useSelect } from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport { combineReducers };\n\n/**\n * Given the name or definition of a registered store, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * or the store definition.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n *\n * select( 'my-shop' ).getPrice( 'hammer' );\n * ```\n *\n * @return {Object} Object containing the store's selectors.\n */\nexport const select = defaultRegistry.select;\n\n/**\n * Given the name of a registered store, returns an object containing the store's\n * selectors pre-bound to state so that you only need to supply additional arguments,\n * and modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * or the store definition.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n *\n * resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given the name of a registered store, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param {string|WPDataStore} storeNameOrDefinition Unique namespace identifier for the store\n * or the store definition.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n *\n * dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );\n * ```\n * @return {Object} Object containing the action creators.\n */\nexport const dispatch = defaultRegistry.dispatch;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. This function returns a `unsubscribe`\n * function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} key Store registry key.\n * @param {Object} config Configuration (getSelectors, getActions, subscribe).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store definition.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {WPDataStore} store Store definition.\n */\nexport const register = defaultRegistry.register;\n"]}
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.createPersistenceInterface = createPersistenceInterface;
9
+ exports.default = void 0;
9
10
  exports.migrateFeaturePreferencesToInterfaceStore = migrateFeaturePreferencesToInterfaceStore;
10
- exports.default = exports.withLazySameState = void 0;
11
+ exports.withLazySameState = void 0;
11
12
 
12
13
  var _lodash = require("lodash");
13
14
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToInterfaceStore","sourceStoreName","interfaceStoreName","sourcePreferences","preferences","sourceFeatures","features","targetFeatures","__unstableMigrate"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAGC,iBAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,iBAAiB,GAAKC,OAAF,IAAe,CAAEC,KAAF,EAASC,MAAT,KAAqB;AACpE,MAAKA,MAAM,CAACC,SAAP,KAAqBF,KAA1B,EAAkC;AACjC,WAAOA,KAAP;AACA;;AAED,SAAOD,OAAO,CAAEC,KAAF,EAASC,MAAT,CAAd;AACA,CANM;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASE,0BAAT,CAAqCC,OAArC,EAA+C;AACrD,QAAM;AACLC,IAAAA,OAAO,GAAGV,eADL;AAELW,IAAAA,UAAU,GAAGT;AAFR,MAGFO,OAHJ;AAKA,MAAIG,IAAJ;AAEA;AACD;AACA;AACA;AACA;;AACC,WAASC,OAAT,GAAmB;AAClB,QAAKD,IAAI,KAAKE,SAAd,EAA0B;AACzB;AACA;AACA,YAAMC,SAAS,GAAGL,OAAO,CAACM,OAAR,CAAiBL,UAAjB,CAAlB;;AACA,UAAKI,SAAS,KAAK,IAAnB,EAA0B;AACzBH,QAAAA,IAAI,GAAG,EAAP;AACA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AAE,EACZ,GAAGD,iBADS;AAEZG,UAAAA,QAAQ,EAAE3C;AAFE;AADoB,OAAlC;AAMA;AACD;AACD;AAED;AACA;AACA;AACA;;;AAEAa,iBAAiB,CAACgC,iBAAlB,GAAwC9B,aAAF,IAAqB;AAC1D,QAAMC,WAAW,GAAGtB,0BAA0B,CAAEqB,aAAF,CAA9C;AAEAsB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,mBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,wBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CAAErB,WAAF,EAAe,gBAAf,CAAzC;AACA,CAZD;;eAceH,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * interface store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the interface\n * package.\n */\nexport function migrateFeaturePreferencesToInterfaceStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst state = persistence.get();\n\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\tconst sourceFeatures = sourcePreferences?.features;\n\n\tif ( sourceFeatures ) {\n\t\tconst targetFeatures =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t\t[ sourceStoreName ]: sourceFeatures,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove feature preferences from the source.\n\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n}\n\n/**\n * Deprecated: Remove this function and the code in WordPress Core that calls\n * it once WordPress 6.0 is released.\n */\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-post' );\n};\n\nexport default persistencePlugin;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["DEFAULT_STORAGE","defaultStorage","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToInterfaceStore","sourceStoreName","interfaceStoreName","sourcePreferences","preferences","sourceFeatures","features","targetFeatures","__unstableMigrate"],"mappings":";;;;;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMA,eAAe,GAAGC,iBAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,MAAMC,iBAAiB,GAAKC,OAA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BG,WAApD;AACA,QAAMC,cAAc,GAAGF,iBAAH,aAAGA,iBAAH,uBAAGA,iBAAiB,CAAEG,QAA1C;;AAEA,MAAKD,cAAL,EAAsB;AAAA;;AACrB,UAAME,cAAc,4BACnBrD,KAAK,CAAEgD,kBAAF,CADc,oFACnB,sBAA6BE,WADV,2DACnB,uBAA0CE,QAD3C,CADqB,CAIrB;;AACA,QAAK,EAAEC,cAAF,aAAEA,cAAF,eAAEA,cAAc,CAAIN,eAAJ,CAAhB,CAAL,EAA6C;AAC5C;AACA;AACA;AACAtB,MAAAA,WAAW,CAACJ,GAAZ,CAAiB2B,kBAAjB,EAAqC;AACpCE,QAAAA,WAAW,EAAE;AACZE,UAAAA,QAAQ,EAAE,EACT,GAAGC,cADM;AAET,aAAEN,eAAF,GAAqBI;AAFZ;AADE;AADuB,OAArC,EAJ4C,CAa5C;;AACA1B,MAAAA,WAAW,CAACJ,GAAZ,CAAiB0B,eAAjB,EAAkC;AACjCG,QAAAA,WAAW,EAAE,EACZ,GAAGD,iBADS;AAEZG,UAAAA,QAAQ,EAAE3C;AAFE;AADoB,OAAlC;AAMA;AACD;AACD;AAED;AACA;AACA;AACA;;;AAEAa,iBAAiB,CAACgC,iBAAlB,GAAwC9B,aAAF,IAAqB;AAC1D,QAAMC,WAAW,GAAGtB,0BAA0B,CAAEqB,aAAF,CAA9C;AAEAsB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,mBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,wBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CAAErB,WAAF,EAAe,gBAAf,CAAzC;AACA,CAZD;;eAceH,iB","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * interface store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the interface\n * package.\n */\nexport function migrateFeaturePreferencesToInterfaceStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst state = persistence.get();\n\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\tconst sourceFeatures = sourcePreferences?.features;\n\n\tif ( sourceFeatures ) {\n\t\tconst targetFeatures =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t\t[ sourceStoreName ]: sourceFeatures,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove feature preferences from the source.\n\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n}\n\n/**\n * Deprecated: Remove this function and the code in WordPress Core that calls\n * it once WordPress 6.0 is released.\n */\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-post' );\n};\n\nexport default persistencePlugin;\n"]}