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.7.0 to 0.7.1

2

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

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -9,6 +9,15 @@ # ProseMirror table module

The top-level directory contains a `demo.js` and `index.html`, which
can be built with `npm run build_demo` to show a simple demo of how the
module can be used.
## Getting started
To see a demo comprised of **index.html** and **demo.js** running in a browser, follow these steps:
```
git clone git@github.com:ProseMirror/prosemirror-tables.git
cd prosemirror-tables
npm install
npm run build_demo
```
Then open **index.html** with your browser.
## Documentation

@@ -15,0 +24,0 @@

@@ -26,3 +26,3 @@ // This file defines a plugin that handles the drawing of cell

// perform more specific behavior.
export function tableEditing(options = {}) {
export function tableEditing() {
return new Plugin({

@@ -58,3 +58,3 @@ key,

handleKeyDown: handleKeyDown(options.deleteRowsAndColumns),
handleKeyDown,

@@ -61,0 +61,0 @@ handlePaste

@@ -14,23 +14,24 @@ // This file defines a number of helpers for wiring up user input to

import {tableNodeTypes} from "./schema"
import {deleteRow, deleteColumn} from "./commands"
export function handleKeyDown(options) {
let deleteCellSel = deleteCellSelection(options)
export const handleKeyDown = keydownHandler({
"ArrowLeft": arrow("horiz", -1),
"ArrowRight": arrow("horiz", 1),
"ArrowUp": arrow("vert", -1),
"ArrowDown": arrow("vert", 1),
return keydownHandler({
"ArrowLeft": arrow("horiz", -1),
"ArrowRight": arrow("horiz", 1),
"ArrowUp": arrow("vert", -1),
"ArrowDown": arrow("vert", 1),
"Shift-ArrowLeft": shiftArrow("horiz", -1),
"Shift-ArrowRight": shiftArrow("horiz", 1),
"Shift-ArrowUp": shiftArrow("vert", -1),
"Shift-ArrowDown": shiftArrow("vert", 1),
"Shift-ArrowLeft": shiftArrow("horiz", -1),
"Shift-ArrowRight": shiftArrow("horiz", 1),
"Shift-ArrowUp": shiftArrow("vert", -1),
"Shift-ArrowDown": shiftArrow("vert", 1),
"Backspace": deleteCellSelection,
"Mod-Backspace": deleteCellSelection,
"Delete": deleteCellSelection,
"Mod-Delete": deleteCellSelection
})
"Backspace": deleteCellSel,
"Mod-Backspace": deleteCellSel,
"Delete": deleteCellSel,
"Mod-Delete": deleteCellSel
})
function maybeSetSelection(state, dispatch, selection) {
if (selection.eq(state.selection)) return false
if (dispatch) dispatch(state.tr.setSelection(selection))
return true
}

@@ -42,4 +43,3 @@

if (sel instanceof CellSelection) {
dispatch(state.tr.setSelection(Selection.near(sel.$headCell, dir)))
return true
return maybeSetSelection(state, dispatch, Selection.near(sel.$headCell, dir))
}

@@ -50,4 +50,3 @@ if (axis != "horiz" && !sel.empty) return false

if (axis == "horiz") {
dispatch(state.tr.setSelection(Selection.near(state.doc.resolve(sel.head + dir), dir)))
return true
return maybeSetSelection(state, dispatch, Selection.near(state.doc.resolve(sel.head + dir), dir))
} else {

@@ -58,4 +57,3 @@ let $cell = state.doc.resolve(end), $next = nextCell($cell, axis, dir), newSel

else newSel = Selection.near(state.doc.resolve($cell.after(-1)), 1)
dispatch(state.tr.setSelection(newSel))
return true
return maybeSetSelection(state, dispatch, newSel)
}

@@ -75,26 +73,19 @@ }

if (!$head) return false
if (dispatch) dispatch(state.tr.setSelection(new CellSelection(sel.$anchorCell, $head)))
return true
return maybeSetSelection(state, dispatch, new CellSelection(sel.$anchorCell, $head))
}
}
function deleteCellSelection(options) {
return function(state, dispatch) {
let sel = state.selection
if (!(sel instanceof CellSelection)) return false
if (dispatch) {
if (options.deleteRowsAndColumns || true) {
if (sel.isRowSelection()) return deleteColumn(state, dispatch)
else if (sel.isColSelection()) return deleteRow(state, dispatch)
}
let tr = state.tr, baseContent = tableNodeTypes(state.schema).cell.createAndFill().content
sel.forEachCell((cell, pos) => {
if (!cell.content.eq(baseContent))
tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1),
new Slice(baseContent, 0, 0))
})
if (tr.docChanged) dispatch(tr)
}
return true
function deleteCellSelection(state, dispatch) {
let sel = state.selection
if (!(sel instanceof CellSelection)) return false
if (dispatch) {
let tr = state.tr, baseContent = tableNodeTypes(state.schema).cell.createAndFill().content
sel.forEachCell((cell, pos) => {
if (!cell.content.eq(baseContent))
tr.replace(tr.mapping.map(pos + 1), tr.mapping.map(pos + cell.nodeSize - 1),
new Slice(baseContent, 0, 0))
})
if (tr.docChanged) dispatch(tr)
}
return true
}

@@ -101,0 +92,0 @@

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

Sorry, the diff of this file is not supported yet

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