@wordpress/data 10.47.0 → 10.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +7 -7
- package/build/components/registry-provider/context.cjs.map +1 -1
- package/build/components/registry-provider/use-registry.cjs.map +1 -1
- package/build/components/with-select/index.cjs +15 -5
- package/build/components/with-select/index.cjs.map +2 -2
- package/build-module/components/registry-provider/context.mjs.map +1 -1
- package/build-module/components/registry-provider/use-registry.mjs.map +1 -1
- package/build-module/components/with-select/index.mjs +16 -6
- package/build-module/components/with-select/index.mjs.map +2 -2
- package/build-types/components/registry-provider/context.d.ts +3 -3
- package/build-types/components/registry-provider/use-registry.d.ts +5 -5
- package/build-types/components/with-select/index.d.ts +1 -1
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/package.json +16 -13
- package/src/components/registry-provider/context.ts +3 -3
- package/src/components/registry-provider/use-registry.ts +5 -5
- package/src/components/use-select/test/suspense.js +7 -25
- package/src/components/with-select/index.tsx +22 -9
- package/src/components/with-select/test/index.js +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 10.48.1 (2026-06-16)
|
|
6
|
+
|
|
7
|
+
## 10.48.0 (2026-06-10)
|
|
8
|
+
|
|
9
|
+
### Code Quality
|
|
10
|
+
|
|
11
|
+
- Add missing `@types/react` dependency. [#78882](https://github.com/WordPress/gutenberg/pull/78882).
|
|
12
|
+
|
|
5
13
|
## 10.47.0 (2026-05-27)
|
|
6
14
|
|
|
7
15
|
## 10.46.0 (2026-05-14)
|
package/README.md
CHANGED
|
@@ -613,9 +613,9 @@ _Returns_
|
|
|
613
613
|
|
|
614
614
|
### RegistryConsumer
|
|
615
615
|
|
|
616
|
-
A custom
|
|
616
|
+
A custom React context consumer exposing the provided `registry` to children components. Used along with the RegistryProvider.
|
|
617
617
|
|
|
618
|
-
You can read more about the
|
|
618
|
+
You can read more about the React context API here: <https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context>
|
|
619
619
|
|
|
620
620
|
_Usage_
|
|
621
621
|
|
|
@@ -646,7 +646,7 @@ const App = ( { props } ) => {
|
|
|
646
646
|
|
|
647
647
|
A custom Context provider for exposing the provided `registry` to children components via a consumer.
|
|
648
648
|
|
|
649
|
-
See <a
|
|
649
|
+
See <a href="#registryconsumer">RegistryConsumer</a> documentation for example.
|
|
650
650
|
|
|
651
651
|
### resolveSelect
|
|
652
652
|
|
|
@@ -790,11 +790,11 @@ _Returns_
|
|
|
790
790
|
|
|
791
791
|
### useRegistry
|
|
792
792
|
|
|
793
|
-
A custom
|
|
793
|
+
A custom React hook exposing the registry context for use.
|
|
794
794
|
|
|
795
|
-
This exposes the `registry` value provided via the <a href="#
|
|
795
|
+
This exposes the `registry` value provided via the <a href="#registryprovider">Registry Provider</a> to a component implementing this hook.
|
|
796
796
|
|
|
797
|
-
It acts similarly to the `useContext`
|
|
797
|
+
It acts similarly to the `useContext` React hook.
|
|
798
798
|
|
|
799
799
|
Note: Generally speaking, `useRegistry` is a low level hook that in most cases won't be needed for implementation. Most interactions with the `@wordpress/data` API can be performed via the `useSelect` hook, or the `withSelect` and `withDispatch` higher order components.
|
|
800
800
|
|
|
@@ -821,7 +821,7 @@ const ParentProvidingRegistry = ( props ) => {
|
|
|
821
821
|
|
|
822
822
|
_Returns_
|
|
823
823
|
|
|
824
|
-
- `DataRegistry`: A custom
|
|
824
|
+
- `DataRegistry`: A custom React hook exposing the registry context value.
|
|
825
825
|
|
|
826
826
|
### useSelect
|
|
827
827
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/context.ts"],
|
|
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
|
|
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 href=\"#registryconsumer\">RegistryConsumer</a> documentation for\n * example.\n */\nexport default Provider;\n"],
|
|
5
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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/use-registry.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\nimport type { DataRegistry } from '../../types';\n\n/**\n * A custom
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\nimport type { DataRegistry } from '../../types';\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 A custom React hook exposing the registry context value.\n */\nexport default function useRegistry(): DataRegistry {\n\treturn useContext( Context );\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2B;AAK3B,qBAAwB;AA0CT,SAAR,cAA6C;AACnD,aAAO,2BAAY,sBAAQ;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -34,14 +34,24 @@ __export(with_select_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(with_select_exports);
|
|
36
36
|
var import_compose = require("@wordpress/compose");
|
|
37
|
+
var import_element = require("@wordpress/element");
|
|
37
38
|
var import_use_select = __toESM(require("../use-select/index.cjs"));
|
|
38
39
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
39
40
|
var withSelect = (mapSelectToProps) => (0, import_compose.createHigherOrderComponent)(
|
|
40
|
-
(WrappedComponent) => (0,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
(WrappedComponent) => (0, import_element.memo)(
|
|
42
|
+
(0, import_element.forwardRef)(function WithSelect(ownProps, ref) {
|
|
43
|
+
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
44
|
+
const mergeProps = (0, import_use_select.default)(mapSelect);
|
|
45
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
46
|
+
WrappedComponent,
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
...ownProps,
|
|
50
|
+
...mergeProps
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
})
|
|
54
|
+
),
|
|
45
55
|
"withSelect"
|
|
46
56
|
);
|
|
47
57
|
var with_select_default = withSelect;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/with-select/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { forwardRef, memo } from '@wordpress/element';\nimport type { ForwardedRef } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\nimport type { SelectFunction, DataRegistry } from '../../types';\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param 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 Enhanced component with merged state data props.\n */\nconst withSelect = (\n\tmapSelectToProps: (\n\t\tselect: SelectFunction,\n\t\townProps: Record< string, unknown >,\n\t\tregistry: DataRegistry\n\t) => Record< string, unknown >\n) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tmemo(\n\t\t\t\tforwardRef( function WithSelect(\n\t\t\t\t\townProps: Record< string, unknown >,\n\t\t\t\t\tref: ForwardedRef< unknown >\n\t\t\t\t) {\n\t\t\t\t\tconst mapSelect = (\n\t\t\t\t\t\tselect: SelectFunction,\n\t\t\t\t\t\tregistry: DataRegistry\n\t\t\t\t\t) => mapSelectToProps( select, ownProps, registry );\n\t\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t{ ...ownProps }\n\t\t\t\t\t\t\t{ ...mergeProps }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} )\n\t\t\t),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2C;AAC3C,qBAAiC;AAMjC,wBAAsB;AA+DhB;AApBN,IAAM,aAAa,CAClB,yBAMA;AAAA,EACC,CAAE,yBACD;AAAA,QACC,2BAAY,SAAS,WACpB,UACA,KACC;AACD,YAAM,YAAY,CACjB,QACA,aACI,iBAAkB,QAAQ,UAAU,QAAS;AAClD,YAAM,iBAAa,kBAAAA,SAAW,SAAU;AACxC,aACC;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACE,GAAG;AAAA,UACH,GAAG;AAAA;AAAA,MACN;AAAA,IAEF,CAAE;AAAA,EACH;AAAA,EACD;AACD;AAED,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["useSelect"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/context.ts"],
|
|
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
|
|
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 href=\"#registryconsumer\">RegistryConsumer</a> documentation for\n * example.\n */\nexport default Provider;\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,qBAAqB;AAK9B,OAAO,qBAAqB;AAErB,IAAM,UAAU,cAAe,eAAgB;AACtD,QAAQ,cAAc;AAEtB,IAAM,EAAE,UAAU,SAAS,IAAI;AAiCxB,IAAM,mBAAmB;AAShC,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/registry-provider/use-registry.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\nimport type { DataRegistry } from '../../types';\n\n/**\n * A custom
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\nimport type { DataRegistry } from '../../types';\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 A custom React hook exposing the registry context value.\n */\nexport default function useRegistry(): DataRegistry {\n\treturn useContext( Context );\n}\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,kBAAkB;AAK3B,SAAS,eAAe;AA0CT,SAAR,cAA6C;AACnD,SAAO,WAAY,OAAQ;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
// packages/data/src/components/with-select/index.tsx
|
|
2
|
-
import { createHigherOrderComponent
|
|
2
|
+
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
3
|
+
import { forwardRef, memo } from "@wordpress/element";
|
|
3
4
|
import useSelect from "../use-select/index.mjs";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
var withSelect = (mapSelectToProps) => createHigherOrderComponent(
|
|
6
|
-
(WrappedComponent) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
(WrappedComponent) => memo(
|
|
8
|
+
forwardRef(function WithSelect(ownProps, ref) {
|
|
9
|
+
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
10
|
+
const mergeProps = useSelect(mapSelect);
|
|
11
|
+
return /* @__PURE__ */ jsx(
|
|
12
|
+
WrappedComponent,
|
|
13
|
+
{
|
|
14
|
+
ref,
|
|
15
|
+
...ownProps,
|
|
16
|
+
...mergeProps
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
})
|
|
20
|
+
),
|
|
11
21
|
"withSelect"
|
|
12
22
|
);
|
|
13
23
|
var with_select_default = withSelect;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/with-select/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent,
|
|
5
|
-
"mappings": ";AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { forwardRef, memo } from '@wordpress/element';\nimport type { ForwardedRef } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\nimport type { SelectFunction, DataRegistry } from '../../types';\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param 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 Enhanced component with merged state data props.\n */\nconst withSelect = (\n\tmapSelectToProps: (\n\t\tselect: SelectFunction,\n\t\townProps: Record< string, unknown >,\n\t\tregistry: DataRegistry\n\t) => Record< string, unknown >\n) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tmemo(\n\t\t\t\tforwardRef( function WithSelect(\n\t\t\t\t\townProps: Record< string, unknown >,\n\t\t\t\t\tref: ForwardedRef< unknown >\n\t\t\t\t) {\n\t\t\t\t\tconst mapSelect = (\n\t\t\t\t\t\tselect: SelectFunction,\n\t\t\t\t\t\tregistry: DataRegistry\n\t\t\t\t\t) => mapSelectToProps( select, ownProps, registry );\n\t\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t\tref={ ref }\n\t\t\t\t\t\t\t{ ...ownProps }\n\t\t\t\t\t\t\t{ ...mergeProps }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} )\n\t\t\t),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,kCAAkC;AAC3C,SAAS,YAAY,YAAY;AAMjC,OAAO,eAAe;AA+DhB;AApBN,IAAM,aAAa,CAClB,qBAMA;AAAA,EACC,CAAE,qBACD;AAAA,IACC,WAAY,SAAS,WACpB,UACA,KACC;AACD,YAAM,YAAY,CACjB,QACA,aACI,iBAAkB,QAAQ,UAAU,QAAS;AAClD,YAAM,aAAa,UAAW,SAAU;AACxC,aACC;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACE,GAAG;AAAA,UACH,GAAG;AAAA;AAAA,MACN;AAAA,IAEF,CAAE;AAAA,EACH;AAAA,EACD;AACD;AAED,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const Context: import("react").Context<import("../..").DataRegistry>;
|
|
2
2
|
declare const Provider: import("react").Provider<import("../..").DataRegistry>;
|
|
3
3
|
/**
|
|
4
|
-
* A custom
|
|
4
|
+
* A custom React context consumer exposing the provided `registry` to
|
|
5
5
|
* children components. Used along with the RegistryProvider.
|
|
6
6
|
*
|
|
7
|
-
* You can read more about the
|
|
7
|
+
* You can read more about the React context API here:
|
|
8
8
|
* https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
@@ -36,7 +36,7 @@ export declare const RegistryConsumer: import("react").Consumer<import("../..").
|
|
|
36
36
|
* A custom Context provider for exposing the provided `registry` to children
|
|
37
37
|
* components via a consumer.
|
|
38
38
|
*
|
|
39
|
-
* See <a
|
|
39
|
+
* See <a href="#registryconsumer">RegistryConsumer</a> documentation for
|
|
40
40
|
* example.
|
|
41
41
|
*/
|
|
42
42
|
export default Provider;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { DataRegistry } from '../../types';
|
|
2
2
|
/**
|
|
3
|
-
* A custom
|
|
3
|
+
* A custom React hook exposing the registry context for use.
|
|
4
4
|
*
|
|
5
5
|
* This exposes the `registry` value provided via the
|
|
6
|
-
* <a href="#
|
|
6
|
+
* <a href="#registryprovider">Registry Provider</a> to a component implementing
|
|
7
7
|
* this hook.
|
|
8
8
|
*
|
|
9
|
-
* It acts similarly to the `useContext`
|
|
9
|
+
* It acts similarly to the `useContext` React hook.
|
|
10
10
|
*
|
|
11
11
|
* Note: Generally speaking, `useRegistry` is a low level hook that in most cases
|
|
12
12
|
* won't be needed for implementation. Most interactions with the `@wordpress/data`
|
|
13
|
-
* API can be performed via the `useSelect` hook,
|
|
13
|
+
* API can be performed via the `useSelect` hook, or the `withSelect` and
|
|
14
14
|
* `withDispatch` higher order components.
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
@@ -36,7 +36,7 @@ import type { DataRegistry } from '../../types';
|
|
|
36
36
|
* };
|
|
37
37
|
* ```
|
|
38
38
|
*
|
|
39
|
-
* @return A custom
|
|
39
|
+
* @return A custom React hook exposing the registry context value.
|
|
40
40
|
*/
|
|
41
41
|
export default function useRegistry(): DataRegistry;
|
|
42
42
|
//# sourceMappingURL=use-registry.d.ts.map
|
|
@@ -39,6 +39,6 @@ import type { SelectFunction, DataRegistry } from '../../types';
|
|
|
39
39
|
*
|
|
40
40
|
* @return Enhanced component with merged state data props.
|
|
41
41
|
*/
|
|
42
|
-
declare const withSelect: (mapSelectToProps: (select: SelectFunction, ownProps: Record<string, unknown>, registry: DataRegistry) => Record<string, unknown>) => (Inner: import("react").ComponentType<any>) => import("react").
|
|
42
|
+
declare const withSelect: (mapSelectToProps: (select: SelectFunction, ownProps: Record<string, unknown>, registry: DataRegistry) => Record<string, unknown>) => (Inner: import("react").ComponentType<any>) => import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<Omit<Record<string, unknown>, "ref"> & import("react").RefAttributes<unknown>>>;
|
|
43
43
|
export default withSelect;
|
|
44
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/with-select/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/with-select/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,QAAA,MAAM,UAAU,qBACG,CACjB,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,EACnC,QAAQ,EAAE,YAAY,KAClB,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,iNAwB7B,CAAC;eAEY,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.48.1",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
},
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
|
-
"react-native": "src/index",
|
|
44
43
|
"wpScript": true,
|
|
45
44
|
"types": "build-types",
|
|
46
45
|
"sideEffects": false,
|
|
47
46
|
"dependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@wordpress/
|
|
50
|
-
"@wordpress/
|
|
51
|
-
"@wordpress/
|
|
52
|
-
"@wordpress/
|
|
53
|
-
"@wordpress/
|
|
54
|
-
"@wordpress/
|
|
55
|
-
"
|
|
47
|
+
"@types/react": "^18.3.27",
|
|
48
|
+
"@wordpress/compose": "^8.1.1",
|
|
49
|
+
"@wordpress/deprecated": "^4.48.1",
|
|
50
|
+
"@wordpress/element": "^8.0.1",
|
|
51
|
+
"@wordpress/is-shallow-equal": "^5.48.1",
|
|
52
|
+
"@wordpress/priority-queue": "^3.48.1",
|
|
53
|
+
"@wordpress/private-apis": "^1.48.1",
|
|
54
|
+
"@wordpress/redux-routine": "^5.48.1",
|
|
55
|
+
"deepmerge": "^4.3.1",
|
|
56
56
|
"equivalent-key-map": "^0.2.2",
|
|
57
57
|
"is-plain-object": "^5.0.0",
|
|
58
58
|
"is-promise": "^4.0.0",
|
|
@@ -61,13 +61,16 @@
|
|
|
61
61
|
"use-memo-one": "^1.1.1"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"
|
|
64
|
+
"@testing-library/dom": "^10.4.1",
|
|
65
|
+
"@testing-library/react": "^16.3.2",
|
|
66
|
+
"@testing-library/user-event": "^14.6.1",
|
|
67
|
+
"deep-freeze": "^0.0.1"
|
|
65
68
|
},
|
|
66
69
|
"peerDependencies": {
|
|
67
|
-
"react": "^
|
|
70
|
+
"react": "^18.0.0"
|
|
68
71
|
},
|
|
69
72
|
"publishConfig": {
|
|
70
73
|
"access": "public"
|
|
71
74
|
},
|
|
72
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "99df7432c5c7cb83ba41146fd1f57f3c19004305"
|
|
73
76
|
}
|
|
@@ -14,10 +14,10 @@ Context.displayName = 'RegistryProviderContext';
|
|
|
14
14
|
const { Consumer, Provider } = Context;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* A custom
|
|
17
|
+
* A custom React context consumer exposing the provided `registry` to
|
|
18
18
|
* children components. Used along with the RegistryProvider.
|
|
19
19
|
*
|
|
20
|
-
* You can read more about the
|
|
20
|
+
* You can read more about the React context API here:
|
|
21
21
|
* https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
@@ -50,7 +50,7 @@ export const RegistryConsumer = Consumer;
|
|
|
50
50
|
* A custom Context provider for exposing the provided `registry` to children
|
|
51
51
|
* components via a consumer.
|
|
52
52
|
*
|
|
53
|
-
* See <a
|
|
53
|
+
* See <a href="#registryconsumer">RegistryConsumer</a> documentation for
|
|
54
54
|
* example.
|
|
55
55
|
*/
|
|
56
56
|
export default Provider;
|
|
@@ -10,17 +10,17 @@ import { Context } from './context';
|
|
|
10
10
|
import type { DataRegistry } from '../../types';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* A custom
|
|
13
|
+
* A custom React hook exposing the registry context for use.
|
|
14
14
|
*
|
|
15
15
|
* This exposes the `registry` value provided via the
|
|
16
|
-
* <a href="#
|
|
16
|
+
* <a href="#registryprovider">Registry Provider</a> to a component implementing
|
|
17
17
|
* this hook.
|
|
18
18
|
*
|
|
19
|
-
* It acts similarly to the `useContext`
|
|
19
|
+
* It acts similarly to the `useContext` React hook.
|
|
20
20
|
*
|
|
21
21
|
* Note: Generally speaking, `useRegistry` is a low level hook that in most cases
|
|
22
22
|
* won't be needed for implementation. Most interactions with the `@wordpress/data`
|
|
23
|
-
* API can be performed via the `useSelect` hook,
|
|
23
|
+
* API can be performed via the `useSelect` hook, or the `withSelect` and
|
|
24
24
|
* `withDispatch` higher order components.
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
@@ -46,7 +46,7 @@ import type { DataRegistry } from '../../types';
|
|
|
46
46
|
* };
|
|
47
47
|
* ```
|
|
48
48
|
*
|
|
49
|
-
* @return A custom
|
|
49
|
+
* @return A custom React hook exposing the registry context value.
|
|
50
50
|
*/
|
|
51
51
|
export default function useRegistry(): DataRegistry {
|
|
52
52
|
return useContext( Context );
|
|
@@ -6,13 +6,13 @@ import { render, screen } from '@testing-library/react';
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { Component, Suspense } from '@wordpress/element';
|
|
10
9
|
import {
|
|
11
10
|
createRegistry,
|
|
12
11
|
createReduxStore,
|
|
13
12
|
useSuspenseSelect,
|
|
14
13
|
RegistryProvider,
|
|
15
14
|
} from '@wordpress/data';
|
|
15
|
+
import { Component, Suspense } from '@wordpress/element';
|
|
16
16
|
|
|
17
17
|
function createRegistryWithStore() {
|
|
18
18
|
const initialState = {
|
|
@@ -110,12 +110,10 @@ describe( 'useSuspenseSelect', () => {
|
|
|
110
110
|
render( <App /> );
|
|
111
111
|
await screen.findByLabelText( 'loaded' );
|
|
112
112
|
|
|
113
|
-
// Verify there were
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
// - final fourth render after all data got loaded.
|
|
118
|
-
expect( attempts ).toBe( 4 );
|
|
113
|
+
// Verify there were 3 attempts to render. Suspended twice because of
|
|
114
|
+
// `getToken` and `getData` selectors not being resolved, and then finally
|
|
115
|
+
// rendered after all data got loaded.
|
|
116
|
+
expect( attempts ).toBe( 3 );
|
|
119
117
|
expect( renders ).toBe( 1 );
|
|
120
118
|
} );
|
|
121
119
|
|
|
@@ -231,23 +229,7 @@ describe( 'useSuspenseSelect', () => {
|
|
|
231
229
|
const slowLabel = await screen.findByLabelText( 'slow loaded' );
|
|
232
230
|
expect( slowLabel ).toHaveTextContent( 'slow' );
|
|
233
231
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
// - second (async) render for sibling prerendering that tries to collect all suspending promises.
|
|
237
|
-
// Both `FastUI` and `SlowUI` suspend again but this time the result is not committed, its purpose
|
|
238
|
-
// was just to collect suspending promises.
|
|
239
|
-
// - `FastUI` renders for third time after its suspended promise is resolved. However, this render
|
|
240
|
-
// is _not_ committed because of "suspense fallback throttling". The render is delayed/throttled for 300ms
|
|
241
|
-
// so that the user doesn't see too many and too fast UI flashes. The fallback continues to be rendered.
|
|
242
|
-
// - `SlowUI` suspended promise is resolved and a third render is triggered. However, as the `FastUI` render
|
|
243
|
-
// is not yet committed, a _fourth_ render is triggered, to make sure that we'll be committing the most
|
|
244
|
-
// up-to-date state of the `FastUI` component.
|
|
245
|
-
//
|
|
246
|
-
// The above explains why there are 4 renders of `FastUI` and 3 renders of `SlowUI`. The non-obvious part
|
|
247
|
-
// is explained by a combination of two React features:
|
|
248
|
-
// - sibling prerendering that triggers an extra rerender after one component suspends;
|
|
249
|
-
// - fallback throttling that delays commit by 300ms and triggers an extra rerender.
|
|
250
|
-
expect( FastUI ).toHaveBeenCalledTimes( 4 );
|
|
251
|
-
expect( SlowUI ).toHaveBeenCalledTimes( 3 );
|
|
232
|
+
expect( FastUI ).toHaveBeenCalledTimes( 2 );
|
|
233
|
+
expect( SlowUI ).toHaveBeenCalledTimes( 2 );
|
|
252
234
|
} );
|
|
253
235
|
} );
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createHigherOrderComponent
|
|
4
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
5
|
+
import { forwardRef, memo } from '@wordpress/element';
|
|
6
|
+
import type { ForwardedRef } from 'react';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Internal dependencies
|
|
@@ -58,14 +60,25 @@ const withSelect = (
|
|
|
58
60
|
) =>
|
|
59
61
|
createHigherOrderComponent(
|
|
60
62
|
( WrappedComponent ) =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
memo(
|
|
64
|
+
forwardRef( function WithSelect(
|
|
65
|
+
ownProps: Record< string, unknown >,
|
|
66
|
+
ref: ForwardedRef< unknown >
|
|
67
|
+
) {
|
|
68
|
+
const mapSelect = (
|
|
69
|
+
select: SelectFunction,
|
|
70
|
+
registry: DataRegistry
|
|
71
|
+
) => mapSelectToProps( select, ownProps, registry );
|
|
72
|
+
const mergeProps = useSelect( mapSelect );
|
|
73
|
+
return (
|
|
74
|
+
<WrappedComponent
|
|
75
|
+
ref={ ref }
|
|
76
|
+
{ ...ownProps }
|
|
77
|
+
{ ...mergeProps }
|
|
78
|
+
/>
|
|
79
|
+
);
|
|
80
|
+
} )
|
|
81
|
+
),
|
|
69
82
|
'withSelect'
|
|
70
83
|
);
|
|
71
84
|
|
|
@@ -8,7 +8,7 @@ import userEvent from '@testing-library/user-event';
|
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
10
|
import { compose } from '@wordpress/compose';
|
|
11
|
-
import { Component } from '@wordpress/element';
|
|
11
|
+
import { Component, createRef, forwardRef } from '@wordpress/element';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Internal dependencies
|
|
@@ -626,5 +626,35 @@ describe( 'withSelect', () => {
|
|
|
626
626
|
expect( OriginalComponent ).toHaveBeenCalledTimes( 2 );
|
|
627
627
|
expect( screen.getByRole( 'status' ) ).toHaveTextContent( 'second' );
|
|
628
628
|
} );
|
|
629
|
+
|
|
630
|
+
it( 'forwards refs to a function component wrapped with withSelect', () => {
|
|
631
|
+
const registry = createRegistry();
|
|
632
|
+
registry.registerStore( 'demo', {
|
|
633
|
+
reducer: ( state = 'value' ) => state,
|
|
634
|
+
selectors: {
|
|
635
|
+
getValue: ( state ) => state,
|
|
636
|
+
},
|
|
637
|
+
} );
|
|
638
|
+
|
|
639
|
+
const OriginalComponent = forwardRef( ( { value }, ref ) => (
|
|
640
|
+
<div ref={ ref } role="status">
|
|
641
|
+
{ value }
|
|
642
|
+
</div>
|
|
643
|
+
) );
|
|
644
|
+
|
|
645
|
+
const DataBoundComponent = withSelect( ( _select ) => ( {
|
|
646
|
+
value: _select( 'demo' ).getValue(),
|
|
647
|
+
} ) )( OriginalComponent );
|
|
648
|
+
|
|
649
|
+
const ref = createRef();
|
|
650
|
+
|
|
651
|
+
render(
|
|
652
|
+
<RegistryProvider value={ registry }>
|
|
653
|
+
<DataBoundComponent ref={ ref } />
|
|
654
|
+
</RegistryProvider>
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
expect( ref.current ).toBe( screen.getByRole( 'status' ) );
|
|
658
|
+
} );
|
|
629
659
|
} );
|
|
630
660
|
/* eslint-enable @wordpress/wp-global-usage */
|