@prezly/theme-kit-nextjs 3.3.2-alpha.0 → 4.0.0-alpha.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.
- package/README.md +5 -4
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js +1 -1
- package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js +1 -1
- package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.d.ts +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js +1 -1
- package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.d.ts +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js +1 -1
- package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/category.js +6 -7
- package/build/adapter-nextjs/page-props/category.js.map +1 -1
- package/build/adapter-nextjs/page-props/gallery.js +3 -3
- package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js +1 -1
- package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
- package/build/adapter-nextjs/page-props/home.js +3 -3
- package/build/adapter-nextjs/page-props/home.js.map +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +1 -1
- package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
- package/build/adapter-nextjs/page-props/story.js +3 -3
- package/build/adapter-nextjs/page-props/story.js.map +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js +1 -1
- package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
- package/build/adapter-nextjs/processRequest.js +3 -2
- package/build/adapter-nextjs/processRequest.js.map +1 -1
- package/build/components-nextjs/PageSeo/PageSeo.js +13 -20
- package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
- package/build/components-nextjs/PageSeo/index.d.ts +0 -1
- package/build/components-nextjs/PageSeo/index.js +0 -15
- package/build/components-nextjs/PageSeo/index.js.map +1 -1
- package/build/components-nextjs/PageSeo/lib/index.d.ts +1 -0
- package/build/components-nextjs/PageSeo/lib/index.js +6 -0
- package/build/components-nextjs/PageSeo/lib/index.js.map +1 -0
- package/build/components-nextjs/document.js +4 -4
- package/build/components-nextjs/document.js.map +1 -1
- package/build/data-fetching/NextPrezlyApi.d.ts +8 -0
- package/build/data-fetching/NextPrezlyApi.js +40 -0
- package/build/data-fetching/NextPrezlyApi.js.map +1 -0
- package/build/data-fetching/getNextPrezlyApi.d.ts +4 -0
- package/build/data-fetching/getNextPrezlyApi.js +21 -0
- package/build/data-fetching/getNextPrezlyApi.js.map +1 -0
- package/build/data-fetching/index.d.ts +1 -3
- package/build/data-fetching/index.js +3 -17
- package/build/data-fetching/index.js.map +1 -1
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/build/infinite-loading/useInfiniteLoading.js +1 -1
- package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
- package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
- package/build/intl/index.d.ts +0 -2
- package/build/intl/index.js +0 -7
- package/build/intl/index.js.map +1 -1
- package/build/intl/languages.d.ts +1 -44
- package/build/intl/languages.js +8 -151
- package/build/intl/languages.js.map +1 -1
- package/build/intl/locale.d.ts +0 -8
- package/build/intl/locale.js +3 -93
- package/build/intl/locale.js.map +1 -1
- package/build/newsroom-context/context.d.ts +2 -2
- package/build/newsroom-context/context.js +2 -2
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/useAlgoliaSettings.d.ts +1 -1
- package/build/newsroom-context/hooks/useCurrentLocale.d.ts +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.d.ts +1 -1
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +3 -3
- package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +1 -1
- package/build/newsroom-context/hooks/useGetTranslationUrl.js +3 -3
- package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
- package/build/types.d.ts +0 -29
- package/package.json +15 -13
- package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +2 -2
- package/src/adapter-nextjs/api-handlers/fetchStories.ts +2 -2
- package/src/adapter-nextjs/getNewsroomServerSideProps.ts +2 -2
- package/src/adapter-nextjs/getNewsroomStaticProps.ts +2 -2
- package/src/adapter-nextjs/page-props/category.ts +3 -4
- package/src/adapter-nextjs/page-props/gallery.ts +1 -1
- package/src/adapter-nextjs/page-props/galleryAlbum.ts +2 -2
- package/src/adapter-nextjs/page-props/home.ts +1 -1
- package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +2 -2
- package/src/adapter-nextjs/page-props/story.ts +4 -4
- package/src/adapter-nextjs/page-props/storyPreview.ts +2 -2
- package/src/adapter-nextjs/processRequest.ts +2 -1
- package/src/components-nextjs/PageSeo/PageSeo.tsx +7 -5
- package/src/components-nextjs/PageSeo/index.ts +0 -1
- package/src/components-nextjs/PageSeo/lib/index.ts +1 -0
- package/src/components-nextjs/document.tsx +1 -1
- package/src/data-fetching/NextPrezlyApi.ts +57 -0
- package/src/data-fetching/{api/getPrezlyApi.ts → getNextPrezlyApi.ts} +5 -6
- package/src/data-fetching/index.ts +1 -3
- package/src/index.ts +0 -1
- package/src/infinite-loading/useInfiniteStoriesLoading.ts +1 -1
- package/src/intl/index.ts +0 -3
- package/src/intl/languages.test.ts +1 -196
- package/src/intl/languages.ts +8 -201
- package/src/intl/locale.test.ts +1 -55
- package/src/intl/locale.ts +1 -106
- package/src/newsroom-context/context.tsx +2 -3
- package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +1 -2
- package/src/newsroom-context/hooks/useGetTranslationUrl.ts +2 -3
- package/src/types.ts +0 -35
- package/build/components-nextjs/PageSeo/lib/types.d.ts +0 -4
- package/build/components-nextjs/PageSeo/lib/types.js +0 -3
- package/build/components-nextjs/PageSeo/lib/types.js.map +0 -1
- package/build/data-fetching/api/PrezlyApi.d.ts +0 -57
- package/build/data-fetching/api/PrezlyApi.js +0 -200
- package/build/data-fetching/api/PrezlyApi.js.map +0 -1
- package/build/data-fetching/api/getPrezlyApi.d.ts +0 -4
- package/build/data-fetching/api/getPrezlyApi.js +0 -21
- package/build/data-fetching/api/getPrezlyApi.js.map +0 -1
- package/build/data-fetching/api/index.d.ts +0 -1
- package/build/data-fetching/api/index.js +0 -18
- package/build/data-fetching/api/index.js.map +0 -1
- package/build/data-fetching/api/lib.d.ts +0 -11
- package/build/data-fetching/api/lib.js +0 -20
- package/build/data-fetching/api/lib.js.map +0 -1
- package/build/data-fetching/api/queries.d.ts +0 -46
- package/build/data-fetching/api/queries.js +0 -56
- package/build/data-fetching/api/queries.js.map +0 -1
- package/build/data-fetching/lib/getAlgoliaSettings.d.ts +0 -4
- package/build/data-fetching/lib/getAlgoliaSettings.js +0 -22
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +0 -1
- package/build/data-fetching/lib/getEnvVariables.d.ts +0 -4
- package/build/data-fetching/lib/getEnvVariables.js +0 -44
- package/build/data-fetching/lib/getEnvVariables.js.map +0 -1
- package/build/data-fetching/lib/index.d.ts +0 -4
- package/build/data-fetching/lib/index.js +0 -12
- package/build/data-fetching/lib/index.js.map +0 -1
- package/build/data-fetching/lib/isSdkError.d.ts +0 -2
- package/build/data-fetching/lib/isSdkError.js +0 -8
- package/build/data-fetching/lib/isSdkError.js.map +0 -1
- package/build/data-fetching/lib/isUuid.d.ts +0 -1
- package/build/data-fetching/lib/isUuid.js +0 -9
- package/build/data-fetching/lib/isUuid.js.map +0 -1
- package/build/data-fetching/types.d.ts +0 -13
- package/build/data-fetching/types.js +0 -3
- package/build/data-fetching/types.js.map +0 -1
- package/build/intl/localeConfig.d.ts +0 -2
- package/build/intl/localeConfig.js +0 -20
- package/build/intl/localeConfig.js.map +0 -1
- package/build/intl/localeList.d.ts +0 -2
- package/build/intl/localeList.js +0 -112
- package/build/intl/localeList.js.map +0 -1
- package/build/intl/localeObject.d.ts +0 -45
- package/build/intl/localeObject.js +0 -91
- package/build/intl/localeObject.js.map +0 -1
- package/build/utils/boilerplate.d.ts +0 -4
- package/build/utils/boilerplate.js +0 -27
- package/build/utils/boilerplate.js.map +0 -1
- package/build/utils/constants.d.ts +0 -3
- package/build/utils/constants.js +0 -7
- package/build/utils/constants.js.map +0 -1
- package/build/utils/getAssetsUrl.d.ts +0 -5
- package/build/utils/getAssetsUrl.js +0 -13
- package/build/utils/getAssetsUrl.js.map +0 -1
- package/build/utils/getDataRequestLink.d.ts +0 -3
- package/build/utils/getDataRequestLink.js +0 -12
- package/build/utils/getDataRequestLink.js.map +0 -1
- package/build/utils/getLocalizedCategoryData.d.ts +0 -10
- package/build/utils/getLocalizedCategoryData.js +0 -37
- package/build/utils/getLocalizedCategoryData.js.map +0 -1
- package/build/utils/getNewsroomLogoUrl.d.ts +0 -3
- package/build/utils/getNewsroomLogoUrl.js +0 -22
- package/build/utils/getNewsroomLogoUrl.js.map +0 -1
- package/build/utils/getPrivacyPortalUrl.d.ts +0 -8
- package/build/utils/getPrivacyPortalUrl.js +0 -13
- package/build/utils/getPrivacyPortalUrl.js.map +0 -1
- package/build/utils/getStoryPublicationDate.d.ts +0 -3
- package/build/utils/getStoryPublicationDate.js +0 -14
- package/build/utils/getStoryPublicationDate.js.map +0 -1
- package/build/utils/getUploadcareGroupUrl.d.ts +0 -8
- package/build/utils/getUploadcareGroupUrl.js +0 -17
- package/build/utils/getUploadcareGroupUrl.js.map +0 -1
- package/build/utils/index.d.ts +0 -10
- package/build/utils/index.js +0 -27
- package/build/utils/index.js.map +0 -1
- package/build/utils/isEmbargoStory.d.ts +0 -6
- package/build/utils/isEmbargoStory.js +0 -8
- package/build/utils/isEmbargoStory.js.map +0 -1
- package/src/@types/global.d.ts +0 -7
- package/src/__mocks__/story.ts +0 -359
- package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
- package/src/data-fetching/api/PrezlyApi.ts +0 -312
- package/src/data-fetching/api/index.ts +0 -1
- package/src/data-fetching/api/lib.ts +0 -24
- package/src/data-fetching/api/queries.ts +0 -59
- package/src/data-fetching/lib/getAlgoliaSettings.ts +0 -29
- package/src/data-fetching/lib/getEnvVariables.ts +0 -46
- package/src/data-fetching/lib/index.ts +0 -4
- package/src/data-fetching/lib/isSdkError.ts +0 -5
- package/src/data-fetching/lib/isUuid.ts +0 -5
- package/src/data-fetching/types.ts +0 -14
- package/src/intl/getFallbackLocale.ts +0 -29
- package/src/intl/localeConfig.js +0 -23
- package/src/intl/localeList.js +0 -110
- package/src/intl/localeObject.test.ts +0 -81
- package/src/intl/localeObject.ts +0 -107
- package/src/seo/getAlternateLanguageLinks.test.ts +0 -166
- package/src/seo/getAlternateLanguageLinks.ts +0 -115
- package/src/seo/index.ts +0 -1
- package/src/seo/utils/bindLanguagesWithLocales.ts +0 -31
- package/src/seo/utils/createAlternateLanguageLink.ts +0 -17
- package/src/utils/boilerplate.ts +0 -30
- package/src/utils/constants.ts +0 -3
- package/src/utils/getAssetsUrl.test.ts +0 -9
- package/src/utils/getAssetsUrl.ts +0 -9
- package/src/utils/getDataRequestLink.ts +0 -14
- package/src/utils/getLocalizedCategoryData.ts +0 -47
- package/src/utils/getNewsroomLogoUrl.ts +0 -22
- package/src/utils/getPrivacyPortalUrl.ts +0 -25
- package/src/utils/getStoryPublicationDate.tsx +0 -15
- package/src/utils/getUploadcareGroupUrl.ts +0 -13
- package/src/utils/index.ts +0 -10
- package/src/utils/isEmbargoStory.ts +0 -10
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NextPrezlyApi = void 0;
|
|
4
|
+
const theme_kit_core_1 = require("@prezly/theme-kit-core");
|
|
5
|
+
const intl_1 = require("../intl");
|
|
6
|
+
class NextPrezlyApi extends theme_kit_core_1.PrezlyApi {
|
|
7
|
+
async getNewsroomServerSideProps(request, nextLocaleIsoCode, story) {
|
|
8
|
+
const [newsroom, languages, categories, themePreset] = await Promise.all([
|
|
9
|
+
this.getNewsroom(),
|
|
10
|
+
this.getNewsroomLanguages(),
|
|
11
|
+
this.getCategories(),
|
|
12
|
+
this.getThemePreset(),
|
|
13
|
+
]);
|
|
14
|
+
const currentLanguage = story
|
|
15
|
+
? (0, theme_kit_core_1.getLanguageFromStory)(languages, story)
|
|
16
|
+
: (0, intl_1.getLanguageFromNextLocaleIsoCode)(languages, nextLocaleIsoCode);
|
|
17
|
+
const defaultLanguage = (0, theme_kit_core_1.getDefaultLanguage)(languages);
|
|
18
|
+
const { code: localeCode } = currentLanguage || defaultLanguage;
|
|
19
|
+
const locale = theme_kit_core_1.LocaleObject.fromAnyCode(localeCode);
|
|
20
|
+
// TODO: if no information given for current language, show boilerplate from default language
|
|
21
|
+
const companyInformation = (0, theme_kit_core_1.getCompanyInformation)(languages, locale);
|
|
22
|
+
const notifications = (0, theme_kit_core_1.getNotifications)(languages, locale);
|
|
23
|
+
const algoliaSettings = (0, theme_kit_core_1.getAlgoliaSettings)(request);
|
|
24
|
+
return {
|
|
25
|
+
newsroomContextProps: {
|
|
26
|
+
newsroom,
|
|
27
|
+
companyInformation,
|
|
28
|
+
categories,
|
|
29
|
+
languages,
|
|
30
|
+
localeCode,
|
|
31
|
+
notifications,
|
|
32
|
+
themePreset,
|
|
33
|
+
algoliaSettings,
|
|
34
|
+
},
|
|
35
|
+
localeResolved: Boolean(currentLanguage),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.NextPrezlyApi = NextPrezlyApi;
|
|
40
|
+
//# sourceMappingURL=NextPrezlyApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NextPrezlyApi.js","sourceRoot":"","sources":["../../src/data-fetching/NextPrezlyApi.ts"],"names":[],"mappings":";;;AACA,2DAQgC;AAGhC,kCAA2D;AAG3D,MAAa,aAAc,SAAQ,0BAAS;IACxC,KAAK,CAAC,0BAA0B,CAC5B,OAAyB,EACzB,iBAA0B,EAC1B,KAAa;QAEb,MAAM,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACrE,IAAI,CAAC,WAAW,EAAE;YAClB,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,aAAa,EAAE;YACpB,IAAI,CAAC,cAAc,EAAE;SACxB,CAAC,CAAC;QAEH,MAAM,eAAe,GAAG,KAAK;YACzB,CAAC,CAAC,IAAA,qCAAoB,EAAC,SAAS,EAAE,KAAK,CAAC;YACxC,CAAC,CAAC,IAAA,uCAAgC,EAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;QACrE,MAAM,eAAe,GAAG,IAAA,mCAAkB,EAAC,SAAS,CAAC,CAAC;QAEtD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,eAAe,IAAI,eAAe,CAAC;QAChE,MAAM,MAAM,GAAG,6BAAY,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAEpD,6FAA6F;QAC7F,MAAM,kBAAkB,GAAG,IAAA,sCAAqB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAEpE,MAAM,aAAa,GAAG,IAAA,iCAAgB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC1D,MAAM,eAAe,GAAG,IAAA,mCAAkB,EAAC,OAAO,CAAC,CAAC;QAEpD,OAAO;YACH,oBAAoB,EAAE;gBAClB,QAAQ;gBACR,kBAAkB;gBAClB,UAAU;gBACV,SAAS;gBACT,UAAU;gBACV,aAAa;gBACb,WAAW;gBACX,eAAe;aAClB;YACD,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC;SAC3C,CAAC;IACN,CAAC;CACJ;AAzCD,sCAyCC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextPrezlyApi = void 0;
|
|
4
|
+
const theme_kit_core_1 = require("@prezly/theme-kit-core");
|
|
5
|
+
const NextPrezlyApi_1 = require("./NextPrezlyApi");
|
|
6
|
+
function getNextPrezlyApi(req) {
|
|
7
|
+
if (typeof window !== 'undefined') {
|
|
8
|
+
throw new Error('"getNextPrezlyApi" should only be used on back-end side.');
|
|
9
|
+
}
|
|
10
|
+
// `getEnvVariables` handles both cases for envs parsing - .env and request headers
|
|
11
|
+
const { PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID } = (0, theme_kit_core_1.getEnvVariables)(req);
|
|
12
|
+
if (!PREZLY_ACCESS_TOKEN) {
|
|
13
|
+
throw new Error('"PREZLY_ACCESS_TOKEN" is not set in env variables.');
|
|
14
|
+
}
|
|
15
|
+
if (!PREZLY_NEWSROOM_UUID) {
|
|
16
|
+
throw new Error('"PREZLY_NEWSROOM_UUID" is not set in env variables.');
|
|
17
|
+
}
|
|
18
|
+
return new NextPrezlyApi_1.NextPrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID);
|
|
19
|
+
}
|
|
20
|
+
exports.getNextPrezlyApi = getNextPrezlyApi;
|
|
21
|
+
//# sourceMappingURL=getNextPrezlyApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNextPrezlyApi.js","sourceRoot":"","sources":["../../src/data-fetching/getNextPrezlyApi.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AAGzD,mDAAgD;AAEhD,SAAgB,gBAAgB,CAAC,GAAqB;IAClD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;KAC/E;IAED,mFAAmF;IACnF,MAAM,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,GAAG,IAAA,gCAAe,EAAC,GAAG,CAAC,CAAC;IAE9F,IAAI,CAAC,mBAAmB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;KACzE;IAED,IAAI,CAAC,oBAAoB,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;KAC1E;IAED,OAAO,IAAI,6BAAa,CAAC,mBAAmB,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,CAAC;AAC3F,CAAC;AAjBD,4CAiBC"}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
exports.getNextPrezlyApi = void 0;
|
|
4
|
+
var getNextPrezlyApi_1 = require("./getNextPrezlyApi");
|
|
5
|
+
Object.defineProperty(exports, "getNextPrezlyApi", { enumerable: true, get: function () { return getNextPrezlyApi_1.getNextPrezlyApi; } });
|
|
20
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/data-fetching/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/data-fetching/index.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -22,5 +22,4 @@ __exportStar(require("./intl"), exports);
|
|
|
22
22
|
__exportStar(require("./newsroom-context"), exports);
|
|
23
23
|
__exportStar(require("./sentry"), exports);
|
|
24
24
|
__exportStar(require("./types"), exports);
|
|
25
|
-
__exportStar(require("./utils"), exports);
|
|
26
25
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,sDAAoC;AACpC,kDAAgC;AAChC,qDAAmC;AACnC,yCAAuB;AACvB,qDAAmC;AACnC,2CAAyB;AACzB,0CAAwB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,sDAAoC;AACpC,kDAAgC;AAChC,qDAAmC;AACnC,yCAAuB;AACvB,qDAAmC;AACnC,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -7,7 +7,7 @@ function useInfiniteLoading({ fetchingFn, initialData, pagination, }) {
|
|
|
7
7
|
const [data, setData] = (0, react_1.useState)(initialData);
|
|
8
8
|
const [currentPage, setCurrentPage] = (0, react_1.useState)(pagination.currentPage);
|
|
9
9
|
const { itemsTotal, pageSize, withHighlightedStory } = pagination;
|
|
10
|
-
const adjustedItemsTotal = withHighlightedStory ? itemsTotal : itemsTotal
|
|
10
|
+
const adjustedItemsTotal = withHighlightedStory ? itemsTotal - 1 : itemsTotal;
|
|
11
11
|
const pagesTotal = Math.ceil(adjustedItemsTotal / pageSize);
|
|
12
12
|
const canLoadMore = currentPage < pagesTotal;
|
|
13
13
|
const [{ error, status }, { execute: loadMoreFn }] = (0, web_1.useAsync)(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteLoading.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAC5C,iCAAyD;AAmBzD,SAAgB,kBAAkB,CAAI,EAClC,UAAU,EACV,WAAW,EACX,UAAU,GACE;IACZ,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAM,WAAW,CAAC,CAAC;IACnD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAEvE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC;IAClE,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"useInfiniteLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteLoading.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAC5C,iCAAyD;AAmBzD,SAAgB,kBAAkB,CAAI,EAClC,UAAU,EACV,WAAW,EACX,UAAU,GACE;IACZ,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAM,WAAW,CAAC,CAAC;IACnD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAEvE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,UAAU,CAAC;IAClE,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAC9E,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC,CAAC;IAC5D,MAAM,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;IAE7C,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,GAAG,IAAA,cAAQ,EAAC,KAAK,IAAI,EAAE;QACrE,MAAM,QAAQ,GAAG,WAAW,GAAG,CAAC,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACrD,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzB,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC9B,IAAI,WAAW,EAAE;YACb,UAAU,EAAE,CAAC;SAChB;IACL,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;IAE9B,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAC/B,OAAO,CAAC,WAAW,CAAC,CAAC;QACrB,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1C,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,KAAK,EAAE;YACP,sCAAsC;YACtC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACxB;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO;QACH,WAAW;QACX,WAAW;QACX,IAAI;QACJ,SAAS,EAAE,MAAM,KAAK,SAAS;QAC/B,QAAQ;QACR,SAAS;KACZ,CAAC;AACN,CAAC;AA9CD,gDA8CC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteStoriesLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteStoriesLoading.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useInfiniteStoriesLoading.js","sourceRoot":"","sources":["../../src/infinite-loading/useInfiniteStoriesLoading.ts"],"names":[],"mappings":";;;AAEA,iCAAkC;AAElC,0DAAuD;AAGvD,6DAA0D;AAE1D,KAAK,UAAU,YAAY,CACvB,IAAY,EACZ,QAAgB,EAChB,oBAA6B,EAC7B,QAAmB,EACnB,MAAqB,EACrB,OAAqC,EACrC,OAAiB;IAEjB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE;QAC7C,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;SACrC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACjB,IAAI;YACJ,QAAQ;YACR,oBAAoB;YACpB,QAAQ;YACR,OAAO;YACP,OAAO;YACP,GAAG,CAAC,MAAM,IAAI;gBACV,UAAU,EAAE,MAAM,CAAC,gBAAgB,EAAE;aACxC,CAAC;SACL,CAAC;KACL,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE;QACZ,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC5B;IAED,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,SAAgB,yBAAyB,CACrC,cAAmB,EACnB,UAA2B,EAC3B,QAAmB,EACnB,OAAqC,EACrC,OAAiB;IAEjB,MAAM,aAAa,GAAG,IAAA,mCAAgB,GAAE,CAAC;IACzC,MAAM,EAAE,oBAAoB,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC;IAEpD,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAA,uCAAkB,EAAI;QAChF,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;YACrC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,YAAY,CAClC,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,QAAQ,EACR,aAAa,EACb,OAAO,EACP,OAAO,CACV,CAAC;YACF,OAAO,OAAO,CAAC;QACnB,CAAC;QACD,WAAW,EAAE,cAAc;QAC3B,UAAU;KACb,CAAC,CAAC;IAEH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,QAAQ,EAAE,EAAE,EAAE;YACd,SAAS,EAAE,CAAC;SACf;IACL,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;IAE9B,OAAO;QACH,WAAW;QACX,SAAS;QACT,eAAe,EAAE,QAAQ;QACzB,OAAO,EAAE,IAAI;KAChB,CAAC;AACN,CAAC;AAvCD,8DAuCC"}
|
package/build/intl/index.d.ts
CHANGED
package/build/intl/index.js
CHANGED
|
@@ -13,14 +13,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.localeConfig = void 0;
|
|
21
17
|
__exportStar(require("./languages"), exports);
|
|
22
18
|
__exportStar(require("./locale"), exports);
|
|
23
|
-
var localeConfig_1 = require("./localeConfig");
|
|
24
|
-
Object.defineProperty(exports, "localeConfig", { enumerable: true, get: function () { return __importDefault(localeConfig_1).default; } });
|
|
25
|
-
__exportStar(require("./localeObject"), exports);
|
|
26
19
|
//# sourceMappingURL=index.js.map
|
package/build/intl/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intl/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intl/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB"}
|
|
@@ -1,49 +1,6 @@
|
|
|
1
|
-
import type { NewsroomLanguageSettings
|
|
2
|
-
import { LocaleObject } from './localeObject';
|
|
3
|
-
/**
|
|
4
|
-
* @returns the display name of the locale in its native language
|
|
5
|
-
*
|
|
6
|
-
* If there's only one culture used in a specific language,
|
|
7
|
-
* we strip the culture name completely.
|
|
8
|
-
*
|
|
9
|
-
* Examples:
|
|
10
|
-
* - English (Global), Spanish (Spain)
|
|
11
|
-
* - -> English, Spanish
|
|
12
|
-
* - English (Global), English (UK), Spanish (Spain)
|
|
13
|
-
* - -> English (Global), English (UK), Spanish
|
|
14
|
-
*/
|
|
15
|
-
export declare function getLanguageDisplayName(language: NewsroomLanguageSettings, languages: NewsroomLanguageSettings[]): string;
|
|
16
|
-
/**
|
|
17
|
-
* @returns Language set as default in the Newsroom Settings.
|
|
18
|
-
*/
|
|
19
|
-
export declare function getDefaultLanguage(languages: NewsroomLanguageSettings[]): NewsroomLanguageSettings;
|
|
20
|
-
/**
|
|
21
|
-
* @returns Only languages having at least one published story
|
|
22
|
-
*/
|
|
23
|
-
export declare function getUsedLanguages(languages: NewsroomLanguageSettings[]): NewsroomLanguageSettings[];
|
|
24
|
-
export declare function getLanguageByExactLocaleCode(languages: NewsroomLanguageSettings[], locale: LocaleObject): NewsroomLanguageSettings | undefined;
|
|
25
|
-
export declare function getLanguageByNeutralLocaleCode(languages: NewsroomLanguageSettings[], locale: LocaleObject): NewsroomLanguageSettings | undefined;
|
|
26
|
-
export declare function getLanguageByShortRegionCode(languages: NewsroomLanguageSettings[], locale: LocaleObject): NewsroomLanguageSettings | undefined;
|
|
1
|
+
import type { NewsroomLanguageSettings } from '@prezly/sdk';
|
|
27
2
|
/**
|
|
28
3
|
* Retrieve a culture with fallback to legacy codes support.
|
|
29
4
|
* Pulled from https://github.com/prezly/prezly/blob/de9900d9890a33502780494aa3fb85c9a732b3c3/lib/model/CulturePeer.php#L91-L114
|
|
30
5
|
*/
|
|
31
6
|
export declare function getLanguageFromNextLocaleIsoCode(languages: NewsroomLanguageSettings[], nextLocaleIsoCode?: string): NewsroomLanguageSettings | undefined;
|
|
32
|
-
export declare function getLanguageFromStory(languages: NewsroomLanguageSettings[], story: Story): NewsroomLanguageSettings | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* Extracts company information for the selected locale
|
|
35
|
-
*/
|
|
36
|
-
export declare function getCompanyInformation(languages: NewsroomLanguageSettings[], locale: LocaleObject): import("@prezly/sdk").NewsroomCompanyInformation;
|
|
37
|
-
/**
|
|
38
|
-
* Get newsroom notifications for the selected locale
|
|
39
|
-
*/
|
|
40
|
-
export declare function getNotifications(languages: NewsroomLanguageSettings[], locale: LocaleObject): import("@prezly/sdk").Notification<string>[];
|
|
41
|
-
/**
|
|
42
|
-
* Get the shortest locale code possible from full locale code
|
|
43
|
-
* First: try shorting to neutral language code (there should be no locales with the same language code)
|
|
44
|
-
* Then: try shorting to region code (there should be no locales with the same region code)
|
|
45
|
-
* Finally: return the original locale code (shorting is not possible)
|
|
46
|
-
*
|
|
47
|
-
* @param locale A LocaleObject constructed from FULL locale code (taken straight from the selected language)
|
|
48
|
-
*/
|
|
49
|
-
export declare function getShortestLocaleCode(languages: NewsroomLanguageSettings[], locale: LocaleObject): string | false;
|
package/build/intl/languages.js
CHANGED
|
@@ -1,173 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getLanguageFromNextLocaleIsoCode = void 0;
|
|
4
|
+
const theme_kit_core_1 = require("@prezly/theme-kit-core");
|
|
4
5
|
const locale_1 = require("./locale");
|
|
5
|
-
const localeObject_1 = require("./localeObject");
|
|
6
|
-
function isOnlyCulture(culture, languages) {
|
|
7
|
-
const numberOfLanguages = languages.filter(({ locale: { language_code } }) => language_code === culture.language_code).length;
|
|
8
|
-
return numberOfLanguages === 1;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* @returns the display name of the locale in its native language
|
|
12
|
-
*
|
|
13
|
-
* If there's only one culture used in a specific language,
|
|
14
|
-
* we strip the culture name completely.
|
|
15
|
-
*
|
|
16
|
-
* Examples:
|
|
17
|
-
* - English (Global), Spanish (Spain)
|
|
18
|
-
* - -> English, Spanish
|
|
19
|
-
* - English (Global), English (UK), Spanish (Spain)
|
|
20
|
-
* - -> English (Global), English (UK), Spanish
|
|
21
|
-
*/
|
|
22
|
-
function getLanguageDisplayName(language, languages) {
|
|
23
|
-
const { locale } = language;
|
|
24
|
-
if (isOnlyCulture(locale, languages)) {
|
|
25
|
-
const cultureNameIndex = locale.native_name.indexOf('(');
|
|
26
|
-
if (cultureNameIndex !== -1) {
|
|
27
|
-
return locale.native_name.slice(0, cultureNameIndex - 1);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return locale.native_name;
|
|
31
|
-
}
|
|
32
|
-
exports.getLanguageDisplayName = getLanguageDisplayName;
|
|
33
|
-
/**
|
|
34
|
-
* @returns Language set as default in the Newsroom Settings.
|
|
35
|
-
*/
|
|
36
|
-
function getDefaultLanguage(languages) {
|
|
37
|
-
return languages.find(({ is_default }) => is_default) || languages[0];
|
|
38
|
-
}
|
|
39
|
-
exports.getDefaultLanguage = getDefaultLanguage;
|
|
40
|
-
/**
|
|
41
|
-
* @returns Only languages having at least one published story
|
|
42
|
-
*/
|
|
43
|
-
function getUsedLanguages(languages) {
|
|
44
|
-
return languages.filter((language) => language.public_stories_count > 0);
|
|
45
|
-
}
|
|
46
|
-
exports.getUsedLanguages = getUsedLanguages;
|
|
47
|
-
function getLanguageByExactLocaleCode(languages, locale) {
|
|
48
|
-
const localeCode = locale.toUnderscoreCode();
|
|
49
|
-
return languages.find(({ code }) => code === localeCode);
|
|
50
|
-
}
|
|
51
|
-
exports.getLanguageByExactLocaleCode = getLanguageByExactLocaleCode;
|
|
52
|
-
// See https://github.com/prezly/prezly/blob/master/lib/model/CulturePeer.php#L123
|
|
53
|
-
function getLanguageByNeutralLocaleCode(languages, locale) {
|
|
54
|
-
const neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
55
|
-
// Prefer default language
|
|
56
|
-
const defaultLanguage = getDefaultLanguage(languages);
|
|
57
|
-
// TODO: This doesn't align with other methods logic
|
|
58
|
-
if (defaultLanguage.code === locale.toUnderscoreCode()) {
|
|
59
|
-
return defaultLanguage;
|
|
60
|
-
}
|
|
61
|
-
// Try to look in used cultures first (giving priority to used ones)
|
|
62
|
-
const usedLanguages = getUsedLanguages(languages);
|
|
63
|
-
const usedLanguage = usedLanguages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode);
|
|
64
|
-
if (usedLanguage) {
|
|
65
|
-
return usedLanguage;
|
|
66
|
-
}
|
|
67
|
-
// Search in all languages
|
|
68
|
-
return languages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode);
|
|
69
|
-
}
|
|
70
|
-
exports.getLanguageByNeutralLocaleCode = getLanguageByNeutralLocaleCode;
|
|
71
|
-
// See https://github.com/prezly/prezly/blob/master/lib/model/CulturePeer.php#L159
|
|
72
|
-
function getLanguageByShortRegionCode(languages, locale) {
|
|
73
|
-
const shortRegionCode = locale.toRegionCode();
|
|
74
|
-
// Prefer default language
|
|
75
|
-
const defaultLanguage = getDefaultLanguage(languages);
|
|
76
|
-
if (localeObject_1.LocaleObject.fromAnyCode(defaultLanguage.code).toRegionCode() === shortRegionCode) {
|
|
77
|
-
return defaultLanguage;
|
|
78
|
-
}
|
|
79
|
-
// Try to look in used cultures first (giving priority to used ones)
|
|
80
|
-
const usedLanguages = getUsedLanguages(languages);
|
|
81
|
-
const usedLanguage = usedLanguages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode);
|
|
82
|
-
if (usedLanguage) {
|
|
83
|
-
return usedLanguage;
|
|
84
|
-
}
|
|
85
|
-
// Search in all languages
|
|
86
|
-
return languages.find(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode);
|
|
87
|
-
}
|
|
88
|
-
exports.getLanguageByShortRegionCode = getLanguageByShortRegionCode;
|
|
89
6
|
/**
|
|
90
7
|
* Retrieve a culture with fallback to legacy codes support.
|
|
91
8
|
* Pulled from https://github.com/prezly/prezly/blob/de9900d9890a33502780494aa3fb85c9a732b3c3/lib/model/CulturePeer.php#L91-L114
|
|
92
9
|
*/
|
|
93
10
|
function getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode) {
|
|
94
|
-
const defaultLanguage = getDefaultLanguage(languages);
|
|
11
|
+
const defaultLanguage = (0, theme_kit_core_1.getDefaultLanguage)(languages);
|
|
95
12
|
if (!nextLocaleIsoCode || nextLocaleIsoCode === locale_1.DUMMY_DEFAULT_LOCALE) {
|
|
96
13
|
return defaultLanguage;
|
|
97
14
|
}
|
|
98
|
-
const locale =
|
|
15
|
+
const locale = theme_kit_core_1.LocaleObject.fromAnyCode(nextLocaleIsoCode);
|
|
99
16
|
let targetLanguage;
|
|
100
17
|
if (nextLocaleIsoCode.length >= 2 && nextLocaleIsoCode.length <= 4) {
|
|
101
18
|
// The order of methods here is reversed from `getShortestLocaleCode`, so that the logic "unwraps" the possible variants with no collisions
|
|
102
19
|
targetLanguage =
|
|
103
|
-
getLanguageByExactLocaleCode(languages, locale) ||
|
|
104
|
-
getLanguageByShortRegionCode(languages, locale) ||
|
|
105
|
-
getLanguageByNeutralLocaleCode(languages, locale);
|
|
20
|
+
(0, theme_kit_core_1.getLanguageByExactLocaleCode)(languages, locale) ||
|
|
21
|
+
(0, theme_kit_core_1.getLanguageByShortRegionCode)(languages, locale) ||
|
|
22
|
+
(0, theme_kit_core_1.getLanguageByNeutralLocaleCode)(languages, locale);
|
|
106
23
|
}
|
|
107
24
|
else {
|
|
108
|
-
targetLanguage = getLanguageByExactLocaleCode(languages, locale);
|
|
25
|
+
targetLanguage = (0, theme_kit_core_1.getLanguageByExactLocaleCode)(languages, locale);
|
|
109
26
|
}
|
|
110
27
|
return targetLanguage;
|
|
111
28
|
}
|
|
112
29
|
exports.getLanguageFromNextLocaleIsoCode = getLanguageFromNextLocaleIsoCode;
|
|
113
|
-
function getLanguageFromStory(languages, story) {
|
|
114
|
-
const { code: storyLocaleCode } = story.culture;
|
|
115
|
-
return languages.find(({ code }) => code === storyLocaleCode);
|
|
116
|
-
}
|
|
117
|
-
exports.getLanguageFromStory = getLanguageFromStory;
|
|
118
|
-
/**
|
|
119
|
-
* Extracts company information for the selected locale
|
|
120
|
-
*/
|
|
121
|
-
function getCompanyInformation(languages, locale) {
|
|
122
|
-
const currentLanguage = getLanguageByExactLocaleCode(languages, locale) || getDefaultLanguage(languages);
|
|
123
|
-
return currentLanguage.company_information;
|
|
124
|
-
}
|
|
125
|
-
exports.getCompanyInformation = getCompanyInformation;
|
|
126
|
-
/**
|
|
127
|
-
* Get newsroom notifications for the selected locale
|
|
128
|
-
*/
|
|
129
|
-
function getNotifications(languages, locale) {
|
|
130
|
-
const currentLanguage = getLanguageByExactLocaleCode(languages, locale) || getDefaultLanguage(languages);
|
|
131
|
-
return currentLanguage.notifications;
|
|
132
|
-
}
|
|
133
|
-
exports.getNotifications = getNotifications;
|
|
134
|
-
/**
|
|
135
|
-
* Get the shortest locale code possible from full locale code
|
|
136
|
-
* First: try shorting to neutral language code (there should be no locales with the same language code)
|
|
137
|
-
* Then: try shorting to region code (there should be no locales with the same region code)
|
|
138
|
-
* Finally: return the original locale code (shorting is not possible)
|
|
139
|
-
*
|
|
140
|
-
* @param locale A LocaleObject constructed from FULL locale code (taken straight from the selected language)
|
|
141
|
-
*/
|
|
142
|
-
function getShortestLocaleCode(languages, locale) {
|
|
143
|
-
const localeCode = locale.toUnderscoreCode();
|
|
144
|
-
const defaultLanguage = getDefaultLanguage(languages);
|
|
145
|
-
// If it's a default locale, return false (no locale needed in URL)
|
|
146
|
-
if (localeCode === defaultLanguage.code) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
// Try shorting to neutral language code
|
|
150
|
-
const neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
151
|
-
const matchingLanguagesByNeutralCode = languages.filter(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === neutralLanguageCode ||
|
|
152
|
-
code === neutralLanguageCode);
|
|
153
|
-
if (matchingLanguagesByNeutralCode.length === 1) {
|
|
154
|
-
return neutralLanguageCode;
|
|
155
|
-
}
|
|
156
|
-
// Try shorting to region code
|
|
157
|
-
const shortRegionCode = locale.toRegionCode();
|
|
158
|
-
const matchingLanguagesByRegionCode = languages.filter(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toRegionCode() === shortRegionCode);
|
|
159
|
-
// Prevent collision with neutral language codes
|
|
160
|
-
const lowerCasedShortRegionCode = shortRegionCode.toLowerCase();
|
|
161
|
-
const mathchingNeutralLanguagesByRegionCode = languages.filter(({ code }) => localeObject_1.LocaleObject.fromAnyCode(code).toNeutralLanguageCode() === lowerCasedShortRegionCode ||
|
|
162
|
-
code === lowerCasedShortRegionCode);
|
|
163
|
-
if (matchingLanguagesByRegionCode.length === 1 &&
|
|
164
|
-
// If there are 2 or more matching neutral languages, it means that there are no languages that can be shortened to neutral code
|
|
165
|
-
mathchingNeutralLanguagesByRegionCode.length !== 1 &&
|
|
166
|
-
// We don't want just numbers in our region code
|
|
167
|
-
Number.isNaN(Number(shortRegionCode))) {
|
|
168
|
-
return shortRegionCode;
|
|
169
|
-
}
|
|
170
|
-
return localeCode;
|
|
171
|
-
}
|
|
172
|
-
exports.getShortestLocaleCode = getShortestLocaleCode;
|
|
173
30
|
//# sourceMappingURL=languages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"languages.js","sourceRoot":"","sources":["../../src/intl/languages.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"languages.js","sourceRoot":"","sources":["../../src/intl/languages.ts"],"names":[],"mappings":";;;AACA,2DAMgC;AAEhC,qCAAgD;AAEhD;;;GAGG;AACH,SAAgB,gCAAgC,CAC5C,SAAqC,EACrC,iBAA0B;IAE1B,MAAM,eAAe,GAAG,IAAA,mCAAkB,EAAC,SAAS,CAAC,CAAC;IAEtD,IAAI,CAAC,iBAAiB,IAAI,iBAAiB,KAAK,6BAAoB,EAAE;QAClE,OAAO,eAAe,CAAC;KAC1B;IAED,MAAM,MAAM,GAAG,6BAAY,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC3D,IAAI,cAAoD,CAAC;IAEzD,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,IAAI,iBAAiB,CAAC,MAAM,IAAI,CAAC,EAAE;QAChE,2IAA2I;QAC3I,cAAc;YACV,IAAA,6CAA4B,EAAC,SAAS,EAAE,MAAM,CAAC;gBAC/C,IAAA,6CAA4B,EAAC,SAAS,EAAE,MAAM,CAAC;gBAC/C,IAAA,+CAA8B,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;KACzD;SAAM;QACH,cAAc,GAAG,IAAA,6CAA4B,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;KACpE;IAED,OAAO,cAAc,CAAC;AAC1B,CAAC;AAxBD,4EAwBC"}
|
package/build/intl/locale.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Redirect } from 'next';
|
|
3
3
|
import type { ParsedUrlQuery } from 'querystring';
|
|
4
|
-
import { LocaleObject } from './localeObject';
|
|
5
|
-
export declare const DEFAULT_LOCALE = "en";
|
|
6
4
|
export declare const DUMMY_DEFAULT_LOCALE = "qps-ploc";
|
|
7
|
-
/**
|
|
8
|
-
* Use this function to determine which translations file you should load from `@prezly/themes-intl-mesages` package.
|
|
9
|
-
* See https://github.com/prezly/theme-nextjs-bea/blob/main/utils/lang.ts for a usage example.
|
|
10
|
-
*/
|
|
11
|
-
export declare function getSupportedLocaleIsoCode(locale: LocaleObject): string;
|
|
12
5
|
export declare function getRedirectToCanonicalLocale(shortestLocaleCode: string | false, nextLocaleIsoCode: string | undefined, redirectPath: string, query?: ParsedUrlQuery): Redirect | undefined;
|
|
13
|
-
export declare function getLocaleDirection(locale: LocaleObject): 'ltr' | 'rtl';
|
package/build/intl/locale.js
CHANGED
|
@@ -1,99 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getRedirectToCanonicalLocale = exports.DUMMY_DEFAULT_LOCALE = void 0;
|
|
4
|
+
const theme_kit_core_1 = require("@prezly/theme-kit-core");
|
|
4
5
|
const querystring_1 = require("querystring");
|
|
5
|
-
const localeObject_1 = require("./localeObject");
|
|
6
|
-
exports.DEFAULT_LOCALE = 'en';
|
|
7
6
|
// We use pseudo locale used for localization testing, to reliably determine if we need to fallback to the default newsroom language
|
|
8
7
|
exports.DUMMY_DEFAULT_LOCALE = 'qps-ploc';
|
|
9
|
-
/**
|
|
10
|
-
* This a list of locales that Prezly has translations for. Each code represents a language file in the `@prezly/themes-intl-messages` package.
|
|
11
|
-
* See https://github.com/prezly/themes-intl-messages for more info.
|
|
12
|
-
*/
|
|
13
|
-
const SUPPORTED_LOCALES = [
|
|
14
|
-
'af',
|
|
15
|
-
'ar',
|
|
16
|
-
'az',
|
|
17
|
-
'be',
|
|
18
|
-
'bg',
|
|
19
|
-
'cs',
|
|
20
|
-
'da',
|
|
21
|
-
'de',
|
|
22
|
-
'el',
|
|
23
|
-
'en',
|
|
24
|
-
'es',
|
|
25
|
-
'et',
|
|
26
|
-
'fi',
|
|
27
|
-
'fil',
|
|
28
|
-
'fr',
|
|
29
|
-
'ga',
|
|
30
|
-
'he',
|
|
31
|
-
'hi',
|
|
32
|
-
'hr',
|
|
33
|
-
'hu',
|
|
34
|
-
'id',
|
|
35
|
-
'it',
|
|
36
|
-
'ja',
|
|
37
|
-
'kk',
|
|
38
|
-
'ko',
|
|
39
|
-
'lt',
|
|
40
|
-
'lv',
|
|
41
|
-
'mt',
|
|
42
|
-
'nl',
|
|
43
|
-
'no',
|
|
44
|
-
'pl',
|
|
45
|
-
'pt-BR',
|
|
46
|
-
'pt',
|
|
47
|
-
'ro',
|
|
48
|
-
'ru',
|
|
49
|
-
'sk',
|
|
50
|
-
'sl',
|
|
51
|
-
'sv',
|
|
52
|
-
'sw',
|
|
53
|
-
'th',
|
|
54
|
-
'tr',
|
|
55
|
-
'uk',
|
|
56
|
-
'ur',
|
|
57
|
-
'uz',
|
|
58
|
-
'vi',
|
|
59
|
-
'zh-CN',
|
|
60
|
-
'zh-TW',
|
|
61
|
-
];
|
|
62
|
-
/**
|
|
63
|
-
* Use this function to determine which translations file you should load from `@prezly/themes-intl-mesages` package.
|
|
64
|
-
* See https://github.com/prezly/theme-nextjs-bea/blob/main/utils/lang.ts for a usage example.
|
|
65
|
-
*/
|
|
66
|
-
function getSupportedLocaleIsoCode(locale) {
|
|
67
|
-
const localeIsoCode = locale.toHyphenCode();
|
|
68
|
-
const isSupportedLocale = localeIsoCode.length >= 2 && SUPPORTED_LOCALES.includes(localeIsoCode);
|
|
69
|
-
if (isSupportedLocale) {
|
|
70
|
-
return localeIsoCode;
|
|
71
|
-
}
|
|
72
|
-
const language = locale.toNeutralLanguageCode();
|
|
73
|
-
const isSupportedLanguage = SUPPORTED_LOCALES.includes(language);
|
|
74
|
-
if (isSupportedLanguage) {
|
|
75
|
-
return language;
|
|
76
|
-
}
|
|
77
|
-
// Custom mapping for Chinese locales
|
|
78
|
-
if (localeIsoCode.toLowerCase() === 'zh-hant') {
|
|
79
|
-
return 'zh-TW';
|
|
80
|
-
}
|
|
81
|
-
if (localeIsoCode.toLowerCase() === 'zh-hk') {
|
|
82
|
-
return 'zh-CN';
|
|
83
|
-
}
|
|
84
|
-
// This code should never be reached, because locale code check is happening in `LocaleObject.fromAnyCode`
|
|
85
|
-
// eslint-disable-next-line no-console
|
|
86
|
-
console.warn('Unsupported locale provided. Please use `LocaleObject.fromAnyCode` to ensure you are using a correct language code');
|
|
87
|
-
return exports.DEFAULT_LOCALE;
|
|
88
|
-
}
|
|
89
|
-
exports.getSupportedLocaleIsoCode = getSupportedLocaleIsoCode;
|
|
90
8
|
function getRedirectToCanonicalLocale(shortestLocaleCode, nextLocaleIsoCode, redirectPath, query) {
|
|
91
9
|
// No need to redirect if no particular locale was requested by the application
|
|
92
10
|
if (!nextLocaleIsoCode || nextLocaleIsoCode === exports.DUMMY_DEFAULT_LOCALE) {
|
|
93
11
|
return undefined;
|
|
94
12
|
}
|
|
95
13
|
const shortestLocaleSlug = shortestLocaleCode
|
|
96
|
-
?
|
|
14
|
+
? theme_kit_core_1.LocaleObject.fromAnyCode(shortestLocaleCode).toUrlSlug()
|
|
97
15
|
: shortestLocaleCode;
|
|
98
16
|
if (shortestLocaleSlug !== nextLocaleIsoCode) {
|
|
99
17
|
const prefixedPath = redirectPath && !redirectPath.startsWith('/') ? `/${redirectPath}` : redirectPath;
|
|
@@ -108,12 +26,4 @@ function getRedirectToCanonicalLocale(shortestLocaleCode, nextLocaleIsoCode, red
|
|
|
108
26
|
return undefined;
|
|
109
27
|
}
|
|
110
28
|
exports.getRedirectToCanonicalLocale = getRedirectToCanonicalLocale;
|
|
111
|
-
function getLocaleDirection(locale) {
|
|
112
|
-
const neutralLanguageCode = locale.toNeutralLanguageCode();
|
|
113
|
-
if (['ar', 'he', 'ur'].includes(neutralLanguageCode)) {
|
|
114
|
-
return 'rtl';
|
|
115
|
-
}
|
|
116
|
-
return 'ltr';
|
|
117
|
-
}
|
|
118
|
-
exports.getLocaleDirection = getLocaleDirection;
|
|
119
29
|
//# sourceMappingURL=locale.js.map
|
package/build/intl/locale.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"locale.js","sourceRoot":"","sources":["../../src/intl/locale.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AAGtD,6CAAwC;AAExC,oIAAoI;AACvH,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAE/C,SAAgB,4BAA4B,CACxC,kBAAkC,EAClC,iBAAqC,EACrC,YAAoB,EACpB,KAAsB;IAEtB,+EAA+E;IAC/E,IAAI,CAAC,iBAAiB,IAAI,iBAAiB,KAAK,4BAAoB,EAAE;QAClE,OAAO,SAAS,CAAC;KACpB;IAED,MAAM,kBAAkB,GAAG,kBAAkB;QACzC,CAAC,CAAC,6BAAY,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,SAAS,EAAE;QAC1D,CAAC,CAAC,kBAAkB,CAAC;IAEzB,IAAI,kBAAkB,KAAK,iBAAiB,EAAE;QAC1C,MAAM,YAAY,GACd,YAAY,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;QAEtF,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,IAAA,uBAAS,EAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAErD,OAAO;YACH,WAAW,EAAE,kBAAkB;gBAC3B,CAAC,CAAC,IAAI,kBAAkB,GAAG,YAAY,GAAG,QAAQ,EAAE;gBACpD,CAAC,CAAC,GAAG,YAAY,GAAG,QAAQ,EAAE;YAClC,SAAS,EAAE,KAAK;SACnB,CAAC;KACL;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AA9BD,oEA8BC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Category, ExtendedStory, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset, Notification } from '@prezly/sdk';
|
|
2
|
+
import type { AlgoliaSettings } from '@prezly/theme-kit-core';
|
|
3
|
+
import { LocaleObject } from '@prezly/theme-kit-core';
|
|
2
4
|
import type { PropsWithChildren } from 'react';
|
|
3
|
-
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
|
-
import { LocaleObject } from '../intl';
|
|
5
5
|
export interface NewsroomContextType {
|
|
6
6
|
/**
|
|
7
7
|
* Basic newsroom information: newsroom logos, settings, etc.
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NewsroomContextProvider = exports.NewsroomContext = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const theme_kit_core_1 = require("@prezly/theme-kit-core");
|
|
5
6
|
const react_1 = require("react");
|
|
6
|
-
const intl_1 = require("../intl");
|
|
7
7
|
exports.NewsroomContext = (0, react_1.createContext)(undefined);
|
|
8
8
|
/**
|
|
9
9
|
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
10
10
|
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
11
11
|
*/
|
|
12
12
|
function NewsroomContextProvider({ categories, contacts, newsroom, currentCategory, currentStory, companyInformation, languages, localeCode, notifications, themePreset, algoliaSettings, children, }) {
|
|
13
|
-
const locale = (0, react_1.useMemo)(() =>
|
|
13
|
+
const locale = (0, react_1.useMemo)(() => theme_kit_core_1.LocaleObject.fromAnyCode(localeCode || theme_kit_core_1.DEFAULT_LOCALE), [localeCode]);
|
|
14
14
|
return ((0, jsx_runtime_1.jsx)(exports.NewsroomContext.Provider, { value: {
|
|
15
15
|
categories,
|
|
16
16
|
contacts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;AAWA,iCAA+C;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;AAWA,2DAAsE;AAEtE,iCAA+C;AAwDlC,QAAA,eAAe,GAAG,IAAA,qBAAa,EAAkC,SAAS,CAAC,CAAC;AAEzF;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,EACpC,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,aAAa,EACb,WAAW,EACX,eAAe,EACf,QAAQ,GAC8B;IACtC,MAAM,MAAM,GAAG,IAAA,eAAO,EAClB,GAAG,EAAE,CAAC,6BAAY,CAAC,WAAW,CAAC,UAAU,IAAI,+BAAc,CAAC,EAC5D,CAAC,UAAU,CAAC,CACf,CAAC;IAEF,OAAO,CACH,uBAAC,uBAAe,CAAC,QAAQ,IACrB,KAAK,EAAE;YACH,UAAU;YACV,QAAQ;YACR,QAAQ;YACR,eAAe;YACf,YAAY;YACZ,kBAAkB;YAClB,SAAS;YACT,MAAM;YACN,aAAa;YACb,WAAW;YACX,eAAe;SAClB,YAEA,QAAQ,GACc,CAC9B,CAAC;AACN,CAAC;AAtCD,0DAsCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useAlgoliaSettings(): import("
|
|
1
|
+
export declare function useAlgoliaSettings(): import("@prezly/theme-kit-core").AlgoliaSettings;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useCurrentLocale(): import("
|
|
1
|
+
export declare function useCurrentLocale(): import("@prezly/theme-kit-core").LocaleObject;
|