Skip to content

Commit f4a0316

Browse files
committed
fix: rm heading & code-block opts
1 parent 069f88f commit f4a0316

File tree

8 files changed

+30
-52
lines changed

8 files changed

+30
-52
lines changed

examples/04-theming/06-code-block/src/App.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import "@blocknote/mantine/style.css";
44
import { useCreateBlockNote } from "@blocknote/react";
55
// This packages some of the most used languages in on-demand bundle
66
import { codeBlock } from "@blocknote/code-block";
7+
import { BlockNoteSchema, createCodeBlockSpec } from "@blocknote/core";
78

89
export default function App() {
910
// Creates a new editor instance.
1011
const editor = useCreateBlockNote({
11-
codeBlock,
12+
schema: BlockNoteSchema.create().extend({
13+
blockSpecs: {
14+
codeBlock: createCodeBlockSpec(codeBlock),
15+
},
16+
}),
1217
initialContent: [
1318
{
1419
type: "codeBlock",

packages/code-block/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ export const codeBlock = {
202202
themes: ["github-dark", "github-light"],
203203
langs: [],
204204
}),
205-
} as CodeBlockOptions;
205+
} satisfies CodeBlockOptions;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function lazyShikiPlugin(options: CodeBlockOptions) {
2222
if (process.env.NODE_ENV === "development" && !hasWarned) {
2323
// eslint-disable-next-line no-console
2424
console.log(
25-
"For syntax highlighting of code blocks, you must provide a `codeBlock.createHighlighter` function",
25+
"For syntax highlighting of code blocks, you must provide a `createCodeBlockSpec({ createHighlighter: () => ... })` function",
2626
);
2727
hasWarned = true;
2828
}

packages/core/src/blocks/defaultBlockTypeGuards.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function editorHasBlockWithType<
2525
[PN in keyof Props]: {
2626
default: undefined;
2727
type: Props[PN];
28+
values?: any[];
2829
};
2930
}
3031
>

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ import {
7070
markdownToBlocks,
7171
markdownToHTML,
7272
} from "../api/parsers/markdown/parseMarkdown.js";
73-
import { CodeBlockOptions } from "../blocks/Code/block.js";
7473
import { editorHasBlockWithType } from "../blocks/defaultBlockTypeGuards.js";
7574
import type { ThreadStore, User } from "../comments/index.js";
7675
import { BlockChangePlugin } from "../extensions/BlockChange/BlockChangePlugin.js";
@@ -190,11 +189,6 @@ export type BlockNoteEditorOptions<
190189
showCursorLabels?: "always" | "activity";
191190
};
192191

193-
/**
194-
* Options for code blocks.
195-
*/
196-
codeBlock?: CodeBlockOptions;
197-
198192
/**
199193
* Configuration for the comments feature, requires a `threadStore`.
200194
*
@@ -253,18 +247,6 @@ export type BlockNoteEditorOptions<
253247
class?: string;
254248
}) => Plugin;
255249

256-
/**
257-
* Configuration for headings
258-
*/
259-
heading?: {
260-
/**
261-
* The levels of headings that should be available in the editor.
262-
* @note Configurable up to 6 levels of headings.
263-
* @default [1, 2, 3]
264-
*/
265-
levels?: (1 | 2 | 3 | 4 | 5 | 6)[];
266-
};
267-
268250
/**
269251
* The content that should be in the editor when it's created, represented as an array of {@link PartialBlock} objects.
270252
*
@@ -585,10 +567,6 @@ export class BlockNoteEditor<
585567
cellTextColor: boolean;
586568
headers: boolean;
587569
};
588-
codeBlock: CodeBlockOptions;
589-
heading: {
590-
levels: (1 | 2 | 3 | 4 | 5 | 6)[];
591-
};
592570
};
593571

594572
public static create<
@@ -638,15 +616,6 @@ export class BlockNoteEditor<
638616
cellTextColor: options?.tables?.cellTextColor ?? false,
639617
headers: options?.tables?.headers ?? false,
640618
},
641-
codeBlock: {
642-
indentLineWithTab: options?.codeBlock?.indentLineWithTab ?? true,
643-
defaultLanguage: options?.codeBlock?.defaultLanguage ?? "text",
644-
supportedLanguages: options?.codeBlock?.supportedLanguages ?? {},
645-
createHighlighter: options?.codeBlock?.createHighlighter ?? undefined,
646-
},
647-
heading: {
648-
levels: options?.heading?.levels ?? [1, 2, 3],
649-
},
650619
};
651620

652621
// apply defaults

packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,10 @@ export function getDefaultSlashMenuItems<
354354
...editor.dictionary.slash_menu.toggle_heading_3,
355355
},
356356
);
357+
}
357358

358-
editor.settings.heading.levels
359+
if (editorHasBlockWithType(editor, "heading", { level: "number" })) {
360+
(editor.schema.blockSchema.heading.propSchema.level.values || [])
359361
.filter((level): level is 4 | 5 | 6 => level > 3)
360362
.forEach((level) => {
361363
items.push({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ export function createBlockSpec<
307307
| (TOptions extends undefined
308308
? () => BlockNoteExtension<any>[]
309309
: (options: Partial<TOptions>) => BlockNoteExtension<any>[]),
310-
): (options?: TOptions) => BlockSpec<TName, TProps, TContent> {
310+
): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent> {
311311
return (options = {} as TOptions) => {
312312
const blockConfig =
313313
typeof blockConfigOrCreator === "function"

tests/src/unit/core/createTestEditor.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
BlockNoteEditor,
33
BlockNoteSchema,
44
BlockSchema,
5+
createCodeBlockSpec,
56
initializeESMDependencies,
67
InlineContentSchema,
78
StyleSchema,
@@ -23,25 +24,25 @@ export const createTestEditor = <
2324
(window as any).__TEST_OPTIONS = (window as any).__TEST_OPTIONS || {};
2425

2526
editor = BlockNoteEditor.create({
26-
codeBlock: {
27-
supportedLanguages: {
28-
javascript: {
29-
name: "JavaScript",
30-
aliases: ["js"],
31-
},
32-
python: {
33-
name: "Python",
34-
aliases: ["py"],
35-
},
27+
schema: schema.extend({
28+
blockSpecs: {
29+
codeBlock: createCodeBlockSpec({
30+
supportedLanguages: {
31+
javascript: {
32+
name: "JavaScript",
33+
aliases: ["js"],
34+
},
35+
python: {
36+
name: "Python",
37+
aliases: ["py"],
38+
},
39+
},
40+
}),
3641
},
37-
},
38-
heading: {
39-
levels: [1, 2, 3, 4, 5, 6],
40-
},
41-
schema,
42+
}),
4243
trailingBlock: false,
4344
uploadFile: uploadToTmpFilesDotOrg_DEV_ONLY,
44-
});
45+
}) as any;
4546
editor.mount(div);
4647

4748
await initializeESMDependencies();

0 commit comments

Comments
 (0)