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,4 +1,4 @@
1
- define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"], function (require, exports, canMergeCells_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.mergeTableCells = void 0;
@@ -8,7 +8,16 @@ define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"],
8
8
  function mergeTableCells(table) {
9
9
  var sel = (0, roosterjs_content_model_dom_1.getSelectedCells)(table);
10
10
  if (sel &&
11
- (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);
12
21
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
13
22
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
14
23
  var cell = table.rows[rowIndex].cells[colIndex];
@@ -22,5 +31,31 @@ define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"],
22
31
  }
23
32
  }
24
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
+ }
25
60
  });
26
61
  //# 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":";;;;IAIA;;OAEG;IACH,SAAgB,eAAe,CAAC,KAAsC;QAClE,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;QAEpC,IACI,GAAG;YACH,IAAA,6BAAa,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,EACvF;YACE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;oBACzE,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAElD,IAAI,IAAI,EAAE;wBACN,IAAM,WAAW,GAAG,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC;wBAEtC,WAAW,CAAC,QAAQ,GAAG,QAAQ,GAAG,GAAG,CAAC,WAAW,CAAC;wBAClD,WAAW,CAAC,SAAS,GAAG,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;qBACnD;iBACJ;aACJ;SACJ;IACL,CAAC;IApBD,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.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableCells.ts"],"names":[],"mappings":";;;;IAOA;;OAEG;IACH,SAAgB,eAAe,CAAC,KAAsC;QAClE,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;QAEpC,IACI,GAAG;YACH,IAAA,2CAAa,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,EACvF;YACE,IAAM,SAAS,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;YAC/E,IAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;YAC7E,IAAM,WAAW,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;YACjF,IAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC;YAClF,IAAM,UAAU,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC;YAEhF,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;YACpD,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;YACxD,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;YAC1D,SAAS,CAAC,SAAS,CA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tC,WAAmB,EACnB,GAA0C,EAC1C,SAAoB;QAEpB,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAE7E,OAAO,MAAM;YACT,KAAK,CAAC,IAAI;iBACL,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;iBACpC,KAAK,CAAC,UAAA,GAAG,IAAI,OAAA,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,EAAlD,CAAkD,CAAC;YACrE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,SAAS,CAAC;IACpB,CAAC;IAED,SAAS,SAAS,CACd,MAAmC,EACnC,SAAoB,EACpB,MAA0B;QAE1B,IAAI,MAAM,EAAE;YACR,MAAM,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;SAC9B;aAAM;YACH,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;SAC5B;IACL,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,4 +1,4 @@
1
- define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"], function (require, exports, canMergeCells_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.mergeTableColumn = void 0;
@@ -15,7 +15,7 @@ define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"],
15
15
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
16
16
  var cell = (_a = table.rows[rowIndex]) === null || _a === void 0 ? void 0 : _a.cells[mergingColIndex];
