Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(template):fix deps, fix styles (#4378)
- Loading branch information
1 parent
30fa9e2
commit cf3041d
Showing
11 changed files
with
328 additions
and
306 deletions.
There are no files selected for viewing
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
115 changes: 0 additions & 115 deletions
115
frontend/providers/template/src/components/YamlCode/hljs.ts
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
frontend/providers/template/src/components/YamlCode/index.module.scss
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
frontend/providers/template/src/components/YamlCode/index.tsx
This file was deleted.
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
48 changes: 48 additions & 0 deletions
48
frontend/providers/template/src/pages/develop/components/Editor.tsx
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 { Box, BoxProps } from '@chakra-ui/react'; | ||
import { StreamLanguage } from '@codemirror/language'; | ||
import { yaml } from '@codemirror/legacy-modes/mode/yaml'; | ||
import { EditorState } from '@codemirror/state'; | ||
import { EditorView, keymap } from '@codemirror/view'; | ||
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap'; | ||
import { basicSetup } from 'codemirror'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
export default function Editor({ | ||
onDocChange, | ||
...styles | ||
}: { onDocChange: (x: EditorState) => void } & BoxProps) { | ||
const [init, setInit] = useState(true); | ||
const extensions = [ | ||
basicSetup, | ||
keymap.of(vscodeKeymap), | ||
StreamLanguage.define(yaml), | ||
EditorView.updateListener.of((update) => { | ||
// persist | ||
const store = update.state.toJSON(); | ||
localStorage.setItem('yamlEditor', JSON.stringify(store)); | ||
if (update.docChanged || init) onDocChange(update.state); | ||
init && setInit(false); | ||
}) | ||
]; | ||
const getState = () => { | ||
try { | ||
return EditorState.create({ | ||
...EditorState.fromJSON(JSON.parse(localStorage.getItem('yamlEditor')!)), | ||
extensions | ||
}); | ||
} catch (err) { | ||
return undefined; | ||
} | ||
}; | ||
const ref = useRef(null); | ||
useEffect(() => { | ||
const view = new EditorView({ | ||
state: getState(), | ||
extensions, // indentOnInput(), | ||
parent: ref.current! | ||
}); | ||
return () => view && view.destroy(); | ||
}, []); | ||
|
||
return <Box ref={ref} {...styles} />; | ||
} |
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.