react-annotation
Version:
React components for annotating SVG elements
167 lines (136 loc) • 6.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _Annotation = _interopRequireDefault(require("./Annotation"));
var _classnames = _interopRequireDefault(require("./classnames"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var EditableAnnotation =
/*#__PURE__*/
function (_React$Component) {
_inherits(EditableAnnotation, _React$Component);
function EditableAnnotation() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, EditableAnnotation);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(EditableAnnotation)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
x: 0,
y: 0,
dx: 0,
dy: 0
});
return _this;
}
_createClass(EditableAnnotation, [{
key: "componentWillMount",
value: function componentWillMount() {
this.setState({
x: this.props.x,
y: this.props.y,
dx: this.props.dx,
dy: this.props.dy
});
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
this.setState({
x: nextProps.x,
y: nextProps.y,
dx: nextProps.dx,
dy: nextProps.dy
});
}
}, {
key: "getData",
value: function getData() {
return Object.assign({}, this.props, this.state);
}
}, {
key: "dragEnd",
value: function dragEnd() {
if (this.props.onDragEnd) {
this.props.onDragEnd(this.getData());
}
}
}, {
key: "dragStart",
value: function dragStart() {
if (this.props.onDragStart) {
this.props.onDragStart(this.getData());
}
}
}, {
key: "dragSubject",
value: function dragSubject(event, data) {
var _this2 = this;
this.setState({
x: this.state.x + data.deltaX,
y: this.state.y + data.deltaY
}, function () {
if (_this2.props.onDrag) _this2.props.onDrag(_this2.getData());
});
}
}, {
key: "dragConnectorSettings",
value: function dragConnectorSettings(event, data) {
var _this3 = this;
this.setState(data, function () {
if (_this3.props.onDrag) _this3.props.onDrag(_this3.getData());
});
}
}, {
key: "dragSubjectSettings",
value: function dragSubjectSettings(event, data) {
var _this4 = this;
this.setState(data, function () {
if (_this4.props.onDrag) _this4.props.onDrag(_this4.getData());
});
}
}, {
key: "dragNote",
value: function dragNote(event, data) {
var _this5 = this;
this.setState({
dx: this.state.dx + data.deltaX,
dy: this.state.dy + data.deltaY
}, function () {
if (_this5.props.onDrag) _this5.props.onDrag(_this5.getData());
});
}
}, {
key: "render",
value: function render() {
var cleanedProps = Object.assign({}, this.props, _objectSpread({}, this.state, {
dragSubject: this.dragSubject.bind(this),
dragNote: this.dragNote.bind(this),
dragSubjectSettings: this.dragSubjectSettings.bind(this),
dragConnectorSettings: this.dragConnectorSettings.bind(this),
dragEnd: this.dragEnd.bind(this),
dragStart: this.dragStart.bind(this),
editMode: true,
className: (0, _classnames.default)(this.props.className, "editable")
}));
return _react.default.createElement(_Annotation.default, cleanedProps);
}
}]);
return EditableAnnotation;
}(_react.default.Component);
exports.default = EditableAnnotation;