core-graphics
Version:
A core library for creating shape-based graphic editors
118 lines (113 loc) • 5.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EditorShapeEventType = undefined;
exports.isEditorShapeEvent = isEditorShapeEvent;
exports.isAddShapeEditorEvent = isAddShapeEditorEvent;
exports.isRemoveShapesEvent = isRemoveShapesEvent;
exports.isRemoveSelectedShapesEvent = isRemoveSelectedShapesEvent;
exports.isRemoveAllShapesEvent = isRemoveAllShapesEvent;
exports.isUpdateShapeCustomParamsEvent = isUpdateShapeCustomParamsEvent;
exports.isMoveSelectedShapesEvent = isMoveSelectedShapesEvent;
exports.isSendShapesBackwardEvent = isSendShapesBackwardEvent;
exports.isSendShapesForwardEvent = isSendShapesForwardEvent;
exports.isSendShapesToBackEvent = isSendShapesToBackEvent;
exports.isSendShapesToFrontEvent = isSendShapesToFrontEvent;
exports.isChangeShapesOrderEvent = isChangeShapesOrderEvent;
exports.addShape = addShape;
exports.removeShapes = removeShapes;
exports.removeSelectedShapes = removeSelectedShapes;
exports.removeAllShapes = removeAllShapes;
exports.updateShapeCustomParams = updateShapeCustomParams;
exports.moveSelectedShapes = moveSelectedShapes;
exports.sendShapesBackward = sendShapesBackward;
exports.sendShapesForward = sendShapesForward;
exports.sendShapesToBack = sendShapesToBack;
exports.sendShapesToFront = sendShapesToFront;
var _editorEvents = require("../editor-events");
var EditorShapeEventType = exports.EditorShapeEventType = undefined;
(function (EditorShapeEventType) {
EditorShapeEventType[EditorShapeEventType["AddShape"] = 0] = "AddShape";
EditorShapeEventType[EditorShapeEventType["RemoveShapes"] = 1] = "RemoveShapes";
EditorShapeEventType[EditorShapeEventType["RemoveSelectedShapes"] = 2] = "RemoveSelectedShapes";
EditorShapeEventType[EditorShapeEventType["RemoveAllShapes"] = 3] = "RemoveAllShapes";
EditorShapeEventType[EditorShapeEventType["UpdateCustomParams"] = 4] = "UpdateCustomParams";
EditorShapeEventType[EditorShapeEventType["MoveSelectedShapes"] = 5] = "MoveSelectedShapes";
EditorShapeEventType[EditorShapeEventType["SendShapesBackward"] = 6] = "SendShapesBackward";
EditorShapeEventType[EditorShapeEventType["SendShapesForward"] = 7] = "SendShapesForward";
EditorShapeEventType[EditorShapeEventType["SendShapesToBack"] = 8] = "SendShapesToBack";
EditorShapeEventType[EditorShapeEventType["SendShapesToFront"] = 9] = "SendShapesToFront";
})(EditorShapeEventType || (exports.EditorShapeEventType = EditorShapeEventType = {}));
function isEditorShapeEvent(base) {
return base.type === _editorEvents.EditorEventType.Shape;
}
function isAddShapeEditorEvent(base) {
return base.subType === EditorShapeEventType.AddShape;
}
function isRemoveShapesEvent(base) {
return base.subType === EditorShapeEventType.RemoveShapes;
}
function isRemoveSelectedShapesEvent(base) {
return base.subType === EditorShapeEventType.RemoveSelectedShapes;
}
function isRemoveAllShapesEvent(base) {
return base.subType === EditorShapeEventType.RemoveAllShapes;
}
function isUpdateShapeCustomParamsEvent(base) {
return base.subType === EditorShapeEventType.UpdateCustomParams;
}
function isMoveSelectedShapesEvent(base) {
return base.subType === EditorShapeEventType.MoveSelectedShapes;
}
function isSendShapesBackwardEvent(base) {
return base.subType === EditorShapeEventType.SendShapesBackward;
}
function isSendShapesForwardEvent(base) {
return base.subType === EditorShapeEventType.SendShapesForward;
}
function isSendShapesToBackEvent(base) {
return base.subType === EditorShapeEventType.SendShapesToBack;
}
function isSendShapesToFrontEvent(base) {
return base.subType === EditorShapeEventType.SendShapesToFront;
}
function isChangeShapesOrderEvent(base) {
return isSendShapesBackwardEvent(base) || isSendShapesForwardEvent(base) || isSendShapesToBackEvent(base) || isSendShapesToFrontEvent(base);
}
function evFact(subType, payload) {
return { type: _editorEvents.EditorEventType.Shape, subType: subType, payload: payload };
}
function addShape(shapeData, params) {
var _ref = params || {};
var _ref$selectWhenAdded = _ref.selectWhenAdded;
var selectWhenAdded = _ref$selectWhenAdded === undefined ? false : _ref$selectWhenAdded;
return evFact(EditorShapeEventType.AddShape, { shapeData: shapeData, selectWhenAdded: selectWhenAdded });
}
function removeShapes(ids) {
return evFact(EditorShapeEventType.RemoveShapes, { ids: ids });
}
function removeSelectedShapes() {
return { type: _editorEvents.EditorEventType.Shape, subType: EditorShapeEventType.RemoveSelectedShapes };
}
function removeAllShapes() {
return { type: _editorEvents.EditorEventType.Shape, subType: EditorShapeEventType.RemoveAllShapes };
}
function updateShapeCustomParams(id, value) {
return evFact(EditorShapeEventType.UpdateCustomParams, { id: id, value: value });
}
function moveSelectedShapes(dx, dy) {
return evFact(EditorShapeEventType.MoveSelectedShapes, { dx: dx, dy: dy });
}
function sendShapesBackward(ids) {
return evFact(EditorShapeEventType.SendShapesBackward, { ids: ids });
}
function sendShapesForward(ids) {
return evFact(EditorShapeEventType.SendShapesForward, { ids: ids });
}
function sendShapesToBack(ids) {
return evFact(EditorShapeEventType.SendShapesToBack, { ids: ids });
}
function sendShapesToFront(ids) {
return evFact(EditorShapeEventType.SendShapesToFront, { ids: ids });
}