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,6 @@
|
|
|
1
|
+
import type { ContentModelImageFormat, FormatParser } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Remove image size if it is larger than editor view width to let it auto size
|
|
5
|
+
*/
|
|
6
|
+
export declare const imageSizeParser: FormatParser<ContentModelImageFormat>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.imageSizeParser = void 0;
|
|
5
|
+
// Only process absolute units (px, pt, in, cm, mm)
|
|
6
|
+
var AbsoluteUnitRegex = /^\s*\d+(\.\d+)?\s*(px|pt|in|cm|mm)\s*$/i;
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Remove image size if it is larger than editor view width to let it auto size
|
|
10
|
+
*/
|
|
11
|
+
var imageSizeParser = function (format, element, context) {
|
|
12
|
+
var maxImageSize = context.editorViewWidth;
|
|
13
|
+
var width = format.width;
|
|
14
|
+
if (width && maxImageSize && AbsoluteUnitRegex.test(width)) {
|
|
15
|
+
var widthValue = (0, roosterjs_content_model_dom_1.parseValueWithUnit)(width, element);
|
|
16
|
+
// If the given width is larger than editor view width, we clear both width and height to let it auto size
|
|
17
|
+
if (widthValue > maxImageSize) {
|
|
18
|
+
delete format.width;
|
|
19
|
+
delete format.height;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.imageSizeParser = imageSizeParser;
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=imageSizeParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imageSizeParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/imageSizeParser.ts"],"names":[],"mappings":";;;;IAGA,mDAAmD;IACnD,IAAM,iBAAiB,GAAG,yCAAyC,CAAC;IAEpE;;;OAGG;IACI,IAAM,eAAe,GAA0C,UAClE,MAAM,EACN,OAAO,EACP,OAAO;QAEP,IAAM,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;QACrC,IAAA,KAAK,GAAK,MAAM,MAAX,CAAY;QAEzB,IAAI,KAAK,IAAI,YAAY,IAAI,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YACxD,IAAM,UAAU,GAAG,IAAA,gDAAkB,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAEtD,0GAA0G;YAC1G,IAAI,UAAU,GAAG,YAAY,EAAE;gBAC3B,OAAO,MAAM,CAAC,KAAK,CAAC;gBACpB,OAAO,MAAM,CAAC,MAAM,CAAC;aACxB;SACJ;IACL,CAAC,CAAC;IAjBW,QAAA,eAAe,mBAiB1B","sourcesContent":["import { parseValueWithUnit } from 'roosterjs-content-model-dom';\nimport type { ContentModelImageFormat, FormatParser } from 'roosterjs-content-model-types';\n\n// Only process absolute units (px, pt, in, cm, mm)\nconst AbsoluteUnitRegex = /^\\s*\\d+(\\.\\d+)?\\s*(px|pt|in|cm|mm)\\s*$/i;\n\n/**\n * @internal\n * Remove image size if it is larger than editor view width to let it auto size\n */\nexport const imageSizeParser: FormatParser<ContentModelImageFormat> = (\n format,\n element,\n context\n) => {\n const maxImageSize = context.editorViewWidth;\n const { width } = format;\n\n if (width && maxImageSize && AbsoluteUnitRegex.test(width)) {\n const widthValue = parseValueWithUnit(width, element);\n\n // If the given width is larger than editor view width, we clear both width and height to let it auto size\n if (widthValue > maxImageSize) {\n delete format.width;\n delete format.height;\n }\n }\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContentModelListItemLevelFormat, FormatParser } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* Parser for processing list level formatting specific to Word Desktop
|
|
5
|
+
* @param format The list item level format to modify
|
|
6
|
+
* @param element The HTML element being processed
|
|
7
|
+
* @param _context The DOM to model context
|
|
8
|
+
* @param defaultStyle The default style properties
|
|
9
|
+
*/
|
|
10
|
+
export declare const listLevelParser: FormatParser<ContentModelListItemLevelFormat>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.listLevelParser = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
* Parser for processing list level formatting specific to Word Desktop
|
|
8
|
+
* @param format The list item level format to modify
|
|
9
|
+
* @param element The HTML element being processed
|
|
10
|
+
* @param _context The DOM to model context
|
|
11
|
+
* @param defaultStyle The default style properties
|
|
12
|
+
*/
|
|
13
|
+
var listLevelParser = function (format, element, _context, defaultStyle) {
|
|
14
|
+
if (element.style.marginLeft !== '') {
|
|
15
|
+
format.marginLeft = defaultStyle.marginLeft;
|
|
16
|
+
}
|
|
17
|
+
format.marginBottom = undefined;
|
|
18
|
+
};
|
|
19
|
+
exports.listLevelParser = listLevelParser;
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=listLevelParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listLevelParser.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/parsers/listLevelParser.ts"],"names":[],"mappings":";;;;IAMA;;;;;;;OAOG;IACI,IAAM,eAAe,GAAkD,UAC1E,MAAuC,EACvC,OAAoB,EACpB,QAA2B,EAC3B,YAAoD;QAEpD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,EAAE,EAAE;YACjC,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;SAC/C;QAED,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;IACpC,CAAC,CAAC;IAXW,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,29 @@
|
|
|
1
|
+
define(["require", "exports", "roosterjs-content-model-dom"], function (require, exports, roosterjs_content_model_dom_1) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.tableBorderParser = void 0;
|
|
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
|
+
});
|
|
29
|
+
//# 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":";;;;IAOA,IAAM,iBAAiB,GAAG,IAAI,GAAG,CAO/B;QACE,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC;QAChF,CAAC,aAAa,EAAE,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC;QACxF,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC;QAC5F,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC;KACvF,CAAC,CAAC;IAEH;;OAEG;IACI,IAAM,iBAAiB,GAA8C,UAAC,MAAM,EAAE,OAAO;QACxF,wCAAU,CAAC,OAAO,CAAC,UAAA,GAAG;YAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;gBACd,IAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAE5C,IACI,QAAQ;oBACR,OAAO,CAAC,KAAK,CAAC,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,CAAC;IAfW,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,22 @@
|
|
|
1
|
+
define(["require", "exports"], function (require, exports) {
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.wordTableParser = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
* Parser for processing table formatting specific to Word Desktop
|
|
8
|
+
* @param format The table format to modify
|
|
9
|
+
* @param element The HTML element being processed
|
|
10
|
+
*/
|
|
11
|
+
var wordTableParser = function (format, element) {
|
|
12
|
+
var _a;
|
|
13
|
+
if ((_a = format.marginLeft) === null || _a === void 0 ? void 0 : _a.startsWith('-')) {
|
|
14
|
+
delete format.marginLeft;
|
|
15
|
+
}
|
|
16
|
+
if (format.htmlAlign) {
|
|
17
|
+
delete format.htmlAlign;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.wordTableParser = wordTableParser;
|
|
21
|
+
});
|
|
22
|
+
//# 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":";;;;IAEA;;;;;OAKG;IACI,IAAM,eAAe,GAA0C,UAAC,MAAM,EAAE,OAAO;;QAClF,IAAI,MAAA,MAAM,CAAC,UAAU,0CAAE,UAAU,CAAC,GAAG,CAAC,EAAE;YACpC,OAAO,MAAM,CAAC,UAAU,CAAC;SAC5B;QACD,IAAI,MAAM,CAAC,SAAS,EAAE;YAClB,OAAO,MAAM,CAAC,SAAS,CAAC;SAC3B;IACL,CAAC,CAAC;IAPW,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"]}
|
|
@@ -2,13 +2,13 @@ import { __read, __spreadArray, __values } from "tslib";
|
|
|
2
2
|
import { ChangeSource } from 'roosterjs-content-model-dom';
|
|
3
3
|
import { checkAndInsertHorizontalLine } from './horizontalLine/checkAndInsertHorizontalLine';
|
|
4
4
|
import { createLink } from './link/createLink';
|
|
5
|
-
import { formatTextSegmentBeforeSelectionMarker, promoteLink } from 'roosterjs-content-model-api';
|
|
6
5
|
import { getListTypeStyle } from './list/getListTypeStyle';
|
|
7
6
|
import { keyboardListTrigger } from './list/keyboardListTrigger';
|
|
8
7
|
import { transformFraction } from './numbers/transformFraction';
|
|
9
8
|
import { transformHyphen } from './hyphen/transformHyphen';
|
|
10
9
|
import { transformOrdinals } from './numbers/transformOrdinals';
|
|
11
10
|
import { unlink } from './link/unlink';
|
|
11
|
+
import { formatTextSegmentBeforeSelectionMarker, promoteLink, getPromoteLink, } from 'roosterjs-content-model-api';
|
|
12
12
|
/**
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
@@ -138,7 +138,6 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
138
138
|
this.editor = null;
|
|
139
139
|
};
|
|
140
140
|
AutoFormatPlugin.prototype.shouldHandleInputEventExclusively = function (editor, event) {
|
|
141
|
-
var _this = this;
|
|
142
141
|
var rawEvent = event.rawEvent;
|
|
143
142
|
var selection = editor.getDOMSelection();
|
|
144
143
|
var shouldHandle = false;
|
|
@@ -147,15 +146,15 @@ var AutoFormatPlugin = /** @class */ (function () {
|
|
|
147
146
|
selection.type === 'range' &&
|
|
148
147
|
selection.range.collapsed &&
|
|
149
148
|
rawEvent.data == ' ') {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var list = getListTypeStyle(model,
|
|
153
|
-
var
|
|
154
|
-
autoLink:
|
|
155
|
-
autoTel:
|
|
156
|
-
autoMailto:
|
|
149
|
+
var _a = this.options, autoLink_1 = _a.autoLink, autoTel_1 = _a.autoTel, autoMailto_1 = _a.autoMailto, autoBullet_1 = _a.autoBullet, autoNumbering_1 = _a.autoNumbering;
|
|
150
|
+
formatTextSegmentBeforeSelectionMarker(editor, function (model, previousSegment, _paragraph, _markerFormat) {
|
|
151
|
+
var list = getListTypeStyle(model, autoBullet_1, autoNumbering_1);
|
|
152
|
+
var promotedLink = getPromoteLink(previousSegment, {
|
|
153
|
+
autoLink: autoLink_1,
|
|
154
|
+
autoTel: autoTel_1,
|
|
155
|
+
autoMailto: autoMailto_1,
|
|
157
156
|
});
|
|
158
|
-
shouldHandle = !!
|
|
157
|
+
shouldHandle = !!promotedLink || !!list;
|
|
159
158
|
return false;
|
|
160
159
|
});
|
|
161
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoFormatPlugin.js","sourceRoot":"","sources":["../../../../packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,sCAAsC,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAClG,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AA+BvC;;GAEG;AACH,IAAM,cAAc,GAA+B;IAC/C,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACjB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;IACnB,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE,KAAK;CAC5B,CAAC;AAEF;;;GAGG;AACH;IAEI;;;;;;;;;;;;;OAaG;IACH,0BAAoB,OAA2C;QAA/D,iBAAmE;QAA/C,wBAAA,EAAA,wBAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;QAfvD,WAAM,GAAmB,IAAI,CAAC;QAqG9B,aAAQ,GAAY;YACxB,OAAO,EAA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AC,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":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EACH,sCAAsC,EACtC,WAAW,EACX,cAAc,GACjB,MAAM,6BAA6B,CAAC;AA+BrC;;GAEG;AACH,IAAM,cAAc,GAA+B;IAC/C,UAAU,EAAE,KAAK;IACjB,aAAa,EAAE,KAAK;IACpB,UAAU,EAAE,KAAK;IACj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f,QAAQ,UAAA;gBACR,OAAO,SAAA;gBACP,UAAU,YAAA;aACb,CAAC,CAAC;SACN;IACL,CAAC;IACL,uBAAC;AAAD,CAAC,AApRD,IAoRC;;AAED,IAAM,YAAY,GAAG,UAAC,GAAW,EAAE,IAAY;IAC3C,IAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,OAAO,MAAM,CAAC;AAClB,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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __assign, __read, __spreadArray } from "tslib";
|
|
2
2
|
import { getListAnnounceData } from 'roosterjs-content-model-api';
|
|
3
3
|
import { splitParagraph } from '../utils/splitParagraph';
|
|
4
|
-
import { copyFormat, createListItem, createListLevel, getClosestAncestorBlockGroupIndex,
|
|
4
|
+
import { copyFormat, createListItem, createListLevel, getClosestAncestorBlockGroupIndex, ListFormats, mutateBlock, } from 'roosterjs-content-model-dom';
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
@@ -25,24 +25,6 @@ export var handleEnterOnList = function (context) {
|
|
|
25
25
|
], __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 (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
|
}
|
|
@@ -83,19 +65,4 @@ var createNewListLevel = function (listItem) {
|
|
|
83
65
|
return createListLevel(level.listType, __assign(__assign({}, level.format), { startNumberOverride: undefined, displayForDummyItem: undefined }), level.dataset);
|
|
84
66
|
});
|
|
85
67
|
};
|
|
86
|
-
var findIndex = function (blocks, levelLength) {
|
|
87
|
-
var counter = 1;
|
|
88
|
-
for (var i = 0; i < blocks.length; i++) {
|
|
89
|
-
var listItem = blocks[i];
|
|
90
|
-
if (isBlockGroupOfType(listItem, 'ListItem') &&
|
|
91
|
-
listItem.levels.length === levelLength) {
|
|
92
|
-
counter++;
|
|
93
|
-
}
|
|
94
|
-
else if (isBlockGroupOfType(listItem, 'ListItem') &&
|
|
95
|
-
listItem.levels.length == 0) {
|
|
96
|
-
return counter;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return counter;
|
|
100
|
-
};
|
|
101
68
|
//# 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":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,UAAU,EACV,cAAc,EACd,eAAe,EACf,iCAAiC,EACjC,kBAAkB,EAClB,WAAW,EACX,WAAW,GACd,MAAM,6BAA6B,CAAC;AAYrC;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAwB,UAAA,OAAO;IACjD,IAAA,YAAY,GAAkB,OAAO,aAAzB,EAAE,WAAW,GAAK,OAAO,YAAZ,CAAa;IAE9C,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,IAAI,iBAAiB,EAAE;QAC3D,IAAA,IAAI,GAAK,WAAW,KAAhB,CAAiB;QAC7B,IAAM,KAAK,GAAG,iCAAiC,CAC3C,IAAI,EACJ,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,EAAE,iBAAiB,CAAC,CACnC,CAAC;QAEF,IAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAEnC,IAAI,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,MAAK,UAAU,IAAI,UAAU,EAAE;YAC/D,IAAI,QAAQ,GAAG,WAAW,CAAC,gBAAgB,CAAC,CAAC;YAE7C,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE;gBAC3B,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;aACzB;iBAAM;gBACH,QA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AAM,IAAI,CAAC,EAC7B;YACE,OAAO,OAAO,CAAC;SAClB;KACJ;IAED,OAAO,OAAO,CAAC;AACnB,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":";AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACH,UAAU,EACV,cAAc,EACd,eAAe,EACf,iCAAiC,EACjC,WAAW,EACX,WAAW,GACd,MAAM,6BAA6B,CAAC;AAWrC;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAwB,UAAA,OAAO;IACjD,IAAA,YAAY,GAAkB,OAAO,aAAzB,EAAE,WAAW,GAAK,OAAO,YAAZ,CAAa;IAE9C,IAAI,YAAY,IAAI,YAAY,IAAI,YAAY,IAAI,iBAAiB,EAAE;QAC3D,IAAA,IAAI,GAAK,WAAW,KAAhB,CAAiB;QAC7B,IAAM,KAAK,GAAG,iCAAiC,CAC3C,IAAI,EACJ,CAAC,UAAU,CAAC,EACZ,CAAC,WAAW,EAAE,iBAAiB,CAAC,CACnC,CAAC;QAEF,IAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAM,UAAU,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;QAEnC,IAAI,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,cAAc,MAAK,UAAU,IAAI,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AAmB,EAAE,SAAS,EAC9B,mBAAmB,EAAE,SAAS,KAElC,KAAK,CAAC,OAAO,CAChB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,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,10 +1,12 @@
|
|
|
1
1
|
import { __read, __spreadArray } from "tslib";
|
|
2
2
|
import { addParser } from './utils/addParser';
|
|
3
|
-
import {
|
|
3
|
+
import { blockElementParser } from './parsers/blockElementParser';
|
|
4
4
|
import { chainSanitizerCallback } from './utils/chainSanitizerCallback';
|
|
5
5
|
import { DefaultSanitizers } from './DefaultSanitizers';
|
|
6
6
|
import { deprecatedBorderColorParser } from './parsers/deprecatedColorParser';
|
|
7
|
+
import { getObjectKeys } from 'roosterjs-content-model-dom';
|
|
7
8
|
import { getPasteSource } from './pasteSourceValidations/getPasteSource';
|
|
9
|
+
import { imageSizeParser } from './parsers/imageSizeParser';
|
|
8
10
|
import { parseLink } from './parsers/linkParser';
|
|
9
11
|
import { pasteButtonProcessor } from './processors/pasteButtonProcessor';
|
|
10
12
|
import { PastePropertyNames } from './pasteSourceValidations/constants';
|
|
@@ -14,6 +16,7 @@ import { processPastedContentFromPowerPoint } from './PowerPoint/processPastedCo
|
|
|
14
16
|
import { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';
|
|
15
17
|
import { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';
|
|
16
18
|
import { setProcessor } from './utils/setProcessor';
|
|
19
|
+
import { tableBorderParser } from './parsers/tableBorderParser';
|
|
17
20
|
/**
|
|
18
21
|
* Paste plugin, handles BeforePaste event and reformat some special content, including:
|
|
19
22
|
* 1. Content copied from Word
|
|
@@ -105,6 +108,7 @@ var PastePlugin = /** @class */ (function () {
|
|
|
105
108
|
addParser(event.domToModelOption, 'tableCell', deprecatedBorderColorParser);
|
|
106
109
|
addParser(event.domToModelOption, 'tableCell', tableBorderParser);
|
|
107
110
|
addParser(event.domToModelOption, 'table', deprecatedBorderColorParser);
|
|
111
|
+
addParser(event.domToModelOption, 'image', imageSizeParser);
|
|
108
112
|
setProcessor(event.domToModelOption, 'button', pasteButtonProcessor);
|
|
109
113
|
if (pasteType === 'mergeFormat') {
|
|
110
114
|
addParser(event.domToModelOption, 'block', blockElementParser);
|
|
@@ -129,32 +133,4 @@ var PastePlugin = /** @class */ (function () {
|
|
|
129
133
|
return PastePlugin;
|
|
130
134
|
}());
|
|
131
135
|
export { PastePlugin };
|
|
132
|
-
/**
|
|
133
|
-
* For block elements that have background color style, remove the background color when user selects the merge current format
|
|
134
|
-
* paste option
|
|
135
|
-
*/
|
|
136
|
-
var blockElementParser = function (format, element) {
|
|
137
|
-
if (element.style.backgroundColor) {
|
|
138
|
-
delete format.backgroundColor;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
var ElementBorderKeys = new Map([
|
|
142
|
-
['borderTop', { w: 'borderTopWidth', s: 'borderTopStyle', c: 'borderTopColor' }],
|
|
143
|
-
['borderRight', { w: 'borderRightWidth', s: 'borderRightStyle', c: 'borderRightColor' }],
|
|
144
|
-
['borderBottom', { w: 'borderBottomWidth', s: 'borderBottomStyle', c: 'borderBottomColor' }],
|
|
145
|
-
['borderLeft', { w: 'borderLeftWidth', s: 'borderLeftStyle', c: 'borderLeftColor' }],
|
|
146
|
-
]);
|
|
147
|
-
function tableBorderParser(format, element) {
|
|
148
|
-
BorderKeys.forEach(function (key) {
|
|
149
|
-
if (!format[key]) {
|
|
150
|
-
var styleSet = ElementBorderKeys.get(key);
|
|
151
|
-
if (styleSet &&
|
|
152
|
-
element.style[styleSet.w] &&
|
|
153
|
-
element.style[styleSet.s] &&
|
|
154
|
-
!element.style[styleSet.c]) {
|
|
155
|
-
format[key] = element.style[styleSet.w] + " " + element.style[styleSet.s];
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
136
|
//# 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":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,M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, 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":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAC5F,OAAO,EAAE,kCAAkC,EAAE,MAAM,iDAAiD,CAAC;AACrG,OAAO,EAAE,mCAAmC,EAAE,MAAM,mDAAmD,CAAC;AACxG,OAAO,EAAE,iCAAiC,EAAE,MAAM,mDAAmD,CAAC;AACtG,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAShE;;;;;;GAMG;AACH;IAGI;;;;OAIG;IACH,qBACY,uBAAiC,EAC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IAAI,IAAI,CAAC,uBAAuB,EAAE;YACxB,IAAA,KAKF,IAAI,CAAC,uBAAuB,EAJ5B,iBAAe,qBAAA,EACf,qBAAmB,yBAAA,EACnB,qBAAqB,2BAAA,EACrB,wBAAwB,8BACI,CAAC;YACjC,aAAa,CAAC,iBAAe,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBACtC,OAAA,sBAAsB,CAClB,KAAK,CAAC,gBAAgB,CAAC,eAAe,EACtC,GAAG,EACH,iBAAe,CAAC,GAAG,CAAC,CACvB;YAJD,CAIC,CACJ,CAAC;YACF,aAAa,CAAC,qBAAmB,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;gBAC1C,OAAA,sBAAsB,CAClB,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,EAC1C,GAAG,EACH,qBAAmB,CAAC,GAAG,CAAC,CAC3B;YAJD,CAIC,CACJ,CAAC;YACF,CAAA,KAAA,KAAK,CAAC,gBAAgB,CAAC,qBAAqB,CAAA,CAAC,IAAI,oCAAI,qBAAqB,WAAE;YAC5E,CAAA,KAAA,KAAK,CAAC,gBAAgB,CAAC,wBAAwB,CAAA,CAAC,IAAI,oCAAI,wBAAwB,WAAE;SACrF;IACL,CAAC;IACL,kBAAC;AAAD,CAAC,AAnJD,IAmJC","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,13 +1,13 @@
|
|
|
1
1
|
import { addParser } from '../utils/addParser';
|
|
2
|
+
import { adjustPercentileLineHeight } from '../parsers/adjustPercentileLineHeightParser';
|
|
2
3
|
import { getStyleMetadata } from './getStyleMetadata';
|
|
3
4
|
import { getStyles } from '../utils/getStyles';
|
|
5
|
+
import { listLevelParser } from '../parsers/listLevelParser';
|
|
4
6
|
import { processWordComments } from './processWordComments';
|
|
5
7
|
import { processWordList } from './processWordLists';
|
|
6
8
|
import { removeNegativeTextIndentParser } from '../parsers/removeNegativeTextIndentParser';
|
|
7
9
|
import { setProcessor } from '../utils/setProcessor';
|
|
8
|
-
|
|
9
|
-
// Default line height in browsers according to https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#normal
|
|
10
|
-
var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 1.2;
|
|
10
|
+
import { wordTableParser } from '../parsers/wordTableParser';
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
|
13
13
|
* Handles Pasted content when source is Word Desktop
|
|
@@ -32,28 +32,4 @@ var wordDesktopElementProcessor = function (metadataKey) {
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
-
function adjustPercentileLineHeight(format, element) {
|
|
36
|
-
//If the line height is less than the browser default line height, line between the text is going to be too narrow
|
|
37
|
-
var parsedLineHeight;
|
|
38
|
-
if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
|
|
39
|
-
!isNaN((parsedLineHeight = parseInt(element.style.lineHeight)))) {
|
|
40
|
-
format.lineHeight = (DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE *
|
|
41
|
-
(parsedLineHeight / 100)).toString();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
var listLevelParser = function (format, element, _context, defaultStyle) {
|
|
45
|
-
if (element.style.marginLeft != '') {
|
|
46
|
-
format.marginLeft = defaultStyle.marginLeft;
|
|
47
|
-
}
|
|
48
|
-
format.marginBottom = undefined;
|
|
49
|
-
};
|
|
50
|
-
var wordTableParser = function (format, element) {
|
|
51
|
-
var _a;
|
|
52
|
-
if ((_a = format.marginLeft) === null || _a === void 0 ? void 0 : _a.startsWith('-')) {
|
|
53
|
-
delete format.marginLeft;
|
|
54
|
-
}
|
|
55
|
-
if (format.htmlAlign) {
|
|
56
|
-
delete format.htmlAlign;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
35
|
//# 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":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,S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AO,CAAC,CAAC;QAClC,4FAA4F;QAC5F,IACI,CAAC,CACG,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC;YAC7D,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CACvC,EACH;YACE,OAAO,CAAC,wBAAwB,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;SACrE;IACL,CAAC,CAAC;AACN,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"]}
|