Skip to content

Commit 59a7a63

Browse files
committed
Merge branch 'default-blocks' of github.com:TypeCellOS/BlockNote into default-blocks
2 parents f242a2f + 05fbc87 commit 59a7a63

File tree

35 files changed

+428
-221
lines changed

35 files changed

+428
-221
lines changed

examples/03-ui-components/13-custom-ui/src/MUIFormattingToolbar.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,24 @@ function MUITextAlignButton(props: {
266266
const editor = useBlockNoteEditor<TextBlockSchema>();
267267

268268
// The text alignment of the block currently containing the text cursor.
269-
const [activeTextAlignment, setActiveTextAlignment] = useState(
270-
() => editor.getTextCursorPosition().block.props.textAlignment,
271-
);
269+
const [activeTextAlignment, setActiveTextAlignment] = useState(() => {
270+
const props = editor.getTextCursorPosition().block.props;
271+
if ("textAlignment" in props) {
272+
return props.textAlignment;
273+
}
274+
return undefined;
275+
});
272276

273277
// Updates the text alignment when the editor content or selection changes.
274-
useEditorContentOrSelectionChange(
275-
() =>
276-
setActiveTextAlignment(
277-
editor.getTextCursorPosition().block.props.textAlignment,
278-
),
279-
editor,
280-
);
278+
useEditorContentOrSelectionChange(() => {
279+
setActiveTextAlignment(() => {
280+
const props = editor.getTextCursorPosition().block.props;
281+
if ("textAlignment" in props) {
282+
return props.textAlignment;
283+
}
284+
return undefined;
285+
});
286+
}, editor);
281287

282288
// Tooltip for the button.
283289
const tooltip = useMemo(

examples/05-interoperability/07-converting-blocks-to-odt/src/App.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
BlockNoteSchema,
33
combineByGroup,
4-
createPageBreakBlockSpec,
4+
withPageBreak,
55
filterSuggestionItems,
66
} from "@blocknote/core";
77
import * as locales from "@blocknote/core/locales";
@@ -22,8 +22,7 @@ import {
2222
getMultiColumnSlashMenuItems,
2323
multiColumnDropCursor,
2424
locales as multiColumnLocales,
25-
ColumnBlock,
26-
ColumnListBlock,
25+
withMultiColumn,
2726
} from "@blocknote/xl-multi-column";
2827
import { useMemo } from "react";
2928

@@ -32,15 +31,7 @@ import "./styles.css";
3231
export default function App() {
3332
// Creates a new editor instance with some initial content.
3433
const editor = useCreateBlockNote({
35-
schema: (
36-
BlockNoteSchema.create().extend({
37-
blockSpecs: {
38-
pageBreak: createPageBreakBlockSpec(),
39-
column: ColumnBlock,
40-
columnList: ColumnListBlock,
41-
},
42-
}),
43-
),
34+
schema: withMultiColumn(withPageBreak(BlockNoteSchema.create())),
4435
dropCursor: multiColumnDropCursor,
4536
dictionary: {
4637
...locales.en,

examples/06-custom-schema/04-pdf-file-block/src/PDF.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export const PDF = createReactBlockSpec(
5252
},
5353
},
5454
content: "none",
55+
},
56+
{
5557
meta: {
5658
fileBlockAccept: ["application/pdf"],
5759
},
58-
},
59-
{
6060
render: (props) => (
6161
<ResizableFileBlockWrapper
6262
{...(props as any)}

packages/core/src/api/clipboard/fromClipboard/handleFileInsertion.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ export async function handleFileInsertion<
108108
for (let i = 0; i < items.length; i++) {
109109
// Gets file block corresponding to MIME type.
110110
let fileBlockType = "file";
111-
for (const fileBlockConfig of Object.values(editor.schema.blockSchema)) {
112-
for (const mimeType of fileBlockConfig.meta?.fileBlockAccept || []) {
111+
for (const blockSpec of Object.values(editor.schema.blockSpecs)) {
112+
for (const mimeType of blockSpec.implementation.meta?.fileBlockAccept ||
113+
[]) {
113114
const isFileExtension = mimeType.startsWith(".");
114115
const file = items[i].getAsFile();
115116

@@ -124,7 +125,7 @@ export async function handleFileInsertion<
124125
mimeType,
125126
))
126127
) {
127-
fileBlockType = fileBlockConfig.type;
128+
fileBlockType = blockSpec.config.type;
128129
break;
129130
}
130131
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ export const createAudioBlockConfig = createBlockConfig(
4242
},
4343
},
4444
content: "none",
45-
meta: {
46-
fileBlockAccept: ["audio/*"],
47-
},
4845
}) as const,
4946
);
5047

@@ -157,6 +154,9 @@ export const audioToExternalHTML =
157154
export const createAudioBlockSpec = createBlockSpec(
158155
createAudioBlockConfig,
159156
(config) => ({
157+
meta: {
158+
fileBlockAccept: ["audio/*"],
159+
},
160160
parse: audioParse(config),
161161
render: audioRender(config),
162162
toExternalHTML: audioToExternalHTML(config),

packages/core/src/blocks/BlockNoteSchema.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export class BlockNoteSchema<
2222
SSchema extends StyleSchema,
2323
> extends CustomBlockNoteSchema<BSchema, ISchema, SSchema> {
2424
public static create<
25-
BSpecs extends BlockSpecs = typeof defaultBlockSpecs,
26-
ISpecs extends InlineContentSpecs = typeof defaultInlineContentSpecs,
27-
SSpecs extends StyleSpecs = typeof defaultStyleSpecs,
25+
BSpecs extends BlockSpecs | undefined = undefined,
26+
ISpecs extends InlineContentSpecs | undefined = undefined,
27+
SSpecs extends StyleSpecs | undefined = undefined,
2828
>(options?: {
2929
/**
3030
* A list of custom block types that should be available in the editor.
@@ -38,12 +38,18 @@ export class BlockNoteSchema<
3838
* A list of custom Styles that should be available in the editor.
3939
*/
4040
styleSpecs?: SSpecs;
41-
}) {
42-
return new BlockNoteSchema<
43-
BlockSchemaFromSpecs<BSpecs>,
44-
InlineContentSchemaFromSpecs<ISpecs>,
45-
StyleSchemaFromSpecs<SSpecs>
46-
>({
41+
}): BlockNoteSchema<
42+
BSpecs extends undefined
43+
? BlockSchemaFromSpecs<typeof defaultBlockSpecs>
44+
: BlockSchemaFromSpecs<NonNullable<BSpecs>>,
45+
ISpecs extends undefined
46+
? InlineContentSchemaFromSpecs<typeof defaultInlineContentSpecs>
47+
: InlineContentSchemaFromSpecs<NonNullable<ISpecs>>,
48+
SSpecs extends undefined
49+
? StyleSchemaFromSpecs<typeof defaultStyleSpecs>
50+
: StyleSchemaFromSpecs<NonNullable<SSpecs>>
51+
> {
52+
return new BlockNoteSchema<any, any, any>({
4753
blockSpecs: options?.blockSpecs ?? defaultBlockSpecs,
4854
inlineContentSpecs:
4955
options?.inlineContentSpecs ?? defaultInlineContentSpecs,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ export const createCodeBlockConfig = createBlockConfig(
6161
},
6262
},
6363
content: "inline",
64-
meta: {
65-
code: true,
66-
defining: true,
67-
isolating: false,
68-
},
6964
}) as const,
7065
);
7166

7267
export const createCodeBlockSpec = createBlockSpec(
7368
createCodeBlockConfig,
7469
(options) => ({
70+
meta: {
71+
code: true,
72+
defining: true,
73+
isolating: false,
74+
},
7575
parse: (e) => {
7676
if (e.tagName !== "PRE") {
7777
return undefined;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export const createFileBlockConfig = createBlockConfig(
2525
},
2626
},
2727
content: "none" as const,
28-
meta: {
29-
fileBlockAccept: ["*/*"],
30-
},
3128
}) as const,
3229
);
3330

@@ -59,6 +56,9 @@ export const fileParse = () => (element: HTMLElement) => {
5956
};
6057

6158
export const createFileBlockSpec = createBlockSpec(createFileBlockConfig, {
59+
meta: {
60+
fileBlockAccept: ["*/*"],
61+
},
6262
parse: fileParse(),
6363
render(block, editor) {
6464
return createFileBlockWrapper(block, editor);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export const createHeadingBlockConfig = createBlockConfig(
3030
: {}),
3131
},
3232
content: "inline",
33-
meta: {
34-
isolating: false,
35-
},
3633
}) as const,
3734
);
3835

3936
export const createHeadingBlockSpec = createBlockSpec(
4037
createHeadingBlockConfig,
4138
({ allowToggleHeadings = true }: HeadingOptions = {}) => ({
39+
meta: {
40+
isolating: false,
41+
},
4242
parse(e) {
4343
let level: number;
4444
switch (e.tagName) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ export const createImageBlockConfig = createBlockConfig(
4747
},
4848
},
4949
content: "none" as const,
50-
meta: {
51-
fileBlockAccept: ["image/*"],
52-
},
5350
}) as const,
5451
);
5552

@@ -172,6 +169,9 @@ export const imageToExternalHTML =
172169
export const createImageBlockSpec = createBlockSpec(
173170
createImageBlockConfig,
174171
(config) => ({
172+
meta: {
173+
fileBlockAccept: ["image/*"],
174+
},
175175
parse: imageParse(config),
176176
render: imageRender(config),
177177
toExternalHTML: imageToExternalHTML(config),

0 commit comments

Comments
 (0)