@searchspring/snap-preact 0.26.1 → 0.27.2

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 (35) hide show
  1. package/dist/cjs/Instantiators/RecommendationInstantiator.d.ts +20 -21
  2. package/dist/cjs/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
  3. package/dist/cjs/Instantiators/RecommendationInstantiator.js +47 -41
  4. package/dist/cjs/Snap.d.ts +17 -15
  5. package/dist/cjs/Snap.d.ts.map +1 -1
  6. package/dist/cjs/Snap.js +301 -232
  7. package/dist/cjs/components/BranchOverride.d.ts +1 -6
  8. package/dist/cjs/components/BranchOverride.d.ts.map +1 -1
  9. package/dist/cjs/components/BranchOverride.js +2 -234
  10. package/dist/cjs/create/index.d.ts +1 -1
  11. package/dist/cjs/create/index.d.ts.map +1 -1
  12. package/dist/cjs/create/index.js +2 -2
  13. package/dist/cjs/getBundleDetails/getBundleDetails.d.ts +7 -0
  14. package/dist/cjs/getBundleDetails/getBundleDetails.d.ts.map +1 -0
  15. package/dist/cjs/getBundleDetails/getBundleDetails.js +64 -0
  16. package/dist/cjs/types.d.ts +1 -0
  17. package/dist/cjs/types.d.ts.map +1 -1
  18. package/dist/esm/Instantiators/RecommendationInstantiator.d.ts +20 -21
  19. package/dist/esm/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
  20. package/dist/esm/Instantiators/RecommendationInstantiator.js +41 -38
  21. package/dist/esm/Snap.d.ts +17 -15
  22. package/dist/esm/Snap.d.ts.map +1 -1
  23. package/dist/esm/Snap.js +144 -107
  24. package/dist/esm/components/BranchOverride.d.ts +1 -6
  25. package/dist/esm/components/BranchOverride.d.ts.map +1 -1
  26. package/dist/esm/components/BranchOverride.js +1 -172
  27. package/dist/esm/create/index.d.ts +1 -1
  28. package/dist/esm/create/index.d.ts.map +1 -1
  29. package/dist/esm/create/index.js +1 -1
  30. package/dist/esm/getBundleDetails/getBundleDetails.d.ts +7 -0
  31. package/dist/esm/getBundleDetails/getBundleDetails.d.ts.map +1 -0
  32. package/dist/esm/getBundleDetails/getBundleDetails.js +22 -0
  33. package/dist/esm/types.d.ts +1 -0
  34. package/dist/esm/types.d.ts.map +1 -1
  35. package/package.json +13 -12
package/dist/cjs/Snap.js CHANGED
@@ -73,7 +73,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
73
73
  return (mod && mod.__esModule) ? mod : { "default": mod };
74
74
  };
75
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
- exports.Snap = void 0;
76
+ exports.Snap = exports.SS_DEV_COOKIE = exports.BRANCH_COOKIE = void 0;
77
77
  var jsx_runtime_1 = require("preact/jsx-runtime");
78
78
  var deepmerge_1 = __importDefault(require("deepmerge"));
79
79
  var is_plain_object_1 = require("is-plain-object");
@@ -83,18 +83,13 @@ var snap_logger_1 = require("@searchspring/snap-logger");
83
83
  var snap_tracker_1 = require("@searchspring/snap-tracker");
84
84
  var snap_toolbox_1 = require("@searchspring/snap-toolbox");
85
85
  var snap_toolbox_2 = require("@searchspring/snap-toolbox");
86
+ var snap_controller_1 = require("@searchspring/snap-controller");
86
87
  var createSearchController_1 = __importDefault(require("./create/createSearchController"));
