UNPKG

@prezly/theme-kit-nextjs

Version:

Data layer and utility library for developing Prezly themes with NextJS

77 lines 3.98 kB
var _excluded = ["resolveDictionary"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } import React from "react"; function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); } function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } import { AsyncResolvable } from '@prezly/theme-kit-core'; import { formatMessageFragment, formatMessageString, importDictionary as importThemeKitDictionary } from '@prezly/theme-kit-intl'; import { FormattedDate as BaseFormattedDate, FormattedTime as BaseFormattedTime } from '@prezly/theme-kit-react'; export var IntlAdapter; (function (_IntlAdapter) { function connect(_ref) { var { resolveDictionary = importThemeKitDictionary } = _ref, config = _objectWithoutProperties(_ref, _excluded); function useIntl(_x) { return _useIntl.apply(this, arguments); } function _useIntl() { _useIntl = _asyncToGenerator(function* (locale) { var timezone = yield AsyncResolvable.resolve(config.timezone); var messages = yield resolveDictionary(locale); return { messages, formatMessage(descriptor, values) { return formatMessageString(locale, descriptor, messages, values); }, timezone }; }); return _useIntl.apply(this, arguments); } function FormattedMessage(_x2) { return _FormattedMessage.apply(this, arguments); } function _FormattedMessage() { _FormattedMessage = _asyncToGenerator(function* (props) { var messages = yield resolveDictionary(props.locale); return /*#__PURE__*/React.createElement(React.Fragment, null, formatMessageFragment(props.locale, props.for, messages, props.values)); }); return _FormattedMessage.apply(this, arguments); } function FormattedDate(_x3) { return _FormattedDate.apply(this, arguments); } function _FormattedDate() { _FormattedDate = _asyncToGenerator(function* (props) { var timezone = yield AsyncResolvable.resolve(config.timezone); return /*#__PURE__*/React.createElement(BaseFormattedDate, _extends({ timezone: timezone }, props)); }); return _FormattedDate.apply(this, arguments); } function FormattedTime(_x4) { return _FormattedTime.apply(this, arguments); } function _FormattedTime() { _FormattedTime = _asyncToGenerator(function* (props) { var timezone = yield AsyncResolvable.resolve(config.timezone); return /*#__PURE__*/React.createElement(BaseFormattedTime, _extends({ timezone: timezone }, props)); }); return _FormattedTime.apply(this, arguments); } return { useIntl, FormattedMessage, FormattedDate, FormattedTime }; } _IntlAdapter.connect = connect; })(IntlAdapter || (IntlAdapter = {}));