@prezly/theme-kit-nextjs 1.1.0 → 1.1.4
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.
- package/README.md +195 -3
- package/build/adapter-nextjs/getBasePageProps.js +59 -9
- package/build/adapter-nextjs/getBasePageProps.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +16 -8
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/data-fetching/api/PrezlyApi.js +286 -127
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/getPrezlyApi.js +4 -4
- package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
- package/build/data-fetching/api/languages.js +62 -32
- package/build/data-fetching/api/languages.js.map +1 -1
- package/build/data-fetching/api/queries.js +44 -18
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/getAssetsUrl.js +2 -2
- package/build/data-fetching/getAssetsUrl.js.map +1 -1
- package/build/data-fetching/getLocalizedCategoryData.js +23 -12
- package/build/data-fetching/getLocalizedCategoryData.js.map +1 -1
- package/build/data-fetching/getNewsroomLogoUrl.js +4 -3
- package/build/data-fetching/getNewsroomLogoUrl.js.map +1 -1
- package/build/data-fetching/getPrivacyPortalUrl.js +2 -2
- package/build/data-fetching/getPrivacyPortalUrl.js.map +1 -1
- package/build/data-fetching/{getStoryPublicationDate.jsx → getStoryPublicationDate.js} +2 -2
- package/build/data-fetching/getStoryPublicationDate.js.map +1 -0
- package/build/data-fetching/getUploadcareGroupUrl.js +2 -2
- package/build/data-fetching/getUploadcareGroupUrl.js.map +1 -1
- package/build/data-fetching/lib/getAlgoliaSettings.js +6 -6
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
- package/build/data-fetching/lib/getEnvVariables.js +24 -13
- package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
- package/build/intl/lang.js +6 -3
- package/build/intl/lang.js.map +1 -1
- package/build/intl/locale.js +14 -14
- package/build/intl/locale.js.map +1 -1
- package/build/intl/localeConfig.js +28 -7
- package/build/intl/localeConfig.js.map +1 -1
- package/build/intl/localeObject.js +41 -29
- package/build/intl/localeObject.js.map +1 -1
- package/build/newsroom-context/context.d.ts +4 -7
- package/build/newsroom-context/context.js +44 -0
- package/build/newsroom-context/context.js.map +1 -0
- package/build/newsroom-context/hooks/useAlgoliaSettings.js +3 -3
- package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
- package/build/newsroom-context/hooks/useCategories.js +3 -3
- package/build/newsroom-context/hooks/useCategories.js.map +1 -1
- package/build/newsroom-context/hooks/useCompanyInformation.js +3 -3
- package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.js +3 -3
- package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +9 -9
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +17 -12
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/newsroom-context/hooks/useLanguages.js +3 -3
- package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroom.js +3 -3
- package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
- package/build/newsroom-context/hooks/useNewsroomContext.js +4 -4
- package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
- package/build/newsroom-context/hooks/useSelectedCategory.js +3 -3
- package/build/newsroom-context/hooks/useSelectedCategory.js.map +1 -1
- package/build/newsroom-context/hooks/useSelectedStory.d.ts +1 -1
- package/build/newsroom-context/hooks/useSelectedStory.js +3 -3
- package/build/newsroom-context/hooks/useSelectedStory.js.map +1 -1
- package/build/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/data-fetching/api/queries.ts +2 -2
- package/src/newsroom-context/context.tsx +8 -8
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +2 -2
- package/src/types.ts +2 -1
- package/build/data-fetching/getStoryPublicationDate.jsx.map +0 -1
- package/build/newsroom-context/context.jsx +0 -26
- package/build/newsroom-context/context.jsx.map +0 -1
package/build/intl/locale.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLocaleDirection = exports.getRedirectToCanonicalLocale = exports.getSupportedLocaleIsoCode = exports.DUMMY_DEFAULT_LOCALE = exports.DEFAULT_LOCALE = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
var querystring_1 = require("querystring");
|
|
5
|
+
var localeObject_1 = require("./localeObject");
|
|
6
6
|
exports.DEFAULT_LOCALE = 'en';
|
|
7
7
|
exports.DUMMY_DEFAULT_LOCALE = 'qps-ploc';
|
|
8
|
-
|
|
8
|
+
var SUPPORTED_LOCALES = [
|
|
9
9
|
'af',
|
|
10
10
|
'ar',
|
|
11
11
|
'az',
|
|
@@ -54,13 +54,13 @@ const SUPPORTED_LOCALES = [
|
|
|
54
54
|
'zh-TW',
|
|
55
55
|
];
|
|
56
56
|
function getSupportedLocaleIsoCode(locale) {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
var localeIsoCode = locale.toHyphenCode();
|
|
58
|
+
var isSupportedLocale = localeIsoCode.length >= 2 && SUPPORTED_LOCALES.includes(localeIsoCode);
|
|
59
59
|
if (isSupportedLocale) {
|
|
60
60
|
return localeIsoCode;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
var language = localeIsoCode.slice(0, 2);
|
|
63
|
+
var isSupportedLanguage = SUPPORTED_LOCALES.includes(language);
|
|
64
64
|
if (isSupportedLanguage) {
|
|
65
65
|
return language;
|
|
66
66
|
}
|
|
@@ -68,20 +68,20 @@ function getSupportedLocaleIsoCode(locale) {
|
|
|
68
68
|
}
|
|
69
69
|
exports.getSupportedLocaleIsoCode = getSupportedLocaleIsoCode;
|
|
70
70
|
function getRedirectToCanonicalLocale(basePageProps, nextLocaleIsoCode, redirectPath, query) {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
var shortestLocaleCode = basePageProps.shortestLocaleCode;
|
|
72
|
+
var shortestLocaleSlug = shortestLocaleCode
|
|
73
73
|
? localeObject_1.LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug()
|
|
74
74
|
: shortestLocaleCode;
|
|
75
75
|
if (nextLocaleIsoCode === exports.DUMMY_DEFAULT_LOCALE) {
|
|
76
76
|
return undefined;
|
|
77
77
|
}
|
|
78
78
|
if (shortestLocaleSlug !== nextLocaleIsoCode) {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
var prefixedPath = redirectPath && !redirectPath.startsWith('/') ? "/".concat(redirectPath) : redirectPath;
|
|
80
|
+
var urlQuery = query ? "?".concat((0, querystring_1.stringify)(query)) : '';
|
|
81
81
|
return {
|
|
82
82
|
destination: shortestLocaleSlug
|
|
83
|
-
?
|
|
84
|
-
:
|
|
83
|
+
? "/".concat(shortestLocaleSlug).concat(prefixedPath).concat(urlQuery)
|
|
84
|
+
: "".concat(prefixedPath).concat(urlQuery),
|
|
85
85
|
permanent: false,
|
|
86
86
|
};
|
|
87
87
|
}
|
|
@@ -89,7 +89,7 @@ function getRedirectToCanonicalLocale(basePageProps, nextLocaleIsoCode, redirect
|
|
|
89
89
|
}
|
|
90
90
|
exports.getRedirectToCanonicalLocale = getRedirectToCanonicalLocale;
|
|
91
91
|
function getLocaleDirection(locale) {
|
|
92
|
-
|
|
92
|
+
var neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
93
93
|
if (['ar', 'he', 'ur'].includes(neutralLanguageCode)) {
|
|
94
94
|
return 'rtl';
|
|
95
95
|
}
|
package/build/intl/locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
2
27
|
// This list is pulled from the main Prezly application. The underscores are replaced with dashes.
|
|
3
|
-
|
|
28
|
+
var supportedLocales = [
|
|
4
29
|
'af-ZA',
|
|
5
30
|
'ar',
|
|
6
31
|
'ar-AE',
|
|
@@ -102,12 +127,8 @@ const supportedLocales = [
|
|
|
102
127
|
'zh-TW',
|
|
103
128
|
'zh-CN',
|
|
104
129
|
];
|
|
105
|
-
|
|
130
|
+
var lowercaseLocales = supportedLocales.map(function (l) { return l.toLowerCase(); });
|
|
106
131
|
// Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes)
|
|
107
|
-
|
|
108
|
-
...lowercaseLocales,
|
|
109
|
-
...lowercaseLocales.map((code) => code.split('-')[0]),
|
|
110
|
-
...lowercaseLocales.map((code) => code.split('-')[1]).filter(Boolean),
|
|
111
|
-
])).sort();
|
|
132
|
+
var lowercaseLocalPermutations = Array.from(new Set(__spreadArray(__spreadArray(__spreadArray([], __read(lowercaseLocales), false), __read(lowercaseLocales.map(function (code) { return code.split('-')[0]; })), false), __read(lowercaseLocales.map(function (code) { return code.split('-')[1]; }).filter(Boolean)), false))).sort();
|
|
112
133
|
module.exports = lowercaseLocalPermutations;
|
|
113
134
|
//# sourceMappingURL=localeConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeConfig.js","sourceRoot":"","sources":["../../src/intl/localeConfig.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"localeConfig.js","sourceRoot":"","sources":["../../src/intl/localeConfig.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kGAAkG;AAClG,IAAM,gBAAgB,GAAG;IACrB,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,OAAO;IACP,IAAI;IACJ,OAAO;IACP,SAAS;IACT,OAAO;IACP,OAAO;IACP,OAAO;CACV,CAAC;AAEF,IAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,WAAW,EAAE,EAAf,CAAe,CAAC,CAAC;AAEtE,kGAAkG;AAClG,IAAM,0BAA0B,GAAG,KAAK,CAAC,IAAI,CACzC,IAAI,GAAG,sDACA,gBAAgB,kBAChB,gBAAgB,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAlB,CAAkB,CAAC,kBAClD,gBAAgB,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAlB,CAAkB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UACvE,CACL,CAAC,IAAI,EAAE,CAAC;AAET,MAAM,CAAC,OAAO,GAAG,0BAA0B,CAAC"}
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
2
18
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
19
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
20
|
};
|
|
5
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
22
|
exports.LocaleObject = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Hyphen-separated locale code.
|
|
11
|
-
* Examples: `nl-BE`, `en-US`, `fr`, `fil`
|
|
12
|
-
*/
|
|
13
|
-
localeCode;
|
|
14
|
-
constructor(localeCode) {
|
|
23
|
+
var localeConfig_1 = __importDefault(require("./localeConfig"));
|
|
24
|
+
var LocaleObject = /** @class */ (function () {
|
|
25
|
+
function LocaleObject(localeCode) {
|
|
15
26
|
if (localeCode.indexOf('_') !== -1) {
|
|
16
27
|
throw new Error('Invalid locale code provided!');
|
|
17
28
|
}
|
|
18
|
-
|
|
29
|
+
var _a = __read(localeCode.split('-'), 2), language = _a[0], region = _a[1];
|
|
19
30
|
if (region) {
|
|
20
31
|
this.localeCode = [language, region.toUpperCase()].join('-');
|
|
21
32
|
}
|
|
@@ -30,37 +41,38 @@ class LocaleObject {
|
|
|
30
41
|
* - Underscore-codes: `nl_BE`, `en_US`, `fr`, `fil`
|
|
31
42
|
* - Slugs: `nl-be`, `en-us`, `fr`, `fil`
|
|
32
43
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
44
|
+
LocaleObject.fromAnyCode = function (localeCode) {
|
|
45
|
+
var lowercaseCode = localeCode.toLowerCase().replace('_', '-');
|
|
46
|
+
var foundCode = localeConfig_1.default.find(function (code) { return code === lowercaseCode; });
|
|
36
47
|
if (!foundCode) {
|
|
37
|
-
throw new Error(
|
|
48
|
+
throw new Error("Unsupported locale code provided: \"".concat(lowercaseCode, "\""));
|
|
38
49
|
}
|
|
39
50
|
return new LocaleObject(foundCode);
|
|
40
|
-
}
|
|
41
|
-
toHyphenCode() {
|
|
51
|
+
};
|
|
52
|
+
LocaleObject.prototype.toHyphenCode = function () {
|
|
42
53
|
return this.localeCode;
|
|
43
|
-
}
|
|
44
|
-
toUnderscoreCode() {
|
|
54
|
+
};
|
|
55
|
+
LocaleObject.prototype.toUnderscoreCode = function () {
|
|
45
56
|
return this.localeCode.replace('-', '_');
|
|
46
|
-
}
|
|
47
|
-
toUrlSlug() {
|
|
57
|
+
};
|
|
58
|
+
LocaleObject.prototype.toUrlSlug = function () {
|
|
48
59
|
return this.localeCode.toLowerCase();
|
|
49
|
-
}
|
|
50
|
-
toNeutralLanguageCode() {
|
|
51
|
-
|
|
60
|
+
};
|
|
61
|
+
LocaleObject.prototype.toNeutralLanguageCode = function () {
|
|
62
|
+
var _a = __read(this.localeCode.split('-'), 1), language = _a[0];
|
|
52
63
|
return language;
|
|
53
|
-
}
|
|
54
|
-
toRegionCode() {
|
|
55
|
-
|
|
64
|
+
};
|
|
65
|
+
LocaleObject.prototype.toRegionCode = function () {
|
|
66
|
+
var _a = __read(this.localeCode.split('-'), 2), language = _a[0], region = _a[1];
|
|
56
67
|
if (!region) {
|
|
57
68
|
return language.toUpperCase();
|
|
58
69
|
}
|
|
59
70
|
return region.toUpperCase();
|
|
60
|
-
}
|
|
61
|
-
isEqual(anotherLocale) {
|
|
71
|
+
};
|
|
72
|
+
LocaleObject.prototype.isEqual = function (anotherLocale) {
|
|
62
73
|
return anotherLocale.toHyphenCode() === this.localeCode;
|
|
63
|
-
}
|
|
64
|
-
|
|
74
|
+
};
|
|
75
|
+
return LocaleObject;
|
|
76
|
+
}());
|
|
65
77
|
exports.LocaleObject = LocaleObject;
|
|
66
78
|
//# sourceMappingURL=localeObject.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"localeObject.js","sourceRoot":"","sources":["../../src/intl/localeObject.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA0C;AAE1C;IAOI,sBAAoB,UAAkB;QAClC,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SACpD;QAEK,IAAA,KAAA,OAAqB,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAAzC,QAAQ,QAAA,EAAE,MAAM,QAAyB,CAAC;QAEjD,IAAI,MAAM,EAAE;YACR,IAAI,CAAC,UAAU,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChE;aAAM;YACH,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;SAC9B;IACL,CAAC;IAED;;;;;;OAMG;IACW,wBAAW,GAAzB,UAA0B,UAAkB;QACxC,IAAM,aAAa,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjE,IAAM,SAAS,GAAG,sBAAY,CAAC,IAAI,CAAC,UAAC,IAAI,IAAK,OAAA,IAAI,KAAK,aAAa,EAAtB,CAAsB,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE;YACZ,MAAM,IAAI,KAAK,CAAC,8CAAsC,aAAa,OAAG,CAAC,CAAC;SAC3E;QAED,OAAO,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAEM,mCAAY,GAAnB;QACI,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAEM,uCAAgB,GAAvB;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC7C,CAAC;IAEM,gCAAS,GAAhB;QACI,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;IAEM,4CAAqB,GAA5B;QACU,IAAA,KAAA,OAAa,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAAtC,QAAQ,QAA8B,CAAC;QAE9C,OAAO,QAAQ,CAAC;IACpB,CAAC;IAEM,mCAAY,GAAnB;QACU,IAAA,KAAA,OAAqB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAA9C,QAAQ,QAAA,EAAE,MAAM,QAA8B,CAAC;QAEtD,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC;SACjC;QAED,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAChC,CAAC;IAEM,8BAAO,GAAd,UAAe,aAA2B;QACtC,OAAO,aAAa,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC;IAC5D,CAAC;IACL,mBAAC;AAAD,CAAC,AAtED,IAsEC;AAtEY,oCAAY"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import type { Category, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset
|
|
2
|
-
import { FunctionComponent } from 'react';
|
|
1
|
+
import type { Category, ExtendedStory, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset } from '@prezly/sdk';
|
|
2
|
+
import React, { FunctionComponent } from 'react';
|
|
3
3
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
4
|
import { LocaleObject } from '../intl';
|
|
5
|
-
import { Translations } from '../types';
|
|
6
5
|
export interface INewsroomContext {
|
|
7
6
|
newsroom: Newsroom;
|
|
8
7
|
companyInformation: NewsroomCompanyInformation;
|
|
9
8
|
categories: Category[];
|
|
10
9
|
contacts?: NewsroomContact[];
|
|
11
10
|
selectedCategory?: Category;
|
|
12
|
-
selectedStory?:
|
|
11
|
+
selectedStory?: ExtendedStory;
|
|
13
12
|
languages: NewsroomLanguageSettings[];
|
|
14
13
|
locale: LocaleObject;
|
|
15
14
|
hasError?: boolean;
|
|
@@ -17,10 +16,8 @@ export interface INewsroomContext {
|
|
|
17
16
|
algoliaSettings: AlgoliaSettings;
|
|
18
17
|
}
|
|
19
18
|
interface Props extends Omit<INewsroomContext, 'locale'> {
|
|
20
|
-
isTrackingEnabled?: boolean;
|
|
21
19
|
localeCode: string;
|
|
22
|
-
translations?: Translations;
|
|
23
20
|
}
|
|
24
|
-
export declare const NewsroomContext:
|
|
21
|
+
export declare const NewsroomContext: React.Context<INewsroomContext | undefined>;
|
|
25
22
|
export declare const NewsroomContextProvider: FunctionComponent<Props>;
|
|
26
23
|
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.NewsroomContextProvider = exports.NewsroomContext = void 0;
|
|
23
|
+
var react_1 = __importStar(require("react"));
|
|
24
|
+
var intl_1 = require("../intl");
|
|
25
|
+
exports.NewsroomContext = (0, react_1.createContext)(undefined);
|
|
26
|
+
var NewsroomContextProvider = function (_a) {
|
|
27
|
+
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom, selectedCategory = _a.selectedCategory, selectedStory = _a.selectedStory, companyInformation = _a.companyInformation, languages = _a.languages, localeCode = _a.localeCode, hasError = _a.hasError, themePreset = _a.themePreset, algoliaSettings = _a.algoliaSettings, children = _a.children;
|
|
28
|
+
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode || intl_1.DEFAULT_LOCALE); }, [localeCode]);
|
|
29
|
+
return (react_1.default.createElement(exports.NewsroomContext.Provider, { value: {
|
|
30
|
+
categories: categories,
|
|
31
|
+
contacts: contacts,
|
|
32
|
+
newsroom: newsroom,
|
|
33
|
+
selectedCategory: selectedCategory,
|
|
34
|
+
selectedStory: selectedStory,
|
|
35
|
+
companyInformation: companyInformation,
|
|
36
|
+
languages: languages,
|
|
37
|
+
locale: locale,
|
|
38
|
+
hasError: hasError,
|
|
39
|
+
themePreset: themePreset,
|
|
40
|
+
algoliaSettings: algoliaSettings,
|
|
41
|
+
} }, children));
|
|
42
|
+
};
|
|
43
|
+
exports.NewsroomContextProvider = NewsroomContextProvider;
|
|
44
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASA,6CAAyE;AAGzE,gCAAuD;AAoB1C,QAAA,eAAe,GAAG,IAAA,qBAAa,EAA+B,SAAS,CAAC,CAAC;AAE/E,IAAM,uBAAuB,GAA6B,UAAC,EAajE;QAZG,UAAU,gBAAA,EACV,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,gBAAgB,sBAAA,EAChB,aAAa,mBAAA,EACb,kBAAkB,wBAAA,EAClB,SAAS,eAAA,EACT,UAAU,gBAAA,EACV,QAAQ,cAAA,EACR,WAAW,iBAAA,EACX,eAAe,qBAAA,EACf,QAAQ,cAAA;IAER,IAAM,MAAM,GAAG,IAAA,eAAO,EAClB,cAAM,OAAA,mBAAY,CAAC,WAAW,CAAC,UAAU,IAAI,qBAAc,CAAC,EAAtD,CAAsD,EAC5D,CAAC,UAAU,CAAC,CACf,CAAC;IAEF,OAAO,CACH,8BAAC,uBAAe,CAAC,QAAQ,IACrB,KAAK,EAAE;YACH,UAAU,YAAA;YACV,QAAQ,UAAA;YACR,QAAQ,UAAA;YACR,gBAAgB,kBAAA;YAChB,aAAa,eAAA;YACb,kBAAkB,oBAAA;YAClB,SAAS,WAAA;YACT,MAAM,QAAA;YACN,QAAQ,UAAA;YACR,WAAW,aAAA;YACX,eAAe,iBAAA;SAClB,IAEA,QAAQ,CACc,CAC9B,CAAC;AACN,CAAC,CAAC;AAtCW,QAAA,uBAAuB,2BAsClC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useAlgoliaSettings = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useAlgoliaSettings = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.algoliaSettings;
|
|
8
8
|
};
|
|
9
9
|
exports.useAlgoliaSettings = useAlgoliaSettings;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlgoliaSettings.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useAlgoliaSettings.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useAlgoliaSettings.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useAlgoliaSettings.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,kBAAkB,GAAG;IAC9B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,eAAe,CAAC;AACnC,CAAC,CAAC;AAJW,QAAA,kBAAkB,sBAI7B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCategories = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useCategories = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.categories;
|
|
8
8
|
};
|
|
9
9
|
exports.useCategories = useCategories;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCategories.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCategories.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useCategories.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCategories.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,aAAa,GAAG;IACzB,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,UAAU,CAAC;AAC9B,CAAC,CAAC;AAJW,QAAA,aAAa,iBAIxB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCompanyInformation = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useCompanyInformation = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.companyInformation;
|
|
8
8
|
};
|
|
9
9
|
exports.useCompanyInformation = useCompanyInformation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompanyInformation.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCompanyInformation.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useCompanyInformation.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCompanyInformation.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,qBAAqB,GAAG;IACjC,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,kBAAkB,CAAC;AACtC,CAAC,CAAC;AAJW,QAAA,qBAAqB,yBAIhC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCurrentLocale = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useCurrentLocale = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.locale;
|
|
8
8
|
};
|
|
9
9
|
exports.useCurrentLocale = useCurrentLocale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrentLocale.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCurrentLocale.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useCurrentLocale.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useCurrentLocale.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,gBAAgB,GAAG;IAC5B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,MAAM,CAAC;AAC1B,CAAC,CAAC;AAJW,QAAA,gBAAgB,oBAI3B"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useGetLinkLocaleSlug = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var data_fetching_1 = require("../../data-fetching");
|
|
6
|
+
var intl_1 = require("../../intl");
|
|
7
|
+
var useCurrentLocale_1 = require("./useCurrentLocale");
|
|
8
|
+
var useLanguages_1 = require("./useLanguages");
|
|
9
9
|
// Determine correct locale slug for the link (trying to shorten the locale code if possible)
|
|
10
10
|
function getLinkLocaleSlug(languages, locale) {
|
|
11
|
-
|
|
11
|
+
var shortestLocaleCode = (0, data_fetching_1.getShortestLocaleCode)(languages, locale);
|
|
12
12
|
// When navigating to default language, we don't append the locale to the URL.
|
|
13
13
|
if (!shortestLocaleCode) {
|
|
14
14
|
return shortestLocaleCode;
|
|
@@ -16,10 +16,10 @@ function getLinkLocaleSlug(languages, locale) {
|
|
|
16
16
|
return intl_1.LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug();
|
|
17
17
|
}
|
|
18
18
|
function useGetLinkLocaleSlug() {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
var currentLocale = (0, useCurrentLocale_1.useCurrentLocale)();
|
|
20
|
+
var languages = (0, useLanguages_1.useLanguages)();
|
|
21
21
|
// The `locale` parameter is mainly used for Language Dropdown
|
|
22
|
-
return (0, react_1.useCallback)((locale)
|
|
22
|
+
return (0, react_1.useCallback)(function (locale) { return getLinkLocaleSlug(languages, locale || currentLocale); }, [languages, currentLocale]);
|
|
23
23
|
}
|
|
24
24
|
exports.useGetLinkLocaleSlug = useGetLinkLocaleSlug;
|
|
25
25
|
//# sourceMappingURL=useGetLinkLocaleSlug.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetLinkLocaleSlug.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetLinkLocaleSlug.ts"],"names":[],"mappings":";;;AACA
|
|
1
|
+
{"version":3,"file":"useGetLinkLocaleSlug.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetLinkLocaleSlug.ts"],"names":[],"mappings":";;;AACA,+BAAoC;AAEpC,qDAA4D;AAC5D,mCAA0C;AAE1C,uDAAsD;AACtD,+CAA8C;AAE9C,6FAA6F;AAC7F,SAAS,iBAAiB,CACtB,SAAqC,EACrC,MAAoB;IAEpB,IAAM,kBAAkB,GAAG,IAAA,qCAAqB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACpE,8EAA8E;IAC9E,IAAI,CAAC,kBAAkB,EAAE;QACrB,OAAO,kBAAkB,CAAC;KAC7B;IAED,OAAO,mBAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC;AACpE,CAAC;AAED,SAAgB,oBAAoB;IAChC,IAAM,aAAa,GAAG,IAAA,mCAAgB,GAAE,CAAC;IACzC,IAAM,SAAS,GAAG,IAAA,2BAAY,GAAE,CAAC;IAEjC,8DAA8D;IAC9D,OAAO,IAAA,mBAAW,EACd,UAAC,MAAqB,IAAK,OAAA,iBAAiB,CAAC,SAAS,EAAE,MAAM,IAAI,aAAa,CAAC,EAArD,CAAqD,EAChF,CAAC,SAAS,EAAE,aAAa,CAAC,CAC7B,CAAC;AACN,CAAC;AATD,oDASC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useGetTranslationUrl = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var router_1 = require("next/router");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var data_fetching_1 = require("../../data-fetching");
|
|
7
|
+
var useSelectedCategory_1 = require("./useSelectedCategory");
|
|
8
|
+
var useSelectedStory_1 = require("./useSelectedStory");
|
|
9
9
|
// Determine correct URL for translated stories/categories with a fallback to homepage
|
|
10
10
|
function getTranslationUrl(locale, path, selectedCategory, selectedStory, noFallback) {
|
|
11
11
|
if (selectedCategory) {
|
|
@@ -17,11 +17,14 @@ function getTranslationUrl(locale, path, selectedCategory, selectedStory, noFall
|
|
|
17
17
|
}
|
|
18
18
|
return '/';
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
var localeCode = locale.toUnderscoreCode();
|
|
21
21
|
if (selectedStory && selectedStory.culture.locale !== localeCode) {
|
|
22
|
-
|
|
22
|
+
var translatedStory = selectedStory.translations.find(function (_a) {
|
|
23
|
+
var culture = _a.culture;
|
|
24
|
+
return culture.locale === localeCode;
|
|
25
|
+
});
|
|
23
26
|
if (translatedStory) {
|
|
24
|
-
return
|
|
27
|
+
return "/".concat(translatedStory.slug);
|
|
25
28
|
}
|
|
26
29
|
if (noFallback) {
|
|
27
30
|
return '';
|
|
@@ -31,10 +34,12 @@ function getTranslationUrl(locale, path, selectedCategory, selectedStory, noFall
|
|
|
31
34
|
return path;
|
|
32
35
|
}
|
|
33
36
|
function useGetTranslationUrl() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return (0, react_1.useCallback)(
|
|
37
|
+
var asPath = (0, router_1.useRouter)().asPath;
|
|
38
|
+
var selectedCategory = (0, useSelectedCategory_1.useSelectedCategory)();
|
|
39
|
+
var selectedStory = (0, useSelectedStory_1.useSelectedStory)();
|
|
40
|
+
return (0, react_1.useCallback)(function (locale, noFallback) {
|
|
41
|
+
return getTranslationUrl(locale, asPath, selectedCategory, selectedStory, noFallback);
|
|
42
|
+
}, [asPath, selectedCategory, selectedStory]);
|
|
38
43
|
}
|
|
39
44
|
exports.useGetTranslationUrl = useGetTranslationUrl;
|
|
40
45
|
//# sourceMappingURL=useGetTranslationUrl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"useGetTranslationUrl.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useGetTranslationUrl.ts"],"names":[],"mappings":";;;AACA,sCAAwC;AACxC,+BAAoC;AAEpC,qDAAgF;AAGhF,6DAA4D;AAC5D,uDAAsD;AAEtD,sFAAsF;AACtF,SAAS,iBAAiB,CACtB,MAAoB,EACpB,IAAY,EACZ,gBAA2B,EAC3B,aAA6B,EAC7B,UAAoB;IAEpB,IAAI,gBAAgB,EAAE;QAClB,IAAI,IAAA,yCAAyB,EAAC,gBAAgB,EAAE,MAAM,CAAC,EAAE;YACrD,OAAO,IAAA,8BAAc,EAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;SACnD;QAED,IAAI,UAAU,EAAE;YACZ,OAAO,EAAE,CAAC;SACb;QAED,OAAO,GAAG,CAAC;KACd;IAED,IAAM,UAAU,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAE7C,IAAI,aAAa,IAAI,aAAa,CAAC,OAAO,CAAC,MAAM,KAAK,UAAU,EAAE;QAC9D,IAAM,eAAe,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,CACnD,UAAC,EAAW;gBAAT,OAAO,aAAA;YAAO,OAAA,OAAO,CAAC,MAAM,KAAK,UAAU;QAA7B,CAA6B,CACjD,CAAC;QACF,IAAI,eAAe,EAAE;YACjB,OAAO,WAAI,eAAe,CAAC,IAAI,CAAE,CAAC;SACrC;QAED,IAAI,UAAU,EAAE;YACZ,OAAO,EAAE,CAAC;SACb;QAED,OAAO,GAAG,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,oBAAoB;IACxB,IAAA,MAAM,GAAK,IAAA,kBAAS,GAAE,OAAhB,CAAiB;IAC/B,IAAM,gBAAgB,GAAG,IAAA,yCAAmB,GAAE,CAAC;IAC/C,IAAM,aAAa,GAAG,IAAA,mCAAgB,GAAE,CAAC;IAEzC,OAAO,IAAA,mBAAW,EACd,UAAC,MAAoB,EAAE,UAAoB;QACvC,OAAA,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,CAAC;IAA9E,CAA8E,EAClF,CAAC,MAAM,EAAE,gBAAgB,EAAE,aAAa,CAAC,CAC5C,CAAC;AACN,CAAC;AAVD,oDAUC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLanguages = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useLanguages = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.languages;
|
|
8
8
|
};
|
|
9
9
|
exports.useLanguages = useLanguages;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useLanguages.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useLanguages.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useLanguages.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,YAAY,GAAG;IACxB,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,SAAS,CAAC;AAC7B,CAAC,CAAC;AAJW,QAAA,YAAY,gBAIvB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useNewsroom = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useNewsroom = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.newsroom;
|
|
8
8
|
};
|
|
9
9
|
exports.useNewsroom = useNewsroom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNewsroom.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroom.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useNewsroom.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroom.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,WAAW,GAAG;IACvB,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,QAAQ,CAAC;AAC5B,CAAC,CAAC;AAJW,QAAA,WAAW,eAItB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useNewsroomContext = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var context_1 = require("../context");
|
|
6
|
+
var useNewsroomContext = function () {
|
|
7
7
|
// TS Compiler is having a hard time figuring this type implicitly, so we have to set it explicitly
|
|
8
8
|
// See https://github.com/microsoft/TypeScript/issues/5711#issuecomment-340283439
|
|
9
|
-
|
|
9
|
+
var newsroomContext = (0, react_1.useContext)(context_1.NewsroomContext);
|
|
10
10
|
if (!newsroomContext) {
|
|
11
11
|
throw new Error('No `NewsroomContextProvider` found when calling `useNewsroomContext`');
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"useNewsroomContext.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useNewsroomContext.ts"],"names":[],"mappings":";;;AAAA,+BAAmC;AAEnC,sCAA+D;AAExD,IAAM,kBAAkB,GAAG;IAC9B,mGAAmG;IACnG,iFAAiF;IACjF,IAAM,eAAe,GAAiC,IAAA,kBAAU,EAAC,yBAAe,CAAC,CAAC;IAClF,IAAI,CAAC,eAAe,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;KAC3F;IAED,OAAO,eAAe,CAAC;AAC3B,CAAC,CAAC;AATW,QAAA,kBAAkB,sBAS7B"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useSelectedCategory = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
var useSelectedCategory = function () {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
7
|
return context.selectedCategory;
|
|
8
8
|
};
|
|
9
9
|
exports.useSelectedCategory = useSelectedCategory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectedCategory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useSelectedCategory.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"useSelectedCategory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useSelectedCategory.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAEnD,IAAM,mBAAmB,GAAG;IAC/B,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,OAAO,OAAO,CAAC,gBAAgB,CAAC;AACpC,CAAC,CAAC;AAJW,QAAA,mBAAmB,uBAI9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useSelectedStory: () => import("@prezly/sdk").
|
|
1
|
+
export declare const useSelectedStory: () => import("@prezly/sdk").ExtendedStory | undefined;
|