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

Commit 0f6545b

Browse files
committed
Merge branch 'bug-style-dnd'
2 parents 14ebba7 + 9764643 commit 0f6545b

File tree

8 files changed

+119
-33
lines changed

8 files changed

+119
-33
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

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The information you add or edit will be saved into the target obsidian note.
1818
- Edit label of existed column
1919
- Delete column
2020
- Order column ascending/descending
21+
- Drag & drop column. Order of the columns persisted
2122
#### Filters
2223
- Global filters
2324
![GlobalFilter.gif](docs/resources/GlobalFilter.gif)
@@ -26,6 +27,21 @@ The information you add or edit will be saved into the target obsidian note.
2627
Database view read the yaml configuration inside .md file and render a react DOM.
2728

2829
You can edit directly the yaml configuration inside the .md file or use the table features to edit the columns.
30+
#### Information
31+
Details about your database
32+
- **name**: Name asociated to your database (TODO)
33+
- **description**: extra information explaining the purpose of the database (TODO)
34+
#### Database
35+
The *columns* key is used to charge the correct information when you charge the react-table. Each column supports all the literals of react-table column configurations.
36+
Mandatory:
37+
- **input**: indicates the type of the column (text,markdown & number)
38+
- **key**: name of obsidian field metadata in your notes (inline not supported edition yet)
39+
- **accessor**: is the key of the data. Must be unique
40+
- **label**: name of the column
41+
Optional:
42+
- **position**: order of the columns
43+
#### Local configuration
44+
2945
```markdown
3046
---
3147

@@ -36,25 +52,38 @@ database-plugin: basic
3652
name: undefined
3753
description: undefined
3854
columns:
39-
1:
55+
title:
4056
input: text
4157
accessor: title
4258
label: title
4359
key: title
44-
2:
60+
position: 1
61+
director:
4562
input: text
4663
accessor: director
4764
label: director
4865
key: director
49-
3:
66+
position: 2
67+
Year:
5068
input: number
5169
accessor: Year
5270
label: Year
5371
key: Year
54-
5:
72+
position: 3
73+
Calification:
5574
input: select
5675
accessor: Calification
5776
label: Calification
5877
key: Calification
78+
position: 4
79+
config:
80+
enable_show_state: false
5981
%%>
60-
```
82+
```
83+
84+
## Sources
85+
### Search engine:
86+
- [dataview](https://github.com/blacksmithgu/obsidian-dataview)
87+
### React UI
88+
- [react-table](https://github.com/TanStack/react-table)
89+
- [Notion Style base](https://github.com/archit-p/editable-react-table)

docs/docs/changelog.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## 0.0.5
2+
### Shiny new things
3+
- Added Drag & Drop columns. Order is persisted [ISSUE#5](https://github.com/RafaelGB/obsidian-bd-folder/issues/5)
4+
- Style background of the table is now adapted to the theme [PR#9](https://github.com/RafaelGB/obsidian-bd-folder/pull/9) [zubayrrr](https://github.com/zubayrrr)
5+
6+
### Developers
7+
- State of table toggle configuration added. Show react table state at bottom of the page. It has a default value & local value of each dadabase.
8+
9+
## 0.0.4
10+
### Shiny new things
11+
- Global filters added
12+
13+
## 0.0.3
14+
### Shiny new things
15+
- Order rows `alphanumericFalsyLast`
16+
- Label of columns now is editable
17+
- Add new columns
18+
- Delete columns
19+
- Modify type of column
20+
21+
## 0.0.2
22+
Initial version. Basic database view.
23+
### Shiny `things`
24+
- Cells are editable
25+
- Cell can render markdown
26+
- metadata columns added (just target file) Not configurable yet
27+
### Developers
28+
- LOGGER console configuration with 4 levels: debug, info, warn, error

manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"id": "dbfolder",
33
"name": "DB Folder",
4-
"version": "0.0.4",
5-
"minAppVersion": "0.14.5",
4+
"version": "0.0.5",
5+
"minAppVersion": "0.14.6",
66
"description": "Folder with the capability to store and retrieve data from a folder like database",
77
"author": "RafaelGB",
88
"authorUrl": "https://github.com/RafaelGB/obsidian-bd-folder",

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)