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