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

Utils library for ProseMirror

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77K
decreased by-26.26%
Maintainers
1
Weekly downloads
 
Created
Source

Utils library for ProseMirror

Quick Start

Install prosemirror-utils package from npm:

npm install prosemirror-utils

Documentation

Getting the parent node based on the current cursor position:

  • 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: HTMLElement, offset: number}) → fn(selection: Selection) → ?HTMLElement
    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.
  • 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.
  • findParentDomRefOfType(nodeType: NodeType, domAtPos: fn(pos: number) → {node: HTMLElement, offset: number}) → fn(selection: Selection) → ?HTMLElement
    Iterates over parent nodes, returning DOM reference of the first node of the given nodeType.

Getting descendants of a given 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.
  • 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.
  • 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.
  • 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 helpers:

  • 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
  • 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
  • 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.
  • 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.
  • removeSelectedNode(tr: Transaction) → ?Transaction
    Returns a delete transaction that removes selected node.
  • safeInsert(content: Fragment | Node | [Node]) → fn(tr: Transaction) → ?Transaction
    Returns an insert transaction that inserts a given content at the current cursor position if its allowed. Otherwise it will try to find the appropriate place for such content in the document, looping through parent nodes up until the root document node.

License

  • MIT : http://opensource.org/licenses/MIT

Keywords

FAQs

Package last updated on 14 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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