choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
150 lines (125 loc) • 4.3 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import getOffset from '../utils/getOffset';
var SuggestionPortal =
/*#__PURE__*/
function (_Component) {
_inherits(SuggestionPortal, _Component);
var _super = _createSuper(SuggestionPortal);
function SuggestionPortal() {
var _this;
_classCallCheck(this, SuggestionPortal);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "matchDecorates", function (props) {
var callbacks = props.callbacks,
suggestionRegex = props.suggestionRegex,
decoratedText = props.decoratedText;
var matches = suggestionRegex.exec(decoratedText);
_this.trigger = matches[2];
_this.updatePortalPosition(_this.props);
callbacks.setEditorState(callbacks.getEditorState());
});
return _this;
}
_createClass(SuggestionPortal, [{
key: "componentWillMount",
value: function componentWillMount() {
this.matchDecorates(this.props);
}
}, {
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
if (nextProps.decoratedText !== this.props.decoratedText) {
this.matchDecorates(nextProps);
}
this.updatePortalPosition(nextProps);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
var _this$props = this.props,
offsetKey = _this$props.offsetKey,
mentionStore = _this$props.mentionStore;
mentionStore.inActiveSuggestion({
offsetKey: offsetKey
});
}
}, {
key: "updatePortalPosition",
value: function updatePortalPosition(props) {
var _this2 = this;
var offsetKey = props.offsetKey,
mentionStore = props.mentionStore;
mentionStore.updateSuggestion({
offsetKey: offsetKey,
trigger: this.trigger,
position: function position() {
var element = _this2.searchPortal;
var rect = getOffset(element);
return {
left: rect.left,
top: rect.top,
width: element.offsetWidth,
height: element.offsetHeight
};
}
});
}
}, {
key: "render",
value: function render() {
var _this3 = this;
return React.createElement("span", {
ref: function ref(node) {
_this3.searchPortal = node;
},
style: this.props.style
}, this.props.children);
}
}]);
return SuggestionPortal;
}(Component);
_defineProperty(SuggestionPortal, "propTypes", {
offsetKey: PropTypes.any,
mentionStore: PropTypes.object,
decoratedText: PropTypes.string,
children: PropTypes.any,
callbacks: PropTypes.any,
suggestionRegex: PropTypes.any
});
export { SuggestionPortal as default };
//# sourceMappingURL=SuggestionPortal.react.js.map