New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-utils

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-utils - npm Package Compare versions

Comparing version 0.4.4 to 0.5.0

CHANGELOG.md

97

dist/index.js

@@ -180,3 +180,3 @@ 'use strict';

if (parent) {
return cloneTr(tr.setNodeMarkup(parent.pos - 1, type, Object.assign({}, parent.node.attrs, attrs), marks));
return cloneTr(tr.setNodeMarkup(parent.pos, type, Object.assign({}, parent.node.attrs, attrs), marks));
}

@@ -200,3 +200,3 @@ return tr;

if (parent) {
return cloneTr(tr.setSelection(prosemirrorState.NodeSelection.create(tr.doc, parent.pos - 1)));
return cloneTr(tr.setSelection(prosemirrorState.NodeSelection.create(tr.doc, parent.pos)));
}

@@ -251,12 +251,11 @@ }

// It will return the original transaction if replacing is not possible.
// `position` should point at the start of a node in the document.
// `position` should point at the position immediately before the node.
var replaceNodeAtPos = function replaceNodeAtPos(position, content) {
return function (tr) {
var before = position - 1;
var node = tr.doc.nodeAt(before);
var $pos = tr.doc.resolve(before);
var node = tr.doc.nodeAt(position);
var $pos = tr.doc.resolve(position);
if (canReplace($pos, content)) {
tr = tr.replaceWith(before, before + node.nodeSize, content);
var start = tr.selection.$from.pos - 1;
return cloneTr(setTextSelection(Math.max(start, 0), -1)(tr));
tr = tr.replaceWith(position, position + node.nodeSize, content);
var cursor = tr.mapping.map(tr.selection.from, -1);
return cloneTr(setTextSelection(cursor)(tr));
}

@@ -278,8 +277,7 @@ return tr;

// Returns a `delete` transaction that removes a node at a given position with the given `node`.
// `position` should point at the start of a node in the document.
// `position` should point at the position immediately before the node.
var removeNodeAtPos = function removeNodeAtPos(position) {
return function (tr) {
var before = position - 1;
var node = tr.doc.nodeAt(before);
return cloneTr(tr.delete(before, before + node.nodeSize));
var node = tr.doc.nodeAt(position);
return cloneTr(tr.delete(position, position + node.nodeSize));
};

@@ -332,3 +330,3 @@ };

// ($pos: ResolvedPos) → ?{pos: number, node: ProseMirrorNode}
// ($pos: ResolvedPos) → ?{pos: number, start: number, node: ProseMirrorNode}
// Iterates over parent nodes, returning a table node closest to a given `$pos`.

@@ -346,3 +344,3 @@ //

// :: ($pos: ResolvedPos) → ?{pos: number, node: ProseMirrorNode}
// :: ($pos: ResolvedPos) → ?{pos: number, start: number, node: ProseMirrorNode}
// Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.

@@ -373,3 +371,3 @@ //

var map = prosemirrorTables.TableMap.get(table.node);
var cellPos = cell.pos - table.pos - 1;
var cellPos = cell.pos - table.start;
return map.rectBetween(cellPos, cellPos);

@@ -379,4 +377,4 @@ }

// :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → ?{pos: number, node: ProseMirrorNode}
// Iterates over parent nodes, returning the closest node and its start position `predicate` returns truthy for.
// :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}
// Iterates over parent nodes, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node.
//

@@ -395,3 +393,4 @@ // ```javascript

return {
pos: $from.start(i),
pos: i > 0 ? $from.before(i) : 0,
start: $from.start(i),
node: node

@@ -404,4 +403,4 @@ };

// :: ($pos: ResolvedPos, predicate: (node: ProseMirrorNode) → boolean) → ?{pos: number, node: ProseMirrorNode}
// Iterates over parent nodes starting from the given `$pos`, returning the closest node and its start position `predicate` returns truthy for.
// :: ($pos: ResolvedPos, predicate: (node: ProseMirrorNode) → boolean) → ?{pos: number, start: number, node: ProseMirrorNode}
// Iterates over parent nodes starting from the given `$pos`, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node.
//

@@ -417,3 +416,4 @@ // ```javascript

return {
pos: $pos.start(i),
pos: i > 0 ? $pos.before(i) : 0,
start: $pos.start(i),
node: node

@@ -437,3 +437,3 @@ };

if (parent) {
return findDomRefAtPos(parent.pos - 1, domAtPos);
return findDomRefAtPos(parent.pos, domAtPos);
}

@@ -457,4 +457,4 @@ };

// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{node: ProseMirrorNode, pos: number}
// Iterates over parent nodes, returning closest node of a given `nodeType`.
// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}
// Iterates over parent nodes, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node.
//

@@ -472,4 +472,4 @@ // ```javascript

// :: ($pos: ResolvedPos, nodeType: union<NodeType, [NodeType]>) → ?{node: ProseMirrorNode, pos: number}
// Iterates over parent nodes starting from the given `$pos`, returning closest node of a given `nodeType`.
// :: ($pos: ResolvedPos, nodeType: union<NodeType, [NodeType]>) → ?{pos: number, start: number, node: ProseMirrorNode}
// Iterates over parent nodes starting from the given `$pos`, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node.
//

@@ -516,4 +516,4 @@ // ```javascript

// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{node: ProseMirrorNode, pos: number}
// Returns a node of a given `nodeType` if it is selected.
// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}
// Returns a node of a given `nodeType` if it is selected. `start` points to the start position of the node, `pos` points directly before the node.
//

@@ -557,3 +557,3 @@ // ```javascript

}
return maybeSelection.$from.pos + 1;
return maybeSelection.$from.pos;
}

@@ -564,3 +564,2 @@ };

// Returns DOM reference of a node at a given `position`.
// @see https://github.com/atlassian/prosemirror-utils/issues/8 for more context.
//

@@ -873,4 +872,4 @@ // ```javascript

if (cells) {
var $anchor = tr.doc.resolve(cells[0].pos - 1);
var $head = tr.doc.resolve(cells[cells.length - 1].pos - 1);
var $anchor = tr.doc.resolve(cells[0].pos);
var $head = tr.doc.resolve(cells[cells.length - 1].pos);
return cloneTr(tr.setSelection(new prosemirrorTables.CellSelection($anchor, $head)));

@@ -894,4 +893,4 @@ }

if (cells) {
var $anchor = tr.doc.resolve(cells[0].pos - 1);
var $head = tr.doc.resolve(cells[cells.length - 1].pos - 1);
var $anchor = tr.doc.resolve(cells[0].pos);
var $head = tr.doc.resolve(cells[cells.length - 1].pos);
return cloneTr(tr.setSelection(new prosemirrorTables.CellSelection($anchor, $head)));

@@ -914,4 +913,4 @@ }

if (cells) {
var $anchor = tr.doc.resolve(cells[0].pos - 1);
var $head = tr.doc.resolve(cells[cells.length - 1].pos - 1);
var $anchor = tr.doc.resolve(cells[0].pos);
var $head = tr.doc.resolve(cells[cells.length - 1].pos);
return cloneTr(tr.setSelection(new prosemirrorTables.CellSelection($anchor, $head)));

@@ -936,3 +935,3 @@ }

if (!cell.node.content.eq(content)) {
tr.replaceWith(cell.pos - 1, cell.pos + cell.node.nodeSize - 2, new prosemirrorModel.Slice(content, 0, 0));
tr.replaceWith(cell.pos, cell.pos + cell.node.nodeSize - 1, new prosemirrorModel.Slice(content, 0, 0));
return cloneTr(tr);

@@ -961,3 +960,3 @@ }

map: map,
tableStart: table.pos,
tableStart: table.start,
table: table.node

@@ -987,3 +986,3 @@ }, columnIndex));

map: map,
tableStart: table.pos,
tableStart: table.start,
table: table.node

@@ -1015,3 +1014,3 @@ }, rowIndex));

map: map,
tableStart: table.pos,
tableStart: table.start,
table: table.node

@@ -1044,3 +1043,3 @@ }, columnIndex);

map: map,
tableStart: table.pos,
tableStart: table.start,
table: table.node

@@ -1094,3 +1093,3 @@ }, rowIndex);

