choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
207 lines (164 loc) • 6.36 kB
JavaScript
;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
var _icon = _interopRequireDefault(require("../icon"));
var _editorMention = _interopRequireWildcard(require("../rc-components/editor-mention"));
var _configure = require("../configure");
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 = (0, _getPrototypeOf2["default"])(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return (0, _possibleConstructorReturn2["default"])(this, result);
};
}
var Mention =
/*#__PURE__*/
function (_Component) {
(0, _inherits2["default"])(Mention, _Component);
var _super = _createSuper(Mention);
function Mention(props) {
var _this;
(0, _classCallCheck2["default"])(this, Mention);
_this = _super.call(this, props);
_this.onSearchChange = function (value, prefix) {
var onSearchChange = _this.props.onSearchChange;
if (onSearchChange) {
return onSearchChange(value, prefix);
}
return _this.defaultSearchChange(value);
};
_this.onFocus = function (ev) {
_this.setState({
focus: true
});
var onFocus = _this.props.onFocus;
if (onFocus) {
onFocus(ev);
}
};
_this.onBlur = function (ev) {
_this.setState({
focus: false
});
var onBlur = _this.props.onBlur;
if (onBlur) {
onBlur(ev);
}
};
_this.focus = function () {
_this.mentionEle._editor.focusEditor();
};
_this.mentionRef = function (ele) {
_this.mentionEle = ele;
};
_this.state = {
suggestions: props.suggestions,
focus: false
};
return _this;
}
(0, _createClass2["default"])(Mention, [{
key: "componentWillReceiveProps",
value: function componentWillReceiveProps(nextProps) {
var suggestions = nextProps.suggestions;
var props = this.props;
if (!(0, _isEqual["default"])(suggestions, props.suggestions)) {
this.setState({
suggestions: suggestions
});
}
}
}, {
key: "defaultSearchChange",
value: function defaultSearchChange(value) {
var searchValue = value.toLowerCase();
var suggestions = this.props.suggestions;
var filteredSuggestions = (suggestions || []).filter(function (suggestion) {
if (suggestion.type && suggestion.type === _editorMention.Nav) {
return suggestion.props.value ? suggestion.props.value.toLowerCase().indexOf(searchValue) !== -1 : true;
}
return suggestion.toLowerCase().indexOf(searchValue) !== -1;
});
this.setState({
suggestions: filteredSuggestions
});
}
}, {
key: "render",
value: function render() {
var _classNames;
var _this$props = this.props,
_this$props$className = _this$props.className,
className = _this$props$className === void 0 ? '' : _this$props$className,
customizePrefixCls = _this$props.prefixCls,
loading = _this$props.loading,
placement = _this$props.placement,
notFoundContent = _this$props.notFoundContent,
onChange = _this$props.onChange;
var prefixCls = (0, _configure.getPrefixCls)('mention', customizePrefixCls);
var _this$state = this.state,
suggestions = _this$state.suggestions,
focus = _this$state.focus;
var cls = (0, _classnames["default"])(className, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-active"), focus), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-placement-top"), placement === 'top'), _classNames));
var notFound = loading ? _react["default"].createElement(_icon["default"], {
type: "loading"
}) : notFoundContent;
return _react["default"].createElement(_editorMention["default"], (0, _extends2["default"])({}, this.props, {
prefixCls: prefixCls,
className: cls,
ref: this.mentionRef,
onSearchChange: this.onSearchChange,
onChange: onChange,
onFocus: this.onFocus,
onBlur: this.onBlur,
suggestions: suggestions,
notFoundContent: notFound
}));
}
}]);
return Mention;
}(_react.Component);
exports["default"] = Mention;
Mention.displayName = 'Mention';
Mention.getMentions = _editorMention.getMentions;
Mention.defaultProps = {
notFoundContent: '无匹配结果,轻敲空格完成输入',
loading: false,
multiLines: false,
placement: 'bottom'
};
Mention.Nav = _editorMention.Nav;
Mention.toString = _editorMention.toString;
Mention.toContentState = _editorMention.toEditorState;
//# sourceMappingURL=index.js.map