87
- var BRANCH_COOKIE = 'ssBranch';
88
- var SS_DEV_COOKIE = 'ssDev';
89
- var DynamicImportNames;
90
- (function (DynamicImportNames) {
91
- DynamicImportNames["SEARCH"] = "searchController";
92
- DynamicImportNames["AUTOCOMPLETE"] = "autocompleteController";
93
- DynamicImportNames["FINDER"] = "finderController";
94
- DynamicImportNames["RECOMMENDATION"] = "recommendationController";
95
- })(DynamicImportNames || (DynamicImportNames = {}));
88
+ exports.BRANCH_COOKIE = 'ssBranch';
89
+ exports.SS_DEV_COOKIE = 'ssDev';
90
+ var COMPONENT_ERROR = "Uncaught Error - Invalid value passed as the component.\nThis usually happens when you pass a JSX Element, and not a function that returns the component, in the snap config. \n\t\t\n\t\tinstead of - \n\n\ttargeters: [\n\t\t{\n\t\t\tselector: '#searchspring-content',\n\t\t\thideTarget: true,\n\t\t\tcomponent: <Content/>,\n\t\t},\n\t]\n\n\t\tor - \n\n\ttargeters: [\n\t\t{\n\t\t\tselector: '#searchspring-content',\n\t\t\thideTarget: true,\n\t\t\tcomponent: Content,\n\t\t},\n\t]\n\n\t\tplease try - \n\n\ttargeters: [\n\t\t{\n\t\t\tselector: '#searchspring-content',\n\t\t\thideTarget: true,\n\t\t\tcomponent: () => Content\n\t\t},\n\t]\n\nThe error above happened in the following targeter in the Snap Config";
96
91
  var Snap = /** @class */ (function () {
97
- function Snap(config) {
92
+ function Snap(config, services) {
98
93
  var _this = this;
99
94
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
100
95
  this.getInstantiator = function (id) {
@@ -112,44 +107,54 @@ var Snap = /** @class */ (function () {
112
107
  controllerIds.forEach(function (id) { return getControllerPromises.push(_this.getController(id)); });
113
108
  return Promise.all(getControllerPromises);
114
109
  };
115
- this.createController = function (type, config, services, urlConfig, resolve, context) {
116
- var importPromise;
117
- switch (type) {
118
- case DynamicImportNames.SEARCH:
119
- importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createSearchController')); });
120
- break;
121
- case DynamicImportNames.AUTOCOMPLETE:
122
- importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createAutocompleteController')); });
123
- break;
124
- case DynamicImportNames.FINDER:
125
- importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createFinderController')); });
126
- break;
127
- case DynamicImportNames.RECOMMENDATION:
128
- importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createRecommendationController')); });
129
- break;
130
- }
131
- return importPromise.then(function (_) {
132
- if (!_this.controllers[config.id]) {
133
- _this.controllers[config.id] = _.default({
134
- url: (0, deepmerge_1.default)(_this.config.url || {}, urlConfig || {}),
135
- controller: config,
136
- context: (0, deepmerge_1.default)(_this.context || {}, context || {}),
137
- }, {
138
- client: (services === null || services === void 0 ? void 0 : services.client) || _this.client,
139
- store: services === null || services === void 0 ? void 0 : services.store,
140
- urlManager: services === null || services === void 0 ? void 0 : services.urlManager,
141
- eventManager: services === null || services === void 0 ? void 0 : services.eventManager,
142
- profiler: services === null || services === void 0 ? void 0 : services.profiler,
143
- logger: services === null || services === void 0 ? void 0 : services.logger,
144
- tracker: (services === null || services === void 0 ? void 0 : services.tracker) || _this.tracker,
145
- });
146
- resolve(_this.controllers[config.id]);
110
+ this.createController = function (type, config, services, urlConfig, context, callback) { return __awaiter(_this, void 0, void 0, function () {
111
+ var importPromise, creationFunc;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ switch (type) {
116
+ case snap_controller_1.ControllerTypes.search:
117
+ importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createSearchController')); });
118
+ break;
119
+ case snap_controller_1.ControllerTypes.autocomplete:
120
+ importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createAutocompleteController')); });
121
+ break;
122
+ case snap_controller_1.ControllerTypes.finder:
123
+ importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createFinderController')); });
124
+ break;
125
+ case snap_controller_1.ControllerTypes.recommendation:
126
+ importPromise = Promise.resolve().then(function () { return __importStar(require('./create/createRecommendationController')); });
127
+ break;
128
+ }
129
+ return [4 /*yield*/, importPromise];
130
+ case 1:
131
+ creationFunc = (_a.sent()).default;
132
+ if (!this.controllers[config.id]) {
133
+ this.controllers[config.id] = creationFunc({
134
+ url: (0, deepmerge_1.default)(this.config.url || {}, urlConfig || {}),
135
+ controller: config,
136
+ context: (0, deepmerge_1.default)(this.context || {}, context || {}),
137
+ }, {
138
+ client: (services === null || services === void 0 ? void 0 : services.client) || this.client,
139
+ store: services === null || services === void 0 ? void 0 : services.store,
140
+ urlManager: services === null || services === void 0 ? void 0 : services.urlManager,
141
+ eventManager: services === null || services === void 0 ? void 0 : services.eventManager,
142
+ profiler: services === null || services === void 0 ? void 0 : services.profiler,
143
+ logger: services === null || services === void 0 ? void 0 : services.logger,
144
+ tracker: (services === null || services === void 0 ? void 0 : services.tracker) || this.tracker,
145
+ });
146
+ }
147
+ if (!callback) return [3 /*break*/, 3];
148
+ return [4 /*yield*/, callback(this.controllers[config.id])];
149
+ case 2:
150
+ _a.sent();
151
+ _a.label = 3;
152
+ case 3: return [2 /*return*/, this.controllers[config.id]];
147
153
  }
148
- return _this.controllers[config.id];
149
154
  });
150
- };
155
+ }); };
151
156
  this.config = config;
152
- this.logger = new snap_logger_1.Logger('Snap Preact ');
157
+ this.logger = (services === null || services === void 0 ? void 0 : services.logger) || new snap_logger_1.Logger('Snap Preact ');
153
158
  var globalContext = {};
154
159
  try {
155
160
  // get global context
@@ -162,12 +167,14 @@ var Snap = /** @class */ (function () {
162
167
  this.config = (0, deepmerge_1.default)(this.config || {}, globalContext.config || {}, {
163
168
  isMergeableObject: is_plain_object_1.isPlainObject,
164
169
  });
165
- this.context = (0, deepmerge_1.default)(globalContext || {}, this.config.context || {});
166
- if (!((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.client) === null || _b === void 0 ? void 0 : _b.globals) === null || _c === void 0 ? void 0 : _c.siteId)) {
170
+ this.context = (0, deepmerge_1.default)(this.config.context || {}, globalContext || {}, {
171
+ isMergeableObject: is_plain_object_1.isPlainObject,
172
+ });
173
+ if ((!(services === null || services === void 0 ? void 0 : services.client) || !(services === null || services === void 0 ? void 0 : services.tracker)) && !((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.client) === null || _b === void 0 ? void 0 : _b.globals) === null || _c === void 0 ? void 0 : _c.siteId)) {
167
174
  throw new Error("Snap: config provided must contain a valid config.client.globals.siteId value");
168
175
  }
169
- this.client = new snap_client_1.Client(this.config.client.globals, this.config.client.config);
170
- this.tracker = new snap_tracker_1.Tracker(this.config.client.globals);
176
+ this.client = (services === null || services === void 0 ? void 0 : services.client) || new snap_client_1.Client(this.config.client.globals, this.config.client.config);
177
+ this.tracker = (services === null || services === void 0 ? void 0 : services.tracker) || new snap_tracker_1.Tracker(this.config.client.globals);
171
178
  this._controllerPromises = {};
172
179
  this._instantiatorPromises = {};
173
180
  this.controllers = {};
@@ -181,12 +188,12 @@ var Snap = /** @class */ (function () {
181
188
  });
182
189
  try {
183
190
  var urlParams = (0, snap_toolbox_1.url)(window.location.href);
184
- var branchParam_1 = ((_e = (_d = urlParams.params) === null || _d === void 0 ? void 0 : _d.query) === null || _e === void 0 ? void 0 : _e.branch) || snap_toolbox_1.cookies.get(BRANCH_COOKIE);
185
- if (branchParam_1 && !document.querySelector("script[".concat(BRANCH_COOKIE, "]"))) {
191
+ var branchParam_1 = ((_e = (_d = urlParams.params) === null || _d === void 0 ? void 0 : _d.query) === null || _e === void 0 ? void 0 : _e.branch) || snap_toolbox_1.cookies.get(exports.BRANCH_COOKIE);
192
+ if (branchParam_1 && !document.querySelector("script[".concat(exports.BRANCH_COOKIE, "]"))) {
186
193
  // set a cookie or localstorage with branch
187
194
  if (snap_toolbox_1.featureFlags.cookies) {
188
- snap_toolbox_1.cookies.set(BRANCH_COOKIE, branchParam_1, 'Lax', 3600000); // 1 hour
189
- snap_toolbox_1.cookies.set(SS_DEV_COOKIE, '1', 'Lax', 0);
195
+ snap_toolbox_1.cookies.set(exports.BRANCH_COOKIE, branchParam_1, 'Lax', 3600000); // 1 hour
196
+ snap_toolbox_1.cookies.set(exports.SS_DEV_COOKIE, '1', 'Lax', 0);
190
197
  }
191
198
  else {
192
199
  this.logger.warn('Cookies are not supported/enabled by this browser, branch overrides will not persist!');
@@ -206,7 +213,7 @@ var Snap = /** @class */ (function () {
206
213
  var branchScript = document.createElement('script');
207
214
  var src_1 = "".concat(path).concat(branchParam_1, "/bundle.js");
208
215
  branchScript.src = src_1;
209
- branchScript.setAttribute(BRANCH_COOKIE, '');
216
+ branchScript.setAttribute(exports.BRANCH_COOKIE, branchParam_1);
210
217
  document.head.appendChild(branchScript);
211
218
  new snap_toolbox_1.DomTargeter([
212
219
  {
@@ -215,19 +222,37 @@ var Snap = /** @class */ (function () {
215
222
  action: 'append',
216
223
  element: function () {
217
224
  var branchContainer = document.createElement('div');
218
- branchContainer.className = 'ss__branch--target';
225
+ branchContainer.id = 'searchspring-branch-override';
219
226
  return branchContainer;
220
227
  },
221
228
  },
222
229
  },
223
230
  ], function (target, elem) { return __awaiter(_this, void 0, void 0, function () {
224
- var BranchOverride;
231
+ var bundleDetails, error, getBundleDetails, err_1, BranchOverride;
225
232
  return __generator(this, function (_a) {
226
233
  switch (_a.label) {
227
- case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('./components/BranchOverride')); })];
234
+ case 0:
235
+ _a.trys.push([0, 3, , 4]);
236
+ return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('./getBundleDetails/getBundleDetails')); })];
228
237
  case 1:
238
+ getBundleDetails = (_a.sent()).getBundleDetails;
239
+ return [4 /*yield*/, getBundleDetails(src_1)];
240
+ case 2:
241
+ bundleDetails = _a.sent();
242
+ return [3 /*break*/, 4];
243
+ case 3:
244
+ err_1 = _a.sent();
245
+ error = err_1;
246
+ return [3 /*break*/, 4];
247
+ case 4: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('./components/BranchOverride')); })];
248
+ case 5:
229
249
  BranchOverride = (_a.sent()).BranchOverride;
230
- (0, preact_1.render)((0, jsx_runtime_1.jsx)(BranchOverride, { branch: branchParam_1, cookieName: BRANCH_COOKIE, bundleUrl: src_1 }), elem);
250
+ (0, preact_1.render)((0, jsx_runtime_1.jsx)(BranchOverride, { name: branchParam_1, details: bundleDetails, error: error, onRemoveClick: function () {
251
+ snap_toolbox_1.cookies.unset(exports.BRANCH_COOKIE);
252
+ var urlState = (0, snap_toolbox_1.url)(window.location.href);
253
+ delete urlState.params.query['branch'];
254
+ window.location.href = urlState.url();
255
+ } }), elem);
231
256
  return [2 /*return*/];
232
257
  }
233
258
  });
@@ -285,66 +310,69 @@ var Snap = /** @class */ (function () {
285
310
  }
286
311
  };
287
312
  var targetFunction_1 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
288
- var onTarget, Component_1, err_1;
313
+ var onTarget, _a, Component_1, err_2;
289
314
  var _this = this;
290
- return __generator(this, function (_a) {
291
- switch (_a.label) {
315
+ return __generator(this, function (_b) {
316
+ switch (_b.label) {
292
317
  case 0:
293
318
  runSearch_1();
294
319
  onTarget = target.onTarget;
295
- onTarget && onTarget(target, elem, originalElem);
296
- _a.label = 1;
320
+ _a = onTarget;
321
+ if (!_a) return [3 /*break*/, 2];
322
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
297
323
  case 1:
298
- _a.trys.push([1, 3, , 4]);
299
- return [4 /*yield*/, target.component()];
324
+ _a = (_b.sent());
325
+ _b.label = 2;
300
326
  case 2:
301
- Component_1 = _a.sent();
327
+ _a;
328
+ _b.label = 3;
329
+ case 3:
330
+ _b.trys.push([3, 5, , 6]);
331
+ return [4 /*yield*/, target.component()];
332
+ case 4:
333
+ Component_1 = _b.sent();
302
334
  setTimeout(function () {
303
335
  (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component_1, __assign({ controller: _this.controllers[controller.config.id] }, target.props)), elem);
304
336
  });
305
- return [3 /*break*/, 4];
306
- case 3:
307
- err_1 = _a.sent();
308
- this.logger.error("Uncaught Error - Invalid value passed as the component.\n\tThis usually happens when you pass a JSX Element, and not a function that returns the component, in the snap config. \n\t\t\t\n\t\t\t\tinstead of - \n\n\t\t\ttargeters: [\n\t\t\t\t{\n\t\t\t\t\tselector: '#searchspring-content',\n\t\t\t\t\thideTarget: true,\n\t\t\t\t\tcomponent: <Content/>,\n\t\t\t\t},\n\t\t\t]\n\n\t\t\t\tor - \n\n\t\t\ttargeters: [\n\t\t\t\t{\n\t\t\t\t\tselector: '#searchspring-content',\n\t\t\t\t\thideTarget: true,\n\t\t\t\t\tcomponent: Content,\n\t\t\t\t},\n\t\t\t]\n\n\t\t\t\tplease try - \n\n\t\t\ttargeters: [\n\t\t\t\t{\n\t\t\t\t\tselector: '#searchspring-content',\n\t\t\t\t\thideTarget: true,\n\t\t\t\t\tcomponent: () => Content\n\t\t\t\t},\n\t\t\t]\n\n\t\t\t\nThe error above happened in the following targeter in the Snap Config", target);
309
- return [3 /*break*/, 4];
310
- case 4: return [2 /*return*/];
337
+ return [3 /*break*/, 6];
338
+ case 5:
339
+ err_2 = _b.sent();
340
+ this.logger.error(COMPONENT_ERROR, target);
341
+ return [3 /*break*/, 6];
342
+ case 6: return [2 /*return*/];
311
343
  }
312
344
  });
313
345
  }); };
314
- (_h = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _h === void 0 ? void 0 : _h.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
315
- var _this = this;
316
- return __generator(this, function (_a) {
317
- if (!target.selector) {
318
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
319
- }
320
- if (!target.component) {
321
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
322
- }
323
- if (target.prefetch) {
324
- runSearch_1();
325
- }
326
- cntrlr_1.createTargeter(__assign({ controller: cntrlr_1 }, target), function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
327
- var Skeleton_1;
328
- return __generator(this, function (_a) {
329
- switch (_a.label) {
330
- case 0:
331
- if (!target.skeleton) return [3 /*break*/, 2];
332
- return [4 /*yield*/, target.skeleton()];
333
- case 1:
334
- Skeleton_1 = _a.sent();
335
- setTimeout(function () {
336
- (0, preact_1.render)((0, jsx_runtime_1.jsx)(Skeleton_1, {}), elem);
337
- });
338
- _a.label = 2;
339
- case 2:
340
- targetFunction_1(target, elem, originalElem);
341
- return [2 /*return*/];
342
- }
343
- });
344
- }); });
345
- return [2 /*return*/];
346
- });
347
- }); });
346
+ (_h = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _h === void 0 ? void 0 : _h.forEach(function (target, target_index) {
347
+ if (!target.selector) {
348
+ throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
349
+ }
350
+ if (!target.component) {
351
+ throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
352
+ }
353
+ if (target.prefetch) {
354
+ runSearch_1();
355
+ }
356
+ cntrlr_1.createTargeter(__assign({ controller: cntrlr_1 }, target), function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
357
+ var Skeleton_1;
358
+ return __generator(this, function (_a) {
359
+ switch (_a.label) {
360
+ case 0:
361
+ if (!target.skeleton) return [3 /*break*/, 2];
362
+ return [4 /*yield*/, target.skeleton()];
363
+ case 1:
364
+ Skeleton_1 = _a.sent();
365
+ setTimeout(function () {
366
+ (0, preact_1.render)((0, jsx_runtime_1.jsx)(Skeleton_1, {}), elem);
367
+ });
368
+ _a.label = 2;
369
+ case 2:
370
+ targetFunction_1(target, elem, originalElem);
371
+ return [2 /*return*/];
372
+ }
373
+ });
374
+ }); });
375
+ });
348
376
  }
