@prezly/theme-kit-nextjs
Version:
Data layer and utility library for developing Prezly themes with NextJS
84 lines (83 loc) • 4.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.IntlAdapter = void 0;
var _react = _interopRequireDefault(require("react"));
var _themeKitCore = require("@prezly/theme-kit-core");
var _themeKitIntl = require("@prezly/theme-kit-intl");
var _themeKitReact = require("@prezly/theme-kit-react");
var _excluded = ["resolveDictionary"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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); }
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; }
var IntlAdapter;
(function (_IntlAdapter) {
function connect(_ref) {
var {
resolveDictionary = _themeKitIntl.importDictionary
} = _ref,
config = _objectWithoutProperties(_ref, _excluded);
function useIntl(_x) {
return _useIntl.apply(this, arguments);
}
function _useIntl() {
_useIntl = _asyncToGenerator(function* (locale) {
var timezone = yield _themeKitCore.AsyncResolvable.resolve(config.timezone);
var messages = yield resolveDictionary(locale);
return {
messages,
formatMessage(descriptor, values) {
return (0, _themeKitIntl.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.default.createElement(_react.default.Fragment, null, (0, _themeKitIntl.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 _themeKitCore.AsyncResolvable.resolve(config.timezone);
return /*#__PURE__*/_react.default.createElement(_themeKitReact.FormattedDate, _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 _themeKitCore.AsyncResolvable.resolve(config.timezone);
return /*#__PURE__*/_react.default.createElement(_themeKitReact.FormattedTime, _extends({
timezone: timezone
}, props));
});
return _FormattedTime.apply(this, arguments);
}
return {
useIntl,
FormattedMessage,
FormattedDate,
FormattedTime
};
}
_IntlAdapter.connect = connect;
})(IntlAdapter || (exports.IntlAdapter = IntlAdapter = {}));