roosterjs-content-model-api 9.14.0 → 9.16.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 (31) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.js +3 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/modelApi/common/queryContentModelBlocks.d.ts +9 -0
  5. package/lib/modelApi/common/queryContentModelBlocks.js +77 -0
  6. package/lib/modelApi/common/queryContentModelBlocks.js.map +1 -0
  7. package/lib/publicApi/utils/formatSegmentWithContentModel.js +74 -2
  8. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  9. package/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js +3 -0
  10. package/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js.map +1 -1
  11. package/lib-amd/index.d.ts +1 -0
  12. package/lib-amd/index.js +3 -2
  13. package/lib-amd/index.js.map +1 -1
  14. package/lib-amd/modelApi/common/queryContentModelBlocks.d.ts +9 -0
  15. package/lib-amd/modelApi/common/queryContentModelBlocks.js +78 -0
  16. package/lib-amd/modelApi/common/queryContentModelBlocks.js.map +1 -0
  17. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +74 -2
  18. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  19. package/lib-amd/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js +3 -0
  20. package/lib-amd/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js.map +1 -1
  21. package/lib-mjs/index.d.ts +1 -0
  22. package/lib-mjs/index.js +1 -0
  23. package/lib-mjs/index.js.map +1 -1
  24. package/lib-mjs/modelApi/common/queryContentModelBlocks.d.ts +9 -0
  25. package/lib-mjs/modelApi/common/queryContentModelBlocks.js +73 -0
  26. package/lib-mjs/modelApi/common/queryContentModelBlocks.js.map +1 -0
  27. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +76 -4
  28. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  29. package/lib-mjs/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js +3 -0
  30. package/lib-mjs/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js.map +1 -1
  31. package/package.json +3 -3
package/lib/index.d.ts CHANGED
@@ -58,3 +58,4 @@ export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
59
  export { promoteLink } from './modelApi/link/promoteLink';
60
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
61
+ export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatSegmentWithContentModel = exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.clearSelectedCells = exports.insertTableColumn = exports.insertTableRow = exports.insertEntity = exports.toggleCode = exports.setParagraphMargin = exports.adjustImageSelection = exports.setImageAltText = exports.adjustLinkSelection = exports.removeLink = exports.insertLink = exports.clearFormat = exports.getFormatState = exports.changeImage = exports.setImageBoxShadow = exports.setImageBorder = exports.setSpacing = exports.toggleBlockQuote = exports.setHeadingLevel = exports.setDirection = exports.setAlignment = exports.setIndentation = exports.setListStartNumber = exports.setListStyle = exports.insertImage = exports.splitTextSegment = exports.changeCapitalization = exports.applySegmentFormat = exports.changeFontSize = exports.setTextColor = exports.setFontSize = exports.setFontName = exports.setBackgroundColor = exports.toggleSuperscript = exports.toggleSubscript = exports.toggleStrikethrough = exports.toggleUnderline = exports.toggleItalic = exports.toggleBold = exports.toggleNumbering = exports.toggleBullet = exports.applyTableBorderFormat = exports.editTable = exports.setTableCellShade = exports.formatTable = exports.insertTable = void 0;
4
- exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = 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;
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");
@@ -122,4 +122,6 @@ var promoteLink_1 = require("./modelApi/link/promoteLink");
122
122
  Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
123
123
  var getListAnnounceData_1 = require("./modelApi/list/getListAnnounceData");
124
124
  Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
