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