@wordpress/data 10.48.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 CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
- ## 10.48.0 (2026-06-04)
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).
6
12
 
7
13
  ## 10.47.0 (2026-05-27)
8
14
 
package/README.md CHANGED
@@ -613,9 +613,9 @@ _Returns_
613
613
 
614
614
  ### RegistryConsumer
615
615
 
616
- A custom react Context consumer exposing the provided `registry` to children components. Used along with the RegistryProvider.
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 react context api here: <https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context>
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 name="#RegistryConsumer">RegistryConsumer</a> documentation for example.
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 react hook exposing the registry context for use.
793
+ A custom React hook exposing the registry context for use.
794
794
 
795
- This exposes the `registry` value provided via the <a href="#RegistryProvider">Registry Provider</a> to a component implementing this hook.
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` react hook.
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 react hook exposing the registry context value.
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 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"],
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 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"],
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, import_compose.pure)((ownProps) => {
41
- const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
42
- const mergeProps = (0, import_use_select.default)(mapSelect);
43
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...ownProps, ...mergeProps });
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, pure } from '@wordpress/compose';\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\tpure( ( ownProps: Record< string, unknown > ) => {\n\t\t\t\tconst mapSelect = (\n\t\t\t\t\tselect: SelectFunction,\n\t\t\t\t\tregistry: DataRegistry\n\t\t\t\t) => mapSelectToProps( 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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAiD;AAKjD,wBAAsB;AA0DX;AAfX,IAAM,aAAa,CAClB,yBAMA;AAAA,EACC,CAAE,yBACD,qBAAM,CAAE,aAAyC;AAChD,UAAM,YAAY,CACjB,QACA,aACI,iBAAkB,QAAQ,UAAU,QAAS;AAClD,UAAM,iBAAa,kBAAAA,SAAW,SAAU;AACxC,WAAO,4CAAC,oBAAmB,GAAG,UAAa,GAAG,YAAa;AAAA,EAC5D,CAAE;AAAA,EACH;AACD;AAED,IAAO,sBAAQ;",
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 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"],
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 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"],
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, pure } from "@wordpress/compose";
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) => pure((ownProps) => {
7
- const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
8
- const mergeProps = useSelect(mapSelect);
9
- return /* @__PURE__ */ jsx(WrappedComponent, { ...ownProps, ...mergeProps });
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, pure } from '@wordpress/compose';\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\tpure( ( ownProps: Record< string, unknown > ) => {\n\t\t\t\tconst mapSelect = (\n\t\t\t\t\tselect: SelectFunction,\n\t\t\t\t\tregistry: DataRegistry\n\t\t\t\t) => mapSelectToProps( 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": ";AAGA,SAAS,4BAA4B,YAAY;AAKjD,OAAO,eAAe;AA0DX;AAfX,IAAM,aAAa,CAClB,qBAMA;AAAA,EACC,CAAE,qBACD,KAAM,CAAE,aAAyC;AAChD,UAAM,YAAY,CACjB,QACA,aACI,iBAAkB,QAAQ,UAAU,QAAS;AAClD,UAAM,aAAa,UAAW,SAAU;AACxC,WAAO,oBAAC,oBAAmB,GAAG,UAAa,GAAG,YAAa;AAAA,EAC5D,CAAE;AAAA,EACH;AACD;AAED,IAAO,sBAAQ;",
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 react Context consumer exposing the provided `registry` to
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 react context api here:
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 name="#RegistryConsumer">RegistryConsumer</a> documentation for
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 react hook exposing the registry context for use.
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="#RegistryProvider">Registry Provider</a> to a component implementing
6
+ * <a href="#registryprovider">Registry Provider</a> to a component implementing
7
7
  * this hook.
8
8
  *
9
- * It acts similarly to the `useContext` react hook.
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, or the `withSelect` and
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 react hook exposing the registry context value.
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").ComponentType<Record<string, unknown>>;
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":"AASA,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,0GAa7B,CAAC;eAEY,UAAU"}
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.48.0",
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
- "@wordpress/compose": "^8.1.0",
49
- "@wordpress/deprecated": "^4.48.0",
50
- "@wordpress/element": "^8.0.0",
51
- "@wordpress/is-shallow-equal": "^5.48.0",
52
- "@wordpress/priority-queue": "^3.48.0",
53
- "@wordpress/private-apis": "^1.48.0",
54
- "@wordpress/redux-routine": "^5.48.0",
55
- "deepmerge": "^4.3.0",
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,7 +61,10 @@
61
61
  "use-memo-one": "^1.1.1"
62
62
  },
63
63
  "devDependencies": {
64
- "deep-freeze": "0.0.1"
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
70
  "react": "^18.0.0"
@@ -69,5 +72,5 @@
69
72
  "publishConfig": {
70
73
  "access": "public"
71
74
  },
72
- "gitHead": "e7856693aeb4e2522d13608cd32c994e4a97cb9c"
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 react Context consumer exposing the provided `registry` to
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 react context api here:
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 name="#RegistryConsumer">RegistryConsumer</a> documentation for
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 react hook exposing the registry context for use.
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="#RegistryProvider">Registry Provider</a> to a component implementing
16
+ * <a href="#registryprovider">Registry Provider</a> to a component implementing
17
17
  * this hook.
18
18
  *
19
- * It acts similarly to the `useContext` react hook.
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, or the `withSelect` and
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 react hook exposing the registry context value.
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 = {
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createHigherOrderComponent, pure } from '@wordpress/compose';
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
- pure( ( ownProps: Record< string, unknown > ) => {
62
- const mapSelect = (
63
- select: SelectFunction,
64
- registry: DataRegistry
65
- ) => mapSelectToProps( select, ownProps, registry );
66
- const mergeProps = useSelect( mapSelect );
67
- return <WrappedComponent { ...ownProps } { ...mergeProps } />;
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 */