Skip to content

Commit a93c42b

Browse files
committed
Add support for Numbers
1 parent e81efab commit a93c42b

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

src/JavaScriptSnippet.jsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "./ui/JavaScriptSnippet.css";
2-
import { createElement, useEffect, useState } from "react";
2+
import { useEffect, useState } from "react";
33

44
export function JavaScriptSnippet({ attributeList, jsCode, ...rest }) {
55
const [canRender, setCanRender] = useState(false);
@@ -45,6 +45,8 @@ export function JavaScriptSnippet({ attributeList, jsCode, ...rest }) {
4545
JSArray = JSArray.split("${" + attr.jsVarName + "}").join(attr.jsAttribute.value);
4646
} else if (Object.prototype.toString.call(attr.jsAttribute.value) === "[object Date]") {
4747
JSArray = JSArray.split("${" + attr.jsVarName + "}").join(useValue);
48+
} else if (typeof attr.jsAttribute.value === "object") {
49+
JSArray = JSArray.split("${" + attr.jsVarName + "}").join(useValue.toNumber());
4850
} else {
4951
JSArray = JSArray.split("${" + attr.jsVarName + "}").join(escape(useValue));
5052
}
@@ -70,19 +72,12 @@ export function JavaScriptSnippet({ attributeList, jsCode, ...rest }) {
7072
// JavaScript evaluation will be done in the context of the widget instance.
7173
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
7274
try {
73-
// eslint-disable-next-line space-before-function-paren
74-
(function () {
75-
// eslint-disable-next-line no-new-func
76-
Function(javaScriptString)();
77-
}.call());
75+
// eslint-disable-next-line no-new-func
76+
Function(javaScriptString)();
7877
return null;
7978
} catch (error) {
80-
console.warn("Error while evaluating javascript input.");
81-
return (
82-
<div name={widgetName} className="alert alert-danger">
83-
Error while evaluating javascript input: {error}
84-
</div>
85-
);
79+
console.warn(`${widgetName}: Error while evaluating javascript input.
80+
${error}`);
8681
}
8782
} else return null;
8883
}

src/JavaScriptSnippet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<description/>
2121
<properties>
2222
<propertyGroup caption="Object list group">
23-
<property key="jsVarName" type="string">
23+
<property key="jsVarName" type="string" required="true">
2424
<caption>Variable name</caption>
2525
<description>camelCaseName: Identifies the attribute value, this name should in the JavaScript Snippet code.</description>
2626
</property>

0 commit comments

Comments
 (0)