UNPKG

@atlaskit/mention

Version:

A React component used to display user profiles in a list for 'Mention' functionality

48 lines 2.48 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import { padArray } from '../util'; /** * This component is stateful and should be instantianted per contextIdentifiers. */ var ContextMentionResource = /*#__PURE__*/function () { function ContextMentionResource(mentionProvider, contextIdentifier) { var _this = this; _classCallCheck(this, ContextMentionResource); _defineProperty(this, "callWithContextIds", function (f, declaredArgs) { return function () { var _this$mentionProvider; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var argsLength = args ? args.length : 0; // cover the scenario where optional parameters are not passed // by passing undefined instead to keep the contextIdentifiers parameter in the right position var mentionArgs = argsLength !== declaredArgs ? padArray(args, declaredArgs - argsLength, undefined) : args; return (_this$mentionProvider = _this.mentionProvider)[f].apply(_this$mentionProvider, _toConsumableArray(mentionArgs).concat([_this.contextIdentifier])); }; }); _defineProperty(this, "callDefault", function (f) { return function () { var _this$mentionProvider2; return (_this$mentionProvider2 = _this.mentionProvider)[f].apply(_this$mentionProvider2, arguments); }; }); _defineProperty(this, "subscribe", this.callDefault('subscribe')); _defineProperty(this, "unsubscribe", this.callDefault('unsubscribe')); _defineProperty(this, "filter", this.callWithContextIds('filter', 1)); _defineProperty(this, "recordMentionSelection", this.callWithContextIds('recordMentionSelection', 1)); _defineProperty(this, "shouldHighlightMention", this.callDefault('shouldHighlightMention')); _defineProperty(this, "isFiltering", this.callDefault('isFiltering')); this.mentionProvider = mentionProvider; this.contextIdentifier = contextIdentifier; } return _createClass(ContextMentionResource, [{ key: "getContextIdentifier", value: function getContextIdentifier() { return this.contextIdentifier; } }]); }(); export { ContextMentionResource as default };