@xenide-io/the-old-ui-theme 0.4.8 → 0.5.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/ai-message-blocknote-4Q4U2T2W.mjs +63 -0
- package/dist/chunk-IAH7Z46I.mjs +104 -0
- package/dist/suite.js +327 -238
- package/dist/suite.mjs +110 -190
- package/package.json +3 -1
- package/src/styles/suite-skin.css +22 -0
- package/src/suite/components/ai-message-blocknote.test.tsx +40 -0
- package/src/suite/components/ai-message-blocknote.tsx +61 -0
- package/src/suite/components/ai-panel.tsx +19 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useSuiteTheme
|
|
4
|
+
} from "./chunk-IAH7Z46I.mjs";
|
|
5
|
+
import "./chunk-FWCSY2DS.mjs";
|
|
6
|
+
|
|
7
|
+
// src/suite/components/ai-message-blocknote.tsx
|
|
8
|
+
import { useEffect } from "react";
|
|
9
|
+
import { BlockNoteSchema, defaultBlockSpecs } from "@blocknote/core";
|
|
10
|
+
import { BlockNoteViewRaw, useCreateBlockNote } from "@blocknote/react";
|
|
11
|
+
import "@blocknote/react/style.css";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
var assistantSchema = BlockNoteSchema.create({
|
|
14
|
+
blockSpecs: {
|
|
15
|
+
paragraph: defaultBlockSpecs.paragraph,
|
|
16
|
+
heading: defaultBlockSpecs.heading,
|
|
17
|
+
bulletListItem: defaultBlockSpecs.bulletListItem,
|
|
18
|
+
numberedListItem: defaultBlockSpecs.numberedListItem,
|
|
19
|
+
checkListItem: defaultBlockSpecs.checkListItem,
|
|
20
|
+
codeBlock: defaultBlockSpecs.codeBlock,
|
|
21
|
+
quote: defaultBlockSpecs.quote,
|
|
22
|
+
table: defaultBlockSpecs.table,
|
|
23
|
+
divider: defaultBlockSpecs.divider
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
function SuiteAiBlockNoteMessage({
|
|
27
|
+
markdown
|
|
28
|
+
}) {
|
|
29
|
+
const { resolvedTheme } = useSuiteTheme();
|
|
30
|
+
const editor = useCreateBlockNote({ schema: assistantSchema });
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
try {
|
|
33
|
+
const blocks = editor.tryParseMarkdownToBlocks(markdown);
|
|
34
|
+
editor.replaceBlocks(
|
|
35
|
+
editor.document,
|
|
36
|
+
blocks.length > 0 ? blocks : [{ type: "paragraph", content: markdown }]
|
|
37
|
+
);
|
|
38
|
+
} catch (e) {
|
|
39
|
+
editor.replaceBlocks(editor.document, [
|
|
40
|
+
{ type: "paragraph", content: markdown }
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
}, [editor, markdown]);
|
|
44
|
+
return /* @__PURE__ */ jsx(
|
|
45
|
+
BlockNoteViewRaw,
|
|
46
|
+
{
|
|
47
|
+
editor,
|
|
48
|
+
editable: false,
|
|
49
|
+
theme: resolvedTheme,
|
|
50
|
+
className: "suite-ai-blocknote",
|
|
51
|
+
formattingToolbar: false,
|
|
52
|
+
sideMenu: false,
|
|
53
|
+
slashMenu: false,
|
|
54
|
+
linkToolbar: false,
|
|
55
|
+
filePanel: false,
|
|
56
|
+
tableHandles: false,
|
|
57
|
+
comments: false
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
SuiteAiBlockNoteMessage as default
|
|
63
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-FWCSY2DS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/suite/components/theme-provider.tsx
|
|
7
|
+
import {
|
|
8
|
+
createContext,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useState
|
|
14
|
+
} from "react";
|
|
15
|
+
import { jsx } from "react/jsx-runtime";
|
|
16
|
+
var SuiteThemeContext = createContext(null);
|
|
17
|
+
function systemTheme(fallback) {
|
|
18
|
+
if (typeof window === "undefined") return fallback;
|
|
19
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
20
|
+
}
|
|
21
|
+
function resolveTheme(theme, fallback) {
|
|
22
|
+
return theme === "system" ? systemTheme(fallback) : theme;
|
|
23
|
+
}
|
|
24
|
+
function applyTheme(theme, config) {
|
|
25
|
+
const resolved = resolveTheme(theme, config.fallbackTheme);
|
|
26
|
+
if (typeof document === "undefined") return resolved;
|
|
27
|
+
document.documentElement.setAttribute(
|
|
28
|
+
"data-theme",
|
|
29
|
+
resolved === "dark" ? config.darkThemeId : config.lightThemeId
|
|
30
|
+
);
|
|
31
|
+
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
32
|
+
if (config.themeColorLight && config.themeColorDark) {
|
|
33
|
+
const meta = document.getElementById(
|
|
34
|
+
"theme-color-meta"
|
|
35
|
+
);
|
|
36
|
+
if (meta) {
|
|
37
|
+
meta.content = resolved === "light" ? config.themeColorLight : config.themeColorDark;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return resolved;
|
|
41
|
+
}
|
|
42
|
+
function readStoredTheme(storageKey) {
|
|
43
|
+
if (typeof window === "undefined") return "system";
|
|
44
|
+
const stored = localStorage.getItem(storageKey);
|
|
45
|
+
if (stored === "light" || stored === "dark" || stored === "system")
|
|
46
|
+
return stored;
|
|
47
|
+
return "system";
|
|
48
|
+
}
|
|
49
|
+
function SuiteThemeProvider({
|
|
50
|
+
config,
|
|
51
|
+
children
|
|
52
|
+
}) {
|
|
53
|
+
const [state, setState] = useState(() => {
|
|
54
|
+
const theme2 = readStoredTheme(config.storageKey);
|
|
55
|
+
if (typeof document === "undefined") {
|
|
56
|
+
return { theme: theme2, resolvedTheme: config.fallbackTheme };
|
|
57
|
+
}
|
|
58
|
+
const domTheme = document.documentElement.getAttribute("data-theme");
|
|
59
|
+
const resolvedTheme2 = domTheme === config.darkThemeId ? "dark" : domTheme === config.lightThemeId ? "light" : resolveTheme(theme2, config.fallbackTheme);
|
|
60
|
+
return { theme: theme2, resolvedTheme: resolvedTheme2 };
|
|
61
|
+
});
|
|
62
|
+
const { theme, resolvedTheme } = state;
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (theme !== "system") return;
|
|
65
|
+
const media = window.matchMedia("(prefers-color-scheme: dark)");
|
|
66
|
+
const update = () => {
|
|
67
|
+
const resolved = applyTheme("system", config);
|
|
68
|
+
setState((current) => __spreadProps(__spreadValues({}, current), { resolvedTheme: resolved }));
|
|
69
|
+
};
|
|
70
|
+
media.addEventListener("change", update);
|
|
71
|
+
return () => media.removeEventListener("change", update);
|
|
72
|
+
}, [theme, config]);
|
|
73
|
+
const setTheme = useCallback(
|
|
74
|
+
(next) => {
|
|
75
|
+
const resolved = applyTheme(next, config);
|
|
76
|
+
setState({ theme: next, resolvedTheme: resolved });
|
|
77
|
+
localStorage.setItem(config.storageKey, next);
|
|
78
|
+
},
|
|
79
|
+
[config]
|
|
80
|
+
);
|
|
81
|
+
const toggleTheme = useCallback(() => {
|
|
82
|
+
setState((prev) => {
|
|
83
|
+
const next = resolveTheme(prev.theme, config.fallbackTheme) === "dark" ? "light" : "dark";
|
|
84
|
+
const resolved = applyTheme(next, config);
|
|
85
|
+
localStorage.setItem(config.storageKey, next);
|
|
86
|
+
return { theme: next, resolvedTheme: resolved };
|
|
87
|
+
});
|
|
88
|
+
}, [config]);
|
|
89
|
+
const value = useMemo(
|
|
90
|
+
() => ({ theme, resolvedTheme, setTheme, toggleTheme }),
|
|
91
|
+
[theme, resolvedTheme, setTheme, toggleTheme]
|
|
92
|
+
);
|
|
93
|
+
return /* @__PURE__ */ jsx(SuiteThemeContext.Provider, { value, children });
|
|
94
|
+
}
|
|
95
|
+
function useSuiteTheme() {
|
|
96
|
+
const ctx = useContext(SuiteThemeContext);
|
|
97
|
+
if (!ctx) throw new Error("useTheme must be used within ThemeProvider");
|
|
98
|
+
return ctx;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export {
|
|
102
|
+
SuiteThemeProvider,
|
|
103
|
+
useSuiteTheme
|
|
104
|
+
};
|