@prezly/theme-kit-nextjs 1.7.0 → 1.7.2-0
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 +8 -0
- package/build/data-fetching/api/PrezlyApi.d.ts +9 -4
- package/build/data-fetching/api/PrezlyApi.js +73 -2
- package/build/data-fetching/api/PrezlyApi.js.map +1 -1
- package/build/data-fetching/api/queries.d.ts +23 -0
- package/build/data-fetching/api/queries.js +10 -1
- package/build/data-fetching/api/queries.js.map +1 -1
- package/build/data-fetching/lib/index.d.ts +1 -0
- package/build/data-fetching/lib/index.js +3 -1
- package/build/data-fetching/lib/index.js.map +1 -1
- package/build/data-fetching/lib/isSdkError.d.ts +2 -0
- package/build/data-fetching/lib/isSdkError.js +8 -0
- package/build/data-fetching/lib/isSdkError.js.map +1 -0
- package/build/newsroom-context/context.d.ts +6 -2
- package/build/newsroom-context/context.js +2 -1
- package/build/newsroom-context/context.js.map +1 -1
- package/build/newsroom-context/hooks/index.d.ts +1 -0
- package/build/newsroom-context/hooks/index.js +1 -0
- package/build/newsroom-context/hooks/index.js.map +1 -1
- package/build/newsroom-context/hooks/useEmbedStory.d.ts +2 -0
- package/build/newsroom-context/hooks/useEmbedStory.js +13 -0
- package/build/newsroom-context/hooks/useEmbedStory.js.map +1 -0
- package/build/types.d.ts +10 -0
- package/package.json +2 -1
- package/src/data-fetching/api/PrezlyApi.ts +44 -3
- package/src/data-fetching/api/queries.ts +10 -0
- package/src/data-fetching/lib/index.ts +1 -0
- package/src/data-fetching/lib/isSdkError.ts +5 -0
- package/src/newsroom-context/context.tsx +7 -0
- package/src/newsroom-context/hooks/index.ts +1 -0
- package/src/newsroom-context/hooks/useEmbedStory.ts +13 -0
- package/src/types.ts +12 -0
package/README.md
CHANGED
|
@@ -102,6 +102,14 @@ type AnyPageProps = Record<string, any>;
|
|
|
102
102
|
function App({ Component, pageProps }: AppProps<AnyPageProps>) {
|
|
103
103
|
const { newsroomContextProps, ...customPageProps } = pageProps as PageProps & AnyPageProps;
|
|
104
104
|
|
|
105
|
+
// `newsroomContextProps` can be undefined, if there was error when fetching the newsroom props.
|
|
106
|
+
// This can happen due to connection issues, or incorrect credentials in your .env file.
|
|
107
|
+
// In this case, a 500 error page would be rendered, which shouldn't rely on the Newsroom Context (especially when statically generated).
|
|
108
|
+
if(!newsroomContextProps) {
|
|
109
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
110
|
+
return <Component {...customPageProps} />
|
|
111
|
+
}
|
|
112
|
+
|
|
105
113
|
/* eslint-disable react/jsx-props-no-spreading */
|
|
106
114
|
return (
|
|
107
115
|
<NewsroomContextProvider {...newsroomContextProps}>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { Category, ExtraStoryFields, Newsroom, NewsroomLanguageSettings, Story } from '@prezly/sdk';
|
|
2
|
+
import type { Category, ExtendedStory, ExtraStoryFields, Newsroom, NewsroomLanguageSettings, Story } from '@prezly/sdk';
|
|
3
3
|
import PrezlySDK from '@prezly/sdk';
|
|
4
4
|
import type { IncomingMessage } from 'http';
|
|
5
5
|
import type { PageProps, ServerSidePageProps } from '../../types';
|
|
@@ -20,7 +20,7 @@ export declare class PrezlyApi {
|
|
|
20
20
|
private readonly newsroomUuid;
|
|
21
21
|
private readonly themeUuid;
|
|
22
22
|
constructor(accessToken: string, newsroomUuid: Newsroom['uuid'], themeUuid?: string);
|
|
23
|
-
getStory(uuid: string): Promise<
|
|
23
|
+
getStory(uuid: string): Promise<ExtendedStory | null>;
|
|
24
24
|
getNewsroom(): Promise<Newsroom>;
|
|
25
25
|
getNewsroomContacts(): Promise<import("@prezly/sdk").NewsroomContact[]>;
|
|
26
26
|
getNewsroomLanguages(): Promise<NewsroomLanguageSettings[]>;
|
|
@@ -36,16 +36,21 @@ export declare class PrezlyApi {
|
|
|
36
36
|
stories: Story[];
|
|
37
37
|
storiesTotal: number;
|
|
38
38
|
}>;
|
|
39
|
-
getStoryBySlug(slug: string): Promise<
|
|
39
|
+
getStoryBySlug(slug: string): Promise<ExtendedStory | null>;
|
|
40
40
|
getCategories(): Promise<Category[]>;
|
|
41
41
|
getCategoryBySlug(slug: string): Promise<Category | undefined>;
|
|
42
42
|
searchStories: typeof PrezlySDK.prototype.stories.search;
|
|
43
43
|
getGalleries({ page, pageSize }: GetGalleriesOptions): Promise<import("@prezly/sdk/dist/Sdk/NewsroomGalleries/types").NewsroomGalleriesListResponse>;
|
|
44
|
-
getGallery(uuid: string): Promise<import("@prezly/sdk").NewsroomGallery>;
|
|
44
|
+
getGallery(uuid: string): Promise<import("@prezly/sdk").NewsroomGallery | null>;
|
|
45
45
|
/**
|
|
46
46
|
* In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
|
|
47
47
|
*/
|
|
48
48
|
getThemePreset(): Promise<import("@prezly/sdk").NewsroomThemePreset | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns summaries for stories embed in the current story (like in Bookmark Blocks)
|
|
51
|
+
* @returns a map of `Story` object with their UUID as keys
|
|
52
|
+
*/
|
|
53
|
+
getEmbedStories(story: ExtendedStory): Promise<Record<string, Story>>;
|
|
49
54
|
getNewsroomServerSideProps(request: IncomingMessage | undefined, nextLocaleIsoCode?: string, story?: Story): Promise<PageProps & ServerSidePageProps>;
|
|
50
55
|
}
|
|
51
56
|
export {};
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -57,8 +68,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
57
68
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
69
|
exports.PrezlyApi = void 0;
|
|
59
70
|
var sdk_1 = __importDefault(require("@prezly/sdk"));
|
|
71
|
+
var slate_types_1 = require("@prezly/slate-types");
|
|
60
72
|
var intl_1 = require("../../intl");
|
|
61
73
|
var constants_1 = require("../constants");
|
|
74
|
+
var lib_1 = require("../lib");
|
|
62
75
|
var getAlgoliaSettings_1 = require("../lib/getAlgoliaSettings");
|
|
63
76
|
var languages_1 = require("./languages");
|
|
64
77
|
var queries_1 = require("./queries");
|
|
@@ -81,7 +94,24 @@ var PrezlyApi = /** @class */ (function () {
|
|
|
81
94
|
this.themeUuid = themeUuid;
|
|
82
95
|
}
|
|
83
96
|
PrezlyApi.prototype.getStory = function (uuid) {
|
|
84
|
-
return this
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var error_1;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0:
|
|
102
|
+
_a.trys.push([0, 2, , 3]);
|
|
103
|
+
return [4 /*yield*/, this.sdk.stories.get(uuid)];
|
|
104
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
105
|
+
case 2:
|
|
106
|
+
error_1 = _a.sent();
|
|
107
|
+
if ((0, lib_1.isSdkError)(error_1) && error_1.status === 404) {
|
|
108
|
+
return [2 /*return*/, null];
|
|
109
|
+
}
|
|
110
|
+
throw error_1;
|
|
111
|
+
case 3: return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
85
115
|
};
|
|
86
116
|
PrezlyApi.prototype.getNewsroom = function () {
|
|
87
117
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -255,8 +285,21 @@ var PrezlyApi = /** @class */ (function () {
|
|
|
255
285
|
};
|
|
256
286
|
PrezlyApi.prototype.getGallery = function (uuid) {
|
|
257
287
|
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
+
var error_2;
|
|
258
289
|
return __generator(this, function (_a) {
|
|
259
|
-
|
|
290
|
+
switch (_a.label) {
|
|
291
|
+
case 0:
|
|
292
|
+
_a.trys.push([0, 2, , 3]);
|
|
293
|
+
return [4 /*yield*/, this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid)];
|
|
294
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
295
|
+
case 2:
|
|
296
|
+
error_2 = _a.sent();
|
|
297
|
+
if ((0, lib_1.isSdkError)(error_2) && error_2.status === 404) {
|
|
298
|
+
return [2 /*return*/, null];
|
|
299
|
+
}
|
|
300
|
+
throw error_2;
|
|
301
|
+
case 3: return [2 /*return*/];
|
|
302
|
+
}
|
|
260
303
|
});
|
|
261
304
|
});
|
|
262
305
|
};
|
|
@@ -273,6 +316,34 @@ var PrezlyApi = /** @class */ (function () {
|
|
|
273
316
|
});
|
|
274
317
|
});
|
|
275
318
|
};
|
|
319
|
+
/**
|
|
320
|
+
* Returns summaries for stories embed in the current story (like in Bookmark Blocks)
|
|
321
|
+
* @returns a map of `Story` object with their UUID as keys
|
|
322
|
+
*/
|
|
323
|
+
PrezlyApi.prototype.getEmbedStories = function (story) {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
325
|
+
var nodes, embedUuids, jsonQuery, stories;
|
|
326
|
+
return __generator(this, function (_a) {
|
|
327
|
+
switch (_a.label) {
|
|
328
|
+
case 0:
|
|
329
|
+
nodes = JSON.parse(story.content);
|
|
330
|
+
return [4 /*yield*/, Promise.all(nodes.children.filter(slate_types_1.isStoryBookmarkNode).map(function (c) { return c.story.uuid; }))];
|
|
331
|
+
case 1:
|
|
332
|
+
embedUuids = _a.sent();
|
|
333
|
+
jsonQuery = JSON.stringify((0, queries_1.getEmbedStoriesQuery)(this.newsroomUuid, embedUuids));
|
|
334
|
+
return [4 /*yield*/, this.searchStories({
|
|
335
|
+
jsonQuery: jsonQuery,
|
|
336
|
+
})];
|
|
337
|
+
case 2:
|
|
338
|
+
stories = (_a.sent()).stories;
|
|
339
|
+
return [2 /*return*/, stories.reduce(function (result, embedStory) {
|
|
340
|
+
var _a;
|
|
341
|
+
return (__assign(__assign({}, result), (_a = {}, _a[embedStory.uuid] = embedStory, _a)));
|
|
342
|
+
}, {})];
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
};
|
|
276
347
|
PrezlyApi.prototype.getNewsroomServerSideProps = function (request, nextLocaleIsoCode, story) {
|
|
277
348
|
return __awaiter(this, void 0, void 0, function () {
|
|
278
349
|
var _a, newsroom, languages, categories, themePreset, currentLanguage, defaultLanguage, localeCode, locale, companyInformation, algoliaSettings;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrezlyApi.js","sourceRoot":"","sources":["../../../src/data-fetching/api/PrezlyApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrezlyApi.js","sourceRoot":"","sources":["../../../src/data-fetching/api/PrezlyApi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,oDAAoC;AAEpC,mDAA0D;AAG1D,mCAA0C;AAE1C,0CAAiD;AACjD,8BAAoC;AACpC,gEAA+D;AAE/D,yCAKqB;AACrB,qCAOmB;AAEnB,IAAM,kBAAkB,GAAc,MAAM,CAAC;AAiB7C;IAOI,mBAAY,WAAmB,EAAE,YAA8B,EAAE,SAAkB;QAAnF,iBAUC;;QAqID,kBAAa,GAA8C,UAAC,OAAO;YAC/D,OAAA,KAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAAhC,C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Ae,IAAI,eAAe,CAAA,KAAvC,CAAwC;wBAC1D,MAAM,GAAG,mBAAY,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;wBAG9C,kBAAkB,GAAG,IAAA,iCAAqB,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;wBAE9D,eAAe,GAAG,IAAA,uCAAkB,EAAC,OAAO,CAAC,CAAC;wBAEpD,sBAAO;gCACH,oBAAoB,EAAE;oCAClB,QAAQ,UAAA;oCACR,kBAAkB,oBAAA;oCAClB,UAAU,YAAA;oCACV,SAAS,WAAA;oCACT,UAAU,YAAA;oCACV,WAAW,aAAA;oCACX,eAAe,iBAAA;iCAClB;gCACD,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC;6BAC3C,EAAC;;;;KACL;IACL,gBAAC;AAAD,CAAC,AAnPD,IAmPC;AAnPY,8BAAS"}
|
|
@@ -21,6 +21,29 @@ export declare function getSlugQuery(newsroomUuid: string, slug: string): {
|
|
|
21
21
|
'newsroom.uuid'?: undefined;
|
|
22
22
|
})[];
|
|
23
23
|
};
|
|
24
|
+
export declare function getEmbedStoriesQuery(newsroomUuid: string, uuids: string[]): {
|
|
25
|
+
$and: ({
|
|
26
|
+
lifecycle_status: {
|
|
27
|
+
$in: string[];
|
|
28
|
+
};
|
|
29
|
+
visibility?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
visibility: {
|
|
32
|
+
$in: string[];
|
|
33
|
+
};
|
|
34
|
+
lifecycle_status?: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
'newsroom.uuid': {
|
|
37
|
+
$in: string[];
|
|
38
|
+
};
|
|
39
|
+
uuid?: undefined;
|
|
40
|
+
} | {
|
|
41
|
+
uuid: {
|
|
42
|
+
$in: string[];
|
|
43
|
+
};
|
|
44
|
+
'newsroom.uuid'?: undefined;
|
|
45
|
+
})[];
|
|
46
|
+
};
|
|
24
47
|
export declare function getStoriesQuery(newsroomUuid: string, categoryId?: number, localeCode?: string): any;
|
|
25
48
|
export declare function getSortByPublishedDate(order: 'asc' | 'desc'): "-published_at" | "published_at";
|
|
26
49
|
export declare function getGalleriesQuery(): {
|
|
@@ -25,7 +25,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
25
25
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.getContactsQuery = exports.getGalleriesQuery = exports.getSortByPublishedDate = exports.getStoriesQuery = exports.getSlugQuery = void 0;
|
|
28
|
+
exports.getContactsQuery = exports.getGalleriesQuery = exports.getSortByPublishedDate = exports.getStoriesQuery = exports.getEmbedStoriesQuery = exports.getSlugQuery = void 0;
|
|
29
29
|
var publishedAndAccessible = [
|
|
30
30
|
{ lifecycle_status: { $in: ['published', 'embargo'] } },
|
|
31
31
|
{ visibility: { $in: ['public', 'private', 'embargo'] } },
|
|
@@ -43,6 +43,15 @@ function getSlugQuery(newsroomUuid, slug) {
|
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
exports.getSlugQuery = getSlugQuery;
|
|
46
|
+
function getEmbedStoriesQuery(newsroomUuid, uuids) {
|
|
47
|
+
return {
|
|
48
|
+
$and: __spreadArray([
|
|
49
|
+
{ 'newsroom.uuid': { $in: [newsroomUuid] } },
|
|
50
|
+
{ uuid: { $in: uuids } }
|
|
51
|
+
], __read(publishedAndAccessible), false),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.getEmbedStoriesQuery = getEmbedStoriesQuery;
|
|
46
55
|
function getStoriesQuery(newsroomUuid, categoryId, localeCode) {
|
|
47
56
|
var query = {
|
|
48
57
|
$and: __spreadArray(__spreadArray([], __read(publishedAndPublic), false), [{ 'newsroom.uuid': { $in: [newsroomUuid] } }], false),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/data-fetching/api/queries.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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,8CAIC;AAED,SAAgB,gBAAgB;IAC5B,OAAO;QACH,IAAI,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC;KACzC,CAAC;AACN,CAAC;AAJD,4CAIC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnvVariables = void 0;
|
|
3
|
+
exports.isSdkError = exports.getEnvVariables = void 0;
|
|
4
4
|
var getEnvVariables_1 = require("./getEnvVariables");
|
|
5
5
|
Object.defineProperty(exports, "getEnvVariables", { enumerable: true, get: function () { return getEnvVariables_1.getEnvVariables; } });
|
|
6
|
+
var isSdkError_1 = require("./isSdkError");
|
|
7
|
+
Object.defineProperty(exports, "isSdkError", { enumerable: true, get: function () { return isSdkError_1.isSdkError; } });
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data-fetching/lib/index.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data-fetching/lib/index.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSdkError.js","sourceRoot":"","sources":["../../../src/data-fetching/lib/isSdkError.ts"],"names":[],"mappings":";;;AAEA,SAAgB,UAAU,CAAC,KAAU;IACjC,OAAO,SAAS,IAAI,KAAK,CAAC;AAC9B,CAAC;AAFD,gCAEC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Category, ExtendedStory, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset } from '@prezly/sdk';
|
|
1
|
+
import type { Category, ExtendedStory, Newsroom, NewsroomCompanyInformation, NewsroomContact, NewsroomLanguageSettings, NewsroomThemePreset, Story } from '@prezly/sdk';
|
|
2
2
|
import type { PropsWithChildren } from 'react';
|
|
3
3
|
import type { AlgoliaSettings } from '../data-fetching';
|
|
4
4
|
import { LocaleObject } from '../intl';
|
|
@@ -28,6 +28,10 @@ export interface NewsroomContextType {
|
|
|
28
28
|
* Optional: Refers to a currently selected story when navigated to `/[slug]` page.
|
|
29
29
|
*/
|
|
30
30
|
currentStory?: ExtendedStory;
|
|
31
|
+
/**
|
|
32
|
+
* Optional: Embed stories data referenced from the current story content (currently used by Story Bookmark blocks)
|
|
33
|
+
*/
|
|
34
|
+
embedStories?: Record<Story['uuid'], Story>;
|
|
31
35
|
/**
|
|
32
36
|
* List of currently enabled newsroom languages, as well as company information translated for each language
|
|
33
37
|
*/
|
|
@@ -55,4 +59,4 @@ export declare const NewsroomContext: import("react").Context<NewsroomContextTyp
|
|
|
55
59
|
* This context provides common Newsroom information retrieved by `getNewsroomServerSideProps` helper.
|
|
56
60
|
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
57
61
|
*/
|
|
58
|
-
export declare function NewsroomContextProvider({ categories, contacts, newsroom, currentCategory, currentStory, companyInformation, languages, localeCode, themePreset, algoliaSettings, children, }: PropsWithChildren<NewsroomContextProps>): JSX.Element;
|
|
62
|
+
export declare function NewsroomContextProvider({ categories, contacts, newsroom, currentCategory, currentStory, embedStories, companyInformation, languages, localeCode, themePreset, algoliaSettings, children, }: PropsWithChildren<NewsroomContextProps>): JSX.Element;
|
|
@@ -21,7 +21,7 @@ exports.NewsroomContext = (0, react_1.createContext)(undefined);
|
|
|
21
21
|
* Please refer to the `NewsroomContextType` definition for more info on what's exposed from the context.
|
|
22
22
|
*/
|
|
23
23
|
function NewsroomContextProvider(_a) {
|
|
24
|
-
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom, currentCategory = _a.currentCategory, currentStory = _a.currentStory, companyInformation = _a.companyInformation, languages = _a.languages, localeCode = _a.localeCode, themePreset = _a.themePreset, algoliaSettings = _a.algoliaSettings, children = _a.children;
|
|
24
|
+
var categories = _a.categories, contacts = _a.contacts, newsroom = _a.newsroom, currentCategory = _a.currentCategory, currentStory = _a.currentStory, embedStories = _a.embedStories, companyInformation = _a.companyInformation, languages = _a.languages, localeCode = _a.localeCode, themePreset = _a.themePreset, algoliaSettings = _a.algoliaSettings, children = _a.children;
|
|
25
25
|
var locale = (0, react_1.useMemo)(function () { return intl_1.LocaleObject.fromAnyCode(localeCode || intl_1.DEFAULT_LOCALE); }, [localeCode]);
|
|
26
26
|
return ((0, jsx_runtime_1.jsx)(exports.NewsroomContext.Provider, __assign({ value: {
|
|
27
27
|
categories: categories,
|
|
@@ -29,6 +29,7 @@ function NewsroomContextProvider(_a) {
|
|
|
29
29
|
newsroom: newsroom,
|
|
30
30
|
currentCategory: currentCategory,
|
|
31
31
|
currentStory: currentStory,
|
|
32
|
+
embedStories: embedStories,
|
|
32
33
|
companyInformation: companyInformation,
|
|
33
34
|
languages: languages,
|
|
34
35
|
locale: locale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/newsroom-context/context.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAWA,+BAA+C;AAG/C,gCAAuD;AAwD1C,QAAA,eAAe,GAAG,IAAA,qBAAa,EAAkC,SAAS,CAAC,CAAC;AAEzF;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,EAaE;QAZtC,UAAU,gBAAA,EACV,QAAQ,cAAA,EACR,QAAQ,cAAA,EACR,eAAe,qBAAA,EACf,YAAY,kBAAA,EACZ,YAAY,kBAAA,EACZ,kBAAkB,wBAAA,EAClB,SAAS,eAAA,EACT,UAAU,gBAAA,EACV,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,uBAAC,uBAAe,CAAC,QAAQ,aACrB,KAAK,EAAE;YACH,UAAU,YAAA;YACV,QAAQ,UAAA;YACR,QAAQ,UAAA;YACR,eAAe,iBAAA;YACf,YAAY,cAAA;YACZ,YAAY,cAAA;YACZ,kBAAkB,oBAAA;YAClB,SAAS,WAAA;YACT,MAAM,QAAA;YACN,WAAW,aAAA;YACX,eAAe,iBAAA;SAClB,gBAEA,QAAQ,YACc,CAC9B,CAAC;AACN,CAAC;AAtCD,0DAsCC"}
|
|
@@ -4,6 +4,7 @@ export * from './useCompanyInformation';
|
|
|
4
4
|
export * from './useCurrentCategory';
|
|
5
5
|
export * from './useCurrentLocale';
|
|
6
6
|
export * from './useCurrentStory';
|
|
7
|
+
export * from './useEmbedStory';
|
|
7
8
|
export * from './useGetLinkLocaleSlug';
|
|
8
9
|
export * from './useGetTranslationUrl';
|
|
9
10
|
export * from './useLanguages';
|
|
@@ -16,6 +16,7 @@ __exportStar(require("./useCompanyInformation"), exports);
|
|
|
16
16
|
__exportStar(require("./useCurrentCategory"), exports);
|
|
17
17
|
__exportStar(require("./useCurrentLocale"), exports);
|
|
18
18
|
__exportStar(require("./useCurrentStory"), exports);
|
|
19
|
+
__exportStar(require("./useEmbedStory"), exports);
|
|
19
20
|
__exportStar(require("./useGetLinkLocaleSlug"), exports);
|
|
20
21
|
__exportStar(require("./useGetTranslationUrl"), exports);
|
|
21
22
|
__exportStar(require("./useLanguages"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,kDAAgC;AAChC,0DAAwC;AACxC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,yDAAuC;AACvC,yDAAuC;AACvC,iDAA+B;AAC/B,gDAA8B;AAC9B,uDAAqC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAqC;AACrC,kDAAgC;AAChC,0DAAwC;AACxC,uDAAqC;AACrC,qDAAmC;AACnC,oDAAkC;AAClC,kDAAgC;AAChC,yDAAuC;AACvC,yDAAuC;AACvC,iDAA+B;AAC/B,gDAA8B;AAC9B,uDAAqC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useEmbedStory = void 0;
|
|
4
|
+
var useNewsroomContext_1 = require("./useNewsroomContext");
|
|
5
|
+
function useEmbedStory(uuid) {
|
|
6
|
+
var context = (0, useNewsroomContext_1.useNewsroomContext)();
|
|
7
|
+
if (!context.embedStories) {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
return context.embedStories[uuid];
|
|
11
|
+
}
|
|
12
|
+
exports.useEmbedStory = useEmbedStory;
|
|
13
|
+
//# sourceMappingURL=useEmbedStory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEmbedStory.js","sourceRoot":"","sources":["../../../src/newsroom-context/hooks/useEmbedStory.ts"],"names":[],"mappings":";;;AAEA,2DAA0D;AAE1D,SAAgB,aAAa,CAAC,IAAmB;IAC7C,IAAM,OAAO,GAAG,IAAA,uCAAkB,GAAE,CAAC;IAErC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;QACvB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AARD,sCAQC"}
|
package/build/types.d.ts
CHANGED
|
@@ -31,3 +31,13 @@ export declare type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subt
|
|
|
31
31
|
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
32
32
|
categories: AlgoliaCategoryRef[];
|
|
33
33
|
};
|
|
34
|
+
export interface SdkError extends Error {
|
|
35
|
+
status: number;
|
|
36
|
+
statusText: string;
|
|
37
|
+
payload: {
|
|
38
|
+
errors: {
|
|
39
|
+
reason: string;
|
|
40
|
+
};
|
|
41
|
+
message: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prezly/theme-kit-nextjs",
|
|
3
|
-
"version": "1.7.0",
|
|
3
|
+
"version": "1.7.2-0",
|
|
4
4
|
"description": "Data layer and utility library for developing Prezly themes with NextJS",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@prezly/sdk": "^6.21.0",
|
|
52
|
+
"@prezly/slate-types": "^0.31.1",
|
|
52
53
|
"@react-hookz/web": "^13.2.1",
|
|
53
54
|
"next-seo": "^5.4.0",
|
|
54
55
|
"parse-data-url": "^4.0.1",
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Category,
|
|
3
|
+
ExtendedStory,
|
|
3
4
|
ExtraStoryFields,
|
|
4
5
|
Newsroom,
|
|
5
6
|
NewsroomLanguageSettings,
|
|
6
7
|
Story,
|
|
7
8
|
} from '@prezly/sdk';
|
|
8
9
|
import PrezlySDK from '@prezly/sdk';
|
|
10
|
+
import type { StoryBookmarkNode } from '@prezly/slate-types';
|
|
11
|
+
import { isStoryBookmarkNode } from '@prezly/slate-types';
|
|
9
12
|
import type { IncomingMessage } from 'http';
|
|
10
13
|
|
|
11
14
|
import { LocaleObject } from '../../intl';
|
|
12
15
|
import type { PageProps, ServerSidePageProps } from '../../types';
|
|
13
16
|
import { DEFAULT_PAGE_SIZE } from '../constants';
|
|
17
|
+
import { isSdkError } from '../lib';
|
|
14
18
|
import { getAlgoliaSettings } from '../lib/getAlgoliaSettings';
|
|
15
19
|
|
|
16
20
|
import {
|
|
@@ -21,6 +25,7 @@ import {
|
|
|
21
25
|
} from './languages';
|
|
22
26
|
import {
|
|
23
27
|
getContactsQuery,
|
|
28
|
+
getEmbedStoriesQuery,
|
|
24
29
|
getGalleriesQuery,
|
|
25
30
|
getSlugQuery,
|
|
26
31
|
getSortByPublishedDate,
|
|
@@ -63,8 +68,15 @@ export class PrezlyApi {
|
|
|
63
68
|
this.themeUuid = themeUuid;
|
|
64
69
|
}
|
|
65
70
|
|
|
66
|
-
getStory(uuid: string) {
|
|
67
|
-
|
|
71
|
+
async getStory(uuid: string) {
|
|
72
|
+
try {
|
|
73
|
+
return await this.sdk.stories.get(uuid);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (isSdkError(error) && error.status === 404) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
async getNewsroom() {
|
|
@@ -199,7 +211,14 @@ export class PrezlyApi {
|
|
|
199
211
|
}
|
|
200
212
|
|
|
201
213
|
async getGallery(uuid: string) {
|
|
202
|
-
|
|
214
|
+
try {
|
|
215
|
+
return await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (isSdkError(error) && error.status === 404) {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
/**
|
|
@@ -213,6 +232,28 @@ export class PrezlyApi {
|
|
|
213
232
|
return null;
|
|
214
233
|
}
|
|
215
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Returns summaries for stories embed in the current story (like in Bookmark Blocks)
|
|
237
|
+
* @returns a map of `Story` object with their UUID as keys
|
|
238
|
+
*/
|
|
239
|
+
async getEmbedStories(story: ExtendedStory) {
|
|
240
|
+
const nodes = JSON.parse(story.content);
|
|
241
|
+
|
|
242
|
+
const embedUuids: Array<string> = await Promise.all(
|
|
243
|
+
nodes.children.filter(isStoryBookmarkNode).map((c: StoryBookmarkNode) => c.story.uuid),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const jsonQuery = JSON.stringify(getEmbedStoriesQuery(this.newsroomUuid, embedUuids));
|
|
247
|
+
const { stories } = await this.searchStories({
|
|
248
|
+
jsonQuery,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return stories.reduce<Record<Story['uuid'], Story>>(
|
|
252
|
+
(result, embedStory) => ({ ...result, [embedStory.uuid]: embedStory }),
|
|
253
|
+
{},
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
|
|
216
257
|
async getNewsroomServerSideProps(
|
|
217
258
|
request: IncomingMessage | undefined,
|
|
218
259
|
nextLocaleIsoCode?: string,
|
|
@@ -18,6 +18,16 @@ export function getSlugQuery(newsroomUuid: string, slug: string) {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export function getEmbedStoriesQuery(newsroomUuid: string, uuids: string[]) {
|
|
22
|
+
return {
|
|
23
|
+
$and: [
|
|
24
|
+
{ 'newsroom.uuid': { $in: [newsroomUuid] } },
|
|
25
|
+
{ uuid: { $in: uuids } },
|
|
26
|
+
...publishedAndAccessible,
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
export function getStoriesQuery(newsroomUuid: string, categoryId?: number, localeCode?: string) {
|
|
22
32
|
const query: any = {
|
|
23
33
|
$and: [...publishedAndPublic, { 'newsroom.uuid': { $in: [newsroomUuid] } }],
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
NewsroomContact,
|
|
7
7
|
NewsroomLanguageSettings,
|
|
8
8
|
NewsroomThemePreset,
|
|
9
|
+
Story,
|
|
9
10
|
} from '@prezly/sdk';
|
|
10
11
|
import type { PropsWithChildren } from 'react';
|
|
11
12
|
import { createContext, useMemo } from 'react';
|
|
@@ -39,6 +40,10 @@ export interface NewsroomContextType {
|
|
|
39
40
|
* Optional: Refers to a currently selected story when navigated to `/[slug]` page.
|
|
40
41
|
*/
|
|
41
42
|
currentStory?: ExtendedStory;
|
|
43
|
+
/**
|
|
44
|
+
* Optional: Embed stories data referenced from the current story content (currently used by Story Bookmark blocks)
|
|
45
|
+
*/
|
|
46
|
+
embedStories?: Record<Story['uuid'], Story>;
|
|
42
47
|
/**
|
|
43
48
|
* List of currently enabled newsroom languages, as well as company information translated for each language
|
|
44
49
|
*/
|
|
@@ -75,6 +80,7 @@ export function NewsroomContextProvider({
|
|
|
75
80
|
newsroom,
|
|
76
81
|
currentCategory,
|
|
77
82
|
currentStory,
|
|
83
|
+
embedStories,
|
|
78
84
|
companyInformation,
|
|
79
85
|
languages,
|
|
80
86
|
localeCode,
|
|
@@ -95,6 +101,7 @@ export function NewsroomContextProvider({
|
|
|
95
101
|
newsroom,
|
|
96
102
|
currentCategory,
|
|
97
103
|
currentStory,
|
|
104
|
+
embedStories,
|
|
98
105
|
companyInformation,
|
|
99
106
|
languages,
|
|
100
107
|
locale,
|
|
@@ -4,6 +4,7 @@ export * from './useCompanyInformation';
|
|
|
4
4
|
export * from './useCurrentCategory';
|
|
5
5
|
export * from './useCurrentLocale';
|
|
6
6
|
export * from './useCurrentStory';
|
|
7
|
+
export * from './useEmbedStory';
|
|
7
8
|
export * from './useGetLinkLocaleSlug';
|
|
8
9
|
export * from './useGetTranslationUrl';
|
|
9
10
|
export * from './useLanguages';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Story } from '@prezly/sdk';
|
|
2
|
+
|
|
3
|
+
import { useNewsroomContext } from './useNewsroomContext';
|
|
4
|
+
|
|
5
|
+
export function useEmbedStory(uuid: Story['uuid']) {
|
|
6
|
+
const context = useNewsroomContext();
|
|
7
|
+
|
|
8
|
+
if (!context.embedStories) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return context.embedStories[uuid];
|
|
13
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -37,3 +37,15 @@ export type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> &
|
|
|
37
37
|
culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
|
|
38
38
|
categories: AlgoliaCategoryRef[];
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
// TODO: This should be exported from `@prezly/sdk`
|
|
42
|
+
export interface SdkError extends Error {
|
|
43
|
+
status: number;
|
|
44
|
+
statusText: string;
|
|
45
|
+
payload: {
|
|
46
|
+
errors: {
|
|
47
|
+
reason: string;
|
|
48
|
+
};
|
|
49
|
+
message: string;
|
|
50
|
+
};
|
|
51
|
+
}
|