@@ -15,6 +15,7 @@ import {
15
15
StompContext ,
16
16
tfetch ,
17
17
doTry ,
18
+ getRemInPixel ,
18
19
} from "src/util.js"
19
20
20
21
export const Chat = ( { chatId} ) => {
@@ -103,7 +104,7 @@ export const Chat = ({chatId}) => {
103
104
/>
104
105
< form className = "flex-none mb-2" onSubmit = { onSendMessage } >
105
106
< input
106
- className = "w-full rounded-lg p -2 border border-gray-500 bg-stone-800 text-stone-100 focus:outline-none"
107
+ className = "w-full px-1 py -2 border border-gray-500 bg-stone-800 text-stone-100 focus:outline-none"
107
108
type = "text"
108
109
name = "message"
109
110
/>
@@ -124,7 +125,7 @@ function isLastChildVisible(container) {
124
125
125
126
function SplitPane ( { messageRef, topElement, bottomElement} ) {
126
127
let [ dragging , setDragging ] = useState ( false )
127
- let [ splitPos , setSplitPos ] = useState ( 200.5 )
128
+ let [ splitPos , setSplitPos ] = useState ( 200 )
128
129
let draggingRef = useRef ( )
129
130
let containerRef = useRef ( )
130
131
draggingRef . current = dragging
@@ -133,13 +134,13 @@ function SplitPane({messageRef, topElement, bottomElement}) {
133
134
if ( ! draggingRef . current ) {
134
135
return
135
136
}
136
- setSplitPos ( getSplitPos ( e . clientY , containerRef ) )
137
+ setSplitPos ( getSplitPos ( e . clientY , containerRef . current ) )
137
138
}
138
139
let mouseup = ( e ) => {
139
140
if ( ! draggingRef . current ) {
140
141
return
141
142
}
142
- setSplitPos ( getSplitPos ( e . clientY , containerRef ) )
143
+ setSplitPos ( getSplitPos ( e . clientY , containerRef . current ) )
143
144
setDragging ( false )
144
145
}
145
146
window . document . addEventListener ( "mousemove" , mousemove )
@@ -151,7 +152,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
151
152
} , [ draggingRef , setDragging ] )
152
153
let onMouseDown = useCallback ( ( e ) => {
153
154
e . preventDefault ( )
154
- setSplitPos ( getSplitPos ( e . clientY , containerRef ) )
155
+ setSplitPos ( getSplitPos ( e . clientY , containerRef . current ) )
155
156
setDragging ( true )
156
157
} , [ setDragging , setSplitPos ] )
157
158
let topElementHeight = Math . trunc ( splitPos )
@@ -162,10 +163,17 @@ function SplitPane({messageRef, topElement, bottomElement}) {
162
163
return (
163
164
< div
164
165
ref = { ( ref ) => {
166
+ if ( ! ref ) {
167
+ return
168
+ }
169
+ if ( ! containerRef . current ) {
170
+ let rect = ref . getBoundingClientRect ( )
171
+ setSplitPos ( getSplitPos ( rect . top , ref ) )
172
+ }
165
173
containerRef . current = ref
166
174
} }
167
175
className = { twJoin (
168
- "grow border border-gray-500 bg-gray-900 rounded-lg flex flex-col overflow-y-hidden" ,
176
+ "grow border-t border-x border- gray-500 bg-gray-900 flex flex-col overflow-y-hidden" ,
169
177
dragging && "cursor-row-resize" ,
170
178
) } >
171
179
< div
@@ -174,7 +182,7 @@ function SplitPane({messageRef, topElement, bottomElement}) {
174
182
{ topElement }
175
183
</ div >
176
184
< SplitBar
177
- containerRef = { containerRef }
185
+ container = { containerRef . current }
178
186
splitPos = { splitPos }
179
187
dragging = { dragging }
180
188
onMouseDown = { onMouseDown } />
@@ -185,35 +193,38 @@ function SplitPane({messageRef, topElement, bottomElement}) {
185
193
)
186
194
}
187
195
188
- function SplitBar ( { splitPos, dragging, onMouseDown, containerRef} ) {
189
- let width = 100 , left = 10 // some default values
190
- if ( containerRef . current ) {
191
- let container = containerRef . current
192
- let rect = containerRef . current . getBoundingClientRect ( )
193
- let parentRect = container . parentNode . getBoundingClientRect ( )
194
- width = rect . width
195
- left = rect . left - parentRect . left
196
+ function SplitBar ( { splitPos, dragging, onMouseDown, container} ) {
197
+ if ( ! container ) {
198
+ return < div />
196
199
}
200
+ let innerHeight = Math . trunc ( getRemInPixel ( ) * 0.5 )
201
+ let rect = container . getBoundingClientRect ( )
202
+ let parentRect = container . parentNode . getBoundingClientRect ( )
203
+ let width = rect . width
204
+ let left = rect . left - parentRect . left
197
205
return < >
198
206
< div
199
207
onMouseDown = { dragging ? undefined : onMouseDown }
200
- style = { { top : Math . trunc ( splitPos - 1 ) + 0.5 , width : width , left : left } }
208
+ style = { { top : Math . trunc ( splitPos - 1 ) + 0.5 , height : 1 , width : width , left : left } }
201
209
className = "absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
202
210
< div
203
211
onMouseDown = { dragging ? undefined : onMouseDown }
204
- style = { { top : Math . trunc ( splitPos ) + 0.5 , width : width , left : left } }
205
- className = "absolute h-[5px] bg-slate-800 z-20 cursor-row-resize" />
212
+ style = { { top : Math . trunc ( splitPos ) + 0.5 , height : innerHeight , width : width , left : left } }
213
+ className = "absolute bg-slate-800 z-20 cursor-row-resize" />
206
214
< div
207
215
onMouseDown = { dragging ? undefined : onMouseDown }
208
- style = { { top : Math . trunc ( splitPos + 5 ) + 0.5 , width : width , left : left } }
216
+ style = { { top : Math . trunc ( splitPos + innerHeight ) + 0.5 , height : 1 , width : width , left : left } }
209
217
className = "absolute h-[1px] bg-gray-500 z-20 cursor-row-resize" />
210
218
</ >
211
219
}
212
220
213
- function getSplitPos ( clientY , containerRef ) {
214
- let rect = containerRef . current . getBoundingClientRect ( )
215
- let result = clientY
216
- result = Math . max ( rect . top + 40 , result )
217
- result = Math . min ( rect . top + rect . height - 40 , result )
221
+ function getSplitPos ( clientY , container ) {
222
+ if ( ! container ) {
223
+ return Math . trunc ( clientY )
224
+ }
225
+ let rect = container . getBoundingClientRect ( )
226
+ let safety = 4 * getRemInPixel ( )
227
+ let result = Math . max ( rect . top + safety , clientY )
228
+ result = Math . min ( rect . top + rect . height - safety , result )
218
229
return Math . trunc ( result )
219
230
}
0 commit comments