Skip to content

Commit 1e0e059

Browse files
committed
Merge branch 'default-blocks-type-guards' into default-blocks
2 parents 9918510 + 1ff7474 commit 1e0e059

File tree

28 files changed

+369
-305
lines changed

28 files changed

+369
-305
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
BlockSchema,
3-
checkBlockIsFileBlock,
3+
blockHasType,
44
InlineContentSchema,
55
StyleSchema,
66
} from "@blocknote/core";
@@ -41,7 +41,7 @@ export const FileReplaceButton = () => {
4141

4242
if (
4343
block === undefined ||
44-
!checkBlockIsFileBlock(block, editor) ||
44+
!blockHasType(block, editor, { url: "string" }) ||
4545
!editor.isEditable
4646
) {
4747
return null;

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Block, PartialBlock } from "../../../blocks/defaultBlocks.js";
22
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
33
import {
44
BlockSchema,
5-
FileBlockConfig,
65
InlineContentSchema,
76
StyleSchema,
87
} from "../../../schema/index.js";
@@ -106,15 +105,11 @@ export async function handleFileInsertion<
106105

107106
event.preventDefault();
108107

109-
const fileBlockConfigs = Object.values(editor.schema.blockSchema).filter(
110-
(blockConfig) => blockConfig.isFileBlock,
111-
) as FileBlockConfig[];
112-
113108
for (let i = 0; i < items.length; i++) {
114109
// Gets file block corresponding to MIME type.
115110
let fileBlockType = "file";
116-
for (const fileBlockConfig of fileBlockConfigs) {
117-
for (const mimeType of fileBlockConfig.fileBlockAccept || []) {
111+
for (const fileBlockConfig of Object.values(editor.schema.blockSchema)) {
112+
for (const mimeType of fileBlockConfig.meta?.fileBlockAccept || []) {
118113
const isFileExtension = mimeType.startsWith(".");
119114
const file = items[i].getAsFile();
120115

packages/core/src/blocks/AudioBlockContent/AudioBlockContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
22
import {
33
BlockFromConfig,
44
createBlockSpec,
5-
FileBlockConfig,
5+
// FileBlockConfig,
66
Props,
77
PropSchema,
88
} from "../../schema/index.js";
@@ -43,7 +43,7 @@ export const audioBlockConfig = {
4343
content: "none",
4444
isFileBlock: true,
4545
fileBlockAccept: ["audio/*"],
46-
} satisfies FileBlockConfig;
46+
} as any;
4747

4848
export const audioRender = (
4949
block: BlockFromConfig<typeof audioBlockConfig, any, any>,

packages/core/src/blocks/FileBlockContent/FileBlockContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
22
import {
33
BlockFromConfig,
4-
FileBlockConfig,
4+
// FileBlockConfig,
55
PropSchema,
66
createBlockSpec,
77
} from "../../schema/index.js";
@@ -32,7 +32,7 @@ export const fileBlockConfig = {
3232
propSchema: filePropSchema,
3333
content: "none",
3434
isFileBlock: true,
35-
} satisfies FileBlockConfig;
35+
} as any;
3636

3737
export const fileRender = (
3838
block: BlockFromConfig<typeof fileBlockConfig, any, any>,

packages/core/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2-
import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
2+
import {
3+
BlockConfig,
4+
BlockFromConfigNoChildren,
5+
} from "../../../../schema/index.js";
36

47
export const createAddFileButton = (
5-
block: BlockFromConfig<FileBlockConfig, any, any>,
8+
block: BlockFromConfigNoChildren<BlockConfig<string, any, "none">, any, any>,
69
editor: BlockNoteEditor<any, any, any>,
710
buttonText?: string,
811
buttonIcon?: HTMLElement,

packages/core/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
22
import {
3-
BlockFromConfig,
4-
BlockSchemaWithBlock,
5-
FileBlockConfig,
3+
BlockConfig,
4+
BlockFromConfigNoChildren,
65
} from "../../../../schema/index.js";
76
import { createAddFileButton } from "./createAddFileButton.js";
87
import { createFileNameWithIcon } from "./createFileNameWithIcon.js";
98

109
export const createFileBlockWrapper = (
11-
block: BlockFromConfig<FileBlockConfig, any, any>,
12-
editor: BlockNoteEditor<
13-
BlockSchemaWithBlock<FileBlockConfig["type"], FileBlockConfig>,
10+
block: BlockFromConfigNoChildren<
11+
BlockConfig<
12+
string,
13+
{
14+
backgroundColor: { default: "default" };
15+
name: { default: "" };
16+
url: { default: "" };
17+
caption: { default: "" };
18+
showPreview?: { default: true };
19+
},
20+
"none"
21+
>,
1422
any,
1523
any
1624
>,
25+
editor: BlockNoteEditor<any, any, any>,
1726
element?: { dom: HTMLElement; destroy?: () => void },
1827
buttonText?: string,
1928
buttonIcon?: HTMLElement,

packages/core/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
1+
import {
2+
BlockConfig,
3+
BlockFromConfigNoChildren,
4+
} from "../../../../schema/index.js";
25

36
export const FILE_ICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M3 8L9.00319 2H19.9978C20.5513 2 21 2.45531 21 2.9918V21.0082C21 21.556 20.5551 22 20.0066 22H3.9934C3.44476 22 3 21.5501 3 20.9932V8ZM10 4V9H5V20H19V4H10Z"></path></svg>`;
47

58
export const createFileNameWithIcon = (
6-
block: BlockFromConfig<FileBlockConfig, any, any>,
9+
block: BlockFromConfigNoChildren<
10+
BlockConfig<
11+
string,
12+
{
13+
name: { default: "" };
14+
},
15+
"none"
16+
>,
17+
any,
18+
any
19+
>,
720
): { dom: HTMLElement; destroy?: () => void } => {
821
const file = document.createElement("div");
922
file.className = "bn-file-name-with-icon";

packages/core/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2-
import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
2+
import {
3+
BlockConfig,
4+
BlockFromConfigNoChildren,
5+
} from "../../../../schema/index.js";
36
import { createFileBlockWrapper } from "./createFileBlockWrapper.js";
47

58
export const createResizableFileBlockWrapper = (
6-
block: BlockFromConfig<FileBlockConfig, any, any>,
9+
block: BlockFromConfigNoChildren<
10+
BlockConfig<
11+
string,
12+
{
13+
backgroundColor: { default: "default" };
14+
name: { default: "" };
15+
url: { default: "" };
16+
caption: { default: "" };
17+
showPreview?: { default: true };
18+
previewWidth?: { default: number };
19+
textAlignment?: { default: "left" };
20+
},
21+
"none"
22+
>,
23+
any,
24+
any
25+
>,
726
editor: BlockNoteEditor<any, any, any>,
827
element: { dom: HTMLElement; destroy?: () => void },
928
resizeHandlesContainerElement: HTMLElement,

packages/core/src/blocks/ImageBlockContent/ImageBlockContent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
22
import {
33
BlockFromConfig,
44
createBlockSpec,
5-
FileBlockConfig,
5+
// FileBlockConfig,
66
Props,
77
PropSchema,
88
} from "../../schema/index.js";
@@ -48,7 +48,7 @@ export const imageBlockConfig = {
4848
content: "none",
4949
isFileBlock: true,
5050
fileBlockAccept: ["image/*"],
51-
} satisfies FileBlockConfig;
51+
} as any;
5252

5353
export const imageRender = (
5454
block: BlockFromConfig<typeof imageBlockConfig, any, any>,

packages/core/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ export const pageBreakConfig = {
88
type: "pageBreak" as const,
99
propSchema: {},
1010
content: "none",
11-
isFileBlock: false,
12-
isSelectable: false,
1311
} satisfies CustomBlockConfig;
1412
export const pageBreakRender = () => {
1513
const pageBreak = document.createElement("div");

0 commit comments

Comments
 (0)