roosterjs-content-model-api 9.40.0 → 9.42.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 (46) hide show
  1. package/lib/publicApi/segment/toggleBold.d.ts +2 -2
  2. package/lib/publicApi/segment/toggleBold.js +7 -1
  3. package/lib/publicApi/segment/toggleBold.js.map +1 -1
  4. package/lib/publicApi/segment/toggleItalic.d.ts +2 -2
  5. package/lib/publicApi/segment/toggleItalic.js +8 -2
  6. package/lib/publicApi/segment/toggleItalic.js.map +1 -1
  7. package/lib/publicApi/segment/toggleUnderline.d.ts +2 -2
  8. package/lib/publicApi/segment/toggleUnderline.js +8 -2
  9. package/lib/publicApi/segment/toggleUnderline.js.map +1 -1
  10. package/lib/publicApi/table/insertTable.d.ts +4 -4
  11. package/lib/publicApi/table/insertTable.js +9 -5
  12. package/lib/publicApi/table/insertTable.js.map +1 -1
  13. package/lib/publicApi/utils/formatSegmentWithContentModel.d.ts +2 -2
  14. package/lib/publicApi/utils/formatSegmentWithContentModel.js +2 -2
  15. package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  16. package/lib-amd/publicApi/segment/toggleBold.d.ts +2 -2
  17. package/lib-amd/publicApi/segment/toggleBold.js +7 -1
  18. package/lib-amd/publicApi/segment/toggleBold.js.map +1 -1
  19. package/lib-amd/publicApi/segment/toggleItalic.d.ts +2 -2
  20. package/lib-amd/publicApi/segment/toggleItalic.js +8 -2
  21. package/lib-amd/publicApi/segment/toggleItalic.js.map +1 -1
  22. package/lib-amd/publicApi/segment/toggleUnderline.d.ts +2 -2
  23. package/lib-amd/publicApi/segment/toggleUnderline.js +8 -2
  24. package/lib-amd/publicApi/segment/toggleUnderline.js.map +1 -1
  25. package/lib-amd/publicApi/table/insertTable.d.ts +4 -4
  26. package/lib-amd/publicApi/table/insertTable.js +9 -6
  27. package/lib-amd/publicApi/table/insertTable.js.map +1 -1
  28. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.d.ts +2 -2
  29. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +2 -2
  30. package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  31. package/lib-mjs/publicApi/segment/toggleBold.d.ts +2 -2
  32. package/lib-mjs/publicApi/segment/toggleBold.js +7 -1
  33. package/lib-mjs/publicApi/segment/toggleBold.js.map +1 -1
  34. package/lib-mjs/publicApi/segment/toggleItalic.d.ts +2 -2
  35. package/lib-mjs/publicApi/segment/toggleItalic.js +8 -2
  36. package/lib-mjs/publicApi/segment/toggleItalic.js.map +1 -1
  37. package/lib-mjs/publicApi/segment/toggleUnderline.d.ts +2 -2
  38. package/lib-mjs/publicApi/segment/toggleUnderline.js +8 -2
  39. package/lib-mjs/publicApi/segment/toggleUnderline.js.map +1 -1
  40. package/lib-mjs/publicApi/table/insertTable.d.ts +4 -4
  41. package/lib-mjs/publicApi/table/insertTable.js +9 -5
  42. package/lib-mjs/publicApi/table/insertTable.js.map +1 -1
  43. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.d.ts +2 -2
  44. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +2 -2
  45. package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
  46. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle bold style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleBold(editor: IEditor): void;
6
+ export declare function toggleBold(editor: IEditor, options?: AnnouncingOption): void;
@@ -7,7 +7,7 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
7
7
  * Toggle bold style
8
8
  * @param editor The editor to operate on
9
9
  */
10
- function toggleBold(editor) {
10
+ function toggleBold(editor, options) {
11
11
  editor.focus();
12
12
  (0, formatSegmentWithContentModel_1.formatSegmentWithContentModel)(editor, 'toggleBold', function (format, isTurningOn) {
13
13
  format.fontWeight = isTurningOn ? 'bold' : 'normal';
@@ -16,6 +16,12 @@ function toggleBold(editor) {
16
16
  return (0, roosterjs_content_model_dom_1.isBold)(typeof format.fontWeight == 'undefined'
17
17
  ? (_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.decorator) === null || _a === void 0 ? void 0 : _a.format.fontWeight
18
18
  : format.fontWeight);
19
+ }, undefined /* includeFormatHolder */, function (_model, isTurningOff, context) {
20
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
21
+ context.announceData = {
22
+ defaultStrings: isTurningOff ? 'announceBoldOff' : 'announceBoldOn',
23
+ };
24
+ }
19
25
  });
20
26
  }
21
27
  exports.toggleBold = toggleBold;
@@ -1 +1 @@
1
- {"version":3,"file":"toggleBold.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleBold.ts"],"names":[],"mappings":";;;AAAA,wFAAuF;AACvF,2EAAqD;AAGrD;;;GAGG;AACH,SAAgB,UAAU,CAAC,MAAe;IACtC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,YAAY,EACZ,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxD,CAAC,EACD,UAAC,MAAM,EAAE,CAAC,EAAE,SAAS;;QACjB,OAAA,IAAA,oCAAM,EACF,OAAO,MAAM,CAAC,UAAU,IAAI,WAAW;YACnC,CAAC,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,0CAAE,MAAM,CAAC,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAA;KAAA,CACR,CAAC;AACN,CAAC;AAhBD,gCAgBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport { isBold } from 'roosterjs-content-model-dom';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle bold style\n * @param editor The editor to operate on\n */\nexport function toggleBold(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleBold',\n (format, isTurningOn) => {\n format.fontWeight = isTurningOn ? 'bold' : 'normal';\n },\n (format, _, paragraph) =>\n isBold(\n typeof format.fontWeight == 'undefined'\n ? paragraph?.decorator?.format.fontWeight\n : format.fontWeight\n )\n );\n}\n"]}
1
+ {"version":3,"file":"toggleBold.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleBold.ts"],"names":[],"mappings":";;;AAAA,wFAAuF;AACvF,2EAAqD;AAGrD;;;GAGG;AACH,SAAgB,UAAU,CAAC,MAAe,EAAE,OAA0B;IAClE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,YAAY,EACZ,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxD,CAAC,EACD,UAAC,MAAM,EAAE,CAAC,EAAE,SAAS;;QACjB,OAAA,IAAA,oCAAM,EACF,OAAO,MAAM,CAAC,UAAU,IAAI,WAAW;YACnC,CAAC,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,0CAAE,MAAM,CAAC,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAA;KAAA,EACL,SAAS,CAAC,yBAAyB,EACnC,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;QAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;YAC/B,OAAO,CAAC,YAAY,GAAG;gBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB;aACtE,CAAC;SACL;IACL,CAAC,CACJ,CAAC;AACN,CAAC;AAxBD,gCAwBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport { isBold } from 'roosterjs-content-model-dom';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle bold style\n * @param editor The editor to operate on\n */\nexport function toggleBold(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleBold',\n (format, isTurningOn) => {\n format.fontWeight = isTurningOn ? 'bold' : 'normal';\n },\n (format, _, paragraph) =>\n isBold(\n typeof format.fontWeight == 'undefined'\n ? paragraph?.decorator?.format.fontWeight\n : format.fontWeight\n ),\n undefined /* includeFormatHolder */,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceBoldOff' : 'announceBoldOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle italic style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleItalic(editor: IEditor): void;
6
+ export declare function toggleItalic(editor: IEditor, options?: AnnouncingOption): void;
@@ -6,11 +6,17 @@ var formatSegmentWithContentModel_1 = require("../utils/formatSegmentWithContent
6
6
  * Toggle italic style
7
7
  * @param editor The editor to operate on
8
8
  */
9
- function toggleItalic(editor) {
9
+ function toggleItalic(editor, options) {
10
10
  editor.focus();
11
11
  (0, formatSegmentWithContentModel_1.formatSegmentWithContentModel)(editor, 'toggleItalic', function (format, isTurningOn) {
12
12
  format.italic = !!isTurningOn;
13
- }, function (format) { return !!format.italic; });
13
+ }, function (format) { return !!format.italic; }, undefined /* includingFormatHolder */, function (_model, isTurningOff, context) {
14
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
15
+ context.announceData = {
16
+ defaultStrings: isTurningOff ? 'announceItalicOff' : 'announceItalicOn',
17
+ };
18
+ }
19
+ });
14
20
  }
