Skip to content

Commit

Permalink
refactor: make NodeViewProps an interface again (#5658)
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 authored Sep 25, 2024
1 parent 1bad8f8 commit 15b5499
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@ export interface EditorOptions {
*
* @default true
*/
enableCoreExtensions?: boolean | Partial<Record<'editable' | 'clipboardTextSerializer' | 'commands' | 'focusEvents' | 'keymap' | 'tabindex', false>>;
enableCoreExtensions?:
| boolean
| Partial<
Record<
| 'editable'
| 'clipboardTextSerializer'
| 'commands'
| 'focusEvents'
| 'keymap'
| 'tabindex',
false
>
>;
/**
* If `true`, the editor will check the content for errors on initialization.
* Emitting the `contentError` event if the content is invalid.
Expand All @@ -122,8 +134,8 @@ export interface EditorOptions {
onFocus: (props: EditorEvents['focus']) => void;
onBlur: (props: EditorEvents['blur']) => void;
onDestroy: (props: EditorEvents['destroy']) => void;
onPaste: (e: ClipboardEvent, slice: Slice) => void
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void
onPaste: (e: ClipboardEvent, slice: Slice) => void;
onDrop: (e: DragEvent, slice: Slice, moved: boolean) => void;
}

export type HTMLContent = string;
Expand Down Expand Up @@ -208,21 +220,17 @@ export type ValuesOf<T> = T[keyof T];

export type KeysWithTypeOf<T, Type> = { [P in keyof T]: T[P] extends Type ? P : never }[keyof T];

export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};

export type DecorationWithType = Decoration & {
type: NodeType;
};

export type NodeViewProps = Simplify<
Omit<NodeViewRendererProps, 'decorations'> & {
// TODO this type is not technically correct, but it's the best we can do for now since prosemirror doesn't expose the type of decorations
decorations: readonly DecorationWithType[];
selected: boolean;
updateAttributes: (attributes: Record<string, any>) => void;
deleteNode: () => void;
}
>;
export interface NodeViewProps extends NodeViewRendererProps {
// TODO this type is not technically correct, but it's the best we can do for now since prosemirror doesn't expose the type of decorations
decorations: readonly DecorationWithType[];
selected: boolean;
updateAttributes: (attributes: Record<string, any>) => void;
deleteNode: () => void;
}

export interface NodeViewRendererOptions {
stopEvent: ((props: { event: Event }) => boolean) | null;
Expand All @@ -232,7 +240,7 @@ export interface NodeViewRendererOptions {
contentDOMElementTag: string;
}

export type NodeViewRendererProps = {
export interface NodeViewRendererProps {
// pass-through from prosemirror
node: Parameters<NodeViewConstructor>[0];
view: Parameters<NodeViewConstructor>[1];
Expand All @@ -243,7 +251,7 @@ export type NodeViewRendererProps = {
editor: Editor;
extension: Node;
HTMLAttributes: Record<string, any>;
};
}

export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView;

Expand Down

0 comments on commit 15b5499

Please sign in to comment.