@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
40 lines • 1.83 kB
JavaScript
import * as tslib_1 from "tslib";
import * as React from 'react';
import { PureComponent } from 'react';
import { setNodeSelection } from '../../utils';
// tslint:disable-next-line:variable-name
export default function wrapComponentWithClickArea(ReactComponent) {
return (function (_super) {
tslib_1.__extends(WrapperClickArea, _super);
function WrapperClickArea() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { selected: false };
_this.handleDocumentSelectionChange = function (anchorPos, headPos) {
var getPos = _this.props.getPos;
var nodePos = getPos();
_this.setState({
selected: nodePos >= anchorPos && nodePos < headPos
});
};
_this.onClick = function () {
var _a = _this.props, getPos = _a.getPos, view = _a.view;
setNodeSelection(view, getPos());
};
return _this;
}
WrapperClickArea.prototype.componentDidMount = function () {
var pluginState = this.props.pluginState;
pluginState.subscribe(this.handleDocumentSelectionChange);
};
WrapperClickArea.prototype.componentWillUnmount = function () {
var pluginState = this.props.pluginState;
pluginState.unsubscribe(this.handleDocumentSelectionChange);
};
WrapperClickArea.prototype.render = function () {
return (React.createElement("div", { onClick: this.onClick },
React.createElement(ReactComponent, tslib_1.__assign({}, this.props, { selected: this.state.selected }))));
};
return WrapperClickArea;
}(PureComponent));
}
//# sourceMappingURL=wrapper-click-area.js.map