roosterjs-content-model-api 9.59.0 → 9.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/modelApi/table/mergeTableCells.js +36 -2
- package/lib/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib/modelApi/table/mergeTableColumn.js +1 -2
- package/lib/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib/modelApi/table/mergeTableRow.js +1 -2
- package/lib/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib/publicApi/table/applyTableBorderFormat.d.ts +1 -0
- package/lib/publicApi/table/applyTableBorderFormat.js +104 -26
- package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableCells.js +37 -2
- package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableColumn.js +2 -2
- package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableRow.js +2 -2
- package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-amd/publicApi/table/applyTableBorderFormat.d.ts +1 -0
- package/lib-amd/publicApi/table/applyTableBorderFormat.js +104 -26
- package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableCells.js +36 -2
- package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableColumn.js +1 -2
- package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableRow.js +1 -2
- package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-mjs/publicApi/table/applyTableBorderFormat.d.ts +1 -0
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js +106 -28
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/package.json +3 -3
- package/lib/modelApi/table/canMergeCells.d.ts +0 -5
- package/lib/modelApi/table/canMergeCells.js +0 -57
- package/lib/modelApi/table/canMergeCells.js.map +0 -1
- package/lib-amd/modelApi/table/canMergeCells.d.ts +0 -5
- package/lib-amd/modelApi/table/canMergeCells.js +0 -59
- package/lib-amd/modelApi/table/canMergeCells.js.map +0 -1
- package/lib-mjs/modelApi/table/canMergeCells.d.ts +0 -5
- package/lib-mjs/modelApi/table/canMergeCells.js +0 -53
- package/lib-mjs/modelApi/table/canMergeCells.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { canMergeCells } from '
|
|
2
|
-
import { getSelectedCells, mutateBlock } from 'roosterjs-content-model-dom';
|
|
1
|
+
import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';
|
|
3
2
|
/**
|
|
4
3
|
* @internal
|
|
5
4
|
*/
|
|
@@ -7,6 +6,15 @@ export function mergeTableCells(table) {
|
|
|
7
6
|
var sel = getSelectedCells(table);
|
|
8
7
|
if (sel &&
|
|
9
8
|
canMergeCells(table.rows, sel.firstRow, sel.firstColumn, sel.lastRow, sel.lastColumn)) {
|
|
9
|
+
var firstCell = mutateBlock(table.rows[sel.firstRow].cells[sel.firstColumn]);
|
|
10
|
+
var borderTop = getHorizontalBorder(table, sel.firstRow, sel, 'borderTop');
|
|
11
|
+
var borderRight = getVerticalBorder(table, sel.lastColumn, sel, 'borderRight');
|
|
12
|
+
var borderBottom = getHorizontalBorder(table, sel.lastRow, sel, 'borderBottom');
|
|
13
|
+
var borderLeft = getVerticalBorder(table, sel.firstColumn, sel, 'borderLeft');
|
|
14
|
+
setBorder(firstCell.format, 'borderTop', borderTop);
|
|
15
|
+
setBorder(firstCell.format, 'borderRight', borderRight);
|
|
16
|
+
setBorder(firstCell.format, 'borderBottom', borderBottom);
|
|
17
|
+
setBorder(firstCell.format, 'borderLeft', borderLeft);
|
|
10
18
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
11
19
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
12
20
|
var cell = table.rows[rowIndex].cells[colIndex];
|
|
@@ -19,4 +27,30 @@ export function mergeTableCells(table) {
|
|
|
19
27
|
}
|
|
20
28
|
}
|
|
21
29
|
}
|
|
30
|
+
function getHorizontalBorder(table, rowIndex, sel, borderKey) {
|
|
31
|
+
var border = table.rows[rowIndex].cells[sel.firstColumn].format[borderKey];
|
|
32
|
+
return border &&
|
|
33
|
+
table.rows[rowIndex].cells
|
|
34
|
+
.slice(sel.firstColumn, sel.lastColumn + 1)
|
|
35
|
+
.every(function (cell) { return cell.format[borderKey] == border; })
|
|
36
|
+
? border
|
|
37
|
+
: undefined;
|
|
38
|
+
}
|
|
39
|
+
function getVerticalBorder(table, columnIndex, sel, borderKey) {
|
|
40
|
+
var border = table.rows[sel.firstRow].cells[columnIndex].format[borderKey];
|
|
41
|
+
return border &&
|
|
42
|
+
table.rows
|
|
43
|
+
.slice(sel.firstRow, sel.lastRow + 1)
|
|
44
|
+
.every(function (row) { return row.cells[columnIndex].format[borderKey] == border; })
|
|
45
|
+
? border
|
|
46
|
+
: undefined;
|
|
47
|
+
}
|
|
48
|
+
function setBorder(format, borderKey, border) {
|
|
49
|
+
if (border) {
|
|
50
|
+
format[borderKey] = border;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
delete format[borderKey];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
22
56
|
//# sourceMappingURL=mergeTableCells.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTableCells.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableCells.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mergeTableCells.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableCells.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aA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,CAAC,SAAS,CAAC,CAAC;IAE7E,OAAO,MAAM;QACT,KAAK,CAAC,IAAI;aACL,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;aACpC,KAAK,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,EAAlD,CAAkD,CAAC;QACrE,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,SAAS,CAAC;AACpB,CAAC;AAED,SAAS,SAAS,CACd,MAAmC,EACnC,SAAoB,EACpB,MAA0B;IAE1B,IAAI,MAAM,EAAE;QACR,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;KAC9B;SAAM;QACH,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;KAC5B;AACL,CAAC","sourcesContent":["import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';\nimport type {\n BorderKey,\n ContentModelTableCellFormat,\n ShallowMutableContentModelTable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function mergeTableCells(table: ShallowMutableContentModelTable) {\n const sel = getSelectedCells(table);\n\n if (\n sel &&\n canMergeCells(table.rows, sel.firstRow, sel.firstColumn, sel.lastRow, sel.lastColumn)\n ) {\n const firstCell = mutateBlock(table.rows[sel.firstRow].cells[sel.firstColumn]);\n const borderTop = getHorizontalBorder(table, sel.firstRow, sel, 'borderTop');\n const borderRight = getVerticalBorder(table, sel.lastColumn, sel, 'borderRight');\n const borderBottom = getHorizontalBorder(table, sel.lastRow, sel, 'borderBottom');\n const borderLeft = getVerticalBorder(table, sel.firstColumn, sel, 'borderLeft');\n\n setBorder(firstCell.format, 'borderTop', borderTop);\n setBorder(firstCell.format, 'borderRight', borderRight);\n setBorder(firstCell.format, 'borderBottom', borderBottom);\n setBorder(firstCell.format, 'borderLeft', borderLeft);\n\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = table.rows[rowIndex].cells[colIndex];\n\n if (cell) {\n const mutableCell = mutateBlock(cell);\n\n mutableCell.spanLeft = colIndex > sel.firstColumn;\n mutableCell.spanAbove = rowIndex > sel.firstRow;\n }\n }\n }\n }\n}\n\nfunction getHorizontalBorder(\n table: ShallowMutableContentModelTable,\n rowIndex: number,\n sel: { firstColumn: number; lastColumn: number },\n borderKey: BorderKey\n) {\n const border = table.rows[rowIndex].cells[sel.firstColumn].format[borderKey];\n\n return border &&\n table.rows[rowIndex].cells\n .slice(sel.firstColumn, sel.lastColumn + 1)\n .every(cell => cell.format[borderKey] == border)\n ? border\n : undefined;\n}\n\nfunction getVerticalBorder(\n table: ShallowMutableContentModelTable,\n columnIndex: number,\n sel: { firstRow: number; lastRow: number },\n borderKey: BorderKey\n) {\n const border = table.rows[sel.firstRow].cells[columnIndex].format[borderKey];\n\n return border &&\n table.rows\n .slice(sel.firstRow, sel.lastRow + 1)\n .every(row => row.cells[columnIndex].format[borderKey] == border)\n ? border\n : undefined;\n}\n\nfunction setBorder(\n format: ContentModelTableCellFormat,\n borderKey: BorderKey,\n border: string | undefined\n) {\n if (border) {\n format[borderKey] = border;\n } else {\n delete format[borderKey];\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mergeTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAM3F;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC5B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CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC","sourcesContent":["import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\n TableHorizontalMergeOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function mergeTableColumn(\n table: ShallowMutableContentModelTable,\n operation: TableHorizontalMergeOperation\n) {\n const sel = getSelectedCells(table);\n const mergeLeft = operation == 'mergeLeft';\n\n if (sel) {\n const mergingColIndex = mergeLeft ? sel.firstColumn : sel.lastColumn + 1;\n\n if (mergingColIndex > 0 && mergingColIndex < table.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = table.rows[rowIndex]?.cells[mergingColIndex];\n\n if (\n cell &&\n canMergeCells(\n table.rows,\n rowIndex,\n mergingColIndex - 1,\n rowIndex,\n mergingColIndex\n )\n ) {\n mutateBlock(cell).spanLeft = true;\n\n let newSelectedCol = mergingColIndex;\n\n while (table.rows[rowIndex]?.cells[newSelectedCol]?.spanLeft) {\n mutateBlock(table.rows[rowIndex].cells[newSelectedCol]);\n newSelectedCol--;\n }\n\n const newCell = table.rows[rowIndex]?.cells[newSelectedCol];\n if (newCell) {\n mutateBlock(newCell).isSelected = true;\n }\n }\n }\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableRow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"mergeTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableRow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAM3F;;GA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CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC","sourcesContent":["import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\n TableVerticalMergeOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function mergeTableRow(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalMergeOperation\n) {\n const sel = getSelectedCells(table);\n const mergeAbove = operation == 'mergeAbove';\n\n if (sel) {\n const mergingRowIndex = mergeAbove ? sel.firstRow : sel.lastRow + 1;\n\n if (mergingRowIndex > 0 && mergingRowIndex < table.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = table.rows[mergingRowIndex].cells[colIndex];\n\n if (\n cell &&\n canMergeCells(\n table.rows,\n mergingRowIndex - 1,\n colIndex,\n mergingRowIndex,\n colIndex\n )\n ) {\n mutateBlock(cell).spanAbove = true;\n\n let newSelectedRow = mergingRowIndex;\n\n while (table.rows[newSelectedRow]?.cells[colIndex]?.spanAbove) {\n mutateBlock(table.rows[newSelectedRow].cells[colIndex]);\n newSelectedRow--;\n }\n\n const newCell = table.rows[newSelectedRow]?.cells[colIndex];\n\n if (newCell) {\n mutateBlock(newCell).isSelected = true;\n }\n }\n }\n }\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IEditor, Border, BorderOperations } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Operations to apply border
|
|
4
|
+
* Remove the targeted borders instead if they all already match the requested format.
|
|
4
5
|
* @param editor The editor instance
|
|
5
6
|
* @param border The border to apply
|
|
6
7
|
* @param operation The operation to apply
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { __read } from "tslib";
|
|
2
|
-
import { extractBorderValues, getFirstSelectedTable, getSelectedCells, mutateBlock, getTableMetadata, parseValueWithUnit, setFirstColumnFormatBorders, updateTableCellMetadata, } from 'roosterjs-content-model-dom';
|
|
1
|
+
import { __read, __values } from "tslib";
|
|
2
|
+
import { extractBorderValues, getFirstSelectedTable, getSelectedCells, mutateBlock, getTableMetadata, parseValueWithUnit, parseColor, setFirstColumnFormatBorders, updateTableCellMetadata, } from 'roosterjs-content-model-dom';
|
|
3
3
|
/**
|
|
4
4
|
* Operations to apply border
|
|
5
|
+
* Remove the targeted borders instead if they all already match the requested format.
|
|
5
6
|
* @param editor The editor instance
|
|
6
7
|
* @param border The border to apply
|
|
7
8
|
* @param operation The operation to apply
|
|
8
9
|
*/
|
|
9
10
|
export function applyTableBorderFormat(editor, border, operation) {
|
|
10
11
|
editor.formatContentModel(function (model) {
|
|
11
|
-
var
|
|
12
|
+
var e_1, _a;
|
|
13
|
+
var _b = __read(getFirstSelectedTable(model), 1), tableModel = _b[0];
|
|
12
14
|
if (tableModel) {
|
|
13
15
|
var sel = getSelectedCells(tableModel);
|
|
14
16
|
var perimeter = {
|
|
@@ -52,6 +54,10 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
52
54
|
// undefined is treated as Left to Right
|
|
53
55
|
var isRtl = tableModel.format.direction == 'rtl';
|
|
54
56
|
if (sel) {
|
|
57
|
+
var borderUpdates_2 = [];
|
|
58
|
+
var collectBorderFormat = function (cell, positions) {
|
|
59
|
+
borderUpdates_2.push({ cell: cell, positions: positions });
|
|
60
|
+
};
|
|
55
61
|
var operations = [operation];
|
|
56
62
|
while (operations.length) {
|
|
57
63
|
switch (operations.pop()) {
|
|
@@ -71,7 +77,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
71
77
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
72
78
|
var cell = tableModel.rows[rowIndex].cells[colIndex];
|
|
73
79
|
// Format cells - All borders
|
|
74
|
-
|
|
80
|
+
collectBorderFormat(cell, allBorders);
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
// Format perimeter
|
|
@@ -85,7 +91,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
85
91
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
86
92
|
var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
|
|
87
93
|
// Format cells - Left border
|
|
88
|
-
|
|
94
|
+
collectBorderFormat(cell, leftBorder);
|
|
89
95
|
}
|
|
90
96
|
// Format perimeter
|
|
91
97
|
isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
|
|
@@ -95,7 +101,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
95
101
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
96
102
|
var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
|
|
97
103
|
// Format cells - Right border
|
|
98
|
-
|
|
104
|
+
collectBorderFormat(cell, rightBorder);
|
|
99
105
|
}
|
|
100
106
|
// Format perimeter
|
|
101
107
|
isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
|
|
@@ -105,7 +111,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
105
111
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
106
112
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
107
113
|
// Format cells - Top border
|
|
108
|
-
|
|
114
|
+
collectBorderFormat(cell, topBorder);
|
|
109
115
|
}
|
|
110
116
|
// Format perimeter
|
|
111
117
|
perimeter.Top = true;
|
|
@@ -115,7 +121,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
115
121
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
116
122
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
117
123
|
// Format cells - Bottom border
|
|
118
|
-
|
|
124
|
+
collectBorderFormat(cell, bottomBorder);
|
|
119
125
|
}
|
|
120
126
|
// Format perimeter
|
|
121
127
|
perimeter.Bottom = true;
|
|
@@ -130,43 +136,37 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
130
136
|
}
|
|
131
137
|
// Single column selection
|
|
132
138
|
if (singleCol) {
|
|
133
|
-
|
|
139
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], ['borderBottom']);
|
|
134
140
|
for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
|
|
135
141
|
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
136
|
-
|
|
137
|
-
'borderTop',
|
|
138
|
-
'borderBottom',
|
|
139
|
-
]);
|
|
142
|
+
collectBorderFormat(cell, ['borderTop', 'borderBottom']);
|
|
140
143
|
}
|
|
141
|
-
|
|
144
|
+
collectBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], ['borderTop']);
|
|
142
145
|
break;
|
|
143
146
|
}
|
|
144
147
|
// Single row selection
|
|
145
148
|
if (singleRow) {
|
|
146
|
-
|
|
149
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderRight']);
|
|
147
150
|
for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
|
|
148
151
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
149
|
-
|
|
150
|
-
'borderLeft',
|
|
151
|
-
'borderRight',
|
|
152
|
-
]);
|
|
152
|
+
collectBorderFormat(cell, ['borderLeft', 'borderRight']);
|
|
153
153
|
}
|
|
154
|
-
|
|
154
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderLeft']);
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
// For multiple rows and columns selections
|
|
158
158
|
// Top left cell
|
|
159
|
-
|
|
159
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderBottom', 'borderRight']);
|
|
160
160
|
// Top right cell
|
|
161
|
-
|
|
161
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderBottom', 'borderLeft']);
|
|
162
162
|
// Bottom left cell
|
|
163
|
-
|
|
163
|
+
collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderTop', 'borderRight']);
|
|
164
164
|
// Bottom right cell
|
|
165
|
-
|
|
165
|
+
collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderTop', 'borderLeft']);
|
|
166
166
|
// First row
|
|
167
167
|
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
168
168
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
169
|
-
|
|
169
|
+
collectBorderFormat(cell, [
|
|
170
170
|
'borderBottom',
|
|
171
171
|
'borderLeft',
|
|
172
172
|
'borderRight',
|
|
@@ -175,7 +175,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
175
175
|
// Last row
|
|
176
176
|
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
177
177
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
178
|
-
|
|
178
|
+
collectBorderFormat(cell, [
|
|
179
179
|
'borderTop',
|
|
180
180
|
'borderLeft',
|
|
181
181
|
'borderRight',
|
|
@@ -184,7 +184,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
184
184
|
// First column
|
|
185
185
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
186
186
|
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
187
|
-
|
|
187
|
+
collectBorderFormat(cell, [
|
|
188
188
|
'borderTop',
|
|
189
189
|
'borderBottom',
|
|
190
190
|
isRtl ? 'borderLeft' : 'borderRight',
|
|
@@ -193,7 +193,7 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
193
193
|
// Last column
|
|
194
194
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
195
195
|
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
196
|
-
|
|
196
|
+
collectBorderFormat(cell, [
|
|
197
197
|
'borderTop',
|
|
198
198
|
'borderBottom',
|
|
199
199
|
isRtl ? 'borderRight' : 'borderLeft',
|
|
@@ -217,6 +217,26 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
217
217
|
break;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
// Compare before changing any cells, and only consider borders targeted by
|
|
221
|
+
// this operation. Normalize CSS so DOM colors (rgb) also match hex input.
|
|
222
|
+
if (operation != 'noBorders' &&
|
|
223
|
+
borderUpdates_2.length > 0 &&
|
|
224
|
+
hasMatchingBorders(borderUpdates_2, borderFormat)) {
|
|
225
|
+
borderFormat = '';
|
|
226
|
+
}
|
|
227
|
+
try {
|
|
228
|
+
for (var borderUpdates_1 = __values(borderUpdates_2), borderUpdates_1_1 = borderUpdates_1.next(); !borderUpdates_1_1.done; borderUpdates_1_1 = borderUpdates_1.next()) {
|
|
229
|
+
var _c = borderUpdates_1_1.value, cell = _c.cell, positions = _c.positions;
|
|
230
|
+
applyBorderFormat(cell, borderFormat, positions);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
234
|
+
finally {
|
|
235
|
+
try {
|
|
236
|
+
if (borderUpdates_1_1 && !borderUpdates_1_1.done && (_a = borderUpdates_1.return)) _a.call(borderUpdates_1);
|
|
237
|
+
}
|
|
238
|
+
finally { if (e_1) throw e_1.error; }
|
|
239
|
+
}
|
|
220
240
|
//Format perimeter if necessary or possible
|
|
221
241
|
modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
|
|
222
242
|
}
|
|
@@ -234,6 +254,64 @@ export function applyTableBorderFormat(editor, border, operation) {
|
|
|
234
254
|
apiName: 'tableBorder',
|
|
235
255
|
});
|
|
236
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Check targeted borders without repeatedly parsing identical CSS values.
|
|
259
|
+
* @param borderUpdates The borders to compare
|
|
260
|
+
* @param borderFormat The requested border format
|
|
261
|
+
*/
|
|
262
|
+
function hasMatchingBorders(borderUpdates, borderFormat) {
|
|
263
|
+
var e_2, _a, e_3, _b;
|
|
264
|
+
var matchingBorders = new Set();
|
|
265
|
+
try {
|
|
266
|
+
for (var borderUpdates_3 = __values(borderUpdates), borderUpdates_3_1 = borderUpdates_3.next(); !borderUpdates_3_1.done; borderUpdates_3_1 = borderUpdates_3.next()) {
|
|
267
|
+
var _c = borderUpdates_3_1.value, cell = _c.cell, positions = _c.positions;
|
|
268
|
+
try {
|
|
269
|
+
for (var positions_1 = (e_3 = void 0, __values(positions)), positions_1_1 = positions_1.next(); !positions_1_1.done; positions_1_1 = positions_1.next()) {
|
|
270
|
+
var pos = positions_1_1.value;
|
|
271
|
+
var value = cell.format[pos] || '';
|
|
272
|
+
// Exact matches need no CSS parsing. Equivalent values are parsed only once.
|
|
273
|
+
if (value == borderFormat || matchingBorders.has(value)) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (!areSameBorders(value, borderFormat)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
matchingBorders.add(value);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
283
|
+
finally {
|
|
284
|
+
try {
|
|
285
|
+
if (positions_1_1 && !positions_1_1.done && (_b = positions_1.return)) _b.call(positions_1);
|
|
286
|
+
}
|
|
287
|
+
finally { if (e_3) throw e_3.error; }
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
292
|
+
finally {
|
|
293
|
+
try {
|
|
294
|
+
if (borderUpdates_3_1 && !borderUpdates_3_1.done && (_a = borderUpdates_3.return)) _a.call(borderUpdates_3);
|
|
295
|
+
}
|
|
296
|
+
finally { if (e_2) throw e_2.error; }
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Compare border components, parsing colors to account for equivalent hex and RGB values.
|
|
302
|
+
*/
|
|
303
|
+
function areSameBorders(border1, border2) {
|
|
304
|
+
var values1 = extractBorderValues(border1);
|
|
305
|
+
var values2 = extractBorderValues(border2);
|
|
306
|
+
var color1 = values1.color || '';
|
|
307
|
+
var color2 = values2.color || '';
|
|
308
|
+
var rgb1 = parseColor(color1);
|
|
309
|
+
var rgb2 = parseColor(color2);
|
|
310
|
+
return (values1.width == values2.width &&
|
|
311
|
+
values1.style == values2.style &&
|
|
312
|
+
(color1 == color2 ||
|
|
313
|
+
(!!rgb1 && !!rgb2 && rgb1[0] == rgb2[0] && rgb1[1] == rgb2[1] && rgb1[2] == rgb2[2])));
|
|
314
|
+
}
|
|
237
315
|
/**
|
|
238
316
|
* @internal
|
|
239
317
|
* Apply border format to a cell
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,2BAA2B,EAC3B,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AA4BrC;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA,OAAe,qBAAqB,CAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;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D;KACJ;IACD,oBAAoB;IACpB,IAAI,SAAS,CAAC,IAAI,IAAI,GAAG,CAAC,WAAW,GAAG,CAAC,IAAI,CAAC,EAAE;QAC5C,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;YAClE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;SACjF;KACJ;IACD,qBAAqB;IACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;QACzE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;SACjF;KACJ;AACL,CAAC","sourcesContent":["import {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n mutateBlock,\n getTableMetadata,\n parseValueWithUnit,\n setFirstColumnFormatBorders,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n IEditor,\n Border,\n BorderOperations,\n TableSelectionCoordinates,\n ReadonlyContentModelTableCell,\n ReadonlyContentModelTable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport function applyTableBorderFormat(\n editor: IEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n // undefined is treated as Left to Right\n const isRtl = tableModel.format.direction == 'rtl';\n\n if (sel) {\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n applyBorderFormat(cell, borderFormat, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Right = true) : (perimeter.Left = true);\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Left = true) : (perimeter.Right = true);\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n applyBorderFormat(cell, borderFormat, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n applyBorderFormat(cell, borderFormat, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastColumn == sel.firstColumn;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex <= sel.lastColumn - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderLeft',\n 'borderRight',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderLeft' : 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderRight' : 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstColumn++;\n sel.firstRow++;\n sel.lastColumn--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);\n }\n\n const tableMeta = getTableMetadata(tableModel);\n if (tableMeta) {\n // Enforce first column format if necessary\n setFirstColumnFormatBorders(mutateBlock(tableModel).rows, tableMeta);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ReadonlyContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n const mutableCell = mutateBlock(cell);\n\n positions.forEach(pos => {\n mutableCell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(mutableCell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ReadonlyContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter,\n isRtl: boolean\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstColumn - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,2BAA2B,EAC3B,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AAqCrC;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;;QACK,IAAA,KAAA,OAAe,qBAAqB,CAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;QAElD,IAAI,UAAU,EAAE;YACZ,IAAM,GAAG,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;YACzC,IAAM,SAAS,GAAc;gBACzB,GAAG,EAAE,KAAK;gBACV,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,KAAK;aACf,CAAC;YAEF,mDAAmD;YACnD,IAAI,YAAY,GAAG,EAAE,CAAC;YACtB,IAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;YACzB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,KAAK,GAAK,MAAM,MAAX,CAAY;YACvC,IAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC9D,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,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umnFormatBorders,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n IEditor,\n Border,\n BorderOperations,\n TableSelectionCoordinates,\n ReadonlyContentModelTableCell,\n ReadonlyContentModelTable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Border positions to update on a cell\n */\ntype BorderUpdate = {\n cell: ReadonlyContentModelTableCell;\n positions: BorderPositions[];\n};\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * Remove the targeted borders instead if they all already match the requested format.\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport function applyTableBorderFormat(\n editor: IEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n // undefined is treated as Left to Right\n const isRtl = tableModel.format.direction == 'rtl';\n\n if (sel) {\n const borderUpdates: BorderUpdate[] = [];\n const collectBorderFormat = (\n cell: ReadonlyContentModelTableCell,\n positions: BorderPositions[]\n ) => {\n borderUpdates.push({ cell, positions });\n };\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n collectBorderFormat(cell, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ];\n // Format cells - Left border\n collectBorderFormat(cell, leftBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Right = true) : (perimeter.Left = true);\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ];\n // Format cells - Right border\n collectBorderFormat(cell, rightBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Left = true) : (perimeter.Right = true);\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n collectBorderFormat(cell, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n collectBorderFormat(cell, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastColumn == sel.firstColumn;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n collectBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[sel.firstColumn];\n collectBorderFormat(cell, ['borderTop', 'borderBottom']);\n }\n collectBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n collectBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n ['borderRight']\n );\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex <= sel.lastColumn - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n collectBorderFormat(cell, ['borderLeft', 'borderRight']);\n }\n collectBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n collectBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n collectBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n collectBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n collectBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n collectBorderFormat(cell, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n collectBorderFormat(cell, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n collectBorderFormat(cell, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderLeft' : 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n collectBorderFormat(cell, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderRight' : 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstColumn++;\n sel.firstRow++;\n sel.lastColumn--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n // Compare before changing any cells, and only consider borders targeted by\n // this operation. Normalize CSS so DOM colors (rgb) also match hex input.\n if (\n operation != 'noBorders' &&\n borderUpdates.length > 0 &&\n hasMatchingBorders(borderUpdates, borderFormat)\n ) {\n borderFormat = '';\n }\n\n for (const { cell, positions } of borderUpdates) {\n applyBorderFormat(cell, borderFormat, positions);\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);\n }\n\n const tableMeta = getTableMetadata(tableModel);\n if (tableMeta) {\n // Enforce first column format if necessary\n setFirstColumnFormatBorders(mutateBlock(tableModel).rows, tableMeta);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * Check targeted borders without repeatedly parsing identical CSS values.\n * @param borderUpdates The borders to compare\n * @param borderFormat The requested border format\n */\nfunction hasMatchingBorders(borderUpdates: BorderUpdate[], borderFormat: string): boolean {\n const matchingBorders = new Set<string>();\n\n for (const { cell, positions } of borderUpdates) {\n for (const pos of positions) {\n const value = cell.format[pos] || '';\n\n // Exact matches need no CSS parsing. Equivalent values are parsed only once.\n if (value == borderFormat || matchingBorders.has(value)) {\n continue;\n }\n\n if (!areSameBorders(value, borderFormat)) {\n return false;\n }\n\n matchingBorders.add(value);\n }\n }\n\n return true;\n}\n\n/**\n * Compare border components, parsing colors to account for equivalent hex and RGB values.\n */\nfunction areSameBorders(border1: string, border2: string): boolean {\n const values1 = extractBorderValues(border1);\n const values2 = extractBorderValues(border2);\n const color1 = values1.color || '';\n const color2 = values2.color || '';\n const rgb1 = parseColor(color1);\n const rgb2 = parseColor(color2);\n\n return (\n values1.width == values2.width &&\n values1.style == values2.style &&\n (color1 == color2 ||\n (!!rgb1 && !!rgb2 && rgb1[0] == rgb2[0] && rgb1[1] == rgb2[1] && rgb1[2] == rgb2[2]))\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ReadonlyContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n const mutableCell = mutateBlock(cell);\n\n positions.forEach(pos => {\n mutableCell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(mutableCell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ReadonlyContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter,\n isRtl: boolean\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstColumn - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"description": "Format API for roosterjs",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"tslib": "^2.3.1",
|
|
6
|
-
"roosterjs-content-model-dom": "^9.
|
|
7
|
-
"roosterjs-content-model-types": "^9.
|
|
6
|
+
"roosterjs-content-model-dom": "^9.60.0",
|
|
7
|
+
"roosterjs-content-model-types": "^9.60.0"
|
|
8
8
|
},
|
|
9
|
-
"version": "9.
|
|
9
|
+
"version": "9.60.0",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"typings": "./lib/index.d.ts",
|
|
12
12
|
"module": "./lib-mjs/index.js",
|