@searchspring/snap-preact 0.25.1 → 0.27.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 (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 +75 -50
  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 +314 -236
  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 +63 -40
  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 +157 -111
  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,24 +188,33 @@ 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!');
193
200
  }
194
201
  this.logger.setMode(snap_logger_1.LogMode.DEVELOPMENT);
195
202
  this.logger.warn("...loading build... '".concat(branchParam_1, "'"));
203
+ // get the path and siteId from the current bundle script in case its not the same as the client config
204
+ var path = "https://snapui.searchspring.io/".concat(this.config.client.globals.siteId, "/");
205
+ var script = document.querySelector('script[src*="//snapui.searchspring.io"]');
206
+ if (script) {
207
+ var scriptRoot = script.getAttribute('src').match(/\/\/snapui.searchspring.io\/[a-zA-Z0-9]{6}\//);
208
+ if (scriptRoot) {
209
+ path = scriptRoot.toString();
210
+ }
211
+ }
196
212
  // append script with new branch in path
197
- var script = document.createElement('script');
198
- var src_1 = "https://snapui.searchspring.io/".concat(this.config.client.globals.siteId, "/").concat(branchParam_1, "/bundle.js");
199
- script.src = src_1;
200
- script.setAttribute(BRANCH_COOKIE, '');
201
- document.head.appendChild(script);
213
+ var branchScript = document.createElement('script');
214
+ var src_1 = "".concat(path).concat(branchParam_1, "/bundle.js");
215
+ branchScript.src = src_1;
216
+ branchScript.setAttribute(exports.BRANCH_COOKIE, branchParam_1);
217
+ document.head.appendChild(branchScript);
202
218
  new snap_toolbox_1.DomTargeter([
203
219
  {
204
220
  selector: 'body',
@@ -206,19 +222,37 @@ var Snap = /** @class */ (function () {
206
222
  action: 'append',
207
223
  element: function () {
208
224
  var branchContainer = document.createElement('div');
209
- branchContainer.className = 'ss__branch--target';
225
+ branchContainer.id = 'searchspring-branch-override';
210
226
  return branchContainer;
211
227
  },
212
228
  },
213
229
  },
214
230
  ], function (target, elem) { return __awaiter(_this, void 0, void 0, function () {
215
- var BranchOverride;
231
+ var bundleDetails, error, getBundleDetails, err_1, BranchOverride;
216
232
  return __generator(this, function (_a) {
217
233
  switch (_a.label) {
218
- 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')); })];
219
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:
220
249
  BranchOverride = (_a.sent()).BranchOverride;
221
- (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);
222
256
  return [2 /*return*/];
223
257
  }
224
258
  });
@@ -276,66 +310,69 @@ var Snap = /** @class */ (function () {
276
310
  }
277
311
  };
278
312
  var targetFunction_1 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
279
- var onTarget, Component_1, err_1;
313
+ var onTarget, _a, Component_1, err_2;
280
314
  var _this = this;
281
- return __generator(this, function (_a) {
282
- switch (_a.label) {
315
+ return __generator(this, function (_b) {
316
+ switch (_b.label) {
283
317
  case 0:
284
318
  runSearch_1();
285
319
  onTarget = target.onTarget;
286
- onTarget && onTarget(target, elem, originalElem);
287
- _a.label = 1;
320
+ _a = onTarget;
321
+ if (!_a) return [3 /*break*/, 2];
322
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
288
323
  case 1:
289
- _a.trys.push([1, 3, , 4]);
290
- return [4 /*yield*/, target.component()];
324
+ _a = (_b.sent());
325
+ _b.label = 2;
291
326
  case 2:
292
- 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();
293
334
  setTimeout(function () {
294
335
  (0, preact_1.render)((0, jsx_runtime_1.jsx)(Component_1, __assign({ controller: _this.controllers[controller.config.id] }, target.props)), elem);
295
336
  });
296
- return [3 /*break*/, 4];
297
- case 3:
298
- err_1 = _a.sent();
299
- 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);
300
- return [3 /*break*/, 4];
301
- 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*/];
302
343
  }
303
344
  });
304
345
  }); };
305
- (_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 () {
306
- var _this = this;
307
- return __generator(this, function (_a) {
308
- if (!target.selector) {
309
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
310
- }
311
- if (!target.component) {
312
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
313
- }
314
- if (target.prefetch) {
315
- runSearch_1();
316
- }
317
- cntrlr_1.createTargeter(__assign({ controller: cntrlr_1 }, target), function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
318
- var Skeleton_1;
319
- return __generator(this, function (_a) {
320
- switch (_a.label) {
321
- case 0:
322
- if (!target.skeleton) return [3 /*break*/, 2];
323
- return [4 /*yield*/, target.skeleton()];
324
- case 1:
325
- Skeleton_1 = _a.sent();
326
- setTimeout(function () {
327
- (0, preact_1.render)((0, jsx_runtime_1.jsx)(Skeleton_1, {}), elem);
328
- });
329
- _a.label = 2;
330
- case 2:
331
- targetFunction_1(target, elem, originalElem);
332
- return [2 /*return*/];
333
- }
334
- });
335
- }); });
336
- return [2 /*return*/];
337
- });
338
- }); });
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
+ });
339
376
  }
