roosterjs 9.11.2 → 9.12.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.11.2)
1
+ // Type definitions for roosterjs (Version 9.12.0)
2
2
  // Generated by dts tool from roosterjs
3
3
  // Project: https://github.com/Microsoft/roosterjs
4
4
 
@@ -4359,6 +4359,28 @@ export interface ContextMenuPluginState {
4359
4359
  contextMenuProviders: ContextMenuProvider<any>[];
4360
4360
  }
4361
4361
 
4362
+ /**
4363
+ * Options to customize the Auto link options in Auto Format Plugin
4364
+ */
4365
+ export interface AutoLinkOptions {
4366
+ /**
4367
+ * When press backspace before a link, remove the hyperlink
4368
+ */
4369
+ autoUnlink?: boolean;
4370
+ /**
4371
+ * When paste or type content with a link, create hyperlink for the link
4372
+ */
4373
+ autoLink?: boolean;
4374
+ /**
4375
+ * When paste content or type content with telephone, create hyperlink for the telephone number
4376
+ */
4377
+ autoTel?: boolean;
4378
+ /**
4379
+ * When paste or type a content with mailto, create hyperlink for the content
4380
+ */
4381
+ autoMailto?: boolean;
4382
+ }
4383
+
4362
4384
  /**
4363
4385
  * Current running environment
4364
4386
  */