349
377
  catch (err) {
350
378
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -367,65 +395,79 @@ var Snap = /** @class */ (function () {
367
395
  }
368
396
  };
369
397
  var targetFunction_2 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
370
- var onTarget, Component;
398
+ var onTarget, _a, Component_2, err_3;
371
399
  var _this = this;
372
- return __generator(this, function (_a) {
373
- switch (_a.label) {
400
+ return __generator(this, function (_b) {
401
+ switch (_b.label) {
374
402
  case 0:
375
403
  onTarget = target.onTarget;
376
- onTarget && onTarget(target, elem, originalElem);
377
- return [4 /*yield*/, target.component()];
404
+ _a = onTarget;
405
+ if (!_a) return [3 /*break*/, 2];
406
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
378
407
  case 1:
379
- Component = (_a.sent());
408
+ _a = (_b.sent());
409
+ _b.label = 2;
410
+ case 2:
411
+ _a;
412
+ _b.label = 3;
413
+ case 3:
414
+ _b.trys.push([3, 5, , 6]);
415
+ return [4 /*yield*/, target.component()];
416
+ case 4:
417
+ Component_2 = (_b.sent());
380
418
  setTimeout(function () {
381
- (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component, __assign({ controller: _this.controllers[controller.config.id], input: originalElem }, target.props)), elem);
419
+ (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component_2, __assign({ controller: _this.controllers[controller.config.id], input: originalElem }, target.props)), elem);
382
420
  });
383
- return [2 /*return*/];
421
+ return [3 /*break*/, 6];
422
+ case 5:
423
+ err_3 = _b.sent();
424
+ this.logger.error(COMPONENT_ERROR, target);
425
+ return [3 /*break*/, 6];
426
+ case 6: return [2 /*return*/];
384
427
  }
385
428
  });
386
429
  }); };
