Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump version to 9.13.0 #2856

Merged
merged 9 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ function getIndexedTableItem(element: HTMLTableElement): TableItem | null {
}
}

// Make a node not indexed. Do not export this function since we should not let code outside here know this detail
function unindex(node: Partial<IndexedSegmentNode>) {
delete node.__roosterjsContentModel;
}

/**
* @internal
* Implementation of DomIndexer
Expand Down Expand Up @@ -197,6 +202,21 @@ export class DomIndexerImpl implements DomIndexer {
this.onBlockEntityDelimiter(entity.wrapper.nextSibling, entity, group);
}

onMergeText(targetText: Text, sourceText: Text) {
if (isIndexedSegment(targetText) && isIndexedSegment(sourceText)) {
if (targetText.nextSibling == sourceText) {
targetText.__roosterjsContentModel.segments.push(
...sourceText.__roosterjsContentModel.segments
);

unindex(sourceText);
}
} else {
unindex(sourceText);
unindex(targetText);
}
}

reconcileSelection(
model: ContentModelDocument,
newSelection: DOMSelection,
Expand Down
4 changes: 0 additions & 4 deletions packages/roosterjs-content-model-core/lib/editor/Editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createEditorCore } from './core/createEditorCore';
import {
createEmptyModel,
tableProcessor,
ChangeSource,
cloneModel,
transformColor,
Expand Down Expand Up @@ -102,9 +101,6 @@ export class Editor implements IEditor {
case 'disconnected':
return cloneModel(
core.api.createContentModel(core, {
processorOverride: {
table: tableProcessor,
},
tryGetFromCache: false,
}),
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createDomToModelConfig, createModelToDomConfig } from 'roosterjs-content-model-dom';
import { tablePreProcessor } from '../../override/tablePreProcessor';
import {
listItemMetadataApplier,
listLevelMetadataApplier,
Expand All @@ -21,11 +20,7 @@ import type {
export function createDomToModelSettings(
options: EditorOptions
): ContentModelSettings<DomToModelOption, DomToModelSettings> {
const builtIn: DomToModelOption = {
processorOverride: {
table: tablePreProcessor,
},
};
const builtIn: DomToModelOption = {};
const customized: DomToModelOption = options.defaultDomToModelOptions ?? {};

return {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Unformatted line',
text: 'Unformatted line\n',
format: {
fontSize: '14px',
textColor: 'white',
Expand Down Expand Up @@ -1149,15 +1149,7 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Unformatted line',
format: {
fontSize: '14px',
textColor: 'white',
},
},
{
segmentType: 'Text',
text: '\n',
text: 'Unformatted line\n',
format: {
fontSize: '14px',
textColor: 'white',
Expand Down Expand Up @@ -1490,15 +1482,7 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Inline text',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
},
},
{
segmentType: 'Text',
text: '\n',
text: 'Inline text\n',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
Expand Down Expand Up @@ -1553,15 +1537,7 @@ describe('mergePasteContent', () => {
},
{
segmentType: 'Text',
text: 'Inline text',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
},
},
{
segmentType: 'Text',
text: '\n',
text: 'Inline text\n',
format: {
fontSize: '14px',
textColor: 'rgb(0,0,0)',
Expand Down Expand Up @@ -1629,16 +1605,7 @@ describe('mergePasteContent', () => {
segments: [
{
segmentType: 'Text',
text: 'Inline text',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
textColor: 'white',
},
},
{
segmentType: 'Text',
text: '\n',
text: 'Inline text\n',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
Expand Down Expand Up @@ -1686,16 +1653,7 @@ describe('mergePasteContent', () => {
{ segmentType: 'Text', text: 'Text in source', format: {} },
{
segmentType: 'Text',
text: 'Inline text',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
textColor: 'white',
},
},
{
segmentType: 'Text',
text: '\n',
text: 'Inline text\n',
format: {
fontFamily: 'Aptos',
fontSize: '14px',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,103 @@ describe('domIndexerImpl.onBlockEntity', () => {
});
});

describe('domIndexImpl.onMergeText', () => {
it('Two unindexed node', () => {
const text1 = document.createTextNode('test1');
const text2 = document.createTextNode('test1');
const div = document.createElement('div');

div.appendChild(text1);
div.appendChild(text2);

new DomIndexerImpl().onMergeText(text1, text2);

expect(((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel).toBeUndefined();
expect(((text2 as Node) as IndexedSegmentNode).__roosterjsContentModel).toBeUndefined();
});

it('One indexed node, one unindexed node', () => {
const text1 = document.createTextNode('test1');
const text2 = document.createTextNode('test1');
const div = document.createElement('div');

div.appendChild(text1);
div.appendChild(text2);

((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel = {
paragraph: createParagraph(),
segments: [],
};

new DomIndexerImpl().onMergeText(text1, text2);

expect(((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel).toBeUndefined();
expect(((text2 as Node) as IndexedSegmentNode).__roosterjsContentModel).toBeUndefined();
});

it('Two separated indexed node', () => {
const text1 = document.createTextNode('test1');
const text2 = document.createTextNode('test1');
const div = document.createElement('div');

div.appendChild(text1);
div.appendChild(document.createElement('img'));
div.appendChild(text2);

const text1Model = createText('test1');
const text2Model = createText('test2');

((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel = {
paragraph: createParagraph(),
segments: [text1Model],
};
((text2 as Node) as IndexedSegmentNode).__roosterjsContentModel = {
paragraph: createParagraph(),
segments: [text2Model],
};

new DomIndexerImpl().onMergeText(text1, text2);

expect(((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel).toEqual({
paragraph: createParagraph(),
segments: [text1Model],
});
expect(((text2 as Node) as IndexedSegmentNode).__roosterjsContentModel).toEqual({
paragraph: createParagraph(),
segments: [text2Model],
});
});

it('Two continuous indexed node', () => {
const text1 = document.createTextNode('test1');
const text2 = document.createTextNode('test1');
const div = document.createElement('div');

div.appendChild(text1);
div.appendChild(text2);

const text1Model = createText('test1');
const text2Model = createText('test2');

((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel = {
paragraph: createParagraph(),
segments: [text1Model],
};
((text2 as Node) as IndexedSegmentNode).__roosterjsContentModel = {
paragraph: createParagraph(),
segments: [text2Model],
};

new DomIndexerImpl().onMergeText(text1, text2);

expect(((text1 as Node) as IndexedSegmentNode).__roosterjsContentModel).toEqual({
paragraph: createParagraph(),
segments: [text1Model, text2Model],
});
expect(((text2 as Node) as IndexedSegmentNode).__roosterjsContentModel).toBeUndefined();
});
});

describe('domIndexerImpl.reconcileSelection', () => {
let setSelectionSpy: jasmine.Spy;
let model: ContentModelDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as createEditorCore from '../../lib/editor/core/createEditorCore';
import * as createEmptyModel from 'roosterjs-content-model-dom/lib/modelApi/creators/createEmptyModel';
import * as domToContentModel from 'roosterjs-content-model-dom/lib/domToModel/domToContentModel';
import * as transformColor from 'roosterjs-content-model-dom/lib/domUtils/style/transformColor';
import { ChangeSource, tableProcessor } from 'roosterjs-content-model-dom';
import { Editor } from '../../lib/editor/Editor';
import { expectHtml } from 'roosterjs-content-model-dom/test/testUtils';
import { ChangeSource } from 'roosterjs-content-model-dom';
import {
CachedElementHandler,
ContentModelDocument,
Expand Down Expand Up @@ -198,9 +198,6 @@ describe('Editor', () => {

expect(model).toBe(mockedClonedModel);
expect(createContentModelSpy).toHaveBeenCalledWith(mockedCore, {
processorOverride: {
table: tableProcessor,
},
tryGetFromCache: false,
});
expect(transformColorSpy).not.toHaveBeenCalled();
Expand All @@ -212,9 +209,6 @@ describe('Editor', () => {

expect(model).toBe(mockedClonedModel);
expect(createContentModelSpy).toHaveBeenCalledWith(mockedCore, {
processorOverride: {
table: tableProcessor,
},
tryGetFromCache: false,
});
expect(transformColorSpy).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as createDomToModelContext from 'roosterjs-content-model-dom/lib/domToModel/context/createDomToModelContext';
import * as createModelToDomContext from 'roosterjs-content-model-dom/lib/modelToDom/context/createModelToDomContext';
import { tablePreProcessor } from '../../../lib/override/tablePreProcessor';
import {
listItemMetadataApplier,
listLevelMetadataApplier,
Expand All @@ -23,22 +22,11 @@ describe('createDomToModelSettings', () => {
const settings = createDomToModelSettings({});

expect(settings).toEqual({
builtIn: {
processorOverride: {
table: tablePreProcessor,
},
},
builtIn: {},
customized: {},
calculated: mockedCalculatedConfig,
});
expect(createDomToModelContext.createDomToModelConfig).toHaveBeenCalledWith([
{
processorOverride: {
table: tablePreProcessor,
},
},
{},
]);
expect(createDomToModelContext.createDomToModelConfig).toHaveBeenCalledWith([{}, {}]);
});

it('Has options', () => {
Expand All @@ -48,20 +36,12 @@ describe('createDomToModelSettings', () => {
});

expect(settings).toEqual({
builtIn: {
processorOverride: {
table: tablePreProcessor,
},
},
builtIn: {},
customized: defaultDomToModelOptions,
calculated: mockedCalculatedConfig,
});
expect(createDomToModelContext.createDomToModelConfig).toHaveBeenCalledWith([
{
processorOverride: {
table: tablePreProcessor,
},
},
{},
defaultDomToModelOptions,
]);
});
Expand Down
Loading
Loading