1
1
import { Label } from '@radix-ui/react-label'
2
- import { useMemo , useRef , useState } from 'react'
2
+ import { useMemo , useRef } from 'react'
3
3
import type { FC } from 'react'
4
4
5
5
import { StyledButton } from '~/components/ui/button'
6
- import {
7
- BaseCodeHighlighter ,
8
- HighLighter ,
9
- } from '~/components/ui/code-highlighter'
6
+ import { CodeEditor } from '~/components/ui/code-editor'
7
+ import { HighLighter } from '~/components/ui/code-highlighter'
10
8
import { useModalStack } from '~/components/ui/modal'
11
9
import { useEventCallback } from '~/hooks/common/use-event-callback'
12
10
import { toast } from '~/lib/toast'
@@ -80,7 +78,6 @@ const EditorModal: FC<{
80
78
onChange : ( value : object ) => void
81
79
} > = ( { value, onChange, dismiss } ) => {
82
80
const currentEditValueRef = useRef ( value )
83
- const [ highlighterValue , setHighlighterValue ] = useState ( value )
84
81
85
82
const handleSave = ( ) => {
86
83
if ( ! isValidJSONString ( currentEditValueRef . current ) ) {
@@ -93,27 +90,19 @@ const EditorModal: FC<{
93
90
}
94
91
95
92
return (
96
- < >
97
- < div className = "relative flex w-full flex-grow flex-col lg:w-[600px]" >
98
- < div className = "relative w-full overflow-auto pb-[60px]" >
99
- < textarea
100
- className = "absolute h-full w-full resize-none bg-transparent p-0 !font-mono text-transparent caret-accent *:leading-4"
101
- defaultValue = { value }
102
- onChange = { ( e ) => {
103
- currentEditValueRef . current = e . target . value
104
- setHighlighterValue ( e . target . value )
105
- } }
106
- />
107
- < BaseCodeHighlighter
108
- className = "code-wrap pointer-events-none relative z-[1] !m-0 overflow-auto !p-0 *:!font-mono *:!leading-4"
109
- lang = "json"
110
- content = { highlighterValue }
111
- />
112
- </ div >
93
+ < div className = "relative flex w-full flex-grow flex-col lg:w-[600px]" >
94
+ < div className = "relative max-h-[450px] w-full overflow-auto" >
95
+ < CodeEditor
96
+ content = { value }
97
+ language = "json"
98
+ onChange = { ( value ) => {
99
+ currentEditValueRef . current = value
100
+ } }
101
+ />
113
102
</ div >
114
- < div className = "absolute bottom-4 right-6 flex flex-shrink-0 justify-end" >
103
+ < div className = "flex flex-shrink-0 justify-end p-2 " >
115
104
< StyledButton onClick = { handleSave } > 保存</ StyledButton >
116
105
</ div >
117
- </ >
106
+ </ div >
118
107
)
119
108
}
0 commit comments