@textbus/platform-browser 5.0.0-alpha.9 → 5.0.0
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/index.esm.js +26 -17
- package/bundles/index.js +26 -17
- package/bundles/selection-bridge.d.ts +1 -1
- package/package.json +4 -4
package/bundles/index.esm.js
CHANGED
|
@@ -50,7 +50,7 @@ function getLayoutRectByRange(range) {
|
|
|
50
50
|
return {
|
|
51
51
|
left: rect.right,
|
|
52
52
|
top: rect.top,
|
|
53
|
-
width: range.collapsed ?
|
|
53
|
+
width: range.collapsed ? 1 : rect.width,
|
|
54
54
|
height: rect.height
|
|
55
55
|
};
|
|
56
56
|
}
|
|
@@ -62,7 +62,7 @@ function getLayoutRectByRange(range) {
|
|
|
62
62
|
return {
|
|
63
63
|
left: rect.right,
|
|
64
64
|
top: rect.top,
|
|
65
|
-
width: range.collapsed ?
|
|
65
|
+
width: range.collapsed ? 1 : rect.width,
|
|
66
66
|
height: rect.height
|
|
67
67
|
};
|
|
68
68
|
}
|
|
@@ -76,7 +76,7 @@ function getLayoutRectByRange(range) {
|
|
|
76
76
|
return {
|
|
77
77
|
left: rect.right,
|
|
78
78
|
top: rect.top,
|
|
79
|
-
width: range.collapsed ?
|
|
79
|
+
width: range.collapsed ? 1 : rect.width,
|
|
80
80
|
height: rect.height
|
|
81
81
|
};
|
|
82
82
|
}
|
|
@@ -87,7 +87,7 @@ function getLayoutRectByRange(range) {
|
|
|
87
87
|
return {
|
|
88
88
|
left: rect.left,
|
|
89
89
|
top: rect.top,
|
|
90
|
-
width: range.collapsed ?
|
|
90
|
+
width: range.collapsed ? 1 : rect.width,
|
|
91
91
|
height: rect.height
|
|
92
92
|
};
|
|
93
93
|
}
|
|
@@ -107,7 +107,7 @@ function getLayoutRectByRange(range) {
|
|
|
107
107
|
return {
|
|
108
108
|
left: rect.left,
|
|
109
109
|
top: rect.top,
|
|
110
|
-
width: range.collapsed ?
|
|
110
|
+
width: range.collapsed ? 1 : rect.width,
|
|
111
111
|
height: rect.height
|
|
112
112
|
};
|
|
113
113
|
}
|
|
@@ -552,8 +552,8 @@ let SelectionBridge = class SelectionBridge {
|
|
|
552
552
|
nativeRange.collapse();
|
|
553
553
|
return getLayoutRectByRange(nativeRange);
|
|
554
554
|
}
|
|
555
|
-
restore(abstractSelection,
|
|
556
|
-
this.changeFromUser =
|
|
555
|
+
restore(abstractSelection, fromLocal) {
|
|
556
|
+
this.changeFromUser = fromLocal;
|
|
557
557
|
if (this.ignoreSelectionChange || !this.connector) {
|
|
558
558
|
return;
|
|
559
559
|
}
|
|
@@ -611,6 +611,10 @@ let SelectionBridge = class SelectionBridge {
|
|
|
611
611
|
this.listen(this.connector);
|
|
612
612
|
}
|
|
613
613
|
};
|
|
614
|
+
if (fromLocal) {
|
|
615
|
+
Promise.resolve().then(bind);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
614
618
|
if (typeof requestIdleCallback === 'function') {
|
|
615
619
|
requestIdleCallback(bind);
|
|
616
620
|
}
|
|
@@ -803,7 +807,7 @@ let SelectionBridge = class SelectionBridge {
|
|
|
803
807
|
isUpdating = true;
|
|
804
808
|
}), this.scheduler.onDocChanged.pipe(delay()).subscribe(() => {
|
|
805
809
|
isUpdating = false;
|
|
806
|
-
}), fromEvent(document, 'selectionchange').
|
|
810
|
+
}), fromEvent(document, 'selectionchange').subscribe(() => {
|
|
807
811
|
if (isUpdating) {
|
|
808
812
|
return;
|
|
809
813
|
}
|
|
@@ -849,7 +853,7 @@ let SelectionBridge = class SelectionBridge {
|
|
|
849
853
|
this.getCorrectedPosition(nativeRange.endContainer, nativeRange.endOffset, isFocusEnd);
|
|
850
854
|
if ([Node.ELEMENT_NODE, Node.TEXT_NODE].includes((_a = nativeRange.commonAncestorContainer) === null || _a === void 0 ? void 0 : _a.nodeType) &&
|
|
851
855
|
startPosition && endPosition) {
|
|
852
|
-
const abstractSelection = isFocusEnd ? {
|
|
856
|
+
const abstractSelection = connector.beforeChange(isFocusEnd ? {
|
|
853
857
|
anchorSlot: startPosition.slot,
|
|
854
858
|
anchorOffset: startPosition.offset,
|
|
855
859
|
focusSlot: endPosition.slot,
|
|
@@ -859,7 +863,12 @@ let SelectionBridge = class SelectionBridge {
|
|
|
859
863
|
focusOffset: startPosition.offset,
|
|
860
864
|
anchorSlot: endPosition.slot,
|
|
861
865
|
anchorOffset: endPosition.offset
|
|
862
|
-
};
|
|
866
|
+
});
|
|
867
|
+
if (!abstractSelection) {
|
|
868
|
+
this.selectionChangeEvent.next(null);
|
|
869
|
+
connector.setSelection(null);
|
|
870
|
+
return;
|
|
871
|
+
}
|
|
863
872
|
const { focus, anchor } = this.getPositionByRange(abstractSelection);
|
|
864
873
|
if (focus && anchor) {
|
|
865
874
|
let start = anchor;
|
|
@@ -1313,17 +1322,17 @@ class ExperimentalCaret {
|
|
|
1313
1322
|
pointEle.style.cssText = 'position: absolute; left: 0; top: 0; width:0;height:0';
|
|
1314
1323
|
hackEle.append(pointEle);
|
|
1315
1324
|
node.append(hackEle);
|
|
1316
|
-
const
|
|
1325
|
+
const p1 = pointEle.getBoundingClientRect();
|
|
1317
1326
|
pointEle.style.right = '0';
|
|
1318
1327
|
pointEle.style.left = '';
|
|
1319
|
-
const
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1328
|
+
const p2 = pointEle.getBoundingClientRect();
|
|
1329
|
+
const x = p1.x - p2.x;
|
|
1330
|
+
const y = p1.y - p2.y;
|
|
1331
|
+
rotate = Math.atan2(y, x) * 180 / Math.PI;
|
|
1323
1332
|
hackEle.remove();
|
|
1324
1333
|
}
|
|
1325
1334
|
}
|
|
1326
|
-
if (
|
|
1335
|
+
if (writingMode === 'vertical-lr' || writingMode === 'vertical-rl') {
|
|
1327
1336
|
rotate += 90;
|
|
1328
1337
|
}
|
|
1329
1338
|
Object.assign(this.elementRef.style, {
|
|
@@ -1334,7 +1343,7 @@ class ExperimentalCaret {
|
|
|
1334
1343
|
fontSize,
|
|
1335
1344
|
transform: `rotate(${rotate}deg)`,
|
|
1336
1345
|
});
|
|
1337
|
-
this.caret.style.backgroundColor = color;
|
|
1346
|
+
this.caret.style.backgroundColor = color === 'rgba(0, 0, 0, 0)' ? '#000' : color;
|
|
1338
1347
|
this.styleChangeEvent.next({
|
|
1339
1348
|
height: boxHeight + 'px',
|
|
1340
1349
|
lineHeight: boxHeight + 'px',
|
package/bundles/index.js
CHANGED
|
@@ -52,7 +52,7 @@ function getLayoutRectByRange(range) {
|
|
|
52
52
|
return {
|
|
53
53
|
left: rect.right,
|
|
54
54
|
top: rect.top,
|
|
55
|
-
width: range.collapsed ?
|
|
55
|
+
width: range.collapsed ? 1 : rect.width,
|
|
56
56
|
height: rect.height
|
|
57
57
|
};
|
|
58
58
|
}
|
|
@@ -64,7 +64,7 @@ function getLayoutRectByRange(range) {
|
|
|
64
64
|
return {
|
|
65
65
|
left: rect.right,
|
|
66
66
|
top: rect.top,
|
|
67
|
-
width: range.collapsed ?
|
|
67
|
+
width: range.collapsed ? 1 : rect.width,
|
|
68
68
|
height: rect.height
|
|
69
69
|
};
|
|
70
70
|
}
|
|
@@ -78,7 +78,7 @@ function getLayoutRectByRange(range) {
|
|
|
78
78
|
return {
|
|
79
79
|
left: rect.right,
|
|
80
80
|
top: rect.top,
|
|
81
|
-
width: range.collapsed ?
|
|
81
|
+
width: range.collapsed ? 1 : rect.width,
|
|
82
82
|
height: rect.height
|
|
83
83
|
};
|
|
84
84
|
}
|
|
@@ -89,7 +89,7 @@ function getLayoutRectByRange(range) {
|
|
|
89
89
|
return {
|
|
90
90
|
left: rect.left,
|
|
91
91
|
top: rect.top,
|
|
92
|
-
width: range.collapsed ?
|
|
92
|
+
width: range.collapsed ? 1 : rect.width,
|
|
93
93
|
height: rect.height
|
|
94
94
|
};
|
|
95
95
|
}
|
|
@@ -109,7 +109,7 @@ function getLayoutRectByRange(range) {
|
|
|
109
109
|
return {
|
|
110
110
|
left: rect.left,
|
|
111
111
|
top: rect.top,
|
|
112
|
-
width: range.collapsed ?
|
|
112
|
+
width: range.collapsed ? 1 : rect.width,
|
|
113
113
|
height: rect.height
|
|
114
114
|
};
|
|
115
115
|
}
|
|
@@ -554,8 +554,8 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
554
554
|
nativeRange.collapse();
|
|
555
555
|
return getLayoutRectByRange(nativeRange);
|
|
556
556
|
}
|
|
557
|
-
restore(abstractSelection,
|
|
558
|
-
this.changeFromUser =
|
|
557
|
+
restore(abstractSelection, fromLocal) {
|
|
558
|
+
this.changeFromUser = fromLocal;
|
|
559
559
|
if (this.ignoreSelectionChange || !this.connector) {
|
|
560
560
|
return;
|
|
561
561
|
}
|
|
@@ -613,6 +613,10 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
613
613
|
this.listen(this.connector);
|
|
614
614
|
}
|
|
615
615
|
};
|
|
616
|
+
if (fromLocal) {
|
|
617
|
+
Promise.resolve().then(bind);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
616
620
|
if (typeof requestIdleCallback === 'function') {
|
|
617
621
|
requestIdleCallback(bind);
|
|
618
622
|
}
|
|
@@ -805,7 +809,7 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
805
809
|
isUpdating = true;
|
|
806
810
|
}), this.scheduler.onDocChanged.pipe(stream.delay()).subscribe(() => {
|
|
807
811
|
isUpdating = false;
|
|
808
|
-
}), stream.fromEvent(document, 'selectionchange').
|
|
812
|
+
}), stream.fromEvent(document, 'selectionchange').subscribe(() => {
|
|
809
813
|
if (isUpdating) {
|
|
810
814
|
return;
|
|
811
815
|
}
|
|
@@ -851,7 +855,7 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
851
855
|
this.getCorrectedPosition(nativeRange.endContainer, nativeRange.endOffset, isFocusEnd);
|
|
852
856
|
if ([Node.ELEMENT_NODE, Node.TEXT_NODE].includes((_a = nativeRange.commonAncestorContainer) === null || _a === void 0 ? void 0 : _a.nodeType) &&
|
|
853
857
|
startPosition && endPosition) {
|
|
854
|
-
const abstractSelection = isFocusEnd ? {
|
|
858
|
+
const abstractSelection = connector.beforeChange(isFocusEnd ? {
|
|
855
859
|
anchorSlot: startPosition.slot,
|
|
856
860
|
anchorOffset: startPosition.offset,
|
|
857
861
|
focusSlot: endPosition.slot,
|
|
@@ -861,7 +865,12 @@ exports.SelectionBridge = class SelectionBridge {
|
|
|
861
865
|
focusOffset: startPosition.offset,
|
|
862
866
|
anchorSlot: endPosition.slot,
|
|
863
867
|
anchorOffset: endPosition.offset
|
|
864
|
-
};
|
|
868
|
+
});
|
|
869
|
+
if (!abstractSelection) {
|
|
870
|
+
this.selectionChangeEvent.next(null);
|
|
871
|
+
connector.setSelection(null);
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
865
874
|
const { focus, anchor } = this.getPositionByRange(abstractSelection);
|
|
866
875
|
if (focus && anchor) {
|
|
867
876
|
let start = anchor;
|
|
@@ -1315,17 +1324,17 @@ class ExperimentalCaret {
|
|
|
1315
1324
|
pointEle.style.cssText = 'position: absolute; left: 0; top: 0; width:0;height:0';
|
|
1316
1325
|
hackEle.append(pointEle);
|
|
1317
1326
|
node.append(hackEle);
|
|
1318
|
-
const
|
|
1327
|
+
const p1 = pointEle.getBoundingClientRect();
|
|
1319
1328
|
pointEle.style.right = '0';
|
|
1320
1329
|
pointEle.style.left = '';
|
|
1321
|
-
const
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1330
|
+
const p2 = pointEle.getBoundingClientRect();
|
|
1331
|
+
const x = p1.x - p2.x;
|
|
1332
|
+
const y = p1.y - p2.y;
|
|
1333
|
+
rotate = Math.atan2(y, x) * 180 / Math.PI;
|
|
1325
1334
|
hackEle.remove();
|
|
1326
1335
|
}
|
|
1327
1336
|
}
|
|
1328
|
-
if (
|
|
1337
|
+
if (writingMode === 'vertical-lr' || writingMode === 'vertical-rl') {
|
|
1329
1338
|
rotate += 90;
|
|
1330
1339
|
}
|
|
1331
1340
|
Object.assign(this.elementRef.style, {
|
|
@@ -1336,7 +1345,7 @@ class ExperimentalCaret {
|
|
|
1336
1345
|
fontSize,
|
|
1337
1346
|
transform: `rotate(${rotate}deg)`,
|
|
1338
1347
|
});
|
|
1339
|
-
this.caret.style.backgroundColor = color;
|
|
1348
|
+
this.caret.style.backgroundColor = color === 'rgba(0, 0, 0, 0)' ? '#000' : color;
|
|
1340
1349
|
this.styleChangeEvent.next({
|
|
1341
1350
|
height: boxHeight + 'px',
|
|
1342
1351
|
lineHeight: boxHeight + 'px',
|
|
@@ -30,7 +30,7 @@ export declare class SelectionBridge implements NativeSelectionBridge {
|
|
|
30
30
|
connect(connector: NativeSelectionConnector): void;
|
|
31
31
|
disConnect(): void;
|
|
32
32
|
getRect(location: SelectionPosition): Rect | null;
|
|
33
|
-
restore(abstractSelection: AbstractSelection | null,
|
|
33
|
+
restore(abstractSelection: AbstractSelection | null, fromLocal: boolean): void;
|
|
34
34
|
destroy(): void;
|
|
35
35
|
getPositionByRange(abstractSelection: AbstractSelection): {
|
|
36
36
|
focus: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textbus/platform-browser",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
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",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@tanbo/stream": "^1.2.7",
|
|
29
|
-
"@textbus/core": "^5.0.0
|
|
30
|
-
"@viewfly/core": "^2.0.0-alpha.
|
|
29
|
+
"@textbus/core": "^5.0.0",
|
|
30
|
+
"@viewfly/core": "^2.0.0-alpha.6"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"bugs": {
|
|
48
48
|
"url": "https://github.com/textbus/textbus.git/issues"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "cf4fd289b73bc777124a32fe42bb58eba05a34f1"
|
|
51
51
|
}
|