roosterjs-content-model-api 0.22.0 → 0.23.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 (55) hide show
  1. package/lib/modelApi/block/setModelAlignment.d.ts +1 -1
  2. package/lib/modelApi/block/setModelAlignment.js +13 -3
  3. package/lib/modelApi/block/setModelAlignment.js.map +1 -1
  4. package/lib/modelApi/block/setModelDirection.js +20 -3
  5. package/lib/modelApi/block/setModelDirection.js.map +1 -1
  6. package/lib/modelApi/common/retrieveModelFormatState.js +5 -3
  7. package/lib/modelApi/common/retrieveModelFormatState.js.map +1 -1
  8. package/lib/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
  9. package/lib/modelApi/selection/adjustTrailingSpaceSelection.js +56 -0
  10. package/lib/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
  11. package/lib/publicApi/block/setAlignment.d.ts +1 -1
  12. package/lib/publicApi/block/setAlignment.js.map +1 -1
  13. package/lib/publicApi/link/insertLink.js +2 -0
  14. package/lib/publicApi/link/insertLink.js.map +1 -1
  15. package/lib/publicApi/segment/toggleUnderline.js +2 -1
  16. package/lib/publicApi/segment/toggleUnderline.js.map +1 -1
  17. package/lib/publicApi/table/applyTableBorderFormat.js +18 -16
  18. package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
  19. package/lib-amd/modelApi/block/setModelAlignment.d.ts +1 -1
  20. package/lib-amd/modelApi/block/setModelAlignment.js +13 -3
  21. package/lib-amd/modelApi/block/setModelAlignment.js.map +1 -1
  22. package/lib-amd/modelApi/block/setModelDirection.js +20 -3
  23. package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
  24. package/lib-amd/modelApi/common/retrieveModelFormatState.js +5 -4
  25. package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +1 -1
  26. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
  27. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js +55 -0
  28. package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
  29. package/lib-amd/publicApi/block/setAlignment.d.ts +1 -1
  30. package/lib-amd/publicApi/block/setAlignment.js.map +1 -1
  31. package/lib-amd/publicApi/link/insertLink.js +2 -1
  32. package/lib-amd/publicApi/link/insertLink.js.map +1 -1
  33. package/lib-amd/publicApi/segment/toggleUnderline.js +2 -2
  34. package/lib-amd/publicApi/segment/toggleUnderline.js.map +1 -1
  35. package/lib-amd/publicApi/table/applyTableBorderFormat.js +18 -16
  36. package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
  37. package/lib-mjs/modelApi/block/setModelAlignment.d.ts +1 -1
  38. package/lib-mjs/modelApi/block/setModelAlignment.js +13 -3
  39. package/lib-mjs/modelApi/block/setModelAlignment.js.map +1 -1
  40. package/lib-mjs/modelApi/block/setModelDirection.js +21 -4
  41. package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
  42. package/lib-mjs/modelApi/common/retrieveModelFormatState.js +5 -3
  43. package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +1 -1
  44. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
  45. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js +52 -0
  46. package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
  47. package/lib-mjs/publicApi/block/setAlignment.d.ts +1 -1
  48. package/lib-mjs/publicApi/block/setAlignment.js.map +1 -1
  49. package/lib-mjs/publicApi/link/insertLink.js +2 -0
  50. package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
  51. package/lib-mjs/publicApi/segment/toggleUnderline.js +2 -1
  52. package/lib-mjs/publicApi/segment/toggleUnderline.js.map +1 -1
  53. package/lib-mjs/publicApi/table/applyTableBorderFormat.js +18 -16
  54. package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
  55. package/package.json +4 -4
@@ -50,6 +50,8 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
50
50
  else if (borderColor) {
51
51
  borderFormat = borderFormat + " " + borderColor;
52
52
  }
53
+ // undefined is treated as Left to Right
54
+ var isRtl = tableModel.format.direction == 'rtl';
53
55
  if (sel) {
54
56
  var operations = [operation];
55
57
  while (operations.length) {
@@ -82,22 +84,22 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
82
84
  case 'leftBorders':
83
85
  var leftBorder = ['borderLeft'];
84
86
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
85
- var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
87
+ var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
86
88
  // Format cells - Left border
87
89
  applyBorderFormat(cell, borderFormat, leftBorder);
88
90
  }
89
91
  // Format perimeter
90
- perimeter.Left = true;
92
+ isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
91
93
  break;
92
94
  case 'rightBorders':
93
95
  var rightBorder = ['borderRight'];
94
96
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
95
- var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
97
+ var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
96
98
  // Format cells - Right border
97
99
  applyBorderFormat(cell, borderFormat, rightBorder);
98
100
  }
99
101
  // Format perimeter
100
- perimeter.Right = true;
102
+ isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
101
103
  break;
102
104
  case 'topBorders':
103
105
  var topBorder = ['borderTop'];
@@ -142,7 +144,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
142
144
  }
143
145
  // Single row selection
144
146
  if (singleRow) {
145
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderRight']);
147
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
146
148
  for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
147
149
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
148
150
  applyBorderFormat(cell, borderFormat, [
@@ -150,18 +152,18 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
150
152
  'borderRight',
151
153
  ]);
152
154
  }
153
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderLeft']);
155
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderLeft']);
154
156
  break;
155
157
  }
156
158
  // For multiple rows and columns selections
157
159
  // Top left cell
