roosterjs 8.14.0 → 8.16.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/dist/rooster.js CHANGED
@@ -2682,6 +2682,13 @@ function createLink(editor, link, altText, displayText) {
2682
2682
  else {
2683
2683
  // the selection is not collapsed, use browser execCommand
2684
2684
  editor.getDocument().execCommand("createLink" /* CreateLink */, false, normalizedUrl_1);
2685
+ var traverser = editor.getSelectionTraverser();
2686
+ var currentInline = traverser.getNextInlineElement();
2687
+ while (currentInline) {
2688
+ var a = currentInline.getContainerNode();
2689
+ a.parentElement.removeChild(a);
2690
+ currentInline = traverser.getNextInlineElement();
2691
+ }
2685
2692
  anchor = getAnchorNodeAtCursor(editor);
2686
2693
  updateAnchorDisplayText(anchor, displayText);
2687
2694
  }
@@ -3794,6 +3801,7 @@ Object.defineProperty(exports, "experimentCommitListChains", { enumerable: true,
3794
3801
  Object.defineProperty(exports, "__esModule", { value: true });
3795
3802
  var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
3796
3803
  var TEMP_BACKGROUND_COLOR = 'originalBackgroundColor';
3804
+ var CELL_SHADE = 'cellShade';
3797
3805
  /**
3798
3806
  * Set background color of cells.
3799
3807
  * @param editor The editor instance
@@ -3806,6 +3814,7 @@ function applyCellShading(editor, color) {
3806
3814
  regions.forEach(function (region) {
3807
3815
  if ((0, roosterjs_editor_dom_1.safeInstanceOf)(region.rootNode, 'HTMLTableCellElement')) {
3808
3816
  (0, roosterjs_editor_dom_1.setColor)(region.rootNode, color, true /* isBackgroundColor */, editor.isDarkMode());
3817
+ region.rootNode.dataset[CELL_SHADE] = 'true';
3809
3818
  region.rootNode.dataset[TEMP_BACKGROUND_COLOR] =
3810
3819
  region.rootNode.style.backgroundColor;
3811
3820
  }
@@ -4116,6 +4125,7 @@ var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./
4116
4125
  */
4117
4126
  function blockFormat(editor, callback, beforeRunCallback) {
4118
4127
  editor.focus();
4128
+ var selection = editor.getSelectionRangeEx();
4119
4129
  editor.addUndoSnapshot(function (start, end) {
4120
4130
  if (!beforeRunCallback || beforeRunCallback()) {
4121
4131
  var regions = editor.getSelectedRegions();
@@ -4123,7 +4133,12 @@ function blockFormat(editor, callback, beforeRunCallback) {
4123
4133
  regions.forEach(function (region) { return callback(region, start, end, chains_1); });
4124
4134
  (0, experimentCommitListChains_1.default)(editor, chains_1);
4125
4135
  }
4126
- editor.select(start, end);
4136
+ if (selection.type == 0 /* Normal */) {
4137
+ editor.select(start, end);
4138
+ }
4139
+ else {
4140
+ editor.select(selection.table, selection.coordinates);
4141
+ }
4127
4142
  }, "Format" /* Format */);
4128
4143
  }
4129
4144
  exports.default = blockFormat;
@@ -4271,8 +4286,7 @@ function execCommand(editor, command) {
4271
4286
  tempRange = range;
4272
4287
  });
4273
4288
  if (tempRange && selection.type == 1 /* TableSelection */) {
4274
- tempRange.collapse();
4275
- editor.select(tempRange);
4289
+ editor.select(selection.table, selection.coordinates);
4276
4290
  }
4277
4291
  }, "Format" /* Format */);
4278
4292
  }
@@ -4485,6 +4499,7 @@ var hasFocus_1 = __webpack_require__(/*! ./hasFocus */ "./packages/roosterjs-edi
4485
4499
  var insertNode_1 = __webpack_require__(/*! ./insertNode */ "./packages/roosterjs-editor-core/lib/coreApi/insertNode.ts");
4486
4500
  var restoreUndoSnapshot_1 = __webpack_require__(/*! ./restoreUndoSnapshot */ "./packages/roosterjs-editor-core/lib/coreApi/restoreUndoSnapshot.ts");
4487
4501
  var selectRange_1 = __webpack_require__(/*! ./selectRange */ "./packages/roosterjs-editor-core/lib/coreApi/selectRange.ts");
4502
+ var selectTable_1 = __webpack_require__(/*! ./selectTable */ "./packages/roosterjs-editor-core/lib/coreApi/selectTable.ts");
4488
4503
  var setContent_1 = __webpack_require__(/*! ./setContent */ "./packages/roosterjs-editor-core/lib/coreApi/setContent.ts");
4489
4504
  var switchShadowEdit_1 = __webpack_require__(/*! ./switchShadowEdit */ "./packages/roosterjs-editor-core/lib/coreApi/switchShadowEdit.ts");
4490
4505
  var transformColor_1 = __webpack_require__(/*! ./transformColor */ "./packages/roosterjs-editor-core/lib/coreApi/transformColor.ts");
@@ -4511,6 +4526,7 @@ exports.coreApiMap = {
4511
4526
  switchShadowEdit: switchShadowEdit_1.switchShadowEdit,
4512
4527
  transformColor: transformColor_1.transformColor,
4513
4528
  triggerEvent: triggerEvent_1.triggerEvent,
4529
+ selectTable: selectTable_1.selectTable,
4514
4530
  };
4515
4531
 
4516
4532
 
@@ -5029,9 +5045,6 @@ exports.getSelectionRange = getSelectionRange;
5029
5045
  Object.defineProperty(exports, "__esModule", { value: true });
5030
5046
  exports.getSelectionRangeEx = void 0;
5031
5047
  var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
5032
- var TABLE_SELECTED = '_tableSelected';
5033
- var TABLE_CELL_SELECTED_CLASS = '_tableCellSelected';
5034
- var TABLE_CELL_SELECTOR = "td." + TABLE_CELL_SELECTED_CLASS + ",th." + TABLE_CELL_SELECTED_CLASS;
5035
5048
  /**
5036
5049
  * @internal
5037
5050
  * Get current or cached selection range
@@ -5039,22 +5052,32 @@ var TABLE_CELL_SELECTOR = "td." + TABLE_CELL_SELECTED_CLASS + ",th." + TABLE_CEL
5039
5052
  * @returns A Range object of the selection range
5040
5053
  */
5041
5054
  var getSelectionRangeEx = function (core) {
5042
- var _a;
5055
+ var _a, _b;
5043
5056
  var result = null;
5044
5057
  if (core.lifecycle.shadowEditFragment) {
5045
- var shadowRange = core.lifecycle.shadowEditSelectionPath &&
5046
- (0, roosterjs_editor_dom_1.createRange)(core.contentDiv, core.lifecycle.shadowEditSelectionPath.start, core.lifecycle.shadowEditSelectionPath.end);
5047
- var tableSelected = getTableSelected(core.contentDiv);
5048
- if (tableSelected) {
5049
- return createTableSelectionEx(tableSelected);
5058
+ var _c = core.lifecycle, shadowEditTableSelectionPath = _c.shadowEditTableSelectionPath, shadowEditSelectionPath = _c.shadowEditSelectionPath;
5059
+ if ((shadowEditTableSelectionPath === null || shadowEditTableSelectionPath === void 0 ? void 0 : shadowEditTableSelectionPath.length) > 0) {
5060
+ var ranges = core.lifecycle.shadowEditTableSelectionPath.map(function (path) {
5061
+ return (0, roosterjs_editor_dom_1.createRange)(core.contentDiv, path.start, path.end);
5062
+ });
5063
+ return {
5064
+ type: 1 /* TableSelection */,
5065
+ ranges: ranges,
5066
+ areAllCollapsed: checkAllCollapsed(ranges),
5067
+ table: (0, roosterjs_editor_dom_1.findClosestElementAncestor)(ranges[0].startContainer, core.contentDiv, 'table'),
5068
+ coordinates: null,
5069
+ };
5070
+ }
5071
+ else {
5072
+ var shadowRange = shadowEditSelectionPath &&
5073
+ (0, roosterjs_editor_dom_1.createRange)(core.contentDiv, shadowEditSelectionPath.start, shadowEditSelectionPath.end);
5074
+ return createNormalSelectionEx(shadowRange ? [shadowRange] : []);
5050
5075
  }
5051
- return createNormalSelectionEx([shadowRange]);
5052
5076
  }
5053
5077
  else {
5054
5078
  if (core.api.hasFocus(core)) {
5055
- var tableSelected = getTableSelected(core.contentDiv);
5056
- if (tableSelected) {
5057
- return createTableSelectionEx(tableSelected);
5079
+ if (core.domEvent.tableSelectionRange) {
5080
+ return core.domEvent.tableSelectionRange;
5058
5081
  }
5059
5082
  var selection = (_a = core.contentDiv.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getSelection();
5060
5083
  if (!result && selection && selection.rangeCount > 0) {
@@ -5064,7 +5087,7 @@ var getSelectionRangeEx = function (core) {
5064
5087
  }
5065
5088
  }
5066
5089
  }
5067
- return createNormalSelectionEx([core.domEvent.selectionRange]);
5090
+ return ((_b = core.domEvent.tableSelectionRange) !== null && _b !== void 0 ? _b : createNormalSelectionEx(core.domEvent.selectionRange ? [core.domEvent.selectionRange] : []));
5068
5091
  }
5069
5092
  };
5070
5093
  exports.getSelectionRangeEx = getSelectionRangeEx;
@@ -5075,45 +5098,9 @@ function createNormalSelectionEx(ranges) {
5075
5098
  areAllCollapsed: checkAllCollapsed(ranges),
5076
5099
  };
5077
5100
  }
5078
- function createTableSelectionEx(table) {
5079
- var ranges = getRangesFromTable(table);
5080
- return {
5081
- type: 1 /* TableSelection */,
5082
- ranges: ranges,
5083
- table: table,
5084
- areAllCollapsed: checkAllCollapsed(ranges),
5085
- };
5086
- }
5087
- function getRangesFromTable(table) {
5088
- var ranges = [];
5089
- table.querySelectorAll('tr').forEach(function (row) {
5090
- var rowRange = new Range();
5091
- var firstSelected = null;
5092
- var lastSelected = null;
5093
- row.querySelectorAll(TABLE_CELL_SELECTOR).forEach(function (cell) {
5094
- if ((0, roosterjs_editor_dom_1.safeInstanceOf)(cell, 'HTMLTableCellElement')) {
5095
- firstSelected = firstSelected || cell;
5096
- lastSelected = cell;
5097
- }
5098
- });
5099
- if (firstSelected) {
5100
- rowRange.setStartBefore(firstSelected);
5101
- rowRange.setEndAfter(lastSelected);
5102
- ranges.push(rowRange);
5103
- }
5104
- });
5105
- return ranges;
5106
- }
5107
5101
  function checkAllCollapsed(ranges) {
5108
5102
  return ranges.filter(function (range) { return range === null || range === void 0 ? void 0 : range.collapsed; }).length == ranges.length;
5109
5103
  }
5110
- function getTableSelected(container) {
5111
- var table = container.querySelector('table.' + TABLE_SELECTED);
5112
- if ((0, roosterjs_editor_dom_1.safeInstanceOf)(table, 'HTMLTableElement')) {
5113
- return table;
5114
- }
5115
- return null;
5116
- }
5117
5104
 
5118
5105
 
5119
5106
  /***/ }),
@@ -5435,6 +5422,188 @@ function restorePendingFormatState(core) {
5435
5422
  }
5436
5423
 
5437
5424
 
5425
+ /***/ }),
5426
+
5427
+ /***/ "./packages/roosterjs-editor-core/lib/coreApi/selectTable.ts":
5428
+ /*!*******************************************************************!*\
5429
+ !*** ./packages/roosterjs-editor-core/lib/coreApi/selectTable.ts ***!
5430
+ \*******************************************************************/
5431
+ /*! no static exports found */
5432
+ /***/ (function(module, exports, __webpack_require__) {
5433
+
5434
+ "use strict";
5435
+
5436
+ Object.defineProperty(exports, "__esModule", { value: true });
5437
+ exports.selectTable = void 0;
5438
+ var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
5439
+ var TABLE_ID = 'tableSelected';
5440
+ var CONTENT_DIV_ID = 'contentDiv_';
5441
+ var STYLE_ID = 'tableStyle';
5442
+ /**
5443
+ * @internal
5444
+ * Select a table and save data of the selected range
5445
+ * @param core The EditorCore object
5446
+ * @param table table to select
5447
+ * @param coordinates first and last cell of the selection, if this parameter is null, instead of
5448
+ * selecting, will unselect the table.
5449
+ * @returns true if successful
5450
+ */
5451
+ var selectTable = function (core, table, coordinates) {
5452
+ unselect(core);
5453
+ if (coordinates && table) {
5454
+ ensureUniqueId(table, TABLE_ID);
5455
+ ensureUniqueId(core.contentDiv, CONTENT_DIV_ID);
5456
+ var ranges = select(core, table, coordinates);
5457
+ core.api.selectRange(core, (0, roosterjs_editor_dom_1.createRange)(new roosterjs_editor_dom_1.Position(table.rows.item(coordinates.firstCell.y).cells.item(coordinates.firstCell.x), 0 /* Begin */)));
5458
+ return {
5459
+ type: 1 /* TableSelection */,
5460
+ ranges: ranges,
5461
+ table: table,
5462
+ areAllCollapsed: ranges.filter(function (range) { return range === null || range === void 0 ? void 0 : range.collapsed; }).length == ranges.length,
5463
+ coordinates: coordinates,
5464
+ };
5465
+ }
5466
+ return null;
5467
+ };
5468
+ exports.selectTable = selectTable;
5469
+ function buildCss(table, coordinates, contentDivSelector) {
5470
+ var tr1 = coordinates.firstCell.y;
5471
+ var td1 = coordinates.firstCell.x;
5472
+ var tr2 = coordinates.lastCell.y;
5473
+ var td2 = coordinates.lastCell.x;
5474
+ var ranges = [];
5475
+ var firstSelected = null;
5476
+ var lastSelected = null;
5477
+ var css = '';
5478
+ var isFirst = true;
5479
+ var vTable = new roosterjs_editor_dom_1.VTable(table);
5480
+ // Get whether table has thead, tbody or tfoot.
5481
+ var tableChildren = (0, roosterjs_editor_dom_1.toArray)(table.childNodes).filter(function (node) { return ['THEAD', 'TBODY', 'TFOOT'].indexOf((0, roosterjs_editor_dom_1.getTagOfNode)(node)) > -1; });
5482
+ // Set the start and end of each of the table childs, so we can build the selector according the element between the table and the row.
5483
+ var cont = 0;
5484
+ var indexes = tableChildren.map(function (node) {
5485
+ var result = {
5486
+ el: (0, roosterjs_editor_dom_1.getTagOfNode)(node),
5487
+ start: cont,
5488
+ end: node.childNodes.length + cont,
5489
+ };
5490
+ cont = result.end;
5491
+ return result;
5492
+ });
5493
+ vTable.cells.forEach(function (row, rowIndex) {
5494
+ var tdCount = 0;
5495
+ var thCount = 0;
5496
+ firstSelected = null;
5497
+ lastSelected = null;
5498
+ //Get current TBODY/THEAD/TFOOT
5499
+ var midElement = indexes.filter(function (ind) { return ind.start <= rowIndex && ind.end > rowIndex; })[0];
5500
+ var middleElSelector = midElement ? '>' + midElement.el + '>' : '>';
5501
+ var currentRow = midElement && rowIndex + 1 >= midElement.start
5502
+ ? rowIndex + 1 - midElement.start
5503
+ : rowIndex + 1;
5504
+ for (var cellIndex = 0; cellIndex < row.length; cellIndex++) {
5505
+ if (row[cellIndex].td) {
5506
+ var tag = (0, roosterjs_editor_dom_1.getTagOfNode)(row[cellIndex].td);
5507
+ if (tag == 'TD') {
5508
+ tdCount++;
5509
+ }
5510
+ if (tag == 'TH') {
5511
+ thCount++;
5512
+ }
5513
+ if (rowIndex >= tr1 && rowIndex <= tr2 && cellIndex >= td1 && cellIndex <= td2) {
5514
+ if (isFirst) {
5515
+ isFirst = false;
5516
+ }
5517
+ else if (!css.endsWith(',')) {
5518
+ css += ',';
5519
+ }
5520
+ removeImportant(row[cellIndex].td);
5521
+ var selector = generateCssFromCell(contentDivSelector, table.id, middleElSelector, currentRow, tag, tag == 'TD' ? tdCount : thCount);
5522
+ css += selector;
5523
+ firstSelected = firstSelected || table.querySelector(selector);
5524
+ lastSelected = table.querySelector(selector);
5525
+ }
5526
+ }
5527
+ }
5528
+ if (firstSelected && lastSelected) {
5529
+ var rowRange = new Range();
5530
+ rowRange.setStartBefore(firstSelected);
5531
+ rowRange.setEndAfter(lastSelected);
5532
+ ranges.push(rowRange);
5533
+ }
5534
+ });
5535
+ css += '{background-color: rgba(198,198,198,0.7) !important;}';
5536
+ return { css: css, ranges: ranges };
5537
+ }
5538
+ function select(core, table, coordinates) {
5539
+ var doc = core.contentDiv.ownerDocument;
5540
+ var contentDivSelector = '#' + core.contentDiv.id;
5541
+ var _a = buildCss(table, coordinates, contentDivSelector), css = _a.css, ranges = _a.ranges;
5542
+ var styleElement = doc.getElementById(STYLE_ID + core.contentDiv.id);
5543
+ if (!styleElement) {
5544
+ styleElement = doc.createElement('style');
5545
+ doc.head.appendChild(styleElement);
5546
+ styleElement.id = STYLE_ID + core.contentDiv.id;
5547
+ }
5548
+ styleElement.sheet.insertRule(css);
5549
+ return ranges;
5550
+ }
5551
+ function unselect(core) {
5552
+ var _a;
5553
+ var div = core.contentDiv;
5554
+ var styleElement = div.ownerDocument.getElementById(STYLE_ID + div.id);
5555
+ if ((_a = styleElement === null || styleElement === void 0 ? void 0 : styleElement.sheet) === null || _a === void 0 ? void 0 : _a.cssRules) {
5556
+ while (styleElement.sheet.cssRules.length > 0) {
5557
+ styleElement.sheet.deleteRule(0);
5558
+ }
5559
+ }
5560
+ }
5561
+ function ensureUniqueId(el, idPrefix) {
5562
+ if (el && !el.id) {
5563
+ var doc = el.ownerDocument;
5564
+ var getElement = function (doc) { return doc.getElementById(idPrefix + cont_1); };
5565
+ var cont_1 = 0;
5566
+ //Ensure that there are no elements with the same ID
5567
+ var element = getElement(doc);
5568
+ while (element) {
5569
+ element = getElement(doc);
5570
+ cont_1++;
5571
+ }
5572
+ el.id = idPrefix + cont_1;
5573
+ }
5574
+ }
5575
+ function generateCssFromCell(contentDivSelector, tableId, middleElSelector, rowIndex, cellTag, index) {
5576
+ return (contentDivSelector +
5577
+ ' #' +
5578
+ tableId +
5579
+ middleElSelector +
5580
+ ' tr:nth-child(' +
5581
+ rowIndex +
5582
+ ')>' +
5583
+ cellTag +
5584
+ ':nth-child(' +
5585
+ index +
5586
+ ')');
5587
+ }
5588
+ function removeImportant(cell) {
5589
+ if (cell) {
5590
+ var styles_1 = (0, roosterjs_editor_dom_1.getStyles)(cell);
5591
+ var modifiedStyles_1 = 0;
5592
+ ['background-color', 'background'].forEach(function (style) {
5593
+ var _a;
5594
+ if (((_a = styles_1[style]) === null || _a === void 0 ? void 0 : _a.indexOf('!important')) > -1) {
5595
+ var index = styles_1[style].indexOf('!');
5596
+ styles_1[style] = styles_1[style].substring(0, index);
5597
+ modifiedStyles_1++;
5598
+ }
5599
+ });
5600
+ if (modifiedStyles_1 > 0) {
5601
+ (0, roosterjs_editor_dom_1.setStyles)(cell, styles_1);
5602
+ }
5603
+ }
5604
+ }
5605
+
5606
+
5438
5607
  /***/ }),
