@wcardinal/wcardinal-geditor
Version:
WebGL-based graphic editor, tester and viewer for supervisory systems
302 lines • 10.8 kB
JavaScript
import { __extends } from "tslib";
import { DControllers, DTableDataSelectionType } from "@wcardinal/wcardinal-ui";
import { utils } from "pixi.js";
import { ECommandShapeSelect } from "../command/e-command-shape-select";
var COMPARATOR = function (a, b) {
return a[0] - b[0];
};
var EEditorTreeSelection = /** @class */ (function (_super) {
__extends(EEditorTreeSelection, _super);
function EEditorTreeSelection(parent, selection) {
var _this = _super.call(this) || this;
_this._parent = parent;
_this._selection = selection;
return _this;
}
Object.defineProperty(EEditorTreeSelection.prototype, "parent", {
get: function () {
return this._parent;
},
enumerable: false,
configurable: true
});
Object.defineProperty(EEditorTreeSelection.prototype, "indices", {
get: function () {
var selection = this._selection;
var result = [];
this._parent.each(function (row, index) {
if (selection.contains(row)) {
result.push(index);
}
});
return result;
},
enumerable: false,
configurable: true
});
Object.defineProperty(EEditorTreeSelection.prototype, "rows", {
get: function () {
var selection = this._selection;
var result = [];
this._parent.each(function (row, index) {
if (selection.contains(row)) {
result.push(row);
}
});
return result;
},
enumerable: false,
configurable: true
});
Object.defineProperty(EEditorTreeSelection.prototype, "type", {
get: function () {
return DTableDataSelectionType.MULTIPLE;
},
enumerable: false,
configurable: true
});
Object.defineProperty(EEditorTreeSelection.prototype, "first", {
get: function () {
var row = this._selection.first();
if (row) {
return this.toIndex(row);
}
return null;
},
enumerable: false,
configurable: true
});
Object.defineProperty(EEditorTreeSelection.prototype, "last", {
get: function () {
var row = this._selection.last();
if (row) {
return this.toIndex(row);
}
return null;
},
enumerable: false,
configurable: true
});
EEditorTreeSelection.prototype.onNodeChange = function (nodes) {
// DO NOTHING
};
EEditorTreeSelection.prototype.toggle = function (rowIndex) {
var row = this._parent.get(rowIndex);
if (row) {
var selection = this._selection;
var before = selection.store();
selection.toggle(row);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
};
EEditorTreeSelection.prototype.add = function (rowIndex) {
var row = this._parent.get(rowIndex);
if (row) {
var selection = this._selection;
if (!selection.contains(row)) {
var before = selection.store();
selection.toggle(row);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
}
};
EEditorTreeSelection.prototype.toIndex = function (target) {
var result = null;
this._parent.each(function (row, index) {
if (target === row) {
result = index;
return false;
}
return true;
});
return result;
};
EEditorTreeSelection.prototype.addTo = function (rowIndex) {
var last = this._selection.last();
if (last != null) {
var index = this.toIndex(last);
if (index != null) {
this.addRange(index, false, rowIndex, true);
}
}
};
EEditorTreeSelection.prototype.addRange = function (from, includeFrom, to, includeTo) {
var rows = [];
var parent = this._parent;
var selection = this._selection;
if (from < to) {
parent.each(function (row) {
if (!selection.contains(row)) {
rows.push(row);
}
}, from + (includeFrom ? 0 : 1), to + (includeTo ? 1 : 0));
}
else {
parent.each(function (row) {
if (!selection.contains(row)) {
rows.push(row);
}
}, to + (includeTo ? 0 : 1), from + (includeFrom ? 1 : 0));
}
if (0 < rows.length) {
var before = selection.store();
selection.addAll(rows);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
};
EEditorTreeSelection.prototype.addAll = function (rowIndices) {
if (0 < rowIndices.length) {
var rows = [];
var parent_1 = this._parent;
var selection = this._selection;
for (var i = 0, imax = rowIndices.length; i < imax; ++i) {
var row = parent_1.get(rowIndices[i]);
if (row && !selection.contains(row)) {
rows.push(row);
}
}
if (0 < rows.length) {
var before = selection.store();
selection.addAll(rows);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
}
};
EEditorTreeSelection.prototype.contains = function (rowIndex) {
var row = this._parent.get(rowIndex);
if (row) {
return this._selection.contains(row);
}
return false;
};
EEditorTreeSelection.prototype.remove = function (rowIndex) {
var row = this._parent.get(rowIndex);
if (row) {
var selection = this._selection;
if (selection.contains(row)) {
var before = selection.store();
selection.remove(row);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
}
};
EEditorTreeSelection.prototype.clear = function () {
var selection = this._selection;
if (!selection.isEmpty()) {
var before = selection.store();
selection.clear();
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
};
EEditorTreeSelection.prototype.clearAndAdd = function (rowIndex) {
var row = this._parent.get(rowIndex);
if (row) {
var selection = this._selection;
if (selection.contains(row)) {
if (1 < selection.size()) {
var before = selection.store();
selection.set(row);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
else {
selection.focus();
}
}
else {
var before = selection.store();
selection.set(row);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
}
};
EEditorTreeSelection.prototype.clearAndAddAll = function (rowIndices) {
var selection = this._selection;
if (!selection.isEmpty() || 0 < rowIndices.length) {
var rows = [];
var parent_2 = this._parent;
for (var i = 0, imax = rowIndices.length; i < imax; ++i) {
var row = parent_2.get(rowIndices[i]);
if (row) {
rows.push(row);
}
}
var before = selection.store();
selection.clearAndAddAll(rows);
selection.focus();
var after = selection.store();
DControllers.getCommandController().push(new ECommandShapeSelect(before, after, selection));
}
};
EEditorTreeSelection.prototype.shift = function (rowIndex, amount) {
// DO NOTHING
};
EEditorTreeSelection.prototype.size = function () {
return this._selection.size();
};
EEditorTreeSelection.prototype.isEmpty = function () {
return this._selection.isEmpty();
};
EEditorTreeSelection.prototype.each = function (iteratee) {
var selection = this._selection;
this._parent.each(function (row, index) {
if (selection.contains(row)) {
if (iteratee(index) === false) {
return false;
}
}
return true;
});
};
EEditorTreeSelection.prototype.toArray = function () {
var selection = this._selection;
var result = [];
this._parent.each(function (row, index) {
if (selection.contains(row)) {
result.push([index, row]);
}
});
return result;
};
EEditorTreeSelection.prototype.toSortedArray = function () {
return this.toArray().sort(COMPARATOR);
};
EEditorTreeSelection.prototype.toObject = function () {
var selection = this._selection;
var result = {};
this._parent.each(function (row, index) {
if (selection.contains(row)) {
result[index] = row;
}
});
return result;
};
EEditorTreeSelection.prototype.toMap = function () {
var selection = this._selection;
var result = new Map();
this._parent.each(function (row, index) {
if (selection.contains(row)) {
result.set(index, row);
}
});
return result;
};
return EEditorTreeSelection;
}(utils.EventEmitter));
export { EEditorTreeSelection };
//# sourceMappingURL=e-editor-tree-selection.js.map