roosterjs-content-model-api 9.59.0 → 9.61.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 (52) 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/link/insertLink.js +1 -2
  8. package/lib/publicApi/link/insertLink.js.map +1 -1
  9. package/lib/publicApi/table/applyTableBorderFormat.d.ts +1 -0
  10. package/lib/publicApi/table/applyTableBorderFormat.js +104 -26
  11. package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
  12. package/lib-amd/modelApi/table/mergeTableCells.js +37 -2
  13. package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
  14. package/lib-amd/modelApi/table/mergeTableColumn.js +2 -2
  15. package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
  16. package/lib-amd/modelApi/table/mergeTableRow.js +2 -2
  17. package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
  18. package/lib-amd/publicApi/link/insertLink.js +2 -2
  19. package/lib-amd/publicApi/link/insertLink.js.map +1 -1
  20. package/lib-amd/publicApi/table/applyTableBorderFormat.d.ts +1 -0
  21. package/lib-amd/publicApi/table/applyTableBorderFormat.js +104 -26
  22. package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
  23. package/lib-mjs/modelApi/table/mergeTableCells.js +36 -2
  24. package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
  25. package/lib-mjs/modelApi/table/mergeTableColumn.js +1 -2
  26. package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
  27. package/lib-mjs/modelApi/table/mergeTableRow.js +1 -2
  28. package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
  29. package/lib-mjs/publicApi/link/insertLink.js +2 -3
  30. package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
  31. package/lib-mjs/publicApi/table/applyTableBorderFormat.d.ts +1 -0
  32. package/lib-mjs/publicApi/table/applyTableBorderFormat.js +106 -28
  33. package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
  34. package/package.json +3 -3
  35. package/lib/modelApi/table/canMergeCells.d.ts +0 -5
  36. package/lib/modelApi/table/canMergeCells.js +0 -57
  37. package/lib/modelApi/table/canMergeCells.js.map +0 -1
  38. package/lib/publicApi/utils/checkXss.d.ts +0 -8
  39. package/lib/publicApi/utils/checkXss.js +0 -15
  40. package/lib/publicApi/utils/checkXss.js.map +0 -1
  41. package/lib-amd/modelApi/table/canMergeCells.d.ts +0 -5
  42. package/lib-amd/modelApi/table/canMergeCells.js +0 -59
  43. package/lib-amd/modelApi/table/canMergeCells.js.map +0 -1
  44. package/lib-amd/publicApi/utils/checkXss.d.ts +0 -8
  45. package/lib-amd/publicApi/utils/checkXss.js +0 -17
  46. package/lib-amd/publicApi/utils/checkXss.js.map +0 -1
  47. package/lib-mjs/modelApi/table/canMergeCells.d.ts +0 -5
  48. package/lib-mjs/modelApi/table/canMergeCells.js +0 -53
  49. package/lib-mjs/modelApi/table/canMergeCells.js.map +0 -1
  50. package/lib-mjs/publicApi/utils/checkXss.d.ts +0 -8
  51. package/lib-mjs/publicApi/utils/checkXss.js +0 -11
  52. package/lib-mjs/publicApi/utils/checkXss.js.map +0 -1
@@ -1,6 +1,7 @@
1
1
  import type { IEditor, Border, BorderOperations } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Operations to apply border
4
+ * Remove the targeted borders instead if they all already match the requested format.
4
5
  * @param editor The editor instance
5
6
  * @param border The border to apply
6
7
  * @param operation The operation to apply
@@ -1,14 +1,16 @@
1
- import { __read } from "tslib";
2
- import { extractBorderValues, getFirstSelectedTable, getSelectedCells, mutateBlock, getTableMetadata, parseValueWithUnit, setFirstColumnFormatBorders, updateTableCellMetadata, } from 'roosterjs-content-model-dom';
1
+ import { __read, __values } from "tslib";
2
+ import { extractBorderValues, getFirstSelectedTable, getSelectedCells, mutateBlock, getTableMetadata, parseValueWithUnit, parseColor, setFirstColumnFormatBorders, updateTableCellMetadata, } from 'roosterjs-content-model-dom';
3
3
  /**
4
4
  * Operations to apply border
5
+ * Remove the targeted borders instead if they all already match the requested format.
5
6
  * @param editor The editor instance
6
7
  * @param border The border to apply
7
8
  * @param operation The operation to apply
8
9
  */
