@textbus/platform-browser 3.1.7 → 3.1.9

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 CHANGED
@@ -1,123 +1,123 @@
1
- Textbus PC 浏览器支持模块
2
- =====================
3
-
4
- Textbus 是一套用于构建富交互的富文本编辑框架。和大多数富文本编辑器不同的是,Textbus 以组件为核心,格式为辅助,并大幅简化了富文本编辑器开发中常见
5
- API,且提供了更高的抽象层,使 Textbus 不仅易于上手,同时还能驱动复杂的富文本应用。
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
- ### 官方文档
122
-
123
- 更多文档请参考:[中文文档](https://textbus.io)
1
+ Textbus PC 浏览器支持模块
2
+ =====================
3
+
4
+ Textbus 是一套用于构建富交互的富文本编辑框架。和大多数富文本编辑器不同的是,Textbus 以组件为核心,格式为辅助,并大幅简化了富文本编辑器开发中常见
5
+ API,且提供了更高的抽象层,使 Textbus 不仅易于上手,同时还能驱动复杂的富文本应用。
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
+ ### 官方文档
122
+
123
+ 更多文档请参考:[中文文档](https://textbus.io)
@@ -1,5 +1,5 @@
1
- export declare const isWindows: () => boolean;
2
- export declare const isMac: () => boolean;
3
- export declare const isSafari: () => boolean;
4
- export declare const isFirefox: () => boolean;
5
- export declare const isMobileBrowser: () => boolean;
1
+ export declare const isWindows: () => boolean;
2
+ export declare const isMac: () => boolean;
3
+ export declare const isSafari: () => boolean;
4
+ export declare const isFirefox: () => boolean;
5
+ export declare const isMobileBrowser: () => boolean;
@@ -1,26 +1,26 @@
1
- /**
2
- * 选区焦点可视位置
3
- */
4
- export interface Rect {
5
- left: number;
6
- top: number;
7
- width: number;
8
- height: number;
9
- }
10
- export interface UIElementParams {
11
- classes?: string[];
12
- attrs?: {
13
- [key: string]: any;
14
- };
15
- props?: {
16
- [key: string]: any;
17
- };
18
- styles?: {
19
- [key: string]: any;
20
- };
21
- children?: (Node | null)[];
22
- on?: Record<string, (ev: Event) => void>;
23
- }
24
- export declare function createElement(tagName: string, options?: UIElementParams): HTMLElement;
25
- export declare function createTextNode(content: string): Text;
26
- export declare function getLayoutRectByRange(range: Range): Rect;
1
+ /**
2
+ * 选区焦点可视位置
3
+ */
4
+ export interface Rect {
5
+ left: number;
6
+ top: number;
7
+ width: number;
8
+ height: number;
9
+ }
10
+ export interface UIElementParams {
11
+ classes?: string[];
12
+ attrs?: {
13
+ [key: string]: any;
14
+ };
15
+ props?: {
16
+ [key: string]: any;
17
+ };
18
+ styles?: {
19
+ [key: string]: any;
20
+ };
21
+ children?: (Node | null)[];
22
+ on?: Record<string, (ev: Event) => void>;
23
+ }
24
+ export declare function createElement(tagName: string, options?: UIElementParams): HTMLElement;
25
+ export declare function createTextNode(content: string): Text;
26
+ export declare function getLayoutRectByRange(range: Range): Rect;
@@ -1,45 +1,45 @@
1
- import { Injector } from '@tanbo/di';
2
- import { Selection, SelectionPaths, AbstractSelection, Scheduler } from '@textbus/core';
3
- import { SelectionBridge } from '../core/selection-bridge';
4
- import { Rect } from '../_utils/uikit';
5
- export interface RemoteSelection {
6
- id: string;
7
- color: string;
8
- username: string;
9
- paths: SelectionPaths;
10
- }
11
- export interface SelectionRect extends Rect {
12
- color: string;
13
- username: string;
14
- id: string;
15
- }
16
- export interface RemoteSelectionCursor {
17
- cursor: HTMLElement;
18
- anchor: HTMLElement;
19
- userTip: HTMLElement;
20
- }
21
- export declare abstract class CollaborateSelectionAwarenessDelegate {
22
- abstract getRects(abstractSelection: AbstractSelection, nativeRange: Range): false | Rect[];
23
- }
24
- export declare class CollaborateCursor {
25
- private injector;
26
- private nativeSelection;
27
- private scheduler;
28
- private selection;
29
- private awarenessDelegate?;
30
- private host;
31
- private canvasContainer;
32
- private canvas;
33
- private context;
34
- private tooltips;
35
- private onRectsChange;
36
- private subscription;
37
- private currentSelection;
38
- private container;
39
- constructor(injector: Injector, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
40
- refresh(): void;
41
- destroy(): void;
42
- draw(paths: RemoteSelection[]): void;
43
- protected drawUserCursor(rects: SelectionRect[]): void;
44
- private getUserCursor;
45
- }
1
+ import { Injector } from '@tanbo/di';
2
+ import { Selection, SelectionPaths, AbstractSelection, Scheduler } from '@textbus/core';
3
+ import { SelectionBridge } from '../core/selection-bridge';
4
+ import { Rect } from '../_utils/uikit';
5
+ export interface RemoteSelection {
6
+ id: string;
7
+ color: string;
8
+ username: string;
9
+ paths: SelectionPaths;
10
+ }
11
+ export interface SelectionRect extends Rect {
12
+ color: string;
13
+ username: string;
14
+ id: string;
15
+ }
16
+ export interface RemoteSelectionCursor {
17
+ cursor: HTMLElement;
18
+ anchor: HTMLElement;
19
+ userTip: HTMLElement;
20
+ }
21
+ export declare abstract class CollaborateSelectionAwarenessDelegate {
22
+ abstract getRects(abstractSelection: AbstractSelection, nativeRange: Range): false | Rect[];
23
+ }
24
+ export declare class CollaborateCursor {
25
+ private injector;
26
+ private nativeSelection;
27
+ private scheduler;
28
+ private selection;
29
+ private awarenessDelegate?;
30
+ private host;
31
+ private canvasContainer;
32
+ private canvas;
33
+ private context;
34
+ private tooltips;
35
+ private onRectsChange;
36
+ private subscription;
37
+ private currentSelection;
38
+ private container;
39
+ constructor(injector: Injector, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
40
+ refresh(): void;
41
+ destroy(): void;
42
+ draw(paths: RemoteSelection[]): void;
43
+ protected drawUserCursor(rects: SelectionRect[]): void;
44
+ private getUserCursor;
45
+ }
@@ -1,6 +1,6 @@
1
- export * from './dom-renderer';
2
- export * from './injection-tokens';
3
- export * from './magic-input';
4
- export * from './native-input';
5
- export * from './selection-bridge';
6
- export * from './types';
1
+ export * from './dom-renderer';
2
+ export * from './injection-tokens';
3
+ export * from './magic-input';
4
+ export * from './native-input';
5
+ export * from './selection-bridge';
6
+ export * from './types';
@@ -1,53 +1,53 @@
1
- import { NativeNode, NativeRenderer } from '@textbus/core';
2
- /**
3
- * Textbus PC 端浏览器渲染能力实现
4
- */
5
- export declare class DomRenderer implements NativeRenderer {
6
- isSVG: RegExp;
7
- xlinkNameSpace: string;
8
- possibleXlinkNames: {
9
- xlinkActuate: string;
10
- xlinkactuate: string;
11
- 'xlink:actuate': string;
12
- xlinkArcrole: string;
13
- xlinkarcrole: string;
14
- 'xlink:arcrole': string;
15
- xlinkHref: string;
16
- xlinkhref: string;
17
- 'xlink:href': string;
18
- xlinkRole: string;
19
- xlinkrole: string;
20
- 'xlink:role': string;
21
- xlinkShow: string;
22
- xlinkshow: string;
23
- 'xlink:show': string;
24
- xlinkTitle: string;
25
- xlinktitle: string;
26
- 'xlink:title': string;
27
- xlinkType: string;
28
- xlinktype: string;
29
- 'xlink:type': string;
30
- };
31
- booleanProps: Record<string, string[]>;
32
- valueProps: Record<string, string[]>;
33
- listen<T = any>(node: NativeNode, type: string, callback: (ev: T) => any): void;
34
- unListen(node: NativeNode, type: string, callback: (ev: any) => any): void;
35
- createTextNode(textContent: string): NativeNode;
36
- createElement(name: string): NativeNode;
37
- appendChild(parent: NativeNode, newChild: NativeNode): void;
38
- remove(node: NativeNode): void;
39
- insertBefore(newNode: NativeNode, ref: NativeNode): void;
40
- getChildByIndex(parent: NativeNode, index: number): NativeNode | null;
41
- addClass(target: NativeNode, name: string): void;
42
- removeClass(target: NativeNode, name: string): void;
43
- setStyle(target: NativeNode, key: string, value: any): void;
44
- syncTextContent(target: NativeNode, content: string): void;
45
- removeStyle(target: NativeNode, key: string): void;
46
- setAttribute(target: NativeNode, key: string, value: string): void;
47
- removeAttribute(target: NativeNode, key: string): void;
48
- setXlinkAttribute(target: NativeNode, key: string, value: string): void;
49
- removeXlinkAttribute(target: NativeNode, key: string): void;
50
- replace(newChild: NativeNode, oldChild: NativeNode): void;
51
- copy(): void;
52
- static replaceEmpty(s: string): string;
53
- }
1
+ import { NativeNode, NativeRenderer } from '@textbus/core';
2
+ /**
3
+ * Textbus PC 端浏览器渲染能力实现
4
+ */
5
+ export declare class DomRenderer implements NativeRenderer {
6
+ isSVG: RegExp;
7
+ xlinkNameSpace: string;
8
+ possibleXlinkNames: {
9
+ xlinkActuate: string;
10
+ xlinkactuate: string;
11
+ 'xlink:actuate': string;
12
+ xlinkArcrole: string;
13
+ xlinkarcrole: string;
14
+ 'xlink:arcrole': string;
15
+ xlinkHref: string;
16
+ xlinkhref: string;
17
+ 'xlink:href': string;
18
+ xlinkRole: string;
19
+ xlinkrole: string;
20
+ 'xlink:role': string;
21
+ xlinkShow: string;
22
+ xlinkshow: string;
23
+ 'xlink:show': string;
24
+ xlinkTitle: string;
25
+ xlinktitle: string;
26
+ 'xlink:title': string;
27
+ xlinkType: string;
28
+ xlinktype: string;
29
+ 'xlink:type': string;
30
+ };
31
+ booleanProps: Record<string, string[]>;
32
+ valueProps: Record<string, string[]>;
33
+ listen<T = any>(node: NativeNode, type: string, callback: (ev: T) => any): void;
34
+ unListen(node: NativeNode, type: string, callback: (ev: any) => any): void;
35
+ createTextNode(textContent: string): NativeNode;
36
+ createElement(name: string): NativeNode;
37
+ appendChild(parent: NativeNode, newChild: NativeNode): void;
38
+ remove(node: NativeNode): void;
39
+ insertBefore(newNode: NativeNode, ref: NativeNode): void;
40
+ getChildByIndex(parent: NativeNode, index: number): NativeNode | null;
41
+ addClass(target: NativeNode, name: string): void;
42
+ removeClass(target: NativeNode, name: string): void;
43
+ setStyle(target: NativeNode, key: string, value: any): void;
44
+ syncTextContent(target: NativeNode, content: string): void;
45
+ removeStyle(target: NativeNode, key: string): void;
46
+ setAttribute(target: NativeNode, key: string, value: string): void;
47
+ removeAttribute(target: NativeNode, key: string): void;
48
+ setXlinkAttribute(target: NativeNode, key: string, value: string): void;
49
+ removeXlinkAttribute(target: NativeNode, key: string): void;
50
+ replace(newChild: NativeNode, oldChild: NativeNode): void;
51
+ copy(): void;
52
+ static replaceEmpty(s: string): string;
53
+ }
@@ -1,18 +1,18 @@
1
- import { InjectionToken } from '@tanbo/di';
2
- import { ViewOptions } from './types';
3
- /**
4
- * 编辑器可选项依赖注入 token
5
- */
6
- export declare const EDITOR_OPTIONS: InjectionToken<ViewOptions>;
7
- /**
8
- * 编辑器容器依赖注入 token
9
- */
10
- export declare const VIEW_CONTAINER: InjectionToken<HTMLElement>;
11
- /**
12
- * 编辑器容器依赖注入 token
13
- */
14
- export declare const VIEW_DOCUMENT: InjectionToken<HTMLElement>;
15
- /**
16
- * 编辑器容器遮罩层 token
17
- */
18
- export declare const VIEW_MASK: InjectionToken<HTMLElement>;
1
+ import { InjectionToken } from '@tanbo/di';
2
+ import { ViewOptions } from './types';
3
+ /**
4
+ * 编辑器可选项依赖注入 token
5
+ */
6
+ export declare const EDITOR_OPTIONS: InjectionToken<ViewOptions>;
7
+ /**
8
+ * 编辑器容器依赖注入 token
9
+ */
10
+ export declare const VIEW_CONTAINER: InjectionToken<HTMLElement>;
11
+ /**
12
+ * 编辑器容器依赖注入 token
13
+ */
14
+ export declare const VIEW_DOCUMENT: InjectionToken<HTMLElement>;
15
+ /**
16
+ * 编辑器容器遮罩层 token
17
+ */
18
+ export declare const VIEW_MASK: InjectionToken<HTMLElement>;