@searchspring/snap-preact 0.77.0 → 0.78.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/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/cjs/Instantiators/RecommendationInstantiator.js +29 -8
- package/dist/esm/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/esm/Instantiators/RecommendationInstantiator.js +27 -8
- package/package.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA2D,MAAM,2BAA2B,CAAC;AACtI,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjI,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAInE,MAAM,MAAM,gCAAgC,GAAG;IAC9C,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO,GAAG,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE;QACX,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;KACzC,CAAC;IACF,MAAM,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,MAAM,CAAC,EAAE,cAAc,CAAC;KACxB,GAAG,WAAW,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;
|
|
1
|
+
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA2D,MAAM,2BAA2B,CAAC;AACtI,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjI,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,+BAA+B,CA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IAEtB,IAAI,EAAE,WAAW,EAAE,CAAM;IACzB,OAAO,EAAE;QAAE,IAAI,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QAAC,IAAI,EAAE,OAAO,EAAE,CAAA;KAAE,EAAE,CAAM;IACvG,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAA;KAAE,EAAE,CAAM;gBAE7D,MAAM,EAAE,gCAAgC,EAAE,QAAQ,CAAC,EAAE,kCAAkC,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAuNxH,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAInG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI;IAIvD,GAAG,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAKnC,uBAAuB,IAAI,IAAI;CAqBtC;AAgKD,KAAK,YAAY,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB,CAAC;AAEF,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY,CAUrE"}
|
|
@@ -111,12 +111,14 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
111
111
|
selector: "".concat(this.config.selector || 'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"]', ", script[type=\"searchspring/recommend\"][profile=\"email\"]"),
|
|
112
112
|
autoRetarget: true,
|
|
113
113
|
clickRetarget: true,
|
|
114
|
+
navigationRetarget: true,
|
|
114
115
|
emptyTarget: false,
|
|
115
116
|
},
|
|
116
117
|
{
|
|
117
118
|
selector: 'script[type="searchspring/recommendations"]',
|
|
118
119
|
autoRetarget: true,
|
|
119
120
|
clickRetarget: true,
|
|
121
|
+
navigationRetarget: true,
|
|
120
122
|
emptyTarget: false,
|
|
121
123
|
},
|
|
122
124
|
], function (target, elem, _originalElem, targeter) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -124,6 +126,7 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
124
126
|
var _this = this;
|
|
125
127
|
var _a;
|
|
126
128
|
return __generator(this, function (_b) {
|
|
129
|
+
this.cleanupStaleControllers();
|
|
127
130
|
this.targeter = this.targeter || targeter;
|
|
128
131
|
scriptElement = elem;
|
|
129
132
|
elemContext = (0, snap_toolbox_1.getContext)([
|
|
@@ -154,12 +157,13 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
154
157
|
}));
|
|
155
158
|
// create a per-profile DomTargeter for each profile so each controller
|
|
156
159
|
// gets its own targeter tracking its specific element
|
|
157
|
-
scriptContextProfiles.forEach(function (profile) {
|
|
160
|
+
scriptContextProfiles.forEach(function (profile, index) {
|
|
158
161
|
if (profile.selector) {
|
|
159
162
|
var profileTarget = {
|
|
160
163
|
selector: profile.selector,
|
|
161
164
|
autoRetarget: true,
|
|
162
165
|
profile: profile,
|
|
166
|
+
order: index,
|
|
163
167
|
};
|
|
164
168
|
// track the controller for this profile so multiple matched elements share it
|
|
165
169
|
var profileControllerPromise_1;
|
|
@@ -169,12 +173,15 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
169
173
|
return __generator(this, function (_d) {
|
|
170
174
|
switch (_d.label) {
|
|
171
175
|
case 0:
|
|
172
|
-
// skip retarget if the source script element was removed
|
|
176
|
+
// skip retarget if the source script element was removed and release the current target
|
|
173
177
|
if (!scriptElement.isConnected) {
|
|
178
|
+
if (targetElem) {
|
|
179
|
+
targeter === null || targeter === void 0 ? void 0 : targeter.releaseTargets([targetElem]);
|
|
180
|
+
}
|
|
174
181
|
return [2 /*return*/];
|
|
175
182
|
}
|
|
176
183
|
if (!(((_a = target.profile) === null || _a === void 0 ? void 0 : _a.profile) || ((_b = target.profile) === null || _b === void 0 ? void 0 : _b.tag))) return [3 /*break*/, 3];
|
|
177
|
-
profileRequestGlobals = __assign(__assign({}, requestGlobals_1), { profile: (_c = target.profile) === null || _c === void 0 ? void 0 : _c.options, tag: target.profile.tag || target.profile.profile });
|
|
184
|
+
profileRequestGlobals = __assign(__assign({}, requestGlobals_1), { profile: __assign(__assign({}, (_c = target.profile) === null || _c === void 0 ? void 0 : _c.options), { order: target.order }), tag: target.profile.tag || target.profile.profile });
|
|
178
185
|
profileContext = (0, deepmerge_1.default)(this.context, defined({ globals: scriptContextGlobals_1, profile: target.profile }));
|
|
179
186
|
if (elemContext.custom) {
|
|
180
187
|
profileContext.custom = elemContext.custom;
|
|
@@ -217,8 +224,11 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
217
224
|
// create a per-element DomTargeter for the injected div (mirrors grouped block pattern)
|
|
218
225
|
new snap_toolbox_1.DomTargeter([{ selector: "[searchspring-recommend=\"".concat(profileAttr, "\"]"), name: "legacy_".concat(profile, "_").concat(profileCount[profile || ''] || 0) }], function (_target, targetElem, _originalElem, targeter) { return __awaiter(_this, void 0, void 0, function () {
|
|
219
226
|
return __generator(this, function (_a) {
|
|
220
|
-
// skip retarget if the source script element was removed
|
|
227
|
+
// skip retarget if the source script element was removed and release the current target
|
|
221
228
|
if (!scriptElement.isConnected) {
|
|
229
|
+
if (targetElem) {
|
|
230
|
+
targeter === null || targeter === void 0 ? void 0 : targeter.releaseTargets([targetElem]);
|
|
231
|
+
}
|
|
222
232
|
return [2 /*return*/];
|
|
223
233
|
}
|
|
224
234
|
readyTheController(this, targetElem, legacyContext_1, profileCount, scriptElement, profileRequestGlobals_1, targeter);
|
|
@@ -254,8 +264,14 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
254
264
|
var _a;
|
|
255
265
|
var controller = _this.controller[id];
|
|
256
266
|
var targeters = Object.values(controller.targeters);
|
|
257
|
-
var hasConnectedTarget = targeters.some(function (targeter) {
|
|
267
|
+
var hasConnectedTarget = targeters.some(function (targeter) {
|
|
268
|
+
return targeter.getTargetedElems().some(function (elem) {
|
|
269
|
+
var attr = elem.isConnected && elem.getAttribute('ss-controller-id');
|
|
270
|
+
return attr === id;
|
|
271
|
+
});
|
|
272
|
+
});
|
|
258
273
|
if (!hasConnectedTarget) {
|
|
274
|
+
Object.keys(controller.targeters).forEach(function (targeterId) { return controller.targeters[targeterId].destroy(); });
|
|
259
275
|
controller.targeters = {};
|
|
260
276
|
delete _this.controller[id];
|
|
261
277
|
if ((_a = window.searchspring) === null || _a === void 0 ? void 0 : _a.controller) {
|
|
@@ -293,8 +309,6 @@ function readyTheController(instance, targetElem, context, profileCount, scriptE
|
|
|
293
309
|
if (profile === null || profile === void 0 ? void 0 : profile.branch) {
|
|
294
310
|
controllerConfigBase.branch = profile === null || profile === void 0 ? void 0 : profile.branch;
|
|
295
311
|
}
|
|
296
|
-
// clean up controllers whose rendered elements are no longer in the DOM (SPA navigation)
|
|
297
|
-
instance.cleanupStaleControllers();
|
|
298
312
|
profileCount[tag] = profileCount[tag] + 1 || 1;
|
|
299
313
|
controllerConfig = __assign({ id: "recommend_".concat(tag, "_").concat(profileCount[tag] - 1) }, controllerConfigBase);
|
|
300
314
|
controller = (0, create_1.createRecommendationController)({
|
|
@@ -303,6 +317,10 @@ function readyTheController(instance, targetElem, context, profileCount, scriptE
|
|
|
303
317
|
context: context,
|
|
304
318
|
mode: instance.config.mode,
|
|
305
319
|
}, { client: instance.client, tracker: instance.tracker });
|
|
320
|
+
// mark element with controller id so cleanupStaleControllers knows it's active
|
|
321
|
+
if (targetElem) {
|
|
322
|
+
targetElem.setAttribute('ss-controller-id', controller.id);
|
|
323
|
+
}
|
|
306
324
|
instance.uses.forEach(function (attachements) { return controller.use(attachements); });
|
|
307
325
|
instance.plugins.forEach(function (plugin) { return controller.plugin.apply(controller, __spreadArray([plugin.func], plugin.args, false)); });
|
|
308
326
|
instance.middleware.forEach(function (middleware) { return controller.on.apply(controller, __spreadArray([middleware.event], middleware.func, false)); });
|
|
@@ -349,6 +367,10 @@ function renderController(instance, controller, targetElem, scriptElem) {
|
|
|
349
367
|
return __generator(this, function (_c) {
|
|
350
368
|
switch (_c.label) {
|
|
351
369
|
case 0:
|
|
370
|
+
// update the element with the controller id
|
|
371
|
+
if (targetElem) {
|
|
372
|
+
targetElem.setAttribute('ss-controller-id', controller.id);
|
|
373
|
+
}
|
|
352
374
|
tag = controller.config.tag;
|
|
353
375
|
component = (_a = controller.store.profile.display.template) === null || _a === void 0 ? void 0 : _a.component;
|
|
354
376
|
if (!component) {
|
|
@@ -368,7 +390,6 @@ function renderController(instance, controller, targetElem, scriptElem) {
|
|
|
368
390
|
return [2 /*return*/];
|
|
369
391
|
}
|
|
370
392
|
setTimeout(function () {
|
|
371
|
-
targetElem.setAttribute('ss-controller-id', controller.config.id);
|
|
372
393
|
(0, preact_1.render)((0, jsx_runtime_1.jsx)(RecommendationsComponent, { controller: controller }), targetElem);
|
|
373
394
|
});
|
|
374
395
|
return [2 /*return*/];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAA2D,MAAM,2BAA2B,CAAC;AACtI,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjI,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAInE,MAAM,MAAM,gCAAgC,GAAG;IAC9C,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO,GAAG,OAAO,CAAC;IACtC,MAAM,CAAC,EAAE;QACR,OAAO,EAAE,aAAa,CAAC;QACvB,MAAM,CAAC,EAAE,YAAY,CAAC;KACtB,CAAC;IACF,UAAU,EAAE;QACX,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;KACzC,CAAC;IACF,MAAM,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,aAAa,CAAC;QACzB,MAAM,CAAC,EAAE,cAAc,CAAC;KACxB,GAAG,WAAW,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;
|
|
1
|
+
{"version":3,"file":"RecommendationInstantiator.d.ts","sourceRoot":"","sources":["../../../src/Instantiators/RecommendationInstantiator.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAc,MAAM,4BAA4B,CAAC;AAC9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;AAgKD,KAAK,YAAY,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACnB,CAAC;AAEF,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY,CAUrE"}
|
|
@@ -47,15 +47,18 @@ export class RecommendationInstantiator {
|
|
|
47
47
|
selector: `${this.config.selector || 'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"]'}, script[type="searchspring/recommend"][profile="email"]`,
|
|
48
48
|
autoRetarget: true,
|
|
49
49
|
clickRetarget: true,
|
|
50
|
+
navigationRetarget: true,
|
|
50
51
|
emptyTarget: false,
|
|
51
52
|
},
|
|
52
53
|
{
|
|
53
54
|
selector: 'script[type="searchspring/recommendations"]',
|
|
54
55
|
autoRetarget: true,
|
|
55
56
|
clickRetarget: true,
|
|
57
|
+
navigationRetarget: true,
|
|
56
58
|
emptyTarget: false,
|
|
57
59
|
},
|
|
58
60
|
], async (target, elem, _originalElem, targeter) => {
|
|
61
|
+
this.cleanupStaleControllers();
|
|
59
62
|
this.targeter = this.targeter || targeter;
|
|
60
63
|
const scriptElement = elem;
|
|
61
64
|
const elemContext = getContext([
|
|
@@ -91,24 +94,28 @@ export class RecommendationInstantiator {
|
|
|
91
94
|
};
|
|
92
95
|
// create a per-profile DomTargeter for each profile so each controller
|
|
93
96
|
// gets its own targeter tracking its specific element
|
|
94
|
-
scriptContextProfiles.forEach((profile) => {
|
|
97
|
+
scriptContextProfiles.forEach((profile, index) => {
|
|
95
98
|
if (profile.selector) {
|
|
96
99
|
const profileTarget = {
|
|
97
100
|
selector: profile.selector,
|
|
98
101
|
autoRetarget: true,
|
|
99
102
|
profile,
|
|
103
|
+
order: index,
|
|
100
104
|
};
|
|
101
105
|
// track the controller for this profile so multiple matched elements share it
|
|
102
106
|
let profileControllerPromise;
|
|
103
107
|
new DomTargeter([profileTarget], async (target, targetElem, _originalElem, targeter) => {
|
|
104
|
-
// skip retarget if the source script element was removed
|
|
108
|
+
// skip retarget if the source script element was removed and release the current target
|
|
105
109
|
if (!scriptElement.isConnected) {
|
|
110
|
+
if (targetElem) {
|
|
111
|
+
targeter?.releaseTargets([targetElem]);
|
|
112
|
+
}
|
|
106
113
|
return;
|
|
107
114
|
}
|
|
108
115
|
if (target.profile?.profile || target.profile?.tag) {
|
|
109
116
|
const profileRequestGlobals = {
|
|
110
117
|
...requestGlobals,
|
|
111
|
-
profile: target.profile?.options,
|
|
118
|
+
profile: { ...target.profile?.options, order: target.order },
|
|
112
119
|
tag: target.profile.tag || target.profile.profile, // have to support both tag and profile due to having profile at release, but will favor tag
|
|
113
120
|
};
|
|
114
121
|
const profileContext = deepmerge(this.context, defined({ globals: scriptContextGlobals, profile: target.profile }));
|
|
@@ -155,8 +162,11 @@ export class RecommendationInstantiator {
|
|
|
155
162
|
const legacyContext = deepmerge(this.context, elemContext);
|
|
156
163
|
// create a per-element DomTargeter for the injected div (mirrors grouped block pattern)
|
|
157
164
|
new DomTargeter([{ selector: `[searchspring-recommend="${profileAttr}"]`, name: `legacy_${profile}_${profileCount[profile || ''] || 0}` }], async (_target, targetElem, _originalElem, targeter) => {
|
|
158
|
-
// skip retarget if the source script element was removed
|
|
165
|
+
// skip retarget if the source script element was removed and release the current target
|
|
159
166
|
if (!scriptElement.isConnected) {
|
|
167
|
+
if (targetElem) {
|
|
168
|
+
targeter?.releaseTargets([targetElem]);
|
|
169
|
+
}
|
|
160
170
|
return;
|
|
161
171
|
}
|
|
162
172
|
readyTheController(this, targetElem, legacyContext, profileCount, scriptElement, profileRequestGlobals, targeter);
|
|
@@ -178,8 +188,12 @@ export class RecommendationInstantiator {
|
|
|
178
188
|
Object.keys(this.controller).forEach((id) => {
|
|
179
189
|
const controller = this.controller[id];
|
|
180
190
|
const targeters = Object.values(controller.targeters);
|
|
181
|
-
const hasConnectedTarget = targeters.some((targeter) => targeter.getTargetedElems().some((elem) =>
|
|
191
|
+
const hasConnectedTarget = targeters.some((targeter) => targeter.getTargetedElems().some((elem) => {
|
|
192
|
+
const attr = elem.isConnected && elem.getAttribute('ss-controller-id');
|
|
193
|
+
return attr === id;
|
|
194
|
+
}));
|
|
182
195
|
if (!hasConnectedTarget) {
|
|
196
|
+
Object.keys(controller.targeters).forEach((targeterId) => controller.targeters[targeterId].destroy());
|
|
183
197
|
controller.targeters = {};
|
|
184
198
|
delete this.controller[id];
|
|
185
199
|
if (window.searchspring?.controller) {
|
|
@@ -216,8 +230,6 @@ async function readyTheController(instance, targetElem, context, profileCount, s
|
|
|
216
230
|
if (profile?.branch) {
|
|
217
231
|
controllerConfigBase.branch = profile?.branch;
|
|
218
232
|
}
|
|
219
|
-
// clean up controllers whose rendered elements are no longer in the DOM (SPA navigation)
|
|
220
|
-
instance.cleanupStaleControllers();
|
|
221
233
|
profileCount[tag] = profileCount[tag] + 1 || 1;
|
|
222
234
|
const controllerConfig = {
|
|
223
235
|
id: `recommend_${tag}_${profileCount[tag] - 1}`,
|
|
@@ -229,6 +241,10 @@ async function readyTheController(instance, targetElem, context, profileCount, s
|
|
|
229
241
|
context,
|
|
230
242
|
mode: instance.config.mode,
|
|
231
243
|
}, { client: instance.client, tracker: instance.tracker });
|
|
244
|
+
// mark element with controller id so cleanupStaleControllers knows it's active
|
|
245
|
+
if (targetElem) {
|
|
246
|
+
targetElem.setAttribute('ss-controller-id', controller.id);
|
|
247
|
+
}
|
|
232
248
|
instance.uses.forEach((attachements) => controller.use(attachements));
|
|
233
249
|
instance.plugins.forEach((plugin) => controller.plugin(plugin.func, ...plugin.args));
|
|
234
250
|
instance.middleware.forEach((middleware) => controller.on(middleware.event, ...middleware.func));
|
|
@@ -262,6 +278,10 @@ async function readyTheController(instance, targetElem, context, profileCount, s
|
|
|
262
278
|
return controller;
|
|
263
279
|
}
|
|
264
280
|
async function renderController(instance, controller, targetElem, scriptElem) {
|
|
281
|
+
// update the element with the controller id
|
|
282
|
+
if (targetElem) {
|
|
283
|
+
targetElem.setAttribute('ss-controller-id', controller.id);
|
|
284
|
+
}
|
|
265
285
|
const tag = controller.config.tag;
|
|
266
286
|
const component = controller.store.profile.display.template?.component;
|
|
267
287
|
if (!component) {
|
|
@@ -275,7 +295,6 @@ async function renderController(instance, controller, targetElem, scriptElem) {
|
|
|
275
295
|
return;
|
|
276
296
|
}
|
|
277
297
|
setTimeout(() => {
|
|
278
|
-
targetElem.setAttribute('ss-controller-id', controller.config.id);
|
|
279
298
|
render(_jsx(RecommendationsComponent, { controller: controller }), targetElem);
|
|
280
299
|
});
|
|
281
300
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-preact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "Snap Preact",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"test:watch": "jest --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@searchspring/snap-client": "0.
|
|
24
|
-
"@searchspring/snap-controller": "0.
|
|
25
|
-
"@searchspring/snap-event-manager": "0.
|
|
26
|
-
"@searchspring/snap-logger": "0.
|
|
27
|
-
"@searchspring/snap-platforms": "0.
|
|
28
|
-
"@searchspring/snap-preact-components": "0.
|
|
29
|
-
"@searchspring/snap-profiler": "0.
|
|
30
|
-
"@searchspring/snap-store-mobx": "0.
|
|
31
|
-
"@searchspring/snap-toolbox": "0.
|
|
32
|
-
"@searchspring/snap-tracker": "0.
|
|
33
|
-
"@searchspring/snap-url-manager": "0.
|
|
23
|
+
"@searchspring/snap-client": "0.78.0",
|
|
24
|
+
"@searchspring/snap-controller": "0.78.0",
|
|
25
|
+
"@searchspring/snap-event-manager": "0.78.0",
|
|
26
|
+
"@searchspring/snap-logger": "0.78.0",
|
|
27
|
+
"@searchspring/snap-platforms": "0.78.0",
|
|
28
|
+
"@searchspring/snap-preact-components": "0.78.0",
|
|
29
|
+
"@searchspring/snap-profiler": "0.78.0",
|
|
30
|
+
"@searchspring/snap-store-mobx": "0.78.0",
|
|
31
|
+
"@searchspring/snap-toolbox": "0.78.0",
|
|
32
|
+
"@searchspring/snap-tracker": "0.78.0",
|
|
33
|
+
"@searchspring/snap-url-manager": "0.78.0",
|
|
34
34
|
"deepmerge": "4.3.1",
|
|
35
35
|
"intersection-observer": "0.12.0",
|
|
36
36
|
"is-plain-object": "5.0.0"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"files": [
|
|
44
44
|
"dist/**/*"
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "9d17504d1ba3b5131c4edeb0cb1edb6ff65ec1b0"
|
|
47
47
|
}
|