125
+ var queryContentModelBlocks_1 = require("./modelApi/common/queryContentModelBlocks");
126
+ Object.defineProperty(exports, "queryContentModelBlocks", { enumerable: true, get: function () { return queryContentModelBlocks_1.queryContentModelBlocks; } });
125
127
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;AAAA,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,6DAA4D;AAAnD,0GAAA,WAAW,OAAA;AACpB,yEAAwE;AAA/D,sHAAA,iBAAiB,OAAA;AAC1B,yDAAwD;AAA/C,sGAAA,SAAS,OAAA;AAClB,mFAAkF;AAAzE,gIAAA,sBAAsB,OAAA;AAC/B,8DAA6D;AAApD,4GAAA,YAAY,OAAA;AACrB,oEAAmE;AAA1D,kHAAA,eAAe,OAAA;AACxB,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,iEAAgE;AAAvD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AC5B,qEAAoE;AAA3D,kHAAA,eAAe,OAAA;AACxB,+EAA8E;AAArE,4HAAA,oBAAoB,OAAA;AAC7B,2EAA0E;AAAjE,wHAAA,kBAAkB,OAAA;AAC3B,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,gEAA+D;AAAtD,4GAAA,YAAY,OAAA;AACrB,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,sHAAA,iBAAiB,OAAA;AAC1B,0EAAyE;AAAhE,wHAAA,kBAAkB,OAAA;AAE3B,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,qGAAoG;AAA3F,kJAAA,+BAA+B,OAAA;AACxC,iGAAgG;AAAvF,8IAAA,6BAA6B,OAAA;AACtC,mHAAkH;AAAzG,gKAAA,sCAAsC,OAAA;AAC/C,yGAAwG;AAA/F,sJAAA,iCAAiC,OAAA;AAE1C,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,uEAAsE;AAA7D,sHAAA,iBAAiB,OAAA;AAC1B,mFAAkF;AAAzE,kIAAA,uBAAuB,OAAA;AAChC,uFAAsF;AAA7E,sIAAA,yBAAyB,OAAA;AAClC,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAC5B,uDAAsD;AAA7C,sGAAA,SAAS,OAAA;AAClB,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,2EAA0E;AAAjE,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
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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kB,OAAA;AAC3B,6DAA4D;AAAnD,wGAAA,UAAU,OAAA;AACnB,gEAA+D;AAAtD,4GAAA,YAAY,OAAA;AACrB,kEAAiE;AAAxD,gHAAA,cAAc,OAAA;AACvB,wEAAuE;AAA9D,sHAAA,iBAAiB,OAAA;AAC1B,0EAAyE;AAAhE,wHAAA,kBAAkB,OAAA;AAE3B,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,6FAA4F;AAAnF,0IAAA,2BAA2B,OAAA;AACpC,qGAAoG;AAA3F,kJAAA,+BAA+B,OAAA;AACxC,iGAAgG;AAAvF,8IAAA,6BAA6B,OAAA;AACtC,mHAAkH;AAAzG,gKAAA,sCAAsC,OAAA;AAC/C,yGAAwG;AAA/F,sJAAA,iCAAiC,OAAA;AAE1C,2DAA0D;AAAjD,0GAAA,WAAW,OAAA;AACpB,uEAAsE;AAA7D,sHAAA,iBAAiB,OAAA;AAC1B,mFAAkF;AAAzE,kIAAA,uBAAuB,OAAA;AAChC,uFAAsF;AAA7E,sIAAA,yBAAyB,OAAA;AAClC,4EAA2E;AAAlE,0HAAA,mBAAmB,OAAA;AAC5B,uDAAsD;AAA7C,sGAAA,SAAS,OAAA;AAClB,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"]}
@@ -0,0 +1,9 @@
1
+ import type { ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Query content model blocks
4
+ * @param group The block group to query
5
+ * @param type The type of block to query
6
+ * @param filter Optional selector to filter the blocks
7
+ * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ */
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[];
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.queryContentModelBlocks = void 0;
4
+ var tslib_1 = require("tslib");
5
+ /**
6
+ * Query content model blocks
7
+ * @param group The block group to query
8
+ * @param type The type of block to query
9
+ * @param filter Optional selector to filter the blocks
10
+ * @param findFirstOnly True to return the first block only, false to return all blocks
11
+ */
12
+ function queryContentModelBlocks(group, type, filter, findFirstOnly) {
13
+ var e_1, _a, e_2, _b;
14
+ var elements = [];
15
+ for (var i = 0; i < group.blocks.length; i++) {
16
+ if (findFirstOnly && elements.length > 0) {
17
+ return elements;
18
+ }
19
+ var block = group.blocks[i];
20
+ switch (block.blockType) {
21
+ case 'Paragraph':
22
+ case 'Divider':
23
+ case 'Entity':
24
+ if (isExpectedBlockType(block, type, filter)) {
25
+ elements.push(block);
26
+ }
27
+ break;
28
+ case 'BlockGroup':
29
+ if (isExpectedBlockType(block, type, filter)) {
30
+ elements.push(block);
31
+ }
32
+ var results = queryContentModelBlocks(block, type, filter, findFirstOnly);
33
+ elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results), false));
34
+ break;
35
+ case 'Table':
36
+ if (isExpectedBlockType(block, type, filter)) {
37
+ elements.push(block);
38
+ }
39
+ try {
40
+ for (var _c = (e_1 = void 0, (0, tslib_1.__values)(block.rows)), _d = _c.next(); !_d.done; _d = _c.next()) {
41
+ var row = _d.value;
42
+ try {
43
+ for (var _e = (e_2 = void 0, (0, tslib_1.__values)(row.cells)), _f = _e.next(); !_f.done; _f = _e.next()) {
44
+ 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));
47
+ }
48
+ }
49
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
50
+ finally {
51
+ try {
52
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
53
+ }
54
+ finally { if (e_2) throw e_2.error; }
55
+ }
56
+ }
57
+ }
58
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59
+ finally {
60
+ try {
61
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
62
+ }
63
+ finally { if (e_1) throw e_1.error; }
64
+ }
65
+ break;
66
+ }
67
+ }
68
+ return elements;
69
+ }
70
+ exports.queryContentModelBlocks = queryContentModelBlocks;
71
+ function isExpectedBlockType(block, type, filter) {
72
+ return isBlockType(block, type) && (!filter || filter(block));
73
+ }
74
+ function isBlockType(block, type) {
75
+ return block.blockType == type;
76
+ }
77
+ //# sourceMappingURL=queryContentModelBlocks.js.map
@@ -0,0 +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,KAAK,QAAQ;gBACT,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE;oBAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACxB;gBACD,MAAM;YACV,KAAK,YAAY;gBACb,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE;oBAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACxB;gBACD,IAAM,OAAO,GAAG,uBAAuB,CAAI,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;gBAC/E,QAAQ,CAAC,IAAI,OAAb,QAAQ,qDAAS,OAAO,WAAE;gBAC1B,MAAM;YACV,KAAK,OAAO;gBACR,IAAI,mBAAmB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE;oBAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACxB;;oBACD,KAAkB,IAAA,oBAAA,sBAAA,KAAK,CAAC,IAAI,CAAA,CAAA,gBAAA,4BAAE;wBAAzB,IAAM,GAAG,WAAA;;4BACV,KAAmB,IAAA,oBAAA,sBAAA,GAAG,CAAC,KAAK,CAAA,CAAA,gBAAA,4BAAE;gCAAzB,IAAM,IAAI,WAAA;gCACX,IAAM,SAAO,GAAG,uBAAuB,CACnC,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,aAAa,CAChB,CAAC;gCACF,QAAQ,CAAC,IAAI,OAAb,QAAQ,qDAAS,SAAO,WAAE;6BAC7B;;;;;;;;;qBACJ;;;;;;;;;gBACD,MAAM;SACb;KACJ;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AA/CD,0DA+CC;AAED,SAAS,mBAAmB,CACxB,KAAgC,EAChC,IAA2B,EAC3B,MAAqC;IAErC,OAAO,WAAW,CAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,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"]}
@@ -15,9 +15,10 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
15
15
  */
16
16
  function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, segmentHasStyleCallback, includingFormatHolder, afterFormatCallback) {
17
17
  editor.formatContentModel(function (model, context) {
18
- var segmentAndParagraphs = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, !!includingFormatHolder, false /*includingEntity*/, true /*mutate*/);
18
+ var segmentAndParagraphs = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, !!includingFormatHolder, true /*includingEntity*/, true /*mutate*/);
19
19
  var isCollapsedSelection = segmentAndParagraphs.length >= 1 &&
20
20
  segmentAndParagraphs.every(function (x) { return x[0].segmentType == 'SelectionMarker'; });
21
+ // 1. adjust selection to a word if selection is collapsed
21
22
  if (isCollapsedSelection) {
22
23
  var para_1 = segmentAndParagraphs[0][1];
23
24
  var path_1 = segmentAndParagraphs[0][2];
@@ -26,24 +27,43 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
26
27
  isCollapsedSelection = false;
27
28
  }
28
29
  }
29
- var formatsAndSegments = segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
30
+ // 2. expand selection for entities if any
31
+ var formatsAndSegments = [];
32
+ var modelsFromEntities = [];
33
+ segmentAndParagraphs.forEach(function (item) {
34
+ if (item[0].segmentType == 'Entity') {
35
+ expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);
36
+ }
37
+ else {
38
+ formatsAndSegments.push([item[0].format, item[0], item[1]]);
39
+ }
40
+ });
41
+ // 3. check if we should turn format on (when not all selection has the required format already)
42
+ // or off (all selections already have the required format)
30
43
  var isTurningOff = segmentHasStyleCallback
31
44
  ? formatsAndSegments.every(function (_a) {
32
45
  var _b = (0, tslib_1.__read)(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
33
46
  return segmentHasStyleCallback(format, segment, paragraph);
34
47
  })
35
48
  : false;
49
+ // 4. invoke the callback function to apply the format
36
50
  formatsAndSegments.forEach(function (_a) {
37
51
  var _b = (0, tslib_1.__read)(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
38
52
  toggleStyleCallback(format, !isTurningOff, segment, paragraph);
39
53
  });
54
+ // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back
40
55
  afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
56
+ // 6. finally merge segments if possible, to avoid fragmentation
41
57
  formatsAndSegments.forEach(function (_a) {
42
58
  var _b = (0, tslib_1.__read)(_a, 3), _ = _b[0], __ = _b[1], paragraph = _b[2];
43
59
  if (paragraph) {
44
60
  (0, roosterjs_content_model_dom_1.mergeTextSegments)(paragraph);
45
61
  }
46
62
  });
63
+ // 7. Write back models that we got from entities (if any)
64
+ writeBackEntities(editor, modelsFromEntities);
65
+ // 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
66
+ // otherwise, write back to editor
47
67
  if (isCollapsedSelection) {
48
68
  context.newPendingFormat = segmentAndParagraphs[0][0].format;
49
69
  editor.focus();
@@ -57,4 +77,56 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
57
77
  });
58
78
  }
