@searchspring/snap-store-mobx 0.20.0
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/cjs/Abstract/AbstractStore.d.ts +18 -0
- package/dist/cjs/Abstract/AbstractStore.d.ts.map +1 -0
- package/dist/cjs/Abstract/AbstractStore.js +31 -0
- package/dist/cjs/Autocomplete/AutocompleteStore.d.ts +32 -0
- package/dist/cjs/Autocomplete/AutocompleteStore.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/AutocompleteStore.js +121 -0
- package/dist/cjs/Autocomplete/Stores/FacetStore.d.ts +9 -0
- package/dist/cjs/Autocomplete/Stores/FacetStore.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/Stores/FacetStore.js +69 -0
- package/dist/cjs/Autocomplete/Stores/QueryStore.d.ts +15 -0
- package/dist/cjs/Autocomplete/Stores/QueryStore.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/Stores/QueryStore.js +30 -0
- package/dist/cjs/Autocomplete/Stores/StateStore.d.ts +23 -0
- package/dist/cjs/Autocomplete/Stores/StateStore.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/Stores/StateStore.js +52 -0
- package/dist/cjs/Autocomplete/Stores/TermStore.d.ts +19 -0
- package/dist/cjs/Autocomplete/Stores/TermStore.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/Stores/TermStore.js +86 -0
- package/dist/cjs/Autocomplete/Stores/TrendingStore.d.ts +7 -0
- package/dist/cjs/Autocomplete/Stores/TrendingStore.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/Stores/TrendingStore.js +44 -0
- package/dist/cjs/Autocomplete/Stores/index.d.ts +6 -0
- package/dist/cjs/Autocomplete/Stores/index.d.ts.map +1 -0
- package/dist/cjs/Autocomplete/Stores/index.js +13 -0
- package/dist/cjs/Finder/FinderStore.d.ts +21 -0
- package/dist/cjs/Finder/FinderStore.d.ts.map +1 -0
- package/dist/cjs/Finder/FinderStore.js +56 -0
- package/dist/cjs/Finder/Stores/SelectionStore.d.ts +8 -0
- package/dist/cjs/Finder/Stores/SelectionStore.d.ts.map +1 -0
- package/dist/cjs/Finder/Stores/SelectionStore.js +232 -0
- package/dist/cjs/Finder/Stores/index.d.ts +2 -0
- package/dist/cjs/Finder/Stores/index.d.ts.map +1 -0
- package/dist/cjs/Finder/Stores/index.js +5 -0
- package/dist/cjs/Recommendation/RecommendationStore.d.ts +14 -0
- package/dist/cjs/Recommendation/RecommendationStore.d.ts.map +1 -0
- package/dist/cjs/Recommendation/RecommendationStore.js +51 -0
- package/dist/cjs/Recommendation/Stores/ProfileStore.d.ts +8 -0
- package/dist/cjs/Recommendation/Stores/ProfileStore.d.ts.map +1 -0
- package/dist/cjs/Recommendation/Stores/ProfileStore.js +22 -0
- package/dist/cjs/Recommendation/Stores/index.d.ts +2 -0
- package/dist/cjs/Recommendation/Stores/index.d.ts.map +1 -0
- package/dist/cjs/Recommendation/Stores/index.js +5 -0
- package/dist/cjs/Search/SearchStore.d.ts +26 -0
- package/dist/cjs/Search/SearchStore.d.ts.map +1 -0
- package/dist/cjs/Search/SearchStore.js +61 -0
- package/dist/cjs/Search/Stores/FacetStore.d.ts +8 -0
- package/dist/cjs/Search/Stores/FacetStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/FacetStore.js +317 -0
- package/dist/cjs/Search/Stores/FilterStore.d.ts +7 -0
- package/dist/cjs/Search/Stores/FilterStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/FilterStore.js +100 -0
- package/dist/cjs/Search/Stores/MerchandisingStore.d.ts +20 -0
- package/dist/cjs/Search/Stores/MerchandisingStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/MerchandisingStore.js +59 -0
- package/dist/cjs/Search/Stores/PaginationStore.d.ts +40 -0
- package/dist/cjs/Search/Stores/PaginationStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/PaginationStore.js +190 -0
- package/dist/cjs/Search/Stores/QueryStore.d.ts +16 -0
- package/dist/cjs/Search/Stores/QueryStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/QueryStore.js +34 -0
- package/dist/cjs/Search/Stores/ResultStore.d.ts +7 -0
- package/dist/cjs/Search/Stores/ResultStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/ResultStore.js +156 -0
- package/dist/cjs/Search/Stores/SortingStore.d.ts +21 -0
- package/dist/cjs/Search/Stores/SortingStore.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/SortingStore.js +75 -0
- package/dist/cjs/Search/Stores/index.d.ts +8 -0
- package/dist/cjs/Search/Stores/index.d.ts.map +1 -0
- package/dist/cjs/Search/Stores/index.js +17 -0
- package/dist/cjs/Storage/StorageStore.d.ts +25 -0
- package/dist/cjs/Storage/StorageStore.d.ts.map +1 -0
- package/dist/cjs/Storage/StorageStore.js +130 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/types.d.ts +81 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +9 -0
- package/dist/esm/Abstract/AbstractStore.d.ts +18 -0
- package/dist/esm/Abstract/AbstractStore.d.ts.map +1 -0
- package/dist/esm/Abstract/AbstractStore.js +25 -0
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts +32 -0
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts.map +1 -0
- package/dist/esm/Autocomplete/AutocompleteStore.js +94 -0
- package/dist/esm/Autocomplete/Stores/FacetStore.d.ts +9 -0
- package/dist/esm/Autocomplete/Stores/FacetStore.d.ts.map +1 -0
- package/dist/esm/Autocomplete/Stores/FacetStore.js +29 -0
- package/dist/esm/Autocomplete/Stores/QueryStore.d.ts +15 -0
- package/dist/esm/Autocomplete/Stores/QueryStore.d.ts.map +1 -0
- package/dist/esm/Autocomplete/Stores/QueryStore.js +24 -0
- package/dist/esm/Autocomplete/Stores/StateStore.d.ts +23 -0
- package/dist/esm/Autocomplete/Stores/StateStore.d.ts.map +1 -0
- package/dist/esm/Autocomplete/Stores/StateStore.js +40 -0
- package/dist/esm/Autocomplete/Stores/TermStore.d.ts +19 -0
- package/dist/esm/Autocomplete/Stores/TermStore.d.ts.map +1 -0
- package/dist/esm/Autocomplete/Stores/TermStore.js +42 -0
- package/dist/esm/Autocomplete/Stores/TrendingStore.d.ts +7 -0
- package/dist/esm/Autocomplete/Stores/TrendingStore.d.ts.map +1 -0
- package/dist/esm/Autocomplete/Stores/TrendingStore.js +16 -0
- package/dist/esm/Autocomplete/Stores/index.d.ts +6 -0
- package/dist/esm/Autocomplete/Stores/index.d.ts.map +1 -0
- package/dist/esm/Autocomplete/Stores/index.js +5 -0
- package/dist/esm/Finder/FinderStore.d.ts +21 -0
- package/dist/esm/Finder/FinderStore.d.ts.map +1 -0
- package/dist/esm/Finder/FinderStore.js +33 -0
- package/dist/esm/Finder/Stores/SelectionStore.d.ts +8 -0
- package/dist/esm/Finder/Stores/SelectionStore.d.ts.map +1 -0
- package/dist/esm/Finder/Stores/SelectionStore.js +171 -0
- package/dist/esm/Finder/Stores/index.d.ts +2 -0
- package/dist/esm/Finder/Stores/index.d.ts.map +1 -0
- package/dist/esm/Finder/Stores/index.js +1 -0
- package/dist/esm/Recommendation/RecommendationStore.d.ts +14 -0
- package/dist/esm/Recommendation/RecommendationStore.d.ts.map +1 -0
- package/dist/esm/Recommendation/RecommendationStore.js +28 -0
- package/dist/esm/Recommendation/Stores/ProfileStore.d.ts +8 -0
- package/dist/esm/Recommendation/Stores/ProfileStore.d.ts.map +1 -0
- package/dist/esm/Recommendation/Stores/ProfileStore.js +17 -0
- package/dist/esm/Recommendation/Stores/index.d.ts +2 -0
- package/dist/esm/Recommendation/Stores/index.d.ts.map +1 -0
- package/dist/esm/Recommendation/Stores/index.js +1 -0
- package/dist/esm/Search/SearchStore.d.ts +26 -0
- package/dist/esm/Search/SearchStore.d.ts.map +1 -0
- package/dist/esm/Search/SearchStore.js +38 -0
- package/dist/esm/Search/Stores/FacetStore.d.ts +8 -0
- package/dist/esm/Search/Stores/FacetStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/FacetStore.js +264 -0
- package/dist/esm/Search/Stores/FilterStore.d.ts +7 -0
- package/dist/esm/Search/Stores/FilterStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/FilterStore.js +68 -0
- package/dist/esm/Search/Stores/MerchandisingStore.d.ts +20 -0
- package/dist/esm/Search/Stores/MerchandisingStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/MerchandisingStore.js +32 -0
- package/dist/esm/Search/Stores/PaginationStore.d.ts +40 -0
- package/dist/esm/Search/Stores/PaginationStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/PaginationStore.js +148 -0
- package/dist/esm/Search/Stores/QueryStore.d.ts +16 -0
- package/dist/esm/Search/Stores/QueryStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/QueryStore.js +28 -0
- package/dist/esm/Search/Stores/ResultStore.d.ts +7 -0
- package/dist/esm/Search/Stores/ResultStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/ResultStore.js +117 -0
- package/dist/esm/Search/Stores/SortingStore.d.ts +21 -0
- package/dist/esm/Search/Stores/SortingStore.d.ts.map +1 -0
- package/dist/esm/Search/Stores/SortingStore.js +65 -0
- package/dist/esm/Search/Stores/index.d.ts +8 -0
- package/dist/esm/Search/Stores/index.d.ts.map +1 -0
- package/dist/esm/Search/Stores/index.js +7 -0
- package/dist/esm/Storage/StorageStore.d.ts +25 -0
- package/dist/esm/Storage/StorageStore.d.ts.map +1 -0
- package/dist/esm/Storage/StorageStore.js +123 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/types.d.ts +81 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +6 -0
- package/package.json +34 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { makeObservable, observable } from 'mobx';
|
|
2
|
+
export class ResultStore extends Array {
|
|
3
|
+
static get [Symbol.species]() {
|
|
4
|
+
return Array;
|
|
5
|
+
}
|
|
6
|
+
constructor(config, services, resultData, paginationData, merchData) {
|
|
7
|
+
let results = (resultData || []).map((result) => {
|
|
8
|
+
return new Product(services, result);
|
|
9
|
+
});
|
|
10
|
+
if (merchData?.content?.inline) {
|
|
11
|
+
const banners = merchData.content.inline
|
|
12
|
+
.sort(function (a, b) {
|
|
13
|
+
return a.config.position.index - b.config.position.index;
|
|
14
|
+
})
|
|
15
|
+
.map((banner) => {
|
|
16
|
+
return new Banner(services, banner);
|
|
17
|
+
});
|
|
18
|
+
if (banners && paginationData?.totalResults) {
|
|
19
|
+
results = addBannersToResults(config, results, banners, paginationData);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
super(...results);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class Banner {
|
|
28
|
+
constructor(services, banner) {
|
|
29
|
+
this.type = 'banner';
|
|
30
|
+
this.attributes = {};
|
|
31
|
+
this.mappings = {
|
|
32
|
+
core: {},
|
|
33
|
+
};
|
|
34
|
+
this.custom = {};
|
|
35
|
+
this.id = 'ss-ib-' + banner.config.position.index;
|
|
36
|
+
this.config = banner.config;
|
|
37
|
+
this.value = banner.value;
|
|
38
|
+
makeObservable(this, {
|
|
39
|
+
id: observable,
|
|
40
|
+
mappings: observable,
|
|
41
|
+
attributes: observable,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class Product {
|
|
46
|
+
constructor(services, result) {
|
|
47
|
+
this.type = 'product';
|
|
48
|
+
this.attributes = {};
|
|
49
|
+
this.mappings = {
|
|
50
|
+
core: {},
|
|
51
|
+
};
|
|
52
|
+
this.custom = {};
|
|
53
|
+
this.children = [];
|
|
54
|
+
this.id = result.id;
|
|
55
|
+
this.attributes = result.attributes;
|
|
56
|
+
this.mappings = result.mappings;
|
|
57
|
+
if (result?.children?.length) {
|
|
58
|
+
this.children = result.children.map((variant, index) => {
|
|
59
|
+
return new Child(services, {
|
|
60
|
+
id: `${result.id}-${index}`,
|
|
61
|
+
...variant,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
makeObservable(this, {
|
|
66
|
+
id: observable,
|
|
67
|
+
attributes: observable,
|
|
68
|
+
custom: observable,
|
|
69
|
+
});
|
|
70
|
+
// must set all subo
|
|
71
|
+
const coreObservables = Object.keys(result.mappings.core).reduce((map, key) => {
|
|
72
|
+
return {
|
|
73
|
+
...map,
|
|
74
|
+
[key]: observable,
|
|
75
|
+
};
|
|
76
|
+
}, {});
|
|
77
|
+
makeObservable(this.mappings.core, coreObservables);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class Child {
|
|
81
|
+
constructor(services, result) {
|
|
82
|
+
this.type = 'child';
|
|
83
|
+
this.attributes = {};
|
|
84
|
+
this.custom = {};
|
|
85
|
+
this.id = result.id;
|
|
86
|
+
this.attributes = result.attributes;
|
|
87
|
+
makeObservable(this, {
|
|
88
|
+
id: observable,
|
|
89
|
+
attributes: observable,
|
|
90
|
+
custom: observable,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function addBannersToResults(config, results, banners, paginationData) {
|
|
95
|
+
const productCount = results.length;
|
|
96
|
+
let minIndex = paginationData.pageSize * (paginationData.page - 1);
|
|
97
|
+
const maxIndex = minIndex + paginationData.pageSize;
|
|
98
|
+
if (config?.settings?.infinite) {
|
|
99
|
+
minIndex = 0;
|
|
100
|
+
}
|
|
101
|
+
banners
|
|
102
|
+
.reduce((adding, banner) => {
|
|
103
|
+
const resultCount = productCount + adding.length;
|
|
104
|
+
if (banner.config.position.index >= minIndex && (banner.config.position.index < maxIndex || resultCount < paginationData.pageSize)) {
|
|
105
|
+
adding.push(banner);
|
|
106
|
+
}
|
|
107
|
+
return adding;
|
|
108
|
+
}, [])
|
|
109
|
+
.forEach((banner, index) => {
|
|
110
|
+
let adjustedIndex = banner.config.position.index - minIndex;
|
|
111
|
+
if (adjustedIndex > productCount - 1) {
|
|
112
|
+
adjustedIndex = productCount + index;
|
|
113
|
+
}
|
|
114
|
+
results.splice(adjustedIndex, 0, banner);
|
|
115
|
+
});
|
|
116
|
+
return results;
|
|
117
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { UrlManager } from '@searchspring/snap-url-manager';
|
|
2
|
+
import type { StoreServices } from '../../types';
|
|
3
|
+
import type { MetaResponseModel, SearchResponseModelSearch, SearchResponseModelSorting } from '@searchspring/snapi-types';
|
|
4
|
+
export declare class SortingStore {
|
|
5
|
+
options: Option[];
|
|
6
|
+
constructor(services: StoreServices, sorting: SearchResponseModelSorting[], search: SearchResponseModelSearch, meta: MetaResponseModel);
|
|
7
|
+
get current(): Option;
|
|
8
|
+
}
|
|
9
|
+
declare class Option {
|
|
10
|
+
active: boolean;
|
|
11
|
+
default: boolean;
|
|
12
|
+
field: string;
|
|
13
|
+
label: string;
|
|
14
|
+
direction: string;
|
|
15
|
+
type: string;
|
|
16
|
+
value: string;
|
|
17
|
+
url: UrlManager;
|
|
18
|
+
constructor(services: StoreServices, option: any, index: any);
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=SortingStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SortingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SortingStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,iBAAiB,EAIjB,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,2BAA2B,CAAC;AAOnC,qBAAa,YAAY;IACxB,OAAO,EAAE,MAAM,EAAE,CAAM;gBAEX,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,0BAA0B,EAAE,EAAE,MAAM,EAAE,yBAAyB,EAAE,IAAI,EAAE,iBAAiB;IAuCtI,IAAI,OAAO,IAAI,MAAM,CAEpB;CACD;AAED,cAAM,MAAM;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,UAAU,CAAC;gBAEJ,QAAQ,EAAE,aAAa,EAAE,MAAM,KAAA,EAAE,KAAK,KAAA;CAuBlD"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { observable, computed, makeObservable } from 'mobx';
|
|
2
|
+
export class SortingStore {
|
|
3
|
+
constructor(services, sorting, search, meta) {
|
|
4
|
+
this.options = [];
|
|
5
|
+
if (services && meta.sortOptions) {
|
|
6
|
+
const activeSort = sorting && sorting.length && sorting[0];
|
|
7
|
+
this.options = meta.sortOptions
|
|
8
|
+
.filter((option) => {
|
|
9
|
+
if (!search?.query) {
|
|
10
|
+
return option.type == 'field';
|
|
11
|
+
}
|
|
12
|
+
return option;
|
|
13
|
+
})
|
|
14
|
+
.map((option, index) => {
|
|
15
|
+
option.active = false;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
if (activeSort && activeSort.field == option.field && activeSort.direction == option.direction) {
|
|
19
|
+
option.active = true;
|
|
20
|
+
}
|
|
21
|
+
else if (!activeSort && index === 0) {
|
|
22
|
+
option.active = true;
|
|
23
|
+
}
|
|
24
|
+
option.default = false;
|
|
25
|
+
if (index === 0) {
|
|
26
|
+
// is the default sort
|
|
27
|
+
option.default = true;
|
|
28
|
+
}
|
|
29
|
+
const optionObj = new Option(services, option, index);
|
|
30
|
+
return optionObj;
|
|
31
|
+
});
|
|
32
|
+
makeObservable(this, {
|
|
33
|
+
options: observable,
|
|
34
|
+
current: computed,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
get current() {
|
|
39
|
+
return this.options.filter((option) => option.active).pop();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class Option {
|
|
43
|
+
constructor(services, option, index) {
|
|
44
|
+
this.active = option.active;
|
|
45
|
+
this.default = option.default;
|
|
46
|
+
this.field = option.field;
|
|
47
|
+
this.label = option.label;
|
|
48
|
+
this.direction = option.direction;
|
|
49
|
+
this.type = option.type;
|
|
50
|
+
this.value = `${option.label}:${option.field}:${option.direction}:${index}`;
|
|
51
|
+
if (this.default) {
|
|
52
|
+
this.url = services.urlManager.remove('page').remove('sort');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.url = services.urlManager.remove('page').set('sort', [{ field: this.field, direction: this.direction }]);
|
|
56
|
+
}
|
|
57
|
+
makeObservable(this, {
|
|
58
|
+
field: observable,
|
|
59
|
+
label: observable,
|
|
60
|
+
direction: observable,
|
|
61
|
+
type: observable,
|
|
62
|
+
value: observable,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { MerchandisingStore } from './MerchandisingStore';
|
|
2
|
+
export { FacetStore } from './FacetStore';
|
|
3
|
+
export { FilterStore } from './FilterStore';
|
|
4
|
+
export { PaginationStore } from './PaginationStore';
|
|
5
|
+
export { ResultStore } from './ResultStore';
|
|
6
|
+
export { SortingStore } from './SortingStore';
|
|
7
|
+
export { QueryStore } from './QueryStore';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { MerchandisingStore } from './MerchandisingStore';
|
|
2
|
+
export { FacetStore } from './FacetStore';
|
|
3
|
+
export { FilterStore } from './FilterStore';
|
|
4
|
+
export { PaginationStore } from './PaginationStore';
|
|
5
|
+
export { ResultStore } from './ResultStore';
|
|
6
|
+
export { SortingStore } from './SortingStore';
|
|
7
|
+
export { QueryStore } from './QueryStore';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class StorageStore {
|
|
2
|
+
type: StorageType | null;
|
|
3
|
+
expiration: number;
|
|
4
|
+
sameSite: any;
|
|
5
|
+
key: string;
|
|
6
|
+
state: {};
|
|
7
|
+
constructor(config?: StorageConfig);
|
|
8
|
+
set(path: string, value: any): void;
|
|
9
|
+
get(path: string): any;
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare type StorageConfig = {
|
|
13
|
+
type: StorageType;
|
|
14
|
+
cookie?: {
|
|
15
|
+
expiration?: number;
|
|
16
|
+
sameSite?: string;
|
|
17
|
+
};
|
|
18
|
+
key: string;
|
|
19
|
+
};
|
|
20
|
+
export declare enum StorageType {
|
|
21
|
+
SESSION = "session",
|
|
22
|
+
LOCAL = "local",
|
|
23
|
+
COOKIE = "cookie"
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=StorageStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageStore.d.ts","sourceRoot":"","sources":["../../../src/Storage/StorageStore.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACxB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;IAChC,UAAU,SAAe;IACzB,QAAQ,MAAa;IACrB,GAAG,SAAgB;IACnB,KAAK,KAAM;gBAEC,MAAM,CAAC,EAAE,aAAa;IAwClC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAyBnC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;IA+BtB,KAAK,IAAI,IAAI;CAcb;AAED,oBAAY,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,oBAAY,WAAW;IACtB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;CACjB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { featureFlags, cookies } from '@searchspring/snap-toolbox';
|
|
2
|
+
const utils = {
|
|
3
|
+
cookies,
|
|
4
|
+
};
|
|
5
|
+
export class StorageStore {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.type = null;
|
|
8
|
+
this.expiration = 31536000000; // one year (ms)
|
|
9
|
+
this.sameSite = undefined;
|
|
10
|
+
this.key = 'ss-storage';
|
|
11
|
+
this.state = {};
|
|
12
|
+
if (config) {
|
|
13
|
+
if (config.key.trim() !== '') {
|
|
14
|
+
this.key = config.key.trim();
|
|
15
|
+
}
|
|
16
|
+
if (config?.cookie?.expiration) {
|
|
17
|
+
this.expiration = config.cookie.expiration;
|
|
18
|
+
}
|
|
19
|
+
if (config?.cookie?.sameSite) {
|
|
20
|
+
this.sameSite = config.cookie.sameSite;
|
|
21
|
+
}
|
|
22
|
+
switch (config.type) {
|
|
23
|
+
case StorageType.SESSION:
|
|
24
|
+
this.type = featureFlags.storage ? config.type : null;
|
|
25
|
+
if (this.type) {
|
|
26
|
+
this.state = JSON.parse(window.sessionStorage.getItem(this.key) || '{}');
|
|
27
|
+
window.sessionStorage.setItem(this.key, JSON.stringify(this.state));
|
|
28
|
+
}
|
|
29
|
+
break;
|
|
30
|
+
case StorageType.LOCAL:
|
|
31
|
+
this.type = featureFlags.storage ? config.type : null;
|
|
32
|
+
if (this.type && !window.localStorage.getItem(this.key)) {
|
|
33
|
+
this.state = JSON.parse(window.localStorage.getItem(this.key) || '{}');
|
|
34
|
+
window.localStorage.setItem(this.key, JSON.stringify(this.state));
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case StorageType.COOKIE:
|
|
38
|
+
if (featureFlags.cookies) {
|
|
39
|
+
this.type = config.type;
|
|
40
|
+
const data = utils.cookies.get(this.key);
|
|
41
|
+
if (data) {
|
|
42
|
+
this.state = JSON.parse(data);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
set(path, value) {
|
|
50
|
+
const paths = path?.split('.');
|
|
51
|
+
let location = this.state;
|
|
52
|
+
paths?.forEach((p, i) => {
|
|
53
|
+
const leaf = i == paths.length - 1;
|
|
54
|
+
if (leaf) {
|
|
55
|
+
location[p] = value;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
location = location[p] = location[p] || {};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
switch (this.type) {
|
|
62
|
+
case StorageType.SESSION:
|
|
63
|
+
window.sessionStorage.setItem(this.key, JSON.stringify(this.state));
|
|
64
|
+
break;
|
|
65
|
+
case StorageType.LOCAL:
|
|
66
|
+
window.localStorage.setItem(this.key, JSON.stringify(this.state));
|
|
67
|
+
break;
|
|
68
|
+
case StorageType.COOKIE:
|
|
69
|
+
utils.cookies.set(this.key, JSON.stringify(this.state), this.sameSite, this.expiration);
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
get(path) {
|
|
74
|
+
switch (this.type) {
|
|
75
|
+
case StorageType.SESSION:
|
|
76
|
+
this.state = JSON.parse(window.sessionStorage.getItem(this.key)) || {};
|
|
77
|
+
break;
|
|
78
|
+
case StorageType.LOCAL:
|
|
79
|
+
this.state = JSON.parse(window.localStorage.getItem(this.key)) || {};
|
|
80
|
+
break;
|
|
81
|
+
case StorageType.COOKIE:
|
|
82
|
+
const data = utils.cookies.get(this.key);
|
|
83
|
+
if (data) {
|
|
84
|
+
this.state = JSON.parse(data) || {};
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
const paths = path?.split('.');
|
|
89
|
+
if (!paths?.length)
|
|
90
|
+
return undefined;
|
|
91
|
+
let value = this.state;
|
|
92
|
+
for (const p of paths) {
|
|
93
|
+
if (value && typeof value[p] != 'undefined') {
|
|
94
|
+
value = value[p];
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
value = undefined;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
clear() {
|
|
104
|
+
switch (this.type) {
|
|
105
|
+
case StorageType.SESSION:
|
|
106
|
+
window.sessionStorage.removeItem(this.key);
|
|
107
|
+
break;
|
|
108
|
+
case StorageType.LOCAL:
|
|
109
|
+
window.localStorage.removeItem(this.key);
|
|
110
|
+
break;
|
|
111
|
+
case StorageType.COOKIE:
|
|
112
|
+
utils.cookies.unset(this.key);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
this.state = {};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export var StorageType;
|
|
119
|
+
(function (StorageType) {
|
|
120
|
+
StorageType["SESSION"] = "session";
|
|
121
|
+
StorageType["LOCAL"] = "local";
|
|
122
|
+
StorageType["COOKIE"] = "cookie";
|
|
123
|
+
})(StorageType || (StorageType = {}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AbstractStore } from './Abstract/AbstractStore';
|
|
2
|
+
export { AutocompleteStore } from './Autocomplete/AutocompleteStore';
|
|
3
|
+
export { FinderStore } from './Finder/FinderStore';
|
|
4
|
+
export { SearchStore } from './Search/SearchStore';
|
|
5
|
+
export { RecommendationStore } from './Recommendation/RecommendationStore';
|
|
6
|
+
export { StorageStore, StorageConfig, StorageType } from './Storage/StorageStore';
|
|
7
|
+
export * from './types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAElF,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { AbstractStore } from './Abstract/AbstractStore';
|
|
2
|
+
export { AutocompleteStore } from './Autocomplete/AutocompleteStore';
|
|
3
|
+
export { FinderStore } from './Finder/FinderStore';
|
|
4
|
+
export { SearchStore } from './Search/SearchStore';
|
|
5
|
+
export { RecommendationStore } from './Recommendation/RecommendationStore';
|
|
6
|
+
export { StorageStore, StorageType } from './Storage/StorageStore';
|
|
7
|
+
export * from './types';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { UrlManager } from '@searchspring/snap-url-manager';
|
|
2
|
+
export declare type StoreConfig = {
|
|
3
|
+
id: string;
|
|
4
|
+
[any: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
export declare type SearchStoreConfig = StoreConfig & {
|
|
7
|
+
globals?: {
|
|
8
|
+
personalization?: {
|
|
9
|
+
disabled: boolean;
|
|
10
|
+
};
|
|
11
|
+
[any: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
settings?: {
|
|
14
|
+
redirects?: {
|
|
15
|
+
merchandising?: boolean;
|
|
16
|
+
singleResult?: boolean;
|
|
17
|
+
};
|
|
18
|
+
facets?: {
|
|
19
|
+
trim?: boolean;
|
|
20
|
+
pinFiltered?: boolean;
|
|
21
|
+
};
|
|
22
|
+
infinite?: {
|
|
23
|
+
backfill?: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare type FinderStoreConfig = StoreConfig & {
|
|
28
|
+
globals?: any;
|
|
29
|
+
url?: string;
|
|
30
|
+
fields: FinderFieldConfig[];
|
|
31
|
+
};
|
|
32
|
+
export declare type FinderFieldConfig = {
|
|
33
|
+
field: string;
|
|
34
|
+
label?: string;
|
|
35
|
+
levels?: string[];
|
|
36
|
+
};
|
|
37
|
+
export declare type AutocompleteStoreConfig = StoreConfig & {
|
|
38
|
+
globals?: {
|
|
39
|
+
personalization?: {
|
|
40
|
+
disabled: boolean;
|
|
41
|
+
};
|
|
42
|
+
search?: {
|
|
43
|
+
[any: string]: unknown;
|
|
44
|
+
query?: {
|
|
45
|
+
[any: string]: unknown;
|
|
46
|
+
spellCorrection?: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
[any: string]: unknown;
|
|
50
|
+
};
|
|
51
|
+
selector: string;
|
|
52
|
+
action?: string;
|
|
53
|
+
settings?: {
|
|
54
|
+
initializeFromUrl?: boolean;
|
|
55
|
+
syncInputs?: boolean;
|
|
56
|
+
facets?: {
|
|
57
|
+
trim?: boolean;
|
|
58
|
+
pinFiltered?: boolean;
|
|
59
|
+
};
|
|
60
|
+
trending?: {
|
|
61
|
+
limit: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export declare type RecommendationStoreConfig = StoreConfig & {
|
|
66
|
+
globals?: any;
|
|
67
|
+
tag: string;
|
|
68
|
+
branch?: string;
|
|
69
|
+
realtime?: boolean;
|
|
70
|
+
batched?: boolean;
|
|
71
|
+
};
|
|
72
|
+
export declare type StoreConfigs = SearchStoreConfig | AutocompleteStoreConfig | FinderStoreConfig | RecommendationStoreConfig;
|
|
73
|
+
export declare type StoreServices = {
|
|
74
|
+
urlManager?: UrlManager;
|
|
75
|
+
};
|
|
76
|
+
export declare enum ErrorType {
|
|
77
|
+
WARNING = "warning",
|
|
78
|
+
INFO = "info",
|
|
79
|
+
ERROR = "error"
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAGjE,oBAAY,WAAW,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB,CAAC;AAGF,oBAAY,iBAAiB,GAAG,WAAW,GAAG;IAC7C,OAAO,CAAC,EAAE;QACT,eAAe,CAAC,EAAE;YACjB,QAAQ,EAAE,OAAO,CAAC;SAClB,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,QAAQ,CAAC,EAAE;QACV,SAAS,CAAC,EAAE;YACX,aAAa,CAAC,EAAE,OAAO,CAAC;YACxB,YAAY,CAAC,EAAE,OAAO,CAAC;SACvB,CAAC;QACF,MAAM,CAAC,EAAE;YACR,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,WAAW,CAAC,EAAE,OAAO,CAAC;SACtB,CAAC;QACF,QAAQ,CAAC,EAAE;YACV,QAAQ,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;KACF,CAAC;CACF,CAAC;AAGF,oBAAY,iBAAiB,GAAG,WAAW,GAAG;IAC7C,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,EAAE,CAAC;CAC5B,CAAC;AAEF,oBAAY,iBAAiB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAGF,oBAAY,uBAAuB,GAAG,WAAW,GAAG;IACnD,OAAO,CAAC,EAAE;QACT,eAAe,CAAC,EAAE;YACjB,QAAQ,EAAE,OAAO,CAAC;SAClB,CAAC;QACF,MAAM,CAAC,EAAE;YACR,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;YACvB,KAAK,CAAC,EAAE;gBACP,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;gBACvB,eAAe,CAAC,EAAE,OAAO,CAAC;aAC1B,CAAC;SACF,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE;QACV,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,MAAM,CAAC,EAAE;YACR,IAAI,CAAC,EAAE,OAAO,CAAC;YACf,WAAW,CAAC,EAAE,OAAO,CAAC;SACtB,CAAC;QACF,QAAQ,CAAC,EAAE;YACV,KAAK,EAAE,MAAM,CAAC;SACd,CAAC;KACF,CAAC;CACF,CAAC;AAGF,oBAAY,yBAAyB,GAAG,WAAW,GAAG;IACrD,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,oBAAY,YAAY,GAAG,iBAAiB,GAAG,uBAAuB,GAAG,iBAAiB,GAAG,yBAAyB,CAAC;AAEvH,oBAAY,aAAa,GAAG;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,oBAAY,SAAS;IACpB,OAAO,YAAY;IACnB,IAAI,SAAS;IACb,KAAK,UAAU;CACf"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@searchspring/snap-store-mobx",
|
|
3
|
+
"version": "0.20.0",
|
|
4
|
+
"description": "Snap MobX Store",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"author": "Searchspring",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": "https://github.com/searchspring/snap",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rm -rf ./dist && tsc && tsc -p tsconfig.cjs.json",
|
|
15
|
+
"build:docs": "typedoc --out docs src/index.ts",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx}'",
|
|
18
|
+
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
|
|
19
|
+
"test": "jest",
|
|
20
|
+
"test:watch": "jest --watch"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@searchspring/snap-toolbox": "^0.20.0",
|
|
24
|
+
"mobx": "^6.3.12"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@searchspring/snap-url-manager": "^0.20.0"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"files": [
|
|
31
|
+
"dist/**/*"
|
|
32
|
+
],
|
|
33
|
+
"gitHead": "122405b27b497c7bb6a189c30535fdc197bc3ef0"
|
|
34
|
+
}
|