roosterjs-content-model-api 9.14.0 → 9.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -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,4GAAA,YAAY,OAAA;AACrB,uEAAsE;AAA7D,kH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B,+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;AAA7D,kHAAA,eAAe,OAAA;AACxB,2EAA0E;AA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,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"]}
@@ -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,0GA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A,+BAA+B,OAAA;IAC/B,8IAAA,6BAA6B,OAAA;IAC7B,gKAAA,sCAAsC,OAAA;IACtC,sJAAA,iCAAiC,OAAA;IAEjC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0GAAA,WAAW,OAAA;IACX,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB,OAAA;IACtB,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAClB,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,wHAAA,kBAAkB,OAAA;IAClB,4HAAA,oBAAoB,OAAA;IACpB,oHAAA,gBAAgB,OAAA;IAChB,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,wHAAA,kBAAkB,OAAA;IAClB,gHAAA,cAAc,OAAA;IACd,4GAAA,YAAY,OAAA;IACZ,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,oHAAA,gBAAgB,OAAA;IAChB,wGAAA,UAAU,OAAA;IACV,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,0GAAA,WAAW,OAAA;IACX,gHAAA,cAAc,OAAA;IACd,0GAAA,WAAW,OAAA;IACX,wGAAA,UAAU,OAAA;IACV,wGAAA,UAAU,OAAA;IACV,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,4HAAA,oBAAoB,OAAA;IACpB,wHAAA,kBAAkB,OAAA;IAClB,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAElB,0IAAA,2BAA2B,OAAA;IAC3B,0IAAA,2BAA2B,OAAA;IAC3B,kJAAA,+BAA+B,OAAA;IAC/B,8IAAA,6BAA6B,OAAA;IAC7B,gKAAA,sCAAsC,OAAA;IACtC,sJAAA,iCAAiC,OAAA;IAEjC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0GAAA,WAAW,OAAA;IACX,0HAAA,mBAAmB,OAAA;IACnB,kIAAA,uBAAuB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\nexport { queryContentModelBlocks } from './modelApi/common/queryContentModelBlocks';\n"]}
@@ -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,uB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,CAAA,CAAA,gBAAA,4BAAE;oCAAzB,IAAM,IAAI,WAAA;oCACX,IAAM,SAAO,GAAG,uBAAuB,CACnC,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,aAAa,CAChB,CAAC;oCACF,QAAQ,CAAC,IAAI,OAAb,QAAQ,qDAAS,SAAO,WAAE;iCAC7B;;;;;;;;;yBACJ;;;;;;;;;oBACD,MAAM;aACb;SACJ;QACD,OAAO,QAAQ,CAAC;IACpB,CAAC;IA/CD,0DA+CC;IAED,SAAS,mBAAmB,CACxB,KAAgC,EAChC,IAA2B,EAC3B,MAAqC;QAErC,OAAO,WAAW,CAAI,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,SAAS,WAAW,CAChB,KAAgC,EAChC,IAA2B;QAE3B,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,CAAC;IACnC,CAAC","sourcesContent":["import type {\n ContentModelBlockType,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockBase,\n ReadonlyContentModelBlockGroup,\n} from 'roosterjs-content-model-types';\n\n/**\n * Query content model blocks\n * @param group The block group to query\n * @param type The type of block to query\n * @param filter Optional selector to filter the blocks\n * @param findFirstOnly True to return the first block only, false to return all blocks\n */\nexport function queryContentModelBlocks<T extends ReadonlyContentModelBlock>(\n group: ReadonlyContentModelBlockGroup,\n type: T extends ReadonlyContentModelBlockBase<infer U> ? U : never,\n filter?: (element: T) => element is T,\n findFirstOnly?: boolean\n): T[] {\n const elements: T[] = [];\n for (let i = 0; i < group.blocks.length; i++) {\n if (findFirstOnly && elements.length > 0) {\n return elements;\n }\n const block = group.blocks[i];\n\n switch (block.blockType) {\n case 'Paragraph':\n case 'Divider':\n case 'Entity':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n break;\n case 'BlockGroup':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n const results = queryContentModelBlocks<T>(block, type, filter, findFirstOnly);\n elements.push(...results);\n break;\n case 'Table':\n if (isExpectedBlockType(block, type, filter)) {\n elements.push(block);\n }\n for (const row of block.rows) {\n for (const cell of row.cells) {\n const results = queryContentModelBlocks<T>(\n cell,\n type,\n filter,\n findFirstOnly\n );\n elements.push(...results);\n }\n }\n break;\n }\n }\n return elements;\n}\n\nfunction isExpectedBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType,\n filter?: (element: T) => element is T\n): block is T {\n return isBlockType<T>(block, type) && (!filter || filter(block));\n}\n\nfunction isBlockType<T extends ReadonlyContentModelBlock>(\n block: ReadonlyContentModelBlock,\n type: ContentModelBlockType\n): block is T {\n return block.blockType == type;\n}\n"]}
@@ -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,EA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AAE,MAAM,qDAAqD,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { splitTextSegment } from './publicApi/segment/splitTextSegment';\nexport { insertImage } from './publicApi/image/insertImage';\nexport { setListStyle } from './publicApi/list/setListStyle';\nexport { setListStartNumber } from './publicApi/list/setListStartNumber';\nexport { setIndentation } from './publicApi/block/setIndentation';\nexport { setAlignment } from './publicApi/block/setAlignment';\nexport { setDirection } from './publicApi/block/setDirection';\nexport { setHeadingLevel } from './publicApi/block/setHeadingLevel';\nexport { toggleBlockQuote } from './publicApi/block/toggleBlockQuote';\nexport { setSpacing } from './publicApi/block/setSpacing';\nexport { setImageBorder } from './publicApi/image/setImageBorder';\nexport { setImageBoxShadow } from './publicApi/image/setImageBoxShadow';\nexport { changeImage } from './publicApi/image/changeImage';\nexport { getFormatState } from './publicApi/format/getFormatState';\nexport { clearFormat } from './publicApi/format/clearFormat';\nexport { insertLink } from './publicApi/link/insertLink';\nexport { removeLink } from './publicApi/link/removeLink';\nexport { adjustLinkSelection } from './publicApi/link/adjustLinkSelection';\nexport { setImageAltText } from './publicApi/image/setImageAltText';\nexport { adjustImageSelection } from './publicApi/image/adjustImageSelection';\nexport { setParagraphMargin } from './publicApi/block/setParagraphMargin';\nexport { toggleCode } from './publicApi/segment/toggleCode';\nexport { insertEntity } from './publicApi/entity/insertEntity';\nexport { insertTableRow } from './modelApi/table/insertTableRow';\nexport { insertTableColumn } from './modelApi/table/insertTableColumn';\nexport { clearSelectedCells } from './modelApi/table/clearSelectedCells';\n\nexport { formatTableWithContentModel } from './publicApi/utils/formatTableWithContentModel';\nexport { formatImageWithContentModel } from './publicApi/utils/formatImageWithContentModel';\nexport { formatParagraphWithContentModel } from './publicApi/utils/formatParagraphWithContentModel';\nexport { formatSegmentWithContentModel } from './publicApi/utils/formatSegmentWithContentModel';\nexport { formatTextSegmentBeforeSelectionMarker } from './publicApi/utils/formatTextSegmentBeforeSelectionMarker';\nexport { formatInsertPointWithContentModel } from './publicApi/utils/formatInsertPointWithContentModel';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { promoteLink } from './modelApi/link/promoteLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCA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AAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,mDAAmD,CAAC;AACpG,OAAO,EAAE,6BAA6B,EAAE,MAAM,iDAAiD,CAAC;AAChG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0DAA0D,CAAC;AAClH,OAAO,EAAE,iCAAiC,EAAE,MAAM,qDAAqD,CAAC;AAExG,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;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;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,2BAAS,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,SAAA,KAAK,CAAC,IAAI,CAAA,CAAA,gBAAA,4BAAE;wBAAzB,IAAM,GAAG,WAAA;;4BACV,KAAmB,IAAA,oBAAA,SAAA,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,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"]}
@@ -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.15.0",
7
+ "roosterjs-content-model-types": "^9.15.0"
8
8
  },
9
- "version": "9.14.0",
9
+ "version": "9.15.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",