Skip to content

Commit 5edf299

Browse files
authored
refactor: blocknote transact API (#1609)
This refactors the blocknote editor to use a new `transact` API for both dispatching transactions to the editor and reading the editor's current state in a "transaction-safe" way.
1 parent 800f7d9 commit 5edf299

File tree

70 files changed

+3001
-3452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3001
-3452
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Test blocknote transactions > should return the correct block info 1`] = `
4+
[
5+
{
6+
"children": [],
7+
"content": [
8+
{
9+
"styles": {},
10+
"text": "Hey-yo",
11+
"type": "text",
12+
},
13+
],
14+
"id": "1",
15+
"props": {
16+
"backgroundColor": "default",
17+
"textAlignment": "left",
18+
"textColor": "default",
19+
},
20+
"type": "paragraph",
21+
},
22+
{
23+
"children": [],
24+
"content": [],
25+
"id": "0",
26+
"props": {
27+
"backgroundColor": "default",
28+
"textAlignment": "left",
29+
"textColor": "default",
30+
},
31+
"type": "paragraph",
32+
},
33+
]
34+
`;

packages/core/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap

+312
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,62 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`Test insertBlocks > Insert multiple blocks after 1`] = `
4+
[
5+
{
6+
"children": [],
7+
"content": [
8+
{
9+
"styles": {},
10+
"text": "Inserted paragraph 1",
11+
"type": "text",
12+
},
13+
],
14+
"id": "0",
15+
"props": {
16+
"backgroundColor": "default",
17+
"textAlignment": "left",
18+
"textColor": "default",
19+
},
20+
"type": "paragraph",
21+
},
22+
{
23+
"children": [],
24+
"content": [
25+
{
26+
"styles": {},
27+
"text": "Inserted paragraph 2",
28+
"type": "text",
29+
},
30+
],
31+
"id": "1",
32+
"props": {
33+
"backgroundColor": "default",
34+
"textAlignment": "left",
35+
"textColor": "default",
36+
},
37+
"type": "paragraph",
38+
},
39+
{
40+
"children": [],
41+
"content": [
42+
{
43+
"styles": {},
44+
"text": "Inserted paragraph 3",
45+
"type": "text",
46+
},
47+
],
48+
"id": "2",
49+
"props": {
50+
"backgroundColor": "default",
51+
"textAlignment": "left",
52+
"textColor": "default",
53+
},
54+
"type": "paragraph",
55+
},
56+
]
57+
`;
58+
59+
exports[`Test insertBlocks > Insert multiple blocks after 2`] = `
460
[
561
{
662
"children": [],
@@ -619,6 +675,62 @@ exports[`Test insertBlocks > Insert multiple blocks after 1`] = `
619675
`;
620676

621677
exports[`Test insertBlocks > Insert multiple blocks before 1`] = `
678+
[
679+
{
680+
"children": [],
681+
"content": [
682+
{
683+
"styles": {},
684+
"text": "Inserted paragraph 1",
685+
"type": "text",
686+
},
687+
],
688+
"id": "0",
689+
"props": {
690+
"backgroundColor": "default",
691+
"textAlignment": "left",
692+
"textColor": "default",
693+
},
694+
"type": "paragraph",
695+
},
696+
{
697+
"children": [],
698+
"content": [
699+
{
700+
"styles": {},
701+
"text": "Inserted paragraph 2",
702+
"type": "text",
703+
},
704+
],
705+
"id": "1",
706+
"props": {
707+
"backgroundColor": "default",
708+
"textAlignment": "left",
709+
"textColor": "default",
710+
},
711+
"type": "paragraph",
712+
},
713+
{
714+
"children": [],
715+
"content": [
716+
{
717+
"styles": {},
718+
"text": "Inserted paragraph 3",
719+
"type": "text",
720+
},
721+
],
722+
"id": "2",
723+
"props": {
724+
"backgroundColor": "default",
725+
"textAlignment": "left",
726+
"textColor": "default",
727+
},
728+
"type": "paragraph",
729+
},
730+
]
731+
`;
732+
733+
exports[`Test insertBlocks > Insert multiple blocks before 2`] = `
622734
[
623735
{
624736
"children": [],
@@ -1237,6 +1349,22 @@ exports[`Test insertBlocks > Insert multiple blocks before 1`] = `
12371349
`;
12381350

12391351
exports[`Test insertBlocks > Insert single basic block after 1`] = `
1352+
[
1353+
{
1354+
"children": [],
1355+
"content": [],
1356+
"id": "0",
1357+
"props": {
1358+
"backgroundColor": "default",
1359+
"textAlignment": "left",
1360+
"textColor": "default",
1361+
},
1362+
"type": "paragraph",
1363+
},
1364+
]
1365+
`;
1366+
1367+
exports[`Test insertBlocks > Insert single basic block after 2`] = `
12401368
[
12411369
{
12421370
"children": [],
@@ -1815,6 +1943,28 @@ exports[`Test insertBlocks > Insert single basic block after 1`] = `
18151943
`;
18161944

18171945
exports[`Test insertBlocks > Insert single basic block before (without type) 1`] = `
1946+
[
1947+
{
1948+
"children": [],
1949+
"content": [
1950+
{
1951+
"styles": {},
1952+
"text": "test",
1953+
"type": "text",
1954+
},
1955+
],
1956+
"id": "0",
1957+
"props": {
1958+
"backgroundColor": "default",
1959+
"textAlignment": "left",
1960+
"textColor": "default",
1961+
},
1962+
"type": "paragraph",
1963+
},
1964+
]
1965+
`;
1966+
1967+
exports[`Test insertBlocks > Insert single basic block before (without type) 2`] = `
18181968
[
18191969
{
18201970
"children": [],
@@ -2399,6 +2549,22 @@ exports[`Test insertBlocks > Insert single basic block before (without type) 1`]
23992549
`;
24002550

24012551
exports[`Test insertBlocks > Insert single basic block before 1`] = `
2552+
[
2553+
{
2554+
"children": [],
2555+
"content": [],
2556+
"id": "0",
2557+
"props": {
2558+
"backgroundColor": "default",
2559+
"textAlignment": "left",
2560+
"textColor": "default",
2561+
},
2562+
"type": "paragraph",
2563+
},
2564+
]
2565+
`;
2566+
2567+
exports[`Test insertBlocks > Insert single basic block before 2`] = `
24022568
[
24032569
{
24042570
"children": [],
@@ -2977,6 +3143,79 @@ exports[`Test insertBlocks > Insert single basic block before 1`] = `
29773143
`;
29783144

29793145
exports[`Test insertBlocks > Insert single complex block after 1`] = `
3146+
[
3147+
{
3148+
"children": [
3149+
{
3150+
"children": [
3151+
{
3152+
"children": [],
3153+
"content": [
3154+
{
3155+
"styles": {},
3156+
"text": "Double Nested Paragraph 2",
3157+
"type": "text",
3158+
},
3159+
],
3160+
"id": "inserted-double-nested-paragraph-2",
3161+
"props": {
3162+
"backgroundColor": "default",
3163+
"textAlignment": "left",
3164+
"textColor": "default",
3165+
},
3166+
"type": "paragraph",
3167+
},
3168+
],
3169+
"content": [
3170+
{
3171+
"styles": {},
3172+
"text": "Nested Paragraph 2",
3173+
"type": "text",
3174+
},
3175+
],
3176+
"id": "inserted-nested-paragraph-2",
3177+
"props": {
3178+
"backgroundColor": "default",
3179+
"textAlignment": "left",
3180+
"textColor": "default",
3181+
},
3182+
"type": "paragraph",
3183+
},
3184+
],
3185+
"content": [
3186+
{
3187+
"styles": {
3188+
"bold": true,
3189+
},
3190+
"text": "Heading",
3191+
"type": "text",
3192+
},
3193+
{
3194+
"styles": {},
3195+
"text": " with styled ",
3196+
"type": "text",
3197+
},
3198+
{
3199+
"styles": {
3200+
"italic": true,
3201+
},
3202+
"text": "content",
3203+
"type": "text",
3204+
},
3205+
],
3206+
"id": "inserted-heading-with-everything",
3207+
"props": {
3208+
"backgroundColor": "red",
3209+
"level": 2,
3210+
"textAlignment": "center",
3211+
"textColor": "red",
3212+
},
3213+
"type": "heading",
3214+
},
3215+
]
3216+
`;
3217+
3218+
exports[`Test insertBlocks > Insert single complex block after 2`] = `
29803219
[
29813220
{
29823221
"children": [],
@@ -3612,6 +3851,79 @@ exports[`Test insertBlocks > Insert single complex block after 1`] = `
36123851
`;
36133852

36143853
exports[`Test insertBlocks > Insert single complex block before 1`] = `
3854+
[
3855+
{
3856+
"children": [
3857+
{
3858+
"children": [
3859+
{
3860+
"children": [],
3861+
"content": [
3862+
{
3863+
"styles": {},
3864+
"text": "Double Nested Paragraph 2",
3865+
"type": "text",
3866+
},
3867+
],
3868+
"id": "inserted-double-nested-paragraph-2",
3869+
"props": {
3870+
"backgroundColor": "default",
3871+
"textAlignment": "left",
3872+
"textColor": "default",
3873+
},
3874+
"type": "paragraph",
3875+
},
3876+
],
3877+
"content": [
3878+
{
3879+
"styles": {},
3880+
"text": "Nested Paragraph 2",
3881+
"type": "text",
3882+
},
3883+
],
3884+
"id": "inserted-nested-paragraph-2",
3885+
"props": {
3886+
"backgroundColor": "default",
3887+
"textAlignment": "left",
3888+
"textColor": "default",
3889+
},
3890+
"type": "paragraph",
3891+
},
3892+
],
3893+
"content": [
3894+
{
3895+
"styles": {
3896+
"bold": true,
3897+
},
3898+
"text": "Heading",
3899+
"type": "text",
3900+
},
3901+
{
3902+
"styles": {},
3903+
"text": " with styled ",
3904+
"type": "text",
3905+
},
3906+
{
3907+
"styles": {
3908+
"italic": true,
3909+
},
3910+
"text": "content",
3911+
"type": "text",
3912+
},
3913+
],
3914+
"id": "inserted-heading-with-everything",
3915+
"props": {
3916+
"backgroundColor": "red",
3917+
"level": 2,
3918+
"textAlignment": "center",
3919+
"textColor": "red",
3920+
},
3921+
"type": "heading",
3922+
},
3923+
]
3924+
`;
3925+
3926+
exports[`Test insertBlocks > Insert single complex block before 2`] = `
36153927
[
36163928
{
36173929
"children": [

0 commit comments

Comments
 (0)