Xnote is a headless, high-performance, framework-independent rich text editor that supports multi-person online collaboration. Provides rich modern document editing functions.
The underlying Xnote relies on the open source rich text framework Textbus and the front-end view Viewfly. Therefore, you can continue to expand your capabilities on this basis.
Online Demo
npm install @textbus/xnote katex
import 'katex/dist/katex.min.css'
import { Editor } from '@textbus/xnote'
const editor = new Editor ( )
editor . mount ( document . getElementById ( 'editor' ) ) . then ( ( ) => {
console . log ( '编辑器准备完成。' )
} ) To implement file upload, you need to implement the FileUploader interface
import { FileUploader } from '@textbus/xnote'
class YourUploader extends FileUploader {
uploadFile ( type : string ) : string | Promise < string > {
if ( type === 'image' ) {
return 'imageUrl'
}
if ( type === 'video' ) {
return 'videoUrl'
}
}
}
const editor = new Editor ( {
providers : [ {
provide : FileUploader ,
useFactory ( ) {
return new YourFileUplader ( )
}
} ]
} ) import { Commander } from '@textbus/core'
import { Injectable } from '@viewfly/core'
import { ImageComponent } from '@textbus/xnote'
@ Injectable ( )
class YourCommander extends Commander {
paste ( slot : Slot , text : string ) {
slot . sliceContent ( ) . forEach ( content => {
if ( content instanceof ImageComponent ) {
const base64 = content . state . url
// base64 转 url,请自行实现
content . state . url = 'https://xxx.com/xxx.jpg'
}
} )
// 待图片转换完成后,可调用超类的 paste 方法
super . paste ( slot , text )
return true
}
}
const editor = new Editor ( {
providers : [ {
provide : Commander ,
useClass : YourCommander
} ]
} ) const html = editor . getHTML ( ) const editor = new Editor ( {
content : '<div>HTML 内容</div>'
} ) editor . setContent ( '<p>你好!</p>' ) In the document, the @ human function needs to implement the following interface to connect to user information
export abstract class Organization {
abstract getMembers ( name ?: string ) : Promise < Member [ ] >
abstract atMember ( member : Member ) : void
}Then pass in your implementation when the editor is initialized
const editor = new Editor ( {
providers : [ {
provide : Organization ,
useValue : new YourOrganization ( )
} ]
} ) Textbus naturally supports collaboration. You only need to add collaboration configuration information to the editor configuration item. For specific configuration, you can refer to https://textbus.io/guide/collab/
const editor = new Editor ( {
collaborateConfig : {
userinfo : user , // 用户信息
createConnector ( yDoc ) : SyncConnector {
// 返回连接器
return new YWebsocketConnector ( 'wss://example.com' , 'docName' , yDoc )
}
}
} )