Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Dec 25, 2024
1 parent 51b2d4a commit 392d0f7
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/plate-utils/src/react/selectSiblingNodePoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Path } from 'slate';

import { type TEditor, type TNode, setSelection } from '@udecode/slate';
import { findPath, focusEditor } from '@udecode/slate-react';
import { focusEditor } from '@udecode/slate-react';
import {
getNextNodeStartPoint,
getPreviousNodeEndPoint,
Expand All @@ -22,7 +22,7 @@ export const selectSiblingNodePoint = (
} = {}
) => {
if (node) {
at = findPath(editor, node);
at = editor.findPath(node);
}
if (!at) return;

Expand Down
3 changes: 1 addition & 2 deletions packages/plate-utils/src/react/useRemoveNodeButton.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useEditorRef } from '@udecode/plate-core/react';
import { type TElement, removeNodes } from '@udecode/slate';
import { findPath } from '@udecode/slate-react';

export const useRemoveNodeButton = ({ element }: { element: TElement }) => {
const editor = useEditorRef();

return {
props: {
onClick: () => {
const path = findPath(editor, element);
const path = editor.findPath(element);

removeNodes(editor, { at: path });
},
Expand Down
1 change: 0 additions & 1 deletion packages/resizable/src/components/Resizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const useResizableState = ({

const setNodeWidth = React.useCallback(
(w: number) => {
if (!path) return;
if (w === nodeWidth) {
// Focus the node if not resized
select(editor, path);
Expand Down
2 changes: 1 addition & 1 deletion packages/selection/src/react/hooks/useBlockSelectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useBlockSelectable = () => {
props: {
className: 'slate-selectable',
onContextMenu: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if (!element || !path) return;
if (!element) return;

const { enableContextMenu } = getOptions();

Expand Down
4 changes: 1 addition & 3 deletions packages/slate-react/src/utils/setNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import type {
TNodeProps,
} from '@udecode/slate';

import { findPath } from '../react-editor';

export const setNode = <N extends NodeOf<E>, E extends TEditor = TEditor>(
editor: E,
node: N,
props: Partial<TNodeProps<N>>,
options?: Omit<SetNodesOptions<E>, 'at'>
) => {
const path = findPath(editor, node);
const path = editor.findPath(node);

if (!path) return;

Expand Down
6 changes: 6 additions & 0 deletions packages/slate/src/interfaces/editor/TEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Modify, UnknownObject } from '@udecode/utils';
import type { Editor, Path, Range } from 'slate';
import type { HistoryEditor } from 'slate-history';

import type { FindNodeOptions } from '../../queries';
import type { TOperation } from '../../types/TOperation';
import type { TElement } from '../element/TElement';
import type { TDescendant } from '../node/TDescendant';
Expand Down Expand Up @@ -30,6 +31,11 @@ export type TEditor<V extends Value = Value> = {
data: DataTransfer,
originEvent?: 'copy' | 'cut' | 'drag'
) => void;
/**
* Find the path of a node. Overridden by `withPlate` to use React.findPath
* (memo). Default is `findNodePath` (traversal).
*/
findPath: (node: TNode, options?: FindNodeOptions) => Path | undefined;
hasRange: (editor: TEditor<V>, range: Range) => boolean;
hasTarget: (editor: TEditor<V>, target: EventTarget | null) => target is Node;
insertData: (data: DataTransfer) => void;
Expand Down
4 changes: 1 addition & 3 deletions packages/slate/src/transforms/setNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import type {
TNodeProps,
} from '../interfaces';

import { findNodePath } from '../queries';

export const setNode = <N extends NodeOf<E>, E extends TEditor = TEditor>(
editor: E,
node: N,
props: Partial<TNodeProps<N>>,
options?: Omit<SetNodesOptions<E>, 'at'>
) => {
const path = findNodePath(editor, node);
const path = editor.findPath(node);

if (!path) return;

Expand Down
2 changes: 1 addition & 1 deletion packages/suggestion/src/lib/withSuggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export const withSuggestion: ExtendEditor<SuggestionConfig> = ({
// return;
// }
//
// const path = findNodePath(editor, node);
// const path = editor.findPath(node);
// if (!path) return;
//
// const id = findSuggestionId(editor, path) ?? nanoid();
Expand Down
3 changes: 1 addition & 2 deletions packages/tabbable/src/react/TabbableEffects.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';

import {
findPath,
focusEditor,
toDOMNode,
toSlateNode,
Expand Down Expand Up @@ -75,7 +74,7 @@ export function TabbableEffects() {

return {
domNode,
path: findPath(editor, slateNode),
path: editor.findPath(slateNode),
slateNode,
} as TabbableEntry;
})
Expand Down

0 comments on commit 392d0f7

Please sign in to comment.