roosterjs-content-model-api 9.11.2 → 9.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -56,4 +56,5 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
56
56
  export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
57
57
  export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
+ export { promoteLink } from './modelApi/link/promoteLink';
59
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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;
4
- exports.getListAnnounceData = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = void 0;
4
+ exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = void 0;
5
5
  var insertTable_1 = require("./publicApi/table/insertTable");
6
6
  Object.defineProperty(exports, "insertTable", { enumerable: true, get: function () { return insertTable_1.insertTable; } });
7
7
  var formatTable_1 = require("./publicApi/table/formatTable");
@@ -118,6 +118,8 @@ var setModelIndentation_1 = require("./modelApi/block/setModelIndentation");
118
118
  Object.defineProperty(exports, "setModelIndentation", { enumerable: true, get: function () { return setModelIndentation_1.setModelIndentation; } });
119
119
  var matchLink_1 = require("./modelApi/link/matchLink");
120
120
  Object.defineProperty(exports, "matchLink", { enumerable: true, get: function () { return matchLink_1.matchLink; } });
121
+ var promoteLink_1 = require("./modelApi/link/promoteLink");
122
+ Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
121
123
  var getListAnnounceData_1 = require("./modelApi/list/getListAnnounceData");
122
124
  Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
123
125
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;AAAA,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA;AAC1B,yDAAwD;AAA/C,sGAAA,SAAS,OAAA;AAClB,mFAAkF;AAAzE,gIAAA,sBAAsB,OAAA;AAC/B,8DAA6D;AAApD,4GAAA,YAAY,OAAA;AACrB,oEAAmE;AAA1D,kHAAA,eAAe,OAAA;AACxB,6DA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,OAAA;AACnB,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAC5B,qEAAoE;AAA3D,kHAAA,eAAe,OAAA;AACxB,+EAA8E;AAArE,4HAAA,oBAAoB,OAAA;AAC7B,2EAA0E;AAAjE,wHAAA,kBAAkB,OAAA;AAC3B,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,gEAA+D;AAAtD,4GAAA,YAAY,OAAA;AACrB,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,sHAAA,iBAAiB,OAAA;AAC1B,0EAAyE;AAAhE,wHAAA,kBAAkB,OAAA;AAE3B,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,qGAAoG;AAA3F,kJAAA,+BAA+B,OAAA;AACxC,iGAAgG;AAAvF,8IAAA,6BAA6B,OAAA;AACtC,mHAAkH;AAAzG,gKAAA,sCAAsC,OAAA;AAC/C,yGAAwG;AAA/F,sJAAA,iCAAiC,OAAA;AAE1C,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,uEAAsE;AAA7D,sHAAA,iBAAiB,OAAA;AAC1B,mFAAkF;AAAzE,kIAAA,uBAAuB,OAAA;AAChC,uFAAsF;AAA7E,sIAAA,yBAAyB,OAAA;AAClC,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAC5B,uDAAsD;AAA7C,sGAAA,SAAS,OAAA;AAClB,2EAA0E;AAAjE,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;AAAA,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA;AAC1B,yDAAwD;AAA/C,sGAAA,SAAS,OAAA;AAClB,mFAAkF;AAAzE,gIAAA,sBAAsB,OAAA;AAC/B,8DAA6D;AAApD,4GAAA,YAAY,OAAA;AACrB,oEAAmE;AAA1D,kHAAA,eAAe,OAAA;AACxB,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,iEAAgE;AAAvD,4GAAA,YAAY,OAAA;AACrB,uEAAsE;AAA7D,kHAAA,eAAe,OAAA;AACxB,+EAA8E;AAArE,0HAAA,mBAAmB,OAAA;AAC5B,uEAAsE;AAA7D,kHAAA,eAAe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A4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,gEAA+D;AAAtD,4GAAA,YAAY,OAAA;AACrB,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,sHAAA,iBAAiB,OAAA;AAC1B,0EAAyE;AAAhE,wHAAA,kBAAkB,OAAA;AAE3B,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,qGAAoG;AAA3F,kJAAA,+BAA+B,OAAA;AACxC,iGAAgG;AAAvF,8IAAA,6BAA6B,OAAA;AACtC,mHAAkH;AAAzG,gKAAA,sCAAsC,OAAA;AAC/C,yGAAwG;AAA/F,sJAAA,iCAAiC,OAAA;AAE1C,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,uEAAsE;AAA7D,sHAAA,iBAAiB,OAAA;AAC1B,mFAAkF;AAAzE,kIAAA,uBAAuB,OAAA;AAChC,uFAAsF;AAA7E,sIAAA,yBAAyB,OAAA;AAClC,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAC5B,uDAAsD;AAA7C,sGAAA,SAAS,OAAA;AAClB,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,2EAA0E;AAAjE,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
@@ -0,0 +1,5 @@
1
+ import type { AutoLinkOptions } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLinkUrl = void 0;
4
+ var matchLink_1 = require("./matchLink");
5
+ var COMMON_REGEX = "[s]*[a-zA-Z0-9+][s]*";
6
+ var TELEPHONE_REGEX = "(T|t)el:" + COMMON_REGEX;
7
+ var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
8
+ /**
9
+ * @internal
10
+ */
11
+ function getLinkUrl(text, autoLinkOptions) {
12
+ var _a;
13
+ var _b = autoLinkOptions !== null && autoLinkOptions !== void 0 ? autoLinkOptions : {}, autoLink = _b.autoLink, autoMailto = _b.autoMailto, autoTel = _b.autoTel;
14
+ var linkMatch = autoLink ? (_a = (0, matchLink_1.matchLink)(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
15
+ var telMatch = autoTel ? matchTel(text) : undefined;
16
+ var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
17
+ return linkMatch || telMatch || mailtoMatch;
18
+ }
19
+ exports.getLinkUrl = getLinkUrl;
20
+ function matchTel(text) {
21
+ return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
22
+ }
23
+ function matchMailTo(text) {
24
+ return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
25
+ }
26
+ //# sourceMappingURL=getLinkUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLinkUrl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAGxC,IAAM,YAAY,GAAG,sBAAwB,CAAC;AAC9C,IAAM,eAAe,GAAG,aAAW,YAAc,CAAC;AAClD,IAAM,YAAY,GAAG,gBAAc,YAAc,CAAC;AAElD;;GAEG;AACH,SAAgB,UAAU,CAAC,IAAY,EAAE,eAAiC;;IAChE,IAAA,KAAoC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,EAAvD,QAAQ,cAAA,EAAE,UAAU,gBAAA,EAAE,OAAO,aAA0B,CAAC;IAChE,IAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAA,IAAA,qBAAS,EAAC,IAAI,CAAC,0CAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,IAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,IAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,OAAO,SAAS,IAAI,QAAQ,IAAI,WAAW,CAAC;AAChD,CAAC;AAPD,gCAOC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC","sourcesContent":["import { matchLink } from './matchLink';\nimport type { AutoLinkOptions } from 'roosterjs-content-model-types';\n\nconst COMMON_REGEX = `[\\s]*[a-zA-Z0-9+][\\s]*`;\nconst TELEPHONE_REGEX = `(T|t)el:${COMMON_REGEX}`;\nconst MAILTO_REGEX = `(M|m)ailto:${COMMON_REGEX}`;\n\n/**\n * @internal\n */\nexport function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined {\n const { autoLink, autoMailto, autoTel } = autoLinkOptions ?? {};\n const linkMatch = autoLink ? matchLink(text)?.normalizedUrl : undefined;\n const telMatch = autoTel ? matchTel(text) : undefined;\n const mailtoMatch = autoMailto ? matchMailTo(text) : undefined;\n\n return linkMatch || telMatch || mailtoMatch;\n}\n\nfunction matchTel(text: string) {\n return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n\nfunction matchMailTo(text: string) {\n return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { AutoLinkOptions, ContentModelText, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
4
+ * When the whole text segment if of a link, promote the whole segment.
5
+ * When the text segment ends with a link format, split the segment and promote the second part
6
+ * When link is in middle of the text segment, no action.
7
+ * This is mainly used for doing auto link when there is a link before cursor
8
+ * @param segment The text segment to search link text from
9
+ * @param paragraph Parent paragraph of the segment
10
+ * @param options Options of auto link
11
+ * @returns If a link is promoted, return this segment. Otherwise return null
12
+ */
13
+ export declare function promoteLink(segment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, autoLinkOptions: AutoLinkOptions): ContentModelText | null;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promoteLink = void 0;
4
+ var getLinkUrl_1 = require("./getLinkUrl");
5
+ var splitTextSegment_1 = require("../../publicApi/segment/splitTextSegment");
6
+ /**
7
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
8
+ * When the whole text segment if of a link, promote the whole segment.
9
+ * When the text segment ends with a link format, split the segment and promote the second part
10
+ * When link is in middle of the text segment, no action.
11
+ * This is mainly used for doing auto link when there is a link before cursor
12
+ * @param segment The text segment to search link text from
13
+ * @param paragraph Parent paragraph of the segment
14
+ * @param options Options of auto link
15
+ * @returns If a link is promoted, return this segment. Otherwise return null
16
+ */
17
+ function promoteLink(segment, paragraph, autoLinkOptions) {
18
+ var link = segment.text.split(' ').pop();
19
+ var url = link === null || link === void 0 ? void 0 : link.trim();
20
+ var linkUrl = undefined;
21
+ if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
22
+ var linkSegment = (0, splitTextSegment_1.splitTextSegment)(segment, paragraph, segment.text.length - link.trimLeft().length, segment.text.trimRight().length);
23
+ linkSegment.link = {
24
+ format: {
25
+ href: linkUrl,
26
+ underline: true,
27
+ },
28
+ dataset: {},
29
+ };
30
+ return linkSegment;
31
+ }
32
+ return null;
33
+ }
34
+ exports.promoteLink = promoteLink;
35
+ //# sourceMappingURL=promoteLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promoteLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts"],"names":[],"mappings":";;;AAAA,2CAA0C;AAC1C,6EAA4E;AAO5E;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACvB,OAAyB,EACzB,SAA8C,EAC9C,eAAgC;IAEhC,IAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAC3C,IAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;IACzB,IAAI,OAAO,GAAuB,SAAS,CAAC;IAE5C,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE;QAC7D,IAAM,WAAW,GAAG,IAAA,mCAAgB,EAChC,OAAO,EACP,SAAS,EACT,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EAC5C,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAClC,CAAC;QACF,WAAW,CAAC,IAAI,GAAG;YACf,MAAM,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,IAAI;aAClB;YACD,OAAO,EAAE,EAAE;SACd,CAAC;QAEF,OAAO,WAAW,CAAC;KACtB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AA5BD,kCA4BC","sourcesContent":["import { getLinkUrl } from './getLinkUrl';\nimport { splitTextSegment } from '../../publicApi/segment/splitTextSegment';\nimport type {\n AutoLinkOptions,\n ContentModelText,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.\n * When the whole text segment if of a link, promote the whole segment.\n * When the text segment ends with a link format, split the segment and promote the second part\n * When link is in middle of the text segment, no action.\n * This is mainly used for doing auto link when there is a link before cursor\n * @param segment The text segment to search link text from\n * @param paragraph Parent paragraph of the segment\n * @param options Options of auto link\n * @returns If a link is promoted, return this segment. Otherwise return null\n */\nexport function promoteLink(\n segment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n autoLinkOptions: AutoLinkOptions\n): ContentModelText | null {\n const link = segment.text.split(' ').pop();\n const url = link?.trim();\n let linkUrl: string | undefined = undefined;\n\n if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) {\n const linkSegment = splitTextSegment(\n segment,\n paragraph,\n segment.text.length - link.trimLeft().length,\n segment.text.trimRight().length\n );\n linkSegment.link = {\n format: {\n href: linkUrl,\n underline: true,\n },\n dataset: {},\n };\n\n return linkSegment;\n }\n\n return null;\n}\n"]}
@@ -56,4 +56,5 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
56
56
  export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
57
57
  export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
+ export { promoteLink } from './modelApi/link/promoteLink';
59
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
package/lib-amd/index.js CHANGED
@@ -1,7 +1,7 @@
1
- define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/table/formatTable", "./publicApi/table/setTableCellShade", "./publicApi/table/editTable", "./publicApi/table/applyTableBorderFormat", "./publicApi/list/toggleBullet", "./publicApi/list/toggleNumbering", "./publicApi/segment/toggleBold", "./publicApi/segment/toggleItalic", "./publicApi/segment/toggleUnderline", "./publicApi/segment/toggleStrikethrough", "./publicApi/segment/toggleSubscript", "./publicApi/segment/toggleSuperscript", "./publicApi/segment/setBackgroundColor", "./publicApi/segment/setFontName", "./publicApi/segment/setFontSize", "./publicApi/segment/setTextColor", "./publicApi/segment/changeFontSize", "./publicApi/segment/applySegmentFormat", "./publicApi/segment/changeCapitalization", "./publicApi/segment/splitTextSegment", "./publicApi/image/insertImage", "./publicApi/list/setListStyle", "./publicApi/list/setListStartNumber", "./publicApi/block/setIndentation", "./publicApi/block/setAlignment", "./publicApi/block/setDirection", "./publicApi/block/setHeadingLevel", "./publicApi/block/toggleBlockQuote", "./publicApi/block/setSpacing", "./publicApi/image/setImageBorder", "./publicApi/image/setImageBoxShadow", "./publicApi/image/changeImage", "./publicApi/format/getFormatState", "./publicApi/format/clearFormat", "./publicApi/link/insertLink", "./publicApi/link/removeLink", "./publicApi/link/adjustLinkSelection", "./publicApi/image/setImageAltText", "./publicApi/image/adjustImageSelection", "./publicApi/block/setParagraphMargin", "./publicApi/segment/toggleCode", "./publicApi/entity/insertEntity", "./modelApi/table/insertTableRow", "./modelApi/table/insertTableColumn", "./modelApi/table/clearSelectedCells", "./publicApi/utils/formatTableWithContentModel", "./publicApi/utils/formatImageWithContentModel", "./publicApi/utils/formatParagraphWithContentModel", "./publicApi/utils/formatSegmentWithContentModel", "./publicApi/utils/formatTextSegmentBeforeSelectionMarker", "./publicApi/utils/formatInsertPointWithContentModel", "./modelApi/list/setListType", "./modelApi/list/setModelListStyle", "./modelApi/list/setModelListStartNumber", "./modelApi/list/findListItemsInSameThread", "./modelApi/block/setModelIndentation", "./modelApi/link/matchLink", "./modelApi/list/getListAnnounceData"], function (require, exports, insertTable_1, formatTable_1, setTableCellShade_1, editTable_1, applyTableBorderFormat_1, toggleBullet_1, toggleNumbering_1, toggleBold_1, toggleItalic_1, toggleUnderline_1, toggleStrikethrough_1, toggleSubscript_1, toggleSuperscript_1, setBackgroundColor_1, setFontName_1, setFontSize_1, setTextColor_1, changeFontSize_1, applySegmentFormat_1, changeCapitalization_1, splitTextSegment_1, insertImage_1, setListStyle_1, setListStartNumber_1, setIndentation_1, setAlignment_1, setDirection_1, setHeadingLevel_1, toggleBlockQuote_1, setSpacing_1, setImageBorder_1, setImageBoxShadow_1, changeImage_1, getFormatState_1, clearFormat_1, insertLink_1, removeLink_1, adjustLinkSelection_1, setImageAltText_1, adjustImageSelection_1, setParagraphMargin_1, toggleCode_1, insertEntity_1, insertTableRow_1, insertTableColumn_1, clearSelectedCells_1, formatTableWithContentModel_1, formatImageWithContentModel_1, formatParagraphWithContentModel_1, formatSegmentWithContentModel_1, formatTextSegmentBeforeSelectionMarker_1, formatInsertPointWithContentModel_1, setListType_1, setModelListStyle_1, setModelListStartNumber_1, findListItemsInSameThread_1, setModelIndentation_1, matchLink_1, getListAnnounceData_1) {
1
+ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/table/formatTable", "./publicApi/table/setTableCellShade", "./publicApi/table/editTable", "./publicApi/table/applyTableBorderFormat", "./publicApi/list/toggleBullet", "./publicApi/list/toggleNumbering", "./publicApi/segment/toggleBold", "./publicApi/segment/toggleItalic", "./publicApi/segment/toggleUnderline", "./publicApi/segment/toggleStrikethrough", "./publicApi/segment/toggleSubscript", "./publicApi/segment/toggleSuperscript", "./publicApi/segment/setBackgroundColor", "./publicApi/segment/setFontName", "./publicApi/segment/setFontSize", "./publicApi/segment/setTextColor", "./publicApi/segment/changeFontSize", "./publicApi/segment/applySegmentFormat", "./publicApi/segment/changeCapitalization", "./publicApi/segment/splitTextSegment", "./publicApi/image/insertImage", "./publicApi/list/setListStyle", "./publicApi/list/setListStartNumber", "./publicApi/block/setIndentation", "./publicApi/block/setAlignment", "./publicApi/block/setDirection", "./publicApi/block/setHeadingLevel", "./publicApi/block/toggleBlockQuote", "./publicApi/block/setSpacing", "./publicApi/image/setImageBorder", "./publicApi/image/setImageBoxShadow", "./publicApi/image/changeImage", "./publicApi/format/getFormatState", "./publicApi/format/clearFormat", "./publicApi/link/insertLink", "./publicApi/link/removeLink", "./publicApi/link/adjustLinkSelection", "./publicApi/image/setImageAltText", "./publicApi/image/adjustImageSelection", "./publicApi/block/setParagraphMargin", "./publicApi/segment/toggleCode", "./publicApi/entity/insertEntity", "./modelApi/table/insertTableRow", "./modelApi/table/insertTableColumn", "./modelApi/table/clearSelectedCells", "./publicApi/utils/formatTableWithContentModel", "./publicApi/utils/formatImageWithContentModel", "./publicApi/utils/formatParagraphWithContentModel", "./publicApi/utils/formatSegmentWithContentModel", "./publicApi/utils/formatTextSegmentBeforeSelectionMarker", "./publicApi/utils/formatInsertPointWithContentModel", "./modelApi/list/setListType", "./modelApi/list/setModelListStyle", "./modelApi/list/setModelListStartNumber", "./modelApi/list/findListItemsInSameThread", "./modelApi/block/setModelIndentation", "./modelApi/link/matchLink", "./modelApi/link/promoteLink", "./modelApi/list/getListAnnounceData"], function (require, exports, insertTable_1, formatTable_1, setTableCellShade_1, editTable_1, applyTableBorderFormat_1, toggleBullet_1, toggleNumbering_1, toggleBold_1, toggleItalic_1, toggleUnderline_1, toggleStrikethrough_1, toggleSubscript_1, toggleSuperscript_1, setBackgroundColor_1, setFontName_1, setFontSize_1, setTextColor_1, changeFontSize_1, applySegmentFormat_1, changeCapitalization_1, splitTextSegment_1, insertImage_1, setListStyle_1, setListStartNumber_1, setIndentation_1, setAlignment_1, setDirection_1, setHeadingLevel_1, toggleBlockQuote_1, setSpacing_1, setImageBorder_1, setImageBoxShadow_1, changeImage_1, getFormatState_1, clearFormat_1, insertLink_1, removeLink_1, adjustLinkSelection_1, setImageAltText_1, adjustImageSelection_1, setParagraphMargin_1, toggleCode_1, insertEntity_1, insertTableRow_1, insertTableColumn_1, clearSelectedCells_1, formatTableWithContentModel_1, formatImageWithContentModel_1, formatParagraphWithContentModel_1, formatSegmentWithContentModel_1, formatTextSegmentBeforeSelectionMarker_1, formatInsertPointWithContentModel_1, setListType_1, setModelListStyle_1, setModelListStartNumber_1, findListItemsInSameThread_1, setModelIndentation_1, matchLink_1, promoteLink_1, getListAnnounceData_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getListAnnounceData = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = 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;
4
+ exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = 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;
5
5
  Object.defineProperty(exports, "insertTable", { enumerable: true, get: function () { return insertTable_1.insertTable; } });
6
6
  Object.defineProperty(exports, "formatTable", { enumerable: true, get: function () { return formatTable_1.formatTable; } });
7
7
  Object.defineProperty(exports, "setTableCellShade", { enumerable: true, get: function () { return setTableCellShade_1.setTableCellShade; } });
@@ -60,6 +60,7 @@ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/tabl
60
60
  Object.defineProperty(exports, "findListItemsInSameThread", { enumerable: true, get: function () { return findListItemsInSameThread_1.findListItemsInSameThread; } });
61
61
  Object.defineProperty(exports, "setModelIndentation", { enumerable: true, get: function () { return setModelIndentation_1.setModelIndentation; } });
62
62
  Object.defineProperty(exports, "matchLink", { enumerable: true, get: function () { return matchLink_1.matchLink; } });
63
+ Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
63
64
  Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
64
65
  });
