@blocknote/core 0.5.0 → 0.6.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.
Files changed (39) hide show
  1. package/dist/blocknote.js +1126 -1031
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +2 -2
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +2 -2
  7. package/src/BlockNoteEditor.ts +244 -3
  8. package/src/BlockNoteExtensions.ts +3 -2
  9. package/src/api/blockManipulation/__snapshots__/blockManipulation.test.ts.snap +35 -35
  10. package/src/api/formatConversions/__snapshots__/formatConversions.test.ts.snap +10 -10
  11. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +10 -10
  12. package/src/api/nodeConversions/nodeConversions.ts +11 -10
  13. package/src/editor.module.css +12 -3
  14. package/src/extensions/Blocks/api/inlineContentTypes.ts +3 -2
  15. package/src/extensions/Blocks/api/selectionTypes.ts +5 -0
  16. package/src/extensions/Blocks/nodes/Block.module.css +20 -2
  17. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +5 -6
  18. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +5 -2
  19. package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.ts +76 -113
  20. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +6 -3
  21. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +2 -34
  22. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +39 -113
  23. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +56 -39
  24. package/src/extensions/UniqueID/UniqueID.ts +1 -1
  25. package/src/index.ts +1 -0
  26. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +14 -2
  27. package/types/src/BlockNoteEditor.d.ts +79 -0
  28. package/types/src/extensions/Blocks/api/inlineContentTypes.d.ts +3 -2
  29. package/types/src/extensions/Blocks/api/selectionTypes.d.ts +4 -0
  30. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +4 -5
  31. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +3 -1
  32. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +14 -16
  33. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +2 -0
  34. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +2 -25
  35. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +9 -4
  36. package/types/src/index.d.ts +1 -0
  37. package/types/src/api/Editor.d.ts +0 -93
  38. package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +0 -24
  39. package/types/src/extensions/SlashMenu/defaultSlashCommands.d.ts +0 -5
@@ -65,7 +65,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested HTML to
65
65
  "type": "text",
66
66
  },
67
67
  ],
68
- "id": 27,
68
+ "id": "27",
69
69
  "props": {
70
70
  "backgroundColor": "default",
71
71
  "level": "1",
@@ -83,7 +83,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested HTML to
83
83
  "type": "text",
84
84
  },
85
85
  ],
86
- "id": 28,
86
+ "id": "28",
87
87
  "props": {
88
88
  "backgroundColor": "default",
89
89
  "textAlignment": "left",
@@ -100,7 +100,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested HTML to
100
100
  "type": "text",
101
101
  },
102
102
  ],
103
- "id": 29,
103
+ "id": "29",
104
104
  "props": {
105
105
  "backgroundColor": "default",
106
106
  "textAlignment": "left",
@@ -117,7 +117,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested HTML to
117
117
  "type": "text",
118
118
  },
119
119
  ],
120
- "id": 30,
120
+ "id": "30",
121
121
  "props": {
122
122
  "backgroundColor": "default",
123
123
  "textAlignment": "left",
@@ -139,7 +139,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested Markdow
139
139
  "type": "text",
140
140
  },
141
141
  ],
142
- "id": 27,
142
+ "id": "27",
143
143
  "props": {
144
144
  "backgroundColor": "default",
145
145
  "level": "1",
@@ -157,7 +157,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested Markdow
157
157
  "type": "text",
158
158
  },
159
159
  ],
160
- "id": 28,
160
+ "id": "28",
161
161
  "props": {
162
162
  "backgroundColor": "default",
163
163
  "textAlignment": "left",
@@ -174,7 +174,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested Markdow
174
174
  "type": "text",
175
175
  },
176
176
  ],
177
- "id": 29,
177
+ "id": "29",
178
178
  "props": {
179
179
  "backgroundColor": "default",
180
180
  "textAlignment": "left",
@@ -191,7 +191,7 @@ exports[`Non-Nested Block/HTML/Markdown Conversions > Convert non-nested Markdow
191
191
  "type": "text",
192
192
  },
193
193
  ],
194
- "id": 30,
194
+ "id": "30",
195
195
  "props": {
196
196
  "backgroundColor": "default",
197
197
  "textAlignment": "left",
@@ -271,7 +271,7 @@ exports[`Styled Block/HTML/Markdown Conversions > Convert styled HTML to blocks
271
271
  "type": "text",
272
272
  },
273
273
  ],