158
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
160
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
159
161
  // Top right cell
160
- applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
162
+ applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
161
163
  // Bottom left cell
162
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
164
+ applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
163
165
  // Bottom right cell
164
- applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
166
+ applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
165
167
  // First row
166
168
  for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
167
169
  var cell = tableModel.rows[sel.firstRow].cells[colIndex];
@@ -186,7 +188,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
186
188
  applyBorderFormat(cell, borderFormat, [
187
189
  'borderTop',
188
190
  'borderBottom',
189
- 'borderRight',
191
+ isRtl ? 'borderLeft' : 'borderRight',
190
192
  ]);
191
193
  }
192
194
  // Last column
@@ -195,7 +197,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
195
197
  applyBorderFormat(cell, borderFormat, [
196
198
  'borderTop',
197
199
  'borderBottom',
198
- 'borderLeft',
200
+ isRtl ? 'borderRight' : 'borderLeft',
199
201
  ]);
200
202
  }
201
203
  // Inner cells
@@ -217,7 +219,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
217
219
  }
218
220
  }
219
221
  //Format perimeter if necessary or possible
220
- modifyPerimeter(tableModel, sel, borderFormat, perimeter);
222
+ modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
221
223
  }
222
224
  return true;
223
225
  }
@@ -257,7 +259,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
257
259
  * If borderFormat is empty, the border will be removed
258
260
  * @param perimeter Where in the perimeter to apply
259
261
  */
260
- function modifyPerimeter(tableModel, sel, borderFormat, perimeter) {
262
+ function modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl) {
261
263
  // Top of selection
262
264
  if (perimeter.Top && sel.firstRow - 1 >= 0) {
263
265
  for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
@@ -276,14 +278,14 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs
276
278
  if (perimeter.Left && sel.firstColumn - 1 >= 0) {
277
279
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
278
280
  var cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];
279
- applyBorderFormat(cell, borderFormat, ['borderRight']);
281
+ applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);
280
282
  }
281
283
  }
282
284
  // Right of selection
283
285
  if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {
284
286
  for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
285
287
  var cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];
286
- applyBorderFormat(cell, borderFormat, ['borderLeft']);
288
+ applyBorderFormat(cell, borderFormat, [isRtl ? 'borderRight' : 'borderLeft']);
287
289
  }
288
290
  }
289
291
  }
