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 9.3.1 -> 9.4 #2658

Merged
merged 145 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
145 commits
Select commit Hold shift + click to select a range
ba053e7
code suport
juliaroldi Mar 26, 2024
48f2fae
markdown
juliaroldi Mar 26, 2024
f9a11a0
conflicts
juliaroldi Apr 1, 2024
1f105ff
adjust
juliaroldi Apr 1, 2024
02ecb84
Merge branch 'master' into u/juliaroldi/port-markdown-plugin-2
juliaroldi Apr 1, 2024
287a8df
demo site
juliaroldi Apr 1, 2024
716f914
Merge branch 'u/juliaroldi/port-markdown-plugin-2' of https://github.…
juliaroldi Apr 1, 2024
c712f3b
WIP
juliaroldi Apr 1, 2024
34ac350
fix code pen
juliaroldi Apr 1, 2024
7489c6d
fix demo site
juliaroldi Apr 1, 2024
1c276af
Merge pull request #2527 from microsoft/u/juliaroldi/port-markdown-pl…
juliaroldi Apr 1, 2024
a5967fb
fix conflixts
juliaroldi Apr 1, 2024
f362e01
Handle Tab key on whole table selection or last cell on Edit Plugin (…
Andres-CT98 Apr 1, 2024
13543b9
Merge branch 'master' into u/juliaroldi/auto-format-demo-site
juliaroldi Apr 2, 2024
9460c0c
Merge pull request #2549 from microsoft/u/juliaroldi/auto-format-demo…
juliaroldi Apr 2, 2024
ef49253
Fix seelection on void element (#2551)
JiuqingSong Apr 2, 2024
498a9f4
port hyphen
juliaroldi Apr 2, 2024
259a94c
Merge branch 'master' into u/juliaroldi/auto-hypen-port
juliaroldi Apr 2, 2024
182ed16
Implement movement with Tab key inside Table (#2529)
Andres-CT98 Apr 2, 2024
28ecdae
fix tests
juliaroldi Apr 3, 2024
f9514d6
Merge branch 'u/juliaroldi/auto-hypen-port' of https://github.com/mic…
juliaroldi Apr 3, 2024
aa92ec3
Merge branch 'master' into u/juliaroldi/auto-hypen-port
juliaroldi Apr 3, 2024
80f1eca
add formatTextSegmentBeforeSelectionMarker
juliaroldi Apr 3, 2024
7995f21
Merge branch 'u/juliaroldi/auto-hypen-port' of https://github.com/mic…
juliaroldi Apr 3, 2024
154d72d
Improve backspace on list (#2555)
JiuqingSong Apr 3, 2024
4ace57a
fix selection with ctrl+a
juliaroldi Apr 3, 2024
1377277
Merge branch 'master' into u/juliaroldi/adjust-image-selection
juliaroldi Apr 3, 2024
12dc692
Merge pull request #2556 from microsoft/u/juliaroldi/adjust-image-sel…
juliaroldi Apr 4, 2024
b1b398e
refactor code using formatTextSegmentBeforeSelectionMarkerTest
juliaroldi Apr 4, 2024
c1b2a9d
remove getLinkSegment
juliaroldi Apr 4, 2024
4bb65d7
Merge branch 'master' into u/juliaroldi/format-segment-before-text
juliaroldi Apr 4, 2024
f34b360
Merge pull request #2557 from microsoft/u/juliaroldi/format-segment-b…
juliaroldi Apr 4, 2024
35c3a33
Set default format in demo site (#2559)
JiuqingSong Apr 4, 2024
35e08b3
clean demo site
juliaroldi Apr 5, 2024
3b4c904
clean
juliaroldi Apr 5, 2024
b7d50b4
Enable selecting image when the only element in the range is an Image…
BryanValverdeU Apr 5, 2024
1072c05
fix markdown plugin
juliaroldi Apr 5, 2024
39cd6c0
Merge branch 'master' into u/juliaroldi/add-markdown-options
juliaroldi Apr 5, 2024
bea0bd7
Port Hyperlink plugin (#2560)
JiuqingSong Apr 5, 2024
1958eab
conflicts
juliaroldi Apr 5, 2024
99a3bbf
Merge pull request #2562 from microsoft/u/juliaroldi/clean-content-edit
juliaroldi Apr 5, 2024
a8982cd
fix conflicts
juliaroldi Apr 5, 2024
4065ba6
Merge branch 'u/juliaroldi/add-markdown-options' of https://github.co…
juliaroldi Apr 5, 2024
31037a1
Merge pull request #2563 from microsoft/u/juliaroldi/add-markdown-opt…
juliaroldi Apr 5, 2024
7d865b9
export formatTextSegmentBeforeSelectionMarker
juliaroldi Apr 5, 2024
b55fe2c
fix build
juliaroldi Apr 5, 2024
53f1f4d
Prevent ScrollTop to be lost when the focus is done to the editor (#2…
BryanValverdeU Apr 5, 2024
29d5315
Merge branch 'master' into u/juliaroldi/export-formatSegment
BryanValverdeU Apr 5, 2024
86cc784
Merge pull request #2565 from microsoft/u/juliaroldi/export-formatSeg…
juliaroldi Apr 5, 2024
a4457db
Fix 265959: extra empty line generated when get plain text (#2566)
JiuqingSong Apr 5, 2024
2088aa5
Fix #2500 Hyperlink misses color (#2570)
JiuqingSong Apr 9, 2024
4ffd535
mac shortcuts
juliaroldi Apr 12, 2024
7ea28f9
fix test
juliaroldi Apr 12, 2024
25f0296
Merge pull request #2574 from microsoft/u/juliaroldi/mac-shortucuts
juliaroldi Apr 12, 2024
d598652
restore selection (#2577)
Rain-Zheng Apr 16, 2024
70684a4
fix: on webkit-based applications, when the selection is empty, focus…
miku1958 Apr 16, 2024
74bc863
Port PickerPlugin (#2569)
JiuqingSong Apr 16, 2024
09fbd0f
adjust image
juliaroldi Apr 16, 2024
b3be12d
fix test
juliaroldi Apr 16, 2024
26f3524
fixes
juliaroldi Apr 17, 2024
a3306fe
remove
juliaroldi Apr 17, 2024
a3e1508
Preserve reverted selection info in Content Model (#2580)
JiuqingSong Apr 17, 2024
8ae1f58
Merge branch 'master' into u/juliaroldi/image-width
juliaroldi Apr 17, 2024
4227e2f
Merge pull request #2579 from microsoft/u/juliaroldi/image-width
juliaroldi Apr 17, 2024
027cb4e
fix empty text
juliaroldi Apr 17, 2024
2250692
Merge branch 'master' into u/juliaroldi/fix-markdown
juliaroldi Apr 17, 2024
705eb09
Merge pull request #2582 from microsoft/u/juliaroldi/fix-markdown
juliaroldi Apr 17, 2024
7e77e4e
trigger Events
juliaroldi Apr 17, 2024
5425f02
Merge branch 'master' into u/juliaroldi/auto-format-api-name
juliaroldi Apr 17, 2024
29045a5
Allow Shift+Delete to Cut (#2585)
JiuqingSong Apr 18, 2024
c3dff00
Merge branch 'master' into u/juliaroldi/auto-format-api-name
juliaroldi Apr 18, 2024
692d221
change source
juliaroldi Apr 18, 2024
e368c85
fix build
juliaroldi Apr 18, 2024
1269238
Merge pull request #2583 from microsoft/u/juliaroldi/auto-format-api-…
juliaroldi Apr 18, 2024
b0cbd9a
Fix #2584: Safari context menu event causes selection to be expanded …
JiuqingSong Apr 20, 2024
4aa8ad2
Port AnnouncePlugin step 1: refactor list number code (#2589)
JiuqingSong Apr 20, 2024
e989c38
test
juliaroldi Apr 22, 2024
2ef7218
refactor
juliaroldi Apr 22, 2024
42dde83
Merge branch 'master' into u/juliaroldi/custom-replace-plugin
juliaroldi Apr 22, 2024
f49c201
fix demo site
juliaroldi Apr 22, 2024
a5b9456
Select image after inserting it (#2593)
BryanValverdeU Apr 22, 2024
49866d5
Merge branch 'master' into u/juliaroldi/custom-replace-plugin
BryanValverdeU Apr 22, 2024
a05e659
Port AnnouncePlugin Step 2: Add announce core API (#2591)
JiuqingSong Apr 22, 2024
4eb25b3
Merge branch 'master' into u/juliaroldi/custom-replace-plugin
juliaroldi Apr 22, 2024
dc5ffde
WIP
juliaroldi Apr 22, 2024
059f39d
custom replace
juliaroldi Apr 22, 2024
924ff2f
Merge branch 'u/juliaroldi/custom-replace-plugin' of https://github.c…
juliaroldi Apr 22, 2024
55b81d3
Fix table mover selector (#2596)
Andres-CT98 Apr 23, 2024
bf0766c
Merge branch 'master' into u/juliaroldi/custom-replace-plugin
juliaroldi Apr 23, 2024
7a42901
Merge pull request #2594 from microsoft/u/juliaroldi/custom-replace-p…
juliaroldi Apr 23, 2024
337cf7c
trigger autolink
juliaroldi Apr 23, 2024
2d38c17
Merge branch 'master' into u/juliaroldi/autoformat-numbers
juliaroldi Apr 23, 2024
7e5f1f5
Merge pull request #2598 from microsoft/u/juliaroldi/trigger-auto-link
juliaroldi Apr 23, 2024
57cd8af
wip
juliaroldi Apr 23, 2024
162b4e3
conflicts'
juliaroldi Apr 23, 2024
af63a38
Port AnnouncePlugin step 3: Add announce features for list and table …
JiuqingSong Apr 24, 2024
2396a39
Merge branch 'master' into u/juliaroldi/autoformat-numbers
juliaroldi Apr 24, 2024
e3cc9e8
Merge pull request #2595 from microsoft/u/juliaroldi/autoformat-numbers
juliaroldi Apr 24, 2024
b69795f
Fix #2575 Entity delimiter cursor moving (#2581)
JiuqingSong Apr 24, 2024
e944971
Allow customizability for table editors (#2603)
BryanValverdeU Apr 26, 2024
657542f
Also allow using Ctrl-Shift-Z on Windows (#2607)
florian-msft Apr 26, 2024
9510406
Wip
juliaroldi Apr 27, 2024
08ec7b0
add span
juliaroldi Apr 29, 2024
dcfe23b
fix test
juliaroldi Apr 29, 2024
e7d09eb
changes
juliaroldi Apr 30, 2024
e2c6ea6
remove code
juliaroldi Apr 30, 2024
73f2362
fixes
juliaroldi Apr 30, 2024
ca86446
fixes
juliaroldi Apr 30, 2024
7ca640e
Merge pull request #2609 from microsoft/u/juliaroldi/image-span
juliaroldi May 1, 2024
8010167
Hide watermark when input with IME (#2611)
JiuqingSong May 2, 2024
5b29fc5
Updated watermark property access modifier to protected (#2614)
vhuseinova-msft May 2, 2024
3b2154b
Move Content Model type files into contentModel folder (#2602)
JiuqingSong May 2, 2024
f65c6a0
Fix 262779 (#2600)
JiuqingSong May 6, 2024
73e62ec
Add undo snapshot when mouse down if there is new content after last …
JiuqingSong May 6, 2024
a3a14a4
Fix #2601 allow customization when convert from content model to plai…
JiuqingSong May 6, 2024
9b86a06
Scroll caret into view when call formatContentModel (#2617)
JiuqingSong May 7, 2024
ea719e1
Perf step 0: Do not allow getting connected model (#2615)
JiuqingSong May 7, 2024
8d2aa9f
debug firefox options (#2620)
Andres-CT98 May 9, 2024
6c69ef9
Updated isModelEmptyFast to consider changed indentation as not empty…
vhuseinova-msft May 9, 2024
b1d4bab
Add parameter to Disable table edit features (#2624)
Andres-CT98 May 10, 2024
01b4f1c
Implement Table Movement (#2599)
Andres-CT98 May 10, 2024
49be6ea
Do not apply Table selection if table is not editable (#2628)
BryanValverdeU May 13, 2024
b230301
Fix #2633 `scrollCaretIntoView` causes unexpected scroll (#2634)
JiuqingSong May 15, 2024
39b70fe
Added tableCellSelectionBackgroundColor option (#2640)
vhuseinova-msft May 17, 2024
7ac3ac7
Add dark color handling for table and image selection (#2647)
vhuseinova-msft May 17, 2024
88d743f
Fix cursor jump issue when applying Gboard suggestions (#2638)
Rain-Zheng May 20, 2024
8ec51b3
Content Model Cache improvement - Step 1: Introduce Readonly types an…
JiuqingSong May 20, 2024
926c2d1
test
juliaroldi May 21, 2024
1d8d743
test
juliaroldi May 21, 2024
11b943e
link preview
juliaroldi May 21, 2024
4995818
remove auto format plugin code
juliaroldi May 21, 2024
e09c51b
Merge branch 'master' into u/juliaroldi/auto-link
juliaroldi May 21, 2024
09a01de
Merge pull request #2653 from microsoft/u/juliaroldi/auto-link
juliaroldi May 21, 2024
1e128ea
Content Model Cache improvement - Step 2: Prepare utility functions (…
JiuqingSong May 21, 2024
ecdb478
Content Model Cache improvement - Step 3: Let creators accept readonl…
JiuqingSong May 22, 2024
bad75d9
Content Model Cache improvement - Step 4: Port "readonly" functions (…
JiuqingSong May 22, 2024
2aa32f4
Fix Table first column (#2652)
Andres-CT98 May 23, 2024
2b74dcb
Content Model Cache improvement - Step 5: Port roosterjs-content-mode…
JiuqingSong May 23, 2024
40dec70
Optimise content model table fetching for Table Edit Plugins (#2656)
Andres-CT98 May 24, 2024
2b5d0a5
Fix normalisation and First Column issues (#2657)
Andres-CT98 May 24, 2024
e174829
bump
Andres-CT98 May 24, 2024
e838caa
bump
Andres-CT98 May 24, 2024
740e04e
Merge branch 'u/acampostams/bump-9.4' of https://github.com/microsoft…
Andres-CT98 May 24, 2024
f0fae79
bump
Andres-CT98 May 24, 2024
e7c5f14
Merge branch 'u/acampostams/bump-9.4' of https://github.com/microsoft…
Andres-CT98 May 24, 2024
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
13 changes: 0 additions & 13 deletions demo/scripts/controlsV2/demoButtons/setTableHeaderButton.ts

This file was deleted.

53 changes: 53 additions & 0 deletions demo/scripts/controlsV2/demoButtons/tableOptionsButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { formatTable, getFormatState } from 'roosterjs-content-model-api';
import { TableMetadataFormat } from 'roosterjs-content-model-types';
import type { RibbonButton } from '../roosterjsReact/ribbon';

const TableEditOperationMap: Partial<Record<
TableOptionsMenuItemStringKey,
keyof TableMetadataFormat
>> = {
menuNameTableSetHeaderRow: 'hasHeaderRow',
menuNameTableSetFirstColumn: 'hasFirstColumn',
menuNameTableSetBandedColumns: 'hasBandedColumns',
menuNameTableSetBandedRows: 'hasBandedRows',
};

/**
* Key of localized strings of Table Options menu items
*/
type TableOptionsMenuItemStringKey =
| 'menuNameTableSetHeaderRow'
| 'menuNameTableSetFirstColumn'
| 'menuNameTableSetBandedColumns'
| 'menuNameTableSetBandedRows';

export const tableOptionsButton: RibbonButton<
'ribbonButtonTableOptions' | TableOptionsMenuItemStringKey
> = {
key: 'ribbonButtonTableOptions',
iconName: '',
unlocalizedText: 'Options',
isDisabled: formatState => !formatState.isInTable,
dropDownMenu: {
items: {
menuNameTableSetHeaderRow: 'Header Row',
menuNameTableSetFirstColumn: 'First Column',
menuNameTableSetBandedColumns: 'Banded Columns',
menuNameTableSetBandedRows: 'Banded Rows',
},
},
onClick: (editor, key) => {
if (key != 'ribbonButtonTableOptions') {
const format = getFormatState(editor);
const tableFormatProperty = TableEditOperationMap[key];
formatTable(
editor,
{ [tableFormatProperty]: !format.tableFormat[tableFormatProperty] },
true /*keepCellShade*/
);
}
},
commandBarProperties: {
iconOnly: false,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ApiPaneProps } from '../ApiPaneProps';
import { insertEntity } from 'roosterjs-content-model-api';
import { trustedHTMLHandler } from '../../../../utils/trustedHTMLHandler';
import {
ContentModelBlockGroup,
ContentModelEntity,
InsertEntityOptions,
ReadonlyContentModelBlockGroup,
} from 'roosterjs-content-model-types';

const styles = require('./InsertEntityPane.scss');
Expand Down Expand Up @@ -155,7 +155,7 @@ export default class InsertEntityPane extends React.Component<ApiPaneProps, Inse
};
}

function findAllEntities(group: ContentModelBlockGroup, result: ContentModelEntity[]) {
function findAllEntities(group: ReadonlyContentModelBlockGroup, result: ContentModelEntity[]) {
group.blocks.forEach(block => {
switch (block.blockType) {
case 'BlockGroup':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cloneModel } from 'roosterjs-content-model-dom';
import { ContentModelPane, ContentModelPaneProps } from './ContentModelPane';
import { createRibbonPlugin, RibbonButton, RibbonPlugin } from '../../roosterjsReact/ribbon';
import { getRefreshButton } from './buttons/refreshButton';
Expand Down Expand Up @@ -70,8 +71,9 @@ export class ContentModelPanePlugin extends SidePanePluginImpl<
this.getComponent(component => {
this.editor.formatContentModel(
model => {
component.setContentModel(model);
setCurrentContentModel(model);
const clonedModel = cloneModel(model);
component.setContentModel(clonedModel);
setCurrentContentModel(clonedModel);

return false;
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import * as React from 'react';
import { ContentModelWithDataset } from 'roosterjs-content-model-types';
import { FormatRenderer } from './utils/FormatRenderer';
import {
ContentModelWithDataset,
ShallowMutableContentModelWithDataset,
} from 'roosterjs-content-model-types';

const styles = require('./FormatView.scss');

export function MetadataView<T>(props: {
model: ContentModelWithDataset<T>;
renderers: FormatRenderer<T>[];
updater: (model: ContentModelWithDataset<T>, callback: (format: T | null) => T | null) => void;
updater: (
model: ShallowMutableContentModelWithDataset<T>,
callback: (format: T | null) => T | null
) => void;
}) {
const { model, renderers, updater } = props;
const metadata = React.useRef<T>(null);
Expand Down
6 changes: 3 additions & 3 deletions demo/scripts/controlsV2/tabs/ribbonButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { setBulletedListStyleButton } from '../demoButtons/setBulletedListStyleB
import { setHeadingLevelButton } from '../roosterjsReact/ribbon/buttons/setHeadingLevelButton';
import { setNumberedListStyleButton } from '../demoButtons/setNumberedListStyleButton';
import { setTableCellShadeButton } from '../demoButtons/setTableCellShadeButton';
import { setTableHeaderButton } from '../demoButtons/setTableHeaderButton';
import { spaceAfterButton, spaceBeforeButton } from '../demoButtons/spaceBeforeAfterButtons';
import { spacingButton } from '../demoButtons/spacingButton';
import { strikethroughButton } from '../roosterjsReact/ribbon/buttons/strikethroughButton';
Expand All @@ -47,6 +46,7 @@ import { tableBorderApplyButton } from '../demoButtons/tableBorderApplyButton';
import { tableBorderColorButton } from '../demoButtons/tableBorderColorButton';
import { tableBorderStyleButton } from '../demoButtons/tableBorderStyleButton';
import { tableBorderWidthButton } from '../demoButtons/tableBorderWidthButton';
import { tableOptionsButton } from '../demoButtons/tableOptionsButton';
import { tabNames } from './getTabs';
import { textColorButton } from '../roosterjsReact/ribbon/buttons/textColorButton';
import { underlineButton } from '../roosterjsReact/ribbon/buttons/underlineButton';
Expand Down Expand Up @@ -79,7 +79,7 @@ const tableButtons: RibbonButton<any>[] = [
insertTableButton,
formatTableButton,
setTableCellShadeButton,
setTableHeaderButton,
tableOptionsButton,
tableInsertButton,
tableDeleteButton,
tableBorderApplyButton,
Expand Down Expand Up @@ -169,7 +169,7 @@ const allButtons: RibbonButton<any>[] = [
listStartNumberButton,
formatTableButton,
setTableCellShadeButton,
setTableHeaderButton,
tableOptionsButton,
tableInsertButton,
tableDeleteButton,
tableMergeButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import {
createListLevel,
getOperationalBlocks,
isBlockGroupOfType,
mutateBlock,
parseValueWithUnit,
updateListMetadata,
} from 'roosterjs-content-model-dom';
import type {
ContentModelBlock,
ContentModelBlockFormat,
ContentModelBlockGroup,
ContentModelDocument,
ContentModelListItem,
ContentModelListLevel,
FormatContentModelContext,
ReadonlyContentModelBlock,
ReadonlyContentModelBlockGroup,
ReadonlyContentModelDocument,
ReadonlyContentModelListItem,
} from 'roosterjs-content-model-types';

const IndentStepInPixel = 40;
Expand All @@ -26,7 +28,7 @@ const IndentStepInPixel = 40;
* Set indentation for selected list items or paragraphs
*/
export function setModelIndentation(
model: ContentModelDocument,
model: ReadonlyContentModelDocument,
indentation: 'indent' | 'outdent',
length: number = IndentStepInPixel,
context?: FormatContentModelContext
Expand All @@ -37,7 +39,7 @@ export function setModelIndentation(
['TableCell']
);
const isIndent = indentation == 'indent';
const modifiedBlocks: ContentModelBlock[] = [];
const modifiedBlocks: ReadonlyContentModelBlock[] = [];

paragraphOrListItem.forEach(({ block, parent, path }) => {
if (isBlockGroupOfType<ContentModelListItem>(block, 'ListItem')) {
Expand Down Expand Up @@ -89,12 +91,12 @@ export function setModelIndentation(
}
}
} else if (block) {
let currentBlock: ContentModelBlock = block;
let currentParent: ContentModelBlockGroup = parent;
let currentBlock: ReadonlyContentModelBlock = block;
let currentParent: ReadonlyContentModelBlockGroup = parent;

while (currentParent && modifiedBlocks.indexOf(currentBlock) < 0) {
const index = path.indexOf(currentParent);
const { format } = currentBlock;
const { format } = mutateBlock(currentBlock);
const newValue = calculateMarginValue(format, isIndent, length);

if (newValue !== null) {
Expand Down Expand Up @@ -124,7 +126,7 @@ export function setModelIndentation(
return paragraphOrListItem.length > 0;
}

function isSelected(listItem: ContentModelListItem) {
function isSelected(listItem: ReadonlyContentModelListItem) {
return listItem.blocks.some(block => {
if (block.blockType == 'Paragraph') {
return block.segments.some(segment => segment.isSelected);
Expand All @@ -137,9 +139,9 @@ function isSelected(listItem: ContentModelListItem) {
* Otherwise, the margin of the first item will be changed, and the sub list will be created, creating a unintentional margin difference between the list items.
*/
function isMultilevelSelection(
model: ContentModelDocument,
listItem: ContentModelListItem,
parent: ContentModelBlockGroup
model: ReadonlyContentModelDocument,
listItem: ReadonlyContentModelListItem,
parent: ReadonlyContentModelBlockGroup
) {
const listIndex = parent.blocks.indexOf(listItem);
for (let i = listIndex - 1; i >= 0; i--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {
deleteSelection,
getClosestAncestorBlockGroupIndex,
setSelection,
mutateBlock,
} from 'roosterjs-content-model-dom';
import type {
ContentModelBlock,
ContentModelBlockGroup,
ContentModelDocument,
ContentModelEntity,
ContentModelParagraph,
FormatContentModelContext,
InsertEntityPosition,
InsertPoint,
ReadonlyContentModelBlock,
ShallowMutableContentModelBlock,
ShallowMutableContentModelBlockGroup,
ShallowMutableContentModelParagraph,
} from 'roosterjs-content-model-types';

/**
Expand All @@ -30,7 +32,7 @@ export function insertEntityModel(
context?: FormatContentModelContext,
insertPointOverride?: InsertPoint
) {
let blockParent: ContentModelBlockGroup | undefined;
let blockParent: ShallowMutableContentModelBlockGroup | undefined;
let blockIndex = -1;
let insertPoint: InsertPoint | null;

Expand All @@ -57,9 +59,10 @@ export function insertEntityModel(
position == 'root'
? getClosestAncestorBlockGroupIndex(path, ['TableCell', 'Document'])
: 0;
blockParent = path[pathIndex];
blockParent = mutateBlock(path[pathIndex]);

const child = path[pathIndex - 1];
const directChild: ContentModelBlock =
const directChild: ReadonlyContentModelBlock =
child?.blockGroupType == 'FormatContainer' ||
child?.blockGroupType == 'General' ||
child?.blockGroupType == 'ListItem'
Expand All @@ -71,16 +74,16 @@ export function insertEntityModel(
}

if (blockIndex >= 0 && blockParent) {
const blocksToInsert: ContentModelBlock[] = [];
let nextParagraph: ContentModelParagraph | undefined;
const blocksToInsert: ShallowMutableContentModelBlock[] = [];
let nextParagraph: ShallowMutableContentModelParagraph | undefined;

if (isBlock) {
const nextBlock = blockParent.blocks[blockIndex];

blocksToInsert.push(entityModel);

if (nextBlock?.blockType == 'Paragraph') {
nextParagraph = nextBlock;
nextParagraph = mutateBlock(nextBlock);
} else if (!nextBlock || nextBlock.blockType == 'Entity' || focusAfterEntity) {
nextParagraph = createParagraph(false /*isImplicit*/, {}, model.format);
nextParagraph.segments.push(createBr(model.format));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
import type { ContentModelBlockGroup, ContentModelListItem } from 'roosterjs-content-model-types';
import type {
ContentModelBlockGroup,
ContentModelListItem,
ReadonlyContentModelBlockGroup,
ReadonlyContentModelListItem,
} from 'roosterjs-content-model-types';

/**
* Search for all list items in the same thread as the current list item
* @param model The content model
* @param currentItem The current list item
* Search for all list items in the same thread as the current list item
*/
export function findListItemsInSameThread(
group: ContentModelBlockGroup,
currentItem: ContentModelListItem
): ContentModelListItem[] {
): ContentModelListItem[];

/**
* Search for all list items in the same thread as the current list item (Readonly)
* @param model The content model
* @param currentItem The current list item
*/
export function findListItemsInSameThread(
group: ReadonlyContentModelBlockGroup,
currentItem: ReadonlyContentModelListItem
): ReadonlyContentModelListItem[];

export function findListItemsInSameThread(
group: ReadonlyContentModelBlockGroup,
currentItem: ReadonlyContentModelListItem
): ReadonlyContentModelListItem[] {
const items: (ContentModelListItem | null)[] = [];

findListItems(group, items);

return filterListItems(items, currentItem);
}

function findListItems(group: ContentModelBlockGroup, result: (ContentModelListItem | null)[]) {
function findListItems(
group: ReadonlyContentModelBlockGroup,
result: (ReadonlyContentModelListItem | null)[]
) {
group.blocks.forEach(block => {
switch (block.blockType) {
case 'BlockGroup':
Expand Down Expand Up @@ -56,7 +79,7 @@ function findListItems(group: ContentModelBlockGroup, result: (ContentModelListI
});
}

function pushNullIfNecessary(result: (ContentModelListItem | null)[]) {
function pushNullIfNecessary(result: (ReadonlyContentModelListItem | null)[]) {
const last = result[result.length - 1];

if (!last || last !== null) {
Expand All @@ -65,10 +88,10 @@ function pushNullIfNecessary(result: (ContentModelListItem | null)[]) {
}

function filterListItems(
items: (ContentModelListItem | null)[],
currentItem: ContentModelListItem
items: (ReadonlyContentModelListItem | null)[],
currentItem: ReadonlyContentModelListItem
) {
const result: ContentModelListItem[] = [];
const result: ReadonlyContentModelListItem[] = [];
const currentIndex = items.indexOf(currentItem);
const levelLength = currentItem.levels.length;
const isOrderedList = currentItem.levels[levelLength - 1]?.listType == 'OL';
Expand Down Expand Up @@ -131,7 +154,7 @@ function filterListItems(
}

function areListTypesCompatible(
listItems: (ContentModelListItem | null)[],
listItems: (ReadonlyContentModelListItem | null)[],
currentIndex: number,
compareToIndex: number
): boolean {
Expand All @@ -146,7 +169,7 @@ function areListTypesCompatible(
);
}

function hasStartNumberOverride(item: ContentModelListItem, levelLength: number): boolean {
function hasStartNumberOverride(item: ReadonlyContentModelListItem, levelLength: number): boolean {
return item.levels
.slice(0, levelLength)
.some(level => level.format.startNumberOverride !== undefined);
Expand Down
Loading
Loading