@guardian/prosemirror-invisibles

中文文档
3.1.3发布于 2026/04/07MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4938

A plugin to show invisibles in prosemirror

原始使用文档
文档目录4 节
  1. Install
  2. Usage
  3. A note on line-break invisibles and selections
  4. Running locally

prosemirror-invisibles

A simple implementation of invisible characters in ProseMirror.

Demo here.


Install

npm install @guardian/prosemirror-invisibles

Usage

Add the plugin to the state and pass the invisibles you would like to display in the document.

import invisibles, { space, hardBreak, paragraph } from 'prosemirror-invisibles';

new EditorView(document.querySelector("#editor"), {
  state: EditorState.create({
    doc: DOMParser.fromSchema(mySchema).parse(
      document.querySelector("#content")
    ),
    plugins: [
      invisibles([space(), hardBreak(), paragraph()])
    ]
  })
});

And import the css from prosemirror-invisibles/dist/invisibles.css.

A note on line-break invisibles and selections

At the time of writing, Chrome, Firefox and Safari all provide limited feedback when rendering a selection that includes a line break – the selection and cursor does not change until content after the break is highlighted. Below, you can see there is a selection position that includes the linebreak which is not visible to users:

No clear indication when we've selected across the paragraph boundary. Taken in Firefox

This is problematic for invisible characters that represent line breaks (paragraphs, soft returns, etc.) – we must include line break invisibles when they're part of a selection, or we risk misleading the user by implying that line breaks are not part of a selection when they are.

Including content in the decorations representing invisible characters introduces problems with layout and cursor behaviour, so at present we fake this by adding an additional span within these decorations when they're part of a selection. We can then add a width to the span, and give it a background colour that's identical to the text selection. This kludge gives us the behaviour we expect:

Selecting invisibles provides a clear indication when we've selected across the paragraph boundary. Taken in Firefox

Adapting this styling may be necessary in your own editor to ensure that the impostor span's colour and size are correct. We recommend removing this styling if this behaviour isn't desirable. Finally, we'd love a better solution to this problem – any suggestions most welcome!

Running locally

To run the sandbox locally run:

yarn watch

版本与发布记录

@guardian/prosemirror-invisibles 共发布 21 个版本,首次发布于 2018/08/22;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.1.3latest2026/04/077 个月前
3.1.12024/07/302 年前
3.0.32023/01/063 年前
3.0.22022/11/164 年前
3.0.12022/11/034 年前
3.0.02022/11/034 年前

其他发布通道:alpha → 1.3.0。

关于 @guardian/prosemirror-invisibles 的常见问题

@guardian/prosemirror-invisibles 是什么?

A plugin to show invisibles in prosemirror

如何安装 @guardian/prosemirror-invisibles?

在项目目录运行 npm install @guardian/prosemirror-invisibles,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:prosemirror-model(^1.18.2)、prosemirror-state(^1.4.2)、prosemirror-view(^1.29.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@guardian/prosemirror-invisibles 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@guardian/prosemirror-invisibles 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@guardian/prosemirror-invisibles 可以商用吗?

@guardian/prosemirror-invisibles 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@guardian/prosemirror-invisibles 的下载量有多少?

根据 npm 官方下载统计,@guardian/prosemirror-invisibles 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,938 次,日均约 165 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@guardian/prosemirror-invisibles 还在维护吗?

最新版本 3.1.3 发布于 2026/04/07(7 个月前);至今共发布 21 个版本,其中过去 12 个月发布了 1 个;首次发布于 2018/08/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。