@blocknote/core 0.30.0 → 0.31.0

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 (245) hide show
  1. package/dist/blocknote.cjs +9 -9
  2. package/dist/blocknote.cjs.map +1 -1
  3. package/dist/blocknote.js +2771 -2245
  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/{en-D4taoCs4.cjs → en-BXVKCwYt.cjs} +2 -2
  8. package/dist/en-BXVKCwYt.cjs.map +1 -0
  9. package/dist/{en-B7ycW7c8.js → en-qGo6sk9V.js} +2 -3
  10. package/dist/en-qGo6sk9V.js.map +1 -0
  11. package/dist/locales.cjs +1 -1
  12. package/dist/locales.cjs.map +1 -1
  13. package/dist/locales.js +20 -39
  14. package/dist/locales.js.map +1 -1
  15. package/dist/style.css +1 -1
  16. package/dist/webpack-stats.json +1 -1
  17. package/package.json +8 -7
  18. package/src/api/README.md +1 -1
  19. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +19 -14
  20. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +7 -8
  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/moveBlocks.test.ts +14 -14
  24. package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +16 -16
  25. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +8 -8
  26. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +12 -12
  27. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +8 -8
  28. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +10 -10
  29. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +2 -2
  30. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2816 -0
  31. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +200 -42
  32. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +104 -34
  33. package/src/api/blockManipulation/getBlock/getBlock.ts +9 -9
  34. package/src/api/blockManipulation/insertContentAt.ts +1 -1
  35. package/src/api/blockManipulation/selections/selection.ts +59 -12
  36. package/src/api/blockManipulation/selections/{textCursorPosition/textCursorPosition.ts → textCursorPosition.ts} +13 -13
  37. package/src/api/blockManipulation/tables/tables.test.ts +106 -106
  38. package/src/api/blockManipulation/tables/tables.ts +35 -35
  39. package/src/api/clipboard/fromClipboard/fileDropExtension.ts +2 -2
  40. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +9 -9
  41. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +3 -3
  42. package/src/api/clipboard/fromClipboard/pasteExtension.ts +3 -3
  43. package/src/api/clipboard/toClipboard/copyExtension.ts +22 -22
  44. package/src/api/exporters/html/externalHTMLExporter.ts +6 -6
  45. package/src/api/exporters/html/internalHTMLSerializer.ts +3 -3
  46. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +16 -16
  47. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +14 -14
  48. package/src/api/exporters/markdown/markdownExporter.ts +3 -3
  49. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +3 -3
  50. package/src/api/getBlockInfoFromPos.ts +6 -6
  51. package/src/api/nodeConversions/blockToNode.ts +31 -28
  52. package/src/api/nodeConversions/fragmentToBlocks.ts +1 -1
  53. package/src/api/nodeConversions/nodeToBlock.ts +240 -41
  54. package/src/api/nodeUtil.test.ts +16 -16
  55. package/src/api/nodeUtil.ts +10 -10
  56. package/src/api/parsers/html/parseHTML.ts +1 -1
  57. package/src/api/parsers/html/util/nestedLists.ts +2 -2
  58. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  59. package/src/api/pmUtil.ts +7 -7
  60. package/src/api/positionMapping.test.ts +3 -3
  61. package/src/api/positionMapping.ts +5 -5
  62. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -4
  63. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +18 -18
  64. package/src/blocks/FileBlockContent/FileBlockContent.ts +2 -2
  65. package/src/blocks/FileBlockContent/helpers/parse/parseFigureElement.ts +2 -2
  66. package/src/blocks/FileBlockContent/helpers/render/createAddFileButton.ts +6 -6
  67. package/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.ts +2 -2
  68. package/src/blocks/FileBlockContent/helpers/render/createFileNameWithIcon.ts +1 -1
  69. package/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.ts +7 -7
  70. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.ts +1 -1
  71. package/src/blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.ts +1 -1
  72. package/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.ts +2 -2
  73. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +6 -6
  74. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -4
  75. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +4 -4
  76. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +10 -10
  77. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  78. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +1 -1
  79. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +4 -4
  80. package/src/blocks/ListItemBlockContent/getListItemContent.ts +5 -5
  81. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +1 -1
  82. package/src/blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.ts +3 -3
  83. package/src/blocks/PageBreakBlockContent/schema.ts +2 -2
  84. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +3 -3
  85. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +4 -4
  86. package/src/blocks/README.md +1 -1
  87. package/src/blocks/TableBlockContent/TableBlockContent.ts +37 -7
  88. package/src/blocks/TableBlockContent/TableExtension.ts +3 -3
  89. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -4
  90. package/src/blocks/defaultBlockHelpers.ts +8 -8
  91. package/src/blocks/defaultBlockTypeGuards.ts +16 -16
  92. package/src/blocks/defaultBlocks.ts +3 -3
  93. package/src/comments/threadstore/DefaultThreadStoreAuth.ts +3 -3
  94. package/src/comments/threadstore/ThreadStore.ts +1 -1
  95. package/src/comments/threadstore/TipTapThreadStore.ts +10 -10
  96. package/src/comments/threadstore/yjs/RESTYjsThreadStore.ts +4 -4
  97. package/src/comments/threadstore/yjs/YjsThreadStore.test.ts +2 -2
  98. package/src/comments/threadstore/yjs/YjsThreadStore.ts +14 -14
  99. package/src/comments/threadstore/yjs/YjsThreadStoreBase.ts +1 -1
  100. package/src/comments/threadstore/yjs/yjsHelpers.ts +6 -6
  101. package/src/editor/Block.css +35 -1
  102. package/src/editor/BlockNoteEditor.test.ts +10 -3
  103. package/src/editor/BlockNoteEditor.ts +95 -38
  104. package/src/editor/BlockNoteExtension.ts +26 -0
  105. package/src/editor/BlockNoteExtensions.ts +38 -22
  106. package/src/editor/BlockNoteSchema.ts +4 -4
  107. package/src/editor/BlockNoteTipTapEditor.ts +33 -12
  108. package/src/editor/README.md +1 -1
  109. package/src/editor/cursorPositionTypes.ts +1 -1
  110. package/src/editor/editor.css +15 -3
  111. package/src/editor/selectionTypes.ts +1 -1
  112. package/src/editor/transformPasted.ts +2 -2
  113. package/src/exporter/Exporter.ts +5 -5
  114. package/src/exporter/mapping.ts +7 -7
  115. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +1 -1
  116. package/src/extensions/Collaboration/CursorPlugin.ts +15 -9
  117. package/src/extensions/Collaboration/ForkYDocPlugin.test.ts +166 -0
  118. package/src/extensions/Collaboration/ForkYDocPlugin.ts +174 -0
  119. package/src/extensions/Collaboration/SyncPlugin.ts +7 -4
  120. package/src/extensions/Collaboration/UndoPlugin.ts +7 -4
  121. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +30 -0
  122. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +30 -0
  123. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -0
  124. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -0
  125. package/src/extensions/Comments/CommentsPlugin.ts +80 -75
  126. package/src/extensions/Comments/userstore/UserStore.ts +2 -2
  127. package/src/extensions/FilePanel/FilePanelPlugin.ts +56 -55
  128. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +60 -30
  129. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +26 -26
  130. package/src/extensions/LinkToolbar/LinkToolbarPlugin.ts +33 -32
  131. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +45 -42
  132. package/src/extensions/Placeholder/PlaceholderPlugin.ts +113 -110
  133. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +179 -170
  134. package/src/extensions/README.md +1 -1
  135. package/src/extensions/ShowSelection/ShowSelectionPlugin.ts +22 -19
  136. package/src/extensions/SideMenu/MultipleNodeSelection.ts +1 -1
  137. package/src/extensions/SideMenu/SideMenuPlugin.ts +49 -48
  138. package/src/extensions/SideMenu/dragging.ts +8 -8
  139. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +176 -176
  140. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -2
  141. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +16 -16
  142. package/src/extensions/Suggestions/SuggestionMarks.ts +175 -0
  143. package/src/extensions/TableHandles/TableHandlesPlugin.ts +199 -195
  144. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  145. package/src/extensions/UniqueID/UniqueID.ts +6 -6
  146. package/src/extensions/getDraggableBlockFromElement.ts +1 -1
  147. package/src/fonts/inter.css +18 -9
  148. package/src/i18n/locales/ar.ts +0 -1
  149. package/src/i18n/locales/de.ts +0 -1
  150. package/src/i18n/locales/en.ts +0 -1
  151. package/src/i18n/locales/es.ts +0 -1
  152. package/src/i18n/locales/fr.ts +0 -1
  153. package/src/i18n/locales/hr.ts +0 -1
  154. package/src/i18n/locales/is.ts +0 -1
  155. package/src/i18n/locales/it.ts +0 -1
  156. package/src/i18n/locales/ja.ts +0 -1
  157. package/src/i18n/locales/ko.ts +0 -1
  158. package/src/i18n/locales/nl.ts +0 -1
  159. package/src/i18n/locales/no.ts +0 -1
  160. package/src/i18n/locales/pl.ts +0 -1
  161. package/src/i18n/locales/pt.ts +0 -1
  162. package/src/i18n/locales/ru.ts +0 -1
  163. package/src/i18n/locales/sk.ts +0 -1
  164. package/src/i18n/locales/uk.ts +0 -1
  165. package/src/i18n/locales/vi.ts +0 -1
  166. package/src/i18n/locales/zh-tw.ts +0 -1
  167. package/src/i18n/locales/zh.ts +0 -1
  168. package/src/index.ts +18 -8
  169. package/src/locales.ts +1 -1
  170. package/src/pm-nodes/BlockContainer.ts +1 -1
  171. package/src/pm-nodes/BlockGroup.ts +2 -2
  172. package/src/pm-nodes/Doc.ts +5 -4
  173. package/src/schema/README.md +1 -1
  174. package/src/schema/blocks/createSpec.ts +14 -14
  175. package/src/schema/blocks/internal.ts +17 -17
  176. package/src/schema/blocks/types.ts +25 -25
  177. package/src/schema/inlineContent/createSpec.ts +16 -20
  178. package/src/schema/inlineContent/internal.ts +9 -9
  179. package/src/schema/inlineContent/types.ts +26 -26
  180. package/src/schema/propTypes.ts +8 -8
  181. package/src/schema/styles/createSpec.ts +2 -2
  182. package/src/schema/styles/internal.ts +7 -7
  183. package/src/schema/styles/types.ts +2 -2
  184. package/src/util/EventEmitter.ts +4 -4
  185. package/src/util/README.md +1 -1
  186. package/src/util/combineByGroup.ts +1 -1
  187. package/src/util/table.ts +33 -30
  188. package/types/src/api/blockManipulation/commands/insertBlocks/insertBlocks.d.ts +1 -1
  189. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.d.ts +4 -0
  190. package/types/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.d.ts +1 -0
  191. package/types/src/api/blockManipulation/commands/updateBlock/updateBlock.d.ts +3 -1
  192. package/types/src/api/blockManipulation/selections/selection.d.ts +10 -0
  193. package/types/src/api/blockManipulation/selections/textCursorPosition.d.ts +5 -0
  194. package/types/src/api/blockManipulation/transactions.test.d.ts +0 -0
  195. package/types/src/api/clipboard/clipboardExternal.test.d.ts +1 -0
  196. package/types/src/api/clipboard/clipboardInternal.test.d.ts +1 -0
  197. package/types/src/api/clipboard/testUtil.d.ts +541 -0
  198. package/types/src/api/exporters/html/htmlConversion.test.d.ts +1 -0
  199. package/types/src/api/exporters/markdown/markdownExporter.test.d.ts +1 -0
  200. package/types/src/api/nodeConversions/nodeConversions.test.d.ts +1 -0
  201. package/types/src/api/nodeConversions/nodeToBlock.d.ts +39 -2
  202. package/types/src/api/parsers/html/parseHTML.test.d.ts +1 -0
  203. package/types/src/api/parsers/markdown/parseMarkdown.test.d.ts +1 -0
  204. package/types/src/api/pmUtil.d.ts +3 -3
  205. package/types/src/api/testUtil/cases/customBlocks.d.ts +670 -0
  206. package/types/src/api/testUtil/cases/customInlineContent.d.ts +558 -0
  207. package/types/src/api/testUtil/cases/customStyles.d.ts +552 -0
  208. package/types/src/api/testUtil/cases/defaultSchema.d.ts +4 -0
  209. package/types/src/api/testUtil/index.d.ts +14 -0
  210. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +9 -0
  211. package/types/src/api/testUtil/paste.d.ts +2 -0
  212. package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
  213. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +9 -1
  214. package/types/src/editor/BlockNoteEditor.d.ts +58 -10
  215. package/types/src/editor/BlockNoteExtension.d.ts +9 -0
  216. package/types/src/editor/BlockNoteExtensions.d.ts +2 -2
  217. package/types/src/editor/BlockNoteTipTapEditor.d.ts +2 -2
  218. package/types/src/extensions/Collaboration/CursorPlugin.d.ts +3 -3
  219. package/types/src/extensions/Collaboration/ForkYDocPlugin.d.ts +41 -0
  220. package/types/src/extensions/Collaboration/ForkYDocPlugin.test.d.ts +1 -0
  221. package/types/src/extensions/Collaboration/SyncPlugin.d.ts +3 -3
  222. package/types/src/extensions/Collaboration/UndoPlugin.d.ts +3 -3
  223. package/types/src/extensions/Collaboration/createCollaborationExtensions.d.ts +17 -0
  224. package/types/src/extensions/Comments/CommentsPlugin.d.ts +2 -4
  225. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +3 -4
  226. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +5 -5
  227. package/types/src/extensions/LinkToolbar/LinkToolbarPlugin.d.ts +3 -4
  228. package/types/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.d.ts +2 -3
  229. package/types/src/extensions/Placeholder/PlaceholderPlugin.d.ts +2 -3
  230. package/types/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.d.ts +2 -3
  231. package/types/src/extensions/ShowSelection/ShowSelectionPlugin.d.ts +2 -3
  232. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +3 -4
  233. package/types/src/extensions/SuggestionMenu/SuggestionPlugin.d.ts +2 -4
  234. package/types/src/extensions/Suggestions/SuggestionMarks.d.ts +4 -0
  235. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +5 -6
  236. package/types/src/i18n/locales/en.d.ts +0 -1
  237. package/types/src/i18n/locales/sk.d.ts +0 -1
  238. package/types/src/index.d.ts +15 -8
  239. package/dist/en-B7ycW7c8.js.map +0 -1
  240. package/dist/en-D4taoCs4.cjs.map +0 -1
  241. package/dist/tsconfig.tsbuildinfo +0 -1
  242. package/src/api/blockManipulation/selections/__snapshots__/selection.test.ts.snap +0 -844
  243. package/src/api/blockManipulation/selections/selection.test.ts +0 -72
  244. package/src/api/blockManipulation/selections/textCursorPosition/__snapshots__/textCursorPosition.test.ts.snap +0 -316
  245. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.ts +0 -74
