@chaaskit/client 0.1.0 → 0.1.1
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/lib/index.js +53 -80
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/routes/AcceptInviteRoute.js +1 -1
- package/dist/lib/routes/AcceptInviteRoute.js.map +1 -1
- package/dist/lib/routes/AdminDashboardRoute.js +1 -1
- package/dist/lib/routes/AdminDashboardRoute.js.map +1 -1
- package/dist/lib/routes/AdminTeamRoute.js +1 -1
- package/dist/lib/routes/AdminTeamRoute.js.map +1 -1
- package/dist/lib/routes/AdminTeamsRoute.js +1 -1
- package/dist/lib/routes/AdminTeamsRoute.js.map +1 -1
- package/dist/lib/routes/AdminUsersRoute.js +1 -1
- package/dist/lib/routes/AdminUsersRoute.js.map +1 -1
- package/dist/lib/routes/ApiKeysRoute.js +1 -1
- package/dist/lib/routes/ApiKeysRoute.js.map +1 -1
- package/dist/lib/routes/AutomationsRoute.js +1 -1
- package/dist/lib/routes/AutomationsRoute.js.map +1 -1
- package/dist/lib/routes/ChatRoute.js +1 -1
- package/dist/lib/routes/ChatRoute.js.map +1 -1
- package/dist/lib/routes/DocumentsRoute.js +1 -1
- package/dist/lib/routes/DocumentsRoute.js.map +1 -1
- package/dist/lib/routes/OAuthConsentRoute.js +1 -1
- package/dist/lib/routes/OAuthConsentRoute.js.map +1 -1
- package/dist/lib/routes/PricingRoute.js +1 -1
- package/dist/lib/routes/PricingRoute.js.map +1 -1
- package/dist/lib/routes/PrivacyRoute.js +1 -1
- package/dist/lib/routes/PrivacyRoute.js.map +1 -1
- package/dist/lib/routes/TeamSettingsRoute.js +1 -1
- package/dist/lib/routes/TeamSettingsRoute.js.map +1 -1
- package/dist/lib/routes/TermsRoute.js +1 -1
- package/dist/lib/routes/TermsRoute.js.map +1 -1
- package/dist/lib/routes/VerifyEmailRoute.js +1 -1
- package/dist/lib/routes/VerifyEmailRoute.js.map +1 -1
- package/dist/lib/ssr-utils.js +44 -1
- package/dist/lib/ssr-utils.js.map +1 -1
- package/dist/lib/ssr.js +23 -0
- package/dist/lib/ssr.js.map +1 -1
- package/dist/lib/styles.css +21 -62
- package/package.json +7 -2
- package/src/contexts/ConfigContext.tsx +42 -4
- package/src/contexts/ThemeContext.tsx +39 -68
- package/src/index.tsx +8 -2
- package/src/routes/AcceptInviteRoute.tsx +1 -1
- package/src/routes/AdminDashboardRoute.tsx +1 -1
- package/src/routes/AdminTeamRoute.tsx +1 -1
- package/src/routes/AdminTeamsRoute.tsx +1 -1
- package/src/routes/AdminUsersRoute.tsx +1 -1
- package/src/routes/ApiKeysRoute.tsx +1 -1
- package/src/routes/AutomationsRoute.tsx +1 -1
- package/src/routes/ChatRoute.tsx +2 -1
- package/src/routes/DocumentsRoute.tsx +1 -1
- package/src/routes/OAuthConsentRoute.tsx +1 -1
- package/src/routes/PricingRoute.tsx +1 -1
- package/src/routes/PrivacyRoute.tsx +1 -1
- package/src/routes/TeamSettingsRoute.tsx +1 -1
- package/src/routes/TermsRoute.tsx +1 -1
- package/src/routes/VerifyEmailRoute.tsx +1 -1
- package/src/ssr-utils.tsx +80 -1
- package/src/ssr.ts +59 -0
- package/src/styles/index.css +16 -63
- package/src/tailwind-preset.js +360 -0
package/dist/lib/index.js
CHANGED
|
@@ -132,6 +132,48 @@ function useAuth() {
|
|
|
132
132
|
}
|
|
133
133
|
return context;
|
|
134
134
|
}
|
|
135
|
+
const ThemeContext = createContext(void 0);
|
|
136
|
+
const DEFAULT_THEMES = ["light", "dark"];
|
|
137
|
+
const DEFAULT_THEME = "dark";
|
|
138
|
+
function ThemeProvider({
|
|
139
|
+
children,
|
|
140
|
+
availableThemes = DEFAULT_THEMES,
|
|
141
|
+
defaultTheme = DEFAULT_THEME
|
|
142
|
+
}) {
|
|
143
|
+
const [theme, setThemeState] = useState(() => {
|
|
144
|
+
if (typeof window !== "undefined") {
|
|
145
|
+
const stored = localStorage.getItem("theme");
|
|
146
|
+
if (stored && availableThemes.includes(stored)) {
|
|
147
|
+
return stored;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return defaultTheme;
|
|
151
|
+
});
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
document.documentElement.setAttribute("data-theme", theme);
|
|
154
|
+
localStorage.setItem("theme", theme);
|
|
155
|
+
document.cookie = `theme=${theme};path=/;max-age=31536000;SameSite=Lax`;
|
|
156
|
+
}, [theme]);
|
|
157
|
+
function setTheme(newTheme) {
|
|
158
|
+
if (availableThemes.includes(newTheme)) {
|
|
159
|
+
setThemeState(newTheme);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: { theme, setTheme, availableThemes }, children });
|
|
163
|
+
}
|
|
164
|
+
function useTheme() {
|
|
165
|
+
const context = useContext(ThemeContext);
|
|
166
|
+
if (context === void 0) {
|
|
167
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
168
|
+
}
|
|
169
|
+
return context;
|
|
170
|
+
}
|
|
171
|
+
function getInjectedConfig() {
|
|
172
|
+
if (typeof window !== "undefined" && window.__CHAASKIT_CONFIG__) {
|
|
173
|
+
return window.__CHAASKIT_CONFIG__;
|
|
174
|
+
}
|
|
175
|
+
return void 0;
|
|
176
|
+
}
|
|
135
177
|
const defaultConfig = {
|
|
136
178
|
app: {
|
|
137
179
|
name: "AI Chat",
|
|
@@ -296,10 +338,15 @@ const ConfigContext = createContext({
|
|
|
296
338
|
config: defaultConfig,
|
|
297
339
|
configLoaded: false
|
|
298
340
|
});
|
|
299
|
-
function ConfigProvider({ children }) {
|
|
300
|
-
const
|
|
301
|
-
const
|
|
341
|
+
function ConfigProvider({ children, initialConfig }) {
|
|
342
|
+
const injectedConfig = getInjectedConfig();
|
|
343
|
+
const preloadedConfig = initialConfig || injectedConfig;
|
|
344
|
+
const [config, setConfig] = useState(
|
|
345
|
+
preloadedConfig ? { ...defaultConfig, ...preloadedConfig } : defaultConfig
|
|
346
|
+
);
|
|
347
|
+
const [configLoaded, setConfigLoaded] = useState(!!preloadedConfig);
|
|
302
348
|
useEffect(() => {
|
|
349
|
+
if (preloadedConfig) return;
|
|
303
350
|
async function loadConfig() {
|
|
304
351
|
try {
|
|
305
352
|
const response = await fetch("/api/config");
|
|
@@ -317,7 +364,7 @@ function ConfigProvider({ children }) {
|
|
|
317
364
|
}
|
|
318
365
|
}
|
|
319
366
|
loadConfig();
|
|
320
|
-
}, []);
|
|
367
|
+
}, [preloadedConfig]);
|
|
321
368
|
return /* @__PURE__ */ jsx(ConfigContext.Provider, { value: { config, configLoaded }, children });
|
|
322
369
|
}
|
|
323
370
|
function useConfig() {
|
|
@@ -326,80 +373,6 @@ function useConfig() {
|
|
|
326
373
|
function useConfigLoaded() {
|
|
327
374
|
return useContext(ConfigContext).configLoaded;
|
|
328
375
|
}
|
|
329
|
-
const ThemeContext = createContext(void 0);
|
|
330
|
-
function ThemeProvider({ children }) {
|
|
331
|
-
const config = useConfig();
|
|
332
|
-
const [theme, setThemeState] = useState(() => {
|
|
333
|
-
const stored = localStorage.getItem("theme");
|
|
334
|
-
if (stored && config.theming.themes[stored]) {
|
|
335
|
-
return stored;
|
|
336
|
-
}
|
|
337
|
-
return config.theming.defaultTheme;
|
|
338
|
-
});
|
|
339
|
-
const availableThemes = Object.keys(config.theming.themes);
|
|
340
|
-
useEffect(() => {
|
|
341
|
-
document.documentElement.setAttribute("data-theme", theme);
|
|
342
|
-
localStorage.setItem("theme", theme);
|
|
343
|
-
document.cookie = `theme=${theme};path=/;max-age=31536000;SameSite=Lax`;
|
|
344
|
-
const themeConfig = config.theming.themes[theme];
|
|
345
|
-
if (themeConfig) {
|
|
346
|
-
const root2 = document.documentElement;
|
|
347
|
-
const colors = themeConfig.colors;
|
|
348
|
-
Object.entries(colors).forEach(([key, value]) => {
|
|
349
|
-
const cssKey = `--color-${key.replace(/([A-Z])/g, "-$1").toLowerCase()}`;
|
|
350
|
-
const rgb = hexToRgb(value);
|
|
351
|
-
if (rgb) {
|
|
352
|
-
root2.style.setProperty(cssKey, `${rgb.r} ${rgb.g} ${rgb.b}`);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
document.documentElement.style.setProperty(
|
|
357
|
-
"--font-sans",
|
|
358
|
-
config.theming.fonts.sans
|
|
359
|
-
);
|
|
360
|
-
document.documentElement.style.setProperty(
|
|
361
|
-
"--font-mono",
|
|
362
|
-
config.theming.fonts.mono
|
|
363
|
-
);
|
|
364
|
-
document.documentElement.style.setProperty(
|
|
365
|
-
"--radius-sm",
|
|
366
|
-
config.theming.borderRadius.sm
|
|
367
|
-
);
|
|
368
|
-
document.documentElement.style.setProperty(
|
|
369
|
-
"--radius-md",
|
|
370
|
-
config.theming.borderRadius.md
|
|
371
|
-
);
|
|
372
|
-
document.documentElement.style.setProperty(
|
|
373
|
-
"--radius-lg",
|
|
374
|
-
config.theming.borderRadius.lg
|
|
375
|
-
);
|
|
376
|
-
document.documentElement.style.setProperty(
|
|
377
|
-
"--radius-full",
|
|
378
|
-
config.theming.borderRadius.full
|
|
379
|
-
);
|
|
380
|
-
}, [theme, config.theming]);
|
|
381
|
-
function setTheme(newTheme) {
|
|
382
|
-
if (config.theming.themes[newTheme]) {
|
|
383
|
-
setThemeState(newTheme);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: { theme, setTheme, availableThemes }, children });
|
|
387
|
-
}
|
|
388
|
-
function useTheme() {
|
|
389
|
-
const context = useContext(ThemeContext);
|
|
390
|
-
if (context === void 0) {
|
|
391
|
-
throw new Error("useTheme must be used within a ThemeProvider");
|
|
392
|
-
}
|
|
393
|
-
return context;
|
|
394
|
-
}
|
|
395
|
-
function hexToRgb(hex) {
|
|
396
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
397
|
-
return result ? {
|
|
398
|
-
r: parseInt(result[1], 16),
|
|
399
|
-
g: parseInt(result[2], 16),
|
|
400
|
-
b: parseInt(result[3], 16)
|
|
401
|
-
} : null;
|
|
402
|
-
}
|
|
403
376
|
const TeamContext = createContext(void 0);
|
|
404
377
|
function TeamProvider({ children }) {
|
|
405
378
|
var _a;
|
|
@@ -74071,8 +74044,8 @@ function AdminTeamPage() {
|
|
|
74071
74044
|
] }) });
|
|
74072
74045
|
}
|
|
74073
74046
|
const styles = "@chaaskit/client/src/styles/index.css";
|
|
74074
|
-
function ChatProviders({ children }) {
|
|
74075
|
-
return /* @__PURE__ */ jsx(ConfigProvider, { children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(AuthProvider, { children: /* @__PURE__ */ jsx(TeamProvider, { children: /* @__PURE__ */ jsx(ProjectProvider, { children }) }) }) }) });
|
|
74047
|
+
function ChatProviders({ children, initialConfig }) {
|
|
74048
|
+
return /* @__PURE__ */ jsx(ConfigProvider, { initialConfig, children: /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(AuthProvider, { children: /* @__PURE__ */ jsx(TeamProvider, { children: /* @__PURE__ */ jsx(ProjectProvider, { children }) }) }) }) });
|
|
74076
74049
|
}
|
|
74077
74050
|
export {
|
|
74078
74051
|
AcceptInvitePage,
|