Skip to content

Commit

Permalink
Merge branch 'master' into u/juliaroldi/trigger-link-space
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi authored Feb 6, 2025
2 parents 2008bc9 + f46f90e commit b4910d3
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/roosterjs-editor-adapter/lib/corePlugins/BridgePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ export class BridgePlugin implements ContextMenuProvider<any> {
onPluginEvent(event: PluginEvent) {
const oldEvent = this.cacheGetOldEvent(event);

if (oldEvent) {
const exclusivelyHandleEventPlugin = this.cacheGetExclusivelyHandlePlugin(event);
const exclusivelyHandleEventPlugin = this.cacheGetExclusivelyHandlePlugin(event);

if (exclusivelyHandleEventPlugin) {
this.handleEvent(exclusivelyHandleEventPlugin, oldEvent, event);
} else {
this.legacyPlugins.forEach(plugin => this.handleEvent(plugin, oldEvent, event));
}
if (exclusivelyHandleEventPlugin) {
this.handleEvent(exclusivelyHandleEventPlugin, oldEvent, event);
} else {
this.legacyPlugins.forEach(plugin => this.handleEvent(plugin, oldEvent, event));
}

if (oldEvent) {
Object.assign(event, oldEventToNewEvent(oldEvent, event));
}
}
Expand Down Expand Up @@ -165,17 +165,15 @@ export class BridgePlugin implements ContextMenuProvider<any> {
return cacheGetEventData(event, ExclusivelyHandleEventPluginKey, event => {
const oldEvent = this.cacheGetOldEvent(event);

if (oldEvent) {
for (let i = 0; i < this.legacyPlugins.length; i++) {
const plugin = this.legacyPlugins[i];
for (let i = 0; i < this.legacyPlugins.length; i++) {
const plugin = this.legacyPlugins[i];

if (plugin.willHandleEventExclusively?.(oldEvent)) {
return plugin;
}
if (oldEvent && plugin.willHandleEventExclusively?.(oldEvent)) {
return plugin;
}

if (isMixedPlugin(plugin) && plugin.willHandleEventExclusivelyV9?.(event)) {
return plugin;
}
if (isMixedPlugin(plugin) && plugin.willHandleEventExclusivelyV9?.(event)) {
return plugin;
}
}

Expand All @@ -200,10 +198,12 @@ export class BridgePlugin implements ContextMenuProvider<any> {

private handleEvent(
plugin: LegacyEditorPlugin,
oldEvent: LegacyPluginEvent,
oldEvent: LegacyPluginEvent | undefined,
newEvent: PluginEvent
) {
plugin.onPluginEvent?.(oldEvent);
if (oldEvent && plugin.onPluginEvent) {
plugin.onPluginEvent(oldEvent);
}

if (isMixedPlugin(plugin)) {
plugin.onPluginEventV9?.(newEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,4 +608,100 @@ describe('BridgePlugin', () => {

expect(disposeSpy).toHaveBeenCalledTimes(1);
});

it('MixedPlugin with event that is not supported in v8', () => {
const initializeV8Spy = jasmine.createSpy('initializeV8');
const initializeV9Spy = jasmine.createSpy('initializeV9');
const onPluginEventV8Spy = jasmine.createSpy('onPluginEventV8');
const onPluginEventV9Spy = jasmine.createSpy('onPluginEventV9');
const willHandleEventExclusivelyV8Spy = jasmine.createSpy('willHandleEventExclusivelyV8');
const willHandleEventExclusivelyV9Spy = jasmine.createSpy('willHandleEventExclusivelyV9');
const disposeSpy = jasmine.createSpy('dispose');

const mockedPlugin = {
initialize: initializeV8Spy,
initializeV9: initializeV9Spy,
onPluginEvent: onPluginEventV8Spy,
onPluginEventV9: onPluginEventV9Spy,
willHandleEventExclusively: willHandleEventExclusivelyV8Spy,
willHandleEventExclusivelyV9: willHandleEventExclusivelyV9Spy,
dispose: disposeSpy,
getName: () => '',
} as any;
const mockedEditor = {} as any;
const onInitializeSpy = jasmine.createSpy('onInitialize').and.returnValue(mockedEditor);
const plugin = new BridgePlugin.BridgePlugin(onInitializeSpy, [mockedPlugin]);

expect(initializeV8Spy).not.toHaveBeenCalled();
expect(initializeV9Spy).not.toHaveBeenCalled();
expect(onPluginEventV8Spy).not.toHaveBeenCalled();
expect(onPluginEventV9Spy).not.toHaveBeenCalled();
expect(disposeSpy).not.toHaveBeenCalled();
expect(onInitializeSpy).not.toHaveBeenCalled();
expect(willHandleEventExclusivelyV8Spy).not.toHaveBeenCalled();
expect(willHandleEventExclusivelyV9Spy).not.toHaveBeenCalled();

const mockedZoomScale = 'ZOOM' as any;
const calculateZoomScaleSpy = jasmine
.createSpy('calculateZoomScale')
.and.returnValue(mockedZoomScale);
const mockedColorManager = 'COLOR' as any;
const mockedInnerDarkColorHandler = 'INNERCOLOR' as any;
const mockedInnerEditor = {
getDOMHelper: () => ({
calculateZoomScale: calculateZoomScaleSpy,
}),
getColorManager: () => mockedInnerDarkColorHandler,
} as any;

const createDarkColorHandlerSpy = spyOn(
DarkColorHandler,
'createDarkColorHandler'
).and.returnValue(mockedColorManager);

plugin.initialize(mockedInnerEditor);

expect(onInitializeSpy).toHaveBeenCalledWith({
customData: {},
experimentalFeatures: [],
sizeTransformer: jasmine.anything(),
darkColorHandler: mockedColorManager,
edit: 'edit',
contextMenuProviders: [],
} as any);
expect(createDarkColorHandlerSpy).toHaveBeenCalledWith(mockedInnerDarkColorHandler);
expect(initializeV8Spy).toHaveBeenCalledTimes(1);
expect(initializeV9Spy).toHaveBeenCalledTimes(1);
expect(disposeSpy).not.toHaveBeenCalled();
expect(initializeV8Spy).toHaveBeenCalledWith(mockedEditor);
expect(initializeV9Spy).toHaveBeenCalledWith(mockedInnerEditor);
expect(onPluginEventV8Spy).not.toHaveBeenCalled();
expect(onPluginEventV9Spy).not.toHaveBeenCalled();
expect(willHandleEventExclusivelyV8Spy).not.toHaveBeenCalled();
expect(willHandleEventExclusivelyV9Spy).not.toHaveBeenCalled();

plugin.onPluginEvent({
eventType: 'rewriteFromModel',
addedBlockElements: [],
removedBlockElements: [],
});

expect(onPluginEventV8Spy).toHaveBeenCalledTimes(0);
expect(onPluginEventV9Spy).toHaveBeenCalledTimes(1);
expect(onPluginEventV9Spy).toHaveBeenCalledWith({
eventType: 'rewriteFromModel',
addedBlockElements: [],
removedBlockElements: [],
eventDataCache: {
__OldEventFromNewEvent: undefined,
__ExclusivelyHandleEventPlugin: null,
},
});
expect(willHandleEventExclusivelyV8Spy).toHaveBeenCalledTimes(0);
expect(willHandleEventExclusivelyV9Spy).toHaveBeenCalledTimes(1);

plugin.dispose();

expect(disposeSpy).toHaveBeenCalledTimes(1);
});
});

0 comments on commit b4910d3

Please sign in to comment.