@@ -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);
package/src/util/table.ts CHANGED
@@ -13,47 +13,50 @@ import { PartialTableCell, TableCell } from "../schema/blocks/types.js";
13
13
  */
14
14
  export function mapTableCell<
15
15
  T extends InlineContentSchema,
16
- S extends StyleSchema
16
+ S extends StyleSchema,
17
17
  >(
18
- content: PartialInlineContent<T, S> | PartialTableCell<T, S> | TableCell<T, S>
18
+ content:
19
+ | PartialInlineContent<T, S>
20
+ | PartialTableCell<T, S>
21
+ | TableCell<T, S>,
19
22
  ): TableCell<T, S> {
20
23
  return isTableCell(content)
21
24
  ? { ...content }
22
25
  : isPartialTableCell(content)
23
- ? {
24
- type: "tableCell",
25
- content: ([] as InlineContent<T, S>[]).concat(content.content as any),
26
- props: {
27
- backgroundColor: content.props?.backgroundColor ?? "default",
28
- textColor: content.props?.textColor ?? "default",
29
- textAlignment: content.props?.textAlignment ?? "left",
30
- colspan: content.props?.colspan ?? 1,
31
- rowspan: content.props?.rowspan ?? 1,
32
- },
33
- }
34
- : {
35
- type: "tableCell",
36
- content: ([] as InlineContent<T, S>[]).concat(content as any),
37
- props: {
38
- backgroundColor: "default",
39
- textColor: "default",
40
- textAlignment: "left",
41
- colspan: 1,
42
- rowspan: 1,
43
- },
44
- };
26
+ ? {
27
+ type: "tableCell",
28
+ content: ([] as InlineContent<T, S>[]).concat(content.content as any),
29
+ props: {
30
+ backgroundColor: content.props?.backgroundColor ?? "default",
31
+ textColor: content.props?.textColor ?? "default",
32
+ textAlignment: content.props?.textAlignment ?? "left",
33
+ colspan: content.props?.colspan ?? 1,
34
+ rowspan: content.props?.rowspan ?? 1,
35
+ },
36
+ }
37
+ : {
38
+ type: "tableCell",
39
+ content: ([] as InlineContent<T, S>[]).concat(content as any),
40
+ props: {
41
+ backgroundColor: "default",
42
+ textColor: "default",
43
+ textAlignment: "left",
44
+ colspan: 1,
45
+ rowspan: 1,
46
+ },
47
+ };
45
48
  }
