roosterjs-content-model-api 9.37.0 → 9.38.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
@@ -60,3 +60,4 @@ export { matchLink } from './modelApi/link/matchLink';
60
60
  export { promoteLink } from './modelApi/link/promoteLink';
61
61
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
62
62
  export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
63
+ export { adjustWordSelection } from './modelApi/selection/adjustWordSelection';
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.createEditorContextForEntity = 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.queryContentModelBlocks = exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = void 0;
4
+ exports.adjustWordSelection = exports.queryContentModelBlocks = exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = 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");
@@ -126,4 +126,6 @@ var getListAnnounceData_1 = require("./modelApi/list/getListAnnounceData");
126
126
  Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
127
127
  var queryContentModelBlocks_1 = require("./modelApi/common/queryContentModelBlocks");
128
128
  Object.defineProperty(exports, "queryContentModelBlocks", { enumerable: true, get: function () { return queryContentModelBlocks_1.queryContentModelBlocks; } });
129
+ var adjustWordSelection_1 = require("./modelApi/selection/adjustWordSelection");
130
+ Object.defineProperty(exports, "adjustWordSelection", { enumerable: true, get: function () { return adjustWordSelection_1.adjustWordSelection; } });
129
131
  //# 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,6DAA4D;A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;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,+FAA8F;AAArF,4IAAA,4BAA4B,OAAA;AACrC,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;AAC5B,qFAAoF;AAA3E,kIAAA,uBAAuB,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 { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\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';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\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;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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 { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\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';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\nexport { adjustWordSelection } from './modelApi/selection/adjustWordSelection';\n"]}
