@blocknote/code-block 0.30.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"builtAt":1747749749764,"assets":[{"name":"blocknote-code-block.cjs","size":6844},{"name":"blocknote-code-block.cjs.map","size":14773}],"chunks":[{"id":"a1ee98a","entry":true,"initial":true,"files":["blocknote-code-block.cjs"],"names":["blocknote-code-block"]}],"modules":[{"name":"./src/shiki.bundle.ts","size":4614,"chunks":["a1ee98a"]},{"name":"./src/index.ts","size":3574,"chunks":["a1ee98a"]}]}
1
+ {"builtAt":1747754363170,"assets":[{"name":"blocknote-code-block.cjs","size":6844},{"name":"blocknote-code-block.cjs.map","size":14773}],"chunks":[{"id":"a1ee98a","entry":true,"initial":true,"files":["blocknote-code-block.cjs"],"names":["blocknote-code-block"]}],"modules":[{"name":"./src/shiki.bundle.ts","size":4614,"chunks":["a1ee98a"]},{"name":"./src/index.ts","size":3574,"chunks":["a1ee98a"]}]}
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "directory": "packages/code-block"
10
10
  },
11
11
  "license": "MPL-2.0",
12
- "version": "0.30.1",
12
+ "version": "0.31.0",
13
13
  "files": [
14
14
  "dist",
15
15
  "types",
@@ -42,7 +42,7 @@
42
42
  }
43
43
  },
44
44
  "dependencies": {
45
- "@blocknote/core": "0.30.1",
45
+ "@blocknote/core": "0.31.0",
46
46
  "@shikijs/core": "^3.2.1",
47
47
  "@shikijs/engine-javascript": "^3.2.1",
48
48
  "@shikijs/langs-precompiled": "^3.2.1",
@@ -59,7 +59,7 @@
59
59
  "vitest": "^2.0.3"
60
60
  },
61
61
  "peerDependencies": {
62
- "@blocknote/core": "^0.30.1"
62
+ "@blocknote/core": "^0.31.0"
63
63
  },
