roosterjs-content-model-api 9.27.0 → 9.28.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.
Files changed (34) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.js +4 -2
  3. package/lib/index.js.map +1 -1
  4. package/lib/modelApi/common/queryContentModelBlocks.d.ts +3 -2
  5. package/lib/modelApi/common/queryContentModelBlocks.js +15 -4
  6. package/lib/modelApi/common/queryContentModelBlocks.js.map +1 -1
  7. package/lib/publicApi/utils/createEditorContextForEntity.d.ts +8 -0
  8. package/lib/publicApi/utils/createEditorContextForEntity.js +30 -0
  9. package/lib/publicApi/utils/createEditorContextForEntity.js.map +1 -0
  10. package/lib/publicApi/utils/formatSegmentWithContentModel.js +4 -21
  11. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  12. package/lib-amd/index.d.ts +1 -0
  13. package/lib-amd/index.js +3 -2
  14. package/lib-amd/index.js.map +1 -1
  15. package/lib-amd/modelApi/common/queryContentModelBlocks.d.ts +3 -2
  16. package/lib-amd/modelApi/common/queryContentModelBlocks.js +15 -5
  17. package/lib-amd/modelApi/common/queryContentModelBlocks.js.map +1 -1
  18. package/lib-amd/publicApi/utils/createEditorContextForEntity.d.ts +8 -0
  19. package/lib-amd/publicApi/utils/createEditorContextForEntity.js +31 -0
  20. package/lib-amd/publicApi/utils/createEditorContextForEntity.js.map +1 -0
  21. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +3 -21
  22. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  23. package/lib-mjs/index.d.ts +1 -0
  24. package/lib-mjs/index.js +1 -0
  25. package/lib-mjs/index.js.map +1 -1
  26. package/lib-mjs/modelApi/common/queryContentModelBlocks.d.ts +3 -2
  27. package/lib-mjs/modelApi/common/queryContentModelBlocks.js +15 -4
  28. package/lib-mjs/modelApi/common/queryContentModelBlocks.js.map +1 -1
  29. package/lib-mjs/publicApi/utils/createEditorContextForEntity.d.ts +8 -0
  30. package/lib-mjs/publicApi/utils/createEditorContextForEntity.js +26 -0
  31. package/lib-mjs/publicApi/utils/createEditorContextForEntity.js.map +1 -0
  32. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +3 -20
  33. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  34. package/package.json +1 -1
package/lib/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export { insertEntity } from './publicApi/entity/insertEntity';
44
44
  export { insertTableRow } from './modelApi/table/insertTableRow';
45
45
  export { insertTableColumn } from './modelApi/table/insertTableColumn';
46
46
  export { clearSelectedCells } from './modelApi/table/clearSelectedCells';
47
+ export { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';
47
48
  export { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';
48
49
  export { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';
49
50
  export { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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.queryContentModelBlocks = exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = void 0;
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;
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");
@@ -94,6 +94,8 @@ var insertTableColumn_1 = require("./modelApi/table/insertTableColumn");
94
94
  Object.defineProperty(exports, "insertTableColumn", { enumerable: true, get: function () { return insertTableColumn_1.insertTableColumn; } });
95
95
  var clearSelectedCells_1 = require("./modelApi/table/clearSelectedCells");
96
96
  Object.defineProperty(exports, "clearSelectedCells", { enumerable: true, get: function () { return clearSelectedCells_1.clearSelectedCells; } });
97
+ var createEditorContextForEntity_1 = require("./publicApi/utils/createEditorContextForEntity");
98
+ Object.defineProperty(exports, "createEditorContextForEntity", { enumerable: true, get: function () { return createEditorContextForEntity_1.createEditorContextForEntity; } });
97
99
  var formatTableWithContentModel_1 = require("./publicApi/utils/formatTableWithContentModel");
98
100
  Object.defineProperty(exports, "formatTableWithContentModel", { enumerable: true, get: function () { return formatTableWithContentModel_1.formatTableWithContentModel; } });
99
101
  var formatImageWithContentModel_1 = require("./publicApi/utils/formatImageWithContentModel");
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;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,OAAA;A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nD,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;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 { 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;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,OAAA;AACxB,2EAA0E;AAAjE,sHAAA,iB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EAA+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,9 +1,10 @@
1
- import type { ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
1
+ import type { ContentModelEntity, EditorContext, ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Query content model blocks
4
4
  * @param group The block group to query
5
5
  * @param type The type of block to query
6
6
  * @param filter Optional selector to filter the blocks
7
7
  * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not
8
9
  */
9
- export declare function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(group: ReadonlyContentModelBlockGroup, type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never, filter?: (element: T) => element is T, findFirstOnly?: boolean): T[];
10
+ export declare function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(group: ReadonlyContentModelBlockGroup, type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never, filter?: (element: T) => element is T, findFirstOnly?: boolean, shouldExpandEntity?: (entity: ContentModelEntity) => EditorContext | null): T[];
@@ -2,14 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.queryContentModelBlocks = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
5
6
  /**
6
7
  * Query content model blocks
7
8
  * @param group The block group to query
8
9
  * @param type The type of block to query
9
10
  * @param filter Optional selector to filter the blocks
10
11
  * @param findFirstOnly True to return the first block only, false to return all blocks
12
+ * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not
11
13
  */
12
- function queryContentModelBlocks(group, type, filter, findFirstOnly) {
14
+ function queryContentModelBlocks(group, type, filter, findFirstOnly, shouldExpandEntity) {
13
15
  var e_1, _a, e_2, _b;
14
16
  var elements = [];
15
17
  for (var i = 0; i < group.blocks.length; i++) {
@@ -24,12 +26,21 @@ function queryContentModelBlocks(group, type, filter, findFirstOnly) {
24
26
  if (isExpectedBlockType(block, type, filter)) {
25
27
  elements.push(block);
26
28
  }
29
+ if (block.blockType == 'Entity' && shouldExpandEntity) {
30
+ var editorContext = shouldExpandEntity(block);
31
+ if (editorContext) {
32
+ var context = (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext);
33
+ var model = (0, roosterjs_content_model_dom_1.domToContentModel)(block.wrapper, context);
34
+ var results_1 = queryContentModelBlocks(model, type, filter, findFirstOnly, shouldExpandEntity);
35
+ elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results_1), false));
36
+ }
37
+ }
27
38
  break;
28
39
  case 'BlockGroup':
29
40
  if (isExpectedBlockType(block, type, filter)) {
30
41
  elements.push(block);
31
42
  }
32
- var results = queryContentModelBlocks(block, type, filter, findFirstOnly);
43
+ var results = queryContentModelBlocks(block, type, filter, findFirstOnly, shouldExpandEntity);
33
44
  elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results), false));
34
45
  break;
35
46
  case 'Table':
@@ -42,8 +53,8 @@ function queryContentModelBlocks(group, type, filter, findFirstOnly) {
42
53
  try {
43
54
  for (var _e = (e_2 = void 0, (0, tslib_1.__values)(row.cells)), _f = _e.next(); !_f.done; _f = _e.next()) {
44
55
  var cell = _f.value;
45
- var results_1 = queryContentModelBlocks(cell, type, filter, findFirstOnly);
46
- elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results_1), false));
56
+ var results_2 = queryContentModelBlocks(cell, type, filter, findFirstOnly, shouldExpandEntity);
57
+ elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results_2), false));
47
58
  }
48
59
  }