var map = prosemirrorTables.TableMap.get(table.node);
var rect = map.rectBetween(selection.$anchorCell.pos - table.pos, selection.$headCell.pos - table.pos);
var rect = map.rectBetween(selection.$anchorCell.pos - table.start, selection.$headCell.pos - table.start);
for (var i = rect.right - 1; i >= rect.left; i--) {

@@ -1124,3 +1123,3 @@ tr = removeColumnAt(i)(tr);

var map = prosemirrorTables.TableMap.get(table.node);
var rect = map.rectBetween(selection.$anchorCell.pos - table.pos, selection.$headCell.pos - table.pos);
var rect = map.rectBetween(selection.$anchorCell.pos - table.start, selection.$headCell.pos - table.start);
for (var i = rect.bottom - 1; i >= rect.top; i--) {

@@ -1147,3 +1146,3 @@ tr = removeRowAt(i)(tr);

if (rect) {
return removeColumnAt(rect.left)(tr);
return removeColumnAt(rect.left)(setTextSelection($pos.pos)(tr));
}

@@ -1166,3 +1165,3 @@ return tr;

if (rect) {
return removeRowAt(rect.top)(tr);
return removeRowAt(rect.top)(setTextSelection($pos.pos)(tr));
}

@@ -1190,3 +1189,3 @@ return tr;

if (setCursorToLastCell) {
var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos - 1));
var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos));
tr.setSelection(prosemirrorState.Selection.near($pos));

@@ -1217,3 +1216,3 @@ }

if (setCursorToLastCell) {
var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos - 1));
var $pos = tr.doc.resolve(tr.mapping.map(cells[cells.length - 1].pos));
tr.setSelection(prosemirrorState.Selection.near($pos));

@@ -1237,3 +1236,3 @@ }

if (cell) {
tr.setNodeMarkup(cell.pos - 1, null, Object.assign({}, cell.node.attrs, attrs));
tr.setNodeMarkup(cell.pos, null, Object.assign({}, cell.node.attrs, attrs));
return cloneTr(tr);

@@ -1240,0 +1239,0 @@ }

{
"name": "prosemirror-utils",
"version": "0.4.4",
"version": "0.5.0",
"description": "Utils library for ProseMirror",

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

@@ -23,4 +23,4 @@ # Utils library for ProseMirror

* **`findParentNode`**`(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → ?{pos: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning the closest node and its start position `predicate` returns truthy for.
* **`findParentNode`**`(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node.

@@ -33,4 +33,4 @@ ```javascript

* **`findParentNodeClosestToPos`**`($pos: ResolvedPos, predicate: fn(node: ProseMirrorNode) → boolean) → ?{pos: number, node: ProseMirrorNode}`\
Iterates over parent nodes starting from the given `$pos`, returning the closest node and its start position `predicate` returns truthy for.
* **`findParentNodeClosestToPos`**`($pos: ResolvedPos, predicate: fn(node: ProseMirrorNode) → boolean) → ?{pos: number, start: number, node: ProseMirrorNode}`\
Iterates over parent nodes starting from the given `$pos`, returning the closest node and its start position `predicate` returns truthy for. `start` points to the start position of the node, `pos` points directly before the node.

@@ -63,4 +63,4 @@ ```javascript

* **`findParentNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}`\
Iterates over parent nodes, returning closest node of a given `nodeType`.
* **`findParentNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node.

@@ -72,4 +72,4 @@ ```javascript

* **`findParentNodeOfTypeClosestToPos`**`($pos: ResolvedPos, nodeType: NodeType | [NodeType]) → ?{node: ProseMirrorNode, pos: number}`\
Iterates over parent nodes starting from the given `$pos`, returning closest node of a given `nodeType`.
* **`findParentNodeOfTypeClosestToPos`**`($pos: ResolvedPos, nodeType: NodeType | [NodeType]) → ?{pos: number, start: number, node: ProseMirrorNode}`\
Iterates over parent nodes starting from the given `$pos`, returning closest node of a given `nodeType`. `start` points to the start position of the node, `pos` points directly before the node.

@@ -100,4 +100,4 @@ ```javascript

* **`findSelectedNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}`\
Returns a node of a given `nodeType` if it is selected.
* **`findSelectedNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{pos: number, start: number, node: ProseMirrorNode}`\
Returns a node of a given `nodeType` if it is selected. `start` points to the start position of the node, `pos` points directly before the node.

@@ -134,3 +134,2 @@ ```javascript

Returns DOM reference of a node at a given `position`.
@see https://github.com/atlassian/prosemirror-utils/issues/8 for more context.

@@ -418,3 +417,3 @@ ```javascript

* **`findCellClosestToPos`**`($pos: ResolvedPos) → ?{pos: number, node: ProseMirrorNode}`\
* **`findCellClosestToPos`**`($pos: ResolvedPos) → ?{pos: number, start: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning a table cell or a table header node closest to a given `$pos`.

@@ -421,0 +420,0 @@

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