npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@type-editor/adapter-svelte

v0.0.3

Published

Type editor Svelte adapter

Downloads

163

Readme

@type-editor/adapter-svelte

Svelte adapter for integrating custom Svelte components as ProseMirror node views, mark views, plugin views, and widget decorations.

Overview

@type-editor/adapter-svelte bridges ProseMirror's view layer and Svelte's rendering pipeline. Each ProseMirror node, mark, plugin view, or widget decoration can be backed by an ordinary Svelte component. Reactive state is passed to components via Svelte's context API using writable stores; rendering happens via direct Svelte mounting.

Installation

npm install @type-editor/adapter-svelte
# or
pnpm add @type-editor/adapter-svelte

Peer dependencies: svelte ^4.0.0 || ^5.0.0

Setup

Call useProsemirrorAdapterProvider inside the <script> block of the root Svelte component that contains your editor. This wires up the rendering infrastructure and makes the factory functions available to all descendants via Svelte's getContext.

<!-- App.svelte -->
<script lang="ts">
    import { useProsemirrorAdapterProvider } from '@type-editor/adapter-svelte';
    import Editor from './Editor.svelte';

    useProsemirrorAdapterProvider();
</script>

<main>
    <Editor />
</main>

Usage

As this is a fork of @prosemirror-adapter/svelte, you'll find more documentation and examples in the original repository: https://github.com/prosekit/prosemirror-adapter/tree/main/packages/svelte

Node views

1. Create a Svelte component

Access editor state through useNodeViewContext. Reactive properties are exposed as Svelte writable stores so the template reacts to changes automatically:

<!-- Paragraph.svelte -->
<script lang="ts">
    import { useNodeViewContext } from '@type-editor/adapter-svelte';
    import { onMount } from 'svelte';

    const dom = useNodeViewContext('dom');
    const nodeStore = useNodeViewContext('node');

    function applyStyles(node: typeof $nodeStore) {
        if (!dom) return;
        if (node.attrs.align) {
            dom.style.textAlign = node.attrs.align as string;
        }
    }

    onMount(() => applyStyles($nodeStore));
    $: applyStyles($nodeStore);
</script>

<!-- No template output when contentAs: 'self' – ProseMirror manages the content. -->

When you need a content-editable region inside your component, use contentRef:

<script lang="ts">
    import { useNodeViewContext } from '@type-editor/adapter-svelte';
    const contentRef = useNodeViewContext('contentRef');
</script>

<div use:contentRef />

2. Create a node view factory

Use useNodeViewFactory inside a component that is a descendant of useProsemirrorAdapterProvider:

<!-- Editor.svelte -->
<script lang="ts">
    import { useNodeViewFactory } from '@type-editor/adapter-svelte';
    import { PmNode } from '@type-editor/model';
    import Paragraph from './Paragraph.svelte';

    const nodeViewFactory = useNodeViewFactory();

    const paragraphView = nodeViewFactory({
        component: Paragraph,
        as: (node: PmNode): HTMLElement => {
            const p = document.createElement('p');
            if (node.attrs.align) p.style.textAlign = node.attrs.align;
            return p;
        },
        contentAs: 'self',
    });

    // Pass to ProseMirror's EditorView
    const editorView = new EditorView(container, {
        state,
        nodeViews: { paragraph: paragraphView },
    });
</script>

Mark views

<!-- BoldMark.svelte -->
<script lang="ts">
    import { useMarkViewContext } from '@type-editor/adapter-svelte';
    const contentRef = useMarkViewContext('contentRef');
</script>
<strong use:contentRef />
// In your editor component:
const markViewFactory = useMarkViewFactory();
const boldView = markViewFactory({ component: BoldMark });

Plugin views

<!-- Toolbar.svelte -->
<script lang="ts">
    import { usePluginViewContext } from '@type-editor/adapter-svelte';
    const view = usePluginViewContext('view');
</script>
<div class="toolbar">…</div>
// In your editor component:
const pluginViewFactory = usePluginViewFactory();
const toolbarPlugin = new Plugin({
    view: pluginViewFactory({ component: Toolbar }),
});

Widget views

// In your editor component:
const widgetViewFactory = useWidgetViewFactory();
const decoration = widgetViewFactory(pos, { component: MyWidget });

API reference

useProsemirrorAdapterProvider()

Setup function. Must be called in the <script> block of an ancestor component before any factory functions are used.

Factory functions

| Function | Returns | Description | |--------------------------|---------------------|--------------------------------------------------------------------------| | useNodeViewFactory() | NodeViewFactory | Creates a ProseMirror NodeViewConstructor backed by a Svelte component | | useMarkViewFactory() | MarkViewFactory | Creates a ProseMirror MarkViewConstructor backed by a Svelte component | | usePluginViewFactory() | PluginViewFactory | Creates a ProseMirror PluginView factory backed by a Svelte component | | useWidgetViewFactory() | WidgetViewFactory | Creates a widget decoration factory backed by a Svelte component |

Context functions

| Function | Returns | Description | |-----------------------------|--------------------------|------------------------------------------------------| | useNodeViewContext(key) | NodeViewContext[key] | Reads a single property from the node view context | | useMarkViewContext(key) | MarkViewContext[key] | Reads a single property from the mark view context | | usePluginViewContext(key) | PluginViewContext[key] | Reads a single property from the plugin view context | | useWidgetViewContext(key) | WidgetViewContext[key] | Reads a single property from the widget view context |

All context functions accept a single string key naming the property to retrieve. This matches Svelte's context model where each key is set individually.

NodeViewContext

| Property | Type | Description | |--------------------|------------------------------------------|--------------------------------------------------------------------------| | contentRef | (element: HTMLElement \| null) => void | Callback to attach the content-editable container | | dom | HTMLElement | The outer DOM element of this node view | | view | PmEditorView | The ProseMirror editor view | | getPos | () => number \| undefined | Returns the node's current document position | | setAttrs | (attrs: Attrs) => void | Dispatches a transaction updating the node's attributes | | node | Writable<Node> | Writable store containing the current ProseMirror document node | | selected | Writable<boolean> | Writable store indicating whether this node is selected | | decorations | Writable<ReadonlyArray<PmDecoration>> | Writable store containing the decorations applied to this node | | innerDecorations | Writable<DecorationSource> | Writable store containing the decorations applied to this node's content |

License

MIT