@textbus/platform-browser 3.0.0-alpha.49 → 3.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/bundles/core/magic-input.d.ts +11 -4
- package/bundles/index.esm.js +33 -6
- package/bundles/index.js +33 -6
- package/package.json +3 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Observable } from '@tanbo/stream';
|
2
2
|
import { Injector } from '@tanbo/di';
|
3
|
-
import { Commander, Controller, Keyboard, Scheduler, Selection } from '@textbus/core';
|
3
|
+
import { Commander, Controller, Keyboard, Scheduler, Selection, Slot } from '@textbus/core';
|
4
4
|
import { Parser } from '../dom-support/parser';
|
5
5
|
import { Caret, CaretPosition, Input, Scroller } from './types';
|
6
6
|
interface CaretStyle {
|
@@ -8,12 +8,18 @@ interface CaretStyle {
|
|
8
8
|
lineHeight: string;
|
9
9
|
fontSize: string;
|
10
10
|
}
|
11
|
+
interface CompositionState {
|
12
|
+
slot: Slot;
|
13
|
+
index: number;
|
14
|
+
data: string;
|
15
|
+
}
|
11
16
|
declare class ExperimentalCaret implements Caret {
|
12
17
|
private scheduler;
|
13
18
|
private editorMask;
|
14
19
|
onPositionChange: Observable<CaretPosition | null>;
|
15
20
|
onStyleChange: Observable<CaretStyle>;
|
16
21
|
elementRef: HTMLElement;
|
22
|
+
compositionState: CompositionState | null;
|
17
23
|
get rect(): DOMRect;
|
18
24
|
private timer;
|
19
25
|
private caret;
|
@@ -27,6 +33,7 @@ declare class ExperimentalCaret implements Caret {
|
|
27
33
|
private styleChangeEvent;
|
28
34
|
private oldRange;
|
29
35
|
private isFixed;
|
36
|
+
private compositionElement;
|
30
37
|
constructor(scheduler: Scheduler, editorMask: HTMLElement);
|
31
38
|
refresh(isFixedCaret?: boolean): void;
|
32
39
|
show(range: Range, restart: boolean): void;
|
@@ -51,6 +58,9 @@ export declare class MagicInput extends Input {
|
|
51
58
|
caret: ExperimentalCaret;
|
52
59
|
set disabled(b: boolean);
|
53
60
|
get disabled(): boolean;
|
61
|
+
private isSafari;
|
62
|
+
private isMac;
|
63
|
+
private isWindows;
|
54
64
|
private _disabled;
|
55
65
|
private container;
|
56
66
|
private subscription;
|
@@ -58,9 +68,6 @@ export declare class MagicInput extends Input {
|
|
58
68
|
private textarea;
|
59
69
|
private isFocus;
|
60
70
|
private nativeFocus;
|
61
|
-
private isSafari;
|
62
|
-
private isMac;
|
63
|
-
private isWindows;
|
64
71
|
private isSougouPinYin;
|
65
72
|
constructor(parser: Parser, keyboard: Keyboard, commander: Commander, selection: Selection, controller: Controller, scheduler: Scheduler, injector: Injector);
|
66
73
|
focus(range: Range, restart: boolean): void;
|
package/bundles/index.esm.js
CHANGED
@@ -1361,6 +1361,7 @@ class ExperimentalCaret {
|
|
1361
1361
|
constructor(scheduler, editorMask) {
|
1362
1362
|
this.scheduler = scheduler;
|
1363
1363
|
this.editorMask = editorMask;
|
1364
|
+
this.compositionState = null;
|
1364
1365
|
this.timer = null;
|
1365
1366
|
this.oldPosition = null;
|
1366
1367
|
this._display = true;
|
@@ -1370,6 +1371,11 @@ class ExperimentalCaret {
|
|
1370
1371
|
this.styleChangeEvent = new Subject();
|
1371
1372
|
this.oldRange = null;
|
1372
1373
|
this.isFixed = false;
|
1374
|
+
this.compositionElement = createElement('span', {
|
1375
|
+
styles: {
|
1376
|
+
textDecoration: 'underline'
|
1377
|
+
}
|
1378
|
+
});
|
1373
1379
|
this.onPositionChange = this.positionChangeEvent.pipe(distinctUntilChanged());
|
1374
1380
|
this.onStyleChange = this.styleChangeEvent.asObservable();
|
1375
1381
|
this.elementRef = createElement('div', {
|
@@ -1502,6 +1508,14 @@ class ExperimentalCaret {
|
|
1502
1508
|
this.positionChangeEvent.next(null);
|
1503
1509
|
return;
|
1504
1510
|
}
|
1511
|
+
if (this.compositionState) {
|
1512
|
+
const compositionElement = this.compositionElement;
|
1513
|
+
compositionElement.innerText = this.compositionState.data;
|
1514
|
+
nativeRange = nativeRange.cloneRange();
|
1515
|
+
nativeRange.insertNode(compositionElement);
|
1516
|
+
nativeRange.selectNodeContents(compositionElement);
|
1517
|
+
nativeRange.collapse();
|
1518
|
+
}
|
1505
1519
|
const rect = getLayoutRectByRange(nativeRange);
|
1506
1520
|
const { fontSize, lineHeight, color } = getComputedStyle(node);
|
1507
1521
|
let height;
|
@@ -1571,15 +1585,15 @@ let MagicInput = class MagicInput extends Input {
|
|
1571
1585
|
this.injector = injector;
|
1572
1586
|
this.composition = false;
|
1573
1587
|
this.caret = new ExperimentalCaret(this.scheduler, this.injector.get(VIEW_MASK));
|
1588
|
+
this.isSafari = isSafari();
|
1589
|
+
this.isMac = isMac();
|
1590
|
+
this.isWindows = isWindows();
|
1574
1591
|
this._disabled = false;
|
1575
1592
|
this.container = this.createEditableFrame();
|
1576
1593
|
this.subscription = new Subscription();
|
1577
1594
|
this.textarea = null;
|
1578
1595
|
this.isFocus = false;
|
1579
1596
|
this.nativeFocus = false;
|
1580
|
-
this.isSafari = isSafari();
|
1581
|
-
this.isMac = isMac();
|
1582
|
-
this.isWindows = isWindows();
|
1583
1597
|
this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
|
1584
1598
|
this.onReady = new Promise(resolve => {
|
1585
1599
|
this.subscription.add(fromEvent(this.container, 'load').subscribe(() => {
|
@@ -1753,6 +1767,19 @@ let MagicInput = class MagicInput extends Input {
|
|
1753
1767
|
}));
|
1754
1768
|
}
|
1755
1769
|
handleInput(textarea) {
|
1770
|
+
let startIndex = 0;
|
1771
|
+
this.subscription.add(fromEvent(textarea, 'compositionstart').subscribe(() => {
|
1772
|
+
startIndex = this.selection.startOffset;
|
1773
|
+
}), fromEvent(textarea, 'compositionupdate').subscribe(ev => {
|
1774
|
+
this.caret.compositionState = {
|
1775
|
+
slot: this.selection.startSlot,
|
1776
|
+
index: startIndex,
|
1777
|
+
data: ev.data
|
1778
|
+
};
|
1779
|
+
this.caret.refresh(true);
|
1780
|
+
}), fromEvent(textarea, 'compositionend').subscribe(() => {
|
1781
|
+
this.caret.compositionState = null;
|
1782
|
+
}));
|
1756
1783
|
this.subscription.add(merge(fromEvent(textarea, 'beforeinput').pipe(filter(ev => {
|
1757
1784
|
ev.preventDefault();
|
1758
1785
|
if (this.isSafari) {
|
@@ -1786,7 +1813,7 @@ let MagicInput = class MagicInput extends Input {
|
|
1786
1813
|
display: 'block',
|
1787
1814
|
height: '100%',
|
1788
1815
|
position: 'relative',
|
1789
|
-
top: this.isWindows ? '
|
1816
|
+
top: this.isWindows ? '3px' : '0'
|
1790
1817
|
}
|
1791
1818
|
});
|
1792
1819
|
}
|
@@ -1908,7 +1935,7 @@ let NativeInput = class NativeInput extends Input {
|
|
1908
1935
|
set disabled(b) {
|
1909
1936
|
this._disabled = b;
|
1910
1937
|
if (b && !this.controller.readonly) {
|
1911
|
-
this.documentView.contentEditable = b ? '
|
1938
|
+
this.documentView.contentEditable = b ? 'false' : 'true';
|
1912
1939
|
}
|
1913
1940
|
}
|
1914
1941
|
get disabled() {
|
@@ -2609,7 +2636,7 @@ class Viewer extends Starter {
|
|
2609
2636
|
});
|
2610
2637
|
const styleEl = document.createElement('style');
|
2611
2638
|
docStyles.push(...(options.styleSheets || []));
|
2612
|
-
editModeStyles.push(`#${this.id} *::selection{background-color: rgba(18, 150, 219, .
|
2639
|
+
editModeStyles.push(`#${this.id} *::selection{background-color: rgba(18, 150, 219, .4); color:inherit}`, ...(options.editingStyleSheets || []));
|
2613
2640
|
this.styleSheet = Viewer.cssMin(docStyles.join(''));
|
2614
2641
|
styleEl.innerHTML = this.styleSheet + Viewer.cssMin(editModeStyles.join(''));
|
2615
2642
|
this.resourceNodes.push(styleEl);
|
package/bundles/index.js
CHANGED
@@ -1363,6 +1363,7 @@ class ExperimentalCaret {
|
|
1363
1363
|
constructor(scheduler, editorMask) {
|
1364
1364
|
this.scheduler = scheduler;
|
1365
1365
|
this.editorMask = editorMask;
|
1366
|
+
this.compositionState = null;
|
1366
1367
|
this.timer = null;
|
1367
1368
|
this.oldPosition = null;
|
1368
1369
|
this._display = true;
|
@@ -1372,6 +1373,11 @@ class ExperimentalCaret {
|
|
1372
1373
|
this.styleChangeEvent = new stream.Subject();
|
1373
1374
|
this.oldRange = null;
|
1374
1375
|
this.isFixed = false;
|
1376
|
+
this.compositionElement = createElement('span', {
|
1377
|
+
styles: {
|
1378
|
+
textDecoration: 'underline'
|
1379
|
+
}
|
1380
|
+
});
|
1375
1381
|
this.onPositionChange = this.positionChangeEvent.pipe(stream.distinctUntilChanged());
|
1376
1382
|
this.onStyleChange = this.styleChangeEvent.asObservable();
|
1377
1383
|
this.elementRef = createElement('div', {
|
@@ -1504,6 +1510,14 @@ class ExperimentalCaret {
|
|
1504
1510
|
this.positionChangeEvent.next(null);
|
1505
1511
|
return;
|
1506
1512
|
}
|
1513
|
+
if (this.compositionState) {
|
1514
|
+
const compositionElement = this.compositionElement;
|
1515
|
+
compositionElement.innerText = this.compositionState.data;
|
1516
|
+
nativeRange = nativeRange.cloneRange();
|
1517
|
+
nativeRange.insertNode(compositionElement);
|
1518
|
+
nativeRange.selectNodeContents(compositionElement);
|
1519
|
+
nativeRange.collapse();
|
1520
|
+
}
|
1507
1521
|
const rect = getLayoutRectByRange(nativeRange);
|
1508
1522
|
const { fontSize, lineHeight, color } = getComputedStyle(node);
|
1509
1523
|
let height;
|
@@ -1573,15 +1587,15 @@ exports.MagicInput = class MagicInput extends Input {
|
|
1573
1587
|
this.injector = injector;
|
1574
1588
|
this.composition = false;
|
1575
1589
|
this.caret = new ExperimentalCaret(this.scheduler, this.injector.get(VIEW_MASK));
|
1590
|
+
this.isSafari = isSafari();
|
1591
|
+
this.isMac = isMac();
|
1592
|
+
this.isWindows = isWindows();
|
1576
1593
|
this._disabled = false;
|
1577
1594
|
this.container = this.createEditableFrame();
|
1578
1595
|
this.subscription = new stream.Subscription();
|
1579
1596
|
this.textarea = null;
|
1580
1597
|
this.isFocus = false;
|
1581
1598
|
this.nativeFocus = false;
|
1582
|
-
this.isSafari = isSafari();
|
1583
|
-
this.isMac = isMac();
|
1584
|
-
this.isWindows = isWindows();
|
1585
1599
|
this.isSougouPinYin = false; // 有 bug 版本搜狗拼音
|
1586
1600
|
this.onReady = new Promise(resolve => {
|
1587
1601
|
this.subscription.add(stream.fromEvent(this.container, 'load').subscribe(() => {
|
@@ -1755,6 +1769,19 @@ exports.MagicInput = class MagicInput extends Input {
|
|
1755
1769
|
}));
|
1756
1770
|
}
|
1757
1771
|
handleInput(textarea) {
|
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 => {
|
1776
|
+
this.caret.compositionState = {
|
1777
|
+
slot: this.selection.startSlot,
|
1778
|
+
index: startIndex,
|
1779
|
+
data: ev.data
|
1780
|
+
};
|
1781
|
+
this.caret.refresh(true);
|
1782
|
+
}), stream.fromEvent(textarea, 'compositionend').subscribe(() => {
|
1783
|
+
this.caret.compositionState = null;
|
1784
|
+
}));
|
1758
1785
|
this.subscription.add(stream.merge(stream.fromEvent(textarea, 'beforeinput').pipe(stream.filter(ev => {
|
1759
1786
|
ev.preventDefault();
|
1760
1787
|
if (this.isSafari) {
|
@@ -1788,7 +1815,7 @@ exports.MagicInput = class MagicInput extends Input {
|
|
1788
1815
|
display: 'block',
|
1789
1816
|
height: '100%',
|
1790
1817
|
position: 'relative',
|
1791
|
-
top: this.isWindows ? '
|
1818
|
+
top: this.isWindows ? '3px' : '0'
|
1792
1819
|
}
|
1793
1820
|
});
|
1794
1821
|
}
|
@@ -1910,7 +1937,7 @@ exports.NativeInput = class NativeInput extends Input {
|
|
1910
1937
|
set disabled(b) {
|
1911
1938
|
this._disabled = b;
|
1912
1939
|
if (b && !this.controller.readonly) {
|
1913
|
-
this.documentView.contentEditable = b ? '
|
1940
|
+
this.documentView.contentEditable = b ? 'false' : 'true';
|
1914
1941
|
}
|
1915
1942
|
}
|
1916
1943
|
get disabled() {
|
@@ -2611,7 +2638,7 @@ class Viewer extends core.Starter {
|
|
2611
2638
|
});
|
2612
2639
|
const styleEl = document.createElement('style');
|
2613
2640
|
docStyles.push(...(options.styleSheets || []));
|
2614
|
-
editModeStyles.push(`#${this.id} *::selection{background-color: rgba(18, 150, 219, .
|
2641
|
+
editModeStyles.push(`#${this.id} *::selection{background-color: rgba(18, 150, 219, .4); color:inherit}`, ...(options.editingStyleSheets || []));
|
2615
2642
|
this.styleSheet = Viewer.cssMin(docStyles.join(''));
|
2616
2643
|
styleEl.innerHTML = this.styleSheet + Viewer.cssMin(editModeStyles.join(''));
|
2617
2644
|
this.resourceNodes.push(styleEl);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@textbus/platform-browser",
|
3
|
-
"version": "3.0.0-alpha.
|
3
|
+
"version": "3.0.0-alpha.50",
|
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.
|
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": "
|
51
|
+
"gitHead": "ad396a0f17fc18d1eaddd2532f223c1252cf5d6f"
|
52
52
|
}
|