@textbus/platform-browser 4.0.0-alpha.5 → 4.0.0-alpha.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -114
- package/bundles/browser-module.d.ts +22 -7
- package/bundles/collaborate-cursor.d.ts +7 -13
- package/bundles/dom-adapter.d.ts +4 -64
- package/bundles/index.esm.js +169 -226
- package/bundles/index.js +171 -228
- package/bundles/magic-input.d.ts +9 -9
- package/bundles/native-input.d.ts +3 -5
- package/bundles/parser.d.ts +10 -11
- package/bundles/public-api.d.ts +1 -0
- package/bundles/selection-bridge.d.ts +3 -4
- package/bundles/types.d.ts +0 -7
- package/package.json +6 -5
package/README.md
CHANGED
@@ -4,120 +4,6 @@ Textbus PC 浏览器支持模块
|
|
4
4
|
Textbus 是一套用于构建富交互的富文本编辑框架。和大多数富文本编辑器不同的是,Textbus 以组件为核心,格式为辅助,并大幅简化了富文本编辑器开发中常见
|
5
5
|
API,且提供了更高的抽象层,使 Textbus 不仅易于上手,同时还能驱动复杂的富文本应用。
|
6
6
|
|
7
|
-
本项目为 Textbus PC 端浏览器中间层实现,提供了 Textbus PC 端所需要的编辑器基本支持能力。如光标、选区桥接、DOM 解析及渲染能力桥接等。
|
8
|
-
|
9
|
-
如果你需要一个开箱即用的编辑器,请参考[官方文档](https://textbus.io)。
|
10
|
-
|
11
|
-
## 安装
|
12
|
-
|
13
|
-
```
|
14
|
-
npm install @textbus/core @textbus/platform-browser
|
15
|
-
```
|
16
|
-
|
17
|
-
## 创建编辑器
|
18
|
-
|
19
|
-
```ts
|
20
|
-
import { Viewer, ViewOptions } from '@textbus/browser'
|
21
|
-
|
22
|
-
import { rootComponent, rootComponentLoader } from './root.component'
|
23
|
-
|
24
|
-
const config: ViewOptions = {
|
25
|
-
// ...配置项
|
26
|
-
}
|
27
|
-
|
28
|
-
const editor = new Viewer(rootComponent, rootComponentLoader, config)
|
29
|
-
```
|
30
|
-
|
31
|
-
其中 `rootComponent`,`rootComponentLoader` 实现请参考[官方文档](https://textbus.io/docs/guide)。
|
32
|
-
|
33
|
-
### 配置项
|
34
|
-
|
35
|
-
配置项接口如下:
|
36
|
-
|
37
|
-
```ts
|
38
|
-
export interface ViewModule extends Module {
|
39
|
-
componentLoaders?: ComponentLoader[]
|
40
|
-
formatLoaders?: FormatLoader[]
|
41
|
-
}
|
42
|
-
|
43
|
-
/**
|
44
|
-
* Textbus PC 端配置接口
|
45
|
-
*/
|
46
|
-
export interface ViewOptions extends TextbusConfig {
|
47
|
-
imports?: ViewModule[]
|
48
|
-
/** 自动获取焦点 */
|
49
|
-
autoFocus?: boolean
|
50
|
-
/** 编辑区最小高度 */
|
51
|
-
minHeight?: string
|
52
|
-
/** 组件加载器 */
|
53
|
-
componentLoaders?: ComponentLoader[]
|
54
|
-
/** 格式加载器 */
|
55
|
-
formatLoaders?: FormatLoader[]
|
56
|
-
/** 默认内容 */
|
57
|
-
content?: string | ComponentLiteral
|
58
|
-
/** 文档默认样式表 */
|
59
|
-
styleSheets?: string[]
|
60
|
-
/** 配置文档编辑状态下用到的样式 */
|
61
|
-
editingStyleSheets?: string[]
|
62
|
-
}
|
63
|
-
```
|
64
|
-
|
65
|
-
### 启动
|
66
|
-
|
67
|
-
```ts
|
68
|
-
const host = document.getElementById('editor')
|
69
|
-
|
70
|
-
editor.mount(host).then(() => {
|
71
|
-
console.log('编辑器创建成功!')
|
72
|
-
})
|
73
|
-
```
|
74
|
-
|
75
|
-
### 销毁编辑器
|
76
|
-
|
77
|
-
```ts
|
78
|
-
editor.destroy()
|
79
|
-
```
|
80
|
-
|
81
|
-
### 获取焦点
|
82
|
-
|
83
|
-
```ts
|
84
|
-
editor.focus()
|
85
|
-
```
|
86
|
-
|
87
|
-
### 取消焦点
|
88
|
-
|
89
|
-
```ts
|
90
|
-
editor.blur()
|
91
|
-
```
|
92
|
-
|
93
|
-
### 获取 HTML 内容
|
94
|
-
|
95
|
-
```ts
|
96
|
-
const content = editor.getContents().content
|
97
|
-
```
|
98
|
-
|
99
|
-
### 获取 JSON 内容
|
100
|
-
|
101
|
-
```ts
|
102
|
-
const json = editor.getJSON().content
|
103
|
-
```
|
104
|
-
|
105
|
-
### 替换内容
|
106
|
-
|
107
|
-
```ts
|
108
|
-
editor.replaceContent('<p>新内容!</p>')
|
109
|
-
|
110
|
-
editor.replaceContent({
|
111
|
-
// 必须为 Textbus 导出的 JSON 格式
|
112
|
-
})
|
113
|
-
```
|
114
|
-
|
115
|
-
### 清空编辑器
|
116
|
-
|
117
|
-
```ts
|
118
|
-
editor.replaceContent('')
|
119
|
-
```
|
120
|
-
|
121
7
|
### 官方文档
|
122
8
|
|
123
9
|
更多文档请参考:[中文文档](https://textbus.io)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { ComponentLiteral, Module } from '@textbus/core';
|
1
|
+
import { ComponentConstructor, Component, ComponentLiteral, Module, Textbus } from '@textbus/core';
|
2
2
|
import { Provider } from '@viewfly/core';
|
3
3
|
import { AttributeLoader, ComponentLoader, FormatLoader } from './parser';
|
4
4
|
import { DomAdapter } from './dom-adapter';
|
@@ -6,7 +6,10 @@ import { DomAdapter } from './dom-adapter';
|
|
6
6
|
* Textbus PC 端配置接口
|
7
7
|
*/
|
8
8
|
export interface ViewOptions {
|
9
|
-
|
9
|
+
/** 跨平台适配器 */
|
10
|
+
adapter: DomAdapter;
|
11
|
+
/** 编辑器根节点 */
|
12
|
+
renderTo(): HTMLElement;
|
10
13
|
/** 自动获取焦点 */
|
11
14
|
autoFocus?: boolean;
|
12
15
|
/** 编辑区最小高度 */
|
@@ -17,17 +20,29 @@ export interface ViewOptions {
|
|
17
20
|
formatLoaders?: FormatLoader<any>[];
|
18
21
|
/** 属性加载器 */
|
19
22
|
attributeLoaders?: AttributeLoader<any>[];
|
20
|
-
/** 默认内容 */
|
21
|
-
content?: string | ComponentLiteral;
|
22
23
|
/** 使用 contentEditable 作为编辑器控制可编辑范围 */
|
23
24
|
useContentEditable?: boolean;
|
24
25
|
}
|
25
26
|
export declare class BrowserModule implements Module {
|
26
|
-
host: HTMLElement;
|
27
27
|
config: ViewOptions;
|
28
28
|
providers: Provider[];
|
29
29
|
private workbench;
|
30
|
-
constructor(
|
31
|
-
|
30
|
+
constructor(config: ViewOptions);
|
31
|
+
/**
|
32
|
+
* 解析 HTML 并返回一个组件实例
|
33
|
+
* @param html 要解析的 HTML
|
34
|
+
* @param rootComponentLoader 文档根组件加载器
|
35
|
+
* @param textbus
|
36
|
+
*/
|
37
|
+
readDocumentByHTML(html: string, rootComponentLoader: ComponentLoader, textbus: Textbus): Component;
|
38
|
+
/**
|
39
|
+
* 将组件数据解析到组件实例中
|
40
|
+
* @param data 要解析的 JSON 数据
|
41
|
+
* @param rootComponent 根组件
|
42
|
+
* @param textbus
|
43
|
+
*/
|
44
|
+
readDocumentByComponentLiteral(data: ComponentLiteral, rootComponent: ComponentConstructor, textbus: Textbus): Component;
|
45
|
+
setup(textbus: Textbus): () => void;
|
46
|
+
onAfterStartup(textbus: Textbus): void;
|
32
47
|
private static createLayout;
|
33
48
|
}
|
@@ -1,16 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import { Selection, AbstractSelection, Scheduler, Textbus } from '@textbus/core';
|
2
|
+
import { UserActivity } from '@textbus/collaborate';
|
3
3
|
import { SelectionBridge } from './selection-bridge';
|
4
4
|
import { Rect } from './_utils/uikit';
|
5
|
-
/**
|
6
|
-
* 远程用户及光标位置信息
|
7
|
-
*/
|
8
|
-
export interface RemoteSelection {
|
9
|
-
id: string;
|
10
|
-
color: string;
|
11
|
-
username: string;
|
12
|
-
paths: SelectionPaths;
|
13
|
-
}
|
14
5
|
export interface SelectionRect extends Rect {
|
15
6
|
color: string;
|
16
7
|
username: string;
|
@@ -34,6 +25,7 @@ export declare class CollaborateCursor {
|
|
34
25
|
private nativeSelection;
|
35
26
|
private scheduler;
|
36
27
|
private selection;
|
28
|
+
private userActivity;
|
37
29
|
private awarenessDelegate?;
|
38
30
|
private host;
|
39
31
|
private canvasContainer;
|
@@ -44,7 +36,9 @@ export declare class CollaborateCursor {
|
|
44
36
|
private subscription;
|
45
37
|
private currentSelection;
|
46
38
|
private container;
|
47
|
-
|
39
|
+
private ratio;
|
40
|
+
constructor(textbus: Textbus, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, userActivity: UserActivity, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
|
41
|
+
init(): void;
|
48
42
|
/**
|
49
43
|
* 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
|
50
44
|
*/
|
@@ -54,7 +48,7 @@ export declare class CollaborateCursor {
|
|
54
48
|
* 根据远程用户光标位置,绘制协作光标
|
55
49
|
* @param paths
|
56
50
|
*/
|
57
|
-
draw
|
51
|
+
private draw;
|
58
52
|
protected drawUserCursor(rects: SelectionRect[]): void;
|
59
53
|
private getUserCursor;
|
60
54
|
}
|
package/bundles/dom-adapter.d.ts
CHANGED
@@ -1,66 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
export declare abstract class DomAdapter<ViewComponent, ViewElement> extends ViewAdapter {
|
6
|
-
private mount;
|
1
|
+
import { Adapter } from '@textbus/core';
|
2
|
+
import { Subject } from '@tanbo/stream';
|
3
|
+
export declare abstract class DomAdapter<ViewComponent extends object = object, ViewElement extends object = object> extends Adapter<HTMLElement, Node, ViewComponent, ViewElement> {
|
4
|
+
onViewUpdated: Subject<void>;
|
7
5
|
host: HTMLElement;
|
8
|
-
protected componentRootElementCaches: {
|
9
|
-
set: {
|
10
|
-
(key: ComponentInstance<unknown, unknown, unknown>, value: HTMLElement): void;
|
11
|
-
(key: HTMLElement, value: ComponentInstance<unknown, unknown, unknown>): void;
|
12
|
-
};
|
13
|
-
get: {
|
14
|
-
(key: ComponentInstance<unknown, unknown, unknown>): HTMLElement;
|
15
|
-
(key: HTMLElement): ComponentInstance<unknown, unknown, unknown>;
|
16
|
-
};
|
17
|
-
remove: (key: HTMLElement | ComponentInstance<unknown, unknown, unknown>) => void;
|
18
|
-
};
|
19
|
-
protected slotRootNativeElementCaches: {
|
20
|
-
set: {
|
21
|
-
(key: Slot<any>, value: HTMLElement): void;
|
22
|
-
(key: HTMLElement, value: Slot<any>): void;
|
23
|
-
};
|
24
|
-
get: {
|
25
|
-
(key: Slot<any>): HTMLElement;
|
26
|
-
(key: HTMLElement): Slot<any>;
|
27
|
-
};
|
28
|
-
remove: (key: HTMLElement | Slot<any>) => void;
|
29
|
-
};
|
30
|
-
protected slotRootVElementCaches: WeakMap<Slot<any>, VElement>;
|
31
|
-
protected constructor(mount: (host: HTMLElement, viewComponent: ViewComponent) => (void | (() => void)));
|
32
|
-
render(rootComponent: ComponentInstance): void | (() => void);
|
33
|
-
abstract componentRender(component: ComponentInstance): ViewComponent;
|
34
|
-
abstract slotRender(slot: Slot, slotHostRender: (children: Array<VElement | VTextNode | ComponentInstance>) => VElement, renderEnv: any): ViewElement;
|
35
|
-
copy(): void;
|
36
|
-
/**
|
37
|
-
* 根据组件获取组件的根 DOM 节点
|
38
|
-
* @param component
|
39
|
-
*/
|
40
|
-
getNativeNodeByComponent(component: ComponentInstance): HTMLElement | null;
|
41
|
-
/**
|
42
|
-
* 根据 DOM 节点,获对对应的组件根节点,如传入的 DOM 节点不为组件的根节点,则返回 null
|
43
|
-
* @param node
|
44
|
-
*/
|
45
|
-
getComponentByNativeNode(node: HTMLElement): ComponentInstance | null;
|
46
|
-
/**
|
47
|
-
* 根据插槽获取插槽的根 DOM 节点
|
48
|
-
* @param slot
|
49
|
-
*/
|
50
|
-
getNativeNodeBySlot(slot: Slot): HTMLElement | null;
|
51
|
-
/**
|
52
|
-
* 根据 DOM 节点,获对对应的插槽根节点,如传入的 DOM 节点不为插槽的根节点,则返回 null
|
53
|
-
* @param node
|
54
|
-
*/
|
55
|
-
getSlotByNativeNode(node: HTMLElement): Slot | null;
|
56
|
-
/**
|
57
|
-
* 获取插槽内容节点集合
|
58
|
-
* @param slot
|
59
|
-
*/
|
60
|
-
getNodesBySlot(slot: Slot): Node[];
|
61
|
-
/**
|
62
|
-
* 获取原生节点的原始数据在文档中的位置
|
63
|
-
* @param node
|
64
|
-
*/
|
65
|
-
getLocationByNativeNode(node: Node): NodeLocation | null;
|
66
6
|
}
|