@wangeditor-next/editor 5.6.36 → 5.6.38
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/core/src/config/interface.d.ts +3 -4
- package/dist/core/src/upload/interface.d.ts +13 -5
- package/dist/css/style.css +7 -8
- package/dist/index.js +843 -288
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/index.mjs.map +1 -1
- package/dist/table-module/src/module/menu/MergeCell.d.ts +0 -1
- package/dist/table-module/src/module/pre-parse-html.d.ts +1 -1
- package/dist/video-module/src/module/menu/index.d.ts +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -13866,7 +13866,7 @@
|
|
|
13866
13866
|
// 传入 html ,转换为 JSON content
|
|
13867
13867
|
editor.children = htmlToContent(editor, html);
|
|
13868
13868
|
}
|
|
13869
|
-
if (content && content.length) {
|
|
13869
|
+
else if (content && content.length) {
|
|
13870
13870
|
editor.children = content; // 传入 JSON content
|
|
13871
13871
|
}
|
|
13872
13872
|
if (editor.children.length === 0) {
|
|
@@ -32473,7 +32473,9 @@
|
|
|
32473
32473
|
CodeBlockMenu.prototype.getValue = function (editor) {
|
|
32474
32474
|
var elem = this.getSelectCodeElem(editor);
|
|
32475
32475
|
if (elem == null) {
|
|
32476
|
-
|
|
32476
|
+
var _a = editor.getMenuConfig('codeSelectLang').codeLangs, codeLangs = _a === void 0 ? [] : _a;
|
|
32477
|
+
var selectItem = codeLangs.find(function (item) { return item.selected; });
|
|
32478
|
+
return (selectItem === null || selectItem === void 0 ? void 0 : selectItem.value) || '';
|
|
32477
32479
|
}
|
|
32478
32480
|
return elem.language || '';
|
|
32479
32481
|
};
|
|
@@ -39038,9 +39040,12 @@
|
|
|
39038
39040
|
}
|
|
39039
39041
|
function tableCellToHtml(cellNode, childrenHtml) {
|
|
39040
39042
|
var _a = cellNode, _b = _a.colSpan, colSpan = _b === void 0 ? 1 : _b, _c = _a.rowSpan, rowSpan = _c === void 0 ? 1 : _c, _d = _a.isHeader, isHeader = _d === void 0 ? false : _d, _e = _a.width, width = _e === void 0 ? 'auto' : _e, _f = _a.hidden, hidden = _f === void 0 ? false : _f;
|
|
39043
|
+
// 如果单元格被隐藏,直接返回空字符串,不生成 HTML 元素
|
|
39044
|
+
if (hidden) {
|
|
39045
|
+
return '';
|
|
39046
|
+
}
|
|
39041
39047
|
var tag = isHeader ? 'th' : 'td';
|
|
39042
|
-
|
|
39043
|
-
return "<".concat(tag, " colSpan=\"").concat(colSpan, "\" rowSpan=\"").concat(rowSpan, "\" width=\"").concat(width, "\" style=\"").concat(style, "\">").concat(childrenHtml, "</").concat(tag, ">");
|
|
39048
|
+
return "<".concat(tag, " colSpan=\"").concat(colSpan, "\" rowSpan=\"").concat(rowSpan, "\" width=\"").concat(width, "\">").concat(childrenHtml, "</").concat(tag, ">");
|
|
39044
39049
|
}
|
|
39045
39050
|
var tableToHtmlConf = {
|
|
39046
39051
|
type: 'table',
|
|
@@ -39227,25 +39232,45 @@
|
|
|
39227
39232
|
for (var _b = __values(matrices(editor, { at: options.at })), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
39228
39233
|
var matrix = _c.value;
|
|
39229
39234
|
var filledSection = [];
|
|
39235
|
+
// 首先,找出最大的列数来确定矩阵的宽度
|
|
39236
|
+
var maxCols = 0;
|
|
39237
|
+
for (var x = 0; x < matrix.length; x += 1) {
|
|
39238
|
+
if (matrix[x]) {
|
|
39239
|
+
maxCols = Math.max(maxCols, matrix[x].length);
|
|
39240
|
+
}
|
|
39241
|
+
}
|
|
39230
39242
|
for (var x = 0; x < matrix.length; x += 1) {
|
|
39231
39243
|
if (!filledSection[x]) {
|
|
39232
39244
|
filledSection[x] = [];
|
|
39233
39245
|
}
|
|
39246
|
+
if (!matrix[x]) {
|
|
39247
|
+
continue;
|
|
39248
|
+
}
|
|
39234
39249
|
for (var y = 0; y < matrix[x].length; y += 1) {
|
|
39250
|
+
if (!matrix[x][y] || !matrix[x][y][0]) {
|
|
39251
|
+
continue;
|
|
39252
|
+
}
|
|
39235
39253
|
var _d = __read(matrix[x][y], 1), _e = _d[0], _f = _e.rowSpan, rowSpan = _f === void 0 ? 1 : _f, _g = _e.colSpan, colSpan = _g === void 0 ? 1 : _g;
|
|
39236
|
-
|
|
39254
|
+
// 找到下一个可用的位置
|
|
39255
|
+
var startCol = y;
|
|
39256
|
+
while (filledSection[x] && filledSection[x][startCol]) {
|
|
39257
|
+
startCol += 1;
|
|
39258
|
+
}
|
|
39259
|
+
for (var c = 0; c < colSpan; c += 1) {
|
|
39237
39260
|
for (var r = 0; r < rowSpan; r += 1) {
|
|
39238
|
-
|
|
39239
|
-
|
|
39261
|
+
var targetX = x + r;
|
|
39262
|
+
var targetY = startCol + c;
|
|
39263
|
+
if (!filledSection[targetX]) {
|
|
39264
|
+
filledSection[targetX] = [];
|
|
39240
39265
|
}
|
|
39241
|
-
if (filledSection[
|
|
39266
|
+
if (filledSection[targetX][targetY]) {
|
|
39242
39267
|
continue;
|
|
39243
39268
|
}
|
|
39244
|
-
filledSection[
|
|
39245
|
-
matrix[x
|
|
39269
|
+
filledSection[targetX][targetY] = [
|
|
39270
|
+
matrix[x][y],
|
|
39246
39271
|
{
|
|
39247
|
-
rtl: c
|
|
39248
|
-
ltr: colSpan - c
|
|
39272
|
+
rtl: c + 1,
|
|
39273
|
+
ltr: colSpan - c,
|
|
39249
39274
|
ttb: r + 1,
|
|
39250
39275
|
btt: rowSpan - r,
|
|
39251
39276
|
},
|
|
@@ -39636,58 +39661,92 @@
|
|
|
39636
39661
|
}
|
|
39637
39662
|
distExports$1.Editor.withoutNormalizing(editor, function () {
|
|
39638
39663
|
var e_1, _a;
|
|
39664
|
+
// 记录需要删除的单元格路径和已处理的合并单元格
|
|
39665
|
+
var cellsToDelete = new Set();
|
|
39666
|
+
var processedMergedCells = new Set();
|
|
39667
|
+
// 遍历每一行的第 tdIndex 列
|
|
39639
39668
|
for (var x = 0; x < matrix.length; x += 1) {
|
|
39640
|
-
|
|
39641
|
-
|
|
39642
|
-
|
|
39643
|
-
|
|
39644
|
-
|
|
39645
|
-
|
|
39646
|
-
|
|
39647
|
-
|
|
39648
|
-
|
|
39669
|
+
if (!matrix[x] || !matrix[x][tdIndex]) {
|
|
39670
|
+
continue;
|
|
39671
|
+
}
|
|
39672
|
+
var _b = __read(matrix[x][tdIndex], 2), _c = __read(_b[0], 2), cellPath = _c[1], _d = _b[1], rtl = _d.rtl, ltr = _d.ltr, ttb = _d.ttb, btt = _d.btt;
|
|
39673
|
+
var cellPathKey = cellPath.join(',');
|
|
39674
|
+
// 判断是否是合并单元格
|
|
39675
|
+
if (rtl > 1 || ltr > 1 || ttb > 1 || btt > 1) {
|
|
39676
|
+
// 这是合并单元格的一部分
|
|
39677
|
+
// 找到真实单元格的位置(左上角的位置)
|
|
39678
|
+
// rtl表示从右到左的距离,所以真实单元格列 = 当前列 - (rtl - 1)
|
|
39679
|
+
// ttb表示从上到下的距离,所以真实单元格行 = 当前行 - (ttb - 1)
|
|
39680
|
+
var realCellRow = x - (ttb - 1);
|
|
39681
|
+
var realCellCol = tdIndex - (rtl - 1);
|
|
39682
|
+
// 安全检查:确保真实单元格位置存在
|
|
39683
|
+
if (realCellRow < 0 || realCellRow >= matrix.length
|
|
39684
|
+
|| !matrix[realCellRow] || !matrix[realCellRow][realCellCol]) {
|
|
39685
|
+
continue;
|
|
39649
39686
|
}
|
|
39650
|
-
|
|
39651
|
-
|
|
39687
|
+
var _e = __read(matrix[realCellRow][realCellCol], 1), _f = __read(_e[0], 2), realCellElement = _f[0], realCellPath = _f[1];
|
|
39688
|
+
var realCellPathKey = realCellPath.join(',');
|
|
39689
|
+
// 避免重复处理同一个合并单元格
|
|
39690
|
+
if (!processedMergedCells.has(realCellPathKey)) {
|
|
39691
|
+
processedMergedCells.add(realCellPathKey);
|
|
39692
|
+
var _g = realCellElement.rowSpan, rowSpan = _g === void 0 ? 1 : _g, _h = realCellElement.colSpan, colSpan = _h === void 0 ? 1 : _h;
|
|
39693
|
+
var newColSpan = Math.max(colSpan - 1, 1);
|
|
39694
|
+
// 更新真实单元格的 colSpan
|
|
39652
39695
|
distExports$1.Transforms.setNodes(editor, {
|
|
39653
39696
|
rowSpan: rowSpan,
|
|
39654
|
-
colSpan:
|
|
39655
|
-
|
|
39656
|
-
|
|
39657
|
-
|
|
39658
|
-
|
|
39659
|
-
|
|
39660
|
-
|
|
39661
|
-
|
|
39662
|
-
|
|
39663
|
-
|
|
39664
|
-
|
|
39665
|
-
|
|
39666
|
-
|
|
39667
|
-
|
|
39668
|
-
|
|
39669
|
-
|
|
39670
|
-
|
|
39671
|
-
|
|
39672
|
-
|
|
39697
|
+
colSpan: newColSpan,
|
|
39698
|
+
}, { at: realCellPath });
|
|
39699
|
+
}
|
|
39700
|
+
}
|
|
39701
|
+
else {
|
|
39702
|
+
// rtl = 1 且 ltr = 1 且 ttb = 1 且 btt = 1,说明这是独立的单元格,直接删除
|
|
39703
|
+
cellsToDelete.add(cellPathKey);
|
|
39704
|
+
}
|
|
39705
|
+
}
|
|
39706
|
+
// 删除独立的单元格
|
|
39707
|
+
var cellsToDeleteArray = Array.from(cellsToDelete);
|
|
39708
|
+
// 按路径深度降序排序,确保从深层到浅层删除,避免路径失效
|
|
39709
|
+
cellsToDeleteArray.sort(function (a, b) {
|
|
39710
|
+
var pathA = a.split(',').map(Number);
|
|
39711
|
+
var pathB = b.split(',').map(Number);
|
|
39712
|
+
// 按行降序排序
|
|
39713
|
+
if (pathA[pathA.length - 2] !== pathB[pathB.length - 2]) {
|
|
39714
|
+
return pathB[pathB.length - 2] - pathA[pathA.length - 2];
|
|
39715
|
+
}
|
|
39716
|
+
// 同行内按列降序排序
|
|
39717
|
+
return pathB[pathB.length - 1] - pathA[pathA.length - 1];
|
|
39718
|
+
});
|
|
39719
|
+
try {
|
|
39720
|
+
for (var cellsToDeleteArray_1 = __values(cellsToDeleteArray), cellsToDeleteArray_1_1 = cellsToDeleteArray_1.next(); !cellsToDeleteArray_1_1.done; cellsToDeleteArray_1_1 = cellsToDeleteArray_1.next()) {
|
|
39721
|
+
var pathKey = cellsToDeleteArray_1_1.value;
|
|
39722
|
+
var path = pathKey.split(',').map(Number);
|
|
39723
|
+
try {
|
|
39724
|
+
if (distExports$1.Editor.hasPath(editor, path)) {
|
|
39725
|
+
distExports$1.Transforms.removeNodes(editor, { at: path });
|
|
39673
39726
|
}
|
|
39674
39727
|
}
|
|
39728
|
+
catch (error) {
|
|
39729
|
+
console.warn('删除单元格失败:', path, error);
|
|
39730
|
+
}
|
|
39675
39731
|
}
|
|
39676
39732
|
}
|
|
39677
|
-
|
|
39678
|
-
|
|
39679
|
-
|
|
39680
|
-
|
|
39733
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
39734
|
+
finally {
|
|
39735
|
+
try {
|
|
39736
|
+
if (cellsToDeleteArray_1_1 && !cellsToDeleteArray_1_1.done && (_a = cellsToDeleteArray_1.return)) _a.call(cellsToDeleteArray_1);
|
|
39737
|
+
}
|
|
39738
|
+
finally { if (e_1) throw e_1.error; }
|
|
39681
39739
|
}
|
|
39682
|
-
//
|
|
39683
|
-
var
|
|
39740
|
+
// 调整表格的 columnWidths
|
|
39741
|
+
var _j = __read(distExports$1.Editor.nodes(editor, {
|
|
39684
39742
|
match: function (n) { return DomEditor.checkNodeType(n, 'table'); },
|
|
39685
39743
|
universal: true,
|
|
39686
|
-
}), 1), tableEntry =
|
|
39744
|
+
}), 1), tableEntry = _j[0];
|
|
39687
39745
|
if (tableEntry) {
|
|
39688
|
-
var
|
|
39689
|
-
var
|
|
39746
|
+
var _k = __read(tableEntry, 2), elemNode = _k[0], tablePath = _k[1];
|
|
39747
|
+
var _l = elemNode.columnWidths, columnWidths = _l === void 0 ? [] : _l;
|
|
39690
39748
|
var adjustColumnWidths = __spreadArray([], __read(columnWidths), false);
|
|
39749
|
+
// 删除对应列的宽度
|
|
39691
39750
|
adjustColumnWidths.splice(tdIndex, 1);
|
|
39692
39751
|
distExports$1.Transforms.setNodes(editor, { columnWidths: adjustColumnWidths }, {
|
|
39693
39752
|
at: tablePath,
|
|
@@ -39769,47 +39828,130 @@
|
|
|
39769
39828
|
}
|
|
39770
39829
|
distExports$1.Editor.withoutNormalizing(editor, function () {
|
|
39771
39830
|
var e_1, _a;
|
|
39831
|
+
// 收集需要在下一行插入的新单元格信息
|
|
39832
|
+
var cellsToInsert = [];
|
|
39772
39833
|
for (var y = 0; y < matrix[trIndex].length; y += 1) {
|
|
39773
|
-
var _b = __read(matrix[trIndex][y], 2), _c = __read(_b[0], 1), hidden = _c[0].hidden, _d = _b[1], ttb = _d.ttb, btt = _d.btt;
|
|
39834
|
+
var _b = __read(matrix[trIndex][y], 2), _c = __read(_b[0], 1), hidden = _c[0].hidden, _d = _b[1], ttb = _d.ttb, btt = _d.btt, rtl = _d.rtl;
|
|
39774
39835
|
// 寻找跨行行为
|
|
39775
39836
|
if (ttb > 1 || btt > 1) {
|
|
39776
39837
|
// 找到显示中 rowSpan 节点
|
|
39777
|
-
var
|
|
39778
|
-
//
|
|
39838
|
+
var originalRowIndex = trIndex - (ttb - 1);
|
|
39839
|
+
// 安全检查:确保目标行和列都存在
|
|
39840
|
+
if (originalRowIndex < 0 || originalRowIndex >= matrix.length || !matrix[originalRowIndex] || !matrix[originalRowIndex][y]) {
|
|
39841
|
+
continue;
|
|
39842
|
+
}
|
|
39843
|
+
var _e = __read(matrix[originalRowIndex][y], 1), _f = __read(_e[0], 2), originalCell = _f[0], path = _f[1];
|
|
39844
|
+
var typedOriginalCell = originalCell;
|
|
39845
|
+
var _g = typedOriginalCell.rowSpan, rowSpan = _g === void 0 ? 1 : _g, _h = typedOriginalCell.colSpan, colSpan = _h === void 0 ? 1 : _h;
|
|
39779
39846
|
if (hidden) {
|
|
39847
|
+
// 如果当前选中节点为隐藏节点,则向上寻找处理 rowSpan 逻辑
|
|
39780
39848
|
distExports$1.Transforms.setNodes(editor, {
|
|
39781
39849
|
rowSpan: Math.max(rowSpan - 1, 1),
|
|
39782
39850
|
colSpan: colSpan,
|
|
39783
39851
|
}, { at: path });
|
|
39784
39852
|
}
|
|
39853
|
+
else if (ttb === 1 && rtl === 1) {
|
|
39854
|
+
// 只处理合并单元格的真正位置(左上角):ttb=1且rtl=1
|
|
39855
|
+
// 这样避免重复处理同一个合并单元格
|
|
39856
|
+
var hasNextRow = trIndex + 1 < matrix.length;
|
|
39857
|
+
if (hasNextRow && rowSpan > 1) {
|
|
39858
|
+
// 创建新的单元格,继承原单元格的内容和属性
|
|
39859
|
+
var newCell = {
|
|
39860
|
+
type: 'table-cell',
|
|
39861
|
+
rowSpan: rowSpan - 1, // 新单元格的rowSpan = 原rowSpan - 1
|
|
39862
|
+
colSpan: colSpan, // 保持原来的colSpan
|
|
39863
|
+
hidden: false,
|
|
39864
|
+
children: typedOriginalCell.children.map(function (child) { return (__assign({}, child)); }), // 深拷贝继承原单元格的内容
|
|
39865
|
+
};
|
|
39866
|
+
// 继承原单元格的其他属性
|
|
39867
|
+
if (typedOriginalCell.isHeader) {
|
|
39868
|
+
newCell.isHeader = typedOriginalCell.isHeader;
|
|
39869
|
+
}
|
|
39870
|
+
if (typedOriginalCell.width) {
|
|
39871
|
+
newCell.width = typedOriginalCell.width;
|
|
39872
|
+
}
|
|
39873
|
+
if (typedOriginalCell.backgroundColor) {
|
|
39874
|
+
newCell.backgroundColor = typedOriginalCell.backgroundColor;
|
|
39875
|
+
}
|
|
39876
|
+
if (typedOriginalCell.borderWidth) {
|
|
39877
|
+
newCell.borderWidth = typedOriginalCell.borderWidth;
|
|
39878
|
+
}
|
|
39879
|
+
if (typedOriginalCell.borderStyle) {
|
|
39880
|
+
newCell.borderStyle = typedOriginalCell.borderStyle;
|
|
39881
|
+
}
|
|
39882
|
+
if (typedOriginalCell.borderColor) {
|
|
39883
|
+
newCell.borderColor = typedOriginalCell.borderColor;
|
|
39884
|
+
}
|
|
39885
|
+
if (typedOriginalCell.textAlign) {
|
|
39886
|
+
newCell.textAlign = typedOriginalCell.textAlign;
|
|
39887
|
+
}
|
|
39888
|
+
// 记录需要插入的单元格信息
|
|
39889
|
+
cellsToInsert.push({
|
|
39890
|
+
cell: newCell,
|
|
39891
|
+
columnIndex: y,
|
|
39892
|
+
});
|
|
39893
|
+
}
|
|
39894
|
+
else {
|
|
39895
|
+
// 如果没有下一行,直接减少原始单元格的 rowSpan
|
|
39896
|
+
distExports$1.Transforms.setNodes(editor, {
|
|
39897
|
+
rowSpan: Math.max(rowSpan - 1, 1),
|
|
39898
|
+
colSpan: colSpan,
|
|
39899
|
+
}, { at: path });
|
|
39900
|
+
}
|
|
39901
|
+
}
|
|
39785
39902
|
else {
|
|
39786
|
-
|
|
39903
|
+
// 处理其他跨行单元格的情况:非隐藏且非左上角原始位置
|
|
39904
|
+
// 这种情况下也需要减少原始单元格的 rowSpan
|
|
39787
39905
|
distExports$1.Transforms.setNodes(editor, {
|
|
39788
|
-
rowSpan: rowSpan - 1,
|
|
39906
|
+
rowSpan: Math.max(rowSpan - 1, 1),
|
|
39789
39907
|
colSpan: colSpan,
|
|
39790
|
-
|
|
39791
|
-
|
|
39792
|
-
|
|
39793
|
-
|
|
39794
|
-
|
|
39795
|
-
|
|
39796
|
-
|
|
39797
|
-
|
|
39798
|
-
|
|
39799
|
-
|
|
39800
|
-
|
|
39801
|
-
|
|
39802
|
-
|
|
39803
|
-
|
|
39908
|
+
}, { at: path });
|
|
39909
|
+
}
|
|
39910
|
+
}
|
|
39911
|
+
}
|
|
39912
|
+
// 删除当前行
|
|
39913
|
+
distExports$1.Transforms.removeNodes(editor, { at: rowPath });
|
|
39914
|
+
// 在下一行(现在变成了当前行)的对应位置插入新单元格
|
|
39915
|
+
if (cellsToInsert.length > 0) {
|
|
39916
|
+
// 删除行后,原来的下一行会移动到rowPath的位置
|
|
39917
|
+
var targetRowPath = rowPath;
|
|
39918
|
+
try {
|
|
39919
|
+
// 按列索引排序,从左到右插入
|
|
39920
|
+
cellsToInsert.sort(function (a, b) { return a.columnIndex - b.columnIndex; });
|
|
39921
|
+
try {
|
|
39922
|
+
for (var cellsToInsert_1 = __values(cellsToInsert), cellsToInsert_1_1 = cellsToInsert_1.next(); !cellsToInsert_1_1.done; cellsToInsert_1_1 = cellsToInsert_1.next()) {
|
|
39923
|
+
var _j = cellsToInsert_1_1.value, cell = _j.cell, columnIndex = _j.columnIndex;
|
|
39804
39924
|
try {
|
|
39805
|
-
|
|
39925
|
+
// 尝试在对应的列位置插入
|
|
39926
|
+
var insertPath = __spreadArray(__spreadArray([], __read(targetRowPath), false), [columnIndex], false);
|
|
39927
|
+
distExports$1.Transforms.insertNodes(editor, cell, { at: insertPath });
|
|
39806
39928
|
}
|
|
39807
|
-
|
|
39929
|
+
catch (error) {
|
|
39930
|
+
// 如果插入失败,尝试在行末尾插入
|
|
39931
|
+
try {
|
|
39932
|
+
var _k = __read(distExports$1.Editor.node(editor, targetRowPath), 1), targetRow = _k[0];
|
|
39933
|
+
var cellCount = targetRow.children.length;
|
|
39934
|
+
var endPath = __spreadArray(__spreadArray([], __read(targetRowPath), false), [cellCount], false);
|
|
39935
|
+
distExports$1.Transforms.insertNodes(editor, cell, { at: endPath });
|
|
39936
|
+
}
|
|
39937
|
+
catch (fallbackError) {
|
|
39938
|
+
console.warn('插入新单元格失败:', fallbackError);
|
|
39939
|
+
}
|
|
39940
|
+
}
|
|
39941
|
+
}
|
|
39942
|
+
}
|
|
39943
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
39944
|
+
finally {
|
|
39945
|
+
try {
|
|
39946
|
+
if (cellsToInsert_1_1 && !cellsToInsert_1_1.done && (_a = cellsToInsert_1.return)) _a.call(cellsToInsert_1);
|
|
39808
39947
|
}
|
|
39948
|
+
finally { if (e_1) throw e_1.error; }
|
|
39809
39949
|
}
|
|
39810
39950
|
}
|
|
39951
|
+
catch (error) {
|
|
39952
|
+
console.warn('插入新单元格失败:', error);
|
|
39953
|
+
}
|
|
39811
39954
|
}
|
|
39812
|
-
distExports$1.Transforms.removeNodes(editor, { at: rowPath });
|
|
39813
39955
|
});
|
|
39814
39956
|
};
|
|
39815
39957
|
return DeleteRow;
|
|
@@ -39864,7 +40006,6 @@
|
|
|
39864
40006
|
this.iconSvg = FULL_WIDTH_SVG;
|
|
39865
40007
|
this.tag = 'button';
|
|
39866
40008
|
}
|
|
39867
|
-
// 是否已设置 宽度自适应
|
|
39868
40009
|
TableFullWidth.prototype.getValue = function (editor) {
|
|
39869
40010
|
var tableNode = DomEditor.getSelectedNodeByType(editor, 'table');
|
|
39870
40011
|
if (tableNode == null) {
|
|
@@ -39976,6 +40117,47 @@
|
|
|
39976
40117
|
// 选区未处于 table cell node ,则禁用
|
|
39977
40118
|
return true;
|
|
39978
40119
|
}
|
|
40120
|
+
// 检查当前单元格的宽度是否小于20px
|
|
40121
|
+
try {
|
|
40122
|
+
var _a = __read(distExports$1.Editor.nodes(editor, {
|
|
40123
|
+
match: function (n) { return DomEditor.checkNodeType(n, 'table-cell'); },
|
|
40124
|
+
universal: true,
|
|
40125
|
+
}), 1), cellEntry = _a[0];
|
|
40126
|
+
if (!cellEntry) {
|
|
40127
|
+
return true;
|
|
40128
|
+
}
|
|
40129
|
+
var _b = __read(cellEntry, 2), selectedCellPath = _b[1];
|
|
40130
|
+
var matrix = filledMatrix(editor);
|
|
40131
|
+
var tdIndex = -1;
|
|
40132
|
+
// 找到当前单元格在矩阵中的列索引
|
|
40133
|
+
for (var x = 0; x < matrix.length; x += 1) {
|
|
40134
|
+
for (var y = 0; y < matrix[x].length; y += 1) {
|
|
40135
|
+
var _c = __read(matrix[x][y], 1), _d = __read(_c[0], 2), path = _d[1];
|
|
40136
|
+
if (distExports$1.Path.equals(selectedCellPath, path)) {
|
|
40137
|
+
tdIndex = y;
|
|
40138
|
+
break;
|
|
40139
|
+
}
|
|
40140
|
+
}
|
|
40141
|
+
if (tdIndex !== -1) {
|
|
40142
|
+
break;
|
|
40143
|
+
}
|
|
40144
|
+
}
|
|
40145
|
+
if (tdIndex === -1) {
|
|
40146
|
+
return true;
|
|
40147
|
+
}
|
|
40148
|
+
// 获取表格的列宽信息
|
|
40149
|
+
var tableElement = tableNode;
|
|
40150
|
+
var _e = tableElement.columnWidths, columnWidths = _e === void 0 ? [] : _e;
|
|
40151
|
+
// 检查当前列的宽度 - 如果小于20px则禁用插入列功能
|
|
40152
|
+
var currentColWidth = columnWidths[tdIndex];
|
|
40153
|
+
if (currentColWidth && currentColWidth < 20) {
|
|
40154
|
+
return true; // 宽度限制:当前列宽度小于20px时禁用插入列功能
|
|
40155
|
+
}
|
|
40156
|
+
}
|
|
40157
|
+
catch (error) {
|
|
40158
|
+
// 如果检查过程中出现错误,为安全起见禁用功能
|
|
40159
|
+
return true;
|
|
40160
|
+
}
|
|
39979
40161
|
return false;
|
|
39980
40162
|
};
|
|
39981
40163
|
InsertCol.prototype.exec = function (editor, _value) {
|
|
@@ -40007,48 +40189,94 @@
|
|
|
40007
40189
|
}
|
|
40008
40190
|
}
|
|
40009
40191
|
distExports$1.Editor.withoutNormalizing(editor, function () {
|
|
40010
|
-
|
|
40192
|
+
// 记录已处理的合并单元格和需要跳过插入的行
|
|
40193
|
+
var processedMergedCells = new Set();
|
|
40194
|
+
var skipInsertForRows = new Set();
|
|
40195
|
+
// 遍历每一行的第 tdIndex 列,处理合并单元格
|
|
40011
40196
|
for (var x = 0; x < matrix.length; x += 1) {
|
|
40012
|
-
|
|
40013
|
-
|
|
40014
|
-
|
|
40015
|
-
|
|
40197
|
+
// 安全检查:确保行和列都存在
|
|
40198
|
+
if (!matrix[x] || !matrix[x][tdIndex]) {
|
|
40199
|
+
continue;
|
|
40200
|
+
}
|
|
40201
|
+
var _a = __read(matrix[x][tdIndex], 2); __read(_a[0], 1); var _c = _a[1], rtl = _c.rtl, ltr = _c.ltr, ttb = _c.ttb, btt = _c.btt;
|
|
40202
|
+
// 判断是否是合并单元格
|
|
40203
|
+
if (rtl > 1 || ltr > 1 || ttb > 1 || btt > 1) {
|
|
40204
|
+
// 这是合并单元格的一部分
|
|
40205
|
+
// 找到真实单元格的位置(左上角的位置)
|
|
40206
|
+
// rtl表示从右到左的距离,所以真实单元格列 = 当前列 - (rtl - 1)
|
|
40207
|
+
// ttb表示从上到下的距离,所以真实单元格行 = 当前行 - (ttb - 1)
|
|
40208
|
+
var realCellRow = x - (ttb - 1);
|
|
40209
|
+
var realCellCol = tdIndex - (rtl - 1);
|
|
40210
|
+
// 安全检查:确保真实单元格位置存在
|
|
40211
|
+
if (realCellRow < 0 || realCellRow >= matrix.length
|
|
40212
|
+
|| !matrix[realCellRow] || !matrix[realCellRow][realCellCol]) {
|
|
40016
40213
|
continue;
|
|
40017
40214
|
}
|
|
40018
|
-
var
|
|
40019
|
-
var
|
|
40020
|
-
|
|
40021
|
-
if (!
|
|
40022
|
-
|
|
40023
|
-
|
|
40024
|
-
|
|
40215
|
+
var _d = __read(matrix[realCellRow][realCellCol], 1), _e = __read(_d[0], 2), realCellElement = _e[0], realCellPath = _e[1];
|
|
40216
|
+
var realCellPathKey = realCellPath.join(',');
|
|
40217
|
+
// 避免重复处理同一个合并单元格
|
|
40218
|
+
if (!processedMergedCells.has(realCellPathKey)) {
|
|
40219
|
+
processedMergedCells.add(realCellPathKey);
|
|
40220
|
+
var _f = realCellElement.rowSpan, rowSpan = _f === void 0 ? 1 : _f, _g = realCellElement.colSpan, colSpan = _g === void 0 ? 1 : _g;
|
|
40221
|
+
var newColSpan = colSpan + 1;
|
|
40222
|
+
// 更新真实单元格的 colSpan
|
|
40223
|
+
if (!realCellElement.hidden) {
|
|
40224
|
+
distExports$1.Transforms.setNodes(editor, {
|
|
40225
|
+
colSpan: newColSpan,
|
|
40226
|
+
}, { at: realCellPath });
|
|
40227
|
+
}
|
|
40228
|
+
// 标记所有被这个合并单元格影响的行,这些行不需要插入新的单元格
|
|
40229
|
+
// 从真实单元格的行开始,标记rowSpan行
|
|
40230
|
+
for (var r = 0; r < rowSpan; r += 1) {
|
|
40231
|
+
skipInsertForRows.add(realCellRow + r);
|
|
40232
|
+
}
|
|
40233
|
+
}
|
|
40234
|
+
else {
|
|
40235
|
+
// 如果已经处理过这个合并单元格,当前行也不需要插入新单元格
|
|
40236
|
+
skipInsertForRows.add(x);
|
|
40025
40237
|
}
|
|
40026
40238
|
}
|
|
40027
40239
|
}
|
|
40028
|
-
//
|
|
40240
|
+
// 遍历所有行,为需要插入的行添加新单元格
|
|
40029
40241
|
for (var x = 0; x < matrix.length; x += 1) {
|
|
40242
|
+
// 如果这一行被合并单元格覆盖,则不插入新单元格
|
|
40243
|
+
if (skipInsertForRows.has(x)) {
|
|
40244
|
+
continue;
|
|
40245
|
+
}
|
|
40246
|
+
// 安全检查:确保矩阵位置存在
|
|
40247
|
+
if (!matrix[x] || !matrix[x][tdIndex]) {
|
|
40248
|
+
continue;
|
|
40249
|
+
}
|
|
40030
40250
|
var newCell = {
|
|
40031
40251
|
type: 'table-cell',
|
|
40032
|
-
hidden: exitMerge.includes(x),
|
|
40033
40252
|
children: [{ text: '' }],
|
|
40034
40253
|
};
|
|
40254
|
+
// 如果是第一行且表格有标题,设置为标题单元格
|
|
40035
40255
|
if (x === 0 && isTableWithHeader(tableNode)) {
|
|
40036
40256
|
newCell.isHeader = true;
|
|
40037
40257
|
}
|
|
40038
|
-
var
|
|
40258
|
+
var _h = __read(matrix[x][tdIndex], 1), _j = __read(_h[0], 2), insertPath = _j[1];
|
|
40039
40259
|
distExports$1.Transforms.insertNodes(editor, newCell, { at: insertPath });
|
|
40040
40260
|
}
|
|
40041
|
-
//
|
|
40042
|
-
var
|
|
40261
|
+
// 调整 columnWidths
|
|
40262
|
+
var _k = __read(distExports$1.Editor.nodes(editor, {
|
|
40043
40263
|
match: function (n) { return DomEditor.checkNodeType(n, 'table'); },
|
|
40044
40264
|
universal: true,
|
|
40045
|
-
}), 1), tableEntry =
|
|
40265
|
+
}), 1), tableEntry = _k[0];
|
|
40046
40266
|
if (tableEntry) {
|
|
40047
|
-
var
|
|
40048
|
-
var
|
|
40267
|
+
var _l = __read(tableEntry, 2), elemNode = _l[0], tablePath = _l[1];
|
|
40268
|
+
var _m = elemNode.columnWidths, columnWidths = _m === void 0 ? [] : _m;
|
|
40049
40269
|
var adjustColumnWidths = __spreadArray([], __read(columnWidths), false);
|
|
40050
|
-
|
|
40051
|
-
|
|
40270
|
+
// 获取当前列的宽度,如果没有设置则使用默认宽度
|
|
40271
|
+
var _o = editor.getMenuConfig('insertTable').minWidth, minWidth = _o === void 0 ? 60 : _o;
|
|
40272
|
+
var currentColWidth = columnWidths[tdIndex] || parseInt(minWidth, 10) || 60;
|
|
40273
|
+
// 将当前列宽度一分为二
|
|
40274
|
+
var halfWidth = Math.floor(currentColWidth / 2);
|
|
40275
|
+
var remainingWidth = currentColWidth - halfWidth;
|
|
40276
|
+
// 在当前位置插入新列(左侧),使用一半宽度
|
|
40277
|
+
adjustColumnWidths.splice(tdIndex, 0, halfWidth);
|
|
40278
|
+
// 更新原列宽度为剩余的一半
|
|
40279
|
+
adjustColumnWidths[tdIndex + 1] = remainingWidth;
|
|
40052
40280
|
distExports$1.Transforms.setNodes(editor, { columnWidths: adjustColumnWidths }, {
|
|
40053
40281
|
at: tablePath,
|
|
40054
40282
|
});
|
|
@@ -40092,20 +40320,15 @@
|
|
|
40092
40320
|
return false;
|
|
40093
40321
|
};
|
|
40094
40322
|
InsertRow.prototype.exec = function (editor, _value) {
|
|
40323
|
+
var _a;
|
|
40095
40324
|
if (this.isDisabled(editor)) {
|
|
40096
40325
|
return;
|
|
40097
40326
|
}
|
|
40098
|
-
var
|
|
40327
|
+
var _b = __read(distExports$1.Editor.nodes(editor, {
|
|
40099
40328
|
match: function (n) { return DomEditor.checkNodeType(n, 'table-cell'); },
|
|
40100
40329
|
universal: true,
|
|
40101
|
-
}), 1), cellEntry =
|
|
40102
|
-
var
|
|
40103
|
-
// 获取 cell length ,即多少列
|
|
40104
|
-
var rowNode = DomEditor.getParentNode(editor, cellNode);
|
|
40105
|
-
var cellsLength = (rowNode === null || rowNode === void 0 ? void 0 : rowNode.children.length) || 0;
|
|
40106
|
-
if (cellsLength === 0) {
|
|
40107
|
-
return;
|
|
40108
|
-
}
|
|
40330
|
+
}), 1), cellEntry = _b[0];
|
|
40331
|
+
var _c = __read(cellEntry, 2), cellPath = _c[1];
|
|
40109
40332
|
var matrix = filledMatrix(editor);
|
|
40110
40333
|
// 向下插入行为,先找到
|
|
40111
40334
|
// 当前选区所在的 tr 索引
|
|
@@ -40113,7 +40336,7 @@
|
|
|
40113
40336
|
/* eslint-disable no-labels */
|
|
40114
40337
|
outer: for (var x = 0; x < matrix.length; x += 1) {
|
|
40115
40338
|
for (var y = 0; y < matrix[x].length; y += 1) {
|
|
40116
|
-
var
|
|
40339
|
+
var _d = __read(matrix[x][y], 1), _e = __read(_d[0], 2), path = _e[1];
|
|
40117
40340
|
if (!distExports$1.Path.equals(cellPath, path)) {
|
|
40118
40341
|
continue;
|
|
40119
40342
|
}
|
|
@@ -40122,7 +40345,11 @@
|
|
|
40122
40345
|
break outer;
|
|
40123
40346
|
}
|
|
40124
40347
|
}
|
|
40125
|
-
|
|
40348
|
+
// 获取表格的真实列数(使用matrix的列数,而不是当前行的physical cell数量)
|
|
40349
|
+
var cellsLength = ((_a = matrix[trIndex]) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
40350
|
+
if (cellsLength === 0) {
|
|
40351
|
+
return;
|
|
40352
|
+
}
|
|
40126
40353
|
distExports$1.Editor.withoutNormalizing(editor, function () {
|
|
40127
40354
|
// 向下添加 tr 索引
|
|
40128
40355
|
var destIndex = trIndex + 1;
|
|
@@ -40132,10 +40359,12 @@
|
|
|
40132
40359
|
var _a = __read(matrix[trIndex][y], 2), _b = _a[1], ttb = _b.ttb, btt = _b.btt;
|
|
40133
40360
|
// 向上找到 1 元素为止
|
|
40134
40361
|
if (ttb > 1 || btt > 1) {
|
|
40135
|
-
|
|
40362
|
+
var originalRowIndex = trIndex - (ttb - 1);
|
|
40363
|
+
// 安全检查:确保目标行和列都存在
|
|
40364
|
+
if (originalRowIndex < 0 || originalRowIndex >= matrix.length || !matrix[originalRowIndex] || !matrix[originalRowIndex][y]) {
|
|
40136
40365
|
continue;
|
|
40137
40366
|
}
|
|
40138
|
-
var _c = __read(matrix[
|
|
40367
|
+
var _c = __read(matrix[originalRowIndex][y], 1), _d = __read(_c[0], 2), element = _d[0], path = _d[1];
|
|
40139
40368
|
var rowSpan = element.rowSpan || 1;
|
|
40140
40369
|
exitMerge.push(y);
|
|
40141
40370
|
if (!element.hidden) {
|
|
@@ -40147,10 +40376,14 @@
|
|
|
40147
40376
|
}
|
|
40148
40377
|
// 拼接新的 row
|
|
40149
40378
|
var newRow = { type: 'table-row', children: [] };
|
|
40379
|
+
// 只为不被合并单元格覆盖的位置创建td元素
|
|
40150
40380
|
for (var i = 0; i < cellsLength; i += 1) {
|
|
40381
|
+
// 如果当前位置被合并单元格覆盖,则跳过(不创建td)
|
|
40382
|
+
if (exitMerge.includes(i)) {
|
|
40383
|
+
continue;
|
|
40384
|
+
}
|
|
40151
40385
|
var cell = {
|
|
40152
40386
|
type: 'table-cell',
|
|
40153
|
-
hidden: exitMerge.includes(i),
|
|
40154
40387
|
children: [{ text: '' }],
|
|
40155
40388
|
};
|
|
40156
40389
|
newRow.children.push(cell);
|
|
@@ -40434,14 +40667,6 @@
|
|
|
40434
40667
|
this.iconSvg = MERGE_CELL_SVG;
|
|
40435
40668
|
this.tag = 'button';
|
|
40436
40669
|
}
|
|
40437
|
-
MergeCell.prototype.needKeepCell = function (editor, trPath) {
|
|
40438
|
-
// 检查同行是否有其他单元格
|
|
40439
|
-
var _a = __read(distExports$1.Node.children(editor, trPath), 2), rowSibling = _a[1];
|
|
40440
|
-
// 检查同列是否有其他单元格
|
|
40441
|
-
var parentTable = distExports$1.Editor.parent(editor, trPath);
|
|
40442
|
-
var hasOtherRows = parentTable[0].children.length > 1;
|
|
40443
|
-
return !!rowSibling || hasOtherRows;
|
|
40444
|
-
};
|
|
40445
40670
|
MergeCell.prototype.getValue = function (_editor) {
|
|
40446
40671
|
// 无需获取 val
|
|
40447
40672
|
return '';
|
|
@@ -40487,7 +40712,6 @@
|
|
|
40487
40712
|
* @returns void
|
|
40488
40713
|
*/
|
|
40489
40714
|
MergeCell.prototype.merge = function (editor) {
|
|
40490
|
-
var _this = this;
|
|
40491
40715
|
if (!this.canMerge(editor)) {
|
|
40492
40716
|
return;
|
|
40493
40717
|
}
|
|
@@ -40498,45 +40722,116 @@
|
|
|
40498
40722
|
var _a = __read(selection[0][0], 1), _b = __read(_a[0], 2), basePath = _b[1];
|
|
40499
40723
|
var _c = __read(distExports$1.Node.children(editor, basePath, { reverse: true }), 1), _d = __read(_c[0], 2), lastPath = _d[1];
|
|
40500
40724
|
distExports$1.Editor.withoutNormalizing(editor, function () {
|
|
40501
|
-
var e_1, _a;
|
|
40502
|
-
|
|
40503
|
-
var
|
|
40504
|
-
|
|
40505
|
-
|
|
40506
|
-
|
|
40507
|
-
|
|
40508
|
-
|
|
40509
|
-
|
|
40725
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
40726
|
+
// 收集所有真实的单元格(避免重复计算虚拟位置)
|
|
40727
|
+
var realCells = new Map();
|
|
40728
|
+
var cellsToDelete = [];
|
|
40729
|
+
// 计算实际的边界范围(考虑单元格的实际跨度)
|
|
40730
|
+
var minRow = Infinity;
|
|
40731
|
+
var maxRow = -Infinity;
|
|
40732
|
+
var minCol = Infinity;
|
|
40733
|
+
var maxCol = -Infinity;
|
|
40734
|
+
// 第一阶段:收集所有真实单元格并计算其实际占用的范围
|
|
40735
|
+
for (var x = 0; x < selection.length; x += 1) {
|
|
40736
|
+
for (var y = 0; y < selection[x].length; y += 1) {
|
|
40737
|
+
var _d = __read(selection[x][y], 2), _e = __read(_d[0], 2), element = _e[0], path = _e[1], ttb = _d[1].ttb;
|
|
40738
|
+
var pathKey = path.join(',');
|
|
40739
|
+
// 只处理真实单元格(ttb === 1 表示单元格的实际位置,不是虚拟扩展)
|
|
40740
|
+
if (ttb === 1 && !realCells.has(pathKey)) {
|
|
40741
|
+
realCells.set(pathKey, {
|
|
40742
|
+
path: path,
|
|
40743
|
+
x: x,
|
|
40744
|
+
y: y,
|
|
40745
|
+
element: element,
|
|
40746
|
+
});
|
|
40747
|
+
// 获取当前单元格的跨度
|
|
40748
|
+
var _f = element.rowSpan, rowSpan = _f === void 0 ? 1 : _f, _g = element.colSpan, colSpan = _g === void 0 ? 1 : _g;
|
|
40749
|
+
// 计算该单元格实际占用的范围
|
|
40750
|
+
var cellMinRow = x;
|
|
40751
|
+
var cellMaxRow = x + rowSpan - 1;
|
|
40752
|
+
var cellMinCol = y;
|
|
40753
|
+
var cellMaxCol = y + colSpan - 1;
|
|
40754
|
+
// 更新整体边界
|
|
40755
|
+
minRow = Math.min(minRow, cellMinRow);
|
|
40756
|
+
maxRow = Math.max(maxRow, cellMaxRow);
|
|
40757
|
+
minCol = Math.min(minCol, cellMinCol);
|
|
40758
|
+
maxCol = Math.max(maxCol, cellMaxCol);
|
|
40759
|
+
}
|
|
40760
|
+
}
|
|
40761
|
+
}
|
|
40762
|
+
// 计算正确的rowSpan和colSpan(基于实际占用的行列范围)
|
|
40763
|
+
var finalRowSpan = maxRow - minRow + 1;
|
|
40764
|
+
var finalColSpan = maxCol - minCol + 1;
|
|
40765
|
+
try {
|
|
40766
|
+
// 第二阶段:确定要删除的单元格
|
|
40767
|
+
for (var realCells_1 = __values(realCells), realCells_1_1 = realCells_1.next(); !realCells_1_1.done; realCells_1_1 = realCells_1.next()) {
|
|
40768
|
+
var _h = __read(realCells_1_1.value, 2), path = _h[1].path;
|
|
40769
|
+
// 跳过基础单元格(第一个单元格作为合并后的目标)
|
|
40770
|
+
if (distExports$1.Path.equals(basePath, path)) {
|
|
40510
40771
|
continue;
|
|
40511
40772
|
}
|
|
40773
|
+
cellsToDelete.push(path);
|
|
40774
|
+
}
|
|
40775
|
+
}
|
|
40776
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
40777
|
+
finally {
|
|
40778
|
+
try {
|
|
40779
|
+
if (realCells_1_1 && !realCells_1_1.done && (_a = realCells_1.return)) _a.call(realCells_1);
|
|
40780
|
+
}
|
|
40781
|
+
finally { if (e_1) throw e_1.error; }
|
|
40782
|
+
}
|
|
40783
|
+
// 第三阶段:按路径降序排序并删除单元格
|
|
40784
|
+
cellsToDelete.sort(function (a, b) {
|
|
40785
|
+
for (var i = 0; i < Math.min(a.length, b.length); i += 1) {
|
|
40786
|
+
if (a[i] !== b[i]) {
|
|
40787
|
+
return b[i] - a[i]; // 降序
|
|
40788
|
+
}
|
|
40789
|
+
}
|
|
40790
|
+
return b.length - a.length;
|
|
40791
|
+
});
|
|
40792
|
+
try {
|
|
40793
|
+
// 删除单元格并移动内容
|
|
40794
|
+
for (var cellsToDelete_1 = __values(cellsToDelete), cellsToDelete_1_1 = cellsToDelete_1.next(); !cellsToDelete_1_1.done; cellsToDelete_1_1 = cellsToDelete_1.next()) {
|
|
40795
|
+
var path = cellsToDelete_1_1.value;
|
|
40512
40796
|
try {
|
|
40513
|
-
//
|
|
40514
|
-
|
|
40515
|
-
|
|
40516
|
-
distExports$1.Transforms.moveNodes(editor, {
|
|
40517
|
-
to: distExports$1.Path.next(lastPath),
|
|
40518
|
-
at: childPath,
|
|
40519
|
-
});
|
|
40797
|
+
// 检查节点是否仍然存在
|
|
40798
|
+
if (!distExports$1.Editor.hasPath(editor, path)) {
|
|
40799
|
+
continue;
|
|
40520
40800
|
}
|
|
40521
|
-
}
|
|
40522
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
40523
|
-
finally {
|
|
40524
40801
|
try {
|
|
40525
|
-
|
|
40802
|
+
// 移动单元格内容到基础单元格
|
|
40803
|
+
for (var _j = (e_3 = void 0, __values(distExports$1.Node.children(editor, path, { reverse: true }))), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
40804
|
+
var _l = __read(_k.value, 2), childPath = _l[1];
|
|
40805
|
+
distExports$1.Transforms.moveNodes(editor, {
|
|
40806
|
+
to: distExports$1.Path.next(lastPath),
|
|
40807
|
+
at: childPath,
|
|
40808
|
+
});
|
|
40809
|
+
}
|
|
40526
40810
|
}
|
|
40527
|
-
|
|
40811
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
40812
|
+
finally {
|
|
40813
|
+
try {
|
|
40814
|
+
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
40815
|
+
}
|
|
40816
|
+
finally { if (e_3) throw e_3.error; }
|
|
40817
|
+
}
|
|
40818
|
+
// 删除单元格
|
|
40819
|
+
distExports$1.Transforms.removeNodes(editor, { at: path });
|
|
40528
40820
|
}
|
|
40529
|
-
|
|
40530
|
-
|
|
40531
|
-
at: path,
|
|
40532
|
-
}), 1), _h = __read(_g[0], 2), trPath = _h[1];
|
|
40533
|
-
if (_this.needKeepCell(editor, trPath)) {
|
|
40534
|
-
distExports$1.Transforms.setNodes(editor, { hidden: true }, { at: path });
|
|
40535
|
-
continue;
|
|
40821
|
+
catch (error) {
|
|
40822
|
+
// 静默处理删除失败的情况
|
|
40536
40823
|
}
|
|
40537
40824
|
}
|
|
40538
40825
|
}
|
|
40539
|
-
|
|
40826
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
40827
|
+
finally {
|
|
40828
|
+
try {
|
|
40829
|
+
if (cellsToDelete_1_1 && !cellsToDelete_1_1.done && (_b = cellsToDelete_1.return)) _b.call(cellsToDelete_1);
|
|
40830
|
+
}
|
|
40831
|
+
finally { if (e_2) throw e_2.error; }
|
|
40832
|
+
}
|
|
40833
|
+
// 为基础单元格设置正确的rowSpan和colSpan属性
|
|
40834
|
+
distExports$1.Transforms.setNodes(editor, { rowSpan: finalRowSpan, colSpan: finalColSpan }, { at: basePath });
|
|
40540
40835
|
});
|
|
40541
40836
|
};
|
|
40542
40837
|
return MergeCell;
|
|
@@ -40558,10 +40853,17 @@
|
|
|
40558
40853
|
return false;
|
|
40559
40854
|
};
|
|
40560
40855
|
SplitCell.prototype.isDisabled = function (editor) {
|
|
40856
|
+
// 查找当前选中的单元格,支持td和th两种类型
|
|
40561
40857
|
var _a = __read(distExports$1.Editor.nodes(editor, {
|
|
40562
|
-
match:
|
|
40563
|
-
|
|
40564
|
-
|
|
40858
|
+
match: function (n) {
|
|
40859
|
+
return DomEditor.checkNodeType(n, 'table-cell');
|
|
40860
|
+
},
|
|
40861
|
+
}), 1), cell = _a[0];
|
|
40862
|
+
if (!cell) {
|
|
40863
|
+
return true; // 如果没有找到单元格,则禁用拆分功能
|
|
40864
|
+
}
|
|
40865
|
+
var _b = __read(cell, 1), _c = _b[0], _d = _c.rowSpan, rowSpan = _d === void 0 ? 1 : _d, _e = _c.colSpan, colSpan = _e === void 0 ? 1 : _e;
|
|
40866
|
+
// 只有当rowSpan或colSpan大于1时才能拆分
|
|
40565
40867
|
if (rowSpan > 1 || colSpan > 1) {
|
|
40566
40868
|
return false;
|
|
40567
40869
|
}
|
|
@@ -40591,70 +40893,100 @@
|
|
|
40591
40893
|
if (!table || !td) {
|
|
40592
40894
|
return;
|
|
40593
40895
|
}
|
|
40594
|
-
var
|
|
40595
|
-
|
|
40596
|
-
|
|
40597
|
-
|
|
40896
|
+
var _b = __read(table, 1), tableNode = _b[0];
|
|
40897
|
+
var hasHeader = isTableWithHeader(tableNode);
|
|
40898
|
+
// 获取当前选中的单元格
|
|
40899
|
+
var _c = __read(td, 2), selectedCell = _c[0], selectedCellPath = _c[1];
|
|
40900
|
+
var _d = selectedCell.rowSpan, rowSpan = _d === void 0 ? 1 : _d, _e = selectedCell.colSpan, colSpan = _e === void 0 ? 1 : _e;
|
|
40901
|
+
// 如果单元格未合并,无需拆分
|
|
40902
|
+
if (rowSpan === 1 && colSpan === 1) {
|
|
40903
|
+
return;
|
|
40904
|
+
}
|
|
40598
40905
|
distExports$1.Editor.withoutNormalizing(editor, function () {
|
|
40599
|
-
|
|
40600
|
-
|
|
40601
|
-
|
|
40602
|
-
|
|
40603
|
-
|
|
40604
|
-
|
|
40605
|
-
|
|
40606
|
-
|
|
40906
|
+
// 1. 重置当前单元格的rowSpan和colSpan
|
|
40907
|
+
distExports$1.Transforms.setNodes(editor, { rowSpan: 1, colSpan: 1 }, { at: selectedCellPath });
|
|
40908
|
+
// 2. 处理同行的其他列(colSpan > 1的情况)
|
|
40909
|
+
// 在当前单元格后面插入 colSpan-1 个新单元格
|
|
40910
|
+
for (var c = 1; c < colSpan; c += 1) {
|
|
40911
|
+
var newCell = {
|
|
40912
|
+
type: 'table-cell',
|
|
40913
|
+
children: [{ text: '' }],
|
|
40914
|
+
};
|
|
40915
|
+
// 如果在第一行且表格有表头,设置isHeader
|
|
40916
|
+
var currentRowIndex = selectedCellPath[selectedCellPath.length - 2];
|
|
40917
|
+
if (currentRowIndex === 0 && hasHeader) {
|
|
40918
|
+
newCell.isHeader = true;
|
|
40919
|
+
}
|
|
40920
|
+
// 在当前行的当前位置之后插入
|
|
40921
|
+
var currentRowPath = selectedCellPath.slice(0, -1);
|
|
40922
|
+
var insertIndex = selectedCellPath[selectedCellPath.length - 1] + c;
|
|
40923
|
+
var insertPath = __spreadArray(__spreadArray([], __read(currentRowPath), false), [insertIndex], false);
|
|
40924
|
+
try {
|
|
40925
|
+
distExports$1.Transforms.insertNodes(editor, newCell, { at: insertPath });
|
|
40926
|
+
}
|
|
40927
|
+
catch (error) {
|
|
40928
|
+
// 如果指定位置插入失败,在行末尾插入
|
|
40929
|
+
try {
|
|
40930
|
+
var _a = __read(distExports$1.Editor.node(editor, currentRowPath), 1), currentRow = _a[0];
|
|
40931
|
+
var cellsCount = currentRow.children.length;
|
|
40932
|
+
var fallbackPath = __spreadArray(__spreadArray([], __read(currentRowPath), false), [cellsCount], false);
|
|
40933
|
+
distExports$1.Transforms.insertNodes(editor, newCell, { at: fallbackPath });
|
|
40607
40934
|
}
|
|
40608
|
-
|
|
40609
|
-
|
|
40935
|
+
catch (fallbackError) {
|
|
40936
|
+
console.warn("\u63D2\u5165\u540C\u884C\u5355\u5143\u683C\u5931\u8D25: ".concat(fallbackError instanceof Error ? fallbackError.message : String(fallbackError)));
|
|
40610
40937
|
}
|
|
40611
|
-
|
|
40938
|
+
}
|
|
40939
|
+
}
|
|
40940
|
+
// 3. 处理其他行(rowSpan > 1的情况)
|
|
40941
|
+
// 在下面的每一行都插入相应数量的单元格
|
|
40942
|
+
for (var r = 1; r < rowSpan; r += 1) {
|
|
40943
|
+
// 计算目标行路径
|
|
40944
|
+
var targetRowIndex = selectedCellPath[selectedCellPath.length - 2] + r;
|
|
40945
|
+
var targetRowPath = __spreadArray(__spreadArray([], __read(selectedCellPath.slice(0, -2)), false), [targetRowIndex], false);
|
|
40946
|
+
try {
|
|
40947
|
+
// 检查目标行是否存在
|
|
40948
|
+
var _b = __read(distExports$1.Editor.node(editor, targetRowPath), 1), targetRow = _b[0];
|
|
40949
|
+
if (!targetRow) {
|
|
40950
|
+
console.warn("\u76EE\u6807\u884C ".concat(targetRowIndex, " \u4E0D\u5B58\u5728"));
|
|
40612
40951
|
continue;
|
|
40613
40952
|
}
|
|
40614
|
-
|
|
40615
|
-
|
|
40616
|
-
|
|
40617
|
-
|
|
40618
|
-
|
|
40619
|
-
|
|
40620
|
-
|
|
40621
|
-
|
|
40622
|
-
|
|
40623
|
-
|
|
40624
|
-
|
|
40953
|
+
// 在目标行中插入colSpan个新单元格
|
|
40954
|
+
for (var c = 0; c < colSpan; c += 1) {
|
|
40955
|
+
var newCell = {
|
|
40956
|
+
type: 'table-cell',
|
|
40957
|
+
children: [{ text: '' }],
|
|
40958
|
+
};
|
|
40959
|
+
// 计算插入位置
|
|
40960
|
+
var originalColumnIndex = selectedCellPath[selectedCellPath.length - 1];
|
|
40961
|
+
var insertIndex = originalColumnIndex + c;
|
|
40962
|
+
var insertPath = __spreadArray(__spreadArray([], __read(targetRowPath), false), [insertIndex], false);
|
|
40963
|
+
try {
|
|
40964
|
+
// 获取目标行当前的单元格数量
|
|
40965
|
+
var currentCellsCount = targetRow.children.length;
|
|
40966
|
+
// 如果插入位置超出当前行的范围,在行末尾插入
|
|
40967
|
+
if (insertIndex >= currentCellsCount) {
|
|
40968
|
+
var endPath = __spreadArray(__spreadArray([], __read(targetRowPath), false), [currentCellsCount], false);
|
|
40969
|
+
distExports$1.Transforms.insertNodes(editor, newCell, { at: endPath });
|
|
40970
|
+
}
|
|
40971
|
+
else {
|
|
40972
|
+
distExports$1.Transforms.insertNodes(editor, newCell, { at: insertPath });
|
|
40625
40973
|
}
|
|
40626
40974
|
}
|
|
40627
|
-
|
|
40628
|
-
|
|
40629
|
-
|
|
40630
|
-
|
|
40631
|
-
|
|
40632
|
-
|
|
40633
|
-
}
|
|
40634
|
-
if (!found) {
|
|
40635
|
-
continue;
|
|
40636
|
-
}
|
|
40637
|
-
// eslint-disable-next-line no-labels
|
|
40638
|
-
out: for (var r = 1; r < rowSpan; r += 1) {
|
|
40639
|
-
for (var i = y; i >= 0; i -= 1) {
|
|
40640
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
40641
|
-
var _f = __read(matrix[x + r][i], 2), ttb_1 = _f[1].ttb;
|
|
40642
|
-
if (ttb_1 === 1) {
|
|
40643
|
-
continue;
|
|
40975
|
+
catch (insertError) {
|
|
40976
|
+
// 最后的备用方案:在行末尾插入
|
|
40977
|
+
try {
|
|
40978
|
+
var updatedCellsCount = targetRow.children.length;
|
|
40979
|
+
var fallbackPath = __spreadArray(__spreadArray([], __read(targetRowPath), false), [updatedCellsCount], false);
|
|
40980
|
+
distExports$1.Transforms.insertNodes(editor, newCell, { at: fallbackPath });
|
|
40644
40981
|
}
|
|
40645
|
-
|
|
40646
|
-
|
|
40647
|
-
distExports$1.Transforms.unsetNodes(editor, ['hidden', 'colSpan', 'rowSpan'], { at: nextPath });
|
|
40982
|
+
catch (finalError) {
|
|
40983
|
+
console.warn("\u63D2\u5165\u5355\u5143\u683C\u5230\u7B2C".concat(r, "\u884C\u5931\u8D25: ").concat(finalError instanceof Error ? finalError.message : String(finalError)));
|
|
40648
40984
|
}
|
|
40649
|
-
// eslint-disable-next-line no-labels
|
|
40650
|
-
continue out;
|
|
40651
40985
|
}
|
|
40652
40986
|
}
|
|
40653
|
-
|
|
40654
|
-
|
|
40655
|
-
|
|
40656
|
-
}
|
|
40657
|
-
distExports$1.Transforms.setNodes(editor, { rowSpan: 1, colSpan: 1 }, { at: path });
|
|
40987
|
+
}
|
|
40988
|
+
catch (rowError) {
|
|
40989
|
+
console.warn("\u5904\u7406\u7B2C".concat(r, "\u884C\u65F6\u51FA\u9519: ").concat(rowError instanceof Error ? rowError.message : String(rowError)));
|
|
40658
40990
|
}
|
|
40659
40991
|
}
|
|
40660
40992
|
});
|
|
@@ -40845,26 +41177,11 @@
|
|
|
40845
41177
|
// 确保是 table-cell 类型
|
|
40846
41178
|
if (DomEditor.getNodeType(child) === 'table-cell') {
|
|
40847
41179
|
var tableCell = child;
|
|
40848
|
-
|
|
40849
|
-
|
|
40850
|
-
|
|
40851
|
-
for (var j = 1; j < colSpan; j += 1) {
|
|
40852
|
-
var nextChild = children[i + j];
|
|
40853
|
-
if (nextChild
|
|
40854
|
-
&& DomEditor.getNodeType(nextChild) === 'table-cell'
|
|
40855
|
-
&& nextChild.hidden) {
|
|
40856
|
-
// 已有隐藏的 table-cell,无需补充
|
|
40857
|
-
continue;
|
|
40858
|
-
}
|
|
40859
|
-
else {
|
|
40860
|
-
// 补齐缺少的隐藏 table-cell
|
|
40861
|
-
tableCellChildren.push({
|
|
40862
|
-
type: 'table-cell',
|
|
40863
|
-
children: [{ text: '' }],
|
|
40864
|
-
hidden: true,
|
|
40865
|
-
});
|
|
40866
|
-
}
|
|
41180
|
+
// 如果是隐藏的单元格,则跳过(删除)
|
|
41181
|
+
if (tableCell.hidden) {
|
|
41182
|
+
continue;
|
|
40867
41183
|
}
|
|
41184
|
+
tableCellChildren.push(tableCell); // 只添加非隐藏的单元格
|
|
40868
41185
|
}
|
|
40869
41186
|
}
|
|
40870
41187
|
return {
|
|
@@ -40981,13 +41298,21 @@
|
|
|
40981
41298
|
TableCursor.unselect(editor);
|
|
40982
41299
|
return apply(op);
|
|
40983
41300
|
}
|
|
41301
|
+
var isTableCell = function (n) {
|
|
41302
|
+
return distExports$1.Element.isElement(n)
|
|
41303
|
+
&& (n.type === 'table-cell'
|
|
41304
|
+
|| n.type === 'th'
|
|
41305
|
+
|| n.type === 'td');
|
|
41306
|
+
};
|
|
40984
41307
|
var _a = __read(distExports$1.Editor.nodes(editor, {
|
|
40985
|
-
match:
|
|
41308
|
+
match: isTableCell,
|
|
40986
41309
|
at: distExports$1.Range.start(selection),
|
|
41310
|
+
mode: 'lowest', // 确保找到最低层的匹配节点
|
|
40987
41311
|
}), 1), fromEntry = _a[0];
|
|
40988
41312
|
var _b = __read(distExports$1.Editor.nodes(editor, {
|
|
40989
|
-
match:
|
|
41313
|
+
match: isTableCell,
|
|
40990
41314
|
at: distExports$1.Range.end(selection),
|
|
41315
|
+
mode: 'lowest', // 确保找到最低层的匹配节点
|
|
40991
41316
|
}), 1), toEntry = _b[0];
|
|
40992
41317
|
if (!fromEntry || !toEntry) {
|
|
40993
41318
|
TableCursor.unselect(editor);
|
|
@@ -41000,58 +41325,104 @@
|
|
|
41000
41325
|
return apply(op);
|
|
41001
41326
|
}
|
|
41002
41327
|
// TODO: perf: could be improved by passing a Span [fromPath, toPath]
|
|
41003
|
-
|
|
41004
|
-
|
|
41005
|
-
|
|
41006
|
-
|
|
41007
|
-
|
|
41008
|
-
|
|
41009
|
-
|
|
41010
|
-
|
|
41011
|
-
|
|
41012
|
-
|
|
41328
|
+
try {
|
|
41329
|
+
var filled = filledMatrix(editor, { at: fromPath });
|
|
41330
|
+
// 基本的有效性检查
|
|
41331
|
+
if (!filled || filled.length === 0) {
|
|
41332
|
+
TableCursor.unselect(editor);
|
|
41333
|
+
return apply(op);
|
|
41334
|
+
}
|
|
41335
|
+
// find initial bounds
|
|
41336
|
+
var from = Point.valueOf(0, 0);
|
|
41337
|
+
var to = Point.valueOf(0, 0);
|
|
41338
|
+
var fromFound = false;
|
|
41339
|
+
var toFound = false;
|
|
41340
|
+
for (var x = 0; x < filled.length; x += 1) {
|
|
41341
|
+
if (!filled[x]) {
|
|
41342
|
+
continue;
|
|
41343
|
+
} // 跳过空行
|
|
41344
|
+
for (var y = 0; y < filled[x].length; y += 1) {
|
|
41345
|
+
if (!filled[x][y]) {
|
|
41346
|
+
continue;
|
|
41347
|
+
} // 跳过空单元格
|
|
41348
|
+
var _e = __read(filled[x][y], 1), _f = __read(_e[0], 2), path = _f[1];
|
|
41349
|
+
if (distExports$1.Path.equals(fromPath, path)) {
|
|
41350
|
+
from.x = x;
|
|
41351
|
+
from.y = y;
|
|
41352
|
+
fromFound = true;
|
|
41353
|
+
}
|
|
41354
|
+
if (distExports$1.Path.equals(toPath, path)) {
|
|
41355
|
+
to.x = x;
|
|
41356
|
+
to.y = y;
|
|
41357
|
+
toFound = true;
|
|
41358
|
+
}
|
|
41359
|
+
}
|
|
41360
|
+
}
|
|
41361
|
+
// 如果找不到位置,可能是选择了被删除的单元格区域
|
|
41362
|
+
if (!fromFound || !toFound) {
|
|
41363
|
+
TableCursor.unselect(editor);
|
|
41364
|
+
return apply(op);
|
|
41365
|
+
}
|
|
41366
|
+
var start = Point.valueOf(Math.min(from.x, to.x), Math.min(from.y, to.y));
|
|
41367
|
+
var end = Point.valueOf(Math.max(from.x, to.x), Math.max(from.y, to.y));
|
|
41368
|
+
// expand the selection based on rowspan and colspan
|
|
41369
|
+
for (;;) {
|
|
41370
|
+
var nextStart = Point.valueOf(start.x, start.y);
|
|
41371
|
+
var nextEnd = Point.valueOf(end.x, end.y);
|
|
41372
|
+
for (var x = nextStart.x; x <= nextEnd.x && x < filled.length; x += 1) {
|
|
41373
|
+
if (!filled[x]) {
|
|
41374
|
+
continue;
|
|
41375
|
+
}
|
|
41376
|
+
for (var y = nextStart.y; y <= nextEnd.y && y < filled[x].length; y += 1) {
|
|
41377
|
+
if (!filled[x][y]) {
|
|
41378
|
+
continue;
|
|
41379
|
+
}
|
|
41380
|
+
var _g = __read(filled[x][y], 2), context = _g[1];
|
|
41381
|
+
if (!context) {
|
|
41382
|
+
continue;
|
|
41383
|
+
}
|
|
41384
|
+
var rtl = context.rtl, ltr = context.ltr, btt = context.btt, ttb = context.ttb;
|
|
41385
|
+
nextStart.x = Math.min(nextStart.x, x - (ttb - 1));
|
|
41386
|
+
nextStart.y = Math.min(nextStart.y, y - (rtl - 1));
|
|
41387
|
+
nextEnd.x = Math.max(nextEnd.x, x + (btt - 1));
|
|
41388
|
+
nextEnd.y = Math.max(nextEnd.y, y + (ltr - 1));
|
|
41389
|
+
}
|
|
41013
41390
|
}
|
|
41014
|
-
if (
|
|
41015
|
-
to.x = x;
|
|
41016
|
-
to.y = y;
|
|
41391
|
+
if (Point.equals(start, nextStart) && Point.equals(end, nextEnd)) {
|
|
41017
41392
|
break;
|
|
41018
41393
|
}
|
|
41394
|
+
start = nextStart;
|
|
41395
|
+
end = nextEnd;
|
|
41019
41396
|
}
|
|
41020
|
-
|
|
41021
|
-
|
|
41022
|
-
|
|
41023
|
-
|
|
41024
|
-
|
|
41025
|
-
|
|
41026
|
-
|
|
41027
|
-
|
|
41028
|
-
|
|
41029
|
-
|
|
41030
|
-
|
|
41031
|
-
|
|
41032
|
-
|
|
41033
|
-
|
|
41397
|
+
var selected = [];
|
|
41398
|
+
var selectedSet = new WeakSet();
|
|
41399
|
+
for (var x = start.x; x <= end.x && x < filled.length; x += 1) {
|
|
41400
|
+
if (!filled[x]) {
|
|
41401
|
+
continue;
|
|
41402
|
+
}
|
|
41403
|
+
var cells = [];
|
|
41404
|
+
for (var y = start.y; y <= end.y && y < filled[x].length; y += 1) {
|
|
41405
|
+
if (!filled[x][y]) {
|
|
41406
|
+
continue;
|
|
41407
|
+
}
|
|
41408
|
+
var _h = __read(filled[x][y], 1), _j = __read(_h[0], 1), element = _j[0];
|
|
41409
|
+
if (!element) {
|
|
41410
|
+
continue;
|
|
41411
|
+
}
|
|
41412
|
+
selectedSet.add(element);
|
|
41413
|
+
cells.push(filled[x][y]);
|
|
41414
|
+
}
|
|
41415
|
+
if (cells.length > 0) {
|
|
41416
|
+
selected.push(cells);
|
|
41034
41417
|
}
|
|
41035
41418
|
}
|
|
41036
|
-
|
|
41037
|
-
|
|
41038
|
-
}
|
|
41039
|
-
start = nextStart;
|
|
41040
|
-
end = nextEnd;
|
|
41419
|
+
EDITOR_TO_SELECTION.set(editor, selected);
|
|
41420
|
+
EDITOR_TO_SELECTION_SET.set(editor, selectedSet);
|
|
41041
41421
|
}
|
|
41042
|
-
|
|
41043
|
-
|
|
41044
|
-
|
|
41045
|
-
var cells = [];
|
|
41046
|
-
for (var y = start.y; y <= end.y; y += 1) {
|
|
41047
|
-
var _j = __read(filled[x][y], 1), _k = __read(_j[0], 1), element = _k[0];
|
|
41048
|
-
selectedSet.add(element);
|
|
41049
|
-
cells.push(filled[x][y]);
|
|
41050
|
-
}
|
|
41051
|
-
selected.push(cells);
|
|
41422
|
+
catch (error) {
|
|
41423
|
+
TableCursor.unselect(editor);
|
|
41424
|
+
return apply(op);
|
|
41052
41425
|
}
|
|
41053
|
-
EDITOR_TO_SELECTION.set(editor, selected);
|
|
41054
|
-
EDITOR_TO_SELECTION_SET.set(editor, selectedSet);
|
|
41055
41426
|
apply(op);
|
|
41056
41427
|
};
|
|
41057
41428
|
return editor;
|
|
@@ -41487,7 +41858,7 @@
|
|
|
41487
41858
|
* @author wangfupeng
|
|
41488
41859
|
*/
|
|
41489
41860
|
/**
|
|
41490
|
-
* pre-prase table ,去掉 <tbody>
|
|
41861
|
+
* pre-prase table ,去掉 <tbody> 和处理单元格中的 <p> 标签,以及删除隐藏的单元格
|
|
41491
41862
|
* @param table table elem
|
|
41492
41863
|
*/
|
|
41493
41864
|
function preParse$1(tableElem) {
|
|
@@ -41505,6 +41876,42 @@
|
|
|
41505
41876
|
var $tr = $table.find('tr');
|
|
41506
41877
|
$table.append($tr);
|
|
41507
41878
|
$tbody.remove();
|
|
41879
|
+
// 删除带有 style="display:none" 的单元格(通常来自复制的隐藏内容)
|
|
41880
|
+
var $allCells = $table.find('td, th');
|
|
41881
|
+
for (var i = 0; i < $allCells.length; i += 1) {
|
|
41882
|
+
var cell = $allCells[i];
|
|
41883
|
+
var $cell = $$1(cell);
|
|
41884
|
+
var styleAttr = $cell.attr('style');
|
|
41885
|
+
// 检查style属性是否包含display:none或display: none
|
|
41886
|
+
if (styleAttr) {
|
|
41887
|
+
// 使用正则表达式匹配display:none,支持空格变化
|
|
41888
|
+
var displayNoneRegex = /display\s*:\s*none/i;
|
|
41889
|
+
if (displayNoneRegex.test(styleAttr)) {
|
|
41890
|
+
$cell.remove();
|
|
41891
|
+
}
|
|
41892
|
+
}
|
|
41893
|
+
}
|
|
41894
|
+
// 处理表格单元格中的 <p> 标签(通常来自Word复制)
|
|
41895
|
+
var $cells = $table.find('td, th');
|
|
41896
|
+
for (var i = 0; i < $cells.length; i += 1) {
|
|
41897
|
+
var cell = $cells[i];
|
|
41898
|
+
var $cell = $$1(cell);
|
|
41899
|
+
// 直接处理单元格中的所有 <p> 标签
|
|
41900
|
+
var cellHtml = $cell.html() || '';
|
|
41901
|
+
// 先清理Word特殊标签
|
|
41902
|
+
cellHtml = cellHtml.replace(/<o:p[^>]*>[\s\S]*?<\/o:p>/gi, ''); // 删除 <o:p> 标签
|
|
41903
|
+
cellHtml = cellHtml.replace(/<\/o:p>/gi, ''); // 删除可能的自闭合标签
|
|
41904
|
+
// 一次性处理所有p标签
|
|
41905
|
+
cellHtml = cellHtml.replace(/<p[^>]*>([\s\S]*?)<\/p>/gi, function (match, content) {
|
|
41906
|
+
// 处理空内容或只包含空白字符的情况
|
|
41907
|
+
var trimmedContent = content.trim();
|
|
41908
|
+
if (!trimmedContent || trimmedContent === ' ') {
|
|
41909
|
+
return ''; // 删除空的p标签
|
|
41910
|
+
}
|
|
41911
|
+
return content; // 返回p标签的内容
|
|
41912
|
+
});
|
|
41913
|
+
$cell.html(cellHtml);
|
|
41914
|
+
}
|
|
41508
41915
|
return $table[0];
|
|
41509
41916
|
}
|
|
41510
41917
|
var preParseTableHtmlConf = {
|
|
@@ -41650,6 +42057,117 @@
|
|
|
41650
42057
|
$window.on('mouseup', onMouseUp);
|
|
41651
42058
|
}
|
|
41652
42059
|
$window.on('mousedown', onMouseDown);
|
|
42060
|
+
/**
|
|
42061
|
+
* 计算等比例调整所有列宽度(用于最右侧列拖动)
|
|
42062
|
+
*/
|
|
42063
|
+
function calculateProportionalWidths(columnWidths, resizingIndex, newRightmostWidth) {
|
|
42064
|
+
var currentTotalWidth = columnWidths.reduce(function (a, b) { return a + b; }, 0);
|
|
42065
|
+
var currentRightmostWidth = columnWidths[resizingIndex];
|
|
42066
|
+
// 确保最右侧列不小于最小宽度
|
|
42067
|
+
var actualNewRightmostWidth = Math.max(10, newRightmostWidth);
|
|
42068
|
+
// 计算新的总宽度
|
|
42069
|
+
var newTotalWidth = currentTotalWidth - currentRightmostWidth + actualNewRightmostWidth;
|
|
42070
|
+
// 如果新总宽度太小,则设置最小总宽度
|
|
42071
|
+
var minTotalWidth = columnWidths.length * 10; // 每列至少10px
|
|
42072
|
+
if (newTotalWidth < minTotalWidth) {
|
|
42073
|
+
// 如果新总宽度小于最小值,则所有列都设为最小宽度
|
|
42074
|
+
return columnWidths.map(function () { return 10; });
|
|
42075
|
+
}
|
|
42076
|
+
// 计算其他列的总宽度
|
|
42077
|
+
var otherColumnsCurrentWidth = currentTotalWidth - currentRightmostWidth;
|
|
42078
|
+
var otherColumnsNewWidth = newTotalWidth - actualNewRightmostWidth;
|
|
42079
|
+
// 如果其他列需要的总宽度为0或负数,则只保留最右侧列
|
|
42080
|
+
if (otherColumnsNewWidth <= 0) {
|
|
42081
|
+
var result = columnWidths.map(function () { return 10; });
|
|
42082
|
+
result[resizingIndex] = Math.max(10, newTotalWidth - (columnWidths.length - 1) * 10);
|
|
42083
|
+
return result;
|
|
42084
|
+
}
|
|
42085
|
+
// 计算其他列的缩放比例
|
|
42086
|
+
var otherColumnsScaleFactor = otherColumnsCurrentWidth > 0 ? otherColumnsNewWidth / otherColumnsCurrentWidth : 1;
|
|
42087
|
+
// 调整所有列宽度
|
|
42088
|
+
var newWidths = columnWidths.map(function (width, index) {
|
|
42089
|
+
if (index === resizingIndex) {
|
|
42090
|
+
// 最右侧列直接使用新宽度
|
|
42091
|
+
return Math.floor(actualNewRightmostWidth * 100) / 100;
|
|
42092
|
+
}
|
|
42093
|
+
// 其他列按比例调整
|
|
42094
|
+
var newWidth = width * otherColumnsScaleFactor;
|
|
42095
|
+
return Math.max(10, Math.floor(newWidth * 100) / 100);
|
|
42096
|
+
});
|
|
42097
|
+
// 由于最小宽度限制,可能导致总宽度偏差,需要微调最右侧列
|
|
42098
|
+
var actualTotalWidth = newWidths.reduce(function (a, b) { return a + b; }, 0);
|
|
42099
|
+
var widthDifference = newTotalWidth - actualTotalWidth;
|
|
42100
|
+
if (Math.abs(widthDifference) > 0.01) {
|
|
42101
|
+
newWidths[resizingIndex] = Math.max(10, newWidths[resizingIndex] + widthDifference);
|
|
42102
|
+
}
|
|
42103
|
+
return newWidths;
|
|
42104
|
+
}
|
|
42105
|
+
/**
|
|
42106
|
+
* 计算相邻列宽度调整(用于中间列拖动)
|
|
42107
|
+
*/
|
|
42108
|
+
function calculateAdjacentWidths(columnWidths, resizingIndex, widthChange) {
|
|
42109
|
+
var newWidths = __spreadArray([], __read(columnWidths), false);
|
|
42110
|
+
// 找到右侧的相邻列进行调整
|
|
42111
|
+
var adjacentIndex = resizingIndex + 1;
|
|
42112
|
+
if (adjacentIndex >= newWidths.length) {
|
|
42113
|
+
// 如果没有右侧相邻列,则不进行调整
|
|
42114
|
+
return newWidths;
|
|
42115
|
+
}
|
|
42116
|
+
var leftColumnWidth = newWidths[resizingIndex];
|
|
42117
|
+
var rightColumnWidth = newWidths[adjacentIndex];
|
|
42118
|
+
// 计算边界可以移动的范围
|
|
42119
|
+
var minLeftWidth = 10;
|
|
42120
|
+
var minRightWidth = 10;
|
|
42121
|
+
var maxLeftWidth = leftColumnWidth + rightColumnWidth - minRightWidth;
|
|
42122
|
+
// 计算新的左列宽度(边界直接跟随鼠标)
|
|
42123
|
+
var newLeftWidth = leftColumnWidth + widthChange;
|
|
42124
|
+
// 限制左列宽度在允许范围内
|
|
42125
|
+
newLeftWidth = Math.max(minLeftWidth, Math.min(maxLeftWidth, newLeftWidth));
|
|
42126
|
+
// 计算新的右列宽度(确保总宽度不变)
|
|
42127
|
+
var newRightWidth = leftColumnWidth + rightColumnWidth - newLeftWidth;
|
|
42128
|
+
// 应用新宽度
|
|
42129
|
+
newWidths[resizingIndex] = Math.floor(newLeftWidth * 100) / 100;
|
|
42130
|
+
newWidths[adjacentIndex] = Math.floor(newRightWidth * 100) / 100;
|
|
42131
|
+
return newWidths;
|
|
42132
|
+
}
|
|
42133
|
+
/**
|
|
42134
|
+
* 根据鼠标位置计算列宽度
|
|
42135
|
+
* @param columnWidths 当前列宽度数组
|
|
42136
|
+
* @param resizingIndex 正在调整的边界索引
|
|
42137
|
+
* @param mousePositionInTable 鼠标相对于表格左边的位置
|
|
42138
|
+
* @param cumulativeWidths 列宽度的累积和数组
|
|
42139
|
+
* @returns 调整后的列宽度数组
|
|
42140
|
+
*/
|
|
42141
|
+
function calculateAdjacentWidthsByBorderPosition(columnWidths, resizingIndex, mousePositionInTable, cumulativeWidths) {
|
|
42142
|
+
var newWidths = __spreadArray([], __read(columnWidths), false);
|
|
42143
|
+
// 检查边界范围
|
|
42144
|
+
if (resizingIndex < 0 || resizingIndex >= columnWidths.length) {
|
|
42145
|
+
return newWidths;
|
|
42146
|
+
}
|
|
42147
|
+
// 计算当前边界的左边界位置(前面所有列的宽度总和)
|
|
42148
|
+
var leftBoundary = resizingIndex === 0 ? 0 : cumulativeWidths[resizingIndex - 1];
|
|
42149
|
+
// 计算当前边界的右边界位置(包括当前列和下一列的宽度)
|
|
42150
|
+
var rightBoundary = resizingIndex + 1 < columnWidths.length
|
|
42151
|
+
? cumulativeWidths[resizingIndex + 1]
|
|
42152
|
+
: cumulativeWidths[resizingIndex];
|
|
42153
|
+
// 计算允许的边界移动范围
|
|
42154
|
+
var minBorderPosition = leftBoundary + 10; // 左列最小宽度
|
|
42155
|
+
var maxBorderPosition = rightBoundary - 10; // 右列最小宽度
|
|
42156
|
+
// 限制鼠标位置在允许范围内
|
|
42157
|
+
var clampedMousePosition = Math.max(minBorderPosition, Math.min(maxBorderPosition, mousePositionInTable));
|
|
42158
|
+
// 计算新的左列宽度(第resizingIndex列)
|
|
42159
|
+
var newLeftWidth = clampedMousePosition - leftBoundary;
|
|
42160
|
+
// 计算新的右列宽度(第resizingIndex+1列)
|
|
42161
|
+
var adjacentIndex = resizingIndex + 1;
|
|
42162
|
+
if (adjacentIndex < columnWidths.length) {
|
|
42163
|
+
var currentTwoColumnsWidth = columnWidths[resizingIndex] + columnWidths[adjacentIndex];
|
|
42164
|
+
var newRightWidth = currentTwoColumnsWidth - newLeftWidth;
|
|
42165
|
+
// 应用新宽度
|
|
42166
|
+
newWidths[resizingIndex] = Math.floor(newLeftWidth * 100) / 100;
|
|
42167
|
+
newWidths[adjacentIndex] = Math.floor(newRightWidth * 100) / 100;
|
|
42168
|
+
}
|
|
42169
|
+
return newWidths;
|
|
42170
|
+
}
|
|
41653
42171
|
var onMouseMove = throttle(function (event) {
|
|
41654
42172
|
if (!isMouseDownForResize) {
|
|
41655
42173
|
return;
|
|
@@ -41659,28 +42177,65 @@
|
|
|
41659
42177
|
}
|
|
41660
42178
|
event.preventDefault();
|
|
41661
42179
|
var clientX = event.clientX;
|
|
41662
|
-
var
|
|
41663
|
-
newWith = Math.floor(newWith * 100) / 100; // 保留小数点后两位
|
|
41664
|
-
if (newWith < 30) {
|
|
41665
|
-
newWith = 30;
|
|
41666
|
-
} // 最小宽度
|
|
42180
|
+
var widthChange = clientX - clientXWhenMouseDown; // 计算宽度变化
|
|
41667
42181
|
var _a = __read(distExports$1.Editor.nodes(editorWhenMouseDown, {
|
|
41668
42182
|
match: isOfType(editorWhenMouseDown, 'table'),
|
|
41669
42183
|
}), 1), _b = __read(_a[0], 1), elemNode = _b[0];
|
|
41670
42184
|
var _c = elemNode, _d = _c.columnWidths, columnWidths = _d === void 0 ? [] : _d, _e = _c.resizingIndex, resizingIndex = _e === void 0 ? -1 : _e;
|
|
41671
|
-
var
|
|
41672
|
-
|
|
41673
|
-
|
|
41674
|
-
|
|
41675
|
-
|
|
41676
|
-
|
|
41677
|
-
|
|
41678
|
-
|
|
41679
|
-
|
|
41680
|
-
|
|
41681
|
-
|
|
41682
|
-
|
|
41683
|
-
|
|
42185
|
+
var adjustColumnWidths;
|
|
42186
|
+
// 判断是否为最右侧列
|
|
42187
|
+
var isRightmostColumn = resizingIndex === columnWidths.length - 1;
|
|
42188
|
+
if (isRightmostColumn) {
|
|
42189
|
+
// 最右侧列:等比例调整所有列宽度
|
|
42190
|
+
var newRightmostWidth = cellWidthWhenMouseDown + widthChange;
|
|
42191
|
+
adjustColumnWidths = calculateProportionalWidths(columnWidths, resizingIndex, newRightmostWidth);
|
|
42192
|
+
}
|
|
42193
|
+
else {
|
|
42194
|
+
// 中间列:计算边界的绝对位置
|
|
42195
|
+
var tableElement = document.querySelector('.table');
|
|
42196
|
+
if (tableElement) {
|
|
42197
|
+
var tableRect = tableElement.getBoundingClientRect();
|
|
42198
|
+
var mousePositionInTable = clientX - tableRect.left; // 鼠标相对于表格左边的位置
|
|
42199
|
+
// 计算边界的新位置
|
|
42200
|
+
var cumulativeWidths = getCumulativeWidths(columnWidths);
|
|
42201
|
+
var newBorderPosition = mousePositionInTable;
|
|
42202
|
+
// 根据新的边界位置计算列宽度
|
|
42203
|
+
adjustColumnWidths = calculateAdjacentWidthsByBorderPosition(columnWidths, resizingIndex, newBorderPosition, cumulativeWidths);
|
|
42204
|
+
}
|
|
42205
|
+
else {
|
|
42206
|
+
// 如果找不到表格元素,则使用原来的逻辑
|
|
42207
|
+
adjustColumnWidths = calculateAdjacentWidths(columnWidths, resizingIndex, widthChange);
|
|
42208
|
+
}
|
|
42209
|
+
}
|
|
42210
|
+
// 检查容器宽度限制(仅对最右侧列生效)
|
|
42211
|
+
if (isRightmostColumn) {
|
|
42212
|
+
var containerElement = document.querySelector('.table-container');
|
|
42213
|
+
if (containerElement) {
|
|
42214
|
+
var newTotalWidth = adjustColumnWidths.reduce(function (a, b) { return a + b; }, 0);
|
|
42215
|
+
var minTableWidth = columnWidths.length * 10; // 最小表格宽度
|
|
42216
|
+
var maxTableWidth = containerElement.clientWidth - 1; // 最大表格宽度
|
|
42217
|
+
// 如果新宽度小于最小宽度,则使用最小宽度
|
|
42218
|
+
if (newTotalWidth < minTableWidth) {
|
|
42219
|
+
adjustColumnWidths = columnWidths.map(function () { return 10; });
|
|
42220
|
+
}
|
|
42221
|
+
else if (newTotalWidth > maxTableWidth) {
|
|
42222
|
+
// 如果新宽度超过容器宽度,则限制在容器宽度内
|
|
42223
|
+
// 计算允许的最大最右侧列宽度
|
|
42224
|
+
var otherColumnsWidth = adjustColumnWidths.slice(0, -1).reduce(function (a, b) { return a + b; }, 0);
|
|
42225
|
+
var maxRightmostWidth = Math.max(10, maxTableWidth - otherColumnsWidth);
|
|
42226
|
+
// 重新计算等比例调整后的列宽度,限制在最大宽度内
|
|
42227
|
+
adjustColumnWidths = calculateProportionalWidths(columnWidths, resizingIndex, maxRightmostWidth);
|
|
42228
|
+
// 确保总宽度不超过容器宽度
|
|
42229
|
+
var finalTotalWidth = adjustColumnWidths.reduce(function (a, b) { return a + b; }, 0);
|
|
42230
|
+
if (finalTotalWidth > maxTableWidth) {
|
|
42231
|
+
// 如果仍然超过,则按比例缩小所有列
|
|
42232
|
+
var scaleFactor_1 = maxTableWidth / finalTotalWidth;
|
|
42233
|
+
adjustColumnWidths = adjustColumnWidths.map(function (width) { return Math.max(10, Math.floor(width * scaleFactor_1 * 100) / 100); });
|
|
42234
|
+
}
|
|
42235
|
+
}
|
|
42236
|
+
}
|
|
42237
|
+
}
|
|
42238
|
+
// 应用新的列宽度
|
|
41684
42239
|
distExports$1.Transforms.setNodes(editorWhenMouseDown, { columnWidths: adjustColumnWidths }, {
|
|
41685
42240
|
mode: 'highest',
|
|
41686
42241
|
});
|