-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89e8e73
commit e08d718
Showing
6 changed files
with
270 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/roosterjs-content-model/lib/editor/plugins/PastePlugin/handleExcelOnline.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ContentModelBeforePasteEvent from '../../../publicTypes/event/ContentModelBeforePasteEvent'; | ||
|
||
const DEFAULT_BORDER_STYLE = 'solid 1px #d4d4d4'; | ||
|
||
export function handleExcelOnline(ev: ContentModelBeforePasteEvent) { | ||
if (!ev.domToModelOption.formatParserOverride) { | ||
ev.domToModelOption.formatParserOverride = {}; | ||
} | ||
|
||
if (!ev.domToModelOption.processorOverride) { | ||
ev.domToModelOption.processorOverride = {}; | ||
} | ||
|
||
ev.domToModelOption.processorOverride.element = (group, element, context) => { | ||
if (element.tagName.toLowerCase() === 'div' && element.getAttribute('data-ccp-timestamp')) { | ||
context.elementProcessors.child(group, element, context); | ||
} else { | ||
context.defaultElementProcessors.element(group, element, context); | ||
} | ||
}; | ||
|
||
ev.domToModelOption.formatParserOverride.border = (format, element) => { | ||
if (element.style.border === 'none') { | ||
format.borderBottom = DEFAULT_BORDER_STYLE; | ||
format.borderRight = DEFAULT_BORDER_STYLE; | ||
format.borderTop = DEFAULT_BORDER_STYLE; | ||
format.borderLeft = DEFAULT_BORDER_STYLE; | ||
} | ||
}; | ||
} |
77 changes: 77 additions & 0 deletions
77
packages/roosterjs-content-model/lib/editor/plugins/PastePlugin/handleWacComponents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import ContentModelBeforePasteEvent from '../../../publicTypes/event/ContentModelBeforePasteEvent'; | ||
import { matchesSelector } from 'roosterjs-editor-dom'; | ||
|
||
const WAC_IDENTIFY_SELECTOR = | ||
'ul[class^="BulletListStyle"]>.OutlineElement,ol[class^="NumberListStyle"]>.OutlineElement,span.WACImageContainer'; | ||
const WORD_ONLINE_IDENTIFYING_SELECTOR = | ||
'div.ListContainerWrapper>ul[class^="BulletListStyle"],div.ListContainerWrapper>ol[class^="NumberListStyle"],span.WACImageContainer > img'; | ||
export const LIST_CONTAINER_ELEMENT_CLASS_NAME = 'ListContainerWrapper'; | ||
const IMAGE_CONTAINER_ELEMENT_CLASS_NAME = 'WACImageContainer'; | ||
|
||
export function handleWacComponents(ev: ContentModelBeforePasteEvent) { | ||
if (!ev.domToModelOption.additionalFormatParsers) { | ||
ev.domToModelOption.additionalFormatParsers = {}; | ||
ev.domToModelOption.additionalFormatParsers.segment = []; | ||
} | ||
if (!ev.domToModelOption.processorOverride) { | ||
ev.domToModelOption.processorOverride = {}; | ||
} | ||
|
||
ev.domToModelOption.additionalFormatParsers.segment!.push((format, element, context) => { | ||
const verticalAlign = element.style.verticalAlign; | ||
if (verticalAlign === 'super') { | ||
format.superOrSubScriptSequence = 'super'; | ||
} | ||
if (verticalAlign === 'sub') { | ||
format.superOrSubScriptSequence = 'sub'; | ||
} | ||
}); | ||
|
||
ev.domToModelOption.processorOverride.element = (group, element, context) => { | ||
if (matchesSelector(element, WAC_IDENTIFY_SELECTOR)) { | ||
element.style.removeProperty('display'); | ||
element.style.removeProperty('margin'); | ||
} | ||
if (element.classList.contains(LIST_CONTAINER_ELEMENT_CLASS_NAME)) { | ||
context.elementProcessors.child(group, element, context); | ||
return; | ||
} | ||
|
||
if (element.parentElement?.classList.contains(IMAGE_CONTAINER_ELEMENT_CLASS_NAME)) { | ||
return; | ||
} | ||
|
||
context.defaultElementProcessors.element(group, element, context); | ||
}; | ||
|
||
ev.domToModelOption.processorOverride.li = (group, element, context) => { | ||
context.defaultElementProcessors.li?.(group, element, context); | ||
const { listFormat } = context; | ||
const listParent = listFormat.listParent; | ||
if (listParent) { | ||
const lastblock = listParent.blocks[listParent.blocks.length - 1]; | ||
if (lastblock.blockType == 'BlockGroup' && lastblock.blockGroupType == 'ListItem') { | ||
const currentLevel = lastblock.levels[lastblock.levels.length - 1]; | ||
|
||
// Get item level from 'data-aria-level' attribute | ||
let level = parseInt(element.getAttribute('data-aria-level') ?? ''); | ||
|
||
if (level > lastblock.levels.length) { | ||
while (level != lastblock.levels.length) { | ||
lastblock.levels.push(currentLevel); | ||
} | ||
} else { | ||
lastblock.levels.splice(level, lastblock.levels.length - 1); | ||
lastblock.levels[level - 1] = currentLevel; | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function isWordOnlineWithList(fragment: DocumentFragment): boolean { | ||
return !!(fragment && fragment.querySelector(WORD_ONLINE_IDENTIFYING_SELECTOR)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters