@wordpress/react-i18n 3.32.0 → 3.33.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,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.33.0 (2023-06-07)
6
+
5
7
  ## 3.32.0 (2023-05-24)
6
8
 
7
9
  ## 3.31.0 (2023-05-10)
package/build/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
@@ -11,8 +9,6 @@ exports.withI18n = withI18n;
11
9
 
12
10
  var _element = require("@wordpress/element");
13
11
 
14
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
-
16
12
  var _i18n = require("@wordpress/i18n");
17
13
 
18
14
  /**
@@ -119,7 +115,9 @@ exports.useI18n = useI18n;
119
115
  function withI18n(InnerComponent) {
120
116
  const EnhancedComponent = props => {
121
117
  const i18nProps = useI18n();
122
- return (0, _element.createElement)(InnerComponent, (0, _extends2.default)({}, props, i18nProps));
118
+ return (0, _element.createElement)(InnerComponent, { ...props,
119
+ ...i18nProps
120
+ });
123
121
  };
124
122
 
125
123
  const innerComponentName = InnerComponent.displayName || InnerComponent.name || 'Component';
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/react-i18n/src/index.tsx"],"names":["makeContextValue","i18n","__","bind","_x","_n","_nx","isRTL","hasTranslation","I18nContext","defaultI18n","I18nProvider","props","children","update","forceUpdate","subscribe","value","useI18n","withI18n","InnerComponent","EnhancedComponent","i18nProps","innerComponentName","displayName","name"],"mappings":";;;;;;;;;;;AAaA;;;;AAOA;;AApBA;AACA;AACA;;AAQA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAT,CAA2BC,IAA3B,EAA0D;AAC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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMK,OAAO,GAAG,MAAM,yBAAYT,WAAZ,CAAtB;;;;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASU,QAAT,CACNC,cADM,EAEmC;AACzC,QAAMC,iBAEL,GAAKT,KAAF,IAAa;AAChB,UAAMU,SAAS,GAAGJ,OAAO,EAAzB;AACA,WAAO,4BAAC,cAAD,6BAAuBN,KAAvB,EAA2CU,SAA3C,EAAP;AACA,GALD;;AAMA,QAAMC,kBAAkB,GACvBH,cAAc,CAACI,WAAf,IAA8BJ,cAAc,CAACK,IAA7C,IAAqD,WADtD;AAEAJ,EAAAA,iBAAiB,CAACG,WAAlB,GAAiC,YAAYD,kBAAoB,GAAjE;AACA,SAAOF,iBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tComponentType,\n\tFunctionComponent,\n\tPropsWithChildren,\n} from 'react';\nimport type { Subtract } from 'utility-types';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { defaultI18n } from '@wordpress/i18n';\nimport type { I18n } from '@wordpress/i18n';\ninterface I18nContextProps {\n\t__: I18n[ '__' ];\n\t_x: I18n[ '_x' ];\n\t_n: I18n[ '_n' ];\n\t_nx: I18n[ '_nx' ];\n\tisRTL: I18n[ 'isRTL' ];\n\thasTranslation: I18n[ 'hasTranslation' ];\n}\n\n/**\n * Utility to make a new context value\n *\n * @param i18n\n */\nfunction makeContextValue( i18n: I18n ): I18nContextProps {\n\treturn {\n\t\t__: i18n.__.bind( i18n ),\n\t\t_x: i18n._x.bind( i18n ),\n\t\t_n: i18n._n.bind( i18n ),\n\t\t_nx: i18n._nx.bind( i18n ),\n\t\tisRTL: i18n.isRTL.bind( i18n ),\n\t\thasTranslation: i18n.hasTranslation.bind( i18n ),\n\t};\n}\n\nconst I18nContext = createContext( makeContextValue( defaultI18n ) );\n\ntype I18nProviderProps = PropsWithChildren< { i18n: I18n } >;\n\n/**\n * The `I18nProvider` should be mounted above any localized components:\n *\n * @example\n * ```js\n * import { createI18n } from '@wordpress/react-i18n';\n * import { I18nProvider } from '@wordpress/react-i18n';\n * const i18n = createI18n();\n *\n * ReactDom.render(\n * \t<I18nProvider i18n={ i18n }>\n * \t\t<App />\n * \t</I18nProvider>,\n * \tel\n * );\n * ```\n *\n * You can also instantiate the provider without the `i18n` prop. In that case it will use the\n * default `I18n` instance exported from `@wordpress/i18n`.\n *\n * @param props i18n provider props.\n * @return Children wrapped in the I18nProvider.\n */\nexport function I18nProvider( props: I18nProviderProps ): JSX.Element {\n\tconst { children, i18n = defaultI18n } = props;\n\tconst [ update, forceUpdate ] = useReducer( () => [], [] );\n\n\t// Rerender translations whenever the i18n instance fires a change event.\n\tuseEffect( () => i18n.subscribe( forceUpdate ), [ i18n ] );\n\n\tconst value = useMemo( () => makeContextValue( i18n ), [ i18n, update ] );\n\n\treturn (\n\t\t<I18nContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</I18nContext.Provider>\n\t);\n}\n\n/**\n * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,\n * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).\n * Refer to their documentation there.\n *\n * @example\n * ```js\n * import { useI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent() {\n * \tconst { __ } = useI18n();\n * \treturn __( 'Hello, world!' );\n * }\n * ```\n */\nexport const useI18n = () => useContext( I18nContext );\n\ntype PropsAndI18n< P > = Pick<\n\tP,\n\tExclude< keyof P, '__' | '_x' | '_n' | '_nx' | 'isRTL' | 'hasTranslation' >\n>;\n\n/**\n * React higher-order component that passes the i18n translate functions (the same set\n * as exposed by the `useI18n` hook) to the wrapped component as props.\n *\n * @example\n * ```js\n * import { withI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent( { __ } ) {\n * \treturn __( 'Hello, world!' );\n * }\n *\n * export default withI18n( MyComponent );\n * ```\n *\n * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`\n * @return The wrapped component\n */\nexport function withI18n< P extends I18nContextProps >(\n\tInnerComponent: ComponentType< P >\n): FunctionComponent< PropsAndI18n< P > > {\n\tconst EnhancedComponent: ComponentType<\n\t\tSubtract< P, I18nContextProps >\n\t> = ( props ) => {\n\t\tconst i18nProps = useI18n();\n\t\treturn <InnerComponent { ...( props as P ) } { ...i18nProps } />;\n\t};\n\tconst innerComponentName =\n\t\tInnerComponent.displayName || InnerComponent.name || 'Component';\n\tEnhancedComponent.displayName = `WithI18n(${ innerComponentName })`;\n\treturn EnhancedComponent;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/react-i18n/src/index.tsx"],"names":["makeContextValue","i18n","__","bind","_x","_n","_nx","isRTL","hasTranslation","I18nContext","defaultI18n","I18nProvider","props","children","update","forceUpdate","subscribe","value","useI18n","withI18n","InnerComponent","EnhancedComponent","i18nProps","innerComponentName","displayName","name"],"mappings":";;;;;;;;;AAaA;;AAOA;;AApBA;AACA;AACA;;AAQA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA,SAASA,gBAAT,CAA2BC,IAA3B,EAA0D;AACzD,SAAO;AACNC,IAAAA,EAAE,EAAED,IAAI,CAACC,EAAL,CAAQC,IAAR,CAAcF,IAAd,CADE;AAENG,IAAAA,EAAE,EAAEH,IAAI,CAACG,EAAL,CAAQD,IAAR,CAAcF,IAAd,CAFE;AAGNI,IAAAA,EAAE,EAAEJ,IAAI,CAACI,EAAL,CAAQF,IAAR,CAAcF,IAAd,CAHE;AAINK,IAAAA,GAAG,EAAEL,IAAI,CAACK,GAAL,CAASH,IAAT,CAAeF,IAAf,CAJC;AAKNM,IAAAA,KAAK,EAAEN,IAAI,CAACM,KAAL,CAAWJ,IAAX,CAAiBF,IAAjB,CALD;AAMNO,IAAAA,cAAc,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I,WAAf,IAA8BJ,cAAc,CAACK,IAA7C,IAAqD,WADtD;AAEAJ,EAAAA,iBAAiB,CAACG,WAAlB,GAAiC,YAAYD,kBAAoB,GAAjE;AACA,SAAOF,iBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tComponentType,\n\tFunctionComponent,\n\tPropsWithChildren,\n} from 'react';\nimport type { Subtract } from 'utility-types';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { defaultI18n } from '@wordpress/i18n';\nimport type { I18n } from '@wordpress/i18n';\ninterface I18nContextProps {\n\t__: I18n[ '__' ];\n\t_x: I18n[ '_x' ];\n\t_n: I18n[ '_n' ];\n\t_nx: I18n[ '_nx' ];\n\tisRTL: I18n[ 'isRTL' ];\n\thasTranslation: I18n[ 'hasTranslation' ];\n}\n\n/**\n * Utility to make a new context value\n *\n * @param i18n\n */\nfunction makeContextValue( i18n: I18n ): I18nContextProps {\n\treturn {\n\t\t__: i18n.__.bind( i18n ),\n\t\t_x: i18n._x.bind( i18n ),\n\t\t_n: i18n._n.bind( i18n ),\n\t\t_nx: i18n._nx.bind( i18n ),\n\t\tisRTL: i18n.isRTL.bind( i18n ),\n\t\thasTranslation: i18n.hasTranslation.bind( i18n ),\n\t};\n}\n\nconst I18nContext = createContext( makeContextValue( defaultI18n ) );\n\ntype I18nProviderProps = PropsWithChildren< { i18n: I18n } >;\n\n/**\n * The `I18nProvider` should be mounted above any localized components:\n *\n * @example\n * ```js\n * import { createI18n } from '@wordpress/react-i18n';\n * import { I18nProvider } from '@wordpress/react-i18n';\n * const i18n = createI18n();\n *\n * ReactDom.render(\n * \t<I18nProvider i18n={ i18n }>\n * \t\t<App />\n * \t</I18nProvider>,\n * \tel\n * );\n * ```\n *\n * You can also instantiate the provider without the `i18n` prop. In that case it will use the\n * default `I18n` instance exported from `@wordpress/i18n`.\n *\n * @param props i18n provider props.\n * @return Children wrapped in the I18nProvider.\n */\nexport function I18nProvider( props: I18nProviderProps ): JSX.Element {\n\tconst { children, i18n = defaultI18n } = props;\n\tconst [ update, forceUpdate ] = useReducer( () => [], [] );\n\n\t// Rerender translations whenever the i18n instance fires a change event.\n\tuseEffect( () => i18n.subscribe( forceUpdate ), [ i18n ] );\n\n\tconst value = useMemo( () => makeContextValue( i18n ), [ i18n, update ] );\n\n\treturn (\n\t\t<I18nContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</I18nContext.Provider>\n\t);\n}\n\n/**\n * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,\n * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).\n * Refer to their documentation there.\n *\n * @example\n * ```js\n * import { useI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent() {\n * \tconst { __ } = useI18n();\n * \treturn __( 'Hello, world!' );\n * }\n * ```\n */\nexport const useI18n = () => useContext( I18nContext );\n\ntype PropsAndI18n< P > = Pick<\n\tP,\n\tExclude< keyof P, '__' | '_x' | '_n' | '_nx' | 'isRTL' | 'hasTranslation' >\n>;\n\n/**\n * React higher-order component that passes the i18n translate functions (the same set\n * as exposed by the `useI18n` hook) to the wrapped component as props.\n *\n * @example\n * ```js\n * import { withI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent( { __ } ) {\n * \treturn __( 'Hello, world!' );\n * }\n *\n * export default withI18n( MyComponent );\n * ```\n *\n * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`\n * @return The wrapped component\n */\nexport function withI18n< P extends I18nContextProps >(\n\tInnerComponent: ComponentType< P >\n): FunctionComponent< PropsAndI18n< P > > {\n\tconst EnhancedComponent: ComponentType<\n\t\tSubtract< P, I18nContextProps >\n\t> = ( props ) => {\n\t\tconst i18nProps = useI18n();\n\t\treturn <InnerComponent { ...( props as P ) } { ...i18nProps } />;\n\t};\n\tconst innerComponentName =\n\t\tInnerComponent.displayName || InnerComponent.name || 'Component';\n\tEnhancedComponent.displayName = `WithI18n(${ innerComponentName })`;\n\treturn EnhancedComponent;\n}\n"]}
@@ -1,4 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import { createElement } from "@wordpress/element";
3
2
 
4
3
  /**
@@ -104,7 +103,9 @@ export const useI18n = () => useContext(I18nContext);
104
103
  export function withI18n(InnerComponent) {
105
104
  const EnhancedComponent = props => {
106
105
  const i18nProps = useI18n();
107
- return createElement(InnerComponent, _extends({}, props, i18nProps));
106
+ return createElement(InnerComponent, { ...props,
107
+ ...i18nProps
108
+ });
108
109
  };
109
110
 
110
111
  const innerComponentName = InnerComponent.displayName || InnerComponent.name || 'Component';
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/react-i18n/src/index.tsx"],"names":["createContext","useContext","useEffect","useMemo","useReducer","defaultI18n","makeContextValue","i18n","__","bind","_x","_n","_nx","isRTL","hasTranslation","I18nContext","I18nProvider","props","children","update","forceUpdate","subscribe","value","useI18n","withI18n","InnerComponent","EnhancedComponent","i18nProps","innerComponentName","displayName","name"],"mappings":";;;AAAA;AACA;AACA;;AAQA;AACA;AACA;AACA,SACCA,aADD,EAECC,UAFD,EAGCC,SAHD,EAICC,OAJD,EAKCC,UALD,QAMO,oBANP;AAOA,SAASC,WAAT,QAA4B,iBAA5B;;AAWA;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAT,CAA2BC,IAA3B,EAA0D;AACzD,SAAO;AACNC,IAAAA,EAAE,EAAED,IAAI,CAACC,EAAL,CAAQC,IAAR,CAAcF,IAAd,CADE;AAENG,IAAAA,EAAE,EAAEH,IAAI,CAACG,EAAL,CAAQD,IAAR,CAAcF,IAAd,CAFE;AAGNI,IAAAA,EAAE,EAAEJ,IAAI,CAACI,EAAL,CAAQF,IAAR,CAAcF,IAAd,CAHE;AAINK,IAAAA,GAAG,EAAEL,IAAI,CAACK,GAAL,CAASH,IAAT,CAAeF,IAAf,CAJC;AAKNM,IAAAA,KAAK,EAAEN,I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AAzB;AACA,WAAO,cAAC,cAAD,eAAuBN,KAAvB,EAA2CU,SAA3C,EAAP;AACA,GALD;;AAMA,QAAMC,kBAAkB,GACvBH,cAAc,CAACI,WAAf,IAA8BJ,cAAc,CAACK,IAA7C,IAAqD,WADtD;AAEAJ,EAAAA,iBAAiB,CAACG,WAAlB,GAAiC,YAAYD,kBAAoB,GAAjE;AACA,SAAOF,iBAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tComponentType,\n\tFunctionComponent,\n\tPropsWithChildren,\n} from 'react';\nimport type { Subtract } from 'utility-types';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { defaultI18n } from '@wordpress/i18n';\nimport type { I18n } from '@wordpress/i18n';\ninterface I18nContextProps {\n\t__: I18n[ '__' ];\n\t_x: I18n[ '_x' ];\n\t_n: I18n[ '_n' ];\n\t_nx: I18n[ '_nx' ];\n\tisRTL: I18n[ 'isRTL' ];\n\thasTranslation: I18n[ 'hasTranslation' ];\n}\n\n/**\n * Utility to make a new context value\n *\n * @param i18n\n */\nfunction makeContextValue( i18n: I18n ): I18nContextProps {\n\treturn {\n\t\t__: i18n.__.bind( i18n ),\n\t\t_x: i18n._x.bind( i18n ),\n\t\t_n: i18n._n.bind( i18n ),\n\t\t_nx: i18n._nx.bind( i18n ),\n\t\tisRTL: i18n.isRTL.bind( i18n ),\n\t\thasTranslation: i18n.hasTranslation.bind( i18n ),\n\t};\n}\n\nconst I18nContext = createContext( makeContextValue( defaultI18n ) );\n\ntype I18nProviderProps = PropsWithChildren< { i18n: I18n } >;\n\n/**\n * The `I18nProvider` should be mounted above any localized components:\n *\n * @example\n * ```js\n * import { createI18n } from '@wordpress/react-i18n';\n * import { I18nProvider } from '@wordpress/react-i18n';\n * const i18n = createI18n();\n *\n * ReactDom.render(\n * \t<I18nProvider i18n={ i18n }>\n * \t\t<App />\n * \t</I18nProvider>,\n * \tel\n * );\n * ```\n *\n * You can also instantiate the provider without the `i18n` prop. In that case it will use the\n * default `I18n` instance exported from `@wordpress/i18n`.\n *\n * @param props i18n provider props.\n * @return Children wrapped in the I18nProvider.\n */\nexport function I18nProvider( props: I18nProviderProps ): JSX.Element {\n\tconst { children, i18n = defaultI18n } = props;\n\tconst [ update, forceUpdate ] = useReducer( () => [], [] );\n\n\t// Rerender translations whenever the i18n instance fires a change event.\n\tuseEffect( () => i18n.subscribe( forceUpdate ), [ i18n ] );\n\n\tconst value = useMemo( () => makeContextValue( i18n ), [ i18n, update ] );\n\n\treturn (\n\t\t<I18nContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</I18nContext.Provider>\n\t);\n}\n\n/**\n * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,\n * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).\n * Refer to their documentation there.\n *\n * @example\n * ```js\n * import { useI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent() {\n * \tconst { __ } = useI18n();\n * \treturn __( 'Hello, world!' );\n * }\n * ```\n */\nexport const useI18n = () => useContext( I18nContext );\n\ntype PropsAndI18n< P > = Pick<\n\tP,\n\tExclude< keyof P, '__' | '_x' | '_n' | '_nx' | 'isRTL' | 'hasTranslation' >\n>;\n\n/**\n * React higher-order component that passes the i18n translate functions (the same set\n * as exposed by the `useI18n` hook) to the wrapped component as props.\n *\n * @example\n * ```js\n * import { withI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent( { __ } ) {\n * \treturn __( 'Hello, world!' );\n * }\n *\n * export default withI18n( MyComponent );\n * ```\n *\n * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`\n * @return The wrapped component\n */\nexport function withI18n< P extends I18nContextProps >(\n\tInnerComponent: ComponentType< P >\n): FunctionComponent< PropsAndI18n< P > > {\n\tconst EnhancedComponent: ComponentType<\n\t\tSubtract< P, I18nContextProps >\n\t> = ( props ) => {\n\t\tconst i18nProps = useI18n();\n\t\treturn <InnerComponent { ...( props as P ) } { ...i18nProps } />;\n\t};\n\tconst innerComponentName =\n\t\tInnerComponent.displayName || InnerComponent.name || 'Component';\n\tEnhancedComponent.displayName = `WithI18n(${ innerComponentName })`;\n\treturn EnhancedComponent;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/react-i18n/src/index.tsx"],"names":["createContext","useContext","useEffect","useMemo","useReducer","defaultI18n","makeContextValue","i18n","__","bind","_x","_n","_nx","isRTL","hasTranslation","I18nContext","I18nProvider","props","children","update","forceUpdate","subscribe","value","useI18n","withI18n","InnerComponent","EnhancedComponent","i18nProps","innerComponentName","displayName","name"],"mappings":";;AAAA;AACA;AACA;;AAQA;AACA;AACA;AACA,SACCA,aADD,EAECC,UAFD,EAGCC,SAHD,EAICC,OAJD,EAKCC,UALD,QAMO,oBANP;AAOA,SAASC,WAAT,QAA4B,iBAA5B;;AAWA;AACA;AACA;AACA;AACA;AACA,SAASC,gBAAT,CAA2BC,IAA3B,EAA0D;AACzD,SAAO;AACNC,IAAAA,EAAE,EAAED,IAAI,CAACC,EAAL,CAAQC,IAAR,CAAcF,IAAd,CADE;AAENG,IAAAA,EAAE,EAAEH,IAAI,CAACG,EAAL,CAAQD,IAAR,CAAcF,IAAd,CAFE;AAGNI,IAAAA,EAAE,EAAEJ,IAAI,CAACI,EAAL,CAAQF,IAAR,CAAcF,IAAd,CAHE;AAINK,IAAAA,GAAG,EAAEL,IAAI,CAACK,GAAL,CAASH,IAAT,CAAeF,IAAf,CAJC;AAKNM,IAAAA,KAAK,EAAEN,IAAI,CAACM,KAAL,CAAWJ,IAAX,CAAiBF,IAAjB,CALD;AAMNO,IAAAA,cAAc,EAAEP,IAAI,CAACO,cAAL,CAAoBL,IAApB,CAA0BF,IAA1B;AANV,GAAP;AAQA;;AAED,MAAMQ,WAAW,GAAGf,aAAa,CAAEM,gBAAgB,CAAED,WAAF,CAAlB,CAAjC;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA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AP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type {\n\tComponentType,\n\tFunctionComponent,\n\tPropsWithChildren,\n} from 'react';\nimport type { Subtract } from 'utility-types';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseEffect,\n\tuseMemo,\n\tuseReducer,\n} from '@wordpress/element';\nimport { defaultI18n } from '@wordpress/i18n';\nimport type { I18n } from '@wordpress/i18n';\ninterface I18nContextProps {\n\t__: I18n[ '__' ];\n\t_x: I18n[ '_x' ];\n\t_n: I18n[ '_n' ];\n\t_nx: I18n[ '_nx' ];\n\tisRTL: I18n[ 'isRTL' ];\n\thasTranslation: I18n[ 'hasTranslation' ];\n}\n\n/**\n * Utility to make a new context value\n *\n * @param i18n\n */\nfunction makeContextValue( i18n: I18n ): I18nContextProps {\n\treturn {\n\t\t__: i18n.__.bind( i18n ),\n\t\t_x: i18n._x.bind( i18n ),\n\t\t_n: i18n._n.bind( i18n ),\n\t\t_nx: i18n._nx.bind( i18n ),\n\t\tisRTL: i18n.isRTL.bind( i18n ),\n\t\thasTranslation: i18n.hasTranslation.bind( i18n ),\n\t};\n}\n\nconst I18nContext = createContext( makeContextValue( defaultI18n ) );\n\ntype I18nProviderProps = PropsWithChildren< { i18n: I18n } >;\n\n/**\n * The `I18nProvider` should be mounted above any localized components:\n *\n * @example\n * ```js\n * import { createI18n } from '@wordpress/react-i18n';\n * import { I18nProvider } from '@wordpress/react-i18n';\n * const i18n = createI18n();\n *\n * ReactDom.render(\n * \t<I18nProvider i18n={ i18n }>\n * \t\t<App />\n * \t</I18nProvider>,\n * \tel\n * );\n * ```\n *\n * You can also instantiate the provider without the `i18n` prop. In that case it will use the\n * default `I18n` instance exported from `@wordpress/i18n`.\n *\n * @param props i18n provider props.\n * @return Children wrapped in the I18nProvider.\n */\nexport function I18nProvider( props: I18nProviderProps ): JSX.Element {\n\tconst { children, i18n = defaultI18n } = props;\n\tconst [ update, forceUpdate ] = useReducer( () => [], [] );\n\n\t// Rerender translations whenever the i18n instance fires a change event.\n\tuseEffect( () => i18n.subscribe( forceUpdate ), [ i18n ] );\n\n\tconst value = useMemo( () => makeContextValue( i18n ), [ i18n, update ] );\n\n\treturn (\n\t\t<I18nContext.Provider value={ value }>\n\t\t\t{ children }\n\t\t</I18nContext.Provider>\n\t);\n}\n\n/**\n * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`,\n * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n).\n * Refer to their documentation there.\n *\n * @example\n * ```js\n * import { useI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent() {\n * \tconst { __ } = useI18n();\n * \treturn __( 'Hello, world!' );\n * }\n * ```\n */\nexport const useI18n = () => useContext( I18nContext );\n\ntype PropsAndI18n< P > = Pick<\n\tP,\n\tExclude< keyof P, '__' | '_x' | '_n' | '_nx' | 'isRTL' | 'hasTranslation' >\n>;\n\n/**\n * React higher-order component that passes the i18n translate functions (the same set\n * as exposed by the `useI18n` hook) to the wrapped component as props.\n *\n * @example\n * ```js\n * import { withI18n } from '@wordpress/react-i18n';\n *\n * function MyComponent( { __ } ) {\n * \treturn __( 'Hello, world!' );\n * }\n *\n * export default withI18n( MyComponent );\n * ```\n *\n * @param InnerComponent React component to be wrapped and receive the i18n functions like `__`\n * @return The wrapped component\n */\nexport function withI18n< P extends I18nContextProps >(\n\tInnerComponent: ComponentType< P >\n): FunctionComponent< PropsAndI18n< P > > {\n\tconst EnhancedComponent: ComponentType<\n\t\tSubtract< P, I18nContextProps >\n\t> = ( props ) => {\n\t\tconst i18nProps = useI18n();\n\t\treturn <InnerComponent { ...( props as P ) } { ...i18nProps } />;\n\t};\n\tconst innerComponentName =\n\t\tInnerComponent.displayName || InnerComponent.name || 'Component';\n\tEnhancedComponent.displayName = `WithI18n(${ innerComponentName })`;\n\treturn EnhancedComponent;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/react-i18n",
3
- "version": "3.32.0",
3
+ "version": "3.33.1",
4
4
  "description": "React bindings for @wordpress/i18n.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -28,12 +28,12 @@
28
28
  "sideEffects": false,
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.16.0",
31
- "@wordpress/element": "^5.11.0",
32
- "@wordpress/i18n": "^4.34.0",
31
+ "@wordpress/element": "^5.12.1",
32
+ "@wordpress/i18n": "^4.35.1",
33
33
  "utility-types": "^3.10.0"
34
34
  },
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  },
38
- "gitHead": "c7c79cb11b677adcbf06cf5f8cfb6c5ec1699f19"
38
+ "gitHead": "ce5639111c30763dbdf07f40eeb136ea6030ecf1"
39
39
  }