roosterjs-content-model-api 0.21.2 → 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.
- package/lib/index.d.ts +0 -3
- package/lib/index.js +1 -7
- package/lib/index.js.map +1 -1
- package/lib/modelApi/block/setModelAlignment.d.ts +1 -1
- package/lib/modelApi/block/setModelAlignment.js +13 -3
- package/lib/modelApi/block/setModelAlignment.js.map +1 -1
- package/lib/modelApi/block/setModelDirection.js +20 -3
- package/lib/modelApi/block/setModelDirection.js.map +1 -1
- package/lib/modelApi/common/retrieveModelFormatState.js +5 -3
- package/lib/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib/modelApi/list/setListType.js +25 -0
- package/lib/modelApi/list/setListType.js.map +1 -1
- package/lib/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
- package/lib/modelApi/selection/adjustTrailingSpaceSelection.js +56 -0
- package/lib/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
- package/lib/modelApi/selection/collapseTableSelection.d.ts +1 -2
- package/lib/modelApi/selection/collapseTableSelection.js +2 -2
- package/lib/modelApi/selection/collapseTableSelection.js.map +1 -1
- package/lib/modelApi/table/alignTableCell.js +2 -3
- package/lib/modelApi/table/alignTableCell.js.map +1 -1
- package/lib/modelApi/table/deleteTableColumn.js +6 -6
- package/lib/modelApi/table/deleteTableColumn.js.map +1 -1
- package/lib/modelApi/table/deleteTableRow.js +2 -2
- package/lib/modelApi/table/deleteTableRow.js.map +1 -1
- package/lib/modelApi/table/insertTableColumn.js +6 -6
- package/lib/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib/modelApi/table/insertTableRow.js +3 -3
- package/lib/modelApi/table/insertTableRow.js.map +1 -1
- package/lib/modelApi/table/mergeTableCells.js +6 -5
- package/lib/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib/modelApi/table/mergeTableColumn.js +3 -3
- package/lib/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib/modelApi/table/mergeTableRow.js +3 -3
- package/lib/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib/modelApi/table/splitTableCellHorizontally.js +3 -3
- package/lib/modelApi/table/splitTableCellHorizontally.js.map +1 -1
- package/lib/modelApi/table/splitTableCellVertically.js +7 -5
- package/lib/modelApi/table/splitTableCellVertically.js.map +1 -1
- package/lib/publicApi/block/setAlignment.d.ts +1 -1
- package/lib/publicApi/block/setAlignment.js.map +1 -1
- package/lib/publicApi/format/getFormatState.js +7 -1
- package/lib/publicApi/format/getFormatState.js.map +1 -1
- package/lib/publicApi/image/changeImage.js +1 -2
- package/lib/publicApi/image/changeImage.js.map +1 -1
- package/lib/publicApi/image/insertImage.js +1 -2
- package/lib/publicApi/image/insertImage.js.map +1 -1
- package/lib/publicApi/link/insertLink.js +2 -0
- package/lib/publicApi/link/insertLink.js.map +1 -1
- package/lib/publicApi/segment/toggleUnderline.js +2 -1
- package/lib/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib/publicApi/table/applyTableBorderFormat.js +39 -38
- package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib/publicApi/table/editTable.js +1 -2
- package/lib/publicApi/table/editTable.js.map +1 -1
- package/lib/publicApi/table/setTableCellShade.js +1 -2
- package/lib/publicApi/table/setTableCellShade.js.map +1 -1
- package/lib-amd/index.d.ts +0 -3
- package/lib-amd/index.js +2 -5
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/modelApi/block/setModelAlignment.d.ts +1 -1
- package/lib-amd/modelApi/block/setModelAlignment.js +13 -3
- package/lib-amd/modelApi/block/setModelAlignment.js.map +1 -1
- package/lib-amd/modelApi/block/setModelDirection.js +20 -3
- package/lib-amd/modelApi/block/setModelDirection.js.map +1 -1
- package/lib-amd/modelApi/common/retrieveModelFormatState.js +5 -4
- package/lib-amd/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib-amd/modelApi/list/setListType.js +25 -0
- package/lib-amd/modelApi/list/setListType.js.map +1 -1
- package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
- package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js +55 -0
- package/lib-amd/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
- package/lib-amd/modelApi/selection/collapseTableSelection.d.ts +1 -2
- package/lib-amd/modelApi/selection/collapseTableSelection.js +2 -2
- package/lib-amd/modelApi/selection/collapseTableSelection.js.map +1 -1
- package/lib-amd/modelApi/table/alignTableCell.js +3 -3
- package/lib-amd/modelApi/table/alignTableCell.js.map +1 -1
- package/lib-amd/modelApi/table/deleteTableColumn.js +6 -6
- package/lib-amd/modelApi/table/deleteTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/deleteTableRow.js +2 -2
- package/lib-amd/modelApi/table/deleteTableRow.js.map +1 -1
- package/lib-amd/modelApi/table/insertTableColumn.js +6 -6
- package/lib-amd/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/insertTableRow.js +3 -3
- package/lib-amd/modelApi/table/insertTableRow.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableCells.js +6 -5
- package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableColumn.js +3 -3
- package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableRow.js +3 -3
- package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-amd/modelApi/table/splitTableCellHorizontally.js +3 -3
- package/lib-amd/modelApi/table/splitTableCellHorizontally.js.map +1 -1
- package/lib-amd/modelApi/table/splitTableCellVertically.js +7 -5
- package/lib-amd/modelApi/table/splitTableCellVertically.js.map +1 -1
- package/lib-amd/publicApi/block/setAlignment.d.ts +1 -1
- package/lib-amd/publicApi/block/setAlignment.js.map +1 -1
- package/lib-amd/publicApi/format/getFormatState.js +7 -1
- package/lib-amd/publicApi/format/getFormatState.js.map +1 -1
- package/lib-amd/publicApi/image/changeImage.js +2 -2
- package/lib-amd/publicApi/image/changeImage.js.map +1 -1
- package/lib-amd/publicApi/image/insertImage.js +2 -2
- package/lib-amd/publicApi/image/insertImage.js.map +1 -1
- package/lib-amd/publicApi/link/insertLink.js +2 -1
- package/lib-amd/publicApi/link/insertLink.js.map +1 -1
- package/lib-amd/publicApi/segment/toggleUnderline.js +2 -2
- package/lib-amd/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib-amd/publicApi/table/applyTableBorderFormat.js +40 -38
- package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-amd/publicApi/table/editTable.js +2 -2
- package/lib-amd/publicApi/table/editTable.js.map +1 -1
- package/lib-amd/publicApi/table/setTableCellShade.js +2 -2
- package/lib-amd/publicApi/table/setTableCellShade.js.map +1 -1
- package/lib-mjs/index.d.ts +0 -3
- package/lib-mjs/index.js +0 -3
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelAlignment.d.ts +1 -1
- package/lib-mjs/modelApi/block/setModelAlignment.js +13 -3
- package/lib-mjs/modelApi/block/setModelAlignment.js.map +1 -1
- package/lib-mjs/modelApi/block/setModelDirection.js +21 -4
- package/lib-mjs/modelApi/block/setModelDirection.js.map +1 -1
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js +5 -3
- package/lib-mjs/modelApi/common/retrieveModelFormatState.js.map +1 -1
- package/lib-mjs/modelApi/list/setListType.js +25 -0
- package/lib-mjs/modelApi/list/setListType.js.map +1 -1
- package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.d.ts +6 -0
- package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js +52 -0
- package/lib-mjs/modelApi/selection/adjustTrailingSpaceSelection.js.map +1 -0
- package/lib-mjs/modelApi/selection/collapseTableSelection.d.ts +1 -2
- package/lib-mjs/modelApi/selection/collapseTableSelection.js +2 -2
- package/lib-mjs/modelApi/selection/collapseTableSelection.js.map +1 -1
- package/lib-mjs/modelApi/table/alignTableCell.js +2 -3
- package/lib-mjs/modelApi/table/alignTableCell.js.map +1 -1
- package/lib-mjs/modelApi/table/deleteTableColumn.js +5 -5
- package/lib-mjs/modelApi/table/deleteTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/deleteTableRow.js +1 -1
- package/lib-mjs/modelApi/table/deleteTableRow.js.map +1 -1
- package/lib-mjs/modelApi/table/insertTableColumn.js +5 -5
- package/lib-mjs/modelApi/table/insertTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/insertTableRow.js +2 -2
- package/lib-mjs/modelApi/table/insertTableRow.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableCells.js +5 -4
- package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableColumn.js +2 -2
- package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableRow.js +2 -2
- package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-mjs/modelApi/table/splitTableCellHorizontally.js +2 -2
- package/lib-mjs/modelApi/table/splitTableCellHorizontally.js.map +1 -1
- package/lib-mjs/modelApi/table/splitTableCellVertically.js +6 -4
- package/lib-mjs/modelApi/table/splitTableCellVertically.js.map +1 -1
- package/lib-mjs/publicApi/block/setAlignment.d.ts +1 -1
- package/lib-mjs/publicApi/block/setAlignment.js.map +1 -1
- package/lib-mjs/publicApi/format/getFormatState.js +8 -2
- package/lib-mjs/publicApi/format/getFormatState.js.map +1 -1
- package/lib-mjs/publicApi/image/changeImage.js +1 -2
- package/lib-mjs/publicApi/image/changeImage.js.map +1 -1
- package/lib-mjs/publicApi/image/insertImage.js +1 -2
- package/lib-mjs/publicApi/image/insertImage.js.map +1 -1
- package/lib-mjs/publicApi/link/insertLink.js +2 -0
- package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
- package/lib-mjs/publicApi/segment/toggleUnderline.js +2 -1
- package/lib-mjs/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js +39 -38
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-mjs/publicApi/table/editTable.js +1 -2
- package/lib-mjs/publicApi/table/editTable.js.map +1 -1
- package/lib-mjs/publicApi/table/setTableCellShade.js +1 -2
- package/lib-mjs/publicApi/table/setTableCellShade.js.map +1 -1
- package/package.json +4 -4
- package/lib/modelApi/domUtils/readFile.d.ts +0 -8
- package/lib/modelApi/domUtils/readFile.js +0 -24
- package/lib/modelApi/domUtils/readFile.js.map +0 -1
- package/lib/modelApi/table/getSelectedCells.d.ts +0 -14
- package/lib/modelApi/table/getSelectedCells.js +0 -32
- package/lib/modelApi/table/getSelectedCells.js.map +0 -1
- package/lib/publicApi/selection/hasSelectionInBlock.d.ts +0 -6
- package/lib/publicApi/selection/hasSelectionInBlock.js +0 -25
- package/lib/publicApi/selection/hasSelectionInBlock.js.map +0 -1
- package/lib/publicApi/selection/hasSelectionInBlockGroup.d.ts +0 -6
- package/lib/publicApi/selection/hasSelectionInBlockGroup.js +0 -18
- package/lib/publicApi/selection/hasSelectionInBlockGroup.js.map +0 -1
- package/lib/publicApi/selection/hasSelectionInSegment.d.ts +0 -6
- package/lib/publicApi/selection/hasSelectionInSegment.js +0 -13
- package/lib/publicApi/selection/hasSelectionInSegment.js.map +0 -1
- package/lib-amd/modelApi/domUtils/readFile.d.ts +0 -8
- package/lib-amd/modelApi/domUtils/readFile.js +0 -26
- package/lib-amd/modelApi/domUtils/readFile.js.map +0 -1
- package/lib-amd/modelApi/table/getSelectedCells.d.ts +0 -14
- package/lib-amd/modelApi/table/getSelectedCells.js +0 -33
- package/lib-amd/modelApi/table/getSelectedCells.js.map +0 -1
- package/lib-amd/publicApi/selection/hasSelectionInBlock.d.ts +0 -6
- package/lib-amd/publicApi/selection/hasSelectionInBlock.js +0 -25
- package/lib-amd/publicApi/selection/hasSelectionInBlock.js.map +0 -1
- package/lib-amd/publicApi/selection/hasSelectionInBlockGroup.d.ts +0 -6
- package/lib-amd/publicApi/selection/hasSelectionInBlockGroup.js +0 -19
- package/lib-amd/publicApi/selection/hasSelectionInBlockGroup.js.map +0 -1
- package/lib-amd/publicApi/selection/hasSelectionInSegment.d.ts +0 -6
- package/lib-amd/publicApi/selection/hasSelectionInSegment.js +0 -14
- package/lib-amd/publicApi/selection/hasSelectionInSegment.js.map +0 -1
- package/lib-mjs/modelApi/domUtils/readFile.d.ts +0 -8
- package/lib-mjs/modelApi/domUtils/readFile.js +0 -20
- package/lib-mjs/modelApi/domUtils/readFile.js.map +0 -1
- package/lib-mjs/modelApi/table/getSelectedCells.d.ts +0 -14
- package/lib-mjs/modelApi/table/getSelectedCells.js +0 -28
- package/lib-mjs/modelApi/table/getSelectedCells.js.map +0 -1
- package/lib-mjs/publicApi/selection/hasSelectionInBlock.d.ts +0 -6
- package/lib-mjs/publicApi/selection/hasSelectionInBlock.js +0 -22
- package/lib-mjs/publicApi/selection/hasSelectionInBlock.js.map +0 -1
- package/lib-mjs/publicApi/selection/hasSelectionInBlockGroup.d.ts +0 -6
- package/lib-mjs/publicApi/selection/hasSelectionInBlockGroup.js +0 -15
- package/lib-mjs/publicApi/selection/hasSelectionInBlockGroup.js.map +0 -1
- package/lib-mjs/publicApi/selection/hasSelectionInSegment.d.ts +0 -6
- package/lib-mjs/publicApi/selection/hasSelectionInSegment.js +0 -10
- package/lib-mjs/publicApi/selection/hasSelectionInSegment.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "
|
|
1
|
+
define(["require", "exports", "tslib", "roosterjs-content-model-dom", "roosterjs-content-model-core"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, roosterjs_content_model_core_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
/**
|
|
@@ -11,7 +11,7 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
11
11
|
editor.formatContentModel(function (model) {
|
|
12
12
|
var _a = (0, tslib_1.__read)((0, roosterjs_content_model_core_1.getFirstSelectedTable)(model), 1), tableModel = _a[0];
|
|
13
13
|
if (tableModel) {
|
|
14
|
-
var sel = (0,
|
|
14
|
+
var sel = (0, roosterjs_content_model_core_1.getSelectedCells)(tableModel);
|
|
15
15
|
var perimeter = {
|
|
16
16
|
Top: false,
|
|
17
17
|
Bottom: false,
|
|
@@ -50,6 +50,8 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
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) {
|
|
@@ -67,7 +69,7 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
67
69
|
'borderRight',
|
|
68
70
|
];
|
|
69
71
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
70
|
-
for (var colIndex = sel.
|
|
72
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
71
73
|
var cell = tableModel.rows[rowIndex].cells[colIndex];
|
|
72
74
|
// Format cells - All borders
|
|
73
75
|
applyBorderFormat(cell, borderFormat, allBorders);
|
|
@@ -82,26 +84,26 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
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.
|
|
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.
|
|
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'];
|
|
104
|
-
for (var colIndex = sel.
|
|
106
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
105
107
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
106
108
|
// Format cells - Top border
|
|
107
109
|
applyBorderFormat(cell, borderFormat, topBorder);
|
|
@@ -111,7 +113,7 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
111
113
|
break;
|
|
112
114
|
case 'bottomBorders':
|
|
113
115
|
var bottomBorder = ['borderBottom'];
|
|
114
|
-
for (var colIndex = sel.
|
|
116
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
115
117
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
116
118
|
// Format cells - Bottom border
|
|
117
119
|
applyBorderFormat(cell, borderFormat, bottomBorder);
|
|
@@ -121,7 +123,7 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
121
123
|
break;
|
|
122
124
|
case 'insideBorders':
|
|
123
125
|
// Format cells - Inside borders
|
|
124
|
-
var singleCol = sel.
|
|
126
|
+
var singleCol = sel.lastColumn == sel.firstColumn;
|
|
125
127
|
var singleRow = sel.lastRow == sel.firstRow;
|
|
126
128
|
// Single cell selection
|
|
127
129
|
if (singleCol && singleRow) {
|
|
@@ -129,41 +131,41 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
129
131
|
}
|
|
130
132
|
// Single column selection
|
|
131
133
|
if (singleCol) {
|
|
132
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
134
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom']);
|
|
133
135
|
for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
|
|
134
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
136
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
135
137
|
applyBorderFormat(cell, borderFormat, [
|
|
136
138
|
'borderTop',
|
|
137
139
|
'borderBottom',
|
|
138
140
|
]);
|
|
139
141
|
}
|
|
140
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
142
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop']);
|
|
141
143
|
break;
|
|
142
144
|
}
|
|
143
145
|
// Single row selection
|
|
144
146
|
if (singleRow) {
|
|
145
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
146
|
-
for (var colIndex = sel.
|
|
147
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], borderFormat, ['borderRight']);
|
|
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, [
|
|
149
151
|
'borderLeft',
|
|
150
152
|
'borderRight',
|
|
151
153
|
]);
|
|
152
154
|
}
|
|
153
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
166
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
|
|
165
167
|
// First row
|
|
166
|
-
for (var colIndex = sel.
|
|
168
|
+
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
167
169
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
168
170
|
applyBorderFormat(cell, borderFormat, [
|
|
169
171
|
'borderBottom',
|
|
@@ -172,7 +174,7 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
172
174
|
]);
|
|
173
175
|
}
|
|
174
176
|
// Last row
|
|
175
|
-
for (var colIndex = sel.
|
|
177
|
+
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
176
178
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
177
179
|
applyBorderFormat(cell, borderFormat, [
|
|
178
180
|
'borderTop',
|
|
@@ -182,26 +184,26 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
182
184
|
}
|
|
183
185
|
// First column
|
|
184
186
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
185
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
187
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
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
|
|
193
195
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
194
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
196
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
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
|
|
202
|
-
sel.
|
|
204
|
+
sel.firstColumn++;
|
|
203
205
|
sel.firstRow++;
|
|
204
|
-
sel.
|
|
206
|
+
sel.lastColumn--;
|
|
205
207
|
sel.lastRow--;
|
|
206
208
|
operations.push('allBorders');
|
|
207
209
|
break;
|
|
@@ -217,7 +219,7 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
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,33 +259,33 @@ define(["require", "exports", "tslib", "../../modelApi/table/getSelectedCells",
|
|
|
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
|
-
for (var colIndex = sel.
|
|
265
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
264
266
|
var cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];
|
|
265
267
|
applyBorderFormat(cell, borderFormat, ['borderBottom']);
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
270
|
// Bottom of selection
|
|
269
271
|
if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {
|
|
270
|
-
for (var colIndex = sel.
|
|
272
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
271
273
|
var cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];
|
|
272
274
|
applyBorderFormat(cell, borderFormat, ['borderTop']);
|
|
273
275
|
}
|
|
274
276
|
}
|
|
275
277
|
// Left of selection
|
|
276
|
-
if (perimeter.Left && sel.
|
|
278
|
+
if (perimeter.Left && sel.firstColumn - 1 >= 0) {
|
|
277
279
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
278
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
279
|
-
applyBorderFormat(cell, borderFormat, ['borderRight']);
|
|
280
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];
|
|
281
|
+
applyBorderFormat(cell, borderFormat, [isRtl ? 'borderLeft' : 'borderRight']);
|
|
280
282
|
}
|
|
281
283
|
}
|
|
282
284
|
// Right of selection
|
|
283
|
-
if (perimeter.Right && sel.
|
|
285
|
+
if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {
|
|
284
286
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
285
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
286
|
-
applyBorderFormat(cell, borderFormat, ['borderLeft']);
|
|
287
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];
|
|
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,mCAAgB,EAAC,UAAU,CAAC,CAAC;gBACzC,IAAM,SAAS,GAAc;oBACzB,GAAG,EAAE,KAAK;oBACV,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,KAAK;oBACX,KAAK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CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;aACxD;SACJ;QACD,oBAAoB;QACpB,IAAI,SAAS,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,EAAE;YACzC,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,QAAQ,GAAG,CAAC,CAAC,CAAC;gBAC/D,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;aAC1D;SACJ;QACD,qBAAqB;QACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;YACtE,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,OAAO,GAAG,CAAC,CAAC,CAAC;gBAC9D,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;aACzD;SACJ;IACL,CAAC","sourcesContent":["import { getSelectedCells } from '../../modelApi/table/getSelectedCells';\nimport { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport {\n extractBorderValues,\n getFirstSelectedTable,\n updateTableCellMetadata,\n} from 'roosterjs-content-model-core';\nimport type {\n IStandaloneEditor,\n Border,\n ContentModelTable,\n ContentModelTableCell,\n BorderOperations,\n} from 'roosterjs-content-model-types';\nimport type { TableSelectionCoordinates } from '../../modelApi/table/getSelectedCells';\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.firstCol;\n colIndex <= sel.lastCol;\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.firstCol];\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.lastCol];\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.firstCol;\n colIndex <= sel.lastCol;\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.firstCol;\n colIndex <= sel.lastCol;\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.lastCol == sel.firstCol;\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.firstCol],\n borderFormat,\n ['borderBottom']\n );\n for (\n let rowIndex = sel.firstRow + 1;\n rowIndex <= sel.lastRow - 1;\n rowIndex++\n ) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstCol];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n ]);\n }\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstCol],\n borderFormat,\n ['borderTop']\n );\n break;\n }\n // Single row selection\n if (singleRow) {\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.firstCol],\n borderFormat,\n ['borderRight']\n );\n for (\n let colIndex = sel.firstCol + 1;\n colIndex <= sel.lastCol - 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.lastCol],\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.firstCol],\n borderFormat,\n ['borderBottom', 'borderRight']\n );\n // Top right cell\n applyBorderFormat(\n tableModel.rows[sel.firstRow].cells[sel.lastCol],\n borderFormat,\n ['borderBottom', 'borderLeft']\n );\n // Bottom left cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.firstCol],\n borderFormat,\n ['borderTop', 'borderRight']\n );\n // Bottom right cell\n applyBorderFormat(\n tableModel.rows[sel.lastRow].cells[sel.lastCol],\n borderFormat,\n ['borderTop', 'borderLeft']\n );\n // First row\n for (\n let colIndex = sel.firstCol + 1;\n colIndex < sel.lastCol;\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.firstCol + 1;\n colIndex < sel.lastCol;\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.firstCol];\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.lastCol];\n applyBorderFormat(cell, borderFormat, [\n 'borderTop',\n 'borderBottom',\n 'borderLeft',\n ]);\n }\n // Inner cells\n sel.firstCol++;\n sel.firstRow++;\n sel.lastCol--;\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.firstCol; colIndex <= sel.lastCol; 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.firstCol; colIndex <= sel.lastCol; 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.firstCol - 1 >= 0) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.firstCol - 1];\n applyBorderFormat(cell, borderFormat, ['borderRight']);\n }\n }\n // Right of selection\n if (perimeter.Right && sel.lastCol + 1 < tableModel.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = tableModel.rows[rowIndex].cells[sel.lastCol + 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;YA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AC5C,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,WAAW,GAAG,CAAC,CAAC,CAAC;gBAClE,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;aACjF;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,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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "
|
|
1
|
+
define(["require", "exports", "tslib", "../../modelApi/table/alignTable", "../../modelApi/table/deleteTable", "../../modelApi/table/deleteTableColumn", "../../modelApi/table/deleteTableRow", "../../modelApi/table/ensureFocusableParagraphForTable", "../../modelApi/table/insertTableColumn", "../../modelApi/table/insertTableRow", "../../modelApi/table/mergeTableCells", "../../modelApi/table/mergeTableColumn", "../../modelApi/table/mergeTableRow", "../../modelApi/table/splitTableCellHorizontally", "../../modelApi/table/splitTableCellVertically", "roosterjs-content-model-core", "../../modelApi/table/alignTableCell", "roosterjs-content-model-dom"], function (require, exports, tslib_1, alignTable_1, deleteTable_1, deleteTableColumn_1, deleteTableRow_1, ensureFocusableParagraphForTable_1, insertTableColumn_1, insertTableRow_1, mergeTableCells_1, mergeTableColumn_1, mergeTableRow_1, splitTableCellHorizontally_1, splitTableCellVertically_1, roosterjs_content_model_core_1, alignTableCell_1, roosterjs_content_model_dom_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
/**
|
|
@@ -62,7 +62,7 @@ define(["require", "exports", "tslib", "../selection/hasSelectionInBlock", "../.
|
|
|
62
62
|
(0, splitTableCellVertically_1.splitTableCellVertically)(tableModel);
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
|
-
if (!(0,
|
|
65
|
+
if (!(0, roosterjs_content_model_core_1.hasSelectionInBlock)(tableModel)) {
|
|
66
66
|
var paragraph = (0, ensureFocusableParagraphForTable_1.ensureFocusableParagraphForTable)(model, path, tableModel);
|
|
67
67
|
if (paragraph) {
|
|
68
68
|
var marker = (0, roosterjs_content_model_dom_1.createSelectionMarker)(model.format);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../pack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,WAAW;SACvB,CACJ,CAAC;IACN,CAAC;IAjGD,4BAiGC","sourcesContent":["import { alignTable } from '../../modelApi/table/alignTable';\nimport { deleteTable } from '../../modelApi/table/deleteTable';\nimport { deleteTableColumn } from '../../modelApi/table/deleteTableColumn';\nimport { deleteTableRow } from '../../modelApi/table/deleteTableRow';\nimport { ensureFocusableParagraphForTable } from '../../modelApi/table/ensureFocusableParagraphForTable';\nimport { insertTableColumn } from '../../modelApi/table/insertTableColumn';\nimport { insertTableRow } from '../../modelApi/table/insertTableRow';\nimport { mergeTableCells } from '../../modelApi/table/mergeTableCells';\nimport { mergeTableColumn } from '../../modelApi/table/mergeTableColumn';\nimport { mergeTableRow } from '../../modelApi/table/mergeTableRow';\nimport { splitTableCellHorizontally } from '../../modelApi/table/splitTableCellHorizontally';\nimport { splitTableCellVertically } from '../../modelApi/table/splitTableCellVertically';\n\nimport {\n hasSelectionInBlock,\n applyTableFormat,\n getFirstSelectedTable,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-core';\nimport type { TableOperation, IStandaloneEditor } from 'roosterjs-content-model-types';\nimport {\n alignTableCellHorizontally,\n alignTableCellVertically,\n} from '../../modelApi/table/alignTableCell';\nimport {\n createSelectionMarker,\n hasMetadata,\n setParagraphNotImplicit,\n} from 'roosterjs-content-model-dom';\n\n/**\n * Format current focused table with the given format\n * @param editor The editor instance\n * @param operation The table operation to apply\n */\nexport default function editTable(editor: IStandaloneEditor, operation: TableOperation) {\n editor.focus();\n\n editor.formatContentModel(\n model => {\n const [tableModel, path] = getFirstSelectedTable(model);\n\n if (tableModel) {\n switch (operation) {\n case 'alignCellLeft':\n case 'alignCellCenter':\n case 'alignCellRight':\n alignTableCellHorizontally(tableModel, operation);\n break;\n case 'alignCellTop':\n case 'alignCellMiddle':\n case 'alignCellBottom':\n alignTableCellVertically(tableModel, operation);\n break;\n case 'alignCenter':\n case 'alignLeft':\n case 'alignRight':\n alignTable(tableModel, operation);\n break;\n\n case 'deleteColumn':\n deleteTableColumn(tableModel);\n break;\n\n case 'deleteRow':\n deleteTableRow(tableModel);\n break;\n\n case 'deleteTable':\n deleteTable(tableModel);\n break;\n\n case 'insertAbove':\n case 'insertBelow':\n insertTableRow(tableModel, operation);\n break;\n\n case 'insertLeft':\n case 'insertRight':\n insertTableColumn(tableModel, operation);\n break;\n\n case 'mergeAbove':\n case 'mergeBelow':\n mergeTableRow(tableModel, operation);\n break;\n\n case 'mergeCells':\n mergeTableCells(tableModel);\n break;\n\n case 'mergeLeft':\n case 'mergeRight':\n mergeTableColumn(tableModel, operation);\n break;\n\n case 'splitHorizontally':\n splitTableCellHorizontally(tableModel);\n break;\n\n case 'splitVertically':\n splitTableCellVertically(tableModel);\n break;\n }\n\n if (!hasSelectionInBlock(tableModel)) {\n const paragraph = ensureFocusableParagraphForTable(model, path, tableModel);\n\n if (paragraph) {\n const marker = createSelectionMarker(model.format);\n\n paragraph.segments.unshift(marker);\n setParagraphNotImplicit(paragraph);\n setSelection(model, marker);\n }\n }\n\n normalizeTable(tableModel, model.format);\n\n if (hasMetadata(tableModel)) {\n applyTableFormat(tableModel, undefined /*newFormat*/, true /*keepCellShade*/);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'editTable',\n }\n );\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "
|
|
1
|
+
define(["require", "exports", "tslib", "roosterjs-content-model-core"], function (require, exports, tslib_1, roosterjs_content_model_core_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
/**
|
|
@@ -14,7 +14,7 @@ define(["require", "exports", "tslib", "../selection/hasSelectionInBlockGroup",
|
|
|
14
14
|
(0, roosterjs_content_model_core_1.normalizeTable)(table);
|
|
15
15
|
table.rows.forEach(function (row) {
|
|
16
16
|
return row.cells.forEach(function (cell) {
|
|
17
|
-
if ((0,
|
|
17
|
+
if ((0, roosterjs_content_model_core_1.hasSelectionInBlockGroup)(cell)) {
|
|
18
18
|
(0, roosterjs_content_model_core_1.setTableCellBackgroundColor)(cell, color, true /*isColorOverride*/);
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setTableCellShade.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/setTableCellShade.ts"],"names":[],"mappings":";;;IAQA;;;;OAIG;IACH,SAAwB,iBAAiB,CAAC,MAAyB,EAAE,KAAoB;QACrF,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACK,IAAA,KAAA,oBAAU,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAArC,KAAK,QAAgC,CAAC;YAE7C,IAAI,KAAK,EAAE;gBACP,IAAA,6CAAc,EAAC,KAAK,CAAC,CAAC;gBAEtB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;oBAClB,OAAA,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;wBAClB,IAAI,IAAA,
|
|
1
|
+
{"version":3,"file":"setTableCellShade.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/setTableCellShade.ts"],"names":[],"mappings":";;;IAQA;;;;OAIG;IACH,SAAwB,iBAAiB,CAAC,MAAyB,EAAE,KAAoB;QACrF,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;YACK,IAAA,KAAA,oBAAU,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAArC,KAAK,QAAgC,CAAC;YAE7C,IAAI,KAAK,EAAE;gBACP,IAAA,6CAAc,EAAC,KAAK,CAAC,CAAC;gBAEtB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAA,GAAG;oBAClB,OAAA,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;wBAClB,IAAI,IAAA,uDAAwB,EAAC,IAAI,CAAC,EAAE;4BAChC,IAAA,0DAA2B,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;yBACtE;oBACL,CAAC,CAAC;gBAJF,CAIE,CACL,CAAC;gBAEF,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,mBAAmB;SAC/B,CACJ,CAAC;IACN,CAAC;IA3BD,oCA2BC","sourcesContent":["import {\n hasSelectionInBlockGroup,\n getFirstSelectedTable,\n normalizeTable,\n setTableCellBackgroundColor,\n} from 'roosterjs-content-model-core';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Set table cell shade color\n * @param editor The editor instance\n * @param color The color to set. Pass null to remove existing shade color\n */\nexport default function setTableCellShade(editor: IStandaloneEditor, color: string | null) {\n editor.focus();\n\n editor.formatContentModel(\n model => {\n const [table] = getFirstSelectedTable(model);\n\n if (table) {\n normalizeTable(table);\n\n table.rows.forEach(row =>\n row.cells.forEach(cell => {\n if (hasSelectionInBlockGroup(cell)) {\n setTableCellBackgroundColor(cell, color, true /*isColorOverride*/);\n }\n })\n );\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'setTableCellShade',\n }\n );\n}\n"]}
|
package/lib-mjs/index.d.ts
CHANGED
|
@@ -21,9 +21,6 @@ export { default as changeCapitalization } from './publicApi/segment/changeCapit
|
|
|
21
21
|
export { default as insertImage } from './publicApi/image/insertImage';
|
|
22
22
|
export { default as setListStyle } from './publicApi/list/setListStyle';
|
|
23
23
|
export { default as setListStartNumber } from './publicApi/list/setListStartNumber';
|
|
24
|
-
export { default as hasSelectionInBlock } from './publicApi/selection/hasSelectionInBlock';
|
|
25
|
-
export { default as hasSelectionInSegment } from './publicApi/selection/hasSelectionInSegment';
|
|
26
|
-
export { default as hasSelectionInBlockGroup } from './publicApi/selection/hasSelectionInBlockGroup';
|
|
27
24
|
export { default as setIndentation } from './publicApi/block/setIndentation';
|
|
28
25
|
export { default as setAlignment } from './publicApi/block/setAlignment';
|
|
29
26
|
export { default as setDirection } from './publicApi/block/setDirection';
|
package/lib-mjs/index.js
CHANGED
|
@@ -21,9 +21,6 @@ export { default as changeCapitalization } from './publicApi/segment/changeCapit
|
|
|
21
21
|
export { default as insertImage } from './publicApi/image/insertImage';
|
|
22
22
|
export { default as setListStyle } from './publicApi/list/setListStyle';
|
|
23
23
|
export { default as setListStartNumber } from './publicApi/list/setListStartNumber';
|
|
24
|
-
export { default as hasSelectionInBlock } from './publicApi/selection/hasSelectionInBlock';
|
|
25
|
-
export { default as hasSelectionInSegment } from './publicApi/selection/hasSelectionInSegment';
|
|
26
|
-
export { default as hasSelectionInBlockGroup } from './publicApi/selection/hasSelectionInBlockGroup';
|
|
27
24
|
export { default as setIndentation } from './publicApi/block/setIndentation';
|
|
28
25
|
export { default as setAlignment } from './publicApi/block/setAlignment';
|
|
29
26
|
export { default as setDirection } from './publicApi/block/setDirection';
|
package/lib-mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages-content-model/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAC7F,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,M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AM,sCAAsC,CAAC;AACrF,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export { default as insertTable } from './publicApi/table/insertTable';\nexport { default as formatTable } from './publicApi/table/formatTable';\nexport { default as setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { default as editTable } from './publicApi/table/editTable';\nexport { default as applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { default as toggleBullet } from './publicApi/list/toggleBullet';\nexport { default as toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { default as toggleBold } from './publicApi/segment/toggleBold';\nexport { default as toggleItalic } from './publicApi/segment/toggleItalic';\nexport { default as toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { default as toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { default as toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { default as toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { default as setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { default as setFontName } from './publicApi/segment/setFontName';\nexport { default as setFontSize } from './publicApi/segment/setFontSize';\nexport { default as setTextColor } from './publicApi/segment/setTextColor';\nexport { default as changeFontSize } from './publicApi/segment/changeFontSize';\nexport { default as applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { default as changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { default as insertImage } from './publicApi/image/insertImage';\nexport { default as setListStyle } from './publicApi/list/setListStyle';\nexport { default as setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { default as setIndentation } from './publicApi/block/setIndentation';\nexport { default as setAlignment } from './publicApi/block/setAlignment';\nexport { default as setDirection } from './publicApi/block/setDirection';\nexport { default as setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { default as toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { default as setSpacing } from './publicApi/block/setSpacing';\nexport { default as setImageBorder } from './publicApi/image/setImageBorder';\nexport { default as setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { default as changeImage } from './publicApi/image/changeImage';\nexport { default as getFormatState } from './publicApi/format/getFormatState';\nexport { default as clearFormat } from './publicApi/format/clearFormat';\nexport { default as insertLink } from './publicApi/link/insertLink';\nexport { default as removeLink } from './publicApi/link/removeLink';\nexport { default as adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { default as setImageAltText } from './publicApi/image/setImageAltText';\nexport { default as adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { default as setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { default as toggleCode } from './publicApi/segment/toggleCode';\nexport { default as insertEntity } from './publicApi/entity/insertEntity';\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
|
|
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 =
|
|
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,
|
|
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,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,SAAkD;IAElD,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,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3F,IAAI,KAAK,CAAC,SAAS,KAAK,OAAO,IAAI,SAAS,KAAK,SAAS,EAAE;YACxD,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;YACd,IAAI,KAAK,CAAC,SAAS,KAAK,YAAY,IAAI,KAAK,CAAC,cAAc,KAAK,UAAU,EAAE;gBACzE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,CAAC;oBACV,IAAA,MAAM,GAAK,CAAC,OAAN,CAAO;oBACrB,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;gBACpC,CAAC,CAAC,CAAC;aACN;YACO,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;YACzB,MAAM,CAAC,SAAS,GAAG,YAAY,CAAC;SACnC;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' | '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"]}
|