| @@ -1,186 +1 @@ | ||
| 1 | -/******/ (function() { // webpackBootstrap | |
| 2 | -/******/ "use strict"; | |
| 3 | -/******/ // The require scope | |
| 4 | -/******/ var __webpack_require__ = {}; | |
| 5 | -/******/ | |
| 6 | -/************************************************************************/ | |
| 7 | -/******/ /* webpack/runtime/define property getters */ | |
| 8 | -/******/ !function() { | |
| 9 | -/******/ // define getter functions for harmony exports | |
| 10 | -/******/ __webpack_require__.d = function(exports, definition) { | |
| 11 | -/******/ for(var key in definition) { | |
| 12 | -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 13 | -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 14 | -/******/ } | |
| 15 | -/******/ } | |
| 16 | -/******/ }; | |
| 17 | -/******/ }(); | |
| 18 | -/******/ | |
| 19 | -/******/ /* webpack/runtime/hasOwnProperty shorthand */ | |
| 20 | -/******/ !function() { | |
| 21 | -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | |
| 22 | -/******/ }(); | |
| 23 | -/******/ | |
| 24 | -/******/ /* webpack/runtime/make namespace object */ | |
| 25 | -/******/ !function() { | |
| 26 | -/******/ // define __esModule on exports | |
| 27 | -/******/ __webpack_require__.r = function(exports) { | |
| 28 | -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | |
| 29 | -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | |
| 30 | -/******/ } | |
| 31 | -/******/ Object.defineProperty(exports, '__esModule', { value: true }); | |
| 32 | -/******/ }; | |
| 33 | -/******/ }(); | |
| 34 | -/******/ | |
| 35 | -/************************************************************************/ | |
| 36 | -var __webpack_exports__ = {}; | |
| 37 | -// ESM COMPAT FLAG | |
| 38 | -__webpack_require__.r(__webpack_exports__); | |
| 39 | - | |
| 40 | -// EXPORTS | |
| 41 | -__webpack_require__.d(__webpack_exports__, { | |
| 42 | - "I18nProvider": function() { return /* binding */ I18nProvider; }, | |
| 43 | - "useI18n": function() { return /* binding */ useI18n; }, | |
| 44 | - "withI18n": function() { return /* binding */ withI18n; } | |
| 45 | -}); | |
| 46 | - | |
| 47 | -;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js | |
| 48 | -function _extends() { | |
| 49 | - _extends = Object.assign || function (target) { | |
| 50 | - for (var i = 1; i < arguments.length; i++) { | |
| 51 | - var source = arguments[i]; | |
| 52 | - | |
| 53 | - for (var key in source) { | |
| 54 | - if (Object.prototype.hasOwnProperty.call(source, key)) { | |
| 55 | - target[key] = source[key]; | |
| 56 | - } | |
| 57 | - } | |
| 58 | - } | |
| 59 | - | |
| 60 | - return target; | |
| 61 | - }; | |
| 62 | - | |
| 63 | - return _extends.apply(this, arguments); | |
| 64 | -} | |
| 65 | -;// CONCATENATED MODULE: external ["wp","element"] | |
| 66 | -var external_wp_element_namespaceObject = window["wp"]["element"]; | |
| 67 | -;// CONCATENATED MODULE: external ["wp","i18n"] | |
| 68 | -var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; | |
| 69 | -;// CONCATENATED MODULE: ./packages/react-i18n/build-module/index.js | |
| 70 | - | |
| 71 | - | |
| 72 | - | |
| 73 | -/** | |
| 74 | - * External dependencies | |
| 75 | - */ | |
| 76 | - | |
| 77 | -/** | |
| 78 | - * WordPress dependencies | |
| 79 | - */ | |
| 80 | - | |
| 81 | - | |
| 82 | - | |
| 83 | -/** | |
| 84 | - * Utility to make a new context value | |
| 85 | - * | |
| 86 | - * @param i18n | |
| 87 | - */ | |
| 88 | -function makeContextValue(i18n) { | |
| 89 | - return { | |
| 90 | - __: i18n.__.bind(i18n), | |
| 91 | - _x: i18n._x.bind(i18n), | |
| 92 | - _n: i18n._n.bind(i18n), | |
| 93 | - _nx: i18n._nx.bind(i18n), | |
| 94 | - isRTL: i18n.isRTL.bind(i18n), | |
| 95 | - hasTranslation: i18n.hasTranslation.bind(i18n) | |
| 96 | - }; | |
| 97 | -} | |
| 98 | - | |
| 99 | -const I18nContext = (0,external_wp_element_namespaceObject.createContext)(makeContextValue(external_wp_i18n_namespaceObject.defaultI18n)); | |
| 100 | - | |
| 101 | -/** | |
| 102 | - * The `I18nProvider` should be mounted above any localized components: | |
| 103 | - * | |
| 104 | - * @example | |
| 105 | - * ```js | |
| 106 | - * import { createI18n } from '@wordpress/react-i18n'; | |
| 107 | - * import { I18nProvider } from '@wordpress/react-i18n'; | |
| 108 | - * const i18n = createI18n(); | |
| 109 | - * | |
| 110 | - * ReactDom.render( | |
| 111 | - * <I18nProvider i18n={ i18n }> | |
| 112 | - * <App /> | |
| 113 | - * </I18nProvider>, | |
| 114 | - * el | |
| 115 | - * ); | |
| 116 | - * ``` | |
| 117 | - * | |
| 118 | - * You can also instantiate the provider without the `i18n` prop. In that case it will use the | |
| 119 | - * default `I18n` instance exported from `@wordpress/i18n`. | |
| 120 | - * | |
| 121 | - * @param props i18n provider props. | |
| 122 | - * @return Children wrapped in the I18nProvider. | |
| 123 | - */ | |
| 124 | -function I18nProvider(props) { | |
| 125 | - const { | |
| 126 | - children, | |
| 127 | - i18n = external_wp_i18n_namespaceObject.defaultI18n | |
| 128 | - } = props; | |
| 129 | - const [update, forceUpdate] = (0,external_wp_element_namespaceObject.useReducer)(() => [], []); // rerender translations whenever the i18n instance fires a change event | |
| 130 | - | |
| 131 | - (0,external_wp_element_namespaceObject.useEffect)(() => i18n.subscribe(forceUpdate), [i18n]); | |
| 132 | - const value = (0,external_wp_element_namespaceObject.useMemo)(() => makeContextValue(i18n), [i18n, update]); | |
| 133 | - return (0,external_wp_element_namespaceObject.createElement)(I18nContext.Provider, { | |
| 134 | - value: value | |
| 135 | - }, children); | |
| 136 | -} | |
| 137 | -/** | |
| 138 | - * React hook providing access to i18n functions. It exposes the `__`, `_x`, `_n`, `_nx`, | |
| 139 | - * `isRTL` and `hasTranslation` functions from [`@wordpress/i18n`](../i18n). | |
| 140 | - * Refer to their documentation there. | |
| 141 | - * | |
| 142 | - * @example | |
| 143 | - * ```js | |
| 144 | - * import { useI18n } from '@wordpress/react-i18n'; | |
| 145 | - * | |
| 146 | - * function MyComponent() { | |
| 147 | - * const { __ } = useI18n(); | |
| 148 | - * return __( 'Hello, world!' ); | |
| 149 | - * } | |
| 150 | - * ``` | |
| 151 | - */ | |
| 152 | - | |
| 153 | -const useI18n = () => (0,external_wp_element_namespaceObject.useContext)(I18nContext); | |
| 154 | - | |
| 155 | -/** | |
| 156 | - * React higher-order component that passes the i18n translate functions (the same set | |
| 157 | - * as exposed by the `useI18n` hook) to the wrapped component as props. | |
| 158 | - * | |
| 159 | - * @example | |
| 160 | - * ```js | |
| 161 | - * import { withI18n } from '@wordpress/react-i18n'; | |
| 162 | - * | |
| 163 | - * function MyComponent( { __ } ) { | |
| 164 | - * return __( 'Hello, world!' ); | |
| 165 | - * } | |
| 166 | - * | |
| 167 | - * export default withI18n( MyComponent ); | |
| 168 | - * ``` | |
| 169 | - * | |
| 170 | - * @param InnerComponent React component to be wrapped and receive the i18n functions like `__` | |
| 171 | - * @return The wrapped component | |
| 172 | - */ | |
| 173 | -function withI18n(InnerComponent) { | |
| 174 | - const EnhancedComponent = props => { | |
| 175 | - const i18nProps = useI18n(); | |
| 176 | - return (0,external_wp_element_namespaceObject.createElement)(InnerComponent, _extends({}, props, i18nProps)); | |
| 177 | - }; | |
| 178 | - | |
| 179 | - const innerComponentName = InnerComponent.displayName || InnerComponent.name || 'Component'; | |
| 180 | - EnhancedComponent.displayName = `WithI18n(${innerComponentName})`; | |
| 181 | - return EnhancedComponent; | |
| 182 | -} | |
| 183 | -//# sourceMappingURL=index.js.map | |
| 184 | -(window.wp = window.wp || {}).reactI18n = __webpack_exports__; | |
| 185 | -/******/ })() | |
| 186 | -; | |
| 1 | +window.wp=window.wp||{},window.wp.reactI18n=function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=509)}({0:function(t,n){t.exports=window.wp.element},1:function(t,n){t.exports=window.wp.i18n},10:function(t,n,e){"use strict";function r(){return(r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t}).apply(this,arguments)}e.d(n,"a",(function(){return r}))},24:function(t,n,e){"use strict";function r(t,n){(null==n||n>t.length)&&(n=t.length);for(var e=0,r=new Array(n);e<n;e++)r[e]=t[e];return r}e.d(n,"a",(function(){return r}))},30:function(t,n,e){"use strict";e.d(n,"a",(function(){return o}));var r=e(24);function o(t,n){if(t){if("string"==typeof t)return Object(r.a)(t,n);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?Object(r.a)(t,n):void 0}}},39:function(t,n,e){"use strict";function r(t){if(Array.isArray(t))return t}e.d(n,"a",(function(){return r}))},40:function(t,n,e){"use strict";function r(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}e.d(n,"a",(function(){return r}))},509:function(t,n,e){"use strict";e.r(n),e.d(n,"I18nProvider",(function(){return f})),e.d(n,"useI18n",(function(){return l})),e.d(n,"withI18n",(function(){return s}));var r=e(10),o=e(8),u=e(0),i=e(1);function c(t){return{__:t.__.bind(t),_x:t._x.bind(t),_n:t._n.bind(t),_nx:t._nx.bind(t),isRTL:t.isRTL.bind(t),hasTranslation:t.hasTranslation.bind(t)}}var a=Object(u.createContext)(c(i.defaultI18n));function f(t){var n=t.children,e=t.i18n,r=void 0===e?i.defaultI18n:e,f=Object(u.useReducer)((function(){return[]}),[]),l=Object(o.a)(f,2),s=l[0],d=l[1];Object(u.useEffect)((function(){return r.subscribe(d)}),[r]);var b=Object(u.useMemo)((function(){return c(r)}),[r,s]);return Object(u.createElement)(a.Provider,{value:b},n)}var l=function(){return Object(u.useContext)(a)};function s(t){var n=function(n){var e=l();return Object(u.createElement)(t,Object(r.a)({},n,e))},e=t.displayName||t.name||"Component";return n.displayName="WithI18n(".concat(e,")"),n}},8:function(t,n,e){"use strict";e.d(n,"a",(function(){return i}));var r=e(39),o=e(30),u=e(40);function i(t,n){return Object(r.a)(t)||function(t,n){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var e=[],_n=!0,r=!1,o=void 0;try{for(var u,i=t[Symbol.iterator]();!(_n=(u=i.next()).done)&&(e.push(u.value),!n||e.length!==n);_n=!0);}catch(t){r=!0,o=t}finally{try{_n||null==i.return||i.return()}finally{if(r)throw o}}return e}}(t,n)||Object(o.a)(t,n)||Object(u.a)()}}}); | |