UNPKG

@wcardinal/wcardinal-geditor

Version:

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

301 lines 11.3 kB
import { __extends } from "tslib"; import { DBaseState, DButtonAmbient, DLayoutHorizontal, DLayoutVertical, DList, DListItem, DText, EShapeDataValueExtensions, EShapeDataValueType } from "@wcardinal/wcardinal-ui"; import { EDialogDataValue } from "./e-dialog-data-value"; var EEditorData = /** @class */ (function (_super) { __extends(EEditorData, _super); function EEditorData(options) { var _this = _super.call(this, options) || this; // Selection var selection = options.selection; _this._selection = selection; // Icons _this._icons = options.icons; // Layout _this.addChild(new DLayoutHorizontal({ x: "padding", width: "padding", height: "auto", children: [ _this.newTextLabel(), _this.buttonNew, _this.buttonDelete, _this.buttonBringForward, _this.buttonSendBackward ] })); _this.addChild(_this.listDataValue); // Initialize selection.on("change", function () { _this.onSelectionChange(selection); }); var listDataValue = _this.listDataValue; listDataValue.selection.on("change", function () { _this.onListDataValueSelectionChange(listDataValue); }); _this.onSelectionChange(selection); return _this; } EEditorData.prototype.newTextLabel = function () { return new DText({ weight: 1, text: { value: this.theme.getLabel() } }); }; Object.defineProperty(EEditorData.prototype, "buttonNew", { get: function () { var result = this._buttonNew; if (result == null) { result = this.newButtonNew(); this._buttonNew = result; } return result; }, enumerable: false, configurable: true }); EEditorData.prototype.newButtonNew = function () { var _this = this; return new DButtonAmbient({ width: 30, image: { source: this._icons.new }, title: this.theme.getButtonNewTitle(), on: { active: function (emitter) { _this.onButtonNewActive(emitter); } } }); }; EEditorData.prototype.onButtonNewActive = function (opener) { var _this = this; this.dialogDataValue .reset() .open(opener) .then(function (value) { if (value != null) { _this._selection.addDataValue(value); } }); }; Object.defineProperty(EEditorData.prototype, "buttonDelete", { get: function () { var result = this._buttonDelete; if (result == null) { result = this.newButtonDelete(); this._buttonDelete = result; } return result; }, enumerable: false, configurable: true }); EEditorData.prototype.newButtonDelete = function () { var _this = this; return new DButtonAmbient({ width: 30, image: { source: this._icons.delete }, title: this.theme.getButtonDeleteTitle(), state: DBaseState.DISABLED, on: { active: function () { var first = _this.listDataValue.selection.first; if (first != null) { _this._selection.removeDataValue(first); } } } }); }; EEditorData.prototype.onListDataValueSelectionChangeButtonDelete = function (listDataValue) { this.buttonDelete.state.isDisabled = listDataValue.data.selection.isEmpty(); }; Object.defineProperty(EEditorData.prototype, "buttonBringForward", { get: function () { var result = this._buttonBringForward; if (result == null) { result = this.newButtonBringForward(); this._buttonBringForward = result; } return result; }, enumerable: false, configurable: true }); EEditorData.prototype.newButtonBringForward = function () { var _this = this; return new DButtonAmbient({ width: 30, image: { source: this._icons.arrow_up }, title: this.theme.getButtonBringForwardTitle(), state: DBaseState.DISABLED, on: { active: function () { var listDataValue = _this.listDataValue; var first = listDataValue.data.selection.first; var items = listDataValue.data.items; if (first != null && items[0] !== first) { _this._selection.bringDataValueForward(first); } } } }); }; EEditorData.prototype.onListDataValueSelectionChangeButtonBringForward = function (listDataValue) { var first = listDataValue.data.selection.first; var items = listDataValue.data.items; this.buttonBringForward.state.isDisabled = first == null || items[0] === first; }; Object.defineProperty(EEditorData.prototype, "buttonSendBackward", { get: function () { var result = this._buttonSendBackward; if (result == null) { result = this.newButtonSendBackward(); this._buttonSendBackward = result; } return result; }, enumerable: false, configurable: true }); EEditorData.prototype.newButtonSendBackward = function () { var _this = this; return new DButtonAmbient({ width: 30, image: { source: this._icons.arrow_down }, title: this.theme.getButtonSendBackwardTitle(), state: DBaseState.DISABLED, on: { active: function () { var listDataValue = _this.listDataValue; var first = listDataValue.data.selection.first; var items = listDataValue.data.items; if (first != null && items[items.length - 1] !== first) { _this._selection.sendDataValueBackward(first); } } } }); }; EEditorData.prototype.onListDataValueSelectionChangeButtonSendBackward = function (listDataValue) { var first = listDataValue.data.selection.first; var items = listDataValue.data.items; this.buttonSendBackward.state.isDisabled = first == null || items[items.length - 1] === first; }; Object.defineProperty(EEditorData.prototype, "dialogDataValue", { get: function () { var result = this._dialogDataValue; if (result == null) { result = this.newDialogDataValue(); this._dialogDataValue = result; } return result; }, enumerable: false, configurable: true }); EEditorData.prototype.newDialogDataValue = function () { return new EDialogDataValue(); }; Object.defineProperty(EEditorData.prototype, "listDataValue", { get: function () { var result = this._listDataValue; if (result == null) { result = this.newListDataValue(); this._listDataValue = result; } return result; }, enumerable: false, configurable: true }); EEditorData.prototype.newListDataValue = function () { var _this = this; var result = new DList({ width: "padding", weight: 1, data: { toLabel: function (value) { var type = value.type; var as = value.as; var prefix = 0 < as.length ? "".concat(as, ": ") : ""; switch (type) { case EShapeDataValueType.BOOLEAN: case EShapeDataValueType.BOOLEAN_ARRAY: case EShapeDataValueType.NUMBER: case EShapeDataValueType.NUMBER_ARRAY: case EShapeDataValueType.STRING: case EShapeDataValueType.STRING_ARRAY: case EShapeDataValueType.OBJECT: case EShapeDataValueType.OBJECT_ARRAY: return prefix + value.id; case EShapeDataValueType.TICKER: return prefix + "Ticker ".concat(value.initial, " ms"); default: var extension = EShapeDataValueExtensions.get(type); if (extension) { return prefix + extension.label; } return prefix + "Unknown"; } } }, updater: { newItem: function (data) { return new DListItem(data, { on: { dblclick: function (e, _, item) { _this.onListDataValueDblClick(e, _, item, result); } } }); } } }); return result; }; EEditorData.prototype.onListDataValueDblClick = function (e, _, item, list) { var _this = this; var oldValue = item.value; if (oldValue != null) { var dialogDataValue = this.dialogDataValue; dialogDataValue.value = oldValue; dialogDataValue.open(item).then(function (newValue) { if (newValue != null) { _this._selection.replaceDataValue(oldValue, newValue, list); } }); } }; EEditorData.prototype.onSelectionChangeListDataValue = function (selection) { var _a; var listDataValue = this.listDataValue; listDataValue.data.items = ((_a = selection.last()) === null || _a === void 0 ? void 0 : _a.data.values) || []; this.onListDataValueSelectionChange(listDataValue); }; EEditorData.prototype.onSelectionChange = function (selection) { this.state.isDisabled = selection.isEmpty(); this.onSelectionChangeListDataValue(selection); }; EEditorData.prototype.onListDataValueSelectionChange = function (listDataValue) { this.onListDataValueSelectionChangeButtonDelete(listDataValue); this.onListDataValueSelectionChangeButtonBringForward(listDataValue); this.onListDataValueSelectionChangeButtonSendBackward(listDataValue); }; EEditorData.prototype.getType = function () { return "EEditorData"; }; return EEditorData; }(DLayoutVertical)); export { EEditorData }; //# sourceMappingURL=e-editor-data.js.map