15
21
  exports.toggleItalic = toggleItalic;
16
22
  //# sourceMappingURL=toggleItalic.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toggleItalic.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleItalic.ts"],"names":[],"mappings":";;;AAAA,wFAAuF;AAGvF;;;GAGG;AACH,SAAgB,YAAY,CAAC,MAAe;IACxC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,cAAc,EACd,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;IAClC,CAAC,EACD,UAAA,MAAM,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,CAC5B,CAAC;AACN,CAAC;AAXD,oCAWC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle italic style\n * @param editor The editor to operate on\n */\nexport function toggleItalic(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleItalic',\n (format, isTurningOn) => {\n format.italic = !!isTurningOn;\n },\n format => !!format.italic\n );\n}\n"]}
1
+ {"version":3,"file":"toggleItalic.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleItalic.ts"],"names":[],"mappings":";;;AAAA,wFAAuF;AAGvF;;;GAGG;AACH,SAAgB,YAAY,CAAC,MAAe,EAAE,OAA0B;IACpE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,cAAc,EACd,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;IAClC,CAAC,EACD,UAAA,MAAM,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,EACzB,SAAS,CAAC,2BAA2B,EACrC,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;QAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;YAC/B,OAAO,CAAC,YAAY,GAAG;gBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB;aAC1E,CAAC;SACL;IACL,CAAC,CACJ,CAAC;AACN,CAAC;AAnBD,oCAmBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle italic style\n * @param editor The editor to operate on\n */\nexport function toggleItalic(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleItalic',\n (format, isTurningOn) => {\n format.italic = !!isTurningOn;\n },\n format => !!format.italic,\n undefined /* includingFormatHolder */,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceItalicOff' : 'announceItalicOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle underline style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleUnderline(editor: IEditor): void;
6
+ export declare function toggleUnderline(editor: IEditor, options?: AnnouncingOption): void;
@@ -6,14 +6,20 @@ var formatSegmentWithContentModel_1 = require("../utils/formatSegmentWithContent
6
6
  * Toggle underline style
7
7
  * @param editor The editor to operate on
8
8
  */
9
- function toggleUnderline(editor) {
9
+ function toggleUnderline(editor, options) {
10
10
  editor.focus();
11
11
  (0, formatSegmentWithContentModel_1.formatSegmentWithContentModel)(editor, 'toggleUnderline', function (format, isTurningOn, segment) {
12
12
  format.underline = !!isTurningOn;
13
13
  if (segment === null || segment === void 0 ? void 0 : segment.link) {
14
14
  segment.link.format.underline = !!isTurningOn;
15
15
  }
16
- }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/);
16
+ }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/, function (_model, isTurningOff, context) {
17
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
18
+ context.announceData = {
19
+ defaultStrings: isTurningOff ? 'announceUnderlineOff' : 'announceUnderlineOn',
20
+ };
21
+ }
22
+ });
17
23
  }
18
24
  exports.toggleUnderline = toggleUnderline;
19
25
  //# sourceMappingURL=toggleUnderline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;;AAAA,wFAAuF;AAGvF;;;GAGG;AACH,SAAgB,eAAe,CAAC,MAAe;IAC3C,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;QACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;SACjD;IACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,CAClC,CAAC;AACN,CAAC;AAhBD,0CAgBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport function toggleUnderline(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/\n );\n}\n"]}
