mirror of
https://github.com/docmost/docmost.git
synced 2025-11-20 21:21:10 +10:00
feat: table row/column drag and drop (#1467)
* chore: add dev container * feat: add drag handle when hovering cell * feat: add column drag and drop * feat: add support for row drag and drop * refactor: extract preview controllers * fix: hover issue * refactor: add handle controller * chore: f * chore: remove log * chore: remove dev files * feat: hide other drop indicators when table dnd working * feat: add auto scroll and bug fix * chore: f * fix: firefox
This commit is contained in:
@ -0,0 +1,44 @@
|
||||
import type { Node } from '@tiptap/pm/model'
|
||||
import { TableMap } from '@tiptap/pm/tables'
|
||||
|
||||
/**
|
||||
* Convert an array of rows to a table node.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export function convertArrayOfRowsToTableNode(
|
||||
tableNode: Node,
|
||||
arrayOfNodes: (Node | null)[][],
|
||||
): Node {
|
||||
const rowsPM = []
|
||||
const map = TableMap.get(tableNode)
|
||||
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
||||
const row = tableNode.child(rowIndex)
|
||||
const rowCells = []
|
||||
|
||||
for (let colIndex = 0; colIndex < map.width; colIndex++) {
|
||||
if (!arrayOfNodes[rowIndex][colIndex]) continue
|
||||
|
||||
const cellPos = map.map[rowIndex * map.width + colIndex]
|
||||
|
||||
const cell = arrayOfNodes[rowIndex][colIndex]!
|
||||
const oldCell = tableNode.nodeAt(cellPos)!
|
||||
const newCell = oldCell.type.createChecked(
|
||||
Object.assign({}, cell.attrs),
|
||||
cell.content,
|
||||
cell.marks,
|
||||
)
|
||||
rowCells.push(newCell)
|
||||
}
|
||||
|
||||
rowsPM.push(row.type.createChecked(row.attrs, rowCells, row.marks))
|
||||
}
|
||||
|
||||
const newTable = tableNode.type.createChecked(
|
||||
tableNode.attrs,
|
||||
rowsPM,
|
||||
tableNode.marks,
|
||||
)
|
||||
|
||||
return newTable
|
||||
}
|
||||
Reference in New Issue
Block a user