@blocknote/core 0.7.1-alpha.0 → 0.8.1
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.
- package/dist/blocknote.js +1711 -1469
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +6 -2
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +3 -3
- package/src/BlockNoteEditor.ts +104 -53
- package/src/BlockNoteExtensions.ts +24 -14
- package/src/api/blockManipulation/blockManipulation.test.ts +6 -3
- package/src/api/blockManipulation/blockManipulation.ts +7 -6
- package/src/api/formatConversions/formatConversions.test.ts +13 -8
- package/src/api/formatConversions/formatConversions.ts +15 -12
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +292 -0
- package/src/api/nodeConversions/nodeConversions.test.ts +265 -10
- package/src/api/nodeConversions/nodeConversions.ts +199 -47
- package/src/api/nodeConversions/testUtil.ts +8 -4
- package/src/editor.module.css +5 -6
- package/src/extensions/Blocks/api/block.ts +229 -0
- package/src/extensions/Blocks/api/blockTypes.ts +158 -71
- package/src/extensions/Blocks/api/cursorPositionTypes.ts +5 -5
- package/src/extensions/Blocks/api/defaultBlocks.ts +44 -0
- package/src/extensions/Blocks/api/selectionTypes.ts +3 -3
- package/src/extensions/Blocks/api/serialization.ts +29 -0
- package/src/extensions/Blocks/index.ts +0 -8
- package/src/extensions/Blocks/nodes/Block.module.css +28 -16
- package/src/extensions/Blocks/nodes/BlockContainer.ts +8 -4
- package/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.ts +4 -4
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -5
- package/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +100 -97
- package/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.ts +4 -4
- package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +11 -9
- package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +6 -5
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +57 -14
- package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +21 -16
- package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +9 -5
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +38 -58
- package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +19 -0
- package/src/extensions/Placeholder/PlaceholderExtension.ts +1 -0
- package/src/extensions/SlashMenu/BaseSlashMenuItem.ts +5 -2
- package/src/extensions/SlashMenu/SlashMenuExtension.ts +37 -33
- package/src/extensions/SlashMenu/defaultSlashMenuItems.tsx +14 -10
- package/src/extensions/SlashMenu/index.ts +2 -2
- package/src/index.ts +4 -0
- package/src/shared/plugins/suggestion/SuggestionPlugin.ts +29 -13
- package/types/src/BlockNoteEditor.d.ts +38 -23
- package/types/src/BlockNoteExtensions.d.ts +15 -8
- package/types/src/api/blockManipulation/blockManipulation.d.ts +4 -4
- package/types/src/api/formatConversions/formatConversions.d.ts +5 -5
- package/types/src/api/nodeConversions/nodeConversions.d.ts +3 -3
- package/types/src/api/nodeConversions/testUtil.d.ts +2 -2
- package/types/src/extensions/Blocks/api/block.d.ts +2 -4
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +77 -33
- package/types/src/extensions/Blocks/api/cursorPositionTypes.d.ts +5 -5
- package/types/src/extensions/Blocks/api/defaultBlocks.d.ts +4 -4
- package/types/src/extensions/Blocks/api/selectionTypes.d.ts +3 -3
- package/types/src/extensions/Blocks/api/serialization.d.ts +2 -0
- package/types/src/extensions/Blocks/nodes/BlockContainer.d.ts +3 -3
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContent.d.ts +1 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +1 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +1 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContent.d.ts +1 -2
- package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +7 -7
- package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +5 -4
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +12 -11
- package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +6 -5
- package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +4 -3
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +16 -19
- package/types/src/extensions/Placeholder/localisation/index.d.ts +2 -0
- package/types/src/extensions/Placeholder/localisation/translation.d.ts +51 -0
- package/types/src/extensions/SlashMenu/BaseSlashMenuItem.d.ts +4 -3
- package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +5 -4
- package/types/src/extensions/SlashMenu/defaultSlashMenuItems.d.ts +66 -1
- package/types/src/extensions/SlashMenu/index.d.ts +2 -2
- package/types/src/index.d.ts +4 -0
- package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +5 -4
- package/types/src/extensions/Blocks/api/alertBlock.d.ts +0 -13
- package/types/src/extensions/Blocks/api/alertBlock2.d.ts +0 -13
|
@@ -7,13 +7,14 @@ import remarkParse from "remark-parse";
|
|
|
7
7
|
import remarkRehype from "remark-rehype";
|
|
8
8
|
import remarkStringify from "remark-stringify";
|
|
9
9
|
import { unified } from "unified";
|
|
10
|
-
import { Block } from "../../extensions/Blocks/api/blockTypes";
|
|
10
|
+
import { Block, BlockSchema } from "../../extensions/Blocks/api/blockTypes";
|
|
11
|
+
|
|
11
12
|
import { blockToNode, nodeToBlock } from "../nodeConversions/nodeConversions";
|
|
12
13
|
import { removeUnderlines } from "./removeUnderlinesRehypePlugin";
|
|
13
14
|
import { simplifyBlocks } from "./simplifyBlocksRehypePlugin";
|
|
14
15
|
|
|
15
|
-
export async function blocksToHTML(
|
|
16
|
-
blocks: Block[],
|
|
16
|
+
export async function blocksToHTML<BSchema extends BlockSchema>(
|
|
17
|
+
blocks: Block<BSchema>[],
|
|
17
18
|
schema: Schema
|
|
18
19
|
): Promise<string> {
|
|
19
20
|
const htmlParentElement = document.createElement("div");
|
|
@@ -37,27 +38,28 @@ export async function blocksToHTML(
|
|
|
37
38
|
return htmlString.value as string;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export async function HTMLToBlocks(
|
|
41
|
+
export async function HTMLToBlocks<BSchema extends BlockSchema>(
|
|
41
42
|
html: string,
|
|
43
|
+
blockSchema: BSchema,
|
|
42
44
|
schema: Schema
|
|
43
|
-
): Promise<Block[]> {
|
|
45
|
+
): Promise<Block<BSchema>[]> {
|
|
44
46
|
const htmlNode = document.createElement("div");
|
|
45
47
|
htmlNode.innerHTML = html.trim();
|
|
46
48
|
|
|
47
49
|
const parser = DOMParser.fromSchema(schema);
|
|
48
50
|
const parentNode = parser.parse(htmlNode);
|
|
49
51
|
|
|
50
|
-
const blocks: Block[] = [];
|
|
52
|
+
const blocks: Block<BSchema>[] = [];
|
|
51
53
|
|
|
52
54
|
for (let i = 0; i < parentNode.firstChild!.childCount; i++) {
|
|
53
|
-
blocks.push(nodeToBlock(parentNode.firstChild!.child(i)));
|
|
55
|
+
blocks.push(nodeToBlock(parentNode.firstChild!.child(i), blockSchema));
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
return blocks;
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
export async function blocksToMarkdown(
|
|
60
|
-
blocks: Block[],
|
|
61
|
+
export async function blocksToMarkdown<BSchema extends BlockSchema>(
|
|
62
|
+
blocks: Block<BSchema>[],
|
|
61
63
|
schema: Schema
|
|
62
64
|
): Promise<string> {
|
|
63
65
|
const markdownString = await unified()
|
|
@@ -71,10 +73,11 @@ export async function blocksToMarkdown(
|
|
|
71
73
|
return markdownString.value as string;
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
export async function markdownToBlocks(
|
|
76
|
+
export async function markdownToBlocks<BSchema extends BlockSchema>(
|
|
75
77
|
markdown: string,
|
|
78
|
+
blockSchema: BSchema,
|
|
76
79
|
schema: Schema
|
|
77
|
-
): Promise<Block[]> {
|
|
80
|
+
): Promise<Block<BSchema>[]> {
|
|
78
81
|
const htmlString = await unified()
|
|
79
82
|
.use(remarkParse)
|
|
80
83
|
.use(remarkGfm)
|
|
@@ -82,5 +85,5 @@ export async function markdownToBlocks(
|
|
|
82
85
|
.use(rehypeStringify)
|
|
83
86
|
.process(markdown);
|
|
84
87
|
|
|
85
|
-
return HTMLToBlocks(htmlString.value as string, schema);
|
|
88
|
+
return HTMLToBlocks(htmlString.value as string, blockSchema, schema);
|
|
86
89
|
}
|
|
@@ -183,6 +183,298 @@ exports[`Simple ProseMirror Node Conversions > Convert simple node to block 1`]
|
|
|
183
183
|
}
|
|
184
184
|
`;
|
|
185
185
|
|
|
186
|
+
exports[`hard breaks > Convert a block with a hard break 1`] = `
|
|
187
|
+
{
|
|
188
|
+
"attrs": {
|
|
189
|
+
"backgroundColor": "default",
|
|
190
|
+
"id": "4",
|
|
191
|
+
"textColor": "default",
|
|
192
|
+
},
|
|
193
|
+
"content": [
|
|
194
|
+
{
|
|
195
|
+
"attrs": {
|
|
196
|
+
"textAlignment": "left",
|
|
197
|
+
},
|
|
198
|
+
"content": [
|
|
199
|
+
{
|
|
200
|
+
"text": "Text1",
|
|
201
|
+
"type": "text",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"type": "hardBreak",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"text": "Text2",
|
|
208
|
+
"type": "text",
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
"type": "paragraph",
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
"type": "blockContainer",
|
|
215
|
+
}
|
|
216
|
+
`;
|
|
217
|
+
|
|
218
|
+
exports[`hard breaks > Convert a block with a hard break and different styles 1`] = `
|
|
219
|
+
{
|
|
220
|
+
"attrs": {
|
|
221
|
+
"backgroundColor": "default",
|
|
222
|
+
"id": "4",
|
|
223
|
+
"textColor": "default",
|
|
224
|
+
},
|
|
225
|
+
"content": [
|
|
226
|
+
{
|
|
227
|
+
"attrs": {
|
|
228
|
+
"textAlignment": "left",
|
|
229
|
+
},
|
|
230
|
+
"content": [
|
|
231
|
+
{
|
|
232
|
+
"text": "Text1",
|
|
233
|
+
"type": "text",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"type": "hardBreak",
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"marks": [
|
|
240
|
+
{
|
|
241
|
+
"type": "bold",
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
"text": "Text2",
|
|
245
|
+
"type": "text",
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
"type": "paragraph",
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
"type": "blockContainer",
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
exports[`hard breaks > Convert a block with a hard break at the end 1`] = `
|
|
256
|
+
{
|
|
257
|
+
"attrs": {
|
|
258
|
+
"backgroundColor": "default",
|
|
259
|
+
"id": "4",
|
|
260
|
+
"textColor": "default",
|
|
261
|
+
},
|
|
262
|
+
"content": [
|
|
263
|
+
{
|
|
264
|
+
"attrs": {
|
|
265
|
+
"textAlignment": "left",
|
|
266
|
+
},
|
|
267
|
+
"content": [
|
|
268
|
+
{
|
|
269
|
+
"text": "Text1",
|
|
270
|
+
"type": "text",
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
"type": "hardBreak",
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
"type": "paragraph",
|
|
277
|
+
},
|
|
278
|
+
],
|
|
279
|
+
"type": "blockContainer",
|
|
280
|
+
}
|
|
281
|
+
`;
|
|
282
|
+
|
|
283
|
+
exports[`hard breaks > Convert a block with a hard break at the start 1`] = `
|
|
284
|
+
{
|
|
285
|
+
"attrs": {
|
|
286
|
+
"backgroundColor": "default",
|
|
287
|
+
"id": "4",
|
|
288
|
+
"textColor": "default",
|
|
289
|
+
},
|
|
290
|
+
"content": [
|
|
291
|
+
{
|
|
292
|
+
"attrs": {
|
|
293
|
+
"textAlignment": "left",
|
|
294
|
+
},
|
|
295
|
+
"content": [
|
|
296
|
+
{
|
|
297
|
+
"type": "hardBreak",
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"text": "Text1",
|
|
301
|
+
"type": "text",
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
"type": "paragraph",
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
"type": "blockContainer",
|
|
308
|
+
}
|
|
309
|
+
`;
|
|
310
|
+
|
|
311
|
+
exports[`hard breaks > Convert a block with a hard break between links 1`] = `
|
|
312
|
+
{
|
|
313
|
+
"attrs": {
|
|
314
|
+
"backgroundColor": "default",
|
|
315
|
+
"id": "4",
|
|
316
|
+
"textColor": "default",
|
|
317
|
+
},
|
|
318
|
+
"content": [
|
|
319
|
+
{
|
|
320
|
+
"attrs": {
|
|
321
|
+
"textAlignment": "left",
|
|
322
|
+
},
|
|
323
|
+
"content": [
|
|
324
|
+
{
|
|
325
|
+
"marks": [
|
|
326
|
+
{
|
|
327
|
+
"attrs": {
|
|
328
|
+
"class": null,
|
|
329
|
+
"href": "https://www.website.com",
|
|
330
|
+
"target": "_blank",
|
|
331
|
+
},
|
|
332
|
+
"type": "link",
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
"text": "Link1",
|
|
336
|
+
"type": "text",
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"type": "hardBreak",
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"marks": [
|
|
343
|
+
{
|
|
344
|
+
"attrs": {
|
|
345
|
+
"class": null,
|
|
346
|
+
"href": "https://www.website2.com",
|
|
347
|
+
"target": "_blank",
|
|
348
|
+
},
|
|
349
|
+
"type": "link",
|
|
350
|
+
},
|
|
351
|
+
],
|
|
352
|
+
"text": "Link2",
|
|
353
|
+
"type": "text",
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
"type": "paragraph",
|
|
357
|
+
},
|
|
358
|
+
],
|
|
359
|
+
"type": "blockContainer",
|
|
360
|
+
}
|
|
361
|
+
`;
|
|
362
|
+
|
|
363
|
+
exports[`hard breaks > Convert a block with a hard break in a link 1`] = `
|
|
364
|
+
{
|
|
365
|
+
"attrs": {
|
|
366
|
+
"backgroundColor": "default",
|
|
367
|
+
"id": "4",
|
|
368
|
+
"textColor": "default",
|
|
369
|
+
},
|
|
370
|
+
"content": [
|
|
371
|
+
{
|
|
372
|
+
"attrs": {
|
|
373
|
+
"textAlignment": "left",
|
|
374
|
+
},
|
|
375
|
+
"content": [
|
|
376
|
+
{
|
|
377
|
+
"marks": [
|
|
378
|
+
{
|
|
379
|
+
"attrs": {
|
|
380
|
+
"class": null,
|
|
381
|
+
"href": "https://www.website.com",
|
|
382
|
+
"target": "_blank",
|
|
383
|
+
},
|
|
384
|
+
"type": "link",
|
|
385
|
+
},
|
|
386
|
+
],
|
|
387
|
+
"text": "Link1",
|
|
388
|
+
"type": "text",
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
"type": "hardBreak",
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
"marks": [
|
|
395
|
+
{
|
|
396
|
+
"attrs": {
|
|
397
|
+
"class": null,
|
|
398
|
+
"href": "https://www.website.com",
|
|
399
|
+
"target": "_blank",
|
|
400
|
+
},
|
|
401
|
+
"type": "link",
|
|
402
|
+
},
|
|
403
|
+
],
|
|
404
|
+
"text": "Link1",
|
|
405
|
+
"type": "text",
|
|
406
|
+
},
|
|
407
|
+
],
|
|
408
|
+
"type": "paragraph",
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
"type": "blockContainer",
|
|
412
|
+
}
|
|
413
|
+
`;
|
|
414
|
+
|
|
415
|
+
exports[`hard breaks > Convert a block with multiple hard breaks 1`] = `
|
|
416
|
+
{
|
|
417
|
+
"attrs": {
|
|
418
|
+
"backgroundColor": "default",
|
|
419
|
+
"id": "4",
|
|
420
|
+
"textColor": "default",
|
|
421
|
+
},
|
|
422
|
+
"content": [
|
|
423
|
+
{
|
|
424
|
+
"attrs": {
|
|
425
|
+
"textAlignment": "left",
|
|
426
|
+
},
|
|
427
|
+
"content": [
|
|
428
|
+
{
|
|
429
|
+
"text": "Text1",
|
|
430
|
+
"type": "text",
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
"type": "hardBreak",
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
"text": "Text2",
|
|
437
|
+
"type": "text",
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
"type": "hardBreak",
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
"text": "Text3",
|
|
444
|
+
"type": "text",
|
|
445
|
+
},
|
|
446
|
+
],
|
|
447
|
+
"type": "paragraph",
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
"type": "blockContainer",
|
|
451
|
+
}
|
|
452
|
+
`;
|
|
453
|
+
|
|
454
|
+
exports[`hard breaks > Convert a block with only a hard break 1`] = `
|
|
455
|
+
{
|
|
456
|
+
"attrs": {
|
|
457
|
+
"backgroundColor": "default",
|
|
458
|
+
"id": "4",
|
|
459
|
+
"textColor": "default",
|
|
460
|
+
},
|
|
461
|
+
"content": [
|
|
462
|
+
{
|
|
463
|
+
"attrs": {
|
|
464
|
+
"textAlignment": "left",
|
|
465
|
+
},
|
|
466
|
+
"content": [
|
|
467
|
+
{
|
|
468
|
+
"type": "hardBreak",
|
|
469
|
+
},
|
|
470
|
+
],
|
|
471
|
+
"type": "paragraph",
|
|
472
|
+
},
|
|
473
|
+
],
|
|
474
|
+
"type": "blockContainer",
|
|
475
|
+
}
|
|
476
|
+
`;
|
|
477
|
+
|
|
186
478
|
exports[`links > Convert a block with link 1`] = `
|
|
187
479
|
{
|
|
188
480
|
"attrs": {
|
|
@@ -5,14 +5,18 @@ import { BlockNoteEditor, PartialBlock } from "../..";
|
|
|
5
5
|
import UniqueID from "../../extensions/UniqueID/UniqueID";
|
|
6
6
|
import { blockToNode, nodeToBlock } from "./nodeConversions";
|
|
7
7
|
import { partialBlockToBlockForTesting } from "./testUtil";
|
|
8
|
+
import {
|
|
9
|
+
defaultBlockSchema,
|
|
10
|
+
DefaultBlockSchema,
|
|
11
|
+
} from "../../extensions/Blocks/api/defaultBlocks";
|
|
8
12
|
|
|
9
13
|
let editor: BlockNoteEditor;
|
|
10
14
|
let tt: Editor;
|
|
11
15
|
|
|
12
|
-
let simpleBlock: PartialBlock
|
|
16
|
+
let simpleBlock: PartialBlock<DefaultBlockSchema>;
|
|
13
17
|
let simpleNode: Node;
|
|
14
18
|
|
|
15
|
-
let complexBlock: PartialBlock
|
|
19
|
+
let complexBlock: PartialBlock<DefaultBlockSchema>;
|
|
16
20
|
let complexNode: Node;
|
|
17
21
|
|
|
18
22
|
beforeEach(() => {
|
|
@@ -119,7 +123,10 @@ describe("Simple ProseMirror Node Conversions", () => {
|
|
|
119
123
|
});
|
|
120
124
|
|
|
121
125
|
it("Convert simple node to block", async () => {
|
|
122
|
-
const firstBlockConversion = nodeToBlock(
|
|
126
|
+
const firstBlockConversion = nodeToBlock<DefaultBlockSchema>(
|
|
127
|
+
simpleNode,
|
|
128
|
+
defaultBlockSchema
|
|
129
|
+
);
|
|
123
130
|
|
|
124
131
|
expect(firstBlockConversion).toMatchSnapshot();
|
|
125
132
|
|
|
@@ -137,7 +144,10 @@ describe("Complex ProseMirror Node Conversions", () => {
|
|
|
137
144
|
});
|
|
138
145
|
|
|
139
146
|
it("Convert complex node to block", async () => {
|
|
140
|
-
const firstBlockConversion = nodeToBlock(
|
|
147
|
+
const firstBlockConversion = nodeToBlock<DefaultBlockSchema>(
|
|
148
|
+
complexNode,
|
|
149
|
+
defaultBlockSchema
|
|
150
|
+
);
|
|
141
151
|
|
|
142
152
|
expect(firstBlockConversion).toMatchSnapshot();
|
|
143
153
|
|
|
@@ -149,7 +159,7 @@ describe("Complex ProseMirror Node Conversions", () => {
|
|
|
149
159
|
|
|
150
160
|
describe("links", () => {
|
|
151
161
|
it("Convert a block with link", async () => {
|
|
152
|
-
const block: PartialBlock = {
|
|
162
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
153
163
|
id: UniqueID.options.generateID(),
|
|
154
164
|
type: "paragraph",
|
|
155
165
|
content: [
|
|
@@ -162,7 +172,10 @@ describe("links", () => {
|
|
|
162
172
|
};
|
|
163
173
|
const node = blockToNode(block, tt.schema);
|
|
164
174
|
expect(node).toMatchSnapshot();
|
|
165
|
-
const outputBlock = nodeToBlock(
|
|
175
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
176
|
+
node,
|
|
177
|
+
defaultBlockSchema
|
|
178
|
+
);
|
|
166
179
|
|
|
167
180
|
// Temporary fix to set props to {}, because at this point
|
|
168
181
|
// we don't have an easy way to access default props at runtime,
|
|
@@ -174,7 +187,7 @@ describe("links", () => {
|
|
|
174
187
|
});
|
|
175
188
|
|
|
176
189
|
it("Convert link block with marks", async () => {
|
|
177
|
-
const block: PartialBlock = {
|
|
190
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
178
191
|
id: UniqueID.options.generateID(),
|
|
179
192
|
type: "paragraph",
|
|
180
193
|
content: [
|
|
@@ -200,7 +213,10 @@ describe("links", () => {
|
|
|
200
213
|
};
|
|
201
214
|
const node = blockToNode(block, tt.schema);
|
|
202
215
|
// expect(node).toMatchSnapshot();
|
|
203
|
-
const outputBlock = nodeToBlock(
|
|
216
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
217
|
+
node,
|
|
218
|
+
defaultBlockSchema
|
|
219
|
+
);
|
|
204
220
|
|
|
205
221
|
// Temporary fix to set props to {}, because at this point
|
|
206
222
|
// we don't have an easy way to access default props at runtime,
|
|
@@ -212,7 +228,7 @@ describe("links", () => {
|
|
|
212
228
|
});
|
|
213
229
|
|
|
214
230
|
it("Convert two adjacent links in a block", async () => {
|
|
215
|
-
const block: PartialBlock = {
|
|
231
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
216
232
|
id: UniqueID.options.generateID(),
|
|
217
233
|
type: "paragraph",
|
|
218
234
|
content: [
|
|
@@ -231,7 +247,246 @@ describe("links", () => {
|
|
|
231
247
|
|
|
232
248
|
const node = blockToNode(block, tt.schema);
|
|
233
249
|
expect(node).toMatchSnapshot();
|
|
234
|
-
const outputBlock = nodeToBlock(
|
|
250
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
251
|
+
node,
|
|
252
|
+
defaultBlockSchema
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// Temporary fix to set props to {}, because at this point
|
|
256
|
+
// we don't have an easy way to access default props at runtime,
|
|
257
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
258
|
+
(outputBlock as any).props = {};
|
|
259
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
260
|
+
|
|
261
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("hard breaks", () => {
|
|
266
|
+
it("Convert a block with a hard break", async () => {
|
|
267
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
268
|
+
id: UniqueID.options.generateID(),
|
|
269
|
+
type: "paragraph",
|
|
270
|
+
content: [
|
|
271
|
+
{
|
|
272
|
+
type: "text",
|
|
273
|
+
text: "Text1\nText2",
|
|
274
|
+
styles: {},
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
};
|
|
278
|
+
const node = blockToNode(block, tt.schema);
|
|
279
|
+
expect(node).toMatchSnapshot();
|
|
280
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
281
|
+
node,
|
|
282
|
+
defaultBlockSchema
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Temporary fix to set props to {}, because at this point
|
|
286
|
+
// we don't have an easy way to access default props at runtime,
|
|
287
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
288
|
+
(outputBlock as any).props = {};
|
|
289
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
290
|
+
|
|
291
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("Convert a block with multiple hard breaks", async () => {
|
|
295
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
296
|
+
id: UniqueID.options.generateID(),
|
|
297
|
+
type: "paragraph",
|
|
298
|
+
content: [
|
|
299
|
+
{
|
|
300
|
+
type: "text",
|
|
301
|
+
text: "Text1\nText2\nText3",
|
|
302
|
+
styles: {},
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
};
|
|
306
|
+
const node = blockToNode(block, tt.schema);
|
|
307
|
+
expect(node).toMatchSnapshot();
|
|
308
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
309
|
+
node,
|
|
310
|
+
defaultBlockSchema
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
// Temporary fix to set props to {}, because at this point
|
|
314
|
+
// we don't have an easy way to access default props at runtime,
|
|
315
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
316
|
+
(outputBlock as any).props = {};
|
|
317
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
318
|
+
|
|
319
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("Convert a block with a hard break at the start", async () => {
|
|
323
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
324
|
+
id: UniqueID.options.generateID(),
|
|
325
|
+
type: "paragraph",
|
|
326
|
+
content: [
|
|
327
|
+
{
|
|
328
|
+
type: "text",
|
|
329
|
+
text: "\nText1",
|
|
330
|
+
styles: {},
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
};
|
|
334
|
+
const node = blockToNode(block, tt.schema);
|
|
335
|
+
expect(node).toMatchSnapshot();
|
|
336
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
337
|
+
node,
|
|
338
|
+
defaultBlockSchema
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
// Temporary fix to set props to {}, because at this point
|
|
342
|
+
// we don't have an easy way to access default props at runtime,
|
|
343
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
344
|
+
(outputBlock as any).props = {};
|
|
345
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
346
|
+
|
|
347
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("Convert a block with a hard break at the end", async () => {
|
|
351
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
352
|
+
id: UniqueID.options.generateID(),
|
|
353
|
+
type: "paragraph",
|
|
354
|
+
content: [
|
|
355
|
+
{
|
|
356
|
+
type: "text",
|
|
357
|
+
text: "Text1\n",
|
|
358
|
+
styles: {},
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
};
|
|
362
|
+
const node = blockToNode(block, tt.schema);
|
|
363
|
+
expect(node).toMatchSnapshot();
|
|
364
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
365
|
+
node,
|
|
366
|
+
defaultBlockSchema
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
// Temporary fix to set props to {}, because at this point
|
|
370
|
+
// we don't have an easy way to access default props at runtime,
|
|
371
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
372
|
+
(outputBlock as any).props = {};
|
|
373
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
374
|
+
|
|
375
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("Convert a block with only a hard break", async () => {
|
|
379
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
380
|
+
id: UniqueID.options.generateID(),
|
|
381
|
+
type: "paragraph",
|
|
382
|
+
content: [
|
|
383
|
+
{
|
|
384
|
+
type: "text",
|
|
385
|
+
text: "\n",
|
|
386
|
+
styles: {},
|
|
387
|
+
},
|
|
388
|
+
],
|
|
389
|
+
};
|
|
390
|
+
const node = blockToNode(block, tt.schema);
|
|
391
|
+
expect(node).toMatchSnapshot();
|
|
392
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
393
|
+
node,
|
|
394
|
+
defaultBlockSchema
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
// Temporary fix to set props to {}, because at this point
|
|
398
|
+
// we don't have an easy way to access default props at runtime,
|
|
399
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
400
|
+
(outputBlock as any).props = {};
|
|
401
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
402
|
+
|
|
403
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("Convert a block with a hard break and different styles", async () => {
|
|
407
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
408
|
+
id: UniqueID.options.generateID(),
|
|
409
|
+
type: "paragraph",
|
|
410
|
+
content: [
|
|
411
|
+
{
|
|
412
|
+
type: "text",
|
|
413
|
+
text: "Text1\n",
|
|
414
|
+
styles: {},
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
type: "text",
|
|
418
|
+
text: "Text2",
|
|
419
|
+
styles: { bold: true },
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
};
|
|
423
|
+
const node = blockToNode(block, tt.schema);
|
|
424
|
+
expect(node).toMatchSnapshot();
|
|
425
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
426
|
+
node,
|
|
427
|
+
defaultBlockSchema
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
// Temporary fix to set props to {}, because at this point
|
|
431
|
+
// we don't have an easy way to access default props at runtime,
|
|
432
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
433
|
+
(outputBlock as any).props = {};
|
|
434
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
435
|
+
|
|
436
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("Convert a block with a hard break in a link", async () => {
|
|
440
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
441
|
+
id: UniqueID.options.generateID(),
|
|
442
|
+
type: "paragraph",
|
|
443
|
+
content: [
|
|
444
|
+
{
|
|
445
|
+
type: "link",
|
|
446
|
+
href: "https://www.website.com",
|
|
447
|
+
content: "Link1\nLink1",
|
|
448
|
+
},
|
|
449
|
+
],
|
|
450
|
+
};
|
|
451
|
+
const node = blockToNode(block, tt.schema);
|
|
452
|
+
expect(node).toMatchSnapshot();
|
|
453
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
454
|
+
node,
|
|
455
|
+
defaultBlockSchema
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
// Temporary fix to set props to {}, because at this point
|
|
459
|
+
// we don't have an easy way to access default props at runtime,
|
|
460
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
461
|
+
(outputBlock as any).props = {};
|
|
462
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
463
|
+
|
|
464
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("Convert a block with a hard break between links", async () => {
|
|
468
|
+
const block: PartialBlock<DefaultBlockSchema> = {
|
|
469
|
+
id: UniqueID.options.generateID(),
|
|
470
|
+
type: "paragraph",
|
|
471
|
+
content: [
|
|
472
|
+
{
|
|
473
|
+
type: "link",
|
|
474
|
+
href: "https://www.website.com",
|
|
475
|
+
content: "Link1\n",
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
type: "link",
|
|
479
|
+
href: "https://www.website2.com",
|
|
480
|
+
content: "Link2",
|
|
481
|
+
},
|
|
482
|
+
],
|
|
483
|
+
};
|
|
484
|
+
const node = blockToNode(block, tt.schema);
|
|
485
|
+
expect(node).toMatchSnapshot();
|
|
486
|
+
const outputBlock = nodeToBlock<DefaultBlockSchema>(
|
|
487
|
+
node,
|
|
488
|
+
defaultBlockSchema
|
|
489
|
+
);
|
|
235
490
|
|
|
236
491
|
// Temporary fix to set props to {}, because at this point
|
|
237
492
|
// we don't have an easy way to access default props at runtime,
|