@rlx-ui/mcp 0.0.10 → 0.0.11
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/data/registry.json +3 -3
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/data/registry.json
CHANGED
|
@@ -1379,7 +1379,7 @@
|
|
|
1379
1379
|
"packageName": "@rlx-components/streaming-text",
|
|
1380
1380
|
"slug": "streaming-text",
|
|
1381
1381
|
"category": "component",
|
|
1382
|
-
"sourceCode": "\"use client\";\n\nimport { cn } from \"@rlx-widgets/base\";\nimport {\n ComponentProps,\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport {\n type StreamingState,\n type StreamingTextControls,\n type StreamingTextProps,\n} from \"./types\";\n\nexport const StreamingText = forwardRef<\n StreamingTextControls,\n StreamingTextProps\n>(\n (\n {\n text,\n className,\n delay = 10,\n indicator,\n autoStart = false,\n onStateChange,\n },\n ref\n ) => {\n const intervalRef = useRef<NodeJS.Timeout | null>(null);\n const [displayedText, setDisplayedText] = useState(\"\");\n const streamingStateRef = useRef<StreamingState>(\"idle\");\n const charIndexRef = useRef(0);\n\n // Helper to clear interval\n const clearIntervalSafe = useCallback(() => {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n // Update state and notify callback\n const updateState = useCallback(\n (newState: StreamingState) => {\n streamingStateRef.current = newState;\n onStateChange?.(newState);\n },\n [onStateChange]\n );\n\n // Helper to reset internal state\n const resetInternalState = useCallback(() => {\n charIndexRef.current = 0;\n setDisplayedText(\"\");\n }, []);\n\n const handleStreaming = useCallback(() => {\n // Don't stream if paused or completed\n if (streamingStateRef.current !== \"streaming\") {\n return;\n }\n\n if (charIndexRef.current >= text.length) {\n clearIntervalSafe();\n updateState(\"completed\");\n return;\n }\n const streamedText = text.slice(0, charIndexRef.current + 1);\n setDisplayedText(streamedText);\n ++charIndexRef.current;\n }, [text, clearIntervalSafe, updateState]);\n\n // Helper to start interval\n const startInterval = useCallback(\n (callback: () => void, delayMs: number) => {\n clearIntervalSafe();\n intervalRef.current = setInterval(callback, delayMs);\n },\n [clearIntervalSafe]\n );\n\n // Control methods\n const start = useCallback(() => {\n const currentState = streamingStateRef.current;\n const isCompleted =\n currentState === \"completed\" || charIndexRef.current >= text.length;\n\n if (isCompleted) {\n resetInternalState();\n updateState(\"idle\");\n }\n\n const newState = streamingStateRef.current;\n if (newState === \"idle\" || newState === \"paused\") {\n const validDelay = Math.max(0, delay);\n updateState(\"streaming\");\n\n // Start immediately and then set interval\n handleStreaming();\n startInterval(handleStreaming, validDelay);\n }\n }, [text
|
|
1382
|
+
"sourceCode": "\"use client\";\n\nimport { cn } from \"@rlx-widgets/base\";\nimport {\n ComponentProps,\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useRef,\n useState,\n} from \"react\";\nimport {\n type StreamingState,\n type StreamingTextControls,\n type StreamingTextProps,\n} from \"./types\";\n\nexport const StreamingText = forwardRef<\n StreamingTextControls,\n StreamingTextProps\n>(\n (\n {\n text,\n className,\n delay = 10,\n indicator,\n autoStart = false,\n onStateChange,\n },\n ref\n ) => {\n const intervalRef = useRef<NodeJS.Timeout | null>(null);\n const [displayedText, setDisplayedText] = useState(\"\");\n const streamingStateRef = useRef<StreamingState>(\"idle\");\n const charIndexRef = useRef(0);\n\n // Helper to clear interval\n const clearIntervalSafe = useCallback(() => {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n // Update state and notify callback\n const updateState = useCallback(\n (newState: StreamingState) => {\n streamingStateRef.current = newState;\n onStateChange?.(newState);\n },\n [onStateChange]\n );\n\n // Helper to reset internal state\n const resetInternalState = useCallback(() => {\n charIndexRef.current = 0;\n setDisplayedText(\"\");\n }, []);\n\n const handleStreaming = useCallback(() => {\n // Don't stream if paused or completed\n if (streamingStateRef.current !== \"streaming\") {\n return;\n }\n\n if (charIndexRef.current >= text.length) {\n clearIntervalSafe();\n updateState(\"completed\");\n return;\n }\n const streamedText = text.slice(0, charIndexRef.current + 1);\n setDisplayedText(streamedText);\n ++charIndexRef.current;\n }, [text, clearIntervalSafe, updateState]);\n\n // Helper to start interval\n const startInterval = useCallback(\n (callback: () => void, delayMs: number) => {\n clearIntervalSafe();\n intervalRef.current = setInterval(callback, delayMs);\n },\n [clearIntervalSafe]\n );\n\n // Control methods\n const start = useCallback(() => {\n const currentState = streamingStateRef.current;\n const isCompleted =\n currentState === \"completed\" || charIndexRef.current >= text.length;\n\n if (isCompleted) {\n resetInternalState();\n updateState(\"idle\");\n }\n\n const newState = streamingStateRef.current;\n if (newState === \"idle\" || newState === \"paused\") {\n const validDelay = Math.max(0, delay);\n updateState(\"streaming\");\n\n // Start immediately and then set interval\n handleStreaming();\n startInterval(handleStreaming, validDelay);\n }\n }, [\n text,\n delay,\n handleStreaming,\n updateState,\n resetInternalState,\n startInterval,\n ]);\n\n const pause = useCallback(() => {\n if (streamingStateRef.current === \"streaming\") {\n clearIntervalSafe();\n updateState(\"paused\");\n }\n }, [clearIntervalSafe, updateState]);\n\n const reset = useCallback(() => {\n clearIntervalSafe();\n resetInternalState();\n updateState(\"idle\");\n }, [clearIntervalSafe, resetInternalState, updateState]);\n\n const finish = useCallback(() => {\n clearIntervalSafe();\n\n setDisplayedText(text);\n charIndexRef.current = text.length;\n\n updateState(\"completed\");\n }, [clearIntervalSafe, text, updateState]);\n\n // Expose control methods via ref\n useImperativeHandle(\n ref,\n () => ({\n start,\n pause,\n reset,\n finish,\n getState: () => streamingStateRef.current,\n }),\n [start, pause, reset, finish]\n );\n\n // Reset when text or delay changes\n useEffect(() => {\n clearIntervalSafe();\n resetInternalState();\n updateState(\"idle\");\n\n // Handle empty text\n if (!text) {\n return;\n }\n\n // Start streaming if autoStart is enabled\n if (autoStart) {\n const validDelay = Math.max(0, delay);\n updateState(\"streaming\");\n\n // Start immediately and then set interval\n const initialText = text.slice(0, 1);\n setDisplayedText(initialText);\n charIndexRef.current = 1;\n\n startInterval(handleStreaming, validDelay);\n }\n }, [\n text,\n delay,\n autoStart,\n handleStreaming,\n updateState,\n clearIntervalSafe,\n resetInternalState,\n startInterval,\n ]);\n\n // Cleanup on unmount\n useEffect(() => {\n return clearIntervalSafe;\n }, [clearIntervalSafe]);\n\n return (\n <div className={cn(\"whitespace-pre-wrap\", className)}>\n {displayedText}\n {indicator}\n </div>\n );\n }\n);\n\nStreamingText.displayName = \"StreamingText\";\n\nexport type StreamingTextIndicatorProps = ComponentProps<\"span\">;\n\nexport const StreamingTextIndicator = ({\n className,\n children,\n ...props\n}: StreamingTextIndicatorProps) => {\n return (\n <span\n className={cn(\"inline-block animate-pulse\", className)}\n aria-hidden=\"true\"\n {...props}\n >\n {children ?? \" ▋\"}\n </span>\n );\n};\n",
|
|
1383
1383
|
"demos": [
|
|
1384
1384
|
{
|
|
1385
1385
|
"name": "default",
|
|
@@ -1388,7 +1388,7 @@
|
|
|
1388
1388
|
],
|
|
1389
1389
|
"sourceFiles": {
|
|
1390
1390
|
"types/StreamingState.t.ts": "export type StreamingState = \"idle\" | \"streaming\" | \"paused\" | \"completed\";\n",
|
|
1391
|
-
"types/StreamingTextControls.t.ts": "import { StreamingState } from \"./StreamingState.t\";\n\nexport type StreamingTextControls = {\n /**\n * Start or resume streaming.\n */\n start: () => void;\n /**\n * Pause streaming (can be resumed later).\n */\n pause: () => void;\n /**\n * Reset streaming to the beginning (idle state).\n */\n reset: () => void;\n /**\n * Get the current streaming state.\n */\n getState: () => StreamingState;\n};\n",
|
|
1391
|
+
"types/StreamingTextControls.t.ts": "import { StreamingState } from \"./StreamingState.t\";\n\nexport type StreamingTextControls = {\n /**\n * Start or resume streaming.\n */\n start: () => void;\n /**\n * Pause streaming (can be resumed later).\n */\n pause: () => void;\n /**\n * Reset streaming to the beginning (idle state).\n */\n reset: () => void;\n /**\n * Finish streaming (display the entire text).\n */\n finish: () => void;\n /**\n * Get the current streaming state.\n */\n getState: () => StreamingState;\n};\n",
|
|
1392
1392
|
"types/StreamingTextProps.t.ts": "import { ReactNode } from \"react\";\nimport { StreamingState } from \"./StreamingState.t\";\n\nexport type StreamingTextProps = {\n text: string;\n className?: string;\n /**\n * The delay in milliseconds between each character.\n * @default 10\n */\n delay?: number;\n /**\n * Optional indicator to show while streaming (e.g., a blinking cursor).\n * Only displayed when streaming is in progress.\n */\n indicator?: ReactNode;\n /**\n * Whether to automatically start streaming on mount.\n * @default false\n */\n autoStart?: boolean;\n /**\n * Callback fired when streaming state changes.\n * Use this to handle state transitions (idle -> streaming -> paused -> completed).\n */\n onStateChange?: (state: StreamingState) => void;\n};\n"
|
|
1393
1393
|
}
|
|
1394
1394
|
},
|
|
@@ -1504,5 +1504,5 @@
|
|
|
1504
1504
|
"sourceCode": "export const isValidDate = (date: Date) => {\n return !Number.isNaN(date.getTime());\n};\n\nexport default isValidDate;\n"
|
|
1505
1505
|
}
|
|
1506
1506
|
],
|
|
1507
|
-
"extractedAt": "2025-11-
|
|
1507
|
+
"extractedAt": "2025-11-30T22:01:06.346Z"
|
|
1508
1508
|
}
|
package/dist/package.json
CHANGED