From 71f2291f6a2e080d082230dbe717e5afb1acc53a Mon Sep 17 00:00:00 2001 From: jiuqingsong Date: Mon, 30 Jan 2023 21:41:38 -0800 Subject: [PATCH 1/6] Content Model code simplify 1 --- .../editor/ExperimentalContentModelEditor.ts | 15 ++++------- .../controls/editor/isContentModelEditor.ts | 2 +- .../context/createModelToDomContext.ts | 1 - .../lib/modelToDom/handlers/handleEntity.ts | 2 +- .../publicApi/utils/formatWithContentModel.ts | 2 +- .../IExperimentalContentModelEditor.ts | 25 +------------------ .../context/ModelToDomEntityContext.ts | 5 ---- .../context/createModelToDomContextTest.ts | 3 --- .../publicApi/format/getFormatStateTest.ts | 2 +- .../publicApi/format/getSegmentFormatTest.ts | 2 +- .../publicApi/segment/changeFontSizeTest.ts | 2 +- 11 files changed, 12 insertions(+), 49 deletions(-) diff --git a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts index 4bc47edd64e..29b19f66067 100644 --- a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts +++ b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts @@ -39,7 +39,7 @@ export default class ExperimentalContentModelEditor extends Editor /** * Create a EditorContext object used by ContentModel API */ - createEditorContext(): EditorContext { + private createEditorContext(): EditorContext { return { isDarkMode: this.isDarkMode(), zoomScale: this.getZoomScale(), @@ -51,13 +51,10 @@ export default class ExperimentalContentModelEditor extends Editor /** * Create Content Model from DOM tree in this editor - * @param startNode Optional start node. If provided, Content Model will be created from this node (including itself), - * otherwise it will create Content Model for the whole content in editor. * @param option The option to customize the behavior of DOM to Content Model conversion */ - createContentModel(startNode?: HTMLElement, option?: DomToModelOption): ContentModelDocument { - return domToContentModel(startNode || this.contentDiv, this.createEditorContext(), { - includeRoot: !!startNode, + createContentModel(option?: DomToModelOption): ContentModelDocument { + return domToContentModel(this.contentDiv, this.createEditorContext(), { selectionRange: this.getSelectionRangeEx(), alwaysNormalizeTable: true, ...(option || {}), @@ -67,7 +64,6 @@ export default class ExperimentalContentModelEditor extends Editor /** * Set content with content model * @param model The content model to set - * @param mergingCallback A callback to indicate how should the new content be integrated into existing content * @param option Additional options to customize the behavior of Content Model to DOM conversion */ setContentModel(model: ContentModelDocument, option?: ModelToDomOption) { @@ -77,17 +73,16 @@ export default class ExperimentalContentModelEditor extends Editor this.createEditorContext(), option ); - const mergingCallback = option?.mergingCallback || restoreContentWithEntityPlaceholder; if (range?.type == SelectionRangeTypes.Normal) { // Need to get start and end from range position before merge because range can be changed during merging const start = Position.getStart(range.ranges[0]); const end = Position.getEnd(range.ranges[0]); - mergingCallback(fragment, this.contentDiv, entityPairs); + restoreContentWithEntityPlaceholder(fragment, this.contentDiv, entityPairs); this.select(start, end); } else { - mergingCallback(fragment, this.contentDiv, entityPairs); + restoreContentWithEntityPlaceholder(fragment, this.contentDiv, entityPairs); this.select(range); } } diff --git a/demo/scripts/controls/editor/isContentModelEditor.ts b/demo/scripts/controls/editor/isContentModelEditor.ts index e0aa9709076..d243ed87819 100644 --- a/demo/scripts/controls/editor/isContentModelEditor.ts +++ b/demo/scripts/controls/editor/isContentModelEditor.ts @@ -6,5 +6,5 @@ export default function isContentModelEditor( ): editor is IExperimentalContentModelEditor { const experimentalEditor = editor as IExperimentalContentModelEditor; - return !!experimentalEditor.createEditorContext && 'contentDiv' in experimentalEditor; + return !!experimentalEditor.createContentModel && 'contentDiv' in experimentalEditor; } diff --git a/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts b/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts index 88275067818..ef40e300dd9 100644 --- a/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts +++ b/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts @@ -51,6 +51,5 @@ export function createModelToDomContext( defaultModelHandlers: defaultContentModelHandlers, defaultFormatAppliers: defaultFormatAppliers, - doNotReuseEntityDom: !!options?.doNotReuseEntityDom, }; } diff --git a/packages/roosterjs-content-model/lib/modelToDom/handlers/handleEntity.ts b/packages/roosterjs-content-model/lib/modelToDom/handlers/handleEntity.ts index 898549a9c05..c10ea7e6503 100644 --- a/packages/roosterjs-content-model/lib/modelToDom/handlers/handleEntity.ts +++ b/packages/roosterjs-content-model/lib/modelToDom/handlers/handleEntity.ts @@ -38,7 +38,7 @@ export const handleEntity: ContentModelHandler = ( parent = span; } - if (context.doNotReuseEntityDom || !entity) { + if (!entity) { parent.appendChild(wrapper); } else { // Create a comment as placeholder and insert into DOM tree. diff --git a/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts index e34b0937f14..7cb1c0c9276 100644 --- a/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts @@ -14,7 +14,7 @@ export function formatWithContentModel( callback: (model: ContentModelDocument) => boolean, domToModelOptions?: DomToModelOption ) { - const model = editor.createContentModel(undefined /*rootNode*/, domToModelOptions); + const model = editor.createContentModel(domToModelOptions); if (callback(model)) { editor.addUndoSnapshot( diff --git a/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts b/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts index 4bc05a1d116..78c6976ae07 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts @@ -1,6 +1,5 @@ import { ContentModelDocument } from './group/ContentModelDocument'; import { ContentModelSegmentFormat } from './format/ContentModelSegmentFormat'; -import { EditorContext } from './context/EditorContext'; import { IEditor, SelectionRangeEx } from 'roosterjs-editor-types'; import { ContentModelHandlerMap, @@ -61,23 +60,6 @@ export interface DomToModelOption { * Options for creating ModelToDomContext */ export interface ModelToDomOption { - /** - * A callback to specify how to merge DOM tree generated from Content Model in to existing container - * @param source Source document fragment that is generated from Content Model - * @param target Target container, usually to be editor root container - * @param entities An array of entity wrapper - placeholder pairs, used for reuse existing DOM structure for entity - */ - mergingCallback?: ( - source: DocumentFragment, - target: HTMLElement, - entities: Record - ) => void; - - /** - * When set to true, directly put entity DOM nodes into the result DOM tree when doing Content Model to DOM conversion and do not use placeholder - */ - doNotReuseEntityDom?: boolean; - /** * Overrides default format appliers */ @@ -105,18 +87,13 @@ export interface ModelToDomOption { * An interface of editor with Content Model support (in experiment) */ export interface IExperimentalContentModelEditor extends IEditor { - /** - * Create a EditorContext object used by ContentModel API - */ - createEditorContext(): EditorContext; - /** * Create Content Model from DOM tree in this editor * @param rootNode Optional start node. If provided, Content Model will be created from this node (including itself), * otherwise it will create Content Model for the whole content in editor. * @param option The options to customize the behavior of DOM to Content Model conversion */ - createContentModel(rootNode?: HTMLElement, option?: DomToModelOption): ContentModelDocument; + createContentModel(option?: DomToModelOption): ContentModelDocument; /** * Set content with content model diff --git a/packages/roosterjs-content-model/lib/publicTypes/context/ModelToDomEntityContext.ts b/packages/roosterjs-content-model/lib/publicTypes/context/ModelToDomEntityContext.ts index d8e564d52cf..1dc2a28f229 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/context/ModelToDomEntityContext.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/context/ModelToDomEntityContext.ts @@ -2,11 +2,6 @@ * Represents context for entity */ export interface ModelToDomEntityContext { - /** - * When set to true, directly put entity DOM nodes into the result DOM tree when doing Content Model to DOM conversion and do not use placeholder - */ - doNotReuseEntityDom: boolean; - /** * Entities collected during DOM tree generation, used for reusing existing DOM structure of entities */ diff --git a/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts b/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts index 761bf479e19..ad883a70120 100644 --- a/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts +++ b/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts @@ -34,7 +34,6 @@ describe('createModelToDomContext', () => { entities: {}, defaultModelHandlers: defaultContentModelHandlers, defaultFormatAppliers: defaultFormatAppliers, - doNotReuseEntityDom: false, }; it('no param', () => { const context = createModelToDomContext(); @@ -59,13 +58,11 @@ describe('createModelToDomContext', () => { }); it('with overrides', () => { - const mockedMergingCallback = 'mergingCallback' as any; const mockedBoldApplier = 'bold' as any; const mockedBlockApplier = 'block' as any; const mockedBrHandler = 'br' as any; const mockedAStyle = 'a' as any; const context = createModelToDomContext(undefined, { - mergingCallback: mockedMergingCallback, formatApplierOverride: { bold: mockedBoldApplier, }, diff --git a/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts b/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts index 77e37f741b4..8c5ea3e7da6 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts @@ -33,7 +33,7 @@ describe('getFormatState', () => { isDarkMode: () => false, getZoomScale: () => 1, getPendingFormat: () => pendingFormat, - createContentModel: (root: Node, options: DomToModelOption) => { + createContentModel: (options: DomToModelOption) => { const model = createContentModelDocument(); const editorDiv = document.createElement('div'); diff --git a/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts b/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts index 64e8257ed2e..d72b27c7b7f 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts @@ -27,7 +27,7 @@ describe('getSegmentFormat', () => { isDarkMode: () => false, getZoomScale: () => 1, getPendingFormat: () => pendingFormat, - createContentModel: (root: Node, options: DomToModelOption) => { + createContentModel: (options: DomToModelOption) => { const model = createContentModelDocument(); const editorDiv = document.createElement('div'); diff --git a/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts b/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts index b6466f36dc1..a4d4d15f688 100644 --- a/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts @@ -294,7 +294,7 @@ describe('changeFontSize', () => { div.style.fontSize = '20pt'; const editor = ({ - createContentModel: (startNode: any, option: any) => + createContentModel: (option: any) => domToContentModel(div, null!, { selectionRange: { type: SelectionRangeTypes.Normal, From 9ccde35b19b59929611a94fbe86725fc103cd704 Mon Sep 17 00:00:00 2001 From: jiuqingsong Date: Mon, 30 Jan 2023 23:06:38 -0800 Subject: [PATCH 2/6] Content Model: Clean up EditorContext --- .../editor/ExperimentalContentModelEditor.ts | 8 +- .../context/createDomToModelContext.ts | 7 +- .../domToModel/context/defaultProcessors.ts | 2 + .../domToModel/processors/rootProcessor.ts | 14 +++ .../domToModel/processors/tableProcessor.ts | 2 +- .../root/rootDirectionFormatHandler.ts | 16 ++++ .../root/zoomScaleFormatHandler.ts | 18 ++++ packages/roosterjs-content-model/lib/index.ts | 1 + .../lib/modelApi/common/insertContent.ts | 2 - .../context/createModelToDomContext.ts | 2 - .../lib/publicApi/domToContentModel.ts | 10 +- .../context/DomToModelFormatContext.ts | 6 ++ .../publicTypes/context/DomToModelSettings.ts | 5 + .../lib/publicTypes/context/EditorContext.ts | 10 -- .../format/formatParts/ZoomScaleFormat.ts | 9 ++ .../context/createDomToModelContextTest.ts | 31 ++---- .../context/createModelToDomContextTest.ts | 4 - .../processors/rootProcessorTest.ts | 87 +++++++++++++++++ .../processors/tableProcessorTest.ts | 2 +- .../block/directionFormatHandlerTest.ts | 2 +- .../root/rootDirectionFormatHandlerTest.ts | 84 +++++++++++++++++ .../root/zoomScaleFormatHandlerTest.ts | 94 +++++++++++++++++++ .../test/publicApi/domToContentModelTest.ts | 81 ++++++++++++++++ 23 files changed, 437 insertions(+), 60 deletions(-) create mode 100644 packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts create mode 100644 packages/roosterjs-content-model/lib/formatHandlers/root/rootDirectionFormatHandler.ts create mode 100644 packages/roosterjs-content-model/lib/formatHandlers/root/zoomScaleFormatHandler.ts create mode 100644 packages/roosterjs-content-model/lib/publicTypes/format/formatParts/ZoomScaleFormat.ts create mode 100644 packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts create mode 100644 packages/roosterjs-content-model/test/formatHandlers/root/rootDirectionFormatHandlerTest.ts create mode 100644 packages/roosterjs-content-model/test/formatHandlers/root/zoomScaleFormatHandlerTest.ts create mode 100644 packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts diff --git a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts index 29b19f66067..a979548ee47 100644 --- a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts +++ b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts @@ -1,5 +1,6 @@ import { Editor } from 'roosterjs-editor-core'; import { EditorOptions, SelectionRangeTypes } from 'roosterjs-editor-types'; +import { Position, restoreContentWithEntityPlaceholder } from 'roosterjs-editor-dom'; import { ContentModelDocument, ContentModelSegmentFormat, @@ -10,11 +11,6 @@ import { IExperimentalContentModelEditor, ModelToDomOption, } from 'roosterjs-content-model'; -import { - getComputedStyles, - Position, - restoreContentWithEntityPlaceholder, -} from 'roosterjs-editor-dom'; /** * !!! This is a temporary interface and will be removed in the future !!! @@ -42,8 +38,6 @@ export default class ExperimentalContentModelEditor extends Editor private createEditorContext(): EditorContext { return { isDarkMode: this.isDarkMode(), - zoomScale: this.getZoomScale(), - isRightToLeft: getComputedStyles(this.contentDiv, 'direction')[0] == 'rtl', getDarkColor: this.getDarkColor, darkColorHandler: this.getDarkColorHandler(), }; diff --git a/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts b/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts index 38653d33f6a..d8f350d6e79 100644 --- a/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts +++ b/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts @@ -16,13 +16,12 @@ export function createDomToModelContext( const context: DomToModelContext = { ...(editorContext || { isDarkMode: false, - zoomScale: 1, - isRightToLeft: false, getDarkColor: undefined, }), blockFormat: {}, segmentFormat: {}, + zoomScaleFormat: {}, isInSelection: false, listFormat: { @@ -53,10 +52,6 @@ export function createDomToModelContext( defaultFormatParsers: defaultFormatParsers, }; - if (editorContext?.isRightToLeft) { - context.blockFormat.direction = 'rtl'; - } - if (options?.alwaysNormalizeTable) { context.alwaysNormalizeTable = true; } diff --git a/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts b/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts index 95524fc2112..75696a1b8f3 100644 --- a/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts +++ b/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts @@ -11,6 +11,7 @@ import { knownElementProcessor } from '../processors/knownElementProcessor'; import { listItemProcessor } from '../processors/listItemProcessor'; import { listProcessor } from '../processors/listProcessor'; import { quoteProcessor } from '../processors/quoteProcessor'; +import { rootProcessor } from '../processors/rootProcessor'; import { tableProcessor } from '../processors/tableProcessor'; import { textProcessor } from '../processors/textProcessor'; @@ -53,6 +54,7 @@ export const defaultProcessorMap: ElementProcessorMap = { '*': generalProcessor, '#text': textProcessor, element: elementProcessor, + root: rootProcessor, entity: entityProcessor, child: childProcessor, }; diff --git a/packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts b/packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts new file mode 100644 index 00000000000..ab00d35f79b --- /dev/null +++ b/packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts @@ -0,0 +1,14 @@ +import { ElementProcessor } from '../../publicTypes/context/ElementProcessor'; +import { parseFormat } from '../utils/parseFormat'; +import { rootDirectionFormatHandler } from '../../formatHandlers/root/rootDirectionFormatHandler'; +import { zoomScaleFormatHandler } from '../../formatHandlers/root/zoomScaleFormatHandler'; + +/** + * @internal + */ +export const rootProcessor: ElementProcessor = (group, element, context) => { + parseFormat(element, [rootDirectionFormatHandler.parse], context.blockFormat, context); + parseFormat(element, [zoomScaleFormatHandler.parse], context.zoomScaleFormat, context); + + context.elementProcessors.child(group, element, context); +}; diff --git a/packages/roosterjs-content-model/lib/domToModel/processors/tableProcessor.ts b/packages/roosterjs-content-model/lib/domToModel/processors/tableProcessor.ts index dfa13ab56fe..c051be85e48 100644 --- a/packages/roosterjs-content-model/lib/domToModel/processors/tableProcessor.ts +++ b/packages/roosterjs-content-model/lib/domToModel/processors/tableProcessor.ts @@ -43,7 +43,7 @@ export const tableProcessor: ElementProcessor = ( const columnPositions: number[] = [0]; const rowPositions: number[] = [0]; - const zoomScale = context.zoomScale; + const zoomScale = context.zoomScaleFormat.zoomScale || 1; for (let row = 0; row < tableElement.rows.length; row++) { const tr = tableElement.rows[row]; diff --git a/packages/roosterjs-content-model/lib/formatHandlers/root/rootDirectionFormatHandler.ts b/packages/roosterjs-content-model/lib/formatHandlers/root/rootDirectionFormatHandler.ts new file mode 100644 index 00000000000..c05b9780a08 --- /dev/null +++ b/packages/roosterjs-content-model/lib/formatHandlers/root/rootDirectionFormatHandler.ts @@ -0,0 +1,16 @@ +import { DirectionFormat } from '../../publicTypes/format/formatParts/DirectionFormat'; +import { FormatHandler } from '../FormatHandler'; + +/** + * @internal + */ +export const rootDirectionFormatHandler: FormatHandler = { + parse: (format, element) => { + const style = element.ownerDocument.defaultView?.getComputedStyle(element); + + if (style?.direction == 'rtl') { + format.direction = 'rtl'; + } + }, + apply: () => {}, +}; diff --git a/packages/roosterjs-content-model/lib/formatHandlers/root/zoomScaleFormatHandler.ts b/packages/roosterjs-content-model/lib/formatHandlers/root/zoomScaleFormatHandler.ts new file mode 100644 index 00000000000..a5c81825c73 --- /dev/null +++ b/packages/roosterjs-content-model/lib/formatHandlers/root/zoomScaleFormatHandler.ts @@ -0,0 +1,18 @@ +import { FormatHandler } from '../FormatHandler'; +import { ZoomScaleFormat } from '../../publicTypes/format/formatParts/ZoomScaleFormat'; + +/** + * @internal + */ +export const zoomScaleFormatHandler: FormatHandler = { + parse: (format, element) => { + const originalWidth = element.getBoundingClientRect().width; + const visualWidth = element.offsetWidth; + + format.zoomScale = + visualWidth > 0 && originalWidth > 0 + ? Math.round((originalWidth / visualWidth) * 100) / 100 + : 1; + }, + apply: () => {}, +}; diff --git a/packages/roosterjs-content-model/lib/index.ts b/packages/roosterjs-content-model/lib/index.ts index 9f1c7076af1..9c7fa0248de 100644 --- a/packages/roosterjs-content-model/lib/index.ts +++ b/packages/roosterjs-content-model/lib/index.ts @@ -118,6 +118,7 @@ export { export { DatasetFormat } from './publicTypes/format/formatParts/DatasetFormat'; export { WhiteSpaceFormat } from './publicTypes/format/formatParts/WhiteSpaceFormat'; export { WordBreakFormat } from './publicTypes/format/formatParts/WordBreakFormat'; +export { ZoomScaleFormat } from './publicTypes/format/formatParts/ZoomScaleFormat'; export { ContentModelFormatMap } from './publicTypes/format/ContentModelFormatMap'; diff --git a/packages/roosterjs-content-model/lib/modelApi/common/insertContent.ts b/packages/roosterjs-content-model/lib/modelApi/common/insertContent.ts index 2b4a16a73fa..25bbfcf8d3f 100644 --- a/packages/roosterjs-content-model/lib/modelApi/common/insertContent.ts +++ b/packages/roosterjs-content-model/lib/modelApi/common/insertContent.ts @@ -21,8 +21,6 @@ export function insertContent( htmlContent, { isDarkMode: !!isFromDarkMode, - zoomScale: 1, - isRightToLeft: false, }, { includeRoot: true, diff --git a/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts b/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts index ef40e300dd9..162bd8eaf25 100644 --- a/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts +++ b/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts @@ -20,8 +20,6 @@ export function createModelToDomContext( return { ...(editorContext || { isDarkMode: false, - isRightToLeft: false, - zoomScale: 1, getDarkColor: undefined, }), regularSelection: { diff --git a/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts index a0a862fcd07..4351560f960 100644 --- a/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts @@ -7,22 +7,22 @@ import { normalizeContentModel } from '../modelApi/common/normalizeContentModel' /** * Create Content Model from DOM tree in this editor - * @param root Root element of DOM tree to create Content Model from + * @param rootElement Root element of DOM tree to create Content Model from * @param editorContext Context of content model editor * @param option The option to customize the behavior of DOM to Content Model conversion * @returns A ContentModelDocument object that contains all the models created from the give root element */ export default function domToContentModel( - root: HTMLElement, + rootElement: HTMLElement, editorContext: EditorContext, option: DomToModelOption ): ContentModelDocument { const model = createContentModelDocument(); const domToModelContext = createDomToModelContext(editorContext, option); - const { element, child } = domToModelContext.elementProcessors; - const processor = option.includeRoot ? element : child; + const { element, root } = domToModelContext.elementProcessors; + const processor = option.includeRoot ? element : root; - processor(model, root, domToModelContext); + processor(model, rootElement, domToModelContext); normalizeContentModel(model); diff --git a/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelFormatContext.ts b/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelFormatContext.ts index e37e5911581..de302ed4417 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelFormatContext.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelFormatContext.ts @@ -3,6 +3,7 @@ import { ContentModelBlockGroup } from '../group/ContentModelBlockGroup'; import { ContentModelLink } from '../decorator/ContentModelLink'; import { ContentModelListItemLevelFormat } from '../format/ContentModelListItemLevelFormat'; import { ContentModelSegmentFormat } from '../format/ContentModelSegmentFormat'; +import { ZoomScaleFormat } from '../format/formatParts/ZoomScaleFormat'; /** * Represents the context object used when do DOM to Content Model conversion and processing a List @@ -48,6 +49,11 @@ export interface DomToModelFormatContext { */ link: ContentModelLink; + /** + * Zoom scale of the content + */ + zoomScaleFormat: ZoomScaleFormat; + /** * When process table, whether we should always normalize it. * This can help persist the size of table that is not created from Content Model diff --git a/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts b/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts index 9139d3dd38b..c82741d4ab2 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts @@ -82,6 +82,11 @@ export type ElementProcessorMap = { */ child: ElementProcessor; + /** + * Processor for root element when root is not included in Content Model since we still need to get some format from root (e.g. rtl direction) + */ + root: ElementProcessor; + /** * Workaround for typescript 4.4.4 that doesn't have element "strike" in its element type */ diff --git a/packages/roosterjs-content-model/lib/publicTypes/context/EditorContext.ts b/packages/roosterjs-content-model/lib/publicTypes/context/EditorContext.ts index ef773d3ed3c..b8a514859fd 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/context/EditorContext.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/context/EditorContext.ts @@ -9,16 +9,6 @@ export interface EditorContext { */ isDarkMode: boolean; - /** - * Zoom scale of the content - */ - zoomScale: number; - - /** - * Whether current content is from right to left - */ - isRightToLeft: boolean; - /** * Calculate color for dark mode * @param lightColor Light mode color diff --git a/packages/roosterjs-content-model/lib/publicTypes/format/formatParts/ZoomScaleFormat.ts b/packages/roosterjs-content-model/lib/publicTypes/format/formatParts/ZoomScaleFormat.ts new file mode 100644 index 00000000000..2de9a3646a3 --- /dev/null +++ b/packages/roosterjs-content-model/lib/publicTypes/format/formatParts/ZoomScaleFormat.ts @@ -0,0 +1,9 @@ +/** + * Format of scale + */ +export type ZoomScaleFormat = { + /** + * Zoom scale number + */ + zoomScale?: number; +}; diff --git a/packages/roosterjs-content-model/test/domToModel/context/createDomToModelContextTest.ts b/packages/roosterjs-content-model/test/domToModel/context/createDomToModelContextTest.ts index a8fed150ad9..69288caa339 100644 --- a/packages/roosterjs-content-model/test/domToModel/context/createDomToModelContextTest.ts +++ b/packages/roosterjs-content-model/test/domToModel/context/createDomToModelContextTest.ts @@ -12,8 +12,6 @@ import { describe('createDomToModelContext', () => { const editorContext: EditorContext = { isDarkMode: false, - zoomScale: 1, - isRightToLeft: false, getDarkColor: undefined, }; const listFormat: DomToModelListFormat = { @@ -34,6 +32,7 @@ describe('createDomToModelContext', () => { ...editorContext, segmentFormat: {}, blockFormat: {}, + zoomScaleFormat: {}, isInSelection: false, listFormat, link: { @@ -47,8 +46,6 @@ describe('createDomToModelContext', () => { it('with content model context', () => { const editorContext: EditorContext = { isDarkMode: true, - zoomScale: 2, - isRightToLeft: true, getDarkColor: () => '', }; @@ -57,9 +54,8 @@ describe('createDomToModelContext', () => { expect(context).toEqual({ ...editorContext, segmentFormat: {}, - blockFormat: { - direction: 'rtl', - }, + blockFormat: {}, + zoomScaleFormat: {}, isInSelection: false, listFormat, link: { @@ -92,6 +88,7 @@ describe('createDomToModelContext', () => { ...editorContext, segmentFormat: {}, blockFormat: {}, + zoomScaleFormat: {}, isInSelection: false, regularSelection: { startContainer: 'DIV 1' as any, @@ -129,6 +126,7 @@ describe('createDomToModelContext', () => { ...editorContext, segmentFormat: {}, blockFormat: {}, + zoomScaleFormat: {}, isInSelection: false, tableSelection: { table: mockTable, @@ -160,6 +158,7 @@ describe('createDomToModelContext', () => { ...editorContext, segmentFormat: {}, blockFormat: {}, + zoomScaleFormat: {}, link: { format: {}, dataset: {}, @@ -180,8 +179,6 @@ describe('createDomToModelContext', () => { const context = createDomToModelContext( { isDarkMode: true, - zoomScale: 2, - isRightToLeft: true, getDarkColor, }, { @@ -195,13 +192,10 @@ describe('createDomToModelContext', () => { expect(context).toEqual({ isDarkMode: true, - zoomScale: 2, - isRightToLeft: true, getDarkColor: getDarkColor, isInSelection: false, - blockFormat: { - direction: 'rtl', - }, + blockFormat: {}, + zoomScaleFormat: {}, segmentFormat: {}, listFormat, link: { @@ -218,8 +212,6 @@ describe('createDomToModelContext', () => { const context = createDomToModelContext( { isDarkMode: true, - zoomScale: 2, - isRightToLeft: true, getDarkColor, }, { @@ -235,13 +227,10 @@ describe('createDomToModelContext', () => { expect(context).toEqual({ isDarkMode: true, - zoomScale: 2, - isRightToLeft: true, getDarkColor: getDarkColor, isInSelection: false, - blockFormat: { - direction: 'rtl', - }, + blockFormat: {}, + zoomScaleFormat: {}, segmentFormat: {}, link: { format: {}, diff --git a/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts b/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts index ad883a70120..059fac27524 100644 --- a/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts +++ b/packages/roosterjs-content-model/test/domToModel/context/createModelToDomContextTest.ts @@ -11,8 +11,6 @@ import { describe('createModelToDomContext', () => { const editorContext: EditorContext = { isDarkMode: false, - zoomScale: 1, - isRightToLeft: false, getDarkColor: undefined, }; const defaultResult: ModelToDomContext = { @@ -44,8 +42,6 @@ describe('createModelToDomContext', () => { it('with content model context', () => { const editorContext: EditorContext = { isDarkMode: true, - zoomScale: 2, - isRightToLeft: true, getDarkColor: () => '', }; diff --git a/packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts b/packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts new file mode 100644 index 00000000000..e4a0bf29516 --- /dev/null +++ b/packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts @@ -0,0 +1,87 @@ +import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; +import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; +import { DomToModelContext } from '../../../lib/publicTypes/context/DomToModelContext'; +import { rootProcessor } from '../../../lib/domToModel/processors/rootProcessor'; + +describe('rootProcessor', () => { + let context: DomToModelContext; + + beforeEach(() => { + context = createDomToModelContext(); + }); + + it('Simple empty element', () => { + const div = document.createElement('div'); + const doc = createContentModelDocument(); + const childProcessor = jasmine.createSpy('childProcessor'); + + context.elementProcessors.child = childProcessor; + + rootProcessor(doc, div, context); + + expect(doc).toEqual({ + blockGroupType: 'Document', + blocks: [], + }); + expect(context.blockFormat).toEqual({}); + expect(context.zoomScaleFormat).toEqual({ + zoomScale: 1, + }); + expect(childProcessor).toHaveBeenCalledTimes(1); + expect(childProcessor).toHaveBeenCalledWith(doc, div, context); + }); + + it('Div with zoom scale', () => { + const div = ({ + tagName: 'DIV', + ownerDocument: { + defaultView: { + getComputedStyle: () => ({}), + }, + }, + getBoundingClientRect: () => ({ width: 100 }), + offsetWidth: 200, + } as any) as HTMLElement; + const doc = createContentModelDocument(); + + rootProcessor(doc, div, context); + + expect(doc).toEqual({ + blockGroupType: 'Document', + blocks: [], + }); + expect(context.blockFormat).toEqual({}); + expect(context.zoomScaleFormat).toEqual({ + zoomScale: 0.5, + }); + }); + + it('Div in RTL', () => { + const div = ({ + tagName: 'DIV', + ownerDocument: { + defaultView: { + getComputedStyle: () => ({ + direction: 'rtl', + }), + }, + }, + getBoundingClientRect: () => ({ width: 0 }), + offsetWidth: 0, + } as any) as HTMLElement; + const doc = createContentModelDocument(); + + rootProcessor(doc, div, context); + + expect(doc).toEqual({ + blockGroupType: 'Document', + blocks: [], + }); + expect(context.blockFormat).toEqual({ + direction: 'rtl', + }); + expect(context.zoomScaleFormat).toEqual({ + zoomScale: 1, + }); + }); +}); diff --git a/packages/roosterjs-content-model/test/domToModel/processors/tableProcessorTest.ts b/packages/roosterjs-content-model/test/domToModel/processors/tableProcessorTest.ts index 16dcd06116e..e2fd70bee98 100644 --- a/packages/roosterjs-content-model/test/domToModel/processors/tableProcessorTest.ts +++ b/packages/roosterjs-content-model/test/domToModel/processors/tableProcessorTest.ts @@ -318,7 +318,7 @@ describe('tableProcessor with format', () => { } as any) as HTMLTableElement; const doc = createContentModelDocument(); - context.zoomScale = 2; + context.zoomScaleFormat.zoomScale = 2; tableProcessor(doc, mockedTable, context); diff --git a/packages/roosterjs-content-model/test/formatHandlers/block/directionFormatHandlerTest.ts b/packages/roosterjs-content-model/test/formatHandlers/block/directionFormatHandlerTest.ts index 6c543482e0c..899699586f2 100644 --- a/packages/roosterjs-content-model/test/formatHandlers/block/directionFormatHandlerTest.ts +++ b/packages/roosterjs-content-model/test/formatHandlers/block/directionFormatHandlerTest.ts @@ -87,7 +87,7 @@ describe('directionFormatHandler.parse', () => { }); it('RTL', () => { - context.isRightToLeft = true; + context.blockFormat.direction = 'rtl'; runTest('left', null, 'rtl', null, 'end', 'rtl', undefined); runTest('center', null, 'rtl', null, 'center', 'rtl', undefined); diff --git a/packages/roosterjs-content-model/test/formatHandlers/root/rootDirectionFormatHandlerTest.ts b/packages/roosterjs-content-model/test/formatHandlers/root/rootDirectionFormatHandlerTest.ts new file mode 100644 index 00000000000..c932c5b9201 --- /dev/null +++ b/packages/roosterjs-content-model/test/formatHandlers/root/rootDirectionFormatHandlerTest.ts @@ -0,0 +1,84 @@ +import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; +import { createModelToDomContext } from '../../../lib/modelToDom/context/createModelToDomContext'; +import { DirectionFormat } from '../../../lib/publicTypes/format/formatParts/DirectionFormat'; +import { DomToModelContext } from '../../../lib/publicTypes/context/DomToModelContext'; +import { ModelToDomContext } from '../../../lib/publicTypes/context/ModelToDomContext'; +import { rootDirectionFormatHandler } from '../../../lib/formatHandlers/root/rootDirectionFormatHandler'; + +describe('rootDirectionFormatHandler.parse', () => { + let div: HTMLElement; + let context: DomToModelContext; + let format: DirectionFormat; + + beforeEach(() => { + div = document.createElement('div'); + context = createDomToModelContext(); + format = {}; + }); + + it('No direction', () => { + rootDirectionFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({}); + }); + + it('LTR from CSS', () => { + div.style.direction = 'ltr'; + + rootDirectionFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({}); + }); + + it('LTR from attribute', () => { + div.dir = 'ltr'; + + rootDirectionFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({}); + }); + + it('RTL from CSS', () => { + div.style.direction = 'rtl'; + + rootDirectionFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({}); + }); + + it('RTL from attribute', () => { + div.dir = 'rtl'; + + rootDirectionFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({}); + }); +}); + +describe('rootDirectionFormatHandler.apply', () => { + let div: HTMLElement; + let format: DirectionFormat; + let context: ModelToDomContext; + + beforeEach(() => { + div = document.createElement('div'); + format = {}; + context = createModelToDomContext(); + }); + + it('ltr', () => { + format.direction = 'ltr'; + + rootDirectionFormatHandler.apply(format, div, context); + + expect(div.outerHTML).toEqual('
'); + }); + + it('rtl', () => { + format.direction = 'rtl'; + + rootDirectionFormatHandler.apply(format, div, context); + + expect(div.outerHTML).toEqual('
'); + }); +}); diff --git a/packages/roosterjs-content-model/test/formatHandlers/root/zoomScaleFormatHandlerTest.ts b/packages/roosterjs-content-model/test/formatHandlers/root/zoomScaleFormatHandlerTest.ts new file mode 100644 index 00000000000..e117d46d313 --- /dev/null +++ b/packages/roosterjs-content-model/test/formatHandlers/root/zoomScaleFormatHandlerTest.ts @@ -0,0 +1,94 @@ +import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; +import { createModelToDomContext } from '../../../lib/modelToDom/context/createModelToDomContext'; +import { DomToModelContext } from '../../../lib/publicTypes/context/DomToModelContext'; +import { ModelToDomContext } from '../../../lib/publicTypes/context/ModelToDomContext'; +import { ZoomScaleFormat } from '../../../lib/publicTypes/format/formatParts/ZoomScaleFormat'; +import { zoomScaleFormatHandler } from '../../../lib/formatHandlers/root/zoomScaleFormatHandler'; + +describe('zoomScaleFormatHandler.parse', () => { + let div: HTMLElement; + let context: DomToModelContext; + let format: ZoomScaleFormat; + + beforeEach(() => { + div = ({ + tagName: 'DIV', + ownerDocument: { + defaultView: { + getComputedStyle: () => ({}), + }, + }, + getBoundingClientRect: () => ({ width: 100 }), + } as any) as HTMLElement; + context = createDomToModelContext(); + format = {}; + }); + + it('No zoom scale', () => { + (div).offsetWidth = undefined; + + zoomScaleFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({ + zoomScale: 1, + }); + }); + + it('Zoom scale = 1', () => { + (div).offsetWidth = 100; + + zoomScaleFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({ + zoomScale: 1, + }); + }); + + it('Zoom scale = 2', () => { + (div).offsetWidth = 50; + + zoomScaleFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({ + zoomScale: 2, + }); + }); + + it('Zoom scale = 0.5', () => { + (div).offsetWidth = 200; + + zoomScaleFormatHandler.parse(format, div, context, {}); + + expect(format).toEqual({ + zoomScale: 0.5, + }); + }); +}); + +describe('zoomScaleFormatHandler.apply', () => { + let div: HTMLElement; + let format: ZoomScaleFormat; + let context: ModelToDomContext; + + beforeEach(() => { + div = document.createElement('div'); + format = {}; + context = createModelToDomContext(); + }); + + it('zoom 1', () => { + format.zoomScale = 1; + + zoomScaleFormatHandler.apply(format, div, context); + + expect(div.outerHTML).toEqual('
'); + }); + + it('zoom 2', () => { + format.zoomScale = 2; + + zoomScaleFormatHandler.apply(format, div, context); + + expect(div.outerHTML).toEqual('
'); + }); +}); diff --git a/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts new file mode 100644 index 00000000000..7db9c29ddb9 --- /dev/null +++ b/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts @@ -0,0 +1,81 @@ +import * as createDomToModelContext from '../../lib/domToModel/context/createDomToModelContext'; +import * as normalizeContentModel from '../../lib/modelApi/common/normalizeContentModel'; +import domToContentModel from '../../lib/publicApi/domToContentModel'; +import { ContentModelDocument } from '../../lib/publicTypes/group/ContentModelDocument'; +import { DomToModelContext } from '../../lib/publicTypes/context/DomToModelContext'; + +describe('domToContentModel', () => { + it('Not include root', () => { + const elementProcessor = jasmine.createSpy('elementProcessor'); + const rootProcessor = jasmine.createSpy('rootProcessor'); + const mockContext = ({ + elementProcessors: { + element: elementProcessor, + root: rootProcessor, + }, + } as any) as DomToModelContext; + + spyOn(createDomToModelContext, 'createDomToModelContext').and.returnValue(mockContext); + spyOn(normalizeContentModel, 'normalizeContentModel'); + + const rootElement = document.createElement('div'); + const options = { + includeRoot: false, + }; + const editorContext = { isDarkMode: false }; + const model = domToContentModel(rootElement, editorContext, options); + const result: ContentModelDocument = { + blockGroupType: 'Document', + blocks: [], + }; + + expect(model).toEqual(result); + expect(createDomToModelContext.createDomToModelContext).toHaveBeenCalledTimes(1); + expect(createDomToModelContext.createDomToModelContext).toHaveBeenCalledWith( + editorContext, + options + ); + expect(elementProcessor).not.toHaveBeenCalled(); + expect(rootProcessor).toHaveBeenCalledTimes(1); + expect(rootProcessor).toHaveBeenCalledWith(result, rootElement, mockContext); + expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledTimes(1); + expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledWith(result); + }); + + it('Include root', () => { + const elementProcessor = jasmine.createSpy('elementProcessor'); + const rootProcessor = jasmine.createSpy('rootProcessor'); + const mockContext = ({ + elementProcessors: { + element: elementProcessor, + root: rootProcessor, + }, + } as any) as DomToModelContext; + + spyOn(createDomToModelContext, 'createDomToModelContext').and.returnValue(mockContext); + spyOn(normalizeContentModel, 'normalizeContentModel'); + + const rootElement = document.createElement('div'); + const options = { + includeRoot: true, + }; + const editorContext = { isDarkMode: false }; + const model = domToContentModel(rootElement, editorContext, options); + const result: ContentModelDocument = { + blockGroupType: 'Document', + blocks: [], + }; + + expect(model).toEqual(result); + expect(createDomToModelContext.createDomToModelContext).toHaveBeenCalledTimes(1); + expect(createDomToModelContext.createDomToModelContext).toHaveBeenCalledWith( + editorContext, + options + ); + expect(rootProcessor).not.toHaveBeenCalled(); + expect(elementProcessor).toHaveBeenCalledTimes(1); + expect(elementProcessor).toHaveBeenCalledWith(result, rootElement, mockContext); + expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledTimes(1); + expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledWith(result); + }); +}); From 63c0d3d09d924ba831ae48bcb9249b83c879f77e Mon Sep 17 00:00:00 2001 From: jiuqingsong Date: Mon, 30 Jan 2023 23:29:43 -0800 Subject: [PATCH 3/6] improve --- .../domToModel/context/defaultProcessors.ts | 2 - .../domToModel/processors/rootProcessor.ts | 14 --- .../lib/publicApi/domToContentModel.ts | 20 +++-- .../publicTypes/context/DomToModelSettings.ts | 5 -- .../processors/rootProcessorTest.ts | 87 ------------------- .../test/publicApi/domToContentModelTest.ts | 18 ++-- 6 files changed, 25 insertions(+), 121 deletions(-) delete mode 100644 packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts delete mode 100644 packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts diff --git a/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts b/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts index 75696a1b8f3..95524fc2112 100644 --- a/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts +++ b/packages/roosterjs-content-model/lib/domToModel/context/defaultProcessors.ts @@ -11,7 +11,6 @@ import { knownElementProcessor } from '../processors/knownElementProcessor'; import { listItemProcessor } from '../processors/listItemProcessor'; import { listProcessor } from '../processors/listProcessor'; import { quoteProcessor } from '../processors/quoteProcessor'; -import { rootProcessor } from '../processors/rootProcessor'; import { tableProcessor } from '../processors/tableProcessor'; import { textProcessor } from '../processors/textProcessor'; @@ -54,7 +53,6 @@ export const defaultProcessorMap: ElementProcessorMap = { '*': generalProcessor, '#text': textProcessor, element: elementProcessor, - root: rootProcessor, entity: entityProcessor, child: childProcessor, }; diff --git a/packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts b/packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts deleted file mode 100644 index ab00d35f79b..00000000000 --- a/packages/roosterjs-content-model/lib/domToModel/processors/rootProcessor.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ElementProcessor } from '../../publicTypes/context/ElementProcessor'; -import { parseFormat } from '../utils/parseFormat'; -import { rootDirectionFormatHandler } from '../../formatHandlers/root/rootDirectionFormatHandler'; -import { zoomScaleFormatHandler } from '../../formatHandlers/root/zoomScaleFormatHandler'; - -/** - * @internal - */ -export const rootProcessor: ElementProcessor = (group, element, context) => { - parseFormat(element, [rootDirectionFormatHandler.parse], context.blockFormat, context); - parseFormat(element, [zoomScaleFormatHandler.parse], context.zoomScaleFormat, context); - - context.elementProcessors.child(group, element, context); -}; diff --git a/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts index 4351560f960..4b8f2b9437d 100644 --- a/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts @@ -4,25 +4,33 @@ import { createDomToModelContext } from '../domToModel/context/createDomToModelC import { DomToModelOption } from '../publicTypes/IExperimentalContentModelEditor'; import { EditorContext } from '../publicTypes/context/EditorContext'; import { normalizeContentModel } from '../modelApi/common/normalizeContentModel'; +import { parseFormat } from '../domToModel/utils/parseFormat'; +import { rootDirectionFormatHandler } from '../formatHandlers/root/rootDirectionFormatHandler'; +import { zoomScaleFormatHandler } from '../formatHandlers/root/zoomScaleFormatHandler'; /** * Create Content Model from DOM tree in this editor - * @param rootElement Root element of DOM tree to create Content Model from + * @param root Root element of DOM tree to create Content Model from * @param editorContext Context of content model editor * @param option The option to customize the behavior of DOM to Content Model conversion * @returns A ContentModelDocument object that contains all the models created from the give root element */ export default function domToContentModel( - rootElement: HTMLElement, + root: HTMLElement, editorContext: EditorContext, option: DomToModelOption ): ContentModelDocument { const model = createContentModelDocument(); - const domToModelContext = createDomToModelContext(editorContext, option); - const { element, root } = domToModelContext.elementProcessors; - const processor = option.includeRoot ? element : root; + const context = createDomToModelContext(editorContext, option); - processor(model, rootElement, domToModelContext); + parseFormat(root, [rootDirectionFormatHandler.parse], context.blockFormat, context); + parseFormat(root, [zoomScaleFormatHandler.parse], context.zoomScaleFormat, context); + + const processor = option.includeRoot + ? context.elementProcessors.element + : context.elementProcessors.child; + + processor(model, root, context); normalizeContentModel(model); diff --git a/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts b/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts index c82741d4ab2..9139d3dd38b 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/context/DomToModelSettings.ts @@ -82,11 +82,6 @@ export type ElementProcessorMap = { */ child: ElementProcessor; - /** - * Processor for root element when root is not included in Content Model since we still need to get some format from root (e.g. rtl direction) - */ - root: ElementProcessor; - /** * Workaround for typescript 4.4.4 that doesn't have element "strike" in its element type */ diff --git a/packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts b/packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts deleted file mode 100644 index e4a0bf29516..00000000000 --- a/packages/roosterjs-content-model/test/domToModel/processors/rootProcessorTest.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; -import { createDomToModelContext } from '../../../lib/domToModel/context/createDomToModelContext'; -import { DomToModelContext } from '../../../lib/publicTypes/context/DomToModelContext'; -import { rootProcessor } from '../../../lib/domToModel/processors/rootProcessor'; - -describe('rootProcessor', () => { - let context: DomToModelContext; - - beforeEach(() => { - context = createDomToModelContext(); - }); - - it('Simple empty element', () => { - const div = document.createElement('div'); - const doc = createContentModelDocument(); - const childProcessor = jasmine.createSpy('childProcessor'); - - context.elementProcessors.child = childProcessor; - - rootProcessor(doc, div, context); - - expect(doc).toEqual({ - blockGroupType: 'Document', - blocks: [], - }); - expect(context.blockFormat).toEqual({}); - expect(context.zoomScaleFormat).toEqual({ - zoomScale: 1, - }); - expect(childProcessor).toHaveBeenCalledTimes(1); - expect(childProcessor).toHaveBeenCalledWith(doc, div, context); - }); - - it('Div with zoom scale', () => { - const div = ({ - tagName: 'DIV', - ownerDocument: { - defaultView: { - getComputedStyle: () => ({}), - }, - }, - getBoundingClientRect: () => ({ width: 100 }), - offsetWidth: 200, - } as any) as HTMLElement; - const doc = createContentModelDocument(); - - rootProcessor(doc, div, context); - - expect(doc).toEqual({ - blockGroupType: 'Document', - blocks: [], - }); - expect(context.blockFormat).toEqual({}); - expect(context.zoomScaleFormat).toEqual({ - zoomScale: 0.5, - }); - }); - - it('Div in RTL', () => { - const div = ({ - tagName: 'DIV', - ownerDocument: { - defaultView: { - getComputedStyle: () => ({ - direction: 'rtl', - }), - }, - }, - getBoundingClientRect: () => ({ width: 0 }), - offsetWidth: 0, - } as any) as HTMLElement; - const doc = createContentModelDocument(); - - rootProcessor(doc, div, context); - - expect(doc).toEqual({ - blockGroupType: 'Document', - blocks: [], - }); - expect(context.blockFormat).toEqual({ - direction: 'rtl', - }); - expect(context.zoomScaleFormat).toEqual({ - zoomScale: 1, - }); - }); -}); diff --git a/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts index 7db9c29ddb9..7cbbbb18879 100644 --- a/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/domToContentModelTest.ts @@ -7,12 +7,14 @@ import { DomToModelContext } from '../../lib/publicTypes/context/DomToModelConte describe('domToContentModel', () => { it('Not include root', () => { const elementProcessor = jasmine.createSpy('elementProcessor'); - const rootProcessor = jasmine.createSpy('rootProcessor'); + const childProcessor = jasmine.createSpy('childProcessor'); const mockContext = ({ elementProcessors: { element: elementProcessor, - root: rootProcessor, + child: childProcessor, }, + defaultStyles: {}, + zoomScaleFormat: {}, } as any) as DomToModelContext; spyOn(createDomToModelContext, 'createDomToModelContext').and.returnValue(mockContext); @@ -36,20 +38,22 @@ describe('domToContentModel', () => { options ); expect(elementProcessor).not.toHaveBeenCalled(); - expect(rootProcessor).toHaveBeenCalledTimes(1); - expect(rootProcessor).toHaveBeenCalledWith(result, rootElement, mockContext); + expect(childProcessor).toHaveBeenCalledTimes(1); + expect(childProcessor).toHaveBeenCalledWith(result, rootElement, mockContext); expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledTimes(1); expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledWith(result); }); it('Include root', () => { const elementProcessor = jasmine.createSpy('elementProcessor'); - const rootProcessor = jasmine.createSpy('rootProcessor'); + const childProcessor = jasmine.createSpy('childProcessor'); const mockContext = ({ elementProcessors: { element: elementProcessor, - root: rootProcessor, + child: childProcessor, }, + defaultStyles: {}, + zoomScaleFormat: {}, } as any) as DomToModelContext; spyOn(createDomToModelContext, 'createDomToModelContext').and.returnValue(mockContext); @@ -72,7 +76,7 @@ describe('domToContentModel', () => { editorContext, options ); - expect(rootProcessor).not.toHaveBeenCalled(); + expect(childProcessor).not.toHaveBeenCalled(); expect(elementProcessor).toHaveBeenCalledTimes(1); expect(elementProcessor).toHaveBeenCalledWith(result, rootElement, mockContext); expect(normalizeContentModel.normalizeContentModel).toHaveBeenCalledTimes(1); From 5e478da966d7c4965c9d18eeea81356632f1865f Mon Sep 17 00:00:00 2001 From: jiuqingsong Date: Tue, 31 Jan 2023 22:37:39 -0800 Subject: [PATCH 4/6] Content Model: Remove get/setPendingFormat --- .../editor/ExperimentalContentModelEditor.ts | 18 --- .../lib/publicApi/format/getFormatState.ts | 3 +- .../lib/publicApi/format/getSegmentFormat.ts | 3 +- .../lib/publicApi/format/pendingFormat.ts | 38 ++++++ .../utils/formatSegmentWithContentModel.ts | 5 +- .../lib/publicPlugin/ContentModelPlugin.ts | 7 +- .../IExperimentalContentModelEditor.ts | 13 -- .../publicApi/block/paragraphTestCommon.ts | 3 - .../publicApi/block/setIndentationTest.ts | 3 - .../publicApi/block/toggleBlockQuoteTest.ts | 3 - .../publicApi/format/getFormatStateTest.ts | 5 +- .../publicApi/format/getSegmentFormatTest.ts | 4 +- .../test/publicApi/insert/insertImageTest.ts | 3 - .../test/publicApi/list/toggleBulletTest.ts | 3 - .../publicApi/list/toggleNumberingTest.ts | 3 - .../publicApi/segment/changeFontSizeTest.ts | 55 +++++++- .../publicApi/segment/segmentTestCommon.ts | 7 +- .../formatParagraphWithContentModelTest.ts | 3 - .../formatSegmentWithContentModelTest.ts | 10 +- .../utils/formatWithContentModelTest.ts | 3 - .../publicPlugin/ContentModelPluginTest.ts | 123 +++++++++--------- 21 files changed, 177 insertions(+), 138 deletions(-) create mode 100644 packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts diff --git a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts index a979548ee47..2f7b205b93b 100644 --- a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts +++ b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts @@ -3,7 +3,6 @@ import { EditorOptions, SelectionRangeTypes } from 'roosterjs-editor-types'; import { Position, restoreContentWithEntityPlaceholder } from 'roosterjs-editor-dom'; import { ContentModelDocument, - ContentModelSegmentFormat, contentModelToDom, domToContentModel, DomToModelOption, @@ -20,7 +19,6 @@ import { export default class ExperimentalContentModelEditor extends Editor implements IExperimentalContentModelEditor { private getDarkColor: ((lightColor: string) => string) | undefined; - private pendingFormat: ContentModelSegmentFormat | null = null; /** * Creates an instance of ExperimentalContentModelEditor @@ -80,20 +78,4 @@ export default class ExperimentalContentModelEditor extends Editor this.select(range); } } - - /** - * Get current pending format if any. A pending format is a format that user set when selection is collapsed, - * it will be applied when next time user input something - */ - getPendingFormat(): ContentModelSegmentFormat | null { - return this.pendingFormat; - } - - /** - * Set current pending format if any. A pending format is a format that user set when selection is collapsed, - * it will be applied when next time user input something - */ - setPendingFormat(format: ContentModelSegmentFormat | null) { - this.pendingFormat = format; - } } diff --git a/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts b/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts index caaa66c6414..f5732c7f39d 100644 --- a/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts +++ b/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts @@ -1,5 +1,6 @@ import { FormatState } from 'roosterjs-editor-types'; import { formatWithContentModel } from '../utils/formatWithContentModel'; +import { getPendingFormat } from './pendingFormat'; import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; import { reducedModelChildProcessor } from '../../domToModel/processors/reducedModelChildProcessor'; import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState'; @@ -20,7 +21,7 @@ export default function getFormatState(editor: IExperimentalContentModelEditor): editor, 'getFormatState', model => { - const pendingFormat = editor.getPendingFormat(); + const pendingFormat = getPendingFormat(editor); retrieveModelFormatState(model, pendingFormat, result); diff --git a/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts b/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts index 8fe81ae6a95..586edda213b 100644 --- a/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts +++ b/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts @@ -1,5 +1,6 @@ import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; import { formatWithContentModel } from '../utils/formatWithContentModel'; +import { getPendingFormat } from './pendingFormat'; import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; import { iterateSelections } from '../../modelApi/selection/iterateSelections'; import { reducedModelChildProcessor } from '../../domToModel/processors/reducedModelChildProcessor'; @@ -11,7 +12,7 @@ import { reducedModelChildProcessor } from '../../domToModel/processors/reducedM export default function getSegmentFormat( editor: IExperimentalContentModelEditor ): ContentModelSegmentFormat | null { - let result = editor.getPendingFormat() || null; + let result = getPendingFormat(editor); if (!result) { formatWithContentModel( diff --git a/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts b/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts new file mode 100644 index 00000000000..301ca082bbc --- /dev/null +++ b/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts @@ -0,0 +1,38 @@ +import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; +import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; + +/** + * @internal + * Get pending segment format from editor if any, otherwise null + * @param editor The editor to get format from + */ +export function getPendingFormat( + editor: IExperimentalContentModelEditor +): ContentModelSegmentFormat | null { + return getPendingFormatHolder(editor).format; +} + +/** + * @internal + * Set pending segment format to editor + * @param editor The editor to set pending format to + * @param format The format to set. Pass null to clear existing format + */ +export function setPendingFormat( + editor: IExperimentalContentModelEditor, + format: ContentModelSegmentFormat | null +) { + getPendingFormatHolder(editor).format = format; +} + +interface PendingFormatHolder { + format: ContentModelSegmentFormat | null; +} + +const PendingFormatHolderKey = '__ContentModelPendingFormat'; + +function getPendingFormatHolder(editor: IExperimentalContentModelEditor): PendingFormatHolder { + return editor.getCustomData(PendingFormatHolderKey, () => ({ + format: null, + })); +} diff --git a/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts index 8e1e6548a34..efe3a1a61f5 100644 --- a/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts @@ -2,6 +2,7 @@ import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelectio import { ContentModelSegment } from '../../publicTypes/segment/ContentModelSegment'; import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; import { formatWithContentModel } from './formatWithContentModel'; +import { getPendingFormat, setPendingFormat } from '../format/pendingFormat'; import { getSelectedSegments } from '../../modelApi/selection/collectSelections'; import { DomToModelOption, @@ -30,7 +31,7 @@ export function formatSegmentWithContentModel( apiName, model => { let segments = getSelectedSegments(model, !!includingFormatHolder); - const pendingFormat = editor.getPendingFormat(); + const pendingFormat = getPendingFormat(editor); let isCollapsedSelection = segments.length == 1 && segments[0].segmentType == 'SelectionMarker'; @@ -59,7 +60,7 @@ export function formatSegmentWithContentModel( ); if (!pendingFormat && isCollapsedSelection) { - editor.setPendingFormat(segments[0].format); + setPendingFormat(editor, segments[0].format); } if (isCollapsedSelection) { diff --git a/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts b/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts index a3550d55e0c..c35331bd568 100644 --- a/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts +++ b/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts @@ -1,6 +1,7 @@ import { ContentModelSegmentFormat } from '../publicTypes/format/ContentModelSegmentFormat'; import { createText } from '../modelApi/creators/createText'; import { EditorPlugin, IEditor, Keys, PluginEvent, PluginEventType } from 'roosterjs-editor-types'; +import { getPendingFormat, setPendingFormat } from '../publicApi/format/pendingFormat'; import { IExperimentalContentModelEditor } from '../publicTypes/IExperimentalContentModelEditor'; import { iterateSelections } from '../modelApi/selection/iterateSelections'; @@ -55,10 +56,10 @@ export default class ContentModelPlugin implements EditorPlugin { !this.editor.isInIME()) || // In Safari, isComposing will be undfined but isInIME() works event.eventType == PluginEventType.CompositionEnd) && event.rawEvent.data && - (format = this.editor.getPendingFormat()) + (format = getPendingFormat(this.editor)) ) { applyPendingFormat(this.editor, event.rawEvent.data, format); - this.editor.setPendingFormat(null); + setPendingFormat(this.editor, null); } if ( @@ -68,7 +69,7 @@ export default class ContentModelPlugin implements EditorPlugin { event.eventType == PluginEventType.MouseDown || event.eventType == PluginEventType.ContentChanged ) { - this.editor.setPendingFormat(null); + setPendingFormat(this.editor, null); } } } diff --git a/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts b/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts index 78c6976ae07..7bb5c54c224 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts @@ -1,5 +1,4 @@ import { ContentModelDocument } from './group/ContentModelDocument'; -import { ContentModelSegmentFormat } from './format/ContentModelSegmentFormat'; import { IEditor, SelectionRangeEx } from 'roosterjs-editor-types'; import { ContentModelHandlerMap, @@ -101,16 +100,4 @@ export interface IExperimentalContentModelEditor extends IEditor { * @param option Additional options to customize the behavior of Content Model to DOM conversion */ setContentModel(model: ContentModelDocument, option?: ModelToDomOption): void; - - /** - * Get current pending format if any. A pending format is a format that user set when selection is collapsed, - * it will be applied when next time user input something - */ - getPendingFormat(): ContentModelSegmentFormat | null; - - /** - * Set current pending format if any. A pending format is a format that user set when selection is collapsed, - * it will be applied when next time user input something - */ - setPendingFormat(format: ContentModelSegmentFormat | null): void; } diff --git a/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts b/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts index aaba220c1f6..ae804e305eb 100644 --- a/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts +++ b/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts @@ -1,5 +1,4 @@ import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; export function paragraphTestCommon( @@ -24,8 +23,6 @@ export function paragraphTestCommon( addUndoSnapshot, focus: jasmine.createSpy(), setContentModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; executionCallback(editor); diff --git a/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts b/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts index 71e1d938343..5d9c88e0df8 100644 --- a/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts @@ -1,7 +1,6 @@ import * as formatWithContentModel from '../../../lib/publicApi/utils/formatWithContentModel'; import * as setModelIndentation from '../../../lib/modelApi/block/setModelIndentation'; import setIndentation from '../../../lib/publicApi/block/setIndentation'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; describe('setIndentation', () => { @@ -11,8 +10,6 @@ describe('setIndentation', () => { beforeEach(() => { editor = ({ createContentModel: () => fakeModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; }); diff --git a/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts b/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts index 7e3e5aef496..c1bb6179582 100644 --- a/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts @@ -1,7 +1,6 @@ import * as formatWithContentModel from '../../../lib/publicApi/utils/formatWithContentModel'; import * as toggleModelBlockQuote from '../../../lib/modelApi/block/toggleModelBlockQuote'; import toggleBlockQuote from '../../../lib/publicApi/block/toggleBlockQuote'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; describe('toggleBlockQuote', () => { @@ -11,8 +10,6 @@ describe('toggleBlockQuote', () => { beforeEach(() => { editor = ({ createContentModel: () => fakeModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; }); diff --git a/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts b/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts index 8c5ea3e7da6..07dd7f795c1 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts @@ -1,3 +1,4 @@ +import * as getPendingFormat from '../../../lib/publicApi/format/pendingFormat'; import * as retrieveModelFormatState from '../../../lib/modelApi/common/retrieveModelFormatState'; import getFormatState from '../../../lib/publicApi/format/getFormatState'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; @@ -32,7 +33,6 @@ describe('getFormatState', () => { }), isDarkMode: () => false, getZoomScale: () => 1, - getPendingFormat: () => pendingFormat, createContentModel: (options: DomToModelOption) => { const model = createContentModelDocument(); const editorDiv = document.createElement('div'); @@ -55,6 +55,9 @@ describe('getFormatState', () => { return model; }, } as any) as IExperimentalContentModelEditor; + + spyOn(getPendingFormat, 'getPendingFormat').and.returnValue(pendingFormat); + const result = getFormatState(editor); expect(retrieveModelFormatState.retrieveModelFormatState).toHaveBeenCalledTimes(1); diff --git a/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts b/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts index d72b27c7b7f..aa300bd63d5 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts @@ -1,3 +1,4 @@ +import * as getPendingFormat from '../../../lib/publicApi/format/pendingFormat'; import getSegmentFormat from '../../../lib/publicApi/format/getSegmentFormat'; import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; @@ -19,6 +20,8 @@ describe('getSegmentFormat', () => { pendingFormat: ContentModelSegmentFormat | null, expectedFormat: ContentModelSegmentFormat | null ) { + spyOn(getPendingFormat, 'getPendingFormat').and.returnValue(pendingFormat); + const editor = ({ getUndoState: () => ({ canUndo: false, @@ -26,7 +29,6 @@ describe('getSegmentFormat', () => { }), isDarkMode: () => false, getZoomScale: () => 1, - getPendingFormat: () => pendingFormat, createContentModel: (options: DomToModelOption) => { const model = createContentModelDocument(); const editorDiv = document.createElement('div'); diff --git a/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts b/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts index eafe2295e18..fcbc14dab32 100644 --- a/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts @@ -2,7 +2,6 @@ import * as readFile from 'roosterjs-editor-dom/lib/utils/readFile'; import insertImage from '../../../lib/publicApi/insert/insertImage'; import { addSegment } from '../../../lib/modelApi/common/addSegment'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; import { createSelectionMarker } from '../../../lib/modelApi/creators/createSelectionMarker'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; @@ -36,8 +35,6 @@ describe('insertImage', () => { setContentModel, isDisposed: () => false, getDocument: () => document, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; executionCallback(editor); diff --git a/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts b/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts index 8f0264a0985..def21f3af0a 100644 --- a/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts @@ -1,7 +1,6 @@ import * as setListType from '../../../lib/modelApi/list/setListType'; import toggleBullet from '../../../lib/publicApi/list/toggleBullet'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; describe('toggleBullet', () => { @@ -25,8 +24,6 @@ describe('toggleBullet', () => { addUndoSnapshot, createContentModel, setContentModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; spyOn(setListType, 'setListType').and.returnValue(true); diff --git a/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts b/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts index 783544c5187..d1bd9899437 100644 --- a/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts @@ -1,7 +1,6 @@ import * as setListType from '../../../lib/modelApi/list/setListType'; import toggleNumbering from '../../../lib/publicApi/list/toggleNumbering'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; describe('toggleNumbering', () => { @@ -25,8 +24,6 @@ describe('toggleNumbering', () => { addUndoSnapshot, createContentModel, setContentModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; spyOn(setListType, 'setListType').and.returnValue(true); diff --git a/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts b/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts index a4d4d15f688..820599c1285 100644 --- a/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts @@ -1,4 +1,5 @@ import * as getComputedStyles from 'roosterjs-editor-dom/lib/utils/getComputedStyles'; +import * as pendingFormat from '../../../lib/publicApi/format/pendingFormat'; import changeFontSize from '../../../lib/publicApi/segment/changeFontSize'; import domToContentModel from '../../../lib/publicApi/domToContentModel'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; @@ -258,30 +259,78 @@ describe('changeFontSize', () => { ); } - it('increase pt', () => { + it('increase pt 1', () => { testSizeChange('7pt', '8pt', 'increase'); + }); + + it('increase pt 2', () => { testSizeChange('8pt', '9pt', 'increase'); + }); + + it('increase pt 3', () => { testSizeChange('28pt', '36pt', 'increase'); + }); + + it('increase pt 4', () => { testSizeChange('37pt', '48pt', 'increase'); + }); + + it('increase pt 5', () => { testSizeChange('72pt', '80pt', 'increase'); + }); + + it('increase pt 6', () => { testSizeChange('80pt', '90pt', 'increase'); + }); + + it('increase pt 7', () => { testSizeChange('990pt', '1000pt', 'increase'); + }); + + it('increase pt 8', () => { testSizeChange('1000pt', '1000pt', 'increase'); }); - it('decrease pt', () => { + it('decrease pt 1', () => { testSizeChange('1pt', '1pt', 'decrease'); + }); + + it('decrease pt 2', () => { testSizeChange('7pt', '6pt', 'decrease'); + }); + + it('decrease pt 3', () => { testSizeChange('8pt', '7pt', 'decrease'); + }); + + it('decrease pt 4', () => { testSizeChange('28pt', '26pt', 'decrease'); + }); + + it('decrease pt 5', () => { testSizeChange('37pt', '36pt', 'decrease'); + }); + + it('decrease pt 6', () => { testSizeChange('72pt', '48pt', 'decrease'); + }); + + it('decrease pt 7', () => { testSizeChange('80pt', '72pt', 'decrease'); + }); + + it('decrease pt 8', () => { testSizeChange('990pt', '980pt', 'decrease'); + }); + + it('decrease pt 9', () => { testSizeChange('1000pt', '990pt', 'decrease'); }); it('Test format parser', () => { + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue(null); + const addUndoSnapshot = jasmine.createSpy().and.callFake((callback: () => void) => { callback(); }); @@ -307,8 +356,6 @@ describe('changeFontSize', () => { addUndoSnapshot, focus: jasmine.createSpy(), setContentModel, - getPendingFormat: () => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; spyOn(getComputedStyles, 'getComputedStyle').and.callFake( diff --git a/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts b/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts index d4d9be74c91..a739284e658 100644 --- a/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts +++ b/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts @@ -1,5 +1,5 @@ +import * as pendingFormat from '../../../lib/publicApi/format/pendingFormat'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; export function segmentTestCommon( @@ -9,6 +9,9 @@ export function segmentTestCommon( result: ContentModelDocument, calledTimes: number ) { + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue(null); + const addUndoSnapshot = jasmine .createSpy() .and.callFake((callback: () => void, source: string, canUndoByBackspace, param: any) => { @@ -24,8 +27,6 @@ export function segmentTestCommon( addUndoSnapshot, focus: jasmine.createSpy(), setContentModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; executionCallback(editor); diff --git a/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts index 637265c289a..6176705838a 100644 --- a/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts @@ -1,5 +1,4 @@ import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; import { createParagraph } from '../../../lib/modelApi/creators/createParagraph'; import { createText } from '../../../lib/modelApi/creators/createText'; @@ -25,8 +24,6 @@ describe('formatParagraphWithContentModel', () => { addUndoSnapshot, createContentModel: () => model, setContentModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; }); diff --git a/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts index 4360c24bac6..c0558f23f6b 100644 --- a/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts @@ -1,3 +1,4 @@ +import * as pendingFormat from '../../../lib/publicApi/format/pendingFormat'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; @@ -22,16 +23,15 @@ describe('formatSegmentWithContentModel', () => { addUndoSnapshot = jasmine.createSpy('addUndoSnapshot').and.callFake(callback => callback()); setContentModel = jasmine.createSpy('setContentModel'); focus = jasmine.createSpy('focus'); - getPendingFormat = jasmine.createSpy('getPendingFormat'); - setPendingFormat = jasmine.createSpy('setPendingFormat'); + + setPendingFormat = spyOn(pendingFormat, 'setPendingFormat'); + getPendingFormat = spyOn(pendingFormat, 'getPendingFormat'); editor = ({ focus, addUndoSnapshot, createContentModel: () => model, setContentModel, - getPendingFormat: getPendingFormat, - setPendingFormat: setPendingFormat, } as any) as IExperimentalContentModelEditor; }); @@ -240,7 +240,7 @@ describe('formatSegmentWithContentModel', () => { expect(addUndoSnapshot).toHaveBeenCalledTimes(0); expect(getPendingFormat).toHaveBeenCalledTimes(1); expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith({ + expect(setPendingFormat).toHaveBeenCalledWith(editor, { fontSize: '10px', fontFamily: 'test', }); diff --git a/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts index 1ce41cfb659..4e9c5ab09bc 100644 --- a/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts @@ -1,6 +1,5 @@ import { ChangeSource } from 'roosterjs-editor-types'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { ContentModelSegmentFormat } from '../../../lib/publicTypes/format/ContentModelSegmentFormat'; import { formatWithContentModel } from '../../../lib/publicApi/utils/formatWithContentModel'; import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; @@ -27,8 +26,6 @@ describe('formatWithContentModel', () => { addUndoSnapshot, createContentModel, setContentModel, - getPendingFormat: (): ContentModelSegmentFormat | null => null, - setPendingFormat: () => {}, } as any) as IExperimentalContentModelEditor; }); diff --git a/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts b/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts index 3f141eda913..72b7ad473f9 100644 --- a/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts +++ b/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts @@ -1,18 +1,18 @@ +import * as pendingFormat from '../../lib/publicApi/format/pendingFormat'; import ContentModelPlugin from '../../lib/publicPlugin/ContentModelPlugin'; import { addSegment } from '../../lib/modelApi/common/addSegment'; import { createContentModelDocument } from '../../lib/modelApi/creators/createContentModelDocument'; import { createSelectionMarker } from '../../lib/modelApi/creators/createSelectionMarker'; import { createText } from '../../lib/modelApi/creators/createText'; -import { FormatState, PluginEventType } from 'roosterjs-editor-types'; import { IExperimentalContentModelEditor } from '../../lib/publicTypes/IExperimentalContentModelEditor'; +import { PluginEventType } from 'roosterjs-editor-types'; describe('ContentModelPlugin', () => { it('no pending format, trigger key down event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); - const editor = ({ - getPendingFormat: (): FormatState | null => null, - setPendingFormat, - } as any) as IExperimentalContentModelEditor; + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue(null); + + const editor = ({} as any) as IExperimentalContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -24,19 +24,19 @@ describe('ContentModelPlugin', () => { plugin.dispose(); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); it('no selection, trigger input event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, isInIME: () => false, } as any) as IExperimentalContentModelEditor; @@ -53,12 +53,15 @@ describe('ContentModelPlugin', () => { plugin.dispose(); expect(setContentModel).toHaveBeenCalledTimes(0); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); it('with pending format and selection, has correct text before, trigger input event with isComposing = true', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const marker = createSelectionMarker(); @@ -66,11 +69,7 @@ describe('ContentModelPlugin', () => { addSegment(model, marker); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, } as any) as IExperimentalContentModelEditor; const plugin = new ContentModelPlugin(); @@ -83,11 +82,15 @@ describe('ContentModelPlugin', () => { plugin.dispose(); expect(setContentModel).toHaveBeenCalledTimes(0); - expect(setPendingFormat).toHaveBeenCalledTimes(0); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(0); }); it('with pending format and selection, no correct text before, trigger input event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const marker = createSelectionMarker(); @@ -95,11 +98,7 @@ describe('ContentModelPlugin', () => { addSegment(model, marker); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, isInIME: () => false, } as any) as IExperimentalContentModelEditor; @@ -113,12 +112,16 @@ describe('ContentModelPlugin', () => { plugin.dispose(); expect(setContentModel).toHaveBeenCalledTimes(0); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); it('with pending format and selection, has correct text before, trigger input event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const text = createText('a'); @@ -128,11 +131,7 @@ describe('ContentModelPlugin', () => { addSegment(model, marker); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, isInIME: () => false, } as any) as IExperimentalContentModelEditor; @@ -173,12 +172,16 @@ describe('ContentModelPlugin', () => { }, ], }); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); it('with pending format and selection, has correct text before, trigger CompositionEnd event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const text = createText('test a test', { fontFamily: 'Arial' }); @@ -188,11 +191,7 @@ describe('ContentModelPlugin', () => { addSegment(model, marker); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, } as any) as IExperimentalContentModelEditor; const plugin = new ContentModelPlugin(); @@ -232,21 +231,21 @@ describe('ContentModelPlugin', () => { }, ], }); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); it('Non-input and cursor moving key down should not trigger pending format change', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, } as any) as IExperimentalContentModelEditor; const plugin = new ContentModelPlugin(); @@ -259,20 +258,20 @@ describe('ContentModelPlugin', () => { plugin.dispose(); expect(setContentModel).toHaveBeenCalledTimes(0); - expect(setPendingFormat).toHaveBeenCalledTimes(0); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(0); }); it('Content changed event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, } as any) as IExperimentalContentModelEditor; const plugin = new ContentModelPlugin(); @@ -285,21 +284,21 @@ describe('ContentModelPlugin', () => { plugin.dispose(); expect(setContentModel).toHaveBeenCalledTimes(0); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); it('Mouse down event', () => { - const setPendingFormat = jasmine.createSpy('setPendingFormat'); + spyOn(pendingFormat, 'setPendingFormat'); + spyOn(pendingFormat, 'getPendingFormat').and.returnValue({ + fontSize: '10px', + }); + const setContentModel = jasmine.createSpy('setContentModel'); const model = createContentModelDocument(); const editor = ({ - getPendingFormat: (): FormatState | null => ({ - fontSize: '10px', - }), createContentModel: () => model, - setPendingFormat, setContentModel, } as any) as IExperimentalContentModelEditor; const plugin = new ContentModelPlugin(); @@ -312,7 +311,7 @@ describe('ContentModelPlugin', () => { plugin.dispose(); expect(setContentModel).toHaveBeenCalledTimes(0); - expect(setPendingFormat).toHaveBeenCalledTimes(1); - expect(setPendingFormat).toHaveBeenCalledWith(null); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledTimes(1); + expect(pendingFormat.setPendingFormat).toHaveBeenCalledWith(editor, null); }); }); From e0c22a6b412fdf2611bdc82200d63c405460220d Mon Sep 17 00:00:00 2001 From: jiuqingsong Date: Tue, 31 Jan 2023 22:46:34 -0800 Subject: [PATCH 5/6] Content Model: Rename IExperimentalContentModelEditor --- .../plugins/FormatPainterPlugin.ts | 8 ++++---- .../editor/ExperimentalContentModelEditor.ts | 5 ++--- .../controls/editor/isContentModelEditor.ts | 8 +++----- .../contentModel/ContentModelRibbonPlugin.ts | 6 +++--- .../context/createDomToModelContext.ts | 2 +- packages/roosterjs-content-model/lib/index.ts | 4 ++-- .../context/createModelToDomContext.ts | 2 +- .../lib/publicApi/block/setAlignment.ts | 4 ++-- .../lib/publicApi/block/setDirection.ts | 7 ++----- .../lib/publicApi/block/setHeaderLevel.ts | 4 ++-- .../lib/publicApi/block/setIndentation.ts | 4 ++-- .../lib/publicApi/block/toggleBlockQuote.ts | 4 ++-- .../lib/publicApi/contentModelToDom.ts | 2 +- .../lib/publicApi/domToContentModel.ts | 2 +- .../lib/publicApi/format/clearFormat.ts | 4 ++-- .../lib/publicApi/format/getFormatState.ts | 4 ++-- .../lib/publicApi/format/getSegmentFormat.ts | 4 ++-- .../lib/publicApi/format/pendingFormat.ts | 10 ++++------ .../publicApi/image/adjustImageSelection.ts | 4 ++-- .../lib/publicApi/image/changeImage.ts | 4 ++-- .../lib/publicApi/image/setImageAltText.ts | 4 ++-- .../lib/publicApi/image/setImageBorder.ts | 4 ++-- .../lib/publicApi/image/setImageBoxShadow.ts | 7 ++----- .../lib/publicApi/insert/insertImage.ts | 4 ++-- .../lib/publicApi/link/adjustLinkSelection.ts | 6 ++---- .../lib/publicApi/link/insertLink.ts | 4 ++-- .../lib/publicApi/link/removeLink.ts | 4 ++-- .../lib/publicApi/list/setListStartNumber.ts | 4 ++-- .../lib/publicApi/list/setListStyle.ts | 7 ++----- .../lib/publicApi/list/toggleBullet.ts | 4 ++-- .../lib/publicApi/list/toggleNumbering.ts | 4 ++-- .../publicApi/segment/applySegmentFormat.ts | 4 ++-- .../publicApi/segment/changeCapitalization.ts | 4 ++-- .../lib/publicApi/segment/changeFontSize.ts | 4 ++-- .../publicApi/segment/setBackgroundColor.ts | 4 ++-- .../lib/publicApi/segment/setFontName.ts | 4 ++-- .../lib/publicApi/segment/setFontSize.ts | 4 ++-- .../lib/publicApi/segment/setTextColor.ts | 7 ++----- .../lib/publicApi/segment/toggleBold.ts | 4 ++-- .../lib/publicApi/segment/toggleItalic.ts | 4 ++-- .../publicApi/segment/toggleStrikethrough.ts | 4 ++-- .../lib/publicApi/segment/toggleSubscript.ts | 4 ++-- .../publicApi/segment/toggleSuperscript.ts | 4 ++-- .../lib/publicApi/segment/toggleUnderline.ts | 4 ++-- .../lib/publicApi/table/editTable.ts | 7 ++----- .../lib/publicApi/table/formatTable.ts | 4 ++-- .../lib/publicApi/table/insertTable.ts | 4 ++-- .../lib/publicApi/table/setTableCellShade.ts | 4 ++-- .../utils/formatImageWithContentModel.ts | 4 ++-- .../utils/formatParagraphWithContentModel.ts | 4 ++-- .../utils/formatSegmentWithContentModel.ts | 7 ++----- .../publicApi/utils/formatWithContentModel.ts | 7 ++----- .../lib/publicPlugin/ContentModelPlugin.ts | 8 ++++---- ...tModelEditor.ts => IContentModelEditor.ts} | 7 +++---- .../publicApi/block/paragraphTestCommon.ts | 6 +++--- .../publicApi/block/setIndentationTest.ts | 6 +++--- .../publicApi/block/toggleBlockQuoteTest.ts | 6 +++--- .../test/publicApi/format/clearFormatTest.ts | 4 ++-- .../publicApi/format/getFormatStateTest.ts | 6 +++--- .../publicApi/format/getSegmentFormatTest.ts | 6 +++--- .../test/publicApi/insert/insertImageTest.ts | 6 +++--- .../publicApi/link/adjustLinkSelectionTest.ts | 10 +++++----- .../test/publicApi/link/insertLinkTest.ts | 10 +++++----- .../test/publicApi/link/removeLinkTest.ts | 10 +++++----- .../test/publicApi/list/toggleBulletTest.ts | 6 +++--- .../publicApi/list/toggleNumberingTest.ts | 6 +++--- .../publicApi/segment/changeFontSizeTest.ts | 4 ++-- .../publicApi/segment/segmentTestCommon.ts | 6 +++--- .../publicApi/table/setTableCellShadeTest.ts | 10 +++++----- .../formatParagraphWithContentModelTest.ts | 6 +++--- .../formatSegmentWithContentModelTest.ts | 6 +++--- .../utils/formatWithContentModelTest.ts | 6 +++--- .../publicPlugin/ContentModelPluginTest.ts | 20 +++++++++---------- 73 files changed, 183 insertions(+), 212 deletions(-) rename packages/roosterjs-content-model/lib/publicTypes/{IExperimentalContentModelEditor.ts => IContentModelEditor.ts} (92%) diff --git a/demo/scripts/controls/contentModel/plugins/FormatPainterPlugin.ts b/demo/scripts/controls/contentModel/plugins/FormatPainterPlugin.ts index b2a380b5c63..941c72e4462 100644 --- a/demo/scripts/controls/contentModel/plugins/FormatPainterPlugin.ts +++ b/demo/scripts/controls/contentModel/plugins/FormatPainterPlugin.ts @@ -3,7 +3,7 @@ import { applySegmentFormat, ContentModelSegmentFormat, getSegmentFormat, - IExperimentalContentModelEditor, + IContentModelEditor, } from 'roosterjs-content-model'; const FORMATPAINTERCURSOR_SVG = require('./formatpaintercursor.svg'); @@ -15,14 +15,14 @@ interface FormatPainterFormatHolder { } export default class FormatPainterPlugin implements EditorPlugin { - private editor: IExperimentalContentModelEditor | null = null; + private editor: IContentModelEditor | null = null; getName() { return 'FormatPainter'; } initialize(editor: IEditor) { - this.editor = editor as IExperimentalContentModelEditor; + this.editor = editor as IContentModelEditor; } dispose() { @@ -42,7 +42,7 @@ export default class FormatPainterPlugin implements EditorPlugin { } } - static startFormatPainter(editor: IExperimentalContentModelEditor) { + static startFormatPainter(editor: IContentModelEditor) { const formatHolder = getFormatHolder(editor); const format = getSegmentFormat(editor); diff --git a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts index 2f7b205b93b..f48646f78e0 100644 --- a/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts +++ b/demo/scripts/controls/editor/ExperimentalContentModelEditor.ts @@ -7,7 +7,7 @@ import { domToContentModel, DomToModelOption, EditorContext, - IExperimentalContentModelEditor, + IContentModelEditor, ModelToDomOption, } from 'roosterjs-content-model'; @@ -16,8 +16,7 @@ import { * * Experimental editor to support Content Model */ -export default class ExperimentalContentModelEditor extends Editor - implements IExperimentalContentModelEditor { +export default class ExperimentalContentModelEditor extends Editor implements IContentModelEditor { private getDarkColor: ((lightColor: string) => string) | undefined; /** diff --git a/demo/scripts/controls/editor/isContentModelEditor.ts b/demo/scripts/controls/editor/isContentModelEditor.ts index d243ed87819..924ccef77fc 100644 --- a/demo/scripts/controls/editor/isContentModelEditor.ts +++ b/demo/scripts/controls/editor/isContentModelEditor.ts @@ -1,10 +1,8 @@ +import { IContentModelEditor } from 'roosterjs-content-model'; import { IEditor } from 'roosterjs-editor-types'; -import { IExperimentalContentModelEditor } from 'roosterjs-content-model'; -export default function isContentModelEditor( - editor: IEditor -): editor is IExperimentalContentModelEditor { - const experimentalEditor = editor as IExperimentalContentModelEditor; +export default function isContentModelEditor(editor: IEditor): editor is IContentModelEditor { + const experimentalEditor = editor as IContentModelEditor; return !!experimentalEditor.createContentModel && 'contentDiv' in experimentalEditor; } diff --git a/demo/scripts/controls/ribbonButtons/contentModel/ContentModelRibbonPlugin.ts b/demo/scripts/controls/ribbonButtons/contentModel/ContentModelRibbonPlugin.ts index ecb78f3c353..0a298ecf4bd 100644 --- a/demo/scripts/controls/ribbonButtons/contentModel/ContentModelRibbonPlugin.ts +++ b/demo/scripts/controls/ribbonButtons/contentModel/ContentModelRibbonPlugin.ts @@ -1,10 +1,10 @@ import { FormatState, PluginEvent, PluginEventType } from 'roosterjs-editor-types'; -import { getFormatState, IExperimentalContentModelEditor } from 'roosterjs-content-model'; +import { getFormatState, IContentModelEditor } from 'roosterjs-content-model'; import { getObjectKeys } from 'roosterjs-editor-dom'; import { LocalizedStrings, RibbonButton, RibbonPlugin, UIUtilities } from 'roosterjs-react'; export class ContentModelRibbonPlugin implements RibbonPlugin { - private editor: IExperimentalContentModelEditor | null = null; + private editor: IContentModelEditor | null = null; private onFormatChanged: ((formatState: FormatState) => void) | null = null; private timer = 0; private formatState: FormatState | null = null; @@ -27,7 +27,7 @@ export class ContentModelRibbonPlugin implements RibbonPlugin { * Initialize this plugin * @param editor The editor instance */ - initialize(editor: IExperimentalContentModelEditor) { + initialize(editor: IContentModelEditor) { this.editor = editor; } diff --git a/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts b/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts index d8f350d6e79..45f02ed3b11 100644 --- a/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts +++ b/packages/roosterjs-content-model/lib/domToModel/context/createDomToModelContext.ts @@ -2,7 +2,7 @@ import { defaultFormatParsers, getFormatParsers } from '../../formatHandlers/def import { defaultProcessorMap } from './defaultProcessors'; import { defaultStyleMap } from '../../formatHandlers/utils/defaultStyles'; import { DomToModelContext } from '../../publicTypes/context/DomToModelContext'; -import { DomToModelOption } from '../../publicTypes/IExperimentalContentModelEditor'; +import { DomToModelOption } from '../../publicTypes/IContentModelEditor'; import { EditorContext } from '../../publicTypes/context/EditorContext'; import { SelectionRangeTypes } from 'roosterjs-editor-types'; diff --git a/packages/roosterjs-content-model/lib/index.ts b/packages/roosterjs-content-model/lib/index.ts index 33ac38a2146..3c432e50ba0 100644 --- a/packages/roosterjs-content-model/lib/index.ts +++ b/packages/roosterjs-content-model/lib/index.ts @@ -174,7 +174,7 @@ export { ContentModelHandler } from './publicTypes/context/ContentModelHandler'; export { Border } from './publicTypes/interface/Border'; export { - IExperimentalContentModelEditor, + IContentModelEditor, DomToModelOption, ModelToDomOption, -} from './publicTypes/IExperimentalContentModelEditor'; +} from './publicTypes/IContentModelEditor'; diff --git a/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts b/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts index 162bd8eaf25..3c9988d2262 100644 --- a/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts +++ b/packages/roosterjs-content-model/lib/modelToDom/context/createModelToDomContext.ts @@ -2,7 +2,7 @@ import { defaultContentModelHandlers } from './defaultContentModelHandlers'; import { defaultImplicitFormatMap } from '../../formatHandlers/utils/defaultStyles'; import { EditorContext } from '../../publicTypes/context/EditorContext'; import { ModelToDomContext } from '../../publicTypes/context/ModelToDomContext'; -import { ModelToDomOption } from '../../publicTypes/IExperimentalContentModelEditor'; +import { ModelToDomOption } from '../../publicTypes/IContentModelEditor'; import { defaultFormatAppliers, getFormatAppliers, diff --git a/packages/roosterjs-content-model/lib/publicApi/block/setAlignment.ts b/packages/roosterjs-content-model/lib/publicApi/block/setAlignment.ts index 9b3e93730ba..382307b2d78 100644 --- a/packages/roosterjs-content-model/lib/publicApi/block/setAlignment.ts +++ b/packages/roosterjs-content-model/lib/publicApi/block/setAlignment.ts @@ -1,5 +1,5 @@ import { formatParagraphWithContentModel } from '../utils/formatParagraphWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; const ResultMap: Record< 'left' | 'center' | 'right', @@ -25,7 +25,7 @@ const ResultMap: Record< * @param alignment Alignment value: left, center or right */ export default function setAlignment( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, alignment: 'left' | 'center' | 'right' ) { formatParagraphWithContentModel(editor, 'setAlignment', para => { diff --git a/packages/roosterjs-content-model/lib/publicApi/block/setDirection.ts b/packages/roosterjs-content-model/lib/publicApi/block/setDirection.ts index 52cfe3f0dad..3a11c205bf1 100644 --- a/packages/roosterjs-content-model/lib/publicApi/block/setDirection.ts +++ b/packages/roosterjs-content-model/lib/publicApi/block/setDirection.ts @@ -1,15 +1,12 @@ import { formatParagraphWithContentModel } from '../utils/formatParagraphWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set text direction of selected paragraphs (Left to right or Right to left) * @param editor The editor to set alignment * @param direction Direction value: ltr (Left to right) or rtl (Right to left) */ -export default function setDirection( - editor: IExperimentalContentModelEditor, - direction: 'ltr' | 'rtl' -) { +export default function setDirection(editor: IContentModelEditor, direction: 'ltr' | 'rtl') { formatParagraphWithContentModel(editor, 'setDirection', para => { const isOldValueRtl = para.format.direction == 'rtl'; const isNewValueRtl = direction == 'rtl'; diff --git a/packages/roosterjs-content-model/lib/publicApi/block/setHeaderLevel.ts b/packages/roosterjs-content-model/lib/publicApi/block/setHeaderLevel.ts index 80a639c378a..0d87e3ee69b 100644 --- a/packages/roosterjs-content-model/lib/publicApi/block/setHeaderLevel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/block/setHeaderLevel.ts @@ -3,7 +3,7 @@ import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModel import { defaultImplicitFormatMap } from '../../formatHandlers/utils/defaultStyles'; import { formatParagraphWithContentModel } from '../utils/formatParagraphWithContentModel'; import { getObjectKeys } from 'roosterjs-editor-dom'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; type HeaderLevelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; @@ -13,7 +13,7 @@ type HeaderLevelTags = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; * @param headerLevel Level of header, from 1 to 6. Set to 0 means set it back to a regular paragraph */ export default function setHeaderLevel( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, headerLevel: 0 | 1 | 2 | 3 | 4 | 5 | 6 ) { formatParagraphWithContentModel(editor, 'setHeaderLevel', para => { diff --git a/packages/roosterjs-content-model/lib/publicApi/block/setIndentation.ts b/packages/roosterjs-content-model/lib/publicApi/block/setIndentation.ts index 95207d6127e..84958490248 100644 --- a/packages/roosterjs-content-model/lib/publicApi/block/setIndentation.ts +++ b/packages/roosterjs-content-model/lib/publicApi/block/setIndentation.ts @@ -1,5 +1,5 @@ import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { setModelIndentation } from '../../modelApi/block/setModelIndentation'; /** @@ -9,7 +9,7 @@ import { setModelIndentation } from '../../modelApi/block/setModelIndentation'; * @param length The length of pixel to indent/outdent @default 40 */ export default function setIndentation( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, indentation: 'indent' | 'outdent', length?: number ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/block/toggleBlockQuote.ts b/packages/roosterjs-content-model/lib/publicApi/block/toggleBlockQuote.ts index fc4dacd9587..178dd4bda0d 100644 --- a/packages/roosterjs-content-model/lib/publicApi/block/toggleBlockQuote.ts +++ b/packages/roosterjs-content-model/lib/publicApi/block/toggleBlockQuote.ts @@ -1,7 +1,7 @@ import { ContentModelBlockFormat } from '../../publicTypes/format/ContentModelBlockFormat'; import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { toggleModelBlockQuote } from '../../modelApi/block/toggleModelBlockQuote'; const DefaultQuoteFormat: ContentModelBlockFormat = { @@ -27,7 +27,7 @@ const BuildInQuoteFormat: ContentModelBlockFormat = { * @param segmentFormat @optional Segment format for the content of model */ export default function toggleBlockQuote( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, quoteFormat: ContentModelBlockFormat = DefaultQuoteFormat, segmentFormat: ContentModelSegmentFormat = DefaultSegmentFormat ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/contentModelToDom.ts b/packages/roosterjs-content-model/lib/publicApi/contentModelToDom.ts index 898f430df6a..eeee2ef1f44 100644 --- a/packages/roosterjs-content-model/lib/publicApi/contentModelToDom.ts +++ b/packages/roosterjs-content-model/lib/publicApi/contentModelToDom.ts @@ -5,7 +5,7 @@ import { EditorContext } from '../publicTypes/context/EditorContext'; import { isNodeOfType } from '../domUtils/isNodeOfType'; import { ModelToDomBlockAndSegmentNode } from '../publicTypes/context/ModelToDomSelectionContext'; import { ModelToDomContext } from '../publicTypes/context/ModelToDomContext'; -import { ModelToDomOption } from '../publicTypes/IExperimentalContentModelEditor'; +import { ModelToDomOption } from '../publicTypes/IContentModelEditor'; import { optimize } from '../modelToDom/optimizers/optimize'; import { NodePosition, diff --git a/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts index 4b8f2b9437d..2847a679946 100644 --- a/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/domToContentModel.ts @@ -1,7 +1,7 @@ import { ContentModelDocument } from '../publicTypes/group/ContentModelDocument'; import { createContentModelDocument } from '../modelApi/creators/createContentModelDocument'; import { createDomToModelContext } from '../domToModel/context/createDomToModelContext'; -import { DomToModelOption } from '../publicTypes/IExperimentalContentModelEditor'; +import { DomToModelOption } from '../publicTypes/IContentModelEditor'; import { EditorContext } from '../publicTypes/context/EditorContext'; import { normalizeContentModel } from '../modelApi/common/normalizeContentModel'; import { parseFormat } from '../domToModel/utils/parseFormat'; diff --git a/packages/roosterjs-content-model/lib/publicApi/format/clearFormat.ts b/packages/roosterjs-content-model/lib/publicApi/format/clearFormat.ts index 4ea673421bb..32f1a3a94b7 100644 --- a/packages/roosterjs-content-model/lib/publicApi/format/clearFormat.ts +++ b/packages/roosterjs-content-model/lib/publicApi/format/clearFormat.ts @@ -5,7 +5,7 @@ import { ContentModelSegment } from '../../publicTypes/segment/ContentModelSegme import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; import { ContentModelTable } from '../../publicTypes/block/ContentModelTable'; import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { normalizeContentModel } from '../../modelApi/common/normalizeContentModel'; /** @@ -13,7 +13,7 @@ import { normalizeContentModel } from '../../modelApi/common/normalizeContentMod * @param editor The editor to clear format from */ export default function clearFormat( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, defaultSegmentFormat?: ContentModelSegmentFormat ) { formatWithContentModel(editor, 'clearFormat', model => { diff --git a/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts b/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts index f5732c7f39d..34c2ec9c72c 100644 --- a/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts +++ b/packages/roosterjs-content-model/lib/publicApi/format/getFormatState.ts @@ -1,7 +1,7 @@ import { FormatState } from 'roosterjs-editor-types'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getPendingFormat } from './pendingFormat'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { reducedModelChildProcessor } from '../../domToModel/processors/reducedModelChildProcessor'; import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFormatState'; @@ -9,7 +9,7 @@ import { retrieveModelFormatState } from '../../modelApi/common/retrieveModelFor * Get current format state * @param editor The editor to get format from */ -export default function getFormatState(editor: IExperimentalContentModelEditor): FormatState { +export default function getFormatState(editor: IContentModelEditor): FormatState { let result: FormatState = { ...editor.getUndoState(), diff --git a/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts b/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts index 586edda213b..c272afc958a 100644 --- a/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts +++ b/packages/roosterjs-content-model/lib/publicApi/format/getSegmentFormat.ts @@ -1,7 +1,7 @@ import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getPendingFormat } from './pendingFormat'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { iterateSelections } from '../../modelApi/selection/iterateSelections'; import { reducedModelChildProcessor } from '../../domToModel/processors/reducedModelChildProcessor'; @@ -10,7 +10,7 @@ import { reducedModelChildProcessor } from '../../domToModel/processors/reducedM * @param editor The editor to get format from */ export default function getSegmentFormat( - editor: IExperimentalContentModelEditor + editor: IContentModelEditor ): ContentModelSegmentFormat | null { let result = getPendingFormat(editor); diff --git a/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts b/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts index 301ca082bbc..6d8bc85ef0e 100644 --- a/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts +++ b/packages/roosterjs-content-model/lib/publicApi/format/pendingFormat.ts @@ -1,14 +1,12 @@ import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * @internal * Get pending segment format from editor if any, otherwise null * @param editor The editor to get format from */ -export function getPendingFormat( - editor: IExperimentalContentModelEditor -): ContentModelSegmentFormat | null { +export function getPendingFormat(editor: IContentModelEditor): ContentModelSegmentFormat | null { return getPendingFormatHolder(editor).format; } @@ -19,7 +17,7 @@ export function getPendingFormat( * @param format The format to set. Pass null to clear existing format */ export function setPendingFormat( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, format: ContentModelSegmentFormat | null ) { getPendingFormatHolder(editor).format = format; @@ -31,7 +29,7 @@ interface PendingFormatHolder { const PendingFormatHolderKey = '__ContentModelPendingFormat'; -function getPendingFormatHolder(editor: IExperimentalContentModelEditor): PendingFormatHolder { +function getPendingFormatHolder(editor: IContentModelEditor): PendingFormatHolder { return editor.getCustomData(PendingFormatHolderKey, () => ({ format: null, })); diff --git a/packages/roosterjs-content-model/lib/publicApi/image/adjustImageSelection.ts b/packages/roosterjs-content-model/lib/publicApi/image/adjustImageSelection.ts index 847182d3660..f8ce9f09452 100644 --- a/packages/roosterjs-content-model/lib/publicApi/image/adjustImageSelection.ts +++ b/packages/roosterjs-content-model/lib/publicApi/image/adjustImageSelection.ts @@ -1,14 +1,14 @@ import { adjustSegmentSelection } from '../../modelApi/selection/adjustSegmentSelection'; import { ContentModelImage } from '../../publicTypes/segment/ContentModelImage'; import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Adjust selection to make sure select an image if any * @return Content Model Image object if an image is select, or null */ export default function adjustImageSelection( - editor: IExperimentalContentModelEditor + editor: IContentModelEditor ): ContentModelImage | null { let image: ContentModelImage | null = null; diff --git a/packages/roosterjs-content-model/lib/publicApi/image/changeImage.ts b/packages/roosterjs-content-model/lib/publicApi/image/changeImage.ts index ab5d04c8293..d3029316c8d 100644 --- a/packages/roosterjs-content-model/lib/publicApi/image/changeImage.ts +++ b/packages/roosterjs-content-model/lib/publicApi/image/changeImage.ts @@ -1,6 +1,6 @@ import formatImageWithContentModel from '../utils/formatImageWithContentModel'; import { ContentModelImage } from '../../publicTypes/segment/ContentModelImage'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { readFile } from 'roosterjs-editor-dom'; /** @@ -8,7 +8,7 @@ import { readFile } from 'roosterjs-editor-dom'; * @param editor The editor instance * @param file The image file */ -export default function changeImage(editor: IExperimentalContentModelEditor, file: File) { +export default function changeImage(editor: IContentModelEditor, file: File) { readFile(file, dataUrl => { if (dataUrl && !editor.isDisposed()) { formatImageWithContentModel(editor, 'changeImage', (image: ContentModelImage) => { diff --git a/packages/roosterjs-content-model/lib/publicApi/image/setImageAltText.ts b/packages/roosterjs-content-model/lib/publicApi/image/setImageAltText.ts index cf5f9caa208..25da1d8ae72 100644 --- a/packages/roosterjs-content-model/lib/publicApi/image/setImageAltText.ts +++ b/packages/roosterjs-content-model/lib/publicApi/image/setImageAltText.ts @@ -1,6 +1,6 @@ import formatImageWithContentModel from '../utils/formatImageWithContentModel'; import { ContentModelImage } from '../../publicTypes/segment/ContentModelImage'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set image alt text for all selected images at selection. If no images is contained @@ -8,7 +8,7 @@ import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimental * @param editor The editor instance * @param altText The image alt text */ -export default function setImageAltText(editor: IExperimentalContentModelEditor, altText: string) { +export default function setImageAltText(editor: IContentModelEditor, altText: string) { formatImageWithContentModel(editor, 'setImageAltText', (image: ContentModelImage) => { image.alt = altText; }); diff --git a/packages/roosterjs-content-model/lib/publicApi/image/setImageBorder.ts b/packages/roosterjs-content-model/lib/publicApi/image/setImageBorder.ts index 09c8aab6a1b..f255e1c66a1 100644 --- a/packages/roosterjs-content-model/lib/publicApi/image/setImageBorder.ts +++ b/packages/roosterjs-content-model/lib/publicApi/image/setImageBorder.ts @@ -2,7 +2,7 @@ import applyImageBorderFormat from '../../modelApi/image/applyImageBorderFormat' import formatImageWithContentModel from '../utils/formatImageWithContentModel'; import { Border } from '../../publicTypes/interface/Border'; import { ContentModelImage } from '../../publicTypes/segment/ContentModelImage'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set image border style for all selected images at selection. @@ -12,7 +12,7 @@ import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimental * @param borderRadius the border radius value, if undefined, the border radius will keep the actual value */ export default function setImageBorder( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, border: Border, borderRadius?: string ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/image/setImageBoxShadow.ts b/packages/roosterjs-content-model/lib/publicApi/image/setImageBoxShadow.ts index 2c63b4a49f7..95b04ac1584 100644 --- a/packages/roosterjs-content-model/lib/publicApi/image/setImageBoxShadow.ts +++ b/packages/roosterjs-content-model/lib/publicApi/image/setImageBoxShadow.ts @@ -1,16 +1,13 @@ import formatImageWithContentModel from '../utils/formatImageWithContentModel'; import { ContentModelImage } from '../../publicTypes/segment/ContentModelImage'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set image box shadow for all selected images at selection. * @param editor The editor instance * @param boxShadow The image box shadow */ -export default function setImageBoxShadow( - editor: IExperimentalContentModelEditor, - boxShadow: string -) { +export default function setImageBoxShadow(editor: IContentModelEditor, boxShadow: string) { formatImageWithContentModel(editor, 'setImageBoxShadow', (image: ContentModelImage) => { image.format.boxShadow = boxShadow; }); diff --git a/packages/roosterjs-content-model/lib/publicApi/insert/insertImage.ts b/packages/roosterjs-content-model/lib/publicApi/insert/insertImage.ts index ea1d804621f..1bd879357c6 100644 --- a/packages/roosterjs-content-model/lib/publicApi/insert/insertImage.ts +++ b/packages/roosterjs-content-model/lib/publicApi/insert/insertImage.ts @@ -1,5 +1,5 @@ import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { insertContent } from '../../modelApi/common/insertContent'; import { readFile } from 'roosterjs-editor-dom'; @@ -8,7 +8,7 @@ import { readFile } from 'roosterjs-editor-dom'; * @param editor The editor to operate on * @param file Image Blob file */ -export default function insertImage(editor: IExperimentalContentModelEditor, file: File) { +export default function insertImage(editor: IContentModelEditor, file: File) { readFile(file, dataUrl => { if (dataUrl && !editor.isDisposed()) { formatWithContentModel(editor, 'insertImage', model => { diff --git a/packages/roosterjs-content-model/lib/publicApi/link/adjustLinkSelection.ts b/packages/roosterjs-content-model/lib/publicApi/link/adjustLinkSelection.ts index 25948fbc9fd..d4acc8bb49a 100644 --- a/packages/roosterjs-content-model/lib/publicApi/link/adjustLinkSelection.ts +++ b/packages/roosterjs-content-model/lib/publicApi/link/adjustLinkSelection.ts @@ -3,16 +3,14 @@ import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelectio import { areSameFormats } from '../../domToModel/utils/areSameFormats'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getSelectedSegments } from '../../modelApi/selection/collectSelections'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { setSelection } from '../../modelApi/selection/setSelection'; /** * Adjust selection to make sure select a hyperlink if any, or a word if original selection is collapsed * @return A combination of existing link display text and url if any. If there is no existing link, return selected text and null */ -export default function adjustLinkSelection( - editor: IExperimentalContentModelEditor -): [string, string | null] { +export default function adjustLinkSelection(editor: IContentModelEditor): [string, string | null] { let text = ''; let url: string | null = null; diff --git a/packages/roosterjs-content-model/lib/publicApi/link/insertLink.ts b/packages/roosterjs-content-model/lib/publicApi/link/insertLink.ts index 29eb5c1c77d..5d5340cc2c4 100644 --- a/packages/roosterjs-content-model/lib/publicApi/link/insertLink.ts +++ b/packages/roosterjs-content-model/lib/publicApi/link/insertLink.ts @@ -8,7 +8,7 @@ import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getSelectedSegments } from '../../modelApi/selection/collectSelections'; import { HtmlSanitizer, matchLink } from 'roosterjs-editor-dom'; import { HyperLinkColorPlaceholder } from '../../formatHandlers/utils/defaultStyles'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { mergeModel } from '../../modelApi/common/mergeModel'; // Regex matching Uri scheme @@ -32,7 +32,7 @@ const FTP_REGEX = /^ftp\./i; * If not specified and there wasn't a link, the link url will be used as display text. */ export default function insertLink( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, link: string, anchorTitle?: string, displayText?: string, diff --git a/packages/roosterjs-content-model/lib/publicApi/link/removeLink.ts b/packages/roosterjs-content-model/lib/publicApi/link/removeLink.ts index 224611e2aaf..27c0397ad7d 100644 --- a/packages/roosterjs-content-model/lib/publicApi/link/removeLink.ts +++ b/packages/roosterjs-content-model/lib/publicApi/link/removeLink.ts @@ -3,7 +3,7 @@ import { areSameFormats } from '../../domToModel/utils/areSameFormats'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getSelectedSegments } from '../../modelApi/selection/collectSelections'; import { HyperLinkColorPlaceholder } from '../../formatHandlers/utils/defaultStyles'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Remove link at selection. If no links at selection, do nothing. @@ -11,7 +11,7 @@ import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimental * If only part of a link is selected, the whole link style will be removed. * @param editor The editor instance */ -export default function removeLink(editor: IExperimentalContentModelEditor) { +export default function removeLink(editor: IContentModelEditor) { formatWithContentModel(editor, 'removeLink', model => { adjustSegmentSelection( model, diff --git a/packages/roosterjs-content-model/lib/publicApi/list/setListStartNumber.ts b/packages/roosterjs-content-model/lib/publicApi/list/setListStartNumber.ts index 035eaef509b..aae1b79d3ea 100644 --- a/packages/roosterjs-content-model/lib/publicApi/list/setListStartNumber.ts +++ b/packages/roosterjs-content-model/lib/publicApi/list/setListStartNumber.ts @@ -1,13 +1,13 @@ import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getFirstSelectedListItem } from '../../modelApi/selection/collectSelections'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set start number of a list item * @param editor The editor to operate on * @param value The number to set to, must be equal or greater than 1 */ -export default function setListStartNumber(editor: IExperimentalContentModelEditor, value: number) { +export default function setListStartNumber(editor: IContentModelEditor, value: number) { formatWithContentModel(editor, 'setListStartNumber', model => { const listItem = getFirstSelectedListItem(model); const level = listItem?.levels[listItem?.levels.length - 1]; diff --git a/packages/roosterjs-content-model/lib/publicApi/list/setListStyle.ts b/packages/roosterjs-content-model/lib/publicApi/list/setListStyle.ts index 7f564e751d0..3df6c6b1aeb 100644 --- a/packages/roosterjs-content-model/lib/publicApi/list/setListStyle.ts +++ b/packages/roosterjs-content-model/lib/publicApi/list/setListStyle.ts @@ -1,7 +1,7 @@ import { findListItemsInSameThread } from '../../modelApi/list/findListItemsInSameThread'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getFirstSelectedListItem } from '../../modelApi/selection/collectSelections'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { ListMetadataFormat } from '../../publicTypes/format/formatParts/ListMetadataFormat'; /** @@ -9,10 +9,7 @@ import { ListMetadataFormat } from '../../publicTypes/format/formatParts/ListMet * @param editor The editor to operate on * @param style The target list item style to set */ -export default function setListStyle( - editor: IExperimentalContentModelEditor, - style: ListMetadataFormat -) { +export default function setListStyle(editor: IContentModelEditor, style: ListMetadataFormat) { formatWithContentModel(editor, 'setListStyle', model => { const listItem = getFirstSelectedListItem(model); diff --git a/packages/roosterjs-content-model/lib/publicApi/list/toggleBullet.ts b/packages/roosterjs-content-model/lib/publicApi/list/toggleBullet.ts index ee8681a62d0..5daee5af867 100644 --- a/packages/roosterjs-content-model/lib/publicApi/list/toggleBullet.ts +++ b/packages/roosterjs-content-model/lib/publicApi/list/toggleBullet.ts @@ -1,5 +1,5 @@ import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { setListType } from '../../modelApi/list/setListType'; /** @@ -8,6 +8,6 @@ import { setListType } from '../../modelApi/list/setListType'; * - When all blocks are already in bullet list, turn off / outdent there list type * @param editor The editor to operate on */ -export default function toggleBullet(editor: IExperimentalContentModelEditor) { +export default function toggleBullet(editor: IContentModelEditor) { formatWithContentModel(editor, 'toggleBullet', model => setListType(model, 'UL')); } diff --git a/packages/roosterjs-content-model/lib/publicApi/list/toggleNumbering.ts b/packages/roosterjs-content-model/lib/publicApi/list/toggleNumbering.ts index d23c1a9ac3f..216c0061162 100644 --- a/packages/roosterjs-content-model/lib/publicApi/list/toggleNumbering.ts +++ b/packages/roosterjs-content-model/lib/publicApi/list/toggleNumbering.ts @@ -1,5 +1,5 @@ import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { setListType } from '../../modelApi/list/setListType'; /** @@ -8,6 +8,6 @@ import { setListType } from '../../modelApi/list/setListType'; * - When all blocks are already in numbering list, turn off / outdent there list type * @param editor The editor to operate on */ -export default function toggleNumbering(editor: IExperimentalContentModelEditor) { +export default function toggleNumbering(editor: IContentModelEditor) { formatWithContentModel(editor, 'toggleNumbering', model => setListType(model, 'OL')); } diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/applySegmentFormat.ts b/packages/roosterjs-content-model/lib/publicApi/segment/applySegmentFormat.ts index 2268fa5b374..7b0af7a5c45 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/applySegmentFormat.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/applySegmentFormat.ts @@ -1,6 +1,6 @@ import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Bulk apply segment format to all selected content. This is usually used for format painter. @@ -8,7 +8,7 @@ import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimental * @param newFormat The segment format to apply */ export default function applySegmentFormat( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, newFormat: ContentModelSegmentFormat ) { formatSegmentWithContentModel( diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/changeCapitalization.ts b/packages/roosterjs-content-model/lib/publicApi/segment/changeCapitalization.ts index e2644202c54..a3900553351 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/changeCapitalization.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/changeCapitalization.ts @@ -1,5 +1,5 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Change the capitalization of text in the selection @@ -10,7 +10,7 @@ import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimental * Default is the host environment’s current locale. */ export default function changeCapitalization( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, capitalization: 'sentence' | 'lowerCase' | 'upperCase' | 'capitalize', language?: string ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/changeFontSize.ts b/packages/roosterjs-content-model/lib/publicApi/segment/changeFontSize.ts index 6cf4eb033db..e8adc1b2c68 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/changeFontSize.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/changeFontSize.ts @@ -3,7 +3,7 @@ import { FontSizeFormat } from '../../publicTypes/format/formatParts/FontSizeFor import { FormatParser } from '../../publicTypes/context/DomToModelSettings'; import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; import { getComputedStyle } from 'roosterjs-editor-dom'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Default font size sequence, in pt. Suggest editor UI use this sequence as your font size list, @@ -20,7 +20,7 @@ const MAX_FONT_SIZE = 1000; * @param fontSizes A sorted font size array, in pt. Default value is FONT_SIZES */ export default function changeFontSize( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, change: 'increase' | 'decrease' ) { formatSegmentWithContentModel( diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/setBackgroundColor.ts b/packages/roosterjs-content-model/lib/publicApi/segment/setBackgroundColor.ts index b7aea12320c..2dcb2c46b14 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/setBackgroundColor.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/setBackgroundColor.ts @@ -1,5 +1,5 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set background color @@ -7,7 +7,7 @@ import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimental * @param backgroundColor The color to set. Pass null to remove existing color. */ export default function setBackgroundColor( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, backgroundColor: string | null ) { formatSegmentWithContentModel( diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/setFontName.ts b/packages/roosterjs-content-model/lib/publicApi/segment/setFontName.ts index c02f31790bc..48b9f0dc9d1 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/setFontName.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/setFontName.ts @@ -1,12 +1,12 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set font name * @param editor The editor to operate on * @param fontName The font name to set */ -export default function setFontName(editor: IExperimentalContentModelEditor, fontName: string) { +export default function setFontName(editor: IContentModelEditor, fontName: string) { formatSegmentWithContentModel( editor, 'setFontName', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/setFontSize.ts b/packages/roosterjs-content-model/lib/publicApi/segment/setFontSize.ts index 4d03a3b8aa0..87fe60c764f 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/setFontSize.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/setFontSize.ts @@ -1,12 +1,12 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set font size * @param editor The editor to operate on * @param fontSize The font size to set */ -export default function setFontSize(editor: IExperimentalContentModelEditor, fontSize: string) { +export default function setFontSize(editor: IContentModelEditor, fontSize: string) { formatSegmentWithContentModel( editor, 'setFontSize', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/setTextColor.ts b/packages/roosterjs-content-model/lib/publicApi/segment/setTextColor.ts index 42109d648bb..8c6882e771b 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/setTextColor.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/setTextColor.ts @@ -1,15 +1,12 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Set text color * @param editor The editor to operate on * @param textColor The text color to set. Pass null to remove existing color. */ -export default function setTextColor( - editor: IExperimentalContentModelEditor, - textColor: string | null -) { +export default function setTextColor(editor: IContentModelEditor, textColor: string | null) { formatSegmentWithContentModel( editor, 'setTextColor', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/toggleBold.ts b/packages/roosterjs-content-model/lib/publicApi/segment/toggleBold.ts index ba2f7bc3702..0e97ad76ed8 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/toggleBold.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/toggleBold.ts @@ -1,11 +1,11 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Toggle bold style * @param editor The editor to operate on */ -export default function toggleBold(editor: IExperimentalContentModelEditor) { +export default function toggleBold(editor: IContentModelEditor) { formatSegmentWithContentModel( editor, 'toggleBold', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/toggleItalic.ts b/packages/roosterjs-content-model/lib/publicApi/segment/toggleItalic.ts index 6c5b8ad2b43..8c62d361122 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/toggleItalic.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/toggleItalic.ts @@ -1,11 +1,11 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Toggle italic style * @param editor The editor to operate on */ -export default function toggleItalic(editor: IExperimentalContentModelEditor) { +export default function toggleItalic(editor: IContentModelEditor) { formatSegmentWithContentModel( editor, 'toggleItalic', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/toggleStrikethrough.ts b/packages/roosterjs-content-model/lib/publicApi/segment/toggleStrikethrough.ts index 29b4645431b..aa227e891d3 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/toggleStrikethrough.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/toggleStrikethrough.ts @@ -1,11 +1,11 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Toggle strikethrough style * @param editor The editor to operate on */ -export default function toggleStrikethrough(editor: IExperimentalContentModelEditor) { +export default function toggleStrikethrough(editor: IContentModelEditor) { formatSegmentWithContentModel( editor, 'toggleStrikethrough', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/toggleSubscript.ts b/packages/roosterjs-content-model/lib/publicApi/segment/toggleSubscript.ts index fe138169b7f..9e9c569fa15 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/toggleSubscript.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/toggleSubscript.ts @@ -1,11 +1,11 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Toggle subscript style * @param editor The editor to operate on */ -export default function toggleSubscript(editor: IExperimentalContentModelEditor) { +export default function toggleSubscript(editor: IContentModelEditor) { formatSegmentWithContentModel( editor, 'toggleSubscript', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/toggleSuperscript.ts b/packages/roosterjs-content-model/lib/publicApi/segment/toggleSuperscript.ts index 093c8c2d79f..4ebbbe2127d 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/toggleSuperscript.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/toggleSuperscript.ts @@ -1,11 +1,11 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Toggle superscript style * @param editor The editor to operate on */ -export default function toggleSuperscript(editor: IExperimentalContentModelEditor) { +export default function toggleSuperscript(editor: IContentModelEditor) { formatSegmentWithContentModel( editor, 'toggleSuperscript', diff --git a/packages/roosterjs-content-model/lib/publicApi/segment/toggleUnderline.ts b/packages/roosterjs-content-model/lib/publicApi/segment/toggleUnderline.ts index 640103f8e86..e7bcceedb37 100644 --- a/packages/roosterjs-content-model/lib/publicApi/segment/toggleUnderline.ts +++ b/packages/roosterjs-content-model/lib/publicApi/segment/toggleUnderline.ts @@ -1,11 +1,11 @@ import { formatSegmentWithContentModel } from '../utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * Toggle underline style * @param editor The editor to operate on */ -export default function toggleUnderline(editor: IExperimentalContentModelEditor) { +export default function toggleUnderline(editor: IContentModelEditor) { formatSegmentWithContentModel( editor, 'toggleUnderline', diff --git a/packages/roosterjs-content-model/lib/publicApi/table/editTable.ts b/packages/roosterjs-content-model/lib/publicApi/table/editTable.ts index 5b6e4375c3b..0deb3aa5a8f 100644 --- a/packages/roosterjs-content-model/lib/publicApi/table/editTable.ts +++ b/packages/roosterjs-content-model/lib/publicApi/table/editTable.ts @@ -7,7 +7,7 @@ import { deleteTableRow } from '../../modelApi/table/deleteTableRow'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getFirstSelectedTable } from '../../modelApi/selection/collectSelections'; import { hasMetadata } from '../../modelApi/metadata/updateMetadata'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { insertTableColumn } from '../../modelApi/table/insertTableColumn'; import { insertTableRow } from '../../modelApi/table/insertTableRow'; import { mergeTableCells } from '../../modelApi/table/mergeTableCells'; @@ -23,10 +23,7 @@ import { TableOperation } from 'roosterjs-editor-types'; * @param editor The editor instance * @param operation The table operation to apply */ -export default function editTable( - editor: IExperimentalContentModelEditor, - operation: TableOperation -) { +export default function editTable(editor: IContentModelEditor, operation: TableOperation) { formatWithContentModel(editor, 'editTable', model => { const tableModel = getFirstSelectedTable(model); diff --git a/packages/roosterjs-content-model/lib/publicApi/table/formatTable.ts b/packages/roosterjs-content-model/lib/publicApi/table/formatTable.ts index 617250695e5..9e527888a8a 100644 --- a/packages/roosterjs-content-model/lib/publicApi/table/formatTable.ts +++ b/packages/roosterjs-content-model/lib/publicApi/table/formatTable.ts @@ -1,7 +1,7 @@ import { applyTableFormat } from '../../modelApi/table/applyTableFormat'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getFirstSelectedTable } from '../../modelApi/selection/collectSelections'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { TableMetadataFormat } from '../../publicTypes/format/formatParts/TableMetadataFormat'; /** @@ -11,7 +11,7 @@ import { TableMetadataFormat } from '../../publicTypes/format/formatParts/TableM * @param keepCellShade Whether keep existing shade color when apply format if there is a manually set shade color */ export default function formatTable( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, format: TableMetadataFormat, keepCellShade?: boolean ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/table/insertTable.ts b/packages/roosterjs-content-model/lib/publicApi/table/insertTable.ts index eabcd44cc44..3c9b793e7dc 100644 --- a/packages/roosterjs-content-model/lib/publicApi/table/insertTable.ts +++ b/packages/roosterjs-content-model/lib/publicApi/table/insertTable.ts @@ -3,7 +3,7 @@ import { createContentModelDocument } from '../../modelApi/creators/createConten import { createSelectionMarker } from '../../modelApi/creators/createSelectionMarker'; import { createTableStructure } from '../../modelApi/table/createTableStructure'; import { formatWithContentModel } from '../utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { mergeModel } from '../../modelApi/common/mergeModel'; import { normalizeTable } from '../../modelApi/table/normalizeTable'; import { setSelection } from '../../modelApi/selection/setSelection'; @@ -19,7 +19,7 @@ import { TableMetadataFormat } from '../../publicTypes/format/formatParts/TableM * background color: #FFF; border color: #ABABAB */ export default function insertTable( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, columns: number, rows: number, format?: TableMetadataFormat diff --git a/packages/roosterjs-content-model/lib/publicApi/table/setTableCellShade.ts b/packages/roosterjs-content-model/lib/publicApi/table/setTableCellShade.ts index 83f6c8f4d1c..dcf9a85f145 100644 --- a/packages/roosterjs-content-model/lib/publicApi/table/setTableCellShade.ts +++ b/packages/roosterjs-content-model/lib/publicApi/table/setTableCellShade.ts @@ -1,7 +1,7 @@ import hasSelectionInBlockGroup from '../selection/hasSelectionInBlockGroup'; import { formatWithContentModel } from '../utils/formatWithContentModel'; import { getFirstSelectedTable } from '../../modelApi/selection/collectSelections'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { normalizeTable } from '../../modelApi/table/normalizeTable'; import { setTableCellBackgroundColor } from '../../modelApi/table/setTableCellBackgroundColor'; @@ -10,7 +10,7 @@ import { setTableCellBackgroundColor } from '../../modelApi/table/setTableCellBa * @param editor The editor instance * @param color The color to set */ -export default function setTableCellShade(editor: IExperimentalContentModelEditor, color: string) { +export default function setTableCellShade(editor: IContentModelEditor, color: string) { formatWithContentModel(editor, 'setTableCellShade', model => { const table = getFirstSelectedTable(model); diff --git a/packages/roosterjs-content-model/lib/publicApi/utils/formatImageWithContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/utils/formatImageWithContentModel.ts index b85e52df87d..a3170086e90 100644 --- a/packages/roosterjs-content-model/lib/publicApi/utils/formatImageWithContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/utils/formatImageWithContentModel.ts @@ -1,12 +1,12 @@ import { ContentModelImage } from '../../publicTypes/segment/ContentModelImage'; import { formatSegmentWithContentModel } from './formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * @internal */ export default function formatImageWithContentModel( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, apiName: string, callback: (segment: ContentModelImage) => void ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/utils/formatParagraphWithContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/utils/formatParagraphWithContentModel.ts index b509a32fdd3..aa68f490f77 100644 --- a/packages/roosterjs-content-model/lib/publicApi/utils/formatParagraphWithContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/utils/formatParagraphWithContentModel.ts @@ -1,13 +1,13 @@ import { ContentModelParagraph } from '../../publicTypes/block/ContentModelParagraph'; import { formatWithContentModel } from './formatWithContentModel'; import { getSelectedParagraphs } from '../../modelApi/selection/collectSelections'; -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * @internal */ export function formatParagraphWithContentModel( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, apiName: string, setStyleCallback: (paragraph: ContentModelParagraph) => void ) { diff --git a/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts index efe3a1a61f5..6e1d1f2dca0 100644 --- a/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/utils/formatSegmentWithContentModel.ts @@ -1,18 +1,15 @@ import { adjustWordSelection } from '../../modelApi/selection/adjustWordSelection'; import { ContentModelSegment } from '../../publicTypes/segment/ContentModelSegment'; import { ContentModelSegmentFormat } from '../../publicTypes/format/ContentModelSegmentFormat'; +import { DomToModelOption, IContentModelEditor } from '../../publicTypes/IContentModelEditor'; import { formatWithContentModel } from './formatWithContentModel'; import { getPendingFormat, setPendingFormat } from '../format/pendingFormat'; import { getSelectedSegments } from '../../modelApi/selection/collectSelections'; -import { - DomToModelOption, - IExperimentalContentModelEditor, -} from '../../publicTypes/IExperimentalContentModelEditor'; /** * @internal */ export function formatSegmentWithContentModel( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, apiName: string, toggleStyleCallback: ( format: ContentModelSegmentFormat, diff --git a/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts b/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts index 7cb1c0c9276..4c242e2cb00 100644 --- a/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts +++ b/packages/roosterjs-content-model/lib/publicApi/utils/formatWithContentModel.ts @@ -1,15 +1,12 @@ import { ChangeSource } from 'roosterjs-editor-types'; import { ContentModelDocument } from '../../publicTypes/group/ContentModelDocument'; -import { - DomToModelOption, - IExperimentalContentModelEditor, -} from '../../publicTypes/IExperimentalContentModelEditor'; +import { DomToModelOption, IContentModelEditor } from '../../publicTypes/IContentModelEditor'; /** * @internal */ export function formatWithContentModel( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, apiName: string, callback: (model: ContentModelDocument) => boolean, domToModelOptions?: DomToModelOption diff --git a/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts b/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts index c35331bd568..14c6e490344 100644 --- a/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts +++ b/packages/roosterjs-content-model/lib/publicPlugin/ContentModelPlugin.ts @@ -2,7 +2,7 @@ import { ContentModelSegmentFormat } from '../publicTypes/format/ContentModelSeg import { createText } from '../modelApi/creators/createText'; import { EditorPlugin, IEditor, Keys, PluginEvent, PluginEventType } from 'roosterjs-editor-types'; import { getPendingFormat, setPendingFormat } from '../publicApi/format/pendingFormat'; -import { IExperimentalContentModelEditor } from '../publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../publicTypes/IContentModelEditor'; import { iterateSelections } from '../modelApi/selection/iterateSelections'; /** @@ -11,7 +11,7 @@ import { iterateSelections } from '../modelApi/selection/iterateSelections'; * 1. Handle pending format changes when selection is collapsed */ export default class ContentModelPlugin implements EditorPlugin { - private editor: IExperimentalContentModelEditor | null = null; + private editor: IContentModelEditor | null = null; /** * Get name of this plugin @@ -28,7 +28,7 @@ export default class ContentModelPlugin implements EditorPlugin { */ initialize(editor: IEditor) { // TODO: Later we may need a different interface for Content Model editor plugin - this.editor = editor as IExperimentalContentModelEditor; + this.editor = editor as IContentModelEditor; } /** @@ -76,7 +76,7 @@ export default class ContentModelPlugin implements EditorPlugin { } function applyPendingFormat( - editor: IExperimentalContentModelEditor, + editor: IContentModelEditor, data: string, format: ContentModelSegmentFormat ) { diff --git a/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts b/packages/roosterjs-content-model/lib/publicTypes/IContentModelEditor.ts similarity index 92% rename from packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts rename to packages/roosterjs-content-model/lib/publicTypes/IContentModelEditor.ts index 7bb5c54c224..d699564e5fa 100644 --- a/packages/roosterjs-content-model/lib/publicTypes/IExperimentalContentModelEditor.ts +++ b/packages/roosterjs-content-model/lib/publicTypes/IContentModelEditor.ts @@ -81,11 +81,10 @@ export interface ModelToDomOption { } /** - * !!! This is a temporary interface and will be removed in the future !!! - * - * An interface of editor with Content Model support (in experiment) + * An interface of editor with Content Model support. + * (This interface is still under development, and may still be changed in the future with some breaking changes) */ -export interface IExperimentalContentModelEditor extends IEditor { +export interface IContentModelEditor extends IEditor { /** * Create Content Model from DOM tree in this editor * @param rootNode Optional start node. If provided, Content Model will be created from this node (including itself), diff --git a/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts b/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts index ae804e305eb..6f4a454f47e 100644 --- a/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts +++ b/packages/roosterjs-content-model/test/publicApi/block/paragraphTestCommon.ts @@ -1,9 +1,9 @@ import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; export function paragraphTestCommon( apiName: string, - executionCallback: (editor: IExperimentalContentModelEditor) => void, + executionCallback: (editor: IContentModelEditor) => void, model: ContentModelDocument, result: ContentModelDocument, calledTimes: number @@ -23,7 +23,7 @@ export function paragraphTestCommon( addUndoSnapshot, focus: jasmine.createSpy(), setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; executionCallback(editor); diff --git a/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts b/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts index 5d9c88e0df8..488d932812d 100644 --- a/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/block/setIndentationTest.ts @@ -1,16 +1,16 @@ import * as formatWithContentModel from '../../../lib/publicApi/utils/formatWithContentModel'; import * as setModelIndentation from '../../../lib/modelApi/block/setModelIndentation'; import setIndentation from '../../../lib/publicApi/block/setIndentation'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('setIndentation', () => { const fakeModel: any = { a: 'b' }; - let editor: IExperimentalContentModelEditor; + let editor: IContentModelEditor; beforeEach(() => { editor = ({ createContentModel: () => fakeModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); it('indent', () => { diff --git a/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts b/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts index c1bb6179582..9aed7bd2ba4 100644 --- a/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/block/toggleBlockQuoteTest.ts @@ -1,16 +1,16 @@ import * as formatWithContentModel from '../../../lib/publicApi/utils/formatWithContentModel'; import * as toggleModelBlockQuote from '../../../lib/modelApi/block/toggleModelBlockQuote'; import toggleBlockQuote from '../../../lib/publicApi/block/toggleBlockQuote'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('toggleBlockQuote', () => { const fakeModel: any = { a: 'b' }; - let editor: IExperimentalContentModelEditor; + let editor: IContentModelEditor; beforeEach(() => { editor = ({ createContentModel: () => fakeModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); it('toggleBlockQuote', () => { diff --git a/packages/roosterjs-content-model/test/publicApi/format/clearFormatTest.ts b/packages/roosterjs-content-model/test/publicApi/format/clearFormatTest.ts index 823ed06b6c1..2e9ea7b7d53 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/clearFormatTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/clearFormatTest.ts @@ -3,11 +3,11 @@ import * as formatWithContentModel from '../../../lib/publicApi/utils/formatWith import * as normalizeContentModel from '../../../lib/modelApi/common/normalizeContentModel'; import clearFormat from '../../../lib/publicApi/format/clearFormat'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('clearFormat', () => { it('Clear format', () => { - const editor = ({} as any) as IExperimentalContentModelEditor; + const editor = ({} as any) as IContentModelEditor; const model = ('Model' as any) as ContentModelDocument; spyOn(formatWithContentModel, 'formatWithContentModel').and.callFake( diff --git a/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts b/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts index 07dd7f795c1..5e4c444a681 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/getFormatStateTest.ts @@ -10,8 +10,8 @@ import { normalizeContentModel } from '../../../lib/modelApi/common/normalizeCon import { DomToModelOption, - IExperimentalContentModelEditor, -} from '../../../lib/publicTypes/IExperimentalContentModelEditor'; + IContentModelEditor, +} from '../../../lib/publicTypes/IContentModelEditor'; const selectedNodeId = 'Selected'; @@ -54,7 +54,7 @@ describe('getFormatState', () => { return model; }, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; spyOn(getPendingFormat, 'getPendingFormat').and.returnValue(pendingFormat); diff --git a/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts b/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts index aa300bd63d5..8f639d3ced7 100644 --- a/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/format/getSegmentFormatTest.ts @@ -9,8 +9,8 @@ import { PositionType, SelectionRangeTypes } from 'roosterjs-editor-types'; import { DomToModelOption, - IExperimentalContentModelEditor, -} from '../../../lib/publicTypes/IExperimentalContentModelEditor'; + IContentModelEditor, +} from '../../../lib/publicTypes/IContentModelEditor'; const selectedNodeId = 'Selected'; @@ -64,7 +64,7 @@ describe('getSegmentFormat', () => { return model; }, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const result = getSegmentFormat(editor); expect(result).toEqual(expectedFormat); diff --git a/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts b/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts index fcbc14dab32..1a191b7dbda 100644 --- a/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/insert/insertImageTest.ts @@ -4,14 +4,14 @@ import { addSegment } from '../../../lib/modelApi/common/addSegment'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; import { createSelectionMarker } from '../../../lib/modelApi/creators/createSelectionMarker'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('insertImage', () => { const testUrl = 'http://test.com/test'; function runTest( apiName: string, - executionCallback: (editor: IExperimentalContentModelEditor) => void, + executionCallback: (editor: IContentModelEditor) => void, model: ContentModelDocument, result: ContentModelDocument, calledTimes: number @@ -35,7 +35,7 @@ describe('insertImage', () => { setContentModel, isDisposed: () => false, getDocument: () => document, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; executionCallback(editor); diff --git a/packages/roosterjs-content-model/test/publicApi/link/adjustLinkSelectionTest.ts b/packages/roosterjs-content-model/test/publicApi/link/adjustLinkSelectionTest.ts index 6e8979be2bf..719085bd6ce 100644 --- a/packages/roosterjs-content-model/test/publicApi/link/adjustLinkSelectionTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/link/adjustLinkSelectionTest.ts @@ -8,12 +8,12 @@ import { createImage } from '../../../lib/modelApi/creators/createImage'; import { createParagraph } from '../../../lib/modelApi/creators/createParagraph'; import { createSelectionMarker } from '../../../lib/modelApi/creators/createSelectionMarker'; import { createText } from '../../../lib/modelApi/creators/createText'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('adjustLinkSelection', () => { - let editor: IExperimentalContentModelEditor; - let setContentModel: jasmine.Spy; - let createContentModel: jasmine.Spy; + let editor: IContentModelEditor; + let setContentModel: jasmine.Spy; + let createContentModel: jasmine.Spy; beforeEach(() => { setContentModel = jasmine.createSpy('setContentModel'); @@ -24,7 +24,7 @@ describe('adjustLinkSelection', () => { addUndoSnapshot: (callback: Function) => callback(), setContentModel, createContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); function runTest( diff --git a/packages/roosterjs-content-model/test/publicApi/link/insertLinkTest.ts b/packages/roosterjs-content-model/test/publicApi/link/insertLinkTest.ts index fcf4ed67866..cdecd2e1ba6 100644 --- a/packages/roosterjs-content-model/test/publicApi/link/insertLinkTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/link/insertLinkTest.ts @@ -7,12 +7,12 @@ import { createImage } from '../../../lib/modelApi/creators/createImage'; import { createSelectionMarker } from '../../../lib/modelApi/creators/createSelectionMarker'; import { createText } from '../../../lib/modelApi/creators/createText'; import { HyperLinkColorPlaceholder } from '../../../lib/formatHandlers/utils/defaultStyles'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('insertLink', () => { - let editor: IExperimentalContentModelEditor; - let setContentModel: jasmine.Spy; - let createContentModel: jasmine.Spy; + let editor: IContentModelEditor; + let setContentModel: jasmine.Spy; + let createContentModel: jasmine.Spy; beforeEach(() => { setContentModel = jasmine.createSpy('setContentModel'); @@ -23,7 +23,7 @@ describe('insertLink', () => { addUndoSnapshot: (callback: Function) => callback(), setContentModel, createContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); function runTest( diff --git a/packages/roosterjs-content-model/test/publicApi/link/removeLinkTest.ts b/packages/roosterjs-content-model/test/publicApi/link/removeLinkTest.ts index 5aded16554b..90ba10a4e8f 100644 --- a/packages/roosterjs-content-model/test/publicApi/link/removeLinkTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/link/removeLinkTest.ts @@ -6,12 +6,12 @@ import { ContentModelLink } from '../../../lib/publicTypes/decorator/ContentMode import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; import { createImage } from '../../../lib/modelApi/creators/createImage'; import { createText } from '../../../lib/modelApi/creators/createText'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('removeLink', () => { - let editor: IExperimentalContentModelEditor; - let setContentModel: jasmine.Spy; - let createContentModel: jasmine.Spy; + let editor: IContentModelEditor; + let setContentModel: jasmine.Spy; + let createContentModel: jasmine.Spy; beforeEach(() => { setContentModel = jasmine.createSpy('setContentModel'); @@ -22,7 +22,7 @@ describe('removeLink', () => { addUndoSnapshot: (callback: Function) => callback(), setContentModel, createContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); function runTest(model: ContentModelDocument, expectedModel: ContentModelDocument | null) { diff --git a/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts b/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts index def21f3af0a..fbb27ebd9d3 100644 --- a/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/list/toggleBulletTest.ts @@ -1,10 +1,10 @@ import * as setListType from '../../../lib/modelApi/list/setListType'; import toggleBullet from '../../../lib/publicApi/list/toggleBullet'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('toggleBullet', () => { - let editor = ({} as any) as IExperimentalContentModelEditor; + let editor = ({} as any) as IContentModelEditor; let addUndoSnapshot: jasmine.Spy; let createContentModel: jasmine.Spy; let setContentModel: jasmine.Spy; @@ -24,7 +24,7 @@ describe('toggleBullet', () => { addUndoSnapshot, createContentModel, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; spyOn(setListType, 'setListType').and.returnValue(true); }); diff --git a/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts b/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts index d1bd9899437..2b44628334f 100644 --- a/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/list/toggleNumberingTest.ts @@ -1,10 +1,10 @@ import * as setListType from '../../../lib/modelApi/list/setListType'; import toggleNumbering from '../../../lib/publicApi/list/toggleNumbering'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('toggleNumbering', () => { - let editor = ({} as any) as IExperimentalContentModelEditor; + let editor = ({} as any) as IContentModelEditor; let addUndoSnapshot: jasmine.Spy; let createContentModel: jasmine.Spy; let setContentModel: jasmine.Spy; @@ -24,7 +24,7 @@ describe('toggleNumbering', () => { addUndoSnapshot, createContentModel, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; spyOn(setListType, 'setListType').and.returnValue(true); }); diff --git a/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts b/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts index 820599c1285..afadb34733c 100644 --- a/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/segment/changeFontSizeTest.ts @@ -4,7 +4,7 @@ import changeFontSize from '../../../lib/publicApi/segment/changeFontSize'; import domToContentModel from '../../../lib/publicApi/domToContentModel'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; import { createRange } from 'roosterjs-editor-dom'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; import { segmentTestCommon } from './segmentTestCommon'; import { SelectionRangeTypes } from 'roosterjs-editor-types'; @@ -356,7 +356,7 @@ describe('changeFontSize', () => { addUndoSnapshot, focus: jasmine.createSpy(), setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; spyOn(getComputedStyles, 'getComputedStyle').and.callFake( (node: HTMLElement, style: string) => { diff --git a/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts b/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts index 5fb699aa317..574619976be 100644 --- a/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts +++ b/packages/roosterjs-content-model/test/publicApi/segment/segmentTestCommon.ts @@ -1,10 +1,10 @@ import * as pendingFormat from '../../../lib/publicApi/format/pendingFormat'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; export function segmentTestCommon( apiName: string, - executionCallback: (editor: IExperimentalContentModelEditor) => void, + executionCallback: (editor: IContentModelEditor) => void, model: ContentModelDocument, result: ContentModelDocument, calledTimes: number @@ -28,7 +28,7 @@ export function segmentTestCommon( focus: jasmine.createSpy(), setContentModel, isDisposed: () => false, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; executionCallback(editor); diff --git a/packages/roosterjs-content-model/test/publicApi/table/setTableCellShadeTest.ts b/packages/roosterjs-content-model/test/publicApi/table/setTableCellShadeTest.ts index 44acc8e9385..29ca81868dc 100644 --- a/packages/roosterjs-content-model/test/publicApi/table/setTableCellShadeTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/table/setTableCellShadeTest.ts @@ -2,12 +2,12 @@ import * as normalizeTable from '../../../lib/modelApi/table/normalizeTable'; import setTableCellShade from '../../../lib/publicApi/table/setTableCellShade'; import { ContentModelTable } from '../../../lib/publicTypes/block/ContentModelTable'; import { createContentModelDocument } from '../../../lib/modelApi/creators/createContentModelDocument'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('setTableCellShade', () => { - let editor: IExperimentalContentModelEditor; - let setContentModel: jasmine.Spy; - let createContentModel: jasmine.Spy; + let editor: IContentModelEditor; + let setContentModel: jasmine.Spy; + let createContentModel: jasmine.Spy; beforeEach(() => { setContentModel = jasmine.createSpy('setContentModel'); @@ -20,7 +20,7 @@ describe('setTableCellShade', () => { addUndoSnapshot: (callback: Function) => callback(), setContentModel, createContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); function runTest(table: ContentModelTable, expectedTable: ContentModelTable | null) { diff --git a/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts index 6176705838a..5ceba23664a 100644 --- a/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/utils/formatParagraphWithContentModelTest.ts @@ -3,10 +3,10 @@ import { createContentModelDocument } from '../../../lib/modelApi/creators/creat import { createParagraph } from '../../../lib/modelApi/creators/createParagraph'; import { createText } from '../../../lib/modelApi/creators/createText'; import { formatParagraphWithContentModel } from '../../../lib/publicApi/utils/formatParagraphWithContentModel'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('formatParagraphWithContentModel', () => { - let editor: IExperimentalContentModelEditor; + let editor: IContentModelEditor; let addUndoSnapshot: jasmine.Spy; let setContentModel: jasmine.Spy; let focus: jasmine.Spy; @@ -24,7 +24,7 @@ describe('formatParagraphWithContentModel', () => { addUndoSnapshot, createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); it('empty doc', () => { diff --git a/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts index c0558f23f6b..f718054389f 100644 --- a/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/utils/formatSegmentWithContentModelTest.ts @@ -6,10 +6,10 @@ import { createParagraph } from '../../../lib/modelApi/creators/createParagraph' import { createSelectionMarker } from '../../../lib/modelApi/creators/createSelectionMarker'; import { createText } from '../../../lib/modelApi/creators/createText'; import { formatSegmentWithContentModel } from '../../../lib/publicApi/utils/formatSegmentWithContentModel'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('formatSegmentWithContentModel', () => { - let editor: IExperimentalContentModelEditor; + let editor: IContentModelEditor; let addUndoSnapshot: jasmine.Spy; let setContentModel: jasmine.Spy; let focus: jasmine.Spy; @@ -32,7 +32,7 @@ describe('formatSegmentWithContentModel', () => { addUndoSnapshot, createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); it('empty doc', () => { diff --git a/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts b/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts index 4e9c5ab09bc..b40fc3c8909 100644 --- a/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts +++ b/packages/roosterjs-content-model/test/publicApi/utils/formatWithContentModelTest.ts @@ -1,10 +1,10 @@ import { ChangeSource } from 'roosterjs-editor-types'; import { ContentModelDocument } from '../../../lib/publicTypes/group/ContentModelDocument'; import { formatWithContentModel } from '../../../lib/publicApi/utils/formatWithContentModel'; -import { IExperimentalContentModelEditor } from '../../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../../lib/publicTypes/IContentModelEditor'; describe('formatWithContentModel', () => { - let editor: IExperimentalContentModelEditor; + let editor: IContentModelEditor; let addUndoSnapshot: jasmine.Spy; let createContentModel: jasmine.Spy; let setContentModel: jasmine.Spy; @@ -26,7 +26,7 @@ describe('formatWithContentModel', () => { addUndoSnapshot, createContentModel, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; }); it('Callback return false', () => { diff --git a/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts b/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts index 72b7ad473f9..f4855c6092c 100644 --- a/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts +++ b/packages/roosterjs-content-model/test/publicPlugin/ContentModelPluginTest.ts @@ -4,7 +4,7 @@ import { addSegment } from '../../lib/modelApi/common/addSegment'; import { createContentModelDocument } from '../../lib/modelApi/creators/createContentModelDocument'; import { createSelectionMarker } from '../../lib/modelApi/creators/createSelectionMarker'; import { createText } from '../../lib/modelApi/creators/createText'; -import { IExperimentalContentModelEditor } from '../../lib/publicTypes/IExperimentalContentModelEditor'; +import { IContentModelEditor } from '../../lib/publicTypes/IContentModelEditor'; import { PluginEventType } from 'roosterjs-editor-types'; describe('ContentModelPlugin', () => { @@ -12,7 +12,7 @@ describe('ContentModelPlugin', () => { spyOn(pendingFormat, 'setPendingFormat'); spyOn(pendingFormat, 'getPendingFormat').and.returnValue(null); - const editor = ({} as any) as IExperimentalContentModelEditor; + const editor = ({} as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -39,7 +39,7 @@ describe('ContentModelPlugin', () => { createContentModel: () => model, setContentModel, isInIME: () => false, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); const model = createContentModelDocument(); @@ -71,7 +71,7 @@ describe('ContentModelPlugin', () => { const editor = ({ createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -101,7 +101,7 @@ describe('ContentModelPlugin', () => { createContentModel: () => model, setContentModel, isInIME: () => false, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -134,7 +134,7 @@ describe('ContentModelPlugin', () => { createContentModel: () => model, setContentModel, isInIME: () => false, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -193,7 +193,7 @@ describe('ContentModelPlugin', () => { const editor = ({ createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -247,7 +247,7 @@ describe('ContentModelPlugin', () => { const editor = ({ createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -273,7 +273,7 @@ describe('ContentModelPlugin', () => { const editor = ({ createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); @@ -300,7 +300,7 @@ describe('ContentModelPlugin', () => { const editor = ({ createContentModel: () => model, setContentModel, - } as any) as IExperimentalContentModelEditor; + } as any) as IContentModelEditor; const plugin = new ContentModelPlugin(); plugin.initialize(editor); From 4afe2d70a62c0a67cd912d10a0c0333040cff99b Mon Sep 17 00:00:00 2001 From: Jiuqing Song Date: Thu, 2 Feb 2023 16:30:56 -0800 Subject: [PATCH 6/6] fix build --- .../lib/publicApi/block/setSpacing.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/roosterjs-content-model/lib/publicApi/block/setSpacing.ts b/packages/roosterjs-content-model/lib/publicApi/block/setSpacing.ts index 2a16491146b..048e6b0f34e 100644 --- a/packages/roosterjs-content-model/lib/publicApi/block/setSpacing.ts +++ b/packages/roosterjs-content-model/lib/publicApi/block/setSpacing.ts @@ -1,10 +1,7 @@ -import { IExperimentalContentModelEditor } from '../../publicTypes/IExperimentalContentModelEditor'; import { formatParagraphWithContentModel } from '../utils/formatParagraphWithContentModel'; +import { IContentModelEditor } from '../../publicTypes/IContentModelEditor'; -export default function setSpacing( - editor: IExperimentalContentModelEditor, - spacing: number | string -) { +export default function setSpacing(editor: IContentModelEditor, spacing: number | string) { formatParagraphWithContentModel(editor, 'setSpacing', paragraph => { paragraph.format.lineHeight = spacing.toString(); paragraph.segments.forEach(segment => {