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