Skip to content

Commit c3422c2

Browse files
fix: Improve setting text for custom file blocks (#1984)
1 parent 7cd14e2 commit c3422c2

File tree

35 files changed

+144
-277
lines changed

35 files changed

+144
-277
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
filterSuggestionItems,
55
insertOrUpdateBlock,
66
} from "@blocknote/core";
7+
import { en } from "@blocknote/core/locales";
78
import "@blocknote/core/fonts/inter.css";
89
import { BlockNoteView } from "@blocknote/mantine";
910
import "@blocknote/mantine/style.css";
@@ -17,6 +18,12 @@ import { RiFilePdfFill } from "react-icons/ri";
1718

1819
import { PDF } from "./PDF";
1920

21+
// Updated English dictionary with entries for PDF blocks.
22+
const dictionary = en;
23+
en.file_blocks.add_button_text["pdf"] = "Add PDF";
24+
en.file_panel.embed.embed_button["pdf"] = "Embed PDF";
25+
en.file_panel.upload.file_placeholder["pdf"] = "Upload PDF";
26+
2027
// Our schema with block specs, which contain the configs and implementations for blocks
2128
// that we want our editor to use.
2229
const schema = BlockNoteSchema.create({
@@ -44,6 +51,7 @@ const insertPDF = (editor: typeof schema.BlockNoteEditor) => ({
4451
export default function App() {
4552
// Creates a new editor instance.
4653
const editor = useCreateBlockNote({
54+
dictionary,
4755
schema,
4856
initialContent: [
4957
{

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export const PDF = createReactBlockSpec(
5454
render: (props) => (
5555
<ResizableFileBlockWrapper
5656
{...(props as any)}
57-
bbuttonText={"Add PDF"}
5857
buttonIcon={<RiFilePdfFill size={24} />}
5958
>
6059
<PDFPreview {...(props as any)} />

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export const audioRender = (
6969
block,
7070
editor,
7171
{ dom: audio },
72-
editor.dictionary.file_blocks.audio.add_button_text,
7372
icon.firstElementChild as HTMLElement,
7473
);
7574
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
44
export const createAddFileButton = (
55
block: BlockFromConfig<FileBlockConfig, any, any>,
66
editor: BlockNoteEditor<any, any, any>,
7-
buttonText?: string,
87
buttonIcon?: HTMLElement,
98
) => {
109
const addFileButton = document.createElement("div");
@@ -23,7 +22,9 @@ export const createAddFileButton = (
2322
const addFileButtonText = document.createElement("p");
2423
addFileButtonText.className = "bn-add-file-button-text";
2524
addFileButtonText.innerHTML =
26-
buttonText || editor.dictionary.file_blocks.file.add_button_text;
25+
block.type in editor.dictionary.file_blocks.add_button_text
26+
? editor.dictionary.file_blocks.add_button_text[block.type]
27+
: editor.dictionary.file_blocks.add_button_text["file"];
2728
addFileButton.appendChild(addFileButtonText);
2829

2930
// Prevents focus from moving to the button.

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export const createFileBlockWrapper = (
1515
any
1616
>,
1717
element?: { dom: HTMLElement; destroy?: () => void },
18-
buttonText?: string,
1918
buttonIcon?: HTMLElement,
2019
) => {
2120
const wrapper = document.createElement("div");
@@ -24,12 +23,7 @@ export const createFileBlockWrapper = (
2423
// Show the add file button if the file has not been uploaded yet. Change to
2524
// show a loader if a file upload for the block begins.
2625
if (block.props.url === "") {
27-
const addFileButton = createAddFileButton(
28-
block,
29-
editor,
30-
buttonText,
31-
buttonIcon,
32-
);
26+
const addFileButton = createAddFileButton(block, editor, buttonIcon);
3327
wrapper.appendChild(addFileButton.dom);
3428

3529
const destroyUploadStartHandler = editor.onUploadStart((blockId) => {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export const createResizableFileBlockWrapper = (
77
editor: BlockNoteEditor<any, any, any>,
88
element: { dom: HTMLElement; destroy?: () => void },
99
resizeHandlesContainerElement: HTMLElement,
10-
buttonText: string,
11-
buttonIcon: HTMLElement,
10+
buttonIcon?: HTMLElement,
1211
): { dom: HTMLElement; destroy: () => void } => {
1312
const { dom, destroy } = createFileBlockWrapper(
1413
block,
1514
editor,
1615
element,
17-
buttonText,
1816
buttonIcon,
1917
);
2018
const wrapper = dom;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export const imageRender = (
8080
editor,
8181
{ dom: imageWrapper },
8282
imageWrapper,
83-
editor.dictionary.file_blocks.image.add_button_text,
8483
icon.firstElementChild as HTMLElement,
8584
);
8685
};

packages/core/src/blocks/VideoBlockContent/VideoBlockContent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export const videoRender = (
8080
editor,
8181
{ dom: videoWrapper },
8282
videoWrapper,
83-
editor.dictionary.file_blocks.video.add_button_text,
8483
icon.firstElementChild as HTMLElement,
8584
);
8685
};

packages/core/src/i18n/locales/ar.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,12 @@ export const ar: Dictionary = {
169169
comment_reply: "أضف تعليقًا...",
170170
},
171171
file_blocks: {
172-
image: {
173-
add_button_text: "إضافة صورة",
174-
},
175-
video: {
176-
add_button_text: "إضافة فيديو",
177-
},
178-
audio: {
179-
add_button_text: "إضافة صوت",
180-
},
181-
file: {
182-
add_button_text: "إضافة ملف",
183-
},
172+
add_button_text: {
173+
image: "إضافة صورة",
174+
video: "إضافة فيديو",
175+
audio: "إضافة صوت",
176+
file: "إضافة ملف",
177+
} as Record<string, string>,
184178
},
185179
toggle_blocks: {
186180
add_block_button: "تبديل فارغ. انقر لإضافة كتلة.",

packages/core/src/i18n/locales/de.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,12 @@ export const de: Dictionary = {
204204
comment_reply: "Kommentar hinzufügen …",
205205
},
206206
file_blocks: {
207-
image: {
208-
add_button_text: "Bild hinzufügen",
209-
},
210-
video: {
211-
add_button_text: "Video hinzufügen",
212-
},
213-
audio: {
214-
add_button_text: "Audio hinzufügen",
215-
},
216-
file: {
217-
add_button_text: "Datei hinzufügen",
218-
},
207+
add_button_text: {
208+
image: "Bild hinzufügen",
209+
video: "Video hinzufügen",
210+
audio: "Audio hinzufügen",
211+
file: "Datei hinzufügen",
212+
} as Record<string, string>,
219213
},
220214
toggle_blocks: {
221215
add_block_button:

0 commit comments

Comments
 (0)