Skip to content

Commit d04aae7

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/feature/dev-19130-upgrade-plate-to-v42' into refactor/dev-19141-find-a-way-to-make-hoc-func-plugins-introducing-new-editor
# Conflicts: # packages/slate-editor/src/index.ts # packages/slate-editor/src/modules/editor/createEditor.ts # packages/slate-editor/src/modules/editor/index.ts # packages/slate-editor/src/modules/editor/plugins/ElementsEqualityCheckPlugin.ts # packages/slate-editor/src/modules/editor/plugins/withDefaultTextBlock.ts # packages/slate-editor/src/modules/editor/plugins/withRichBlocks.ts # packages/slate-editor/src/modules/editor/useCreateEditor.ts # packages/slate-types/src/nodes/ElementNode.ts # packages/slate-types/src/nodes/TableNode.ts # packages/slate-types/src/nodes/TextNode.ts
2 parents 94a3fd8 + f4d160e commit d04aae7

File tree

298 files changed

+896
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

298 files changed

+896
-1040
lines changed

packages/slate-commons/src/commands/isAtEmptyBlock.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export function isAtEmptyBlock(
2929

3030
const [node] = entry;
3131
return (
32-
ElementApi.isElement(node) && editor.api.isBlock(node) && isNodeEmpty(editor, node, options?.trim)
32+
ElementApi.isElement(node) &&
33+
editor.api.isBlock(node) &&
34+
isNodeEmpty(editor, node, options?.trim)
3335
);
3436
}

packages/slate-commons/src/commands/removeNode.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { Node, SlateEditor } from '@udecode/plate';
1+
import type { Editor, EditorNodesOptions, ElementOrTextOf, SlateEditor } from '@udecode/plate';
22

