@blocknote/core 0.8.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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "homepage": "https://github.com/TypeCellOS/BlockNote",
4
4
  "private": false,
5
5
  "license": "MPL-2.0",
6
- "version": "0.8.0",
6
+ "version": "0.8.1",
7
7
  "files": [
8
8
  "dist",
9
9
  "types",
@@ -110,5 +110,5 @@
110
110
  "access": "public",
111
111
  "registry": "https://registry.npmjs.org/"
112
112
  },
113
- "gitHead": "cec8be26bbdf008846b907b52966ae3ef126cd64"
113
+ "gitHead": "2265d9068126df0881dd813ba6a265b82f48b466"
114
114
  }
@@ -154,6 +154,10 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
154
154
  return this._tiptapEditor.view.dom as HTMLDivElement;
155
155
  }
156
156
 
157
+ public isFocused() {
158
+ return this._tiptapEditor.view.hasFocus();
159
+ }
160
+
157
161
  public focus() {
158
162
  this._tiptapEditor.view.focus();
159
163
  }
@@ -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": {
@@ -261,3 +261,239 @@ describe("links", () => {
261
261
  expect(outputBlock).toStrictEqual(fullOriginalBlock);
262
262
  });
263
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
+ );
490
+
491
+ // Temporary fix to set props to {}, because at this point
492
+ // we don't have an easy way to access default props at runtime,
493
+ // so partialBlockToBlockForTesting will not set them.
494
+ (outputBlock as any).props = {};
495
+ const fullOriginalBlock = partialBlockToBlockForTesting(block);
496
+
497
+ expect(outputBlock).toStrictEqual(fullOriginalBlock);
498
+ });
499
+ });