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

1.0.2 • Public • Published

prosemirror-svelte-nodeview

Create a ProseMirror NodeView using Svelte.

Basic usage

A basic heading NodeView (SimpleHeadingView)

<script lang="ts">
  export var attrs: { level: number };
  export let contentDOM:  (node: HTMLElement) => void;

  $: tag = `h${attrs.level}`;

</script>

<svelte:element this={tag} use:contentDOM />

Loading the component using the plugin

EditorState.create({
  doc,
  plugins: [
    sveltePlugin({
      nodes: {
        heading: SimpleHeadingView,
      }
    })
  ]
})

Component props

These props are passed to the components loaded into this plugin.

type ComponentProps = {
  attrs?: Record<string, unknown>;
  controls?: SvelteNodeViewControls,
  contentDOM?: (node: HTMLElement) => void,
  rootDOM?: (node: HTMLElement) => void,
}

export interface SvelteNodeViewControls {
  delete: () => void;
  update: (cb: (editorState: EditorState, node?: Node, getPos?: () => number) => Transaction) => void;
}

Examples

Check out the basic example project for a more complete example component showing the use of a nested editor to edit attributes.

Package Sidebar

Install

npm i prosemirror-svelte-nodeview

Weekly Downloads

14

Version

1.0.2

License

MIT

Unpacked Size

15.1 kB

Total Files

5

Last publish

Collaborators

  • mattosborn