59
79
  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
+ function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
99
+ var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
100
+ if (id && type) {
101
+ var formattableRoots = [];
102
+ var entityOperationEventData = {
103
+ entity: { id: id, type: type, isReadonly: !!isReadonly, wrapper: entity.wrapper },
104
+ operation: 'beforeFormat',
105
+ formattableRoots: formattableRoots,
106
+ };
107
+ editor.triggerEvent('entityOperation', entityOperationEventData);
108
+ formattableRoots.forEach(function (root) {
109
+ if (entity.wrapper.contains(root.element)) {
110
+ var editorContext = createEditorContextForEntity(editor, entity);
111
+ var context = (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext, root.domToModelOptions);
112
+ // Treat everything as selected since the parent entity is selected
113
+ context.isInSelection = true;
114
+ var model = (0, roosterjs_content_model_dom_1.domToContentModel)(root.element, context);
115
+ var selections = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, false /*includingFormatHolder*/, false /*includingEntity*/, true /*mutate*/);
116
+ selections.forEach(function (item) {
117
+ formatsAndSegments.push([item[0].format, item[0], item[1]]);
118
+ });
119
+ modelsFromEntities.push([entity, root, model]);
120
+ }
121
+ });
122
+ }
123
+ }
124
+ function writeBackEntities(editor, modelsFromEntities) {
125
+ modelsFromEntities.forEach(function (_a) {
126
+ var _b = (0, tslib_1.__read)(_a, 3), entity = _b[0], root = _b[1], model = _b[2];
127
+ var editorContext = createEditorContextForEntity(editor, entity);
128
+ var modelToDomContext = (0, roosterjs_content_model_dom_1.createModelToDomContext)(editorContext, root.modelToDomOptions);
129
+ (0, roosterjs_content_model_dom_1.contentModelToDom)(editor.getDocument(), root.element, model, modelToDomContext);
130
+ });
131
+ }
60
132
  //# sourceMappingURL=formatSegmentWithContentModel.js.map
@@ -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,2EAAkG;AASlG;;;;;;;;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,KAAK,CAAC,mBAAmB,EACzB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,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QAAA,EAAE,SAAS,QAAA;YACnD,mBAAmB,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;QAEH,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAC;QAE7B,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAkB;gBAAlB,KAAA,0BAAkB,EAAjB,CAAC,QAAA,EAAE,EAAE,QAAA,EAAE,SAAS,QAAA;YACzC,IAAI,SAAS,EAAE;gBACX,IAAA,+CAAiB,EAAC,SAAS,CAAC,CAAC;aAChC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,oBAAoB,EAAE;YACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;SAChB;aAAM;YACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;SACxC;IACL,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC;AA/ED,sEA+EC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs, mergeTextSegments } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n IEditor,\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 false /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\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 const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n afterFormatCallback?.(model);\n\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\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"]}
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,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,EAA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,CAAC;gBAChE,CAAC,CAAC,CAAC;gBAEH,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,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,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,IAAA,+CAAiB,EAAC,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"]}
@@ -20,6 +20,9 @@ function formatTextSegmentBeforeSelectionMarker(editor, callback, options) {
20
20
  var previousSegment = paragraph.segments[markerIndex - 1];
21
21
  if (previousSegment && previousSegment.segmentType === 'Text') {
22
22
  result = true;
23
+ // Preserve pending format if any when format text segment, so if there is pending format (e.g. from paste)
24
+ // and some auto action happens after paste, the pending format will still take effect
25
+ context.newPendingFormat = 'preserve';
23
26
  rewrite = callback(model, previousSegment, paragraph, marker.format, context);
24
27
  }
25
28
  });