3-
export function removeNode(
3+
export function removeNode<T extends ElementOrTextOf<Editor>>(
44
editor: SlateEditor,
5-
options: NonNullable<Parameters<typeof editor.api.nodes>[0]>,
6-
): Node | null {
5+
options: NonNullable<EditorNodesOptions>,
6+
): T | null {
77
const [nodeEntry] = editor.api.nodes(options);
88
if (nodeEntry) {
99
const [node, nodePath] = nodeEntry;

packages/slate-commons/src/commands/replaceChildren.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { type Editor, ElementApi, type ElementOrTextOf, type NodeEntry, type SlateEditor } from '@udecode/plate';
1+
import {
2+
type Editor,
3+
ElementApi,
4+
type ElementOrTextOf,
5+
type NodeEntry,
6+
type SlateEditor,
7+
} from '@udecode/plate';
28

39
/**
410
* Replaces the given element children with a new list of nodes.
@@ -15,7 +21,8 @@ export function replaceChildren(
1521
return false;
1622
}
1723

18-
const newChildren: ElementOrTextOf<Editor>[] = children.length === 0 ? [{ text: '' }] : children;
24+
const newChildren: ElementOrTextOf<Editor>[] =
25+
children.length === 0 ? [{ text: '' }] : children;
1926

2027
editor.tf.withoutNormalizing(() => {
2128
node.children.forEach(() => {

packages/slate-commons/src/commands/replaceNode.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ interface Options {
99
select?: boolean;
1010
}
1111

12-
export function replaceNode(
13-
editor: SlateEditor,
14-
newNode: Node,
15-
options: Options,
16-
) {
12+
export function replaceNode(editor: SlateEditor, newNode: Node, options: Options) {
1713
const { at, match, select = false } = options;
1814
editor.tf.withoutNormalizing(() => {
1915
const [entry] = editor.api.nodes({ at, match, mode: 'highest' });

packages/slate-editor/src/components/EditorBlock/EditorBlock.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { EditorCommands } from '@prezly/slate-commons';
22
import type { ElementNode } from '@prezly/slate-types';
33
import { Alignment } from '@prezly/slate-types';
4-
import { findNodePath, focusEditor, useEditorRef } from '@udecode/plate-common/react';
4+
import { type RenderElementProps } from '@udecode/plate';
5+
import { useEditorRef, useSelected } from '@udecode/plate/react';
56
import classNames from 'classnames';
67
import type { MouseEvent, ReactNode } from 'react';
78
import React, { forwardRef, useCallback, useEffect, useState } from 'react';
8-
import type { RenderElementProps } from 'slate-react';
9-
import { useSelected } from 'slate-react';
109

1110
import { NewParagraphDelimiter } from '#components';
1211
import { useFunction } from '#lib';
@@ -102,7 +101,7 @@ export const EditorBlock = forwardRef<HTMLDivElement, Props>(function (
102101
const isNodeSelected = useSelected();
103102
const isOnlyBlockSelected =
104103
isNodeSelected &&
105-
Array.from(editor.nodes({ match: EditorCommands.isTopLevelNode })).length === 1;
104+
Array.from(editor.api.nodes({ match: EditorCommands.isTopLevelNode })).length === 1;
106105
const isSelected = selected ?? isNodeSelected;
107106
const isOverlayEnabled = overlay === 'always' || (overlay === 'autohide' && !isSelected);
108107
const popperOptions = usePopperOptionsContext();
@@ -113,7 +112,7 @@ export const EditorBlock = forwardRef<HTMLDivElement, Props>(function (
113112

114113
const closeMenu = useCallback(() => {
115114
setMenuOpen(false);
116-
focusEditor(editor);
115+
editor.tf.focus();
117116
}, [editor]);
118117

119118
const handleFrameClick = useFunction(function (event: MouseEvent) {
@@ -122,9 +121,9 @@ export const EditorBlock = forwardRef<HTMLDivElement, Props>(function (
122121
event.stopPropagation();
123122

124123
if (!isSelected) {
125-
const path = findNodePath(editor, element);
124+
const path = editor.api.findPath(element);
126125
if (path) {
127-
editor.select(path);
126+
editor.tf.select(path);
128127
}
129128
}
130129
});

packages/slate-editor/src/components/NewParagraphDelimiter/NewParagraphDelimiter.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ElementNode } from '@prezly/slate-types';
2-
import { findNodePath, useEditorRef } from '@udecode/plate-common/react';
2+
import { PathApi } from '@udecode/plate';
3+
import { useEditorRef } from '@udecode/plate/react';
34
import classNames from 'classnames';
45
import type { MouseEvent } from 'react';
56
import React from 'react';
6-
import { Path } from 'slate';
77

88
import { useFunction } from '#lib';
99

@@ -26,13 +26,14 @@ export function NewParagraphDelimiter(props: Props) {
2626
const handleClick = useFunction((event: MouseEvent) => {
2727
preventBubbling(event);
2828

29-
const path = findNodePath(editor, element);
29+
const path = editor.api.findPath(element);
3030
if (!path) {
3131
return;
3232
}
3333

34-
editor.insertNodes(editor.createDefaultTextBlock(), {
35-
at: position === 'top' ? path : Path.next(path),
34+
// @ts-expect-error TODO: Fix types
35+
editor.tf.insertNodes(editor.createDefaultTextBlock(), {
36+
at: position === 'top' ? path : PathApi.next(path),
3637
select: true,
3738
});
3839

packages/slate-editor/src/components/Portals/TextSelectionPortalV2.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { identity } from '@technically/lodash';
2-
import type { SlateEditor } from '@udecode/plate-common';
3-
import { toDOMRange, useEditorRef } from '@udecode/plate-common/react';
2+
import type { SlateEditor } from '@udecode/plate';
3+
import { toDOMRange, useEditorRef } from '@udecode/plate/react';
44
import classNames from 'classnames';
55
import RangeFix from 'rangefix';
66
import React, { useCallback, useRef, useState } from 'react';

packages/slate-editor/src/extensions/blockquote/components/BlockQuoteElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EditorCommands } from '@prezly/slate-commons';
22
import type { QuoteNode } from '@prezly/slate-types';
33
import { Alignment } from '@prezly/slate-types';
4-
import { useEditorRef } from '@udecode/plate-common/react';
4+
import { useEditorRef } from '@udecode/plate/react';
55
import classNames from 'classnames';
66
import type { HTMLAttributes, Ref } from 'react';
77
import React, { forwardRef } from 'react';

packages/slate-editor/src/extensions/blockquote/lib/normalizeRedundantAttributes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { EditorCommands } from '@prezly/slate-commons';
22
import type { QuoteNode } from '@prezly/slate-types';
33
import { isQuoteNode } from '@prezly/slate-types';
4-
import type { SlateEditor } from '@udecode/plate-common';
5-
import type { NodeEntry } from 'slate';
4+
import type { NodeEntry, SlateEditor } from '@udecode/plate';
65

76
const shape: Record<keyof QuoteNode, true> = {
87
type: true,

packages/slate-editor/src/extensions/button-block/ButtonBlockNode.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { ElementNode } from '@prezly/slate-types';
22
import { isElementNode } from '@prezly/slate-types';
3-
import type { TNode } from '@udecode/plate-common';
4-
import type { Node } from 'slate';
3+
import type { Node } from '@udecode/plate';
54

65
type Uuid = string;
76

@@ -30,7 +29,7 @@ export namespace ButtonBlockNode {
3029
OUTLINE = 'outline',
3130
}
3231

33-
export function isButtonBlockNode(node: Node | TNode): node is ButtonBlockNode {
32+
export function isButtonBlockNode(node: Node): node is ButtonBlockNode {
3433
return isElementNode(node, Type);
3534
}
3635
}

0 commit comments

Comments
 (0)