Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-tables

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-tables - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

22

package.json
{
"name": "prosemirror-tables",
"version": "0.3.0",
"version": "0.4.0",
"description": "ProseMirror's rowspan/colspan tables component",

@@ -23,7 +23,7 @@ "main": "dist/index.js",

"dependencies": {
"prosemirror-keymap": "^0.24.0",
"prosemirror-model": "^0.24.0",
"prosemirror-state": "^0.24.0",
"prosemirror-transform": "^0.24.0",
"prosemirror-view": "^0.24.0"
"prosemirror-keymap": "^1.0.0",
"prosemirror-model": "^1.0.0",
"prosemirror-state": "^1.0.0",
"prosemirror-transform": "^1.0.0",
"prosemirror-view": "^1.0.0"
},

@@ -33,7 +33,7 @@ "devDependencies": {

"mocha": "^3.4.2",
"prosemirror-commands": "^0.24.0",
"prosemirror-example-setup": "^0.24.0",
"prosemirror-menu": "^0.24.0",
"prosemirror-schema-basic": "^0.24.0",
"prosemirror-test-builder": "^0.24.0",
"prosemirror-commands": "^1.0.0",
"prosemirror-example-setup": "^1.0.0",
"prosemirror-menu": "^1.0.0",
"prosemirror-schema-basic": "^1.0.0",
"prosemirror-test-builder": "^1.0.0",
"rollup": "^0.49.0",

@@ -40,0 +40,0 @@ "rollup-plugin-buble": "^0.15.0",

@@ -91,23 +91,23 @@ import {Plugin, PluginKey} from "prosemirror-state"

let pluginState = key.getState(view.state)
if (pluginState.activeHandle > -1 && !pluginState.dragging) {
let cell = view.state.doc.nodeAt(pluginState.activeHandle)
let width = currentColWidth(view, pluginState.activeHandle, cell.attrs)
view.dispatch(view.state.tr.setMeta(key, {setDragging: {startX: event.clientX, startWidth: width}}))
if (pluginState.activeHandle == -1 || pluginState.dragging) return false
function finish(event) {
window.removeEventListener("mouseup", finish)
window.removeEventListener("mousemove", move)
let pluginState = key.getState(view.state)
if (pluginState.dragging) {
updateColumnWidth(view, pluginState.activeHandle, draggedWidth(pluginState.dragging, event, cellMinWidth))
view.dispatch(view.state.tr.setMeta(key, {setDragging: null}))
}
let cell = view.state.doc.nodeAt(pluginState.activeHandle)
let width = currentColWidth(view, pluginState.activeHandle, cell.attrs)
view.dispatch(view.state.tr.setMeta(key, {setDragging: {startX: event.clientX, startWidth: width}}))
function finish(event) {
window.removeEventListener("mouseup", finish)
window.removeEventListener("mousemove", move)
let pluginState = key.getState(view.state)
if (pluginState.dragging) {
updateColumnWidth(view, pluginState.activeHandle, draggedWidth(pluginState.dragging, event, cellMinWidth))
view.dispatch(view.state.tr.setMeta(key, {setDragging: null}))
}
function move(event) { if (!event.which) finish(event) }
}
function move(event) { if (!event.which) finish(event) }
window.addEventListener("mouseup", finish)
window.addEventListener("mousemove", move)
event.preventDefault()
return true
}
window.addEventListener("mouseup", finish)
window.addEventListener("mousemove", move)
event.preventDefault()
return true
}

@@ -166,3 +166,3 @@

colwidth[index] = width
tr.setNodeType(start + pos, null, setAttr(attrs, "colwidth", colwidth))
tr.setNodeMarkup(start + pos, null, setAttr(attrs, "colwidth", colwidth))
}

@@ -169,0 +169,0 @@ if (tr.docChanged) view.dispatch(tr)

@@ -47,4 +47,4 @@ // This file defines a number of table-related commands.

let pos = map.map[index], cell = table.nodeAt(pos)
tr.setNodeType(tr.mapping.map(tableStart + pos), null,
addColSpan(cell.attrs, col - map.colCount(pos)))
tr.setNodeMarkup(tr.mapping.map(tableStart + pos), null,
addColSpan(cell.attrs, col - map.colCount(pos)))
// Skip ahead if rowspan > 1

@@ -90,4 +90,4 @@ row += cell.attrs.rowspan - 1

if ((col > 0 && map.map[index - 1] == pos) || (col < map.width - 1 && map.map[index + 1] == pos)) {
tr.setNodeType(tr.mapping.slice(mapStart).map(tableStart + pos), null,
rmColSpan(cell.attrs, col - map.colCount(pos)))
tr.setNodeMarkup(tr.mapping.slice(mapStart).map(tableStart + pos), null,
rmColSpan(cell.attrs, col - map.colCount(pos)))
} else {

@@ -137,3 +137,3 @@ let start = tr.mapping.slice(mapStart).map(tableStart + pos)

let pos = map.map[index], attrs = table.nodeAt(pos).attrs
tr.setNodeType(tableStart + pos, null, setAttr(attrs, "rowspan", attrs.rowspan + 1))
tr.setNodeMarkup(tableStart + pos, null, setAttr(attrs, "rowspan", attrs.rowspan + 1))
col += attrs.colspan - 1

@@ -185,3 +185,3 @@ } else {

let attrs = table.nodeAt(pos).attrs
tr.setNodeType(tr.mapping.slice(mapFrom).map(pos + tableStart), null, setAttr(attrs, "rowspan", attrs.rowspan - 1))
tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + tableStart), null, setAttr(attrs, "rowspan", attrs.rowspan - 1))
col += attrs.colspan - 1

