@agentscope-ai/chat 1.1.56 → 1.1.57

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.
@@ -3,5 +3,5 @@ import { ChatInput } from '@agentscope-ai/chat';
3
3
 
4
4
  export default function () {
5
5
  const [value, setValue] = useState('Hello, Alibaba Cloud Spark Chat!');
6
- return <ChatInput placeholder='Please type here...' value={value} onChange={setValue}></ChatInput>
6
+ return <ChatInput placeholder='Please type here...' value={value} onChange={setValue} maxLength={100}></ChatInput>
7
7
  }
@@ -430,8 +430,14 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
430
430
  isCompositionRef.current = true;
431
431
  };
432
432
 
433
- const onInternalCompositionEnd = () => {
433
+ const onInternalCompositionEnd = (e: React.CompositionEvent<HTMLTextAreaElement>) => {
434
434
  isCompositionRef.current = false;
435
+ if (props.maxLength) {
436
+ const currentValue = (e.target as HTMLTextAreaElement).value;
437
+ if (currentValue.length > props.maxLength) {
438
+ triggerValueChange(currentValue.slice(0, props.maxLength));
439
+ }
440
+ }
435
441
  };
436
442
 
437
443
  const onInternalPressEnter: TextareaProps['onPressEnter'] = (e) => {
@@ -533,7 +539,10 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
533
539
  autoSize={autoSize}
534
540
  value={innerValue.slice(0, props.maxLength || Number.MAX_SAFE_INTEGER)}
535
541
  onChange={(event) => {
536
- const nextValue = (event.target as HTMLTextAreaElement).value;
542
+ let nextValue = (event.target as HTMLTextAreaElement).value;
543
+ if (props.maxLength && !isCompositionRef.current && nextValue.length > props.maxLength) {
544
+ nextValue = nextValue.slice(0, props.maxLength);
545
+ }
537
546
  triggerValueChange(
538
547
  nextValue,
539
548
  event as React.ChangeEvent<HTMLTextAreaElement>,
@@ -639,7 +648,7 @@ const ForwardSender = React.forwardRef<SenderRef, SenderProps>((props, ref) => {
639
648
  >
640
649
  {
641
650
  props.maxLength ? <div className={`${actionListCls}-length`}>
642
- {innerValue.length}/{props.maxLength}
651
+ {Math.min(innerValue.length, props.maxLength)}/{props.maxLength}
643
652
  </div> : null
644
653
  }
645
654
  <ActionButtonContext.Provider
@@ -225,8 +225,14 @@ var ForwardSender = /*#__PURE__*/React.forwardRef(function (props, ref) {
225
225
  var onInternalCompositionStart = function onInternalCompositionStart() {
226
226
  isCompositionRef.current = true;
227
227
  };
228
- var onInternalCompositionEnd = function onInternalCompositionEnd() {
228
+ var onInternalCompositionEnd = function onInternalCompositionEnd(e) {
229
229
  isCompositionRef.current = false;
230
+ if (props.maxLength) {
231
+ var currentValue = e.target.value;
232
+ if (currentValue.length > props.maxLength) {
233
+ triggerValueChange(currentValue.slice(0, props.maxLength));
234
+ }
235
+ }
230
236
  };
231
237
  var onInternalPressEnter = function onInternalPressEnter(e) {
232
238
  var canSubmit = !isCompositionRef.current && !suggestionOpenRef.current;
@@ -326,6 +332,9 @@ var ForwardSender = /*#__PURE__*/React.forwardRef(function (props, ref) {
326
332
  value: innerValue.slice(0, props.maxLength || Number.MAX_SAFE_INTEGER),
327
333
  onChange: function onChange(event) {
328
334
  var nextValue = event.target.value;
335
+ if (props.maxLength && !isCompositionRef.current && nextValue.length > props.maxLength) {
336
+ nextValue = nextValue.slice(0, props.maxLength);
337
+ }
329
338
  triggerValueChange(nextValue, event);
330
339
  if (hasSuggestions) {
331
340
  var nextSlashCommandKeyword = getSlashCommandKeyword(nextValue);
@@ -413,7 +422,7 @@ var ForwardSender = /*#__PURE__*/React.forwardRef(function (props, ref) {
413
422
  style: styles.actions,
414
423
  children: [props.maxLength ? /*#__PURE__*/_jsxs("div", {
415
424
  className: "".concat(actionListCls, "-length"),
416
- children: [innerValue.length, "/", props.maxLength]
425
+ children: [Math.min(innerValue.length, props.maxLength), "/", props.maxLength]
417
426
  }) : null, /*#__PURE__*/_jsx(ActionButtonContext.Provider, {
418
427
  value: contextValue,
419
428
  children: actionNode
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.56",
3
+ "version": "1.1.57",
4
4
  "description": "a free and open-source chat framework for building excellent LLM-powered chat experiences",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": [