@athoscommerce/snap-preact 1.3.0 → 1.5.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/README.md +16 -0
- package/dist/cjs/components/src/components/Molecules/Filter/Filter.d.ts +1 -1
- package/dist/cjs/components/src/components/Molecules/Filter/Filter.d.ts.map +1 -1
- package/dist/cjs/components/src/components/Organisms/FilterSummary/FilterSummary.d.ts +2 -2
- package/dist/cjs/components/src/components/Organisms/FilterSummary/FilterSummary.d.ts.map +1 -1
- package/dist/cjs/components/src/components/Templates/AutocompleteModal/AutocompleteModal.d.ts.map +1 -1
- package/dist/cjs/components/src/components/Templates/AutocompleteModal/AutocompleteModal.js +0 -2
- package/dist/cjs/components/src/hooks/useAcRenderedInput.d.ts.map +1 -1
- package/dist/cjs/components/src/hooks/useAcRenderedInput.js +65 -15
- package/dist/cjs/components/src/providers/theme.d.ts +1 -1
- package/dist/cjs/components/src/providers/theme.d.ts.map +1 -1
- package/dist/cjs/src/Instantiators/RecommendationInstantiator.d.ts +1 -0
- package/dist/cjs/src/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/cjs/src/Instantiators/RecommendationInstantiator.js +161 -123
- package/dist/cjs/src/Snap.d.ts +1 -1
- package/dist/cjs/src/Snap.d.ts.map +1 -1
- package/dist/cjs/src/Snap.js +8 -6
- package/dist/cjs/src/Templates/SnapTemplates.d.ts.map +1 -1
- package/dist/cjs/src/Templates/SnapTemplates.js +14 -8
- package/dist/cjs/src/Templates/Stores/TemplateEditor/TemplateEditorStore.d.ts +2 -1
- package/dist/cjs/src/Templates/Stores/TemplateEditor/TemplateEditorStore.d.ts.map +1 -1
- package/dist/cjs/src/Templates/Stores/TemplateEditor/TemplateEditorStore.js +2 -2
- package/dist/cjs/src/Templates/Stores/TemplateStore.d.ts +4 -3
- package/dist/cjs/src/Templates/Stores/TemplateStore.d.ts.map +1 -1
- package/dist/cjs/src/Templates/Stores/TemplateStore.js +4 -4
- package/dist/esm/components/src/components/Molecules/Filter/Filter.d.ts +1 -1
- package/dist/esm/components/src/components/Molecules/Filter/Filter.d.ts.map +1 -1
- package/dist/esm/components/src/components/Organisms/FilterSummary/FilterSummary.d.ts +2 -2
- package/dist/esm/components/src/components/Organisms/FilterSummary/FilterSummary.d.ts.map +1 -1
- package/dist/esm/components/src/components/Templates/AutocompleteModal/AutocompleteModal.d.ts.map +1 -1
- package/dist/esm/components/src/components/Templates/AutocompleteModal/AutocompleteModal.js +0 -2
- package/dist/esm/components/src/hooks/useAcRenderedInput.d.ts.map +1 -1
- package/dist/esm/components/src/hooks/useAcRenderedInput.js +61 -11
- package/dist/esm/components/src/providers/theme.d.ts +1 -1
- package/dist/esm/components/src/providers/theme.d.ts.map +1 -1
- package/dist/esm/src/Instantiators/RecommendationInstantiator.d.ts +1 -0
- package/dist/esm/src/Instantiators/RecommendationInstantiator.d.ts.map +1 -1
- package/dist/esm/src/Instantiators/RecommendationInstantiator.js +130 -84
- package/dist/esm/src/Snap.d.ts +1 -1
- package/dist/esm/src/Snap.d.ts.map +1 -1
- package/dist/esm/src/Snap.js +8 -6
- package/dist/esm/src/Templates/SnapTemplates.d.ts.map +1 -1
- package/dist/esm/src/Templates/SnapTemplates.js +20 -9
- package/dist/esm/src/Templates/Stores/TemplateEditor/TemplateEditorStore.d.ts +2 -1
- package/dist/esm/src/Templates/Stores/TemplateEditor/TemplateEditorStore.d.ts.map +1 -1
- package/dist/esm/src/Templates/Stores/TemplateEditor/TemplateEditorStore.js +1 -1
- package/dist/esm/src/Templates/Stores/TemplateStore.d.ts +4 -3
- package/dist/esm/src/Templates/Stores/TemplateStore.d.ts.map +1 -1
- package/dist/esm/src/Templates/Stores/TemplateStore.js +1 -1
- package/package.json +20 -14
|
@@ -10,29 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -91,6 +68,7 @@ var snap_toolbox_1 = require("@athoscommerce/snap-toolbox");
|
|
|
91
68
|
var snap_client_1 = require("@athoscommerce/snap-client");
|
|
92
69
|
var snap_logger_1 = require("@athoscommerce/snap-logger");
|
|
93
70
|
var snap_tracker_1 = require("@athoscommerce/snap-tracker");
|
|
71
|
+
var create_1 = require("../create");
|
|
94
72
|
var DEFAULT_BRANCH = 'production';
|
|
95
73
|
var RecommendationInstantiator = /** @class */ (function () {
|
|
96
74
|
function RecommendationInstantiator(config, services, context) {
|
|
@@ -128,33 +106,30 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
128
106
|
this.tracker = (services === null || services === void 0 ? void 0 : services.tracker) || new snap_tracker_1.Tracker(this.config.client.globals);
|
|
129
107
|
this.logger = (services === null || services === void 0 ? void 0 : services.logger) || new snap_logger_1.Logger({ prefix: 'RecommendationInstantiator ', mode: this.mode });
|
|
130
108
|
var profileCount = {};
|
|
109
|
+
// script block targeter for "grouped" and "legacy" blocks
|
|
131
110
|
this.targeter = new snap_toolbox_1.DomTargeter([
|
|
132
111
|
{
|
|
133
112
|
selector: "".concat(this.config.selector ||
|
|
134
113
|
'script[type="searchspring/recommend"], script[type="searchspring/personalized-recommendations"], script[type="athos/recommend"], script[type="athos/personalized-recommendations"]', ", script[type=\"searchspring/recommend\"][profile=\"email\"], script[type=\"athos/recommend\"][profile=\"email\"]"),
|
|
135
114
|
autoRetarget: true,
|
|
136
115
|
clickRetarget: true,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
element: function (target, origElement) {
|
|
140
|
-
var profile = origElement.getAttribute('profile') || '';
|
|
141
|
-
var recsContainer = document.createElement('div');
|
|
142
|
-
recsContainer.setAttribute('searchspring-recommend', profile);
|
|
143
|
-
return recsContainer;
|
|
144
|
-
},
|
|
145
|
-
},
|
|
116
|
+
navigationRetarget: true,
|
|
117
|
+
emptyTarget: false,
|
|
146
118
|
},
|
|
147
119
|
{
|
|
148
120
|
selector: 'script[type="searchspring/recommendations"], script[type="athos/recommendations"]',
|
|
149
121
|
autoRetarget: true,
|
|
150
122
|
clickRetarget: true,
|
|
123
|
+
navigationRetarget: true,
|
|
151
124
|
emptyTarget: false,
|
|
152
125
|
},
|
|
153
|
-
], function (target, elem
|
|
154
|
-
var elemContext, scriptContextProfiles, scriptContextGlobals_1, requestGlobals_1,
|
|
126
|
+
], function (target, elem) { return __awaiter(_this, void 0, void 0, function () {
|
|
127
|
+
var scriptElement, elemContext, scriptContextProfiles, scriptContextGlobals_1, requestGlobals_1, profile, products, product, seed, filters, blockedItems, options, shopper, shopperId, combinedProducts, shopperIdentifier, profileRequestGlobals_1, profileAttr, recsContainer, legacyContext_1;
|
|
155
128
|
var _this = this;
|
|
156
129
|
var _a;
|
|
157
130
|
return __generator(this, function (_b) {
|
|
131
|
+
this.cleanupStaleControllers();
|
|
132
|
+
scriptElement = elem;
|
|
158
133
|
elemContext = (0, snap_toolbox_1.getContext)([
|
|
159
134
|
'shopperId',
|
|
160
135
|
'shopper',
|
|
@@ -169,7 +144,7 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
169
144
|
'custom',
|
|
170
145
|
'profiles',
|
|
171
146
|
'globals',
|
|
172
|
-
],
|
|
147
|
+
], scriptElement);
|
|
173
148
|
if (elemContext.profiles && elemContext.profiles.length) {
|
|
174
149
|
scriptContextProfiles = elemContext.profiles;
|
|
175
150
|
scriptContextGlobals_1 = elemContext.globals;
|
|
@@ -179,42 +154,62 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
179
154
|
cart: (scriptContextGlobals_1 === null || scriptContextGlobals_1 === void 0 ? void 0 : scriptContextGlobals_1.cart) && getArrayFunc(scriptContextGlobals_1.cart),
|
|
180
155
|
products: scriptContextGlobals_1 === null || scriptContextGlobals_1 === void 0 ? void 0 : scriptContextGlobals_1.products,
|
|
181
156
|
shopper: (_a = scriptContextGlobals_1 === null || scriptContextGlobals_1 === void 0 ? void 0 : scriptContextGlobals_1.shopper) === null || _a === void 0 ? void 0 : _a.id,
|
|
182
|
-
batchId: Math.random(),
|
|
157
|
+
batchId: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
|
|
183
158
|
}));
|
|
184
|
-
|
|
185
|
-
//
|
|
186
|
-
scriptContextProfiles.forEach(function (profile) {
|
|
159
|
+
// create a per-profile DomTargeter for each profile so each controller
|
|
160
|
+
// gets its own targeter tracking its specific element
|
|
161
|
+
scriptContextProfiles.forEach(function (profile, index) {
|
|
187
162
|
if (profile.selector) {
|
|
188
|
-
var
|
|
163
|
+
var profileTarget = {
|
|
189
164
|
selector: profile.selector,
|
|
190
165
|
autoRetarget: true,
|
|
191
|
-
clickRetarget: true,
|
|
192
166
|
profile: profile,
|
|
167
|
+
order: index,
|
|
193
168
|
};
|
|
194
|
-
|
|
169
|
+
// track the controller for this profile so multiple matched elements share it
|
|
170
|
+
var profileControllerPromise_1;
|
|
171
|
+
new snap_toolbox_1.DomTargeter([profileTarget], function (target, targetElem, _originalElem, targeter) { return __awaiter(_this, void 0, void 0, function () {
|
|
172
|
+
var profileRequestGlobals, profileContext, controller;
|
|
173
|
+
var _a, _b, _c;
|
|
174
|
+
return __generator(this, function (_d) {
|
|
175
|
+
switch (_d.label) {
|
|
176
|
+
case 0:
|
|
177
|
+
// skip retarget if the source script element was removed and release the current target
|
|
178
|
+
if (scriptElement.isConnected === false) {
|
|
179
|
+
if (targetElem) {
|
|
180
|
+
targeter === null || targeter === void 0 ? void 0 : targeter.releaseTargets([targetElem]);
|
|
181
|
+
}
|
|
182
|
+
return [2 /*return*/];
|
|
183
|
+
}
|
|
184
|
+
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];
|
|
185
|
+
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 });
|
|
186
|
+
profileContext = (0, deepmerge_1.default)(this.context, defined({ globals: scriptContextGlobals_1, profile: target.profile }));
|
|
187
|
+
if (elemContext.custom) {
|
|
188
|
+
profileContext.custom = (0, deepmerge_1.default)(profileContext.custom, elemContext.custom);
|
|
189
|
+
}
|
|
190
|
+
if (!!profileControllerPromise_1) return [3 /*break*/, 1];
|
|
191
|
+
// first element match — create the controller
|
|
192
|
+
profileControllerPromise_1 = readyTheController(this, services || {}, targetElem, profileContext, profileCount, scriptElement, profileRequestGlobals, target, targeter);
|
|
193
|
+
return [3 /*break*/, 3];
|
|
194
|
+
case 1: return [4 /*yield*/, profileControllerPromise_1];
|
|
195
|
+
case 2:
|
|
196
|
+
controller = _d.sent();
|
|
197
|
+
if (controller && targetElem) {
|
|
198
|
+
renderController(this, services || {}, controller, targetElem, scriptElement, target);
|
|
199
|
+
}
|
|
200
|
+
_d.label = 3;
|
|
201
|
+
case 3: return [2 /*return*/];
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}); });
|
|
195
205
|
}
|
|
196
206
|
});
|
|
197
|
-
new snap_toolbox_1.DomTargeter(targetsArr_1, function (target, elem, originalElem) { return __awaiter(_this, void 0, void 0, function () {
|
|
198
|
-
var profileRequestGlobals, profileContext;
|
|
199
|
-
var _a, _b, _c;
|
|
200
|
-
return __generator(this, function (_d) {
|
|
201
|
-
if (((_a = target.profile) === null || _a === void 0 ? void 0 : _a.profile) || ((_b = target.profile) === null || _b === void 0 ? void 0 : _b.tag)) {
|
|
202
|
-
profileRequestGlobals = __assign(__assign({}, requestGlobals_1), { profile: (_c = target.profile) === null || _c === void 0 ? void 0 : _c.options, tag: target.profile.tag || target.profile.profile });
|
|
203
|
-
profileContext = (0, deepmerge_1.default)(this.context, defined({ globals: scriptContextGlobals_1, profile: target.profile }));
|
|
204
|
-
if (elemContext.custom) {
|
|
205
|
-
profileContext.custom = (0, deepmerge_1.default)(profileContext.custom, elemContext.custom);
|
|
206
|
-
}
|
|
207
|
-
readyTheController(this, services || {}, elem, profileContext, profileCount, originalElem, profileRequestGlobals, target);
|
|
208
|
-
}
|
|
209
|
-
return [2 /*return*/];
|
|
210
|
-
});
|
|
211
|
-
}); });
|
|
212
207
|
}
|
|
213
208
|
else {
|
|
214
209
|
profile = elemContext.profile, products = elemContext.products, product = elemContext.product, seed = elemContext.seed, filters = elemContext.filters, blockedItems = elemContext.blockedItems, options = elemContext.options, shopper = elemContext.shopper, shopperId = elemContext.shopperId;
|
|
215
210
|
combinedProducts = [].concat(products || product || seed || []);
|
|
216
211
|
shopperIdentifier = [shopper, shopper === null || shopper === void 0 ? void 0 : shopper.id, shopperId, shopperId === null || shopperId === void 0 ? void 0 : shopperId.id].filter(function (val) { return val && typeof val === 'string'; }).pop();
|
|
217
|
-
|
|
212
|
+
profileRequestGlobals_1 = __assign({ tag: profile }, defined({
|
|
218
213
|
products: combinedProducts.length ? combinedProducts : undefined,
|
|
219
214
|
cart: elemContext.cart && getArrayFunc(elemContext.cart),
|
|
220
215
|
shopper: shopperIdentifier,
|
|
@@ -222,7 +217,25 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
222
217
|
blockedItems: blockedItems,
|
|
223
218
|
profile: options,
|
|
224
219
|
}));
|
|
225
|
-
|
|
220
|
+
profileAttr = scriptElement.getAttribute('profile') || '';
|
|
221
|
+
recsContainer = scriptElement.ownerDocument.createElement('div');
|
|
222
|
+
recsContainer.setAttribute('searchspring-recommend', profileAttr);
|
|
223
|
+
scriptElement.before(recsContainer);
|
|
224
|
+
legacyContext_1 = (0, deepmerge_1.default)(this.context, elemContext);
|
|
225
|
+
// create a per-element DomTargeter for the injected div (mirrors grouped block pattern)
|
|
226
|
+
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 () {
|
|
227
|
+
return __generator(this, function (_a) {
|
|
228
|
+
// skip retarget if the source script element was removed and release the current target
|
|
229
|
+
if (scriptElement.isConnected === false) {
|
|
230
|
+
if (targetElem) {
|
|
231
|
+
targeter === null || targeter === void 0 ? void 0 : targeter.releaseTargets([targetElem]);
|
|
232
|
+
}
|
|
233
|
+
return [2 /*return*/];
|
|
234
|
+
}
|
|
235
|
+
readyTheController(this, services || {}, targetElem, legacyContext_1, profileCount, scriptElement, profileRequestGlobals_1, target, targeter);
|
|
236
|
+
return [2 /*return*/];
|
|
237
|
+
});
|
|
238
|
+
}); });
|
|
226
239
|
}
|
|
227
240
|
return [2 /*return*/];
|
|
228
241
|
});
|
|
@@ -245,34 +258,55 @@ var RecommendationInstantiator = /** @class */ (function () {
|
|
|
245
258
|
RecommendationInstantiator.prototype.use = function (attachments) {
|
|
246
259
|
this.uses.push(attachments);
|
|
247
260
|
};
|
|
261
|
+
// cleanup to ensure we release controllers no longer rendering in the DOM (memory leak prevention for SPA's)
|
|
262
|
+
RecommendationInstantiator.prototype.cleanupStaleControllers = function () {
|
|
263
|
+
var _this = this;
|
|
264
|
+
Object.keys(this.controller).forEach(function (id) {
|
|
265
|
+
var _a;
|
|
266
|
+
var controller = _this.controller[id];
|
|
267
|
+
var targeters = Object.values(controller.targeters);
|
|
268
|
+
var hasConnectedTarget = targeters.some(function (targeter) {
|
|
269
|
+
return targeter.getTargetedElems().some(function (elem) {
|
|
270
|
+
var attr = elem.isConnected !== false && elem.getAttribute('ss-controller-id');
|
|
271
|
+
return attr === id;
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
if (!hasConnectedTarget) {
|
|
275
|
+
Object.keys(controller.targeters).forEach(function (targeterId) { return controller.targeters[targeterId].destroy(); });
|
|
276
|
+
controller.targeters = {};
|
|
277
|
+
delete _this.controller[id];
|
|
278
|
+
if ((_a = window.athos) === null || _a === void 0 ? void 0 : _a.controller) {
|
|
279
|
+
delete window.athos.controller[id];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
};
|
|
248
284
|
return RecommendationInstantiator;
|
|
249
285
|
}());
|
|
250
286
|
exports.RecommendationInstantiator = RecommendationInstantiator;
|
|
251
|
-
function readyTheController(instance, services,
|
|
287
|
+
function readyTheController(instance, services, targetElem, context, profileCount, scriptElem, controllerGlobals, target, targeter) {
|
|
252
288
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var profile, batchId, cart, tag, batched, globals, controllerConfig, controller,
|
|
254
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s
|
|
255
|
-
return __generator(this, function (
|
|
256
|
-
switch (
|
|
289
|
+
var profile, batchId, cart, tag, batched, globals, controllerConfigBase, controllerConfig, controller, profileVars;
|
|
290
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
291
|
+
return __generator(this, function (_t) {
|
|
292
|
+
switch (_t.label) {
|
|
257
293
|
case 0:
|
|
258
294
|
profile = controllerGlobals.profile, batchId = controllerGlobals.batchId, cart = controllerGlobals.cart, tag = controllerGlobals.tag;
|
|
259
295
|
batched = (_b = (_a = profile === null || profile === void 0 ? void 0 : profile.batched) !== null && _a !== void 0 ? _a : controllerGlobals.batched) !== null && _b !== void 0 ? _b : true;
|
|
260
296
|
if (!tag) {
|
|
261
297
|
// FEEDBACK: change message depending on script integration type (profile vs. legacy)
|
|
262
|
-
instance.logger.warn("'tag' is missing from <script> tag, skipping this profile",
|
|
298
|
+
instance.logger.warn("'tag' is missing from <script> tag, skipping this profile", scriptElem);
|
|
263
299
|
return [2 /*return*/];
|
|
264
300
|
}
|
|
265
301
|
if (Array.isArray(cart)) {
|
|
266
302
|
instance.tracker.cookies.cart.set(cart);
|
|
267
303
|
}
|
|
268
|
-
profileCount[tag] = profileCount[tag] + 1 || 1;
|
|
269
304
|
globals = deepmerge_1.default.all([
|
|
270
305
|
((_c = instance.config.client) === null || _c === void 0 ? void 0 : _c.globals) || {},
|
|
271
306
|
((_d = instance.config.config) === null || _d === void 0 ? void 0 : _d.globals) || {},
|
|
272
307
|
controllerGlobals,
|
|
273
308
|
]);
|
|
274
|
-
|
|
275
|
-
id: "recommend_".concat(tag, "_").concat(profileCount[tag] - 1),
|
|
309
|
+
controllerConfigBase = {
|
|
276
310
|
tag: tag,
|
|
277
311
|
batched: (_f = batched !== null && batched !== void 0 ? batched : (_e = instance.config.config) === null || _e === void 0 ? void 0 : _e.batched) !== null && _f !== void 0 ? _f : true,
|
|
278
312
|
realtime: Boolean((_l = (_h = (_g = context.options) === null || _g === void 0 ? void 0 : _g.realtime) !== null && _h !== void 0 ? _h : (_k = (_j = context.profile) === null || _j === void 0 ? void 0 : _j.options) === null || _k === void 0 ? void 0 : _k.realtime) !== null && _l !== void 0 ? _l : (_m = instance.config.config) === null || _m === void 0 ? void 0 : _m.realtime),
|
|
@@ -281,106 +315,110 @@ function readyTheController(instance, services, injectedElem, context, profileCo
|
|
|
281
315
|
plugins: instance.config.config.plugins,
|
|
282
316
|
branch: ((_o = instance.config.config) === null || _o === void 0 ? void 0 : _o.branch) || 'production',
|
|
283
317
|
limit: (_p = instance.config.config) === null || _p === void 0 ? void 0 : _p.limit,
|
|
318
|
+
beacon: ((_q = instance.config.config) === null || _q === void 0 ? void 0 : _q.beacon) || { enabled: true },
|
|
284
319
|
settings: {
|
|
285
|
-
variants: (
|
|
320
|
+
variants: (_r = instance.config.config) === null || _r === void 0 ? void 0 : _r.variants,
|
|
286
321
|
},
|
|
287
322
|
globals: globals,
|
|
288
323
|
};
|
|
289
324
|
if (profile === null || profile === void 0 ? void 0 : profile.branch) {
|
|
290
|
-
|
|
325
|
+
controllerConfigBase.branch = profile === null || profile === void 0 ? void 0 : profile.branch;
|
|
291
326
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return (JSON.stringify({
|
|
296
|
-
batched: controller.config.batched,
|
|
297
|
-
branch: controller.config.branch,
|
|
298
|
-
globals: controller.config.globals,
|
|
299
|
-
tag: controller.config.tag,
|
|
300
|
-
realtime: controller.config.realtime,
|
|
301
|
-
}) ==
|
|
302
|
-
JSON.stringify({
|
|
303
|
-
batched: controllerConfig.batched,
|
|
304
|
-
branch: controllerConfig.branch,
|
|
305
|
-
globals: controllerConfig.globals,
|
|
306
|
-
tag: controllerConfig.tag,
|
|
307
|
-
realtime: controllerConfig.realtime,
|
|
308
|
-
}));
|
|
309
|
-
})[0];
|
|
310
|
-
if (!!controller) return [3 /*break*/, 2];
|
|
311
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('../create/createRecommendationController')); })];
|
|
312
|
-
case 1:
|
|
313
|
-
createRecommendationController = (_w.sent()).default;
|
|
314
|
-
controller = createRecommendationController({
|
|
327
|
+
profileCount[tag] = profileCount[tag] + 1 || 1;
|
|
328
|
+
controllerConfig = __assign({ id: "recommend_".concat(tag, "_").concat(profileCount[tag] - 1) }, controllerConfigBase);
|
|
329
|
+
controller = (0, create_1.createRecommendationController)({
|
|
315
330
|
url: instance.config.url,
|
|
316
331
|
controller: controllerConfig,
|
|
317
332
|
context: context,
|
|
318
333
|
mode: instance.config.mode,
|
|
319
334
|
}, { client: instance.client, tracker: instance.tracker });
|
|
335
|
+
// mark element with controller id so cleanupStaleControllers knows it's active
|
|
336
|
+
if (targetElem) {
|
|
337
|
+
targetElem.setAttribute('ss-controller-id', controller.id);
|
|
338
|
+
}
|
|
320
339
|
instance.uses.forEach(function (attachements) { return controller.use(attachements); });
|
|
321
340
|
instance.plugins.forEach(function (plugin) { return controller.plugin.apply(controller, __spreadArray([plugin.func], plugin.args, false)); });
|
|
322
341
|
instance.middleware.forEach(function (middleware) { return controller.on.apply(controller, __spreadArray([middleware.event], middleware.func, false)); });
|
|
323
|
-
|
|
324
|
-
case 2:
|
|
325
|
-
if (!!controller.store.loading) return [3 /*break*/, 4];
|
|
326
|
-
return [4 /*yield*/, controller.search()];
|
|
327
|
-
case 3:
|
|
328
|
-
_w.sent();
|
|
329
|
-
_w.label = 4;
|
|
330
|
-
case 4:
|
|
331
|
-
controller.addTargeter(instance.targeter);
|
|
342
|
+
// add controller to instantiator and global namespace
|
|
332
343
|
instance.controller[controller.config.id] = controller;
|
|
333
344
|
window.athos.controller = window.athos.controller || {};
|
|
334
345
|
window.athos.controller[controller.config.id] = controller;
|
|
335
|
-
|
|
336
|
-
|
|
346
|
+
// register targeter on the controller for element tracking
|
|
347
|
+
controller.addTargeter(targeter);
|
|
348
|
+
if (!!controller.store.loading) return [3 /*break*/, 2];
|
|
349
|
+
return [4 /*yield*/, controller.search()];
|
|
350
|
+
case 1:
|
|
351
|
+
_t.sent();
|
|
352
|
+
_t.label = 2;
|
|
353
|
+
case 2:
|
|
354
|
+
profileVars = (_s = controller.store.profile.display) === null || _s === void 0 ? void 0 : _s.templateParameters;
|
|
337
355
|
if (controller.store.error) {
|
|
338
356
|
//something went wrong
|
|
339
357
|
//err was already logged - nothing to do.
|
|
340
358
|
return [2 /*return*/];
|
|
341
359
|
}
|
|
342
360
|
if (!controller.store.profile.display.template) {
|
|
343
|
-
instance.logger.error("profile '".concat(tag, "' found on the following element is missing a template!\n").concat(
|
|
361
|
+
instance.logger.error("profile '".concat(tag, "' found on the following element is missing a template!\n").concat(scriptElem === null || scriptElem === void 0 ? void 0 : scriptElem.outerHTML));
|
|
344
362
|
return [2 /*return*/];
|
|
345
363
|
}
|
|
346
364
|
if (!profileVars) {
|
|
347
|
-
instance.logger.error("profile '".concat(tag, "' found on the following element is missing templateParameters!\n").concat(
|
|
365
|
+
instance.logger.error("profile '".concat(tag, "' found on the following element is missing templateParameters!\n").concat(scriptElem === null || scriptElem === void 0 ? void 0 : scriptElem.outerHTML));
|
|
348
366
|
return [2 /*return*/];
|
|
349
367
|
}
|
|
368
|
+
if (!targetElem) return [3 /*break*/, 4];
|
|
369
|
+
return [4 /*yield*/, renderController(instance, services, controller, targetElem, scriptElem, target)];
|
|
370
|
+
case 3:
|
|
371
|
+
_t.sent();
|
|
372
|
+
_t.label = 4;
|
|
373
|
+
case 4: return [2 /*return*/, controller];
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function renderController(instance, services, controller, targetElem, scriptElem, target) {
|
|
379
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
380
|
+
var tag, component, props, RecommendationsComponent, importPromises, importResolutions;
|
|
381
|
+
var _a, _b, _c, _d;
|
|
382
|
+
return __generator(this, function (_e) {
|
|
383
|
+
switch (_e.label) {
|
|
384
|
+
case 0:
|
|
385
|
+
// update the element with the controller id
|
|
386
|
+
if (targetElem) {
|
|
387
|
+
targetElem.setAttribute('ss-controller-id', controller.id);
|
|
388
|
+
}
|
|
389
|
+
tag = controller.config.tag;
|
|
390
|
+
component = (_b = (_a = controller.store.profile.display) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.component;
|
|
350
391
|
if (!component) {
|
|
351
|
-
instance.logger.error("profile '".concat(tag, "' found on the following element is missing a component!\n").concat(
|
|
392
|
+
instance.logger.error("profile '".concat(tag, "' found on the following element is missing a component!\n").concat(scriptElem === null || scriptElem === void 0 ? void 0 : scriptElem.outerHTML));
|
|
352
393
|
return [2 /*return*/];
|
|
353
394
|
}
|
|
354
395
|
props = {};
|
|
355
396
|
RecommendationsComponent = undefined;
|
|
356
397
|
props.className = "ss__recommendation-".concat(component.toLowerCase());
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (!(instance.config.components[component] && typeof instance.config.components[component] == 'function')) return [3 /*break*/, 6];
|
|
398
|
+
(_d = (_c = instance.config.components[component]) === null || _c === void 0 ? void 0 : _c.onTarget) === null || _d === void 0 ? void 0 : _d.call(_c, target, scriptElem, targetElem, controller);
|
|
399
|
+
if (!(instance.config.components[component] && typeof instance.config.components[component] == 'function')) return [3 /*break*/, 2];
|
|
360
400
|
return [4 /*yield*/, instance.config.components[component]()];
|
|
361
|
-
case
|
|
362
|
-
RecommendationsComponent =
|
|
363
|
-
return [3 /*break*/,
|
|
364
|
-
case
|
|
365
|
-
if (!(instance.config.components[component] && typeof instance.config.components[component] == 'object')) return [3 /*break*/,
|
|
401
|
+
case 1:
|
|
402
|
+
RecommendationsComponent = _e.sent();
|
|
403
|
+
return [3 /*break*/, 4];
|
|
404
|
+
case 2:
|
|
405
|
+
if (!(instance.config.components[component] && typeof instance.config.components[component] == 'object')) return [3 /*break*/, 4];
|
|
366
406
|
props = instance.config.components[component].props || {};
|
|
367
407
|
importPromises = [];
|
|
368
408
|
// dynamically import the component
|
|
369
409
|
importPromises.push(instance.config.components[component].component());
|
|
370
410
|
return [4 /*yield*/, Promise.all(importPromises)];
|
|
371
|
-
case
|
|
372
|
-
importResolutions =
|
|
411
|
+
case 3:
|
|
412
|
+
importResolutions = _e.sent();
|
|
373
413
|
RecommendationsComponent = importResolutions[0];
|
|
374
|
-
|
|
375
|
-
case
|
|
414
|
+
_e.label = 4;
|
|
415
|
+
case 4:
|
|
376
416
|
if (!RecommendationsComponent) {
|
|
377
|
-
instance.logger.error("profile '".concat(tag, "' found on the following element is expecting component mapping for '").concat(component, "' - verify instantiator config.\n").concat(
|
|
417
|
+
instance.logger.error("profile '".concat(tag, "' found on the following element is expecting component mapping for '").concat(component, "' - verify instantiator config.\n").concat(scriptElem === null || scriptElem === void 0 ? void 0 : scriptElem.outerHTML));
|
|
378
418
|
return [2 /*return*/];
|
|
379
419
|
}
|
|
380
420
|
setTimeout(function () {
|
|
381
|
-
|
|
382
|
-
(0, preact_1.render)((0, jsx_runtime_1.jsx)(RecommendationsComponent, __assign({ controller: controller, snap: services === null || services === void 0 ? void 0 : services.snap }, props)), injectedElem);
|
|
383
|
-
}
|
|
421
|
+
(0, preact_1.render)((0, jsx_runtime_1.jsx)(RecommendationsComponent, __assign({ controller: controller, snap: services === null || services === void 0 ? void 0 : services.snap }, props)), targetElem);
|
|
384
422
|
});
|
|
385
423
|
return [2 /*return*/];
|
|
386
424
|
}
|
package/dist/cjs/src/Snap.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { Controllers, AbstractController, SearchControllerConfig, Autocompl
|
|
|
9
9
|
import type { TrackerConfig, TrackerGlobals } from '@athoscommerce/snap-tracker';
|
|
10
10
|
import type { Target, OnTarget } from '@athoscommerce/snap-toolbox';
|
|
11
11
|
import type { UrlTranslatorConfig } from '@athoscommerce/snap-url-manager';
|
|
12
|
-
import { RecommendationInstantiator, RecommendationInstantiatorConfig } from './Instantiators/RecommendationInstantiator';
|
|
12
|
+
import type { RecommendationInstantiator, RecommendationInstantiatorConfig } from './Instantiators/RecommendationInstantiator';
|
|
13
13
|
import type { SnapControllerServices, InitialUrlConfig, SnapFeatures } from './types';
|
|
14
14
|
import type { TemplatesStore } from './Templates/Stores/TemplateStore';
|
|
15
15
|
export declare const BRANCH_COOKIE = "athosBranch";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../../src/Snap.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAgE,MAAM,6BAA6B,CAAC;AACpH,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAIjE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EACX,WAAW,EACX,kBAAkB,EAElB,sBAAsB,EACtB,4BAA4B,EAC5B,sBAAsB,EACtB,8BAA8B,EAC9B,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAmB,MAAM,6BAA6B,CAAC;AAClG,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,OAAO,EAAE,0BAA0B,EAAE,gCAAgC,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"Snap.d.ts","sourceRoot":"","sources":["../../../src/Snap.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAA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AC,CAarB;IAGF,OAAO,CAAC,iBAAiB,CAsDvB;IAEK,QAAQ;4BACM,UAAU,KAAG,IAAI;uBAsDtB,UAAU,KAAG,IAAI;MAgC/B;gBAEU,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,YAAY;CA+qBvD"}
|
package/dist/cjs/src/Snap.js
CHANGED
|
@@ -222,12 +222,14 @@ var Snap = /** @class */ (function () {
|
|
|
222
222
|
var elem = null;
|
|
223
223
|
elem = event && event.target;
|
|
224
224
|
while (Object.keys(attributes).length == 0 && elem !== null && levels <= MAX_PARENT_LEVELS) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
if (elem.attributes) {
|
|
226
|
+
Object.values(elem.attributes).forEach(function (attr) {
|
|
227
|
+
var attrName = attr.nodeName;
|
|
228
|
+
if (attributeList.indexOf(attrName) != -1) {
|
|
229
|
+
attributes[attrName] = elem && elem.getAttribute(attrName);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
231
233
|
elem = elem.parentElement;
|
|
232
234
|
levels++;
|
|
233
235
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapTemplates.d.ts","sourceRoot":"","sources":["../../../../src/Templates/SnapTemplates.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAI/B,OAAO,EAAkB,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxE,OAAO,EAAE,KAAK,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,KAAK,EAA0C,cAAc,EAAoB,MAAM,gCAAgC,CAAC;AAC/H,OAAO,KAAK,EAAE,6BAA6B,EAAoC,MAAM,6CAA6C,CAAC;AACnI,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAA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oCAAoC,CACnD,cAAc,EAAE,mBAAmB,GAAG,2BAA2B,EACjE,cAAc,EAAE,cAAc,GAC5B;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,6BAA6B,CAAA;CAAE,CAiDnD;AAED,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,mBAAmB,GAAG,2BAA2B,EAAE,cAAc,EAAE,cAAc,GAAG,UAAU,CA2I9I;AAED,wBAAgB,aAAa,CAC5B,cAAc,EAAE,mBAAmB,GAAG,2BAA2B,EACjE,cAAc,EAAE,cAAc,EAC9B,cAAc,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,gBAAgB,GAC3D,cAAc,EAAE,CAmFlB"}
|
|
@@ -124,10 +124,18 @@ var SnapTemplates = /** @class */ (function (_super) {
|
|
|
124
124
|
function SnapTemplates(config) {
|
|
125
125
|
var _this = this;
|
|
126
126
|
var _a;
|
|
127
|
+
var context = {};
|
|
128
|
+
try {
|
|
129
|
+
context = (0, snap_toolbox_1.getContext)(['editor']);
|
|
130
|
+
}
|
|
131
|
+
catch (_b) {
|
|
132
|
+
context = {};
|
|
133
|
+
}
|
|
134
|
+
var editor = context.editor;
|
|
127
135
|
var urlParams = (0, snap_toolbox_1.url)(window.location.href);
|
|
128
136
|
var editorCookieValue = snap_toolbox_1.cookies.get(exports.TEMPLATE_EDITOR_COOKIE);
|
|
129
|
-
var editUIMode = Boolean((((_a = urlParams === null || urlParams === void 0 ? void 0 : urlParams.params) === null || _a === void 0 ? void 0 : _a.query) && exports.TEMPLATE_EDITOR_UI_PARAM in urlParams.params.query) || editorCookieValue === 'ui');
|
|
130
|
-
var editMode = Boolean(editorCookieValue) || editUIMode;
|
|
137
|
+
var editUIMode = Boolean((((_a = urlParams === null || urlParams === void 0 ? void 0 : urlParams.params) === null || _a === void 0 ? void 0 : _a.query) && exports.TEMPLATE_EDITOR_UI_PARAM in urlParams.params.query) || editorCookieValue === 'ui' || (editor === null || editor === void 0 ? void 0 : editor.mode) === 'ui');
|
|
138
|
+
var editMode = Boolean(editorCookieValue) || editUIMode || Boolean((editor === null || editor === void 0 ? void 0 : editor.mode) === 'headless');
|
|
131
139
|
var templatesStore = new TemplateStore_1.TemplatesStore({ config: config, settings: { editMode: editMode } });
|
|
132
140
|
var snapConfig = createSnapConfig(config, templatesStore);
|
|
133
141
|
_this = _super.call(this, snapConfig, { templatesStore: templatesStore }) || this;
|
|
@@ -280,9 +288,9 @@ function createAutocompleteTargeters(templateConfig, templatesStore) {
|
|
|
280
288
|
}
|
|
281
289
|
// load target override from localstorage OR from the editorStore (would be better);
|
|
282
290
|
return mergedConfigs.map(function (targetConfig) {
|
|
283
|
-
var target = templatesStore.addTarget(__assign(__assign({}, targetConfig), { type: 'autocomplete' }));
|
|
291
|
+
var target = templatesStore.addTarget(__assign(__assign({}, targetConfig), { type: 'autocomplete', selector: targetConfig.selector || targetConfig.inputSelector }));
|
|
284
292
|
var targeter = {
|
|
285
|
-
selector: targetConfig.selector,
|
|
293
|
+
selector: targetConfig.selector || targetConfig.inputSelector,
|
|
286
294
|
component: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
287
295
|
var componentImportPromises;
|
|
288
296
|
return __generator(this, function (_a) {
|
|
@@ -297,12 +305,10 @@ function createAutocompleteTargeters(templateConfig, templatesStore) {
|
|
|
297
305
|
}
|
|
298
306
|
});
|
|
299
307
|
}); },
|
|
300
|
-
props: { target: target, templatesStore: templatesStore },
|
|
308
|
+
props: __assign({ target: target, templatesStore: templatesStore }, (targetConfig.selector && targetConfig.selector !== targetConfig.inputSelector ? { input: targetConfig.inputSelector } : {})),
|
|
301
309
|
hideTarget: true,
|
|
302
310
|
createControllerBeforeTargeting: templatesStore.settings.editMode,
|
|
303
311
|
};
|
|
304
|
-
if (targetConfig.inputSelector)
|
|
305
|
-
targeter.props.input = targetConfig.inputSelector;
|
|
306
312
|
return targeter;
|
|
307
313
|
});
|
|
308
314
|
}
|
|
@@ -408,7 +414,7 @@ function createSnapConfig(templateConfig, templatesStore) {
|
|
|
408
414
|
config: {
|
|
409
415
|
id: 'autocomplete',
|
|
410
416
|
plugins: createPlugins(templateConfig, templatesStore, 'autocomplete'),
|
|
411
|
-
selector: templateConfig.autocomplete.targets.map(function (target) { return target.inputSelector
|
|
417
|
+
selector: templateConfig.autocomplete.targets.map(function (target) { return target.inputSelector; }).join(', '),
|
|
412
418
|
settings: autocompleteControllerSettings,
|
|
413
419
|
},
|
|
414
420
|
targeters: createAutocompleteTargeters(templateConfig, templatesStore),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AutocompleteStoreConfigSettings, SearchStoreConfigSettings
|
|
1
|
+
import { AutocompleteStoreConfigSettings, SearchStoreConfigSettings } from '@athoscommerce/snap-store-mobx';
|
|
2
|
+
import { StorageStore } from '@athoscommerce/snap-toolbox';
|
|
2
3
|
import { TemplatesStore, TemplateTarget } from '../TemplateStore';
|
|
3
4
|
import { AutocompleteController, SearchController } from '@athoscommerce/snap-controller';
|
|
4
5
|
import type { AbstractionGroup } from '../../../types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEditorStore.d.ts","sourceRoot":"","sources":["../../../../../../src/Templates/Stores/TemplateEditor/TemplateEditorStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,yBAAyB,EAAE,YAAY,EAAe,MAAM,
|
|
1
|
+
{"version":3,"file":"TemplateEditorStore.d.ts","sourceRoot":"","sources":["../../../../../../src/Templates/Stores/TemplateEditor/TemplateEditorStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAe,MAAM,6BAA6B,CAAC;AAKxE,OAAO,EAAE,cAAc,EAAsB,cAAc,EAAgD,MAAM,kBAAkB,CAAC;AACpI,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAE1F,OAAO,KAAK,EAAE,gBA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E,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,UAsHrE;IAEF,kBAAkB,CAAC,cAAc,SAAS,gBAAgB,GAAG,sBAAsB,EAAE,UAAU,EAAE,cAAc;IAgC/G,UAAU;;;;;;IA2CV,uBAAuB,CAAC,OAAO,CAAC,EAAE,8BAA8B,GAAG,mBAAmB;CAuItF"}
|
|
@@ -24,7 +24,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.TemplateEditorStore = void 0;
|
|
27
|
-
var
|
|
27
|
+
var snap_toolbox_1 = require("@athoscommerce/snap-toolbox");
|
|
28
28
|
var mobx_1 = require("mobx");
|
|
29
29
|
var color_1 = __importDefault(require("color"));
|
|
30
30
|
var deepmerge_1 = __importDefault(require("deepmerge"));
|
|
@@ -224,7 +224,7 @@ var TemplateEditorStore = /** @class */ (function () {
|
|
|
224
224
|
// target.setComponent
|
|
225
225
|
};
|
|
226
226
|
this.templatesStore = templatesStore;
|
|
227
|
-
this.storage = new
|
|
227
|
+
this.storage = new snap_toolbox_1.StorageStore({ type: snap_toolbox_1.StorageType.local, key: TemplateStore_1.TEMPLATE_STORE_KEY });
|
|
228
228
|
this.storedState = this.storage.get('editor') || this.storedState;
|
|
229
229
|
this.initial.config = (0, deepmerge_1.default)(this.initial.config, templatesStore.config.config);
|
|
230
230
|
this.initial.controller = {}; // set when registering controllers
|