Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/content/docs/features/extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BlockNote includes an extensions system which lets you expand the editor's behav

## Creating an extension

An extension is an instance of the [`BlockNoteExtension`](https://github.com/TypeCellOS/BlockNote/blob/10cdbfb5f77ef82f3617c0fa1191e0bf5b7358c5/packages/core/src/editor/BlockNoteExtension.ts#L13) class. However, it's recommended for most use cases to create extensions using the `createBlockNoteExtension` function, rather than instanciating the class directly:
An extension is an instance of the [`BlockNoteExtension`](https://github.com/TypeCellOS/BlockNote/blob/10cdbfb5f77ef82f3617c0fa1191e0bf5b7358c5/packages/core/src/editor/BlockNoteExtension.ts#L13) class. However, it's recommended for most use cases to create extensions using the `createExtension` function, rather than instanciating the class directly:

```typescript
type BlockNoteExtensionOptions = {
Expand Down Expand Up @@ -43,10 +43,10 @@ const customBlockExtensionOptions: BlockNoteExtensionOptions = {
tiptapExtensions: ...,
}

const CustomExtension = createBlockNoteExtension(customBlockExtensionOptions);
const CustomExtension = createExtension(customBlockExtensionOptions);
```

Let's go over the options that can be passed into `createBlockNoteExtension`:
Let's go over the options that can be passed into `createExtension`:

`key:` The name of the extension.

Expand Down Expand Up @@ -74,7 +74,7 @@ The `extensions` [editor option](/docs/reference/editor/overview#options) takes
const editor = useCreateBlockNote({
extensions: [
// Add extensions here:
createBlockNoteExtension({ ... })
createExtension({ ... })
],
});
```
Expand All @@ -95,7 +95,7 @@ const createCustomBlock = createReactBlockSpec(
}
[
// Add extensions here:
createBlockNoteExtension({ ... })
createExtension({ ... })
],
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const FileReplaceButton = () => {
variant={"panel-popover"}
>
{/* Replaces default file panel with our Uppy one. */}
<UppyFilePanel block={block as any} />
<UppyFilePanel blockId={block.id} />
</Components.Generic.Popover.Content>
</Components.Generic.Popover.Root>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const uppy = new Uppy()
});

export function UppyFilePanel(props: FilePanelProps) {
const { block } = props;
const { blockId } = props;
const editor = useBlockNoteEditor();

useEffect(() => {
Expand All @@ -68,7 +68,7 @@ export function UppyFilePanel(props: FilePanelProps) {
url: response.uploadURL,
},
};
editor.updateBlock(block, updateData);
editor.updateBlock(blockId, updateData);

// File should be removed from the Uppy instance after upload.
uppy.removeFile(file.id);
Expand All @@ -78,7 +78,7 @@ export function UppyFilePanel(props: FilePanelProps) {
return () => {
uppy.off("upload-success", handler);
};
}, [block, editor]);
}, [blockId, editor]);

// set up dashboard as in https://uppy.io/examples/
return <Dashboard uppy={uppy} width={400} height={500} />;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
},
"dependencies": {
"@emoji-mart/data": "^1.2.1",
"@handlewithcare/prosemirror-inputrules": "0.1.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty nice to be able to add this, allows us to undo an input rule

"@shikijs/types": "3.13.0",
"@tanstack/store": "0.7.7",
"@tiptap/core": "^3.7.2",
"@tiptap/extension-bold": "^3.7.2",
"@tiptap/extension-code": "^3.7.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/blocks/Code/block.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HighlighterGeneric } from "@shikijs/types";
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
import { createExtension } from "../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
import { lazyShikiPlugin } from "./shiki.js";
import { DOMParser } from "@tiptap/pm/model";
Expand Down Expand Up @@ -169,11 +169,11 @@ export const createCodeBlockSpec = createBlockSpec(
}),
(options) => {
return [
createBlockNoteExtension({
createExtension({
key: "code-block-highlighter",
plugins: [lazyShikiPlugin(options)],
}),
createBlockNoteExtension({
createExtension({
key: "code-block-keyboard-shortcuts",
keyboardShortcuts: {
Delete: ({ editor }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/Divider/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
import { createExtension } from "../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";

export type DividerBlockConfig = ReturnType<typeof createDividerBlockConfig>;
Expand Down Expand Up @@ -34,7 +34,7 @@ export const createDividerBlockSpec = createBlockSpec(
},
},
[
createBlockNoteExtension({
createExtension({
key: "divider-block-shortcuts",
inputRules: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
import { FilePanelPlugin } from "../../../../extensions/FilePanel/FilePanelPlugin.js";
import {
BlockConfig,
BlockFromConfigNoChildren,
Expand Down Expand Up @@ -36,11 +37,7 @@ export const createAddFileButton = (
};
// Opens the file toolbar.
const addFileButtonClickHandler = () => {
editor.transact((tr) =>
tr.setMeta(editor.filePanel!.plugins[0], {
block: block,
}),
);
editor.getExtension(FilePanelPlugin)?.showMenu(block.id);
};
addFileButton.addEventListener(
"mousedown",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/Heading/block.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
import { createExtension } from "../../editor/BlockNoteExtension.js";
import {
addDefaultPropsExternalHTML,
defaultProps,
Expand Down Expand Up @@ -97,7 +97,7 @@ export const createHeadingBlockSpec = createBlockSpec(
},
}),
({ levels = HEADING_LEVELS }: HeadingOptions = {}) => [
createBlockNoteExtension({
createExtension({
key: "heading-shortcuts",
keyboardShortcuts: Object.fromEntries(
levels.map((level) => [
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/ListItem/BulletListItem/block.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
import { createExtension } from "../../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
import {
addDefaultPropsExternalHTML,
Expand Down Expand Up @@ -78,7 +78,7 @@ export const createBulletListItemBlockSpec = createBlockSpec(
},
},
[
createBlockNoteExtension({
createExtension({
key: "bullet-list-item-shortcuts",
keyboardShortcuts: {
Enter: ({ editor }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/ListItem/CheckListItem/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
import { createExtension } from "../../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
import {
addDefaultPropsExternalHTML,
Expand Down Expand Up @@ -123,7 +123,7 @@ export const createCheckListItemBlockSpec = createBlockSpec(
runsBefore: ["bulletListItem"],
},
[
createBlockNoteExtension({
createExtension({
key: "check-list-item-shortcuts",
keyboardShortcuts: {
Enter: ({ editor }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/ListItem/NumberedListItem/block.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
import { createExtension } from "../../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
import {
addDefaultPropsExternalHTML,
Expand Down Expand Up @@ -91,7 +91,7 @@ export const createNumberedListItemBlockSpec = createBlockSpec(
},
},
[
createBlockNoteExtension({
createExtension({
key: "numbered-list-item-shortcuts",
inputRules: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/ListItem/ToggleListItem/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
import { createExtension } from "../../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
import {
addDefaultPropsExternalHTML,
Expand Down Expand Up @@ -50,7 +50,7 @@ export const createToggleListItemBlockSpec = createBlockSpec(
},
},
[
createBlockNoteExtension({
createExtension({
key: "toggle-list-item-shortcuts",
keyboardShortcuts: {
Enter: ({ editor }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/Paragraph/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
import { createExtension } from "../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
import {
addDefaultPropsExternalHTML,
Expand Down Expand Up @@ -55,7 +55,7 @@ export const createParagraphBlockSpec = createBlockSpec(
runsBefore: ["default"],
},
[
createBlockNoteExtension({
createExtension({
key: "paragraph-shortcuts",
keyboardShortcuts: {
"Mod-Alt-0": ({ editor }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blocks/Quote/block.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
import { createExtension } from "../../editor/BlockNoteExtension.js";
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
import {
addDefaultPropsExternalHTML,
Expand Down Expand Up @@ -54,7 +54,7 @@ export const createQuoteBlockSpec = createBlockSpec(
},
},
[
createBlockNoteExtension({
createExtension({
key: "quote-block-shortcuts",
keyboardShortcuts: {
"Mod-Alt-q": ({ editor }) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/blocks/Table/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Node, mergeAttributes } from "@tiptap/core";
import { DOMParser, Fragment, Node as PMNode, Schema } from "prosemirror-model";
import { CellSelection, TableView } from "prosemirror-tables";
import { NodeView } from "prosemirror-view";
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
import { createExtension } from "../../editor/BlockNoteExtension.js";
import {
BlockConfig,
createBlockSpecFromTiptapNode,
Expand Down Expand Up @@ -385,7 +385,7 @@ export const createTableBlockSpec = () =>
{ node: TiptapTableNode, type: "table", content: "table" },
tablePropSchema,
[
createBlockNoteExtension({
createExtension({
key: "table-extensions",
tiptapExtensions: [
TableExtension,
Expand All @@ -399,7 +399,7 @@ export const createTableBlockSpec = () =>
// and all cells are selected. Uses a separate extension as it needs
// priority over keyboard handlers in the `TableExtension`'s
// `tableEditing` plugin.
createBlockNoteExtension({
createExtension({
key: "table-keyboard-delete",
keyboardShortcuts: {
Backspace: ({ editor }) => {
Expand Down
Loading
Loading