@@ -1 +1 @@
1
- {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":";;;AAAA,2EAA8F;AAW9F;;;;;GAKG;AACH,SAAgB,sCAAsC,CAClD,MAAe,EACf,QAMY,EACZ,OAAmC;IAEnC,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;QACrC,IAAM,6BAA6B,GAAG,IAAA,8DAAgC,EAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;QACF,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,IACI,6BAA6B,CAAC,MAAM,GAAG,CAAC;YACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB;YACpE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC;YACE,IAAA,2CAAa,EACT,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,UAAC,MAAM,EAAE,SAAS,EAAE,WAAW;gBAC3B,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;gBAE5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;oBAC3D,MAAM,GAAG,IAAI,CAAC;oBACd,OAAO,GAAG,QAAQ,CACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,MAAM,CAAC,MAAM,EACb,OAAO,CACV,CAAC;iBACL;YACL,CAAC,CACJ,CAAC;SACL;QAED,OAAO,OAAO,CAAC;IACnB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAClB,CAAC;AAjDD,wFAiDC","sourcesContent":["import { getSelectedSegmentsAndParagraphs, mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n ShallowMutableContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the text segment before the selection marker using Content Model\n * @param editor The editor object\n * @param callback The callback to format the text segment.\n * @returns True if the segment before cursor is found and callback is called, otherwise false\n */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ShallowMutableContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean,\n options?: FormatContentModelOptions\n): boolean {\n let result = false;\n\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n let rewrite = false;\n\n if (\n selectedSegmentsAndParagraphs.length > 0 &&\n selectedSegmentsAndParagraphs[0][0].segmentType == 'SelectionMarker' &&\n selectedSegmentsAndParagraphs[0][1]\n ) {\n mutateSegment(\n selectedSegmentsAndParagraphs[0][1],\n selectedSegmentsAndParagraphs[0][0],\n (marker, paragraph, markerIndex) => {\n const previousSegment = paragraph.segments[markerIndex - 1];\n\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n rewrite = callback(\n model,\n previousSegment,\n paragraph,\n marker.format,\n context\n );\n }\n }\n );\n }\n\n return rewrite;\n }, options);\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":";;;AAAA,2EAA8F;AAW9F;;;;;GAKG;AACH,SAAgB,sCAAsC,CAClD,MAAe,EACf,QAMY,EACZ,OAAmC;IAEnC,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;QACrC,IAAM,6BAA6B,GAAG,IAAA,8DAAgC,EAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;QACF,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,IACI,6BAA6B,CAAC,MAAM,GAAG,CAAC;YACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB;YACpE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC;YACE,IAAA,2CAAa,EACT,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,UAAC,MAAM,EAAE,SAAS,EAAE,WAAW;gBAC3B,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;gBAE5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;oBAC3D,MAAM,GAAG,IAAI,CAAC;oBAEd,2GAA2G;oBAC3G,sFAAsF;oBACtF,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;oBAEtC,OAAO,GAAG,QAAQ,CACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,MAAM,CAAC,MAAM,EACb,OAAO,CACV,CAAC;iBACL;YACL,CAAC,CACJ,CAAC;SACL;QAED,OAAO,OAAO,CAAC;IACnB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAClB,CAAC;AAtDD,wFAsDC","sourcesContent":["import { getSelectedSegmentsAndParagraphs, mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n ShallowMutableContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the text segment before the selection marker using Content Model\n * @param editor The editor object\n * @param callback The callback to format the text segment.\n * @returns True if the segment before cursor is found and callback is called, otherwise false\n */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ShallowMutableContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean,\n options?: FormatContentModelOptions\n): boolean {\n let result = false;\n\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n let rewrite = false;\n\n if (\n selectedSegmentsAndParagraphs.length > 0 &&\n selectedSegmentsAndParagraphs[0][0].segmentType == 'SelectionMarker' &&\n selectedSegmentsAndParagraphs[0][1]\n ) {\n mutateSegment(\n selectedSegmentsAndParagraphs[0][1],\n selectedSegmentsAndParagraphs[0][0],\n (marker, paragraph, markerIndex) => {\n const previousSegment = paragraph.segments[markerIndex - 1];\n\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n\n // Preserve pending format if any when format text segment, so if there is pending format (e.g. from paste)\n // and some auto action happens after paste, the pending format will still take effect\n context.newPendingFormat = 'preserve';\n\n rewrite = callback(\n model,\n previousSegment,\n paragraph,\n marker.format,\n context\n );\n }\n }\n );\n }\n\n return rewrite;\n }, options);\n\n return result;\n}\n"]}
@@ -58,3 +58,4 @@ export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
59
  export { promoteLink } from './modelApi/link/promoteLink';
60
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
61
+ export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
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"], 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) {
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) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getListAnnounceData = exports.promoteLink = exports.matchLink = exports.setModelIndentation = exports.findListItemsInSameThread = exports.setModelListStartNumber = exports.setModelListStyle = exports.setListType = exports.formatInsertPointWithContentModel = exports.formatTextSegmentBeforeSelectionMarker = exports.formatSegmentWithContentModel = exports.formatParagraphWithContentModel = exports.formatImageWithContentModel = exports.formatTableWithContentModel = exports.clearSelectedCells = exports.insertTableColumn = exports.insertTableRow = exports.insertEntity = exports.toggleCode = exports.setParagraphMargin = exports.adjustImageSelection = exports.setImageAltText = exports.adjustLinkSelection = exports.removeLink = exports.insertLink = exports.clearFormat = exports.getFormatState = exports.changeImage = exports.setImageBoxShadow = exports.setImageBorder = exports.setSpacing = exports.toggleBlockQuote = exports.setHeadingLevel = exports.setDirection = exports.setAlignment = exports.setIndentation = exports.setListStartNumber = exports.setListStyle = exports.insertImage = exports.splitTextSegment = exports.changeCapitalization = exports.applySegmentFormat = exports.changeFontSize = exports.setTextColor = exports.setFontSize = exports.setFontName = exports.setBackgroundColor = exports.toggleSuperscript = exports.toggleSubscript = exports.toggleStrikethrough = exports.toggleUnderline = exports.toggleItalic = exports.toggleBold = exports.toggleNumbering = exports.toggleBullet = exports.applyTableBorderFormat = exports.editTable = exports.setTableCellShade = exports.formatTable = exports.insertTable = void 0;
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;
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; } });
@@ -62,5 +62,6 @@ define(["require", "exports", "./publicApi/table/insertTable", "./publicApi/tabl
62
62
  Object.defineProperty(exports, "matchLink", { enumerable: true, get: function () { return matchLink_1.matchLink; } });
63
63
  Object.defineProperty(exports, "promoteLink", { enumerable: true, get: function () { return promoteLink_1.promoteLink; } });
64
64
  Object.defineProperty(exports, "getListAnnounceData", { enumerable: true, get: function () { return getListAnnounceData_1.getListAnnounceData; } });
65
+ Object.defineProperty(exports, "queryContentModelBlocks", { enumerable: true, get: function () { return queryContentModelBlocks_1.queryContentModelBlocks; } });
65
66
  });
66
67
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB,OAAA;IACtB,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,wGAAA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AA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0GAAA,WAAW,OAAA;IACX,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
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;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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"]}
@@ -0,0 +1,9 @@
1
+ import type { ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Query content model blocks
4
+ * @param group The block group to query
5
+ * @param type The type of block to query
6
+ * @param filter Optional selector to filter the blocks
7
+ * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ */
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[];
@@ -0,0 +1,78 @@
1
+ define(["require", "exports", "tslib"], function (require, exports, tslib_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.queryContentModelBlocks = void 0;
5
+ /**
6
+ * Query content model blocks
7
+ * @param group The block group to query
8
+ * @param type The type of block to query
9
+ * @param filter Optional selector to filter the blocks
10
+ * @param findFirstOnly True to return the first block only, false to return all blocks
11
+ */
12
+ function queryContentModelBlocks(group, type, filter, findFirstOnly) {
13
+ var e_1, _a, e_2, _b;
14
+ var elements = [];
15
+ for (var i = 0; i < group.blocks.length; i++) {
16
+ if (findFirstOnly && elements.length > 0) {
17
+ return elements;
18
+ }
19
+ var block = group.blocks[i];
20
+ switch (block.blockType) {
21
+ case 'Paragraph':
22
+ case 'Divider':
23
+ case 'Entity':
24
+ if (isExpectedBlockType(block, type, filter)) {
25
+ elements.push(block);
26
+ }
27
+ break;
28
+ case 'BlockGroup':
29
+ if (isExpectedBlockType(block, type, filter)) {
30
+ elements.push(block);
31
+ }
32
+ var results = queryContentModelBlocks(block, type, filter, findFirstOnly);
33
+ elements.push.apply(elements, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(results), false));
34
+ break;
35
+ case 'Table':
36
+ if (isExpectedBlockType(block, type, filter)) {
37
+ elements.push(block);
38
+ }
39
+ try {
40
+ for (var _c = (e_1 = void 0, (0, tslib_1.__values)(block.rows)), _d = _c.next(); !_d.done; _d = _c.next()) {
41
+ var row = _d.value;
42
+ try {
43
+ for (var _e = (e_2 = void 0, (0, tslib_1.__values)(row.cells)), _f = _e.next(); !_f.done; _f = _e.next()) {
44
+ 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));
47
+ }
48
+ }
49
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
50
+ finally {
51
+ try {
52
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
53
+ }
54
+ finally { if (e_2) throw e_2.error; }
55
+ }
56
+ }
57
+ }
58
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
59
+ finally {
60
+ try {
61
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
62
+ }
63
+ finally { if (e_1) throw e_1.error; }
64
+ }
65
+ break;
66
+ }
67
+ }
68
+ return elements;
69
+ }
70
+ exports.queryContentModelBlocks = queryContentModelBlocks;
71
+ function isExpectedBlockType(block, type, filter) {
72
+ return isBlockType(block, type) && (!filter || filter(block));
73
+ }
74
+ function isBlockType(block, type) {
75
+ return block.blockType == type;
76
+ }
77
+ });
78
+ //# sourceMappingURL=queryContentModelBlocks.js.map
@@ -0,0 +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,IAAkE,EAClE,MAAqC,EACrC,aAAuB;;QAEvB,IAAM,QAAQ,GAAQ,EAAE,CAAC;QACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,M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AQ,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"]}
@@ -13,9 +13,10 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
13
13
  */
