Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prosemirror-splittable

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-splittable

Inherit ProseMirror node attributes when splitting nodes.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5K
increased by20.84%
Maintainers
1
Weekly downloads
 
Created
Source

prosemirror-splittable

NPM version

Extends ProseMirror's AttributeSpec to allow for splittable property. splittable is a boolean that, when true, enables the inheritance of the attribute when splitting a node using the splitSplittableBlock command.

Example

In the schema defined below, the textAlign attribute is defined as splittable for both paragraph and heading nodes.

import { Schema } from 'prosemirror-model'

const schema = new Schema({
  nodes: {
    text: {},
    paragraph: {
      content: 'text*',
      group: 'block',
      attrs: {
        textAlign: { default: 'left', splittable: true },
      },
      toDOM(node) {
        return ['p', { style: `text-align: ${node.attrs.textAlign};` }, 0]
      },
    },
    heading: {
      content: 'text*',
      group: 'block',
      attrs: {
        textAlign: { default: 'left', splittable: true },
      },
      toDOM(node) {
        return ['h1', { style: `text-align: ${node.attrs.textAlign};` }, 0]
      },
    },
    doc: { content: 'block*' },
  },
})

Later, we can use the keymap plugin to bind the Enter key to the splitSplittableBlock command.

import { splitSplittableBlock } from 'prosemirror-splittable'
import { keymap } from 'prosemirror-keymap'
import {
  baseKeymap,
  chainCommands,
  createParagraphNear,
  liftEmptyBlock,
  newlineInCode,
} from 'prosemirror-commands'

const customBaseKeymap = {
  ...baseKeymap,
  Enter: chainCommands(
    newlineInCode,
    createParagraphNear,
    liftEmptyBlock,
    splitSplittableBlock,
  ),
}

const plugin = keymap(customBaseKeymap)

License

MIT

FAQs

Package last updated on 29 May 2024

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