@blocknote/core 0.30.0 → 0.30.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 (148) hide show
  1. package/dist/blocknote.cjs +2 -2
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +22 -20
  4. package/dist/blocknote.js.map +1 -1
  5. package/dist/comments.cjs.map +1 -1
  6. package/dist/comments.js.map +1 -1
  7. package/dist/style.css +1 -1
  8. package/dist/tsconfig.tsbuildinfo +1 -1
  9. package/dist/webpack-stats.json +1 -1
  10. package/package.json +5 -3
  11. package/src/api/README.md +1 -1
  12. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
  13. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -5
  14. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
  15. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
  16. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
  17. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
  18. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
  19. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
  20. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +7 -7
  21. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
  22. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
  23. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -42
  24. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +18 -18
  25. package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
  26. package/src/api/blockManipulation/insertContentAt.ts +1 -1
  27. package/src/api/blockManipulation/selections/selection.ts +11 -11
  28. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +7 -7
  29. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +6 -6
  30. package/src/api/blockManipulation/tables/tables.test.ts +106 -106
  31. package/src/api/blockManipulation/tables/tables.ts +35 -35
  32. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
  33. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
  34. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
  35. package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
  36. package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
  37. package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
  38. package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
  39. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
  40. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
  41. package/src/api/exporters/markdown/markdownExporter.ts +3 -3
  42. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
  43. package/src/api/getBlockInfoFromPos.ts +6 -6
  44. package/src/api/nodeConversions/blockToNode.ts +26 -26
  45. package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
  46. package/src/api/nodeConversions/nodeToBlock.ts +37 -33
  47. package/src/api/nodeUtil.test.ts +16 -16
  48. package/src/api/nodeUtil.ts +10 -10
  49. package/src/api/parsers/html/parseHTML.ts +1 -1
  50. package/src/api/parsers/html/util/nestedLists.ts +2 -2
  51. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  52. package/src/api/pmUtil.ts +4 -4
  53. package/src/api/positionMapping.test.ts +3 -3
  54. package/src/api/positionMapping.ts +5 -5
  55. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
  56. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +12 -12
  57. package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
  58. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
  59. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +5 -5
  60. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
  61. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
  62. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
  63. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
  64. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
  65. package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
  66. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
  67. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
  68. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
  69. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
  70. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  71. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  72. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
  73. package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
  74. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
  75. package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
  76. package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
  77. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
  78. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
  79. package/src/blocks/README.md +1 -1
  80. package/src/blocks/TableBlockContent/TableBlockContent.ts +5 -5
  81. package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
  82. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
  83. package/src/blocks/defaultBlockHelpers.ts +8 -8
  84. package/src/blocks/defaultBlockTypeGuards.ts +16 -16
  85. package/src/blocks/defaultBlocks.ts +3 -3
  86. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
  87. package/src/comments/threadstore/ThreadStore.ts +1 -1
  88. package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
  89. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
  90. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
  91. package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
  92. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
  93. package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
  94. package/src/editor/Block.css +8 -0
  95. package/src/editor/BlockNoteEditor.test.ts +3 -3
  96. package/src/editor/BlockNoteEditor.ts +7 -1
  97. package/src/editor/BlockNoteExtensions.ts +10 -10
  98. package/src/editor/BlockNoteSchema.ts +4 -4
  99. package/src/editor/BlockNoteTipTapEditor.ts +10 -10
  100. package/src/editor/README.md +1 -1
  101. package/src/editor/cursorPositionTypes.ts +1 -1
  102. package/src/editor/editor.css +15 -3
  103. package/src/editor/selectionTypes.ts +1 -1
  104. package/src/editor/transformPasted.ts +2 -2
  105. package/src/exporter/Exporter.ts +5 -5
  106. package/src/exporter/mapping.ts +7 -7
  107. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  108. package/src/extensions/Collaboration/CursorPlugin.ts +2 -2
  109. package/src/extensions/Comments/CommentsPlugin.ts +9 -9
  110. package/src/extensions/Comments/userstore/UserStore.ts +2 -2
  111. package/src/extensions/FilePanel/FilePanelPlugin.ts +7 -7
  112. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +4 -4
  113. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
  114. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -11
  115. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +4 -4
  116. package/src/extensions/Placeholder/PlaceholderPlugin.ts +10 -10
  117. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +2 -2
  118. package/src/extensions/README.md +1 -1
  119. package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
  120. package/src/extensions/SideMenu/SideMenuPlugin.ts +31 -31
  121. package/src/extensions/SideMenu/dragging.ts +8 -8
  122. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -17
  123. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
  124. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +12 -12
  125. package/src/extensions/TableHandles/TableHandlesPlugin.ts +54 -53
  126. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  127. package/src/extensions/UniqueID/UniqueID.ts +6 -6
  128. package/src/extensions/getDraggableBlockFromElement.ts +1 -1
  129. package/src/fonts/inter.css +18 -9
  130. package/src/locales.ts +1 -1
  131. package/src/pm-nodes/BlockGroup.ts +1 -1
  132. package/src/pm-nodes/Doc.ts +4 -4
  133. package/src/schema/README.md +1 -1
  134. package/src/schema/blocks/createSpec.ts +14 -14
  135. package/src/schema/blocks/internal.ts +17 -17
  136. package/src/schema/blocks/types.ts +25 -25
  137. package/src/schema/inlineContent/createSpec.ts +16 -20
  138. package/src/schema/inlineContent/internal.ts +9 -9
  139. package/src/schema/inlineContent/types.ts +26 -26
  140. package/src/schema/propTypes.ts +8 -8
  141. package/src/schema/styles/createSpec.ts +2 -2
  142. package/src/schema/styles/internal.ts +7 -7
  143. package/src/schema/styles/types.ts +2 -2
  144. package/src/util/EventEmitter.ts +4 -4
  145. package/src/util/README.md +1 -1
  146. package/src/util/combineByGroup.ts +1 -1
  147. package/src/util/table.ts +33 -30
  148. package/types/src/editor/BlockNoteEditor.d.ts +3 -1