@@ -5333,14 +5355,16 @@ export interface MergeModelOption {
5333
5355
  insertPosition?: InsertPoint;
5334
5356
  /**
5335
5357
  * Use this to decide whether to change the source model format when doing the merge.
5336
- * 'mergeAll': segment format of the insert position will be merged into the content that is merged into current model.
5358
+ * 'mergeAll': (deprecated) Use PreferSource Instead, segment format of the insert position will be merged into the content that is merged into current model.
5337
5359
  * If the source model already has some format, it will not be overwritten.
5338
5360
  * 'keepSourceEmphasisFormat': format of the insert position will be set into the content that is merged into current model.
5339
5361
  * If the source model already has emphasis format, such as, fontWeight, Italic or underline different than the default style, it will not be overwritten.
5340
5362
  * 'none' the source segment format will not be modified.
5363
+ * 'preferSource' Will merge both formatting, but source will overwrite target
5364
+ * 'preferTarget' Will merge both formatting, but target will overwrite source
5341
5365
  * @default undefined
5342
5366
  */
5343
- mergeFormat?: 'mergeAll' | 'keepSourceEmphasisFormat' | 'none';
5367
+ mergeFormat?: 'mergeAll' | 'keepSourceEmphasisFormat' | 'none' | 'preferSource' | 'preferTarget';
5344
5368
  /**
5345
5369
  * Whether to add a paragraph after the merged content.
5346
5370
  */
@@ -7181,9 +7205,10 @@ export function getListStyleTypeFromString(listType: 'OL' | 'UL', bullet: string
7181
7205
  /**
7182
7206
  * Get the text format of a segment, this function will return only format that is applicable to text
7183
7207
  * @param segment The segment to get format from
7208
+ * @param includingBIU When pass true, also get Bold/Italic/Underline format
7184
7209
  * @returns
7185
7210
  */
7186
- export function getSegmentTextFormat(segment: ReadonlyContentModelSegment): ContentModelSegmentFormat;
7211
+ export function getSegmentTextFormat(segment: ReadonlyContentModelSegment, includingBIU?: boolean): ContentModelSegmentFormat;
7187
7212
 
7188
7213
  /**
7189
7214
  * Get index of closest ancestor block group of the expected block group type. If not found, return -1
@@ -8269,6 +8294,19 @@ export function setModelIndentation(model: ReadonlyContentModelDocument, indenta
8269
8294
  */
8270
8295
  export function matchLink(url: string): LinkData | null;
8271
8296
 
8297
+ /**
8298
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
8299
+ * When the whole text segment if of a link, promote the whole segment.
8300
+ * When the text segment ends with a link format, split the segment and promote the second part
8301
+ * When link is in middle of the text segment, no action.
8302
+ * This is mainly used for doing auto link when there is a link before cursor
8303
+ * @param segment The text segment to search link text from
8304
+ * @param paragraph Parent paragraph of the segment
8305
+ * @param options Options of auto link
8306
+ * @returns If a link is promoted, return this segment. Otherwise return null
8307
+ */
8308
+ export function promoteLink(segment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, autoLinkOptions: AutoLinkOptions): ContentModelText | null;
8309
+
8272
8310
  /**
8273
8311
  * Get announce data for list item
8274
8312
  * @param path Content model path that include the list item
@@ -8527,28 +8565,6 @@ export interface AutoFormatOptions extends AutoLinkOptions {
8527
8565
  autoOrdinals?: boolean;
8528
8566
  }
8529
8567
 
8530
- /**
8531
- * Options to customize the Auto link options in Auto Format Plugin
8532
- */
8533
- export interface AutoLinkOptions {
8534
- /**
8535
- * When press backspace before a link, remove the hyperlink
8536
- */
8537
- autoUnlink?: boolean;
8538
- /**
8539
- * When paste or type content with a link, create hyperlink for the link
8540
- */
8541
- autoLink?: boolean;
8542
- /**
8543
- * When paste content or type content with telephone, create hyperlink for the telephone number
8544
- */
8545
- autoTel?: boolean;
8546
- /**
8547
- * When paste or type a content with mailto, create hyperlink for the content
8548
- */
8549
- autoMailto?: boolean;
8550
- }
8551
-
8552
8568
  /**
8553
8569
  * Shortcut command for Bold
8554
8570
  * Windows: Ctrl + B
@@ -2094,7 +2094,7 @@ exports["default"] = getDarkColor;
2094
2094
 
2095
2095
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2096
2096
  exports.formatSegmentWithContentModel = exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.clearSelectedCells = exports.insertTableColumn = exports.insertTableRow = exports.insertEntity = exports.toggleCode = exports.setParagraphMargin = exports.adjustImageSelection = exports.setImageAltText = exports.adjustLinkSelection = exports.removeLink = exports.insertLink = exports.clearFormat = exports.getFormatState = exports.changeImage = exports.setImageBoxShadow = exports.setImageBorder = exports.setSpacing = exports.toggleBlockQuote = exports.setHeadingLevel = exports.setDirection = exports.setAlignment = exports.setIndentation = exports.setListStartNumber = exports.setListStyle = exports.insertImage = exports.splitTextSegment = exports.changeCapitalization = exports.applySegmentFormat = exports.changeFontSize = exports.setTextColor = exports.setFontSize = exports.setFontName = exports.setBackgroundColor = exports.toggleSuperscript = exports.toggleSubscript = exports.toggleStrikethrough = exports.toggleUnderline = exports.toggleItalic = exports.toggleBold = exports.toggleNumbering = exports.toggleBullet = exports.applyTableBorderFormat = exports.editTable = exports.setTableCellShade = exports.formatTable = exports.insertTable = void 0;
2097
- exports.getListAnnounceData = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = void 0;
2097
+ exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = void 0;
2098
2098
  var insertTable_1 = __webpack_require__(/*! ./publicApi/table/insertTable */ "./packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts");
2099
2099
  Object.defineProperty(exports, "insertTable", ({ enumerable: true, get: function () { return insertTable_1.insertTable; } }));
2100
2100
  var formatTable_1 = __webpack_require__(/*! ./publicApi/table/formatTable */ "./packages/roosterjs-content-model-api/lib/publicApi/table/formatTable.ts");
@@ -2211,6 +2211,8 @@ var setModelIndentation_1 = __webpack_require__(/*! ./modelApi/block/setModelInd
2211
2211
  Object.defineProperty(exports, "setModelIndentation", ({ enumerable: true, get: function () { return setModelIndentation_1.setModelIndentation; } }));
2212
2212
  var matchLink_1 = __webpack_require__(/*! ./modelApi/link/matchLink */ "./packages/roosterjs-content-model-api/lib/modelApi/link/matchLink.ts");
2213
2213
  Object.defineProperty(exports, "matchLink", ({ enumerable: true, get: function () { return matchLink_1.matchLink; } }));
2214
+ var promoteLink_1 = __webpack_require__(/*! ./modelApi/link/promoteLink */ "./packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts");
2215
+ Object.defineProperty(exports, "promoteLink", ({ enumerable: true, get: function () { return promoteLink_1.promoteLink; } }));
2214
2216
  var getListAnnounceData_1 = __webpack_require__(/*! ./modelApi/list/getListAnnounceData */ "./packages/roosterjs-content-model-api/lib/modelApi/list/getListAnnounceData.ts");
2215
2217
  Object.defineProperty(exports, "getListAnnounceData", ({ enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } }));
2216
2218
 
