Skip to content

Commit c51767a

Browse files
committed
Made type guards more generic
1 parent 5751974 commit c51767a

File tree

23 files changed

+283
-269
lines changed

23 files changed

+283
-269
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+
blockHasProps,
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+
!blockHasProps(block, { url: { default: "" } }) ||
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/blks/Audio/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const definition = createBlockDefinition(config).implementation(
7272
},
7373
render: (block, editor) => {
7474
const icon = document.createElement("div");
75-
icon.innerHTML = config.icon ?? FILE_AUDIO_ICON_SVG;
75+
icon.innerHTML = config?.icon ?? FILE_AUDIO_ICON_SVG;
7676

7777
const audio = document.createElement("audio");
7878
audio.className = "bn-audio";

packages/core/src/blks/Image/definition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const config = createBlockConfig((_ctx: ImageOptions = {}) => ({
4141
default: undefined,
4242
type: "number",
4343
},
44-
},
44+
} as const,
4545
content: "none" as const,
4646
meta: {
4747
fileBlockAccept: ["image/*"],
@@ -78,7 +78,7 @@ export const definition = createBlockDefinition(config).implementation(
7878
},
7979
render: (block, editor) => {
8080
const icon = document.createElement("div");
81-
icon.innerHTML = config.icon ?? FILE_IMAGE_ICON_SVG;
81+
icon.innerHTML = config?.icon ?? FILE_IMAGE_ICON_SVG;
8282

8383
const imageWrapper = document.createElement("div");
8484
imageWrapper.className = "bn-visual-media-wrapper";

packages/core/src/blks/NumberedListItem/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const config = createBlockConfig(() => ({
1515
propSchema: {
1616
...defaultProps,
1717
start: { default: undefined, type: "number" },
18-
},
18+
} as const,
1919
content: "inline",
2020
}));
2121

packages/core/src/blks/Video/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const definition = createBlockDefinition(config).implementation(
6262
},
6363
render: (block, editor) => {
6464
const icon = document.createElement("div");
65-
icon.innerHTML = config.icon ?? FILE_VIDEO_ICON_SVG;
65+
icon.innerHTML = config?.icon ?? FILE_VIDEO_ICON_SVG;
6666

6767
const videoWrapper = document.createElement("div");
6868
videoWrapper.className = "bn-visual-media-wrapper";

packages/core/src/blks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export * as heading from "./Heading/definition.js";
66
export * as numberedListItem from "./NumberedListItem/definition.js";
77
export * as pageBreak from "./PageBreak/definition.js";
88
export * as paragraph from "./Paragraph/definition.js";
9-
export * as quoteBlock from "./Quote/definition.js";
9+
export * as quote from "./Quote/definition.js";
1010
export * as toggleListItem from "./ToggleListItem/definition.js";
1111

1212
export * as file from "./File/definition.js";

0 commit comments

Comments
 (0)