@textbus/platform-browser 5.4.8 → 5.4.10
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/dist/index.esm.js +480 -329
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +480 -329
- package/dist/index.js.map +1 -1
- package/dist/native-input.d.ts +2 -4
- package/dist/selection-bridge.d.ts +14 -7
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -4,13 +4,13 @@ import { InjectionToken, Injectable, Inject, Optional } from '@viewfly/core';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 选区焦点可视位置
|
|
7
|
-
*/ function _array_like_to_array$
|
|
7
|
+
*/ function _array_like_to_array$4(arr, len) {
|
|
8
8
|
if (len == null || len > arr.length) len = arr.length;
|
|
9
9
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
10
10
|
return arr2;
|
|
11
11
|
}
|
|
12
|
-
function _array_without_holes$
|
|
13
|
-
if (Array.isArray(arr)) return _array_like_to_array$
|
|
12
|
+
function _array_without_holes$3(arr) {
|
|
13
|
+
if (Array.isArray(arr)) return _array_like_to_array$4(arr);
|
|
14
14
|
}
|
|
15
15
|
function _instanceof$4(left, right) {
|
|
16
16
|
"@swc/helpers - instanceof";
|
|
@@ -20,22 +20,22 @@ function _instanceof$4(left, right) {
|
|
|
20
20
|
return left instanceof right;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
function _iterable_to_array$
|
|
23
|
+
function _iterable_to_array$3(iter) {
|
|
24
24
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
25
25
|
}
|
|
26
|
-
function _non_iterable_spread$
|
|
26
|
+
function _non_iterable_spread$3() {
|
|
27
27
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
28
28
|
}
|
|
29
|
-
function _to_consumable_array$
|
|
30
|
-
return _array_without_holes$
|
|
29
|
+
function _to_consumable_array$3(arr) {
|
|
30
|
+
return _array_without_holes$3(arr) || _iterable_to_array$3(arr) || _unsupported_iterable_to_array$4(arr) || _non_iterable_spread$3();
|
|
31
31
|
}
|
|
32
|
-
function _unsupported_iterable_to_array$
|
|
32
|
+
function _unsupported_iterable_to_array$4(o, minLen) {
|
|
33
33
|
if (!o) return;
|
|
34
|
-
if (typeof o === "string") return _array_like_to_array$
|
|
34
|
+
if (typeof o === "string") return _array_like_to_array$4(o, minLen);
|
|
35
35
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
36
36
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
37
37
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
38
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$
|
|
38
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$4(o, minLen);
|
|
39
39
|
}
|
|
40
40
|
var OVERFLOW_CLIP_VALUES = new Set([
|
|
41
41
|
'auto',
|
|
@@ -98,7 +98,7 @@ function readOverflowClipAxes(style) {
|
|
|
98
98
|
}
|
|
99
99
|
return {
|
|
100
100
|
clipAncestors: clipAncestors,
|
|
101
|
-
scrollContainers: _to_consumable_array$
|
|
101
|
+
scrollContainers: _to_consumable_array$3(scrollContainers),
|
|
102
102
|
firstScrollContainer: (_ref1 = (_clipAncestors_ = clipAncestors[0]) === null || _clipAncestors_ === void 0 ? void 0 : _clipAncestors_.element) !== null && _ref1 !== void 0 ? _ref1 : documentElement
|
|
103
103
|
};
|
|
104
104
|
}
|
|
@@ -283,7 +283,7 @@ function createElement(tagName) {
|
|
|
283
283
|
var el = document.createElement(tagName);
|
|
284
284
|
if (options.classes) {
|
|
285
285
|
var _el_classList;
|
|
286
|
-
(_el_classList = el.classList).add.apply(_el_classList, _to_consumable_array$
|
|
286
|
+
(_el_classList = el.classList).add.apply(_el_classList, _to_consumable_array$3(options.classes));
|
|
287
287
|
}
|
|
288
288
|
if (options.attrs) {
|
|
289
289
|
Object.keys(options.attrs).forEach(function(key) {
|
|
@@ -418,13 +418,13 @@ var isMobileBrowser = function isMobileBrowser() {
|
|
|
418
418
|
* 编辑器容器遮罩层 token
|
|
419
419
|
*/ var VIEW_MASK = new InjectionToken('VIEW_MASK');
|
|
420
420
|
|
|
421
|
-
function _array_like_to_array$
|
|
421
|
+
function _array_like_to_array$3(arr, len) {
|
|
422
422
|
if (len == null || len > arr.length) len = arr.length;
|
|
423
423
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
424
424
|
return arr2;
|
|
425
425
|
}
|
|
426
|
-
function _array_without_holes$
|
|
427
|
-
if (Array.isArray(arr)) return _array_like_to_array$
|
|
426
|
+
function _array_without_holes$2(arr) {
|
|
427
|
+
if (Array.isArray(arr)) return _array_like_to_array$3(arr);
|
|
428
428
|
}
|
|
429
429
|
function _class_call_check$7(instance, Constructor) {
|
|
430
430
|
if (!(instance instanceof Constructor)) {
|
|
@@ -466,22 +466,22 @@ function _instanceof$3(left, right) {
|
|
|
466
466
|
return left instanceof right;
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
|
-
function _iterable_to_array$
|
|
469
|
+
function _iterable_to_array$2(iter) {
|
|
470
470
|
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
471
471
|
}
|
|
472
|
-
function _non_iterable_spread$
|
|
472
|
+
function _non_iterable_spread$2() {
|
|
473
473
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
474
474
|
}
|
|
475
|
-
function _to_consumable_array$
|
|
476
|
-
return _array_without_holes$
|
|
475
|
+
function _to_consumable_array$2(arr) {
|
|
476
|
+
return _array_without_holes$2(arr) || _iterable_to_array$2(arr) || _unsupported_iterable_to_array$3(arr) || _non_iterable_spread$2();
|
|
477
477
|
}
|
|
478
|
-
function _unsupported_iterable_to_array$
|
|
478
|
+
function _unsupported_iterable_to_array$3(o, minLen) {
|
|
479
479
|
if (!o) return;
|
|
480
|
-
if (typeof o === "string") return _array_like_to_array$
|
|
480
|
+
if (typeof o === "string") return _array_like_to_array$3(o, minLen);
|
|
481
481
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
482
482
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
483
483
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
484
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$
|
|
484
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$3(o, minLen);
|
|
485
485
|
}
|
|
486
486
|
function _ts_decorate$4(decorators, target, key, desc) {
|
|
487
487
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -505,9 +505,9 @@ var Parser = /*#__PURE__*/ function() {
|
|
|
505
505
|
_define_property$6(this, "formatLoaders", void 0);
|
|
506
506
|
_define_property$6(this, "attributeLoaders", void 0);
|
|
507
507
|
this.textbus = textbus;
|
|
508
|
-
var componentLoaders = _to_consumable_array$
|
|
509
|
-
var formatLoaders = _to_consumable_array$
|
|
510
|
-
var attributeLoaders = _to_consumable_array$
|
|
508
|
+
var componentLoaders = _to_consumable_array$2(options.componentLoaders || []);
|
|
509
|
+
var formatLoaders = _to_consumable_array$2(options.formatLoaders || []);
|
|
510
|
+
var attributeLoaders = _to_consumable_array$2(options.attributeLoaders || []);
|
|
511
511
|
// options.imports?.forEach(i => {
|
|
512
512
|
// componentLoaders.push(...(i.componentLoaders || []))
|
|
513
513
|
// formatLoaders.push(...(i.formatLoaders || []))
|
|
@@ -551,7 +551,7 @@ var Parser = /*#__PURE__*/ function() {
|
|
|
551
551
|
slot.insert('\n');
|
|
552
552
|
return;
|
|
553
553
|
}
|
|
554
|
-
var schema = _to_consumable_array$
|
|
554
|
+
var schema = _to_consumable_array$2(slot.schema);
|
|
555
555
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
556
556
|
try {
|
|
557
557
|
for(var _iterator = this.componentLoaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
@@ -1074,13 +1074,10 @@ var SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1074
1074
|
value: function getLinePosition(currentPosition, toNext) {
|
|
1075
1075
|
var _this = this;
|
|
1076
1076
|
clearTimeout(this.cacheCaretPositionTimer);
|
|
1077
|
-
|
|
1078
|
-
if (this.oldCaretPosition) {
|
|
1079
|
-
p = toNext ? this.getNextLinePositionByOffset(currentPosition, this.oldCaretPosition.left) : this.getPreviousLinePositionByOffset(currentPosition, this.oldCaretPosition.left);
|
|
1080
|
-
} else {
|
|
1077
|
+
if (!this.oldCaretPosition) {
|
|
1081
1078
|
this.oldCaretPosition = this.getRect(currentPosition);
|
|
1082
|
-
p = toNext ? this.getNextLinePositionByOffset(currentPosition, this.oldCaretPosition.left) : this.getPreviousLinePositionByOffset(currentPosition, this.oldCaretPosition.left);
|
|
1083
1079
|
}
|
|
1080
|
+
var p = this.getVerticalMovePosition(currentPosition, this.oldCaretPosition.left, toNext);
|
|
1084
1081
|
this.cacheCaretPositionTimer = setTimeout(function() {
|
|
1085
1082
|
_this.oldCaretPosition = null;
|
|
1086
1083
|
}, 3000);
|
|
@@ -1088,119 +1085,137 @@ var SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1088
1085
|
}
|
|
1089
1086
|
},
|
|
1090
1087
|
{
|
|
1091
|
-
key: "
|
|
1088
|
+
key: "getVerticalMovePosition",
|
|
1092
1089
|
value: /**
|
|
1093
|
-
*
|
|
1090
|
+
* 计算光标到下一行或上一行的位置
|
|
1094
1091
|
* @param currentPosition
|
|
1095
|
-
* @param startLeft
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
var
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
var
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
var
|
|
1107
|
-
var
|
|
1108
|
-
|
|
1092
|
+
* @param startLeft
|
|
1093
|
+
* @param toNext
|
|
1094
|
+
* @private
|
|
1095
|
+
*/ function getVerticalMovePosition(currentPosition, startLeft, toNext) {
|
|
1096
|
+
var nativePos = this.findSelectedNodeAndOffset(currentPosition.slot, currentPosition.offset);
|
|
1097
|
+
if (!nativePos) return currentPosition;
|
|
1098
|
+
this.ignoreSelectionChange = true;
|
|
1099
|
+
var sel = this.nativeSelection;
|
|
1100
|
+
sel.removeAllRanges();
|
|
1101
|
+
sel.setBaseAndExtent(nativePos.node, nativePos.offset, nativePos.node, nativePos.offset);
|
|
1102
|
+
var startRect = getLayoutRectByRange(sel.getRangeAt(0).cloneRange());
|
|
1103
|
+
var lastPos = currentPosition;
|
|
1104
|
+
var prevRange = {
|
|
1105
|
+
node: nativePos.node,
|
|
1106
|
+
offset: nativePos.offset
|
|
1107
|
+
};
|
|
1109
1108
|
while(true){
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
//
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
if (oldPosition) {
|
|
1130
|
-
if (rect2.left >= oldLeft) {
|
|
1131
|
-
return oldPosition;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
oldLeft = rect2.left;
|
|
1135
|
-
oldPosition = position;
|
|
1136
|
-
}
|
|
1137
|
-
if (loopCount > 10000) {
|
|
1109
|
+
sel.modify('move', toNext ? 'forward' : 'backward', 'line');
|
|
1110
|
+
var focusNode = sel.focusNode, focusOffset = sel.focusOffset;
|
|
1111
|
+
if (!focusNode) break;
|
|
1112
|
+
// 浏览器无法继续移动
|
|
1113
|
+
if (prevRange && focusNode === prevRange.node && focusOffset === prevRange.offset) break;
|
|
1114
|
+
prevRange = {
|
|
1115
|
+
node: focusNode,
|
|
1116
|
+
offset: focusOffset
|
|
1117
|
+
};
|
|
1118
|
+
// X 轴对齐
|
|
1119
|
+
// const movedRect = getLayoutRectByRange(sel.getRangeAt(0).cloneRange())
|
|
1120
|
+
// const xRefined = this.caretPositionFromPoint(startLeft, movedRect)
|
|
1121
|
+
// if (xRefined) {
|
|
1122
|
+
// focusNode = xRefined.offsetNode
|
|
1123
|
+
// focusOffset = xRefined.offset
|
|
1124
|
+
// }
|
|
1125
|
+
var modelPos = this.getCorrectedPosition(focusNode, focusOffset, true);
|
|
1126
|
+
if (!modelPos) {
|
|
1127
|
+
lastPos = this.getDocumentBoundary(toNext);
|
|
1138
1128
|
break;
|
|
1139
1129
|
}
|
|
1130
|
+
lastPos = modelPos;
|
|
1131
|
+
var rect = this.getRect(modelPos);
|
|
1132
|
+
// 仍未到达新行,继续 modify
|
|
1133
|
+
if (this.isSameLine(startRect, rect, toNext)) continue;
|
|
1134
|
+
// 已到达新行,沿该行微调 X
|
|
1135
|
+
this.ignoreSelectionChange = false;
|
|
1136
|
+
return this.refineXOnLine(modelPos, startLeft, rect);
|
|
1140
1137
|
}
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1138
|
+
this.ignoreSelectionChange = false;
|
|
1139
|
+
return lastPos;
|
|
1140
|
+
}
|
|
1141
|
+
},
|
|
1142
|
+
{
|
|
1143
|
+
key: "isSameLine",
|
|
1144
|
+
value: /** 目标位置是否仍在当前视觉行内 */ function isSameLine(startRect, targetRect, toNext) {
|
|
1145
|
+
var startBottom = startRect.top + startRect.height;
|
|
1146
|
+
var targetBottom = targetRect.top + targetRect.height;
|
|
1147
|
+
if (toNext) {
|
|
1148
|
+
return targetRect.top <= startRect.top || targetBottom <= startBottom;
|
|
1149
|
+
}
|
|
1150
|
+
return targetRect.top >= startRect.top || targetBottom >= startBottom;
|
|
1145
1151
|
}
|
|
1146
1152
|
},
|
|
1147
1153
|
{
|
|
1148
|
-
key: "
|
|
1154
|
+
key: "refineXOnLine",
|
|
1149
1155
|
value: /**
|
|
1150
|
-
*
|
|
1151
|
-
*
|
|
1152
|
-
*
|
|
1153
|
-
*/ function
|
|
1154
|
-
var
|
|
1155
|
-
var
|
|
1156
|
-
var
|
|
1157
|
-
var
|
|
1158
|
-
|
|
1159
|
-
var
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1156
|
+
* 沿目标行微调位置。
|
|
1157
|
+
* 起点在 targetX 右侧 → 向左找到离 targetX 最近的右侧位置;
|
|
1158
|
+
* 起点在 targetX 左侧 → 向右找到第一个右侧位置。
|
|
1159
|
+
*/ function refineXOnLine(position, targetX, lineRect) {
|
|
1160
|
+
var startRect = this.getRect(position);
|
|
1161
|
+
var startLeft = startRect.left;
|
|
1162
|
+
var lineTop = lineRect.top;
|
|
1163
|
+
var lineBottom = lineTop + Math.max(lineRect.height, 12);
|
|
1164
|
+
if (startLeft === targetX) return position;
|
|
1165
|
+
var cur = position;
|
|
1166
|
+
if (startLeft > targetX) {
|
|
1167
|
+
var rightSide = position;
|
|
1168
|
+
while(true){
|
|
1169
|
+
var prev = this.selection.getPreviousPositionByPosition(cur.slot, cur.offset);
|
|
1170
|
+
if (prev.slot === cur.slot && prev.offset === cur.offset) break;
|
|
1171
|
+
var rect = this.getRect(prev);
|
|
1172
|
+
if (!rect) break;
|
|
1173
|
+
if (rect.top >= lineBottom || rect.top + rect.height <= lineTop) break;
|
|
1174
|
+
cur = prev;
|
|
1175
|
+
if (rect.left === targetX) return prev;
|
|
1176
|
+
if (rect.left < targetX) return rightSide;
|
|
1177
|
+
rightSide = prev;
|
|
1178
|
+
}
|
|
1179
|
+
return rightSide;
|
|
1180
|
+
}
|
|
1166
1181
|
while(true){
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
oldPosition = position;
|
|
1192
|
-
oldLeft = rect2.left;
|
|
1193
|
-
}
|
|
1194
|
-
if (loopCount > 10000) {
|
|
1195
|
-
break;
|
|
1196
|
-
}
|
|
1182
|
+
var next = this.selection.getNextPositionByPosition(cur.slot, cur.offset);
|
|
1183
|
+
if (next.slot === cur.slot && next.offset === cur.offset) break;
|
|
1184
|
+
var rect1 = this.getRect(next);
|
|
1185
|
+
if (!rect1) break;
|
|
1186
|
+
if (rect1.top >= lineBottom || rect1.top + rect1.height <= lineTop) break;
|
|
1187
|
+
cur = next;
|
|
1188
|
+
if (rect1.left === targetX) return cur;
|
|
1189
|
+
if (rect1.left > targetX) return cur;
|
|
1190
|
+
}
|
|
1191
|
+
return cur;
|
|
1192
|
+
}
|
|
1193
|
+
},
|
|
1194
|
+
{
|
|
1195
|
+
key: "getDocumentBoundary",
|
|
1196
|
+
value: /** 跳转到文档开头或结尾 */ function getDocumentBoundary(toNext) {
|
|
1197
|
+
var slots = this.rootComponentRef.component.slots;
|
|
1198
|
+
if (toNext) {
|
|
1199
|
+
var lastSlot = slots[slots.length - 1];
|
|
1200
|
+
return {
|
|
1201
|
+
slot: lastSlot,
|
|
1202
|
+
offset: lastSlot.length
|
|
1203
|
+
};
|
|
1197
1204
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
slot:
|
|
1205
|
+
var firstSlot = slots[0];
|
|
1206
|
+
return {
|
|
1207
|
+
slot: firstSlot,
|
|
1208
|
+
offset: 0
|
|
1201
1209
|
};
|
|
1202
1210
|
}
|
|
1203
1211
|
},
|
|
1212
|
+
{
|
|
1213
|
+
key: "caretPositionFromPoint",
|
|
1214
|
+
value: function caretPositionFromPoint(x, rect) {
|
|
1215
|
+
var _document_caretPositionFromPoint, _document;
|
|
1216
|
+
return (_document_caretPositionFromPoint = (_document = document).caretPositionFromPoint) === null || _document_caretPositionFromPoint === void 0 ? void 0 : _document_caretPositionFromPoint.call(_document, x, rect.top + rect.height / 2);
|
|
1217
|
+
}
|
|
1218
|
+
},
|
|
1204
1219
|
{
|
|
1205
1220
|
key: "unListen",
|
|
1206
1221
|
value: function unListen() {
|
|
@@ -1500,7 +1515,7 @@ var SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1500
1515
|
};
|
|
1501
1516
|
}
|
|
1502
1517
|
var firstChild = toAfter ? node.firstChild : node.lastChild;
|
|
1503
|
-
if (firstChild) {
|
|
1518
|
+
if (firstChild && !excludeNodes.includes(firstChild)) {
|
|
1504
1519
|
return this.findFocusNode(firstChild, toAfter, excludeNodes);
|
|
1505
1520
|
}
|
|
1506
1521
|
var nextSibling = toAfter ? node.nextSibling : node.previousSibling;
|
|
@@ -1515,6 +1530,13 @@ var SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1515
1530
|
value: function findFocusNodeByParent(node, toAfter, excludeNodes) {
|
|
1516
1531
|
var parentNode = node.parentNode;
|
|
1517
1532
|
if (parentNode) {
|
|
1533
|
+
if (excludeNodes.includes(parentNode)) {
|
|
1534
|
+
var nextNode = toAfter ? parentNode.nextSibling : parentNode.previousSibling;
|
|
1535
|
+
if (nextNode) {
|
|
1536
|
+
return this.findFocusNode(nextNode, toAfter, excludeNodes);
|
|
1537
|
+
}
|
|
1538
|
+
return this.findFocusNodeByParent(parentNode, toAfter, excludeNodes);
|
|
1539
|
+
}
|
|
1518
1540
|
var parentPosition = this.domAdapter.getLocationByNativeNode(parentNode);
|
|
1519
1541
|
if (parentPosition) {
|
|
1520
1542
|
return {
|
|
@@ -1522,8 +1544,12 @@ var SelectionBridge = /*#__PURE__*/ function() {
|
|
|
1522
1544
|
offset: toAfter ? parentPosition.endIndex : parentPosition.startIndex
|
|
1523
1545
|
};
|
|
1524
1546
|
}
|
|
1525
|
-
excludeNodes.push(
|
|
1526
|
-
|
|
1547
|
+
excludeNodes.push(parentNode);
|
|
1548
|
+
var nextNode1 = toAfter ? parentNode.nextSibling : parentNode.previousSibling;
|
|
1549
|
+
if (nextNode1) {
|
|
1550
|
+
return this.findFocusNode(nextNode1, toAfter, excludeNodes);
|
|
1551
|
+
}
|
|
1552
|
+
return this.findFocusNodeByParent(parentNode, toAfter, excludeNodes);
|
|
1527
1553
|
}
|
|
1528
1554
|
return null;
|
|
1529
1555
|
}
|
|
@@ -1547,6 +1573,14 @@ SelectionBridge = _ts_decorate$3([
|
|
|
1547
1573
|
])
|
|
1548
1574
|
], SelectionBridge);
|
|
1549
1575
|
|
|
1576
|
+
function _array_like_to_array$2(arr, len) {
|
|
1577
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
1578
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
1579
|
+
return arr2;
|
|
1580
|
+
}
|
|
1581
|
+
function _array_without_holes$1(arr) {
|
|
1582
|
+
if (Array.isArray(arr)) return _array_like_to_array$2(arr);
|
|
1583
|
+
}
|
|
1550
1584
|
function _assert_this_initialized$1(self) {
|
|
1551
1585
|
if (self === void 0) {
|
|
1552
1586
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -1607,6 +1641,12 @@ function _inherits$1(subClass, superClass) {
|
|
|
1607
1641
|
});
|
|
1608
1642
|
if (superClass) _set_prototype_of$1(subClass, superClass);
|
|
1609
1643
|
}
|
|
1644
|
+
function _iterable_to_array$1(iter) {
|
|
1645
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
1646
|
+
}
|
|
1647
|
+
function _non_iterable_spread$1() {
|
|
1648
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
1649
|
+
}
|
|
1610
1650
|
function _possible_constructor_return$1(self, call) {
|
|
1611
1651
|
if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
|
|
1612
1652
|
return call;
|
|
@@ -1620,10 +1660,21 @@ function _set_prototype_of$1(o, p) {
|
|
|
1620
1660
|
};
|
|
1621
1661
|
return _set_prototype_of$1(o, p);
|
|
1622
1662
|
}
|
|
1663
|
+
function _to_consumable_array$1(arr) {
|
|
1664
|
+
return _array_without_holes$1(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread$1();
|
|
1665
|
+
}
|
|
1623
1666
|
function _type_of$1(obj) {
|
|
1624
1667
|
"@swc/helpers - typeof";
|
|
1625
1668
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
1626
1669
|
}
|
|
1670
|
+
function _unsupported_iterable_to_array$2(o, minLen) {
|
|
1671
|
+
if (!o) return;
|
|
1672
|
+
if (typeof o === "string") return _array_like_to_array$2(o, minLen);
|
|
1673
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
1674
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
1675
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
1676
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
|
|
1677
|
+
}
|
|
1627
1678
|
function _is_native_reflect_construct$1() {
|
|
1628
1679
|
try {
|
|
1629
1680
|
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
@@ -1981,25 +2032,49 @@ var ExperimentalCaret = /*#__PURE__*/ function() {
|
|
|
1981
2032
|
{
|
|
1982
2033
|
key: "scrollCaretIntoViewIfNeeded",
|
|
1983
2034
|
value: function scrollCaretIntoViewIfNeeded(layoutElRect, clipContext) {
|
|
1984
|
-
var _scrollContainer_ownerDocument;
|
|
1985
2035
|
if (!this.changeFromSelf) {
|
|
1986
2036
|
return;
|
|
1987
2037
|
}
|
|
1988
2038
|
this.changeFromSelf = false;
|
|
1989
|
-
var scrollContainer = clipContext.firstScrollContainer;
|
|
1990
|
-
var doc = (_scrollContainer_ownerDocument = scrollContainer.ownerDocument) !== null && _scrollContainer_ownerDocument !== void 0 ? _scrollContainer_ownerDocument : document;
|
|
1991
|
-
var scrollRect = scrollContainer === doc.documentElement ? {
|
|
1992
|
-
top: 0,
|
|
1993
|
-
bottom: doc.documentElement.clientHeight
|
|
1994
|
-
} : scrollContainer.getBoundingClientRect();
|
|
1995
2039
|
var limit = this.getLimit();
|
|
1996
|
-
var
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2040
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
2041
|
+
try {
|
|
2042
|
+
// 从外到内逐层处理,每滚动一层后重新获取光标位置再处理内层
|
|
2043
|
+
for(var _iterator = _to_consumable_array$1(clipContext.scrollContainers).reverse()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
2044
|
+
var scrollContainer = _step.value;
|
|
2045
|
+
var _scrollContainer_ownerDocument;
|
|
2046
|
+
var doc = (_scrollContainer_ownerDocument = scrollContainer.ownerDocument) !== null && _scrollContainer_ownerDocument !== void 0 ? _scrollContainer_ownerDocument : document;
|
|
2047
|
+
var isDoc = scrollContainer === doc.documentElement;
|
|
2048
|
+
var scrollRect = isDoc ? {
|
|
2049
|
+
top: 0,
|
|
2050
|
+
bottom: doc.documentElement.clientHeight
|
|
2051
|
+
} : scrollContainer.getBoundingClientRect();
|
|
2052
|
+
var visibleTop = Math.max(limit.top, scrollRect.top);
|
|
2053
|
+
var visibleBottom = Math.min(limit.bottom, scrollRect.bottom);
|
|
2054
|
+
var caretBottom = layoutElRect.top + layoutElRect.height;
|
|
2055
|
+
if (layoutElRect.top >= visibleTop && caretBottom <= visibleBottom) {
|
|
2056
|
+
continue; // 光标已在当前容器可视区域内,无需滚动
|
|
2057
|
+
}
|
|
2058
|
+
if (layoutElRect.top < visibleTop) {
|
|
2059
|
+
scrollContainer.scrollTop -= visibleTop - layoutElRect.top;
|
|
2060
|
+
} else if (caretBottom > visibleBottom) {
|
|
2061
|
+
scrollContainer.scrollTop += caretBottom - visibleBottom;
|
|
2062
|
+
}
|
|
2063
|
+
layoutElRect = this.elementRef.getBoundingClientRect();
|
|
2064
|
+
}
|
|
2065
|
+
} catch (err) {
|
|
2066
|
+
_didIteratorError = true;
|
|
2067
|
+
_iteratorError = err;
|
|
2068
|
+
} finally{
|
|
2069
|
+
try {
|
|
2070
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
2071
|
+
_iterator.return();
|
|
2072
|
+
}
|
|
2073
|
+
} finally{
|
|
2074
|
+
if (_didIteratorError) {
|
|
2075
|
+
throw _iteratorError;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2003
2078
|
}
|
|
2004
2079
|
}
|
|
2005
2080
|
}
|
|
@@ -2378,7 +2453,8 @@ var MagicInput = /*#__PURE__*/ function(Input) {
|
|
|
2378
2453
|
width: '100%',
|
|
2379
2454
|
display: 'block',
|
|
2380
2455
|
height: '16px',
|
|
2381
|
-
position: '
|
|
2456
|
+
position: 'absolute',
|
|
2457
|
+
left: 0,
|
|
2382
2458
|
bottom: this.isWindows ? '3px' : '0'
|
|
2383
2459
|
}
|
|
2384
2460
|
});
|
|
@@ -2402,13 +2478,13 @@ MagicInput = _ts_decorate$2([
|
|
|
2402
2478
|
])
|
|
2403
2479
|
], MagicInput);
|
|
2404
2480
|
|
|
2405
|
-
function _array_like_to_array(arr, len) {
|
|
2481
|
+
function _array_like_to_array$1(arr, len) {
|
|
2406
2482
|
if (len == null || len > arr.length) len = arr.length;
|
|
2407
2483
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
2408
2484
|
return arr2;
|
|
2409
2485
|
}
|
|
2410
2486
|
function _array_without_holes(arr) {
|
|
2411
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
2487
|
+
if (Array.isArray(arr)) return _array_like_to_array$1(arr);
|
|
2412
2488
|
}
|
|
2413
2489
|
function _class_call_check$2(instance, Constructor) {
|
|
2414
2490
|
if (!(instance instanceof Constructor)) {
|
|
@@ -2448,15 +2524,15 @@ function _non_iterable_spread() {
|
|
|
2448
2524
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
2449
2525
|
}
|
|
2450
2526
|
function _to_consumable_array(arr) {
|
|
2451
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
2527
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_spread();
|
|
2452
2528
|
}
|
|
2453
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
2529
|
+
function _unsupported_iterable_to_array$1(o, minLen) {
|
|
2454
2530
|
if (!o) return;
|
|
2455
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
2531
|
+
if (typeof o === "string") return _array_like_to_array$1(o, minLen);
|
|
2456
2532
|
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
2457
2533
|
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
2458
2534
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
2459
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
2535
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
|
|
2460
2536
|
}
|
|
2461
2537
|
function _ts_decorate$1(decorators, target, key, desc) {
|
|
2462
2538
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2789,6 +2865,14 @@ CollaborateCursor = _ts_decorate$1([
|
|
|
2789
2865
|
])
|
|
2790
2866
|
], CollaborateCursor);
|
|
2791
2867
|
|
|
2868
|
+
function _array_like_to_array(arr, len) {
|
|
2869
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
2870
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
2871
|
+
return arr2;
|
|
2872
|
+
}
|
|
2873
|
+
function _array_with_holes(arr) {
|
|
2874
|
+
if (Array.isArray(arr)) return arr;
|
|
2875
|
+
}
|
|
2792
2876
|
function _assert_this_initialized(self) {
|
|
2793
2877
|
if (self === void 0) {
|
|
2794
2878
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
@@ -2857,6 +2941,33 @@ function _instanceof$1(left, right) {
|
|
|
2857
2941
|
return left instanceof right;
|
|
2858
2942
|
}
|
|
2859
2943
|
}
|
|
2944
|
+
function _iterable_to_array_limit(arr, i) {
|
|
2945
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
2946
|
+
if (_i == null) return;
|
|
2947
|
+
var _arr = [];
|
|
2948
|
+
var _n = true;
|
|
2949
|
+
var _d = false;
|
|
2950
|
+
var _s, _e;
|
|
2951
|
+
try {
|
|
2952
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
2953
|
+
_arr.push(_s.value);
|
|
2954
|
+
if (i && _arr.length === i) break;
|
|
2955
|
+
}
|
|
2956
|
+
} catch (err) {
|
|
2957
|
+
_d = true;
|
|
2958
|
+
_e = err;
|
|
2959
|
+
} finally{
|
|
2960
|
+
try {
|
|
2961
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
2962
|
+
} finally{
|
|
2963
|
+
if (_d) throw _e;
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
return _arr;
|
|
2967
|
+
}
|
|
2968
|
+
function _non_iterable_rest() {
|
|
2969
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
2970
|
+
}
|
|
2860
2971
|
function _possible_constructor_return(self, call) {
|
|
2861
2972
|
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
2862
2973
|
return call;
|
|
@@ -2870,10 +2981,21 @@ function _set_prototype_of(o, p) {
|
|
|
2870
2981
|
};
|
|
2871
2982
|
return _set_prototype_of(o, p);
|
|
2872
2983
|
}
|
|
2984
|
+
function _sliced_to_array(arr, i) {
|
|
2985
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
2986
|
+
}
|
|
2873
2987
|
function _type_of(obj) {
|
|
2874
2988
|
"@swc/helpers - typeof";
|
|
2875
2989
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
2876
2990
|
}
|
|
2991
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
2992
|
+
if (!o) return;
|
|
2993
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
2994
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
2995
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
2996
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
2997
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
2998
|
+
}
|
|
2877
2999
|
function _is_native_reflect_construct() {
|
|
2878
3000
|
try {
|
|
2879
3001
|
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
@@ -2891,6 +3013,150 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
2891
3013
|
function _ts_metadata(k, v) {
|
|
2892
3014
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2893
3015
|
}
|
|
3016
|
+
/**
|
|
3017
|
+
* 轻量级 DOM 文本变化记录器,仅在 composition 期间激活。
|
|
3018
|
+
* 记录 composition 期间 DOM 中新增/修改的文本节点,在 compositionend 时从 DOM 读取最终文本。
|
|
3019
|
+
* 写入模型后清理浏览器创建的新文本节点,避免残留在文档中。
|
|
3020
|
+
*/ var CompositionRecorder = /*#__PURE__*/ function() {
|
|
3021
|
+
function CompositionRecorder() {
|
|
3022
|
+
_class_call_check$1(this, CompositionRecorder);
|
|
3023
|
+
_define_property$1(this, "observer", null);
|
|
3024
|
+
_define_property$1(this, "nodeOldValues", new Map());
|
|
3025
|
+
}
|
|
3026
|
+
_create_class$1(CompositionRecorder, [
|
|
3027
|
+
{
|
|
3028
|
+
key: "start",
|
|
3029
|
+
value: function start(target) {
|
|
3030
|
+
var _this = this;
|
|
3031
|
+
this.nodeOldValues.clear();
|
|
3032
|
+
this.observer = new MutationObserver(function(mutations) {
|
|
3033
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
3034
|
+
try {
|
|
3035
|
+
for(var _iterator = mutations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
3036
|
+
var m = _step.value;
|
|
3037
|
+
if (m.type === 'childList') {
|
|
3038
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
3039
|
+
try {
|
|
3040
|
+
for(var _iterator1 = Array.from(m.addedNodes)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
3041
|
+
var node = _step1.value;
|
|
3042
|
+
if (node.nodeType === Node.TEXT_NODE && !_this.nodeOldValues.has(node)) {
|
|
3043
|
+
_this.nodeOldValues.set(node, null);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
} catch (err) {
|
|
3047
|
+
_didIteratorError1 = true;
|
|
3048
|
+
_iteratorError1 = err;
|
|
3049
|
+
} finally{
|
|
3050
|
+
try {
|
|
3051
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
3052
|
+
_iterator1.return();
|
|
3053
|
+
}
|
|
3054
|
+
} finally{
|
|
3055
|
+
if (_didIteratorError1) {
|
|
3056
|
+
throw _iteratorError1;
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
} else if (m.type === 'characterData') {
|
|
3061
|
+
var _$target = m.target;
|
|
3062
|
+
if (!_this.nodeOldValues.has(_$target)) {
|
|
3063
|
+
_this.nodeOldValues.set(_$target, m.oldValue);
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
} catch (err) {
|
|
3068
|
+
_didIteratorError = true;
|
|
3069
|
+
_iteratorError = err;
|
|
3070
|
+
} finally{
|
|
3071
|
+
try {
|
|
3072
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
3073
|
+
_iterator.return();
|
|
3074
|
+
}
|
|
3075
|
+
} finally{
|
|
3076
|
+
if (_didIteratorError) {
|
|
3077
|
+
throw _iteratorError;
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
});
|
|
3082
|
+
this.observer.observe(target, {
|
|
3083
|
+
childList: true,
|
|
3084
|
+
subtree: true,
|
|
3085
|
+
characterData: true,
|
|
3086
|
+
characterDataOldValue: true
|
|
3087
|
+
});
|
|
3088
|
+
}
|
|
3089
|
+
},
|
|
3090
|
+
{
|
|
3091
|
+
key: "readText",
|
|
3092
|
+
value: function readText() {
|
|
3093
|
+
var text = '';
|
|
3094
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
3095
|
+
try {
|
|
3096
|
+
for(var _iterator = this.nodeOldValues[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
3097
|
+
var _step_value = _sliced_to_array(_step.value, 2), node = _step_value[0], oldValue = _step_value[1];
|
|
3098
|
+
if (!node.isConnected) continue;
|
|
3099
|
+
var current = node.textContent || '';
|
|
3100
|
+
if (!current) continue;
|
|
3101
|
+
if (oldValue === null) {
|
|
3102
|
+
text += current;
|
|
3103
|
+
} else {
|
|
3104
|
+
text += this.diffText(oldValue, current);
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
} catch (err) {
|
|
3108
|
+
_didIteratorError = true;
|
|
3109
|
+
_iteratorError = err;
|
|
3110
|
+
} finally{
|
|
3111
|
+
try {
|
|
3112
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
3113
|
+
_iterator.return();
|
|
3114
|
+
}
|
|
3115
|
+
} finally{
|
|
3116
|
+
if (_didIteratorError) {
|
|
3117
|
+
throw _iteratorError;
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
return text;
|
|
3122
|
+
}
|
|
3123
|
+
},
|
|
3124
|
+
{
|
|
3125
|
+
/** 移除 composition 期间浏览器创建的文本节点(焦点处),光标位置不可能被协作触及 */ key: "cleanup",
|
|
3126
|
+
value: function cleanup(committedText, focusNode) {
|
|
3127
|
+
if (_instanceof$1(focusNode, Text) && focusNode.isConnected && focusNode.textContent === committedText && this.nodeOldValues.has(focusNode) && focusNode.parentNode) {
|
|
3128
|
+
focusNode.parentNode.removeChild(focusNode);
|
|
3129
|
+
}
|
|
3130
|
+
this.nodeOldValues.clear();
|
|
3131
|
+
}
|
|
3132
|
+
},
|
|
3133
|
+
{
|
|
3134
|
+
key: "stop",
|
|
3135
|
+
value: function stop() {
|
|
3136
|
+
var _this_observer;
|
|
3137
|
+
(_this_observer = this.observer) === null || _this_observer === void 0 ? void 0 : _this_observer.disconnect();
|
|
3138
|
+
this.observer = null;
|
|
3139
|
+
}
|
|
3140
|
+
},
|
|
3141
|
+
{
|
|
3142
|
+
key: "diffText",
|
|
3143
|
+
value: function diffText(oldStr, newStr) {
|
|
3144
|
+
var start = 0;
|
|
3145
|
+
while(start < oldStr.length && start < newStr.length && oldStr[start] === newStr[start]){
|
|
3146
|
+
start++;
|
|
3147
|
+
}
|
|
3148
|
+
var oldEnd = oldStr.length - 1;
|
|
3149
|
+
var newEnd = newStr.length - 1;
|
|
3150
|
+
while(oldEnd >= start && newEnd >= start && oldStr[oldEnd] === newStr[newEnd]){
|
|
3151
|
+
oldEnd--;
|
|
3152
|
+
newEnd--;
|
|
3153
|
+
}
|
|
3154
|
+
return newStr.slice(start, newEnd + 1);
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
]);
|
|
3158
|
+
return CompositionRecorder;
|
|
3159
|
+
}();
|
|
2894
3160
|
var NativeCaret = /*#__PURE__*/ function() {
|
|
2895
3161
|
function NativeCaret() {
|
|
2896
3162
|
_class_call_check$1(this, NativeCaret);
|
|
@@ -2962,8 +3228,7 @@ var NativeInput = /*#__PURE__*/ function(Input) {
|
|
|
2962
3228
|
_class_call_check$1(this, NativeInput);
|
|
2963
3229
|
var _this;
|
|
2964
3230
|
_this = _call_super(this, NativeInput), _define_property$1(_this, "parser", void 0), _define_property$1(_this, "selection", void 0), _define_property$1(_this, "keyboard", void 0), _define_property$1(_this, "domAdapter", void 0), _define_property$1(_this, "commander", void 0), _define_property$1(_this, "controller", void 0), _define_property$1(_this, "caret", void 0), _define_property$1(_this, "composition", void 0), // compositionState: CompositionState | null = null
|
|
2965
|
-
_define_property$1(_this, "onReady", void 0), _define_property$1(_this, "_disabled", void 0), _define_property$1(_this, "documentView", void 0), _define_property$1(_this, "nativeSelection", void 0), _define_property$1(_this, "subscription", void 0), _define_property$1(_this, "nativeRange", void 0), _define_property$1(_this, "isSafari", void 0), _define_property$1(_this, "isMac", void 0), _define_property$1(_this, "
|
|
2966
|
-
), _this.parser = parser, _this.selection = selection, _this.keyboard = keyboard, _this.domAdapter = domAdapter, _this.commander = commander, _this.controller = controller, _this.caret = new NativeCaret(), _this.composition = false, _this.onReady = Promise.resolve(), _this._disabled = false, _this.nativeSelection = document.getSelection(), _this.subscription = new Subscription(), _this.nativeRange = null, _this.isSafari = isSafari(), _this.isMac = isMac(), _this.isMobileBrowser = isMobileBrowser(), _this.ignoreComposition = false;
|
|
3231
|
+
_define_property$1(_this, "onReady", void 0), _define_property$1(_this, "_disabled", void 0), _define_property$1(_this, "documentView", void 0), _define_property$1(_this, "nativeSelection", void 0), _define_property$1(_this, "subscription", void 0), _define_property$1(_this, "nativeRange", void 0), _define_property$1(_this, "isSafari", void 0), _define_property$1(_this, "isMac", void 0), _define_property$1(_this, "compositionEndedAt", void 0), _this.parser = parser, _this.selection = selection, _this.keyboard = keyboard, _this.domAdapter = domAdapter, _this.commander = commander, _this.controller = controller, _this.caret = new NativeCaret(), _this.composition = false, _this.onReady = Promise.resolve(), _this._disabled = false, _this.nativeSelection = document.getSelection(), _this.subscription = new Subscription(), _this.nativeRange = null, _this.isSafari = isSafari(), _this.isMac = isMac(), _this.compositionEndedAt = 0;
|
|
2967
3232
|
_this.documentView = textbus.get(VIEW_DOCUMENT);
|
|
2968
3233
|
if (!controller.readonly) {
|
|
2969
3234
|
_this.documentView.contentEditable = 'true';
|
|
@@ -3111,27 +3376,15 @@ var NativeInput = /*#__PURE__*/ function(Input) {
|
|
|
3111
3376
|
key: "handleShortcut",
|
|
3112
3377
|
value: function handleShortcut(input) {
|
|
3113
3378
|
var _this = this;
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
isWriting = false;
|
|
3120
|
-
}), fromEvent(input, 'beforeinput').subscribe(function(ev) {
|
|
3121
|
-
if (_this.isSafari) {
|
|
3122
|
-
if (ev.inputType === 'insertFromComposition') {
|
|
3123
|
-
isIgnore = true;
|
|
3124
|
-
}
|
|
3125
|
-
}
|
|
3126
|
-
}), fromEvent(input, 'keydown').pipe(filter(function() {
|
|
3127
|
-
if (_this.isSafari && isIgnore) {
|
|
3128
|
-
isIgnore = false;
|
|
3379
|
+
this.subscription.add(fromEvent(input, 'keydown').pipe(filter(function() {
|
|
3380
|
+
// Safari: IME 确认键(Enter)会在 compositionend 后紧接着触发 keydown
|
|
3381
|
+
// 用时间戳窗口检测并忽略
|
|
3382
|
+
if (_this.isSafari && _this.compositionEndedAt > 0 && Date.now() - _this.compositionEndedAt < 500) {
|
|
3383
|
+
_this.compositionEndedAt = 0;
|
|
3129
3384
|
return false;
|
|
3130
3385
|
}
|
|
3131
|
-
return !
|
|
3132
|
-
;
|
|
3386
|
+
return !_this.composition;
|
|
3133
3387
|
})).subscribe(function(ev) {
|
|
3134
|
-
_this.ignoreComposition = false;
|
|
3135
3388
|
var key = ev.key;
|
|
3136
3389
|
var keys = ')!@#$%^Z&*(';
|
|
3137
3390
|
var b = key === 'Process' && /Digit\d/.test(ev.code) && ev.shiftKey;
|
|
@@ -3151,7 +3404,6 @@ var NativeInput = /*#__PURE__*/ function(Input) {
|
|
|
3151
3404
|
}
|
|
3152
3405
|
});
|
|
3153
3406
|
if (is) {
|
|
3154
|
-
_this.ignoreComposition = true;
|
|
3155
3407
|
ev.preventDefault();
|
|
3156
3408
|
}
|
|
3157
3409
|
}));
|
|
@@ -3160,101 +3412,70 @@ var NativeInput = /*#__PURE__*/ function(Input) {
|
|
|
3160
3412
|
{
|
|
3161
3413
|
key: "handleInput",
|
|
3162
3414
|
value: function handleInput(input) {
|
|
3163
|
-
if (this.isMobileBrowser) {
|
|
3164
|
-
this.handleMobileInput(input);
|
|
3165
|
-
} else {
|
|
3166
|
-
this.handlePCInput(input);
|
|
3167
|
-
}
|
|
3168
|
-
}
|
|
3169
|
-
},
|
|
3170
|
-
{
|
|
3171
|
-
key: "handleMobileInput",
|
|
3172
|
-
value: function handleMobileInput(input) {
|
|
3173
3415
|
var _this = this;
|
|
3174
|
-
var
|
|
3175
|
-
var startIndex;
|
|
3176
|
-
|
|
3416
|
+
var recorder = new CompositionRecorder();
|
|
3417
|
+
var startIndex = 0;
|
|
3418
|
+
this.subscription.add(// ===== Composition 事件:纯开关,不读 ev.data 做模型决策 =====
|
|
3419
|
+
fromEvent(input, 'compositionstart').subscribe(function() {
|
|
3177
3420
|
_this.composition = true;
|
|
3421
|
+
recorder.start(input);
|
|
3178
3422
|
startIndex = _this.selection.startOffset;
|
|
3179
3423
|
var startSlot = _this.selection.startSlot;
|
|
3180
3424
|
var event = new Event(startSlot, {
|
|
3181
3425
|
index: startIndex
|
|
3182
3426
|
});
|
|
3183
3427
|
invokeListener(startSlot.parent, 'onCompositionStart', event);
|
|
3184
|
-
}
|
|
3185
|
-
var compositionUpdate = function compositionUpdate(data) {
|
|
3428
|
+
}), fromEvent(input, 'compositionupdate').subscribe(function(ev) {
|
|
3186
3429
|
var startSlot = _this.selection.startSlot;
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3430
|
+
if (startSlot) {
|
|
3431
|
+
invokeListener(startSlot.parent, 'onCompositionUpdate', new Event(startSlot, {
|
|
3432
|
+
index: startIndex,
|
|
3433
|
+
data: ev.data
|
|
3434
|
+
}));
|
|
3435
|
+
}
|
|
3436
|
+
}), fromEvent(input, 'compositionend').subscribe(function() {
|
|
3437
|
+
if (!_this.composition) return;
|
|
3194
3438
|
_this.composition = false;
|
|
3195
|
-
|
|
3196
|
-
|
|
3439
|
+
_this.compositionEndedAt = Date.now();
|
|
3440
|
+
// Safari: WebKit 在 compositionend 之后才更新 DOM,通过 microtask 延迟读取
|
|
3441
|
+
if (_this.isSafari) {
|
|
3442
|
+
queueMicrotask(function() {
|
|
3443
|
+
return _this.syncCompositionText(recorder);
|
|
3444
|
+
});
|
|
3445
|
+
} else {
|
|
3446
|
+
_this.syncCompositionText(recorder);
|
|
3197
3447
|
}
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3448
|
+
}), // ===== beforeinput:仅处理非 IME 输入 =====
|
|
3449
|
+
fromEvent(input, 'beforeinput').subscribe(function(ev) {
|
|
3450
|
+
if (ev.isComposing || _this.composition) {
|
|
3451
|
+
return;
|
|
3202
3452
|
}
|
|
3203
|
-
|
|
3204
|
-
this.subscription.add(fromEvent(input, 'compositionstart').subscribe(function() {
|
|
3205
|
-
compositionStart();
|
|
3206
|
-
}), fromEvent(input, 'compositionupdate').subscribe(function(ev) {
|
|
3207
|
-
compositionUpdate(ev.data);
|
|
3208
|
-
}), fromEvent(input, 'compositionend').subscribe(function(ev) {
|
|
3209
|
-
compositionEnd(ev.data);
|
|
3210
|
-
var startContainer = _this.nativeSelection.focusNode;
|
|
3211
|
-
if (_instanceof$1(startContainer, Text) && startContainer.textContent === ev.data) {
|
|
3212
|
-
startContainer.remove();
|
|
3213
|
-
}
|
|
3214
|
-
}), fromEvent(input, 'beforeinput').subscribe(function(ev) {
|
|
3453
|
+
ev.preventDefault();
|
|
3215
3454
|
switch(ev.inputType){
|
|
3216
3455
|
case 'insertText':
|
|
3217
3456
|
if (ev.data) {
|
|
3218
3457
|
_this.commander.write(ev.data);
|
|
3219
|
-
ev.preventDefault();
|
|
3220
3458
|
}
|
|
3221
3459
|
break;
|
|
3222
|
-
case '
|
|
3223
|
-
|
|
3224
|
-
isCompositionStart = false;
|
|
3225
|
-
compositionStart();
|
|
3226
|
-
} else {
|
|
3227
|
-
compositionUpdate(ev.data || '');
|
|
3228
|
-
}
|
|
3460
|
+
case 'deleteContentBackward':
|
|
3461
|
+
_this.commander.delete(true);
|
|
3229
3462
|
break;
|
|
3230
|
-
case '
|
|
3231
|
-
_this.
|
|
3463
|
+
case 'deleteContentForward':
|
|
3464
|
+
_this.commander.delete();
|
|
3232
3465
|
break;
|
|
3233
|
-
case 'deleteContentBackward':
|
|
3234
|
-
{
|
|
3235
|
-
_this.composition = false;
|
|
3236
|
-
var range = ev.getTargetRanges()[0];
|
|
3237
|
-
if (!range) {
|
|
3238
|
-
break;
|
|
3239
|
-
}
|
|
3240
|
-
var location = _this.domAdapter.getLocationByNativeNode(range.startContainer);
|
|
3241
|
-
var startSlot = _this.selection.startSlot;
|
|
3242
|
-
if (startSlot) {
|
|
3243
|
-
_this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
|
|
3244
|
-
_this.commander.delete();
|
|
3245
|
-
}
|
|
3246
|
-
break;
|
|
3247
|
-
}
|
|
3248
3466
|
case 'insertReplacementText':
|
|
3249
3467
|
{
|
|
3250
3468
|
var _ev_dataTransfer;
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3469
|
+
var range = ev.getTargetRanges()[0];
|
|
3470
|
+
if (range) {
|
|
3471
|
+
var location = _this.domAdapter.getLocationByNativeNode(range.startContainer);
|
|
3472
|
+
if (location) {
|
|
3473
|
+
var startSlot = _this.selection.startSlot;
|
|
3474
|
+
_this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
|
|
3475
|
+
_this.commander.delete();
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
var text = ((_ev_dataTransfer = ev.dataTransfer) === null || _ev_dataTransfer === void 0 ? void 0 : _ev_dataTransfer.getData('text')) || ev.data;
|
|
3258
3479
|
if (text) {
|
|
3259
3480
|
_this.commander.write(text);
|
|
3260
3481
|
}
|
|
@@ -3265,89 +3486,19 @@ var NativeInput = /*#__PURE__*/ function(Input) {
|
|
|
3265
3486
|
}
|
|
3266
3487
|
},
|
|
3267
3488
|
{
|
|
3268
|
-
key: "
|
|
3269
|
-
value: function
|
|
3270
|
-
var
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
});
|
|
3282
|
-
invokeListener(startSlot.parent, 'onCompositionStart', event);
|
|
3283
|
-
}), fromEvent(input, 'compositionupdate').pipe(filter(function() {
|
|
3284
|
-
return !_this.ignoreComposition;
|
|
3285
|
-
})).subscribe(function(ev) {
|
|
3286
|
-
var startSlot = _this.selection.startSlot;
|
|
3287
|
-
var event = new Event(startSlot, {
|
|
3288
|
-
index: startIndex,
|
|
3289
|
-
data: ev.data
|
|
3290
|
-
});
|
|
3291
|
-
invokeListener(startSlot.parent, 'onCompositionUpdate', event);
|
|
3292
|
-
}), merge(fromEvent(input, 'beforeinput').pipe(map(function(ev) {
|
|
3293
|
-
ev.preventDefault();
|
|
3294
|
-
if (ev.inputType === 'insertCompositionText') {
|
|
3295
|
-
return null;
|
|
3296
|
-
}
|
|
3297
|
-
if (ev.inputType === 'insertReplacementText') {
|
|
3298
|
-
var _ev_dataTransfer;
|
|
3299
|
-
var range = ev.getTargetRanges()[0];
|
|
3300
|
-
var location = _this.domAdapter.getLocationByNativeNode(range.startContainer);
|
|
3301
|
-
var startSlot = _this.selection.startSlot;
|
|
3302
|
-
_this.selection.setBaseAndExtent(startSlot, location.startIndex + range.startOffset, startSlot, location.startIndex + range.endOffset);
|
|
3303
|
-
_this.commander.delete();
|
|
3304
|
-
return ((_ev_dataTransfer = ev.dataTransfer) === null || _ev_dataTransfer === void 0 ? void 0 : _ev_dataTransfer.getData('text')) || ev.data || null;
|
|
3305
|
-
}
|
|
3306
|
-
isCompositionEnd = ev.inputType === 'insertFromComposition';
|
|
3307
|
-
if (isCompositionEnd && _this.composition) {
|
|
3308
|
-
return null;
|
|
3309
|
-
}
|
|
3310
|
-
if (_this.isSafari) {
|
|
3311
|
-
if (ev.inputType === 'insertText' || isCompositionEnd) {
|
|
3312
|
-
return ev.data;
|
|
3313
|
-
}
|
|
3314
|
-
}
|
|
3315
|
-
if (!ev.isComposing && !!ev.data) {
|
|
3316
|
-
return ev.data;
|
|
3317
|
-
}
|
|
3318
|
-
return null;
|
|
3319
|
-
}), filter(function(text) {
|
|
3320
|
-
return text;
|
|
3321
|
-
})), this.isSafari ? new Observable() : fromEvent(input, 'compositionend').pipe(filter(function() {
|
|
3322
|
-
return !_this.ignoreComposition;
|
|
3323
|
-
})).pipe(filter(function() {
|
|
3324
|
-
return _this.composition;
|
|
3325
|
-
}), map(function(ev) {
|
|
3326
|
-
isCompositionEnd = true;
|
|
3327
|
-
ev.preventDefault();
|
|
3328
|
-
return ev.data;
|
|
3329
|
-
}), filter(function() {
|
|
3330
|
-
var b = _this.ignoreComposition;
|
|
3331
|
-
_this.ignoreComposition = false;
|
|
3332
|
-
return !b;
|
|
3333
|
-
}))).subscribe(function(text) {
|
|
3334
|
-
_this.composition = false;
|
|
3335
|
-
if (text) {
|
|
3336
|
-
var startContainer = _this.nativeSelection.focusNode;
|
|
3337
|
-
if (_instanceof$1(startContainer, Text) && startContainer.textContent === text) {
|
|
3338
|
-
startContainer.remove();
|
|
3339
|
-
}
|
|
3340
|
-
_this.commander.write(text);
|
|
3341
|
-
}
|
|
3342
|
-
if (isCompositionEnd) {
|
|
3343
|
-
var startSlot = _this.selection.startSlot;
|
|
3344
|
-
if (startSlot) {
|
|
3345
|
-
var event = new Event(startSlot, null);
|
|
3346
|
-
invokeListener(startSlot.parent, 'onCompositionEnd', event);
|
|
3347
|
-
}
|
|
3348
|
-
}
|
|
3349
|
-
isCompositionEnd = false;
|
|
3350
|
-
}));
|
|
3489
|
+
key: "syncCompositionText",
|
|
3490
|
+
value: function syncCompositionText(recorder) {
|
|
3491
|
+
var text = recorder.readText();
|
|
3492
|
+
recorder.stop();
|
|
3493
|
+
if (text) {
|
|
3494
|
+
// 先清理 composition 期间浏览器创建的节点,确保写入模型时 DOM 是干净的
|
|
3495
|
+
recorder.cleanup(text, this.nativeSelection.focusNode);
|
|
3496
|
+
this.commander.write(text);
|
|
3497
|
+
}
|
|
3498
|
+
var startSlot = this.selection.startSlot;
|
|
3499
|
+
if (startSlot) {
|
|
3500
|
+
invokeListener(startSlot.parent, 'onCompositionEnd', new Event(startSlot, null));
|
|
3501
|
+
}
|
|
3351
3502
|
}
|
|
3352
3503
|
}
|
|
3353
3504
|
]);
|