1
+ {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;;AAAA,wFAAuF;AAGvF;;;GAGG;AACH,SAAgB,eAAe,CAAC,MAAe,EAAE,OAA0B;IACvE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;QACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;SACjD;IACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,EAC/B,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;QAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;YAC/B,OAAO,CAAC,YAAY,GAAG;gBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,qBAAqB;aAChF,CAAC;SACL;IACL,CAAC,CACJ,CAAC;AACN,CAAC;AAvBD,0CAuBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport function toggleUnderline(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceUnderlineOff' : 'announceUnderlineOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,11 +1,11 @@
1
- import type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
1
+ import type { ContentModelTableFormat, IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Insert table into editor at current selection
4
4
  * @param editor The editor instance
5
5
  * @param columns Number of columns in table, it also controls the default table cell width:
6
6
  * if columns <= 4, width = 120px; if columns <= 6, width = 100px; else width = 70px
7
7
  * @param rows Number of rows in table
8
- * @param format (Optional) The table format. If not passed, the default format will be applied:
9
- * background color: #FFF; border color: #ABABAB
8
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
9
+ * @param format (Optional) The table format used for style attributes
10
10
  */
11
- export declare function insertTable(editor: IEditor, columns: number, rows: number, format?: Partial<TableMetadataFormat>): void;
11
+ export declare function insertTable(editor: IEditor, columns: number, rows: number, tableMetadataFormat?: Partial<TableMetadataFormat>, format?: ContentModelTableFormat): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.insertTable = void 0;
4
+ var tslib_1 = require("tslib");
4
5
  var adjustIndentation_1 = require("../../modelApi/common/adjustIndentation");
5
6
  var createTableStructure_1 = require("../../modelApi/table/createTableStructure");
6
7
  var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
@@ -10,10 +11,10 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
10
11
  * @param columns Number of columns in table, it also controls the default table cell width:
11
12
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
12
13
  * @param rows Number of rows in table
13
- * @param format (Optional) The table format. If not passed, the default format will be applied:
14
- * background color: #FFF; border color: #ABABAB
14
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
15
+ * @param format (Optional) The table format used for style attributes
15
16
  */
16
- function insertTable(editor, columns, rows, format) {
17
+ function insertTable(editor, columns, rows, tableMetadataFormat, format) {
17
18
  editor.focus();
18
19
  editor.formatContentModel(function (model, context) {
19
20
  var _a, _b, _c;
@@ -21,11 +22,14 @@ function insertTable(editor, columns, rows, format) {
21
22
  if (insertPosition) {
22
23
  var doc = (0, roosterjs_content_model_dom_1.createContentModelDocument)();
23
24
  var table = (0, createTableStructure_1.createTableStructure)(doc, columns, rows);
25
+ if (format) {
26
+ table.format = (0, tslib_1.__assign)({}, format);
27
+ }
24
28
  (0, roosterjs_content_model_dom_1.normalizeTable)(table, editor.getPendingFormat() || insertPosition.marker.format);
25
29
  (0, adjustIndentation_1.adjustTableIndentation)(insertPosition, table);
26
30
  // Assign default vertical align
27
- format = format || { verticalAlign: 'top' };
28
- (0, roosterjs_content_model_dom_1.applyTableFormat)(table, format);
31
+ tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };
32
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, tableMetadataFormat);
29
33
  (0, roosterjs_content_model_dom_1.mergeModel)(model, doc, context, {
30
34
  insertPosition: insertPosition,
31
35
  mergeFormat: 'mergeAll',
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;AAAA,6EAAiF;AACjF,kFAAiF;AACjF,2EAQqC;AAGrC;;;;;;;;GAQG;AACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAAqC;IAErC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;QACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;QAEvE,IAAI,cAAc,EAAE;YAChB,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;YACzC,IAAM,KAAK,GAAG,IAAA,2CAAoB,EAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAEvD,IAAA,4CAAc,EAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEjF,IAAA,0CAAsB,EAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YAE9C,gCAAgC;YAChC,MAAM,GAAG,MAAM,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;YAC5C,IAAA,8CAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAChC,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;gBAC5B,cAAc,gBAAA;gBACd,WAAW,EAAE,UAAU;aAC1B,CAAC,CAAC;YAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;gBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;gBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC;AA7CD,kCA6CC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;AAAA,6EAAiF;AACjF,kFAAiF;AACjF,2EAQqC;AAOrC;;;;;;;;GAQG;AACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,mBAAkD,EAClD,MAAgC;IAEhC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;QACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;QAEvE,IAAI,cAAc,EAAE;YAChB,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;YACzC,IAAM,KAAK,GAAG,IAAA,2CAAoB,EAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACvD,IAAI,MAAM,EAAE;gBACR,KAAK,CAAC,MAAM,6BAAQ,MAAM,CAAE,CAAC;aAChC;YAED,IAAA,4CAAc,EAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEjF,IAAA,0CAAsB,EAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YAE9C,gCAAgC;YAChC,mBAAmB,GAAG,mBAAmB,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;YACtE,IAAA,8CAAgB,EAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;YAC7C,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;gBAC5B,cAAc,gBAAA;gBACd,WAAW,EAAE,UAAU;aAC1B,CAAC,CAAC;YAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;gBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;gBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC;AAjDD,kCAiDC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTableFormat,\n IEditor,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB\n * @param format (Optional) The table format used for style attributes\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n tableMetadataFormat?: Partial<TableMetadataFormat>,\n format?: ContentModelTableFormat\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n if (format) {\n table.format = { ...format };\n }\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };\n applyTableFormat(table, tableMetadataFormat);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ContentModelSegmentFormat, IEditor, ReadonlyContentModelDocument, ShallowMutableContentModelParagraph, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
1
+ import type { ContentModelSegmentFormat, FormatContentModelContext, IEditor, ReadonlyContentModelDocument, ShallowMutableContentModelParagraph, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Invoke a callback to format the selected segment using Content Model
4
4
  * @param editor The editor object
@@ -8,4 +8,4 @@ import type { ContentModelSegmentFormat, IEditor, ReadonlyContentModelDocument,
8
8
  * @param includingFormatHolder True to also include format holder of list item when search selected segments
9
9
  * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree
10
10
  */
11
- export declare function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument) => void): void;
11
+ export declare function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument, isTurningOff: boolean, context: FormatContentModelContext) => void): void;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatSegmentWithContentModel = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
6
5
  var adjustWordSelection_1 = require("../../modelApi/selection/adjustWordSelection");
7
6
  var createEditorContextForEntity_1 = require("./createEditorContextForEntity");
7
+ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
8
8
  /**
9
9
  * Invoke a callback to format the selected segment using Content Model
10
10
  * @param editor The editor object
@@ -53,7 +53,7 @@ function formatSegmentWithContentModel(editor, apiName, toggleStyleCallback, seg
53
53
  toggleStyleCallback(format, !isTurningOff, segment, paragraph);
54
54
  });
55
55
  // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back
56
- afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
56
+ afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model, isTurningOff, context);
57
57
  // 6. finally merge segments if possible, to avoid fragmentation
58
58
  formatsAndSegments.forEach(function (_a) {
59
59
  var _b = (0, tslib_1.__read)(_a, 3), _ = _b[0], __ = _b[1], paragraph = _b[2];
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,2EAOqC;AAYrC,oFAAmF;AACnF,+EAA8E;AAE9E;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;IAEnE,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;QAE3E,0DAA0D;QAC1D,IAAI,oBAAoB,EAAE;YACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAExC,oBAAoB,GAAG,IAAA,yCAAmB,EACtC,KAAK,EAC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QAAA;QAC5C,IAAM,aAAa,GAAG,IAAA,2DAA4B,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\nimport { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;AAAA,oFAAmF;AACnF,+EAA8E;AAC9E,2EAOqC;AAcrC;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAIS;IAET,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;QAE3E,0DAA0D;QAC1D,IAAI,oBAAoB,EAAE;YACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAExC,oBAAoB,GAAG,IAAA,yCAAmB,EACtC,KAAK,EACL,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC7B,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,EAAE,MAAI,EAAE,MAAI,CAAC,EAAf,CAAe,CAAC,CAAC;YAE5B,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACjC,oBAAoB,GAAG,KAAK,CAAC;aAChC;SACJ;QAED,0CAA0C;QAC1C,IAAM,kBAAkB,GAIlB,EAAE,CAAC;QACT,IAAM,kBAAkB,GAI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ACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormatContentModelContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (\n model: ReadonlyContentModelDocument,\n isTurningOff: boolean,\n context: FormatContentModelContext\n ) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model, isTurningOff, context);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle bold style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleBold(editor: IEditor): void;
6
+ export declare function toggleBold(editor: IEditor, options?: AnnouncingOption): void;
@@ -6,7 +6,7 @@ define(["require", "exports", "../utils/formatSegmentWithContentModel", "rooster
6
6
  * Toggle bold style
7
7
  * @param editor The editor to operate on
8
8
  */
9
- function toggleBold(editor) {
9
+ function toggleBold(editor, options) {
10
10
  editor.focus();
11
11
  (0, formatSegmentWithContentModel_1.formatSegmentWithContentModel)(editor, 'toggleBold', function (format, isTurningOn) {
12
12
  format.fontWeight = isTurningOn ? 'bold' : 'normal';
@@ -15,6 +15,12 @@ define(["require", "exports", "../utils/formatSegmentWithContentModel", "rooster
15
15
  return (0, roosterjs_content_model_dom_1.isBold)(typeof format.fontWeight == 'undefined'
16
16
  ? (_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.decorator) === null || _a === void 0 ? void 0 : _a.format.fontWeight
17
17
  : format.fontWeight);
18
+ }, undefined /* includeFormatHolder */, function (_model, isTurningOff, context) {
19
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
20
+ context.announceData = {
21
+ defaultStrings: isTurningOff ? 'announceBoldOff' : 'announceBoldOn',
22
+ };
23
+ }
18
24
  });
19
25
  }
20
26
  exports.toggleBold = toggleBold;
@@ -1 +1 @@
1
- {"version":3,"file":"toggleBold.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleBold.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACH,SAAgB,UAAU,CAAC,MAAe;QACtC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,YAAY,EACZ,UAAC,MAAM,EAAE,WAAW;YAChB,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxD,CAAC,EACD,UAAC,MAAM,EAAE,CAAC,EAAE,SAAS;;YACjB,OAAA,IAAA,oCAAM,EACF,OAAO,MAAM,CAAC,UAAU,IAAI,WAAW;gBACnC,CAAC,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,0CAAE,MAAM,CAAC,UAAU;gBACzC,CAAC,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAA;SAAA,CACR,CAAC;IACN,CAAC;IAhBD,gCAgBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport { isBold } from 'roosterjs-content-model-dom';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle bold style\n * @param editor The editor to operate on\n */\nexport function toggleBold(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleBold',\n (format, isTurningOn) => {\n format.fontWeight = isTurningOn ? 'bold' : 'normal';\n },\n (format, _, paragraph) =>\n isBold(\n typeof format.fontWeight == 'undefined'\n ? paragraph?.decorator?.format.fontWeight\n : format.fontWeight\n )\n );\n}\n"]}
1
+ {"version":3,"file":"toggleBold.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleBold.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACH,SAAgB,UAAU,CAAC,MAAe,EAAE,OAA0B;QAClE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,YAAY,EACZ,UAAC,MAAM,EAAE,WAAW;YAChB,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;QACxD,CAAC,EACD,UAAC,MAAM,EAAE,CAAC,EAAE,SAAS;;YACjB,OAAA,IAAA,oCAAM,EACF,OAAO,MAAM,CAAC,UAAU,IAAI,WAAW;gBACnC,CAAC,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,0CAAE,MAAM,CAAC,UAAU;gBACzC,CAAC,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAA;SAAA,EACL,SAAS,CAAC,yBAAyB,EACnC,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;YAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;gBAC/B,OAAO,CAAC,YAAY,GAAG;oBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB;iBACtE,CAAC;aACL;QACL,CAAC,CACJ,CAAC;IACN,CAAC;IAxBD,gCAwBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport { isBold } from 'roosterjs-content-model-dom';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle bold style\n * @param editor The editor to operate on\n */\nexport function toggleBold(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleBold',\n (format, isTurningOn) => {\n format.fontWeight = isTurningOn ? 'bold' : 'normal';\n },\n (format, _, paragraph) =>\n isBold(\n typeof format.fontWeight == 'undefined'\n ? paragraph?.decorator?.format.fontWeight\n : format.fontWeight\n ),\n undefined /* includeFormatHolder */,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceBoldOff' : 'announceBoldOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle italic style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleItalic(editor: IEditor): void;
6
+ export declare function toggleItalic(editor: IEditor, options?: AnnouncingOption): void;
@@ -6,11 +6,17 @@ define(["require", "exports", "../utils/formatSegmentWithContentModel"], functio
6
6
  * Toggle italic style
7
7
  * @param editor The editor to operate on
8
8
  */
9
- function toggleItalic(editor) {
9
+ function toggleItalic(editor, options) {
10
10
  editor.focus();
11
11
  (0, formatSegmentWithContentModel_1.formatSegmentWithContentModel)(editor, 'toggleItalic', function (format, isTurningOn) {
12
12
  format.italic = !!isTurningOn;
13
- }, function (format) { return !!format.italic; });
13
+ }, function (format) { return !!format.italic; }, undefined /* includingFormatHolder */, function (_model, isTurningOff, context) {
14
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
15
+ context.announceData = {
16
+ defaultStrings: isTurningOff ? 'announceItalicOff' : 'announceItalicOn',
17
+ };
18
+ }
19
+ });
14
20
  }
15
21
  exports.toggleItalic = toggleItalic;
16
22
  });
@@ -1 +1 @@
1
- {"version":3,"file":"toggleItalic.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleItalic.ts"],"names":[],"mappings":";;;;IAGA;;;OAGG;IACH,SAAgB,YAAY,CAAC,MAAe;QACxC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,cAAc,EACd,UAAC,MAAM,EAAE,WAAW;YAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;QAClC,CAAC,EACD,UAAA,MAAM,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,CAC5B,CAAC;IACN,CAAC;IAXD,oCAWC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle italic style\n * @param editor The editor to operate on\n */\nexport function toggleItalic(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleItalic',\n (format, isTurningOn) => {\n format.italic = !!isTurningOn;\n },\n format => !!format.italic\n );\n}\n"]}
1
+ {"version":3,"file":"toggleItalic.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleItalic.ts"],"names":[],"mappings":";;;;IAGA;;;OAGG;IACH,SAAgB,YAAY,CAAC,MAAe,EAAE,OAA0B;QACpE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,cAAc,EACd,UAAC,MAAM,EAAE,WAAW;YAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;QAClC,CAAC,EACD,UAAA,MAAM,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,EACzB,SAAS,CAAC,2BAA2B,EACrC,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;YAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;gBAC/B,OAAO,CAAC,YAAY,GAAG;oBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB;iBAC1E,CAAC;aACL;QACL,CAAC,CACJ,CAAC;IACN,CAAC;IAnBD,oCAmBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle italic style\n * @param editor The editor to operate on\n */\nexport function toggleItalic(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleItalic',\n (format, isTurningOn) => {\n format.italic = !!isTurningOn;\n },\n format => !!format.italic,\n undefined /* includingFormatHolder */,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceItalicOff' : 'announceItalicOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle underline style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleUnderline(editor: IEditor): void;
6
+ export declare function toggleUnderline(editor: IEditor, options?: AnnouncingOption): void;
@@ -6,14 +6,20 @@ define(["require", "exports", "../utils/formatSegmentWithContentModel"], functio
6
6
  * Toggle underline style
7
7
  * @param editor The editor to operate on
8
8
  */
9
- function toggleUnderline(editor) {
9
+ function toggleUnderline(editor, options) {
10
10
  editor.focus();
11
11
  (0, formatSegmentWithContentModel_1.formatSegmentWithContentModel)(editor, 'toggleUnderline', function (format, isTurningOn, segment) {
12
12
  format.underline = !!isTurningOn;
13
13
  if (segment === null || segment === void 0 ? void 0 : segment.link) {
14
14
  segment.link.format.underline = !!isTurningOn;
15
15
  }
16
- }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/);
16
+ }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/, function (_model, isTurningOff, context) {
17
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
18
+ context.announceData = {
19
+ defaultStrings: isTurningOff ? 'announceUnderlineOff' : 'announceUnderlineOn',
20
+ };
21
+ }
22
+ });
17
23
  }
18
24
  exports.toggleUnderline = toggleUnderline;
19
25
  });
