roosterjs-content-model-api 9.40.0 → 9.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/publicApi/segment/toggleBold.d.ts +2 -2
- package/lib/publicApi/segment/toggleBold.js +7 -1
- package/lib/publicApi/segment/toggleBold.js.map +1 -1
- package/lib/publicApi/segment/toggleItalic.d.ts +2 -2
- package/lib/publicApi/segment/toggleItalic.js +8 -2
- package/lib/publicApi/segment/toggleItalic.js.map +1 -1
- package/lib/publicApi/segment/toggleUnderline.d.ts +2 -2
- package/lib/publicApi/segment/toggleUnderline.js +8 -2
- package/lib/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib/publicApi/utils/formatSegmentWithContentModel.d.ts +2 -2
- package/lib/publicApi/utils/formatSegmentWithContentModel.js +2 -2
- package/lib/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-amd/publicApi/segment/toggleBold.d.ts +2 -2
- package/lib-amd/publicApi/segment/toggleBold.js +7 -1
- package/lib-amd/publicApi/segment/toggleBold.js.map +1 -1
- package/lib-amd/publicApi/segment/toggleItalic.d.ts +2 -2
- package/lib-amd/publicApi/segment/toggleItalic.js +8 -2
- package/lib-amd/publicApi/segment/toggleItalic.js.map +1 -1
- package/lib-amd/publicApi/segment/toggleUnderline.d.ts +2 -2
- package/lib-amd/publicApi/segment/toggleUnderline.js +8 -2
- package/lib-amd/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.d.ts +2 -2
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js +2 -2
- package/lib-amd/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- package/lib-mjs/publicApi/segment/toggleBold.d.ts +2 -2
- package/lib-mjs/publicApi/segment/toggleBold.js +7 -1
- package/lib-mjs/publicApi/segment/toggleBold.js.map +1 -1
- package/lib-mjs/publicApi/segment/toggleItalic.d.ts +2 -2
- package/lib-mjs/publicApi/segment/toggleItalic.js +8 -2
- package/lib-mjs/publicApi/segment/toggleItalic.js.map +1 -1
- package/lib-mjs/publicApi/segment/toggleUnderline.d.ts +2 -2
- package/lib-mjs/publicApi/segment/toggleUnderline.js +8 -2
- package/lib-mjs/publicApi/segment/toggleUnderline.js.map +1 -1
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.d.ts +2 -2
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js +2 -2
- package/lib-mjs/publicApi/utils/formatSegmentWithContentModel.js.map +1 -1
- 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;
|
|
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;
|
|
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;
|
|
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,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,EAC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,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,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,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,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AAED,SAAS,iBAAiB,CACtB,MAAe,EACf,kBAAiF;IAEjF,kBAAkB,CAAC,OAAO,CAAC,UAAC,EAAqB;YAArB,KAAA,0BAAqB,EAApB,MAAM,QAAA,EAAE,IAAI,QAAA,EAAE,KAAK,QAAA;QAC5C,IAAM,aAAa,GAAG,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 { 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;
|
|
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;
|
|
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;
|
|
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,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", "
|
|
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;gBACxC,IAAM,MAAI,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAExC,oBAAoB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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,oBAAoB,GAAG,KAAK,CAAC;iBAChC;aACJ;YAED,0CAA0C;YAC1C,IAAM,kBAAkB,GAIlB,EA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AAK,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;
|
|
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;
|
|
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;
|
|
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,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,CACrB,UAAC,KAAK,EAAE,OAAO;QACX,IAAI,oBAAoB,GAAG,gCAAgC,CACvD,KAAK,EACL,CAAC,CAAC,qBAAqB,EACvB,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,UAAU,CAClB,CAAC;QACF,IAAI,oBAAoB,GACpB,oBAAoB,CAAC,MAAM,IAAI,CAAC;YAChC,oBAAoB,CAAC,KAAK,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAArC,CAAqC,CAAC,CAAC;QAE3E,0DAA0D;QAC1D,IAAI,oBAAoB,EAAE;YACtB,IAAM,MAA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ACf,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,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,mBAAmB,CACtC,KAAK,EACL,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC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AC;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.
|
|
7
|
-
"roosterjs-content-model-types": "^9.
|
|
6
|
+
"roosterjs-content-model-dom": "^9.41.0",
|
|
7
|
+
"roosterjs-content-model-types": "^9.41.0"
|
|
8
8
|
},
|
|
9
|
-
"version": "9.
|
|
9
|
+
"version": "9.41.0",
|
|
10
10
|
"main": "./lib/index.js",
|
|
11
11
|
"typings": "./lib/index.d.ts",
|
|
12
12
|
"module": "./lib-mjs/index.js",
|