roosterjs 9.51.0 → 9.52.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.
@@ -1,4 +1,4 @@
1
- // Type definitions for roosterjs (Version 9.51.0)
1
+ // Type definitions for roosterjs (Version 9.52.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -6322,6 +6322,18 @@ export interface BeforePasteEvent extends BasePluginEvent<'beforePaste'> {
6322
6322
  * Whether the current clipboard contains at least a block element.
6323
6323
  */
6324
6324
  readonly containsBlockElements?: boolean;
6325
+ /**
6326
+ * Global CSS rules extracted from the pasted document's style sheets
6327
+ */
6328
+ readonly globalCssRules?: CssRule[];
6329
+ }
6330
+
6331
+ /**
6332
+ * Represents a single CSS rule parsed from a pasted document's style sheets
6333
+ */
6334
+ export interface CssRule {
6335
+ selectors: string[];
6336
+ text: string;
6325
6337
  }
6326
6338
 
6327
6339
  /**
@@ -9542,7 +9554,6 @@ export type EditOptions = {
9542
9554
  */
9543
9555
  handleExpandedSelectionOnDelete?: boolean;
9544
9556
  /**
9545
- * @deprecated This is always treated as true now
9546
9557
  * Callback function to determine whether the Rooster should handle the Enter key press.
9547
9558
  * If the function returns true, the Rooster will handle the Enter key press instead of the browser.
9548
9559
  * @param editor - The editor instance.
@@ -9318,6 +9318,7 @@ function generatePasteOptionFromPlugins(editor, clipboardData, fragment, htmlFro
9318
9318
  pasteType: pasteType,
9319
9319
  domToModelOption: domToModelOption,
9320
9320
  containsBlockElements: !!htmlFromClipboard.containsBlockElements,
9321
+ globalCssRules: htmlFromClipboard.globalCssRules,
9321
9322
  };
9322
9323
  return editor.triggerEvent('beforePaste', event, true /* broadcast */);
9323
9324
  }
