UNPKG

@prezly/theme-kit-nextjs

Version:

Data layer and utility library for developing Prezly themes with NextJS

49 lines (48 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.connect = connect; var _themeKitCore = require("@prezly/theme-kit-core"); 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 connect(createRouter, config) { function useRouting() { return _useRouting.apply(this, arguments); } function _useRouting() { _useRouting = _asyncToGenerator(function* () { var router = createRouter(); var { locales, defaultLocale, toLocaleSlug, origin } = yield _themeKitCore.AsyncResolvable.resolve(config); return { router, generateUrl(routeName) { var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return _themeKitCore.Routing.generateUrlFromPattern(router.routes[routeName].pattern, params, { defaultLocale, locales, toLocaleSlug }); }, generateAbsoluteUrl(routeName) { var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var url = _themeKitCore.Routing.generateUrlFromPattern(router.routes[routeName].pattern, params, { defaultLocale, locales, toLocaleSlug }); return "".concat(origin).concat(url); } }; }); return _useRouting.apply(this, arguments); } return { useRouting }; }