Skip to content

Commit 124bc5c

Browse files
committed
Remove 'slate' imports from the main codebase
1 parent f4d160e commit 124bc5c

Some content is hidden

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

52 files changed

+147
-162
lines changed
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { Descendant, NodeEntry, Path } from 'slate';
2-
import { Node } from 'slate';
1+
import { type Descendant, type Node, NodeApi, type NodeEntry, type Path } from '@udecode/plate';
32

43
export function findDescendants<N extends Node>(
54
node: N,
65
match: (descendant: Descendant, path: Path) => boolean,
76
): NodeEntry[] {
8-
const descendants = Array.from(Node.descendants(node));
7+
const descendants = Array.from(NodeApi.descendants(node));
98
return descendants.filter(([element, path]) => match(element, path));
109
}

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

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

6-
export function isBlockActive(editor: Editor, type: ElementNode['type'], at?: Location): boolean {
5+
export function isBlockActive(
6+
editor: SlateEditor,
7+
type: ElementNode['type'],
8+
at?: Location,
9+
): boolean {
710
const [match] = Array.from(
8-
Editor.nodes(editor, {
11+
editor.api.nodes({
912
match: (node) => isElementNode(node, type),
1013
at,
1114
}),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Node, Path } from 'slate';
1+
import { type Node, type Path } from '@udecode/plate';
22

33
export function isTopLevelNode(_node: Node, path: Path): boolean {
44
return path.length === 1;

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { Node } from 'slate';
2-
import { Editor } from 'slate';
1+
import { type Editor, type Node } from '@udecode/plate';
32

43
import { isTopLevelNode } from './isTopLevelNode';
54

@@ -11,7 +10,7 @@ export function isTopLevelNodeSelected(
1110
const selection = editor.selection;
1211
if (!selection) return false;
1312

14-
const selectedNodes = Array.from(Editor.nodes(editor, { match: isTopLevelNode }));
13+
const selectedNodes = Array.from(editor.api.nodes({ match: isTopLevelNode }));
1514

1615
for (const [selectedNode] of selectedNodes) {
1716
if (selectedNode === node) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { NodeEntry, SlateEditor, Text } from '@udecode/plate';
1+
import { type Editor, type NodeEntry, type Text } from '@udecode/plate';
22

33
export function unsetMark<T extends Text>(
4-
editor: SlateEditor,
4+
editor: Editor,
55
entry: NodeEntry<T>,
66
mark: keyof Omit<T, 'text'>,
77
) {

packages/slate-commons/src/lib/createDeserializeElement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Node } from 'slate';
1+
import { type Node } from '@udecode/plate';
22

33
type Parse<E extends Node> = (serialized: string) => E | undefined;
44

packages/slate-commons/src/lib/withoutNodes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
import type { Node } from 'slate';
2-
import { Text } from 'slate';
1+
import { type Node, TextApi } from '@udecode/plate';
32

43
export function withoutNodes<T extends Node>(nodes: T[], match: (node: Node) => boolean): T[] {
54
return nodes
65
.map((node: T): T | null => {
76
if (match(node)) {
87
return null;
98
}
10-
if (Text.isText(node)) {
9+
if (TextApi.isText(node)) {
1110
return node;
1211
}
1312
return { ...node, children: withoutNodes(node.children, match) };

packages/slate-commons/src/selection/highest.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import type { Location, Range } from 'slate';
2-
import { Path, Point } from 'slate';
1+
import {
2+
type Location,
3+
type Path,
4+
PathApi,
5+
type Point,
6+
PointApi,
7+
type Range,
8+
} from '@udecode/plate';
39

410
export function highest(selection: Path): Path;
511
export function highest(selection: Point): Path;
612
export function highest(selection: Range): Path;
713
export function highest(selection: Location): Path {
8-
if (Path.isPath(selection)) {
14+
if (PathApi.isPath(selection)) {
915
return selection.slice(0, 1) as Path;
1016
}
11-
if (Point.isPoint(selection)) {
17+
if (PointApi.isPoint(selection)) {
1218
return highest(selection.path);
1319
}
1420
return highest(selection.focus);

packages/slate-commons/src/types/Extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Node } from 'slate';
1+
import { type Node } from '@udecode/plate';
22

33
import type { DecorateFactory } from './DecorateFactory';
44
import type { DeserializeHtml } from './DeserializeHtml';

packages/slate-editor/src/extensions/allowed-blocks/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Node, Path } from 'slate';
1+
import { type Node, type Path } from '@udecode/plate';
22

33
export interface AllowedBlocksExtensionConfiguration {
44
/**

packages/slate-editor/src/extensions/heading/HeadingExtension.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
isSubtitleHeadingNode,
99
isTitleHeadingNode,
1010
} from '@prezly/slate-types';
11+
import { type Node } from '@udecode/plate';
1112
import React from 'react';
12-
import type { Node } from 'slate';
1313

1414
import { onBackspaceResetFormattingAtDocumentStart, withResetFormattingOnBreak } from '#lib';
1515

packages/slate-editor/src/extensions/inline-links/lib/autolinkPlaintext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Node } from 'slate';
1+
import { type Node } from '@udecode/plate';
22
import validator from 'validator';
33

44
import { matchUrls } from '#lib';

packages/slate-editor/src/extensions/mentions/MentionsExtension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Extension } from '@prezly/slate-commons';
22
import { createDeserializeElement } from '@prezly/slate-commons';
3-
import type { Node } from 'slate';
4-
import { Element } from 'slate';
3+
import { ElementApi, type Node } from '@udecode/plate';
54

65
import { composeElementDeserializer } from '#modules/html-deserialization';
76

@@ -23,7 +22,7 @@ export function MentionsExtension<T extends string>({
2322
type,
2423
}: Options<T>): Extension {
2524
function isMention(node: Node) {
26-
return Element.isElementType(node, type);
25+
return ElementApi.isElementType(node, type);
2726
}
2827

2928
return {

packages/slate-editor/src/extensions/placeholders/lib/removePlaceholder.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { Editor } from 'slate';
2-
import { Transforms } from 'slate';
1+
import { type Editor } from '@udecode/plate';
32

43
import { PlaceholderNode } from '../PlaceholderNode';
54

65
export function removePlaceholder(editor: Editor, placeholder: PlaceholderNode): void {
7-
Transforms.removeNodes(editor, {
6+
editor.tf.removeNodes({
87
match: (node) =>
98
PlaceholderNode.isPlaceholderNode(node) &&
109
node.type === placeholder.type &&

packages/slate-editor/src/extensions/placeholders/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NewsroomRef, OEmbedInfo } from '@prezly/sdk';
2-
import type { Path } from 'slate';
2+
import { type Path } from '@udecode/plate';
33

44
import type { PlaceholderNode } from './PlaceholderNode';
55

packages/slate-editor/src/extensions/tables/TablesExtension.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import {
1515
isTableCellNode,
1616
} from '@prezly/slate-types';
1717
import { flow } from '@technically/lodash';
18+
import { type Element, type RenderElementProps } from '@udecode/plate';
1819
import React from 'react';
19-
import type { Element } from 'slate';
20-
import type { RenderElementProps } from 'slate-react';
2120

2221
import { composeElementDeserializer } from '#modules/html-deserialization';
2322

packages/slate-editor/src/extensions/tables/components/elements/TableCellElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { TablesEditor } from '@prezly/slate-tables';
22
import type { TableCellNode } from '@prezly/slate-types';
3+
import { type RenderElementProps } from '@udecode/plate';
34
import classNames from 'classnames';
45
import React from 'react';
5-
import type { RenderElementProps } from 'slate-react';
66

77
import styles from './elements.module.scss';
88
import { TableContext } from './TableContext';

packages/slate-editor/src/extensions/tables/components/elements/TableElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TableNode } from '@prezly/slate-types';
2+
import { type RenderElementProps } from '@udecode/plate';
23
import classNames from 'classnames';
34
import React from 'react';
4-
import type { RenderElementProps } from 'slate-react';
55

66
import { EditorBlock } from '#components';
77

packages/slate-editor/src/extensions/tables/components/elements/TableRowElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TableRowNode } from '@prezly/slate-types';
2+
import { type RenderElementProps } from '@udecode/plate';
23
import React from 'react';
3-
import type { RenderElementProps } from 'slate-react';
44

55
import styles from './elements.module.scss';
66

packages/slate-editor/src/extensions/tables/onKeyDown.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TablesEditor } from '@prezly/slate-tables';
2+
import { type Element, RangeApi } from '@udecode/plate';
23
import { isHotkey } from 'is-hotkey';
34
import type { KeyboardEvent } from 'react';
4-
import { type Element, Range } from 'slate';
55

66
const isClipboardCopy = isHotkey(['mod+c', 'ctrl+insert']);
77
const isClipboardCut = isHotkey(['mod+x', 'shift+delete']);
@@ -13,7 +13,7 @@ export function onClipboardHotkey(
1313
) {
1414
const selection = editor.selection;
1515

16-
if (!selection || Range.isExpanded(selection)) return;
16+
if (!selection || RangeApi.isExpanded(selection)) return;
1717

1818
if (isClipboardCopy(event)) {
1919
const entry = TablesEditor.findParentTable(editor, selection);
@@ -22,7 +22,7 @@ export function onClipboardHotkey(
2222
}
2323
const [, path] = entry;
2424

25-
editor.select(path); // Select the table
25+
editor.tf.select(path); // Select the table
2626

2727
document.execCommand('copy');
2828

@@ -36,16 +36,16 @@ export function onClipboardHotkey(
3636
}
3737
const [, path] = entry;
3838

39-
editor.withoutNormalizing(() => {
40-
editor.select(path); // Select the table
41-
const ref = editor.pathRef(path);
39+
editor.tf.withoutNormalizing(() => {
40+
editor.tf.select(path); // Select the table
41+
const ref = editor.api.pathRef(path);
4242

4343
if (document.execCommand('cut')) {
44-
editor.insertNodes(createDefaultElement(), { at: path });
44+
editor.tf.insertNodes(createDefaultElement(), { at: path });
4545
if (ref.current) {
46-
editor.removeNodes({ at: ref.current });
46+
editor.tf.removeNodes({ at: ref.current });
4747
}
48-
editor.select(path);
48+
editor.tf.select(path);
4949
}
5050

5151
ref.unref();

packages/slate-editor/src/extensions/user-mentions/components/UserMentionsDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { type Range } from '@udecode/plate';
12
import React from 'react';
2-
import type { Range } from 'slate';
33

44
import { Avatar } from '#components';
55

packages/slate-editor/src/extensions/variables/components/VariablesDropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { type Range } from '@udecode/plate';
12
import React from 'react';
2-
import type { Range } from 'slate';
33

44
import type { Option } from '#extensions/mentions';
55
import { MentionsDropdown } from '#extensions/mentions';

packages/slate-editor/src/lib/encodeSlateFragment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Node } from 'slate';
1+
import { type Node } from '@udecode/plate';
22

33
export function encodeSlateFragment(fragment: Node[]): string {
44
return window.btoa(encodeURIComponent(JSON.stringify(fragment)));

packages/slate-editor/src/modules/editor/getEnabledExtensions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EditorCommands, type Extension } from '@prezly/slate-commons';
22
import { TablesEditor } from '@prezly/slate-tables';
33
import type { Alignment } from '@prezly/slate-types';
44
import { CalloutNode, isImageNode, isQuoteNode } from '@prezly/slate-types';
5-
import { Node } from 'slate';
5+
import { NodeApi } from '@udecode/plate';
66

77
import { AllowedBlocksExtension } from '#extensions/allowed-blocks';
88
import { BlockquoteExtension } from '#extensions/blockquote';
@@ -312,7 +312,7 @@ export function* getEnabledExtensions(parameters: Parameters): Generator<Extensi
312312
},
313313
onCropped(editor, image) {
314314
EventsEditor.dispatchEvent(editor, 'image-edited', {
315-
description: Node.string(image),
315+
description: NodeApi.string(image),
316316
mimeType: image.file.mime_type,
317317
size: image.file.size,
318318
uuid: image.file.uuid,
@@ -328,7 +328,7 @@ export function* getEnabledExtensions(parameters: Parameters): Generator<Extensi
328328
},
329329
onReplaced(editor, image) {
330330
EventsEditor.dispatchEvent(editor, 'image-edited', {
331-
description: Node.string(image),
331+
description: NodeApi.string(image),
332332
mimeType: image.file.mime_type,
333333
size: image.file.size,
334334
uuid: image.file.uuid,

packages/slate-editor/src/modules/editor/plugins/withDeserializeHtml/createDeserialize/createDeserializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Extension } from '@prezly/slate-commons';
2-
import type { Descendant } from 'slate';
2+
import { type Descendant } from '@udecode/plate';
33

44
import { isGoogleDocsWrapper } from '#lib';
55

packages/slate-editor/src/modules/editor/plugins/withDeserializeHtml/createDeserialize/createElementsDeserializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { DeserializeElement } from '@prezly/slate-commons';
2-
import type { Descendant, Element } from 'slate';
2+
import { type Descendant, type Element } from '@udecode/plate';
33

44
import type { HTMLElement } from './dom';
55

packages/slate-editor/src/modules/editor/plugins/withDeserializeHtml/createDeserialize/createMarksDeserializer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DeserializeMarks } from '@prezly/slate-commons';
2-
import type { Descendant } from 'slate';
3-
import { Element, Text } from 'slate';
2+
import { type Descendant, ElementApi, TextApi } from '@udecode/plate';
43

54
export type MarksDeserializer = (node: HTMLElement, children: Descendant[]) => Descendant[];
65

@@ -20,12 +19,12 @@ export function createMarksDeserializer(deserialize: DeserializeMarks): MarksDes
2019
* Recursively apply the given style marks to all descendant Text nodes.
2120
*/
2221
function applyStylingProps<T extends Descendant>(node: T, styles: Record<string, any>): T {
23-
if (Text.isText(node)) {
22+
if (TextApi.isText(node)) {
2423
const { text, ...props } = node;
2524
return { ...props, ...styles, text } as T;
2625
}
2726

28-
if (Element.isElement(node)) {
27+
if (ElementApi.isElement(node)) {
2928
const { children, ...props } = node;
3029

3130
return {

packages/slate-editor/src/modules/editor/plugins/withDeserializeHtml/createDeserialize/createTextDeserializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Text } from 'slate';
1+
import { type Text } from '@udecode/plate';
22

33
import type { HTMLText } from './dom';
44

packages/slate-editor/src/modules/editor/plugins/withDeserializeHtml/deserializeHtml/deserializeHtml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Extension } from '@prezly/slate-commons';
2-
import type { Descendant } from 'slate';
2+
import { type Descendant } from '@udecode/plate';
33

44
import { createDeserializer } from '../createDeserialize';
55
import {
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import { Transforms } from 'slate';
2-
import type { NodeEntry } from 'slate';
3-
import type { Editor } from 'slate';
1+
import { type Editor, type NodeEntry } from '@udecode/plate';
42

53
export function insertTextNode(editor: Editor, [node, path]: NodeEntry) {
6-
Transforms.insertNodes(editor, [{ text: '' }], { at: path, match: (n) => n === node });
4+
editor.tf.insertNodes([{ text: '' }], { at: path, match: (n) => n === node });
75
return true;
86
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import { Editor, Element, Path, Transforms } from 'slate';
2-
import type { NodeEntry } from 'slate';
1+
import { type Editor, ElementApi, type NodeEntry, PathApi } from '@udecode/plate';
32

43
export function removeNode(editor: Editor, [, path]: NodeEntry) {
5-
const targetPath = Path.parent(path);
6-
const ancestor = Editor.above(editor, { at: targetPath });
4+
const targetPath = PathApi.parent(path);
5+
const ancestor = editor.api.above({ at: targetPath });
76

87
if (!ancestor) {
98
return false;
109
}
1110

1211
const [ancestorNode] = ancestor;
1312

14-
if (!Element.isElement(ancestorNode)) {
13+
if (!ElementApi.isElement(ancestorNode)) {
1514
return false;
1615
}
1716

18-
Transforms.removeNodes(editor, { at: targetPath, voids: true });
17+
editor.tf.removeNodes({ at: targetPath, voids: true });
1918

2019
return true;
2120
}

0 commit comments

Comments
 (0)