49
60
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -1 +1 @@
1
- {"version":3,"file":"queryContentModelBlocks.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/queryContentModelBlocks.ts"],"names":[],"mappings":";;;;AAOA;;;;;;GAMG;AACH,SAAgB,uBAAuB,CACnC,KAAqC,EACrC,IAAkE,EAClE,MAAqC,EACrC,aAAuB;;IAEvB,IAAM,QAAQ,GAAQ,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,aAAa,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,OAAO,QAAQ,CAAC;SACnB;QACD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE9B,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,WAAW,CAAC;YACjB,KAAK,SAAS,CAAC;YACf,KA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,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,WAAW,CAChB,KAAgC,EAChC,IAA2B;IAE3B,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;AACnC,CAAC","sourcesContent":["import type {\n ContentModelBlockType,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(block, type, filter, findFirstOnly);\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
1
+ {"version":3,"file":"queryContentModelBlocks.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/queryContentModelBlocks.ts"],"names":[],"mappings":";;;;AAAA,2EAAyF;AAUzF;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACnC,KAAqC,EACrC,IAAkE,EAClE,MAAqC,EACrC,aAAuB,EACvB,kBAAyE;;IAEzE,IAAM,QAAQ,GAAQ,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,aAAa,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,OAAO,QAAQ,CAAC;SACnB;QACD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE9B,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,WAAW,CAAC;YACjB,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACT,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE;oBAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACxB;gBACD,IAAI,KAAK,CAAC,SAAS,IAAI,QAAQ,IAAI,kBAAkB,EAAE;oBACnD,IAAM,aAAa,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;oBAChD,IAAI,aAAa,EAAE;wBACf,IAAM,OAAO,GAAG,IAAA,qDAAuB,EAAC,aAAa,CAAC,CAAC;wBACvD,IAAM,KAAK,GAAG,IAAA,+CAAiB,EAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBACxD,IAAM,SAAO,GAAG,uBAAuB,CACnC,KAAK,EACL,IAAI,EACJ,MAAM,EACN,aAAa,EACb,kBAAkB,CACrB,CAAC;wBACF,QAAQ,CAAC,IAAI,OAAb,QAAQ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,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;AACnC,CAAC","sourcesContent":["import { createDomToModelContext, domToContentModel } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockType,\n ContentModelEntity,\n EditorContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean,\n shouldExpandEntity?: (entity: ContentModelEntity) => EditorContext | null\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n if (block.blockType == 'Entity' && shouldExpandEntity) {\n const editorContext = shouldExpandEntity(block);\n if (editorContext) {\n const context = createDomToModelContext(editorContext);\n const model = domToContentModel(block.wrapper, context);\n const results = queryContentModelBlocks<T>(\n model,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n }\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(\n block,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Create an EditorContext for an entity
4
+ * @param editor The editor object
5
+ * @param entity The entity to create the context for
6
+ * @returns The generated EditorContext for the entity
7
+ */
8
+ export declare function createEditorContextForEntity(editor: IEditor, entity: ContentModelEntity): EditorContext;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createEditorContextForEntity = void 0;
4
+ var tslib_1 = require("tslib");
5
+ /**
6
+ * Create an EditorContext for an entity
7
+ * @param editor The editor object
8
+ * @param entity The entity to create the context for
9
+ * @returns The generated EditorContext for the entity
10
+ */
11
+ function createEditorContextForEntity(editor, entity) {
12
+ var _a;
13
+ var domHelper = editor.getDOMHelper();
14
+ var context = {
15
+ isDarkMode: editor.isDarkMode(),
16
+ defaultFormat: (0, tslib_1.__assign)({}, entity.format),
17
+ darkColorHandler: editor.getColorManager(),
18
+ addDelimiterForEntity: false,
19
+ allowCacheElement: false,
20
+ domIndexer: undefined,
21
+ zoomScale: domHelper.calculateZoomScale(),
22
+ experimentalFeatures: [],
23
+ };
24
+ if (((_a = editor.getDocument().defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(entity.wrapper).direction) == 'rtl') {
25
+ context.isRootRtl = true;
26
+ }
27
+ return context;
28
+ }
29
+ exports.createEditorContextForEntity = createEditorContextForEntity;
30
+ //# sourceMappingURL=createEditorContextForEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createEditorContextForEntity.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/createEditorContextForEntity.ts"],"names":[],"mappings":";;;;AAEA;;;;;GAKG;AACH,SAAgB,4BAA4B,CACxC,MAAe,EACf,MAA0B;;IAE1B,IAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IACxC,IAAM,OAAO,GAAkB;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;QAC/B,aAAa,4BAAO,MAAM,CAAC,MAAM,CAAE;QACnC,gBAAgB,EAAE,MAAM,CAAC,eAAe,EAAE;QAC1C,qBAAqB,EAAE,KAAK;QAC5B,iBAAiB,EAAE,KAAK;QACxB,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,SAAS,CAAC,kBAAkB,EAAE;QACzC,oBAAoB,EAAE,EAAE;KAC3B,CAAC;IAEF,IAAI,CAAA,MAAA,MAAM,CAAC,WAAW,EAAE,CAAC,WAAW,0CAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,KAAI,KAAK,EAAE;QACvF,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;KAC5B;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AArBD,oEAqBC","sourcesContent":["import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Create an EditorContext for an entity\n * @param editor The editor object\n * @param entity The entity to create the context for\n * @returns The generated EditorContext for the entity\n */\nexport function createEditorContextForEntity(\n editor: IEditor,\n entity: ContentModelEntity\n): EditorContext {\n const domHelper = editor.getDOMHelper();\n const context: EditorContext = {\n isDarkMode: editor.isDarkMode(),\n defaultFormat: { ...entity.format },\n darkColorHandler: editor.getColorManager(),\n addDelimiterForEntity: false,\n allowCacheElement: false,\n domIndexer: undefined,\n zoomScale: domHelper.calculateZoomScale(),\n experimentalFeatures: [],\n };\n\n if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {\n context.isRootRtl = true;\n }\n\n return context;\n}\n"]}
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatSegmentWithContentModel = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var adjustWordSelection_1 = require("../../modelApi/selection/adjustWordSelection");
6
5
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
+ var adjustWordSelection_1 = require("../../modelApi/selection/adjustWordSelection");
7
+ var createEditorContextForEntity_1 = require("./createEditorContextForEntity");
7
8
  /**
8
9
  * Invoke a callback to format the selected segment using Content Model
9
10
  * @param editor The editor object
@@ -77,24 +78,6 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
77
78
  });
78
79
  }
79
80
  exports.formatSegmentWithContentModel = formatSegmentWithContentModel;
80
- function createEditorContextForEntity(editor, entity) {
81
- var _a;
82
- var domHelper = editor.getDOMHelper();
83
- var context = {
84
- isDarkMode: editor.isDarkMode(),
85
- defaultFormat: (0, tslib_1.__assign)({}, entity.format),
86
- darkColorHandler: editor.getColorManager(),
87
- addDelimiterForEntity: false,
88
- allowCacheElement: false,
89
- domIndexer: undefined,
90
- zoomScale: domHelper.calculateZoomScale(),
91
- experimentalFeatures: [],
92
- };
93
- if (((_a = editor.getDocument().defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(entity.wrapper).direction) == 'rtl') {
94
- context.isRootRtl = true;
95
- }
96
- return context;
97
- }
98
81
  function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
99
82
  var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
100
83
  if (id && type) {
@@ -107,7 +90,7 @@ function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEn
107
90
  editor.triggerEvent('entityOperation', entityOperationEventData);
108
91
  formattableRoots.forEach(function (root) {
109
92
  if (entity.wrapper.contains(root.element)) {
110
- var editorContext = createEditorContextForEntity(editor, entity);
93
+ var editorContext = (0, createEditorContextForEntity_1.createEditorContextForEntity)(editor, entity);
111
94
  var context = (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext, root.domToModelOptions);
112
95
  // Treat everything as selected since the parent entity is selected
113
96
  context.isInSelection = true;
@@ -124,7 +107,7 @@ function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEn
124
107
  function writeBackEntities(editor, modelsFromEntities) {
125
108
  modelsFromEntities.forEach(function (_a) {
126
109
  var _b = (0, tslib_1.__read)(_a, 3), entity = _b[0], root = _b[1], model = _b[2];
127
- var editorContext = createEditorContextForEntity(editor, entity);
110
+ var editorContext = (0, createEditorContextForEntity_1.createEditorContextForEntity)(editor, entity);
128
111
  var modelToDomContext = (0, roosterjs_content_model_dom_1.createModelToDomContext)(editorContext, root.modelToDomOptions);
129
112
  (0, roosterjs_content_model_dom_1.contentModelToDom)(editor.getDocument(), root.element, model, modelToDomContext);
130
113
  });
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,oFAAmF;AACnF,2EAOqC;AAcrC;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;IAEnE,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,O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C;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n EditorContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction createEditorContextForEntity(editor: IEditor, entity: ContentModelEntity): EditorContext {\n const domHelper = editor.getDOMHelper();\n const context: EditorContext = {\n isDarkMode: editor.isDarkMode(),\n defaultFormat: { ...entity.format },\n darkColorHandler: editor.getColorManager(),\n addDelimiterForEntity: false,\n allowCacheElement: false,\n domIndexer: undefined,\n zoomScale: domHelper.calculateZoomScale(),\n experimentalFeatures: [],\n };\n\n if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {\n context.isRootRtl = true;\n }\n\n return context;\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,2EAOqC;AAYrC,oFAAmF;AACnF,+EAA8E;AAE9E;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;IAEnE,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;QAE3E,0DAA0D;QAC1D,IAAI,oBAAoB,EAAE;YACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAExC,oBAAoB,GAAG,IAAA,yCAAmB,EACtC,KAAK,EACL,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7B,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,EAAE,MAAI,EAAE,MAAI,CAAC,EAAf,CAAe,CAAC,CAAC;YAE5B,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACjC,oBAAoB,GAAG,KAAK,CAAC;aAChC;SACJ;QAED,0CAA0C;QAC1C,IAAM,kBAAkB,GAIlB,EA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,CAAC;AACP,CAAC","sourcesContent":["import {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\nimport { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
@@ -44,6 +44,7 @@ export { insertEntity } from './publicApi/entity/insertEntity';
44
44
  export { insertTableRow } from './modelApi/table/insertTableRow';
45
45
  export { insertTableColumn } from './modelApi/table/insertTableColumn';
46
46
  export { clearSelectedCells } from './modelApi/table/clearSelectedCells';
47
+ export { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';
47
48
  export { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';
48
49
  export { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';
49
50
  export { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';
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/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, 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"], 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) {
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.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 = 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; } });
@@ -48,6 +48,7 @@ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/tabl
48
48
  Object.defineProperty(exports, "insertTableRow", { enumerable: true, get: function () { return insertTableRow_1.insertTableRow; } });
49
49
  Object.defineProperty(exports, "insertTableColumn", { enumerable: true, get: function () { return insertTableColumn_1.insertTableColumn; } });
50
50
  Object.defineProperty(exports, "clearSelectedCells", { enumerable: true, get: function () { return clearSelectedCells_1.clearSelectedCells; } });
51
+ Object.defineProperty(exports, "createEditorContextForEntity", { enumerable: true, get: function () { return createEditorContextForEntity_1.createEditorContextForEntity; } });
51
52
  Object.defineProperty(exports, "formatTableWithContentModel", { enumerable: true, get: function () { return formatTableWithContentModel_1.formatTableWithContentModel; } });
52
53
  Object.defineProperty(exports, "formatImageWithContentModel", { enumerable: true, get: function () { return formatImageWithContentModel_1.formatImageWithContentModel; } });
53
54
  Object.defineProperty(exports, "formatParagraphWithContentModel", { enumerable: true, get: function () { return formatParagraphWithContentModel_1.formatParagraphWithContentModel; } });
@@ -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,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 { 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,WA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} 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,9 +1,10 @@
1
- import type { ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
1
+ import type { ContentModelEntity, EditorContext, ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Query content model blocks
4
4
  * @param group The block group to query
5
5
  * @param type The type of block to query
6
6
  * @param filter Optional selector to filter the blocks
7
7
  * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not
8
9
  */
9
- export declare function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(group: ReadonlyContentModelBlockGroup, type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never, filter?: (element: T) => element is T, findFirstOnly?: boolean): T[];
10
+ export declare function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(group: ReadonlyContentModelBlockGroup, type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never, filter?: (element: T) => element is T, findFirstOnly?: boolean, shouldExpandEntity?: (entity: ContentModelEntity) => EditorContext | null): T[];
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
1
+ define(["require", "exports", "tslib", "roosterjs-content-model-dom"], function (require, exports, tslib_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.queryContentModelBlocks = void 0;
@@ -8,8 +8,9 @@ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
8
8
  * @param type The type of block to query
9
9
  * @param filter Optional selector to filter the blocks
10
10
  * @param findFirstOnly True to return the first block only, false to return all blocks
11
+ * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not
11
12
  */
12
- function queryContentModelBlocks(group, type, filter, findFirstOnly) {
13
+ function queryContentModelBlocks(group, type, filter, findFirstOnly, shouldExpandEntity) {
13
14
  var e_1, _a, e_2, _b;
14
15
  var elements = [];
15
16
  for (var i = 0; i < group.blocks.length; i++) {
@@ -24,12 +25,21 @@ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
24
25
  if (isExpectedBlockType(block, type, filter)) {
25
26
  elements.push(block);
26
27
  }
28
+ if (block.blockType == 'Entity' && shouldExpandEntity) {
29
+ var editorContext = shouldExpandEntity(block);
30
+ if (editorContext) {
31
+ var context = (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext);
32
+ var model = (0, roosterjs_content_model_dom_1.domToContentModel)(block.wrapper, context);
33
+ var results_1 = queryContentModelBlocks(model, type, filter, findFirstOnly, shouldExpandEntity);
34
+ elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results_1), false));
35
+ }
36
+ }
27
37
  break;
28
38
  case 'BlockGroup':
29
39
  if (isExpectedBlockType(block, type, filter)) {
30
40
  elements.push(block);
31
41
  }
32
- var results = queryContentModelBlocks(block, type, filter, findFirstOnly);
42
+ var results = queryContentModelBlocks(block, type, filter, findFirstOnly, shouldExpandEntity);
33
43
  elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results), false));
34
44
  break;
35
45
  case 'Table':
@@ -42,8 +52,8 @@ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
42
52
  try {
43
53
  for (var _e = (e_2 = void 0, (0, tslib_1.__values)(row.cells)), _f = _e.next(); !_f.done; _f = _e.next()) {
44
54
  var cell = _f.value;
45
- var results_1 = queryContentModelBlocks(cell, type, filter, findFirstOnly);
46
- elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results_1), false));
55
+ var results_2 = queryContentModelBlocks(cell, type, filter, findFirstOnly, shouldExpandEntity);
56
+ elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results_2), false));
47
57
  }
