roosterjs 9.61.0 → 9.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rooster.js CHANGED
@@ -11032,6 +11032,33 @@ function findTableCellElement(parsedTable, coordinate) {
11032
11032
  exports.findTableCellElement = findTableCellElement;
11033
11033
 
11034
11034
 
11035
+ /***/ },
11036
+
11037
+ /***/ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts"
11038
+ /*!****************************************************************************************************!*\
11039
+ !*** ./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts ***!
11040
+ \****************************************************************************************************/
11041
+ (__unused_webpack_module, exports) {
11042
+
11043
+ "use strict";
11044
+
11045
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
11046
+ exports.getTextSelectionStyle = exports.RANGE_SELECTION_CSS_KEY = void 0;
11047
+ /**
11048
+ * @internal
11049
+ */
11050
+ exports.RANGE_SELECTION_CSS_KEY = '_RangeSelection';
11051
+ /**
11052
+ * @internal
11053
+ * Get the text selection style for the current color mode, or null to use browser defaults.
11054
+ */
11055
+ function getTextSelectionStyle(state, isDarkMode) {
11056
+ var color = isDarkMode ? state.textSelectionColorDark : state.textSelectionColor;
11057
+ return color ? "background-color: " + color + " !important; color: currentColor !important;" : null;
11058
+ }
11059
+ exports.getTextSelectionStyle = getTextSelectionStyle;
11060
+
11061
+
11035
11062
  /***/ },
11036
11063
 
11037
11064
  /***/ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setDOMSelection.ts"
