@searchspring/snap-toolbox
Advanced tools
Comparing version 0.61.5 to 0.62.0
@@ -16,3 +16,3 @@ "use strict"; | ||
function getContext(evaluate, script) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
if (evaluate === void 0) { evaluate = []; } | ||
@@ -51,5 +51,13 @@ if (!script || typeof script === 'string') { | ||
var scriptVariables = {}; | ||
var scriptInnerHTML = scriptElem.innerHTML; | ||
// attempt to grab inner HTML variables | ||
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, ''); }); | ||
var combinedVars = evaluate.concat(scriptInnerVars || []); | ||
// de-dupe vars | ||
var evaluateVars = combinedVars.filter(function (item, index) { | ||
return combinedVars.indexOf(item) === index; | ||
}); | ||
// evaluate text and put into variables | ||
evaluate === null || evaluate === void 0 ? void 0 : evaluate.forEach(function (name) { | ||
var fn = new Function("\n\t\t\tvar ".concat(evaluate.join(', '), ";\n\t\t\t").concat(scriptElem.innerHTML, "\n\t\t\treturn ").concat(name, ";\n\t\t")); | ||
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")); | ||
scriptVariables[name] = fn(); | ||
@@ -61,3 +69,3 @@ }); | ||
if (!variables[siteIdString]) { | ||
var siteId = (_d = script.getAttribute('src')) === null || _d === void 0 ? void 0 : _d.match(/.*snapui.searchspring.io\/([a-zA-Z0-9]{6})\//); | ||
var siteId = (_e = script.getAttribute('src')) === null || _e === void 0 ? void 0 : _e.match(/.*snapui.searchspring.io\/([a-zA-Z0-9]{6})\//); | ||
if (siteId && siteId.length > 1) { | ||
@@ -64,0 +72,0 @@ variables.siteId = siteId[1]; |
@@ -34,7 +34,15 @@ export function getContext(evaluate = [], script) { | ||
const scriptVariables = {}; | ||
const scriptInnerHTML = scriptElem.innerHTML; | ||
// attempt to grab inner HTML variables | ||
const scriptInnerVars = scriptInnerHTML.match(/([a-zA-Z_$][a-zA-Z_$0-9]*)\s?=/g)?.map((match) => match.replace(/[\s=]/g, '')); | ||
const combinedVars = evaluate.concat(scriptInnerVars || []); | ||
// de-dupe vars | ||
const evaluateVars = combinedVars.filter((item, index) => { | ||
return combinedVars.indexOf(item) === index; | ||
}); | ||
// evaluate text and put into variables | ||
evaluate?.forEach((name) => { | ||
const fn = new Function(` | ||
var ${evaluate.join(', ')}; | ||
${scriptElem.innerHTML} | ||
var ${evaluateVars.join(', ')}; | ||
${scriptInnerHTML} | ||
return ${name}; | ||
@@ -41,0 +49,0 @@ `); |
{ | ||
"name": "@searchspring/snap-toolbox", | ||
"version": "0.61.5", | ||
"version": "0.62.0", | ||
"description": "Snap Toolbox", | ||
@@ -26,3 +26,3 @@ "main": "dist/cjs/index.js", | ||
], | ||
"gitHead": "bae1305742558d1736e535d77a76da7b845bc046" | ||
"gitHead": "2c9561e8b0097a44c5587bc5629068b06041385f" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
76409
1496