@blocknote/core 0.4.0 → 0.4.2
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 +2043 -1918
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +20 -20
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/BlockNoteEditor.ts +5 -4
- package/src/BlockNoteExtensions.ts +11 -11
- package/src/api/Editor.ts +90 -6
- package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +616 -0
- package/src/api/blockManipulation/blockManipulation.test.ts +172 -0
- package/src/api/blockManipulation/blockManipulation.ts +25 -14
- package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +346 -0
- package/src/api/formatConversions/formatConversions.test.ts +766 -0
- package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +268 -0
- package/src/api/nodeConversions/nodeConversions.test.ts +244 -0
- package/src/api/nodeConversions/nodeConversions.ts +167 -58
- package/src/api/nodeConversions/testUtil.ts +61 -0
- package/src/api/util/nodeUtil.ts +38 -0
- package/src/editor.module.css +1 -0
- package/src/extensions/Blocks/api/blockTypes.ts +14 -9
- package/src/extensions/Blocks/api/inlineContentTypes.ts +27 -36
- package/src/extensions/Blocks/nodes/Block.module.css +39 -36
- package/src/extensions/Blocks/nodes/BlockContainer.ts +15 -14
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +149 -87
- package/src/shared/utils.ts +6 -0
- package/types/src/BlockNoteEditor.d.ts +2 -2
- package/types/src/api/Editor.d.ts +26 -6
- package/types/src/api/blockManipulation/blockManipulation.d.ts +5 -5
- package/types/src/api/blockManipulation/blockManipulation.test.d.ts +1 -0
- package/types/src/api/formatConversions/formatConversions.test.d.ts +1 -0
- package/types/src/api/nodeConversions/nodeConversions.d.ts +11 -4
- package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
- package/types/src/api/nodeConversions/testUtil.d.ts +2 -0
- package/types/src/api/util/nodeUtil.d.ts +8 -0
- package/types/src/extensions/Blocks/api/blockTypes.d.ts +10 -9
- package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +25 -19
- package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +15 -0
- package/types/src/shared/utils.d.ts +3 -0
- package/types/src/EditorElement.d.ts +0 -7
- package/types/src/api/Document.d.ts +0 -5
- package/types/src/api/removeUnderlinesRehypePlugin.d.ts +0 -6
- package/types/src/api/simplifyBlocksRehypePlugin.d.ts +0 -16
- package/types/src/extensions/Blocks/BlockAttributes.d.ts +0 -2
- package/types/src/extensions/Blocks/MultipleNodeSelection.d.ts +0 -24
- package/types/src/extensions/Blocks/api/apiTypes.d.ts +0 -18
- package/types/src/extensions/Blocks/api/styleTypes.d.ts +0 -22
- package/types/src/extensions/Blocks/apiTypes.d.ts +0 -16
- package/types/src/extensions/Blocks/nodes/Block.d.ts +0 -24
- package/types/src/extensions/Blocks/nodes/BlockContent/BlockContentTypes.d.ts +0 -4
- package/types/src/extensions/Blocks/nodes/BlockContent/HeadingBlockContent/HeadingBlockContentTypes.d.ts +0 -4
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContentTypes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContentTypes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockContent/ParagraphBlockContent/ParagraphBlockContentTypes.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockTypes/HeadingBlock/HeadingContent.d.ts +0 -8
- package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.d.ts +0 -8
- package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.d.ts +0 -2
- package/types/src/extensions/Blocks/nodes/BlockTypes/TextBlock/TextContent.d.ts +0 -6
- package/types/src/extensions/BubbleMenu/BubbleMenuExtension.d.ts +0 -8
- package/types/src/extensions/BubbleMenu/BubbleMenuFactoryTypes.d.ts +0 -27
- package/types/src/extensions/BubbleMenu/BubbleMenuPlugin.d.ts +0 -44
- package/types/src/extensions/DraggableBlocks/BlockMenuFactoryTypes.d.ts +0 -12
- package/types/src/extensions/DraggableBlocks/DragMenuFactoryTypes.d.ts +0 -18
- package/types/src/extensions/Hyperlinks/HyperlinkMark.d.ts +0 -8
- package/types/src/extensions/Hyperlinks/HyperlinkMenuFactoryTypes.d.ts +0 -11
- package/types/src/extensions/Hyperlinks/HyperlinkMenuPlugin.d.ts +0 -11
- package/types/src/extensions/Paragraph/FixedParagraph.d.ts +0 -1
- package/types/src/extensions/SlashMenu/defaultCommands.d.ts +0 -8
- package/types/src/utils.d.ts +0 -2
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
// Vitest Snapshot v1
|
|
2
|
+
|
|
3
|
+
exports[`Complex ProseMirror Node Conversions > Convert complex block to node 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"attrs": {
|
|
6
|
+
"backgroundColor": "blue",
|
|
7
|
+
"id": 4,
|
|
8
|
+
"textColor": "yellow",
|
|
9
|
+
},
|
|
10
|
+
"content": [
|
|
11
|
+
{
|
|
12
|
+
"attrs": {
|
|
13
|
+
"level": "2",
|
|
14
|
+
"textAlignment": "right",
|
|
15
|
+
},
|
|
16
|
+
"content": [
|
|
17
|
+
{
|
|
18
|
+
"marks": [
|
|
19
|
+
{
|
|
20
|
+
"type": "bold",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"type": "underline",
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
"text": "Heading ",
|
|
27
|
+
"type": "text",
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"marks": [
|
|
31
|
+
{
|
|
32
|
+
"type": "italic",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"type": "strike",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
"text": "2",
|
|
39
|
+
"type": "text",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
"type": "heading",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"content": [
|
|
46
|
+
{
|
|
47
|
+
"attrs": {
|
|
48
|
+
"backgroundColor": "red",
|
|
49
|
+
"id": 5,
|
|
50
|
+
"textColor": "default",
|
|
51
|
+
},
|
|
52
|
+
"content": [
|
|
53
|
+
{
|
|
54
|
+
"attrs": {
|
|
55
|
+
"textAlignment": "left",
|
|
56
|
+
},
|
|
57
|
+
"content": [
|
|
58
|
+
{
|
|
59
|
+
"text": "Paragraph",
|
|
60
|
+
"type": "text",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
"type": "paragraph",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
"type": "blockContainer",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"attrs": {
|
|
70
|
+
"backgroundColor": "default",
|
|
71
|
+
"id": 6,
|
|
72
|
+
"textColor": "default",
|
|
73
|
+
},
|
|
74
|
+
"content": [
|
|
75
|
+
{
|
|
76
|
+
"attrs": {
|
|
77
|
+
"textAlignment": "left",
|
|
78
|
+
},
|
|
79
|
+
"type": "bulletListItem",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
"type": "blockContainer",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
"type": "blockGroup",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
"type": "blockContainer",
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
exports[`Complex ProseMirror Node Conversions > Convert complex node to block 1`] = `
|
|
93
|
+
{
|
|
94
|
+
"children": [
|
|
95
|
+
{
|
|
96
|
+
"children": [],
|
|
97
|
+
"content": [
|
|
98
|
+
{
|
|
99
|
+
"styles": {},
|
|
100
|
+
"text": "Paragraph",
|
|
101
|
+
"type": "text",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
"id": 2,
|
|
105
|
+
"props": {
|
|
106
|
+
"backgroundColor": "red",
|
|
107
|
+
"textAlignment": "left",
|
|
108
|
+
"textColor": "default",
|
|
109
|
+
},
|
|
110
|
+
"type": "paragraph",
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"children": [],
|
|
114
|
+
"content": [],
|
|
115
|
+
"id": 3,
|
|
116
|
+
"props": {
|
|
117
|
+
"backgroundColor": "default",
|
|
118
|
+
"textAlignment": "left",
|
|
119
|
+
"textColor": "default",
|
|
120
|
+
},
|
|
121
|
+
"type": "bulletListItem",
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
"content": [
|
|
125
|
+
{
|
|
126
|
+
"styles": {
|
|
127
|
+
"bold": true,
|
|
128
|
+
"underline": true,
|
|
129
|
+
},
|
|
130
|
+
"text": "Heading ",
|
|
131
|
+
"type": "text",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"styles": {
|
|
135
|
+
"italic": true,
|
|
136
|
+
"strike": true,
|
|
137
|
+
},
|
|
138
|
+
"text": "2",
|
|
139
|
+
"type": "text",
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
"id": 1,
|
|
143
|
+
"props": {
|
|
144
|
+
"backgroundColor": "blue",
|
|
145
|
+
"level": "2",
|
|
146
|
+
"textAlignment": "right",
|
|
147
|
+
"textColor": "yellow",
|
|
148
|
+
},
|
|
149
|
+
"type": "heading",
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
exports[`Simple ProseMirror Node Conversions > Convert simple block to node 1`] = `
|
|
154
|
+
{
|
|
155
|
+
"attrs": {
|
|
156
|
+
"backgroundColor": "default",
|
|
157
|
+
"id": 4,
|
|
158
|
+
"textColor": "default",
|
|
159
|
+
},
|
|
160
|
+
"content": [
|
|
161
|
+
{
|
|
162
|
+
"attrs": {
|
|
163
|
+
"textAlignment": "left",
|
|
164
|
+
},
|
|
165
|
+
"type": "paragraph",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
"type": "blockContainer",
|
|
169
|
+
}
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
exports[`Simple ProseMirror Node Conversions > Convert simple node to block 1`] = `
|
|
173
|
+
{
|
|
174
|
+
"children": [],
|
|
175
|
+
"content": [],
|
|
176
|
+
"id": 0,
|
|
177
|
+
"props": {
|
|
178
|
+
"backgroundColor": "default",
|
|
179
|
+
"textAlignment": "left",
|
|
180
|
+
"textColor": "default",
|
|
181
|
+
},
|
|
182
|
+
"type": "paragraph",
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
|
|
186
|
+
exports[`links > Convert a block with link 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
|
+
"marks": [
|
|
201
|
+
{
|
|
202
|
+
"attrs": {
|
|
203
|
+
"class": null,
|
|
204
|
+
"href": "https://www.website.com",
|
|
205
|
+
"target": "_blank",
|
|
206
|
+
},
|
|
207
|
+
"type": "link",
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
"text": "Website",
|
|
211
|
+
"type": "text",
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
"type": "paragraph",
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
"type": "blockContainer",
|
|
218
|
+
}
|
|
219
|
+
`;
|
|
220
|
+
|
|
221
|
+
exports[`links > Convert two adjacent links in a block 1`] = `
|
|
222
|
+
{
|
|
223
|
+
"attrs": {
|
|
224
|
+
"backgroundColor": "default",
|
|
225
|
+
"id": 4,
|
|
226
|
+
"textColor": "default",
|
|
227
|
+
},
|
|
228
|
+
"content": [
|
|
229
|
+
{
|
|
230
|
+
"attrs": {
|
|
231
|
+
"textAlignment": "left",
|
|
232
|
+
},
|
|
233
|
+
"content": [
|
|
234
|
+
{
|
|
235
|
+
"marks": [
|
|
236
|
+
{
|
|
237
|
+
"attrs": {
|
|
238
|
+
"class": null,
|
|
239
|
+
"href": "https://www.website.com",
|
|
240
|
+
"target": "_blank",
|
|
241
|
+
},
|
|
242
|
+
"type": "link",
|
|
243
|
+
},
|
|
244
|
+
],
|
|
245
|
+
"text": "Website",
|
|
246
|
+
"type": "text",
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"marks": [
|
|
250
|
+
{
|
|
251
|
+
"attrs": {
|
|
252
|
+
"class": null,
|
|
253
|
+
"href": "https://www.website2.com",
|
|
254
|
+
"target": "_blank",
|
|
255
|
+
},
|
|
256
|
+
"type": "link",
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
"text": "Website2",
|
|
260
|
+
"type": "text",
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
"type": "paragraph",
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
"type": "blockContainer",
|
|
267
|
+
}
|
|
268
|
+
`;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { Editor } from "@tiptap/core";
|
|
2
|
+
import { Node } from "prosemirror-model";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { BlockNoteEditor, PartialBlock } from "../..";
|
|
5
|
+
import UniqueID from "../../extensions/UniqueID/UniqueID";
|
|
6
|
+
import { blockToNode, nodeToBlock } from "./nodeConversions";
|
|
7
|
+
import { partialBlockToBlockForTesting } from "./testUtil";
|
|
8
|
+
|
|
9
|
+
let editor: BlockNoteEditor;
|
|
10
|
+
let tt: Editor;
|
|
11
|
+
|
|
12
|
+
let simpleBlock: PartialBlock;
|
|
13
|
+
let simpleNode: Node;
|
|
14
|
+
|
|
15
|
+
let complexBlock: PartialBlock;
|
|
16
|
+
let complexNode: Node;
|
|
17
|
+
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
(window as Window & { __TEST_OPTIONS?: {} }).__TEST_OPTIONS = {};
|
|
20
|
+
|
|
21
|
+
editor = new BlockNoteEditor();
|
|
22
|
+
tt = editor._tiptapEditor;
|
|
23
|
+
|
|
24
|
+
simpleBlock = {
|
|
25
|
+
type: "paragraph",
|
|
26
|
+
};
|
|
27
|
+
simpleNode = tt.schema.nodes["blockContainer"].create(
|
|
28
|
+
{ id: UniqueID.options.generateID() },
|
|
29
|
+
tt.schema.nodes["paragraph"].create()
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
complexBlock = {
|
|
33
|
+
type: "heading",
|
|
34
|
+
props: {
|
|
35
|
+
backgroundColor: "blue",
|
|
36
|
+
textColor: "yellow",
|
|
37
|
+
textAlignment: "right",
|
|
38
|
+
level: "2",
|
|
39
|
+
},
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: "Heading ",
|
|
44
|
+
styles: {
|
|
45
|
+
bold: true,
|
|
46
|
+
underline: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "text",
|
|
51
|
+
text: "2",
|
|
52
|
+
styles: {
|
|
53
|
+
italic: true,
|
|
54
|
+
strike: true,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
type: "paragraph",
|
|
61
|
+
props: {
|
|
62
|
+
backgroundColor: "red",
|
|
63
|
+
},
|
|
64
|
+
content: "Paragraph",
|
|
65
|
+
children: [],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: "bulletListItem",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
complexNode = tt.schema.nodes["blockContainer"].create(
|
|
73
|
+
{
|
|
74
|
+
id: UniqueID.options.generateID(),
|
|
75
|
+
backgroundColor: "blue",
|
|
76
|
+
textColor: "yellow",
|
|
77
|
+
},
|
|
78
|
+
[
|
|
79
|
+
tt.schema.nodes["heading"].create(
|
|
80
|
+
{ textAlignment: "right", level: "2" },
|
|
81
|
+
[
|
|
82
|
+
tt.schema.text("Heading ", [
|
|
83
|
+
tt.schema.mark("bold"),
|
|
84
|
+
tt.schema.mark("underline"),
|
|
85
|
+
]),
|
|
86
|
+
tt.schema.text("2", [
|
|
87
|
+
tt.schema.mark("italic"),
|
|
88
|
+
tt.schema.mark("strike"),
|
|
89
|
+
]),
|
|
90
|
+
]
|
|
91
|
+
),
|
|
92
|
+
tt.schema.nodes["blockGroup"].create({}, [
|
|
93
|
+
tt.schema.nodes["blockContainer"].create(
|
|
94
|
+
{ id: UniqueID.options.generateID(), backgroundColor: "red" },
|
|
95
|
+
[tt.schema.nodes["paragraph"].create({}, tt.schema.text("Paragraph"))]
|
|
96
|
+
),
|
|
97
|
+
tt.schema.nodes["blockContainer"].create(
|
|
98
|
+
{ id: UniqueID.options.generateID() },
|
|
99
|
+
[tt.schema.nodes["bulletListItem"].create()]
|
|
100
|
+
),
|
|
101
|
+
]),
|
|
102
|
+
]
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
tt.destroy();
|
|
108
|
+
editor = undefined as any;
|
|
109
|
+
tt = undefined as any;
|
|
110
|
+
|
|
111
|
+
delete (window as Window & { __TEST_OPTIONS?: {} }).__TEST_OPTIONS;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe("Simple ProseMirror Node Conversions", () => {
|
|
115
|
+
it("Convert simple block to node", async () => {
|
|
116
|
+
const firstNodeConversion = blockToNode(simpleBlock, tt.schema);
|
|
117
|
+
|
|
118
|
+
expect(firstNodeConversion).toMatchSnapshot();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("Convert simple node to block", async () => {
|
|
122
|
+
const firstBlockConversion = nodeToBlock(simpleNode);
|
|
123
|
+
|
|
124
|
+
expect(firstBlockConversion).toMatchSnapshot();
|
|
125
|
+
|
|
126
|
+
const firstNodeConversion = blockToNode(firstBlockConversion, tt.schema);
|
|
127
|
+
|
|
128
|
+
expect(firstNodeConversion).toStrictEqual(simpleNode);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("Complex ProseMirror Node Conversions", () => {
|
|
133
|
+
it("Convert complex block to node", async () => {
|
|
134
|
+
const firstNodeConversion = blockToNode(complexBlock, tt.schema);
|
|
135
|
+
|
|
136
|
+
expect(firstNodeConversion).toMatchSnapshot();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("Convert complex node to block", async () => {
|
|
140
|
+
const firstBlockConversion = nodeToBlock(complexNode);
|
|
141
|
+
|
|
142
|
+
expect(firstBlockConversion).toMatchSnapshot();
|
|
143
|
+
|
|
144
|
+
const firstNodeConversion = blockToNode(firstBlockConversion, tt.schema);
|
|
145
|
+
|
|
146
|
+
expect(firstNodeConversion).toStrictEqual(complexNode);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("links", () => {
|
|
151
|
+
it("Convert a block with link", async () => {
|
|
152
|
+
const block: PartialBlock = {
|
|
153
|
+
id: UniqueID.options.generateID(),
|
|
154
|
+
type: "paragraph",
|
|
155
|
+
content: [
|
|
156
|
+
{
|
|
157
|
+
type: "link",
|
|
158
|
+
href: "https://www.website.com",
|
|
159
|
+
content: "Website",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
const node = blockToNode(block, tt.schema);
|
|
164
|
+
expect(node).toMatchSnapshot();
|
|
165
|
+
const outputBlock = nodeToBlock(node);
|
|
166
|
+
|
|
167
|
+
// Temporary fix to set props to {}, because at this point
|
|
168
|
+
// we don't have an easy way to access default props at runtime,
|
|
169
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
170
|
+
(outputBlock as any).props = {};
|
|
171
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
172
|
+
|
|
173
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("Convert link block with marks", async () => {
|
|
177
|
+
const block: PartialBlock = {
|
|
178
|
+
id: UniqueID.options.generateID(),
|
|
179
|
+
type: "paragraph",
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
type: "link",
|
|
183
|
+
href: "https://www.website.com",
|
|
184
|
+
content: [
|
|
185
|
+
{
|
|
186
|
+
type: "text",
|
|
187
|
+
text: "Web",
|
|
188
|
+
styles: {
|
|
189
|
+
bold: true,
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: "text",
|
|
194
|
+
text: "site",
|
|
195
|
+
styles: {},
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
const node = blockToNode(block, tt.schema);
|
|
202
|
+
// expect(node).toMatchSnapshot();
|
|
203
|
+
const outputBlock = nodeToBlock(node);
|
|
204
|
+
|
|
205
|
+
// Temporary fix to set props to {}, because at this point
|
|
206
|
+
// we don't have an easy way to access default props at runtime,
|
|
207
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
208
|
+
(outputBlock as any).props = {};
|
|
209
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
210
|
+
|
|
211
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("Convert two adjacent links in a block", async () => {
|
|
215
|
+
const block: PartialBlock = {
|
|
216
|
+
id: UniqueID.options.generateID(),
|
|
217
|
+
type: "paragraph",
|
|
218
|
+
content: [
|
|
219
|
+
{
|
|
220
|
+
type: "link",
|
|
221
|
+
href: "https://www.website.com",
|
|
222
|
+
content: "Website",
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
type: "link",
|
|
226
|
+
href: "https://www.website2.com",
|
|
227
|
+
content: "Website2",
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const node = blockToNode(block, tt.schema);
|
|
233
|
+
expect(node).toMatchSnapshot();
|
|
234
|
+
const outputBlock = nodeToBlock(node);
|
|
235
|
+
|
|
236
|
+
// Temporary fix to set props to {}, because at this point
|
|
237
|
+
// we don't have an easy way to access default props at runtime,
|
|
238
|
+
// so partialBlockToBlockForTesting will not set them.
|
|
239
|
+
(outputBlock as any).props = {};
|
|
240
|
+
const fullOriginalBlock = partialBlockToBlockForTesting(block);
|
|
241
|
+
|
|
242
|
+
expect(outputBlock).toStrictEqual(fullOriginalBlock);
|
|
243
|
+
});
|
|
244
|
+
});
|