340
377
  catch (err) {
341
378
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -358,65 +395,79 @@ var Snap = /** @class */ (function () {
358
395
  }
359
396
  };
360
397
  var targetFunction_2 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
361
- var onTarget, Component;
398
+ var onTarget, _a, Component_2, err_3;
362
399
  var _this = this;
363
- return __generator(this, function (_a) {
364
- switch (_a.label) {
400
+ return __generator(this, function (_b) {
401
+ switch (_b.label) {
365
402
  case 0:
366
403
  onTarget = target.onTarget;
367
- onTarget && onTarget(target, elem, originalElem);
368
- return [4 /*yield*/, target.component()];
404
+ _a = onTarget;
405
+ if (!_a) return [3 /*break*/, 2];
406
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
369
407
  case 1:
370
- 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());
371
418
  setTimeout(function () {
372
- (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);
373
420
  });
374
- 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*/];
375
427
  }
376
428
  });
377
429
  }); };
378
430
  if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
379
- _this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context);
380
- }
381
- (_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 () {
382
- var targeter;
383
- var _this = this;
384
- return __generator(this, function (_a) {
385
- if (!target.selector) {
386
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
387
- }
388
- if (!target.component) {
389
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
390
- }
391
- targeter = new snap_toolbox_1.DomTargeter([
392
- __assign({ inject: {
393
- action: 'after',
394
- element: function () {
395
- var acContainer = document.createElement('div');
396
- acContainer.className = 'ss__autocomplete--target';
397
- acContainer.addEventListener('click', function (e) {
398
- e.stopPropagation();
399
- });
400
- return acContainer;
401
- },
402
- } }, target),
403
- ], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
404
- var cntrlr;
405
- return __generator(this, function (_a) {
406
- switch (_a.label) {
407
- case 0: return [4 /*yield*/, this.createController(DynamicImportNames.AUTOCOMPLETE, controller.config, controller.services, controller.url, resolve, controller.context)];
408
- case 1:
409
- cntrlr = _a.sent();
410
- runBind_1();
411
- targetFunction_2(__assign({ controller: cntrlr }, target), elem, originalElem);
412
- cntrlr.addTargeter(targeter);
413
- return [2 /*return*/];
414
- }
415
- });
416
- }); });
417
- return [2 /*return*/];
431
+ _this.createController(snap_controller_1.ControllerTypes.autocomplete, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
432
+ resolve(cntrlr);
418
433
  });
419
- }); });
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
+ });
420
471
  }
421
472
  catch (err) {
422
473
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -438,53 +489,67 @@ var Snap = /** @class */ (function () {
438
489
  }
439
490
  };
440
491
  var targetFunction_3 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
441
- var onTarget, Component;
492
+ var onTarget, _a, Component_3, err_4;
442
493
  var _this = this;
443
- return __generator(this, function (_a) {
444
- switch (_a.label) {
494
+ return __generator(this, function (_b) {
495
+ switch (_b.label) {
445
496
  case 0:
446
497
  onTarget = target.onTarget;
447
- onTarget && onTarget(target, elem, originalElem);
448
- return [4 /*yield*/, target.component()];
498
+ _a = onTarget;
499
+ if (!_a) return [3 /*break*/, 2];
500
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
449
501
  case 1:
450
- 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();
451
512
  setTimeout(function () {
452
- (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);
453
514
  });
454
- 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*/];
455
521
  }
456
522
  });
457
523
  }); };
458
524
  if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
