@blocknote/core 0.29.1 → 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 (182) hide show
  1. package/README.md +125 -0
  2. package/dist/blocknote.cjs +9 -9
  3. package/dist/blocknote.cjs.map +1 -1
  4. package/dist/blocknote.js +1501 -1359
  5. package/dist/blocknote.js.map +1 -1
  6. package/dist/comments.cjs.map +1 -1
  7. package/dist/comments.js.map +1 -1
  8. package/dist/locales.cjs +1 -1
  9. package/dist/locales.cjs.map +1 -1
  10. package/dist/locales.js +751 -9
  11. package/dist/locales.js.map +1 -1
  12. package/dist/style.css +1 -1
  13. package/dist/tsconfig.tsbuildinfo +1 -1
  14. package/dist/webpack-stats.json +1 -1
  15. package/package.json +7 -8
  16. package/src/api/README.md +1 -1
  17. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +0 -7
  18. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
  19. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +5 -5
  20. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +0 -5
  21. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
  22. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +12 -12
  23. package/src/api/blockManipulation/commands/moveBlocks/__snapshots__/moveBlocks.test.ts.snap +0 -20
  24. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +14 -14
  25. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
  26. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
  27. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +0 -12
  28. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
  29. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +7 -7
  30. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +0 -6
  31. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
  32. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
  33. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +0 -17
  34. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -42
  35. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +18 -18
  36. package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
  37. package/src/api/blockManipulation/insertContentAt.ts +1 -1
  38. package/src/api/blockManipulation/selections/selection.ts +11 -11
  39. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +7 -7
  40. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +6 -6
  41. package/src/api/blockManipulation/tables/tables.test.ts +106 -106
  42. package/src/api/blockManipulation/tables/tables.ts +35 -35
  43. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
  44. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
  45. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
  46. package/src/api/clipboard/fromClipboard/pasteExtension.ts +21 -3
  47. package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
  48. package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
  49. package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
  50. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
  51. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
  52. package/src/api/exporters/markdown/markdownExporter.ts +3 -3
  53. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
  54. package/src/api/getBlockInfoFromPos.ts +6 -6
  55. package/src/api/nodeConversions/blockToNode.ts +26 -26
  56. package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
  57. package/src/api/nodeConversions/nodeToBlock.ts +37 -33
  58. package/src/api/nodeUtil.test.ts +16 -16
  59. package/src/api/nodeUtil.ts +10 -10
  60. package/src/api/parsers/html/parseHTML.ts +1 -1
  61. package/src/api/parsers/html/util/nestedLists.ts +2 -2
  62. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  63. package/src/api/pmUtil.ts +4 -4
  64. package/src/api/positionMapping.test.ts +3 -3
  65. package/src/api/positionMapping.ts +5 -5
  66. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +9 -4
  67. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +40 -26
  68. package/src/blocks/FileBlockContent/FileBlockContent.ts +7 -2
  69. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
  70. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +5 -5
  71. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
  72. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
  73. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +15 -8
  74. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
  75. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
  76. package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
  77. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +9 -6
  78. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +14 -6
  79. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +13 -29
  80. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +24 -13
  81. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  82. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  83. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +13 -30
  84. package/src/blocks/ListItemBlockContent/getListItemContent.ts +115 -0
  85. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
  86. package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
  87. package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
  88. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +9 -5
  89. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +10 -5
  90. package/src/blocks/README.md +1 -1
  91. package/src/blocks/TableBlockContent/TableBlockContent.ts +76 -19
  92. package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
  93. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +14 -6
  94. package/src/blocks/defaultBlockHelpers.ts +24 -8
  95. package/src/blocks/defaultBlockTypeGuards.ts +16 -16
  96. package/src/blocks/defaultBlocks.ts +3 -3
  97. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
  98. package/src/comments/threadstore/ThreadStore.ts +1 -1
  99. package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
  100. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
  101. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
  102. package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
  103. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
  104. package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
  105. package/src/editor/Block.css +10 -1
  106. package/src/editor/BlockNoteEditor.test.ts +3 -3
  107. package/src/editor/BlockNoteEditor.ts +110 -61
  108. package/src/editor/BlockNoteExtensions.ts +24 -15
  109. package/src/editor/BlockNoteSchema.ts +4 -4
  110. package/src/editor/BlockNoteTipTapEditor.ts +10 -10
  111. package/src/editor/README.md +1 -1
  112. package/src/editor/cursorPositionTypes.ts +1 -1
  113. package/src/editor/editor.css +15 -3
  114. package/src/editor/selectionTypes.ts +1 -1
  115. package/src/editor/transformPasted.ts +2 -2
  116. package/src/exporter/Exporter.ts +5 -5
  117. package/src/exporter/mapping.ts +7 -7
  118. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  119. package/src/extensions/Collaboration/CursorPlugin.ts +152 -0
  120. package/src/extensions/Collaboration/SyncPlugin.ts +15 -0
  121. package/src/extensions/Collaboration/UndoPlugin.ts +14 -0
  122. package/src/extensions/Comments/CommentsPlugin.ts +9 -9
  123. package/src/extensions/Comments/userstore/UserStore.ts +2 -2
  124. package/src/extensions/FilePanel/FilePanelPlugin.ts +37 -28
  125. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +6 -8
  126. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +29 -26
  127. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +11 -11
  128. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +4 -4
  129. package/src/extensions/Placeholder/PlaceholderPlugin.ts +10 -10
  130. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +2 -2
  131. package/src/extensions/README.md +1 -1
  132. package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
  133. package/src/extensions/SideMenu/SideMenuPlugin.ts +31 -31
  134. package/src/extensions/SideMenu/dragging.ts +8 -8
  135. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +17 -17
  136. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
  137. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +12 -12
  138. package/src/extensions/TableHandles/TableHandlesPlugin.ts +54 -53
  139. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  140. package/src/extensions/UniqueID/UniqueID.ts +6 -6
  141. package/src/extensions/getDraggableBlockFromElement.ts +1 -1
  142. package/src/fonts/inter.css +18 -9
  143. package/src/i18n/locales/index.ts +2 -0
  144. package/src/i18n/locales/ru.ts +2 -2
  145. package/src/i18n/locales/sk.ts +355 -0
  146. package/src/i18n/locales/zh-tw.ts +390 -0
  147. package/src/locales.ts +1 -1
  148. package/src/pm-nodes/BlockContainer.ts +7 -6
  149. package/src/pm-nodes/BlockGroup.ts +1 -1
  150. package/src/pm-nodes/Doc.ts +4 -4
  151. package/src/schema/README.md +1 -1
  152. package/src/schema/blocks/createSpec.ts +15 -15
  153. package/src/schema/blocks/internal.ts +17 -18
  154. package/src/schema/blocks/types.ts +27 -26
  155. package/src/schema/inlineContent/createSpec.ts +16 -20
  156. package/src/schema/inlineContent/internal.ts +9 -9
  157. package/src/schema/inlineContent/types.ts +26 -26
  158. package/src/schema/propTypes.ts +8 -8
  159. package/src/schema/styles/createSpec.ts +2 -2
  160. package/src/schema/styles/internal.ts +7 -7
  161. package/src/schema/styles/types.ts +2 -2
  162. package/src/util/EventEmitter.ts +4 -4
  163. package/src/util/README.md +1 -1
  164. package/src/util/combineByGroup.ts +1 -1
  165. package/src/util/table.ts +33 -30
  166. package/types/src/api/blockManipulation/setupTestEnv.d.ts +8 -4
  167. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +8 -4
  168. package/types/src/blocks/ListItemBlockContent/getListItemContent.d.ts +28 -0
  169. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +8 -4
  170. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -0
  171. package/types/src/blocks/defaultBlocks.d.ts +16 -8
  172. package/types/src/editor/BlockNoteEditor.d.ts +21 -2
  173. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +31 -0
  174. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +7 -0
  175. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +6 -0
  176. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +1 -1
  177. package/types/src/i18n/locales/index.d.ts +2 -0
  178. package/types/src/i18n/locales/sk.d.ts +313 -0
  179. package/types/src/i18n/locales/zh-tw.d.ts +2 -0
  180. package/types/src/schema/blocks/types.d.ts +2 -1
  181. package/src/extensions/Collaboration/createCollaborationExtensions.ts +0 -147
  182. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +0 -17