14
14
  function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, segmentHasStyleCallback, includingFormatHolder, afterFormatCallback) {
15
15
  editor.formatContentModel(function (model, context) {
16
- var segmentAndParagraphs = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, !!includingFormatHolder, false /*includingEntity*/, true /*mutate*/);
16
+ var segmentAndParagraphs = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, !!includingFormatHolder, true /*includingEntity*/, true /*mutate*/);
17
17
  var isCollapsedSelection = segmentAndParagraphs.length >= 1 &&
18
18
  segmentAndParagraphs.every(function (x) { return x[0].segmentType == 'SelectionMarker'; });
19
+ // 1. adjust selection to a word if selection is collapsed
19
20
  if (isCollapsedSelection) {
20
21
  var para_1 = segmentAndParagraphs[0][1];
21
22
  var path_1 = segmentAndParagraphs[0][2];
@@ -24,24 +25,43 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
24
25
  isCollapsedSelection = false;
25
26
  }
26
27
  }
27
- var formatsAndSegments = segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
28
+ // 2. expand selection for entities if any
29
+ var formatsAndSegments = [];
30
+ var modelsFromEntities = [];
31
+ segmentAndParagraphs.forEach(function (item) {
32
+ if (item[0].segmentType == 'Entity') {
33
+ expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);
34
+ }
35
+ else {
36
+ formatsAndSegments.push([item[0].format, item[0], item[1]]);
37
+ }
38
+ });
39
+ // 3. check if we should turn format on (when not all selection has the required format already)
40
+ // or off (all selections already have the required format)
28
41
  var isTurningOff = segmentHasStyleCallback
29
42
  ? formatsAndSegments.every(function (_a) {
30
43
  var _b = (0, tslib_1.__read)(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
31
44
  return segmentHasStyleCallback(format, segment, paragraph);
32
45
  })
33
46
  : false;
47
+ // 4. invoke the callback function to apply the format
34
48
  formatsAndSegments.forEach(function (_a) {
35
49
  var _b = (0, tslib_1.__read)(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
36
50
  toggleStyleCallback(format, !isTurningOff, segment, paragraph);
37
51
  });
52
+ // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back
38
53
  afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
54
+ // 6. finally merge segments if possible, to avoid fragmentation
39
55
  formatsAndSegments.forEach(function (_a) {
40
56
  var _b = (0, tslib_1.__read)(_a, 3), _ = _b[0], __ = _b[1], paragraph = _b[2];
41
57
  if (paragraph) {
42
58
  (0, roosterjs_content_model_dom_1.mergeTextSegments)(paragraph);
43
59
  }
44
60
  });
61
+ // 7. Write back models that we got from entities (if any)
62
+ writeBackEntities(editor, modelsFromEntities);
63
+ // 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
64
+ // otherwise, write back to editor
45
65
  if (isCollapsedSelection) {
46
66
  context.newPendingFormat = segmentAndParagraphs[0][0].format;
47
67
  editor.focus();
@@ -55,5 +75,57 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
55
75
  });
56
76
  }
57
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
+ function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
97
+ var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
98
+ if (id && type) {
99
+ var formattableRoots = [];
100
+ var entityOperationEventData = {
101
+ entity: { id: id, type: type, isReadonly: !!isReadonly, wrapper: entity.wrapper },
102
+ operation: 'beforeFormat',
103
+ formattableRoots: formattableRoots,
104
+ };
105
+ editor.triggerEvent('entityOperation', entityOperationEventData);
106
+ formattableRoots.forEach(function (root) {
107
+ if (entity.wrapper.contains(root.element)) {
108
+ var editorContext = createEditorContextForEntity(editor, entity);
109
+ var context = (0, roosterjs_content_model_dom_1.createDomToModelContext)(editorContext, root.domToModelOptions);
110
+ // Treat everything as selected since the parent entity is selected
111
+ context.isInSelection = true;
112
+ var model = (0, roosterjs_content_model_dom_1.domToContentModel)(root.element, context);
113
+ var selections = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, false /*includingFormatHolder*/, false /*includingEntity*/, true /*mutate*/);
114
+ selections.forEach(function (item) {
115
+ formatsAndSegments.push([item[0].format, item[0], item[1]]);
116
+ });
117
+ modelsFromEntities.push([entity, root, model]);
118
+ }
119
+ });
120
+ }
121
+ }
122
+ function writeBackEntities(editor, modelsFromEntities) {
123
+ modelsFromEntities.forEach(function (_a) {
124
+ var _b = (0, tslib_1.__read)(_a, 3), entity = _b[0], root = _b[1], model = _b[2];
125
+ var editorContext = createEditorContextForEntity(editor, entity);
126
+ var modelToDomContext = (0, roosterjs_content_model_dom_1.createModelToDomContext)(editorContext, root.modelToDomOptions);
127
+ (0, roosterjs_content_model_dom_1.contentModelToDom)(editor.getDocument(), root.element, model, modelToDomContext);
128
+ });
129
+ }
58
130
  });
59
131
  //# sourceMappingURL=formatSegmentWithContentModel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IAUA;;;;;;;;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,KAAK,CAAC,mBAAmB,EACzB,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,IAAI,oBAAoB,EAAE;gBACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxC,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAExC,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;gBAE5B,IAA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AC;gBAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;aAChB;iBAAM;gBACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;aACxC;QACL,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IA/ED,sEA+EC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs, mergeTextSegments } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n IEditor,\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 false /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\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 const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n afterFormatCallback?.(model);\n\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\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"]}
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,oBAA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AAW,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"]}
@@ -20,6 +20,9 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
20
20
  var previousSegment = paragraph.segments[markerIndex - 1];
21
21
  if (previousSegment && previousSegment.segmentType === 'Text') {
22
22
  result = true;
23
+ // Preserve pending format if any when format text segment, so if there is pending format (e.g. from paste)
24
+ // and some auto action happens after paste, the pending format will still take effect
25
+ context.newPendingFormat = 'preserve';
23
26
  rewrite = callback(model, previousSegment, paragraph, marker.format, context);
24
27
  }
25
28
  });
