prosemirror-tables
Advanced tools
Comparing version 0.7.6 to 0.7.7
{ | ||
"name": "prosemirror-tables", | ||
"version": "0.7.6", | ||
"version": "0.7.7", | ||
"description": "ProseMirror's rowspan/colspan tables component", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -9,2 +9,12 @@ # ProseMirror table module | ||
Note that Firefox will, by default, add various kinds of controls to | ||
editable tables, even though those don't work in ProseMirror. The only | ||
way to turn these off is globally, which you might want to do with the | ||
following code: | ||
```javascript | ||
document.execCommand("enableObjectResizing", false, "false") | ||
document.execCommand("enableInlineTableEditing", false, "false") | ||
``` | ||
## Getting started | ||
@@ -11,0 +21,0 @@ |
@@ -252,2 +252,25 @@ // This file defines a ProseMirror selection subclass that models | ||
function isTextSelectionAcrossCells({$from, $to}) { | ||
let fromCellBoundaryNode; | ||
let toCellBoundaryNode; | ||
for (let i = $from.depth; i > 0; i--) { | ||
let node = $from.node(i); | ||
if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') { | ||
fromCellBoundaryNode = node; | ||
break; | ||
} | ||
} | ||
for (let i = $to.depth; i > 0; i--) { | ||
let node = $to.node(i); | ||
if (node.type.spec.tableRole === 'cell' || node.type.spec.tableRole === 'header_cell') { | ||
toCellBoundaryNode = node; | ||
break; | ||
} | ||
} | ||
return fromCellBoundaryNode !== toCellBoundaryNode && $to.parentOffset === 0 | ||
} | ||
export function normalizeSelection(state, tr) { | ||
@@ -268,2 +291,4 @@ let sel = (tr || state).selection, doc = (tr || state).doc, normalize, role | ||
normalize = TextSelection.create(doc, sel.from) | ||
} else if (sel instanceof TextSelection && isTextSelectionAcrossCells(sel)) { | ||
normalize = TextSelection.create(doc, sel.$from.start(), sel.$from.end()); | ||
} | ||
@@ -270,0 +295,0 @@ if (normalize) |
@@ -86,8 +86,13 @@ // This file defines helpers for normalizing tables, making sure no | ||
for (let i = 0, pos = tablePos + 1; i < map.height; i++) { | ||
let end = pos + table.child(i).nodeSize | ||
let row = table.child(i) | ||
let end = pos + row.nodeSize | ||
let add = mustAdd[i] | ||
if (add > 0) { | ||
let tableNodeType = 'cell'; | ||
if (row.firstChild) { | ||
tableNodeType = row.firstChild.type.spec.tableRole | ||
} | ||
let nodes = [] | ||
for (let j = 0; j < add; j++) | ||
nodes.push(tableNodeTypes(state.schema).cell.createAndFill()) | ||
nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill()) | ||
let side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1 | ||
@@ -94,0 +99,0 @@ tr.insert(tr.mapping.map(side), nodes) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1018607
19081
246