roosterjs-content-model-plugins 9.41.0 → 9.43.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/autoFormat/AutoFormatPlugin.js +9 -10
- package/lib/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib/edit/inputSteps/handleEnterOnList.js +0 -33
- package/lib/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib/paste/PastePlugin.js +8 -32
- package/lib/paste/PastePlugin.js.map +1 -1
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +7 -31
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib/paste/parsers/adjustPercentileLineHeightParser.d.ts +8 -0
- package/lib/paste/parsers/adjustPercentileLineHeightParser.js +26 -0
- package/lib/paste/parsers/adjustPercentileLineHeightParser.js.map +1 -0
- package/lib/paste/parsers/blockElementParser.d.ts +7 -0
- package/lib/paste/parsers/blockElementParser.js +15 -0
- package/lib/paste/parsers/blockElementParser.js.map +1 -0
- package/lib/paste/parsers/imageSizeParser.d.ts +6 -0
- package/lib/paste/parsers/imageSizeParser.js +24 -0
- package/lib/paste/parsers/imageSizeParser.js.map +1 -0
- package/lib/paste/parsers/listLevelParser.d.ts +10 -0
- package/lib/paste/parsers/listLevelParser.js +19 -0
- package/lib/paste/parsers/listLevelParser.js.map +1 -0
- package/lib/paste/parsers/tableBorderParser.d.ts +5 -0
- package/lib/paste/parsers/tableBorderParser.js +28 -0
- package/lib/paste/parsers/tableBorderParser.js.map +1 -0
- package/lib/paste/parsers/wordTableParser.d.ts +8 -0
- package/lib/paste/parsers/wordTableParser.js +20 -0
- package/lib/paste/parsers/wordTableParser.js.map +1 -0
- package/lib-amd/autoFormat/AutoFormatPlugin.js +9 -10
- package/lib-amd/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-amd/edit/inputSteps/handleEnterOnList.js +0 -33
- package/lib-amd/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-amd/paste/PastePlugin.js +5 -32
- package/lib-amd/paste/PastePlugin.js.map +1 -1
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +5 -32
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-amd/paste/parsers/adjustPercentileLineHeightParser.d.ts +8 -0
- package/lib-amd/paste/parsers/adjustPercentileLineHeightParser.js +28 -0
- package/lib-amd/paste/parsers/adjustPercentileLineHeightParser.js.map +1 -0
- package/lib-amd/paste/parsers/blockElementParser.d.ts +7 -0
- package/lib-amd/paste/parsers/blockElementParser.js +17 -0
- package/lib-amd/paste/parsers/blockElementParser.js.map +1 -0
- package/lib-amd/paste/parsers/imageSizeParser.d.ts +6 -0
- package/lib-amd/paste/parsers/imageSizeParser.js +25 -0
- package/lib-amd/paste/parsers/imageSizeParser.js.map +1 -0
- package/lib-amd/paste/parsers/listLevelParser.d.ts +10 -0
- package/lib-amd/paste/parsers/listLevelParser.js +21 -0
- package/lib-amd/paste/parsers/listLevelParser.js.map +1 -0
- package/lib-amd/paste/parsers/tableBorderParser.d.ts +5 -0
- package/lib-amd/paste/parsers/tableBorderParser.js +29 -0
- package/lib-amd/paste/parsers/tableBorderParser.js.map +1 -0
- package/lib-amd/paste/parsers/wordTableParser.d.ts +8 -0
- package/lib-amd/paste/parsers/wordTableParser.js +22 -0
- package/lib-amd/paste/parsers/wordTableParser.js.map +1 -0
- package/lib-mjs/autoFormat/AutoFormatPlugin.js +9 -10
- package/lib-mjs/autoFormat/AutoFormatPlugin.js.map +1 -1
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js +1 -34
- package/lib-mjs/edit/inputSteps/handleEnterOnList.js.map +1 -1
- package/lib-mjs/paste/PastePlugin.js +5 -29
- package/lib-mjs/paste/PastePlugin.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +3 -27
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-mjs/paste/parsers/adjustPercentileLineHeightParser.d.ts +8 -0
- package/lib-mjs/paste/parsers/adjustPercentileLineHeightParser.js +22 -0
- package/lib-mjs/paste/parsers/adjustPercentileLineHeightParser.js.map +1 -0
- package/lib-mjs/paste/parsers/blockElementParser.d.ts +7 -0
- package/lib-mjs/paste/parsers/blockElementParser.js +11 -0
- package/lib-mjs/paste/parsers/blockElementParser.js.map +1 -0
- package/lib-mjs/paste/parsers/imageSizeParser.d.ts +6 -0
- package/lib-mjs/paste/parsers/imageSizeParser.js +20 -0
- package/lib-mjs/paste/parsers/imageSizeParser.js.map +1 -0
- package/lib-mjs/paste/parsers/listLevelParser.d.ts +10 -0
- package/lib-mjs/paste/parsers/listLevelParser.js +15 -0
- package/lib-mjs/paste/parsers/listLevelParser.js.map +1 -0
- package/lib-mjs/paste/parsers/tableBorderParser.d.ts +5 -0
- package/lib-mjs/paste/parsers/tableBorderParser.js +24 -0
- package/lib-mjs/paste/parsers/tableBorderParser.js.map +1 -0
- package/lib-mjs/paste/parsers/wordTableParser.d.ts +8 -0
- package/lib-mjs/paste/parsers/wordTableParser.js +16 -0
- package/lib-mjs/paste/parsers/wordTableParser.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listLevelParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/listLevelParser.ts"],"names":[],"mappings":";;;AAMA;;;;;;;GAOG;AACI,IAAM,eAAe,GAAkD,UAC1E,MAAuC,EACvC,OAAoB,EACpB,QAA2B,EAC3B,YAAoD;IAEpD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,EAAE,EAAE;QACjC,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;KAC/C;IAED,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;AACpC,CAAC,CAAC;AAXW,QAAA,eAAe,mBAW1B","sourcesContent":["import type {\n ContentModelListItemLevelFormat,\n DomToModelContext,\n FormatParser,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Parser for processing list level formatting specific to Word Desktop\n * @param format The list item level format to modify\n * @param element The HTML element being processed\n * @param _context The DOM to model context\n * @param defaultStyle The default style properties\n */\nexport const listLevelParser: FormatParser<ContentModelListItemLevelFormat> = (\n format: ContentModelListItemLevelFormat,\n element: HTMLElement,\n _context: DomToModelContext,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>\n) => {\n if (element.style.marginLeft !== '') {\n format.marginLeft = defaultStyle.marginLeft;\n }\n\n format.marginBottom = undefined;\n};\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tableBorderParser = void 0;
|
|
4
|
+
var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
5
|
+
var ElementBorderKeys = new Map([
|
|
6
|
+
['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],
|
|
7
|
+
['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],
|
|
8
|
+
['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],
|
|
9
|
+
['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
var tableBorderParser = function (format, element) {
|
|
15
|
+
roosterjs_content_model_dom_1.BorderKeys.forEach(function (key) {
|
|
16
|
+
if (!format[key]) {
|
|
17
|
+
var styleSet = ElementBorderKeys.get(key);
|
|
18
|
+
if (styleSet &&
|
|
19
|
+
element.style[styleSet.w] &&
|
|
20
|
+
element.style[styleSet.s] &&
|
|
21
|
+
!element.style[styleSet.c]) {
|
|
22
|
+
format[key] = element.style[styleSet.w] + " " + element.style[styleSet.s];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
exports.tableBorderParser = tableBorderParser;
|
|
28
|
+
//# sourceMappingURL=tableBorderParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableBorderParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/tableBorderParser.ts"],"names":[],"mappings":";;;AAAA,2EAAyD;AAOzD,IAAM,iBAAiB,GAAG,IAAI,GAAG,CAO/B;IACE,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChF,CAAC,aAAa,EAAE,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACxF,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC5F,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACvF,CAAC,CAAC;AAEH;;GAEG;AACI,IAAM,iBAAiB,GAA8C,UAAC,MAAM,EAAE,OAAO;IACxF,wCAAU,CAAC,OAAO,CAAC,UAAA,GAAG;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACd,IAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAE5C,IACI,QAAQ;gBACR,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC5B;gBACE,MAAM,CAAC,GAAG,CAAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;aAC7E;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B","sourcesContent":["import { BorderKeys } from 'roosterjs-content-model-dom';\nimport type {\n BorderFormat,\n ContentModelTableCellFormat,\n FormatParser,\n} from 'roosterjs-content-model-types';\n\nconst ElementBorderKeys = new Map<\n keyof BorderFormat,\n {\n c: keyof CSSStyleDeclaration;\n s: keyof CSSStyleDeclaration;\n w: keyof CSSStyleDeclaration;\n }\n>([\n ['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],\n ['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],\n ['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],\n ['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],\n]);\n\n/**\n * @internal\n */\nexport const tableBorderParser: FormatParser<ContentModelTableCellFormat> = (format, element) => {\n BorderKeys.forEach(key => {\n if (!format[key]) {\n const styleSet = ElementBorderKeys.get(key);\n\n if (\n styleSet &&\n element.style[styleSet.w] &&\n element.style[styleSet.s] &&\n !element.style[styleSet.c]\n ) {\n format[key] = `${element.style[styleSet.w]} ${element.style[styleSet.s]}`;\n }\n }\n });\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContentModelTableFormat, FormatParser } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Parser for processing table formatting specific to Word Desktop
|
|
5
|
+
* @param format The table format to modify
|
|
6
|
+
* @param element The HTML element being processed
|
|
7
|
+
*/
|
|
8
|
+
export declare const wordTableParser: FormatParser<ContentModelTableFormat>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wordTableParser = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* Parser for processing table formatting specific to Word Desktop
|
|
7
|
+
* @param format The table format to modify
|
|
8
|
+
* @param element The HTML element being processed
|
|
9
|
+
*/
|
|
10
|
+
var wordTableParser = function (format, element) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((_a = format.marginLeft) === null || _a === void 0 ? void 0 : _a.startsWith('-')) {
|
|
13
|
+
delete format.marginLeft;
|
|
14
|
+
}
|
|
15
|
+
if (format.htmlAlign) {
|
|
16
|
+
delete format.htmlAlign;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
exports.wordTableParser = wordTableParser;
|
|
20
|
+
//# sourceMappingURL=wordTableParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wordTableParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/wordTableParser.ts"],"names":[],"mappings":";;;AAEA;;;;;GAKG;AACI,IAAM,eAAe,GAA0C,UAAC,MAAM,EAAE,OAAO;;IAClF,IAAI,MAAA,MAAM,CAAC,UAAU,0CAAE,UAAU,CAAC,GAAG,CAAC,EAAE;QACpC,OAAO,MAAM,CAAC,UAAU,CAAC;KAC5B;IACD,IAAI,MAAM,CAAC,SAAS,EAAE;QAClB,OAAO,MAAM,CAAC,SAAS,CAAC;KAC3B;AACL,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B","sourcesContent":["import type { ContentModelTableFormat, FormatParser } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Parser for processing table formatting specific to Word Desktop\n * @param format The table format to modify\n * @param element The HTML element being processed\n */\nexport const wordTableParser: FormatParser<ContentModelTableFormat> = (format, element): void => {\n if (format.marginLeft?.startsWith('-')) {\n delete format.marginLeft;\n }\n if (format.htmlAlign) {\n delete format.htmlAlign;\n }\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "roosterjs-content-model-dom", "./horizontalLine/checkAndInsertHorizontalLine", "./link/createLink", "
|
|
1
|
+
define(["require", "exports", "tslib", "roosterjs-content-model-dom", "./horizontalLine/checkAndInsertHorizontalLine", "./link/createLink", "./list/getListTypeStyle", "./list/keyboardListTrigger", "./numbers/transformFraction", "./hyphen/transformHyphen", "./numbers/transformOrdinals", "./link/unlink", "roosterjs-content-model-api"], function (require, exports, tslib_1, roosterjs_content_model_dom_1, checkAndInsertHorizontalLine_1, createLink_1, getListTypeStyle_1, keyboardListTrigger_1, transformFraction_1, transformHyphen_1, transformOrdinals_1, unlink_1, roosterjs_content_model_api_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.AutoFormatPlugin = void 0;
|
|
@@ -131,7 +131,6 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "./horizon
|
|
|
131
131
|
this.editor = null;
|
|
132
132
|
};
|
|
133
133
|
AutoFormatPlugin.prototype.shouldHandleInputEventExclusively = function (editor, event) {
|
|
134
|
-
var _this = this;
|
|
135
134
|
var rawEvent = event.rawEvent;
|
|
136
135
|
var selection = editor.getDOMSelection();
|
|
137
136
|
var shouldHandle = false;
|
|
@@ -140,15 +139,15 @@ define(["require", "exports", "tslib", "roosterjs-content-model-dom", "./horizon
|
|
|
140
139
|
selection.type === 'range' &&
|
|
141
140
|
selection.range.collapsed &&
|
|
142
141
|
rawEvent.data == ' ') {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var list = (0, getListTypeStyle_1.getListTypeStyle)(model,
|
|
146
|
-
var
|
|
147
|
-
autoLink:
|
|
148
|
-
autoTel:
|
|
149
|
-
autoMailto:
|
|
142
|
+
var _a = this.options, autoLink_1 = _a.autoLink, autoTel_1 = _a.autoTel, autoMailto_1 = _a.autoMailto, autoBullet_1 = _a.autoBullet, autoNumbering_1 = _a.autoNumbering;
|
|
143
|
+
(0, roosterjs_content_model_api_1.formatTextSegmentBeforeSelectionMarker)(editor, function (model, previousSegment, _paragraph, _markerFormat) {
|
|
144
|
+
var list = (0, getListTypeStyle_1.getListTypeStyle)(model, autoBullet_1, autoNumbering_1);
|
|
145
|
+
var promotedLink = (0, roosterjs_content_model_api_1.getPromoteLink)(previousSegment, {
|
|
146
|
+
autoLink: autoLink_1,
|
|
147
|
+
autoTel: autoTel_1,
|
|
148
|
+
autoMailto: autoMailto_1,
|
|
150
149
|
});
|
|
151
|
-
shouldHandle = !!
|
|
150
|
+
shouldHandle = !!promotedLink || !!list;
|
|
152
151
|
return false;
|
|
153
152
|
});
|
|
154
153
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;;IAwCA;;OAEG;IACH,IAAM,cAAc,GAA+B;QAC/C,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;QACnB,iBAAiB,EAAE,KAAK;QACxB,kBAAkB,EAAE,KAAK;KAC5B,CAAC;IAEF;;;OAGG;IACH;QAEI;;;;;;;;;;;;;WAaG;QACH,0BAAoB,OAA2C;YAA/D,iBAAmE;YAA/C,wBAAA,EAAA,wBAA2C;YAA3C,YAAO,GAAP,OAAO,CAAoC;YAfvD,WAAM,GAAmB,IAAI,CAAC;YAqG9B,aAAQ,GAAY;gBACxB,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,I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,WAAW,GAAG,IAAI,CAAC;QAC1B,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { checkAndInsertHorizontalLine } from './horizontalLine/checkAndInsertHorizontalLine';\nimport { createLink } from './link/createLink';\nimport { formatTextSegmentBeforeSelectionMarker, promoteLink } from 'roosterjs-content-model-api';\nimport { getListTypeStyle } from './list/getListTypeStyle';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformFraction } from './numbers/transformFraction';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { transformOrdinals } from './numbers/transformOrdinals';\nimport { unlink } from './link/unlink';\nimport type { AutoFormatOptions } from './interface/AutoFormatOptions';\nimport type {\n ContentChangedEvent,\n ContentModelText,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\ninterface Feature {\n enabled: boolean;\n transformFunction: (\n model: ReadonlyContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n ) => boolean | HTMLElement;\n changeSource: string;\n apiName: string;\n}\n\n/**\n * @internal\n */\nconst DefaultOptions: Partial<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n autoFraction: false,\n autoOrdinals: false,\n removeListMargins: false,\n autoHorizontalLine: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - removeListMargins: A boolean to remove list margins when it is automatically triggered. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.\n * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink url address creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.\n * - autoMailto: A boolean that enables or disables automatic hyperlink email address transformation. Defaults to false.\n * - autoHorizontalLine: A boolean that enables or disables automatic horizontal line creation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n private shouldHandleInputEventExclusively(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n let shouldHandle = false;\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed &&\n rawEvent.data == ' '\n ) {\n formatTextSegmentBeforeSelectionMarker(editor, (model, previousSegment, paragraph) => {\n const { autoLink, autoTel, autoMailto, autoBullet, autoNumbering } = this.options;\n const list = getListTypeStyle(model, autoBullet, autoNumbering);\n const link = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n shouldHandle = !!link || !!list;\n return false;\n });\n }\n return shouldHandle;\n }\n\n willHandleEventExclusively(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'input':\n return this.shouldHandleInputEventExclusively(this.editor, event);\n }\n }\n return false;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private autoLink: Feature = {\n enabled: !!(this.options.autoLink || this.options.autoTel || this.options.autoMailto),\n transformFunction: (_model, previousSegment, paragraph, context) => {\n const { autoLink, autoTel, autoMailto } = this.options;\n const linkSegment = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n\n if (linkSegment) {\n return createAnchor(linkSegment.link?.format.href || '', linkSegment.text);\n }\n return false;\n },\n apiName: 'autoLink',\n changeSource: ChangeSource.AutoLink,\n };\n\n private tabFeatures: Feature[] = [\n {\n enabled: !!(this.options.autoBullet || this.options.autoNumbering),\n transformFunction: (model, _previousSegment, paragraph, context) =>\n keyboardListTrigger(\n model,\n paragraph,\n context,\n this.options.autoBullet,\n this.options.autoNumbering,\n this.options.removeListMargins\n ),\n apiName: 'autoToggleList',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private features: Feature[] = [\n ...this.tabFeatures,\n {\n enabled: !!this.options.autoHyphen,\n apiName: 'autoHyphen',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformHyphen(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoFraction,\n apiName: 'autoFraction',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformFraction(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoOrdinals,\n apiName: 'autoOrdinal',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformOrdinals(previousSegment, paragraph, context),\n },\n ];\n\n private enterFeatures: Feature[] = [\n {\n enabled: !!this.options.autoHorizontalLine,\n transformFunction: (model, _previousSegment, paragraph, context) =>\n checkAndInsertHorizontalLine(model, paragraph, context),\n apiName: 'autoHorizontalLine',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private handleKeyboardEvents(editor: IEditor, features: Feature[]): FormatContentModelOptions {\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n getChangeData: undefined,\n };\n\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n let featureApplied: Feature | undefined = undefined;\n for (const feature of features) {\n if (feature.enabled) {\n const result = feature.transformFunction(\n model,\n previousSegment,\n paragraph,\n context\n );\n if (result) {\n if (typeof result !== 'boolean') {\n formatOptions.getChangeData = () => result;\n }\n featureApplied = feature;\n break;\n }\n }\n }\n\n if (featureApplied) {\n formatOptions.changeSource = featureApplied.changeSource;\n formatOptions.apiName = featureApplied.apiName;\n }\n\n return !!featureApplied;\n },\n formatOptions\n );\n return formatOptions;\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n this.handleKeyboardEvents(editor, this.features);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n case 'Tab':\n if (!rawEvent.shiftKey) {\n const eventHandled = this.handleKeyboardEvents(editor, this.tabFeatures);\n if (eventHandled.apiName == 'autoToggleList') {\n event.rawEvent.preventDefault();\n }\n }\n break;\n case 'Enter':\n const eventHandled = this.handleKeyboardEvents(editor, this.enterFeatures);\n if (eventHandled.apiName == 'autoHorizontalLine') {\n event.rawEvent.preventDefault();\n }\n break;\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink, autoTel, autoMailto } = this.options;\n if (event.source == 'Paste' && (autoLink || autoTel || autoMailto)) {\n createLink(editor, {\n autoLink,\n autoTel,\n autoMailto,\n });\n }\n }\n}\n\nconst createAnchor = (url: string, text: string) => {\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.textContent = text;\n return anchor;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";;;;IA4CA;;OAEG;IACH,IAAM,cAAc,GAA+B;QAC/C,UAAU,EAAE,KAAK;QACjB,aAAa,EAAE,KAAK;QACpB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;QACnB,YAAY,EAAE,KAAK;QACnB,iBAAiB,EAAE,KAAK;QACxB,kBAAkB,EAAE,KAAK;KAC5B,CAAC;IAEF;;;OAGG;IACH;QAEI;;;;;;;;;;;;;WAaG;QACH,0BAAoB,OAA2C;YAA/D,iBAAmE;YAA/C,wBAAA,EAAA,wBAA2C;YAA3C,YAAO,GAAP,OAAO,CAAoC;YAfvD,WAAM,GAAmB,IAAI,CAAC;YA0G9B,aAAQ,GAAY;gBACxB,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO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B,OAAO,MAAM,CAAC;IAClB,CAAC,CAAC","sourcesContent":["import { ChangeSource } from 'roosterjs-content-model-dom';\nimport { checkAndInsertHorizontalLine } from './horizontalLine/checkAndInsertHorizontalLine';\nimport { createLink } from './link/createLink';\nimport { getListTypeStyle } from './list/getListTypeStyle';\nimport { keyboardListTrigger } from './list/keyboardListTrigger';\nimport { transformFraction } from './numbers/transformFraction';\nimport { transformHyphen } from './hyphen/transformHyphen';\nimport { transformOrdinals } from './numbers/transformOrdinals';\nimport { unlink } from './link/unlink';\nimport {\n formatTextSegmentBeforeSelectionMarker,\n promoteLink,\n getPromoteLink,\n} from 'roosterjs-content-model-api';\nimport type { AutoFormatOptions } from './interface/AutoFormatOptions';\nimport type {\n ContentChangedEvent,\n ContentModelText,\n EditorInputEvent,\n EditorPlugin,\n FormatContentModelContext,\n FormatContentModelOptions,\n IEditor,\n KeyDownEvent,\n PluginEvent,\n ReadonlyContentModelDocument,\n ShallowMutableContentModelParagraph,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\ninterface Feature {\n enabled: boolean;\n transformFunction: (\n model: ReadonlyContentModelDocument,\n previousSegment: ContentModelText,\n paragraph: ShallowMutableContentModelParagraph,\n context: FormatContentModelContext\n ) => boolean | HTMLElement;\n changeSource: string;\n apiName: string;\n}\n\n/**\n * @internal\n */\nconst DefaultOptions: Partial<AutoFormatOptions> = {\n autoBullet: false,\n autoNumbering: false,\n autoUnlink: false,\n autoLink: false,\n autoHyphen: false,\n autoFraction: false,\n autoOrdinals: false,\n removeListMargins: false,\n autoHorizontalLine: false,\n};\n\n/**\n * Auto Format plugin handles auto formatting, such as transforming * characters into a bullet list.\n * It can be customized with options to enable or disable auto list features.\n */\nexport class AutoFormatPlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n /**\n * @param options An optional parameter that takes in an object of type AutoFormatOptions, which includes the following properties:\n * - autoBullet: A boolean that enables or disables automatic bullet list formatting. Defaults to false.\n * - autoNumbering: A boolean that enables or disables automatic numbering formatting. Defaults to false.\n * - removeListMargins: A boolean to remove list margins when it is automatically triggered. Defaults to false.\n * - autoHyphen: A boolean that enables or disables automatic hyphen transformation. Defaults to false.\n * - autoFraction: A boolean that enables or disables automatic fraction transformation. Defaults to false.\n * - autoOrdinals: A boolean that enables or disables automatic ordinal number transformation. Defaults to false.\n * - autoLink: A boolean that enables or disables automatic hyperlink url address creation when pasting or typing content. Defaults to false.\n * - autoUnlink: A boolean that enables or disables automatic hyperlink removal when pressing backspace. Defaults to false.\n * - autoTel: A boolean that enables or disables automatic hyperlink telephone numbers transformation. Defaults to false.\n * - autoMailto: A boolean that enables or disables automatic hyperlink email address transformation. Defaults to false.\n * - autoHorizontalLine: A boolean that enables or disables automatic horizontal line creation. Defaults to false.\n */\n constructor(private options: AutoFormatOptions = DefaultOptions) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'AutoFormat';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n private shouldHandleInputEventExclusively(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n let shouldHandle = false;\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed &&\n rawEvent.data == ' '\n ) {\n const { autoLink, autoTel, autoMailto, autoBullet, autoNumbering } = this.options;\n\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, _paragraph, _markerFormat) => {\n const list = getListTypeStyle(model, autoBullet, autoNumbering);\n const promotedLink = getPromoteLink(previousSegment, {\n autoLink,\n autoTel,\n autoMailto,\n });\n shouldHandle = !!promotedLink || !!list;\n\n return false;\n }\n );\n }\n return shouldHandle;\n }\n\n willHandleEventExclusively(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'input':\n return this.shouldHandleInputEventExclusively(this.editor, event);\n }\n }\n return false;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (this.editor) {\n switch (event.eventType) {\n case 'input':\n this.handleEditorInputEvent(this.editor, event);\n break;\n case 'keyDown':\n this.handleKeyDownEvent(this.editor, event);\n break;\n case 'contentChanged':\n this.handleContentChangedEvent(this.editor, event);\n break;\n }\n }\n }\n\n private autoLink: Feature = {\n enabled: !!(this.options.autoLink || this.options.autoTel || this.options.autoMailto),\n transformFunction: (_model, previousSegment, paragraph, context) => {\n const { autoLink, autoTel, autoMailto } = this.options;\n const linkSegment = promoteLink(previousSegment, paragraph, {\n autoLink,\n autoTel,\n autoMailto,\n });\n\n if (linkSegment) {\n return createAnchor(linkSegment.link?.format.href || '', linkSegment.text);\n }\n return false;\n },\n apiName: 'autoLink',\n changeSource: ChangeSource.AutoLink,\n };\n\n private tabFeatures: Feature[] = [\n {\n enabled: !!(this.options.autoBullet || this.options.autoNumbering),\n transformFunction: (model, _previousSegment, paragraph, context) =>\n keyboardListTrigger(\n model,\n paragraph,\n context,\n this.options.autoBullet,\n this.options.autoNumbering,\n this.options.removeListMargins\n ),\n apiName: 'autoToggleList',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private features: Feature[] = [\n ...this.tabFeatures,\n {\n enabled: !!this.options.autoHyphen,\n apiName: 'autoHyphen',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformHyphen(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoFraction,\n apiName: 'autoFraction',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformFraction(previousSegment, paragraph, context),\n },\n {\n enabled: !!this.options.autoOrdinals,\n apiName: 'autoOrdinal',\n changeSource: ChangeSource.Format,\n transformFunction: (_model, previousSegment, paragraph, context) =>\n transformOrdinals(previousSegment, paragraph, context),\n },\n ];\n\n private enterFeatures: Feature[] = [\n {\n enabled: !!this.options.autoHorizontalLine,\n transformFunction: (model, _previousSegment, paragraph, context) =>\n checkAndInsertHorizontalLine(model, paragraph, context),\n apiName: 'autoHorizontalLine',\n changeSource: ChangeSource.AutoFormat,\n },\n this.autoLink,\n ];\n\n private handleKeyboardEvents(editor: IEditor, features: Feature[]): FormatContentModelOptions {\n const formatOptions: FormatContentModelOptions = {\n changeSource: '',\n apiName: '',\n getChangeData: undefined,\n };\n\n formatTextSegmentBeforeSelectionMarker(\n editor,\n (model, previousSegment, paragraph, _markerFormat, context) => {\n let featureApplied: Feature | undefined = undefined;\n for (const feature of features) {\n if (feature.enabled) {\n const result = feature.transformFunction(\n model,\n previousSegment,\n paragraph,\n context\n );\n\n if (result) {\n if (typeof result !== 'boolean') {\n formatOptions.getChangeData = () => result;\n }\n featureApplied = feature;\n break;\n }\n }\n }\n\n if (featureApplied) {\n formatOptions.changeSource = featureApplied.changeSource;\n formatOptions.apiName = featureApplied.apiName;\n }\n\n return !!featureApplied;\n },\n formatOptions\n );\n return formatOptions;\n }\n\n private handleEditorInputEvent(editor: IEditor, event: EditorInputEvent) {\n const rawEvent = event.rawEvent;\n const selection = editor.getDOMSelection();\n if (\n rawEvent.inputType === 'insertText' &&\n selection &&\n selection.type === 'range' &&\n selection.range.collapsed\n ) {\n switch (rawEvent.data) {\n case ' ':\n this.handleKeyboardEvents(editor, this.features);\n break;\n }\n }\n }\n\n private handleKeyDownEvent(editor: IEditor, event: KeyDownEvent) {\n const rawEvent = event.rawEvent;\n if (!rawEvent.defaultPrevented && !event.handledByEditFeature) {\n switch (rawEvent.key) {\n case 'Backspace':\n if (this.options.autoUnlink) {\n unlink(editor, rawEvent);\n }\n break;\n case 'Tab':\n if (!rawEvent.shiftKey) {\n const eventHandled = this.handleKeyboardEvents(editor, this.tabFeatures);\n if (eventHandled.apiName == 'autoToggleList') {\n event.rawEvent.preventDefault();\n }\n }\n break;\n case 'Enter':\n const eventHandled = this.handleKeyboardEvents(editor, this.enterFeatures);\n if (eventHandled.apiName == 'autoHorizontalLine') {\n event.rawEvent.preventDefault();\n }\n break;\n }\n }\n }\n\n private handleContentChangedEvent(editor: IEditor, event: ContentChangedEvent) {\n const { autoLink, autoTel, autoMailto } = this.options;\n if (event.source == 'Paste' && (autoLink || autoTel || autoMailto)) {\n createLink(editor, {\n autoLink,\n autoTel,\n autoMailto,\n });\n }\n }\n}\n\nconst createAnchor = (url: string, text: string) => {\n const anchor = document.createElement('a');\n anchor.href = url;\n anchor.textContent = text;\n return anchor;\n};\n"]}
|
|
@@ -25,24 +25,6 @@ define(["require", "exports", "tslib", "roosterjs-content-model-api", "../utils/
|
|
|
25
25
|
], (0, tslib_1.__read)(path.slice(index + 1)), false));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
var listIndex = listParent.blocks.indexOf(listItem);
|
|
29
|
-
var nextBlock = listParent.blocks[listIndex + 1];
|
|
30
|
-
if (nextBlock) {
|
|
31
|
-
if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(nextBlock, 'ListItem') &&
|
|
32
|
-
nextBlock.levels[0]) {
|
|
33
|
-
nextBlock.levels.forEach(function (level) {
|
|
34
|
-
// Remove startNumberOverride so that next list item can join current list, unless it is 1.
|
|
35
|
-
// List start with 1 means it should be an explicit new list and should never join another list before it
|
|
36
|
-
if (level.format.startNumberOverride !== 1) {
|
|
37
|
-
level.format.startNumberOverride = undefined;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
if (listItem.levels.length == 0) {
|
|
41
|
-
var nextBlockIndex = findIndex(listParent.blocks, nextBlock.levels.length);
|
|
42
|
-
nextBlock.levels[nextBlock.levels.length - 1].format.startNumberOverride = nextBlockIndex;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
28
|
context.deleteResult = 'range';
|
|
47
29
|
}
|
|
48
30
|
}
|
|
@@ -84,20 +66,5 @@ define(["require", "exports", "tslib", "roosterjs-content-model-api", "../utils/
|
|
|
84
66
|
return (0, roosterjs_content_model_dom_1.createListLevel)(level.listType, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, level.format), { startNumberOverride: undefined, displayForDummyItem: undefined }), level.dataset);
|
|
85
67
|
});
|
|
86
68
|
};
|
|
87
|
-
var findIndex = function (blocks, levelLength) {
|
|
88
|
-
var counter = 1;
|
|
89
|
-
for (var i = 0; i < blocks.length; i++) {
|
|
90
|
-
var listItem = blocks[i];
|
|
91
|
-
if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(listItem, 'ListItem') &&
|
|
92
|
-
listItem.levels.length === levelLength) {
|
|
93
|
-
counter++;
|
|
94
|
-
}
|
|
95
|
-
else if ((0, roosterjs_content_model_dom_1.isBlockGroupOfType)(listItem, 'ListItem') &&
|
|
96
|
-
listItem.levels.length == 0) {
|
|
97
|
-
return counter;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return counter;
|
|
101
|
-
};
|
|
102
69
|
});
|
|
103
70
|
//# sourceMappingURL=handleEnterOnList.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;IAsBA;;OAEG;IACI,IAAM,iBAAiB,GAAwB,UAAA,OAAO;QACjD,IAAA,YAAY,GAAkB,OAAO,aAAzB,EAAE,WAAW,GAAK,OAAO,YAAZ,CAAa;QAE9C,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,IAAI,iBAAiB,EAAE;YAC3D,IAAA,IAAI,GAAK,WAAW,KAAhB,CAAiB;YAC7B,IAAM,KAAK,GAAG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EP,KAAK,CAAC,MAAM,KACf,mBAAmB,EAAE,SAAS,EAC9B,mBAAmB,EAAE,SAAS,KAElC,KAAK,CAAC,OAAO,CAChB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,IAAM,SAAS,GAAG,UAAC,MAA4C,EAAE,WAAmB;QAChF,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACpC,IAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAE3B,IACI,IAAA,gDAAkB,EAAuB,QAAQ,EAAE,UAAU,CAAC;gBAC9D,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,EACxC;gBACE,OAAO,EAAE,CAAC;aACb;iBAAM,IACH,IAAA,gDAAkB,EAAuB,QAAQ,EAAE,UAAU,CAAC;gBAC9D,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,EAC7B;gBACE,OAAO,OAAO,CAAC;aAClB;SACJ;QAED,OAAO,OAAO,CAAC;IACnB,CAAC,CAAC","sourcesContent":["import { getListAnnounceData } from 'roosterjs-content-model-api';\nimport { splitParagraph } from '../utils/splitParagraph';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getClosestAncestorBlockGroupIndex,\n isBlockGroupOfType,\n ListFormats,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n ContentModelListItem,\n DeleteSelectionStep,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n ValidDeleteSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const handleEnterOnList: DeleteSelectionStep = context => {\n const { deleteResult, insertPoint } = context;\n\n if (deleteResult == 'notDeleted' || deleteResult == 'nothingToDelete') {\n const { path } = insertPoint;\n const index = getClosestAncestorBlockGroupIndex(\n path,\n ['ListItem'],\n ['TableCell', 'FormatContainer']\n );\n\n const readonlyListItem = path[index];\n const listParent = path[index + 1];\n\n if (readonlyListItem?.blockGroupType === 'ListItem' && listParent) {\n let listItem = mutateBlock(readonlyListItem);\n\n if (isEmptyListItem(listItem)) {\n listItem.levels.pop();\n } else {\n listItem = createNewListItem(context, listItem, listParent);\n\n if (context.formatContext) {\n context.formatContext.announceData = getListAnnounceData([\n listItem,\n ...path.slice(index + 1),\n ]);\n }\n }\n\n const listIndex = listParent.blocks.indexOf(listItem);\n const nextBlock = listParent.blocks[listIndex + 1];\n\n if (nextBlock) {\n if (\n isBlockGroupOfType<ContentModelListItem>(nextBlock, 'ListItem') &&\n nextBlock.levels[0]\n ) {\n nextBlock.levels.forEach(level => {\n // Remove startNumberOverride so that next list item can join current list, unless it is 1.\n // List start with 1 means it should be an explicit new list and should never join another list before it\n if (level.format.startNumberOverride !== 1) {\n level.format.startNumberOverride = undefined;\n }\n });\n\n if (listItem.levels.length == 0) {\n const nextBlockIndex = findIndex(\n listParent.blocks,\n nextBlock.levels.length\n );\n\n nextBlock.levels[\n nextBlock.levels.length - 1\n ].format.startNumberOverride = nextBlockIndex;\n }\n }\n }\n\n context.deleteResult = 'range';\n }\n }\n};\n\nconst isEmptyListItem = (listItem: ReadonlyContentModelListItem) => {\n return listItem.blocks.length === 1 && isEmptyParagraph(listItem.blocks[0]);\n};\n\nconst isEmptyParagraph = (block: ReadonlyContentModelBlock) => {\n return (\n block.blockType === 'Paragraph' &&\n block.segments.length === 2 &&\n block.segments[0].segmentType === 'SelectionMarker' &&\n block.segments[1].segmentType === 'Br'\n );\n};\n\nconst createNewListItem = (\n context: ValidDeleteSelectionContext,\n listItem: ReadonlyContentModelListItem,\n listParent: ReadonlyContentModelBlockGroup\n) => {\n const { insertPoint } = context;\n const listIndex = listParent.blocks.indexOf(listItem);\n const currentPara = insertPoint.paragraph;\n const paraIndex = listItem.blocks.indexOf(currentPara);\n const newParagraph = splitParagraph(insertPoint);\n\n const levels = createNewListLevel(listItem);\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n levels,\n listItem.formatHolder.format\n );\n\n newListItem.blocks.push(newParagraph);\n\n copyFormat<ContentModelBlockFormat>(newListItem.format, listItem.format, ListFormats);\n\n const remainingBlockCount = listItem.blocks.length - paraIndex - 1;\n\n if (paraIndex >= 0 && remainingBlockCount > 0) {\n newListItem.blocks.push(\n ...mutateBlock(listItem).blocks.splice(paraIndex + 1, remainingBlockCount)\n );\n }\n\n insertPoint.paragraph = newParagraph;\n mutateBlock(listParent).blocks.splice(listIndex + 1, 0, newListItem);\n\n if (context.lastParagraph == currentPara) {\n context.lastParagraph = newParagraph;\n }\n\n return newListItem;\n};\n\nconst createNewListLevel = (listItem: ReadonlyContentModelListItem) => {\n return listItem.levels.map(level => {\n return createListLevel(\n level.listType,\n {\n ...level.format,\n startNumberOverride: undefined,\n displayForDummyItem: undefined, // When ENTER, we should create a new regular list item, so force its dummy item display to undefined\n },\n level.dataset\n );\n });\n};\n\nconst findIndex = (blocks: readonly ReadonlyContentModelBlock[], levelLength: number) => {\n let counter = 1;\n for (let i = 0; i < blocks.length; i++) {\n const listItem = blocks[i];\n\n if (\n isBlockGroupOfType<ContentModelListItem>(listItem, 'ListItem') &&\n listItem.levels.length === levelLength\n ) {\n counter++;\n } else if (\n isBlockGroupOfType<ContentModelListItem>(listItem, 'ListItem') &&\n listItem.levels.length == 0\n ) {\n return counter;\n }\n }\n\n return counter;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"handleEnterOnList.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/edit/inputSteps/handleEnterOnList.ts"],"names":[],"mappings":";;;;IAoBA;;OAEG;IACI,IAAM,iBAAiB,GAAwB,UAAA,OAAO;QACjD,IAAA,YAAY,GAAkB,OAAO,aAAzB,EAAE,WAAW,GAAK,OAAO,YAAZ,CAAa;QAE9C,IAAI,YAAY,IAAI,YAAY,I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mBAAmB,CAAC,WAC5E;SACL;QAED,WAAW,CAAC,SAAS,GAAG,YAAY,CAAC;QACrC,IAAA,yCAAW,EAAC,UAAU,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,CAAC;QAErE,IAAI,OAAO,CAAC,aAAa,IAAI,WAAW,EAAE;YACtC,OAAO,CAAC,aAAa,GAAG,YAAY,CAAC;SACxC;QAED,OAAO,WAAW,CAAC;IACvB,CAAC,CAAC;IAEF,IAAM,kBAAkB,GAAG,UAAC,QAAsC;QAC9D,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,UAAA,KAAK;YAC5B,OAAO,IAAA,6CAAe,EAClB,KAAK,CAAC,QAAQ,kDAEP,KAAK,CAAC,MAAM,KACf,mBAAmB,EAAE,SAAS,EAC9B,mBAAmB,EAAE,SAAS,KAElC,KAAK,CAAC,OAAO,CAChB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC,CAAC","sourcesContent":["import { getListAnnounceData } from 'roosterjs-content-model-api';\nimport { splitParagraph } from '../utils/splitParagraph';\nimport {\n copyFormat,\n createListItem,\n createListLevel,\n getClosestAncestorBlockGroupIndex,\n ListFormats,\n mutateBlock,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockFormat,\n DeleteSelectionStep,\n ReadonlyContentModelBlock,\n ReadonlyContentModelBlockGroup,\n ReadonlyContentModelListItem,\n ShallowMutableContentModelListItem,\n ValidDeleteSelectionContext,\n} from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const handleEnterOnList: DeleteSelectionStep = context => {\n const { deleteResult, insertPoint } = context;\n\n if (deleteResult == 'notDeleted' || deleteResult == 'nothingToDelete') {\n const { path } = insertPoint;\n const index = getClosestAncestorBlockGroupIndex(\n path,\n ['ListItem'],\n ['TableCell', 'FormatContainer']\n );\n\n const readonlyListItem = path[index];\n const listParent = path[index + 1];\n\n if (readonlyListItem?.blockGroupType === 'ListItem' && listParent) {\n let listItem = mutateBlock(readonlyListItem);\n\n if (isEmptyListItem(listItem)) {\n listItem.levels.pop();\n } else {\n listItem = createNewListItem(context, listItem, listParent);\n\n if (context.formatContext) {\n context.formatContext.announceData = getListAnnounceData([\n listItem,\n ...path.slice(index + 1),\n ]);\n }\n }\n\n context.deleteResult = 'range';\n }\n }\n};\n\nconst isEmptyListItem = (listItem: ReadonlyContentModelListItem) => {\n return listItem.blocks.length === 1 && isEmptyParagraph(listItem.blocks[0]);\n};\n\nconst isEmptyParagraph = (block: ReadonlyContentModelBlock) => {\n return (\n block.blockType === 'Paragraph' &&\n block.segments.length === 2 &&\n block.segments[0].segmentType === 'SelectionMarker' &&\n block.segments[1].segmentType === 'Br'\n );\n};\n\nconst createNewListItem = (\n context: ValidDeleteSelectionContext,\n listItem: ReadonlyContentModelListItem,\n listParent: ReadonlyContentModelBlockGroup\n) => {\n const { insertPoint } = context;\n const listIndex = listParent.blocks.indexOf(listItem);\n const currentPara = insertPoint.paragraph;\n const paraIndex = listItem.blocks.indexOf(currentPara);\n const newParagraph = splitParagraph(insertPoint);\n\n const levels = createNewListLevel(listItem);\n const newListItem: ShallowMutableContentModelListItem = createListItem(\n levels,\n listItem.formatHolder.format\n );\n\n newListItem.blocks.push(newParagraph);\n\n copyFormat<ContentModelBlockFormat>(newListItem.format, listItem.format, ListFormats);\n\n const remainingBlockCount = listItem.blocks.length - paraIndex - 1;\n\n if (paraIndex >= 0 && remainingBlockCount > 0) {\n newListItem.blocks.push(\n ...mutateBlock(listItem).blocks.splice(paraIndex + 1, remainingBlockCount)\n );\n }\n\n insertPoint.paragraph = newParagraph;\n mutateBlock(listParent).blocks.splice(listIndex + 1, 0, newListItem);\n\n if (context.lastParagraph == currentPara) {\n context.lastParagraph = newParagraph;\n }\n\n return newListItem;\n};\n\nconst createNewListLevel = (listItem: ReadonlyContentModelListItem) => {\n return listItem.levels.map(level => {\n return createListLevel(\n level.listType,\n {\n ...level.format,\n startNumberOverride: undefined,\n displayForDummyItem: undefined, // When ENTER, we should create a new regular list item, so force its dummy item display to undefined\n },\n level.dataset\n );\n });\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
define(["require", "exports", "tslib", "./utils/addParser", "
|
|
1
|
+
define(["require", "exports", "tslib", "./utils/addParser", "./parsers/blockElementParser", "./utils/chainSanitizerCallback", "./DefaultSanitizers", "./parsers/deprecatedColorParser", "roosterjs-content-model-dom", "./pasteSourceValidations/getPasteSource", "./parsers/imageSizeParser", "./parsers/linkParser", "./processors/pasteButtonProcessor", "./pasteSourceValidations/constants", "./Excel/processPastedContentFromExcel", "./oneNote/processPastedContentFromOneNote", "./PowerPoint/processPastedContentFromPowerPoint", "./WordDesktop/processPastedContentFromWordDesktop", "./WacComponents/processPastedContentWacComponents", "./utils/setProcessor", "./parsers/tableBorderParser"], function (require, exports, tslib_1, addParser_1, blockElementParser_1, chainSanitizerCallback_1, DefaultSanitizers_1, deprecatedColorParser_1, roosterjs_content_model_dom_1, getPasteSource_1, imageSizeParser_1, linkParser_1, pasteButtonProcessor_1, constants_1, processPastedContentFromExcel_1, processPastedContentFromOneNote_1, processPastedContentFromPowerPoint_1, processPastedContentFromWordDesktop_1, processPastedContentWacComponents_1, setProcessor_1, tableBorderParser_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.PastePlugin = void 0;
|
|
@@ -91,12 +91,13 @@ define(["require", "exports", "tslib", "./utils/addParser", "roosterjs-content-m
|
|
|
91
91
|
}
|
|
92
92
|
(0, addParser_1.addParser)(event.domToModelOption, 'link', linkParser_1.parseLink);
|
|
93
93
|
(0, addParser_1.addParser)(event.domToModelOption, 'tableCell', deprecatedColorParser_1.deprecatedBorderColorParser);
|
|
94
|
-
(0, addParser_1.addParser)(event.domToModelOption, 'tableCell', tableBorderParser);
|
|
94
|
+
(0, addParser_1.addParser)(event.domToModelOption, 'tableCell', tableBorderParser_1.tableBorderParser);
|
|
95
95
|
(0, addParser_1.addParser)(event.domToModelOption, 'table', deprecatedColorParser_1.deprecatedBorderColorParser);
|
|
96
|
+
(0, addParser_1.addParser)(event.domToModelOption, 'image', imageSizeParser_1.imageSizeParser);
|
|
96
97
|
(0, setProcessor_1.setProcessor)(event.domToModelOption, 'button', pasteButtonProcessor_1.pasteButtonProcessor);
|
|
97
98
|
if (pasteType === 'mergeFormat') {
|
|
98
|
-
(0, addParser_1.addParser)(event.domToModelOption, 'block', blockElementParser);
|
|
99
|
-
(0, addParser_1.addParser)(event.domToModelOption, 'listLevel', blockElementParser);
|
|
99
|
+
(0, addParser_1.addParser)(event.domToModelOption, 'block', blockElementParser_1.blockElementParser);
|
|
100
|
+
(0, addParser_1.addParser)(event.domToModelOption, 'listLevel', blockElementParser_1.blockElementParser);
|
|
100
101
|
}
|
|
101
102
|
this.setEventSanitizers(event);
|
|
102
103
|
};
|
|
@@ -117,33 +118,5 @@ define(["require", "exports", "tslib", "./utils/addParser", "roosterjs-content-m
|
|
|
117
118
|
return PastePlugin;
|
|
118
119
|
}());
|
|
119
120
|
exports.PastePlugin = PastePlugin;
|
|
120
|
-
/**
|
|
121
|
-
* For block elements that have background color style, remove the background color when user selects the merge current format
|
|
122
|
-
* paste option
|
|
123
|
-
*/
|
|
124
|
-
var blockElementParser = function (format, element) {
|
|
125
|
-
if (element.style.backgroundColor) {
|
|
126
|
-
delete format.backgroundColor;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
var ElementBorderKeys = new Map([
|
|
130
|
-
['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],
|
|
131
|
-
['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],
|
|
132
|
-
['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],
|
|
133
|
-
['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],
|
|
134
|
-
]);
|
|
135
|
-
function tableBorderParser(format, element) {
|
|
136
|
-
roosterjs_content_model_dom_1.BorderKeys.forEach(function (key) {
|
|
137
|
-
if (!format[key]) {
|
|
138
|
-
var styleSet = ElementBorderKeys.get(key);
|
|
139
|
-
if (styleSet &&
|
|
140
|
-
element.style[styleSet.w] &&
|
|
141
|
-
element.style[styleSet.s] &&
|
|
142
|
-
!element.style[styleSet.c]) {
|
|
143
|
-
format[key] = element.style[styleSet.w] + " " + element.style[styleSet.s];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
121
|
});
|
|
149
122
|
//# sourceMappingURL=PastePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PastePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/paste/PastePlugin.ts"],"names":[],"mappings":";;;;IA2BA;;;;;;OAMG;IACH;QAGI;;;;WAIG;QACH,qBACY,uBAAiC,EACjC,uBAWP;YAXO,wCAAA,EAAA;gBAOJ,eAAe,EAAE,qCAAiB;gBAClC,qBAAqB,EAAE,EAAE;gBACzB,wBAAwB,EAAE,EAAE;gBAC5B,mBAAmB,EAAE,EAAE;aAC1B;YAZO,4BAAuB,GAAvB,uBAAuB,CAAU;YACjC,4BAAuB,GAAvB,uBAAuB,CAW9B;YApBG,WAAM,GAAmB,IAAI,CAAC;QAqBnC,CAAC;QAEJ;;WAEG;QACH,6BAAO,GAAP;YACI,OAAO,OAAO,CAAC;QACnB,CAAC;QAED;;;;;WAKG;QACH,gCAAU,GAAV,UAAW,MAAe;YACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;QAED;;;;WAIG;QACH,6BAAO,GAAP;YACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;QAED;;;;;WAKG;QACH,mCAAa,GAAb,UAAc,KAAkB;YAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,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,QAAQ,CAAC,CAAC,CAAC;oBACzB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;oBACzB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC5B;oBACE,MAAM,CAAC,GAAG,CAAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;iBAC7E;aACJ;QACL,CAAC,CAAC,CAAC;IACP,CAAC","sourcesContent":["import { addParser } from './utils/addParser';\nimport { BorderKeys, getObjectKeys } from 'roosterjs-content-model-dom';\nimport { chainSanitizerCallback } from './utils/chainSanitizerCallback';\nimport { DefaultSanitizers } from './DefaultSanitizers';\nimport { deprecatedBorderColorParser } from './parsers/deprecatedColorParser';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { parseLink } from './parsers/linkParser';\nimport { pasteButtonProcessor } from './processors/pasteButtonProcessor';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromOneNote } from './oneNote/processPastedContentFromOneNote';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport { setProcessor } from './utils/setProcessor';\nimport type {\n BeforePasteEvent,\n BorderFormat,\n ContentModelBlockFormat,\n ContentModelTableCellFormat,\n DomToModelOptionForSanitizing,\n EditorPlugin,\n FormatParser,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste plugin, handles BeforePaste event and reformat some special content, including:\n * 1. Content copied from Word\n * 2. Content copied from Excel\n * 3. Content copied from Word Online or OneNote Online\n * 4. Content copied from Power Point\n */\nexport class PastePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n\n /**\n * Construct a new instance of Paste class\n * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN\n * @param allowExcelNoBorderTable Allow table copied from Excel without border\n */\n constructor(\n private allowExcelNoBorderTable?: boolean,\n private domToModelForSanitizing: Pick<\n DomToModelOptionForSanitizing,\n | 'additionalAllowedTags'\n | 'additionalDisallowedTags'\n | 'styleSanitizers'\n | 'attributeSanitizers'\n > = {\n styleSanitizers: DefaultSanitizers,\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n attributeSanitizers: {},\n }\n ) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Paste';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor || event.eventType != 'beforePaste') {\n return;\n }\n\n if (!event.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(\n event,\n false /* shouldConvertSingleImage */,\n this.editor.getEnvironment()\n );\n const pasteType = event.pasteType;\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(event);\n break;\n case 'wacComponents':\n processPastedContentWacComponents(event);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n case 'excelNonNativeEvent':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n event,\n this.editor.getDOMCreator(),\n !!this.allowExcelNoBorderTable,\n pasteSource != 'excelNonNativeEvent' /* isNativeEvent */\n );\n }\n break;\n case 'googleSheets':\n event.domToModelOption.additionalAllowedTags.push(\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME as Lowercase<string>\n );\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(event, this.editor.getDOMCreator());\n break;\n\n case 'oneNoteDesktop':\n processPastedContentFromOneNote(event);\n break;\n }\n\n addParser(event.domToModelOption, 'link', parseLink);\n addParser(event.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'tableCell', tableBorderParser);\n addParser(event.domToModelOption, 'table', deprecatedBorderColorParser);\n setProcessor(event.domToModelOption, 'button', pasteButtonProcessor);\n\n if (pasteType === 'mergeFormat') {\n addParser(event.domToModelOption, 'block', blockElementParser);\n addParser(event.domToModelOption, 'listLevel', blockElementParser);\n }\n\n this.setEventSanitizers(event);\n }\n\n private setEventSanitizers(event: BeforePasteEvent) {\n if (this.domToModelForSanitizing) {\n const {\n styleSanitizers,\n attributeSanitizers,\n additionalAllowedTags,\n additionalDisallowedTags,\n } = this.domToModelForSanitizing;\n getObjectKeys(styleSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.styleSanitizers,\n key,\n styleSanitizers[key]\n )\n );\n getObjectKeys(attributeSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.attributeSanitizers,\n key,\n attributeSanitizers[key]\n )\n );\n event.domToModelOption.additionalAllowedTags.push(...additionalAllowedTags);\n event.domToModelOption.additionalDisallowedTags.push(...additionalDisallowedTags);\n }\n }\n}\n\n/**\n * For block elements that have background color style, remove the background color when user selects the merge current format\n * paste option\n */\nconst blockElementParser: FormatParser<ContentModelBlockFormat> = (\n format: ContentModelBlockFormat,\n element: HTMLElement\n) => {\n if (element.style.backgroundColor) {\n delete format.backgroundColor;\n }\n};\n\nconst ElementBorderKeys = new Map<\n keyof BorderFormat,\n {\n c: keyof CSSStyleDeclaration;\n s: keyof CSSStyleDeclaration;\n w: keyof CSSStyleDeclaration;\n }\n>([\n ['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],\n ['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],\n ['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],\n ['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],\n]);\n\nfunction tableBorderParser(format: ContentModelTableCellFormat, element: HTMLElement): void {\n BorderKeys.forEach(key => {\n if (!format[key]) {\n const styleSet = ElementBorderKeys.get(key);\n if (\n styleSet &&\n element.style[styleSet.w] &&\n element.style[styleSet.s] &&\n !element.style[styleSet.c]\n ) {\n format[key] = `${element.style[styleSet.w]} ${element.style[styleSet.s]}`;\n }\n }\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PastePlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/paste/PastePlugin.ts"],"names":[],"mappings":";;;;IA0BA;;;;;;OAMG;IACH;QAGI;;;;WAIG;QACH,qBACY,uBAAiC,EACjC,uBAWP;YAXO,wCAAA,EAAA;gBAOJ,eAAe,EAAE,qCAAiB;gBAClC,qBAAqB,EAAE,EAAE;gBACzB,wBAAwB,EAAE,EAAE;gBAC5B,mBAAmB,EAAE,EAAE;aAC1B;YAZO,4BAAuB,GAAvB,uBAAuB,CAAU;YACjC,4BAAuB,GAAvB,uBAAuB,CAW9B;YApBG,WAAM,GAAmB,IAAI,CAAC;QAqBnC,CAAC;QAEJ;;WAEG;QACH,6BAAO,GAAP;YACI,OAAO,OAAO,CAAC;QACnB,CAAC;QAED;;;;;WAKG;QACH,gCAAU,GAAV,UAAW,MAAe;YACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;QAED;;;;WAIG;QACH,6BAAO,GAAP;YACI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACvB,CAAC;QAED;;;;;WAKG;QACH,mCAAa,G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A,GAAG;oBAC1C,OAAA,IAAA,+CAAsB,EAClB,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,EAC1C,GAAG,EACH,qBAAmB,CAAC,GAAG,CAAC,CAC3B;gBAJD,CAIC,CACJ,CAAC;gBACF,CAAA,KAAA,KAAK,CAAC,gBAAgB,CAAC,qBAAqB,CAAA,CAAC,IAAI,8DAAI,qBAAqB,WAAE;gBAC5E,CAAA,KAAA,KAAK,CAAC,gBAAgB,CAAC,wBAAwB,CAAA,CAAC,IAAI,8DAAI,wBAAwB,WAAE;aACrF;QACL,CAAC;QACL,kBAAC;IAAD,CAAC,AAnJD,IAmJC;IAnJY,kCAAW","sourcesContent":["import { addParser } from './utils/addParser';\nimport { blockElementParser } from './parsers/blockElementParser';\nimport { chainSanitizerCallback } from './utils/chainSanitizerCallback';\nimport { DefaultSanitizers } from './DefaultSanitizers';\nimport { deprecatedBorderColorParser } from './parsers/deprecatedColorParser';\nimport { getObjectKeys } from 'roosterjs-content-model-dom';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { imageSizeParser } from './parsers/imageSizeParser';\nimport { parseLink } from './parsers/linkParser';\nimport { pasteButtonProcessor } from './processors/pasteButtonProcessor';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromOneNote } from './oneNote/processPastedContentFromOneNote';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport { setProcessor } from './utils/setProcessor';\nimport { tableBorderParser } from './parsers/tableBorderParser';\nimport type {\n BeforePasteEvent,\n DomToModelOptionForSanitizing,\n EditorPlugin,\n IEditor,\n PluginEvent,\n} from 'roosterjs-content-model-types';\n\n/**\n * Paste plugin, handles BeforePaste event and reformat some special content, including:\n * 1. Content copied from Word\n * 2. Content copied from Excel\n * 3. Content copied from Word Online or OneNote Online\n * 4. Content copied from Power Point\n */\nexport class PastePlugin implements EditorPlugin {\n private editor: IEditor | null = null;\n\n /**\n * Construct a new instance of Paste class\n * @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN\n * @param allowExcelNoBorderTable Allow table copied from Excel without border\n */\n constructor(\n private allowExcelNoBorderTable?: boolean,\n private domToModelForSanitizing: Pick<\n DomToModelOptionForSanitizing,\n | 'additionalAllowedTags'\n | 'additionalDisallowedTags'\n | 'styleSanitizers'\n | 'attributeSanitizers'\n > = {\n styleSanitizers: DefaultSanitizers,\n additionalAllowedTags: [],\n additionalDisallowedTags: [],\n attributeSanitizers: {},\n }\n ) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'Paste';\n }\n\n /**\n * The first method that editor will call to a plugin when editor is initializing.\n * It will pass in the editor instance, plugin should take this chance to save the\n * editor reference so that it can call to any editor method or format API later.\n * @param editor The editor object\n */\n initialize(editor: IEditor) {\n this.editor = editor;\n }\n\n /**\n * The last method that editor will call to a plugin before it is disposed.\n * Plugin can take this chance to clear the reference to editor. After this method is\n * called, plugin should not call to any editor method since it will result in error.\n */\n dispose() {\n this.editor = null;\n }\n\n /**\n * Core method for a plugin. Once an event happens in editor, editor will call this\n * method of each plugin to handle the event as long as the event is not handled\n * exclusively by another plugin.\n * @param event The event to handle:\n */\n onPluginEvent(event: PluginEvent) {\n if (!this.editor || event.eventType != 'beforePaste') {\n return;\n }\n\n if (!event.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(\n event,\n false /* shouldConvertSingleImage */,\n this.editor.getEnvironment()\n );\n const pasteType = event.pasteType;\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(event);\n break;\n case 'wacComponents':\n processPastedContentWacComponents(event);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n case 'excelNonNativeEvent':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n event,\n this.editor.getDOMCreator(),\n !!this.allowExcelNoBorderTable,\n pasteSource != 'excelNonNativeEvent' /* isNativeEvent */\n );\n }\n break;\n case 'googleSheets':\n event.domToModelOption.additionalAllowedTags.push(\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME as Lowercase<string>\n );\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(event, this.editor.getDOMCreator());\n break;\n\n case 'oneNoteDesktop':\n processPastedContentFromOneNote(event);\n break;\n }\n\n addParser(event.domToModelOption, 'link', parseLink);\n addParser(event.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'tableCell', tableBorderParser);\n addParser(event.domToModelOption, 'table', deprecatedBorderColorParser);\n addParser(event.domToModelOption, 'image', imageSizeParser);\n setProcessor(event.domToModelOption, 'button', pasteButtonProcessor);\n\n if (pasteType === 'mergeFormat') {\n addParser(event.domToModelOption, 'block', blockElementParser);\n addParser(event.domToModelOption, 'listLevel', blockElementParser);\n }\n\n this.setEventSanitizers(event);\n }\n\n private setEventSanitizers(event: BeforePasteEvent) {\n if (this.domToModelForSanitizing) {\n const {\n styleSanitizers,\n attributeSanitizers,\n additionalAllowedTags,\n additionalDisallowedTags,\n } = this.domToModelForSanitizing;\n getObjectKeys(styleSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.styleSanitizers,\n key,\n styleSanitizers[key]\n )\n );\n getObjectKeys(attributeSanitizers).forEach(key =>\n chainSanitizerCallback(\n event.domToModelOption.attributeSanitizers,\n key,\n attributeSanitizers[key]\n )\n );\n event.domToModelOption.additionalAllowedTags.push(...additionalAllowedTags);\n event.domToModelOption.additionalDisallowedTags.push(...additionalDisallowedTags);\n }\n }\n}\n"]}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
define(["require", "exports", "../utils/addParser", "./getStyleMetadata", "../utils/getStyles", "./processWordComments", "./processWordLists", "../parsers/removeNegativeTextIndentParser", "../utils/setProcessor"], function (require, exports, addParser_1, getStyleMetadata_1, getStyles_1, processWordComments_1, processWordLists_1, removeNegativeTextIndentParser_1, setProcessor_1) {
|
|
1
|
+
define(["require", "exports", "../utils/addParser", "../parsers/adjustPercentileLineHeightParser", "./getStyleMetadata", "../utils/getStyles", "../parsers/listLevelParser", "./processWordComments", "./processWordLists", "../parsers/removeNegativeTextIndentParser", "../utils/setProcessor", "../parsers/wordTableParser"], function (require, exports, addParser_1, adjustPercentileLineHeightParser_1, getStyleMetadata_1, getStyles_1, listLevelParser_1, processWordComments_1, processWordLists_1, removeNegativeTextIndentParser_1, setProcessor_1, wordTableParser_1) {
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.processPastedContentFromWordDesktop = void 0;
|
|
5
|
-
var PERCENTAGE_REGEX = /%/;
|
|
6
|
-
// Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal
|
|
7
|
-
var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;
|
|
8
5
|
/**
|
|
9
6
|
* @internal
|
|
10
7
|
* Handles Pasted content when source is Word Desktop
|
|
@@ -13,11 +10,11 @@ define(["require", "exports", "../utils/addParser", "./getStyleMetadata", "../ut
|
|
|
13
10
|
function processPastedContentFromWordDesktop(ev) {
|
|
14
11
|
var metadataMap = (0, getStyleMetadata_1.getStyleMetadata)(ev);
|
|
15
12
|
(0, setProcessor_1.setProcessor)(ev.domToModelOption, 'element', wordDesktopElementProcessor(metadataMap));
|
|
16
|
-
(0, addParser_1.addParser)(ev.domToModelOption, 'block', adjustPercentileLineHeight);
|
|
13
|
+
(0, addParser_1.addParser)(ev.domToModelOption, 'block', adjustPercentileLineHeightParser_1.adjustPercentileLineHeight);
|
|
17
14
|
(0, addParser_1.addParser)(ev.domToModelOption, 'block', removeNegativeTextIndentParser_1.removeNegativeTextIndentParser);
|
|
18
|
-
(0, addParser_1.addParser)(ev.domToModelOption, 'listLevel', listLevelParser);
|
|
19
|
-
(0, addParser_1.addParser)(ev.domToModelOption, 'container', wordTableParser);
|
|
20
|
-
(0, addParser_1.addParser)(ev.domToModelOption, 'table', wordTableParser);
|
|
15
|
+
(0, addParser_1.addParser)(ev.domToModelOption, 'listLevel', listLevelParser_1.listLevelParser);
|
|
16
|
+
(0, addParser_1.addParser)(ev.domToModelOption, 'container', wordTableParser_1.wordTableParser);
|
|
17
|
+
(0, addParser_1.addParser)(ev.domToModelOption, 'table', wordTableParser_1.wordTableParser);
|
|
21
18
|
}
|
|
22
19
|
exports.processPastedContentFromWordDesktop = processPastedContentFromWordDesktop;
|
|
23
20
|
var wordDesktopElementProcessor = function (metadataKey) {
|
|
@@ -30,29 +27,5 @@ define(["require", "exports", "../utils/addParser", "./getStyleMetadata", "../ut
|
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
29
|
};
|
|
33
|
-
function adjustPercentileLineHeight(format, element) {
|
|
34
|
-
//If the line height is less than the browser default line height, line between the text is going to be too narrow
|
|
35
|
-
var parsedLineHeight;
|
|
36
|
-
if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
|
|
37
|
-
!isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))) {
|
|
38
|
-
format.lineHeight = (DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *
|
|
39
|
-
(parsedLineHeight / 100)).toString();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
var listLevelParser = function (format, element, _context, defaultStyle) {
|
|
43
|
-
if (element.style.marginLeft != '') {
|
|
44
|
-
format.marginLeft = defaultStyle.marginLeft;
|
|
45
|
-
}
|
|
46
|
-
format.marginBottom = undefined;
|
|
47
|
-
};
|
|
48
|
-
var wordTableParser = function (format, element) {
|
|
49
|
-
var _a;
|
|
50
|
-
if ((_a = format.marginLeft) === null || _a === void 0 ? void 0 : _a.startsWith('-')) {
|
|
51
|
-
delete format.marginLeft;
|
|
52
|
-
}
|
|
53
|
-
if (format.htmlAlign) {
|
|
54
|
-
delete format.htmlAlign;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
30
|
});
|
|
58
31
|
//# sourceMappingURL=processPastedContentFromWordDesktop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":";;;;IAaA;;;;OAIG;IACH,SAAgB,mCAAmC,CAAC,EAAoB;QACpE,IAAM,WAAW,GAA8B,IAAA,mCAAgB,EAAC,EAAE,CAAC,CAAC;QAEpE,IAAA,2BAAY,EAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,2BAA2B,CAAC,WAAW,CAAC,CAAC,CAAC;QACvF,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,6DAA0B,CAAC,CAAC;QACpE,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,+DAA8B,CAAC,CAAC;QACxE,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,iCAAe,CAAC,CAAC;QAC7D,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,iCAAe,CAAC,CAAC;QAC7D,IAAA,qBAAS,EAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,iCAAe,CAAC,CAAC;IAC7D,CAAC;IATD,kFASC;IAED,IAAM,2BAA2B,GAAG,UAChC,WAAsC;QAEtC,OAAO,UAAC,KAAK,EAAE,OAAO,EAAE,OAAO;YAC3B,IAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,CAAC;YAClC,4FAA4F;YAC5F,IACI,CAAC,CACG,IAAA,kCAAe,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC;gBAC7D,IAAA,yCAAmB,EAAC,MAAM,EAAE,OAAO,CAAC,CACvC,EACH;gBACE,OAAO,CAAC,wBAAwB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;aACrE;QACL,CAAC,CAAC;IACN,CAAC,CAAC","sourcesContent":["import { addParser } from '../utils/addParser';\nimport { adjustPercentileLineHeight } from '../parsers/adjustPercentileLineHeightParser';\nimport { getStyleMetadata } from './getStyleMetadata';\nimport { getStyles } from '../utils/getStyles';\nimport { listLevelParser } from '../parsers/listLevelParser';\nimport { processWordComments } from './processWordComments';\nimport { processWordList } from './processWordLists';\nimport { removeNegativeTextIndentParser } from '../parsers/removeNegativeTextIndentParser';\nimport { setProcessor } from '../utils/setProcessor';\nimport { wordTableParser } from '../parsers/wordTableParser';\nimport type { WordMetadata } from './WordMetadata';\nimport type { BeforePasteEvent, ElementProcessor } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * Handles Pasted content when source is Word Desktop\n * @param ev BeforePasteEvent\n */\nexport function processPastedContentFromWordDesktop(ev: BeforePasteEvent) {\n const metadataMap: Map<string, WordMetadata> = getStyleMetadata(ev);\n\n setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor(metadataMap));\n addParser(ev.domToModelOption, 'block', adjustPercentileLineHeight);\n addParser(ev.domToModelOption, 'block', removeNegativeTextIndentParser);\n addParser(ev.domToModelOption, 'listLevel', listLevelParser);\n addParser(ev.domToModelOption, 'container', wordTableParser);\n addParser(ev.domToModelOption, 'table', wordTableParser);\n}\n\nconst wordDesktopElementProcessor = (\n metadataKey: Map<string, WordMetadata>\n): ElementProcessor<HTMLElement> => {\n return (group, element, context) => {\n const styles = getStyles(element);\n // Process Word Lists or Word Commands, otherwise use the default processor on this element.\n if (\n !(\n processWordList(styles, group, element, context, metadataKey) ||\n processWordComments(styles, element)\n )\n ) {\n context.defaultElementProcessors.element(group, element, context);\n }\n };\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContentModelBlockFormat } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Parser for adjusting percentage-based line heights and converting 'normal' to a specific percentage
|
|
5
|
+
* @param format The block format to modify
|
|
6
|
+
* @param element The HTML element being processed
|
|
7
|
+
*/
|
|
8
|
+
export declare function adjustPercentileLineHeight(format: ContentModelBlockFormat, element: HTMLElement): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.adjustPercentileLineHeight = void 0;
|
|
5
|
+
var PERCENTAGE_REGEX = /%/;
|
|
6
|
+
// Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal
|
|
7
|
+
var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
* Parser for adjusting percentage-based line heights and converting 'normal' to a specific percentage
|
|
11
|
+
* @param format The block format to modify
|
|
12
|
+
* @param element The HTML element being processed
|
|
13
|
+
*/
|
|
14
|
+
function adjustPercentileLineHeight(format, element) {
|
|
15
|
+
// If the line height is less than the browser default line height, line between the text is going to be too narrow
|
|
16
|
+
var parsedLineHeight;
|
|
17
|
+
if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
|
|
18
|
+
!isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))) {
|
|
19
|
+
format.lineHeight = (DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *
|
|
20
|
+
(parsedLineHeight / 100)).toString();
|
|
21
|
+
}
|
|
22
|
+
else if (element.style.lineHeight.toLowerCase() === 'normal') {
|
|
23
|
+
format.lineHeight = '120%';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.adjustPercentileLineHeight = adjustPercentileLineHeight;
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=adjustPercentileLineHeightParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adjustPercentileLineHeightParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/adjustPercentileLineHeightParser.ts"],"names":[],"mappings":";;;;IAEA,IAAM,gBAAgB,GAAG,GAAG,CAAC;IAC7B,mHAAmH;IACnH,IAAM,sCAAsC,GAAG,GAAG,CAAC;IAEnD;;;;;OAKG;IACH,SAAgB,0BAA0B,CACtC,MAA+B,EAC/B,OAAoB;QAEpB,mHAAmH;QACnH,IAAI,gBAAwB,CAAC;QAC7B,IACI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;YAC/C,CAAC,KAAK,CAAC,CAAC,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EACjE;YACE,MAAM,CAAC,UAAU,GAAG,CAChB,sCAAsC;gBACtC,CAAC,gBAAgB,GAAG,GAAG,CAAC,CAC3B,CAAC,QAAQ,EAAE,CAAC;SAChB;aAAM,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,KAAK,QAAQ,EAAE;YAC5D,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC;SAC9B;IACL,CAAC;IAjBD,gEAiBC","sourcesContent":["import type { ContentModelBlockFormat } from 'roosterjs-content-model-types';\n\nconst PERCENTAGE_REGEX = /%/;\n// Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal\nconst DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;\n\n/**\n * @internal\n * Parser for adjusting percentage-based line heights and converting 'normal' to a specific percentage\n * @param format The block format to modify\n * @param element The HTML element being processed\n */\nexport function adjustPercentileLineHeight(\n format: ContentModelBlockFormat,\n element: HTMLElement\n): void {\n // If the line height is less than the browser default line height, line between the text is going to be too narrow\n let parsedLineHeight: number;\n if (\n PERCENTAGE_REGEX.test(element.style.lineHeight) &&\n !isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))\n ) {\n format.lineHeight = (\n DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *\n (parsedLineHeight / 100)\n ).toString();\n } else if (element.style.lineHeight.toLowerCase() === 'normal') {\n format.lineHeight = '120%';\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ContentModelBlockFormat, FormatParser } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* For block elements that have background color style, remove the background color when user selects the merge current format
|
|
5
|
+
* paste option
|
|
6
|
+
*/
|
|
7
|
+
export declare const blockElementParser: FormatParser<ContentModelBlockFormat>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.blockElementParser = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
* For block elements that have background color style, remove the background color when user selects the merge current format
|
|
8
|
+
* paste option
|
|
9
|
+
*/
|
|
10
|
+
var blockElementParser = function (format, element) {
|
|
11
|
+
if (element.style.backgroundColor) {
|
|
12
|
+
delete format.backgroundColor;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.blockElementParser = blockElementParser;
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=blockElementParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockElementParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/blockElementParser.ts"],"names":[],"mappings":";;;;IAEA;;;;OAIG;IACI,IAAM,kBAAkB,GAA0C,UACrE,MAA+B,EAC/B,OAAoB;QAEpB,IAAI,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE;YAC/B,OAAO,MAAM,CAAC,eAAe,CAAC;SACjC;IACL,CAAC,CAAC;IAPW,QAAA,kBAAkB,sBAO7B","sourcesContent":["import type { ContentModelBlockFormat, FormatParser } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n * For block elements that have background color style, remove the background color when user selects the merge current format\n * paste option\n */\nexport const blockElementParser: FormatParser<ContentModelBlockFormat> = (\n format: ContentModelBlockFormat,\n element: HTMLElement\n) => {\n if (element.style.backgroundColor) {\n delete format.backgroundColor;\n }\n};\n"]}
|