Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 1ce6217

Browse files
committed
working!
1 parent 1b1c317 commit 1ce6217

File tree

5 files changed

+55
-26
lines changed

5 files changed

+55
-26
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ main.js
1313

1414
# obsidian
1515
data.json
16-
.DS_Store
16+
.DS_Store
17+
18+
# VSCode
19+
*.code-workspace

src/components/Table.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { LOGGER } from "services/Logger";
2525
import Cell from "components/Cell";
2626
import Header from "components/Header";
2727
import GlobalFilter from "components/reducers/GlobalFilter";
28-
import DraggableStyle from "components/styles/DragableStyle";
28+
import { useDraggableInPortal } from "components/portals/UseDraggableInPortal";
2929

3030
const defaultColumn = {
3131
minWidth: 50,
@@ -208,6 +208,7 @@ export function Table(initialState: TableDataType){
208208
}
209209
// Manage DnD
210210
const currentColOrder = React.useRef(null);
211+
const renderDraggable = useDraggableInPortal();
211212
// Manage input of new row
212213
const [inputNewRow, setInputNewRow] = React.useState('');
213214
const newRowRef = React.useRef(null);
@@ -249,12 +250,17 @@ export function Table(initialState: TableDataType){
249250
currentColOrder.current = null;
250251
}}
251252
>
252-
<Droppable key={`Droppable-${i}`} droppableId="droppable" direction="horizontal">
253+
<Droppable
254+
key={`Droppable-${i}`}
255+
droppableId="droppable"
256+
direction="horizontal"
257+
>
253258
{(droppableProvided, snapshot) => (
254259
<div
260+
key={`div-Droppable-${i}`}
255261
{...headerGroup.getHeaderGroupProps()}
256262
ref={droppableProvided.innerRef}
257-
className='tr'
263+
className='tr header-group'
258264
>
259265
{headerGroup.headers.map((column,index) => (
260266

@@ -264,24 +270,18 @@ export function Table(initialState: TableDataType){
264270
index={index}
265271
isDragDisabled={(column as any).isMetadata}
266272
>
267-
{(provided, snapshot) => {
273+
{renderDraggable((provided) => {
268274
return (
269275
<div
270276
{...column.getHeaderProps()}
271-
className='th noselect'
277+
className='th noselect header'
272278
>
273279
<div
280+
key={`div-Draggable-${column.id}`}
274281
{...provided.draggableProps}
275282
{...provided.dragHandleProps}
276283
// {...extraProps}
277284
ref={provided.innerRef}
278-
style={{
279-
...DraggableStyle({
280-
dragableProps: snapshot,
281-
draggableStyle: provided.draggableProps.style
282-
})
283-
// ...style
284-
}}
285285
>
286286
{column.render("Header")}
287287
{/* Use column.getResizerProps to hook up the events correctly */}
@@ -295,7 +295,7 @@ export function Table(initialState: TableDataType){
295295
</div>
296296
</div>
297297
);
298-
}}
298+
})}
299299
</Draggable>
300300
))}
301301
{droppableProvided.placeholder}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { DraggableProvided, DraggingStyle } from 'react-beautiful-dnd'
2+
import { ReactElement, useEffect, useRef } from 'react'
3+
import { createPortal } from 'react-dom'
4+
5+
export const useDraggableInPortal = () => {
6+
const element = useRef<HTMLDivElement>(document.createElement('div')).current
7+
8+
useEffect(() => {
9+
if (element) {
10+
element.style.pointerEvents = 'none'
11+
element.style.position = 'absolute'
12+
element.style.height = '100%'
13+
element.style.width = '100%'
14+
element.style.top = '0'
15+
16+
document.body.appendChild(element)
17+
18+
return () => {
19+
document.body.removeChild(element)
20+
}
21+
}
22+
}, [element])
23+
24+
return (render: (provided: DraggableProvided) => ReactElement) => (provided: DraggableProvided) => {
25+
const result = render(provided)
26+
const style = provided.draggableProps.style as DraggingStyle
27+
if (style.position === 'fixed') {
28+
return createPortal(result, element)
29+
}
30+
return result
31+
}
32+
}

src/components/styles/DragableStyle.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

styles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ html {
297297
*/
298298
.dbfolder-table-container tr input {
299299
background: var(--background-modifier-box-shadow);
300+
}
300301

301302
.resizer {
302303
display: inline-block;
@@ -314,3 +315,8 @@ html {
314315
.isResizing {
315316
background: rgb(182, 119, 119);
316317
}
318+
319+
.draggable {
320+
top: auto !important;
321+
left: auto !important;
322+
}

0 commit comments

Comments
 (0)