@@ -1,5 +1,8 @@
1
1
  import type { ReadonlyContentModelDocument, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * Return specific word segment where the selection marker is located
4
+ * @param model The model document
5
+ * @param marker The selection marker
6
+ * @returns An array of segments that form the word where the selection marker is located
4
7
  */
5
8
  export declare function adjustWordSelection(model: ReadonlyContentModelDocument, marker: ShallowMutableContentModelSegment): ShallowMutableContentModelSegment[];
@@ -4,7 +4,10 @@ exports.adjustWordSelection = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
6
  /**
7
- * @internal
7
+ * Return specific word segment where the selection marker is located
8
+ * @param model The model document
9
+ * @param marker The selection marker
10
+ * @returns An array of segments that form the word where the selection marker is located
8
11
  */
9
12
  function adjustWordSelection(model, marker) {
10
13
  var markerBlock;
@@ -1 +1 @@
1
- {"version":3,"file":"adjustWordSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/selection/adjustWordSelection.ts"],"names":[],"mappings":";;;;AAAA,2EAMqC;AAQrC;;GAEG;AACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,MAAyC;IAEzC,IAAI,WAA4D,CAAC;IAEjE,IAAA,+CAAiB,EAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;QAC5C,0CAA0C;QAC1C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,KAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;YACnF,WAAW,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAM,YAAY,GAAG,WAAW,CAAC,CAAC,oDAAK,WAAW,CAAC,QAAQ,UAAE,CAAC,CAAC,SAAS,CAAC;IAEzE,IAAI,YAAY,IAAI,WAAW,EAAE;QAC7B,IAAM,QAAQ,GAAwC,EAAE,CAAC;QACzD,IAAI,oBAAoB,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,C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YACvC,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,IAAA,2CAAa,EAAC,IAAI,CAAC,IAAI,IAAA,qCAAO,EAAC,IAAI,CAAC,EAAE;gBACtC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM;aACT;SACJ;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CACrB,QAA6C,EAC7C,WAAuC,EACvC,KAAa,EACb,KAAa;IAEb,IAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAC9B,IAAM,cAAc,GAAG,IAAA,wCAAU,EAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EACxB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,IAAM,eAAe,GAAG,IAAA,wCAAU,EAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import {\n createText,\n isPunctuation,\n isSpace,\n iterateSelections,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelText,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function adjustWordSelection(\n model: ReadonlyContentModelDocument,\n marker: ShallowMutableContentModelSegment\n): ShallowMutableContentModelSegment[] {\n let markerBlock: ShallowMutableContentModelParagraph | undefined;\n\n iterateSelections(model, (_, __, block, segments) => {\n //Find the block with the selection marker\n if (block?.blockType == 'Paragraph' && segments?.length == 1 && segments[0] == marker) {\n markerBlock = mutateBlock(block);\n }\n return true;\n });\n\n const tempSegments = markerBlock ? [...markerBlock.segments] : undefined;\n\n if (tempSegments && markerBlock) {\n const segments: ShallowMutableContentModelSegment[] = [];\n let markerSelectionIndex = tempSegments.indexOf(marker);\n for (let i = markerSelectionIndex - 1; i >= 0; i--) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, false /*moveRightward*/);\n if (found > -1) {\n if (found == currentSegment.text.length) {\n break;\n }\n\n splitTextSegment(tempSegments, currentSegment, i, found);\n\n segments.push(tempSegments[i + 1]);\n\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n markerSelectionIndex = tempSegments.indexOf(marker);\n segments.push(marker);\n\n // Marker is at start of word\n if (segments.length <= 1) {\n return segments;\n }\n\n for (let i = markerSelectionIndex + 1; i < tempSegments.length; i++) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, true /*moveRightward*/);\n if (found > -1) {\n if (found == 0) {\n break;\n }\n splitTextSegment(tempSegments, currentSegment, i, found);\n segments.push(tempSegments[i]);\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n // Marker is at end of word\n if (segments[segments.length - 1] == marker) {\n return [marker];\n }\n\n markerBlock.segments = tempSegments;\n return segments;\n } else {\n return [marker];\n }\n}\n\n/*\n// These are unicode characters mostly from the Category Space Separator (Zs)\nhttps://unicode.org/Public/UNIDATA/Scripts.txt\n\n\\u2000 = EN QUAD\n\\u2009 = THIN SPACE\n\\u200a = HAIR SPACE\n​\\u200b = ZERO WIDTH SPACE\n​\\u202f = NARROW NO-BREAK SPACE\n\\u205f​ = MEDIUM MATHEMATICAL SPACE\n\\u3000 = IDEOGRAPHIC SPACE\n*/\nfunction findDelimiter(segment: ContentModelText, moveRightward: boolean): number {\n const word = segment.text;\n let offset = -1;\n if (moveRightward) {\n for (let i = 0; i < word.length; i++) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i;\n break;\n }\n }\n } else {\n for (let i = word.length - 1; i >= 0; i--) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i + 1;\n break;\n }\n }\n }\n return offset;\n}\n\nfunction splitTextSegment(\n segments: ShallowMutableContentModelSegment[],\n textSegment: Readonly<ContentModelText>,\n index: number,\n found: number\n) {\n const text = textSegment.text;\n const newSegmentLeft = createText(\n text.substring(0, found),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n const newSegmentRight = createText(\n text.substring(found, text.length),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n segments.splice(index, 1, newSegmentLeft, newSegmentRight);\n}\n"]}
1
+ {"version":3,"file":"adjustWordSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/selection/adjustWordSelection.ts"],"names":[],"mappings":";;;;AAAA,2EAMqC;AAQrC;;;;;GAKG;AACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,MAAyC;IAEzC,IAAI,WAA4D,CAAC;IAEjE,IAAA,+CAAiB,EAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;QAC5C,0CAA0C;QAC1C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,KAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;YACnF,WAAW,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAM,YAAY,GAAG,WAAW,CAAC,CAAC,oDAAK,WAAW,CAAC,QAAQ,UAAE,CAAC,CAAC,SAAS,CAAC;IAEzE,IAAI,YAAY,IAAI,W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;SAAM;QACH,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YACvC,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,IAAA,2CAAa,EAAC,IAAI,CAAC,IAAI,IAAA,qCAAO,EAAC,IAAI,CAAC,EAAE;gBACtC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM;aACT;SACJ;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CACrB,QAA6C,EAC7C,WAAuC,EACvC,KAAa,EACb,KAAa;IAEb,IAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAC9B,IAAM,cAAc,GAAG,IAAA,wCAAU,EAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EACxB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,IAAM,eAAe,GAAG,IAAA,wCAAU,EAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import {\n createText,\n isPunctuation,\n isSpace,\n iterateSelections,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelText,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Return specific word segment where the selection marker is located\n * @param model The model document\n * @param marker The selection marker\n * @returns An array of segments that form the word where the selection marker is located\n */\nexport function adjustWordSelection(\n model: ReadonlyContentModelDocument,\n marker: ShallowMutableContentModelSegment\n): ShallowMutableContentModelSegment[] {\n let markerBlock: ShallowMutableContentModelParagraph | undefined;\n\n iterateSelections(model, (_, __, block, segments) => {\n //Find the block with the selection marker\n if (block?.blockType == 'Paragraph' && segments?.length == 1 && segments[0] == marker) {\n markerBlock = mutateBlock(block);\n }\n return true;\n });\n\n const tempSegments = markerBlock ? [...markerBlock.segments] : undefined;\n\n if (tempSegments && markerBlock) {\n const segments: ShallowMutableContentModelSegment[] = [];\n let markerSelectionIndex = tempSegments.indexOf(marker);\n for (let i = markerSelectionIndex - 1; i >= 0; i--) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, false /*moveRightward*/);\n if (found > -1) {\n if (found == currentSegment.text.length) {\n break;\n }\n\n splitTextSegment(tempSegments, currentSegment, i, found);\n\n segments.push(tempSegments[i + 1]);\n\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n markerSelectionIndex = tempSegments.indexOf(marker);\n segments.push(marker);\n\n // Marker is at start of word\n if (segments.length <= 1) {\n return segments;\n }\n\n for (let i = markerSelectionIndex + 1; i < tempSegments.length; i++) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, true /*moveRightward*/);\n if (found > -1) {\n if (found == 0) {\n break;\n }\n splitTextSegment(tempSegments, currentSegment, i, found);\n segments.push(tempSegments[i]);\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n // Marker is at end of word\n if (segments[segments.length - 1] == marker) {\n return [marker];\n }\n\n markerBlock.segments = tempSegments;\n return segments;\n } else {\n return [marker];\n }\n}\n\n/*\n// These are unicode characters mostly from the Category Space Separator (Zs)\nhttps://unicode.org/Public/UNIDATA/Scripts.txt\n\n\\u2000 = EN QUAD\n\\u2009 = THIN SPACE\n\\u200a = HAIR SPACE\n​\\u200b = ZERO WIDTH SPACE\n​\\u202f = NARROW NO-BREAK SPACE\n\\u205f​ = MEDIUM MATHEMATICAL SPACE\n\\u3000 = IDEOGRAPHIC SPACE\n*/\nfunction findDelimiter(segment: ContentModelText, moveRightward: boolean): number {\n const word = segment.text;\n let offset = -1;\n if (moveRightward) {\n for (let i = 0; i < word.length; i++) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i;\n break;\n }\n }\n } else {\n for (let i = word.length - 1; i >= 0; i--) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i + 1;\n break;\n }\n }\n }\n return offset;\n}\n\nfunction splitTextSegment(\n segments: ShallowMutableContentModelSegment[],\n textSegment: Readonly<ContentModelText>,\n index: number,\n found: number\n) {\n const text = textSegment.text;\n const newSegmentLeft = createText(\n text.substring(0, found),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n const newSegmentRight = createText(\n text.substring(found, text.length),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n segments.splice(index, 1, newSegmentLeft, newSegmentRight);\n}\n"]}
@@ -60,3 +60,4 @@ export { matchLink } from './modelApi/link/matchLink';
60
60
  export { promoteLink } from './modelApi/link/promoteLink';
