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.11 to 0.8.0

2

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

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

@@ -185,2 +185,7 @@ # ProseMirror table module

* **`toggleHeader`**`(type: string, options: ?{useDeprecatedLogic: bool}) → fn(EditorState, dispatch: ?fn(tr: Transaction)) → bool`\
Toggles between row/column header and normal cells (Only applies to first row/column).
For deprecated behavior pass useDeprecatedLogic in options with true.
* **`goToNextCell`**`(direction: number) → fn(EditorState, dispatch: ?fn(tr: Transaction)) → bool`\

@@ -187,0 +192,0 @@ Returns a command for selecting the next (direction=1) or previous

@@ -341,3 +341,3 @@ // This file defines a number of table-related commands.

function toggleHeader(type) {
function deprecated_toggleHeader(type) {
return function(state, dispatch) {

@@ -362,13 +362,76 @@ if (!isInTable(state)) return false

function isHeaderEnabledByType(type, rect, types) {
// Get cell positions for first row or first column
const cellPositions = rect.map.cellsInRect({
left: 0,
top: 0,
right: type == "row" ? rect.map.width : 1,
bottom: type == "column" ? rect.map.height : 1,
})
for (let i = 0; i < cellPositions.length; i++) {
const cell = rect.table.nodeAt(cellPositions[i])
if (cell && cell.type !== types.header_cell) {
return false
}
}
return true
}
// :: (string, ?{ useDeprecatedLogic: bool }) → (EditorState, dispatch: ?(tr: Transaction)) → bool
// Toggles between row/column header and normal cells (Only applies to first row/column).
// For deprecated behavior pass `useDeprecatedLogic` in options with true.
export function toggleHeader(type, options) {
options = options || { useDeprecatedLogic: false }
if (options.useDeprecatedLogic)
return deprecated_toggleHeader(type)
return function(state, dispatch) {
if (!isInTable(state)) return false
if (dispatch) {
let types = tableNodeTypes(state.schema)
let rect = selectedRect(state), tr = state.tr
let isHeaderRowEnabled = isHeaderEnabledByType("row", rect, types)
let isHeaderColumnEnabled = isHeaderEnabledByType("column", rect, types)
let isHeaderEnabled = type === "column" ? isHeaderRowEnabled :
type === "row" ? isHeaderColumnEnabled : false
let selectionStartsAt = isHeaderEnabled ? 1 : 0
let cellsRect = type == "column" ? new Rect(0, selectionStartsAt, 1, rect.map.height) :
type == "row" ? new Rect(selectionStartsAt, 0, rect.map.width, 1) : rect
let newType = type == "column" ? isHeaderColumnEnabled ? types.cell : types.header_cell :
type == "row" ? isHeaderRowEnabled ? types.cell : types.header_cell : types.cell
rect.map.cellsInRect(cellsRect).forEach(relativeCellPos => {
const cellPos = relativeCellPos + rect.tableStart
const cell = tr.doc.nodeAt(cellPos)
if (cell) {
tr.setNodeMarkup(cellPos, newType, cell.attrs)
}
})
dispatch(tr)
}
return true
}
}
// :: (EditorState, dispatch: ?(tr: Transaction)) → bool
// Toggles whether the selected row contains header cells.
export let toggleHeaderRow = toggleHeader("row")
export let toggleHeaderRow = toggleHeader("row", { useDeprecatedLogic: true })
// :: (EditorState, dispatch: ?(tr: Transaction)) → bool
// Toggles whether the selected column contains header cells.
export let toggleHeaderColumn = toggleHeader("column")
export let toggleHeaderColumn = toggleHeader("column", { useDeprecatedLogic: true })
// :: (EditorState, dispatch: ?(tr: Transaction)) → bool
// Toggles whether the selected cells are header cells.
export let toggleHeaderCell = toggleHeader("cell")
export let toggleHeaderCell = toggleHeader("cell", { useDeprecatedLogic: true })

@@ -375,0 +438,0 @@ function findNextCell($cell, dir) {

@@ -54,2 +54,4 @@ # ProseMirror table module

@toggleHeader
@goToNextCell

@@ -56,0 +58,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