From 08c69bf745227790645afe080aa1081f70a2ec2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Roldi?= Date: Thu, 6 Jun 2024 12:08:22 -0300 Subject: [PATCH] formatContentModel --- .../formatContentModel/formatContentModel.ts | 15 ++++----------- .../lib/autoFormat/AutoFormatPlugin.ts | 9 ++------- .../test/autoFormat/AutoFormatPluginTest.ts | 18 ------------------ 3 files changed, 6 insertions(+), 36 deletions(-) diff --git a/packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts b/packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts index bcebd23f23b..6a54afab304 100644 --- a/packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts +++ b/packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts @@ -24,15 +24,8 @@ export const formatContentModel: FormatContentModel = ( options, domToModelOptions ) => { - const { - apiName, - onNodeCreated, - getChangeData, - changeSource, - rawEvent, - selectionOverride, - scrollCaretIntoView, - } = options || {}; + const { onNodeCreated, getChangeData, rawEvent, selectionOverride, scrollCaretIntoView } = + options || {}; const model = core.api.createContentModel(core, domToModelOptions, selectionOverride); const context: FormatContentModelContext = { newEntities: [], @@ -82,9 +75,9 @@ export const formatContentModel: FormatContentModel = ( eventType: 'contentChanged', contentModel: clearModelCache ? undefined : model, selection: clearModelCache ? undefined : selection, - source: changeSource || ChangeSource.Format, + source: options?.changeSource || ChangeSource.Format, data: getChangeData?.(), - formatApiName: apiName, + formatApiName: options?.apiName, changedEntities: getChangedEntities(context, rawEvent), }; diff --git a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts index bdb3484c1fa..b0936bdf511 100644 --- a/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts +++ b/packages/roosterjs-content-model-plugins/lib/autoFormat/AutoFormatPlugin.ts @@ -220,14 +220,9 @@ export class AutoFormatPlugin implements EditorPlugin { shouldFraction || shouldOrdinals ); - } + }, + formatOptions ); - if (formatOptions.changeSource) { - editor.triggerEvent('contentChanged', { - source: formatOptions.changeSource, - formatApiName: formatOptions.apiName, - }); - } break; } diff --git a/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts b/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts index 7c741599870..9203fa27645 100644 --- a/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts +++ b/packages/roosterjs-content-model-plugins/test/autoFormat/AutoFormatPluginTest.ts @@ -108,10 +108,6 @@ describe('Content Model Auto Format Plugin Test', () => { changeSource: 'AutoFormat', apiName: formatOptions.apiName, }); - expect(triggerEventSpy).toHaveBeenCalledWith('contentChanged', { - source: 'AutoFormat', - formatApiName: formatOptions.apiName, - }); }); } @@ -397,10 +393,6 @@ describe('Content Model Auto Format Plugin Test', () => { changeSource: 'AutoFormat', apiName: formatOption.apiName, }); - expect(triggerEventSpy).toHaveBeenCalledWith('contentChanged', { - source: 'AutoFormat', - formatApiName: formatOption.apiName, - }); }); } @@ -481,11 +473,6 @@ describe('Content Model Auto Format Plugin Test', () => { changeSource: 'AutoFormat', apiName: formatOption.apiName, }); - - expect(triggerEventSpy).toHaveBeenCalledWith('contentChanged', { - source: 'AutoFormat', - formatApiName: formatOption.apiName, - }); }); } @@ -552,11 +539,6 @@ describe('Content Model Auto Format Plugin Test', () => { changeSource: 'AutoFormat', apiName: formatOption.apiName, }); - - expect(triggerEventSpy).toHaveBeenCalledWith('contentChanged', { - source: 'AutoFormat', - formatApiName: formatOption.apiName, - }); }); }