@wordpress/data 10.41.0 → 10.41.1-next.v.202603161435.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -28
- package/build/components/async-mode-provider/context.cjs +1 -1
- package/build/components/async-mode-provider/context.cjs.map +3 -3
- package/build/components/async-mode-provider/index.cjs +1 -1
- package/build/components/async-mode-provider/index.cjs.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs.map +3 -3
- package/build/components/registry-provider/context.cjs +1 -1
- package/build/components/registry-provider/context.cjs.map +1 -1
- package/build/components/registry-provider/index.cjs +1 -1
- package/build/components/registry-provider/index.cjs.map +1 -1
- package/build/components/registry-provider/use-registry.cjs +1 -1
- package/build/components/registry-provider/use-registry.cjs.map +3 -3
- package/build/components/use-dispatch/index.cjs +1 -1
- package/build/components/use-dispatch/index.cjs.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs.map +3 -3
- package/build/components/use-dispatch/use-dispatch.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch.cjs.map +3 -3
- package/build/components/use-select/index.cjs +2 -2
- package/build/components/use-select/index.cjs.map +3 -3
- package/build/components/with-dispatch/index.cjs +1 -1
- package/build/components/with-dispatch/index.cjs.map +3 -3
- package/build/components/with-registry/index.cjs +1 -1
- package/build/components/with-registry/index.cjs.map +3 -3
- package/build/components/with-select/index.cjs +1 -1
- package/build/components/with-select/index.cjs.map +3 -3
- package/build/controls.cjs +7 -6
- package/build/controls.cjs.map +3 -3
- package/build/default-registry.cjs +3 -2
- package/build/default-registry.cjs.map +3 -3
- package/build/dispatch.cjs +3 -1
- package/build/dispatch.cjs.map +2 -2
- package/build/factory.cjs.map +2 -2
- package/build/index.cjs +9 -8
- package/build/index.cjs.map +3 -3
- package/build/plugins/index.cjs +1 -1
- package/build/plugins/index.cjs.map +1 -1
- package/build/plugins/persistence/index.cjs +13 -8
- package/build/plugins/persistence/index.cjs.map +3 -3
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +3 -3
- package/build/plugins/persistence/storage/object.cjs +1 -1
- package/build/plugins/persistence/storage/object.cjs.map +3 -3
- package/build/promise-middleware.cjs +2 -1
- package/build/promise-middleware.cjs.map +3 -3
- package/build/redux-store/index.cjs +32 -16
- package/build/redux-store/index.cjs.map +3 -3
- package/build/redux-store/metadata/selectors.cjs +1 -1
- package/build/redux-store/metadata/selectors.cjs.map +3 -3
- package/build/redux-store/metadata/types.cjs +19 -0
- package/build/redux-store/metadata/types.cjs.map +7 -0
- package/build/registry.cjs +11 -7
- package/build/registry.cjs.map +3 -3
- package/build/resolvers-cache-middleware.cjs +6 -3
- package/build/resolvers-cache-middleware.cjs.map +3 -3
- package/build/select.cjs +3 -1
- package/build/select.cjs.map +2 -2
- package/build/store/index.cjs +1 -1
- package/build/store/index.cjs.map +3 -3
- package/build/types.cjs.map +1 -1
- package/build-module/components/async-mode-provider/context.mjs +1 -1
- package/build-module/components/async-mode-provider/context.mjs.map +3 -3
- package/build-module/components/async-mode-provider/index.mjs +1 -1
- package/build-module/components/async-mode-provider/index.mjs.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs.map +3 -3
- package/build-module/components/registry-provider/context.mjs +1 -1
- package/build-module/components/registry-provider/context.mjs.map +1 -1
- package/build-module/components/registry-provider/index.mjs +1 -1
- package/build-module/components/registry-provider/index.mjs.map +1 -1
- package/build-module/components/registry-provider/use-registry.mjs +1 -1
- package/build-module/components/registry-provider/use-registry.mjs.map +3 -3
- package/build-module/components/use-dispatch/index.mjs +1 -1
- package/build-module/components/use-dispatch/index.mjs.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs.map +3 -3
- package/build-module/components/use-dispatch/use-dispatch.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch.mjs.map +3 -3
- package/build-module/components/use-select/index.mjs +2 -2
- package/build-module/components/use-select/index.mjs.map +3 -3
- package/build-module/components/with-dispatch/index.mjs +1 -1
- package/build-module/components/with-dispatch/index.mjs.map +3 -3
- package/build-module/components/with-registry/index.mjs +1 -1
- package/build-module/components/with-registry/index.mjs.map +3 -3
- package/build-module/components/with-select/index.mjs +1 -1
- package/build-module/components/with-select/index.mjs.map +3 -3
- package/build-module/controls.mjs +7 -6
- package/build-module/controls.mjs.map +3 -3
- package/build-module/default-registry.mjs +3 -2
- package/build-module/default-registry.mjs.map +3 -3
- package/build-module/dispatch.mjs +3 -1
- package/build-module/dispatch.mjs.map +2 -2
- package/build-module/factory.mjs.map +2 -2
- package/build-module/index.mjs +4 -3
- package/build-module/index.mjs.map +2 -2
- package/build-module/plugins/index.mjs +1 -1
- package/build-module/plugins/index.mjs.map +1 -1
- package/build-module/plugins/persistence/index.mjs +13 -8
- package/build-module/plugins/persistence/index.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/object.mjs +1 -1
- package/build-module/plugins/persistence/storage/object.mjs.map +3 -3
- package/build-module/promise-middleware.mjs +2 -1
- package/build-module/promise-middleware.mjs.map +3 -3
- package/build-module/redux-store/index.mjs +32 -16
- package/build-module/redux-store/index.mjs.map +3 -3
- package/build-module/redux-store/metadata/selectors.mjs +1 -1
- package/build-module/redux-store/metadata/selectors.mjs.map +3 -3
- package/build-module/redux-store/metadata/types.mjs +1 -0
- package/build-module/redux-store/metadata/types.mjs.map +7 -0
- package/build-module/registry.mjs +11 -7
- package/build-module/registry.mjs.map +3 -3
- package/build-module/resolvers-cache-middleware.mjs +6 -3
- package/build-module/resolvers-cache-middleware.mjs.map +3 -3
- package/build-module/select.mjs +3 -1
- package/build-module/select.mjs.map +2 -2
- package/build-module/store/index.mjs +1 -1
- package/build-module/store/index.mjs.map +3 -3
- package/build-types/components/async-mode-provider/context.d.ts +37 -3
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/index.d.ts +2 -2
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -1
- package/build-types/components/registry-provider/context.d.ts +10 -3
- package/build-types/components/registry-provider/context.d.ts.map +1 -1
- package/build-types/components/registry-provider/index.d.ts +2 -2
- package/build-types/components/registry-provider/index.d.ts.map +1 -1
- package/build-types/components/registry-provider/use-registry.d.ts +3 -2
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -1
- package/build-types/components/use-dispatch/index.d.ts +2 -2
- package/build-types/components/use-dispatch/index.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +11 -9
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch.d.ts +10 -19
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -1
- package/build-types/components/use-select/index.d.ts +24 -28
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/components/with-dispatch/index.d.ts +10 -11
- package/build-types/components/with-dispatch/index.d.ts.map +1 -1
- package/build-types/components/with-registry/index.d.ts +2 -6
- package/build-types/components/with-registry/index.d.ts.map +1 -1
- package/build-types/components/with-select/index.d.ts +7 -8
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/build-types/controls.d.ts +57 -44
- package/build-types/controls.d.ts.map +1 -1
- package/build-types/default-registry.d.ts +2 -2
- package/build-types/default-registry.d.ts.map +1 -1
- package/build-types/dispatch.d.ts +4 -0
- package/build-types/dispatch.d.ts.map +1 -1
- package/build-types/factory.d.ts +2 -1
- package/build-types/factory.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/index.d.ts +1 -1
- package/build-types/plugins/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts +38 -27
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/default.d.ts +7 -1
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/object.d.ts +4 -5
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
- package/build-types/promise-middleware.d.ts +6 -4
- package/build-types/promise-middleware.d.ts.map +1 -1
- package/build-types/redux-store/index.d.ts +12 -15
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts +45 -50
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/build-types/redux-store/metadata/types.d.ts +48 -0
- package/build-types/redux-store/metadata/types.d.ts.map +1 -0
- package/build-types/registry.d.ts +5 -49
- package/build-types/registry.d.ts.map +1 -1
- package/build-types/resolvers-cache-middleware.d.ts +13 -7
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
- package/build-types/select.d.ts +3 -0
- package/build-types/select.d.ts.map +1 -1
- package/build-types/store/index.d.ts +5 -12
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/types.d.ts +201 -10
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/async-mode-provider/{context.js → context.ts} +0 -1
- package/src/components/async-mode-provider/{use-async-mode.js → use-async-mode.ts} +1 -1
- package/src/components/registry-provider/{use-registry.js → use-registry.ts} +3 -2
- package/src/components/use-dispatch/{use-dispatch-with-map.js → use-dispatch-with-map.ts} +18 -9
- package/src/components/use-dispatch/{use-dispatch.js → use-dispatch.ts} +25 -20
- package/src/components/use-select/{index.js → index.ts} +84 -70
- package/src/components/with-dispatch/{index.js → index.tsx} +20 -13
- package/src/components/with-registry/{index.js → index.tsx} +1 -5
- package/src/components/with-select/{index.js → index.tsx} +17 -10
- package/src/{controls.js → controls.ts} +53 -26
- package/src/{default-registry.js → default-registry.ts} +3 -1
- package/src/dispatch.ts +7 -1
- package/src/factory.ts +4 -3
- package/src/index.ts +4 -8
- package/src/plugins/persistence/{index.js → index.ts} +93 -54
- package/src/plugins/persistence/storage/{default.js → default.ts} +3 -2
- package/src/plugins/persistence/storage/object.ts +25 -0
- package/src/{promise-middleware.js → promise-middleware.ts} +3 -3
- package/src/redux-store/{index.js → index.ts} +218 -131
- package/src/redux-store/metadata/{selectors.js → selectors.ts} +83 -54
- package/src/redux-store/metadata/types.ts +100 -0
- package/src/{registry.js → registry.ts} +98 -88
- package/src/{resolvers-cache-middleware.js → resolvers-cache-middleware.ts} +22 -7
- package/src/select.ts +6 -1
- package/src/store/{index.js → index.ts} +13 -8
- package/src/types.ts +263 -24
- package/src/plugins/persistence/storage/object.js +0 -23
- /package/src/components/async-mode-provider/{index.js → index.ts} +0 -0
- /package/src/components/registry-provider/{context.js → context.ts} +0 -0
- /package/src/components/registry-provider/{index.js → index.ts} +0 -0
- /package/src/components/use-dispatch/{index.js → index.ts} +0 -0
- /package/src/plugins/{index.js → index.ts} +0 -0
package/build/controls.cjs
CHANGED
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// packages/data/src/controls.
|
|
20
|
+
// packages/data/src/controls.ts
|
|
21
21
|
var controls_exports = {};
|
|
22
22
|
__export(controls_exports, {
|
|
23
23
|
builtinControls: () => builtinControls,
|
|
@@ -28,13 +28,13 @@ var import_factory = require("./factory.cjs");
|
|
|
28
28
|
var SELECT = "@@data/SELECT";
|
|
29
29
|
var RESOLVE_SELECT = "@@data/RESOLVE_SELECT";
|
|
30
30
|
var DISPATCH = "@@data/DISPATCH";
|
|
31
|
-
function
|
|
31
|
+
function isStoreDescriptor(object) {
|
|
32
32
|
return object !== null && typeof object === "object";
|
|
33
33
|
}
|
|
34
34
|
function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
35
35
|
return {
|
|
36
36
|
type: SELECT,
|
|
37
|
-
storeKey:
|
|
37
|
+
storeKey: isStoreDescriptor(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
38
38
|
selectorName,
|
|
39
39
|
args
|
|
40
40
|
};
|
|
@@ -42,7 +42,7 @@ function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
42
42
|
function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
43
43
|
return {
|
|
44
44
|
type: RESOLVE_SELECT,
|
|
45
|
-
storeKey:
|
|
45
|
+
storeKey: isStoreDescriptor(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
46
46
|
selectorName,
|
|
47
47
|
args
|
|
48
48
|
};
|
|
@@ -50,7 +50,7 @@ function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
50
50
|
function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
51
51
|
return {
|
|
52
52
|
type: DISPATCH,
|
|
53
|
-
storeKey:
|
|
53
|
+
storeKey: isStoreDescriptor(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
54
54
|
actionName,
|
|
55
55
|
args
|
|
56
56
|
};
|
|
@@ -62,7 +62,8 @@ var builtinControls = {
|
|
|
62
62
|
),
|
|
63
63
|
[RESOLVE_SELECT]: (0, import_factory.createRegistryControl)(
|
|
64
64
|
(registry) => ({ storeKey, selectorName, args }) => {
|
|
65
|
-
const
|
|
65
|
+
const selector = registry.select(storeKey)[selectorName];
|
|
66
|
+
const method = selector.hasResolver ? "resolveSelect" : "select";
|
|
66
67
|
return registry[method](storeKey)[selectorName](
|
|
67
68
|
...args
|
|
68
69
|
);
|
package/build/controls.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/controls.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAsC;
|
|
3
|
+
"sources": ["../src/controls.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\nimport type { StoreDescriptor } from './types';\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\nfunction isStoreDescriptor( object: unknown ): object is StoreDescriptor {\n\treturn object !== null && typeof object === 'object';\n}\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 storeNameOrDescriptor Unique namespace identifier for the store\n * @param selectorName The name of the selector.\n * @param 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 The control descriptor.\n */\nfunction select(\n\tstoreNameOrDescriptor: string | StoreDescriptor,\n\tselectorName: string,\n\t...args: unknown[]\n) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isStoreDescriptor( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\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 storeNameOrDescriptor Unique namespace identifier for the store\n * @param selectorName The name of the selector\n * @param 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 The control descriptor.\n */\nfunction resolveSelect(\n\tstoreNameOrDescriptor: string | StoreDescriptor< any >,\n\tselectorName: string,\n\t...args: any[]\n) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isStoreDescriptor( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param storeNameOrDescriptor Unique namespace identifier for the store\n * @param actionName The name of the action to dispatch\n * @param 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/editor', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return The control descriptor.\n */\nfunction dispatch(\n\tstoreNameOrDescriptor: string | StoreDescriptor,\n\tactionName: string,\n\t...args: unknown[]\n) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isStoreDescriptor( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\ntype SelectorControlArgs = {\n\tstoreKey: string;\n\tselectorName: string;\n\targs: unknown[];\n};\n\ntype ActionControlArgs = {\n\tstoreKey: string;\n\tactionName: string;\n\targs: unknown[];\n};\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args }: SelectorControlArgs ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args }: SelectorControlArgs ) => {\n\t\t\t\tconst selector = registry.select( storeKey )[\n\t\t\t\t\tselectorName\n\t\t\t\t] as ( ( ...a: any[] ) => any ) & {\n\t\t\t\t\thasResolver?: boolean;\n\t\t\t\t};\n\t\t\t\tconst method = selector.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args }: ActionControlArgs ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAsC;AAGtC,IAAM,SAAS;AACf,IAAM,iBAAiB;AACvB,IAAM,WAAW;AAEjB,SAAS,kBAAmB,QAA6C;AACxE,SAAO,WAAW,QAAQ,OAAO,WAAW;AAC7C;AAyBA,SAAS,OACR,uBACA,iBACG,MACF;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,kBAAmB,qBAAsB,IAChD,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AA0BA,SAAS,cACR,uBACA,iBACG,MACF;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,kBAAmB,qBAAsB,IAChD,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AAsBA,SAAS,SACR,uBACA,eACG,MACF;AACD,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,kBAAmB,qBAAsB,IAChD,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AAEO,IAAM,WAAW,EAAE,QAAQ,eAAe,SAAS;AAcnD,IAAM,kBAAkB;AAAA,EAC9B,CAAE,MAAO,OAAG;AAAA,IACX,CAAE,aACD,CAAE,EAAE,UAAU,cAAc,KAAK,MAChC,SAAS,OAAQ,QAAS,EAAG,YAAa,EAAG,GAAG,IAAK;AAAA,EACxD;AAAA,EACA,CAAE,cAAe,OAAG;AAAA,IACnB,CAAE,aACD,CAAE,EAAE,UAAU,cAAc,KAAK,MAA4B;AAC5D,YAAM,WAAW,SAAS,OAAQ,QAAS,EAC1C,YACD;AAGA,YAAM,SAAS,SAAS,cACrB,kBACA;AACH,aAAO,SAAU,MAAO,EAAG,QAAS,EAAG,YAAa;AAAA,QACnD,GAAG;AAAA,MACJ;AAAA,IACD;AAAA,EACF;AAAA,EACA,CAAE,QAAS,OAAG;AAAA,IACb,CAAE,aACD,CAAE,EAAE,UAAU,YAAY,KAAK,MAC9B,SAAS,SAAU,QAAS,EAAG,UAAW,EAAG,GAAG,IAAK;AAAA,EACxD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,12 +17,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// packages/data/src/default-registry.
|
|
20
|
+
// packages/data/src/default-registry.ts
|
|
21
21
|
var default_registry_exports = {};
|
|
22
22
|
__export(default_registry_exports, {
|
|
23
23
|
default: () => default_registry_default
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(default_registry_exports);
|
|
26
26
|
var import_registry = require("./registry.cjs");
|
|
27
|
-
var
|
|
27
|
+
var defaultRegistry = (0, import_registry.createRegistry)();
|
|
28
|
+
var default_registry_default = defaultRegistry;
|
|
28
29
|
//# sourceMappingURL=default-registry.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/default-registry.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistry } from './registry';\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA+B;AAE/B,
|
|
3
|
+
"sources": ["../src/default-registry.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistry } from './registry';\n\nconst defaultRegistry = createRegistry();\n\nexport default defaultRegistry;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA+B;AAE/B,IAAM,sBAAkB,gCAAe;AAEvC,IAAO,2BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/dispatch.cjs
CHANGED
|
@@ -35,7 +35,9 @@ __export(dispatch_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(dispatch_exports);
|
|
36
36
|
var import_default_registry = __toESM(require("./default-registry.cjs"));
|
|
37
37
|
function dispatch(storeNameOrDescriptor) {
|
|
38
|
-
return import_default_registry.default.dispatch(
|
|
38
|
+
return import_default_registry.default.dispatch(
|
|
39
|
+
storeNameOrDescriptor
|
|
40
|
+
);
|
|
39
41
|
}
|
|
40
42
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
43
|
0 && (module.exports = {
|
package/build/dispatch.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dispatch.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, 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 storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAA4B;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, 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 * Warning: This global `dispatch` function only works with the default registry.\n * It will not work with custom `RegistryProvider` or `BlockEditorProvider` contexts.\n * In React components, prefer the `useDispatch` hook instead, which is registry-aware.\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch(\n\t\tstoreNameOrDescriptor\n\t) as DispatchReturn< StoreNameOrDescriptor >;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAA4B;AAyBrB,SAAS,SAGf,uBAC0C;AAC1C,SAAO,wBAAAA,QAAgB;AAAA,IACtB;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["defaultRegistry"]
|
|
7
7
|
}
|
package/build/factory.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/factory.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\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 * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).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( coreStore ).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 registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\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 wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\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 `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\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 registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\nimport type { DataRegistry } from './types';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\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 * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).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( coreStore ).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 registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\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 wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\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 `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\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 registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl<\n\tT extends ( registry: DataRegistry ) => ( ...args: any ) => any,\n>( registryControl: T & { isRegistryControl?: boolean } ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDO,SAAS,uBAGf,kBAC+B;AAC/B,QAAM,sBAAsB,oBAAI,QAAQ;AAIxC,QAAM,kBAAgD,IAAK,SAAU;AACpE,QAAI,WAAW,oBAAoB,IAAK,gBAAgB,QAAS;AAKjE,QAAK,CAAE,UAAW;AACjB,iBAAW,iBAAkB,gBAAgB,SAAS,MAAO;AAC7D,0BAAoB,IAAK,gBAAgB,UAAU,QAAS;AAAA,IAC7D;AACA,WAAO,SAAU,GAAG,IAAK;AAAA,EAC1B;AAOA,kBAAgB,qBAAqB;AAErC,SAAO;AACR;AAsBO,SAAS,sBAEb,iBAAuD;AACzD,kBAAgB,oBAAoB;AAEpC,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/index.cjs
CHANGED
|
@@ -76,17 +76,18 @@ var import_controls = require("./controls.cjs");
|
|
|
76
76
|
var import_redux_store2 = __toESM(require("./redux-store/index.cjs"));
|
|
77
77
|
var import_dispatch = require("./dispatch.cjs");
|
|
78
78
|
var import_select = require("./select.cjs");
|
|
79
|
-
var defaultRegistry = import_default_registry.default;
|
|
80
79
|
var combineReducers = import_redux_store.combineReducers;
|
|
81
80
|
function resolveSelect(storeNameOrDescriptor) {
|
|
82
|
-
return
|
|
81
|
+
return import_default_registry.default.resolveSelect(
|
|
82
|
+
storeNameOrDescriptor
|
|
83
|
+
);
|
|
83
84
|
}
|
|
84
|
-
var suspendSelect = (storeNameOrDescriptor) =>
|
|
85
|
-
var subscribe = (listener, storeNameOrDescriptor) =>
|
|
86
|
-
var registerGenericStore =
|
|
87
|
-
var registerStore =
|
|
88
|
-
var use =
|
|
89
|
-
var register = (store) =>
|
|
85
|
+
var suspendSelect = (storeNameOrDescriptor) => import_default_registry.default.suspendSelect(storeNameOrDescriptor);
|
|
86
|
+
var subscribe = (listener, storeNameOrDescriptor) => import_default_registry.default.subscribe(listener, storeNameOrDescriptor);
|
|
87
|
+
var registerGenericStore = import_default_registry.default.registerGenericStore;
|
|
88
|
+
var registerStore = import_default_registry.default.registerStore;
|
|
89
|
+
var use = import_default_registry.default.use;
|
|
90
|
+
var register = (store) => import_default_registry.default.register(store);
|
|
90
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
92
|
0 && (module.exports = {
|
|
92
93
|
AsyncModeProvider,
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
6
|
-
"names": ["import_redux_store", "
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\nimport type {\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tcombineReducers as CombineReducers,\n\tAnyConfig,\n\tCurriedSelectorsResolveOf,\n} from './types';\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 {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} 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 { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\nexport type * from './types';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\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 * @type {import('./types').combineReducers}\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 const combineReducers =\n\tcombineReducersModule as unknown as CombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors\n * pre-bound to state so that you only need to supply additional arguments, and\n * modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return Object containing the store's promise-wrapped selectors.\n */\nexport function resolveSelect< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: T | string\n): CurriedSelectorsResolveOf< T > {\n\treturn defaultRegistry.resolveSelect(\n\t\tstoreNameOrDescriptor\n\t) as CurriedSelectorsResolveOf< T >;\n}\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.suspendSelect( storeNameOrDescriptor );\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. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\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 = (\n\tlistener: () => void,\n\tstoreNameOrDescriptor?:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): ( () => void ) =>\n\tdefaultRegistry.subscribe( listener, storeNameOrDescriptor );\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore: Function =\n\tdefaultRegistry.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: Function = 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: any = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\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 {StoreDescriptor} store Store descriptor.\n */\nexport const register = (\n\tstore: StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): void => defaultRegistry.register( store );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,8BAA4B;AAC5B,cAAyB;AACzB,yBAAyD;AAUzD,yBAAsC;AACtC,2BAAwC;AACxC,2BAAwC;AACxC,+BAIO;AACP,wBAGO;AACP,0BAA4B;AAC5B,iCAAkC;AAClC,sBAA+B;AAC/B,qBAA8D;AAC9D,6BAA+B;AAC/B,sBAAyB;AACzB,IAAAA,sBAA4C;AAC5C,sBAAyB;AACzB,oBAAuB;AAkDhB,IAAM,kBACZ,mBAAAC;AAsBM,SAAS,cACf,uBACiC;AACjC,SAAO,wBAAAC,QAAgB;AAAA,IACtB;AAAA,EACD;AACD;AAaO,IAAM,gBAAgB,CAC5B,0BAGS,wBAAAA,QAAgB,cAAe,qBAAsB;AA0BxD,IAAM,YAAY,CACxB,UACA,0BAIA,wBAAAA,QAAgB,UAAW,UAAU,qBAAsB;AAUrD,IAAM,uBACZ,wBAAAA,QAAgB;AAYV,IAAM,gBAA0B,wBAAAA,QAAgB;AAShD,IAAM,MAAW,wBAAAA,QAAgB;AAoBjC,IAAM,WAAW,CACvB,UACU,wBAAAA,QAAgB,SAAU,KAAM;",
|
|
6
|
+
"names": ["import_redux_store", "combineReducersModule", "defaultRegistry"]
|
|
7
7
|
}
|
package/build/plugins/index.cjs
CHANGED
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/data/src/plugins/index.
|
|
30
|
+
// packages/data/src/plugins/index.ts
|
|
31
31
|
var plugins_exports = {};
|
|
32
32
|
__export(plugins_exports, {
|
|
33
33
|
persistence: () => import_persistence.default
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/plugins/index.
|
|
3
|
+
"sources": ["../../src/plugins/index.ts"],
|
|
4
4
|
"sourcesContent": ["export { default as persistence } from './persistence';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAuC;",
|
|
6
6
|
"names": []
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/data/src/plugins/persistence/index.
|
|
30
|
+
// packages/data/src/plugins/persistence/index.ts
|
|
31
31
|
var persistence_exports = {};
|
|
32
32
|
__export(persistence_exports, {
|
|
33
33
|
createPersistenceInterface: () => createPersistenceInterface,
|
|
@@ -89,7 +89,7 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
89
89
|
(0, import__.combineReducers)(reducers)
|
|
90
90
|
);
|
|
91
91
|
} else {
|
|
92
|
-
getPersistedState = (
|
|
92
|
+
getPersistedState = (_state, action) => action.nextState;
|
|
93
93
|
}
|
|
94
94
|
let lastState = getPersistedState(void 0, {
|
|
95
95
|
nextState: getState()
|
|
@@ -115,9 +115,13 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
115
115
|
type: "@@WP/PERSISTENCE_RESTORE"
|
|
116
116
|
});
|
|
117
117
|
if ((0, import_is_plain_object.isPlainObject)(initialState) && (0, import_is_plain_object.isPlainObject)(persistedState)) {
|
|
118
|
-
initialState = (0, import_deepmerge.default)(
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
initialState = (0, import_deepmerge.default)(
|
|
119
|
+
initialState,
|
|
120
|
+
persistedState,
|
|
121
|
+
{
|
|
122
|
+
isMergeableObject: import_is_plain_object.isPlainObject
|
|
123
|
+
}
|
|
124
|
+
);
|
|
121
125
|
} else {
|
|
122
126
|
initialState = persistedState;
|
|
123
127
|
}
|
|
@@ -138,9 +142,10 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
138
142
|
}
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
var persistence_default = Object.assign(persistencePlugin, {
|
|
146
|
+
__unstableMigrate: () => {
|
|
147
|
+
}
|
|
148
|
+
});
|
|
144
149
|
// Annotate the CommonJS export names for ESM import in node:
|
|
145
150
|
0 && (module.exports = {
|
|
146
151
|
createPersistenceInterface,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/persistence/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
3
|
+
"sources": ["../../../src/plugins/persistence/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\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 reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\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 key Key to update.\n\t * @param value Updated value.\n\t */\n\tfunction setData( key: string, value: unknown ): void {\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 registry Data registry.\n * @param pluginOptions Plugin options.\n *\n * @return Data plugin.\n */\nfunction persistencePlugin(\n\tregistry: DataRegistry,\n\tpluginOptions: PersistencePluginOptions\n): Partial< DataRegistry > {\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 getState Function which returns current state.\n\t * @param storeName Store name.\n\t * @param keys Optional subset of keys to save.\n\t *\n\t * @return Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange(\n\t\tgetState: () => unknown,\n\t\tstoreName: string,\n\t\tkeys: boolean | string[]\n\t): () => void {\n\t\tlet getPersistedState: ( state: any, action: any ) => any;\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(\n\t\t\t\t\taccumulator: Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t( state: any, action: any ) => any\n\t\t\t\t\t>,\n\t\t\t\t\tkey: string\n\t\t\t\t) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: (\n\t\t\t\t\t\t\tstate: unknown,\n\t\t\t\t\t\t\taction: { nextState: Record< string, unknown > }\n\t\t\t\t\t\t) => 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 = (\n\t\t\t\t_state: unknown,\n\t\t\t\taction: { nextState: unknown }\n\t\t\t) => 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(\n\t\t\tstoreName: string,\n\t\t\toptions: ReduxStoreConfig< any, any, any > & {\n\t\t\t\tpersist?: boolean | string[];\n\t\t\t}\n\t\t) {\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 = deepmerge(\n\t\t\t\t\t\tinitialState as Record< string, unknown >,\n\t\t\t\t\t\tpersistedState as Record< string, unknown >,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\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\nexport default Object.assign( persistencePlugin, {\n\t__unstableMigrate: () => {},\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,6BAA8B;AAC9B,uBAAsB;AAKtB,qBAA2B;AAC3B,eAAgC;AA4BhC,IAAM,kBAAkB,eAAAA;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,SAAU,OAAQ;AAGjB,iBAAO,CAAC;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAQA,WAAS,QAAS,KAAa,OAAuB;AACrD,WAAO,EAAE,GAAG,MAAM,CAAE,GAAI,GAAG,MAAM;AACjC,YAAQ,QAAS,YAAY,KAAK,UAAW,IAAK,CAAE;AAAA,EACrD;AAEA,SAAO;AAAA,IACN,KAAK;AAAA,IACL,KAAK;AAAA,EACN;AACD;AAUA,SAAS,kBACR,UACA,eAC0B;AAC1B,QAAM,cAAc,2BAA4B,aAAc;AAY9D,WAAS,sBACR,UACA,WACA,MACa;AACb,QAAI;AACJ,QAAK,MAAM,QAAS,IAAK,GAAI;AAM5B,YAAM,WAAW,KAAK;AAAA,QACrB,CACC,aAIA,QAEA,OAAO,OAAQ,aAAa;AAAA,UAC3B,CAAE,GAAI,GAAG,CACR,OACA,WACI,OAAO,UAAW,GAAI;AAAA,QAC5B,CAAE;AAAA,QACH,CAAC;AAAA,MACF;AAEA,0BAAoB;AAAA,YACnB,0BAAiB,QAAS;AAAA,MAC3B;AAAA,IACD,OAAO;AACN,0BAAoB,CACnB,QACA,WACI,OAAO;AAAA,IACb;AAEA,QAAI,YAAY,kBAAmB,QAAW;AAAA,MAC7C,WAAW,SAAS;AAAA,IACrB,CAAE;AAEF,WAAO,MAAM;AACZ,YAAM,QAAQ,kBAAmB,WAAW;AAAA,QAC3C,WAAW,SAAS;AAAA,MACrB,CAAE;AACF,UAAK,UAAU,WAAY;AAC1B,oBAAY,IAAK,WAAW,KAAM;AAClC,oBAAY;AAAA,MACb;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AAAA,IACN,cACC,WACA,SAGC;AACD,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO,SAAS,cAAe,WAAW,OAAQ;AAAA,MACnD;AAGA,YAAM,iBAAiB,YAAY,IAAI,EAAG,SAAU;AACpD,UAAK,mBAAmB,QAAY;AACnC,YAAI,eAAe,QAAQ,QAAS,QAAQ,cAAc;AAAA,UACzD,MAAM;AAAA,QACP,CAAE;AAEF,gBACC,sCAAe,YAAa,SAC5B,sCAAe,cAAe,GAC7B;AAMD,6BAAe,iBAAAC;AAAA,YACd;AAAA,YACA;AAAA,YACA;AAAA,cACC,mBAAmB;AAAA,YACpB;AAAA,UACD;AAAA,QACD,OAAO;AAGN,yBAAe;AAAA,QAChB;AAEA,kBAAU;AAAA,UACT,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,SAAS,cAAe,WAAW,OAAQ;AAEzD,YAAM;AAAA,QACL;AAAA,UACC,MAAM;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAO,sBAAQ,OAAO,OAAQ,mBAAmB;AAAA,EAChD,mBAAmB,MAAM;AAAA,EAAC;AAC3B,CAAE;",
|
|
6
6
|
"names": ["defaultStorage", "deepmerge"]
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/data/src/plugins/persistence/storage/default.
|
|
30
|
+
// packages/data/src/plugins/persistence/storage/default.ts
|
|
31
31
|
var default_exports = {};
|
|
32
32
|
__export(default_exports, {
|
|
33
33
|
default: () => default_default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/persistence/storage/default.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport objectStorage from './object';\n\nlet storage;\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem( '__wpDataTestLocalStorage' );\n} catch ( error ) {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
3
|
+
"sources": ["../../../../src/plugins/persistence/storage/default.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch ( error ) {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA0B;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,SAAU,OAAQ;AACjB,YAAU,cAAAA;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": ["objectStorage"]
|
|
7
7
|
}
|
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// packages/data/src/plugins/persistence/storage/object.
|
|
20
|
+
// packages/data/src/plugins/persistence/storage/object.ts
|
|
21
21
|
var object_exports = {};
|
|
22
22
|
__export(object_exports, {
|
|
23
23
|
default: () => object_default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/persistence/storage/object.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
3
|
+
"sources": ["../../../../src/plugins/persistence/storage/object.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StorageInterface } from '../../../types';\n\nlet objectStorage: Record< string, string > | undefined;\n\nconst storage: StorageInterface & { clear: VoidFunction } = {\n\tgetItem( key: string ): string | null {\n\t\tif ( ! objectStorage || ! objectStorage[ key ] ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn objectStorage[ key ];\n\t},\n\tsetItem( key: string, value: string ) {\n\t\tif ( ! objectStorage ) {\n\t\t\tstorage.clear();\n\t\t}\n\n\t\tobjectStorage![ key ] = String( value );\n\t},\n\tclear() {\n\t\tobjectStorage = Object.create( null );\n\t},\n};\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,IAAI;AAEJ,IAAM,UAAsD;AAAA,EAC3D,QAAS,KAA6B;AACrC,QAAK,CAAE,iBAAiB,CAAE,cAAe,GAAI,GAAI;AAChD,aAAO;AAAA,IACR;AAEA,WAAO,cAAe,GAAI;AAAA,EAC3B;AAAA,EACA,QAAS,KAAa,OAAgB;AACrC,QAAK,CAAE,eAAgB;AACtB,cAAQ,MAAM;AAAA,IACf;AAEA,kBAAgB,GAAI,IAAI,OAAQ,KAAM;AAAA,EACvC;AAAA,EACA,QAAQ;AACP,oBAAgB,uBAAO,OAAQ,IAAK;AAAA,EACrC;AACD;AAEA,IAAO,iBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/data/src/promise-middleware.
|
|
30
|
+
// packages/data/src/promise-middleware.ts
|
|
31
31
|
var promise_middleware_exports = {};
|
|
32
32
|
__export(promise_middleware_exports, {
|
|
33
33
|
default: () => promise_middleware_default
|
|
@@ -40,6 +40,7 @@ var promiseMiddleware = () => (next) => (action) => {
|
|
|
40
40
|
if (resolvedAction) {
|
|
41
41
|
return next(resolvedAction);
|
|
42
42
|
}
|
|
43
|
+
return void 0;
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
return next(action);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/promise-middleware.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport isPromise from 'is-promise';\n\n/**\n * Simplest possible promise redux middleware.\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
3
|
+
"sources": ["../src/promise-middleware.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { Middleware } from 'redux';\nimport isPromise from 'is-promise';\n\n/**\n * Simplest possible promise redux middleware.\n */\nconst promiseMiddleware: Middleware = () => ( next ) => ( action ) => {\n\tif ( isPromise( action ) ) {\n\t\treturn action.then( ( resolvedAction ) => {\n\t\t\tif ( resolvedAction ) {\n\t\t\t\treturn next( resolvedAction );\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} );\n\t}\n\n\treturn next( action );\n};\n\nexport default promiseMiddleware;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,wBAAsB;AAKtB,IAAM,oBAAgC,MAAM,CAAE,SAAU,CAAE,WAAY;AACrE,UAAK,kBAAAA,SAAW,MAAO,GAAI;AAC1B,WAAO,OAAO,KAAM,CAAE,mBAAoB;AACzC,UAAK,gBAAiB;AACrB,eAAO,KAAM,cAAe;AAAA,MAC7B;AACA,aAAO;AAAA,IACR,CAAE;AAAA,EACH;AAEA,SAAO,KAAM,MAAO;AACrB;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": ["isPromise"]
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/data/src/redux-store/index.
|
|
30
|
+
// packages/data/src/redux-store/index.ts
|
|
31
31
|
var redux_store_exports = {};
|
|
32
32
|
__export(redux_store_exports, {
|
|
33
33
|
combineReducers: () => import_combine_reducers.combineReducers,
|
|
@@ -62,11 +62,11 @@ var mapValues = (obj, callback) => Object.fromEntries(
|
|
|
62
62
|
callback(value, key)
|
|
63
63
|
])
|
|
64
64
|
);
|
|
65
|
-
var devToolsReplacer = (
|
|
65
|
+
var devToolsReplacer = (_key, state) => {
|
|
66
66
|
if (state instanceof Map) {
|
|
67
67
|
return Object.fromEntries(state);
|
|
68
68
|
}
|
|
69
|
-
if (state instanceof window.HTMLElement) {
|
|
69
|
+
if (typeof window !== "undefined" && state instanceof window.HTMLElement) {
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
72
72
|
return state;
|
|
@@ -75,7 +75,7 @@ function createResolversCache() {
|
|
|
75
75
|
const cache = {};
|
|
76
76
|
return {
|
|
77
77
|
isRunning(selectorName, args) {
|
|
78
|
-
return cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args));
|
|
78
|
+
return !!(cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args)));
|
|
79
79
|
},
|
|
80
80
|
clear(selectorName, args) {
|
|
81
81
|
if (cache[selectorName]) {
|
|
@@ -154,8 +154,14 @@ function createReduxStore(key, options) {
|
|
|
154
154
|
return (...args) => Promise.resolve(store.dispatch(action(...args)));
|
|
155
155
|
}
|
|
156
156
|
const actions = {
|
|
157
|
-
...mapValues(
|
|
158
|
-
|
|
157
|
+
...mapValues(
|
|
158
|
+
metadataActions,
|
|
159
|
+
bindAction
|
|
160
|
+
),
|
|
161
|
+
...mapValues(
|
|
162
|
+
options.actions,
|
|
163
|
+
bindAction
|
|
164
|
+
)
|
|
159
165
|
};
|
|
160
166
|
const allActions = createPrivateProxy(
|
|
161
167
|
actions,
|
|
@@ -166,10 +172,15 @@ function createReduxStore(key, options) {
|
|
|
166
172
|
);
|
|
167
173
|
const thunkDispatch = new Proxy(
|
|
168
174
|
(action) => store.dispatch(action),
|
|
169
|
-
{
|
|
175
|
+
{
|
|
176
|
+
get: (_target, name) => allActions[name]
|
|
177
|
+
}
|
|
170
178
|
);
|
|
171
179
|
(0, import_lock_unlock.lock)(actions, allActions);
|
|
172
|
-
const resolvers = options.resolvers ? mapValues(
|
|
180
|
+
const resolvers = options.resolvers ? mapValues(
|
|
181
|
+
options.resolvers,
|
|
182
|
+
mapResolver
|
|
183
|
+
) : {};
|
|
173
184
|
function bindSelector(selector, selectorName) {
|
|
174
185
|
if (selector.isRegistrySelector) {
|
|
175
186
|
selector.registry = registry;
|
|
@@ -223,7 +234,10 @@ function createReduxStore(key, options) {
|
|
|
223
234
|
metadataSelectors,
|
|
224
235
|
bindMetadataSelector
|
|
225
236
|
);
|
|
226
|
-
const boundSelectors = mapValues(
|
|
237
|
+
const boundSelectors = mapValues(
|
|
238
|
+
options.selectors,
|
|
239
|
+
bindSelector
|
|
240
|
+
);
|
|
227
241
|
const selectors = {
|
|
228
242
|
...boundMetadataSelectors,
|
|
229
243
|
...boundSelectors
|
|
@@ -241,7 +255,9 @@ function createReduxStore(key, options) {
|
|
|
241
255
|
}
|
|
242
256
|
const thunkSelect = new Proxy(
|
|
243
257
|
(selector) => selector(store.__unstableOriginalGetState()),
|
|
244
|
-
{
|
|
258
|
+
{
|
|
259
|
+
get: (_target, name) => allSelectors[name]
|
|
260
|
+
}
|
|
245
261
|
);
|
|
246
262
|
(0, import_lock_unlock.lock)(selectors, allSelectors);
|
|
247
263
|
const bindResolveSelector = mapResolveSelector(
|
|
@@ -283,10 +299,10 @@ function createReduxStore(key, options) {
|
|
|
283
299
|
const getSuspendSelectors = () => suspendSelectors;
|
|
284
300
|
store.__unstableOriginalGetState = store.getState;
|
|
285
301
|
store.getState = () => store.__unstableOriginalGetState().root;
|
|
286
|
-
const subscribe =
|
|
302
|
+
const subscribe = (listener) => {
|
|
287
303
|
listeners.add(listener);
|
|
288
304
|
return () => listeners.delete(listener);
|
|
289
|
-
}
|
|
305
|
+
};
|
|
290
306
|
let lastState = store.__unstableOriginalGetState();
|
|
291
307
|
store.subscribe(() => {
|
|
292
308
|
const state = store.__unstableOriginalGetState();
|
|
@@ -350,13 +366,13 @@ function instantiateReduxStore(key, options, registry, thunkArgs) {
|
|
|
350
366
|
return (0, import_redux.createStore)(
|
|
351
367
|
enhancedReducer,
|
|
352
368
|
{ root: initialState },
|
|
353
|
-
(0, import_compose.compose)(enhancers)
|
|
369
|
+
(0, import_compose.compose)(...enhancers)
|
|
354
370
|
);
|
|
355
371
|
}
|
|
356
372
|
function mapResolveSelector(store, boundMetadataSelectors) {
|
|
357
373
|
return (selector, selectorName) => {
|
|
358
374
|
if (!selector.hasResolver) {
|
|
359
|
-
return async (...args) => selector
|
|
375
|
+
return async (...args) => selector(...args);
|
|
360
376
|
}
|
|
361
377
|
return (...args) => new Promise((resolve, reject) => {
|
|
362
378
|
const hasFinished = () => {
|
|
@@ -380,7 +396,7 @@ function mapResolveSelector(store, boundMetadataSelectors) {
|
|
|
380
396
|
resolve(result2);
|
|
381
397
|
}
|
|
382
398
|
};
|
|
383
|
-
const getResult = () => selector
|
|
399
|
+
const getResult = () => selector(...args);
|
|
384
400
|
const result = getResult();
|
|
385
401
|
if (hasFinished()) {
|
|
386
402
|
return finalize(result);
|
|
@@ -400,7 +416,7 @@ function mapSuspendSelector(store, boundMetadataSelectors) {
|
|
|
400
416
|
return selector;
|
|
401
417
|
}
|
|
402
418
|
return (...args) => {
|
|
403
|
-
const result = selector
|
|
419
|
+
const result = selector(...args);
|
|
404
420
|
if (boundMetadataSelectors.hasFinishedResolution(
|
|
405
421
|
selectorName,
|
|
406
422
|
args
|