17
17
  if (cell &&
18
- (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)) {
19
19
  (0, roosterjs_content_model_dom_1.mutateBlock)(cell).spanLeft = true;
20
20
  var newSelectedCol = mergingColIndex;
21
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":";;;;IAOA;;OAEG;IACH,SAAgB,gBAAgB,CAC5B,KAAsC,EACtC,SAAwC;;QAExC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,SAAS,GAAG,SAAS,IAAI,WAAW,CAAC;QAE3C,IAAI,GAAG,EAAE;YACL,IAAM,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC;YAEzE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;gBACrE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;oBACnE,IAAM,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,eAAe,CAAC,CAAC;oBAE1D,IACI,IAAI;wBACJ,IAAA,6BAAa,EACT,KAAK,CAAC,IAAI,EACV,QAAQ,EACR,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,CAClB,EACH;wBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;wBAElC,IAAI,cAAc,GAAG,eAAe,CAAC;wBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,0CAAE,QAAQ,EAAE;4BAC1D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;4BACxD,cAAc,EAAE,CAAC;yBACpB;wBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,CAAC;wBAC5D,IAAI,OAAO,EAAE;4BACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;yBAC1C;qBACJ;iBACJ;aACJ;SACJ;IACL,CAAC;IAzCD,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":";;;;IAMA;;OAEG;IACH,SAAgB,gBAAgB,CAC5B,KAAsC,EACtC,SAAwC;;QAExC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,SAAS,GAAG,SAAS,IAAI,WAAW,CAAC;QAE3C,IAAI,GAAG,EAAE;YACL,IAAM,eAAe,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC;YAEzE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;gBACrE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;oBACnE,IAAM,IAAI,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,eAAe,CAAC,CAAC;oBAE1D,IACI,IAAI;wBACJ,IAAA,2CAAa,EACT,KAAK,CAAC,IAAI,EACV,QAAQ,EACR,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,CAClB,EACH;wBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC;wBAElC,IAAI,cAAc,GAAG,eAAe,CAAC;wBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,0CAAE,QAAQ,EAAE;4BAC1D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;4BACxD,cAAc,EAAE,CAAC;yBACpB;wBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,CAAC;wBAC5D,IAAI,OAAO,EAAE;4BACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;yBAC1C;qBACJ;iBACJ;aACJ;SACJ;IACL,CAAC;IAzCD,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,4 +1,4 @@
1
- define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"], function (require, exports, canMergeCells_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.mergeTableRow = void 0;
@@ -15,7 +15,7 @@ define(["require", "exports", "./canMergeCells", "roosterjs-content-model-dom"],
15
15
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
16
16
  var cell = table.rows[mergingRowIndex].cells[colIndex];
17
17
  if (cell &&
18
- (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)) {
19
19
  (0, roosterjs_content_model_dom_1.mutateBlock)(cell).spanAbove = true;
20
20
  var newSelectedRow = mergingRowIndex;
21
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":";;;;IAOA;;OAEG;IACH,SAAgB,aAAa,CACzB,KAAsC,EACtC,SAAsC;;QAEtC,IAAM,GAAG,GAAG,IAAA,8CAAgB,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;SACJ;IACL,CAAC;IA1CD,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":";;;;IAMA;;OAEG;IACH,SAAgB,aAAa,CACzB,KAAsC,EACtC,SAAsC;;QAEtC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;QACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;QAE7C,IAAI,GAAG,EAAE;YACL,IAAM,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;YAEpE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC5D,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;oBACzE,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAEzD,IACI,IAAI;wBACJ,IAAA,2CAAa,EACT,KAAK,CAAC,IAAI,EACV,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,EACf,QAAQ,CACX,EACH;wBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;wBAEnC,IAAI,cAAc,GAAG,eAAe,CAAC;wBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,0CAAE,SAAS,EAAE;4BAC3D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;4BACxD,cAAc,EAAE,CAAC;yBACpB;wBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;wBAE5D,IAAI,OAAO,EAAE;4BACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;yBAC1C;qBACJ;iBACJ;aACJ;SACJ;IACL,CAAC;IA1CD,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
@@ -4,13 +4,15 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
4
4
  exports.applyTableBorderFormat = void 0;
5
5
  /**
6
6
  * Operations to apply border
7
+ * Remove the targeted borders instead if they all already match the requested format.
7
8
  * @param editor The editor instance
8
9
  * @param border The border to apply
9
10
  * @param operation The operation to apply
10
11
  */
11
12
  function applyTableBorderFormat(editor, border, operation) {
12
13
  editor.formatContentModel(function (model) {
13
- var _a = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getFirstSelectedTable)(model), 1), tableModel = _a[0];
14
+ var e_1, _a;
15
+ var _b = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getFirstSelectedTable)(model), 1), tableModel = _b[0];
14
16
  if (tableModel) {
15
17
  var sel = (0, roosterjs_content_model_dom_1.getSelectedCells)(tableModel);
16
18
  var perimeter = {
@@ -54,6 +56,10 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
54
56
  // undefined is treated as Left to Right
55
57
  var isRtl = tableModel.format.direction == 'rtl';
56
58
  if (sel) {
59
+ var borderUpdates_2 = [];
60
+ var collectBorderFormat = function (cell, positions) {
61
+ borderUpdates_2.push({ cell: cell, positions: positions });
62
+ };
57
63
  var operations = [operation];
58
64
  while (operations.length) {
59
65
  switch (operations.pop()) {
@@ -73,7 +79,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
73
79
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
74
80
  var cell = tableModel.rows[rowIndex].cells[colIndex];
75
81
  // Format cells - All borders
76
- applyBorderFormat(cell, borderFormat, allBorders);
82
+ collectBorderFormat(cell, allBorders);
77
83
  }
78
84
  }
79
85
  // Format perimeter
@@ -87,7 +93,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
87
93
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
88
94
  var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
89
95
  // Format cells - Left border
90
- applyBorderFormat(cell, borderFormat, leftBorder);
96
+ collectBorderFormat(cell, leftBorder);
91
97
  }
92
98
  // Format perimeter
93
99
  isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
@@ -97,7 +103,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
97
103
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
98
104
  var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
99
105
  // Format cells - Right border
100
- applyBorderFormat(cell, borderFormat, rightBorder);
106
+ collectBorderFormat(cell, rightBorder);
101
107
  }
102
108
  // Format perimeter
103
109
  isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
@@ -107,7 +113,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
107
113
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
108
114
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
109
115
  // Format cells - Top border
110
- applyBorderFormat(cell, borderFormat, topBorder);
116
+ collectBorderFormat(cell, topBorder);
111
117
  }
112
118
  // Format perimeter
113
119
  perimeter.Top = true;
@@ -117,7 +123,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
117
123
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
118
124
  var cell = tableModel.rows[sel.lastRow].cells[colIndex];
119
125
  // Format cells - Bottom border
120
- applyBorderFormat(cell, borderFormat, bottomBorder);
126
+ collectBorderFormat(cell, bottomBorder);
121
127
  }
122
128
  // Format perimeter
123
129
  perimeter.Bottom = true;
@@ -132,43 +138,37 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
132
138
  }
