@usereactify/search 4.4.0-beta.0 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/package.json +8 -10
  3. package/dist/filter/Filter.d.ts +0 -12
  4. package/dist/filter/Filter.js +0 -71
  5. package/dist/filter/FilterList.d.ts +0 -4
  6. package/dist/filter/FilterList.js +0 -15
  7. package/dist/filter/FilterStack.d.ts +0 -11
  8. package/dist/filter/FilterStack.js +0 -25
  9. package/dist/filter/index.d.ts +0 -3
  10. package/dist/filter/index.js +0 -15
  11. package/dist/hooks/index.d.ts +0 -14
  12. package/dist/hooks/index.js +0 -26
  13. package/dist/hooks/reactivesearch/index.d.ts +0 -5
  14. package/dist/hooks/reactivesearch/index.js +0 -17
  15. package/dist/hooks/reactivesearch/useReactiveBaseProps.d.ts +0 -7
  16. package/dist/hooks/reactivesearch/useReactiveBaseProps.js +0 -43
  17. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +0 -28
  18. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.js +0 -71
  19. package/dist/hooks/reactivesearch/useReactiveFilterListProps.d.ts +0 -68
  20. package/dist/hooks/reactivesearch/useReactiveFilterListProps.js +0 -106
  21. package/dist/hooks/reactivesearch/useReactiveReactProp.d.ts +0 -3
  22. package/dist/hooks/reactivesearch/useReactiveReactProp.js +0 -25
  23. package/dist/hooks/reactivesearch/useReactiveResultListProps.d.ts +0 -19
  24. package/dist/hooks/reactivesearch/useReactiveResultListProps.js +0 -32
  25. package/dist/hooks/useAnalytics.d.ts +0 -95
  26. package/dist/hooks/useAnalytics.js +0 -110
  27. package/dist/hooks/useCollection.d.ts +0 -1
  28. package/dist/hooks/useCollection.js +0 -6
  29. package/dist/hooks/useConfig.d.ts +0 -1
  30. package/dist/hooks/useConfig.js +0 -6
  31. package/dist/hooks/useCuration.d.ts +0 -1
  32. package/dist/hooks/useCuration.js +0 -6
  33. package/dist/hooks/useFilterCollapsedState.d.ts +0 -8
  34. package/dist/hooks/useFilterCollapsedState.js +0 -27
  35. package/dist/hooks/useFilterListProps.d.ts +0 -22
  36. package/dist/hooks/useFilterListProps.js +0 -35
  37. package/dist/hooks/useFilterStack.d.ts +0 -1
  38. package/dist/hooks/useFilterStack.js +0 -6
  39. package/dist/hooks/useFilters.d.ts +0 -1
  40. package/dist/hooks/useFilters.js +0 -17
  41. package/dist/hooks/useLiveConfig.d.ts +0 -4
  42. package/dist/hooks/useLiveConfig.js +0 -74
  43. package/dist/hooks/usePages.d.ts +0 -10
  44. package/dist/hooks/usePages.js +0 -97
  45. package/dist/hooks/useProductPrice.d.ts +0 -12
  46. package/dist/hooks/useProductPrice.js +0 -61
  47. package/dist/hooks/useSearch.d.ts +0 -8
  48. package/dist/hooks/useSearch.js +0 -16
  49. package/dist/hooks/useSort.d.ts +0 -5
  50. package/dist/hooks/useSort.js +0 -24
  51. package/dist/index.d.ts +0 -9
  52. package/dist/index.js +0 -24
  53. package/dist/provider.d.ts +0 -78
  54. package/dist/provider.js +0 -287
  55. package/dist/result/ResultCard.d.ts +0 -14
  56. package/dist/result/ResultCard.js +0 -66
  57. package/dist/result/ResultCardCallout.d.ts +0 -13
  58. package/dist/result/ResultCardCallout.js +0 -53
  59. package/dist/result/ResultList.d.ts +0 -34
  60. package/dist/result/ResultList.js +0 -93
  61. package/dist/result/ResultLoadMoreButton.d.ts +0 -10
  62. package/dist/result/ResultLoadMoreButton.js +0 -61
  63. package/dist/result/ResultPagination.d.ts +0 -10
  64. package/dist/result/ResultPagination.js +0 -60
  65. package/dist/result/ResultPaginationNextPrev.d.ts +0 -8
  66. package/dist/result/ResultPaginationNextPrev.js +0 -30
  67. package/dist/result/ResultStateProvider.d.ts +0 -7
  68. package/dist/result/ResultStateProvider.js +0 -10
  69. package/dist/result/index.d.ts +0 -6
  70. package/dist/result/index.js +0 -18
  71. package/dist/search/SearchInput.d.ts +0 -9
  72. package/dist/search/SearchInput.js +0 -17
  73. package/dist/search/index.d.ts +0 -1
  74. package/dist/search/index.js +0 -13
  75. package/dist/sensor/SensorCollection.d.ts +0 -2
  76. package/dist/sensor/SensorCollection.js +0 -41
  77. package/dist/sensor/SensorInventoryAvailable.d.ts +0 -2
  78. package/dist/sensor/SensorInventoryAvailable.js +0 -52
  79. package/dist/sensor/SensorPublished.d.ts +0 -2
  80. package/dist/sensor/SensorPublished.js +0 -16
  81. package/dist/sensor/SensorSearch.d.ts +0 -2
  82. package/dist/sensor/SensorSearch.js +0 -82
  83. package/dist/sensor/SensorSort.d.ts +0 -2
  84. package/dist/sensor/SensorSort.js +0 -205
  85. package/dist/sensor/SensorSortScore.d.ts +0 -2
  86. package/dist/sensor/SensorSortScore.js +0 -12
  87. package/dist/sensor/SensorStack.d.ts +0 -2
  88. package/dist/sensor/SensorStack.js +0 -31
  89. package/dist/sensor/index.d.ts +0 -8
  90. package/dist/sensor/index.js +0 -29
  91. package/dist/types/config.d.ts +0 -25
  92. package/dist/types/config.js +0 -2
  93. package/dist/types/elastic.d.ts +0 -209
  94. package/dist/types/elastic.js +0 -18
  95. package/dist/types/firestore.d.ts +0 -280
  96. package/dist/types/firestore.js +0 -18
  97. package/dist/types/graphql.d.ts +0 -26545
  98. package/dist/types/graphql.js +0 -4687
  99. package/dist/types/reactivesearch.d.ts +0 -73
  100. package/dist/types/reactivesearch.js +0 -2
  101. package/dist/types/shopify.d.ts +0 -21
  102. package/dist/types/shopify.js +0 -27
  103. package/dist/utility/UtilityAuthenticatedReactiveBase.d.ts +0 -2
  104. package/dist/utility/UtilityAuthenticatedReactiveBase.js +0 -14
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useReactiveFilterListProps = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const useReactiveReactProp_1 = require("./useReactiveReactProp");
9
- const useReactiveFilterListProps = (filter) => {
10
- const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)(filter.handle);
11
- const nestedField = react_1.default.useMemo(() => {
12
- const nestedFields = ["variants"];
13
- const topField = filter.field.split(".")[0];
14
- if (nestedFields.includes(topField))
15
- return topField;
16
- return undefined;
17
- }, [filter]);
18
- // define a custom query for when settingsHideUnavailable is enabled and the target field is inside variants
19
- // customQuery defines how this filter affects *other* components like the results component
20
- const customQuery = react_1.default.useMemo(() => {
21
- if (!filter.settingsHideUnavailable ||
22
- !filter.field.startsWith("variants."))
23
- return undefined;
24
- return (value) => {
25
- if (!value)
26
- return {};
27
- // reactivesearch sometimes returns string, sometimes string[]
28
- const valueArray = "string" === typeof value ? [value] : value;
29
- if (0 === valueArray.length)
30
- return {};
31
- return {
32
- query: {
33
- nested: {
34
- path: "variants",
35
- query: {
36
- bool: {
37
- must: [
38
- {
39
- match: {
40
- "variants.available": "true",
41
- },
42
- },
43
- {
44
- terms: {
45
- [filter.field]: valueArray,
46
- },
47
- },
48
- ],
49
- },
50
- },
51
- },
52
- },
53
- };
54
- };
55
- }, [filter]);
56
- // define a default query for when settingsHideUnavailable is enabled and the target field is inside variants
57
- // defaultQuery defines how this filter affects itself i.e. the options displayed
58
- const defaultQuery = react_1.default.useMemo(() => {
59
- if (!filter.settingsHideUnavailable ||
60
- !filter.field.startsWith("variants."))
61
- return undefined;
62
- // override the aggregation query to filter the results by the variants.available attribute
63
- return () => {
64
- return {
65
- aggs: {
66
- reactivesearch_nested: {
67
- nested: { path: "variants" },
68
- aggs: {
69
- reactify_nested_outer: {
70
- filter: {
71
- match: {
72
- "variants.available": "true",
73
- },
74
- },
75
- aggs: {
76
- [filter.field]: {
77
- terms: {
78
- field: filter.field,
79
- size: 100,
80
- order: { _count: "desc" },
81
- },
82
- },
83
- },
84
- },
85
- },
86
- },
87
- },
88
- };
89
- };
90
- }, [filter]);
91
- return react_1.default.useMemo(() => ({
92
- nestedField,
93
- customQuery,
94
- defaultQuery,
95
- URLParams: true,
96
- componentId: filter.handle,
97
- dataField: filter.field,
98
- filterLabel: filter.name,
99
- react: reactiveReactProp,
100
- size: parseInt(filter.displaySize) || undefined,
101
- showFilter: filter.settingsShowFilter || true,
102
- showLoadMore: filter.settingsShowMore || false,
103
- showSearch: (filter === null || filter === void 0 ? void 0 : filter.settingsShowSearch) || false,
104
- }), [filter, reactiveReactProp]);
105
- };
106
- exports.useReactiveFilterListProps = useReactiveFilterListProps;
@@ -1,3 +0,0 @@
1
- export declare const useReactiveReactProp: (currentHandle?: string | undefined) => {
2
- and: string[];
3
- };
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useReactiveReactProp = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const sensor_1 = require("../../sensor");
9
- const useFilters_1 = require("../useFilters");
10
- const provider_1 = require("../../provider");
11
- const useReactiveReactProp = (currentHandle) => {
12
- const filters = (0, useFilters_1.useFilters)();
13
- const { additionalComponentHandles } = (0, provider_1.useContext)();
14
- return react_1.default.useMemo(() => {
15
- return {
16
- and: [
17
- "SearchInput",
18
- ...sensor_1.SENSOR_IDS,
19
- ...(additionalComponentHandles !== null && additionalComponentHandles !== void 0 ? additionalComponentHandles : []),
20
- ...filters.map((filter) => filter.handle),
21
- ].filter((handle) => handle !== currentHandle),
22
- };
23
- }, [filters, currentHandle]);
24
- };
25
- exports.useReactiveReactProp = useReactiveReactProp;
@@ -1,19 +0,0 @@
1
- declare type Props = {
2
- pageSize?: number;
3
- };
4
- export declare const useReactiveResultListProps: (props?: Props) => {
5
- size: number;
6
- URLParams: boolean;
7
- showLoader: boolean;
8
- dataField: string;
9
- showResultStats: boolean;
10
- react: {
11
- and: string[];
12
- };
13
- componentId: string;
14
- scrollOnChange: boolean;
15
- pagination: boolean;
16
- infiniteScroll: boolean;
17
- renderNoResults: () => null;
18
- };
19
- export {};
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useReactiveResultListProps = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const hooks_1 = require("../../hooks");
9
- const useReactiveReactProp_1 = require("./useReactiveReactProp");
10
- const useReactiveResultListProps = (props = {}) => {
11
- const { pageSize } = props;
12
- const filterStack = (0, hooks_1.useFilterStack)();
13
- const reactiveReactProp = (0, useReactiveReactProp_1.useReactiveReactProp)();
14
- const size = react_1.default.useMemo(() => {
15
- var _a;
16
- return (_a = pageSize !== null && pageSize !== void 0 ? pageSize : filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) !== null && _a !== void 0 ? _a : 20;
17
- }, [pageSize, filterStack]);
18
- return react_1.default.useMemo(() => ({
19
- size,
20
- URLParams: true,
21
- showLoader: false,
22
- dataField: "title",
23
- showResultStats: false,
24
- react: reactiveReactProp,
25
- componentId: "page",
26
- scrollOnChange: false,
27
- pagination: (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) !== "infinite_scroll",
28
- infiniteScroll: (filterStack === null || filterStack === void 0 ? void 0 : filterStack.paginationType) === "infinite_scroll",
29
- renderNoResults: () => null, // always use only render, otherwise both are shown
30
- }), [filterStack, reactiveReactProp, pageSize]);
31
- };
32
- exports.useReactiveResultListProps = useReactiveResultListProps;
@@ -1,95 +0,0 @@
1
- export declare const useAnalytics: () => {
2
- track: (event: TrackEvent) => Promise<import("axios").AxiosResponse<any, any> | undefined>;
3
- };
4
- export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.ZeroResultsEvent | TrackEvent.ViewProductEvent | TrackEvent.ClickProductEvent | TrackEvent.ViewPromotionEvent | TrackEvent.ClickPromotionEvent | TrackEvent.PaginationChangeEvent | TrackEvent.SortChangeEvent | TrackEvent.FilterChangeEvent;
5
- export declare namespace TrackEvent {
6
- interface SearchEvent {
7
- eventName: "search";
8
- payload: SearchEvent.Payload;
9
- }
10
- namespace SearchEvent {
11
- interface Payload {
12
- searchTerm: string;
13
- }
14
- }
15
- interface ZeroResultsEvent {
16
- eventName: "zeroResults";
17
- payload: ZeroResultsEvent.Payload;
18
- }
19
- namespace ZeroResultsEvent {
20
- interface Payload {
21
- searchTerm: string;
22
- }
23
- }
24
- interface ViewProductEvent {
25
- eventName: "viewProduct";
26
- payload: ViewProductEvent.Payload;
27
- }
28
- namespace ViewProductEvent {
29
- interface Payload {
30
- elasticProduct: ElasticProduct;
31
- }
32
- }
33
- interface ClickProductEvent {
34
- eventName: "clickProduct";
35
- payload: ClickProductEvent.Payload;
36
- }
37
- namespace ClickProductEvent {
38
- interface Payload {
39
- elasticProduct: ElasticProduct;
40
- }
41
- }
42
- interface ViewPromotionEvent {
43
- eventName: "viewPromotion";
44
- payload: ViewPromotionEvent.Payload;
45
- }
46
- namespace ViewPromotionEvent {
47
- interface Payload {
48
- link: string;
49
- title: string;
50
- }
51
- }
52
- interface ClickPromotionEvent {
53
- eventName: "clickPromotion";
54
- payload: ClickPromotionEvent.Payload;
55
- }
56
- namespace ClickPromotionEvent {
57
- interface Payload {
58
- link: string;
59
- title: string;
60
- }
61
- }
62
- interface PaginationChangeEvent {
63
- eventName: "paginationChange";
64
- payload: PaginationChangeEvent.Payload;
65
- }
66
- namespace PaginationChangeEvent {
67
- interface Payload {
68
- page: number;
69
- source: "search" | "collection";
70
- }
71
- }
72
- interface SortChangeEvent {
73
- eventName: "sortChange";
74
- payload: SortChangeEvent.Payload;
75
- }
76
- namespace SortChangeEvent {
77
- interface Payload {
78
- type: string;
79
- }
80
- }
81
- interface FilterChangeEvent {
82
- eventName: "filterChange";
83
- payload: FilterChangeEvent.Payload;
84
- }
85
- namespace FilterChangeEvent {
86
- interface Payload {
87
- name: string;
88
- value: string;
89
- }
90
- }
91
- interface ElasticProduct {
92
- id: number;
93
- title: string;
94
- }
95
- }
@@ -1,110 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useAnalytics = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const provider_1 = require("../provider");
18
- const useAnalytics = () => {
19
- const { shopifyPermanentDomain } = (0, provider_1.useContext)();
20
- const url = "https://analytics.search.reactify.app/record/";
21
- const track = (event) => __awaiter(void 0, void 0, void 0, function* () {
22
- if (!shopifyPermanentDomain) {
23
- console.warn(new Error('Unable to send tracking event, missing value for "shopifyPermanentDomain".'));
24
- return;
25
- }
26
- const events = getTrackEvents(event);
27
- return axios_1.default.post(url, { events }, { headers: { "X-Reactify-Tenant": shopifyPermanentDomain } });
28
- });
29
- return { track };
30
- };
31
- exports.useAnalytics = useAnalytics;
32
- function getTrackEvents(event) {
33
- const { eventName } = event;
34
- let events = [];
35
- switch (eventName) {
36
- case "search":
37
- events = [
38
- {
39
- eventName,
40
- payload: event.payload,
41
- },
42
- ];
43
- break;
44
- case "zeroResults":
45
- events = [
46
- {
47
- eventName,
48
- payload: event.payload,
49
- },
50
- ];
51
- break;
52
- case "viewProduct":
53
- events = [
54
- {
55
- eventName,
56
- payload: event.payload,
57
- },
58
- ];
59
- break;
60
- case "clickProduct":
61
- events = [
62
- {
63
- eventName,
64
- payload: event.payload,
65
- },
66
- ];
67
- break;
68
- case "viewPromotion":
69
- events = [
70
- {
71
- eventName,
72
- payload: event.payload,
73
- },
74
- ];
75
- break;
76
- case "clickPromotion":
77
- events = [
78
- {
79
- eventName,
80
- payload: event.payload,
81
- },
82
- ];
83
- break;
84
- case "paginationChange":
85
- events = [
86
- {
87
- eventName,
88
- payload: event.payload,
89
- },
90
- ];
91
- break;
92
- case "sortChange":
93
- events = [
94
- {
95
- eventName,
96
- payload: event.payload,
97
- },
98
- ];
99
- break;
100
- case "filterChange":
101
- events = [
102
- {
103
- eventName,
104
- payload: event.payload,
105
- },
106
- ];
107
- break;
108
- }
109
- return events;
110
- }
@@ -1 +0,0 @@
1
- export declare const useCollection: () => import("../provider").Collection | undefined;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCollection = void 0;
4
- const provider_1 = require("../provider");
5
- const useCollection = () => (0, provider_1.useContext)().collection;
6
- exports.useCollection = useCollection;
@@ -1 +0,0 @@
1
- export declare const useConfig: () => import("..").Config;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useConfig = void 0;
4
- const provider_1 = require("../provider");
5
- const useConfig = () => (0, provider_1.useContext)().config;
6
- exports.useConfig = useConfig;
@@ -1 +0,0 @@
1
- export declare const useCuration: () => import("..").ConfigCuration | undefined;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useCuration = void 0;
4
- const provider_1 = require("../provider");
5
- const useCuration = () => (0, provider_1.useContext)().curation;
6
- exports.useCuration = useCuration;
@@ -1,8 +0,0 @@
1
- import { ConfigFilterOption } from "../types/config";
2
- export declare const useFilterCollapsedState: (filter: ConfigFilterOption) => {
3
- collapsed: boolean;
4
- shouldRender: boolean;
5
- collapsedShow: () => void;
6
- collapsedHide: () => void;
7
- collapsedToggle: () => void;
8
- };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useFilterCollapsedState = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const useFilterCollapsedState = (filter) => {
9
- // @todo use settingsCollapsedDesktop and settingsCollapsedMobile with device detection
10
- const [collapsed, setCollapsed] = react_1.default.useState(filter.settingsCollapsedDesktop);
11
- // when the filter is shown, it needs to stay rendered or when it's collapsed, the filter context
12
- // will be lost which isn't expected behaviour
13
- const [shouldRender, setShouldRender] = react_1.default.useState(!collapsed);
14
- // enable render when filter is uncollapsed
15
- react_1.default.useEffect(() => {
16
- if (!collapsed)
17
- setShouldRender(true);
18
- }, [collapsed]);
19
- return {
20
- collapsed,
21
- shouldRender,
22
- collapsedShow: react_1.default.useCallback(() => setCollapsed(true), []),
23
- collapsedHide: react_1.default.useCallback(() => setCollapsed(false), []),
24
- collapsedToggle: react_1.default.useCallback(() => setCollapsed((collapsed) => !collapsed), []),
25
- };
26
- };
27
- exports.useFilterCollapsedState = useFilterCollapsedState;
@@ -1,22 +0,0 @@
1
- import { ConfigFilterOption } from "../types/config";
2
- import { ReactivesearchFilterProps } from "../types/reactivesearch";
3
- export declare const useFilterListProps: (filter: ConfigFilterOption, reactivesearchFilterProps: ReactivesearchFilterProps) => {
4
- filter: ConfigFilterOption;
5
- options: {
6
- checked: boolean;
7
- doc_count: number;
8
- key: string;
9
- }[];
10
- hasSelected: boolean;
11
- totalSelected: number;
12
- loading: boolean;
13
- error: Error | null;
14
- handleChange: (value: string) => void;
15
- data: {
16
- doc_count: number;
17
- key: string;
18
- }[];
19
- value: string | {
20
- [key: string]: boolean;
21
- };
22
- };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useFilterListProps = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- // converts reactivesearch props returned in filters to a cleaned up/filtered version
9
- const useFilterListProps = (filter, reactivesearchFilterProps) => {
10
- return react_1.default.useMemo(() => {
11
- const { data, value } = reactivesearchFilterProps;
12
- // remove excluded options, sort alphabeticaly, map checked boolean
13
- const options = data
14
- .filter(({ key }) => {
15
- var _a, _b;
16
- if ((_a = filter.valuesExclude) === null || _a === void 0 ? void 0 : _a.includes(key))
17
- return false;
18
- if (!!((_b = filter.valuesManual) === null || _b === void 0 ? void 0 : _b.length) && !filter.valuesManual.includes(key))
19
- return false;
20
- return true;
21
- })
22
- .sort((a, b) => a.key.localeCompare(b.key))
23
- .map((option) => (Object.assign(Object.assign({}, option), { checked: (typeof value === "object" && value[option.key]) ||
24
- value === option.key })));
25
- // work out if at least one option selected
26
- const hasSelected = (typeof value === "object" && 0 < Object.keys(value).length) ||
27
- (typeof value !== "object" && !!value);
28
- const totalSelected = options.filter((option) => option.checked).length;
29
- return Object.assign(Object.assign({}, reactivesearchFilterProps), { filter,
30
- options,
31
- hasSelected,
32
- totalSelected });
33
- }, [filter, reactivesearchFilterProps]);
34
- };
35
- exports.useFilterListProps = useFilterListProps;
@@ -1 +0,0 @@
1
- export declare const useFilterStack: () => import("..").ConfigFilter | undefined;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useFilterStack = void 0;
4
- const provider_1 = require("../provider");
5
- const useFilterStack = () => (0, provider_1.useContext)().filterStack;
6
- exports.useFilterStack = useFilterStack;
@@ -1 +0,0 @@
1
- export declare const useFilters: () => Omit<import("../types/firestore").FilterOption, "enabled">[];
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useFilters = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const useFilterStack_1 = require("./useFilterStack");
9
- const useFilters = () => {
10
- const filterStack = (0, useFilterStack_1.useFilterStack)();
11
- return react_1.default.useMemo(() => {
12
- if (!filterStack)
13
- return [];
14
- return filterStack.options.sort((a, b) => a.position > b.position ? 1 : -1);
15
- }, [filterStack]);
16
- };
17
- exports.useFilters = useFilters;
@@ -1,4 +0,0 @@
1
- import { Config } from "../types/config";
2
- export declare const useLiveConfig: (shopifyPermanentDomain: string, configId?: string | undefined) => {
3
- config: Config | undefined;
4
- };
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.useLiveConfig = void 0;
16
- const react_1 = __importDefault(require("react"));
17
- const debug = require("debug")("reactify-search:useLiveConfig");
18
- // 5 minute cache expiry
19
- const CACHE_EXPIRY = 5 * 60 * 1000;
20
- // synchronously returns cached and non-expired config from session storage
21
- function getCachedConfig() {
22
- var _a;
23
- if (typeof window === "undefined") {
24
- return;
25
- }
26
- // skip checking cache if url search param "nocache" is set
27
- const skipCache = new URLSearchParams(window.location.href.split("?")[1]).get("nocache") !==
28
- null;
29
- if (skipCache) {
30
- debug("skipping cache");
31
- return;
32
- }
33
- const sessionConfig = JSON.parse((_a = window.sessionStorage.getItem("reactify-search:config")) !== null && _a !== void 0 ? _a : "null");
34
- if (sessionConfig) {
35
- const sessionConfigTtl = sessionConfig.expiresAt - Date.now();
36
- debug(`found ${sessionConfigTtl > 0 ? "cached" : "expired"} config`);
37
- if (sessionConfigTtl > 0) {
38
- debug(`config expires in ${(sessionConfigTtl / 1000).toFixed()} seconds`);
39
- return sessionConfig.config;
40
- }
41
- }
42
- return;
43
- }
44
- const useLiveConfig = (shopifyPermanentDomain, configId) => {
45
- const [config, setConfig] = react_1.default.useState(getCachedConfig());
46
- react_1.default.useEffect(() => {
47
- const cachedConfig = getCachedConfig();
48
- if (cachedConfig)
49
- return;
50
- (() => __awaiter(void 0, void 0, void 0, function* () {
51
- debug("fetching fresh config");
52
- const searchParams = new URLSearchParams();
53
- searchParams.set("shop", shopifyPermanentDomain);
54
- if (configId) {
55
- searchParams.set("id", configId);
56
- }
57
- const skipCache = new URLSearchParams(window.location.href.split("?")[1]).get("nocache") !== null;
58
- if (skipCache) {
59
- searchParams.set("nocache", "true");
60
- }
61
- const json = yield fetch(`https://config.search.reactify.app/?${searchParams.toString()}`).then((response) => response.json());
62
- setConfig(json.body);
63
- window.sessionStorage.setItem("reactify-search:config", JSON.stringify({
64
- expiresAt: new Date().getTime() + CACHE_EXPIRY,
65
- noCache: skipCache,
66
- config: json.body,
67
- }));
68
- }))();
69
- }, [shopifyPermanentDomain, configId]);
70
- return {
71
- config,
72
- };
73
- };
74
- exports.useLiveConfig = useLiveConfig;
@@ -1,10 +0,0 @@
1
- import { ReactivesearchPaginationProps } from "../types/reactivesearch";
2
- export declare const usePages: (props: ReactivesearchPaginationProps) => {
3
- pagesToShow: number[];
4
- hasNextPage: boolean;
5
- buildPagePath: (page: number) => string;
6
- handleNextPage: (event?: any) => void;
7
- hasPreviousPage: boolean;
8
- actualCurrentPage: number;
9
- handlePreviousPage: (event?: any) => void;
10
- };