Create a ProseMirror NodeView using Svelte.
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,
}
})
]
})
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;
}
Check out the basic example project for a more complete example component showing the use of a nested editor to edit attributes.