roosterjs-content-model-api 9.59.0 → 9.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/modelApi/table/mergeTableCells.js +36 -2
- package/lib/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib/modelApi/table/mergeTableColumn.js +1 -2
- package/lib/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib/modelApi/table/mergeTableRow.js +1 -2
- package/lib/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib/publicApi/link/insertLink.js +1 -2
- package/lib/publicApi/link/insertLink.js.map +1 -1
- package/lib/publicApi/table/applyTableBorderFormat.d.ts +1 -0
- package/lib/publicApi/table/applyTableBorderFormat.js +104 -26
- package/lib/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableCells.js +37 -2
- package/lib-amd/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableColumn.js +2 -2
- package/lib-amd/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-amd/modelApi/table/mergeTableRow.js +2 -2
- package/lib-amd/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-amd/publicApi/link/insertLink.js +2 -2
- package/lib-amd/publicApi/link/insertLink.js.map +1 -1
- package/lib-amd/publicApi/table/applyTableBorderFormat.d.ts +1 -0
- package/lib-amd/publicApi/table/applyTableBorderFormat.js +104 -26
- package/lib-amd/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableCells.js +36 -2
- package/lib-mjs/modelApi/table/mergeTableCells.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableColumn.js +1 -2
- package/lib-mjs/modelApi/table/mergeTableColumn.js.map +1 -1
- package/lib-mjs/modelApi/table/mergeTableRow.js +1 -2
- package/lib-mjs/modelApi/table/mergeTableRow.js.map +1 -1
- package/lib-mjs/publicApi/link/insertLink.js +2 -3
- package/lib-mjs/publicApi/link/insertLink.js.map +1 -1
- package/lib-mjs/publicApi/table/applyTableBorderFormat.d.ts +1 -0
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js +106 -28
- package/lib-mjs/publicApi/table/applyTableBorderFormat.js.map +1 -1
- package/package.json +3 -3
- package/lib/modelApi/table/canMergeCells.d.ts +0 -5
- package/lib/modelApi/table/canMergeCells.js +0 -57
- package/lib/modelApi/table/canMergeCells.js.map +0 -1
- package/lib/publicApi/utils/checkXss.d.ts +0 -8
- package/lib/publicApi/utils/checkXss.js +0 -15
- package/lib/publicApi/utils/checkXss.js.map +0 -1
- package/lib-amd/modelApi/table/canMergeCells.d.ts +0 -5
- package/lib-amd/modelApi/table/canMergeCells.js +0 -59
- package/lib-amd/modelApi/table/canMergeCells.js.map +0 -1
- package/lib-amd/publicApi/utils/checkXss.d.ts +0 -8
- package/lib-amd/publicApi/utils/checkXss.js +0 -17
- package/lib-amd/publicApi/utils/checkXss.js.map +0 -1
- package/lib-mjs/modelApi/table/canMergeCells.d.ts +0 -5
- package/lib-mjs/modelApi/table/canMergeCells.js +0 -53
- package/lib-mjs/modelApi/table/canMergeCells.js.map +0 -1
- package/lib-mjs/publicApi/utils/checkXss.d.ts +0 -8
- package/lib-mjs/publicApi/utils/checkXss.js +0 -11
- package/lib-mjs/publicApi/utils/checkXss.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeTableCells = void 0;
|
|
4
|
-
var canMergeCells_1 = require("./canMergeCells");
|
|
5
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
@@ -9,7 +8,16 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
9
8
|
function mergeTableCells(table) {
|
|
10
9
|
var sel = (0, roosterjs_content_model_dom_1.getSelectedCells)(table);
|
|
11
10
|
if (sel &&
|
|
12
|
-
(0,
|
|
11
|
+
(0, roosterjs_content_model_dom_1.canMergeCells)(table.rows, sel.firstRow, sel.firstColumn, sel.lastRow, sel.lastColumn)) {
|
|
12
|
+
var firstCell = (0, roosterjs_content_model_dom_1.mutateBlock)(table.rows[sel.firstRow].cells[sel.firstColumn]);
|
|
13
|
+
var borderTop = getHorizontalBorder(table, sel.firstRow, sel, 'borderTop');
|
|
14
|
+
var borderRight = getVerticalBorder(table, sel.lastColumn, sel, 'borderRight');
|
|
15
|
+
var borderBottom = getHorizontalBorder(table, sel.lastRow, sel, 'borderBottom');
|
|
16
|
+
var borderLeft = getVerticalBorder(table, sel.firstColumn, sel, 'borderLeft');
|
|
17
|
+
setBorder(firstCell.format, 'borderTop', borderTop);
|
|
18
|
+
setBorder(firstCell.format, 'borderRight', borderRight);
|
|
19
|
+
setBorder(firstCell.format, 'borderBottom', borderBottom);
|
|
20
|
+
setBorder(firstCell.format, 'borderLeft', borderLeft);
|
|
13
21
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
14
22
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
15
23
|
var cell = table.rows[rowIndex].cells[colIndex];
|
|
@@ -23,4 +31,30 @@ function mergeTableCells(table) {
|
|
|
23
31
|
}
|
|
24
32
|
}
|
|
25
33
|
exports.mergeTableCells = mergeTableCells;
|
|
34
|
+
function getHorizontalBorder(table, rowIndex, sel, borderKey) {
|
|
35
|
+
var border = table.rows[rowIndex].cells[sel.firstColumn].format[borderKey];
|
|
36
|
+
return border &&
|
|
37
|
+
table.rows[rowIndex].cells
|
|
38
|
+
.slice(sel.firstColumn, sel.lastColumn + 1)
|
|
39
|
+
.every(function (cell) { return cell.format[borderKey] == border; })
|
|
40
|
+
? border
|
|
41
|
+
: undefined;
|
|
42
|
+
}
|
|
43
|
+
function getVerticalBorder(table, columnIndex, sel, borderKey) {
|
|
44
|
+
var border = table.rows[sel.firstRow].cells[columnIndex].format[borderKey];
|
|
45
|
+
return border &&
|
|
46
|
+
table.rows
|
|
47
|
+
.slice(sel.firstRow, sel.lastRow + 1)
|
|
48
|
+
.every(function (row) { return row.cells[columnIndex].format[borderKey] == border; })
|
|
49
|
+
? border
|
|
50
|
+
: undefined;
|
|
51
|
+
}
|
|
52
|
+
function setBorder(format, borderKey, border) {
|
|
53
|
+
if (border) {
|
|
54
|
+
format[borderKey] = border;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
delete format[borderKey];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
26
60
|
//# sourceMappingURL=mergeTableCells.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTableCells.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableCells.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"mergeTableCells.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableCells.ts"],"names":[],"mappings":";;;AAAA,2EAA2F;AAO3F;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAsC;IAClE,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IAEpC,IACI,GAAG;QACH,IAAA,2CAAa,EAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,UAAU,CAAC,EACvF;QACE,IAAM,SAAS,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;QAC/E,IAAM,SAAS,GAAG,mBAAmB,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;QAC7E,IAAM,WAAW,GAAG,iBAA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ourcesContent":["import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';\nimport type {\n BorderKey,\n ContentModelTableCellFormat,\n ShallowMutableContentModelTable,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function mergeTableCells(table: ShallowMutableContentModelTable) {\n const sel = getSelectedCells(table);\n\n if (\n sel &&\n canMergeCells(table.rows, sel.firstRow, sel.firstColumn, sel.lastRow, sel.lastColumn)\n ) {\n const firstCell = mutateBlock(table.rows[sel.firstRow].cells[sel.firstColumn]);\n const borderTop = getHorizontalBorder(table, sel.firstRow, sel, 'borderTop');\n const borderRight = getVerticalBorder(table, sel.lastColumn, sel, 'borderRight');\n const borderBottom = getHorizontalBorder(table, sel.lastRow, sel, 'borderBottom');\n const borderLeft = getVerticalBorder(table, sel.firstColumn, sel, 'borderLeft');\n\n setBorder(firstCell.format, 'borderTop', borderTop);\n setBorder(firstCell.format, 'borderRight', borderRight);\n setBorder(firstCell.format, 'borderBottom', borderBottom);\n setBorder(firstCell.format, 'borderLeft', borderLeft);\n\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = table.rows[rowIndex].cells[colIndex];\n\n if (cell) {\n const mutableCell = mutateBlock(cell);\n\n mutableCell.spanLeft = colIndex > sel.firstColumn;\n mutableCell.spanAbove = rowIndex > sel.firstRow;\n }\n }\n }\n }\n}\n\nfunction getHorizontalBorder(\n table: ShallowMutableContentModelTable,\n rowIndex: number,\n sel: { firstColumn: number; lastColumn: number },\n borderKey: BorderKey\n) {\n const border = table.rows[rowIndex].cells[sel.firstColumn].format[borderKey];\n\n return border &&\n table.rows[rowIndex].cells\n .slice(sel.firstColumn, sel.lastColumn + 1)\n .every(cell => cell.format[borderKey] == border)\n ? border\n : undefined;\n}\n\nfunction getVerticalBorder(\n table: ShallowMutableContentModelTable,\n columnIndex: number,\n sel: { firstRow: number; lastRow: number },\n borderKey: BorderKey\n) {\n const border = table.rows[sel.firstRow].cells[columnIndex].format[borderKey];\n\n return border &&\n table.rows\n .slice(sel.firstRow, sel.lastRow + 1)\n .every(row => row.cells[columnIndex].format[borderKey] == border)\n ? border\n : undefined;\n}\n\nfunction setBorder(\n format: ContentModelTableCellFormat,\n borderKey: BorderKey,\n border: string | undefined\n) {\n if (border) {\n format[borderKey] = border;\n } else {\n delete format[borderKey];\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeTableColumn = void 0;
|
|
4
|
-
var canMergeCells_1 = require("./canMergeCells");
|
|
5
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
@@ -16,7 +15,7 @@ function mergeTableColumn(table, operation) {
|
|
|
16
15
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
17
16
|
var cell = (_a = table.rows[rowIndex]) === null || _a === void 0 ? void 0 : _a.cells[mergingColIndex];
|
|
18
17
|
if (cell &&
|
|
19
|
-
(0,
|
|
18
|
+
(0, roosterjs_content_model_dom_1.canMergeCells)(table.rows, rowIndex, mergingColIndex - 1, rowIndex, mergingColIndex)) {
|
|
20
19
|
(0, roosterjs_content_model_dom_1.mutateBlock)(cell).spanLeft = true;
|
|
21
20
|
var newSelectedCol = mergingColIndex;
|
|
22
21
|
while ((_c = (_b = table.rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.cells[newSelectedCol]) === null || _c === void 0 ? void 0 : _c.spanLeft) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTableColumn.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableColumn.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"mergeTableColumn.js","sourceRoot":"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;oBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,0CAAE,KAAK,CAAC,cAAc,CAAC,CAAC;oBAC5D,IAAI,OAAO,EAAE;wBACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC;AAzCD,4CAyCC","sourcesContent":["import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\n TableHorizontalMergeOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function mergeTableColumn(\n table: ShallowMutableContentModelTable,\n operation: TableHorizontalMergeOperation\n) {\n const sel = getSelectedCells(table);\n const mergeLeft = operation == 'mergeLeft';\n\n if (sel) {\n const mergingColIndex = mergeLeft ? sel.firstColumn : sel.lastColumn + 1;\n\n if (mergingColIndex > 0 && mergingColIndex < table.rows[0].cells.length) {\n for (let rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {\n const cell = table.rows[rowIndex]?.cells[mergingColIndex];\n\n if (\n cell &&\n canMergeCells(\n table.rows,\n rowIndex,\n mergingColIndex - 1,\n rowIndex,\n mergingColIndex\n )\n ) {\n mutateBlock(cell).spanLeft = true;\n\n let newSelectedCol = mergingColIndex;\n\n while (table.rows[rowIndex]?.cells[newSelectedCol]?.spanLeft) {\n mutateBlock(table.rows[rowIndex].cells[newSelectedCol]);\n newSelectedCol--;\n }\n\n const newCell = table.rows[rowIndex]?.cells[newSelectedCol];\n if (newCell) {\n mutateBlock(newCell).isSelected = true;\n }\n }\n }\n }\n }\n}\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeTableRow = void 0;
|
|
4
|
-
var canMergeCells_1 = require("./canMergeCells");
|
|
5
4
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
@@ -16,7 +15,7 @@ function mergeTableRow(table, operation) {
|
|
|
16
15
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
17
16
|
var cell = table.rows[mergingRowIndex].cells[colIndex];
|
|
18
17
|
if (cell &&
|
|
19
|
-
(0,
|
|
18
|
+
(0, roosterjs_content_model_dom_1.canMergeCells)(table.rows, mergingRowIndex - 1, colIndex, mergingRowIndex, colIndex)) {
|
|
20
19
|
(0, roosterjs_content_model_dom_1.mutateBlock)(cell).spanAbove = true;
|
|
21
20
|
var newSelectedRow = mergingRowIndex;
|
|
22
21
|
while ((_b = (_a = table.rows[newSelectedRow]) === null || _a === void 0 ? void 0 : _a.cells[colIndex]) === null || _b === void 0 ? void 0 : _b.spanAbove) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableRow.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"mergeTableRow.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/table/mergeTableRow.ts"],"names":[],"mappings":";;;AAAA,2EAA2F;AAM3F;;GAEG;AACH,SAAgB,aAAa,CACzB,KAAsC,EACtC,SAAsC;;IAEtC,IAAM,GAAG,GAAG,IAAA,8CAAgB,EAAC,KAAK,CAAC,CAAC;IACpC,IAAM,UAAU,GAAG,SAAS,IAAI,YAAY,CAAC;IAE7C,IAAI,GAAG,EAAE;QACL,IAAM,eAAe,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC;QAEpE,IAAI,eAAe,GAAG,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE;YAC5D,KAAK,IAAI,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,QAAQ,IAAI,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,EAAE;gBACzE,IAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAEzD,IACI,IAAI;oBACJ,IAAA,2CAAa,EACT,KAAK,CAAC,IAAI,EACV,eAAe,GAAG,CAAC,EACnB,QAAQ,EACR,eAAe,EACf,QAAQ,CACX,EACH;oBACE,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC;oBAEnC,IAAI,cAAc,GAAG,eAAe,CAAC;oBAErC,OAAO,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,0CAAE,SAAS,EAAE;wBAC3D,IAAA,yCAAW,EAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACxD,cAAc,EAAE,CAAC;qBACpB;oBAED,IAAM,OAAO,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,0CAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;oBAE5D,IAAI,OAAO,EAAE;wBACT,IAAA,yCAAW,EAAC,OAAO,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC;qBAC1C;iBACJ;aACJ;SACJ;KACJ;AACL,CAAC;AA1CD,sCA0CC","sourcesContent":["import { getSelectedCells, mutateBlock, canMergeCells } from 'roosterjs-content-model-dom';\nimport type {\n ShallowMutableContentModelTable,\n TableVerticalMergeOperation,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function mergeTableRow(\n table: ShallowMutableContentModelTable,\n operation: TableVerticalMergeOperation\n) {\n const sel = getSelectedCells(table);\n const mergeAbove = operation == 'mergeAbove';\n\n if (sel) {\n const mergingRowIndex = mergeAbove ? sel.firstRow : sel.lastRow + 1;\n\n if (mergingRowIndex > 0 && mergingRowIndex < table.rows.length) {\n for (let colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {\n const cell = table.rows[mergingRowIndex].cells[colIndex];\n\n if (\n cell &&\n canMergeCells(\n table.rows,\n mergingRowIndex - 1,\n colIndex,\n mergingRowIndex,\n colIndex\n )\n ) {\n mutateBlock(cell).spanAbove = true;\n\n let newSelectedRow = mergingRowIndex;\n\n while (table.rows[newSelectedRow]?.cells[colIndex]?.spanAbove) {\n mutateBlock(table.rows[newSelectedRow].cells[colIndex]);\n newSelectedRow--;\n }\n\n const newCell = table.rows[newSelectedRow]?.cells[colIndex];\n\n if (newCell) {\n mutateBlock(newCell).isSelected = true;\n }\n }\n }\n }\n }\n}\n"]}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.insertLink = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var adjustTrailingSpaceSelection_1 = require("../../modelApi/selection/adjustTrailingSpaceSelection");
|
|
6
|
-
var checkXss_1 = require("../utils/checkXss");
|
|
7
6
|
var matchLink_1 = require("../../modelApi/link/matchLink");
|
|
8
7
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
9
8
|
// Regex matching Uri scheme
|
|
@@ -27,7 +26,7 @@ var FTP_REGEX = /^ftp\./i;
|
|
|
27
26
|
*/
|
|
28
27
|
function insertLink(editor, link, anchorTitle, displayText, target) {
|
|
29
28
|
editor.focus();
|
|
30
|
-
var url = ((0,
|
|
29
|
+
var url = ((0, roosterjs_content_model_dom_1.isUnsafeUrl)(link) ? '' : link || '').trim();
|
|
31
30
|
if (url) {
|
|
32
31
|
var linkData_1 = (0, matchLink_1.matchLink)(url);
|
|
33
32
|
var linkUrl_1 = linkData_1 ? linkData_1.normalizedUrl : applyLinkPrefix(url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;;AAAA,sGAAqG;AACrG,
|
|
1
|
+
{"version":3,"file":"insertLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/link/insertLink.ts"],"names":[],"mappings":";;;;AAAA,sGAAqG;AACrG,2DAA0D;AAC1D,2EASqC;AAGrC,4BAA4B;AAC5B,IAAM,SAAS,GAAG,cAAc,CAAC;AACjC,wCAAwC;AACxC,IAAM,YAAY,GAAG,cAAc,CAAC;AACpC,sDAAsD;AACtD,IAAM,SAAS,GAAG,SAAS,CAAC;AAE5B;;;;;;;;;;;;GAYG;AACH,SAAgB,UAAU,CACtB,MAAe,EACf,IAAY,EACZ,WAAoB,EACpB,WAAoB,EACpB,MAAe;IAEf,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAM,GAAG,GAAG,CAAC,IAAA,yCAAW,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACzD,IAAI,GAAG,EAAE;QACL,IAAM,UAAQ,GAAG,IAAA,qBAAS,EAAC,GAAG,CAAC,CAAC;QAChC,IAAM,SAAO,GAAG,UAAQ,CAAC,CAAC,CAAC,UAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACzE,IAAM,OAAK,GAAuB,EAAE,CAAC;QACrC,IAAI,YAA4B,CAAC;QAEjC,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,QAAQ,GAAG,IAAA,iDAAmB,EAChC,KAAK,EACL,KAAK,CAAC,yBAAyB,EAC/B,IAAI,CAAC,UAAU,CAClB,CAAC;YAEF,IAAM,YAAY,GAAG,QAAQ;iBACxB,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CA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C,GAAG,EAAE;QACN,OAAO,GAAG,CAAC;KACd;IAED,4BAA4B;IAC5B,oEAAoE;IACpE,iEAAiE;IACjE,qDAAqD;IACrD,+BAA+B;IAC/B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;QAC3B,IAAI,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,GAAG,SAAS,CAAC;SACtB;aAAM,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YACnC,MAAM,GAAG,QAAQ,CAAC;SACrB;aAAM;YACH,sBAAsB;YACtB,MAAM,GAAG,SAAS,CAAC;SACtB;KACJ;IAED,OAAO,MAAM,GAAG,GAAG,CAAC;AACxB,CAAC","sourcesContent":["import { adjustTrailingSpaceSelection } from '../../modelApi/selection/adjustTrailingSpaceSelection';\nimport { matchLink } from '../../modelApi/link/matchLink';\nimport {\n addLink,\n addSegment,\n ChangeSource,\n createContentModelDocument,\n createText,\n getSelectedSegments,\n isUnsafeUrl,\n mergeModel,\n} from 'roosterjs-content-model-dom';\nimport type { ContentModelLink, IEditor } from 'roosterjs-content-model-types';\n\n// Regex matching Uri scheme\nconst URI_REGEX = /^[a-zA-Z]+:/i;\n// Regex matching begin of email address\nconst MAILTO_REGEX = /^[\\w.%+-]+@/i;\n// Regex matching begin of ftp, i.e. ftp.microsoft.com\nconst FTP_REGEX = /^ftp\\./i;\n\n/**\n * Insert a hyperlink at cursor.\n * When there is a selection, hyperlink will be applied to the selection,\n * otherwise a hyperlink will be inserted to the cursor position.\n * @param editor Editor object\n * @param link Link address, can be http(s), mailto, notes, file, unc, ftp, news, telnet, gopher, wais.\n * When protocol is not specified, a best matched protocol will be predicted.\n * @param anchorTitle Optional alt text of the link, will be shown when hover on the link\n * @param displayText Optional display text for the link.\n * @param target Optional display target for the link (\"_blank\"|\"_self\"|\"_parent\"|\"_top\"|\"{framename}\")\n * If specified, the display text of link will be replaced with this text.\n * If not specified and there wasn't a link, the link url will be used as display text.\n */\nexport function insertLink(\n editor: IEditor,\n link: string,\n anchorTitle?: string,\n displayText?: string,\n target?: string\n) {\n editor.focus();\n\n const url = (isUnsafeUrl(link) ? '' : link || '').trim();\n if (url) {\n const linkData = matchLink(url);\n const linkUrl = linkData ? linkData.normalizedUrl : applyLinkPrefix(url);\n const links: ContentModelLink[] = [];\n let anchorNode: Node | undefined;\n\n editor.formatContentModel(\n (model, context) => {\n const segments = getSelectedSegments(\n model,\n false /*includingFormatHolder*/,\n true /*mutate*/\n );\n\n const originalText = segments\n .map(x => (x.segmentType == 'Text' ? x.text : ''))\n .join('');\n const text = displayText || originalText || '';\n\n if (\n (segments.some(x => x.segmentType != 'SelectionMarker') &&\n originalText == text) ||\n (segments.length == 1 && segments[0].segmentType == 'Image')\n ) {\n segments.forEach(x => {\n const link = createLink(\n linkUrl,\n anchorTitle,\n target,\n x.segmentType == 'Text'\n );\n addLink(x, link);\n if (x.link) {\n links.push(x.link);\n }\n });\n } else if (\n segments.every(x => x.segmentType == 'SelectionMarker') ||\n (!!text && text != originalText)\n ) {\n const segment = createText(text || (linkData ? linkData.originalUrl : url), {\n ...segments[0]?.format,\n ...editor.getPendingFormat(),\n });\n const doc = createContentModelDocument();\n const link = createLink(linkUrl, anchorTitle, target);\n\n addLink(segment, link);\n addSegment(doc, segment);\n\n if (segment.link) {\n links.push(segment.link);\n }\n\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n }\n\n adjustTrailingSpaceSelection(model);\n return segments.length > 0;\n },\n {\n changeSource: ChangeSource.CreateLink,\n onNodeCreated: (modelElement, node) => {\n if (!anchorNode && links.indexOf(modelElement as ContentModelLink) >= 0) {\n anchorNode = node;\n }\n },\n getChangeData: () => anchorNode,\n apiName: 'insertLink',\n }\n );\n }\n}\n\nconst createLink = (\n url: string,\n anchorTitle?: string,\n target?: string,\n underline: boolean = true\n): ContentModelLink => {\n return {\n dataset: {},\n format: {\n href: url,\n anchorTitle,\n target,\n underline: underline,\n },\n };\n};\n\nfunction applyLinkPrefix(url: string): string {\n if (!url) {\n return url;\n }\n\n // Add link prefix per rule:\n // (a) if the url always starts with a URI scheme, leave it as it is\n // (b) if the url is an email address, xxx@... add mailto: prefix\n // (c) if the url starts with ftp., add ftp:// prefix\n // (d) rest, add http:// prefix\n let prefix = '';\n if (url.search(URI_REGEX) < 0) {\n if (url.search(MAILTO_REGEX) == 0) {\n prefix = 'mailto:';\n } else if (url.search(FTP_REGEX) == 0) {\n prefix = 'ftp://';\n } else {\n // fallback to http://\n prefix = 'http://';\n }\n }\n\n return prefix + url;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IEditor, Border, BorderOperations } from 'roosterjs-content-model-types';
|
|
2
2
|
/**
|
|
3
3
|
* Operations to apply border
|
|
4
|
+
* Remove the targeted borders instead if they all already match the requested format.
|
|
4
5
|
* @param editor The editor instance
|
|
5
6
|
* @param border The border to apply
|
|
6
7
|
* @param operation The operation to apply
|
|
@@ -5,13 +5,15 @@ var tslib_1 = require("tslib");
|
|
|
5
5
|
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
6
6
|
/**
|
|
7
7
|
* Operations to apply border
|
|
8
|
+
* Remove the targeted borders instead if they all already match the requested format.
|
|
8
9
|
* @param editor The editor instance
|
|
9
10
|
* @param border The border to apply
|
|
10
11
|
* @param operation The operation to apply
|
|
11
12
|
*/
|
|
12
13
|
function applyTableBorderFormat(editor, border, operation) {
|
|
13
14
|
editor.formatContentModel(function (model) {
|
|
14
|
-
var
|
|
15
|
+
var e_1, _a;
|
|
16
|
+
var _b = (0, tslib_1.__read)((0, roosterjs_content_model_dom_1.getFirstSelectedTable)(model), 1), tableModel = _b[0];
|
|
15
17
|
if (tableModel) {
|
|
16
18
|
var sel = (0, roosterjs_content_model_dom_1.getSelectedCells)(tableModel);
|
|
17
19
|
var perimeter = {
|
|
@@ -55,6 +57,10 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
55
57
|
// undefined is treated as Left to Right
|
|
56
58
|
var isRtl = tableModel.format.direction == 'rtl';
|
|
57
59
|
if (sel) {
|
|
60
|
+
var borderUpdates_2 = [];
|
|
61
|
+
var collectBorderFormat = function (cell, positions) {
|
|
62
|
+
borderUpdates_2.push({ cell: cell, positions: positions });
|
|
63
|
+
};
|
|
58
64
|
var operations = [operation];
|
|
59
65
|
while (operations.length) {
|
|
60
66
|
switch (operations.pop()) {
|
|
@@ -74,7 +80,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
74
80
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
75
81
|
var cell = tableModel.rows[rowIndex].cells[colIndex];
|
|
76
82
|
// Format cells - All borders
|
|
77
|
-
|
|
83
|
+
collectBorderFormat(cell, allBorders);
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
// Format perimeter
|
|
@@ -88,7 +94,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
88
94
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
89
95
|
var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.lastColumn : sel.firstColumn];
|
|
90
96
|
// Format cells - Left border
|
|
91
|
-
|
|
97
|
+
collectBorderFormat(cell, leftBorder);
|
|
92
98
|
}
|
|
93
99
|
// Format perimeter
|
|
94
100
|
isRtl ? (perimeter.Right = true) : (perimeter.Left = true);
|
|
@@ -98,7 +104,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
98
104
|
for (var rowIndex = sel.firstRow; rowIndex <= sel.lastRow; rowIndex++) {
|
|
99
105
|
var cell = tableModel.rows[rowIndex].cells[isRtl ? sel.firstColumn : sel.lastColumn];
|
|
100
106
|
// Format cells - Right border
|
|
101
|
-
|
|
107
|
+
collectBorderFormat(cell, rightBorder);
|
|
102
108
|
}
|
|
103
109
|
// Format perimeter
|
|
104
110
|
isRtl ? (perimeter.Left = true) : (perimeter.Right = true);
|
|
@@ -108,7 +114,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
108
114
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
109
115
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
110
116
|
// Format cells - Top border
|
|
111
|
-
|
|
117
|
+
collectBorderFormat(cell, topBorder);
|
|
112
118
|
}
|
|
113
119
|
// Format perimeter
|
|
114
120
|
perimeter.Top = true;
|
|
@@ -118,7 +124,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
118
124
|
for (var colIndex = sel.firstColumn; colIndex <= sel.lastColumn; colIndex++) {
|
|
119
125
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
120
126
|
// Format cells - Bottom border
|
|
121
|
-
|
|
127
|
+
collectBorderFormat(cell, bottomBorder);
|
|
122
128
|
}
|
|
123
129
|
// Format perimeter
|
|
124
130
|
perimeter.Bottom = true;
|
|
@@ -133,43 +139,37 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
133
139
|
}
|
|
134
140
|
// Single column selection
|
|
135
141
|
if (singleCol) {
|
|
136
|
-
|
|
142
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[sel.firstColumn], ['borderBottom']);
|
|
137
143
|
for (var rowIndex = sel.firstRow + 1; rowIndex <= sel.lastRow - 1; rowIndex++) {
|
|
138
144
|
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
139
|
-
|
|
140
|
-
'borderTop',
|
|
141
|
-
'borderBottom',
|
|
142
|
-
]);
|
|
145
|
+
collectBorderFormat(cell, ['borderTop', 'borderBottom']);
|
|
143
146
|
}
|
|
144
|
-
|
|
147
|
+
collectBorderFormat(tableModel.rows[sel.lastRow].cells[sel.firstColumn], ['borderTop']);
|
|
145
148
|
break;
|
|
146
149
|
}
|
|
147
150
|
// Single row selection
|
|
148
151
|
if (singleRow) {
|
|
149
|
-
|
|
152
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderRight']);
|
|
150
153
|
for (var colIndex = sel.firstColumn + 1; colIndex <= sel.lastColumn - 1; colIndex++) {
|
|
151
154
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
152
|
-
|
|
153
|
-
'borderLeft',
|
|
154
|
-
'borderRight',
|
|
155
|
-
]);
|
|
155
|
+
collectBorderFormat(cell, ['borderLeft', 'borderRight']);
|
|
156
156
|
}
|
|
157
|
-
|
|
157
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderLeft']);
|
|
158
158
|
break;
|
|
159
159
|
}
|
|
160
160
|
// For multiple rows and columns selections
|
|
161
161
|
// Top left cell
|
|
162
|
-
|
|
162
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderBottom', 'borderRight']);
|
|
163
163
|
// Top right cell
|
|
164
|
-
|
|
164
|
+
collectBorderFormat(tableModel.rows[sel.firstRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderBottom', 'borderLeft']);
|
|
165
165
|
// Bottom left cell
|
|
166
|
-
|
|
166
|
+
collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.lastColumn : sel.firstColumn], ['borderTop', 'borderRight']);
|
|
167
167
|
// Bottom right cell
|
|
168
|
-
|
|
168
|
+
collectBorderFormat(tableModel.rows[sel.lastRow].cells[isRtl ? sel.firstColumn : sel.lastColumn], ['borderTop', 'borderLeft']);
|
|
169
169
|
// First row
|
|
170
170
|
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
171
171
|
var cell = tableModel.rows[sel.firstRow].cells[colIndex];
|
|
172
|
-
|
|
172
|
+
collectBorderFormat(cell, [
|
|
173
173
|
'borderBottom',
|
|
174
174
|
'borderLeft',
|
|
175
175
|
'borderRight',
|
|
@@ -178,7 +178,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
178
178
|
// Last row
|
|
179
179
|
for (var colIndex = sel.firstColumn + 1; colIndex < sel.lastColumn; colIndex++) {
|
|
180
180
|
var cell = tableModel.rows[sel.lastRow].cells[colIndex];
|
|
181
|
-
|
|
181
|
+
collectBorderFormat(cell, [
|
|
182
182
|
'borderTop',
|
|
183
183
|
'borderLeft',
|
|
184
184
|
'borderRight',
|
|
@@ -187,7 +187,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
187
187
|
// First column
|
|
188
188
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
189
189
|
var cell = tableModel.rows[rowIndex].cells[sel.firstColumn];
|
|
190
|
-
|
|
190
|
+
collectBorderFormat(cell, [
|
|
191
191
|
'borderTop',
|
|
192
192
|
'borderBottom',
|
|
193
193
|
isRtl ? 'borderLeft' : 'borderRight',
|
|
@@ -196,7 +196,7 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
196
196
|
// Last column
|
|
197
197
|
for (var rowIndex = sel.firstRow + 1; rowIndex < sel.lastRow; rowIndex++) {
|
|
198
198
|
var cell = tableModel.rows[rowIndex].cells[sel.lastColumn];
|
|
199
|
-
|
|
199
|
+
collectBorderFormat(cell, [
|
|
200
200
|
'borderTop',
|
|
201
201
|
'borderBottom',
|
|
202
202
|
isRtl ? 'borderRight' : 'borderLeft',
|
|
@@ -220,6 +220,26 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
220
220
|
break;
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
+
// Compare before changing any cells, and only consider borders targeted by
|
|
224
|
+
// this operation. Normalize CSS so DOM colors (rgb) also match hex input.
|
|
225
|
+
if (operation != 'noBorders' &&
|
|
226
|
+
borderUpdates_2.length > 0 &&
|
|
227
|
+
hasMatchingBorders(borderUpdates_2, borderFormat)) {
|
|
228
|
+
borderFormat = '';
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
for (var borderUpdates_1 = (0, tslib_1.__values)(borderUpdates_2), borderUpdates_1_1 = borderUpdates_1.next(); !borderUpdates_1_1.done; borderUpdates_1_1 = borderUpdates_1.next()) {
|
|
232
|
+
var _c = borderUpdates_1_1.value, cell = _c.cell, positions = _c.positions;
|
|
233
|
+
applyBorderFormat(cell, borderFormat, positions);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
237
|
+
finally {
|
|
238
|
+
try {
|
|
239
|
+
if (borderUpdates_1_1 && !borderUpdates_1_1.done && (_a = borderUpdates_1.return)) _a.call(borderUpdates_1);
|
|
240
|
+
}
|
|
241
|
+
finally { if (e_1) throw e_1.error; }
|
|
242
|
+
}
|
|
223
243
|
//Format perimeter if necessary or possible
|
|
224
244
|
modifyPerimeter(tableModel, sel, borderFormat, perimeter, isRtl);
|
|
225
245
|
}
|
|
@@ -238,6 +258,64 @@ function applyTableBorderFormat(editor, border, operation) {
|
|
|
238
258
|
});
|
|
239
259
|
}
|
|
240
260
|
exports.applyTableBorderFormat = applyTableBorderFormat;
|
|
261
|
+
/**
|
|
262
|
+
* Check targeted borders without repeatedly parsing identical CSS values.
|
|
263
|
+
* @param borderUpdates The borders to compare
|
|
264
|
+
* @param borderFormat The requested border format
|
|
265
|
+
*/
|
|
266
|
+
function hasMatchingBorders(borderUpdates, borderFormat) {
|
|
267
|
+
var e_2, _a, e_3, _b;
|
|
268
|
+
var matchingBorders = new Set();
|
|
269
|
+
try {
|
|
270
|
+
for (var borderUpdates_3 = (0, tslib_1.__values)(borderUpdates), borderUpdates_3_1 = borderUpdates_3.next(); !borderUpdates_3_1.done; borderUpdates_3_1 = borderUpdates_3.next()) {
|
|
271
|
+
var _c = borderUpdates_3_1.value, cell = _c.cell, positions = _c.positions;
|
|
272
|
+
try {
|
|
273
|
+
for (var positions_1 = (e_3 = void 0, (0, tslib_1.__values)(positions)), positions_1_1 = positions_1.next(); !positions_1_1.done; positions_1_1 = positions_1.next()) {
|
|
274
|
+
var pos = positions_1_1.value;
|
|
275
|
+
var value = cell.format[pos] || '';
|
|
276
|
+
// Exact matches need no CSS parsing. Equivalent values are parsed only once.
|
|
277
|
+
if (value == borderFormat || matchingBorders.has(value)) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (!areSameBorders(value, borderFormat)) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
matchingBorders.add(value);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
287
|
+
finally {
|
|
288
|
+
try {
|
|
289
|
+
if (positions_1_1 && !positions_1_1.done && (_b = positions_1.return)) _b.call(positions_1);
|
|
290
|
+
}
|
|
291
|
+
finally { if (e_3) throw e_3.error; }
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
296
|
+
finally {
|
|
297
|
+
try {
|
|
298
|
+
if (borderUpdates_3_1 && !borderUpdates_3_1.done && (_a = borderUpdates_3.return)) _a.call(borderUpdates_3);
|
|
299
|
+
}
|
|
300
|
+
finally { if (e_2) throw e_2.error; }
|
|
301
|
+
}
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Compare border components, parsing colors to account for equivalent hex and RGB values.
|
|
306
|
+
*/
|
|
307
|
+
function areSameBorders(border1, border2) {
|
|
308
|
+
var values1 = (0, roosterjs_content_model_dom_1.extractBorderValues)(border1);
|
|
309
|
+
var values2 = (0, roosterjs_content_model_dom_1.extractBorderValues)(border2);
|
|
310
|
+
var color1 = values1.color || '';
|
|
311
|
+
var color2 = values2.color || '';
|
|
312
|
+
var rgb1 = (0, roosterjs_content_model_dom_1.parseColor)(color1);
|
|
313
|
+
var rgb2 = (0, roosterjs_content_model_dom_1.parseColor)(color2);
|
|
314
|
+
return (values1.width == values2.width &&
|
|
315
|
+
values1.style == values2.style &&
|
|
316
|
+
(color1 == color2 ||
|
|
317
|
+
(!!rgb1 && !!rgb2 && rgb1[0] == rgb2[0] && rgb1[1] == rgb2[1] && rgb1[2] == rgb2[2])));
|
|
318
|
+
}
|
|
241
319
|
/**
|
|
242
320
|
* @internal
|
|
243
321
|
* Apply border format to a cell
|