61
61
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
62
62
  export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
63
+ export { adjustWordSelection } from './modelApi/selection/adjustWordSelection';
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/createEditorContextForEntity", "./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", "./modelApi/common/queryContentModelBlocks"], 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, createEditorContextForEntity_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, queryContentModelBlocks_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/createEditorContextForEntity", "./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", "./modelApi/common/queryContentModelBlocks", "./modelApi/selection/adjustWordSelection"], 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, createEditorContextForEntity_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, queryContentModelBlocks_1, adjustWordSelection_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.queryContentModelBlocks = 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.createEditorContextForEntity = 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.adjustWordSelection = exports.queryContentModelBlocks = 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.createEditorContextForEntity = 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; } });
@@ -64,5 +64,6 @@ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/tabl
64
64
  Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
65
65
  Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
66
66
  Object.defineProperty(exports, "queryContentModelBlocks", { enumerable: true, get: function () { return queryContentModelBlocks_1.queryContentModelBlocks; } });
67
+ Object.defineProperty(exports, "adjustWordSelection", { enumerable: true, get: function () { return adjustWordSelection_1.adjustWordSelection; } });
67
68
  });
68
69
  //# 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,4IAAA,4BAA4B,OAAA;IAC5B,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;IACnB,kIAAA,uBAAuB,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 { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\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';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\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,4IAAA,4BAA4B,OAAA;IAC5B,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;IACnB,kIAAA,uBAAuB,OAAA;IACvB,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 { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\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';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\nexport { adjustWordSelection } from './modelApi/selection/adjustWordSelection';\n"]}
