UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

43 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = require("react"); var react_1 = require("react"); var utils_1 = require("../../utils"); // tslint:disable-next-line:variable-name 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; utils_1.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; }(react_1.PureComponent)); } exports.default = wrapComponentWithClickArea; //# sourceMappingURL=wrapper-click-area.js.map