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.
Files changed (37) hide show
  1. package/lib/modelApi/table/mergeTableCells.js +36 -2
  2. package/lib/modelApi/table/mergeTableCells.js.map +1 -1
  3. package/lib/modelApi/table/mergeTableColumn.js +1 -2
  4. package/lib/modelApi/table/mergeTableColumn.js.map +1 -1
  5. package/lib/modelApi/table/mergeTableRow.js +1 -2
  6. package/lib/modelApi/table/mergeTableRow.js.map +1 -1
  7. package/lib/publicApi/table/applyTableBorderFormat.d.ts +1 -0
  8. package/lib/publicApi/table/applyTableBorderFormat.js +104 -26
  9. package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
  10. package/lib-amd/modelApi/table/mergeTableCells.js +37 -2
  11. package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
  12. package/lib-amd/modelApi/table/mergeTableColumn.js +2 -2
  13. package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
  14. package/lib-amd/modelApi/table/mergeTableRow.js +2 -2
  15. package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
  16. package/lib-amd/publicApi/table/applyTableBorderFormat.d.ts +1 -0
  17. package/lib-amd/publicApi/table/applyTableBorderFormat.js +104 -26
  18. package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
  19. package/lib-mjs/modelApi/table/mergeTableCells.js +36 -2
  20. package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
  21. package/lib-mjs/modelApi/table/mergeTableColumn.js +1 -2
  22. package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
  23. package/lib-mjs/modelApi/table/mergeTableRow.js +1 -2
  24. package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
  25. package/lib-mjs/publicApi/table/applyTableBorderFormat.d.ts +1 -0
  26. package/lib-mjs/publicApi/table/applyTableBorderFormat.js +106 -28
  27. package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
  28. package/package.json +3 -3
  29. package/lib/modelApi/table/canMergeCells.d.ts +0 -5
  30. package/lib/modelApi/table/canMergeCells.js +0 -57
  31. package/lib/modelApi/table/canMergeCells.js.map +0 -1
  32. package/lib-amd/modelApi/table/canMergeCells.d.ts +0 -5
  33. package/lib-amd/modelApi/table/canMergeCells.js +0 -59
  34. package/lib-amd/modelApi/table/canMergeCells.js.map +0 -1
  35. package/lib-mjs/modelApi/table/canMergeCells.d.ts +0 -5
  36. package/lib-mjs/modelApi/table/canMergeCells.js +0 -53
  37. package/lib-mjs/modelApi/table/canMergeCells.js.map +0 -1
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeTableCells = void 0;
4
- var canMergeCells_1 = require("./canMergeCells");
5
4
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
5
  /**
7
6
  * @internal
@@ -9,7 +8,16 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
9
8
  function mergeTableCells(table) {
10
9
  var sel = (0, roosterjs_content_model_dom_1.getSelectedCells)(table);
11
10
  if (sel &&
12
- (0, canMergeCells_1.canMergeCells)(table.rows, sel.firstRow, sel.firstColumn, sel.lastRow, sel.lastColumn)) {
11
+ (0, roosterjs_content_model_dom_1.canMergeCells)(table.rows, sel.firstRow, sel.firstColumn, sel.lastRow, sel.lastColumn)) {
12
+ var firstCell = (0, roosterjs_content_model_dom_1.mutateBlock)(table.rows[sel.firstRow].cells[sel.firstColumn]);
13
+ var borderTop = getHorizontalBorder(table, sel.firstRow, sel, 'borderTop');
14
+ var borderRight = getVerticalBorder(table, sel.lastColumn, sel, 'borderRight');
15
+ var borderBottom = getHorizontalBorder(table, sel.lastRow, sel, 'borderBottom');
16
+ var borderLeft = getVerticalBorder(table, sel.firstColumn, sel, 'borderLeft');
17
+ setBorder(firstCell.format, 'borderTop', borderTop);
18
+ setBorder(firstCell.format, 'borderRight', borderRight);
19
+ setBorder(firstCell.format, 'borderBottom', borderBottom);
20
+ setBorder(firstCell.format, 'borderLeft', borderLeft);
13
21
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
14
22
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
15
23
  var cell = table.rows[rowIndex].cells[colIndex];
@@ -23,4 +31,30 @@ function mergeTableCells(table) {
23
31
  }
24
32
  }
25
33
  exports.mergeTableCells = mergeTableCells;
34
+ function getHorizontalBorder(table, rowIndex, sel, borderKey) {
35
+ var border = table.rows[rowIndex].cells[sel.firstColumn].format[borderKey];
36
+ return border &&
37
+ table.rows[rowIndex].cells
38
+ .slice(sel.firstColumn, sel.lastColumn + 1)
39
+ .every(function (cell) { return cell.format[borderKey] == border; })
40
+ ? border
41
+ : undefined;
42
+ }
43
+ function getVerticalBorder(table, columnIndex, sel, borderKey) {
44
+ var border = table.rows[sel.firstRow].cells[columnIndex].format[borderKey];
45
+ return border &&
46
+ table.rows
47
+ .slice(sel.firstRow, sel.lastRow + 1)
48
+ .every(function (row) { return row.cells[columnIndex].format[borderKey] == border; })
49
+ ? border
50
+ : undefined;
51
+ }
52
+ function setBorder(format, borderKey, border) {
53
+ if (border) {
54
+ format[borderKey] = border;
55
+ }
56
+ else {
57
+ delete format[borderKey];
58
+ }
59
+ }
26
60
  //# 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,iDAAgD;AAChD,2EAA4E;AAG5E;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAsC;IAClE,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IAEpC,IACI,GAAG;QACH,IAAA,6BAAa,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,EACvF;QACE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YACnE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;gBACzE,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAElD,IAAI,IAAI,EAAE;oBACN,IAAM,WAAW,GAAG,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC;oBAEtC,WAAW,CAAC,QAAQ,GAAG,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC;oBAClD,WAAW,CAAC,SAAS,GAAG,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;iBACnD;aACJ;SACJ;KACJ;AACL,CAAC;AApBD,0CAoBC","sourcesContent":["import { canMergeCells } from './canMergeCells';\nimport { getSelectedCells, mutateBlock } from 'roosterjs-content-model-dom';\nimport type { ShallowMutableContentModelTable } 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 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"]}
1
+ {"version":3,"file":"mergeTableCells.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AAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeTableColumn = void 0;
4
- var canMergeCells_1 = require("./canMergeCells");
5
4
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
5
  /**
7
6
  * @internal
@@ -16,7 +15,7 @@ function mergeTableColumn(table, operation) {
16
15
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
17
16
  var cell = (_a = table.rows[rowIndex]) === null || _a === void 0 ? void 0 : _a.cells[mergingColIndex];
18
17
  if (cell &&
19
- (0, canMergeCells_1.canMergeCells)(table.rows, rowIndex, mergingColIndex - 1, rowIndex, mergingColIndex)) {
18
+ (0, roosterjs_content_model_dom_1.canMergeCells)(table.rows, rowIndex, mergingColIndex - 1, rowIndex, mergingColIndex)) {
20
19
  (0, roosterjs_content_model_dom_1.mutateBlock)(cell).spanLeft = true;
21
20
  var newSelectedCol = mergingColIndex;
22
21
  while ((_c = (_b = table.rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.cells[newSelectedCol]) === null || _c === void 0 ? void 0 : _c.spanLeft) {
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableColumn.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,2EAA4E;AAM5E;;GAEG;AACH,SAAgB,gBAAgB,CAC5B,KAAsC,EACtC,SAAwC;;IAExC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,SAAS,GAAG,SAAS,IAAI,WAAW,CAAC;IAE3C,IAAI,GAAG,EAAE;QACL,IAAM,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC;QAEzE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACrE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,IAAM,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,eAAe,CAAC,CAAC;gBAE1D,IACI,IAAI;oBACJ,IAAA,6BAAa,EACT,KAAK,CAAC,IAAI,EACV,QAAQ,EACR,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,CAClB,EACH;oBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;oBAElC,IAAI,cAAc,GAAG,eAAe,CAAC;oBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,0CAAE,QAAQ,EAAE;wBAC1D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;wBACxD,cAAc,EAAE,CAAC;qBACpB;oBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,CAAC;oBAC5D,IAAI,OAAO,EAAE;wBACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC;AAzCD,4CAyCC","sourcesContent":["import { canMergeCells } from './canMergeCells';\nimport { getSelectedCells, mutateBlock } 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
+ {"version":3,"file":"mergeTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableColumn.ts"],"names":[],"mappings":";;;AAAA,2EAA2F;AAM3F;;GAEG;AACH,SAAgB,gBAAgB,CAC5B,KAAsC,EACtC,SAAwC;;IAExC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,SAAS,GAAG,SAAS,IAAI,WAAW,CAAC;IAE3C,IAAI,GAAG,EAAE;QACL,IAAM,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC;QAEzE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACrE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,IAAM,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,eAAe,CAAC,CAAC;gBAE1D,IACI,IAAI;oBACJ,IAAA,2CAAa,EACT,KAAK,CAAC,IAAI,EACV,QAAQ,EACR,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,CAClB,EACH;oBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;oBAElC,IAAI,cAAc,GAAG,eAAe,CAAC;oBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,0CAAE,QAAQ,EAAE;wBAC1D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;wBACxD,cAAc,EAAE,CAAC;qBACpB;oBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,CAAC;oBAC5D,IAAI,OAAO,EAAE;wBACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC;AAzCD,4CAyCC","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,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeTableRow = void 0;
4
- var canMergeCells_1 = require("./canMergeCells");
5
4
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
5
  /**
7
6
  * @internal
@@ -16,7 +15,7 @@ function mergeTableRow(table, operation) {
16
15
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
17
16
  var cell = table.rows[mergingRowIndex].cells[colIndex];
18
17
  if (cell &&
19
- (0, canMergeCells_1.canMergeCells)(table.rows, mergingRowIndex - 1, colIndex, mergingRowIndex, colIndex)) {
18
+ (0, roosterjs_content_model_dom_1.canMergeCells)(table.rows, mergingRowIndex - 1, colIndex, mergingRowIndex, colIndex)) {
20
19
  (0, roosterjs_content_model_dom_1.mutateBlock)(cell).spanAbove = true;
21
20
  var newSelectedRow = mergingRowIndex;
22
21
  while ((_b = (_a = table.rows[newSelectedRow]) === null || _a === void 0 ? void 0 : _a.cells[colIndex]) === null || _b === void 0 ? void 0 : _b.spanAbove) {
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableRow.ts"],"names":[],"mappings":";;;AAAA,iDAAgD;AAChD,2EAA4E;AAM5E;;GAEG;AACH,SAAgB,aAAa,CACzB,KAAsC,EACtC,SAAsC;;IAEtC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,IAAM,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;QAEpE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;YAC5D,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;gBACzE,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAEzD,IACI,IAAI;oBACJ,IAAA,6BAAa,EACT,KAAK,CAAC,IAAI,EACV,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,EACf,QAAQ,CACX,EACH;oBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;oBAEnC,IAAI,cAAc,GAAG,eAAe,CAAC;oBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,0CAAE,SAAS,EAAE;wBAC3D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACxD,cAAc,EAAE,CAAC;qBACpB;oBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAE5D,IAAI,OAAO,EAAE;wBACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC;AA1CD,sCA0CC","sourcesContent":["import { canMergeCells } from './canMergeCells';\nimport { getSelectedCells, mutateBlock } 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
+ {"version":3,"file":"mergeTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableRow.ts"],"names":[],"mappings":";;;AAAA,2EAA2F;AAM3F;;GAEG;AACH,SAAgB,aAAa,CACzB,KAAsC,EACtC,SAAsC;;IAEtC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,IAAM,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;QAEpE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;YAC5D,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;gBACzE,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAEzD,IACI,IAAI;oBACJ,IAAA,2CAAa,EACT,KAAK,CAAC,IAAI,EACV,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,EACf,QAAQ,CACX,EACH;oBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;oBAEnC,IAAI,cAAc,GAAG,eAAe,CAAC;oBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,0CAAE,SAAS,EAAE;wBAC3D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACxD,cAAc,EAAE,CAAC;qBACpB;oBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAE5D,IAAI,OAAO,EAAE;wBACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC;AA1CD,sCA0CC","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
@@ -5,13 +5,15 @@ var tslib_1 = require("tslib");
5
5
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
6
  /**
7
7
  * Operations to apply border
8
+ * Remove the targeted borders instead if they all already match the requested format.
8
9
  * @param editor The editor instance
9
10
  * @param border The border to apply
10
11
  * @param operation The operation to apply
11
12
  */