@@ -1,5 +1,8 @@
1
1
  import type { ReadonlyContentModelDocument, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * Return specific word segment where the selection marker is located
4
+ * @param model The model document
5
+ * @param marker The selection marker
6
+ * @returns An array of segments that form the word where the selection marker is located
4
7
  */
5
8
  export declare function adjustWordSelection(model: ReadonlyContentModelDocument, marker: ShallowMutableContentModelSegment): ShallowMutableContentModelSegment[];
@@ -3,7 +3,10 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.adjustWordSelection = void 0;
5
5
  /**
6
- * @internal
6
+ * Return specific word segment where the selection marker is located
7
+ * @param model The model document
8
+ * @param marker The selection marker
9
+ * @returns An array of segments that form the word where the selection marker is located
7
10
  */
8
11
  function adjustWordSelection(model, marker) {
9
12
  var markerBlock;
@@ -1 +1 @@
1
- {"version":3,"file":"adjustWordSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/selection/adjustWordSelection.ts"],"names":[],"mappings":";;;;IAcA;;OAEG;IACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,MAAyC;QAEzC,IAAI,WAA4D,CAAC;QAEjE,IAAA,+CAAiB,EAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;YAC5C,0CAA0C;YAC1C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,KAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;gBACnF,WAAW,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,CAAC;aACpC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,IAAM,YAAY,GAAG,WAAW,CAAC,CAAC,oDAAK,WAAW,CAAC,QAAQ,UAAE,CAAC,CAAC,SAAS,CAAC;QAEzE,IAAI,YAAY,IAAI,WAAW,EAAE;YAC7B,IAAM,QAAQ,GAAwC,EAAE,CAAC;YACzD,IAAI,oBAAoB,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACxD,KAAK,IAAI,CAAC,GAAG,oBAAoB,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;gBAChD,IAAM,cAAc,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBACvC,IAAI,cAAc,CAAC,WAAW,IAAI,MAAM,EAAE;oBACtC,IAAM,KAAK,GAAG,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;oBACrE,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;wBACZ,IAAI,KAAK,IAAI,cAAc,CAAC,IAAI,CAAC,MAA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AC9B,IAAM,cAAc,GAAG,IAAA,wCAAU,EAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EACxB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;QACF,IAAM,eAAe,GAAG,IAAA,wCAAU,EAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;QACF,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;IAC/D,CAAC","sourcesContent":["import {\n createText,\n isPunctuation,\n isSpace,\n iterateSelections,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelText,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function adjustWordSelection(\n model: ReadonlyContentModelDocument,\n marker: ShallowMutableContentModelSegment\n): ShallowMutableContentModelSegment[] {\n let markerBlock: ShallowMutableContentModelParagraph | undefined;\n\n iterateSelections(model, (_, __, block, segments) => {\n //Find the block with the selection marker\n if (block?.blockType == 'Paragraph' && segments?.length == 1 && segments[0] == marker) {\n markerBlock = mutateBlock(block);\n }\n return true;\n });\n\n const tempSegments = markerBlock ? [...markerBlock.segments] : undefined;\n\n if (tempSegments && markerBlock) {\n const segments: ShallowMutableContentModelSegment[] = [];\n let markerSelectionIndex = tempSegments.indexOf(marker);\n for (let i = markerSelectionIndex - 1; i >= 0; i--) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, false /*moveRightward*/);\n if (found > -1) {\n if (found == currentSegment.text.length) {\n break;\n }\n\n splitTextSegment(tempSegments, currentSegment, i, found);\n\n segments.push(tempSegments[i + 1]);\n\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n markerSelectionIndex = tempSegments.indexOf(marker);\n segments.push(marker);\n\n // Marker is at start of word\n if (segments.length <= 1) {\n return segments;\n }\n\n for (let i = markerSelectionIndex + 1; i < tempSegments.length; i++) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, true /*moveRightward*/);\n if (found > -1) {\n if (found == 0) {\n break;\n }\n splitTextSegment(tempSegments, currentSegment, i, found);\n segments.push(tempSegments[i]);\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n // Marker is at end of word\n if (segments[segments.length - 1] == marker) {\n return [marker];\n }\n\n markerBlock.segments = tempSegments;\n return segments;\n } else {\n return [marker];\n }\n}\n\n/*\n// These are unicode characters mostly from the Category Space Separator (Zs)\nhttps://unicode.org/Public/UNIDATA/Scripts.txt\n\n\\u2000 = EN QUAD\n\\u2009 = THIN SPACE\n\\u200a = HAIR SPACE\n​\\u200b = ZERO WIDTH SPACE\n​\\u202f = NARROW NO-BREAK SPACE\n\\u205f​ = MEDIUM MATHEMATICAL SPACE\n\\u3000 = IDEOGRAPHIC SPACE\n*/\nfunction findDelimiter(segment: ContentModelText, moveRightward: boolean): number {\n const word = segment.text;\n let offset = -1;\n if (moveRightward) {\n for (let i = 0; i < word.length; i++) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i;\n break;\n }\n }\n } else {\n for (let i = word.length - 1; i >= 0; i--) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i + 1;\n break;\n }\n }\n }\n return offset;\n}\n\nfunction splitTextSegment(\n segments: ShallowMutableContentModelSegment[],\n textSegment: Readonly<ContentModelText>,\n index: number,\n found: number\n) {\n const text = textSegment.text;\n const newSegmentLeft = createText(\n text.substring(0, found),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n const newSegmentRight = createText(\n text.substring(found, text.length),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n segments.splice(index, 1, newSegmentLeft, newSegmentRight);\n}\n"]}
1
+ {"version":3,"file":"adjustWordSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/selection/adjustWordSelection.ts"],"names":[],"mappings":";;;;IAcA;;;;;OAKG;IACH,SAAgB,mBAAmB,CAC/B,KAAmC,EACnC,MAAyC;QAEzC,IAAI,WAA4D,CAAC;QAEjE,IAAA,+CAAiB,EAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;YAC5C,0CAA0C;YAC1C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,KAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;gBACnF,WAAW,GAAG,IAAA,yCAAW,EAAC,KAAK,CAAC,CAAC;aACpC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;QAEH,IAAM,YAAY,GAAG,WAAW,CAAC,CAAC,oDAAK,WAAW,CAAC,QAAQ,UAAE,CAAC,CAAC,SAAS,CAAC;QAEzE,IAAI,YAAY,IAAI,WAAW,EAAE;YAC7B,IAAM,QAAQ,GAAwC,EAAE,CAAC;YACzD,IAAI,oBAAoB,GAAG,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACxD,KAAK,IAAI,CAAC,GAAG,oBAAoB,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;gBAChD,IAAM,cAAc,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBACvC,IAAI,cAAc,CAAC,WAAW,IAAI,MAAM,EAAE;oBACtC,IAAM,KAAK,GAAG,aAAa,CAAC,cAAc,EAAE,KAAK,CAA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IAED,SAAS,gBAAgB,CACrB,QAA6C,EAC7C,WAAuC,EACvC,KAAa,EACb,KAAa;QAEb,IAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;QAC9B,IAAM,cAAc,GAAG,IAAA,wCAAU,EAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EACxB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;QACF,IAAM,eAAe,GAAG,IAAA,wCAAU,EAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;QACF,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;IAC/D,CAAC","sourcesContent":["import {\n createText,\n isPunctuation,\n isSpace,\n iterateSelections,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelText,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Return specific word segment where the selection marker is located\n * @param model The model document\n * @param marker The selection marker\n * @returns An array of segments that form the word where the selection marker is located\n */\nexport function adjustWordSelection(\n model: ReadonlyContentModelDocument,\n marker: ShallowMutableContentModelSegment\n): ShallowMutableContentModelSegment[] {\n let markerBlock: ShallowMutableContentModelParagraph | undefined;\n\n iterateSelections(model, (_, __, block, segments) => {\n //Find the block with the selection marker\n if (block?.blockType == 'Paragraph' && segments?.length == 1 && segments[0] == marker) {\n markerBlock = mutateBlock(block);\n }\n return true;\n });\n\n const tempSegments = markerBlock ? [...markerBlock.segments] : undefined;\n\n if (tempSegments && markerBlock) {\n const segments: ShallowMutableContentModelSegment[] = [];\n let markerSelectionIndex = tempSegments.indexOf(marker);\n for (let i = markerSelectionIndex - 1; i >= 0; i--) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, false /*moveRightward*/);\n if (found > -1) {\n if (found == currentSegment.text.length) {\n break;\n }\n\n splitTextSegment(tempSegments, currentSegment, i, found);\n\n segments.push(tempSegments[i + 1]);\n\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n markerSelectionIndex = tempSegments.indexOf(marker);\n segments.push(marker);\n\n // Marker is at start of word\n if (segments.length <= 1) {\n return segments;\n }\n\n for (let i = markerSelectionIndex + 1; i < tempSegments.length; i++) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, true /*moveRightward*/);\n if (found > -1) {\n if (found == 0) {\n break;\n }\n splitTextSegment(tempSegments, currentSegment, i, found);\n segments.push(tempSegments[i]);\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n // Marker is at end of word\n if (segments[segments.length - 1] == marker) {\n return [marker];\n }\n\n markerBlock.segments = tempSegments;\n return segments;\n } else {\n return [marker];\n }\n}\n\n/*\n// These are unicode characters mostly from the Category Space Separator (Zs)\nhttps://unicode.org/Public/UNIDATA/Scripts.txt\n\n\\u2000 = EN QUAD\n\\u2009 = THIN SPACE\n\\u200a = HAIR SPACE\n​\\u200b = ZERO WIDTH SPACE\n​\\u202f = NARROW NO-BREAK SPACE\n\\u205f​ = MEDIUM MATHEMATICAL SPACE\n\\u3000 = IDEOGRAPHIC SPACE\n*/\nfunction findDelimiter(segment: ContentModelText, moveRightward: boolean): number {\n const word = segment.text;\n let offset = -1;\n if (moveRightward) {\n for (let i = 0; i < word.length; i++) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i;\n break;\n }\n }\n } else {\n for (let i = word.length - 1; i >= 0; i--) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i + 1;\n break;\n }\n }\n }\n return offset;\n}\n\nfunction splitTextSegment(\n segments: ShallowMutableContentModelSegment[],\n textSegment: Readonly<ContentModelText>,\n index: number,\n found: number\n) {\n const text = textSegment.text;\n const newSegmentLeft = createText(\n text.substring(0, found),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n const newSegmentRight = createText(\n text.substring(found, text.length),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n segments.splice(index, 1, newSegmentLeft, newSegmentRight);\n}\n"]}
@@ -60,3 +60,4 @@ export { matchLink } from './modelApi/link/matchLink';
60
60
  export { promoteLink } from './modelApi/link/promoteLink';
