@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,317 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FacetStore = void 0;
19
+ var mobx_1 = require("mobx");
20
+ var FacetStore = /** @class */ (function (_super) {
21
+ __extends(FacetStore, _super);
22
+ function FacetStore(config, services, storage, facetsData, pagination, meta) {
23
+ if (facetsData === void 0) { facetsData = []; }
24
+ var _this = this;
25
+ var facets = facetsData
26
+ .filter(function (facet) {
27
+ var _a, _b, _c, _d;
28
+ var facetMeta = meta.facets[facet.field];
29
+ if ((_b = (_a = config.settings) === null || _a === void 0 ? void 0 : _a.facets) === null || _b === void 0 ? void 0 : _b.trim) {
30
+ if ((facetMeta.display == 'slider' && facet.type !== 'range') || (facet.type == 'range' && facetMeta.display !== 'slider')) {
31
+ return false;
32
+ }
33
+ else if (facet.type === 'range' &&
34
+ facet.range.low == facet.range.high) {
35
+ return false;
36
+ }
37
+ else if (((_c = facet.values) === null || _c === void 0 ? void 0 : _c.length) == 0) {
38
+ return false;
39
+ }
40
+ else if (!facet.filtered && ((_d = facet.values) === null || _d === void 0 ? void 0 : _d.length) == 1) {
41
+ return facet.values[0].count != pagination.totalResults;
42
+ }
43
+ }
44
+ return true;
45
+ })
46
+ .map(function (facet) {
47
+ var facetMeta = meta.facets[facet.field];
48
+ switch (facet.type) {
49
+ case 'range':
50
+ return new RangeFacet(services, storage, facet, facetMeta);
51
+ case 'value':
52
+ case 'range-buckets':
53
+ default:
54
+ return new ValueFacet(config, services, storage, facet, facetMeta);
55
+ }
56
+ });
57
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
58
+ // @ts-ignore
59
+ _this = _super.apply(this, facets) || this;
60
+ return _this;
61
+ }
62
+ Object.defineProperty(FacetStore, Symbol.species, {
63
+ get: function () {
64
+ return Array;
65
+ },
66
+ enumerable: false,
67
+ configurable: true
68
+ });
69
+ return FacetStore;
70
+ }(Array));
71
+ exports.FacetStore = FacetStore;
72
+ var Facet = /** @class */ (function () {
73
+ function Facet(services, storage, facet, facetMeta) {
74
+ this.filtered = false;
75
+ this.custom = {};
76
+ this.collapsed = false;
77
+ this.display = '';
78
+ this.label = '';
79
+ this.services = services;
80
+ this.storage = storage;
81
+ Object.assign(this, facetMeta, facet);
82
+ (0, mobx_1.makeObservable)(this, {
83
+ type: mobx_1.observable,
84
+ field: mobx_1.observable,
85
+ filtered: mobx_1.observable,
86
+ custom: mobx_1.observable,
87
+ collapsed: mobx_1.observable,
88
+ display: mobx_1.observable,
89
+ label: mobx_1.observable,
90
+ clear: mobx_1.computed,
91
+ toggleCollapse: mobx_1.action,
92
+ });
93
+ var collapseData = this.storage.get("facets.".concat(this.field, ".collapsed"));
94
+ this.collapsed = collapseData !== null && collapseData !== void 0 ? collapseData : this.collapsed;
95
+ if (this.filtered && this.collapsed && typeof collapseData == 'undefined') {
96
+ this.toggleCollapse();
97
+ }
98
+ }
99
+ Object.defineProperty(Facet.prototype, "clear", {
100
+ get: function () {
101
+ var _a, _b;
102
+ return {
103
+ url: (_b = (_a = this.services) === null || _a === void 0 ? void 0 : _a.urlManager) === null || _b === void 0 ? void 0 : _b.remove('page').remove("filter.".concat(this.field)),
104
+ };
105
+ },
106
+ enumerable: false,
107
+ configurable: true
108
+ });
109
+ Facet.prototype.toggleCollapse = function () {
110
+ this.collapsed = !this.collapsed;
111
+ this.storage.set("facets.".concat(this.field, ".collapsed"), this.collapsed);
112
+ };
113
+ return Facet;
114
+ }());
115
+ var RangeFacet = /** @class */ (function (_super) {
116
+ __extends(RangeFacet, _super);
117
+ function RangeFacet(services, storage, facet, facetMeta) {
118
+ var _this = _super.call(this, services, storage, facet, facetMeta) || this;
119
+ _this.range = {
120
+ low: 0,
121
+ high: 0,
122
+ };
123
+ _this.active = {
124
+ low: 0,
125
+ high: 0,
126
+ };
127
+ _this.step = facet.step;
128
+ var storedRange = _this.storage.get("facets.".concat(_this.field, ".range"));
129
+ if (storedRange && facet.filtered && (facet.range.low > storedRange.low || facet.range.high < storedRange.high)) {
130
+ // range from API has shrunk
131
+ _this.range = _this.storage.get("facets.".concat(_this.field, ".range"));
132
+ }
133
+ else {
134
+ _this.storage.set("facets.".concat(_this.field, ".range"), facet.range);
135
+ _this.range = facet.range;
136
+ }
137
+ // TODO: Fix api
138
+ // needed when API returns no active (only seems to be when range.low == range.high)
139
+ _this.active = facet.active || facet.range;
140
+ _this.formatSeparator = (facetMeta === null || facetMeta === void 0 ? void 0 : facetMeta.formatSeparator) || '-';
141
+ _this.formatValue = (facetMeta === null || facetMeta === void 0 ? void 0 : facetMeta.formatValue) || '%01.2f';
142
+ (0, mobx_1.makeObservable)(_this, {
143
+ step: mobx_1.observable,
144
+ range: mobx_1.observable,
145
+ active: mobx_1.observable,
146
+ formatSeparator: mobx_1.observable,
147
+ formatValue: mobx_1.observable,
148
+ });
149
+ return _this;
150
+ }
151
+ return RangeFacet;
152
+ }(Facet));
153
+ var ValueFacet = /** @class */ (function (_super) {
154
+ __extends(ValueFacet, _super);
155
+ function ValueFacet(config, services, storage, facet, facetMeta) {
156
+ var _a, _b;
157
+ var _this = _super.call(this, services, storage, facet, facetMeta) || this;
158
+ _this.values = [];
159
+ _this.search = {
160
+ input: '',
161
+ };
162
+ _this.overflow = {
163
+ enabled: false,
164
+ limited: true,
165
+ limit: 0,
166
+ remaining: undefined,
167
+ setLimit: function (limit) {
168
+ if (limit != this.limit) {
169
+ this.enabled = true;
170
+ this.limit = limit;
171
+ this.calculate();
172
+ }
173
+ },
174
+ toggle: function (val) {
175
+ if (typeof val != 'undefined') {
176
+ _this.overflow.limited = val;
177
+ }
178
+ else {
179
+ _this.overflow.limited = !_this.overflow.limited;
180
+ }
181
+ _this.storage.set("facets.".concat(_this.field, ".overflow.limited"), _this.overflow.limited);
182
+ _this.overflow.calculate();
183
+ },
184
+ calculate: function () {
185
+ if (_this.overflow.limit > 0) {
186
+ var remaining = _this.values.length - _this.overflow.limit;
187
+ if (remaining > 0 && !_this.search.input) {
188
+ _this.overflow.enabled = true;
189
+ if (_this.overflow.limited) {
190
+ _this.overflow.remaining = remaining;
191
+ }
192
+ else {
193
+ _this.overflow.remaining = 0;
194
+ }
195
+ }
196
+ else {
197
+ _this.overflow.enabled = false;
198
+ }
199
+ }
200
+ },
201
+ };
202
+ _this.multiple = _this.multiple;
203
+ _this.values =
204
+ (facet.values &&
205
+ facet.values.map(function (value) {
206
+ switch (facet.type) {
207
+ case 'value':
208
+ if (facetMeta.display === 'hierarchy') {
209
+ var filteredValues = facet.values.filter(function (value) { return value.filtered; });
210
+ return new HierarchyValue(services, _this, value, filteredValues);
211
+ }
212
+ else {
213
+ return new Value(services, _this, value);
214
+ }
215
+ case 'range-buckets':
216
+ return new RangeValue(services, _this, value);
217
+ }
218
+ })) ||
219
+ [];
220
+ if (((_b = (_a = config.settings) === null || _a === void 0 ? void 0 : _a.facets) === null || _b === void 0 ? void 0 : _b.pinFiltered) && facetMeta.display !== 'hierarchy') {
221
+ _this.values.sort(function (a, b) { return Number(b.filtered) - Number(a.filtered); });
222
+ }
223
+ var overflowLimitedState = _this.storage.get("facets.".concat(_this.field, ".overflow.limited"));
224
+ if (typeof overflowLimitedState != 'undefined') {
225
+ _this.overflow.toggle(overflowLimitedState);
226
+ }
227
+ (0, mobx_1.makeObservable)(_this, {
228
+ values: mobx_1.observable,
229
+ search: mobx_1.observable,
230
+ multiple: mobx_1.observable,
231
+ overflow: mobx_1.observable,
232
+ refinedValues: mobx_1.computed,
233
+ });
234
+ (0, mobx_1.reaction)(function () { return _this.search.input; }, function () {
235
+ _this.overflow.calculate();
236
+ });
237
+ return _this;
238
+ }
239
+ Object.defineProperty(ValueFacet.prototype, "refinedValues", {
240
+ get: function () {
241
+ var values = this.values || [];
242
+ if (this.search.input) {
243
+ var search_1 = new RegExp(escapeRegExp(this.search.input), 'i');
244
+ values = this.values.filter(function (value) { return String(value.label).match(search_1); });
245
+ }
246
+ if (this.overflow.enabled && this.overflow.limited) {
247
+ values = values.slice(0, this.overflow.limit);
248
+ }
249
+ return values;
250
+ },
251
+ enumerable: false,
252
+ configurable: true
253
+ });
254
+ return ValueFacet;
255
+ }(Facet));
256
+ var Value = /** @class */ (function () {
257
+ function Value(services, facet, value) {
258
+ var _a, _b;
259
+ Object.assign(this, value);
260
+ if (this.filtered) {
261
+ this.url = (_a = services.urlManager) === null || _a === void 0 ? void 0 : _a.remove('page').remove("filter.".concat(facet.field), value.value);
262
+ }
263
+ else {
264
+ var valueUrl = (_b = services.urlManager) === null || _b === void 0 ? void 0 : _b.remove('page');
265
+ if (facet.multiple == 'single') {
266
+ valueUrl = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.remove("filter.".concat(facet.field));
267
+ }
268
+ this.url = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.merge("filter.".concat(facet.field), value.value);
269
+ }
270
+ }
271
+ return Value;
272
+ }());
273
+ var HierarchyValue = /** @class */ (function (_super) {
274
+ __extends(HierarchyValue, _super);
275
+ function HierarchyValue(services, facet, value, filteredValues) {
276
+ var _a, _b;
277
+ var _this = _super.call(this, services, facet, value) || this;
278
+ _this.level = 0;
279
+ _this.history = false;
280
+ if (value.value && facet.hierarchyDelimiter) {
281
+ _this.level = value.value.split(facet.hierarchyDelimiter).length;
282
+ }
283
+ if (facet.filtered && (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length)) {
284
+ var filteredLevel = filteredValues[0].value.split(facet.hierarchyDelimiter).length;
285
+ if (_this.level <= filteredLevel) {
286
+ _this.history = true;
287
+ }
288
+ }
289
+ if (value.value) {
290
+ _this.url = (_a = services === null || services === void 0 ? void 0 : services.urlManager) === null || _a === void 0 ? void 0 : _a.remove('page').set("filter.".concat(facet.field), value.value);
291
+ }
292
+ else {
293
+ _this.url = (_b = services === null || services === void 0 ? void 0 : services.urlManager) === null || _b === void 0 ? void 0 : _b.remove('page').remove("filter.".concat(facet.field));
294
+ }
295
+ return _this;
296
+ }
297
+ return HierarchyValue;
298
+ }(Value));
299
+ var RangeValue = /** @class */ (function () {
300
+ function RangeValue(services, facet, value) {
301
+ Object.assign(this, value);
302
+ if (this.filtered) {
303
+ this.url = services === null || services === void 0 ? void 0 : services.urlManager.remove('page').remove("filter.".concat(facet.field), [{ low: this.low, high: this.high }]);
304
+ }
305
+ else {
306
+ var valueUrl = services === null || services === void 0 ? void 0 : services.urlManager.remove('page');
307
+ if (facet.multiple == 'single') {
308
+ valueUrl = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.remove("filter.".concat(facet.field));
309
+ }
310
+ this.url = valueUrl === null || valueUrl === void 0 ? void 0 : valueUrl.merge("filter.".concat(facet.field), [{ low: this.low, high: this.high }]);
311
+ }
312
+ }
313
+ return RangeValue;
314
+ }());
315
+ function escapeRegExp(string) {
316
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
317
+ }
@@ -0,0 +1,7 @@
1
+ import type { StoreServices } from '../../types';
2
+ import type { SearchResponseModelFilter, MetaResponseModel } from '@searchspring/snapi-types';
3
+ export declare class FilterStore extends Array {
4
+ static get [Symbol.species](): ArrayConstructor;
5
+ constructor(services: StoreServices, filtersData: SearchResponseModelFilter[], meta: MetaResponseModel);
6
+ }
7
+ //# sourceMappingURL=FilterStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FilterStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/FilterStore.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACX,yBAAyB,EACzB,iBAAiB,EAKjB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,WAAY,SAAQ,KAAK;IACrC,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEW,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,yBAAyB,EAAO,EAAE,IAAI,EAAE,iBAAiB;CAuC3G"}
@@ -0,0 +1,100 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FilterStore = void 0;
19
+ var mobx_1 = require("mobx");
20
+ var FilterStore = /** @class */ (function (_super) {
21
+ __extends(FilterStore, _super);
22
+ function FilterStore(services, filtersData, meta) {
23
+ if (filtersData === void 0) { filtersData = []; }
24
+ var _this = this;
25
+ var filters = filtersData.map(function (filter) {
26
+ var facetMeta = meta.facets[filter.field];
27
+ switch (filter.type) {
28
+ case 'range':
29
+ var rangeFilter = filter;
30
+ return new RangeFilter(services, {
31
+ facet: {
32
+ field: rangeFilter.field,
33
+ label: (facetMeta === null || facetMeta === void 0 ? void 0 : facetMeta.label) || rangeFilter.field,
34
+ },
35
+ value: {
36
+ low: rangeFilter.value.low,
37
+ high: rangeFilter.value.high,
38
+ label: rangeFilter.label || "".concat(rangeFilter.value.low, " - ").concat(rangeFilter.value.high),
39
+ },
40
+ });
41
+ case 'value':
42
+ default:
43
+ var valueFilter = filter;
44
+ return new Filter(services, {
45
+ facet: {
46
+ field: valueFilter.field,
47
+ label: (facetMeta === null || facetMeta === void 0 ? void 0 : facetMeta.label) || valueFilter.field,
48
+ },
49
+ value: {
50
+ value: valueFilter.value,
51
+ label: valueFilter.label,
52
+ },
53
+ });
54
+ }
55
+ });
56
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
+ // @ts-ignore
58
+ _this = _super.apply(this, filters) || this;
59
+ return _this;
60
+ }
61
+ Object.defineProperty(FilterStore, Symbol.species, {
62
+ get: function () {
63
+ return Array;
64
+ },
65
+ enumerable: false,
66
+ configurable: true
67
+ });
68
+ return FilterStore;
69
+ }(Array));
70
+ exports.FilterStore = FilterStore;
71
+ var Filter = /** @class */ (function () {
72
+ function Filter(services, filter) {
73
+ var _a;
74
+ this.facet = filter.facet;
75
+ this.value = filter.value;
76
+ this.label = "".concat(filter.facet.label, ": ").concat(filter.value.label);
77
+ this.url = (_a = services === null || services === void 0 ? void 0 : services.urlManager) === null || _a === void 0 ? void 0 : _a.remove('page').remove("filter.".concat(this.facet.field), this.value.value);
78
+ (0, mobx_1.makeObservable)(this, {
79
+ facet: mobx_1.observable,
80
+ value: mobx_1.observable,
81
+ label: mobx_1.observable,
82
+ });
83
+ }
84
+ return Filter;
85
+ }());
86
+ var RangeFilter = /** @class */ (function () {
87
+ function RangeFilter(services, filter) {
88
+ var _a;
89
+ this.facet = filter.facet;
90
+ this.value = filter.value;
91
+ this.label = "".concat(filter.facet.label, ": ").concat(filter.value.label);
92
+ this.url = (_a = services === null || services === void 0 ? void 0 : services.urlManager) === null || _a === void 0 ? void 0 : _a.remove('page').remove("filter.".concat(filter.facet.field), { low: filter.value.low, high: filter.value.high });
93
+ (0, mobx_1.makeObservable)(this, {
94
+ facet: mobx_1.observable,
95
+ value: mobx_1.observable,
96
+ label: mobx_1.observable,
97
+ });
98
+ }
99
+ return RangeFilter;
100
+ }());
@@ -0,0 +1,20 @@
1
+ import type { StoreServices } from '../../types';
2
+ import type { SearchResponseModelMerchandising } from '@searchspring/snapi-types';
3
+ declare enum ContentType {
4
+ HEADER = "header",
5
+ BANNER = "banner",
6
+ FOOTER = "footer",
7
+ LEFT = "left",
8
+ INLINE = "inline"
9
+ }
10
+ export declare class MerchandisingStore {
11
+ redirect: string;
12
+ content: Partial<Record<ContentType, Content[]>>;
13
+ constructor(services: StoreServices, merchData: SearchResponseModelMerchandising);
14
+ }
15
+ declare class Content extends Array {
16
+ static get [Symbol.species](): ArrayConstructor;
17
+ constructor(content: any);
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=MerchandisingStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MerchandisingStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/MerchandisingStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAElF,aAAK,WAAW;IACf,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,MAAM,WAAW;CACjB;AACD,qBAAa,kBAAkB;IAC9B,QAAQ,SAAM;IACd,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC,CAAM;gBAE1C,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,gCAAgC;CAahF;AAED,cAAM,OAAQ,SAAQ,KAAK;IAC1B,MAAM,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAE9C;gBAEW,OAAO,KAAA;CAGnB"}
@@ -0,0 +1,59 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MerchandisingStore = void 0;
19
+ var ContentType;
20
+ (function (ContentType) {
21
+ ContentType["HEADER"] = "header";
22
+ ContentType["BANNER"] = "banner";
23
+ ContentType["FOOTER"] = "footer";
24
+ ContentType["LEFT"] = "left";
25
+ ContentType["INLINE"] = "inline";
26
+ })(ContentType || (ContentType = {}));
27
+ var MerchandisingStore = /** @class */ (function () {
28
+ function MerchandisingStore(services, merchData) {
29
+ var _this = this;
30
+ this.redirect = '';
31
+ this.content = {};
32
+ if (merchData) {
33
+ this.redirect = merchData.redirect || '';
34
+ if (merchData.content) {
35
+ Object.values(ContentType).forEach(function (type) {
36
+ if (merchData.content[type]) {
37
+ _this.content[type] = new Content(merchData.content[type]);
38
+ }
39
+ });
40
+ }
41
+ }
42
+ }
43
+ return MerchandisingStore;
44
+ }());
45
+ exports.MerchandisingStore = MerchandisingStore;
46
+ var Content = /** @class */ (function (_super) {
47
+ __extends(Content, _super);
48
+ function Content(content) {
49
+ return _super.apply(this, content) || this;
50
+ }
51
+ Object.defineProperty(Content, Symbol.species, {
52
+ get: function () {
53
+ return Array;
54
+ },
55
+ enumerable: false,
56
+ configurable: true
57
+ });
58
+ return Content;
59
+ }(Array));
@@ -0,0 +1,40 @@
1
+ import type { SearchStoreConfig, StoreServices } from '../../types';
2
+ import type { SearchResponseModelPagination } from '@searchspring/snapi-types';
3
+ import type { UrlManager } from '@searchspring/snap-url-manager';
4
+ export declare class PaginationStore {
5
+ private services;
6
+ page: number;
7
+ pageSize: number;
8
+ pageSizeOptions: {
9
+ label: string;
10
+ value: number;
11
+ }[];
12
+ defaultPageSize: number;
13
+ totalResults: number;
14
+ totalPages: number;
15
+ infinite: boolean;
16
+ controllerConfig: SearchStoreConfig;
17
+ constructor(config: SearchStoreConfig, services: StoreServices, paginationData?: SearchResponseModelPagination);
18
+ get begin(): number;
19
+ get end(): number;
20
+ get multiplePages(): boolean;
21
+ get current(): Page;
22
+ get first(): Page;
23
+ get last(): Page;
24
+ get next(): Page;
25
+ get previous(): Page;
26
+ getPages(min?: number, max?: number): Page[];
27
+ setPageSize(num: number): void;
28
+ }
29
+ export declare class Page {
30
+ services: StoreServices;
31
+ number: number;
32
+ active: boolean;
33
+ url: UrlManager;
34
+ key: string;
35
+ constructor(services: StoreServices, page: {
36
+ number: number;
37
+ active?: boolean;
38
+ });
39
+ }
40
+ //# sourceMappingURL=PaginationStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaginationStore.d.ts","sourceRoot":"","sources":["../../../../src/Search/Stores/PaginationStore.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEjE,qBAAa,eAAe;IAC3B,OAAO,CAAC,QAAQ,CAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IACJ,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,gBAAgB,EAAE,iBAAiB,CAAC;gBAGnC,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,aAAa,EACvB,cAAc,GAAE,6BAMf;IA4CF,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,IAAI,GAAG,IAAI,MAAM,CAMhB;IAED,IAAI,aAAa,IAAI,OAAO,CAE3B;IAED,IAAI,OAAO,IAAI,IAAI,CAKlB;IAED,IAAI,KAAK,IAAI,IAAI,CAKhB;IAED,IAAI,IAAI,IAAI,IAAI,CAKf;IAED,IAAI,IAAI,IAAI,IAAI,CAMf;IAED,IAAI,QAAQ,IAAI,IAAI,CAMnB;IAED,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE;IAmD5C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;CAK9B;AAED,qBAAa,IAAI;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,UAAU,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;gBAGX,QAAQ,EAAE,aAAa,EACvB,IAAI,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;KACjB;CAQF"}