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

prosemirror-completion

v0.1.1

Published

Copilot-style text completion plugin for ProseMirror

Readme

ProseMirror Completion

Copilot-style text completion plugin for ProseMirror.

Features

  • 🎯 Invisible Trigger: Automatically triggers completion as you type based on cursor context
  • 👻 Ghost Text: Visual suggestion overlay that doesn't interfere with editing
  • ⌨️ Intuitive Keybindings: Tab to accept, Esc to cancel
  • 🔌 Customizable: Debounce timing, abort controller, custom prompt builders
  • 🎨 Rich Results: Support plain text, HTML, Markdown, or ProseMirror nodes
  • Framework Agnostic: Works with any JavaScript framework or vanilla JS

Installation

npm install prosemirror-completion

Quick Start

import { EditorState } from "prosemirror-state";
import { EditorView } from "prosemirror-view";
import { keymap } from "prosemirror-keymap";
import { schema } from "prosemirror-schema-basic";
import { exampleSetup } from "prosemirror-example-setup";
import {
  completion,
  approveCompletion,
  exitCompletion,
} from "prosemirror-completion";

const completionPlugin = completion({
  debounceMs: 300,
  minTriggerLength: 2,
  getPromptType: (ctx) =>
    ctx.parent.type.name === "code_block" ? "code" : "common",
  callCompletion: async ({ beforeText }) => {
    const lastWord = beforeText.split(/\s+/).pop() ?? "";
    return lastWord ? `${lastWord}…` : "";
  },
  debug: import.meta.env.DEV,
});

const completionKeymap = keymap({
  Tab: approveCompletion,
  Escape: exitCompletion,
});

const state = EditorState.create({
  schema,
  plugins: [completionPlugin, completionKeymap, ...exampleSetup({ schema })],
});

const view = new EditorView(document.querySelector("#editor")!, {
  state,
});

Completion result shapes

callCompletion can return a simple string, or an object containing HTML or ProseMirror Node:

type CompletionResult =
  | string
  | { plain: string; html?: string }
  | { html: string }
  | { prosemirror: Node };

Configuration

completion accepts the following configuration options:

| Option | Type | Default | Description | | --- | --- | --- | --- | | debounceMs | number | 300 | Debounce time before triggering completion, in milliseconds | | minTriggerLength | number | 3 | Minimum characters before cursor to trigger completion request | | callCompletion | (context) => CompletionResult \| Promise<CompletionResult> | Required | The actual completion function, returns string, HTML or ProseMirror Node | | getPromptType | (context) => PromptType | defaultGetPromptType | Custom prompt type inference logic (e.g., code/Markdown detection) | | onChange | (context, view) => void | undefined | Triggered when user types continuously, can be used for analytics or real-time status display | | ghostClassName | string | "prosemirror-ghost-text" | Custom CSS class for Ghost Text | | showGhost | boolean | true | Whether to show Ghost Text (can be disabled to keep only keyboard behavior) | | debug | boolean | false | Whether to output debug logs for troubleshooting trigger and request processes |

CompletionResult supports string, { plain; html? }, { html }, { prosemirror: Node }, see docs for examples.

If you need to execute logic when the user accepts/cancels completion at the callback level, you can listen to and extend the exported approveCompletion/exitCompletion commands.

Project Structure

packages/
├── plugin/
│   ├── src/
│   │   ├── decorations.ts # Ghost text rendering
│   │   ├── index.ts       # Entry exports
│   │   ├── keymap.ts      # Keyboard handlers
│   │   ├── plugin.ts      # Core plugin implementation
│   │   ├── prompts.ts     # Prompt builders
│   │   ├── types.ts       # Shared types & contexts
│   │   └── utils.ts       # Helpers (commands, prompt detection, text extraction…)
│   ├── scripts/postbuild.mjs
│   └── package.json
├── eslint-config/         # Shared eslint preset
└── typescript-config/     # Shared tsconfig presets

apps/
├── demo/                  # Playground + Vitest suite
│   ├── src/main.ts
│   └── src/completion.test.ts
└── docs/                  # VitePress documentation site (en & zh)
    └── docs/
        ├── guide/
        ├── api/
        └── examples/

Development

# Install dependencies (pnpm workspace)
pnpm install

# Run the playground demo
pnpm --filter demo dev

# Run Vitest suite for the demo (covers plugin behaviors)
pnpm --filter demo test

# Build documentation site
pnpm --filter docs build

# Build the plugin package
pnpm --filter @prosemirror-completion/plugin build

Architecture

The plugin is built with a three-layer architecture:

  1. Matcher (State Tracker): Tracks cursor position and triggers completion using Transaction meta
  2. Ghost Decoration: Virtual rendering layer using ProseMirror DecorationSet
  3. Key Handler: Intercepts Tab and Esc for completion actions

License

MIT