UNPKG

@wcardinal/wcardinal-geditor

Version:

WebGL-based graphic editor, tester and viewer for supervisory systems

64 lines 2.52 kB
import { NumberFormatters } from "@wcardinal/wcardinal-ui"; import { EShapeTableColumnValueType } from "./e-shape-table-column-value"; var toValueDefault = function (row, index) { return row[index]; }; var fromValueDefault = function (row, index, rows, value) { row[index] = value; }; var formatterDefault = function (value) { return String(value); }; var EShapeTableColumnValueRuntime = /** @class */ (function () { function EShapeTableColumnValueRuntime(value) { this.toValue = this.parseToValue(value.getter, toValueDefault, '""'); this.fromValue = this.parseFromValue(value.setter, fromValueDefault); if (value.type === EShapeTableColumnValueType.TEXT) { this.formatter = this.parseFormat(value.format, formatterDefault, '""'); } else { var format = value.format; if (0 < format.trim().length) { var formatter_1 = NumberFormatters.create(format); this.formatter = function (v) { return formatter_1.format(v, 1); }; } else { this.formatter = formatterDefault; } } } EShapeTableColumnValueRuntime.prototype.parseToValue = function (expression, def, defLiteral) { if (expression.trim().length <= 0) { return def; } try { return Function("row", "index", "rows", "try{ return (".concat(expression, "); } catch( e ) { return ").concat(defLiteral, "; }")); } catch (_a) { return def; } }; EShapeTableColumnValueRuntime.prototype.parseFromValue = function (expression, def) { if (expression.trim().length <= 0) { return def; } try { return Function("row", "index", "rows", "value", "try{ ".concat(expression, " = value; } catch( e ) {}")); } catch (_a) { return def; } }; EShapeTableColumnValueRuntime.prototype.parseFormat = function (expression, def, defLiteral) { if (expression.trim().length <= 0) { return def; } try { return Function("value", "index", "try{ return (".concat(expression, "); } catch( e ) { return ").concat(defLiteral, "; }")); } catch (_a) { return def; } }; return EShapeTableColumnValueRuntime; }()); export { EShapeTableColumnValueRuntime }; //# sourceMappingURL=e-shape-table-column-value-runtime.js.map