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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@textbus/browser

v2.6.3

Published

Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.

Downloads

44

Readme

Textbus PC 浏览器支持模块

Textbus 是一套用于构建富交互的富文本编辑框架。和大多数富文本编辑器不同的是,Textbus 以组件为核心,格式为辅助,并大幅简化了富文本编辑器开发中常见 API,且提供了更高的抽象层,使 Textbus 不仅易于上手,同时还能驱动复杂的富文本应用。

本项目为 Textbus PC 端浏览器中间层实现,提供了 Textbus PC 端所需要的编辑器基本支持能力。如光标、选区桥接、DOM 解析及渲染能力桥接等。

如果你需要一个开箱即用的编辑器,请参考官方文档

安装

npm install @textbus/core @textbus/browser

创建编辑器

import { Viewer, ViewOptions } from '@textbus/browser'

import { rootComponent, rootComponentLoader } from './root.component'

const config: ViewOptions = {
  // ...配置项
}

const editor = new Viewer(rootComponent, rootComponentLoader, config)

其中 rootComponentrootComponentLoader 实现请参考官方文档

配置项

配置项接口如下:

export interface ViewModule extends Module {
  componentLoaders?: ComponentLoader[]
  formatLoaders?: FormatLoader[]
}

/**
 * Textbus PC 端配置接口
 */
export interface ViewOptions extends TextbusConfig {
  imports?: ViewModule[]
  /** 自动获取焦点 */
  autoFocus?: boolean
  /** 编辑区最小高度 */
  minHeight?: string
  /** 组件加载器 */
  componentLoaders?: ComponentLoader[]
  /** 格式加载器 */
  formatLoaders?: FormatLoader[]
  /** 默认内容 */
  content?: string | ComponentLiteral
  /** 文档默认样式表 */
  styleSheets?: string[]
  /** 配置文档编辑状态下用到的样式 */
  editingStyleSheets?: string[]
}

启动

const host = document.getElementById('editor')

editor.mount(host).then(() => {
  console.log('编辑器创建成功!')
})

销毁编辑器

editor.destroy()

获取焦点

editor.focus()

取消焦点

editor.blur()

获取 HTML 内容

const content = editor.getContents().content

获取 JSON 内容

const json = editor.getJSON().content

替换内容

editor.replaceContent('<p>新内容!</p>')

editor.replaceContent({
  // 必须为 Textbus 导出的 JSON 格式
})

清空编辑器

editor.replaceContent('')

官方文档

更多文档请参考:中文文档