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