@blocknote/core 0.17.1 → 0.19.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 (490) hide show
  1. package/dist/blocknote.js +2774 -1804
  2. package/dist/blocknote.js.map +1 -1
  3. package/dist/blocknote.umd.cjs +9 -6
  4. package/dist/blocknote.umd.cjs.map +1 -1
  5. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js +27 -0
  6. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.js.map +1 -0
  7. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js +99 -0
  8. package/dist/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.js.map +1 -0
  9. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js +97 -0
  10. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.js.map +1 -0
  11. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js +88 -0
  12. package/dist/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.js.map +1 -0
  13. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js +116 -0
  14. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.js.map +1 -0
  15. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js +106 -0
  16. package/dist/src/api/blockManipulation/commands/moveBlock/moveBlock.test.js.map +1 -0
  17. package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js +57 -0
  18. package/dist/src/api/blockManipulation/commands/nestBlock/nestBlock.js.map +1 -0
  19. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js +43 -0
  20. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.js.map +1 -0
  21. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js +27 -0
  22. package/dist/src/api/blockManipulation/commands/removeBlocks/removeBlocks.test.js.map +1 -0
  23. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js +29 -0
  24. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.js.map +1 -0
  25. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js +157 -0
  26. package/dist/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.js.map +1 -0
  27. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js +27 -0
  28. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.js.map +1 -0
  29. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js +64 -0
  30. package/dist/src/api/blockManipulation/commands/splitBlock/splitBlock.test.js.map +1 -0
  31. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js +145 -0
  32. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.js.map +1 -0
  33. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js +252 -0
  34. package/dist/src/api/blockManipulation/commands/updateBlock/updateBlock.test.js.map +1 -0
  35. package/dist/src/api/blockManipulation/insertContentAt.js +64 -0
  36. package/dist/src/api/blockManipulation/insertContentAt.js.map +1 -0
  37. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js +76 -0
  38. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.js.map +1 -0
  39. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js +33 -0
  40. package/dist/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.test.js.map +1 -0
  41. package/dist/src/api/blockManipulation/setupTestEnv.js +172 -0
  42. package/dist/src/api/blockManipulation/setupTestEnv.js.map +1 -0
  43. package/dist/src/api/clipboard/clipboard.test.js +246 -0
  44. package/dist/src/api/clipboard/clipboard.test.js.map +1 -0
  45. package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js +8 -0
  46. package/dist/src/api/clipboard/fromClipboard/acceptedMIMETypes.js.map +1 -0
  47. package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js +38 -0
  48. package/dist/src/api/clipboard/fromClipboard/fileDropExtension.js.map +1 -0
  49. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js +109 -0
  50. package/dist/src/api/clipboard/fromClipboard/handleFileInsertion.js.map +1 -0
  51. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js +26 -0
  52. package/dist/src/api/clipboard/fromClipboard/handleVSCodePaste.js.map +1 -0
  53. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js +57 -0
  54. package/dist/src/api/clipboard/fromClipboard/pasteExtension.js.map +1 -0
  55. package/dist/src/api/clipboard/toClipboard/copyExtension.js +132 -0
  56. package/dist/src/api/clipboard/toClipboard/copyExtension.js.map +1 -0
  57. package/dist/src/api/exporters/html/externalHTMLExporter.js +35 -0
  58. package/dist/src/api/exporters/html/externalHTMLExporter.js.map +1 -0
  59. package/dist/src/api/exporters/html/htmlConversion.test.js +72 -0
  60. package/dist/src/api/exporters/html/htmlConversion.test.js.map +1 -0
  61. package/dist/src/api/exporters/html/internalHTMLSerializer.js +21 -0
  62. package/dist/src/api/exporters/html/internalHTMLSerializer.js.map +1 -0
  63. package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js +141 -0
  64. package/dist/src/api/exporters/html/util/serializeBlocksExternalHTML.js.map +1 -0
  65. package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js +96 -0
  66. package/dist/src/api/exporters/html/util/serializeBlocksInternalHTML.js.map +1 -0
  67. package/dist/src/api/exporters/markdown/markdownExporter.js +31 -0
  68. package/dist/src/api/exporters/markdown/markdownExporter.js.map +1 -0
  69. package/dist/src/api/exporters/markdown/markdownExporter.test.js +57 -0
  70. package/dist/src/api/exporters/markdown/markdownExporter.test.js.map +1 -0
  71. package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js +33 -0
  72. package/dist/src/api/exporters/markdown/removeUnderlinesRehypePlugin.js.map +1 -0
  73. package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js +37 -0
  74. package/dist/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.js.map +1 -0
  75. package/dist/src/api/getBlockInfoFromPos.js +171 -0
  76. package/dist/src/api/getBlockInfoFromPos.js.map +1 -0
  77. package/dist/src/api/nodeConversions/blockToNode.js +197 -0
  78. package/dist/src/api/nodeConversions/blockToNode.js.map +1 -0
  79. package/dist/src/api/nodeConversions/fragmentToBlocks.js +50 -0
  80. package/dist/src/api/nodeConversions/fragmentToBlocks.js.map +1 -0
  81. package/dist/src/api/nodeConversions/nodeConversions.test.js +54 -0
  82. package/dist/src/api/nodeConversions/nodeConversions.test.js.map +1 -0
  83. package/dist/src/api/nodeConversions/nodeToBlock.js +316 -0
  84. package/dist/src/api/nodeConversions/nodeToBlock.js.map +1 -0
  85. package/dist/src/api/nodeUtil.js +28 -0
  86. package/dist/src/api/nodeUtil.js.map +1 -0
  87. package/dist/src/api/parsers/html/parseHTML.js +19 -0
  88. package/dist/src/api/parsers/html/parseHTML.js.map +1 -0
  89. package/dist/src/api/parsers/html/parseHTML.test.js +470 -0
  90. package/dist/src/api/parsers/html/parseHTML.test.js.map +1 -0
  91. package/dist/src/api/parsers/html/util/nestedLists.js +106 -0
  92. package/dist/src/api/parsers/html/util/nestedLists.js.map +1 -0
  93. package/dist/src/api/parsers/html/util/nestedLists.test.js +166 -0
  94. package/dist/src/api/parsers/html/util/nestedLists.test.js.map +1 -0
  95. package/dist/src/api/parsers/markdown/parseMarkdown.js +52 -0
  96. package/dist/src/api/parsers/markdown/parseMarkdown.js.map +1 -0
  97. package/dist/src/api/parsers/markdown/parseMarkdown.test.js +109 -0
  98. package/dist/src/api/parsers/markdown/parseMarkdown.test.js.map +1 -0
  99. package/dist/src/api/testUtil/cases/customBlocks.js +313 -0
  100. package/dist/src/api/testUtil/cases/customBlocks.js.map +1 -0
  101. package/dist/src/api/testUtil/cases/customInlineContent.js +91 -0
  102. package/dist/src/api/testUtil/cases/customInlineContent.js.map +1 -0
  103. package/dist/src/api/testUtil/cases/customStyles.js +83 -0
  104. package/dist/src/api/testUtil/cases/customStyles.js.map +1 -0
  105. package/dist/src/api/testUtil/cases/defaultSchema.js +673 -0
  106. package/dist/src/api/testUtil/cases/defaultSchema.js.map +1 -0
  107. package/dist/src/api/testUtil/index.js +2 -0
  108. package/dist/src/api/testUtil/index.js.map +1 -0
  109. package/dist/src/api/testUtil/partialBlockTestUtil.js +114 -0
  110. package/dist/src/api/testUtil/partialBlockTestUtil.js.map +1 -0
  111. package/dist/src/api/testUtil/paste.js +29 -0
  112. package/dist/src/api/testUtil/paste.js.map +1 -0
  113. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js +97 -0
  114. package/dist/src/blocks/AudioBlockContent/AudioBlockContent.js.map +1 -0
  115. package/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js +5 -0
  116. package/dist/src/blocks/AudioBlockContent/audioBlockHelpers.js.map +1 -0
  117. package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js +273 -0
  118. package/dist/src/blocks/CodeBlockContent/CodeBlockContent.js.map +1 -0
  119. package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js +90 -0
  120. package/dist/src/blocks/CodeBlockContent/defaultSupportedLanguages.js.map +1 -0
  121. package/dist/src/blocks/FileBlockContent/FileBlockContent.js +70 -0
  122. package/dist/src/blocks/FileBlockContent/FileBlockContent.js.map +1 -0
  123. package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js +317 -0
  124. package/dist/src/blocks/FileBlockContent/fileBlockHelpers.js.map +1 -0
  125. package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js +15 -0
  126. package/dist/src/blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js.map +1 -0
  127. package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js +141 -0
  128. package/dist/src/blocks/HeadingBlockContent/HeadingBlockContent.js.map +1 -0
  129. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js +106 -0
  130. package/dist/src/blocks/ImageBlockContent/ImageBlockContent.js.map +1 -0
  131. package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js +6 -0
  132. package/dist/src/blocks/ImageBlockContent/imageBlockHelpers.js.map +1 -0
  133. package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js +111 -0
  134. package/dist/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.js.map +1 -0
  135. package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js +218 -0
  136. package/dist/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.js.map +1 -0
  137. package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js +41 -0
  138. package/dist/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.js.map +1 -0
  139. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js +58 -0
  140. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.js.map +1 -0
  141. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js +128 -0
  142. package/dist/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.js.map +1 -0
  143. package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js +51 -0
  144. package/dist/src/blocks/ParagraphBlockContent/ParagraphBlockContent.js.map +1 -0
  145. package/dist/src/blocks/TableBlockContent/TableBlockContent.js +130 -0
  146. package/dist/src/blocks/TableBlockContent/TableBlockContent.js.map +1 -0
  147. package/dist/src/blocks/TableBlockContent/TableExtension.js +57 -0
  148. package/dist/src/blocks/TableBlockContent/TableExtension.js.map +1 -0
  149. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js +103 -0
  150. package/dist/src/blocks/VideoBlockContent/VideoBlockContent.js.map +1 -0
  151. package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.js +6 -0
  152. package/dist/src/blocks/VideoBlockContent/videoBlockHelpers.js.map +1 -0
  153. package/dist/src/blocks/defaultBlockHelpers.js +50 -0
  154. package/dist/src/blocks/defaultBlockHelpers.js.map +1 -0
  155. package/dist/src/blocks/defaultBlockTypeGuards.js +40 -0
  156. package/dist/src/blocks/defaultBlockTypeGuards.js.map +1 -0
  157. package/dist/src/blocks/defaultBlocks.js +50 -0
  158. package/dist/src/blocks/defaultBlocks.js.map +1 -0
  159. package/dist/src/blocks/defaultProps.js +19 -0
  160. package/dist/src/blocks/defaultProps.js.map +1 -0
  161. package/dist/src/editor/BlockNoteEditor.js +750 -0
  162. package/dist/src/editor/BlockNoteEditor.js.map +1 -0
  163. package/dist/src/editor/BlockNoteEditor.test.js +65 -0
  164. package/dist/src/editor/BlockNoteEditor.test.js.map +1 -0
  165. package/dist/src/editor/BlockNoteExtensions.js +149 -0
  166. package/dist/src/editor/BlockNoteExtensions.js.map +1 -0
  167. package/dist/src/editor/BlockNoteSchema.js +38 -0
  168. package/dist/src/editor/BlockNoteSchema.js.map +1 -0
  169. package/dist/src/editor/BlockNoteTipTapEditor.js +169 -0
  170. package/dist/src/editor/BlockNoteTipTapEditor.js.map +1 -0
  171. package/dist/src/editor/cursorPositionTypes.js +2 -0
  172. package/dist/src/editor/cursorPositionTypes.js.map +1 -0
  173. package/dist/src/editor/defaultColors.js +77 -0
  174. package/dist/src/editor/defaultColors.js.map +1 -0
  175. package/dist/src/editor/selectionTypes.js +2 -0
  176. package/dist/src/editor/selectionTypes.js.map +1 -0
  177. package/dist/src/editor/transformPasted.js +79 -0
  178. package/dist/src/editor/transformPasted.js.map +1 -0
  179. package/dist/src/exporter/Exporter.js +36 -0
  180. package/dist/src/exporter/Exporter.js.map +1 -0
  181. package/dist/src/exporter/index.js +3 -0
  182. package/dist/src/exporter/index.js.map +1 -0
  183. package/dist/src/exporter/mapping.js +12 -0
  184. package/dist/src/exporter/mapping.js.map +1 -0
  185. package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js +30 -0
  186. package/dist/src/extensions/BackgroundColor/BackgroundColorExtension.js.map +1 -0
  187. package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js +39 -0
  188. package/dist/src/extensions/BackgroundColor/BackgroundColorMark.js.map +1 -0
  189. package/dist/src/extensions/FilePanel/FilePanelPlugin.js +131 -0
  190. package/dist/src/extensions/FilePanel/FilePanelPlugin.js.map +1 -0
  191. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js +195 -0
  192. package/dist/src/extensions/FormattingToolbar/FormattingToolbarPlugin.js.map +1 -0
  193. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js +309 -0
  194. package/dist/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.js.map +1 -0
  195. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js +247 -0
  196. package/dist/src/extensions/LinkToolbar/LinkToolbarPlugin.js.map +1 -0
  197. package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js +51 -0
  198. package/dist/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.js.map +1 -0
  199. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js +81 -0
  200. package/dist/src/extensions/Placeholder/PlaceholderPlugin.js.map +1 -0
  201. package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js +183 -0
  202. package/dist/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.js.map +1 -0
  203. package/dist/src/extensions/SideMenu/MultipleNodeSelection.js +68 -0
  204. package/dist/src/extensions/SideMenu/MultipleNodeSelection.js.map +1 -0
  205. package/dist/src/extensions/SideMenu/SideMenuPlugin.js +339 -0
  206. package/dist/src/extensions/SideMenu/SideMenuPlugin.js.map +1 -0
  207. package/dist/src/extensions/SideMenu/dragging.js +128 -0
  208. package/dist/src/extensions/SideMenu/dragging.js.map +1 -0
  209. package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js +2 -0
  210. package/dist/src/extensions/SuggestionMenu/DefaultGridSuggestionItem.js.map +1 -0
  211. package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js +2 -0
  212. package/dist/src/extensions/SuggestionMenu/DefaultSuggestionItem.js.map +1 -0
  213. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js +245 -0
  214. package/dist/src/extensions/SuggestionMenu/SuggestionPlugin.js.map +1 -0
  215. package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js +26 -0
  216. package/dist/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.js.map +1 -0
  217. package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js +244 -0
  218. package/dist/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.js.map +1 -0
  219. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js +553 -0
  220. package/dist/src/extensions/TableHandles/TableHandlesPlugin.js.map +1 -0
  221. package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js +36 -0
  222. package/dist/src/extensions/TextAlignment/TextAlignmentExtension.js.map +1 -0
  223. package/dist/src/extensions/TextColor/TextColorExtension.js +29 -0
  224. package/dist/src/extensions/TextColor/TextColorExtension.js.map +1 -0
  225. package/dist/src/extensions/TextColor/TextColorMark.js +37 -0
  226. package/dist/src/extensions/TextColor/TextColorMark.js.map +1 -0
  227. package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js +58 -0
  228. package/dist/src/extensions/TrailingNode/TrailingNodeExtension.js.map +1 -0
  229. package/dist/src/extensions/UniqueID/UniqueID.js +283 -0
  230. package/dist/src/extensions/UniqueID/UniqueID.js.map +1 -0
  231. package/dist/src/extensions/getDraggableBlockFromElement.js +13 -0
  232. package/dist/src/extensions/getDraggableBlockFromElement.js.map +1 -0
  233. package/dist/src/extensions-shared/UiElementPosition.js +2 -0
  234. package/dist/src/extensions-shared/UiElementPosition.js.map +1 -0
  235. package/dist/src/i18n/dictionary.js +4 -0
  236. package/dist/src/i18n/dictionary.js.map +1 -0
  237. package/dist/src/i18n/locales/ar.js +298 -0
  238. package/dist/src/i18n/locales/ar.js.map +1 -0
  239. package/dist/src/i18n/locales/de.js +313 -0
  240. package/dist/src/i18n/locales/de.js.map +1 -0
  241. package/dist/src/i18n/locales/en.js +314 -0
  242. package/dist/src/i18n/locales/en.js.map +1 -0
  243. package/dist/src/i18n/locales/es.js +312 -0
  244. package/dist/src/i18n/locales/es.js.map +1 -0
  245. package/dist/src/i18n/locales/fr.js +313 -0
  246. package/dist/src/i18n/locales/fr.js.map +1 -0
  247. package/dist/src/i18n/locales/hr.js +308 -0
  248. package/dist/src/i18n/locales/hr.js.map +1 -0
  249. package/dist/src/i18n/locales/index.js +16 -0
  250. package/dist/src/i18n/locales/index.js.map +1 -0
  251. package/dist/src/i18n/locales/is.js +305 -0
  252. package/dist/src/i18n/locales/is.js.map +1 -0
  253. package/dist/src/i18n/locales/ja.js +333 -0
  254. package/dist/src/i18n/locales/ja.js.map +1 -0
  255. package/dist/src/i18n/locales/ko.js +326 -0
  256. package/dist/src/i18n/locales/ko.js.map +1 -0
  257. package/dist/src/i18n/locales/nl.js +313 -0
  258. package/dist/src/i18n/locales/nl.js.map +1 -0
  259. package/dist/src/i18n/locales/pl.js +297 -0
  260. package/dist/src/i18n/locales/pl.js.map +1 -0
  261. package/dist/src/i18n/locales/pt.js +305 -0
  262. package/dist/src/i18n/locales/pt.js.map +1 -0
  263. package/dist/src/i18n/locales/ru.js +340 -0
  264. package/dist/src/i18n/locales/ru.js.map +1 -0
  265. package/dist/src/i18n/locales/vi.js +312 -0
  266. package/dist/src/i18n/locales/vi.js.map +1 -0
  267. package/dist/src/i18n/locales/zh.js +346 -0
  268. package/dist/src/i18n/locales/zh.js.map +1 -0
  269. package/dist/src/index.js +55 -0
  270. package/dist/src/index.js.map +1 -0
  271. package/dist/src/pm-nodes/BlockContainer.js +72 -0
  272. package/dist/src/pm-nodes/BlockContainer.js.map +1 -0
  273. package/dist/src/pm-nodes/BlockGroup.js +43 -0
  274. package/dist/src/pm-nodes/BlockGroup.js.map +1 -0
  275. package/dist/src/pm-nodes/Doc.js +7 -0
  276. package/dist/src/pm-nodes/Doc.js.map +1 -0
  277. package/dist/src/pm-nodes/index.js +4 -0
  278. package/dist/src/pm-nodes/index.js.map +1 -0
  279. package/dist/src/schema/blocks/createSpec.js +126 -0
  280. package/dist/src/schema/blocks/createSpec.js.map +1 -0
  281. package/dist/src/schema/blocks/internal.js +147 -0
  282. package/dist/src/schema/blocks/internal.js.map +1 -0
  283. package/dist/src/schema/blocks/types.js +2 -0
  284. package/dist/src/schema/blocks/types.js.map +1 -0
  285. package/dist/src/schema/index.js +11 -0
  286. package/dist/src/schema/index.js.map +1 -0
  287. package/dist/src/schema/inlineContent/createSpec.js +64 -0
  288. package/dist/src/schema/inlineContent/createSpec.js.map +1 -0
  289. package/dist/src/schema/inlineContent/internal.js +52 -0
  290. package/dist/src/schema/inlineContent/internal.js.map +1 -0
  291. package/dist/src/schema/inlineContent/types.js +10 -0
  292. package/dist/src/schema/inlineContent/types.js.map +1 -0
  293. package/dist/src/schema/propTypes.js +2 -0
  294. package/dist/src/schema/propTypes.js.map +1 -0
  295. package/dist/src/schema/styles/createSpec.js +48 -0
  296. package/dist/src/schema/styles/createSpec.js.map +1 -0
  297. package/dist/src/schema/styles/internal.js +53 -0
  298. package/dist/src/schema/styles/internal.js.map +1 -0
  299. package/dist/src/schema/styles/types.js +2 -0
  300. package/dist/src/schema/styles/types.js.map +1 -0
  301. package/dist/src/util/EventEmitter.js +33 -0
  302. package/dist/src/util/EventEmitter.js.map +1 -0
  303. package/dist/src/util/browser.js +17 -0
  304. package/dist/src/util/browser.js.map +1 -0
  305. package/dist/src/util/combineByGroup.js +20 -0
  306. package/dist/src/util/combineByGroup.js.map +1 -0
  307. package/dist/src/util/esmDependencies.js +35 -0
  308. package/dist/src/util/esmDependencies.js.map +1 -0
  309. package/dist/src/util/string.js +14 -0
  310. package/dist/src/util/string.js.map +1 -0
  311. package/dist/src/util/typescript.js +12 -0
  312. package/dist/src/util/typescript.js.map +1 -0
  313. package/dist/style.css +1 -1
  314. package/dist/tsconfig.tsbuildinfo +1 -0
  315. package/dist/webpack-stats.json +1 -1
  316. package/package.json +9 -7
  317. package/src/api/blockManipulation/commands/insertBlocks/__snapshots__/insertBlocks.test.ts.snap +30 -0
  318. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +2 -0
  319. package/src/api/blockManipulation/commands/mergeBlocks/__snapshots__/mergeBlocks.test.ts.snap +25 -0
  320. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +2 -2
  321. package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.ts +104 -39
  322. package/src/api/blockManipulation/commands/moveBlock/__snapshots__/moveBlock.test.ts.snap +40 -0
  323. package/src/api/blockManipulation/commands/moveBlock/moveBlock.ts +3 -5
  324. package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +100 -0
  325. package/src/api/blockManipulation/commands/removeBlocks/__snapshots__/removeBlocks.test.ts.snap +10 -0
  326. package/src/api/blockManipulation/commands/removeBlocks/removeBlocks.ts +1 -1
  327. package/src/api/blockManipulation/commands/replaceBlocks/__snapshots__/replaceBlocks.test.ts.snap +40 -0
  328. package/src/api/blockManipulation/commands/splitBlock/__snapshots__/splitBlock.test.ts.snap +30 -0
  329. package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +8 -4
  330. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +11 -7
  331. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +87 -0
  332. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +5 -5
  333. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +192 -107
  334. package/src/api/blockManipulation/selections/textCursorPosition/textCursorPosition.ts +48 -33
  335. package/src/api/clipboard/clipboard.test.ts +1 -1
  336. package/src/api/clipboard/fromClipboard/acceptedMIMETypes.ts +1 -0
  337. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +1 -1
  338. package/src/api/clipboard/fromClipboard/handleVSCodePaste.ts +49 -0
  339. package/src/api/clipboard/fromClipboard/pasteExtension.ts +6 -0
  340. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
  341. package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/external.html +1 -0
  342. package/src/api/exporters/html/__snapshots__/codeBlock/defaultLanguage/internal.html +1 -0
  343. package/src/api/exporters/html/__snapshots__/codeBlock/empty/external.html +1 -0
  344. package/src/api/exporters/html/__snapshots__/codeBlock/empty/internal.html +1 -0
  345. package/src/api/exporters/html/__snapshots__/codeBlock/python/external.html +1 -0
  346. package/src/api/exporters/html/__snapshots__/codeBlock/python/internal.html +1 -0
  347. package/src/api/exporters/html/__snapshots__/image/basic/internal.html +1 -1
  348. package/src/api/exporters/html/__snapshots__/image/nested/internal.html +1 -1
  349. package/src/api/exporters/html/__snapshots__/image/noName/internal.html +1 -1
  350. package/src/api/exporters/html/__snapshots__/image/noPreview/internal.html +1 -1
  351. package/src/api/exporters/html/__snapshots__/lists/basic/internal.html +1 -1
  352. package/src/api/exporters/html/__snapshots__/lists/nested/internal.html +1 -1
  353. package/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +1 -1
  354. package/src/api/exporters/html/__snapshots__/simpleImage/basic/internal.html +1 -1
  355. package/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +1 -1
  356. package/src/api/exporters/html/__snapshots__/simpleImage/nested/internal.html +1 -1
  357. package/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +1 -1
  358. package/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +1 -1
  359. package/src/api/exporters/html/__snapshots__/simpleImage/noName/internal.html +1 -1
  360. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +1 -1
  361. package/src/api/exporters/html/__snapshots__/simpleImage/noPreview/internal.html +1 -1
  362. package/src/api/exporters/html/__snapshots__/table/allColWidths/external.html +1 -0
  363. package/src/api/exporters/html/__snapshots__/table/allColWidths/internal.html +1 -0
  364. package/src/api/exporters/html/__snapshots__/table/basic/external.html +1 -0
  365. package/src/api/exporters/html/__snapshots__/table/basic/internal.html +1 -0
  366. package/src/api/exporters/html/__snapshots__/table/mixedColWidths/external.html +1 -0
  367. package/src/api/exporters/html/__snapshots__/table/mixedColWidths/internal.html +1 -0
  368. package/src/api/exporters/html/htmlConversion.test.ts +1 -4
  369. package/src/api/exporters/html/internalHTMLSerializer.ts +2 -7
  370. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +7 -1
  371. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +75 -33
  372. package/src/api/exporters/markdown/__snapshots__/codeBlock/defaultLanguage/markdown.md +3 -0
  373. package/src/api/exporters/markdown/__snapshots__/codeBlock/empty/markdown.md +2 -0
  374. package/src/api/exporters/markdown/__snapshots__/codeBlock/python/markdown.md +3 -0
  375. package/src/api/exporters/markdown/__snapshots__/table/allColWidths/markdown.md +5 -0
  376. package/src/api/exporters/markdown/__snapshots__/table/basic/markdown.md +5 -0
  377. package/src/api/exporters/markdown/__snapshots__/table/mixedColWidths/markdown.md +5 -0
  378. package/src/api/exporters/markdown/markdownExporter.test.ts +1 -4
  379. package/src/api/getBlockInfoFromPos.ts +113 -58
  380. package/src/api/nodeConversions/__snapshots__/nodeConversions.test.ts.snap +711 -0
  381. package/src/api/nodeConversions/blockToNode.ts +62 -26
  382. package/src/api/nodeConversions/fragmentToBlocks.ts +18 -0
  383. package/src/api/nodeConversions/nodeToBlock.ts +35 -22
  384. package/src/api/nodeUtil.ts +1 -1
  385. package/src/api/parsers/html/__snapshots__/parse-notion-html.json +5 -0
  386. package/src/api/parsers/markdown/parseMarkdown.ts +1 -1
  387. package/src/api/testUtil/cases/defaultSchema.ts +95 -0
  388. package/src/api/testUtil/partialBlockTestUtil.ts +41 -4
  389. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +4 -2
  390. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +369 -0
  391. package/src/blocks/CodeBlockContent/defaultSupportedLanguages.ts +96 -0
  392. package/src/blocks/FileBlockContent/fileBlockHelpers.ts +10 -2
  393. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +19 -31
  394. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +4 -2
  395. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +5 -9
  396. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +6 -10
  397. package/src/blocks/ListItemBlockContent/ListItemKeyboardShortcuts.ts +1 -1
  398. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +11 -4
  399. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +5 -9
  400. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +4 -8
  401. package/src/blocks/TableBlockContent/TableBlockContent.ts +83 -8
  402. package/src/blocks/TableBlockContent/TableExtension.ts +10 -1
  403. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +4 -2
  404. package/src/blocks/defaultBlockHelpers.ts +7 -2
  405. package/src/blocks/defaultBlocks.ts +4 -0
  406. package/src/editor/Block.css +71 -3
  407. package/src/editor/BlockNoteEditor.test.ts +2 -2
  408. package/src/editor/BlockNoteEditor.ts +18 -21
  409. package/src/editor/BlockNoteExtensions.ts +2 -3
  410. package/src/editor/BlockNoteTipTapEditor.ts +8 -1
  411. package/src/editor/defaultColors.ts +77 -0
  412. package/src/editor/editor.css +43 -5
  413. package/src/editor/transformPasted.ts +6 -3
  414. package/src/exporter/Exporter.ts +101 -0
  415. package/src/exporter/index.ts +2 -0
  416. package/src/exporter/mapping.ts +75 -0
  417. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +8 -0
  418. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +201 -48
  419. package/src/extensions/NodeSelectionKeyboard/NodeSelectionKeyboardPlugin.ts +1 -1
  420. package/src/extensions/Placeholder/PlaceholderPlugin.ts +5 -0
  421. package/src/extensions/SideMenu/SideMenuPlugin.ts +141 -52
  422. package/src/extensions/SideMenu/dragging.ts +3 -54
  423. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +5 -0
  424. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +2 -1
  425. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +22 -6
  426. package/src/extensions/TableHandles/TableHandlesPlugin.ts +225 -120
  427. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +1 -1
  428. package/src/extensions/getDraggableBlockFromElement.ts +19 -0
  429. package/src/i18n/locales/ar.ts +6 -0
  430. package/src/i18n/locales/de.ts +299 -294
  431. package/src/i18n/locales/en.ts +6 -0
  432. package/src/i18n/locales/es.ts +310 -274
  433. package/src/i18n/locales/fr.ts +6 -0
  434. package/src/i18n/locales/is.ts +6 -0
  435. package/src/i18n/locales/ja.ts +6 -0
  436. package/src/i18n/locales/ko.ts +6 -0
  437. package/src/i18n/locales/nl.ts +6 -0
  438. package/src/i18n/locales/pl.ts +6 -0
  439. package/src/i18n/locales/pt.ts +10 -4
  440. package/src/i18n/locales/ru.ts +6 -0
  441. package/src/i18n/locales/vi.ts +6 -0
  442. package/src/i18n/locales/zh.ts +6 -0
  443. package/src/index.ts +9 -0
  444. package/src/pm-nodes/BlockContainer.ts +1 -1
  445. package/src/pm-nodes/BlockGroup.ts +2 -2
  446. package/src/pm-nodes/README.md +127 -28
  447. package/src/schema/blocks/createSpec.ts +4 -1
  448. package/src/schema/blocks/internal.ts +12 -2
  449. package/src/schema/blocks/types.ts +3 -1
  450. package/src/util/combineByGroup.ts +25 -0
  451. package/types/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.d.ts +22 -2
  452. package/types/src/api/blockManipulation/commands/nestBlock/nestBlock.d.ts +5 -0
  453. package/types/src/api/blockManipulation/setupTestEnv.d.ts +22 -8
  454. package/types/src/api/clipboard/fromClipboard/acceptedMIMETypes.d.ts +1 -1
  455. package/types/src/api/clipboard/fromClipboard/handleVSCodePaste.d.ts +3 -0
  456. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +2 -3
  457. package/types/src/api/getBlockInfoFromPos.d.ts +55 -5
  458. package/types/src/api/nodeConversions/blockToNode.d.ts +1 -1
  459. package/types/src/api/nodeConversions/nodeToBlock.d.ts +3 -1
  460. package/types/src/api/testUtil/cases/customBlocks.d.ts +22 -8
  461. package/types/src/api/testUtil/cases/customInlineContent.d.ts +22 -8
  462. package/types/src/api/testUtil/cases/customStyles.d.ts +22 -8
  463. package/types/src/api/testUtil/partialBlockTestUtil.d.ts +2 -1
  464. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +1 -0
  465. package/types/src/blocks/CodeBlockContent/CodeBlockContent.d.ts +57 -0
  466. package/types/src/blocks/CodeBlockContent/defaultSupportedLanguages.d.ts +6 -0
  467. package/types/src/blocks/FileBlockContent/fileBlockHelpers.d.ts +1 -0
  468. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +1 -0
  469. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -12
  470. package/types/src/blocks/TableBlockContent/TableExtension.d.ts +3 -0
  471. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +1 -0
  472. package/types/src/blocks/defaultBlocks.d.ts +45 -16
  473. package/types/src/editor/BlockNoteEditor.d.ts +4 -3
  474. package/types/src/editor/BlockNoteTipTapEditor.d.ts +1 -0
  475. package/types/src/editor/defaultColors.d.ts +76 -0
  476. package/types/src/exporter/Exporter.d.ts +43 -0
  477. package/types/src/exporter/index.d.ts +2 -0
  478. package/types/src/exporter/mapping.d.ts +30 -0
  479. package/types/src/extensions/SideMenu/SideMenuPlugin.d.ts +2 -1
  480. package/types/src/extensions/SideMenu/dragging.d.ts +1 -6
  481. package/types/src/extensions/TableHandles/TableHandlesPlugin.d.ts +9 -5
  482. package/types/src/extensions/getDraggableBlockFromElement.d.ts +5 -0
  483. package/types/src/i18n/locales/de.d.ts +6 -0
  484. package/types/src/i18n/locales/en.d.ts +6 -0
  485. package/types/src/i18n/locales/es.d.ts +6 -0
  486. package/types/src/index.d.ts +6 -0
  487. package/types/src/schema/blocks/createSpec.d.ts +1 -1
  488. package/types/src/schema/blocks/internal.d.ts +2 -2
  489. package/types/src/schema/blocks/types.d.ts +3 -1
  490. package/types/src/util/combineByGroup.d.ts +9 -0