459
- _this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context);
460
- }
461
- (_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 () {
462
- var targeter;
463
- var _this = this;
464
- return __generator(this, function (_a) {
465
- if (!target.selector) {
466
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
467
- }
468
- if (!target.component) {
469
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
470
- }
471
- targeter = new snap_toolbox_1.DomTargeter([__assign({}, target)], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
472
- var cntrlr;
473
- return __generator(this, function (_a) {
474
- switch (_a.label) {
475
- case 0: return [4 /*yield*/, this.createController(DynamicImportNames.FINDER, controller.config, controller.services, controller.url, resolve, controller.context)];
476
- case 1:
477
- cntrlr = _a.sent();
478
- runSearch_2();
479
- targetFunction_3(__assign({ controller: cntrlr }, target), elem, originalElem);
480
- cntrlr.addTargeter(targeter);
481
- return [2 /*return*/];
482
- }
483
- });
484
- }); });
485
- return [2 /*return*/];
525
+ _this.createController(snap_controller_1.ControllerTypes.finder, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
526
+ resolve(cntrlr);
486
527
  });
487
- }); });
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
+ });
488
553
  }
489
554
  catch (err) {
490
555
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -506,53 +571,67 @@ var Snap = /** @class */ (function () {
506
571
  }
507
572
  };
508
573
  var targetFunction_4 = function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
509
- var onTarget, Component;
574
+ var onTarget, _a, Component_4, err_5;
510
575
  var _this = this;
511
- return __generator(this, function (_a) {
512
- switch (_a.label) {
576
+ return __generator(this, function (_b) {
577
+ switch (_b.label) {
513
578
  case 0:
514
579
  onTarget = target.onTarget;
515
- onTarget && onTarget(target, elem, originalElem);
516
- return [4 /*yield*/, target.component()];
580
+ _a = onTarget;
581
+ if (!_a) return [3 /*break*/, 2];
582
+ return [4 /*yield*/, onTarget(target, elem, originalElem)];
517
583
  case 1:
518
- 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();
519
594
  setTimeout(function () {
520
- (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);
521
596
  });
522
- 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*/];
523
603
  }
524
604
  });
525
605
  }); };
526
606
  if (!(controller === null || controller === void 0 ? void 0 : controller.targeters) || (controller === null || controller === void 0 ? void 0 : controller.targeters.length) === 0) {
527
- _this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context);
528
- }
529
- (_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 () {
530
- var targeter;
531
- var _this = this;
532
- return __generator(this, function (_a) {
533
- if (!target.selector) {
534
- throw new Error("Targets at index ".concat(target_index, " missing selector value (string)."));
535
- }
536
- if (!target.component) {
537
- throw new Error("Targets at index ".concat(target_index, " missing component value (Component)."));
538
- }
539
- targeter = new snap_toolbox_1.DomTargeter([__assign({}, target)], function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
540
- var cntrlr;
541
- return __generator(this, function (_a) {
542
- switch (_a.label) {
543
- case 0: return [4 /*yield*/, this.createController(DynamicImportNames.RECOMMENDATION, controller.config, controller.services, controller.url, resolve, controller.context)];
544
- case 1:
545
- cntrlr = _a.sent();
546
- runSearch_3();
547
- targetFunction_4(__assign({ controller: cntrlr }, target), elem, originalElem);
548
- cntrlr.addTargeter(targeter);
549
- return [2 /*return*/];
550
- }
551
- });
552
- }); });
553
- return [2 /*return*/];
607
+ _this.createController(snap_controller_1.ControllerTypes.recommendation, controller.config, controller.services, controller.url, controller.context, function (cntrlr) {
608
+ resolve(cntrlr);
554
609
  });
555
- }); });
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
+ });
556
635
  }
557
636
  catch (err) {
558
637
  _this.logger.error("Failed to instantiate ".concat(type, " controller at index ").concat(index, "."), err);
@@ -565,13 +644,12 @@ var Snap = /** @class */ (function () {
565
644
  });
566
645
  if ((_m = (_l = this.config) === null || _l === void 0 ? void 0 : _l.instantiators) === null || _m === void 0 ? void 0 : _m.recommendation) {
567
646
  try {
568
- this._instantiatorPromises.recommendations = Promise.resolve().then(function () { return __importStar(require('./Instantiators/RecommendationInstantiator')); }).then(function (_a) {
569
- var _b, _c, _d, _e, _f, _g;
647
+ this._instantiatorPromises.recommendation = Promise.resolve().then(function () { return __importStar(require('./Instantiators/RecommendationInstantiator')); }).then(function (_a) {
570
648
  var RecommendationInstantiator = _a.RecommendationInstantiator;
571
649
  return new RecommendationInstantiator(_this.config.instantiators.recommendation, {
572
- 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,
573
- 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,
574
- 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,
575
653
  }, _this.context);
576
654
  });
577
655
  }