@djangocfg/ui-tools 2.1.91 → 2.1.94

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/ui-tools",
3
- "version": "2.1.91",
3
+ "version": "2.1.94",
4
4
  "description": "Heavy React tools with lazy loading - for Electron, Vite, CRA, Next.js apps",
5
5
  "keywords": [
6
6
  "ui-tools",
@@ -55,7 +55,7 @@
55
55
  "consola": "^3.4.2"
56
56
  },
57
57
  "dependencies": {
58
- "@djangocfg/ui-core": "^2.1.91",
58
+ "@djangocfg/ui-core": "^2.1.94",
59
59
  "@rjsf/core": "^6.1.2",
60
60
  "@rjsf/utils": "^6.1.2",
61
61
  "@rjsf/validator-ajv8": "^6.1.2",
@@ -73,7 +73,7 @@
73
73
  "wavesurfer.js": "^7.12.1"
74
74
  },
75
75
  "devDependencies": {
76
- "@djangocfg/typescript-config": "^2.1.91",
76
+ "@djangocfg/typescript-config": "^2.1.94",
77
77
  "@types/node": "^24.7.2",
78
78
  "@types/react": "^19.1.0",
79
79
  "@types/react-dom": "^19.1.0",
@@ -282,6 +282,35 @@ const createMarkdownComponents = (isUser: boolean = false, isCompact: boolean =
282
282
  ),
283
283
  };};
284
284
 
285
+ // Check if content contains markdown syntax or line breaks
286
+ const hasMarkdownSyntax = (text: string): boolean => {
287
+ // If there are line breaks (after trim), treat as markdown for proper paragraph rendering
288
+ if (text.trim().includes('\n')) {
289
+ return true;
290
+ }
291
+
292
+ // Common markdown patterns
293
+ const markdownPatterns = [
294
+ /^#{1,6}\s/m, // Headers
295
+ /\*\*[^*]+\*\*/, // Bold
296
+ /\*[^*]+\*/, // Italic
297
+ /__[^_]+__/, // Bold (underscore)
298
+ /_[^_]+_/, // Italic (underscore)
299
+ /\[.+\]\(.+\)/, // Links
300
+ /!\[.*\]\(.+\)/, // Images
301
+ /```[\s\S]*```/, // Code blocks
302
+ /`[^`]+`/, // Inline code
303
+ /^\s*[-*+]\s/m, // Unordered lists
304
+ /^\s*\d+\.\s/m, // Ordered lists
305
+ /^\s*>/m, // Blockquotes
306
+ /\|.+\|/, // Tables
307
+ /^---+$/m, // Horizontal rules
308
+ /~~[^~]+~~/, // Strikethrough
309
+ ];
310
+
311
+ return markdownPatterns.some(pattern => pattern.test(text));
312
+ };
313
+
285
314
  /**
286
315
  * MarkdownMessage - Renders markdown content with syntax highlighting and GFM support
287
316
  *
@@ -291,6 +320,7 @@ const createMarkdownComponents = (isUser: boolean = false, isCompact: boolean =
291
320
  * - Mermaid diagram rendering
292
321
  * - Tables, lists, blockquotes
293
322
  * - User/assistant styling modes
323
+ * - Plain text optimization (skips ReactMarkdown for simple text)
294
324
  *
295
325
  * @example
296
326
  * ```tsx
@@ -306,11 +336,25 @@ export const MarkdownMessage: React.FC<MarkdownMessageProps> = ({
306
336
  isUser = false,
307
337
  isCompact = false,
308
338
  }) => {
339
+ // Trim content to remove leading/trailing whitespace and empty lines
340
+ const trimmedContent = content.trim();
341
+
309
342
  const components = React.useMemo(() => createMarkdownComponents(isUser, isCompact), [isUser, isCompact]);
310
343
 
311
344
  const textSizeClass = isCompact ? 'text-xs' : 'text-sm';
312
345
  const proseClass = isCompact ? 'prose-xs' : 'prose-sm';
313
346
 
347
+ // For plain text without markdown, render directly without ReactMarkdown
348
+ const isPlainText = !hasMarkdownSyntax(trimmedContent);
349
+
350
+ if (isPlainText) {
351
+ return (
352
+ <span className={`${textSizeClass} leading-relaxed break-words ${className}`}>
353
+ {trimmedContent}
354
+ </span>
355
+ );
356
+ }
357
+
314
358
  return (
315
359
  <div
316
360
  className={`
@@ -331,7 +375,7 @@ export const MarkdownMessage: React.FC<MarkdownMessageProps> = ({
331
375
  remarkPlugins={[remarkGfm]}
332
376
  components={components}
333
377
  >
334
- {content}
378
+ {trimmedContent}
335
379
  </ReactMarkdown>
336
380
  </div>
337
381
  );