@@ -1,8 +1,9 @@
1
1
  import { Plugin, PluginKey, PluginView } from "prosemirror-state";
2
2
  import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
3
3
  import { nodeToBlock } from "../../api/nodeConversions/nodeToBlock.js";
4
+ import { getNodeById } from "../../api/nodeUtil.js";
4
5
  import { checkBlockIsDefaultType } from "../../blocks/defaultBlockTypeGuards.js";
5
- import { Block, DefaultBlockSchema } from "../../blocks/defaultBlocks.js";
6
+ import { DefaultBlockSchema } from "../../blocks/defaultBlocks.js";
6
7
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
7
8
  import {
8
9
  BlockFromConfigNoChildren,
@@ -11,7 +12,7 @@ import {
11
12
  StyleSchema,
12
13
  } from "../../schema/index.js";
13
14
  import { EventEmitter } from "../../util/EventEmitter.js";
14
- import { getDraggableBlockFromElement } from "../SideMenu/dragging.js";
15
+ import { getDraggableBlockFromElement } from "../getDraggableBlockFromElement.js";
15
16
 
16
17
  let dragImageElement: HTMLElement | undefined;
17
18
 
@@ -20,12 +21,14 @@ export type TableHandlesState<
20
21
  S extends StyleSchema
21
22
  > = {
22
23
  show: boolean;
23
- referencePosCell: DOMRect;
24
+ showAddOrRemoveRowsButton: boolean;
25
+ showAddOrRemoveColumnsButton: boolean;
26
+ referencePosCell: DOMRect | undefined;
24
27
  referencePosTable: DOMRect;
25
28
 
26
29
  block: BlockFromConfigNoChildren<DefaultBlockSchema["table"], I, S>;
27
- colIndex: number;
28
- rowIndex: number;
30
+ colIndex: number | undefined;
31
+ rowIndex: number | undefined;
29
32
 
30
33
  draggingState:
31
34
  | {
@@ -34,6 +37,8 @@ export type TableHandlesState<
34
37
  mousePos: number;
35
38
  }
36
39
  | undefined;
40
+
41
+ widgetContainer: HTMLElement | undefined;
37
42
  };
38
43
 
39
44
  function setHiddenDragImage(rootEl: Document | ShadowRoot) {
@@ -70,28 +75,45 @@ function getChildIndex(node: Element) {
70
75
 
71
76
  // Finds the DOM element corresponding to the table cell that the target element
72
77
  // is currently in. If the target element is not in a table cell, returns null.
73
- function domCellAround(target: Element | null): Element | null {
74
- while (target && target.nodeName !== "TD" && target.nodeName !== "TH") {
75
- target =
76
- target.classList && target.classList.contains("ProseMirror")
77
- ? null
78
- : (target.parentNode as Element);
78
+ function domCellAround(target: Element) {
79
+ let currentTarget: Element | undefined = target;
80
+ while (
81
+ currentTarget &&
82
+ currentTarget.nodeName !== "TD" &&
83
+ currentTarget.nodeName !== "TH" &&
84
+ !currentTarget.classList.contains("tableWrapper")
85
+ ) {
86
+ if (currentTarget.classList.contains("ProseMirror")) {
87
+ return undefined;
88
+ }
89
+ const parent: ParentNode | null = currentTarget.parentNode;
90
+
91
+ if (!parent || !(parent instanceof Element)) {
92
+ return undefined;
93
+ }
94
+ currentTarget = parent;
79
95
  }
80
- return target;
96
+
97
+ return currentTarget.nodeName === "TD" || currentTarget.nodeName === "TH"
98
+ ? {
99
+ type: "cell",
100
+ domNode: currentTarget,
101
+ tbodyNode: currentTarget.closest("tbody"),
102
+ }
103
+ : {
104
+ type: "wrapper",
105
+ domNode: currentTarget,
106
+ tbodyNode: currentTarget.querySelector("tbody"),
107
+ };
81
108
  }
82
109
 
83
110
  // Hides elements in the DOMwith the provided class names.
84
- function hideElementsWithClassNames(
85
- classNames: string[],
86
- rootEl: Document | ShadowRoot
87
- ) {
88
- classNames.forEach((className) => {
89
- const elementsToHide = rootEl.querySelectorAll(className);
90
-
91
- for (let i = 0; i < elementsToHide.length; i++) {
92
- (elementsToHide[i] as HTMLElement).style.visibility = "hidden";
93
- }
94
- });
111
+ function hideElements(selector: string, rootEl: Document | ShadowRoot) {
112
+ const elementsToHide = rootEl.querySelectorAll(selector);
113
+
114
+ for (let i = 0; i < elementsToHide.length; i++) {
115
+ (elementsToHide[i] as HTMLElement).style.visibility = "hidden";
116
+ }
95
117
  }
96
118
 
97
119
  export class TableHandlesView<
@@ -104,6 +126,7 @@ export class TableHandlesView<
104
126
 
105
127
  public tableId: string | undefined;
106
128
  public tablePos: number | undefined;
129
+ public tableElement: HTMLElement | undefined;
107
130
 
108
131
  public menuFrozen = false;
109
132
 
@@ -130,25 +153,20 @@ export class TableHandlesView<
130
153
 
131
154
  pmView.dom.addEventListener("mousemove", this.mouseMoveHandler);
132
155
  pmView.dom.addEventListener("mousedown", this.viewMousedownHandler);
133
- pmView.dom.addEventListener("mouseup", this.viewMouseupHandler);
156
+ window.addEventListener("mouseup", this.mouseUpHandler);
134
157
 
135
158
  pmView.root.addEventListener(
136
159
  "dragover",
137
160
  this.dragOverHandler as EventListener
138
161
  );
139
162
  pmView.root.addEventListener("drop", this.dropHandler as EventListener);
140
-
141
- // Setting capture=true ensures that any parent container of the editor that
142
- // gets scrolled will trigger the scroll event. Scroll events do not bubble
143
- // and so won't propagate to the document by default.
144
- pmView.root.addEventListener("scroll", this.scrollHandler, true);
145
163
  }
146
164
 
147
165
  viewMousedownHandler = () => {
148
166
  this.mouseState = "down";
149
167
  };
150
168
 
151
- viewMouseupHandler = (event: MouseEvent) => {
169
+ mouseUpHandler = (event: MouseEvent) => {
152
170
  this.mouseState = "up";
153
171
  this.mouseMoveHandler(event);
154
172
  };
@@ -158,100 +176,150 @@ export class TableHandlesView<
158
176
  return;
159
177
  }
160
178
 
161
- if (this.mouseState === "down") {
179
+ if (this.mouseState === "selecting") {
180
+ return;
181
+ }
182
+
183
+ if (
184
+ !(event.target instanceof Element) ||
185
+ !this.pmView.dom.contains(event.target)
186
+ ) {
187
+ return;
188
+ }
189
+
190
+ const target = domCellAround(event.target);
191
+
192
+ if (
193
+ target?.type === "cell" &&
194
+ this.mouseState === "down" &&
195
+ !this.state?.draggingState
196
+ ) {
197
+ // hide draghandles when selecting text as they could be in the way of the user
162
198
  this.mouseState = "selecting";
163
199
 
164
200
  if (this.state?.show) {
165
201
  this.state.show = false;
202
+ this.state.showAddOrRemoveRowsButton = false;
203
+ this.state.showAddOrRemoveColumnsButton = false;
166
204
  this.emitUpdate();
167
205
  }
168
- }
169
-
170
- if (this.mouseState === "selecting") {
171
206
  return;
172
207
  }
173
208
 
174
- const target = domCellAround(event.target as HTMLElement);
175
-
176
209
  if (!target || !this.editor.isEditable) {
177
210
  if (this.state?.show) {
178
211
  this.state.show = false;
212
+ this.state.showAddOrRemoveRowsButton = false;
213
+ this.state.showAddOrRemoveColumnsButton = false;
179
214
  this.emitUpdate();
180
215
  }
181
216
  return;
182
217
  }
183
218
 
184
- const colIndex = getChildIndex(target);
185
- const rowIndex = getChildIndex(target.parentElement!);
186
- const cellRect = target.getBoundingClientRect();
187
- const tableRect =
188
- target.parentElement?.parentElement?.getBoundingClientRect();
189
-
190
- if (!tableRect) {
219
+ if (!target.tbodyNode) {
191
220
  return;
192
221
  }
193
222
 
194
- const blockEl = getDraggableBlockFromElement(target, this.pmView);
223
+ const tableRect = target.tbodyNode.getBoundingClientRect();
224
+
225
+ const blockEl = getDraggableBlockFromElement(target.domNode, this.pmView);
195
226
  if (!blockEl) {
196
227
  return;
197
228
  }
229
+ this.tableElement = blockEl.node;
198
230
 
199
- let tableBlock: Block<any, any, any> | undefined = undefined;
200
-
201
- // Copied from `getBlock`. We don't use `getBlock` since we also need the PM
202
- // node for the table, so we would effectively be doing the same work twice.
203
- this.editor._tiptapEditor.state.doc.descendants((node, pos) => {
204
- if (typeof tableBlock !== "undefined") {
205
- return false;
206
- }
207
-
208
- if (node.type.name !== "blockContainer" || node.attrs.id !== blockEl.id) {
209
- return true;
210
- }
231
+ let tableBlock:
232
+ | BlockFromConfigNoChildren<DefaultBlockSchema["table"], I, S>
233
+ | undefined;
211
234
 
212
- const block = nodeToBlock(
213
- node,
214
- this.editor.schema.blockSchema,
215
- this.editor.schema.inlineContentSchema,
216
- this.editor.schema.styleSchema,
217
- this.editor.blockCache
218
- );
235
+ const pmNodeInfo = getNodeById(
236
+ blockEl.id,
237
+ this.editor._tiptapEditor.state.doc
238
+ );
219
239
 
220
- if (checkBlockIsDefaultType("table", block, this.editor)) {
221
- this.tablePos = pos + 1;
222
- tableBlock = block;
223
- }
240
+ const block = nodeToBlock(
241
+ pmNodeInfo.node,
242
+ this.editor.schema.blockSchema,
243
+ this.editor.schema.inlineContentSchema,
244
+ this.editor.schema.styleSchema,
245
+ this.editor.blockCache
246
+ );
224
247
 
225
- return false;
226
- });
248
+ if (checkBlockIsDefaultType("table", block, this.editor)) {
249
+ this.tablePos = pmNodeInfo.posBeforeNode + 1;
250
+ tableBlock = block;
251
+ }
227
252
 
228
253
  if (!tableBlock) {
229
254
  return;
230
255
  }
231
256
 
232
257
  this.tableId = blockEl.id;
258
+ const widgetContainer = target.domNode
259
+ .closest(".tableWrapper")
260
+ ?.querySelector(".table-widgets-container") as HTMLElement;
261
+
262
+ if (target?.type === "wrapper") {
263
+ // if we're just to the right or below the table, show the extend buttons
264
+ // (this is a bit hacky. It would probably be cleaner to render the extend buttons in the Table NodeView instead)
265
+ const belowTable =
266
+ event.clientY >= tableRect.bottom - 1 && // -1 to account for fractions of pixels in "bottom"
267
+ event.clientY < tableRect.bottom + 20;
268
+ const toRightOfTable =
269
+ event.clientX >= tableRect.right - 1 &&
270
+ event.clientX < tableRect.right + 20;
271
+
272
+ // without this check, we'd also hide draghandles when hovering over them
273
+ const hideHandles =
274
+ event.clientX > tableRect.right || event.clientY > tableRect.bottom;
275
+
276
+ this.state = {
277
+ ...this.state!,
278
+ show: true,
279
+ showAddOrRemoveRowsButton: belowTable,
280
+ showAddOrRemoveColumnsButton: toRightOfTable,
281
+ referencePosTable: tableRect,
282
+ block: tableBlock,
283
+ widgetContainer,
284
+ colIndex: hideHandles ? undefined : this.state!.colIndex,
285
+ rowIndex: hideHandles ? undefined : this.state!.rowIndex,
286
+ referencePosCell: hideHandles
287
+ ? undefined
288
+ : this.state!.referencePosCell,
289
+ };
290
+ } else {
291
+ const colIndex = getChildIndex(target.domNode);
292
+ const rowIndex = getChildIndex(target.domNode.parentElement!);
293
+ const cellRect = target.domNode.getBoundingClientRect();
294
+
295
+ if (
296
+ this.state !== undefined &&
297
+ this.state.show &&
298
+ this.tableId === blockEl.id &&
299
+ this.state.rowIndex === rowIndex &&
300
+ this.state.colIndex === colIndex
301
+ ) {
302
+ // no update needed
303
+ return;
304
+ }
233
305
 
234
- if (
235
- this.state !== undefined &&
236
- this.state.show &&
237
- this.tableId === blockEl.id &&
238
- this.state.rowIndex === rowIndex &&
239
- this.state.colIndex === colIndex
240
- ) {
241
- return;
306
+ this.state = {
307
+ show: true,
308
+ showAddOrRemoveColumnsButton:
309
+ colIndex === tableBlock.content.rows[0].cells.length - 1,
310
+ showAddOrRemoveRowsButton:
311
+ rowIndex === tableBlock.content.rows.length - 1,
312
+ referencePosTable: tableRect,
313
+
314
+ block: tableBlock,
315
+ draggingState: undefined,
316
+ referencePosCell: cellRect,
317
+ colIndex: colIndex,
318
+ rowIndex: rowIndex,
319
+
320
+ widgetContainer,
321
+ };
242
322
  }
243
-
244
- this.state = {
245
- show: true,
246
- referencePosCell: cellRect,
247
- referencePosTable: tableRect,
248
-
249
- block: tableBlock,
250
- colIndex: colIndex,
251
- rowIndex: rowIndex,
252
-
253
- draggingState: undefined,
254
- };
255
323
  this.emitUpdate();
256
324
 
257
325
  return false;
@@ -265,12 +333,8 @@ export class TableHandlesView<
265
333
  event.preventDefault();
266
334
  event.dataTransfer!.dropEffect = "move";
267
335
 
268
- hideElementsWithClassNames(
269
- [
270
- "column-resize-handle",
271
- "prosemirror-dropcursor-block",
272
- "prosemirror-dropcursor-inline",
273
- ],
336
+ hideElements(
337
+ ".prosemirror-dropcursor-block, .prosemirror-dropcursor-inline",
274
338
  this.pmView.root
275
339
  );
276
340
 
@@ -358,25 +422,37 @@ export class TableHandlesView<
358
422
  };
359
423
 
360
424
  dropHandler = (event: DragEvent) => {
425
+ this.mouseState = "up";
361
426
  if (this.state === undefined || this.state.draggingState === undefined) {
362
427
  return;
363
428
  }
364
429
 
430
+ if (
431
+ this.state.rowIndex === undefined ||
432
+ this.state.colIndex === undefined
433
+ ) {
434
+ throw new Error(
435
+ "Attempted to drop table row or column, but no table block was hovered prior."
436
+ );
437
+ }
438
+
365
439
  event.preventDefault();
366
440
 
441
+ const { draggingState, colIndex, rowIndex } = this.state;
442
+
367
443
  const rows = this.state.block.content.rows;
368
444
 
369
- if (this.state.draggingState.draggedCellOrientation === "row") {
370
- const rowToMove = rows[this.state.draggingState.originalIndex];
371
- rows.splice(this.state.draggingState.originalIndex, 1);
372
- rows.splice(this.state.rowIndex, 0, rowToMove);
445
+ if (draggingState.draggedCellOrientation === "row") {
446
+ const rowToMove = rows[draggingState.originalIndex];
447
+ rows.splice(draggingState.originalIndex, 1);
448
+ rows.splice(rowIndex, 0, rowToMove);
373
449
  } else {
374
450
  const cellsToMove = rows.map(
375
- (row) => row.cells[this.state!.draggingState!.originalIndex]
451
+ (row) => row.cells[draggingState.originalIndex]
376
452
  );
377
453
  rows.forEach((row, rowIndex) => {
378
- row.cells.splice(this.state!.draggingState!.originalIndex, 1);
379
- row.cells.splice(this.state!.colIndex, 0, cellsToMove[rowIndex]);
454
+ row.cells.splice(draggingState.originalIndex, 1);
455
+ row.cells.splice(colIndex, 0, cellsToMove[rowIndex]);
380
456
  });
381
457
  }
382
458
 
@@ -392,26 +468,45 @@ export class TableHandlesView<
392
468
  // the existing selection out of the block.
393
469
  this.editor.setTextCursorPosition(this.state.block.id);
394
470
  };
471
+ // Updates drag handle positions on table content updates.
472
+ update() {
473
+ if (!this.state || !this.state.show) {
474
+ return;
475
+ }
395
476
 
396
- scrollHandler = () => {
397
- if (this.state?.show) {
398
- const tableElement = this.pmView.root.querySelector(
399
- `[data-node-type="blockContainer"][data-id="${this.tableId}"] table`
400
- )!;
401
- const cellElement = tableElement.querySelector(
402
- `tr:nth-child(${this.state.rowIndex + 1}) > td:nth-child(${
403
- this.state.colIndex + 1
404
- })`
405
- )!;
406
-
407
- this.state.referencePosTable = tableElement.getBoundingClientRect();
408
- this.state.referencePosCell = cellElement.getBoundingClientRect();
409
- this.emitUpdate();
477
+ const tableBody = this.tableElement!.querySelector("tbody");
478
+ if (!tableBody) {
479
+ return;
410
480
  }
411
- };
481
+
482
+ if (
483
+ this.state.rowIndex !== undefined &&
484
+ this.state.colIndex !== undefined
485
+ ) {
486
+ // If rows or columns are deleted in the update, the hovered indices for
487
+ // those may now be out of bounds. If this is the case, they are moved to
488
+ // the new last row or column.
489
+ if (this.state.rowIndex >= tableBody.children.length) {
490
+ this.state.rowIndex = tableBody.children.length - 1;
491
+ }
492
+ if (this.state.colIndex >= tableBody.children[0].children.length) {
493
+ this.state.colIndex = tableBody.children[0].children.length - 1;
494
+ }
495
+
496
+ const row = tableBody.children[this.state.rowIndex];
497
+ const cell = row.children[this.state.colIndex];
498
+ this.state.referencePosCell = cell.getBoundingClientRect();
499
+ }
500
+
501
+ this.state.block = this.editor.getBlock(this.state.block.id)!;
502
+ this.state.referencePosTable = tableBody.getBoundingClientRect();
503
+ this.emitUpdate();
504
+ }
412
505
 
413
506
  destroy() {
414
507
  this.pmView.dom.removeEventListener("mousemove", this.mouseMoveHandler);
508
+ window.removeEventListener("mouseup", this.mouseUpHandler);
509
+ this.pmView.dom.removeEventListener("mousedown", this.viewMousedownHandler);
415
510
  this.pmView.root.removeEventListener(
416
511
  "dragover",
417
512
  this.dragOverHandler as EventListener
@@ -420,7 +515,6 @@ export class TableHandlesView<
420
515
  "drop",
421
516
  this.dropHandler as EventListener
422
517
  );
423
- this.pmView.root.removeEventListener("scroll", this.scrollHandler, true);
424
518
  }
425
519
  }
426
520
 
@@ -467,6 +561,10 @@ export class TableHandlesProsemirrorPlugin<
467
561
  ? this.view.state.rowIndex
468
562
  : this.view.state.colIndex;
469
563
 
564
+ if (newIndex === undefined) {
565
+ return;
566
+ }
567
+
470
568
  const decorations: Decoration[] = [];
471
569
 
472
570
  if (newIndex === this.view.state.draggingState.originalIndex) {
@@ -547,6 +645,7 @@ export class TableHandlesProsemirrorPlugin<
547
645
  (newIndex > this.view.state.draggingState.originalIndex
548
646
  ? cellNode.nodeSize - 2
549
647
  : 0);
648
+
550
649
  decorations.push(
551
650
  // The widget is a small bar which spans the height of the cell.
552
651
  Decoration.widget(decorationPos, () => {
@@ -592,7 +691,10 @@ export class TableHandlesProsemirrorPlugin<
592
691
  dataTransfer: DataTransfer | null;
593
692
  clientX: number;
594
693
  }) => {
595
- if (this.view!.state === undefined) {
694
+ if (
695
+ this.view!.state === undefined ||
696
+ this.view!.state.colIndex === undefined
697
+ ) {
596
698
  throw new Error(
597
699
  "Attempted to drag table column, but no table block was hovered prior."
598
700
  );
@@ -628,7 +730,10 @@ export class TableHandlesProsemirrorPlugin<
628
730
  dataTransfer: DataTransfer | null;
629
731
  clientY: number;
630
732
  }) => {
631
- if (this.view!.state === undefined) {
733
+ if (
734
+ this.view!.state === undefined ||
735
+ this.view!.state.rowIndex === undefined
736
+ ) {
632
737
  throw new Error(
633
738
  "Attempted to drag table row, but no table block was hovered prior."
634
739
  );
@@ -62,7 +62,7 @@ export const TrailingNode = Extension.create<TrailingNodeOptions>({
62
62
  lastNode = lastNode.lastChild;
63
63
 
64
64
  if (!lastNode || lastNode.type.name !== "blockContainer") {
65
- throw new Error("Expected blockContainer");
65
+ return true; // not a blockContainer, but for example Columns. Insert trailing node
66
66
  }
67
67
 
68
68
  const lastContentNode = lastNode.firstChild;
@@ -0,0 +1,19 @@
1
+ import { EditorView } from "prosemirror-view";
2
+
3
+ export function getDraggableBlockFromElement(
4
+ element: Element,
5
+ view: EditorView
6
+ ) {
7
+ while (
8
+ element &&
9
+ element.parentElement &&
10
+ element.parentElement !== view.dom &&
11
+ element.getAttribute?.("data-node-type") !== "blockContainer"
12
+ ) {
13
+ element = element.parentElement;
14
+ }
15
+ if (element.getAttribute?.("data-node-type") !== "blockContainer") {
16
+ return undefined;
17
+ }
18
+ return { node: element as HTMLElement, id: element.getAttribute("data-id")! };
19
+ }
@@ -52,6 +52,12 @@ export const ar: Dictionary = {
52
52
  aliases: ["ف", "فقرة"],
53
53
  group: "الكتل الأساسية",
54
54
  },
55
+ code_block: {
56
+ title: "كود",
57
+ subtext: "يستخدم لعرض الكود مع تحديد الصيغة",
58
+ aliases: ["كود", "مسبق"],
59
+ group: "الكتل الأساسية",
60
+ },
55
61
  table: {
56
62
  title: "جدول",
57
63
  subtext: "يستخدم للجداول",