@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
121 lines (120 loc) • 6.45 kB
JavaScript
'use client';
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["type", "menu", "className", "style", "loading", "generating", "size", "shape", "onSend", "onStop", "disabled", "onClick"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { Button, Icon } from '@lobehub/ui';
import { Dropdown, Space } from 'antd';
import { cx } from 'antd-style';
import { ChevronDownIcon } from 'lucide-react';
import { useMemo } from 'react';
import SendIcon from "./components/SendIcon";
import StopIcon from "./components/StopIcon";
import { styles } from "./style";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var SendButton = function SendButton(_ref) {
var _ref$type = _ref.type,
type = _ref$type === void 0 ? 'primary' : _ref$type,
menu = _ref.menu,
className = _ref.className,
style = _ref.style,
loading = _ref.loading,
generating = _ref.generating,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 32 : _ref$size,
shape = _ref.shape,
onSend = _ref.onSend,
onStop = _ref.onStop,
disabled = _ref.disabled,
_onClick = _ref.onClick,
rest = _objectWithoutProperties(_ref, _excluded);
var cssVariables = useMemo(function () {
return {
'--send-button-size': "".concat(size, "px")
};
}, [size]);
if (generating) return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
className: cx(styles.loadingButton, className),
onClick: function onClick(e) {
e.stopPropagation();
e.preventDefault();
if (onStop) onStop(e);
if (_onClick) _onClick(e);
},
shape: shape,
style: _objectSpread(_objectSpread(_objectSpread({}, cssVariables), style), {}, {
width: menu ? size * 2 : size
})
}, rest), {}, {
children: /*#__PURE__*/_jsx(StopIcon, {
size: size * 0.75
})
}));
if (loading) return /*#__PURE__*/_jsx(Button, _objectSpread({
className: cx(styles.loadingButton, className),
disabled: true,
loading: loading,
shape: shape,
style: _objectSpread(_objectSpread(_objectSpread({}, cssVariables), style), {}, {
width: menu ? size * 2 : size
}),
type: type
}, rest));
if (!menu) return /*#__PURE__*/_jsx(Button, _objectSpread({
className: cx(styles.button, disabled && styles.disabled, className),
disabled: disabled,
icon: /*#__PURE__*/_jsx(SendIcon, {}),
onClick: function onClick(e) {
e.stopPropagation();
e.preventDefault();
if (onSend) onSend(e);
if (_onClick) _onClick(e);
},
shape: shape,
style: _objectSpread(_objectSpread({}, cssVariables), style),
type: type
}, rest));
return /*#__PURE__*/_jsxs(Space.Compact, _objectSpread(_objectSpread({
className: cx(styles.dropdownButton, disabled && styles.disabled, shape === 'round' && styles.dropdownButtonRound, className),
style: _objectSpread(_objectSpread({}, cssVariables), style)
}, rest), {}, {
children: [/*#__PURE__*/_jsx(Button, _objectSpread({
className: cx(styles.button, disabled && styles.disabled, className),
disabled: disabled,
icon: /*#__PURE__*/_jsx(SendIcon, {}),
onClick: function onClick(e) {
e.stopPropagation();
e.preventDefault();
if (onSend) onSend(e);
if (_onClick) _onClick(e);
},
shape: shape,
style: _objectSpread(_objectSpread({}, cssVariables), style),
type: type
}, rest)), /*#__PURE__*/_jsx(Dropdown, _objectSpread(_objectSpread({
menu: menu,
placement: 'topRight'
}, rest), {}, {
children: /*#__PURE__*/_jsx(Button, {
className: cx(styles.button, disabled && styles.disabled, className),
disabled: disabled,
icon: /*#__PURE__*/_jsx(Icon, {
icon: ChevronDownIcon
}),
shape: shape,
style: _objectSpread(_objectSpread({}, cssVariables), {}, {
cursor: 'pointer'
}),
type: type
})
}))]
}));
};
SendButton.displayName = 'SendButton';
export default SendButton;