@textbus/platform-browser 3.3.2 → 3.3.4

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.
@@ -2,6 +2,9 @@ import { Injector } from '@tanbo/di';
2
2
  import { Selection, SelectionPaths, AbstractSelection, Scheduler } from '@textbus/core';
3
3
  import { SelectionBridge } from '../core/selection-bridge';
4
4
  import { Rect } from '../_utils/uikit';
5
+ /**
6
+ * 远程用户及光标位置信息
7
+ */
5
8
  export interface RemoteSelection {
6
9
  id: string;
7
10
  color: string;
@@ -18,9 +21,15 @@ export interface RemoteSelectionCursor {
18
21
  anchor: HTMLElement;
19
22
  userTip: HTMLElement;
20
23
  }
24
+ /**
25
+ * 远程光标绘制范围计算代理类,可用于定制特定场景下的远程选区绘制,如表格有选区,不会遵守常见的文档流形式
26
+ */
21
27
  export declare abstract class CollaborateSelectionAwarenessDelegate {
22
28
  abstract getRects(abstractSelection: AbstractSelection, nativeRange: Range): false | Rect[];
23
29
  }
30
+ /**
31
+ * 协作光标绘制类
32
+ */
24
33
  export declare class CollaborateCursor {
25
34
  private injector;
26
35
  private nativeSelection;
@@ -37,8 +46,15 @@ export declare class CollaborateCursor {
37
46
  private currentSelection;
38
47
  private container;
39
48
  constructor(injector: Injector, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
49
+ /**
50
+ * 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
51
+ */
40
52
  refresh(): void;
41
53
  destroy(): void;
54
+ /**
55
+ * 根据远程用户光标位置,绘制协作光标
56
+ * @param paths
57
+ */
42
58
  draw(paths: RemoteSelection[]): void;
43
59
  protected drawUserCursor(rects: SelectionRect[]): void;
44
60
  private getUserCursor;
@@ -1,6 +1,6 @@
1
1
  import { VElement } from '@textbus/core';
2
2
  /**
3
- * HTML 输出转换器
3
+ * HTML 输出转换器,用于将虚拟 DOM 转换为 HTML 字符串
4
4
  */
5
5
  export declare class OutputTranslator {
6
6
  static singleTags: string[];
@@ -10,6 +10,10 @@ export declare class OutputTranslator {
10
10
  attrValue(text: string): string;
11
11
  };
12
12
  private singleTagTest;
13
+ /**
14
+ * 将虚拟 DOM 转换为 HTML 字符串的方法
15
+ * @param vDom 虚拟 DOM 节点
16
+ */
13
17
  transform(vDom: VElement): string;
14
18
  private vDomToHTMLString;
15
19
  private replaceEmpty;
@@ -1,6 +1,9 @@
1
1
  import { Injector } from '@tanbo/di';
2
2
  import { Attribute, ComponentInstance, Formatter, FormatValue, Slot } from '@textbus/core';
3
3
  import { ViewOptions } from '../core/types';
4
+ /**
5
+ * 组件可附加携带的信息,如一些样式表、脚本、或编辑时模式时的样式
6
+ */
4
7
  export interface ComponentResources {
5
8
  links?: Array<{
6
9
  [key: string]: string;
@@ -9,7 +12,18 @@ export interface ComponentResources {
9
12
  scripts?: string[];
10
13
  editModeStyles?: string[];
11
14
  }
15
+ /**
16
+ * 插槽解析器
17
+ */
12
18
  export interface SlotParser {
19
+ /**
20
+ * 将指定 DOM 节点解析为插槽数据
21
+ * @param childSlot 储存数据的插槽
22
+ * @param slotRootElement 插槽的根节点
23
+ * @param slotContentHostElement 插槽的内容节点
24
+ *
25
+ * 注意:当不传入内容节点时,Textbus 会把根节点当成内容节点
26
+ */
13
27
  <T extends Slot>(childSlot: T, slotRootElement: HTMLElement, slotContentHostElement?: HTMLElement): T;
14
28
  }
15
29
  /**
@@ -27,18 +41,43 @@ export interface FormatLoaderReadResult<T extends FormatValue> {
27
41
  formatter: Formatter<T>;
28
42
  value: T;
29
43
  }
44
+ /**
45
+ * 格式加载器
46
+ */
30
47
  export interface FormatLoader<T extends FormatValue> {
48
+ /**
49
+ * 匹配一个 DOM 节点是否是某个格式节点
50
+ * @param element
51
+ */
31
52
  match(element: HTMLElement): boolean;
53
+ /**
54
+ * 读取匹配到的节点,并返回读取后的信息
55
+ * @param element
56
+ */
32
57
  read(element: HTMLElement): FormatLoaderReadResult<T>;
33
58
  }
34
59
  export interface AttributeLoaderReadResult<T extends FormatValue> {
35
60
  attribute: Attribute<T>;
36
61
  value: T;
37
62
  }
63
+ /**
64
+ * 属性加载器
65
+ */
38
66
  export interface AttributeLoader<T extends FormatValue> {
67
+ /**
68
+ * 匹配一个 DOM 节点是否是某个属性节点
69
+ * @param element
70
+ */
39
71
  match(element: HTMLElement): boolean;
72
+ /**
73
+ * 读取匹配到的节点,并返回读取后的信息
74
+ * @param element
75
+ */
40
76
  read(element: HTMLElement): AttributeLoaderReadResult<T>;
41
77
  }
78
+ /**
79
+ * 用于解析 HTML,并把 HTML 内容转换为 Textbus 可以支持的组件或插槽数据
80
+ */
42
81
  export declare class Parser {
43
82
  private options;
44
83
  private injector;
@@ -47,7 +86,17 @@ export declare class Parser {
47
86
  formatLoaders: FormatLoader<any>[];
48
87
  attributeLoaders: AttributeLoader<any>[];
49
88
  constructor(options: ViewOptions, injector: Injector);
89
+ /**
90
+ * 使用指定的组件加载器解析一段 HTML 字符串
91
+ * @param html
92
+ * @param rootComponentLoader
93
+ */
50
94
  parseDoc(html: string, rootComponentLoader: ComponentLoader): Slot<any> | ComponentInstance<import("@textbus/core").ComponentExtends, any, unknown>;
95
+ /**
96
+ * 将一段 HTML 解析到指定插槽
97
+ * @param html
98
+ * @param rootSlot
99
+ */
51
100
  parse(html: string, rootSlot: Slot): Slot<any>;
52
101
  private readComponent;
53
102
  private readFormats;
@@ -735,8 +735,14 @@ SelectionBridge = __decorate([
735
735
  Renderer])
736
736
  ], SelectionBridge);
737
737
 
738
+ /**
739
+ * 远程光标绘制范围计算代理类,可用于定制特定场景下的远程选区绘制,如表格有选区,不会遵守常见的文档流形式
740
+ */
738
741
  class CollaborateSelectionAwarenessDelegate {
739
742
  }
743
+ /**
744
+ * 协作光标绘制类
745
+ */
740
746
  let CollaborateCursor = class CollaborateCursor {
741
747
  constructor(injector, nativeSelection, scheduler, selection, awarenessDelegate) {
742
748
  this.injector = injector;
@@ -811,12 +817,19 @@ let CollaborateCursor = class CollaborateCursor {
811
817
  this.refresh();
812
818
  }));
813
819
  }
820
+ /**
821
+ * 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
822
+ */
814
823
  refresh() {
815
824
  this.draw(this.currentSelection);
816
825
  }
817
826
  destroy() {
818
827
  this.subscription.unsubscribe();
819
828
  }
829
+ /**
830
+ * 根据远程用户光标位置,绘制协作光标
831
+ * @param paths
832
+ */
820
833
  draw(paths) {
821
834
  this.currentSelection = paths;
822
835
  const containerRect = this.container.getBoundingClientRect();
@@ -1197,6 +1210,9 @@ DomRenderer = DomRenderer_1 = __decorate([
1197
1210
  ], DomRenderer);
1198
1211
 
1199
1212
  var Parser_1;
1213
+ /**
1214
+ * 用于解析 HTML,并把 HTML 内容转换为 Textbus 可以支持的组件或插槽数据
1215
+ */
1200
1216
  let Parser = Parser_1 = class Parser {
1201
1217
  static parseHTML(html) {
1202
1218
  return new DOMParser().parseFromString(html, 'text/html').body;
@@ -1222,12 +1238,22 @@ let Parser = Parser_1 = class Parser {
1222
1238
  this.formatLoaders = formatLoaders;
1223
1239
  this.attributeLoaders = attributeLoaders;
1224
1240
  }
1241
+ /**
1242
+ * 使用指定的组件加载器解析一段 HTML 字符串
1243
+ * @param html
1244
+ * @param rootComponentLoader
1245
+ */
1225
1246
  parseDoc(html, rootComponentLoader) {
1226
1247
  const element = Parser_1.parseHTML(html);
1227
1248
  return rootComponentLoader.read(element, this.injector, (childSlot, slotRootElement, slotContentHostElement = slotRootElement) => {
1228
1249
  return this.readSlot(childSlot, slotRootElement, slotContentHostElement);
1229
1250
  });
1230
1251
  }
1252
+ /**
1253
+ * 将一段 HTML 解析到指定插槽
1254
+ * @param html
1255
+ * @param rootSlot
1256
+ */
1231
1257
  parse(html, rootSlot) {
1232
1258
  const element = Parser_1.parseHTML(html);
1233
1259
  return this.readFormats(element, rootSlot);
@@ -1268,9 +1294,11 @@ let Parser = Parser_1 = class Parser {
1268
1294
  return f.read(el);
1269
1295
  });
1270
1296
  const startIndex = slot.index;
1271
- Array.from(el.childNodes).forEach(child => {
1272
- this.readComponent(child, slot);
1273
- });
1297
+ let startNode = el.firstChild;
1298
+ while (startNode) {
1299
+ this.readComponent(startNode, slot);
1300
+ startNode = startNode.nextSibling;
1301
+ }
1274
1302
  const endIndex = slot.index;
1275
1303
  this.applyFormats(slot, formats.map(i => {
1276
1304
  return {
@@ -1513,7 +1541,7 @@ class ExperimentalCaret {
1513
1541
  else {
1514
1542
  height = parseFloat(fontSize) * parseFloat(lineHeight);
1515
1543
  }
1516
- const boxHeight = Math.floor(Math.max(height, rect.height));
1544
+ const boxHeight = Math.max(Math.floor(Math.max(height, rect.height)), 12);
1517
1545
  // const boxHeight = Math.floor(height)
1518
1546
  let rectTop = rect.top;
1519
1547
  if (rect.height < height) {
@@ -2328,12 +2356,16 @@ NativeInput = __decorate([
2328
2356
 
2329
2357
  var OutputTranslator_1;
2330
2358
  /**
2331
- * HTML 输出转换器
2359
+ * HTML 输出转换器,用于将虚拟 DOM 转换为 HTML 字符串
2332
2360
  */
2333
2361
  let OutputTranslator = OutputTranslator_1 = class OutputTranslator {
2334
2362
  constructor() {
2335
2363
  this.singleTagTest = new RegExp(`^(${OutputTranslator_1.singleTags.join('|')})$`, 'i');
2336
2364
  }
2365
+ /**
2366
+ * 将虚拟 DOM 转换为 HTML 字符串的方法
2367
+ * @param vDom 虚拟 DOM 节点
2368
+ */
2337
2369
  transform(vDom) {
2338
2370
  return vDom.children.map(child => {
2339
2371
  return this.vDomToHTMLString(child);
package/bundles/index.js CHANGED
@@ -737,8 +737,14 @@ exports.SelectionBridge = __decorate([
737
737
  core.Renderer])
738
738
  ], exports.SelectionBridge);
739
739
 
740
+ /**
741
+ * 远程光标绘制范围计算代理类,可用于定制特定场景下的远程选区绘制,如表格有选区,不会遵守常见的文档流形式
742
+ */
740
743
  class CollaborateSelectionAwarenessDelegate {
741
744
  }
745
+ /**
746
+ * 协作光标绘制类
747
+ */
742
748
  exports.CollaborateCursor = class CollaborateCursor {
743
749
  constructor(injector, nativeSelection, scheduler, selection, awarenessDelegate) {
744
750
  this.injector = injector;
@@ -813,12 +819,19 @@ exports.CollaborateCursor = class CollaborateCursor {
813
819
  this.refresh();
814
820
  }));
815
821
  }
822
+ /**
823
+ * 刷新协作光标,由于 Textbus 只会绘制可视区域的光标,当可视区域发生变化时,需要重新绘制
824
+ */
816
825
  refresh() {
817
826
  this.draw(this.currentSelection);
818
827
  }
819
828
  destroy() {
820
829
  this.subscription.unsubscribe();
821
830
  }
831
+ /**
832
+ * 根据远程用户光标位置,绘制协作光标
833
+ * @param paths
834
+ */
822
835
  draw(paths) {
823
836
  this.currentSelection = paths;
824
837
  const containerRect = this.container.getBoundingClientRect();
@@ -1199,6 +1212,9 @@ exports.DomRenderer = DomRenderer_1 = __decorate([
1199
1212
  ], exports.DomRenderer);
1200
1213
 
1201
1214
  var Parser_1;
1215
+ /**
1216
+ * 用于解析 HTML,并把 HTML 内容转换为 Textbus 可以支持的组件或插槽数据
1217
+ */
1202
1218
  exports.Parser = Parser_1 = class Parser {
1203
1219
  static parseHTML(html) {
1204
1220
  return new DOMParser().parseFromString(html, 'text/html').body;
@@ -1224,12 +1240,22 @@ exports.Parser = Parser_1 = class Parser {
1224
1240
  this.formatLoaders = formatLoaders;
1225
1241
  this.attributeLoaders = attributeLoaders;
1226
1242
  }
1243
+ /**
1244
+ * 使用指定的组件加载器解析一段 HTML 字符串
1245
+ * @param html
1246
+ * @param rootComponentLoader
1247
+ */
1227
1248
  parseDoc(html, rootComponentLoader) {
1228
1249
  const element = Parser_1.parseHTML(html);
1229
1250
  return rootComponentLoader.read(element, this.injector, (childSlot, slotRootElement, slotContentHostElement = slotRootElement) => {
1230
1251
  return this.readSlot(childSlot, slotRootElement, slotContentHostElement);
1231
1252
  });
1232
1253
  }
1254
+ /**
1255
+ * 将一段 HTML 解析到指定插槽
1256
+ * @param html
1257
+ * @param rootSlot
1258
+ */
1233
1259
  parse(html, rootSlot) {
1234
1260
  const element = Parser_1.parseHTML(html);
1235
1261
  return this.readFormats(element, rootSlot);
@@ -1270,9 +1296,11 @@ exports.Parser = Parser_1 = class Parser {
1270
1296
  return f.read(el);
1271
1297
  });
1272
1298
  const startIndex = slot.index;
1273
- Array.from(el.childNodes).forEach(child => {
1274
- this.readComponent(child, slot);
1275
- });
1299
+ let startNode = el.firstChild;
1300
+ while (startNode) {
1301
+ this.readComponent(startNode, slot);
1302
+ startNode = startNode.nextSibling;
1303
+ }
1276
1304
  const endIndex = slot.index;
1277
1305
  this.applyFormats(slot, formats.map(i => {
1278
1306
  return {
@@ -1515,7 +1543,7 @@ class ExperimentalCaret {
1515
1543
  else {
1516
1544
  height = parseFloat(fontSize) * parseFloat(lineHeight);
1517
1545
  }
1518
- const boxHeight = Math.floor(Math.max(height, rect.height));
1546
+ const boxHeight = Math.max(Math.floor(Math.max(height, rect.height)), 12);
1519
1547
  // const boxHeight = Math.floor(height)
1520
1548
  let rectTop = rect.top;
1521
1549
  if (rect.height < height) {
@@ -2330,12 +2358,16 @@ exports.NativeInput = __decorate([
2330
2358
 
2331
2359
  var OutputTranslator_1;
2332
2360
  /**
2333
- * HTML 输出转换器
2361
+ * HTML 输出转换器,用于将虚拟 DOM 转换为 HTML 字符串
2334
2362
  */
2335
2363
  exports.OutputTranslator = OutputTranslator_1 = class OutputTranslator {
2336
2364
  constructor() {
2337
2365
  this.singleTagTest = new RegExp(`^(${OutputTranslator_1.singleTags.join('|')})$`, 'i');
2338
2366
  }
2367
+ /**
2368
+ * 将虚拟 DOM 转换为 HTML 字符串的方法
2369
+ * @param vDom 虚拟 DOM 节点
2370
+ */
2339
2371
  transform(vDom) {
2340
2372
  return vDom.children.map(child => {
2341
2373
  return this.vDomToHTMLString(child);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.3.2",
3
+ "version": "3.3.4",
4
4
  "description": "Textbus is a rich text editor and framework that is highly customizable and extensible to achieve rich wysiwyg effects.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@tanbo/di": "^1.1.4",
29
29
  "@tanbo/stream": "^1.1.9",
30
- "@textbus/core": "^3.3.2",
30
+ "@textbus/core": "^3.3.4",
31
31
  "reflect-metadata": "^0.1.13"
32
32
  },
33
33
  "devDependencies": {
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/textbus/textbus.git/issues"
50
50
  },
51
- "gitHead": "fc7c6a727bb3c1a9c24b6a8be683f09b1b18e0a8"
51
+ "gitHead": "38e3a1379ed4d6f9c85790613255cd8c6f9f89b9"
52
52
  }