@tapcart/mobile-components 0.6.6 → 0.6.7
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/dist/components/ThemeProvider.d.ts +3 -0
- package/dist/components/ThemeProvider.d.ts.map +1 -0
- package/dist/components/ThemeProvider.js +18 -0
- package/dist/components/ThemeToggle.d.ts +2 -0
- package/dist/components/ThemeToggle.d.ts.map +1 -0
- package/dist/components/ThemeToggle.js +8 -0
- package/dist/components/hooks/use-sort-filter.d.ts +26 -0
- package/dist/components/hooks/use-sort-filter.d.ts.map +1 -0
- package/dist/components/hooks/use-sort-filter.js +31 -0
- package/dist/components/libs/sort-filter/beyond-search.d.ts +15 -0
- package/dist/components/libs/sort-filter/beyond-search.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/beyond-search.js +78 -0
- package/dist/components/libs/sort-filter/kmp.d.ts +15 -0
- package/dist/components/libs/sort-filter/kmp.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/kmp.js +55 -0
- package/dist/components/libs/sort-filter/nosto-search.d.ts +9 -0
- package/dist/components/libs/sort-filter/nosto-search.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/nosto-search.js +8 -0
- package/dist/components/libs/sort-filter/search-integration.d.ts +50 -0
- package/dist/components/libs/sort-filter/search-integration.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/search-integration.js +38 -0
- package/dist/components/libs/sort-filter/search-spring.d.ts +9 -0
- package/dist/components/libs/sort-filter/search-spring.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/search-spring.js +8 -0
- package/dist/components/libs/sort-filter/shopify-search-and-discovery.d.ts +64 -0
- package/dist/components/libs/sort-filter/shopify-search-and-discovery.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/shopify-search-and-discovery.js +172 -0
- package/dist/components/ui/empty-message.d.ts.map +1 -1
- package/dist/components/ui/empty-message.js +47 -1
- package/dist/components/ui/input.d.ts +17 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +35 -0
- package/dist/components/ui/product-grid.d.ts +15 -0
- package/dist/components/ui/product-grid.d.ts.map +1 -0
- package/dist/components/ui/product-grid.js +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/styles.css +17 -0
- package/package.json +1 -1
- package/dist/components/hooks/use-click-outside.d.ts +0 -8
- package/dist/components/hooks/use-click-outside.d.ts.map +0 -1
- package/dist/components/hooks/use-click-outside.js +0 -46
- package/dist/components/hooks/use-pull-to-refresh.d.ts +0 -9
- package/dist/components/hooks/use-pull-to-refresh.d.ts.map +0 -1
- package/dist/components/hooks/use-pull-to-refresh.js +0 -88
- package/dist/components/ui/favorite/favorite.d.ts +0 -16
- package/dist/components/ui/favorite/favorite.d.ts.map +0 -1
- package/dist/components/ui/favorite/favorite.js +0 -156
- package/dist/components/ui/favorite/favorite.spec.d.ts +0 -2
- package/dist/components/ui/favorite/favorite.spec.d.ts.map +0 -1
- package/dist/components/ui/favorite/favorite.spec.js +0 -6
- package/dist/components/ui/favorite/index.d.ts +0 -2
- package/dist/components/ui/favorite/index.d.ts.map +0 -1
- package/dist/components/ui/favorite/index.js +0 -1
- package/dist/components/ui/select.d.ts +0 -39
- package/dist/components/ui/select.d.ts.map +0 -1
- package/dist/components/ui/select.js +0 -87
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../components/ThemeProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,kBAAkB,2CAEvE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { ThemeProvider as NextThemesProvider } from "next-themes";
|
|
15
|
+
export function ThemeProvider(_a) {
|
|
16
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
17
|
+
return _jsx(NextThemesProvider, Object.assign({}, props, { children: children }));
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeToggle.d.ts","sourceRoot":"","sources":["../../components/ThemeToggle.tsx"],"names":[],"mappings":"AAOA,wBAAgB,WAAW,4CAc1B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useTheme } from "next-themes";
|
|
4
|
+
import { Button } from "../components/ui/button";
|
|
5
|
+
export function ThemeToggle() {
|
|
6
|
+
const { setTheme, theme } = useTheme();
|
|
7
|
+
return (_jsxs(Button, Object.assign({ variant: "ghost", size: "sm", onClick: () => setTheme(theme === "light" ? "dark" : "light") }, { children: [_jsx("div", { className: "rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" }), _jsx("div", { className: "absolute rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" }), _jsx("span", Object.assign({ className: "sr-only" }, { children: "Toggle theme" }))] })));
|
|
8
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Collection } from "app-studio-types";
|
|
2
|
+
import { FilterCategory, Integration, IntegrationSortItem } from "../libs/sort-filter/search-integration";
|
|
3
|
+
interface UseSortFilterProps {
|
|
4
|
+
initialData: PageData;
|
|
5
|
+
queryVariables: Record<string, any>;
|
|
6
|
+
}
|
|
7
|
+
interface PageData {
|
|
8
|
+
filtersURL: string;
|
|
9
|
+
sortFilterURL: string;
|
|
10
|
+
}
|
|
11
|
+
interface UseSortFilterReturn {
|
|
12
|
+
sortFilterData: SortFilterData;
|
|
13
|
+
data: any[];
|
|
14
|
+
mutate: () => Promise<any>;
|
|
15
|
+
isLoading: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface SortFilterData {
|
|
18
|
+
collection: Collection;
|
|
19
|
+
filtersAndRelatedCategories: FilterCategory[];
|
|
20
|
+
sortOptions: IntegrationSortItem[];
|
|
21
|
+
dynamicFiltersEnabled: boolean;
|
|
22
|
+
integrations: Integration[];
|
|
23
|
+
}
|
|
24
|
+
declare const useSortFilter: ({ initialData, queryVariables, }: UseSortFilterProps) => UseSortFilterReturn;
|
|
25
|
+
export { useSortFilter };
|
|
26
|
+
//# sourceMappingURL=use-sort-filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-sort-filter.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-sort-filter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,mBAAmB,EAAqB,MAAM,wCAAwC,CAAA;AAG5H,UAAU,kBAAkB;IAC1B,WAAW,EAAE,QAAQ,CAAA;IACrB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACpC;AAED,UAAU,QAAQ;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,UAAU,mBAAmB;IAC3B,cAAc,EAAE,cAAc,CAAC;IAC/B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,MAAM,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,cAAc;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,2BAA2B,EAAE,cAAc,EAAE,CAAA;IAC7C,WAAW,EAAE,mBAAmB,EAAE,CAAA;IAClC,qBAAqB,EAAE,OAAO,CAAA;IAC9B,YAAY,EAAE,WAAW,EAAE,CAAA;CAC5B;AAaD,QAAA,MAAM,aAAa,qCAGhB,kBAAkB,KAAG,mBAiCvB,CAAA;AAED,OAAO,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWRInfinite from "swr/infinite";
|
|
3
|
+
import useSWR from "swr";
|
|
4
|
+
const constructURL = (apiURL) => {
|
|
5
|
+
const url = new URL(apiURL);
|
|
6
|
+
return url.toString();
|
|
7
|
+
};
|
|
8
|
+
const fetcher = ({ apiURL, body }) => fetch(constructURL(apiURL), {
|
|
9
|
+
method: "POST",
|
|
10
|
+
body: JSON.stringify(body),
|
|
11
|
+
}).then((res) => res.json());
|
|
12
|
+
const useSortFilter = ({ initialData, queryVariables, }) => {
|
|
13
|
+
const shouldFetch = queryVariables && Object.keys(queryVariables).length > 0;
|
|
14
|
+
const { data: sortFilterData, isLoading } = useSWR(shouldFetch ? { apiUrl: initialData.sortFilterURL, body: Object.assign({}, queryVariables) } : null, ({ apiUrl, body }) => fetcher({ apiURL: apiUrl, body }));
|
|
15
|
+
const getKey = () => {
|
|
16
|
+
if (!sortFilterData || !sortFilterData.dynamicFiltersEnabled)
|
|
17
|
+
return null;
|
|
18
|
+
return Object.assign(Object.assign(Object.assign({}, queryVariables), (sortFilterData.searchQuery && { searchQuery: sortFilterData.searchQuery })), { filterCategories: sortFilterData === null || sortFilterData === void 0 ? void 0 : sortFilterData.filtersAndRelatedCategories.filterCategories, sortOption: sortFilterData === null || sortFilterData === void 0 ? void 0 : sortFilterData.sortOption, limit: 10 });
|
|
19
|
+
};
|
|
20
|
+
const { data, mutate } = useSWRInfinite(getKey, (body) => fetcher({ apiURL: initialData.filtersURL, body }), {
|
|
21
|
+
revalidateFirstPage: true,
|
|
22
|
+
initialSize: 1,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
sortFilterData,
|
|
26
|
+
data: data !== null && data !== void 0 ? data : [],
|
|
27
|
+
mutate,
|
|
28
|
+
isLoading,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export { useSortFilter };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FilterCategory, IntegrationSortItem, SearchIntegration } from "./search-integration";
|
|
2
|
+
import { ReadonlyURLSearchParams } from "next/navigation";
|
|
3
|
+
export declare class BeyondSearch implements SearchIntegration {
|
|
4
|
+
getSortSearchParamKey: () => string;
|
|
5
|
+
convertFilterCategoriesToSearchParams: (filters: FilterCategory[], searchParams: ReadonlyURLSearchParams) => string;
|
|
6
|
+
convertSortToSearchParams({ sortOption, existingParams, }: {
|
|
7
|
+
sortOption: IntegrationSortItem | undefined;
|
|
8
|
+
existingParams: ReadonlyURLSearchParams;
|
|
9
|
+
}): URLSearchParams;
|
|
10
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }: {
|
|
11
|
+
searchParams: ReadonlyURLSearchParams;
|
|
12
|
+
sortOptions: IntegrationSortItem[];
|
|
13
|
+
}): IntegrationSortItem | null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=beyond-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"beyond-search.d.ts","sourceRoot":"","sources":["../../../../components/libs/sort-filter/beyond-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,cAAc,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACrG,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,qBAAa,YAAa,YAAW,iBAAiB;IAEpD,qBAAqB,QAAO,MAAM,CAEjC;IAED,qCAAqC,YAC1B,cAAc,EAAE,gBACX,uBAAuB,KACpC,MAAM,CAoDR;IAED,yBAAyB,CAAC,EACxB,UAAU,EACV,cAAc,GACf,EAAE;QACD,UAAU,EAAE,mBAAmB,GAAG,SAAS,CAAA;QAC3C,cAAc,EAAE,uBAAuB,CAAA;KACxC,GAAG,eAAe;IAcnB,6BAA6B,CAAC,EAC5B,YAAY,EACZ,WAAW,GACZ,EAAE;QACD,YAAY,EAAE,uBAAuB,CAAA;QACrC,WAAW,EAAE,mBAAmB,EAAE,CAAA;KACnC,GAAG,mBAAmB,GAAG,IAAI;CAI/B"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export class BeyondSearch {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.getSortSearchParamKey = () => {
|
|
4
|
+
return "selectedSort";
|
|
5
|
+
};
|
|
6
|
+
this.convertFilterCategoriesToSearchParams = (filters, searchParams) => {
|
|
7
|
+
const filtersToApply = filters
|
|
8
|
+
.flatMap((category) => {
|
|
9
|
+
var _a;
|
|
10
|
+
let key = (_a = category.id) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
11
|
+
let values = [];
|
|
12
|
+
if (key == "price") {
|
|
13
|
+
values = category.filters
|
|
14
|
+
.filter((filter) => filter.isSelected)
|
|
15
|
+
.map((filter) => {
|
|
16
|
+
var _a;
|
|
17
|
+
return `(${filter.min},${(_a = filter.max) !== null && _a !== void 0 ? _a : 10000})`;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else if (key == "rating") {
|
|
21
|
+
values = category.filters
|
|
22
|
+
.filter((filter) => filter.isSelected)
|
|
23
|
+
.map((filter) => {
|
|
24
|
+
return `${filter.min}`;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
values = category.filters
|
|
29
|
+
.filter((filter) => filter.isSelected)
|
|
30
|
+
.map((filter) => {
|
|
31
|
+
return filter.tag;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (values.length) {
|
|
35
|
+
return `${key}=${JSON.stringify(values)}`;
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
.filter((it) => it !== undefined);
|
|
39
|
+
const filterKeysToRemove = filters.flatMap((it) => { var _a; return (_a = it.id) === null || _a === void 0 ? void 0 : _a.toLowerCase(); });
|
|
40
|
+
const oldParams = new URLSearchParams(searchParams.toString());
|
|
41
|
+
const newParams = new URLSearchParams();
|
|
42
|
+
//remove old filters
|
|
43
|
+
oldParams.forEach((value, key) => {
|
|
44
|
+
if (!filterKeysToRemove.some((it) => it == key)) {
|
|
45
|
+
newParams.append(key, value);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
//build new filters
|
|
49
|
+
filtersToApply.forEach((param) => {
|
|
50
|
+
if (param) {
|
|
51
|
+
const [key, value] = param.split("=");
|
|
52
|
+
if (key && value) {
|
|
53
|
+
newParams.append(key, value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return newParams.toString();
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
convertSortToSearchParams({ sortOption, existingParams, }) {
|
|
61
|
+
const input = sortOption.sortType;
|
|
62
|
+
const newParams = new URLSearchParams();
|
|
63
|
+
existingParams.forEach((value, key) => {
|
|
64
|
+
if (!key.startsWith(this.getSortSearchParamKey())) {
|
|
65
|
+
newParams.append(key, value);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (input && input.length) {
|
|
69
|
+
newParams.append(this.getSortSearchParamKey(), input);
|
|
70
|
+
}
|
|
71
|
+
return newParams;
|
|
72
|
+
}
|
|
73
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }) {
|
|
74
|
+
var _a;
|
|
75
|
+
const name = searchParams.get(this.getSortSearchParamKey());
|
|
76
|
+
return (_a = sortOptions.find((it) => (it === null || it === void 0 ? void 0 : it.sortType) == name)) !== null && _a !== void 0 ? _a : null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FilterCategory, SearchIntegration, IntegrationSortItem } from "./search-integration";
|
|
2
|
+
import { ReadonlyURLSearchParams } from "next/navigation";
|
|
3
|
+
export declare class KMP implements SearchIntegration {
|
|
4
|
+
getSortSearchParamKey: () => string;
|
|
5
|
+
convertFilterCategoriesToSearchParams: (filters: FilterCategory[], searchParams: ReadonlyURLSearchParams) => string;
|
|
6
|
+
convertSortToSearchParams({ sortOption, existingParams, }: {
|
|
7
|
+
sortOption: IntegrationSortItem | undefined;
|
|
8
|
+
existingParams: ReadonlyURLSearchParams;
|
|
9
|
+
}): URLSearchParams;
|
|
10
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }: {
|
|
11
|
+
searchParams: ReadonlyURLSearchParams;
|
|
12
|
+
sortOptions: IntegrationSortItem[];
|
|
13
|
+
}): IntegrationSortItem | null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=kmp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kmp.d.ts","sourceRoot":"","sources":["../../../../components/libs/sort-filter/kmp.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAGzD,qBAAa,GAAI,YAAW,iBAAiB;IAG3C,qBAAqB,QAAO,MAAM,CAEjC;IAED,qCAAqC,YAC1B,cAAc,EAAE,gBACX,uBAAuB,KACpC,MAAM,CA4BR;IAED,yBAAyB,CAAC,EACxB,UAAU,EACV,cAAc,GACf,EAAE;QACD,UAAU,EAAE,mBAAmB,GAAG,SAAS,CAAA;QAC3C,cAAc,EAAE,uBAAuB,CAAA;KACxC,GAAG,eAAe;IAcnB,6BAA6B,CAAC,EAC5B,YAAY,EACZ,WAAW,GACZ,EAAE;QACD,YAAY,EAAE,uBAAuB,CAAA;QACrC,WAAW,EAAE,mBAAmB,EAAE,CAAA;KACnC,GAAG,mBAAmB,GAAG,IAAI;CAS/B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export class KMP {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.getSortSearchParamKey = () => {
|
|
4
|
+
return "sort_by";
|
|
5
|
+
};
|
|
6
|
+
this.convertFilterCategoriesToSearchParams = (filters, searchParams) => {
|
|
7
|
+
const filtersToApply = filters.reduce((acc, it) => {
|
|
8
|
+
const inner = it.filters.reduce((innerAcc, f) => {
|
|
9
|
+
if (f.isSelected) {
|
|
10
|
+
innerAcc.push(`${it.title}-${f.tag}`);
|
|
11
|
+
}
|
|
12
|
+
return innerAcc;
|
|
13
|
+
}, []);
|
|
14
|
+
return acc.concat(inner);
|
|
15
|
+
}, []);
|
|
16
|
+
const oldParams = new URLSearchParams(searchParams.toString());
|
|
17
|
+
const newParams = new URLSearchParams();
|
|
18
|
+
//remove old filters
|
|
19
|
+
oldParams.forEach((value, key) => {
|
|
20
|
+
if (!key.startsWith("filter")) {
|
|
21
|
+
newParams.append(key, value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
//build new filters
|
|
25
|
+
if (filtersToApply.length) {
|
|
26
|
+
newParams.append("filter", JSON.stringify(filtersToApply));
|
|
27
|
+
}
|
|
28
|
+
return newParams.toString();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
convertSortToSearchParams({ sortOption, existingParams, }) {
|
|
32
|
+
const input = JSON.stringify(sortOption);
|
|
33
|
+
const newParams = new URLSearchParams();
|
|
34
|
+
existingParams.forEach((value, key) => {
|
|
35
|
+
if (!key.startsWith(this.getSortSearchParamKey())) {
|
|
36
|
+
newParams.append(key, value);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
if (input && input.length) {
|
|
40
|
+
newParams.append(this.getSortSearchParamKey(), input);
|
|
41
|
+
}
|
|
42
|
+
return newParams;
|
|
43
|
+
}
|
|
44
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }) {
|
|
45
|
+
var _a;
|
|
46
|
+
const json = searchParams.get(this.getSortSearchParamKey());
|
|
47
|
+
try {
|
|
48
|
+
const option = JSON.parse(json !== null && json !== void 0 ? json : "{}");
|
|
49
|
+
return (_a = sortOptions.find((it) => (it === null || it === void 0 ? void 0 : it.sortName) == option.sortName)) !== null && _a !== void 0 ? _a : null;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KMP } from "./kmp";
|
|
2
|
+
import { Integration } from "./search-integration";
|
|
3
|
+
export declare class NostoSearch extends KMP {
|
|
4
|
+
private readonly sendFirstSort;
|
|
5
|
+
constructor({ integration }: {
|
|
6
|
+
integration: Integration | undefined;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=nosto-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nosto-search.d.ts","sourceRoot":"","sources":["../../../../components/libs/sort-filter/nosto-search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,WAAY,SAAQ,GAAG;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE;CAItE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KMP } from "./kmp";
|
|
2
|
+
export class NostoSearch extends KMP {
|
|
3
|
+
constructor({ integration }) {
|
|
4
|
+
var _a;
|
|
5
|
+
super();
|
|
6
|
+
this.sendFirstSort = (_a = integration === null || integration === void 0 ? void 0 : integration.sendFirstSort) !== null && _a !== void 0 ? _a : false;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ReadonlyURLSearchParams } from "next/navigation";
|
|
2
|
+
export type Integration = {
|
|
3
|
+
name: string;
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
key?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
export type IntegrationSortItem = {
|
|
10
|
+
type: string;
|
|
11
|
+
name: string;
|
|
12
|
+
sortName: string;
|
|
13
|
+
sortKey: string;
|
|
14
|
+
isReverse: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type Filter = {
|
|
17
|
+
title: string;
|
|
18
|
+
image?: string | null;
|
|
19
|
+
tag: any;
|
|
20
|
+
amount?: number | null;
|
|
21
|
+
isSelected: boolean;
|
|
22
|
+
collectionId?: string | null;
|
|
23
|
+
min: number | null;
|
|
24
|
+
max: number | null;
|
|
25
|
+
};
|
|
26
|
+
export type FilterCategory = {
|
|
27
|
+
title: string;
|
|
28
|
+
type: string;
|
|
29
|
+
filters: Filter[];
|
|
30
|
+
field?: string | null;
|
|
31
|
+
id: string | null;
|
|
32
|
+
multiSelect?: boolean | undefined;
|
|
33
|
+
};
|
|
34
|
+
export interface SearchIntegration {
|
|
35
|
+
getSortSearchParamKey(): string;
|
|
36
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }: {
|
|
37
|
+
searchParams: ReadonlyURLSearchParams;
|
|
38
|
+
sortOptions: IntegrationSortItem[];
|
|
39
|
+
}): IntegrationSortItem | null;
|
|
40
|
+
convertSortToSearchParams({ sortOption, existingParams, }: {
|
|
41
|
+
sortOption: IntegrationSortItem | undefined;
|
|
42
|
+
existingParams: ReadonlyURLSearchParams;
|
|
43
|
+
}): URLSearchParams;
|
|
44
|
+
convertFilterCategoriesToSearchParams(filters: FilterCategory[], searchParams: ReadonlyURLSearchParams): string;
|
|
45
|
+
}
|
|
46
|
+
export declare const createIntegrationLookup: (integrations: Integration[]) => Record<string, Integration>;
|
|
47
|
+
export declare const isSearchProvider: (integrationLookup: Record<string, Integration>, searchIntegrationNames: string[]) => boolean;
|
|
48
|
+
export declare const searchIntegrationProvider: (integrations: Integration[]) => SearchIntegration;
|
|
49
|
+
export declare const isDynamicFiltersSupported: (searchIntegration: SearchIntegration | null) => boolean;
|
|
50
|
+
//# sourceMappingURL=search-integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-integration.d.ts","sourceRoot":"","sources":["../../../../components/libs/sort-filter/search-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAOzD,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IACjB,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAClC,CAAA;AAED,MAAM,WAAW,iBAAiB;IAIhC,qBAAqB,IAAI,MAAM,CAAA;IAE/B,6BAA6B,CAAC,EAC5B,YAAY,EACZ,WAAW,GACZ,EAAE;QACD,YAAY,EAAE,uBAAuB,CAAA;QACrC,WAAW,EAAE,mBAAmB,EAAE,CAAA;KACnC,GAAG,mBAAmB,GAAG,IAAI,CAAA;IAK9B,yBAAyB,CAAC,EACxB,UAAU,EACV,cAAc,GACf,EAAE;QACD,UAAU,EAAE,mBAAmB,GAAG,SAAS,CAAA;QAC3C,cAAc,EAAE,uBAAuB,CAAA;KACxC,GAAG,eAAe,CAAA;IAKnB,qCAAqC,CACnC,OAAO,EAAE,cAAc,EAAE,EACzB,YAAY,EAAE,uBAAuB,GACpC,MAAM,CAAA;CACV;AAED,eAAO,MAAM,uBAAuB,iBAAkB,WAAW,EAAE,gCAKlE,CAAC;AAEF,eAAO,MAAM,gBAAgB,sBACR,OAAO,MAAM,EAAE,WAAW,CAAC,0BACtB,MAAM,EAAE,KAC/B,OAIF,CAAC;AAEF,eAAO,MAAM,yBAAyB,iBACtB,WAAW,EAAE,KAC1B,iBA2BF,CAAA;AAED,eAAO,MAAM,yBAAyB,sBACjB,iBAAiB,GAAG,IAAI,YACc,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { KMP } from "./kmp";
|
|
2
|
+
import { BeyondSearch } from "./beyond-search";
|
|
3
|
+
import { SearchSpring } from "./search-spring";
|
|
4
|
+
import { NostoSearch } from "./nosto-search";
|
|
5
|
+
import { ShopifySearchAndDiscovery } from "./shopify-search-and-discovery";
|
|
6
|
+
export const createIntegrationLookup = (integrations) => {
|
|
7
|
+
return integrations.reduce((lookup, integration) => {
|
|
8
|
+
lookup[integration.name] = integration;
|
|
9
|
+
return lookup;
|
|
10
|
+
}, {});
|
|
11
|
+
};
|
|
12
|
+
export const isSearchProvider = (integrationLookup, searchIntegrationNames) => {
|
|
13
|
+
return searchIntegrationNames.some((name) => { var _a; return (_a = integrationLookup[name]) === null || _a === void 0 ? void 0 : _a.enabled; });
|
|
14
|
+
};
|
|
15
|
+
export const searchIntegrationProvider = (integrations) => {
|
|
16
|
+
const integrationLookup = createIntegrationLookup(integrations);
|
|
17
|
+
switch (true) {
|
|
18
|
+
case isSearchProvider(integrationLookup, ["beyond-search"]):
|
|
19
|
+
return new BeyondSearch();
|
|
20
|
+
case isSearchProvider(integrationLookup, ["search-spring"]):
|
|
21
|
+
return new SearchSpring({
|
|
22
|
+
integration: integrationLookup["search-spring"],
|
|
23
|
+
});
|
|
24
|
+
case isSearchProvider(integrationLookup, ["nosto-search"]):
|
|
25
|
+
return new NostoSearch({
|
|
26
|
+
integration: integrationLookup["nosto-search"],
|
|
27
|
+
});
|
|
28
|
+
case isSearchProvider(integrationLookup, [
|
|
29
|
+
"algolia",
|
|
30
|
+
"instant-search-plus",
|
|
31
|
+
"searchanise",
|
|
32
|
+
]):
|
|
33
|
+
return new KMP();
|
|
34
|
+
default:
|
|
35
|
+
return new ShopifySearchAndDiscovery();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const isDynamicFiltersSupported = (searchIntegration) => searchIntegration instanceof ShopifySearchAndDiscovery;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KMP } from "./kmp";
|
|
2
|
+
import { Integration } from "./search-integration";
|
|
3
|
+
export declare class SearchSpring extends KMP {
|
|
4
|
+
private readonly sendFirstSort;
|
|
5
|
+
constructor({ integration }: {
|
|
6
|
+
integration: Integration | undefined;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=search-spring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-spring.d.ts","sourceRoot":"","sources":["../../../../components/libs/sort-filter/search-spring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD,qBAAa,YAAa,SAAQ,GAAG;IACnC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE;CAItE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KMP } from "./kmp";
|
|
2
|
+
export class SearchSpring extends KMP {
|
|
3
|
+
constructor({ integration }) {
|
|
4
|
+
var _a;
|
|
5
|
+
super();
|
|
6
|
+
this.sendFirstSort = (_a = integration === null || integration === void 0 ? void 0 : integration.sendFirstSort) !== null && _a !== void 0 ? _a : false;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { FilterCategory, IntegrationSortItem, SearchIntegration } from "./search-integration";
|
|
2
|
+
import { ReadonlyURLSearchParams } from "next/navigation";
|
|
3
|
+
export declare class ShopifySearchAndDiscovery implements SearchIntegration {
|
|
4
|
+
private collectionSortOptions;
|
|
5
|
+
getSortSearchParamKey: () => string;
|
|
6
|
+
convertFilterCategoriesToSearchParams: (filters: FilterCategory[], searchParams: ReadonlyURLSearchParams) => string;
|
|
7
|
+
convertSortToSearchParams({ sortOption, existingParams, }: {
|
|
8
|
+
sortOption: IntegrationSortItem | undefined;
|
|
9
|
+
existingParams: ReadonlyURLSearchParams;
|
|
10
|
+
}): URLSearchParams;
|
|
11
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }: {
|
|
12
|
+
searchParams: ReadonlyURLSearchParams;
|
|
13
|
+
sortOptions: IntegrationSortItem[];
|
|
14
|
+
}): IntegrationSortItem | null;
|
|
15
|
+
}
|
|
16
|
+
export declare enum SearchSortKeys {
|
|
17
|
+
/**
|
|
18
|
+
* Sort by the price value.
|
|
19
|
+
*/
|
|
20
|
+
PRICE = "PRICE",
|
|
21
|
+
RELEVANCE = "RELEVANCE"
|
|
22
|
+
}
|
|
23
|
+
export declare enum SearchUnavailableProductsType {
|
|
24
|
+
SHOW = "SHOW",
|
|
25
|
+
HIDE = "HIDE"
|
|
26
|
+
}
|
|
27
|
+
export declare enum ProductCollectionSortKeys {
|
|
28
|
+
/**
|
|
29
|
+
* Sort by the `title` value.
|
|
30
|
+
*/
|
|
31
|
+
TITLE = "TITLE",
|
|
32
|
+
/**
|
|
33
|
+
* Sort by the `price` value.
|
|
34
|
+
*/
|
|
35
|
+
PRICE = "PRICE",
|
|
36
|
+
/**
|
|
37
|
+
* Sort by the `best-selling` value.
|
|
38
|
+
*/
|
|
39
|
+
BEST_SELLING = "BEST_SELLING",
|
|
40
|
+
/**
|
|
41
|
+
* Sort by the `created` value.
|
|
42
|
+
*/
|
|
43
|
+
CREATED = "CREATED",
|
|
44
|
+
/**
|
|
45
|
+
* Sort by the `id` value.
|
|
46
|
+
*/
|
|
47
|
+
ID = "ID",
|
|
48
|
+
/**
|
|
49
|
+
* Sort by the `manual` value.
|
|
50
|
+
*/
|
|
51
|
+
MANUAL = "MANUAL",
|
|
52
|
+
/**
|
|
53
|
+
* Sort by the `collection-default` value.
|
|
54
|
+
*/
|
|
55
|
+
COLLECTION_DEFAULT = "COLLECTION_DEFAULT",
|
|
56
|
+
/**
|
|
57
|
+
* During a search (i.e. when the `query` parameter has been specified on the connection) this sorts the
|
|
58
|
+
* results by relevance to the search term(s). When no search query is specified, this sort key is not
|
|
59
|
+
* deterministic and should not be used.
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
RELEVANCE = "RELEVANCE"
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=shopify-search-and-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shopify-search-and-discovery.d.ts","sourceRoot":"","sources":["../../../../components/libs/sort-filter/shopify-search-and-discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AAEzD,qBAAa,yBAA0B,YAAW,iBAAiB;IAEjE,OAAO,CAAC,qBAAqB,CA+BH;IAE1B,qBAAqB,QAAO,MAAM,CAEjC;IACD,qCAAqC,YAC1B,cAAc,EAAE,gBACX,uBAAuB,KACpC,MAAM,CAmDR;IAED,yBAAyB,CAAC,EACxB,UAAU,EACV,cAAc,GACf,EAAE;QACD,UAAU,EAAE,mBAAmB,GAAG,SAAS,CAAA;QAC3C,cAAc,EAAE,uBAAuB,CAAA;KACxC,GAAG,eAAe;IAgBnB,6BAA6B,CAAC,EAC5B,YAAY,EACZ,WAAW,GACZ,EAAE;QACD,YAAY,EAAE,uBAAuB,CAAA;QACrC,WAAW,EAAE,mBAAmB,EAAE,CAAA;KACnC,GAAG,mBAAmB,GAAG,IAAI;CAO/B;AAED,oBAAY,cAAc;IACxB;;OAEG;IACH,KAAK,UAAU;IAIf,SAAS,cAAc;CACxB;AAED,oBAAY,6BAA6B;IAIvC,IAAI,SAAS;IAKb,IAAI,SAAS;CACd;AAED,oBAAY,yBAAyB;IACnC;;OAEG;IACH,KAAK,UAAU;IAEf;;OAEG;IACH,KAAK,UAAU;IAEf;;OAEG;IACH,YAAY,iBAAiB;IAE7B;;OAEG;IACH,OAAO,YAAY;IAEnB;;OAEG;IACH,EAAE,OAAO;IAET;;OAEG;IACH,MAAM,WAAW;IAEjB;;OAEG;IACH,kBAAkB,uBAAuB;IAEzC;;;;;OAKG;IACH,SAAS,cAAc;CACxB"}
|