387
430
  if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
388
- _this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context);
389
- }
390
- (_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
391
- var targeter;
392
- var _this = this;
393
- return __generator(this, function (_a) {
394
- if (!target.selector) {
395
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
396
- }
397
- if (!target.component) {
398
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
399
- }
400
- targeter = new snap_toolbox_1.DomTargeter([
401
- __assign({ inject: {
402
- action: 'after',
403
- element: function () {
404
- var acContainer = document.createElement('div');
405
- acContainer.className = 'ss__autocomplete--target';
406
- acContainer.addEventListener('click', function (e) {
407
- e.stopPropagation();
408
- });
409
- return acContainer;
410
- },
411
- } }, target),
412
- ], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
413
- var cntrlr;
414
- return __generator(this, function (_a) {
415
- switch (_a.label) {
416
- case 0: return [4 /*yield*/, this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context)];
417
- case 1:
418
- cntrlr = _a.sent();
419
- runBind_1();
420
- targetFunction_2(__assign({ controller: cntrlr }, target), elem, originalElem);
421
- cntrlr.addTargeter(targeter);
422
- return [2 /*return*/];
423
- }
424
- });
425
- }); });
426
- return [2 /*return*/];
431
+ _this.createController(snap_controller_1.ControllerTypes.autocomplete, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
432
+ resolve(cntrlr);
427
433
  });