5439
5608
 
5440
5609
  /***/ "./packages/roosterjs-editor-core/lib/coreApi/setContent.ts":
@@ -5499,12 +5668,15 @@ var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./
5499
5668
  */
5500
5669
  var switchShadowEdit = function (core, isOn) {
5501
5670
  var lifecycle = core.lifecycle, contentDiv = core.contentDiv;
5502
- var shadowEditFragment = lifecycle.shadowEditFragment, shadowEditSelectionPath = lifecycle.shadowEditSelectionPath;
5671
+ var shadowEditFragment = lifecycle.shadowEditFragment, shadowEditSelectionPath = lifecycle.shadowEditSelectionPath, shadowEditTableSelectionPath = lifecycle.shadowEditTableSelectionPath;
5503
5672
  var wasInShadowEdit = !!shadowEditFragment;
5504
5673
  if (isOn) {
5505
5674
  if (!wasInShadowEdit) {
5675
+ var selection = core.api.getSelectionRangeEx(core);
5506
5676
  var range = core.api.getSelectionRange(core, true /*tryGetFromCache*/);
5507
5677
  shadowEditSelectionPath = range && (0, roosterjs_editor_dom_1.getSelectionPath)(contentDiv, range);
5678
+ shadowEditTableSelectionPath =
5679
+ selection && selection.ranges.map(function (range) { return (0, roosterjs_editor_dom_1.getSelectionPath)(contentDiv, range); });
5508
5680
  shadowEditFragment = core.contentDiv.ownerDocument.createDocumentFragment();
5509
5681
  (0, roosterjs_editor_dom_1.moveChildNodes)(shadowEditFragment, contentDiv);
5510
5682
  shadowEditFragment.normalize();
@@ -5515,6 +5687,7 @@ var switchShadowEdit = function (core, isOn) {
5515
5687
  }, false /*broadcast*/);
5516
5688
  lifecycle.shadowEditFragment = shadowEditFragment;
5517
5689
  lifecycle.shadowEditSelectionPath = shadowEditSelectionPath;
5690
+ lifecycle.shadowEditTableSelectionPath = shadowEditTableSelectionPath;
5518
5691
  }
5519
5692
  (0, roosterjs_editor_dom_1.moveChildNodes)(contentDiv);
5520
5693
  contentDiv.appendChild(lifecycle.shadowEditFragment.cloneNode(true /*deep*/));
@@ -5532,6 +5705,14 @@ var switchShadowEdit = function (core, isOn) {
5532
5705
  if (shadowEditSelectionPath) {
5533
5706
  core.api.selectRange(core, (0, roosterjs_editor_dom_1.createRange)(contentDiv, shadowEditSelectionPath.start, shadowEditSelectionPath.end));
5534
5707
  }
5708
+ if (core.domEvent.tableSelectionRange) {
5709
+ var _a = core.domEvent.tableSelectionRange, table = _a.table, coordinates = _a.coordinates;
5710
+ var tableId = table.id;
5711
+ var tableElement = core.contentDiv.querySelector('#' + tableId);
5712
+ if (table) {
5713
+ core.domEvent.tableSelectionRange = core.api.selectTable(core, tableElement, coordinates);
5714
+ }
5715
+ }
5535
5716
  }
5536
5717
  }
5537
5718
  };