12
13
  function applyTableBorderFormat(editor, border, operation) {
13
14
  editor.formatContentModel(function (model) {
14
- var _a = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getFirstSelectedTable)(model), 1), tableModel = _a[0];
15
+ var e_1, _a;
16
+ var _b = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getFirstSelectedTable)(model), 1), tableModel = _b[0];
15
17
  if (tableModel) {
16
18
  var sel = (0, roosterjs_content_model_dom_1.getSelectedCells)(tableModel);
17
19
  var perimeter = {
@@ -55,6 +57,10 @@ function applyTableBorderFormat(editor, border, operation) {
55
57
  // undefined is treated as Left to Right
56
58
  var isRtl = tableModel.format.direction == 'rtl';
57
59
  if (sel) {
60
+ var borderUpdates_2 = [];
61
+ var collectBorderFormat = function (cell, positions) {
62
+ borderUpdates_2.push({ cell: cell, positions: positions });
63
+ };
58
64
  var operations = [operation];
59
65
  while (operations.length) {
60
66
  switch (operations.pop()) {
@@ -74,7 +80,7 @@ function applyTableBorderFormat(editor, border, operation) {
74
80
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
75
81
  var cell = tableModel.rows[rowIndex].cells[colIndex];
76
82
  // Format cells - All borders
77
- applyBorderFormat(cell, borderFormat, allBorders);
83
+ collectBorderFormat(cell, allBorders);
78
84
  }
79
85
  }
80
86
  // Format perimeter
@@ -88,7 +94,7 @@ function applyTableBorderFormat(editor, border, operation) {
88
94
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
89
95
  var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
90
96
  // Format cells - Left border
91
- applyBorderFormat(cell, borderFormat, leftBorder);
97
+ collectBorderFormat(cell, leftBorder);
92
98
  }
93
99
  // Format perimeter
94
100
  isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
@@ -98,7 +104,7 @@ function applyTableBorderFormat(editor, border, operation) {
98
104
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
99
105
  var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
100
106
  // Format cells - Right border
101
- applyBorderFormat(cell, borderFormat, rightBorder);
107
+ collectBorderFormat(cell, rightBorder);
102
108
  }
103
109
  // Format perimeter
104
110
  isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
@@ -108,7 +114,7 @@ function applyTableBorderFormat(editor, border, operation) {
108
114
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
109
115
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
110
116
  // Format cells - Top border
111
- applyBorderFormat(cell, borderFormat, topBorder);
117
+ collectBorderFormat(cell, topBorder);
112
118
  }
113
119
  // Format perimeter
114
120
  perimeter.Top = true;
@@ -118,7 +124,7 @@ function applyTableBorderFormat(editor, border, operation) {
118
124
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
119
125
  var cell = tableModel.rows[sel.lastRow].cells[colIndex];
120
126
  // Format cells - Bottom border
121
- applyBorderFormat(cell, borderFormat, bottomBorder);
127
+ collectBorderFormat(cell, bottomBorder);
122
128
  }
123
129
  // Format perimeter
124
130
  perimeter.Bottom = true;
@@ -133,43 +139,37 @@ function applyTableBorderFormat(editor, border, operation) {
133
139
  }
134
140
  // Single column selection
135
141
  if (singleCol) {
136
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom']);
142
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], ['borderBottom']);
137
143
  for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
138
144
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
139
- applyBorderFormat(cell, borderFormat, [
140
- 'borderTop',
141
- 'borderBottom',
142
- ]);
145
+ collectBorderFormat(cell, ['borderTop', 'borderBottom']);
143
146
  }
144
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop']);
147
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], ['borderTop']);
145
148
  break;
146
149
  }