274
- "id": 27,
274
+ "id": "27",
275
275
  "props": {
276
276
  "backgroundColor": "default",
277
277
  "textAlignment": "left",
@@ -327,7 +327,7 @@ exports[`Styled Block/HTML/Markdown Conversions > Convert styled Markdown to blo
327
327
  "type": "text",
328
328
  },
329
329
  ],
330
- "id": 27,
330
+ "id": "27",
331
331
  "props": {
332
332
  "backgroundColor": "default",
333
333
  "textAlignment": "left",
@@ -4,7 +4,7 @@ exports[`Complex ProseMirror Node Conversions > Convert complex block to node 1`
4
4
  {
5
5
  "attrs": {
6
6
  "backgroundColor": "blue",
7
- "id": 4,
7
+ "id": "4",
8
8
  "textColor": "yellow",
9
9
  },
10
10
  "content": [
@@ -46,7 +46,7 @@ exports[`Complex ProseMirror Node Conversions > Convert complex block to node 1`
46
46
  {
47
47
  "attrs": {
48
48
  "backgroundColor": "red",
49
- "id": 5,
49
+ "id": "5",
50
50
  "textColor": "default",
51
51
  },
52
52
  "content": [
@@ -68,7 +68,7 @@ exports[`Complex ProseMirror Node Conversions > Convert complex block to node 1`
68
68
  {
69
69
  "attrs": {
70
70
  "backgroundColor": "default",
71
- "id": 6,
71
+ "id": "6",
72
72
  "textColor": "default",
73
73
  },
74
74
  "content": [
@@ -101,7 +101,7 @@ exports[`Complex ProseMirror Node Conversions > Convert complex node to block 1`
101
101
  "type": "text",
102
102
  },
103
103
  ],
104
- "id": 2,
104
+ "id": "2",
105
105
  "props": {
106
106
  "backgroundColor": "red",
107
107
  "textAlignment": "left",
@@ -112,7 +112,7 @@ exports[`Complex ProseMirror Node Conversions > Convert complex node to block 1`
112
112
  {
113
113
  "children": [],
114
114
  "content": [],
115
- "id": 3,
115
+ "id": "3",
116
116
  "props": {
117
117
  "backgroundColor": "default",
118
118
  "textAlignment": "left",
@@ -139,7 +139,7 @@ exports[`Complex ProseMirror Node Conversions > Convert complex node to block 1`
139
139
  "type": "text",
140
140
  },
141
141
  ],
142
- "id": 1,
142
+ "id": "1",
143
143
  "props": {
144
144
  "backgroundColor": "blue",
145
145
  "level": "2",
@@ -154,7 +154,7 @@ exports[`Simple ProseMirror Node Conversions > Convert simple block to node 1`]
154
154
  {
155
155
  "attrs": {
156
156
  "backgroundColor": "default",
157
- "id": 4,
157
+ "id": "4",
158
158
  "textColor": "default",
159
159
  },
160
160
  "content": [
@@ -173,7 +173,7 @@ exports[`Simple ProseMirror Node Conversions > Convert simple node to block 1`]
173
173
  {
174
174
  "children": [],
175
175
  "content": [],
176
- "id": 0,
176
+ "id": "0",
177
177
  "props": {
178
178
  "backgroundColor": "default",
179
179
  "textAlignment": "left",
@@ -187,7 +187,7 @@ exports[`links > Convert a block with link 1`] = `
187
187
  {
188
188
  "attrs": {
189
189
  "backgroundColor": "default",
190
- "id": 4,
190
+ "id": "4",
191
191
  "textColor": "default",
192
192
  },
193
193
  "content": [
@@ -222,7 +222,7 @@ exports[`links > Convert two adjacent links in a block 1`] = `
222
222
  {
223
223
  "attrs": {
224
224
  "backgroundColor": "default",
225
- "id": 4,
225
+ "id": "4",
226
226
  "textColor": "default",
227
227
  },
228
228
  "content": [
@@ -6,26 +6,27 @@ import {
6
6
  PartialBlock,
7
7
  } from "../../extensions/Blocks/api/blockTypes";
8
8
  import {
9
- ColorStyles,
9
+ ColorStyle,
10
10
  InlineContent,
11
11
  Link,
12
12
  PartialInlineContent,
13
13
  PartialLink,
14
14
  StyledText,
15
15
  Styles,
16
- ToggledStyles,
16
+ ToggledStyle,
17
17
  } from "../../extensions/Blocks/api/inlineContentTypes";
18
18
  import { getBlockInfoFromPos } from "../../extensions/Blocks/helpers/getBlockInfoFromPos";
19
19
  import UniqueID from "../../extensions/UniqueID/UniqueID";
20
20
  import { UnreachableCaseError } from "../../shared/utils";
21
21
 
22
- const toggleStyles = new Set<ToggledStyles>([
22
+ const toggleStyles = new Set<ToggledStyle>([
23
23
  "bold",
24
24
  "italic",
25
25
  "underline",
26
26
  "strike",
27
+ "code",
27
28
  ]);
28
- const colorStyles = new Set<ColorStyles>(["textColor", "backgroundColor"]);
29
+ const colorStyles = new Set<ColorStyle>(["textColor", "backgroundColor"]);
29
30
 
30
31
  /**
31
32
  * Convert a StyledText inline element to a
@@ -35,9 +36,9 @@ function styledTextToNode(styledText: StyledText, schema: Schema): Node {
35
36
  const marks: Mark[] = [];
36
37
 
37
38
  for (const [style, value] of Object.entries(styledText.styles)) {
38
- if (toggleStyles.has(style as ToggledStyles)) {
39
+ if (toggleStyles.has(style as ToggledStyle)) {
39
40
  marks.push(schema.mark(style));
40
- } else if (colorStyles.has(style as ColorStyles)) {
41
+ } else if (colorStyles.has(style as ColorStyle)) {
41
42
  marks.push(schema.mark(style, { color: value }));
42
43
  }
43
44
  }
@@ -167,10 +168,10 @@ function contentNodeToInlineContent(contentNode: Node) {
167
168
  for (const mark of node.marks) {
168
169
  if (mark.type.name === "link") {
169
170
  linkMark = mark;
170
- } else if (toggleStyles.has(mark.type.name as ToggledStyles)) {
171
- styles[mark.type.name as ToggledStyles] = true;
172
- } else if (colorStyles.has(mark.type.name as ColorStyles)) {
173
- styles[mark.type.name as ColorStyles] = mark.attrs.color;
171
+ } else if (toggleStyles.has(mark.type.name as ToggledStyle)) {
172
+ styles[mark.type.name as ToggledStyle] = true;
173
+ } else if (colorStyles.has(mark.type.name as ColorStyle)) {
174
+ styles[mark.type.name as ColorStyle] = mark.attrs.color;
174
175
  } else {
175
176
  throw Error("Mark is of an unrecognized type: " + mark.type.name);
176
177
  }
@@ -2,7 +2,8 @@
2
2
 
3
3
  .bnEditor {
4
4
  outline: none;
5
- margin-left: 50px;
5
+ padding-inline: 50px;
6
+ border-radius: 8px;
6
7
 
7
8
  /* Define a set of colors to be used throughout the app for consistency
8
9
  see https://atlassian.design/foundations/color for more info */
@@ -36,7 +37,7 @@ Tippy popups that are appended to document.body directly
36
37
  .defaultStyles h2,
37
38
  .defaultStyles h3,
38
39
  .defaultStyles li {
39
- all: unset;
40
+ all: unset !important;
40
41
  margin: 0;
41
42
  padding: 0;
42
43
  font-size: inherit;
@@ -50,8 +51,16 @@ Tippy popups that are appended to document.body directly
50
51
  "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
51
52
  -webkit-font-smoothing: antialiased;
52
53
  -moz-osx-font-smoothing: grayscale;
54
+ }
55
+
56
+ [data-theme="light"] {
57
+ background-color: #FFFFFF;
58
+ color: #444444;
59
+ }
53
60
 
54
- color: rgb(60, 65, 73);
61
+ [data-theme="dark"] {
62
+ background-color: #444444;
63
+ color: #DDDDDD;
55
64
  }
56
65
 
57
66
  .dragPreview {
@@ -3,15 +3,16 @@ export type Styles = {
3
3
  italic?: true;
4
4
  underline?: true;
5
5
  strike?: true;
6
+ code?: true;
6
7
  textColor?: string;
7
8
  backgroundColor?: string;
8
9
  };
9
10
 
10
- export type ToggledStyles = {
11
+ export type ToggledStyle = {
11
12
  [K in keyof Styles]-?: Required<Styles>[K] extends true ? K : never;
12
13
  }[keyof Styles];
13
14
 
14
- export type ColorStyles = {
15
+ export type ColorStyle = {
15
16
  [K in keyof Styles]-?: Required<Styles>[K] extends string ? K : never;
16
17
  }[keyof Styles];
17
18
 
@@ -0,0 +1,5 @@
1
+ import { Block } from "./blockTypes";
2
+
3
+ export type Selection = {
4
+ blocks: Block[];
5
+ };
@@ -34,13 +34,22 @@ NESTED BLOCKS
34
34
  .blockGroup .blockGroup > .blockOuter:not([data-prev-depth-changed])::before {
35
35
  content: " ";
36
36
  display: inline;
37
- border-left: 1px solid #ccc;
38
37
  position: absolute;
39
38
  left: -20px;
40
39
  height: 100%;
41
40
  transition: all 0.2s 0.1s;
42
41
  }
43
42
 
43
+ [data-theme="light"] .blockGroup .blockGroup
44
+ > .blockOuter:not([data-prev-depth-changed])::before {
45
+ border-left: 1px solid #CCCCCC;
46
+ }
47
+
48
+ [data-theme="dark"] .blockGroup .blockGroup
49
+ > .blockOuter:not([data-prev-depth-changed])::before {
50
+ border-left: 1px solid #999999;
51
+ }
52
+
44
53
  .blockGroup .blockGroup > .blockOuter[data-prev-depth-change="-2"]::before {
45
54
  height: 0;
46
55
  }
@@ -216,7 +225,6 @@ NESTED BLOCKS
216
225
  .blockContent.isFilter > :first-child:before {
217
226
  /*float: left; */
218
227
  content: "";
219
- color: #aeb8c2;
220
228
  pointer-events: none;
221
229
  height: 0;
222
230
  /* width: 0; */
@@ -224,6 +232,16 @@ NESTED BLOCKS
224
232
  font-style: italic;
225
233
  }
226
234
 
235
+ [data-theme="light"] .blockContent.isEmpty > :first-child:before,
236
+ .blockContent.isFilter > :first-child:before {
237
+ color: #CCCCCC;
238
+ }
239
+
240
+ [data-theme="dark"] .blockContent.isEmpty > :first-child:before,
241
+ .blockContent.isFilter > :first-child:before {
242
+ color: #999999;
243
+ }
244
+
227
245
  /* TODO: would be nicer if defined from code */
228
246
 
229
247
  .blockContent.isEmpty.hasAnchor > :first-child:before {
@@ -1,22 +1,21 @@
1
1
  import { EditorElement, ElementFactory } from "../../shared/EditorElement";
2
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
3
+ import { Block } from "../Blocks/api/blockTypes";
2
4
 
3
5
  export type BlockSideMenuStaticParams = {
6
+ editor: BlockNoteEditor;
7
+
4
8
  addBlock: () => void;
5
- deleteBlock: () => void;
6
9
 
7
10
  blockDragStart: (event: DragEvent) => void;
8
11
  blockDragEnd: () => void;
9
12
 
10
13
  freezeMenu: () => void;
11
14
  unfreezeMenu: () => void;
12
-
13
- setBlockTextColor: (color: string) => void;
14
- setBlockBackgroundColor: (color: string) => void;
15
15
  };
16
16
 
17
17
  export type BlockSideMenuDynamicParams = {
18
- blockTextColor: string;
19
- blockBackgroundColor: string;
18
+ block: Block;
20
19
 
21
20
  referenceRect: DOMRect;
22
21
  };
@@ -1,9 +1,11 @@
1
1
  import { Editor, Extension } from "@tiptap/core";
2
2
  import { BlockSideMenuFactory } from "./BlockSideMenuFactoryTypes";
3
3
  import { createDraggableBlocksPlugin } from "./DraggableBlocksPlugin";
4
+ import { BlockNoteEditor } from "../../BlockNoteEditor";
4
5
 
5
6
  export type DraggableBlocksOptions = {
6
- editor: Editor;
7
+ tiptapEditor: Editor;
8
+ editor: BlockNoteEditor;
7
9
  blockSideMenuFactory: BlockSideMenuFactory;
8
10
  };
9
11
 
@@ -25,7 +27,8 @@ export const DraggableBlocksExtension =
25
27
  }
26
28
  return [
27
29
  createDraggableBlocksPlugin({
28
- editor: this.editor,
30
+ tiptapEditor: this.editor,
31
+ editor: this.options.editor,
29
32
  blockSideMenuFactory: this.options.blockSideMenuFactory,
30
33
  }),
31
34
  ];