Skip to content

Commit d41a572

Browse files
authored
refactor: remove initializeESMDependencies kludge (#1962)
1 parent a5a0871 commit d41a572

File tree

26 files changed

+766
-1719
lines changed

26 files changed

+766
-1719
lines changed

docs/next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const config = {
99
serverExternalPackages: ["typescript", "twoslash"],
1010
experimental: {
1111
reactCompiler: true,
12+
turbopackScopeHoisting: false,
1213
},
1314
images: {
1415
remotePatterns: [

docs/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
"@fumadocs/mdx-remote": "1.3.0",
3636
"@headlessui/react": "^1.7.19",
3737
"@heroicons/react": "^2.2.0",
38-
"@liveblocks/client": "^2.23.1",
39-
"@liveblocks/react": "^2.23.1",
40-
"@liveblocks/react-blocknote": "^2.23.1",
41-
"@liveblocks/react-tiptap": "^2.23.1",
42-
"@liveblocks/react-ui": "^2.23.1",
38+
"@liveblocks/client": "^3",
39+
"@liveblocks/react": "^3",
40+
"@liveblocks/react-blocknote": "^3",
41+
"@liveblocks/react-tiptap": "^3",
42+
"@liveblocks/react-ui": "^3",
4343
"@mantine/core": "^7.17.3",
4444
"@mui/icons-material": "^5.16.1",
4545
"@mui/material": "^5.16.1",

examples/07-collaboration/02-liveblocks/.bnexample.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"author": "yousefed",
55
"tags": ["Advanced", "Saving/Loading", "Collaboration"],
66
"dependencies": {
7-
"@liveblocks/client": "^2.23.1",
8-
"@liveblocks/react": "^2.23.1",
9-
"@liveblocks/react-blocknote": "^2.23.1",
10-
"@liveblocks/react-tiptap": "^2.23.1",
11-
"@liveblocks/react-ui": "^2.23.1",
7+
"@liveblocks/client": "^3",
8+
"@liveblocks/react": "^3",
9+
"@liveblocks/react-blocknote": "^3",
10+
"@liveblocks/react-tiptap": "^3",
11+
"@liveblocks/react-ui": "^3",
1212
"yjs": "^13.6.27"
1313
}
1414
}

examples/07-collaboration/02-liveblocks/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"@blocknote/shadcn": "latest",
1818
"react": "^19.1.0",
1919
"react-dom": "^19.1.0",
20-
"@liveblocks/client": "^2.23.1",
21-
"@liveblocks/react": "^2.23.1",
22-
"@liveblocks/react-blocknote": "^2.23.1",
23-
"@liveblocks/react-tiptap": "^2.23.1",
24-
"@liveblocks/react-ui": "^2.23.1",
20+
"@liveblocks/client": "^3",
21+
"@liveblocks/react": "^3",
22+
"@liveblocks/react-blocknote": "^3",
23+
"@liveblocks/react-tiptap": "^3",
24+
"@liveblocks/react-ui": "^3",
2525
"yjs": "^13.6.27"
2626
},
2727
"devDependencies": {

packages/core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,21 @@
103103
"prosemirror-view": "^1.38.1",
104104
"rehype-format": "^5.0.1",
105105
"rehype-parse": "^9.0.1",
106-
"rehype-remark": "^10.0.0",
106+
"rehype-remark": "^10.0.1",
107107
"rehype-stringify": "^10.0.1",
108108
"remark-gfm": "^4.0.1",
109109
"remark-parse": "^11.0.0",
110-
"remark-rehype": "^11.1.1",
110+
"remark-rehype": "^11.1.2",
111111
"remark-stringify": "^11.0.0",
112112
"unified": "^11.0.5",
113113
"uuid": "^8.3.2",
114-
"y-prosemirror": "^1.3.4",
114+
"y-prosemirror": "^1.3.7",
115115
"y-protocols": "^1.0.6",
116116
"yjs": "^13.6.27"
117117
},
118118
"devDependencies": {
119119
"@types/emoji-mart": "^3.0.14",
120-
"@types/hast": "^3.0.0",
120+
"@types/hast": "^3.0.4",
121121
"@types/uuid": "^8.3.4",
122122
"eslint": "^8.10.0",
123123
"jsdom": "^25.0.1",

packages/core/src/api/clipboard/toClipboard/copyExtension.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
contentNodeToInlineContent,
1818
contentNodeToTableContent,
1919
} from "../../nodeConversions/nodeToBlock.js";
20-
import { initializeESMDependencies } from "../../../util/esmDependencies.js";
2120

2221
function fragmentToExternalHTML<
2322
BSchema extends BlockSchema,
@@ -209,7 +208,6 @@ export const createCopyToClipboardExtension = <
209208
Extension.create<{ editor: BlockNoteEditor<BSchema, I, S> }, undefined>({
210209
name: "copyToClipboard",
211210
addProseMirrorPlugins() {
212-
initializeESMDependencies();
213211
return [
214212
new Plugin({
215213
props: {

packages/core/src/api/exporters/html/externalHTMLExporter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import {
2828
// 4. The HTML is wrapped in a single `div` element.
2929

3030
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
31-
// Ideally, call `await initializeESMDependencies()` before calling this function
3231
export const createExternalHTMLExporter = <
3332
BSchema extends BlockSchema,
3433
I extends InlineContentSchema,

packages/core/src/api/exporters/markdown/markdownExporter.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
import { Schema } from "prosemirror-model";
2+
import rehypeParse from "rehype-parse";
3+
import rehypeRemark from "rehype-remark";
4+
import remarkGfm from "remark-gfm";
5+
import remarkStringify from "remark-stringify";
6+
import { unified } from "unified";
7+
28
import { PartialBlock } from "../../../blocks/defaultBlocks.js";
39
import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
410
import {
511
BlockSchema,
612
InlineContentSchema,
713
StyleSchema,
814
} from "../../../schema/index.js";
9-
import {
10-
esmDependencies,
11-
initializeESMDependencies,
12-
} from "../../../util/esmDependencies.js";
1315
import { createExternalHTMLExporter } from "../html/externalHTMLExporter.js";
1416
import { removeUnderlines } from "./removeUnderlinesRehypePlugin.js";
1517
import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin.js";
1618

1719
// Needs to be sync because it's used in drag handler event (SideMenuPlugin)
18-
// Ideally, call `await initializeESMDependencies()` before calling this function
1920
export function cleanHTMLToMarkdown(cleanHTMLString: string) {
20-
const deps = esmDependencies;
21-
22-
if (!deps) {
23-
throw new Error(
24-
"cleanHTMLToMarkdown requires ESM dependencies to be initialized",
25-
);
26-
}
27-
28-
const markdownString = deps.unified
29-
.unified()
30-
.use(deps.rehypeParse.default, { fragment: true })
21+
const markdownString = unified()
22+
.use(rehypeParse, { fragment: true })
3123
.use(removeUnderlines)
3224
.use(addSpacesToCheckboxes)
33-
.use(deps.rehypeRemark.default)
34-
.use(deps.remarkGfm.default)
35-
.use(deps.remarkStringify.default, {
25+
.use(rehypeRemark)
26+
.use(remarkGfm)
27+
.use(remarkStringify, {
3628
handlers: { text: (node) => node.value },
3729
})
3830
.processSync(cleanHTMLString);
@@ -50,7 +42,6 @@ export async function blocksToMarkdown<
5042
editor: BlockNoteEditor<BSchema, I, S>,
5143
options: { document?: Document },
5244
): Promise<string> {
53-
await initializeESMDependencies();
5445
const exporter = createExternalHTMLExporter(schema, editor);
5546
const externalHTML = exporter.exportBlocks(blocks, options);
5647

packages/core/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
import { Element as HASTElement, Parent as HASTParent } from "hast";
2-
import { esmDependencies } from "../../../../util/esmDependencies.js";
2+
import { fromDom } from "hast-util-from-dom";
33

44
/**
55
* Rehype plugin which adds a space after each checkbox input element. This is
66
* because remark doesn't add any spaces between the checkbox input and the text
77
* itself, but these are needed for correct Markdown syntax.
88
*/
99
export function addSpacesToCheckboxes() {
10-
const deps = esmDependencies;
11-
12-
if (!deps) {
13-
throw new Error(
14-
"addSpacesToCheckboxes requires ESM dependencies to be initialized",
15-
);
16-
}
17-
1810
const helper = (tree: HASTParent) => {
1911
if (tree.children && "length" in tree.children && tree.children.length) {
2012
for (let i = tree.children.length - 1; i >= 0; i--) {
@@ -37,9 +29,7 @@ export function addSpacesToCheckboxes() {
3729
nextChild.children.splice(
3830
0,
3931
0,
40-
deps.hastUtilFromDom.fromDom(
41-
document.createTextNode(" "),
42-
) as HASTElement,
32+
fromDom(document.createTextNode(" ")) as HASTElement,
4333
);
4434
} else {
4535
helper(child as HASTParent);

packages/core/src/api/parsers/html/parseHTML.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
import { Block } from "../../../blocks/defaultBlocks.js";
99
import { nodeToBlock } from "../../nodeConversions/nodeToBlock.js";
1010
import { nestedListsToBlockNoteStructure } from "./util/nestedLists.js";
11-
export async function HTMLToBlocks<
11+
export function HTMLToBlocks<
1212
BSchema extends BlockSchema,
1313
I extends InlineContentSchema,
1414
S extends StyleSchema,
15-
>(html: string, pmSchema: Schema): Promise<Block<BSchema, I, S>[]> {
15+
>(html: string, pmSchema: Schema): Block<BSchema, I, S>[] {
1616
const htmlNode = nestedListsToBlockNoteStructure(html);
1717
const parser = DOMParser.fromSchema(pmSchema);
1818

0 commit comments

Comments
 (0)