@@ -1 +1 @@
1
- {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":";;;;IAWA;;;;;OAKG;IACH,SAAgB,sCAAsC,CAClD,MAAe,EACf,QAMY,EACZ,OAAmC;QAEnC,IAAI,MAAM,GAAG,KAAK,CAAC;QAEnB,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;YACrC,IAAM,6BAA6B,GAAG,IAAA,8DAAgC,EAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;YACF,IAAI,OAAO,GAAG,KAAK,CAAC;YAEpB,IACI,6BAA6B,CAAC,MAAM,GAAG,CAAC;gBACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB;gBACpE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC;gBACE,IAAA,2CAAa,EACT,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,UAAC,MAAM,EAAE,SAAS,EAAE,WAAW;oBAC3B,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;oBAE5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;wBAC3D,MAAM,GAAG,IAAI,CAAC;wBACd,OAAO,GAAG,QAAQ,CACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,MAAM,CAAC,MAAM,EACb,OAAO,CACV,CAAC;qBACL;gBACL,CAAC,CACJ,CAAC;aACL;YAED,OAAO,OAAO,CAAC;QACnB,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,OAAO,MAAM,CAAC;IAClB,CAAC;IAjDD,wFAiDC","sourcesContent":["import { getSelectedSegmentsAndParagraphs, mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n ShallowMutableContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the text segment before the selection marker using Content Model\n * @param editor The editor object\n * @param callback The callback to format the text segment.\n * @returns True if the segment before cursor is found and callback is called, otherwise false\n */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ShallowMutableContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean,\n options?: FormatContentModelOptions\n): boolean {\n let result = false;\n\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n let rewrite = false;\n\n if (\n selectedSegmentsAndParagraphs.length > 0 &&\n selectedSegmentsAndParagraphs[0][0].segmentType == 'SelectionMarker' &&\n selectedSegmentsAndParagraphs[0][1]\n ) {\n mutateSegment(\n selectedSegmentsAndParagraphs[0][1],\n selectedSegmentsAndParagraphs[0][0],\n (marker, paragraph, markerIndex) => {\n const previousSegment = paragraph.segments[markerIndex - 1];\n\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n rewrite = callback(\n model,\n previousSegment,\n paragraph,\n marker.format,\n context\n );\n }\n }\n );\n }\n\n return rewrite;\n }, options);\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":";;;;IAWA;;;;;OAKG;IACH,SAAgB,sCAAsC,CAClD,MAAe,EACf,QAMY,EACZ,OAAmC;QAEnC,IAAI,MAAM,GAAG,KAAK,CAAC;QAEnB,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;YACrC,IAAM,6BAA6B,GAAG,IAAA,8DAAgC,EAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;YACF,IAAI,OAAO,GAAG,KAAK,CAAC;YAEpB,IACI,6BAA6B,CAAC,MAAM,GAAG,CAAC;gBACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB;gBACpE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC;gBACE,IAAA,2CAAa,EACT,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,UAAC,MAAM,EAAE,SAAS,EAAE,WAAW;oBAC3B,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;oBAE5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;wBAC3D,MAAM,GAAG,IAAI,CAAC;wBAEd,2GAA2G;wBAC3G,sFAAsF;wBACtF,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;wBAEtC,OAAO,GAAG,QAAQ,CACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,MAAM,CAAC,MAAM,EACb,OAAO,CACV,CAAC;qBACL;gBACL,CAAC,CACJ,CAAC;aACL;YAED,OAAO,OAAO,CAAC;QACnB,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,OAAO,MAAM,CAAC;IAClB,CAAC;IAtDD,wFAsDC","sourcesContent":["import { getSelectedSegmentsAndParagraphs, mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n ShallowMutableContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the text segment before the selection marker using Content Model\n * @param editor The editor object\n * @param callback The callback to format the text segment.\n * @returns True if the segment before cursor is found and callback is called, otherwise false\n */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ShallowMutableContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean,\n options?: FormatContentModelOptions\n): boolean {\n let result = false;\n\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n let rewrite = false;\n\n if (\n selectedSegmentsAndParagraphs.length > 0 &&\n selectedSegmentsAndParagraphs[0][0].segmentType == 'SelectionMarker' &&\n selectedSegmentsAndParagraphs[0][1]\n ) {\n mutateSegment(\n selectedSegmentsAndParagraphs[0][1],\n selectedSegmentsAndParagraphs[0][0],\n (marker, paragraph, markerIndex) => {\n const previousSegment = paragraph.segments[markerIndex - 1];\n\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n\n // Preserve pending format if any when format text segment, so if there is pending format (e.g. from paste)\n // and some auto action happens after paste, the pending format will still take effect\n context.newPendingFormat = 'preserve';\n\n rewrite = callback(\n model,\n previousSegment,\n paragraph,\n marker.format,\n context\n );\n }\n }\n );\n }\n\n return rewrite;\n }, options);\n\n return result;\n}\n"]}
@@ -58,3 +58,4 @@ export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
59
  export { promoteLink } from './modelApi/link/promoteLink';
60
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
61
+ export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
package/lib-mjs/index.js CHANGED
@@ -58,4 +58,5 @@ export { setModelIndentation } from './modelApi/block/setModelIndentation';
58
58
  export { matchLink } from './modelApi/link/matchLink';
59
59
  export { promoteLink } from './modelApi/link/promoteLink';
60
60
  export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
61
+ export { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';
61
62
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,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;A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AAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
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,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AChG,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 { 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"]}
@@ -0,0 +1,9 @@
1
+ import type { ReadonlyContentModelBlock, ReadonlyContentModelBlockBase, ReadonlyContentModelBlockGroup } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Query content model blocks
4
+ * @param group The block group to query
5
+ * @param type The type of block to query
6
+ * @param filter Optional selector to filter the blocks
7
+ * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ */
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[];
@@ -0,0 +1,73 @@
1
+ import { __read, __spreadArray, __values } from "tslib";
2
+ /**
3
+ * Query content model blocks
4
+ * @param group The block group to query
5
+ * @param type The type of block to query
6
+ * @param filter Optional selector to filter the blocks
7
+ * @param findFirstOnly True to return the first block only, false to return all blocks
8
+ */
9
+ export function queryContentModelBlocks(group, type, filter, findFirstOnly) {
10
+ var e_1, _a, e_2, _b;
11
+ var elements = [];
12
+ for (var i = 0; i < group.blocks.length; i++) {
13
+ if (findFirstOnly && elements.length > 0) {
14
+ return elements;
15
+ }
16
+ var block = group.blocks[i];
17
+ switch (block.blockType) {
18
+ case 'Paragraph':
19
+ case 'Divider':
20
+ case 'Entity':
21
+ if (isExpectedBlockType(block, type, filter)) {
22
+ elements.push(block);
23
+ }
24
+ break;
25
+ case 'BlockGroup':
26
+ if (isExpectedBlockType(block, type, filter)) {
27
+ elements.push(block);
28
+ }
29
+ var results = queryContentModelBlocks(block, type, filter, findFirstOnly);
30
+ elements.push.apply(elements, __spreadArray([], __read(results), false));
31
+ break;
32
+ case 'Table':
33
+ if (isExpectedBlockType(block, type, filter)) {
34
+ elements.push(block);
35
+ }
36
+ try {
37
+ for (var _c = (e_1 = void 0, __values(block.rows)), _d = _c.next(); !_d.done; _d = _c.next()) {
38
+ var row = _d.value;
39
+ try {
40
+ for (var _e = (e_2 = void 0, __values(row.cells)), _f = _e.next(); !_f.done; _f = _e.next()) {
41
+ var cell = _f.value;
42
+ var results_1 = queryContentModelBlocks(cell, type, filter, findFirstOnly);
43
+ elements.push.apply(elements, __spreadArray([], __read(results_1), false));
44
+ }
45
+ }
46
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
47
+ finally {
48
+ try {
49
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
50
+ }
51
+ finally { if (e_2) throw e_2.error; }
52
+ }
53
+ }
54
+ }
55
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
56
+ finally {
57
+ try {
58
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
59
+ }
60
+ finally { if (e_1) throw e_1.error; }
61
+ }
62
+ break;
63
+ }
64
+ }
65
+ return elements;
66
+ }
67
+ function isExpectedBlockType(block, type, filter) {
68
+ return isBlockType(block, type) && (!filter || filter(block));
69
+ }
70
+ function isBlockType(block, type) {
71
+ return block.blockType == type;
72
+ }
73
+ //# sourceMappingURL=queryContentModelBlocks.js.map
@@ -0,0 +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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I,EACJ,MAAM,EACN,aAAa,CAChB,CAAC;gCACF,QAAQ,CAAC,IAAI,OAAb,QAAQ,2BAAS,SAAO,WAAE;6BAC7B;;;;;;;;;qBACJ;;;;;;;;;gBACD,MAAM;SACb;KACJ;IACD,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAS,mBAAmB,CACxB,KAAgC,EAChC,IAA2B,EAC3B,MAAqC;IAErC,OAAO,WAAW,CAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,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,6 +1,6 @@
1
- import { __read } from "tslib";
1
+ import { __assign, __read } from "tslib";
2
2
  import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';
3
- import { getSelectedSegmentsAndParagraphs, mergeTextSegments } from 'roosterjs-content-model-dom';
3
+ import { contentModelToDom, createDomToModelContext, createModelToDomContext, domToContentModel, getSelectedSegmentsAndParagraphs, mergeTextSegments, } from 'roosterjs-content-model-dom';
4
4
  /**
5
5
  * Invoke a callback to format the selected segment using Content Model
6
6
  * @param editor The editor object
@@ -12,9 +12,10 @@ import { getSelectedSegmentsAndParagraphs, mergeTextSegments } from 'roosterjs-c
12
12
  */
13
13
  export function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, segmentHasStyleCallback, includingFormatHolder, afterFormatCallback) {
14
14
  editor.formatContentModel(function (model, context) {
15
- var segmentAndParagraphs = getSelectedSegmentsAndParagraphs(model, !!includingFormatHolder, false /*includingEntity*/, true /*mutate*/);
15
+ var segmentAndParagraphs = getSelectedSegmentsAndParagraphs(model, !!includingFormatHolder, true /*includingEntity*/, true /*mutate*/);
16
16
  var isCollapsedSelection = segmentAndParagraphs.length >= 1 &&
17
17
  segmentAndParagraphs.every(function (x) { return x[0].segmentType == 'SelectionMarker'; });
18
+ // 1. adjust selection to a word if selection is collapsed
18
19
  if (isCollapsedSelection) {
19
20
  var para_1 = segmentAndParagraphs[0][1];
20
21
  var path_1 = segmentAndParagraphs[0][2];
@@ -23,24 +24,43 @@ export function formatSegmentWithContentModel(editor, apiName, toggleStyleCallba
23
24
  isCollapsedSelection = false;
24
25
  }
25
26
  }
26
- var formatsAndSegments = segmentAndParagraphs.map(function (item) { return [item[0].format, item[0], item[1]]; });
27
+ // 2. expand selection for entities if any
28
+ var formatsAndSegments = [];
29
+ var modelsFromEntities = [];
30
+ segmentAndParagraphs.forEach(function (item) {
31
+ if (item[0].segmentType == 'Entity') {
32
+ expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);
33
+ }
34
+ else {
35
+ formatsAndSegments.push([item[0].format, item[0], item[1]]);
36
+ }
37
+ });
38
+ // 3. check if we should turn format on (when not all selection has the required format already)
39
+ // or off (all selections already have the required format)
27
40
  var isTurningOff = segmentHasStyleCallback
28
41
  ? formatsAndSegments.every(function (_a) {
29
42
  var _b = __read(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
30
43
  return segmentHasStyleCallback(format, segment, paragraph);
31
44
  })
32
45
  : false;
46
+ // 4. invoke the callback function to apply the format
33
47
  formatsAndSegments.forEach(function (_a) {
34
48
  var _b = __read(_a, 3), format = _b[0], segment = _b[1], paragraph = _b[2];
35
49
  toggleStyleCallback(format, !isTurningOff, segment, paragraph);
36
50
  });
51
+ // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back
37
52
  afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
53
+ // 6. finally merge segments if possible, to avoid fragmentation
38
54
  formatsAndSegments.forEach(function (_a) {
39
55
  var _b = __read(_a, 3), _ = _b[0], __ = _b[1], paragraph = _b[2];
40
56
  if (paragraph) {
41
57
  mergeTextSegments(paragraph);
42
58
  }
43
59
  });
60
+ // 7. Write back models that we got from entities (if any)
61
+ writeBackEntities(editor, modelsFromEntities);
62
+ // 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
63
+ // otherwise, write back to editor
44
64
  if (isCollapsedSelection) {
45
65
  context.newPendingFormat = segmentAndParagraphs[0][0].format;
46
66
  editor.focus();
@@ -53,4 +73,56 @@ export function formatSegmentWithContentModel(editor, apiName, toggleStyleCallba
53
73
  apiName: apiName,
54
74
  });
55
75
  }
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
+ function expandEntitySelections(editor, entity, formatsAndSegments, modelsFromEntities) {
95
+ var _a = entity.entityFormat, id = _a.id, type = _a.entityType, isReadonly = _a.isReadonly;
96
+ if (id && type) {
97
+ var formattableRoots = [];
98
+ var entityOperationEventData = {
99
+ entity: { id: id, type: type, isReadonly: !!isReadonly, wrapper: entity.wrapper },
100
+ operation: 'beforeFormat',
101
+ formattableRoots: formattableRoots,
102
+ };
103
+ editor.triggerEvent('entityOperation', entityOperationEventData);
104
+ formattableRoots.forEach(function (root) {
105
+ if (entity.wrapper.contains(root.element)) {
106
+ var editorContext = createEditorContextForEntity(editor, entity);
107
+ var context = createDomToModelContext(editorContext, root.domToModelOptions);
108
+ // Treat everything as selected since the parent entity is selected
109
+ context.isInSelection = true;
110
+ var model = domToContentModel(root.element, context);
111
+ var selections = getSelectedSegmentsAndParagraphs(model, false /*includingFormatHolder*/, false /*includingEntity*/, true /*mutate*/);
112
+ selections.forEach(function (item) {
113
+ formatsAndSegments.push([item[0].format, item[0], item[1]]);
114
+ });
115
+ modelsFromEntities.push([entity, root, model]);
116
+ }
117
+ });
118
+ }
119
+ }
120
+ function writeBackEntities(editor, modelsFromEntities) {
121
+ modelsFromEntities.forEach(function (_a) {
122
+ var _b = __read(_a, 3), entity = _b[0], root = _b[1], model = _b[2];
123
+ var editorContext = createEditorContextForEntity(editor, entity);
124
+ var modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);
125
+ contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);
126
+ });
127
+ }
56
128
  //# sourceMappingURL=formatSegmentWithContentModel.js.map
@@ -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,EAAE,gCAAgC,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AASlG;;;;;;;;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,KAAK,CAAC,mBAAmB,EACzB,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,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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,EAAE;gBACX,iBAAiB,CAAC,SAAS,CAAC,CAAC;aAChC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,oBAAoB,EAAE;YACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;YAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,OAAO,KAAK,CAAC;SAChB;aAAM;YACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;SACxC;IACL,CAAC,EACD;QACI,OAAO,SAAA;KACV,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs, mergeTextSegments } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n IEditor,\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 false /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\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 const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n afterFormatCallback?.(model);\n\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\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"]}
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,iBAAiB,EACjB,gCAAgC,EAChC,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAcrC;;;;;;;;GAQG;AACH,MAAM,UAAU,6B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AqB,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"]}
@@ -17,6 +17,9 @@ export function formatTextSegmentBeforeSelectionMarker(editor, callback, options
17
17
  var previousSegment = paragraph.segments[markerIndex - 1];
18
18
  if (previousSegment && previousSegment.segmentType === 'Text') {
19
19
  result = true;
20
+ // Preserve pending format if any when format text segment, so if there is pending format (e.g. from paste)
21
+ // and some auto action happens after paste, the pending format will still take effect
22
+ context.newPendingFormat = 'preserve';
20
23
  rewrite = callback(model, previousSegment, paragraph, marker.format, context);
21
24
  }
22
25
  });
@@ -1 +1 @@
1
- {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAW9F;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CAClD,MAAe,EACf,QAMY,EACZ,OAAmC;IAEnC,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;QACrC,IAAM,6BAA6B,GAAG,gCAAgC,CAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;QACF,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,IACI,6BAA6B,CAAC,MAAM,GAAG,CAAC;YACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB;YACpE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC;YACE,aAAa,CACT,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,UAAC,MAAM,EAAE,SAAS,EAAE,WAAW;gBAC3B,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;gBAE5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;oBAC3D,MAAM,GAAG,IAAI,CAAC;oBACd,OAAO,GAAG,QAAQ,CACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,MAAM,CAAC,MAAM,EACb,OAAO,CACV,CAAC;iBACL;YACL,CAAC,CACJ,CAAC;SACL;QAED,OAAO,OAAO,CAAC;IACnB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { getSelectedSegmentsAndParagraphs, mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n ShallowMutableContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the text segment before the selection marker using Content Model\n * @param editor The editor object\n * @param callback The callback to format the text segment.\n * @returns True if the segment before cursor is found and callback is called, otherwise false\n */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ShallowMutableContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean,\n options?: FormatContentModelOptions\n): boolean {\n let result = false;\n\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n let rewrite = false;\n\n if (\n selectedSegmentsAndParagraphs.length > 0 &&\n selectedSegmentsAndParagraphs[0][0].segmentType == 'SelectionMarker' &&\n selectedSegmentsAndParagraphs[0][1]\n ) {\n mutateSegment(\n selectedSegmentsAndParagraphs[0][1],\n selectedSegmentsAndParagraphs[0][0],\n (marker, paragraph, markerIndex) => {\n const previousSegment = paragraph.segments[markerIndex - 1];\n\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n rewrite = callback(\n model,\n previousSegment,\n paragraph,\n marker.format,\n context\n );\n }\n }\n );\n }\n\n return rewrite;\n }, options);\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAW9F;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CAClD,MAAe,EACf,QAMY,EACZ,OAAmC;IAEnC,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;QACrC,IAAM,6BAA6B,GAAG,gCAAgC,CAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;QACF,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,IACI,6BAA6B,CAAC,MAAM,GAAG,CAAC;YACxC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB;YACpE,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACrC;YACE,aAAa,CACT,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACnC,UAAC,MAAM,EAAE,SAAS,EAAE,WAAW;gBAC3B,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;gBAE5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;oBAC3D,MAAM,GAAG,IAAI,CAAC;oBAEd,2GAA2G;oBAC3G,sFAAsF;oBACtF,OAAO,CAAC,gBAAgB,GAAG,UAAU,CAAC;oBAEtC,OAAO,GAAG,QAAQ,CACd,KAAK,EACL,eAAe,EACf,SAAS,EACT,MAAM,CAAC,MAAM,EACb,OAAO,CACV,CAAC;iBACL;YACL,CAAC,CACJ,CAAC;SACL;QAED,OAAO,OAAO,CAAC;IACnB,CAAC,EAAE,OAAO,CAAC,CAAC;IAEZ,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import { getSelectedSegmentsAndParagraphs, mutateSegment } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n ShallowMutableContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the text segment before the selection marker using Content Model\n * @param editor The editor object\n * @param callback The callback to format the text segment.\n * @returns True if the segment before cursor is found and callback is called, otherwise false\n */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ShallowMutableContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean,\n options?: FormatContentModelOptions\n): boolean {\n let result = false;\n\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n let rewrite = false;\n\n if (\n selectedSegmentsAndParagraphs.length > 0 &&\n selectedSegmentsAndParagraphs[0][0].segmentType == 'SelectionMarker' &&\n selectedSegmentsAndParagraphs[0][1]\n ) {\n mutateSegment(\n selectedSegmentsAndParagraphs[0][1],\n selectedSegmentsAndParagraphs[0][0],\n (marker, paragraph, markerIndex) => {\n const previousSegment = paragraph.segments[markerIndex - 1];\n\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n\n // Preserve pending format if any when format text segment, so if there is pending format (e.g. from paste)\n // and some auto action happens after paste, the pending format will still take effect\n context.newPendingFormat = 'preserve';\n\n rewrite = callback(\n model,\n previousSegment,\n paragraph,\n marker.format,\n context\n );\n }\n }\n );\n }\n\n return rewrite;\n }, options);\n\n return result;\n}\n"]}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.14.0",
7
- "roosterjs-content-model-types": "^9.14.0"
6
+ "roosterjs-content-model-dom": "^9.16.0",
7
+ "roosterjs-content-model-types": "^9.16.0"
8
8
  },
9
- "version": "9.14.0",
9
+ "version": "9.16.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",