@wordpress/data 10.33.1 → 10.34.1-next.2f1c7c01b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/async-mode-provider/context.js +5 -3
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/async-mode-provider/index.js +2 -0
- package/build/components/async-mode-provider/index.js.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.js +2 -0
- package/build/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build/components/registry-provider/context.js +5 -3
- package/build/components/registry-provider/context.js.map +1 -1
- package/build/components/registry-provider/index.js +2 -0
- package/build/components/registry-provider/index.js.map +1 -1
- package/build/components/registry-provider/use-registry.js +2 -0
- package/build/components/registry-provider/use-registry.js.map +1 -1
- package/build/components/use-dispatch/index.js +2 -0
- package/build/components/use-dispatch/index.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +3 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +3 -1
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +3 -1
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-dispatch/index.js +4 -2
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js +4 -2
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +4 -2
- package/build/components/with-select/index.js.map +1 -1
- package/build/controls.js +7 -5
- package/build/controls.js.map +1 -1
- package/build/create-selector.js +2 -0
- package/build/create-selector.js.map +1 -1
- package/build/default-registry.js +2 -0
- package/build/default-registry.js.map +1 -1
- package/build/dispatch.js +2 -0
- package/build/dispatch.js.map +1 -1
- package/build/factory.js +2 -0
- package/build/factory.js.map +1 -1
- package/build/index.js +10 -8
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +3 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/plugins/index.js +2 -0
- package/build/plugins/index.js.map +1 -1
- package/build/plugins/persistence/index.js +5 -3
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/plugins/persistence/storage/default.js +3 -1
- package/build/plugins/persistence/storage/default.js.map +1 -1
- package/build/plugins/persistence/storage/object.js +4 -2
- package/build/plugins/persistence/storage/object.js.map +1 -1
- package/build/promise-middleware.js +3 -1
- package/build/promise-middleware.js.map +1 -1
- package/build/redux-store/combine-reducers.js +2 -0
- package/build/redux-store/combine-reducers.js.map +1 -1
- package/build/redux-store/index.js +5 -3
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +2 -0
- package/build/redux-store/metadata/actions.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +4 -2
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +3 -1
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +3 -1
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/redux-store/thunk-middleware.js +2 -0
- package/build/redux-store/thunk-middleware.js.map +1 -1
- package/build/registry.js +2 -0
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +3 -1
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/select.js +2 -0
- package/build/select.js.map +1 -1
- package/build/store/index.js +3 -1
- package/build/store/index.js.map +1 -1
- package/build/types.js +2 -0
- package/build/types.js.map +1 -1
- package/build/utils/emitter.js +2 -0
- package/build/utils/emitter.js.map +1 -1
- package/build-module/components/async-mode-provider/context.js +4 -3
- package/build-module/components/async-mode-provider/context.js.map +1 -1
- package/build-module/components/async-mode-provider/index.js +1 -0
- package/build-module/components/async-mode-provider/index.js.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +1 -0
- package/build-module/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build-module/components/registry-provider/context.js +4 -3
- package/build-module/components/registry-provider/context.js.map +1 -1
- package/build-module/components/registry-provider/index.js +1 -0
- package/build-module/components/registry-provider/index.js.map +1 -1
- package/build-module/components/registry-provider/use-registry.js +1 -0
- package/build-module/components/registry-provider/use-registry.js.map +1 -1
- package/build-module/components/use-dispatch/index.js +1 -0
- package/build-module/components/use-dispatch/index.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +2 -1
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +2 -1
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +3 -2
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js +3 -2
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +3 -2
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/controls.js +6 -5
- package/build-module/controls.js.map +1 -1
- package/build-module/create-selector.js +1 -0
- package/build-module/create-selector.js.map +1 -1
- package/build-module/default-registry.js +1 -0
- package/build-module/default-registry.js.map +1 -1
- package/build-module/dispatch.js +1 -0
- package/build-module/dispatch.js.map +1 -1
- package/build-module/factory.js +1 -0
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +9 -8
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js +2 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/plugins/index.js +1 -0
- package/build-module/plugins/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js +4 -3
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/plugins/persistence/storage/default.js +2 -1
- package/build-module/plugins/persistence/storage/default.js.map +1 -1
- package/build-module/plugins/persistence/storage/object.js +3 -2
- package/build-module/plugins/persistence/storage/object.js.map +1 -1
- package/build-module/promise-middleware.js +2 -1
- package/build-module/promise-middleware.js.map +1 -1
- package/build-module/redux-store/combine-reducers.js +1 -0
- package/build-module/redux-store/combine-reducers.js.map +1 -1
- package/build-module/redux-store/index.js +4 -3
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/actions.js +1 -0
- package/build-module/redux-store/metadata/actions.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +3 -2
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +2 -1
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +2 -1
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/redux-store/thunk-middleware.js +1 -0
- package/build-module/redux-store/thunk-middleware.js.map +1 -1
- package/build-module/registry.js +1 -0
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +2 -1
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/select.js +1 -0
- package/build-module/select.js.map +1 -1
- package/build-module/store/index.js +2 -1
- package/build-module/store/index.js.map +1 -1
- package/build-module/utils/emitter.js +1 -0
- package/build-module/utils/emitter.js.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/components/async-mode-provider/context.js
|
|
19
21
|
var context_exports = {};
|
|
20
22
|
__export(context_exports, {
|
|
21
23
|
AsyncModeConsumer: () => AsyncModeConsumer,
|
|
@@ -24,10 +26,10 @@ __export(context_exports, {
|
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(context_exports);
|
|
26
28
|
var import_element = require("@wordpress/element");
|
|
27
|
-
|
|
29
|
+
var Context = (0, import_element.createContext)(false);
|
|
28
30
|
Context.displayName = "AsyncModeContext";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
var { Consumer, Provider } = Context;
|
|
32
|
+
var AsyncModeConsumer = Consumer;
|
|
31
33
|
var context_default = Provider;
|
|
32
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
35
|
0 && (module.exports = {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/async-mode-provider/context.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nexport const Context = createContext( false );\nContext.displayName = 'AsyncModeContext';\n\nconst { Consumer, Provider } = Context;\n\nexport const AsyncModeConsumer = Consumer;\n\n/**\n * Context Provider Component used to switch the data module component rerendering\n * between Sync and Async modes.\n *\n * @example\n *\n * ```js\n * import { useSelect, AsyncModeProvider } from '@wordpress/data';\n * import { store as blockEditorStore } from '@wordpress/block-editor';\n *\n * function BlockCount() {\n * const count = useSelect( ( select ) => {\n * return select( blockEditorStore ).getBlockCount()\n * }, [] );\n *\n * return count;\n * }\n *\n * function App() {\n * return (\n * <AsyncModeProvider value={ true }>\n * <BlockCount />\n * </AsyncModeProvider>\n * );\n * }\n * ```\n *\n * In this example, the BlockCount component is rerendered asynchronously.\n * It means if a more critical task is being performed (like typing in an input),\n * the rerendering is delayed until the browser becomes IDLE.\n * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.\n *\n * @param {boolean} props.value Enable Async Mode.\n * @return {Component} The component to be rendered.\n */\nexport default Provider;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAEvB,IAAM,cAAU,8BAAe,KAAM;AAC5C,QAAQ,cAAc;AAEtB,IAAM,EAAE,UAAU,SAAS,IAAI;AAExB,IAAM,oBAAoB;AAqCjC,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/async-mode-provider/index.js
|
|
29
31
|
var async_mode_provider_exports = {};
|
|
30
32
|
__export(async_mode_provider_exports, {
|
|
31
33
|
AsyncModeConsumer: () => import_context.AsyncModeConsumer,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/async-mode-provider/index.js"],
|
|
4
4
|
"sourcesContent": ["export { default as useAsyncMode } from './use-async-mode';\nexport { default as AsyncModeProvider, AsyncModeConsumer } from './context';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAwC;AACxC,qBAAgE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/components/async-mode-provider/use-async-mode.js
|
|
19
21
|
var use_async_mode_exports = {};
|
|
20
22
|
__export(use_async_mode_exports, {
|
|
21
23
|
default: () => useAsyncMode
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/async-mode-provider/use-async-mode.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\nexport default function useAsyncMode() {\n\treturn useContext( Context );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2B;AAK3B,qBAAwB;AAET,SAAR,eAAgC;AACtC,aAAO,2BAAY,sBAAQ;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/registry-provider/context.js
|
|
29
31
|
var context_exports = {};
|
|
30
32
|
__export(context_exports, {
|
|
31
33
|
Context: () => Context,
|
|
@@ -35,10 +37,10 @@ __export(context_exports, {
|
|
|
35
37
|
module.exports = __toCommonJS(context_exports);
|
|
36
38
|
var import_element = require("@wordpress/element");
|
|
37
39
|
var import_default_registry = __toESM(require("../../default-registry"));
|
|
38
|
-
|
|
40
|
+
var Context = (0, import_element.createContext)(import_default_registry.default);
|
|
39
41
|
Context.displayName = "RegistryProviderContext";
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
var { Consumer, Provider } = Context;
|
|
43
|
+
var RegistryConsumer = Consumer;
|
|
42
44
|
var context_default = Provider;
|
|
43
45
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
46
|
0 && (module.exports = {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/context.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from '../../default-registry';\n\nexport const Context = createContext( defaultRegistry );\nContext.displayName = 'RegistryProviderContext';\n\nconst { Consumer, Provider } = Context;\n\n/**\n * A custom react Context consumer exposing the provided `registry` to\n * children components. Used along with the RegistryProvider.\n *\n * You can read more about the react context api here:\n * https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * RegistryConsumer,\n * createRegistry\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const App = ( { props } ) => {\n * return <RegistryProvider value={ registry }>\n * <div>Hello There</div>\n * <RegistryConsumer>\n * { ( registry ) => (\n * <ComponentUsingRegistry\n * \t\t{ ...props }\n * \t registry={ registry }\n * ) }\n * </RegistryConsumer>\n * </RegistryProvider>\n * }\n * ```\n */\nexport const RegistryConsumer = Consumer;\n\n/**\n * A custom Context provider for exposing the provided `registry` to children\n * components via a consumer.\n *\n * See <a name=\"#RegistryConsumer\">RegistryConsumer</a> documentation for\n * example.\n */\nexport default Provider;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA8B;AAK9B,8BAA4B;AAErB,IAAM,cAAU,8BAAe,wBAAAA,OAAgB;AACtD,QAAQ,cAAc;AAEtB,IAAM,EAAE,UAAU,SAAS,IAAI;AAiCxB,IAAM,mBAAmB;AAShC,IAAO,kBAAQ;",
|
|
6
6
|
"names": ["defaultRegistry"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/registry-provider/index.js
|
|
29
31
|
var registry_provider_exports = {};
|
|
30
32
|
__export(registry_provider_exports, {
|
|
31
33
|
RegistryConsumer: () => import_context.RegistryConsumer,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/index.js"],
|
|
4
4
|
"sourcesContent": ["export { default as RegistryProvider, RegistryConsumer } from './context';\nexport { default as useRegistry } from './use-registry';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8D;AAC9D,0BAAuC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/components/registry-provider/use-registry.js
|
|
19
21
|
var use_registry_exports = {};
|
|
20
22
|
__export(use_registry_exports, {
|
|
21
23
|
default: () => useRegistry
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/use-registry.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\n/**\n * A custom react hook exposing the registry context for use.\n *\n * This exposes the `registry` value provided via the\n * <a href=\"#RegistryProvider\">Registry Provider</a> to a component implementing\n * this hook.\n *\n * It acts similarly to the `useContext` react hook.\n *\n * Note: Generally speaking, `useRegistry` is a low level hook that in most cases\n * won't be needed for implementation. Most interactions with the `@wordpress/data`\n * API can be performed via the `useSelect` hook, or the `withSelect` and\n * `withDispatch` higher order components.\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * createRegistry,\n * useRegistry,\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const SomeChildUsingRegistry = ( props ) => {\n * const registry = useRegistry();\n * // ...logic implementing the registry in other react hooks.\n * };\n *\n *\n * const ParentProvidingRegistry = ( props ) => {\n * return <RegistryProvider value={ registry }>\n * <SomeChildUsingRegistry { ...props } />\n * </RegistryProvider>\n * };\n * ```\n *\n * @return {Function} A custom react hook exposing the registry context value.\n */\nexport default function useRegistry() {\n\treturn useContext( Context );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2B;AAK3B,qBAAwB;AAyCT,SAAR,cAA+B;AACrC,aAAO,2BAAY,sBAAQ;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/use-dispatch/index.js
|
|
29
31
|
var use_dispatch_exports = {};
|
|
30
32
|
__export(use_dispatch_exports, {
|
|
31
33
|
useDispatch: () => import_use_dispatch.default,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-dispatch/index.js"],
|
|
4
4
|
"sourcesContent": ["export { default as useDispatch } from './use-dispatch';\nexport { default as useDispatchWithMap } from './use-dispatch-with-map';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAuC;AACvC,mCAA8C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/use-dispatch/use-dispatch-with-map.js
|
|
29
31
|
var use_dispatch_with_map_exports = {};
|
|
30
32
|
__export(use_dispatch_with_map_exports, {
|
|
31
33
|
default: () => use_dispatch_with_map_default
|
|
@@ -34,7 +36,7 @@ module.exports = __toCommonJS(use_dispatch_with_map_exports);
|
|
|
34
36
|
var import_element = require("@wordpress/element");
|
|
35
37
|
var import_compose = require("@wordpress/compose");
|
|
36
38
|
var import_use_registry = __toESM(require("../registry-provider/use-registry"));
|
|
37
|
-
|
|
39
|
+
var useDispatchWithMap = (dispatchMap, deps) => {
|
|
38
40
|
const registry = (0, import_use_registry.default)();
|
|
39
41
|
const currentDispatchMapRef = (0, import_element.useRef)(dispatchMap);
|
|
40
42
|
(0, import_compose.useIsomorphicLayoutEffect)(() => {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-dispatch/use-dispatch-with-map.js"],
|
|
4
4
|
"sourcesContent": ["/**\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 currentDispatchMapRef = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMapRef.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMapRef.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( currentDispatchProps ).map(\n\t\t\t\t( [ propName, dispatcher ] ) => {\n\t\t\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn [\n\t\t\t\t\t\tpropName,\n\t\t\t\t\t\t( ...args ) =>\n\t\t\t\t\t\t\tcurrentDispatchMapRef\n\t\t\t\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t\t\t\t[ propName ]( ...args ),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAChC,qBAA0C;AAK1C,0BAAwB;AAgBxB,IAAM,qBAAqB,CAAE,aAAa,SAAU;AACnD,QAAM,eAAW,oBAAAA,SAAY;AAC7B,QAAM,4BAAwB,uBAAQ,WAAY;AAElD,gDAA2B,MAAM;AAChC,0BAAsB,UAAU;AAAA,EACjC,CAAE;AAEF,aAAO,wBAAS,MAAM;AACrB,UAAM,uBAAuB,sBAAsB;AAAA,MAClD,SAAS;AAAA,MACT;AAAA,IACD;AACA,WAAO,OAAO;AAAA,MACb,OAAO,QAAS,oBAAqB,EAAE;AAAA,QACtC,CAAE,CAAE,UAAU,UAAW,MAAO;AAC/B,cAAK,OAAO,eAAe,YAAa;AAEvC,oBAAQ;AAAA,cACP,YAAa,QAAS;AAAA,YACvB;AAAA,UACD;AACA,iBAAO;AAAA,YACN;AAAA,YACA,IAAK,SACJ,sBACE,QAAS,SAAS,UAAU,QAAS,EACpC,QAAS,EAAG,GAAG,IAAK;AAAA,UACzB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,UAAU,GAAG,IAAK,CAAE;AAC1B;AAEA,IAAO,gCAAQ;",
|
|
6
6
|
"names": ["useRegistry"]
|
|
7
7
|
}
|
|
@@ -26,13 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/use-dispatch/use-dispatch.js
|
|
29
31
|
var use_dispatch_exports = {};
|
|
30
32
|
__export(use_dispatch_exports, {
|
|
31
33
|
default: () => use_dispatch_default
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(use_dispatch_exports);
|
|
34
36
|
var import_use_registry = __toESM(require("../registry-provider/use-registry"));
|
|
35
|
-
|
|
37
|
+
var useDispatch = (storeNameOrDescriptor) => {
|
|
36
38
|
const { dispatch } = (0, import_use_registry.default)();
|
|
37
39
|
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
|
|
38
40
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-dispatch/use-dispatch.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor\n * @template {import('../../types').AnyConfig} StoreConfig\n */\n/**\n * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn\n * @template StoreNameOrDescriptor\n */\n\n/**\n * A custom react hook returning the current registry dispatch actions creators.\n *\n * Note: The component using this hook must be within the context of a\n * RegistryProvider.\n *\n * @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor\n * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the\n * store or its descriptor from which to\n * retrieve action creators. If not\n * provided, the registry.dispatch\n * function is returned instead.\n *\n * @example\n * This illustrates a pattern where you may need to retrieve dynamic data from\n * the server via the `useSelect` hook to use in combination with the dispatch\n * action.\n *\n * ```jsx\n * import { useCallback } from 'react';\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>\n * }\n *\n * const SaleButton = ( { children } ) => {\n * const { stockNumber } = useSelect(\n * ( select ) => select( myCustomStore ).getStockNumber(),\n * []\n * );\n * const { startSale } = useDispatch( myCustomStore );\n * const onClick = useCallback( () => {\n * const discountPercent = stockNumber > 50 ? 10: 20;\n * startSale( discountPercent );\n * }, [ stockNumber ] );\n * return <Button onClick={ onClick }>{ children }</Button>\n * }\n *\n * // Rendered somewhere in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n * @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.\n */\nconst useDispatch = ( storeNameOrDescriptor ) => {\n\tconst { dispatch } = useRegistry();\n\treturn storeNameOrDescriptor === void 0\n\t\t? dispatch\n\t\t: dispatch( storeNameOrDescriptor );\n};\n\nexport default useDispatch;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAwB;AAyDxB,IAAM,cAAc,CAAE,0BAA2B;AAChD,QAAM,EAAE,SAAS,QAAI,oBAAAA,SAAY;AACjC,SAAO,0BAA0B,SAC9B,WACA,SAAU,qBAAsB;AACpC;AAEA,IAAO,uBAAQ;",
|
|
6
6
|
"names": ["useRegistry"]
|
|
7
7
|
}
|
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/use-select/index.js
|
|
29
31
|
var use_select_exports = {};
|
|
30
32
|
__export(use_select_exports, {
|
|
31
33
|
default: () => useSelect,
|
|
@@ -37,7 +39,7 @@ var import_element = require("@wordpress/element");
|
|
|
37
39
|
var import_is_shallow_equal = __toESM(require("@wordpress/is-shallow-equal"));
|
|
38
40
|
var import_use_registry = __toESM(require("../registry-provider/use-registry"));
|
|
39
41
|
var import_use_async_mode = __toESM(require("../async-mode-provider/use-async-mode"));
|
|
40
|
-
|
|
42
|
+
var renderQueue = (0, import_priority_queue.createQueue)();
|
|
41
43
|
function warnOnUnstableReference(a, b) {
|
|
42
44
|
if (!a || !b) {
|
|
43
45
|
return;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-select/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference( a, b ) {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\tlet didWarnUnstableReference;\n\tconst storeStatesOnMount = new Map();\n\n\tfunction getStoreState( name ) {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? _useStaticSelect( mapSelect )\n\t\t: _useMappingSelect( false, mapSelect, deps );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @template {MapSelect} T\n * @param {T} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws {Promise} A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return {ReturnType<T>} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn _useMappingSelect( true, mapSelect, deps );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAA4B;AAC5B,qBAMO;AACP,8BAA2B;AAK3B,0BAAwB;AACxB,4BAAyB;AAEzB,IAAM,kBAAc,mCAAY;AAEhC,SAAS,wBAAyB,GAAG,GAAI;AACxC,MAAK,CAAE,KAAK,CAAE,GAAI;AACjB;AAAA,EACD;AAEA,QAAM,OACL,OAAO,MAAM,YAAY,OAAO,MAAM,WACnC,OAAO,KAAM,CAAE,EAAE,OAAQ,CAAE,MAAO,EAAG,CAAE,MAAM,EAAG,CAAE,CAAE,IACpD,CAAC;AAGL,UAAQ;AAAA,IACP;AAAA,IAGA,KAAK,KAAM,IAAK;AAAA,EACjB;AACD;AAkBA,SAAS,MAAO,UAAU,UAAW;AACpC,QAAM,SAAS,WAAW,SAAS,gBAAgB,SAAS;AAC5D,QAAM,eAAe,CAAC;AACtB,MAAI;AACJ,MAAI;AACJ,MAAI,qBAAqB;AACzB,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,QAAM,qBAAqB,oBAAI,IAAI;AAEnC,WAAS,cAAe,MAAO;AAI9B,WAAO,SAAS,OAAQ,IAAK,GAAG,OAAO,WAAW,KAAK,CAAC;AAAA,EACzD;AAEA,QAAM,mBAAmB,CAAE,WAAY;AAGtC,UAAM,eAAe,CAAE,GAAG,MAAO;AAKjC,UAAM,sBAAsB,oBAAI,IAAI;AAEpC,aAAS,UAAW,UAAW;AAQ9B,UAAK,oBAAqB;AACzB,mBAAY,QAAQ,cAAe;AAClC,cACC,mBAAmB,IAAK,IAAK,MAAM,cAAe,IAAK,GACtD;AACD,iCAAqB;AAAA,UACtB;AAAA,QACD;AAAA,MACD;AAEA,yBAAmB,MAAM;AAEzB,YAAM,gBAAgB,MAAM;AAE3B,6BAAqB;AACrB,iBAAS;AAAA,MACV;AAEA,YAAM,WAAW,MAAM;AACtB,YAAK,aAAc;AAClB,sBAAY,IAAK,cAAc,aAAc;AAAA,QAC9C,OAAO;AACN,wBAAc;AAAA,QACf;AAAA,MACD;AAEA,YAAM,SAAS,CAAC;AAChB,eAAS,eAAgB,WAAY;AACpC,eAAO,KAAM,SAAS,UAAW,UAAU,SAAU,CAAE;AAAA,MACxD;AAEA,iBAAY,aAAa,cAAe;AACvC,uBAAgB,SAAU;AAAA,MAC3B;AAEA,0BAAoB,IAAK,cAAe;AAExC,aAAO,MAAM;AACZ,4BAAoB,OAAQ,cAAe;AAE3C,mBAAY,SAAS,OAAO,OAAO,GAAI;AAEtC,kBAAQ;AAAA,QACT;AAEA,oBAAY,OAAQ,YAAa;AAAA,MAClC;AAAA,IACD;AAGA,aAAS,aAAc,WAAY;AAClC,iBAAY,YAAY,WAAY;AACnC,YAAK,aAAa,SAAU,QAAS,GAAI;AACxC;AAAA,QACD;AAGA,qBAAa,KAAM,QAAS;AAG5B,mBAAY,gBAAgB,qBAAsB;AACjD,uBAAc,QAAS;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEA,WAAO,EAAE,WAAW,aAAa;AAAA,EAClC;AAEA,SAAO,CAAE,WAAW,YAAa;AAChC,aAAS,cAAc;AAItB,UAAK,sBAAsB,cAAc,eAAgB;AACxD,eAAO;AAAA,MACR;AAEA,YAAM,kBAAkB,EAAE,SAAS,KAAK;AACxC,YAAM,YAAY,SAAS;AAAA,QAC1B,MAAM,UAAW,QAAQ,QAAS;AAAA,QAClC;AAAA,MACD;AAEA,UAAK,WAAW,cAAe;AAC9B,YAAK,CAAE,0BAA2B;AACjC,gBAAM,kBAAkB,UAAW,QAAQ,QAAS;AACpD,cAAK,KAAE,wBAAAA,SAAgB,WAAW,eAAgB,GAAI;AACrD,oCAAyB,WAAW,eAAgB;AACpD,uCAA2B;AAAA,UAC5B;AAAA,QACD;AAAA,MACD;AAEA,UAAK,CAAE,YAAa;AACnB,mBAAY,QAAQ,gBAAgB,SAAU;AAC7C,6BAAmB,IAAK,MAAM,cAAe,IAAK,CAAE;AAAA,QACrD;AACA,qBAAa,iBAAkB,gBAAgB,OAAQ;AAAA,MACxD,OAAO;AACN,mBAAW,aAAc,gBAAgB,OAAQ;AAAA,MAClD;AAIA,UAAK,KAAE,wBAAAA,SAAgB,eAAe,SAAU,GAAI;AACnD,wBAAgB;AAAA,MACjB;AACA,sBAAgB;AAChB,2BAAqB;AAAA,IACtB;AAEA,aAAS,WAAW;AAEnB,kBAAY;AACZ,aAAO;AAAA,IACR;AAKA,QAAK,eAAe,CAAE,SAAU;AAC/B,2BAAqB;AACrB,kBAAY,OAAQ,YAAa;AAAA,IAClC;AAEA,gBAAY;AAEZ,kBAAc;AAGd,WAAO,EAAE,WAAW,WAAW,WAAW,SAAS;AAAA,EACpD;AACD;AAEA,SAAS,iBAAkB,WAAY;AACtC,aAAO,oBAAAC,SAAY,EAAE,OAAQ,SAAU;AACxC;AAEA,SAAS,kBAAmB,UAAU,WAAW,MAAO;AACvD,QAAM,eAAW,oBAAAA,SAAY;AAC7B,QAAM,cAAU,sBAAAC,SAAa;AAC7B,QAAM,YAAQ;AAAA,IACb,MAAM,MAAO,UAAU,QAAS;AAAA,IAChC,CAAE,UAAU,QAAS;AAAA,EACtB;AAIA,QAAM,eAAW,4BAAa,WAAW,IAAK;AAC9C,QAAM,EAAE,WAAW,SAAS,IAAI,MAAO,UAAU,OAAQ;AACzD,QAAM,aAAS,qCAAsB,WAAW,UAAU,QAAS;AACnE,oCAAe,MAAO;AACtB,SAAO;AACR;AAkEe,SAAR,UAA4B,WAAW,MAAO;AAGpD,QAAM,mBAAmB,OAAO,cAAc;AAC9C,QAAM,0BAAsB,uBAAQ,gBAAiB;AAErD,MAAK,qBAAqB,oBAAoB,SAAU;AACvD,UAAM,WAAW,oBAAoB,UAAU,WAAW;AAC1D,UAAM,WAAW,mBAAmB,WAAW;AAC/C,UAAM,IAAI;AAAA,MACT,4BAA6B,QAAS,OAAQ,QAAS;AAAA,IACxD;AAAA,EACD;AAIA,SAAO,mBACJ,iBAAkB,SAAU,IAC5B,kBAAmB,OAAO,WAAW,IAAK;AAC9C;AAqBO,SAAS,kBAAmB,WAAW,MAAO;AACpD,SAAO,kBAAmB,MAAM,WAAW,IAAK;AACjD;",
|
|
6
6
|
"names": ["isShallowEqual", "useRegistry", "useAsyncMode"]
|
|
7
7
|
}
|
|
@@ -16,15 +16,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/components/with-dispatch/index.js
|
|
19
21
|
var with_dispatch_exports = {};
|
|
20
22
|
__export(with_dispatch_exports, {
|
|
21
23
|
default: () => with_dispatch_default
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(with_dispatch_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
26
|
var import_compose = require("@wordpress/compose");
|
|
26
27
|
var import_use_dispatch = require("../use-dispatch");
|
|
27
|
-
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
var withDispatch = (mapDispatchToProps) => (0, import_compose.createHigherOrderComponent)(
|
|
28
30
|
(WrappedComponent) => (ownProps) => {
|
|
29
31
|
const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
|
|
30
32
|
const dispatchProps = (0, import_use_dispatch.useDispatchWithMap)(mapDispatch, []);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/with-dispatch/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( myCustomStore );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( myCustomStore );\n * const { startSale } = dispatch( myCustomStore );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {ComponentType} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2C;AAK3C,0BAAmC;AA2FzB;AANV,IAAM,eAAe,CAAE,2BACtB;AAAA,EACC,CAAE,qBAAsB,CAAE,aAAc;AACvC,UAAM,cAAc,CAAE,UAAU,aAC/B,mBAAoB,UAAU,UAAU,QAAS;AAClD,UAAM,oBAAgB,wCAAoB,aAAa,CAAC,CAAE;AAC1D,WAAO,4CAAC,oBAAmB,GAAG,UAAa,GAAG,eAAgB;AAAA,EAC/D;AAAA,EACA;AACD;AAED,IAAO,wBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,15 +16,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/components/with-registry/index.js
|
|
19
21
|
var with_registry_exports = {};
|
|
20
22
|
__export(with_registry_exports, {
|
|
21
23
|
default: () => with_registry_default
|
|
22
24
|
});
|
|
23
25
|
module.exports = __toCommonJS(with_registry_exports);
|
|
24
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
26
|
var import_compose = require("@wordpress/compose");
|
|
26
27
|
var import_registry_provider = require("../registry-provider");
|
|
27
|
-
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
var withRegistry = (0, import_compose.createHigherOrderComponent)(
|
|
28
30
|
(OriginalComponent) => (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_registry_provider.RegistryConsumer, { children: (registry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OriginalComponent, { ...props, registry }) }),
|
|
29
31
|
"withRegistry"
|
|
30
32
|
);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/with-registry/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {Component} OriginalComponent Original component.\n *\n * @return {Component} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) => (\n\t\t<RegistryConsumer>\n\t\t\t{ ( registry ) => (\n\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t) }\n\t\t</RegistryConsumer>\n\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2C;AAK3C,+BAAiC;AAc7B;AAJJ,IAAM,mBAAe;AAAA,EACpB,CAAE,sBAAuB,CAAE,UAC1B,4CAAC,6CACE,WAAE,aACH,4CAAC,qBAAoB,GAAG,OAAQ,UAAsB,GAExD;AAAA,EAED;AACD;AAEA,IAAO,wBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,15 +26,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/components/with-select/index.js
|
|
29
31
|
var with_select_exports = {};
|
|
30
32
|
__export(with_select_exports, {
|
|
31
33
|
default: () => with_select_default
|
|
32
34
|
});
|
|
33
35
|
module.exports = __toCommonJS(with_select_exports);
|
|
34
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
36
|
var import_compose = require("@wordpress/compose");
|
|
36
37
|
var import_use_select = __toESM(require("../use-select"));
|
|
37
|
-
|
|
38
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
|
+
var withSelect = (mapSelectToProps) => (0, import_compose.createHigherOrderComponent)(
|
|
38
40
|
(WrappedComponent) => (0, import_compose.pure)((ownProps) => {
|
|
39
41
|
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
40
42
|
const mergeProps = (0, import_use_select.default)(mapSelect);
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/with-select/index.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {ComponentType} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAiD;AAKjD,wBAAsB;AAmDX;AAPX,IAAM,aAAa,CAAE,yBACpB;AAAA,EACC,CAAE,yBACD,qBAAM,CAAE,aAAc;AACrB,UAAM,YAAY,CAAE,QAAQ,aAC3B,iBAAkB,QAAQ,UAAU,QAAS;AAC9C,UAAM,iBAAa,kBAAAA,SAAW,SAAU;AACxC,WAAO,4CAAC,oBAAmB,GAAG,UAAa,GAAG,YAAa;AAAA,EAC5D,CAAE;AAAA,EACH;AACD;AAED,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["useSelect"]
|
|
7
7
|
}
|
package/build/controls.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/controls.js
|
|
19
21
|
var controls_exports = {};
|
|
20
22
|
__export(controls_exports, {
|
|
21
23
|
builtinControls: () => builtinControls,
|
|
@@ -23,9 +25,9 @@ __export(controls_exports, {
|
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(controls_exports);
|
|
25
27
|
var import_factory = require("./factory");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
var SELECT = "@@data/SELECT";
|
|
29
|
+
var RESOLVE_SELECT = "@@data/RESOLVE_SELECT";
|
|
30
|
+
var DISPATCH = "@@data/DISPATCH";
|
|
29
31
|
function isObject(object) {
|
|
30
32
|
return object !== null && typeof object === "object";
|
|
31
33
|
}
|
|
@@ -53,8 +55,8 @@ function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
|
53
55
|
args
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
var controls = { select, resolveSelect, dispatch };
|
|
59
|
+
var builtinControls = {
|
|
58
60
|
[SELECT]: (0, import_factory.createRegistryControl)(
|
|
59
61
|
(registry) => ({ storeKey, selectorName, args }) => registry.select(storeKey)[selectorName](...args)
|
|
60
62
|
),
|
package/build/controls.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/controls.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\nfunction isObject( object ) {\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 {string|StoreDescriptor} storeNameOrDescriptor 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( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( 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 {string|StoreDescriptor} storeNameOrDescriptor 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( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( 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 {string|StoreDescriptor} storeNameOrDescriptor 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/editor', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( 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\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\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 } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.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 } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAsC;AAItC,IAAM,SAAS;AACf,IAAM,iBAAiB;AACvB,IAAM,WAAW;AAEjB,SAAS,SAAU,QAAS;AAC3B,SAAO,WAAW,QAAQ,OAAO,WAAW;AAC7C;AAyBA,SAAS,OAAQ,uBAAuB,iBAAiB,MAAO;AAC/D,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,SAAU,qBAAsB,IACvC,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AA0BA,SAAS,cAAe,uBAAuB,iBAAiB,MAAO;AACtE,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,SAAU,qBAAsB,IACvC,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AAsBA,SAAS,SAAU,uBAAuB,eAAe,MAAO;AAC/D,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,SAAU,qBAAsB,IACvC,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AAEO,IAAM,WAAW,EAAE,QAAQ,eAAe,SAAS;AAEnD,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,MAAO;AACvC,YAAM,SAAS,SAAS,OAAQ,QAAS,EAAG,YAAa,EACvD,cACC,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
|
}
|
package/build/create-selector.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/create-selector.ts
|
|
29
31
|
var create_selector_exports = {};
|
|
30
32
|
__export(create_selector_exports, {
|
|
31
33
|
createSelector: () => import_rememo.default
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/create-selector.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * Creates a memoized selector that caches the computed values according to the array of \"dependants\"\n * and the selector parameters, and recomputes the values only when any of them changes.\n *\n * @see The documentation for the `rememo` package from which the `createSelector` function is reexported.\n */\nexport { default as createSelector } from 'rememo';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oBAA0C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/default-registry.js
|
|
19
21
|
var default_registry_exports = {};
|
|
20
22
|
__export(default_registry_exports, {
|
|
21
23
|
default: () => default_registry_default
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/default-registry.js"],
|
|
4
4
|
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistry } from './registry';\n\nexport default createRegistry();\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAA+B;AAE/B,IAAO,+BAAQ,gCAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build/dispatch.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// packages/data/src/dispatch.ts
|
|
29
31
|
var dispatch_exports = {};
|
|
30
32
|
__export(dispatch_exports, {
|
|
31
33
|
dispatch: () => dispatch
|
package/build/dispatch.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dispatch.ts"],
|
|
4
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( storeNameOrDescriptor );\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,8BAA4B;AAqBrB,SAAS,SAGf,uBAC0C;AAC1C,SAAO,wBAAAA,QAAgB,SAAU,qBAAsB;AACxD;",
|
|
6
6
|
"names": ["defaultRegistry"]
|
|
7
7
|
}
|
package/build/factory.js
CHANGED
|
@@ -16,6 +16,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/data/src/factory.ts
|
|
19
21
|
var factory_exports = {};
|
|
20
22
|
__export(factory_exports, {
|
|
21
23
|
createRegistryControl: () => createRegistryControl,
|
package/build/factory.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/factory.ts"],
|
|
4
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< T extends ( ...args: any ) => any >(\n\tregistryControl: T & { isRegistryControl?: boolean }\n) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmDO,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,sBACf,iBACC;AACD,kBAAgB,oBAAoB;AAEpC,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|