@@ -11049,6 +11076,7 @@ var ensureUniqueId_1 = __webpack_require__(/*! ../setEditorStyle/ensureUniqueId
11049
11076
  var findLastedCoInMergedCell_1 = __webpack_require__(/*! ./findLastedCoInMergedCell */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/findLastedCoInMergedCell.ts");
11050
11077
  var findTableCellElement_1 = __webpack_require__(/*! ./findTableCellElement */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/findTableCellElement.ts");
11051
11078
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
11079
+ var getTextSelectionStyle_1 = __webpack_require__(/*! ./getTextSelectionStyle */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts");
11052
11080
  var setTableCellsStyle_1 = __webpack_require__(/*! ./setTableCellsStyle */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/setTableCellsStyle.ts");
11053
11081
  var toggleCaret_1 = __webpack_require__(/*! ./toggleCaret */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/toggleCaret.ts");
11054
11082
  var DOM_SELECTION_CSS_KEY = '_DOMSelection';
@@ -11073,6 +11101,7 @@ var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
11073
11101
  core.selection.skipReselectOnFocus = true;
11074
11102
  core.api.setEditorStyle(core, DOM_SELECTION_CSS_KEY, null /*cssRule*/);
11075
11103
  core.api.setEditorStyle(core, HIDE_SELECTION_CSS_KEY, null /*cssRule*/);
11104
+ core.api.setEditorStyle(core, getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, null /*cssRule*/);
11076
11105
  (0, toggleCaret_1.toggleCaret)(core, false /* hide */);
11077
11106
  try {
11078
11107
  switch (selection === null || selection === void 0 ? void 0 : selection.type) {
@@ -11125,6 +11154,14 @@ var setDOMSelection = function (core, selection, skipSelectionChangedEvent) {
11125
11154
  }
11126
11155
  break;
11127
11156
  case 'range':
11157
+ var textSelectionStyle = !selection.range.collapsed
11158
+ ? (0, getTextSelectionStyle_1.getTextSelectionStyle)(core.selection, isDarkMode)
11159
+ : null;
11160
+ if (textSelectionStyle) {
11161
+ core.api.setEditorStyle(core, getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, textSelectionStyle, [
11162
+ SELECTION_SELECTOR,
11163
+ ]);
11164
+ }
11128
11165
  core.domHelper.setSelectionRange(selection.range, selection.isReverted);
11129
11166
  core.selection.selection = core.domHelper.hasFocus() ? null : selection;
11130
11167
  break;
@@ -14521,6 +14558,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
14521
14558
  exports.createSelectionPlugin = exports.DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR = exports.DEFAULT_SELECTION_BORDER_COLOR = void 0;
14522
14559
  var findCoordinate_1 = __webpack_require__(/*! ./findCoordinate */ "./packages/roosterjs-content-model-core/lib/corePlugin/selection/findCoordinate.ts");
14523
14560
  var findTableCellElement_1 = __webpack_require__(/*! ../../coreApi/setDOMSelection/findTableCellElement */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/findTableCellElement.ts");
14561
+ var getTextSelectionStyle_1 = __webpack_require__(/*! ../../coreApi/setDOMSelection/getTextSelectionStyle */ "./packages/roosterjs-content-model-core/lib/coreApi/setDOMSelection/getTextSelectionStyle.ts");
14524
14562
  var isSingleImageInSelection_1 = __webpack_require__(/*! ./isSingleImageInSelection */ "./packages/roosterjs-content-model-core/lib/corePlugin/selection/isSingleImageInSelection.ts");
14525
14563
  var normalizePos_1 = __webpack_require__(/*! ./normalizePos */ "./packages/roosterjs-content-model-core/lib/corePlugin/selection/normalizePos.ts");
14526
14564
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
@@ -14640,6 +14678,7 @@ var SelectionPlugin = /** @class */ (function () {
14640
14678
  this.onSelectionChange = function () {
14641
14679
  var _a, _b;
14642
14680
  if (((_a = _this.editor) === null || _a === void 0 ? void 0 : _a.hasFocus()) && !_this.editor.isInShadowEdit()) {
14681
+ _this.editor.setEditorStyle(getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, null /* cssRule */);
14643
14682
  var newSelection = _this.editor.getDOMSelection();
14644
14683
  var domHelper = _this.editor.getDOMHelper();
14645
14684
  // If an image selection changed to a wider range due to a keyboard event, we should update the selection
@@ -14651,22 +14690,31 @@ var SelectionPlugin = /** @class */ (function () {
14651
14690
  var isReverted = sel
14652
14691
  ? sel.focusNode != range.endContainer || sel.focusOffset != range.endOffset
14653
14692
  : false;
14654
- _this.editor.setDOMSelection({
14693
+ newSelection = {
14655
14694
  type: 'range',
14656
14695
  range: range,
14657
14696
  isReverted: isReverted,
14658
- });
14697
+ };
14698
+ _this.editor.setDOMSelection(newSelection);
14659
14699
  }
14660
14700
  else if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) !== 'image' && image) {
14661
- _this.editor.setDOMSelection({
14701
+ newSelection = {
14662
14702
  type: 'image',
14663
14703
  image: image,
14664
- });
14704
+ };
14705
+ _this.editor.setDOMSelection(newSelection);
14665
14706
  }
14666
14707
  }
14667
- // Safari has problem to handle onBlur event. When blur, we cannot get the original selection from editor.
14668
- // So we always save a selection whenever editor has focus. Then after blur, we can still use this cached selection.
14669
14708
  if ((newSelection === null || newSelection === void 0 ? void 0 : newSelection.type) == 'range') {
14709
+ if (!newSelection.range.collapsed) {
14710
+ var textSelectionStyle = (0, getTextSelectionStyle_1.getTextSelectionStyle)(_this.state, _this.editor.isDarkMode());
14711
+ if (textSelectionStyle) {
14712
+ _this.editor.setEditorStyle(getTextSelectionStyle_1.RANGE_SELECTION_CSS_KEY, textSelectionStyle, [
14713
+ '*::selection',
14714
+ ]);
14715
+ }
14716
+ }
14717
+ // Safari cannot retrieve the original selection on blur, so cache it while focused.
14670
14718
  if (_this.isSafari) {
14671
14719
  _this.state.selection = newSelection;
14672
14720
  }
@@ -14685,12 +14733,20 @@ var SelectionPlugin = /** @class */ (function () {
14685
14733
  ? undefined
14686
14734
  : exports.DEFAULT_TABLE_CELL_SELECTION_BACKGROUND_COLOR,
14687
14735
  };
14736
+ if (options.textSelectionColor) {
14737
+ this.state.textSelectionColor = options.textSelectionColor;
14738
+ }
14688
14739
  }
14689
14740
  SelectionPlugin.prototype.getName = function () {
14690
14741
  return 'Selection';
14691
14742
  };
14692
14743
  SelectionPlugin.prototype.initialize = function (editor) {
14693
14744
  this.editor = editor;
14745
+ if (!this.state.textSelectionColorDark && this.state.textSelectionColor) {
14746
+ this.state.textSelectionColorDark = editor
14747
+ .getColorManager()
14748
+ .getDarkColor(this.state.textSelectionColor, undefined, 'background');
14749
+ }
14694
14750
  if (!this.state.imageSelectionBorderColorDark && this.state.imageSelectionBorderColor) {
14695
14751
  this.state.imageSelectionBorderColorDark = editor
14696
14752
  .getColorManager()
@@ -17488,6 +17544,7 @@ exports.EmptySegmentFormat = {
17488
17544
  letterSpacing: '',
17489
17545
  lineHeight: '',
17490
17546
  strikethrough: false,
17547
+ superOrSubScriptFontSize: '',
17491
17548
  superOrSubScriptSequence: '',
17492
17549
  textColor: '',
17493
17550
  underline: false,
@@ -23117,6 +23174,7 @@ exports.listStyleFormatHandler = {
23117
23174
 
23118
23175
  Object.defineProperty(exports, "__esModule", ({ value: true }));
23119
23176
  exports.boldFormatHandler = void 0;
23177
+ var isBlockElement_1 = __webpack_require__(/*! ../../domToModel/utils/isBlockElement */ "./packages/roosterjs-content-model-dom/lib/domToModel/utils/isBlockElement.ts");
23120
23178
  var shouldSetValue_1 = __webpack_require__(/*! ../utils/shouldSetValue */ "./packages/roosterjs-content-model-dom/lib/formatHandlers/utils/shouldSetValue.ts");
23121
23179
  var moveChildNodes_1 = __webpack_require__(/*! ../../domUtils/moveChildNodes */ "./packages/roosterjs-content-model-dom/lib/domUtils/moveChildNodes.ts");
23122
23180
  /**
@@ -23136,7 +23194,7 @@ exports.boldFormatHandler = {
23136
23194
  var blockFontWeight = context.implicitFormat.fontWeight;
23137
23195
  if ((blockFontWeight && blockFontWeight != format.fontWeight) ||
23138
23196
  (!blockFontWeight && format.fontWeight && format.fontWeight != 'normal')) {
23139
- if (format.fontWeight == 'bold') {
23197
+ if (format.fontWeight == 'bold' && !(0, isBlockElement_1.isBlockElement)(element)) {
23140
23198
  (0, moveChildNodes_1.wrapAllChildNodes)(element, 'b');
23141
23199
  }
23142
23200
  else {
@@ -23530,12 +23588,17 @@ exports.superOrSubScriptFormatHandler = {
23530
23588
  parse: function (format, element, context, defaultStyle) {
23531
23589
  var verticalAlign = element.style.verticalAlign || defaultStyle.verticalAlign;
23532
23590
  var fontSize = element.style.fontSize || defaultStyle.fontSize;
23533
- if (isSuperOrSubScript(fontSize, verticalAlign)) {
23591
+ var inheritFontSize = (element.tagName == 'SUP' || element.tagName == 'SUB') && fontSize == 'inherit';
23592
+ if (isSuperOrSubScript(fontSize, verticalAlign) ||
23593
+ (inheritFontSize && (verticalAlign == 'super' || verticalAlign == 'sub'))) {
23534
23594
  format.superOrSubScriptSequence = (format.superOrSubScriptSequence || '')
23535
23595
  .split(' ')
23536
23596
  .concat(verticalAlign)
23537
23597
  .join(' ')
23538
23598
  .trim();
23599
+ if (inheritFontSize) {
23600
+ format.superOrSubScriptFontSize = 'inherit';
23601
+ }
23539
23602
  }
23540
23603
  },
23541
23604
  apply: function (format, element) {
@@ -23546,7 +23609,10 @@ exports.superOrSubScriptFormatHandler = {
23546
23609
  .forEach(function (value) {
23547
23610
  var tagName = value == 'super' ? 'sup' : value == 'sub' ? 'sub' : null;
23548
23611
  if (tagName) {
23549
- (0, moveChildNodes_1.wrapAllChildNodes)(element, tagName);
23612
+ var wrapper = (0, moveChildNodes_1.wrapAllChildNodes)(element, tagName);
23613
+ if (format.superOrSubScriptFontSize) {
23614
+ wrapper.style.fontSize = format.superOrSubScriptFontSize;
23615
+ }
23550
23616
  }
23551
23617
  });
23552
23618
  }
@@ -25482,9 +25548,9 @@ exports.normalizeSegmentFormat = normalizeSegmentFormat;
25482
25548
  Object.defineProperty(exports, "__esModule", ({ value: true }));
25483
25549
  exports.stripInvisibleUnicode = void 0;
25484
25550
  // According to https://embracethered.com/blog/posts/2024/hiding-and-finding-text-with-unicode-tags/
25485
- // there are some invisible unicode characters in the range of U+E0000 to U+EFFFF, which are used for hiding text in HTML.
25551
+ // there are some invisible unicode characters in the range of U+E0000 to U+E007F, which are used for hiding text in HTML.
25486
25552
  // We need to strip them out before processing the pasted content, otherwise they will be treated as normal text and cause unexpected behavior.
25487
- var INVISIBLE_UNICODE_REGEX = /[\u{E0000}-\u{EFFFF}]/gu;
25553
+ var INVISIBLE_UNICODE_REGEX = /[\u{E0000}-\u{E007F}]/gu;
25488
25554
  /**
25489
25555
  * @internal
25490
25556
  * Strip invisible unicode characters from the given string
@@ -27465,21 +27531,22 @@ var KeysOfSegmentFormat = (0, getObjectKeys_1.getObjectKeys)(EmptySegmentFormat_
27465
27531
  * @returns Insert point after merge, or null if there is no insert point
27466
27532
  */
27467
27533
  function mergeModel(target, source, context, options) {
27468
- var _a, _b;
27534
+ var _a, _b, _c;
27469
27535
  var insertPosition = (_a = options === null || options === void 0 ? void 0 : options.insertPosition) !== null && _a !== void 0 ? _a : (0, deleteSelection_1.deleteSelection)(target, [], context).insertPoint;
27470
- var _c = options || {}, addParagraphAfterMergedContent = _c.addParagraphAfterMergedContent, mergeFormat = _c.mergeFormat, mergeParagraphAfterList = _c.mergeParagraphAfterList, mergeTable = _c.mergeTable;
27536
+ var _d = options || {}, addParagraphAfterMergedContent = _d.addParagraphAfterMergedContent, mergeFormat = _d.mergeFormat, mergeParagraphAfterList = _d.mergeParagraphAfterList, mergeTable = _d.mergeTable;
27471
27537
  if (mergeParagraphAfterList && insertPosition && ((_b = source.blocks[0]) === null || _b === void 0 ? void 0 : _b.blockType) == 'Paragraph') {
27472
27538
  moveParagraphAfterListIntoList(insertPosition);
27473
27539
  }
27474
27540
  if (addParagraphAfterMergedContent && !mergeTable) {
27475
- var _d = insertPosition || {}, paragraph = _d.paragraph, marker = _d.marker;
27541
+ var _e = insertPosition || {}, paragraph = _e.paragraph, marker = _e.marker;
27476
27542
  var newPara = (0, createParagraph_1.createParagraph)(false /* isImplicit */, paragraph === null || paragraph === void 0 ? void 0 : paragraph.format, marker === null || marker === void 0 ? void 0 : marker.format);
27477
27543
  (0, addBlock_1.addBlock)(source, newPara);
27478
27544
  }
27479
27545
  if (insertPosition) {
27480
27546
  if (mergeFormat && mergeFormat != 'none') {
27481
- var newFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (target.format || {})), insertPosition.marker.format);
27482
- applyDefaultFormat(source, newFormat, mergeFormat);
27547
+ var newFormat = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, (target.format || {})), ((options === null || options === void 0 ? void 0 : options.preserveParagraphDecorator)
27548
+ ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, (_c = insertPosition.paragraph.decorator) === null || _c === void 0 ? void 0 : _c.format), insertPosition.paragraph.segmentFormat) : undefined)), insertPosition.marker.format);
27549
+ applyDefaultFormat(source, newFormat, mergeFormat, options === null || options === void 0 ? void 0 : options.preserveParagraphDecorator);
27483
27550
  }
27484
27551
  for (var i = 0; i < source.blocks.length; i++) {
27485
27552
  var block = source.blocks[i];
@@ -27757,7 +27824,7 @@ function insertBlock(markerPosition, block) {
27757
27824
  (0, mutate_1.mutateBlock)(path[0]).blocks.splice(blockIndex, 0, block);
27758
27825
  }
27759
27826
  }
27760
- function applyDefaultFormat(group, format, applyDefaultFormatOption) {
27827
+ function applyDefaultFormat(group, format, applyDefaultFormatOption, preserveParagraphDecorator) {
27761
27828
  group.blocks.forEach(function (block) {
27762
27829
  var _a;
27763
27830
  mergeBlockFormat(applyDefaultFormatOption, block);
@@ -27766,28 +27833,32 @@ function applyDefaultFormat(group, format, applyDefaultFormatOption) {
27766
27833
  if (block.blockGroupType == 'ListItem') {
27767
27834
  (0, mutate_1.mutateBlock)(block).formatHolder.format = mergeSegmentFormat(applyDefaultFormatOption, format, block.formatHolder.format);
27768
27835
  }
27769
- applyDefaultFormat(block, format, applyDefaultFormatOption);
27836
+ applyDefaultFormat(block, format, applyDefaultFormatOption, preserveParagraphDecorator);
27770
27837
  break;
27771
27838
  case 'Table':
27772
27839
  block.rows.forEach(function (row) {
27773
27840
  return row.cells.forEach(function (cell) {
27774
- applyDefaultFormat(cell, format, applyDefaultFormatOption);
27841
+ applyDefaultFormat(cell, format, applyDefaultFormatOption, preserveParagraphDecorator);
27775
27842
  });
27776
27843
  });
27777
27844
  break;
27778
27845
  case 'Paragraph':
27779
27846
  var paragraphFormat_1 = ((_a = block.decorator) === null || _a === void 0 ? void 0 : _a.format) || {};
27780
27847
  var paragraph = (0, mutate_1.mutateBlock)(block);
27848
+ var paragraphTargetFormat_1 = applyDefaultFormatOption === 'keepSourceEmphasisFormat' &&
27849
+ preserveParagraphDecorator
27850
+ ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, format), paragraphFormat_1) : format;
27781
27851
  paragraph.segments.forEach(function (segment) {
27782
27852
  if (segment.segmentType == 'General') {
27783
- applyDefaultFormat(segment, format, applyDefaultFormatOption);
27853
+ applyDefaultFormat(segment, format, applyDefaultFormatOption, preserveParagraphDecorator);
27784
27854
  }
27785
- segment.format = mergeSegmentFormat(applyDefaultFormatOption, format, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, paragraphFormat_1), segment.format));
27855
+ segment.format = mergeSegmentFormat(applyDefaultFormatOption, paragraphTargetFormat_1, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, paragraphFormat_1), segment.format));
27786
27856
  if (segment.link) {
27787
27857
  segment.link.format = mergeLinkFormat(applyDefaultFormatOption, format, segment.link.format);
27788
27858
  }
27789
27859
  });
27790
- if (applyDefaultFormatOption === 'keepSourceEmphasisFormat') {
27860
+ if (applyDefaultFormatOption === 'keepSourceEmphasisFormat' &&
27861
+ !preserveParagraphDecorator) {
27791
27862
  delete paragraph.decorator;
27792
27863
  }
27793
27864
  break;
@@ -27837,7 +27908,7 @@ function mergeSegmentFormat(applyDefaultFormatOption, targetFormat, sourceFormat
27837
27908
  }
27838
27909
  function getSemanticFormat(segmentFormat) {
27839
27910
  var result = {};
27840
- var fontWeight = segmentFormat.fontWeight, italic = segmentFormat.italic, underline = segmentFormat.underline;
27911
+ var fontWeight = segmentFormat.fontWeight, italic = segmentFormat.italic, underline = segmentFormat.underline, strikethrough = segmentFormat.strikethrough;
27841
27912
  if (fontWeight && fontWeight != 'normal') {
27842
27913
  result.fontWeight = fontWeight;
27843
27914
  }
@@ -27847,6 +27918,9 @@ function getSemanticFormat(segmentFormat) {
27847
27918
  if (underline) {
27848
27919
  result.underline = underline;
27849
27920
  }
27921
+ if (strikethrough) {
27922
+ result.strikethrough = strikethrough;
27923
+ }
27850
27924
  return result;
27851
27925
  }
27852
27926
  /**
@@ -31838,11 +31912,27 @@ exports.createTableFromMarkdown = void 0;
31838
31912
  var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
31839
31913
  var createParagraphFromMarkdown_1 = __webpack_require__(/*! ./createParagraphFromMarkdown */ "./packages/roosterjs-content-model-markdown/lib/markdownToModel/creators/createParagraphFromMarkdown.ts");
31840
31914
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
31915
+ var DefaultMarkdownTable = {
31916
+ headerRowColor: null,
31917
+ topBorderColor: '#000',
31918
+ bottomBorderColor: '#000',
31919
+ verticalBorderColor: '#000',
31920
+ tableBorderFormat: roosterjs_content_model_dom_1.TableBorderFormat.Default,
31921
+ headerRowCustomStyles: {
31922
+ fontWeight: 'normal',
31923
+ italic: false,
31924
+ },
31925
+ firstColumnCustomStyles: {
31926
+ fontWeight: 'normal',
31927
+ italic: false,
31928
+ },
31929
+ };
31841
31930
  /**
31842
31931
  * @internal
31843
31932
  */
31844
31933
  function createTableFromMarkdown(tableLines, options) {
31845
31934
  var e_1, _a;
31935
+ var _b;
31846
31936
  var tableDivider = tableLines[1].split('|').filter(function (content) { return content.trim() !== ''; });
31847
31937
  tableLines.splice(1, 1);
31848
31938
  var table = (0, roosterjs_content_model_dom_1.createTable)(0, options.direction
@@ -31861,9 +31951,7 @@ function createTableFromMarkdown(tableLines, options) {
31861
31951
  }
31862
31952
  finally { if (e_1) throw e_1.error; }
31863
31953
  }
31864
- (0, roosterjs_content_model_dom_1.applyTableFormat)(table, {
31865
- hasHeaderRow: true,
31866
- });
31954
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, (_b = options.tableStyles) !== null && _b !== void 0 ? _b : DefaultMarkdownTable);
31867
31955
  return table;
31868
31956
  }
31869
31957
  exports.createTableFromMarkdown = createTableFromMarkdown;
@@ -32843,12 +32931,16 @@ exports.modelProcessor = modelProcessor;
32843
32931
 
32844
32932
  Object.defineProperty(exports, "__esModule", ({ value: true }));
32845
32933
  exports.MarkdownPastePlugin = void 0;
32934
+ var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
32846
32935
  var convertMarkdownToContentModel_1 = __webpack_require__(/*! ../markdownToModel/convertMarkdownToContentModel */ "./packages/roosterjs-content-model-markdown/lib/markdownToModel/convertMarkdownToContentModel.ts");
32847
32936
  var isPastedContentMarkdown_1 = __webpack_require__(/*! ../publicApi/isPastedContentMarkdown */ "./packages/roosterjs-content-model-markdown/lib/publicApi/isPastedContentMarkdown.ts");
32848
32937
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
32849
32938
  var DefaultOptions = {
32850
32939
  autoConversion: false,
32851
32940
  undoConversion: false,
32941
+ markdownToModelOptions: {
32942
+ emptyLine: 'merge',
32943
+ },
32852
32944
  };
32853
32945
  /**
32854
32946
  * Markdown paste plugin. Handles the BeforePaste event and, when the pasted content
@@ -32861,8 +32953,9 @@ var MarkdownPastePlugin = /** @class */ (function () {
32861
32953
  * @param options Options to control the markdown paste behavior
32862
32954
  */
32863
32955
  function MarkdownPastePlugin(options) {
32956
+ var _a, _b;
32864
32957
  this.editor = null;
32865
- this.options = options !== null && options !== void 0 ? options : DefaultOptions;
32958
+ this.options = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultOptions), options), { markdownToModelOptions: (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultOptions.markdownToModelOptions), options === null || options === void 0 ? void 0 : options.markdownToModelOptions), { emptyLine: (_b = (_a = options === null || options === void 0 ? void 0 : options.markdownToModelOptions) === null || _a === void 0 ? void 0 : _a.emptyLine) !== null && _b !== void 0 ? _b : 'merge' }) });
32866
32959
  }
32867
32960
  /**
32868
32961
  * Get name of this plugin
@@ -32907,10 +33000,9 @@ var MarkdownPastePlugin = /** @class */ (function () {
32907
33000
  (0, isPastedContentMarkdown_1.isPastedContentMarkdown)(this.editor, clipboardData) &&
32908
33001
  clipboardData.modelBeforePaste) {
32909
33002
  var modelBeforePaste_1 = (0, roosterjs_content_model_dom_1.cloneModelForPaste)(clipboardData.modelBeforePaste);
32910
- (0, roosterjs_content_model_dom_1.mergeModel)(modelBeforePaste_1, (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(clipboardData.text, {
32911
- emptyLine: 'merge',
32912
- }), undefined /*context*/, {
32913
- mergeFormat: 'preferTarget',
33003
+ (0, roosterjs_content_model_dom_1.mergeModel)(modelBeforePaste_1, (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(clipboardData.text, this.options.markdownToModelOptions), undefined /*context*/, {
33004
+ mergeFormat: 'keepSourceEmphasisFormat',
33005
+ preserveParagraphDecorator: true,
32914
33006
  });
32915
33007
  if (this.options.undoConversion) {
32916
33008
  this.editor.takeSnapshot();
@@ -32928,17 +33020,15 @@ var MarkdownPastePlugin = /** @class */ (function () {
32928
33020
  else if (event.eventType === 'beforePaste' && !event.clipboardData.pasteNativeEvent) {
32929
33021
  var shouldConvert = event.pasteType === 'asMarkdown';
32930
33022
  if (shouldConvert && (0, isPastedContentMarkdown_1.isPastedContentMarkdown)(this.editor, event.clipboardData)) {
32931
- convertPastedTextToMarkdown(this.editor, event.fragment, event.clipboardData.text);
33023
+ convertPastedTextToMarkdown(this.editor, event.fragment, event.clipboardData.text, this.options.markdownToModelOptions);
32932
33024
  }
32933
33025
  }
32934
33026
  };
32935
33027
  return MarkdownPastePlugin;
32936
33028
  }());
32937
33029
  exports.MarkdownPastePlugin = MarkdownPastePlugin;
32938
- function convertPastedTextToMarkdown(editor, fragment, text) {
32939
- var model = (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(text, {
32940
- emptyLine: 'merge',
32941
- });
33030
+ function convertPastedTextToMarkdown(editor, fragment, text, markdownToModelOptions) {
33031
+ var model = (0, convertMarkdownToContentModel_1.convertMarkdownToContentModel)(text, markdownToModelOptions);
32942
33032
  while (fragment.firstChild) {
32943
33033
  fragment.removeChild(fragment.firstChild);
32944
33034
  }
@@ -37591,6 +37681,211 @@ var HyperlinkPlugin = /** @class */ (function () {
37591
37681
  exports.HyperlinkPlugin = HyperlinkPlugin;
37592
37682
 
37593
37683
 
37684
+ /***/ },
37685
+
37686
+ /***/ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/ImageCropKeyboardHelper.ts"
37687
+ /*!***************************************************************************************************!*\
37688
+ !*** ./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/ImageCropKeyboardHelper.ts ***!
37689
+ \***************************************************************************************************/
37690
+ (__unused_webpack_module, exports, __webpack_require__) {
37691
+
37692
+ "use strict";
37693
+
37694
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
37695
+ exports.ImageCropKeyboardHelper = void 0;
37696
+ var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
37697
+ var cropperContext_1 = __webpack_require__(/*! ./cropperContext */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/cropperContext.ts");
37698
+ var ImageEditElementClass_1 = __webpack_require__(/*! ../types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
37699
+ var DefaultTopLeftLabel = 'Top left';
37700
+ var DefaultBottomRightLabel = 'Bottom right';
37701
+ var DefaultMoveCropLabel = 'Move Crop';
37702
+ var FocusTargetAttributes = [
37703
+ 'tabindex',
37704
+ 'contenteditable',
37705
+ 'role',
37706
+ 'aria-label',
37707
+ 'aria-describedby',
37708
+ 'part',
37709
+ ];
37710
+ /**
37711
+ * @internal
37712
+ * Keyboard cropping shares the pointer handler's geometry and constraints.
37713
+ */
37714
+ var ImageCropKeyboardHelper = /** @class */ (function () {
37715
+ function ImageCropKeyboardHelper(wrapper, imageId, editInfo, options, onCrop, onFinish) {
37716
+ var _this = this;
37717
+ this.wrapper = wrapper;
37718
+ this.editInfo = editInfo;
37719
+ this.options = options;
37720
+ this.onCrop = onCrop;
37721
+ this.onFinish = onFinish;
37722
+ this.cropFocusTargets = [];
37723
+ this.disposed = false;
37724
+ this.stopPropagation = function (event) {
37725
+ if (_this.contains(event.target)) {
37726
+ event.stopPropagation();
37727
+ }
37728
+ };
37729
+ this.onFocusOut = function (event) {
37730
+ if (!_this.disposed && _this.contains(event.target) && !_this.contains(event.relatedTarget)) {
37731
+ _this.onFinish(true, false);
37732
+ }
37733
+ };
37734
+ this.onKeyDown = function (event) {
37735
+ if (!_this.contains(event.target)) {
37736
+ return;
37737
+ }
37738
+ event.stopPropagation();
37739
+ if (event.key == 'Tab') {
37740
+ var index = _this.cropFocusTargets.findIndex(function (target) { return target === event.target; });
37741
+ var next = _this.cropFocusTargets[index + (event.shiftKey ? -1 : 1)];
37742
+ if (next) {
37743
+ event.preventDefault();
37744
+ next.focus();
37745
+ }
37746
+ }
37747
+ else if (event.key == 'Enter' || event.key == 'Escape') {
37748
+ event.preventDefault();
37749
+ _this.onFinish(event.key == 'Enter', true);
37750
+ }
37751
+ else if (event.key == 'ArrowLeft' ||
37752
+ event.key == 'ArrowRight' ||
37753
+ event.key == 'ArrowUp' ||
37754
+ event.key == 'ArrowDown') {
37755
+ event.preventDefault();
37756
+ if (!event.ctrlKey && !event.metaKey && !event.altKey) {
37757
+ _this.crop(event);
37758
+ }
37759
+ }
37760
+ else if (event.key == ' ' || event.key == 'Delete' || event.key == 'Backspace') {
37761
+ event.preventDefault();
37762
+ }
37763
+ };
37764
+ var cropLabels = options.cropLabels;
37765
+ if (cropLabels === null || cropLabels === void 0 ? void 0 : cropLabels.instructions) {
37766
+ this.instructions = this.createInstructions(imageId, cropLabels.instructions);
37767
+ wrapper.appendChild(this.instructions);
37768
+ }
37769
+ ['nw', 'se'].forEach(function (direction) {
37770
+ var _a;
37771
+ var handle = wrapper.querySelector("." + ImageEditElementClass_1.ImageEditElementClass.CropHandle + "[data-y=\"" + direction[0] + "\"][data-x=\"" + direction[1] + "\"]");
37772
+ if (handle) {
37773
+ _this.prepareTarget(handle, ((_a = cropLabels === null || cropLabels === void 0 ? void 0 : cropLabels.handleLabel) === null || _a === void 0 ? void 0 : _a.call(cropLabels, direction)) ||
37774
+ (direction == 'nw' ? DefaultTopLeftLabel : DefaultBottomRightLabel));
37775
+ }
37776
+ });
37777
+ this.cropMoveTarget = wrapper.querySelector("." + ImageEditElementClass_1.ImageEditElementClass.ImageBorder);
37778
+ if (this.cropMoveTarget) {
37779
+ wrapper.appendChild(this.cropMoveTarget);
37780
+ this.prepareTarget(this.cropMoveTarget, (cropLabels === null || cropLabels === void 0 ? void 0 : cropLabels.moveCropLabel) || DefaultMoveCropLabel);
37781
+ }
37782
+ // Make native tab entry start at the top-left corner as well.
37783
+ var first = this.cropFocusTargets[0];
37784
+ if (first === null || first === void 0 ? void 0 : first.parentElement) {
37785
+ first.parentElement.insertBefore(first, first.parentElement.firstChild);
37786
+ }
37787
+ wrapper.addEventListener('keydown', this.onKeyDown);
37788
+ wrapper.addEventListener('keyup', this.stopPropagation);
37789
+ wrapper.addEventListener('keypress', this.stopPropagation);
37790
+ wrapper.addEventListener('focusout', this.onFocusOut);
37791
+ }
37792
+ ImageCropKeyboardHelper.prototype.focus = function () {
37793
+ var _a;
37794
+ (_a = this.cropFocusTargets[0]) === null || _a === void 0 ? void 0 : _a.focus();
37795
+ };
37796
+ ImageCropKeyboardHelper.prototype.contains = function (target) {
37797
+ return this.cropFocusTargets.some(function (element) { return element === target; });
37798
+ };
37799
+ ImageCropKeyboardHelper.prototype.dispose = function () {
37800
+ var e_1, _a, e_2, _b;
37801
+ var _c;
37802
+ this.disposed = true;
37803
+ this.wrapper.removeEventListener('keydown', this.onKeyDown);
37804
+ this.wrapper.removeEventListener('keyup', this.stopPropagation);
37805
+ this.wrapper.removeEventListener('keypress', this.stopPropagation);
37806
+ this.wrapper.removeEventListener('focusout', this.onFocusOut);
37807
+ try {
37808
+ for (var _d = (0, tslib_1.__values)(this.cropFocusTargets), _e = _d.next(); !_e.done; _e = _d.next()) {
37809
+ var target = _e.value;
37810
+ try {
37811
+ for (var FocusTargetAttributes_1 = (e_2 = void 0, (0, tslib_1.__values)(FocusTargetAttributes)), FocusTargetAttributes_1_1 = FocusTargetAttributes_1.next(); !FocusTargetAttributes_1_1.done; FocusTargetAttributes_1_1 = FocusTargetAttributes_1.next()) {
37812
+ var attribute = FocusTargetAttributes_1_1.value;
37813
+ target.removeAttribute(attribute);
37814
+ }
37815
+ }
37816
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
37817
+ finally {
37818
+ try {
37819
+ if (FocusTargetAttributes_1_1 && !FocusTargetAttributes_1_1.done && (_b = FocusTargetAttributes_1.return)) _b.call(FocusTargetAttributes_1);
37820
+ }
37821
+ finally { if (e_2) throw e_2.error; }
37822
+ }
37823
+ target.classList.remove(ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget);
37824
+ }
37825
+ }
37826
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
37827
+ finally {
37828
+ try {
37829
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
37830
+ }
37831
+ finally { if (e_1) throw e_1.error; }
37832
+ }
37833
+ (_c = this.instructions) === null || _c === void 0 ? void 0 : _c.remove();
37834
+ };
37835
+ ImageCropKeyboardHelper.prototype.createInstructions = function (imageId, text) {
37836
+ var instructions = this.wrapper.ownerDocument.createElement('span');
37837
+ instructions.id = 'imageCropInstructions' + imageId;
37838
+ instructions.textContent = text;
37839
+ instructions.style.cssText =
37840
+ 'position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;';
37841
+ return instructions;
37842
+ };
37843
+ ImageCropKeyboardHelper.prototype.prepareTarget = function (target, label) {
37844
+ target.tabIndex = 0;
37845
+ target.contentEditable = 'false';
37846
+ target.setAttribute('role', 'application');
37847
+ if (label) {
37848
+ target.setAttribute('aria-label', label);
37849
+ }
37850
+ if (this.instructions) {
37851
+ target.setAttribute('aria-describedby', this.instructions.id);
37852
+ }
37853
+ target.classList.add(ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget);
37854
+ target.setAttribute('part', ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget);
37855
+ this.cropFocusTargets.push(target);
37856
+ };
37857
+ ImageCropKeyboardHelper.prototype.crop = function (event) {
37858
+ var _a, _b;
37859
+ var target = this.cropFocusTargets.find(function (element) { return element === event.target; });
37860
+ var context = {
37861
+ editInfo: this.editInfo,
37862
+ options: this.options,
37863
+ elementClass: target === this.cropMoveTarget
37864
+ ? ImageEditElementClass_1.ImageEditElementClass.CropContainer
37865
+ : ImageEditElementClass_1.ImageEditElementClass.CropHandle,
37866
+ x: (target === null || target === void 0 ? void 0 : target.dataset.x) == 'e' ? 'e' : (target === null || target === void 0 ? void 0 : target.dataset.x) == 'w' ? 'w' : '',
37867
+ y: (target === null || target === void 0 ? void 0 : target.dataset.y) == 'n' ? 'n' : (target === null || target === void 0 ? void 0 : target.dataset.y) == 's' ? 's' : '',
37868
+ };
37869
+ var dragEvent = {
37870
+ clientX: 0,
37871
+ clientY: 0,
37872
+ pageX: 0,
37873
+ pageY: 0,
37874
+ target: event.target,
37875
+ shiftKey: event.shiftKey,
37876
+ altKey: event.altKey,
37877
+ };
37878
+ var base = (_a = cropperContext_1.Cropper.onDragStart) === null || _a === void 0 ? void 0 : _a.call(cropperContext_1.Cropper, context, dragEvent);
37879
+ if (base &&
37880
+ ((_b = cropperContext_1.Cropper.onDragging) === null || _b === void 0 ? void 0 : _b.call(cropperContext_1.Cropper, context, dragEvent, base, event.key == 'ArrowLeft' ? -1 : event.key == 'ArrowRight' ? 1 : 0, event.key == 'ArrowUp' ? -1 : event.key == 'ArrowDown' ? 1 : 0))) {
37881
+ this.onCrop();
37882
+ }
37883
+ };
37884
+ return ImageCropKeyboardHelper;
37885
+ }());
37886
+ exports.ImageCropKeyboardHelper = ImageCropKeyboardHelper;
37887
+
37888
+
37594
37889
  /***/ },
37595
37890
 
37596
37891
  /***/ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/createImageCropper.ts"
@@ -37695,6 +37990,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
37695
37990
  exports.Cropper = void 0;
37696
37991
  var tslib_1 = __webpack_require__(/*! tslib */ "./node_modules/tslib/tslib.es6.mjs");
37697
37992
  var imageEditUtils_1 = __webpack_require__(/*! ../utils/imageEditUtils */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/imageEditUtils.ts");
37993
+ var ImageEditElementClass_1 = __webpack_require__(/*! ../types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
37698
37994
  /**
37699
37995
  * @internal
37700
37996
  * Crop handle for DragAndDropHelper
@@ -37707,7 +38003,7 @@ exports.Cropper = {
37707
38003
  onDragging: function (_a, e, base, dx, dy) {
37708
38004
  var _b;
37709
38005
  var _c;
37710
- var editInfo = _a.editInfo, x = _a.x, y = _a.y, options = _a.options;
38006
+ var editInfo = _a.editInfo, x = _a.x, y = _a.y, options = _a.options, elementClass = _a.elementClass;
37711
38007
  _b = (0, tslib_1.__read)((0, imageEditUtils_1.rotateCoordinate)(dx, dy, (_c = editInfo.angleRad) !== null && _c !== void 0 ? _c : 0), 2), dx = _b[0], dy = _b[1];
37712
38008
  var widthPx = editInfo.widthPx, heightPx = editInfo.heightPx, leftPercent = editInfo.leftPercent, rightPercent = editInfo.rightPercent, topPercent = editInfo.topPercent, bottomPercent = editInfo.bottomPercent;
37713
38009
  if (leftPercent === undefined ||
@@ -37731,6 +38027,15 @@ exports.Cropper = {
37731
38027
  minHeight !== undefined) {
37732
38028
  var fullWidth = widthPx / widthPercent;
37733
38029
  var fullHeight = heightPx / heightPercent;
38030
+ if (elementClass == ImageEditElementClass_1.ImageEditElementClass.CropContainer) {
38031
+ var deltaX = Math.max(-base.leftPercent, Math.min(dx / fullWidth, base.rightPercent));
38032
+ var deltaY = Math.max(-base.topPercent, Math.min(dy / fullHeight, base.bottomPercent));
38033
+ editInfo.leftPercent = base.leftPercent + deltaX;
38034
+ editInfo.rightPercent = base.rightPercent - deltaX;
38035
+ editInfo.topPercent = base.topPercent + deltaY;
38036
+ editInfo.bottomPercent = base.bottomPercent - deltaY;
38037
+ return true;
38038
+ }
37734
38039
  var newLeft = x != 'e'
37735
38040
  ? crop(base.leftPercent, dx, fullWidth, rightPercent, minWidth)
37736
38041
  : leftPercent;
@@ -37789,6 +38094,7 @@ var getHTMLImageOptions_1 = __webpack_require__(/*! ./utils/getHTMLImageOptions
37789
38094
  var getSelectedImage_1 = __webpack_require__(/*! ./utils/getSelectedImage */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/getSelectedImage.ts");
37790
38095
  var updateImageEditInfo_1 = __webpack_require__(/*! ./utils/updateImageEditInfo */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/updateImageEditInfo.ts");
37791
38096
  var ImageEditElementClass_1 = __webpack_require__(/*! ./types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
38097
+ var ImageCropKeyboardHelper_1 = __webpack_require__(/*! ./Cropper/ImageCropKeyboardHelper */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/ImageCropKeyboardHelper.ts");
37792
38098
  var normalizeImageSelection_1 = __webpack_require__(/*! ./utils/normalizeImageSelection */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/utils/normalizeImageSelection.ts");
37793
38099
  var resizerContext_1 = __webpack_require__(/*! ./Resizer/resizerContext */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Resizer/resizerContext.ts");
37794
38100
  var rotatorContext_1 = __webpack_require__(/*! ./Rotator/rotatorContext */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Rotator/rotatorContext.ts");
@@ -37809,6 +38115,7 @@ var MouseRightButton = 2;
37809
38115
  var DRAG_ID = '_dragging';
37810
38116
  var IMAGE_EDIT_CLASS = 'imageEdit';
37811
38117
  var IMAGE_EDIT_CLASS_CARET = 'imageEditCaretColor';
38118
+ var IMAGE_EDIT_CLASS_CROP_KEYBOARD = 'imageEditCropKeyboard';
37812
38119
  var IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';
37813
38120
  /**
37814
38121
  * ImageEdit plugin handles the following image editing features:
@@ -37816,6 +38123,10 @@ var IMAGE_EDIT_FORMAT_EVENT = 'ImageEditEvent';
37816
38123
  * - Crop image
37817
38124
  * - Rotate image
37818
38125
  * - Flip image
38126
+ *
38127
+ * In crop mode, Tab focuses the top-left corner, bottom-right corner, then the
38128
+ * whole image. Arrow keys crop at corners or move the fixed-size crop viewport
38129
+ * by one pixel. Enter applies the crop; Escape cancels it.
37819
38130
  */
37820
38131
  var ImageEditPlugin = /** @class */ (function () {
37821
38132
  function ImageEditPlugin(options) {
@@ -37835,6 +38146,7 @@ var ImageEditPlugin = /** @class */ (function () {
37835
38146
  this.croppers = [];
37836
38147
  this.zoomScale = 1;
37837
38148
  this.disposer = null;
38149
+ this.cropKeyboardHelper = null;
37838
38150
  this.isEditing = false;
37839
38151
  this.options = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, DefaultOptions), options);
37840
38152
  }
@@ -37854,8 +38166,19 @@ var ImageEditPlugin = /** @class */ (function () {
37854
38166
  var _this = this;
37855
38167
  this.editor = editor;
37856
38168
  this.disposer = editor.attachDomEvent({
38169
+ keydown: {
38170
+ capture: true,
38171
+ beforeDispatch: function (ev) {
38172
+ _this.focusCropHandle(ev);
38173
+ },
38174
+ },
37857
38175
  blur: {
37858
- beforeDispatch: function () {
38176
+ beforeDispatch: function (ev) {
38177
+ if (_this.cropKeyboardHelper &&
38178
+ (ev.relatedTarget === _this.shadowSpan ||
38179
+ _this.cropKeyboardHelper.contains(ev.relatedTarget))) {
38180
+ return;
38181
+ }
37859
38182
  if (_this.isEditing && _this.editor && !_this.editor.isDisposed()) {
37860
38183
  _this.applyFormatWithContentModel(_this.editor, _this.isCropMode, true /* shouldSelectImage */);
37861
38184
  }
@@ -37990,6 +38313,11 @@ var ImageEditPlugin = /** @class */ (function () {
37990
38313
  };
37991
38314
  ImageEditPlugin.prototype.keyDownHandler = function (editor, event) {
37992
38315
  if (this.isEditing) {
38316
+ if (this.cropKeyboardHelper &&
38317
+ (this.cropKeyboardHelper.contains(event.rawEvent.composedPath()[0]) ||
38318
+ this.focusCropHandle(event.rawEvent))) {
38319
+ return;
38320
+ }
37993
38321
  if (event.rawEvent.key === 'Escape' ||
37994
38322
  event.rawEvent.key === 'Delete' ||
37995
38323
  event.rawEvent.key === 'Backspace') {
@@ -38006,6 +38334,19 @@ var ImageEditPlugin = /** @class */ (function () {
38006
38334
  }
38007
38335
  }
38008
38336
  };
38337
+ ImageEditPlugin.prototype.focusCropHandle = function (event) {
38338
+ if (this.cropKeyboardHelper &&
38339
+ event.key == 'Tab' &&
38340
+ !event.shiftKey &&
38341
+ !this.cropKeyboardHelper.contains(event.composedPath()[0])) {
38342
+ // Enter crop controls before editing plugins can indent or rerender the image.
38343
+ event.preventDefault();
38344
+ event.stopPropagation();
38345
+ this.cropKeyboardHelper.focus();
38346
+ return true;
38347
+ }
38348
+ return false;
38349
+ };
38009
38350
  ImageEditPlugin.prototype.setContentHandler = function () {
38010
38351
  if (this.selectedImage) {
38011
38352
  this.cleanInfo();
@@ -38246,7 +38587,7 @@ var ImageEditPlugin = /** @class */ (function () {
38246
38587
  if (this.imageEditInfo) {
38247
38588
  this.startEditing(editor, image, ['crop']);
38248
38589
  if (this.imageEditInfo && this.selectedImage && this.wrapper && this.clonedImage) {
38249
- this.dndHelpers = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.CropHandle, cropperContext_1.Cropper, function () {
38590
+ var onCrop = function () {
38250
38591
  if (_this.imageEditInfo &&
38251
38592
  _this.selectedImage &&
38252
38593
  _this.wrapper &&
@@ -38254,9 +38595,44 @@ var ImageEditPlugin = /** @class */ (function () {
38254
38595
  (0, updateWrapper_1.updateWrapper)(_this.imageEditInfo, _this.options, _this.selectedImage, _this.clonedImage, _this.wrapper, undefined /* resizers */, _this.croppers, isRTL);
38255
38596
  _this.isCropMode = true;
38256
38597
  }
38257
- }, this.zoomScale, !!editor.getEnvironment().isMobileOrTablet, !!editor.getEnvironment().isTouchSupported)), false);
38598
+ };
38599
+ this.dndHelpers = (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)((0, getDropAndDragHelpers_1.getDropAndDragHelpers)(this.wrapper, this.imageEditInfo, this.options, ImageEditElementClass_1.ImageEditElementClass.CropHandle, cropperContext_1.Cropper, onCrop, this.zoomScale, !!editor.getEnvironment().isMobileOrTablet, !!editor.getEnvironment().isTouchSupported)), false);
38258
38600
  (0, updateWrapper_1.updateWrapper)(this.imageEditInfo, this.options, this.selectedImage, this.clonedImage, this.wrapper, undefined /* resizers */, this.croppers, isRTL);
38601
+ this.startCropWithKeyboard(editor, onCrop);
38602
+ }
38603
+ }
38604
+ };
38605
+ ImageEditPlugin.prototype.startCropWithKeyboard = function (editor, onCrop) {
38606
+ var _this = this;
38607
+ var _a;
38608
+ if (this.wrapper && this.selectedImage && this.imageEditInfo) {
38609
+ (_a = this.cropKeyboardHelper) === null || _a === void 0 ? void 0 : _a.dispose();
38610
+ this.cropKeyboardHelper = new ImageCropKeyboardHelper_1.ImageCropKeyboardHelper(this.wrapper, this.selectedImage.id, this.imageEditInfo, this.options, onCrop, function (apply, restoreFocus) { return _this.finishKeyboardCrop(editor, apply, restoreFocus); });
38611
+ editor.setEditorStyle(IMAGE_EDIT_CLASS_CROP_KEYBOARD, 'outline:2px solid Highlight;outline-offset:-2px;', ["span::part(" + ImageEditElementClass_1.ImageEditElementClass.CropKeyboardTarget + "):focus"]);
38612
+ }
38613
+ };
38614
+ ImageEditPlugin.prototype.finishKeyboardCrop = function (editor, apply, restoreFocus) {
38615
+ var _a;
38616
+ (_a = this.cropKeyboardHelper) === null || _a === void 0 ? void 0 : _a.dispose();
38617
+ this.cropKeyboardHelper = null;
38618
+ editor.setEditorStyle(IMAGE_EDIT_CLASS_CROP_KEYBOARD, null);
38619
+ if (apply) {
38620
+ this.applyFormatWithContentModel(editor, true, true);
38621
+ }
38622
+ else {
38623
+ this.isEditing = false;
38624
+ var image = this.removeImageWrapper();
38625
+ if (image) {
38626
+ (0, roosterjs_content_model_dom_1.setImageState)(image, '');
38259
38627
  }
38628
+ this.cleanInfo();
38629
+ if (restoreFocus && image) {
38630
+ editor.focus();
38631
+ editor.setDOMSelection({ type: 'image', image: image });
38632
+ }
38633
+ }
38634
+ if (restoreFocus) {
38635
+ editor.focus();
38260
38636
  }
38261
38637
  };
38262
38638
  ImageEditPlugin.prototype.cropImage = function () {
@@ -38284,9 +38660,12 @@ var ImageEditPlugin = /** @class */ (function () {
38284
38660
  * Exported for testing purpose only
38285
38661
  */
38286
38662
  ImageEditPlugin.prototype.cleanInfo = function () {
38287
- var _a, _b;
38288
- (_a = this.editor) === null || _a === void 0 ? void 0 : _a.setEditorStyle(IMAGE_EDIT_CLASS, null);
38289
- (_b = this.editor) === null || _b === void 0 ? void 0 : _b.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
38663
+ var _a, _b, _c, _d;
38664
+ (_a = this.cropKeyboardHelper) === null || _a === void 0 ? void 0 : _a.dispose();
38665
+ this.cropKeyboardHelper = null;
38666
+ (_b = this.editor) === null || _b === void 0 ? void 0 : _b.setEditorStyle(IMAGE_EDIT_CLASS, null);
38667
+ (_c = this.editor) === null || _c === void 0 ? void 0 : _c.setEditorStyle(IMAGE_EDIT_CLASS_CARET, null);
38668
+ (_d = this.editor) === null || _d === void 0 ? void 0 : _d.setEditorStyle(IMAGE_EDIT_CLASS_CROP_KEYBOARD, null);
38290
38669
  this.selectedImage = null;
38291
38670
  this.shadowSpan = null;
38292
38671
  this.wrapper = null;
@@ -38873,6 +39252,14 @@ exports.ImageEditElementClass = void 0;
38873
39252
  */
38874
39253
  var ImageEditElementClass;
38875
39254
  (function (ImageEditElementClass) {
39255
+ /**
39256
+ * CSS class name for the image border
39257
+ */
39258
+ ImageEditElementClass["ImageBorder"] = "r_imageB";
39259
+ /**
39260
+ * CSS class and part name for keyboard crop focus targets
39261
+ */
39262
+ ImageEditElementClass["CropKeyboardTarget"] = "r_cropK";
38876
39263
  /**
38877
39264
  * CSS class name for resize handle
38878
39265
  */
@@ -39112,6 +39499,7 @@ exports.createImageWrapper = void 0;
39112
39499
  var createImageCropper_1 = __webpack_require__(/*! ../Cropper/createImageCropper */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Cropper/createImageCropper.ts");
39113
39500
  var createImageResizer_1 = __webpack_require__(/*! ../Resizer/createImageResizer */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Resizer/createImageResizer.ts");
39114
39501
  var createImageRotator_1 = __webpack_require__(/*! ../Rotator/createImageRotator */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/Rotator/createImageRotator.ts");
39502
+ var ImageEditElementClass_1 = __webpack_require__(/*! ../types/ImageEditElementClass */ "./packages/roosterjs-content-model-plugins/lib/imageEdit/types/ImageEditElementClass.ts");
39115
39503
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
39116
39504
  /**
39117
39505
  * @internal
@@ -39188,6 +39576,7 @@ var createWrapper = function (editor, image, options, editInfo, resizers, rotato
39188
39576
  var createBorder = function (editor, borderColor) {
39189
39577
  var doc = editor.getDocument();
39190
39578
  var resizeBorder = doc.createElement('div');
39579
+ resizeBorder.className = ImageEditElementClass_1.ImageEditElementClass.ImageBorder;
39191
39580
  resizeBorder.setAttribute("style", "position:absolute;left:0;right:0;top:0;bottom:0;border:solid 2px " + borderColor + ";pointer-events:none;");
39192
39581
  return resizeBorder;
39193
39582
  };
@@ -40885,12 +41274,16 @@ var wacSubSuperParser = function (format, element) {
40885
41274
  if (verticalAlign === 'sub') {
40886
41275
  format.superOrSubScriptSequence = 'sub';
40887
41276
  }
41277
+ if ((verticalAlign === 'super' || verticalAlign === 'sub') &&
41278
+ element.style.fontSize !== 'smaller') {
41279
+ format.superOrSubScriptFontSize = 'inherit';
41280
+ }
40888
41281
  };
40889
41282
  /**
40890
41283
  * This processor does:
40891
41284
  * 1) Remove the display and margin of the element.
40892
41285
  * 2) When an element should be ignored but should handle the child elements call the default child processor.
40893
- * 3) Removes the End of Paragraph element to avoid empty lines, we should only remove this if the previous element of the EOP is an EmptyTextRun
41286
+ * 3) Removes selected End of Paragraph markers unless they are the paragraph's only content.
40894
41287
  * 4) Finally call the default processor.
40895
41288
  * @returns
40896
41289
  */
@@ -40904,12 +41297,19 @@ var wacElementProcessor = function (group, element, context) {
40904
41297
  context.elementProcessors.child(group, element, context);
40905
41298
  return;
40906
41299
  }
40907
- if (constants_1.TEMP_ELEMENTS_CLASSES.some(function (className) { return element.classList.contains(className); }) ||
40908
- // This is needed to remove some temporary End of paragraph elements that WAC sometimes preserves
40909
- (element.classList.contains(SELECTED_CLASS) && element.classList.contains(END_OF_PARAGRAPH))) {
41300
+ if (constants_1.TEMP_ELEMENTS_CLASSES.some(function (className) { return element.classList.contains(className); })) {
40910
41301
  return;
40911
41302
  }
40912
- else if (shouldClearListContext(elementTag, element, context)) {
41303
+ if (element.classList.contains(SELECTED_CLASS) &&
41304
+ element.classList.contains(END_OF_PARAGRAPH)) {
41305
+ var lastBlock = group.blocks[group.blocks.length - 1];
41306
+ if ((lastBlock === null || lastBlock === void 0 ? void 0 : lastBlock.blockType) != 'Paragraph' || lastBlock.segments.length > 0) {
41307
+ return;
41308
+ }
41309
+ element.style.removeProperty('background-color');
41310
+ element.style.removeProperty('border-color');
41311
+ }
41312
+ if (shouldClearListContext(elementTag, element, context)) {
40913
41313
  var listFormat = context.listFormat;
40914
41314
  listFormat.levels = [];
40915
41315
  listFormat.listParent = undefined;
@@ -40947,6 +41347,7 @@ var wacLiElementProcessor = function (group, element, context) {
40947
41347
  if (lastblock.blockType == 'BlockGroup' && lastblock.blockGroupType == 'ListItem') {
40948
41348
  var currentLevel = lastblock.levels[lastblock.levels.length - 1];
40949
41349
  updateStartOverride(currentLevel, element, context);
41350
+ updateHeading(lastblock, element, context);
40950
41351
  }
40951
41352
  }
40952
41353
  var newLevels = [];
@@ -40978,6 +41379,19 @@ var wacListLevelParser = function (format) {
40978
41379
  format.marginLeft = undefined;
40979
41380
  format.paddingLeft = BASE_PADDING_WAC_LISTS;
40980
41381
  };
41382
+ var wacTableCellPaddingParser = function (format, element) {
41383
+ var keys = [
41384
+ 'paddingTop',
41385
+ 'paddingRight',
41386
+ 'paddingBottom',
41387
+ 'paddingLeft',
41388
+ ];
41389
+ keys.forEach(function (key) {
41390
+ if (element.style[key]) {
41391
+ format[key] = element.style[key];
41392
+ }
41393
+ });
41394
+ };
40981
41395
  /**
40982
41396
  * This function returns whether we need to clear the list format.
40983
41397
  * Word Online wraps lists inside divs to have this structure:
@@ -41021,6 +41435,7 @@ function processPastedContentWacComponents(ev) {
41021
41435
  (0, addParser_1.addParser)(ev.domToModelOption, 'listLevel', wacListLevelParser);
41022
41436
  (0, addParser_1.addParser)(ev.domToModelOption, 'container', wacContainerParser);
41023
41437
  (0, addParser_1.addParser)(ev.domToModelOption, 'table', wacContainerParser);
41438
+ (0, addParser_1.addParser)(ev.domToModelOption, 'tableCell', wacTableCellPaddingParser);
41024
41439
  (0, addParser_1.addParser)(ev.domToModelOption, 'segment', wacCommentParser);
41025
41440
  (0, setProcessor_1.setProcessor)(ev.domToModelOption, 'element', wacElementProcessor);
41026
41441
  (0, setProcessor_1.setProcessor)(ev.domToModelOption, 'li', wacLiElementProcessor);
@@ -41031,6 +41446,58 @@ var wacContainerParser = function (format, element) {
41031
41446
  delete format.marginLeft;
41032
41447
  }
41033
41448
  };
41449
+ function updateHeading(listItem, element, context) {
41450
+ var _a;
41451
+ var paragraph = element.querySelector('p');
41452
+ var styleName = (_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.querySelector('[data-ccp-parastyle]')) === null || _a === void 0 ? void 0 : _a.getAttribute('data-ccp-parastyle');
41453
+ var list = element.closest('ol');
41454
+ if (!paragraph || !list || !/^heading [1-6]$/i.test(styleName || '')) {
41455
+ return;
41456
+ }
41457
+ var headingParagraph = listItem.blocks.find(function (block) { var _a; return block.blockType == 'Paragraph' && ((_a = block.decorator) === null || _a === void 0 ? void 0 : _a.tagName) == 'p'; });
41458
+ if ((headingParagraph === null || headingParagraph === void 0 ? void 0 : headingParagraph.blockType) == 'Paragraph') {
41459
+ // An inside marker and a block paragraph would occupy separate lines.
41460
+ Object.assign(listItem.format, headingParagraph.format);
41461
+ headingParagraph.isImplicit = true;
41462
+ headingParagraph.format = {};
41463
+ delete headingParagraph.decorator;
41464
+ }
41465
+ listItem.levels.forEach(function (level) {
41466
+ level.format.paddingLeft = '0px';
41467
+ level.format.paddingRight = '0px';
41468
+ level.format.marginTop = '0px';
41469
+ level.format.marginBottom = '0px';
41470
+ });
41471
+ listItem.format.marginLeft = '0px';
41472
+ listItem.format.marginRight = '0px';
41473
+ listItem.format.listStylePosition = 'inside';
41474
+ (0, roosterjs_content_model_dom_1.parseFormat)(paragraph, context.formatParsers.segmentOnBlock, listItem.formatHolder.format, context);
41475
+ var listId = element.getAttribute('data-listid');
41476
+ var template = element.getAttribute('data-leveltext');
41477
+ var _b = (0, tslib_1.__read)(extractWordListMetadata(list, element), 2), start = _b[0], level = _b[1];
41478
+ if (!listId ||
41479
+ !template ||
41480
+ !/^%[1-9](?:\.%[1-9])*[.)]?$/.test(template) ||
41481
+ !(level > 0 && level <= 9) ||
41482
+ !Number.isFinite(start)) {
41483
+ return;
41484
+ }
41485
+ var listFormat = context.listFormat;
41486
+ var headings = (listFormat.headingNumbers = listFormat.headingNumbers || new Map());
41487
+ var numbers = headings.get(listId) || [];
41488
+ numbers[level - 1] = start;
41489
+ numbers.length = level;
41490
+ headings.set(listId, numbers);
41491
+ var complete = true;
41492
+ var label = template.replace(/%([1-9])/g, function (_match, index) {
41493
+ var number = numbers[parseInt(index) - 1];
41494
+ complete = complete && number !== undefined;
41495
+ return number === undefined ? '' : number.toString();
41496
+ });
41497
+ if (complete) {
41498
+ listItem.format.listStyleType = '"' + label + ' "';
41499
+ }
41500
+ }
41034
41501
  function updateStartOverride(currentLevel, element, ctx) {
41035
41502
  if (!currentLevel || currentLevel.listType == 'UL') {
41036
41503
  return;
@@ -41321,6 +41788,7 @@ function processWordList(styles, group, element, context, metadata) {
41321
41788
  }
41322
41789
  if (wordListStyle && group && typeof listFormat.wordLevel === 'number') {
41323
41790
  var wordLevel_1 = listFormat.wordLevel, wordList = listFormat.wordList;
41791
+ var isHeading_1 = /^H[1-6]$/.test(element.tagName);
41324
41792
  // Retrieve the Fake bullet on the element and also the list type
41325
41793
  var listMetadata_1 = metadata.get(lNumber + ":" + level);
41326
41794
  var listType_1 = ((_a = listMetadata_1 === null || listMetadata_1 === void 0 ? void 0 : listMetadata_1['mso-level-number-format']) === null || _a === void 0 ? void 0 : _a.toLowerCase()) != BULLET_METADATA
@@ -41333,26 +41801,52 @@ function processWordList(styles, group, element, context, metadata) {
41333
41801
  var currentLevelFormat = listFormat.levels[listFormat.levels.length - 1]
41334
41802
  .format;
41335
41803
  currentLevelFormat.wordList = wordList;
41336
- if (wordLevel_1 > 1) {
41804
+ if (isHeading_1) {
41805
+ // Keep Word's heading spacing on the item, not on synthesized list wrappers.
41806
+ currentLevelFormat.paddingLeft = '0px';
41807
+ currentLevelFormat.paddingRight = '0px';
41808
+ currentLevelFormat.marginTop = '0px';
41809
+ currentLevelFormat.marginBottom = '0px';
41810
+ }
41811
+ else if (wordLevel_1 > 1) {
41337
41812
  delete currentLevelFormat.paddingLeft;
41338
41813
  delete currentLevelFormat.paddingRight;
41339
41814
  }
41340
- var bullet = getBulletFromMetadata(listMetadata_1, listType_1);
41341
- var listFormatMetadata = bullet
41815
+ var bullet_1 = getBulletFromMetadata(listMetadata_1, listType_1);
41816
+ var bulletElement_1 = getBulletElement(element);
41817
+ var listFormatMetadata = bullet_1
41342
41818
  ? {
41343
- unorderedStyleType: listType_1 == 'UL' ? bullet : undefined,
41344
- orderedStyleType: listType_1 == 'OL' ? bullet : undefined,
41819
+ unorderedStyleType: listType_1 == 'UL' ? bullet_1 : undefined,
41820
+ orderedStyleType: listType_1 == 'OL' ? bullet_1 : undefined,
41345
41821
  }
41346
41822
  : undefined;
41347
- (0, customListUtils_1.processAsListItem)(context, element, group, listFormatMetadata, getBulletElement(element), function (listItem) {
41348
- if (wordLevel_1 > 1) {
41349
- delete listItem.format.marginLeft;
41350
- delete listItem.format.marginRight;
41351
- }
41352
- if (listType_1 == 'OL') {
41353
- setStartNumber(listItem, context, listMetadata_1, element);
41354
- }
41355
- });
41823
+ var originalSegmentFormat = context.segmentFormat;
41824
+ try {
41825
+ context.segmentFormat = (0, tslib_1.__assign)({}, originalSegmentFormat);
41826
+ (0, customListUtils_1.processAsListItem)(context, element, group, listFormatMetadata, bulletElement_1, function (listItem) {
41827
+ var _a;
41828
+ if (isHeading_1 && listType_1 == 'OL') {
41829
+ listItem.format.marginLeft = '0px';
41830
+ listItem.format.marginRight = '0px';
41831
+ listItem.format.listStylePosition = 'inside';
41832
+ // Preserve Word's rendered number when its outline template is unsupported.
41833
+ var number = (_a = bulletElement_1 === null || bulletElement_1 === void 0 ? void 0 : bulletElement_1.textContent) === null || _a === void 0 ? void 0 : _a.trim();
41834
+ if (bullet_1 === undefined && number && /^\d+(?:\.\d+)*[.)]?$/.test(number)) {
41835
+ listItem.format.listStyleType = '"' + number + ' "';
41836
+ }
41837
+ }
41838
+ else if (wordLevel_1 > 1 && !isHeading_1) {
41839
+ delete listItem.format.marginLeft;
41840
+ delete listItem.format.marginRight;
41841
+ }
41842
+ if (listType_1 == 'OL') {
41843
+ setStartNumber(listItem, context, listMetadata_1, element);
41844
+ }
41845
+ });
41846
+ }
41847
+ finally {
41848
+ context.segmentFormat = originalSegmentFormat;
41849
+ }
41356
41850
  if (listFormat.levels.length > 0 &&
41357
41851
  listFormat.wordKnownLevels.get(wordList) != listFormat.levels) {
41358
41852
  listFormat.wordKnownLevels.set(wordList, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(listFormat.levels), false));
@@ -41473,8 +41967,13 @@ function wordListPaddingParser(format, element) {
41473
41967
  * @returns
41474
41968
  */
41475
41969
  function getBulletElement(element) {
41970
+ var _a;
41476
41971
  var firstChild = element.firstElementChild;
41477
41972
  var isBulletElement = false;
41973
+ if ((0, roosterjs_content_model_dom_1.isNodeOfType)(firstChild, 'ELEMENT_NODE') &&
41974
+ ((_a = (0, getStyles_1.getStyles)(firstChild)[MSO_LIST]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === MSO_LIST_IGNORE) {
41975
+ return firstChild;
41976
+ }
41478
41977
  if (firstChild) {
41479
41978
  for (var i = 0; i < firstChild.childNodes.length; i++) {
41480
41979
  var child = firstChild.childNodes[i];