428
- }); });
434
+ }
435
+ (_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) {
436
+ if (!target.selector) {
437
+ throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
438
+ }
439
+ if (!target.component) {
440
+ throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
441
+ }
442
+ var targeter = new snap_toolbox_1.DomTargeter([
443
+ __assign({ inject: {
444
+ action: 'after',
445
+ element: function () {
446
+ var acContainer = document.createElement('div');
447
+ acContainer.className = 'ss__autocomplete--target';
448
+ acContainer.addEventListener('click', function (e) {
449
+ e.stopPropagation();
450
+ });
451
+ return acContainer;
452
+ },
453
+ } }, target),
454
+ ], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
455
+ var cntrlr;
456
+ return __generator(this, function (_a) {
457
+ switch (_a.label) {
458
+ case 0: return [4 /*yield*/, this.createController(snap_controller_1.ControllerTypes.autocomplete, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
459
+ resolve(cntrlr);
460
+ })];
461
+ case 1:
462
+ cntrlr = _a.sent();
463
+ runBind_1();
464
+ targetFunction_2(__assign({ controller: cntrlr }, target), elem, originalElem);
465
+ cntrlr.addTargeter(targeter);
466
+ return [2 /*return*/];
467
+ }
468
+ });
469
+ }); });
470
+ });
429
471
  }
