roosterjs-content-model-api 9.1.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/lib/index.d.ts +1 -0
  2. package/lib/index.js +3 -1
  3. package/lib/index.js.map +1 -1
  4. package/lib/modelApi/block/setModelIndentation.d.ts +2 -2
  5. package/lib/modelApi/block/setModelIndentation.js +6 -1
  6. package/lib/modelApi/block/setModelIndentation.js.map +1 -1
  7. package/lib/modelApi/list/findListItemsInSameThread.d.ts +2 -2
  8. package/lib/modelApi/list/findListItemsInSameThread.js +8 -4
  9. package/lib/modelApi/list/findListItemsInSameThread.js.map +1 -1
  10. package/lib/modelApi/list/getListAnnounceData.d.ts +7 -0
  11. package/lib/modelApi/list/getListAnnounceData.js +69 -0
  12. package/lib/modelApi/list/getListAnnounceData.js.map +1 -0
  13. package/lib/publicApi/image/insertImage.js +2 -0
  14. package/lib/publicApi/image/insertImage.js.map +1 -1
  15. package/lib/publicApi/table/editTable.js +17 -0
  16. package/lib/publicApi/table/editTable.js.map +1 -1
  17. package/lib/publicApi/utils/formatSegmentWithContentModel.js +2 -1
  18. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  19. package/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.d.ts +3 -2
  20. package/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js +6 -2
  21. package/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js.map +1 -1
  22. package/lib-amd/index.d.ts +1 -0
  23. package/lib-amd/index.js +3 -2
  24. package/lib-amd/index.js.map +1 -1
  25. package/lib-amd/modelApi/block/setModelIndentation.d.ts +2 -2
  26. package/lib-amd/modelApi/block/setModelIndentation.js +5 -2
  27. package/lib-amd/modelApi/block/setModelIndentation.js.map +1 -1
  28. package/lib-amd/modelApi/list/findListItemsInSameThread.d.ts +2 -2
  29. package/lib-amd/modelApi/list/findListItemsInSameThread.js +8 -4
  30. package/lib-amd/modelApi/list/findListItemsInSameThread.js.map +1 -1
  31. package/lib-amd/modelApi/list/getListAnnounceData.d.ts +7 -0
  32. package/lib-amd/modelApi/list/getListAnnounceData.js +69 -0
  33. package/lib-amd/modelApi/list/getListAnnounceData.js.map +1 -0
  34. package/lib-amd/publicApi/image/insertImage.js +2 -0
  35. package/lib-amd/publicApi/image/insertImage.js.map +1 -1
  36. package/lib-amd/publicApi/table/editTable.js +17 -0
  37. package/lib-amd/publicApi/table/editTable.js.map +1 -1
  38. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +2 -1
  39. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  40. package/lib-amd/publicApi/utils/formatTextSegmentBeforeSelectionMarker.d.ts +3 -2
  41. package/lib-amd/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js +6 -2
  42. package/lib-amd/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js.map +1 -1
  43. package/lib-mjs/index.d.ts +1 -0
  44. package/lib-mjs/index.js +1 -0
  45. package/lib-mjs/index.js.map +1 -1
  46. package/lib-mjs/modelApi/block/setModelIndentation.d.ts +2 -2
  47. package/lib-mjs/modelApi/block/setModelIndentation.js +6 -1
  48. package/lib-mjs/modelApi/block/setModelIndentation.js.map +1 -1
  49. package/lib-mjs/modelApi/list/findListItemsInSameThread.d.ts +2 -2
  50. package/lib-mjs/modelApi/list/findListItemsInSameThread.js +8 -4
  51. package/lib-mjs/modelApi/list/findListItemsInSameThread.js.map +1 -1
  52. package/lib-mjs/modelApi/list/getListAnnounceData.d.ts +7 -0
  53. package/lib-mjs/modelApi/list/getListAnnounceData.js +65 -0
  54. package/lib-mjs/modelApi/list/getListAnnounceData.js.map +1 -0
  55. package/lib-mjs/publicApi/image/insertImage.js +3 -1
  56. package/lib-mjs/publicApi/image/insertImage.js.map +1 -1
  57. package/lib-mjs/publicApi/table/editTable.js +17 -0
  58. package/lib-mjs/publicApi/table/editTable.js.map +1 -1
  59. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +2 -1
  60. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  61. package/lib-mjs/publicApi/utils/formatTextSegmentBeforeSelectionMarker.d.ts +3 -2
  62. package/lib-mjs/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js +6 -2
  63. package/lib-mjs/publicApi/utils/formatTextSegmentBeforeSelectionMarker.js.map +1 -1
  64. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":";;;;IAAS,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,sGAAA,SAAS,OAAA;IACT,gIAAA,sBAAsB,OAAA;IACtB,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,wGAAA,UAAU,OAAA;IACV,4GAAA,YAAY,OAAA;IACZ,kHAAA,eAAe,OAAA;IACf,0HAAA,mBAAmB,OAAA;IACnB,kHAAA,eAAe,OAAA;IACf,sHAAA,iBAAiB,OAAA;IACjB,wHAAA,kBAAkB,OAAA;IAClB,0GAAA,WAAW,OAAA;IACX,0GAAA,WAAW,OAAA;IACX,4GAAA,YAAY,OAAA;IACZ,gHAAA,cAAc,OAAA;IACd,wHAAA,kBAAkB,OAAA;IAClB,4HAAA,oBAAoB,OAAA;IACpB,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;IAEtC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,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 { 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';\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';\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,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;IAEtC,0GAAA,WAAW,OAAA;IACX,sHAAA,iBAAiB,OAAA;IACjB,kIAAA,uBAAuB,OAAA;IACvB,sIAAA,yBAAyB,OAAA;IACzB,0HAAA,mBAAmB,OAAA;IACnB,sGAAA,SAAS,OAAA;IACT,0HAAA,mBAAmB,OAAA","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { 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';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
@@ -1,8 +1,8 @@
1
- import type { ContentModelDocument } from 'roosterjs-content-model-types';
1
+ import type { ContentModelDocument, FormatContentModelContext } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @param model The content model to set indentation
4
4
  * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent
5
5
  * @param length The length of indentation in pixel, default value is 40
6
6
  * Set indentation for selected list items or paragraphs
7
7
  */
8
- export declare function setModelIndentation(model: ContentModelDocument, indentation: 'indent' | 'outdent', length?: number): boolean;
8
+ export declare function setModelIndentation(model: ContentModelDocument, indentation: 'indent' | 'outdent', length?: number, context?: FormatContentModelContext): boolean;
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "../list/findListItemsInSameThread", "roosterjs-content-model-dom"], function (require, exports, findListItemsInSameThread_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "../list/findListItemsInSameThread", "../list/getListAnnounceData", "roosterjs-content-model-dom"], function (require, exports, tslib_1, findListItemsInSameThread_1, getListAnnounceData_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setModelIndentation = void 0;
@@ -9,7 +9,7 @@ define(["require", "exports", "../list/findListItemsInSameThread", "roosterjs-co
9
9
  * @param length The length of indentation in pixel, default value is 40
10
10
  * Set indentation for selected list items or paragraphs
11
11
  */
12
- function setModelIndentation(model, indentation, length) {
12
+ function setModelIndentation(model, indentation, length, context) {
13
13
  if (length === void 0) { length = IndentStepInPixel; }
14
14
  var paragraphOrListItem = (0, roosterjs_content_model_dom_1.getOperationalBlocks)(model, ['ListItem'], ['TableCell']);
15
15
  var isIndent = indentation == 'indent';
@@ -56,6 +56,9 @@ define(["require", "exports", "../list/findListItemsInSameThread", "roosterjs-co
56
56
  else {
57
57
  block.levels.pop();
58
58
  }
59
+ if (block.levels.length > 0 && context) {
60
+ context.announceData = (0, getListAnnounceData_1.getListAnnounceData)((0, tslib_1.__spreadArray)([block], (0, tslib_1.__read)(path), false));
61
+ }
59
62
  }
60
63
  }
61
64
  else if (block) {
@@ -1 +1 @@
1
- {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAiBA,IAAM,iBAAiB,GAAG,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,SAAgB,mBAAmB,CAC/B,KAA2B,EAC3B,WAAiC,EACjC,MAAkC;QAAlC,uBAAA,EAAA,0BAAkC;QAElC,IAAM,mBAAmB,GAAG,IAAA,kDAAoB,EAC5C,KAAK,EACL,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,CAAC,CAChB,CAAC;QACF,IAAM,QAAQ,GAAG,WAAW,IAAI,QAAQ,CAAC;QACzC,IAAM,cAAc,GAAwB,EAAE,CAAC;QAE/C,mBAAmB,CAAC,OAAO,CAAC,UAAC,EAAuB;gBAArB,KAAK,WAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAA;YAC9C,IAAI,IAAA,gDAAkB,EAAuB,KAAK,EAAE,UAAU,CAAC,EAAE;gBAC7D,IAAM,MAAM,GAAG,IAAA,qDAAyB,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACvD,IAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC5B,8FAA8F;gBAC9F,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE;oBACvD,IAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;oBACtB,IAAA,MAAM,GAAK,KAAK,OAAV,CAAW;oBACjB,IAAA,UAAU,GAAkB,MAAM,WAAxB,EAAE,WAAW,GAAK,MAAM,YAAX,CAAY;oBAC3C,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WAAnC,EAAE,WAAW,GAAgB,MAAM,YAAtB,EAAE,SAAS,GAAK,MAAM,UAAX,CAAY;QACtD,IAAM,KAAK,GAAG,SAAS,IAAI,KAAK,CAAC;QACjC,IAAM,aAAa,GAAG,IAAA,gDAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACnE;QAED,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,oDAAoD;YACpD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelListLevel,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel\n) {\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const lastLevel = block.levels[block.levels.length - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n }\n } else if (block) {\n let currentBlock: ContentModelBlock = block;\n let currentParent: ContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = currentBlock;\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n delete currentParent.cachedElement;\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ContentModelDocument,\n listItem: ContentModelListItem,\n parent: ContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: ContentModelBlockFormat,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
1
+ {"version":3,"file":"setModelIndentation.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/block/setModelIndentation.ts"],"names":[],"mappings":";;;;IAmBA,IAAM,iBAAiB,GAAG,EAAE,CAAC;IAE7B;;;;;OAKG;IACH,SAAg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AAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;QAC3E,IAAI,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;QAEpF,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SACnE;QAED,IAAI,QAAQ,IAAI,aAAa,EAAE;YAC3B,oDAAoD;YACpD,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,QAAQ,CAAC;SACnB;IACL,CAAC","sourcesContent":["import { findListItemsInSameThread } from '../list/findListItemsInSameThread';\nimport { getListAnnounceData } from '../list/getListAnnounceData';\nimport {\n createListLevel,\n getOperationalBlocks,\n isBlockGroupOfType,\n parseValueWithUnit,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlock,\n ContentModelBlockFormat,\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n ContentModelListLevel,\n FormatContentModelContext,\n} from 'roosterjs-content-model-types';\n\nconst IndentStepInPixel = 40;\n\n/**\n * @param model The content model to set indentation\n * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent\n * @param length The length of indentation in pixel, default value is 40\n * Set indentation for selected list items or paragraphs\n */\nexport function setModelIndentation(\n model: ContentModelDocument,\n indentation: 'indent' | 'outdent',\n length: number = IndentStepInPixel,\n context?: FormatContentModelContext\n) {\n const paragraphOrListItem = getOperationalBlocks<ContentModelListItem>(\n model,\n ['ListItem'],\n ['TableCell']\n );\n const isIndent = indentation == 'indent';\n const modifiedBlocks: ContentModelBlock[] = [];\n\n paragraphOrListItem.forEach(({ block, parent, path }) => {\n if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n const thread = findListItemsInSameThread(model, block);\n const firstItem = thread[0];\n //if the first item is selected and has only one level, we should add margin to the whole list\n if (isSelected(firstItem) && firstItem.levels.length == 1) {\n const level = block.levels[0];\n const { format } = level;\n const { marginLeft, marginRight } = format;\n const newValue = calculateMarginValue(format, isIndent, length);\n const isRtl = format.direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n\n if (!isIndent && originalValue == 0) {\n block.levels.pop();\n } else if (newValue !== null) {\n if (isRtl) {\n level.format.marginRight = newValue + 'px';\n } else {\n level.format.marginLeft = newValue + 'px';\n }\n }\n //if block has only one level, there is not need to check if it is multilevel selection\n } else if (block.levels.length == 1 || !isMultilevelSelection(model, block, parent)) {\n if (isIndent) {\n const lastLevel = block.levels[block.levels.length - 1];\n const newLevel: ContentModelListLevel = createListLevel(\n lastLevel?.listType || 'UL',\n lastLevel?.format\n );\n\n updateListMetadata(newLevel, metadata => {\n metadata = metadata || {};\n metadata.applyListStyleFromLevel = true;\n return metadata;\n });\n\n // New level is totally new, no need to have these attributes for now\n delete newLevel.format.startNumberOverride;\n\n block.levels.push(newLevel);\n } else {\n block.levels.pop();\n }\n\n if (block.levels.length > 0 && context) {\n context.announceData = getListAnnounceData([block, ...path]);\n }\n }\n } else if (block) {\n let currentBlock: ContentModelBlock = block;\n let currentParent: ContentModelBlockGroup = parent;\n\n while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {\n const index = path.indexOf(currentParent);\n const { format } = currentBlock;\n const newValue = calculateMarginValue(format, isIndent, length);\n\n if (newValue !== null) {\n const isRtl = format.direction == 'rtl';\n\n if (isRtl) {\n format.marginRight = newValue + 'px';\n } else {\n format.marginLeft = newValue + 'px';\n }\n\n modifiedBlocks.push(currentBlock);\n\n break;\n } else if (currentParent.blockGroupType == 'FormatContainer' && index >= 0) {\n delete currentParent.cachedElement;\n\n currentBlock = currentParent;\n currentParent = path[index + 1];\n } else {\n break;\n }\n }\n }\n });\n\n return paragraphOrListItem.length > 0;\n}\n\nfunction isSelected(listItem: ContentModelListItem) {\n return listItem.blocks.some(block => {\n if (block.blockType == 'Paragraph') {\n return block.segments.some(segment => segment.isSelected);\n }\n });\n}\n\n/*\n * Check if the selection has list items with different levels and the first item of the list is selected, do not create a sub list.\n * Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.\n */\nfunction isMultilevelSelection(\n model: ContentModelDocument,\n listItem: ContentModelListItem,\n parent: ContentModelBlockGroup\n) {\n const listIndex = parent.blocks.indexOf(listItem);\n for (let i = listIndex - 1; i >= 0; i--) {\n const block = parent.blocks[i];\n if (\n isBlockGroupOfType<ContentModelListItem>(block, 'ListItem') &&\n block.levels.length == 1 &&\n isSelected(block)\n ) {\n const firstItem = findListItemsInSameThread(model, block)[0];\n return isSelected(firstItem);\n }\n\n if (!isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {\n return false;\n }\n }\n return false;\n}\n\nfunction calculateMarginValue(\n format: ContentModelBlockFormat,\n isIndent: boolean,\n length: number = IndentStepInPixel\n): number | null {\n const { marginLeft, marginRight, direction } = format;\n const isRtl = direction == 'rtl';\n const originalValue = parseValueWithUnit(isRtl ? marginRight : marginLeft);\n let newValue = (isIndent ? Math.ceil : Math.floor)(originalValue / length) * length;\n\n if (newValue == originalValue) {\n newValue = Math.max(newValue + length * (isIndent ? 1 : -1), 0);\n }\n\n if (newValue == originalValue) {\n // Return null to let caller know nothing is changed\n return null;\n } else {\n return newValue;\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
- import type { ContentModelDocument, ContentModelListItem } from 'roosterjs-content-model-types';
1
+ import type { ContentModelBlockGroup, ContentModelListItem } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @param model The content model
4
4
  * @param currentItem The current list item
5
5
  * Search for all list items in the same thread as the current list item
6
6
  */
7
- export declare function findListItemsInSameThread(model: ContentModelDocument, currentItem: ContentModelListItem): ContentModelListItem[];
7
+ export declare function findListItemsInSameThread(group: ContentModelBlockGroup, currentItem: ContentModelListItem): ContentModelListItem[];
@@ -7,9 +7,9 @@ define(["require", "exports"], function (require, exports) {
7
7
  * @param currentItem The current list item
8
8
  * Search for all list items in the same thread as the current list item
9
9
  */
10
- function findListItemsInSameThread(model, currentItem) {
10
+ function findListItemsInSameThread(group, currentItem) {
11
11
  var items = [];
12
- findListItems(model, items);
12
+ findListItems(group, items);
13
13
  return filterListItems(items, currentItem);
14
14
  }
15
15
  exports.findListItemsInSameThread = findListItemsInSameThread;
@@ -77,7 +77,9 @@ define(["require", "exports"], function (require, exports) {
77
77
  break;
78
78
  }
79
79
  }
80
- else if (!isOrderedList || startNumberOverride) {
80
+ else if (!isOrderedList ||
81
+ startNumberOverride ||
82
+ item.levels.length < currentItem.levels.length) {
81
83
  break;
82
84
  }
83
85
  }
@@ -95,7 +97,9 @@ define(["require", "exports"], function (require, exports) {
95
97
  if (areListTypesCompatible(items, currentIndex, i) && !startNumberOverride) {
96
98
  result.push(item);
97
99
  }
98
- else if (!isOrderedList || startNumberOverride) {
100
+ else if (!isOrderedList ||
101
+ startNumberOverride ||
102
+ item.levels.length < currentItem.levels.length) {
99
103
  break;
100
104
  }
101
105
  }
@@ -1 +1 @@
1
- {"version":3,"file":"findListItemsInSameThread.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/findListItemsInSameThread.ts"],"names":[],"mappings":";;;;IAMA;;;;OAIG;IACH,SAAgB,yBAAyB,CACrC,KAA2B,EAC3B,WAAiC;QAEjC,IAAM,KAAK,GAAoC,EAAE,CAAC;QAElD,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAE5B,OAAO,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IATD,8DASC;IAED,SAAS,aAAa,CAAC,KAA6B,EAAE,MAAuC;QACzF,KAAK,CAAC,MAA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IAAM,mBAAmB,GAAG,sBAAsB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;gBAEtE,IAAI,sBAAsB,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC,IAAI,CAAC,mBAAmB,EAAE;oBACxE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACrB;qBAAM,IAAI,CAAC,aAAa,IAAI,mBAAmB,EAAE;oBAC9C,MAAM;iBACT;aACJ;SACJ;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,SAAS,sBAAsB,CAC3B,SAA0C,EAC1C,YAAoB,EACpB,cAAsB;QAEtB,IAAM,aAAa,GAAG,SAAS,CAAC,YAAY,CAAE,CAAC,MAAM,CAAC;QACtD,IAAM,eAAe,GAAG,SAAS,CAAC,cAAc,CAAE,CAAC,MAAM,CAAC;QAE1D,OAAO,CACH,aAAa,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM;YAC9C,aAAa,CAAC,KAAK,CACf,UAAC,YAAY,EAAE,CAAC,IAAK,OAAA,YAAY,CAAC,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,EAApD,CAAoD,CAC5E,CACJ,CAAC;IACN,CAAC;IAED,SAAS,sBAAsB,CAAC,IAA0B,EAAE,WAAmB;QAC3E,OAAO,IAAI,CAAC,MAAM;aACb,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;aACrB,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,MAAM,CAAC,mBAAmB,KAAK,SAAS,EAA9C,CAA8C,CAAC,CAAC;IACvE,CAAC","sourcesContent":["import type {\n ContentModelBlockGroup,\n ContentModelDocument,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * @param model The content model\n * @param currentItem The current list item\n * Search for all list items in the same thread as the current list item\n */\nexport function findListItemsInSameThread(\n model: ContentModelDocument,\n currentItem: ContentModelListItem\n): ContentModelListItem[] {\n const items: (ContentModelListItem | null)[] = [];\n\n findListItems(model, items);\n\n return filterListItems(items, currentItem);\n}\n\nfunction findListItems(group: ContentModelBlockGroup, result: (ContentModelListItem | null)[]) {\n group.blocks.forEach(block => {\n switch (block.blockType) {\n case 'BlockGroup':\n if (block.blockGroupType == 'ListItem') {\n result.push(block);\n } else {\n pushNullIfNecessary(result);\n findListItems(block, result);\n pushNullIfNecessary(result);\n }\n break;\n\n case 'Paragraph':\n pushNullIfNecessary(result);\n\n block.segments.forEach(segment => {\n if (segment.segmentType == 'General') {\n findListItems(segment, result);\n }\n });\n\n pushNullIfNecessary(result);\n break;\n\n case 'Table':\n pushNullIfNecessary(result);\n\n block.rows.forEach(row =>\n row.cells.forEach(cell => {\n findListItems(cell, result);\n })\n );\n pushNullIfNecessary(result);\n\n break;\n }\n });\n}\n\nfunction pushNullIfNecessary(result: (ContentModelListItem | null)[]) {\n const last = result[result.length - 1];\n\n if (!last || last !== null) {\n result.push(null);\n }\n}\n\nfunction filterListItems(\n items: (ContentModelListItem | null)[],\n currentItem: ContentModelListItem\n) {\n const result: ContentModelListItem[] = [];\n const currentIndex = items.indexOf(currentItem);\n const levelLength = currentItem.levels.length;\n const isOrderedList = currentItem.levels[levelLength - 1]?.listType == 'OL';\n\n if (currentIndex >= 0) {\n for (let i = currentIndex; i >= 0; i--) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i)) {\n result.unshift(item);\n\n if (isOrderedList && startNumberOverride) {\n break;\n }\n } else if (!isOrderedList || startNumberOverride) {\n break;\n }\n }\n\n for (let i = currentIndex + 1; i < items.length; i++) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i) && !startNumberOverride) {\n result.push(item);\n } else if (!isOrderedList || startNumberOverride) {\n break;\n }\n }\n }\n\n return result;\n}\n\nfunction areListTypesCompatible(\n listItems: (ContentModelListItem | null)[],\n currentIndex: number,\n compareToIndex: number\n): boolean {\n const currentLevels = listItems[currentIndex]!.levels;\n const compareToLevels = listItems[compareToIndex]!.levels;\n\n return (\n currentLevels.length <= compareToLevels.length &&\n currentLevels.every(\n (currentLevel, i) => currentLevel.listType == compareToLevels[i].listType\n )\n );\n}\n\nfunction hasStartNumberOverride(item: ContentModelListItem, levelLength: number): boolean {\n return item.levels\n .slice(0, levelLength)\n .some(level => level.format.startNumberOverride !== undefined);\n}\n"]}
1
+ {"version":3,"file":"findListItemsInSameThread.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/findListItemsInSameThread.ts"],"names":[],"mappings":";;;;IAEA;;;;OAIG;IACH,SAAgB,yBAAyB,CACrC,KAA6B,EAC7B,WAAiC;QAEjC,IAAM,KAAK,GAAoC,EAAE,CAAC;QAElD,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAE5B,OAAO,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IATD,8DASC;IAED,SAAS,aAAa,CAAC,KAA6B,EAAE,MAAuC;QACzF,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,UAAA,KAAK;YACtB,QAAQ,KAAK,CAAC,SAAS,EAAE;gBACrB,KAAK,YAAY;oBACb,IAAI,KAAK,CAAC,cAAc,IAAI,UAAU,EAAE;wBACpC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;qBACtB;yBAAM;wBACH,mBAAmB,CAAC,MAAM,CAAC,CAAC;wBAC5B,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;wBAC7B,mBAAmB,CAAC,MAAM,CAAC,CAAC;qBAC/B;oBACD,MAAM;gBAEV,KAAK,WAAW;oBACZ,mBAAmB,CAAC,MAAM,CAAC,CAAC;oBAE5B,KAAK,CAAC,QAAQ,CAAC,OA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,CAAC;IAClB,CAAC;IAED,SAAS,sBAAsB,CAC3B,SAA0C,EAC1C,YAAoB,EACpB,cAAsB;QAEtB,IAAM,aAAa,GAAG,SAAS,CAAC,YAAY,CAAE,CAAC,MAAM,CAAC;QACtD,IAAM,eAAe,GAAG,SAAS,CAAC,cAAc,CAAE,CAAC,MAAM,CAAC;QAE1D,OAAO,CACH,aAAa,CAAC,MAAM,IAAI,eAAe,CAAC,MAAM;YAC9C,aAAa,CAAC,KAAK,CACf,UAAC,YAAY,EAAE,CAAC,IAAK,OAAA,YAAY,CAAC,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,EAApD,CAAoD,CAC5E,CACJ,CAAC;IACN,CAAC;IAED,SAAS,sBAAsB,CAAC,IAA0B,EAAE,WAAmB;QAC3E,OAAO,IAAI,CAAC,MAAM;aACb,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;aACrB,IAAI,CAAC,UAAA,KAAK,IAAI,OAAA,KAAK,CAAC,MAAM,CAAC,mBAAmB,KAAK,SAAS,EAA9C,CAA8C,CAAC,CAAC;IACvE,CAAC","sourcesContent":["import type { ContentModelBlockGroup, ContentModelListItem } from 'roosterjs-content-model-types';\n\n/**\n * @param model The content model\n * @param currentItem The current list item\n * Search for all list items in the same thread as the current list item\n */\nexport function findListItemsInSameThread(\n group: ContentModelBlockGroup,\n currentItem: ContentModelListItem\n): ContentModelListItem[] {\n const items: (ContentModelListItem | null)[] = [];\n\n findListItems(group, items);\n\n return filterListItems(items, currentItem);\n}\n\nfunction findListItems(group: ContentModelBlockGroup, result: (ContentModelListItem | null)[]) {\n group.blocks.forEach(block => {\n switch (block.blockType) {\n case 'BlockGroup':\n if (block.blockGroupType == 'ListItem') {\n result.push(block);\n } else {\n pushNullIfNecessary(result);\n findListItems(block, result);\n pushNullIfNecessary(result);\n }\n break;\n\n case 'Paragraph':\n pushNullIfNecessary(result);\n\n block.segments.forEach(segment => {\n if (segment.segmentType == 'General') {\n findListItems(segment, result);\n }\n });\n\n pushNullIfNecessary(result);\n break;\n\n case 'Table':\n pushNullIfNecessary(result);\n\n block.rows.forEach(row =>\n row.cells.forEach(cell => {\n findListItems(cell, result);\n })\n );\n pushNullIfNecessary(result);\n\n break;\n }\n });\n}\n\nfunction pushNullIfNecessary(result: (ContentModelListItem | null)[]) {\n const last = result[result.length - 1];\n\n if (!last || last !== null) {\n result.push(null);\n }\n}\n\nfunction filterListItems(\n items: (ContentModelListItem | null)[],\n currentItem: ContentModelListItem\n) {\n const result: ContentModelListItem[] = [];\n const currentIndex = items.indexOf(currentItem);\n const levelLength = currentItem.levels.length;\n const isOrderedList = currentItem.levels[levelLength - 1]?.listType == 'OL';\n\n if (currentIndex >= 0) {\n for (let i = currentIndex; i >= 0; i--) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i)) {\n result.unshift(item);\n\n if (isOrderedList && startNumberOverride) {\n break;\n }\n } else if (\n !isOrderedList ||\n startNumberOverride ||\n item.levels.length < currentItem.levels.length\n ) {\n break;\n }\n }\n\n for (let i = currentIndex + 1; i < items.length; i++) {\n const item = items[i];\n\n if (!item) {\n if (isOrderedList) {\n continue;\n } else {\n break;\n }\n }\n\n const startNumberOverride = hasStartNumberOverride(item, levelLength);\n\n if (areListTypesCompatible(items, currentIndex, i) && !startNumberOverride) {\n result.push(item);\n } else if (\n !isOrderedList ||\n startNumberOverride ||\n item.levels.length < currentItem.levels.length\n ) {\n break;\n }\n }\n }\n\n return result;\n}\n\nfunction areListTypesCompatible(\n listItems: (ContentModelListItem | null)[],\n currentIndex: number,\n compareToIndex: number\n): boolean {\n const currentLevels = listItems[currentIndex]!.levels;\n const compareToLevels = listItems[compareToIndex]!.levels;\n\n return (\n currentLevels.length <= compareToLevels.length &&\n currentLevels.every(\n (currentLevel, i) => currentLevel.listType == compareToLevels[i].listType\n )\n );\n}\n\nfunction hasStartNumberOverride(item: ContentModelListItem, levelLength: number): boolean {\n return item.levels\n .slice(0, levelLength)\n .some(level => level.format.startNumberOverride !== undefined);\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import type { AnnounceData, ContentModelBlockGroup } from 'roosterjs-content-model-types';
2
+ /**
3
+ * Get announce data for list item
4
+ * @param path Content model path that include the list item
5
+ * @returns Announce data of current list item if any, or null
6
+ */
7
+ export declare function getListAnnounceData(path: ContentModelBlockGroup[]): AnnounceData | null;
@@ -0,0 +1,69 @@
1
+ define(["require", "exports", "./findListItemsInSameThread", "roosterjs-content-model-dom"], function (require, exports, findListItemsInSameThread_1, roosterjs_content_model_dom_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.getListAnnounceData = void 0;
5
+ /**
6
+ * Get announce data for list item
7
+ * @param path Content model path that include the list item
8
+ * @returns Announce data of current list item if any, or null
9
+ */
10
+ function getListAnnounceData(path) {
11
+ var index = (0, roosterjs_content_model_dom_1.getClosestAncestorBlockGroupIndex)(path, ['ListItem'], ['TableCell']);
12
+ if (index >= 0) {
13
+ var listItem = path[index];
14
+ var level = listItem.levels[listItem.levels.length - 1];
15
+ if (level.format.displayForDummyItem) {
16
+ return null;
17
+ }
18
+ else if (level.listType == 'OL') {
19
+ var listNumber = getListNumber(path, listItem);
20
+ var metadata = (0, roosterjs_content_model_dom_1.updateListMetadata)(level);
21
+ var listStyle = (0, roosterjs_content_model_dom_1.getAutoListStyleType)('OL', metadata !== null && metadata !== void 0 ? metadata : {}, listItem.levels.length - 1, level.format.listStyleType);
22
+ return listStyle === undefined
23
+ ? null
24
+ : {
25
+ defaultStrings: 'announceListItemNumbering',
26
+ formatStrings: [(0, roosterjs_content_model_dom_1.getOrderedListNumberStr)(listStyle, listNumber)],
27
+ };
28
+ }
29
+ else {
30
+ return {
31
+ defaultStrings: 'announceListItemBullet',
32
+ };
33
+ }
34
+ }
35
+ else {
36
+ return null;
37
+ }
38
+ }
39
+ exports.getListAnnounceData = getListAnnounceData;
40
+ function getListNumber(path, listItem) {
41
+ var _a, _b;
42
+ var items = (0, findListItemsInSameThread_1.findListItemsInSameThread)(path[path.length - 1], listItem);
43
+ var listNumber = 0;
44
+ for (var i = 0; i < items.length; i++) {
45
+ var item = items[i];
46
+ if (listNumber == 0 && item.levels.length == listItem.levels.length) {
47
+ listNumber = (_b = (_a = item.levels[item.levels.length - 1]) === null || _a === void 0 ? void 0 : _a.format.startNumberOverride) !== null && _b !== void 0 ? _b : 1;
48
+ }
49
+ if (item == listItem) {
50
+ // Found current item, so break and return
51
+ break;
52
+ }
53
+ else if (item.levels.length < listItem.levels.length) {
54
+ // Found upper level item, reset list number
55
+ listNumber = 0;
56
+ }
57
+ else if (item.levels.length > listItem.levels.length) {
58
+ // Found deeper level item, skip
59
+ continue;
60
+ }
61
+ else if (!item.levels[item.levels.length - 1].format.displayForDummyItem) {
62
+ // Save level, and is not dummy, number plus one
63
+ listNumber++;
64
+ }
65
+ }
66
+ return listNumber;
67
+ }
68
+ });
69
+ //# sourceMappingURL=getListAnnounceData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getListAnnounceData.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/modelApi/list/getListAnnounceData.ts"],"names":[],"mappings":";;;;IAaA;;;;OAIG;IACH,SAAgB,mBAAmB,CAAC,IAA8B;QAC9D,IAAM,KAAK,GAAG,IAAA,+DAAiC,EAAC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;QAEnF,IAAI,KAAK,IAAI,CAAC,EAAE;YACZ,IAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAyB,CAAC;YACrD,IAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAE1D,IAAI,KAAK,CAAC,MAAM,CAAC,mBAAmB,EAAE;gBACl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A,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,MAAM,CAAC,mBAAmB,mCAAI,CAAC,CAAC;aACrF;YAED,IAAI,IAAI,IAAI,QAAQ,EAAE;gBAClB,0CAA0C;gBAC1C,MAAM;aACT;iBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpD,4CAA4C;gBAC5C,UAAU,GAAG,CAAC,CAAC;aAClB;iBAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpD,gCAAgC;gBAChC,SAAS;aACZ;iBAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,mBAAmB,EAAE;gBACxE,gDAAgD;gBAChD,UAAU,EAAE,CAAC;aAChB;SACJ;QACD,OAAO,UAAU,CAAC;IACtB,CAAC","sourcesContent":["import { findListItemsInSameThread } from './findListItemsInSameThread';\nimport {\n getAutoListStyleType,\n getClosestAncestorBlockGroupIndex,\n getOrderedListNumberStr,\n updateListMetadata,\n} from 'roosterjs-content-model-dom';\nimport type {\n AnnounceData,\n ContentModelBlockGroup,\n ContentModelListItem,\n} from 'roosterjs-content-model-types';\n\n/**\n * Get announce data for list item\n * @param path Content model path that include the list item\n * @returns Announce data of current list item if any, or null\n */\nexport function getListAnnounceData(path: ContentModelBlockGroup[]): AnnounceData | null {\n const index = getClosestAncestorBlockGroupIndex(path, ['ListItem'], ['TableCell']);\n\n if (index >= 0) {\n const listItem = path[index] as ContentModelListItem;\n const level = listItem.levels[listItem.levels.length - 1];\n\n if (level.format.displayForDummyItem) {\n return null;\n } else if (level.listType == 'OL') {\n const listNumber = getListNumber(path, listItem);\n const metadata = updateListMetadata(level);\n const listStyle = getAutoListStyleType(\n 'OL',\n metadata ?? {},\n listItem.levels.length - 1,\n level.format.listStyleType\n );\n\n return listStyle === undefined\n ? null\n : {\n defaultStrings: 'announceListItemNumbering',\n formatStrings: [getOrderedListNumberStr(listStyle, listNumber)],\n };\n } else {\n return {\n defaultStrings: 'announceListItemBullet',\n };\n }\n } else {\n return null;\n }\n}\n\nfunction getListNumber(path: ContentModelBlockGroup[], listItem: ContentModelListItem) {\n const items = findListItemsInSameThread(path[path.length - 1], listItem);\n let listNumber = 0;\n\n for (let i = 0; i < items.length; i++) {\n const item = items[i];\n\n if (listNumber == 0 && item.levels.length == listItem.levels.length) {\n listNumber = item.levels[item.levels.length - 1]?.format.startNumberOverride ?? 1;\n }\n\n if (item == listItem) {\n // Found current item, so break and return\n break;\n } else if (item.levels.length < listItem.levels.length) {\n // Found upper level item, reset list number\n listNumber = 0;\n } else if (item.levels.length > listItem.levels.length) {\n // Found deeper level item, skip\n continue;\n } else if (!item.levels[item.levels.length - 1].format.displayForDummyItem) {\n // Save level, and is not dummy, number plus one\n listNumber++;\n }\n }\n return listNumber;\n}\n"]}
@@ -29,6 +29,8 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
29
29
  (0, roosterjs_content_model_dom_1.mergeModel)(model, doc, context, {
30
30
  mergeFormat: 'mergeAll',
31
31
  });
32
+ image.isSelected = true;
33
+ (0, roosterjs_content_model_dom_1.setSelection)(model, image);
32
34
  return true;
33
35
  }, {
34
36
  apiName: 'insertImage',
@@ -1 +1 @@
1
- {"version":3,"file":"insertImage.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/image/insertImage.ts"],"names":[],"mappings":";;;;IASA;;;;OAIG;IACH,SAAgB,WAAW,CAAC,MAAe,EAAE,cAA6B;QACtE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAI,OAAO,cAAc,IAAI,QAAQ,EAAE;YACnC,kBAAkB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;SAC9C;aAAM;YACH,IAAA,sCAAQ,EAAC,cAAc,EAAE,UAAA,OAAO;gBAC5B,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE;oBACjC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;iBACvC;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAZD,kCAYC;IAED,SAAS,kBAAkB,CAAC,MAAe,EAAE,GAAW;QACpD,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,KAAK,GAAG,IAAA,yCAAW,EAAC,GAAG,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;YACxD,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;YAEzC,IAAA,wCAAU,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACvB,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;gBAC5B,WAAW,EAAE,UAAU;aAC1B,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QAChB,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC","sourcesContent":["import {\n mergeModel,\n readFile,\n addSegment,\n createContentModelDocument,\n createImage,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Insert an image into current selected position\n * @param editor The editor to operate on\n * @param file Image Blob file or source string\n */\nexport function insertImage(editor: IEditor, imageFileOrSrc: File | string) {\n editor.focus();\n\n if (typeof imageFileOrSrc == 'string') {\n insertImageWithSrc(editor, imageFileOrSrc);\n } else {\n readFile(imageFileOrSrc, dataUrl => {\n if (dataUrl && !editor.isDisposed()) {\n insertImageWithSrc(editor, dataUrl);\n }\n });\n }\n}\n\nfunction insertImageWithSrc(editor: IEditor, src: string) {\n editor.formatContentModel(\n (model, context) => {\n const image = createImage(src, { backgroundColor: '' });\n const doc = createContentModelDocument();\n\n addSegment(doc, image);\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n\n return true;\n },\n {\n apiName: 'insertImage',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertImage.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/image/insertImage.ts"],"names":[],"mappings":";;;;IAUA;;;;OAIG;IACH,SAAgB,WAAW,CAAC,MAAe,EAAE,cAA6B;QACtE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAI,OAAO,cAAc,IAAI,QAAQ,EAAE;YACnC,kBAAkB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;SAC9C;aAAM;YACH,IAAA,sCAAQ,EAAC,cAAc,EAAE,UAAA,OAAO;gBAC5B,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE;oBACjC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;iBACvC;YACL,CAAC,CAAC,CAAC;SACN;IACL,CAAC;IAZD,kCAYC;IAED,SAAS,kBAAkB,CAAC,MAAe,EAAE,GAAW;QACpD,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAM,KAAK,GAAG,IAAA,yCAAW,EAAC,GAAG,EAAE,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,CAAC;YACxD,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;YAEzC,IAAA,wCAAU,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACvB,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;gBAC5B,WAAW,EAAE,UAAU;aAC1B,CAAC,CAAC;YACH,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;YACxB,IAAA,0CAAY,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAE3B,OAAO,IAAI,CAAC;QAChB,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC","sourcesContent":["import {\n mergeModel,\n readFile,\n addSegment,\n createContentModelDocument,\n createImage,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Insert an image into current selected position\n * @param editor The editor to operate on\n * @param file Image Blob file or source string\n */\nexport function insertImage(editor: IEditor, imageFileOrSrc: File | string) {\n editor.focus();\n\n if (typeof imageFileOrSrc == 'string') {\n insertImageWithSrc(editor, imageFileOrSrc);\n } else {\n readFile(imageFileOrSrc, dataUrl => {\n if (dataUrl && !editor.isDisposed()) {\n insertImageWithSrc(editor, dataUrl);\n }\n });\n }\n}\n\nfunction insertImageWithSrc(editor: IEditor, src: string) {\n editor.formatContentModel(\n (model, context) => {\n const image = createImage(src, { backgroundColor: '' });\n const doc = createContentModelDocument();\n\n addSegment(doc, image);\n mergeModel(model, doc, context, {\n mergeFormat: 'mergeAll',\n });\n image.isSelected = true;\n setSelection(model, image);\n\n return true;\n },\n {\n apiName: 'insertImage',\n }\n );\n}\n"]}
@@ -9,6 +9,7 @@ define(["require", "exports", "../../modelApi/table/alignTable", "../../modelApi
9
9
  */
10
10
  function editTable(editor, operation) {
11
11
  editor.focus();
12
+ fixUpSafariSelection(editor);
12
13
  (0, formatTableWithContentModel_1.formatTableWithContentModel)(editor, 'editTable', function (tableModel) {
13
14
  switch (operation) {
14
15
  case 'alignCellLeft':
@@ -64,5 +65,21 @@ define(["require", "exports", "../../modelApi/table/alignTable", "../../modelApi
64
65
  });
65
66
  }
66
67
  exports.editTable = editTable;
68
+ // In safari, when open context menu under a table, it may expand the range selection to the beginning of next table cell.
69
+ // So we make a workaround here to collapse the selection when need, to avoid unexpected table editing behavior
70
+ // (e.g. insert two columns but actually need one only)
71
+ function fixUpSafariSelection(editor) {
72
+ if (editor.getEnvironment().isSafari) {
73
+ var selection = editor.getDOMSelection();
74
+ if ((selection === null || selection === void 0 ? void 0 : selection.type) == 'range' && !selection.range.collapsed) {
75
+ selection.range.collapse(true /*toStart*/);
76
+ editor.setDOMSelection({
77
+ type: 'range',
78
+ range: selection.range,
79
+ isReverted: false,
80
+ });
81
+ }
82
+ }
83
+ }
67
84
  });
68
85
  //# sourceMappingURL=editTable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":";;;;IAkBA;;;;OAIG;IACH,SAAgB,SAAS,CAAC,MAAe,EAAE,SAAyB;QAChE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,yDAA2B,EAAC,MAAM,EAAE,WAAW,EAAE,UAAA,UAAU;YACvD,QAAQ,SAAS,EAAE;gBACf,KAAK,eAAe,CAAC;gBACrB,KAAK,iBAAiB,CAAC;gBACvB,KAAK,gBAAgB;oBACjB,IAAA,2CAA0B,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBAClD,MAAM;gBACV,KAAK,cAAc,CAAC;gBACpB,KAAK,iBAAiB,CAAC;gBACvB,KAAK,iBAAiB;oBAClB,IAAA,yCAAwB,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBAChD,MAAM;gBACV,KAAK,aAAa,CAAC;gBACnB,KAAK,WAAW,CAAC;gBACjB,KAAK,YAAY;oBACb,IAAA,uBAAU,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBAClC,MAAM;gBAEV,KAAK,cAAc;oBACf,IAAA,qCAAiB,EAAC,UAAU,CAAC,CAAC;oBAC9B,MAAM;gBAEV,KAAK,WAAW;oBACZ,IAAA,+BAAc,EAAC,UAAU,CAAC,CAAC;oBAC3B,MAAM;gBAEV,KAAK,aAAa;oBACd,IAAA,yBAAW,EAAC,UAAU,CAAC,CAAC;oBACxB,MAAM;gBAEV,KAAK,aAAa,CAAC;gBACnB,KAAK,aAAa;oBACd,IAAA,+BAAc,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBACtC,MAAM;gBAEV,KAAK,YAAY,CAAC;gBAClB,KAAK,aAAa;oBACd,IAAA,qCAAiB,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBACzC,MAAM;gBAEV,KAAK,YAAY,CAAC;gBAClB,KAAK,YAAY;oBACb,IAAA,6BAAa,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBACrC,MAAM;gBAEV,KAAK,YAAY;oBACb,IAAA,iCAAe,EAAC,UAAU,CAAC,CAAC;oBAC5B,MAAM;gBAEV,KAAK,WAAW,CAAC;gBACjB,KAAK,YAAY;oBACb,IAAA,mCAAgB,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBACxC,MAAM;gBAEV,KAAK,mBAAmB;oBACpB,IAAA,uDAA0B,EAAC,UAAU,CAAC,CAAC;oBACvC,MAAM;gBAEV,KAAK,iBAAiB;oBAClB,IAAA,mDAAwB,EAAC,UAAU,CAAC,CAAC;oBACrC,MAAM;aACb;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAlED,8BAkEC","sourcesContent":["import { alignTable } from '../../modelApi/table/alignTable';\nimport { deleteTable } from '../../modelApi/table/deleteTable';\nimport { deleteTableColumn } from '../../modelApi/table/deleteTableColumn';\nimport { deleteTableRow } from '../../modelApi/table/deleteTableRow';\nimport { formatTableWithContentModel } from '../utils/formatTableWithContentModel';\nimport { insertTableColumn } from '../../modelApi/table/insertTableColumn';\nimport { insertTableRow } from '../../modelApi/table/insertTableRow';\nimport { mergeTableCells } from '../../modelApi/table/mergeTableCells';\nimport { mergeTableColumn } from '../../modelApi/table/mergeTableColumn';\nimport { mergeTableRow } from '../../modelApi/table/mergeTableRow';\nimport { splitTableCellHorizontally } from '../../modelApi/table/splitTableCellHorizontally';\nimport { splitTableCellVertically } from '../../modelApi/table/splitTableCellVertically';\nimport type { TableOperation, IEditor } from 'roosterjs-content-model-types';\nimport {\n alignTableCellHorizontally,\n alignTableCellVertically,\n} from '../../modelApi/table/alignTableCell';\n\n/**\n * Format current focused table with the given format\n * @param editor The editor instance\n * @param operation The table operation to apply\n */\nexport function editTable(editor: IEditor, operation: TableOperation) {\n editor.focus();\n\n formatTableWithContentModel(editor, 'editTable', tableModel => {\n switch (operation) {\n case 'alignCellLeft':\n case 'alignCellCenter':\n case 'alignCellRight':\n alignTableCellHorizontally(tableModel, operation);\n break;\n case 'alignCellTop':\n case 'alignCellMiddle':\n case 'alignCellBottom':\n alignTableCellVertically(tableModel, operation);\n break;\n case 'alignCenter':\n case 'alignLeft':\n case 'alignRight':\n alignTable(tableModel, operation);\n break;\n\n case 'deleteColumn':\n deleteTableColumn(tableModel);\n break;\n\n case 'deleteRow':\n deleteTableRow(tableModel);\n break;\n\n case 'deleteTable':\n deleteTable(tableModel);\n break;\n\n case 'insertAbove':\n case 'insertBelow':\n insertTableRow(tableModel, operation);\n break;\n\n case 'insertLeft':\n case 'insertRight':\n insertTableColumn(tableModel, operation);\n break;\n\n case 'mergeAbove':\n case 'mergeBelow':\n mergeTableRow(tableModel, operation);\n break;\n\n case 'mergeCells':\n mergeTableCells(tableModel);\n break;\n\n case 'mergeLeft':\n case 'mergeRight':\n mergeTableColumn(tableModel, operation);\n break;\n\n case 'splitHorizontally':\n splitTableCellHorizontally(tableModel);\n break;\n\n case 'splitVertically':\n splitTableCellVertically(tableModel);\n break;\n }\n });\n}\n"]}
1
+ {"version":3,"file":"editTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/editTable.ts"],"names":[],"mappings":";;;;IAkBA;;;;OAIG;IACH,SAAgB,SAAS,CAAC,MAAe,EAAE,SAAyB;QAChE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAE7B,IAAA,yDAA2B,EAAC,MAAM,EAAE,WAAW,EAAE,UAAA,UAAU;YACvD,QAAQ,SAAS,EAAE;gBACf,KAAK,eAAe,CAAC;gBACrB,KAAK,iBAAiB,CAAC;gBACvB,KAAK,gBAAgB;oBACjB,IAAA,2CAA0B,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;oBAClD,MA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CAAC;IACP,CAAC;IApED,8BAoEC;IAED,0HAA0H;IAC1H,+GAA+G;IAC/G,uDAAuD;IACvD,SAAS,oBAAoB,CAAC,MAAe;QACzC,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,QAAQ,EAAE;YAClC,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;YAE3C,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,IAAI,KAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE;gBAC1D,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBAC3C,MAAM,CAAC,eAAe,CAAC;oBACnB,IAAI,EAAE,OAAO;oBACb,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,UAAU,EAAE,KAAK;iBACpB,CAAC,CAAC;aACN;SACJ;IACL,CAAC","sourcesContent":["import { alignTable } from '../../modelApi/table/alignTable';\nimport { deleteTable } from '../../modelApi/table/deleteTable';\nimport { deleteTableColumn } from '../../modelApi/table/deleteTableColumn';\nimport { deleteTableRow } from '../../modelApi/table/deleteTableRow';\nimport { formatTableWithContentModel } from '../utils/formatTableWithContentModel';\nimport { insertTableColumn } from '../../modelApi/table/insertTableColumn';\nimport { insertTableRow } from '../../modelApi/table/insertTableRow';\nimport { mergeTableCells } from '../../modelApi/table/mergeTableCells';\nimport { mergeTableColumn } from '../../modelApi/table/mergeTableColumn';\nimport { mergeTableRow } from '../../modelApi/table/mergeTableRow';\nimport { splitTableCellHorizontally } from '../../modelApi/table/splitTableCellHorizontally';\nimport { splitTableCellVertically } from '../../modelApi/table/splitTableCellVertically';\nimport type { TableOperation, IEditor } from 'roosterjs-content-model-types';\nimport {\n alignTableCellHorizontally,\n alignTableCellVertically,\n} from '../../modelApi/table/alignTableCell';\n\n/**\n * Format current focused table with the given format\n * @param editor The editor instance\n * @param operation The table operation to apply\n */\nexport function editTable(editor: IEditor, operation: TableOperation) {\n editor.focus();\n\n fixUpSafariSelection(editor);\n\n formatTableWithContentModel(editor, 'editTable', tableModel => {\n switch (operation) {\n case 'alignCellLeft':\n case 'alignCellCenter':\n case 'alignCellRight':\n alignTableCellHorizontally(tableModel, operation);\n break;\n case 'alignCellTop':\n case 'alignCellMiddle':\n case 'alignCellBottom':\n alignTableCellVertically(tableModel, operation);\n break;\n case 'alignCenter':\n case 'alignLeft':\n case 'alignRight':\n alignTable(tableModel, operation);\n break;\n\n case 'deleteColumn':\n deleteTableColumn(tableModel);\n break;\n\n case 'deleteRow':\n deleteTableRow(tableModel);\n break;\n\n case 'deleteTable':\n deleteTable(tableModel);\n break;\n\n case 'insertAbove':\n case 'insertBelow':\n insertTableRow(tableModel, operation);\n break;\n\n case 'insertLeft':\n case 'insertRight':\n insertTableColumn(tableModel, operation);\n break;\n\n case 'mergeAbove':\n case 'mergeBelow':\n mergeTableRow(tableModel, operation);\n break;\n\n case 'mergeCells':\n mergeTableCells(tableModel);\n break;\n\n case 'mergeLeft':\n case 'mergeRight':\n mergeTableColumn(tableModel, operation);\n break;\n\n case 'splitHorizontally':\n splitTableCellHorizontally(tableModel);\n break;\n\n case 'splitVertically':\n splitTableCellVertically(tableModel);\n break;\n }\n });\n}\n\n// In safari, when open context menu under a table, it may expand the range selection to the beginning of next table cell.\n// So we make a workaround here to collapse the selection when need, to avoid unexpected table editing behavior\n// (e.g. insert two columns but actually need one only)\nfunction fixUpSafariSelection(editor: IEditor) {\n if (editor.getEnvironment().isSafari) {\n const selection = editor.getDOMSelection();\n\n if (selection?.type == 'range' && !selection.range.collapsed) {\n selection.range.collapse(true /*toStart*/);\n editor.setDOMSelection({\n type: 'range',\n range: selection.range,\n isReverted: false,\n });\n }\n }\n}\n"]}
@@ -18,7 +18,8 @@ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelec
18
18
  segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';
19
19
  if (isCollapsedSelection) {
20
20
  var para_1 = segmentAndParagraphs[0][1];
21
- segmentAndParagraphs = (0, adjustWordSelection_1.adjustWordSelection)(model, segmentAndParagraphs[0][0]).map(function (x) { return [x, para_1]; });
21
+ var path_1 = segmentAndParagraphs[0][2];
22
+ segmentAndParagraphs = (0, adjustWordSelection_1.adjustWordSelection)(model, segmentAndParagraphs[0][0]).map(function (x) { return [x, para_1, path_1]; });
22
23
  if (segmentAndParagraphs.length > 1) {
23
24
  isCollapsedSelection = false;
24
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IAUA;;;;;;;;OAQG;IACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAA2D;QAE3D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,CAC1B,CAAC;YACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;gBAChC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,CAAC;YAEhE,IAAI,oBAAoB,EAAE;gBACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAExC,oBAAoB,GAAG,IAAA,yCAAmB,EACtC,KAAK,EACL,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7B,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,EAAE,MAAI,CAAC,EAAT,CAAS,CAAC,CAAC;gBAEtB,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;oBACjC,oBAAoB,GAAG,KAAK,CAAC;iBAChC;aACJ;YAED,IAAM,kBAAkB,GAIlB,oBAAoB,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAlC,CAAkC,CAAC,CAAC;YAE3E,IAAM,YAAY,GAAG,uBAAuB;gBACxC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,UAAC,EAA4B;wBAA5B,KAAA,0BAA4B,EAA3B,MAAM,QAAA,EAAE,OAAO,QAAA,EAAE,SAAS,QAAA;oBACjD,OAAA,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;gBAAnD,CAAmD,CACtD;gBACH,CAAC,CAAC,KAAK,CAAC;YAEZ,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAA4B;oBAA5B,KAAA,0BAA4B,EAA3B,MAAM,QAAA,EAAE,OAAO,QAAA,EAAE,SAAS,QAAA;gBACnD,OAAA,mBAAmB,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC;YAA9D,CAA8D,CACjE,CAAC;YAEF,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAC;YAE7B,IAAI,oBAAoB,EAAE;gBACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;aAChB;iBAAM;gBACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;aACxC;QACL,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IAtED,sEAsEC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length == 1 &&\n segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';\n\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ContentModelSegment | null,\n ContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) =>\n toggleStyleCallback(format, !isTurningOff, segment, paragraph)\n );\n\n afterFormatCallback?.(model);\n\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IAUA;;;;;;;;OAQG;IACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAA2D;QAE3D,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,CAC1B,CAAC;YACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;gBAChC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,CAAC;YAEhE,IAAI,oBAAoB,EAAE;gBACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACxC,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAExC,oBAAoB,GAAG,IAAA,yCAAmB,EACtC,KAAK,EACL,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7B,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,EAAE,MAAI,EAAE,MAAI,CAAC,EAAf,CAAe,CAAC,CAAC;gBAE5B,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;oBACjC,oBAAoB,GAAG,KAAK,CAAC;iBAChC;aACJ;YAED,IAAM,kBAAkB,GAIlB,oBAAoB,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAlC,CAAkC,CAAC,CAAC;YAE3E,IAAM,YAAY,GAAG,uBAAuB;gBACxC,CAAC,CAAC,kBAAkB,CAAC,KAAK,CAAC,UAAC,EAA4B;wBAA5B,KAAA,0BAA4B,EAA3B,MAAM,QAAA,EAAE,OAAO,QAAA,EAAE,SAAS,QAAA;oBACjD,OAAA,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;gBAAnD,CAAmD,CACtD;gBACH,CAAC,CAAC,KAAK,CAAC;YAEZ,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAA4B;oBAA5B,KAAA,0BAA4B,EAA3B,MAAM,QAAA,EAAE,OAAO,QAAA,EAAE,SAAS,QAAA;gBACnD,OAAA,mBAAmB,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,OAAO,EAAE,SAAS,CAAC;YAA9D,CAA8D,CACjE,CAAC;YAEF,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAG,KAAK,CAAC,CAAC;YAE7B,IAAI,oBAAoB,EAAE;gBACtB,OAAO,CAAC,gBAAgB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;gBAC7D,MAAM,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;aAChB;iBAAM;gBACH,OAAO,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;aACxC;QACL,CAAC,EACD;YACI,OAAO,SAAA;SACV,CACJ,CAAC;IACN,CAAC;IAvED,sEAuEC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegment,\n ContentModelSegmentFormat,\n IEditor,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ContentModelSegment | null,\n paragraph: ContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length == 1 &&\n segmentAndParagraphs[0][0].segmentType == 'SelectionMarker';\n\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ContentModelSegment | null,\n ContentModelParagraph | null\n ][] = segmentAndParagraphs.map(item => [item[0].format, item[0], item[1]]);\n\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n formatsAndSegments.forEach(([format, segment, paragraph]) =>\n toggleStyleCallback(format, !isTurningOff, segment, paragraph)\n );\n\n afterFormatCallback?.(model);\n\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n"]}
@@ -1,7 +1,8 @@
1
- import type { ContentModelDocument, ContentModelParagraph, ContentModelSegmentFormat, ContentModelText, FormatContentModelContext, IEditor } from 'roosterjs-content-model-types';
1
+ import type { ContentModelDocument, ContentModelParagraph, ContentModelSegmentFormat, ContentModelText, FormatContentModelContext, FormatContentModelOptions, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Invoke a callback to format the text segment before the selection marker using Content Model
4
4
  * @param editor The editor object
5
5
  * @param callback The callback to format the text segment.
6
+ * @returns True if the segment before cursor is found and callback is called, otherwise false
6
7
  */
7
- export declare function formatTextSegmentBeforeSelectionMarker(editor: IEditor, callback: (model: ContentModelDocument, previousSegment: ContentModelText, paragraph: ContentModelParagraph, markerFormat: ContentModelSegmentFormat, context: FormatContentModelContext) => boolean): void;
8
+ export declare function formatTextSegmentBeforeSelectionMarker(editor: IEditor, callback: (model: ContentModelDocument, previousSegment: ContentModelText, paragraph: ContentModelParagraph, markerFormat: ContentModelSegmentFormat, context: FormatContentModelContext) => boolean, options?: FormatContentModelOptions): boolean;
@@ -6,8 +6,10 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
6
6
  * Invoke a callback to format the text segment before the selection marker using Content Model
7
7
  * @param editor The editor object
8
8
  * @param callback The callback to format the text segment.
9
+ * @returns True if the segment before cursor is found and callback is called, otherwise false
9
10
  */
10
- function formatTextSegmentBeforeSelectionMarker(editor, callback) {
11
+ function formatTextSegmentBeforeSelectionMarker(editor, callback, options) {
12
+ var result = false;
11
13
  editor.formatContentModel(function (model, context) {
12
14
  var selectedSegmentsAndParagraphs = (0, roosterjs_content_model_dom_1.getSelectedSegmentsAndParagraphs)(model, false /*includeFormatHolder*/);
13
15
  if (selectedSegmentsAndParagraphs.length > 0 && selectedSegmentsAndParagraphs[0][1]) {
@@ -17,12 +19,14 @@ define(["require", "exports", "roosterjs-content-model-dom"], function (require,
17
19
  if (marker.segmentType === 'SelectionMarker' && markerIndex > 0) {
18
20
  var previousSegment = paragraph.segments[markerIndex - 1];
19
21
  if (previousSegment && previousSegment.segmentType === 'Text') {
22
+ result = true;
20
23
  return callback(model, previousSegment, paragraph, marker.format, context);
21
24
  }
22
25
  }
23
26
  }
24
27
  return false;
25
- });
28
+ }, options);
29
+ return result;
26
30
  }
27
31
  exports.formatTextSegmentBeforeSelectionMarker = formatTextSegmentBeforeSelectionMarker;
28
32
  });
@@ -1 +1 @@
1
- {"version":3,"file":"formatTextSegmentBeforeSelectionMarker.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatTextSegmentBeforeSelectionMarker.ts"],"names":[],"mappings":";;;;IAUA;;;;OAIG;IACH,SAAgB,sCAAsC,CAClD,MAAe,EACf,QAMY;QAEZ,MAAM,CAAC,kBAAkB,CAAC,UAAC,KAAK,EAAE,OAAO;YACrC,IAAM,6BAA6B,GAAG,IAAA,8DAAgC,EAClE,KAAK,EACL,KAAK,CAAC,uBAAuB,CAChC,CAAC;YAEF,IAAI,6BAA6B,CAAC,MAAM,GAAG,CAAC,IAAI,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;gBACjF,IAAM,MAAM,GAAG,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnD,IAAM,SAAS,GAAG,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACtD,IAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACvD,IAAI,MAAM,CAAC,WAAW,KAAK,iBAAiB,IAAI,WAAW,GAAG,CAAC,EAAE;oBAC7D,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;oBAC5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;wBAC3D,OAAO,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;qBAC9E;iBACJ;aACJ;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;IACP,CAAC;IA7BD,wFA6BC","sourcesContent":["import { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n IEditor,\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 */\nexport function formatTextSegmentBeforeSelectionMarker(\n editor: IEditor,\n callback: (\n model: ContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ContentModelParagraph,\n markerFormat: ContentModelSegmentFormat,\n context: FormatContentModelContext\n ) => boolean\n) {\n editor.formatContentModel((model, context) => {\n const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n false /*includeFormatHolder*/\n );\n\n if (selectedSegmentsAndParagraphs.length > 0 && selectedSegmentsAndParagraphs[0][1]) {\n const marker = selectedSegmentsAndParagraphs[0][0];\n const paragraph = selectedSegmentsAndParagraphs[0][1];\n const markerIndex = paragraph.segments.indexOf(marker);\n if (marker.segmentType === 'SelectionMarker' && markerIndex > 0) {\n const previousSegment = paragraph.segments[markerIndex - 1];\n if (previousSegment && previousSegment.segmentType === 'Text') {\n return callback(model, previousSegment, paragraph, marker.format, context);\n }\n }\n }\n return false;\n });\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;YAEF,IAAI,6BAA6B,CAAC,MAAM,GAAG,CAAC,IAAI,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;gBACjF,IAAM,MAAM,GAAG,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnD,IAAM,SAAS,GAAG,6BAA6B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACtD,IAAM,WAAW,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACvD,IAAI,MAAM,CAAC,WAAW,KAAK,iBAAiB,IAAI,WAAW,GAAG,CAAC,EAAE;oBAC7D,IAAM,eAAe,GAAG,SAAS,CAAC,QAAQ,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;oBAC5D,IAAI,eAAe,IAAI,eAAe,CAAC,WAAW,KAAK,MAAM,EAAE;wBAC3D,MAAM,GAAG,IAAI,CAAC;wBAEd,OAAO,QAAQ,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;qBAC9E;iBACJ;aACJ;YAED,OAAO,KAAK,CAAC;QACjB,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,OAAO,MAAM,CAAC;IAClB,CAAC;IArCD,wFAqCC","sourcesContent":["import { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelParagraph,\n ContentModelSegmentFormat,\n ContentModelText,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\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: ContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ContentModelParagraph,\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\n if (selectedSegmentsAndParagraphs.length > 0 && selectedSegmentsAndParagraphs[0][1]) {\n const marker = selectedSegmentsAndParagraphs[0][0];\n const paragraph = selectedSegmentsAndParagraphs[0][1];\n const markerIndex = paragraph.segments.indexOf(marker);\n if (marker.segmentType === 'SelectionMarker' && markerIndex > 0) {\n const previousSegment = paragraph.segments[markerIndex - 1];\n if (previousSegment && previousSegment.segmentType === 'Text') {\n result = true;\n\n return callback(model, previousSegment, paragraph, marker.format, context);\n }\n }\n }\n\n return false;\n }, options);\n\n return result;\n}\n"]}
@@ -54,3 +54,4 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
54
54
  export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
55
55
  export { setModelIndentation } from './modelApi/block/setModelIndentation';
56
56
  export { matchLink } from './modelApi/link/matchLink';
57
+ export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
package/lib-mjs/index.js CHANGED
@@ -54,4 +54,5 @@ export { setModelListStartNumber } from './modelApi/list/setModelListStartNumber
54
54
  export { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';
55
55
  export { setModelIndentation } from './modelApi/block/setModelIndentation';
56
56
  export { matchLink } from './modelApi/link/matchLink';
57
+ export { getListAnnounceData } from './modelApi/list/getListAnnounceData';
57
58
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/roosterjs-content-model-api/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;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,wCAAwC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAC;AAChF,OAAO,EAAE,WAAW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,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;AAElH,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","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 { 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';\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';\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,kB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,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;AAElH,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAClF,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC","sourcesContent":["export { insertTable } from './publicApi/table/insertTable';\nexport { formatTable } from './publicApi/table/formatTable';\nexport { setTableCellShade } from './publicApi/table/setTableCellShade';\nexport { editTable } from './publicApi/table/editTable';\nexport { applyTableBorderFormat } from './publicApi/table/applyTableBorderFormat';\nexport { toggleBullet } from './publicApi/list/toggleBullet';\nexport { toggleNumbering } from './publicApi/list/toggleNumbering';\nexport { toggleBold } from './publicApi/segment/toggleBold';\nexport { toggleItalic } from './publicApi/segment/toggleItalic';\nexport { toggleUnderline } from './publicApi/segment/toggleUnderline';\nexport { toggleStrikethrough } from './publicApi/segment/toggleStrikethrough';\nexport { toggleSubscript } from './publicApi/segment/toggleSubscript';\nexport { toggleSuperscript } from './publicApi/segment/toggleSuperscript';\nexport { setBackgroundColor } from './publicApi/segment/setBackgroundColor';\nexport { setFontName } from './publicApi/segment/setFontName';\nexport { setFontSize } from './publicApi/segment/setFontSize';\nexport { setTextColor } from './publicApi/segment/setTextColor';\nexport { changeFontSize } from './publicApi/segment/changeFontSize';\nexport { applySegmentFormat } from './publicApi/segment/applySegmentFormat';\nexport { changeCapitalization } from './publicApi/segment/changeCapitalization';\nexport { 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';\n\nexport { setListType } from './modelApi/list/setListType';\nexport { setModelListStyle } from './modelApi/list/setModelListStyle';\nexport { setModelListStartNumber } from './modelApi/list/setModelListStartNumber';\nexport { findListItemsInSameThread } from './modelApi/list/findListItemsInSameThread';\nexport { setModelIndentation } from './modelApi/block/setModelIndentation';\nexport { matchLink } from './modelApi/link/matchLink';\nexport { getListAnnounceData } from './modelApi/list/getListAnnounceData';\n"]}
@@ -1,8 +1,8 @@
1
- import type { ContentModelDocument } from 'roosterjs-content-model-types';
1
+ import type { ContentModelDocument, FormatContentModelContext } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * @param model The content model to set indentation
4
4
  * @param indentation The indentation type, 'indent' to indent, 'outdent' to outdent
5
5
  * @param length The length of indentation in pixel, default value is 40
6
6
  * Set indentation for selected list items or paragraphs
7
7
  */
8
- export declare function setModelIndentation(model: ContentModelDocument, indentation: 'indent' | 'outdent', length?: number): boolean;
8
+ export declare function setModelIndentation(model: ContentModelDocument, indentation: 'indent' | 'outdent', length?: number, context?: FormatContentModelContext): boolean;
@@ -1,4 +1,6 @@
1
+ import { __read, __spreadArray } from "tslib";
1
2
  import { findListItemsInSameThread } from '../list/findListItemsInSameThread';
3
+ import { getListAnnounceData } from '../list/getListAnnounceData';
2
4
  import { createListLevel, getOperationalBlocks, isBlockGroupOfType, parseValueWithUnit, updateListMetadata, } from 'roosterjs-content-model-dom';
3
5
  var IndentStepInPixel = 40;
4
6
  /**
@@ -7,7 +9,7 @@ var IndentStepInPixel = 40;
7
9
  * @param length The length of indentation in pixel, default value is 40
8
10
  * Set indentation for selected list items or paragraphs
9
11
  */
10
- export function setModelIndentation(model, indentation, length) {
12
+ export function setModelIndentation(model, indentation, length, context) {
11
13
  if (length === void 0) { length = IndentStepInPixel; }
12
14
  var paragraphOrListItem = getOperationalBlocks(model, ['ListItem'], ['TableCell']);
13
15
  var isIndent = indentation == 'indent';
@@ -54,6 +56,9 @@ export function setModelIndentation(model, indentation, length) {
54
56
  else {
55
57
  block.levels.pop();
56
58
  }
59
+ if (block.levels.length > 0 && context) {
60
+ context.announceData = getListAnnounceData(__spreadArray([block], __read(path), false));
61
+ }
57
62
  }
58
63
  }
59
64
  else if (block) {