@usereactify/search 2.1.0-beta.2 → 2.1.0-beta.3

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 (98) hide show
  1. package/README.md +5 -0
  2. package/dist/filter/Filter.d.ts +12 -0
  3. package/dist/filter/Filter.js +58 -0
  4. package/dist/filter/FilterList.d.ts +4 -0
  5. package/dist/filter/FilterList.js +15 -0
  6. package/dist/filter/FilterStack.d.ts +11 -0
  7. package/dist/filter/FilterStack.js +25 -0
  8. package/dist/filter/index.d.ts +3 -0
  9. package/dist/filter/index.js +15 -0
  10. package/dist/hooks/index.d.ts +14 -0
  11. package/dist/hooks/index.js +26 -0
  12. package/dist/hooks/reactivesearch/index.d.ts +5 -0
  13. package/dist/hooks/reactivesearch/index.js +17 -0
  14. package/dist/hooks/reactivesearch/useReactiveBaseProps.d.ts +7 -0
  15. package/dist/hooks/reactivesearch/useReactiveBaseProps.js +43 -0
  16. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.d.ts +24 -0
  17. package/dist/hooks/reactivesearch/useReactiveDataSearchProps.js +87 -0
  18. package/dist/hooks/reactivesearch/useReactiveFilterListProps.d.ts +68 -0
  19. package/dist/hooks/reactivesearch/useReactiveFilterListProps.js +106 -0
  20. package/dist/hooks/reactivesearch/useReactiveReactProp.d.ts +3 -0
  21. package/dist/hooks/reactivesearch/useReactiveReactProp.js +25 -0
  22. package/dist/hooks/reactivesearch/useReactiveResultListProps.d.ts +20 -0
  23. package/dist/hooks/reactivesearch/useReactiveResultListProps.js +32 -0
  24. package/dist/hooks/useAnalytics.d.ts +14 -0
  25. package/dist/hooks/useAnalytics.js +47 -0
  26. package/dist/hooks/useCollection.d.ts +1 -0
  27. package/dist/hooks/useCollection.js +6 -0
  28. package/dist/hooks/useCombinedResults.d.ts +7 -0
  29. package/dist/hooks/useCombinedResults.js +25 -0
  30. package/dist/hooks/useConfig.d.ts +1 -0
  31. package/dist/hooks/useConfig.js +6 -0
  32. package/dist/hooks/useCuration.d.ts +1 -0
  33. package/dist/hooks/useCuration.js +6 -0
  34. package/dist/hooks/useFilterCollapsedState.d.ts +8 -0
  35. package/dist/hooks/useFilterCollapsedState.js +27 -0
  36. package/dist/hooks/useFilterListProps.d.ts +21 -0
  37. package/dist/hooks/useFilterListProps.js +35 -0
  38. package/dist/hooks/useFilterStack.d.ts +1 -0
  39. package/dist/hooks/useFilterStack.js +6 -0
  40. package/dist/hooks/useFilters.d.ts +1 -0
  41. package/dist/hooks/useFilters.js +17 -0
  42. package/dist/hooks/usePages.d.ts +10 -0
  43. package/dist/hooks/usePages.js +82 -0
  44. package/dist/hooks/useProductPrice.d.ts +12 -0
  45. package/dist/hooks/useProductPrice.js +61 -0
  46. package/dist/hooks/useSearch.d.ts +8 -0
  47. package/dist/hooks/useSearch.js +16 -0
  48. package/dist/hooks/useSort.d.ts +5 -0
  49. package/dist/hooks/useSort.js +9 -0
  50. package/dist/index.d.ts +7 -0
  51. package/dist/index.js +19 -0
  52. package/dist/provider.d.ts +44 -0
  53. package/dist/provider.js +165 -0
  54. package/dist/result/ResultCard.d.ts +10 -0
  55. package/dist/result/ResultCard.js +45 -0
  56. package/dist/result/ResultCardCallout.d.ts +9 -0
  57. package/dist/result/ResultCardCallout.js +38 -0
  58. package/dist/result/ResultList.d.ts +30 -0
  59. package/dist/result/ResultList.js +99 -0
  60. package/dist/result/ResultLoadMoreButton.d.ts +9 -0
  61. package/dist/result/ResultLoadMoreButton.js +27 -0
  62. package/dist/result/ResultPagination.d.ts +8 -0
  63. package/dist/result/ResultPagination.js +50 -0
  64. package/dist/result/ResultPaginationNextPrev.d.ts +8 -0
  65. package/dist/result/ResultPaginationNextPrev.js +30 -0
  66. package/dist/result/ResultStateProvider.d.ts +7 -0
  67. package/dist/result/ResultStateProvider.js +10 -0
  68. package/dist/result/index.d.ts +5 -0
  69. package/dist/result/index.js +17 -0
  70. package/dist/search/SearchInput.d.ts +8 -0
  71. package/dist/search/SearchInput.js +19 -0
  72. package/dist/search/index.d.ts +1 -0
  73. package/dist/search/index.js +13 -0
  74. package/dist/sensor/SensorCollection.d.ts +2 -0
  75. package/dist/sensor/SensorCollection.js +41 -0
  76. package/dist/sensor/SensorInventoryAvailable.d.ts +2 -0
  77. package/dist/sensor/SensorInventoryAvailable.js +25 -0
  78. package/dist/sensor/SensorPublished.d.ts +2 -0
  79. package/dist/sensor/SensorPublished.js +16 -0
  80. package/dist/sensor/SensorSearch.d.ts +2 -0
  81. package/dist/sensor/SensorSearch.js +81 -0
  82. package/dist/sensor/SensorSort.d.ts +2 -0
  83. package/dist/sensor/SensorSort.js +144 -0
  84. package/dist/sensor/SensorSortScore.d.ts +2 -0
  85. package/dist/sensor/SensorSortScore.js +12 -0
  86. package/dist/sensor/SensorStack.d.ts +2 -0
  87. package/dist/sensor/SensorStack.js +31 -0
  88. package/dist/sensor/index.d.ts +8 -0
  89. package/dist/sensor/index.js +29 -0
  90. package/dist/types/config.d.ts +130 -0
  91. package/dist/types/config.js +2 -0
  92. package/dist/types/index.d.ts +79 -0
  93. package/dist/types/index.js +14 -0
  94. package/dist/types/results.d.ts +48 -0
  95. package/dist/types/results.js +2 -0
  96. package/dist/utility/UtilityAuthenticatedReactiveBase.d.ts +2 -0
  97. package/dist/utility/UtilityAuthenticatedReactiveBase.js +14 -0
  98. package/package.json +1 -1