430
472
  catch (err) {
431
473
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -447,53 +489,67 @@ var Snap = /** @class */ (function () {
447
489
  }
448
490
  };
449
491
  var targetFunction_3 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
450
- var onTarget, Component;
492
+ var onTarget, _a, Component_3, err_4;
451
493
  var _this = this;
452
- return __generator(this, function (_a) {
453
- switch (_a.label) {
494
+ return __generator(this, function (_b) {
495
+ switch (_b.label) {
454
496
  case 0:
455
497
  onTarget = target.onTarget;
456
- onTarget && onTarget(target, elem, originalElem);
457
- return [4 /*yield*/, target.component()];
498
+ _a = onTarget;
499
+ if (!_a) return [3 /*break*/, 2];
500
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
458
501
  case 1:
459
- Component = _a.sent();
502
+ _a = (_b.sent());
503
+ _b.label = 2;
504
+ case 2:
505
+ _a;
506
+ _b.label = 3;
507
+ case 3:
508
+ _b.trys.push([3, 5, , 6]);
509
+ return [4 /*yield*/, target.component()];
510
+ case 4:
511
+ Component_3 = _b.sent();
460
512
  setTimeout(function () {
461
- (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component, __assign({ controller: _this.controllers[controller.config.id] }, target.props)), elem);
513
+ (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component_3, __assign({ controller: _this.controllers[controller.config.id] }, target.props)), elem);
462
514
  });
463
- return [2 /*return*/];
515
+ return [3 /*break*/, 6];
516
+ case 5:
517
+ err_4 = _b.sent();
518
+ this.logger.error(COMPONENT_ERROR, target);
519
+ return [3 /*break*/, 6];
520
+ case 6: return [2 /*return*/];
464
521
  }
465
522
  });
466
523
  }); };
