@rolder/kit 3.0.0-alpha.8 → 3.0.0-alpha.9
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/ui/conversation/ConversationContext.d.ts +7 -0
- package/dist/ai/ui/conversation/ConversationContext.js +8 -0
- package/dist/ai/ui/conversation/ConversationProvider.d.ts +2 -0
- package/dist/ai/ui/conversation/ConversationProvider.js +14 -0
- package/dist/ai/ui/conversation/Empty.d.ts +1 -0
- package/dist/ai/ui/conversation/Empty.js +21 -0
- package/dist/ai/ui/conversation/File.d.ts +4 -0
- package/dist/ai/ui/conversation/File.js +42 -0
- package/dist/ai/ui/conversation/FileIcon.d.ts +3 -0
- package/dist/ai/ui/conversation/FileIcon.js +225 -0
- package/dist/ai/ui/conversation/Loader.d.ts +2 -0
- package/dist/ai/ui/conversation/Loader.js +12 -0
- package/dist/ai/ui/conversation/Message.d.ts +4 -0
- package/dist/ai/ui/conversation/Message.js +25 -0
- package/dist/ai/ui/conversation/Root.d.ts +2 -0
- package/dist/ai/ui/conversation/Root.js +26 -0
- package/dist/ai/ui/conversation/index.d.ts +13 -0
- package/dist/ai/ui/conversation/index.js +14 -0
- package/{src/ai/ui/conversation/types.ts → dist/ai/ui/conversation/types.d.ts} +4 -5
- package/dist/ai/ui/conversation/types.js +0 -0
- package/dist/ai/ui/conversation/useChatMessage.d.ts +2 -0
- package/dist/ai/ui/conversation/useChatMessage.js +12 -0
- package/dist/ai/ui/promptInput/File.d.ts +2 -0
- package/dist/ai/ui/promptInput/File.js +117 -0
- package/dist/ai/ui/promptInput/FileIcon.d.ts +3 -0
- package/dist/ai/ui/promptInput/FileIcon.js +225 -0
- package/dist/ai/ui/promptInput/Footer.d.ts +2 -0
- package/dist/ai/ui/promptInput/Footer.js +8 -0
- package/dist/ai/ui/promptInput/PromptInputContext.d.ts +12 -0
- package/dist/ai/ui/promptInput/PromptInputContext.js +8 -0
- package/dist/ai/ui/promptInput/PromptInputProvider.d.ts +2 -0
- package/dist/ai/ui/promptInput/PromptInputProvider.js +50 -0
- package/dist/ai/ui/promptInput/Root.d.ts +3 -0
- package/dist/ai/ui/promptInput/Root.js +17 -0
- package/dist/ai/ui/promptInput/Submit.d.ts +2 -0
- package/dist/ai/ui/promptInput/Submit.js +40 -0
- package/dist/ai/ui/promptInput/Textarea.d.ts +2 -0
- package/dist/ai/ui/promptInput/Textarea.js +33 -0
- package/dist/ai/ui/promptInput/index.d.ts +8 -0
- package/dist/ai/ui/promptInput/index.js +13 -0
- package/dist/ai/ui/promptInput/types.d.ts +11 -0
- package/dist/ai/ui/promptInput/types.js +0 -0
- package/dist/ai/utils/convertFileUIPartBlobToDataURL.d.ts +5 -0
- package/dist/ai/utils/convertFileUIPartBlobToDataURL.js +21 -0
- package/dist/ai/utils/parseAiMessagePart.d.ts +2 -0
- package/dist/ai/utils/parseAiMessagePart.js +12 -0
- package/dist/app/AppDefaults.d.ts +3 -0
- package/dist/app/AppDefaults.js +27 -0
- package/dist/app/DefaultApp.d.ts +6 -0
- package/dist/app/DefaultApp.js +43 -0
- package/dist/app/cookieColorSchemeManager.d.ts +6 -0
- package/dist/app/cookieColorSchemeManager.js +46 -0
- package/dist/app/defaultRequestMiddlewares.d.ts +4 -0
- package/dist/app/defaultRequestMiddlewares.js +24 -0
- package/dist/app/defaultTheme.d.ts +141 -0
- package/dist/app/defaultTheme.js +24 -0
- package/dist/functions/getCookie.d.ts +3 -0
- package/dist/functions/getCookie.js +8 -0
- package/dist/functions/setCookie.d.ts +10 -0
- package/dist/functions/setCookie.js +19 -0
- package/dist/functions/setCookies.d.ts +14 -0
- package/dist/functions/setCookies.js +13 -0
- package/dist/hooks/useMutation.d.ts +4 -0
- package/dist/hooks/useMutation.js +8 -0
- package/dist/hooks/useMutationWithInvalidate.d.ts +4 -0
- package/dist/hooks/useMutationWithInvalidate.js +16 -0
- package/{src/index.ts → dist/index.d.ts} +5 -45
- package/dist/index.js +26 -0
- package/{src → dist}/styles.css +11 -21
- package/dist/surreal/connection.d.ts +9 -0
- package/dist/surreal/connection.js +49 -0
- package/dist/surreal/deafaultCrud.d.ts +2 -0
- package/dist/surreal/deafaultCrud.js +18 -0
- package/dist/surreal/deserialize.d.ts +17 -0
- package/dist/surreal/deserialize.js +46 -0
- package/dist/surreal/encryption.d.ts +6 -0
- package/dist/surreal/encryption.js +30 -0
- package/dist/ui/AnimatedChevron.d.ts +6 -0
- package/dist/ui/AnimatedChevron.js +31 -0
- package/dist/ui/JsonInput.d.ts +2 -0
- package/dist/ui/JsonInput.js +45 -0
- package/dist/ui/RouterLink.d.ts +16 -0
- package/dist/ui/RouterLink.js +36 -0
- package/dist/ui/editor/Content.d.ts +3 -0
- package/dist/ui/editor/Content.js +13 -0
- package/dist/ui/editor/Provider.d.ts +17 -0
- package/dist/ui/editor/Provider.js +80 -0
- package/dist/ui/editor/Root.d.ts +2 -0
- package/dist/ui/editor/Root.js +18 -0
- package/dist/ui/editor/Toolbar.d.ts +5 -0
- package/dist/ui/editor/Toolbar.js +156 -0
- package/dist/ui/editor/index.d.ts +12 -0
- package/dist/ui/editor/index.js +11 -0
- package/dist/ui/editor/types.d.ts +7 -0
- package/dist/ui/editor/types.js +0 -0
- package/dist/ui/error/DefaultError.d.ts +2 -0
- package/dist/ui/error/DefaultError.js +62 -0
- package/dist/ui/error/DefaultNotFound.d.ts +1 -0
- package/dist/ui/error/DefaultNotFound.js +37 -0
- package/dist/ui/error/Forbidden.d.ts +1 -0
- package/dist/ui/error/Forbidden.js +32 -0
- package/dist/ui/error/defaultErrorNotification.d.ts +1 -0
- package/dist/ui/error/defaultErrorNotification.js +8 -0
- package/dist/ui/error/index.js +5 -0
- package/dist/ui/form/blurOnError.d.ts +4 -0
- package/dist/ui/form/blurOnError.js +11 -0
- package/dist/ui/form/buttons/CancelButton.d.ts +5 -0
- package/dist/ui/form/buttons/CancelButton.js +44 -0
- package/dist/ui/form/buttons/SubmitButton.d.ts +5 -0
- package/dist/ui/form/buttons/SubmitButton.js +47 -0
- package/dist/ui/form/buttons/SubscribeActionIcon.d.ts +4 -0
- package/dist/ui/form/buttons/SubscribeActionIcon.js +15 -0
- package/dist/ui/form/buttons/SubscribeButton.d.ts +5 -0
- package/dist/ui/form/buttons/SubscribeButton.js +16 -0
- package/dist/ui/form/buttons/index.js +4 -0
- package/dist/ui/form/context.d.ts +83 -0
- package/dist/ui/form/context.js +26 -0
- package/dist/ui/form/fields/JsonField.d.ts +2 -0
- package/dist/ui/form/fields/JsonField.js +13 -0
- package/dist/ui/form/fields/MultiSelectField.d.ts +2 -0
- package/dist/ui/form/fields/MultiSelectField.js +15 -0
- package/dist/ui/form/fields/NumberField.d.ts +2 -0
- package/dist/ui/form/fields/NumberField.js +15 -0
- package/dist/ui/form/fields/PassowrdField.d.ts +2 -0
- package/dist/ui/form/fields/PassowrdField.js +18 -0
- package/dist/ui/form/fields/SelectField.d.ts +2 -0
- package/dist/ui/form/fields/SelectField.js +15 -0
- package/dist/ui/form/fields/SwitchField.d.ts +2 -0
- package/dist/ui/form/fields/SwitchField.js +15 -0
- package/dist/ui/form/fields/TextField.d.ts +2 -0
- package/dist/ui/form/fields/TextField.js +15 -0
- package/dist/ui/form/fields/TextPassowrdField.d.ts +2 -0
- package/dist/ui/form/fields/TextPassowrdField.js +51 -0
- package/dist/ui/form/fields/TextareaField.d.ts +2 -0
- package/dist/ui/form/fields/TextareaField.js +15 -0
- package/dist/ui/form/fields/index.js +9 -0
- package/dist/ui/form/fieldsSchema.d.ts +12 -0
- package/dist/ui/form/fieldsSchema.js +13 -0
- package/dist/ui/form/index.js +4 -0
- package/dist/ui/hoverPaper/HoverPaper.d.ts +6 -0
- package/dist/ui/hoverPaper/HoverPaper.js +15 -0
- package/dist/ui/hoverPaper/index.js +3 -0
- package/dist/ui/hoverPaper/usePaperHover.d.ts +4 -0
- package/dist/ui/hoverPaper/usePaperHover.js +9 -0
- package/dist/ui/saveInput/JsonInput.d.ts +6 -0
- package/dist/ui/saveInput/JsonInput.js +34 -0
- package/dist/ui/saveInput/NumberInput.d.ts +6 -0
- package/dist/ui/saveInput/NumberInput.js +27 -0
- package/dist/ui/saveInput/SaveInput.d.ts +36 -0
- package/dist/ui/saveInput/SaveInput.js +15 -0
- package/dist/ui/saveInput/Select.d.ts +6 -0
- package/dist/ui/saveInput/Select.js +27 -0
- package/dist/ui/saveInput/Switch.d.ts +6 -0
- package/dist/ui/saveInput/Switch.js +30 -0
- package/dist/ui/saveInput/TextInput.d.ts +6 -0
- package/dist/ui/saveInput/TextInput.js +26 -0
- package/dist/ui/saveInput/Textarea.d.ts +6 -0
- package/dist/ui/saveInput/Textarea.js +26 -0
- package/dist/ui/saveInput/index.js +2 -0
- package/{src/ui/scrollArea/ScrollArea.tsx → dist/ui/scrollArea/ScrollArea.d.ts} +10 -41
- package/dist/ui/scrollArea/ScrollArea.js +30 -0
- package/dist/ui/scrollArea/ScrollAreaButton.d.ts +5 -0
- package/dist/ui/scrollArea/ScrollAreaButton.js +51 -0
- package/dist/ui/scrollArea/ScrollAreaContent.d.ts +6 -0
- package/dist/ui/scrollArea/ScrollAreaContent.js +29 -0
- package/{src/ui/scrollArea/context.tsx → dist/ui/scrollArea/context.d.ts} +3 -18
- package/dist/ui/scrollArea/context.js +10 -0
- package/dist/ui/scrollArea/index.d.ts +3 -0
- package/dist/ui/scrollArea/index.js +3 -0
- package/dist/ui/scrollArea/types.d.ts +65 -0
- package/dist/ui/scrollArea/types.js +0 -0
- package/dist/ui/scrollArea/useScrollArea.d.ts +9 -0
- package/dist/ui/scrollArea/useScrollArea.js +146 -0
- package/package.json +4 -1
- package/rslib.config.ts +0 -21
- package/src/ai/ui/conversation/ConversationContext.ts +0 -21
- package/src/ai/ui/conversation/ConversationProvider.tsx +0 -21
- package/src/ai/ui/conversation/Empty.tsx +0 -15
- package/src/ai/ui/conversation/File.tsx +0 -40
- package/src/ai/ui/conversation/FileIcon.tsx +0 -143
- package/src/ai/ui/conversation/Loader.tsx +0 -8
- package/src/ai/ui/conversation/Message.tsx +0 -34
- package/src/ai/ui/conversation/Root.tsx +0 -24
- package/src/ai/ui/conversation/index.ts +0 -16
- package/src/ai/ui/conversation/useChatMessage.ts +0 -13
- package/src/ai/ui/promptInput/File.tsx +0 -98
- package/src/ai/ui/promptInput/FileIcon.tsx +0 -149
- package/src/ai/ui/promptInput/Footer.tsx +0 -5
- package/src/ai/ui/promptInput/PromptInputContext.ts +0 -24
- package/src/ai/ui/promptInput/PromptInputProvider.tsx +0 -54
- package/src/ai/ui/promptInput/Root.tsx +0 -29
- package/src/ai/ui/promptInput/Submit.tsx +0 -39
- package/src/ai/ui/promptInput/Textarea.tsx +0 -39
- package/src/ai/ui/promptInput/index.ts +0 -15
- package/src/ai/ui/promptInput/types.ts +0 -9
- package/src/ai/utils/convertFileUIPartBlobToDataURL.ts +0 -29
- package/src/ai/utils/parseAiMessagePart.ts +0 -19
- package/src/app/AppDefaults.tsx +0 -21
- package/src/app/DefaultApp.tsx +0 -50
- package/src/app/cookieColorSchemeManager.ts +0 -70
- package/src/app/defaultRequestMiddlewares.ts +0 -22
- package/src/app/defaultTheme.ts +0 -22
- package/src/functions/getCookie.ts +0 -36
- package/src/functions/setCookie.ts +0 -29
- package/src/functions/setCookies.ts +0 -24
- package/src/hooks/useMutation.ts +0 -14
- package/src/hooks/useMutationWithInvalidate.ts +0 -23
- package/src/surreal/connection.ts +0 -72
- package/src/surreal/deafaultCrud.ts +0 -25
- package/src/surreal/deserialize.ts +0 -144
- package/src/surreal/encryption.ts +0 -51
- package/src/ui/AnimatedChevron.tsx +0 -32
- package/src/ui/JsonInput.tsx +0 -52
- package/src/ui/RouterLink.tsx +0 -78
- package/src/ui/editor/Content.tsx +0 -11
- package/src/ui/editor/Provider.tsx +0 -96
- package/src/ui/editor/Root.tsx +0 -25
- package/src/ui/editor/Toolbar.tsx +0 -92
- package/src/ui/editor/index.ts +0 -13
- package/src/ui/editor/types.ts +0 -7
- package/src/ui/error/DefaultError.tsx +0 -60
- package/src/ui/error/DefaultNotFound.tsx +0 -19
- package/src/ui/error/Forbidden.tsx +0 -18
- package/src/ui/error/defaultErrorNotification.ts +0 -9
- package/src/ui/form/blurOnError.ts +0 -21
- package/src/ui/form/buttons/CancelButton.tsx +0 -42
- package/src/ui/form/buttons/SubmitButton.tsx +0 -43
- package/src/ui/form/buttons/SubscribeActionIcon.tsx +0 -18
- package/src/ui/form/buttons/SubscribeButton.tsx +0 -17
- package/src/ui/form/context.ts +0 -45
- package/src/ui/form/fields/JsonField.tsx +0 -16
- package/src/ui/form/fields/MultiSelectField.tsx +0 -17
- package/src/ui/form/fields/NumberField.tsx +0 -17
- package/src/ui/form/fields/PassowrdField.tsx +0 -20
- package/src/ui/form/fields/SelectField.tsx +0 -17
- package/src/ui/form/fields/SwitchField.tsx +0 -17
- package/src/ui/form/fields/TextField.tsx +0 -17
- package/src/ui/form/fields/TextPassowrdField.tsx +0 -51
- package/src/ui/form/fields/TextareaField.tsx +0 -17
- package/src/ui/form/fieldsSchema.ts +0 -24
- package/src/ui/hoverPaper/HoverPaper.tsx +0 -17
- package/src/ui/hoverPaper/usePaperHover.ts +0 -9
- package/src/ui/saveInput/JsonInput.tsx +0 -40
- package/src/ui/saveInput/NumberInput.tsx +0 -40
- package/src/ui/saveInput/SaveInput.tsx +0 -15
- package/src/ui/saveInput/Select.tsx +0 -41
- package/src/ui/saveInput/Switch.tsx +0 -46
- package/src/ui/saveInput/TextInput.tsx +0 -40
- package/src/ui/saveInput/Textarea.tsx +0 -40
- package/src/ui/scrollArea/ARCH.md +0 -204
- package/src/ui/scrollArea/README.md +0 -369
- package/src/ui/scrollArea/ScrollAreaButton.tsx +0 -56
- package/src/ui/scrollArea/ScrollAreaContent.tsx +0 -36
- package/src/ui/scrollArea/index.ts +0 -10
- package/src/ui/scrollArea/types.ts +0 -77
- package/src/ui/scrollArea/useScrollArea.ts +0 -227
- package/tsconfig.json +0 -14
- /package/{src/ui/error/index.ts → dist/ui/error/index.d.ts} +0 -0
- /package/{src/ui/form/buttons/index.ts → dist/ui/form/buttons/index.d.ts} +0 -0
- /package/{src/ui/form/fields/index.ts → dist/ui/form/fields/index.d.ts} +0 -0
- /package/{src/ui/form/index.ts → dist/ui/form/index.d.ts} +0 -0
- /package/{src/ui/hoverPaper/index.ts → dist/ui/hoverPaper/index.d.ts} +0 -0
- /package/{src/ui/saveInput/index.ts → dist/ui/saveInput/index.d.ts} +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
const FileIcon = ({ mimeType })=>{
|
|
3
|
+
switch(true){
|
|
4
|
+
case mimeType.includes('image/'):
|
|
5
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
6
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
7
|
+
width: "24",
|
|
8
|
+
height: "24",
|
|
9
|
+
viewBox: "0 0 24 24",
|
|
10
|
+
fill: "none",
|
|
11
|
+
stroke: "var(--mantine-color-dimmed)",
|
|
12
|
+
strokeWidth: "1.5",
|
|
13
|
+
strokeLinecap: "round",
|
|
14
|
+
strokeLinejoin: "round",
|
|
15
|
+
role: "img",
|
|
16
|
+
"aria-label": "Image",
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsx("path", {
|
|
19
|
+
stroke: "none",
|
|
20
|
+
d: "M0 0h24v24H0z",
|
|
21
|
+
fill: "none"
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ jsx("path", {
|
|
24
|
+
d: "M15 8h.01"
|
|
25
|
+
}),
|
|
26
|
+
/*#__PURE__*/ jsx("path", {
|
|
27
|
+
d: "M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12"
|
|
28
|
+
}),
|
|
29
|
+
/*#__PURE__*/ jsx("path", {
|
|
30
|
+
d: "M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5"
|
|
31
|
+
}),
|
|
32
|
+
/*#__PURE__*/ jsx("path", {
|
|
33
|
+
d: "M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3"
|
|
34
|
+
})
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
case mimeType.includes('application/pdf'):
|
|
38
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
39
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
40
|
+
width: "24",
|
|
41
|
+
height: "24",
|
|
42
|
+
viewBox: "0 0 24 24",
|
|
43
|
+
fill: "none",
|
|
44
|
+
stroke: "var(--mantine-color-dimmed)",
|
|
45
|
+
strokeWidth: "1.5",
|
|
46
|
+
strokeLinecap: "round",
|
|
47
|
+
strokeLinejoin: "round",
|
|
48
|
+
role: "img",
|
|
49
|
+
"aria-label": "FilePdf",
|
|
50
|
+
children: [
|
|
51
|
+
/*#__PURE__*/ jsx("path", {
|
|
52
|
+
stroke: "none",
|
|
53
|
+
d: "M0 0h24v24H0z",
|
|
54
|
+
fill: "none"
|
|
55
|
+
}),
|
|
56
|
+
/*#__PURE__*/ jsx("path", {
|
|
57
|
+
d: "M14 3v4a1 1 0 0 0 1 1h4"
|
|
58
|
+
}),
|
|
59
|
+
/*#__PURE__*/ jsx("path", {
|
|
60
|
+
d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
|
|
61
|
+
}),
|
|
62
|
+
/*#__PURE__*/ jsx("path", {
|
|
63
|
+
d: "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"
|
|
64
|
+
}),
|
|
65
|
+
/*#__PURE__*/ jsx("path", {
|
|
66
|
+
d: "M17 18h2"
|
|
67
|
+
}),
|
|
68
|
+
/*#__PURE__*/ jsx("path", {
|
|
69
|
+
d: "M20 15h-3v6"
|
|
70
|
+
}),
|
|
71
|
+
/*#__PURE__*/ jsx("path", {
|
|
72
|
+
d: "M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1"
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
case mimeType.includes('application/vnd.openxmlformats-officedocument.wordprocessingml.document'):
|
|
77
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
78
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
79
|
+
width: "24",
|
|
80
|
+
height: "24",
|
|
81
|
+
viewBox: "0 0 24 24",
|
|
82
|
+
fill: "none",
|
|
83
|
+
stroke: "var(--mantine-color-dimmed)",
|
|
84
|
+
strokeWidth: "1.5",
|
|
85
|
+
strokeLinecap: "round",
|
|
86
|
+
strokeLinejoin: "round",
|
|
87
|
+
role: "img",
|
|
88
|
+
"aria-label": "FileDoc",
|
|
89
|
+
children: [
|
|
90
|
+
/*#__PURE__*/ jsx("path", {
|
|
91
|
+
stroke: "none",
|
|
92
|
+
d: "M0 0h24v24H0z",
|
|
93
|
+
fill: "none"
|
|
94
|
+
}),
|
|
95
|
+
/*#__PURE__*/ jsx("path", {
|
|
96
|
+
d: "M14 3v4a1 1 0 0 0 1 1h4"
|
|
97
|
+
}),
|
|
98
|
+
/*#__PURE__*/ jsx("path", {
|
|
99
|
+
d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
|
|
100
|
+
}),
|
|
101
|
+
/*#__PURE__*/ jsx("path", {
|
|
102
|
+
d: "M5 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1"
|
|
103
|
+
}),
|
|
104
|
+
/*#__PURE__*/ jsx("path", {
|
|
105
|
+
d: "M20 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0"
|
|
106
|
+
}),
|
|
107
|
+
/*#__PURE__*/ jsx("path", {
|
|
108
|
+
d: "M12.5 15a1.5 1.5 0 0 1 1.5 1.5v3a1.5 1.5 0 0 1 -3 0v-3a1.5 1.5 0 0 1 1.5 -1.5"
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
case mimeType.includes('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'):
|
|
113
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
114
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
115
|
+
width: "24",
|
|
116
|
+
height: "24",
|
|
117
|
+
viewBox: "0 0 24 24",
|
|
118
|
+
fill: "none",
|
|
119
|
+
stroke: "var(--mantine-color-dimmed)",
|
|
120
|
+
strokeWidth: "1.5",
|
|
121
|
+
strokeLinecap: "round",
|
|
122
|
+
strokeLinejoin: "round",
|
|
123
|
+
role: "img",
|
|
124
|
+
"aria-label": "FileXls",
|
|
125
|
+
children: [
|
|
126
|
+
/*#__PURE__*/ jsx("path", {
|
|
127
|
+
stroke: "none",
|
|
128
|
+
d: "M0 0h24v24H0z",
|
|
129
|
+
fill: "none"
|
|
130
|
+
}),
|
|
131
|
+
/*#__PURE__*/ jsx("path", {
|
|
132
|
+
d: "M14 3v4a1 1 0 0 0 1 1h4"
|
|
133
|
+
}),
|
|
134
|
+
/*#__PURE__*/ jsx("path", {
|
|
135
|
+
d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
|
|
136
|
+
}),
|
|
137
|
+
/*#__PURE__*/ jsx("path", {
|
|
138
|
+
d: "M4 15l4 6"
|
|
139
|
+
}),
|
|
140
|
+
/*#__PURE__*/ jsx("path", {
|
|
141
|
+
d: "M4 21l4 -6"
|
|
142
|
+
}),
|
|
143
|
+
/*#__PURE__*/ jsx("path", {
|
|
144
|
+
d: "M17 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"
|
|
145
|
+
}),
|
|
146
|
+
/*#__PURE__*/ jsx("path", {
|
|
147
|
+
d: "M11 15v6h3"
|
|
148
|
+
})
|
|
149
|
+
]
|
|
150
|
+
});
|
|
151
|
+
case mimeType.includes('application/vnd.openxmlformats-officedocument.presentationml.presentation'):
|
|
152
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
153
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
154
|
+
width: "24",
|
|
155
|
+
height: "24",
|
|
156
|
+
viewBox: "0 0 24 24",
|
|
157
|
+
fill: "none",
|
|
158
|
+
stroke: "var(--mantine-color-dimmed)",
|
|
159
|
+
strokeWidth: "1.5",
|
|
160
|
+
strokeLinecap: "round",
|
|
161
|
+
strokeLinejoin: "round",
|
|
162
|
+
role: "img",
|
|
163
|
+
"aria-label": "FilePpt",
|
|
164
|
+
children: [
|
|
165
|
+
/*#__PURE__*/ jsx("path", {
|
|
166
|
+
stroke: "none",
|
|
167
|
+
d: "M0 0h24v24H0z",
|
|
168
|
+
fill: "none"
|
|
169
|
+
}),
|
|
170
|
+
/*#__PURE__*/ jsx("path", {
|
|
171
|
+
d: "M14 3v4a1 1 0 0 0 1 1h4"
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ jsx("path", {
|
|
174
|
+
d: "M14 3v4a1 1 0 0 0 1 1h4"
|
|
175
|
+
}),
|
|
176
|
+
/*#__PURE__*/ jsx("path", {
|
|
177
|
+
d: "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"
|
|
178
|
+
}),
|
|
179
|
+
/*#__PURE__*/ jsx("path", {
|
|
180
|
+
d: "M11 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"
|
|
181
|
+
}),
|
|
182
|
+
/*#__PURE__*/ jsx("path", {
|
|
183
|
+
d: "M16.5 15h3"
|
|
184
|
+
}),
|
|
185
|
+
/*#__PURE__*/ jsx("path", {
|
|
186
|
+
d: "M18 15v6"
|
|
187
|
+
}),
|
|
188
|
+
/*#__PURE__*/ jsx("path", {
|
|
189
|
+
d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
|
|
190
|
+
})
|
|
191
|
+
]
|
|
192
|
+
});
|
|
193
|
+
default:
|
|
194
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
195
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
196
|
+
width: "24",
|
|
197
|
+
height: "24",
|
|
198
|
+
viewBox: "0 0 24 24",
|
|
199
|
+
fill: "none",
|
|
200
|
+
stroke: "var(--mantine-color-dimmed)",
|
|
201
|
+
strokeWidth: "1.5",
|
|
202
|
+
strokeLinecap: "round",
|
|
203
|
+
strokeLinejoin: "round",
|
|
204
|
+
role: "img",
|
|
205
|
+
"aria-label": "File",
|
|
206
|
+
children: [
|
|
207
|
+
/*#__PURE__*/ jsx("path", {
|
|
208
|
+
stroke: "none",
|
|
209
|
+
d: "M0 0h24v24H0z",
|
|
210
|
+
fill: "none"
|
|
211
|
+
}),
|
|
212
|
+
/*#__PURE__*/ jsx("path", {
|
|
213
|
+
d: "M15 3v4a1 1 0 0 0 1 1h4"
|
|
214
|
+
}),
|
|
215
|
+
/*#__PURE__*/ jsx("path", {
|
|
216
|
+
d: "M18 17h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h4l5 5v7a2 2 0 0 1 -2 2"
|
|
217
|
+
}),
|
|
218
|
+
/*#__PURE__*/ jsx("path", {
|
|
219
|
+
d: "M16 17v2a2 2 0 0 1 -2 2h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h2"
|
|
220
|
+
})
|
|
221
|
+
]
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
export { FileIcon };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface PromptInputContext {
|
|
2
|
+
text: string;
|
|
3
|
+
setText: (text: string) => void;
|
|
4
|
+
file?: File;
|
|
5
|
+
setFile: (file?: File) => void;
|
|
6
|
+
onSubmit: () => void;
|
|
7
|
+
submiting: boolean;
|
|
8
|
+
uploading: boolean;
|
|
9
|
+
accept?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const PromptInputContext: import("react").Context<PromptInputContext | null>;
|
|
12
|
+
export declare const usePromptInput: () => PromptInputContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const PromptInputContext = createContext(null);
|
|
3
|
+
const usePromptInput = ()=>{
|
|
4
|
+
const context = useContext(PromptInputContext);
|
|
5
|
+
if (!context) throw new Error('usePromptInput must be used within a PromptInputProvider');
|
|
6
|
+
return context;
|
|
7
|
+
};
|
|
8
|
+
export { PromptInputContext, usePromptInput };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { PromptInputContext } from "./PromptInputContext.js";
|
|
4
|
+
const Provider = ({ children, onSubmit, submiting, uploading, accept = [
|
|
5
|
+
'text',
|
|
6
|
+
'image',
|
|
7
|
+
'pdf'
|
|
8
|
+
] })=>{
|
|
9
|
+
const [text, setText] = useState('');
|
|
10
|
+
const [file, setFile] = useState();
|
|
11
|
+
const value = {
|
|
12
|
+
text,
|
|
13
|
+
setText,
|
|
14
|
+
file,
|
|
15
|
+
setFile,
|
|
16
|
+
onSubmit: ()=>{
|
|
17
|
+
if (text.trim()) {
|
|
18
|
+
onSubmit({
|
|
19
|
+
text: text.trim(),
|
|
20
|
+
file
|
|
21
|
+
});
|
|
22
|
+
setText('');
|
|
23
|
+
setFile(void 0);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
submiting,
|
|
27
|
+
uploading,
|
|
28
|
+
accept: accept.map((type)=>{
|
|
29
|
+
switch(type){
|
|
30
|
+
case 'text':
|
|
31
|
+
return 'text/plain';
|
|
32
|
+
case 'image':
|
|
33
|
+
return 'image/*';
|
|
34
|
+
case 'pdf':
|
|
35
|
+
return 'application/pdf';
|
|
36
|
+
case 'excel':
|
|
37
|
+
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
38
|
+
case 'word':
|
|
39
|
+
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
40
|
+
default:
|
|
41
|
+
return type;
|
|
42
|
+
}
|
|
43
|
+
}).join(',')
|
|
44
|
+
};
|
|
45
|
+
return /*#__PURE__*/ jsx(PromptInputContext.Provider, {
|
|
46
|
+
value: value,
|
|
47
|
+
children: children
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export { Provider };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Paper } from "@mantine/core";
|
|
3
|
+
import clsx from "clsx";
|
|
4
|
+
import { Provider } from "./PromptInputProvider.js";
|
|
5
|
+
const Root = ({ className, onSubmit, submiting, uploading, accept, ...props })=>/*#__PURE__*/ jsx(Provider, {
|
|
6
|
+
onSubmit: onSubmit,
|
|
7
|
+
submiting: submiting,
|
|
8
|
+
uploading: uploading,
|
|
9
|
+
accept: accept,
|
|
10
|
+
children: /*#__PURE__*/ jsx(Paper, {
|
|
11
|
+
radius: "md",
|
|
12
|
+
withBorder: true,
|
|
13
|
+
className: clsx('rolder-prompt-input-root', className),
|
|
14
|
+
...props
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
export { Root };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ActionIcon } from "@mantine/core";
|
|
3
|
+
import { usePromptInput } from "./PromptInputContext.js";
|
|
4
|
+
const Submit = ({ children, ...props })=>{
|
|
5
|
+
const Icon = /*#__PURE__*/ jsxs("svg", {
|
|
6
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
7
|
+
width: "24",
|
|
8
|
+
height: "24",
|
|
9
|
+
viewBox: "0 0 24 24",
|
|
10
|
+
fill: "none",
|
|
11
|
+
stroke: "currentColor",
|
|
12
|
+
strokeWidth: "1.5",
|
|
13
|
+
strokeLinecap: "round",
|
|
14
|
+
strokeLinejoin: "round",
|
|
15
|
+
role: "img",
|
|
16
|
+
"aria-label": "Submit",
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsx("path", {
|
|
19
|
+
stroke: "none",
|
|
20
|
+
d: "M0 0h24v24H0z",
|
|
21
|
+
fill: "none"
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ jsx("path", {
|
|
24
|
+
d: "M9 20v-8h-3.586a1 1 0 0 1 -.707 -1.707l6.586 -6.586a1 1 0 0 1 1.414 0l6.586 6.586a1 1 0 0 1 -.707 1.707h-3.586v8a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1"
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
});
|
|
28
|
+
const { onSubmit, submiting, uploading } = usePromptInput();
|
|
29
|
+
return /*#__PURE__*/ jsx(ActionIcon, {
|
|
30
|
+
"aria-label": "Submit",
|
|
31
|
+
variant: "light",
|
|
32
|
+
size: "lg",
|
|
33
|
+
onClick: onSubmit,
|
|
34
|
+
disabled: uploading,
|
|
35
|
+
loading: submiting,
|
|
36
|
+
...props,
|
|
37
|
+
children: children ?? Icon
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export { Submit };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Textarea } from "@mantine/core";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { usePromptInput } from "./PromptInputContext.js";
|
|
5
|
+
const Textarea_Textarea = (props)=>{
|
|
6
|
+
const { text, setText, onSubmit, submiting, uploading } = usePromptInput();
|
|
7
|
+
const [isComposing, setIsComposing] = useState(false);
|
|
8
|
+
const handleKeyDown = (e)=>{
|
|
9
|
+
if ('Enter' === e.key) {
|
|
10
|
+
if (isComposing || e.nativeEvent.isComposing) return;
|
|
11
|
+
if (e.shiftKey) return;
|
|
12
|
+
e.preventDefault();
|
|
13
|
+
onSubmit();
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
return /*#__PURE__*/ jsx(Textarea, {
|
|
17
|
+
w: "100%",
|
|
18
|
+
size: "md",
|
|
19
|
+
rows: 3,
|
|
20
|
+
classNames: {
|
|
21
|
+
input: 'rolder-prompt-input-textarea'
|
|
22
|
+
},
|
|
23
|
+
placeholder: "Напишите сообщение",
|
|
24
|
+
onCompositionEnd: ()=>setIsComposing(false),
|
|
25
|
+
onCompositionStart: ()=>setIsComposing(true),
|
|
26
|
+
onKeyDown: handleKeyDown,
|
|
27
|
+
value: text,
|
|
28
|
+
onChange: (e)=>setText(e.target.value),
|
|
29
|
+
disabled: submiting || uploading,
|
|
30
|
+
...props
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
export { Textarea_Textarea as Textarea };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Accept, PromptInputProps } from './types';
|
|
2
|
+
export declare const PromptInput: {
|
|
3
|
+
Root: ({ className, onSubmit, submiting, uploading, accept, ...props }: import("@mantine/core").PaperProps & import("./types").PromptInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
Textarea: (props: import("@mantine/core").TextareaProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
Footer: (props: import("@mantine/core").GroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
Submit: ({ children, ...props }: import("@mantine/core").ActionIconProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
File: (props: Omit<import("@mantine/core").FileButtonProps, "onChange" | "children">) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { File } from "./File.js";
|
|
2
|
+
import { Footer } from "./Footer.js";
|
|
3
|
+
import { Root } from "./Root.js";
|
|
4
|
+
import { Submit } from "./Submit.js";
|
|
5
|
+
import { Textarea } from "./Textarea.js";
|
|
6
|
+
const PromptInput = {
|
|
7
|
+
Root: Root,
|
|
8
|
+
Textarea: Textarea,
|
|
9
|
+
Footer: Footer,
|
|
10
|
+
Submit: Submit,
|
|
11
|
+
File: File
|
|
12
|
+
};
|
|
13
|
+
export { PromptInput };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Accept = 'text' | 'image' | 'pdf' | 'excel' | 'word';
|
|
2
|
+
export interface PromptInputProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
onSubmit: ({ text, file }: {
|
|
5
|
+
text: string;
|
|
6
|
+
file?: File;
|
|
7
|
+
}) => void;
|
|
8
|
+
submiting: boolean;
|
|
9
|
+
uploading: boolean;
|
|
10
|
+
accept?: Accept[];
|
|
11
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
async function blobToDataURL(blobUrl) {
|
|
2
|
+
const response = await fetch(blobUrl);
|
|
3
|
+
const blob = await response.blob();
|
|
4
|
+
return new Promise((resolve, reject)=>{
|
|
5
|
+
const reader = new FileReader();
|
|
6
|
+
reader.onload = ()=>resolve(reader.result);
|
|
7
|
+
reader.onerror = reject;
|
|
8
|
+
reader.readAsDataURL(blob);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
async function convertFileUIPartBlobToDataURL(file) {
|
|
12
|
+
if (file.url.startsWith('blob:')) {
|
|
13
|
+
const dataUrl = await blobToDataURL(file.url);
|
|
14
|
+
return {
|
|
15
|
+
...file,
|
|
16
|
+
url: dataUrl
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return file;
|
|
20
|
+
}
|
|
21
|
+
export { convertFileUIPartBlobToDataURL };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parsePartialJson } from "ai";
|
|
2
|
+
const parseAiMessagePart = async (part)=>{
|
|
3
|
+
if (!part.text.startsWith('{')) return part;
|
|
4
|
+
try {
|
|
5
|
+
const result = await parsePartialJson(part.text);
|
|
6
|
+
return result?.value || part;
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error('Error parsing partial JSON:', error);
|
|
9
|
+
return part;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export { parseAiMessagePart };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useComputedColorScheme } from "@mantine/core";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { setCookies } from "../functions/setCookies.js";
|
|
4
|
+
const AppDefaults = ({ saveColorScheme })=>{
|
|
5
|
+
const colorScheme = useComputedColorScheme();
|
|
6
|
+
useEffect(()=>{
|
|
7
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
8
|
+
const cookies = [
|
|
9
|
+
{
|
|
10
|
+
name: 'tz',
|
|
11
|
+
value: tz,
|
|
12
|
+
expires: 365
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
if (saveColorScheme) cookies.push({
|
|
16
|
+
name: 'colorScheme',
|
|
17
|
+
value: colorScheme,
|
|
18
|
+
expires: 365
|
|
19
|
+
});
|
|
20
|
+
setCookies(cookies);
|
|
21
|
+
}, [
|
|
22
|
+
colorScheme,
|
|
23
|
+
saveColorScheme
|
|
24
|
+
]);
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
export { AppDefaults };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type MantineProviderProps } from '@mantine/core';
|
|
2
|
+
interface Props extends MantineProviderProps {
|
|
3
|
+
saveColorScheme?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const DefaultApp: ({ children, saveColorScheme, defaultColorScheme, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ColorSchemeScript, MantineProvider } from "@mantine/core";
|
|
3
|
+
import { HeadContent, Scripts } from "@tanstack/react-router";
|
|
4
|
+
import { getCookie } from "../functions/getCookie.js";
|
|
5
|
+
import { AppDefaults } from "./AppDefaults.js";
|
|
6
|
+
import { cookieColorSchemeManager } from "./cookieColorSchemeManager.js";
|
|
7
|
+
import { defaultTheme } from "./defaultTheme.js";
|
|
8
|
+
const colorSchemeManager = cookieColorSchemeManager();
|
|
9
|
+
const DefaultApp = ({ children, saveColorScheme = true, defaultColorScheme = 'auto', ...props })=>{
|
|
10
|
+
const colorScheme = saveColorScheme ? getCookie('colorScheme', defaultColorScheme) : defaultColorScheme;
|
|
11
|
+
return /*#__PURE__*/ jsxs("html", {
|
|
12
|
+
lang: "ru",
|
|
13
|
+
suppressHydrationWarning: true,
|
|
14
|
+
children: [
|
|
15
|
+
/*#__PURE__*/ jsxs("head", {
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsx(HeadContent, {}),
|
|
18
|
+
/*#__PURE__*/ jsx(ColorSchemeScript, {
|
|
19
|
+
defaultColorScheme: colorScheme
|
|
20
|
+
})
|
|
21
|
+
]
|
|
22
|
+
}),
|
|
23
|
+
/*#__PURE__*/ jsxs("body", {
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ jsxs(MantineProvider, {
|
|
26
|
+
defaultColorScheme: colorScheme,
|
|
27
|
+
theme: defaultTheme,
|
|
28
|
+
colorSchemeManager: colorSchemeManager,
|
|
29
|
+
...props,
|
|
30
|
+
children: [
|
|
31
|
+
/*#__PURE__*/ jsx(AppDefaults, {
|
|
32
|
+
saveColorScheme: saveColorScheme
|
|
33
|
+
}),
|
|
34
|
+
children
|
|
35
|
+
]
|
|
36
|
+
}),
|
|
37
|
+
/*#__PURE__*/ jsx(Scripts, {})
|
|
38
|
+
]
|
|
39
|
+
})
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export { DefaultApp };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type MantineColorSchemeManager } from '@mantine/core';
|
|
2
|
+
export interface CookieColorSchemeManager {
|
|
3
|
+
/** Название куки, `colorScheme` по умолчанию */
|
|
4
|
+
key?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const cookieColorSchemeManager: ({ key, }?: CookieColorSchemeManager) => MantineColorSchemeManager;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isMantineColorScheme } from "@mantine/core";
|
|
2
|
+
import { atom } from "nanostores";
|
|
3
|
+
import { setCookie } from "../functions/setCookie.js";
|
|
4
|
+
const $colorScheme = atom();
|
|
5
|
+
let unsubscribeSystemTheme;
|
|
6
|
+
const cookieColorSchemeManager = ({ key = 'colorScheme' } = {})=>({
|
|
7
|
+
get: (defaultValue)=>{
|
|
8
|
+
try {
|
|
9
|
+
return $colorScheme.get() || defaultValue;
|
|
10
|
+
} catch {
|
|
11
|
+
return defaultValue;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
set: (value)=>{
|
|
15
|
+
try {
|
|
16
|
+
setCookie(key, value);
|
|
17
|
+
$colorScheme.set(value);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.warn('[cookieColorSchemeManager] Ошибка при сохранении цветовой схемы в куки.', error);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
subscribe: (onUpdate)=>{
|
|
23
|
+
$colorScheme.listen((newValue)=>{
|
|
24
|
+
if (isMantineColorScheme(newValue)) {
|
|
25
|
+
setCookie(key, newValue);
|
|
26
|
+
onUpdate(newValue);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
30
|
+
const handleSystemThemeChange = ()=>onUpdate('auto');
|
|
31
|
+
mediaQuery.addEventListener('change', handleSystemThemeChange);
|
|
32
|
+
unsubscribeSystemTheme = ()=>mediaQuery.removeEventListener('change', handleSystemThemeChange);
|
|
33
|
+
},
|
|
34
|
+
unsubscribe: ()=>{
|
|
35
|
+
$colorScheme.off();
|
|
36
|
+
if (unsubscribeSystemTheme) {
|
|
37
|
+
unsubscribeSystemTheme();
|
|
38
|
+
unsubscribeSystemTheme = void 0;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
clear: ()=>{
|
|
42
|
+
setCookie(key);
|
|
43
|
+
$colorScheme.set(void 0);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
export { cookieColorSchemeManager };
|