Skip to content

Commit

Permalink
feat: 从源仓库迁移代码
Browse files Browse the repository at this point in the history
  • Loading branch information
tbhuabi committed Apr 23, 2022
1 parent 5fb4ca4 commit 16ff66d
Show file tree
Hide file tree
Showing 230 changed files with 69,984 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true
},
"rules": {
"linebreak-style": 0,
"no-console": 0,
"no-debugger": 0,
"no-useless-escape": "off",
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"no-constant-condition": ["error", {"checkLoops": false }],
"semi": [1, "never"]
},
"ignorePatterns": ["index.ts"]
}
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules/
npm-debug.log
dist/
package/bundles
bundles/
zip
.idea
coverage/
*.swp
*.swo
.vscode/
yarn.lock
22 changes: 22 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.DS_Store
coverage/
node_modules/
src/
test/
.gitignore
.npmignore
.eslintrc.js
disable-output-webpack-plugin.js
gulpfile.js
package-lock.json
template-style-loader.js
tsconfig.json
tsconfig-build.json
webpack.config.js
webpack-sass.config.js
webpack-template-style.config.js
npm-debug.log
jest.config.js
.idea
*.swp
*.swo
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
Textbus
================================

> 如果你还在使用 1.0 版本,源代码请访问 [Textbus 1.*](https://github.com/textbus/textbus-1.0)
Textbus 是一个组件化、跨平台、数据驱动的富文本框架,并坚定的支持在线协同。使用 Textbus 你可以轻松创建你自完全自定义的编辑器。

我们一直致力于让富文本开发也能像普通前端框架一样,通过简明易懂的 api 和少量的约定,即可扩展出健壮的、符合预期的富文本编辑器。在 Textbus 1.0 的时,我们为此做了非常多的探索和努力,取得了不错的成果,但也因为如此,1.0 的设计在某些方面还留下一些遗憾。

幸运的是,Textbus 2.0 即将面世,我们在 1.0 的成果之上,重新设计了整个架构,致力于更简洁的 api,更友好的开发接入方式。

+ 重新设计了组件系统,去掉了大家难以理解的装饰器,改为用类似 vue 的 setup 形式开发组件,并提供了一系列的 hooks 供大家定制交互行为
+ 重新设计了数据模型,可根据用户的操作生成特定的底层原子命令,这让细粒度的历史记录和文档协同成为可能
+ 核心架构脱离了具体平台,让 Textbus 的能力不仅限于在 PC 端,通过编写特定的中间层,可以方便的在移动端,甚至小程序上实现丰富的富文本能力
+ 重写了渲染层,现在 Textbus 2.0 大多数情况下更新视图仅需要 0.2ms 时间,比 1.0 性能更好

![](./_source/demo.png)

## 安装

Textbus 可能通过两种方式引入到你的项目中。

### 通过 npm 安装
```
npm install @textbus/core @textbus/browser @textbus/editor
```
在 DOM 中准备好一个空的标签
```html
<div id="editor"></div>
```

创建编辑器实例

```ts
import '@textbus/editor/bundles/textbus.min.css';
import { createEditor } from '@textbus/editor';

const editor = createEditor(document.getElementById('editor'))

```


### 通过 script 标签引入

```html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/path/textbus.min.css">
<script src="/path/textbus.min.js"></script>
<title>Textbus 示例</title>
</head>
<body>
<div id="editor"></div>
<script>
var editor = textbus.editor.createEditor(document.getElementById('editor'))
</script>
</body>
</html>
```
## 官方文档

[Textbus 官方文档](https://Textbus.io)

## 本地开发

Textbus 采用 lerna 作为多模块管理,全局安装 lerna。

```
npm install lerna -g
```

克隆 Textbus 仓库,并安装依赖。

```
git clone [email protected]:textbus/textbus.git
cd textbus
lerna bootstrap --hoist
```

启动开发环境。

```
npm start
```

## 联系我们

如果在官网还不能找到你想了解的问题,你可以加入 Textbus 的官方 QQ 群:786923770。你也可以直接扫码加入:

![](./_source/qq-group.jpg)

## 赞助

Textbus 的成长离不开社会的支持,如果 Textbus 为你带来了帮助,并且你也认同为知识付费,同时鼓励我们做的更好,欢迎通过下面的二维码表达你的支持

![](./_source/wx.jpg) ![](./_source/alipay.jpg)
1 change: 1 addition & 0 deletions _source/Textbus 时序图.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2022-04-02T05:38:15.502Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36" etag="nhKCGIT0xmUqJAx0SzMk" version="16.6.6" type="device"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7Vxbd6M2EP41esweQNz0CDbZbrvbk550u+0jaxSbLjEOljd2f30lITAIOcYXDEn8kqABBNJ8+mZGMxjA0eP6YxYuZl/SCCfA0KI1gGNgGMh26F8m2OQCW9NzwTSLo1xUEdzH/2Eh1IR0FUd4WbuQpGlC4kVdOEnnczwhNVmYZelz/bKHNKk/dRFOcUNwPwmTpvRbHJFZLnUNZyv/BcfTWfFk3Ub5mcewuFiMZDkLo/S5IoIBgKMsTUl+9Lge4YTNXTEv3z5tviWff9gff/1j+RR+9X/78/e/bvLObg+5pRxChufk6K6XTpi48eou1jVz4c20py8kFbdoP8NkJeYLBBZwbeBaILCBpwHfZRJfB64hpoFsirnN0tU8wqx/HUD/eRYTfL8IJ+zsMwUTlc3IYyJOP6RzIuChW6wdJ8koTdKM9wWjELsPEypfkiz9gStn7ImLvz/QM+JdcUbwWlLunpnRS3VRmOP0EZNsQ+8TvbhiFgTCTdF83sJFLzAwq0DFFrJQIHRadrzVAj0QijhAKbpSKT4CPuTauQW+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YQ6HZuIN9MbEq7QralI4f6to7j6JKbJrtfXVtMRaj6AnYmSbhcxpM6YupIqOGqCZsmvHav3SPh1JsbJVNsy1hFUSK0p6OOQQFfa9BjyUFPS2ouHZrzF4AOIOjpmpuv9XTnWneq8KUs6y7qYwIEqJFAedXcLYtarn5ulQPsOhpKnPVVMQMV6VoWotDgk5c/UQV6sPKtDa98pGGqoX39RP+IuknEP75hNVN29auO/AONSiUlB4eLuGQEfE91+xUuFX9MKrAq97/21V12ZzIOc+dbuGTlrteN9sGobywb+r6tL966w1lMR8ewMJT95n53zCCsWwrTPs7klCbmwE8AqPbDTeUyse52v7D8HPHCbd+rcEG3wM7f4Lz2T5U34xWj6FZUjCJeCO4GXEKZciwkSGfWMa8s98wrxdUsYl3ztsonvmhqrUV4cULMidcxEWQHRTPnOtMoTm+pjjVqTKdIvjnQPDj91i7MZY+XqVXJtyey6fk+vOqXdiGqsxKUaxiPpV0og70j2i0+JG39Xgh1T7tmky9ff0XY2TPRluQoHr+7I3cEu8FeIxDSXsZe43q45/od4+gWq6pgqmH+WbHNGHijIsPXtC/v2yHYgYzeQmTT6YOBhrhTfW6SOtZANjpqmZc4maSsA0lqj0HdNY5uSersEfwQoXqp7V21B3W4yydnZy6cabPOmglowmO//pu42RXxGPvqDU+C0uDDjF1e+8k/8GBcaHfHEFnlI1mONre/ZZVfvv1BMBj8Dw==</diagram></mxfile>
1 change: 1 addition & 0 deletions _source/Textbus 架构图.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2022-04-02T02:25:31.891Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36" etag="lVC2QEEtoGpP2PIaWT4S" version="16.6.6" type="device"><diagram id="nZ9XGS9c5bAofMBQ1eQH" name="Page-1">7Vxtc5s4EP41+pgOIF6kj8jG6Vyn187k5tp86hCj2lyJ8WAcJ/31pxXCGKTk0to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pGVeoP2G1z7Xuumu24xd9mbvrdMw9+E1zd7t+Q17Z3A3F4NncTxS1e7NOgutFvY6iwPXh3zRROBru5HunslIxbd4uVH29eUUTjv4F</diagram></mxfile>
Binary file added _source/alipay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _source/demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _source/qq-group.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _source/textbus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _source/wx.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Textbus</title>
<style>
#editor {
width: 1000px;
margin-left: auto;
margin-right: auto;
}

table {
border-collapse: collapse;
border-spacing: 0;
}

td {
width: 100px;
height: 20px;
border: 1px solid #ccc
}
</style>
</head>
<body>
<div>
<button type="button" id="insert-btn">insert</button>
<span id="insert-span">insert</span>
</div>
<div style="max-width: 800px; margin: 30px auto; height: 40px" id="header">

</div>
<div style="max-width: 800px; margin: 30px auto;" id="box"></div>
<div style="width: 800px; margin: 30px auto;" id="box1">fdsafdsa</div>
<div id="template1" contenteditable="true">
fdfads
</div>
<div id="template" style="display: none">
</div>
</body>
</html>

2 changes: 2 additions & 0 deletions index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import "./packages/editor/assets/icons/style.css";
@import "./packages/editor/assets/index";
112 changes: 112 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import "./index.scss"
import { createEditor } from '@textbus/editor';
import { RootComponentRef, History, Commander } from '@textbus/core';
import { Collaborate, CollaborateCursor, RemoteSelection } from '@textbus/collaborate';
import { WebsocketProvider } from 'y-websocket'
import { WebrtcProvider } from 'y-webrtc'

const header = document.getElementById('header')!
const insertBtn = document.getElementById('insert-btn')!
const insertSpan = document.getElementById('insert-span')!

insertBtn.addEventListener('click', () => {
const commander = editor.injector!.get(Commander)
commander.insert('xxx')
})
insertSpan.addEventListener('click', () => {
const commander = editor.injector!.get(Commander)
commander.insert('vvv')
})

export interface User {
color: string
name: string
}

const editor = createEditor(document.getElementById('box')!, {
autoFocus: true,
// autoHeight: true,
minHeight: '300px',
theme: 'light',
placeholder: '请输入内容……',
content: document.getElementById('template')?.innerHTML,
providers: [
Collaborate,
CollaborateCursor,
{
provide: History,
useClass: Collaborate
}
],
setup(starter) {
const collaborate = starter.get(Collaborate)

// const provide = new WebrtcProvider('textbus', collaborate.yDoc)
const provide = new WebsocketProvider('wss://textbus.io/api', 'collab', collaborate.yDoc)
const users: User[] = [{
color: '#f00',
name: '张三'
}, {
color: '#448299',
name: '李国'
}, {
color: '#fe91dd',
name: '赵功'
}, {
color: '#1f2baf',
name: '载膛'
}, {
color: '#2aad30',
name: '魂牵梦萦'
}, {
color: '#c4ee6e',
name: '杰国'
}, {
color: '#00a6ff',
name: '膛世界杯'
}]

const user = users[Math.floor(Math.random() * users.length)]

provide.awareness.setLocalStateField('user', user)

collaborate.setup()

const sub = collaborate.onSelectionChange.subscribe(paths => {
const localSelection: RemoteSelection = {
username: user.name,
color: user.color,
paths
}
provide.awareness.setLocalStateField('selection', localSelection)
})

provide.awareness.on('update', () => {
const users: User[] = []
const remoteSelections: RemoteSelection[] = []
provide.awareness.getStates().forEach(state => {
if (state.user) {
users.push(state.user)
}
if (state.selection) {
remoteSelections.push(state.selection)
}
})

const selections = remoteSelections.filter(i => i.username !== user.name)

collaborate.updateRemoteSelection(selections)
header.innerHTML = users.map(i => {
return `<span style="color: ${i.color}">${i.name}</span>`
}).join('')
})
return () => {
sub.unsubscribe()
}
},
})

editor.onChange.subscribe(() => {
const root = editor.injector!.get(RootComponentRef)
// console.log(root.component.toString())
})
9 changes: 9 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"packages": [
"packages/*"
],
"publishConfig": {
"access": "public"
},
"version": "2.0.0-alpha.76"
}
Loading

0 comments on commit 16ff66d

Please sign in to comment.