roosterjs-content-model-api 0.21.1 → 0.22.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/list/setListType.js +25 -0
- package/lib/modelApi/list/setListType.js.map +1 -1
- 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/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/table/applyTableBorderFormat.js +29 -30
- 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/list/setListType.js +25 -0
- package/lib-amd/modelApi/list/setListType.js.map +1 -1
- 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/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/table/applyTableBorderFormat.js +30 -30
- 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/list/setListType.js +25 -0
- package/lib-mjs/modelApi/list/setListType.js.map +1 -1
- 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/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/table/applyTableBorderFormat.js +29 -30
- 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
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.splitTableCellVertically = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
|
-
var
|
|
6
|
+
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
7
7
|
var MIN_HEIGHT = 22;
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
function splitTableCellVertically(table) {
|
|
12
|
-
var sel = (0,
|
|
12
|
+
var sel = (0, roosterjs_content_model_core_1.getSelectedCells)(table);
|
|
13
13
|
if (sel) {
|
|
14
14
|
for (var rowIndex = sel.lastRow; rowIndex >= sel.firstRow; rowIndex--) {
|
|
15
15
|
var row = table.rows[rowIndex];
|
|
@@ -19,10 +19,12 @@ function splitTableCellVertically(table) {
|
|
|
19
19
|
});
|
|
20
20
|
delete row.cachedElement;
|
|
21
21
|
if (belowRow === null || belowRow === void 0 ? void 0 : belowRow.cells.every(function (belowCell, colIndex) {
|
|
22
|
-
return colIndex < sel.
|
|
22
|
+
return colIndex < sel.firstColumn ||
|
|
23
|
+
colIndex > sel.lastColumn ||
|
|
24
|
+
belowCell.spanAbove;
|
|
23
25
|
})) {
|
|
24
26
|
belowRow.cells.forEach(function (belowCell, colIndex) {
|
|
25
|
-
if (colIndex >= sel.
|
|
27
|
+
if (colIndex >= sel.firstColumn && colIndex <= sel.lastColumn) {
|
|
26
28
|
belowCell.spanAbove = false;
|
|
27
29
|
delete belowCell.cachedElement;
|
|
28
30
|
}
|
|
@@ -37,7 +39,7 @@ function splitTableCellVertically(table) {
|
|
|
37
39
|
cells: row.cells.map(function (cell, colIndex) {
|
|
38
40
|
var newCell = (0, roosterjs_content_model_dom_1.createTableCell)(cell.spanLeft, cell.spanAbove, cell.isHeader, cell.format);
|
|
39
41
|
newCell.dataset = (0, tslib_1.__assign)({}, cell.dataset);
|
|
40
|
-
if (colIndex < sel.
|
|
42
|
+
if (colIndex < sel.firstColumn || colIndex > sel.lastColumn) {
|
|
41
43
|
newCell.spanAbove = true;
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitTableCellVertically.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/splitTableCellVertically.ts"],"names":[],"mappings":";;;;AAAA,2EAA8D;AAC9D,
|
|
1
|
+
{"version":3,"file":"splitTableCellVertically.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/modelApi/table/splitTableCellVertically.ts"],"names":[],"mappings":";;;;AAAA,2EAA8D;AAC9D,6EAAgE;AAGhE,IAAM,UAAU,GAAG,EAAE,CAAC;AAEtB;;GAEG;AACH,SAAgB,wBAAwB,CAAC,KAAwB;IAC7D,IAAM,GAAG,GAAG,IAAA,+CAAgB,EAAC,KAAK,CAAC,CAAC;IAEpC,IAAI,GAAG,EAAE;QACL,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,QAAQ,IAAI,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE;YACnE,IAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACjC,IAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;YAE1C,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,UAAA,IAAI;gBAClB,OAAO,IAAI,CAAC,aAAa,CAAC;YAC9B,CAAC,CAAC,C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AC;yBAC5B;6BAAM;4BACH,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;yBACxC;wBAED,OAAO,OAAO,CAAC;oBACnB,CAAC,CAAC;iBACL,CAAC;gBAEF,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC;gBACvB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;aAC9C;SACJ;KACJ;AACL,CAAC;AA5DD,4DA4DC","sourcesContent":["import { createTableCell } from 'roosterjs-content-model-dom';\nimport { getSelectedCells } from 'roosterjs-content-model-core';\nimport type { ContentModelTable, ContentModelTableRow } from 'roosterjs-content-model-types';\n\nconst MIN_HEIGHT = 22;\n\n/**\n * @internal\n */\nexport function splitTableCellVertically(table: ContentModelTable) {\n const sel = getSelectedCells(table);\n\n if (sel) {\n for (let rowIndex = sel.lastRow; rowIndex >= sel.firstRow; rowIndex--) {\n const row = table.rows[rowIndex];\n const belowRow = table.rows[rowIndex + 1];\n\n row.cells.forEach(cell => {\n delete cell.cachedElement;\n });\n\n delete row.cachedElement;\n\n if (\n belowRow?.cells.every(\n (belowCell, colIndex) =>\n colIndex < sel.firstColumn ||\n colIndex > sel.lastColumn ||\n belowCell.spanAbove\n )\n ) {\n belowRow.cells.forEach((belowCell, colIndex) => {\n if (colIndex >= sel.firstColumn && colIndex <= sel.lastColumn) {\n belowCell.spanAbove = false;\n delete belowCell.cachedElement;\n }\n });\n\n delete belowRow.cachedElement;\n } else {\n const newHeight = Math.max((row.height /= 2), MIN_HEIGHT);\n const newRow: ContentModelTableRow = {\n format: { ...row.format },\n height: newHeight,\n cells: row.cells.map((cell, colIndex) => {\n const newCell = createTableCell(\n cell.spanLeft,\n cell.spanAbove,\n cell.isHeader,\n cell.format\n );\n\n newCell.dataset = { ...cell.dataset };\n\n if (colIndex < sel.firstColumn || colIndex > sel.lastColumn) {\n newCell.spanAbove = true;\n } else {\n newCell.isSelected = cell.isSelected;\n }\n\n return newCell;\n }),\n };\n\n row.height = newHeight;\n table.rows.splice(rowIndex + 1, 0, newRow);\n }\n }\n }\n}\n"]}
|
|
@@ -16,7 +16,13 @@ function getFormatState(editor) {
|
|
|
16
16
|
child: reducedModelChildProcessor,
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
|
-
var
|
|
19
|
+
var manager = editor.getSnapshotsManager();
|
|
20
|
+
var result = {
|
|
21
|
+
canUndo: manager.hasNewContent || manager.canMove(-1),
|
|
22
|
+
canRedo: manager.canMove(1),
|
|
23
|
+
isDarkMode: editor.isDarkMode(),
|
|
24
|
+
zoomScale: editor.getZoomScale(),
|
|
25
|
+
};
|
|
20
26
|
(0, retrieveModelFormatState_1.retrieveModelFormatState)(model, pendingFormat, result);
|
|
21
27
|
return result;
|
|
22
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";;;;AAAA,6EAAoE;AACpE,2FAA0F;AAQ1F,2EAKqC;AAErC;;;GAGG;AACH,SAAwB,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACpC,iBAAiB,EAAE;YACf,KAAK,EAAE,0BAA0B;SACpC;KACJ,CAAC,CAAC;IACH,IAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"getFormatState.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/format/getFormatState.ts"],"names":[],"mappings":";;;;AAAA,6EAAoE;AACpE,2FAA0F;AAQ1F,2EAKqC;AAErC;;;GAGG;AACH,SAAwB,cAAc,CAAC,MAAyB;IAC5D,IAAM,aAAa,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAChD,IAAM,KAAK,GAAG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AU,CAAC;IAE9B,OAAO,KAAK,IAAI,KAAK,IAAI,UAAU,EAAE;QACjC,KAAK,EAAE,CAAC;QACR,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;KAC7B;IACD,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { getSelectionRootNode } from 'roosterjs-content-model-core';\nimport { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState';\nimport type {\n IStandaloneEditor,\n ContentModelBlockGroup,\n ContentModelFormatState,\n DomToModelContext,\n} from 'roosterjs-content-model-types';\n\nimport {\n getRegularSelectionOffsets,\n handleRegularSelection,\n isNodeOfType,\n processChildNode,\n} from 'roosterjs-content-model-dom';\n\n/**\n * Get current format state\n * @param editor The editor to get format from\n */\nexport default function getFormatState(editor: IStandaloneEditor): ContentModelFormatState {\n const pendingFormat = editor.getPendingFormat();\n const model = editor.createContentModel({\n processorOverride: {\n child: reducedModelChildProcessor,\n },\n });\n const manager = editor.getSnapshotsManager();\n const result: ContentModelFormatState = {\n canUndo: manager.hasNewContent || manager.canMove(-1),\n canRedo: manager.canMove(1),\n isDarkMode: editor.isDarkMode(),\n zoomScale: editor.getZoomScale(),\n };\n\n retrieveModelFormatState(model, pendingFormat, result);\n\n return result;\n}\n\n/**\n * @internal\n */\ninterface FormatStateContext extends DomToModelContext {\n /**\n * An optional stack of parent elements to process. When provided, the child nodes of current parent element will be ignored,\n * but use the top element in this stack instead in childProcessor.\n */\n nodeStack?: Node[];\n}\n\n/**\n * @internal\n * Export for test only\n * In order to get format, we can still use the regular child processor. However, to improve performance, we don't need to create\n * content model for the whole doc, instead we only need to traverse the tree path that can arrive current selected node.\n * This \"reduced\" child processor will first create a node stack that stores DOM node from root to current common ancestor node of selection,\n * then use this stack as a faked DOM tree to create a reduced content model which we can use to retrieve format state\n */\nexport function reducedModelChildProcessor(\n group: ContentModelBlockGroup,\n parent: ParentNode,\n context: FormatStateContext\n) {\n if (!context.nodeStack) {\n const selectionRootNode = getSelectionRootNode(context.selection);\n context.nodeStack = selectionRootNode ? createNodeStack(parent, selectionRootNode) : [];\n }\n\n const stackChild = context.nodeStack.pop();\n\n if (stackChild) {\n const [nodeStartOffset, nodeEndOffset] = getRegularSelectionOffsets(context, parent);\n\n // If selection is not on this node, skip getting node index to save some time since we don't need it here\n const index =\n nodeStartOffset >= 0 || nodeEndOffset >= 0 ? getChildIndex(parent, stackChild) : -1;\n\n if (index >= 0) {\n handleRegularSelection(index, context, group, nodeStartOffset, nodeEndOffset);\n }\n\n processChildNode(group, stackChild, context);\n\n if (index >= 0) {\n handleRegularSelection(index + 1, context, group, nodeStartOffset, nodeEndOffset);\n }\n } else {\n // No child node from node stack, that means we have reached the deepest node of selection.\n // Now we can use default child processor to perform full sub tree scanning for content model,\n // So that all selected node will be included.\n context.defaultElementProcessors.child(group, parent, context);\n }\n}\n\nfunction createNodeStack(root: Node, startNode: Node): Node[] {\n const result: Node[] = [];\n let node: Node | null = startNode;\n\n while (node && root != node && root.contains(node)) {\n if (isNodeOfType(node, 'ELEMENT_NODE') && node.tagName == 'TABLE') {\n // For table, we can't do a reduced model creation since we need to handle their cells and indexes,\n // so clean up whatever we already have, and just put table into the stack\n result.splice(0, result.length, node);\n } else {\n result.push(node);\n }\n\n node = node.parentNode;\n }\n\n return result;\n}\n\nfunction getChildIndex(parent: ParentNode, stackChild: Node) {\n let index = 0;\n let child = parent.firstChild;\n\n while (child && child != stackChild) {\n index++;\n child = child.nextSibling;\n }\n return index;\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var formatImageWithContentModel_1 = require("../utils/formatImageWithContentModel");
|
|
4
|
-
var readFile_1 = require("../../modelApi/domUtils/readFile");
|
|
5
4
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
6
5
|
/**
|
|
7
6
|
* Change the selected image src
|
|
@@ -11,7 +10,7 @@ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
|
11
10
|
function changeImage(editor, file) {
|
|
12
11
|
editor.focus();
|
|
13
12
|
var selection = editor.getDOMSelection();
|
|
14
|
-
(0,
|
|
13
|
+
(0, roosterjs_content_model_core_1.readFile)(file, function (dataUrl) {
|
|
15
14
|
if (dataUrl && !editor.isDisposed() && (selection === null || selection === void 0 ? void 0 : selection.type) === 'image') {
|
|
16
15
|
(0, formatImageWithContentModel_1.default)(editor, 'changeImage', function (image) {
|
|
17
16
|
var _a, _b;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/changeImage.ts"],"names":[],"mappings":";;AAAA,oFAA+E;AAE/E,
|
|
1
|
+
{"version":3,"file":"changeImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/changeImage.ts"],"names":[],"mappings":";;AAAA,oFAA+E;AAE/E,6EAA6E;AAG7E;;;;GAIG;AACH,SAAwB,WAAW,CAAC,MAAyB,EAAE,IAAU;IACrE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAC3C,IAAA,uCAAQ,EAAC,IAAI,EAAE,UAAA,OAAO;QAClB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,MAAK,OAAO,EAAE;YAChE,IAAA,qCAA2B,EAAC,MAAM,EAAE,aAAa,EAAE,UAAC,KAAwB;;gBACxE,IAAM,WAAW,GAAG,MAAA,MAAA,IAAA,kDAAmB,EAAC,KAAK,CAAC,0CAAE,GAAG,mCAAI,EAAE,CAAC;gBAC1D,IAAM,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC;gBAE9B,KAAK,CAAC,GAAG,GAAG,OAAO,CAAC;gBACpB,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;gBACnB,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;gBACxB,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;gBACzB,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC;gBAEf,MAAM,CAAC,kBAAkB,qBAA4B;oBACjD,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,WAAW,aAAA;oBACX,MAAM,EAAE,OAAO;oBACf,WAAW,aAAA;iBACd,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;SACN;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAzBD,8BAyBC","sourcesContent":["import formatImageWithContentModel from '../utils/formatImageWithContentModel';\nimport { PluginEventType } from 'roosterjs-editor-types';\nimport { readFile, updateImageMetadata } from 'roosterjs-content-model-core';\nimport type { ContentModelImage, IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Change the selected image src\n * @param editor The editor instance\n * @param file The image file\n */\nexport default function changeImage(editor: IStandaloneEditor, file: File) {\n editor.focus();\n\n const selection = editor.getDOMSelection();\n readFile(file, dataUrl => {\n if (dataUrl && !editor.isDisposed() && selection?.type === 'image') {\n formatImageWithContentModel(editor, 'changeImage', (image: ContentModelImage) => {\n const originalSrc = updateImageMetadata(image)?.src ?? '';\n const previousSrc = image.src;\n\n image.src = dataUrl;\n image.dataset = {};\n image.format.width = '';\n image.format.height = '';\n image.alt = '';\n\n editor.triggerPluginEvent(PluginEventType.EditImage, {\n image: selection.image,\n previousSrc,\n newSrc: dataUrl,\n originalSrc,\n });\n });\n }\n });\n}\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
4
4
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
5
|
-
var readFile_1 = require("../../modelApi/domUtils/readFile");
|
|
6
5
|
/**
|
|
7
6
|
* Insert an image into current selected position
|
|
8
7
|
* @param editor The editor to operate on
|
|
@@ -14,7 +13,7 @@ function insertImage(editor, imageFileOrSrc) {
|
|
|
14
13
|
insertImageWithSrc(editor, imageFileOrSrc);
|
|
15
14
|
}
|
|
16
15
|
else {
|
|
17
|
-
(0,
|
|
16
|
+
(0, roosterjs_content_model_core_1.readFile)(imageFileOrSrc, function (dataUrl) {
|
|
18
17
|
if (dataUrl && !editor.isDisposed()) {
|
|
19
18
|
insertImageWithSrc(editor, dataUrl);
|
|
20
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/insertImage.ts"],"names":[],"mappings":";;AAAA,2EAAkG;AAClG,
|
|
1
|
+
{"version":3,"file":"insertImage.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/image/insertImage.ts"],"names":[],"mappings":";;AAAA,2EAAkG;AAClG,6EAAoE;AAGpE;;;;GAIG;AACH,SAAwB,WAAW,CAAC,MAAyB,EAAE,cAA6B;IACxF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAI,OAAO,cAAc,IAAI,QAAQ,EAAE;QACnC,kBAAkB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;KAC9C;SAAM;QACH,IAAA,uCAAQ,EAAC,cAAc,EAAE,UAAA,OAAO;YAC5B,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE;gBACjC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;aACvC;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAZD,8BAYC;AAED,SAAS,kBAAkB,CAAC,MAAyB,EAAE,GAAW;IAC9D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAM,KAAK,GAAG,IAAA,yCAAW,EAAC,GAAG,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;QACxD,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;QAEzC,IAAA,wCAAU,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACvB,IAAA,yCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;YAC5B,WAAW,EAAE,UAAU;SAC1B,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IAChB,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { addSegment, createContentModelDocument, createImage } from 'roosterjs-content-model-dom';\nimport { mergeModel, readFile } from 'roosterjs-content-model-core';\nimport type { IStandaloneEditor } from 'roosterjs-content-model-types';\n\n/**\n * Insert an image into current selected position\n * @param editor The editor to operate on\n * @param file Image Blob file or source string\n */\nexport default function insertImage(editor: IStandaloneEditor, imageFileOrSrc: File | string) {\n editor.focus();\n\n if (typeof imageFileOrSrc == 'string') {\n insertImageWithSrc(editor, imageFileOrSrc);\n } else {\n readFile(imageFileOrSrc, dataUrl => {\n if (dataUrl && !editor.isDisposed()) {\n insertImageWithSrc(editor, dataUrl);\n }\n });\n }\n}\n\nfunction insertImageWithSrc(editor: IStandaloneEditor, src: string) {\n editor.formatContentModel(\n (model, context) => {\n const image = createImage(src, { backgroundColor: '' });\n const doc = createContentModelDocument();\n\n addSegment(doc, image);\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n\n return true;\n },\n {\n apiName: 'insertImage',\n }\n );\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var getSelectedCells_1 = require("../../modelApi/table/getSelectedCells");
|
|
5
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
5
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
7
6
|
/**
|
|
@@ -14,7 +13,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
14
13
|
editor.formatContentModel(function (model) {
|
|
15
14
|
var _a = (0, tslib_1.__read)((0, roosterjs_content_model_core_1.getFirstSelectedTable)(model), 1), tableModel = _a[0];
|
|
16
15
|
if (tableModel) {
|
|
17
|
-
var sel = (0,
|
|
16
|
+
var sel = (0, roosterjs_content_model_core_1.getSelectedCells)(tableModel);
|
|
18
17
|
var perimeter = {
|
|
19
18
|
Top: false,
|
|
20
19
|
Bottom: false,
|
|
@@ -70,7 +69,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
70
69
|
'borderRight',
|
|
71
70
|
];
|
|
72
71
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
73
|
-
for (var colIndex = sel.
|
|
72
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
74
73
|
var cell = tableModel.rows[rowIndex].cells[colIndex];
|
|
75
74
|
// Format cells - All borders
|
|
76
75
|
applyBorderFormat(cell, borderFormat, allBorders);
|
|
@@ -85,7 +84,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
85
84
|
case 'leftBorders':
|
|
86
85
|
var leftBorder = ['borderLeft'];
|
|
87
86
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
88
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
87
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
89
88
|
// Format cells - Left border
|
|
90
89
|
applyBorderFormat(cell, borderFormat, leftBorder);
|
|
91
90
|
}
|
|
@@ -95,7 +94,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
95
94
|
case 'rightBorders':
|
|
96
95
|
var rightBorder = ['borderRight'];
|
|
97
96
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
98
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
97
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
99
98
|
// Format cells - Right border
|
|
100
99
|
applyBorderFormat(cell, borderFormat, rightBorder);
|
|
101
100
|
}
|
|
@@ -104,7 +103,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
104
103
|
break;
|
|
105
104
|
case 'topBorders':
|
|
106
105
|
var topBorder = ['borderTop'];
|
|
107
|
-
for (var colIndex = sel.
|
|
106
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
108
107
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
109
108
|
// Format cells - Top border
|
|
110
109
|
applyBorderFormat(cell, borderFormat, topBorder);
|
|
@@ -114,7 +113,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
114
113
|
break;
|
|
115
114
|
case 'bottomBorders':
|
|
116
115
|
var bottomBorder = ['borderBottom'];
|
|
117
|
-
for (var colIndex = sel.
|
|
116
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
118
117
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
119
118
|
// Format cells - Bottom border
|
|
120
119
|
applyBorderFormat(cell, borderFormat, bottomBorder);
|
|
@@ -124,7 +123,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
124
123
|
break;
|
|
125
124
|
case 'insideBorders':
|
|
126
125
|
// Format cells - Inside borders
|
|
127
|
-
var singleCol = sel.
|
|
126
|
+
var singleCol = sel.lastColumn == sel.firstColumn;
|
|
128
127
|
var singleRow = sel.lastRow == sel.firstRow;
|
|
129
128
|
// Single cell selection
|
|
130
129
|
if (singleCol && singleRow) {
|
|
@@ -132,41 +131,41 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
132
131
|
}
|
|
133
132
|
// Single column selection
|
|
134
133
|
if (singleCol) {
|
|
135
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
134
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom']);
|
|
136
135
|
for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
|
|
137
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
136
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
138
137
|
applyBorderFormat(cell, borderFormat, [
|
|
139
138
|
'borderTop',
|
|
140
139
|
'borderBottom',
|
|
141
140
|
]);
|
|
142
141
|
}
|
|
143
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
142
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop']);
|
|
144
143
|
break;
|
|
145
144
|
}
|
|
146
145
|
// Single row selection
|
|
147
146
|
if (singleRow) {
|
|
148
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
149
|
-
for (var colIndex = sel.
|
|
147
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderRight']);
|
|
148
|
+
for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
|
|
150
149
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
151
150
|
applyBorderFormat(cell, borderFormat, [
|
|
152
151
|
'borderLeft',
|
|
153
152
|
'borderRight',
|
|
154
153
|
]);
|
|
155
154
|
}
|
|
156
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
155
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderLeft']);
|
|
157
156
|
break;
|
|
158
157
|
}
|
|
159
158
|
// For multiple rows and columns selections
|
|
160
159
|
// Top left cell
|
|
161
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
160
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], borderFormat, ['borderBottom', 'borderRight']);
|
|
162
161
|
// Top right cell
|
|
163
|
-
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.
|
|
162
|
+
applyBorderFormat(tableModel.rows[sel.firstRow].cells[sel.lastColumn], borderFormat, ['borderBottom', 'borderLeft']);
|
|
164
163
|
// Bottom left cell
|
|
165
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
164
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], borderFormat, ['borderTop', 'borderRight']);
|
|
166
165
|
// Bottom right cell
|
|
167
|
-
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.
|
|
166
|
+
applyBorderFormat(tableModel.rows[sel.lastRow].cells[sel.lastColumn], borderFormat, ['borderTop', 'borderLeft']);
|
|
168
167
|
// First row
|
|
169
|
-
for (var colIndex = sel.
|
|
168
|
+
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
170
169
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
171
170
|
applyBorderFormat(cell, borderFormat, [
|
|
172
171
|
'borderBottom',
|
|
@@ -175,7 +174,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
175
174
|
]);
|
|
176
175
|
}
|
|
177
176
|
// Last row
|
|
178
|
-
for (var colIndex = sel.
|
|
177
|
+
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
179
178
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
180
179
|
applyBorderFormat(cell, borderFormat, [
|
|
181
180
|
'borderTop',
|
|
@@ -185,7 +184,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
185
184
|
}
|
|
186
185
|
// First column
|
|
187
186
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
188
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
187
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
189
188
|
applyBorderFormat(cell, borderFormat, [
|
|
190
189
|
'borderTop',
|
|
191
190
|
'borderBottom',
|
|
@@ -194,7 +193,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
194
193
|
}
|
|
195
194
|
// Last column
|
|
196
195
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
197
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
196
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
198
197
|
applyBorderFormat(cell, borderFormat, [
|
|
199
198
|
'borderTop',
|
|
200
199
|
'borderBottom',
|
|
@@ -202,9 +201,9 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
202
201
|
]);
|
|
203
202
|
}
|
|
204
203
|
// Inner cells
|
|
205
|
-
sel.
|
|
204
|
+
sel.firstColumn++;
|
|
206
205
|
sel.firstRow++;
|
|
207
|
-
sel.
|
|
206
|
+
sel.lastColumn--;
|
|
208
207
|
sel.lastRow--;
|
|
209
208
|
operations.push('allBorders');
|
|
210
209
|
break;
|
|
@@ -263,29 +262,29 @@ function applyBorderFormat(cell, borderFormat, positions) {
|
|
|
263
262
|
function modifyPerimeter(tableModel, sel, borderFormat, perimeter) {
|
|
264
263
|
// Top of selection
|
|
265
264
|
if (perimeter.Top && sel.firstRow - 1 >= 0) {
|
|
266
|
-
for (var colIndex = sel.
|
|
265
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
267
266
|
var cell = tableModel.rows[sel.firstRow - 1].cells[colIndex];
|
|
268
267
|
applyBorderFormat(cell, borderFormat, ['borderBottom']);
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
270
|
// Bottom of selection
|
|
272
271
|
if (perimeter.Bottom && sel.lastRow + 1 < tableModel.rows.length) {
|
|
273
|
-
for (var colIndex = sel.
|
|
272
|
+
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
274
273
|
var cell = tableModel.rows[sel.lastRow + 1].cells[colIndex];
|
|
275
274
|
applyBorderFormat(cell, borderFormat, ['borderTop']);
|
|
276
275
|
}
|
|
277
276
|
}
|
|
278
277
|
// Left of selection
|
|
279
|
-
if (perimeter.Left && sel.
|
|
278
|
+
if (perimeter.Left && sel.firstColumn - 1 >= 0) {
|
|
280
279
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
281
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
280
|
+
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn - 1];
|
|
282
281
|
applyBorderFormat(cell, borderFormat, ['borderRight']);
|
|
283
282
|
}
|
|
284
283
|
}
|
|
285
284
|
// Right of selection
|
|
286
|
-
if (perimeter.Right && sel.
|
|
285
|
+
if (perimeter.Right && sel.lastColumn + 1 < tableModel.rows[0].cells.length) {
|
|
287
286
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
288
|
-
var cell = tableModel.rows[rowIndex].cells[sel.
|
|
287
|
+
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn + 1];
|
|
289
288
|
applyBorderFormat(cell, borderFormat, ['borderLeft']);
|
|
290
289
|
}
|
|
291
290
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyTableBorderFormat.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/applyTableBorderFormat.ts"],"names":[],"mappings":";;;AAAA,0EAAyE;AACzE,2EAAiE;AACjE,6EAIsC;AA4BtC;;;;;GAKG;AACH,SAAwB,sBAAsB,CAC1C,MAAyB,EACzB,MAAc,EACd,SAA2B;IAE3B,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA,oBAAe,IAAA,oDAAqB,EAAC,KAAK,CAAC,IAAA,EAA1C,UAAU,QAAgC,CAAC;QAElD,IAAI,UAAU,EAAE;YACZ,IA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M,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC9D,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SACxD;KACJ;IACD,oBAAoB;IACpB,IAAI,SAAS,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,GAAG,CAAC,IAAI,CAAC,EAAE;QACzC,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;YAC/D,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;SAC1D;KACJ;IACD,qBAAqB;IACrB,IAAI,SAAS,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE;QACtE,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,IAAI,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YACnE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;YAC9D,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;SACzD;KACJ;AACL,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":";;;AAAA,2EAAiE;AACjE,6EAKsC;AA4BtC;;;;;GAKG;AACH,SAAwB,sBAAsB,CAC1C,MAAyB,EACzB,MA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C,CAAC;SACzD;KACJ;AACL,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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var hasSelectionInBlock_1 = require("../selection/hasSelectionInBlock");
|
|
5
4
|
var alignTable_1 = require("../../modelApi/table/alignTable");
|
|
6
5
|
var deleteTable_1 = require("../../modelApi/table/deleteTable");
|
|
7
6
|
var deleteTableColumn_1 = require("../../modelApi/table/deleteTableColumn");
|
|
@@ -78,7 +77,7 @@ function editTable(editor, operation) {
|
|
|
78
77
|
(0, splitTableCellVertically_1.splitTableCellVertically)(tableModel);
|
|
79
78
|
break;
|
|
80
79
|
}
|
|
81
|
-
if (!(0,
|
|
80
|
+
if (!(0, roosterjs_content_model_core_1.hasSelectionInBlock)(tableModel)) {
|
|
82
81
|
var paragraph = (0, ensureFocusableParagraphForTable_1.ensureFocusableParagraphForTable)(model, path, tableModel);
|
|
83
82
|
if (paragraph) {
|
|
84
83
|
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":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":";;;AAAA,8DAA6D;AAC7D,gEAA+D;AAC/D,4EAA2E;AAC3E,sEAAqE;AACrE,0GAAyG;AACzG,4EAA2E;AAC3E,sEAAqE;AACrE,wEAAuE;AACvE,0EAAyE;AACzE,oEAAmE;AACnE,8FAA6F;AAC7F,0FAAyF;AAEzF,6EAMsC;AAEtC,sEAG6C;AAC7C,2EAIqC;AAErC;;;;GAIG;AACH,SAAwB,SAAS,CAAC,MAAyB,EAAE,SAAyB;IAClF,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAA,KAAK;QACK,IAAA,KAAA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AAW,CAAC;gBACjB,KAAK,YAAY;oBACb,IAAA,mCAAgB,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBACxC,MAAM;gBAEV,KAAK,mBAAmB;oBACpB,IAAA,uDAA0B,EAAC,UAAU,CAAC,CAAC;oBACvC,MAAM;gBAEV,KAAK,iBAAiB;oBAClB,IAAA,mDAAwB,EAAC,UAAU,CAAC,CAAC;oBACrC,MAAM;aACb;YAED,IAAI,CAAC,IAAA,kDAAmB,EAAC,UAAU,CAAC,EAAE;gBAClC,IAAM,SAAS,GAAG,IAAA,mEAAgC,EAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;gBAE5E,IAAI,SAAS,EAAE;oBACX,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,KAAK,CAAC,MAAM,CAAC,CAAC;oBAEnD,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACnC,IAAA,qDAAuB,EAAC,SAAS,CAAC,CAAC;oBACnC,IAAA,2CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;aACJ;YAED,IAAA,6CAAc,EAAC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAEzC,IAAI,IAAA,yCAAW,EAAC,UAAU,CAAC,EAAE;gBACzB,IAAA,+CAAgB,EAAC,UAAU,EAAE,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;aACjF;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,WAAW;KACvB,CACJ,CAAC;AACN,CAAC;AAjGD,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,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
-
var hasSelectionInBlockGroup_1 = require("../selection/hasSelectionInBlockGroup");
|
|
5
4
|
var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
6
5
|
/**
|
|
7
6
|
* Set table cell shade color
|
|
@@ -16,7 +15,7 @@ function setTableCellShade(editor, color) {
|
|
|
16
15
|
(0, roosterjs_content_model_core_1.normalizeTable)(table);
|
|
17
16
|
table.rows.forEach(function (row) {
|
|
18
17
|
return row.cells.forEach(function (cell) {
|
|
19
|
-
if ((0,
|
|
18
|
+
if ((0, roosterjs_content_model_core_1.hasSelectionInBlockGroup)(cell)) {
|
|
20
19
|
(0, roosterjs_content_model_core_1.setTableCellBackgroundColor)(cell, color, true /*isColorOverride*/);
|
|
21
20
|
}
|
|
22
21
|
});
|