@@ -0,0 +1,32 @@
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, pageSizeAdjust } = 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) - (pageSizeAdjust !== null && pageSizeAdjust !== void 0 ? pageSizeAdjust : 0);
17
+ }, [pageSize, pageSizeAdjust, 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;
@@ -0,0 +1,14 @@
1
+ export declare const useAnalytics: () => {
2
+ track: (event: TrackEvent) => Promise<void>;
3
+ };
4
+ export declare type TrackEvent = TrackEvent.SearchEvent | TrackEvent.SelectItemEvent;
5
+ export declare namespace TrackEvent {
6
+ interface SearchEvent {
7
+ eventName: "search";
8
+ searchTerm: string;
9
+ }
10
+ interface SelectItemEvent {
11
+ eventName: "select_item";
12
+ id: number;
13
+ }
14
+ }
@@ -0,0 +1,47 @@
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.useAnalytics = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ const provider_1 = require("../provider");
9
+ const useAnalytics = () => {
10
+ const { shopName } = (0, provider_1.useContext)();
11
+ const url = "https://analytics.search.reactify.app/record/";
12
+ const track = (event) => {
13
+ const events = getTrackEvents(event);
14
+ return axios_1.default
15
+ .post(url, { events }, { headers: { "X-Reactify-Tenant": shopName || "test shop name" } })
16
+ .then((response) => {
17
+ console.log(response);
18
+ });
19
+ };
20
+ return { track };
21
+ };
22
+ exports.useAnalytics = useAnalytics;
23
+ function getTrackEvents(event) {
24
+ const { eventName } = event;
25
+ let events = [];
26
+ switch (eventName) {
27
+ case "search":
28
+ const { searchTerm } = event;
29
+ events = [
30
+ {
31
+ eventName,
32
+ searchTerm,
33
+ },
34
+ ];
35
+ break;
36
+ case "select_item":
37
+ const { id } = event;
38
+ events = [
39
+ {
40
+ eventName,
41
+ id,
42
+ },
43
+ ];
44
+ break;
45
+ }
46
+ return events;
47
+ }
@@ -0,0 +1 @@
1
+ export declare const useCollection: () => import("..").Collection | undefined;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,7 @@
1
+ import { ConfigCallout, ResultCombined, ReactivesearchResultProps } from "../types";
2
+ interface Props {
3
+ callouts: ConfigCallout[];
4
+ products: ReactivesearchResultProps["data"];
5
+ }
6
+ export declare const useCombinedResults: ({ callouts, products }: Props) => ResultCombined[];
7
+ export {};
@@ -0,0 +1,25 @@
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.useCombinedResults = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const useCombinedResults = ({ callouts, products }) => react_1.default.useMemo(() => {
9
+ const combinedResults = [];
10
+ let n = 0;
11
+ for (const product of products) {
12
+ // search for a callout in this position
13
+ const callout = callouts.find((callout) => n === callout.position);
14
+ if (callout)
15
+ combinedResults.push({ type: "callout", data: callout });
16
+ combinedResults.push({ type: "product", data: product });
17
+ n++;
18
+ }
19
+ // add a trailing callout if available
20
+ const callout = callouts.find((callout) => n === callout.position);
21
+ if (callout)
22
+ combinedResults.push({ type: "callout", data: callout });
23
+ return combinedResults;
24
+ }, [callouts, products]);
25
+ exports.useCombinedResults = useCombinedResults;
@@ -0,0 +1 @@
1
+ export declare const useConfig: () => import("..").Config;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1 @@
1
+ export declare const useCuration: () => import("..").ConfigCuration | undefined;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,8 @@
1
+ import { ConfigFilterOption } from "../types";
2
+ export declare const useFilterCollapsedState: (filter: ConfigFilterOption) => {
3
+ collapsed: boolean;
4
+ shouldRender: boolean;
5
+ collapsedShow: () => void;
6
+ collapsedHide: () => void;
7
+ collapsedToggle: () => void;
8
+ };
@@ -0,0 +1,27 @@
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;
@@ -0,0 +1,21 @@
1
+ import { ConfigFilterOption, ReactivesearchFilterProps } from "../types";
2
+ export declare const useFilterListProps: (filter: ConfigFilterOption, reactivesearchFilterProps: ReactivesearchFilterProps) => {
3
+ filter: ConfigFilterOption;
4
+ options: {
5
+ checked: boolean;
6
+ doc_count: number;
7
+ key: string;
8
+ }[];
9
+ hasSelected: boolean;
10
+ totalSelected: number;
11
+ loading: boolean;
12
+ error: Error | null;
13
+ handleChange: () => void;
14
+ data: {
15
+ doc_count: number;
16
+ key: string;
17
+ }[];
18
+ value: string | {
19
+ [key: string]: boolean;
20
+ };
21
+ };
@@ -0,0 +1,35 @@
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;
@@ -0,0 +1 @@
1
+ export declare const useFilterStack: () => import("..").ConfigFilter | undefined;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1 @@
1
+ export declare const useFilters: () => import("..").ConfigFilterOption[];
@@ -0,0 +1,17 @@
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;
@@ -0,0 +1,10 @@
1
+ import { ReactivesearchPaginationProps } from "../types";
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
+ };
@@ -0,0 +1,82 @@
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.usePages = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const usePages = (props) => {
9
+ const { pages, setPage, totalPages, currentPage } = props;
10
+ const buildPagePath = react_1.default.useCallback((page) => {
11
+ const currentPath = window.location.pathname;
12
+ return currentPath.includes("page=")
13
+ ? currentPath.replace(/page=\d+/g, `page=${page}`)
14
+ : `${currentPath}${currentPath.includes("?") ? "&" : "?"}page=${page}`;
15
+ }, []);
16
+ const pagesToShow = react_1.default.useMemo(() => getPages(pages, totalPages, currentPage), [pages, totalPages, currentPage]);
17
+ // default currentPage is zero-indexed, actualCurrentPage is one-indexed
18
+ const actualCurrentPage = react_1.default.useMemo(() => currentPage + 1, [currentPage]);
19
+ const hasNextPage = react_1.default.useMemo(() => actualCurrentPage < totalPages, [
20
+ actualCurrentPage,
21
+ totalPages,
22
+ ]);
23
+ const handleNextPage = react_1.default.useCallback((event) => {
24
+ event === null || event === void 0 ? void 0 : event.preventDefault();
25
+ if (!hasNextPage)
26
+ return;
27
+ setPage(currentPage + 1);
28
+ }, [hasNextPage, currentPage, setPage]);
29
+ const hasPreviousPage = react_1.default.useMemo(() => actualCurrentPage > 1, [
30
+ actualCurrentPage,
31
+ ]);
32
+ const handlePreviousPage = react_1.default.useCallback((event) => {
33
+ event === null || event === void 0 ? void 0 : event.preventDefault();
34
+ if (!hasPreviousPage)
35
+ return;
36
+ setPage(currentPage - 1);
37
+ }, [hasPreviousPage, currentPage, setPage]);
38
+ return react_1.default.useMemo(() => ({
39
+ pagesToShow,
40
+ hasNextPage,
41
+ buildPagePath,
42
+ handleNextPage,
43
+ hasPreviousPage,
44
+ actualCurrentPage,
45
+ handlePreviousPage,
46
+ }), [
47
+ pagesToShow,
48
+ hasNextPage,
49
+ buildPagePath,
50
+ handleNextPage,
51
+ hasPreviousPage,
52
+ actualCurrentPage,
53
+ handlePreviousPage,
54
+ ]);
55
+ };
56
+ exports.usePages = usePages;
57
+ // get a list of pages to display buttons for
58
+ // @todo this is super hacky and needs to be cleaned up
59
+ const getPages = (pages, totalPages, currentPage) => {
60
+ const pagesToShow = pages > totalPages ? totalPages : pages;
61
+ const buffer = Math.floor(pagesToShow / 2);
62
+ let list = [];
63
+ let start = 0;
64
+ if (totalPages <= 5 || currentPage < buffer + 1) {
65
+ start = 0;
66
+ }
67
+ else {
68
+ if (totalPages - buffer <= currentPage) {
69
+ start =
70
+ currentPage + 1 === totalPages
71
+ ? currentPage - (pagesToShow - 1)
72
+ : currentPage - (buffer + buffer / 2);
73
+ }
74
+ else {
75
+ start = currentPage - buffer;
76
+ }
77
+ }
78
+ Array.apply(null, Array(pagesToShow)).map((item, index) => {
79
+ list.push(start + index);
80
+ });
81
+ return list;
82
+ };
@@ -0,0 +1,12 @@
1
+ import currency from "currency.js";
2
+ import { Product } from "../types";
3
+ declare type PriceResponse = {
4
+ onSale: boolean;
5
+ price?: currency;
6
+ currencyCode: string;
7
+ formattedPrice?: string;
8
+ compareAtPrice?: currency;
9
+ formattedCompareAtPrice?: string;
10
+ };
11
+ export declare const useProductPrice: (product: Product) => PriceResponse;
12
+ export {};
@@ -0,0 +1,61 @@
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.useProductPrice = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const currency_js_1 = __importDefault(require("currency.js"));
9
+ const useProductPrice = (product) => react_1.default.useMemo(() => {
10
+ var _a, _b, _c, _d;
11
+ const variant = (_a = product.variants) === null || _a === void 0 ? void 0 : _a[0];
12
+ if (!variant) {
13
+ return {
14
+ onSale: false,
15
+ price: undefined,
16
+ currencyCode: "AUD",
17
+ compareAtPrice: undefined,
18
+ };
19
+ }
20
+ // @todo select the appropriate currency
21
+ const priceSet = (_b = variant.presentment_prices) === null || _b === void 0 ? void 0 : _b[0];
22
+ if (!priceSet || !priceSet.price) {
23
+ return {
24
+ onSale: false,
25
+ price: undefined,
26
+ currencyCode: "AUD",
27
+ compareAtPrice: undefined,
28
+ };
29
+ }
30
+ const currencyCode = (_c = priceSet.price.currency_code) !== null && _c !== void 0 ? _c : "AUD";
31
+ const price = priceSet.price.amount
32
+ ? (0, currency_js_1.default)(priceSet.price.amount)
33
+ : undefined;
34
+ const formattedPrice = price ? formatPrice(price, currencyCode) : undefined;
35
+ const compareAtPrice = ((_d = priceSet.compare_at_price) === null || _d === void 0 ? void 0 : _d.amount)
36
+ ? (0, currency_js_1.default)(priceSet.compare_at_price.amount)
37
+ : undefined;
38
+ const formattedCompareAtPrice = compareAtPrice
39
+ ? formatPrice(compareAtPrice, currencyCode)
40
+ : undefined;
41
+ const onSale = !!compareAtPrice && !!price && compareAtPrice.intValue > price.intValue;
42
+ return {
43
+ price,
44
+ onSale,
45
+ currencyCode,
46
+ compareAtPrice,
47
+ formattedPrice,
48
+ formattedCompareAtPrice,
49
+ };
50
+ }, [product]);
51
+ exports.useProductPrice = useProductPrice;
52
+ const formatPrice = (price, currencyCode) => {
53
+ let priceString = new Intl.NumberFormat("en-AU", {
54
+ style: "currency",
55
+ currency: currencyCode,
56
+ }).format(price.value);
57
+ if ("AUD" === currencyCode) {
58
+ priceString = `AU ${priceString}`;
59
+ }
60
+ return priceString;
61
+ };
@@ -0,0 +1,8 @@
1
+ export declare const useSearch: () => {
2
+ searchQuery: string | undefined;
3
+ submitSearch: (localSearchQuery?: string | undefined) => void;
4
+ instantSearch: boolean;
5
+ setSearchQuery: (searchQuery: string) => void;
6
+ showInstantSearchResults: boolean;
7
+ setShowInstantSearchResults: (showInstantSearchResults: boolean) => void;
8
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSearch = void 0;
4
+ const provider_1 = require("../provider");
5
+ const useSearch = () => {
6
+ const { searchQuery, submitSearch, setSearchQuery, instantSearch, showInstantSearchResults, setShowInstantSearchResults, } = (0, provider_1.useContext)();
7
+ return {
8
+ searchQuery,
9
+ submitSearch,
10
+ instantSearch,
11
+ setSearchQuery,
12
+ showInstantSearchResults,
13
+ setShowInstantSearchResults,
14
+ };
15
+ };
16
+ exports.useSearch = useSearch;
@@ -0,0 +1,5 @@
1
+ export declare const useSort: () => {
2
+ sortOption: import("..").ConfigSort;
3
+ sortOptions: import("..").ConfigSort[];
4
+ setSortOption: (sortOptionId: string) => void;
5
+ };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSort = void 0;
4
+ const provider_1 = require("../provider");
5
+ const useSort = () => {
6
+ const { sortOption, sortOptions, setSortOption } = (0, provider_1.useContext)();
7
+ return { sortOption, sortOptions, setSortOption };
8
+ };
9
+ exports.useSort = useSort;
@@ -0,0 +1,7 @@
1
+ export * from "./types";
2
+ export * from "./hooks";
3
+ export * from "./filter";
4
+ export * from "./sensor";
5
+ export * from "./result";
6
+ export * from "./search";
7
+ export * from "./provider";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./types"), exports);
14
+ __exportStar(require("./hooks"), exports);
15
+ __exportStar(require("./filter"), exports);
16
+ __exportStar(require("./sensor"), exports);
17
+ __exportStar(require("./result"), exports);
18
+ __exportStar(require("./search"), exports);
19
+ __exportStar(require("./provider"), exports);
@@ -0,0 +1,44 @@
1
+ import React from "react";
2
+ import type { Collection, Config, ConfigSort, ConfigFilter, ConfigCuration, ConfigCredentials, ConfigTheme } from "./types";
3
+ declare type Context = {
4
+ index: string;
5
+ config: Config;
6
+ shopName: string;
7
+ sortOption: ConfigSort;
8
+ sortOptions: ConfigSort[];
9
+ searchQuery?: string;
10
+ filterStack?: ConfigFilter;
11
+ collection?: Collection;
12
+ instantSearch: boolean;
13
+ credentials: ConfigCredentials;
14
+ submitSearch: (localSearchQuery?: string) => void;
15
+ setSearchQuery: (searchQuery: string) => void;
16
+ setSortOption: (sortOptionId: string) => void;
17
+ showInstantSearchResults: boolean;
18
+ setShowInstantSearchResults: (showInstantSearchResults: boolean) => void;
19
+ theme?: ConfigTheme;
20
+ curation?: ConfigCuration;
21
+ /** Array of additional component IDs managed outside of Reactify Search */
22
+ additionalComponentIds?: string[];
23
+ /** Enable the new callouts feature */
24
+ enableCallouts?: boolean;
25
+ };
26
+ declare const Context: React.Context<Context | undefined>;
27
+ declare type Props = {
28
+ index: string;
29
+ config: Config;
30
+ shopName: string;
31
+ filterStackId?: string;
32
+ collection?: Collection;
33
+ noReactiveBase?: boolean;
34
+ instantSearch?: boolean;
35
+ credentials?: ConfigCredentials;
36
+ theme?: ConfigTheme;
37
+ /** Array of additional component IDs managed outside of Reactify Search */
38
+ additionalComponentIds?: string[];
39
+ /** Enable the new callouts feature */
40
+ enableCallouts?: boolean;
41
+ };
42
+ export declare const Provider: React.FC<Props>;
43
+ export declare const useContext: () => Context;
44
+ export {};