roosterjs 8.16.0 → 8.17.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.
@@ -3017,6 +3017,7 @@ exports.default = rotateElement;
3017
3017
 
3018
3018
  Object.defineProperty(exports, "__esModule", { value: true });
3019
3019
  var execCommand_1 = __webpack_require__(/*! ../utils/execCommand */ "./packages/roosterjs-editor-api/lib/utils/execCommand.ts");
3020
+ var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
3020
3021
  /**
3021
3022
  * Set content alignment
3022
3023
  * @param editor The editor instance
@@ -3024,8 +3025,52 @@ var execCommand_1 = __webpack_require__(/*! ../utils/execCommand */ "./packages/
3024
3025
  * Alignment.Center, Alignment.Left, Alignment.Right
3025
3026
  */
3026
3027
  function setAlignment(editor, alignment) {
3027
- var command = "justifyLeft" /* JustifyLeft */;
3028
+ var selection = editor.getSelectionRangeEx();
3029
+ var isATable = selection && selection.type === 1 /* TableSelection */;
3030
+ editor.addUndoSnapshot(function () {
3031
+ if (editor.isFeatureEnabled("TableAlignment" /* TableAlignment */) &&
3032
+ isATable &&
3033
+ isWholeTableSelected(selection)) {
3034
+ alignTable(selection, alignment);
3035
+ }
3036
+ else {
3037
+ alignText(editor, alignment);
3038
+ }
3039
+ }, "Format" /* Format */);
3040
+ }
3041
+ exports.default = setAlignment;
3042
+ /**
3043
+ * Align text using the margins
3044
+ * @param editor
3045
+ * @param element
3046
+ * @param alignment
3047
+ * @param addUndoSnapshot
3048
+ * @returns
3049
+ */
3050
+ function alignTable(selection, alignment) {
3051
+ var table = selection.table;
3052
+ if (alignment == 1 /* Center */) {
3053
+ table.style.marginLeft = 'auto';
3054
+ table.style.marginRight = 'auto';
3055
+ }
3056
+ else if (alignment == 2 /* Right */) {
3057
+ table.style.marginLeft = 'auto';
3058
+ table.style.marginRight = '';
3059
+ }
3060
+ else {
3061
+ table.style.marginLeft = '';
3062
+ table.style.marginRight = 'auto';
3063
+ }
3064
+ }
3065
+ /**
3066
+ * Align text using the text-align
3067
+ * @param editor
3068
+ * @param alignment
3069
+ * @returns
3070
+ */
3071
+ function alignText(editor, alignment) {
3028
3072
  var align = 'left';
3073
+ var command = "justifyLeft" /* JustifyLeft */;
3029
3074
  if (alignment == 1 /* Center */) {
3030
3075
  command = "justifyCenter" /* JustifyCenter */;
3031
3076
  align = 'center';
@@ -3034,12 +3079,28 @@ function setAlignment(editor, alignment) {
3034
3079
  command = "justifyRight" /* JustifyRight */;
3035
3080
  align = 'right';
3036
3081
  }
3037
- editor.addUndoSnapshot(function () {
3038
- (0, execCommand_1.default)(editor, command);
3039
- editor.queryElements('[align]', 1 /* OnSelection */, function (node) { return (node.style.textAlign = align); });
3040
- }, "Format" /* Format */);
3082
+ (0, execCommand_1.default)(editor, command);
3083
+ editor.queryElements('[align]', 1 /* OnSelection */, function (node) { return (node.style.textAlign = align); });
3084
+ }
3085
+ /**
3086
+ * Check if the whole table is selected
3087
+ * @param selection
3088
+ * @returns
3089
+ */
3090
+ function isWholeTableSelected(selection) {
3091
+ if (!selection) {
3092
+ return false;
3093
+ }
3094
+ var vTable = new roosterjs_editor_dom_1.VTable(selection.table);
3095
+ var _a = selection.coordinates, firstCell = _a.firstCell, lastCell = _a.lastCell;
3096
+ var rowsLength = vTable.cells.length - 1;
3097
+ var colIndex = vTable.cells[rowsLength].length - 1;
3098
+ var firstX = firstCell.x;
3099
+ var firstY = firstCell.y;
3100
+ var lastX = lastCell.x;
3101
+ var lastY = lastCell.y;
3102
+ return firstX == 0 && firstY == 0 && lastX == colIndex && lastY == rowsLength;
3041
3103
  }
3042
- exports.default = setAlignment;
3043
3104
 
3044
3105
 
3045
3106
  /***/ }),
@@ -3848,6 +3909,8 @@ function editTable(editor, operation) {
3848
3909
  var vtable = new roosterjs_editor_dom_1.VTable(td);
3849
3910
  vtable.edit(operation);
3850
3911
  vtable.writeBack();
3912
+ //Adding replaceNode to transform color when the theme is switched to dark.
3913
+ editor.replaceNode(vtable.table, vtable.table, true /**transformColorForDarkMode*/);
3851
3914
  editor.focus();
3852
3915
  var cellToSelect = calculateCellToSelect(operation, vtable.row, vtable.col);
3853
3916
  editor.select(vtable.getCell(cellToSelect.newRow, cellToSelect.newCol).td, 0 /* Begin */);
@@ -3907,6 +3970,8 @@ function formatTable(editor, format, table) {
3907
3970
  var vtable = new roosterjs_editor_dom_1.VTable(table);
3908
3971
  vtable.applyFormat(format);
3909
3972
  vtable.writeBack();
3973
+ //Adding replaceNode to transform color when the theme is switched to dark.
3974
+ editor.replaceNode(vtable.table, vtable.table, true /**transformColorForDarkMode*/);
3910
3975
  editor.focus();
3911
3976
  editor.select(start, end);
3912
3977
  }, "Format" /* Format */);
