prosemirror-tables
Advanced tools
Comparing version 0.7.2 to 0.7.3
{ | ||
"name": "prosemirror-tables", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "ProseMirror's rowspan/colspan tables component", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -10,2 +10,3 @@ // This file defines a number of table-related commands. | ||
import {tableNodeTypes} from "./schema" | ||
import {cellWrapping, cellAround} from './util' | ||
@@ -279,5 +280,13 @@ // Helper to get the selected rectangle in a table, if any. Adds table | ||
let sel = state.selection | ||
if (!(sel instanceof CellSelection) || sel.$anchorCell.pos != sel.$headCell.pos) return false | ||
let cellNode = sel.$anchorCell.nodeAfter | ||
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) return false | ||
let cellNode, cellPos | ||
if (!(sel instanceof CellSelection)) { | ||
cellNode = cellWrapping(sel.$from) | ||
if (!cellNode) return false | ||
cellPos = cellAround(sel.$from).pos | ||
} else { | ||
if (sel.$anchorCell.pos != sel.$headCell.pos) return false | ||
cellNode = sel.$anchorCell.nodeAfter | ||
cellPos = sel.$anchorCell.pos | ||
} | ||
if (cellNode.attrs.colspan == 1 && cellNode.attrs.rowspan == 1) {return false} | ||
if (dispatch) { | ||
@@ -301,5 +310,6 @@ let baseAttrs = cellNode.attrs, attrs = [], colwidth = baseAttrs.colwidth | ||
} | ||
tr.setNodeMarkup(sel.$anchorCell.pos, null, attrs[0]) | ||
tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), | ||
lastCell && tr.doc.resolve(lastCell))) | ||
tr.setNodeMarkup(cellPos, null, attrs[0]) | ||
if (sel instanceof CellSelection) | ||
tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos), | ||
lastCell && tr.doc.resolve(lastCell))) | ||
dispatch(tr) | ||
@@ -306,0 +316,0 @@ } |
@@ -15,2 +15,8 @@ // Various helper function for working with tables | ||
export function cellWrapping($pos) { | ||
for (var d = $pos.depth - 1; d > 0; d--) | ||
if ($pos.node(d).type.spec.tableRole == "cell") return $pos.node(d) | ||
return null | ||
} | ||
export function isInTable(state) { | ||
@@ -17,0 +23,0 @@ let $head = state.selection.$head |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1011544
23
19000
1