65
66
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB,OAAA;IACtB,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAClB,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,wHAAA,kBAAkB,OAAA;IAClB,4HAAA,oBAAoB,OAAA;IACpB,oHAAA,gBAAgB,OAAA;IAChB,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,wHAAA,kBAAkB,OAAA;IAClB,gHAAA,cAAc,OAAA;IACd,4GAAA,YAAY,OAAA;IACZ,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,oHAAA,gBAAgB,OAAA;IAChB,wGAAA,UAAU,OAAA;IACV,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,0GAAA,WAAW,OAAA;IACX,gHAAA,cAAc,OAAA;IACd,0GAAA,WAAW,OAAA;IACX,wGAAA,UAAU,OAAA;IACV,wGAAA,UAAU,OAAA;IACV,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,4HAAA,oBAAoB,OAAA;IACpB,wHAAA,kBAAkB,OAAA;IAClB,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAElB,0IAAA,2BAA2B,OAAA;IAC3B,0IAAA,2BAA2B,OAAA;IAC3B,kJAAA,+BAA+B,OAAA;IAC/B,8IAAA,6BAA6B,OAAA;IAC7B,gKAAA,sCAAsC,OAAA;IACtC,sJAAA,iCAAiC,OAAA;IAEjC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB,OAAA;IACtB,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAClB,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,wHAAA,kBAAkB,OAAA;IAClB,4HAAA,oBAAoB,OAAA;IACpB,oHAAA,gBAAgB,OAAA;IAChB,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,wHAAA,kBAAkB,OAAA;IAClB,gHAAA,cAAc,OAAA;IACd,4GAAA,YAAY,OAAA;IACZ,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,oHAAA,gBAAgB,OAAA;IAChB,wGAAA,UAAU,OAAA;IACV,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,0GAAA,WAAW,OAAA;IACX,gHAAA,cAAc,OAAA;IACd,0GAAA,WAAW,OAAA;IACX,wGAAA,UAAU,OAAA;IACV,wGAAA,UAAU,OAAA;IACV,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,4HAAA,oBAAoB,OAAA;IACpB,wHAAA,kBAAkB,OAAA;IAClB,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAElB,0IAAA,2BAA2B,OAAA;IAC3B,0IAAA,2BAA2B,OAAA;IAC3B,kJAAA,+BAA+B,OAAA;IAC/B,8IAAA,6BAA6B,OAAA;IAC7B,gKAAA,sCAAsC,OAAA;IACtC,sJAAA,iCAAiC,OAAA;IAEjC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0GAAA,WAAW,OAAA;IACX,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
@@ -0,0 +1,5 @@
1
+ import type { AutoLinkOptions } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined;
@@ -0,0 +1,27 @@
1
+ define(["require", "exports", "./matchLink"], function (require, exports, matchLink_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getLinkUrl = void 0;
5
+ var COMMON_REGEX = "[s]*[a-zA-Z0-9+][s]*";
6
+ var TELEPHONE_REGEX = "(T|t)el:" + COMMON_REGEX;
7
+ var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
8
+ /**
9
+ * @internal
10
+ */
11
+ function getLinkUrl(text, autoLinkOptions) {
12
+ var _a;
13
+ var _b = autoLinkOptions !== null && autoLinkOptions !== void 0 ? autoLinkOptions : {}, autoLink = _b.autoLink, autoMailto = _b.autoMailto, autoTel = _b.autoTel;
14
+ var linkMatch = autoLink ? (_a = (0, matchLink_1.matchLink)(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
15
+ var telMatch = autoTel ? matchTel(text) : undefined;
16
+ var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
17
+ return linkMatch || telMatch || mailtoMatch;
18
+ }
19
+ exports.getLinkUrl = getLinkUrl;
20
+ function matchTel(text) {
21
+ return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
22
+ }
23
+ function matchMailTo(text) {
24
+ return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
25
+ }
26
+ });
27
+ //# sourceMappingURL=getLinkUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLinkUrl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts"],"names":[],"mappings":";;;;IAGA,IAAM,YAAY,GAAG,sBAAwB,CAAC;IAC9C,IAAM,eAAe,GAAG,aAAW,YAAc,CAAC;IAClD,IAAM,YAAY,GAAG,gBAAc,YAAc,CAAC;IAElD;;OAEG;IACH,SAAgB,UAAU,CAAC,IAAY,EAAE,eAAiC;;QAChE,IAAA,KAAoC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,EAAvD,QAAQ,cAAA,EAAE,UAAU,gBAAA,EAAE,OAAO,aAA0B,CAAC;QAChE,IAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAA,IAAA,qBAAS,EAAC,IAAI,CAAC,0CAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;QACxE,IAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACtD,IAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE/D,OAAO,SAAS,IAAI,QAAQ,IAAI,WAAW,CAAC;IAChD,CAAC;IAPD,gCAOC;IAED,SAAS,QAAQ,CAAC,IAAY;QAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,CAAC;IAED,SAAS,WAAW,CAAC,IAAY;QAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC","sourcesContent":["import { matchLink } from './matchLink';\nimport type { AutoLinkOptions } from 'roosterjs-content-model-types';\n\nconst COMMON_REGEX = `[\\s]*[a-zA-Z0-9+][\\s]*`;\nconst TELEPHONE_REGEX = `(T|t)el:${COMMON_REGEX}`;\nconst MAILTO_REGEX = `(M|m)ailto:${COMMON_REGEX}`;\n\n/**\n * @internal\n */\nexport function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined {\n const { autoLink, autoMailto, autoTel } = autoLinkOptions ?? {};\n const linkMatch = autoLink ? matchLink(text)?.normalizedUrl : undefined;\n const telMatch = autoTel ? matchTel(text) : undefined;\n const mailtoMatch = autoMailto ? matchMailTo(text) : undefined;\n\n return linkMatch || telMatch || mailtoMatch;\n}\n\nfunction matchTel(text: string) {\n return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n\nfunction matchMailTo(text: string) {\n return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { AutoLinkOptions, ContentModelText, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
4
+ * When the whole text segment if of a link, promote the whole segment.
5
+ * When the text segment ends with a link format, split the segment and promote the second part
6
+ * When link is in middle of the text segment, no action.
7
+ * This is mainly used for doing auto link when there is a link before cursor
8
+ * @param segment The text segment to search link text from
9
+ * @param paragraph Parent paragraph of the segment
10
+ * @param options Options of auto link
11
+ * @returns If a link is promoted, return this segment. Otherwise return null
12
+ */
13
+ export declare function promoteLink(segment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, autoLinkOptions: AutoLinkOptions): ContentModelText | null;
@@ -0,0 +1,35 @@
1
+ define(["require", "exports", "./getLinkUrl", "../../publicApi/segment/splitTextSegment"], function (require, exports, getLinkUrl_1, splitTextSegment_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.promoteLink = void 0;
5
+ /**
6
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
7
+ * When the whole text segment if of a link, promote the whole segment.
8
+ * When the text segment ends with a link format, split the segment and promote the second part
9
+ * When link is in middle of the text segment, no action.
10
+ * This is mainly used for doing auto link when there is a link before cursor
11
+ * @param segment The text segment to search link text from
12
+ * @param paragraph Parent paragraph of the segment
13
+ * @param options Options of auto link
14
+ * @returns If a link is promoted, return this segment. Otherwise return null
15
+ */
16
+ function promoteLink(segment, paragraph, autoLinkOptions) {
17
+ var link = segment.text.split(' ').pop();
18
+ var url = link === null || link === void 0 ? void 0 : link.trim();
19
+ var linkUrl = undefined;
20
+ if (url && link && (linkUrl = (0, getLinkUrl_1.getLinkUrl)(url, autoLinkOptions))) {
21
+ var linkSegment = (0, splitTextSegment_1.splitTextSegment)(segment, paragraph, segment.text.length - link.trimLeft().length, segment.text.trimRight().length);
22
+ linkSegment.link = {
23
+ format: {
24
+ href: linkUrl,
25
+ underline: true,
26
+ },
27
+ dataset: {},
28
+ };
29
+ return linkSegment;
30
+ }
31
+ return null;
32
+ }
33
+ exports.promoteLink = promoteLink;
34
+ });
35
+ //# sourceMappingURL=promoteLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promoteLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts"],"names":[],"mappings":";;;;IAQA;;;;;;;;;;OAUG;IACH,SAAgB,WAAW,CACvB,OAAyB,EACzB,SAA8C,EAC9C,eAAgC;QAEhC,IAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QAC3C,IAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;QACzB,IAAI,OAAO,GAAuB,SAAS,CAAC;QAE5C,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,GAAG,IAAA,uBAAU,EAAC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE;YAC7D,IAAM,WAAW,GAAG,IAAA,mCAAgB,EAChC,OAAO,EACP,SAAS,EACT,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EAC5C,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAClC,CAAC;YACF,WAAW,CAAC,IAAI,GAAG;gBACf,MAAM,EAAE;oBACJ,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,IAAI;iBAClB;gBACD,OAAO,EAAE,EAAE;aACd,CAAC;YAEF,OAAO,WAAW,CAAC;SACtB;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IA5BD,kCA4BC","sourcesContent":["import { getLinkUrl } from './getLinkUrl';\nimport { splitTextSegment } from '../../publicApi/segment/splitTextSegment';\nimport type {\n AutoLinkOptions,\n ContentModelText,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.\n * When the whole text segment if of a link, promote the whole segment.\n * When the text segment ends with a link format, split the segment and promote the second part\n * When link is in middle of the text segment, no action.\n * This is mainly used for doing auto link when there is a link before cursor\n * @param segment The text segment to search link text from\n * @param paragraph Parent paragraph of the segment\n * @param options Options of auto link\n * @returns If a link is promoted, return this segment. Otherwise return null\n */\nexport function promoteLink(\n segment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n autoLinkOptions: AutoLinkOptions\n): ContentModelText | null {\n const link = segment.text.split(' ').pop();\n const url = link?.trim();\n let linkUrl: string | undefined = undefined;\n\n if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) {\n const linkSegment = splitTextSegment(\n segment,\n paragraph,\n segment.text.length - link.trimLeft().length,\n segment.text.trimRight().length\n );\n linkSegment.link = {\n format: {\n href: linkUrl,\n underline: true,\n },\n dataset: {},\n };\n\n return linkSegment;\n }\n\n return null;\n}\n"]}
@@ -56,4 +56,5 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
56
56
  export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
57
57
  export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
+ export { promoteLink } from './modelApi/link/promoteLink';
59
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
package/lib-mjs/index.js CHANGED
@@ -56,5 +56,6 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
56
56
  export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
57
57
  export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
+ export { promoteLink } from './modelApi/link/promoteLink';
59
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
60
61
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content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+C,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,mDAAmD,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0DAA0D,CAAC;AAClH,OAAO,EAAE,iCAAiC,EAAE,MAAM,qDAAqD,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,WAAW,EA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,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,mDAAmD,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0DAA0D,CAAC;AAClH,OAAO,EAAE,iCAAiC,EAAE,MAAM,qDAAqD,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
@@ -0,0 +1,5 @@
1
+ import type { AutoLinkOptions } from 'roosterjs-content-model-types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined;
@@ -0,0 +1,22 @@
1
+ import { matchLink } from './matchLink';
2
+ var COMMON_REGEX = "[s]*[a-zA-Z0-9+][s]*";
3
+ var TELEPHONE_REGEX = "(T|t)el:" + COMMON_REGEX;
4
+ var MAILTO_REGEX = "(M|m)ailto:" + COMMON_REGEX;
5
+ /**
6
+ * @internal
7
+ */
8
+ export function getLinkUrl(text, autoLinkOptions) {
9
+ var _a;
10
+ var _b = autoLinkOptions !== null && autoLinkOptions !== void 0 ? autoLinkOptions : {}, autoLink = _b.autoLink, autoMailto = _b.autoMailto, autoTel = _b.autoTel;
11
+ var linkMatch = autoLink ? (_a = matchLink(text)) === null || _a === void 0 ? void 0 : _a.normalizedUrl : undefined;
12
+ var telMatch = autoTel ? matchTel(text) : undefined;
13
+ var mailtoMatch = autoMailto ? matchMailTo(text) : undefined;
14
+ return linkMatch || telMatch || mailtoMatch;
15
+ }
16
+ function matchTel(text) {
17
+ return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;
18
+ }
19
+ function matchMailTo(text) {
20
+ return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;
21
+ }
22
+ //# sourceMappingURL=getLinkUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLinkUrl.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/getLinkUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,IAAM,YAAY,GAAG,sBAAwB,CAAC;AAC9C,IAAM,eAAe,GAAG,aAAW,YAAc,CAAC;AAClD,IAAM,YAAY,GAAG,gBAAc,YAAc,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,eAAiC;;IAChE,IAAA,KAAoC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,EAAE,EAAvD,QAAQ,cAAA,EAAE,UAAU,gBAAA,EAAE,OAAO,aAA0B,CAAC;IAChE,IAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAA,SAAS,CAAC,IAAI,CAAC,0CAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,IAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtD,IAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE/D,OAAO,SAAS,IAAI,QAAQ,IAAI,WAAW,CAAC;AAChD,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9E,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC7B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3E,CAAC","sourcesContent":["import { matchLink } from './matchLink';\nimport type { AutoLinkOptions } from 'roosterjs-content-model-types';\n\nconst COMMON_REGEX = `[\\s]*[a-zA-Z0-9+][\\s]*`;\nconst TELEPHONE_REGEX = `(T|t)el:${COMMON_REGEX}`;\nconst MAILTO_REGEX = `(M|m)ailto:${COMMON_REGEX}`;\n\n/**\n * @internal\n */\nexport function getLinkUrl(text: string, autoLinkOptions?: AutoLinkOptions): string | undefined {\n const { autoLink, autoMailto, autoTel } = autoLinkOptions ?? {};\n const linkMatch = autoLink ? matchLink(text)?.normalizedUrl : undefined;\n const telMatch = autoTel ? matchTel(text) : undefined;\n const mailtoMatch = autoMailto ? matchMailTo(text) : undefined;\n\n return linkMatch || telMatch || mailtoMatch;\n}\n\nfunction matchTel(text: string) {\n return text.match(TELEPHONE_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n\nfunction matchMailTo(text: string) {\n return text.match(MAILTO_REGEX) ? text.toLocaleLowerCase() : undefined;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { AutoLinkOptions, ContentModelText, ShallowMutableContentModelParagraph } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
4
+ * When the whole text segment if of a link, promote the whole segment.
5
+ * When the text segment ends with a link format, split the segment and promote the second part
6
+ * When link is in middle of the text segment, no action.
7
+ * This is mainly used for doing auto link when there is a link before cursor
8
+ * @param segment The text segment to search link text from
9
+ * @param paragraph Parent paragraph of the segment
10
+ * @param options Options of auto link
11
+ * @returns If a link is promoted, return this segment. Otherwise return null
12
+ */
13
+ export declare function promoteLink(segment: ContentModelText, paragraph: ShallowMutableContentModelParagraph, autoLinkOptions: AutoLinkOptions): ContentModelText | null;
@@ -0,0 +1,31 @@
1
+ import { getLinkUrl } from './getLinkUrl';
2
+ import { splitTextSegment } from '../../publicApi/segment/splitTextSegment';
3
+ /**
4
+ * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.
5
+ * When the whole text segment if of a link, promote the whole segment.
6
+ * When the text segment ends with a link format, split the segment and promote the second part
7
+ * When link is in middle of the text segment, no action.
8
+ * This is mainly used for doing auto link when there is a link before cursor
9
+ * @param segment The text segment to search link text from
10
+ * @param paragraph Parent paragraph of the segment
11
+ * @param options Options of auto link
12
+ * @returns If a link is promoted, return this segment. Otherwise return null
13
+ */
14
+ export function promoteLink(segment, paragraph, autoLinkOptions) {
15
+ var link = segment.text.split(' ').pop();
16
+ var url = link === null || link === void 0 ? void 0 : link.trim();
17
+ var linkUrl = undefined;
18
+ if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) {
19
+ var linkSegment = splitTextSegment(segment, paragraph, segment.text.length - link.trimLeft().length, segment.text.trimRight().length);
20
+ linkSegment.link = {
21
+ format: {
22
+ href: linkUrl,
23
+ underline: true,
24
+ },
25
+ dataset: {},
26
+ };
27
+ return linkSegment;
28
+ }
29
+ return null;
30
+ }
31
+ //# sourceMappingURL=promoteLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promoteLink.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAO5E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACvB,OAAyB,EACzB,SAA8C,EAC9C,eAAgC;IAEhC,IAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IAC3C,IAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;IACzB,IAAI,OAAO,GAAuB,SAAS,CAAC;IAE5C,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE;QAC7D,IAAM,WAAW,GAAG,gBAAgB,CAChC,OAAO,EACP,SAAS,EACT,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,MAAM,EAC5C,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,CAClC,CAAC;QACF,WAAW,CAAC,IAAI,GAAG;YACf,MAAM,EAAE;gBACJ,IAAI,EAAE,OAAO;gBACb,SAAS,EAAE,IAAI;aAClB;YACD,OAAO,EAAE,EAAE;SACd,CAAC;QAEF,OAAO,WAAW,CAAC;KACtB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["import { getLinkUrl } from './getLinkUrl';\nimport { splitTextSegment } from '../../publicApi/segment/splitTextSegment';\nimport type {\n AutoLinkOptions,\n ContentModelText,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Promote the given text segment to a hyper link when the segment text is ending with a valid link format.\n * When the whole text segment if of a link, promote the whole segment.\n * When the text segment ends with a link format, split the segment and promote the second part\n * When link is in middle of the text segment, no action.\n * This is mainly used for doing auto link when there is a link before cursor\n * @param segment The text segment to search link text from\n * @param paragraph Parent paragraph of the segment\n * @param options Options of auto link\n * @returns If a link is promoted, return this segment. Otherwise return null\n */\nexport function promoteLink(\n segment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n autoLinkOptions: AutoLinkOptions\n): ContentModelText | null {\n const link = segment.text.split(' ').pop();\n const url = link?.trim();\n let linkUrl: string | undefined = undefined;\n\n if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) {\n const linkSegment = splitTextSegment(\n segment,\n paragraph,\n segment.text.length - link.trimLeft().length,\n segment.text.trimRight().length\n );\n linkSegment.link = {\n format: {\n href: linkUrl,\n underline: true,\n },\n dataset: {},\n };\n\n return linkSegment;\n }\n\n return null;\n}\n"]}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.11.2",
7
- "roosterjs-content-model-types": "^9.11.2"
6
+ "roosterjs-content-model-dom": "^9.13.0",
7
+ "roosterjs-content-model-types": "^9.13.0"
8
8
  },
9
- "version": "9.11.2",
9
+ "version": "9.13.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",