9
10
  export function applyTableBorderFormat(editor, border, operation) {
10
11
  editor.formatContentModel(function (model) {
11
- var _a = __read(getFirstSelectedTable(model), 1), tableModel = _a[0];
12
+ var e_1, _a;
13
+ var _b = __read(getFirstSelectedTable(model), 1), tableModel = _b[0];
12
14
  if (tableModel) {
13
15
  var sel = getSelectedCells(tableModel);
14
16
  var perimeter = {
@@ -52,6 +54,10 @@ export function applyTableBorderFormat(editor, border, operation) {
52
54
  // undefined is treated as Left to Right
53
55
  var isRtl = tableModel.format.direction == 'rtl';
54
56
  if (sel) {
57
+ var borderUpdates_2 = [];
58
+ var collectBorderFormat = function (cell, positions) {
59
+ borderUpdates_2.push({ cell: cell, positions: positions });
60
+ };
55
61
  var operations = [operation];
56
62
  while (operations.length) {
57
63
  switch (operations.pop()) {
@@ -71,7 +77,7 @@ export function applyTableBorderFormat(editor, border, operation) {
71
77
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
72
78
  var cell = tableModel.rows[rowIndex].cells[colIndex];
73
79
  // Format cells - All borders
74
- applyBorderFormat(cell, borderFormat, allBorders);
80
+ collectBorderFormat(cell, allBorders);
75
81
  }
76
82
  }
77
83
  // Format perimeter
@@ -85,7 +91,7 @@ export function applyTableBorderFormat(editor, border, operation) {
85
91
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
86
92
  var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
87
93
  // Format cells - Left border
88
- applyBorderFormat(cell, borderFormat, leftBorder);
94
+ collectBorderFormat(cell, leftBorder);
89
95
  }
90
96
  // Format perimeter
91
97
  isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
@@ -95,7 +101,7 @@ export function applyTableBorderFormat(editor, border, operation) {
95
101
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
96
102
  var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
97
103
  // Format cells - Right border
98
- applyBorderFormat(cell, borderFormat, rightBorder);
104
+ collectBorderFormat(cell, rightBorder);
99
105
  }
100
106
  // Format perimeter
101
107
  isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
@@ -105,7 +111,7 @@ export function applyTableBorderFormat(editor, border, operation) {
105
111
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
106
112
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
107
113
  // Format cells - Top border
108
- applyBorderFormat(cell, borderFormat, topBorder);
114
+ collectBorderFormat(cell, topBorder);
109
115
  }
110
116
  // Format perimeter
111
117
  perimeter.Top = true;
@@ -115,7 +121,7 @@ export function applyTableBorderFormat(editor, border, operation) {
115
121
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
116
122
  var cell = tableModel.rows[sel.lastRow].cells[colIndex];
117
123
  // Format cells - Bottom border
118
- applyBorderFormat(cell, borderFormat, bottomBorder);
124
+ collectBorderFormat(cell, bottomBorder);
119
125
  }
120
126
  // Format perimeter
121
127
  perimeter.Bottom = true;
@@ -130,43 +136,37 @@ export function applyTableBorderFormat(editor, border, operation) {
130
136
  }
131
137
  // Single column selection
132
138
  if (singleCol) {
133
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom']);
139
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], ['borderBottom']);
134
140
  for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
135
141
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
136
- applyBorderFormat(cell, borderFormat, [
137
- 'borderTop',
138
- 'borderBottom',
139
- ]);
142
+ collectBorderFormat(cell, ['borderTop', 'borderBottom']);
140
143
  }
141
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop']);
144
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], ['borderTop']);
142
145
  break;
143
146
  }
144
147
  // Single row selection
145
148
  if (singleRow) {
146
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
149
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderRight']);
147
150
  for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
148
151
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
149
- applyBorderFormat(cell, borderFormat, [
150
- 'borderLeft',
151
- 'borderRight',
152
- ]);
152
+ collectBorderFormat(cell, ['borderLeft', 'borderRight']);
153
153
  }
154
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderLeft']);
154
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderLeft']);
155
155
  break;
156
156
  }
157
157
  // For multiple rows and columns selections
158
158
  // Top left cell
159
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
159
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderBottom', 'borderRight']);
160
160
  // Top right cell
161
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
161
+ collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderBottom', 'borderLeft']);
162
162
  // Bottom left cell
163
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
163
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderTop', 'borderRight']);
164
164
  // Bottom right cell
165
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
165
+ collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderTop', 'borderLeft']);
166
166
  // First row
167
167
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
168
168
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
169
- applyBorderFormat(cell, borderFormat, [
169
+ collectBorderFormat(cell, [
170
170
  'borderBottom',
171
171
  'borderLeft',
172
172
  'borderRight',
@@ -175,7 +175,7 @@ export function applyTableBorderFormat(editor, border, operation) {
175
175
  // Last row
176
176
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
177
177
  var cell = tableModel.rows[sel.lastRow].cells[colIndex];
178
- applyBorderFormat(cell, borderFormat, [
178
+ collectBorderFormat(cell, [
179
179
  'borderTop',
180
180
  'borderLeft',
181
181
  'borderRight',
@@ -184,7 +184,7 @@ export function applyTableBorderFormat(editor, border, operation) {
184
184
  // First column
185
185
  for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
186
186
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
187
- applyBorderFormat(cell, borderFormat, [
187
+ collectBorderFormat(cell, [
188
188
  'borderTop',
189
189
  'borderBottom',
190
190
  isRtl ? 'borderLeft' : 'borderRight',
@@ -193,7 +193,7 @@ export function applyTableBorderFormat(editor, border, operation) {
193
193
  // Last column
194
194
  for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
195
195
  var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
196
- applyBorderFormat(cell, borderFormat, [
196
+ collectBorderFormat(cell, [
197
197
  'borderTop',
198
198
  'borderBottom',
199
199
  isRtl ? 'borderRight' : 'borderLeft',
@@ -217,6 +217,26 @@ export function applyTableBorderFormat(editor, border, operation) {
217
217
  break;
218
218
  }
219
219
  }
220
+ // Compare before changing any cells, and only consider borders targeted by
221
+ // this operation. Normalize CSS so DOM colors (rgb) also match hex input.
222
+ if (operation != 'noBorders' &&
223
+ borderUpdates_2.length > 0 &&
224
+ hasMatchingBorders(borderUpdates_2, borderFormat)) {
225
+ borderFormat = '';
226
+ }
227
+ try {
228
+ for (var borderUpdates_1 = __values(borderUpdates_2), borderUpdates_1_1 = borderUpdates_1.next(); !borderUpdates_1_1.done; borderUpdates_1_1 = borderUpdates_1.next()) {
229
+ var _c = borderUpdates_1_1.value, cell = _c.cell, positions = _c.positions;
230
+ applyBorderFormat(cell, borderFormat, positions);
231
+ }
232
+ }
233
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
234
+ finally {
235
+ try {
236
+ if (borderUpdates_1_1 && !borderUpdates_1_1.done && (_a = borderUpdates_1.return)) _a.call(borderUpdates_1);
237
+ }
238
+ finally { if (e_1) throw e_1.error; }
239
+ }
220
240
  //Format perimeter if necessary or possible
221
241
  modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
222
242
  }
@@ -234,6 +254,64 @@ export function applyTableBorderFormat(editor, border, operation) {
234
254
  apiName: 'tableBorder',
235
255
  });
236
256
  }
257
+ /**
258
+ * Check targeted borders without repeatedly parsing identical CSS values.
259
+ * @param borderUpdates The borders to compare
260
+ * @param borderFormat The requested border format
261
+ */
262
+ function hasMatchingBorders(borderUpdates, borderFormat) {
263
+ var e_2, _a, e_3, _b;
264
+ var matchingBorders = new Set();
265
+ try {
266
+ for (var borderUpdates_3 = __values(borderUpdates), borderUpdates_3_1 = borderUpdates_3.next(); !borderUpdates_3_1.done; borderUpdates_3_1 = borderUpdates_3.next()) {
267
+ var _c = borderUpdates_3_1.value, cell = _c.cell, positions = _c.positions;
268
+ try {
269
+ for (var positions_1 = (e_3 = void 0, __values(positions)), positions_1_1 = positions_1.next(); !positions_1_1.done; positions_1_1 = positions_1.next()) {
270
+ var pos = positions_1_1.value;
271
+ var value = cell.format[pos] || '';
272
+ // Exact matches need no CSS parsing. Equivalent values are parsed only once.
273
+ if (value == borderFormat || matchingBorders.has(value)) {
274
+ continue;
275
+ }
276
+ if (!areSameBorders(value, borderFormat)) {
277
+ return false;
278
+ }
279
+ matchingBorders.add(value);
280
+ }
281
+ }
282
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
283
+ finally {
284
+ try {
285
+ if (positions_1_1 && !positions_1_1.done && (_b = positions_1.return)) _b.call(positions_1);
286
+ }
287
+ finally { if (e_3) throw e_3.error; }
288
+ }
289
+ }
290
+ }
291
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
292
+ finally {
293
+ try {
294
+ if (borderUpdates_3_1 && !borderUpdates_3_1.done && (_a = borderUpdates_3.return)) _a.call(borderUpdates_3);
295
+ }
296
+ finally { if (e_2) throw e_2.error; }
297
+ }
298
+ return true;
299
+ }
300
+ /**
301
+ * Compare border components, parsing colors to account for equivalent hex and RGB values.
302
+ */
303
+ function areSameBorders(border1, border2) {
304
+ var values1 = extractBorderValues(border1);
305
+ var values2 = extractBorderValues(border2);
306
+ var color1 = values1.color || '';
307
+ var color2 = values2.color || '';
308
+ var rgb1 = parseColor(color1);
309
+ var rgb2 = parseColor(color2);
310
+ return (values1.width == values2.width &&
311
+ values1.style == values2.style &&
312
+ (color1 == color2 ||
313
+ (!!rgb1 && !!rgb2 && rgb1[0] == rgb2[0] && rgb1[1] == rgb2[1] && rgb1[2] == rgb2[2])));
314
+ }
237
315
  /**
238
316
  * @internal
239
317
  * Apply border format to a cell
@@ -1 +1 @@
1
- {"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,2BAA2B,EAC3B,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AA4BrC;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA,OAAe,qBAAqB,CAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;QAElD,IAAI,UAAU,EAAE;YACZ,IAAM,GAAG,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;YACzC,IAAM,SAAS,GAAc;gBACzB,GAAG,EAAE,KAAK;gBACV,MAAM,EAAE,KAAK;gBACb,IAAI,EAAE,KAAK;gBACX,KAAK,EAAE,KAAK;aACf,CAAC;YAEF,mDAAmD;YACnD,IAAI,YAAY,GAAG,EAAE,CAAC;YACtB,IAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;YACzB,IAAA,KAAK,GAAmB,MAAM,MAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,KAAK,GAAK,MAAM,MAAX,CAAY;YACvC,IAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC9D,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAC1C,IAAM,WAAW,GAAG,eAAe,CAAC,KAAK,CAAC;YAE1C,IAAI,KAAK,EAAE;gBACP,YAAY,GAAG,kBAAkB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QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;SACjF;KACJ;AACL,CAAC","sourcesContent":["import {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n mutateBlock,\n getTableMetadata,\n parseValueWithUnit,\n setFirstColumnFormatBorders,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n IEditor,\n Border,\n BorderOperations,\n TableSelectionCoordinates,\n ReadonlyContentModelTableCell,\n ReadonlyContentModelTable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Border positions\n */\ntype BorderPositions = 'borderTop' | 'borderBottom' | 'borderLeft' | 'borderRight';\n\n/**\n * @internal\n * Perimeter of the table selection\n * Used to determine where to apply border to the cells adjacent to the selection.\n */\ntype Perimeter = {\n Top: boolean;\n Bottom: boolean;\n Left: boolean;\n Right: boolean;\n};\n\n/**\n * Operations to apply border\n * @param editor The editor instance\n * @param border The border to apply\n * @param operation The operation to apply\n */\nexport function applyTableBorderFormat(\n editor: IEditor,\n border: Border,\n operation: BorderOperations\n) {\n editor.formatContentModel(\n model => {\n const [tableModel] = getFirstSelectedTable(model);\n\n if (tableModel) {\n const sel = getSelectedCells(tableModel);\n const perimeter: Perimeter = {\n Top: false,\n Bottom: false,\n Left: false,\n Right: false,\n };\n\n // Create border format with table format as backup\n let borderFormat = '';\n const format = tableModel.format;\n const { width, style, color } = border;\n const extractedBorder = extractBorderValues(format.borderTop);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n\n if (width) {\n borderFormat = parseValueWithUnit(width) + 'px';\n } else if (borderWidth) {\n borderFormat = borderWidth;\n } else {\n borderFormat = '1px';\n }\n\n if (style) {\n borderFormat = `${borderFormat} ${style}`;\n } else if (borderStyle) {\n borderFormat = `${borderFormat} ${borderStyle}`;\n } else {\n borderFormat = `${borderFormat} solid`;\n }\n\n if (color) {\n borderFormat = `${borderFormat} ${color}`;\n } else if (borderColor) {\n borderFormat = `${borderFormat} ${borderColor}`;\n }\n\n // undefined is treated as Left to Right\n const isRtl = tableModel.format.direction == 'rtl';\n\n if (sel) {\n const operations: BorderOperations[] = [operation];\n while (operations.length) {\n switch (operations.pop()) {\n case 'noBorders':\n // Do All borders but with empty border format\n borderFormat = '';\n operations.push('allBorders');\n break;\n case 'allBorders':\n const allBorders: BorderPositions[] = [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[colIndex];\n // Format cells - All borders\n applyBorderFormat(cell, borderFormat, allBorders);\n }\n }\n\n // Format perimeter\n perimeter.Top = true;\n perimeter.Bottom = true;\n perimeter.Left = true;\n perimeter.Right = true;\n break;\n case 'leftBorders':\n const leftBorder: BorderPositions[] = ['borderLeft'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Right = true) : (perimeter.Left = true);\n break;\n case 'rightBorders':\n const rightBorder: BorderPositions[] = ['borderRight'];\n for (\n let rowIndex = sel.firstRow;\n rowIndex <= sel.lastRow;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n isRtl ? (perimeter.Left = true) : (perimeter.Right = true);\n break;\n case 'topBorders':\n const topBorder: BorderPositions[] = ['borderTop'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n // Format cells - Top border\n applyBorderFormat(cell, borderFormat, topBorder);\n }\n\n // Format perimeter\n perimeter.Top = true;\n break;\n case 'bottomBorders':\n const bottomBorder: BorderPositions[] = ['borderBottom'];\n for (\n let colIndex = sel.firstColumn;\n colIndex <= sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n // Format cells - Bottom border\n applyBorderFormat(cell, borderFormat, bottomBorder);\n }\n\n // Format perimeter\n perimeter.Bottom = true;\n break;\n case 'insideBorders':\n // Format cells - Inside borders\n const singleCol = sel.lastColumn == sel.firstColumn;\n const singleRow = sel.lastRow == sel.firstRow;\n // Single cell selection\n if (singleCol && singleRow) {\n break;\n }\n // Single column selection\n if (singleCol) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstColumn],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell =\n tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex <= sel.lastColumn - 1;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderLeft',\n 'borderRight',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderLeft']\n );\n break;\n }\n\n // For multiple rows and columns selections\n // Top left cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.lastColumn : sel.firstColumn\n ],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[\n isRtl ? sel.firstColumn : sel.lastColumn\n ],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.firstRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderBottom',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // Last row\n for (\n let colIndex = sel.firstColumn + 1;\n colIndex < sel.lastColumn;\n colIndex++\n ) {\n const cell = tableModel.rows[sel.lastRow].cells[colIndex];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderLeft',\n 'borderRight',\n ]);\n }\n // First column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderLeft' : 'borderRight',\n ]);\n }\n // Last column\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex < sel.lastRow;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n isRtl ? 'borderRight' : 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstColumn++;\n sel.firstRow++;\n sel.lastColumn--;\n sel.lastRow--;\n operations.push('allBorders');\n break;\n case 'outsideBorders':\n // Format cells - Outside borders\n operations.push('topBorders');\n operations.push('bottomBorders');\n operations.push('leftBorders');\n operations.push('rightBorders');\n break;\n default:\n break;\n }\n }\n\n //Format perimeter if necessary or possible\n modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);\n }\n\n const tableMeta = getTableMetadata(tableModel);\n if (tableMeta) {\n // Enforce first column format if necessary\n setFirstColumnFormatBorders(mutateBlock(tableModel).rows, tableMeta);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'tableBorder',\n }\n );\n}\n\n/**\n * @internal\n * Apply border format to a cell\n * @param cell The cell to apply border format\n * @param borderFormat The border format to apply\n * @param positions The positions to apply\n */\nfunction applyBorderFormat(\n cell: ReadonlyContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n const mutableCell = mutateBlock(cell);\n\n positions.forEach(pos => {\n mutableCell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(mutableCell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n}\n\n/**\n * @internal\n * Modify the perimeter of the table selection\n * @param tableModel The table model\n * @param sel The table selection\n * @param borderFormat The border format to apply\n * If borderFormat is empty, the border will be removed\n * @param perimeter Where in the perimeter to apply\n */\nfunction modifyPerimeter(\n tableModel: ReadonlyContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter,\n isRtl: boolean\n) {\n // Top of selection\n if (perimeter.Top && sel.firstRow - 1 >= 0) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderBottom']);\n }\n }\n // Bottom of selection\n if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];\n applyBorderFormat(cell, borderFormat, ['borderTop']);\n }\n }\n // Left of selection\n if (perimeter.Left && sel.firstColumn - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];\n applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,2BAA2B,EAC3B,uBAAuB,GAC1B,MAAM,6BAA6B,CAAC;AAqCrC;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAClC,MAAe,EACf,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;;QACK,IAAA,KAAA,OAAe,qBAAqB,CAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;QAElD,IA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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"]}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.59.0",
7
- "roosterjs-content-model-types": "^9.59.0"
6
+ "roosterjs-content-model-dom": "^9.61.0",
7
+ "roosterjs-content-model-types": "^9.61.0"
8
8
  },
9
- "version": "9.59.0",
9
+ "version": "9.61.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",
@@ -1,5 +0,0 @@
1
- import type { ReadonlyContentModelTableRow } from 'roosterjs-content-model-types';
2
- /**
3
- * @internal
4
- */
5
- export declare function canMergeCells(rows: ReadonlyContentModelTableRow[], firstRow: number, firstCol: number, lastRow: number, lastCol: number): boolean;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canMergeCells = void 0;
4
- /**
5
- * @internal
6
- */
7
- function canMergeCells(rows, firstRow, firstCol, lastRow, lastCol) {
8
- var noSpanAbove = firstCol == lastCol ||
9
- rows[firstRow].cells.every(function (cell, colIndex) { return colIndex < firstCol || colIndex > lastCol || !cell.spanAbove; });
10
- var noSpanLeft = firstRow == lastRow ||
11
- rows.every(function (row, rowIndex) {
12
- return rowIndex < firstRow || rowIndex > lastRow || !row.cells[firstCol].spanLeft;
13
- });
14
- var noDifferentBelowSpan = rows[lastRow].cells
15
- .map(function (_, colIndex) {
16
- return colIndex >= firstCol && colIndex <= lastCol
17
- ? getBelowSpanCount(rows, lastRow, colIndex)
18
- : -1;
19
- })
20
- .every(function (x, _, a) { return x < 0 || x == a[firstCol]; });
21
- var noDifferentRightSpan = rows
22
- .map(function (_, rowIndex) {
23
- return rowIndex >= firstRow && rowIndex <= lastRow
24
- ? getRightSpanCount(rows, rowIndex, lastCol)
25
- : -1;
26
- })
27
- .every(function (x, _, a) { return x < 0 || x == a[firstRow]; });
28
- return noSpanAbove && noSpanLeft && noDifferentBelowSpan && noDifferentRightSpan;
29
- }
30
- exports.canMergeCells = canMergeCells;
31
- function getBelowSpanCount(rows, rowIndex, colIndex) {
32
- var _a, _b;
33
- var spanCount = 0;
34
- for (var row = rowIndex + 1; row < rows.length; row++) {
35
- if ((_b = (_a = rows[row]) === null || _a === void 0 ? void 0 : _a.cells[colIndex]) === null || _b === void 0 ? void 0 : _b.spanAbove) {
36
- spanCount++;
37
- }
38
- else {
39
- break;
40
- }
41
- }
42
- return spanCount;
43
- }
44
- function getRightSpanCount(rows, rowIndex, colIndex) {
45
- var _a, _b, _c;
46
- var spanCount = 0;
47
- for (var col = colIndex + 1; col < ((_a = rows[rowIndex]) === null || _a === void 0 ? void 0 : _a.cells.length); col++) {
48
- if ((_c = (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.cells[col]) === null || _c === void 0 ? void 0 : _c.spanLeft) {
49
- spanCount++;
50
- }
51
- else {
52
- break;
53
- }
54
- }
55
- return spanCount;
56
- }
57
- //# sourceMappingURL=canMergeCells.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"canMergeCells.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/canMergeCells.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,SAAgB,aAAa,CACzB,IAAoC,EACpC,QAAgB,EAChB,QAAgB,EAChB,OAAe,EACf,OAAe;IAEf,IAAM,WAAW,GACb,QAAQ,IAAI,OAAO;QACnB,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,KAAK,CACtB,UAAC,IAAI,EAAE,QAAQ,IAAK,OAAA,QAAQ,GAAG,QAAQ,IAAI,QAAQ,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAA5D,CAA4D,CACnF,CAAC;IACN,IAAM,UAAU,GACZ,QAAQ,IAAI,OAAO;QACnB,IAAI,CAAC,KAAK,CACN,UAAC,GAAG,EAAE,QAAQ;YACV,OAAA,QAAQ,GAAG,QAAQ,IAAI,QAAQ,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,QAAQ;QAA1E,CAA0E,CACjF,CAAC;IAEN,IAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK;SAC3C,GAAG,CAAC,UAAC,CAAC,EAAE,QAAQ;QACb,OAAA,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,OAAO;YACvC,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC;YAC5C,CAAC,CAAC,CAAC,CAAC;IAFR,CAEQ,CACX;SACA,KAAK,CAAC,UAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAzB,CAAyB,CAAC,CAAC;IACnD,IAAM,oBAAoB,GAAG,IAAI;SAC5B,GAAG,CAAC,UAAC,CAAC,EAAE,QAAQ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AED,OAAO,SAAS,CAAC;AACrB,CAAC","sourcesContent":["import type { ReadonlyContentModelTableRow } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function canMergeCells(\n rows: ReadonlyContentModelTableRow[],\n firstRow: number,\n firstCol: number,\n lastRow: number,\n lastCol: number\n): boolean {\n const noSpanAbove =\n firstCol == lastCol ||\n rows[firstRow].cells.every(\n (cell, colIndex) => colIndex < firstCol || colIndex > lastCol || !cell.spanAbove\n );\n const noSpanLeft =\n firstRow == lastRow ||\n rows.every(\n (row, rowIndex) =>\n rowIndex < firstRow || rowIndex > lastRow || !row.cells[firstCol].spanLeft\n );\n\n const noDifferentBelowSpan = rows[lastRow].cells\n .map((_, colIndex) =>\n colIndex >= firstCol && colIndex <= lastCol\n ? getBelowSpanCount(rows, lastRow, colIndex)\n : -1\n )\n .every((x, _, a) => x < 0 || x == a[firstCol]);\n const noDifferentRightSpan = rows\n .map((_, rowIndex) =>\n rowIndex >= firstRow && rowIndex <= lastRow\n ? getRightSpanCount(rows, rowIndex, lastCol)\n : -1\n )\n .every((x, _, a) => x < 0 || x == a[firstRow]);\n\n return noSpanAbove && noSpanLeft && noDifferentBelowSpan && noDifferentRightSpan;\n}\n\nfunction getBelowSpanCount(\n rows: ReadonlyContentModelTableRow[],\n rowIndex: number,\n colIndex: number\n) {\n let spanCount = 0;\n\n for (let row = rowIndex + 1; row < rows.length; row++) {\n if (rows[row]?.cells[colIndex]?.spanAbove) {\n spanCount++;\n } else {\n break;\n }\n }\n\n return spanCount;\n}\n\nfunction getRightSpanCount(\n rows: ReadonlyContentModelTableRow[],\n rowIndex: number,\n colIndex: number\n) {\n let spanCount = 0;\n\n for (let col = colIndex + 1; col < rows[rowIndex]?.cells.length; col++) {\n if (rows[rowIndex]?.cells[col]?.spanLeft) {\n spanCount++;\n } else {\n break;\n }\n }\n\n return spanCount;\n}\n"]}
@@ -1,8 +0,0 @@
1
- /**
2
- * @internal Check if there is XSS attack in the link
3
- * @param link The link to be checked
4
- * @returns The safe link, or empty string if there is XSS attack
5
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
6
- * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
7
- */
8
- export declare function checkXss(link: string): string;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkXss = void 0;
4
- /**
5
- * @internal Check if there is XSS attack in the link
6
- * @param link The link to be checked
7
- * @returns The safe link, or empty string if there is XSS attack
8
- * @remarks This function checks for patterns like s\nc\nr\ni\np\nt: to prevent XSS attacks. This may block some valid links,
9
- * but it is necessary for security reasons. We treat the word "script" as safe if there are "/" before it.
10
- */
11
- function checkXss(link) {
12
- return link.match(/^[^\/]*s\n*c\n*r\n*i\n*p\n*t\n*:/i) ? '' : link;
13
- }
14
- exports.checkXss = checkXss;
15
- //# sourceMappingURL=checkXss.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"checkXss.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/checkXss.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACvE,CAAC;AAFD,4BAEC","sourcesContent":["/**\n * @internal Check if there is XSS attack in the link\n * @param link The link to be checked\n * @returns The safe link, or empty string if there is XSS attack\n * @remarks This function checks for patterns like s\\nc\\nr\\ni\\np\\nt: to prevent XSS attacks. This may block some valid links,\n * but it is necessary for security reasons. We treat the word \"script\" as safe if there are \"/\" before it.\n */\nexport function checkXss(link: string): string {\n return link.match(/^[^\\/]*s\\n*c\\n*r\\n*i\\n*p\\n*t\\n*:/i) ? '' : link;\n}\n"]}
@@ -1,5 +0,0 @@
1
- import type { ReadonlyContentModelTableRow } from 'roosterjs-content-model-types';
2
- /**
3
- * @internal
4
- */
5
- export declare function canMergeCells(rows: ReadonlyContentModelTableRow[], firstRow: number, firstCol: number, lastRow: number, lastCol: number): boolean;
@@ -1,59 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.canMergeCells = void 0;
5
- /**
6
- * @internal
7
- */
8
- function canMergeCells(rows, firstRow, firstCol, lastRow, lastCol) {
9
- var noSpanAbove = firstCol == lastCol ||
10
- rows[firstRow].cells.every(function (cell, colIndex) { return colIndex < firstCol || colIndex > lastCol || !cell.spanAbove; });
11
- var noSpanLeft = firstRow == lastRow ||
12
- rows.every(function (row, rowIndex) {
13
- return rowIndex < firstRow || rowIndex > lastRow || !row.cells[firstCol].spanLeft;
14
- });
15
- var noDifferentBelowSpan = rows[lastRow].cells
16
- .map(function (_, colIndex) {
17
- return colIndex >= firstCol && colIndex <= lastCol
18
- ? getBelowSpanCount(rows, lastRow, colIndex)
19
- : -1;
20
- })
21
- .every(function (x, _, a) { return x < 0 || x == a[firstCol]; });
22
- var noDifferentRightSpan = rows
23
- .map(function (_, rowIndex) {
24
- return rowIndex >= firstRow && rowIndex <= lastRow
25
- ? getRightSpanCount(rows, rowIndex, lastCol)
26
- : -1;
27
- })
28
- .every(function (x, _, a) { return x < 0 || x == a[firstRow]; });
29
- return noSpanAbove && noSpanLeft && noDifferentBelowSpan && noDifferentRightSpan;
30
- }
31
- exports.canMergeCells = canMergeCells;
32
- function getBelowSpanCount(rows, rowIndex, colIndex) {
33
- var _a, _b;
34
- var spanCount = 0;
35
- for (var row = rowIndex + 1; row < rows.length; row++) {
36
- if ((_b = (_a = rows[row]) === null || _a === void 0 ? void 0 : _a.cells[colIndex]) === null || _b === void 0 ? void 0 : _b.spanAbove) {
37
- spanCount++;
38
- }
39
- else {
40
- break;
41
- }
42
- }
43
- return spanCount;
44
- }
45
- function getRightSpanCount(rows, rowIndex, colIndex) {
46
- var _a, _b, _c;
47
- var spanCount = 0;
48
- for (var col = colIndex + 1; col < ((_a = rows[rowIndex]) === null || _a === void 0 ? void 0 : _a.cells.length); col++) {
49
- if ((_c = (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.cells[col]) === null || _c === void 0 ? void 0 : _c.spanLeft) {
50
- spanCount++;
51
- }
52
- else {
53
- break;
54
- }
55
- }
56
- return spanCount;
57
- }
58
- });
59
- //# sourceMappingURL=canMergeCells.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"canMergeCells.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/canMergeCells.ts"],"names":[],"mappings":";;;;IAEA;;OAEG;IACH,SAAgB,aAAa,CACzB,IAAoC,EACpC,QAAgB,EAChB,QAAgB,EAChB,OAAe,EACf,OAAe;QAEf,IAAM,WAAW,GACb,QAAQ,IAAI,OAAO;YACnB,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,KAAK,CACtB,UAAC,IAAI,EAAE,QAAQ,IAAK,OAAA,QAAQ,GAAG,QAAQ,IAAI,QAAQ,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAA5D,CAA4D,CACnF,CAAC;QACN,IAAM,UAAU,GACZ,QAAQ,IAAI,OAAO;YACnB,IAAI,CAAC,KAAK,CACN,UAAC,GAAG,EAAE,QAAQ;gBACV,OAAA,QAAQ,GAAG,QAAQ,IAAI,QAAQ,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,QAAQ;YAA1E,CAA0E,CACjF,CAAC;QAEN,IAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK;aAC3C,GAAG,CAAC,UAAC,CAAC,EAAE,QAAQ;YACb,OAAA,QAAQ,IAAI,QAAQ,IAAI,QAAQ,IAAI,OAAO;gBACvC,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC;gBAC5C,CAAC,CA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AAC,EAAE,GAAG,IAAG,MAAA,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,MAAM,CAAA,EAAE,GAAG,EAAE,EAAE;YACpE,IAAI,MAAA,MAAA,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,GAAG,CAAC,0CAAE,QAAQ,EAAE;gBACtC,SAAS,EAAE,CAAC;aACf;iBAAM;gBACH,MAAM;aACT;SACJ;QAED,OAAO,SAAS,CAAC;IACrB,CAAC","sourcesContent":["import type { ReadonlyContentModelTableRow } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function canMergeCells(\n rows: ReadonlyContentModelTableRow[],\n firstRow: number,\n firstCol: number,\n lastRow: number,\n lastCol: number\n): boolean {\n const noSpanAbove =\n firstCol == lastCol ||\n rows[firstRow].cells.every(\n (cell, colIndex) => colIndex < firstCol || colIndex > lastCol || !cell.spanAbove\n );\n const noSpanLeft =\n firstRow == lastRow ||\n rows.every(\n (row, rowIndex) =>\n rowIndex < firstRow || rowIndex > lastRow || !row.cells[firstCol].spanLeft\n );\n\n const noDifferentBelowSpan = rows[lastRow].cells\n .map((_, colIndex) =>\n colIndex >= firstCol && colIndex <= lastCol\n ? getBelowSpanCount(rows, lastRow, colIndex)\n : -1\n )\n .every((x, _, a) => x < 0 || x == a[firstCol]);\n const noDifferentRightSpan = rows\n .map((_, rowIndex) =>\n rowIndex >= firstRow && rowIndex <= lastRow\n ? getRightSpanCount(rows, rowIndex, lastCol)\n : -1\n )\n .every((x, _, a) => x < 0 || x == a[firstRow]);\n\n return noSpanAbove && noSpanLeft && noDifferentBelowSpan && noDifferentRightSpan;\n}\n\nfunction getBelowSpanCount(\n rows: ReadonlyContentModelTableRow[],\n rowIndex: number,\n colIndex: number\n) {\n let spanCount = 0;\n\n for (let row = rowIndex + 1; row < rows.length; row++) {\n if (rows[row]?.cells[colIndex]?.spanAbove) {\n spanCount++;\n } else {\n break;\n }\n }\n\n return spanCount;\n}\n\nfunction getRightSpanCount(\n rows: ReadonlyContentModelTableRow[],\n rowIndex: number,\n colIndex: number\n) {\n let spanCount = 0;\n\n for (let col = colIndex + 1; col < rows[rowIndex]?.cells.length; col++) {\n if (rows[rowIndex]?.cells[col]?.spanLeft) {\n spanCount++;\n } else {\n break;\n }\n }\n\n return spanCount;\n}\n"]}