@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
126 lines • 5.23 kB
JavaScript
import { __extends } from "tslib";
import { DApplications, EShapeRuntimeImpl } from "@wcardinal/wcardinal-ui";
import { Point } from "pixi.js";
import { EShapeTable } from "./e-shape-table";
import { EShapeTableCellActionValueChangeColor } from "./e-shape-table-cell-action-value-change-color";
import { EShapeTableRowSelectionType } from "./e-shape-table-row-selection";
var EShapeTableBodyRuntime = /** @class */ (function (_super) {
__extends(EShapeTableBodyRuntime, _super);
function EShapeTableBodyRuntime(shape) {
var _this = _super.call(this, shape) || this;
_this.lastRowIndex = -1;
_this.lastColumnIndex = -1;
_this.init(shape);
return _this;
}
EShapeTableBodyRuntime.prototype.init = function (shape) {
var parent = shape.parent;
if (parent instanceof EShapeTable) {
this.selection = parent.row.selection;
var rows = shape.children;
for (var i = 0, imax = rows.length; i < imax; ++i) {
var row = rows[i];
var cells = row.children;
for (var j = 0, jmax = cells.length; j < jmax; ++j) {
cells[j].action.add(new EShapeTableCellActionValueChangeColor());
}
}
}
};
EShapeTableBodyRuntime.prototype.onClick = function (shape, e) {
_super.prototype.onClick.call(this, shape, e);
// Update the selection
var selection = this.selection;
if (e != null && selection != null && selection.type !== EShapeTableRowSelectionType.NONE) {
var lastRowIndex = this.lastRowIndex;
if (0 <= lastRowIndex) {
var indices = selection.indices;
var isSingle = selection.type === EShapeTableRowSelectionType.SINGLE;
var isNotSingle = !isSingle;
var originalEvent = "data" in e ? e.data.originalEvent : e;
var ctrlKey = originalEvent.ctrlKey;
var shiftKey = originalEvent.shiftKey;
if (isSingle || indices.length <= 0 || !(isNotSingle && (ctrlKey || shiftKey))) {
selection.clearAndAdd(lastRowIndex);
}
else if (ctrlKey) {
selection.toggle(lastRowIndex);
}
else if (shiftKey) {
selection.addTo(lastRowIndex);
}
}
}
};
EShapeTableBodyRuntime.prototype.onDblClick = function (shape, e, interactionManager) {
var result = _super.prototype.onDblClick.call(this, shape, e, interactionManager);
// Focus on clicked cell
var cell = this.getCell(shape, this.lastRowIndex, this.lastColumnIndex);
if (cell != null) {
cell.focus();
}
return result;
};
EShapeTableBodyRuntime.prototype.onOut = function (shape, e) {
_super.prototype.onOut.call(this, shape, e);
// Clear highlight
var lastRowIndex = this.lastRowIndex;
if (0 <= lastRowIndex) {
this.setRowHovered(shape, lastRowIndex, false);
this.lastRowIndex = -1;
}
};
EShapeTableBodyRuntime.prototype.onCellTouched = function (shape, rowIndex, columnIndex) {
var isChanged = false;
var lastRowTouched = this.lastRowIndex;
if (lastRowTouched !== rowIndex) {
this.setRowHovered(shape, lastRowTouched, false);
this.setRowHovered(shape, rowIndex, true);
this.lastRowIndex = rowIndex;
isChanged = true;
}
var lastColumnIndex = this.lastColumnIndex;
if (lastColumnIndex !== columnIndex) {
this.lastColumnIndex = columnIndex;
isChanged = true;
}
if (isChanged) {
var cell = this.getCell(shape, rowIndex, columnIndex);
shape.title = (cell && cell.text.value) || "";
var layer = DApplications.getLayer(shape);
if (layer) {
layer.view.title = shape.title;
}
}
};
EShapeTableBodyRuntime.prototype.getRow = function (shape, index) {
var rows = shape.children;
if (0 <= index && index < rows.length) {
return rows[index];
}
return null;
};
EShapeTableBodyRuntime.prototype.getCell = function (shape, rowIndex, columnIndex) {
var row = this.getRow(shape, rowIndex);
if (row != null) {
var cells = row.children;
if (0 <= columnIndex && columnIndex < cells.length) {
return cells[columnIndex];
}
}
return null;
};
EShapeTableBodyRuntime.prototype.setRowHovered = function (shape, index, isHovered) {
var row = this.getRow(shape, index);
if (row != null) {
var cells = row.children;
for (var i = 0, imax = cells.length; i < imax; ++i) {
cells[i].state.isHovered = isHovered;
}
}
};
EShapeTableBodyRuntime.WORK_POINT = new Point();
return EShapeTableBodyRuntime;
}(EShapeRuntimeImpl));
export { EShapeTableBodyRuntime };
//# sourceMappingURL=e-shape-table-body-runtime.js.map