diff --git a/packages-content-model/roosterjs-content-model-editor/lib/editor/utils/eventConverter.ts b/packages-content-model/roosterjs-content-model-editor/lib/editor/utils/eventConverter.ts index bce247dd55f..c973fc8c0c2 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/editor/utils/eventConverter.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/editor/utils/eventConverter.ts @@ -1,5 +1,6 @@ import { convertDomSelectionToRangeEx, convertRangeExToDomSelection } from './selectionConverter'; import { createDefaultHtmlSanitizerOptions } from 'roosterjs-editor-dom'; +import type { ContentModelBeforePasteEvent } from '../../publicTypes/ContentModelBeforePasteEvent'; import { KnownAnnounceStrings as OldKnownAnnounceStrings, PasteType as OldPasteType, @@ -133,20 +134,23 @@ export function oldEventToNewEvent( case PluginEventType.BeforePaste: const refBeforePasteEvent = refEvent?.eventType == 'beforePaste' ? refEvent : undefined; + const cmBeforePasteEvent = input as ContentModelBeforePasteEvent; return { eventType: 'beforePaste', clipboardData: input.clipboardData, - customizedMerge: refBeforePasteEvent?.customizedMerge, - domToModelOption: refBeforePasteEvent?.domToModelOption ?? { - additionalAllowedTags: [], - additionalDisallowedTags: [], - additionalFormatParsers: {}, - formatParserOverride: {}, - processorOverride: {}, - styleSanitizers: {}, - attributeSanitizers: {}, - }, + customizedMerge: + cmBeforePasteEvent.customizedMerge ?? refBeforePasteEvent?.customizedMerge, + domToModelOption: cmBeforePasteEvent.domToModelOption ?? + refBeforePasteEvent?.domToModelOption ?? { + additionalAllowedTags: [], + additionalDisallowedTags: [], + additionalFormatParsers: {}, + formatParserOverride: {}, + processorOverride: {}, + styleSanitizers: {}, + attributeSanitizers: {}, + }, eventDataCache: input.eventDataCache, fragment: input.fragment, htmlAfter: input.htmlAfter, @@ -349,7 +353,7 @@ export function newEventToOldEvent(input: NewEvent, refEvent?: OldEvent): OldEve const refBeforePasteEvent = refEvent?.eventType == PluginEventType.BeforePaste ? refEvent : undefined; - return { + const oldBeforePasteEvent: ContentModelBeforePasteEvent = { eventType: PluginEventType.BeforePaste, clipboardData: input.clipboardData, eventDataCache: input.eventDataCache, @@ -360,8 +364,12 @@ export function newEventToOldEvent(input: NewEvent, refEvent?: OldEvent): OldEve pasteType: PasteTypeNewToOld[input.pasteType], sanitizingOption: refBeforePasteEvent?.sanitizingOption ?? createDefaultHtmlSanitizerOptions(), + domToModelOption: input.domToModelOption, + customizedMerge: input.customizedMerge, }; + return oldBeforePasteEvent; + case 'beforeSetContent': return { eventType: PluginEventType.BeforeSetContent, diff --git a/packages-content-model/roosterjs-content-model-editor/lib/index.ts b/packages-content-model/roosterjs-content-model-editor/lib/index.ts index 38364003350..1aecfd69e2c 100644 --- a/packages-content-model/roosterjs-content-model-editor/lib/index.ts +++ b/packages-content-model/roosterjs-content-model-editor/lib/index.ts @@ -10,6 +10,7 @@ export { export { IContentModelEditor, ContentModelEditorOptions } from './publicTypes/IContentModelEditor'; export { ContextMenuPluginState } from './publicTypes/ContextMenuPluginState'; export { ContentModelCorePluginState } from './publicTypes/ContentModelCorePlugins'; +export { ContentModelBeforePasteEvent } from './publicTypes/ContentModelBeforePasteEvent'; export { ContentModelEditor } from './editor/ContentModelEditor'; export { isContentModelEditor } from './editor/isContentModelEditor'; diff --git a/packages-content-model/roosterjs-content-model-editor/lib/publicTypes/ContentModelBeforePasteEvent.ts b/packages-content-model/roosterjs-content-model-editor/lib/publicTypes/ContentModelBeforePasteEvent.ts new file mode 100644 index 00000000000..d9cb72619f1 --- /dev/null +++ b/packages-content-model/roosterjs-content-model-editor/lib/publicTypes/ContentModelBeforePasteEvent.ts @@ -0,0 +1,20 @@ +import type { BeforePasteEvent } from 'roosterjs-editor-types'; +import type { + DomToModelOptionForPaste, + MergePastedContentFunc, +} from 'roosterjs-content-model-types'; + +/** + * A temporary event type to be compatible with both legacy plugin and content model editor + */ +export interface ContentModelBeforePasteEvent extends BeforePasteEvent { + /** + * domToModel Options to use when creating the content model from the paste fragment + */ + readonly domToModelOption: DomToModelOptionForPaste; + + /** + * customizedMerge Customized merge function to use when merging the paste fragment into the editor + */ + customizedMerge?: MergePastedContentFunc; +} diff --git a/packages-content-model/roosterjs-content-model-editor/test/editor/utils/eventConverterTest.ts b/packages-content-model/roosterjs-content-model-editor/test/editor/utils/eventConverterTest.ts index fe0752ef384..3adf797f5ec 100644 --- a/packages-content-model/roosterjs-content-model-editor/test/editor/utils/eventConverterTest.ts +++ b/packages-content-model/roosterjs-content-model-editor/test/editor/utils/eventConverterTest.ts @@ -8,6 +8,7 @@ import { } from 'roosterjs-editor-types'; import type { ContentChangedEvent, PluginEvent as OldEvent } from 'roosterjs-editor-types'; import type { PluginEvent as NewEvent } from 'roosterjs-content-model-types'; +import type { ContentModelBeforePasteEvent } from '../../../lib/publicTypes/ContentModelBeforePasteEvent'; describe('oldEventToNewEvent', () => { function runTest( @@ -744,7 +745,9 @@ describe('newEventToOldEvent', () => { preserveHtmlComments: false, unknownTagReplacement: null, }, - } + customizedMerge: mockedCustomizedMerge, + domToModelOption: mockedDomToModelOption, + } as ContentModelBeforePasteEvent ); }); @@ -792,7 +795,9 @@ describe('newEventToOldEvent', () => { htmlAttributes: mockedHTmlAttributes, pasteType: PasteType.AsImage, sanitizingOption: mockedSanitizeOption, - } + customizedMerge: mockedCustomizedMerge, + domToModelOption: mockedDomToModelOption, + } as ContentModelBeforePasteEvent ); }); diff --git a/versions.json b/versions.json index a1e188d5464..370bcc85dab 100644 --- a/versions.json +++ b/versions.json @@ -4,6 +4,7 @@ "packages-content-model": "0.24.0", "overrides": { "roosterjs-editor-core": "8.59.1", - "roosterjs-editor-plugins": "8.60.0" + "roosterjs-editor-plugins": "8.60.0", + "roosterjs-content-model-editor": "8.24.1" } -} \ No newline at end of file +}