From 082b710a5c8d5264ca4008ad45a40655073aad4b Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Sat, 15 Mar 2025 12:17:54 +0100 Subject: [PATCH 1/5] feat: split out localization files for optimized bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: ```txt vite v5.3.4 building for production... ✓ 168 modules transformed. dist/webpack-stats.json 14.00 kB │ gzip: 2.39 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/comments.js 17.39 kB │ gzip: 3.51 kB │ map: 49.43 kB dist/blocknote.js 416.35 kB │ gzip: 93.27 kB │ map: 1,103.85 kB dist/webpack-stats.json 14.01 kB │ gzip: 2.41 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/comments.cjs 11.72 kB │ gzip: 2.85 kB │ map: 47.30 kB dist/blocknote.cjs 273.46 kB │ gzip: 72.57 kB │ map: 1,044.26 kB ✓ built in 506ms ``` After: ```txt vite v5.3.4 building for production... ✓ 170 modules transformed. dist/webpack-stats.json 14.50 kB │ gzip: 2.52 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/en-BEb_5vQO.js 7.78 kB │ gzip: 1.91 kB │ map: 14.03 kB dist/comments.js 17.39 kB │ gzip: 3.51 kB │ map: 49.43 kB dist/locales.js 135.64 kB │ gzip: 27.15 kB │ map: 238.90 kB dist/blocknote.js 274.20 kB │ gzip: 65.23 kB │ map: 853.96 kB dist/webpack-stats.json 14.51 kB │ gzip: 2.52 kB dist/style.css 11.63 kB │ gzip: 2.82 kB dist/en-DoDAHwFo.cjs 5.34 kB │ gzip: 1.76 kB │ map: 12.34 kB dist/comments.cjs 11.72 kB │ gzip: 2.85 kB │ map: 47.30 kB dist/locales.cjs 93.50 kB │ gzip: 24.76 kB │ map: 210.56 kB dist/blocknote.cjs 175.52 kB │ gzip: 47.01 kB │ map: 823.91 kB ✓ built in 588ms ``` Shaved ~100kb from cjs --- examples/01-basic/10-localization/App.tsx | 2 +- packages/core/package.json | 5 +++++ packages/core/src/i18n/index.ts | 2 ++ packages/core/src/index.ts | 3 --- packages/core/vite.config.ts | 1 + 5 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 packages/core/src/i18n/index.ts diff --git a/examples/01-basic/10-localization/App.tsx b/examples/01-basic/10-localization/App.tsx index 72b7557f1f..7f966069ae 100644 --- a/examples/01-basic/10-localization/App.tsx +++ b/examples/01-basic/10-localization/App.tsx @@ -1,4 +1,4 @@ -import { locales } from "@blocknote/core"; +import { locales } from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { BlockNoteView } from "@blocknote/mantine"; import "@blocknote/mantine/style.css"; diff --git a/packages/core/package.json b/packages/core/package.json index 3510bbdc0c..ff7e9f7f39 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -49,6 +49,11 @@ "types": "./types/src/comments/index.d.ts", "import": "./dist/comments.js", "require": "./dist/comments.cjs" + }, + "./locales": { + "types": "./types/src/i18n/index.d.ts", + "import": "./dist/locales.js", + "require": "./dist/locales.cjs" } }, "scripts": { diff --git a/packages/core/src/i18n/index.ts b/packages/core/src/i18n/index.ts new file mode 100644 index 0000000000..2a04b0f9cb --- /dev/null +++ b/packages/core/src/i18n/index.ts @@ -0,0 +1,2 @@ +export * as locales from "./locales/index.js"; +export * from "./dictionary.js"; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 3ec64b0dc6..2c70a913aa 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,4 +1,3 @@ -import * as locales from "./i18n/locales/index.js"; export * from "./api/blockManipulation/commands/updateBlock/updateBlock.js"; export * from "./api/exporters/html/externalHTMLExporter.js"; export * from "./api/exporters/html/internalHTMLSerializer.js"; @@ -57,7 +56,6 @@ export * from "./util/table.js"; export * from "./util/string.js"; export * from "./util/typescript.js"; export { UnreachableCaseError, assertEmpty } from "./util/typescript.js"; -export { locales }; // for testing from react (TODO: move): export * from "./api/nodeConversions/blockToNode.js"; @@ -69,4 +67,3 @@ export * from "./extensions/UniqueID/UniqueID.js"; export * from "./api/exporters/markdown/markdownExporter.js"; export * from "./api/parsers/html/parseHTML.js"; export * from "./api/parsers/markdown/parseMarkdown.js"; - diff --git a/packages/core/vite.config.ts b/packages/core/vite.config.ts index c5f9b60463..0fc59bfd4d 100644 --- a/packages/core/vite.config.ts +++ b/packages/core/vite.config.ts @@ -19,6 +19,7 @@ export default defineConfig({ entry: { blocknote: path.resolve(__dirname, "src/index.ts"), comments: path.resolve(__dirname, "src/comments/index.ts"), + locales: path.resolve(__dirname, "src/i18n/index.ts"), }, name: "blocknote", formats: ["es", "cjs"], From e33a4a3efd4bbeedc66065bc4fe8e102ec29d272 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Mon, 24 Mar 2025 15:48:11 +0100 Subject: [PATCH 2/5] refactor: export individual locales for tree-shaking --- examples/01-basic/03-multi-column/App.tsx | 2 +- examples/01-basic/11-custom-placeholder/App.tsx | 4 ++-- packages/core/src/i18n/index.ts | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/01-basic/03-multi-column/App.tsx b/examples/01-basic/03-multi-column/App.tsx index 630f8e557a..595f4fac80 100644 --- a/examples/01-basic/03-multi-column/App.tsx +++ b/examples/01-basic/03-multi-column/App.tsx @@ -2,8 +2,8 @@ import { BlockNoteSchema, combineByGroup, filterSuggestionItems, - locales, } from "@blocknote/core"; +import { locales } from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { BlockNoteView } from "@blocknote/mantine"; import "@blocknote/mantine/style.css"; diff --git a/examples/01-basic/11-custom-placeholder/App.tsx b/examples/01-basic/11-custom-placeholder/App.tsx index 2919ce8e0d..b1323aacb5 100644 --- a/examples/01-basic/11-custom-placeholder/App.tsx +++ b/examples/01-basic/11-custom-placeholder/App.tsx @@ -1,4 +1,4 @@ -import { locales } from "@blocknote/core"; +import { en } from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { BlockNoteView } from "@blocknote/mantine"; import "@blocknote/mantine/style.css"; @@ -6,7 +6,7 @@ import { useCreateBlockNote } from "@blocknote/react"; export default function App() { // We use the English, default dictionary - const locale = locales["en"]; + const locale = en; // Creates a new editor instance. const editor = useCreateBlockNote({ diff --git a/packages/core/src/i18n/index.ts b/packages/core/src/i18n/index.ts index 2a04b0f9cb..79b741643b 100644 --- a/packages/core/src/i18n/index.ts +++ b/packages/core/src/i18n/index.ts @@ -1,2 +1,3 @@ export * as locales from "./locales/index.js"; +export * from "./locales/index.js"; export * from "./dictionary.js"; From f9b8cb9a56039a2057ce8a25d74721ee8f5dcec5 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Mon, 24 Mar 2025 15:49:54 +0100 Subject: [PATCH 3/5] chore: update example to show usage --- examples/01-basic/10-localization/App.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/01-basic/10-localization/App.tsx b/examples/01-basic/10-localization/App.tsx index 7f966069ae..7000c3e436 100644 --- a/examples/01-basic/10-localization/App.tsx +++ b/examples/01-basic/10-localization/App.tsx @@ -1,4 +1,4 @@ -import { locales } from "@blocknote/core/locales"; +import { nl } from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { BlockNoteView } from "@blocknote/mantine"; import "@blocknote/mantine/style.css"; @@ -12,7 +12,7 @@ export default function App() { // Passes the Dutch (NL) dictionary to the editor instance. // You can also provide your own dictionary here to customize the strings used in the editor, // or submit a Pull Request to add support for your language of your choice - dictionary: locales.nl, + dictionary: nl, // dictionary: locales[lang as keyof typeof locales], // Use the language from the i18n library dynamically }); From a7308cb0d1996685c1b4ec3efa988d185d222f5e Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Mon, 24 Mar 2025 22:20:12 +0100 Subject: [PATCH 4/5] chore: fix import --- docs/components/pages/landing/hero/DemoEditor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/components/pages/landing/hero/DemoEditor.tsx b/docs/components/pages/landing/hero/DemoEditor.tsx index 192d4bbf4e..7a035f1219 100644 --- a/docs/components/pages/landing/hero/DemoEditor.tsx +++ b/docs/components/pages/landing/hero/DemoEditor.tsx @@ -2,9 +2,9 @@ import { BlockNoteSchema, combineByGroup, filterSuggestionItems, - locales, uploadToTmpFilesDotOrg_DEV_ONLY, } from "@blocknote/core"; +import { locales } from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { getDefaultReactSlashMenuItems, From 3da71223d6cbd8375e5810f7a035a2a4e4ae9b91 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Tue, 25 Mar 2025 09:14:53 +0100 Subject: [PATCH 5/5] refactor: remove `locales` export --- docs/components/pages/landing/hero/DemoEditor.tsx | 2 +- examples/01-basic/03-multi-column/App.tsx | 2 +- packages/core/src/i18n/index.ts | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/components/pages/landing/hero/DemoEditor.tsx b/docs/components/pages/landing/hero/DemoEditor.tsx index 7a035f1219..9919e2ce19 100644 --- a/docs/components/pages/landing/hero/DemoEditor.tsx +++ b/docs/components/pages/landing/hero/DemoEditor.tsx @@ -4,7 +4,7 @@ import { filterSuggestionItems, uploadToTmpFilesDotOrg_DEV_ONLY, } from "@blocknote/core"; -import { locales } from "@blocknote/core/locales"; +import * as locales from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { getDefaultReactSlashMenuItems, diff --git a/examples/01-basic/03-multi-column/App.tsx b/examples/01-basic/03-multi-column/App.tsx index 595f4fac80..b10d9808b5 100644 --- a/examples/01-basic/03-multi-column/App.tsx +++ b/examples/01-basic/03-multi-column/App.tsx @@ -3,7 +3,7 @@ import { combineByGroup, filterSuggestionItems, } from "@blocknote/core"; -import { locales } from "@blocknote/core/locales"; +import * as locales from "@blocknote/core/locales"; import "@blocknote/core/fonts/inter.css"; import { BlockNoteView } from "@blocknote/mantine"; import "@blocknote/mantine/style.css"; diff --git a/packages/core/src/i18n/index.ts b/packages/core/src/i18n/index.ts index 79b741643b..73f53b8826 100644 --- a/packages/core/src/i18n/index.ts +++ b/packages/core/src/i18n/index.ts @@ -1,3 +1,2 @@ -export * as locales from "./locales/index.js"; export * from "./locales/index.js"; export * from "./dictionary.js";