1
- import { Editable , useEditableContext } from "@ark-ui/react" ;
1
+ import { Tooltip } from "#components/tooltip" ;
2
+ import { css , cx } from "#styled-system/css" ;
3
+ import { styled } from "#styled-system/jsx" ;
4
+ import { Editable , Portal , useEditableContext } from "@ark-ui/react" ;
2
5
import { useSelector } from "@xstate/store/react" ;
3
6
import { TrashIcon , Undo2 } from "lucide-react" ;
4
7
import { useRef , useState } from "react" ;
5
- import { css } from "#styled-system/css" ;
6
- import { styled } from "#styled-system/jsx" ;
7
- import { Tooltip } from "#components/tooltip" ;
8
+ import { useDevtoolsContext } from "./devtools-context" ;
8
9
import { HighlightMatch } from "./highlight-match" ;
9
10
import { hypenateProperty } from "./lib/hyphenate-proprety" ;
10
11
import { symbols } from "./lib/symbols" ;
11
12
import { store } from "./store" ;
12
- import { useDevtoolsContext } from "./devtools-context" ;
13
13
14
14
export interface EditableValueProps {
15
15
index :number ;
@@ -109,9 +109,19 @@ export const EditableValue = (props: EditableValueProps) => {
109
109
}
110
110
} ;
111
111
112
+ const parentRef = useRef < HTMLDivElement > ( null ) ;
113
+
112
114
return (
113
115
< Editable . Root
114
- className = { css ( { display :"flex" , alignItems :"center" } ) }
116
+ ref = { parentRef }
117
+ className = { cx (
118
+ "group" ,
119
+ css ( {
120
+ display :"flex" ,
121
+ justifyContent :"flex-start" ,
122
+ alignItems :"center" ,
123
+ } ) ,
124
+ ) }
115
125
key = { key }
116
126
autoResize
117
127
selectOnFocus
@@ -122,7 +132,7 @@ export const EditableValue = (props: EditableValueProps) => {
122
132
overrideValue ( update . value ) ;
123
133
} }
124
134
>
125
- < Editable . Area ref = { ref } >
135
+ < Editable . Area ref = { ref } className = { css ( { display : "flex" } ) } >
126
136
< Editable . Input
127
137
className = { css ( {
128
138
margin :"0 -2px -1px!" ,
@@ -141,7 +151,7 @@ export const EditableValue = (props: EditableValueProps) => {
141
151
onBlur = { ( ) => setKey ( ( key ) => key + 1 ) }
142
152
aria-label = "Property value"
143
153
/>
144
- < EditablePreview />
154
+ < EditablePreview parentRef = { parentRef } />
145
155
</ Editable . Area >
146
156
{ isRemovable && (
147
157
< Tooltip
@@ -188,12 +198,15 @@ export const EditableValue = (props: EditableValueProps) => {
188
198
/>
189
199
</ Tooltip >
190
200
) }
191
- < span > ;</ span >
192
201
</ Editable . Root >
193
202
) ;
194
203
} ;
195
204
196
- const EditablePreview = ( ) => {
205
+ const EditablePreview = ( {
206
+ parentRef,
207
+ } :{
208
+ parentRef :React . RefObject < HTMLSpanElement > ;
209
+ } ) => {
197
210
const ctx = useEditableContext ( ) ;
198
211
const filter = useSelector ( store , ( s ) => s . context . filter ) ;
199
212
@@ -202,6 +215,12 @@ const EditablePreview = () => {
202
215
< HighlightMatch highlight = { filter } >
203
216
{ ctx . previewProps . children }
204
217
</ HighlightMatch >
218
+ < Portal container = { parentRef } >
219
+ < span className = { css ( { display :ctx . isEditing ?"contents" :"none" } ) } >
220
+ ;
221
+ </ span >
222
+ </ Portal >
223
+ { ctx . isEditing ?null :< span > ;</ span > }
205
224
</ span >
206
225
) ;
207
226
} ;