@zengenti/contensis-react-base 3.0.0-beta.72 → 3.0.0-beta.73

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.
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var contensisCoreApi = require('contensis-core-api');
6
6
  var React = require('react');
7
7
  var reactRedux = require('react-redux');
8
- var sagas = require('./sagas-24f5607f.js');
8
+ var sagas = require('./sagas-594b5ecd.js');
9
9
  var mapJson = require('jsonpath-mapper');
10
10
  require('reselect');
11
11
  require('deepmerge');
@@ -128,9 +128,10 @@ const navigate = (path, state) => {
128
128
  state
129
129
  };
130
130
  };
131
- const clearFilters$1 = () => {
131
+ const clearFilters$1 = filterKey => {
132
132
  return {
133
- type: CLEAR_FILTERS
133
+ type: CLEAR_FILTERS,
134
+ filterKey
134
135
  };
135
136
  };
136
137
  const updatePageIndex$1 = (pageIndex, scrollYPos) => {
@@ -476,6 +477,14 @@ var selectors = /*#__PURE__*/Object.freeze({
476
477
  selectVersionStatus: selectVersionStatus
477
478
  });
478
479
 
480
+ const now = () => {
481
+ if (typeof window == 'undefined') {
482
+ return Date.now();
483
+ }
484
+
485
+ return window.performance.now();
486
+ };
487
+
479
488
  const getClientConfig = (project, env) => {
480
489
  let config = DELIVERY_API_CONFIG;
481
490
  /* global DELIVERY_API_CONFIG */
@@ -640,14 +649,6 @@ class CachedSearch {
640
649
 
641
650
  const cachedSearch = new CachedSearch();
642
651
 
643
- const now = () => {
644
- if (typeof window == 'undefined') {
645
- return Date.now();
646
- }
647
-
648
- return window.performance.now();
649
- };
650
-
651
652
  // eslint-disable-next-line import/default
652
653
  function fixFreeTextForElastic(s) {
653
654
  const illegalChars = ['>', '<', '=', '|', '!', '{', '}', '[', ']', '^', '~', '*', '?', ':', '\\', '/'];
@@ -690,6 +691,26 @@ const buildUrl = (route, params) => {
690
691
  const path = qs ? `${route}${route.includes('?') ? '&' : '?'}${qs}` : route;
691
692
  return path;
692
693
  };
694
+ /**
695
+ * Returns all params from the current route query string or static route
696
+ * Supply static route argument if reading parameters from the route path
697
+ * Supply location argument for the params to be read in SSR
698
+ * @param staticRoute Matched static route from react-router 5 or 6
699
+ * @param location location object containing at least pathname and search
700
+ * @returns Keyed params object
701
+ */
702
+
703
+ const routeParams = (staticRoute, location) => {
704
+ var _staticRoute$match;
705
+
706
+ // match.params is react-router-config/react-router@5 style
707
+ // params is supplied with RouteObject in react-router@6
708
+ const pathParams = (staticRoute === null || staticRoute === void 0 ? 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) || {};
709
+ const queryParams = queryString.parse(typeof window !== 'undefined' ? window.location.search : (location === null || location === void 0 ? void 0 : location.search) || '');
710
+ return { ...pathParams,
711
+ ...queryParams
712
+ };
713
+ };
693
714
  const callCustomApi = async (customApi, filters) => {
694
715
  const apiUri = customApi.uri || '';
695
716
  let uri = buildUrl(apiUri, filters);
@@ -731,6 +752,43 @@ const areArraysEqualSets = (a1, a2) => {
731
752
  return true;
732
753
  };
733
754
 
755
+ const searchUriTemplate = {
756
+ path: ({
757
+ state,
758
+ facet,
759
+ pageIndex
760
+ }) => {
761
+ const currentFacet = getSearchContext(state) !== exports.Context.listings && (facet || getCurrentFacet(state));
762
+ const currentPath = selectCurrentPath(state) || '/search';
763
+ const newPath = currentFacet ? `${currentPath}/${currentFacet}` : currentPath;
764
+ if (pageIndex) return `${newPath}/${pageIndex + 1}`;
765
+ return newPath;
766
+ },
767
+ search: ({
768
+ state,
769
+ facet,
770
+ orderBy,
771
+ term
772
+ }) => {
773
+ const searchContext = getSearchContext(state); // Lose stateFilters and currentSearch if a new
774
+ // term is passed via an argument
775
+
776
+ const stateFilters = term ? {} : Object.fromEntries(Object.entries(getSelectedFilters(state, facet, searchContext, 'js')).map(([key, f]) => [key, f === null || f === void 0 ? void 0 : f.join(',')]));
777
+ const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
778
+ const currentQs = removeEmptyAttributes(queryString.parse(currentSearch));
779
+ if (orderBy) currentQs.orderBy = orderBy;
780
+ const searchTerm = getSearchTerm(state); // Merge the stateFilters with any current qs to build the new qs
781
+
782
+ const mergedSearch = removeEmptyAttributes({ ...merge__default["default"](currentQs, stateFilters),
783
+ term: searchTerm
784
+ });
785
+ return queryString.stringify(mergedSearch);
786
+ },
787
+ hash: state => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
788
+ };
789
+
790
+ const mapStateToSearchUri = params => mapJson__default["default"](params, searchUriTemplate);
791
+
734
792
  const DataFormats = {
735
793
  asset: 'asset',
736
794
  entry: 'entry',
@@ -1144,43 +1202,6 @@ var queries = /*#__PURE__*/Object.freeze({
1144
1202
  searchQuery: searchQuery
1145
1203
  });
1146
1204
 
1147
- const searchUriTemplate = {
1148
- path: ({
1149
- state,
1150
- facet,
1151
- pageIndex
1152
- }) => {
1153
- const currentFacet = getSearchContext(state) !== exports.Context.listings && (facet || getCurrentFacet(state));
1154
- const currentPath = selectCurrentPath(state) || '/search';
1155
- const newPath = currentFacet ? `${currentPath}/${currentFacet}` : currentPath;
1156
- if (pageIndex) return `${newPath}/${pageIndex + 1}`;
1157
- return newPath;
1158
- },
1159
- search: ({
1160
- state,
1161
- facet,
1162
- orderBy,
1163
- term
1164
- }) => {
1165
- const searchContext = getSearchContext(state); // Lose stateFilters and currentSearch if a new
1166
- // term is passed via an argument
1167
-
1168
- const stateFilters = term ? {} : Object.fromEntries(Object.entries(getSelectedFilters(state, facet, searchContext, 'js')).map(([key, f]) => [key, f === null || f === void 0 ? void 0 : f.join(',')]));
1169
- const currentSearch = !term && getImmutableOrJS(state, ['routing', 'location', 'search']);
1170
- const currentQs = removeEmptyAttributes(queryString.parse(currentSearch));
1171
- if (orderBy) currentQs.orderBy = orderBy;
1172
- const searchTerm = getSearchTerm(state); // Merge the stateFilters with any current qs to build the new qs
1173
-
1174
- const mergedSearch = removeEmptyAttributes({ ...merge__default["default"](currentQs, stateFilters),
1175
- term: searchTerm
1176
- });
1177
- return queryString.stringify(mergedSearch);
1178
- },
1179
- hash: state => getImmutableOrJS(state, ['routing', 'location', 'hash'], '').replace('#', '')
1180
- };
1181
-
1182
- const mapStateToSearchUri = params => mapJson__default["default"](params, searchUriTemplate);
1183
-
1184
1205
  const mapEntriesToSearchResults = ({
1185
1206
  mappers,
1186
1207
  mapper,
@@ -1988,6 +2009,19 @@ function* buildUri({
1988
2009
  return `${uri.path}${uri.search && `?${uri.search}` || ''}${uri.hash && `#${uri.hash}` || ''}`;
1989
2010
  }
1990
2011
 
2012
+ function* triggerMinilistSsr(options) {
2013
+ yield effects.call(doSearch, {
2014
+ type: DO_SEARCH,
2015
+ ...options
2016
+ });
2017
+ }
2018
+ function* triggerListingSsr(options) {
2019
+ yield effects.call(setRouteFilters, options);
2020
+ }
2021
+ function* triggerSearchSsr(options) {
2022
+ yield effects.call(setRouteFilters, options);
2023
+ }
2024
+
1991
2025
  exports.APPLY_CONFIG = APPLY_CONFIG;
1992
2026
  exports.CLEAR_FILTERS = CLEAR_FILTERS;
1993
2027
  exports.EXECUTE_SEARCH = EXECUTE_SEARCH;
@@ -2033,6 +2067,7 @@ exports.getTotalCount = getTotalCount;
2033
2067
  exports.mapStateToSearchUri = mapStateToSearchUri;
2034
2068
  exports.orderByExpression = orderByExpression;
2035
2069
  exports.queries = queries;
2070
+ exports.routeParams = routeParams;
2036
2071
  exports.searchSagas = searchSagas;
2037
2072
  exports.selectFacets = selectFacets;
2038
2073
  exports.selectListing = selectListing;
@@ -2040,7 +2075,10 @@ exports.selectors = selectors;
2040
2075
  exports.setRouteFilters = setRouteFilters;
2041
2076
  exports.termExpressions = termExpressions;
2042
2077
  exports.toArray = toArray;
2078
+ exports.triggerListingSsr = triggerListingSsr;
2079
+ exports.triggerMinilistSsr = triggerMinilistSsr;
2043
2080
  exports.triggerSearch = triggerSearch;
2081
+ exports.triggerSearchSsr = triggerSearchSsr;
2044
2082
  exports.types = types;
2045
2083
  exports.updateCurrentFacet = updateCurrentFacet$1;
2046
2084
  exports.updateCurrentTab = updateCurrentTab$1;
@@ -2049,4 +2087,4 @@ exports.updateSearchTerm = updateSearchTerm$1;
2049
2087
  exports.updateSelectedFilters = updateSelectedFilters;
2050
2088
  exports.updateSortOrder = updateSortOrder$1;
2051
2089
  exports.withMappers = withMappers;
2052
- //# sourceMappingURL=sagas-24f5607f.js.map
2090
+ //# sourceMappingURL=sagas-594b5ecd.js.map