48
58
  }
49
59
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -1 +1 @@
1
- {"version":3,"file":"queryContentModelBlocks.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/queryContentModelBlocks.ts"],"names":[],"mappings":";;;;IAOA;;;;;;OAMG;IACH,SAAgB,uBAAuB,CACnC,KAAqC,EACrC,I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;oCAAzB,IAAM,IAAI,WAAA;oCACX,IAAM,SAAO,GAAG,uBAAuB,CACnC,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,aAAa,CAChB,CAAC;oCACF,QAAQ,CAAC,IAAI,OAAb,QAAQ,qDAAS,SAAO,WAAE;iCAC7B;;;;;;;;;yBACJ;;;;;;;;;oBACD,MAAM;aACb;SACJ;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IA/CD,0DA+CC;IAED,SAAS,mBAAmB,CACxB,KAAgC,EAChC,IAA2B,EAC3B,MAAqC;QAErC,OAAO,WAAW,CAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,SAAS,WAAW,CAChB,KAAgC,EAChC,IAA2B;QAE3B,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;IACnC,CAAC","sourcesContent":["import type {\n ContentModelBlockType,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(block, type, filter, findFirstOnly);\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
1
+ {"version":3,"file":"queryContentModelBlocks.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/queryContentModelBlocks.ts"],"names":[],"mappings":";;;;IAUA;;;;;;;OAOG;IACH,SAAgB,uBAAuB,CACnC,KAAqC,EACrC,IAAkE,EAClE,MAAqC,EACrC,aAAuB,EACvB,kBAAyE;;QAEzE,IAAM,QAAQ,GAAQ,EAAE,CAAC;QACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,IAAI,aAAa,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBACtC,OAAO,QAAQ,CAAC;aACnB;YACD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAE9B,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,WAAW,CAAC;gBACjB,KAAK,SAAS,CAAC;gBACf,KAAK,QAAQ;oBACT,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE;wBAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBACxB;oBACD,I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aAAa,EACb,kBAAkB,CACrB,CAAC;oCACF,QAAQ,CAAC,IAAI,OAAb,QAAQ,qDAAS,SAAO,WAAE;iCAC7B;;;;;;;;;yBACJ;;;;;;;;;oBACD,MAAM;aACb;SACJ;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IAtED,0DAsEC;IAED,SAAS,mBAAmB,CACxB,KAAgC,EAChC,IAA2B,EAC3B,MAAqC;QAErC,OAAO,WAAW,CAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,SAAS,WAAW,CAChB,KAAgC,EAChC,IAA2B;QAE3B,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;IACnC,CAAC","sourcesContent":["import { createDomToModelContext, domToContentModel } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockType,\n ContentModelEntity,\n EditorContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean,\n shouldExpandEntity?: (entity: ContentModelEntity) => EditorContext | null\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n if (block.blockType == 'Entity' && shouldExpandEntity) {\n const editorContext = shouldExpandEntity(block);\n if (editorContext) {\n const context = createDomToModelContext(editorContext);\n const model = domToContentModel(block.wrapper, context);\n const results = queryContentModelBlocks<T>(\n model,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n }\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(\n block,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Create an EditorContext for an entity
4
+ * @param editor The editor object
5
+ * @param entity The entity to create the context for
6
+ * @returns The generated EditorContext for the entity
7
+ */
8
+ export declare function createEditorContextForEntity(editor: IEditor, entity: ContentModelEntity): EditorContext;
@@ -0,0 +1,31 @@
1
+ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createEditorContextForEntity = void 0;
5
+ /**
6
+ * Create an EditorContext for an entity
7
+ * @param editor The editor object
8
+ * @param entity The entity to create the context for
9
+ * @returns The generated EditorContext for the entity
10
+ */
11
+ function createEditorContextForEntity(editor, entity) {
12
+ var _a;
13
+ var domHelper = editor.getDOMHelper();
14
+ var context = {
15
+ isDarkMode: editor.isDarkMode(),
16
+ defaultFormat: (0, tslib_1.__assign)({}, entity.format),
17
+ darkColorHandler: editor.getColorManager(),
18
+ addDelimiterForEntity: false,
19
+ allowCacheElement: false,
20
+ domIndexer: undefined,
21
+ zoomScale: domHelper.calculateZoomScale(),
22
+ experimentalFeatures: [],
23
+ };
24
+ if (((_a = editor.getDocument().defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(entity.wrapper).direction) == 'rtl') {
25
+ context.isRootRtl = true;
26
+ }
27
+ return context;
28
+ }
29
+ exports.createEditorContextForEntity = createEditorContextForEntity;
30
+ });
31
+ //# sourceMappingURL=createEditorContextForEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createEditorContextForEntity.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/createEditorContextForEntity.ts"],"names":[],"mappings":";;;;IAEA;;;;;OAKG;IACH,SAAgB,4BAA4B,CACxC,MAAe,EACf,MAA0B;;QAE1B,IAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;QACxC,IAAM,OAAO,GAAkB;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;YAC/B,aAAa,4BAAO,MAAM,CAAC,MAAM,CAAE;YACnC,gBAAgB,EAAE,MAAM,CAAC,eAAe,EAAE;YAC1C,qBAAqB,EAAE,KAAK;YAC5B,iBAAiB,EAAE,KAAK;YACxB,UAAU,EAAE,SAAS;YACrB,SAAS,EAAE,SAAS,CAAC,kBAAkB,EAAE;YACzC,oBAAoB,EAAE,EAAE;SAC3B,CAAC;QAEF,IAAI,CAAA,MAAA,MAAM,CAAC,WAAW,EAAE,CAAC,WAAW,0CAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,KAAI,KAAK,EAAE;YACvF,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;SAC5B;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;IArBD,oEAqBC","sourcesContent":["import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Create an EditorContext for an entity\n * @param editor The editor object\n * @param entity The entity to create the context for\n * @returns The generated EditorContext for the entity\n */\nexport function createEditorContextForEntity(\n editor: IEditor,\n entity: ContentModelEntity\n): EditorContext {\n const domHelper = editor.getDOMHelper();\n const context: EditorContext = {\n isDarkMode: editor.isDarkMode(),\n defaultFormat: { ...entity.format },\n darkColorHandler: editor.getColorManager(),\n addDelimiterForEntity: false,\n allowCacheElement: false,\n domIndexer: undefined,\n zoomScale: domHelper.calculateZoomScale(),\n experimentalFeatures: [],\n };\n\n if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {\n context.isRootRtl = true;\n }\n\n return context;\n}\n"]}
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelection", "roosterjs-content-model-dom"], function (require, exports, tslib_1, adjustWordSelection_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "../../modelApi/selection/adjustWordSelection", "./createEditorContextForEntity"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, adjustWordSelection_1, createEditorContextForEntity_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.formatSegmentWithContentModel = void 0;
@@ -75,24 +75,6 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
75
75
  });
