@zengenti/contensis-react-base 4.0.0-beta.6 → 4.0.0-beta.60
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-Dr56ZsQj.js} +476 -99
- package/cjs/App-Dr56ZsQj.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-gN3_MHEl.js} +32 -74
- package/cjs/ContensisDeliveryApi-gN3_MHEl.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-Bbt-nG3v.js} +13 -8
- package/cjs/RouteLoader-Bbt-nG3v.js.map +1 -0
- package/cjs/SSRContext-DotLlTQc.js +116 -0
- package/cjs/SSRContext-DotLlTQc.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 +62 -64
- package/cjs/client.js.map +1 -1
- package/cjs/contensis-react-base.js +235 -127
- 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-CbZhaRNd.js → sagas-OfBUtx74.js} +523 -370
- package/cjs/sagas-OfBUtx74.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-Dn7vP6G0.js} +52 -4
- package/cjs/store-Dn7vP6G0.js.map +1 -0
- package/cjs/urls-DVIwGZmd.js +25 -0
- package/cjs/urls-DVIwGZmd.js.map +1 -0
- package/cjs/user.js +20 -17
- package/cjs/user.js.map +1 -1
- package/cjs/util-wQwG9vit.js +148 -0
- package/cjs/util-wQwG9vit.js.map +1 -0
- package/cjs/util.js +80 -22
- package/cjs/util.js.map +1 -1
- package/cjs/{version-B7XFkBhY.js → version-2FamXHhj.js} +15 -16
- package/cjs/version-2FamXHhj.js.map +1 -0
- 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/esm/{App-DLZweVSp.js → App-CrCf7gso.js} +436 -60
- package/esm/App-CrCf7gso.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-CvEoOLCl.js} +30 -67
- package/esm/ContensisDeliveryApi-CvEoOLCl.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-BpHhiAlL.js} +10 -5
- package/esm/RouteLoader-BpHhiAlL.js.map +1 -0
- package/esm/SSRContext-CYxBWky3.js +106 -0
- package/esm/SSRContext-CYxBWky3.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 +62 -63
- package/esm/client.js.map +1 -1
- package/esm/contensis-react-base.js +227 -121
- 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-xJU-zOpn.js → sagas-BZWjx5by.js} +511 -357
- package/esm/sagas-BZWjx5by.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-DSjRYsM2.js} +52 -5
- package/esm/store-DSjRYsM2.js.map +1 -0
- package/esm/urls-DfCisos-.js +22 -0
- package/esm/urls-DfCisos-.js.map +1 -0
- package/esm/user.js +9 -6
- package/esm/user.js.map +1 -1
- package/esm/util-BafFLYzn.js +136 -0
- package/esm/util-BafFLYzn.js.map +1 -0
- package/esm/util.js +58 -14
- package/esm/util.js.map +1 -1
- package/esm/{version-BlsI7hX2.js → version-B75wA6Te.js} +16 -16
- package/esm/version-B75wA6Te.js.map +1 -0
- 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/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 +0 -1
- 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 +5 -0
- 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/SSRContext.d.ts +4 -4
- package/models/models/StaticRoute.d.ts +11 -0
- 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 +3 -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/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/index.d.ts +6 -1
- package/models/util/subsite.d.ts +12 -0
- package/models/util/useIsClient.d.ts +6 -0
- package/package.json +39 -38
- 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-CbZhaRNd.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-xJU-zOpn.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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var queryString = require('query-string');
|
|
4
|
+
var ContensisDeliveryApi = require('./ContensisDeliveryApi-gN3_MHEl.js');
|
|
5
|
+
|
|
6
|
+
const now = () => {
|
|
7
|
+
if (typeof window == 'undefined') {
|
|
8
|
+
return Date.now();
|
|
9
|
+
}
|
|
10
|
+
return window.performance.now();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function fixFreeTextForElastic(s) {
|
|
14
|
+
const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
|
|
15
|
+
const illegalRegEx = new RegExp(illegalChars.map(c => '\\' + c).join('|'), 'g');
|
|
16
|
+
s = s.replace(illegalRegEx, '');
|
|
17
|
+
// s = s.replace(encodedRegEx, ''); // (m) => '\\\\' + m);
|
|
18
|
+
|
|
19
|
+
return s;
|
|
20
|
+
}
|
|
21
|
+
/** `convertKeyForAggregation` and `parseKeyForAggregation` exists to prevent an
|
|
22
|
+
* auto-generated aggregation using a reserved keyword because Elasticsearch has a list of
|
|
23
|
+
* reserved keywords when it parses the response:
|
|
24
|
+
* `'location' is one of the reserved aggregation keywords we use a heuristics based
|
|
25
|
+
* response parser and using these reserved keywords could throw its heuristics off
|
|
26
|
+
* course. We are working on a solution in Elasticsearch itself to make the response
|
|
27
|
+
* parseable. For now these are all the reserved keywords: after_key, _as_string,
|
|
28
|
+
* bg_count, bottom_right, bounds, buckets, count, doc_count, doc_count_error_upper_bound,
|
|
29
|
+
* fields, from, top, type, from_as_string, hits, key, key_as_string, keys, location,
|
|
30
|
+
* max_score, meta, min, min_length, score, sum_other_doc_count, to, to_as_string, top_left,
|
|
31
|
+
* total, value, value_as_string, values, geometry, properties`
|
|
32
|
+
*/
|
|
33
|
+
const convertKeyForAggregation = key => `sf_${key}`;
|
|
34
|
+
const cleanseFieldIdForAggregation = fieldId => fieldId.replaceAll('[]', '');
|
|
35
|
+
const timedSearch = async (query, linkDepth = 0, projectId,
|
|
36
|
+
// get api instance from SSR context that is connected to the current request in SSR,
|
|
37
|
+
// fall back to the imported cachedSearch api that is not connected to the current SSR context
|
|
38
|
+
ssr = {
|
|
39
|
+
api: ContensisDeliveryApi.cachedSearch
|
|
40
|
+
}) => {
|
|
41
|
+
if (!query) return null;
|
|
42
|
+
let duration = 0;
|
|
43
|
+
const start = now();
|
|
44
|
+
const payload = await ssr.api.search(query, linkDepth, projectId);
|
|
45
|
+
const end = now();
|
|
46
|
+
duration = Number((end - start).toFixed(2));
|
|
47
|
+
return {
|
|
48
|
+
duration,
|
|
49
|
+
payload
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const getItemsFromResult = result => {
|
|
53
|
+
const {
|
|
54
|
+
payload
|
|
55
|
+
} = result || {};
|
|
56
|
+
if (payload) {
|
|
57
|
+
if (Array.isArray(payload)) return payload;
|
|
58
|
+
if (Array.isArray(payload.items)) return payload.items;
|
|
59
|
+
return payload;
|
|
60
|
+
}
|
|
61
|
+
return [];
|
|
62
|
+
};
|
|
63
|
+
const extractQuotedPhrases = searchTerm => {
|
|
64
|
+
const pattern = new RegExp(/(?=["'])(?:"[^"\\]*(?:\\[\s\S][^"\\]*)*"|'[^'\\]*(?:\\[\s\S][^'\\]*)*')/gm);
|
|
65
|
+
return (searchTerm.match(pattern) || []).map(match => match.replace(/"/g, ''));
|
|
66
|
+
};
|
|
67
|
+
const buildUrl = (route, params) => {
|
|
68
|
+
const qs = queryString.stringify(params);
|
|
69
|
+
const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;
|
|
70
|
+
return path;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns all params from the current route query string or static route
|
|
75
|
+
* Supply static route argument if reading parameters from the route path
|
|
76
|
+
* Supply location argument for the params to be read in SSR
|
|
77
|
+
* @param staticRoute Matched static route from react-router 5 or 6
|
|
78
|
+
* @param location location object containing at least pathname and search
|
|
79
|
+
* @returns Keyed params object
|
|
80
|
+
*/
|
|
81
|
+
const routeParams = (staticRoute, location) => {
|
|
82
|
+
var _staticRoute$match;
|
|
83
|
+
// match.params is react-router-config/react-router@5 style
|
|
84
|
+
// params is supplied with RouteObject in react-router@6
|
|
85
|
+
const pathParams = (staticRoute === null || staticRoute === void 0 || (_staticRoute$match = staticRoute.match) === null || _staticRoute$match === void 0 ? void 0 : _staticRoute$match.params) || (staticRoute === null || staticRoute === void 0 ? void 0 : staticRoute.params) || {};
|
|
86
|
+
const queryParams = queryString.parse(typeof window !== 'undefined' ? window.location.search : (location === null || location === void 0 ? void 0 : location.search) || '');
|
|
87
|
+
return {
|
|
88
|
+
...pathParams,
|
|
89
|
+
...queryParams
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const callCustomApi = async (customApi, filters,
|
|
93
|
+
// get api instance from SSR context that is connected to the current request in SSR,
|
|
94
|
+
// fall back to the imported cachedSearch api that is not connected to the current SSR context
|
|
95
|
+
ssr = {
|
|
96
|
+
api: ContensisDeliveryApi.cachedSearch
|
|
97
|
+
}) => {
|
|
98
|
+
const apiUri = customApi.uri || '';
|
|
99
|
+
let uri = buildUrl(apiUri, filters);
|
|
100
|
+
if (!uri) throw new Error('uri is required to use customApi');
|
|
101
|
+
if (typeof window == 'undefined') {
|
|
102
|
+
if (!uri.startsWith('http')) uri = `http://localhost:3001${uri}`;
|
|
103
|
+
const response = await fetch(uri);
|
|
104
|
+
return await response.json();
|
|
105
|
+
}
|
|
106
|
+
const response = await ssr.api.fetch(uri);
|
|
107
|
+
return await response.clone().json();
|
|
108
|
+
};
|
|
109
|
+
const removeEmptyAttributes = obj => {
|
|
110
|
+
Object.entries(obj).forEach(([key, val]) => val && typeof val === 'object' && removeEmptyAttributes(val) || (typeof val === 'undefined' || val === null || val === '') && delete obj[key]);
|
|
111
|
+
return obj;
|
|
112
|
+
};
|
|
113
|
+
const toArray = (obj, seperator = ',') => typeof obj === 'undefined' || obj === null ? obj : Array.isArray(obj) ? obj : obj.split(seperator);
|
|
114
|
+
|
|
115
|
+
// assumes array elements are primitive types
|
|
116
|
+
const areArraysEqualSets = (a1, a2) => {
|
|
117
|
+
const superSet = {};
|
|
118
|
+
for (const ai of a1) {
|
|
119
|
+
const e = ai + typeof ai;
|
|
120
|
+
superSet[e] = 1;
|
|
121
|
+
}
|
|
122
|
+
for (const ai of a2) {
|
|
123
|
+
const e = ai + typeof ai;
|
|
124
|
+
if (!superSet[e]) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
superSet[e] = 2;
|
|
128
|
+
}
|
|
129
|
+
for (const e in superSet) {
|
|
130
|
+
if (superSet[e] === 1) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
exports.areArraysEqualSets = areArraysEqualSets;
|
|
138
|
+
exports.callCustomApi = callCustomApi;
|
|
139
|
+
exports.cleanseFieldIdForAggregation = cleanseFieldIdForAggregation;
|
|
140
|
+
exports.convertKeyForAggregation = convertKeyForAggregation;
|
|
141
|
+
exports.extractQuotedPhrases = extractQuotedPhrases;
|
|
142
|
+
exports.fixFreeTextForElastic = fixFreeTextForElastic;
|
|
143
|
+
exports.getItemsFromResult = getItemsFromResult;
|
|
144
|
+
exports.removeEmptyAttributes = removeEmptyAttributes;
|
|
145
|
+
exports.routeParams = routeParams;
|
|
146
|
+
exports.timedSearch = timedSearch;
|
|
147
|
+
exports.toArray = toArray;
|
|
148
|
+
//# sourceMappingURL=util-wQwG9vit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util-wQwG9vit.js","sources":["../src/search/search/performance.ts","../src/search/search/util.ts"],"sourcesContent":["export const now = () => {\n if (typeof window == 'undefined') {\n return Date.now();\n }\n return window.performance.now();\n};\n","import { parse, stringify } from 'query-string';\nimport { now } from './performance';\n\nimport { Entry } from 'contensis-delivery-api/lib/models';\nimport { PagedList, Query } from 'contensis-core-api';\nimport { CustomApi } from '../models/Search';\nimport { TimedSearchResponse } from '../models/SearchUtil';\nimport { SearchParams } from '../models/SearchActions';\nimport { CachedSearch, cachedSearch } from '~/util/ContensisDeliveryApi';\n\nexport function fixFreeTextForElastic(s: string): string {\n const illegalChars = [\n '>',\n '<',\n '=',\n '|',\n '!',\n '{',\n '}',\n '[',\n ']',\n '^',\n '~',\n '*',\n '?',\n ':',\n '\\\\',\n '/',\n ];\n\n const illegalRegEx = new RegExp(\n illegalChars.map(c => '\\\\' + c).join('|'),\n 'g'\n );\n s = s.replace(illegalRegEx, '');\n // s = s.replace(encodedRegEx, ''); // (m) => '\\\\\\\\' + m);\n\n return s;\n}\n/** `convertKeyForAggregation` and `parseKeyForAggregation` exists to prevent an\n * auto-generated aggregation using a reserved keyword because Elasticsearch has a list of\n * reserved keywords when it parses the response:\n * `'location' is one of the reserved aggregation keywords we use a heuristics based\n * response parser and using these reserved keywords could throw its heuristics off\n * course. We are working on a solution in Elasticsearch itself to make the response\n * parseable. For now these are all the reserved keywords: after_key, _as_string,\n * bg_count, bottom_right, bounds, buckets, count, doc_count, doc_count_error_upper_bound,\n * fields, from, top, type, from_as_string, hits, key, key_as_string, keys, location,\n * max_score, meta, min, min_length, score, sum_other_doc_count, to, to_as_string, top_left,\n * total, value, value_as_string, values, geometry, properties`\n */\nexport const convertKeyForAggregation = (key: string) => `sf_${key}`;\nexport const parseKeyForAggregation = (key: string) =>\n key.startsWith(`sf_`) ? key.slice(3) : key;\nexport const cleanseFieldIdForAggregation = (fieldId: string) =>\n fieldId.replaceAll('[]', '');\n\nexport const timedSearch = async (\n query: Query,\n linkDepth = 0,\n projectId?: string,\n // get api instance from SSR context that is connected to the current request in SSR,\n // fall back to the imported cachedSearch api that is not connected to the current SSR context\n ssr: { api: CachedSearch } = { api: cachedSearch }\n): Promise<null | TimedSearchResponse> => {\n if (!query) return null;\n\n let duration = 0;\n\n const start = now();\n const payload = (await ssr.api.search(\n query,\n linkDepth,\n projectId\n )) as PagedList<Entry>;\n const end = now();\n\n duration = Number((end - start).toFixed(2));\n\n return { duration, payload };\n};\n\nexport const getItemsFromResult = (result?: {\n duration: number;\n payload: PagedList<Entry> | any[];\n}): Entry[] => {\n const { payload } = result || {};\n if (payload) {\n if (Array.isArray(payload)) return payload;\n if (Array.isArray(payload.items)) return payload.items;\n return payload as any;\n }\n return [];\n};\n\nexport const extractQuotedPhrases = (searchTerm: string): string[] => {\n const pattern = new RegExp(\n /(?=[\"'])(?:\"[^\"\\\\]*(?:\\\\[\\s\\S][^\"\\\\]*)*\"|'[^'\\\\]*(?:\\\\[\\s\\S][^'\\\\]*)*')/gm\n );\n\n return (searchTerm.match(pattern) || []).map(match =>\n match.replace(/\"/g, '')\n );\n};\n\nexport const buildUrl = (route: string, params: SearchParams): string => {\n const qs = stringify(params) as string;\n const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;\n return path;\n};\n\n/**\n * Returns all params from the current route query string or static route\n * Supply static route argument if reading parameters from the route path\n * Supply location argument for the params to be read in SSR\n * @param staticRoute Matched static route from react-router 5 or 6\n * @param location location object containing at least pathname and search\n * @returns Keyed params object\n */\nexport const routeParams = (\n staticRoute?: any,\n location?: {\n [key: string]: any;\n pathname: string;\n search: string;\n hash?: string;\n }\n) => {\n // match.params is react-router-config/react-router@5 style\n // params is supplied with RouteObject in react-router@6\n const pathParams = staticRoute?.match?.params || staticRoute?.params || {};\n const queryParams = parse(\n typeof window !== 'undefined'\n ? window.location.search\n : location?.search || ''\n );\n return {\n ...pathParams,\n ...queryParams,\n };\n};\n\nexport const callCustomApi = async <T>(\n customApi: CustomApi,\n filters: SearchParams,\n // get api instance from SSR context that is connected to the current request in SSR,\n // fall back to the imported cachedSearch api that is not connected to the current SSR context\n ssr: { api: CachedSearch } = { api: cachedSearch }\n): Promise<T> => {\n const apiUri = customApi.uri || '';\n let uri = buildUrl(apiUri, filters);\n if (!uri) throw new Error('uri is required to use customApi');\n if (typeof window == 'undefined') {\n if (!uri.startsWith('http')) uri = `http://localhost:3001${uri}`;\n const response = await fetch(uri);\n return (await response.json()) as T;\n }\n const response = await ssr.api.fetch(uri);\n return (await response.clone().json()) as T;\n};\n\nexport const removeEmptyAttributes = (obj: any) => {\n Object.entries(obj).forEach(\n ([key, val]) =>\n (val && typeof val === 'object' && removeEmptyAttributes(val)) ||\n ((typeof val === 'undefined' || val === null || val === '') &&\n delete obj[key])\n );\n return obj;\n};\n\nexport const toArray = (obj: string | null, seperator = ',') =>\n typeof obj === 'undefined' || obj === null\n ? obj\n : Array.isArray(obj)\n ? (obj as string[])\n : obj.split(seperator);\n\n// assumes array elements are primitive types\nexport const areArraysEqualSets = (a1: any[], a2: any[]) => {\n const superSet = {} as { [key: string]: any };\n for (const ai of a1) {\n const e = ai + typeof ai;\n superSet[e] = 1;\n }\n\n for (const ai of a2) {\n const e = ai + typeof ai;\n if (!superSet[e]) {\n return false;\n }\n superSet[e] = 2;\n }\n\n for (const e in superSet) {\n if (superSet[e] === 1) {\n return false;\n }\n }\n\n return true;\n};\n"],"names":["now","window","Date","performance","fixFreeTextForElastic","s","illegalChars","illegalRegEx","RegExp","map","c","join","replace","convertKeyForAggregation","key","cleanseFieldIdForAggregation","fieldId","replaceAll","timedSearch","query","linkDepth","projectId","ssr","api","cachedSearch","duration","start","payload","search","end","Number","toFixed","getItemsFromResult","result","Array","isArray","items","extractQuotedPhrases","searchTerm","pattern","match","buildUrl","route","params","qs","stringify","path","includes","routeParams","staticRoute","location","_staticRoute$match","pathParams","queryParams","parse","callCustomApi","customApi","filters","apiUri","uri","Error","startsWith","response","fetch","json","clone","removeEmptyAttributes","obj","Object","entries","forEach","val","toArray","seperator","split","areArraysEqualSets","a1","a2","superSet","ai","e"],"mappings":";;;;;AAAO,MAAMA,GAAG,GAAGA,MAAM;AACvB,EAAA,IAAI,OAAOC,MAAM,IAAI,WAAW,EAAE;AAChC,IAAA,OAAOC,IAAI,CAACF,GAAG,EAAE;AACnB,EAAA;AACA,EAAA,OAAOC,MAAM,CAACE,WAAW,CAACH,GAAG,EAAE;AACjC,CAAC;;ACKM,SAASI,qBAAqBA,CAACC,CAAS,EAAU;AACvD,EAAA,MAAMC,YAAY,GAAG,CACnB,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,IAAI,EACJ,GAAG,CACJ;EAED,MAAMC,YAAY,GAAG,IAAIC,MAAM,CAC7BF,YAAY,CAACG,GAAG,CAACC,CAAC,IAAI,IAAI,GAAGA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urls = require('./urls-DVIwGZmd.js');
|
|
4
|
+
var ContensisDeliveryApi = require('./ContensisDeliveryApi-gN3_MHEl.js');
|
|
5
|
+
var SSRContext = require('./SSRContext-DotLlTQc.js');
|
|
6
|
+
var VersionInfo = require('./VersionInfo-zFPsvS8q.js');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var reactHelmetAsync = require('react-helmet-async');
|
|
5
9
|
var mapJson = require('jsonpath-mapper');
|
|
6
|
-
require('
|
|
7
|
-
require('react');
|
|
8
|
-
require('react-redux');
|
|
9
|
-
require('./selectors-wCs5fHD4.js');
|
|
10
|
-
require('immer');
|
|
11
|
-
require('query-string');
|
|
12
|
-
require('./version-CM-bJ62L.js');
|
|
13
|
-
require('styled-components');
|
|
14
|
-
require('react-cookie');
|
|
10
|
+
var reactRouterDom = require('react-router-dom');
|
|
15
11
|
require('contensis-delivery-api');
|
|
16
|
-
require('
|
|
12
|
+
require('query-string');
|
|
13
|
+
require('./selectors-BrxJ8-F8.js');
|
|
14
|
+
require('immer');
|
|
15
|
+
require('reselect');
|
|
16
|
+
require('./store-Dn7vP6G0.js');
|
|
17
17
|
require('redux');
|
|
18
18
|
require('redux-thunk');
|
|
19
19
|
require('redux-saga');
|
|
20
20
|
require('redux-injectors-19');
|
|
21
|
-
require('./
|
|
21
|
+
require('./slice-5xJMH24n.js');
|
|
22
|
+
require('@reduxjs/toolkit');
|
|
23
|
+
require('@redux-saga/core/effects');
|
|
24
|
+
require('./CookieConstants-DfPiWCRZ.js');
|
|
25
|
+
require('react-cookie');
|
|
26
|
+
require('react-redux');
|
|
27
|
+
require('./CookieHelper.class-Det3qfdU.js');
|
|
28
|
+
require('./_commonjsHelpers-BJu3ubxk.js');
|
|
29
|
+
require('./version-rFG9Y6_B.js');
|
|
30
|
+
require('styled-components');
|
|
22
31
|
|
|
23
32
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
33
|
|
|
34
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
25
35
|
var mapJson__default = /*#__PURE__*/_interopDefault(mapJson);
|
|
26
36
|
|
|
27
37
|
/**
|
|
@@ -146,18 +156,63 @@ const entryMapper = mapping => (node, state) => mapJson__default.default({
|
|
|
146
156
|
state
|
|
147
157
|
}, mapping);
|
|
148
158
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
159
|
+
// hooks/useIsClient.ts
|
|
160
|
+
/**
|
|
161
|
+
* A hook that returns true only when the component has mounted in the browser client
|
|
162
|
+
* Used to prevent SSR render and defer rendering to client-side to safely refernce
|
|
163
|
+
* browser-only apis or avoid React Hydration errors
|
|
164
|
+
*/
|
|
165
|
+
const useIsClient = () => {
|
|
166
|
+
const [isClient, setIsClient] = React.useState(false);
|
|
167
|
+
React.useEffect(() => setIsClient(true), []);
|
|
168
|
+
return isClient;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* NoSSR component to prevent children from rendering on the server.
|
|
173
|
+
* Renders children only after component has mounted in the browser.
|
|
174
|
+
*/
|
|
175
|
+
const NoSSR = ({
|
|
176
|
+
children
|
|
177
|
+
}) => {
|
|
178
|
+
const isClient = useIsClient();
|
|
179
|
+
if (!isClient) return null;
|
|
180
|
+
return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, children);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** @deprecated ponyfill for useHistory hook in react-router v5 removed in v6 */
|
|
184
|
+
const useHistory = () => {
|
|
185
|
+
const navigate = reactRouterDom.useNavigate();
|
|
186
|
+
const location = reactRouterDom.useLocation();
|
|
187
|
+
return {
|
|
188
|
+
push: navigate,
|
|
189
|
+
replace: navigate,
|
|
190
|
+
location
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
exports.setCachingHeaders = urls.setCachingHeaders;
|
|
195
|
+
exports.urls = urls.url;
|
|
196
|
+
exports.cachedSearch = ContensisDeliveryApi.cachedSearch;
|
|
197
|
+
exports.cachedSearchWithContext = ContensisDeliveryApi.cachedSearchWithContext;
|
|
198
|
+
exports.cachedSearchWithCookies = ContensisDeliveryApi.cachedSearchWithCookies;
|
|
199
|
+
exports.deliveryApi = ContensisDeliveryApi.deliveryApi;
|
|
200
|
+
exports.deliveryApiWithCookies = ContensisDeliveryApi.deliveryApiWithCookies;
|
|
201
|
+
exports.getClientConfig = ContensisDeliveryApi.getClientConfig;
|
|
153
202
|
exports.SSRContextProvider = SSRContext.SSRContextProvider;
|
|
154
|
-
exports.
|
|
155
|
-
exports.cachedSearchWithCookies = SSRContext.cachedSearchWithCookies;
|
|
156
|
-
exports.deliveryApi = SSRContext.deliveryApi;
|
|
157
|
-
exports.deliveryApiWithCookies = SSRContext.deliveryApiWithCookies;
|
|
158
|
-
exports.getClientConfig = SSRContext.getClientConfig;
|
|
203
|
+
exports.getSubsitePath = SSRContext.getSubsitePath;
|
|
159
204
|
exports.useDeliveryApi = SSRContext.useDeliveryApi;
|
|
160
205
|
exports.useSSRContext = SSRContext.useSSRContext;
|
|
206
|
+
exports.VersionInfo = VersionInfo.VersionInfo;
|
|
207
|
+
exports.stringifyStrings = VersionInfo.stringifyStrings;
|
|
208
|
+
Object.defineProperty(exports, "Helmet", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function () { return reactHelmetAsync.Helmet; }
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(exports, "HelmetProvider", {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function () { return reactHelmetAsync.HelmetProvider; }
|
|
215
|
+
});
|
|
161
216
|
Object.defineProperty(exports, "jpath", {
|
|
162
217
|
enumerable: true,
|
|
163
218
|
get: function () { return mapJson.jpath; }
|
|
@@ -166,11 +221,14 @@ Object.defineProperty(exports, "mapJson", {
|
|
|
166
221
|
enumerable: true,
|
|
167
222
|
get: function () { return mapJson__default.default; }
|
|
168
223
|
});
|
|
224
|
+
exports.NoSSR = NoSSR;
|
|
169
225
|
exports.entryMapper = entryMapper;
|
|
170
226
|
exports.mapComposer = mapComposer;
|
|
171
227
|
exports.mapEntries = mapEntries;
|
|
172
228
|
exports.useComposerMapper = useComposerMapper;
|
|
173
229
|
exports.useEntriesMapper = useEntriesMapper;
|
|
174
230
|
exports.useEntryMapper = useEntryMapper;
|
|
231
|
+
exports.useHistory = useHistory;
|
|
232
|
+
exports.useIsClient = useIsClient;
|
|
175
233
|
exports.useMapper = useMapper;
|
|
176
234
|
//# sourceMappingURL=util.js.map
|
package/cjs/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../src/util/json-mapper.ts"],"sourcesContent":["import { Entry } from 'contensis-delivery-api/lib/models';\nimport mapJson, { jpath } from 'jsonpath-mapper';\nimport {\n MappingTemplate,\n PureJsFunction,\n} from 'jsonpath-mapper';\nimport { AppState, EntryMapper, RouteNode } from '~/models';\n\nexport { default as mapJson, jpath } from 'jsonpath-mapper';\n\ntype Mappers<S> = { [contentTypeId: string]: MappingTemplate<S> };\n\n/**\n *\n * @param {object} json The source object we wish to transform\n * @param {object} template The mapping template we wish to apply to the source\n * object to generate the intended target object\n */\nexport const useMapper = <T, S>(json: S, template: MappingTemplate<S>) => {\n return template ? (mapJson((json || {}) as S, template) as T) : json;\n};\n\nconst chooseMapperByFieldValue = <S, T extends Mappers<S>>(\n entry: S,\n mappers: T,\n field = 'sys.contentTypeId'\n) => {\n const fieldValue = jpath(field, entry || {}) as string;\n return (mappers[fieldValue] || mappers.default || {}) as T[keyof T];\n};\n\n/**\n * useEntriesMapper hook to take a list of entries from Delivery API along\n * with mappers for each contentTypeId and return an array of mapped objects\n * @param {any} entry The source entry we wish to transform\n * @param {object} mappers Object with keys containing mapper templates,\n * the key name matching sys.contentTypeId\n * @param {string} field Only include if we need to match content based on\n * a field other than sys.contentTypeId in the source data\n * @returns {object} Object transformed using a matched content type or\n * a default mapper template, returns an empty object if no mapper template\n * couild be applied.\n */\nexport const useEntriesMapper = <S, T extends Mappers<S>>(\n entry: S,\n mappers: T,\n field = 'sys.contentTypeId'\n) => {\n const mapper = chooseMapperByFieldValue(entry, mappers, field);\n return useMapper(entry, mapper);\n};\n\n/**\n * Deprecated: due to misleading name, use the hook useEntriesMapper instead\n */\nexport const useEntryMapper = useEntriesMapper;\n\n/**\n * mapEntries mapping function to take a list of entries from Delivery API along\n * with mappers for each contentTypeId and return an array of mapped objects\n * @param {any} entry The source entry we wish to transform\n * @param {object} mappers Object with keys containing mapper templates,\n * the key name matching sys.contentTypeId\n * @param {string} field Only include if we need to match content based on\n * a field other than sys.contentTypeId in the source data\n * @returns {object} Object transformed using a matched content type or\n * a default mapper template, returns an empty object if no mapper template\n * couild be applied.\n */\nexport const mapEntries = <\n S,\n Mappers extends { [contentTypeId: string]: MappingTemplate<S> }\n>(\n entries: S[],\n mappers: Mappers,\n field = 'sys.contentTypeId'\n) =>\n entries.map(entry => {\n const mapper = chooseMapperByFieldValue(entry, mappers, field);\n return mapper ? mapJson((entry || {}) as S, mapper) : entry;\n });\n\n/**\n * mapComposer mapping function to take a composer field from Delivery API along\n * with mappers for each Composer Item \"type\" and return an array of mapped components\n * @param {array} composer Composer field array of Composer Items\n * @param {object} mappers A keyed object with each key matching the Composer Item \"type\"\n * @returns {array} Array of mapped objects transformed using a matched Composer Item \"type\" mapping\n * or null. Injects a \"_type\" property into each transformed object in the array to indicate\n * where the mapping originated and for what component the mapped object is representing\n */\nexport const mapComposer = <\n S extends { type: string; value: any },\n T extends Mappers<S>\n>(\n composer: S[],\n mappers: T\n) =>\n Array.isArray(composer)\n ? composer.map((composerItem, index) => {\n const itemValue = composerItem.value;\n const mapper = mappers[composerItem.type] || mappers.default;\n if (mapper) {\n // Add some fields into the composer item mapper and return object\n const addedFields = {\n _type: composerItem.type,\n _index: index,\n };\n\n // Add fields and $root item into the composer item source object\n // for use inside each item mapping, for arrays we inject the added fields\n // into the first array item. This is useful if we require any of\n // composerItem.type, composerItem index/position and composer $root\n // in scope to influence any composer item's mapping logic\n const sourceObject =\n itemValue && Array.isArray(itemValue)\n ? itemValue.map((iv, idx) =>\n idx !== 0\n ? iv\n : typeof iv === 'object'\n ? { ...addedFields, ...iv, $root: composer }\n : iv\n )\n : typeof itemValue === 'object'\n ? { ...addedFields, ...itemValue, $root: composer }\n : itemValue || {};\n\n // Apply the composer item mapping\n const mappedFields = mapJson(sourceObject, mapper) as any;\n\n // Add the extra fields in with the return object\n return mappedFields && typeof mappedFields === 'object'\n ? { ...mappedFields, ...addedFields }\n : mappedFields;\n } else return {};\n })\n : composer || [];\n\n/**\n * useComposerMapper hook to take a composer field from Delivery API along\n * with mappers for each Composer Item \"type\" and return an array of mapped components\n * @param {array} composer Composer field array of Composer Items\n * @param {object} mappers A keyed object with each key matching the Composer Item \"type\"\n * @returns {array} Array of mapped objects transformed using a matched Composer Item \"type\" mapping\n * or null. Injects a \"_type\" property into each transformed object in the array to indicate\n * where the mapping originated and for what component the mapped object is representing\n */\nexport const useComposerMapper = <\n S extends { type: string; value: any },\n T extends Mappers<S>\n>(\n composer: S[] = [],\n mappers: T\n) => mapComposer(composer, mappers);\n\n/**\n * entryMapper will return a function to satisfy an entryMapper when defining app route\n * this is essentially a shorthand function to prevent boilerplate repetition inside your routes file\n * you do not need to use this function should you wish to map your entry via raw JS functions\n * @param mapping the jsonpath-mapper mapping template to apply when the route is resolved\n * @returns {mappedEntry}\n */\nexport const entryMapper =\n (\n mapping:\n | MappingTemplate<RouteNode & Entry & { state?: AppState }>\n | PureJsFunction<RouteNode & Entry & { state?: AppState }>\n ): EntryMapper =>\n (node, state) =>\n mapJson({ ...node, ...(node.entry || ({} as Entry)), state }, mapping);\n\nexport default mapJson;\n"],"names":["useMapper","json","template","mapJson","chooseMapperByFieldValue","entry","mappers","field","fieldValue","jpath","default","useEntriesMapper","mapper","useEntryMapper","mapEntries","entries","map","mapComposer","composer","Array","isArray","composerItem","index","itemValue","value","type","addedFields","_type","_index","sourceObject","iv","idx","$root","mappedFields","useComposerMapper","entryMapper","mapping","node","state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A;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMgB,iBAAiB,GAAGA,CAI/BhB,QAAa,GAAG,EAAE,EAClBZ,OAAU,KACPW,WAAW,CAACC,QAAQ,EAAEZ,OAAO;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM6B,WAAW,GAEpBC,OAE4D,IAE5D,CAACC,IAAI,EAAEC,KAAK,KACVnC,wBAAO,CAAC;AAAE,EAAA,GAAGkC,IAAI;AAAE,EAAA,IAAIA,IAAI,CAAChC,KAAK,IAAK,EAAY,CAAC;AAAEiC,EAAAA;AAAM,CAAC,EAAEF,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../src/util/json-mapper.ts","../src/util/useIsClient.ts","../src/util/NoSSR.tsx","../src/util/donotuse_useHistory.ts"],"sourcesContent":["import { Entry } from 'contensis-delivery-api/lib/models';\nimport mapJson, { jpath } from 'jsonpath-mapper';\nimport {\n MappingTemplate,\n PureJsFunction,\n} from 'jsonpath-mapper';\nimport { AppState, EntryMapper, RouteNode } from '~/models';\n\nexport { default as mapJson, jpath } from 'jsonpath-mapper';\n\ntype Mappers<S> = { [contentTypeId: string]: MappingTemplate<S> };\n\n/**\n *\n * @param {object} json The source object we wish to transform\n * @param {object} template The mapping template we wish to apply to the source\n * object to generate the intended target object\n */\nexport const useMapper = <T, S>(json: S, template: MappingTemplate<S>) => {\n return template ? (mapJson((json || {}) as S, template) as T) : json;\n};\n\nconst chooseMapperByFieldValue = <S, T extends Mappers<S>>(\n entry: S,\n mappers: T,\n field = 'sys.contentTypeId'\n) => {\n const fieldValue = jpath(field, entry || {}) as string;\n return (mappers[fieldValue] || mappers.default || {}) as T[keyof T];\n};\n\n/**\n * useEntriesMapper hook to take a list of entries from Delivery API along\n * with mappers for each contentTypeId and return an array of mapped objects\n * @param {any} entry The source entry we wish to transform\n * @param {object} mappers Object with keys containing mapper templates,\n * the key name matching sys.contentTypeId\n * @param {string} field Only include if we need to match content based on\n * a field other than sys.contentTypeId in the source data\n * @returns {object} Object transformed using a matched content type or\n * a default mapper template, returns an empty object if no mapper template\n * couild be applied.\n */\nexport const useEntriesMapper = <S, T extends Mappers<S>>(\n entry: S,\n mappers: T,\n field = 'sys.contentTypeId'\n) => {\n const mapper = chooseMapperByFieldValue(entry, mappers, field);\n return useMapper(entry, mapper);\n};\n\n/**\n * Deprecated: due to misleading name, use the hook useEntriesMapper instead\n */\nexport const useEntryMapper = useEntriesMapper;\n\n/**\n * mapEntries mapping function to take a list of entries from Delivery API along\n * with mappers for each contentTypeId and return an array of mapped objects\n * @param {any} entry The source entry we wish to transform\n * @param {object} mappers Object with keys containing mapper templates,\n * the key name matching sys.contentTypeId\n * @param {string} field Only include if we need to match content based on\n * a field other than sys.contentTypeId in the source data\n * @returns {object} Object transformed using a matched content type or\n * a default mapper template, returns an empty object if no mapper template\n * couild be applied.\n */\nexport const mapEntries = <\n S,\n Mappers extends { [contentTypeId: string]: MappingTemplate<S> }\n>(\n entries: S[],\n mappers: Mappers,\n field = 'sys.contentTypeId'\n) =>\n entries.map(entry => {\n const mapper = chooseMapperByFieldValue(entry, mappers, field);\n return mapper ? mapJson((entry || {}) as S, mapper) : entry;\n });\n\n/**\n * mapComposer mapping function to take a composer field from Delivery API along\n * with mappers for each Composer Item \"type\" and return an array of mapped components\n * @param {array} composer Composer field array of Composer Items\n * @param {object} mappers A keyed object with each key matching the Composer Item \"type\"\n * @returns {array} Array of mapped objects transformed using a matched Composer Item \"type\" mapping\n * or null. Injects a \"_type\" property into each transformed object in the array to indicate\n * where the mapping originated and for what component the mapped object is representing\n */\nexport const mapComposer = <\n S extends { type: string; value: any },\n T extends Mappers<S>\n>(\n composer: S[],\n mappers: T\n) =>\n Array.isArray(composer)\n ? composer.map((composerItem, index) => {\n const itemValue = composerItem.value;\n const mapper = mappers[composerItem.type] || mappers.default;\n if (mapper) {\n // Add some fields into the composer item mapper and return object\n const addedFields = {\n _type: composerItem.type,\n _index: index,\n };\n\n // Add fields and $root item into the composer item source object\n // for use inside each item mapping, for arrays we inject the added fields\n // into the first array item. This is useful if we require any of\n // composerItem.type, composerItem index/position and composer $root\n // in scope to influence any composer item's mapping logic\n const sourceObject =\n itemValue && Array.isArray(itemValue)\n ? itemValue.map((iv, idx) =>\n idx !== 0\n ? iv\n : typeof iv === 'object'\n ? { ...addedFields, ...iv, $root: composer }\n : iv\n )\n : typeof itemValue === 'object'\n ? { ...addedFields, ...itemValue, $root: composer }\n : itemValue || {};\n\n // Apply the composer item mapping\n const mappedFields = mapJson(sourceObject, mapper) as any;\n\n // Add the extra fields in with the return object\n return mappedFields && typeof mappedFields === 'object'\n ? { ...mappedFields, ...addedFields }\n : mappedFields;\n } else return {};\n })\n : composer || [];\n\n/**\n * useComposerMapper hook to take a composer field from Delivery API along\n * with mappers for each Composer Item \"type\" and return an array of mapped components\n * @param {array} composer Composer field array of Composer Items\n * @param {object} mappers A keyed object with each key matching the Composer Item \"type\"\n * @returns {array} Array of mapped objects transformed using a matched Composer Item \"type\" mapping\n * or null. Injects a \"_type\" property into each transformed object in the array to indicate\n * where the mapping originated and for what component the mapped object is representing\n */\nexport const useComposerMapper = <\n S extends { type: string; value: any },\n T extends Mappers<S>\n>(\n composer: S[] = [],\n mappers: T\n) => mapComposer(composer, mappers);\n\n/**\n * entryMapper will return a function to satisfy an entryMapper when defining app route\n * this is essentially a shorthand function to prevent boilerplate repetition inside your routes file\n * you do not need to use this function should you wish to map your entry via raw JS functions\n * @param mapping the jsonpath-mapper mapping template to apply when the route is resolved\n * @returns {mappedEntry}\n */\nexport const entryMapper =\n (\n mapping:\n | MappingTemplate<RouteNode & Entry & { state?: AppState }>\n | PureJsFunction<RouteNode & Entry & { state?: AppState }>\n ): EntryMapper =>\n (node, state) =>\n mapJson({ ...node, ...(node.entry || ({} as Entry)), state }, mapping);\n\nexport default mapJson;\n","// hooks/useIsClient.ts\nimport { useEffect, useState } from 'react';\n/**\n * A hook that returns true only when the component has mounted in the browser client\n * Used to prevent SSR render and defer rendering to client-side to safely refernce\n * browser-only apis or avoid React Hydration errors\n */\nexport const useIsClient = () => {\n const [isClient, setIsClient] = useState(false);\n useEffect(() => setIsClient(true), []);\n return isClient;\n};\n","import React from 'react';\nimport { useIsClient } from './useIsClient';\n\n/**\n * NoSSR component to prevent children from rendering on the server.\n * Renders children only after component has mounted in the browser.\n */\nexport const NoSSR: React.FC<React.PropsWithChildren> = ({ children }) => {\n const isClient = useIsClient();\n\n if (!isClient) return null;\n\n return <>{children}</>;\n};\n","import { useNavigate } from 'react-router-dom';\nimport { useLocation } from 'react-router-dom';\n\n/** @deprecated ponyfill for useHistory hook in react-router v5 removed in v6 */\nexport const useHistory = () => {\n const navigate = useNavigate();\n const location = useLocation();\n\n return {\n push: navigate,\n replace: navigate,\n location,\n };\n};\n"],"names":["useMapper","json","template","mapJson","chooseMapperByFieldValue","entry","mappers","field","fieldValue","jpath","default","useEntriesMapper","mapper","useEntryMapper","mapEntries","entries","map","mapComposer","composer","Array","isArray","composerItem","index","itemValue","value","type","addedFields","_type","_index","sourceObject","iv","idx","$root","mappedFields","useComposerMapper","entryMapper","mapping","node","state","useIsClient","isClient","setIsClient","useState","useEffect","NoSSR","children","React","createElement","Fragment","useHistory","navigate","useNavigate","location","useLocation","push","replace"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA;AACA;AACA;AACA;AACA;AACA;MACaA,SAAS,GAAGA,CAAOC,IAAO,EAAEC,QAA4B,KAAK;AACxE,EAAA,OAAOA,QAAQ,GAAIC,wBAAO,CAAEF,IAAI,IAAI,EAAE,EAAQC,QAAQ,CAAC,GAASD,IAAI;AACtE;AAEA,MAAMG,wBAAwB,GAAGA,CAC/BC,KAAQ,EACRC,OAAU,EACVC,KAAK,GAAG,mBAAmB,KACxB;EACH,MAAMC,UAAU,GAAGC,aAAK,CAACF,KAAK,EAAEF,KAAK,IAAI,EAAE,CAAW;EACtD,OAAQC,OAAO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;AACA;AACA;AACA;AACO,MAAMG,WAAW,GAAGA,MAAM;EAC/B,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;EAC/CC,eAAS,CAAC,MAAMF,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;AACtC,EAAA,OAAOD,QAAQ;AACjB;;ACRA;AACA;AACA;AACA;AACO,MAAMI,KAAwC,GAAGA,CAAC;AAAEC,EAAAA;AAAS,CAAC,KAAK;AACxE,EAAA,MAAML,QAAQ,GAAGD,WAAW,EAAE;AAE9B,EAAA,IAAI,CAACC,QAAQ,EAAE,OAAO,IAAI;EAE1B,oBAAOM,sBAAA,CAAAC,aAAA,CAAAD,sBAAA,CAAAE,QAAA,EAAA,IAAA,EAAGH,QAAW,CAAC;AACxB;;ACVA;AACO,MAAMI,UAAU,GAAGA,MAAM;AAC9B,EAAA,MAAMC,QAAQ,GAAGC,0BAAW,EAAE;AAC9B,EAAA,MAAMC,QAAQ,GAAGC,0BAAW,EAAE;EAE9B,OAAO;AACLC,IAAAA,IAAI,EAAEJ,QAAQ;AACdK,IAAAA,OAAO,EAAEL,QAAQ;AACjBE,IAAAA;GACD;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var selectors = require('./selectors-
|
|
4
|
-
var
|
|
5
|
-
var store = require('./store-D07FOXvM.js');
|
|
3
|
+
var selectors = require('./selectors-BrxJ8-F8.js');
|
|
4
|
+
var store = require('./store-Dn7vP6G0.js');
|
|
6
5
|
|
|
7
6
|
const hasNavigationTree = state => selectors.getImmutableOrJS(state, ['navigation', 'isReady']);
|
|
8
7
|
const selectNavigationRoot = state => selectors.getImmutableOrJS(state, ['navigation', 'root']);
|
|
@@ -17,12 +16,6 @@ var navigation = /*#__PURE__*/Object.freeze({
|
|
|
17
16
|
selectNavigationRoot: selectNavigationRoot
|
|
18
17
|
});
|
|
19
18
|
|
|
20
|
-
const convertSagaArray = sagas => {
|
|
21
|
-
if (Array.isArray(sagas)) return function* rootSaga() {
|
|
22
|
-
yield effects.all(sagas);
|
|
23
|
-
};
|
|
24
|
-
return sagas;
|
|
25
|
-
};
|
|
26
19
|
const injectReducer = ({
|
|
27
20
|
key,
|
|
28
21
|
reducer
|
|
@@ -35,31 +28,38 @@ const injectSaga = ({
|
|
|
35
28
|
key,
|
|
36
29
|
saga
|
|
37
30
|
}, store$1 = store.reduxStore) => {
|
|
38
|
-
|
|
31
|
+
// Proceed with the injection as usual if it's not a duplicate
|
|
39
32
|
let hasSaga = Reflect.has(store$1.injectedSagas, key);
|
|
40
33
|
if (process.env.NODE_ENV !== 'production') {
|
|
41
34
|
const oldDescriptor = store$1.injectedSagas[key]; // enable hot reloading of daemon and once-till-unmount sagas
|
|
42
35
|
|
|
43
|
-
if (hasSaga && oldDescriptor.saga !==
|
|
36
|
+
if (hasSaga && oldDescriptor.saga !== saga) {
|
|
44
37
|
oldDescriptor.task.cancel();
|
|
45
38
|
hasSaga = false;
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
|
-
console.info('injectSaga, key: ', key, 'hasSaga: ', hasSaga);
|
|
49
41
|
if (!hasSaga) {
|
|
42
|
+
// Check if the saga has already been added in the initial sagas
|
|
43
|
+
const injectEffects = [];
|
|
44
|
+
for (const effect of saga) {
|
|
45
|
+
// Inject this saga effect if it's not already present
|
|
46
|
+
if (!store$1.initialSagas.has(effect)) injectEffects.push(effect);
|
|
47
|
+
}
|
|
48
|
+
const rootSaga = store.wrapSagasInGenerator(injectEffects);
|
|
50
49
|
store$1.injectedSagas[key] = {
|
|
51
50
|
key,
|
|
52
|
-
saga:
|
|
51
|
+
saga: saga,
|
|
53
52
|
task: store$1.runSaga(rootSaga)
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
55
|
};
|
|
56
|
+
|
|
57
57
|
const injectRedux = ({
|
|
58
58
|
key,
|
|
59
59
|
reducer,
|
|
60
60
|
saga
|
|
61
61
|
}, store$1 = store.reduxStore) => {
|
|
62
|
-
console.info('injectRedux, key: ', key);
|
|
62
|
+
// console.info('injectRedux, key: ', key);
|
|
63
63
|
if (reducer) injectReducer({
|
|
64
64
|
key,
|
|
65
65
|
reducer
|
|
@@ -85,7 +85,6 @@ var version = /*#__PURE__*/Object.freeze({
|
|
|
85
85
|
setVersionStatus: setVersionStatus
|
|
86
86
|
});
|
|
87
87
|
|
|
88
|
-
exports.convertSagaArray = convertSagaArray;
|
|
89
88
|
exports.hasNavigationTree = hasNavigationTree;
|
|
90
89
|
exports.injectReducer = injectReducer;
|
|
91
90
|
exports.injectRedux = injectRedux;
|
|
@@ -95,4 +94,4 @@ exports.setVersion = setVersion;
|
|
|
95
94
|
exports.setVersionStatus = setVersionStatus;
|
|
96
95
|
exports.useInjectRedux = useInjectRedux;
|
|
97
96
|
exports.version = version;
|
|
98
|
-
//# sourceMappingURL=version-
|
|
97
|
+
//# sourceMappingURL=version-2FamXHhj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-2FamXHhj.js","sources":["../src/redux/selectors/navigation.js","../src/redux/store/injectors/inject.ts","../src/redux/store/injectors/index.ts","../src/redux/actions/version.js"],"sourcesContent":["import { getImmutableOrJS as getIn } from '~/redux/util';\n\nexport const hasNavigationTree = state =>\n getIn(state, ['navigation', 'isReady']);\n\nexport const selectNavigationRoot = state =>\n getIn(state, ['navigation', 'root']);\n\nexport const selectNavigationChildren = state =>\n getIn(state, ['navigation', 'root', 'children']);\n\nexport const selectNavigationDepends = () => [];\n","import { Reducer } from 'redux';\nimport { Effect } from 'redux-saga/effects';\nimport { reduxStore as DefaultStore } from '../store';\nimport { wrapSagasInGenerator } from './util';\n\nexport const injectReducer = (\n { key, reducer }: { key: string; reducer: Reducer },\n store = DefaultStore\n) => {\n if (\n Reflect.has(store.injectedReducers, key) &&\n store.injectedReducers[key] === reducer\n )\n return;\n store.injectedReducers[key] = reducer;\n\n store.replaceReducer(store.createReducer(store.injectedReducers));\n};\n\nexport const injectSaga = (\n { key, saga }: { key: string; saga: Effect[] },\n store = DefaultStore\n) => {\n // Proceed with the injection as usual if it's not a duplicate\n let hasSaga = Reflect.has(store.injectedSagas, key);\n\n if (process.env.NODE_ENV !== 'production') {\n const oldDescriptor = store.injectedSagas[key]; // enable hot reloading of daemon and once-till-unmount sagas\n\n if (hasSaga && oldDescriptor.saga !== saga) {\n oldDescriptor.task.cancel();\n hasSaga = false;\n }\n }\n\n if (!hasSaga) {\n // Check if the saga has already been added in the initial sagas\n const injectEffects: Effect[] = [];\n for (const effect of saga) {\n // Inject this saga effect if it's not already present\n if (!store.initialSagas.has(effect)) injectEffects.push(effect);\n }\n const rootSaga = wrapSagasInGenerator(injectEffects);\n store.injectedSagas[key] = {\n key,\n saga: saga,\n task: store.runSaga(rootSaga),\n };\n }\n};\n","import { Reducer } from 'redux';\nimport { Effect } from 'redux-saga/effects';\nimport { reduxStore as DefaultStore } from '../store';\nimport { injectReducer, injectSaga } from './inject';\n\nexport const injectRedux = (\n { key, reducer, saga }: { key: string; reducer?: Reducer; saga?: Effect[] },\n store = DefaultStore\n) => {\n // console.info('injectRedux, key: ', key);\n if (reducer) injectReducer({ key, reducer }, store);\n if (saga) injectSaga({ key, saga }, store);\n};\n\nexport const useInjectRedux = injectRedux;\n","import { action } from '../util';\nimport { SET_VERSION, SET_VERSION_STATUS } from '../types/version';\n\nexport const setVersion = (commitRef, buildNo) =>\n action(SET_VERSION, { commitRef, buildNo });\n\nexport const setVersionStatus = status =>\n action(SET_VERSION_STATUS, { status });\n"],"names":["hasNavigationTree","state","getIn","selectNavigationRoot","selectNavigationChildren","selectNavigationDepends","injectReducer","key","reducer","store","DefaultStore","Reflect","has","injectedReducers","replaceReducer","createReducer","injectSaga","saga","hasSaga","injectedSagas","process","env","NODE_ENV","oldDescriptor","task","cancel","injectEffects","effect","initialSagas","push","rootSaga","wrapSagasInGenerator","runSaga","injectRedux","useInjectRedux","setVersion","commitRef","buildNo","action","SET_VERSION","setVersionStatus","status","SET_VERSION_STATUS"],"mappings":";;;;;AAEO,MAAMA,iBAAiB,GAAGC,KAAK,IACpCC,0BAAK,CAACD,KAAK,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;AAEjC,MAAME,oBAAoB,GAAGF,KAAK,IACvCC,0BAAK,CAACD,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAE/B,MAAMG,wBAAwB,GAAGH,KAAK,IAC3CC,0BAAK,CAACD,KAAK,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;AAE3C,MAAMI,uBAAuB,GAAGA,MAAM,EAAE;;;;;;;;;;ACNxC,MAAMC,aAAa,GAAGA,CAC3B;EAAEC,GAAG;AAAEC,EAAAA;AAA2C,CAAC,EACnDC,OAAK,GAAGC,gBAAY,KACjB;AACH,EAAA,IACEC,OAAO,CAACC,GAAG,CAACH,OAAK,CAACI,gBAAgB,EAAEN,GAAG,CAAC,IACxCE,OAAK,CAACI,gBAAgB,CAACN,GAAG,CAAC,KAAKC,OAAO,EAEvC;AACFC,EAAAA,OAAK,CAACI,gBAAgB,CAACN,GAAG,CAAC,GAAGC,OAAO;EAErCC,OAAK,CAACK,cAAc,CAACL,OAAK,CAACM,aAAa,CAACN,OAAK,CAACI,gBAAgB,CAAC,CAAC;AACnE;AAEO,MAAMG,UAAU,GAAGA,CACxB;EAAET,GAAG;AAAEU,EAAAA;AAAsC,CAAC,EAC9CR,OAAK,GAAGC,gBAAY,KACjB;AACH;EACA,IAAIQ,OAAO,GAAGP,OAAO,CAACC,GAAG,CAACH,OAAK,CAACU,aAAa,EAAEZ,GAAG,CAAC;AAEnD,EAAA,IAAIa,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;IACzC,MAAMC,aAAa,GAAGd,OAAK,CAACU,aAAa,CAACZ,GAAG,CAAC,CAAC;;AAE/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,CAAC;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var selectors = require('./selectors-
|
|
3
|
+
var selectors = require('./selectors-BrxJ8-F8.js');
|
|
4
4
|
|
|
5
5
|
const selectCommitRef = state => selectors.getImmutableOrJS(state, ['version', 'commitRef']);
|
|
6
6
|
const selectBuildNumber = state => selectors.getImmutableOrJS(state, ['version', 'buildNo']);
|
|
@@ -17,4 +17,4 @@ exports.selectBuildNumber = selectBuildNumber;
|
|
|
17
17
|
exports.selectCommitRef = selectCommitRef;
|
|
18
18
|
exports.selectVersionStatus = selectVersionStatus;
|
|
19
19
|
exports.version = version;
|
|
20
|
-
//# sourceMappingURL=version-
|
|
20
|
+
//# sourceMappingURL=version-rFG9Y6_B.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-
|
|
1
|
+
{"version":3,"file":"version-rFG9Y6_B.js","sources":["../src/redux/selectors/version.js"],"sourcesContent":["import { getImmutableOrJS as getIn } from '~/redux/util';\n\nexport const selectCommitRef = state => getIn(state, ['version', 'commitRef']);\n\nexport const selectBuildNumber = state => getIn(state, ['version', 'buildNo']);\n\nexport const selectVersionStatus = state =>\n getIn(state, ['version', 'contensisVersionStatus']);\n"],"names":["selectCommitRef","state","getIn","selectBuildNumber","selectVersionStatus"],"mappings":";;;;AAEO,MAAMA,eAAe,GAAGC,KAAK,IAAIC,0BAAK,CAACD,KAAK,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC;AAEtE,MAAME,iBAAiB,GAAGF,KAAK,IAAIC,0BAAK,CAACD,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC;AAEtE,MAAMG,mBAAmB,GAAGH,KAAK,IACtCC,0BAAK,CAACD,KAAK,EAAE,CAAC,SAAS,EAAE,wBAAwB,CAAC;;;;;;;;;;;;;;"}
|