Skip to content

Commit f934d26

Browse files
committed
fix: remove tiptapblockimplementation
1 parent 760be84 commit f934d26

File tree

4 files changed

+18
-60
lines changed

4 files changed

+18
-60
lines changed

packages/core/src/editor/CustomSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
2323

2424
export type BlockSpecOf<BSpecs extends BlockSchema> = {
2525
[key in keyof BSpecs]: key extends string
26-
? BlockDefinition<key, PropSchema>
26+
? BlockDefinition<key, PropSchema, "inline" | "none" | "table">
2727
: never;
2828
};
2929

packages/core/src/schema/blocks/createSpec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export function createBlockSpec<
294294

295295
return createInternalBlockSpec(blockConfig, {
296296
node,
297-
toInternalHTML: (block, editor) => {
297+
render: (block, editor) => {
298298
const blockContentDOMAttributes =
299299
node.options.domAttributes?.blockContent || {};
300300

packages/core/src/schema/blocks/internal.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import { PropSchema, Props } from "../propTypes.js";
1616
import { StyleSchema } from "../styles/types.js";
1717
import {
1818
BlockConfig,
19+
BlockDefinition,
20+
BlockImplementation,
1921
BlockSchemaWithBlock,
20-
BlockSpec,
2122
SpecificBlock,
22-
TiptapBlockImplementation,
2323
} from "./types.js";
2424

2525
// Function that uses the 'propSchema' of a blockConfig to create a TipTap
@@ -232,17 +232,15 @@ export function createStronglyTypedTiptapNode<
232232
// config and implementation that conform to the type of Config
233233
export function createInternalBlockSpec<T extends BlockConfig>(
234234
config: T,
235-
implementation: TiptapBlockImplementation<
236-
T,
237-
any,
238-
InlineContentSchema,
239-
StyleSchema
240-
>,
241-
) {
235+
implementation: BlockImplementation<T["type"], PropSchema> & {
236+
node: Node;
237+
requiredExtensions?: Array<Extension | Node>;
238+
},
239+
): BlockDefinition<T["type"], PropSchema> {
242240
return {
243241
config,
244242
implementation,
245-
} satisfies BlockSpec<T, any, InlineContentSchema, StyleSchema>;
243+
};
246244
}
247245

248246
export function createBlockSpecFromStronglyTypedTiptapNode<
@@ -262,9 +260,8 @@ export function createBlockSpecFromStronglyTypedTiptapNode<
262260
{
263261
node,
264262
requiredExtensions,
265-
toInternalHTML: defaultBlockToHTML,
263+
render: defaultBlockToHTML,
266264
toExternalHTML: defaultBlockToHTML,
267-
// parse: () => undefined, // parse rules are in node already
268265
},
269266
);
270267
}

packages/core/src/schema/blocks/types.ts

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/** Define the main block types **/
2-
import type { Extension, Node } from "@tiptap/core";
32

3+
import type { Fragment, Schema } from "prosemirror-model";
4+
import type { ViewMutationRecord } from "prosemirror-view";
45
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
6+
import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
57
import type {
68
InlineContent,
79
InlineContentSchema,
810
PartialInlineContent,
911
} from "../inlineContent/types.js";
1012
import type { PropSchema, Props } from "../propTypes.js";
1113
import type { StyleSchema } from "../styles/types.js";
12-
import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
13-
import type { Fragment, Schema } from "prosemirror-model";
14-
import type { ViewMutationRecord } from "prosemirror-view";
1514

1615
export type BlockNoteDOMElement =
1716
| "editor"
@@ -76,45 +75,10 @@ export interface BlockConfig<
7675
meta?: BlockConfigMeta;
7776
}
7877

79-
// Block implementation contains the "implementation" info about a Block
80-
// such as the functions / Nodes required to render and / or serialize it
81-
export type TiptapBlockImplementation<
82-
T extends BlockConfig,
83-
B extends BlockSchema,
84-
I extends InlineContentSchema,
85-
S extends StyleSchema,
86-
> = {
87-
requiredExtensions?: Array<Extension | Node>;
88-
node: Node;
89-
toInternalHTML: (
90-
block: BlockFromConfigNoChildren<T, I, S> & {
91-
children: BlockNoDefaults<B, I, S>[];
92-
},
93-
editor: BlockNoteEditor<B, I, S>,
94-
) => {
95-
dom: HTMLElement;
96-
contentDOM?: HTMLElement;
97-
};
98-
toExternalHTML: (
99-
block: BlockFromConfigNoChildren<T, I, S> & {
100-
children: BlockNoDefaults<B, I, S>[];
101-
},
102-
editor: BlockNoteEditor<B, I, S>,
103-
) => {
104-
dom: HTMLElement;
105-
contentDOM?: HTMLElement;
106-
};
107-
};
108-
10978
// A Spec contains both the Config and Implementation
110-
export type BlockSpec<
111-
T extends BlockConfig,
112-
B extends BlockSchema,
113-
I extends InlineContentSchema,
114-
S extends StyleSchema,
115-
> = {
79+
export type BlockSpec<T extends BlockConfig> = {
11680
config: T;
117-
implementation: TiptapBlockImplementation<NoInfer<T>, B, I, S>;
81+
implementation: BlockImplementation<NoInfer<T["type"]>, PropSchema>;
11882
};
11983

12084
// Utility type. For a given object block schema, ensures that the key of each
@@ -133,14 +97,11 @@ type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
13397
// The keys are the "type" of a block
13498
export type BlockSchema = NamesMatch<Record<string, BlockConfig>>;
13599

136-
export type BlockSpecs = Record<
137-
string,
138-
BlockSpec<any, any, InlineContentSchema, StyleSchema>
139-
>;
100+
export type BlockSpecs = Record<string, BlockSpec<any>>;
140101

141102
export type BlockImplementations = Record<
142103
string,
143-
TiptapBlockImplementation<any, any, any, any>
104+
BlockImplementation<any, any>
144105
>;
145106

146107
export type BlockSchemaFromSpecs<T extends BlockSpecs> = {

0 commit comments

Comments
 (0)