@textbus/platform-browser 3.0.0-alpha.51 → 3.0.0-alpha.52

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.
@@ -1,5 +1,5 @@
1
1
  import { Injector } from '@tanbo/di';
2
- import { Selection, SelectionPaths, AbstractSelection, Renderer } from '@textbus/core';
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
5
  export interface RemoteSelection {
@@ -24,7 +24,7 @@ export declare abstract class CollaborateSelectionAwarenessDelegate {
24
24
  export declare class CollaborateCursor {
25
25
  private injector;
26
26
  private nativeSelection;
27
- private renderer;
27
+ private scheduler;
28
28
  private selection;
29
29
  private awarenessDelegate?;
30
30
  private host;
@@ -36,7 +36,7 @@ export declare class CollaborateCursor {
36
36
  private subscription;
37
37
  private currentSelection;
38
38
  private container;
39
- constructor(injector: Injector, nativeSelection: SelectionBridge, renderer: Renderer, selection: Selection, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
39
+ constructor(injector: Injector, nativeSelection: SelectionBridge, scheduler: Scheduler, selection: Selection, awarenessDelegate?: CollaborateSelectionAwarenessDelegate | undefined);
40
40
  refresh(): void;
41
41
  destroy(): void;
42
42
  draw(paths: RemoteSelection[]): void;
@@ -10,6 +10,7 @@ interface CaretStyle {
10
10
  }
11
11
  interface CompositionState {
12
12
  slot: Slot;
13
+ index: number;
13
14
  data: string;
14
15
  }
15
16
  declare class ExperimentalCaret implements Caret {
@@ -20,6 +21,7 @@ declare class ExperimentalCaret implements Caret {
20
21
  elementRef: HTMLElement;
21
22
  compositionState: CompositionState | null;
22
23
  get rect(): DOMRect;
24
+ compositionElement: HTMLElement;
23
25
  private timer;
24
26
  private caret;
25
27
  private oldPosition;
@@ -32,7 +34,6 @@ declare class ExperimentalCaret implements Caret {
32
34
  private styleChangeEvent;
33
35
  private oldRange;
34
36
  private isFixed;
35
- private compositionElement;
36
37
  constructor(scheduler: Scheduler, editorMask: HTMLElement);
37
38
  refresh(isFixedCaret?: boolean): void;
38
39
  show(range: Range, restart: boolean): void;
@@ -1,6 +1,6 @@
1
1
  import 'reflect-metadata';
2
2
  import { InjectionToken, Injectable, Inject, Injector, Optional } from '@tanbo/di';
3
- import { VTextNode, VElement, Controller, Selection, RootComponentRef, Renderer, Slot, ContentType, Keyboard, Commander, Scheduler, makeError, Starter, NativeRenderer, NativeSelectionBridge, OutputRenderer, Registry, invokeListener, History } from '@textbus/core';
3
+ import { VTextNode, VElement, Controller, Selection, RootComponentRef, Renderer, Scheduler, Slot, ContentType, Keyboard, Commander, makeError, Starter, NativeRenderer, NativeSelectionBridge, OutputRenderer, Registry, invokeListener, History } from '@textbus/core';
4
4
  import { Subject, filter, fromEvent, Subscription, merge, map, Observable, distinctUntilChanged } from '@tanbo/stream';
5
5
 
6
6
  function createElement(tagName, options = {}) {
@@ -59,8 +59,8 @@ function getLayoutRectByRange(range) {
59
59
  }
60
60
  else if (beforeNode.nodeType === Node.TEXT_NODE) {
61
61
  const range2 = document.createRange();
62
- range2.selectNodeContents(beforeNode);
63
- range2.collapse();
62
+ range2.setStart(beforeNode, beforeNode.textContent.length);
63
+ range2.setEnd(beforeNode, beforeNode.textContent.length);
64
64
  return range2.getBoundingClientRect();
65
65
  }
66
66
  }
@@ -776,10 +776,10 @@ SelectionBridge = __decorate([
776
776
  class CollaborateSelectionAwarenessDelegate {
777
777
  }
778
778
  let CollaborateCursor = class CollaborateCursor {
779
- constructor(injector, nativeSelection, renderer, selection, awarenessDelegate) {
779
+ constructor(injector, nativeSelection, scheduler, selection, awarenessDelegate) {
780
780
  this.injector = injector;
781
781
  this.nativeSelection = nativeSelection;
782
- this.renderer = renderer;
782
+ this.scheduler = scheduler;
783
783
  this.selection = selection;
784
784
  this.awarenessDelegate = awarenessDelegate;
785
785
  this.host = createElement('div', {
@@ -845,7 +845,7 @@ let CollaborateCursor = class CollaborateCursor {
845
845
  }), fromEvent(window, 'resize').subscribe(() => {
846
846
  this.canvas.style.height = document.documentElement.clientHeight + 'px';
847
847
  this.refresh();
848
- }), this.renderer.onViewUpdated.subscribe(() => {
848
+ }), this.scheduler.onDocChanged.subscribe(() => {
849
849
  this.refresh();
850
850
  }));
851
851
  }
@@ -1017,7 +1017,7 @@ CollaborateCursor = __decorate([
1017
1017
  __param(4, Optional()),
1018
1018
  __metadata("design:paramtypes", [Injector,
1019
1019
  SelectionBridge,
1020
- Renderer,
1020
+ Scheduler,
1021
1021
  Selection,
1022
1022
  CollaborateSelectionAwarenessDelegate])
1023
1023
  ], CollaborateCursor);
@@ -1328,24 +1328,24 @@ Parser = Parser_1 = __decorate([
1328
1328
  __metadata("design:paramtypes", [Object, Injector])
1329
1329
  ], Parser);
1330
1330
 
1331
- const iframeHTML = `
1332
- <!DOCTYPE html>
1333
- <html>
1334
- <head>
1335
- <meta charset="UTF-8">
1336
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
1337
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
1338
- <title>Textbus</title>
1339
- <style>
1340
- html {position: fixed; left:0; overflow: hidden}
1341
- html, body{height: 100%;width:100%}
1342
- body{margin:0; overflow: hidden}
1343
- textarea{width: 2000px;height: 100%;opacity: 0; padding: 0; outline: none; border: none; position: absolute; left:0; top:0;}
1344
- </style>
1345
- </head>
1346
- <body>
1347
- </body>
1348
- </html>
1331
+ const iframeHTML = `
1332
+ <!DOCTYPE html>
1333
+ <html>
1334
+ <head>
1335
+ <meta charset="UTF-8">
1336
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
1337
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
1338
+ <title>Textbus</title>
1339
+ <style>
1340
+ html {position: fixed; left:0; overflow: hidden}
1341
+ html, body{height: 100%;width:100%}
1342
+ body{margin:0; overflow: hidden}
1343
+ textarea{width: 2000px;height: 100%;opacity: 0; padding: 0; outline: none; border: none; position: absolute; left:0; top:0;}
1344
+ </style>
1345
+ </head>
1346
+ <body>
1347
+ </body>
1348
+ </html>
1349
1349
  `;
1350
1350
  class ExperimentalCaret {
1351
1351
  get rect() {
@@ -1362,6 +1362,11 @@ class ExperimentalCaret {
1362
1362
  this.scheduler = scheduler;
1363
1363
  this.editorMask = editorMask;
1364
1364
  this.compositionState = null;
1365
+ this.compositionElement = createElement('span', {
1366
+ styles: {
1367
+ textDecoration: 'underline'
1368
+ }
1369
+ });
1365
1370
  this.timer = null;
1366
1371
  this.oldPosition = null;
1367
1372
  this._display = true;
@@ -1371,11 +1376,6 @@ class ExperimentalCaret {
1371
1376
  this.styleChangeEvent = new Subject();
1372
1377
  this.oldRange = null;
1373
1378
  this.isFixed = false;
1374
- this.compositionElement = createElement('span', {
1375
- styles: {
1376
- textDecoration: 'underline'
1377
- }
1378
- });
1379
1379
  this.onPositionChange = this.positionChangeEvent.pipe(distinctUntilChanged());
1380
1380
  this.onStyleChange = this.styleChangeEvent.asObservable();
1381
1381
  this.elementRef = createElement('div', {
@@ -1767,19 +1767,24 @@ let MagicInput = class MagicInput extends Input {
1767
1767
  }));
1768
1768
  }
1769
1769
  handleInput(textarea) {
1770
- this.subscription.add(fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1770
+ let startIndex = 0;
1771
+ this.subscription.add(fromEvent(textarea, 'compositionstart').subscribe(() => {
1772
+ startIndex = this.selection.startOffset;
1773
+ }), fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1771
1774
  if (ev.data === ' ') {
1772
1775
  // 处理搜狗五笔不符合 composition 事件预期,会意外跳光标的问题
1773
1776
  return;
1774
1777
  }
1775
- const slot = this.selection.startSlot;
1776
1778
  this.caret.compositionState = {
1777
- slot,
1779
+ slot: this.selection.startSlot,
1780
+ index: startIndex,
1778
1781
  data: ev.data
1779
1782
  };
1780
- slot.changeMarker.forceMarkDirtied();
1783
+ this.caret.refresh(true);
1781
1784
  }), fromEvent(textarea, 'compositionend').subscribe(() => {
1785
+ var _a;
1782
1786
  this.caret.compositionState = null;
1787
+ (_a = this.caret.compositionElement.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this.caret.compositionElement);
1783
1788
  }));
1784
1789
  this.subscription.add(merge(fromEvent(textarea, 'beforeinput').pipe(filter(ev => {
1785
1790
  ev.preventDefault();
package/bundles/index.js CHANGED
@@ -61,8 +61,8 @@ function getLayoutRectByRange(range) {
61
61
  }
62
62
  else if (beforeNode.nodeType === Node.TEXT_NODE) {
63
63
  const range2 = document.createRange();
64
- range2.selectNodeContents(beforeNode);
65
- range2.collapse();
64
+ range2.setStart(beforeNode, beforeNode.textContent.length);
65
+ range2.setEnd(beforeNode, beforeNode.textContent.length);
66
66
  return range2.getBoundingClientRect();
67
67
  }
68
68
  }
@@ -778,10 +778,10 @@ exports.SelectionBridge = __decorate([
778
778
  class CollaborateSelectionAwarenessDelegate {
779
779
  }
780
780
  exports.CollaborateCursor = class CollaborateCursor {
781
- constructor(injector, nativeSelection, renderer, selection, awarenessDelegate) {
781
+ constructor(injector, nativeSelection, scheduler, selection, awarenessDelegate) {
782
782
  this.injector = injector;
783
783
  this.nativeSelection = nativeSelection;
784
- this.renderer = renderer;
784
+ this.scheduler = scheduler;
785
785
  this.selection = selection;
786
786
  this.awarenessDelegate = awarenessDelegate;
787
787
  this.host = createElement('div', {
@@ -847,7 +847,7 @@ exports.CollaborateCursor = class CollaborateCursor {
847
847
  }), stream.fromEvent(window, 'resize').subscribe(() => {
848
848
  this.canvas.style.height = document.documentElement.clientHeight + 'px';
849
849
  this.refresh();
850
- }), this.renderer.onViewUpdated.subscribe(() => {
850
+ }), this.scheduler.onDocChanged.subscribe(() => {
851
851
  this.refresh();
852
852
  }));
853
853
  }
@@ -1019,7 +1019,7 @@ exports.CollaborateCursor = __decorate([
1019
1019
  __param(4, di.Optional()),
1020
1020
  __metadata("design:paramtypes", [di.Injector,
1021
1021
  exports.SelectionBridge,
1022
- core.Renderer,
1022
+ core.Scheduler,
1023
1023
  core.Selection,
1024
1024
  CollaborateSelectionAwarenessDelegate])
1025
1025
  ], exports.CollaborateCursor);
@@ -1330,24 +1330,24 @@ exports.Parser = Parser_1 = __decorate([
1330
1330
  __metadata("design:paramtypes", [Object, di.Injector])
1331
1331
  ], exports.Parser);
1332
1332
 
1333
- const iframeHTML = `
1334
- <!DOCTYPE html>
1335
- <html>
1336
- <head>
1337
- <meta charset="UTF-8">
1338
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
1339
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
1340
- <title>Textbus</title>
1341
- <style>
1342
- html {position: fixed; left:0; overflow: hidden}
1343
- html, body{height: 100%;width:100%}
1344
- body{margin:0; overflow: hidden}
1345
- textarea{width: 2000px;height: 100%;opacity: 0; padding: 0; outline: none; border: none; position: absolute; left:0; top:0;}
1346
- </style>
1347
- </head>
1348
- <body>
1349
- </body>
1350
- </html>
1333
+ const iframeHTML = `
1334
+ <!DOCTYPE html>
1335
+ <html>
1336
+ <head>
1337
+ <meta charset="UTF-8">
1338
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
1339
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
1340
+ <title>Textbus</title>
1341
+ <style>
1342
+ html {position: fixed; left:0; overflow: hidden}
1343
+ html, body{height: 100%;width:100%}
1344
+ body{margin:0; overflow: hidden}
1345
+ textarea{width: 2000px;height: 100%;opacity: 0; padding: 0; outline: none; border: none; position: absolute; left:0; top:0;}
1346
+ </style>
1347
+ </head>
1348
+ <body>
1349
+ </body>
1350
+ </html>
1351
1351
  `;
1352
1352
  class ExperimentalCaret {
1353
1353
  get rect() {
@@ -1364,6 +1364,11 @@ class ExperimentalCaret {
1364
1364
  this.scheduler = scheduler;
1365
1365
  this.editorMask = editorMask;
1366
1366
  this.compositionState = null;
1367
+ this.compositionElement = createElement('span', {
1368
+ styles: {
1369
+ textDecoration: 'underline'
1370
+ }
1371
+ });
1367
1372
  this.timer = null;
1368
1373
  this.oldPosition = null;
1369
1374
  this._display = true;
@@ -1373,11 +1378,6 @@ class ExperimentalCaret {
1373
1378
  this.styleChangeEvent = new stream.Subject();
1374
1379
  this.oldRange = null;
1375
1380
  this.isFixed = false;
1376
- this.compositionElement = createElement('span', {
1377
- styles: {
1378
- textDecoration: 'underline'
1379
- }
1380
- });
1381
1381
  this.onPositionChange = this.positionChangeEvent.pipe(stream.distinctUntilChanged());
1382
1382
  this.onStyleChange = this.styleChangeEvent.asObservable();
1383
1383
  this.elementRef = createElement('div', {
@@ -1769,19 +1769,24 @@ exports.MagicInput = class MagicInput extends Input {
1769
1769
  }));
1770
1770
  }
1771
1771
  handleInput(textarea) {
1772
- this.subscription.add(stream.fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1772
+ let startIndex = 0;
1773
+ this.subscription.add(stream.fromEvent(textarea, 'compositionstart').subscribe(() => {
1774
+ startIndex = this.selection.startOffset;
1775
+ }), stream.fromEvent(textarea, 'compositionupdate').subscribe(ev => {
1773
1776
  if (ev.data === ' ') {
1774
1777
  // 处理搜狗五笔不符合 composition 事件预期,会意外跳光标的问题
1775
1778
  return;
1776
1779
  }
1777
- const slot = this.selection.startSlot;
1778
1780
  this.caret.compositionState = {
1779
- slot,
1781
+ slot: this.selection.startSlot,
1782
+ index: startIndex,
1780
1783
  data: ev.data
1781
1784
  };
1782
- slot.changeMarker.forceMarkDirtied();
1785
+ this.caret.refresh(true);
1783
1786
  }), stream.fromEvent(textarea, 'compositionend').subscribe(() => {
1787
+ var _a;
1784
1788
  this.caret.compositionState = null;
1789
+ (_a = this.caret.compositionElement.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(this.caret.compositionElement);
1785
1790
  }));
1786
1791
  this.subscription.add(stream.merge(stream.fromEvent(textarea, 'beforeinput').pipe(stream.filter(ev => {
1787
1792
  ev.preventDefault();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/platform-browser",
3
- "version": "3.0.0-alpha.51",
3
+ "version": "3.0.0-alpha.52",
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.0.0-alpha.51",
30
+ "@textbus/core": "^3.0.0-alpha.50",
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": "4f2557bae5aa8800130c827f502d4439bddb1ff4"
51
+ "gitHead": "4c64b9a00d2a4e87ad7bfdc9502b8a70ed1dc39a"
52
52
  }