@yuntijs/ui 1.0.0-beta.98 → 1.0.0

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", "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"];
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';
@@ -39,6 +39,7 @@ export var ChatItem = /*#__PURE__*/memo(function (_ref) {
39
39
  onChange = _ref.onChange,
40
40
  onEditingChange = _ref.onEditingChange,
41
41
  messageExtra = _ref.messageExtra,
42
+ affixation = _ref.affixation,
42
43
  renderMessage = _ref.renderMessage,
43
44
  text = _ref.text,
44
45
  errorMessage = _ref.errorMessage,
@@ -106,7 +107,10 @@ export var ChatItem = /*#__PURE__*/memo(function (_ref) {
106
107
  renderMessage: renderMessage,
107
108
  text: text,
108
109
  type: type
109
- }), /*#__PURE__*/_jsx(Actions, {
110
+ }), affixation ? /*#__PURE__*/_jsx("div", {
111
+ className: "affixation",
112
+ children: affixation
113
+ }) : null, /*#__PURE__*/_jsx(Actions, {
110
114
  actions: actions,
111
115
  editing: editing,
112
116
  placement: placement,
@@ -35,6 +35,7 @@ export interface ChatItemProps {
35
35
  */
36
36
  message?: ReactNode;
37
37
  messageExtra?: ReactNode;
38
+ affixation?: ReactNode;
38
39
  onAvatarClick?: () => void;
39
40
  /**
40
41
  * @description Callback when the message content changes
@@ -16,12 +16,12 @@ var useStyles = createStyles(function (_ref) {
16
16
  token = _ref.token,
17
17
  isDarkMode = _ref.isDarkMode;
18
18
  return {
19
- container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n padding-block: 12px;\n color: ", ";\n "])), token.colorTextSecondary),
20
- titlebox: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding: 8px 12px;\n\n font-size: 12px;\n color: ", ";\n\n background: ", ";\n border-radius: 8px;\n "])), token.colorText, isDarkMode ? token.colorFillTertiary : '#f3f5fc')
19
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 12px;\n color: ", ";\n "])), token.colorTextSecondary),
20
+ titlebox: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n cursor: pointer;\n\n min-width: 140px;\n max-width: 230px;\n padding: 8px 12px;\n\n font-size: 12px;\n color: ", ";\n\n background: ", ";\n border-radius: 8px;\n "])), token.colorText, isDarkMode ? token.colorFillTertiary : '#f3f5fc')
21
21
  };
22
22
  });
23
23
  var mProps = {
24
- fontSize: 12,
24
+ fontSize: 13,
25
25
  lineHeight: 1.625,
26
26
  headerMultiple: 0.2,
27
27
  marginMultiple: 0.6
@@ -39,14 +39,14 @@ var Render = /*#__PURE__*/memo(function (_ref2) {
39
39
  setShowDetail = _useState2[1];
40
40
  return /*#__PURE__*/_jsxs(Flexbox, {
41
41
  className: styles.container,
42
- onClick: function onClick() {
43
- setShowDetail(!showDetail);
44
- },
45
42
  children: [/*#__PURE__*/_jsxs(Flexbox, {
46
43
  className: styles.titlebox,
47
44
  distribution: 'space-between',
48
45
  flex: 1,
49
46
  horizontal: true,
47
+ onClick: function onClick() {
48
+ setShowDetail(!showDetail);
49
+ },
50
50
  children: [/*#__PURE__*/_jsxs(Flexbox, {
51
51
  gap: 8,
52
52
  horizontal: true,
@@ -40,7 +40,7 @@ export var remarkCaptureThink = function remarkCaptureThink() {
40
40
  data: {
41
41
  hChildren: [{
42
42
  type: 'text',
43
- value: content
43
+ value: content || ' '
44
44
  }],
45
45
  hName: 'think'
46
46
  },
@@ -1,10 +1,15 @@
1
1
  // 预处理函数:确保 think 标签前后有两个换行符
2
2
  export var normalizeThinkTags = function normalizeThinkTags(markdown) {
3
+ var reg1 = new RegExp('([^\\n])\\s*<think>', 'g');
4
+ var reg2 = new RegExp('<think>\\s*([^\\n])', 'g');
5
+ var reg3 = new RegExp('([^\\n])\\s*<\\/think>', 'g');
6
+ var reg4 = new RegExp('<\\/think>\\s*([^\\n])', 'g');
7
+ var reg5 = new RegExp('\\n{3,}', 'g');
3
8
  return (markdown || ''
4
9
  // 确保 <think> 标签前后有两个换行符
5
- ).replaceAll(/([^\n])\s*<think>/g, '$1\n\n<think>').replaceAll(/<think>\s*([^\n])/g, '<think>\n\n$1')
10
+ ).replaceAll(reg1, '$1\n\n<think>').replaceAll(reg2, '<think>\n\n$1')
6
11
  // 确保 </think> 标签前后有两个换行符
7
- .replaceAll(/([^\n])\s*<\/think>/g, '$1\n\n</think>').replaceAll(/<\/think>\s*([^\n])/g, '</think>\n\n$1')
12
+ .replaceAll(reg3, '$1\n\n</think>').replaceAll(reg4, '</think>\n\n$1')
8
13
  // 处理可能产生的多余换行符
9
- .replaceAll(/\n{3,}/g, '\n\n');
14
+ .replaceAll(reg5, '\n\n');
10
15
  };
@@ -0,0 +1,52 @@
1
+ import { CSSProperties, FocusEventHandler, KeyboardEventHandler, MouseEventHandler, Ref } from 'react';
2
+ import { FlexboxProps } from 'react-layout-kit';
3
+ export interface CodeEditorProps extends Omit<FlexboxProps, 'onFocus' | 'onBlur' | 'onKeyUp' | 'onKeyDown' | 'onClick'> {
4
+ autoFocus?: boolean;
5
+ classNames?: {
6
+ highlight?: string;
7
+ textarea?: string;
8
+ };
9
+ disabled?: boolean;
10
+ fontSize?: number | string;
11
+ form?: string;
12
+ ignoreTabKey?: boolean;
13
+ insertSpaces?: boolean;
14
+ language: string;
15
+ maxLength?: number;
16
+ minLength?: number;
17
+ onBlur?: FocusEventHandler<HTMLTextAreaElement>;
18
+ onClick?: MouseEventHandler<HTMLTextAreaElement>;
19
+ onFocus?: FocusEventHandler<HTMLTextAreaElement>;
20
+ onKeyDown?: KeyboardEventHandler<HTMLTextAreaElement>;
21
+ onKeyUp?: KeyboardEventHandler<HTMLTextAreaElement>;
22
+ onValueChange: (value: string) => void;
23
+ placeholder?: string;
24
+ readOnly?: boolean;
25
+ required?: boolean;
26
+ style?: CSSProperties;
27
+ styles?: {
28
+ highlight?: CSSProperties;
29
+ textarea?: CSSProperties;
30
+ };
31
+ tabSize?: number;
32
+ textareaId?: string;
33
+ value: string;
34
+ variant?: 'ghost' | 'block' | 'pure';
35
+ }
36
+ type Record = {
37
+ selectionEnd: number;
38
+ selectionStart: number;
39
+ value: string;
40
+ };
41
+ type History = {
42
+ offset: number;
43
+ stack: (Record & {
44
+ timestamp: number;
45
+ })[];
46
+ };
47
+ export declare const CodeEditor: import("react").ForwardRefExoticComponent<CodeEditorProps & import("react").RefAttributes<Ref<{
48
+ session: {
49
+ history: History;
50
+ };
51
+ } | null>>>;
52
+ export {};
@@ -0,0 +1,418 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ var _excluded = ["autoFocus", "disabled", "form", "classNames", "styles", "ignoreTabKey", "insertSpaces", "maxLength", "minLength", "onBlur", "onClick", "onFocus", "onKeyDown", "onKeyUp", "onValueChange", "placeholder", "readOnly", "required", "style", "className", "tabSize", "textareaId", "value", "language", "fontSize", "variant"];
5
+ 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; }
6
+ 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; }
7
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
8
+ import { Flexbox } from 'react-layout-kit';
9
+ import { SyntaxHighlighter } from "../Highlighter";
10
+ import { isMacLike } from "../utils/platform";
11
+ import { useStyles } from "./style";
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ var KEYCODE_Y = 89;
15
+ var KEYCODE_Z = 90;
16
+ var KEYCODE_M = 77;
17
+ var KEYCODE_PARENS = 57;
18
+ var KEYCODE_BRACKETS = 219;
19
+ var KEYCODE_QUOTE = 222;
20
+ var KEYCODE_BACK_QUOTE = 192;
21
+ var HISTORY_LIMIT = 100;
22
+ var HISTORY_TIME_GAP = 3000;
23
+ var isWindows = typeof window !== 'undefined' && 'navigator' in window && /win/i.test(navigator.platform);
24
+ var getLines = function getLines(text, position) {
25
+ return text.slice(0, Math.max(0, position)).split('\n');
26
+ };
27
+ export var CodeEditor = /*#__PURE__*/forwardRef(function (_ref, ref) {
28
+ var autoFocus = _ref.autoFocus,
29
+ disabled = _ref.disabled,
30
+ form = _ref.form,
31
+ _ref$classNames = _ref.classNames,
32
+ classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
33
+ _ref$styles = _ref.styles,
34
+ s = _ref$styles === void 0 ? {} : _ref$styles,
35
+ _ref$ignoreTabKey = _ref.ignoreTabKey,
36
+ ignoreTabKey = _ref$ignoreTabKey === void 0 ? false : _ref$ignoreTabKey,
37
+ _ref$insertSpaces = _ref.insertSpaces,
38
+ insertSpaces = _ref$insertSpaces === void 0 ? true : _ref$insertSpaces,
39
+ maxLength = _ref.maxLength,
40
+ minLength = _ref.minLength,
41
+ onBlur = _ref.onBlur,
42
+ onClick = _ref.onClick,
43
+ onFocus = _ref.onFocus,
44
+ onKeyDown = _ref.onKeyDown,
45
+ onKeyUp = _ref.onKeyUp,
46
+ onValueChange = _ref.onValueChange,
47
+ placeholder = _ref.placeholder,
48
+ readOnly = _ref.readOnly,
49
+ required = _ref.required,
50
+ style = _ref.style,
51
+ className = _ref.className,
52
+ _ref$tabSize = _ref.tabSize,
53
+ tabSize = _ref$tabSize === void 0 ? 2 : _ref$tabSize,
54
+ textareaId = _ref.textareaId,
55
+ value = _ref.value,
56
+ language = _ref.language,
57
+ _ref$fontSize = _ref.fontSize,
58
+ fontSize = _ref$fontSize === void 0 ? 12 : _ref$fontSize,
59
+ _ref$variant = _ref.variant,
60
+ variant = _ref$variant === void 0 ? 'ghost' : _ref$variant,
61
+ rest = _objectWithoutProperties(_ref, _excluded);
62
+ var _useStyles = useStyles({
63
+ fontSize: fontSize,
64
+ variant: variant
65
+ }),
66
+ styles = _useStyles.styles,
67
+ cx = _useStyles.cx;
68
+ var historyRef = useRef({
69
+ offset: -1,
70
+ stack: []
71
+ });
72
+ var inputRef = useRef(null);
73
+ var _useState = useState(true),
74
+ _useState2 = _slicedToArray(_useState, 2),
75
+ capture = _useState2[0],
76
+ setCapture = _useState2[1];
77
+ var recordChange = useCallback(function (record) {
78
+ var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
79
+ var _historyRef$current = historyRef.current,
80
+ stack = _historyRef$current.stack,
81
+ offset = _historyRef$current.offset;
82
+ if (stack.length > 0 && offset > -1) {
83
+ // When something updates, drop the redo operations
84
+ historyRef.current.stack = stack.slice(0, offset + 1);
85
+
86
+ // Limit the number of operations to 100
87
+ var count = historyRef.current.stack.length;
88
+ if (count > HISTORY_LIMIT) {
89
+ var extras = count - HISTORY_LIMIT;
90
+ historyRef.current.stack = stack.slice(extras, count);
91
+ historyRef.current.offset = Math.max(historyRef.current.offset - extras, 0);
92
+ }
93
+ }
94
+ var timestamp = Date.now();
95
+ if (overwrite) {
96
+ var last = historyRef.current.stack[historyRef.current.offset];
97
+ if (last && timestamp - last.timestamp < HISTORY_TIME_GAP) {
98
+ var _getLines$pop, _getLines$pop2, _current$;
99
+ // A previous entry exists and was in short interval
100
+
101
+ // Match the last word in the line
102
+ var re = /[^\da-z]([\da-z]+)$/i;
103
+
104
+ // Get the previous line
105
+ var previous = (_getLines$pop = getLines(last.value, last.selectionStart).pop()) === null || _getLines$pop === void 0 ? void 0 : _getLines$pop.match(re);
106
+
107
+ // Get the current line
108
+ var current = (_getLines$pop2 = getLines(record.value, record.selectionStart).pop()) === null || _getLines$pop2 === void 0 ? void 0 : _getLines$pop2.match(re);
109
+ if (previous !== null && previous !== void 0 && previous[1] && current !== null && current !== void 0 && (_current$ = current[1]) !== null && _current$ !== void 0 && _current$.startsWith(previous[1])) {
110
+ // The last word of the previous line and current line match
111
+ // Overwrite previous entry so that undo will remove whole word
112
+ historyRef.current.stack[historyRef.current.offset] = _objectSpread(_objectSpread({}, record), {}, {
113
+ timestamp: timestamp
114
+ });
115
+ return;
116
+ }
117
+ }
118
+ }
119
+
120
+ // Add the new operation to the stack
121
+ historyRef.current.stack.push(_objectSpread(_objectSpread({}, record), {}, {
122
+ timestamp: timestamp
123
+ }));
124
+ historyRef.current.offset++;
125
+ }, []);
126
+ var recordCurrentState = useCallback(function () {
127
+ var input = inputRef.current;
128
+ if (!input) return;
129
+
130
+ // Save current state of the input
131
+ var value = input.value,
132
+ selectionStart = input.selectionStart,
133
+ selectionEnd = input.selectionEnd;
134
+ recordChange({
135
+ selectionEnd: selectionEnd,
136
+ selectionStart: selectionStart,
137
+ value: value
138
+ });
139
+ }, [recordChange]);
140
+ var updateInput = function updateInput(record) {
141
+ var input = inputRef.current;
142
+ if (!input) return;
143
+
144
+ // Update values and selection state
145
+ input.value = record.value;
146
+ input.selectionStart = record.selectionStart;
147
+ input.selectionEnd = record.selectionEnd;
148
+ onValueChange === null || onValueChange === void 0 || onValueChange(record.value);
149
+ };
150
+ var applyEdits = function applyEdits(record) {
151
+ // Save last selection state
152
+ var input = inputRef.current;
153
+ var last = historyRef.current.stack[historyRef.current.offset];
154
+ if (last && input) {
155
+ historyRef.current.stack[historyRef.current.offset] = _objectSpread(_objectSpread({}, last), {}, {
156
+ selectionEnd: input.selectionEnd,
157
+ selectionStart: input.selectionStart
158
+ });
159
+ }
160
+
161
+ // Save the changes
162
+ recordChange(record);
163
+ updateInput(record);
164
+ };
165
+ var undoEdit = function undoEdit() {
166
+ var _historyRef$current2 = historyRef.current,
167
+ stack = _historyRef$current2.stack,
168
+ offset = _historyRef$current2.offset;
169
+
170
+ // Get the previous edit
171
+ var record = stack[offset - 1];
172
+ if (record) {
173
+ // Apply the changes and update the offset
174
+ updateInput(record);
175
+ historyRef.current.offset = Math.max(offset - 1, 0);
176
+ }
177
+ };
178
+ var redoEdit = function redoEdit() {
179
+ var _historyRef$current3 = historyRef.current,
180
+ stack = _historyRef$current3.stack,
181
+ offset = _historyRef$current3.offset;
182
+
183
+ // Get the next edit
184
+ var record = stack[offset + 1];
185
+ if (record) {
186
+ // Apply the changes and update the offset
187
+ updateInput(record);
188
+ historyRef.current.offset = Math.min(offset + 1, stack.length - 1);
189
+ }
190
+ };
191
+ var handleKeyDown = function handleKeyDown(e) {
192
+ if (onKeyDown) {
193
+ onKeyDown(e);
194
+ if (e.defaultPrevented) {
195
+ return;
196
+ }
197
+ }
198
+ if (e.key === 'Escape') {
199
+ e.currentTarget.blur();
200
+ }
201
+ var _e$currentTarget = e.currentTarget,
202
+ value = _e$currentTarget.value,
203
+ selectionStart = _e$currentTarget.selectionStart,
204
+ selectionEnd = _e$currentTarget.selectionEnd;
205
+ var tabCharacter = (insertSpaces ? ' ' : '\t').repeat(tabSize);
206
+ var windowCondition = isWindows ?
207
+ // Trigger redo with Ctrl+Y on Windows
208
+ e.ctrlKey && e.keyCode === KEYCODE_Y :
209
+ // Trigger redo with Ctrl+Shift+Z on other platforms
210
+ e.ctrlKey && e.keyCode === KEYCODE_Z && e.shiftKey;
211
+ if (e.key === 'Tab' && !ignoreTabKey && capture) {
212
+ // Prevent focus change
213
+ e.preventDefault();
214
+ if (e.shiftKey) {
215
+ // Unindent selected lines
216
+ var linesBeforeCaret = getLines(value, selectionStart);
217
+ var startLine = linesBeforeCaret.length - 1;
218
+ var endLine = getLines(value, selectionEnd).length - 1;
219
+ var nextValue = value.split('\n').map(function (line, i) {
220
+ if (i >= startLine && i <= endLine && line.startsWith(tabCharacter)) {
221
+ return line.slice(tabCharacter.length);
222
+ }
223
+ return line;
224
+ }).join('\n');
225
+ if (value !== nextValue) {
226
+ var startLineText = linesBeforeCaret[startLine];
227
+ applyEdits({
228
+ // Move the end cursor by total number of characters removed
229
+ selectionEnd: selectionEnd - (value.length - nextValue.length),
230
+ // Move the start cursor if first line in selection was modified
231
+ // It was modified only if it started with a tab
232
+ selectionStart: startLineText !== null && startLineText !== void 0 && startLineText.startsWith(tabCharacter) ? selectionStart - tabCharacter.length : selectionStart,
233
+ value: nextValue
234
+ });
235
+ }
236
+ } else if (selectionStart === selectionEnd) {
237
+ var updatedSelection = selectionStart + tabCharacter.length;
238
+ applyEdits({
239
+ selectionEnd: updatedSelection,
240
+ // Update caret position
241
+ selectionStart: updatedSelection,
242
+ // Insert tab character at caret
243
+ value: value.slice(0, Math.max(0, selectionStart)) + tabCharacter + value.slice(Math.max(0, selectionEnd))
244
+ });
245
+ } else {
246
+ // Indent selected lines
247
+ var _linesBeforeCaret = getLines(value, selectionStart);
248
+ var _startLine = _linesBeforeCaret.length - 1;
249
+ var _endLine = getLines(value, selectionEnd).length - 1;
250
+ var _startLineText = _linesBeforeCaret[_startLine];
251
+ applyEdits({
252
+ // Move the end cursor by total number of characters added
253
+ selectionEnd: selectionEnd + tabCharacter.length * (_endLine - _startLine + 1),
254
+ // Move the start cursor by number of characters added in first line of selection
255
+ // Don't move it if it there was no text before cursor
256
+ selectionStart: _startLineText && /\S/.test(_startLineText) ? selectionStart + tabCharacter.length : selectionStart,
257
+ value: value.split('\n').map(function (line, i) {
258
+ if (i >= _startLine && i <= _endLine) {
259
+ return tabCharacter + line;
260
+ }
261
+ return line;
262
+ }).join('\n')
263
+ });
264
+ }
265
+ } else if (e.key === 'Backspace') {
266
+ var hasSelection = selectionStart !== selectionEnd;
267
+ var textBeforeCaret = value.slice(0, Math.max(0, selectionStart));
268
+ if (textBeforeCaret.endsWith(tabCharacter) && !hasSelection) {
269
+ // Prevent default delete behaviour
270
+ e.preventDefault();
271
+ var _updatedSelection = selectionStart - tabCharacter.length;
272
+ applyEdits({
273
+ selectionEnd: _updatedSelection,
274
+ // Update caret position
275
+ selectionStart: _updatedSelection,
276
+ // Remove tab character at caret
277
+ value: value.slice(0, Math.max(0, selectionStart - tabCharacter.length)) + value.slice(Math.max(0, selectionEnd))
278
+ });
279
+ }
280
+ } else if (e.key === 'Enter') {
281
+ // Ignore selections
282
+ if (selectionStart === selectionEnd) {
283
+ // Get the current line
284
+ var line = getLines(value, selectionStart).pop();
285
+ var matches = line === null || line === void 0 ? void 0 : line.match(/^\s+/);
286
+ if (matches !== null && matches !== void 0 && matches[0]) {
287
+ e.preventDefault();
288
+
289
+ // Preserve indentation on inserting a new line
290
+ var indent = '\n' + matches[0];
291
+ var _updatedSelection2 = selectionStart + indent.length;
292
+ applyEdits({
293
+ selectionEnd: _updatedSelection2,
294
+ // Update caret position
295
+ selectionStart: _updatedSelection2,
296
+ // Insert indentation character at caret
297
+ value: value.slice(0, Math.max(0, selectionStart)) + indent + value.slice(Math.max(0, selectionEnd))
298
+ });
299
+ }
300
+ }
301
+ } else if (e.keyCode === KEYCODE_PARENS || e.keyCode === KEYCODE_BRACKETS || e.keyCode === KEYCODE_QUOTE || e.keyCode === KEYCODE_BACK_QUOTE) {
302
+ var chars;
303
+ if (e.keyCode === KEYCODE_PARENS && e.shiftKey) {
304
+ chars = ['(', ')'];
305
+ } else if (e.keyCode === KEYCODE_BRACKETS) {
306
+ chars = e.shiftKey ? ['{', '}'] : ['[', ']'];
307
+ } else if (e.keyCode === KEYCODE_QUOTE) {
308
+ chars = e.shiftKey ? ['"', '"'] : ["'", "'"];
309
+ } else if (e.keyCode === KEYCODE_BACK_QUOTE && !e.shiftKey) {
310
+ chars = ['`', '`'];
311
+ }
312
+
313
+ // If text is selected, wrap them in the characters
314
+ if (selectionStart !== selectionEnd && chars) {
315
+ e.preventDefault();
316
+ applyEdits({
317
+ selectionEnd: selectionEnd + 2,
318
+ // Update caret position
319
+ selectionStart: selectionStart,
320
+ value: value.slice(0, Math.max(0, selectionStart)) + chars[0] +
321
+ // eslint-disable-next-line unicorn/prefer-string-slice
322
+ value.substring(selectionStart, selectionEnd) + chars[1] + value.slice(Math.max(0, selectionEnd))
323
+ });
324
+ }
325
+ } else if ((isMacLike ?
326
+ // Trigger undo with ⌘+Z on Mac
327
+ e.metaKey && e.keyCode === KEYCODE_Z :
328
+ // Trigger undo with Ctrl+Z on other platforms
329
+ e.ctrlKey && e.keyCode === KEYCODE_Z) && !e.shiftKey && !e.altKey) {
330
+ e.preventDefault();
331
+ undoEdit();
332
+ } else if ((isMacLike ?
333
+ // Trigger redo with ⌘+Shift+Z on Mac
334
+ e.metaKey && e.keyCode === KEYCODE_Z && e.shiftKey : windowCondition) && !e.altKey) {
335
+ e.preventDefault();
336
+ redoEdit();
337
+ } else if (e.keyCode === KEYCODE_M && e.ctrlKey && (isMacLike ? e.shiftKey : true)) {
338
+ e.preventDefault();
339
+
340
+ // Toggle capturing tab key so users can focus away
341
+ setCapture(function (prev) {
342
+ return !prev;
343
+ });
344
+ }
345
+ };
346
+ var handleChange = function handleChange(e) {
347
+ var _e$currentTarget2 = e.currentTarget,
348
+ value = _e$currentTarget2.value,
349
+ selectionStart = _e$currentTarget2.selectionStart,
350
+ selectionEnd = _e$currentTarget2.selectionEnd;
351
+ recordChange({
352
+ selectionEnd: selectionEnd,
353
+ selectionStart: selectionStart,
354
+ value: value
355
+ }, true);
356
+ onValueChange(value);
357
+ };
358
+ useEffect(function () {
359
+ recordCurrentState();
360
+ }, [recordCurrentState]);
361
+
362
+ // @ts-ignore
363
+ useImperativeHandle(ref, function () {
364
+ return {
365
+ get session() {
366
+ return {
367
+ history: historyRef.current
368
+ };
369
+ },
370
+ set session(session) {
371
+ historyRef.current = session.history;
372
+ }
373
+ };
374
+ }, []);
375
+ return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
376
+ className: cx(styles.container, className),
377
+ style: style
378
+ }, rest), {}, {
379
+ children: /*#__PURE__*/_jsxs("div", {
380
+ className: styles.editor,
381
+ children: [/*#__PURE__*/_jsx(SyntaxHighlighter, {
382
+ className: cx(styles.highlight, classNames === null || classNames === void 0 ? void 0 : classNames.highlight),
383
+ language: language,
384
+ style: s.highlight,
385
+ children: value
386
+ }), /*#__PURE__*/_jsx("textarea", {
387
+ autoCapitalize: "off",
388
+ autoComplete: "off",
389
+ autoCorrect: "off",
390
+ autoFocus: autoFocus,
391
+ className: cx(styles.textarea, classNames === null || classNames === void 0 ? void 0 : classNames.textarea),
392
+ "data-gramm": false,
393
+ disabled: disabled,
394
+ form: form,
395
+ id: textareaId,
396
+ maxLength: maxLength,
397
+ minLength: minLength,
398
+ onBlur: onBlur,
399
+ onChange: handleChange,
400
+ onClick: onClick,
401
+ onFocus: onFocus,
402
+ onKeyDown: handleKeyDown,
403
+ onKeyUp: onKeyUp,
404
+ placeholder: placeholder,
405
+ readOnly: readOnly
406
+ // @ts-ignore
407
+ ,
408
+ ref: function ref(c) {
409
+ return inputRef.current = c;
410
+ },
411
+ required: required,
412
+ spellCheck: false,
413
+ style: _objectSpread({}, s === null || s === void 0 ? void 0 : s.textarea),
414
+ value: value
415
+ })]
416
+ })
417
+ }));
418
+ });
@@ -0,0 +1,9 @@
1
+ export declare const useStyles: (props?: {
2
+ fontSize: string | number;
3
+ variant: 'ghost' | 'block' | 'pure';
4
+ } | undefined) => import("antd-style").ReturnStyles<{
5
+ container: string;
6
+ editor: import("antd-style").SerializedStyles;
7
+ highlight: import("antd-style").SerializedStyles;
8
+ textarea: import("antd-style").SerializedStyles;
9
+ }>;
@@ -0,0 +1,19 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
3
+ import { createStyles } from 'antd-style';
4
+ import { isNumber } from 'lodash-es';
5
+ export var useStyles = createStyles(function (_ref, _ref2) {
6
+ var cx = _ref.cx,
7
+ css = _ref.css,
8
+ token = _ref.token;
9
+ var variant = _ref2.variant,
10
+ fontSize = _ref2.fontSize;
11
+ var size = isNumber(fontSize) ? "".concat(fontSize, "px") : fontSize;
12
+ var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 8px;\n padding-inline: 12px;\n\n background-color: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n "])), variant === 'block' ? token.colorFillTertiary : 'transparent', variant === 'block' ? 'transparent' : token.colorBorderSecondary, token.borderRadius);
13
+ return {
14
+ container: cx(variant !== 'pure' && typeStylish, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden auto;\n width: 100%;\n "])))),
15
+ editor: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n height: fit-content;\n\n * {\n font-family: ", " !important;\n font-size: ", " !important;\n line-height: 1.5 !important;\n word-break: break-all !important;\n word-wrap: break-word !important;\n white-space: pre-wrap !important;\n }\n "])), token.fontFamilyCode, size),
16
+ highlight: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n pre,\n code {\n overflow: hidden;\n }\n "]))),
17
+ textarea: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n resize: none;\n\n position: absolute;\n inset-block-start: 0;\n inset-inline-start: 0;\n\n overflow: hidden;\n\n box-sizing: border-box;\n width: 100%;\n height: 100%;\n padding: 0;\n\n color: transparent !important;\n text-align: start;\n\n background: transparent;\n border: none;\n outline: none;\n caret-color: ", ";\n\n &::placeholder {\n color: ", ";\n }\n\n &:focus {\n border: none !important;\n outline: none !important;\n box-shadow: none !important;\n }\n "])), token.colorText, token.colorTextQuaternary)
18
+ };
19
+ });
@@ -1,9 +1,10 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["className", "variant"];
3
+ var _excluded = ["className", "variant", "collapsible", "expandIcon"];
4
4
  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; }
5
5
  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; }
6
- import { Form as LobeForm } from '@lobehub/ui';
6
+ import { ActionIcon, Form as LobeForm } from '@lobehub/ui';
7
+ import { ChevronDown, ChevronRight } from 'lucide-react';
7
8
  import React from 'react';
8
9
  import { useStyles } from "./style";
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -11,13 +12,28 @@ var FormGroup = LobeForm.Group;
11
12
  export var CollapseGroup = function CollapseGroup(_ref) {
12
13
  var className = _ref.className,
13
14
  variant = _ref.variant,
15
+ collapsible = _ref.collapsible,
16
+ _ref$expandIcon = _ref.expandIcon,
17
+ expandIcon = _ref$expandIcon === void 0 ? function (panelProps) {
18
+ return /*#__PURE__*/_jsx(ActionIcon, {
19
+ icon: panelProps.isActive ? ChevronDown : ChevronRight,
20
+ size: {
21
+ blockSize: 24,
22
+ fontSize: 14,
23
+ strokeWidth: 3
24
+ }
25
+ });
26
+ } : _ref$expandIcon,
14
27
  otherProps = _objectWithoutProperties(_ref, _excluded);
15
- var _useStyles = useStyles(),
28
+ var _useStyles = useStyles({
29
+ collapsible: collapsible
30
+ }),
16
31
  styles = _useStyles.styles,
17
32
  cx = _useStyles.cx;
18
33
  return /*#__PURE__*/_jsx(FormGroup, _objectSpread({
19
34
  className: cx(styles.root, className),
20
- collapsible: variant !== 'pure',
35
+ collapsible: variant === 'pure' ? false : collapsible,
36
+ expandIcon: expandIcon,
21
37
  variant: variant
22
38
  }, otherProps));
23
39
  };
@@ -1,3 +1,5 @@
1
- export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
1
+ export declare const useStyles: (props?: {
2
+ collapsible?: boolean | undefined;
3
+ } | undefined) => import("antd-style").ReturnStyles<{
2
4
  root: import("antd-style").SerializedStyles;
3
5
  }>;