@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,42 @@
|
|
|
1
|
+
import { observable, makeObservable } from 'mobx';
|
|
2
|
+
export class TermStore extends Array {
|
|
3
|
+
static get [Symbol.species]() {
|
|
4
|
+
return Array;
|
|
5
|
+
}
|
|
6
|
+
constructor(services, autocomplete, paginationData, resetTerms, rootState) {
|
|
7
|
+
const suggestions = [...(autocomplete?.alternatives ? autocomplete.alternatives : []).map((term) => term.text)];
|
|
8
|
+
if (autocomplete?.suggested?.text) {
|
|
9
|
+
suggestions.unshift(autocomplete.suggested.text);
|
|
10
|
+
}
|
|
11
|
+
else if (autocomplete?.query && paginationData.totalResults) {
|
|
12
|
+
suggestions.unshift(autocomplete?.query);
|
|
13
|
+
}
|
|
14
|
+
const terms = [];
|
|
15
|
+
suggestions.map((term, index) => terms.push(new Term(services, {
|
|
16
|
+
active: index === 0,
|
|
17
|
+
value: term,
|
|
18
|
+
}, terms, resetTerms, rootState)));
|
|
19
|
+
super(...terms);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class Term {
|
|
23
|
+
constructor(services, term, terms, resetTerms, rootState) {
|
|
24
|
+
this.active = term.active;
|
|
25
|
+
this.value = term.value;
|
|
26
|
+
this.url = services?.urlManager?.set({ query: this.value });
|
|
27
|
+
this.preview = () => {
|
|
28
|
+
resetTerms();
|
|
29
|
+
terms.map((term) => {
|
|
30
|
+
term.active = false;
|
|
31
|
+
});
|
|
32
|
+
this.active = true;
|
|
33
|
+
rootState.locks.terms.lock();
|
|
34
|
+
rootState.locks.facets.unlock();
|
|
35
|
+
this.url?.set({ query: this.value }).go();
|
|
36
|
+
};
|
|
37
|
+
makeObservable(this, {
|
|
38
|
+
active: observable,
|
|
39
|
+
value: observable,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { StoreServices } from '../../types';
|
|
2
|
+
import type { StateStore } from './StateStore';
|
|
3
|
+
export declare class TrendingStore extends Array {
|
|
4
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
5
|
+
constructor(services: StoreServices, trendingData: any, resetTerms: () => void, rootState: StateStore);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=TrendingStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrendingStore.d.ts","sourceRoot":"","sources":["../../../../src/Autocomplete/Stores/TrendingStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,qBAAa,aAAc,SAAQ,KAAK;IACvC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEW,QAAQ,EAAE,aAAa,EAAE,YAAY,KAAA,EAAE,UAAU,EAAE,MAAM,IAAI,EAAE,SAAS,EAAE,UAAU;CAoBhG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Term } from './TermStore';
|
|
2
|
+
export class TrendingStore extends Array {
|
|
3
|
+
static get [Symbol.species]() {
|
|
4
|
+
return Array;
|
|
5
|
+
}
|
|
6
|
+
constructor(services, trendingData, resetTerms, rootState) {
|
|
7
|
+
const terms = [];
|
|
8
|
+
trendingData?.queries?.map((term) => {
|
|
9
|
+
terms.push(new Term(services, {
|
|
10
|
+
active: false,
|
|
11
|
+
value: term.searchQuery,
|
|
12
|
+
}, terms, resetTerms, rootState));
|
|
13
|
+
});
|
|
14
|
+
super(...terms);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Autocomplete/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SearchResponseModel, MetaResponseModel } from '@searchspring/snapi-types';
|
|
2
|
+
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
3
|
+
import { PaginationStore } from '../Search/Stores';
|
|
4
|
+
import { StorageStore } from '../Storage/StorageStore';
|
|
5
|
+
import { SelectionStore } from './Stores';
|
|
6
|
+
import type { FinderStoreConfig, StoreServices } from '../types';
|
|
7
|
+
export declare class FinderStore extends AbstractStore {
|
|
8
|
+
services: StoreServices;
|
|
9
|
+
config: FinderStoreConfig;
|
|
10
|
+
meta: MetaResponseModel;
|
|
11
|
+
storage: StorageStore;
|
|
12
|
+
pagination: PaginationStore;
|
|
13
|
+
selections: SelectionStore;
|
|
14
|
+
constructor(config: FinderStoreConfig, services: StoreServices);
|
|
15
|
+
setService(name: any, service: any): void;
|
|
16
|
+
update(data: SearchResponseModel & {
|
|
17
|
+
meta: MetaResponseModel;
|
|
18
|
+
selections: SelectionStore[];
|
|
19
|
+
}): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=FinderStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FinderStore.d.ts","sourceRoot":"","sources":["../../../src/Finder/FinderStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjE,qBAAa,WAAY,SAAQ,aAAa;IAC7C,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,IAAI,EAAE,iBAAiB,CAAM;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,UAAU,EAAE,eAAe,CAAC;IAC5B,UAAU,EAAE,cAAc,CAAC;gBAEf,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa;IAmB9D,UAAU,CAAC,IAAI,KAAA,EAAE,OAAO,KAAA,GAAG,IAAI;IAM/B,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG;QAAE,IAAI,EAAE,iBAAiB,CAAC;QAAC,UAAU,EAAE,cAAc,EAAE,CAAA;KAAE,GAAG,IAAI;CAOnG"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { makeObservable, observable } from 'mobx';
|
|
2
|
+
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
3
|
+
import { PaginationStore } from '../Search/Stores';
|
|
4
|
+
import { StorageStore } from '../Storage/StorageStore';
|
|
5
|
+
import { SelectionStore } from './Stores';
|
|
6
|
+
export class FinderStore extends AbstractStore {
|
|
7
|
+
constructor(config, services) {
|
|
8
|
+
super(config);
|
|
9
|
+
this.meta = {};
|
|
10
|
+
if (typeof services != 'object' || typeof services.urlManager?.subscribe != 'function') {
|
|
11
|
+
throw new Error(`Invalid service 'urlManager' passed to AutocompleteStore. Missing "subscribe" function.`);
|
|
12
|
+
}
|
|
13
|
+
this.services = services;
|
|
14
|
+
this.storage = new StorageStore();
|
|
15
|
+
this.update({ meta: {}, selections: [] });
|
|
16
|
+
makeObservable(this, {
|
|
17
|
+
selections: observable,
|
|
18
|
+
pagination: observable,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
setService(name, service) {
|
|
22
|
+
if (this.services[name] && service) {
|
|
23
|
+
this.services[name] = service;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
update(data) {
|
|
27
|
+
this.error = undefined;
|
|
28
|
+
this.loaded = !!data.pagination;
|
|
29
|
+
this.meta = data.meta;
|
|
30
|
+
this.pagination = new PaginationStore(this.config, this.services, data.pagination);
|
|
31
|
+
this.selections = new SelectionStore(this.config, this.services, data.facets, this.meta, this.loading, this.storage);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FinderStoreConfig, StoreServices } from '../../types';
|
|
2
|
+
import type { StorageStore } from '../../Storage/StorageStore';
|
|
3
|
+
import type { MetaResponseModel, SearchResponseModelFacet } from '@searchspring/snapi-types';
|
|
4
|
+
export declare class SelectionStore extends Array {
|
|
5
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
6
|
+
constructor(config: FinderStoreConfig, services: StoreServices, facets: SearchResponseModelFacet[], meta: MetaResponseModel, loading: boolean, storage: StorageStore);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=SelectionStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionStore.d.ts","sourceRoot":"","sources":["../../../../src/Finder/Stores/SelectionStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAqB,aAAa,EAAE,MAAM,aAAa,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAA4C,MAAM,2BAA2B,CAAC;AAEvI,qBAAa,cAAe,SAAQ,KAAK;IACxC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAGA,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,aAAa,EACvB,MAAM,EAAE,wBAAwB,EAAE,EAClC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,YAAY;CA+CtB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export class SelectionStore extends Array {
|
|
2
|
+
static get [Symbol.species]() {
|
|
3
|
+
return Array;
|
|
4
|
+
}
|
|
5
|
+
constructor(config, services, facets, meta, loading, storage) {
|
|
6
|
+
if (!facets || !meta) {
|
|
7
|
+
super();
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
// re-order facets to match our config
|
|
11
|
+
config?.fields &&
|
|
12
|
+
facets.sort((a, b) => {
|
|
13
|
+
const fields = config.fields.map((fieldConfig) => fieldConfig.field);
|
|
14
|
+
return fields.indexOf(a.field) - fields.indexOf(b.field);
|
|
15
|
+
});
|
|
16
|
+
const selections = [];
|
|
17
|
+
config?.fields?.forEach((fieldObj) => {
|
|
18
|
+
let facet = facets?.filter((facet) => facet.field == fieldObj.field).pop();
|
|
19
|
+
facet = {
|
|
20
|
+
...meta?.facets[fieldObj.field],
|
|
21
|
+
...facet,
|
|
22
|
+
};
|
|
23
|
+
const isHierarchy = facet.display === 'hierarchy';
|
|
24
|
+
if (isHierarchy) {
|
|
25
|
+
// filter out history/current hierarchy values
|
|
26
|
+
const filtered = facet.filtered && facet.values.filter((value) => value.filtered).pop();
|
|
27
|
+
if (filtered) {
|
|
28
|
+
const filteredLevel = filtered.value.split(facet.hierarchyDelimiter).length;
|
|
29
|
+
facet.values = facet.values.filter((value, index) => {
|
|
30
|
+
return (value.value && value.value.split(facet.hierarchyDelimiter).length > filteredLevel) || index == facet.values.length - 1;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
const levels = fieldObj?.levels || facet?.values[facet?.values.length - 1]?.value.split(facet.hierarchyDelimiter);
|
|
34
|
+
levels?.map((level, index) => {
|
|
35
|
+
const levelConfig = { index, label: fieldObj.levels ? level : '', key: `ss-${index}` };
|
|
36
|
+
selections.push(new SelectionHierarchy(services, config.id, facet, levelConfig, loading, storage));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
selections.push(new Selection(services, config.id, facet, fieldObj, loading, storage));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
super(...selections);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class SelectionBase {
|
|
47
|
+
constructor(services, id, facet, selectionConfig, loading, storageStore) {
|
|
48
|
+
this.filtered = false;
|
|
49
|
+
this.collapsed = false;
|
|
50
|
+
this.display = '';
|
|
51
|
+
this.disabled = false;
|
|
52
|
+
this.selected = '';
|
|
53
|
+
this.custom = {};
|
|
54
|
+
this.services = services;
|
|
55
|
+
this.loading = loading;
|
|
56
|
+
this.id = id;
|
|
57
|
+
this.config = selectionConfig;
|
|
58
|
+
// inherit all standard facet properties
|
|
59
|
+
this.type = facet.type;
|
|
60
|
+
this.field = facet.field;
|
|
61
|
+
this.filtered = facet.filtered;
|
|
62
|
+
this.collapsed = facet.collapsed;
|
|
63
|
+
this.display = facet.display;
|
|
64
|
+
this.label = facet.label;
|
|
65
|
+
this.multiple = facet.multiple;
|
|
66
|
+
// abstracted StorageStore
|
|
67
|
+
this.storage = {
|
|
68
|
+
key: `ss-finder-${this.id}.${this.field}`,
|
|
69
|
+
get: function (key) {
|
|
70
|
+
const path = this.key + (key ? `.${key}` : '');
|
|
71
|
+
return storageStore.get(path);
|
|
72
|
+
},
|
|
73
|
+
set: function (key, value) {
|
|
74
|
+
const path = this.key + (key ? `.${key}` : '');
|
|
75
|
+
return storageStore.set(path, value);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
get values() {
|
|
80
|
+
const values = [...(this.data || [])];
|
|
81
|
+
values.unshift({
|
|
82
|
+
filtered: false,
|
|
83
|
+
value: '',
|
|
84
|
+
label: this.config.label || this.label,
|
|
85
|
+
});
|
|
86
|
+
return values;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
class Selection extends SelectionBase {
|
|
90
|
+
constructor(services, id, facet, config, loading, storageStore) {
|
|
91
|
+
super(services, id, facet, config, loading, storageStore);
|
|
92
|
+
this.loading = loading;
|
|
93
|
+
this.storage.set('values', facet.values);
|
|
94
|
+
const storageData = this.storage.get();
|
|
95
|
+
this.data = storageData.values;
|
|
96
|
+
// check if any dropdowns have been selected
|
|
97
|
+
this.disabled = !this.values.length;
|
|
98
|
+
this.selected = this.disabled ? '' : storageData.selected || '';
|
|
99
|
+
}
|
|
100
|
+
select(value = '') {
|
|
101
|
+
if (this.loading)
|
|
102
|
+
return;
|
|
103
|
+
this.selected = value;
|
|
104
|
+
this.storage.set('selected', value);
|
|
105
|
+
if (!value) {
|
|
106
|
+
this.services.urlManager.remove(`filter.${this.field}`).go();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
this.services.urlManager.set(`filter.${this.field}`, value).go();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
class SelectionHierarchy extends SelectionBase {
|
|
114
|
+
constructor(services, id, facet, config, loading, storageStore) {
|
|
115
|
+
super(services, id, facet, config, loading, storageStore);
|
|
116
|
+
// inherit additional facet properties
|
|
117
|
+
this.hierarchyDelimiter = facet.hierarchyDelimiter;
|
|
118
|
+
let storageData = this.storage.get();
|
|
119
|
+
if (!storageData) {
|
|
120
|
+
// nothing in storage - initial state for first dropdown
|
|
121
|
+
this.storage.set(`${this.config.key}.values`, facet.values);
|
|
122
|
+
storageData = this.storage.get();
|
|
123
|
+
}
|
|
124
|
+
else if (storageData[this.config.key]?.values) {
|
|
125
|
+
// set selected from storage
|
|
126
|
+
this.selected = storageData[this.config.key]?.selected || '';
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
// value does not exist in storage
|
|
130
|
+
const storedLevels = this.storage.get();
|
|
131
|
+
const levels = Object.keys(storedLevels).map((a, index) => `ss-${index}`);
|
|
132
|
+
!levels.includes(this.config.key) && levels.push(this.config.key);
|
|
133
|
+
const selectedLevels = Object.keys(storedLevels).filter((key) => storedLevels[key].selected);
|
|
134
|
+
const lastSelected = selectedLevels[selectedLevels.length - 1];
|
|
135
|
+
const labelIndex = levels.indexOf(this.config.key);
|
|
136
|
+
const lastSelectedIndex = levels.indexOf(lastSelected);
|
|
137
|
+
if (lastSelectedIndex != -1 && labelIndex == lastSelectedIndex + 1) {
|
|
138
|
+
this.storage.set(`${this.config.key}.values`, facet.values);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.disabled = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
this.data = storageData[this.config.key]?.values || [];
|
|
145
|
+
}
|
|
146
|
+
select(value = '') {
|
|
147
|
+
if (this.loading)
|
|
148
|
+
return;
|
|
149
|
+
this.selected = value;
|
|
150
|
+
const selectedLevel = this.config.index;
|
|
151
|
+
const storedLevels = this.storage.get();
|
|
152
|
+
const keysToRemove = Object.keys(storedLevels).slice(selectedLevel);
|
|
153
|
+
Object.keys(storedLevels)
|
|
154
|
+
.reverse()
|
|
155
|
+
.forEach((key) => {
|
|
156
|
+
if (key == this.config.key) {
|
|
157
|
+
this.storage.set(`${key}.selected`, value);
|
|
158
|
+
}
|
|
159
|
+
else if (keysToRemove.includes(key)) {
|
|
160
|
+
this.storage.set(`${key}`, {});
|
|
161
|
+
}
|
|
162
|
+
value = value || this.storage.get(`${key}.selected`);
|
|
163
|
+
});
|
|
164
|
+
if (!value) {
|
|
165
|
+
this.services.urlManager.remove(`filter.${this.field}`).go();
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
this.services.urlManager.set(`filter.${this.field}`, value).go();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Finder/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SelectionStore } from './SelectionStore';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
2
|
+
import { ResultStore } from '../Search/Stores';
|
|
3
|
+
import { ProfileStore } from './Stores';
|
|
4
|
+
import type { RecommendationStoreConfig, StoreServices } from '../types';
|
|
5
|
+
export declare class RecommendationStore extends AbstractStore {
|
|
6
|
+
services: StoreServices;
|
|
7
|
+
loaded: boolean;
|
|
8
|
+
profile: ProfileStore;
|
|
9
|
+
results: ResultStore;
|
|
10
|
+
constructor(config: RecommendationStoreConfig, services: StoreServices);
|
|
11
|
+
reset(): void;
|
|
12
|
+
update(data: any): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=RecommendationStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecommendationStore.d.ts","sourceRoot":"","sources":["../../../src/Recommendation/RecommendationStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzE,qBAAa,mBAAoB,SAAQ,aAAa;IACrD,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,UAAS;IACf,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC;gBAET,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,aAAa;IAiBtE,KAAK,IAAI,IAAI;IAIb,MAAM,CAAC,IAAI,KAAA,GAAG,IAAI;CAMlB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { makeObservable, observable } from 'mobx';
|
|
2
|
+
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
3
|
+
import { ResultStore } from '../Search/Stores';
|
|
4
|
+
import { ProfileStore } from './Stores';
|
|
5
|
+
export class RecommendationStore extends AbstractStore {
|
|
6
|
+
constructor(config, services) {
|
|
7
|
+
super(config);
|
|
8
|
+
this.loaded = false;
|
|
9
|
+
if (typeof services != 'object' || typeof services.urlManager?.subscribe != 'function') {
|
|
10
|
+
throw new Error(`Invalid service 'urlManager' passed to AutocompleteStore. Missing "subscribe" function.`);
|
|
11
|
+
}
|
|
12
|
+
this.services = services;
|
|
13
|
+
this.reset();
|
|
14
|
+
makeObservable(this, {
|
|
15
|
+
profile: observable,
|
|
16
|
+
results: observable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
reset() {
|
|
20
|
+
this.update({});
|
|
21
|
+
}
|
|
22
|
+
update(data) {
|
|
23
|
+
this.error = undefined;
|
|
24
|
+
this.loaded = !!data.profile;
|
|
25
|
+
this.profile = new ProfileStore(this.services, data.profile);
|
|
26
|
+
this.results = new ResultStore(this.config, this.services, data.results);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProfileStore.d.ts","sourceRoot":"","sources":["../../../../src/Recommendation/Stores/ProfileStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,qBAAa,YAAY;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAEtB,QAAQ,EAAE,aAAa,EAAE,OAAO,KAAA;CAe5C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { observable, makeObservable } from 'mobx';
|
|
2
|
+
export class ProfileStore {
|
|
3
|
+
constructor(services, profile) {
|
|
4
|
+
this.display = {};
|
|
5
|
+
if (!profile?.tag) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
this.tag = profile.tag;
|
|
9
|
+
this.placement = profile.placement;
|
|
10
|
+
this.display = profile.display;
|
|
11
|
+
makeObservable(this, {
|
|
12
|
+
tag: observable,
|
|
13
|
+
placement: observable,
|
|
14
|
+
display: observable,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Recommendation/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ProfileStore } from './ProfileStore';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { SearchResponseModel, MetaResponseModel } from '@searchspring/snapi-types';
|
|
2
|
+
import type { SearchStoreConfig, StoreServices } from '../types';
|
|
3
|
+
import { MerchandisingStore, FacetStore, FilterStore, ResultStore, PaginationStore, SortingStore, QueryStore } from './Stores';
|
|
4
|
+
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
5
|
+
import { StorageStore } from '../Storage/StorageStore';
|
|
6
|
+
export declare class SearchStore extends AbstractStore {
|
|
7
|
+
config: SearchStoreConfig;
|
|
8
|
+
services: StoreServices;
|
|
9
|
+
data: SearchResponseModel & {
|
|
10
|
+
meta: MetaResponseModel;
|
|
11
|
+
};
|
|
12
|
+
meta: MetaResponseModel;
|
|
13
|
+
merchandising: MerchandisingStore;
|
|
14
|
+
search: QueryStore;
|
|
15
|
+
facets: FacetStore;
|
|
16
|
+
filters: FilterStore;
|
|
17
|
+
results: ResultStore;
|
|
18
|
+
pagination: PaginationStore;
|
|
19
|
+
sorting: SortingStore;
|
|
20
|
+
storage: StorageStore;
|
|
21
|
+
constructor(config: SearchStoreConfig, services: StoreServices);
|
|
22
|
+
update(data: SearchResponseModel & {
|
|
23
|
+
meta: MetaResponseModel;
|
|
24
|
+
}): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=SearchStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SearchStore.d.ts","sourceRoot":"","sources":["../../../src/Search/SearchStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/H,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,qBAAa,WAAY,SAAQ,aAAa;IAC7C,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,aAAa,CAAC;IACjB,IAAI,EAAE,mBAAmB,GAAG;QAAE,IAAI,EAAE,iBAAiB,CAAA;KAAE,CAAC;IACxD,IAAI,EAAE,iBAAiB,CAAM;IAC7B,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,eAAe,CAAC;IAC5B,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,YAAY,CAAC;gBAEjB,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa;IAuB9D,MAAM,CAAC,IAAI,EAAE,mBAAmB,GAAG;QAAE,IAAI,EAAE,iBAAiB,CAAA;KAAE,GAAG,IAAI;CAarE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { makeObservable, observable } from 'mobx';
|
|
2
|
+
import { MerchandisingStore, FacetStore, FilterStore, ResultStore, PaginationStore, SortingStore, QueryStore } from './Stores';
|
|
3
|
+
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
4
|
+
import { StorageStore } from '../Storage/StorageStore';
|
|
5
|
+
export class SearchStore extends AbstractStore {
|
|
6
|
+
constructor(config, services) {
|
|
7
|
+
super(config);
|
|
8
|
+
this.meta = {};
|
|
9
|
+
if (typeof services != 'object' || typeof services.urlManager?.subscribe != 'function') {
|
|
10
|
+
throw new Error(`Invalid service 'urlManager' passed to SearchStore. Missing "subscribe" function.`);
|
|
11
|
+
}
|
|
12
|
+
this.services = services;
|
|
13
|
+
this.storage = new StorageStore();
|
|
14
|
+
this.update({ meta: this.meta });
|
|
15
|
+
makeObservable(this, {
|
|
16
|
+
search: observable,
|
|
17
|
+
merchandising: observable,
|
|
18
|
+
facets: observable,
|
|
19
|
+
filters: observable,
|
|
20
|
+
results: observable,
|
|
21
|
+
pagination: observable,
|
|
22
|
+
sorting: observable,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
update(data) {
|
|
26
|
+
this.error = undefined;
|
|
27
|
+
this.data = JSON.parse(JSON.stringify(data));
|
|
28
|
+
this.loaded = !!data.pagination;
|
|
29
|
+
this.meta = data.meta;
|
|
30
|
+
this.merchandising = new MerchandisingStore(this.services, data.merchandising);
|
|
31
|
+
this.search = new QueryStore(this.services, data.search);
|
|
32
|
+
this.facets = new FacetStore(this.config, this.services, this.storage, data.facets, data.pagination, this.meta);
|
|
33
|
+
this.filters = new FilterStore(this.services, data.filters, this.meta);
|
|
34
|
+
this.results = new ResultStore(this.config, this.services, data.results, data.pagination, data.merchandising);
|
|
35
|
+
this.pagination = new PaginationStore(this.config, this.services, data.pagination);
|
|
36
|
+
this.sorting = new SortingStore(this.services, data.sorting, data.search, this.meta);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StorageStore } from '../../Storage/StorageStore';
|
|
2
|
+
import type { AutocompleteStoreConfig, SearchStoreConfig, StoreServices } from '../../types';
|
|
3
|
+
import type { MetaResponseModel, SearchResponseModelPagination, SearchResponseModelFacet } from '@searchspring/snapi-types';
|
|
4
|
+
export declare class FacetStore extends Array {
|
|
5
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
6
|
+
constructor(config: SearchStoreConfig | AutocompleteStoreConfig, services: StoreServices, storage: StorageStore, facetsData: SearchResponseModelFacet[], pagination: SearchResponseModelPagination, meta: MetaResponseModel);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=FacetStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FacetStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/FacetStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,KAAK,EACX,iBAAiB,EAMjB,6BAA6B,EAC7B,wBAAwB,EAMxB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,UAAW,SAAQ,KAAK;IACpC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEA,MAAM,EAAE,iBAAiB,GAAG,uBAAuB,EACnD,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,wBAAwB,EAAO,EAC3C,UAAU,EAAE,6BAA6B,EACzC,IAAI,EAAE,iBAAiB;CAsCxB"}
|