prosemirror-splittable
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i prosemirror-splittable

Weekly Downloads

1,574

Version

0.1.1

License

MIT

Unpacked Size

15 kB

Total Files

7

Last publish

Collaborators

  • ocavue