@searchspring/snap-toolbox 0.45.1 → 0.47.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,aAAK,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,aAAK,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,CAwEzG"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.getContext = void 0;
|
|
4
15
|
function getContext(evaluate, script) {
|
|
@@ -27,24 +38,21 @@ function getContext(evaluate, script) {
|
|
|
27
38
|
throw new Error('getContext: first parameter must be an array of strings');
|
|
28
39
|
}
|
|
29
40
|
var siteIdString = 'siteId';
|
|
30
|
-
var
|
|
31
|
-
// evaluate text and put into variables
|
|
32
|
-
evaluate === null || evaluate === void 0 ? void 0 : evaluate.forEach(function (name) {
|
|
33
|
-
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"));
|
|
34
|
-
variables[name] = fn();
|
|
35
|
-
});
|
|
41
|
+
var attributeVariables = {};
|
|
36
42
|
// grab element attributes and put into variables
|
|
37
43
|
Object.values(scriptElem.attributes).map(function (attr) {
|
|
38
44
|
var name = attr.nodeName;
|
|
39
45
|
if (evaluate.includes(name)) {
|
|
40
|
-
|
|
46
|
+
attributeVariables[name] = scriptElem.getAttribute(name);
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
var scriptVariables = {};
|
|
50
|
+
// evaluate text and put into variables
|
|
51
|
+
evaluate === null || evaluate === void 0 ? void 0 : evaluate.forEach(function (name) {
|
|
52
|
+
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"));
|
|
53
|
+
scriptVariables[name] = fn();
|
|
47
54
|
});
|
|
55
|
+
var variables = __assign(__assign({}, removeUndefined(attributeVariables)), removeUndefined(scriptVariables));
|
|
48
56
|
if (evaluate.includes(siteIdString)) {
|
|
49
57
|
// if we didnt find a siteId in the context, lets grab the id from the src url.
|
|
50
58
|
if (!variables[siteIdString]) {
|
|
@@ -57,3 +65,10 @@ function getContext(evaluate, script) {
|
|
|
57
65
|
return variables;
|
|
58
66
|
}
|
|
59
67
|
exports.getContext = getContext;
|
|
68
|
+
function removeUndefined(variables) {
|
|
69
|
+
Object.keys(variables).forEach(function (key) {
|
|
70
|
+
if (typeof variables[key] === 'undefined')
|
|
71
|
+
delete variables[key];
|
|
72
|
+
});
|
|
73
|
+
return variables;
|
|
74
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getContext.d.ts","sourceRoot":"","sources":["../../../src/getContext/getContext.ts"],"names":[],"mappings":"AAAA,aAAK,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,aAAK,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,CAwEzG"}
|
|
@@ -22,7 +22,15 @@ export function getContext(evaluate = [], script) {
|
|
|
22
22
|
throw new Error('getContext: first parameter must be an array of strings');
|
|
23
23
|
}
|
|
24
24
|
const siteIdString = 'siteId';
|
|
25
|
-
const
|
|
25
|
+
const attributeVariables = {};
|
|
26
|
+
// grab element attributes and put into variables
|
|
27
|
+
Object.values(scriptElem.attributes).map((attr) => {
|
|
28
|
+
const name = attr.nodeName;
|
|
29
|
+
if (evaluate.includes(name)) {
|
|
30
|
+
attributeVariables[name] = scriptElem.getAttribute(name);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const scriptVariables = {};
|
|
26
34
|
// evaluate text and put into variables
|
|
27
35
|
evaluate?.forEach((name) => {
|
|
28
36
|
const fn = new Function(`
|
|
@@ -30,20 +38,12 @@ export function getContext(evaluate = [], script) {
|
|
|
30
38
|
${scriptElem.innerHTML}
|
|
31
39
|
return ${name};
|
|
32
40
|
`);
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
// grab element attributes and put into variables
|
|
36
|
-
Object.values(scriptElem.attributes).map((attr) => {
|
|
37
|
-
const name = attr.nodeName;
|
|
38
|
-
if (evaluate.includes(name)) {
|
|
39
|
-
variables[name] = scriptElem.getAttribute(name);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
// remove undefined entries
|
|
43
|
-
Object.keys(variables).forEach((key) => {
|
|
44
|
-
if (typeof variables[key] === 'undefined')
|
|
45
|
-
delete variables[key];
|
|
41
|
+
scriptVariables[name] = fn();
|
|
46
42
|
});
|
|
43
|
+
const variables = {
|
|
44
|
+
...removeUndefined(attributeVariables),
|
|
45
|
+
...removeUndefined(scriptVariables),
|
|
46
|
+
};
|
|
47
47
|
if (evaluate.includes(siteIdString)) {
|
|
48
48
|
// if we didnt find a siteId in the context, lets grab the id from the src url.
|
|
49
49
|
if (!variables[siteIdString]) {
|
|
@@ -55,3 +55,10 @@ export function getContext(evaluate = [], script) {
|
|
|
55
55
|
}
|
|
56
56
|
return variables;
|
|
57
57
|
}
|
|
58
|
+
function removeUndefined(variables) {
|
|
59
|
+
Object.keys(variables).forEach((key) => {
|
|
60
|
+
if (typeof variables[key] === 'undefined')
|
|
61
|
+
delete variables[key];
|
|
62
|
+
});
|
|
63
|
+
return variables;
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.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": "a63e30a2be1a74dabf22063eddb28e81ef1b1aa1"
|
|
27
27
|
}
|