roosterjs-content-model-plugins 0.21.2 → 0.21.4
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/edit/ContentModelEditPlugin.d.ts +35 -35
- package/lib/edit/ContentModelEditPlugin.js +75 -75
- package/lib/edit/ContentModelEditPlugin.js.map +1 -1
- package/lib/edit/deleteSteps/deleteAllSegmentBefore.d.ts +5 -5
- package/lib/edit/deleteSteps/deleteAllSegmentBefore.js +19 -19
- package/lib/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib/edit/deleteSteps/deleteCollapsedSelection.d.ts +9 -9
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js +90 -90
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib/edit/deleteSteps/deleteWordSelection.d.ts +9 -9
- package/lib/edit/deleteSteps/deleteWordSelection.js +170 -170
- package/lib/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib/edit/handleKeyboardEventCommon.d.ts +15 -15
- package/lib/edit/handleKeyboardEventCommon.js +54 -54
- package/lib/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib/edit/keyboardDelete.d.ts +8 -8
- package/lib/edit/keyboardDelete.js +67 -67
- package/lib/edit/keyboardDelete.js.map +1 -1
- package/lib/edit/keyboardInput.d.ts +5 -5
- package/lib/edit/keyboardInput.js +50 -49
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/edit/utils/getLeafSiblingBlock.d.ts +23 -23
- package/lib/edit/utils/getLeafSiblingBlock.js +75 -75
- package/lib/edit/utils/getLeafSiblingBlock.js.map +1 -1
- package/lib/entityDelimiter/EntityDelimiterPlugin.d.ts +35 -35
- package/lib/entityDelimiter/EntityDelimiterPlugin.js +256 -254
- package/lib/entityDelimiter/EntityDelimiterPlugin.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +9 -9
- package/lib/index.js.map +1 -1
- package/lib/paste/ContentModelPastePlugin.d.ts +42 -42
- package/lib/paste/ContentModelPastePlugin.js +148 -148
- package/lib/paste/ContentModelPastePlugin.js.map +1 -1
- package/lib/paste/Excel/processPastedContentFromExcel.d.ts +13 -13
- package/lib/paste/Excel/processPastedContentFromExcel.js +82 -82
- package/lib/paste/Excel/processPastedContentFromExcel.js.map +1 -1
- package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +7 -7
- package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js +19 -19
- package/lib/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
- package/lib/paste/WacComponents/processPastedContentWacComponents.d.ts +9 -9
- package/lib/paste/WacComponents/processPastedContentWacComponents.js +207 -207
- package/lib/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +12 -12
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +69 -69
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib/paste/WordDesktop/processWordComments.d.ts +7 -7
- package/lib/paste/WordDesktop/processWordComments.js +21 -21
- package/lib/paste/WordDesktop/processWordComments.js.map +1 -1
- package/lib/paste/WordDesktop/processWordLists.d.ts +10 -10
- package/lib/paste/WordDesktop/processWordLists.js +154 -154
- package/lib/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib/paste/pasteSourceValidations/constants.d.ts +17 -17
- package/lib/paste/pasteSourceValidations/constants.js +21 -21
- package/lib/paste/pasteSourceValidations/constants.js.map +1 -1
- package/lib/paste/pasteSourceValidations/documentContainWacElements.d.ts +8 -8
- package/lib/paste/pasteSourceValidations/documentContainWacElements.js +24 -24
- package/lib/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -1
- package/lib/paste/pasteSourceValidations/getPasteSource.d.ts +27 -27
- package/lib/paste/pasteSourceValidations/getPasteSource.js +43 -43
- package/lib/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
- package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.d.ts +8 -8
- package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.js +16 -16
- package/lib/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -1
- package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.d.ts +8 -8
- package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.js +18 -18
- package/lib/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -1
- package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.d.ts +8 -8
- package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.js +14 -14
- package/lib/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -1
- package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.d.ts +8 -8
- package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +14 -14
- package/lib/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -1
- package/lib/paste/pasteSourceValidations/isWordDesktopDocument.d.ts +8 -8
- package/lib/paste/pasteSourceValidations/isWordDesktopDocument.js +18 -18
- package/lib/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -1
- package/lib/paste/pasteSourceValidations/shouldConvertToSingleImage.d.ts +9 -9
- package/lib/paste/pasteSourceValidations/shouldConvertToSingleImage.js +18 -18
- package/lib/paste/pasteSourceValidations/shouldConvertToSingleImage.js.map +1 -1
- package/lib/paste/utils/addParser.d.ts +5 -5
- package/lib/paste/utils/addParser.js +16 -16
- package/lib/paste/utils/addParser.js.map +1 -1
- package/lib/paste/utils/deprecatedColorParser.d.ts +5 -5
- package/lib/paste/utils/deprecatedColorParser.js +19 -19
- package/lib/paste/utils/deprecatedColorParser.js.map +1 -1
- package/lib/paste/utils/getStyles.d.ts +6 -6
- package/lib/paste/utils/getStyles.js +22 -22
- package/lib/paste/utils/getStyles.js.map +1 -1
- package/lib/paste/utils/linkParser.d.ts +5 -5
- package/lib/paste/utils/linkParser.js +27 -27
- package/lib/paste/utils/linkParser.js.map +1 -1
- package/lib/paste/utils/setProcessor.d.ts +5 -5
- package/lib/paste/utils/setProcessor.js +13 -13
- package/lib/paste/utils/setProcessor.js.map +1 -1
- package/lib-amd/edit/ContentModelEditPlugin.d.ts +35 -35
- package/lib-amd/edit/ContentModelEditPlugin.js +75 -75
- package/lib-amd/edit/ContentModelEditPlugin.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.d.ts +5 -5
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js +20 -20
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.d.ts +9 -9
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js +89 -89
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteWordSelection.d.ts +9 -9
- package/lib-amd/edit/deleteSteps/deleteWordSelection.js +169 -169
- package/lib-amd/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib-amd/edit/handleKeyboardEventCommon.d.ts +15 -15
- package/lib-amd/edit/handleKeyboardEventCommon.js +55 -55
- package/lib-amd/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib-amd/edit/keyboardDelete.d.ts +8 -8
- package/lib-amd/edit/keyboardDelete.js +63 -63
- package/lib-amd/edit/keyboardDelete.js.map +1 -1
- package/lib-amd/edit/keyboardInput.d.ts +5 -5
- package/lib-amd/edit/keyboardInput.js +50 -49
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/edit/utils/getLeafSiblingBlock.d.ts +23 -23
- package/lib-amd/edit/utils/getLeafSiblingBlock.js +75 -75
- package/lib-amd/edit/utils/getLeafSiblingBlock.js.map +1 -1
- package/lib-amd/entityDelimiter/EntityDelimiterPlugin.d.ts +35 -35
- package/lib-amd/entityDelimiter/EntityDelimiterPlugin.js +255 -253
- package/lib-amd/entityDelimiter/EntityDelimiterPlugin.js.map +1 -1
- package/lib-amd/index.d.ts +3 -3
- package/lib-amd/index.js +8 -8
- package/lib-amd/index.js.map +1 -1
- package/lib-amd/paste/ContentModelPastePlugin.d.ts +42 -42
- package/lib-amd/paste/ContentModelPastePlugin.js +140 -140
- package/lib-amd/paste/ContentModelPastePlugin.js.map +1 -1
- package/lib-amd/paste/Excel/processPastedContentFromExcel.d.ts +13 -13
- package/lib-amd/paste/Excel/processPastedContentFromExcel.js +80 -80
- package/lib-amd/paste/Excel/processPastedContentFromExcel.js.map +1 -1
- package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +7 -7
- package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js +20 -20
- package/lib-amd/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.d.ts +9 -9
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js +206 -206
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +12 -12
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +64 -64
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-amd/paste/WordDesktop/processWordComments.d.ts +7 -7
- package/lib-amd/paste/WordDesktop/processWordComments.js +22 -22
- package/lib-amd/paste/WordDesktop/processWordComments.js.map +1 -1
- package/lib-amd/paste/WordDesktop/processWordLists.d.ts +10 -10
- package/lib-amd/paste/WordDesktop/processWordLists.js +153 -153
- package/lib-amd/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/constants.d.ts +17 -17
- package/lib-amd/paste/pasteSourceValidations/constants.js +23 -23
- package/lib-amd/paste/pasteSourceValidations/constants.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.d.ts +8 -8
- package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.js +26 -26
- package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/getPasteSource.d.ts +27 -27
- package/lib-amd/paste/pasteSourceValidations/getPasteSource.js +38 -38
- package/lib-amd/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.d.ts +8 -8
- package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.js +18 -18
- package/lib-amd/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.d.ts +8 -8
- package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.js +20 -20
- package/lib-amd/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.d.ts +8 -8
- package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.js +16 -16
- package/lib-amd/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.d.ts +8 -8
- package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +16 -16
- package/lib-amd/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.d.ts +8 -8
- package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.js +20 -20
- package/lib-amd/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/shouldConvertToSingleImage.d.ts +9 -9
- package/lib-amd/paste/pasteSourceValidations/shouldConvertToSingleImage.js +20 -20
- package/lib-amd/paste/pasteSourceValidations/shouldConvertToSingleImage.js.map +1 -1
- package/lib-amd/paste/utils/addParser.d.ts +5 -5
- package/lib-amd/paste/utils/addParser.js +18 -18
- package/lib-amd/paste/utils/addParser.js.map +1 -1
- package/lib-amd/paste/utils/deprecatedColorParser.d.ts +5 -5
- package/lib-amd/paste/utils/deprecatedColorParser.js +20 -20
- package/lib-amd/paste/utils/deprecatedColorParser.js.map +1 -1
- package/lib-amd/paste/utils/getStyles.d.ts +6 -6
- package/lib-amd/paste/utils/getStyles.js +24 -24
- package/lib-amd/paste/utils/getStyles.js.map +1 -1
- package/lib-amd/paste/utils/linkParser.d.ts +5 -5
- package/lib-amd/paste/utils/linkParser.js +28 -28
- package/lib-amd/paste/utils/linkParser.js.map +1 -1
- package/lib-amd/paste/utils/setProcessor.d.ts +5 -5
- package/lib-amd/paste/utils/setProcessor.js +15 -15
- package/lib-amd/paste/utils/setProcessor.js.map +1 -1
- package/lib-mjs/edit/ContentModelEditPlugin.d.ts +35 -35
- package/lib-mjs/edit/ContentModelEditPlugin.js +72 -72
- package/lib-mjs/edit/ContentModelEditPlugin.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.d.ts +5 -5
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js +15 -15
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.d.ts +9 -9
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js +87 -87
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.d.ts +9 -9
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.js +167 -167
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib-mjs/edit/handleKeyboardEventCommon.d.ts +15 -15
- package/lib-mjs/edit/handleKeyboardEventCommon.js +48 -48
- package/lib-mjs/edit/handleKeyboardEventCommon.js.map +1 -1
- package/lib-mjs/edit/keyboardDelete.d.ts +8 -8
- package/lib-mjs/edit/keyboardDelete.js +63 -63
- package/lib-mjs/edit/keyboardDelete.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.d.ts +5 -5
- package/lib-mjs/edit/keyboardInput.js +46 -45
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/edit/utils/getLeafSiblingBlock.d.ts +23 -23
- package/lib-mjs/edit/utils/getLeafSiblingBlock.js +71 -71
- package/lib-mjs/edit/utils/getLeafSiblingBlock.js.map +1 -1
- package/lib-mjs/entityDelimiter/EntityDelimiterPlugin.d.ts +35 -35
- package/lib-mjs/entityDelimiter/EntityDelimiterPlugin.js +252 -250
- package/lib-mjs/entityDelimiter/EntityDelimiterPlugin.js.map +1 -1
- package/lib-mjs/index.d.ts +3 -3
- package/lib-mjs/index.js +3 -3
- package/lib-mjs/index.js.map +1 -1
- package/lib-mjs/paste/ContentModelPastePlugin.d.ts +42 -42
- package/lib-mjs/paste/ContentModelPastePlugin.js +145 -145
- package/lib-mjs/paste/ContentModelPastePlugin.js.map +1 -1
- package/lib-mjs/paste/Excel/processPastedContentFromExcel.d.ts +13 -13
- package/lib-mjs/paste/Excel/processPastedContentFromExcel.js +77 -77
- package/lib-mjs/paste/Excel/processPastedContentFromExcel.js.map +1 -1
- package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.d.ts +7 -7
- package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js +15 -15
- package/lib-mjs/paste/PowerPoint/processPastedContentFromPowerPoint.js.map +1 -1
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.d.ts +9 -9
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js +203 -203
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +12 -12
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +64 -64
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/processWordComments.d.ts +7 -7
- package/lib-mjs/paste/WordDesktop/processWordComments.js +17 -17
- package/lib-mjs/paste/WordDesktop/processWordComments.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/processWordLists.d.ts +10 -10
- package/lib-mjs/paste/WordDesktop/processWordLists.js +150 -150
- package/lib-mjs/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/constants.d.ts +17 -17
- package/lib-mjs/paste/pasteSourceValidations/constants.js +18 -18
- package/lib-mjs/paste/pasteSourceValidations/constants.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.d.ts +8 -8
- package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.js +20 -20
- package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/getPasteSource.d.ts +27 -27
- package/lib-mjs/paste/pasteSourceValidations/getPasteSource.js +39 -39
- package/lib-mjs/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.d.ts +8 -8
- package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.js +12 -12
- package/lib-mjs/paste/pasteSourceValidations/isExcelDesktopDocument.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.d.ts +8 -8
- package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.js +14 -14
- package/lib-mjs/paste/pasteSourceValidations/isExcelOnlineDocument.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.d.ts +8 -8
- package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.js +10 -10
- package/lib-mjs/paste/pasteSourceValidations/isGoogleSheetDocument.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.d.ts +8 -8
- package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.js +10 -10
- package/lib-mjs/paste/pasteSourceValidations/isPowerPointDesktopDocument.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.d.ts +8 -8
- package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.js +14 -14
- package/lib-mjs/paste/pasteSourceValidations/isWordDesktopDocument.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/shouldConvertToSingleImage.d.ts +9 -9
- package/lib-mjs/paste/pasteSourceValidations/shouldConvertToSingleImage.js +14 -14
- package/lib-mjs/paste/pasteSourceValidations/shouldConvertToSingleImage.js.map +1 -1
- package/lib-mjs/paste/utils/addParser.d.ts +5 -5
- package/lib-mjs/paste/utils/addParser.js +13 -13
- package/lib-mjs/paste/utils/addParser.js.map +1 -1
- package/lib-mjs/paste/utils/deprecatedColorParser.d.ts +5 -5
- package/lib-mjs/paste/utils/deprecatedColorParser.js +15 -15
- package/lib-mjs/paste/utils/deprecatedColorParser.js.map +1 -1
- package/lib-mjs/paste/utils/getStyles.d.ts +6 -6
- package/lib-mjs/paste/utils/getStyles.js +18 -18
- package/lib-mjs/paste/utils/getStyles.js.map +1 -1
- package/lib-mjs/paste/utils/linkParser.d.ts +5 -5
- package/lib-mjs/paste/utils/linkParser.js +23 -23
- package/lib-mjs/paste/utils/linkParser.js.map +1 -1
- package/lib-mjs/paste/utils/setProcessor.d.ts +5 -5
- package/lib-mjs/paste/utils/setProcessor.js +9 -9
- package/lib-mjs/paste/utils/setProcessor.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import addParser from '../utils/addParser';
|
|
2
|
-
import { chainSanitizerCallback } from 'roosterjs-editor-dom';
|
|
3
|
-
import { getStyles } from '../utils/getStyles';
|
|
4
|
-
import { moveChildNodes } from 'roosterjs-content-model-dom';
|
|
5
|
-
import { processWordComments } from './processWordComments';
|
|
6
|
-
import { processWordList } from './processWordLists';
|
|
7
|
-
import { setProcessor } from '../utils/setProcessor';
|
|
8
|
-
var PERCENTAGE_REGEX = /%/;
|
|
9
|
-
var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 120;
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
* Handles Pasted content when source is Word Desktop
|
|
13
|
-
* @param ev ContentModelBeforePasteEvent
|
|
14
|
-
*/
|
|
15
|
-
export function processPastedContentFromWordDesktop(ev) {
|
|
16
|
-
setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor);
|
|
17
|
-
addParser(ev.domToModelOption, 'block', removeNonValidLineHeight);
|
|
18
|
-
addParser(ev.domToModelOption, 'listLevel', listLevelParser);
|
|
19
|
-
addParser(ev.domToModelOption, 'listItemElement', listItemElementParser);
|
|
20
|
-
// Remove "border:none" for image to fix image resize behavior
|
|
21
|
-
// We found a problem that when paste an image with "border:none" then the resize border will be
|
|
22
|
-
// displayed incorrectly when resize it. So we need to drop this style
|
|
23
|
-
chainSanitizerCallback(ev.sanitizingOption.cssStyleCallbacks, 'border', function (value, element) { return element.tagName != 'IMG' || value != 'none'; });
|
|
24
|
-
// Preserve <o:p> when its innerHTML is " " to avoid dropping an empty line
|
|
25
|
-
chainSanitizerCallback(ev.sanitizingOption.elementCallbacks, 'O:P', function (element) {
|
|
26
|
-
moveChildNodes(element);
|
|
27
|
-
element.appendChild(element.ownerDocument.createTextNode('\u00A0')); //
|
|
28
|
-
return true;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @internal
|
|
33
|
-
* Exported only for unit test
|
|
34
|
-
*/
|
|
35
|
-
export var wordDesktopElementProcessor = function (group, element, context) {
|
|
36
|
-
var styles = getStyles(element);
|
|
37
|
-
// Process Word Lists or Word Commands, otherwise use the default processor on this element.
|
|
38
|
-
if (!(processWordList(styles, group, element, context) || processWordComments(styles, element))) {
|
|
39
|
-
context.defaultElementProcessors.element(group, element, context);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
function removeNonValidLineHeight(format, element, context, defaultStyle) {
|
|
43
|
-
//If the line height is less than the browser default line height, line between the text is going to be too narrow
|
|
44
|
-
var parsedLineHeight;
|
|
45
|
-
if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
|
|
46
|
-
!isNaN((parsedLineHeight = parseInt(element.style.lineHeight))) &&
|
|
47
|
-
parsedLineHeight < DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE) {
|
|
48
|
-
format.lineHeight = defaultStyle.lineHeight;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function listLevelParser(format, element, context, defaultStyle) {
|
|
52
|
-
if (element.style.marginLeft != '') {
|
|
53
|
-
format.marginLeft = defaultStyle.marginLeft;
|
|
54
|
-
}
|
|
55
|
-
format.marginBottom = undefined;
|
|
56
|
-
}
|
|
57
|
-
var listItemElementParser = function (format, element) {
|
|
58
|
-
if (element.style.marginLeft) {
|
|
59
|
-
format.marginLeft = undefined;
|
|
60
|
-
}
|
|
61
|
-
if (element.style.marginRight) {
|
|
62
|
-
format.marginRight = undefined;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
1
|
+
import addParser from '../utils/addParser';
|
|
2
|
+
import { chainSanitizerCallback } from 'roosterjs-editor-dom';
|
|
3
|
+
import { getStyles } from '../utils/getStyles';
|
|
4
|
+
import { moveChildNodes } from 'roosterjs-content-model-dom';
|
|
5
|
+
import { processWordComments } from './processWordComments';
|
|
6
|
+
import { processWordList } from './processWordLists';
|
|
7
|
+
import { setProcessor } from '../utils/setProcessor';
|
|
8
|
+
var PERCENTAGE_REGEX = /%/;
|
|
9
|
+
var DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 120;
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
* Handles Pasted content when source is Word Desktop
|
|
13
|
+
* @param ev ContentModelBeforePasteEvent
|
|
14
|
+
*/
|
|
15
|
+
export function processPastedContentFromWordDesktop(ev) {
|
|
16
|
+
setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor);
|
|
17
|
+
addParser(ev.domToModelOption, 'block', removeNonValidLineHeight);
|
|
18
|
+
addParser(ev.domToModelOption, 'listLevel', listLevelParser);
|
|
19
|
+
addParser(ev.domToModelOption, 'listItemElement', listItemElementParser);
|
|
20
|
+
// Remove "border:none" for image to fix image resize behavior
|
|
21
|
+
// We found a problem that when paste an image with "border:none" then the resize border will be
|
|
22
|
+
// displayed incorrectly when resize it. So we need to drop this style
|
|
23
|
+
chainSanitizerCallback(ev.sanitizingOption.cssStyleCallbacks, 'border', function (value, element) { return element.tagName != 'IMG' || value != 'none'; });
|
|
24
|
+
// Preserve <o:p> when its innerHTML is " " to avoid dropping an empty line
|
|
25
|
+
chainSanitizerCallback(ev.sanitizingOption.elementCallbacks, 'O:P', function (element) {
|
|
26
|
+
moveChildNodes(element);
|
|
27
|
+
element.appendChild(element.ownerDocument.createTextNode('\u00A0')); //
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
* Exported only for unit test
|
|
34
|
+
*/
|
|
35
|
+
export var wordDesktopElementProcessor = function (group, element, context) {
|
|
36
|
+
var styles = getStyles(element);
|
|
37
|
+
// Process Word Lists or Word Commands, otherwise use the default processor on this element.
|
|
38
|
+
if (!(processWordList(styles, group, element, context) || processWordComments(styles, element))) {
|
|
39
|
+
context.defaultElementProcessors.element(group, element, context);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
function removeNonValidLineHeight(format, element, context, defaultStyle) {
|
|
43
|
+
//If the line height is less than the browser default line height, line between the text is going to be too narrow
|
|
44
|
+
var parsedLineHeight;
|
|
45
|
+
if (PERCENTAGE_REGEX.test(element.style.lineHeight) &&
|
|
46
|
+
!isNaN((parsedLineHeight = parseInt(element.style.lineHeight))) &&
|
|
47
|
+
parsedLineHeight < DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE) {
|
|
48
|
+
format.lineHeight = defaultStyle.lineHeight;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function listLevelParser(format, element, context, defaultStyle) {
|
|
52
|
+
if (element.style.marginLeft != '') {
|
|
53
|
+
format.marginLeft = defaultStyle.marginLeft;
|
|
54
|
+
}
|
|
55
|
+
format.marginBottom = undefined;
|
|
56
|
+
}
|
|
57
|
+
var listItemElementParser = function (format, element) {
|
|
58
|
+
if (element.style.marginLeft) {
|
|
59
|
+
format.marginLeft = undefined;
|
|
60
|
+
}
|
|
61
|
+
if (element.style.marginRight) {
|
|
62
|
+
format.marginRight = undefined;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
65
|
//# sourceMappingURL=processPastedContentFromWordDesktop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD,IAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,IAAM,sCAAsC,GAAG,GAAG,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CAAC,EAAgC;IAChF,YAAY,CAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,2BAA2B,CAAC,CAAC;IAC1E,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAAC;IAClE,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC7D,SAAS,CAAC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gB,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;QAC/D,gBAAgB,GAAG,sCAAsC,EAC3D;QACE,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;KAC/C;AACL,CAAC;AAED,SAAS,eAAe,CACpB,MAAuC,EACvC,OAAoB,EACpB,OAA0B,EAC1B,YAAoD;IAEpD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;QAChC,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;KAC/C;IAED,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;AACpC,CAAC;AAED,IAAM,qBAAqB,GAA6C,UACpE,MAAkC,EAClC,OAAoB;IAEpB,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE;QAC1B,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;KACjC;IACD,IAAI,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE;QAC3B,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC;KAClC;AACL,CAAC,CAAC","sourcesContent":["import addParser from '../utils/addParser';\nimport { chainSanitizerCallback } from 'roosterjs-editor-dom';\nimport { getStyles } from '../utils/getStyles';\nimport { moveChildNodes } from 'roosterjs-content-model-dom';\nimport { processWordComments } from './processWordComments';\nimport { processWordList } from './processWordLists';\nimport { setProcessor } from '../utils/setProcessor';\nimport type {\n ContentModelBeforePasteEvent,\n ContentModelBlockFormat,\n ContentModelListItemFormat,\n ContentModelListItemLevelFormat,\n DomToModelContext,\n ElementProcessor,\n FormatParser,\n} from 'roosterjs-content-model-types';\n\nconst PERCENTAGE_REGEX = /%/;\nconst DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 120;\n\n/**\n * @internal\n * Handles Pasted content when source is Word Desktop\n * @param ev ContentModelBeforePasteEvent\n */\nexport function processPastedContentFromWordDesktop(ev: ContentModelBeforePasteEvent) {\n setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor);\n addParser(ev.domToModelOption, 'block', removeNonValidLineHeight);\n addParser(ev.domToModelOption, 'listLevel', listLevelParser);\n addParser(ev.domToModelOption, 'listItemElement', listItemElementParser);\n\n // Remove \"border:none\" for image to fix image resize behavior\n // We found a problem that when paste an image with \"border:none\" then the resize border will be\n // displayed incorrectly when resize it. So we need to drop this style\n chainSanitizerCallback(\n ev.sanitizingOption.cssStyleCallbacks,\n 'border',\n (value, element) => element.tagName != 'IMG' || value != 'none'\n );\n\n // Preserve <o:p> when its innerHTML is \" \" to avoid dropping an empty line\n chainSanitizerCallback(ev.sanitizingOption.elementCallbacks, 'O:P', element => {\n moveChildNodes(element);\n element.appendChild(element.ownerDocument.createTextNode('\\u00A0')); // \n return true;\n });\n}\n\n/**\n * @internal\n * Exported only for unit test\n */\nexport const wordDesktopElementProcessor: ElementProcessor<HTMLElement> = (\n group,\n element,\n context\n) => {\n const styles = getStyles(element);\n // Process Word Lists or Word Commands, otherwise use the default processor on this element.\n if (\n !(processWordList(styles, group, element, context) || processWordComments(styles, element))\n ) {\n context.defaultElementProcessors.element(group, element, context);\n }\n};\n\nfunction removeNonValidLineHeight(\n format: ContentModelBlockFormat,\n element: HTMLElement,\n context: DomToModelContext,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>\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 parsedLineHeight < DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE\n ) {\n format.lineHeight = defaultStyle.lineHeight;\n }\n}\n\nfunction listLevelParser(\n format: ContentModelListItemLevelFormat,\n element: HTMLElement,\n context: DomToModelContext,\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>\n): void {\n if (element.style.marginLeft != '') {\n format.marginLeft = defaultStyle.marginLeft;\n }\n\n format.marginBottom = undefined;\n}\n\nconst listItemElementParser: FormatParser<ContentModelListItemFormat> = (\n format: ContentModelListItemFormat,\n element: HTMLElement\n): void => {\n if (element.style.marginLeft) {\n format.marginLeft = undefined;\n }\n if (element.style.marginRight) {\n format.marginRight = undefined;\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"processPastedContentFromWordDesktop.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAWrD,IAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,IAAM,sCAAsC,GAAG,GAAG,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CAAC,EAAgC;IAChF,YAAY,CAAC,EAAE,CAAC,gBAAgB,EAAE,SAAS,EAAE,2BAA2B,CAAC,CAAC;IAC1E,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAAC;IAClE,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC7D,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB,CAAC,CAAC;IAEzE,8DAA8D;IAC9D,gGAAgG;IAChG,sEAAsE;IACtE,sBAAsB,CAClB,EAAE,CAAC,gBAAgB,CAAC,iBAAiB,EACrC,QAAQ,EACR,UAAC,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S,eAAe,CACpB,MAAuC,EACvC,OAAoB,EACpB,OAA0B,EAC1B,YAAoD;IAEpD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;QAChC,MAAM,CAAC,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;KAC/C;IAED,MAAM,CAAC,YAAY,GAAG,SAAS,CAAC;AACpC,CAAC;AAED,IAAM,qBAAqB,GAA6C,UACpE,MAAkC,EAClC,OAAoB;IAEpB,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE;QAC1B,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;KACjC;IACD,IAAI,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE;QAC3B,MAAM,CAAC,WAAW,GAAG,SAAS,CAAC;KAClC;AACL,CAAC,CAAC","sourcesContent":["import addParser from '../utils/addParser';\r\nimport { chainSanitizerCallback } from 'roosterjs-editor-dom';\r\nimport { getStyles } from '../utils/getStyles';\r\nimport { moveChildNodes } from 'roosterjs-content-model-dom';\r\nimport { processWordComments } from './processWordComments';\r\nimport { processWordList } from './processWordLists';\r\nimport { setProcessor } from '../utils/setProcessor';\r\nimport type {\r\n ContentModelBeforePasteEvent,\r\n ContentModelBlockFormat,\r\n ContentModelListItemFormat,\r\n ContentModelListItemLevelFormat,\r\n DomToModelContext,\r\n ElementProcessor,\r\n FormatParser,\r\n} from 'roosterjs-content-model-types';\r\n\r\nconst PERCENTAGE_REGEX = /%/;\r\nconst DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE = 120;\r\n\r\n/**\r\n * @internal\r\n * Handles Pasted content when source is Word Desktop\r\n * @param ev ContentModelBeforePasteEvent\r\n */\r\nexport function processPastedContentFromWordDesktop(ev: ContentModelBeforePasteEvent) {\r\n setProcessor(ev.domToModelOption, 'element', wordDesktopElementProcessor);\r\n addParser(ev.domToModelOption, 'block', removeNonValidLineHeight);\r\n addParser(ev.domToModelOption, 'listLevel', listLevelParser);\r\n addParser(ev.domToModelOption, 'listItemElement', listItemElementParser);\r\n\r\n // Remove \"border:none\" for image to fix image resize behavior\r\n // We found a problem that when paste an image with \"border:none\" then the resize border will be\r\n // displayed incorrectly when resize it. So we need to drop this style\r\n chainSanitizerCallback(\r\n ev.sanitizingOption.cssStyleCallbacks,\r\n 'border',\r\n (value, element) => element.tagName != 'IMG' || value != 'none'\r\n );\r\n\r\n // Preserve <o:p> when its innerHTML is \" \" to avoid dropping an empty line\r\n chainSanitizerCallback(ev.sanitizingOption.elementCallbacks, 'O:P', element => {\r\n moveChildNodes(element);\r\n element.appendChild(element.ownerDocument.createTextNode('\\u00A0')); // \r\n return true;\r\n });\r\n}\r\n\r\n/**\r\n * @internal\r\n * Exported only for unit test\r\n */\r\nexport const wordDesktopElementProcessor: ElementProcessor<HTMLElement> = (\r\n group,\r\n element,\r\n context\r\n) => {\r\n const styles = getStyles(element);\r\n // Process Word Lists or Word Commands, otherwise use the default processor on this element.\r\n if (\r\n !(processWordList(styles, group, element, context) || processWordComments(styles, element))\r\n ) {\r\n context.defaultElementProcessors.element(group, element, context);\r\n }\r\n};\r\n\r\nfunction removeNonValidLineHeight(\r\n format: ContentModelBlockFormat,\r\n element: HTMLElement,\r\n context: DomToModelContext,\r\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>\r\n): void {\r\n //If the line height is less than the browser default line height, line between the text is going to be too narrow\r\n let parsedLineHeight: number;\r\n if (\r\n PERCENTAGE_REGEX.test(element.style.lineHeight) &&\r\n !isNaN((parsedLineHeight = parseInt(element.style.lineHeight))) &&\r\n parsedLineHeight < DEFAULT_BROWSER_LINE_HEIGHT_PERCENTAGE\r\n ) {\r\n format.lineHeight = defaultStyle.lineHeight;\r\n }\r\n}\r\n\r\nfunction listLevelParser(\r\n format: ContentModelListItemLevelFormat,\r\n element: HTMLElement,\r\n context: DomToModelContext,\r\n defaultStyle: Readonly<Partial<CSSStyleDeclaration>>\r\n): void {\r\n if (element.style.marginLeft != '') {\r\n format.marginLeft = defaultStyle.marginLeft;\r\n }\r\n\r\n format.marginBottom = undefined;\r\n}\r\n\r\nconst listItemElementParser: FormatParser<ContentModelListItemFormat> = (\r\n format: ContentModelListItemFormat,\r\n element: HTMLElement\r\n): void => {\r\n if (element.style.marginLeft) {\r\n format.marginLeft = undefined;\r\n }\r\n if (element.style.marginRight) {\r\n format.marginRight = undefined;\r\n }\r\n};\r\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
* Check whether the element contain Word attributes related to comments and if it does we should no process
|
|
4
|
-
* this element.
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare function processWordComments(styles: Record<string, string>, element: HTMLElement): boolean;
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
* Check whether the element contain Word attributes related to comments and if it does we should no process
|
|
4
|
+
* this element.
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function processWordComments(styles: Record<string, string>, element: HTMLElement): boolean;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { isElementOfType } from 'roosterjs-content-model-dom';
|
|
2
|
-
var MSO_COMMENT_ANCHOR_HREF_REGEX = /#_msocom_/;
|
|
3
|
-
var MSO_SPECIAL_CHARACTER = 'mso-special-character';
|
|
4
|
-
var MSO_SPECIAL_CHARACTER_COMMENT = 'comment';
|
|
5
|
-
var MSO_ELEMENT = 'mso-element';
|
|
6
|
-
var MSO_ELEMENT_COMMENT_LIST = 'comment-list';
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
* Check whether the element contain Word attributes related to comments and if it does we should no process
|
|
10
|
-
* this element.
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export function processWordComments(styles, element) {
|
|
14
|
-
return (styles[MSO_SPECIAL_CHARACTER] == MSO_SPECIAL_CHARACTER_COMMENT ||
|
|
15
|
-
(isElementOfType(element, 'a') && MSO_COMMENT_ANCHOR_HREF_REGEX.test(element.href)) ||
|
|
16
|
-
styles[MSO_ELEMENT] == MSO_ELEMENT_COMMENT_LIST);
|
|
17
|
-
}
|
|
1
|
+
import { isElementOfType } from 'roosterjs-content-model-dom';
|
|
2
|
+
var MSO_COMMENT_ANCHOR_HREF_REGEX = /#_msocom_/;
|
|
3
|
+
var MSO_SPECIAL_CHARACTER = 'mso-special-character';
|
|
4
|
+
var MSO_SPECIAL_CHARACTER_COMMENT = 'comment';
|
|
5
|
+
var MSO_ELEMENT = 'mso-element';
|
|
6
|
+
var MSO_ELEMENT_COMMENT_LIST = 'comment-list';
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
* Check whether the element contain Word attributes related to comments and if it does we should no process
|
|
10
|
+
* this element.
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export function processWordComments(styles, element) {
|
|
14
|
+
return (styles[MSO_SPECIAL_CHARACTER] == MSO_SPECIAL_CHARACTER_COMMENT ||
|
|
15
|
+
(isElementOfType(element, 'a') && MSO_COMMENT_ANCHOR_HREF_REGEX.test(element.href)) ||
|
|
16
|
+
styles[MSO_ELEMENT] == MSO_ELEMENT_COMMENT_LIST);
|
|
17
|
+
}
|
|
18
18
|
//# sourceMappingURL=processWordComments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processWordComments.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WordDesktop/processWordComments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,IAAM,6BAA6B,GAAG,WAAW,CAAC;AAClD,IAAM,qBAAqB,GAAG,uBAAuB,CAAC;AACtD,IAAM,6BAA6B,GAAG,SAAS,CAAC;AAChD,IAAM,WAAW,GAAG,aAAa,CAAC;AAClC,IAAM,wBAAwB,GAAG,cAAc,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA8B,EAAE,OAAoB;IACpF,OAAO,CACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,6BAA6B;QAC9D,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnF,MAAM,CAAC,WAAW,CAAC,IAAI,wBAAwB,CAClD,CAAC;AACN,CAAC","sourcesContent":["import { isElementOfType } from 'roosterjs-content-model-dom';\n\nconst MSO_COMMENT_ANCHOR_HREF_REGEX = /#_msocom_/;\nconst MSO_SPECIAL_CHARACTER = 'mso-special-character';\nconst MSO_SPECIAL_CHARACTER_COMMENT = 'comment';\nconst MSO_ELEMENT = 'mso-element';\nconst MSO_ELEMENT_COMMENT_LIST = 'comment-list';\n\n/**\n * @internal\n * Check whether the element contain Word attributes related to comments and if it does we should no process\n * this element.\n * @returns\n */\nexport function processWordComments(styles: Record<string, string>, element: HTMLElement) {\n return (\n styles[MSO_SPECIAL_CHARACTER] == MSO_SPECIAL_CHARACTER_COMMENT ||\n (isElementOfType(element, 'a') && MSO_COMMENT_ANCHOR_HREF_REGEX.test(element.href)) ||\n styles[MSO_ELEMENT] == MSO_ELEMENT_COMMENT_LIST\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"processWordComments.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WordDesktop/processWordComments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,IAAM,6BAA6B,GAAG,WAAW,CAAC;AAClD,IAAM,qBAAqB,GAAG,uBAAuB,CAAC;AACtD,IAAM,6BAA6B,GAAG,SAAS,CAAC;AAChD,IAAM,WAAW,GAAG,aAAa,CAAC;AAClC,IAAM,wBAAwB,GAAG,cAAc,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAA8B,EAAE,OAAoB;IACpF,OAAO,CACH,MAAM,CAAC,qBAAqB,CAAC,IAAI,6BAA6B;QAC9D,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnF,MAAM,CAAC,WAAW,CAAC,IAAI,wBAAwB,CAClD,CAAC;AACN,CAAC","sourcesContent":["import { isElementOfType } from 'roosterjs-content-model-dom';\r\n\r\nconst MSO_COMMENT_ANCHOR_HREF_REGEX = /#_msocom_/;\r\nconst MSO_SPECIAL_CHARACTER = 'mso-special-character';\r\nconst MSO_SPECIAL_CHARACTER_COMMENT = 'comment';\r\nconst MSO_ELEMENT = 'mso-element';\r\nconst MSO_ELEMENT_COMMENT_LIST = 'comment-list';\r\n\r\n/**\r\n * @internal\r\n * Check whether the element contain Word attributes related to comments and if it does we should no process\r\n * this element.\r\n * @returns\r\n */\r\nexport function processWordComments(styles: Record<string, string>, element: HTMLElement) {\r\n return (\r\n styles[MSO_SPECIAL_CHARACTER] == MSO_SPECIAL_CHARACTER_COMMENT ||\r\n (isElementOfType(element, 'a') && MSO_COMMENT_ANCHOR_HREF_REGEX.test(element.href)) ||\r\n styles[MSO_ELEMENT] == MSO_ELEMENT_COMMENT_LIST\r\n );\r\n}\r\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-content-model-types';
|
|
2
|
-
/**
|
|
3
|
-
* @internal
|
|
4
|
-
* @param styles
|
|
5
|
-
* @param group
|
|
6
|
-
* @param element
|
|
7
|
-
* @param context
|
|
8
|
-
* @returns
|
|
9
|
-
*/
|
|
10
|
-
export declare function processWordList(styles: Record<string, string>, group: ContentModelBlockGroup, element: HTMLElement, context: DomToModelContext): boolean;
|
|
1
|
+
import type { ContentModelBlockGroup, DomToModelContext } from 'roosterjs-content-model-types';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
* @param styles
|
|
5
|
+
* @param group
|
|
6
|
+
* @param element
|
|
7
|
+
* @param context
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function processWordList(styles: Record<string, string>, group: ContentModelBlockGroup, element: HTMLElement, context: DomToModelContext): boolean;
|
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
import { __read, __spreadArray } from "tslib";
|
|
2
|
-
import { getStyles } from '../utils/getStyles';
|
|
3
|
-
import { addBlock, createListItem, createListLevel, isNodeOfType, parseFormat, } from 'roosterjs-content-model-dom';
|
|
4
|
-
/** Word list metadata style name */
|
|
5
|
-
var MSO_LIST = 'mso-list';
|
|
6
|
-
var MSO_LIST_IGNORE = 'ignore';
|
|
7
|
-
var LOOKUP_DEPTH = 5;
|
|
8
|
-
var WORD_FIRST_LIST = 'l0';
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
* @param styles
|
|
12
|
-
* @param group
|
|
13
|
-
* @param element
|
|
14
|
-
* @param context
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
export function processWordList(styles, group, element, context) {
|
|
18
|
-
var listFormat = context.listFormat;
|
|
19
|
-
if (!listFormat.wordKnownLevels) {
|
|
20
|
-
listFormat.wordKnownLevels = new Map();
|
|
21
|
-
}
|
|
22
|
-
var wordListStyle = styles[MSO_LIST] || '';
|
|
23
|
-
// If the element contains Ignore style, do not process it,
|
|
24
|
-
// Usually this element contains the fake bullet used in Word Desktop.
|
|
25
|
-
if (wordListStyle.toLowerCase() === MSO_LIST_IGNORE) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
var listProps = wordListStyle.split(' ');
|
|
29
|
-
// Try get the list metadata from word, which follows this format: l1 level1 lfo2
|
|
30
|
-
// If we are able to get the level property means we can process this element to be a list
|
|
31
|
-
listFormat.wordLevel = listProps[1] && parseInt(listProps[1].substr('level'.length));
|
|
32
|
-
listFormat.wordList = listProps[0] || WORD_FIRST_LIST;
|
|
33
|
-
if (listFormat.levels.length == 0) {
|
|
34
|
-
listFormat.levels = listFormat.wordKnownLevels.get(listFormat.wordList) || [];
|
|
35
|
-
}
|
|
36
|
-
if (wordListStyle && group && typeof listFormat.wordLevel === 'number') {
|
|
37
|
-
var wordLevel = listFormat.wordLevel;
|
|
38
|
-
// Retrieve the Fake bullet on the element and also the list type
|
|
39
|
-
var fakeBullet = getFakeBulletText(element);
|
|
40
|
-
var listType = getFakeBulletTagName(fakeBullet);
|
|
41
|
-
// Create the new level of the list item and parse the format
|
|
42
|
-
var newLevel = createListLevel(listType);
|
|
43
|
-
parseFormat(element, context.formatParsers.listLevel, newLevel.format, context);
|
|
44
|
-
// If the list format is in a different level, update the array so we get the new item
|
|
45
|
-
// To be in the same level as the provided level metadata.
|
|
46
|
-
if (wordLevel > listFormat.levels.length) {
|
|
47
|
-
while (wordLevel != listFormat.levels.length) {
|
|
48
|
-
listFormat.levels.push(newLevel);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
listFormat.levels.splice(wordLevel, listFormat.levels.length - 1);
|
|
53
|
-
listFormat.levels[wordLevel - 1] = newLevel;
|
|
54
|
-
}
|
|
55
|
-
listFormat.listParent = group;
|
|
56
|
-
processAsListItem(listFormat, context, element, group, fakeBullet);
|
|
57
|
-
if (listFormat.levels.length > 0 &&
|
|
58
|
-
listFormat.wordKnownLevels.get(listFormat.wordList) != listFormat.levels) {
|
|
59
|
-
listFormat.wordKnownLevels.set(listFormat.wordList, __spreadArray([], __read(listFormat.levels), false));
|
|
60
|
-
}
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
function processAsListItem(listFormat, context, element, group, fakeBullet) {
|
|
66
|
-
var listItem = createListItem(listFormat.levels, context.segmentFormat);
|
|
67
|
-
var lastLevel = listItem.levels[listItem.levels.length - 1];
|
|
68
|
-
parseFormat(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);
|
|
69
|
-
parseFormat(element, context.formatParsers.listItemElement, listItem.format, context);
|
|
70
|
-
if ((lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.listType) == 'OL') {
|
|
71
|
-
parseFormat(element, [startNumberOverrideParser(fakeBullet)], listItem.levels[listItem.levels.length - 1].format, context);
|
|
72
|
-
}
|
|
73
|
-
context.elementProcessors.child(listItem, element, context);
|
|
74
|
-
addBlock(group, listItem);
|
|
75
|
-
}
|
|
76
|
-
function startNumberOverrideParser(fakeBullet) {
|
|
77
|
-
return function (format, _, context) {
|
|
78
|
-
var _a = context.listFormat, wordKnownLevels = _a.wordKnownLevels, wordLevel = _a.wordLevel, wordList = _a.wordList;
|
|
79
|
-
if (typeof wordLevel === 'number' && wordList) {
|
|
80
|
-
var start = parseInt(fakeBullet);
|
|
81
|
-
if (start != undefined && !isNaN(start) && !(wordKnownLevels === null || wordKnownLevels === void 0 ? void 0 : wordKnownLevels.has(wordList))) {
|
|
82
|
-
format.startNumberOverride = start;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check whether the string is a fake bullet from word Desktop
|
|
89
|
-
*/
|
|
90
|
-
function isFakeBullet(fakeBullet) {
|
|
91
|
-
return ['o', '·', '§', '-'].indexOf(fakeBullet) >= 0;
|
|
92
|
-
}
|
|
93
|
-
/** Given a fake bullet text, returns the type of list that should be used for it */
|
|
94
|
-
function getFakeBulletTagName(fakeBullet) {
|
|
95
|
-
return isFakeBullet(fakeBullet) ? 'UL' : 'OL';
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Finds the fake bullet text out of the specified node and returns it. For images, it will return
|
|
99
|
-
* a bullet string. If not found, it returns null...
|
|
100
|
-
*/
|
|
101
|
-
function getFakeBulletText(node, levels) {
|
|
102
|
-
var _a, _b;
|
|
103
|
-
// Word uses the following format for their bullets:
|
|
104
|
-
// <p style="mso-list:l1 level1 lfo2">
|
|
105
|
-
// <span style="...">
|
|
106
|
-
// <span style="mso-list:Ignore">1.<span style="..."> </span></span>
|
|
107
|
-
// </span>
|
|
108
|
-
// Content here...
|
|
109
|
-
// </p>
|
|
110
|
-
//
|
|
111
|
-
// Basically, we need to locate the mso-list:Ignore SPAN, which holds either one text or image node. That
|
|
112
|
-
// text or image node will be the fake bullet we are looking for
|
|
113
|
-
var result = '';
|
|
114
|
-
levels = levels || LOOKUP_DEPTH;
|
|
115
|
-
var child = node.firstChild;
|
|
116
|
-
while (!result && child) {
|
|
117
|
-
// Check if this is the node that holds the fake bullets (mso-list: Ignore)
|
|
118
|
-
if (isIgnoreNode(child)) {
|
|
119
|
-
// Yes... this is the node that holds either the text or image data
|
|
120
|
-
result = (_b = (_a = child.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
121
|
-
// This is the case for image case
|
|
122
|
-
if (result.length == 0) {
|
|
123
|
-
result = 'o';
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else if (isNodeOfType(child, 'ELEMENT_NODE') && levels > 1) {
|
|
127
|
-
// If this is an element and we are not in the last level, try to get the fake bullet
|
|
128
|
-
// out of the child
|
|
129
|
-
result = getFakeBulletText(child, levels - 1);
|
|
130
|
-
}
|
|
131
|
-
child = child.nextSibling;
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Checks if the specified node is marked as a mso-list: Ignore. These
|
|
137
|
-
* nodes need to be ignored when a list item is converted into standard
|
|
138
|
-
* HTML lists
|
|
139
|
-
*/
|
|
140
|
-
function isIgnoreNode(node) {
|
|
141
|
-
if (isNodeOfType(node, 'ELEMENT_NODE')) {
|
|
142
|
-
var listAttribute = getStyles(node)[MSO_LIST];
|
|
143
|
-
if (listAttribute &&
|
|
144
|
-
listAttribute.length > 0 &&
|
|
145
|
-
listAttribute.trim().toLowerCase() == MSO_LIST_IGNORE) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
import { getStyles } from '../utils/getStyles';
|
|
3
|
+
import { addBlock, createListItem, createListLevel, isNodeOfType, parseFormat, } from 'roosterjs-content-model-dom';
|
|
4
|
+
/** Word list metadata style name */
|
|
5
|
+
var MSO_LIST = 'mso-list';
|
|
6
|
+
var MSO_LIST_IGNORE = 'ignore';
|
|
7
|
+
var LOOKUP_DEPTH = 5;
|
|
8
|
+
var WORD_FIRST_LIST = 'l0';
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
* @param styles
|
|
12
|
+
* @param group
|
|
13
|
+
* @param element
|
|
14
|
+
* @param context
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export function processWordList(styles, group, element, context) {
|
|
18
|
+
var listFormat = context.listFormat;
|
|
19
|
+
if (!listFormat.wordKnownLevels) {
|
|
20
|
+
listFormat.wordKnownLevels = new Map();
|
|
21
|
+
}
|
|
22
|
+
var wordListStyle = styles[MSO_LIST] || '';
|
|
23
|
+
// If the element contains Ignore style, do not process it,
|
|
24
|
+
// Usually this element contains the fake bullet used in Word Desktop.
|
|
25
|
+
if (wordListStyle.toLowerCase() === MSO_LIST_IGNORE) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
var listProps = wordListStyle.split(' ');
|
|
29
|
+
// Try get the list metadata from word, which follows this format: l1 level1 lfo2
|
|
30
|
+
// If we are able to get the level property means we can process this element to be a list
|
|
31
|
+
listFormat.wordLevel = listProps[1] && parseInt(listProps[1].substr('level'.length));
|
|
32
|
+
listFormat.wordList = listProps[0] || WORD_FIRST_LIST;
|
|
33
|
+
if (listFormat.levels.length == 0) {
|
|
34
|
+
listFormat.levels = listFormat.wordKnownLevels.get(listFormat.wordList) || [];
|
|
35
|
+
}
|
|
36
|
+
if (wordListStyle && group && typeof listFormat.wordLevel === 'number') {
|
|
37
|
+
var wordLevel = listFormat.wordLevel;
|
|
38
|
+
// Retrieve the Fake bullet on the element and also the list type
|
|
39
|
+
var fakeBullet = getFakeBulletText(element);
|
|
40
|
+
var listType = getFakeBulletTagName(fakeBullet);
|
|
41
|
+
// Create the new level of the list item and parse the format
|
|
42
|
+
var newLevel = createListLevel(listType);
|
|
43
|
+
parseFormat(element, context.formatParsers.listLevel, newLevel.format, context);
|
|
44
|
+
// If the list format is in a different level, update the array so we get the new item
|
|
45
|
+
// To be in the same level as the provided level metadata.
|
|
46
|
+
if (wordLevel > listFormat.levels.length) {
|
|
47
|
+
while (wordLevel != listFormat.levels.length) {
|
|
48
|
+
listFormat.levels.push(newLevel);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
listFormat.levels.splice(wordLevel, listFormat.levels.length - 1);
|
|
53
|
+
listFormat.levels[wordLevel - 1] = newLevel;
|
|
54
|
+
}
|
|
55
|
+
listFormat.listParent = group;
|
|
56
|
+
processAsListItem(listFormat, context, element, group, fakeBullet);
|
|
57
|
+
if (listFormat.levels.length > 0 &&
|
|
58
|
+
listFormat.wordKnownLevels.get(listFormat.wordList) != listFormat.levels) {
|
|
59
|
+
listFormat.wordKnownLevels.set(listFormat.wordList, __spreadArray([], __read(listFormat.levels), false));
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
function processAsListItem(listFormat, context, element, group, fakeBullet) {
|
|
66
|
+
var listItem = createListItem(listFormat.levels, context.segmentFormat);
|
|
67
|
+
var lastLevel = listItem.levels[listItem.levels.length - 1];
|
|
68
|
+
parseFormat(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);
|
|
69
|
+
parseFormat(element, context.formatParsers.listItemElement, listItem.format, context);
|
|
70
|
+
if ((lastLevel === null || lastLevel === void 0 ? void 0 : lastLevel.listType) == 'OL') {
|
|
71
|
+
parseFormat(element, [startNumberOverrideParser(fakeBullet)], listItem.levels[listItem.levels.length - 1].format, context);
|
|
72
|
+
}
|
|
73
|
+
context.elementProcessors.child(listItem, element, context);
|
|
74
|
+
addBlock(group, listItem);
|
|
75
|
+
}
|
|
76
|
+
function startNumberOverrideParser(fakeBullet) {
|
|
77
|
+
return function (format, _, context) {
|
|
78
|
+
var _a = context.listFormat, wordKnownLevels = _a.wordKnownLevels, wordLevel = _a.wordLevel, wordList = _a.wordList;
|
|
79
|
+
if (typeof wordLevel === 'number' && wordList) {
|
|
80
|
+
var start = parseInt(fakeBullet);
|
|
81
|
+
if (start != undefined && !isNaN(start) && !(wordKnownLevels === null || wordKnownLevels === void 0 ? void 0 : wordKnownLevels.has(wordList))) {
|
|
82
|
+
format.startNumberOverride = start;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check whether the string is a fake bullet from word Desktop
|
|
89
|
+
*/
|
|
90
|
+
function isFakeBullet(fakeBullet) {
|
|
91
|
+
return ['o', '·', '§', '-'].indexOf(fakeBullet) >= 0;
|
|
92
|
+
}
|
|
93
|
+
/** Given a fake bullet text, returns the type of list that should be used for it */
|
|
94
|
+
function getFakeBulletTagName(fakeBullet) {
|
|
95
|
+
return isFakeBullet(fakeBullet) ? 'UL' : 'OL';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Finds the fake bullet text out of the specified node and returns it. For images, it will return
|
|
99
|
+
* a bullet string. If not found, it returns null...
|
|
100
|
+
*/
|
|
101
|
+
function getFakeBulletText(node, levels) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
// Word uses the following format for their bullets:
|
|
104
|
+
// <p style="mso-list:l1 level1 lfo2">
|
|
105
|
+
// <span style="...">
|
|
106
|
+
// <span style="mso-list:Ignore">1.<span style="..."> </span></span>
|
|
107
|
+
// </span>
|
|
108
|
+
// Content here...
|
|
109
|
+
// </p>
|
|
110
|
+
//
|
|
111
|
+
// Basically, we need to locate the mso-list:Ignore SPAN, which holds either one text or image node. That
|
|
112
|
+
// text or image node will be the fake bullet we are looking for
|
|
113
|
+
var result = '';
|
|
114
|
+
levels = levels || LOOKUP_DEPTH;
|
|
115
|
+
var child = node.firstChild;
|
|
116
|
+
while (!result && child) {
|
|
117
|
+
// Check if this is the node that holds the fake bullets (mso-list: Ignore)
|
|
118
|
+
if (isIgnoreNode(child)) {
|
|
119
|
+
// Yes... this is the node that holds either the text or image data
|
|
120
|
+
result = (_b = (_a = child.textContent) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : '';
|
|
121
|
+
// This is the case for image case
|
|
122
|
+
if (result.length == 0) {
|
|
123
|
+
result = 'o';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else if (isNodeOfType(child, 'ELEMENT_NODE') && levels > 1) {
|
|
127
|
+
// If this is an element and we are not in the last level, try to get the fake bullet
|
|
128
|
+
// out of the child
|
|
129
|
+
result = getFakeBulletText(child, levels - 1);
|
|
130
|
+
}
|
|
131
|
+
child = child.nextSibling;
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the specified node is marked as a mso-list: Ignore. These
|
|
137
|
+
* nodes need to be ignored when a list item is converted into standard
|
|
138
|
+
* HTML lists
|
|
139
|
+
*/
|
|
140
|
+
function isIgnoreNode(node) {
|
|
141
|
+
if (isNodeOfType(node, 'ELEMENT_NODE')) {
|
|
142
|
+
var listAttribute = getStyles(node)[MSO_LIST];
|
|
143
|
+
if (listAttribute &&
|
|
144
|
+
listAttribute.length > 0 &&
|
|
145
|
+
listAttribute.trim().toLowerCase() == MSO_LIST_IGNORE) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
151
|
//# sourceMappingURL=processWordLists.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processWordLists.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WordDesktop/processWordLists.ts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I,CAAC,EAAE;gBACpB,MAAM,GAAG,GAAG,CAAC;aAChB;SACJ;aAAM,IAAI,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE;YAC1D,qFAAqF;YACrF,mBAAmB;YACnB,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;SACjD;QAED,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;KAC7B;IAED,OAAO,MAAM,CAAC;AAClB,CAAC;AACD;;;;GAIG;AACH,SAAS,YAAY,CAAC,IAAU;IAC5B,IAAI,YAAY,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE;QACpC,IAAM,aAAa,GAAG,SAAS,CAAC,IAAmB,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC/D,IACI,aAAa;YACb,aAAa,CAAC,MAAM,GAAG,CAAC;YACxB,aAAa,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,eAAe,EACvD;YACE,OAAO,IAAI,CAAC;SACf;KACJ;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { getStyles } from '../utils/getStyles';\nimport {\n addBlock,\n createListItem,\n createListLevel,\n isNodeOfType,\n parseFormat,\n} from 'roosterjs-content-model-dom';\nimport type {\n ContentModelBlockGroup,\n ContentModelListItemLevelFormat,\n ContentModelListLevel,\n DomToModelContext,\n DomToModelListFormat,\n FormatParser,\n} from 'roosterjs-content-model-types';\n\n/** Word list metadata style name */\nconst MSO_LIST = 'mso-list';\nconst MSO_LIST_IGNORE = 'ignore';\nconst LOOKUP_DEPTH = 5;\nconst WORD_FIRST_LIST = 'l0';\n\ninterface WordDesktopListFormat extends DomToModelListFormat {\n wordLevel?: number | '';\n wordList?: string;\n wordKnownLevels?: Map<string, ContentModelListLevel[]>;\n}\n\n/**\n * @internal\n * @param styles\n * @param group\n * @param element\n * @param context\n * @returns\n */\nexport function processWordList(\n styles: Record<string, string>,\n group: ContentModelBlockGroup,\n element: HTMLElement,\n context: DomToModelContext\n) {\n const listFormat = context.listFormat as WordDesktopListFormat;\n if (!listFormat.wordKnownLevels) {\n listFormat.wordKnownLevels = new Map<string, ContentModelListLevel[]>();\n }\n const wordListStyle = styles[MSO_LIST] || '';\n\n // If the element contains Ignore style, do not process it,\n // Usually this element contains the fake bullet used in Word Desktop.\n if (wordListStyle.toLowerCase() === MSO_LIST_IGNORE) {\n return true;\n }\n\n const listProps = wordListStyle.split(' ');\n // Try get the list metadata from word, which follows this format: l1 level1 lfo2\n // If we are able to get the level property means we can process this element to be a list\n listFormat.wordLevel = listProps[1] && parseInt(listProps[1].substr('level'.length));\n\n listFormat.wordList = listProps[0] || WORD_FIRST_LIST;\n if (listFormat.levels.length == 0) {\n listFormat.levels = listFormat.wordKnownLevels.get(listFormat.wordList) || [];\n }\n\n if (wordListStyle && group && typeof listFormat.wordLevel === 'number') {\n const { wordLevel } = listFormat;\n // Retrieve the Fake bullet on the element and also the list type\n const fakeBullet = getFakeBulletText(element);\n const listType = getFakeBulletTagName(fakeBullet);\n\n // Create the new level of the list item and parse the format\n const newLevel: ContentModelListLevel = createListLevel(listType);\n parseFormat(element, context.formatParsers.listLevel, newLevel.format, context);\n\n // If the list format is in a different level, update the array so we get the new item\n // To be in the same level as the provided level metadata.\n if (wordLevel > listFormat.levels.length) {\n while (wordLevel != listFormat.levels.length) {\n listFormat.levels.push(newLevel);\n }\n } else {\n listFormat.levels.splice(wordLevel, listFormat.levels.length - 1);\n listFormat.levels[wordLevel - 1] = newLevel;\n }\n\n listFormat.listParent = group;\n\n processAsListItem(listFormat, context, element, group, fakeBullet);\n\n if (\n listFormat.levels.length > 0 &&\n listFormat.wordKnownLevels.get(listFormat.wordList) != listFormat.levels\n ) {\n listFormat.wordKnownLevels.set(listFormat.wordList, [...listFormat.levels]);\n }\n return true;\n }\n\n return false;\n}\n\nfunction processAsListItem(\n listFormat: WordDesktopListFormat,\n context: DomToModelContext,\n element: HTMLElement,\n group: ContentModelBlockGroup,\n fakeBullet: string\n) {\n const listItem = createListItem(listFormat.levels, context.segmentFormat);\n const lastLevel = listItem.levels[listItem.levels.length - 1];\n\n parseFormat(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);\n parseFormat(element, context.formatParsers.listItemElement, listItem.format, context);\n\n if (lastLevel?.listType == 'OL') {\n parseFormat(\n element,\n [startNumberOverrideParser(fakeBullet)],\n listItem.levels[listItem.levels.length - 1].format,\n context\n );\n }\n\n context.elementProcessors.child(listItem, element, context);\n addBlock(group, listItem);\n}\n\nfunction startNumberOverrideParser(\n fakeBullet: string\n): FormatParser<ContentModelListItemLevelFormat> | null {\n return (format, _, context) => {\n const {\n wordKnownLevels,\n wordLevel,\n wordList,\n } = context.listFormat as WordDesktopListFormat;\n if (typeof wordLevel === 'number' && wordList) {\n const start = parseInt(fakeBullet);\n if (start != undefined && !isNaN(start) && !wordKnownLevels?.has(wordList)) {\n format.startNumberOverride = start;\n }\n }\n };\n}\n\n/**\n * Check whether the string is a fake bullet from word Desktop\n */\nfunction isFakeBullet(fakeBullet: string): boolean {\n return ['o', '·', '§', '-'].indexOf(fakeBullet) >= 0;\n}\n\n/** Given a fake bullet text, returns the type of list that should be used for it */\nfunction getFakeBulletTagName(fakeBullet: string): 'UL' | 'OL' {\n return isFakeBullet(fakeBullet) ? 'UL' : 'OL';\n}\n\n/**\n * Finds the fake bullet text out of the specified node and returns it. For images, it will return\n * a bullet string. If not found, it returns null...\n */\nfunction getFakeBulletText(node: Node, levels?: number): string {\n // Word uses the following format for their bullets:\n // <p style=\"mso-list:l1 level1 lfo2\">\n // <span style=\"...\">\n // <span style=\"mso-list:Ignore\">1.<span style=\"...\"> </span></span>\n // </span>\n // Content here...\n // </p>\n //\n // Basically, we need to locate the mso-list:Ignore SPAN, which holds either one text or image node. That\n // text or image node will be the fake bullet we are looking for\n let result: string = '';\n levels = levels || LOOKUP_DEPTH;\n let child: Node | null = node.firstChild;\n while (!result && child) {\n // Check if this is the node that holds the fake bullets (mso-list: Ignore)\n if (isIgnoreNode(child)) {\n // Yes... this is the node that holds either the text or image data\n result = child.textContent?.trim() ?? '';\n\n // This is the case for image case\n if (result.length == 0) {\n result = 'o';\n }\n } else if (isNodeOfType(child, 'ELEMENT_NODE') && levels > 1) {\n // If this is an element and we are not in the last level, try to get the fake bullet\n // out of the child\n result = getFakeBulletText(child, levels - 1);\n }\n\n child = child.nextSibling;\n }\n\n return result;\n}\n/**\n * Checks if the specified node is marked as a mso-list: Ignore. These\n * nodes need to be ignored when a list item is converted into standard\n * HTML lists\n */\nfunction isIgnoreNode(node: Node): boolean {\n if (isNodeOfType(node, 'ELEMENT_NODE')) {\n const listAttribute = getStyles(node as HTMLElement)[MSO_LIST];\n if (\n listAttribute &&\n listAttribute.length > 0 &&\n listAttribute.trim().toLowerCase() == MSO_LIST_IGNORE\n ) {\n return true;\n }\n }\n\n return false;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"processWordLists.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WordDesktop/processWordLists.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACH,QAAQ,EACR,cAAc,EACd,eAAe,EACf,YAAY,EACZ,WAAW,GACd,MAAM,6BAA6B,CAAC;AAUrC,oCAAoC;AACpC,IAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,IAAM,eAAe,GAAG,QAAQ,CAAC;AACjC,IAAM,YAAY,GAAG,CAAC,CAAC;AACvB,IAAM,eAAe,GAAG,IAAI,CAAC;AAQ7B;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC3B,MAA8B,EAC9B,KAA6B,EAC7B,OAAoB,EACpB,OAA0B;IAE1B,IAAM,UAAU,GAAG,OAAO,CAAC,UAAmC,CAAC;IAC/D,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE;QAC7B,UAAU,CAAC,eAAe,GAAG,IAAI,GAAG,EA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a,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,eAAe,EACvD;YACE,OAAO,IAAI,CAAC;SACf;KACJ;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import { getStyles } from '../utils/getStyles';\r\nimport {\r\n addBlock,\r\n createListItem,\r\n createListLevel,\r\n isNodeOfType,\r\n parseFormat,\r\n} from 'roosterjs-content-model-dom';\r\nimport type {\r\n ContentModelBlockGroup,\r\n ContentModelListItemLevelFormat,\r\n ContentModelListLevel,\r\n DomToModelContext,\r\n DomToModelListFormat,\r\n FormatParser,\r\n} from 'roosterjs-content-model-types';\r\n\r\n/** Word list metadata style name */\r\nconst MSO_LIST = 'mso-list';\r\nconst MSO_LIST_IGNORE = 'ignore';\r\nconst LOOKUP_DEPTH = 5;\r\nconst WORD_FIRST_LIST = 'l0';\r\n\r\ninterface WordDesktopListFormat extends DomToModelListFormat {\r\n wordLevel?: number | '';\r\n wordList?: string;\r\n wordKnownLevels?: Map<string, ContentModelListLevel[]>;\r\n}\r\n\r\n/**\r\n * @internal\r\n * @param styles\r\n * @param group\r\n * @param element\r\n * @param context\r\n * @returns\r\n */\r\nexport function processWordList(\r\n styles: Record<string, string>,\r\n group: ContentModelBlockGroup,\r\n element: HTMLElement,\r\n context: DomToModelContext\r\n) {\r\n const listFormat = context.listFormat as WordDesktopListFormat;\r\n if (!listFormat.wordKnownLevels) {\r\n listFormat.wordKnownLevels = new Map<string, ContentModelListLevel[]>();\r\n }\r\n const wordListStyle = styles[MSO_LIST] || '';\r\n\r\n // If the element contains Ignore style, do not process it,\r\n // Usually this element contains the fake bullet used in Word Desktop.\r\n if (wordListStyle.toLowerCase() === MSO_LIST_IGNORE) {\r\n return true;\r\n }\r\n\r\n const listProps = wordListStyle.split(' ');\r\n // Try get the list metadata from word, which follows this format: l1 level1 lfo2\r\n // If we are able to get the level property means we can process this element to be a list\r\n listFormat.wordLevel = listProps[1] && parseInt(listProps[1].substr('level'.length));\r\n\r\n listFormat.wordList = listProps[0] || WORD_FIRST_LIST;\r\n if (listFormat.levels.length == 0) {\r\n listFormat.levels = listFormat.wordKnownLevels.get(listFormat.wordList) || [];\r\n }\r\n\r\n if (wordListStyle && group && typeof listFormat.wordLevel === 'number') {\r\n const { wordLevel } = listFormat;\r\n // Retrieve the Fake bullet on the element and also the list type\r\n const fakeBullet = getFakeBulletText(element);\r\n const listType = getFakeBulletTagName(fakeBullet);\r\n\r\n // Create the new level of the list item and parse the format\r\n const newLevel: ContentModelListLevel = createListLevel(listType);\r\n parseFormat(element, context.formatParsers.listLevel, newLevel.format, context);\r\n\r\n // If the list format is in a different level, update the array so we get the new item\r\n // To be in the same level as the provided level metadata.\r\n if (wordLevel > listFormat.levels.length) {\r\n while (wordLevel != listFormat.levels.length) {\r\n listFormat.levels.push(newLevel);\r\n }\r\n } else {\r\n listFormat.levels.splice(wordLevel, listFormat.levels.length - 1);\r\n listFormat.levels[wordLevel - 1] = newLevel;\r\n }\r\n\r\n listFormat.listParent = group;\r\n\r\n processAsListItem(listFormat, context, element, group, fakeBullet);\r\n\r\n if (\r\n listFormat.levels.length > 0 &&\r\n listFormat.wordKnownLevels.get(listFormat.wordList) != listFormat.levels\r\n ) {\r\n listFormat.wordKnownLevels.set(listFormat.wordList, [...listFormat.levels]);\r\n }\r\n return true;\r\n }\r\n\r\n return false;\r\n}\r\n\r\nfunction processAsListItem(\r\n listFormat: WordDesktopListFormat,\r\n context: DomToModelContext,\r\n element: HTMLElement,\r\n group: ContentModelBlockGroup,\r\n fakeBullet: string\r\n) {\r\n const listItem = createListItem(listFormat.levels, context.segmentFormat);\r\n const lastLevel = listItem.levels[listItem.levels.length - 1];\r\n\r\n parseFormat(element, context.formatParsers.segmentOnBlock, context.segmentFormat, context);\r\n parseFormat(element, context.formatParsers.listItemElement, listItem.format, context);\r\n\r\n if (lastLevel?.listType == 'OL') {\r\n parseFormat(\r\n element,\r\n [startNumberOverrideParser(fakeBullet)],\r\n listItem.levels[listItem.levels.length - 1].format,\r\n context\r\n );\r\n }\r\n\r\n context.elementProcessors.child(listItem, element, context);\r\n addBlock(group, listItem);\r\n}\r\n\r\nfunction startNumberOverrideParser(\r\n fakeBullet: string\r\n): FormatParser<ContentModelListItemLevelFormat> | null {\r\n return (format, _, context) => {\r\n const {\r\n wordKnownLevels,\r\n wordLevel,\r\n wordList,\r\n } = context.listFormat as WordDesktopListFormat;\r\n if (typeof wordLevel === 'number' && wordList) {\r\n const start = parseInt(fakeBullet);\r\n if (start != undefined && !isNaN(start) && !wordKnownLevels?.has(wordList)) {\r\n format.startNumberOverride = start;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Check whether the string is a fake bullet from word Desktop\r\n */\r\nfunction isFakeBullet(fakeBullet: string): boolean {\r\n return ['o', '·', '§', '-'].indexOf(fakeBullet) >= 0;\r\n}\r\n\r\n/** Given a fake bullet text, returns the type of list that should be used for it */\r\nfunction getFakeBulletTagName(fakeBullet: string): 'UL' | 'OL' {\r\n return isFakeBullet(fakeBullet) ? 'UL' : 'OL';\r\n}\r\n\r\n/**\r\n * Finds the fake bullet text out of the specified node and returns it. For images, it will return\r\n * a bullet string. If not found, it returns null...\r\n */\r\nfunction getFakeBulletText(node: Node, levels?: number): string {\r\n // Word uses the following format for their bullets:\r\n // <p style=\"mso-list:l1 level1 lfo2\">\r\n // <span style=\"...\">\r\n // <span style=\"mso-list:Ignore\">1.<span style=\"...\"> </span></span>\r\n // </span>\r\n // Content here...\r\n // </p>\r\n //\r\n // Basically, we need to locate the mso-list:Ignore SPAN, which holds either one text or image node. That\r\n // text or image node will be the fake bullet we are looking for\r\n let result: string = '';\r\n levels = levels || LOOKUP_DEPTH;\r\n let child: Node | null = node.firstChild;\r\n while (!result && child) {\r\n // Check if this is the node that holds the fake bullets (mso-list: Ignore)\r\n if (isIgnoreNode(child)) {\r\n // Yes... this is the node that holds either the text or image data\r\n result = child.textContent?.trim() ?? '';\r\n\r\n // This is the case for image case\r\n if (result.length == 0) {\r\n result = 'o';\r\n }\r\n } else if (isNodeOfType(child, 'ELEMENT_NODE') && levels > 1) {\r\n // If this is an element and we are not in the last level, try to get the fake bullet\r\n // out of the child\r\n result = getFakeBulletText(child, levels - 1);\r\n }\r\n\r\n child = child.nextSibling;\r\n }\r\n\r\n return result;\r\n}\r\n/**\r\n * Checks if the specified node is marked as a mso-list: Ignore. These\r\n * nodes need to be ignored when a list item is converted into standard\r\n * HTML lists\r\n */\r\nfunction isIgnoreNode(node: Node): boolean {\r\n if (isNodeOfType(node, 'ELEMENT_NODE')) {\r\n const listAttribute = getStyles(node as HTMLElement)[MSO_LIST];\r\n if (\r\n listAttribute &&\r\n listAttribute.length > 0 &&\r\n listAttribute.trim().toLowerCase() == MSO_LIST_IGNORE\r\n ) {\r\n return true;\r\n }\r\n }\r\n\r\n return false;\r\n}\r\n"]}
|