@@ -33632,7 +33633,11 @@ var EditPlugin = /** @class */ (function () {
33632
33633
  if (!hasCtrlOrMetaKey &&
33633
33634
  !event.rawEvent.isComposing &&
33634
33635
  event.rawEvent.keyCode !== DEAD_KEY) {
33635
- (0, keyboardEnter_1.keyboardEnter)(editor, rawEvent, this.options.formatsToPreserveOnMerge);
33636
+ var shouldHandleEnterKey = this.options.shouldHandleEnterKey;
33637
+ var handleNormalEnter = typeof shouldHandleEnterKey === 'function'
33638
+ ? shouldHandleEnterKey(editor)
33639
+ : shouldHandleEnterKey !== false;
33640
+ (0, keyboardEnter_1.keyboardEnter)(editor, rawEvent, handleNormalEnter, this.options.formatsToPreserveOnMerge);
33636
33641
  }
33637
33642
  break;
33638
33643
  default:
@@ -34627,11 +34632,11 @@ var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-mo
34627
34632
  /**
34628
34633
  * @internal
34629
34634
  */
34630
- function keyboardEnter(editor, rawEvent, formatsToPreserveOnMerge) {
34635
+ function keyboardEnter(editor, rawEvent, handleNormalEnter, formatsToPreserveOnMerge) {
34631
34636
  if (formatsToPreserveOnMerge === void 0) { formatsToPreserveOnMerge = []; }
34632
34637
  var selection = editor.getDOMSelection();
34633
34638
  editor.formatContentModel(function (model, context) {
34634
- var _a;
34639
+ var _a, _b;
34635
34640
  // 1. delete the expanded selection if any, then merge paragraph
34636
34641
  var result = (0, roosterjs_content_model_dom_1.deleteSelection)(model, [], context);
34637
34642
  // 2. Add line break
@@ -34642,12 +34647,14 @@ function keyboardEnter(editor, rawEvent, formatsToPreserveOnMerge) {
34642
34647
  var steps = rawEvent.shiftKey
34643
34648
  ? []
34644
34649
  : [handleAutoLink_1.handleAutoLink, handleEnterOnList_1.handleEnterOnList, deleteEmptyQuote_1.deleteEmptyQuote];
34645
- steps.push((0, handleEnterOnParagraph_1.handleEnterOnParagraph)(formatsToPreserveOnMerge));
34650
+ if (handleNormalEnter || handleEnterForEntity((_a = result.insertPoint) === null || _a === void 0 ? void 0 : _a.paragraph)) {
34651
+ steps.push((0, handleEnterOnParagraph_1.handleEnterOnParagraph)(formatsToPreserveOnMerge));
34652
+ }
34646
34653
  (0, roosterjs_content_model_dom_1.runEditSteps)(steps, result);
34647
34654
  }
34648
34655
  if (result.deleteResult == 'range') {
34649
34656
  // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here
34650
- context.newPendingFormat = (_a = result.insertPoint) === null || _a === void 0 ? void 0 : _a.marker.format;
34657
+ context.newPendingFormat = (_b = result.insertPoint) === null || _b === void 0 ? void 0 : _b.marker.format;
34651
34658
  (0, roosterjs_content_model_dom_1.normalizeContentModel)(model);
34652
34659
  rawEvent.preventDefault();
34653
34660
  return true;
@@ -34664,6 +34671,10 @@ function keyboardEnter(editor, rawEvent, formatsToPreserveOnMerge) {
34664
34671
  });
34665
34672
  }
34666
34673
  exports.keyboardEnter = keyboardEnter;
34674
+ function handleEnterForEntity(paragraph) {
34675
+ return (paragraph &&
34676
+ (paragraph.isImplicit || paragraph.segments.some(function (x) { return x.segmentType == 'Entity'; })));
34677
+ }
34667
34678
 
34668
34679
 
34669
34680
  /***/ },
@@ -39044,7 +39055,7 @@ var PastePlugin = /** @class */ (function () {
39044
39055
  var pasteType = event.pasteType;
39045
39056
  switch (pasteSource) {
39046
39057
  case 'wordDesktop':
39047
- (0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(event.domToModelOption, event.htmlBefore || event.clipboardData.rawHtml || '');
39058
+ (0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(event.domToModelOption, event.htmlBefore || event.clipboardData.rawHtml || '', event.globalCssRules);
39048
39059
  break;
39049
39060
  case 'wacComponents':
39050
39061
  (0, processPastedContentWacComponents_1.processPastedContentWacComponents)(event);
@@ -39681,13 +39692,17 @@ var removeNegativeTextIndentParser_1 = __webpack_require__(/*! ../parsers/remove
39681
39692
  var setProcessor_1 = __webpack_require__(/*! ../utils/setProcessor */ "./packages/roosterjs-content-model-plugins/lib/paste/utils/setProcessor.ts");
39682
39693
  var wordContainerParser_1 = __webpack_require__(/*! ../parsers/wordContainerParser */ "./packages/roosterjs-content-model-plugins/lib/paste/parsers/wordContainerParser.ts");
39683
39694
  var wordTableParser_1 = __webpack_require__(/*! ../parsers/wordTableParser */ "./packages/roosterjs-content-model-plugins/lib/paste/parsers/wordTableParser.ts");
39695
+ var removeListParagraphMargins_1 = __webpack_require__(/*! ./removeListParagraphMargins */ "./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/removeListParagraphMargins.ts");
39684
39696
  /**
39685
39697
  * @internal
39686
39698
  * Handles pasted content when the source is Word Desktop.
39687
39699
  * @param domToModelOption Options for DOM to Content Model conversion
39688
39700
  * @param htmlString The HTML string to process
39701
+ * @param globalCssRules Global CSS rules extracted from the pasted document
39689
39702
  */
39690
- function processPastedContentFromWordDesktop(domToModelOption, htmlString) {
39703
+ function processPastedContentFromWordDesktop(domToModelOption, htmlString, globalCssRules) {
39704
+ if (globalCssRules === void 0) { globalCssRules = []; }
39705
+ (0, removeListParagraphMargins_1.removeListParagraphMargins)(globalCssRules);
39691
39706
  var metadataMap = (0, getStyleMetadata_1.getStyleMetadata)(htmlString);
39692
39707
  (0, setProcessor_1.setProcessor)(domToModelOption, 'element', wordDesktopElementProcessor(metadataMap));
39693
39708
  (0, addParser_1.addParser)(domToModelOption, 'block', adjustPercentileLineHeightParser_1.adjustPercentileLineHeight);
@@ -39958,6 +39973,96 @@ function getBulletElement(element) {
39958
39973
  }
39959
39974
 
39960
39975
 
39976
+ /***/ },
39977
+
39978
+ /***/ "./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/removeListParagraphMargins.ts"
39979
+ /*!******************************************************************************************************!*\
39980
+ !*** ./packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/removeListParagraphMargins.ts ***!
39981
+ \******************************************************************************************************/
39982
+ (__unused_webpack_module, exports) {
39983
+
39984
+ "use strict";
39985
+
39986
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
39987
+ exports.removeListParagraphMargins = void 0;
39988
+ /**
39989
+ * CSS class selectors used by Word Desktop to mark list paragraph elements.
39990
+ * Word emits global CSS rules that apply margins to these classes, which we want
39991
+ * to suppress so that RoosterJS list indentation logic is used instead.
39992
+ */
39993
+ var WORD_LIST_PARAGRAPH_SELECTORS = new Set([
39994
+ 'p.MsoListParagraph',
39995
+ 'p.MsoListParagraphCxSpFirst',
39996
+ 'p.MsoListParagraphCxSpMiddle',
39997
+ 'p.MsoListParagraphCxSpLast',
39998
+ 'div.MsoListParagraph',
39999
+ 'div.MsoListParagraphCxSpFirst',
40000
+ 'div.MsoListParagraphCxSpMiddle',
40001
+ 'div.MsoListParagraphCxSpLast',
40002
+ ]);
40003
+ /**
40004
+ * @internal
40005
+ * Strips all margin-* properties from a CSS property string.
40006
+ * Empty tokens produced by a trailing semicolon are preserved so that the
40007
+ * resulting string still ends with ";" and remains safe to concatenate.
40008
+ * For example, "margin-top: 0pt; color: red;" becomes " color: red;".
40009
+ */
40010
+ function removeMarginProperties(cssText) {
40011
+ return cssText
40012
+ .split(';')
40013
+ .filter(function (prop) {
40014
+ var name = prop.split(':')[0].trim().toLowerCase();
40015
+ // Keep empty tokens (the trailing ';' produces one) and any non-margin property.
40016
+ return !name || !/^margin/.test(name);
40017
+ })
40018
+ .join(';');
40019
+ }
40020
+ /**
40021
+ * @internal
40022
+ * Removes margin properties from global CSS rules that target Word list paragraph
40023
+ * classes (p.MsoListParagraph, p.MsoListParagraphCxSpFirst, etc.).
40024
+ *
40025
+ * Word Desktop pastes a global stylesheet that typically includes rules like:
40026
+ * p.MsoListParagraph { margin: 0in; margin-bottom: .0001pt; ... }
40027
+ * These margins conflict with RoosterJS's own list indentation, causing double
40028
+ * indentation when the CSS is converted to inline styles via convertInlineCss.
40029
+ *
40030
+ * When a rule's selectors are exclusively list paragraph classes the margins are
40031
+ * removed in place. When a rule groups list paragraph classes with other selectors
40032
+ * the rule is split: the non-list selectors keep the original text, and a new rule
40033
+ * is inserted for the list paragraph selectors with margins stripped.
40034
+ *
40035
+ * The array is mutated in place so the changes are reflected when convertInlineCss
40036
+ * subsequently processes the same array reference.
40037
+ */
40038
+ function removeListParagraphMargins(globalCssRules) {
40039
+ // Iterate in reverse so that splice insertions don't shift unvisited indices.
40040
+ for (var i = globalCssRules.length - 1; i >= 0; i--) {
40041
+ var rule = globalCssRules[i];
40042
+ var matchingSelectors = rule.selectors.filter(function (s) { return WORD_LIST_PARAGRAPH_SELECTORS.has(s); });
40043
+ if (matchingSelectors.length === 0) {
40044
+ continue;
40045
+ }
40046
+ var nonMatchingSelectors = rule.selectors.filter(function (s) { return !WORD_LIST_PARAGRAPH_SELECTORS.has(s); });
40047
+ if (nonMatchingSelectors.length === 0) {
40048
+ // All selectors target list paragraphs — strip margins directly.
40049
+ rule.text = removeMarginProperties(rule.text);
40050
+ }
40051
+ else {
40052
+ // Mixed rule: keep the non-list selectors on the original entry, then
40053
+ // insert a new entry immediately after for the list paragraph selectors
40054
+ // with margins removed.
40055
+ rule.selectors = nonMatchingSelectors;
40056
+ globalCssRules.splice(i + 1, 0, {
40057
+ selectors: matchingSelectors,
40058
+ text: removeMarginProperties(rule.text),
40059
+ });
40060
+ }
40061
+ }
40062
+ }
40063
+ exports.removeListParagraphMargins = removeListParagraphMargins;
40064
+
40065
+
39961
40066
  /***/ },
39962
40067
 
39963
40068
  /***/ "./packages/roosterjs-content-model-plugins/lib/paste/oneNote/processPastedContentFromOneNote.ts"