From a8e46cd0a7f969ebcce45eb6fd04dda9b51ecd7a Mon Sep 17 00:00:00 2001 From: Jiuqing Song Date: Thu, 6 Jun 2024 12:17:07 -0700 Subject: [PATCH] improve --- .../lib/command/paste/mergePasteContent.ts | 2 +- .../lib/corePlugin/cache/domIndexerImpl.ts | 2 +- .../lib/constants}/EmptySegmentFormat.ts | 4 ++-- .../roosterjs-content-model-dom/lib/index.ts | 1 + .../lib/modelApi/editing/mergeModel.ts | 17 ++--------------- 5 files changed, 7 insertions(+), 19 deletions(-) rename packages/{roosterjs-content-model-core/lib/corePlugin/cache => roosterjs-content-model-dom/lib/constants}/EmptySegmentFormat.ts (67%) diff --git a/packages/roosterjs-content-model-core/lib/command/paste/mergePasteContent.ts b/packages/roosterjs-content-model-core/lib/command/paste/mergePasteContent.ts index c491851941b..1985248838c 100644 --- a/packages/roosterjs-content-model-core/lib/command/paste/mergePasteContent.ts +++ b/packages/roosterjs-content-model-core/lib/command/paste/mergePasteContent.ts @@ -1,7 +1,7 @@ import { createDomToModelContextForSanitizing } from '../createModelFromHtml/createDomToModelContextForSanitizing'; -import { EmptySegmentFormat } from '../../corePlugin/cache/EmptySegmentFormat'; import { ChangeSource, + EmptySegmentFormat, cloneModel, domToContentModel, getSegmentTextFormat, diff --git a/packages/roosterjs-content-model-core/lib/corePlugin/cache/domIndexerImpl.ts b/packages/roosterjs-content-model-core/lib/corePlugin/cache/domIndexerImpl.ts index 35ef9fdf4c5..41783fb0666 100644 --- a/packages/roosterjs-content-model-core/lib/corePlugin/cache/domIndexerImpl.ts +++ b/packages/roosterjs-content-model-core/lib/corePlugin/cache/domIndexerImpl.ts @@ -1,5 +1,5 @@ -import { EmptySegmentFormat } from './EmptySegmentFormat'; import { + EmptySegmentFormat, createSelectionMarker, createText, getObjectKeys, diff --git a/packages/roosterjs-content-model-core/lib/corePlugin/cache/EmptySegmentFormat.ts b/packages/roosterjs-content-model-dom/lib/constants/EmptySegmentFormat.ts similarity index 67% rename from packages/roosterjs-content-model-core/lib/corePlugin/cache/EmptySegmentFormat.ts rename to packages/roosterjs-content-model-dom/lib/constants/EmptySegmentFormat.ts index 5408d42f816..4eb04cf14be 100644 --- a/packages/roosterjs-content-model-core/lib/corePlugin/cache/EmptySegmentFormat.ts +++ b/packages/roosterjs-content-model-dom/lib/constants/EmptySegmentFormat.ts @@ -1,9 +1,9 @@ import type { ContentModelSegmentFormat } from 'roosterjs-content-model-types'; /** - * @internal + * Provide a default empty instance of segment format with all its properties */ -export const EmptySegmentFormat: Required = { +export const EmptySegmentFormat: Readonly> = { backgroundColor: '', fontFamily: '', fontSize: '', diff --git a/packages/roosterjs-content-model-dom/lib/index.ts b/packages/roosterjs-content-model-dom/lib/index.ts index d57626c233c..3b4dc813935 100644 --- a/packages/roosterjs-content-model-dom/lib/index.ts +++ b/packages/roosterjs-content-model-dom/lib/index.ts @@ -155,3 +155,4 @@ export { NumberingListType } from './constants/NumberingListType'; export { TableBorderFormat } from './constants/TableBorderFormat'; export { OrderedListStyleMap } from './constants/OrderedListStyleMap'; export { UnorderedListStyleMap } from './constants/UnorderedListStyleMap'; +export { EmptySegmentFormat } from './constants/EmptySegmentFormat'; diff --git a/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts b/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts index 94ed4f65319..dfdc35ed0a6 100644 --- a/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts +++ b/packages/roosterjs-content-model-dom/lib/modelApi/editing/mergeModel.ts @@ -5,6 +5,7 @@ import { createParagraph } from '../creators/createParagraph'; import { createSelectionMarker } from '../creators/createSelectionMarker'; import { createTableCell } from '../creators/createTableCell'; import { deleteSelection } from './deleteSelection'; +import { EmptySegmentFormat } from '../../constants/EmptySegmentFormat'; import { getClosestAncestorBlockGroupIndex } from './getClosestAncestorBlockGroupIndex'; import { getObjectKeys } from '../..//domUtils/getObjectKeys'; import { mutateBlock } from '../common/mutate'; @@ -29,21 +30,7 @@ import type { } from 'roosterjs-content-model-types'; const HeadingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; -// An object to provide keys of required properties of segment format, do NOT use any of its values -const RequiredEmptySegmentFormat: Required = { - backgroundColor: null!, - fontFamily: null!, - fontSize: null!, - fontWeight: null!, - italic: null!, - letterSpacing: null!, - lineHeight: null!, - strikethrough: null!, - superOrSubScriptSequence: null!, - textColor: null!, - underline: null!, -}; -const KeysOfSegmentFormat = getObjectKeys(RequiredEmptySegmentFormat); +const KeysOfSegmentFormat = getObjectKeys(EmptySegmentFormat); /** * Merge source model into target mode