@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.
Files changed (159) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -0
  3. package/dist/cjs/Abstract/AbstractStore.d.ts +18 -0
  4. package/dist/cjs/Abstract/AbstractStore.d.ts.map +1 -0
  5. package/dist/cjs/Abstract/AbstractStore.js +31 -0
  6. package/dist/cjs/Autocomplete/AutocompleteStore.d.ts +32 -0
  7. package/dist/cjs/Autocomplete/AutocompleteStore.d.ts.map +1 -0
  8. package/dist/cjs/Autocomplete/AutocompleteStore.js +121 -0
  9. package/dist/cjs/Autocomplete/Stores/FacetStore.d.ts +9 -0
  10. package/dist/cjs/Autocomplete/Stores/FacetStore.d.ts.map +1 -0
  11. package/dist/cjs/Autocomplete/Stores/FacetStore.js +69 -0
  12. package/dist/cjs/Autocomplete/Stores/QueryStore.d.ts +15 -0
  13. package/dist/cjs/Autocomplete/Stores/QueryStore.d.ts.map +1 -0
  14. package/dist/cjs/Autocomplete/Stores/QueryStore.js +30 -0
  15. package/dist/cjs/Autocomplete/Stores/StateStore.d.ts +23 -0
  16. package/dist/cjs/Autocomplete/Stores/StateStore.d.ts.map +1 -0
  17. package/dist/cjs/Autocomplete/Stores/StateStore.js +52 -0
  18. package/dist/cjs/Autocomplete/Stores/TermStore.d.ts +19 -0
  19. package/dist/cjs/Autocomplete/Stores/TermStore.d.ts.map +1 -0
  20. package/dist/cjs/Autocomplete/Stores/TermStore.js +86 -0
  21. package/dist/cjs/Autocomplete/Stores/TrendingStore.d.ts +7 -0
  22. package/dist/cjs/Autocomplete/Stores/TrendingStore.d.ts.map +1 -0
  23. package/dist/cjs/Autocomplete/Stores/TrendingStore.js +44 -0
  24. package/dist/cjs/Autocomplete/Stores/index.d.ts +6 -0
  25. package/dist/cjs/Autocomplete/Stores/index.d.ts.map +1 -0
  26. package/dist/cjs/Autocomplete/Stores/index.js +13 -0
  27. package/dist/cjs/Finder/FinderStore.d.ts +21 -0
  28. package/dist/cjs/Finder/FinderStore.d.ts.map +1 -0
  29. package/dist/cjs/Finder/FinderStore.js +56 -0
  30. package/dist/cjs/Finder/Stores/SelectionStore.d.ts +8 -0
  31. package/dist/cjs/Finder/Stores/SelectionStore.d.ts.map +1 -0
  32. package/dist/cjs/Finder/Stores/SelectionStore.js +232 -0
  33. package/dist/cjs/Finder/Stores/index.d.ts +2 -0
  34. package/dist/cjs/Finder/Stores/index.d.ts.map +1 -0
  35. package/dist/cjs/Finder/Stores/index.js +5 -0
  36. package/dist/cjs/Recommendation/RecommendationStore.d.ts +14 -0
  37. package/dist/cjs/Recommendation/RecommendationStore.d.ts.map +1 -0
  38. package/dist/cjs/Recommendation/RecommendationStore.js +51 -0
  39. package/dist/cjs/Recommendation/Stores/ProfileStore.d.ts +8 -0
  40. package/dist/cjs/Recommendation/Stores/ProfileStore.d.ts.map +1 -0
  41. package/dist/cjs/Recommendation/Stores/ProfileStore.js +22 -0
  42. package/dist/cjs/Recommendation/Stores/index.d.ts +2 -0
  43. package/dist/cjs/Recommendation/Stores/index.d.ts.map +1 -0
  44. package/dist/cjs/Recommendation/Stores/index.js +5 -0
  45. package/dist/cjs/Search/SearchStore.d.ts +26 -0
  46. package/dist/cjs/Search/SearchStore.d.ts.map +1 -0
  47. package/dist/cjs/Search/SearchStore.js +61 -0
  48. package/dist/cjs/Search/Stores/FacetStore.d.ts +8 -0
  49. package/dist/cjs/Search/Stores/FacetStore.d.ts.map +1 -0
  50. package/dist/cjs/Search/Stores/FacetStore.js +317 -0
  51. package/dist/cjs/Search/Stores/FilterStore.d.ts +7 -0
  52. package/dist/cjs/Search/Stores/FilterStore.d.ts.map +1 -0
  53. package/dist/cjs/Search/Stores/FilterStore.js +100 -0
  54. package/dist/cjs/Search/Stores/MerchandisingStore.d.ts +20 -0
  55. package/dist/cjs/Search/Stores/MerchandisingStore.d.ts.map +1 -0
  56. package/dist/cjs/Search/Stores/MerchandisingStore.js +59 -0
  57. package/dist/cjs/Search/Stores/PaginationStore.d.ts +40 -0
  58. package/dist/cjs/Search/Stores/PaginationStore.d.ts.map +1 -0
  59. package/dist/cjs/Search/Stores/PaginationStore.js +190 -0
  60. package/dist/cjs/Search/Stores/QueryStore.d.ts +16 -0
  61. package/dist/cjs/Search/Stores/QueryStore.d.ts.map +1 -0
  62. package/dist/cjs/Search/Stores/QueryStore.js +34 -0
  63. package/dist/cjs/Search/Stores/ResultStore.d.ts +7 -0
  64. package/dist/cjs/Search/Stores/ResultStore.d.ts.map +1 -0
  65. package/dist/cjs/Search/Stores/ResultStore.js +156 -0
  66. package/dist/cjs/Search/Stores/SortingStore.d.ts +21 -0
  67. package/dist/cjs/Search/Stores/SortingStore.d.ts.map +1 -0
  68. package/dist/cjs/Search/Stores/SortingStore.js +75 -0
  69. package/dist/cjs/Search/Stores/index.d.ts +8 -0
  70. package/dist/cjs/Search/Stores/index.d.ts.map +1 -0
  71. package/dist/cjs/Search/Stores/index.js +17 -0
  72. package/dist/cjs/Storage/StorageStore.d.ts +25 -0
  73. package/dist/cjs/Storage/StorageStore.d.ts.map +1 -0
  74. package/dist/cjs/Storage/StorageStore.js +130 -0
  75. package/dist/cjs/index.d.ts +8 -0
  76. package/dist/cjs/index.d.ts.map +1 -0
  77. package/dist/cjs/index.js +27 -0
  78. package/dist/cjs/types.d.ts +81 -0
  79. package/dist/cjs/types.d.ts.map +1 -0
  80. package/dist/cjs/types.js +9 -0
  81. package/dist/esm/Abstract/AbstractStore.d.ts +18 -0
  82. package/dist/esm/Abstract/AbstractStore.d.ts.map +1 -0
  83. package/dist/esm/Abstract/AbstractStore.js +25 -0
  84. package/dist/esm/Autocomplete/AutocompleteStore.d.ts +32 -0
  85. package/dist/esm/Autocomplete/AutocompleteStore.d.ts.map +1 -0
  86. package/dist/esm/Autocomplete/AutocompleteStore.js +94 -0
  87. package/dist/esm/Autocomplete/Stores/FacetStore.d.ts +9 -0
  88. package/dist/esm/Autocomplete/Stores/FacetStore.d.ts.map +1 -0
  89. package/dist/esm/Autocomplete/Stores/FacetStore.js +29 -0
  90. package/dist/esm/Autocomplete/Stores/QueryStore.d.ts +15 -0
  91. package/dist/esm/Autocomplete/Stores/QueryStore.d.ts.map +1 -0
  92. package/dist/esm/Autocomplete/Stores/QueryStore.js +24 -0
  93. package/dist/esm/Autocomplete/Stores/StateStore.d.ts +23 -0
  94. package/dist/esm/Autocomplete/Stores/StateStore.d.ts.map +1 -0
  95. package/dist/esm/Autocomplete/Stores/StateStore.js +40 -0
  96. package/dist/esm/Autocomplete/Stores/TermStore.d.ts +19 -0
  97. package/dist/esm/Autocomplete/Stores/TermStore.d.ts.map +1 -0
  98. package/dist/esm/Autocomplete/Stores/TermStore.js +42 -0
  99. package/dist/esm/Autocomplete/Stores/TrendingStore.d.ts +7 -0
  100. package/dist/esm/Autocomplete/Stores/TrendingStore.d.ts.map +1 -0
  101. package/dist/esm/Autocomplete/Stores/TrendingStore.js +16 -0
  102. package/dist/esm/Autocomplete/Stores/index.d.ts +6 -0
  103. package/dist/esm/Autocomplete/Stores/index.d.ts.map +1 -0
  104. package/dist/esm/Autocomplete/Stores/index.js +5 -0
  105. package/dist/esm/Finder/FinderStore.d.ts +21 -0
  106. package/dist/esm/Finder/FinderStore.d.ts.map +1 -0
  107. package/dist/esm/Finder/FinderStore.js +33 -0
  108. package/dist/esm/Finder/Stores/SelectionStore.d.ts +8 -0
  109. package/dist/esm/Finder/Stores/SelectionStore.d.ts.map +1 -0
  110. package/dist/esm/Finder/Stores/SelectionStore.js +171 -0
  111. package/dist/esm/Finder/Stores/index.d.ts +2 -0
  112. package/dist/esm/Finder/Stores/index.d.ts.map +1 -0
  113. package/dist/esm/Finder/Stores/index.js +1 -0
  114. package/dist/esm/Recommendation/RecommendationStore.d.ts +14 -0
  115. package/dist/esm/Recommendation/RecommendationStore.d.ts.map +1 -0
  116. package/dist/esm/Recommendation/RecommendationStore.js +28 -0
  117. package/dist/esm/Recommendation/Stores/ProfileStore.d.ts +8 -0
  118. package/dist/esm/Recommendation/Stores/ProfileStore.d.ts.map +1 -0
  119. package/dist/esm/Recommendation/Stores/ProfileStore.js +17 -0
  120. package/dist/esm/Recommendation/Stores/index.d.ts +2 -0
  121. package/dist/esm/Recommendation/Stores/index.d.ts.map +1 -0
  122. package/dist/esm/Recommendation/Stores/index.js +1 -0
  123. package/dist/esm/Search/SearchStore.d.ts +26 -0
  124. package/dist/esm/Search/SearchStore.d.ts.map +1 -0
  125. package/dist/esm/Search/SearchStore.js +38 -0
  126. package/dist/esm/Search/Stores/FacetStore.d.ts +8 -0
  127. package/dist/esm/Search/Stores/FacetStore.d.ts.map +1 -0
  128. package/dist/esm/Search/Stores/FacetStore.js +264 -0
  129. package/dist/esm/Search/Stores/FilterStore.d.ts +7 -0
  130. package/dist/esm/Search/Stores/FilterStore.d.ts.map +1 -0
  131. package/dist/esm/Search/Stores/FilterStore.js +68 -0
  132. package/dist/esm/Search/Stores/MerchandisingStore.d.ts +20 -0
  133. package/dist/esm/Search/Stores/MerchandisingStore.d.ts.map +1 -0
  134. package/dist/esm/Search/Stores/MerchandisingStore.js +32 -0
  135. package/dist/esm/Search/Stores/PaginationStore.d.ts +40 -0
  136. package/dist/esm/Search/Stores/PaginationStore.d.ts.map +1 -0
  137. package/dist/esm/Search/Stores/PaginationStore.js +148 -0
  138. package/dist/esm/Search/Stores/QueryStore.d.ts +16 -0
  139. package/dist/esm/Search/Stores/QueryStore.d.ts.map +1 -0
  140. package/dist/esm/Search/Stores/QueryStore.js +28 -0
  141. package/dist/esm/Search/Stores/ResultStore.d.ts +7 -0
  142. package/dist/esm/Search/Stores/ResultStore.d.ts.map +1 -0
  143. package/dist/esm/Search/Stores/ResultStore.js +117 -0
  144. package/dist/esm/Search/Stores/SortingStore.d.ts +21 -0
  145. package/dist/esm/Search/Stores/SortingStore.d.ts.map +1 -0
  146. package/dist/esm/Search/Stores/SortingStore.js +65 -0
  147. package/dist/esm/Search/Stores/index.d.ts +8 -0
  148. package/dist/esm/Search/Stores/index.d.ts.map +1 -0
  149. package/dist/esm/Search/Stores/index.js +7 -0
  150. package/dist/esm/Storage/StorageStore.d.ts +25 -0
  151. package/dist/esm/Storage/StorageStore.d.ts.map +1 -0
  152. package/dist/esm/Storage/StorageStore.js +123 -0
  153. package/dist/esm/index.d.ts +8 -0
  154. package/dist/esm/index.d.ts.map +1 -0
  155. package/dist/esm/index.js +7 -0
  156. package/dist/esm/types.d.ts +81 -0
  157. package/dist/esm/types.d.ts.map +1 -0
  158. package/dist/esm/types.js +6 -0
  159. package/package.json +34 -0
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Page = exports.PaginationStore = void 0;
4
+ var mobx_1 = require("mobx");
5
+ var PaginationStore = /** @class */ (function () {
6
+ function PaginationStore(config, services, paginationData) {
7
+ if (paginationData === void 0) { paginationData = {
8
+ page: undefined,
9
+ pageSize: undefined,
10
+ totalResults: undefined,
11
+ defaultPageSize: 24,
12
+ totalPages: undefined,
13
+ }; }
14
+ this.services = services;
15
+ this.controllerConfig = config;
16
+ this.page = paginationData.page;
17
+ this.pageSize = paginationData.pageSize;
18
+ this.totalResults = paginationData.totalResults;
19
+ this.defaultPageSize = paginationData.defaultPageSize;
20
+ this.totalPages = paginationData.totalPages;
21
+ this.pageSizeOptions = [
22
+ {
23
+ label: "Show ".concat(this.defaultPageSize),
24
+ value: this.defaultPageSize,
25
+ },
26
+ {
27
+ label: "Show ".concat(this.defaultPageSize * 2),
28
+ value: this.defaultPageSize * 2,
29
+ },
30
+ {
31
+ label: "Show ".concat(this.defaultPageSize * 3),
32
+ value: this.defaultPageSize * 3,
33
+ },
34
+ ];
35
+ (0, mobx_1.makeObservable)(this, {
36
+ page: mobx_1.observable,
37
+ pageSize: mobx_1.observable,
38
+ totalResults: mobx_1.observable,
39
+ totalPages: mobx_1.observable,
40
+ begin: mobx_1.computed,
41
+ end: mobx_1.computed,
42
+ multiplePages: mobx_1.computed,
43
+ current: mobx_1.computed,
44
+ first: mobx_1.computed,
45
+ last: mobx_1.computed,
46
+ next: mobx_1.computed,
47
+ previous: mobx_1.computed,
48
+ getPages: mobx_1.action,
49
+ setPageSize: mobx_1.action,
50
+ });
51
+ }
52
+ Object.defineProperty(PaginationStore.prototype, "begin", {
53
+ get: function () {
54
+ var _a;
55
+ if ((_a = this.controllerConfig.settings) === null || _a === void 0 ? void 0 : _a.infinite) {
56
+ return 1;
57
+ }
58
+ return this.pageSize * (this.page - 1) + 1;
59
+ },
60
+ enumerable: false,
61
+ configurable: true
62
+ });
63
+ Object.defineProperty(PaginationStore.prototype, "end", {
64
+ get: function () {
65
+ if (this.pageSize * this.page > this.totalResults) {
66
+ return this.totalResults;
67
+ }
68
+ return this.pageSize * this.page;
69
+ },
70
+ enumerable: false,
71
+ configurable: true
72
+ });
73
+ Object.defineProperty(PaginationStore.prototype, "multiplePages", {
74
+ get: function () {
75
+ return this.pageSize < this.totalResults;
76
+ },
77
+ enumerable: false,
78
+ configurable: true
79
+ });
80
+ Object.defineProperty(PaginationStore.prototype, "current", {
81
+ get: function () {
82
+ return new Page(this.services, {
83
+ number: this.page,
84
+ active: true,
85
+ });
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ Object.defineProperty(PaginationStore.prototype, "first", {
91
+ get: function () {
92
+ return new Page(this.services, {
93
+ number: 1,
94
+ active: this.page == 1,
95
+ });
96
+ },
97
+ enumerable: false,
98
+ configurable: true
99
+ });
100
+ Object.defineProperty(PaginationStore.prototype, "last", {
101
+ get: function () {
102
+ return new Page(this.services, {
103
+ number: this.totalPages,
104
+ active: this.totalPages == this.page,
105
+ });
106
+ },
107
+ enumerable: false,
108
+ configurable: true
109
+ });
110
+ Object.defineProperty(PaginationStore.prototype, "next", {
111
+ get: function () {
112
+ if (this.page < this.totalPages) {
113
+ return new Page(this.services, {
114
+ number: this.page + 1,
115
+ });
116
+ }
117
+ },
118
+ enumerable: false,
119
+ configurable: true
120
+ });
121
+ Object.defineProperty(PaginationStore.prototype, "previous", {
122
+ get: function () {
123
+ if (this.page > 1) {
124
+ return new Page(this.services, {
125
+ number: this.page - 1,
126
+ });
127
+ }
128
+ },
129
+ enumerable: false,
130
+ configurable: true
131
+ });
132
+ PaginationStore.prototype.getPages = function (min, max) {
133
+ if (!Number.isInteger(min)) {
134
+ return [];
135
+ }
136
+ if (!Number.isInteger(max)) {
137
+ var surrounding = min - 1;
138
+ var from = this.page;
139
+ var to = this.page;
140
+ var last = to - from;
141
+ do {
142
+ last = to - from;
143
+ if (to < this.totalPages) {
144
+ to++;
145
+ }
146
+ if (to - from >= surrounding) {
147
+ break;
148
+ }
149
+ if (from > 1) {
150
+ from--;
151
+ }
152
+ } while (last != to - from && to - from < surrounding);
153
+ min = from - this.page;
154
+ max = to - this.page;
155
+ }
156
+ else {
157
+ min = -Math.abs(min);
158
+ max = Math.abs(max);
159
+ }
160
+ var pages = [];
161
+ for (var i = this.page + min; i <= this.page + max; i++) {
162
+ if (i > 0 && i <= this.totalPages) {
163
+ pages.push(new Page(this.services, {
164
+ number: i,
165
+ active: i == this.page,
166
+ }));
167
+ }
168
+ }
169
+ return pages;
170
+ };
171
+ PaginationStore.prototype.setPageSize = function (num) {
172
+ if (num) {
173
+ this.services.urlManager.remove('page').set('pageSize', num).go();
174
+ }
175
+ };
176
+ return PaginationStore;
177
+ }());
178
+ exports.PaginationStore = PaginationStore;
179
+ var Page = /** @class */ (function () {
180
+ function Page(services, page) {
181
+ var _a, _b;
182
+ this.services = services;
183
+ this.number = page.number;
184
+ this.active = page.active || false;
185
+ this.url = (_b = (_a = this.services) === null || _a === void 0 ? void 0 : _a.urlManager) === null || _b === void 0 ? void 0 : _b.set('page', this.number);
186
+ this.key = this.url.href;
187
+ }
188
+ return Page;
189
+ }());
190
+ exports.Page = Page;
@@ -0,0 +1,16 @@
1
+ import type { UrlManager } from '@searchspring/snap-url-manager';
2
+ import type { StoreServices } from '../../types';
3
+ import type { SearchResponseModelSearch } from '@searchspring/snapi-types';
4
+ export declare class QueryStore {
5
+ query: Query;
6
+ didYouMean: Query;
7
+ originalQuery: Query;
8
+ constructor(services: StoreServices, search: SearchResponseModelSearch);
9
+ }
10
+ declare class Query {
11
+ string: string;
12
+ url: UrlManager;
13
+ constructor(services: StoreServices, query: string);
14
+ }
15
+ export {};
16
+ //# sourceMappingURL=QueryStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/QueryStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAE3E,qBAAa,UAAU;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,KAAK,CAAC;IAClB,aAAa,EAAE,KAAK,CAAC;gBAET,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,yBAAyB;CAoBtE;AAQD,cAAM,KAAK;IACV,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,UAAU,CAAC;gBAEJ,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM;CASlD"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryStore = void 0;
4
+ var mobx_1 = require("mobx");
5
+ var QueryStore = /** @class */ (function () {
6
+ function QueryStore(services, search) {
7
+ var observables = {};
8
+ if (search === null || search === void 0 ? void 0 : search.query) {
9
+ this.query = new Query(services, search.query);
10
+ observables.query = mobx_1.observable;
11
+ }
12
+ if (search === null || search === void 0 ? void 0 : search.didYouMean) {
13
+ this.didYouMean = new Query(services, search.didYouMean);
14
+ observables.didYouMean = mobx_1.observable;
15
+ }
16
+ if (search === null || search === void 0 ? void 0 : search.originalQuery) {
17
+ this.originalQuery = new Query(services, search.originalQuery);
18
+ observables.originalQuery = mobx_1.observable;
19
+ }
20
+ (0, mobx_1.makeObservable)(this, observables);
21
+ }
22
+ return QueryStore;
23
+ }());
24
+ exports.QueryStore = QueryStore;
25
+ var Query = /** @class */ (function () {
26
+ function Query(services, query) {
27
+ this.string = query;
28
+ this.url = services.urlManager.remove('page').remove('filter').set('query', this.string);
29
+ (0, mobx_1.makeObservable)(this, {
30
+ string: mobx_1.observable,
31
+ });
32
+ }
33
+ return Query;
34
+ }());
@@ -0,0 +1,7 @@
1
+ import type { SearchStoreConfig, AutocompleteStoreConfig, StoreServices } from '../../types';
2
+ import type { SearchResponseModelResult, SearchResponseModelPagination, SearchResponseModelMerchandising } from '@searchspring/snapi-types';
3
+ export declare class ResultStore extends Array {
4
+ static get [Symbol.species](): ArrayConstructor;
5
+ constructor(config: SearchStoreConfig | AutocompleteStoreConfig, services: StoreServices, resultData: SearchResponseModelResult[], paginationData?: SearchResponseModelPagination, merchData?: SearchResponseModelMerchandising);
6
+ }
7
+ //# sourceMappingURL=ResultStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResultStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/ResultStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,KAAK,EACX,yBAAyB,EACzB,6BAA6B,EAC7B,gCAAgC,EAIhC,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,WAAY,SAAQ,KAAK;IACrC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAGA,MAAM,EAAE,iBAAiB,GAAG,uBAAuB,EACnD,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,yBAAyB,EAAE,EACvC,cAAc,CAAC,EAAE,6BAA6B,EAC9C,SAAS,CAAC,EAAE,gCAAgC;CAuB7C"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ResultStore = void 0;
30
+ var mobx_1 = require("mobx");
31
+ var ResultStore = /** @class */ (function (_super) {
32
+ __extends(ResultStore, _super);
33
+ function ResultStore(config, services, resultData, paginationData, merchData) {
34
+ var _a;
35
+ var _this = this;
36
+ var results = (resultData || []).map(function (result) {
37
+ return new Product(services, result);
38
+ });
39
+ if ((_a = merchData === null || merchData === void 0 ? void 0 : merchData.content) === null || _a === void 0 ? void 0 : _a.inline) {
40
+ var banners = merchData.content.inline
41
+ .sort(function (a, b) {
42
+ return a.config.position.index - b.config.position.index;
43
+ })
44
+ .map(function (banner) {
45
+ return new Banner(services, banner);
46
+ });
47
+ if (banners && (paginationData === null || paginationData === void 0 ? void 0 : paginationData.totalResults)) {
48
+ results = addBannersToResults(config, results, banners, paginationData);
49
+ }
50
+ }
51
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
52
+ // @ts-ignore
53
+ _this = _super.apply(this, results) || this;
54
+ return _this;
55
+ }
56
+ Object.defineProperty(ResultStore, Symbol.species, {
57
+ get: function () {
58
+ return Array;
59
+ },
60
+ enumerable: false,
61
+ configurable: true
62
+ });
63
+ return ResultStore;
64
+ }(Array));
65
+ exports.ResultStore = ResultStore;
66
+ var Banner = /** @class */ (function () {
67
+ function Banner(services, banner) {
68
+ this.type = 'banner';
69
+ this.attributes = {};
70
+ this.mappings = {
71
+ core: {},
72
+ };
73
+ this.custom = {};
74
+ this.id = 'ss-ib-' + banner.config.position.index;
75
+ this.config = banner.config;
76
+ this.value = banner.value;
77
+ (0, mobx_1.makeObservable)(this, {
78
+ id: mobx_1.observable,
79
+ mappings: mobx_1.observable,
80
+ attributes: mobx_1.observable,
81
+ });
82
+ }
83
+ return Banner;
84
+ }());
85
+ var Product = /** @class */ (function () {
86
+ function Product(services, result) {
87
+ var _a;
88
+ this.type = 'product';
89
+ this.attributes = {};
90
+ this.mappings = {
91
+ core: {},
92
+ };
93
+ this.custom = {};
94
+ this.children = [];
95
+ this.id = result.id;
96
+ this.attributes = result.attributes;
97
+ this.mappings = result.mappings;
98
+ if ((_a = result === null || result === void 0 ? void 0 : result.children) === null || _a === void 0 ? void 0 : _a.length) {
99
+ this.children = result.children.map(function (variant, index) {
100
+ return new Child(services, __assign({ id: "".concat(result.id, "-").concat(index) }, variant));
101
+ });
102
+ }
103
+ (0, mobx_1.makeObservable)(this, {
104
+ id: mobx_1.observable,
105
+ attributes: mobx_1.observable,
106
+ custom: mobx_1.observable,
107
+ });
108
+ // must set all subo
109
+ var coreObservables = Object.keys(result.mappings.core).reduce(function (map, key) {
110
+ var _a;
111
+ return __assign(__assign({}, map), (_a = {}, _a[key] = mobx_1.observable, _a));
112
+ }, {});
113
+ (0, mobx_1.makeObservable)(this.mappings.core, coreObservables);
114
+ }
115
+ return Product;
116
+ }());
117
+ var Child = /** @class */ (function () {
118
+ function Child(services, result) {
119
+ this.type = 'child';
120
+ this.attributes = {};
121
+ this.custom = {};
122
+ this.id = result.id;
123
+ this.attributes = result.attributes;
124
+ (0, mobx_1.makeObservable)(this, {
125
+ id: mobx_1.observable,
126
+ attributes: mobx_1.observable,
127
+ custom: mobx_1.observable,
128
+ });
129
+ }
130
+ return Child;
131
+ }());
132
+ function addBannersToResults(config, results, banners, paginationData) {
133
+ var _a;
134
+ var productCount = results.length;
135
+ var minIndex = paginationData.pageSize * (paginationData.page - 1);
136
+ var maxIndex = minIndex + paginationData.pageSize;
137
+ if ((_a = config === null || config === void 0 ? void 0 : config.settings) === null || _a === void 0 ? void 0 : _a.infinite) {
138
+ minIndex = 0;
139
+ }
140
+ banners
141
+ .reduce(function (adding, banner) {
142
+ var resultCount = productCount + adding.length;
143
+ if (banner.config.position.index >= minIndex && (banner.config.position.index < maxIndex || resultCount < paginationData.pageSize)) {
144
+ adding.push(banner);
145
+ }
146
+ return adding;
147
+ }, [])
148
+ .forEach(function (banner, index) {
149
+ var adjustedIndex = banner.config.position.index - minIndex;
150
+ if (adjustedIndex > productCount - 1) {
151
+ adjustedIndex = productCount + index;
152
+ }
153
+ results.splice(adjustedIndex, 0, banner);
154
+ });
155
+ return results;
156
+ }
@@ -0,0 +1,21 @@
1
+ import type { UrlManager } from '@searchspring/snap-url-manager';
2
+ import type { StoreServices } from '../../types';
3
+ import type { MetaResponseModel, SearchResponseModelSearch, SearchResponseModelSorting } from '@searchspring/snapi-types';
4
+ export declare class SortingStore {
5
+ options: Option[];
6
+ constructor(services: StoreServices, sorting: SearchResponseModelSorting[], search: SearchResponseModelSearch, meta: MetaResponseModel);
7
+ get current(): Option;
8
+ }
9
+ declare class Option {
10
+ active: boolean;
11
+ default: boolean;
12
+ field: string;
13
+ label: string;
14
+ direction: string;
15
+ type: string;
16
+ value: string;
17
+ url: UrlManager;
18
+ constructor(services: StoreServices, option: any, index: any);
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=SortingStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SortingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/SortingStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,iBAAiB,EAIjB,yBAAyB,EACzB,0BAA0B,EAC1B,MAAM,2BAA2B,CAAC;AAOnC,qBAAa,YAAY;IACxB,OAAO,EAAE,MAAM,EAAE,CAAM;gBAEX,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,0BAA0B,EAAE,EAAE,MAAM,EAAE,yBAAyB,EAAE,IAAI,EAAE,iBAAiB;IAuCtI,IAAI,OAAO,IAAI,MAAM,CAEpB;CACD;AAED,cAAM,MAAM;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,UAAU,CAAC;gBAEJ,QAAQ,EAAE,aAAa,EAAE,MAAM,KAAA,EAAE,KAAK,KAAA;CAuBlD"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SortingStore = void 0;
4
+ var mobx_1 = require("mobx");
5
+ var SortingStore = /** @class */ (function () {
6
+ function SortingStore(services, sorting, search, meta) {
7
+ this.options = [];
8
+ if (services && meta.sortOptions) {
9
+ var activeSort_1 = sorting && sorting.length && sorting[0];
10
+ this.options = meta.sortOptions
11
+ .filter(function (option) {
12
+ if (!(search === null || search === void 0 ? void 0 : search.query)) {
13
+ return option.type == 'field';
14
+ }
15
+ return option;
16
+ })
17
+ .map(function (option, index) {
18
+ option.active = false;
19
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
20
+ // @ts-ignore
21
+ if (activeSort_1 && activeSort_1.field == option.field && activeSort_1.direction == option.direction) {
22
+ option.active = true;
23
+ }
24
+ else if (!activeSort_1 && index === 0) {
25
+ option.active = true;
26
+ }
27
+ option.default = false;
28
+ if (index === 0) {
29
+ // is the default sort
30
+ option.default = true;
31
+ }
32
+ var optionObj = new Option(services, option, index);
33
+ return optionObj;
34
+ });
35
+ (0, mobx_1.makeObservable)(this, {
36
+ options: mobx_1.observable,
37
+ current: mobx_1.computed,
38
+ });
39
+ }
40
+ }
41
+ Object.defineProperty(SortingStore.prototype, "current", {
42
+ get: function () {
43
+ return this.options.filter(function (option) { return option.active; }).pop();
44
+ },
45
+ enumerable: false,
46
+ configurable: true
47
+ });
48
+ return SortingStore;
49
+ }());
50
+ exports.SortingStore = SortingStore;
51
+ var Option = /** @class */ (function () {
52
+ function Option(services, option, index) {
53
+ this.active = option.active;
54
+ this.default = option.default;
55
+ this.field = option.field;
56
+ this.label = option.label;
57
+ this.direction = option.direction;
58
+ this.type = option.type;
59
+ this.value = "".concat(option.label, ":").concat(option.field, ":").concat(option.direction, ":").concat(index);
60
+ if (this.default) {
61
+ this.url = services.urlManager.remove('page').remove('sort');
62
+ }
63
+ else {
64
+ this.url = services.urlManager.remove('page').set('sort', [{ field: this.field, direction: this.direction }]);
65
+ }
66
+ (0, mobx_1.makeObservable)(this, {
67
+ field: mobx_1.observable,
68
+ label: mobx_1.observable,
69
+ direction: mobx_1.observable,
70
+ type: mobx_1.observable,
71
+ value: mobx_1.observable,
72
+ });
73
+ }
74
+ return Option;
75
+ }());
@@ -0,0 +1,8 @@
1
+ export { MerchandisingStore } from './MerchandisingStore';
2
+ export { FacetStore } from './FacetStore';
3
+ export { FilterStore } from './FilterStore';
4
+ export { PaginationStore } from './PaginationStore';
5
+ export { ResultStore } from './ResultStore';
6
+ export { SortingStore } from './SortingStore';
7
+ export { QueryStore } from './QueryStore';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryStore = exports.SortingStore = exports.ResultStore = exports.PaginationStore = exports.FilterStore = exports.FacetStore = exports.MerchandisingStore = void 0;
4
+ var MerchandisingStore_1 = require("./MerchandisingStore");
5
+ Object.defineProperty(exports, "MerchandisingStore", { enumerable: true, get: function () { return MerchandisingStore_1.MerchandisingStore; } });
6
+ var FacetStore_1 = require("./FacetStore");
7
+ Object.defineProperty(exports, "FacetStore", { enumerable: true, get: function () { return FacetStore_1.FacetStore; } });
8
+ var FilterStore_1 = require("./FilterStore");
9
+ Object.defineProperty(exports, "FilterStore", { enumerable: true, get: function () { return FilterStore_1.FilterStore; } });
10
+ var PaginationStore_1 = require("./PaginationStore");
11
+ Object.defineProperty(exports, "PaginationStore", { enumerable: true, get: function () { return PaginationStore_1.PaginationStore; } });
12
+ var ResultStore_1 = require("./ResultStore");
13
+ Object.defineProperty(exports, "ResultStore", { enumerable: true, get: function () { return ResultStore_1.ResultStore; } });
14
+ var SortingStore_1 = require("./SortingStore");
15
+ Object.defineProperty(exports, "SortingStore", { enumerable: true, get: function () { return SortingStore_1.SortingStore; } });
16
+ var QueryStore_1 = require("./QueryStore");
17
+ Object.defineProperty(exports, "QueryStore", { enumerable: true, get: function () { return QueryStore_1.QueryStore; } });
@@ -0,0 +1,25 @@
1
+ export declare class StorageStore {
2
+ type: StorageType | null;
3
+ expiration: number;
4
+ sameSite: any;
5
+ key: string;
6
+ state: {};
7
+ constructor(config?: StorageConfig);
8
+ set(path: string, value: any): void;
9
+ get(path: string): any;
10
+ clear(): void;
11
+ }
12
+ export declare type StorageConfig = {
13
+ type: StorageType;
14
+ cookie?: {
15
+ expiration?: number;
16
+ sameSite?: string;
17
+ };
18
+ key: string;
19
+ };
20
+ export declare enum StorageType {
21
+ SESSION = "session",
22
+ LOCAL = "local",
23
+ COOKIE = "cookie"
24
+ }
25
+ //# sourceMappingURL=StorageStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageStore.d.ts","sourceRoot":"","sources":["../../../src/Storage/StorageStore.ts"],"names":[],"mappings":"AAMA,qBAAa,YAAY;IACxB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAQ;IAChC,UAAU,SAAe;IACzB,QAAQ,MAAa;IACrB,GAAG,SAAgB;IACnB,KAAK,KAAM;gBAEC,MAAM,CAAC,EAAE,aAAa;IAwClC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAyBnC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG;IA+BtB,KAAK,IAAI,IAAI;CAcb;AAED,oBAAY,aAAa,GAAG;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,GAAG,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,oBAAY,WAAW;IACtB,OAAO,YAAY;IACnB,KAAK,UAAU;IACf,MAAM,WAAW;CACjB"}