61
61
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
62
62
  export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
63
+ export { adjustWordSelection } from './modelApi/selection/adjustWordSelection';
package/lib-mjs/index.js CHANGED
@@ -60,4 +60,5 @@ export { matchLink } from './modelApi/link/matchLink';
60
60
  export { promoteLink } from './modelApi/link/promoteLink';
61
61
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
62
62
  export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
63
+ export { adjustWordSelection } from './modelApi/selection/adjustWordSelection';
63
64
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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,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E,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;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,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 { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\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';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\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,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC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E,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,4BAA4B,EAAE,MAAM,gDAAgD,CAAC;AAC9F,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;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,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 { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';\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';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\nexport { adjustWordSelection } from './modelApi/selection/adjustWordSelection';\n"]}
@@ -1,5 +1,8 @@
1
1
  import type { ReadonlyContentModelDocument, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
2
2
  /**
3
- * @internal
3
+ * Return specific word segment where the selection marker is located
4
+ * @param model The model document
5
+ * @param marker The selection marker
6
+ * @returns An array of segments that form the word where the selection marker is located
4
7
  */
5
8
  export declare function adjustWordSelection(model: ReadonlyContentModelDocument, marker: ShallowMutableContentModelSegment): ShallowMutableContentModelSegment[];
@@ -1,7 +1,10 @@
1
1
  import { __read, __spreadArray } from "tslib";
2
2
  import { createText, isPunctuation, isSpace, iterateSelections, mutateBlock, } from 'roosterjs-content-model-dom';
3
3
  /**
4
- * @internal
4
+ * Return specific word segment where the selection marker is located
5
+ * @param model The model document
6
+ * @param marker The selection marker
7
+ * @returns An array of segments that form the word where the selection marker is located
5
8
  */
6
9
  export function adjustWordSelection(model, marker) {
7
10
  var markerBlock;
@@ -1 +1 @@
1
- {"version":3,"file":"adjustWordSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/selection/adjustWordSelection.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,UAAU,EACV,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,WAAW,GACd,MAAM,6BAA6B,CAAC;AAQrC;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAAmC,EACnC,MAAyC;IAEzC,IAAI,WAA4D,CAAC;IAEjE,iBAAiB,CAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;QAC5C,0CAA0C;QAC1C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,KAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;YACnF,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAM,YAAY,GAAG,WAAW,CAAC,CAAC,0BAAK,WAAW,CAAC,QAAQ,UAAE,CAAC,CAAC,SAAS,CAAC;IAEzE,IAAI,YAAY,IAAI,WAAW,EAAE;QAC7B,IAAM,QAAQ,GAAwC,EAAE,CAAC;QACzD,IAAI,oBAAoB,GAAG,YAAY,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;YACvC,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;gBACtC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM;aACT;SACJ;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CACrB,QAA6C,EAC7C,WAAuC,EACvC,KAAa,EACb,KAAa;IAEb,IAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAC9B,IAAM,cAAc,GAAG,UAAU,CAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EACxB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,IAAM,eAAe,GAAG,UAAU,CAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import {\n createText,\n isPunctuation,\n isSpace,\n iterateSelections,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelText,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function adjustWordSelection(\n model: ReadonlyContentModelDocument,\n marker: ShallowMutableContentModelSegment\n): ShallowMutableContentModelSegment[] {\n let markerBlock: ShallowMutableContentModelParagraph | undefined;\n\n iterateSelections(model, (_, __, block, segments) => {\n //Find the block with the selection marker\n if (block?.blockType == 'Paragraph' && segments?.length == 1 && segments[0] == marker) {\n markerBlock = mutateBlock(block);\n }\n return true;\n });\n\n const tempSegments = markerBlock ? [...markerBlock.segments] : undefined;\n\n if (tempSegments && markerBlock) {\n const segments: ShallowMutableContentModelSegment[] = [];\n let markerSelectionIndex = tempSegments.indexOf(marker);\n for (let i = markerSelectionIndex - 1; i >= 0; i--) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, false /*moveRightward*/);\n if (found > -1) {\n if (found == currentSegment.text.length) {\n break;\n }\n\n splitTextSegment(tempSegments, currentSegment, i, found);\n\n segments.push(tempSegments[i + 1]);\n\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n markerSelectionIndex = tempSegments.indexOf(marker);\n segments.push(marker);\n\n // Marker is at start of word\n if (segments.length <= 1) {\n return segments;\n }\n\n for (let i = markerSelectionIndex + 1; i < tempSegments.length; i++) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, true /*moveRightward*/);\n if (found > -1) {\n if (found == 0) {\n break;\n }\n splitTextSegment(tempSegments, currentSegment, i, found);\n segments.push(tempSegments[i]);\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n // Marker is at end of word\n if (segments[segments.length - 1] == marker) {\n return [marker];\n }\n\n markerBlock.segments = tempSegments;\n return segments;\n } else {\n return [marker];\n }\n}\n\n/*\n// These are unicode characters mostly from the Category Space Separator (Zs)\nhttps://unicode.org/Public/UNIDATA/Scripts.txt\n\n\\u2000 = EN QUAD\n\\u2009 = THIN SPACE\n\\u200a = HAIR SPACE\n​\\u200b = ZERO WIDTH SPACE\n​\\u202f = NARROW NO-BREAK SPACE\n\\u205f​ = MEDIUM MATHEMATICAL SPACE\n\\u3000 = IDEOGRAPHIC SPACE\n*/\nfunction findDelimiter(segment: ContentModelText, moveRightward: boolean): number {\n const word = segment.text;\n let offset = -1;\n if (moveRightward) {\n for (let i = 0; i < word.length; i++) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i;\n break;\n }\n }\n } else {\n for (let i = word.length - 1; i >= 0; i--) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i + 1;\n break;\n }\n }\n }\n return offset;\n}\n\nfunction splitTextSegment(\n segments: ShallowMutableContentModelSegment[],\n textSegment: Readonly<ContentModelText>,\n index: number,\n found: number\n) {\n const text = textSegment.text;\n const newSegmentLeft = createText(\n text.substring(0, found),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n const newSegmentRight = createText(\n text.substring(found, text.length),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n segments.splice(index, 1, newSegmentLeft, newSegmentRight);\n}\n"]}
1
+ {"version":3,"file":"adjustWordSelection.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/selection/adjustWordSelection.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,UAAU,EACV,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,WAAW,GACd,MAAM,6BAA6B,CAAC;AAQrC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAC/B,KAAmC,EACnC,MAAyC;IAEzC,IAAI,WAA4D,CAAC;IAEjE,iBAAiB,CAAC,KAAK,EAAE,UAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ;QAC5C,0CAA0C;QAC1C,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,SAAS,KAAI,WAAW,IAAI,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,KAAI,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE;YACnF,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,IAAM,YAAY,GAAG,WAAW,CAAC,CAAC,0BAAK,WAAW,CAAC,QAAQ,UAAE,CAAC,CAA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SACJ;KACJ;SAAM;QACH,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YACvC,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAErB,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;gBACtC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;gBACf,MAAM;aACT;SACJ;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CACrB,QAA6C,EAC7C,WAAuC,EACvC,KAAa,EACb,KAAa;IAEb,IAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC;IAC9B,IAAM,cAAc,GAAG,UAAU,CAC7B,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EACxB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,IAAM,eAAe,GAAG,UAAU,CAC9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAClC,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,IAAI,CACnB,CAAC;IACF,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import {\n createText,\n isPunctuation,\n isSpace,\n iterateSelections,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelText,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Return specific word segment where the selection marker is located\n * @param model The model document\n * @param marker The selection marker\n * @returns An array of segments that form the word where the selection marker is located\n */\nexport function adjustWordSelection(\n model: ReadonlyContentModelDocument,\n marker: ShallowMutableContentModelSegment\n): ShallowMutableContentModelSegment[] {\n let markerBlock: ShallowMutableContentModelParagraph | undefined;\n\n iterateSelections(model, (_, __, block, segments) => {\n //Find the block with the selection marker\n if (block?.blockType == 'Paragraph' && segments?.length == 1 && segments[0] == marker) {\n markerBlock = mutateBlock(block);\n }\n return true;\n });\n\n const tempSegments = markerBlock ? [...markerBlock.segments] : undefined;\n\n if (tempSegments && markerBlock) {\n const segments: ShallowMutableContentModelSegment[] = [];\n let markerSelectionIndex = tempSegments.indexOf(marker);\n for (let i = markerSelectionIndex - 1; i >= 0; i--) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, false /*moveRightward*/);\n if (found > -1) {\n if (found == currentSegment.text.length) {\n break;\n }\n\n splitTextSegment(tempSegments, currentSegment, i, found);\n\n segments.push(tempSegments[i + 1]);\n\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n markerSelectionIndex = tempSegments.indexOf(marker);\n segments.push(marker);\n\n // Marker is at start of word\n if (segments.length <= 1) {\n return segments;\n }\n\n for (let i = markerSelectionIndex + 1; i < tempSegments.length; i++) {\n const currentSegment = tempSegments[i];\n if (currentSegment.segmentType == 'Text') {\n const found = findDelimiter(currentSegment, true /*moveRightward*/);\n if (found > -1) {\n if (found == 0) {\n break;\n }\n splitTextSegment(tempSegments, currentSegment, i, found);\n segments.push(tempSegments[i]);\n break;\n } else {\n segments.push(tempSegments[i]);\n }\n } else {\n break;\n }\n }\n\n // Marker is at end of word\n if (segments[segments.length - 1] == marker) {\n return [marker];\n }\n\n markerBlock.segments = tempSegments;\n return segments;\n } else {\n return [marker];\n }\n}\n\n/*\n// These are unicode characters mostly from the Category Space Separator (Zs)\nhttps://unicode.org/Public/UNIDATA/Scripts.txt\n\n\\u2000 = EN QUAD\n\\u2009 = THIN SPACE\n\\u200a = HAIR SPACE\n​\\u200b = ZERO WIDTH SPACE\n​\\u202f = NARROW NO-BREAK SPACE\n\\u205f​ = MEDIUM MATHEMATICAL SPACE\n\\u3000 = IDEOGRAPHIC SPACE\n*/\nfunction findDelimiter(segment: ContentModelText, moveRightward: boolean): number {\n const word = segment.text;\n let offset = -1;\n if (moveRightward) {\n for (let i = 0; i < word.length; i++) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i;\n break;\n }\n }\n } else {\n for (let i = word.length - 1; i >= 0; i--) {\n const char = word[i];\n\n if (isPunctuation(char) || isSpace(char)) {\n offset = i + 1;\n break;\n }\n }\n }\n return offset;\n}\n\nfunction splitTextSegment(\n segments: ShallowMutableContentModelSegment[],\n textSegment: Readonly<ContentModelText>,\n index: number,\n found: number\n) {\n const text = textSegment.text;\n const newSegmentLeft = createText(\n text.substring(0, found),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n const newSegmentRight = createText(\n text.substring(found, text.length),\n textSegment.format,\n textSegment.link,\n textSegment.code\n );\n segments.splice(index, 1, newSegmentLeft, newSegmentRight);\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.37.0",
7
- "roosterjs-content-model-types": "^9.37.0"
6
+ "roosterjs-content-model-dom": "^9.38.0",
7
+ "roosterjs-content-model-types": "^9.38.0"
8
8
  },
9
- "version": "9.37.0",
9
+ "version": "9.38.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",