@schandlergarcia/sf-web-components 1.8.0 → 1.9.0
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/components/library/cards/SemanticTableCard.d.ts +1 -1
- package/dist/components/library/chat/ChatBar.d.ts +14 -11
- package/dist/components/library/chat/ChatBar.js +2 -3
- package/dist/components/library/chat/ChatBar.js.map +1 -1
- package/dist/components/library/chat/ChatInput.d.ts +9 -8
- package/dist/components/library/chat/ChatInput.js.map +1 -1
- package/dist/components/library/chat/ChatMessage.d.ts +17 -4
- package/dist/components/library/chat/ChatMessage.js.map +1 -1
- package/dist/components/library/chat/ChatMessageList.d.ts +11 -8
- package/dist/components/library/chat/ChatMessageList.js.map +1 -1
- package/dist/components/library/chat/ChatPanel.d.ts +16 -12
- package/dist/components/library/chat/ChatPanel.js +8 -9
- package/dist/components/library/chat/ChatPanel.js.map +1 -1
- package/dist/components/library/chat/ChatSuggestions.d.ts +5 -4
- package/dist/components/library/chat/ChatSuggestions.js +2 -3
- package/dist/components/library/chat/ChatSuggestions.js.map +1 -1
- package/dist/components/library/chat/ChatToolCall.d.ts +11 -3
- package/dist/components/library/chat/ChatToolCall.js.map +1 -1
- package/dist/components/library/chat/ChatTypingIndicator.d.ts +4 -3
- package/dist/components/library/chat/ChatTypingIndicator.js +2 -3
- package/dist/components/library/chat/ChatTypingIndicator.js.map +1 -1
- package/dist/components/library/chat/ChatWelcome.d.ts +9 -7
- package/dist/components/library/chat/ChatWelcome.js +6 -7
- package/dist/components/library/chat/ChatWelcome.js.map +1 -1
- package/dist/components/library/chat/index.d.ts +10 -0
- package/dist/components/library/chat/useChatState.d.ts +36 -11
- package/dist/components/library/chat/useChatState.js +63 -46
- package/dist/components/library/chat/useChatState.js.map +1 -1
- package/dist/components/library/data/DataModeProvider.d.ts +15 -11
- package/dist/components/library/data/DataModeProvider.js +1 -1
- package/dist/components/library/data/DataModeProvider.js.map +1 -1
- package/dist/components/library/data/DataModeToggle.d.ts +4 -3
- package/dist/components/library/data/DataModeToggle.js +4 -5
- package/dist/components/library/data/DataModeToggle.js.map +1 -1
- package/dist/components/library/data/chartDataProvider.d.ts +41 -3
- package/dist/components/library/data/filterUtils.d.ts +38 -9
- package/dist/components/library/data/filterUtils.js.map +1 -1
- package/dist/components/library/data/useDataSource.d.ts +6 -4
- package/dist/components/library/data/useDataSource.js.map +1 -1
- package/dist/components/library/data/usePageFilters.d.ts +31 -5
- package/dist/components/library/data/usePageFilters.js +6 -2
- package/dist/components/library/data/usePageFilters.js.map +1 -1
- package/dist/components/library/index.d.ts +92 -73
- package/dist/components/library/index.js +25 -25
- package/dist/components/library/index.js.map +1 -1
- package/dist/components/library/skeletons/CardSkeleton.d.ts +5 -4
- package/dist/components/library/skeletons/CardSkeleton.js +2 -3
- package/dist/components/library/skeletons/CardSkeleton.js.map +1 -1
- package/dist/components/library/theme/AppThemeProvider.d.ts +13 -50
- package/dist/components/library/theme/AppThemeProvider.js.map +1 -1
- package/dist/components/library/theme/tokens.d.ts +45 -44
- package/dist/components/library/theme/tokens.js.map +1 -1
- package/package.json +1 -1
- package/src/components/library/cards/SemanticMetricCard.tsx +1 -1
- package/src/components/library/cards/SemanticTableCard.tsx +3 -3
- package/src/components/library/chat/{ChatBar.jsx → ChatBar.tsx} +19 -8
- package/src/components/library/chat/{ChatInput.jsx → ChatInput.tsx} +13 -11
- package/src/components/library/chat/{ChatMessage.jsx → ChatMessage.tsx} +22 -9
- package/src/components/library/chat/{ChatMessageList.jsx → ChatMessageList.tsx} +13 -11
- package/src/components/library/chat/{ChatPanel.jsx → ChatPanel.tsx} +16 -13
- package/src/components/library/chat/{ChatSuggestions.jsx → ChatSuggestions.tsx} +6 -5
- package/src/components/library/chat/{ChatToolCall.jsx → ChatToolCall.tsx} +14 -4
- package/src/components/library/chat/{ChatTypingIndicator.jsx → ChatTypingIndicator.tsx} +5 -2
- package/src/components/library/chat/{ChatWelcome.jsx → ChatWelcome.tsx} +9 -7
- package/src/components/library/chat/index.tsx +26 -0
- package/src/components/library/chat/useChatState.tsx +181 -0
- package/src/components/library/data/{DataModeProvider.jsx → DataModeProvider.tsx} +25 -8
- package/src/components/library/data/{DataModeToggle.jsx → DataModeToggle.tsx} +5 -2
- package/src/components/library/data/{chartDataProvider.jsx → chartDataProvider.tsx} +49 -5
- package/src/components/library/data/{filterUtils.jsx → filterUtils.tsx} +58 -12
- package/src/components/library/data/{useDataSource.jsx → useDataSource.tsx} +9 -2
- package/src/components/library/data/{usePageFilters.jsx → usePageFilters.tsx} +49 -9
- package/src/components/library/{index.jsx → index.ts} +14 -14
- package/src/components/library/skeletons/{CardSkeleton.jsx → CardSkeleton.tsx} +5 -4
- package/src/components/library/theme/{AppThemeProvider.jsx → AppThemeProvider.tsx} +20 -7
- package/src/components/library/theme/{tokens.jsx → tokens.tsx} +37 -3
- package/src/components/library/chat/index.jsx +0 -10
- package/src/components/library/chat/useChatState.jsx +0 -130
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { tokens, getTokenCSSProperties } from "./tokens";
|
|
2
|
+
import { tokens, getTokenCSSProperties, Tokens } from "./tokens";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export type ThemeMode = "light" | "dark";
|
|
5
|
+
|
|
6
|
+
export interface ThemeModeContextValue {
|
|
7
|
+
mode: ThemeMode;
|
|
8
|
+
theme: Tokens;
|
|
9
|
+
toggle: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const ThemeModeContext = React.createContext<ThemeModeContextValue>({
|
|
5
13
|
mode: "light",
|
|
6
14
|
theme: tokens,
|
|
7
15
|
toggle: () => {}
|
|
@@ -9,14 +17,14 @@ const ThemeModeContext = React.createContext({
|
|
|
9
17
|
|
|
10
18
|
const STORAGE_KEY = "app-color-mode";
|
|
11
19
|
|
|
12
|
-
function applyHtmlDarkClass(mode) {
|
|
20
|
+
function applyHtmlDarkClass(mode: ThemeMode): void {
|
|
13
21
|
if (typeof document === "undefined") return;
|
|
14
22
|
const root = document.documentElement;
|
|
15
23
|
if (mode === "dark") root.classList.add("dark");
|
|
16
24
|
else root.classList.remove("dark");
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
function applyTokenCSSProperties() {
|
|
27
|
+
function applyTokenCSSProperties(): void {
|
|
20
28
|
if (typeof document === "undefined") return;
|
|
21
29
|
const root = document.documentElement;
|
|
22
30
|
const props = getTokenCSSProperties();
|
|
@@ -25,12 +33,17 @@ function applyTokenCSSProperties() {
|
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
|
|
28
|
-
export function useThemeMode() {
|
|
36
|
+
export function useThemeMode(): ThemeModeContextValue {
|
|
29
37
|
return React.useContext(ThemeModeContext);
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
export
|
|
33
|
-
|
|
40
|
+
export interface AppThemeProviderProps {
|
|
41
|
+
initialMode?: ThemeMode;
|
|
42
|
+
children: React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default function AppThemeProvider({ initialMode = "light", children }: AppThemeProviderProps) {
|
|
46
|
+
const [mode, setMode] = React.useState<ThemeMode>(initialMode);
|
|
34
47
|
|
|
35
48
|
React.useEffect(() => {
|
|
36
49
|
applyTokenCSSProperties();
|
|
@@ -10,7 +10,41 @@
|
|
|
10
10
|
* and tailwind.config.js references them via var(--color-brand-*).
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface ColorShades {
|
|
14
|
+
50: string;
|
|
15
|
+
100: string;
|
|
16
|
+
200: string;
|
|
17
|
+
300: string;
|
|
18
|
+
400: string;
|
|
19
|
+
500: string;
|
|
20
|
+
600: string;
|
|
21
|
+
700: string;
|
|
22
|
+
800: string;
|
|
23
|
+
900: string;
|
|
24
|
+
950: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface Tokens {
|
|
28
|
+
colors: {
|
|
29
|
+
brand: ColorShades;
|
|
30
|
+
accent: ColorShades;
|
|
31
|
+
};
|
|
32
|
+
fonts: {
|
|
33
|
+
sans: string;
|
|
34
|
+
mono: string;
|
|
35
|
+
};
|
|
36
|
+
radius: {
|
|
37
|
+
sm: string;
|
|
38
|
+
md: string;
|
|
39
|
+
lg: string;
|
|
40
|
+
};
|
|
41
|
+
spacing: {
|
|
42
|
+
pageX: string;
|
|
43
|
+
pageY: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const tokens: Tokens = {
|
|
14
48
|
colors: {
|
|
15
49
|
brand: {
|
|
16
50
|
50: "#EEF2FF",
|
|
@@ -61,8 +95,8 @@ export const tokens = {
|
|
|
61
95
|
* Generates CSS custom property assignments from the token palettes.
|
|
62
96
|
* Used by AppThemeProvider to inject on :root at runtime.
|
|
63
97
|
*/
|
|
64
|
-
export function getTokenCSSProperties() {
|
|
65
|
-
const props = {};
|
|
98
|
+
export function getTokenCSSProperties(): Record<string, string> {
|
|
99
|
+
const props: Record<string, string> = {};
|
|
66
100
|
for (const [palette, shades] of Object.entries(tokens.colors)) {
|
|
67
101
|
for (const [shade, value] of Object.entries(shades)) {
|
|
68
102
|
props[`--color-${palette}-${shade}`] = value;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as ChatPanel } from "./ChatPanel";
|
|
2
|
-
export { default as ChatBar } from "./ChatBar";
|
|
3
|
-
export { default as ChatMessageList } from "./ChatMessageList";
|
|
4
|
-
export { default as ChatMessage } from "./ChatMessage";
|
|
5
|
-
export { default as ChatInput } from "./ChatInput";
|
|
6
|
-
export { default as ChatTypingIndicator } from "./ChatTypingIndicator";
|
|
7
|
-
export { default as ChatSuggestions } from "./ChatSuggestions";
|
|
8
|
-
export { default as ChatToolCall } from "./ChatToolCall";
|
|
9
|
-
export { default as ChatWelcome } from "./ChatWelcome";
|
|
10
|
-
export { default as useChatState } from "./useChatState";
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
let _nextId = 1;
|
|
4
|
-
function uid() {
|
|
5
|
-
return `msg-${Date.now()}-${_nextId++}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Core state management hook for AI chat.
|
|
10
|
-
*
|
|
11
|
-
* @param {Object} options
|
|
12
|
-
* @param {Array} options.initialMessages — seed the conversation
|
|
13
|
-
* @param {Function} options.onSend — async (userMessage, allMessages) => assistantMessage | void
|
|
14
|
-
* Return a message object to add it, or use appendChunk / addMessage for streaming.
|
|
15
|
-
*
|
|
16
|
-
* @returns {Object}
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* const chat = useChatState({
|
|
20
|
-
* onSend: async (msg, history) => {
|
|
21
|
-
* const res = await fetch("/api/chat", { method: "POST", body: JSON.stringify({ messages: history }) });
|
|
22
|
-
* const data = await res.json();
|
|
23
|
-
* return { role: "assistant", content: data.reply, components: data.components };
|
|
24
|
-
* },
|
|
25
|
-
* });
|
|
26
|
-
*/
|
|
27
|
-
export default function useChatState({ initialMessages = [], onSend } = {}) {
|
|
28
|
-
const [messages, setMessages] = useState(() =>
|
|
29
|
-
initialMessages.map((m) => ({ id: uid(), timestamp: new Date().toISOString(), ...m }))
|
|
30
|
-
);
|
|
31
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
32
|
-
const [isStreaming, setIsStreaming] = useState(false);
|
|
33
|
-
const [error, setError] = useState(null);
|
|
34
|
-
const onSendRef = useRef(onSend);
|
|
35
|
-
onSendRef.current = onSend;
|
|
36
|
-
|
|
37
|
-
const addMessage = useCallback((msg) => {
|
|
38
|
-
const full = { id: uid(), timestamp: new Date().toISOString(), ...msg };
|
|
39
|
-
setMessages((prev) => [...prev, full]);
|
|
40
|
-
return full.id;
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
const updateMessage = useCallback((id, updates) => {
|
|
44
|
-
setMessages((prev) =>
|
|
45
|
-
prev.map((m) => (m.id === id ? { ...m, ...updates } : m))
|
|
46
|
-
);
|
|
47
|
-
}, []);
|
|
48
|
-
|
|
49
|
-
const appendChunk = useCallback((id, chunk) => {
|
|
50
|
-
setMessages((prev) =>
|
|
51
|
-
prev.map((m) =>
|
|
52
|
-
m.id === id ? { ...m, content: (m.content ?? "") + chunk } : m
|
|
53
|
-
)
|
|
54
|
-
);
|
|
55
|
-
}, []);
|
|
56
|
-
|
|
57
|
-
const removeMessage = useCallback((id) => {
|
|
58
|
-
setMessages((prev) => prev.filter((m) => m.id !== id));
|
|
59
|
-
}, []);
|
|
60
|
-
|
|
61
|
-
const clearMessages = useCallback(() => {
|
|
62
|
-
setMessages([]);
|
|
63
|
-
setError(null);
|
|
64
|
-
}, []);
|
|
65
|
-
|
|
66
|
-
const sendMessage = useCallback(
|
|
67
|
-
async (content, extra = {}) => {
|
|
68
|
-
if (!content?.trim()) return;
|
|
69
|
-
setError(null);
|
|
70
|
-
|
|
71
|
-
const userMsg = { role: "user", content: content.trim(), ...extra };
|
|
72
|
-
const userId = uid();
|
|
73
|
-
const fullUser = { ...userMsg, id: userId, timestamp: new Date().toISOString() };
|
|
74
|
-
|
|
75
|
-
setMessages((prev) => [...prev, fullUser]);
|
|
76
|
-
setIsLoading(true);
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
const allMsgs = [...messages, fullUser];
|
|
80
|
-
const result = await onSendRef.current?.(fullUser, allMsgs, {
|
|
81
|
-
addMessage,
|
|
82
|
-
updateMessage,
|
|
83
|
-
appendChunk,
|
|
84
|
-
setStreaming: setIsStreaming,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (result && typeof result === "object" && result.role) {
|
|
88
|
-
addMessage(result);
|
|
89
|
-
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
setError(err?.message ?? "Failed to send message");
|
|
92
|
-
addMessage({
|
|
93
|
-
role: "system",
|
|
94
|
-
content: err?.message ?? "Something went wrong. Please try again.",
|
|
95
|
-
isError: true,
|
|
96
|
-
});
|
|
97
|
-
} finally {
|
|
98
|
-
setIsLoading(false);
|
|
99
|
-
setIsStreaming(false);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
[messages, addMessage, updateMessage, appendChunk]
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const retryLast = useCallback(() => {
|
|
106
|
-
const lastUser = [...messages].reverse().find((m) => m.role === "user");
|
|
107
|
-
if (!lastUser) return;
|
|
108
|
-
|
|
109
|
-
const idx = messages.lastIndexOf(lastUser);
|
|
110
|
-
setMessages(messages.slice(0, idx));
|
|
111
|
-
setError(null);
|
|
112
|
-
|
|
113
|
-
sendMessage(lastUser.content);
|
|
114
|
-
}, [messages, sendMessage]);
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
messages,
|
|
118
|
-
isLoading,
|
|
119
|
-
isStreaming,
|
|
120
|
-
error,
|
|
121
|
-
sendMessage,
|
|
122
|
-
addMessage,
|
|
123
|
-
updateMessage,
|
|
124
|
-
appendChunk,
|
|
125
|
-
removeMessage,
|
|
126
|
-
clearMessages,
|
|
127
|
-
retryLast,
|
|
128
|
-
setError,
|
|
129
|
-
};
|
|
130
|
-
}
|