Skip to content

Commit 95c493a

Browse files
committed
build: get build working again with better types
1 parent 17398cc commit 95c493a

File tree

7 files changed

+127
-82
lines changed

7 files changed

+127
-82
lines changed

examples/05-interoperability/07-converting-blocks-to-odt/src/App.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
BlockNoteSchema,
33
combineByGroup,
4-
createPageBreakBlockSpec,
4+
withPageBreak,
55
filterSuggestionItems,
66
} from "@blocknote/core";
77
import * as locales from "@blocknote/core/locales";
@@ -22,8 +22,7 @@ import {
2222
getMultiColumnSlashMenuItems,
2323
multiColumnDropCursor,
2424
locales as multiColumnLocales,
25-
ColumnBlock,
26-
ColumnListBlock,
25+
withMultiColumn,
2726
} from "@blocknote/xl-multi-column";
2827
import { useMemo } from "react";
2928

@@ -32,15 +31,7 @@ import "./styles.css";
3231
export default function App() {
3332
// Creates a new editor instance with some initial content.
3433
const editor = useCreateBlockNote({
35-
schema: (
36-
BlockNoteSchema.create().extend({
37-
blockSpecs: {
38-
pageBreak: createPageBreakBlockSpec(),
39-
column: ColumnBlock,
40-
columnList: ColumnListBlock,
41-
},
42-
}),
43-
),
34+
schema: withMultiColumn(withPageBreak(BlockNoteSchema.create())),
4435
dropCursor: multiColumnDropCursor,
4536
dictionary: {
4637
...locales.en,

packages/core/src/blocks/PageBreak/block.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
1+
import {
2+
BlockSchema,
3+
createBlockConfig,
4+
createBlockSpec,
5+
InlineContentSchema,
6+
StyleSchema,
7+
} from "../../schema/index.js";
8+
import { BlockNoteSchema } from "../BlockNoteSchema.js";
29

310
export const createPageBreakBlockConfig = createBlockConfig(
411
() =>
@@ -43,3 +50,20 @@ export const createPageBreakBlockSpec = createBlockSpec(
4350
},
4451
},
4552
);
53+
54+
/**
55+
* Adds multi-column support to the given schema.
56+
*/
57+
export const withPageBreak = <
58+
B extends BlockSchema,
59+
I extends InlineContentSchema,
60+
S extends StyleSchema,
61+
>(
62+
schema: BlockNoteSchema<B, I, S>,
63+
) => {
64+
return schema.extend({
65+
blockSpecs: {
66+
pageBreak: createPageBreakBlockSpec(),
67+
},
68+
});
69+
};

packages/core/src/schema/blocks/createSpec.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,31 @@ export function createBlockConfig<
287287
* Can accept either functions that return the required objects, or the objects directly.
288288
*/
289289
export function createBlockSpec<
290-
TName extends string,
291-
TProps extends PropSchema,
292-
TContent extends "inline" | "none",
293-
BlockConf extends BlockConfig<TName, TProps, TContent>,
294-
TOptions extends Partial<Record<string, any>>,
290+
const TName extends string,
291+
const TProps extends PropSchema,
292+
const TContent extends "inline" | "none",
293+
const TOptions extends Partial<Record<string, any>> | undefined = undefined,
294+
>(
295+
blockConfigOrCreator: BlockConfig<TName, TProps, TContent>,
296+
blockImplementationOrCreator:
297+
| BlockImplementation<TName, TProps, TContent>
298+
| (TOptions extends undefined
299+
? () => BlockImplementation<TName, TProps, TContent>
300+
: (
301+
options: Partial<TOptions>,
302+
) => BlockImplementation<TName, TProps, TContent>),
303+
extensionsOrCreator?:
304+
| BlockNoteExtension<any>[]
305+
| (TOptions extends undefined
306+
? () => BlockNoteExtension<any>[]
307+
: (options: Partial<TOptions>) => BlockNoteExtension<any>[]),
308+
): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent>;
309+
export function createBlockSpec<
310+
const TName extends string,
311+
const TProps extends PropSchema,
312+
const TContent extends "inline" | "none",
313+
const BlockConf extends BlockConfig<TName, TProps, TContent>,
314+
const TOptions extends Partial<Record<string, any>>,
295315
>(
296316
blockCreator: (options: Partial<TOptions>) => BlockConf,
297317
blockImplementationOrCreator:
@@ -307,7 +327,7 @@ export function createBlockSpec<
307327
BlockConf["content"]
308328
>
309329
: (
310-
options: TOptions,
330+
options: Partial<TOptions>,
311331
) => BlockImplementation<
312332
BlockConf["type"],
313333
BlockConf["propSchema"],
@@ -317,19 +337,19 @@ export function createBlockSpec<
317337
| BlockNoteExtension<any>[]
318338
| (TOptions extends undefined
319339
? () => BlockNoteExtension<any>[]
320-
: (options: TOptions) => BlockNoteExtension<any>[]),
340+
: (options: Partial<TOptions>) => BlockNoteExtension<any>[]),
321341
): (
322-
options?: TOptions,
342+
options?: Partial<TOptions>,
323343
) => BlockSpec<
324344
BlockConf["type"],
325345
BlockConf["propSchema"],
326346
BlockConf["content"]
327347
>;
328348
export function createBlockSpec<
329-
TName extends string,
330-
TProps extends PropSchema,
331-
TContent extends "inline" | "none",
332-
TOptions extends Partial<Record<string, any>> | undefined = undefined,
349+
const TName extends string,
350+
const TProps extends PropSchema,
351+
const TContent extends "inline" | "none",
352+
const TOptions extends Partial<Record<string, any>> | undefined = undefined,
333353
>(
334354
blockConfigOrCreator:
335355
| BlockConfig<TName, TProps, TContent>

packages/core/src/schema/schema.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,30 +156,33 @@ export class CustomBlockNoteSchema<
156156
* @returns The current schema instance for chaining
157157
*/
158158
public extend<
159-
AdditionalBlockSpecs extends BlockSpecs,
159+
AdditionalBlockSpecs extends BlockSpecs = Record<string, never>,
160160
AdditionalInlineContentSpecs extends Record<
161161
string,
162162
InlineContentSpec<InlineContentConfig>
163-
>,
164-
AdditionalStyleSpecs extends Record<string, StyleSpec<StyleConfig>>,
163+
> = Record<string, never>,
164+
AdditionalStyleSpecs extends Record<
165+
string,
166+
StyleSpec<StyleConfig>
167+
> = Record<string, never>,
165168
>(opts: {
166169
blockSpecs?: AdditionalBlockSpecs;
167170
inlineContentSpecs?: AdditionalInlineContentSpecs;
168171
styleSpecs?: AdditionalStyleSpecs;
169172
}): CustomBlockNoteSchema<
170-
AdditionalBlockSpecs extends undefined
173+
AdditionalBlockSpecs extends undefined | Record<string, never>
171174
? BSchema
172175
: BSchema & {
173176
[K in keyof AdditionalBlockSpecs]: K extends string
174177
? AdditionalBlockSpecs[K]["config"]
175178
: never;
176179
},
177-
AdditionalInlineContentSpecs extends undefined
180+
AdditionalInlineContentSpecs extends undefined | Record<string, never>
178181
? ISchema
179182
: ISchema & {
180183
[K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K]["config"];
181184
},
182-
AdditionalStyleSpecs extends undefined
185+
AdditionalStyleSpecs extends undefined | Record<string, never>
183186
? SSchema
184187
: SSchema & {
185188
[K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K]["config"];

packages/react/src/schema/ReactBlockSpec.tsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,31 @@ export function BlockContentWrapper<
122122
* Can accept either functions that return the required objects, or the objects directly.
123123
*/
124124
export function createReactBlockSpec<
125-
TName extends string,
126-
TProps extends PropSchema,
127-
TContent extends "inline" | "none",
128-
BlockConf extends BlockConfig<TName, TProps, TContent>,
129-
TOptions extends Partial<Record<string, any>>,
125+
const TName extends string,
126+
const TProps extends PropSchema,
127+
const TContent extends "inline" | "none",
128+
const TOptions extends Record<string, any> | undefined = undefined,
129+
>(
130+
blockConfigOrCreator: BlockConfig<TName, TProps, TContent>,
131+
blockImplementationOrCreator:
132+
| ReactCustomBlockImplementation<TName, TProps, TContent>
133+
| (TOptions extends undefined
134+
? () => ReactCustomBlockImplementation<TName, TProps, TContent>
135+
: (
136+
options: Partial<TOptions>,
137+
) => ReactCustomBlockImplementation<TName, TProps, TContent>),
138+
extensionsOrCreator?:
139+
| BlockNoteExtension<any>[]
140+
| (TOptions extends undefined
141+
? () => BlockNoteExtension<any>[]
142+
: (options: Partial<TOptions>) => BlockNoteExtension<any>[]),
143+
): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent>;
144+
export function createReactBlockSpec<
145+
const TName extends string,
146+
const TProps extends PropSchema,
147+
const TContent extends "inline" | "none",
148+
const BlockConf extends BlockConfig<TName, TProps, TContent>,
149+
const TOptions extends Partial<Record<string, any>>,
130150
>(
131151
blockCreator: (options: Partial<TOptions>) => BlockConf,
132152
blockImplementationOrCreator:
@@ -142,7 +162,7 @@ export function createReactBlockSpec<
142162
BlockConf["content"]
143163
>
144164
: (
145-
options: TOptions,
165+
options: Partial<TOptions>,
146166
) => ReactCustomBlockImplementation<
147167
BlockConf["type"],
148168
BlockConf["propSchema"],
@@ -152,19 +172,19 @@ export function createReactBlockSpec<
152172
| BlockNoteExtension<any>[]
153173
| (TOptions extends undefined
154174
? () => BlockNoteExtension<any>[]
155-
: (options: TOptions) => BlockNoteExtension<any>[]),
175+
: (options: Partial<TOptions>) => BlockNoteExtension<any>[]),
156176
): (
157-
options?: TOptions,
177+
options?: Partial<TOptions>,
158178
) => BlockSpec<
159179
BlockConf["type"],
160180
BlockConf["propSchema"],
161181
BlockConf["content"]
162182
>;
163183
export function createReactBlockSpec<
164-
TName extends string,
165-
TProps extends PropSchema,
166-
TContent extends "inline" | "none",
167-
TOptions extends Record<string, any> | undefined = undefined,
184+
const TName extends string,
185+
const TProps extends PropSchema,
186+
const TContent extends "inline" | "none",
187+
const TOptions extends Record<string, any> | undefined = undefined,
168188
>(
169189
blockConfigOrCreator:
170190
| BlockConfig<TName, TProps, TContent>
@@ -183,7 +203,7 @@ export function createReactBlockSpec<
183203
| (TOptions extends undefined
184204
? () => BlockNoteExtension<any>[]
185205
: (options: Partial<TOptions>) => BlockNoteExtension<any>[]),
186-
): (options?: TOptions) => BlockSpec<TName, TProps, TContent> {
206+
): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent> {
187207
return (options = {} as TOptions) => {
188208
const blockConfig =
189209
typeof blockConfigOrCreator === "function"

packages/xl-ai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"prosemirror-state": "^1.4.3",
7878
"prosemirror-tables": "^1.6.4",
7979
"prosemirror-transform": "^1.10.4",
80-
"prosemirror-view": "^1.33.7",
80+
"prosemirror-view": "^1.40.1",
8181
"react": "^19.1.0",
8282
"react-dom": "^19.1.0",
8383
"react-icons": "^5.2.1",

0 commit comments

Comments
 (0)