133
139
  // Single column selection
134
140
  if (singleCol) {
135
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom']);
141
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], ['borderBottom']);
136
142
  for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
137
143
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
138
- applyBorderFormat(cell, borderFormat, [
139
- 'borderTop',
140
- 'borderBottom',
141
- ]);
144
+ collectBorderFormat(cell, ['borderTop', 'borderBottom']);
142
145
  }
143
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop']);
146
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], ['borderTop']);
144
147
  break;
145
148
  }
146
149
  // Single row selection
147
150
  if (singleRow) {
148
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
151
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderRight']);
149
152
  for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
150
153
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
151
- applyBorderFormat(cell, borderFormat, [
152
- 'borderLeft',
153
- 'borderRight',
154
- ]);
154
+ collectBorderFormat(cell, ['borderLeft', 'borderRight']);
155
155
  }
156
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderLeft']);
156
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderLeft']);
157
157
  break;
158
158
  }
159
159
  // For multiple rows and columns selections
160
160
  // Top left cell
161
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
161
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderBottom', 'borderRight']);
162
162
  // Top right cell
163
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
163
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderBottom', 'borderLeft']);
164
164
  // Bottom left cell
165
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
165
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderTop', 'borderRight']);
166
166
  // Bottom right cell
167
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
167
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderTop', 'borderLeft']);
168
168
  // First row
