vue-blox-expressions
Version:
Adds scripting support to vue-blox.
91 lines (90 loc) • 2.88 kB
JavaScript
var w = Object.defineProperty;
var m = (n, e, t) => e in n ? w(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var l = (n, e, t) => (m(n, typeof e != "symbol" ? e + "" : e, t), t);
class b {
constructor(e) {
l(this, "parser");
this.parser = e;
}
run({ context: e, key: t, value: r, variables: o, buildContext: c }) {
const s = "compute:";
if (!t.startsWith(s))
return;
const a = t.substring(s.length, t.length);
if (a.length === 0)
throw new Error("The value for the prop name for compute must be a string with length > 0.");
const i = JSON.parse(JSON.stringify(o ?? {})), u = this.evaluate(r, i);
e.setProp({
propName: a,
value: u
});
}
evaluate(e, t) {
if (typeof e == "string") {
const r = e;
if (/^__proto__|prototype|constructor$/.test(r))
throw new Error(`The call to parser.evaluate() for value ${e} was aborted because prototype access was detected.`);
try {
return this.parser.evaluate(r, t);
} catch (o) {
throw new Error(`The call to parser.evaluate() for value ${e} threw the error: ${o}`);
}
} else if (typeof e == "object" && Array.isArray(e)) {
const r = [];
for (let o = 0; o < e.length; o += 1) {
const c = e[o], s = this.evaluate(c, t);
r.push(s);
}
return r;
} else if (typeof e == "object") {
const r = {}, o = Object.keys(e);
for (let c = 0; c < o.length; c += 1) {
const s = o[c], a = e[s], i = this.evaluate(a, t);
r[s] = i;
}
return r;
}
}
}
function d({ parser: n }) {
return new b(n);
}
class v {
constructor(e) {
l(this, "parser");
this.parser = e;
}
run({ context: e, key: t, value: r, variables: o, buildContext: c }) {
const s = "event:";
if (!t.startsWith(s))
return;
const a = t.substring(s.length, t.length);
if (a.length === 0)
throw new Error("The value for the prop name for event must be a string with length > 0.");
const i = r, u = `on${a.charAt(0).toUpperCase()}${a.slice(1)}`, h = JSON.parse(JSON.stringify(o ?? {}));
e.setProp({
propName: u,
value: (...f) => {
if (/^__proto__|prototype|constructor$/.test(i))
throw new Error(`The call to parser.evaluate() for value ${r} was aborted because prototype access was detected.`);
Object.assign(h, f);
try {
this.parser.functions.setVariable = (p, g) => {
o[p] = g;
}, this.parser.evaluate(i, h);
} catch (p) {
throw new Error(`The call to parser.evaluate() for value ${r} threw the error: ${p}`);
}
}
});
}
}
function $({ parser: n }) {
return new v(n);
}
export {
b as BloxPluginCompute,
v as BloxPluginEvent,
d as getPluginCompute,
$ as getPluginEvent
};