@@ -18,12 +18,12 @@ export function createDefaultBlockDOMOutputSpec(
18
18
  blockName: string,
19
19
  htmlTag: string,
20
20
  blockContentHTMLAttributes: Record<string, string>,
21
- inlineContentHTMLAttributes: Record<string, string>
21
+ inlineContentHTMLAttributes: Record<string, string>,
22
22
  ) {
23
23
  const blockContent = document.createElement("div");
24
24
  blockContent.className = mergeCSSClasses(
25
25
  "bn-block-content",
26
- blockContentHTMLAttributes.class
26
+ blockContentHTMLAttributes.class,
27
27
  );
28
28
  blockContent.setAttribute("data-content-type", blockName);
29
29
  for (const [attribute, value] of Object.entries(blockContentHTMLAttributes)) {
@@ -35,10 +35,10 @@ export function createDefaultBlockDOMOutputSpec(
35
35
  const inlineContent = document.createElement(htmlTag);
36
36
  inlineContent.className = mergeCSSClasses(
37
37
  "bn-inline-content",
38
- inlineContentHTMLAttributes.class
38
+ inlineContentHTMLAttributes.class,
39
39
  );
40
40
  for (const [attribute, value] of Object.entries(
41
- inlineContentHTMLAttributes
41
+ inlineContentHTMLAttributes,
42
42
  )) {
43
43
  if (attribute !== "class") {
44
44
  inlineContent.setAttribute(attribute, value);
@@ -59,10 +59,10 @@ export function createDefaultBlockDOMOutputSpec(
59
59
  export const defaultBlockToHTML = <
60
60
  BSchema extends BlockSchema,
61
61
  I extends InlineContentSchema,
62
- S extends StyleSchema
62
+ S extends StyleSchema,
63
63
  >(
64
64
  block: BlockNoDefaults<BSchema, I, S>,
65
- editor: BlockNoteEditor<BSchema, I, S>
65
+ editor: BlockNoteEditor<BSchema, I, S>,
66
66
  ): {
67
67
  dom: HTMLElement;
68
68
  contentDOM?: HTMLElement;
@@ -78,7 +78,7 @@ export const defaultBlockToHTML = <
78
78
 
79
79
  if (toDOM === undefined) {
80
80
  throw new Error(
81
- "This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`."
81
+ "This block has no default HTML serialization as its corresponding TipTap node doesn't implement `renderHTML`.",
82
82
  );
83
83
  }
84
84
 
@@ -86,7 +86,7 @@ export const defaultBlockToHTML = <
86
86
 
87
87
  if (typeof renderSpec !== "object" || !("dom" in renderSpec)) {
88
88
  throw new Error(
89
- "Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property."
89
+ "Cannot use this block's default HTML serialization as its corresponding TipTap node's `renderHTML` function does not return an object with the `dom` property.",
90
90
  );
91
91
  }
92
92
 
@@ -20,10 +20,10 @@ import { Selection } from "prosemirror-state";
20
20
  export function checkDefaultBlockTypeInSchema<
21
21
  BlockType extends keyof DefaultBlockSchema,
22
22
  I extends InlineContentSchema,
23
- S extends StyleSchema
23
+ S extends StyleSchema,
24
24
  >(
25
25
  blockType: BlockType,
26
- editor: BlockNoteEditor<any, I, S>
26
+ editor: BlockNoteEditor<any, I, S>,
27
27
  ): editor is BlockNoteEditor<{ Type: DefaultBlockSchema[BlockType] }, I, S> {
28
28
  return (
29
29
  blockType in editor.schema.blockSchema &&
@@ -34,10 +34,10 @@ export function checkDefaultBlockTypeInSchema<
34
34
  export function checkDefaultInlineContentTypeInSchema<
35
35
  InlineContentType extends keyof DefaultInlineContentSchema,
36
36
  B extends BlockSchema,
37
- S extends StyleSchema
37
+ S extends StyleSchema,
38
38
  >(
39
39
  inlineContentType: InlineContentType,
40
- editor: BlockNoteEditor<B, any, S>
40
+ editor: BlockNoteEditor<B, any, S>,
41
41
  ): editor is BlockNoteEditor<
42
42
  B,
43
43
  { Type: DefaultInlineContentSchema[InlineContentType] },
@@ -53,11 +53,11 @@ export function checkDefaultInlineContentTypeInSchema<
53
53
  export function checkBlockIsDefaultType<
54
54
  BlockType extends keyof DefaultBlockSchema,
55
55
  I extends InlineContentSchema,
56
- S extends StyleSchema
56
+ S extends StyleSchema,
57
57
  >(
58
58
  blockType: BlockType,
59
59
  block: Block<any, I, S>,
60
- editor: BlockNoteEditor<any, I, S>
60
+ editor: BlockNoteEditor<any, I, S>,
61
61
  ): block is BlockFromConfig<DefaultBlockSchema[BlockType], I, S> {
62
62
  return (
63
63
  block.type === blockType &&
@@ -69,10 +69,10 @@ export function checkBlockIsDefaultType<
69
69
  export function checkBlockIsFileBlock<
70
70
  B extends BlockSchema,
71
71
  I extends InlineContentSchema,
72
- S extends StyleSchema
72
+ S extends StyleSchema,
73
73
  >(
74
74
  block: Block<any, I, S>,
75
- editor: BlockNoteEditor<B, I, S>
75
+ editor: BlockNoteEditor<B, I, S>,
76
76
  ): block is BlockFromConfig<FileBlockConfig, I, S> {
77
77
  return (
78
78
  (block.type in editor.schema.blockSchema &&
@@ -84,10 +84,10 @@ export function checkBlockIsFileBlock<
84
84
  export function checkBlockIsFileBlockWithPreview<
85
85
  B extends BlockSchema,
86
86
  I extends InlineContentSchema,
87
- S extends StyleSchema
87
+ S extends StyleSchema,
88
88
  >(
89
89
  block: Block<any, I, S>,
90
- editor: BlockNoteEditor<B, I, S>
90
+ editor: BlockNoteEditor<B, I, S>,
91
91
  ): block is BlockFromConfig<
92
92
  FileBlockConfig & {
93
93
  propSchema: Required<FileBlockConfig["propSchema"]>;
@@ -106,7 +106,7 @@ export function checkBlockIsFileBlockWithPreview<
106
106
  export function checkBlockIsFileBlockWithPlaceholder<
107
107
  B extends BlockSchema,
108
108
  I extends InlineContentSchema,
109
- S extends StyleSchema
109
+ S extends StyleSchema,
110
110
  >(block: Block<B, I, S>, editor: BlockNoteEditor<B, I, S>) {
111
111
  const config = editor.schema.blockSchema[block.type];
112
112
  return config.isFileBlock && !block.props.url;
@@ -115,11 +115,11 @@ export function checkBlockIsFileBlockWithPlaceholder<
115
115
  export function checkBlockTypeHasDefaultProp<
116
116
  Prop extends keyof typeof defaultProps,
117
117
  I extends InlineContentSchema,
118
- S extends StyleSchema
118
+ S extends StyleSchema,
119
119
  >(
120
120
  prop: Prop,
121
121
  blockType: string,
122
- editor: BlockNoteEditor<any, I, S>
122
+ editor: BlockNoteEditor<any, I, S>,
123
123
  ): editor is BlockNoteEditor<
124
124
  {
125
125
  [BT in string]: {
@@ -143,11 +143,11 @@ export function checkBlockTypeHasDefaultProp<
143
143
  export function checkBlockHasDefaultProp<
144
144
  Prop extends keyof typeof defaultProps,
145
145
  I extends InlineContentSchema,
146
- S extends StyleSchema
146
+ S extends StyleSchema,
147
147
  >(
148
148
  prop: Prop,
149
149
  block: Block<any, I, S>,
150
- editor: BlockNoteEditor<any, I, S>
150
+ editor: BlockNoteEditor<any, I, S>,
151
151
  ): block is BlockFromConfig<
152
152
  {
153
153
  type: string;
@@ -163,7 +163,7 @@ export function checkBlockHasDefaultProp<
163
163
  }
164
164
 
165
165
  export function isTableCellSelection(
166
- selection: Selection
166
+ selection: Selection,
167
167
  ): selection is CellSelection {
168
168
  return selection instanceof CellSelection;
169
169
  }
@@ -78,7 +78,7 @@ export const defaultInlineContentSpecs = {
78
78
  } satisfies InlineContentSpecs;
79
79
 
80
80
  export const defaultInlineContentSchema = getInlineContentSchemaFromSpecs(
81
- defaultInlineContentSpecs
81
+ defaultInlineContentSpecs,
82
82
  );
83
83
 
84
84
  // underscore is used that in case a user overrides DefaultInlineContentSchema,
@@ -89,11 +89,11 @@ export type DefaultInlineContentSchema = _DefaultInlineContentSchema;
89
89
  export type PartialBlock<
90
90
  BSchema extends BlockSchema = DefaultBlockSchema,
91
91
  I extends InlineContentSchema = DefaultInlineContentSchema,
92
- S extends StyleSchema = DefaultStyleSchema
92
+ S extends StyleSchema = DefaultStyleSchema,
93
93
  > = PartialBlockNoDefaults<BSchema, I, S>;
94
94
 
95
95
  export type Block<
96
96
  BSchema extends BlockSchema = DefaultBlockSchema,
97
97
  I extends InlineContentSchema = DefaultInlineContentSchema,
98
- S extends StyleSchema = DefaultStyleSchema
98
+ S extends StyleSchema = DefaultStyleSchema,
99
99
  > = BlockNoDefaults<BSchema, I, S>;
@@ -18,7 +18,7 @@ import { ThreadStoreAuth } from "./ThreadStoreAuth.js";
18
18
  export class DefaultThreadStoreAuth extends ThreadStoreAuth {
19
19
  constructor(
20
20
  private readonly userId: string,
21
- private readonly role: "comment" | "editor"
21
+ private readonly role: "comment" | "editor",
22
22
  ) {
23
23
  super();
24
24
  }
@@ -84,7 +84,7 @@ export class DefaultThreadStoreAuth extends ThreadStoreAuth {
84
84
 
85
85
  return !comment.reactions.some(
86
86
  (reaction) =>
87
- reaction.emoji === emoji && reaction.userIds.includes(this.userId)
87
+ reaction.emoji === emoji && reaction.userIds.includes(this.userId),
88
88
  );
89
89
  }
90
90
 
@@ -100,7 +100,7 @@ export class DefaultThreadStoreAuth extends ThreadStoreAuth {
100
100
 
101
101
  return comment.reactions.some(
102
102
  (reaction) =>
103
- reaction.emoji === emoji && reaction.userIds.includes(this.userId)
103
+ reaction.emoji === emoji && reaction.userIds.includes(this.userId),
104
104
  );
105
105
  }
106
106
  }
@@ -129,6 +129,6 @@ export abstract class ThreadStore {
129
129
  * @returns a function to unsubscribe from the thread store
130
130
  */
131
131
  abstract subscribe(
132
- cb: (threads: Map<string, ThreadData>) => void
132
+ cb: (threads: Map<string, ThreadData>) => void,
133
133
  ): () => void;
134
134
  }
@@ -28,7 +28,7 @@ export class TiptapThreadStore extends ThreadStore {
28
28
  constructor(
29
29
  private readonly userId: string,
30
30
  private readonly provider: TiptapCollabProvider,
31
- auth: ThreadStoreAuth // TODO: use?
31
+ auth: ThreadStoreAuth, // TODO: use?
32
32
  ) {
33
33
  super(auth);
34
34
  }
@@ -80,7 +80,7 @@ export class TiptapThreadStore extends ThreadStore {
80
80
  });
81
81
 
82
82
  return this.tiptapCommentToCommentData(
83
- thread.comments[thread.comments.length - 1]
83
+ thread.comments[thread.comments.length - 1],
84
84
  );
85
85
  }
86
86
 
@@ -98,7 +98,7 @@ export class TiptapThreadStore extends ThreadStore {
98
98
  const comment = this.provider.getThreadComment(
99
99
  options.threadId,
100
100
  options.commentId,
101
- true
101
+ true,
102
102
  );
103
103
 
104
104
  if (!comment) {
@@ -120,12 +120,12 @@ export class TiptapThreadStore extends ThreadStore {
120
120
  for (const reaction of (comment.data?.reactions ||
121
121
  []) as ReactionAsTiptapData[]) {
122
122
  const existingReaction = reactions.find(
123
- (r) => r.emoji === reaction.emoji
123
+ (r) => r.emoji === reaction.emoji,
124
124
  );
125
125
  if (existingReaction) {
126
126
  existingReaction.userIds.push(reaction.userId);
127
127
  existingReaction.createdAt = new Date(
128
- Math.min(existingReaction.createdAt.getTime(), reaction.createdAt)
128
+ Math.min(existingReaction.createdAt.getTime(), reaction.createdAt),
129
129
  );
130
130
  } else {
131
131
  reactions.push({
@@ -153,7 +153,7 @@ export class TiptapThreadStore extends ThreadStore {
153
153
  type: "thread",
154
154
  id: thread.id,
155
155
  comments: thread.comments.map((comment) =>
156
- this.tiptapCommentToCommentData(comment)
156
+ this.tiptapCommentToCommentData(comment),
157
157
  ),
158
158
  resolved: !!thread.resolvedAt,
159
159
  metadata: thread.data?.metadata,
@@ -207,7 +207,7 @@ export class TiptapThreadStore extends ThreadStore {
207
207
  const comment = this.provider.getThreadComment(
208
208
  options.threadId,
209
209
  options.commentId,
210
- true
210
+ true,
211
211
  );
212
212
 
213
213
  if (!comment) {
@@ -242,7 +242,7 @@ export class TiptapThreadStore extends ThreadStore {
242
242
  const comment = this.provider.getThreadComment(
243
243
  options.threadId,
244
244
  options.commentId,
245
- true
245
+ true,
246
246
  );
247
247
 
248
248
  if (!comment) {
@@ -256,7 +256,7 @@ export class TiptapThreadStore extends ThreadStore {
256
256
  (comment.data?.reactions || []) as ReactionAsTiptapData[]
257
257
  ).filter(
258
258
  (reaction) =>
259
- reaction.emoji !== options.emoji && reaction.userId !== this.userId
259
+ reaction.emoji !== options.emoji && reaction.userId !== this.userId,
260
260
  ),
261
261
  },
262
262
  });
@@ -276,7 +276,7 @@ export class TiptapThreadStore extends ThreadStore {
276
276
  return new Map(
277
277
  this.provider
278
278
  .getThreads()
279
- .map((thread) => [thread.id, this.tiptapThreadToThreadData(thread)])
279
+ .map((thread) => [thread.id, this.tiptapThreadToThreadData(thread)]),
280
280
  );
281
281
  }
282
282
 
@@ -22,7 +22,7 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
22
22
  private readonly BASE_URL: string,
23
23
  private readonly headers: Record<string, string>,
24
24
  threadsYMap: Y.Map<any>,
25
- auth: ThreadStoreAuth
25
+ auth: ThreadStoreAuth,
26
26
  ) {
27
27
  super(threadsYMap, auth);
28
28
  }
@@ -102,7 +102,7 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
102
102
  const { threadId, commentId, ...rest } = options;
103
103
  return this.doRequest(
104
104
  `/${threadId}/comments/${commentId}?soft=${!!rest.softDelete}`,
105
- "DELETE"
105
+ "DELETE",
106
106
  );
107
107
  };
108
108
 
@@ -127,7 +127,7 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
127
127
  return this.doRequest(
128
128
  `/${threadId}/comments/${commentId}/reactions`,
129
129
  "POST",
130
- rest
130
+ rest,
131
131
  );
132
132
  };
133
133
 
@@ -138,7 +138,7 @@ export class RESTYjsThreadStore extends YjsThreadStoreBase {
138
138
  }) => {
139
139
  return this.doRequest(
140
140
  `/${options.threadId}/comments/${options.commentId}/reactions/${options.emoji}`,
141
- "DELETE"
141
+ "DELETE",
142
142
  );
143
143
  };
144
144
  }
@@ -25,7 +25,7 @@ describe("YjsThreadStore", () => {
25
25
  store = new YjsThreadStore(
26
26
  "test-user",
27
27
  threadsYMap,
28
- new DefaultThreadStoreAuth("test-user", "editor")
28
+ new DefaultThreadStoreAuth("test-user", "editor"),
29
29
  );
30
30
  });
31
31
 
@@ -99,7 +99,7 @@ describe("YjsThreadStore", () => {
99
99
  comment: {
100
100
  body: "Test comment" as CommentBody,
101
101
  },
102
- })
102
+ }),
103
103
  ).rejects.toThrow("Thread not found");
104
104
  });
105
105
  });
@@ -26,13 +26,13 @@ export class YjsThreadStore extends YjsThreadStoreBase {
26
26
  constructor(
27
27
  private readonly userId: string,
28
28
  threadsYMap: Y.Map<any>,
29
- auth: ThreadStoreAuth
29
+ auth: ThreadStoreAuth,
30
30
  ) {
31
31
  super(threadsYMap, auth);
32
32
  }
33
33
 
34
34
  private transact = <T, R>(
35
- fn: (options: T) => R
35
+ fn: (options: T) => R,
36
36
  ): ((options: T) => Promise<R>) => {
37
37
  return async (options: T) => {
38
38
  return this.threadsYMap.doc!.transact(() => {
@@ -79,7 +79,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
79
79
  this.threadsYMap.set(thread.id, threadToYMap(thread));
80
80
 
81
81
  return thread;
82
- }
82
+ },
83
83
  );
84
84
 
85
85
  // YjsThreadStore does not support addThreadToDocument
@@ -121,7 +121,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
121
121
 
122
122
  yThread.set("updatedAt", new Date().getTime());
123
123
  return comment;
124
- }
124
+ },
125
125
  );
126
126
 
127
127
  public updateComment = this.transact(
@@ -140,7 +140,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
140
140
 
141
141
  const yCommentIndex = yArrayFindIndex(
142
142
  yThread.get("comments"),
143
- (comment) => comment.get("id") === options.commentId
143
+ (comment) => comment.get("id") === options.commentId,
144
144
  );
145
145
 
146
146
  if (yCommentIndex === -1) {
@@ -156,7 +156,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
156
156
  yComment.set("body", options.comment.body);
157
157
  yComment.set("updatedAt", new Date().getTime());
158
158
  yComment.set("metadata", options.comment.metadata);
159
- }
159
+ },
160
160
  );
161
161
 
162
162
  public deleteComment = this.transact(
@@ -172,7 +172,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
172
172
 
173
173
  const yCommentIndex = yArrayFindIndex(
174
174
  yThread.get("comments"),
175
- (comment) => comment.get("id") === options.commentId
175
+ (comment) => comment.get("id") === options.commentId,
176
176
  );
177
177
 
178
178
  if (yCommentIndex === -1) {
@@ -210,13 +210,13 @@ export class YjsThreadStore extends YjsThreadStoreBase {
210
210
  }
211
211
 
212
212
  yThread.set("updatedAt", new Date().getTime());
213
- }
213
+ },
214
214
  );
215
215
 
216
216
  public deleteThread = this.transact((options: { threadId: string }) => {
217
217
  if (
218
218
  !this.auth.canDeleteThread(
219
- yMapToThread(this.threadsYMap.get(options.threadId))
219
+ yMapToThread(this.threadsYMap.get(options.threadId)),
220
220
  )
221
221
  ) {
222
222
  throw new Error("Not authorized");
@@ -263,7 +263,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
263
263
 
264
264
  const yCommentIndex = yArrayFindIndex(
265
265
  yThread.get("comments"),
266
- (comment) => comment.get("id") === options.commentId
266
+ (comment) => comment.get("id") === options.commentId,
267
267
  );
268
268
 
269
269
  if (yCommentIndex === -1) {
@@ -292,7 +292,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
292
292
  reaction.set("userId", this.userId);
293
293
  reactionsByUser.set(key, reaction);
294
294
  }
295
- }
295
+ },
296
296
  );
297
297
 
298
298
  public deleteReaction = this.transact(
@@ -304,7 +304,7 @@ export class YjsThreadStore extends YjsThreadStoreBase {
304
304
 
305
305
  const yCommentIndex = yArrayFindIndex(
306
306
  yThread.get("comments"),
307
- (comment) => comment.get("id") === options.commentId
307
+ (comment) => comment.get("id") === options.commentId,
308
308
  );
309
309
 
310
310
  if (yCommentIndex === -1) {
@@ -324,13 +324,13 @@ export class YjsThreadStore extends YjsThreadStoreBase {
324
324
  const reactionsByUser = yComment.get("reactionsByUser");
325
325
 
326
326
  reactionsByUser.delete(key);
327
- }
327
+ },
328
328
  );
329
329
  }
330
330
 
331
331
  function yArrayFindIndex(
332
332
  yArray: Y.Array<any>,
333
- predicate: (item: any) => boolean
333
+ predicate: (item: any) => boolean,
334
334
  ) {
335
335
  for (let i = 0; i < yArray.length; i++) {
336
336
  if (predicate(yArray.get(i))) {
@@ -11,7 +11,7 @@ import { yMapToThread } from "./yjsHelpers.js";
11
11
  export abstract class YjsThreadStoreBase extends ThreadStore {
12
12
  constructor(
13
13
  protected readonly threadsYMap: Y.Map<any>,
14
- auth: ThreadStoreAuth
14
+ auth: ThreadStoreAuth,
15
15
  ) {
16
16
  super(auth);
17
17
  }
@@ -52,7 +52,7 @@ type SingleUserCommentReactionData = {
52
52
  };
53
53
 
54
54
  export function yMapToReaction(
55
- yMap: Y.Map<any>
55
+ yMap: Y.Map<any>,
56
56
  ): SingleUserCommentReactionData {
57
57
  return {
58
58
  emoji: yMap.get("emoji"),
@@ -63,7 +63,7 @@ export function yMapToReaction(
63
63
 
64
64
  function yMapToReactions(yMap: Y.Map<any>): CommentReactionData[] {
65
65
  const flatReactions = [...yMap.values()].map((reaction: Y.Map<any>) =>
66
- yMapToReaction(reaction)
66
+ yMapToReaction(reaction),
67
67
  );
68
68
  // combine reactions by the same emoji
69
69
  return flatReactions.reduce(
@@ -74,8 +74,8 @@ function yMapToReactions(yMap: Y.Map<any>): CommentReactionData[] {
74
74
  existingReaction.createdAt = new Date(
75
75
  Math.min(
76
76
  existingReaction.createdAt.getTime(),
77
- reaction.createdAt.getTime()
78
- )
77
+ reaction.createdAt.getTime(),
78
+ ),
79
79
  );
80
80
  } else {
81
81
  acc.push({
@@ -86,7 +86,7 @@ function yMapToReactions(yMap: Y.Map<any>): CommentReactionData[] {
86
86
  }
87
87
  return acc;
88
88
  },
89
- [] as CommentReactionData[]
89
+ [] as CommentReactionData[],
90
90
  );
91
91
  }
92
92
 
@@ -113,7 +113,7 @@ export function yMapToThread(yMap: Y.Map<any>): ThreadData {
113
113
  createdAt: new Date(yMap.get("createdAt")),
114
114
  updatedAt: new Date(yMap.get("updatedAt")),
115
115
  comments: ((yMap.get("comments") as Y.Array<Y.Map<any>>) || []).map(
116
- (comment) => yMapToComment(comment)
116
+ (comment) => yMapToComment(comment),
117
117
  ),
118
118
  resolved: yMap.get("resolved"),
119
119
  resolvedUpdatedAt: new Date(yMap.get("resolvedUpdatedAt")),
@@ -23,6 +23,14 @@ BASIC STYLES
23
23
  */
24
24
  }
25
25
 
26
+ /* We can't set `display: flex` on `.bn-block-content` while it has inline
27
+ content (see #1629). However, it's necessary to set alignment of blocks
28
+ without content as these can't use `text-align`, so this additional rule is
29
+ used. */
30
+ .bn-block-content:not(:has(.bn-inline-content)) {
31
+ display: flex;
32
+ }
33
+
26
34
  .bn-block-content::before {
27
35
  /* content: ""; */
28
36
  transition: all 0.2s;
@@ -18,7 +18,7 @@ it("creates an editor", () => {
18
18
  it("immediately replaces doc", async () => {
19
19
  const editor = BlockNoteEditor.create();
20
20
  const blocks = await editor.tryParseMarkdownToBlocks(
21
- "This is a normal text\n\n# And this is a large heading"
21
+ "This is a normal text\n\n# And this is a large heading",
22
22
  );
23
23
  editor.replaceBlocks(editor.document, blocks);
24
24
  expect(editor.document).toMatchInlineSnapshot(`
@@ -67,11 +67,11 @@ it("adds id attribute when requested", async () => {
67
67
  setIdAttribute: true,
68
68
  });
69
69
  const blocks = await editor.tryParseMarkdownToBlocks(
70
- "This is a normal text\n\n# And this is a large heading"
70
+ "This is a normal text\n\n# And this is a large heading",
71
71
  );
72
72
  editor.replaceBlocks(editor.document, blocks);
73
73
  expect(await editor.blocksToFullHTML(editor.document)).toMatchInlineSnapshot(
74
- `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1" id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1" id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">This is a normal text</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2" id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2" id="2"><div class="bn-block-content" data-content-type="heading"><h1 class="bn-inline-content">And this is a large heading</h1></div></div></div></div>"`
74
+ `"<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1" id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1" id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">This is a normal text</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2" id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2" id="2"><div class="bn-block-content" data-content-type="heading"><h1 class="bn-inline-content">And this is a large heading</h1></div></div></div></div>"`,
75
75
  );
76
76
  });
77
77
 
@@ -1231,7 +1231,10 @@ export class BlockNoteEditor<
1231
1231
  *
1232
1232
  * @param content can be a string, or array of partial inline content elements
1233
1233
  */
1234
- public insertInlineContent(content: PartialInlineContent<ISchema, SSchema>) {
1234
+ public insertInlineContent(
1235
+ content: PartialInlineContent<ISchema, SSchema>,
1236
+ { updateSelection = false }: { updateSelection?: boolean } = {},
1237
+ ) {
1235
1238
  const nodes = inlineContentToNodes(content, this.pmSchema);
1236
1239
 
1237
1240
  this.transact((tr) => {
@@ -1242,6 +1245,9 @@ export class BlockNoteEditor<
1242
1245
  to: tr.selection.to,
1243
1246
  },
1244
1247
  nodes,
1248
+ {
1249
+ updateSelection,
1250
+ },
1245
1251
  );
1246
1252
  });
1247
1253
  }
@@ -55,7 +55,7 @@ import type {
55
55
  type ExtensionOptions<
56
56
  BSchema extends BlockSchema,
57
57
  I extends InlineContentSchema,
58
- S extends StyleSchema
58
+ S extends StyleSchema,
59
59
  > = {
60
60
  editor: BlockNoteEditor<BSchema, I, S>;
61
61
  domAttributes: Partial<BlockNoteDOMAttributes>;
@@ -97,9 +97,9 @@ type ExtensionOptions<
97
97
  export const getBlockNoteExtensions = <
98
98
  BSchema extends BlockSchema,
99
99
  I extends InlineContentSchema,
100
- S extends StyleSchema
100
+ S extends StyleSchema,
101
101
  >(
102
- opts: ExtensionOptions<BSchema, I, S>
102
+ opts: ExtensionOptions<BSchema, I, S>,
103
103
  ) => {
104
104
  const ret: Record<string, BlockNoteExtension> = {};
105
105
  const tiptapExtensions = getTipTapExtensions(opts);
@@ -120,12 +120,12 @@ export const getBlockNoteExtensions = <
120
120
  // Note: this is pretty hardcoded and will break when user provides plugins with same keys.
121
121
  // Define name on plugins instead and not make this a map?
122
122
  ret["formattingToolbar"] = new FormattingToolbarProsemirrorPlugin(
123
- opts.editor
123
+ opts.editor,
124
124
  );
125
125
  ret["linkToolbar"] = new LinkToolbarProsemirrorPlugin(opts.editor);
126
126
  ret["sideMenu"] = new SideMenuProsemirrorPlugin(
127
127
  opts.editor,
128
- opts.sideMenuDetection
128
+ opts.sideMenuDetection,
129
129
  );
130
130
  ret["suggestionMenus"] = new SuggestionMenuProseMirrorPlugin(opts.editor);
131
131
  ret["filePanel"] = new FilePanelProsemirrorPlugin(opts.editor as any);
@@ -155,7 +155,7 @@ export const getBlockNoteExtensions = <
155
155
  ret["comments"] = new CommentsPlugin(
156
156
  opts.editor,
157
157
  opts.comments.threadStore,
158
- CommentMark.name
158
+ CommentMark.name,
159
159
  );
160
160
  }
161
161
 
@@ -175,9 +175,9 @@ let LINKIFY_INITIALIZED = false;
175
175
  const getTipTapExtensions = <
176
176
  BSchema extends BlockSchema,
177
177
  I extends InlineContentSchema,
178
- S extends StyleSchema
178
+ S extends StyleSchema,
179
179
  >(
180
- opts: ExtensionOptions<BSchema, I, S>
180
+ opts: ExtensionOptions<BSchema, I, S>,
181
181
  ) => {
182
182
  const tiptapExtensions: AnyExtension[] = [
183
183
  extensions.ClipboardTextSerializer,
@@ -264,7 +264,7 @@ const getTipTapExtensions = <
264
264
  ext.configure({
265
265
  editor: opts.editor,
266
266
  domAttributes: opts.domAttributes,
267
- })
267
+ }),
268
268
  ),
269
269
  // the actual node itself
270
270
  blockSpec.implementation.node.configure({
@@ -282,7 +282,7 @@ const getTipTapExtensions = <
282
282
  prioritizeMarkdownOverHTML?: boolean;
283
283
  plainTextAsMarkdown?: boolean;
284
284
  }) => boolean | undefined;
285
- }) => context.defaultPasteHandler())
285
+ }) => context.defaultPasteHandler()),
286
286
  ),
287
287
  createDropFileExtension(opts.editor),
288
288