Skip to content

Commit

Permalink
Merge pull request #2682 from kristian-puccio/fix/table-new-cell-chil…
Browse files Browse the repository at this point in the history
…dren

fetch newCellChildren or allow it to be passed into insertTable
  • Loading branch information
zbeyens authored Oct 6, 2023
2 parents 0a37e1b + 7128b7f commit 3acc2f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-students-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-table': patch
---

newCellChildren is now passed as an option to insertTable or the plugin option is used
19 changes: 16 additions & 3 deletions packages/table/src/transforms/insertTable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
getBlockAbove,
getPluginOptions,
getPluginType,
getStartPoint,
insertNodes,
Expand All @@ -12,7 +13,7 @@ import {
} from '@udecode/plate-common';

import { ELEMENT_TABLE } from '../createTablePlugin';
import { TTableElement } from '../types';
import { TablePlugin, TTableElement } from '../types';
import {
getEmptyTableNode,
GetEmptyTableNodeOptions,
Expand All @@ -24,9 +25,16 @@ import {
*/
export const insertTable = <V extends Value>(
editor: PlateEditor<V>,
{ rowCount = 2, colCount = 2, header }: GetEmptyTableNodeOptions = {},
{
rowCount = 2,
colCount = 2,
header,
newCellChildren,
}: GetEmptyTableNodeOptions = {},
options: InsertNodesOptions<V> = {}
) => {
const pluginOptions = getPluginOptions<TablePlugin, V>(editor, ELEMENT_TABLE);

withoutNormalizing(editor, () => {
if (
!someNode(editor, {
Expand All @@ -35,7 +43,12 @@ export const insertTable = <V extends Value>(
) {
insertNodes<TTableElement>(
editor,
getEmptyTableNode(editor, { header, rowCount, colCount }),
getEmptyTableNode(editor, {
header,
rowCount,
colCount,
newCellChildren: newCellChildren || pluginOptions?.newCellChildren,
}),
{
nextBlock: true,
...(options as any),
Expand Down

0 comments on commit 3acc2f0

Please sign in to comment.