Skip to content

Commit b94e7ee

Browse files
committed
refactor(extensions): rewrite to use new extension system
1 parent f1d6e89 commit b94e7ee

File tree

73 files changed

+3793
-3709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3793
-3709
lines changed

docs/content/docs/features/extensions.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ BlockNote includes an extensions system which lets you expand the editor's behav
1414

1515
## Creating an extension
1616

17-
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:
17+
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:
1818

1919
```typescript
2020
type BlockNoteExtensionOptions = {
@@ -43,10 +43,10 @@ const customBlockExtensionOptions: BlockNoteExtensionOptions = {
4343
tiptapExtensions: ...,
4444
}
4545

46-
const CustomExtension = createBlockNoteExtension(customBlockExtensionOptions);
46+
const CustomExtension = createExtension(customBlockExtensionOptions);
4747
```
4848

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

5151
`key:` The name of the extension.
5252

@@ -74,7 +74,7 @@ The `extensions` [editor option](/docs/reference/editor/overview#options) takes
7474
const editor = useCreateBlockNote({
7575
extensions: [
7676
// Add extensions here:
77-
createBlockNoteExtension({ ... })
77+
createExtension({ ... })
7878
],
7979
});
8080
```
@@ -95,7 +95,7 @@ const createCustomBlock = createReactBlockSpec(
9595
}
9696
[
9797
// Add extensions here:
98-
createBlockNoteExtension({ ... })
98+
createExtension({ ... })
9999
],
100100
});
101101
```

examples/03-ui-components/11-uppy-file-panel/src/FileReplaceButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const FileReplaceButton = () => {
7070
variant={"panel-popover"}
7171
>
7272
{/* Replaces default file panel with our Uppy one. */}
73-
<UppyFilePanel block={block as any} />
73+
<UppyFilePanel blockId={block.id} />
7474
</Components.Generic.Popover.Content>
7575
</Components.Generic.Popover.Root>
7676
);

examples/03-ui-components/11-uppy-file-panel/src/UppyFilePanel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const uppy = new Uppy()
4343
});
4444

4545
export function UppyFilePanel(props: FilePanelProps) {
46-
const { block } = props;
46+
const { blockId } = props;
4747
const editor = useBlockNoteEditor();
4848

4949
useEffect(() => {
@@ -68,7 +68,7 @@ export function UppyFilePanel(props: FilePanelProps) {
6868
url: response.uploadURL,
6969
},
7070
};
71-
editor.updateBlock(block, updateData);
71+
editor.updateBlock(blockId, updateData);
7272

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

8383
// set up dashboard as in https://uppy.io/examples/
8484
return <Dashboard uppy={uppy} width={400} height={500} />;

packages/core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@
8080
},
8181
"dependencies": {
8282
"@emoji-mart/data": "^1.2.1",
83+
"@handlewithcare/prosemirror-inputrules": "0.1.3",
8384
"@shikijs/types": "3.13.0",
85+
"@tanstack/store": "0.7.7",
8486
"@tiptap/core": "^3.7.2",
8587
"@tiptap/extension-bold": "^3.7.2",
8688
"@tiptap/extension-code": "^3.7.2",

packages/core/src/blocks/Code/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { HighlighterGeneric } from "@shikijs/types";
2-
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
2+
import { createExtension } from "../../editor/BlockNoteExtension.js";
33
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
44
import { lazyShikiPlugin } from "./shiki.js";
55
import { DOMParser } from "@tiptap/pm/model";
@@ -169,11 +169,11 @@ export const createCodeBlockSpec = createBlockSpec(
169169
}),
170170
(options) => {
171171
return [
172-
createBlockNoteExtension({
172+
createExtension({
173173
key: "code-block-highlighter",
174174
plugins: [lazyShikiPlugin(options)],
175175
}),
176-
createBlockNoteExtension({
176+
createExtension({
177177
key: "code-block-keyboard-shortcuts",
178178
keyboardShortcuts: {
179179
Delete: ({ editor }) => {

packages/core/src/blocks/Divider/block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
1+
import { createExtension } from "../../editor/BlockNoteExtension.js";
22
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
33

44
export type DividerBlockConfig = ReturnType<typeof createDividerBlockConfig>;
@@ -34,7 +34,7 @@ export const createDividerBlockSpec = createBlockSpec(
3434
},
3535
},
3636
[
37-
createBlockNoteExtension({
37+
createExtension({
3838
key: "divider-block-shortcuts",
3939
inputRules: [
4040
{

packages/core/src/blocks/Heading/block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
2-
import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
2+
import { createExtension } from "../../editor/BlockNoteExtension.js";
33
import {
44
addDefaultPropsExternalHTML,
55
defaultProps,
@@ -97,7 +97,7 @@ export const createHeadingBlockSpec = createBlockSpec(
9797
},
9898
}),
9999
({ levels = HEADING_LEVELS }: HeadingOptions = {}) => [
100-
createBlockNoteExtension({
100+
createExtension({
101101
key: "heading-shortcuts",
102102
keyboardShortcuts: Object.fromEntries(
103103
levels.map((level) => [

packages/core/src/blocks/ListItem/BulletListItem/block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
2-
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
2+
import { createExtension } from "../../../editor/BlockNoteExtension.js";
33
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
44
import {
55
addDefaultPropsExternalHTML,
@@ -78,7 +78,7 @@ export const createBulletListItemBlockSpec = createBlockSpec(
7878
},
7979
},
8080
[
81-
createBlockNoteExtension({
81+
createExtension({
8282
key: "bullet-list-item-shortcuts",
8383
keyboardShortcuts: {
8484
Enter: ({ editor }) => {

packages/core/src/blocks/ListItem/CheckListItem/block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
1+
import { createExtension } from "../../../editor/BlockNoteExtension.js";
22
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
33
import {
44
addDefaultPropsExternalHTML,
@@ -123,7 +123,7 @@ export const createCheckListItemBlockSpec = createBlockSpec(
123123
runsBefore: ["bulletListItem"],
124124
},
125125
[
126-
createBlockNoteExtension({
126+
createExtension({
127127
key: "check-list-item-shortcuts",
128128
keyboardShortcuts: {
129129
Enter: ({ editor }) => {

packages/core/src/blocks/ListItem/NumberedListItem/block.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
2-
import { createBlockNoteExtension } from "../../../editor/BlockNoteExtension.js";
2+
import { createExtension } from "../../../editor/BlockNoteExtension.js";
33
import { createBlockConfig, createBlockSpec } from "../../../schema/index.js";
44
import {
55
addDefaultPropsExternalHTML,
@@ -91,7 +91,7 @@ export const createNumberedListItemBlockSpec = createBlockSpec(
9191
},
9292
},
9393
[
94-
createBlockNoteExtension({
94+
createExtension({
9595
key: "numbered-list-item-shortcuts",
9696
inputRules: [
9797
{

0 commit comments

Comments
 (0)