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

@fe-muzi/rte-core

v0.1.1

Published

移动端富文本编辑器内核:话题(#)插入 + 图片/视频图文混排,框架无关,基于 contentEditable + Selection API

Readme

@fe-muzi/rte-core

移动端富文本编辑器内核:话题(#)插入 + 图片/视频图文混排。框架无关,基于原生 contentEditable + Selection/Range API,不依赖任何框架。

从社区 App 的富文本场景中提取,抹平 iOS/Android 差异,适合作为自研编辑器的底座。

在线演示 · GitHub

特性

  • 话题(#)插入:# 触发话题面板,选中话题以高亮 span 插入光标处,携带话题 ID
  • 图文混排:图片/视频作为原子块内联插入,带上传状态跟踪(loading → success/failure)、删除保护、媒体后可继续输入
  • 选区保护:话题/媒体节点禁止部分选中,删除重定向,选区缓存恢复
  • 中文输入法兼容:composition 状态机区分组词态与上屏态,避免误触发与误统计
  • 跨端抹平:iOS/Android 的 BR 计数差异、光标时序、键盘滚动行为
  • 字符长度计算:codePointAt 步进算法,emoji 代理对按 1 计数
  • 原生能力解耦:JSBridge 抽象为 PlatformAdapter / MediaUploader 可注入接口,默认纯 Web 实现

安装

pnpm add @fe-muzi/rte-core

快速上手

import { createRichTextEditor } from '@fe-muzi/rte-core'
import '@fe-muzi/rte-core/styles/editor.css'

const editor = createRichTextEditor({
  root: document.getElementById('editor')!,
  maxLength: 180,
  placeholder: { focus: '说点什么…', blur: '说点什么…' },
  onChange: (html, plain, length) => console.log(html, plain, length),
  onTopicTrigger: () => {
    // 用户输入 # 时触发:弹出话题面板,选中后调用 editor.insertTopic(...)
  },
  mediaUploader: {
    upload: (file, onStatus) => {
      onStatus('loading')
      // 调宿主上传接口,完成后回写:
      // onStatus('success', url) 或 onStatus('failure')
    },
  },
})

// 命令式操作
editor.insertTopic({ id: '1', title: '话题名' }, 'tab')
editor.insertMedia([{ id: 'f1', type: 'image', status: 'loading' }], 'image')
editor.setMediaStatus('f1', 'success', 'https://cdn.example.com/a.jpg')
console.log(editor.getHTML(), editor.getPlain(), editor.getLength())

API

createRichTextEditor(options: EditorOptions): RichTextEditor

EditorOptions

| 属性 | 类型 | 说明 | |---|---|---| | root | HTMLElement | 挂载的 contentEditable 容器(必填) | | maxLength | number | 最大长度,默认 180 | | placeholder | { focus?: string; blur?: string } | 聚焦/失焦占位文案 | | platform | Partial<PlatformAdapter> | 注入原生能力(见下) | | mediaUploader | MediaUploader | 上传实现(见下) | | onChange | (html, plain, length) => void | 内容变化回调(html 已做样式治理,length 为真实长度) | | onTopicTrigger | () => void | 输入 # 触发,宿主弹出话题面板 | | onMediaRequest | (type: 'image' \| 'video') => void | 媒体占位点击触发 | | onMediaInsert | (items: MediaInsertInfo[]) => void | 媒体节点插入通知 | | onMediaStatusChange | (localId, status, url?) => void | 上传状态变化通知 | | onLengthLimit | (isOver: boolean) => void | 超长提示 |

RichTextEditor 实例方法

insertTopic / insertMedia / setMediaStatus / removeMedia / getHTML / getPlain / getLength / focus / blur / destroy

PlatformAdapter(原生能力注入)

export interface PlatformAdapter {
  getOS(): 'iOS' | 'Android' | 'Other'
  onFocus?(root: HTMLElement): void          // 默认: root.focus();App 可接 JSBridge 拉起键盘
  setScrollEnabled?(enabled: boolean): void  // App: 键盘弹出时锁滚动;Web: no-op
  previewMedia?(src: string): void           // 图片预览;App 可接原生预览
}

MediaUploader(上传接口)

export interface MediaUploader {
  upload(file: File | MediaFile, onStatus: (status: UploadStatus, url?: string) => void): void
}

样式与主题

样式需手动引入一次,主题 CSS 变量可在宿主覆盖:

:root {
  --rte-text-primary: #000;      /* 正文 */
  --rte-text-disabled: #949598;  /* 占位文案 */
  --rte-text-link: #2762EC;      /* 话题高亮 */
}

License

MIT