@blocknote/core 0.30.1 → 0.31.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.cjs +9 -9
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +2793 -2213
- package/dist/blocknote.js.map +1 -1
- package/dist/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
- package/dist/en-BXVKCwYt.cjs.map +1 -0
- package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
- package/dist/en-qGo6sk9V.js.map +1 -0
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +20 -39
- package/dist/locales.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +5 -6
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +2 -3
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +158 -0
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +87 -17
- package/src/api/blockManipulation/selections/selection.ts +48 -1
- package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +7 -7
- package/src/api/getBlockInfoFromPos.ts +1 -1
- package/src/api/nodeConversions/blockToNode.ts +5 -2
- package/src/api/nodeConversions/nodeToBlock.ts +203 -8
- package/src/api/pmUtil.ts +3 -3
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +6 -6
- package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +1 -1
- package/src/blocks/TableBlockContent/TableBlockContent.ts +32 -2
- package/src/editor/Block.css +27 -1
- package/src/editor/BlockNoteEditor.test.ts +7 -0
- package/src/editor/BlockNoteEditor.ts +124 -39
- package/src/editor/BlockNoteExtension.ts +26 -0
- package/src/editor/BlockNoteExtensions.ts +28 -12
- package/src/editor/BlockNoteTipTapEditor.ts +23 -2
- package/src/extensions/Collaboration/CursorPlugin.ts +13 -7
- package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
- package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
- package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
- package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
- package/src/extensions/Comments/CommentsPlugin.ts +79 -70
- package/src/extensions/FilePanel/FilePanelPlugin.ts +54 -49
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -26
- package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +26 -21
- package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +49 -42
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +115 -108
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +183 -170
- package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +26 -19
- package/src/extensions/SideMenu/SideMenuPlugin.ts +23 -18
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +172 -168
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +4 -4
- package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +157 -150
- package/src/i18n/locales/ar.ts +0 -1
- package/src/i18n/locales/de.ts +0 -1
- package/src/i18n/locales/en.ts +0 -1
- package/src/i18n/locales/es.ts +0 -1
- package/src/i18n/locales/fr.ts +0 -1
- package/src/i18n/locales/hr.ts +0 -1
- package/src/i18n/locales/is.ts +0 -1
- package/src/i18n/locales/it.ts +0 -1
- package/src/i18n/locales/ja.ts +0 -1
- package/src/i18n/locales/ko.ts +0 -1
- package/src/i18n/locales/nl.ts +0 -1
- package/src/i18n/locales/no.ts +0 -1
- package/src/i18n/locales/pl.ts +0 -1
- package/src/i18n/locales/pt.ts +0 -1
- package/src/i18n/locales/ru.ts +0 -1
- package/src/i18n/locales/sk.ts +0 -1
- package/src/i18n/locales/uk.ts +0 -1
- package/src/i18n/locales/vi.ts +0 -1
- package/src/i18n/locales/zh-tw.ts +0 -1
- package/src/i18n/locales/zh.ts +0 -1
- package/src/index.ts +18 -8
- package/src/pm-nodes/BlockContainer.ts +1 -1
- package/src/pm-nodes/BlockGroup.ts +1 -1
- package/src/pm-nodes/Doc.ts +1 -0
- package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
- package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
- package/types/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.d.ts → textCursorPosition.d.ts} +2 -2
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
- package/types/src/api/pmUtil.d.ts +3 -3
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
- package/types/src/editor/BlockNoteEditor.d.ts +62 -10
- package/types/src/editor/BlockNoteExtension.d.ts +9 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
- package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
- package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
- package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +3 -4
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
- package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +6 -5
- package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +4 -4
- package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +3 -3
- package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +3 -3
- package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +3 -3
- package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +3 -3
- package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +4 -4
- package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +3 -4
- package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +6 -6
- package/types/src/i18n/locales/en.d.ts +0 -1
- package/types/src/i18n/locales/sk.d.ts +0 -1
- package/types/src/index.d.ts +15 -8
- package/dist/en-B7ycW7c8.js.map +0 -1
- package/dist/en-D4taoCs4.cjs.map +0 -1
- package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
- package/src/api/blockManipulation/selections/selection.test.ts +0 -72
- package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
- package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +0 -74
- package/types/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.d.ts +0 -1
- /package/types/src/{api/blockManipulation/selections/selection.test.d.ts → extensions/Collaboration/ForkYDocPlugin.test.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Mark, Node, Schema } from "@tiptap/pm/model";
|
|
2
|
-
|
|
1
|
+
import { Mark, Node, Schema, Slice } from "@tiptap/pm/model";
|
|
2
|
+
import type { Block } from "../../blocks/defaultBlocks.js";
|
|
3
3
|
import UniqueID from "../../extensions/UniqueID/UniqueID.js";
|
|
4
4
|
import type {
|
|
5
5
|
BlockSchema,
|
|
@@ -13,17 +13,18 @@ import type {
|
|
|
13
13
|
TableCell,
|
|
14
14
|
TableContent,
|
|
15
15
|
} from "../../schema/index.js";
|
|
16
|
-
import { getBlockInfoWithManualOffset } from "../getBlockInfoFromPos.js";
|
|
17
|
-
|
|
18
|
-
import type { Block } from "../../blocks/defaultBlocks.js";
|
|
19
16
|
import {
|
|
20
17
|
isLinkInlineContent,
|
|
21
18
|
isStyledTextInlineContent,
|
|
22
19
|
} from "../../schema/inlineContent/types.js";
|
|
23
20
|
import { UnreachableCaseError } from "../../util/typescript.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
21
|
+
import { getBlockInfoWithManualOffset } from "../getBlockInfoFromPos.js";
|
|
22
|
+
import {
|
|
23
|
+
getBlockCache,
|
|
24
|
+
getBlockSchema,
|
|
25
|
+
getInlineContentSchema,
|
|
26
|
+
getStyleSchema,
|
|
27
|
+
} from "../pmUtil.js";
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Converts an internal (prosemirror) table node contentto a BlockNote Tablecontent
|
|
@@ -492,3 +493,197 @@ export function nodeToBlock<
|
|
|
492
493
|
|
|
493
494
|
return block;
|
|
494
495
|
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Convert a Prosemirror document to a BlockNote document (array of blocks)
|
|
499
|
+
*/
|
|
500
|
+
export function docToBlocks<
|
|
501
|
+
BSchema extends BlockSchema,
|
|
502
|
+
I extends InlineContentSchema,
|
|
503
|
+
S extends StyleSchema,
|
|
504
|
+
>(
|
|
505
|
+
doc: Node,
|
|
506
|
+
schema: Schema,
|
|
507
|
+
blockSchema: BSchema = getBlockSchema(schema) as BSchema,
|
|
508
|
+
inlineContentSchema: I = getInlineContentSchema(schema) as I,
|
|
509
|
+
styleSchema: S = getStyleSchema(schema) as S,
|
|
510
|
+
blockCache = getBlockCache(schema),
|
|
511
|
+
) {
|
|
512
|
+
const blocks: Block<BSchema, I, S>[] = [];
|
|
513
|
+
doc.firstChild!.descendants((node) => {
|
|
514
|
+
blocks.push(
|
|
515
|
+
nodeToBlock(
|
|
516
|
+
node,
|
|
517
|
+
schema,
|
|
518
|
+
blockSchema,
|
|
519
|
+
inlineContentSchema,
|
|
520
|
+
styleSchema,
|
|
521
|
+
blockCache,
|
|
522
|
+
),
|
|
523
|
+
);
|
|
524
|
+
return false;
|
|
525
|
+
});
|
|
526
|
+
return blocks;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
*
|
|
531
|
+
* Parse a Prosemirror Slice into a BlockNote selection. The prosemirror schema looks like this:
|
|
532
|
+
*
|
|
533
|
+
* <blockGroup>
|
|
534
|
+
* <blockContainer> (main content of block)
|
|
535
|
+
* <p, heading, etc.>
|
|
536
|
+
* <blockGroup> (only if blocks has children)
|
|
537
|
+
* <blockContainer> (child block)
|
|
538
|
+
* <p, heading, etc.>
|
|
539
|
+
* </blockContainer>
|
|
540
|
+
* <blockContainer> (child block 2)
|
|
541
|
+
* <p, heading, etc.>
|
|
542
|
+
* </blockContainer>
|
|
543
|
+
* </blockContainer>
|
|
544
|
+
* </blockGroup>
|
|
545
|
+
* </blockGroup>
|
|
546
|
+
*
|
|
547
|
+
*/
|
|
548
|
+
export function prosemirrorSliceToSlicedBlocks<
|
|
549
|
+
BSchema extends BlockSchema,
|
|
550
|
+
I extends InlineContentSchema,
|
|
551
|
+
S extends StyleSchema,
|
|
552
|
+
>(
|
|
553
|
+
slice: Slice,
|
|
554
|
+
schema: Schema,
|
|
555
|
+
blockSchema: BSchema = getBlockSchema(schema) as BSchema,
|
|
556
|
+
inlineContentSchema: I = getInlineContentSchema(schema) as I,
|
|
557
|
+
styleSchema: S = getStyleSchema(schema) as S,
|
|
558
|
+
blockCache: WeakMap<Node, Block<BSchema, I, S>> = getBlockCache(schema),
|
|
559
|
+
): {
|
|
560
|
+
/**
|
|
561
|
+
* The blocks that are included in the selection.
|
|
562
|
+
*/
|
|
563
|
+
blocks: Block<BSchema, I, S>[];
|
|
564
|
+
/**
|
|
565
|
+
* If a block was "cut" at the start of the selection, this will be the id of the block that was cut.
|
|
566
|
+
*/
|
|
567
|
+
blockCutAtStart: string | undefined;
|
|
568
|
+
/**
|
|
569
|
+
* If a block was "cut" at the end of the selection, this will be the id of the block that was cut.
|
|
570
|
+
*/
|
|
571
|
+
blockCutAtEnd: string | undefined;
|
|
572
|
+
} {
|
|
573
|
+
// console.log(JSON.stringify(slice.toJSON()));
|
|
574
|
+
function processNode(
|
|
575
|
+
node: Node,
|
|
576
|
+
openStart: number,
|
|
577
|
+
openEnd: number,
|
|
578
|
+
): {
|
|
579
|
+
blocks: Block<BSchema, I, S>[];
|
|
580
|
+
blockCutAtStart: string | undefined;
|
|
581
|
+
blockCutAtEnd: string | undefined;
|
|
582
|
+
} {
|
|
583
|
+
if (node.type.name !== "blockGroup") {
|
|
584
|
+
throw new Error("unexpected");
|
|
585
|
+
}
|
|
586
|
+
const blocks: Block<BSchema, I, S>[] = [];
|
|
587
|
+
let blockCutAtStart: string | undefined;
|
|
588
|
+
let blockCutAtEnd: string | undefined;
|
|
589
|
+
|
|
590
|
+
node.forEach((blockContainer, _offset, index) => {
|
|
591
|
+
if (blockContainer.type.name !== "blockContainer") {
|
|
592
|
+
throw new Error("unexpected");
|
|
593
|
+
}
|
|
594
|
+
if (blockContainer.childCount === 0) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
if (blockContainer.childCount === 0 || blockContainer.childCount > 2) {
|
|
598
|
+
throw new Error(
|
|
599
|
+
"unexpected, blockContainer.childCount: " + blockContainer.childCount,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
const isFirstBlock = index === 0;
|
|
604
|
+
const isLastBlock = index === node.childCount - 1;
|
|
605
|
+
|
|
606
|
+
if (blockContainer.firstChild!.type.name === "blockGroup") {
|
|
607
|
+
// this is the parent where a selection starts within one of its children,
|
|
608
|
+
// e.g.:
|
|
609
|
+
// A
|
|
610
|
+
// ├── B
|
|
611
|
+
// selection starts within B, then this blockContainer is A, but we don't care about A
|
|
612
|
+
// so let's descend into B and continue processing
|
|
613
|
+
if (!isFirstBlock) {
|
|
614
|
+
throw new Error("unexpected");
|
|
615
|
+
}
|
|
616
|
+
const ret = processNode(
|
|
617
|
+
blockContainer.firstChild!,
|
|
618
|
+
Math.max(0, openStart - 1),
|
|
619
|
+
isLastBlock ? Math.max(0, openEnd - 1) : 0,
|
|
620
|
+
);
|
|
621
|
+
blockCutAtStart = ret.blockCutAtStart;
|
|
622
|
+
if (isLastBlock) {
|
|
623
|
+
blockCutAtEnd = ret.blockCutAtEnd;
|
|
624
|
+
}
|
|
625
|
+
blocks.push(...ret.blocks);
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const block = nodeToBlock(
|
|
630
|
+
blockContainer,
|
|
631
|
+
schema,
|
|
632
|
+
blockSchema,
|
|
633
|
+
inlineContentSchema,
|
|
634
|
+
styleSchema,
|
|
635
|
+
blockCache,
|
|
636
|
+
);
|
|
637
|
+
const childGroup =
|
|
638
|
+
blockContainer.childCount > 1 ? blockContainer.child(1) : undefined;
|
|
639
|
+
|
|
640
|
+
let childBlocks: Block<BSchema, I, S>[] = [];
|
|
641
|
+
if (childGroup) {
|
|
642
|
+
const ret = processNode(
|
|
643
|
+
childGroup,
|
|
644
|
+
0, // TODO: can this be anything other than 0?
|
|
645
|
+
isLastBlock ? Math.max(0, openEnd - 1) : 0,
|
|
646
|
+
);
|
|
647
|
+
childBlocks = ret.blocks;
|
|
648
|
+
if (isLastBlock) {
|
|
649
|
+
blockCutAtEnd = ret.blockCutAtEnd;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (isLastBlock && !childGroup && openEnd > 1) {
|
|
654
|
+
blockCutAtEnd = block.id;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (isFirstBlock && openStart > 1) {
|
|
658
|
+
blockCutAtStart = block.id;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
blocks.push({
|
|
662
|
+
...(block as any),
|
|
663
|
+
children: childBlocks,
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
return { blocks, blockCutAtStart, blockCutAtEnd };
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (slice.content.childCount === 0) {
|
|
671
|
+
return {
|
|
672
|
+
blocks: [],
|
|
673
|
+
blockCutAtStart: undefined,
|
|
674
|
+
blockCutAtEnd: undefined,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (slice.content.childCount !== 1) {
|
|
679
|
+
throw new Error(
|
|
680
|
+
"slice must be a single block, did you forget includeParents=true?",
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
return processNode(
|
|
685
|
+
slice.content.firstChild!,
|
|
686
|
+
Math.max(slice.openStart - 1, 0),
|
|
687
|
+
Math.max(slice.openEnd - 1, 0),
|
|
688
|
+
);
|
|
689
|
+
}
|
package/src/api/pmUtil.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Node, Schema } from "prosemirror-model";
|
|
2
|
-
import
|
|
2
|
+
import { Transform } from "prosemirror-transform";
|
|
3
3
|
import type { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
4
|
+
import { BlockNoteSchema } from "../editor/BlockNoteSchema.js";
|
|
4
5
|
import type { BlockSchema } from "../schema/blocks/types.js";
|
|
5
6
|
import type { InlineContentSchema } from "../schema/inlineContent/types.js";
|
|
6
7
|
import type { StyleSchema } from "../schema/styles/types.js";
|
|
7
|
-
import { BlockNoteSchema } from "../editor/BlockNoteSchema.js";
|
|
8
8
|
|
|
9
|
-
export function getPmSchema(trOrNode:
|
|
9
|
+
export function getPmSchema(trOrNode: Transform | Node) {
|
|
10
10
|
if ("doc" in trOrNode) {
|
|
11
11
|
return trOrNode.doc.type.schema;
|
|
12
12
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import type { HighlighterGeneric } from "@shikijs/types";
|
|
1
2
|
import { InputRule, isTextSelection } from "@tiptap/core";
|
|
2
3
|
import { TextSelection } from "@tiptap/pm/state";
|
|
3
|
-
import {
|
|
4
|
+
import { Parser, createHighlightPlugin } from "prosemirror-highlight";
|
|
4
5
|
import { createParser } from "prosemirror-highlight/shiki";
|
|
6
|
+
import { BlockNoteEditor } from "../../index.js";
|
|
5
7
|
import {
|
|
8
|
+
PropSchema,
|
|
6
9
|
createBlockSpecFromStronglyTypedTiptapNode,
|
|
7
10
|
createStronglyTypedTiptapNode,
|
|
8
|
-
PropSchema,
|
|
9
11
|
} from "../../schema/index.js";
|
|
10
12
|
import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
|
|
11
|
-
import type { HighlighterGeneric } from "@shikijs/types";
|
|
12
|
-
import { BlockNoteEditor } from "../../index.js";
|
|
13
13
|
|
|
14
14
|
export type CodeBlockOptions = {
|
|
15
15
|
/**
|
|
@@ -76,7 +76,7 @@ const CodeBlockContent = createStronglyTypedTiptapNode({
|
|
|
76
76
|
name: "codeBlock",
|
|
77
77
|
content: "inline*",
|
|
78
78
|
group: "blockContent",
|
|
79
|
-
marks: "",
|
|
79
|
+
marks: "insertion deletion modification",
|
|
80
80
|
code: true,
|
|
81
81
|
defining: true,
|
|
82
82
|
addOptions() {
|
|
@@ -152,7 +152,7 @@ const CodeBlockContent = createStronglyTypedTiptapNode({
|
|
|
152
152
|
// Parse from external HTML.
|
|
153
153
|
{
|
|
154
154
|
tag: "pre",
|
|
155
|
-
contentElement: "code",
|
|
155
|
+
// contentElement: "code",
|
|
156
156
|
preserveWhitespace: "full",
|
|
157
157
|
},
|
|
158
158
|
];
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from "@tiptap/core";
|
|
1
2
|
import { TableCell } from "@tiptap/extension-table-cell";
|
|
2
3
|
import { TableHeader } from "@tiptap/extension-table-header";
|
|
3
|
-
import { TableRow } from "@tiptap/extension-table-row";
|
|
4
4
|
import { DOMParser, Fragment, Node as PMNode, Schema } from "prosemirror-model";
|
|
5
5
|
import { TableView } from "prosemirror-tables";
|
|
6
|
-
|
|
7
6
|
import { NodeView } from "prosemirror-view";
|
|
8
7
|
import {
|
|
9
8
|
createBlockSpecFromStronglyTypedTiptapNode,
|
|
@@ -24,6 +23,7 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
|
|
|
24
23
|
group: "blockContent",
|
|
25
24
|
tableRole: "table",
|
|
26
25
|
|
|
26
|
+
marks: "deletion insertion modification",
|
|
27
27
|
isolating: true,
|
|
28
28
|
|
|
29
29
|
parseHTML() {
|
|
@@ -152,6 +152,36 @@ const TableParagraph = createStronglyTypedTiptapNode({
|
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
/**
|
|
155
|
+
* This extension allows you to create table rows.
|
|
156
|
+
* @see https://www.tiptap.dev/api/nodes/table-row
|
|
157
|
+
*/
|
|
158
|
+
export const TableRow = Node.create<{ HTMLAttributes: Record<string, any> }>({
|
|
159
|
+
name: "tableRow",
|
|
160
|
+
|
|
161
|
+
addOptions() {
|
|
162
|
+
return {
|
|
163
|
+
HTMLAttributes: {},
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
content: "(tableCell | tableHeader)+",
|
|
168
|
+
|
|
169
|
+
tableRole: "row",
|
|
170
|
+
marks: "deletion insertion modification",
|
|
171
|
+
parseHTML() {
|
|
172
|
+
return [{ tag: "tr" }];
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
renderHTML({ HTMLAttributes }) {
|
|
176
|
+
return [
|
|
177
|
+
"tr",
|
|
178
|
+
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
|
|
179
|
+
0,
|
|
180
|
+
];
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
/*
|
|
155
185
|
* This will flatten a node's content to fit into a table cell's paragraph.
|
|
156
186
|
*/
|
|
157
187
|
function parseTableContent(node: HTMLElement, schema: Schema) {
|
package/src/editor/Block.css
CHANGED
|
@@ -152,6 +152,11 @@ NESTED BLOCKS
|
|
|
152
152
|
|
|
153
153
|
.bn-block-outer:not([data-prev-type])
|
|
154
154
|
> .bn-block
|
|
155
|
+
> .bn-block-content[data-content-type="heading"],
|
|
156
|
+
.bn-block-outer:not([data-prev-type])
|
|
157
|
+
> .bn-block
|
|
158
|
+
> div[data-type="modification"]
|
|
159
|
+
> div[data-type="modification"]
|
|
155
160
|
> .bn-block-content[data-content-type="heading"] {
|
|
156
161
|
font-size: var(--level);
|
|
157
162
|
font-weight: bold;
|
|
@@ -195,6 +200,10 @@ NESTED BLOCKS
|
|
|
195
200
|
|
|
196
201
|
.bn-block-outer:not([data-prev-type])
|
|
197
202
|
> .bn-block
|
|
203
|
+
> .bn-block-content[data-content-type="numberedListItem"]::before,
|
|
204
|
+
.bn-block-outer:not([data-prev-type])
|
|
205
|
+
> .bn-block
|
|
206
|
+
> div[data-type="modification"]
|
|
198
207
|
> .bn-block-content[data-content-type="numberedListItem"]::before {
|
|
199
208
|
content: var(--index) ".";
|
|
200
209
|
}
|
|
@@ -239,6 +248,10 @@ NESTED BLOCKS
|
|
|
239
248
|
|
|
240
249
|
.bn-block-outer:not([data-prev-type])
|
|
241
250
|
> .bn-block
|
|
251
|
+
> .bn-block-content[data-content-type="bulletListItem"]::before,
|
|
252
|
+
.bn-block-outer:not([data-prev-type])
|
|
253
|
+
> .bn-block
|
|
254
|
+
> div[data-type="modification"]
|
|
242
255
|
> .bn-block-content[data-content-type="bulletListItem"]::before {
|
|
243
256
|
content: "•";
|
|
244
257
|
}
|
|
@@ -256,6 +269,12 @@ NESTED BLOCKS
|
|
|
256
269
|
~ .bn-block-group
|
|
257
270
|
> .bn-block-outer:not([data-prev-type])
|
|
258
271
|
> .bn-block
|
|
272
|
+
> .bn-block-content[data-content-type="bulletListItem"]::before,
|
|
273
|
+
[data-content-type="bulletListItem"]
|
|
274
|
+
~ .bn-block-group
|
|
275
|
+
> .bn-block-outer:not([data-prev-type])
|
|
276
|
+
> .bn-block
|
|
277
|
+
> div[data-type="modification"]
|
|
259
278
|
> .bn-block-content[data-content-type="bulletListItem"]::before {
|
|
260
279
|
content: "◦";
|
|
261
280
|
}
|
|
@@ -277,6 +296,14 @@ NESTED BLOCKS
|
|
|
277
296
|
~ .bn-block-group
|
|
278
297
|
> .bn-block-outer:not([data-prev-type])
|
|
279
298
|
> .bn-block
|
|
299
|
+
> .bn-block-content[data-content-type="bulletListItem"]::before,
|
|
300
|
+
[data-content-type="bulletListItem"]
|
|
301
|
+
~ .bn-block-group
|
|
302
|
+
[data-content-type="bulletListItem"]
|
|
303
|
+
~ .bn-block-group
|
|
304
|
+
> .bn-block-outer:not([data-prev-type])
|
|
305
|
+
> .bn-block
|
|
306
|
+
> div[data-type="modification"]
|
|
280
307
|
> .bn-block-content[data-content-type="bulletListItem"]::before {
|
|
281
308
|
content: "▪";
|
|
282
309
|
}
|
|
@@ -442,7 +469,6 @@ NESTED BLOCKS
|
|
|
442
469
|
position: absolute;
|
|
443
470
|
font-style: italic;
|
|
444
471
|
}
|
|
445
|
-
|
|
446
472
|
/* TODO: should this be here? */
|
|
447
473
|
|
|
448
474
|
/* TEXT COLORS */
|
|
@@ -75,6 +75,13 @@ it("adds id attribute when requested", async () => {
|
|
|
75
75
|
);
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
+
it("updates block", () => {
|
|
79
|
+
const editor = BlockNoteEditor.create();
|
|
80
|
+
editor.updateBlock(editor.document[0], {
|
|
81
|
+
content: "hello",
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
78
85
|
it("block prop types", () => {
|
|
79
86
|
// this test checks whether the block props are correctly typed in typescript
|
|
80
87
|
const editor = BlockNoteEditor.create();
|