@@ -5675,7 +5740,8 @@ var switchShadowEdit = function (core, isOn) {
5675
5740
  var range = core.api.getSelectionRange(core, true /*tryGetFromCache*/);
5676
5741
  shadowEditSelectionPath = range && (0, roosterjs_editor_dom_1.getSelectionPath)(contentDiv, range);
5677
5742
  shadowEditTableSelectionPath =
5678
- selection && selection.ranges.map(function (range) { return (0, roosterjs_editor_dom_1.getSelectionPath)(contentDiv, range); });
5743
+ (selection === null || selection === void 0 ? void 0 : selection.type) == 1 /* TableSelection */ &&
5744
+ selection.ranges.map(function (range) { return (0, roosterjs_editor_dom_1.getSelectionPath)(contentDiv, range); });
5679
5745
  shadowEditFragment = core.contentDiv.ownerDocument.createDocumentFragment();
5680
5746
  (0, roosterjs_editor_dom_1.moveChildNodes)(shadowEditFragment, contentDiv);
5681
5747
  shadowEditFragment.normalize();
@@ -13933,7 +13999,7 @@ var __assign = (this && this.__assign) || function () {
13933
13999
  return __assign.apply(this, arguments);
13934
14000
  };
13935
14001
  Object.defineProperty(exports, "__esModule", { value: true });
13936
- var applyTableFormat_1 = __webpack_require__(/*! ../utils/applyTableFormat */ "./packages/roosterjs-editor-dom/lib/utils/applyTableFormat.ts");
14002
+ var applyTableFormat_1 = __webpack_require__(/*! ./applyTableFormat */ "./packages/roosterjs-editor-dom/lib/table/applyTableFormat.ts");
13937
14003
  var moveChildNodes_1 = __webpack_require__(/*! ../utils/moveChildNodes */ "./packages/roosterjs-editor-dom/lib/utils/moveChildNodes.ts");
13938
14004
  var normalizeRect_1 = __webpack_require__(/*! ../utils/normalizeRect */ "./packages/roosterjs-editor-dom/lib/utils/normalizeRect.ts");
13939
14005
  var safeInstanceOf_1 = __webpack_require__(/*! ../utils/safeInstanceOf */ "./packages/roosterjs-editor-dom/lib/utils/safeInstanceOf.ts");
@@ -14004,8 +14070,10 @@ var VTable = /** @class */ (function () {
14004
14070
  }
14005
14071
  /**
14006
14072
  * Write the virtual table back to DOM tree to represent the change of VTable
14073
+ * @param skipApplyFormat Do not reapply table format when write back.
14074
+ * Only use this parameter when you are pretty sure there is no format or table structure change during the process.
14007
14075
  */
14008
- VTable.prototype.writeBack = function () {
14076
+ VTable.prototype.writeBack = function (skipApplyFormat) {
14009
14077
  var _this = this;
14010
14078
  if (this.cells) {
14011
14079
  (0, moveChildNodes_1.default)(this.table);
@@ -14019,7 +14087,7 @@ var VTable = /** @class */ (function () {
14019
14087
  }
14020
14088
  });
14021
14089
  });
14022
- if (this.formatInfo) {
14090
+ if (this.formatInfo && !skipApplyFormat) {
14023
14091
  (0, tableFormatInfo_1.saveTableInfo)(this.table, this.formatInfo);
14024
14092
  (0, applyTableFormat_1.default)(this.table, this.cells, this.formatInfo);
14025
14093
  }
@@ -14040,7 +14108,7 @@ var VTable = /** @class */ (function () {
14040
14108
  this.deleteCellShadeDataset(this.cells);
14041
14109
  };
14042
14110
  /**
14043
- * Remove the cellshade dataset to apply a new style format at the cell.
14111
+ * Remove the cellShade dataset to apply a new style format at the cell.
14044
14112
  * @param cells
14045
14113
  */
14046
14114
  VTable.prototype.deleteCellShadeDataset = function (cells) {
@@ -14472,224 +14540,9 @@ function cloneNode(node) {
14472
14540
 
14473
14541
  /***/ }),
14474
14542
 
14475
- /***/ "./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts":
14476
- /*!********************************************************************!*\
14477
- !*** ./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts ***!
14478
- \********************************************************************/
14479
- /*! no static exports found */
14480
- /***/ (function(module, exports, __webpack_require__) {
14481
-
14482
- "use strict";
14483
-
14484
- Object.defineProperty(exports, "__esModule", { value: true });
14485
- exports.saveTableInfo = exports.getTableFormatInfo = void 0;
14486
- var TABLE_STYLE_INFO = 'roosterTableInfo';
14487
- /**
14488
- * @internal
14489
- * Get the format info of a table
14490
- * If the table does not have a info saved, it will be retrieved from the css styles
14491
- * @param table The table that has the info
14492
- */
14493
- function getTableFormatInfo(table) {
14494
- var obj = safeParseJSON(table === null || table === void 0 ? void 0 : table.dataset[TABLE_STYLE_INFO]);
14495
- return checkIfTableFormatIsValid(obj) ? obj : null;
14496
- }
14497
- exports.getTableFormatInfo = getTableFormatInfo;
14498
- /**
14499
- * @internal
14500
- * Save the format info of a table
14501
- * @param table The table the info will be saved
14502
- * @param format The format of the table
14503
- */
14504
- function saveTableInfo(table, format) {
14505
- if (table && format) {
14506
- table.dataset[TABLE_STYLE_INFO] = JSON.stringify(format);
14507
- }
14508
- }
14509
- exports.saveTableInfo = saveTableInfo;
14510
- function checkIfTableFormatIsValid(format) {
14511
- if (!format) {
14512
- return false;
14513
- }
14514
- var topBorderColor = format.topBorderColor, verticalBorderColor = format.verticalBorderColor, bottomBorderColor = format.bottomBorderColor, bgColorOdd = format.bgColorOdd, bgColorEven = format.bgColorEven, hasBandedColumns = format.hasBandedColumns, hasBandedRows = format.hasBandedRows, hasFirstColumn = format.hasFirstColumn, hasHeaderRow = format.hasHeaderRow, tableBorderFormat = format.tableBorderFormat;
14515
- var colorsValues = [
14516
- topBorderColor,
14517
- verticalBorderColor,
14518
- bottomBorderColor,
14519
- bgColorOdd,
14520
- bgColorEven,
14521
- ];
14522
- var stateValues = [hasBandedColumns, hasBandedRows, hasFirstColumn, hasHeaderRow];
14523
- if (colorsValues.some(function (key) { return !isAValidColor(key); }) ||
14524
- stateValues.some(function (key) { return !isBoolean(key); }) ||
14525
- !isAValidTableBorderType(tableBorderFormat)) {
14526
- return false;
14527
- }
14528
- return true;
14529
- }
14530
- function isAValidColor(color) {
14531
- if (color === null || color === undefined || typeof color === 'string') {
14532
- return true;
14533
- }
14534
- return false;
14535
- }
14536
- function isBoolean(a) {
14537
- if (typeof a === 'boolean') {
14538
- return true;
14539
- }
14540
- return false;
14541
- }
14542
- function isAValidTableBorderType(border) {
14543
- if (-1 < border && border < 8) {
14544
- return true;
14545
- }
14546
- return false;
14547
- }
14548
- function safeParseJSON(json) {
14549
- if (!json) {
14550
- return null;
14551
- }
14552
- try {
14553
- return JSON.parse(json);
14554
- }
14555
- catch (_a) {
14556
- return null;
14557
- }
14558
- }
14559
-
14560
-
14561
- /***/ }),
14562
-
14563
- /***/ "./packages/roosterjs-editor-dom/lib/utils/Browser.ts":
14564
- /*!************************************************************!*\
14565
- !*** ./packages/roosterjs-editor-dom/lib/utils/Browser.ts ***!
14566
- \************************************************************/
14567
- /*! no static exports found */
14568
- /***/ (function(module, exports, __webpack_require__) {
14569
-
14570
- "use strict";
14571
-
14572
- Object.defineProperty(exports, "__esModule", { value: true });
14573
- exports.Browser = exports.getBrowserInfo = void 0;
14574
- var isAndroidRegex = /android/i;
14575
- /**
14576
- * Get current browser information from user agent string
14577
- * @param userAgent The userAgent string of a browser
14578
- * @param appVersion The appVersion string of a browser
14579
- * @returns The BrowserInfo object calculated from the given userAgent and appVersion
14580
- */
14581
- function getBrowserInfo(userAgent, appVersion) {
14582
- // checks whether the browser is running in IE
14583
- // IE11 will use rv in UA instead of MSIE. Unfortunately Firefox also uses this. We should also look for "Trident" to confirm this.
14584
- // There have been cases where companies using older version of IE and custom UserAgents have broken this logic (e.g. IE 10 and KellyServices)
14585
- // therefore we should check that the Trident/rv combo is not just from an older IE browser
14586
- var isIE11OrGreater = userAgent.indexOf('rv:') != -1 && userAgent.indexOf('Trident') != -1;
14587
- var isIE = userAgent.indexOf('MSIE') != -1 || isIE11OrGreater;
14588
- // IE11+ may also have 'Chrome', 'Firefox' and 'Safari' in user agent. But it will have 'trident' as well
14589
- var isChrome = false;
14590
- var isFirefox = false;
14591
- var isSafari = false;
14592
- var isEdge = false;
14593
- var isWebKit = userAgent.indexOf('WebKit') != -1;
14594
- if (!isIE) {
14595
- isChrome = userAgent.indexOf('Chrome') != -1;
14596
- isFirefox = userAgent.indexOf('Firefox') != -1;
14597
- if (userAgent.indexOf('Safari') != -1) {
14598
- // Android and Chrome have Safari in the user string
14599
- isSafari = userAgent.indexOf('Chrome') == -1 && userAgent.indexOf('Android') == -1;
14600
- }
14601
- // Sample Edge UA: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10121
14602
- isEdge = userAgent.indexOf('Edge') != -1;
14603
- // When it is edge, it should not be chrome or firefox. and it is also not webkit
14604
- if (isEdge) {
14605
- isWebKit = isChrome = isFirefox = false;
14606
- }
14607
- }
14608
- var isMac = appVersion.indexOf('Mac') != -1;
14609
- var isWin = appVersion.indexOf('Win') != -1 || appVersion.indexOf('NT') != -1;
14610
- var isAndroid = isAndroidRegex.test(userAgent);
14611
- return {
14612
- isMac: isMac,
14613
- isWin: isWin,
14614
- isWebKit: isWebKit,
14615
- isIE: isIE,
14616
- isIE11OrGreater: isIE11OrGreater,
14617
- isSafari: isSafari,
14618
- isChrome: isChrome,
14619
- isFirefox: isFirefox,
14620
- isEdge: isEdge,
14621
- isIEOrEdge: isIE || isEdge,
14622
- isAndroid: isAndroid,
14623
- };
14624
- }
14625
- exports.getBrowserInfo = getBrowserInfo;
14626
- /**
14627
- * Browser object contains browser and operating system information of current environment
14628
- */
14629
- exports.Browser = window
14630
- ? getBrowserInfo(window.navigator.userAgent, window.navigator.appVersion)
14631
- : {};
14632
-
14633
-
14634
- /***/ }),
14635
-
14636
- /***/ "./packages/roosterjs-editor-dom/lib/utils/applyFormat.ts":
14637
- /*!****************************************************************!*\
14638
- !*** ./packages/roosterjs-editor-dom/lib/utils/applyFormat.ts ***!
14639
- \****************************************************************/
14640
- /*! no static exports found */
14641
- /***/ (function(module, exports, __webpack_require__) {
14642
-
14643
- "use strict";
14644
-
14645
- Object.defineProperty(exports, "__esModule", { value: true });
14646
- var setColor_1 = __webpack_require__(/*! ./setColor */ "./packages/roosterjs-editor-dom/lib/utils/setColor.ts");
14647
- /**
14648
- * Apply format to an HTML element
14649
- * @param element The HTML element to apply format to
14650
- * @param format The format to apply
14651
- */
14652
- function applyFormat(element, format, isDarkMode) {
14653
- if (format) {
14654
- var elementStyle = element.style;
14655
- var fontFamily = format.fontFamily, fontSize = format.fontSize, textColor = format.textColor, textColors = format.textColors, backgroundColor = format.backgroundColor, backgroundColors = format.backgroundColors, bold = format.bold, italic = format.italic, underline = format.underline;
14656
- if (fontFamily) {
14657
- elementStyle.fontFamily = fontFamily;
14658
- }
14659
- if (fontSize) {
14660
- elementStyle.fontSize = fontSize;
14661
- }
14662
- if (textColors) {
14663
- (0, setColor_1.default)(element, textColors, false /*isBackground*/, isDarkMode);
14664
- }
14665
- else if (textColor) {
14666
- (0, setColor_1.default)(element, textColor, false /*isBackground*/, isDarkMode);
14667
- }
14668
- if (backgroundColors) {
14669
- (0, setColor_1.default)(element, backgroundColors, true /*isBackground*/, isDarkMode);
14670
- }
14671
- else if (backgroundColor) {
14672
- (0, setColor_1.default)(element, backgroundColor, true /*isBackground*/, isDarkMode);
14673
- }
14674
- if (bold) {
14675
- elementStyle.fontWeight = 'bold';
14676
- }
14677
- if (italic) {
14678
- elementStyle.fontStyle = 'italic';
14679
- }
14680
- if (underline) {
14681
- elementStyle.textDecoration = 'underline';
14682
- }
14683
- }
14684
- }
14685
- exports.default = applyFormat;
14686
-
14687
-
14688
- /***/ }),
14689
-
14690
- /***/ "./packages/roosterjs-editor-dom/lib/utils/applyTableFormat.ts":
14543
+ /***/ "./packages/roosterjs-editor-dom/lib/table/applyTableFormat.ts":
14691
14544
  /*!*********************************************************************!*\
14692
- !*** ./packages/roosterjs-editor-dom/lib/utils/applyTableFormat.ts ***!
14545
+ !*** ./packages/roosterjs-editor-dom/lib/table/applyTableFormat.ts ***!
14693
14546
  \*********************************************************************/
14694
14547
  /*! no static exports found */
14695
14548
  /***/ (function(module, exports, __webpack_require__) {
@@ -14697,7 +14550,8 @@ exports.default = applyFormat;
14697
14550
  "use strict";
14698
14551
 
14699
14552
  Object.defineProperty(exports, "__esModule", { value: true });
14700
- var changeElementTag_1 = __webpack_require__(/*! ./changeElementTag */ "./packages/roosterjs-editor-dom/lib/utils/changeElementTag.ts");
14553
+ var changeElementTag_1 = __webpack_require__(/*! ../utils/changeElementTag */ "./packages/roosterjs-editor-dom/lib/utils/changeElementTag.ts");
14554
+ var setColor_1 = __webpack_require__(/*! ../utils/setColor */ "./packages/roosterjs-editor-dom/lib/utils/setColor.ts");
14701
14555
  var TRANSPARENT = 'transparent';
14702
14556
  var TABLE_CELL_TAG_NAME = 'TD';
14703
14557
  var TABLE_HEADER_TAG_NAME = 'TH';
@@ -14713,7 +14567,7 @@ function applyTableFormat(table, cells, format) {
14713
14567
  }
14714
14568
  table.style.borderCollapse = 'collapse';
14715
14569
  setBordersType(cells, format);
14716
- setColor(cells, format);
14570
+ setCellColor(cells, format);
14717
14571
  setFirstColumnFormat(cells, format);
14718
14572
  setHeaderRowFormat(cells, format);
14719
14573
  }
@@ -14734,7 +14588,7 @@ function hasCellShade(cell) {
14734
14588
  * Set color to the table
14735
14589
  * @param format the format that must be applied
14736
14590
  */
14737
- function setColor(cells, format) {
14591
+ function setCellColor(cells, format) {
14738
14592
  var color = function (index) { return (index % 2 === 0 ? format.bgColorEven : format.bgColorOdd); };
14739
14593
  var hasBandedRows = format.hasBandedRows, hasBandedColumns = format.hasBandedColumns, bgColorOdd = format.bgColorOdd, bgColorEven = format.bgColorEven;
14740
14594
  var shouldColorWholeTable = !hasBandedRows && bgColorOdd === bgColorEven ? true : false;
@@ -14743,13 +14597,13 @@ function setColor(cells, format) {
14743
14597
  if (cell.td && !hasCellShade(cell)) {
14744
14598
  if (hasBandedRows) {
14745
14599
  var backgroundColor = color(index);
14746
- cell.td.style.backgroundColor = backgroundColor || TRANSPARENT;
14600
+ (0, setColor_1.default)(cell.td, backgroundColor || TRANSPARENT, true /** isBackgroundColor*/);
14747
14601
  }
14748
14602
  else if (shouldColorWholeTable) {
14749
- cell.td.style.backgroundColor = format.bgColorOdd || TRANSPARENT;
14603
+ (0, setColor_1.default)(cell.td, format.bgColorOdd || TRANSPARENT, true /** isBackgroundColor*/);
14750
14604
  }
14751
14605
  else {
14752
- cell.td.style.backgroundColor = TRANSPARENT;
14606
+ (0, setColor_1.default)(cell.td, TRANSPARENT, true /** isBackgroundColor*/);
14753
14607
  }
14754
14608
  }
14755
14609
  });
@@ -14759,7 +14613,7 @@ function setColor(cells, format) {
14759
14613
  row.forEach(function (cell, index) {
14760
14614
  var backgroundColor = color(index);
14761
14615
  if (cell.td && backgroundColor && !hasCellShade(cell)) {
14762
- cell.td.style.backgroundColor = backgroundColor;
14616
+ (0, setColor_1.default)(cell.td, backgroundColor, true /** isBackgroundColor*/);
14763
14617
  }
14764
14618
  });
14765
14619
  });
@@ -14926,7 +14780,7 @@ function setFirstColumnFormat(cells, format) {
14926
14780
  if (cell.td && cellIndex === 0) {
14927
14781
  if (rowIndex !== 0) {
14928
14782
  cell.td.style.borderTopColor = TRANSPARENT;
14929
- cell.td.style.backgroundColor = TRANSPARENT;
14783
+ (0, setColor_1.default)(cell.td, TRANSPARENT, true /** isBackgroundColor*/);
14930
14784
  }
14931
14785
  if (rowIndex !== cells.length - 1 && rowIndex !== 0) {
14932
14786
  cell.td.style.borderBottomColor = TRANSPARENT;
@@ -14955,7 +14809,7 @@ function setHeaderRowFormat(cells, format) {
14955
14809
  }
14956
14810
  (_b = cells[0]) === null || _b === void 0 ? void 0 : _b.forEach(function (cell) {
14957
14811
  if (cell.td && format.headerRowColor) {
14958
- cell.td.style.backgroundColor = format.headerRowColor;
14812
+ (0, setColor_1.default)(cell.td, format.headerRowColor, true /** isBackgroundColor*/);
14959
14813
  cell.td.style.borderRightColor = format.headerRowColor;
14960
14814
  cell.td.style.borderLeftColor = format.headerRowColor;
14961
14815
  cell.td.style.borderTopColor = format.headerRowColor;
@@ -14970,6 +14824,221 @@ function getBorderStyle(style) {
14970
14824
  }
14971
14825
 
14972
14826
 
14827
+ /***/ }),
14828
+
14829
+ /***/ "./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts":
14830
+ /*!********************************************************************!*\
14831
+ !*** ./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts ***!
14832
+ \********************************************************************/
14833
+ /*! no static exports found */
14834
+ /***/ (function(module, exports, __webpack_require__) {
14835
+
14836
+ "use strict";
14837
+
14838
+ Object.defineProperty(exports, "__esModule", { value: true });
14839
+ exports.saveTableInfo = exports.getTableFormatInfo = void 0;
14840
+ var TABLE_STYLE_INFO = 'roosterTableInfo';
14841
+ /**
14842
+ * @internal
14843
+ * Get the format info of a table
14844
+ * If the table does not have a info saved, it will be retrieved from the css styles
14845
+ * @param table The table that has the info
14846
+ */
14847
+ function getTableFormatInfo(table) {
14848
+ var obj = safeParseJSON(table === null || table === void 0 ? void 0 : table.dataset[TABLE_STYLE_INFO]);
14849
+ return checkIfTableFormatIsValid(obj) ? obj : null;
14850
+ }
14851
+ exports.getTableFormatInfo = getTableFormatInfo;
14852
+ /**
14853
+ * @internal
14854
+ * Save the format info of a table
14855
+ * @param table The table the info will be saved
14856
+ * @param format The format of the table
14857
+ */
14858
+ function saveTableInfo(table, format) {
14859
+ if (table && format) {
14860
+ table.dataset[TABLE_STYLE_INFO] = JSON.stringify(format);
14861
+ }
14862
+ }
14863
+ exports.saveTableInfo = saveTableInfo;
14864
+ function checkIfTableFormatIsValid(format) {
14865
+ if (!format) {
14866
+ return false;
14867
+ }
14868
+ var topBorderColor = format.topBorderColor, verticalBorderColor = format.verticalBorderColor, bottomBorderColor = format.bottomBorderColor, bgColorOdd = format.bgColorOdd, bgColorEven = format.bgColorEven, hasBandedColumns = format.hasBandedColumns, hasBandedRows = format.hasBandedRows, hasFirstColumn = format.hasFirstColumn, hasHeaderRow = format.hasHeaderRow, tableBorderFormat = format.tableBorderFormat;
14869
+ var colorsValues = [
14870
+ topBorderColor,
14871
+ verticalBorderColor,
14872
+ bottomBorderColor,
14873
+ bgColorOdd,
14874
+ bgColorEven,
14875
+ ];
14876
+ var stateValues = [hasBandedColumns, hasBandedRows, hasFirstColumn, hasHeaderRow];
14877
+ if (colorsValues.some(function (key) { return !isAValidColor(key); }) ||
14878
+ stateValues.some(function (key) { return !isBoolean(key); }) ||
14879
+ !isAValidTableBorderType(tableBorderFormat)) {
14880
+ return false;
14881
+ }
14882
+ return true;
14883
+ }
14884
+ function isAValidColor(color) {
14885
+ if (color === null || color === undefined || typeof color === 'string') {
14886
+ return true;
14887
+ }
14888
+ return false;
14889
+ }
14890
+ function isBoolean(a) {
14891
+ if (typeof a === 'boolean') {
14892
+ return true;
14893
+ }
14894
+ return false;
14895
+ }
14896
+ function isAValidTableBorderType(border) {
14897
+ if (-1 < border && border < 8) {
14898
+ return true;
14899
+ }
14900
+ return false;
14901
+ }
14902
+ function safeParseJSON(json) {
14903
+ if (!json) {
14904
+ return null;
14905
+ }
14906
+ try {
14907
+ return JSON.parse(json);
14908
+ }
14909
+ catch (_a) {
14910
+ return null;
14911
+ }
14912
+ }
14913
+
14914
+
14915
+ /***/ }),
14916
+
14917
+ /***/ "./packages/roosterjs-editor-dom/lib/utils/Browser.ts":
14918
+ /*!************************************************************!*\
14919
+ !*** ./packages/roosterjs-editor-dom/lib/utils/Browser.ts ***!
14920
+ \************************************************************/
14921
+ /*! no static exports found */
14922
+ /***/ (function(module, exports, __webpack_require__) {
14923
+
14924
+ "use strict";
14925
+
14926
+ Object.defineProperty(exports, "__esModule", { value: true });
14927
+ exports.Browser = exports.getBrowserInfo = void 0;
14928
+ var isAndroidRegex = /android/i;
14929
+ /**
14930
+ * Get current browser information from user agent string
14931
+ * @param userAgent The userAgent string of a browser
14932
+ * @param appVersion The appVersion string of a browser
14933
+ * @returns The BrowserInfo object calculated from the given userAgent and appVersion
14934
+ */
14935
+ function getBrowserInfo(userAgent, appVersion) {
14936
+ // checks whether the browser is running in IE
14937
+ // IE11 will use rv in UA instead of MSIE. Unfortunately Firefox also uses this. We should also look for "Trident" to confirm this.
14938
+ // There have been cases where companies using older version of IE and custom UserAgents have broken this logic (e.g. IE 10 and KellyServices)
14939
+ // therefore we should check that the Trident/rv combo is not just from an older IE browser
14940
+ var isIE11OrGreater = userAgent.indexOf('rv:') != -1 && userAgent.indexOf('Trident') != -1;
14941
+ var isIE = userAgent.indexOf('MSIE') != -1 || isIE11OrGreater;
14942
+ // IE11+ may also have 'Chrome', 'Firefox' and 'Safari' in user agent. But it will have 'trident' as well
14943
+ var isChrome = false;
14944
+ var isFirefox = false;
14945
+ var isSafari = false;
14946
+ var isEdge = false;
14947
+ var isWebKit = userAgent.indexOf('WebKit') != -1;
14948
+ if (!isIE) {
14949
+ isChrome = userAgent.indexOf('Chrome') != -1;
14950
+ isFirefox = userAgent.indexOf('Firefox') != -1;
14951
+ if (userAgent.indexOf('Safari') != -1) {
14952
+ // Android and Chrome have Safari in the user string
14953
+ isSafari = userAgent.indexOf('Chrome') == -1 && userAgent.indexOf('Android') == -1;
14954
+ }
14955
+ // Sample Edge UA: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10121
14956
+ isEdge = userAgent.indexOf('Edge') != -1;
14957
+ // When it is edge, it should not be chrome or firefox. and it is also not webkit
14958
+ if (isEdge) {
14959
+ isWebKit = isChrome = isFirefox = false;
14960
+ }
14961
+ }
14962
+ var isMac = appVersion.indexOf('Mac') != -1;
14963
+ var isWin = appVersion.indexOf('Win') != -1 || appVersion.indexOf('NT') != -1;
14964
+ var isAndroid = isAndroidRegex.test(userAgent);
14965
+ return {
14966
+ isMac: isMac,
14967
+ isWin: isWin,
14968
+ isWebKit: isWebKit,
14969
+ isIE: isIE,
14970
+ isIE11OrGreater: isIE11OrGreater,
14971
+ isSafari: isSafari,
14972
+ isChrome: isChrome,
14973
+ isFirefox: isFirefox,
14974
+ isEdge: isEdge,
14975
+ isIEOrEdge: isIE || isEdge,
14976
+ isAndroid: isAndroid,
14977
+ };
14978
+ }
14979
+ exports.getBrowserInfo = getBrowserInfo;
14980
+ /**
14981
+ * Browser object contains browser and operating system information of current environment
14982
+ */
14983
+ exports.Browser = window
14984
+ ? getBrowserInfo(window.navigator.userAgent, window.navigator.appVersion)
14985
+ : {};
14986
+
14987
+
14988
+ /***/ }),
14989
+
14990
+ /***/ "./packages/roosterjs-editor-dom/lib/utils/applyFormat.ts":
14991
+ /*!****************************************************************!*\
14992
+ !*** ./packages/roosterjs-editor-dom/lib/utils/applyFormat.ts ***!
14993
+ \****************************************************************/
14994
+ /*! no static exports found */
14995
+ /***/ (function(module, exports, __webpack_require__) {
14996
+
14997
+ "use strict";
14998
+
14999
+ Object.defineProperty(exports, "__esModule", { value: true });
15000
+ var setColor_1 = __webpack_require__(/*! ./setColor */ "./packages/roosterjs-editor-dom/lib/utils/setColor.ts");
15001
+ /**
15002
+ * Apply format to an HTML element
15003
+ * @param element The HTML element to apply format to
15004
+ * @param format The format to apply
15005
+ */
15006
+ function applyFormat(element, format, isDarkMode) {
15007
+ if (format) {
15008
+ var elementStyle = element.style;
15009
+ var fontFamily = format.fontFamily, fontSize = format.fontSize, textColor = format.textColor, textColors = format.textColors, backgroundColor = format.backgroundColor, backgroundColors = format.backgroundColors, bold = format.bold, italic = format.italic, underline = format.underline;
15010
+ if (fontFamily) {
15011
+ elementStyle.fontFamily = fontFamily;
15012
+ }
15013
+ if (fontSize) {
15014
+ elementStyle.fontSize = fontSize;
15015
+ }
15016
+ if (textColors) {
15017
+ (0, setColor_1.default)(element, textColors, false /*isBackground*/, isDarkMode);
15018
+ }
15019
+ else if (textColor) {
15020
+ (0, setColor_1.default)(element, textColor, false /*isBackground*/, isDarkMode);
15021
+ }
15022
+ if (backgroundColors) {
15023
+ (0, setColor_1.default)(element, backgroundColors, true /*isBackground*/, isDarkMode);
15024
+ }
15025
+ else if (backgroundColor) {
15026
+ (0, setColor_1.default)(element, backgroundColor, true /*isBackground*/, isDarkMode);
15027
+ }
15028
+ if (bold) {
15029
+ elementStyle.fontWeight = 'bold';
15030
+ }
15031
+ if (italic) {
15032
+ elementStyle.fontStyle = 'italic';
15033
+ }
15034
+ if (underline) {
15035
+ elementStyle.textDecoration = 'underline';
15036
+ }
15037
+ }
15038
+ }
15039
+ exports.default = applyFormat;
15040
+
15041
+
14973
15042
  /***/ }),
14974
15043
 
14975
15044
  /***/ "./packages/roosterjs-editor-dom/lib/utils/arrayPush.ts":
@@ -22154,11 +22223,12 @@ var TableCellSelection = /** @class */ (function () {
22154
22223
  if (selection.type == 1 /* TableSelection */) {
22155
22224
  this.tableRange = selection.coordinates;
22156
22225
  this.firstTable = selection.table;
22226
+ this.tableSelection = true;
22157
22227
  this.editor.select(selection.table, null);
22158
22228
  }
22159
22229
  break;
22160
22230
  case 18 /* LeavingShadowEdit */:
22161
- if (this.firstTable && this.tableRange) {
22231
+ if (this.firstTable && this.tableSelection && this.tableRange) {
22162
22232
  var table = this.editor.queryElements('#' + this.firstTable.id);
22163
22233
  if (table.length == 1) {
22164
22234
  this.firstTable = table[0];
@@ -22310,6 +22380,7 @@ var TableCellSelection = /** @class */ (function () {
22310
22380
  : -3 /* After */);
22311
22381
  var sel = this.editor.getDocument().defaultView.getSelection();
22312
22382
  var anchorNode = sel.anchorNode, anchorOffset = sel.anchorOffset;
22383
+ this.editor.select(sel.getRangeAt(0));
22313
22384
  sel.setBaseAndExtent(anchorNode, anchorOffset, position.node, position.offset);
22314
22385
  this.lastTarget = position.node;
22315
22386
  event.rawEvent.preventDefault();
@@ -22942,7 +23013,7 @@ function createCellResizer(td, zoomScale, isRTL, isHorizontal, onStart, onEnd) {
22942
23013
  return { node: td, div: div, featureHandler: featureHandler };
22943
23014
  }
22944
23015
  exports.default = createCellResizer;
22945
- function onDragStart(context, event) {
23016
+ function onDragStart(context) {
22946
23017
  var td = context.td, isRTL = context.isRTL, zoomScale = context.zoomScale, onStart = context.onStart;
22947
23018
  var vTable = new roosterjs_editor_dom_1.VTable(td, true /*normalizeSize*/, zoomScale);
22948
23019
  var rect = (0, roosterjs_editor_dom_1.normalizeRect)(td.getBoundingClientRect());
@@ -22971,10 +23042,11 @@ function onDraggingHorizontal(context, event, initValue, deltaX, deltaY) {
22971
23042
  cell.td.style.height = cell.td == td ? cell.height / zoomScale + deltaY + "px" : null;
22972
23043
  }
22973
23044
  });
22974
- vTable.writeBack();
23045
+ // To avoid apply format styles when the table is being resizing, the skipApplyFormat is set to true.
23046
+ vTable.writeBack(true /**skipApplyFormat*/);
22975
23047
  return true;
22976
23048
  }
22977
- function onDraggingVertical(context, event, initValue, deltaX, deltaY) {
23049
+ function onDraggingVertical(context, event, initValue) {
22978
23050
  var isRTL = context.isRTL, zoomScale = context.zoomScale;
22979
23051
  var vTable = initValue.vTable, nextCells = initValue.nextCells, currentCells = initValue.currentCells;
22980
23052
  if (!canResizeColumns(event.pageX, currentCells, nextCells, isRTL, zoomScale)) {
@@ -23010,7 +23082,8 @@ function onDraggingVertical(context, event, initValue, deltaX, deltaY) {
23010
23082
  td.style.width = null;
23011
23083
  });
23012
23084
  }
23013
- vTable.writeBack();
23085
+ // To avoid apply format styles when the table is being resizing, the skipApplyFormat is set to true.
23086
+ vTable.writeBack(true /**skipApplyFormat*/);
23014
23087
  return true;
23015
23088
  }
23016
23089
  function getHorizontalDistance(rect, pos, toLeft) {
@@ -23125,14 +23198,18 @@ var TableEditor = /** @class */ (function () {
23125
23198
  this.table = table;
23126
23199
  this.onChanged = onChanged;
23127
23200
  this.onFinishEditing = function () {
23201
+ _this.editor.focus();
23128
23202
  _this.editor.select(_this.start, _this.end);
23129
23203
  _this.editor.addUndoSnapshot(null /*callback*/, "Format" /* Format */);
23130
- _this.editor.focus();
23131
23204
  _this.onChanged();
23132
23205
  return false;
23133
23206
  };
23207
+ this.onStartTableResize = function () {
23208
+ _this.onStartResize();
23209
+ };
23134
23210
  this.onStartCellResize = function () {
23135
23211
  _this.disposeTableResizer();
23212
+ _this.onStartResize();
23136
23213
  };
23137
23214
  this.onInserted = function () {
23138
23215
  _this.disposeTableResizer();
@@ -23163,12 +23240,8 @@ var TableEditor = /** @class */ (function () {
23163
23240
  }
23164
23241
  };
23165
23242
  this.isRTL = (0, roosterjs_editor_dom_1.getComputedStyle)(table, 'direction') == 'rtl';
23166
- this.tableResizer = (0, TableResizer_1.default)(table, editor.getZoomScale(), this.isRTL, this.onFinishEditing);
23243
+ this.tableResizer = (0, TableResizer_1.default)(table, editor.getZoomScale(), this.isRTL, this.onStartTableResize, this.onFinishEditing);
23167
23244
  this.tableSelector = (0, TableSelector_1.default)(table, editor.getZoomScale(), this.onSelect);
23168
- this.editor.addUndoSnapshot(function (start, end) {
23169
- _this.start = start;
23170
- _this.end = end;
23171
- });
23172
23245
  }
23173
23246
  TableEditor.prototype.dispose = function () {
23174
23247
  this.disposeTableResizer();
@@ -23272,6 +23345,14 @@ var TableEditor = /** @class */ (function () {
23272
23345
  this.tableSelector = null;
23273
23346
  }
23274
23347
  };
23348
+ TableEditor.prototype.onStartResize = function () {
23349
+ var range = this.editor.getSelectionRange();
23350
+ if (range) {
23351
+ this.start = roosterjs_editor_dom_1.Position.getStart(range);
23352
+ this.end = roosterjs_editor_dom_1.Position.getEnd(range);
23353
+ }
23354
+ this.editor.addUndoSnapshot();
23355
+ };
23275
23356
  return TableEditor;
23276
23357
  }());
23277
23358
  exports.default = TableEditor;
@@ -23344,29 +23425,31 @@ function createTableInserter(editor, td, isRTL, isHorizontal, onInsert) {
23344
23425
  div.firstChild.style.height = tableRect.bottom - tableRect.top + "px";
23345
23426
  }
23346
23427
  document_1.body.appendChild(div);
23347
- var handler = new TableInsertHandler(div, td, isHorizontal, editor.getZoomScale(), onInsert);
23428
+ var handler = new TableInsertHandler(div, td, isHorizontal, editor, onInsert);
23348
23429
  return { div: div, featureHandler: handler, node: td };
23349
23430
  }
23350
23431
  }
23351
23432
  exports.default = createTableInserter;
23352
23433
  var TableInsertHandler = /** @class */ (function () {
23353
- function TableInsertHandler(div, td, isHorizontal, zoomScale, onInsert) {
23434
+ function TableInsertHandler(div, td, isHorizontal, editor, onInsert) {
23354
23435
  var _this = this;
23355
23436
  this.div = div;
23356
23437
  this.td = td;
23357
23438
  this.isHorizontal = isHorizontal;
23358
- this.zoomScale = zoomScale;
23439
+ this.editor = editor;
23359
23440
  this.onInsert = onInsert;
23360
23441
  this.insertTd = function () {
23361
23442
  var vtable = new roosterjs_editor_dom_1.VTable(_this.td);
23362
23443
  if (!_this.isHorizontal) {
23363
- vtable.normalizeTableCellSize(_this.zoomScale);
23444
+ vtable.normalizeTableCellSize(_this.editor.getZoomScale());
23364
23445
  // Since adding new column will cause table width to change, we need to remove width properties
23365
23446
  vtable.table.removeAttribute('width');
23366
23447
  vtable.table.style.width = null;
23367
23448
  }
23368
23449
  vtable.edit(_this.isHorizontal ? 1 /* InsertBelow */ : 3 /* InsertRight */);
23369
23450
  vtable.writeBack();
23451
+ //Adding replaceNode to transform color when the theme is switched to dark.
23452
+ _this.editor.replaceNode(vtable.table, vtable.table, true /**transformColorForDarkMode*/);
23370
23453
  _this.onInsert();
23371
23454
  };
23372
23455
  this.div.addEventListener('click', this.insertTd);
@@ -23374,6 +23457,7 @@ var TableInsertHandler = /** @class */ (function () {
23374
23457
  TableInsertHandler.prototype.dispose = function () {
23375
23458
  this.div.removeEventListener('click', this.insertTd);
23376
23459
  this.div = null;
23460
+ this.editor = null;
23377
23461
  };
23378
23462
  return TableInsertHandler;
23379
23463
  }());
@@ -23417,7 +23501,7 @@ var MIN_CELL_HEIGHT = 20;
23417
23501
  /**
23418
23502
  * @internal
23419
23503
  */
23420
- function createTableResizer(table, zoomScale, isRTL, onDragEnd) {
23504
+ function createTableResizer(table, zoomScale, isRTL, onStart, onDragEnd) {
23421
23505
  var document = table.ownerDocument;
23422
23506
  var div = (0, roosterjs_editor_dom_1.createElement)(isRTL
23423
23507
  ? 10 /* TableResizerRTL */
@@ -23429,6 +23513,7 @@ function createTableResizer(table, zoomScale, isRTL, onDragEnd) {
23429
23513
  isRTL: isRTL,
23430
23514
  table: table,
23431
23515
  zoomScale: zoomScale,
23516
+ onStart: onStart,
23432
23517
  };
23433
23518
  setResizeDivPosition(context, div);
23434
23519
  var featureHandler = new DragAndDropHelper_1.default(div, context, setResizeDivPosition, {
@@ -23439,7 +23524,8 @@ function createTableResizer(table, zoomScale, isRTL, onDragEnd) {
23439
23524
  return { node: table, div: div, featureHandler: featureHandler };
23440
23525
  }
23441
23526
  exports.default = createTableResizer;
23442
- function onDragStart(context, event) {
23527
+ function onDragStart(context) {
23528
+ context.onStart();
23443
23529
  return {
23444
23530
  originalRect: context.table.getBoundingClientRect(),
23445
23531
  vTable: new roosterjs_editor_dom_1.VTable(context.table, true /*normalizeTable*/, context.zoomScale),
@@ -23484,7 +23570,8 @@ function onDragging(context, event, initValue, deltaX, deltaY) {
23484
23570
  }
23485
23571
  }
23486
23572
  }
23487
- vTable.writeBack();
23573
+ // To avoid apply format styles when the table is being resizing, the skipApplyFormat is set to true.
23574
+ vTable.writeBack(true /**skipApplyFormat*/);
23488
23575
  return true;
23489
23576
  }
23490
23577
  else {