@searchspring/snap-toolbox 0.61.5 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,CAmFzG"}
|
|
@@ -13,7 +13,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.getContext = void 0;
|
|
15
15
|
function getContext(evaluate, script) {
|
|
16
|
-
var _a, _b, _c, _d;
|
|
16
|
+
var _a, _b, _c, _d, _e;
|
|
17
17
|
if (evaluate === void 0) { evaluate = []; }
|
|
18
18
|
if (!script || typeof script === 'string') {
|
|
19
19
|
var scripts = Array.from(document.querySelectorAll(script || 'script[id^=searchspring], script[src*="snapui.searchspring.io"]'));
|
|
@@ -47,16 +47,24 @@ function getContext(evaluate, script) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
var scriptVariables = {};
|
|
50
|
+
var scriptInnerHTML = scriptElem.innerHTML;
|
|
51
|
+
// attempt to grab inner HTML variables
|
|
52
|
+
var scriptInnerVars = (_d = scriptInnerHTML.match(/([a-zA-Z_$][a-zA-Z_$0-9]*)\s?=/g)) === null || _d === void 0 ? void 0 : _d.map(function (match) { return match.replace(/[\s=]/g, ''); });
|
|
53
|
+
var combinedVars = evaluate.concat(scriptInnerVars || []);
|
|
54
|
+
// de-dupe vars
|
|
55
|
+
var evaluateVars = combinedVars.filter(function (item, index) {
|
|
56
|
+
return combinedVars.indexOf(item) === index;
|
|
57
|
+
});
|
|
50
58
|
// evaluate text and put into variables
|
|
51
59
|
evaluate === null || evaluate === void 0 ? void 0 : evaluate.forEach(function (name) {
|
|
52
|
-
var fn = new Function("\n\t\t\tvar ".concat(
|
|
60
|
+
var fn = new Function("\n\t\t\tvar ".concat(evaluateVars.join(', '), ";\n\t\t\t").concat(scriptInnerHTML, "\n\t\t\treturn ").concat(name, ";\n\t\t"));
|
|
53
61
|
scriptVariables[name] = fn();
|
|
54
62
|
});
|
|
55
63
|
var variables = __assign(__assign({}, removeUndefined(attributeVariables)), removeUndefined(scriptVariables));
|
|
56
64
|
if (evaluate.includes(siteIdString)) {
|
|
57
65
|
// if we didnt find a siteId in the context, lets grab the id from the src url.
|
|
58
66
|
if (!variables[siteIdString]) {
|
|
59
|
-
var siteId = (
|
|
67
|
+
var siteId = (_e = script.getAttribute('src')) === null || _e === void 0 ? void 0 : _e.match(/.*snapui.searchspring.io\/([a-zA-Z0-9]{6})\//);
|
|
60
68
|
if (siteId && siteId.length > 1) {
|
|
61
69
|
variables.siteId = siteId[1];
|
|
62
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,
|
|
1
|
+
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACxB,CAAC;AAEF,wBAAgB,UAAU,CAAC,QAAQ,GAAE,MAAM,EAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,gBAAgB,CAmFzG"}
|
|
@@ -31,11 +31,19 @@ export function getContext(evaluate = [], script) {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
const scriptVariables = {};
|
|
34
|
+
const scriptInnerHTML = scriptElem.innerHTML;
|
|
35
|
+
// attempt to grab inner HTML variables
|
|
36
|
+
const scriptInnerVars = scriptInnerHTML.match(/([a-zA-Z_$][a-zA-Z_$0-9]*)\s?=/g)?.map((match) => match.replace(/[\s=]/g, ''));
|
|
37
|
+
const combinedVars = evaluate.concat(scriptInnerVars || []);
|
|
38
|
+
// de-dupe vars
|
|
39
|
+
const evaluateVars = combinedVars.filter((item, index) => {
|
|
40
|
+
return combinedVars.indexOf(item) === index;
|
|
41
|
+
});
|
|
34
42
|
// evaluate text and put into variables
|
|
35
43
|
evaluate?.forEach((name) => {
|
|
36
44
|
const fn = new Function(`
|
|
37
|
-
var ${
|
|
38
|
-
${
|
|
45
|
+
var ${evaluateVars.join(', ')};
|
|
46
|
+
${scriptInnerHTML}
|
|
39
47
|
return ${name};
|
|
40
48
|
`);
|
|
41
49
|
scriptVariables[name] = fn();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
4
4
|
"description": "Snap Toolbox",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist/**/*"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "2c9561e8b0097a44c5587bc5629068b06041385f"
|
|
27
27
|
}
|