@searchspring/snap-store-mobx 0.51.1 → 0.52.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/dist/cjs/Autocomplete/AutocompleteStore.js +1 -2
- package/dist/cjs/Cart/CartStore.d.ts +15 -0
- package/dist/cjs/Cart/CartStore.d.ts.map +1 -0
- package/dist/cjs/Cart/CartStore.js +104 -0
- package/dist/cjs/Finder/FinderStore.js +1 -2
- package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts +4 -4
- package/dist/cjs/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
- package/dist/cjs/Finder/Stores/FinderSelectionStore.js +1 -2
- package/dist/cjs/Recommendation/RecommendationStore.d.ts +4 -2
- package/dist/cjs/Recommendation/RecommendationStore.d.ts.map +1 -1
- package/dist/cjs/Recommendation/RecommendationStore.js +6 -2
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.d.ts +1 -0
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.d.ts.map +1 -1
- package/dist/cjs/Recommendation/Stores/RecommendationProfileStore.js +3 -0
- package/dist/cjs/Search/SearchStore.js +1 -2
- package/dist/cjs/Search/Stores/SearchFacetStore.js +4 -4
- package/dist/cjs/Search/Stores/SearchHistoryStore.d.ts +1 -1
- package/dist/cjs/Search/Stores/SearchHistoryStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchMerchandisingStore.d.ts +1 -1
- package/dist/cjs/Search/Stores/SearchMerchandisingStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchMerchandisingStore.js +1 -1
- package/dist/cjs/Search/Stores/SearchResultStore.d.ts +54 -2
- package/dist/cjs/Search/Stores/SearchResultStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchResultStore.js +240 -5
- package/dist/cjs/Search/Stores/SearchSortingStore.d.ts +1 -1
- package/dist/cjs/Search/Stores/SearchSortingStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/index.d.ts +1 -1
- package/dist/cjs/Search/Stores/index.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/index.js +2 -1
- package/dist/cjs/Storage/StorageStore.d.ts +1 -1
- package/dist/cjs/Storage/StorageStore.d.ts.map +1 -1
- package/dist/cjs/Storage/StorageStore.js +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/types.d.ts +23 -12
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +1 -1
- package/dist/esm/Cart/CartStore.d.ts +15 -0
- package/dist/esm/Cart/CartStore.d.ts.map +1 -0
- package/dist/esm/Cart/CartStore.js +69 -0
- package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts +4 -4
- package/dist/esm/Finder/Stores/FinderSelectionStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationStore.d.ts +4 -2
- package/dist/esm/Recommendation/RecommendationStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationStore.js +5 -0
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.d.ts +1 -0
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/Stores/RecommendationProfileStore.js +3 -0
- package/dist/esm/Search/Stores/SearchHistoryStore.d.ts +1 -1
- package/dist/esm/Search/Stores/SearchHistoryStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchMerchandisingStore.d.ts +1 -1
- package/dist/esm/Search/Stores/SearchMerchandisingStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchResultStore.d.ts +54 -2
- package/dist/esm/Search/Stores/SearchResultStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchResultStore.js +207 -2
- package/dist/esm/Search/Stores/SearchSortingStore.d.ts +1 -1
- package/dist/esm/Search/Stores/SearchSortingStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/index.d.ts +1 -1
- package/dist/esm/Search/Stores/index.d.ts.map +1 -1
- package/dist/esm/Search/Stores/index.js +1 -1
- package/dist/esm/Storage/StorageStore.d.ts +1 -1
- package/dist/esm/Storage/StorageStore.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/types.d.ts +23 -12
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FinderStoreConfig, FinderFieldConfig, StoreServices, SelectedSelection, FinderStoreState } from '../../types';
|
|
2
2
|
import type { StorageStore } from '../../Storage/StorageStore';
|
|
3
3
|
import type { MetaResponseModel, MetaResponseModelFacetGrid, MetaResponseModelFacetHierarchy, MetaResponseModelFacetList, MetaResponseModelFacetPalette, MetaResponseModelFacetSlider, SearchResponseModelFacet, SearchResponseModelFacetRange, SearchResponseModelFacetRangeBuckets, SearchResponseModelFacetValue, SearchResponseModelFacetValueAllOfValues } from '@searchspring/snapi-types';
|
|
4
|
-
export
|
|
4
|
+
export type FinderSelectionStoreData = {
|
|
5
5
|
state: FinderStoreState;
|
|
6
6
|
facets: SearchResponseModelFacet[];
|
|
7
7
|
meta: MetaResponseModel;
|
|
@@ -9,7 +9,7 @@ export declare type FinderSelectionStoreData = {
|
|
|
9
9
|
storage: StorageStore;
|
|
10
10
|
selections: SelectedSelection[];
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
type FacetWithMeta = MetaResponseModelFacetGrid & MetaResponseModelFacetHierarchy & MetaResponseModelFacetList & MetaResponseModelFacetPalette & MetaResponseModelFacetSlider & SearchResponseModelFacetValue & SearchResponseModelFacetRange & SearchResponseModelFacetRangeBuckets;
|
|
13
13
|
export declare class FinderSelectionStore extends Array<Selection | SelectionHierarchy> {
|
|
14
14
|
static get [Symbol.species](): ArrayConstructor;
|
|
15
15
|
constructor(config: FinderStoreConfig, services: StoreServices, { state, facets, meta, loading, storage, selections }: FinderSelectionStoreData);
|
|
@@ -34,7 +34,7 @@ declare class SelectionBase {
|
|
|
34
34
|
data?: SearchResponseModelFacetValueAllOfValues[];
|
|
35
35
|
storage: {
|
|
36
36
|
key: string;
|
|
37
|
-
get: (key?: string
|
|
37
|
+
get: (key?: string) => any;
|
|
38
38
|
set: (key: string, value: unknown) => void;
|
|
39
39
|
};
|
|
40
40
|
constructor(services: StoreServices, id: string, state: FinderStoreState, facet: FacetWithMeta, selectionConfig: FinderFieldConfig | LevelConfig, loading: boolean, storageStore: StorageStore);
|
|
@@ -51,7 +51,7 @@ declare class SelectionHierarchy extends SelectionBase {
|
|
|
51
51
|
constructor(services: StoreServices, id: string, state: FinderStoreState, facet: FacetWithMeta, config: LevelConfig, loading: boolean, storageStore: StorageStore);
|
|
52
52
|
select(value?: string): void;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
type LevelConfig = {
|
|
55
55
|
index: number;
|
|
56
56
|
label?: string;
|
|
57
57
|
key: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FinderSelectionStore.d.ts","sourceRoot":"","sources":["../../../../src/Finder/Stores/FinderSelectionStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC5H,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACX,iBAAiB,EACjB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC5B,wBAAwB,EACxB,6BAA6B,EAC7B,oCAAoC,EACpC,6BAA6B,EAC7B,wCAAwC,EACxC,MAAM,2BAA2B,CAAC;AAEnC,
|
|
1
|
+
{"version":3,"file":"FinderSelectionStore.d.ts","sourceRoot":"","sources":["../../../../src/Finder/Stores/FinderSelectionStore.ts"],"names":[],"mappings":"AAA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AAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
2
|
-
import {
|
|
2
|
+
import { Product } from '../Search/Stores';
|
|
3
|
+
import { CartStore } from '../Cart/CartStore';
|
|
3
4
|
import { RecommendationProfileStore } from './Stores';
|
|
4
5
|
import type { RecommendationStoreConfig, StoreServices } from '../types';
|
|
5
6
|
import type { RecommendCombinedResponseModel } from '@searchspring/snap-client';
|
|
@@ -7,7 +8,8 @@ export declare class RecommendationStore extends AbstractStore {
|
|
|
7
8
|
services: StoreServices;
|
|
8
9
|
loaded: boolean;
|
|
9
10
|
profile: RecommendationProfileStore;
|
|
10
|
-
results:
|
|
11
|
+
results: Product[];
|
|
12
|
+
cart: CartStore;
|
|
11
13
|
constructor(config: RecommendationStoreConfig, services: StoreServices);
|
|
12
14
|
reset(): void;
|
|
13
15
|
update(data?: RecommendCombinedResponseModel): void;
|
|
@@ -1 +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,
|
|
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,OAAO,EAAqB,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAEhF,qBAAa,mBAAoB,SAAQ,aAAa;IAC9C,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,UAAS;IACf,OAAO,EAAG,0BAA0B,CAAC;IACrC,OAAO,EAAG,OAAO,EAAE,CAAC;IACpB,IAAI,EAAG,SAAS,CAAC;gBAEZ,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,aAAa;IAiB/D,KAAK,IAAI,IAAI;IAIb,MAAM,CAAC,IAAI,CAAC,EAAE,8BAA8B,GAAG,IAAI;CAW1D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { makeObservable, observable } from 'mobx';
|
|
2
2
|
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
3
3
|
import { SearchResultStore } from '../Search/Stores';
|
|
4
|
+
import { CartStore } from '../Cart/CartStore';
|
|
4
5
|
import { RecommendationProfileStore } from './Stores';
|
|
5
6
|
export class RecommendationStore extends AbstractStore {
|
|
6
7
|
constructor(config, services) {
|
|
@@ -24,5 +25,9 @@ export class RecommendationStore extends AbstractStore {
|
|
|
24
25
|
this.loaded = !!data?.profile;
|
|
25
26
|
this.profile = new RecommendationProfileStore(this.services, data);
|
|
26
27
|
this.results = new SearchResultStore(this.config, this.services, data?.results);
|
|
28
|
+
// only create a cart store when type is bundle
|
|
29
|
+
if (this.profile.type == 'bundle') {
|
|
30
|
+
this.cart = new CartStore();
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
}
|
|
@@ -4,6 +4,7 @@ export declare class RecommendationProfileStore {
|
|
|
4
4
|
tag: string;
|
|
5
5
|
placement: string;
|
|
6
6
|
display: Record<string, any>;
|
|
7
|
+
type?: string | undefined;
|
|
7
8
|
constructor(services: StoreServices, data?: RecommendCombinedResponseModel);
|
|
8
9
|
}
|
|
9
10
|
//# sourceMappingURL=RecommendationProfileStore.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationProfileStore.d.ts","sourceRoot":"","sources":["../../../../src/Recommendation/Stores/RecommendationProfileStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAEhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,qBAAa,0BAA0B;IAC/B,GAAG,EAAG,MAAM,CAAC;IACb,SAAS,EAAG,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;
|
|
1
|
+
{"version":3,"file":"RecommendationProfileStore.d.ts","sourceRoot":"","sources":["../../../../src/Recommendation/Stores/RecommendationProfileStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAEhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,qBAAa,0BAA0B;IAC/B,GAAG,EAAG,MAAM,CAAC;IACb,SAAS,EAAG,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;IAClC,IAAI,CAAC,qBAAa;gBAEb,QAAQ,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,8BAA8B;CAiB1E"}
|
|
@@ -2,16 +2,19 @@ import { observable, makeObservable } from 'mobx';
|
|
|
2
2
|
export class RecommendationProfileStore {
|
|
3
3
|
constructor(services, data) {
|
|
4
4
|
this.display = {};
|
|
5
|
+
this.type = 'default';
|
|
5
6
|
if (!data?.profile?.tag) {
|
|
6
7
|
return;
|
|
7
8
|
}
|
|
8
9
|
this.tag = data.profile.tag;
|
|
9
10
|
this.placement = data.profile.placement;
|
|
10
11
|
this.display = data.profile.display;
|
|
12
|
+
this.type = data.profile.display.template.type;
|
|
11
13
|
makeObservable(this, {
|
|
12
14
|
tag: observable,
|
|
13
15
|
placement: observable,
|
|
14
16
|
display: observable,
|
|
17
|
+
type: observable,
|
|
15
18
|
});
|
|
16
19
|
}
|
|
17
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchHistoryStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchHistoryStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,
|
|
1
|
+
{"version":3,"file":"SearchHistoryStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchHistoryStore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAAG;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AACF,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,aAAa;IAqC/D,IAAI,OAAO,IAAI,KAAK,EAAE,CAGrB;IAEM,IAAI,CAAC,IAAI,EAAE,MAAM;IAoBjB,MAAM,CAAC,IAAI,EAAE,MAAM;IAWnB,KAAK,IAAI,IAAI;IAIb,aAAa,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;CAmB9C"}
|
|
@@ -7,7 +7,7 @@ export declare enum ContentType {
|
|
|
7
7
|
LEFT = "left",
|
|
8
8
|
INLINE = "inline"
|
|
9
9
|
}
|
|
10
|
-
export
|
|
10
|
+
export type BannerContent = Partial<Record<ContentType, Content>>;
|
|
11
11
|
export declare class SearchMerchandisingStore {
|
|
12
12
|
redirect: string;
|
|
13
13
|
content: BannerContent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchMerchandisingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchMerchandisingStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,gCAAgC,EAChC,6CAA6C,EAC7C,yCAAyC,EACzC,MAAM,2BAA2B,CAAC;AAEnC,oBAAY,WAAW;IACtB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;CACjB;AAED,
|
|
1
|
+
{"version":3,"file":"SearchMerchandisingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchMerchandisingStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,gCAAgC,EAChC,6CAA6C,EAC7C,yCAAyC,EACzC,MAAM,2BAA2B,CAAC;AAEnC,oBAAY,WAAW;IACtB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAElE,qBAAa,wBAAwB;IAC7B,QAAQ,SAAM;IACd,OAAO,EAAE,aAAa,CAAM;IAC5B,SAAS,EAAE,yCAAyC,EAAE,CAAM;IAC5D,WAAW,CAAC,EAAE,yCAAyC,CAAC;IACxD,YAAY,CAAC,EAAE,OAAO,CAAC;gBAElB,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,gCAAgC;CAwBhF;AAED,cAAM,OAAQ,SAAQ,KAAK,CAAC,MAAM,GAAG,6CAA6C,CAAC;IAClF,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEW,OAAO,EAAE,MAAM,EAAE,GAAG,6CAA6C,EAAE;CAG/E"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StoreServices, StoreConfigs } from '../../types';
|
|
1
|
+
import type { StoreServices, StoreConfigs, VariantSelectionOptions } from '../../types';
|
|
2
2
|
import type { SearchResponseModelResult, SearchResponseModelPagination, SearchResponseModelMerchandising, SearchResponseModelResultMappings, SearchResponseModelMerchandisingContentInline, SearchResponseModelMerchandisingContentConfig } from '@searchspring/snapi-types';
|
|
3
3
|
export declare class SearchResultStore extends Array<Product | Banner> {
|
|
4
4
|
static get [Symbol.species](): ArrayConstructor;
|
|
@@ -14,6 +14,11 @@ export declare class Banner {
|
|
|
14
14
|
value: string;
|
|
15
15
|
constructor(services: StoreServices, banner: SearchResponseModelMerchandisingContentInline);
|
|
16
16
|
}
|
|
17
|
+
type VariantData = {
|
|
18
|
+
mappings: SearchResponseModelResultMappings;
|
|
19
|
+
attributes: Record<string, unknown>;
|
|
20
|
+
options: Record<string, string>;
|
|
21
|
+
};
|
|
17
22
|
export declare class Product {
|
|
18
23
|
type: string;
|
|
19
24
|
id: string;
|
|
@@ -21,7 +26,54 @@ export declare class Product {
|
|
|
21
26
|
mappings: SearchResponseModelResultMappings;
|
|
22
27
|
custom: {};
|
|
23
28
|
children?: Array<Child>;
|
|
24
|
-
|
|
29
|
+
quantity: number;
|
|
30
|
+
display: VariantData;
|
|
31
|
+
variants?: Variants;
|
|
32
|
+
constructor(services: StoreServices, result: SearchResponseModelResult, config?: StoreConfigs);
|
|
33
|
+
updateDisplay: (display?: {
|
|
34
|
+
mappings: SearchResponseModelResultMappings;
|
|
35
|
+
attributes: Record<string, unknown>;
|
|
36
|
+
options: Record<string, string>;
|
|
37
|
+
}) => void;
|
|
38
|
+
}
|
|
39
|
+
declare class Variants {
|
|
40
|
+
active?: Variant;
|
|
41
|
+
data: Variant[];
|
|
42
|
+
selections: VariantSelection[];
|
|
43
|
+
config: StoreConfigs;
|
|
44
|
+
updateDisplay: (variant: VariantData) => void;
|
|
45
|
+
constructor(config: StoreConfigs, services: StoreServices, variantData: VariantData[], updateDisplay: (variant: VariantData) => void);
|
|
46
|
+
setActive(variant: Variant): void;
|
|
47
|
+
makeSelections(options?: Record<string, string>): void;
|
|
48
|
+
update(fromSelection: VariantSelection): void;
|
|
49
|
+
}
|
|
50
|
+
type SelectionValue = {
|
|
51
|
+
value: string;
|
|
52
|
+
label?: string;
|
|
53
|
+
thumbnailImageUrl?: string;
|
|
54
|
+
background?: string;
|
|
55
|
+
available?: boolean;
|
|
56
|
+
};
|
|
57
|
+
export declare class VariantSelection {
|
|
58
|
+
field: string;
|
|
59
|
+
label: string;
|
|
60
|
+
selected?: string;
|
|
61
|
+
previouslySelected?: string;
|
|
62
|
+
values: SelectionValue[];
|
|
63
|
+
private variants;
|
|
64
|
+
constructor(config: StoreConfigs, services: StoreServices, variants: Variants, selectorConfig: VariantSelectionOptions, data: Variant[]);
|
|
65
|
+
refineSelections(allVariants: Variant[]): void;
|
|
66
|
+
reset(): void;
|
|
67
|
+
select(value: string, internalSelection?: boolean): void;
|
|
68
|
+
}
|
|
69
|
+
declare class Variant {
|
|
70
|
+
type: string;
|
|
71
|
+
available: boolean;
|
|
72
|
+
attributes: Record<string, unknown>;
|
|
73
|
+
options: Record<string, string>;
|
|
74
|
+
mappings: SearchResponseModelResultMappings;
|
|
75
|
+
custom: {};
|
|
76
|
+
constructor(services: StoreServices, variantData: VariantData);
|
|
25
77
|
}
|
|
26
78
|
declare class Child {
|
|
27
79
|
type: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchResultStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchResultStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SearchResultStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchResultStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAqB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E,cAAc,EAAE,CAAM;IACrC,OAAO,CAAC,QAAQ,CAAW;gBAEf,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,uBAAuB,EAAE,IAAI,EAAE,OAAO,EAAE;IAgBhI,gBAAgB,CAAC,WAAW,EAAE,OAAO,EAAE;IAqDvC,KAAK;IAKL,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,iBAAiB,UAAQ;CAWtD;AAED,cAAM,OAAO;IACL,IAAI,SAAa;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACrC,QAAQ,EAAE,iCAAiC,CAEhD;IACK,MAAM,KAAM;gBAEP,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW;CAa7D;AAED,cAAM,KAAK;IACH,IAAI,SAAW;IACf,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IACzC,MAAM,KAAM;gBAEP,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,yBAAyB;CAUtE"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { makeObservable, observable } from 'mobx';
|
|
2
|
+
import deepmerge from 'deepmerge';
|
|
3
|
+
import { isPlainObject } from 'is-plain-object';
|
|
2
4
|
export class SearchResultStore extends Array {
|
|
3
5
|
static get [Symbol.species]() {
|
|
4
6
|
return Array;
|
|
5
7
|
}
|
|
6
8
|
constructor(config, services, resultData, paginationData, merchData) {
|
|
7
9
|
let results = (resultData || []).map((result) => {
|
|
8
|
-
return new Product(services, result);
|
|
10
|
+
return new Product(services, result, config);
|
|
9
11
|
});
|
|
10
12
|
if (merchData?.content?.inline) {
|
|
11
13
|
const banners = merchData.content.inline
|
|
@@ -41,7 +43,7 @@ export class Banner {
|
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
export class Product {
|
|
44
|
-
constructor(services, result) {
|
|
46
|
+
constructor(services, result, config) {
|
|
45
47
|
this.type = 'product';
|
|
46
48
|
this.attributes = {};
|
|
47
49
|
this.mappings = {
|
|
@@ -49,9 +51,42 @@ export class Product {
|
|
|
49
51
|
};
|
|
50
52
|
this.custom = {};
|
|
51
53
|
this.children = [];
|
|
54
|
+
this.quantity = 1;
|
|
55
|
+
this.display = {
|
|
56
|
+
mappings: {
|
|
57
|
+
core: {},
|
|
58
|
+
},
|
|
59
|
+
attributes: {},
|
|
60
|
+
options: {},
|
|
61
|
+
};
|
|
62
|
+
this.updateDisplay = (display) => {
|
|
63
|
+
const defaultDisplay = {
|
|
64
|
+
mappings: this.mappings,
|
|
65
|
+
attributes: this.attributes,
|
|
66
|
+
options: {},
|
|
67
|
+
};
|
|
68
|
+
const newDisplay = deepmerge(defaultDisplay, display || defaultDisplay, { isMergeableObject: isPlainObject });
|
|
69
|
+
if (JSON.stringify(this.display) !== JSON.stringify(newDisplay)) {
|
|
70
|
+
this.display = newDisplay;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
52
73
|
this.id = result.id;
|
|
53
74
|
this.attributes = result.attributes;
|
|
54
75
|
this.mappings = result.mappings;
|
|
76
|
+
//initialize the display
|
|
77
|
+
this.updateDisplay();
|
|
78
|
+
const variantsField = config?.settings?.variants?.field;
|
|
79
|
+
if (config && variantsField && this.attributes && this.attributes[variantsField]) {
|
|
80
|
+
try {
|
|
81
|
+
// parse the field (JSON)
|
|
82
|
+
const parsedVariants = JSON.parse(this.attributes[variantsField]);
|
|
83
|
+
this.variants = new Variants(config, services, parsedVariants, this.updateDisplay);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
// failed to parse the variant JSON
|
|
87
|
+
console.error(err, `Invalid variant JSON for product id: ${result.id}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
55
90
|
if (result?.children?.length) {
|
|
56
91
|
this.children = result.children.map((variant, index) => {
|
|
57
92
|
return new Child(services, {
|
|
@@ -62,8 +97,10 @@ export class Product {
|
|
|
62
97
|
}
|
|
63
98
|
makeObservable(this, {
|
|
64
99
|
id: observable,
|
|
100
|
+
display: observable,
|
|
65
101
|
attributes: observable,
|
|
66
102
|
custom: observable,
|
|
103
|
+
quantity: observable,
|
|
67
104
|
});
|
|
68
105
|
// must set all subo
|
|
69
106
|
const coreObservables = Object.keys(this.mappings.core).reduce((map, key) => {
|
|
@@ -75,6 +112,174 @@ export class Product {
|
|
|
75
112
|
makeObservable(this.mappings.core, coreObservables);
|
|
76
113
|
}
|
|
77
114
|
}
|
|
115
|
+
class Variants {
|
|
116
|
+
constructor(config, services, variantData, updateDisplay) {
|
|
117
|
+
this.data = [];
|
|
118
|
+
this.selections = [];
|
|
119
|
+
const options = [];
|
|
120
|
+
// create variants objects
|
|
121
|
+
this.data = variantData.map((variant) => {
|
|
122
|
+
Object.keys(variant.options).forEach((variantOption) => {
|
|
123
|
+
if (!options.includes(variantOption)) {
|
|
124
|
+
options.push(variantOption);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return new Variant(services, variant);
|
|
128
|
+
});
|
|
129
|
+
this.config = config;
|
|
130
|
+
this.updateDisplay = updateDisplay;
|
|
131
|
+
options.map((option) => {
|
|
132
|
+
// TODO - merge with variant config before constructing selection (for label overrides and swatch mappings)
|
|
133
|
+
const optionConfig = {
|
|
134
|
+
field: option,
|
|
135
|
+
label: option,
|
|
136
|
+
};
|
|
137
|
+
this.selections.push(new VariantSelection(config, services, this, optionConfig, this.data));
|
|
138
|
+
});
|
|
139
|
+
// select first available
|
|
140
|
+
this.makeSelections();
|
|
141
|
+
}
|
|
142
|
+
setActive(variant) {
|
|
143
|
+
this.active = variant;
|
|
144
|
+
this.updateDisplay(this.active);
|
|
145
|
+
}
|
|
146
|
+
makeSelections(options) {
|
|
147
|
+
// TODO - support for affinity to attempt to pre-selected options
|
|
148
|
+
// options = {color: 'Blue', size: 'L'};
|
|
149
|
+
if (!options) {
|
|
150
|
+
// select first available for each selection
|
|
151
|
+
this.selections.forEach((selection) => {
|
|
152
|
+
const firstAvailableOption = selection.values.find((value) => value.available);
|
|
153
|
+
if (firstAvailableOption) {
|
|
154
|
+
selection.select(firstAvailableOption.value);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
update(fromSelection) {
|
|
160
|
+
// need to ensure the update originator is at the BOTTOM of the list for refinement
|
|
161
|
+
const orderedSelections = [...this.selections];
|
|
162
|
+
orderedSelections.sort((a) => {
|
|
163
|
+
if (a.field == fromSelection.field) {
|
|
164
|
+
return 1;
|
|
165
|
+
}
|
|
166
|
+
return -1;
|
|
167
|
+
});
|
|
168
|
+
// refine selections ensuring that the selection that triggered the update refines LAST
|
|
169
|
+
orderedSelections.forEach((selection) => selection.refineSelections(this.data));
|
|
170
|
+
// check to see if we have enough selections made to update the display
|
|
171
|
+
const selectedSelections = this.selections.filter((selection) => selection.selected?.length);
|
|
172
|
+
if (selectedSelections.length) {
|
|
173
|
+
let availableVariants = this.data;
|
|
174
|
+
// loop through selectedSelections and only include available products that match current selections
|
|
175
|
+
for (const selectedSelection of selectedSelections) {
|
|
176
|
+
availableVariants = availableVariants.filter((variant) => selectedSelection.selected == variant.options[selectedSelection.field] && variant.available);
|
|
177
|
+
}
|
|
178
|
+
// set active variant
|
|
179
|
+
if (availableVariants.length == 1) {
|
|
180
|
+
this.setActive(availableVariants[0]);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export class VariantSelection {
|
|
186
|
+
constructor(config, services, variants, selectorConfig, data) {
|
|
187
|
+
this.selected = ''; //ex: blue
|
|
188
|
+
this.previouslySelected = '';
|
|
189
|
+
this.values = [];
|
|
190
|
+
this.field = selectorConfig.field;
|
|
191
|
+
this.label = selectorConfig.label;
|
|
192
|
+
// reference to parent variants
|
|
193
|
+
this.variants = variants;
|
|
194
|
+
// create possible values from the data and refine them
|
|
195
|
+
this.refineSelections(data);
|
|
196
|
+
makeObservable(this, {
|
|
197
|
+
selected: observable,
|
|
198
|
+
values: observable,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
refineSelections(allVariants) {
|
|
202
|
+
// current selection should only consider OTHER selections for availability
|
|
203
|
+
const selectedSelections = this.variants.selections.filter((selection) => selection.field != this.field && selection.selected);
|
|
204
|
+
let availableVariants = allVariants;
|
|
205
|
+
// loop through selectedSelections and remove products that do not match
|
|
206
|
+
for (const selectedSelection of selectedSelections) {
|
|
207
|
+
availableVariants = availableVariants.filter((variant) => selectedSelection.selected == variant.options[selectedSelection.field] && variant.available);
|
|
208
|
+
}
|
|
209
|
+
const newValues = allVariants
|
|
210
|
+
.filter((variant) => variant.options[this.field])
|
|
211
|
+
.reduce((values, variant) => {
|
|
212
|
+
if (!values.some((val) => variant.options[this.field] == val.value)) {
|
|
213
|
+
values.push({
|
|
214
|
+
value: variant.options[this.field],
|
|
215
|
+
label: variant.options[this.field], // TODO - use configurable mappings
|
|
216
|
+
// TODO set background for swatches (via configurable mappings)
|
|
217
|
+
thumbnailImageUrl: variant.mappings.core?.thumbnailImageUrl,
|
|
218
|
+
available: Boolean(availableVariants.some((availableVariant) => availableVariant.options[this.field] == variant.options[this.field])),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return values;
|
|
222
|
+
}, []);
|
|
223
|
+
// if selection has been made
|
|
224
|
+
if (this.selected) {
|
|
225
|
+
//is that selection still available?
|
|
226
|
+
if (!newValues.some((val) => val.value == this.selected && val.available)) {
|
|
227
|
+
// the previous selection is no longer available
|
|
228
|
+
if (this.previouslySelected && newValues.some((val) => val.value == this.previouslySelected && val.available)) {
|
|
229
|
+
if (this.selected !== this.previouslySelected) {
|
|
230
|
+
this.select(this.previouslySelected, true);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
//otherwise just choose the first available option
|
|
235
|
+
const availableValues = newValues.filter((val) => val.available);
|
|
236
|
+
if (newValues.length && availableValues.length) {
|
|
237
|
+
const nextAvailableValue = availableValues[0].value;
|
|
238
|
+
if (this.selected !== nextAvailableValue) {
|
|
239
|
+
this.select(nextAvailableValue, true);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
this.values = newValues;
|
|
246
|
+
}
|
|
247
|
+
reset() {
|
|
248
|
+
this.selected = '';
|
|
249
|
+
this.values.forEach((val) => (val.available = false));
|
|
250
|
+
}
|
|
251
|
+
select(value, internalSelection = false) {
|
|
252
|
+
const valueExist = this.values.find((val) => val.value == value);
|
|
253
|
+
if (valueExist) {
|
|
254
|
+
this.selected = value;
|
|
255
|
+
if (!internalSelection) {
|
|
256
|
+
this.previouslySelected = value;
|
|
257
|
+
}
|
|
258
|
+
this.variants.update(this);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class Variant {
|
|
263
|
+
constructor(services, variantData) {
|
|
264
|
+
this.type = 'variant';
|
|
265
|
+
this.attributes = {};
|
|
266
|
+
this.options = {};
|
|
267
|
+
this.mappings = {
|
|
268
|
+
core: {},
|
|
269
|
+
};
|
|
270
|
+
this.custom = {};
|
|
271
|
+
this.attributes = variantData.attributes;
|
|
272
|
+
this.mappings = variantData.mappings;
|
|
273
|
+
this.options = variantData.options;
|
|
274
|
+
this.available = this.attributes.available || false;
|
|
275
|
+
makeObservable(this, {
|
|
276
|
+
attributes: observable,
|
|
277
|
+
mappings: observable,
|
|
278
|
+
custom: observable,
|
|
279
|
+
available: observable,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
78
283
|
class Child {
|
|
79
284
|
constructor(services, result) {
|
|
80
285
|
this.type = 'child';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { UrlManager } from '@searchspring/snap-url-manager';
|
|
2
2
|
import type { StoreServices } from '../../types';
|
|
3
3
|
import type { MetaResponseModel, MetaResponseModelSortOption, SearchResponseModelSearch, SearchResponseModelSorting } from '@searchspring/snapi-types';
|
|
4
|
-
|
|
4
|
+
type MetaResponseModelSortOptionMutated = MetaResponseModelSortOption & {
|
|
5
5
|
active?: boolean;
|
|
6
6
|
default?: boolean;
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchSortingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchSortingStore.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,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,
|
|
1
|
+
{"version":3,"file":"SearchSortingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchSortingStore.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,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,KAAK,kCAAkC,GAAG,2BAA2B,GAAG;IACvE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,qBAAa,kBAAkB;IACvB,OAAO,EAAE,MAAM,EAAE,CAAM;gBAElB,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,0BAA0B,EAAE,EAAE,MAAM,EAAE,yBAAyB,EAAE,IAAI,EAAE,iBAAiB;IAsCtI,IAAW,OAAO,IAAI,MAAM,GAAG,SAAS,CAEvC;CACD;AAED,cAAM,MAAM;IACJ,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;gBAEX,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,kCAAkC,EAAE,KAAK,EAAE,MAAM;CAuB9F"}
|
|
@@ -2,7 +2,7 @@ export { SearchMerchandisingStore, BannerContent, ContentType } from './SearchMe
|
|
|
2
2
|
export { SearchFacetStore, ValueFacet, RangeFacet, FacetValue, FacetHierarchyValue, FacetRangeValue } from './SearchFacetStore';
|
|
3
3
|
export { SearchFilterStore, Filter } from './SearchFilterStore';
|
|
4
4
|
export { SearchPaginationStore } from './SearchPaginationStore';
|
|
5
|
-
export { SearchResultStore, Product, Banner } from './SearchResultStore';
|
|
5
|
+
export { SearchResultStore, Product, Banner, VariantSelection } from './SearchResultStore';
|
|
6
6
|
export { SearchSortingStore } from './SearchSortingStore';
|
|
7
7
|
export { SearchQueryStore } from './SearchQueryStore';
|
|
8
8
|
export { SearchHistoryStore } from './SearchHistoryStore';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChI,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAChI,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -2,7 +2,7 @@ export { SearchMerchandisingStore, ContentType } from './SearchMerchandisingStor
|
|
|
2
2
|
export { SearchFacetStore, ValueFacet, RangeFacet, FacetValue, FacetHierarchyValue, FacetRangeValue } from './SearchFacetStore';
|
|
3
3
|
export { SearchFilterStore, Filter } from './SearchFilterStore';
|
|
4
4
|
export { SearchPaginationStore } from './SearchPaginationStore';
|
|
5
|
-
export { SearchResultStore, Product, Banner } from './SearchResultStore';
|
|
5
|
+
export { SearchResultStore, Product, Banner, VariantSelection } from './SearchResultStore';
|
|
6
6
|
export { SearchSortingStore } from './SearchSortingStore';
|
|
7
7
|
export { SearchQueryStore } from './SearchQueryStore';
|
|
8
8
|
export { SearchHistoryStore } from './SearchHistoryStore';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageStore.d.ts","sourceRoot":"","sources":["../../../src/Storage/StorageStore.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACxB,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAgB;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAE3B,MAAM,CAAC,EAAE,aAAa;IA8C3B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAyBnC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAiClC,KAAK,IAAI,IAAI;CAcpB;AAED,
|
|
1
|
+
{"version":3,"file":"StorageStore.d.ts","sourceRoot":"","sources":["../../../src/Storage/StorageStore.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACxB,OAAO,CAAC,IAAI,CAA4B;IACxC,OAAO,CAAC,UAAU,CAAe;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,GAAG,CAAgB;IACpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM;gBAE3B,MAAM,CAAC,EAAE,aAAa;IA8C3B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAyBnC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAiClC,KAAK,IAAI,IAAI;CAcpB;AAED,MAAM,MAAM,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;IACjB,MAAM,WAAW;CACjB"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { FinderStore } from './Finder/FinderStore';
|
|
|
4
4
|
export { SearchStore } from './Search/SearchStore';
|
|
5
5
|
export * from './Search/Stores/';
|
|
6
6
|
export { RecommendationStore } from './Recommendation/RecommendationStore';
|
|
7
|
+
export { CartStore } from './Cart/CartStore';
|
|
7
8
|
export { StorageStore, StorageConfig, StorageType } from './Storage/StorageStore';
|
|
8
9
|
export * from './types';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +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,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAElF,cAAc,SAAS,CAAC"}
|
|
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,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAElF,cAAc,SAAS,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -4,5 +4,6 @@ export { FinderStore } from './Finder/FinderStore';
|
|
|
4
4
|
export { SearchStore } from './Search/SearchStore';
|
|
5
5
|
export * from './Search/Stores/';
|
|
6
6
|
export { RecommendationStore } from './Recommendation/RecommendationStore';
|
|
7
|
+
export { CartStore } from './Cart/CartStore';
|
|
7
8
|
export { StorageStore, StorageType } from './Storage/StorageStore';
|
|
8
9
|
export * from './types';
|