Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
BlockSchema,
checkBlockIsFileBlock,
blockHasType,
InlineContentSchema,
StyleSchema,
} from "@blocknote/core";
Expand Down Expand Up @@ -41,7 +41,7 @@ export const FileReplaceButton = () => {

if (
block === undefined ||
!checkBlockIsFileBlock(block, editor) ||
!blockHasType(block, editor, { url: "string" }) ||
!editor.isEditable
) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Block, PartialBlock } from "../../../blocks/defaultBlocks.js";
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
import {
BlockSchema,
FileBlockConfig,
InlineContentSchema,
StyleSchema,
} from "../../../schema/index.js";
Expand Down Expand Up @@ -106,15 +105,11 @@ export async function handleFileInsertion<

event.preventDefault();

const fileBlockConfigs = Object.values(editor.schema.blockSchema).filter(
(blockConfig) => blockConfig.isFileBlock,
) as FileBlockConfig[];

for (let i = 0; i < items.length; i++) {
// Gets file block corresponding to MIME type.
let fileBlockType = "file";
for (const fileBlockConfig of fileBlockConfigs) {
for (const mimeType of fileBlockConfig.fileBlockAccept || []) {
for (const fileBlockConfig of Object.values(editor.schema.blockSchema)) {
for (const mimeType of fileBlockConfig.meta?.fileBlockAccept || []) {
const isFileExtension = mimeType.startsWith(".");
const file = items[i].getAsFile();

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blks/Audio/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const definition = createBlockDefinition(config).implementation(
},
render: (block, editor) => {
const icon = document.createElement("div");
icon.innerHTML = config.icon ?? FILE_AUDIO_ICON_SVG;
icon.innerHTML = config?.icon ?? FILE_AUDIO_ICON_SVG;

const audio = document.createElement("audio");
audio.className = "bn-audio";
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/blks/Heading/definition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { updateBlockTr } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
import { getBlockInfoFromTransaction } from "../../api/getBlockInfoFromPos.js";
import { defaultProps } from "../../blocks/defaultProps.js";
import { createToggleWrapper } from "../../blocks/ToggleWrapper/createToggleWrapper.js";
import {
createBlockConfig,
Expand All @@ -24,6 +25,7 @@ const config = createBlockConfig(
}: HeadingOptions = {}) => ({
type: "heading" as const,
propSchema: {
...defaultProps,
level: { default: defaultLevel, values: levels },
...(allowToggleHeadings ? { isToggleable: { default: false } } : {}),
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/blks/Image/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const config = createBlockConfig((_ctx: ImageOptions = {}) => ({
default: undefined,
type: "number",
},
},
} as const,
content: "none" as const,
meta: {
fileBlockAccept: ["image/*"],
Expand Down Expand Up @@ -78,7 +78,7 @@ export const definition = createBlockDefinition(config).implementation(
},
render: (block, editor) => {
const icon = document.createElement("div");
icon.innerHTML = config.icon ?? FILE_IMAGE_ICON_SVG;
icon.innerHTML = config?.icon ?? FILE_IMAGE_ICON_SVG;

const imageWrapper = document.createElement("div");
imageWrapper.className = "bn-visual-media-wrapper";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blks/NumberedListItem/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const config = createBlockConfig(() => ({
propSchema: {
...defaultProps,
start: { default: undefined, type: "number" },
},
} as const,
content: "inline",
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blks/Video/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const definition = createBlockDefinition(config).implementation(
},
render: (block, editor) => {
const icon = document.createElement("div");
icon.innerHTML = config.icon ?? FILE_VIDEO_ICON_SVG;
icon.innerHTML = config?.icon ?? FILE_VIDEO_ICON_SVG;

const videoWrapper = document.createElement("div");
videoWrapper.className = "bn-visual-media-wrapper";
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * as heading from "./Heading/definition.js";
export * as numberedListItem from "./NumberedListItem/definition.js";
export * as pageBreak from "./PageBreak/definition.js";
export * as paragraph from "./Paragraph/definition.js";
export * as quoteBlock from "./Quote/definition.js";
export * as quote from "./Quote/definition.js";
export * as toggleListItem from "./ToggleListItem/definition.js";

export * as file from "./File/definition.js";
Expand Down
Loading
Loading