@searchspring/snap-store-mobx 0.53.4 → 0.55.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.d.ts +2 -1
- package/dist/cjs/Autocomplete/AutocompleteStore.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/AutocompleteStore.js +7 -6
- package/dist/cjs/Finder/FinderStore.d.ts +3 -2
- package/dist/cjs/Finder/FinderStore.d.ts.map +1 -1
- package/dist/cjs/Finder/FinderStore.js +5 -5
- package/dist/cjs/Meta/MetaStore.d.ts +15 -0
- package/dist/cjs/Meta/MetaStore.d.ts.map +1 -0
- package/dist/cjs/Meta/MetaStore.js +54 -0
- package/dist/cjs/Recommendation/RecommendationStore.d.ts +6 -1
- package/dist/cjs/Recommendation/RecommendationStore.d.ts.map +1 -1
- package/dist/cjs/Recommendation/RecommendationStore.js +3 -1
- package/dist/cjs/Search/SearchStore.d.ts +2 -1
- package/dist/cjs/Search/SearchStore.d.ts.map +1 -1
- package/dist/cjs/Search/SearchStore.js +7 -6
- package/dist/cjs/Search/Stores/SearchHistoryStore.js +1 -1
- package/dist/cjs/Search/Stores/SearchResultStore.d.ts +28 -10
- package/dist/cjs/Search/Stores/SearchResultStore.d.ts.map +1 -1
- package/dist/cjs/Search/Stores/SearchResultStore.js +152 -45
- package/dist/cjs/Storage/StorageStore.d.ts +5 -5
- package/dist/cjs/Storage/StorageStore.d.ts.map +1 -1
- package/dist/cjs/Storage/StorageStore.js +17 -17
- 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 +8 -3
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts +2 -1
- package/dist/esm/Autocomplete/AutocompleteStore.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteStore.js +7 -6
- package/dist/esm/Finder/FinderStore.d.ts +3 -2
- package/dist/esm/Finder/FinderStore.d.ts.map +1 -1
- package/dist/esm/Finder/FinderStore.js +6 -6
- package/dist/esm/Meta/MetaStore.d.ts +15 -0
- package/dist/esm/Meta/MetaStore.d.ts.map +1 -0
- package/dist/esm/Meta/MetaStore.js +44 -0
- package/dist/esm/Recommendation/RecommendationStore.d.ts +6 -1
- package/dist/esm/Recommendation/RecommendationStore.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationStore.js +3 -1
- package/dist/esm/Search/SearchStore.d.ts +2 -1
- package/dist/esm/Search/SearchStore.d.ts.map +1 -1
- package/dist/esm/Search/SearchStore.js +7 -6
- package/dist/esm/Search/Stores/SearchHistoryStore.js +2 -2
- package/dist/esm/Search/Stores/SearchResultStore.d.ts +28 -10
- package/dist/esm/Search/Stores/SearchResultStore.d.ts.map +1 -1
- package/dist/esm/Search/Stores/SearchResultStore.js +139 -39
- package/dist/esm/Storage/StorageStore.d.ts +5 -5
- package/dist/esm/Storage/StorageStore.d.ts.map +1 -1
- package/dist/esm/Storage/StorageStore.js +17 -17
- 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 +8 -3
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { makeObservable, observable } from 'mobx';
|
|
2
2
|
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
3
3
|
import { SearchPaginationStore } from '../Search/Stores';
|
|
4
|
-
import { StorageStore
|
|
4
|
+
import { StorageStore } from '../Storage/StorageStore';
|
|
5
5
|
import { FinderSelectionStore } from './Stores';
|
|
6
|
+
import { MetaStore } from '../Meta/MetaStore';
|
|
6
7
|
export class FinderStore extends AbstractStore {
|
|
7
8
|
constructor(config, services) {
|
|
8
9
|
super(config);
|
|
9
|
-
this.meta = {};
|
|
10
10
|
this.state = {
|
|
11
11
|
persisted: false,
|
|
12
12
|
};
|
|
@@ -30,7 +30,7 @@ export class FinderStore extends AbstractStore {
|
|
|
30
30
|
this.services = services;
|
|
31
31
|
if (config.persist?.enabled) {
|
|
32
32
|
this.persistedStorage = new StorageStore({
|
|
33
|
-
type:
|
|
33
|
+
type: 'local',
|
|
34
34
|
key: `ss-${config.id}-persisted`,
|
|
35
35
|
});
|
|
36
36
|
}
|
|
@@ -72,12 +72,12 @@ export class FinderStore extends AbstractStore {
|
|
|
72
72
|
update(data, selectedSelections) {
|
|
73
73
|
this.error = undefined;
|
|
74
74
|
this.loaded = !!data.pagination;
|
|
75
|
-
this.meta = data.meta;
|
|
76
|
-
this.pagination = new SearchPaginationStore(this.config, this.services, data.pagination, this.meta);
|
|
75
|
+
this.meta = new MetaStore(data.meta);
|
|
76
|
+
this.pagination = new SearchPaginationStore(this.config, this.services, data.pagination, this.meta.data);
|
|
77
77
|
this.selections = new FinderSelectionStore(this.config, this.services, {
|
|
78
78
|
state: this.state,
|
|
79
79
|
facets: data.facets || [],
|
|
80
|
-
meta: this.meta,
|
|
80
|
+
meta: this.meta.data,
|
|
81
81
|
loading: this.loading,
|
|
82
82
|
storage: this.storage,
|
|
83
83
|
selections: selectedSelections || [],
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MetaResponseModel } from '@searchspring/snapi-types';
|
|
2
|
+
export declare class MetaStore {
|
|
3
|
+
data: MetaResponseModel;
|
|
4
|
+
badges: MetaBadges;
|
|
5
|
+
constructor(metaData?: MetaResponseModel);
|
|
6
|
+
}
|
|
7
|
+
declare class MetaBadges {
|
|
8
|
+
groups: Record<string, {
|
|
9
|
+
sections: string[];
|
|
10
|
+
grid: string[][];
|
|
11
|
+
}>;
|
|
12
|
+
constructor(metaData?: MetaResponseModel);
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=MetaStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaStore.d.ts","sourceRoot":"","sources":["../../../src/Meta/MetaStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,qBAAa,SAAS;IACd,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,UAAU,CAAC;gBAEd,QAAQ,CAAC,EAAE,iBAAiB;CAIxC;AAED,cAAM,UAAU;IACR,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;KAAE,CAAC,CAAM;gBAEjE,QAAQ,CAAC,EAAE,iBAAiB;CA8BxC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export class MetaStore {
|
|
2
|
+
constructor(metaData) {
|
|
3
|
+
this.data = metaData ?? {};
|
|
4
|
+
this.badges = new MetaBadges(this.data);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
class MetaBadges {
|
|
8
|
+
constructor(metaData) {
|
|
9
|
+
this.groups = {};
|
|
10
|
+
// 'overlay' group is created by default - could support additional groups via config in the future
|
|
11
|
+
const groups = { overlay: { sections: ['left', 'right'] } };
|
|
12
|
+
// process groups - create the grid for each group
|
|
13
|
+
Object.keys(groups).map((name) => {
|
|
14
|
+
const group = groups[name];
|
|
15
|
+
const sections = group.sections.map((section) => ({
|
|
16
|
+
areas: metaData?.badges?.locations?.[section]?.map((area) => area.tag) || [],
|
|
17
|
+
grid: [],
|
|
18
|
+
}));
|
|
19
|
+
// find lcm of sections
|
|
20
|
+
const lcmSections = sections.map((section) => section.areas.length).reduce(lcm);
|
|
21
|
+
sections.forEach((section) => {
|
|
22
|
+
section.grid = Array.from({ length: lcmSections }).map((_, index) => section.areas[Math.floor(index / (lcmSections / section.areas.length))]);
|
|
23
|
+
});
|
|
24
|
+
// set the grid by creating rows of columns
|
|
25
|
+
const grid = Array.from({ length: lcmSections }).map((_, i) => {
|
|
26
|
+
return sections.map((section) => section.grid[i]);
|
|
27
|
+
});
|
|
28
|
+
this.groups[name] = {
|
|
29
|
+
sections: group.sections,
|
|
30
|
+
grid,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function gcd(a, b) {
|
|
36
|
+
if (!b) {
|
|
37
|
+
return a;
|
|
38
|
+
}
|
|
39
|
+
return gcd(b, a % b);
|
|
40
|
+
}
|
|
41
|
+
function lcm(a, b) {
|
|
42
|
+
const gcdValue = gcd(a, b);
|
|
43
|
+
return (a * b) / gcdValue;
|
|
44
|
+
}
|
|
@@ -4,14 +4,19 @@ import { CartStore } from '../Cart/CartStore';
|
|
|
4
4
|
import { RecommendationProfileStore } from './Stores';
|
|
5
5
|
import type { RecommendationStoreConfig, StoreServices } from '../types';
|
|
6
6
|
import type { RecommendCombinedResponseModel } from '@searchspring/snap-client';
|
|
7
|
+
import { MetaResponseModel } from '@searchspring/snapi-types';
|
|
8
|
+
import { MetaStore } from '../Meta/MetaStore';
|
|
7
9
|
export declare class RecommendationStore extends AbstractStore {
|
|
8
10
|
services: StoreServices;
|
|
11
|
+
meta: MetaStore;
|
|
9
12
|
loaded: boolean;
|
|
10
13
|
profile: RecommendationProfileStore;
|
|
11
14
|
results: Product[];
|
|
12
15
|
cart: CartStore;
|
|
13
16
|
constructor(config: RecommendationStoreConfig, services: StoreServices);
|
|
14
17
|
reset(): void;
|
|
15
|
-
update(data?: RecommendCombinedResponseModel
|
|
18
|
+
update(data?: RecommendCombinedResponseModel & {
|
|
19
|
+
meta?: MetaResponseModel;
|
|
20
|
+
}): void;
|
|
16
21
|
}
|
|
17
22
|
//# sourceMappingURL=RecommendationStore.d.ts.map
|
|
@@ -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,O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3,6 +3,7 @@ import { AbstractStore } from '../Abstract/AbstractStore';
|
|
|
3
3
|
import { SearchResultStore } from '../Search/Stores';
|
|
4
4
|
import { CartStore } from '../Cart/CartStore';
|
|
5
5
|
import { RecommendationProfileStore } from './Stores';
|
|
6
|
+
import { MetaStore } from '../Meta/MetaStore';
|
|
6
7
|
export class RecommendationStore extends AbstractStore {
|
|
7
8
|
constructor(config, services) {
|
|
8
9
|
super(config);
|
|
@@ -23,8 +24,9 @@ export class RecommendationStore extends AbstractStore {
|
|
|
23
24
|
update(data) {
|
|
24
25
|
this.error = undefined;
|
|
25
26
|
this.loaded = !!data?.profile;
|
|
27
|
+
this.meta = new MetaStore(data?.meta);
|
|
26
28
|
this.profile = new RecommendationProfileStore(this.services, data);
|
|
27
|
-
this.results = new SearchResultStore(this.config, this.services, data?.results);
|
|
29
|
+
this.results = new SearchResultStore(this.config, this.services, this.meta.data, data?.results);
|
|
28
30
|
// only create a cart store when type is bundle
|
|
29
31
|
if (this.profile.type == 'bundle') {
|
|
30
32
|
this.cart = new CartStore();
|
|
@@ -3,9 +3,10 @@ import type { SearchStoreConfig, StoreServices } from '../types';
|
|
|
3
3
|
import { SearchMerchandisingStore, SearchFacetStore, SearchFilterStore, SearchResultStore, SearchPaginationStore, SearchSortingStore, SearchQueryStore, SearchHistoryStore } from './Stores';
|
|
4
4
|
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
5
5
|
import { StorageStore } from '../Storage/StorageStore';
|
|
6
|
+
import { MetaStore } from '../Meta/MetaStore';
|
|
6
7
|
export declare class SearchStore extends AbstractStore {
|
|
7
8
|
services: StoreServices;
|
|
8
|
-
meta:
|
|
9
|
+
meta: MetaStore;
|
|
9
10
|
merchandising: SearchMerchandisingStore;
|
|
10
11
|
search: SearchQueryStore;
|
|
11
12
|
facets: SearchFacetStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchStore.d.ts","sourceRoot":"","sources":["../../../src/Search/SearchStore.ts"],"names":[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IACnC,OAAO,EAAG,kBAAkB,CAAC;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,kBAAkB,CAAC;gBAEvB,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,aAAa;IAiDvD,KAAK,IAAI,IAAI;IAIb,MAAM,CAAC,IAAI,GAAE,mBAAmB,GAAG;QAAE,IAAI,CAAC,EAAE,iBAAiB,CAAA;KAAO,GAAG,IAAI;CAoBlF"}
|
|
@@ -2,6 +2,7 @@ import { makeObservable, observable } from 'mobx';
|
|
|
2
2
|
import { SearchMerchandisingStore, SearchFacetStore, SearchFilterStore, SearchResultStore, SearchPaginationStore, SearchSortingStore, SearchQueryStore, SearchHistoryStore, } from './Stores';
|
|
3
3
|
import { AbstractStore } from '../Abstract/AbstractStore';
|
|
4
4
|
import { StorageStore } from '../Storage/StorageStore';
|
|
5
|
+
import { MetaStore } from '../Meta/MetaStore';
|
|
5
6
|
export class SearchStore extends AbstractStore {
|
|
6
7
|
constructor(config, services) {
|
|
7
8
|
super(config);
|
|
@@ -48,13 +49,13 @@ export class SearchStore extends AbstractStore {
|
|
|
48
49
|
update(data = {}) {
|
|
49
50
|
this.error = undefined;
|
|
50
51
|
this.loaded = !!data.pagination;
|
|
51
|
-
this.meta = data.meta
|
|
52
|
+
this.meta = new MetaStore(data.meta);
|
|
52
53
|
this.merchandising = new SearchMerchandisingStore(this.services, data?.merchandising || {});
|
|
53
54
|
this.search = new SearchQueryStore(this.services, data?.search || {});
|
|
54
|
-
this.facets = new SearchFacetStore(this.config, this.services, this.storage, data.facets, data?.pagination || {}, this.meta, data?.merchandising || {});
|
|
55
|
-
this.filters = new SearchFilterStore(this.services, data.filters, this.meta);
|
|
56
|
-
this.results = new SearchResultStore(this.config, this.services, data?.results || [], data.pagination, data.merchandising);
|
|
57
|
-
this.pagination = new SearchPaginationStore(this.config, this.services, data.pagination, this.meta);
|
|
58
|
-
this.sorting = new SearchSortingStore(this.services, data?.sorting || [], data?.search || {}, this.meta);
|
|
55
|
+
this.facets = new SearchFacetStore(this.config, this.services, this.storage, data.facets, data?.pagination || {}, this.meta.data, data?.merchandising || {});
|
|
56
|
+
this.filters = new SearchFilterStore(this.services, data.filters, this.meta.data);
|
|
57
|
+
this.results = new SearchResultStore(this.config, this.services, this.meta.data, data?.results || [], data.pagination, data.merchandising);
|
|
58
|
+
this.pagination = new SearchPaginationStore(this.config, this.services, data.pagination, this.meta.data);
|
|
59
|
+
this.sorting = new SearchSortingStore(this.services, data?.sorting || [], data?.search || {}, this.meta.data);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StorageStore
|
|
1
|
+
import { StorageStore } from '../../Storage/StorageStore';
|
|
2
2
|
import { Query } from './SearchQueryStore';
|
|
3
3
|
export class SearchHistoryStore {
|
|
4
4
|
constructor(config, services) {
|
|
@@ -16,7 +16,7 @@ export class SearchHistoryStore {
|
|
|
16
16
|
this.config.max = 25;
|
|
17
17
|
}
|
|
18
18
|
this.storage = new StorageStore({
|
|
19
|
-
type:
|
|
19
|
+
type: 'local',
|
|
20
20
|
key: `ss-history${this.config.siteId ? `-${this.config.siteId}` : ``}`,
|
|
21
21
|
});
|
|
22
22
|
// reset to zero to clear any potentially existing terms
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { StoreServices, StoreConfigs, VariantSelectionOptions } from '../../types';
|
|
2
|
-
import type { SearchResponseModelResult, SearchResponseModelPagination, SearchResponseModelMerchandising, SearchResponseModelResultMappings, SearchResponseModelMerchandisingContentInline, SearchResponseModelMerchandisingContentConfig } from '@searchspring/snapi-types';
|
|
1
|
+
import type { StoreServices, StoreConfigs, VariantSelectionOptions, ResultBadge, VariantConfig } from '../../types';
|
|
2
|
+
import type { SearchResponseModelResult, SearchResponseModelPagination, SearchResponseModelMerchandising, SearchResponseModelResultMappings, SearchResponseModelMerchandisingContentInline, SearchResponseModelMerchandisingContentConfig, MetaResponseModel } from '@searchspring/snapi-types';
|
|
3
3
|
export declare class SearchResultStore extends Array<Product | Banner> {
|
|
4
4
|
static get [Symbol.species](): ArrayConstructor;
|
|
5
|
-
constructor(config: StoreConfigs, services: StoreServices, resultData?: SearchResponseModelResult[], paginationData?: SearchResponseModelPagination, merchData?: SearchResponseModelMerchandising);
|
|
5
|
+
constructor(config: StoreConfigs, services: StoreServices, metaData: MetaResponseModel, resultData?: SearchResponseModelResult[], paginationData?: SearchResponseModelPagination, merchData?: SearchResponseModelMerchandising);
|
|
6
6
|
}
|
|
7
7
|
export declare class Banner {
|
|
8
8
|
type: string;
|
|
@@ -17,7 +17,11 @@ export declare class Banner {
|
|
|
17
17
|
export type VariantData = {
|
|
18
18
|
mappings: SearchResponseModelResultMappings;
|
|
19
19
|
attributes: Record<string, unknown>;
|
|
20
|
-
options: Record<string,
|
|
20
|
+
options: Record<string, {
|
|
21
|
+
value: string;
|
|
22
|
+
attributeId?: string;
|
|
23
|
+
optionId?: string;
|
|
24
|
+
}>;
|
|
21
25
|
};
|
|
22
26
|
type ProductMinimal = {
|
|
23
27
|
id: string;
|
|
@@ -31,12 +35,20 @@ export declare class Product {
|
|
|
31
35
|
mappings: SearchResponseModelResultMappings;
|
|
32
36
|
custom: {};
|
|
33
37
|
children?: Array<Child>;
|
|
38
|
+
badges: Badges;
|
|
34
39
|
quantity: number;
|
|
35
40
|
mask: ProductMask;
|
|
36
41
|
variants?: Variants;
|
|
37
|
-
constructor(services: StoreServices, result: SearchResponseModelResult, config?: StoreConfigs);
|
|
42
|
+
constructor(services: StoreServices, result: SearchResponseModelResult, metaData: MetaResponseModel, config?: StoreConfigs);
|
|
38
43
|
get display(): ProductMinimal;
|
|
39
44
|
}
|
|
45
|
+
export declare class Badges {
|
|
46
|
+
all: ResultBadge[];
|
|
47
|
+
constructor(result: SearchResponseModelResult, metaData: MetaResponseModel);
|
|
48
|
+
atLocation(location?: string[] | string): ResultBadge[];
|
|
49
|
+
get tags(): Record<string, ResultBadge>;
|
|
50
|
+
get locations(): Record<string, Record<string, ResultBadge[]>>;
|
|
51
|
+
}
|
|
40
52
|
export declare class ProductMask {
|
|
41
53
|
data: Partial<Product>;
|
|
42
54
|
constructor();
|
|
@@ -49,9 +61,11 @@ export declare class Variants {
|
|
|
49
61
|
data: Variant[];
|
|
50
62
|
selections: VariantSelection[];
|
|
51
63
|
setActive: (variant: Variant) => void;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
update(
|
|
64
|
+
private config?;
|
|
65
|
+
constructor(variantData: VariantData[], mask: ProductMask, config?: VariantConfig);
|
|
66
|
+
update(variantData: VariantData[], config?: VariantConfig | undefined): void;
|
|
67
|
+
makeSelections(options?: Record<string, string[]>): void;
|
|
68
|
+
refineSelections(fromSelection: VariantSelection): void;
|
|
55
69
|
}
|
|
56
70
|
type SelectionValue = {
|
|
57
71
|
value: string;
|
|
@@ -68,7 +82,7 @@ export declare class VariantSelection {
|
|
|
68
82
|
values: SelectionValue[];
|
|
69
83
|
private variantsUpdate;
|
|
70
84
|
constructor(variants: Variants, selectorConfig: VariantSelectionOptions);
|
|
71
|
-
|
|
85
|
+
refineValues(variants: Variants): void;
|
|
72
86
|
reset(): void;
|
|
73
87
|
select(value: string, internalSelection?: boolean): void;
|
|
74
88
|
}
|
|
@@ -76,7 +90,11 @@ export declare class Variant {
|
|
|
76
90
|
type: string;
|
|
77
91
|
available: boolean;
|
|
78
92
|
attributes: Record<string, unknown>;
|
|
79
|
-
options: Record<string,
|
|
93
|
+
options: Record<string, {
|
|
94
|
+
value: string;
|
|
95
|
+
attributeId?: string;
|
|
96
|
+
optionId?: string;
|
|
97
|
+
}>;
|
|
80
98
|
mappings: SearchResponseModelResultMappings;
|
|
81
99
|
custom: {};
|
|
82
100
|
constructor(variantData: VariantData);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchResultStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SearchResultStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAqB,aA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AAI,SAAa;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IACzC,OAAO,EAAE,MAAM,CACrB,MAAM,EACN;QACC,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,CACD,CAAC;IAEK,QAAQ,EAAE,iCAAiC,CAEhD;IACK,MAAM,KAAM;gBAEP,WAAW,EAAE,WAAW;CAapC;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"}
|
|
@@ -5,9 +5,9 @@ export class SearchResultStore extends Array {
|
|
|
5
5
|
static get [Symbol.species]() {
|
|
6
6
|
return Array;
|
|
7
7
|
}
|
|
8
|
-
constructor(config, services, resultData, paginationData, merchData) {
|
|
8
|
+
constructor(config, services, metaData, resultData, paginationData, merchData) {
|
|
9
9
|
let results = (resultData || []).map((result) => {
|
|
10
|
-
return new Product(services, result, config);
|
|
10
|
+
return new Product(services, result, metaData, config);
|
|
11
11
|
});
|
|
12
12
|
if (merchData?.content?.inline) {
|
|
13
13
|
const banners = merchData.content.inline
|
|
@@ -43,7 +43,7 @@ export class Banner {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
export class Product {
|
|
46
|
-
constructor(services, result, config) {
|
|
46
|
+
constructor(services, result, metaData, config) {
|
|
47
47
|
this.type = 'product';
|
|
48
48
|
this.attributes = {};
|
|
49
49
|
this.mappings = {
|
|
@@ -56,12 +56,13 @@ export class Product {
|
|
|
56
56
|
this.id = result.id;
|
|
57
57
|
this.attributes = result.attributes;
|
|
58
58
|
this.mappings = result.mappings;
|
|
59
|
+
this.badges = new Badges(result, metaData);
|
|
59
60
|
const variantsField = config?.settings?.variants?.field;
|
|
60
61
|
if (config && variantsField && this.attributes && this.attributes[variantsField]) {
|
|
61
62
|
try {
|
|
62
63
|
// parse the field (JSON)
|
|
63
64
|
const parsedVariants = JSON.parse(this.attributes[variantsField]);
|
|
64
|
-
this.variants = new Variants(parsedVariants, this.mask);
|
|
65
|
+
this.variants = new Variants(parsedVariants, this.mask, config.settings?.variants);
|
|
65
66
|
}
|
|
66
67
|
catch (err) {
|
|
67
68
|
// failed to parse the variant JSON
|
|
@@ -96,6 +97,55 @@ export class Product {
|
|
|
96
97
|
return deepmerge({ id: this.id, mappings: this.mappings, attributes: this.attributes }, this.mask.data, { isMergeableObject: isPlainObject });
|
|
97
98
|
}
|
|
98
99
|
}
|
|
100
|
+
export class Badges {
|
|
101
|
+
constructor(result, metaData) {
|
|
102
|
+
this.all = [];
|
|
103
|
+
this.all = (result.badges || [])
|
|
104
|
+
.filter((badge) => {
|
|
105
|
+
// remove badges that are not in the meta or are disabled
|
|
106
|
+
return !!(badge?.tag && metaData?.badges?.tags && metaData?.badges?.tags[badge.tag] && metaData?.badges?.tags[badge.tag].enabled);
|
|
107
|
+
})
|
|
108
|
+
.map((badge) => {
|
|
109
|
+
// merge badge with badge meta data
|
|
110
|
+
const metaBadgeData = metaData?.badges?.tags?.[badge.tag];
|
|
111
|
+
return {
|
|
112
|
+
...badge,
|
|
113
|
+
...metaBadgeData,
|
|
114
|
+
};
|
|
115
|
+
})
|
|
116
|
+
.sort((a, b) => {
|
|
117
|
+
return a.priority - b.priority;
|
|
118
|
+
});
|
|
119
|
+
makeObservable(this, {
|
|
120
|
+
all: observable,
|
|
121
|
+
tags: computed,
|
|
122
|
+
locations: computed,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// get all the result badges that are in a specific location
|
|
126
|
+
atLocation(location) {
|
|
127
|
+
const locations = Array.isArray(location) ? location : [location];
|
|
128
|
+
return this.all.filter((badge) => {
|
|
129
|
+
// filter location
|
|
130
|
+
return locations.some((location) => badge.location.startsWith(`${location}/`) || badge.location == location);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
get tags() {
|
|
134
|
+
return this.all.reduce((badgeMap, badge) => {
|
|
135
|
+
badgeMap[badge.tag] = badge;
|
|
136
|
+
return badgeMap;
|
|
137
|
+
}, {});
|
|
138
|
+
}
|
|
139
|
+
get locations() {
|
|
140
|
+
return this.all.reduce((locationMap, badge) => {
|
|
141
|
+
// put badge in location by path
|
|
142
|
+
const [section, tag] = badge.location.split('/');
|
|
143
|
+
locationMap[section] = locationMap[section] || {};
|
|
144
|
+
locationMap[section][tag] = (locationMap[section][tag] || []).concat(badge);
|
|
145
|
+
return locationMap;
|
|
146
|
+
}, {});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
99
149
|
// Mask is used to power the product display for quick attribute swapping
|
|
100
150
|
export class ProductMask {
|
|
101
151
|
constructor() {
|
|
@@ -123,37 +173,56 @@ export class ProductMask {
|
|
|
123
173
|
}
|
|
124
174
|
}
|
|
125
175
|
export class Variants {
|
|
126
|
-
constructor(variantData, mask) {
|
|
176
|
+
constructor(variantData, mask, config) {
|
|
127
177
|
this.data = [];
|
|
128
178
|
this.selections = [];
|
|
129
|
-
const options = [];
|
|
130
|
-
// create variants objects
|
|
131
|
-
this.data = variantData.map((variant) => {
|
|
132
|
-
Object.keys(variant.options).forEach((variantOption) => {
|
|
133
|
-
if (!options.includes(variantOption)) {
|
|
134
|
-
options.push(variantOption);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
return new Variant(variant);
|
|
138
|
-
});
|
|
139
|
-
options.map((option) => {
|
|
140
|
-
// TODO - merge with variant config before constructing selection (for label overrides and swatch mappings)
|
|
141
|
-
const optionConfig = {
|
|
142
|
-
field: option,
|
|
143
|
-
label: option,
|
|
144
|
-
};
|
|
145
|
-
this.selections.push(new VariantSelection(this, optionConfig));
|
|
146
|
-
});
|
|
147
179
|
// setting function in constructor to prevent exposing mask as class property
|
|
148
180
|
this.setActive = (variant) => {
|
|
149
181
|
this.active = variant;
|
|
150
182
|
mask.set({ mappings: this.active.mappings, attributes: this.active.attributes });
|
|
151
183
|
};
|
|
152
|
-
|
|
153
|
-
this.
|
|
184
|
+
this.config = config;
|
|
185
|
+
this.update(variantData, config);
|
|
186
|
+
}
|
|
187
|
+
update(variantData, config = this.config) {
|
|
188
|
+
try {
|
|
189
|
+
const options = [];
|
|
190
|
+
// create variants objects
|
|
191
|
+
this.data = variantData.map((variant) => {
|
|
192
|
+
Object.keys(variant.options).forEach((variantOption) => {
|
|
193
|
+
if (!options.includes(variantOption)) {
|
|
194
|
+
options.push(variantOption);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
return new Variant(variant);
|
|
198
|
+
});
|
|
199
|
+
//need to reset this.selections first
|
|
200
|
+
this.selections = [];
|
|
201
|
+
options.map((option) => {
|
|
202
|
+
// TODO - merge with variant config before constructing selection (for label overrides and swatch mappings)
|
|
203
|
+
const optionConfig = {
|
|
204
|
+
field: option,
|
|
205
|
+
label: option,
|
|
206
|
+
};
|
|
207
|
+
this.selections.push(new VariantSelection(this, optionConfig));
|
|
208
|
+
});
|
|
209
|
+
const preselectedOptions = {};
|
|
210
|
+
if (config?.options) {
|
|
211
|
+
Object.keys(config?.options).forEach((option) => {
|
|
212
|
+
if (config.options[option].preSelected) {
|
|
213
|
+
preselectedOptions[option] = config.options[option].preSelected;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// select first available
|
|
218
|
+
this.makeSelections(preselectedOptions);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
// failed to parse the variant JSON
|
|
222
|
+
console.error(err, `Invalid variant JSON for: ${variantData}`);
|
|
223
|
+
}
|
|
154
224
|
}
|
|
155
225
|
makeSelections(options) {
|
|
156
|
-
// TODO - support for affinity to attempt to pre-selected options
|
|
157
226
|
// options = {color: 'Blue', size: 'L'};
|
|
158
227
|
if (!options) {
|
|
159
228
|
// select first available for each selection
|
|
@@ -164,8 +233,40 @@ export class Variants {
|
|
|
164
233
|
}
|
|
165
234
|
});
|
|
166
235
|
}
|
|
236
|
+
else {
|
|
237
|
+
this.selections.forEach((selection, idx) => {
|
|
238
|
+
// filter by first available, then by preselected option preference
|
|
239
|
+
//make all options available for first selection.
|
|
240
|
+
const availableOptions = selection.values.filter((value) => (idx == 0 ? true : value.available));
|
|
241
|
+
const preferedOptions = options[selection.field];
|
|
242
|
+
let preferencedOption = availableOptions[0];
|
|
243
|
+
// if theres a preference for that field
|
|
244
|
+
if (preferedOptions) {
|
|
245
|
+
const checkIfAvailable = (preference) => {
|
|
246
|
+
//see if that option is in the available options
|
|
247
|
+
const availablePreferedOptions = availableOptions.find((value) => value.value.toLowerCase() == preference.toLowerCase());
|
|
248
|
+
//use it
|
|
249
|
+
if (availablePreferedOptions) {
|
|
250
|
+
preferencedOption = availablePreferedOptions;
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
if (Array.isArray(preferedOptions)) {
|
|
254
|
+
//loop through each preference option
|
|
255
|
+
preferedOptions.forEach((preference) => {
|
|
256
|
+
checkIfAvailable(preference);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
checkIfAvailable(preferedOptions);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (preferencedOption) {
|
|
264
|
+
selection.select(preferencedOption.value);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
167
268
|
}
|
|
168
|
-
|
|
269
|
+
refineSelections(fromSelection) {
|
|
169
270
|
// need to ensure the update originator is at the BOTTOM of the list for refinement
|
|
170
271
|
const orderedSelections = [...this.selections];
|
|
171
272
|
orderedSelections.sort((a) => {
|
|
@@ -175,14 +276,14 @@ export class Variants {
|
|
|
175
276
|
return -1;
|
|
176
277
|
});
|
|
177
278
|
// refine selections ensuring that the selection that triggered the update refines LAST
|
|
178
|
-
orderedSelections.forEach((selection) => selection.
|
|
279
|
+
orderedSelections.forEach((selection) => selection.refineValues(this));
|
|
179
280
|
// check to see if we have enough selections made to update the display
|
|
180
|
-
const selectedSelections = this.selections.filter((selection) => selection.selected
|
|
281
|
+
const selectedSelections = this.selections.filter((selection) => selection.selected);
|
|
181
282
|
if (selectedSelections.length) {
|
|
182
283
|
let availableVariants = this.data;
|
|
183
284
|
// loop through selectedSelections and only include available products that match current selections
|
|
184
285
|
for (const selectedSelection of selectedSelections) {
|
|
185
|
-
availableVariants = availableVariants.filter((variant) => selectedSelection.selected == variant.options[selectedSelection.field] && variant.available);
|
|
286
|
+
availableVariants = availableVariants.filter((variant) => selectedSelection.selected == variant.options[selectedSelection.field].value && variant.available);
|
|
186
287
|
}
|
|
187
288
|
// set active variant
|
|
188
289
|
if (availableVariants.length == 1) {
|
|
@@ -199,33 +300,33 @@ export class VariantSelection {
|
|
|
199
300
|
this.field = selectorConfig.field;
|
|
200
301
|
this.label = selectorConfig.label;
|
|
201
302
|
// needed to prevent attaching variants as class property
|
|
202
|
-
this.variantsUpdate = () => variants.
|
|
303
|
+
this.variantsUpdate = () => variants.refineSelections(this);
|
|
203
304
|
// create possible values from the data and refine them
|
|
204
|
-
this.
|
|
305
|
+
this.refineValues(variants);
|
|
205
306
|
makeObservable(this, {
|
|
206
307
|
selected: observable,
|
|
207
308
|
values: observable,
|
|
208
309
|
});
|
|
209
310
|
}
|
|
210
|
-
|
|
311
|
+
refineValues(variants) {
|
|
211
312
|
// current selection should only consider OTHER selections for availability
|
|
212
313
|
const selectedSelections = variants.selections.filter((selection) => selection.field != this.field && selection.selected);
|
|
213
314
|
let availableVariants = variants.data;
|
|
214
315
|
// loop through selectedSelections and remove products that do not match
|
|
215
316
|
for (const selectedSelection of selectedSelections) {
|
|
216
|
-
availableVariants = availableVariants.filter((variant) => selectedSelection.selected == variant.options[selectedSelection.field] && variant.available);
|
|
317
|
+
availableVariants = availableVariants.filter((variant) => selectedSelection.selected == variant.options[selectedSelection.field].value && variant.available);
|
|
217
318
|
}
|
|
218
319
|
const newValues = variants.data
|
|
219
320
|
.filter((variant) => variant.options[this.field])
|
|
220
321
|
.reduce((values, variant) => {
|
|
221
|
-
if (!values.some((val) => variant.options[this.field] == val.value)) {
|
|
322
|
+
if (!values.some((val) => variant.options[this.field].value == val.value)) {
|
|
222
323
|
values.push({
|
|
223
|
-
|
|
224
|
-
label: variant.options[this.field],
|
|
324
|
+
label: variant.options[this.field].value,
|
|
225
325
|
// TODO: use configurable mappings from config
|
|
226
326
|
// TODO: set background for swatches (via configurable mappings) from config
|
|
227
327
|
thumbnailImageUrl: variant.mappings.core?.thumbnailImageUrl,
|
|
228
|
-
available: Boolean(availableVariants.some((availableVariant) => availableVariant.options[this.field] == variant.options[this.field])),
|
|
328
|
+
available: Boolean(availableVariants.some((availableVariant) => availableVariant.options[this.field].value == variant.options[this.field].value)),
|
|
329
|
+
...variant.options[this.field],
|
|
229
330
|
});
|
|
230
331
|
}
|
|
231
332
|
// TODO: use sorting function from config
|
|
@@ -274,7 +375,6 @@ export class Variant {
|
|
|
274
375
|
constructor(variantData) {
|
|
275
376
|
this.type = 'variant';
|
|
276
377
|
this.attributes = {};
|
|
277
|
-
this.options = {};
|
|
278
378
|
this.mappings = {
|
|
279
379
|
core: {},
|
|
280
380
|
};
|
|
@@ -10,7 +10,7 @@ export declare class StorageStore {
|
|
|
10
10
|
clear(): void;
|
|
11
11
|
}
|
|
12
12
|
export type StorageConfig = {
|
|
13
|
-
type: StorageType;
|
|
13
|
+
type: StorageType | keyof typeof StorageType;
|
|
14
14
|
cookie?: {
|
|
15
15
|
expiration?: number;
|
|
16
16
|
sameSite?: string;
|
|
@@ -18,9 +18,9 @@ export type StorageConfig = {
|
|
|
18
18
|
key: string;
|
|
19
19
|
};
|
|
20
20
|
export declare enum StorageType {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
session = "session",
|
|
22
|
+
local = "local",
|
|
23
|
+
cookie = "cookie",
|
|
24
|
+
memory = "memory"
|
|
25
25
|
}
|
|
26
26
|
//# sourceMappingURL=StorageStore.d.ts.map
|
|
@@ -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,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAC;
|
|
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,GAAG,MAAM,OAAO,WAAW,C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