147
150
  // Single row selection
148
151
  if (singleRow) {
149
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
152
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderRight']);
150
153
  for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
151
154
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
152
- applyBorderFormat(cell, borderFormat, [
153
- 'borderLeft',
154
- 'borderRight',
155
- ]);
155
+ collectBorderFormat(cell, ['borderLeft', 'borderRight']);
156
156
  }
157
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderLeft']);
157
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderLeft']);
158
158
  break;
159
159
  }
160
160
  // For multiple rows and columns selections
161
161
  // Top left cell
162
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
162
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderBottom', 'borderRight']);
163
163
  // Top right cell
164
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
164
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderBottom', 'borderLeft']);
165
165
  // Bottom left cell
166
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
166
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderTop', 'borderRight']);
167
167
  // Bottom right cell
168
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
168
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderTop', 'borderLeft']);
169
169
  // First row
170
170
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
171
171
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
172
- applyBorderFormat(cell, borderFormat, [
172
+ collectBorderFormat(cell, [
173
173
  'borderBottom',
174
174
  'borderLeft',
175
175
  'borderRight',
@@ -178,7 +178,7 @@ function applyTableBorderFormat(editor, border, operation) {
178
178
  // Last row
179
179
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
180
180
  var cell = tableModel.rows[sel.lastRow].cells[colIndex];
181
- applyBorderFormat(cell, borderFormat, [
181
+ collectBorderFormat(cell, [
182
182
  'borderTop',
183
183
  'borderLeft',
184
184
  'borderRight',
@@ -187,7 +187,7 @@ function applyTableBorderFormat(editor, border, operation) {
187
187
  // First column
188
188
  for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
189
189
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
190
- applyBorderFormat(cell, borderFormat, [
190
+ collectBorderFormat(cell, [
191
191
  'borderTop',
192
192
  'borderBottom',
193
193
  isRtl ? 'borderLeft' : 'borderRight',
@@ -196,7 +196,7 @@ function applyTableBorderFormat(editor, border, operation) {
196
196
  // Last column
197
197
  for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
198
198
  var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
199
- applyBorderFormat(cell, borderFormat, [
199
+ collectBorderFormat(cell, [
200
200
  'borderTop',
201
201
  'borderBottom',
202
202
  isRtl ? 'borderRight' : 'borderLeft',
@@ -220,6 +220,26 @@ function applyTableBorderFormat(editor, border, operation) {
220
220
  break;
221
221
  }
222
222
  }
223
+ // Compare before changing any cells, and only consider borders targeted by
224
+ // this operation. Normalize CSS so DOM colors (rgb) also match hex input.
225
+ if (operation != 'noBorders' &&
226
+ borderUpdates_2.length > 0 &&
227
+ hasMatchingBorders(borderUpdates_2, borderFormat)) {
228
+ borderFormat = '';
229
+ }
230
+ try {
231
+ for (var borderUpdates_1 = (0, tslib_1.__values)(borderUpdates_2), borderUpdates_1_1 = borderUpdates_1.next(); !borderUpdates_1_1.done; borderUpdates_1_1 = borderUpdates_1.next()) {
232
+ var _c = borderUpdates_1_1.value, cell = _c.cell, positions = _c.positions;
233
+ applyBorderFormat(cell, borderFormat, positions);
234
+ }
235
+ }
236
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
237
+ finally {
238
+ try {
239
+ if (borderUpdates_1_1 && !borderUpdates_1_1.done && (_a = borderUpdates_1.return)) _a.call(borderUpdates_1);
240
+ }
241
+ finally { if (e_1) throw e_1.error; }
242
+ }
223
243
  //Format perimeter if necessary or possible
224
244
  modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
225
245
  }
@@ -238,6 +258,64 @@ function applyTableBorderFormat(editor, border, operation) {
238
258
  });
239
259
  }
240
260
  exports.applyTableBorderFormat = applyTableBorderFormat;
261
+ /**
262
+ * Check targeted borders without repeatedly parsing identical CSS values.
263
+ * @param borderUpdates The borders to compare
264
+ * @param borderFormat The requested border format
265
+ */
266
+ function hasMatchingBorders(borderUpdates, borderFormat) {
267
+ var e_2, _a, e_3, _b;
268
+ var matchingBorders = new Set();
269
+ try {
270
+ for (var borderUpdates_3 = (0, tslib_1.__values)(borderUpdates), borderUpdates_3_1 = borderUpdates_3.next(); !borderUpdates_3_1.done; borderUpdates_3_1 = borderUpdates_3.next()) {
271
+ var _c = borderUpdates_3_1.value, cell = _c.cell, positions = _c.positions;
272
+ try {
273
+ for (var positions_1 = (e_3 = void 0, (0, tslib_1.__values)(positions)), positions_1_1 = positions_1.next(); !positions_1_1.done; positions_1_1 = positions_1.next()) {
274
+ var pos = positions_1_1.value;
275
+ var value = cell.format[pos] || '';
276
+ // Exact matches need no CSS parsing. Equivalent values are parsed only once.
277
+ if (value == borderFormat || matchingBorders.has(value)) {
278
+ continue;
279
+ }
280
+ if (!areSameBorders(value, borderFormat)) {
281
+ return false;
282
+ }
283
+ matchingBorders.add(value);
284
+ }
285
+ }
286
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
287
+ finally {
288
+ try {
289
+ if (positions_1_1 && !positions_1_1.done && (_b = positions_1.return)) _b.call(positions_1);
290
+ }
291
+ finally { if (e_3) throw e_3.error; }
292
+ }
293
+ }
294
+ }
295
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
296
+ finally {
297
+ try {
298
+ if (borderUpdates_3_1 && !borderUpdates_3_1.done && (_a = borderUpdates_3.return)) _a.call(borderUpdates_3);
299
+ }
300
+ finally { if (e_2) throw e_2.error; }
301
+ }
302
+ return true;
303
+ }
304
+ /**
305
+ * Compare border components, parsing colors to account for equivalent hex and RGB values.
306
+ */
307
+ function areSameBorders(border1, border2) {
308
+ var values1 = (0, roosterjs_content_model_dom_1.extractBorderValues)(border1);
309
+ var values2 = (0, roosterjs_content_model_dom_1.extractBorderValues)(border2);
310
+ var color1 = values1.color || '';
311
+ var color2 = values2.color || '';
312
+ var rgb1 = (0, roosterjs_content_model_dom_1.parseColor)(color1);
313
+ var rgb2 = (0, roosterjs_content_model_dom_1.parseColor)(color2);
314
+ return (values1.width == values2.width &&
315
+ values1.style == values2.style &&
316
+ (color1 == color2 ||
317
+ (!!rgb1 && !!rgb2 && rgb1[0] == rgb2[0] && rgb1[1] == rgb2[1] && rgb1[2] == rgb2[2])));
318
+ }
241
319
  /**
242
320
  * @internal
243
321
  * 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,2EASqC;AA4BrC;;;;;GAKG;AACH,SAAgB,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA,oBAAe,IAAA,mDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;QAElD,IAAI,UAAU,EAAE;YACZ,IAAM,GAAG,GAA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AAC,CAAC,CAAC;SACxD;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,2EAUqC;AAqCrC;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;;QACK,IAAA,KAAA,oBAAe,IAAA,mDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;QAElD,IAAI,UAAU,EAAE;YACZ,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,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,IAAA,iDAAmB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC9D,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAE1C,IAAI,KAAK,EAAE;gBACP,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CAAC;YAC9D,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SACxD;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 parseColor,\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 * 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"]}