@@ -3066,6 +3068,42 @@ function applyImageBorderFormat(image, border, borderRadius) {
3066
3068
  exports.applyImageBorderFormat = applyImageBorderFormat;
3067
3069
 
3068
3070
 
3071
+ /***/ }),
3072
+
3073
+ /***/ "./packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts":
3074
+ /*!******************************************************************************!*\
3075
+ !*** ./packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts ***!
3076
+ \******************************************************************************/
3077
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3078
+
3079
+ "use strict";
3080
+
3081
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3082
+ exports.getLinkUrl = void 0;
3083
+ var matchLink_1 = __webpack_require__(/*! ./matchLink */ "./packages/roosterjs-content-model-api/lib/modelApi/link/matchLink.ts");
3084
+ var COMMON_REGEX = "[s]*[a-zA-Z0-9+][s]*";
3085
+ var TELEPHONE_REGEX = "(T|t)el:" + COMMON_REGEX;
3086
+ var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
3087
+ /**
3088
+ * @internal
3089
+ */
3090
+ function getLinkUrl(text, autoLinkOptions) {
3091
+ var _a;
3092
+ var _b = autoLinkOptions !== null && autoLinkOptions !== void 0 ? autoLinkOptions : {}, autoLink = _b.autoLink, autoMailto = _b.autoMailto, autoTel = _b.autoTel;
3093
+ var linkMatch = autoLink ? (_a = (0, matchLink_1.matchLink)(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
3094
+ var telMatch = autoTel ? matchTel(text) : undefined;
3095
+ var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
3096
+ return linkMatch || telMatch || mailtoMatch;
3097
+ }
3098
+ exports.getLinkUrl = getLinkUrl;
3099
+ function matchTel(text) {
3100
+ return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
3101
+ }
3102
+ function matchMailTo(text) {
3103
+ return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
3104
+ }
3105
+
3106
+
3069
3107
  /***/ }),
3070
3108
 
3071
3109
  /***/ "./packages/roosterjs-content-model-api/lib/modelApi/link/matchLink.ts":
@@ -3170,6 +3208,51 @@ function matchLink(url) {
3170
3208
  exports.matchLink = matchLink;
3171
3209
 
3172
3210
 
3211
+ /***/ }),
3212
+
3213
+ /***/ "./packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts":
3214
+ /*!*******************************************************************************!*\
3215
+ !*** ./packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts ***!
3216
+ \*******************************************************************************/
3217
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
3218
+
3219
+ "use strict";
3220
+
3221
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3222
+ exports.promoteLink = void 0;
3223
+ var getLinkUrl_1 = __webpack_require__(/*! ./getLinkUrl */ "./packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts");
3224
+ var splitTextSegment_1 = __webpack_require__(/*! ../../publicApi/segment/splitTextSegment */ "./packages/roosterjs-content-model-api/lib/publicApi/segment/splitTextSegment.ts");
3225
+ /**
3226
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
3227
+ * When the whole text segment if of a link, promote the whole segment.
3228
+ * When the text segment ends with a link format, split the segment and promote the second part
3229
+ * When link is in middle of the text segment, no action.
3230
+ * This is mainly used for doing auto link when there is a link before cursor
3231
+ * @param segment The text segment to search link text from
3232
+ * @param paragraph Parent paragraph of the segment
3233
+ * @param options Options of auto link
3234
+ * @returns If a link is promoted, return this segment. Otherwise return null
3235
+ */
3236
+ function promoteLink(segment, paragraph, autoLinkOptions) {
3237
+ var link = segment.text.split(' ').pop();
3238
+ var url = link === null || link === void 0 ? void 0 : link.trim();
3239
+ var linkUrl = undefined;
3240
+ if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
3241
+ var linkSegment = (0, splitTextSegment_1.splitTextSegment)(segment, paragraph, segment.text.length - link.trimLeft().length, segment.text.trimRight().length);
3242
+ linkSegment.link = {
3243
+ format: {
3244
+ href: linkUrl,
3245
+ underline: true,
3246
+ },
3247
+ dataset: {},
3248
+ };
3249
+ return linkSegment;
3250
+ }
3251
+ return null;
3252
+ }
3253
+ exports.promoteLink = promoteLink;
3254
+
3255
+
3173
3256
  /***/ }),
3174
3257
 
3175
3258
  /***/ "./packages/roosterjs-content-model-api/lib/modelApi/list/findListItemsInSameThread.ts":
