@searchspring/snap-controller 0.61.4 → 0.62.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/AutocompleteController.d.ts.map +1 -1
- package/dist/cjs/Autocomplete/AutocompleteController.js +52 -65
- package/dist/cjs/Finder/FinderController.d.ts.map +1 -1
- package/dist/cjs/Finder/FinderController.js +30 -41
- package/dist/cjs/Recommendation/RecommendationController.d.ts.map +1 -1
- package/dist/cjs/Recommendation/RecommendationController.js +45 -48
- package/dist/cjs/Search/SearchController.d.ts.map +1 -1
- package/dist/cjs/Search/SearchController.js +53 -66
- package/dist/esm/Autocomplete/AutocompleteController.d.ts.map +1 -1
- package/dist/esm/Autocomplete/AutocompleteController.js +25 -24
- package/dist/esm/Finder/FinderController.d.ts.map +1 -1
- package/dist/esm/Finder/FinderController.js +12 -13
- package/dist/esm/Recommendation/RecommendationController.d.ts.map +1 -1
- package/dist/esm/Recommendation/RecommendationController.js +23 -17
- package/dist/esm/Search/SearchController.d.ts.map +1 -1
- package/dist/esm/Search/SearchController.js +12 -15
- package/package.json +10 -10
|
@@ -82,6 +82,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
82
82
|
__extends(RecommendationController, _super);
|
|
83
83
|
function RecommendationController(config, _a, context) {
|
|
84
84
|
var client = _a.client, store = _a.store, urlManager = _a.urlManager, eventManager = _a.eventManager, profiler = _a.profiler, logger = _a.logger, tracker = _a.tracker;
|
|
85
|
+
var _b;
|
|
85
86
|
var _this = _super.call(this, config, { client: client, store: store, urlManager: urlManager, eventManager: eventManager, profiler: profiler, logger: logger, tracker: tracker }, context) || this;
|
|
86
87
|
_this.type = types_1.ControllerTypes.recommendation;
|
|
87
88
|
_this.events = {
|
|
@@ -137,7 +138,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
137
138
|
product: {
|
|
138
139
|
id: result.id,
|
|
139
140
|
mappings: {
|
|
140
|
-
core: result.
|
|
141
|
+
core: result.mappings.core,
|
|
141
142
|
},
|
|
142
143
|
seed: getSeed(),
|
|
143
144
|
},
|
|
@@ -165,7 +166,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
165
166
|
product: {
|
|
166
167
|
id: result.id,
|
|
167
168
|
mappings: {
|
|
168
|
-
core: result.
|
|
169
|
+
core: result.mappings.core,
|
|
169
170
|
},
|
|
170
171
|
seed: getSeed(),
|
|
171
172
|
},
|
|
@@ -194,7 +195,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
194
195
|
product: {
|
|
195
196
|
id: result.id,
|
|
196
197
|
mappings: {
|
|
197
|
-
core: result.
|
|
198
|
+
core: result.mappings.core,
|
|
198
199
|
},
|
|
199
200
|
seed: getSeed(),
|
|
200
201
|
},
|
|
@@ -227,7 +228,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
227
228
|
product: {
|
|
228
229
|
id: result.id,
|
|
229
230
|
mappings: {
|
|
230
|
-
core: result.
|
|
231
|
+
core: result.mappings.core,
|
|
231
232
|
},
|
|
232
233
|
seed: getSeed(),
|
|
233
234
|
},
|
|
@@ -260,7 +261,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
260
261
|
product: {
|
|
261
262
|
id: result.id,
|
|
262
263
|
mappings: {
|
|
263
|
-
core: result.
|
|
264
|
+
core: result.mappings.core,
|
|
264
265
|
},
|
|
265
266
|
seed: getSeed(),
|
|
266
267
|
},
|
|
@@ -290,7 +291,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
290
291
|
products: results.map(function (result) { return ({
|
|
291
292
|
id: result.id,
|
|
292
293
|
mappings: {
|
|
293
|
-
core: result.
|
|
294
|
+
core: result.mappings.core,
|
|
294
295
|
},
|
|
295
296
|
quantity: result.quantity,
|
|
296
297
|
}); }),
|
|
@@ -395,6 +396,7 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
395
396
|
return __generator(this, function (_a) {
|
|
396
397
|
switch (_a.label) {
|
|
397
398
|
case 0:
|
|
399
|
+
_a.trys.push([0, 16, 17, 18]);
|
|
398
400
|
if (!!this.initialized) return [3 /*break*/, 2];
|
|
399
401
|
return [4 /*yield*/, this.init()];
|
|
400
402
|
case 1:
|
|
@@ -402,20 +404,18 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
402
404
|
_a.label = 2;
|
|
403
405
|
case 2:
|
|
404
406
|
params = this.params;
|
|
407
|
+
this.store.loading = true;
|
|
405
408
|
_a.label = 3;
|
|
406
409
|
case 3:
|
|
407
|
-
_a.trys.push([3,
|
|
408
|
-
_a.label = 4;
|
|
409
|
-
case 4:
|
|
410
|
-
_a.trys.push([4, 6, , 7]);
|
|
410
|
+
_a.trys.push([3, 5, , 6]);
|
|
411
411
|
return [4 /*yield*/, this.eventManager.fire('beforeSearch', {
|
|
412
412
|
controller: this,
|
|
413
413
|
request: params,
|
|
414
414
|
})];
|
|
415
|
-
case
|
|
415
|
+
case 4:
|
|
416
416
|
_a.sent();
|
|
417
|
-
return [3 /*break*/,
|
|
418
|
-
case
|
|
417
|
+
return [3 /*break*/, 6];
|
|
418
|
+
case 5:
|
|
419
419
|
err_1 = _a.sent();
|
|
420
420
|
if ((err_1 === null || err_1 === void 0 ? void 0 : err_1.message) == 'cancelled') {
|
|
421
421
|
this.log.warn("'beforeSearch' middleware cancelled");
|
|
@@ -425,27 +425,27 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
425
425
|
this.log.error("error in 'beforeSearch' middleware");
|
|
426
426
|
throw err_1;
|
|
427
427
|
}
|
|
428
|
-
return [3 /*break*/,
|
|
429
|
-
case
|
|
428
|
+
return [3 /*break*/, 6];
|
|
429
|
+
case 6:
|
|
430
430
|
searchProfile = this.profiler.create({ type: 'event', name: 'search', context: params }).start();
|
|
431
431
|
return [4 /*yield*/, this.client.recommend(params)];
|
|
432
|
-
case
|
|
432
|
+
case 7:
|
|
433
433
|
response = _a.sent();
|
|
434
434
|
searchProfile.stop();
|
|
435
435
|
this.log.profile(searchProfile);
|
|
436
436
|
afterSearchProfile = this.profiler.create({ type: 'event', name: 'afterSearch', context: params }).start();
|
|
437
|
-
_a.label =
|
|
438
|
-
case
|
|
439
|
-
_a.trys.push([
|
|
437
|
+
_a.label = 8;
|
|
438
|
+
case 8:
|
|
439
|
+
_a.trys.push([8, 10, , 11]);
|
|
440
440
|
return [4 /*yield*/, this.eventManager.fire('afterSearch', {
|
|
441
441
|
controller: this,
|
|
442
442
|
request: params,
|
|
443
443
|
response: response,
|
|
444
444
|
})];
|
|
445
|
-
case
|
|
445
|
+
case 9:
|
|
446
446
|
_a.sent();
|
|
447
|
-
return [3 /*break*/,
|
|
448
|
-
case
|
|
447
|
+
return [3 /*break*/, 11];
|
|
448
|
+
case 10:
|
|
449
449
|
err_2 = _a.sent();
|
|
450
450
|
if ((err_2 === null || err_2 === void 0 ? void 0 : err_2.message) == 'cancelled') {
|
|
451
451
|
this.log.warn("'afterSearch' middleware cancelled");
|
|
@@ -456,25 +456,25 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
456
456
|
this.log.error("error in 'afterSearch' middleware");
|
|
457
457
|
throw err_2;
|
|
458
458
|
}
|
|
459
|
-
return [3 /*break*/,
|
|
460
|
-
case
|
|
459
|
+
return [3 /*break*/, 11];
|
|
460
|
+
case 11:
|
|
461
461
|
afterSearchProfile.stop();
|
|
462
462
|
this.log.profile(afterSearchProfile);
|
|
463
463
|
// update the store
|
|
464
464
|
this.store.update(response);
|
|
465
465
|
afterStoreProfile = this.profiler.create({ type: 'event', name: 'afterStore', context: params }).start();
|
|
466
|
-
_a.label =
|
|
467
|
-
case
|
|
468
|
-
_a.trys.push([
|
|
466
|
+
_a.label = 12;
|
|
467
|
+
case 12:
|
|
468
|
+
_a.trys.push([12, 14, , 15]);
|
|
469
469
|
return [4 /*yield*/, this.eventManager.fire('afterStore', {
|
|
470
470
|
controller: this,
|
|
471
471
|
request: params,
|
|
472
472
|
response: response,
|
|
473
473
|
})];
|
|
474
|
-
case
|
|
474
|
+
case 13:
|
|
475
475
|
_a.sent();
|
|
476
|
-
return [3 /*break*/,
|
|
477
|
-
case
|
|
476
|
+
return [3 /*break*/, 15];
|
|
477
|
+
case 14:
|
|
478
478
|
err_3 = _a.sent();
|
|
479
479
|
if ((err_3 === null || err_3 === void 0 ? void 0 : err_3.message) == 'cancelled') {
|
|
480
480
|
this.log.warn("'afterStore' middleware cancelled");
|
|
@@ -485,12 +485,12 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
485
485
|
this.log.error("error in 'afterStore' middleware");
|
|
486
486
|
throw err_3;
|
|
487
487
|
}
|
|
488
|
-
return [3 /*break*/,
|
|
489
|
-
case
|
|
488
|
+
return [3 /*break*/, 15];
|
|
489
|
+
case 15:
|
|
490
490
|
afterStoreProfile.stop();
|
|
491
491
|
this.log.profile(afterStoreProfile);
|
|
492
492
|
return [3 /*break*/, 18];
|
|
493
|
-
case
|
|
493
|
+
case 16:
|
|
494
494
|
err_4 = _a.sent();
|
|
495
495
|
if (err_4) {
|
|
496
496
|
if (err_4.err && err_4.fetchDetails) {
|
|
@@ -530,9 +530,11 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
530
530
|
this.log.error(err_4);
|
|
531
531
|
this.handleError(err_4);
|
|
532
532
|
}
|
|
533
|
-
this.store.loading = false;
|
|
534
533
|
}
|
|
535
534
|
return [3 /*break*/, 18];
|
|
535
|
+
case 17:
|
|
536
|
+
this.store.loading = false;
|
|
537
|
+
return [7 /*endfinally*/];
|
|
536
538
|
case 18: return [2 /*return*/];
|
|
537
539
|
}
|
|
538
540
|
});
|
|
@@ -540,22 +542,18 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
540
542
|
if (!config.tag) {
|
|
541
543
|
throw new Error("Invalid config passed to RecommendationController. The \"tag\" attribute is required.");
|
|
542
544
|
}
|
|
545
|
+
// attach to bfCache restore event and re-run search on the controller
|
|
546
|
+
// enabled by default
|
|
547
|
+
if (((_b = config.settings) === null || _b === void 0 ? void 0 : _b.searchOnPageShow) !== false) {
|
|
548
|
+
window.addEventListener('pageshow', function (e) {
|
|
549
|
+
if (e.persisted && !_this.store.error && _this.store.loaded && !_this.store.loading) {
|
|
550
|
+
_this.search();
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
}
|
|
543
554
|
// deep merge config with defaults
|
|
544
555
|
_this.config = (0, deepmerge_1.default)(defaultConfig, _this.config);
|
|
545
556
|
_this.store.setConfig(_this.config);
|
|
546
|
-
// add 'beforeSearch' middleware
|
|
547
|
-
_this.eventManager.on('beforeSearch', function (recommend, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
548
|
-
return __generator(this, function (_a) {
|
|
549
|
-
switch (_a.label) {
|
|
550
|
-
case 0:
|
|
551
|
-
recommend.controller.store.loading = true;
|
|
552
|
-
return [4 /*yield*/, next()];
|
|
553
|
-
case 1:
|
|
554
|
-
_a.sent();
|
|
555
|
-
return [2 /*return*/];
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
}); });
|
|
559
557
|
// add 'afterStore' middleware
|
|
560
558
|
_this.eventManager.on('afterStore', function (recommend, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
561
559
|
var _this = this;
|
|
@@ -578,7 +576,6 @@ var RecommendationController = /** @class */ (function (_super) {
|
|
|
578
576
|
_this.track.product.removedFromBundle(item);
|
|
579
577
|
});
|
|
580
578
|
});
|
|
581
|
-
recommend.controller.store.loading = false;
|
|
582
579
|
return [2 /*return*/];
|
|
583
580
|
}
|
|
584
581
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SearchController.d.ts","sourceRoot":"","sources":["../../../src/Search/SearchController.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAa,MAAM,+BAA+B,CAAC;AAExE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAE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AAQ,IAAI,CAAC,CAmN9B;CACF;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,kBAAkB,GAAG,kBAAkB,CAiBxF;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,GAAG,SAAS,CAgCvG"}
|
|
@@ -148,38 +148,37 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
148
148
|
},
|
|
149
149
|
};
|
|
150
150
|
_this.search = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
151
|
-
var
|
|
151
|
+
var params_1, err_1, stringyParams, prevStringyParams, searchProfile, meta, response, preventBackfill, dontBackfill, backfillRequests, backfillResponses, backfillResults, afterSearchProfile, err_2, afterStoreProfile, err_3, err_4;
|
|
152
152
|
var _a, _b;
|
|
153
153
|
var _this = this;
|
|
154
154
|
var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
155
155
|
return __generator(this, function (_p) {
|
|
156
156
|
switch (_p.label) {
|
|
157
157
|
case 0:
|
|
158
|
+
_p.trys.push([0, 22, 23, 24]);
|
|
158
159
|
if (!!this.initialized) return [3 /*break*/, 2];
|
|
159
160
|
return [4 /*yield*/, this.init()];
|
|
160
161
|
case 1:
|
|
161
162
|
_p.sent();
|
|
162
163
|
_p.label = 2;
|
|
163
164
|
case 2:
|
|
164
|
-
|
|
165
|
+
params_1 = this.params;
|
|
165
166
|
if (((_d = (_c = this.params.search) === null || _c === void 0 ? void 0 : _c.query) === null || _d === void 0 ? void 0 : _d.string) && ((_f = (_e = this.params.search) === null || _e === void 0 ? void 0 : _e.query) === null || _f === void 0 ? void 0 : _f.string.length)) {
|
|
166
167
|
// save it to the history store
|
|
167
168
|
this.store.history.save(this.params.search.query.string);
|
|
168
169
|
}
|
|
170
|
+
this.store.loading = true;
|
|
169
171
|
_p.label = 3;
|
|
170
172
|
case 3:
|
|
171
|
-
_p.trys.push([3,
|
|
172
|
-
_p.label = 4;
|
|
173
|
-
case 4:
|
|
174
|
-
_p.trys.push([4, 6, , 7]);
|
|
173
|
+
_p.trys.push([3, 5, , 6]);
|
|
175
174
|
return [4 /*yield*/, this.eventManager.fire('beforeSearch', {
|
|
176
175
|
controller: this,
|
|
177
|
-
request:
|
|
176
|
+
request: params_1,
|
|
178
177
|
})];
|
|
179
|
-
case
|
|
178
|
+
case 4:
|
|
180
179
|
_p.sent();
|
|
181
|
-
return [3 /*break*/,
|
|
182
|
-
case
|
|
180
|
+
return [3 /*break*/, 6];
|
|
181
|
+
case 5:
|
|
183
182
|
err_1 = _p.sent();
|
|
184
183
|
if ((err_1 === null || err_1 === void 0 ? void 0 : err_1.message) == 'cancelled') {
|
|
185
184
|
this.log.warn("'beforeSearch' middleware cancelled");
|
|
@@ -189,19 +188,19 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
189
188
|
this.log.error("error in 'beforeSearch' middleware");
|
|
190
189
|
throw err_1;
|
|
191
190
|
}
|
|
192
|
-
return [3 /*break*/,
|
|
193
|
-
case
|
|
194
|
-
stringyParams = JSON.stringify(
|
|
191
|
+
return [3 /*break*/, 6];
|
|
192
|
+
case 6:
|
|
193
|
+
stringyParams = JSON.stringify(params_1);
|
|
195
194
|
prevStringyParams = this.storage.get('lastStringyParams');
|
|
196
195
|
if (stringyParams == prevStringyParams) {
|
|
197
196
|
// no param change - not searching
|
|
198
197
|
return [2 /*return*/];
|
|
199
198
|
}
|
|
200
|
-
searchProfile = this.profiler.create({ type: 'event', name: 'search', context:
|
|
199
|
+
searchProfile = this.profiler.create({ type: 'event', name: 'search', context: params_1 }).start();
|
|
201
200
|
meta = {};
|
|
202
201
|
response = {};
|
|
203
|
-
if (!(((_g = this.config.settings) === null || _g === void 0 ? void 0 : _g.infinite) && ((_h =
|
|
204
|
-
preventBackfill = ((_j = this.config.settings.infinite) === null || _j === void 0 ? void 0 : _j.backfill) && !this.store.results.length &&
|
|
202
|
+
if (!(((_g = this.config.settings) === null || _g === void 0 ? void 0 : _g.infinite) && ((_h = params_1.pagination) === null || _h === void 0 ? void 0 : _h.page) && params_1.pagination.page > 1)) return [3 /*break*/, 11];
|
|
203
|
+
preventBackfill = ((_j = this.config.settings.infinite) === null || _j === void 0 ? void 0 : _j.backfill) && !this.store.results.length && params_1.pagination.page > this.config.settings.infinite.backfill;
|
|
205
204
|
dontBackfill = !((_k = this.config.settings.infinite) === null || _k === void 0 ? void 0 : _k.backfill) && !this.store.results.length;
|
|
206
205
|
// if the page is higher than the backfill setting redirect back to page 1
|
|
207
206
|
if (preventBackfill || dontBackfill) {
|
|
@@ -209,12 +208,12 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
209
208
|
this.urlManager.set('page', 1).go();
|
|
210
209
|
return [2 /*return*/];
|
|
211
210
|
}
|
|
212
|
-
if (!(((_l = this.config.settings) === null || _l === void 0 ? void 0 : _l.infinite.backfill) && !this.previousResults.length)) return [3 /*break*/,
|
|
213
|
-
backfillRequests = Array(
|
|
211
|
+
if (!(((_l = this.config.settings) === null || _l === void 0 ? void 0 : _l.infinite.backfill) && !this.previousResults.length)) return [3 /*break*/, 8];
|
|
212
|
+
backfillRequests = Array(params_1.pagination.page)
|
|
214
213
|
.fill('backfill')
|
|
215
214
|
.map(function (v, i) {
|
|
216
215
|
var _a, _b, _c, _d;
|
|
217
|
-
var backfillParams = (0, deepmerge_1.default)(__assign({},
|
|
216
|
+
var backfillParams = (0, deepmerge_1.default)(__assign({}, params_1), { pagination: { page: i + 1 }, search: { redirectResponse: 'full' } });
|
|
218
217
|
// don't include page parameter if on page 1
|
|
219
218
|
if (i + 1 == 1) {
|
|
220
219
|
(_a = backfillParams === null || backfillParams === void 0 ? void 0 : backfillParams.pagination) === null || _a === void 0 ? true : delete _a.page;
|
|
@@ -227,7 +226,7 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
227
226
|
return _this.client.search(backfillParams);
|
|
228
227
|
});
|
|
229
228
|
return [4 /*yield*/, Promise.all(backfillRequests)];
|
|
230
|
-
case
|
|
229
|
+
case 7:
|
|
231
230
|
backfillResponses = _p.sent();
|
|
232
231
|
// backfillResponses are [meta, searchResponse][]
|
|
233
232
|
// set the meta and response to the first page of backfillResponses
|
|
@@ -239,43 +238,43 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
239
238
|
}, []);
|
|
240
239
|
// overwrite pagination params to expected state
|
|
241
240
|
response.pagination.totalPages = Math.ceil(response.pagination.totalResults / response.pagination.pageSize);
|
|
242
|
-
response.pagination.page = (_m =
|
|
241
|
+
response.pagination.page = (_m = params_1.pagination) === null || _m === void 0 ? void 0 : _m.page;
|
|
243
242
|
// set the response results with results from backfill responses
|
|
244
243
|
response.results = backfillResults;
|
|
245
|
-
return [3 /*break*/,
|
|
246
|
-
case
|
|
247
|
-
case
|
|
244
|
+
return [3 /*break*/, 10];
|
|
245
|
+
case 8: return [4 /*yield*/, this.client.search(params_1)];
|
|
246
|
+
case 9:
|
|
248
247
|
// infinite with no backfills.
|
|
249
248
|
_a = _p.sent(), meta = _a[0], response = _a[1];
|
|
250
249
|
// append new results to previous results
|
|
251
250
|
response.results = __spreadArray(__spreadArray([], this.previousResults, true), (response.results || []), true);
|
|
252
|
-
_p.label =
|
|
253
|
-
case
|
|
254
|
-
case
|
|
255
|
-
case
|
|
251
|
+
_p.label = 10;
|
|
252
|
+
case 10: return [3 /*break*/, 13];
|
|
253
|
+
case 11: return [4 /*yield*/, this.client.search(params_1)];
|
|
254
|
+
case 12:
|
|
256
255
|
// standard request (not using infinite scroll)
|
|
257
256
|
_b = _p.sent(), meta = _b[0], response = _b[1];
|
|
258
|
-
_p.label =
|
|
259
|
-
case
|
|
257
|
+
_p.label = 13;
|
|
258
|
+
case 13:
|
|
260
259
|
// MockClient will overwrite the client search() method and use SearchData to return mock data which already contains meta data
|
|
261
260
|
if (!response.meta) {
|
|
262
261
|
response.meta = meta;
|
|
263
262
|
}
|
|
264
263
|
searchProfile.stop();
|
|
265
264
|
this.log.profile(searchProfile);
|
|
266
|
-
afterSearchProfile = this.profiler.create({ type: 'event', name: 'afterSearch', context:
|
|
267
|
-
_p.label =
|
|
268
|
-
case
|
|
269
|
-
_p.trys.push([
|
|
265
|
+
afterSearchProfile = this.profiler.create({ type: 'event', name: 'afterSearch', context: params_1 }).start();
|
|
266
|
+
_p.label = 14;
|
|
267
|
+
case 14:
|
|
268
|
+
_p.trys.push([14, 16, , 17]);
|
|
270
269
|
return [4 /*yield*/, this.eventManager.fire('afterSearch', {
|
|
271
270
|
controller: this,
|
|
272
|
-
request:
|
|
271
|
+
request: params_1,
|
|
273
272
|
response: response,
|
|
274
273
|
})];
|
|
275
|
-
case
|
|
274
|
+
case 15:
|
|
276
275
|
_p.sent();
|
|
277
|
-
return [3 /*break*/,
|
|
278
|
-
case
|
|
276
|
+
return [3 /*break*/, 17];
|
|
277
|
+
case 16:
|
|
279
278
|
err_2 = _p.sent();
|
|
280
279
|
if ((err_2 === null || err_2 === void 0 ? void 0 : err_2.message) == 'cancelled') {
|
|
281
280
|
this.log.warn("'afterSearch' middleware cancelled");
|
|
@@ -286,8 +285,8 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
286
285
|
this.log.error("error in 'afterSearch' middleware");
|
|
287
286
|
throw err_2;
|
|
288
287
|
}
|
|
289
|
-
return [3 /*break*/,
|
|
290
|
-
case
|
|
288
|
+
return [3 /*break*/, 17];
|
|
289
|
+
case 17:
|
|
291
290
|
afterSearchProfile.stop();
|
|
292
291
|
this.log.profile(afterSearchProfile);
|
|
293
292
|
// store previous results for infinite usage
|
|
@@ -296,19 +295,19 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
296
295
|
}
|
|
297
296
|
// update the store
|
|
298
297
|
this.store.update(response);
|
|
299
|
-
afterStoreProfile = this.profiler.create({ type: 'event', name: 'afterStore', context:
|
|
300
|
-
_p.label =
|
|
301
|
-
case
|
|
302
|
-
_p.trys.push([
|
|
298
|
+
afterStoreProfile = this.profiler.create({ type: 'event', name: 'afterStore', context: params_1 }).start();
|
|
299
|
+
_p.label = 18;
|
|
300
|
+
case 18:
|
|
301
|
+
_p.trys.push([18, 20, , 21]);
|
|
303
302
|
return [4 /*yield*/, this.eventManager.fire('afterStore', {
|
|
304
303
|
controller: this,
|
|
305
|
-
request:
|
|
304
|
+
request: params_1,
|
|
306
305
|
response: response,
|
|
307
306
|
})];
|
|
308
|
-
case
|
|
307
|
+
case 19:
|
|
309
308
|
_p.sent();
|
|
310
|
-
return [3 /*break*/,
|
|
311
|
-
case
|
|
309
|
+
return [3 /*break*/, 21];
|
|
310
|
+
case 20:
|
|
312
311
|
err_3 = _p.sent();
|
|
313
312
|
if ((err_3 === null || err_3 === void 0 ? void 0 : err_3.message) == 'cancelled') {
|
|
314
313
|
this.log.warn("'afterStore' middleware cancelled");
|
|
@@ -319,12 +318,12 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
319
318
|
this.log.error("error in 'afterStore' middleware");
|
|
320
319
|
throw err_3;
|
|
321
320
|
}
|
|
322
|
-
return [3 /*break*/,
|
|
323
|
-
case
|
|
321
|
+
return [3 /*break*/, 21];
|
|
322
|
+
case 21:
|
|
324
323
|
afterStoreProfile.stop();
|
|
325
324
|
this.log.profile(afterStoreProfile);
|
|
326
325
|
return [3 /*break*/, 24];
|
|
327
|
-
case
|
|
326
|
+
case 22:
|
|
328
327
|
err_4 = _p.sent();
|
|
329
328
|
if (err_4) {
|
|
330
329
|
if (err_4.err && err_4.fetchDetails) {
|
|
@@ -364,9 +363,11 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
364
363
|
this.log.error(err_4);
|
|
365
364
|
this.handleError(err_4);
|
|
366
365
|
}
|
|
367
|
-
this.store.loading = false;
|
|
368
366
|
}
|
|
369
367
|
return [3 /*break*/, 24];
|
|
368
|
+
case 23:
|
|
369
|
+
this.store.loading = false;
|
|
370
|
+
return [7 /*endfinally*/];
|
|
370
371
|
case 24: return [2 /*return*/];
|
|
371
372
|
}
|
|
372
373
|
});
|
|
@@ -384,19 +385,6 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
384
385
|
});
|
|
385
386
|
// set last params to undefined for compare in search
|
|
386
387
|
_this.storage.set('lastStringyParams', undefined);
|
|
387
|
-
// add 'beforeSearch' middleware
|
|
388
|
-
_this.eventManager.on('beforeSearch', function (search, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
389
|
-
return __generator(this, function (_a) {
|
|
390
|
-
switch (_a.label) {
|
|
391
|
-
case 0:
|
|
392
|
-
search.controller.store.loading = true;
|
|
393
|
-
return [4 /*yield*/, next()];
|
|
394
|
-
case 1:
|
|
395
|
-
_a.sent();
|
|
396
|
-
return [2 /*return*/];
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
}); });
|
|
400
388
|
// add 'afterSearch' middleware
|
|
401
389
|
_this.eventManager.on('afterSearch', function (search, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
402
390
|
var config, redirectURL, searchStore, nonBackgroundFilters;
|
|
@@ -447,7 +435,6 @@ var SearchController = /** @class */ (function (_super) {
|
|
|
447
435
|
return [4 /*yield*/, this.eventManager.fire('restorePosition', { controller: this, element: elementPosition })];
|
|
448
436
|
case 2:
|
|
449
437
|
_a.sent();
|
|
450
|
-
search.controller.store.loading = false;
|
|
451
438
|
return [2 /*return*/];
|
|
452
439
|
}
|
|
453
440
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/Autocomplete/AutocompleteController.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAa,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,4BAA4B,
|
|
1
|
+
{"version":3,"file":"AutocompleteController.d.ts","sourceRoot":"","sources":["../../../src/Autocom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,CAAC,KAAG,QAAQ,IAAI,CAAC;mCAgDhD,MAAM,WAAW,CAAC,gBAAgB,CAAC,KAAG,IAAI;uBAqBtD,KAAK;;;;uBAyDL,UAAU,KAAG,IAAI;;MAS5B;IAEF,MAAM,IAAI,IAAI;IAgBR,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAgF3B,cAAc,QAAa,QAAQ,IAAI,CAAC,CAwBtC;IAEF,MAAM,QAAa,QAAQ,IAAI,CAAC,CA0I9B;CACF"}
|
|
@@ -27,6 +27,10 @@ const defaultConfig = {
|
|
|
27
27
|
merchandising: true,
|
|
28
28
|
singleResult: false,
|
|
29
29
|
},
|
|
30
|
+
bind: {
|
|
31
|
+
input: true,
|
|
32
|
+
submit: true,
|
|
33
|
+
},
|
|
30
34
|
},
|
|
31
35
|
};
|
|
32
36
|
export class AutocompleteController extends AbstractController {
|
|
@@ -176,6 +180,8 @@ export class AutocompleteController extends AbstractController {
|
|
|
176
180
|
return;
|
|
177
181
|
}
|
|
178
182
|
this.store.state.input = value;
|
|
183
|
+
// remove merch redirect to prevent race condition
|
|
184
|
+
this.store.merchandising.redirect = '';
|
|
179
185
|
if (this.config?.settings?.syncInputs) {
|
|
180
186
|
const inputs = document.querySelectorAll(this.config.selector);
|
|
181
187
|
inputs.forEach((input) => {
|
|
@@ -247,16 +253,20 @@ export class AutocompleteController extends AbstractController {
|
|
|
247
253
|
this.store.updateTrendingTerms(terms);
|
|
248
254
|
};
|
|
249
255
|
this.search = async () => {
|
|
250
|
-
// if urlManager has no query, there will be no need to get params and no query
|
|
251
|
-
if (!this.urlManager.state.query) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
const params = this.params;
|
|
255
|
-
// if params have no query do not search
|
|
256
|
-
if (!params?.search?.query?.string) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
256
|
try {
|
|
257
|
+
if (!this.initialized) {
|
|
258
|
+
await this.init();
|
|
259
|
+
}
|
|
260
|
+
// if urlManager has no query, there will be no need to get params and no query
|
|
261
|
+
if (!this.urlManager.state.query) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const params = this.params;
|
|
265
|
+
// if params have no query do not search
|
|
266
|
+
if (!params?.search?.query?.string) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
this.store.loading = true;
|
|
260
270
|
try {
|
|
261
271
|
await this.eventManager.fire('beforeSearch', {
|
|
262
272
|
controller: this,
|
|
@@ -366,9 +376,11 @@ export class AutocompleteController extends AbstractController {
|
|
|
366
376
|
this.log.error(err);
|
|
367
377
|
this.handleError(err);
|
|
368
378
|
}
|
|
369
|
-
this.store.loading = false;
|
|
370
379
|
}
|
|
371
380
|
}
|
|
381
|
+
finally {
|
|
382
|
+
this.store.loading = false;
|
|
383
|
+
}
|
|
372
384
|
};
|
|
373
385
|
// deep merge config with defaults
|
|
374
386
|
this.config = deepmerge(defaultConfig, this.config);
|
|
@@ -385,25 +397,14 @@ export class AutocompleteController extends AbstractController {
|
|
|
385
397
|
type: 'session',
|
|
386
398
|
key: `ss-controller-${this.config.id}`,
|
|
387
399
|
});
|
|
388
|
-
// add 'beforeSearch' middleware
|
|
389
|
-
this.eventManager.on('beforeSearch', async (ac, next) => {
|
|
390
|
-
ac.controller.store.loading = true;
|
|
391
|
-
await next();
|
|
392
|
-
});
|
|
393
400
|
// add 'afterSearch' middleware
|
|
394
401
|
this.eventManager.on('afterSearch', async (ac, next) => {
|
|
395
402
|
await next();
|
|
396
403
|
// cancel search if no input or query doesn't match current urlState
|
|
397
404
|
if (ac.response.autocomplete.query != ac.controller.urlManager.state.query) {
|
|
398
|
-
ac.controller.store.loading = false;
|
|
399
405
|
return false;
|
|
400
406
|
}
|
|
401
407
|
});
|
|
402
|
-
// add 'afterStore' middleware
|
|
403
|
-
this.eventManager.on('afterStore', async (ac, next) => {
|
|
404
|
-
await next();
|
|
405
|
-
ac.controller.store.loading = false;
|
|
406
|
-
});
|
|
407
408
|
this.eventManager.on('beforeSubmit', async (ac, next) => {
|
|
408
409
|
await next();
|
|
409
410
|
const redirectURL = ac.controller.store.merchandising?.redirect;
|
|
@@ -521,7 +522,7 @@ export class AutocompleteController extends AbstractController {
|
|
|
521
522
|
input.setAttribute('autocorrect', 'off');
|
|
522
523
|
input.setAttribute('autocapitalize', 'none');
|
|
523
524
|
input.setAttribute(INPUT_ATTRIBUTE, '');
|
|
524
|
-
input.addEventListener('input', this.handlers.input.input);
|
|
525
|
+
this.config.settings?.bind?.input && input.addEventListener('input', this.handlers.input.input);
|
|
525
526
|
if (this.config?.settings?.initializeFromUrl && !input.value && this.store.state.input) {
|
|
526
527
|
input.value = this.store.state.input;
|
|
527
528
|
}
|
|
@@ -530,11 +531,11 @@ export class AutocompleteController extends AbstractController {
|
|
|
530
531
|
const form = input.form;
|
|
531
532
|
let formActionUrl;
|
|
532
533
|
if (this.config.action) {
|
|
533
|
-
input.addEventListener('keydown', this.handlers.input.enterKey);
|
|
534
|
+
this.config.settings?.bind?.submit && input.addEventListener('keydown', this.handlers.input.enterKey);
|
|
534
535
|
formActionUrl = this.config.action;
|
|
535
536
|
}
|
|
536
537
|
else if (form) {
|
|
537
|
-
form.addEventListener('submit', this.handlers.input.formSubmit);
|
|
538
|
+
this.config.settings?.bind?.submit && form.addEventListener('submit', this.handlers.input.formSubmit);
|
|
538
539
|
formActionUrl = form.action || '';
|
|
539
540
|
// serializeForm will include additional form element in our urlManager as globals
|
|
540
541
|
if (this.config.settings?.serializeForm) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FinderController.d.ts","sourceRoot":"","sources":["../../../src/Finder/FinderController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,KAAK,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"FinderController.d.ts","sourceRoot":"","sources":["../../../src/Finder/FinderController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,KAAK,EAAE,sBAAsB,EAAkB,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAiB7G,qBAAa,gBAAiB,SAAQ,kBAAkB;IAChD,IAAI,kBAA0B;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,sBAAsB,CAAC;gBAGtC,MAAM,EAAE,sBAAsB,EAC9B,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,kBAAkB,EAC1F,OAAO,CAAC,EAAE,gBAAgB;IA+B3B,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA+BhC;IAED,IAAI,QAAa,QAAQ,IAAI,CAAC,CAkB5B;IAEF,KAAK,QAAO,IAAI,CAId;IAEF,MAAM,QAAa,QAAQ,IAAI,CAAC,CAoI9B;CACF"}
|