@@ -1 +1 @@
1
- {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;;;IAGA;;;OAGG;IACH,SAAgB,eAAe,CAAC,MAAe;QAC3C,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;YACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;YAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;gBACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;aACjD;QACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,CAClC,CAAC;IACN,CAAC;IAhBD,0CAgBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport function toggleUnderline(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/\n );\n}\n"]}
1
+ {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":";;;;IAGA;;;OAGG;IACH,SAAgB,eAAe,CAAC,MAAe,EAAE,OAA0B;QACvE,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,IAAA,6DAA6B,EACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;YACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;YAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;gBACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;aACjD;QACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,EAC/B,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;YAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;gBAC/B,OAAO,CAAC,YAAY,GAAG;oBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,qBAAqB;iBAChF,CAAC;aACL;QACL,CAAC,CACJ,CAAC;IACN,CAAC;IAvBD,0CAuBC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport function toggleUnderline(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceUnderlineOff' : 'announceUnderlineOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,11 +1,11 @@
1
- import type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
1
+ import type { ContentModelTableFormat, IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Insert table into editor at current selection
4
4
  * @param editor The editor instance
5
5
  * @param columns Number of columns in table, it also controls the default table cell width:
6
6
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
7
7
  * @param rows Number of rows in table
8
- * @param format (Optional) The table format. If not passed, the default format will be applied:
9
- * background color: #FFF; border color: #ABABAB
8
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
9
+ * @param format (Optional) The table format used for style attributes
10
10
  */
11
- export declare function insertTable(editor: IEditor, columns: number, rows: number, format?: Partial<TableMetadataFormat>): void;
11
+ export declare function insertTable(editor: IEditor, columns: number, rows: number, tableMetadataFormat?: Partial<TableMetadataFormat>, format?: ContentModelTableFormat): void;
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../modelApi/table/createTableStructure", "roosterjs-content-model-dom"], function (require, exports, adjustIndentation_1, createTableStructure_1, roosterjs_content_model_dom_1) {
1
+ define(["require", "exports", "tslib", "../../modelApi/common/adjustIndentation", "../../modelApi/table/createTableStructure", "roosterjs-content-model-dom"], function (require, exports, tslib_1, adjustIndentation_1, createTableStructure_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.insertTable = void 0;
@@ -8,10 +8,10 @@ define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../
8
8
  * @param columns Number of columns in table, it also controls the default table cell width:
9
9
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
10
10
  * @param rows Number of rows in table
11
- * @param format (Optional) The table format. If not passed, the default format will be applied:
12
- * background color: #FFF; border color: #ABABAB
11
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
12
+ * @param format (Optional) The table format used for style attributes
13
13
  */
14
- function insertTable(editor, columns, rows, format) {
14
+ function insertTable(editor, columns, rows, tableMetadataFormat, format) {
15
15
  editor.focus();
16
16
  editor.formatContentModel(function (model, context) {
17
17
  var _a, _b, _c;
@@ -19,11 +19,14 @@ define(["require", "exports", "../../modelApi/common/adjustIndentation", "../../
19
19
  if (insertPosition) {
20
20
  var doc = (0, roosterjs_content_model_dom_1.createContentModelDocument)();
21
21
  var table = (0, createTableStructure_1.createTableStructure)(doc, columns, rows);
22
+ if (format) {
23
+ table.format = (0, tslib_1.__assign)({}, format);
24
+ }
22
25
  (0, roosterjs_content_model_dom_1.normalizeTable)(table, editor.getPendingFormat() || insertPosition.marker.format);
23
26
  (0, adjustIndentation_1.adjustTableIndentation)(insertPosition, table);
24
27
  // Assign default vertical align
25
- format = format || { verticalAlign: 'top' };
26
- (0, roosterjs_content_model_dom_1.applyTableFormat)(table, format);
28
+ tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };
29
+ (0, roosterjs_content_model_dom_1.applyTableFormat)(table, tableMetadataFormat);
27
30
  (0, roosterjs_content_model_dom_1.mergeModel)(model, doc, context, {
28
31
  insertPosition: insertPosition,
29
32
  mergeFormat: 'mergeAll',
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;IAaA;;;;;;;;OAQG;IACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAAqC;QAErC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;YAEvE,IAAI,cAAc,EAAE;gBAChB,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;gBACzC,IAAM,KAAK,GAAG,IAAA,2CAAoB,EAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBAEvD,IAAA,4CAAc,EAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEjF,IAAA,0CAAsB,EAAC,cAAc,EAAE,KAAK,CAAC,CAAC;gBAE9C,gCAAgC;gBAChC,MAAM,GAAG,MAAM,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;gBAC5C,IAAA,8CAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBAChC,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;oBAC5B,cAAc,gBAAA;oBACd,WAAW,EAAE,UAAU;iBAC1B,CAAC,CAAC;gBAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;gBAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;oBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;oBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC;IA7CD,kCA6CC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";;;;IAiBA;;;;;;;;OAQG;IACH,SAAgB,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,mBAAkD,EAClD,MAAgC;QAEhC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,cAAc,GAAG,IAAA,6CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;YAEvE,IAAI,cAAc,EAAE;gBAChB,IAAM,GAAG,GAAG,IAAA,wDAA0B,GAAE,CAAC;gBACzC,IAAM,KAAK,GAAG,IAAA,2CAAoB,EAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;gBACvD,IAAI,MAAM,EAAE;oBACR,KAAK,CAAC,MAAM,6BAAQ,MAAM,CAAE,CAAC;iBAChC;gBAED,IAAA,4CAAc,EAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEjF,IAAA,0CAAsB,EAAC,cAAc,EAAE,KAAK,CAAC,CAAC;gBAE9C,gCAAgC;gBAChC,mBAAmB,GAAG,mBAAmB,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;gBACtE,IAAA,8CAAgB,EAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;gBAC7C,IAAA,wCAAU,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;oBAC5B,cAAc,gBAAA;oBACd,WAAW,EAAE,UAAU;iBAC1B,CAAC,CAAC;gBAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;gBAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;oBACtC,IAAM,MAAM,GAAG,IAAA,mDAAqB,EAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;oBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;oBACpC,IAAA,0CAAY,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;iBAC/B;gBAED,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,OAAO,EAAE,aAAa;SACzB,CACJ,CAAC;IACN,CAAC;IAjDD,kCAiDC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTableFormat,\n IEditor,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB\n * @param format (Optional) The table format used for style attributes\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n tableMetadataFormat?: Partial<TableMetadataFormat>,\n format?: ContentModelTableFormat\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n if (format) {\n table.format = { ...format };\n }\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };\n applyTableFormat(table, tableMetadataFormat);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ContentModelSegmentFormat, IEditor, ReadonlyContentModelDocument, ShallowMutableContentModelParagraph, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
1
+ import type { ContentModelSegmentFormat, FormatContentModelContext, IEditor, ReadonlyContentModelDocument, ShallowMutableContentModelParagraph, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Invoke a callback to format the selected segment using Content Model
4
4
  * @param editor The editor object
@@ -8,4 +8,4 @@ import type { ContentModelSegmentFormat, IEditor, ReadonlyContentModelDocument,
8
8
  * @param includingFormatHolder True to also include format holder of list item when search selected segments
9
9
  * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree
10
10
  */
11
- export declare function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument) => void): void;
11
+ export declare function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument, isTurningOff: boolean, context: FormatContentModelContext) => void): void;
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "roosterjs-content-model-dom", "../../modelApi/selection/adjustWordSelection", "./createEditorContextForEntity"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, adjustWordSelection_1, createEditorContextForEntity_1) {
1
+ define(["require", "exports", "tslib", "../../modelApi/selection/adjustWordSelection", "./createEditorContextForEntity", "roosterjs-content-model-dom"], function (require, exports, tslib_1, adjustWordSelection_1, createEditorContextForEntity_1, roosterjs_content_model_dom_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.formatSegmentWithContentModel = void 0;
@@ -50,7 +50,7 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "../../mod
50
50
  toggleStyleCallback(format, !isTurningOff, segment, paragraph);
51
51
  });
52
52
  // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back
53
- afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
53
+ afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model, isTurningOff, context);
54
54
  // 6. finally merge segments if possible, to avoid fragmentation
55
55
  formatsAndSegments.forEach(function (_a) {
56
56
  var _b = (0, tslib_1.__read)(_a, 3), _ = _b[0], __ = _b[1], paragraph = _b[2];
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IAsBA;;;;;;;;OAQG;IACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;QAEnE,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;YACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;gBAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;YAE3E,0DAA0D;YAC1D,IAAI,oBAAoB,EAAE;gBACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;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S,iBAAiB,CACtB,MAAe,EACf,kBAAiF;QAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;gBAArB,KAAA,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;YAC5C,IAAM,aAAa,GAAG,IAAA,2DAA4B,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YACnE,IAAM,iBAAiB,GAAG,IAAA,qDAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;YAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC","sourcesContent":["import {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\nimport { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";;;;IAuBA;;;;;;;;OAQG;IACH,SAAgB,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAIS;QAET,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;YACX,IAAI,oBAAoB,GAAG,IAAA,8DAAgC,EACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;YACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;gBAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;YAE3E,0DAA0D;YAC1D,IAAI,oBAAoB,EAAE;gBACtB,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;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,o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YAEzF,IAAA,+CAAiB,EAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;QACpF,CAAC,CAAC,CAAC;IACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormatContentModelContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (\n model: ReadonlyContentModelDocument,\n isTurningOff: boolean,\n context: FormatContentModelContext\n ) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model, isTurningOff, context);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle bold style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleBold(editor: IEditor): void;
6
+ export declare function toggleBold(editor: IEditor, options?: AnnouncingOption): void;
@@ -4,7 +4,7 @@ import { isBold } from 'roosterjs-content-model-dom';
4
4
  * Toggle bold style
5
5
  * @param editor The editor to operate on
6
6
  */
7
- export function toggleBold(editor) {
7
+ export function toggleBold(editor, options) {
8
8
  editor.focus();
9
9
  formatSegmentWithContentModel(editor, 'toggleBold', function (format, isTurningOn) {
10
10
  format.fontWeight = isTurningOn ? 'bold' : 'normal';
@@ -13,6 +13,12 @@ export function toggleBold(editor) {
13
13
  return isBold(typeof format.fontWeight == 'undefined'
14
14
  ? (_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.decorator) === null || _a === void 0 ? void 0 : _a.format.fontWeight
15
15
  : format.fontWeight);
16
+ }, undefined /* includeFormatHolder */, function (_model, isTurningOff, context) {
17
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
18
+ context.announceData = {
19
+ defaultStrings: isTurningOff ? 'announceBoldOff' : 'announceBoldOn',
20
+ };
21
+ }
16
22
  });
17
23
  }
18
24
  //# sourceMappingURL=toggleBold.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toggleBold.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleBold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAGrD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAe;IACtC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CACzB,MAAM,EACN,YAAY,EACZ,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxD,CAAC,EACD,UAAC,MAAM,EAAE,CAAC,EAAE,SAAS;;QACjB,OAAA,MAAM,CACF,OAAO,MAAM,CAAC,UAAU,IAAI,WAAW;YACnC,CAAC,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,0CAAE,MAAM,CAAC,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAA;KAAA,CACR,CAAC;AACN,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport { isBold } from 'roosterjs-content-model-dom';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle bold style\n * @param editor The editor to operate on\n */\nexport function toggleBold(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleBold',\n (format, isTurningOn) => {\n format.fontWeight = isTurningOn ? 'bold' : 'normal';\n },\n (format, _, paragraph) =>\n isBold(\n typeof format.fontWeight == 'undefined'\n ? paragraph?.decorator?.format.fontWeight\n : format.fontWeight\n )\n );\n}\n"]}
1
+ {"version":3,"file":"toggleBold.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleBold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAGrD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAe,EAAE,OAA0B;IAClE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CACzB,MAAM,EACN,YAAY,EACZ,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;IACxD,CAAC,EACD,UAAC,MAAM,EAAE,CAAC,EAAE,SAAS;;QACjB,OAAA,MAAM,CACF,OAAO,MAAM,CAAC,UAAU,IAAI,WAAW;YACnC,CAAC,CAAC,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,SAAS,0CAAE,MAAM,CAAC,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,UAAU,CAC1B,CAAA;KAAA,EACL,SAAS,CAAC,yBAAyB,EACnC,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;QAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;YAC/B,OAAO,CAAC,YAAY,GAAG;gBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB;aACtE,CAAC;SACL;IACL,CAAC,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport { isBold } from 'roosterjs-content-model-dom';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle bold style\n * @param editor The editor to operate on\n */\nexport function toggleBold(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleBold',\n (format, isTurningOn) => {\n format.fontWeight = isTurningOn ? 'bold' : 'normal';\n },\n (format, _, paragraph) =>\n isBold(\n typeof format.fontWeight == 'undefined'\n ? paragraph?.decorator?.format.fontWeight\n : format.fontWeight\n ),\n undefined /* includeFormatHolder */,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceBoldOff' : 'announceBoldOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle italic style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleItalic(editor: IEditor): void;
6
+ export declare function toggleItalic(editor: IEditor, options?: AnnouncingOption): void;
@@ -3,10 +3,16 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContent
3
3
  * Toggle italic style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export function toggleItalic(editor) {
6
+ export function toggleItalic(editor, options) {
7
7
  editor.focus();
8
8
  formatSegmentWithContentModel(editor, 'toggleItalic', function (format, isTurningOn) {
9
9
  format.italic = !!isTurningOn;
10
- }, function (format) { return !!format.italic; });
10
+ }, function (format) { return !!format.italic; }, undefined /* includingFormatHolder */, function (_model, isTurningOff, context) {
11
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
12
+ context.announceData = {
13
+ defaultStrings: isTurningOff ? 'announceItalicOff' : 'announceItalicOn',
14
+ };
15
+ }
16
+ });
11
17
  }
12
18
  //# sourceMappingURL=toggleItalic.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toggleItalic.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleItalic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAGvF;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAe;IACxC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CACzB,MAAM,EACN,cAAc,EACd,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;IAClC,CAAC,EACD,UAAA,MAAM,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,CAC5B,CAAC;AACN,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle italic style\n * @param editor The editor to operate on\n */\nexport function toggleItalic(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleItalic',\n (format, isTurningOn) => {\n format.italic = !!isTurningOn;\n },\n format => !!format.italic\n );\n}\n"]}
1
+ {"version":3,"file":"toggleItalic.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleItalic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAGvF;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,MAAe,EAAE,OAA0B;IACpE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CACzB,MAAM,EACN,cAAc,EACd,UAAC,MAAM,EAAE,WAAW;QAChB,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC;IAClC,CAAC,EACD,UAAA,MAAM,IAAI,OAAA,CAAC,CAAC,MAAM,CAAC,MAAM,EAAf,CAAe,EACzB,SAAS,CAAC,2BAA2B,EACrC,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;QAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;YAC/B,OAAO,CAAC,YAAY,GAAG;gBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,kBAAkB;aAC1E,CAAC;SACL;IACL,CAAC,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle italic style\n * @param editor The editor to operate on\n */\nexport function toggleItalic(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleItalic',\n (format, isTurningOn) => {\n format.italic = !!isTurningOn;\n },\n format => !!format.italic,\n undefined /* includingFormatHolder */,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceItalicOff' : 'announceItalicOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { IEditor } from 'roosterjs-content-model-types';
1
+ import type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Toggle underline style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export declare function toggleUnderline(editor: IEditor): void;
6
+ export declare function toggleUnderline(editor: IEditor, options?: AnnouncingOption): void;
@@ -3,13 +3,19 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContent
3
3
  * Toggle underline style
4
4
  * @param editor The editor to operate on
5
5
  */
6
- export function toggleUnderline(editor) {
6
+ export function toggleUnderline(editor, options) {
7
7
  editor.focus();
8
8
  formatSegmentWithContentModel(editor, 'toggleUnderline', function (format, isTurningOn, segment) {
9
9
  format.underline = !!isTurningOn;
10
10
  if (segment === null || segment === void 0 ? void 0 : segment.link) {
11
11
  segment.link.format.underline = !!isTurningOn;
12
12
  }
13
- }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/);
13
+ }, function (format, segment) { var _a, _b; return !!format.underline || !!((_b = (_a = segment === null || segment === void 0 ? void 0 : segment.link) === null || _a === void 0 ? void 0 : _a.format) === null || _b === void 0 ? void 0 : _b.underline); }, false /*includingFormatHolder*/, function (_model, isTurningOff, context) {
14
+ if (options === null || options === void 0 ? void 0 : options.announceFormatChange) {
15
+ context.announceData = {
16
+ defaultStrings: isTurningOff ? 'announceUnderlineOff' : 'announceUnderlineOn',
17
+ };
18
+ }
19
+ });
14
20
  }
15
21
  //# sourceMappingURL=toggleUnderline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAGvF;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAe;IAC3C,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;QACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;SACjD;IACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,CAClC,CAAC;AACN,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport function toggleUnderline(editor: IEditor) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/\n );\n}\n"]}
1
+ {"version":3,"file":"toggleUnderline.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/segment/toggleUnderline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAGvF;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,MAAe,EAAE,OAA0B;IACvE,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,6BAA6B,CACzB,MAAM,EACN,iBAAiB,EACjB,UAAC,MAAM,EAAE,WAAW,EAAE,OAAO;QACzB,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;QAEjC,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACf,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC,WAAW,CAAC;SACjD;IACL,CAAC,EACD,UAAC,MAAM,EAAE,OAAO,gBAAK,OAAA,CAAC,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC,CAAA,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,0CAAE,SAAS,CAAA,CAAA,EAAA,EAC7E,KAAK,CAAC,yBAAyB,EAC/B,UAAC,MAAM,EAAE,YAAY,EAAE,OAAO;QAC1B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,oBAAoB,EAAE;YAC/B,OAAO,CAAC,YAAY,GAAG;gBACnB,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,qBAAqB;aAChF,CAAC;SACL;IACL,CAAC,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel';\nimport type { AnnouncingOption, IEditor } from 'roosterjs-content-model-types';\n\n/**\n * Toggle underline style\n * @param editor The editor to operate on\n */\nexport function toggleUnderline(editor: IEditor, options?: AnnouncingOption) {\n editor.focus();\n\n formatSegmentWithContentModel(\n editor,\n 'toggleUnderline',\n (format, isTurningOn, segment) => {\n format.underline = !!isTurningOn;\n\n if (segment?.link) {\n segment.link.format.underline = !!isTurningOn;\n }\n },\n (format, segment) => !!format.underline || !!segment?.link?.format?.underline,\n false /*includingFormatHolder*/,\n (_model, isTurningOff, context) => {\n if (options?.announceFormatChange) {\n context.announceData = {\n defaultStrings: isTurningOff ? 'announceUnderlineOff' : 'announceUnderlineOn',\n };\n }\n }\n );\n}\n"]}
@@ -1,11 +1,11 @@
1
- import type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
1
+ import type { ContentModelTableFormat, IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Insert table into editor at current selection
4
4
  * @param editor The editor instance
5
5
  * @param columns Number of columns in table, it also controls the default table cell width:
6
6
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
7
7
  * @param rows Number of rows in table
8
- * @param format (Optional) The table format. If not passed, the default format will be applied:
9
- * background color: #FFF; border color: #ABABAB
8
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
9
+ * @param format (Optional) The table format used for style attributes
10
10
  */
11
- export declare function insertTable(editor: IEditor, columns: number, rows: number, format?: Partial<TableMetadataFormat>): void;
11
+ export declare function insertTable(editor: IEditor, columns: number, rows: number, tableMetadataFormat?: Partial<TableMetadataFormat>, format?: ContentModelTableFormat): void;
@@ -1,3 +1,4 @@
1
+ import { __assign } from "tslib";
1
2
  import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';
2
3
  import { createTableStructure } from '../../modelApi/table/createTableStructure';
3
4
  import { createContentModelDocument, createSelectionMarker, applyTableFormat, deleteSelection, mergeModel, normalizeTable, setSelection, } from 'roosterjs-content-model-dom';
@@ -7,10 +8,10 @@ import { createContentModelDocument, createSelectionMarker, applyTableFormat, de
7
8
  * @param columns Number of columns in table, it also controls the default table cell width:
8
9
  * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px
9
10
  * @param rows Number of rows in table
10
- * @param format (Optional) The table format. If not passed, the default format will be applied:
11
- * background color: #FFF; border color: #ABABAB
11
+ * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB
12
+ * @param format (Optional) The table format used for style attributes
12
13
  */
13
- export function insertTable(editor, columns, rows, format) {
14
+ export function insertTable(editor, columns, rows, tableMetadataFormat, format) {
14
15
  editor.focus();
15
16
  editor.formatContentModel(function (model, context) {
16
17
  var _a, _b, _c;
@@ -18,11 +19,14 @@ export function insertTable(editor, columns, rows, format) {
18
19
  if (insertPosition) {
19
20
  var doc = createContentModelDocument();
20
21
  var table = createTableStructure(doc, columns, rows);
22
+ if (format) {
23
+ table.format = __assign({}, format);
24
+ }
21
25
  normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);
22
26
  adjustTableIndentation(insertPosition, table);
23
27
  // Assign default vertical align
24
- format = format || { verticalAlign: 'top' };
25
- applyTableFormat(table, format);
28
+ tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };
29
+ applyTableFormat(table, tableMetadataFormat);
26
30
  mergeModel(model, doc, context, {
27
31
  insertPosition: insertPosition,
28
32
  mergeFormat: 'mergeAll',
@@ -1 +1 @@
1
- {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACH,0BAA0B,EAC1B,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,GACf,MAAM,6BAA6B,CAAC;AAGrC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,MAAqC;IAErC,MAAM,CAAC,KAAK,EAAE,CAAC;IAEf,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;QACX,IAAM,cAAc,GAAG,eAAe,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,WAAW,CAAC;QAEvE,IAAI,cAAc,EAAE;YAChB,IAAM,GAAG,GAAG,0BAA0B,EAAE,CAAC;YACzC,IAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAEvD,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,gBAAgB,EAAE,IAAI,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAEjF,sBAAsB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YAE9C,gCAAgC;YAChC,MAAM,GAAG,MAAM,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;YAC5C,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAChC,UAAU,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE;gBAC5B,cAAc,gBAAA;gBACd,WAAW,EAAE,UAAU;aAC1B,CAAC,CAAC;YAEH,IAAM,UAAU,GAAG,MAAA,MAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC,CAAC,CAAC;YAEtD,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,SAAS,KAAI,WAAW,EAAE;gBACtC,IAAM,MAAM,GAAG,qBAAqB,CAAC,MAAA,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,0CAAE,MAAM,CAAC,CAAC;gBACrE,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type { IEditor, TableMetadataFormat } from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param format (Optional) The table format. If not passed, the default format will be applied:\n * background color: #FFF; border color: #ABABAB\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n format?: Partial<TableMetadataFormat>\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n format = format || { verticalAlign: 'top' };\n applyTableFormat(table, format);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
1
+ {"version":3,"file":"insertTable.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/table/insertTable.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACH,0BAA0B,EAC1B,qBAAqB,EACrB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,GACf,MAAM,6BAA6B,CAAC;AAOrC;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CACvB,MAAe,EACf,OAAe,EACf,IAAY,EACZ,mBAAkD,EAClD,MAAgC;IAEhC,MAAM,CAA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AAE,MAAM,CAAC,CAAC;aAC/B;YAED,OAAO,IAAI,CAAC;SACf;aAAM;YACH,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,EACD;QACI,OAAO,EAAE,aAAa;KACzB,CACJ,CAAC;AACN,CAAC","sourcesContent":["import { adjustTableIndentation } from '../../modelApi/common/adjustIndentation';\nimport { createTableStructure } from '../../modelApi/table/createTableStructure';\nimport {\n createContentModelDocument,\n createSelectionMarker,\n applyTableFormat,\n deleteSelection,\n mergeModel,\n normalizeTable,\n setSelection,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelTableFormat,\n IEditor,\n TableMetadataFormat,\n} from 'roosterjs-content-model-types';\n\n/**\n * Insert table into editor at current selection\n * @param editor The editor instance\n * @param columns Number of columns in table, it also controls the default table cell width:\n * if columns &lt;= 4, width = 120px; if columns &lt;= 6, width = 100px; else width = 70px\n * @param rows Number of rows in table\n * @param tableMetadataFormat (Optional) The table format that are stored as metadata. If not passed, the default format will be applied: background color: #FFF; border color: #ABABAB\n * @param format (Optional) The table format used for style attributes\n */\nexport function insertTable(\n editor: IEditor,\n columns: number,\n rows: number,\n tableMetadataFormat?: Partial<TableMetadataFormat>,\n format?: ContentModelTableFormat\n) {\n editor.focus();\n\n editor.formatContentModel(\n (model, context) => {\n const insertPosition = deleteSelection(model, [], context).insertPoint;\n\n if (insertPosition) {\n const doc = createContentModelDocument();\n const table = createTableStructure(doc, columns, rows);\n if (format) {\n table.format = { ...format };\n }\n\n normalizeTable(table, editor.getPendingFormat() || insertPosition.marker.format);\n\n adjustTableIndentation(insertPosition, table);\n\n // Assign default vertical align\n tableMetadataFormat = tableMetadataFormat || { verticalAlign: 'top' };\n applyTableFormat(table, tableMetadataFormat);\n mergeModel(model, doc, context, {\n insertPosition,\n mergeFormat: 'mergeAll',\n });\n\n const firstBlock = table.rows[0]?.cells[0]?.blocks[0];\n\n if (firstBlock?.blockType == 'Paragraph') {\n const marker = createSelectionMarker(firstBlock.segments[0]?.format);\n firstBlock.segments.unshift(marker);\n setSelection(model, marker);\n }\n\n return true;\n } else {\n return false;\n }\n },\n {\n apiName: 'insertTable',\n }\n );\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ContentModelSegmentFormat, IEditor, ReadonlyContentModelDocument, ShallowMutableContentModelParagraph, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
1
+ import type { ContentModelSegmentFormat, FormatContentModelContext, IEditor, ReadonlyContentModelDocument, ShallowMutableContentModelParagraph, ShallowMutableContentModelSegment } from 'roosterjs-content-model-types';
2
2
  /**
3
3
  * Invoke a callback to format the selected segment using Content Model
4
4
  * @param editor The editor object
@@ -8,4 +8,4 @@ import type { ContentModelSegmentFormat, IEditor, ReadonlyContentModelDocument,
8
8
  * @param includingFormatHolder True to also include format holder of list item when search selected segments
9
9
  * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree
10
10
  */
11
- export declare function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument) => void): void;
11
+ export declare function formatSegmentWithContentModel(editor: IEditor, apiName: string, toggleStyleCallback: (format: ContentModelSegmentFormat, isTuringOn: boolean, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => void, segmentHasStyleCallback?: (format: ContentModelSegmentFormat, segment: ShallowMutableContentModelSegment | null, paragraph: ShallowMutableContentModelParagraph | null) => boolean, includingFormatHolder?: boolean, afterFormatCallback?: (model: ReadonlyContentModelDocument, isTurningOff: boolean, context: FormatContentModelContext) => void): void;
@@ -1,7 +1,7 @@
1
1
  import { __read } from "tslib";
2
- import { contentModelToDom, createDomToModelContext, createModelToDomContext, domToContentModel, getSelectedSegmentsAndParagraphs, mergeTextSegments, } from 'roosterjs-content-model-dom';
3
2
  import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';
4
3
  import { createEditorContextForEntity } from './createEditorContextForEntity';
4
+ import { contentModelToDom, createDomToModelContext, createModelToDomContext, domToContentModel, getSelectedSegmentsAndParagraphs, mergeTextSegments, } from 'roosterjs-content-model-dom';
5
5
  /**
6
6
  * Invoke a callback to format the selected segment using Content Model
7
7
  * @param editor The editor object
@@ -50,7 +50,7 @@ export function formatSegmentWithContentModel(editor, apiName, toggleStyleCallba
50
50
  toggleStyleCallback(format, !isTurningOff, segment, paragraph);
51
51
  });
52
52
  // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back
53
- afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model);
53
+ afterFormatCallback === null || afterFormatCallback === void 0 ? void 0 : afterFormatCallback(model, isTurningOff, context);
54
54
  // 6. finally merge segments if possible, to avoid fragmentation
55
55
  formatsAndSegments.forEach(function (_a) {
56
56
  var _b = __read(_a, 3), _ = _b[0], __ = _b[1], paragraph = _b[2];
@@ -1 +1 @@
1
- {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EACH,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,gCAAgC,EAChC,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAYrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAAmE;IAEnE,MAAM,CAAC,kBAAkB,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,CAAC,UAAU,CAClB,CAAC;gBAEF,UAAU,CAAC,OAAO,CAAC,UAAA,IAAI;oBACnB,kBAAkB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChE,CAAC,CAAC,CAAC;gBAEH,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aAClD;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,aAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\nimport { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (model: ReadonlyContentModelDocument) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
1
+ {"version":3,"file":"formatSegmentWithContentModel.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-api/lib/publicApi/utils/formatSegmentWithContentModel.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,8CAA8C,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EACH,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,gCAAgC,EAChC,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAcrC;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CACzC,MAAe,EACf,OAAe,EACf,mBAKS,EACT,uBAIY,EACZ,qBAA+B,EAC/B,mBAIS;IAET,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,gCAAgC,CACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oB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AAC,CAAC,CAAC;gBAChE,CAAC,CAAC,CAAC;gBAEH,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;aAClD;QACL,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,aAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,4BAA4B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAEzF,iBAAiB,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,iBAAiB,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection';\nimport { createEditorContextForEntity } from './createEditorContextForEntity';\nimport {\n contentModelToDom,\n createDomToModelContext,\n createModelToDomContext,\n domToContentModel,\n getSelectedSegmentsAndParagraphs,\n mergeTextSegments,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelDocument,\n ContentModelEntity,\n ContentModelSegmentFormat,\n FormatContentModelContext,\n FormattableRoot,\n IEditor,\n PluginEventData,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n ShallowMutableContentModelSegment,\n} from 'roosterjs-content-model-types';\n\n/**\n * Invoke a callback to format the selected segment using Content Model\n * @param editor The editor object\n * @param apiName Name of API this calling this function. This is mostly for logging.\n * @param toggleStyleCallback The callback to format the segment. It will be called with current selected table. If no table is selected, it will not be called.\n * @param segmentHasStyleCallback The callback used for checking if the given segment already has required format\n * @param includingFormatHolder True to also include format holder of list item when search selected segments\n * @param afterFormatCallback A callback to invoke after format is applied to all selected segments and before the change is applied to DOM tree\n */\nexport function formatSegmentWithContentModel(\n editor: IEditor,\n apiName: string,\n toggleStyleCallback: (\n format: ContentModelSegmentFormat,\n isTuringOn: boolean,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => void,\n segmentHasStyleCallback?: (\n format: ContentModelSegmentFormat,\n segment: ShallowMutableContentModelSegment | null,\n paragraph: ShallowMutableContentModelParagraph | null\n ) => boolean,\n includingFormatHolder?: boolean,\n afterFormatCallback?: (\n model: ReadonlyContentModelDocument,\n isTurningOff: boolean,\n context: FormatContentModelContext\n ) => void\n) {\n editor.formatContentModel(\n (model, context) => {\n let segmentAndParagraphs = getSelectedSegmentsAndParagraphs(\n model,\n !!includingFormatHolder,\n true /*includingEntity*/,\n true /*mutate*/\n );\n let isCollapsedSelection =\n segmentAndParagraphs.length >= 1 &&\n segmentAndParagraphs.every(x => x[0].segmentType == 'SelectionMarker');\n\n // 1. adjust selection to a word if selection is collapsed\n if (isCollapsedSelection) {\n const para = segmentAndParagraphs[0][1];\n const path = segmentAndParagraphs[0][2];\n\n segmentAndParagraphs = adjustWordSelection(\n model,\n segmentAndParagraphs[0][0]\n ).map(x => [x, para, path]);\n\n if (segmentAndParagraphs.length > 1) {\n isCollapsedSelection = false;\n }\n }\n\n // 2. expand selection for entities if any\n const formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][] = [];\n const modelsFromEntities: [\n ContentModelEntity,\n FormattableRoot,\n ContentModelDocument\n ][] = [];\n\n segmentAndParagraphs.forEach(item => {\n if (item[0].segmentType == 'Entity') {\n expandEntitySelections(editor, item[0], formatsAndSegments, modelsFromEntities);\n } else {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n }\n });\n\n // 3. check if we should turn format on (when not all selection has the required format already)\n // or off (all selections already have the required format)\n const isTurningOff = segmentHasStyleCallback\n ? formatsAndSegments.every(([format, segment, paragraph]) =>\n segmentHasStyleCallback(format, segment, paragraph)\n )\n : false;\n\n // 4. invoke the callback function to apply the format\n formatsAndSegments.forEach(([format, segment, paragraph]) => {\n toggleStyleCallback(format, !isTurningOff, segment, paragraph);\n });\n\n // 5. after format is applied to all selections, invoke another callback to do some clean up before write the change back\n afterFormatCallback?.(model, isTurningOff, context);\n\n // 6. finally merge segments if possible, to avoid fragmentation\n formatsAndSegments.forEach(([_, __, paragraph]) => {\n if (paragraph) {\n mergeTextSegments(paragraph);\n }\n });\n\n // 7. Write back models that we got from entities (if any)\n writeBackEntities(editor, modelsFromEntities);\n\n // 8. if the selection is still collapsed, it means we didn't actually applied format, set a pending format so it can be applied when user type\n // otherwise, write back to editor\n if (isCollapsedSelection) {\n context.newPendingFormat = segmentAndParagraphs[0][0].format;\n editor.focus();\n return false;\n } else {\n return formatsAndSegments.length > 0;\n }\n },\n {\n apiName,\n }\n );\n}\n\nfunction expandEntitySelections(\n editor: IEditor,\n entity: ContentModelEntity,\n formatsAndSegments: [\n ContentModelSegmentFormat,\n ShallowMutableContentModelSegment | null,\n ShallowMutableContentModelParagraph | null\n ][],\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n const { id, entityType: type, isReadonly } = entity.entityFormat;\n\n if (id && type) {\n const formattableRoots: FormattableRoot[] = [];\n const entityOperationEventData: PluginEventData<'entityOperation'> = {\n entity: { id, type, isReadonly: !!isReadonly, wrapper: entity.wrapper },\n operation: 'beforeFormat',\n formattableRoots,\n };\n\n editor.triggerEvent('entityOperation', entityOperationEventData);\n\n formattableRoots.forEach(root => {\n if (entity.wrapper.contains(root.element)) {\n const editorContext = createEditorContextForEntity(editor, entity);\n const context = createDomToModelContext(editorContext, root.domToModelOptions);\n\n // Treat everything as selected since the parent entity is selected\n context.isInSelection = true;\n\n const model = domToContentModel(root.element, context);\n const selections = getSelectedSegmentsAndParagraphs(\n model,\n false /*includingFormatHolder*/,\n false /*includingEntity*/,\n true /*mutate*/\n );\n\n selections.forEach(item => {\n formatsAndSegments.push([item[0].format, item[0], item[1]]);\n });\n\n modelsFromEntities.push([entity, root, model]);\n }\n });\n }\n}\n\nfunction writeBackEntities(\n editor: IEditor,\n modelsFromEntities: [ContentModelEntity, FormattableRoot, ContentModelDocument][]\n) {\n modelsFromEntities.forEach(([entity, root, model]) => {\n const editorContext = createEditorContextForEntity(editor, entity);\n const modelToDomContext = createModelToDomContext(editorContext, root.modelToDomOptions);\n\n contentModelToDom(editor.getDocument(), root.element, model, modelToDomContext);\n });\n}\n"]}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "description": "Format API for roosterjs",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.1",
6
- "roosterjs-content-model-dom": "^9.40.0",
7
- "roosterjs-content-model-types": "^9.40.0"
6
+ "roosterjs-content-model-dom": "^9.42.0",
7
+ "roosterjs-content-model-types": "^9.42.0"
8
8
  },
9
- "version": "9.40.0",
9
+ "version": "9.42.0",
10
10
  "main": "./lib/index.js",
11
11
  "typings": "./lib/index.d.ts",
12
12
  "module": "./lib-mjs/index.js",