GitXplorerGitXplorer
o

prosemirror-splittable

public
7 stars
0 forks
0 issues

Commits

List of commits on branch master.
Verified
e3dcdfdd1bee01236ade5f53475ac9fe25f721ba

chore(master): release 0.1.1 (#3)

ggithub-actions[bot] committed 8 months ago
Verified
ff5dc5bd619725faf648e2e12697facbf72ed31e

refactor: use unreleased code from prosemirror-commands (#2)

oocavue committed 8 months ago
Verified
3ae275c3854055efa973cbb57dd857171ef5c021

chore(master): release 0.1.0 (#1)

ggithub-actions[bot] committed 8 months ago
Unverified
f1c02c25f00d2568ec00b8f4e962aa9813454a07

test: fix typecheck

oocavue committed 8 months ago
Unverified
aa385ee94b7a5f6a33d31722e81c5152d003365a

docs: use ESM import

oocavue committed 8 months ago
Unverified
c9a7fed2b32512b4b8afed012c33e2b5bb3b1a79

docs: add README

oocavue committed 8 months ago

README

The README file for this repository.

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