46
49
 
47
50
  export function isPartialTableCell<
48
51
  T extends InlineContentSchema,
49
- S extends StyleSchema
52
+ S extends StyleSchema,
50
53
  >(
51
54
  content:
52
55
  | TableCell<T, S>
53
56
  | PartialInlineContent<T, S>
54
57
  | PartialTableCell<T, S>
55
58
  | undefined
56
- | null
59
+ | null,
57
60
  ): content is PartialTableCell<T, S> {
58
61
  return (
59
62
  content !== undefined &&
@@ -66,14 +69,14 @@ export function isPartialTableCell<
66
69
 
67
70
  export function isTableCell<
68
71
  T extends InlineContentSchema,
69
- S extends StyleSchema
72
+ S extends StyleSchema,
70
73
  >(
71
74
  content:
72
75
  | TableCell<T, S>
73
76
  | PartialInlineContent<T, S>
74
77
  | PartialTableCell<T, S>
75
78
  | undefined
76
- | null
79
+ | null,
77
80
  ): content is TableCell<T, S> {
78
81
  return (
79
82
  isPartialTableCell(content) &&
@@ -86,7 +89,7 @@ export function getColspan(
86
89
  cell:
87
90
  | TableCell<any, any>
88
91
  | PartialTableCell<any, any>
89
- | PartialInlineContent<any, any>
92
+ | PartialInlineContent<any, any>,
90
93
  ): number {
91
94
  if (isTableCell(cell)) {
92
95
  return cell.props.colspan ?? 1;
@@ -98,7 +101,7 @@ export function getRowspan(
98
101
  cell:
99
102
  | TableCell<any, any>
100
103
  | PartialTableCell<any, any>
101
- | PartialInlineContent<any, any>
104
+ | PartialInlineContent<any, any>,
102
105
  ): number {
103
106
  if (isTableCell(cell)) {
104
107
  return cell.props.rowspan ?? 1;
@@ -1,4 +1,4 @@
1
+ import type { Transaction } from "prosemirror-state";
1
2
  import { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
2
3
  import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema } from "../../../../schema/index.js";
3
- import type { Transaction } from "prosemirror-state";
4
4
  export declare function insertBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(tr: Transaction, blocksToInsert: PartialBlock<BSchema, I, S>[], referenceBlock: BlockIdentifier, placement?: "before" | "after"): Block<BSchema, I, S>[];
@@ -0,0 +1,4 @@
1
+ import { Block } from "../../../../blocks/defaultBlocks.js";
2
+ import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor";
3
+ import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema } from "../../../../schema/index.js";
4
+ export declare function removeBlocks<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(editor: BlockNoteEditor<BSchema, I, S>, blocksToRemove: BlockIdentifier[]): Block<BSchema, I, S>[];
@@ -1,4 +1,5 @@
1
1
  import type { Transaction } from "prosemirror-state";
2
+ import { Transform } from "prosemirror-transform";
2
3
  import type { Block, PartialBlock } from "../../../../blocks/defaultBlocks.js";
3
4
  import type { BlockIdentifier, BlockSchema } from "../../../../schema/blocks/types.js";
4
5
  import type { InlineContentSchema } from "../../../../schema/inlineContent/types.js";
@@ -7,4 +8,5 @@ export declare const updateBlockCommand: <BSchema extends BlockSchema, I extends
7
8
  tr: Transaction;
8
9
  dispatch?: () => void;
9
10
  }) => boolean;
10
- export declare function updateBlock<BSchema extends BlockSchema = any, I extends InlineContentSchema = any, S extends StyleSchema = any>(tr: Transaction, blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, I, S>): Block<BSchema, I, S>;
11
+ export declare function updateBlockTr<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(tr: Transform, posBeforeBlock: number, block: PartialBlock<BSchema, I, S>, replaceFromPos?: number, replaceToPos?: number): void;
12
+ export declare function updateBlock<BSchema extends BlockSchema = any, I extends InlineContentSchema = any, S extends StyleSchema = any>(tr: Transaction, blockToUpdate: BlockIdentifier, update: PartialBlock<BSchema, I, S>, replaceFromPos?: number, replaceToPos?: number): Block<BSchema, I, S>;
@@ -1,5 +1,15 @@
1
1
  import { type Transaction } from "prosemirror-state";
2
+ import { Block } from "../../../blocks/defaultBlocks.js";
2
3
  import { Selection } from "../../../editor/selectionTypes.js";
3
4
  import { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema/index.js";
4
5
  export declare function getSelection<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(tr: Transaction): Selection<BSchema, I, S> | undefined;
5
6
  export declare function setSelection(tr: Transaction, startBlock: BlockIdentifier, endBlock: BlockIdentifier): void;
7
+ export declare function getSelectionCutBlocks(tr: Transaction): {
8
+ blocks: Block<Record<string, import("../../../index.js").BlockConfig>, InlineContentSchema, StyleSchema>[];
9
+ blockCutAtStart: string | undefined;
10
+ blockCutAtEnd: string | undefined;
11
+ _meta: {
12
+ startPos: number;
13
+ endPos: number;
14
+ };
15
+ };
@@ -0,0 +1,5 @@
1
+ import { type Transaction } from "prosemirror-state";
2
+ import type { TextCursorPosition } from "../../../editor/cursorPositionTypes.js";
3
+ import type { BlockIdentifier, BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema/index.js";
4
+ export declare function getTextCursorPosition<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema>(tr: Transaction): TextCursorPosition<BSchema, I, S>;
5
+ export declare function setTextCursorPosition(tr: Transaction, targetBlock: BlockIdentifier, placement?: "start" | "end"): void;