76
76
  }
77
77
  exports.formatSegmentWithContentModel = formatSegmentWithContentModel;
78
- function createEditorContextForEntity(editor, entity) {
79
- var _a;
80
- var domHelper = editor.getDOMHelper();
81
- var context = {
82
- isDarkMode: editor.isDarkMode(),
83
- defaultFormat: (0, tslib_1.__assign)({}, entity.format),
84
- darkColorHandler: editor.getColorManager(),
85
- addDelimiterForEntity: false,
86
- allowCacheElement: false,
87
- domIndexer: undefined,
88
- zoomScale: domHelper.calculateZoomScale(),
89
- experimentalFeatures: [],
90
- };
91
- if (((_a = editor.getDocument().defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(entity.wrapper).direction) == 'rtl') {
92
- context.isRootRtl = true;
93
- }
94
- return context;
95
- }
96
78
  function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
97
79
  var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
98
80
  if (id && type) {
@@ -105,7 +87,7 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
105
87
  editor.triggerEvent('entityOperation', entityOperationEventData);
106
88
  formattableRoots.forEach(function (root) {
107
89
  if (entity.wrapper.contains(root.element)) {
108
- var editorContext = createEditorContextForEntity(editor, entity);
90
+ var editorContext = (0, createEditorContextForEntity_1.createEditorContextForEntity)(editor, entity);
109
91
  var context = (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext, root.domToModelOptions);
110
92
  // Treat everything as selected since the parent entity is selected
111
93
  context.isInSelection = true;
@@ -122,7 +104,7 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
122
104
  function writeBackEntities(editor, modelsFromEntities) {
123
105
  modelsFromEntities.forEach(function (_a) {
124
106
  var _b = (0, tslib_1.__read)(_a, 3), entity = _b[0], root = _b[1], model = _b[2];
125
- var editorContext = createEditorContextForEntity(editor, entity);
107
+ var editorContext = (0, createEditorContextForEntity_1.createEditorContextForEntity)(editor, entity);
126
108
  var modelToDomContext = (0, roosterjs_content_model_dom_1.createModelToDomContext)(editorContext, root.modelToDomOptions);
127
109
  (0, roosterjs_content_model_dom_1.contentModelToDom)(editor.getDocument(), root.element, model, modelToDomContext);
128
110
  });
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":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C,CAAC,CAAC;SACN;IACL,CAAC;IAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;QAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;gBAArB,KAAA,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;YAC5C,IAAM,aAAa,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n EditorContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction createEditorContextForEntity(editor: IEditor, entity: ContentModelEntity): EditorContext {\n const domHelper = editor.getDOMHelper();\n const context: EditorContext = {\n isDarkMode: editor.isDarkMode(),\n defaultFormat: { ...entity.format },\n darkColorHandler: editor.getColorManager(),\n addDelimiterForEntity: false,\n allowCacheElement: false,\n domIndexer: undefined,\n zoomScale: domHelper.calculateZoomScale(),\n experimentalFeatures: [],\n };\n\n if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {\n context.isRootRtl = true;\n }\n\n return context;\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IAsBA;;;;;;;;OAQG;IACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;QAEnE,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;YACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;gBAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;YAE3E,0DAA0D;YAC1D,IAAI,oBAAoB,EAAE;gBACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;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S,iBAAiB,CACtB,MAAe,EACf,kBAAiF;QAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;gBAArB,KAAA,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;YAC5C,IAAM,aAAa,GAAG,IAAA,2DAA4B,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC","sourcesContent":["import {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\nimport { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
@@ -44,6 +44,7 @@ export { insertEntity } from './publicApi/entity/insertEntity';
44
44
  export { insertTableRow } from './modelApi/table/insertTableRow';
45
45
  export { insertTableColumn } from './modelApi/table/insertTableColumn';
46
46
  export { clearSelectedCells } from './modelApi/table/clearSelectedCells';
47
+ export { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';
47
48
  export { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';
48
49
  export { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';
49
50
  export { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';
package/lib-mjs/index.js CHANGED
@@ -44,6 +44,7 @@ export { insertEntity } from './publicApi/entity/insertEntity';
44
44
  export { insertTableRow } from './modelApi/table/insertTableRow';
45
45
  export { insertTableColumn } from './modelApi/table/insertTableColumn';
46
46
  export { clearSelectedCells } from './modelApi/table/clearSelectedCells';
47
+ export { createEditorContextForEntity } from './publicApi/utils/createEditorContextForEntity';
47
48
  export { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';
48
49
  export { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';
49
50
  export { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';
@@ -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,0CAA0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,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","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';\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,E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O,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,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","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,9 +1,10 @@
1
- import type { ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
1
+ import type { ContentModelEntity, EditorContext, ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Query content model blocks
4
4
  * @param group The block group to query
5
5
  * @param type The type of block to query
6
6
  * @param filter Optional selector to filter the blocks
7
7
  * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not
8
9
  */
9
- export declare function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(group: ReadonlyContentModelBlockGroup, type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never, filter?: (element: T) => element is T, findFirstOnly?: boolean): T[];
10
+ export declare function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(group: ReadonlyContentModelBlockGroup, type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never, filter?: (element: T) => element is T, findFirstOnly?: boolean, shouldExpandEntity?: (entity: ContentModelEntity) => EditorContext | null): T[];
@@ -1,12 +1,14 @@
1
1
  import { __read, __spreadArray, __values } from "tslib";
2
+ import { createDomToModelContext, domToContentModel } from 'roosterjs-content-model-dom';
2
3
  /**
3
4
  * Query content model blocks
4
5
  * @param group The block group to query
5
6
  * @param type The type of block to query
6
7
  * @param filter Optional selector to filter the blocks
7
8
  * @param findFirstOnly True to return the first block only, false to return all blocks
9
+ * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not
8
10
  */
9
- export function queryContentModelBlocks(group, type, filter, findFirstOnly) {
11
+ export function queryContentModelBlocks(group, type, filter, findFirstOnly, shouldExpandEntity) {
10
12
  var e_1, _a, e_2, _b;
11
13
  var elements = [];
12
14
  for (var i = 0; i < group.blocks.length; i++) {
@@ -21,12 +23,21 @@ export function queryContentModelBlocks(group, type, filter, findFirstOnly) {
21
23
  if (isExpectedBlockType(block, type, filter)) {
22
24
  elements.push(block);
23
25
  }
26
+ if (block.blockType == 'Entity' && shouldExpandEntity) {
27
+ var editorContext = shouldExpandEntity(block);
28
+ if (editorContext) {
29
+ var context = createDomToModelContext(editorContext);
30
+ var model = domToContentModel(block.wrapper, context);
31
+ var results_1 = queryContentModelBlocks(model, type, filter, findFirstOnly, shouldExpandEntity);
32
+ elements.push.apply(elements, __spreadArray([], __read(results_1), false));
33
+ }
34
+ }
24
35
  break;
25
36
  case 'BlockGroup':
26
37
  if (isExpectedBlockType(block, type, filter)) {
27
38
  elements.push(block);
28
39
  }
29
- var results = queryContentModelBlocks(block, type, filter, findFirstOnly);
40
+ var results = queryContentModelBlocks(block, type, filter, findFirstOnly, shouldExpandEntity);
30
41
  elements.push.apply(elements, __spreadArray([], __read(results), false));
31
42
  break;
32
43
  case 'Table':
@@ -39,8 +50,8 @@ export function queryContentModelBlocks(group, type, filter, findFirstOnly) {
39
50
  try {
40
51
  for (var _e = (e_2 = void 0, __values(row.cells)), _f = _e.next(); !_f.done; _f = _e.next()) {
41
52
  var cell = _f.value;
42
- var results_1 = queryContentModelBlocks(cell, type, filter, findFirstOnly);
43
- elements.push.apply(elements, __spreadArray([], __read(results_1), false));
53
+ var results_2 = queryContentModelBlocks(cell, type, filter, findFirstOnly, shouldExpandEntity);
54
+ elements.push.apply(elements, __spreadArray([], __read(results_2), false));
44
55
  }
45
56
  }
46
57
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -1 +1 @@
1
- {"version":3,"file":"queryContentModelBlocks.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/queryContentModelBlocks.ts"],"names":[],"mappings":";AAOA;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACnC,KAAqC,EACrC,IAAkE,EAClE,MAAqC,EACrC,aAAuB;;IAEvB,IAAM,QAAQ,GAAQ,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,aAAa,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,OAAO,QAAQ,CAAC;SACnB;QACD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE9B,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK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AM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,WAAW,CAChB,KAAgC,EAChC,IAA2B;IAE3B,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;AACnC,CAAC","sourcesContent":["import type {\n ContentModelBlockType,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(block, type, filter, findFirstOnly);\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
1
+ {"version":3,"file":"queryContentModelBlocks.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/common/queryContentModelBlocks.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAUzF;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACnC,KAAqC,EACrC,IAAkE,EAClE,MAAqC,EACrC,aAAuB,EACvB,kBAAyE;;IAEzE,IAAM,QAAQ,GAAQ,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,aAAa,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YACtC,OAAO,QAAQ,CAAC;SACnB;QACD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAE9B,QAAQ,KAAK,CAAC,SAAS,EAAE;YACrB,KAAK,WAAW,CAAC;YACjB,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ;gBACT,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE;oBAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACxB;gBACD,IAAI,KAAK,CAAC,SAAS,IAAI,QAAQ,IAAI,kBAAkB,EAAE;oBACnD,IAAM,aAAa,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;oBAChD,IAAI,aAAa,EAAE;wBACf,IAAM,OAAO,GAAG,uBAAuB,CAAC,aAAa,CAAC,CAAC;wBACvD,IAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBACxD,IAAM,SAAO,GAAG,uBAAuB,CACnC,KAAK,EACL,IAAI,EACJ,MAAM,EACN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C;AAED,SAAS,WAAW,CAChB,KAAgC,EAChC,IAA2B;IAE3B,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;AACnC,CAAC","sourcesContent":["import { createDomToModelContext, domToContentModel } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockType,\n ContentModelEntity,\n EditorContext,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n * @param shouldExpandEntity Optional function to determine if an entity's children should be recursively queried, should return a EditorContext if the entity should be expanded, or null if not\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean,\n shouldExpandEntity?: (entity: ContentModelEntity) => EditorContext | null\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n if (block.blockType == 'Entity' && shouldExpandEntity) {\n const editorContext = shouldExpandEntity(block);\n if (editorContext) {\n const context = createDomToModelContext(editorContext);\n const model = domToContentModel(block.wrapper, context);\n const results = queryContentModelBlocks<T>(\n model,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n }\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(\n block,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly,\n shouldExpandEntity\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Create an EditorContext for an entity
4
+ * @param editor The editor object
5
+ * @param entity The entity to create the context for
6
+ * @returns The generated EditorContext for the entity
7
+ */
8
+ export declare function createEditorContextForEntity(editor: IEditor, entity: ContentModelEntity): EditorContext;
@@ -0,0 +1,26 @@
1
+ import { __assign } from "tslib";
2
+ /**
3
+ * Create an EditorContext for an entity
4
+ * @param editor The editor object
5
+ * @param entity The entity to create the context for
6
+ * @returns The generated EditorContext for the entity
7
+ */
8
+ export function createEditorContextForEntity(editor, entity) {
9
+ var _a;
10
+ var domHelper = editor.getDOMHelper();
11
+ var context = {
12
+ isDarkMode: editor.isDarkMode(),
13
+ defaultFormat: __assign({}, entity.format),
14
+ darkColorHandler: editor.getColorManager(),
15
+ addDelimiterForEntity: false,
16
+ allowCacheElement: false,
17
+ domIndexer: undefined,
18
+ zoomScale: domHelper.calculateZoomScale(),
19
+ experimentalFeatures: [],
20
+ };
21
+ if (((_a = editor.getDocument().defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(entity.wrapper).direction) == 'rtl') {
22
+ context.isRootRtl = true;
23
+ }
24
+ return context;
25
+ }
26
+ //# sourceMappingURL=createEditorContextForEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createEditorContextForEntity.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/createEditorContextForEntity.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CACxC,MAAe,EACf,MAA0B;;IAE1B,IAAM,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;IACxC,IAAM,OAAO,GAAkB;QAC3B,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE;QAC/B,aAAa,eAAO,MAAM,CAAC,MAAM,CAAE;QACnC,gBAAgB,EAAE,MAAM,CAAC,eAAe,EAAE;QAC1C,qBAAqB,EAAE,KAAK;QAC5B,iBAAiB,EAAE,KAAK;QACxB,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,SAAS,CAAC,kBAAkB,EAAE;QACzC,oBAAoB,EAAE,EAAE;KAC3B,CAAC;IAEF,IAAI,CAAA,MAAA,MAAM,CAAC,WAAW,EAAE,CAAC,WAAW,0CAAE,gBAAgB,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,KAAI,KAAK,EAAE;QACvF,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;KAC5B;IAED,OAAO,OAAO,CAAC;AACnB,CAAC","sourcesContent":["import type { ContentModelEntity, EditorContext, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Create an EditorContext for an entity\n * @param editor The editor object\n * @param entity The entity to create the context for\n * @returns The generated EditorContext for the entity\n */\nexport function createEditorContextForEntity(\n editor: IEditor,\n entity: ContentModelEntity\n): EditorContext {\n const domHelper = editor.getDOMHelper();\n const context: EditorContext = {\n isDarkMode: editor.isDarkMode(),\n defaultFormat: { ...entity.format },\n darkColorHandler: editor.getColorManager(),\n addDelimiterForEntity: false,\n allowCacheElement: false,\n domIndexer: undefined,\n zoomScale: domHelper.calculateZoomScale(),\n experimentalFeatures: [],\n };\n\n if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {\n context.isRootRtl = true;\n }\n\n return context;\n}\n"]}
@@ -1,6 +1,7 @@
1
- import { __assign, __read } from "tslib";
2
- import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';
1
+ import { __read } from "tslib";
3
2
  import { contentModelToDom, createDomToModelContext, createModelToDomContext, domToContentModel, getSelectedSegmentsAndParagraphs, mergeTextSegments, } from 'roosterjs-content-model-dom';
3
+ import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';
4
+ import { createEditorContextForEntity } from './createEditorContextForEntity';
4
5
  /**
5
6
  * Invoke a callback to format the selected segment using Content Model
6
7
  * @param editor The editor object
@@ -73,24 +74,6 @@ export function formatSegmentWithContentModel(editor, apiName, toggleStyleCallba
73
74
  apiName: apiName,
74
75
  });
75
76
  }
76
- function createEditorContextForEntity(editor, entity) {
77
- var _a;
78
- var domHelper = editor.getDOMHelper();
79
- var context = {
80
- isDarkMode: editor.isDarkMode(),
81
- defaultFormat: __assign({}, entity.format),
82
- darkColorHandler: editor.getColorManager(),
83
- addDelimiterForEntity: false,
84
- allowCacheElement: false,
85
- domIndexer: undefined,
86
- zoomScale: domHelper.calculateZoomScale(),
87
- experimentalFeatures: [],
88
- };
89
- if (((_a = editor.getDocument().defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(entity.wrapper).direction) == 'rtl') {
90
- context.isRootRtl = true;
91
- }
92
- return context;
93
- }
94
77
  function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
95
78
  var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
96
79
  if (id && type) {
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EACH,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAi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AS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,aAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n EditorContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction createEditorContextForEntity(editor: IEditor, entity: ContentModelEntity): EditorContext {\n const domHelper = editor.getDOMHelper();\n const context: EditorContext = {\n isDarkMode: editor.isDarkMode(),\n defaultFormat: { ...entity.format },\n darkColorHandler: editor.getColorManager(),\n addDelimiterForEntity: false,\n allowCacheElement: false,\n domIndexer: undefined,\n zoomScale: domHelper.calculateZoomScale(),\n experimentalFeatures: [],\n };\n\n if (editor.getDocument().defaultView?.getComputedStyle(entity.wrapper).direction == 'rtl') {\n context.isRootRtl = true;\n }\n\n return context;\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,gCAAgC,EAChC,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAYrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;IAEnE,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,gCAAgC,CACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAA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IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aAClD;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,aAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\nimport { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "roosterjs-content-model-dom": "^9.27.0",
7
7
  "roosterjs-content-model-types": "^9.27.0"
8
8
  },
9
- "version": "9.27.0",
9
+ "version": "9.28.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",