@@ -18434,12 +18517,15 @@ var directionFormatHandler_1 = __webpack_require__(/*! ./directionFormatHandler
18434
18517
  */
18435
18518
  exports.htmlAlignFormatHandler = {
18436
18519
  parse: function (format, element, context, defaultStyle) {
18437
- directionFormatHandler_1.directionFormatHandler.parse(format, element, context, defaultStyle);
18438
- var htmlAlign = element.getAttribute('align');
18439
- if (htmlAlign) {
18440
- format.htmlAlign = (0, dir_1.calcAlign)(htmlAlign, format.direction);
18441
- delete format.textAlign;
18442
- delete context.blockFormat.textAlign;
18520
+ // When there is text-align in CSS style on the same element, we should ignore HTML align
18521
+ if (!element.style.textAlign) {
18522
+ directionFormatHandler_1.directionFormatHandler.parse(format, element, context, defaultStyle);
18523
+ var htmlAlign = element.getAttribute('align');
18524
+ if (htmlAlign) {
18525
+ format.htmlAlign = (0, dir_1.calcAlign)(htmlAlign, format.direction);
18526
+ delete format.textAlign;
18527
+ delete context.blockFormat.textAlign;
18528
+ }
18443
18529
  }
18444
18530
  },
18445
18531
  apply: function (format, element) {
@@ -22624,7 +22710,7 @@ function deleteExpandedSelection(model, formatContext) {
22624
22710
  // so we can put cursor here after delete
22625
22711
  paragraph = block_1;
22626
22712
  insertMarkerIndex = indexes[0];
22627
- markerFormat = (0, getSegmentTextFormat_1.getSegmentTextFormat)(segments[0]);
22713
+ markerFormat = (0, getSegmentTextFormat_1.getSegmentTextFormat)(segments[0], true /*includingBIU*/);
22628
22714
  context.lastParagraph = paragraph;
22629
22715
  context.lastTableContext = tableContext;
22630
22716
  segments.forEach(function (segment, i) {
@@ -22968,18 +23054,22 @@ exports.getSegmentTextFormat = void 0;
22968
23054
  /**
22969
23055
  * Get the text format of a segment, this function will return only format that is applicable to text
22970
23056
  * @param segment The segment to get format from
23057
+ * @param includingBIU When pass true, also get Bold/Italic/Underline format
22971
23058
  * @returns
22972
23059
  */
22973
- function getSegmentTextFormat(segment) {
23060
+ function getSegmentTextFormat(segment, includingBIU) {
22974
23061
  var _a;
22975
- var _b = (_a = segment === null || segment === void 0 ? void 0 : segment.format) !== null && _a !== void 0 ? _a : {}, fontFamily = _b.fontFamily, fontSize = _b.fontSize, textColor = _b.textColor, backgroundColor = _b.backgroundColor, letterSpacing = _b.letterSpacing, lineHeight = _b.lineHeight;
23062
+ var format = (_a = segment.format) !== null && _a !== void 0 ? _a : {};
22976
23063
  var textFormat = {
22977
- fontFamily: fontFamily,
22978
- fontSize: fontSize,
22979
- textColor: textColor,
22980
- backgroundColor: backgroundColor,
22981
- letterSpacing: letterSpacing,
22982
- lineHeight: lineHeight,
23064
+ fontFamily: format.fontFamily,
23065
+ fontSize: format.fontSize,
23066
+ textColor: format.textColor,
23067
+ backgroundColor: format.backgroundColor,
23068
+ letterSpacing: format.letterSpacing,
23069
+ lineHeight: format.lineHeight,
23070
+ fontWeight: includingBIU ? format.fontWeight : undefined,
23071
+ italic: includingBIU ? format.italic : undefined,
23072
+ underline: includingBIU ? format.underline : undefined,
22983
23073
  };
22984
23074
  return removeUndefinedValues(textFormat);
22985
23075
  }
@@ -23293,12 +23383,26 @@ function getSegmentFormatInLinkFormat(targetFormat) {
23293
23383
  return result;
23294
23384
  }
23295
23385
  function mergeLinkFormat(applyDefaultFormatOption, targetFormat, sourceFormat) {
23296
- return applyDefaultFormatOption == 'mergeAll'
23297
- ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, getSegmentFormatInLinkFormat(targetFormat)), sourceFormat) : (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, getFormatWithoutSegmentFormat(sourceFormat)), getSegmentFormatInLinkFormat(targetFormat)), getSemanticFormat(sourceFormat)), getHyperlinkTextColor(sourceFormat));
23386
+ switch (applyDefaultFormatOption) {
23387
+ case 'mergeAll':
23388
+ case 'preferSource':
23389
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, getSegmentFormatInLinkFormat(targetFormat)), sourceFormat);
23390
+ case 'keepSourceEmphasisFormat':
23391
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, getFormatWithoutSegmentFormat(sourceFormat)), getSegmentFormatInLinkFormat(targetFormat)), getSemanticFormat(sourceFormat)), getHyperlinkTextColor(sourceFormat));
23392
+ case 'preferTarget':
23393
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, sourceFormat), getSegmentFormatInLinkFormat(targetFormat));
23394
+ }
23298
23395
  }
