@colletdev/react 0.2.0 → 0.2.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.
@@ -1,11 +1,47 @@
1
1
  import type React from 'react';
2
2
  export interface MessagePartProps {
3
+ id?: string;
4
+ /** Content kind. Determines how the part renders. */
5
+ kind?: 'text' | 'tool-call' | 'tool-result' | 'thinking' | 'code-block' | 'error';
6
+ /** Connection to adjacent parts (for connected card groups). */
7
+ connection?: 'standalone' | 'first' | 'middle' | 'last';
8
+ /** Component size. */
9
+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
10
+ /** Plain text content. */
11
+ content?: string;
12
+ /** Pre-rendered HTML content. */
13
+ htmlContent?: string;
14
+ /** Tool/function name (for tool-call and tool-result kinds). */
15
+ toolName?: string;
16
+ /** Tool arguments text (for tool-call kind). */
17
+ toolArguments?: string;
18
+ /** Tool execution status. */
19
+ toolStatus?: 'pending' | 'success' | 'error';
20
+ /** Tool action kind (determines icon). */
21
+ toolAction?: 'generic' | 'read' | 'write' | 'edit' | 'delete' | 'search';
22
+ /** Human-readable description. */
23
+ description?: string;
24
+ /** Whether tool result is collapsible. */
25
+ collapsible?: boolean;
26
+ /** Whether the thinking indicator is completed. */
27
+ completed?: boolean;
28
+ /** Border treatment. */
29
+ border?: 'auto' | 'none' | 'subtle';
30
+ /** Thinking label text. */
31
+ thinkingLabel?: string;
32
+ /** Code language hint (for code-block kind). */
33
+ language?: string;
34
+ /** Filename for code block title bar. */
35
+ filename?: string;
36
+ /** Enable markdown rendering for text content. */
37
+ markdown?: boolean;
3
38
  /** Enable streaming mode. Pauses WASM rendering. */
4
39
  stream?: boolean;
5
- className?: string;
6
- style?: React.CSSProperties;
7
40
  /** Fired when streaming ends (after sanitization pass). */
8
41
  onStreamEnd?: (e: CustomEvent) => void;
42
+ children?: React.ReactNode;
43
+ className?: string;
44
+ style?: React.CSSProperties;
9
45
  }
10
46
  export interface MessagePartRef {
11
47
  /** The underlying DOM element. */
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { forwardRef, useImperativeHandle, useRef } from 'react';
2
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
3
3
  export const MessagePart = forwardRef((props, forwardedRef) => {
4
4
  const ref = useRef(null);
5
5
  useImperativeHandle(forwardedRef, () => ({
@@ -20,17 +20,55 @@ export const MessagePart = forwardRef((props, forwardedRef) => {
20
20
  await el.endStream();
21
21
  },
22
22
  }));
23
- // Build attribute object
23
+ // Event listener for stream end
24
+ useEffect(() => {
25
+ const el = ref.current;
26
+ if (!el || !props.onStreamEnd)
27
+ return;
28
+ const handler = props.onStreamEnd;
29
+ el.addEventListener('cx-stream-end', handler);
30
+ return () => el.removeEventListener('cx-stream-end', handler);
31
+ }, [props.onStreamEnd]);
32
+ // Build attribute object — maps React props to kebab-case HTML attributes
24
33
  const attrs = {};
34
+ if (props.id != null)
35
+ attrs['id'] = props.id;
36
+ if (props.kind != null)
37
+ attrs['kind'] = props.kind;
38
+ if (props.connection != null)
39
+ attrs['connection'] = props.connection;
40
+ if (props.size != null)
41
+ attrs['size'] = props.size;
42
+ if (props.content != null)
43
+ attrs['content'] = props.content;
44
+ if (props.htmlContent != null)
45
+ attrs['html-content'] = props.htmlContent;
46
+ if (props.toolName != null)
47
+ attrs['tool-name'] = props.toolName;
48
+ if (props.toolArguments != null)
49
+ attrs['tool-arguments'] = props.toolArguments;
50
+ if (props.toolStatus != null)
51
+ attrs['tool-status'] = props.toolStatus;
52
+ if (props.toolAction != null)
53
+ attrs['tool-action'] = props.toolAction;
54
+ if (props.description != null)
55
+ attrs['description'] = props.description;
56
+ if (props.collapsible)
57
+ attrs['collapsible'] = '';
58
+ if (props.completed)
59
+ attrs['completed'] = '';
60
+ if (props.border != null)
61
+ attrs['border'] = props.border;
62
+ if (props.thinkingLabel != null)
63
+ attrs['thinking-label'] = props.thinkingLabel;
64
+ if (props.language != null)
65
+ attrs['language'] = props.language;
66
+ if (props.filename != null)
67
+ attrs['filename'] = props.filename;
68
+ if (props.markdown)
69
+ attrs['markdown'] = '';
25
70
  if (props.stream)
26
- attrs.stream = '';
27
- // Event listener setup
28
- const handleRef = (el) => {
29
- ref.current = el;
30
- if (el && props.onStreamEnd) {
31
- el.addEventListener('cx-stream-end', props.onStreamEnd);
32
- }
33
- };
34
- return (_jsx("cx-message-part", { ref: handleRef, ...attrs, className: props.className, style: props.style }));
71
+ attrs['stream'] = '';
72
+ return (_jsx("cx-message-part", { ref: ref, ...attrs, className: props.className, style: props.style, children: props.children }));
35
73
  });
36
74
  MessagePart.displayName = 'MessagePart';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colletdev/react",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "React wrappers for Collet Rust/WASM UI components",
5
5
  "type": "module",
6
6
  "main": "dist/generated/index.js",