Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of fixes for Word Online Paste #1965

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ContentModelBeforePasteEvent from '../../../../publicTypes/event/ContentM
import { findClosestElementAncestor, getTagOfNode, matchesSelector } from 'roosterjs-editor-dom';
import { setProcessor } from '../utils/setProcessor';
import {
ContentModelBlockFormat,
ContentModelBlockGroup,
ContentModelListItemLevelFormat,
ContentModelSegmentFormat,
Expand All @@ -15,9 +16,8 @@ const WAC_IDENTIFY_SELECTOR =
'ul[class^="BulletListStyle"]>.OutlineElement,ol[class^="NumberListStyle"]>.OutlineElement,span.WACImageContainer,span.WACImageBorder';
const LIST_CONTAINER_ELEMENT_CLASS_NAME = 'ListContainerWrapper';

const EMPTY_TEXT_RUN = 'EmptyTextRun';
const END_OF_PARAGRAPH = 'EOP';
const PARAGRAPH = 'Paragraph';
const TABLE_CONTAINER = 'TableContainer';

const TEMP_ELEMENTS_CLASSES = [
'TableInsertRowGapBlank',
Expand All @@ -35,13 +35,13 @@ const CLASSES_TO_KEEP = [
'WACImageContainer',
'ListContainerWrapper',
'BulletListStyle',
END_OF_PARAGRAPH,
EMPTY_TEXT_RUN,
...TEMP_ELEMENTS_CLASSES,
'TableCellContent',
PARAGRAPH,
'WACImageContainer',
'WACImageBorder',
TABLE_CONTAINER,
'LineBreakBlob',
];

const LIST_ELEMENT_TAGS = ['UL', 'OL', 'LI'];
Expand Down Expand Up @@ -88,11 +88,7 @@ const wacElementProcessor: ElementProcessor<HTMLElement> = (
return;
}

if (
(element.classList.contains(END_OF_PARAGRAPH) &&
element.previousElementSibling?.classList.contains(EMPTY_TEXT_RUN)) ||
TEMP_ELEMENTS_CLASSES.some(className => element.classList.contains(className))
) {
if (TEMP_ELEMENTS_CLASSES.some(className => element.classList.contains(className))) {
return;
} else if (shouldClearListContext(elementTag, element, context)) {
const { listFormat } = context;
Expand Down Expand Up @@ -206,6 +202,7 @@ export function processPastedContentWacComponents(ev: ContentModelBeforePasteEve
addParser(ev.domToModelOption, 'segment', wacSubSuperParser);
addParser(ev.domToModelOption, 'listItem', wacListItemParser);
addParser(ev.domToModelOption, 'listLevel', wacListLevelParser);
addParser(ev.domToModelOption, 'container', wacBlockParser);

setProcessor(ev.domToModelOption, 'element', wacElementProcessor);
setProcessor(ev.domToModelOption, 'li', wacLiElementProcessor);
Expand Down Expand Up @@ -259,3 +256,12 @@ const wacListProcessor: ElementProcessor<HTMLOListElement | HTMLUListElement> =
context.defaultElementProcessors.ul?.(group, element as HTMLUListElement, context);
}
};

const wacBlockParser: FormatParser<ContentModelBlockFormat> = (
format: ContentModelBlockFormat,
element: HTMLElement
) => {
if (element.classList.contains(TABLE_CONTAINER) && element.style.marginLeft.startsWith('-')) {
delete format.marginLeft;
}
};

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { getSourceFunction, getSourceInputParams } from './getPasteSource';

const WAC_IDENTIFY_SELECTOR =
'ul[class^="BulletListStyle"]>.OutlineElement,ol[class^="NumberListStyle"]>.OutlineElement,span.WACImageContainer';
'ul[class^="BulletListStyle"]>.OutlineElement,ol[class^="NumberListStyle"]>.OutlineElement,span.WACImageContainer,.TableContainer';

/**
* @internal
Expand Down