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.0.8 to 0.0.9

159

dist/index.js

@@ -5,4 +5,49 @@ 'use strict';

var prosemirrorState = require('prosemirror-state');
var prosemirrorTables = require('prosemirror-tables');
// :: (selection: Selection) → boolean
// Checks if current selection is a NodeSelection
var isNodeSelection = function isNodeSelection(selection) {
return selection instanceof prosemirrorState.NodeSelection;
};
// (nodeType: union<NodeType, [NodeType]>) → boolean
// Checks if the type a given `node` equals to a given `nodeType`.
var equalNodeType = function equalNodeType(nodeType, node) {
return Array.isArray(nodeType) && nodeType.indexOf(node.type) > -1 || node.type === nodeType;
};
// (tr: Transaction) → Transaction
// Creates a new transaction object from a given transaction
var cloneTr = function cloneTr(tr) {
return Object.assign(Object.create(tr), tr).setTime(Date.now());
};
// (position: number, node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a `delete` transaction that removes a node at a given position with the given `node`.
// It will return the original transaction if replacing is not possible.
var replaceNodeAtPos = function replaceNodeAtPos(position, node) {
return function (tr) {
var $pos = tr.doc.resolve(position);
var from = $pos.before($pos.depth);
var to = $pos.after($pos.depth);
if (tr.doc.canReplaceWith($pos.index($pos.depth), $pos.indexAfter($pos.depth), node.type)) {
return cloneTr(tr.replaceWith(from, to, node));
}
return tr;
};
};
// (position: number, node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a `delete` transaction that removes a node at a given position with the given `node`.
var removeNodeAtPos = function removeNodeAtPos(position, node) {
return function (tr) {
var $pos = tr.doc.resolve(position);
var from = $pos.before($pos.depth);
var to = $pos.after($pos.depth);
return cloneTr(tr.delete(from, to));
};
};
// :: (predicate: (node: ProseMirrorNode) → boolean) → (selection: Selection) → ?{pos: number, node: ProseMirrorNode}

@@ -45,3 +90,3 @@ // Iterates over parent nodes, returning the first node and its position `predicate` returns truthy for.

// :: (nodeType: NodeType) → (selection: Selection) → ?{node: ProseMirrorNode, pos: number}
// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{node: ProseMirrorNode, pos: number}
// Iterates over parent nodes, returning first node of the given `nodeType`.

@@ -51,3 +96,3 @@ var findParentNodeOfType = function findParentNodeOfType(nodeType) {

return findParentNode(function (node) {
return node.type === nodeType;
return equalNodeType(nodeType, node);
})(selection);

@@ -57,3 +102,3 @@ };

// :: (nodeType: NodeType) → (selection: Selection) → boolean
// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → boolean
// Checks if there's a parent node of the given `nodeType`.

@@ -63,3 +108,3 @@ var hasParentNodeOfType = function hasParentNodeOfType(nodeType) {

return hasParentNode(function (node) {
return node.type === nodeType;
return equalNodeType(nodeType, node);
})(selection);

@@ -69,3 +114,3 @@ };

// :: (nodeType: NodeType, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → (selection: Selection) → ?dom.Node
// :: (nodeType: union<NodeType, [NodeType]>, domAtPos: (pos: number) → {node: dom.Node, offset: number}) → (selection: Selection) → ?dom.Node
// Iterates over parent nodes, returning DOM reference of the first node of the given `nodeType`.

@@ -75,3 +120,3 @@ var findParentDomRefOfType = function findParentDomRefOfType(nodeType, domAtPos) {

return findParentDomRef(function (node) {
return node.type === nodeType;
return equalNodeType(nodeType, node);
}, domAtPos)(selection);

@@ -81,11 +126,12 @@ };

// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?ProseMirrorNode
// :: (nodeType: union<NodeType, [NodeType]>) → (selection: Selection) → ?{node: ProseMirrorNode, pos: number}
// Returns a node of a given `nodeType` if its selected.
var findSelectedNodeOfType = function findSelectedNodeOfType(nodeType) {
return function (selection) {
if (selection.node) {
var node = selection.node;
if (isNodeSelection(selection)) {
var node = selection.node,
$from = selection.$from;
if (Array.isArray(nodeType) && nodeType.indexOf(node.type) > -1 || node.type === nodeType) {
return node;
if (equalNodeType(nodeType, node)) {
return { node: node, pos: $from.pos };
}

@@ -305,36 +351,4 @@ }

// (tr: Transaction) → Transaction
// Creates a new transaction object from a given transaction
var cloneTr = function cloneTr(tr) {
return Object.assign(Object.create(tr), tr).setTime(Date.now());
};
// (position: number, node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a `delete` transaction that removes a node at a given position with the given `node`.
// It will return the original transaction if replacing is not possible.
var replaceNodeAtPos = function replaceNodeAtPos(position, node) {
return function (tr) {
var $pos = tr.doc.resolve(position);
var from = $pos.before($pos.depth);
var to = $pos.after($pos.depth);
if (tr.doc.canReplaceWith($pos.index($pos.depth), $pos.indexAfter($pos.depth), node.type)) {
return cloneTr(tr.replaceWith(from, to, node));
}
return tr;
};
};
// (position: number, node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a `delete` transaction that removes a node at a given position with the given `node`.
var removeNodeAtPos = function removeNodeAtPos(position, node) {
return function (tr) {
var $pos = tr.doc.resolve(position);
var from = $pos.before($pos.depth);
var to = $pos.after($pos.depth);
return cloneTr(tr.delete(from, to));
};
};
// :: (nodeType: NodeType) → (tr: Transaction) → Transaction
// Returns a `replace` transaction that replaces a node of a given `nodeType` with the given `node`.
// :: (nodeType: union<NodeType, [NodeType]>) → (tr: Transaction) → Transaction
// Returns a new transaction that removes a node of a given `nodeType`.
// It will return the original transaction if parent node hasn't been found.

@@ -351,4 +365,4 @@ var removeParentNodeOfType = function removeParentNodeOfType(nodeType) {

// :: (nodeType: NodeType, node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a `replace` transaction that replaces parent node of a given `nodeType` with the given `node`.
// :: (nodeType: union<NodeType, [NodeType]>, node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a new transaction that replaces parent node of a given `nodeType` with the given `node`.
// It will return the original transaction if parent node hasn't been found, or replacing is not possible.

@@ -366,7 +380,6 @@ var replaceParentNodeOfType = function replaceParentNodeOfType(nodeType, node) {

// :: (tr: Transaction) → Transaction
// Returns a `delete` transaction that removes selected node.
// Returns a new transaction that removes selected node.
// It will return the original transaction if current selection is not a NodeSelection
var removeSelectedNode = function removeSelectedNode(tr) {
// NodeSelection
if (tr.curSelection.node) {
if (isNodeSelection(tr.selection)) {
var from = tr.curSelection.$from.pos;

@@ -380,8 +393,7 @@ var to = tr.curSelection.$to.pos;

// :: (node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns a `replace` transaction that replaces selected node with a given `node`.
// Returns a new transaction that replaces selected node with a given `node`.
// It will return the original transaction if current selection is not a NodeSelection, or replacing is not possible.
var replaceSelectedNode = function replaceSelectedNode(node) {
return function (tr) {
// NodeSelection
if (tr.curSelection.node) {
if (isNodeSelection(tr.selection)) {
var _tr$curSelection = tr.curSelection,

@@ -400,3 +412,3 @@ $from = _tr$curSelection.$from,

// :: (node: ProseMirrorNode) → (tr: Transaction) → Transaction
// Returns an `insert` transaction that inserts a given `node` at the current cursor position if it is allowed by schema. If schema restricts such nesting, it will try to find the appropriate place for the given `node` in the document, looping through parent nodes up until the root document node.
// Returns a new transaction that inserts a given `node` at the current cursor position if it is allowed by schema. If schema restricts such nesting, it will try to find an appropriate place for a given `node` in the document, looping through parent nodes up until the root document node.
// It will return the original transaction if the place for insertion hasn't been found.

@@ -427,7 +439,29 @@ var safeInsert = function safeInsert(node) {

exports.removeParentNodeOfType = removeParentNodeOfType;
exports.replaceParentNodeOfType = replaceParentNodeOfType;
exports.removeSelectedNode = removeSelectedNode;
exports.safeInsert = safeInsert;
exports.replaceSelectedNode = replaceSelectedNode;
// :: (nodeType: union<NodeType, [NodeType]>, type: ?union<NodeType, null>, attrs: ?union<Object, null>, marks?: [Mark]) → (tr: Transaction) → Transaction
// Returns a transaction that changes the type, attributes, and/or marks of the parent node of a given `nodeType`.
var setParentNodeMarkup = function setParentNodeMarkup(nodeType, type, attrs, marks) {
return function (tr) {
var parent = findParentNodeOfType(nodeType)(tr.curSelection);
if (parent) {
return cloneTr(tr.setNodeMarkup(parent.pos - 1, type, Object.assign({}, parent.node.attrs, attrs), marks));
}
return tr;
};
};
// :: (nodeType: union<NodeType, [NodeType]>) → (tr: Transaction) → Transaction
// Returns a transaction that sets a NodeSelection on a parent node of a given `nodeType`.
var selectParentNodeOfType = function selectParentNodeOfType(nodeType) {
return function (tr) {
if (!isNodeSelection(tr.selection)) {
var parent = findParentNodeOfType(nodeType)(tr.curSelection);
if (parent) {
return cloneTr(tr.setSelection(prosemirrorState.NodeSelection.create(tr.doc, parent.pos - 1)));
}
}
return tr;
};
};
exports.isNodeSelection = isNodeSelection;
exports.findParentNode = findParentNode;

@@ -457,2 +491,9 @@ exports.findParentDomRef = findParentDomRef;

exports.getCellsInTable = getCellsInTable;
exports.removeParentNodeOfType = removeParentNodeOfType;
exports.replaceParentNodeOfType = replaceParentNodeOfType;
exports.removeSelectedNode = removeSelectedNode;
exports.replaceSelectedNode = replaceSelectedNode;
exports.safeInsert = safeInsert;
exports.setParentNodeMarkup = setParentNodeMarkup;
exports.selectParentNodeOfType = selectParentNodeOfType;
//# sourceMappingURL=index.js.map
{
"name": "prosemirror-utils",
"version": "0.0.8",
"version": "0.0.9",
"description": "Utils library for ProseMirror",

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

},
"keywords": ["ProseMirror", "utils", "helpers"],
"keywords": [
"ProseMirror",
"utils",
"helpers"
],
"jest": {

@@ -25,7 +29,9 @@ "transform": {

"typings": "typings.d.ts",
"files": ["dist", "typings.d.ts"],
"files": [
"dist",
"typings.d.ts"
],
"scripts": {
"build": "NODE_ENV=production rollup -c",
"build_readme":
"builddocs --name utils --format markdown --main src/README.md src/*.js > README.md",
"build_readme": "builddocs --name utils --format markdown --main src/README.md src/*.js > README.md",
"build_all": "npm run build && npm run build_readme",

@@ -36,3 +42,4 @@ "test": "NODE_ENV=testing jest",

},
"dependencies": {
"peerDependencies": {
"prosemirror-state": "^1.0.1",
"prosemirror-tables": "^0.6.3"

@@ -51,2 +58,4 @@ },

"prosemirror-schema-basic": "^1.0.0",
"prosemirror-state": "^1.0.1",
"prosemirror-tables": "^0.6.3",
"prosemirror-test-builder": "^1.0.1",

@@ -58,4 +67,7 @@ "prosemirror-view": "^1.1.1",

"lint-staged": {
"*.{js,json,css,md}": ["prettier --write", "git add"]
"*.{js, md}": [
"prettier --write",
"git add"
]
}
}

@@ -15,103 +15,145 @@ # Utils library for ProseMirror

* **`findParentNode`**`(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → ?{pos: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning the first node and its position `predicate` returns truthy for.
* **`findParentNode`**`(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → ?{pos: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning the first node and its position `predicate` returns truthy for.
- **`findParentDomRef`**`(predicate: fn(node: ProseMirrorNode) → boolean, domAtPos: fn(pos: number) → {node: dom.Node, offset: number}) → fn(selection: Selection) → ?dom.Node`\
Iterates over parent nodes, returning DOM reference of the first node `predicate` returns truthy for.
* **`hasParentNode`**`(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → boolean`\
Checks if there's a parent node `predicate` returns truthy for.
* **`findParentDomRef`**`(predicate: fn(node: ProseMirrorNode) → boolean, domAtPos: fn(pos: number) → {node: dom.Node, offset: number}) → fn(selection: Selection) → ?dom.Node`\
Iterates over parent nodes, returning DOM reference of the first node `predicate` returns truthy for.
- **`findParentNodeOfType`**`(nodeType: NodeType) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}`\
Iterates over parent nodes, returning first node of the given `nodeType`.
* **`hasParentNodeOfType`**`(nodeType: NodeType) → fn(selection: Selection) → boolean`\
Checks if there's a parent node of the given `nodeType`.
* **`hasParentNode`**`(predicate: fn(node: ProseMirrorNode) → boolean) → fn(selection: Selection) → boolean`\
Checks if there's a parent node `predicate` returns truthy for.
- **`findParentDomRefOfType`**`(nodeType: NodeType, domAtPos: fn(pos: number) → {node: dom.Node, offset: number}) → fn(selection: Selection) → ?dom.Node`\
Iterates over parent nodes, returning DOM reference of the first node of the given `nodeType`.
* **`findParentNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}`\
Iterates over parent nodes, returning first node of the given `nodeType`.
* **`hasParentNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → boolean`\
Checks if there's a parent node of the given `nodeType`.
* **`findParentDomRefOfType`**`(nodeType: NodeType | [NodeType], domAtPos: fn(pos: number) → {node: dom.Node, offset: number}) → fn(selection: Selection) → ?dom.Node`\
Iterates over parent nodes, returning DOM reference of the first node of the given `nodeType`.
* **`findSelectedNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?{node: ProseMirrorNode, pos: number}`\
Returns a node of a given `nodeType` if its selected.
* **`isNodeSelection`**`(selection: Selection) → boolean`\
Checks if current selection is a NodeSelection
### Node
* **`flatten`**`(node: ProseMirrorNode, descend: ?boolean = true) → [{node: ProseMirrorNode, pos: number}]`\
Flattens descendants of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`. Defaults to `true`.
* **`flatten`**`(node: ProseMirrorNode, descend: ?boolean = true) → [{node: ProseMirrorNode, pos: number}]`\
Flattens descendants of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`. Defaults to `true`.
- **`findChildren`**`(node: ProseMirrorNode, predicate: fn(node: ProseMirrorNode) → boolean, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes `predicate` returns truthy for. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findTextNodes`**`(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Returns text nodes of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findChildren`**`(node: ProseMirrorNode, predicate: fn(node: ProseMirrorNode) → boolean, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes `predicate` returns truthy for. Doesn't descend into a `node` when `descend` argument is `false`.
- **`findInlineNodes`**`(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Returns inline nodes of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findBlockNodes`**`(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Returns block descendants of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findTextNodes`**`(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Returns text nodes of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`.
- **`findChildrenByAttr`**`(node: ProseMirrorNode, predicate: fn(attrs: ?Object) → boolean, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes `predicate` returns truthy for. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findChildrenByType`**`(node: ProseMirrorNode, nodeType: NodeType, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes of a given `nodeType`. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findInlineNodes`**`(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Returns inline nodes of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`.
- **`findChildrenByMark`**`(node: ProseMirrorNode, markType: markType, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes that have a mark of a given `markType`. Doesn't descend into a `node` when `descend` argument is `false`.
exapmle: `findChildrenByMark(paragraph, schema.marks.strong)`
* **`contains`**`(node: ProseMirrorNode, nodeType: NodeType) → boolean`\
Returns `true` if a given `node` contains nodes of a given `nodeType`
* **`findBlockNodes`**`(node: ProseMirrorNode, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Returns block descendants of a given `node`. Doesn't descend into a `node` when `descend` argument is `false`.
- **`findSelectedNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(selection: Selection) → ?ProseMirrorNode`\
Returns a node of a given `nodeType` if its selected.
* **`findChildrenByAttr`**`(node: ProseMirrorNode, predicate: fn(attrs: ?Object) → boolean, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes `predicate` returns truthy for. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findChildrenByType`**`(node: ProseMirrorNode, nodeType: NodeType, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes of a given `nodeType`. Doesn't descend into a `node` when `descend` argument is `false`.
* **`findChildrenByMark`**`(node: ProseMirrorNode, markType: markType, descend: ?boolean) → [{node: ProseMirrorNode, pos: number}]`\
Iterates over descendants of a given `node`, returning child nodes that have a mark of a given `markType`. Doesn't descend into a `node` when `descend` argument is `false`.
exapmle: `findChildrenByMark(paragraph, schema.marks.strong)`
* **`contains`**`(node: ProseMirrorNode, nodeType: NodeType) → boolean`\
Returns `true` if a given `node` contains nodes of a given `nodeType`
### Tables
* **`findTable`**`(selection: Selection) → ?{pos: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning the first found table node.
* **`findTable`**`(selection: Selection) → ?{pos: number, node: ProseMirrorNode}`\
Iterates over parent nodes, returning the first found table node.
- **`isCellSelection`**`(selection: Selection) → boolean`\
Checks if current selection is a CellSelection
* **`isColumnSelected`**`(columnIndex: number) → fn(selection: Selection) → boolean`\
Checks if entire column at index `columnIndex` is selected
* **`isCellSelection`**`(selection: Selection) → boolean`\
Checks if current selection is a CellSelection
- **`isRowSelected`**`(rowIndex: number) → fn(selection: Selection) → boolean`\
Checks if entire row at index `rowIndex` is selected
* **`isTableSelected`**`(selection: Selection) → boolean`\
Checks if entire table is selected
* **`isColumnSelected`**`(columnIndex: number) → fn(selection: Selection) → boolean`\
Checks if entire column at index `columnIndex` is selected
- **`getCellsInColumn`**`(columnIndex: number) → fn(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]`\
Returns an array of cells in a column at index `columnIndex`.
* **`getCellsInRow`**`(rowIndex: number) → fn(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]`\
Returns an array of cells in a row at index `rowIndex`.
* **`isRowSelected`**`(rowIndex: number) → fn(selection: Selection) → boolean`\
Checks if entire row at index `rowIndex` is selected
- **`getCellsInTable`**`(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]`\
Returns an array of all cells in a table.
* **`isTableSelected`**`(selection: Selection) → boolean`\
Checks if entire table is selected
* **`getCellsInColumn`**`(columnIndex: number) → fn(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]`\
Returns an array of cells in a column at index `columnIndex`.
* **`getCellsInRow`**`(rowIndex: number) → fn(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]`\
Returns an array of cells in a row at index `rowIndex`.
* **`getCellsInTable`**`(selection: Selection) → ?[{pos: number, node: ProseMirrorNode}]`\
Returns an array of all cells in a table.
### Transforms
* **`removeParentNodeOfType`**`(nodeType: NodeType) → fn(tr: Transaction) → Transaction`\
Returns a `replace` transaction that replaces a node of a given `nodeType` with the given `node`.
It will return the original transaction if parent node hasn't been found.
* **`removeParentNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(tr: Transaction) → Transaction`\
Returns a new transaction that removes a node of a given `nodeType`.
It will return the original transaction if parent node hasn't been found.
- **`replaceParentNodeOfType`**`(nodeType: NodeType, node: ProseMirrorNode) → fn(tr: Transaction) → Transaction`\
Returns a `replace` transaction that replaces parent node of a given `nodeType` with the given `node`.
It will return the original transaction if parent node hasn't been found, or replacing is not possible.
* **`removeSelectedNode`**`(tr: Transaction) → Transaction`\
Returns a `delete` transaction that removes selected node.
It will return the original transaction if current selection is not a NodeSelection
* **`replaceParentNodeOfType`**`(nodeType: NodeType | [NodeType], node: ProseMirrorNode) → fn(tr: Transaction) → Transaction`\
Returns a new transaction that replaces parent node of a given `nodeType` with the given `node`.
It will return the original transaction if parent node hasn't been found, or replacing is not possible.
- **`replaceSelectedNode`**`(node: ProseMirrorNode) → fn(tr: Transaction) → Transaction`\
Returns a `replace` transaction that replaces selected node with a given `node`.
It will return the original transaction if current selection is not a NodeSelection, or replacing is not possible.
* **`safeInsert`**`(node: ProseMirrorNode) → fn(tr: Transaction) → Transaction`\
Returns an `insert` transaction that inserts a given `node` at the current cursor position if it is allowed by schema. If schema restricts such nesting, it will try to find the appropriate place for the given `node` in the document, looping through parent nodes up until the root document node.
It will return the original transaction if the place for insertion hasn't been found.
* **`removeSelectedNode`**`(tr: Transaction) → Transaction`\
Returns a new transaction that removes selected node.
It will return the original transaction if current selection is not a NodeSelection
* **`replaceSelectedNode`**`(node: ProseMirrorNode) → fn(tr: Transaction) → Transaction`\
Returns a new transaction that replaces selected node with a given `node`.
It will return the original transaction if current selection is not a NodeSelection, or replacing is not possible.
* **`safeInsert`**`(node: ProseMirrorNode) → fn(tr: Transaction) → Transaction`\
Returns a new transaction that inserts a given `node` at the current cursor position if it is allowed by schema. If schema restricts such nesting, it will try to find an appropriate place for a given `node` in the document, looping through parent nodes up until the root document node.
It will return the original transaction if the place for insertion hasn't been found.
* **`setParentNodeMarkup`**`(nodeType: NodeType | [NodeType], type: ?NodeType | null, attrs: ?Object | null, marks: ?[Mark]) → fn(tr: Transaction) → Transaction`\
Returns a transaction that changes the type, attributes, and/or marks of the parent node of a given `nodeType`.
* **`selectParentNodeOfType`**`(nodeType: NodeType | [NodeType]) → fn(tr: Transaction) → Transaction`\
Returns a transaction that sets a NodeSelection on a parent node of a given `nodeType`.
## License
* **MIT** : http://opensource.org/licenses/MIT

@@ -1,2 +0,2 @@

import { Node as ProsemirrorNode, NodeType, MarkType } from 'prosemirror-model';
import { Node as ProsemirrorNode, NodeType, Mark, MarkType } from 'prosemirror-model';
import { Selection, Transaction } from 'prosemirror-state';

@@ -15,10 +15,12 @@

export function findParentNodeOfType(nodeType: NodeType): (selection: Selection) => {pos: number, node: ProsemirrorNode} | undefined;
export function findParentNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => {pos: number, node: ProsemirrorNode} | undefined;
export function hasParentNodeOfType(nodeType: NodeType): (selection: Selection) => boolean;
export function hasParentNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => boolean;
export function findParentDomRefOfType(nodeType: NodeType, domAtPos: DomAtPos): (selection: Selection) => Node | undefined;
export function findParentDomRefOfType(nodeType: NodeType | NodeType[], domAtPos: DomAtPos): (selection: Selection) => Node | undefined;
export function findSelectedNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => ProsemirrorNode | undefined;
export function findSelectedNodeOfType(nodeType: NodeType | NodeType[]): (selection: Selection) => {pos: number, node: ProsemirrorNode} | undefined;
export function isNodeSelection(selection: Selection): boolean;
// Node

@@ -61,5 +63,5 @@ export function flatten(node: ProsemirrorNode, descend?: boolean): {pos: number, node: ProsemirrorNode}[];

// Transforms
export function removeParentNodeOfType(nodeType: NodeType): (tr: Transaction) => Transaction;
export function removeParentNodeOfType(nodeType: NodeType | NodeType[]): (tr: Transaction) => Transaction;
export function replaceParentNodeOfType(nodeType: NodeType, node: ProsemirrorNode): (tr: Transaction) => Transaction;
export function replaceParentNodeOfType(nodeType: NodeType | NodeType[], node: ProsemirrorNode): (tr: Transaction) => Transaction;

@@ -71,1 +73,5 @@ export function removeSelectedNode(tr: Transaction): Transaction;

export function safeInsert(node: ProsemirrorNode): (tr: Transaction) => Transaction;
export function setParentNodeMarkup(nodeType: NodeType | NodeType[], type?: NodeType | null, attrs?: { [key: string]: any } | null, marks?: Mark[]): (tr: Transaction) => Transaction;
export function selectParentNodeOfType(nodeType: NodeType | NodeType[]): (tr: Transaction) => Transaction;

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