@nwebui/react-niagara-px
Version:
React Niagara Px View
46 lines • 1.46 kB
JavaScript
import Converter from "./Converter";
export default class IEnumToSimple extends Converter {
constructor(nativeConverter) {
super(nativeConverter);
}
convert(widget, target) {
if (!target.isComplex()) {
console.warn("IEnumToSimple for non complex not implemented");
return;
}
const converter = this.nativeConverter;
const name = converter.name();
const v = target.get("out", "value");
const map = new EnumToSimpleMap(converter.get("map") + "");
const mappedValue = map.map(v.ordinal);
const image = widget.get(name);
widget.set(name, image.decodeFromString(mappedValue));
}
}
class EnumToSimpleMap {
type;
mapping = {};
default = "";
constructor(mapstr) {
const i = mapstr.indexOf(" ");
this.type = mapstr.substring(0, i);
const maps = mapstr
.substring(i + 1)
.split(";")
.filter((x) => x);
maps.forEach((m) => {
const ss = m.split("=");
if (ss[0] === "default") {
this.default = ss[1];
}
else {
const ss2 = ss[0].split(",");
ss2.forEach((s) => (this.mapping[s] = ss[1]));
}
});
}
map(v) {
return this.mapping[v] || this.default;
}
}
//# sourceMappingURL=IEnumToSimple.js.map