169
169
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
170
170
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
171
- applyBorderFormat(cell, borderFormat, [
171
+ collectBorderFormat(cell, [
172
172
  'borderBottom',
173
173
  'borderLeft',
174
174
  'borderRight',
@@ -177,7 +177,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
177
177
  // Last row
178
178
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
179
179
  var cell = tableModel.rows[sel.lastRow].cells[colIndex];
180
- applyBorderFormat(cell, borderFormat, [
180
+ collectBorderFormat(cell, [
181
181
  'borderTop',
182
182
  'borderLeft',
183
183
  'borderRight',
@@ -186,7 +186,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
186
186
  // First column
187
187
  for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
188
188
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
189
- applyBorderFormat(cell, borderFormat, [
189
+ collectBorderFormat(cell, [
190
190
  'borderTop',
191
191
  'borderBottom',
192
192
  isRtl ? 'borderLeft' : 'borderRight',
@@ -195,7 +195,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
195
195
  // Last column
196
196
  for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
197
197
  var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
198
- applyBorderFormat(cell, borderFormat, [
198
+ collectBorderFormat(cell, [
199
199
  'borderTop',
200
200
  'borderBottom',
201
201
  isRtl ? 'borderRight' : 'borderLeft',
@@ -219,6 +219,26 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
219
219
  break;
220
220
  }
221
221
  }
222
+ // Compare before changing any cells, and only consider borders targeted by
223
+ // this operation. Normalize CSS so DOM colors (rgb) also match hex input.
224
+ if (operation != 'noBorders' &&
225
+ borderUpdates_2.length > 0 &&
226
+ hasMatchingBorders(borderUpdates_2, borderFormat)) {
227
+ borderFormat = '';
228
+ }
229
+ try {
230
+ 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()) {
231
+ var _c = borderUpdates_1_1.value, cell = _c.cell, positions = _c.positions;
232
+ applyBorderFormat(cell, borderFormat, positions);
233
+ }
234
+ }
235
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
236
+ finally {
237
+ try {
238
+ if (borderUpdates_1_1 && !borderUpdates_1_1.done && (_a = borderUpdates_1.return)) _a.call(borderUpdates_1);
239
+ }
240
+ finally { if (e_1) throw e_1.error; }
241
+ }
222
242
  //Format perimeter if necessary or possible
223
243
  modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
224
244
  }
@@ -237,6 +257,64 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
237
257
  });
238
258
  }
239
259
  exports.applyTableBorderFormat = applyTableBorderFormat;
260
+ /**
261
+ * Check targeted borders without repeatedly parsing identical CSS values.
262
+ * @param borderUpdates The borders to compare
263
+ * @param borderFormat The requested border format
264
+ */
265
+ function hasMatchingBorders(borderUpdates, borderFormat) {
266
+ var e_2, _a, e_3, _b;
267
+ var matchingBorders = new Set();
268
+ try {
269
+ 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()) {
270
+ var _c = borderUpdates_3_1.value, cell = _c.cell, positions = _c.positions;
271
+ try {
272
+ 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()) {
273
+ var pos = positions_1_1.value;
274
+ var value = cell.format[pos] || '';
275
+ // Exact matches need no CSS parsing. Equivalent values are parsed only once.
276
+ if (value == borderFormat || matchingBorders.has(value)) {
277
+ continue;
278
+ }
279
+ if (!areSameBorders(value, borderFormat)) {
280
+ return false;
281
+ }
282
+ matchingBorders.add(value);
283
+ }
284
+ }
285
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
286
+ finally {
287
+ try {
288
+ if (positions_1_1 && !positions_1_1.done && (_b = positions_1.return)) _b.call(positions_1);
289
+ }
290
+ finally { if (e_3) throw e_3.error; }
291
+ }
292
+ }
293
+ }
294
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
295
+ finally {
296
+ try {
297
+ if (borderUpdates_3_1 && !borderUpdates_3_1.done && (_a = borderUpdates_3.return)) _a.call(borderUpdates_3);
298
+ }
299
+ finally { if (e_2) throw e_2.error; }
300
+ }
301
+ return true;
302
+ }
303
+ /**
304
+ * Compare border components, parsing colors to account for equivalent hex and RGB values.
305
+ */
306
+ function areSameBorders(border1, border2) {
307
+ var values1 = (0, roosterjs_content_model_dom_1.extractBorderValues)(border1);
308
+ var values2 = (0, roosterjs_content_model_dom_1.extractBorderValues)(border2);
309
+ var color1 = values1.color || '';
310
+ var color2 = values2.color || '';
311
+ var rgb1 = (0, roosterjs_content_model_dom_1.parseColor)(color1);
312
+ var rgb2 = (0, roosterjs_content_model_dom_1.parseColor)(color2);
313
+ return (values1.width == values2.width &&
314
+ values1.style == values2.style &&
315
+ (color1 == color2 ||
316
+ (!!rgb1 && !!rgb2 && rgb1[0] == rgb2[0] && rgb1[1] == rgb2[1] && rgb1[2] == rgb2[2])));
317
+ }
240
318
  /**
241
319
  * @internal
242
320
  * 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":";;;;IAqCA;;;;;OAKG;IACH,SA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C,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;aACjF;SACJ;IACL,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":";;;;IA+CA;;;;;;OAMG;IACH,SAAgB,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;QAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;;YACK,IAAA,KAAA,oBAAe,IAAA,mDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;YAElD,IAAI,UAAU,EAAE;gBACZ,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,UAAU,CAAC,CAAC;gBACzC,IAAM,SAAS,GAAc;oBACzB,GAAG,EAAE,KAAK;oBACV,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,KAAK;iBACf,CAAC;gBAEF,mDAAmD;gBACnD,IAAI,YAAY,GAAG,EAAE,CAAC;gBACtB,IAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;gBACzB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,KAAK,GAAK,MA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U,GAAG,CAAC,CAAC,CAAC;gBACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;aACjF;SACJ;IACL,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"]}