Skip to content

Commit

Permalink
Added destroy function so vanilla custom blocks can clean ip betwee…
Browse files Browse the repository at this point in the history
…n renders
  • Loading branch information
matthewlipski committed Aug 31, 2023
1 parent 8cbbc50 commit 99f7738
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/extensions/Blocks/api/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Attribute, Node } from "@tiptap/core";
import { Attribute, Attributes, Node } from "@tiptap/core";
import { BlockNoteDOMAttributes, BlockNoteEditor } from "../../..";
import styles from "../nodes/Block.module.css";
import {
Expand All @@ -10,6 +10,7 @@ import {
TipTapNodeConfig,
} from "./blockTypes";
import { mergeCSSClasses } from "../../../shared/utils";
import { ParseRule } from "prosemirror-model";

export function camelToDataKebab(str: string): string {
return "data-" + str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
Expand All @@ -27,7 +28,7 @@ export function propsToAttributes<
BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>,
"render"
>
) {
): Attributes {
const tiptapAttributes: Record<string, Attribute> = {};

Object.entries(blockConfig.propSchema).forEach(([name, spec]) => {
Expand Down Expand Up @@ -63,7 +64,7 @@ export function parse<
BlockConfig<BType, PSchema, ContainsInlineContent, BSchema>,
"render"
>
) {
): ParseRule[] {
return [
{
tag: "div[data-content-type=" + blockConfig.type + "]",
Expand Down Expand Up @@ -228,9 +229,11 @@ export function createBlockSpec<
? {
dom: blockContent,
contentDOM: rendered.contentDOM,
destroy: rendered.destroy,
}
: {
dom: blockContent,
destroy: rendered.destroy,
};
};
},
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/extensions/Blocks/api/blockTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ export type BlockConfig<
? {
dom: HTMLElement;
contentDOM: HTMLElement;
destroy?: () => void;
}
: {
dom: HTMLElement;
destroy?: () => void;
};
};

Expand Down

0 comments on commit 99f7738

Please sign in to comment.