@@ -1 +1 @@
1
- {"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";;;IAkCA;;;;;OAKG;IACH,SAAwB,sBAAsB,CAC1C,MAAyB,EACzB,MAAc,EACd,SAA2B;QAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACK,IAAA,KAAA,oBAAe,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;YAElD,IAAI,UAAU,EAAE;gBACZ,IAAM,GAAG,GAAG,IAAA,+CAAgB,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,MAAM,MAAX,CAAY;gBACvC,IAAM,eAAe,GAAG,IAAA,kDAAmB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAC9D,IAAM,WAAW,G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K,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;gBAClE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;aAC1D;SACJ;QACD,qBAAqB;QACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACzE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;gBACjE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;aACzD;SACJ;IACL,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n TableSelectionCoordinates,\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 default function applyTableBorderFormat(\n editor: IStandaloneEditor,\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 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 = tableModel.rows[rowIndex].cells[sel.firstColumn];\n // Format cells - Left border\n applyBorderFormat(cell, borderFormat, leftBorder);\n }\n\n // Format perimeter\n 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 = tableModel.rows[rowIndex].cells[sel.lastColumn];\n // Format cells - Right border\n applyBorderFormat(cell, borderFormat, rightBorder);\n }\n\n // Format perimeter\n 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[sel.firstColumn],\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[sel.lastColumn],\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[sel.firstColumn],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastColumn],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstColumn],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.lastColumn],\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 '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 '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);\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: ContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n positions.forEach(pos => {\n cell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n\n // Cell was modified, so delete cached element\n delete cell.cachedElement;\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: ContentModelTable,\n sel: TableSelectionCoordinates,\n borderFormat: string,\n perimeter: Perimeter\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, ['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, ['borderLeft']);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";;;IAkCA;;;;;OAKG;IACH,SAAwB,sBAAsB,CAC1C,MAAyB,EACzB,MAAc,EACd,SAA2B;QAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACK,IAAA,KAAA,oBAAe,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;YAElD,IAAI,UAAU,EAAE;gBACZ,IAAM,GAAG,GAAG,IAAA,+CAAgB,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,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D,qBAAqB;QACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,UAAU,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACzE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;gBACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,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 { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n getSelectedCells,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n TableSelectionCoordinates,\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 default function applyTableBorderFormat(\n editor: IStandaloneEditor,\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 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: ContentModelTableCell,\n borderFormat: string,\n positions: BorderPositions[]\n) {\n positions.forEach(pos => {\n cell.format[pos] = borderFormat;\n });\n\n updateTableCellMetadata(cell, metadata => {\n metadata = metadata || {};\n metadata.borderOverride = true;\n return metadata;\n });\n\n // Cell was modified, so delete cached element\n delete cell.cachedElement;\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: ContentModelTable,\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"]}
@@ -2,4 +2,4 @@ import type { ContentModelDocument } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function setModelAlignment(model: ContentModelDocument, alignment: 'left' | 'center' | 'right'): boolean;
5
+ export declare function setModelAlignment(model: ContentModelDocument, alignment: 'left' | 'center' | 'right' | 'justify'): boolean;
@@ -13,6 +13,10 @@ var ResultMap = {
13
13
  ltr: 'end',
14
14
  rtl: 'start',
15
15
  },
16
+ justify: {
17
+ ltr: 'justify',
18
+ rtl: 'justify',
19
+ },
16
20
  };
17
21
  var TableAlignMap = {
18
22
  left: {
@@ -35,13 +39,19 @@ export function setModelAlignment(model, alignment) {
35
39
  var paragraphOrListItemOrTable = getOperationalBlocks(model, ['ListItem'], ['TableCell']);
36
40
  paragraphOrListItemOrTable.forEach(function (_a) {
37
41
  var block = _a.block;
38
- var newAligment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];
39
- if (block.blockType === 'Table') {
42
+ var newAlignment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];
43
+ if (block.blockType === 'Table' && alignment !== 'justify') {
40
44
  alignTable(block, TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']);
41
45
  }
42
46
  else if (block) {
47
+ if (block.blockType === 'BlockGroup' && block.blockGroupType === 'ListItem') {
48
+ block.blocks.forEach(function (b) {
49
+ var format = b.format;
50
+ format.textAlign = newAlignment;
51
+ });
52
+ }
43
53
  var format = block.format;
44
- format.textAlign = newAligment;
54
+ format.textAlign = newAlignment;
45
55
  }
46
56
  });
47
57
  return paragraphOrListItemOrTable.length > 0;
@@ -1 +1 @@
1
- {"version":3,"file":"setModelAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelAlignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOpE,IAAM,SAAS,GAGX;IACA,IAAI,EAAE;QACF,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,KAAK;KACb;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KAChB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,OAAO;KACf;CACJ,CAAC;AAEF,IAAM,aAAa,GAGf;IACA,IAAI,EAAE;QACF,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,YAAY;KACpB;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,aAAa;QAClB,GAAG,EAAE,aAAa;KACrB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,YAAY;QACjB,GAAG,EAAE,WAAW;KACnB;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC7B,KAA2B,EAC3B,SAAsC;IAEtC,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAM,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC1F,IAAI,KAAK,CAAC,SAAS,KAAK,OAAO,EAAE;YAC7B,UAAU,CACN,KAAK,EACL,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAC5E,CAAC;SACL;aAAM,IAAI,KAAK,EAAE;YACN,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;YACzB,MAAM,CAAC,SAAS,GAAG,WAAW,CAAC;SAClC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,0BAA0B,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { alignTable } from '../table/alignTable';\nimport { getOperationalBlocks } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n TableAlignOperation,\n} from 'roosterjs-content-model-types';\n\nconst ResultMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', 'start' | 'center' | 'end'>\n> = {\n left: {\n ltr: 'start',\n rtl: 'end',\n },\n center: {\n ltr: 'center',\n rtl: 'center',\n },\n right: {\n ltr: 'end',\n rtl: 'start',\n },\n};\n\nconst TableAlignMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', TableAlignOperation>\n> = {\n left: {\n ltr: 'alignLeft',\n rtl: 'alignRight',\n },\n center: {\n ltr: 'alignCenter',\n rtl: 'alignCenter',\n },\n right: {\n ltr: 'alignRight',\n rtl: 'alignLeft',\n },\n};\n\n/**\n * @internal\n */\nexport function setModelAlignment(\n model: ContentModelDocument,\n alignment: 'left' | 'center' | 'right'\n) {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n const newAligment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];\n if (block.blockType === 'Table') {\n alignTable(\n block,\n TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']\n );\n } else if (block) {\n const { format } = block;\n format.textAlign = newAligment;\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n"]}
1
+ {"version":3,"file":"setModelAlignment.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelAlignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAOpE,IAAM,SAAS,GAGX;IACA,IAAI,EAAE;QACF,GAAG,EAAE,OAAO;QACZ,GAAG,EAAE,KAAK;KACb;IACD,MAAM,EAAE;QACJ,GAAG,EAAE,QAAQ;QACb,GAAG,EAAE,QAAQ;KAChB;IACD,KAAK,EAAE;QACH,GAAG,EAAE,KAAK;QACV,GAAG,EAAE,OAAO;KACf;IACD,OAAO,EAAE;QACL,GAAG,EAAE,SAAS;QACd,GAAG,EAAE,SAAS;KACjB;CACJ,CAAC;AAEF,IAAM,aAAa,GAGf;IACA,IAAI,EAAE;QACF,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,Y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AC,CAAC;AACjD,CAAC","sourcesContent":["import { alignTable } from '../table/alignTable';\nimport { getOperationalBlocks } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelListItem,\n TableAlignOperation,\n} from 'roosterjs-content-model-types';\n\nconst ResultMap: Record<\n 'left' | 'center' | 'right' | 'justify',\n Record<'ltr' | 'rtl', 'start' | 'center' | 'end' | 'justify'>\n> = {\n left: {\n ltr: 'start',\n rtl: 'end',\n },\n center: {\n ltr: 'center',\n rtl: 'center',\n },\n right: {\n ltr: 'end',\n rtl: 'start',\n },\n justify: {\n ltr: 'justify',\n rtl: 'justify',\n },\n};\n\nconst TableAlignMap: Record<\n 'left' | 'center' | 'right',\n Record<'ltr' | 'rtl', TableAlignOperation>\n> = {\n left: {\n ltr: 'alignLeft',\n rtl: 'alignRight',\n },\n center: {\n ltr: 'alignCenter',\n rtl: 'alignCenter',\n },\n right: {\n ltr: 'alignRight',\n rtl: 'alignLeft',\n },\n};\n\n/**\n * @internal\n */\nexport function setModelAlignment(\n model: ContentModelDocument,\n alignment: 'left' | 'center' | 'right' | 'justify'\n) {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n const newAlignment = ResultMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr'];\n if (block.blockType === 'Table' && alignment !== 'justify') {\n alignTable(\n block,\n TableAlignMap[alignment][block.format.direction == 'rtl' ? 'rtl' : 'ltr']\n );\n } else if (block) {\n if (block.blockType === 'BlockGroup' && block.blockGroupType === 'ListItem') {\n block.blocks.forEach(b => {\n const { format } = b;\n format.textAlign = newAlignment;\n });\n }\n const { format } = block;\n format.textAlign = newAlignment;\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { findListItemsInSameThread } from '../list/findListItemsInSameThread';
2
- import { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';
2
+ import { applyTableFormat, getOperationalBlocks, isBlockGroupOfType, updateTableCellMetadata, } from 'roosterjs-content-model-core';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -17,25 +17,42 @@ export function setModelDirection(model, direction) {
17
17
  });
18
18
  }
19
19
  else if (block) {
20
- internalSetDirection(block.format, direction);
20
+ internalSetDirection(block.format, direction, block);
21
21
  }
22
22
  });
23
23
  return paragraphOrListItemOrTable.length > 0;
24
24
  }
25
- function internalSetDirection(format, direction) {
25
+ function internalSetDirection(format, direction, block) {
26
26
  var wasRtl = format.direction == 'rtl';
27
27
  var isRtl = direction == 'rtl';
28
28
  if (wasRtl != isRtl) {
29
29
  format.direction = direction;
30
30
  // Adjust margin when change direction
31
31
  // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here
32
- // TODO: Do we also need to handle border here?
33
32
  var marginLeft = format.marginLeft;
34
33
  var paddingLeft = format.paddingLeft;
35
34
  setProperty(format, 'marginLeft', format.marginRight);
36
35
  setProperty(format, 'marginRight', marginLeft);
37
36
  setProperty(format, 'paddingLeft', format.paddingRight);
38
37
  setProperty(format, 'paddingRight', paddingLeft);
38
+ // If whole Table direction changed, flip cell side borders
39
+ if (block && block.blockType == 'Table') {
40
+ block.rows.forEach(function (row) {
41
+ row.cells.forEach(function (cell) {
42
+ // Optimise by skipping cells with unchanged borders
43
+ updateTableCellMetadata(cell, function (metadata) {
44
+ if (metadata === null || metadata === void 0 ? void 0 : metadata.borderOverride) {
45
+ var storeBorderLeft = cell.format.borderLeft;
46
+ setProperty(cell.format, 'borderLeft', cell.format.borderRight);
47
+ setProperty(cell.format, 'borderRight', storeBorderLeft);
48
+ }
49
+ return metadata;
50
+ });
51
+ });
52
+ });
53
+ // Apply changed borders
54
+ applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);
55
+ }
39
56
  }
40
57
  }
41
58
  function setProperty(format, key, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AASxF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;IACnF,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAI,kBAAkB,CAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;YAC7D,IAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAEtD,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;gBACd,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;oBACrB,KAAK,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;gBACvC,CAAC,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK,IAAI,OAAA,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAA7C,CAA6C,CAAC,CAAC;YAChF,CAAC,CAAC,CAAC;SACN;aAAM,IAAI,KAAK,EAAE;YACd,oBAAoB,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;SACjD;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,0BAA0B,CAAC,MAAM,GAAG,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,oBAAoB,CAAC,MAA+B,EAAE,SAAwB;IACnF,IAAM,MAAM,GAAG,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC;IACzC,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;IAEjC,IAAI,MAAM,IAAI,KAAK,EAAE;QACjB,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;QAE7B,sCAAsC;QACtC,gHAAgH;QAChH,+CAA+C;QAC/C,IAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,IAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QAEvC,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;QACtD,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;QAC/C,WAAW,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;QACxD,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;KACpD;AACL,CAAC;AAED,SAAS,WAAW,CAChB,MAAoC,EACpC,GAAyC,EACzC,KAAyB;IAEzB,IAAI,KAAK,EAAE;QACP,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KACvB;SAAM;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { getOperationalBlocks, isBlockGroupOfType } from 'roosterjs-content-model-core';\nimport type {\n ContentModelBlockFormat,\n ContentModelDocument,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ContentModelDocument, direction: 'ltr' | 'rtl') {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(item => {\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block.format, direction));\n });\n } else if (block) {\n internalSetDirection(block.format, direction);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(format: ContentModelBlockFormat, direction: 'ltr' | 'rtl') {\n const wasRtl = format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n format.direction = direction;\n\n // Adjust margin when change direction\n // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here\n // TODO: Do we also need to handle border here?\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat,\n key: keyof (MarginFormat & PaddingFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
1
+ {"version":3,"file":"setModelDirection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/block/setModelDirection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EACH,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,GAC1B,MAAM,8BAA8B,CAAC;AAWtC;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA2B,EAAE,SAAwB;IACnF,IAAM,0BAA0B,GAAG,oBAAoB,CACnD,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;IAEF,0BAA0B,CAAC,OAAO,CAAC,UAAC,EAAS;YAAP,KAAK,WAAA;QACvC,IAAI,kBAAkB,CAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;YAC7D,IAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAEtD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AS,IAAI,OAAO,EAAE;YACrC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;gBAClB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;oBAClB,oDAAoD;oBACpD,uBAAuB,CAAC,IAAI,EAAE,UAAA,QAAQ;wBAClC,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,cAAc,EAAE;4BAC1B,IAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;4BAC/C,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;4BAChE,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;yBAC5D;wBACD,OAAO,QAAQ,CAAC;oBACpB,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YAEH,wBAAwB;YACxB,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;SAC/E;KACJ;AACL,CAAC;AAED,SAAS,WAAW,CAChB,MAAmD,EACnD,GAAwD,EACxD,KAAyB;IAEzB,IAAI,KAAK,EAAE;QACP,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KACvB;SAAM;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;KACtB;AACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n applyTableFormat,\n getOperationalBlocks,\n isBlockGroupOfType,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n BorderFormat,\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelDocument,\n ContentModelListItem,\n MarginFormat,\n PaddingFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function setModelDirection(model: ContentModelDocument, direction: 'ltr' | 'rtl') {\n const paragraphOrListItemOrTable = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n\n paragraphOrListItemOrTable.forEach(({ block }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const items = findListItemsInSameThread(model, block);\n\n items.forEach(item => {\n item.levels.forEach(level => {\n level.format.direction = direction;\n });\n\n item.blocks.forEach(block => internalSetDirection(block.format, direction));\n });\n } else if (block) {\n internalSetDirection(block.format, direction, block);\n }\n });\n\n return paragraphOrListItemOrTable.length > 0;\n}\n\nfunction internalSetDirection(\n format: ContentModelBlockFormat,\n direction: 'ltr' | 'rtl',\n block?: ContentModelBlock\n) {\n const wasRtl = format.direction == 'rtl';\n const isRtl = direction == 'rtl';\n\n if (wasRtl != isRtl) {\n format.direction = direction;\n\n // Adjust margin when change direction\n // TODO: make margin and padding direction-aware, like what we did for textAlign. So no need to adjust them here\n const marginLeft = format.marginLeft;\n const paddingLeft = format.paddingLeft;\n\n setProperty(format, 'marginLeft', format.marginRight);\n setProperty(format, 'marginRight', marginLeft);\n setProperty(format, 'paddingLeft', format.paddingRight);\n setProperty(format, 'paddingRight', paddingLeft);\n\n // If whole Table direction changed, flip cell side borders\n if (block && block.blockType == 'Table') {\n block.rows.forEach(row => {\n row.cells.forEach(cell => {\n // Optimise by skipping cells with unchanged borders\n updateTableCellMetadata(cell, metadata => {\n if (metadata?.borderOverride) {\n const storeBorderLeft = cell.format.borderLeft;\n setProperty(cell.format, 'borderLeft', cell.format.borderRight);\n setProperty(cell.format, 'borderRight', storeBorderLeft);\n }\n return metadata;\n });\n });\n });\n\n // Apply changed borders\n applyTableFormat(block, undefined /* newFormat */, true /* keepCellShade*/);\n }\n }\n}\n\nfunction setProperty(\n format: MarginFormat & PaddingFormat & BorderFormat,\n key: keyof (MarginFormat & PaddingFormat & BorderFormat),\n value: string | undefined\n) {\n if (value) {\n format[key] = value;\n } else {\n delete format[key];\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { parseValueWithUnit } from 'roosterjs-content-model-dom';
1
2
  import { extractBorderValues, getClosestAncestorBlockGroupIndex, isBold, iterateSelections, updateTableMetadata, } from 'roosterjs-content-model-core';
2
3
  /**
3
4
  * @internal
@@ -91,7 +92,7 @@ function retrieveSegmentFormat(result, isFirst, mergedFormat) {
91
92
  mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);
92
93
  mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);
93
94
  mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);
94
- mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst);
95
+ mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst, function (val) { return parseValueWithUnit(val, undefined, 'pt') + 'pt'; });
95
96
  mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);
96
97
  mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);
97
98
  mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);
@@ -146,13 +147,14 @@ function retrieveImageFormat(image, result) {
146
147
  borderRadius: format.borderRadius,
147
148
  };
148
149
  }
149
- function mergeValue(format, key, newValue, isFirst) {
150
+ function mergeValue(format, key, newValue, isFirst, parseFn) {
151
+ if (parseFn === void 0) { parseFn = function (val) { return val; }; }
150
152
  if (isFirst) {
151
153
  if (newValue !== undefined) {
152
154
  format[key] = newValue;
153
155
  }
154
156
  }
155
- else if (newValue !== format[key]) {
157
+ else if (parseFn(newValue) !== parseFn(format[key])) {
156
158
  delete format[key];
157
159
  }
158
160
  }
@@ -1 +1 @@
1
- {"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,mBAAmB,EACnB,iCAAiC,EACjC,MAAM,EACN,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,8BAA8B,CAAC;AActC;;GAEG;AACH,M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,uHAAuH;QACvH,wBAAwB;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;KAC9D;IACD,OAAO,EAAE,CAAC;AACd,CAAC","sourcesContent":["import {\n extractBorderValues,\n getClosestAncestorBlockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n\n // TODO: Support Code block in format state for Content Model\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(result, 'fontSize', mergedFormat.fontSize, isFirst);\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n\n //TODO: handle block owning segments with different line-heights\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (newValue !== format[key]) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}
1
+ {"version":3,"file":"retrieveModelFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/common/retrieveModelFormatState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EACH,mBAAmB,EACnB,iCAAiC,EACjC,MAAM,EACN,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,8BAA8B,CAAC;AActC;;GAEG;AACH,MAAM,UAAU,wBAAwB,CACpC,KAA2B,EAC3B,aAA+C,EAC/C,WAAoC;IAEpC,IAAI,iBAAoD,CAAC;IACzD,IAAI,UAAyC,CAAC;IAC9C,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,IAAI,cAAc,GAAG,IAAI,CAAC;IAE1B,iBAAiB,CACb,KAAK,EACL,UAAC,IAAI,EAAE,YAAY,EAAE,KAAK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CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;KAC9D;IACD,OAAO,EAAE,CAAC;AACd,CAAC","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getClosestAncestorBlockGroupIndex,\n isBold,\n iterateSelections,\n updateTableMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n ContentModelFormatState,\n ContentModelBlock,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelFormatContainer,\n ContentModelImage,\n ContentModelListItem,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n TableSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function retrieveModelFormatState(\n model: ContentModelDocument,\n pendingFormat: ContentModelSegmentFormat | null,\n formatState: ContentModelFormatState\n) {\n let firstTableContext: TableSelectionContext | undefined;\n let firstBlock: ContentModelBlock | undefined;\n let isFirst = true;\n let isFirstImage = true;\n let isFirstSegment = true;\n\n iterateSelections(\n model,\n (path, tableContext, block, segments) => {\n // Structure formats\n retrieveStructureFormat(formatState, path, isFirst);\n\n // Multiple line format\n if (block) {\n if (firstBlock) {\n formatState.isMultilineSelection = true;\n } else {\n firstBlock = block;\n }\n }\n\n if (block?.blockType == 'Paragraph') {\n // Paragraph formats\n retrieveParagraphFormat(formatState, block, isFirst);\n\n // Segment formats\n segments?.forEach(segment => {\n if (isFirstSegment || segment.segmentType != 'SelectionMarker') {\n const modelFormat = Object.assign({}, model.format);\n delete modelFormat?.italic;\n delete modelFormat?.underline;\n delete modelFormat?.fontWeight;\n\n retrieveSegmentFormat(\n formatState,\n isFirst,\n Object.assign(\n {},\n modelFormat,\n block.format,\n block.decorator?.format,\n segment.format,\n segment.code?.format,\n segment.link?.format,\n pendingFormat\n )\n );\n\n mergeValue(formatState, 'isCodeInline', !!segment?.code, isFirst);\n }\n\n // We only care the format of selection marker when it is the first selected segment. This is because when selection marker\n // is after some other selected segments, it mostly like appears at the beginning of a seconde line when the whole first line\n // is selected (e.g. triple-click on a line) then the second selection marker doesn't contain a correct format, so we need to\n // ignore it\n isFirstSegment = false;\n\n formatState.canUnlink = formatState.canUnlink || !!segment.link;\n formatState.canAddImageAltText =\n formatState.canAddImageAltText ||\n segments.some(segment => segment.segmentType == 'Image');\n\n isFirst = false;\n\n if (segment.segmentType === 'Image') {\n if (isFirstImage) {\n retrieveImageFormat(segment, formatState);\n isFirstImage = false;\n } else {\n formatState.imageFormat = undefined;\n }\n }\n });\n\n isFirst = false;\n }\n\n if (tableContext) {\n if (firstTableContext) {\n const { table, colIndex, rowIndex } = firstTableContext;\n\n // Merge table format\n if (\n tableContext.table == table &&\n (tableContext.colIndex != colIndex || tableContext.rowIndex != rowIndex)\n ) {\n formatState.canMergeTableCell = true;\n formatState.isMultilineSelection = true;\n }\n } else {\n // Table formats\n retrieveTableFormat(tableContext, formatState);\n firstTableContext = tableContext;\n }\n }\n\n // TODO: Support Code block in format state for Content Model\n },\n {\n includeListFormatHolder: 'never',\n }\n );\n\n if (formatState.fontSize) {\n formatState.fontSize = px2Pt(formatState.fontSize);\n }\n}\n\nfunction retrieveSegmentFormat(\n result: ContentModelFormatState,\n isFirst: boolean,\n mergedFormat: ContentModelSegmentFormat\n) {\n const superOrSubscript = mergedFormat.superOrSubScriptSequence?.split(' ')?.pop();\n\n mergeValue(result, 'isBold', isBold(mergedFormat.fontWeight), isFirst);\n mergeValue(result, 'isItalic', mergedFormat.italic, isFirst);\n mergeValue(result, 'isUnderline', mergedFormat.underline, isFirst);\n mergeValue(result, 'isStrikeThrough', mergedFormat.strikethrough, isFirst);\n mergeValue(result, 'isSuperscript', superOrSubscript == 'super', isFirst);\n mergeValue(result, 'isSubscript', superOrSubscript == 'sub', isFirst);\n mergeValue(result, 'letterSpacing', mergedFormat.letterSpacing, isFirst);\n\n mergeValue(result, 'fontName', mergedFormat.fontFamily, isFirst);\n mergeValue(\n result,\n 'fontSize',\n mergedFormat.fontSize,\n isFirst,\n val => parseValueWithUnit(val, undefined, 'pt') + 'pt'\n );\n mergeValue(result, 'backgroundColor', mergedFormat.backgroundColor, isFirst);\n mergeValue(result, 'textColor', mergedFormat.textColor, isFirst);\n mergeValue(result, 'fontWeight', mergedFormat.fontWeight, isFirst);\n\n //TODO: handle block owning segments with different line-heights\n mergeValue(result, 'lineHeight', mergedFormat.lineHeight, isFirst);\n}\n\nfunction retrieveParagraphFormat(\n result: ContentModelFormatState,\n paragraph: ContentModelParagraph,\n isFirst: boolean\n) {\n const headingLevel = parseInt((paragraph.decorator?.tagName || '').substring(1));\n const validHeadingLevel = headingLevel >= 1 && headingLevel <= 6 ? headingLevel : undefined;\n\n mergeValue(result, 'marginBottom', paragraph.format.marginBottom, isFirst);\n mergeValue(result, 'marginTop', paragraph.format.marginTop, isFirst);\n mergeValue(result, 'headingLevel', validHeadingLevel, isFirst);\n mergeValue(result, 'textAlign', paragraph.format.textAlign, isFirst);\n mergeValue(result, 'direction', paragraph.format.direction, isFirst);\n}\n\nfunction retrieveStructureFormat(\n result: ContentModelFormatState,\n path: ContentModelBlockGroup[],\n isFirst: boolean\n) {\n const listItemIndex = getClosestAncestorBlockGroupIndex(path, ['ListItem'], []);\n const containerIndex = getClosestAncestorBlockGroupIndex(path, ['FormatContainer'], []);\n\n if (listItemIndex >= 0) {\n const listItem = path[listItemIndex] as ContentModelListItem;\n const listType = listItem?.levels[listItem.levels.length - 1]?.listType;\n\n mergeValue(result, 'isBullet', listType == 'UL', isFirst);\n mergeValue(result, 'isNumbering', listType == 'OL', isFirst);\n }\n\n mergeValue(\n result,\n 'isBlockQuote',\n containerIndex >= 0 &&\n (path[containerIndex] as ContentModelFormatContainer)?.tagName == 'blockquote',\n isFirst\n );\n}\n\nfunction retrieveTableFormat(tableContext: TableSelectionContext, result: ContentModelFormatState) {\n const tableFormat = updateTableMetadata(tableContext.table);\n\n result.isInTable = true;\n result.tableHasHeader = tableContext.table.rows.some(row =>\n row.cells.some(cell => cell.isHeader)\n );\n\n if (tableFormat) {\n result.tableFormat = tableFormat;\n }\n}\n\nfunction retrieveImageFormat(image: ContentModelImage, result: ContentModelFormatState) {\n const { format } = image;\n const borderKey = 'borderTop';\n const extractedBorder = extractBorderValues(format[borderKey]);\n const borderColor = extractedBorder.color;\n const borderWidth = extractedBorder.width;\n const borderStyle = extractedBorder.style;\n result.imageFormat = {\n borderColor,\n borderWidth,\n borderStyle,\n boxShadow: format.boxShadow,\n borderRadius: format.borderRadius,\n };\n}\n\nfunction mergeValue<K extends keyof ContentModelFormatState>(\n format: ContentModelFormatState,\n key: K,\n newValue: ContentModelFormatState[K] | undefined,\n isFirst: boolean,\n parseFn: (val: ContentModelFormatState[K]) => ContentModelFormatState[K] = val => val\n) {\n if (isFirst) {\n if (newValue !== undefined) {\n format[key] = newValue;\n }\n } else if (parseFn(newValue) !== parseFn(format[key])) {\n delete format[key];\n }\n}\n\nfunction px2Pt(px: string) {\n if (px && px.indexOf('px') == px.length - 2) {\n // Edge may not handle the floating computing well which causes the calculated value is a little less than actual value\n // So add 0.05 to fix it\n return Math.round(parseFloat(px) * 75 + 0.05) / 100 + 'pt';\n }\n return px;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { ContentModelDocument } from 'roosterjs-content-model-types';
2
+ /**
3
+ * If a format cannot be applied to be applied to a trailing space, split the trailing space into a separate segment
4
+ * @internal
5
+ */
6
+ export declare function adjustTrailingSpaceSelection(model: ContentModelDocument): void;
@@ -0,0 +1,52 @@
1
+ import { __assign } from "tslib";
2
+ import { createText } from 'roosterjs-content-model-dom';
3
+ import { iterateSelections } from 'roosterjs-content-model-core';
4
+ /**
5
+ * If a format cannot be applied to be applied to a trailing space, split the trailing space into a separate segment
6
+ * @internal
7
+ */
8
+ export function adjustTrailingSpaceSelection(model) {
9
+ iterateSelections(model, function (_, __, block, segments) {
10
+ if ((block === null || block === void 0 ? void 0 : block.blockType) === 'Paragraph' && segments && segments.length > 0) {
11
+ if (segments.length === 1 &&
12
+ segments[0].segmentType === 'Text' &&
13
+ shouldSplitTrailingSpace(segments[0])) {
14
+ splitTextSegment(block, segments[0]);
15
+ }
16
+ else {
17
+ var lastTextSegment = segments[segments.length - 1].segmentType === 'SelectionMarker'
18
+ ? segments[segments.length - 2]
19
+ : segments[segments.length - 1];
20
+ if (lastTextSegment &&
21
+ lastTextSegment.segmentType === 'Text' &&
22
+ shouldSplitTrailingSpace(lastTextSegment)) {
23
+ splitTextSegment(block, lastTextSegment);
24
+ }
25
+ }
26
+ }
27
+ return false;
28
+ });
29
+ }
30
+ function shouldSplitTrailingSpace(segment) {
31
+ return segment.isSelected && hasTrailingSpace(segment.text) && !isTrailingSpace(segment.text);
32
+ }
33
+ function hasTrailingSpace(text) {
34
+ return text.trimRight() !== text;
35
+ }
36
+ function isTrailingSpace(text) {
37
+ return text.trimRight().length == 0;
38
+ }
39
+ function splitTextSegment(block, textSegment) {
40
+ var _a;
41
+ var text = textSegment.text.trimRight();
42
+ var trailingSpace = textSegment.text.substring(text.length);
43
+ var newText = createText(text, textSegment.format, textSegment.link, textSegment.code);
44
+ newText.isSelected = true;
45
+ var trailingSpaceLink = textSegment.link
46
+ ? __assign(__assign({}, textSegment.link), { format: __assign(__assign({}, (_a = textSegment.link) === null || _a === void 0 ? void 0 : _a.format), { underline: false }) }) : undefined;
47
+ var trailingSpaceSegment = createText(trailingSpace, undefined, trailingSpaceLink, textSegment.code);
48
+ trailingSpaceSegment.isSelected = true;
49
+ var index = block.segments.indexOf(textSegment);
50
+ block.segments.splice(index, 1, newText, trailingSpaceSegment);
51
+ }
52
+ //# sourceMappingURL=adjustTrailingSpaceSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adjustTrailingSpaceSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/selection/adjustTrailingSpaceSelection.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE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AAS,EAAE,KAAK,IAAI,CAAC;AACrC,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,gBAAgB,CAAC,KAA4B,EAAE,WAAuC;;IAC3F,IAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1C,IAAM,aAAa,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9D,IAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACzF,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAC1B,IAAM,iBAAiB,GAAG,WAAW,CAAC,IAAI;QACtC,CAAC,uBACQ,WAAW,CAAC,IAAI,KACnB,MAAM,wBACC,MAAA,WAAW,CAAC,IAAI,0CAAE,MAAM,KAC3B,SAAS,EAAE,KAAK,OAG1B,CAAC,CAAC,SAAS,CAAC;IAChB,IAAM,oBAAoB,GAAG,UAAU,CACnC,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,oBAAoB,CAAC,UAAU,GAAG,IAAI,CAAC;IACvC,IAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { createText } from 'roosterjs-content-model-dom';\nimport { iterateSelections } from 'roosterjs-content-model-core';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelText,\n} from 'roosterjs-content-model-types';\n\n/**\n * If a format cannot be applied to be applied to a trailing space, split the trailing space into a separate segment\n * @internal\n */\nexport function adjustTrailingSpaceSelection(model: ContentModelDocument) {\n iterateSelections(model, (_, __, block, segments) => {\n if (block?.blockType === 'Paragraph' && segments && segments.length > 0) {\n if (\n segments.length === 1 &&\n segments[0].segmentType === 'Text' &&\n shouldSplitTrailingSpace(segments[0])\n ) {\n splitTextSegment(block, segments[0]);\n } else {\n const lastTextSegment =\n segments[segments.length - 1].segmentType === 'SelectionMarker'\n ? segments[segments.length - 2]\n : segments[segments.length - 1];\n if (\n lastTextSegment &&\n lastTextSegment.segmentType === 'Text' &&\n shouldSplitTrailingSpace(lastTextSegment)\n ) {\n splitTextSegment(block, lastTextSegment);\n }\n }\n }\n\n return false;\n });\n}\n\nfunction shouldSplitTrailingSpace(segment: ContentModelText) {\n return segment.isSelected && hasTrailingSpace(segment.text) && !isTrailingSpace(segment.text);\n}\n\nfunction hasTrailingSpace(text: string) {\n return text.trimRight() !== text;\n}\n\nfunction isTrailingSpace(text: string) {\n return text.trimRight().length == 0;\n}\n\nfunction splitTextSegment(block: ContentModelParagraph, textSegment: Readonly<ContentModelText>) {\n const text = textSegment.text.trimRight();\n const trailingSpace = textSegment.text.substring(text.length);\n const newText = createText(text, textSegment.format, textSegment.link, textSegment.code);\n newText.isSelected = true;\n const trailingSpaceLink = textSegment.link\n ? {\n ...textSegment.link,\n format: {\n ...textSegment.link?.format,\n underline: false, // Remove underline for trailing space link\n },\n }\n : undefined;\n const trailingSpaceSegment = createText(\n trailingSpace,\n undefined,\n trailingSpaceLink,\n textSegment.code\n );\n trailingSpaceSegment.isSelected = true;\n const index = block.segments.indexOf(textSegment);\n block.segments.splice(index, 1, newText, trailingSpaceSegment);\n}\n"]}