467
524
  if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
468
- _this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context);
469
- }
470
- (_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
471
- var targeter;
472
- var _this = this;
473
- return __generator(this, function (_a) {
474
- if (!target.selector) {
475
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
476
- }
477
- if (!target.component) {
478
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
479
- }
480
- targeter = new snap_toolbox_1.DomTargeter([__assign({}, target)], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
481
- var cntrlr;
482
- return __generator(this, function (_a) {
483
- switch (_a.label) {
484
- case 0: return [4 /*yield*/, this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context)];
485
- case 1:
486
- cntrlr = _a.sent();
487
- runSearch_2();
488
- targetFunction_3(__assign({ controller: cntrlr }, target), elem, originalElem);
489
- cntrlr.addTargeter(targeter);
490
- return [2 /*return*/];
491
- }
492
- });
493
- }); });
494
- return [2 /*return*/];
525
+ _this.createController(snap_controller_1.ControllerTypes.finder, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
526
+ resolve(cntrlr);
495
527
  });
496
- }); });
528
+ }
529
+ (_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) {
530
+ if (!target.selector) {
531
+ throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
532
+ }
533
+ if (!target.component) {
534
+ throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
535
+ }
536
+ var targeter = new snap_toolbox_1.DomTargeter([__assign({}, target)], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
537
+ var cntrlr;
538
+ return __generator(this, function (_a) {
539
+ switch (_a.label) {
540
+ case 0: return [4 /*yield*/, this.createController(snap_controller_1.ControllerTypes.finder, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
541
+ resolve(cntrlr);
542
+ })];
543
+ case 1:
544
+ cntrlr = _a.sent();
545
+ runSearch_2();
546
+ targetFunction_3(__assign({ controller: cntrlr }, target), elem, originalElem);
547
+ cntrlr.addTargeter(targeter);
548
+ return [2 /*return*/];
549
+ }
550
+ });
551
+ }); });
552
+ });
497
553
  }
498
554
  catch (err) {
499
555
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -515,53 +571,67 @@ var Snap = /** @class */ (function () {
515
571
  }
516
572
  };
517
573
  var targetFunction_4 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
518
- var onTarget, Component;
574
+ var onTarget, _a, Component_4, err_5;
519
575
  var _this = this;
520
- return __generator(this, function (_a) {
521
- switch (_a.label) {
576
+ return __generator(this, function (_b) {
577
+ switch (_b.label) {
522
578
  case 0:
523
579
  onTarget = target.onTarget;
524
- onTarget && onTarget(target, elem, originalElem);
525
- return [4 /*yield*/, target.component()];
580
+ _a = onTarget;
581
+ if (!_a) return [3 /*break*/, 2];
582
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
526
583
  case 1:
527
- Component = _a.sent();
584
+ _a = (_b.sent());
585
+ _b.label = 2;
586
+ case 2:
587
+ _a;
588
+ _b.label = 3;
589
+ case 3:
590
+ _b.trys.push([3, 5, , 6]);
591
+ return [4 /*yield*/, target.component()];
592
+ case 4:
593
+ Component_4 = _b.sent();
528
594
  setTimeout(function () {
529
- (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component, __assign({ controller: _this.controllers[controller.config.id] }, target.props)), elem);
595
+ (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component_4, __assign({ controller: _this.controllers[controller.config.id] }, target.props)), elem);
530
596
  });
531
- return [2 /*return*/];
597
+ return [3 /*break*/, 6];
598
+ case 5:
599
+ err_5 = _b.sent();
600
+ this.logger.error(COMPONENT_ERROR, target);
601
+ return [3 /*break*/, 6];
602
+ case 6: return [2 /*return*/];
532
603
  }
533
604
  });
534
605
  }); };
