Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Sep 30, 2023
1 parent 5ed1205 commit 18f9778
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/cyan-plums-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/slate-utils': minor
---

Add replaceNode
2 changes: 1 addition & 1 deletion packages/slate-utils/src/transforms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export * from './insertElements';
export * from './insertEmptyElement';
export * from './moveChildren';
export * from './removeMark';
export * from './removeNodeChildren';
export * from './removeSelectionMark';
export * from './replaceNode';
export * from './replaceNodeChildren';
export * from './selectEndOfBlockAboveSelection';
export * from './setMarks';
Expand Down
27 changes: 27 additions & 0 deletions packages/slate-utils/src/transforms/replaceNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
EElementOrText,
insertNodes,
removeNodes,
TEditor,
Value,
withoutNormalizing,
} from '@udecode/slate';

import { ReplaceNodeChildrenOptions } from './replaceNodeChildren';

export const replaceNode = <
N extends EElementOrText<V>,
V extends Value = Value,
>(
editor: TEditor<V>,
{ at, nodes, insertOptions, removeOptions }: ReplaceNodeChildrenOptions<N, V>
) => {
withoutNormalizing(editor, () => {
removeNodes(editor, { ...insertOptions, at });

insertNodes(editor, nodes, {
...insertOptions,
at,
});
});
};

0 comments on commit 18f9778

Please sign in to comment.