roosterjs-content-model-plugins 0.21.3 → 0.22.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/edit/deleteSteps/deleteAllSegmentBefore.js +3 -0
- package/lib/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js +3 -0
- package/lib/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib/edit/deleteSteps/deleteWordSelection.js +3 -0
- package/lib/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib/edit/keyboardInput.js +1 -1
- package/lib/edit/keyboardInput.js.map +1 -1
- package/lib/paste/ContentModelPastePlugin.d.ts +3 -1
- package/lib/paste/ContentModelPastePlugin.js +5 -3
- package/lib/paste/ContentModelPastePlugin.js.map +1 -1
- package/lib/paste/Excel/processPastedContentFromExcel.d.ts +1 -1
- package/lib/paste/Excel/processPastedContentFromExcel.js +2 -2
- package/lib/paste/Excel/processPastedContentFromExcel.js.map +1 -1
- package/lib/paste/WacComponents/constants.d.ts +56 -0
- package/lib/paste/WacComponents/constants.js +86 -0
- package/lib/paste/WacComponents/constants.js.map +1 -0
- package/lib/paste/WacComponents/processPastedContentWacComponents.js +19 -34
- package/lib/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib/paste/WordDesktop/WordMetadata.d.ts +9 -0
- package/lib/paste/WordDesktop/WordMetadata.js +3 -0
- package/lib/paste/WordDesktop/WordMetadata.js.map +1 -0
- package/lib/paste/WordDesktop/getStyleMetadata.d.ts +23 -0
- package/lib/paste/WordDesktop/getStyleMetadata.js +79 -0
- package/lib/paste/WordDesktop/getStyleMetadata.js.map +1 -0
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -7
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js +14 -14
- package/lib/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib/paste/WordDesktop/processWordLists.d.ts +2 -1
- package/lib/paste/WordDesktop/processWordLists.js +83 -85
- package/lib/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib/paste/pasteSourceValidations/documentContainWacElements.js +2 -11
- package/lib/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -1
- package/lib/paste/pasteSourceValidations/getPasteSource.d.ts +2 -1
- package/lib/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js +3 -0
- package/lib-amd/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js +3 -0
- package/lib-amd/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-amd/edit/deleteSteps/deleteWordSelection.js +3 -0
- package/lib-amd/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib-amd/edit/keyboardInput.js +1 -1
- package/lib-amd/edit/keyboardInput.js.map +1 -1
- package/lib-amd/paste/ContentModelPastePlugin.d.ts +3 -1
- package/lib-amd/paste/ContentModelPastePlugin.js +5 -3
- package/lib-amd/paste/ContentModelPastePlugin.js.map +1 -1
- package/lib-amd/paste/Excel/processPastedContentFromExcel.d.ts +1 -1
- package/lib-amd/paste/Excel/processPastedContentFromExcel.js +2 -2
- package/lib-amd/paste/Excel/processPastedContentFromExcel.js.map +1 -1
- package/lib-amd/paste/WacComponents/constants.d.ts +56 -0
- package/lib-amd/paste/WacComponents/constants.js +87 -0
- package/lib-amd/paste/WacComponents/constants.js.map +1 -0
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js +19 -35
- package/lib-amd/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib-amd/paste/WordDesktop/WordMetadata.d.ts +9 -0
- package/lib-amd/paste/WordDesktop/WordMetadata.js +5 -0
- package/lib-amd/paste/WordDesktop/WordMetadata.js.map +1 -0
- package/lib-amd/paste/WordDesktop/getStyleMetadata.d.ts +23 -0
- package/lib-amd/paste/WordDesktop/getStyleMetadata.js +79 -0
- package/lib-amd/paste/WordDesktop/getStyleMetadata.js.map +1 -0
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -7
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js +14 -15
- package/lib-amd/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-amd/paste/WordDesktop/processWordLists.d.ts +2 -1
- package/lib-amd/paste/WordDesktop/processWordLists.js +83 -85
- package/lib-amd/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.js +2 -12
- package/lib-amd/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -1
- package/lib-amd/paste/pasteSourceValidations/getPasteSource.d.ts +2 -1
- package/lib-amd/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js +3 -0
- package/lib-mjs/edit/deleteSteps/deleteAllSegmentBefore.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js +3 -0
- package/lib-mjs/edit/deleteSteps/deleteCollapsedSelection.js.map +1 -1
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.js +3 -0
- package/lib-mjs/edit/deleteSteps/deleteWordSelection.js.map +1 -1
- package/lib-mjs/edit/keyboardInput.js +1 -1
- package/lib-mjs/edit/keyboardInput.js.map +1 -1
- package/lib-mjs/paste/ContentModelPastePlugin.d.ts +3 -1
- package/lib-mjs/paste/ContentModelPastePlugin.js +5 -3
- package/lib-mjs/paste/ContentModelPastePlugin.js.map +1 -1
- package/lib-mjs/paste/Excel/processPastedContentFromExcel.d.ts +1 -1
- package/lib-mjs/paste/Excel/processPastedContentFromExcel.js +2 -2
- package/lib-mjs/paste/Excel/processPastedContentFromExcel.js.map +1 -1
- package/lib-mjs/paste/WacComponents/constants.d.ts +56 -0
- package/lib-mjs/paste/WacComponents/constants.js +83 -0
- package/lib-mjs/paste/WacComponents/constants.js.map +1 -0
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js +12 -27
- package/lib-mjs/paste/WacComponents/processPastedContentWacComponents.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/WordMetadata.d.ts +9 -0
- package/lib-mjs/paste/WordDesktop/WordMetadata.js +2 -0
- package/lib-mjs/paste/WordDesktop/WordMetadata.js.map +1 -0
- package/lib-mjs/paste/WordDesktop/getStyleMetadata.d.ts +23 -0
- package/lib-mjs/paste/WordDesktop/getStyleMetadata.js +76 -0
- package/lib-mjs/paste/WordDesktop/getStyleMetadata.js.map +1 -0
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.d.ts +2 -7
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js +13 -12
- package/lib-mjs/paste/WordDesktop/processPastedContentFromWordDesktop.js.map +1 -1
- package/lib-mjs/paste/WordDesktop/processWordLists.d.ts +2 -1
- package/lib-mjs/paste/WordDesktop/processWordLists.js +84 -86
- package/lib-mjs/paste/WordDesktop/processWordLists.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.js +1 -10
- package/lib-mjs/paste/pasteSourceValidations/documentContainWacElements.js.map +1 -1
- package/lib-mjs/paste/pasteSourceValidations/getPasteSource.d.ts +2 -1
- package/lib-mjs/paste/pasteSourceValidations/getPasteSource.js.map +1 -1
- package/package.json +5 -5
|
@@ -6,6 +6,9 @@ var roosterjs_content_model_core_1 = require("roosterjs-content-model-core");
|
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
8
|
var deleteAllSegmentBefore = function (context) {
|
|
9
|
+
if (context.deleteResult != 'notDeleted') {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
9
12
|
var _a = context.insertPoint, paragraph = _a.paragraph, marker = _a.marker;
|
|
10
13
|
var index = paragraph.segments.indexOf(marker);
|
|
11
14
|
for (var i = index - 1; i >= 0; i--) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteAllSegmentBefore.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteAllSegmentBefore.ts"],"names":[],"mappings":";;;AAAA,6EAA6D;AAG7D;;GAEG;AACI,IAAM,sBAAsB,GAAwB,UAAA,OAAO;
|
|
1
|
+
{"version":3,"file":"deleteAllSegmentBefore.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteAllSegmentBefore.ts"],"names":[],"mappings":";;;AAAA,6EAA6D;AAG7D;;GAEG;AACI,IAAM,sBAAsB,GAAwB,UAAA,OAAO;IAC9D,IAAI,OAAO,CAAC,YAAY,IAAI,YAAY,EAAE;QACtC,OAAO;KACV;IAEK,IAAA,KAAwB,OAAO,CAAC,WAAW,EAAzC,SAAS,eAAA,EAAE,MAAM,YAAwB,CAAC;IAClD,IAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEjD,KAAK,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;QACjC,IAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QAEtC,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;QAE1B,IAAI,IAAA,4CAAa,EAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC,EAAE;YAC1D,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;SAClC;KACJ;AACL,CAAC,CAAC;AAjBW,QAAA,sBAAsB,0BAiBjC","sourcesContent":["import { deleteSegment } from 'roosterjs-content-model-core';\nimport type { DeleteSelectionStep } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport const deleteAllSegmentBefore: DeleteSelectionStep = context => {\n if (context.deleteResult != 'notDeleted') {\n return;\n }\n\n const { paragraph, marker } = context.insertPoint;\n const index = paragraph.segments.indexOf(marker);\n\n for (let i = index - 1; i >= 0; i--) {\n const segment = paragraph.segments[i];\n\n segment.isSelected = true;\n\n if (deleteSegment(paragraph, segment, context.formatContext)) {\n context.deleteResult = 'range';\n }\n }\n};\n"]}
|
|
@@ -7,6 +7,9 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
7
7
|
function getDeleteCollapsedSelection(direction) {
|
|
8
8
|
return function (context) {
|
|
9
9
|
var _a;
|
|
10
|
+
if (context.deleteResult != 'notDeleted') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
10
13
|
var isForward = direction == 'forward';
|
|
11
14
|
var _b = context.insertPoint, paragraph = _b.paragraph, marker = _b.marker, path = _b.path, tableContext = _b.tableContext;
|
|
12
15
|
var segments = paragraph.segments;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteCollapsedSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteCollapsedSelection.ts"],"names":[],"mappings":";;;AAAA,6EAA0E;AAC1E,oEAAmE;AACnE,2EAAsE;AAItE,SAAS,2BAA2B,CAAC,SAAiC;IAClE,OAAO,UAAA,OAAO;;QACV,IAAM,SAAS,GAAG,SAAS,IAAI,SAAS,CAAC;QACnC,IAAA,KAA4C,OAAO,CAAC,WAAW,EAA7D,SAAS,eAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAA,EAAE,YAAY,kBAAwB,CAAC;QACtE,IAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAElB,IAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxC,I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AAC,YAAY,GAAG,OAAO,CAAC;iBAClC;gBAED,qHAAqH;gBACrH,OAAO,CAAC,gBAAgB,GAAG,YAAY,CAAC;aAC3C;iBAAM;gBACH,IACI,IAAA,0CAAW,EACP,MAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EACd,KAAK,EACL,SAAS,CAAC,eAAe,EACzB,OAAO,CAAC,aAAa,EACrB,SAAS,CACZ,EACH;oBACE,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;iBAClC;aACJ;SACJ;aAAM;YACH,mFAAmF;YACnF,yGAAyG;YACzG,uFAAuF;YACvF,OAAO,CAAC,YAAY,GAAG,iBAAiB,CAAC;SAC5C;IACL,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAS,OAAO,CAAC,QAA+B;;IAC5C,IAAI,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,WAAW,KAAI,IAAI,EAAE;QACpD,IAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAAlC,CAAkC,CAAC,CAAC;QAEnF,IAAI,CAAA,MAAA,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,WAAW,KAAI,IAAI,EAAE;YACtE,QAAQ,CAAC,GAAG,EAAE,CAAC;SAClB;KACJ;AACL,CAAC;AAED;;GAEG;AACU,QAAA,+BAA+B,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;AAEtF;;GAEG;AACU,QAAA,gCAAgC,GAAG,2BAA2B,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { deleteBlock, deleteSegment } from 'roosterjs-content-model-core';\nimport { getLeafSiblingBlock } from '../utils/getLeafSiblingBlock';\nimport { setParagraphNotImplicit } from 'roosterjs-content-model-dom';\nimport type { BlockAndPath } from '../utils/getLeafSiblingBlock';\nimport type { ContentModelSegment, DeleteSelectionStep } from 'roosterjs-content-model-types';\n\nfunction getDeleteCollapsedSelection(direction: 'forward' | 'backward'): DeleteSelectionStep {\n return context => {\n const isForward = direction == 'forward';\n const { paragraph, marker, path, tableContext } = context.insertPoint;\n const segments = paragraph.segments;\n\n fixupBr(segments);\n\n const index = segments.indexOf(marker) + (isForward ? 1 : -1);\n const segmentToDelete = segments[index];\n let blockToDelete: BlockAndPath | null;\n\n if (segmentToDelete) {\n if (deleteSegment(paragraph, segmentToDelete, context.formatContext, direction)) {\n context.deleteResult = 'singleChar';\n\n // It is possible that we have deleted everything from this paragraph, so we need to mark it as not implicit\n // to avoid losing its format. See https://github.com/microsoft/roosterjs/issues/1953\n setParagraphNotImplicit(paragraph);\n }\n } else if ((blockToDelete = getLeafSiblingBlock(path, paragraph, isForward))) {\n const { block, path, siblingSegment } = blockToDelete;\n\n if (block.blockType == 'Paragraph') {\n if (siblingSegment) {\n // When selection is under general segment, need to check if it has a sibling sibling, and delete from it\n if (deleteSegment(block, siblingSegment, context.formatContext, direction)) {\n context.deleteResult = 'range';\n }\n } else {\n if (isForward) {\n context.lastParagraph = block;\n } else {\n if (block.segments[block.segments.length - 1]?.segmentType == 'Br') {\n block.segments.pop();\n }\n\n context.insertPoint = {\n marker,\n paragraph: block,\n path,\n tableContext,\n };\n context.lastParagraph = paragraph;\n delete block.cachedElement;\n }\n\n context.deleteResult = 'range';\n }\n\n // When go across table, getLeafSiblingBlock will return null, when we are here, we must be in the same table context\n context.lastTableContext = tableContext;\n } else {\n if (\n deleteBlock(\n path[0].blocks,\n block,\n undefined /*replacement*/,\n context.formatContext,\n direction\n )\n ) {\n context.deleteResult = 'range';\n }\n }\n } else {\n // We have nothing to delete, in this case we don't want browser handle it as well.\n // Because when Backspace on an empty document, it will also delete the only DIV and SPAN element, causes\n // editor is really empty. We don't want that happen. So the handling should stop here.\n context.deleteResult = 'nothingToDelete';\n }\n };\n}\n\n/**\n * If the last segment is BR, remove it for now. We may add it back later when normalize model.\n * So that if this is an empty paragraph, it will start to delete next block\n */\nfunction fixupBr(segments: ContentModelSegment[]) {\n if (segments[segments.length - 1]?.segmentType == 'Br') {\n const segmentsWithoutBr = segments.filter(x => x.segmentType != 'SelectionMarker');\n\n if (segmentsWithoutBr[segmentsWithoutBr.length - 2]?.segmentType != 'Br') {\n segments.pop();\n }\n }\n}\n\n/**\n * @internal if we didn't delete anything, and we want to delete forward, now perform it\n */\nexport const forwardDeleteCollapsedSelection = getDeleteCollapsedSelection('forward');\n\n/**\n * @internal if we didn't delete anything, and we want to delete backward, now perform it\n */\nexport const backwardDeleteCollapsedSelection = getDeleteCollapsedSelection('backward');\n"]}
|
|
1
|
+
{"version":3,"file":"deleteCollapsedSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteCollapsedSelection.ts"],"names":[],"mappings":";;;AAAA,6EAA0E;AAC1E,oEAAmE;AACnE,2EAAsE;AAItE,SAAS,2BAA2B,CAAC,SAAiC;IAClE,OAAO,UAAA,OAAO;;QACV,IAAI,OAAO,CAAC,YAAY,IAAI,YAAY,EAAE;YACtC,OAAO;SACV;QAED,IAAM,SAAS,GAAG,SAAS,IAAI,SAAS,CAAC;QACnC,IAAA,KAA4C,OAAO,CAAC,WAAW,EAA7D,SAAS,eAAA,EAAE,MAAM,YAAA,EAAE,IAAI,UAAA,EAAE,YAAY,kBAAwB,CAAC;QACtE,IAAM,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC;QAEpC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAElB,IAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,IAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxC,IAAI,aAAkC,CAAC;QAEvC,IAAI,eAAe,EAAE;YACjB,IAAI,IAAA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AO,CAAC,gBAAgB,GAAG,YAAY,CAAC;aAC3C;iBAAM;gBACH,IACI,IAAA,0CAAW,EACP,MAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EACd,KAAK,EACL,SAAS,CAAC,eAAe,EACzB,OAAO,CAAC,aAAa,EACrB,SAAS,CACZ,EACH;oBACE,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;iBAClC;aACJ;SACJ;aAAM;YACH,mFAAmF;YACnF,yGAAyG;YACzG,uFAAuF;YACvF,OAAO,CAAC,YAAY,GAAG,iBAAiB,CAAC;SAC5C;IACL,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,SAAS,OAAO,CAAC,QAA+B;;IAC5C,IAAI,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,WAAW,KAAI,IAAI,EAAE;QACpD,IAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,WAAW,IAAI,iBAAiB,EAAlC,CAAkC,CAAC,CAAC;QAEnF,IAAI,CAAA,MAAA,iBAAiB,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,0CAAE,WAAW,KAAI,IAAI,EAAE;YACtE,QAAQ,CAAC,GAAG,EAAE,CAAC;SAClB;KACJ;AACL,CAAC;AAED;;GAEG;AACU,QAAA,+BAA+B,GAAG,2BAA2B,CAAC,SAAS,CAAC,CAAC;AAEtF;;GAEG;AACU,QAAA,gCAAgC,GAAG,2BAA2B,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { deleteBlock, deleteSegment } from 'roosterjs-content-model-core';\nimport { getLeafSiblingBlock } from '../utils/getLeafSiblingBlock';\nimport { setParagraphNotImplicit } from 'roosterjs-content-model-dom';\nimport type { BlockAndPath } from '../utils/getLeafSiblingBlock';\nimport type { ContentModelSegment, DeleteSelectionStep } from 'roosterjs-content-model-types';\n\nfunction getDeleteCollapsedSelection(direction: 'forward' | 'backward'): DeleteSelectionStep {\n return context => {\n if (context.deleteResult != 'notDeleted') {\n return;\n }\n\n const isForward = direction == 'forward';\n const { paragraph, marker, path, tableContext } = context.insertPoint;\n const segments = paragraph.segments;\n\n fixupBr(segments);\n\n const index = segments.indexOf(marker) + (isForward ? 1 : -1);\n const segmentToDelete = segments[index];\n let blockToDelete: BlockAndPath | null;\n\n if (segmentToDelete) {\n if (deleteSegment(paragraph, segmentToDelete, context.formatContext, direction)) {\n context.deleteResult = 'singleChar';\n\n // It is possible that we have deleted everything from this paragraph, so we need to mark it as not implicit\n // to avoid losing its format. See https://github.com/microsoft/roosterjs/issues/1953\n setParagraphNotImplicit(paragraph);\n }\n } else if ((blockToDelete = getLeafSiblingBlock(path, paragraph, isForward))) {\n const { block, path, siblingSegment } = blockToDelete;\n\n if (block.blockType == 'Paragraph') {\n if (siblingSegment) {\n // When selection is under general segment, need to check if it has a sibling sibling, and delete from it\n if (deleteSegment(block, siblingSegment, context.formatContext, direction)) {\n context.deleteResult = 'range';\n }\n } else {\n if (isForward) {\n context.lastParagraph = block;\n } else {\n if (block.segments[block.segments.length - 1]?.segmentType == 'Br') {\n block.segments.pop();\n }\n\n context.insertPoint = {\n marker,\n paragraph: block,\n path,\n tableContext,\n };\n context.lastParagraph = paragraph;\n delete block.cachedElement;\n }\n\n context.deleteResult = 'range';\n }\n\n // When go across table, getLeafSiblingBlock will return null, when we are here, we must be in the same table context\n context.lastTableContext = tableContext;\n } else {\n if (\n deleteBlock(\n path[0].blocks,\n block,\n undefined /*replacement*/,\n context.formatContext,\n direction\n )\n ) {\n context.deleteResult = 'range';\n }\n }\n } else {\n // We have nothing to delete, in this case we don't want browser handle it as well.\n // Because when Backspace on an empty document, it will also delete the only DIV and SPAN element, causes\n // editor is really empty. We don't want that happen. So the handling should stop here.\n context.deleteResult = 'nothingToDelete';\n }\n };\n}\n\n/**\n * If the last segment is BR, remove it for now. We may add it back later when normalize model.\n * So that if this is an empty paragraph, it will start to delete next block\n */\nfunction fixupBr(segments: ContentModelSegment[]) {\n if (segments[segments.length - 1]?.segmentType == 'Br') {\n const segmentsWithoutBr = segments.filter(x => x.segmentType != 'SelectionMarker');\n\n if (segmentsWithoutBr[segmentsWithoutBr.length - 2]?.segmentType != 'Br') {\n segments.pop();\n }\n }\n}\n\n/**\n * @internal if we didn't delete anything, and we want to delete forward, now perform it\n */\nexport const forwardDeleteCollapsedSelection = getDeleteCollapsedSelection('forward');\n\n/**\n * @internal if we didn't delete anything, and we want to delete backward, now perform it\n */\nexport const backwardDeleteCollapsedSelection = getDeleteCollapsedSelection('backward');\n"]}
|
|
@@ -15,6 +15,9 @@ var DeleteWordState;
|
|
|
15
15
|
})(DeleteWordState || (DeleteWordState = {}));
|
|
16
16
|
function getDeleteWordSelection(direction) {
|
|
17
17
|
return function (context) {
|
|
18
|
+
if (context.deleteResult != 'notDeleted') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
18
21
|
var _a = context.insertPoint, marker = _a.marker, paragraph = _a.paragraph;
|
|
19
22
|
var startIndex = paragraph.segments.indexOf(marker);
|
|
20
23
|
var deleteNext = direction == 'forward';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteWordSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteWordSelection.ts"],"names":[],"mappings":";;;;AAAA,6EAAqF;AACrF,2EAAoE;AAOpE,IAAW,eAOV;AAPD,WAAW,eAAe;IACtB,uDAAK,CAAA;IACL,mEAAW,CAAA;IACX,qDAAI,CAAA;IACJ,2DAAO,CAAA;IACP,uDAAK,CAAA;IACL,mDAAG,CAAA;AACP,CAAC,EAPU,eAAe,KAAf,eAAe,QAOzB;AAQD,SAAS,sBAAsB,CAAC,SAAiC;IAC7D,OAAO,UAAA,OAAO;QACJ,IAAA,KAAwB,OAAO,CAAC,WAAW,EAAzC,MAAM,YAAA,EAAE,SAAS,eAAwB,CAAC;QAClD,IAAM,UAAU,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,wBAAM;qBACT;iBACJ;;;gBAjCD,CAAC,IAAI,IAAI,CAAA;;oBAmCb,yBAAM;oBAIF,qBAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAA,CAAC,gEAAgE;;gBAD3H,IACI,SAAsD,CAAC,gEAAgE;kBACzH;oBACE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBAEtB,IAAI,IAAI,GAAG,CAAC,EAAE;wBACV,CAAC,IAAI,IAAI,CAAC;qBACb;oBAED,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;iBAClC;gBACD,yBAAM;oBAGN,yBAAM;qBAGN,sBAAO,IAAI,EAAC;;gBA/DwC,CAAC,IAAI,IAAI,CAAA;;qBAmEzE,sBAAO,IAAI,EAAC;;;CACf;AAED;;GAEG;AACU,QAAA,0BAA0B,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;AAE5E;;GAEG;AACU,QAAA,2BAA2B,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { isPunctuation, isSpace, normalizeText } from 'roosterjs-content-model-core';\nimport { isWhiteSpacePreserved } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelParagraph,\n DeleteSelectionContext,\n DeleteSelectionStep,\n} from 'roosterjs-content-model-types';\n\nconst enum DeleteWordState {\n Start,\n Punctuation,\n Text,\n NonText,\n Space,\n End,\n}\n\ninterface CharInfo {\n text: boolean;\n space: boolean;\n punctuation: boolean;\n}\n\nfunction getDeleteWordSelection(direction: 'forward' | 'backward'): DeleteSelectionStep {\n return context => {\n const { marker, paragraph } = context.insertPoint;\n const startIndex = paragraph.segments.indexOf(marker);\n const deleteNext = direction == 'forward';\n\n const iterator = iterateSegments(paragraph, startIndex, deleteNext, context);\n let curr = iterator.next();\n\n for (let state = DeleteWordState.Start; state != DeleteWordState.End && !curr.done; ) {\n const { punctuation, space, text } = curr.value;\n\n // This is a state machine of how to delete a whole word together with space and punctuations.\n // For a full state machine chart, see\n // Forward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/ForwardDeleteWord.png\n // Backward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/BackwardDeleteWord.png\n switch (state) {\n case DeleteWordState.Start:\n state = space\n ? DeleteWordState.Space\n : punctuation\n ? DeleteWordState.Punctuation\n : DeleteWordState.Text;\n curr = iterator.next(true /*delete*/);\n break;\n\n case DeleteWordState.Punctuation:\n if (deleteNext && space) {\n state = DeleteWordState.NonText;\n curr = iterator.next(true /*delete*/);\n } else if (punctuation) {\n curr = iterator.next(true /*delete*/);\n } else {\n state = DeleteWordState.End;\n }\n break;\n\n case DeleteWordState.Text:\n if (deleteNext && space) {\n state = DeleteWordState.NonText;\n curr = iterator.next(true /*delete*/);\n } else if (text) {\n curr = iterator.next(true /*delete*/);\n } else {\n state = DeleteWordState.End;\n }\n break;\n\n case DeleteWordState.NonText:\n if (punctuation || !space) {\n state = DeleteWordState.End;\n } else {\n curr = iterator.next(true /*delete*/);\n }\n break;\n\n case DeleteWordState.Space:\n if (space) {\n curr = iterator.next(true /*delete*/);\n } else if (punctuation) {\n state = deleteNext ? DeleteWordState.NonText : DeleteWordState.Punctuation;\n curr = iterator.next(true /*delete*/);\n } else {\n state = deleteNext ? DeleteWordState.End : DeleteWordState.Text;\n }\n break;\n }\n }\n };\n}\n\nfunction* iterateSegments(\n paragraph: ContentModelParagraph,\n markerIndex: number,\n forward: boolean,\n context: DeleteSelectionContext\n): Generator<CharInfo, null, boolean> {\n const step = forward ? 1 : -1;\n const segments = paragraph.segments;\n const preserveWhiteSpace = isWhiteSpacePreserved(paragraph);\n\n for (let i = markerIndex + step; i >= 0 && i < segments.length; i += step) {\n const segment = segments[i];\n\n switch (segment.segmentType) {\n case 'Text':\n for (\n let j = forward ? 0 : segment.text.length - 1;\n j >= 0 && j < segment.text.length;\n j += step\n ) {\n const c = segment.text[j];\n const punctuation = isPunctuation(c);\n const space = isSpace(c);\n const text = !punctuation && !space;\n\n if (yield { punctuation, space, text }) {\n let newText = segment.text;\n\n newText = newText.substring(0, j) + newText.substring(j + 1);\n\n if (!preserveWhiteSpace) {\n newText = normalizeText(newText, forward);\n }\n\n context.deleteResult = 'range';\n\n if (newText) {\n segment.text = newText;\n\n if (step > 0) {\n j -= step;\n }\n } else {\n segments.splice(i, 1);\n\n if (step > 0) {\n i -= step;\n }\n\n break;\n }\n }\n }\n break;\n\n case 'Image':\n if (\n yield { punctuation: true, space: false, text: false } // Treat image as punctuation since they have the same behavior.\n ) {\n segments.splice(i, 1);\n\n if (step > 0) {\n i -= step;\n }\n\n context.deleteResult = 'range';\n }\n break;\n\n case 'SelectionMarker':\n break;\n\n default:\n return null;\n }\n }\n\n return null;\n}\n\n/**\n * @internal\n */\nexport const forwardDeleteWordSelection = getDeleteWordSelection('forward');\n\n/**\n * @internal\n */\nexport const backwardDeleteWordSelection = getDeleteWordSelection('backward');\n"]}
|
|
1
|
+
{"version":3,"file":"deleteWordSelection.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/deleteSteps/deleteWordSelection.ts"],"names":[],"mappings":";;;;AAAA,6EAAqF;AACrF,2EAAoE;AAOpE,IAAW,eAOV;AAPD,WAAW,eAAe;IACtB,uDAAK,CAAA;IACL,mEAAW,CAAA;IACX,qDAAI,CAAA;IACJ,2DAAO,CAAA;IACP,uDAAK,CAAA;IACL,mDAAG,CAAA;AACP,CAAC,EAPU,eAAe,KAAf,eAAe,QAOzB;AAQD,SAAS,sBAAsB,CAAC,SAAiC;IAC7D,OAAO,UAAA,OAAO;QACV,IAAI,OAAO,CAAC,YAAY,IAAI,YAAY,EAAE;YACtC,OAAO;SACV;QAEK,IAAA,KAAwB,OAAO,CAAC,WAAW,EAAzC,MAAM,YAAA,EAAE,SAAS,eAAwB,CAAC;QAClD,IAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM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I,CAAA;;oBAmCb,yBAAM;oBAIF,qBAAM,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAA,CAAC,gEAAgE;;gBAD3H,IACI,SAAsD,CAAC,gEAAgE;kBACzH;oBACE,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBAEtB,IAAI,IAAI,GAAG,CAAC,EAAE;wBACV,CAAC,IAAI,IAAI,CAAC;qBACb;oBAED,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC;iBAClC;gBACD,yBAAM;oBAGN,yBAAM;qBAGN,sBAAO,IAAI,EAAC;;gBA/DwC,CAAC,IAAI,IAAI,CAAA;;qBAmEzE,sBAAO,IAAI,EAAC;;;CACf;AAED;;GAEG;AACU,QAAA,0BAA0B,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;AAE5E;;GAEG;AACU,QAAA,2BAA2B,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC","sourcesContent":["import { isPunctuation, isSpace, normalizeText } from 'roosterjs-content-model-core';\nimport { isWhiteSpacePreserved } from 'roosterjs-content-model-dom';\nimport type {\n ContentModelParagraph,\n DeleteSelectionContext,\n DeleteSelectionStep,\n} from 'roosterjs-content-model-types';\n\nconst enum DeleteWordState {\n Start,\n Punctuation,\n Text,\n NonText,\n Space,\n End,\n}\n\ninterface CharInfo {\n text: boolean;\n space: boolean;\n punctuation: boolean;\n}\n\nfunction getDeleteWordSelection(direction: 'forward' | 'backward'): DeleteSelectionStep {\n return context => {\n if (context.deleteResult != 'notDeleted') {\n return;\n }\n\n const { marker, paragraph } = context.insertPoint;\n const startIndex = paragraph.segments.indexOf(marker);\n const deleteNext = direction == 'forward';\n\n const iterator = iterateSegments(paragraph, startIndex, deleteNext, context);\n let curr = iterator.next();\n\n for (let state = DeleteWordState.Start; state != DeleteWordState.End && !curr.done; ) {\n const { punctuation, space, text } = curr.value;\n\n // This is a state machine of how to delete a whole word together with space and punctuations.\n // For a full state machine chart, see\n // Forward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/ForwardDeleteWord.png\n // Backward delete: https://github.com/microsoft/roosterjs/blob/master/assets/design-charts/BackwardDeleteWord.png\n switch (state) {\n case DeleteWordState.Start:\n state = space\n ? DeleteWordState.Space\n : punctuation\n ? DeleteWordState.Punctuation\n : DeleteWordState.Text;\n curr = iterator.next(true /*delete*/);\n break;\n\n case DeleteWordState.Punctuation:\n if (deleteNext && space) {\n state = DeleteWordState.NonText;\n curr = iterator.next(true /*delete*/);\n } else if (punctuation) {\n curr = iterator.next(true /*delete*/);\n } else {\n state = DeleteWordState.End;\n }\n break;\n\n case DeleteWordState.Text:\n if (deleteNext && space) {\n state = DeleteWordState.NonText;\n curr = iterator.next(true /*delete*/);\n } else if (text) {\n curr = iterator.next(true /*delete*/);\n } else {\n state = DeleteWordState.End;\n }\n break;\n\n case DeleteWordState.NonText:\n if (punctuation || !space) {\n state = DeleteWordState.End;\n } else {\n curr = iterator.next(true /*delete*/);\n }\n break;\n\n case DeleteWordState.Space:\n if (space) {\n curr = iterator.next(true /*delete*/);\n } else if (punctuation) {\n state = deleteNext ? DeleteWordState.NonText : DeleteWordState.Punctuation;\n curr = iterator.next(true /*delete*/);\n } else {\n state = deleteNext ? DeleteWordState.End : DeleteWordState.Text;\n }\n break;\n }\n }\n };\n}\n\nfunction* iterateSegments(\n paragraph: ContentModelParagraph,\n markerIndex: number,\n forward: boolean,\n context: DeleteSelectionContext\n): Generator<CharInfo, null, boolean> {\n const step = forward ? 1 : -1;\n const segments = paragraph.segments;\n const preserveWhiteSpace = isWhiteSpacePreserved(paragraph);\n\n for (let i = markerIndex + step; i >= 0 && i < segments.length; i += step) {\n const segment = segments[i];\n\n switch (segment.segmentType) {\n case 'Text':\n for (\n let j = forward ? 0 : segment.text.length - 1;\n j >= 0 && j < segment.text.length;\n j += step\n ) {\n const c = segment.text[j];\n const punctuation = isPunctuation(c);\n const space = isSpace(c);\n const text = !punctuation && !space;\n\n if (yield { punctuation, space, text }) {\n let newText = segment.text;\n\n newText = newText.substring(0, j) + newText.substring(j + 1);\n\n if (!preserveWhiteSpace) {\n newText = normalizeText(newText, forward);\n }\n\n context.deleteResult = 'range';\n\n if (newText) {\n segment.text = newText;\n\n if (step > 0) {\n j -= step;\n }\n } else {\n segments.splice(i, 1);\n\n if (step > 0) {\n i -= step;\n }\n\n break;\n }\n }\n }\n break;\n\n case 'Image':\n if (\n yield { punctuation: true, space: false, text: false } // Treat image as punctuation since they have the same behavior.\n ) {\n segments.splice(i, 1);\n\n if (step > 0) {\n i -= step;\n }\n\n context.deleteResult = 'range';\n }\n break;\n\n case 'SelectionMarker':\n break;\n\n default:\n return null;\n }\n }\n\n return null;\n}\n\n/**\n * @internal\n */\nexport const forwardDeleteWordSelection = getDeleteWordSelection('forward');\n\n/**\n * @internal\n */\nexport const backwardDeleteWordSelection = getDeleteWordSelection('backward');\n"]}
|
|
@@ -9,7 +9,7 @@ var roosterjs_content_model_dom_1 = require("roosterjs-content-model-dom");
|
|
|
9
9
|
function keyboardInput(editor, rawEvent) {
|
|
10
10
|
var selection = editor.getDOMSelection();
|
|
11
11
|
if (shouldInputWithContentModel(selection, rawEvent)) {
|
|
12
|
-
editor.
|
|
12
|
+
editor.takeSnapshot();
|
|
13
13
|
editor.formatContentModel(function (model, context) {
|
|
14
14
|
var _a;
|
|
15
15
|
var result = (0, roosterjs_content_model_core_1.deleteSelection)(model, [], context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAC9E,2EAAoE;AAIpE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAA2B,EAAE,QAAuB;IAC9E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAClD,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"keyboardInput.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/edit/keyboardInput.ts"],"names":[],"mappings":";;;AAAA,6EAA8E;AAC9E,2EAAoE;AAIpE;;GAEG;AACH,SAAgB,aAAa,CAAC,MAA2B,EAAE,QAAuB;IAC9E,IAAM,SAAS,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;IAE3C,IAAI,2BAA2B,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;QAClD,MAAM,CAAC,YAAY,EAAE,CAAC;QAEtB,MAAM,CAAC,kBAAkB,CACrB,UAAC,KAAK,EAAE,OAAO;;YACX,IAAM,MAAM,GAAG,IAAA,8CAAe,EAAC,KAAK,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;YAEnD,0EAA0E;YAC1E,qFAAqF;YACrF,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAE/B,oJAAoJ;YACpJ,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAEhC,IAAI,MAAM,CAAC,YAAY,IAAI,OAAO,EAAE;gBAChC,2HAA2H;gBAC3H,OAAO,CAAC,gBAAgB,GAAG,MAAA,MAAM,CAAC,WAAW,0CAAE,MAAM,CAAC,MAAM,CAAC;gBAE7D,IAAA,mDAAqB,EAAC,KAAK,CAAC,CAAC;gBAE7B,sFAAsF;gBACtF,OAAO,IAAI,CAAC;aACf;iBAAM;gBACH,OAAO,KAAK,CAAC;aAChB;QACL,CAAC,EACD;YACI,QAAQ,UAAA;SACX,CACJ,CAAC;QAEF,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AApCD,sCAoCC;AAED,SAAS,2BAA2B,CAAC,SAA8B,EAAE,QAAuB;IACxF,IAAI,CAAC,SAAS,EAAE;QACZ,OAAO,KAAK,CAAC,CAAC,oBAAoB;KACrC;SAAM,IACH,CAAC,IAAA,4CAAa,EAAC,QAAQ,CAAC;QACxB,CAAC,QAAQ,CAAC,GAAG,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG,IAAI,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,EAClF;QACE,OAAO,SAAS,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,0DAA0D;KAC7H;SAAM;QACH,OAAO,KAAK,CAAC;KAChB;AACL,CAAC","sourcesContent":["import { deleteSelection, isModifierKey } from 'roosterjs-content-model-core';\nimport { normalizeContentModel } from 'roosterjs-content-model-dom';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type { DOMSelection } from 'roosterjs-content-model-types';\n\n/**\n * @internal\n */\nexport function keyboardInput(editor: IContentModelEditor, rawEvent: KeyboardEvent) {\n const selection = editor.getDOMSelection();\n\n if (shouldInputWithContentModel(selection, rawEvent)) {\n editor.takeSnapshot();\n\n editor.formatContentModel(\n (model, context) => {\n const result = deleteSelection(model, [], context);\n\n // We have deleted selection then we will let browser to handle the input.\n // With this combined operation, we don't wan to mass up the cached model so clear it\n context.clearModelCache = true;\n\n // Skip undo snapshot here and add undo snapshot before the operation so that we don't add another undo snapshot in middle of this replace operation\n context.skipUndoSnapshot = true;\n\n if (result.deleteResult == 'range') {\n // We have deleted something, next input should inherit the segment format from deleted content, so set pending format here\n context.newPendingFormat = result.insertPoint?.marker.format;\n\n normalizeContentModel(model);\n\n // Do not preventDefault since we still want browser to handle the final input for now\n return true;\n } else {\n return false;\n }\n },\n {\n rawEvent,\n }\n );\n\n return true;\n }\n}\n\nfunction shouldInputWithContentModel(selection: DOMSelection | null, rawEvent: KeyboardEvent) {\n if (!selection) {\n return false; // Nothing to delete\n } else if (\n !isModifierKey(rawEvent) &&\n (rawEvent.key == 'Enter' || rawEvent.key == 'Space' || rawEvent.key.length == 1)\n ) {\n return selection.type != 'range' || !selection.range.collapsed; // TODO: Also handle Enter key even selection is collapsed\n } else {\n return false;\n }\n}\n"]}
|
|
@@ -9,12 +9,14 @@ import type { EditorPlugin, IEditor, PluginEvent } from 'roosterjs-editor-types'
|
|
|
9
9
|
*/
|
|
10
10
|
export declare class ContentModelPastePlugin implements EditorPlugin {
|
|
11
11
|
private unknownTagReplacement;
|
|
12
|
+
private allowExcelNoBorderTable?;
|
|
12
13
|
private editor;
|
|
13
14
|
/**
|
|
14
15
|
* Construct a new instance of Paste class
|
|
15
16
|
* @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN
|
|
17
|
+
* @param allowExcelNoBorderTable Allow table copied from Excel without border
|
|
16
18
|
*/
|
|
17
|
-
constructor(unknownTagReplacement?: string);
|
|
19
|
+
constructor(unknownTagReplacement?: string, allowExcelNoBorderTable?: boolean | undefined);
|
|
18
20
|
/**
|
|
19
21
|
* Get name of this plugin
|
|
20
22
|
*/
|
|
@@ -32,10 +32,12 @@ var ContentModelPastePlugin = /** @class */ (function () {
|
|
|
32
32
|
/**
|
|
33
33
|
* Construct a new instance of Paste class
|
|
34
34
|
* @param unknownTagReplacement Replace solution of unknown tags, default behavior is to replace with SPAN
|
|
35
|
+
* @param allowExcelNoBorderTable Allow table copied from Excel without border
|
|
35
36
|
*/
|
|
36
|
-
function ContentModelPastePlugin(unknownTagReplacement) {
|
|
37
|
+
function ContentModelPastePlugin(unknownTagReplacement, allowExcelNoBorderTable) {
|
|
37
38
|
if (unknownTagReplacement === void 0) { unknownTagReplacement = 'SPAN'; }
|
|
38
39
|
this.unknownTagReplacement = unknownTagReplacement;
|
|
40
|
+
this.allowExcelNoBorderTable = allowExcelNoBorderTable;
|
|
39
41
|
this.editor = null;
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
@@ -80,7 +82,7 @@ var ContentModelPastePlugin = /** @class */ (function () {
|
|
|
80
82
|
var pasteType = PasteTypeMap[ev.pasteType];
|
|
81
83
|
switch (pasteSource) {
|
|
82
84
|
case 'wordDesktop':
|
|
83
|
-
(0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(ev);
|
|
85
|
+
(0, processPastedContentFromWordDesktop_1.processPastedContentFromWordDesktop)(ev, this.editor.getTrustedHTMLHandler());
|
|
84
86
|
break;
|
|
85
87
|
case 'wacComponents':
|
|
86
88
|
(0, processPastedContentWacComponents_1.processPastedContentWacComponents)(ev);
|
|
@@ -89,7 +91,7 @@ var ContentModelPastePlugin = /** @class */ (function () {
|
|
|
89
91
|
case 'excelDesktop':
|
|
90
92
|
if (pasteType === 'normal' || pasteType === 'mergeFormat') {
|
|
91
93
|
// Handle HTML copied from Excel
|
|
92
|
-
(0, processPastedContentFromExcel_1.processPastedContentFromExcel)(ev, this.editor.getTrustedHTMLHandler());
|
|
94
|
+
(0, processPastedContentFromExcel_1.processPastedContentFromExcel)(ev, this.editor.getTrustedHTMLHandler(), this.allowExcelNoBorderTable);
|
|
93
95
|
}
|
|
94
96
|
break;
|
|
95
97
|
case 'googleSheets':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentModelPastePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts"],"names":[],"mappings":";;;;AAAA,+CAA0C;AAC1C,2EAAyD;AACzD,6DAA8D;AAC9D,uEAA4E;AAC5E,0EAAyE;AACzE,iDAA+C;AAG/C,uFAAsF;AACtF,sGAAqG;AACrG,yGAAwG;AACxG,uGAAsG;AAiBtG,qCAAqC;AACrC,0DAA0D;AAC1D,IAAM,YAAY;IACd,sBAAwB,SAAS;IACjC,0BAA4B,aAAa;IACzC,0BAA4B,aAAa;IACzC,qBAAuB,QAAQ;OAClC,CAAC;AAEF;;;;;;;GAOG;AACH;IAGI;;;OAGG;IACH,iCAAoB,qBAAsC;QAAtC,sCAAA,EAAA,8BAAsC;QAAtC,0BAAqB,GAArB,qBAAqB,CAAiB;QANlD,WAAM,GAA+B,IAAI,CAAC;IAMW,CAAC;IAE9D;;OAEG;IACH,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C,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChF,CAAC,aAAa,EAAE,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACxF,CAAC,cAAc,EAAE,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC5F,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,iBAAiB,EAAE,CAAC;CACvF,CAAC,CAAC;AAEH,SAAS,iBAAiB,CAAC,MAAmC,EAAE,OAAoB;IAChF,wCAAU,CAAC,OAAO,CAAC,UAAA,GAAG;QAClB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACd,IAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5C,IACI,QAAQ;gBACR,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACzB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC5B;gBACE,MAAM,CAAC,GAAG,CAAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;aAC7E;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import addParser from './utils/addParser';\nimport { BorderKeys } from 'roosterjs-content-model-dom';\nimport { chainSanitizerCallback } from 'roosterjs-editor-dom';\nimport { deprecatedBorderColorParser } from './utils/deprecatedColorParser';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { parseLink } from './utils/linkParser';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { PasteType as OldPasteType, PluginEventType } from 'roosterjs-editor-types';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type {\n BorderFormat,\n ContentModelBeforePasteEvent,\n ContentModelBlockFormat,\n ContentModelTableCellFormat,\n FormatParser,\n PasteType,\n} from 'roosterjs-content-model-types';\nimport type {\n EditorPlugin,\n HtmlSanitizerOptions,\n IEditor,\n PluginEvent,\n} from 'roosterjs-editor-types';\n\n// Map old PasteType to new PasteType\n// TODO: We can remove this once we have standalone editor\nconst PasteTypeMap: Record<OldPasteType, PasteType> = {\n [OldPasteType.AsImage]: 'asImage',\n [OldPasteType.AsPlainText]: 'asPlainText',\n [OldPasteType.MergeFormat]: 'mergeFormat',\n [OldPasteType.Normal]: 'normal',\n};\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 * (This class is still under development, and may still be changed in the future with some breaking changes)\n */\nexport class ContentModelPastePlugin implements EditorPlugin {\n private editor: IContentModelEditor | 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 */\n constructor(private unknownTagReplacement: string = 'SPAN') {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelPaste';\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 // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IContentModelEditor;\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 != PluginEventType.BeforePaste) {\n return;\n }\n\n const ev = event as ContentModelBeforePasteEvent;\n\n if (!ev.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(ev, false);\n const pasteType = PasteTypeMap[ev.pasteType];\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(ev);\n break;\n case 'wacComponents':\n processPastedContentWacComponents(ev);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(ev, this.editor.getTrustedHTMLHandler());\n }\n break;\n case 'googleSheets':\n ev.sanitizingOption.additionalTagReplacements[\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME\n ] = '*';\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(ev, this.editor.getTrustedHTMLHandler());\n break;\n }\n\n addParser(ev.domToModelOption, 'link', parseLink);\n addParser(ev.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(ev.domToModelOption, 'tableCell', tableBorderParser);\n addParser(ev.domToModelOption, 'table', deprecatedBorderColorParser);\n sanitizeBlockStyles(ev.sanitizingOption);\n\n if (pasteType === 'mergeFormat') {\n addParser(ev.domToModelOption, 'block', blockElementParser);\n addParser(ev.domToModelOption, 'listLevel', blockElementParser);\n }\n\n ev.sanitizingOption.unknownTagReplacement = this.unknownTagReplacement;\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\nfunction sanitizeBlockStyles(sanitizingOption: Required<HtmlSanitizerOptions>) {\n chainSanitizerCallback(sanitizingOption.cssStyleCallbacks, 'display', (value: string) => {\n return value != 'flex'; // return whether we keep the style\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":"ContentModelPastePlugin.js","sourceRoot":"","sources":["../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/ContentModelPastePlugin.ts"],"names":[],"mappings":";;;;AAAA,+CAA0C;AAC1C,2EAAyD;AACzD,6DAA8D;AAC9D,uEAA4E;AAC5E,0EAAyE;AACzE,iDAA+C;AAG/C,uFAAsF;AACtF,sGAAqG;AACrG,yGAAwG;AACxG,uGAAsG;AAiBtG,qCAAqC;AACrC,0DAA0D;AAC1D,IAAM,YAAY;IACd,sBAAwB,SAAS;IACjC,0BAA4B,aAAa;IACzC,0B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AAC,GAAM,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAG,CAAC;aAC7E;SACJ;IACL,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import addParser from './utils/addParser';\nimport { BorderKeys } from 'roosterjs-content-model-dom';\nimport { chainSanitizerCallback } from 'roosterjs-editor-dom';\nimport { deprecatedBorderColorParser } from './utils/deprecatedColorParser';\nimport { getPasteSource } from './pasteSourceValidations/getPasteSource';\nimport { parseLink } from './utils/linkParser';\nimport { PastePropertyNames } from './pasteSourceValidations/constants';\nimport { PasteType as OldPasteType, PluginEventType } from 'roosterjs-editor-types';\nimport { processPastedContentFromExcel } from './Excel/processPastedContentFromExcel';\nimport { processPastedContentFromPowerPoint } from './PowerPoint/processPastedContentFromPowerPoint';\nimport { processPastedContentFromWordDesktop } from './WordDesktop/processPastedContentFromWordDesktop';\nimport { processPastedContentWacComponents } from './WacComponents/processPastedContentWacComponents';\nimport type { IContentModelEditor } from 'roosterjs-content-model-editor';\nimport type {\n BorderFormat,\n ContentModelBeforePasteEvent,\n ContentModelBlockFormat,\n ContentModelTableCellFormat,\n FormatParser,\n PasteType,\n} from 'roosterjs-content-model-types';\nimport type {\n EditorPlugin,\n HtmlSanitizerOptions,\n IEditor,\n PluginEvent,\n} from 'roosterjs-editor-types';\n\n// Map old PasteType to new PasteType\n// TODO: We can remove this once we have standalone editor\nconst PasteTypeMap: Record<OldPasteType, PasteType> = {\n [OldPasteType.AsImage]: 'asImage',\n [OldPasteType.AsPlainText]: 'asPlainText',\n [OldPasteType.MergeFormat]: 'mergeFormat',\n [OldPasteType.Normal]: 'normal',\n};\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 * (This class is still under development, and may still be changed in the future with some breaking changes)\n */\nexport class ContentModelPastePlugin implements EditorPlugin {\n private editor: IContentModelEditor | 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 unknownTagReplacement: string = 'SPAN',\n private allowExcelNoBorderTable?: boolean\n ) {}\n\n /**\n * Get name of this plugin\n */\n getName() {\n return 'ContentModelPaste';\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 // TODO: Later we may need a different interface for Content Model editor plugin\n this.editor = editor as IContentModelEditor;\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 != PluginEventType.BeforePaste) {\n return;\n }\n\n const ev = event as ContentModelBeforePasteEvent;\n\n if (!ev.domToModelOption) {\n return;\n }\n\n const pasteSource = getPasteSource(ev, false);\n const pasteType = PasteTypeMap[ev.pasteType];\n\n switch (pasteSource) {\n case 'wordDesktop':\n processPastedContentFromWordDesktop(ev, this.editor.getTrustedHTMLHandler());\n break;\n case 'wacComponents':\n processPastedContentWacComponents(ev);\n break;\n case 'excelOnline':\n case 'excelDesktop':\n if (pasteType === 'normal' || pasteType === 'mergeFormat') {\n // Handle HTML copied from Excel\n processPastedContentFromExcel(\n ev,\n this.editor.getTrustedHTMLHandler(),\n this.allowExcelNoBorderTable\n );\n }\n break;\n case 'googleSheets':\n ev.sanitizingOption.additionalTagReplacements[\n PastePropertyNames.GOOGLE_SHEET_NODE_NAME\n ] = '*';\n break;\n case 'powerPointDesktop':\n processPastedContentFromPowerPoint(ev, this.editor.getTrustedHTMLHandler());\n break;\n }\n\n addParser(ev.domToModelOption, 'link', parseLink);\n addParser(ev.domToModelOption, 'tableCell', deprecatedBorderColorParser);\n addParser(ev.domToModelOption, 'tableCell', tableBorderParser);\n addParser(ev.domToModelOption, 'table', deprecatedBorderColorParser);\n sanitizeBlockStyles(ev.sanitizingOption);\n\n if (pasteType === 'mergeFormat') {\n addParser(ev.domToModelOption, 'block', blockElementParser);\n addParser(ev.domToModelOption, 'listLevel', blockElementParser);\n }\n\n ev.sanitizingOption.unknownTagReplacement = this.unknownTagReplacement;\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\nfunction sanitizeBlockStyles(sanitizingOption: Required<HtmlSanitizerOptions>) {\n chainSanitizerCallback(sanitizingOption.cssStyleCallbacks, 'display', (value: string) => {\n return value != 'flex'; // return whether we keep the style\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"]}
|
|
@@ -5,7 +5,7 @@ import type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-types
|
|
|
5
5
|
* Convert pasted content from Excel, add borders when source doc doesn't have a border
|
|
6
6
|
* @param event The BeforePaste event
|
|
7
7
|
*/
|
|
8
|
-
export declare function processPastedContentFromExcel(event: ContentModelBeforePasteEvent, trustedHTMLHandler: TrustedHTMLHandler): void;
|
|
8
|
+
export declare function processPastedContentFromExcel(event: ContentModelBeforePasteEvent, trustedHTMLHandler: TrustedHTMLHandler, allowExcelNoBorderTable?: boolean): void;
|
|
9
9
|
/**
|
|
10
10
|
* @internal Export for test only
|
|
11
11
|
* @param html Source html
|
|
@@ -15,7 +15,7 @@ var DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4';
|
|
|
15
15
|
* Convert pasted content from Excel, add borders when source doc doesn't have a border
|
|
16
16
|
* @param event The BeforePaste event
|
|
17
17
|
*/
|
|
18
|
-
function processPastedContentFromExcel(event, trustedHTMLHandler) {
|
|
18
|
+
function processPastedContentFromExcel(event, trustedHTMLHandler, allowExcelNoBorderTable) {
|
|
19
19
|
var fragment = event.fragment, htmlBefore = event.htmlBefore, clipboardData = event.clipboardData;
|
|
20
20
|
var html = clipboardData.html ? excelHandler(clipboardData.html, htmlBefore) : undefined;
|
|
21
21
|
if (html && clipboardData.html != html) {
|
|
@@ -42,7 +42,7 @@ function processPastedContentFromExcel(event, trustedHTMLHandler) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
(0, addParser_1.default)(event.domToModelOption, 'tableCell', function (format, element) {
|
|
45
|
-
if (element.style.borderStyle === 'none') {
|
|
45
|
+
if (!allowExcelNoBorderTable && element.style.borderStyle === 'none') {
|
|
46
46
|
format.borderBottom = DEFAULT_BORDER_STYLE;
|
|
47
47
|
format.borderLeft = DEFAULT_BORDER_STYLE;
|
|
48
48
|
format.borderRight = DEFAULT_BORDER_STYLE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processPastedContentFromExcel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts"],"names":[],"mappings":";;;;AAAA,gDAA2C;AAC3C,2EAA2E;AAC3E,sDAAqD;AAIrD,IAAM,iBAAiB,GAAG,yCAAyC,CAAC;AACpE,IAAM,iBAAiB,GAAG,4CAA4C,CAAC;AACvE,IAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,IAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,IAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD;;;;GAIG;AAEH,SAAgB,6BAA6B,CACzC,KAAmC,EACnC,kBAAsC;
|
|
1
|
+
{"version":3,"file":"processPastedContentFromExcel.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/Excel/processPastedContentFromExcel.ts"],"names":[],"mappings":";;;;AAAA,gDAA2C;AAC3C,2EAA2E;AAC3E,sDAAqD;AAIrD,IAAM,iBAAiB,GAAG,yCAAyC,CAAC;AACpE,IAAM,iBAAiB,GAAG,4CAA4C,CAAC;AACvE,IAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,IAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAC9C,IAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD;;;;GAIG;AAEH,SAAgB,6BAA6B,CACzC,KAAmC,EACnC,kBAAsC,EACtC,uBAAiC;IAEzB,IAAA,QAAQ,GAAgC,KAAK,SAArC,EAAE,UAAU,GAAoB,KAAK,WAAzB,EAAE,aAAa,GAAK,KAAK,cAAV,CAAW;IACtD,IAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3F,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AC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACtD,IAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACrD,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,UAAU,CAAC;KACpC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAbD,oCAaC","sourcesContent":["import addParser from '../utils/addParser';\nimport { isNodeOfType, moveChildNodes } from 'roosterjs-content-model-dom';\nimport { setProcessor } from '../utils/setProcessor';\nimport type { TrustedHTMLHandler } from 'roosterjs-editor-types';\nimport type { ContentModelBeforePasteEvent } from 'roosterjs-content-model-types';\n\nconst LAST_TD_END_REGEX = /<\\/\\s*td\\s*>((?!<\\/\\s*tr\\s*>)[\\s\\S])*$/i;\nconst LAST_TR_END_REGEX = /<\\/\\s*tr\\s*>((?!<\\/\\s*table\\s*>)[\\s\\S])*$/i;\nconst LAST_TR_REGEX = /<tr[^>]*>[^<]*/i;\nconst LAST_TABLE_REGEX = /<table[^>]*>[^<]*/i;\nconst DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4';\n\n/**\n * @internal\n * Convert pasted content from Excel, add borders when source doc doesn't have a border\n * @param event The BeforePaste event\n */\n\nexport function processPastedContentFromExcel(\n event: ContentModelBeforePasteEvent,\n trustedHTMLHandler: TrustedHTMLHandler,\n allowExcelNoBorderTable?: boolean\n) {\n const { fragment, htmlBefore, clipboardData } = event;\n const html = clipboardData.html ? excelHandler(clipboardData.html, htmlBefore) : undefined;\n\n if (html && clipboardData.html != html) {\n const doc = new DOMParser().parseFromString(trustedHTMLHandler(html), 'text/html');\n moveChildNodes(fragment, doc?.body);\n }\n\n // For Excel Online\n const firstChild = fragment.firstChild;\n if (\n isNodeOfType(firstChild, 'ELEMENT_NODE') &&\n firstChild.tagName == 'div' &&\n firstChild.firstChild\n ) {\n const tableFound = Array.from(firstChild.childNodes).every((child: Node) => {\n // Tables pasted from Excel Online should be of the format: 0 to N META tags and 1 TABLE tag\n const tagName = isNodeOfType(child, 'ELEMENT_NODE') && child.tagName;\n\n return tagName == 'META'\n ? true\n : tagName == 'TABLE'\n ? child == firstChild.lastChild\n : false;\n });\n\n // Extract Table from Div\n if (tableFound && firstChild.lastChild) {\n event.fragment.replaceChildren(firstChild.lastChild);\n }\n }\n\n addParser(event.domToModelOption, 'tableCell', (format, element) => {\n if (!allowExcelNoBorderTable && element.style.borderStyle === 'none') {\n format.borderBottom = DEFAULT_BORDER_STYLE;\n format.borderLeft = DEFAULT_BORDER_STYLE;\n format.borderRight = DEFAULT_BORDER_STYLE;\n format.borderTop = DEFAULT_BORDER_STYLE;\n }\n });\n\n setProcessor(event.domToModelOption, 'child', (group, element, context) => {\n const segmentFormat = { ...context.segmentFormat };\n if (group.blockGroupType === 'TableCell' && group.format.textColor) {\n context.segmentFormat.textColor = group.format.textColor;\n }\n\n context.defaultElementProcessors.child(group, element, context);\n\n if (group.blockGroupType === 'TableCell' && group.format.textColor) {\n context.segmentFormat = segmentFormat;\n delete group.format.textColor;\n }\n });\n}\n\n/**\n * @internal Export for test only\n * @param html Source html\n */\n\nexport function excelHandler(html: string, htmlBefore: string): string {\n if (html.match(LAST_TD_END_REGEX)) {\n const trMatch = htmlBefore.match(LAST_TR_REGEX);\n const tr = trMatch ? trMatch[0] : '<TR>';\n html = tr + html + '</TR>';\n }\n if (html.match(LAST_TR_END_REGEX)) {\n const tableMatch = htmlBefore.match(LAST_TABLE_REGEX);\n const table = tableMatch ? tableMatch[0] : '<TABLE>';\n html = table + html + '</TABLE>';\n }\n\n return html;\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
**/
|
|
4
|
+
export declare const WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES: string[];
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
**/
|
|
8
|
+
export declare const BULLET_LIST_STYLE: string;
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
**/
|
|
12
|
+
export declare const NUMBER_LIST_STYLE: string;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
**/
|
|
16
|
+
export declare const IMAGE_BORDER: string;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
**/
|
|
20
|
+
export declare const IMAGE_CONTAINER: string;
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
**/
|
|
24
|
+
export declare const OUTLINE_ELEMENT: string;
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
**/
|
|
28
|
+
export declare const PARAGRAPH: string;
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
**/
|
|
32
|
+
export declare const LIST_CONTAINER_ELEMENT_CLASS_NAME: string;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
**/
|
|
36
|
+
export declare const TABLE_CONTAINER: string;
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
**/
|
|
40
|
+
export declare const COMMENT_HIGHLIGHT_CLASS: string;
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
**/
|
|
44
|
+
export declare const COMMENT_HIGHLIGHT_CLICKED_CLASS: string;
|
|
45
|
+
/**
|
|
46
|
+
* @internal
|
|
47
|
+
**/
|
|
48
|
+
export declare const TEMP_ELEMENTS_CLASSES: string[];
|
|
49
|
+
/**
|
|
50
|
+
* @internal
|
|
51
|
+
**/
|
|
52
|
+
export declare const WAC_IDENTIFY_SELECTOR: string;
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
**/
|
|
56
|
+
export declare const CLASSES_TO_KEEP: string[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLASSES_TO_KEEP = exports.WAC_IDENTIFY_SELECTOR = exports.TEMP_ELEMENTS_CLASSES = exports.COMMENT_HIGHLIGHT_CLICKED_CLASS = exports.COMMENT_HIGHLIGHT_CLASS = exports.TABLE_CONTAINER = exports.LIST_CONTAINER_ELEMENT_CLASS_NAME = exports.PARAGRAPH = exports.OUTLINE_ELEMENT = exports.IMAGE_CONTAINER = exports.IMAGE_BORDER = exports.NUMBER_LIST_STYLE = exports.BULLET_LIST_STYLE = exports.WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
**/
|
|
8
|
+
exports.WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES = [
|
|
9
|
+
'TableInsertRowGapBlank',
|
|
10
|
+
'TableColumnResizeHandle',
|
|
11
|
+
'TableCellTopBorderHandle',
|
|
12
|
+
'TableCellLeftBorderHandle',
|
|
13
|
+
'TableHoverColumnHandle',
|
|
14
|
+
'TableHoverRowHandle',
|
|
15
|
+
];
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
**/
|
|
19
|
+
exports.BULLET_LIST_STYLE = 'BulletListStyle';
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
**/
|
|
23
|
+
exports.NUMBER_LIST_STYLE = 'NumberListStyle';
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
**/
|
|
27
|
+
exports.IMAGE_BORDER = 'WACImageBorder';
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
**/
|
|
31
|
+
exports.IMAGE_CONTAINER = 'WACImageContainer';
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
**/
|
|
35
|
+
exports.OUTLINE_ELEMENT = 'OutlineElement';
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
**/
|
|
39
|
+
exports.PARAGRAPH = 'Paragraph';
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
**/
|
|
43
|
+
exports.LIST_CONTAINER_ELEMENT_CLASS_NAME = 'ListContainerWrapper';
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
**/
|
|
47
|
+
exports.TABLE_CONTAINER = 'TableContainer';
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
**/
|
|
51
|
+
exports.COMMENT_HIGHLIGHT_CLASS = 'CommentHighlightRest';
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
**/
|
|
55
|
+
exports.COMMENT_HIGHLIGHT_CLICKED_CLASS = 'CommentHighlightClicked';
|
|
56
|
+
/**
|
|
57
|
+
* @internal
|
|
58
|
+
**/
|
|
59
|
+
exports.TEMP_ELEMENTS_CLASSES = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(exports.WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES), false), [
|
|
60
|
+
'ListMarkerWrappingSpan',
|
|
61
|
+
], false);
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
**/
|
|
65
|
+
exports.WAC_IDENTIFY_SELECTOR = "ul[class^=\"" + exports.BULLET_LIST_STYLE + "\"]>." + exports.OUTLINE_ELEMENT + ",ol[class^=\"" + exports.NUMBER_LIST_STYLE + "\"]>." + exports.OUTLINE_ELEMENT + ",span." + exports.IMAGE_CONTAINER + ",span." + exports.IMAGE_BORDER + ",." + exports.COMMENT_HIGHLIGHT_CLASS + ",." + exports.COMMENT_HIGHLIGHT_CLICKED_CLASS + "," +
|
|
66
|
+
exports.WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES.map(function (c) { return "table div[class^=\"" + c + "\"]"; }).join(',');
|
|
67
|
+
/**
|
|
68
|
+
* @internal
|
|
69
|
+
**/
|
|
70
|
+
exports.CLASSES_TO_KEEP = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([
|
|
71
|
+
exports.OUTLINE_ELEMENT,
|
|
72
|
+
exports.IMAGE_CONTAINER
|
|
73
|
+
], (0, tslib_1.__read)(exports.TEMP_ELEMENTS_CLASSES), false), [
|
|
74
|
+
exports.PARAGRAPH,
|
|
75
|
+
exports.IMAGE_BORDER,
|
|
76
|
+
exports.TABLE_CONTAINER,
|
|
77
|
+
exports.COMMENT_HIGHLIGHT_CLASS,
|
|
78
|
+
exports.COMMENT_HIGHLIGHT_CLICKED_CLASS,
|
|
79
|
+
'NumberListStyle',
|
|
80
|
+
'ListContainerWrapper',
|
|
81
|
+
'BulletListStyle',
|
|
82
|
+
'TableCellContent',
|
|
83
|
+
'WACImageContainer',
|
|
84
|
+
'LineBreakBlob',
|
|
85
|
+
], false);
|
|
86
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../packages-content-model/roosterjs-content-model-plugins/lib/paste/WacComponents/constants.ts"],"names":[],"mappings":";;;;AAAA;;IAEI;AACS,QAAA,sCAAsC,GAAa;IAC5D,wBAAwB;IACxB,yBAAyB;IACzB,0BAA0B;IAC1B,2BAA2B;IAC3B,wBAAwB;IACxB,qBAAqB;CACxB,CAAC;AACF;;IAEI;AACS,QAAA,iBAAiB,GAAW,iBAAiB,CAAC;AAC3D;;IAEI;AACS,QAAA,iBAAiB,GAAW,iBAAiB,CAAC;AAC3D;;IAEI;AACS,QAAA,YAAY,GAAW,gBAAgB,CAAC;AACrD;;IAEI;AACS,QAAA,eAAe,GAAW,mBAAmB,CAAC;AAC3D;;IAEI;AACS,QAAA,eAAe,GAAW,gBAAgB,CAAC;AACxD;;IAEI;AACS,QAAA,SAAS,GAAW,WAAW,CAAC;AAC7C;;IAEI;AACS,QAAA,iCAAiC,GAAW,sBAAsB,CAAC;AAChF;;IAEI;AACS,QAAA,eAAe,GAAW,gBAAgB,CAAC;AACxD;;IAEI;AACS,QAAA,uBAAuB,GAAW,sBAAsB,CAAC;AACtE;;IAEI;AACS,QAAA,+BAA+B,GAAW,yBAAyB,CAAC;AACjF;;IAEI;AACS,QAAA,qBAAqB,iFAC3B,8CAAsC;IACzC,wBAAwB;UAC1B;AACF;;IAEI;AACS,QAAA,qBAAqB,GAC9B,iBAAc,yBAAiB,aAAO,uBAAe,qBAAe,yBAAiB,aAAO,uBAAe,cAAS,uBAAe,cAAS,oBAAY,UAAK,+BAAuB,UAAK,uCAA+B,MAAG;IAC3N,8CAAsC,CAAC,GAAG,CAAC,UAAA,CAAC,IAAI,OAAA,wBAAqB,CAAC,QAAI,EAA1B,CAA0B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1F;;IAEI;AACS,QAAA,eAAe;IACxB,uBAAe;IACf,uBAAe;uBACZ,6BAAqB;IACxB,iBAAS;IACT,oBAAY;IACZ,uBAAe;IACf,+BAAuB;IACvB,uCAA+B;IAC/B,iBAAiB;IACjB,sBAAsB;IACtB,iBAAiB;IACjB,kBAAkB;IAClB,mBAAmB;IACnB,eAAe;UACjB","sourcesContent":["/**\n * @internal\n **/\nexport const WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES: string[] = [\n 'TableInsertRowGapBlank',\n 'TableColumnResizeHandle',\n 'TableCellTopBorderHandle',\n 'TableCellLeftBorderHandle',\n 'TableHoverColumnHandle',\n 'TableHoverRowHandle',\n];\n/**\n * @internal\n **/\nexport const BULLET_LIST_STYLE: string = 'BulletListStyle';\n/**\n * @internal\n **/\nexport const NUMBER_LIST_STYLE: string = 'NumberListStyle';\n/**\n * @internal\n **/\nexport const IMAGE_BORDER: string = 'WACImageBorder';\n/**\n * @internal\n **/\nexport const IMAGE_CONTAINER: string = 'WACImageContainer';\n/**\n * @internal\n **/\nexport const OUTLINE_ELEMENT: string = 'OutlineElement';\n/**\n * @internal\n **/\nexport const PARAGRAPH: string = 'Paragraph';\n/**\n * @internal\n **/\nexport const LIST_CONTAINER_ELEMENT_CLASS_NAME: string = 'ListContainerWrapper';\n/**\n * @internal\n **/\nexport const TABLE_CONTAINER: string = 'TableContainer';\n/**\n * @internal\n **/\nexport const COMMENT_HIGHLIGHT_CLASS: string = 'CommentHighlightRest';\n/**\n * @internal\n **/\nexport const COMMENT_HIGHLIGHT_CLICKED_CLASS: string = 'CommentHighlightClicked';\n/**\n * @internal\n **/\nexport const TEMP_ELEMENTS_CLASSES: string[] = [\n ...WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES,\n 'ListMarkerWrappingSpan',\n];\n/**\n * @internal\n **/\nexport const WAC_IDENTIFY_SELECTOR: string =\n `ul[class^=\"${BULLET_LIST_STYLE}\"]>.${OUTLINE_ELEMENT},ol[class^=\"${NUMBER_LIST_STYLE}\"]>.${OUTLINE_ELEMENT},span.${IMAGE_CONTAINER},span.${IMAGE_BORDER},.${COMMENT_HIGHLIGHT_CLASS},.${COMMENT_HIGHLIGHT_CLICKED_CLASS},` +\n WORD_ONLINE_TABLE_TEMP_ELEMENT_CLASSES.map(c => `table div[class^=\"${c}\"]`).join(',');\n/**\n * @internal\n **/\nexport const CLASSES_TO_KEEP: string[] = [\n OUTLINE_ELEMENT,\n IMAGE_CONTAINER,\n ...TEMP_ELEMENTS_CLASSES,\n PARAGRAPH,\n IMAGE_BORDER,\n TABLE_CONTAINER,\n COMMENT_HIGHLIGHT_CLASS,\n COMMENT_HIGHLIGHT_CLICKED_CLASS,\n 'NumberListStyle',\n 'ListContainerWrapper',\n 'BulletListStyle',\n 'TableCellContent',\n 'WACImageContainer',\n 'LineBreakBlob',\n];\n"]}
|
|
@@ -4,35 +4,11 @@ exports.processPastedContentWacComponents = void 0;
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var addParser_1 = require("../utils/addParser");
|
|
6
6
|
var setProcessor_1 = require("../utils/setProcessor");
|
|
7
|
-
var
|
|
8
|
-
var LIST_CONTAINER_ELEMENT_CLASS_NAME = 'ListContainerWrapper';
|
|
9
|
-
var PARAGRAPH = 'Paragraph';
|
|
10
|
-
var TABLE_CONTAINER = 'TableContainer';
|
|
11
|
-
var TEMP_ELEMENTS_CLASSES = [
|
|
12
|
-
'TableInsertRowGapBlank',
|
|
13
|
-
'TableColumnResizeHandle',
|
|
14
|
-
'TableCellTopBorderHandle',
|
|
15
|
-
'TableCellLeftBorderHandle',
|
|
16
|
-
'TableHoverColumnHandle',
|
|
17
|
-
'TableHoverRowHandle',
|
|
18
|
-
'ListMarkerWrappingSpan',
|
|
19
|
-
];
|
|
20
|
-
var CLASSES_TO_KEEP = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([
|
|
21
|
-
'OutlineElement',
|
|
22
|
-
'NumberListStyle',
|
|
23
|
-
'WACImageContainer',
|
|
24
|
-
'ListContainerWrapper',
|
|
25
|
-
'BulletListStyle'
|
|
26
|
-
], (0, tslib_1.__read)(TEMP_ELEMENTS_CLASSES), false), [
|
|
27
|
-
'TableCellContent',
|
|
28
|
-
PARAGRAPH,
|
|
29
|
-
'WACImageContainer',
|
|
30
|
-
'WACImageBorder',
|
|
31
|
-
TABLE_CONTAINER,
|
|
32
|
-
'LineBreakBlob',
|
|
33
|
-
], false);
|
|
7
|
+
var constants_1 = require("./constants");
|
|
34
8
|
var LIST_ELEMENT_TAGS = ['UL', 'OL', 'LI'];
|
|
35
9
|
var LIST_ELEMENT_SELECTOR = LIST_ELEMENT_TAGS.join(',');
|
|
10
|
+
var COMMENT_BG_COLOR_REST = 'rgba(209, 209, 209, 0.5)';
|
|
11
|
+
var COMMENTS_TEXT_HIGHLIGHT_CLICKED = 'rgba(197, 139, 204, 0.5)';
|
|
36
12
|
/**
|
|
37
13
|
* Wac components do not use sub and super tags, instead only add vertical align to a span.
|
|
38
14
|
* This parser normalize the content for content model
|
|
@@ -56,15 +32,15 @@ var wacSubSuperParser = function (format, element) {
|
|
|
56
32
|
*/
|
|
57
33
|
var wacElementProcessor = function (group, element, context) {
|
|
58
34
|
var elementTag = element.tagName;
|
|
59
|
-
if (element.matches(WAC_IDENTIFY_SELECTOR)) {
|
|
35
|
+
if (element.matches(constants_1.WAC_IDENTIFY_SELECTOR)) {
|
|
60
36
|
element.style.removeProperty('display');
|
|
61
37
|
element.style.removeProperty('margin');
|
|
62
38
|
}
|
|
63
|
-
if (element.classList.contains(LIST_CONTAINER_ELEMENT_CLASS_NAME)) {
|
|
39
|
+
if (element.classList.contains(constants_1.LIST_CONTAINER_ELEMENT_CLASS_NAME)) {
|
|
64
40
|
context.elementProcessors.child(group, element, context);
|
|
65
41
|
return;
|
|
66
42
|
}
|
|
67
|
-
if (TEMP_ELEMENTS_CLASSES.some(function (className) { return element.classList.contains(className); })) {
|
|
43
|
+
if (constants_1.TEMP_ELEMENTS_CLASSES.some(function (className) { return element.classList.contains(className); })) {
|
|
68
44
|
return;
|
|
69
45
|
}
|
|
70
46
|
else if (shouldClearListContext(elementTag, element, context)) {
|
|
@@ -145,6 +121,14 @@ function shouldClearListContext(elementTag, element, context) {
|
|
|
145
121
|
LIST_ELEMENT_TAGS.every(function (tag) { return tag != elementTag; }) &&
|
|
146
122
|
!element.closest(LIST_ELEMENT_SELECTOR));
|
|
147
123
|
}
|
|
124
|
+
var wacCommentParser = function (format, element) {
|
|
125
|
+
if ((element.className.includes(constants_1.COMMENT_HIGHLIGHT_CLASS) &&
|
|
126
|
+
element.style.backgroundColor == COMMENT_BG_COLOR_REST) ||
|
|
127
|
+
(element.className.includes(constants_1.COMMENT_HIGHLIGHT_CLICKED_CLASS) &&
|
|
128
|
+
element.style.backgroundColor == COMMENTS_TEXT_HIGHLIGHT_CLICKED)) {
|
|
129
|
+
delete format.backgroundColor;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
148
132
|
/**
|
|
149
133
|
* @internal
|
|
150
134
|
* Convert pasted content from Office Online
|
|
@@ -158,11 +142,12 @@ function processPastedContentWacComponents(ev) {
|
|
|
158
142
|
(0, addParser_1.default)(ev.domToModelOption, 'listItemThread', wacListItemParser);
|
|
159
143
|
(0, addParser_1.default)(ev.domToModelOption, 'listLevel', wacListLevelParser);
|
|
160
144
|
(0, addParser_1.default)(ev.domToModelOption, 'container', wacBlockParser);
|
|
145
|
+
(0, addParser_1.default)(ev.domToModelOption, 'segment', wacCommentParser);
|
|
161
146
|
(0, setProcessor_1.setProcessor)(ev.domToModelOption, 'element', wacElementProcessor);
|
|
162
147
|
(0, setProcessor_1.setProcessor)(ev.domToModelOption, 'li', wacLiElementProcessor);
|
|
163
148
|
(0, setProcessor_1.setProcessor)(ev.domToModelOption, 'ol', wacListProcessor);
|
|
164
149
|
(0, setProcessor_1.setProcessor)(ev.domToModelOption, 'ul', wacListProcessor);
|
|
165
|
-
(_a = ev.sanitizingOption.additionalAllowedCssClasses).push.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(CLASSES_TO_KEEP), false));
|
|
150
|
+
(_a = ev.sanitizingOption.additionalAllowedCssClasses).push.apply(_a, (0, tslib_1.__spreadArray)([], (0, tslib_1.__read)(constants_1.CLASSES_TO_KEEP), false));
|
|
166
151
|
}
|
|
167
152
|
exports.processPastedContentWacComponents = processPastedContentWacComponents;
|
|
168
153
|
/**
|
|
@@ -183,8 +168,8 @@ exports.processPastedContentWacComponents = processPastedContentWacComponents;
|
|
|
183
168
|
var wacListProcessor = function (group, element, context) {
|
|
184
169
|
var _a, _b, _c, _d, _e;
|
|
185
170
|
var lastBlock = group.blocks[group.blocks.length - 1];
|
|
186
|
-
var isWrappedInContainer = element.closest("." + LIST_CONTAINER_ELEMENT_CLASS_NAME);
|
|
187
|
-
if ((_a = isWrappedInContainer === null || isWrappedInContainer === void 0 ? void 0 : isWrappedInContainer.previousElementSibling) === null || _a === void 0 ? void 0 : _a.classList.contains(LIST_CONTAINER_ELEMENT_CLASS_NAME)) {
|
|
171
|
+
var isWrappedInContainer = element.closest("." + constants_1.LIST_CONTAINER_ELEMENT_CLASS_NAME);
|
|
172
|
+
if ((_a = isWrappedInContainer === null || isWrappedInContainer === void 0 ? void 0 : isWrappedInContainer.previousElementSibling) === null || _a === void 0 ? void 0 : _a.classList.contains(constants_1.LIST_CONTAINER_ELEMENT_CLASS_NAME)) {
|
|
188
173
|
if ((lastBlock === null || lastBlock === void 0 ? void 0 : lastBlock.blockType) === 'BlockGroup' && lastBlock.blockGroupType == 'ListItem') {
|
|
189
174
|
context.listFormat = {
|
|
190
175
|
threadItemCounts: [],
|
|
@@ -201,7 +186,7 @@ var wacListProcessor = function (group, element, context) {
|
|
|
201
186
|
}
|
|
202
187
|
};
|
|
203
188
|
var wacBlockParser = function (format, element) {
|
|
204
|
-
if (element.classList.contains(TABLE_CONTAINER) && element.style.marginLeft.startsWith('-')) {
|
|
189
|
+
if (element.classList.contains(constants_1.TABLE_CONTAINER) && element.style.marginLeft.startsWith('-')) {
|
|
205
190
|
delete format.marginLeft;
|
|
206
191
|
}
|
|
207
192
|
};
|