535
606
  if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
536
- _this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context);
537
- }
538
- (_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) { return __awaiter(_this, void 0, void 0, function () {
539
- var targeter;
540
- var _this = this;
541
- return __generator(this, function (_a) {
542
- if (!target.selector) {
543
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
544
- }
545
- if (!target.component) {
546
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
547
- }
548
- targeter = new snap_toolbox_1.DomTargeter([__assign({}, target)], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
549
- var cntrlr;
550
- return __generator(this, function (_a) {
551
- switch (_a.label) {
552
- case 0: return [4 /*yield*/, this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context)];
553
- case 1:
554
- cntrlr = _a.sent();
555
- runSearch_3();
556
- targetFunction_4(__assign({ controller: cntrlr }, target), elem, originalElem);
557
- cntrlr.addTargeter(targeter);
558
- return [2 /*return*/];
559
- }
560
- });
561
- }); });
562
- return [2 /*return*/];
607
+ _this.createController(snap_controller_1.ControllerTypes.recommendation, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
608
+ resolve(cntrlr);
563
609
  });
564
- }); });
610
+ }
611
+ (_a = controller === null || controller === void 0 ? void 0 : controller.targeters) === null || _a === void 0 ? void 0 : _a.forEach(function (target, target_index) {
612
+ if (!target.selector) {
613
+ throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
614
+ }
615
+ if (!target.component) {
616
+ throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
617
+ }
618
+ var targeter = new snap_toolbox_1.DomTargeter([__assign({}, target)], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
619
+ var cntrlr;
620
+ return __generator(this, function (_a) {
621
+ switch (_a.label) {
622
+ case 0: return [4 /*yield*/, this.createController(snap_controller_1.ControllerTypes.recommendation, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
623
+ resolve(cntrlr);
624
+ })];
625
+ case 1:
626
+ cntrlr = _a.sent();
627
+ runSearch_3();
628
+ targetFunction_4(__assign({ controller: cntrlr }, target), elem, originalElem);
629
+ cntrlr.addTargeter(targeter);
630
+ return [2 /*return*/];
631
+ }
632
+ });
633
+ }); });
634
+ });
565
635
  }
566
636
  catch (err) {
567
637
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -574,13 +644,12 @@ var Snap = /** @class */ (function () {
574
644
  });
575
645
  if ((_m = (_l = this.config) === null || _l === void 0 ? void 0 : _l.instantiators) === null || _m === void 0 ? void 0 : _m.recommendation) {
576
646
  try {
577
- this._instantiatorPromises.recommendations = Promise.resolve().then(function () { return __importStar(require('./Instantiators/RecommendationInstantiator')); }).then(function (_a) {
578
- var _b, _c, _d, _e, _f, _g;
647
+ this._instantiatorPromises.recommendation = Promise.resolve().then(function () { return __importStar(require('./Instantiators/RecommendationInstantiator')); }).then(function (_a) {
579
648
  var RecommendationInstantiator = _a.RecommendationInstantiator;
580
649
  return new RecommendationInstantiator(_this.config.instantiators.recommendation, {
581
- client: ((_c = (_b = _this.config.instantiators.recommendation) === null || _b === void 0 ? void 0 : _b.services) === null || _c === void 0 ? void 0 : _c.client) || _this.client,
582
- tracker: ((_e = (_d = _this.config.instantiators.recommendation) === null || _d === void 0 ? void 0 : _d.services) === null || _e === void 0 ? void 0 : _e.tracker) || _this.tracker,
583
- logger: ((_g = (_f = _this.config.instantiators.recommendation) === null || _f === void 0 ? void 0 : _f.services) === null || _g === void 0 ? void 0 : _g.logger) || _this.logger,
650
+ client: _this.client,
651
+ tracker: _this.tracker,
652
+ logger: _this.logger,
584
653
  }, _this.context);
585
654
  });
586
655
  }