@djangocfg/ui-tools 2.1.376 → 2.1.377

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.
@@ -1284,6 +1284,22 @@ function useChatContextOptional() {
1284
1284
  return react.useContext(Ctx);
1285
1285
  }
1286
1286
  chunkOLISEQHS_cjs.__name(useChatContextOptional, "useChatContextOptional");
1287
+
1288
+ // src/tools/Chat/utils/sanitizeDraft.ts
1289
+ function sanitizeDraft(input) {
1290
+ if (!input) return "";
1291
+ let s = input.replace(/[​‌‍]/g, "");
1292
+ s = s.replace(/\r\n?/g, "\n");
1293
+ s = s.trim();
1294
+ return s;
1295
+ }
1296
+ chunkOLISEQHS_cjs.__name(sanitizeDraft, "sanitizeDraft");
1297
+ function isSubmittableDraft(input) {
1298
+ return sanitizeDraft(input).length > 0;
1299
+ }
1300
+ chunkOLISEQHS_cjs.__name(isSubmittableDraft, "isSubmittableDraft");
1301
+
1302
+ // src/tools/Chat/hooks/useChatComposer.ts
1287
1303
  var MAX_TEXTAREA_HEIGHT = 240;
1288
1304
  function useChatComposer(options) {
1289
1305
  const {
@@ -1295,7 +1311,8 @@ function useChatComposer(options) {
1295
1311
  submitOn = "enter",
1296
1312
  history = { enabled: true, size: LIMITS.composerHistorySize },
1297
1313
  onPasteFiles,
1298
- persistKey
1314
+ persistKey,
1315
+ preserveExactValue = false
1299
1316
  } = options;
1300
1317
  const initialFromStorage = (() => {
1301
1318
  if (!persistKey || typeof window === "undefined") return initialValue;
@@ -1341,26 +1358,25 @@ function useChatComposer(options) {
1341
1358
  requestAnimationFrame(() => textareaRef.current?.focus());
1342
1359
  }, []);
1343
1360
  const submit = react.useCallback(async () => {
1344
- const trimmed = value.trim();
1345
- if (!trimmed && attachments.length === 0 || isSubmitting || disabled) return;
1361
+ const cleaned = preserveExactValue ? value : sanitizeDraft(value);
1362
+ if (!cleaned && attachments.length === 0 || isSubmitting || disabled) return;
1346
1363
  setIsSubmitting(true);
1347
1364
  try {
1348
- if (history.enabled !== false && trimmed) {
1365
+ if (history.enabled !== false && cleaned) {
1349
1366
  const buf = historyRef.current.items;
1350
- if (buf[buf.length - 1] !== trimmed) {
1351
- buf.push(trimmed);
1367
+ if (buf[buf.length - 1] !== cleaned) {
1368
+ buf.push(cleaned);
1352
1369
  if (buf.length > (history.size ?? LIMITS.composerHistorySize)) buf.shift();
1353
1370
  }
1354
1371
  historyRef.current.index = -1;
1355
1372
  }
1356
1373
  const snapshot = [...attachments];
1357
- const text = value;
1358
1374
  reset();
1359
- await onSubmit(text, snapshot);
1375
+ await onSubmit(cleaned, snapshot);
1360
1376
  } finally {
1361
1377
  setIsSubmitting(false);
1362
1378
  }
1363
- }, [value, attachments, isSubmitting, disabled, history, onSubmit, reset]);
1379
+ }, [value, attachments, isSubmitting, disabled, history, onSubmit, reset, preserveExactValue]);
1364
1380
  const addAttachment = react.useCallback(
1365
1381
  (a) => {
1366
1382
  setAttachments((prev) => {
@@ -1434,7 +1450,7 @@ function useChatComposer(options) {
1434
1450
  },
1435
1451
  [onPasteFiles]
1436
1452
  );
1437
- const canSubmit = !disabled && !isSubmitting && (value.trim().length > 0 || attachments.length > 0);
1453
+ const canSubmit = !disabled && !isSubmitting && ((preserveExactValue ? value.trim().length : sanitizeDraft(value).length) > 0 || attachments.length > 0);
1438
1454
  return {
1439
1455
  value,
1440
1456
  setValue,
@@ -2421,8 +2437,10 @@ exports.createTokenBuffer = createTokenBuffer;
2421
2437
  exports.deriveInitials = deriveInitials;
2422
2438
  exports.getChatLogger = getChatLogger;
2423
2439
  exports.initialState = initialState;
2440
+ exports.isSubmittableDraft = isSubmittableDraft;
2424
2441
  exports.reducer = reducer;
2425
2442
  exports.resolvePersona = resolvePersona;
2443
+ exports.sanitizeDraft = sanitizeDraft;
2426
2444
  exports.useChat = useChat;
2427
2445
  exports.useChatAudio = useChatAudio;
2428
2446
  exports.useChatAudioPrefs = useChatAudioPrefs;
@@ -2430,5 +2448,5 @@ exports.useChatComposer = useChatComposer;
2430
2448
  exports.useChatContext = useChatContext;
2431
2449
  exports.useChatContextOptional = useChatContextOptional;
2432
2450
  exports.useChatLayout = useChatLayout;
2433
- //# sourceMappingURL=chunk-UVIFD3TH.cjs.map
2434
- //# sourceMappingURL=chunk-UVIFD3TH.cjs.map
2451
+ //# sourceMappingURL=chunk-TUZZROQU.cjs.map
2452
+ //# sourceMappingURL=chunk-TUZZROQU.cjs.map