-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): implement backup dialog
- Loading branch information
1 parent
1a42f9d
commit 58b69fe
Showing
17 changed files
with
524 additions
and
166 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
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,48 @@ | ||
import InputLabel from '@mui/material/InputLabel'; | ||
import AceEditor from 'react-ace'; | ||
|
||
import { useTranslation } from '@/hooks'; | ||
import { selectEditorMode } from '@/utils/selector'; | ||
|
||
export type CSSEditorProps = { | ||
editorMode: string; | ||
setPreset: (script: string) => void; | ||
setStyle: (style: string) => void; | ||
style: string; | ||
}; | ||
|
||
export const CSSEditor = ({ editorMode, setPreset, setStyle, style }: CSSEditorProps) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<> | ||
<InputLabel sx={{ marginTop: '20px' }}>{t('custom-css-label')}</InputLabel> | ||
<AceEditor | ||
style={{ | ||
width: '95%', | ||
backgroundColor: '#2424248c', | ||
}} | ||
onChange={(value) => { | ||
setStyle(value); | ||
localStorage.setItem('customCSS', value); | ||
setPreset('0'); | ||
}} | ||
fontSize={'1rem'} | ||
height="300px" | ||
mode="css" | ||
theme="one_dark" | ||
value={style} | ||
setOptions={{ useWorker: false }} | ||
placeholder="{ body: url('https://localhost' }" | ||
name="Custom CSS" | ||
enableBasicAutocompletion | ||
enableLiveAutocompletion | ||
enableSnippets | ||
keyboardHandler={selectEditorMode(editorMode)} | ||
highlightActiveLine | ||
tabSize={2} | ||
editorProps={{ $blockScrolling: true }} | ||
/> | ||
</> | ||
); | ||
}; |
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,12 @@ | ||
// @index('./*', f => `export * from '${f.path}'`) | ||
export * from './css_editor'; | ||
export * from './js_editor'; | ||
|
||
// NOTE: These extensions must be loaded after importing AceEditor or they will error | ||
import 'ace-builds/src-min-noconflict/ext-language_tools'; // For completion | ||
import 'ace-builds/src-min-noconflict/keybinding-vim'; | ||
import 'ace-builds/src-min-noconflict/mode-css'; | ||
import 'ace-builds/src-min-noconflict/mode-javascript'; | ||
import 'ace-builds/src-min-noconflict/snippets/css'; | ||
import 'ace-builds/src-min-noconflict/snippets/javascript'; | ||
import 'ace-builds/src-min-noconflict/theme-one_dark'; |
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,76 @@ | ||
import { Checkbox, FormControlLabel, Grid, Tooltip } from '@mui/material'; | ||
import InputLabel from '@mui/material/InputLabel'; | ||
import AceEditor from 'react-ace'; | ||
|
||
import { useInjectScript, useStorageState, useTranslation } from '@/hooks'; | ||
import { selectEditorMode } from '@/utils/selector'; | ||
|
||
export type JSEditorProps = { | ||
editorMode: string; | ||
marginTop?: string; | ||
}; | ||
export const JSEditor = ({ editorMode, marginTop }: JSEditorProps) => { | ||
const { t } = useTranslation(); | ||
|
||
const [script, setScript] = useInjectScript(); | ||
const [runScript, setRunScript] = useStorageState('runScript', 'false'); | ||
|
||
return ( | ||
<> | ||
<Grid container sx={{ display: 'flex', justifyContent: 'space-evenly', width: '100%', marginTop: marginTop }}> | ||
<InputLabel sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }} error> | ||
{t('custom-js-label')} | ||
</InputLabel> | ||
<Tooltip | ||
title={ | ||
<> | ||
{t('custom-js-auto-run-tooltip')} | ||
<br /> | ||
{t('custom-js-auto-run-tooltip2')} | ||
</> | ||
} | ||
> | ||
<FormControlLabel | ||
control={ | ||
<Checkbox | ||
checked={runScript === 'true'} | ||
onClick={() => setRunScript(runScript === 'true' ? 'false' : 'true')} | ||
/> | ||
} | ||
label={t('custom-js-auto-run-label')} | ||
/> | ||
</Tooltip> | ||
</Grid> | ||
|
||
<AceEditor | ||
style={{ | ||
width: '95%', | ||
backgroundColor: '#2424248c', | ||
}} | ||
onChange={(value) => { | ||
localStorage.setItem('customJS', value); | ||
setScript(value); | ||
}} | ||
placeholder={`(()=> { | ||
const p = document.createElement('p'); | ||
p.innerText = 'Hello'; | ||
document.body.appendChild(p); | ||
)()`} | ||
editorProps={{ $blockScrolling: true }} | ||
enableBasicAutocompletion | ||
enableLiveAutocompletion | ||
enableSnippets | ||
fontSize={'1rem'} | ||
height="250px" | ||
highlightActiveLine | ||
keyboardHandler={selectEditorMode(editorMode)} | ||
mode="javascript" | ||
name="Custom JavaScript" | ||
setOptions={{ useWorker: false }} | ||
tabSize={2} | ||
theme="one_dark" | ||
value={script} | ||
/> | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.