UNPKG

@uimkit/uikit-react

Version:

<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>

88 lines (81 loc) 6.01 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var React = require('react'); var EmojiPicker = require('./EmojiPicker.js'); var index = require('../Plugins/index.js'); var useUploadElement = require('./hooks/useUploadElement.js'); var TranslationContext = require('../../context/TranslationContext.js'); require('../../context/UIKitContext.js'); require('../../context/ComponentContext.js'); require('../../context/ChatActionContext.js'); var MessageInputContext = require('../../context/MessageInputContext.js'); require('../../context/UIMessageContext.js'); var ChatStateContext = require('../../context/ChatStateContext.js'); var Icon = require('../Icon/Icon.js'); var type = require('../Icon/type.js'); var models = require('../../types/models.js'); require('../../types/events.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var React__default = /*#__PURE__*/_interopDefaultLegacy(React); function InputPluginsDefault() { var _a, _b, _c, _d, _e, _f, _g; var _h = MessageInputContext.useMessageInputContext('UIMessageInputDefault'), sendUploadMessage = _h.sendUploadMessage, propsPluginConfig = _h.pluginConfig; var UIMessageInputConfig = ChatStateContext.useChatStateContext().UIMessageInputConfig; var propPlugins = (propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.plugins) || ((_a = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _a === void 0 ? void 0 : _a.plugins) || []; var showNumber = (propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.showNumber) || ((_b = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _b === void 0 ? void 0 : _b.showNumber) || 10; var MoreIcon = (propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.MoreIcon) || ((_c = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _c === void 0 ? void 0 : _c.MoreIcon); var handlePluginBoolenParams = function (porpsVal, contextVal, defaultVal) { if (typeof (porpsVal) === 'boolean') { return porpsVal; } if (typeof (contextVal) === 'boolean') { return contextVal; } return defaultVal; }; var isEmojiPicker = handlePluginBoolenParams(propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.isEmojiPicker, (_d = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _d === void 0 ? void 0 : _d.isEmojiPicker, true); var isImagePicker = handlePluginBoolenParams(propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.isImagePicker, (_e = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _e === void 0 ? void 0 : _e.isImagePicker, true); var isVideoPicker = handlePluginBoolenParams(propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.isVideoPicker, (_f = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _f === void 0 ? void 0 : _f.isVideoPicker, true); var isFilePicker = handlePluginBoolenParams(propsPluginConfig === null || propsPluginConfig === void 0 ? void 0 : propsPluginConfig.isFilePicker, (_g = UIMessageInputConfig === null || UIMessageInputConfig === void 0 ? void 0 : UIMessageInputConfig.pluginConfig) === null || _g === void 0 ? void 0 : _g.isFilePicker, true); var pluginsRef = React.useRef(null); TranslationContext.useTranslationContext().t; var ImagePicker = isImagePicker && useUploadElement.useUploadElement({ children: (React__default["default"].createElement("div", { className: "input-plugin-item" }, React__default["default"].createElement(Icon.Icon, { width: 20, height: 20, type: type.IconTypes.IMAGE }))), type: 'image', accept: 'image/*', onChange: function (file) { pluginsRef.current.closeMore(); sendUploadMessage({ file: file }, models.MessageType.Image); }, }); var VideoPicker = isVideoPicker && useUploadElement.useUploadElement({ children: (React__default["default"].createElement("div", { className: "input-plugin-item" }, React__default["default"].createElement(Icon.Icon, { width: 20, height: 20, type: type.IconTypes.VIDEO }))), type: 'video', accept: 'video/*', onChange: function (file) { pluginsRef.current.closeMore(); sendUploadMessage({ file: file }, models.MessageType.Video); }, }); var FilePicker = isFilePicker && useUploadElement.useUploadElement({ children: (React__default["default"].createElement("div", { className: "input-plugin-item" }, React__default["default"].createElement(Icon.Icon, { width: 20, height: 20, type: type.IconTypes.DOCUMENT }))), type: 'file', accept: 'file/*', onChange: function (file) { pluginsRef.current.closeMore(); sendUploadMessage({ file: file }, models.MessageType.File); }, }); var plugins = tslib.__spreadArray([ isEmojiPicker && React__default["default"].createElement(EmojiPicker.EmojiPicker, null), ImagePicker, VideoPicker, FilePicker ], propPlugins, true).filter(function (item) { return item; }); return React__default["default"].createElement(index.Plugins, { ref: pluginsRef, plugins: plugins, showNumber: showNumber, MoreIcon: MoreIcon }); } exports.InputPluginsDefault = InputPluginsDefault; //# sourceMappingURL=InputPluginsDefault.js.map