@@ -5656,6 +5837,12 @@ function getAll(rootNode, includeSelf) {
5656
5837
 
5657
5838
  Object.defineProperty(exports, "__esModule", { value: true });
5658
5839
  exports.triggerEvent = void 0;
5840
+ var allowedEventsInShadowEdit = [
5841
+ 11 /* EditorReady */,
5842
+ 12 /* BeforeDispose */,
5843
+ 8 /* ExtractContentWithDom */,
5844
+ 21 /* ZoomChanged */,
5845
+ ];
5659
5846
  /**
5660
5847
  * @internal
5661
5848
  * Trigger a plugin event
@@ -5665,7 +5852,7 @@ exports.triggerEvent = void 0;
5665
5852
  */
5666
5853
  var triggerEvent = function (core, pluginEvent, broadcast) {
5667
5854
  if ((!core.lifecycle.shadowEditFragment ||
5668
- pluginEvent.eventType == 12 /* BeforeDispose */) &&
5855
+ allowedEventsInShadowEdit.indexOf(pluginEvent.eventType) >= 0) &&
5669
5856
  (broadcast || !core.plugins.some(function (plugin) { return handledExclusively(pluginEvent, plugin); }))) {
5670
5857
  core.plugins.forEach(function (plugin) {
5671
5858
  if (plugin.onPluginEvent) {
@@ -5861,7 +6048,13 @@ var DOMEventPlugin = /** @class */ (function () {
5861
6048
  });
5862
6049
  };
5863
6050
  this.onFocus = function () {
5864
- _this.editor.select(_this.state.selectionRange);
6051
+ var _a = _this.state.tableSelectionRange || {}, table = _a.table, coordinates = _a.coordinates;
6052
+ if (table && coordinates) {
6053
+ _this.editor.select(table, coordinates);
6054
+ }
6055
+ else {
6056
+ _this.editor.select(_this.state.selectionRange);
6057
+ }
5865
6058
  _this.state.selectionRange = null;
5866
6059
  };
5867
6060
  this.onKeyDownDocument = function (event) {
@@ -5921,6 +6114,7 @@ var DOMEventPlugin = /** @class */ (function () {
5921
6114
  selectionRange: null,
5922
6115
  stopPrintableKeyboardEventPropagation: !options.allowKeyboardEventPropagation,
5923
6116
  contextMenuProviders: ((_a = options.plugins) === null || _a === void 0 ? void 0 : _a.filter(isContextMenuProvider)) || [],
6117
+ tableSelectionRange: null,
5924
6118
  };
5925
6119
  }
5926
6120
  /**
@@ -6556,6 +6750,7 @@ var LifecyclePlugin = /** @class */ (function () {
6556
6750
  experimentalFeatures: options.experimentalFeatures || [],
6557
6751
  shadowEditFragment: null,
6558
6752
  shadowEditSelectionPath: null,
6753
+ shadowEditTableSelectionPath: null,
6559
6754
  };
6560
6755
  }
6561
6756
  /**
@@ -7228,7 +7423,8 @@ var Editor = /** @class */ (function () {
7228
7423
  plugins.push(corePlugins[name]);
7229
7424
  }
7230
7425
  });
7231
- this.core = __assign(__assign({ contentDiv: contentDiv, api: __assign(__assign({}, coreApiMap_1.coreApiMap), (options.coreApiOverride || {})), plugins: plugins.filter(function (x) { return !!x; }) }, (0, createCorePlugins_1.getPluginState)(corePlugins)), { trustedHTMLHandler: options.trustedHTMLHandler || (function (html) { return html; }), sizeTransformer: options.sizeTransformer || (function (size) { return size; }) });
7426
+ var zoomScale = options.zoomScale > 0 ? options.zoomScale : 1;
7427
+ this.core = __assign(__assign({ contentDiv: contentDiv, api: __assign(__assign({}, coreApiMap_1.coreApiMap), (options.coreApiOverride || {})), plugins: plugins.filter(function (x) { return !!x; }) }, (0, createCorePlugins_1.getPluginState)(corePlugins)), { trustedHTMLHandler: options.trustedHTMLHandler || (function (html) { return html; }), zoomScale: zoomScale, sizeTransformer: options.sizeTransformer || (function (size) { return size / zoomScale; }) });
7232
7428
  // 3. Initialize plugins
7233
7429
  this.core.plugins.forEach(function (plugin) { return plugin.initialize(_this); });
7234
7430
  // 4. Ensure user will type in a container node, not the editor content DIV
@@ -7469,6 +7665,16 @@ var Editor = /** @class */ (function () {
7469
7665
  this.core.api.focus(this.core);
7470
7666
  };
7471
7667
  Editor.prototype.select = function (arg1, arg2, arg3, arg4) {
7668
+ var _a;
7669
+ if (!!((_a = arg1) === null || _a === void 0 ? void 0 : _a.rows)) {
7670
+ var selection = this.core.api.selectTable(this.core, arg1, arg2);
7671
+ this.core.domEvent.tableSelectionRange = selection;
7672
+ return !!selection;
7673
+ }
7674
+ else {
7675
+ this.core.api.selectTable(this.core, null);
7676
+ this.core.domEvent.tableSelectionRange = null;
7677
+ }
7472
7678
  var range = !arg1
7473
7679
  ? null
7474
7680
  : (0, roosterjs_editor_dom_1.safeInstanceOf)(arg1, 'Range')
@@ -7850,11 +8056,38 @@ var Editor = /** @class */ (function () {
7850
8056
  return this.core.trustedHTMLHandler;
7851
8057
  };
7852
8058
  /**
7853
- * Get a transformer function. It transform the size changes according to current situation.
8059
+ * @deprecated Use getZoomScale() instead
7854
8060
  */
7855
8061
  Editor.prototype.getSizeTransformer = function () {
7856
8062
  return this.core.sizeTransformer;
7857
8063
  };
8064
+ /**
8065
+ * Get current zoom scale, default value is 1
8066
+ * When editor is put under a zoomed container, need to pass the zoom scale number using EditorOptions.zoomScale
8067
+ * to let editor behave correctly especially for those mouse drag/drop behaviors
8068
+ * @returns current zoom scale number
8069
+ */
8070
+ Editor.prototype.getZoomScale = function () {
8071
+ return this.core.zoomScale;
8072
+ };
8073
+ /**
8074
+ * Set current zoom scale, default value is 1
8075
+ * When editor is put under a zoomed container, need to pass the zoom scale number using EditorOptions.zoomScale
8076
+ * to let editor behave correctly especially for those mouse drag/drop behaviors
8077
+ * @param scale The new scale number to set. It should be positive number and no greater than 10, otherwise it will be ignored.
8078
+ */
8079
+ Editor.prototype.setZoomScale = function (scale) {
8080
+ if (scale > 0 && scale <= 10) {
8081
+ var oldValue = this.core.zoomScale;
8082
+ this.core.zoomScale = scale;
8083
+ if (oldValue != scale) {
8084
+ this.triggerPluginEvent(21 /* ZoomChanged */, {
8085
+ oldZoomScale: oldValue,
8086
+ newZoomScale: scale,
8087
+ }, true /*broadcast*/);
8088
+ }
8089
+ }
8090
+ };
7858
8091
  return Editor;
7859
8092
  }());
7860
8093
  exports.default = Editor;
@@ -8251,8 +8484,9 @@ var toArray_1 = __webpack_require__(/*! ../utils/toArray */ "./packages/roosterj
8251
8484
  * not supported by browser.
8252
8485
  */
8253
8486
  function extractClipboardEvent(event, callback, options) {
8487
+ var _a;
8254
8488
  var dataTransfer = event.clipboardData ||
8255
- event.target.ownerDocument.defaultView.clipboardData;
8489
+ ((_a = event.target.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView).clipboardData;
8256
8490
  if (dataTransfer.items) {
8257
8491
  event.preventDefault();
8258
8492
  (0, extractClipboardItems_1.default)((0, toArray_1.default)(dataTransfer.items), options).then(callback);
@@ -8307,7 +8541,7 @@ var ContentHandlers = (_a = {},
8307
8541
  return (data.rawHtml = Browser_1.Browser.isEdge ? workaroundForEdge(value) : value);
8308
8542
  },
8309
8543
  _a["text/plain" /* PlainText */] = function (data, value) { return (data.text = value); },
8310
- _a[OTHER_TEXT_TYPE] = function (data, value, type) { return (data.customValues[type] = value); },
8544
+ _a[OTHER_TEXT_TYPE] = function (data, value, type) { return !!type && (data.customValues[type] = value); },
8311
8545
  _a);
8312
8546
  /**
8313
8547
  * Extract clipboard items to be a ClipboardData object for IE
@@ -8339,10 +8573,15 @@ function extractClipboardItems(items, options) {
8339
8573
  data.types.push(type);
8340
8574
  data.image = item.getAsFile();
8341
8575
  return new Promise(function (resolve) {
8342
- (0, readFile_1.default)(data.image, function (dataUrl) {
8343
- data.imageDataUri = dataUrl;
8576
+ if (data.image) {
8577
+ (0, readFile_1.default)(data.image, function (dataUrl) {
8578
+ data.imageDataUri = dataUrl;
8579
+ resolve();
8580
+ });
8581
+ }
8582
+ else {
8344
8583
  resolve();
8345
- });
8584
+ }
8346
8585
  });
8347
8586
  }
8348
8587
  else {
@@ -8386,9 +8625,10 @@ function tryParseLinkPreview(data, value) {
8386
8625
  }
8387
8626
  function getAllowedCustomType(type, allowedCustomPasteType) {
8388
8627
  var textType = type.indexOf("text/" /* Text */) == 0
8389
- ? type.substr("text/" /* Text */.length)
8628
+ ? type.substring("text/" /* Text */.length)
8390
8629
  : null;
8391
- return textType && (allowedCustomPasteType === null || allowedCustomPasteType === void 0 ? void 0 : allowedCustomPasteType.indexOf(textType)) >= 0 ? textType : null;
8630
+ var index = allowedCustomPasteType && textType ? allowedCustomPasteType.indexOf(textType) : -1;
8631
+ return textType && index >= 0 ? textType : undefined;
8392
8632
  }
8393
8633
 
8394
8634
 
@@ -8419,7 +8659,7 @@ var toArray_1 = __webpack_require__(/*! ../utils/toArray */ "./packages/roosterj
8419
8659
  * not supported by browser.
8420
8660
  */
8421
8661
  function extractClipboardItemsForIE(dataTransfer, callback, options) {
8422
- var _a;
8662
+ var _a, _b, _c;
8423
8663
  var clipboardData = {
8424
8664
  types: dataTransfer.types ? (0, toArray_1.default)(dataTransfer.types) : [],
8425
8665
  text: dataTransfer.getData('text'),
@@ -8429,7 +8669,7 @@ function extractClipboardItemsForIE(dataTransfer, callback, options) {
8429
8669
  };
8430
8670
  for (var i = 0; i < (dataTransfer.files ? dataTransfer.files.length : 0); i++) {
8431
8671
  var file = dataTransfer.files.item(i);
8432
- if (((_a = file.type) === null || _a === void 0 ? void 0 : _a.indexOf("image/" /* Image */)) == 0) {
8672
+ if (((_a = file === null || file === void 0 ? void 0 : file.type) === null || _a === void 0 ? void 0 : _a.indexOf("image/" /* Image */)) == 0) {
8433
8673
  clipboardData.image = file;
8434
8674
  break;
8435
8675
  }
@@ -8450,9 +8690,10 @@ function extractClipboardItemsForIE(dataTransfer, callback, options) {
8450
8690
  div_1.contentEditable = 'true';
8451
8691
  div_1.innerHTML = '';
8452
8692
  div_1.focus();
8453
- div_1.ownerDocument.defaultView.setTimeout(function () {
8693
+ (_c = (_b = div_1.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView) === null || _c === void 0 ? void 0 : _c.setTimeout(function () {
8694
+ var _a;
8454
8695
  clipboardData.rawHtml = div_1.innerHTML;
8455
- options.removeTempDiv(div_1);
8696
+ (_a = options.removeTempDiv) === null || _a === void 0 ? void 0 : _a.call(options, div_1);
8456
8697
  nextStep();
8457
8698
  }, 0);
8458
8699
  }
@@ -9664,7 +9905,7 @@ var isModifierKey_1 = __webpack_require__(/*! ./isModifierKey */ "./packages/roo
9664
9905
  * @param event The keyboard event object
9665
9906
  */
9666
9907
  function isCharacterValue(event) {
9667
- return !(0, isModifierKey_1.default)(event) && event.key && event.key.length == 1;
9908
+ return !(0, isModifierKey_1.default)(event) && !!event.key && event.key.length == 1;
9668
9909
  }
9669
9910
  exports.default = isCharacterValue;
9670
9911
 
@@ -9765,10 +10006,10 @@ var HtmlSanitizer = /** @class */ (function () {
9765
10006
  this.allowedAttributes = (0, getAllowedValues_1.getAllowedAttributes)(options.additionalAllowedAttributes);
9766
10007
  this.allowedCssClassesRegex = (0, getAllowedValues_1.getAllowedCssClassesRegex)(options.additionalAllowedCssClasses);
9767
10008
  this.defaultStyleValues = (0, getAllowedValues_1.getDefaultStyleValues)(options.additionalDefaultStyleValues);
9768
- this.additionalPredefinedCssForElement = options.additionalPredefinedCssForElement;
10009
+ this.additionalPredefinedCssForElement = options.additionalPredefinedCssForElement || null;
9769
10010
  this.additionalGlobalStyleNodes = options.additionalGlobalStyleNodes || [];
9770
- this.preserveHtmlComments = options.preserveHtmlComments;
9771
- this.unknownTagReplacement = options.unknownTagReplacement;
10011
+ this.preserveHtmlComments = options.preserveHtmlComments || false;
10012
+ this.unknownTagReplacement = options.unknownTagReplacement || null;
9772
10013
  }
9773
10014
  /**
9774
10015
  * @deprecated Use new HtmlSanitizer().convertGlobalCssToInlineCss() instead
@@ -9877,6 +10118,7 @@ var HtmlSanitizer = /** @class */ (function () {
9877
10118
  });
9878
10119
  };
9879
10120
  HtmlSanitizer.prototype.processNode = function (node, currentStyle, context) {
10121
+ var _a;
9880
10122
  var nodeType = node.nodeType;
9881
10123
  var isElement = nodeType == 1 /* Element */;
9882
10124
  var isText = nodeType == 3 /* Text */;
@@ -9910,7 +10152,7 @@ var HtmlSanitizer = /** @class */ (function () {
9910
10152
  whiteSpace == 'pre' ||
9911
10153
  whiteSpace == 'pre-line' ||
9912
10154
  whiteSpace == 'pre-wrap' ||
9913
- !/^[\r\n]*$/g.test(node.nodeValue);
10155
+ !/^[\r\n]*$/g.test(node.nodeValue || '');
9914
10156
  }
9915
10157
  else if (isFragment) {
9916
10158
  shouldKeep = true;
@@ -9922,11 +10164,13 @@ var HtmlSanitizer = /** @class */ (function () {
9922
10164
  shouldKeep = false;
9923
10165
  }
9924
10166
  if (!shouldKeep) {
9925
- node.parentNode.removeChild(node);
10167
+ (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(node);
9926
10168
  }
9927
10169
  else if (isText &&
9928
10170
  (currentStyle['white-space'] == 'pre' || currentStyle['white-space'] == 'pre-wrap')) {
9929
- node.nodeValue = node.nodeValue.replace(/^ /gm, '\u00A0').replace(/ {2}/g, ' \u00A0');
10171
+ node.nodeValue = (node.nodeValue || '')
10172
+ .replace(/^ /gm, '\u00A0')
10173
+ .replace(/ {2}/g, ' \u00A0');
9930
10174
  }
9931
10175
  else if (isElement || isFragment) {
9932
10176
  var thisStyle = (0, cloneObject_1.cloneObject)(currentStyle);
@@ -10005,12 +10249,13 @@ var HtmlSanitizer = /** @class */ (function () {
10005
10249
  var originalClasses = originalValue ? originalValue.split(' ') : [];
10006
10250
  var calculatedClasses = calculatedValue ? calculatedValue.split(' ') : [];
10007
10251
  originalClasses.forEach(function (className) {
10008
- if (_this.allowedCssClassesRegex.test(className) &&
10252
+ var _a;
10253
+ if (((_a = _this.allowedCssClassesRegex) === null || _a === void 0 ? void 0 : _a.test(className)) &&
10009
10254
  calculatedClasses.indexOf(className) < 0) {
10010
10255
  calculatedClasses.push(className);
10011
10256
  }
10012
10257
  });
10013
- return calculatedClasses.length > 0 ? calculatedClasses.join(' ') : null;
10258
+ return (calculatedClasses === null || calculatedClasses === void 0 ? void 0 : calculatedClasses.length) > 0 ? calculatedClasses.join(' ') : null;
10014
10259
  };
10015
10260
  return HtmlSanitizer;
10016
10261
  }());
@@ -10082,6 +10327,7 @@ function customClone(source, existingObj) {
10082
10327
  }
10083
10328
  return result;
10084
10329
  }
10330
+ // @ts-ignore Ignore this error for IE compatibility
10085
10331
  var cloneObjectImpl = Object.assign ? nativeClone : customClone;
10086
10332
  /**
10087
10333
  * @internal
@@ -10424,7 +10670,7 @@ var INHERITABLE_PROPERTIES = ('border-spacing,caption-side,color,' +
10424
10670
  */
10425
10671
  function getInheritableStyles(element) {
10426
10672
  var win = element && element.ownerDocument && element.ownerDocument.defaultView;
10427
- var styles = win && win.getComputedStyle(element);
10673
+ var styles = win && element && win.getComputedStyle(element);
10428
10674
  var result = {};
10429
10675
  INHERITABLE_PROPERTIES.forEach(function (name) { return (result[name] = (styles && styles.getPropertyValue(name)) || ''); });
10430
10676
  return result;
@@ -13676,16 +13922,38 @@ exports.default = setStyles;
13676
13922
 
13677
13923
  "use strict";
13678
13924
 
13925
+ var __assign = (this && this.__assign) || function () {
13926
+ __assign = Object.assign || function(t) {
13927
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
13928
+ s = arguments[i];
13929
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13930
+ t[p] = s[p];
13931
+ }
13932
+ return t;
13933
+ };
13934
+ return __assign.apply(this, arguments);
13935
+ };
13679
13936
  Object.defineProperty(exports, "__esModule", { value: true });
13680
- var changeElementTag_1 = __webpack_require__(/*! ../utils/changeElementTag */ "./packages/roosterjs-editor-dom/lib/utils/changeElementTag.ts");
13937
+ var applyTableFormat_1 = __webpack_require__(/*! ../utils/applyTableFormat */ "./packages/roosterjs-editor-dom/lib/utils/applyTableFormat.ts");
13681
13938
  var moveChildNodes_1 = __webpack_require__(/*! ../utils/moveChildNodes */ "./packages/roosterjs-editor-dom/lib/utils/moveChildNodes.ts");
13682
13939
  var normalizeRect_1 = __webpack_require__(/*! ../utils/normalizeRect */ "./packages/roosterjs-editor-dom/lib/utils/normalizeRect.ts");
13683
13940
  var safeInstanceOf_1 = __webpack_require__(/*! ../utils/safeInstanceOf */ "./packages/roosterjs-editor-dom/lib/utils/safeInstanceOf.ts");
13684
13941
  var toArray_1 = __webpack_require__(/*! ../utils/toArray */ "./packages/roosterjs-editor-dom/lib/utils/toArray.ts");
13685
- var tableFormatInfo_1 = __webpack_require__(/*! ../utils/tableFormatInfo */ "./packages/roosterjs-editor-dom/lib/utils/tableFormatInfo.ts");
13686
- var TRANSPARENT = 'transparent';
13687
- var TABLE_CELL_TAG_NAME = 'TD';
13688
- var TABLE_HEADER_TAG_NAME = 'TH';
13942
+ var tableFormatInfo_1 = __webpack_require__(/*! ./tableFormatInfo */ "./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts");
13943
+ var CELL_SHADE = 'cellShade';
13944
+ var DEFAULT_FORMAT = {
13945
+ topBorderColor: '#ABABAB',
13946
+ bottomBorderColor: '#ABABAB',
13947
+ verticalBorderColor: '#ABABAB',
13948
+ hasHeaderRow: false,
13949
+ hasFirstColumn: false,
13950
+ hasBandedRows: false,
13951
+ hasBandedColumns: false,
13952
+ bgColorEven: null,
13953
+ bgColorOdd: '#ABABAB20',
13954
+ headerRowColor: '#ABABAB',
13955
+ tableBorderFormat: 0 /* DEFAULT */,
13956
+ };
13689
13957
  /**
13690
13958
  * A virtual table class, represent an HTML table, by expand all merged cells to each separated cells
13691
13959
  */
@@ -13694,9 +13962,9 @@ var VTable = /** @class */ (function () {
13694
13962
  * Create a new instance of VTable object using HTML TABLE or TD node
13695
13963
  * @param node The HTML Table or TD node
13696
13964
  * @param normalizeSize Whether table size needs to be normalized
13697
- * @param sizeTransformer A size transformer function used for normalize table size
13965
+ * @param zoomScale When the table is under a zoomed container, pass in the zoom scale here
13698
13966
  */
13699
- function VTable(node, normalizeSize, sizeTransformer) {
13967
+ function VTable(node, normalizeSize, zoomScale) {
13700
13968
  var _this = this;
13701
13969
  this.trs = [];
13702
13970
  this.table = (0, safeInstanceOf_1.default)(node, 'HTMLTableElement') ? node : getTableFromTd(node);
@@ -13731,7 +13999,7 @@ var VTable = /** @class */ (function () {
13731
13999
  });
13732
14000
  this.formatInfo = (0, tableFormatInfo_1.getTableFormatInfo)(this.table);
13733
14001
  if (normalizeSize) {
13734
- this.normalizeSize(sizeTransformer);
14002
+ this.normalizeSize(typeof zoomScale == 'number' ? function (n) { return n / zoomScale; } : zoomScale);
13735
14003
  }
13736
14004
  }
13737
14005
  }
@@ -13753,8 +14021,8 @@ var VTable = /** @class */ (function () {
13753
14021
  });
13754
14022
  });
13755
14023
  if (this.formatInfo) {
13756
- this.applyFormat(this.formatInfo);
13757
14024
  (0, tableFormatInfo_1.saveTableInfo)(this.table, this.formatInfo);
14025
+ (0, applyTableFormat_1.default)(this.table, this.cells, this.formatInfo);
13758
14026
  }
13759
14027
  }
13760
14028
  else if (this.table) {
@@ -13769,242 +14037,20 @@ var VTable = /** @class */ (function () {
13769
14037
  if (!this.table) {
13770
14038
  return;
13771
14039
  }
13772
- this.formatInfo = format ? format : this.formatInfo;
13773
- this.table.style.borderCollapse = 'collapse';
13774
- this.setBordersType(this.formatInfo);
13775
- this.setColor(this.formatInfo);
13776
- this.setFirstColumnFormat(this.formatInfo);
13777
- this.setHeaderRowFormat(this.formatInfo);
14040
+ this.formatInfo = __assign(__assign(__assign({}, DEFAULT_FORMAT), (this.formatInfo || {})), (format || {}));
14041
+ this.deleteCellShadeDataset(this.cells);
13778
14042
  };
13779
14043
  /**
13780
- * Set color to the table
13781
- * @param format
14044
+ * Remove the cellshade dataset to apply a new style format at the cell.
14045
+ * @param cells
13782
14046
  */
13783
- VTable.prototype.setColor = function (format) {
13784
- var color = function (index) { return (index % 2 === 0 ? format.bgColorEven : format.bgColorOdd); };
13785
- var hasBandedRows = format.hasBandedRows, hasBandedColumns = format.hasBandedColumns, bgColorOdd = format.bgColorOdd, bgColorEven = format.bgColorEven;
13786
- var shouldColorWholeTable = !hasBandedRows && bgColorOdd === bgColorEven ? true : false;
13787
- this.cells.forEach(function (row, index) {
14047
+ VTable.prototype.deleteCellShadeDataset = function (cells) {
14048
+ cells.forEach(function (row) {
13788
14049
  row.forEach(function (cell) {
13789
- if (cell.td) {
13790
- if (hasBandedRows) {
13791
- var backgroundColor = color(index);
13792
- cell.td.style.backgroundColor = backgroundColor;
13793
- }
13794
- else if (shouldColorWholeTable) {
13795
- cell.td.style.backgroundColor = format.bgColorOdd;
13796
- }
13797
- else {
13798
- cell.td.style.backgroundColor = null;
13799
- }
13800
- }
13801
- });
13802
- });
13803
- if (hasBandedColumns) {
13804
- this.cells.forEach(function (row) {
13805
- row.forEach(function (cell, index) {
13806
- var backgroundColor = color(index);
13807
- if (cell.td && backgroundColor) {
13808
- cell.td.style.backgroundColor = backgroundColor;
13809
- }
13810
- });
13811
- });
13812
- }
13813
- };
13814
- /**
13815
- * Set color to borders of an table
13816
- * @param format
13817
- * @returns
13818
- */
13819
- VTable.prototype.setBorderColors = function (td, format) {
13820
- td.style.borderTop = getBorderStyle(format.topBorderColor);
13821
- td.style.borderLeft = getBorderStyle(format.verticalBorderColor);
13822
- td.style.borderRight = getBorderStyle(format.verticalBorderColor);
13823
- td.style.borderBottom = getBorderStyle(format.bottomBorderColor);
13824
- };
13825
- /**
13826
- * Format the border type
13827
- * @returns
13828
- */
13829
- VTable.prototype.formatBorders = function (format, td, isFirstRow, isLastRow, isFirstColumn, isLastColumn) {
13830
- this.setBorderColors(td, format);
13831
- switch (format.tableBorderFormat) {
13832
- case 0 /* DEFAULT */:
13833
- return;
13834
- case 1 /* LIST_WITH_SIDE_BORDERS */:
13835
- if (!isFirstColumn) {
13836
- td.style.borderLeftColor = TRANSPARENT;
13837
- }
13838
- if (!isLastColumn) {
13839
- td.style.borderRightColor = TRANSPARENT;
13840
- }
13841
- break;
13842
- case 4 /* FIRST_COLUMN_HEADER_EXTERNAL */:
13843
- if (!isFirstRow) {
13844
- td.style.borderTopColor = TRANSPARENT;
13845
- }
13846
- if (!isLastRow && !isFirstRow) {
13847
- td.style.borderBottomColor = TRANSPARENT;
13848
- }
13849
- if (!isFirstColumn) {
13850
- td.style.borderLeftColor = TRANSPARENT;
13851
- }
13852
- if (!isLastColumn && !isFirstColumn) {
13853
- td.style.borderRightColor = TRANSPARENT;
13854
- }
13855
- if (isFirstColumn && isFirstRow) {
13856
- td.style.borderRightColor = TRANSPARENT;
13857
- }
13858
- break;
13859
- case 2 /* NO_HEADER_BORDERS */:
13860
- if (isFirstRow) {
13861
- td.style.borderTopColor = TRANSPARENT;
13862
- td.style.borderRightColor = TRANSPARENT;
13863
- td.style.borderLeftColor = TRANSPARENT;
13864
- }
13865
- if (isFirstColumn) {
13866
- td.style.borderLeftColor = TRANSPARENT;
13867
- }
13868
- if (isLastColumn) {
13869
- td.style.borderRightColor = TRANSPARENT;
13870
- }
13871
- break;
13872
- case 3 /* NO_SIDE_BORDERS */:
13873
- if (isFirstColumn) {
13874
- td.style.borderLeftColor = TRANSPARENT;
13875
- }
13876
- if (isLastColumn) {
13877
- td.style.borderRightColor = TRANSPARENT;
13878
- }
13879
- break;
13880
- case 5 /* ESPECIAL_TYPE_1 */:
13881
- if (isFirstRow) {
13882
- td.style.borderRightColor = TRANSPARENT;
13883
- td.style.borderLeftColor = TRANSPARENT;
13884
- }
13885
- if (isFirstColumn) {
13886
- td.style.borderBottomColor = TRANSPARENT;
13887
- td.style.borderTopColor = TRANSPARENT;
13888
- }
13889
- if (isFirstRow && isFirstColumn) {
13890
- td.style.borderLeftColor = format.verticalBorderColor;
13891
- td.style.borderBottomColor = format.bottomBorderColor;
13892
- td.style.borderTopColor = format.topBorderColor;
13893
- }
13894
- break;
13895
- case 6 /* ESPECIAL_TYPE_2 */:
13896
- if (isFirstRow) {
13897
- td.style.borderRightColor = TRANSPARENT;
13898
- td.style.borderLeftColor = TRANSPARENT;
13899
- }
13900
- if (isFirstColumn) {
13901
- td.style.borderBottomColor = TRANSPARENT;
13902
- td.style.borderTopColor = TRANSPARENT;
13903
- }
13904
- if (isFirstRow && isFirstColumn) {
13905
- td.style.borderLeftColor = format.verticalBorderColor;
13906
- td.style.borderBottomColor = format.bottomBorderColor;
13907
- td.style.borderTopColor = format.topBorderColor;
13908
- }
13909
- if (!isFirstRow && !isFirstColumn) {
13910
- td.style.borderLeftColor = TRANSPARENT;
13911
- td.style.borderBottomColor = TRANSPARENT;
13912
- td.style.borderTopColor = TRANSPARENT;
13913
- td.style.borderRightColor = TRANSPARENT;
13914
- }
13915
- break;
13916
- case 7 /* ESPECIAL_TYPE_3 */:
13917
- if (isFirstRow) {
13918
- td.style.borderLeftColor = TRANSPARENT;
13919
- td.style.borderTopColor = TRANSPARENT;
13920
- td.style.borderRightColor = TRANSPARENT;
13921
- }
13922
- if (isFirstColumn) {
13923
- td.style.borderLeftColor = TRANSPARENT;
13924
- td.style.borderTopColor = TRANSPARENT;
13925
- td.style.borderBottomColor = TRANSPARENT;
13926
- }
13927
- if (!isFirstRow && !isFirstColumn) {
13928
- td.style.borderLeftColor = TRANSPARENT;
13929
- td.style.borderBottomColor = TRANSPARENT;
13930
- td.style.borderTopColor = TRANSPARENT;
13931
- td.style.borderRightColor = TRANSPARENT;
13932
- }
13933
- if (isFirstRow && isFirstColumn) {
13934
- td.style.borderBottomColor = format.bottomBorderColor;
13935
- }
13936
- break;
13937
- }
13938
- };
13939
- /**
13940
- * Organize the borders of table according to a border type
13941
- * @param format
13942
- * @returns
13943
- */
13944
- VTable.prototype.setBordersType = function (format) {
13945
- var _this = this;
13946
- this.cells.forEach(function (row, rowIndex) {
13947
- row.forEach(function (cell, cellIndex) {
13948
- if (cell.td) {
13949
- _this.formatBorders(format, cell.td, rowIndex === 0, rowIndex === _this.cells.length - 1, cellIndex === 0, cellIndex === row.length - 1);
13950
- }
13951
- });
13952
- });
13953
- };
13954
- /**
13955
- * Apply custom design to the first table column
13956
- * @param format
13957
- * @returns
13958
- */
13959
- VTable.prototype.setFirstColumnFormat = function (format) {
13960
- var _this = this;
13961
- if (!format.hasFirstColumn) {
13962
- this.forEachCellOfColumn(0, function (cell, row, i) {
13963
- if (cell.td) {
13964
- cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_CELL_TAG_NAME);
13965
- cell.td.scope = '';
13966
- }
13967
- });
13968
- return;
13969
- }
13970
- this.forEachCellOfColumn(0, function (cell, row, i) {
13971
- if (cell.td) {
13972
- if (i !== 0) {
13973
- cell.td.style.borderTopColor = TRANSPARENT;
13974
- cell.td.style.backgroundColor = TRANSPARENT;
13975
- }
13976
- if (i !== _this.cells.length - 1 && i !== 0) {
13977
- cell.td.style.borderBottomColor = TRANSPARENT;
13978
- }
13979
- cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_HEADER_TAG_NAME);
13980
- cell.td.scope = 'col';
13981
- }
13982
- });
13983
- };
13984
- /**
13985
- * Apply custom design to the Header Row
13986
- * @param format
13987
- * @returns
13988
- */
13989
- VTable.prototype.setHeaderRowFormat = function (format) {
13990
- if (!format.hasHeaderRow) {
13991
- this.forEachCellOfRow(0, function (cell, i) {
13992
- if (cell.td) {
13993
- cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_CELL_TAG_NAME);
13994
- cell.td.scope = '';
14050
+ if (cell.td && cell.td.dataset[CELL_SHADE]) {
14051
+ delete cell.td.dataset[CELL_SHADE];
13995
14052
  }
13996
14053
  });
13997
- return;
13998
- }
13999
- this.forEachCellOfRow(0, function (cell, i) {
14000
- if (cell.td) {
14001
- cell.td.style.backgroundColor = format.headerRowColor;
14002
- cell.td.style.borderRightColor = format.headerRowColor;
14003
- cell.td.style.borderLeftColor = format.headerRowColor;
14004
- cell.td.style.borderTopColor = format.headerRowColor;
14005
- cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_HEADER_TAG_NAME);
14006
- cell.td.scope = 'row';
14007
- }
14008
14054
  });
14009
14055
  };
14010
14056
  /**
@@ -14355,7 +14401,7 @@ var VTable = /** @class */ (function () {
14355
14401
  }
14356
14402
  };
14357
14403
  /* normalize width/height for each cell in the table */
14358
- VTable.prototype.normalizeTableCellSize = function (sizeTransformer) {
14404
+ VTable.prototype.normalizeTableCellSize = function (zoomScale) {
14359
14405
  // remove width/height for each row
14360
14406
  for (var i = 0, row = void 0; (row = this.table.rows[i]); i++) {
14361
14407
  row.removeAttribute('width');
@@ -14368,7 +14414,8 @@ var VTable = /** @class */ (function () {
14368
14414
  for (var j = 0; j < this.cells[i].length; j++) {
14369
14415
  var cell = this.cells[i][j];
14370
14416
  if (cell) {
14371
- setHTMLElementSizeInPx(cell.td, (sizeTransformer === null || sizeTransformer === void 0 ? void 0 : sizeTransformer(cell.width)) || cell.width, (sizeTransformer === null || sizeTransformer === void 0 ? void 0 : sizeTransformer(cell.height)) || cell.height);
14417
+ var func = typeof zoomScale == 'number' ? function (n) { return n / zoomScale; } : zoomScale;
14418
+ setHTMLElementSizeInPx(cell.td, (func === null || func === void 0 ? void 0 : func(cell.width)) || cell.width, (func === null || func === void 0 ? void 0 : func(cell.height)) || cell.height);
14372
14419
  }
14373
14420
  }
14374
14421
  }
@@ -14397,9 +14444,6 @@ function getTableFromTd(td) {
14397
14444
  for (; result && result.tagName != 'TABLE'; result = result.parentElement) { }
14398
14445
  return result;
14399
14446
  }
14400
- function getBorderStyle(style) {
14401
- return 'solid 1px ' + (style || 'transparent');
14402
- }
14403
14447
  /**
14404
14448
  * Clone a table cell
14405
14449
  * @param cell The cell to clone
@@ -14429,31 +14473,119 @@ function cloneNode(node) {
14429
14473
 
14430
14474
  /***/ }),
14431
14475
 
14432
- /***/ "./packages/roosterjs-editor-dom/lib/utils/Browser.ts":
14433
- /*!************************************************************!*\
14434
- !*** ./packages/roosterjs-editor-dom/lib/utils/Browser.ts ***!
14435
- \************************************************************/
14476
+ /***/ "./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts":
14477
+ /*!********************************************************************!*\
14478
+ !*** ./packages/roosterjs-editor-dom/lib/table/tableFormatInfo.ts ***!
14479
+ \********************************************************************/
14436
14480
  /*! no static exports found */
14437
14481
  /***/ (function(module, exports, __webpack_require__) {
14438
14482
 
14439
14483
  "use strict";
14440
14484
 
14441
14485
  Object.defineProperty(exports, "__esModule", { value: true });
14442
- exports.Browser = exports.getBrowserInfo = void 0;
14443
- var isAndroidRegex = /android/i;
14486
+ exports.saveTableInfo = exports.getTableFormatInfo = void 0;
14487
+ var TABLE_STYLE_INFO = 'roosterTableInfo';
14444
14488
  /**
14445
- * Get current browser information from user agent string
14446
- * @param userAgent The userAgent string of a browser
14447
- * @param appVersion The appVersion string of a browser
14448
- * @returns The BrowserInfo object calculated from the given userAgent and appVersion
14489
+ * @internal
14490
+ * Get the format info of a table
14491
+ * If the table does not have a info saved, it will be retrieved from the css styles
14492
+ * @param table The table that has the info
14449
14493
  */
14450
- function getBrowserInfo(userAgent, appVersion) {
14451
- // checks whether the browser is running in IE
14452
- // IE11 will use rv in UA instead of MSIE. Unfortunately Firefox also uses this. We should also look for "Trident" to confirm this.
14453
- // There have been cases where companies using older version of IE and custom UserAgents have broken this logic (e.g. IE 10 and KellyServices)
14454
- // therefore we should check that the Trident/rv combo is not just from an older IE browser
14455
- var isIE11OrGreater = userAgent.indexOf('rv:') != -1 && userAgent.indexOf('Trident') != -1;
14456
- var isIE = userAgent.indexOf('MSIE') != -1 || isIE11OrGreater;
14494
+ function getTableFormatInfo(table) {
14495
+ var obj = safeParseJSON(table === null || table === void 0 ? void 0 : table.dataset[TABLE_STYLE_INFO]);
14496
+ return checkIfTableFormatIsValid(obj) ? obj : null;
14497
+ }
14498
+ exports.getTableFormatInfo = getTableFormatInfo;
14499
+ /**
14500
+ * @internal
14501
+ * Save the format info of a table
14502
+ * @param table The table the info will be saved
14503
+ * @param format The format of the table
14504
+ */
14505
+ function saveTableInfo(table, format) {
14506
+ if (table && format) {
14507
+ table.dataset[TABLE_STYLE_INFO] = JSON.stringify(format);
14508
+ }
14509
+ }
14510
+ exports.saveTableInfo = saveTableInfo;
14511
+ function checkIfTableFormatIsValid(format) {
14512
+ if (!format) {
14513
+ return false;
14514
+ }
14515
+ 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;
14516
+ var colorsValues = [
14517
+ topBorderColor,
14518
+ verticalBorderColor,
14519
+ bottomBorderColor,
14520
+ bgColorOdd,
14521
+ bgColorEven,
14522
+ ];
14523
+ var stateValues = [hasBandedColumns, hasBandedRows, hasFirstColumn, hasHeaderRow];
14524
+ if (colorsValues.some(function (key) { return !isAValidColor(key); }) ||
14525
+ stateValues.some(function (key) { return !isBoolean(key); }) ||
14526
+ !isAValidTableBorderType(tableBorderFormat)) {
14527
+ return false;
14528
+ }
14529
+ return true;
14530
+ }
14531
+ function isAValidColor(color) {
14532
+ if (color === null || color === undefined || typeof color === 'string') {
14533
+ return true;
14534
+ }
14535
+ return false;
14536
+ }
14537
+ function isBoolean(a) {
14538
+ if (typeof a === 'boolean') {
14539
+ return true;
14540
+ }
14541
+ return false;
14542
+ }
14543
+ function isAValidTableBorderType(border) {
14544
+ if (-1 < border && border < 8) {
14545
+ return true;
14546
+ }
14547
+ return false;
14548
+ }
14549
+ function safeParseJSON(json) {
14550
+ if (!json) {
14551
+ return null;
14552
+ }
14553
+ try {
14554
+ return JSON.parse(json);
14555
+ }
14556
+ catch (_a) {
14557
+ return null;
14558
+ }
14559
+ }
14560
+
14561
+
14562
+ /***/ }),
14563
+
14564
+ /***/ "./packages/roosterjs-editor-dom/lib/utils/Browser.ts":
14565
+ /*!************************************************************!*\
14566
+ !*** ./packages/roosterjs-editor-dom/lib/utils/Browser.ts ***!
14567
+ \************************************************************/
14568
+ /*! no static exports found */
14569
+ /***/ (function(module, exports, __webpack_require__) {
14570
+
14571
+ "use strict";
14572
+
14573
+ Object.defineProperty(exports, "__esModule", { value: true });
14574
+ exports.Browser = exports.getBrowserInfo = void 0;
14575
+ var isAndroidRegex = /android/i;
14576
+ /**
14577
+ * Get current browser information from user agent string
14578
+ * @param userAgent The userAgent string of a browser
14579
+ * @param appVersion The appVersion string of a browser
14580
+ * @returns The BrowserInfo object calculated from the given userAgent and appVersion
14581
+ */
14582
+ function getBrowserInfo(userAgent, appVersion) {
14583
+ // checks whether the browser is running in IE
14584
+ // IE11 will use rv in UA instead of MSIE. Unfortunately Firefox also uses this. We should also look for "Trident" to confirm this.
14585
+ // There have been cases where companies using older version of IE and custom UserAgents have broken this logic (e.g. IE 10 and KellyServices)
14586
+ // therefore we should check that the Trident/rv combo is not just from an older IE browser
14587
+ var isIE11OrGreater = userAgent.indexOf('rv:') != -1 && userAgent.indexOf('Trident') != -1;
14588
+ var isIE = userAgent.indexOf('MSIE') != -1 || isIE11OrGreater;
14457
14589
  // IE11+ may also have 'Chrome', 'Firefox' and 'Safari' in user agent. But it will have 'trident' as well
14458
14590
  var isChrome = false;
14459
14591
  var isFirefox = false;
@@ -14554,6 +14686,291 @@ function applyFormat(element, format, isDarkMode) {
14554
14686
  exports.default = applyFormat;
14555
14687
 
14556
14688
 
14689
+ /***/ }),
14690
+
14691
+ /***/ "./packages/roosterjs-editor-dom/lib/utils/applyTableFormat.ts":
14692
+ /*!*********************************************************************!*\
14693
+ !*** ./packages/roosterjs-editor-dom/lib/utils/applyTableFormat.ts ***!
14694
+ \*********************************************************************/
14695
+ /*! no static exports found */
14696
+ /***/ (function(module, exports, __webpack_require__) {
14697
+
14698
+ "use strict";
14699
+
14700
+ Object.defineProperty(exports, "__esModule", { value: true });
14701
+ var changeElementTag_1 = __webpack_require__(/*! ./changeElementTag */ "./packages/roosterjs-editor-dom/lib/utils/changeElementTag.ts");
14702
+ var TRANSPARENT = 'transparent';
14703
+ var TABLE_CELL_TAG_NAME = 'TD';
14704
+ var TABLE_HEADER_TAG_NAME = 'TH';
14705
+ var CELL_SHADE = 'cellShade';
14706
+ /**
14707
+ * @internal
14708
+ * Apply the given table format to this virtual table
14709
+ * @param format Table format to apply
14710
+ */
14711
+ function applyTableFormat(table, cells, format) {
14712
+ if (!format) {
14713
+ return;
14714
+ }
14715
+ table.style.borderCollapse = 'collapse';
14716
+ setBordersType(cells, format);
14717
+ setColor(cells, format);
14718
+ setFirstColumnFormat(cells, format);
14719
+ setHeaderRowFormat(cells, format);
14720
+ }
14721
+ exports.default = applyTableFormat;
14722
+ /**
14723
+ * Check if the cell has shade
14724
+ * @param cell
14725
+ * @returns
14726
+ */
14727
+ function hasCellShade(cell) {
14728
+ if (!cell.td) {
14729
+ return false;
14730
+ }
14731
+ var colorShade = cell.td.dataset[CELL_SHADE];
14732
+ return colorShade ? true : false;
14733
+ }
14734
+ /**
14735
+ * Set color to the table
14736
+ * @param format the format that must be applied
14737
+ */
14738
+ function setColor(cells, format) {
14739
+ var color = function (index) { return (index % 2 === 0 ? format.bgColorEven : format.bgColorOdd); };
14740
+ var hasBandedRows = format.hasBandedRows, hasBandedColumns = format.hasBandedColumns, bgColorOdd = format.bgColorOdd, bgColorEven = format.bgColorEven;
14741
+ var shouldColorWholeTable = !hasBandedRows && bgColorOdd === bgColorEven ? true : false;
14742
+ cells.forEach(function (row, index) {
14743
+ row.forEach(function (cell) {
14744
+ if (cell.td && !hasCellShade(cell)) {
14745
+ if (hasBandedRows) {
14746
+ var backgroundColor = color(index);
14747
+ cell.td.style.backgroundColor = backgroundColor || TRANSPARENT;
14748
+ }
14749
+ else if (shouldColorWholeTable) {
14750
+ cell.td.style.backgroundColor = format.bgColorOdd || TRANSPARENT;
14751
+ }
14752
+ else {
14753
+ cell.td.style.backgroundColor = TRANSPARENT;
14754
+ }
14755
+ }
14756
+ });
14757
+ });
14758
+ if (hasBandedColumns) {
14759
+ cells.forEach(function (row) {
14760
+ row.forEach(function (cell, index) {
14761
+ var backgroundColor = color(index);
14762
+ if (cell.td && backgroundColor && !hasCellShade(cell)) {
14763
+ cell.td.style.backgroundColor = backgroundColor;
14764
+ }
14765
+ });
14766
+ });
14767
+ }
14768
+ }
14769
+ /**
14770
+ * Set color to borders of an table
14771
+ * @param format
14772
+ * @returns
14773
+ */
14774
+ function setBorderColors(td, format) {
14775
+ td.style.borderTop = getBorderStyle(format.topBorderColor);
14776
+ td.style.borderLeft = getBorderStyle(format.verticalBorderColor);
14777
+ td.style.borderRight = getBorderStyle(format.verticalBorderColor);
14778
+ td.style.borderBottom = getBorderStyle(format.bottomBorderColor);
14779
+ }
14780
+ /**
14781
+ * Format the border type
14782
+ * @returns
14783
+ */
14784
+ function formatBorders(format, td, isFirstRow, isLastRow, isFirstColumn, isLastColumn) {
14785
+ setBorderColors(td, format);
14786
+ switch (format.tableBorderFormat) {
14787
+ case 0 /* DEFAULT */:
14788
+ return;
14789
+ case 1 /* LIST_WITH_SIDE_BORDERS */:
14790
+ if (!isFirstColumn) {
14791
+ td.style.borderLeftColor = TRANSPARENT;
14792
+ }
14793
+ if (!isLastColumn) {
14794
+ td.style.borderRightColor = TRANSPARENT;
14795
+ }
14796
+ break;
14797
+ case 4 /* FIRST_COLUMN_HEADER_EXTERNAL */:
14798
+ if (!isFirstRow) {
14799
+ td.style.borderTopColor = TRANSPARENT;
14800
+ }
14801
+ if (!isLastRow && !isFirstRow) {
14802
+ td.style.borderBottomColor = TRANSPARENT;
14803
+ }
14804
+ if (!isFirstColumn) {
14805
+ td.style.borderLeftColor = TRANSPARENT;
14806
+ }
14807
+ if (!isLastColumn && !isFirstColumn) {
14808
+ td.style.borderRightColor = TRANSPARENT;
14809
+ }
14810
+ if (isFirstColumn && isFirstRow) {
14811
+ td.style.borderRightColor = TRANSPARENT;
14812
+ }
14813
+ break;
14814
+ case 2 /* NO_HEADER_BORDERS */:
14815
+ if (isFirstRow) {
14816
+ td.style.borderTopColor = TRANSPARENT;
14817
+ td.style.borderRightColor = TRANSPARENT;
14818
+ td.style.borderLeftColor = TRANSPARENT;
14819
+ }
14820
+ if (isFirstColumn) {
14821
+ td.style.borderLeftColor = TRANSPARENT;
14822
+ }
14823
+ if (isLastColumn) {
14824
+ td.style.borderRightColor = TRANSPARENT;
14825
+ }
14826
+ break;
14827
+ case 3 /* NO_SIDE_BORDERS */:
14828
+ if (isFirstColumn) {
14829
+ td.style.borderLeftColor = TRANSPARENT;
14830
+ }
14831
+ if (isLastColumn) {
14832
+ td.style.borderRightColor = TRANSPARENT;
14833
+ }
14834
+ break;
14835
+ case 5 /* ESPECIAL_TYPE_1 */:
14836
+ if (isFirstRow) {
14837
+ td.style.borderRightColor = TRANSPARENT;
14838
+ td.style.borderLeftColor = TRANSPARENT;
14839
+ }
14840
+ if (isFirstColumn) {
14841
+ td.style.borderBottomColor = TRANSPARENT;
14842
+ td.style.borderTopColor = TRANSPARENT;
14843
+ }
14844
+ if (isFirstRow && isFirstColumn) {
14845
+ td.style.borderLeftColor = format.verticalBorderColor || TRANSPARENT;
14846
+ td.style.borderBottomColor = format.bottomBorderColor || TRANSPARENT;
14847
+ td.style.borderTopColor = format.topBorderColor || TRANSPARENT;
14848
+ }
14849
+ break;
14850
+ case 6 /* ESPECIAL_TYPE_2 */:
14851
+ if (isFirstRow) {
14852
+ td.style.borderRightColor = TRANSPARENT;
14853
+ td.style.borderLeftColor = TRANSPARENT;
14854
+ }
14855
+ if (isFirstColumn) {
14856
+ td.style.borderBottomColor = TRANSPARENT;
14857
+ td.style.borderTopColor = TRANSPARENT;
14858
+ }
14859
+ if (isFirstRow && isFirstColumn) {
14860
+ td.style.borderLeftColor = format.verticalBorderColor || TRANSPARENT;
14861
+ td.style.borderBottomColor = format.bottomBorderColor || TRANSPARENT;
14862
+ td.style.borderTopColor = format.topBorderColor || TRANSPARENT;
14863
+ }
14864
+ if (!isFirstRow && !isFirstColumn) {
14865
+ td.style.borderLeftColor = TRANSPARENT;
14866
+ td.style.borderBottomColor = TRANSPARENT;
14867
+ td.style.borderTopColor = TRANSPARENT;
14868
+ td.style.borderRightColor = TRANSPARENT;
14869
+ }
14870
+ break;
14871
+ case 7 /* ESPECIAL_TYPE_3 */:
14872
+ if (isFirstRow) {
14873
+ td.style.borderLeftColor = TRANSPARENT;
14874
+ td.style.borderTopColor = TRANSPARENT;
14875
+ td.style.borderRightColor = TRANSPARENT;
14876
+ }
14877
+ if (isFirstColumn) {
14878
+ td.style.borderLeftColor = TRANSPARENT;
14879
+ td.style.borderTopColor = TRANSPARENT;
14880
+ td.style.borderBottomColor = TRANSPARENT;
14881
+ }
14882
+ if (!isFirstRow && !isFirstColumn) {
14883
+ td.style.borderLeftColor = TRANSPARENT;
14884
+ td.style.borderBottomColor = TRANSPARENT;
14885
+ td.style.borderTopColor = TRANSPARENT;
14886
+ td.style.borderRightColor = TRANSPARENT;
14887
+ }
14888
+ if (isFirstRow && isFirstColumn) {
14889
+ td.style.borderBottomColor = format.bottomBorderColor || TRANSPARENT;
14890
+ }
14891
+ break;
14892
+ }
14893
+ }
14894
+ /**
14895
+ * Organize the borders of table according to a border type
14896
+ * @param format
14897
+ * @returns
14898
+ */
14899
+ function setBordersType(cells, format) {
14900
+ cells.forEach(function (row, rowIndex) {
14901
+ row.forEach(function (cell, cellIndex) {
14902
+ if (cell.td) {
14903
+ formatBorders(format, cell.td, rowIndex === 0, rowIndex === cells.length - 1, cellIndex === 0, cellIndex === row.length - 1);
14904
+ }
14905
+ });
14906
+ });
14907
+ }
14908
+ /**
14909
+ * Apply custom design to the first table column
14910
+ * @param format
14911
+ * @returns
14912
+ */
14913
+ function setFirstColumnFormat(cells, format) {
14914
+ if (!format.hasFirstColumn) {
14915
+ cells.forEach(function (row) {
14916
+ row.forEach(function (cell, cellIndex) {
14917
+ if (cell.td && cellIndex === 0) {
14918
+ cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_CELL_TAG_NAME);
14919
+ cell.td.scope = '';
14920
+ }
14921
+ });
14922
+ });
14923
+ return;
14924
+ }
14925
+ cells.forEach(function (row, rowIndex) {
14926
+ row.forEach(function (cell, cellIndex) {
14927
+ if (cell.td && cellIndex === 0) {
14928
+ if (rowIndex !== 0) {
14929
+ cell.td.style.borderTopColor = TRANSPARENT;
14930
+ cell.td.style.backgroundColor = TRANSPARENT;
14931
+ }
14932
+ if (rowIndex !== cells.length - 1 && rowIndex !== 0) {
14933
+ cell.td.style.borderBottomColor = TRANSPARENT;
14934
+ }
14935
+ cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_HEADER_TAG_NAME);
14936
+ cell.td.scope = 'col';
14937
+ }
14938
+ });
14939
+ });
14940
+ }
14941
+ /**
14942
+ * Apply custom design to the Header Row
14943
+ * @param format
14944
+ * @returns
14945
+ */
14946
+ function setHeaderRowFormat(cells, format) {
14947
+ var _a, _b;
14948
+ if (!format.hasHeaderRow) {
14949
+ (_a = cells[0]) === null || _a === void 0 ? void 0 : _a.forEach(function (cell) {
14950
+ if (cell.td) {
14951
+ cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_CELL_TAG_NAME);
14952
+ cell.td.scope = '';
14953
+ }
14954
+ });
14955
+ return;
14956
+ }
14957
+ (_b = cells[0]) === null || _b === void 0 ? void 0 : _b.forEach(function (cell) {
14958
+ if (cell.td && format.headerRowColor) {
14959
+ cell.td.style.backgroundColor = format.headerRowColor;
14960
+ cell.td.style.borderRightColor = format.headerRowColor;
14961
+ cell.td.style.borderLeftColor = format.headerRowColor;
14962
+ cell.td.style.borderTopColor = format.headerRowColor;
14963
+ cell.td = (0, changeElementTag_1.default)(cell.td, TABLE_HEADER_TAG_NAME);
14964
+ cell.td.scope = 'row';
14965
+ }
14966
+ });
14967
+ }
14968
+ function getBorderStyle(style) {
14969
+ var color = style ? style : 'transparent';
14970
+ return 'solid 1px ' + color;
14971
+ }
14972
+
14973
+
14557
14974
  /***/ }),
14558
14975
 
14559
14976
  /***/ "./packages/roosterjs-editor-dom/lib/utils/arrayPush.ts":
@@ -14597,13 +15014,18 @@ function changeElementTag(element, newTag) {
14597
15014
  if (!element || !newTag) {
14598
15015
  return null;
14599
15016
  }
15017
+ var origianlTag = (0, getTagOfNode_1.default)(element);
15018
+ if (origianlTag == newTag.toUpperCase()) {
15019
+ // Already in the target tag, no need to change
15020
+ return element;
15021
+ }
14600
15022
  var newElement = element.ownerDocument.createElement(newTag);
14601
15023
  for (var i = 0; i < element.attributes.length; i++) {
14602
15024
  var attr = element.attributes[i];
14603
15025
  newElement.setAttribute(attr.name, attr.value);
14604
15026
  }
14605
15027
  (0, moveChildNodes_1.default)(newElement, element);
14606
- if ((0, getTagOfNode_1.default)(element) == 'P' || (0, getTagOfNode_1.default)(newElement) == 'P') {
15028
+ if (origianlTag == 'P' || (0, getTagOfNode_1.default)(newElement) == 'P') {
14607
15029
  _a = (0, getComputedStyles_1.default)(element, [
14608
15030
  'margin-top',
14609
15031
  'margin-bottom',
@@ -15884,156 +16306,48 @@ function splitBalancedNodeRange(nodes) {
15884
16306
  var end = Array.isArray(nodes) ? nodes[nodes.length - 1] : nodes;
15885
16307
  var parentNode = start && end && start.parentNode == end.parentNode ? start.parentNode : null;
15886
16308
  if (parentNode) {
15887
- if ((0, isNodeAfter_1.default)(start, end)) {
15888
- var temp = end;
15889
- end = start;
15890
- start = temp;
15891
- }
15892
- splitParentNode(start, true /*splitBefore*/);
15893
- splitParentNode(end, false /*splitBefore*/);
15894
- }
15895
- return parentNode;
15896
- }
15897
- exports.splitBalancedNodeRange = splitBalancedNodeRange;
15898
-
15899
-
15900
- /***/ }),
15901
-
15902
- /***/ "./packages/roosterjs-editor-dom/lib/utils/splitTextNode.ts":
15903
- /*!******************************************************************!*\
15904
- !*** ./packages/roosterjs-editor-dom/lib/utils/splitTextNode.ts ***!
15905
- \******************************************************************/
15906
- /*! no static exports found */
15907
- /***/ (function(module, exports, __webpack_require__) {
15908
-
15909
- "use strict";
15910
-
15911
- Object.defineProperty(exports, "__esModule", { value: true });
15912
- /**
15913
- * Split a text node into two parts by an offset number, and return one of them
15914
- * @param textNode The text node to split
15915
- * @param offset The offset number to split at
15916
- * @param returnFirstPart True to return the first part, then the passed in textNode will become the second part.
15917
- * Otherwise return the second part, and the passed in textNode will become the first part
15918
- */
15919
- function splitTextNode(textNode, offset, returnFirstPart) {
15920
- var _a, _b, _c;
15921
- var firstPart = ((_a = textNode.nodeValue) === null || _a === void 0 ? void 0 : _a.substring(0, offset)) || '';
15922
- var secondPart = ((_b = textNode.nodeValue) === null || _b === void 0 ? void 0 : _b.substring(offset)) || '';
15923
- var newNode = textNode.ownerDocument.createTextNode(returnFirstPart ? firstPart : secondPart);
15924
- textNode.nodeValue = returnFirstPart ? secondPart : firstPart;
15925
- (_c = textNode.parentNode) === null || _c === void 0 ? void 0 : _c.insertBefore(newNode, returnFirstPart ? textNode : textNode.nextSibling);
15926
- return newNode;
15927
- }
15928
- exports.default = splitTextNode;
15929
-
15930
-
15931
- /***/ }),
15932
-
15933
- /***/ "./packages/roosterjs-editor-dom/lib/utils/tableFormatInfo.ts":
15934
- /*!********************************************************************!*\
15935
- !*** ./packages/roosterjs-editor-dom/lib/utils/tableFormatInfo.ts ***!
15936
- \********************************************************************/
15937
- /*! no static exports found */
15938
- /***/ (function(module, exports, __webpack_require__) {
15939
-
15940
- "use strict";
15941
-
15942
- Object.defineProperty(exports, "__esModule", { value: true });
15943
- exports.saveTableInfo = exports.getTableFormatInfo = void 0;
15944
- var TABLE_STYLE_INFO = 'roosterTableInfo';
15945
- var DEFAULT_FORMAT = {
15946
- topBorderColor: '#ABABAB',
15947
- bottomBorderColor: '#ABABAB',
15948
- verticalBorderColor: '#ABABAB',
15949
- hasHeaderRow: false,
15950
- hasFirstColumn: false,
15951
- hasBandedRows: false,
15952
- hasBandedColumns: false,
15953
- bgColorEven: null,
15954
- bgColorOdd: '#ABABAB20',
15955
- headerRowColor: '#ABABAB',
15956
- tableBorderFormat: 0 /* DEFAULT */,
15957
- };
15958
- /**
15959
- * @internal
15960
- * Get the format info of a table
15961
- * If the table does not have a info saved, it will be retrieved from the css styles
15962
- * @param table The table that has the info
15963
- */
15964
- function getTableFormatInfo(table) {
15965
- var obj = safeParseJSON(table === null || table === void 0 ? void 0 : table.dataset[TABLE_STYLE_INFO]);
15966
- return checkIfTableFormatIsValid(obj) ? obj : DEFAULT_FORMAT;
15967
- }
15968
- exports.getTableFormatInfo = getTableFormatInfo;
15969
- function checkIfTableFormatIsValid(format) {
15970
- if (!format) {
15971
- return false;
15972
- }
15973
- 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;
15974
- var colorsValues = [
15975
- topBorderColor,
15976
- verticalBorderColor,
15977
- bottomBorderColor,
15978
- bgColorOdd,
15979
- bgColorEven,
15980
- ];
15981
- var stateValues = [hasBandedColumns, hasBandedRows, hasFirstColumn, hasHeaderRow];
15982
- if (colorsValues.some(function (key) { return !isAValidColor(key); }) ||
15983
- stateValues.some(function (key) { return !isBoolean(key); }) ||
15984
- !isAValidTableBorderType(tableBorderFormat)) {
15985
- return false;
15986
- }
15987
- return true;
15988
- }
15989
- function isAValidColor(color) {
15990
- if (color === null || color === undefined || typeof color === 'string') {
15991
- return true;
15992
- }
15993
- return false;
15994
- }
15995
- function isBoolean(a) {
15996
- if (typeof a === 'boolean') {
15997
- return true;
15998
- }
15999
- return false;
16000
- }
16001
- function isAValidTableBorderType(border) {
16002
- if (-1 < border && border < 8) {
16003
- return true;
16004
- }
16005
- return false;
16006
- }
16007
- function safeParseJSON(json) {
16008
- if (!json) {
16009
- return null;
16010
- }
16011
- try {
16012
- return JSON.parse(json);
16013
- }
16014
- catch (_a) {
16015
- return null;
16016
- }
16017
- }
16018
- /**
16019
- * @internal
16020
- * Save the format info of a table
16021
- * @param table The table the info will be saved
16022
- * @param format The format of the table
16023
- */
16024
- function saveTableInfo(table, format) {
16025
- if (checkIfItIsDefault(format)) {
16026
- return;
16027
- }
16028
- if (table && format) {
16029
- table.dataset[TABLE_STYLE_INFO] = JSON.stringify(format);
16309
+ if ((0, isNodeAfter_1.default)(start, end)) {
16310
+ var temp = end;
16311
+ end = start;
16312
+ start = temp;
16313
+ }
16314
+ splitParentNode(start, true /*splitBefore*/);
16315
+ splitParentNode(end, false /*splitBefore*/);
16030
16316
  }
16317
+ return parentNode;
16031
16318
  }
16032
- exports.saveTableInfo = saveTableInfo;
16033
- function checkIfItIsDefault(format) {
16034
- var formatKeys = Object.keys(DEFAULT_FORMAT);
16035
- return formatKeys.every(function (key) { return format[key] === DEFAULT_FORMAT[key]; });
16319
+ exports.splitBalancedNodeRange = splitBalancedNodeRange;
16320
+
16321
+
16322
+ /***/ }),
16323
+
16324
+ /***/ "./packages/roosterjs-editor-dom/lib/utils/splitTextNode.ts":
16325
+ /*!******************************************************************!*\
16326
+ !*** ./packages/roosterjs-editor-dom/lib/utils/splitTextNode.ts ***!
16327
+ \******************************************************************/
16328
+ /*! no static exports found */
16329
+ /***/ (function(module, exports, __webpack_require__) {
16330
+
16331
+ "use strict";
16332
+
16333
+ Object.defineProperty(exports, "__esModule", { value: true });
16334
+ /**
16335
+ * Split a text node into two parts by an offset number, and return one of them
16336
+ * @param textNode The text node to split
16337
+ * @param offset The offset number to split at
16338
+ * @param returnFirstPart True to return the first part, then the passed in textNode will become the second part.
16339
+ * Otherwise return the second part, and the passed in textNode will become the first part
16340
+ */
16341
+ function splitTextNode(textNode, offset, returnFirstPart) {
16342
+ var _a, _b, _c;
16343
+ var firstPart = ((_a = textNode.nodeValue) === null || _a === void 0 ? void 0 : _a.substring(0, offset)) || '';
16344
+ var secondPart = ((_b = textNode.nodeValue) === null || _b === void 0 ? void 0 : _b.substring(offset)) || '';
16345
+ var newNode = textNode.ownerDocument.createTextNode(returnFirstPart ? firstPart : secondPart);
16346
+ textNode.nodeValue = returnFirstPart ? secondPart : firstPart;
16347
+ (_c = textNode.parentNode) === null || _c === void 0 ? void 0 : _c.insertBefore(newNode, returnFirstPart ? textNode : textNode.nextSibling);
16348
+ return newNode;
16036
16349
  }
16350
+ exports.default = splitTextNode;
16037
16351
 
16038
16352
 
16039
16353
  /***/ }),
@@ -16494,13 +16808,13 @@ var DragAndDropHelper = /** @class */ (function () {
16494
16808
  * @param onSubmit A callback that will be invoked when event handler in handler object returns true
16495
16809
  * @param handler The event handler object, see DragAndDropHandler interface for more information
16496
16810
  */
16497
- function DragAndDropHelper(trigger, context, onSubmit, handler, sizeTransformer) {
16811
+ function DragAndDropHelper(trigger, context, onSubmit, handler, zoomScale) {
16498
16812
  var _this = this;
16499
16813
  this.trigger = trigger;
16500
16814
  this.context = context;
16501
16815
  this.onSubmit = onSubmit;
16502
16816
  this.handler = handler;
16503
- this.sizeTransformer = sizeTransformer;
16817
+ this.zoomScale = zoomScale;
16504
16818
  this.onMouseDown = function (e) {
16505
16819
  var _a, _b;
16506
16820
  e.preventDefault();
@@ -16513,9 +16827,8 @@ var DragAndDropHelper = /** @class */ (function () {
16513
16827
  this.onMouseMove = function (e) {
16514
16828
  var _a, _b, _c;
16515
16829
  e.preventDefault();
16516
- var sizeTransformer = _this.sizeTransformer;
16517
- var deltaX = sizeTransformer(e.pageX - _this.initX);
16518
- var deltaY = sizeTransformer(e.pageY - _this.initY);
16830
+ var deltaX = (e.pageX - _this.initX) / _this.zoomScale;
16831
+ var deltaY = (e.pageY - _this.initY) / _this.zoomScale;
16519
16832
  if ((_b = (_a = _this.handler).onDragging) === null || _b === void 0 ? void 0 : _b.call(_a, _this.context, e, _this.initValue, deltaX, deltaY)) {
16520
16833
  (_c = _this.onSubmit) === null || _c === void 0 ? void 0 : _c.call(_this, _this.context, _this.trigger);
16521
16834
  }
@@ -16529,7 +16842,6 @@ var DragAndDropHelper = /** @class */ (function () {
16529
16842
  }
16530
16843
  };
16531
16844
  trigger.addEventListener('mousedown', this.onMouseDown);
16532
- this.sizeTransformer = sizeTransformer;
16533
16845
  }
16534
16846
  /**
16535
16847
  * Dispose this object, remove all event listeners that has been attached
@@ -18694,7 +19006,7 @@ var ImageEdit = /** @class */ (function () {
18694
19006
  var wrapper = this.getImageWrapper(this.image);
18695
19007
  return wrapper
18696
19008
  ? getEditElements(wrapper, elementClass).map(function (element) {
18697
- return new DragAndDropHelper_1.default(element, __assign(__assign({}, commonContext), { x: element.dataset.x, y: element.dataset.y }), _this.updateWrapper, dragAndDrop, _this.editor.getSizeTransformer());
19009
+ return new DragAndDropHelper_1.default(element, __assign(__assign({}, commonContext), { x: element.dataset.x, y: element.dataset.y }), _this.updateWrapper, dragAndDrop, _this.editor.getZoomScale());
18698
19010
  })
18699
19011
  : [];
18700
19012
  };
@@ -21710,16 +22022,12 @@ Object.defineProperty(exports, "PickerPlugin", { enumerable: true, get: function
21710
22022
  "use strict";
21711
22023
 
21712
22024
  Object.defineProperty(exports, "__esModule", { value: true });
21713
- var deSelectAll_1 = __webpack_require__(/*! ./utils/deSelectAll */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deSelectAll.ts");
22025
+ var normalizeTableSelection_1 = __webpack_require__(/*! ./utils/normalizeTableSelection */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/normalizeTableSelection.ts");
21714
22026
  var forEachSelectedCell_1 = __webpack_require__(/*! ./utils/forEachSelectedCell */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachSelectedCell.ts");
21715
22027
  var getCellCoordinates_1 = __webpack_require__(/*! ./utils/getCellCoordinates */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/getCellCoordinates.ts");
21716
- var highlight_1 = __webpack_require__(/*! ./utils/highlight */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlight.ts");
21717
- var highlightAll_1 = __webpack_require__(/*! ./utils/highlightAll */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightAll.ts");
21718
22028
  var removeCellsOutsideSelection_1 = __webpack_require__(/*! ./utils/removeCellsOutsideSelection */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/removeCellsOutsideSelection.ts");
21719
22029
  var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
21720
22030
  var TABLE_CELL_SELECTOR = 'td,th';
21721
- var TABLE_SELECTED = "_tableSelected" /* TABLE_SELECTED */;
21722
- var TABLE_CELL_SELECTED = "_tableCellSelected" /* TABLE_CELL_SELECTED */;
21723
22031
  var LEFT_CLICK = 1;
21724
22032
  var RIGHT_CLICK = 3;
21725
22033
  /**
@@ -21831,6 +22139,7 @@ var TableCellSelection = /** @class */ (function () {
21831
22139
  * Dispose this plugin
21832
22140
  */
21833
22141
  TableCellSelection.prototype.dispose = function () {
22142
+ this.editor.select(null);
21834
22143
  this.removeMouseUpEventListener();
21835
22144
  this.editor = null;
21836
22145
  };
@@ -21841,8 +22150,22 @@ var TableCellSelection = /** @class */ (function () {
21841
22150
  TableCellSelection.prototype.onPluginEvent = function (event) {
21842
22151
  if (this.editor) {
21843
22152
  switch (event.eventType) {
21844
- case 8 /* ExtractContentWithDom */:
21845
- clearSelectedTables(event.clonedRoot);
22153
+ case 17 /* EnteredShadowEdit */:
22154
+ var selection = this.editor.getSelectionRangeEx();
22155
+ if (selection.type == 1 /* TableSelection */) {
22156
+ this.tableRange = selection.coordinates;
22157
+ this.firstTable = selection.table;
22158
+ this.editor.select(selection.table, null);
22159
+ }
22160
+ break;
22161
+ case 18 /* LeavingShadowEdit */:
22162
+ if (this.firstTable && this.tableRange) {
22163
+ var table = this.editor.queryElements('#' + this.firstTable.id);
22164
+ if (table.length == 1) {
22165
+ this.firstTable = table[0];
22166
+ this.editor.select(this.firstTable, this.tableRange);
22167
+ }
22168
+ }
21846
22169
  break;
21847
22170
  case 9 /* BeforeCutCopy */:
21848
22171
  this.handleBeforeCutCopy(event);
@@ -21886,12 +22209,12 @@ var TableCellSelection = /** @class */ (function () {
21886
22209
  if (this.firstTable == this.targetTable) {
21887
22210
  if (this.tableSelection) {
21888
22211
  this.vTable.selection.lastCell = (0, getCellCoordinates_1.getCellCoordinates)(this.vTable, this.lastTarget);
21889
- (0, highlight_1.highlight)(this.vTable);
22212
+ this.selectTable();
21890
22213
  this.tableRange.lastCell = this.vTable.selection.lastCell;
21891
22214
  updateSelection(this.editor, this.firstTarget, 0);
21892
22215
  }
21893
22216
  }
21894
- else if (this.tableRange) {
22217
+ else if (this.tableSelection) {
21895
22218
  this.restoreSelection();
21896
22219
  }
21897
22220
  };
@@ -21902,21 +22225,23 @@ var TableCellSelection = /** @class */ (function () {
21902
22225
  */
21903
22226
  TableCellSelection.prototype.handleBeforeCutCopy = function (event) {
21904
22227
  var _this = this;
21905
- var clonedTable = event.clonedRoot.querySelector('table.' + TABLE_SELECTED);
21906
- if (clonedTable) {
21907
- var clonedVTable = new roosterjs_editor_dom_1.VTable(clonedTable);
21908
- clonedVTable.selection = this.tableRange;
21909
- (0, removeCellsOutsideSelection_1.removeCellsOutsideSelection)(clonedVTable);
21910
- clonedVTable.writeBack();
21911
- event.range.selectNode(clonedTable);
21912
- if (event.isCut) {
21913
- (0, forEachSelectedCell_1.forEachSelectedCell)(this.vTable, function (cell) {
21914
- if (cell === null || cell === void 0 ? void 0 : cell.td) {
21915
- deleteNodeContents(cell.td, _this.editor);
21916
- }
21917
- });
22228
+ var selection = this.editor.getSelectionRangeEx();
22229
+ if (selection.type == 1 /* TableSelection */) {
22230
+ var clonedTable = event.clonedRoot.querySelector('table#' + selection.table.id);
22231
+ if (clonedTable) {
22232
+ var clonedVTable = new roosterjs_editor_dom_1.VTable(clonedTable);
22233
+ clonedVTable.selection = this.tableRange;
22234
+ (0, removeCellsOutsideSelection_1.removeCellsOutsideSelection)(clonedVTable);
22235
+ clonedVTable.writeBack();
22236
+ event.range.selectNode(clonedTable);
22237
+ if (event.isCut) {
22238
+ (0, forEachSelectedCell_1.forEachSelectedCell)(this.vTable, function (cell) {
22239
+ if (cell === null || cell === void 0 ? void 0 : cell.td) {
22240
+ deleteNodeContents(cell.td, _this.editor);
22241
+ }
22242
+ });
22243
+ }
21918
22244
  }
21919
- clearSelectedTables(event.clonedRoot);
21920
22245
  }
21921
22246
  };
21922
22247
  //#region Key events
@@ -21951,7 +22276,9 @@ var TableCellSelection = /** @class */ (function () {
21951
22276
  _this.handleKeySelectionInsideTable(event);
21952
22277
  }
21953
22278
  else if (_this.tableSelection) {
21954
- clearSelectedTableCells(_this.editor);
22279
+ if (_this.firstTable) {
22280
+ _this.editor.select(_this.firstTable, null);
22281
+ }
21955
22282
  _this.tableSelection = false;
21956
22283
  }
21957
22284
  });
@@ -21991,7 +22318,7 @@ var TableCellSelection = /** @class */ (function () {
21991
22318
  }
21992
22319
  }
21993
22320
  this.vTable.selection = this.tableRange;
21994
- (0, highlight_1.highlight)(this.vTable);
22321
+ this.selectTable();
21995
22322
  var isBeginAboveEnd = this.isAfter(this.firstTarget, this.lastTarget);
21996
22323
  var targetPosition = new roosterjs_editor_dom_1.Position(this.lastTarget, isBeginAboveEnd ? 0 /* Begin */ : -1 /* End */);
21997
22324
  updateSelection(this.editor, targetPosition.node, targetPosition.offset);
@@ -22006,17 +22333,22 @@ var TableCellSelection = /** @class */ (function () {
22006
22333
  if (which == RIGHT_CLICK && this.tableSelection) {
22007
22334
  //If the user is right clicking To open context menu
22008
22335
  var td = this.editor.getElementAtCursor(TABLE_CELL_SELECTOR);
22009
- if (td === null || td === void 0 ? void 0 : td.classList.contains(TABLE_CELL_SELECTED)) {
22010
- this.firstTarget = null;
22011
- this.lastTarget = null;
22012
- this.editor.queryElements('td.' + TABLE_CELL_SELECTED, function (node) {
22013
- _this.firstTarget = _this.firstTarget || node;
22014
- _this.lastTarget = node;
22015
- });
22016
- var selection = this.editor.getDocument().defaultView.getSelection();
22017
- selection.setBaseAndExtent(this.firstTarget, 0, this.lastTarget, 0);
22018
- (0, highlight_1.highlight)(this.vTable);
22019
- return;
22336
+ var coord = (0, getCellCoordinates_1.getCellCoordinates)(this.vTable, td);
22337
+ if (coord) {
22338
+ var _b = (0, normalizeTableSelection_1.default)(this.vTable), firstCell = _b.firstCell, lastCell = _b.lastCell;
22339
+ if (coord.y >= firstCell.y &&
22340
+ coord.y <= lastCell.y &&
22341
+ coord.x >= firstCell.x &&
22342
+ coord.x <= lastCell.x) {
22343
+ this.firstTarget = this.vTable.getCell(firstCell.y, firstCell.x).td;
22344
+ this.lastTarget = this.vTable.getCell(lastCell.y, lastCell.x).td;
22345
+ if (this.firstTarget && this.lastTarget) {
22346
+ var selection = this.editor.getDocument().defaultView.getSelection();
22347
+ selection.setBaseAndExtent(this.firstTarget, 0, this.lastTarget, 0);
22348
+ this.selectTable();
22349
+ }
22350
+ return;
22351
+ }
22020
22352
  }
22021
22353
  }
22022
22354
  this.editor.getDocument().addEventListener('mouseup', this.onMouseUp, true /*setCapture*/);
@@ -22046,7 +22378,7 @@ var TableCellSelection = /** @class */ (function () {
22046
22378
  };
22047
22379
  _this.firstTarget = first;
22048
22380
  _this.lastTarget = last;
22049
- (0, highlight_1.highlight)(_this.vTable);
22381
+ _this.selectTable();
22050
22382
  _this.tableRange = _this.vTable.selection;
22051
22383
  _this.tableSelection = true;
22052
22384
  _this.firstTable = firstTable;
@@ -22057,7 +22389,9 @@ var TableCellSelection = /** @class */ (function () {
22057
22389
  }
22058
22390
  };
22059
22391
  TableCellSelection.prototype.restoreSelection = function () {
22060
- clearSelectedTableCells(this.editor);
22392
+ if (this.firstTable) {
22393
+ this.editor.select(this.firstTable, null);
22394
+ }
22061
22395
  this.tableSelection = false;
22062
22396
  var isBeginAboveEnd = this.isAfter(this.firstTarget, this.lastTarget);
22063
22397
  var targetPosition = new roosterjs_editor_dom_1.Position(this.lastTarget, isBeginAboveEnd ? -1 /* End */ : 0 /* Begin */);
@@ -22075,7 +22409,7 @@ var TableCellSelection = /** @class */ (function () {
22075
22409
  * @param event mouse event
22076
22410
  */
22077
22411
  TableCellSelection.prototype.selectionInsideTableMouseMove = function (event) {
22078
- var _a, _b;
22412
+ var _a;
22079
22413
  if (this.lastTarget != this.firstTarget) {
22080
22414
  updateSelection(this.editor, this.firstTarget, 0);
22081
22415
  if (this.firstTable != this.targetTable &&
@@ -22083,21 +22417,14 @@ var TableCellSelection = /** @class */ (function () {
22083
22417
  //If selection started in a table that is inside of another table and moves to parent table
22084
22418
  //Make the firstTarget the TD of the parent table.
22085
22419
  this.firstTarget = this.editor.getElementAtCursor(TABLE_CELL_SELECTOR, this.lastTarget);
22086
- this.firstTarget.querySelectorAll('table').forEach(function (table) {
22087
- var vTable = new roosterjs_editor_dom_1.VTable(table);
22088
- (0, highlightAll_1.highlightAll)(vTable);
22089
- });
22090
22420
  }
22091
22421
  if (this.firstTable) {
22092
22422
  this.tableSelection = true;
22093
- if (((_b = this.vTable) === null || _b === void 0 ? void 0 : _b.table) != this.firstTable &&
22094
- (0, roosterjs_editor_dom_1.safeInstanceOf)(this.firstTarget, 'HTMLTableCellElement')) {
22095
- this.vTable = new roosterjs_editor_dom_1.VTable(this.firstTarget);
22096
- }
22423
+ this.vTable = this.vTable || new roosterjs_editor_dom_1.VTable(this.firstTable);
22097
22424
  this.tableRange.firstCell = (0, getCellCoordinates_1.getCellCoordinates)(this.vTable, this.firstTarget);
22098
22425
  this.tableRange.lastCell = (0, getCellCoordinates_1.getCellCoordinates)(this.vTable, this.lastTarget);
22099
22426
  this.vTable.selection = this.tableRange;
22100
- (0, highlight_1.highlight)(this.vTable);
22427
+ this.selectTable();
22101
22428
  }
22102
22429
  event.preventDefault();
22103
22430
  }
@@ -22106,8 +22433,7 @@ var TableCellSelection = /** @class */ (function () {
22106
22433
  this.tableRange.firstCell = (0, getCellCoordinates_1.getCellCoordinates)(this.vTable, this.firstTarget);
22107
22434
  this.tableRange.lastCell = this.tableRange.firstCell;
22108
22435
  this.vTable.selection = this.tableRange;
22109
- (0, highlight_1.highlight)(this.vTable);
22110
- this.tableRange = this.vTable.selection;
22436
+ this.selectTable();
22111
22437
  }
22112
22438
  };
22113
22439
  TableCellSelection.prototype.removeMouseUpEventListener = function () {
@@ -22119,14 +22445,8 @@ var TableCellSelection = /** @class */ (function () {
22119
22445
  };
22120
22446
  //#endregion
22121
22447
  //#region utils
22122
- TableCellSelection.prototype.clearTableCellSelection = function () {
22123
- var _a;
22124
- if ((_a = this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) {
22125
- clearSelectedTableCells(this.editor);
22126
- }
22127
- };
22128
22448
  TableCellSelection.prototype.clearState = function () {
22129
- this.clearTableCellSelection();
22449
+ this.editor.select(null);
22130
22450
  this.vTable = null;
22131
22451
  this.firstTarget = null;
22132
22452
  this.lastTarget = null;
@@ -22248,6 +22568,12 @@ var TableCellSelection = /** @class */ (function () {
22248
22568
  });
22249
22569
  return result;
22250
22570
  };
22571
+ TableCellSelection.prototype.selectTable = function () {
22572
+ var _a;
22573
+ if (this.editor && this.vTable) {
22574
+ (_a = this.editor) === null || _a === void 0 ? void 0 : _a.select(this.vTable.table, (0, normalizeTableSelection_1.default)(this.vTable));
22575
+ }
22576
+ };
22251
22577
  return TableCellSelection;
22252
22578
  }());
22253
22579
  exports.default = TableCellSelection;
@@ -22275,18 +22601,6 @@ function getTableAtCursor(editor, node) {
22275
22601
  }
22276
22602
  return null;
22277
22603
  }
22278
- function clearSelectedTableCells(input) {
22279
- input.queryElements('table.' + TABLE_SELECTED, deselectTable);
22280
- }
22281
- function clearSelectedTables(element) {
22282
- element.querySelectorAll('table.' + TABLE_SELECTED).forEach(deselectTable);
22283
- }
22284
- function deselectTable(element) {
22285
- if ((0, roosterjs_editor_dom_1.safeInstanceOf)(element, 'HTMLTableElement')) {
22286
- var vTable = new roosterjs_editor_dom_1.VTable(element);
22287
- (0, deSelectAll_1.deSelectAll)(vTable);
22288
- }
22289
- }
22290
22604
 
22291
22605
 
22292
22606
  /***/ }),
@@ -22306,105 +22620,6 @@ var TableCellSelection_1 = __webpack_require__(/*! ./TableCellSelection */ "./pa
22306
22620
  Object.defineProperty(exports, "TableCellSelection", { enumerable: true, get: function () { return TableCellSelection_1.default; } });
22307
22621
 
22308
22622
 
22309
- /***/ }),
22310
-
22311
- /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deSelectAll.ts":
22312
- /*!***********************************************************************************************!*\
22313
- !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deSelectAll.ts ***!
22314
- \***********************************************************************************************/
22315
- /*! no static exports found */
22316
- /***/ (function(module, exports, __webpack_require__) {
22317
-
22318
- "use strict";
22319
-
22320
- Object.defineProperty(exports, "__esModule", { value: true });
22321
- exports.deSelectAll = void 0;
22322
- var deselectCellHandler_1 = __webpack_require__(/*! ./deselectCellHandler */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deselectCellHandler.ts");
22323
- var forEachCell_1 = __webpack_require__(/*! ./forEachCell */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachCell.ts");
22324
- /**
22325
- * @internal
22326
- * Removes the selection of all the tables
22327
- */
22328
- function deSelectAll(vTable) {
22329
- var _a;
22330
- (0, forEachCell_1.forEachCell)(vTable, function (cell) {
22331
- if (cell.td) {
22332
- (0, deselectCellHandler_1.deselectCellHandler)(cell.td);
22333
- }
22334
- });
22335
- if ((_a = vTable.table) === null || _a === void 0 ? void 0 : _a.classList.contains("_tableSelected" /* TABLE_SELECTED */)) {
22336
- vTable.table.classList.remove("_tableSelected" /* TABLE_SELECTED */);
22337
- }
22338
- }
22339
- exports.deSelectAll = deSelectAll;
22340
-
22341
-
22342
- /***/ }),
22343
-
22344
- /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deselectCellHandler.ts":
22345
- /*!*******************************************************************************************************!*\
22346
- !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deselectCellHandler.ts ***!
22347
- \*******************************************************************************************************/
22348
- /*! no static exports found */
22349
- /***/ (function(module, exports, __webpack_require__) {
22350
-
22351
- "use strict";
22352
-
22353
- Object.defineProperty(exports, "__esModule", { value: true });
22354
- exports.deselectCellHandler = void 0;
22355
- var forEachCell_1 = __webpack_require__(/*! ./forEachCell */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachCell.ts");
22356
- var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
22357
- /**
22358
- * @internal
22359
- * Handler to remove the selected style
22360
- * @param cell element to apply the style
22361
- */
22362
- function deselectCellHandler(cell) {
22363
- var _a;
22364
- if (cell &&
22365
- (0, roosterjs_editor_dom_1.safeInstanceOf)(cell, 'HTMLTableCellElement') &&
22366
- cell.classList.contains("_tableCellSelected" /* TABLE_CELL_SELECTED */)) {
22367
- cell.classList.remove("_tableCellSelected" /* TABLE_CELL_SELECTED */);
22368
- cell.style.backgroundColor =
22369
- (_a = cell.dataset["originalBackgroundColor" /* TEMP_BACKGROUND_COLOR */]) !== null && _a !== void 0 ? _a : '';
22370
- delete cell.dataset["originalBackgroundColor" /* TEMP_BACKGROUND_COLOR */];
22371
- cell.querySelectorAll('table').forEach(function (table) {
22372
- var vTable2 = new roosterjs_editor_dom_1.VTable(table);
22373
- (0, forEachCell_1.forEachCell)(vTable2, function (cell) { return deselectCellHandler(cell.td); });
22374
- });
22375
- }
22376
- }
22377
- exports.deselectCellHandler = deselectCellHandler;
22378
-
22379
-
22380
- /***/ }),
22381
-
22382
- /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachCell.ts":
22383
- /*!***********************************************************************************************!*\
22384
- !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachCell.ts ***!
22385
- \***********************************************************************************************/
22386
- /*! no static exports found */
22387
- /***/ (function(module, exports, __webpack_require__) {
22388
-
22389
- "use strict";
22390
-
22391
- Object.defineProperty(exports, "__esModule", { value: true });
22392
- exports.forEachCell = void 0;
22393
- /**
22394
- * @internal
22395
- * Execute an action on all the cells
22396
- * @param callback action to apply on all the cells.
22397
- */
22398
- function forEachCell(vTable, callback) {
22399
- for (var indexY = 0; indexY < vTable.cells.length; indexY++) {
22400
- for (var indexX = 0; indexX < vTable.cells[indexY].length; indexX++) {
22401
- callback(vTable.cells[indexY][indexX], indexX, indexY);
22402
- }
22403
- }
22404
- }
22405
- exports.forEachCell = forEachCell;
22406
-
22407
-
22408
22623
  /***/ }),
22409
22624
 
22410
22625
  /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachSelectedCell.ts":
@@ -22425,21 +22640,15 @@ exports.forEachSelectedCell = void 0;
22425
22640
  * @returns the amount of cells modified
22426
22641
  */
22427
22642
  function forEachSelectedCell(vTable, callback) {
22428
- var selectedCells = 0;
22429
- var _a = vTable.selection, lastCell = _a.lastCell, firstCell = _a.firstCell;
22430
- for (var y = 0; y < vTable.cells.length; y++) {
22431
- for (var x = 0; x < vTable.cells[y].length; x++) {
22432
- var element = vTable.cells[y][x].td;
22433
- if ((element === null || element === void 0 ? void 0 : element.classList.contains("_tableCellSelected" /* TABLE_CELL_SELECTED */)) ||
22434
- (((y >= firstCell.y && y <= lastCell.y) || (y <= firstCell.y && y >= lastCell.y)) &&
22435
- ((x >= firstCell.x && x <= lastCell.x) ||
22436
- (x <= firstCell.x && x >= lastCell.x)))) {
22437
- selectedCells += 1;
22643
+ var _a;
22644
+ var _b = vTable.selection, lastCell = _b.lastCell, firstCell = _b.firstCell;
22645
+ for (var y = firstCell.y; y <= lastCell.y; y++) {
22646
+ for (var x = firstCell.x; x <= lastCell.x; x++) {
22647
+ if ((_a = vTable.cells[y][x]) === null || _a === void 0 ? void 0 : _a.td) {
22438
22648
  callback(vTable.cells[y][x]);
22439
22649
  }
22440
22650
  }
22441
22651
  }
22442
- return selectedCells;
22443
22652
  }
22444
22653
  exports.forEachSelectedCell = forEachSelectedCell;
22445
22654
 
@@ -22465,7 +22674,7 @@ exports.getCellCoordinates = void 0;
22465
22674
  */
22466
22675
  function getCellCoordinates(vTable, cellInput) {
22467
22676
  var result;
22468
- if (vTable.cells) {
22677
+ if (vTable === null || vTable === void 0 ? void 0 : vTable.cells) {
22469
22678
  for (var indexY = 0; indexY < vTable.cells.length; indexY++) {
22470
22679
  for (var indexX = 0; indexX < vTable.cells[indexY].length; indexX++) {
22471
22680
  if (cellInput == vTable.cells[indexY][indexX].td) {
@@ -22482,166 +22691,6 @@ function getCellCoordinates(vTable, cellInput) {
22482
22691
  exports.getCellCoordinates = getCellCoordinates;
22483
22692
 
22484
22693
 
22485
- /***/ }),
22486
-
22487
- /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlight.ts":
22488
- /*!*********************************************************************************************!*\
22489
- !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlight.ts ***!
22490
- \*********************************************************************************************/
22491
- /*! no static exports found */
22492
- /***/ (function(module, exports, __webpack_require__) {
22493
-
22494
- "use strict";
22495
-
22496
- Object.defineProperty(exports, "__esModule", { value: true });
22497
- exports.highlight = void 0;
22498
- var deselectCellHandler_1 = __webpack_require__(/*! ./deselectCellHandler */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/deselectCellHandler.ts");
22499
- var highlightCellHandler_1 = __webpack_require__(/*! ./highlightCellHandler */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightCellHandler.ts");
22500
- var normalizeTableSelection_1 = __webpack_require__(/*! ./normalizeTableSelection */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/normalizeTableSelection.ts");
22501
- /**
22502
- * @internal
22503
- * Highlights a range of cells, used in the TableSelection Plugin
22504
- */
22505
- function highlight(vTable) {
22506
- if (vTable.selection && vTable.cells && vTable) {
22507
- if (!vTable.table.classList.contains("_tableSelected" /* TABLE_SELECTED */)) {
22508
- vTable.table.classList.add("_tableSelected" /* TABLE_SELECTED */);
22509
- }
22510
- var _a = (0, normalizeTableSelection_1.normalizeTableSelection)(vTable.selection), firstCell = _a.firstCell, lastCell = _a.lastCell;
22511
- var colIndex = vTable.cells[vTable.cells.length - 1].length - 1;
22512
- var selectedAllTable = firstCell.x == 0 &&
22513
- firstCell.y == 0 &&
22514
- lastCell.x == colIndex &&
22515
- lastCell.y == vTable.cells.length - 1;
22516
- for (var indexY = 0; indexY < vTable.cells.length; indexY++) {
22517
- for (var indexX = 0; indexX < vTable.cells[indexY].length; indexX++) {
22518
- var element = getMergedCell(vTable, indexX, indexY);
22519
- if (element) {
22520
- if (selectedAllTable ||
22521
- (((indexY >= firstCell.y && indexY <= lastCell.y) ||
22522
- (indexY <= firstCell.y && indexY >= lastCell.y)) &&
22523
- ((indexX >= firstCell.x && indexX <= lastCell.x) ||
22524
- (indexX <= firstCell.x && indexX >= lastCell.x)))) {
22525
- (0, highlightCellHandler_1.highlightCellHandler)(element);
22526
- }
22527
- else {
22528
- (0, deselectCellHandler_1.deselectCellHandler)(element);
22529
- }
22530
- }
22531
- }
22532
- }
22533
- }
22534
- }
22535
- exports.highlight = highlight;
22536
- function getMergedCell(vTable, x, y) {
22537
- var element = vTable.cells[y][x].td;
22538
- if (vTable.cells[y][x].spanLeft) {
22539
- for (var cellX = x; cellX > 0; cellX--) {
22540
- var cell = vTable.cells[y][cellX];
22541
- if (cell.spanAbove) {
22542
- element = null;
22543
- break;
22544
- }
22545
- if (cell.td) {
22546
- element = cell.td;
22547
- x = cellX;
22548
- break;
22549
- }
22550
- }
22551
- }
22552
- return element;
22553
- }
22554
-
22555
-
22556
- /***/ }),
22557
-
22558
- /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightAll.ts":
22559
- /*!************************************************************************************************!*\
22560
- !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightAll.ts ***!
22561
- \************************************************************************************************/
22562
- /*! no static exports found */
22563
- /***/ (function(module, exports, __webpack_require__) {
22564
-
22565
- "use strict";
22566
-
22567
- Object.defineProperty(exports, "__esModule", { value: true });
22568
- exports.highlightAll = void 0;
22569
- var forEachCell_1 = __webpack_require__(/*! ./forEachCell */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/forEachCell.ts");
22570
- var highlightCellHandler_1 = __webpack_require__(/*! ./highlightCellHandler */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightCellHandler.ts");
22571
- /**
22572
- * @internal
22573
- * Highlights all the cells in the table.
22574
- */
22575
- function highlightAll(vTable) {
22576
- var firstCol = null;
22577
- var firstRow = null;
22578
- var lastCol;
22579
- var lastRow;
22580
- if (!vTable.table.classList.contains("_tableSelected" /* TABLE_SELECTED */)) {
22581
- vTable.table.classList.add("_tableSelected" /* TABLE_SELECTED */);
22582
- }
22583
- (0, forEachCell_1.forEachCell)(vTable, function (cell, x, y) {
22584
- if (cell.td) {
22585
- (0, highlightCellHandler_1.highlightCellHandler)(cell.td);
22586
- firstCol = firstCol !== null && firstCol !== void 0 ? firstCol : x;
22587
- firstRow = firstRow !== null && firstRow !== void 0 ? firstRow : y;
22588
- lastCol = x;
22589
- lastRow = y;
22590
- }
22591
- });
22592
- vTable.selection = {
22593
- firstCell: {
22594
- x: firstCol,
22595
- y: firstRow,
22596
- },
22597
- lastCell: {
22598
- x: lastCol,
22599
- y: lastRow,
22600
- },
22601
- };
22602
- }
22603
- exports.highlightAll = highlightAll;
22604
-
22605
-
22606
- /***/ }),
22607
-
22608
- /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightCellHandler.ts":
22609
- /*!********************************************************************************************************!*\
22610
- !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/highlightCellHandler.ts ***!
22611
- \********************************************************************************************************/
22612
- /*! no static exports found */
22613
- /***/ (function(module, exports, __webpack_require__) {
22614
-
22615
- "use strict";
22616
-
22617
- Object.defineProperty(exports, "__esModule", { value: true });
22618
- exports.highlightCellHandler = void 0;
22619
- var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
22620
- /**
22621
- * @internal
22622
- * Handler to apply te selected styles on the cell
22623
- * @param element element to apply the style
22624
- */
22625
- function highlightCellHandler(element) {
22626
- var _a, _b;
22627
- if (!element.classList.contains("_tableCellSelected" /* TABLE_CELL_SELECTED */) &&
22628
- element.style.backgroundColor != "rgba(198,198,198,0.7)" /* HIGHLIGHT_COLOR */ &&
22629
- (!element.dataset["originalBackgroundColor" /* TEMP_BACKGROUND_COLOR */] ||
22630
- element.dataset["originalBackgroundColor" /* TEMP_BACKGROUND_COLOR */] == '')) {
22631
- element.dataset["originalBackgroundColor" /* TEMP_BACKGROUND_COLOR */] =
22632
- (_b = (_a = element.style.backgroundColor) !== null && _a !== void 0 ? _a : element.style.background) !== null && _b !== void 0 ? _b : '';
22633
- }
22634
- element.style.backgroundColor = "rgba(198,198,198,0.7)" /* HIGHLIGHT_COLOR */;
22635
- element.classList.add("_tableCellSelected" /* TABLE_CELL_SELECTED */);
22636
- element.querySelectorAll('td, th').forEach(function (cell) {
22637
- if ((0, roosterjs_editor_dom_1.safeInstanceOf)(cell, 'HTMLTableCellElement')) {
22638
- highlightCellHandler(cell);
22639
- }
22640
- });
22641
- }
22642
- exports.highlightCellHandler = highlightCellHandler;
22643
-
22644
-
22645
22694
  /***/ }),
22646
22695
 
22647
22696
  /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/normalizeTableSelection.ts":
@@ -22654,7 +22703,6 @@ exports.highlightCellHandler = highlightCellHandler;
22654
22703
  "use strict";
22655
22704
 
22656
22705
  Object.defineProperty(exports, "__esModule", { value: true });
22657
- exports.normalizeTableSelection = void 0;
22658
22706
  /**
22659
22707
  * @internal
22660
22708
  * Make the first Cell of a table selection always be on top of the last cell.
@@ -22662,25 +22710,40 @@ exports.normalizeTableSelection = void 0;
22662
22710
  * @returns Table Selection where the first cell is always going to be first selected in the table
22663
22711
  * and the last cell always going to be last selected in the table.
22664
22712
  */
22665
- function normalizeTableSelection(input) {
22666
- var firstCell = input.firstCell, lastCell = input.lastCell;
22713
+ function normalizeTableSelection(vTable) {
22714
+ if (!vTable || !vTable.selection) {
22715
+ return null;
22716
+ }
22717
+ var _a = vTable.selection, firstCell = _a.firstCell, lastCell = _a.lastCell;
22718
+ var rows = vTable.table.rows;
22667
22719
  var newFirst = {
22668
- x: min(firstCell.x, lastCell.x),
22669
- y: min(firstCell.y, lastCell.y),
22720
+ x: Math.min(firstCell.x, lastCell.x),
22721
+ y: Math.min(firstCell.y, lastCell.y),
22670
22722
  };
22671
22723
  var newLast = {
22672
- x: max(firstCell.x, lastCell.x),
22673
- y: max(firstCell.y, lastCell.y),
22724
+ x: Math.max(firstCell.x, lastCell.x),
22725
+ y: Math.max(firstCell.y, lastCell.y),
22726
+ };
22727
+ var fixCoordinates = function (coord) {
22728
+ if (coord.x < 0) {
22729
+ coord.x = 0;
22730
+ }
22731
+ if (coord.y < 0) {
22732
+ coord.y = 0;
22733
+ }
22734
+ if (coord.y >= rows.length) {
22735
+ coord.y = rows.length - 1;
22736
+ }
22737
+ var rowsCells = rows.item(coord.y).cells.length;
22738
+ if (coord.x >= rowsCells) {
22739
+ coord.x = rowsCells - 1;
22740
+ }
22674
22741
  };
22742
+ fixCoordinates(firstCell);
22743
+ fixCoordinates(lastCell);
22675
22744
  return { firstCell: newFirst, lastCell: newLast };
22676
22745
  }
22677
- exports.normalizeTableSelection = normalizeTableSelection;
22678
- function min(input1, input2) {
22679
- return input1 > input2 ? input2 : input1;
22680
- }
22681
- function max(input1, input2) {
22682
- return input1 < input2 ? input2 : input1;
22683
- }
22746
+ exports.default = normalizeTableSelection;
22684
22747
 
22685
22748
 
22686
22749
  /***/ }),
@@ -22696,13 +22759,13 @@ function max(input1, input2) {
22696
22759
 
22697
22760
  Object.defineProperty(exports, "__esModule", { value: true });
22698
22761
  exports.removeCellsOutsideSelection = void 0;
22699
- var normalizeTableSelection_1 = __webpack_require__(/*! ./normalizeTableSelection */ "./packages/roosterjs-editor-plugins/lib/plugins/TableCellSelection/utils/normalizeTableSelection.ts");
22700
22762
  /**
22701
22763
  * @internal
22702
22764
  * Remove the cells outside of the selection.
22765
+ * @param vTable VTable to remove selection
22703
22766
  */
22704
22767
  function removeCellsOutsideSelection(vTable) {
22705
- var _a = (0, normalizeTableSelection_1.normalizeTableSelection)(vTable.selection), firstCell = _a.firstCell, lastCell = _a.lastCell;
22768
+ var _a = vTable.selection, firstCell = _a.firstCell, lastCell = _a.lastCell;
22706
22769
  var rowsLength = vTable.cells.length - 1;
22707
22770
  var colIndex = vTable.cells[rowsLength].length - 1;
22708
22771
  var resultCells = [];
@@ -22715,10 +22778,7 @@ function removeCellsOutsideSelection(vTable) {
22715
22778
  return;
22716
22779
  }
22717
22780
  vTable.cells.forEach(function (row, y) {
22718
- row = row.filter(function (_, x) {
22719
- return ((y >= firstY && y <= lastY) || (y <= firstY && y >= lastY)) &&
22720
- ((x >= firstX && x <= lastX) || (x <= firstX && x >= lastX));
22721
- });
22781
+ row = row.filter(function (_, x) { return y >= firstY && y <= lastY && x >= firstX && x <= lastX; });
22722
22782
  if (row.length > 0) {
22723
22783
  resultCells.push(row);
22724
22784
  }
@@ -22756,7 +22816,9 @@ var TableResize = /** @class */ (function () {
22756
22816
  return;
22757
22817
  }
22758
22818
  _this.ensureTableRects();
22759
- var x = e.pageX, y = e.pageY;
22819
+ var editorWindow = _this.editor.getDocument().defaultView;
22820
+ var x = e.pageX - editorWindow.scrollX;
22821
+ var y = e.pageY - editorWindow.scrollY;
22760
22822
  var currentTable = null;
22761
22823
  for (var i = _this.tableRectMap.length - 1; i >= 0; i--) {
22762
22824
  var _b = _this.tableRectMap[i], table = _b.table, rect = _b.rect;
@@ -22807,6 +22869,7 @@ var TableResize = /** @class */ (function () {
22807
22869
  case 3 /* Input */:
22808
22870
  case 7 /* ContentChanged */:
22809
22871
  case 14 /* Scroll */:
22872
+ case 21 /* ZoomChanged */:
22810
22873
  this.setTableEditor(null);
22811
22874
  this.invalidateTableRects();
22812
22875
  break;
@@ -22862,13 +22925,13 @@ var MIN_CELL_WIDTH = 30;
22862
22925
  /**
22863
22926
  * @internal
22864
22927
  */
22865
- function createCellResizer(td, sizeTransformer, isRTL, isHorizontal, onStart, onEnd) {
22928
+ function createCellResizer(td, zoomScale, isRTL, isHorizontal, onStart, onEnd) {
22866
22929
  var document = td.ownerDocument;
22867
22930
  var div = (0, roosterjs_editor_dom_1.createElement)(isHorizontal
22868
22931
  ? 7 /* TableHorizontalResizer */
22869
22932
  : 8 /* TableVerticalResizer */, document);
22870
22933
  document.body.appendChild(div);
22871
- var context = { td: td, isRTL: isRTL, sizeTransformer: sizeTransformer, onStart: onStart };
22934
+ var context = { td: td, isRTL: isRTL, zoomScale: zoomScale, onStart: onStart };
22872
22935
  var setPosition = isHorizontal ? setHorizontalPosition : setVerticalPosition;
22873
22936
  setPosition(context, div);
22874
22937
  var handler = {
@@ -22876,13 +22939,13 @@ function createCellResizer(td, sizeTransformer, isRTL, isHorizontal, onStart, on
22876
22939
  onDragging: isHorizontal ? onDraggingHorizontal : onDraggingVertical,
22877
22940
  onDragEnd: onEnd,
22878
22941
  };
22879
- var featureHandler = new DragAndDropHelper_1.default(div, context, setPosition, handler, sizeTransformer);
22942
+ var featureHandler = new DragAndDropHelper_1.default(div, context, setPosition, handler, zoomScale);
22880
22943
  return { node: td, div: div, featureHandler: featureHandler };
22881
22944
  }
22882
22945
  exports.default = createCellResizer;
22883
22946
  function onDragStart(context, event) {
22884
- var td = context.td, isRTL = context.isRTL, sizeTransformer = context.sizeTransformer, onStart = context.onStart;
22885
- var vTable = new roosterjs_editor_dom_1.VTable(td, true /*normalizeSize*/, sizeTransformer);
22947
+ var td = context.td, isRTL = context.isRTL, zoomScale = context.zoomScale, onStart = context.onStart;
22948
+ var vTable = new roosterjs_editor_dom_1.VTable(td, true /*normalizeSize*/, zoomScale);
22886
22949
  var rect = (0, roosterjs_editor_dom_1.normalizeRect)(td.getBoundingClientRect());
22887
22950
  if (rect) {
22888
22951
  onStart();
@@ -22900,23 +22963,22 @@ function onDragStart(context, event) {
22900
22963
  }
22901
22964
  }
22902
22965
  function onDraggingHorizontal(context, event, initValue, deltaX, deltaY) {
22903
- var td = context.td, sizeTransformer = context.sizeTransformer;
22966
+ var td = context.td, zoomScale = context.zoomScale;
22904
22967
  var vTable = initValue.vTable;
22905
22968
  vTable.table.removeAttribute('height');
22906
22969
  vTable.table.style.height = null;
22907
22970
  vTable.forEachCellOfCurrentRow(function (cell) {
22908
22971
  if (cell.td) {
22909
- cell.td.style.height =
22910
- cell.td == td ? sizeTransformer(cell.height) + deltaY + "px" : null;
22972
+ cell.td.style.height = cell.td == td ? cell.height / zoomScale + deltaY + "px" : null;
22911
22973
  }
22912
22974
  });
22913
22975
  vTable.writeBack();
22914
22976
  return true;
22915
22977
  }
22916
22978
  function onDraggingVertical(context, event, initValue, deltaX, deltaY) {
22917
- var isRTL = context.isRTL, sizeTransformer = context.sizeTransformer;
22979
+ var isRTL = context.isRTL, zoomScale = context.zoomScale;
22918
22980
  var vTable = initValue.vTable, nextCells = initValue.nextCells, currentCells = initValue.currentCells;
22919
- if (!canResizeColumns(event.pageX, currentCells, nextCells, isRTL, sizeTransformer)) {
22981
+ if (!canResizeColumns(event.pageX, currentCells, nextCells, isRTL, zoomScale)) {
22920
22982
  return false;
22921
22983
  }
22922
22984
  // Since we allow the user to resize the table width on adjusting the border of the last cell,
@@ -22934,7 +22996,7 @@ function onDraggingVertical(context, event, initValue, deltaX, deltaY) {
22934
22996
  td.style.wordBreak = 'break-word';
22935
22997
  td.style.whiteSpace = 'normal';
22936
22998
  td.style.boxSizing = 'border-box';
22937
- var newWidth = sizeTransformer(getHorizontalDistance(rect, event.pageX, !isRTL));
22999
+ var newWidth = getHorizontalDistance(rect, event.pageX, !isRTL) / zoomScale;
22938
23000
  newWidthList.set(td, newWidth);
22939
23001
  }
22940
23002
  });
@@ -22981,12 +23043,12 @@ function setVerticalPosition(context, trigger) {
22981
23043
  * @returns if the move is allowed, or, if any of the cells on either side of the vertical border is smaller than
22982
23044
  * the minimum width, such move is not allowed
22983
23045
  */
22984
- function canResizeColumns(newPos, currentCells, nextCells, isRTL, sizeTransformer) {
23046
+ function canResizeColumns(newPos, currentCells, nextCells, isRTL, zoomScale) {
22985
23047
  for (var i = 0; i < currentCells.length; i++) {
22986
23048
  var td = currentCells[i];
22987
23049
  var rect = (0, roosterjs_editor_dom_1.normalizeRect)(td.getBoundingClientRect());
22988
23050
  if (rect) {
22989
- var width = sizeTransformer(getHorizontalDistance(rect, newPos, !isRTL));
23051
+ var width = getHorizontalDistance(rect, newPos, !isRTL) / zoomScale;
22990
23052
  if (width < MIN_CELL_WIDTH) {
22991
23053
  return false;
22992
23054
  }
@@ -22998,7 +23060,7 @@ function canResizeColumns(newPos, currentCells, nextCells, isRTL, sizeTransforme
22998
23060
  if (td) {
22999
23061
  var rect = (0, roosterjs_editor_dom_1.normalizeRect)(td.getBoundingClientRect());
23000
23062
  if (rect) {
23001
- width = sizeTransformer(getHorizontalDistance(rect, newPos, isRTL));
23063
+ width = getHorizontalDistance(rect, newPos, isRTL) / zoomScale;
23002
23064
  }
23003
23065
  }
23004
23066
  if (width < MIN_CELL_WIDTH) {
@@ -23024,6 +23086,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23024
23086
  var CellResizer_1 = __webpack_require__(/*! ./CellResizer */ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/CellResizer.ts");
23025
23087
  var TableInserter_1 = __webpack_require__(/*! ./TableInserter */ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableInserter.ts");
23026
23088
  var TableResizer_1 = __webpack_require__(/*! ./TableResizer */ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableResizer.ts");
23089
+ var TableSelector_1 = __webpack_require__(/*! ./TableSelector */ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableSelector.ts");
23027
23090
  var TableEditorFeature_1 = __webpack_require__(/*! ./TableEditorFeature */ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableEditorFeature.ts");
23028
23091
  var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
23029
23092
  var INSERTER_HOVER_OFFSET = 5;
@@ -23031,26 +23094,28 @@ var INSERTER_HOVER_OFFSET = 5;
23031
23094
  * @internal
23032
23095
  *
23033
23096
  * A table has 5 hot areas to be resized/edited (take LTR example):
23034
- * [ ]
23035
- * +[ 1 ]+--------------------+
23036
- * |[ ]| |
23037
- * [ ] [ ] |
23038
- * [ ] [ ] |
23039
- * [2] [3] |
23040
- * [ ] [ ] |
23041
- * [ ][ 4 ]| |
23042
- * +------------------+--------------------+
23043
- * | | |
23044
- * | | |
23045
- * | | |
23046
- * +------------------+--------------------+
23047
- * [5]
23097
+ *
23098
+ * [6] [ ]
23099
+ * +[ 1 ]+--------------------+
23100
+ * |[ ]| |
23101
+ * [ ] [ ] |
23102
+ * [ ] [ ] |
23103
+ * [2] [3] |
23104
+ * [ ] [ ] |
23105
+ * [ ][ 4 ]| |
23106
+ * +------------------+--------------------+
23107
+ * | | |
23108
+ * | | |
23109
+ * | | |
23110
+ * +------------------+--------------------+
23111
+ * [5]
23048
23112
  *
23049
23113
  * 1 - Hover area to show insert column button
23050
23114
  * 2 - Hover area to show insert row button
23051
23115
  * 3 - Hover area to show vertical resizing bar
23052
23116
  * 4 - Hover area to show horizontal resizing bar
23053
23117
  * 5 - Hover area to show whole table resize button
23118
+ * 6 - Hover area to show whole table selector button
23054
23119
  *
23055
23120
  * When set a different current table or change current TD, we need to update these areas
23056
23121
  */
@@ -23074,9 +23139,33 @@ var TableEditor = /** @class */ (function () {
23074
23139
  _this.disposeTableResizer();
23075
23140
  _this.onFinishEditing();
23076
23141
  };
23077
- var sizeTransformer = editor.getSizeTransformer();
23142
+ this.onSelect = function (table) {
23143
+ _this.editor.focus();
23144
+ if (table) {
23145
+ var vTable = new roosterjs_editor_dom_1.VTable(table);
23146
+ var rows = vTable.cells.length - 1;
23147
+ var lastCellIndex_1 = 0;
23148
+ vTable.cells[rows].forEach(function (cell, index) {
23149
+ if (cell.td) {
23150
+ lastCellIndex_1 = index;
23151
+ }
23152
+ });
23153
+ var selection = {
23154
+ firstCell: {
23155
+ x: 0,
23156
+ y: 0,
23157
+ },
23158
+ lastCell: {
23159
+ y: rows,
23160
+ x: lastCellIndex_1,
23161
+ },
23162
+ };
23163
+ _this.editor.select(table, selection);
23164
+ }
23165
+ };
23078
23166
  this.isRTL = (0, roosterjs_editor_dom_1.getComputedStyle)(table, 'direction') == 'rtl';
23079
- this.tableResizer = (0, TableResizer_1.default)(table, sizeTransformer, this.isRTL, this.onFinishEditing);
23167
+ this.tableResizer = (0, TableResizer_1.default)(table, editor.getZoomScale(), this.isRTL, this.onFinishEditing);
23168
+ this.tableSelector = (0, TableSelector_1.default)(table, editor.getZoomScale(), this.onSelect);
23080
23169
  this.editor.addUndoSnapshot(function (start, end) {
23081
23170
  _this.start = start;
23082
23171
  _this.end = end;
@@ -23086,6 +23175,7 @@ var TableEditor = /** @class */ (function () {
23086
23175
  this.disposeTableResizer();
23087
23176
  this.disposeCellResizers();
23088
23177
  this.disposeTableInserter();
23178
+ this.disposeTableSelector();
23089
23179
  };
23090
23180
  TableEditor.prototype.onMouseMove = function (x, y) {
23091
23181
  var _a;
@@ -23131,9 +23221,9 @@ var TableEditor = /** @class */ (function () {
23131
23221
  this.disposeCellResizers();
23132
23222
  }
23133
23223
  if (!this.horizontalResizer && td) {
23134
- var sizeTransformer = this.editor.getSizeTransformer();
23135
- this.horizontalResizer = (0, CellResizer_1.default)(td, sizeTransformer, this.isRTL, true /*isHorizontal*/, this.onStartCellResize, this.onFinishEditing);
23136
- this.verticalResizer = (0, CellResizer_1.default)(td, sizeTransformer, this.isRTL, false /*isHorizontal*/, this.onStartCellResize, this.onFinishEditing);
23224
+ var zoomScale = this.editor.getZoomScale();
23225
+ this.horizontalResizer = (0, CellResizer_1.default)(td, zoomScale, this.isRTL, true /*isHorizontal*/, this.onStartCellResize, this.onFinishEditing);
23226
+ this.verticalResizer = (0, CellResizer_1.default)(td, zoomScale, this.isRTL, false /*isHorizontal*/, this.onStartCellResize, this.onFinishEditing);
23137
23227
  }
23138
23228
  };
23139
23229
  TableEditor.prototype.setInserterTd = function (td, isHorizontal) {
@@ -23177,6 +23267,12 @@ var TableEditor = /** @class */ (function () {
23177
23267
  this.verticalResizer = null;
23178
23268
  }
23179
23269
  };
23270
+ TableEditor.prototype.disposeTableSelector = function () {
23271
+ if (this.tableSelector) {
23272
+ (0, TableEditorFeature_1.disposeTableEditFeature)(this.tableSelector);
23273
+ this.tableSelector = null;
23274
+ }
23275
+ };
23180
23276
  return TableEditor;
23181
23277
  }());
23182
23278
  exports.default = TableEditor;
@@ -23249,23 +23345,23 @@ function createTableInserter(editor, td, isRTL, isHorizontal, onInsert) {
23249
23345
  div.firstChild.style.height = tableRect.bottom - tableRect.top + "px";
23250
23346
  }
23251
23347
  document_1.body.appendChild(div);
23252
- var handler = new TableInsertHandler(div, td, isHorizontal, editor.getSizeTransformer(), onInsert);
23348
+ var handler = new TableInsertHandler(div, td, isHorizontal, editor.getZoomScale(), onInsert);
23253
23349
  return { div: div, featureHandler: handler, node: td };
23254
23350
  }
23255
23351
  }
23256
23352
  exports.default = createTableInserter;
23257
23353
  var TableInsertHandler = /** @class */ (function () {
23258
- function TableInsertHandler(div, td, isHorizontal, sizeTransformer, onInsert) {
23354
+ function TableInsertHandler(div, td, isHorizontal, zoomScale, onInsert) {
23259
23355
  var _this = this;
23260
23356
  this.div = div;
23261
23357
  this.td = td;
23262
23358
  this.isHorizontal = isHorizontal;
23263
- this.sizeTransformer = sizeTransformer;
23359
+ this.zoomScale = zoomScale;
23264
23360
  this.onInsert = onInsert;
23265
23361
  this.insertTd = function () {
23266
23362
  var vtable = new roosterjs_editor_dom_1.VTable(_this.td);
23267
23363
  if (!_this.isHorizontal) {
23268
- vtable.normalizeTableCellSize(_this.sizeTransformer);
23364
+ vtable.normalizeTableCellSize(_this.zoomScale);
23269
23365
  // Since adding new column will cause table width to change, we need to remove width properties
23270
23366
  vtable.table.removeAttribute('width');
23271
23367
  vtable.table.style.width = null;
@@ -23322,7 +23418,7 @@ var MIN_CELL_HEIGHT = 20;
23322
23418
  /**
23323
23419
  * @internal
23324
23420
  */
23325
- function createTableResizer(table, sizeTransformer, isRTL, onDragEnd) {
23421
+ function createTableResizer(table, zoomScale, isRTL, onDragEnd) {
23326
23422
  var document = table.ownerDocument;
23327
23423
  var div = (0, roosterjs_editor_dom_1.createElement)(isRTL
23328
23424
  ? 10 /* TableResizerRTL */
@@ -23333,28 +23429,28 @@ function createTableResizer(table, sizeTransformer, isRTL, onDragEnd) {
23333
23429
  var context = {
23334
23430
  isRTL: isRTL,
23335
23431
  table: table,
23336
- sizeTransformer: sizeTransformer,
23432
+ zoomScale: zoomScale,
23337
23433
  };
23338
23434
  setResizeDivPosition(context, div);
23339
23435
  var featureHandler = new DragAndDropHelper_1.default(div, context, setResizeDivPosition, {
23340
23436
  onDragStart: onDragStart,
23341
23437
  onDragging: onDragging,
23342
23438
  onDragEnd: onDragEnd,
23343
- }, sizeTransformer);
23439
+ }, zoomScale);
23344
23440
  return { node: table, div: div, featureHandler: featureHandler };
23345
23441
  }
23346
23442
  exports.default = createTableResizer;
23347
23443
  function onDragStart(context, event) {
23348
23444
  return {
23349
23445
  originalRect: context.table.getBoundingClientRect(),
23350
- vTable: new roosterjs_editor_dom_1.VTable(context.table, true /*normalizeTable*/, context.sizeTransformer),
23446
+ vTable: new roosterjs_editor_dom_1.VTable(context.table, true /*normalizeTable*/, context.zoomScale),
23351
23447
  };
23352
23448
  }
23353
23449
  function onDragging(context, event, initValue, deltaX, deltaY) {
23354
- var isRTL = context.isRTL, sizeTransformer = context.sizeTransformer;
23450
+ var isRTL = context.isRTL, zoomScale = context.zoomScale;
23355
23451
  var originalRect = initValue.originalRect, vTable = initValue.vTable;
23356
- var ratioX = 1.0 + (deltaX / sizeTransformer(originalRect.width)) * (isRTL ? -1 : 1);
23357
- var ratioY = 1.0 + deltaY / sizeTransformer(originalRect.height);
23452
+ var ratioX = 1.0 + (deltaX / originalRect.width) * zoomScale * (isRTL ? -1 : 1);
23453
+ var ratioY = 1.0 + (deltaY / originalRect.height) * zoomScale;
23358
23454
  var shouldResizeX = Math.abs(ratioX - 1.0) > 1e-3;
23359
23455
  var shouldResizeY = Math.abs(ratioY - 1.0) > 1e-3;
23360
23456
  if (shouldResizeX || shouldResizeY) {
@@ -23365,7 +23461,7 @@ function onDragging(context, event, initValue, deltaX, deltaY) {
23365
23461
  if (shouldResizeX) {
23366
23462
  // the width of some external table is fixed, we need to make it resizable
23367
23463
  vTable.table.style.width = null;
23368
- var newWidth = sizeTransformer(cell.width * ratioX);
23464
+ var newWidth = (cell.width * ratioX) / zoomScale;
23369
23465
  cell.td.style.boxSizing = 'border-box';
23370
23466
  if (newWidth >= MIN_CELL_WIDTH) {
23371
23467
  cell.td.style.wordBreak = 'break-word';
@@ -23377,7 +23473,7 @@ function onDragging(context, event, initValue, deltaX, deltaY) {
23377
23473
  // the height of some external table is fixed, we need to make it resizable
23378
23474
  vTable.table.style.height = null;
23379
23475
  if (j == 0) {
23380
- var newHeight = sizeTransformer(cell.height * ratioY);
23476
+ var newHeight = (cell.height * ratioY) / zoomScale;
23381
23477
  if (newHeight >= MIN_CELL_HEIGHT) {
23382
23478
  cell.td.style.height = newHeight + "px";
23383
23479
  }
@@ -23408,6 +23504,59 @@ function setResizeDivPosition(context, trigger) {
23408
23504
  }
23409
23505
 
23410
23506
 
23507
+ /***/ }),
23508
+
23509
+ /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableSelector.ts":
23510
+ /*!********************************************************************************************!*\
23511
+ !*** ./packages/roosterjs-editor-plugins/lib/plugins/TableResize/editors/TableSelector.ts ***!
23512
+ \********************************************************************************************/
23513
+ /*! no static exports found */
23514
+ /***/ (function(module, exports, __webpack_require__) {
23515
+
23516
+ "use strict";
23517
+
23518
+ Object.defineProperty(exports, "__esModule", { value: true });
23519
+ var DragAndDropHelper_1 = __webpack_require__(/*! ../../../pluginUtils/DragAndDropHelper */ "./packages/roosterjs-editor-plugins/lib/pluginUtils/DragAndDropHelper.ts");
23520
+ var roosterjs_editor_dom_1 = __webpack_require__(/*! roosterjs-editor-dom */ "./packages/roosterjs-editor-dom/lib/index.ts");
23521
+ var TABLE_SELECTOR_LENGTH = 12;
23522
+ var TABLE_SELECTOR_ID = '_Table_Selector';
23523
+ /**
23524
+ * @internal
23525
+ */
23526
+ function createTableSelector(table, zoomScale, onFinishDragging) {
23527
+ var document = table.ownerDocument;
23528
+ var div = (0, roosterjs_editor_dom_1.createElement)(11 /* TableSelector */, document);
23529
+ div.id = TABLE_SELECTOR_ID;
23530
+ div.style.width = TABLE_SELECTOR_LENGTH + "px";
23531
+ div.style.height = TABLE_SELECTOR_LENGTH + "px";
23532
+ document.body.appendChild(div);
23533
+ var context = {
23534
+ table: table,
23535
+ zoomScale: zoomScale,
23536
+ };
23537
+ setSelectorDivPosition(context, div);
23538
+ var onDragEnd = function (context, event) {
23539
+ if (event.target == div) {
23540
+ onFinishDragging(context.table);
23541
+ }
23542
+ return false;
23543
+ };
23544
+ var featureHandler = new DragAndDropHelper_1.default(div, context, setSelectorDivPosition, {
23545
+ onDragEnd: onDragEnd,
23546
+ }, zoomScale);
23547
+ return { div: div, featureHandler: featureHandler, node: table };
23548
+ }
23549
+ exports.default = createTableSelector;
23550
+ function setSelectorDivPosition(context, trigger) {
23551
+ var table = context.table;
23552
+ var rect = (0, roosterjs_editor_dom_1.normalizeRect)(table.getBoundingClientRect());
23553
+ if (rect) {
23554
+ trigger.style.top = rect.top - TABLE_SELECTOR_LENGTH + "px";
23555
+ trigger.style.left = rect.left - TABLE_SELECTOR_LENGTH - 2 + "px";
23556
+ }
23557
+ }
23558
+
23559
+
23411
23560
  /***/ }),
23412
23561
 
23413
23562
  /***/ "./packages/roosterjs-editor-plugins/lib/plugins/TableResize/index.ts":