64
64
  "eslintConfig": {
65
65
  "extends": [
@@ -0,0 +1,137 @@
1
+ import { Block, BlockNoteEditor, BlockNoteEditorOptions, BlockSchema, DefaultBlockSchema, DefaultInlineContentSchema, DefaultStyleSchema, InlineContentSchema, PartialBlock, StyleSchema } from "@blocknote/core";
2
+ import { Node } from "@tiptap/pm/model";
3
+ import * as React from "react";
4
+ import type * as Y from "yjs";
5
+ /**
6
+ * Use the ServerBlockNoteEditor to interact with BlockNote documents in a server (nodejs) environment.
7
+ */
8
+ export declare class ServerBlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema> {
9
+ /**
10
+ * Internal BlockNoteEditor (not recommended to use directly, use the methods of this class instead)
11
+ */
12
+ readonly editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
13
+ /**
14
+ * We currently use a JSDOM instance to mock document and window methods
15
+ *
16
+ * A possible improvement could be to make this:
17
+ * a) pluggable so other shims can be used as well
18
+ * b) obsolete, but for this all blocks should be React based and we need to remove all references to document / window
19
+ * from the core / react package. (and even then, it's likely some custom blocks would still use document / window methods)
20
+ */
21
+ private jsdom;
22
+ /**
23
+ * Calls a function with mocking window and document using JSDOM
24
+ *
25
+ * We could make this obsolete by passing in a document / window object to the render / serialize methods of Blocks
26
+ */
27
+ _withJSDOM<T>(fn: () => Promise<T>): Promise<T>;
28
+ static create<BSchema extends BlockSchema = DefaultBlockSchema, ISchema extends InlineContentSchema = DefaultInlineContentSchema, SSchema extends StyleSchema = DefaultStyleSchema>(options?: Partial<BlockNoteEditorOptions<BSchema, ISchema, SSchema>>): ServerBlockNoteEditor<BSchema, ISchema, SSchema>;
29
+ protected constructor(options: Partial<BlockNoteEditorOptions<any, any, any>>);
30
+ /** PROSEMIRROR / BLOCKNOTE conversions */
31
+ /**
32
+ * Turn Prosemirror JSON to BlockNote style JSON
33
+ * @param json Prosemirror JSON
34
+ * @returns BlockNote style JSON
35
+ */
36
+ _prosemirrorNodeToBlocks(pmNode: Node): Block<BSchema, InlineContentSchema, StyleSchema>[];
37
+ /**
38
+ * Turn Prosemirror JSON to BlockNote style JSON
39
+ * @param json Prosemirror JSON
40
+ * @returns BlockNote style JSON
41
+ */
42
+ _prosemirrorJSONToBlocks(json: any): Block<BSchema, InlineContentSchema, StyleSchema>[];
43
+ /**
44
+ * Turn BlockNote JSON to Prosemirror node / state
45
+ * @param blocks BlockNote blocks
46
+ * @returns Prosemirror root node
47
+ */
48
+ _blocksToProsemirrorNode(blocks: PartialBlock<BSchema, ISchema, SSchema>[]): Node;
49
+ /** YJS / BLOCKNOTE conversions */
50
+ /**
51
+ * Turn a Y.XmlFragment collaborative doc into a BlockNote document (BlockNote style JSON of all blocks)
52
+ * @returns BlockNote document (BlockNote style JSON of all blocks)
53
+ */
54
+ yXmlFragmentToBlocks(xmlFragment: Y.XmlFragment): Block<BSchema, InlineContentSchema, StyleSchema>[];
55
+ /**
56
+ * Convert blocks to a Y.XmlFragment
57
+ *
58
+ * This can be used when importing existing content to Y.Doc for the first time,
59
+ * note that this should not be used to rehydrate a Y.Doc from a database once
60
+ * collaboration has begun as all history will be lost
61
+ *
62
+ * @param blocks the blocks to convert
63
+ * @returns Y.XmlFragment
64
+ */
65
+ blocksToYXmlFragment(blocks: Block<BSchema, ISchema, SSchema>[], xmlFragment?: Y.XmlFragment): Y.XmlFragment;
66
+ /**
67
+ * Turn a Y.Doc collaborative doc into a BlockNote document (BlockNote style JSON of all blocks)
68
+ * @returns BlockNote document (BlockNote style JSON of all blocks)
69
+ */
70
+ yDocToBlocks(ydoc: Y.Doc, xmlFragment?: string): Block<BSchema, InlineContentSchema, StyleSchema>[];
71
+ /**
72
+ * This can be used when importing existing content to Y.Doc for the first time,
73
+ * note that this should not be used to rehydrate a Y.Doc from a database once
74
+ * collaboration has begun as all history will be lost
75
+ *
76
+ * @param blocks
77
+ */
78
+ blocksToYDoc(blocks: PartialBlock<BSchema, ISchema, SSchema>[], xmlFragment?: string): Y.Doc;
79
+ /** HTML / BLOCKNOTE conversions */
80
+ /**
81
+ * Exports blocks into a simplified HTML string. To better conform to HTML standards, children of blocks which aren't list
82
+ * items are un-nested in the output HTML.
83
+ *
84
+ * @param blocks An array of blocks that should be serialized into HTML.
85
+ * @returns The blocks, serialized as an HTML string.
86
+ */
87
+ blocksToHTMLLossy(blocks: PartialBlock<BSchema, ISchema, SSchema>[]): Promise<string>;
88
+ /**
89
+ * Serializes blocks into an HTML string in the format that would normally be rendered by the editor.
90
+ *
91
+ * Use this method if you want to server-side render HTML (for example, a blog post that has been edited in BlockNote)
92
+ * and serve it to users without loading the editor on the client (i.e.: displaying the blog post)
93
+ *
94
+ * @param blocks An array of blocks that should be serialized into HTML.
95
+ * @returns The blocks, serialized as an HTML string.
96
+ */
97
+ blocksToFullHTML(blocks: PartialBlock<BSchema, ISchema, SSchema>[]): Promise<string>;
98
+ /**
99
+ * Parses blocks from an HTML string. Tries to create `Block` objects out of any HTML block-level elements, and
100
+ * `InlineNode` objects from any HTML inline elements, though not all element types are recognized. If BlockNote
101
+ * doesn't recognize an HTML element's tag, it will parse it as a paragraph or plain text.
102
+ * @param html The HTML string to parse blocks from.
103
+ * @returns The blocks parsed from the HTML string.
104
+ */
105
+ tryParseHTMLToBlocks(html: string): Promise<Block<BSchema, ISchema, SSchema>[]>;
106
+ /** MARKDOWN / BLOCKNOTE conversions */
107
+ /**
108
+ * Serializes blocks into a Markdown string. The output is simplified as Markdown does not support all features of
109
+ * BlockNote - children of blocks which aren't list items are un-nested and certain styles are removed.
110
+ * @param blocks An array of blocks that should be serialized into Markdown.
111
+ * @returns The blocks, serialized as a Markdown string.
112
+ */
113
+ blocksToMarkdownLossy(blocks: PartialBlock<BSchema, ISchema, SSchema>[]): Promise<string>;
114
+ /**
115
+ * Creates a list of blocks from a Markdown string. Tries to create `Block` and `InlineNode` objects based on
116
+ * Markdown syntax, though not all symbols are recognized. If BlockNote doesn't recognize a symbol, it will parse it
117
+ * as text.
118
+ * @param markdown The Markdown string to parse blocks from.
119
+ * @returns The blocks parsed from the Markdown string.
120
+ */
121
+ tryParseMarkdownToBlocks(markdown: string): Promise<Block<BSchema, ISchema, SSchema>[]>;
122
+ /**
123
+ * If you're using React Context in your blocks, you can use this method to wrap editor calls for importing / exporting / block manipulation
124
+ * with the React Context Provider.
125
+ *
126
+ * Example:
127
+ *
128
+ * ```tsx
129
+ const html = await editor.withReactContext(
130
+ ({ children }) => (
131
+ <YourContext.Provider value={true}>{children}</YourContext.Provider>
132
+ ),
133
+ async () => editor.blocksToFullHTML(blocks)
134
+ );
135
+ */
136
+ withReactContext<T>(comp: React.FC<any>, fn: () => Promise<T>): Promise<T>;
137
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const TestContext: import("react").Context<true | undefined>;