-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bd41e22
commit c857415
Showing
12 changed files
with
1,000 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getStorageString, StorageKeys } from "./localStorage"; | ||
|
||
export const applyCustomCss = () => { | ||
let style = document.getElementById("custom-css"); | ||
const css = getStorageString(StorageKeys.CUSTOM_CSS, ""); | ||
|
||
if (!css.trim().length) { | ||
if (style) { | ||
style.innerHTML = css; | ||
} | ||
return; | ||
} | ||
|
||
if (!style) { | ||
style = document.createElement("style"); | ||
style.id = "custom-css"; | ||
document.head.appendChild(style); | ||
} | ||
style.innerHTML = css; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { createCodeMirror } from "solid-codemirror"; | ||
import { EditorState, Extension } from "@codemirror/state"; | ||
|
||
import { css } from "@codemirror/lang-css"; | ||
import { dracula } from "thememirror"; | ||
import { | ||
defaultKeymap, | ||
history, | ||
historyKeymap, | ||
indentWithTab, | ||
} from "@codemirror/commands"; | ||
import { | ||
crosshairCursor, | ||
highlightSpecialChars, | ||
keymap, | ||
lineNumbers, | ||
rectangularSelection, | ||
} from "@codemirror/view"; | ||
import { | ||
defaultHighlightStyle, | ||
syntaxHighlighting, | ||
indentOnInput, | ||
bracketMatching, | ||
foldGutter, | ||
foldKeymap, | ||
} from "@codemirror/language"; | ||
import { | ||
autocompletion, | ||
completionKeymap, | ||
closeBrackets, | ||
closeBracketsKeymap, | ||
} from "@codemirror/autocomplete"; | ||
const EDITOR_BASE_SETUP: Extension = [ | ||
lineNumbers(), | ||
highlightSpecialChars(), | ||
history(), | ||
foldGutter(), | ||
EditorState.allowMultipleSelections.of(true), | ||
indentOnInput(), | ||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }), | ||
bracketMatching(), | ||
closeBrackets(), | ||
autocompletion(), | ||
rectangularSelection(), | ||
crosshairCursor(), | ||
keymap.of([ | ||
...closeBracketsKeymap, | ||
...defaultKeymap, | ||
...historyKeymap, | ||
...foldKeymap, | ||
...completionKeymap, | ||
indentWithTab, | ||
]), | ||
|
||
css(), | ||
dracula, | ||
]; | ||
|
||
interface Props { | ||
value: string; | ||
onValueChange: (value: string) => void; | ||
} | ||
|
||
export default (props: Props) => { | ||
let containerRef: HTMLDivElement | undefined; | ||
const { | ||
editorView, | ||
ref: editorRef, | ||
createExtension, | ||
} = createCodeMirror({ | ||
value: props.value, | ||
onValueChange: (value) => props.onValueChange(value), | ||
}); | ||
|
||
createExtension(EDITOR_BASE_SETUP); | ||
|
||
return ( | ||
<div | ||
ref={containerRef} | ||
style={{ | ||
"border-radius": "8px", | ||
overflow: "hidden", | ||
height: "100%", | ||
border: "solid 1px rgba(255, 255, 255, 0.1)", | ||
}} | ||
> | ||
<div ref={editorRef} style={{ height: "100%" }} /> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { createEffect, createSignal, lazy } from "solid-js"; | ||
import { styled } from "solid-styled-components"; | ||
|
||
import useStore from "@/chat-api/store/useStore"; | ||
import Breadcrumb, { BreadcrumbItem } from "../ui/Breadcrumb"; | ||
import { t } from "i18next"; | ||
import { | ||
getStorageString, | ||
setStorageString, | ||
StorageKeys, | ||
} from "@/common/localStorage"; | ||
import Button from "../ui/Button"; | ||
import { Notice } from "../ui/Notice/Notice"; | ||
import { applyCustomCss } from "@/common/customCss"; | ||
|
||
const CodeMirror = lazy(() => import("@/components/code-mirror/CodeMirror")); | ||
|
||
const Container = styled("div")` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
padding: 10px; | ||
height: 100%; | ||
`; | ||
|
||
export default function CustomCssSettings() { | ||
const { header } = useStore(); | ||
const [css, setCss] = createSignal( | ||
getStorageString(StorageKeys.CUSTOM_CSS, "") | ||
); | ||
|
||
createEffect(() => { | ||
header.updateHeader({ | ||
title: "Settings - Custom CSS", | ||
iconName: "settings", | ||
}); | ||
}); | ||
|
||
const onSaveClick = () => { | ||
setStorageString(StorageKeys.CUSTOM_CSS, css()); | ||
applyCustomCss(); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<Breadcrumb style={{ "margin-bottom": "8px" }}> | ||
<BreadcrumbItem href="/app" icon="home" title="Dashboard" /> | ||
<BreadcrumbItem title={t("settings.drawer.interface")} href="../" /> | ||
<BreadcrumbItem title="Custom CSS" /> | ||
</Breadcrumb> | ||
|
||
<Notice | ||
type="warn" | ||
description="Do not paste code from people you don't trust." | ||
/> | ||
<CodeMirror value={css()} onValueChange={setCss} /> | ||
<Button | ||
label="Save & Apply" | ||
onClick={onSaveClick} | ||
iconName="save" | ||
margin={0} | ||
/> | ||
</Container> | ||
); | ||
} |
Oops, something went wrong.