@aizu-chat/react 0.1.1 → 0.1.2

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.
package/dist/index.js CHANGED
@@ -1224,12 +1224,15 @@ var import_react9 = require("react");
1224
1224
 
1225
1225
  // src/hooks/use-keyboard.ts
1226
1226
  var import_react7 = require("react");
1227
+ var MAX_LENGTH = 300;
1227
1228
  var useKeyboard = ({ userMessages, isLoading, onSend }) => {
1228
1229
  const [value, setValue] = (0, import_react7.useState)("");
1229
1230
  const [historyIndex, setHistoryIndex] = (0, import_react7.useState)((userMessages == null ? void 0 : userMessages.length) || 0);
1230
1231
  const textareaRef = (0, import_react7.useRef)(null);
1231
1232
  const handleChange = (e) => {
1232
- setValue(e.target.value);
1233
+ const currentValue = e.target.value;
1234
+ const truncatedValue = currentValue.length > MAX_LENGTH ? currentValue.slice(0, MAX_LENGTH) : currentValue;
1235
+ setValue(truncatedValue);
1233
1236
  };
1234
1237
  const handleSubmit = (e) => {
1235
1238
  e.preventDefault();
@@ -1253,17 +1256,21 @@ var useKeyboard = ({ userMessages, isLoading, onSend }) => {
1253
1256
  if (key === "ArrowUp") {
1254
1257
  e.preventDefault();
1255
1258
  if (userMessages.length === 0) return;
1256
- const next = historyIndex === userMessages.length ? userMessages.length - 1 : Math.max(0, historyIndex - 1);
1257
- setHistoryIndex(next);
1258
- setValue((_b = (_a = userMessages[next]) == null ? void 0 : _a.text) != null ? _b : "");
1259
+ const nextIndex = historyIndex === userMessages.length ? userMessages.length - 1 : Math.max(0, historyIndex - 1);
1260
+ setHistoryIndex(nextIndex);
1261
+ const nextValue = (_b = (_a = userMessages[nextIndex]) == null ? void 0 : _a.text) != null ? _b : "";
1262
+ const truncatedValue = nextValue.slice(0, MAX_LENGTH);
1263
+ setValue(truncatedValue);
1259
1264
  return;
1260
1265
  }
1261
1266
  if (key === "ArrowDown") {
1262
1267
  e.preventDefault();
1263
1268
  if (userMessages.length === 0) return;
1264
- const next = historyIndex >= userMessages.length - 1 ? userMessages.length : historyIndex + 1;
1265
- setHistoryIndex(next);
1266
- setValue(next === userMessages.length ? "" : (_d = (_c = userMessages[next]) == null ? void 0 : _c.text) != null ? _d : "");
1269
+ const nextIndex = historyIndex >= userMessages.length - 1 ? userMessages.length : historyIndex + 1;
1270
+ setHistoryIndex(nextIndex);
1271
+ const nextValue = nextIndex === userMessages.length ? "" : (_d = (_c = userMessages[nextIndex]) == null ? void 0 : _c.text) != null ? _d : "";
1272
+ const truncatedValue = nextValue.slice(0, MAX_LENGTH);
1273
+ setValue(truncatedValue);
1267
1274
  }
1268
1275
  };
1269
1276
  const adjustTextareaHeight = (0, import_react7.useCallback)(() => {
package/dist/index.mjs CHANGED
@@ -1201,12 +1201,15 @@ import {
1201
1201
 
1202
1202
  // src/hooks/use-keyboard.ts
1203
1203
  import { useCallback as useCallback6, useEffect as useEffect3, useRef as useRef4, useState as useState4 } from "react";
1204
+ var MAX_LENGTH = 300;
1204
1205
  var useKeyboard = ({ userMessages, isLoading, onSend }) => {
1205
1206
  const [value, setValue] = useState4("");
1206
1207
  const [historyIndex, setHistoryIndex] = useState4((userMessages == null ? void 0 : userMessages.length) || 0);
1207
1208
  const textareaRef = useRef4(null);
1208
1209
  const handleChange = (e) => {
1209
- setValue(e.target.value);
1210
+ const currentValue = e.target.value;
1211
+ const truncatedValue = currentValue.length > MAX_LENGTH ? currentValue.slice(0, MAX_LENGTH) : currentValue;
1212
+ setValue(truncatedValue);
1210
1213
  };
1211
1214
  const handleSubmit = (e) => {
1212
1215
  e.preventDefault();
@@ -1230,17 +1233,21 @@ var useKeyboard = ({ userMessages, isLoading, onSend }) => {
1230
1233
  if (key === "ArrowUp") {
1231
1234
  e.preventDefault();
1232
1235
  if (userMessages.length === 0) return;
1233
- const next = historyIndex === userMessages.length ? userMessages.length - 1 : Math.max(0, historyIndex - 1);
1234
- setHistoryIndex(next);
1235
- setValue((_b = (_a = userMessages[next]) == null ? void 0 : _a.text) != null ? _b : "");
1236
+ const nextIndex = historyIndex === userMessages.length ? userMessages.length - 1 : Math.max(0, historyIndex - 1);
1237
+ setHistoryIndex(nextIndex);
1238
+ const nextValue = (_b = (_a = userMessages[nextIndex]) == null ? void 0 : _a.text) != null ? _b : "";
1239
+ const truncatedValue = nextValue.slice(0, MAX_LENGTH);
1240
+ setValue(truncatedValue);
1236
1241
  return;
1237
1242
  }
1238
1243
  if (key === "ArrowDown") {
1239
1244
  e.preventDefault();
1240
1245
  if (userMessages.length === 0) return;
1241
- const next = historyIndex >= userMessages.length - 1 ? userMessages.length : historyIndex + 1;
1242
- setHistoryIndex(next);
1243
- setValue(next === userMessages.length ? "" : (_d = (_c = userMessages[next]) == null ? void 0 : _c.text) != null ? _d : "");
1246
+ const nextIndex = historyIndex >= userMessages.length - 1 ? userMessages.length : historyIndex + 1;
1247
+ setHistoryIndex(nextIndex);
1248
+ const nextValue = nextIndex === userMessages.length ? "" : (_d = (_c = userMessages[nextIndex]) == null ? void 0 : _c.text) != null ? _d : "";
1249
+ const truncatedValue = nextValue.slice(0, MAX_LENGTH);
1250
+ setValue(truncatedValue);
1244
1251
  }
1245
1252
  };
1246
1253
  const adjustTextareaHeight = useCallback6(() => {
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "@aizu-chat/react",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
7
- "sideEffects": [
8
- "*.css",
9
- "dist/**/*.css"
10
- ],
7
+ "sideEffects": ["*.css", "dist/**/*.css"],
11
8
  "license": "MIT",
12
- "files": [
13
- "dist/**"
14
- ],
9
+ "files": ["dist/**"],
15
10
  "scripts": {
16
11
  "build": "tsup",
17
12
  "dev": "tsup --watch",