@prezly/theme-kit-core 7.1.0 → 8.0.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.
Files changed (250) hide show
  1. package/build/boilerplate.cjs +17 -0
  2. package/build/boilerplate.d.ts +8 -0
  3. package/build/boilerplate.mjs +9 -0
  4. package/build/constants.cjs +11 -0
  5. package/build/{utils/constants.d.ts → constants.d.ts} +2 -1
  6. package/build/constants.mjs +5 -0
  7. package/build/content-delivery/ContentDelivery.cjs +348 -0
  8. package/build/content-delivery/ContentDelivery.d.ts +8 -4
  9. package/build/content-delivery/ContentDelivery.mjs +342 -0
  10. package/build/content-delivery/cache/index.cjs +35 -0
  11. package/build/content-delivery/cache/index.d.ts +3 -0
  12. package/build/content-delivery/cache/index.mjs +3 -0
  13. package/build/content-delivery/cache/memory.cjs +65 -0
  14. package/build/content-delivery/cache/memory.d.ts +3 -0
  15. package/build/content-delivery/cache/memory.mjs +58 -0
  16. package/build/content-delivery/cache/memory.test.cjs +54 -0
  17. package/build/content-delivery/cache/memory.test.mjs +52 -0
  18. package/build/content-delivery/cache/stacked.cjs +32 -0
  19. package/build/content-delivery/cache/stacked.d.ts +2 -0
  20. package/build/content-delivery/cache/stacked.mjs +26 -0
  21. package/build/content-delivery/cache/type.cjs +1 -0
  22. package/build/content-delivery/cache/type.d.ts +8 -0
  23. package/build/content-delivery/cache/type.mjs +1 -0
  24. package/build/content-delivery/index.cjs +27 -0
  25. package/build/content-delivery/index.d.ts +2 -1
  26. package/build/content-delivery/index.mjs +2 -0
  27. package/build/environment.cjs +42 -0
  28. package/build/environment.d.ts +2 -0
  29. package/build/environment.mjs +36 -0
  30. package/build/galleries.cjs +38 -0
  31. package/build/galleries.d.ts +11 -0
  32. package/build/galleries.mjs +30 -0
  33. package/build/http/HttpClient.cjs +66 -0
  34. package/build/http/HttpClient.d.ts +20 -0
  35. package/build/http/HttpClient.mjs +59 -0
  36. package/build/http/index.cjs +10 -0
  37. package/build/http/index.d.ts +1 -0
  38. package/build/http/index.mjs +2 -0
  39. package/build/index.cjs +88 -0
  40. package/build/index.d.ts +15 -4
  41. package/build/index.mjs +26 -0
  42. package/build/intl/getLanguageDisplayName.cjs +37 -0
  43. package/build/intl/getLanguageDisplayName.d.ts +20 -0
  44. package/build/intl/getLanguageDisplayName.mjs +32 -0
  45. package/build/intl/getLanguageDisplayName.test.cjs +46 -0
  46. package/build/intl/getLanguageDisplayName.test.mjs +44 -0
  47. package/build/intl/index.cjs +12 -0
  48. package/build/intl/index.d.ts +1 -5
  49. package/build/intl/index.mjs +1 -0
  50. package/build/metadata/getAlternateLanguageLinks.cjs +76 -0
  51. package/build/{seo → metadata}/getAlternateLanguageLinks.d.ts +2 -2
  52. package/build/metadata/getAlternateLanguageLinks.mjs +72 -0
  53. package/build/metadata/getAlternateLanguageLinks.test.cjs +198 -0
  54. package/build/metadata/getAlternateLanguageLinks.test.mjs +196 -0
  55. package/build/metadata/index.cjs +12 -0
  56. package/build/metadata/index.d.ts +2 -0
  57. package/build/metadata/index.mjs +1 -0
  58. package/build/metadata/types.cjs +1 -0
  59. package/build/metadata/types.d.ts +6 -0
  60. package/build/metadata/types.mjs +1 -0
  61. package/build/newsrooms.cjs +36 -0
  62. package/build/newsrooms.d.ts +5 -0
  63. package/build/newsrooms.mjs +28 -0
  64. package/build/privacy-portal.cjs +28 -0
  65. package/build/privacy-portal.d.ts +9 -0
  66. package/build/privacy-portal.mjs +21 -0
  67. package/build/resolvable.cjs +38 -0
  68. package/build/resolvable.d.ts +71 -0
  69. package/build/resolvable.mjs +32 -0
  70. package/build/routing/Route.cjs +46 -0
  71. package/build/routing/Route.d.ts +37 -0
  72. package/build/routing/Route.mjs +40 -0
  73. package/build/routing/Router.cjs +51 -0
  74. package/build/routing/Router.d.ts +23 -0
  75. package/build/routing/Router.mjs +45 -0
  76. package/build/routing/Routing.cjs +24 -0
  77. package/build/routing/Routing.d.ts +1 -0
  78. package/build/routing/Routing.mjs +2 -0
  79. package/build/routing/UrlGenerator.cjs +13 -0
  80. package/build/routing/UrlGenerator.d.ts +39 -0
  81. package/build/routing/UrlGenerator.mjs +7 -0
  82. package/build/routing/index.cjs +24 -0
  83. package/build/routing/index.d.ts +4 -0
  84. package/build/routing/index.mjs +4 -0
  85. package/build/routing/types.cjs +1 -0
  86. package/build/routing/types.d.ts +14 -0
  87. package/build/routing/types.mjs +1 -0
  88. package/build/routing/utils/generateUrlFromPattern.cjs +52 -0
  89. package/build/routing/utils/generateUrlFromPattern.d.ts +12 -0
  90. package/build/routing/utils/generateUrlFromPattern.mjs +47 -0
  91. package/build/routing/utils/generateUrlFromPattern.test.cjs +44 -0
  92. package/build/routing/utils/generateUrlFromPattern.test.mjs +42 -0
  93. package/build/routing/utils/getShortestLocaleSlug.cjs +60 -0
  94. package/build/routing/utils/getShortestLocaleSlug.d.ts +11 -0
  95. package/build/routing/utils/getShortestLocaleSlug.mjs +53 -0
  96. package/build/routing/utils/getShortestLocaleSlug.test.cjs +37 -0
  97. package/build/routing/utils/getShortestLocaleSlug.test.mjs +35 -0
  98. package/build/routing/utils/index.cjs +40 -0
  99. package/build/routing/utils/index.d.ts +5 -0
  100. package/build/routing/utils/index.mjs +5 -0
  101. package/build/routing/utils/isNumberCode.cjs +12 -0
  102. package/build/routing/utils/isNumberCode.d.ts +4 -0
  103. package/build/routing/utils/isNumberCode.mjs +6 -0
  104. package/build/routing/utils/matchLocaleSlug.cjs +41 -0
  105. package/build/routing/utils/matchLocaleSlug.d.ts +15 -0
  106. package/build/routing/utils/matchLocaleSlug.mjs +34 -0
  107. package/build/routing/utils/matchLocaleSlug.test.cjs +43 -0
  108. package/build/routing/utils/matchLocaleSlug.test.mjs +40 -0
  109. package/build/routing/utils/normalizeUrl.cjs +9 -0
  110. package/build/routing/utils/normalizeUrl.d.ts +1 -0
  111. package/build/routing/utils/normalizeUrl.mjs +3 -0
  112. package/build/search.cjs +1 -0
  113. package/build/{types.d.ts → search.d.ts} +3 -3
  114. package/build/search.mjs +1 -0
  115. package/build/sitemap/build.cjs +33 -0
  116. package/build/sitemap/build.d.ts +6 -0
  117. package/build/sitemap/build.mjs +27 -0
  118. package/build/sitemap/generate.cjs +192 -0
  119. package/build/sitemap/generate.d.ts +37 -0
  120. package/build/sitemap/generate.mjs +183 -0
  121. package/build/sitemap/index.cjs +38 -0
  122. package/build/sitemap/index.d.ts +4 -0
  123. package/build/sitemap/index.mjs +3 -0
  124. package/build/sitemap/stringify.cjs +24 -0
  125. package/build/sitemap/stringify.d.ts +2 -0
  126. package/build/sitemap/stringify.mjs +18 -0
  127. package/build/sitemap/types.cjs +1 -0
  128. package/build/sitemap/types.d.ts +67 -0
  129. package/build/sitemap/types.mjs +1 -0
  130. package/build/uploads.cjs +14 -0
  131. package/build/{utils/getAssetsUrl.d.ts → uploads.d.ts} +1 -1
  132. package/build/uploads.mjs +8 -0
  133. package/build/uploads.test.cjs +10 -0
  134. package/build/uploads.test.mjs +8 -0
  135. package/package.json +23 -26
  136. package/build/content-delivery/ContentDelivery.js +0 -238
  137. package/build/content-delivery/ContentDelivery.js.map +0 -1
  138. package/build/content-delivery/index.js +0 -28
  139. package/build/content-delivery/index.js.map +0 -1
  140. package/build/data-fetching/api/index.d.ts +0 -1
  141. package/build/data-fetching/api/index.js +0 -6
  142. package/build/data-fetching/api/index.js.map +0 -1
  143. package/build/data-fetching/api/initContentDeliveryClient.d.ts +0 -4
  144. package/build/data-fetching/api/initContentDeliveryClient.js +0 -25
  145. package/build/data-fetching/api/initContentDeliveryClient.js.map +0 -1
  146. package/build/data-fetching/index.d.ts +0 -3
  147. package/build/data-fetching/index.js +0 -20
  148. package/build/data-fetching/index.js.map +0 -1
  149. package/build/data-fetching/lib/getAlgoliaSettings.d.ts +0 -4
  150. package/build/data-fetching/lib/getAlgoliaSettings.js +0 -21
  151. package/build/data-fetching/lib/getAlgoliaSettings.js.map +0 -1
  152. package/build/data-fetching/lib/getEnvVariables.d.ts +0 -4
  153. package/build/data-fetching/lib/getEnvVariables.js +0 -43
  154. package/build/data-fetching/lib/getEnvVariables.js.map +0 -1
  155. package/build/data-fetching/lib/index.d.ts +0 -3
  156. package/build/data-fetching/lib/index.js +0 -10
  157. package/build/data-fetching/lib/index.js.map +0 -1
  158. package/build/data-fetching/lib/isUuid.d.ts +0 -1
  159. package/build/data-fetching/lib/isUuid.js +0 -9
  160. package/build/data-fetching/lib/isUuid.js.map +0 -1
  161. package/build/data-fetching/types.d.ts +0 -13
  162. package/build/data-fetching/types.js +0 -3
  163. package/build/data-fetching/types.js.map +0 -1
  164. package/build/index.js +0 -21
  165. package/build/index.js.map +0 -1
  166. package/build/intl/getFallbackLocale.d.ts +0 -10
  167. package/build/intl/getFallbackLocale.js +0 -24
  168. package/build/intl/getFallbackLocale.js.map +0 -1
  169. package/build/intl/index.js +0 -27
  170. package/build/intl/index.js.map +0 -1
  171. package/build/intl/languages.d.ts +0 -57
  172. package/build/intl/languages.js +0 -191
  173. package/build/intl/languages.js.map +0 -1
  174. package/build/intl/locale.d.ts +0 -11
  175. package/build/intl/locale.js +0 -41
  176. package/build/intl/locale.js.map +0 -1
  177. package/build/intl/localeConfig.d.ts +0 -2
  178. package/build/intl/localeConfig.js +0 -22
  179. package/build/intl/localeConfig.js.map +0 -1
  180. package/build/intl/localeList.d.ts +0 -2
  181. package/build/intl/localeList.js +0 -114
  182. package/build/intl/localeList.js.map +0 -1
  183. package/build/intl/localeObject.d.ts +0 -51
  184. package/build/intl/localeObject.js +0 -98
  185. package/build/intl/localeObject.js.map +0 -1
  186. package/build/seo/getAlternateLanguageLinks.js +0 -85
  187. package/build/seo/getAlternateLanguageLinks.js.map +0 -1
  188. package/build/seo/index.d.ts +0 -2
  189. package/build/seo/index.js +0 -19
  190. package/build/seo/index.js.map +0 -1
  191. package/build/seo/types.d.ts +0 -4
  192. package/build/seo/types.js +0 -3
  193. package/build/seo/types.js.map +0 -1
  194. package/build/seo/utils/bindLanguagesWithLocales.d.ts +0 -11
  195. package/build/seo/utils/bindLanguagesWithLocales.js +0 -23
  196. package/build/seo/utils/bindLanguagesWithLocales.js.map +0 -1
  197. package/build/seo/utils/createAlternateLanguageLink.d.ts +0 -5
  198. package/build/seo/utils/createAlternateLanguageLink.js +0 -15
  199. package/build/seo/utils/createAlternateLanguageLink.js.map +0 -1
  200. package/build/seo/utils/index.d.ts +0 -2
  201. package/build/seo/utils/index.js +0 -8
  202. package/build/seo/utils/index.js.map +0 -1
  203. package/build/server.d.ts +0 -2
  204. package/build/server.js +0 -21
  205. package/build/server.js.map +0 -1
  206. package/build/types.js +0 -3
  207. package/build/types.js.map +0 -1
  208. package/build/utils/assertServerEnv.d.ts +0 -1
  209. package/build/utils/assertServerEnv.js +0 -10
  210. package/build/utils/assertServerEnv.js.map +0 -1
  211. package/build/utils/boilerplate.d.ts +0 -8
  212. package/build/utils/boilerplate.js +0 -27
  213. package/build/utils/boilerplate.js.map +0 -1
  214. package/build/utils/constants.js +0 -8
  215. package/build/utils/constants.js.map +0 -1
  216. package/build/utils/getAssetsUrl.js +0 -13
  217. package/build/utils/getAssetsUrl.js.map +0 -1
  218. package/build/utils/getDataRequestLink.d.ts +0 -3
  219. package/build/utils/getDataRequestLink.js +0 -12
  220. package/build/utils/getDataRequestLink.js.map +0 -1
  221. package/build/utils/getGalleryThumbnail.d.ts +0 -2
  222. package/build/utils/getGalleryThumbnail.js +0 -15
  223. package/build/utils/getGalleryThumbnail.js.map +0 -1
  224. package/build/utils/getLocalizedCategoryData.d.ts +0 -12
  225. package/build/utils/getLocalizedCategoryData.js +0 -34
  226. package/build/utils/getLocalizedCategoryData.js.map +0 -1
  227. package/build/utils/getNewsroomLogoUrl.d.ts +0 -5
  228. package/build/utils/getNewsroomLogoUrl.js +0 -30
  229. package/build/utils/getNewsroomLogoUrl.js.map +0 -1
  230. package/build/utils/getPrivacyPortalUrl.d.ts +0 -8
  231. package/build/utils/getPrivacyPortalUrl.js +0 -13
  232. package/build/utils/getPrivacyPortalUrl.js.map +0 -1
  233. package/build/utils/getStoryPublicationDate.d.ts +0 -3
  234. package/build/utils/getStoryPublicationDate.js +0 -14
  235. package/build/utils/getStoryPublicationDate.js.map +0 -1
  236. package/build/utils/getUploadcareGroupUrl.d.ts +0 -8
  237. package/build/utils/getUploadcareGroupUrl.js +0 -17
  238. package/build/utils/getUploadcareGroupUrl.js.map +0 -1
  239. package/build/utils/index.d.ts +0 -14
  240. package/build/utils/index.js +0 -31
  241. package/build/utils/index.js.map +0 -1
  242. package/build/utils/isEmbargoStory.d.ts +0 -6
  243. package/build/utils/isEmbargoStory.js +0 -9
  244. package/build/utils/isEmbargoStory.js.map +0 -1
  245. package/build/utils/isGalleryEmpty.d.ts +0 -2
  246. package/build/utils/isGalleryEmpty.js +0 -8
  247. package/build/utils/isGalleryEmpty.js.map +0 -1
  248. package/build/utils/sdkHelpers.d.ts +0 -32
  249. package/build/utils/sdkHelpers.js +0 -42
  250. package/build/utils/sdkHelpers.js.map +0 -1
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Route", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _Route.Route;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Router", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _Router.Router;
16
+ }
17
+ });
18
+ exports.Routing = void 0;
19
+ var _Route = require("./Route.cjs");
20
+ var _Router = require("./Router.cjs");
21
+ var _Routing = _interopRequireWildcard(require("./Routing.cjs"));
22
+ exports.Routing = _Routing;
23
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -0,0 +1,4 @@
1
+ export { Route } from './Route';
2
+ export { Router, type RoutesMap } from './Router';
3
+ export * as Routing from './Routing';
4
+ export type { UrlGenerator } from './UrlGenerator';
@@ -0,0 +1,4 @@
1
+ export { Route } from "./Route.mjs";
2
+ export { Router } from "./Router.mjs";
3
+ import * as _Routing from "./Routing.mjs";
4
+ export { _Routing as Routing };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,14 @@
1
+ export type Awaitable<T> = T | Promise<T> | PromiseLike<T>;
2
+ export type ExtractPathParams<T extends string> = T extends `${infer _Start}(/:${infer Param})/${infer Rest}` ? {
3
+ [k in Param]?: string;
4
+ } & ExtractPathParams<Rest> : T extends `${infer _Start}(:${infer Param})/${infer Rest}` ? {
5
+ [k in Param]?: string;
6
+ } & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
7
+ [k in Param]: string;
8
+ } & ExtractPathParams<Rest> : T extends `${infer _Start}(/:${infer Param})` ? {
9
+ [k in Param]?: string;
10
+ } : T extends `${infer _Start}(:${infer Param})` ? {
11
+ [k in Param]?: string;
12
+ } : T extends `${infer _Start}:${infer Param}` ? {
13
+ [k in Param]: string;
14
+ } : {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateUrlFromPattern = generateUrlFromPattern;
7
+ var _omitUndefined = require("@technically/omit-undefined");
8
+ var _urlPattern = _interopRequireDefault(require("url-pattern"));
9
+ var _getShortestLocaleSlug = require("./getShortestLocaleSlug.cjs");
10
+ var _normalizeUrl = require("./normalizeUrl.cjs");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
16
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable @typescript-eslint/no-use-before-define */
17
+ var CACHE = new Map();
18
+ function toUrlPattern(pattern) {
19
+ var cached = CACHE.get(pattern);
20
+ if (cached) return cached;
21
+ var urlPattern = new _urlPattern.default(pattern);
22
+ CACHE.set(pattern, urlPattern);
23
+ return urlPattern;
24
+ }
25
+ function generateUrlFromPattern(pattern) {
26
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
27
+ var context = arguments.length > 2 ? arguments[2] : undefined;
28
+ var urlPattern = toUrlPattern(pattern);
29
+ if (context) {
30
+ var {
31
+ localeCode
32
+ } = params;
33
+ var localeSlug = getLocaleSlug(params, context);
34
+ return (0, _normalizeUrl.normalizeUrl)(urlPattern.stringify((0, _omitUndefined.omitUndefined)(_objectSpread(_objectSpread({}, params), {}, {
35
+ localeCode,
36
+ localeSlug
37
+ }))));
38
+ }
39
+ return (0, _normalizeUrl.normalizeUrl)(urlPattern.stringify((0, _omitUndefined.omitUndefined)(params)));
40
+ }
41
+ function getLocaleSlug(params, context) {
42
+ if (params.localeSlug) {
43
+ return params.localeSlug;
44
+ }
45
+ if (params.localeCode) {
46
+ var {
47
+ toLocaleSlug = _getShortestLocaleSlug.getShortestLocaleSlug
48
+ } = context;
49
+ return toLocaleSlug(params.localeCode, context) || '';
50
+ }
51
+ return '';
52
+ }
@@ -0,0 +1,12 @@
1
+ import type { Locale } from '@prezly/theme-kit-intl';
2
+ export interface Context {
3
+ defaultLocale: Locale.Code;
4
+ locales: Locale.Code[];
5
+ toLocaleSlug?: (locale: Locale.Code, context: Pick<Context, 'defaultLocale' | 'locales'>) => Locale.UrlSlug;
6
+ }
7
+ export type Params = Record<string, string | undefined | null> & ({
8
+ localeCode?: Locale.Code;
9
+ } | {
10
+ localeSlug?: Locale.AnySlug;
11
+ });
12
+ export declare function generateUrlFromPattern(pattern: `/${string}`, params?: Params, context?: Context): `/${string}`;
@@ -0,0 +1,47 @@
1
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
5
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
+ /* eslint-disable @typescript-eslint/no-use-before-define */
7
+
8
+ import { omitUndefined } from '@technically/omit-undefined';
9
+ import UrlPattern from 'url-pattern';
10
+ import { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
11
+ import { normalizeUrl } from "./normalizeUrl.mjs";
12
+ var CACHE = new Map();
13
+ function toUrlPattern(pattern) {
14
+ var cached = CACHE.get(pattern);
15
+ if (cached) return cached;
16
+ var urlPattern = new UrlPattern(pattern);
17
+ CACHE.set(pattern, urlPattern);
18
+ return urlPattern;
19
+ }
20
+ export function generateUrlFromPattern(pattern) {
21
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
22
+ var context = arguments.length > 2 ? arguments[2] : undefined;
23
+ var urlPattern = toUrlPattern(pattern);
24
+ if (context) {
25
+ var {
26
+ localeCode
27
+ } = params;
28
+ var localeSlug = getLocaleSlug(params, context);
29
+ return normalizeUrl(urlPattern.stringify(omitUndefined(_objectSpread(_objectSpread({}, params), {}, {
30
+ localeCode,
31
+ localeSlug
32
+ }))));
33
+ }
34
+ return normalizeUrl(urlPattern.stringify(omitUndefined(params)));
35
+ }
36
+ function getLocaleSlug(params, context) {
37
+ if (params.localeSlug) {
38
+ return params.localeSlug;
39
+ }
40
+ if (params.localeCode) {
41
+ var {
42
+ toLocaleSlug = getShortestLocaleSlug
43
+ } = context;
44
+ return toLocaleSlug(params.localeCode, context) || '';
45
+ }
46
+ return '';
47
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _generateUrlFromPattern = require("./generateUrlFromPattern.cjs");
4
+ describe('generateUrlFromPattern', () => {
5
+ it('should generate a URL (without context)', () => {
6
+ var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/:localeCode/media', {
7
+ localeCode: 'en'
8
+ });
9
+ expect(href).toBe('/en/media');
10
+ });
11
+ it('should generate a URL with optional variables (without context)', () => {
12
+ var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
13
+ localeSlug: ''
14
+ });
15
+ expect(href).toBe('/media');
16
+ });
17
+ it('should generate a URL based on the current locale', () => {
18
+ var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
19
+ localeCode: 'fr'
20
+ }, {
21
+ defaultLocale: 'en',
22
+ locales: ['en', 'nl', 'fr']
23
+ });
24
+ expect(href).toBe('/fr/media');
25
+ });
26
+ it('should generate a homepage URL based on the current locale', () => {
27
+ var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
28
+ localeCode: 'en'
29
+ }, {
30
+ defaultLocale: 'en',
31
+ locales: ['en', 'nl', 'fr']
32
+ });
33
+ expect(href).toBe('/media');
34
+ });
35
+ it('should generate a shortest possible locale slug', () => {
36
+ var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
37
+ localeCode: 'nl_BE'
38
+ }, {
39
+ defaultLocale: 'en_US',
40
+ locales: ['en_US', 'nl_BE', 'fr_FR']
41
+ });
42
+ expect(href).toBe('/nl/media');
43
+ });
44
+ });
@@ -0,0 +1,42 @@
1
+ import { generateUrlFromPattern } from "./generateUrlFromPattern.mjs";
2
+ describe('generateUrlFromPattern', () => {
3
+ it('should generate a URL (without context)', () => {
4
+ var href = generateUrlFromPattern('/:localeCode/media', {
5
+ localeCode: 'en'
6
+ });
7
+ expect(href).toBe('/en/media');
8
+ });
9
+ it('should generate a URL with optional variables (without context)', () => {
10
+ var href = generateUrlFromPattern('/(:localeSlug/)media', {
11
+ localeSlug: ''
12
+ });
13
+ expect(href).toBe('/media');
14
+ });
15
+ it('should generate a URL based on the current locale', () => {
16
+ var href = generateUrlFromPattern('/(:localeSlug/)media', {
17
+ localeCode: 'fr'
18
+ }, {
19
+ defaultLocale: 'en',
20
+ locales: ['en', 'nl', 'fr']
21
+ });
22
+ expect(href).toBe('/fr/media');
23
+ });
24
+ it('should generate a homepage URL based on the current locale', () => {
25
+ var href = generateUrlFromPattern('/(:localeSlug/)media', {
26
+ localeCode: 'en'
27
+ }, {
28
+ defaultLocale: 'en',
29
+ locales: ['en', 'nl', 'fr']
30
+ });
31
+ expect(href).toBe('/media');
32
+ });
33
+ it('should generate a shortest possible locale slug', () => {
34
+ var href = generateUrlFromPattern('/(:localeSlug/)media', {
35
+ localeCode: 'nl_BE'
36
+ }, {
37
+ defaultLocale: 'en_US',
38
+ locales: ['en_US', 'nl_BE', 'fr_FR']
39
+ });
40
+ expect(href).toBe('/nl/media');
41
+ });
42
+ });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getShortestLocaleSlug = getShortestLocaleSlug;
7
+ var _themeKitIntl = require("@prezly/theme-kit-intl");
8
+ var _isNumberCode = require("./isNumberCode.cjs");
9
+ /* eslint-disable @typescript-eslint/no-use-before-define */
10
+
11
+ /**
12
+ * Get the shortest locale code possible from full locale code
13
+ * First: try shorting to neutral language code (there should be no locales with the same language code)
14
+ * Then: try shorting to region code (there should be no locales with the same region code)
15
+ * Finally: return the original locale code (shorting is not possible)
16
+ */
17
+ function getShortestLocaleSlug(locale, context) {
18
+ var _ref, _getUnambiguousLangCo;
19
+ var {
20
+ code: localeCode,
21
+ lang: langCode,
22
+ region: regionCode,
23
+ slug: localeSlug
24
+ } = _themeKitIntl.Locale.from(locale);
25
+
26
+ // If it's a default locale, return false (no locale needed in URL)
27
+ if (localeCode === context.defaultLocale) {
28
+ return false;
29
+ }
30
+ var shortened = // Try shortening to neutral language code
31
+ (_ref = (_getUnambiguousLangCo = getUnambiguousLangCode(langCode, context)) !== null && _getUnambiguousLangCo !== void 0 ? _getUnambiguousLangCo :
32
+ // Try shortening to region code
33
+ getUnambiguousRegionCode(regionCode, context)) !== null && _ref !== void 0 ? _ref :
34
+ // Return the original (exact) code if shortening is not possible
35
+ localeSlug;
36
+ return shortened.toLowerCase();
37
+ }
38
+ function getUnambiguousLangCode(langCode, context) {
39
+ var candidates = context.locales.filter(code => _themeKitIntl.Locale.isLanguageCode(code, langCode));
40
+ if (candidates.length === 1) {
41
+ return langCode;
42
+ }
43
+ return undefined;
44
+ }
45
+ function getUnambiguousRegionCode(regionCode, context) {
46
+ if (!regionCode) {
47
+ return undefined;
48
+ }
49
+ if ((0, _isNumberCode.isNumberCode)(regionCode)) {
50
+ // We don't want just numbers in our region code
51
+ return undefined;
52
+ }
53
+ var candidates = context.locales.filter(locale => _themeKitIntl.Locale.isRegionCode(locale, regionCode));
54
+ // Prevent collision with neutral language codes
55
+ var collisions = context.locales.filter(locale => _themeKitIntl.Locale.isLanguageCode(locale, regionCode.toLowerCase()));
56
+ if (candidates.length === 1 && collisions.length === 0) {
57
+ return regionCode;
58
+ }
59
+ return undefined;
60
+ }
@@ -0,0 +1,11 @@
1
+ import { Locale } from '@prezly/theme-kit-intl';
2
+ /**
3
+ * Get the shortest locale code possible from full locale code
4
+ * First: try shorting to neutral language code (there should be no locales with the same language code)
5
+ * Then: try shorting to region code (there should be no locales with the same region code)
6
+ * Finally: return the original locale code (shorting is not possible)
7
+ */
8
+ export declare function getShortestLocaleSlug(locale: Locale.Code, context: {
9
+ locales: Locale.Code[];
10
+ defaultLocale: Locale.Code;
11
+ }): Locale.AnySlug | false;
@@ -0,0 +1,53 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
2
+ import { Locale } from '@prezly/theme-kit-intl';
3
+ import { isNumberCode } from "./isNumberCode.mjs";
4
+ /**
5
+ * Get the shortest locale code possible from full locale code
6
+ * First: try shorting to neutral language code (there should be no locales with the same language code)
7
+ * Then: try shorting to region code (there should be no locales with the same region code)
8
+ * Finally: return the original locale code (shorting is not possible)
9
+ */
10
+ export function getShortestLocaleSlug(locale, context) {
11
+ var _ref, _getUnambiguousLangCo;
12
+ var {
13
+ code: localeCode,
14
+ lang: langCode,
15
+ region: regionCode,
16
+ slug: localeSlug
17
+ } = Locale.from(locale);
18
+
19
+ // If it's a default locale, return false (no locale needed in URL)
20
+ if (localeCode === context.defaultLocale) {
21
+ return false;
22
+ }
23
+ var shortened = // Try shortening to neutral language code
24
+ (_ref = (_getUnambiguousLangCo = getUnambiguousLangCode(langCode, context)) !== null && _getUnambiguousLangCo !== void 0 ? _getUnambiguousLangCo :
25
+ // Try shortening to region code
26
+ getUnambiguousRegionCode(regionCode, context)) !== null && _ref !== void 0 ? _ref :
27
+ // Return the original (exact) code if shortening is not possible
28
+ localeSlug;
29
+ return shortened.toLowerCase();
30
+ }
31
+ function getUnambiguousLangCode(langCode, context) {
32
+ var candidates = context.locales.filter(code => Locale.isLanguageCode(code, langCode));
33
+ if (candidates.length === 1) {
34
+ return langCode;
35
+ }
36
+ return undefined;
37
+ }
38
+ function getUnambiguousRegionCode(regionCode, context) {
39
+ if (!regionCode) {
40
+ return undefined;
41
+ }
42
+ if (isNumberCode(regionCode)) {
43
+ // We don't want just numbers in our region code
44
+ return undefined;
45
+ }
46
+ var candidates = context.locales.filter(locale => Locale.isRegionCode(locale, regionCode));
47
+ // Prevent collision with neutral language codes
48
+ var collisions = context.locales.filter(locale => Locale.isLanguageCode(locale, regionCode.toLowerCase()));
49
+ if (candidates.length === 1 && collisions.length === 0) {
50
+ return regionCode;
51
+ }
52
+ return undefined;
53
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _languages = require("../../__mocks__/languages.cjs");
4
+ var _getShortestLocaleSlug = require("./getShortestLocaleSlug.cjs");
5
+ var locales = Object.values(_languages.LANGUAGES).map(lang => lang.code);
6
+ var defaultLocale = Object.values(_languages.LANGUAGES).filter(lang => lang.is_default).map(lang => lang.code)[0];
7
+ var context = {
8
+ locales,
9
+ defaultLocale
10
+ };
11
+ function without(codes, exclude) {
12
+ return codes.filter(code => code !== exclude);
13
+ }
14
+ describe('getShortestLocaleSlug', () => {
15
+ it('returns false for default language', () => {
16
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('en', context)).toBe(false);
17
+ });
18
+ it('returns neutral language code if it is the only culture with that language', () => {
19
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('es_ES', {
20
+ locales: without(locales, 'es_419'),
21
+ defaultLocale
22
+ })).toBe('es');
23
+ });
24
+ it('returns region code if it is the only culture with that region', () => {
25
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('en_US', context)).toBe('us');
26
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('en_GB', context)).toBe('gb');
27
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('nl_NL', context)).toBe('nl-nl'); // cannot use `nl`, as it collides with language code
28
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('fr', context)).toBe('fr');
29
+ });
30
+ it('returns full code if it can not be shortened', () => {
31
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('fr_BE', context)).toBe('fr-be');
32
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('nl_BE', context)).toBe('nl-be');
33
+ });
34
+ it('returns full code when trying to shorten to region code for es-419', () => {
35
+ expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('es_419', context)).toBe('es-419');
36
+ });
37
+ });
@@ -0,0 +1,35 @@
1
+ import { LANGUAGES } from "../../__mocks__/languages.mjs";
2
+ import { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
3
+ var locales = Object.values(LANGUAGES).map(lang => lang.code);
4
+ var defaultLocale = Object.values(LANGUAGES).filter(lang => lang.is_default).map(lang => lang.code)[0];
5
+ var context = {
6
+ locales,
7
+ defaultLocale
8
+ };
9
+ function without(codes, exclude) {
10
+ return codes.filter(code => code !== exclude);
11
+ }
12
+ describe('getShortestLocaleSlug', () => {
13
+ it('returns false for default language', () => {
14
+ expect(getShortestLocaleSlug('en', context)).toBe(false);
15
+ });
16
+ it('returns neutral language code if it is the only culture with that language', () => {
17
+ expect(getShortestLocaleSlug('es_ES', {
18
+ locales: without(locales, 'es_419'),
19
+ defaultLocale
20
+ })).toBe('es');
21
+ });
22
+ it('returns region code if it is the only culture with that region', () => {
23
+ expect(getShortestLocaleSlug('en_US', context)).toBe('us');
24
+ expect(getShortestLocaleSlug('en_GB', context)).toBe('gb');
25
+ expect(getShortestLocaleSlug('nl_NL', context)).toBe('nl-nl'); // cannot use `nl`, as it collides with language code
26
+ expect(getShortestLocaleSlug('fr', context)).toBe('fr');
27
+ });
28
+ it('returns full code if it can not be shortened', () => {
29
+ expect(getShortestLocaleSlug('fr_BE', context)).toBe('fr-be');
30
+ expect(getShortestLocaleSlug('nl_BE', context)).toBe('nl-be');
31
+ });
32
+ it('returns full code when trying to shorten to region code for es-419', () => {
33
+ expect(getShortestLocaleSlug('es_419', context)).toBe('es-419');
34
+ });
35
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "generateUrlFromPattern", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _generateUrlFromPattern.generateUrlFromPattern;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getShortestLocaleSlug", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _getShortestLocaleSlug.getShortestLocaleSlug;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "isNumberCode", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _isNumberCode.isNumberCode;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "matchLocaleSlug", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _matchLocaleSlug.matchLocaleSlug;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "normalizeUrl", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _normalizeUrl.normalizeUrl;
34
+ }
35
+ });
36
+ var _generateUrlFromPattern = require("./generateUrlFromPattern.cjs");
37
+ var _getShortestLocaleSlug = require("./getShortestLocaleSlug.cjs");
38
+ var _matchLocaleSlug = require("./matchLocaleSlug.cjs");
39
+ var _isNumberCode = require("./isNumberCode.cjs");
40
+ var _normalizeUrl = require("./normalizeUrl.cjs");
@@ -0,0 +1,5 @@
1
+ export { generateUrlFromPattern } from './generateUrlFromPattern';
2
+ export { getShortestLocaleSlug } from './getShortestLocaleSlug';
3
+ export { matchLocaleSlug } from './matchLocaleSlug';
4
+ export { isNumberCode } from './isNumberCode';
5
+ export { normalizeUrl } from './normalizeUrl';
@@ -0,0 +1,5 @@
1
+ export { generateUrlFromPattern } from "./generateUrlFromPattern.mjs";
2
+ export { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
3
+ export { matchLocaleSlug } from "./matchLocaleSlug.mjs";
4
+ export { isNumberCode } from "./isNumberCode.mjs";
5
+ export { normalizeUrl } from "./normalizeUrl.mjs";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isNumberCode = isNumberCode;
7
+ /**
8
+ * Get newsroom notifications for the selected locale
9
+ */
10
+ function isNumberCode(code) {
11
+ return !Number.isNaN(Number(code));
12
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Get newsroom notifications for the selected locale
3
+ */
4
+ export declare function isNumberCode(code: string): boolean;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Get newsroom notifications for the selected locale
3
+ */
4
+ export function isNumberCode(code) {
5
+ return !Number.isNaN(Number(code));
6
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.matchLocaleSlug = matchLocaleSlug;
7
+ var _themeKitIntl = require("@prezly/theme-kit-intl");
8
+ var _isNumberCode = require("./isNumberCode.cjs");
9
+ /* eslint-disable @typescript-eslint/no-use-before-define */
10
+
11
+ /**
12
+ * Match the requested locale slug against the enabled locales.
13
+ * The enabled locales have to be provided in the order of importance:
14
+ * default first, then locales with public stories, then the rest.
15
+ *
16
+ * The logic is reversed from `getShortestLocaleSlug`, so that it "unwraps" the possible variants.
17
+ * @see {getShortestLocaleSlug()}
18
+ *
19
+ * The order of checks is:
20
+ * - exact locale slug match
21
+ * - match by language code
22
+ * - match by region code
23
+ */
24
+ function matchLocaleSlug(slug, locales) {
25
+ var _ref, _ref2, _matchByExactLocaleSl;
26
+ return (_ref = (_ref2 = (_matchByExactLocaleSl = matchByExactLocaleSlug(slug, locales)) !== null && _matchByExactLocaleSl !== void 0 ? _matchByExactLocaleSl : matchByLangSlug(slug, locales)) !== null && _ref2 !== void 0 ? _ref2 : matchByRegionSlug(slug, locales)) !== null && _ref !== void 0 ? _ref : undefined;
27
+ }
28
+ function matchByExactLocaleSlug(slug, locales) {
29
+ if (!_themeKitIntl.Locale.isValid(slug)) return undefined;
30
+ var locale = _themeKitIntl.Locale.from(slug);
31
+ return locales.find(localeCode => localeCode === locale.code);
32
+ }
33
+ function matchByLangSlug(slug, locales) {
34
+ return locales.find(localeCode => _themeKitIntl.Locale.isLanguageCode(localeCode, slug.toLowerCase()));
35
+ }
36
+ function matchByRegionSlug(slug, locales) {
37
+ if (!slug || (0, _isNumberCode.isNumberCode)(slug)) {
38
+ return undefined;
39
+ }
40
+ return locales.find(localeCode => _themeKitIntl.Locale.isRegionCode(localeCode, slug.toUpperCase()));
41
+ }
@@ -0,0 +1,15 @@
1
+ import { Locale } from '@prezly/theme-kit-intl';
2
+ /**
3
+ * Match the requested locale slug against the enabled locales.
4
+ * The enabled locales have to be provided in the order of importance:
5
+ * default first, then locales with public stories, then the rest.
6
+ *
7
+ * The logic is reversed from `getShortestLocaleSlug`, so that it "unwraps" the possible variants.
8
+ * @see {getShortestLocaleSlug()}
9
+ *
10
+ * The order of checks is:
11
+ * - exact locale slug match
12
+ * - match by language code
13
+ * - match by region code
14
+ */
15
+ export declare function matchLocaleSlug(slug: Locale.AnySlug, locales: Locale.Code[]): Locale.Code | undefined;
@@ -0,0 +1,34 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
2
+ import { Locale } from '@prezly/theme-kit-intl';
3
+ import { isNumberCode } from "./isNumberCode.mjs";
4
+ /**
5
+ * Match the requested locale slug against the enabled locales.
6
+ * The enabled locales have to be provided in the order of importance:
7
+ * default first, then locales with public stories, then the rest.
8
+ *
9
+ * The logic is reversed from `getShortestLocaleSlug`, so that it "unwraps" the possible variants.
10
+ * @see {getShortestLocaleSlug()}
11
+ *
12
+ * The order of checks is:
13
+ * - exact locale slug match
14
+ * - match by language code
15
+ * - match by region code
16
+ */
17
+ export function matchLocaleSlug(slug, locales) {
18
+ var _ref, _ref2, _matchByExactLocaleSl;
19
+ return (_ref = (_ref2 = (_matchByExactLocaleSl = matchByExactLocaleSlug(slug, locales)) !== null && _matchByExactLocaleSl !== void 0 ? _matchByExactLocaleSl : matchByLangSlug(slug, locales)) !== null && _ref2 !== void 0 ? _ref2 : matchByRegionSlug(slug, locales)) !== null && _ref !== void 0 ? _ref : undefined;
20
+ }
21
+ function matchByExactLocaleSlug(slug, locales) {
22
+ if (!Locale.isValid(slug)) return undefined;
23
+ var locale = Locale.from(slug);
24
+ return locales.find(localeCode => localeCode === locale.code);
25
+ }
26
+ function matchByLangSlug(slug, locales) {
27
+ return locales.find(localeCode => Locale.isLanguageCode(localeCode, slug.toLowerCase()));
28
+ }
29
+ function matchByRegionSlug(slug, locales) {
30
+ if (!slug || isNumberCode(slug)) {
31
+ return undefined;
32
+ }
33
+ return locales.find(localeCode => Locale.isRegionCode(localeCode, slug.toUpperCase()));
34
+ }