23299
23396
  function mergeSegmentFormat(applyDefaultFormatOption, targetFormat, sourceFormat) {
23300
- return applyDefaultFormatOption == 'mergeAll'
23301
- ? (0, tslib_1.__assign)((0, tslib_1.__assign)({}, targetFormat), sourceFormat) : (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, getFormatWithoutSegmentFormat(sourceFormat)), targetFormat), getSemanticFormat(sourceFormat));
23397
+ switch (applyDefaultFormatOption) {
23398
+ case 'mergeAll':
23399
+ case 'preferSource':
23400
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, targetFormat), sourceFormat);
23401
+ case 'preferTarget':
23402
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, sourceFormat), targetFormat);
23403
+ case 'keepSourceEmphasisFormat':
23404
+ return (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, getFormatWithoutSegmentFormat(sourceFormat)), targetFormat), getSemanticFormat(sourceFormat));
23405
+ }
23302
23406
  }
23303
23407
  function getSemanticFormat(segmentFormat) {
23304
23408
  var result = {};
@@ -26602,7 +26706,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
26602
26706
  exports.AutoFormatPlugin = void 0;
26603
26707
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
26604
26708
  var createLink_1 = __webpack_require__(/*! ./link/createLink */ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.ts");
26605
- var createLinkAfterSpace_1 = __webpack_require__(/*! ./link/createLinkAfterSpace */ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts");
26606
26709
  var roosterjs_content_model_api_1 = __webpack_require__(/*! roosterjs-content-model-api */ "./packages/roosterjs-content-model-api/lib/index.ts");
26607
26710
  var keyboardListTrigger_1 = __webpack_require__(/*! ./list/keyboardListTrigger */ "./packages/roosterjs-content-model-plugins/lib/autoFormat/list/keyboardListTrigger.ts");
26608
26711
  var transformFraction_1 = __webpack_require__(/*! ./numbers/transformFraction */ "./packages/roosterjs-content-model-plugins/lib/autoFormat/numbers/transformFraction.ts");
@@ -26712,11 +26815,14 @@ var AutoFormatPlugin = /** @class */ (function () {
26712
26815
  shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
26713
26816
  }
26714
26817
  if (autoLink || autoTel || autoMailto) {
26715
- shouldLink = (0, createLinkAfterSpace_1.createLinkAfterSpace)(previousSegment, paragraph, context, {
26818
+ shouldLink = !!(0, roosterjs_content_model_api_1.promoteLink)(previousSegment, paragraph, {
26716
26819
  autoLink: autoLink,
26717
26820
  autoTel: autoTel,
26718
26821
  autoMailto: autoMailto,
26719
26822
  });
26823
+ if (shouldLink) {
26824
+ context.canUndoByBackspace = true;
26825
+ }
26720
26826
  }
26721
26827
  if (autoHyphen) {
26722
26828
  shouldHyphen = (0, transformHyphen_1.transformHyphen)(previousSegment, paragraph, context);
@@ -26740,6 +26846,7 @@ var AutoFormatPlugin = /** @class */ (function () {
26740
26846
  }
26741
26847
  };
26742
26848
  AutoFormatPlugin.prototype.handleKeyDownEvent = function (editor, event) {
26849
+ var _this = this;
26743
26850
  var rawEvent = event.rawEvent;
26744
26851
  if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
26745
26852
  switch (rawEvent.key) {
@@ -26748,6 +26855,20 @@ var AutoFormatPlugin = /** @class */ (function () {
26748
26855
  (0, unlink_1.unlink)(editor, rawEvent);
26749
26856
  }
26750
26857
  break;
26858
+ case 'Tab':
26859
+ (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, _previousSegment, paragraph, _markerFormat, context) {
26860
+ var _a = _this.options, autoBullet = _a.autoBullet, autoNumbering = _a.autoNumbering;
26861
+ var shouldList = false;
26862
+ if (autoBullet || autoNumbering) {
26863
+ shouldList = (0, keyboardListTrigger_1.keyboardListTrigger)(model, paragraph, context, autoBullet, autoNumbering);
26864
+ context.canUndoByBackspace = shouldList;
26865
+ event.rawEvent.preventDefault();
26866
+ }
26867
+ return shouldList;
26868
+ }, {
26869
+ changeSource: roosterjs_content_model_dom_1.ChangeSource.AutoFormat,
26870
+ apiName: 'autoToggleList',
26871
+ });
26751
26872
  }
26752
26873
  }
26753
26874
  };
@@ -26835,33 +26956,26 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
26835
26956
  exports.createLink = void 0;
26836
26957
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
26837
26958
  var roosterjs_content_model_api_1 = __webpack_require__(/*! roosterjs-content-model-api */ "./packages/roosterjs-content-model-api/lib/index.ts");
26838
- var getLinkUrl_1 = __webpack_require__(/*! ./getLinkUrl */ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/getLinkUrl.ts");
26839
26959
  /**
26840
26960
  * @internal
26841
26961
  */
26842
26962
  function createLink(editor, autoLinkOptions) {
26843
26963
  var anchorNode = null;
26844
26964
  var links = [];
26845
- (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, linkSegment, _paragraph) {
26846
- if (linkSegment.link) {
26847
- links.push(linkSegment.link);
26965
+ (0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (_model, segment, paragraph) {
26966
+ var promotedSegment = null;
26967
+ if (segment.link) {
26968
+ links.push(segment.link);
26848
26969
  return true;
26849
26970
  }
26850
- var linkUrl = undefined;
26851
- if (!linkSegment.link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(linkSegment.text, autoLinkOptions))) {
26852
- (0, roosterjs_content_model_dom_1.addLink)(linkSegment, {
26853
- format: {
26854
- href: linkUrl,
26855
- underline: true,
26856
- },
26857
- dataset: {},
26858
- });
26859
- if (linkSegment.link) {
26860
- links.push(linkSegment.link);
26861
- }
26971
+ else if ((promotedSegment = (0, roosterjs_content_model_api_1.promoteLink)(segment, paragraph, autoLinkOptions)) &&
26972
+ promotedSegment.link) {
26973
+ links.push(promotedSegment.link);
26862
26974
  return true;
26863
26975
  }
26864
- return false;
26976
+ else {
26977
+ return false;
26978
+ }
26865
26979
  }, {
26866
26980
  changeSource: roosterjs_content_model_dom_1.ChangeSource.AutoLink,
26867
26981
  onNodeCreated: function (modelElement, node) {
@@ -26875,80 +26989,6 @@ function createLink(editor, autoLinkOptions) {
26875
26989
  exports.createLink = createLink;
26876
26990
 
26877
26991
 
26878
- /***/ }),
26879
-
26880
- /***/ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts":
26881
- /*!**********************************************************************************************!*\
26882
- !*** ./packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLinkAfterSpace.ts ***!
26883
- \**********************************************************************************************/
26884
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
26885
-
26886
- "use strict";
26887
-
26888
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26889
- exports.createLinkAfterSpace = void 0;
26890
- var getLinkUrl_1 = __webpack_require__(/*! ./getLinkUrl */ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/getLinkUrl.ts");
26891
- var roosterjs_content_model_api_1 = __webpack_require__(/*! roosterjs-content-model-api */ "./packages/roosterjs-content-model-api/lib/index.ts");
26892
- /**
26893
- * @internal
26894
- */
26895
- function createLinkAfterSpace(previousSegment, paragraph, context, autoLinkOptions) {
26896
- var link = previousSegment.text.split(' ').pop();
26897
- var url = link === null || link === void 0 ? void 0 : link.trim();
26898
- var linkUrl = undefined;
26899
- if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
26900
- var linkSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - link.trimLeft().length, previousSegment.text.trimRight().length);
26901
- linkSegment.link = {
26902
- format: {
26903
- href: linkUrl,
26904
- underline: true,
26905
- },
26906
- dataset: {},
26907
- };
26908
- context.canUndoByBackspace = true;
26909
- return true;
26910
- }
26911
- return false;
26912
- }
26913
- exports.createLinkAfterSpace = createLinkAfterSpace;
26914
-
26915
-
26916
- /***/ }),
26917
-
26918
- /***/ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/getLinkUrl.ts":
26919
- /*!************************************************************************************!*\
26920
- !*** ./packages/roosterjs-content-model-plugins/lib/autoFormat/link/getLinkUrl.ts ***!
26921
- \************************************************************************************/
26922
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
26923
-
26924
- "use strict";
26925
-
26926
- Object.defineProperty(exports, "__esModule", ({ value: true }));
26927
- exports.getLinkUrl = void 0;
26928
- var roosterjs_content_model_api_1 = __webpack_require__(/*! roosterjs-content-model-api */ "./packages/roosterjs-content-model-api/lib/index.ts");
26929
- var COMMON_REGEX = "[s]*[a-zA-Z0-9+][s]*";
26930
- var TELEPHONE_REGEX = "(T|t)el:" + COMMON_REGEX;
26931
- var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
26932
- /**
26933
- * @internal
26934
- */
26935
- function getLinkUrl(text, autoLinkOptions) {
26936
- var _a;
26937
- var autoLink = autoLinkOptions.autoLink, autoMailto = autoLinkOptions.autoMailto, autoTel = autoLinkOptions.autoTel;
26938
- var linkMatch = autoLink ? (_a = (0, roosterjs_content_model_api_1.matchLink)(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
26939
- var telMatch = autoTel ? matchTel(text) : undefined;
26940
- var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
26941
- return linkMatch || telMatch || mailtoMatch;
26942
- }
26943
- exports.getLinkUrl = getLinkUrl;
26944
- function matchTel(text) {
26945
- return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
26946
- }
26947
- function matchMailTo(text) {
26948
- return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
26949
- }
26950
-
26951
-
26952
26992
  /***/ }),
26953
26993
 
26954
26994
  /***/ "./packages/roosterjs-content-model-plugins/lib/autoFormat/link/unlink.ts":
@@ -27419,6 +27459,7 @@ var getOrdinal = function (value) {
27419
27459
  };
27420
27460
  return ORDINALS[value] || 'th';
27421
27461
  };
27462
+ var ORDINALS = ['st', 'nd', 'rd', 'th'];
27422
27463
  /**
27423
27464
  * The two last characters of ordinal number (st, nd, rd, th)
27424
27465
  */
@@ -27428,21 +27469,39 @@ var ORDINAL_LENGTH = 2;
27428
27469
  */ function transformOrdinals(previousSegment, paragraph, context) {
27429
27470
  var _a;
27430
27471
  var value = (_a = previousSegment.text.split(' ').pop()) === null || _a === void 0 ? void 0 : _a.trim();
27472
+ var shouldAddSuperScript = false;
27431
27473
  if (value) {
27432
- var ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th
27433
- var numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value = 10
27434
- if (numericValue && getOrdinal(numericValue) === ordinal) {
27474
+ var isOrdinal = ORDINALS.indexOf(value) > -1;
27475
+ if (isOrdinal) {
27476
+ var index = paragraph.segments.indexOf(previousSegment);
27477
+ var numberSegment = paragraph.segments[index - 1];
27478
+ var numericValue = null;
27479
+ if (numberSegment &&
27480
+ numberSegment.segmentType == 'Text' &&
27481
+ (numericValue = getNumericValue(numberSegment.text, true /* checkFullText */)) &&
27482
+ getOrdinal(numericValue) === value) {
27483
+ shouldAddSuperScript = true;
27484
+ }
27485
+ }
27486
+ else {
27487
+ var ordinal = value.substring(value.length - ORDINAL_LENGTH); // This value is equal st, nd, rd, th
27488
+ var numericValue = getNumericValue(value); //This is the numeric part. Ex: 10th, numeric value =
27489
+ if (numericValue && getOrdinal(numericValue) === ordinal) {
27490
+ shouldAddSuperScript = true;
27491
+ }
27492
+ }
27493
+ if (shouldAddSuperScript) {
27435
27494
  var ordinalSegment = (0, roosterjs_content_model_api_1.splitTextSegment)(previousSegment, paragraph, previousSegment.text.length - 3, previousSegment.text.length - 1);
27436
27495
  ordinalSegment.format.superOrSubScriptSequence = 'super';
27437
27496
  context.canUndoByBackspace = true;
27438
- return true;
27439
27497
  }
27440
27498
  }
27441
- return false;
27499
+ return shouldAddSuperScript;
27442
27500
  }
27443
27501
  exports.transformOrdinals = transformOrdinals;
27444
- function getNumericValue(text) {
27445
- var number = text.substring(0, text.length - ORDINAL_LENGTH);
27502
+ function getNumericValue(text, checkFullText) {
27503
+ if (checkFullText === void 0) { checkFullText = false; }
27504
+ var number = checkFullText ? text : text.substring(0, text.length - ORDINAL_LENGTH);
27446
27505
  var isNumber = /^-?\d+$/.test(number);
27447
27506
  if (isNumber) {
27448
27507
  return parseInt(text);
@@ -27777,6 +27836,7 @@ var EditPlugin = /** @class */ (function () {
27777
27836
  };
27778
27837
  EditPlugin.prototype.handleKeyDownEvent = function (editor, event) {
27779
27838
  var rawEvent = event.rawEvent;
27839
+ var hasCtrlOrMetaKey = rawEvent.ctrlKey || rawEvent.metaKey;
27780
27840
  if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {
27781
27841
  switch (rawEvent.key) {
27782
27842
  case 'Backspace':
@@ -27793,7 +27853,7 @@ var EditPlugin = /** @class */ (function () {
27793
27853
  }
27794
27854
  break;
27795
27855
  case 'Tab':
27796
- if (this.options.handleTabKey) {
27856
+ if (this.options.handleTabKey && !hasCtrlOrMetaKey) {
27797
27857
  (0, keyboardTab_1.keyboardTab)(editor, rawEvent);
27798
27858
  }
27799
27859
  break;
@@ -27803,7 +27863,9 @@ var EditPlugin = /** @class */ (function () {
27803
27863
  }
27804
27864
  break;
27805
27865
  case 'Enter':
27806
- (0, keyboardEnter_1.keyboardEnter)(editor, rawEvent, this.handleNormalEnter);
27866
+ if (!hasCtrlOrMetaKey) {
27867
+ (0, keyboardEnter_1.keyboardEnter)(editor, rawEvent, this.handleNormalEnter);
27868
+ }
27807
27869
  break;
27808
27870
  default:
27809
27871
  (0, keyboardInput_1.keyboardInput)(editor, rawEvent);
@@ -28366,6 +28428,41 @@ function shouldDeleteAllSegmentsBefore(rawEvent) {
28366
28428
  exports.shouldDeleteAllSegmentsBefore = shouldDeleteAllSegmentsBefore;
28367
28429
 
28368
28430
 
28431
+ /***/ }),
28432
+
28433
+ /***/ "./packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleAutoLink.ts":
28434
+ /*!****************************************************************************************!*\
28435
+ !*** ./packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleAutoLink.ts ***!
28436
+ \****************************************************************************************/
28437
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
28438
+
28439
+ "use strict";
28440
+
28441
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
28442
+ exports.handleAutoLink = void 0;
28443
+ var roosterjs_content_model_api_1 = __webpack_require__(/*! roosterjs-content-model-api */ "./packages/roosterjs-content-model-api/lib/index.ts");
28444
+ /**
28445
+ * @internal
28446
+ */
28447
+ var handleAutoLink = function (context) {
28448
+ var deleteResult = context.deleteResult, insertPoint = context.insertPoint;
28449
+ if (deleteResult == 'notDeleted' || deleteResult == 'nothingToDelete') {
28450
+ var marker = insertPoint.marker, paragraph = insertPoint.paragraph;
28451
+ var index = paragraph.segments.indexOf(marker);
28452
+ var segBefore = index > 0 ? paragraph.segments[index - 1] : null;
28453
+ if ((segBefore === null || segBefore === void 0 ? void 0 : segBefore.segmentType) == 'Text' &&
28454
+ (0, roosterjs_content_model_api_1.promoteLink)(segBefore, paragraph, {
28455
+ autoLink: true,
28456
+ }) &&
28457
+ context.formatContext) {
28458
+ context.formatContext.canUndoByBackspace = true;
28459
+ }
28460
+ // Do not set deleteResult here since we haven't really start a new paragraph, we need other delete step to keep working on it
28461
+ }
28462
+ };
28463
+ exports.handleAutoLink = handleAutoLink;
28464
+
28465
+
28369
28466
  /***/ }),
28370
28467
 
28371
28468
  /***/ "./packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts":
@@ -28595,6 +28692,7 @@ function canDeleteAfter(rawEvent, range) {
28595
28692
  Object.defineProperty(exports, "__esModule", ({ value: true }));
28596
28693
  exports.keyboardEnter = void 0;
28597
28694
  var deleteEmptyQuote_1 = __webpack_require__(/*! ./deleteSteps/deleteEmptyQuote */ "./packages/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteEmptyQuote.ts");
28695
+ var handleAutoLink_1 = __webpack_require__(/*! ./inputSteps/handleAutoLink */ "./packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleAutoLink.ts");
28598
28696
  var handleEnterOnList_1 = __webpack_require__(/*! ./inputSteps/handleEnterOnList */ "./packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts");
28599
28697
  var handleEnterOnParagraph_1 = __webpack_require__(/*! ./inputSteps/handleEnterOnParagraph */ "./packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnParagraph.ts");
28600
28698
  var roosterjs_content_model_dom_1 = __webpack_require__(/*! roosterjs-content-model-dom */ "./packages/roosterjs-content-model-dom/lib/index.ts");
@@ -28612,7 +28710,9 @@ function keyboardEnter(editor, rawEvent, handleNormalEnter) {
28612
28710
  // For ENTER key, although we may have deleted something, since we still need to split the line, we always treat it as not delete
28613
28711
  // so further delete steps can keep working
28614
28712
  result.deleteResult = 'notDeleted';
28615
- var steps = rawEvent.shiftKey ? [] : [handleEnterOnList_1.handleEnterOnList, deleteEmptyQuote_1.deleteEmptyQuote];
28713
+ var steps = rawEvent.shiftKey
28714
+ ? []
28715
+ : [handleAutoLink_1.handleAutoLink, handleEnterOnList_1.handleEnterOnList, deleteEmptyQuote_1.deleteEmptyQuote];
28616
28716
  if (handleNormalEnter) {
28617
28717
  steps.push(handleEnterOnParagraph_1.handleEnterOnParagraph);
28618
28718
  }