@yuntijs/ui 1.1.0-beta.7 → 1.1.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "affixation", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "markdownProps", "markdownClassname", "isLatest"];
5
+ var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "affixation", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "markdownProps", "markdownClassname", "isLatest", "hideAvatar"];
6
6
  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; }
7
7
  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; }
8
8
  import Avatar from '@lobehub/ui/es/chat/ChatItem/components/Avatar';
@@ -48,6 +48,7 @@ export var ChatItem = /*#__PURE__*/memo(function (_ref) {
48
48
  markdownProps = _ref.markdownProps,
49
49
  markdownClassname = _ref.markdownClassname,
50
50
  isLatest = _ref.isLatest,
51
+ hideAvatar = _ref.hideAvatar,
51
52
  rest = _objectWithoutProperties(_ref, _excluded);
52
53
  var _useResponsive = useResponsive(),
53
54
  mobile = _useResponsive.mobile;
@@ -68,7 +69,7 @@ export var ChatItem = /*#__PURE__*/memo(function (_ref) {
68
69
  direction: placement === 'left' ? 'horizontal' : 'horizontal-reverse',
69
70
  gap: mobile ? 6 : 12
70
71
  }, rest), {}, {
71
- children: [/*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, avatarProps), {}, {
72
+ children: [hideAvatar ? null : /*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, avatarProps), {}, {
72
73
  addon: avatarAddon,
73
74
  avatar: avatar,
74
75
  loading: loading,
@@ -16,11 +16,12 @@ export var useStyles = createStyles(function (_ref, _ref2) {
16
16
  editing = _ref2.editing,
17
17
  time = _ref2.time,
18
18
  isLatest = _ref2.isLatest;
19
- var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 8px;\n padding-inline: 12px;\n\n background-color: ", ";\n border-radius: ", "px;\n\n transition: background-color 100ms ", ";\n "])), primary ? isDarkMode ? token.colorFill : token.colorBgElevated : isDarkMode ? token.colorFillSecondary : token.colorBgContainer, token.borderRadiusLG, token.motionEaseOut);
19
+ var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n /* padding-block: 8px;\n padding-inline: 12px; */\n\n background-color: ", ";\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n "])), primary ? isDarkMode ? token.colorFill : token.colorBgElevated : isDarkMode ? token.colorFillSecondary : token.colorBgContainer, token.borderRadiusLG, token.motionEaseOut);
20
20
  var pureStylish = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-block-start: ", ";\n "])), title ? 0 : '6px');
21
21
  var pureContainerStylish = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n margin-block-end: -16px;\n transition: background-color 100ms ", ";\n "])), token.motionEaseOut);
22
22
  var typeStylish = type === 'block' ? blockStylish : pureStylish;
23
23
  var editingStylish = editing && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n width: 100%;\n "])));
24
+ var insetInline = placement === 'right' ? '-4px unset' : 'unset -4px';
24
25
  return {
25
26
  actions: cx(css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n flex: none;\n align-self: ", ";\n justify-content: ", ";\n "])), placement === 'left' ? 'flex-start' : 'flex-end', placement === 'left' ? 'flex-end' : 'flex-start'), editing && css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n pointer-events: none !important;\n opacity: 0 !important;\n "])))),
26
27
  avatarContainer: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n flex: none;\n width: ", "px;\n height: ", "px;\n "])), avatarSize, avatarSize),
@@ -29,7 +30,7 @@ export var useStyles = createStyles(function (_ref, _ref2) {
29
30
  editingContainer: cx(editingStylish, css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n padding-block: 8px 12px;\n padding-inline: 12px;\n border: 1px solid ", ";\n\n &:active,\n &:hover {\n border-color: ", ";\n }\n "])), token.colorBorderSecondary, token.colorBorder), type === 'pure' && css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n background: ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadius)),
30
31
  editingInput: css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n width: 100%;\n "]))),
31
32
  errorContainer: css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n width: 100%;\n "]))),
32
- loading: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n inset-block-end: 0;\n inset-inline: ", "\n ", ";\n\n width: 16px;\n height: 16px;\n\n color: ", ";\n\n background: ", ";\n border-radius: 50%;\n "])), placement === 'right' ? '-4px' : 'unset', placement === 'left' ? '-4px' : 'unset', token.colorBgLayout, token.colorPrimary),
33
+ loading: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n inset-block-end: 0;\n inset-inline: ", ";\n\n width: 16px;\n height: 16px;\n\n color: ", ";\n\n background: ", ";\n border-radius: 50%;\n "])), insetInline, token.colorBgLayout, token.colorPrimary),
33
34
  message: cx(typeStylish, css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n ", " {\n width: 100%;\n }\n "])), responsive.mobile)),
34
35
  messageContainer: cx(editingStylish, css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n margin-block-start: ", "px;\n\n ", " {\n overflow-x: auto;\n }\n "])), time ? -16 : 0, responsive.mobile)),
35
36
  messageContent: cx(editingStylish, css(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n ", " {\n flex-direction: column !important;\n }\n "])), responsive.mobile)),
@@ -84,4 +84,8 @@ export interface ChatItemProps {
84
84
  * @description Whether this message is latest
85
85
  */
86
86
  isLatest?: boolean;
87
+ /**
88
+ * @description Hide avatar
89
+ */
90
+ hideAvatar?: boolean;
87
91
  }
@@ -19,6 +19,12 @@ export interface MentionsProps extends MentionPickerPluginProps {
19
19
  onChange?: (text: string) => void;
20
20
  onBlur?: () => void;
21
21
  onFocus?: () => void;
22
+ /**
23
+ * 按下回车的回调,指定后会改变回车的默认行为,换行需要使用 shift + enter
24
+ */
25
+ onPressEnter?: (value: string, { event }: {
26
+ event: KeyboardEvent | null;
27
+ }) => void;
22
28
  variant?: 'outlined' | 'filled' | 'borderless';
23
29
  autoSize?: AutoSize;
24
30
  code?: boolean;
@@ -18,6 +18,7 @@ import { EditorRefPlugin } from "./plugins/editor-ref";
18
18
  import { MentionNode, MentionNodePlugin, MentionNodePluginReplacement } from "./plugins/mention-node";
19
19
  import { MentionPickerPlugin } from "./plugins/mention-picker";
20
20
  import { OnBlurBlockPlugin } from "./plugins/on-blur-block";
21
+ import { ShiftEnterKeyPlugin } from "./plugins/shift-enter-key";
21
22
  import { MentionsConfigProvider } from "./provider";
22
23
  import { useStyles } from "./style";
23
24
  import { textToEditorState } from "./utils";
@@ -51,7 +52,8 @@ export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
51
52
  onSelect = _ref.onSelect,
52
53
  _ref$code = _ref.code,
53
54
  code = _ref$code === void 0 ? false : _ref$code,
54
- getPopContainer = _ref.getPopContainer;
55
+ getPopContainer = _ref.getPopContainer,
56
+ onPressEnter = _ref.onPressEnter;
55
57
  var _ConfigProvider$useCo = ConfigProvider.useConfig(),
56
58
  componentDisabled = _ConfigProvider$useCo.componentDisabled;
57
59
  var _useStyles = useStyles({
@@ -160,6 +162,8 @@ export var Mentions = /*#__PURE__*/forwardRef(function (_ref, ref) {
160
162
  editable: editable
161
163
  }), /*#__PURE__*/_jsx(EditorRefPlugin, {
162
164
  editorRef: ref
165
+ }), onPressEnter && /*#__PURE__*/_jsx(ShiftEnterKeyPlugin, {
166
+ onPressEnter: onPressEnter
163
167
  })]
164
168
  })
165
169
  })
@@ -3,6 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
4
4
  import { LexicalTypeaheadMenuPlugin } from '@lexical/react/LexicalTypeaheadMenuPlugin';
5
5
  import { ConfigProvider, Tree } from 'antd';
6
+ import { COMMAND_PRIORITY_NORMAL } from 'lexical';
6
7
  import { flatMap } from 'lodash-es';
7
8
  import React, { memo, useCallback, useMemo, useRef, useState } from 'react';
8
9
  import ReactDOM from 'react-dom';
@@ -163,7 +164,10 @@ export var MentionPickerPlugin = /*#__PURE__*/memo(function (_ref) {
163
164
  return null;
164
165
  }, [cx, handleDisabledItem, options, overlayClassName, queryString, renderMenuTree, styles.menuOverlay]);
165
166
  return /*#__PURE__*/_jsx(LexicalTypeaheadMenuPlugin, {
166
- anchorClassName: styles.anchor,
167
+ anchorClassName: styles.anchor
168
+ // 优先级要高于 ShiftEnterKeyPlugin
169
+ ,
170
+ commandPriority: COMMAND_PRIORITY_NORMAL,
167
171
  menuRenderFn: renderMenu,
168
172
  onQueryChange: setQueryString,
169
173
  onSelectOption: onSelectOption,
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { MentionsProps } from '..';
3
+ export interface ShiftEnterKeyPluginProps {
4
+ onPressEnter: Required<MentionsProps>['onPressEnter'];
5
+ }
6
+ export declare const ShiftEnterKeyPlugin: React.FC<ShiftEnterKeyPluginProps>;
@@ -0,0 +1,48 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
3
+ import { CAN_USE_BEFORE_INPUT, IS_APPLE_WEBKIT, IS_IOS, IS_SAFARI } from '@lexical/utils';
4
+ import { $getRoot, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND, KEY_ENTER_COMMAND } from 'lexical';
5
+ import { useEffect } from 'react';
6
+ export var ShiftEnterKeyPlugin = function ShiftEnterKeyPlugin(_ref) {
7
+ var onPressEnter = _ref.onPressEnter;
8
+ var _useLexicalComposerCo = useLexicalComposerContext(),
9
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
10
+ editor = _useLexicalComposerCo2[0];
11
+ useEffect(function () {
12
+ // https://github.com/facebook/lexical/discussions/4464#discussioncomment-5833227
13
+ editor.registerCommand(KEY_ENTER_COMMAND, function (event) {
14
+ var selection = $getSelection();
15
+ if (!$isRangeSelection(selection)) {
16
+ return false;
17
+ }
18
+ if (event !== null) {
19
+ // If we have beforeinput, then we can avoid blocking
20
+ // the default behavior. This ensures that the iOS can
21
+ // intercept that we're actually inserting a paragraph,
22
+ // and autocomplete, autocapitalize etc work as intended.
23
+ // This can also cause a strange performance issue in
24
+ // Safari, where there is a noticeable pause due to
25
+ // preventing the key down of enter.
26
+ if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
27
+ return false;
28
+ }
29
+ event.preventDefault();
30
+ if (event.shiftKey) {
31
+ return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, void 0);
32
+ }
33
+ }
34
+ event === null || event === void 0 || event.preventDefault();
35
+ var text = editor.read(function () {
36
+ return $getRoot().getTextContent();
37
+ });
38
+ var value = text.replaceAll('\n\n', '\n');
39
+ onPressEnter(value, {
40
+ event: event
41
+ });
42
+ return true;
43
+ },
44
+ // 优先级要低于 MentionPickerPlugin
45
+ COMMAND_PRIORITY_LOW);
46
+ }, [editor, onPressEnter]);
47
+ return null;
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.1.0-beta.7",
3
+ "version": "1.1.0-beta.9",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",