@@ -263,5 +263,5 @@ } else if (row < map.width && pos == map.map[index + map.width]) {

}
tr.setNodeType(mergedPos + rect.tableStart, null,
setAttr(addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, (rect.right - rect.left) - mergedCell.attrs.colspan),
"rowspan", rect.bottom - rect.top))
tr.setNodeMarkup(mergedPos + rect.tableStart, null,
setAttr(addColSpan(mergedCell.attrs, mergedCell.attrs.colspan, (rect.right - rect.left) - mergedCell.attrs.colspan),
"rowspan", rect.bottom - rect.top))
if (content.size) {

@@ -304,3 +304,3 @@ let end = mergedPos + 1 + mergedCell.content.size

}
tr.setNodeType(sel.$anchorCell.pos, null, attrs[0])
tr.setNodeMarkup(sel.$anchorCell.pos, null, attrs[0])
tr.setSelection(new CellSelection(tr.doc.resolve(sel.$anchorCell.pos),

@@ -327,6 +327,6 @@ lastCell && tr.doc.resolve(lastCell)))

if (node.attrs[name] !== value)
tr.setNodeType(pos, null, setAttr(node.attrs, name, value))
tr.setNodeMarkup(pos, null, setAttr(node.attrs, name, value))
})
else
tr.setNodeType($cell.pos, null, setAttr($cell.nodeAfter.attrs, name, value))
tr.setNodeMarkup($cell.pos, null, setAttr($cell.nodeAfter.attrs, name, value))
dispatch(tr)

@@ -349,5 +349,5 @@ }

if (nodes[i].type == types.header_cell)
tr.setNodeType(rect.tableStart + cells[i], types.cell, nodes[i].attrs)
tr.setNodeMarkup(rect.tableStart + cells[i], types.cell, nodes[i].attrs)
if (tr.steps.length == 0) for (let i = 0; i < cells.length; i++) // No headers removed, add instead
tr.setNodeType(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs)
tr.setNodeMarkup(rect.tableStart + cells[i], types.header_cell, nodes[i].attrs)
dispatch(tr)

@@ -354,0 +354,0 @@ }

@@ -173,3 +173,3 @@ // Utilities used for copy/paste handling.

let {top: cellTop, left: cellLeft} = map.findCell(pos)
tr.setNodeType(tr.mapping.slice(mapFrom).map(pos + start), null, setAttr(cell.attrs, "rowspan", top - cellTop))
tr.setNodeMarkup(tr.mapping.slice(mapFrom).map(pos + start), null, setAttr(cell.attrs, "rowspan", top - cellTop))
tr.insert(tr.mapping.slice(mapFrom).map(map.positionAt(top, cellLeft, table)),

@@ -195,3 +195,3 @@ cell.type.createAndFill(setAttr(cell.attrs, "rowspan", (cellTop + cell.attrs.rowspan) - top)))

let updatePos = tr.mapping.slice(mapFrom).map(pos + start)
tr.setNodeType(updatePos, null, rmColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)))
tr.setNodeMarkup(updatePos, null, rmColSpan(cell.attrs, left - cellLeft, cell.attrs.colspan - (left - cellLeft)))
tr.insert(updatePos + cell.nodeSize, cell.type.createAndFill(rmColSpan(cell.attrs, 0, left - cellLeft)))

@@ -198,0 +198,0 @@ row += cell.attrs.rowspan - 1

@@ -65,3 +65,3 @@ // This file defines helpers for normalizing tables, making sure no

for (let j = 0; j < cell.attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n
tr.setNodeType(tr.mapping.map(tablePos + 1 + prob.pos), null, rmColSpan(cell.attrs, cell.attrs.colspan - prob.n, prob.n))
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, rmColSpan(cell.attrs, cell.attrs.colspan - prob.n, prob.n))
} else if (prob.type == "missing") {

@@ -71,6 +71,6 @@ mustAdd[prob.row] += prob.n

let cell = table.nodeAt(prob.pos)
tr.setNodeType(tr.mapping.map(tablePos + 1 + prob.pos), null, setAttr(cell.attrs, "rowspan", cell.attrs.rowspan - prob.n))
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, setAttr(cell.attrs, "rowspan", cell.attrs.rowspan - prob.n))
} else if (prob.type == "colwidth mismatch") {
let cell = table.nodeAt(prob.pos)
tr.setNodeType(tr.mapping.map(tablePos + 1 + prob.pos), null, setAttr(cell.attrs, "colwidth", prob.colwidth))
tr.setNodeMarkup(tr.mapping.map(tablePos + 1 + prob.pos), null, setAttr(cell.attrs, "colwidth", prob.colwidth))
}

@@ -77,0 +77,0 @@ }

@@ -77,2 +77,3 @@ // Helper for creating a schema that supports tables.

tableRole: "table",
isolating: true,
group: options.tableGroup,

@@ -79,0 +80,0 @@ parseDOM: [{tag: "table"}],

@@ -23,9 +23,19 @@ // Various helper function for working with tables

let sel = state.selection
if (sel instanceof NodeSelection && sel.$from.parent.type.spec.tableRole == "row") return sel.$from
if (sel.$anchorCell) {
return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
}
return sel.$anchorCell || cellAround(sel.$head)
return sel.$anchorCell || cellAround(sel.$head) || cellNear(sel.$head)
}
function cellNear($pos) {
for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
let role = after.type.spec.tableRole
if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos)
}
for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
let role = after.type.spec.tableRole
if (role == "cell" || role == "header_cell") return $pos.doc.resolve(pos - before.nodeSize)
}
}
export function pointsAtCell($pos) {

@@ -32,0 +42,0 @@ return $pos.parent.type.spec.tableRole == "row" && $pos.nodeAfter

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc