@zengenti/contensis-react-base 4.0.0-beta.9 → 4.0.1-beta.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 +14 -1
- package/cjs/{App-vZrUfVgQ.js → App-Bg1MzW4V.js} +593 -110
- package/cjs/App-Bg1MzW4V.js.map +1 -0
- package/cjs/{ChangePassword.container-ECjEXixF.js → ChangePassword.container-C4Du3Wb1.js} +57 -50
- package/cjs/ChangePassword.container-C4Du3Wb1.js.map +1 -0
- package/cjs/{SSRContext-DVj_QAC1.js → ContensisDeliveryApi-MfcvdfDR.js} +32 -74
- package/cjs/ContensisDeliveryApi-MfcvdfDR.js.map +1 -0
- package/cjs/CookieConstants-DfPiWCRZ.js +12 -0
- package/cjs/CookieConstants-DfPiWCRZ.js.map +1 -0
- package/{esm/CookieHelper.class-FTURFpz3.js → cjs/CookieHelper.class-Det3qfdU.js} +4 -6
- package/cjs/CookieHelper.class-Det3qfdU.js.map +1 -0
- package/cjs/{RouteLoader-D5Yg7EB5.js → RouteLoader-DJeM8cym.js} +17 -9
- package/cjs/RouteLoader-DJeM8cym.js.map +1 -0
- package/cjs/SSRContext-tMufQDHY.js +116 -0
- package/cjs/SSRContext-tMufQDHY.js.map +1 -0
- package/cjs/ToJs-BsWqWjdm.js +23 -0
- package/cjs/ToJs-BsWqWjdm.js.map +1 -0
- package/cjs/{VersionInfo-B_dKCubg.js → VersionInfo-zFPsvS8q.js} +3 -25
- package/cjs/VersionInfo-zFPsvS8q.js.map +1 -0
- package/cjs/client.js +63 -65
- package/cjs/client.js.map +1 -1
- package/cjs/contensis-react-base.js +208 -119
- package/cjs/contensis-react-base.js.map +1 -1
- package/cjs/i18n.js +75 -0
- package/cjs/i18n.js.map +1 -0
- package/cjs/{ToJs-C9jwV7YB.js → matchGroups-dqONU-vY.js} +2 -22
- package/cjs/matchGroups-dqONU-vY.js.map +1 -0
- package/cjs/redux.js +8 -6
- package/cjs/redux.js.map +1 -1
- package/cjs/routing.js +15 -7
- package/cjs/routing.js.map +1 -1
- package/cjs/{sagas-BVX4Ps1e.js → sagas-BCy9u6zA.js} +523 -375
- package/cjs/sagas-BCy9u6zA.js.map +1 -0
- package/cjs/search.js +54 -29
- package/cjs/search.js.map +1 -1
- package/cjs/{selectors-wCs5fHD4.js → selectors-BrxJ8-F8.js} +27 -6
- package/cjs/selectors-BrxJ8-F8.js.map +1 -0
- package/cjs/selectors-DAQR0uZa.js +18 -0
- package/cjs/selectors-DAQR0uZa.js.map +1 -0
- package/cjs/slice-5xJMH24n.js +69 -0
- package/cjs/slice-5xJMH24n.js.map +1 -0
- package/cjs/{store-D07FOXvM.js → store-B7SJs5Hf.js} +64 -5
- package/cjs/store-B7SJs5Hf.js.map +1 -0
- package/cjs/urls-DGZlAs0y.js +25 -0
- package/cjs/urls-DGZlAs0y.js.map +1 -0
- package/cjs/user.js +20 -17
- package/cjs/user.js.map +1 -1
- package/cjs/util-eOjxDjxF.js +148 -0
- package/cjs/util-eOjxDjxF.js.map +1 -0
- package/cjs/util.js +80 -22
- package/cjs/util.js.map +1 -1
- package/cjs/{version-CM-bJ62L.js → version-rFG9Y6_B.js} +2 -2
- package/cjs/{version-CM-bJ62L.js.map → version-rFG9Y6_B.js.map} +1 -1
- package/cjs/{version-B7XFkBhY.js → version-yjHMrfVz.js} +15 -16
- package/cjs/version-yjHMrfVz.js.map +1 -0
- package/esm/{App-DLZweVSp.js → App-Bplaqueq.js} +554 -72
- package/esm/App-Bplaqueq.js.map +1 -0
- package/esm/{ChangePassword.container-BgzIy8dA.js → ChangePassword.container-CUBtn82K.js} +19 -13
- package/esm/ChangePassword.container-CUBtn82K.js.map +1 -0
- package/esm/{SSRContext-BE8ElZ3X.js → ContensisDeliveryApi-LWYXevZ1.js} +30 -67
- package/esm/ContensisDeliveryApi-LWYXevZ1.js.map +1 -0
- package/esm/CookieConstants-DEmbwzYr.js +7 -0
- package/esm/CookieConstants-DEmbwzYr.js.map +1 -0
- package/{cjs/CookieHelper.class-C3Eqoze9.js → esm/CookieHelper.class-C6rTRl_1.js} +2 -14
- package/esm/CookieHelper.class-C6rTRl_1.js.map +1 -0
- package/esm/{RouteLoader-xeQBXywk.js → RouteLoader-CzrlySZf.js} +14 -6
- package/esm/RouteLoader-CzrlySZf.js.map +1 -0
- package/esm/SSRContext-Bxtg1KGv.js +106 -0
- package/esm/SSRContext-Bxtg1KGv.js.map +1 -0
- package/esm/ToJs-BnRRHk6f.js +17 -0
- package/esm/ToJs-BnRRHk6f.js.map +1 -0
- package/esm/{VersionInfo-Cno7K0OA.js → VersionInfo-By2ZCZOh.js} +4 -24
- package/esm/VersionInfo-By2ZCZOh.js.map +1 -0
- package/esm/client.js +63 -64
- package/esm/client.js.map +1 -1
- package/esm/contensis-react-base.js +201 -114
- package/esm/contensis-react-base.js.map +1 -1
- package/esm/i18n.js +64 -0
- package/esm/i18n.js.map +1 -0
- package/esm/{ToJs-CNzfvyxJ.js → matchGroups-_w8BwzCC.js} +3 -18
- package/esm/matchGroups-_w8BwzCC.js.map +1 -0
- package/esm/redux.js +11 -8
- package/esm/redux.js.map +1 -1
- package/esm/routing.js +14 -7
- package/esm/routing.js.map +1 -1
- package/esm/{sagas-JI51CS37.js → sagas-Fr9yRduO.js} +511 -362
- package/esm/sagas-Fr9yRduO.js.map +1 -0
- package/esm/search.js +73 -47
- package/esm/search.js.map +1 -1
- package/esm/{selectors-DO2ocdOp.js → selectors-8ROQrTd7.js} +25 -7
- package/esm/selectors-8ROQrTd7.js.map +1 -0
- package/esm/selectors-DcmvOeX2.js +10 -0
- package/esm/selectors-DcmvOeX2.js.map +1 -0
- package/esm/slice-C6JLQik8.js +63 -0
- package/esm/slice-C6JLQik8.js.map +1 -0
- package/esm/{store-3u0RzHZ0.js → store-B4IrBYHm.js} +64 -6
- package/esm/store-B4IrBYHm.js.map +1 -0
- package/esm/urls-tLxo_skx.js +22 -0
- package/esm/urls-tLxo_skx.js.map +1 -0
- package/esm/user.js +9 -6
- package/esm/user.js.map +1 -1
- package/esm/util-Bl2u6LpY.js +136 -0
- package/esm/util-Bl2u6LpY.js.map +1 -0
- package/esm/util.js +58 -14
- package/esm/util.js.map +1 -1
- package/esm/{version-wnf-TITV.js → version-BQAL8sQO.js} +2 -2
- package/esm/{version-wnf-TITV.js.map → version-BQAL8sQO.js.map} +1 -1
- package/esm/{version-BlsI7hX2.js → version-CA9Mdm3A.js} +16 -16
- package/esm/version-CA9Mdm3A.js.map +1 -0
- package/i18n/package.json +5 -0
- package/models/app/pages/VersionInfo/components/VersionInfo.d.ts +1 -1
- package/models/app/pages/VersionInfo/components/VersionInfo.styled.d.ts +1 -2
- package/models/i18n/index.d.ts +5 -0
- package/models/i18n/redux/sagas.d.ts +19 -0
- package/models/i18n/redux/selectors.d.ts +11 -0
- package/models/i18n/redux/slice.d.ts +198 -0
- package/models/i18n/routes.d.ts +8 -0
- package/models/i18n/useI18n.hook.d.ts +20 -0
- package/models/index.d.ts +1 -0
- package/models/models/AppState.d.ts +2 -0
- package/models/models/ContentTypeMapping.d.ts +6 -1
- package/models/models/EntryMapper.d.ts +2 -1
- package/models/models/Locales.d.ts +11 -0
- package/models/models/MatchedRoute.d.ts +5 -1
- package/models/models/RouteComponent.d.ts +0 -1
- package/models/models/RouteNode.d.ts +4 -2
- package/models/models/SSRContext.d.ts +4 -4
- package/models/models/StaticRoute.d.ts +12 -1
- package/models/models/WithEvents.d.ts +8 -0
- package/models/models/config/AppConfig.d.ts +2 -0
- package/models/models/config/I18n.d.ts +38 -0
- package/models/models/config/ServerConfig.d.ts +14 -0
- package/models/redux/index.d.ts +2 -1
- package/models/redux/sagas/index.d.ts +3 -1
- package/models/redux/sagas/injector.d.ts +13 -0
- package/models/redux/store/injectors/index.d.ts +26 -0
- package/models/redux/store/injectors/inject.d.ts +24 -0
- package/models/redux/store/injectors/util.d.ts +2 -0
- package/models/redux/store/store.d.ts +13 -4
- package/models/redux/util.d.ts +1 -1
- package/models/routing/components/RouteLoader.d.ts +3 -3
- package/models/routing/httpContext.d.ts +0 -1
- package/models/routing/index.d.ts +1 -0
- package/models/routing/redux/actions.d.ts +1 -1
- package/models/routing/redux/invokeSearch.d.ts +22 -0
- package/models/routing/redux/selectors.d.ts +47 -4
- package/models/routing/util/expressions.d.ts +1 -1
- package/models/routing/util/find-contenttype-mapping.d.ts +3 -1
- package/models/search/containers/withListing.d.ts +1 -1
- package/models/search/containers/withSearch.d.ts +1 -1
- package/models/search/models/Queries.d.ts +3 -5
- package/models/search/models/Search.d.ts +43 -13
- package/models/search/models/SearchActions.d.ts +61 -18
- package/models/search/models/SearchProps.d.ts +11 -10
- package/models/search/models/SearchState.d.ts +23 -2
- package/models/search/models/SearchUtil.d.ts +3 -3
- package/models/search/redux/getIn.d.ts +2 -2
- package/models/search/redux/reducers.d.ts +3 -4
- package/models/search/redux/sagas.d.ts +13 -14
- package/models/search/redux/schema.d.ts +3 -3
- package/models/search/redux/selectors.d.ts +64 -42
- package/models/search/redux/util.d.ts +10 -1
- package/models/search/search/ContensisDeliveryApi.d.ts +6 -26
- package/models/search/search/expressions.d.ts +6 -4
- package/models/search/search/util.d.ts +9 -7
- package/models/search/transformations/state-to-queryparams.mapper.d.ts +1 -1
- package/models/server/features/linkdepth-api/search.d.ts +1 -1
- package/models/server/features/response-handler/render-stream.d.ts +2 -4
- package/models/server/features/static-assets/index.d.ts +4 -3
- package/models/server/internalServer.d.ts +1 -2
- package/models/server/middleware/subsiteDebug.d.ts +11 -0
- package/models/server/root.d.ts +3 -0
- package/models/server/util/bundles.d.ts +9 -9
- package/models/server/util/jsx.d.ts +2 -14
- package/models/user/components.styled/Login.styled.d.ts +1 -1
- package/models/user/components.styled/LoginForm.styled.d.ts +1 -1
- package/models/user/hocs/withRegistration.d.ts +1 -1
- package/models/util/CachedDeliveryApi.d.ts +8 -2
- package/models/util/ContensisDeliveryApi.d.ts +2 -4
- package/models/util/NoSSR.d.ts +6 -0
- package/models/util/SSRContext.d.ts +3 -19
- package/models/util/donotuse_useHistory.d.ts +6 -0
- package/models/util/errors.d.ts +16 -0
- package/models/util/index.d.ts +7 -2
- package/models/util/subsite.d.ts +12 -0
- package/models/util/urls.d.ts +1 -2
- package/models/util/useIsClient.d.ts +6 -0
- package/package.json +37 -39
- package/cjs/App-vZrUfVgQ.js.map +0 -1
- package/cjs/ChangePassword.container-ECjEXixF.js.map +0 -1
- package/cjs/CookieHelper.class-C3Eqoze9.js.map +0 -1
- package/cjs/RouteLoader-D5Yg7EB5.js.map +0 -1
- package/cjs/SSRContext-DVj_QAC1.js.map +0 -1
- package/cjs/ToJs-C9jwV7YB.js.map +0 -1
- package/cjs/VersionInfo-B_dKCubg.js.map +0 -1
- package/cjs/sagas-BVX4Ps1e.js.map +0 -1
- package/cjs/selectors-wCs5fHD4.js.map +0 -1
- package/cjs/store-D07FOXvM.js.map +0 -1
- package/cjs/version-B7XFkBhY.js.map +0 -1
- package/esm/App-DLZweVSp.js.map +0 -1
- package/esm/ChangePassword.container-BgzIy8dA.js.map +0 -1
- package/esm/CookieHelper.class-FTURFpz3.js.map +0 -1
- package/esm/RouteLoader-xeQBXywk.js.map +0 -1
- package/esm/SSRContext-BE8ElZ3X.js.map +0 -1
- package/esm/ToJs-CNzfvyxJ.js.map +0 -1
- package/esm/VersionInfo-Cno7K0OA.js.map +0 -1
- package/esm/sagas-JI51CS37.js.map +0 -1
- package/esm/selectors-DO2ocdOp.js.map +0 -1
- package/esm/store-3u0RzHZ0.js.map +0 -1
- package/esm/version-BlsI7hX2.js.map +0 -1
- package/models/redux/store/injectors.d.ts +0 -31
- package/models/search/search/ToJs.d.ts +0 -4
|
@@ -1,21 +1,89 @@
|
|
|
1
1
|
import { createBrowserHistory, createMemoryHistory } from 'history';
|
|
2
|
-
import { takeEvery, select, put, call, all } from '@redux-saga/core/effects';
|
|
2
|
+
import { takeEvery, select, put, call, cancel, fork, take, cancelled, all } from '@redux-saga/core/effects';
|
|
3
3
|
import * as log from 'loglevel';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { error as error$1 } from 'loglevel';
|
|
5
|
+
import { G as GET_NODE_TREE, b as SET_NODE_TREE, d as GET_NODE_TREE_ERROR } from './store-B4IrBYHm.js';
|
|
6
|
+
import { h as hasNavigationTree, b as injectRedux } from './version-CA9Mdm3A.js';
|
|
6
7
|
import to, { to as to$1 } from 'await-to-js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { eventChannel } from 'redux-saga';
|
|
9
|
+
import { Query, Op } from 'contensis-delivery-api';
|
|
10
|
+
import { a as actions } from './slice-C6JLQik8.js';
|
|
11
|
+
import { o as selectCurrentPath, G as setRoute, K as selectRouteEntryAvailableLanguages, M as selectRouteEntryID, N as selectStaticRoute, y as SET_NAVIGATION_PATH, x as SET_ROUTE, j as selectRouteEntry, O as selectCurrentNode, f as selectCurrentProject, z as UPDATE_LOADING_STATE, P as selectCurrentAncestors, Q as selectCurrentSiblings, T as selectRouteEntryEntryId, W as selectRouteEntryLanguage, n as selectMappedEntry, A as SET_ENTRY, B as SET_ANCESTORS, w as SET_SIBLINGS, R as REGISTER_USER, X as REGISTER_USER_SUCCESS, Y as REGISTER_USER_FAILED, E as queryParams, F as selectCurrentSearch, H as REQUEST_USER_PASSWORD_RESET, I as RESET_USER_PASSWORD, J as CHANGE_USER_PASSWORD, Z as REQUEST_USER_PASSWORD_RESET_SENDING, _ as REQUEST_USER_PASSWORD_RESET_SUCCESS, $ as REQUEST_USER_PASSWORD_RESET_ERROR, a0 as RESET_USER_PASSWORD_SENDING, a1 as RESET_USER_PASSWORD_SUCCESS, a2 as RESET_USER_PASSWORD_ERROR, a3 as CHANGE_USER_PASSWORD_ERROR, a4 as CHANGE_USER_PASSWORD_SENDING, a5 as CHANGE_USER_PASSWORD_SUCCESS } from './selectors-8ROQrTd7.js';
|
|
12
|
+
import { s as selectVersionStatus } from './version-BQAL8sQO.js';
|
|
13
|
+
import { c as cachedSearch } from './ContensisDeliveryApi-LWYXevZ1.js';
|
|
10
14
|
import React from 'react';
|
|
11
15
|
import 'react-cookie';
|
|
12
16
|
import 'react-redux';
|
|
17
|
+
import './VersionInfo-By2ZCZOh.js';
|
|
18
|
+
import 'react-helmet-async';
|
|
13
19
|
import 'jsonpath-mapper';
|
|
14
|
-
import { Op, Query } from 'contensis-delivery-api';
|
|
15
|
-
import { l as selectClientCredentials } from './ToJs-CNzfvyxJ.js';
|
|
16
|
-
import 'query-string';
|
|
17
20
|
import 'react-router-dom';
|
|
18
|
-
import { a as
|
|
21
|
+
import { s as selectCurrentLanguage, a as selectDictionary, c as selectLocaleRoutes, b as selectLocales, f as selectDictionaryResolver, d as selectPrimaryLanguage } from './selectors-DcmvOeX2.js';
|
|
22
|
+
import { i as findContentTypeMapping, h as handleRequiresLoginSaga, L as LoginHelper, j as getSearchOptions, k as getManagementApiClient, m as loginSagas } from './ChangePassword.container-CUBtn82K.js';
|
|
23
|
+
import './sagas-Fr9yRduO.js';
|
|
24
|
+
import 'reselect';
|
|
25
|
+
import 'immer';
|
|
26
|
+
import 'deep-equal';
|
|
27
|
+
import 'deepmerge';
|
|
28
|
+
import { r as routeParams } from './util-Bl2u6LpY.js';
|
|
29
|
+
import 'contensis-core-api';
|
|
30
|
+
import { l as selectClientCredentials } from './matchGroups-_w8BwzCC.js';
|
|
31
|
+
import { a as RouteLoader } from './RouteLoader-CzrlySZf.js';
|
|
32
|
+
import 'query-string';
|
|
33
|
+
|
|
34
|
+
const isApiError = e => !!e && typeof e === 'object' && 'status' in e && 'statusText' in e;
|
|
35
|
+
const isPlainError = e => !!e && typeof e === 'object' && 'message' in e && typeof e.message === 'string';
|
|
36
|
+
const logError = (prefix, e) => {
|
|
37
|
+
var _e$data;
|
|
38
|
+
const message = isApiError(e) ? `${prefix} ${e.status} "${((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.message) || ''}" url: ${e.url || ''}` : isPlainError(e) ? `${prefix} "${(e === null || e === void 0 ? void 0 : e.message) || e}"${e !== null && e !== void 0 && e.stack ? `\n${e.stack}` : ''}` : `${prefix} "${e}"`;
|
|
39
|
+
error$1(message);
|
|
40
|
+
};
|
|
41
|
+
const shorten = (str, maxLength = 120, endWeight = 0.6) => {
|
|
42
|
+
if (!str || str.length <= maxLength) return str;
|
|
43
|
+
const charsToShow = maxLength - 3;
|
|
44
|
+
const back = Math.floor(charsToShow * endWeight);
|
|
45
|
+
const front = charsToShow - back;
|
|
46
|
+
return `${str.slice(0, front)}...${str.slice(str.length - back)}`;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const deparameterise = path => {
|
|
50
|
+
return path.replace(/\/:\w+\??/g, '');
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Create static routes for routes with specified locales */
|
|
54
|
+
const createLocaleRoutes = routes => {
|
|
55
|
+
const localeRoutes = {};
|
|
56
|
+
for (const route of routes.StaticRoutes) {
|
|
57
|
+
// If the route has defined locales, create entries for each locale
|
|
58
|
+
if (route.i18n && route.path) {
|
|
59
|
+
for (const [language, path] of Object.entries(route.i18n)) {
|
|
60
|
+
// We already have a locale route, so just append the language and path
|
|
61
|
+
const deparameterisedPath = deparameterise(route.path);
|
|
62
|
+
const deparameterisedLocalePath = deparameterise(path);
|
|
63
|
+
if (localeRoutes[deparameterisedPath]) localeRoutes[deparameterisedPath][language] = deparameterisedLocalePath;
|
|
64
|
+
// Otherwise, create a new entry for this route path
|
|
65
|
+
else localeRoutes[deparameterisedPath] = {
|
|
66
|
+
[language]: deparameterisedLocalePath
|
|
67
|
+
};
|
|
68
|
+
if (deparameterise(route.path) !== deparameterisedLocalePath) {
|
|
69
|
+
// I think we are OK to mutate here as this is only run once on app init
|
|
70
|
+
// we can change this if needed later
|
|
71
|
+
routes.StaticRoutes.push({
|
|
72
|
+
...route,
|
|
73
|
+
path,
|
|
74
|
+
// Add the path with any parameters included
|
|
75
|
+
language,
|
|
76
|
+
i18n: undefined
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
// Just set the language on the existing route instead of creating a duplicate
|
|
80
|
+
route.language = language;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return localeRoutes;
|
|
86
|
+
};
|
|
19
87
|
|
|
20
88
|
// Create a history depending on the environment
|
|
21
89
|
const selectedHistory = typeof window !== 'undefined' ? createBrowserHistory : createMemoryHistory;
|
|
@@ -29,12 +97,17 @@ function* ensureNodeTreeSaga(action) {
|
|
|
29
97
|
language,
|
|
30
98
|
project,
|
|
31
99
|
versionStatus,
|
|
100
|
+
subsitePath,
|
|
32
101
|
treeDepth
|
|
33
102
|
} = action;
|
|
34
103
|
const state = yield select();
|
|
35
104
|
try {
|
|
36
105
|
if (!hasNavigationTree(state)) {
|
|
37
|
-
const nodes = yield api.
|
|
106
|
+
const nodes = subsitePath ? yield api.getNode({
|
|
107
|
+
path: subsitePath,
|
|
108
|
+
depth: treeDepth || 0,
|
|
109
|
+
language
|
|
110
|
+
}, project) : yield api.getRootNode({
|
|
38
111
|
depth: treeDepth || 0,
|
|
39
112
|
language
|
|
40
113
|
}, versionStatus, project);
|
|
@@ -58,6 +131,238 @@ function* ensureNodeTreeSaga(action) {
|
|
|
58
131
|
}
|
|
59
132
|
}
|
|
60
133
|
|
|
134
|
+
const i18nSagas = [takeEvery(actions.INIT_LOCALES.type, getProjectLanguages), takeEvery(actions.UPDATE_LANGUAGE.type, updateLanguage), takeEvery(actions.SET_LANGUAGE.type, setLanguageRoute)];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Resolve the current route language based on the entry, node, static route or path
|
|
138
|
+
* Is called directly from the routing saga as soon as an entry or node has been fetched
|
|
139
|
+
*/
|
|
140
|
+
function* resolveCurrentRouteLanguage({
|
|
141
|
+
entry,
|
|
142
|
+
node
|
|
143
|
+
}) {
|
|
144
|
+
var _entry$sys, _staticRoute$route;
|
|
145
|
+
const currentLanguage = yield select(selectCurrentLanguage);
|
|
146
|
+
const staticRoute = yield select(selectStaticRoute);
|
|
147
|
+
let nextLanguage = currentLanguage;
|
|
148
|
+
if (entry !== null && entry !== void 0 && (_entry$sys = entry.sys) !== null && _entry$sys !== void 0 && _entry$sys.language) nextLanguage = entry.sys.language;else if (node !== null && node !== void 0 && node.language) nextLanguage = node.language;else if (staticRoute !== null && staticRoute !== void 0 && (_staticRoute$route = staticRoute.route) !== null && _staticRoute$route !== void 0 && _staticRoute$route.language) nextLanguage = staticRoute.route.language;else {
|
|
149
|
+
var _currentPath$split$fi;
|
|
150
|
+
// attempt to infer language from the path
|
|
151
|
+
const currentPath = yield select(selectCurrentPath);
|
|
152
|
+
|
|
153
|
+
// path is normally lowercase
|
|
154
|
+
const firstPathSegment = (_currentPath$split$fi = currentPath.split('/').find(segment => segment.length)) === null || _currentPath$split$fi === void 0 ? void 0 : _currentPath$split$fi.toLowerCase();
|
|
155
|
+
const locales = yield select(selectLocales);
|
|
156
|
+
const matchedLanguage = Object.keys(locales).find(lang => lang.toLowerCase() === firstPathSegment);
|
|
157
|
+
// matched a supported language in the path
|
|
158
|
+
if (matchedLanguage) nextLanguage = matchedLanguage;else
|
|
159
|
+
// falling back to primary language
|
|
160
|
+
nextLanguage = yield select(selectPrimaryLanguage);
|
|
161
|
+
}
|
|
162
|
+
if (nextLanguage && nextLanguage !== currentLanguage) {
|
|
163
|
+
const dictionary = yield call(resolveDictionaryForLanguage, nextLanguage);
|
|
164
|
+
yield put(actions.SET_LANGUAGE({
|
|
165
|
+
language: nextLanguage,
|
|
166
|
+
dictionary
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Resolve the current dictionary for route language either using a supplied resolver
|
|
173
|
+
* function or directly derive from the locales stored in state
|
|
174
|
+
* Is called directly any time the language is changed
|
|
175
|
+
*/
|
|
176
|
+
function* resolveDictionaryForLanguage(language) {
|
|
177
|
+
let dictionary = yield select(selectDictionary);
|
|
178
|
+
// try and resolve a dictionary for this language
|
|
179
|
+
const resolver = yield select(selectDictionaryResolver);
|
|
180
|
+
if (typeof resolver === 'function') {
|
|
181
|
+
try {
|
|
182
|
+
// dynamic import of dictionary file
|
|
183
|
+
const loadedDictionary = yield call(resolver, language);
|
|
184
|
+
dictionary = loadedDictionary;
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error(`No dictionary resolved for language ${language}`, error);
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
// Load dictionary from locales in state
|
|
190
|
+
const locales = yield select(selectLocales);
|
|
191
|
+
if (locales && locales[language]) {
|
|
192
|
+
dictionary = locales[language];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return dictionary;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Side effects triggered from updating the language via dispatched action
|
|
200
|
+
* in language switching components, including resolving the next route,
|
|
201
|
+
* update the dictionary and subsequently redirect if needed
|
|
202
|
+
*/
|
|
203
|
+
function* updateLanguage({
|
|
204
|
+
payload: {
|
|
205
|
+
language,
|
|
206
|
+
redirect,
|
|
207
|
+
fallbackPath
|
|
208
|
+
}
|
|
209
|
+
}) {
|
|
210
|
+
const currentLanguage = yield select(selectCurrentLanguage);
|
|
211
|
+
if (language === currentLanguage) {
|
|
212
|
+
// no change needed
|
|
213
|
+
return;
|
|
214
|
+
} else {
|
|
215
|
+
const dictionary = language !== currentLanguage ? yield call(resolveDictionaryForLanguage, language) : yield select(selectDictionary);
|
|
216
|
+
const uri = yield call(resolveNextLanguageRoute, {
|
|
217
|
+
language,
|
|
218
|
+
redirect,
|
|
219
|
+
fallbackPath
|
|
220
|
+
});
|
|
221
|
+
yield put(actions.SET_LANGUAGE({
|
|
222
|
+
language,
|
|
223
|
+
dictionary: dictionary != null ? dictionary : undefined,
|
|
224
|
+
redirect: redirect !== false ? uri : undefined
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Handle any route redirection after we have set the language */
|
|
230
|
+
function* setLanguageRoute({
|
|
231
|
+
payload
|
|
232
|
+
}) {
|
|
233
|
+
if (payload !== null && payload !== void 0 && payload.redirect) {
|
|
234
|
+
const currentPath = yield select(selectCurrentPath);
|
|
235
|
+
if (payload.redirect === currentPath) {
|
|
236
|
+
// already on the correct path, no need to redirect
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
yield put(setRoute(payload.redirect));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Determine the correct route uri when the language changes */
|
|
244
|
+
function* resolveNextLanguageRoute({
|
|
245
|
+
language,
|
|
246
|
+
redirect,
|
|
247
|
+
fallbackPath
|
|
248
|
+
}) {
|
|
249
|
+
// have they supplied the route to go to?
|
|
250
|
+
if (typeof redirect === 'string') {
|
|
251
|
+
return redirect;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// is this an entry or a static route?
|
|
255
|
+
const availableLanguages = yield select(selectRouteEntryAvailableLanguages);
|
|
256
|
+
if (availableLanguages.find(l => l.toLowerCase() === language.toLowerCase())) {
|
|
257
|
+
// if entry, get the uri for this language variation from the api
|
|
258
|
+
const entryUri = yield call(getEntryUriForLanguage, {
|
|
259
|
+
entryId: yield select(selectRouteEntryID),
|
|
260
|
+
language
|
|
261
|
+
});
|
|
262
|
+
if (entryUri) {
|
|
263
|
+
return entryUri;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// if static route, get the uri from the routes config
|
|
268
|
+
const staticRouteUri = yield call(getStaticRouteUri, {
|
|
269
|
+
language
|
|
270
|
+
});
|
|
271
|
+
if (staticRouteUri) {
|
|
272
|
+
return staticRouteUri;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// if all else fails, fallback to the supplied fallback path or homepage
|
|
276
|
+
return fallbackPath || `/${language.toLowerCase()}`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Check any current static route for a language variation we have stored in i18n.routes */
|
|
280
|
+
function* getStaticRouteUri({
|
|
281
|
+
language
|
|
282
|
+
}) {
|
|
283
|
+
const staticRoute = yield select(selectStaticRoute);
|
|
284
|
+
if (staticRoute !== null && staticRoute !== void 0 && staticRoute.route.path) {
|
|
285
|
+
var _Object$entries$find;
|
|
286
|
+
// Routes can have parameters such as `/:facet?` we need to deparameterise
|
|
287
|
+
// so we can check against our stored locale routes
|
|
288
|
+
const deparameterisedPath = deparameterise(staticRoute.route.path);
|
|
289
|
+
const localeRoutes = yield select(selectLocaleRoutes);
|
|
290
|
+
const originalPath = (_Object$entries$find = Object.entries(localeRoutes || {}).find(([, locales]) => Object.values(locales).includes(deparameterisedPath))) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[0];
|
|
291
|
+
const routeLocales = localeRoutes[deparameterisedPath] || localeRoutes[originalPath || ''];
|
|
292
|
+
const routeUri = routeLocales === null || routeLocales === void 0 ? void 0 : routeLocales[language];
|
|
293
|
+
return routeUri;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Run when the app initiates locales, populating supported languages from the config
|
|
299
|
+
* or fetching from the project if not provided
|
|
300
|
+
*/
|
|
301
|
+
function* getProjectLanguages({
|
|
302
|
+
payload
|
|
303
|
+
}) {
|
|
304
|
+
const stateLocales = yield select(selectLocales);
|
|
305
|
+
if (stateLocales && Object.keys(stateLocales).length > 0)
|
|
306
|
+
// Locales already set in state, no need to fetch again
|
|
307
|
+
return;
|
|
308
|
+
const locales = {};
|
|
309
|
+
let primaryLanguage = payload.primaryLanguage;
|
|
310
|
+
const supportedLanguages = [...(payload.supportedLanguages || [])];
|
|
311
|
+
if (supportedLanguages !== null && supportedLanguages !== void 0 && supportedLanguages.length) {
|
|
312
|
+
// If supported languages are provided in config, use these
|
|
313
|
+
for (const supportedLanguage of supportedLanguages) {
|
|
314
|
+
locales[supportedLanguage] = {};
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
// Fallback to getting languages from the project
|
|
318
|
+
const [error, project] = yield to(cachedSearch.getClient().project.get());
|
|
319
|
+
if (error) {
|
|
320
|
+
console.error('Problem fetching project languages:', error);
|
|
321
|
+
} else if (project) {
|
|
322
|
+
var _project$primaryLangu;
|
|
323
|
+
for (const supportedLanguage of project.supportedLanguages || []) {
|
|
324
|
+
locales[supportedLanguage] = {};
|
|
325
|
+
supportedLanguages.push(supportedLanguage);
|
|
326
|
+
}
|
|
327
|
+
// Set primary language from project if we have it
|
|
328
|
+
primaryLanguage = (_project$primaryLangu = project.primaryLanguage) != null ? _project$primaryLangu : primaryLanguage;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (Object.keys(locales).length === 0) {
|
|
332
|
+
// Ensure at least the primary language is included
|
|
333
|
+
locales[payload.primaryLanguage] = {};
|
|
334
|
+
supportedLanguages.push(payload.primaryLanguage);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Only commit if we have locales to set or we will end up in an infinite loop
|
|
338
|
+
if (Object.keys(locales).length) yield put(actions.SET_LOCALES({
|
|
339
|
+
...payload,
|
|
340
|
+
primaryLanguage,
|
|
341
|
+
supportedLanguages,
|
|
342
|
+
locales
|
|
343
|
+
}));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Run a Delivery API query to get the uri for the chosen language variation of this entryId
|
|
348
|
+
* */
|
|
349
|
+
function* getEntryUriForLanguage({
|
|
350
|
+
entryId,
|
|
351
|
+
language
|
|
352
|
+
}) {
|
|
353
|
+
try {
|
|
354
|
+
const versionStatus = yield select(selectVersionStatus);
|
|
355
|
+
const query = new Query(Op.equalTo('sys.id', entryId), Op.equalTo('sys.language', language), Op.equalTo('sys.versionStatus', versionStatus));
|
|
356
|
+
query.fields = ['sys.uri'];
|
|
357
|
+
query.pageSize = 1;
|
|
358
|
+
const result = yield cachedSearch.search(query);
|
|
359
|
+
return result.items.length ? result.items[0].sys.uri : null;
|
|
360
|
+
} catch (error) {
|
|
361
|
+
console.error('Error fetching language variations:', error);
|
|
362
|
+
yield put(actions.GET_ENTRY_URI_ERROR(error));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
61
366
|
const sys = {
|
|
62
367
|
versionStatus: 'sys.versionStatus'
|
|
63
368
|
};
|
|
@@ -80,6 +385,88 @@ const routeEntryByFieldsQuery = (id, language = 'en-GB', contentTypeId = '', fie
|
|
|
80
385
|
return query;
|
|
81
386
|
};
|
|
82
387
|
|
|
388
|
+
function* reduxInjectorSaga(injectorFn) {
|
|
389
|
+
if (typeof injectorFn === 'function') {
|
|
390
|
+
const {
|
|
391
|
+
key,
|
|
392
|
+
reducer,
|
|
393
|
+
saga
|
|
394
|
+
} = yield injectorFn();
|
|
395
|
+
injectRedux({
|
|
396
|
+
key,
|
|
397
|
+
reducer,
|
|
398
|
+
saga
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* @description Asynchronously load and inject assets related to Search
|
|
405
|
+
*/
|
|
406
|
+
const importSearchAssets = () => import('./search.js');
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Invokes the Search saga if:
|
|
410
|
+
* - `searchOptions` is present on `staticRoute` or `contentTypeRoute`
|
|
411
|
+
* - `searchOptions` is provided by the consumer app
|
|
412
|
+
* - and path starts with one of `onPaths: ['/search']`
|
|
413
|
+
* - or a `facet` or `listingType` is present in provided `searchOptions`
|
|
414
|
+
*
|
|
415
|
+
* A `config` is required if we want to inject the redux reducer here, sagas are injected automatically
|
|
416
|
+
*/
|
|
417
|
+
function* handleSearchSaga({
|
|
418
|
+
location,
|
|
419
|
+
params,
|
|
420
|
+
routeSearchOptions,
|
|
421
|
+
searchOptions,
|
|
422
|
+
ssr
|
|
423
|
+
}) {
|
|
424
|
+
// Merge supplied mappers with route-supplied mappers taking precedence
|
|
425
|
+
const mappers = {
|
|
426
|
+
results: e => e,
|
|
427
|
+
...((searchOptions === null || searchOptions === void 0 ? void 0 : searchOptions.mappers) || {}),
|
|
428
|
+
...((routeSearchOptions === null || routeSearchOptions === void 0 ? void 0 : routeSearchOptions.mappers) || {})
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// Merge all other search options with route-supplied options taking precedence
|
|
432
|
+
const {
|
|
433
|
+
onPaths = ['/search'],
|
|
434
|
+
...searchOpts
|
|
435
|
+
} = {
|
|
436
|
+
...(routeSearchOptions || {}),
|
|
437
|
+
...(searchOptions || {})
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// Check do we meet conditions to run the search saga
|
|
441
|
+
const invokeSearch = onPaths.find(p => location.pathname.startsWith(p)) || searchOpts.composition || searchOpts.facet || searchOpts.listingType;
|
|
442
|
+
|
|
443
|
+
// An empty routeSearchOptions object can be used to import assets and load config for a minilist
|
|
444
|
+
const importAssets = routeSearchOptions;
|
|
445
|
+
if (importAssets || invokeSearch) {
|
|
446
|
+
// Async load search assets
|
|
447
|
+
const {
|
|
448
|
+
reducer,
|
|
449
|
+
sagas,
|
|
450
|
+
setRouteFilters
|
|
451
|
+
} = yield importSearchAssets();
|
|
452
|
+
|
|
453
|
+
// Inject search reducer and sagas
|
|
454
|
+
yield call(reduxInjectorSaga, async () => ({
|
|
455
|
+
key: 'search',
|
|
456
|
+
reducer: searchOpts.config && reducer(searchOpts.config),
|
|
457
|
+
saga: sagas
|
|
458
|
+
}));
|
|
459
|
+
if (invokeSearch) yield call(setRouteFilters, {
|
|
460
|
+
params,
|
|
461
|
+
ssr,
|
|
462
|
+
...searchOpts,
|
|
463
|
+
mappers
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const error = (e, message) => logError(`[routeSaga]${message ? ` ${message}` : ''}`, e);
|
|
469
|
+
let livePreviewTask = null;
|
|
83
470
|
const routingSagas = [takeEvery(SET_NAVIGATION_PATH, getRouteSaga), takeEvery(SET_ROUTE, setRouteSaga)];
|
|
84
471
|
|
|
85
472
|
/**
|
|
@@ -98,7 +485,7 @@ function* setRouteSaga(action) {
|
|
|
98
485
|
function* getRouteSaga(action) {
|
|
99
486
|
let entry = null;
|
|
100
487
|
try {
|
|
101
|
-
var _staticRoute$route, _staticRoute$route2, _staticRoute$route3, _staticRoute$route4, _appsays, _appsays2, _appsays3, _pathNode3, _pathNode4;
|
|
488
|
+
var _staticRoute$route, _staticRoute$route2, _staticRoute$route3, _staticRoute$route4, _appsays, _appsays2, _appsays3, _pathNode3, _pathNode4, _pathNode5;
|
|
102
489
|
const {
|
|
103
490
|
withEvents,
|
|
104
491
|
routes: {
|
|
@@ -107,7 +494,8 @@ function* getRouteSaga(action) {
|
|
|
107
494
|
staticRoute,
|
|
108
495
|
// get api instance from ssr context that is connected to the specific request in ssr
|
|
109
496
|
ssr: {
|
|
110
|
-
api
|
|
497
|
+
api,
|
|
498
|
+
subsitePath
|
|
111
499
|
}
|
|
112
500
|
} = action;
|
|
113
501
|
|
|
@@ -124,7 +512,12 @@ function* getRouteSaga(action) {
|
|
|
124
512
|
// These variables are the return values from
|
|
125
513
|
// calls to withEvents.onRouteLoad and onRouteLoaded
|
|
126
514
|
let appsays,
|
|
127
|
-
requireLogin = false
|
|
515
|
+
requireLogin = false,
|
|
516
|
+
searchOptions = false;
|
|
517
|
+
|
|
518
|
+
// Route parameters are used for driving search options and live preview functionality,
|
|
519
|
+
// and are passed to the consuming app via withEvents hooks
|
|
520
|
+
const params = routeParams(staticRoute, action.location);
|
|
128
521
|
if (withEvents && withEvents.onRouteLoad) {
|
|
129
522
|
appsays = yield withEvents.onRouteLoad(action);
|
|
130
523
|
}
|
|
@@ -141,15 +534,30 @@ function* getRouteSaga(action) {
|
|
|
141
534
|
const entryFieldLinkDepths = (_appsays = appsays) === null || _appsays === void 0 ? void 0 : _appsays.entryFieldLinkDepths;
|
|
142
535
|
const setStaticRouteLimits = typeof linkDepth !== 'undefined' || fields || fieldLinkDepths;
|
|
143
536
|
const setContentTypeLimits = !!ContentTypeMappings.find(ct => ct.fields || ct.linkDepth || ct.nodeOptions || ct.fieldLinkDepths);
|
|
537
|
+
|
|
538
|
+
// Limits set in a static route take priority over limits in a content type mapping
|
|
539
|
+
// If we have limits set in:
|
|
540
|
+
// - a matched static route - set them here to resolve everything with the initial node upfront
|
|
541
|
+
// - any content type mapping - we set defaults for the initial node resolve then
|
|
542
|
+
// - identify the contentTypeId and locate the content type mapping
|
|
543
|
+
// - perform a second search query with the limits applied from the content type mapping
|
|
544
|
+
// If no limits are set in route configuration:
|
|
545
|
+
// - fall back to entryLinkDepth and entryFieldLinkDepths provided by the app in `onRouteLoad` event
|
|
546
|
+
// - or default to entryLinkDepth of 2 with all fields (default for legacy `/preview` endpoints)
|
|
547
|
+
fields = setStaticRouteLimits ? fields || '*' : setContentTypeLimits ? ['sys.contentTypeId', 'sys.id'] : '*';
|
|
548
|
+
linkDepth = setStaticRouteLimits && typeof linkDepth !== 'undefined' ? linkDepth : setContentTypeLimits ? 0 : entryLinkDepth;
|
|
549
|
+
fieldLinkDepths = setStaticRouteLimits ? fieldLinkDepths : setContentTypeLimits ? undefined : entryFieldLinkDepths;
|
|
144
550
|
const state = yield select();
|
|
145
551
|
const routeEntry = selectRouteEntry(state, 'js');
|
|
146
552
|
const routeNode = selectCurrentNode(state, 'js');
|
|
147
553
|
const currentPath = action.path; //selectCurrentPath(state);
|
|
554
|
+
const contentPath = action.contentPath;
|
|
148
555
|
const deliveryApiStatus = selectVersionStatus(state);
|
|
149
556
|
const project = selectCurrentProject(state);
|
|
150
557
|
// const isHome = currentPath === '/';
|
|
151
558
|
const isPreview = currentPath && currentPath.startsWith('/preview/');
|
|
152
|
-
const
|
|
559
|
+
const currentLanguage = selectCurrentLanguage(state);
|
|
560
|
+
const defaultLang = appsays && appsays.defaultLang || currentLanguage || 'en-GB';
|
|
153
561
|
if (!isPreview && ((_appsays2 = appsays) !== null && _appsays2 !== void 0 && _appsays2.customRouting || staticRoute && !staticRoute.route.fetchNode || routeEntry && action.statePath === action.path && ((_appsays3 = appsays) === null || _appsays3 === void 0 ? void 0 : _appsays3.refetchNode) !== true)) {
|
|
154
562
|
var _staticRoute$route5;
|
|
155
563
|
// To prevent erroneous 404s and wasted network calls, this covers
|
|
@@ -162,21 +570,25 @@ function* getRouteSaga(action) {
|
|
|
162
570
|
entry: null
|
|
163
571
|
};
|
|
164
572
|
pathNode.entry = entry = routeEntry;
|
|
165
|
-
//Do nothing, the entry is allready the right one.
|
|
166
|
-
// yield put({
|
|
167
|
-
// type: SET_ENTRY,
|
|
168
|
-
// entry,
|
|
169
|
-
// node: routeNode,
|
|
170
|
-
// isLoading: false,
|
|
171
|
-
// });
|
|
172
573
|
yield put({
|
|
173
574
|
type: UPDATE_LOADING_STATE,
|
|
174
575
|
isLoading: false
|
|
175
576
|
});
|
|
577
|
+
if (params.livePreview && typeof window !== 'undefined') {
|
|
578
|
+
var _contentTypeMapping, _contentTypeMapping2, _contentTypeMapping3;
|
|
579
|
+
// Update the "limits" (fields, fieldLinkDepths and linkDepth)
|
|
580
|
+
// used in route resolution (likely SSR) based on the entry's content type mapping
|
|
581
|
+
// so that we can pass the correct limits to live preview parent
|
|
582
|
+
contentTypeMapping = findContentTypeMapping(ContentTypeMappings, entry.sys.contentTypeId);
|
|
583
|
+
// Static route limits override content type mapping limits
|
|
584
|
+
fields = setStaticRouteLimits ? fields || '*' : ((_contentTypeMapping = contentTypeMapping) === null || _contentTypeMapping === void 0 ? void 0 : _contentTypeMapping.fields) || fields;
|
|
585
|
+
linkDepth = setStaticRouteLimits ? linkDepth || 0 : typeof ((_contentTypeMapping2 = contentTypeMapping) === null || _contentTypeMapping2 === void 0 ? void 0 : _contentTypeMapping2.linkDepth) !== 'undefined' ? contentTypeMapping.linkDepth : linkDepth;
|
|
586
|
+
fieldLinkDepths = setStaticRouteLimits ? fieldLinkDepths : ((_contentTypeMapping3 = contentTypeMapping) === null || _contentTypeMapping3 === void 0 ? void 0 : _contentTypeMapping3.fieldLinkDepths) || fieldLinkDepths;
|
|
587
|
+
}
|
|
176
588
|
} else yield call(setRouteEntry, currentPath, routeEntry, yield select(selectCurrentNode), yield select(selectCurrentAncestors), yield select(selectCurrentSiblings));
|
|
177
589
|
} else {
|
|
178
590
|
var _staticRoute$route6;
|
|
179
|
-
// Handle preview routes
|
|
591
|
+
// Handle preview routes (legacy - can we remove?)
|
|
180
592
|
if (isPreview) {
|
|
181
593
|
let splitPath = currentPath.split('/');
|
|
182
594
|
let entryGuid = splitPath[2];
|
|
@@ -189,7 +601,6 @@ function* getRouteSaga(action) {
|
|
|
189
601
|
// for previewing entries as it gives a response of []
|
|
190
602
|
// -- apparently it is not correct to request latest content
|
|
191
603
|
// with Node API
|
|
192
|
-
|
|
193
604
|
let previewEntry = yield api.getClient(deliveryApiStatus, project).entries.get({
|
|
194
605
|
id: entryGuid,
|
|
195
606
|
language,
|
|
@@ -212,11 +623,13 @@ function* getRouteSaga(action) {
|
|
|
212
623
|
// Resolve the complete entry with the node if we are setting limits in a static route
|
|
213
624
|
[nodeError, pathNode] = yield to(api.getNode({
|
|
214
625
|
depth: 0,
|
|
215
|
-
path:
|
|
216
|
-
entryFields:
|
|
217
|
-
entryLinkDepth:
|
|
218
|
-
entryFieldLinkDepths:
|
|
219
|
-
language
|
|
626
|
+
path: contentPath,
|
|
627
|
+
entryFields: fields,
|
|
628
|
+
entryLinkDepth: linkDepth,
|
|
629
|
+
entryFieldLinkDepths: fieldLinkDepths,
|
|
630
|
+
// language parameter is not used when resolving a node by path
|
|
631
|
+
// https://www.contensis.com/help-and-docs/apis/delivery-http/navigation/nodes/get-a-node-by-path
|
|
632
|
+
// language: defaultLang,
|
|
220
633
|
versionStatus: deliveryApiStatus
|
|
221
634
|
}, project));
|
|
222
635
|
if (nodeError) {
|
|
@@ -266,10 +679,10 @@ function* getRouteSaga(action) {
|
|
|
266
679
|
if (!setStaticRouteLimits) ({
|
|
267
680
|
fieldLinkDepths,
|
|
268
681
|
fields,
|
|
269
|
-
linkDepth
|
|
682
|
+
linkDepth = 0
|
|
270
683
|
} = contentTypeMapping || {});
|
|
271
684
|
const query = routeEntryByFieldsQuery(pathNode.entry.sys.id, pathNode.entry.sys.language, pathNode.entry.sys.contentTypeId, fields, fieldLinkDepths, deliveryApiStatus);
|
|
272
|
-
const payload = yield api.search(query,
|
|
685
|
+
const payload = yield api.search(query, linkDepth, project);
|
|
273
686
|
if ((payload === null || payload === void 0 || (_payload$items = payload.items) === null || _payload$items === void 0 ? void 0 : _payload$items.length) > 0) {
|
|
274
687
|
pathNode.entry = entry = payload.items[0];
|
|
275
688
|
}
|
|
@@ -283,25 +696,42 @@ function* getRouteSaga(action) {
|
|
|
283
696
|
appsays,
|
|
284
697
|
contentTypeMapping: contentTypeMapping || (staticRoute === null || staticRoute === void 0 || (_staticRoute$route6 = staticRoute.route) === null || _staticRoute$route6 === void 0 ? void 0 : _staticRoute$route6.fetchNode) || {},
|
|
285
698
|
language: defaultLang,
|
|
286
|
-
path:
|
|
699
|
+
path: contentPath,
|
|
287
700
|
pathNode,
|
|
288
701
|
project,
|
|
702
|
+
subsitePath,
|
|
289
703
|
versionStatus: deliveryApiStatus
|
|
290
704
|
});
|
|
291
705
|
if (children) pathNode.children = children;
|
|
292
706
|
}
|
|
293
|
-
|
|
707
|
+
|
|
708
|
+
// We initially listened for SET_ENTRY to complete before
|
|
709
|
+
// resolving the current route language, but this meant
|
|
710
|
+
// that the language change was not captured in time for the SSR response
|
|
711
|
+
yield call(resolveCurrentRouteLanguage, {
|
|
712
|
+
entry: (_pathNode3 = pathNode) === null || _pathNode3 === void 0 ? void 0 : _pathNode3.entry,
|
|
713
|
+
node: pathNode
|
|
714
|
+
});
|
|
715
|
+
const contentTypeRoute = findContentTypeMapping(ContentTypeMappings, (_pathNode4 = pathNode) === null || _pathNode4 === void 0 || (_pathNode4 = _pathNode4.entry) === null || _pathNode4 === void 0 || (_pathNode4 = _pathNode4.sys) === null || _pathNode4 === void 0 ? void 0 : _pathNode4.contentTypeId);
|
|
294
716
|
|
|
295
717
|
// Inject redux { key, reducer, saga } provided by ContentTypeMapping
|
|
296
|
-
if (
|
|
718
|
+
if (contentTypeRoute !== null && contentTypeRoute !== void 0 && contentTypeRoute.injectRedux) yield call(reduxInjectorSaga, contentTypeRoute.injectRedux);
|
|
719
|
+
|
|
720
|
+
// Have we defined search options in the route configuration (for triggering search)
|
|
721
|
+
const routeSearchOptions = getSearchOptions(staticRoute, contentTypeRoute);
|
|
297
722
|
if (withEvents && withEvents.onRouteLoaded) {
|
|
298
723
|
// Check if the app has provided a requireLogin boolean flag or groups array
|
|
299
724
|
// in addition to checking if requireLogin is set in the route definition
|
|
725
|
+
// The app can provide an object to invoke the search saga
|
|
300
726
|
({
|
|
301
|
-
requireLogin
|
|
727
|
+
requireLogin,
|
|
728
|
+
searchOptions
|
|
302
729
|
} = (yield withEvents.onRouteLoaded({
|
|
303
730
|
...action,
|
|
304
|
-
|
|
731
|
+
contentTypeRoute,
|
|
732
|
+
entry,
|
|
733
|
+
params,
|
|
734
|
+
searchOptions: routeSearchOptions
|
|
305
735
|
})) || {});
|
|
306
736
|
}
|
|
307
737
|
if (requireLogin !== false) {
|
|
@@ -312,22 +742,88 @@ function* getRouteSaga(action) {
|
|
|
312
742
|
requireLogin
|
|
313
743
|
});
|
|
314
744
|
}
|
|
745
|
+
if (searchOptions || routeSearchOptions) yield call(handleSearchSaga, {
|
|
746
|
+
...action,
|
|
747
|
+
params,
|
|
748
|
+
routeSearchOptions,
|
|
749
|
+
searchOptions
|
|
750
|
+
});
|
|
315
751
|
if (!appsays || !appsays.preventScrollTop) {
|
|
316
752
|
// Scroll into View
|
|
317
753
|
if (typeof window !== 'undefined') window.scrollTo(0, 0);
|
|
318
754
|
}
|
|
319
|
-
if ((
|
|
755
|
+
if ((_pathNode5 = pathNode) !== null && _pathNode5 !== void 0 && (_pathNode5 = _pathNode5.entry) !== null && _pathNode5 !== void 0 && (_pathNode5 = _pathNode5.sys) !== null && _pathNode5 !== void 0 && _pathNode5.id) {
|
|
320
756
|
var _appsays4;
|
|
757
|
+
entryMapper = entryMapper || (contentTypeRoute === null || contentTypeRoute === void 0 ? void 0 : contentTypeRoute.entryMapper);
|
|
758
|
+
if (params.livePreview && typeof window !== 'undefined') {
|
|
759
|
+
if (livePreviewTask) yield cancel(livePreviewTask);
|
|
760
|
+
livePreviewTask = yield fork(watchLivePreviewSaga, {
|
|
761
|
+
currentPath,
|
|
762
|
+
entry,
|
|
763
|
+
entryMapper,
|
|
764
|
+
pathNode,
|
|
765
|
+
limits: {
|
|
766
|
+
fields,
|
|
767
|
+
fieldLinkDepths,
|
|
768
|
+
linkDepth
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
}
|
|
321
772
|
entry = pathNode.entry;
|
|
322
|
-
yield call(setRouteEntry, currentPath, entry, pathNode, ancestors, siblings, entryMapper
|
|
773
|
+
yield call(setRouteEntry, currentPath, entry, pathNode, ancestors, siblings, entryMapper, false, (_appsays4 = appsays) === null || _appsays4 === void 0 ? void 0 : _appsays4.refetchNode);
|
|
323
774
|
} else {
|
|
324
775
|
if (staticRoute) yield call(setRouteEntry, currentPath, null, pathNode, ancestors, siblings);else yield call(do404);
|
|
325
776
|
}
|
|
326
777
|
} catch (e) {
|
|
327
|
-
|
|
778
|
+
error(e);
|
|
328
779
|
yield call(do500, e);
|
|
329
780
|
}
|
|
330
781
|
}
|
|
782
|
+
function createLivePreviewChannel() {
|
|
783
|
+
return eventChannel(emit => {
|
|
784
|
+
const handler = e => {
|
|
785
|
+
var _e$data;
|
|
786
|
+
// console.log('Received message in live preview channel', e.data);
|
|
787
|
+
if ((_e$data = e.data) !== null && _e$data !== void 0 && (_e$data = _e$data.type) !== null && _e$data !== void 0 && _e$data.startsWith('LIVE_ENTRY_')) emit(e.data);
|
|
788
|
+
};
|
|
789
|
+
window.addEventListener('message', handler);
|
|
790
|
+
return () => window.removeEventListener('message', handler);
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
function* watchLivePreviewSaga(context) {
|
|
794
|
+
var _parent;
|
|
795
|
+
const channel = createLivePreviewChannel();
|
|
796
|
+
const routeLoadOptions = {
|
|
797
|
+
type: 'LIVE_ENTRY_ROUTE_LOAD_OPTIONS',
|
|
798
|
+
payload: context.limits
|
|
799
|
+
};
|
|
800
|
+
if (routeParams().debug) routeLoadOptions.debug = context.pathNode;
|
|
801
|
+
(_parent = parent) === null || _parent === void 0 || _parent.postMessage(routeLoadOptions, '*');
|
|
802
|
+
try {
|
|
803
|
+
while (true) {
|
|
804
|
+
const data = yield take(channel);
|
|
805
|
+
let entry = yield select(selectRouteEntry);
|
|
806
|
+
if (data.type === 'LIVE_ENTRY_RESET') {
|
|
807
|
+
console.log('Resetting live preview entry to original route entry');
|
|
808
|
+
entry = context.entry;
|
|
809
|
+
} else if (data.type === 'LIVE_ENTRY_UPDATE') {
|
|
810
|
+
console.log('Handling live preview update', data);
|
|
811
|
+
entry = {
|
|
812
|
+
...entry,
|
|
813
|
+
...data.payload
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
yield call(setRouteEntry, context.currentPath, entry, context.pathNode, null,
|
|
817
|
+
// ancestors unchanged
|
|
818
|
+
null,
|
|
819
|
+
// siblings unchanged
|
|
820
|
+
context.entryMapper, false, true // we need to remap the entry here
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
} finally {
|
|
824
|
+
if (yield cancelled()) channel.close();
|
|
825
|
+
}
|
|
826
|
+
}
|
|
331
827
|
function* resolveCurrentNodeOrdinates(action) {
|
|
332
828
|
const {
|
|
333
829
|
api,
|
|
@@ -337,6 +833,7 @@ function* resolveCurrentNodeOrdinates(action) {
|
|
|
337
833
|
path,
|
|
338
834
|
pathNode,
|
|
339
835
|
project,
|
|
836
|
+
subsitePath,
|
|
340
837
|
versionStatus
|
|
341
838
|
} = action;
|
|
342
839
|
const apiCall = [() => null, () => null, () => null, () => null];
|
|
@@ -359,10 +856,11 @@ function* resolveCurrentNodeOrdinates(action) {
|
|
|
359
856
|
return yield api.getAncestors({
|
|
360
857
|
id: pathNode.id,
|
|
361
858
|
language,
|
|
362
|
-
versionStatus
|
|
859
|
+
versionStatus,
|
|
860
|
+
startLevel: (subsitePath || '').split('/').length
|
|
363
861
|
}, project);
|
|
364
862
|
} catch (ex) {
|
|
365
|
-
|
|
863
|
+
error(ex, 'Problem fetching ancestors');
|
|
366
864
|
return [];
|
|
367
865
|
}
|
|
368
866
|
};
|
|
@@ -382,7 +880,7 @@ function* resolveCurrentNodeOrdinates(action) {
|
|
|
382
880
|
versionStatus
|
|
383
881
|
}, project);
|
|
384
882
|
} catch (ex) {
|
|
385
|
-
|
|
883
|
+
error(ex, 'Problem fetching children');
|
|
386
884
|
return [];
|
|
387
885
|
}
|
|
388
886
|
};
|
|
@@ -401,7 +899,7 @@ function* resolveCurrentNodeOrdinates(action) {
|
|
|
401
899
|
versionStatus
|
|
402
900
|
}, project);
|
|
403
901
|
} catch (ex) {
|
|
404
|
-
|
|
902
|
+
error(ex, 'Problem fetching siblings');
|
|
405
903
|
return [];
|
|
406
904
|
}
|
|
407
905
|
};
|
|
@@ -465,7 +963,7 @@ function* mapRouteEntry(entryMapper, node) {
|
|
|
465
963
|
return mappedEntry;
|
|
466
964
|
}
|
|
467
965
|
} catch (e) {
|
|
468
|
-
|
|
966
|
+
error(e, 'Error in entryMapper:');
|
|
469
967
|
throw e;
|
|
470
968
|
}
|
|
471
969
|
return;
|
|
@@ -500,20 +998,6 @@ function* do500(error) {
|
|
|
500
998
|
statusCode: error && error.status ? error.status : 500
|
|
501
999
|
});
|
|
502
1000
|
}
|
|
503
|
-
function* reduxInjectorSaga(injectorFn) {
|
|
504
|
-
if (typeof injectorFn === 'function') {
|
|
505
|
-
const {
|
|
506
|
-
key,
|
|
507
|
-
reducer,
|
|
508
|
-
saga
|
|
509
|
-
} = yield injectorFn();
|
|
510
|
-
injectRedux({
|
|
511
|
-
key,
|
|
512
|
-
reducer,
|
|
513
|
-
saga
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
1001
|
|
|
518
1002
|
const registerSagas = [takeEvery(REGISTER_USER, registerSaga), takeEvery(REGISTER_USER_SUCCESS, redirectSaga)];
|
|
519
1003
|
function* registerSaga({
|
|
@@ -763,11 +1247,6 @@ function* changePasswordSaga(action) {
|
|
|
763
1247
|
});
|
|
764
1248
|
return;
|
|
765
1249
|
}
|
|
766
|
-
|
|
767
|
-
// // eslint-disable-next-line no-console
|
|
768
|
-
// console.log(changePasswordObject);
|
|
769
|
-
// // eslint-disable-next-line no-console
|
|
770
|
-
// console.log(userCredentialsObject);
|
|
771
1250
|
yield put({
|
|
772
1251
|
type: CHANGE_USER_PASSWORD_SUCCESS
|
|
773
1252
|
});
|
|
@@ -781,13 +1260,16 @@ function* changePasswordSaga(action) {
|
|
|
781
1260
|
|
|
782
1261
|
const userSagas = [...loginSagas, ...registerSagas, ...resetPasswordSagas];
|
|
783
1262
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
1263
|
+
var rootSaga = (featureSagas = []) => {
|
|
1264
|
+
return [...i18nSagas, ...routingSagas, ...navigationSagas, ...userSagas, ...featureSagas];
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
// export default function (featureSagas: Effect[] = []) {
|
|
1268
|
+
// return function* rootSaga() {
|
|
1269
|
+
// const subSagas = [...routingSagas, ...navigationSagas, ...userSagas];
|
|
1270
|
+
// yield all([...subSagas, ...featureSagas]);
|
|
1271
|
+
// };
|
|
1272
|
+
// }
|
|
791
1273
|
|
|
792
1274
|
const servers = SERVERS; /* global SERVERS */
|
|
793
1275
|
const alias = servers.alias.toLowerCase();
|
|
@@ -832,5 +1314,5 @@ const AppRoot = props => {
|
|
|
832
1314
|
return /*#__PURE__*/React.createElement(RouteLoader, props);
|
|
833
1315
|
};
|
|
834
1316
|
|
|
835
|
-
export { AppRoot as A, browserHistory as b, history as h, pickProject as p, rootSaga as r };
|
|
836
|
-
//# sourceMappingURL=App-
|
|
1317
|
+
export { AppRoot as A, browserHistory as b, createLocaleRoutes as c, history as h, pickProject as p, rootSaga as r, shorten as s };
|
|
1318
|
+
//# sourceMappingURL=App-Bplaqueq.js.map
|