@@ -45,7 +45,8 @@ export type FileBlockConfig = {
45
45
  };
46
46
  // File preview width in px.
47
47
  previewWidth?: {
48
- default: number;
48
+ default: undefined;
49
+ type: "number";
49
50
  };
50
51
  };
51
52
  content: "none";
@@ -73,7 +74,7 @@ export type TiptapBlockImplementation<
73
74
  T extends BlockConfig,
74
75
  B extends BlockSchema,
75
76
  I extends InlineContentSchema,
76
- S extends StyleSchema
77
+ S extends StyleSchema,
77
78
  > = {
78
79
  requiredExtensions?: Array<Extension | Node>;
79
80
  node: Node;
@@ -81,7 +82,7 @@ export type TiptapBlockImplementation<
81
82
  block: BlockFromConfigNoChildren<T, I, S> & {
82
83
  children: BlockNoDefaults<B, I, S>[];
83
84
  },
84
- editor: BlockNoteEditor<B, I, S>
85
+ editor: BlockNoteEditor<B, I, S>,
85
86
  ) => {
86
87
  dom: HTMLElement;
87
88
  contentDOM?: HTMLElement;
@@ -90,7 +91,7 @@ export type TiptapBlockImplementation<
90
91
  block: BlockFromConfigNoChildren<T, I, S> & {
91
92
  children: BlockNoDefaults<B, I, S>[];
92
93
  },
93
- editor: BlockNoteEditor<B, I, S>
94
+ editor: BlockNoteEditor<B, I, S>,
94
95
  ) => {
95
96
  dom: HTMLElement;
96
97
  contentDOM?: HTMLElement;
@@ -102,7 +103,7 @@ export type BlockSpec<
102
103
  T extends BlockConfig,
103
104
  B extends BlockSchema,
104
105
  I extends InlineContentSchema,
105
- S extends StyleSchema
106
+ S extends StyleSchema,
106
107
  > = {
107
108
  config: T;
108
109
  implementation: TiptapBlockImplementation<NoInfer<T>, B, I, S>;
@@ -140,7 +141,7 @@ export type BlockSchemaFromSpecs<T extends BlockSpecs> = {
140
141
 
141
142
  export type BlockSchemaWithBlock<
142
143
  BType extends string,
143
- C extends BlockConfig
144
+ C extends BlockConfig,
144
145
  > = {
145
146
  [k in BType]: C;
146
147
  };
@@ -155,7 +156,7 @@ export type TableCellProps = {
155
156
 
156
157
  export type TableCell<
157
158
  I extends InlineContentSchema,
158
- S extends StyleSchema = StyleSchema
159
+ S extends StyleSchema = StyleSchema,
159
160
  > = {
160
161
  type: "tableCell";
161
162
  props: TableCellProps;
@@ -164,7 +165,7 @@ export type TableCell<
164
165
 
165
166
  export type TableContent<
166
167
  I extends InlineContentSchema,
167
- S extends StyleSchema = StyleSchema
168
+ S extends StyleSchema = StyleSchema,
168
169
  > = {
169
170
  type: "tableContent";
170
171
  columnWidths: (number | undefined)[];
@@ -181,7 +182,7 @@ export type TableContent<
181
182
  export type BlockFromConfigNoChildren<
182
183
  B extends BlockConfig,
183
184
  I extends InlineContentSchema,
184
- S extends StyleSchema
185
+ S extends StyleSchema,
185
186
  > = {
186
187
  id: string;
187
188
  type: B["type"];
@@ -189,16 +190,16 @@ export type BlockFromConfigNoChildren<
189
190
  content: B["content"] extends "inline"
190
191
  ? InlineContent<I, S>[]
191
192
  : B["content"] extends "table"
192
- ? TableContent<I, S>
193
- : B["content"] extends "none"
194
- ? undefined
195
- : never;
193
+ ? TableContent<I, S>
194
+ : B["content"] extends "none"
195
+ ? undefined
196
+ : never;
196
197
  };
197
198
 
198
199
  export type BlockFromConfig<
199
200
  B extends BlockConfig,
200
201
  I extends InlineContentSchema,
201
- S extends StyleSchema
202
+ S extends StyleSchema,
202
203
  > = BlockFromConfigNoChildren<B, I, S> & {
203
204
  children: BlockNoDefaults<BlockSchema, I, S>[];
204
205
  };
@@ -209,7 +210,7 @@ export type BlockFromConfig<
209
210
  type BlocksWithoutChildren<
210
211
  BSchema extends BlockSchema,
211
212
  I extends InlineContentSchema,
212
- S extends StyleSchema
213
+ S extends StyleSchema,
213
214
  > = {
214
215
  [BType in keyof BSchema]: BlockFromConfigNoChildren<BSchema[BType], I, S>;
215
216
  };
@@ -219,7 +220,7 @@ type BlocksWithoutChildren<
219
220
  export type BlockNoDefaults<
220
221
  BSchema extends BlockSchema,
221
222
  I extends InlineContentSchema,
222
- S extends StyleSchema
223
+ S extends StyleSchema,
223
224
  > = BlocksWithoutChildren<BSchema, I, S>[keyof BSchema] & {
224
225
  children: BlockNoDefaults<BSchema, I, S>[];
225
226
  };
@@ -228,7 +229,7 @@ export type SpecificBlock<
228
229
  BSchema extends BlockSchema,
229
230
  BType extends keyof BSchema,
230
231
  I extends InlineContentSchema,
231
- S extends StyleSchema
232
+ S extends StyleSchema,
232
233
  > = BlocksWithoutChildren<BSchema, I, S>[BType] & {
233
234
  children: BlockNoDefaults<BSchema, I, S>[];
234
235
  };
@@ -242,7 +243,7 @@ export type SpecificBlock<
242
243
 
243
244
  export type PartialTableCell<
244
245
  I extends InlineContentSchema,
245
- S extends StyleSchema = StyleSchema
246
+ S extends StyleSchema = StyleSchema,
246
247
  > = {
247
248
  type: "tableCell";
248
249
  props?: Partial<TableCellProps>;
@@ -251,7 +252,7 @@ export type PartialTableCell<
251
252
 
252
253
  export type PartialTableContent<
253
254
  I extends InlineContentSchema,
254
- S extends StyleSchema = StyleSchema
255
+ S extends StyleSchema = StyleSchema,
255
256
  > = {
256
257
  type: "tableContent";
257
258
  columnWidths?: (number | undefined)[];
@@ -265,7 +266,7 @@ export type PartialTableContent<
265
266
  type PartialBlockFromConfigNoChildren<
266
267
  B extends BlockConfig,
267
268
  I extends InlineContentSchema,
268
- S extends StyleSchema
269
+ S extends StyleSchema,
269
270
  > = {
270
271
  id?: string;
271
272
  type?: B["type"];
@@ -273,14 +274,14 @@ type PartialBlockFromConfigNoChildren<
273
274
  content?: B["content"] extends "inline"
274
275
  ? PartialInlineContent<I, S>
275
276
  : B["content"] extends "table"
276
- ? PartialTableContent<I, S>
277
- : undefined;
277
+ ? PartialTableContent<I, S>
278
+ : undefined;
278
279
  };
279
280
 
280
281
  type PartialBlocksWithoutChildren<
281
282
  BSchema extends BlockSchema,
282
283
  I extends InlineContentSchema,
283
- S extends StyleSchema
284
+ S extends StyleSchema,
284
285
  > = {
285
286
  [BType in keyof BSchema]: PartialBlockFromConfigNoChildren<
286
287
  BSchema[BType],
@@ -292,7 +293,7 @@ type PartialBlocksWithoutChildren<
292
293
  export type PartialBlockNoDefaults<
293
294
  BSchema extends BlockSchema,
294
295
  I extends InlineContentSchema,
295
- S extends StyleSchema
296
+ S extends StyleSchema,
296
297
  > = PartialBlocksWithoutChildren<
297
298
  BSchema,
298
299
  I,
@@ -306,7 +307,7 @@ export type SpecificPartialBlock<
306
307
  BSchema extends BlockSchema,
307
308
  I extends InlineContentSchema,
308
309
  BType extends keyof BSchema,
309
- S extends StyleSchema
310
+ S extends StyleSchema,
310
311
  > = PartialBlocksWithoutChildren<BSchema, I, S>[BType] & {
311
312
  children?: BlockNoDefaults<BSchema, I, S>[];
312
313
  };
@@ -314,7 +315,7 @@ export type SpecificPartialBlock<
314
315
  export type PartialBlockFromConfig<
315
316
  B extends BlockConfig,
316
317
  I extends InlineContentSchema,
317
- S extends StyleSchema
318
+ S extends StyleSchema,
318
319
  > = PartialBlockFromConfigNoChildren<B, I, S> & {
319
320
  children?: BlockNoDefaults<BlockSchema, I, S>[];
320
321
  };
@@ -25,7 +25,7 @@ export type CustomInlineContentImplementation<
25
25
  T extends CustomInlineContentConfig,
26
26
  // B extends BlockSchema,
27
27
  // I extends InlineContentSchema,
28
- S extends StyleSchema
28
+ S extends StyleSchema,
29
29
  > = {
30
30
  render: (
31
31
  /**
@@ -33,14 +33,14 @@ export type CustomInlineContentImplementation<
33
33
  */
34
34
  inlineContent: InlineContentFromConfig<T, S>,
35
35
  updateInlineContent: (
36
- update: PartialCustomInlineContentFromConfig<T, S>
36
+ update: PartialCustomInlineContentFromConfig<T, S>,
37
37
  ) => void,
38
38
  /**
39
39
  * The BlockNote editor instance
40
40
  * This is typed generically. If you want an editor with your custom schema, you need to
41
41
  * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
42
42
  */
43
- editor: BlockNoteEditor<any, any, S>
43
+ editor: BlockNoteEditor<any, any, S>,
44
44
  // (note) if we want to fix the manual cast, we need to prevent circular references and separate block definition and render implementations
45
45
  // or allow manually passing <BSchema>, but that's not possible without passing the other generics because Typescript doesn't support partial inferred generics
46
46
  ) => {
@@ -51,7 +51,7 @@ export type CustomInlineContentImplementation<
51
51
  };
52
52
 
53
53
  export function getInlineContentParseRules(
54
- config: CustomInlineContentConfig
54
+ config: CustomInlineContentConfig,
55
55
  ): TagParseRule[] {
56
56
  return [
57
57
  {
@@ -71,10 +71,10 @@ export function getInlineContentParseRules(
71
71
 
72
72
  export function createInlineContentSpec<
73
73
  T extends CustomInlineContentConfig,
74
- S extends StyleSchema
74
+ S extends StyleSchema,
75
75
  >(
76
76
  inlineContentConfig: T,
77
- inlineContentImplementation: CustomInlineContentImplementation<T, S>
77
+ inlineContentImplementation: CustomInlineContentImplementation<T, S>,
78
78
  ): InlineContentSpec<T> {
79
79
  const node = Node.create({
80
80
  name: inlineContentConfig.type,
@@ -105,31 +105,31 @@ export function createInlineContentSpec<
105
105
  nodeToCustomInlineContent(
106
106
  node,
107
107
  editor.schema.inlineContentSchema,
108
- editor.schema.styleSchema
108
+ editor.schema.styleSchema,
109
109
  ) as any as InlineContentFromConfig<T, S>, // TODO: fix cast
110
110
  () => {
111
111
  // No-op
112
112
  },
113
- editor
113
+ editor,
114
114
  );
115
115
 
116
116
  return addInlineContentAttributes(
117
117
  output,
118
118
  inlineContentConfig.type,
119
119
  node.attrs as Props<T["propSchema"]>,
120
- inlineContentConfig.propSchema
120
+ inlineContentConfig.propSchema,
121
121
  );
122
122
  },
123
123
 
124
124
  addNodeView() {
125
125
  return ({ node, getPos }) => {
126
- const editor = this.options.editor;
126
+ const editor = this.options.editor as BlockNoteEditor<any, any, S>;
127
127
 
128
128
  const output = inlineContentImplementation.render(
129
129
  nodeToCustomInlineContent(
130
130
  node,
131
131
  editor.schema.inlineContentSchema,
132
- editor.schema.styleSchema
132
+ editor.schema.styleSchema,
133
133
  ) as any as InlineContentFromConfig<T, S>, // TODO: fix cast
134
134
  (update) => {
135
135
  if (typeof getPos === "boolean") {
@@ -138,22 +138,18 @@ export function createInlineContentSpec<
138
138
 
139
139
  const content = inlineContentToNodes([update], editor.pmSchema);
140
140
 
141
- editor.dispatch(
142
- editor.prosemirrorView.state.tr.replaceWith(
143
- getPos(),
144
- getPos() + node.nodeSize,
145
- content
146
- )
141
+ editor.transact((tr) =>
142
+ tr.replaceWith(getPos(), getPos() + node.nodeSize, content),
147
143
  );
148
144
  },
149
- editor
145
+ editor,
150
146
  );
151
147
 
152
148
  return addInlineContentAttributes(
153
149
  output,
154
150
  inlineContentConfig.type,
155
151
  node.attrs as Props<T["propSchema"]>,
156
- inlineContentConfig.propSchema
152
+ inlineContentConfig.propSchema,
157
153
  );
158
154
  };
159
155
  },
@@ -161,6 +157,6 @@ export function createInlineContentSpec<
161
157
 
162
158
  return createInlineContentSpecFromTipTapNode(
163
159
  node,
164
- inlineContentConfig.propSchema
160
+ inlineContentConfig.propSchema,
165
161
  ) as InlineContentSpec<T>; // TODO: fix cast
166
162
  }
@@ -16,7 +16,7 @@ import {
16
16
  // is lost on internal copy & paste.
17
17
  export function addInlineContentAttributes<
18
18
  IType extends string,
19
- PSchema extends PropSchema
19
+ PSchema extends PropSchema,
20
20
  >(
21
21
  element: {
22
22
  dom: HTMLElement;
@@ -24,7 +24,7 @@ export function addInlineContentAttributes<
24
24
  },
25
25
  inlineContentType: IType,
26
26
  inlineContentProps: Props<PSchema>,
27
- propSchema: PSchema
27
+ propSchema: PSchema,
28
28
  ): {
29
29
  dom: HTMLElement;
30
30
  contentDOM?: HTMLElement;
@@ -52,9 +52,9 @@ export function addInlineContentAttributes<
52
52
 
53
53
  // see https://github.com/TypeCellOS/BlockNote/pull/435
54
54
  export function addInlineContentKeyboardShortcuts<
55
- T extends CustomInlineContentConfig
55
+ T extends CustomInlineContentConfig,
56
56
  >(
57
- config: T
57
+ config: T,
58
58
  ): {
59
59
  [p: string]: KeyboardShortcutCommand;
60
60
  } {
@@ -75,7 +75,7 @@ export function addInlineContentKeyboardShortcuts<
75
75
  // config and implementation that conform to the type of Config
76
76
  export function createInternalInlineContentSpec<T extends InlineContentConfig>(
77
77
  config: T,
78
- implementation: InlineContentImplementation<T>
78
+ implementation: InlineContentImplementation<T>,
79
79
  ) {
80
80
  return {
81
81
  config,
@@ -85,7 +85,7 @@ export function createInternalInlineContentSpec<T extends InlineContentConfig>(
85
85
 
86
86
  export function createInlineContentSpecFromTipTapNode<
87
87
  T extends Node,
88
- P extends PropSchema
88
+ P extends PropSchema,
89
89
  >(node: T, propSchema: P) {
90
90
  return createInternalInlineContentSpec(
91
91
  {
@@ -95,14 +95,14 @@ export function createInlineContentSpecFromTipTapNode<
95
95
  },
96
96
  {
97
97
  node,
98
- }
98
+ },
99
99
  );
100
100
  }
101
101
 
102
102
  export function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(
103
- specs: T
103
+ specs: T,
104
104
  ) {
105
105
  return Object.fromEntries(
106
- Object.entries(specs).map(([key, value]) => [key, value.config])
106
+ Object.entries(specs).map(([key, value]) => [key, value.config]),
107
107
  ) as InlineContentSchemaFromSpecs<T>;
108
108
  }
@@ -44,55 +44,55 @@ export type InlineContentSchemaFromSpecs<T extends InlineContentSpecs> = {
44
44
 
45
45
  export type CustomInlineContentFromConfig<
46
46
  I extends CustomInlineContentConfig,
47
- S extends StyleSchema
47
+ S extends StyleSchema,
48
48
  > = {
49
49
  type: I["type"];
50
50
  props: Props<I["propSchema"]>;
51
51
  content: I["content"] extends "styled"
52
52
  ? StyledText<S>[]
53
53
  : I["content"] extends "plain"
54
- ? string
55
- : I["content"] extends "none"
56
- ? undefined
57
- : never;
54
+ ? string
55
+ : I["content"] extends "none"
56
+ ? undefined
57
+ : never;
58
58
  };
59
59
 
60
60
  export type InlineContentFromConfig<
61
61
  I extends InlineContentConfig,
62
- S extends StyleSchema
62
+ S extends StyleSchema,
63
63
  > = I extends "text"
64
64
  ? StyledText<S>
65
65
  : I extends "link"
66
- ? Link<S>
67
- : I extends CustomInlineContentConfig
68
- ? CustomInlineContentFromConfig<I, S>
69
- : never;
66
+ ? Link<S>
67
+ : I extends CustomInlineContentConfig
68
+ ? CustomInlineContentFromConfig<I, S>
69
+ : never;
70
70
 
71
71
  export type PartialCustomInlineContentFromConfig<
72
72
  I extends CustomInlineContentConfig,
73
- S extends StyleSchema
73
+ S extends StyleSchema,
74
74
  > = {
75
75
  type: I["type"];
76
76
  props?: Props<I["propSchema"]>;
77
77
  content?: I["content"] extends "styled"
78
78
  ? StyledText<S>[] | string
79
79
  : I["content"] extends "plain"
80
- ? string
81
- : I["content"] extends "none"
82
- ? undefined
83
- : never;
80
+ ? string
81
+ : I["content"] extends "none"
82
+ ? undefined
83
+ : never;
84
84
  };
85
85
 
86
86
  export type PartialInlineContentFromConfig<
87
87
  I extends InlineContentConfig,
88
- S extends StyleSchema
88
+ S extends StyleSchema,
89
89
  > = I extends "text"
90
90
  ? string | StyledText<S>
91
91
  : I extends "link"
92
- ? PartialLink<S>
93
- : I extends CustomInlineContentConfig
94
- ? PartialCustomInlineContentFromConfig<I, S>
95
- : never;
92
+ ? PartialLink<S>
93
+ : I extends CustomInlineContentConfig
94
+ ? PartialCustomInlineContentFromConfig<I, S>
95
+ : never;
96
96
 
97
97
  export type StyledText<T extends StyleSchema> = {
98
98
  type: "text";
@@ -112,33 +112,33 @@ export type PartialLink<T extends StyleSchema> = Omit<Link<T>, "content"> & {
112
112
 
113
113
  export type InlineContent<
114
114
  I extends InlineContentSchema,
115
- T extends StyleSchema
115
+ T extends StyleSchema,
116
116
  > = InlineContentFromConfig<I[keyof I], T>;
117
117
 
118
118
  type PartialInlineContentElement<
119
119
  I extends InlineContentSchema,
120
- T extends StyleSchema
120
+ T extends StyleSchema,
121
121
  > = PartialInlineContentFromConfig<I[keyof I], T>;
122
122
 
123
123
  export type PartialInlineContent<
124
124
  I extends InlineContentSchema,
125
- T extends StyleSchema
125
+ T extends StyleSchema,
126
126
  > = PartialInlineContentElement<I, T>[] | string;
127
127
 
128
128
  export function isLinkInlineContent<T extends StyleSchema>(
129
- content: InlineContent<any, T>
129
+ content: InlineContent<any, T>,
130
130
  ): content is Link<T> {
131
131
  return content.type === "link";
132
132
  }
133
133
 
134
134
  export function isPartialLinkInlineContent<T extends StyleSchema>(
135
- content: PartialInlineContentElement<any, T>
135
+ content: PartialInlineContentElement<any, T>,
136
136
  ): content is PartialLink<T> {
137
137
  return typeof content !== "string" && content.type === "link";
138
138
  }
139
139
 
140
140
  export function isStyledTextInlineContent<T extends StyleSchema>(
141
- content: PartialInlineContentElement<any, T>
141
+ content: PartialInlineContentElement<any, T>,
142
142
  ): content is StyledText<T> {
143
143
  return typeof content !== "string" && content.type === "text";
144
144
  }
@@ -39,14 +39,14 @@ export type Props<PSchema extends PropSchema> = {
39
39
  ? PSchema[PName]["values"][number]
40
40
  : boolean
41
41
  : PSchema[PName] extends { default: number } | { type: "number" }
42
- ? PSchema[PName]["values"] extends readonly number[]
43
- ? PSchema[PName]["values"][number]
44
- : number
45
- : PSchema[PName] extends { default: string } | { type: "string" }
46
- ? PSchema[PName]["values"] extends readonly string[]
47
- ? PSchema[PName]["values"][number]
48
- : string
49
- : never
42
+ ? PSchema[PName]["values"] extends readonly number[]
43
+ ? PSchema[PName]["values"][number]
44
+ : number
45
+ : PSchema[PName] extends { default: string } | { type: "string" }
46
+ ? PSchema[PName]["values"] extends readonly string[]
47
+ ? PSchema[PName]["values"][number]
48
+ : string
49
+ : never
50
50
  ) extends infer T
51
51
  ? PSchema[PName] extends { optional: true }
52
52
  ? T | undefined
@@ -42,7 +42,7 @@ export function getStyleParseRules(config: StyleConfig): ParseRule[] {
42
42
 
43
43
  export function createStyleSpec<T extends StyleConfig>(
44
44
  styleConfig: T,
45
- styleImplementation: CustomStyleImplementation<T>
45
+ styleImplementation: CustomStyleImplementation<T>,
46
46
  ): StyleSpec<T> {
47
47
  const mark = Mark.create({
48
48
  name: styleConfig.type,
@@ -75,7 +75,7 @@ export function createStyleSpec<T extends StyleConfig>(
75
75
  renderResult,
76
76
  styleConfig.type,
77
77
  mark.attrs.stringValue,
78
- styleConfig.propSchema
78
+ styleConfig.propSchema,
79
79
  );
80
80
  },
81
81
  });
@@ -9,7 +9,7 @@ import {
9
9
  } from "./types.js";
10
10
 
11
11
  export function stylePropsToAttributes(
12
- propSchema: StylePropSchema
12
+ propSchema: StylePropSchema,
13
13
  ): Attributes {
14
14
  if (propSchema === "boolean") {
15
15
  return {};
@@ -34,7 +34,7 @@ export function stylePropsToAttributes(
34
34
  // on internal copy & paste.
35
35
  export function addStyleAttributes<
36
36
  SType extends string,
37
- PSchema extends StylePropSchema
37
+ PSchema extends StylePropSchema,
38
38
  >(
39
39
  element: {
40
40
  dom: HTMLElement;
@@ -42,7 +42,7 @@ export function addStyleAttributes<
42
42
  },
43
43
  styleType: SType,
44
44
  styleValue: PSchema extends "boolean" ? undefined : string,
45
- propSchema: PSchema
45
+ propSchema: PSchema,
46
46
  ): {
47
47
  dom: HTMLElement;
48
48
  contentDOM?: HTMLElement;
@@ -66,7 +66,7 @@ export function addStyleAttributes<
66
66
  // config and implementation that conform to the type of Config
67
67
  export function createInternalStyleSpec<T extends StyleConfig>(
68
68
  config: T,
69
- implementation: StyleImplementation
69
+ implementation: StyleImplementation,
70
70
  ) {
71
71
  return {
72
72
  config,
@@ -76,7 +76,7 @@ export function createInternalStyleSpec<T extends StyleConfig>(
76
76
 
77
77
  export function createStyleSpecFromTipTapMark<
78
78
  T extends Mark,
79
- P extends StylePropSchema
79
+ P extends StylePropSchema,
80
80
  >(mark: T, propSchema: P) {
81
81
  return createInternalStyleSpec(
82
82
  {
@@ -85,12 +85,12 @@ export function createStyleSpecFromTipTapMark<
85
85
  },
86
86
  {
87
87
  mark,
88
- }
88
+ },
89
89
  );
90
90
  }
91
91
 
92
92
  export function getStyleSchemaFromSpecs<T extends StyleSpecs>(specs: T) {
93
93
  return Object.fromEntries(
94
- Object.entries(specs).map(([key, value]) => [key, value.config])
94
+ Object.entries(specs).map(([key, value]) => [key, value.config]),
95
95
  ) as StyleSchemaFromSpecs<T>;
96
96
  }
@@ -37,6 +37,6 @@ export type Styles<T extends StyleSchema> = {
37
37
  [K in keyof T]?: T[K]["propSchema"] extends "boolean"
38
38
  ? boolean
39
39
  : T[K]["propSchema"] extends "string"
40
- ? string
41
- : never;
40
+ ? string
41
+ : never;
42
42
  };
@@ -3,11 +3,11 @@
3
3
  type StringKeyOf<T> = Extract<keyof T, string>;
4
4
  type CallbackType<
5
5
  T extends Record<string, any>,
6
- EventName extends StringKeyOf<T>
6
+ EventName extends StringKeyOf<T>,
7
7
  > = T[EventName] extends any[] ? T[EventName] : [T[EventName]];
8
8
  type CallbackFunction<
9
9
  T extends Record<string, any>,
10
- EventName extends StringKeyOf<T>
10
+ EventName extends StringKeyOf<T>,
11
11
  > = (...props: CallbackType<T, EventName>) => any;
12
12
 
13
13
  export class EventEmitter<T extends Record<string, any>> {
@@ -16,7 +16,7 @@ export class EventEmitter<T extends Record<string, any>> {
16
16
 
17
17
  public on<EventName extends StringKeyOf<T>>(
18
18
  event: EventName,
19
- fn: CallbackFunction<T, EventName>
19
+ fn: CallbackFunction<T, EventName>,
20
20
  ) {
21
21
  if (!this.callbacks[event]) {
22
22
  this.callbacks[event] = [];
@@ -40,7 +40,7 @@ export class EventEmitter<T extends Record<string, any>> {
40
40
 
41
41
  public off<EventName extends StringKeyOf<T>>(
42
42
  event: EventName,
43
- fn?: CallbackFunction<T, EventName>
43
+ fn?: CallbackFunction<T, EventName>,
44
44
  ) {
45
45
  const callbacks = this.callbacks[event];
46
46
 
@@ -1,3 +1,3 @@
1
1
  ### @blocknote/core/src/@util
2
2
 
3
- Contains generic utility files with helper functions / classes.
3
+ Contains generic utility files with helper functions / classes.
@@ -12,7 +12,7 @@ export function combineByGroup<T extends { group?: string }>(
12
12
  for (const additionalItems of additionalItemsArray) {
13
13
  for (const additionalItem of additionalItems) {
14
14
  const lastItemWithSameGroup = combinedItems.findLastIndex(
15
- (item) => item.group === additionalItem.group
15
+ (item) => item.group === additionalItem.group,
16
16
  );
17
17
  if (lastItemWithSameGroup === -1) {
18
18
  combinedItems.push(additionalItem as T);