-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimise content model table fetching for Table Edit Plugins (#2656)
* optimise cmTable fetching * create getCMTableFromTable
- Loading branch information
1 parent
2b74dcb
commit 40dec70
Showing
4 changed files
with
40 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...s/roosterjs-content-model-plugins/lib/tableEdit/editors/utils/getTableFromContentModel.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getFirstSelectedTable } from 'roosterjs-content-model-dom'; | ||
import type { ContentModelTable, IEditor } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
* Get ContentModelTable from a table element if it is present in the content model | ||
*/ | ||
export function getCMTableFromTable(editor: IEditor, table: HTMLTableElement) { | ||
let cmTable: ContentModelTable | undefined; | ||
|
||
editor.formatContentModel( | ||
model => { | ||
[cmTable] = getFirstSelectedTable(model); | ||
return false; | ||
}, | ||
{ | ||
selectionOverride: { | ||
type: 'table', | ||
firstColumn: 0, | ||
firstRow: 0, | ||
lastColumn: 0, | ||
lastRow: 0, | ||
table: table, | ||
}, | ||
} | ||
); | ||
|
||
return cmTable; | ||
} |