@blocknote/core 0.38.0 → 0.39.1-capitol

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 (239) hide show
  1. package/dist/BlockNoteSchema-Bsa_tSAC.cjs +11 -0
  2. package/dist/BlockNoteSchema-Bsa_tSAC.cjs.map +1 -0
  3. package/dist/BlockNoteSchema-CZez1nQf.js +4244 -0
  4. package/dist/BlockNoteSchema-CZez1nQf.js.map +1 -0
  5. package/dist/blocknote.cjs +4 -12
  6. package/dist/blocknote.cjs.map +1 -1
  7. package/dist/blocknote.js +3401 -7305
  8. package/dist/blocknote.js.map +1 -1
  9. package/dist/blocks.cjs +2 -0
  10. package/dist/blocks.cjs.map +1 -0
  11. package/dist/blocks.js +71 -0
  12. package/dist/blocks.js.map +1 -0
  13. package/dist/style.css +1 -1
  14. package/dist/webpack-stats.json +1 -1
  15. package/package.json +19 -17
  16. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
  17. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
  18. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
  19. package/src/api/blockManipulation/setupTestEnv.ts +0 -1
  20. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +6 -10
  21. package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
  22. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
  23. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
  24. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
  25. package/src/api/pmUtil.ts +1 -1
  26. package/src/api/positionMapping.test.ts +58 -15
  27. package/src/api/positionMapping.ts +2 -4
  28. package/src/blocks/Audio/block.ts +174 -0
  29. package/src/blocks/BlockNoteSchema.ts +59 -0
  30. package/src/blocks/Code/block.ts +299 -0
  31. package/src/blocks/File/block.ts +98 -0
  32. package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +5 -2
  33. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +15 -6
  34. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
  35. package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +21 -2
  36. package/src/blocks/Heading/block.ts +138 -0
  37. package/src/blocks/Image/block.ts +190 -0
  38. package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
  39. package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
  40. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
  41. package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
  42. package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
  43. package/src/blocks/PageBreak/block.ts +72 -0
  44. package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
  45. package/src/blocks/Paragraph/block.ts +80 -0
  46. package/src/blocks/Quote/block.ts +90 -0
  47. package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
  48. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
  49. package/src/blocks/Video/block.ts +143 -0
  50. package/src/blocks/defaultBlockHelpers.ts +2 -2
  51. package/src/blocks/defaultBlockTypeGuards.ts +143 -174
  52. package/src/blocks/defaultBlocks.ts +107 -35
  53. package/src/blocks/defaultProps.ts +145 -4
  54. package/src/blocks/index.ts +26 -0
  55. package/src/blocks/utils/listItemEnterHandler.ts +42 -0
  56. package/src/editor/Block.css +54 -18
  57. package/src/editor/BlockNoteEditor.ts +256 -211
  58. package/src/editor/BlockNoteExtension.ts +92 -0
  59. package/src/editor/BlockNoteExtensions.ts +18 -17
  60. package/src/editor/defaultColors.ts +2 -2
  61. package/src/exporter/Exporter.ts +1 -1
  62. package/src/exporter/mapping.ts +1 -1
  63. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
  64. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
  65. package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
  66. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
  67. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
  68. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  69. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  70. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
  71. package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
  72. package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
  73. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
  74. package/src/extensions/Comments/CommentsPlugin.ts +1 -1
  75. package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
  76. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
  77. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
  78. package/src/extensions/Placeholder/PlaceholderPlugin.ts +6 -6
  79. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
  80. package/src/extensions/SideMenu/SideMenuPlugin.ts +1 -3
  81. package/src/extensions/SideMenu/dragging.ts +2 -2
  82. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +4 -7
  83. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
  84. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
  85. package/src/extensions/TableHandles/TableHandlesPlugin.ts +8 -8
  86. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
  87. package/src/extensions/TextColor/TextColorExtension.ts +3 -17
  88. package/src/extensions/TextColor/TextColorMark.ts +4 -9
  89. package/src/extensions/UniqueID/UniqueID.ts +6 -13
  90. package/src/index.ts +2 -28
  91. package/src/schema/blocks/createSpec.ts +342 -169
  92. package/src/schema/blocks/internal.ts +77 -138
  93. package/src/schema/blocks/types.ts +264 -94
  94. package/src/schema/index.ts +1 -0
  95. package/src/schema/inlineContent/createSpec.ts +99 -21
  96. package/src/schema/inlineContent/internal.ts +16 -7
  97. package/src/schema/inlineContent/types.ts +24 -2
  98. package/src/schema/propTypes.ts +15 -9
  99. package/src/schema/schema.ts +209 -0
  100. package/src/schema/styles/createSpec.ts +79 -31
  101. package/src/schema/styles/internal.ts +61 -2
  102. package/src/schema/styles/types.ts +17 -3
  103. package/src/util/topo-sort.test.ts +125 -0
  104. package/src/util/topo-sort.ts +160 -0
  105. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
  106. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  107. package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
  108. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
  109. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
  110. package/types/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.d.ts +2 -0
  111. package/types/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.d.ts +6 -0
  112. package/types/src/api/pmUtil.d.ts +1 -1
  113. package/types/src/blocks/Audio/block.d.ts +58 -0
  114. package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
  115. package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
  116. package/types/src/blocks/Code/shiki.d.ts +4 -0
  117. package/types/src/blocks/Divider/block.d.ts +3 -0
  118. package/types/src/blocks/File/block.d.ts +37 -0
  119. package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
  120. package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
  121. package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
  122. package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
  123. package/types/src/blocks/Heading/block.d.ts +71 -0
  124. package/types/src/blocks/Image/block.d.ts +102 -0
  125. package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
  126. package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
  127. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
  128. package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
  129. package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
  130. package/types/src/blocks/PageBreak/block.d.ts +11 -0
  131. package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
  132. package/types/src/blocks/Paragraph/block.d.ts +25 -0
  133. package/types/src/blocks/Quote/block.d.ts +17 -0
  134. package/types/src/blocks/Table/block.d.ts +21 -0
  135. package/types/src/blocks/Video/block.d.ts +67 -0
  136. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
  137. package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
  138. package/types/src/blocks/defaultBlocks.d.ts +221 -1060
  139. package/types/src/blocks/defaultProps.d.ts +17 -1
  140. package/types/src/blocks/index.d.ts +24 -0
  141. package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
  142. package/types/src/editor/BlockNoteEditor.d.ts +36 -67
  143. package/types/src/editor/BlockNoteExtension.d.ts +67 -0
  144. package/types/src/editor/BlockNoteExtensions.d.ts +1 -1
  145. package/types/src/editor/defaultColors.d.ts +8 -76
  146. package/types/src/editor/managers/BlockManager.d.ts +114 -0
  147. package/types/src/editor/managers/CollaborationManager.d.ts +115 -0
  148. package/types/src/editor/managers/EventManager.d.ts +58 -0
  149. package/types/src/editor/managers/ExportManager.d.ts +64 -0
  150. package/types/src/editor/managers/ExtensionManager.d.ts +68 -0
  151. package/types/src/editor/managers/SelectionManager.d.ts +54 -0
  152. package/types/src/editor/managers/StateManager.d.ts +115 -0
  153. package/types/src/editor/managers/StyleManager.d.ts +48 -0
  154. package/types/src/editor/managers/index.d.ts +8 -0
  155. package/types/src/exporter/Exporter.d.ts +1 -1
  156. package/types/src/exporter/mapping.d.ts +1 -1
  157. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
  158. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
  159. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
  160. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
  161. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
  162. package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
  163. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  164. package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
  165. package/types/src/index.d.ts +2 -25
  166. package/types/src/schema/blocks/createSpec.d.ts +16 -36
  167. package/types/src/schema/blocks/internal.d.ts +11 -33
  168. package/types/src/schema/blocks/types.d.ts +181 -57
  169. package/types/src/schema/index.d.ts +1 -0
  170. package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
  171. package/types/src/schema/inlineContent/internal.d.ts +7 -15
  172. package/types/src/schema/inlineContent/types.d.ts +15 -1
  173. package/types/src/schema/propTypes.d.ts +4 -4
  174. package/types/src/schema/schema.d.ts +40 -0
  175. package/types/src/schema/styles/createSpec.d.ts +6 -4
  176. package/types/src/schema/styles/internal.d.ts +6 -3
  177. package/types/src/schema/styles/types.d.ts +11 -2
  178. package/types/src/util/topo-sort.d.ts +18 -0
  179. package/types/src/util/topo-sort.test.d.ts +1 -0
  180. package/dist/tsconfig.tsbuildinfo +0 -1
  181. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -144
  182. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
  183. package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
  184. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
  185. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -159
  186. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
  187. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
  188. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
  189. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
  190. package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
  191. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
  192. package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
  193. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
  194. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
  195. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -158
  196. package/src/editor/BlockNoteSchema.ts +0 -107
  197. package/src/editor/BlockNoteTipTapEditor.ts +0 -335
  198. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
  199. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
  200. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
  201. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
  202. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
  203. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
  204. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
  205. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
  206. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
  207. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
  208. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
  209. package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
  210. package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
  211. package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
  212. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
  213. package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
  214. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
  215. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
  216. package/types/src/editor/BlockNoteSchema.d.ts +0 -34
  217. package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
  218. /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
  219. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
  220. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
  221. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
  222. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
  223. /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  224. /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
  225. /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
  226. /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
  227. /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
  228. /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
  229. /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
  230. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
  231. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
  232. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
  233. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
  234. /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
  235. /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
  236. /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
  237. /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
  238. /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
  239. /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
@@ -1,12 +1,11 @@
1
1
  import { Node, mergeAttributes } from "@tiptap/core";
2
- import { TableCell } from "@tiptap/extension-table-cell";
3
- import { TableHeader } from "@tiptap/extension-table-header";
4
2
  import { DOMParser, Fragment, Node as PMNode, Schema } from "prosemirror-model";
5
3
  import { TableView } from "prosemirror-tables";
6
4
  import { NodeView } from "prosemirror-view";
5
+ import { createBlockNoteExtension } from "../../editor/BlockNoteExtension.js";
7
6
  import {
8
- createBlockSpecFromStronglyTypedTiptapNode,
9
- createStronglyTypedTiptapNode,
7
+ BlockConfig,
8
+ createBlockSpecFromTiptapNode,
10
9
  } from "../../schema/index.js";
11
10
  import { mergeCSSClasses } from "../../util/browser.js";
12
11
  import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
@@ -17,7 +16,134 @@ export const tablePropSchema = {
17
16
  textColor: defaultProps.textColor,
18
17
  };
19
18
 
20
- export const TableBlockContent = createStronglyTypedTiptapNode({
19
+ const TiptapTableHeader = Node.create<{
20
+ HTMLAttributes: Record<string, any>;
21
+ }>({
22
+ name: "tableHeader",
23
+
24
+ addOptions() {
25
+ return {
26
+ HTMLAttributes: {},
27
+ };
28
+ },
29
+
30
+ /**
31
+ * We allow table headers and cells to have multiple tableContent nodes because
32
+ * when merging cells, prosemirror-tables will concat the contents of the cells naively.
33
+ * This would cause that content to overflow into other cells when prosemirror tries to enforce the cell structure.
34
+ *
35
+ * So, we manually fix this up when reading back in the `nodeToBlock` and only ever place a single tableContent back into the cell.
36
+ */
37
+ content: "tableContent+",
38
+
39
+ addAttributes() {
40
+ return {
41
+ colspan: {
42
+ default: 1,
43
+ },
44
+ rowspan: {
45
+ default: 1,
46
+ },
47
+ colwidth: {
48
+ default: null,
49
+ parseHTML: (element) => {
50
+ const colwidth = element.getAttribute("colwidth");
51
+ const value = colwidth
52
+ ? colwidth.split(",").map((width) => parseInt(width, 10))
53
+ : null;
54
+
55
+ return value;
56
+ },
57
+ },
58
+ };
59
+ },
60
+
61
+ tableRole: "header_cell",
62
+
63
+ isolating: true,
64
+
65
+ parseHTML() {
66
+ return [
67
+ {
68
+ tag: "th",
69
+ // As `th` elements can contain multiple paragraphs, we need to merge their contents
70
+ // into a single one so that ProseMirror can parse everything correctly.
71
+ getContent: (node, schema) =>
72
+ parseTableContent(node as HTMLElement, schema),
73
+ },
74
+ ];
75
+ },
76
+
77
+ renderHTML({ HTMLAttributes }) {
78
+ return [
79
+ "th",
80
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
81
+ 0,
82
+ ];
83
+ },
84
+ });
85
+
86
+ const TiptapTableCell = Node.create<{
87
+ HTMLAttributes: Record<string, any>;
88
+ }>({
89
+ name: "tableCell",
90
+
91
+ addOptions() {
92
+ return {
93
+ HTMLAttributes: {},
94
+ };
95
+ },
96
+
97
+ content: "tableContent+",
98
+
99
+ addAttributes() {
100
+ return {
101
+ colspan: {
102
+ default: 1,
103
+ },
104
+ rowspan: {
105
+ default: 1,
106
+ },
107
+ colwidth: {
108
+ default: null,
109
+ parseHTML: (element) => {
110
+ const colwidth = element.getAttribute("colwidth");
111
+ const value = colwidth
112
+ ? colwidth.split(",").map((width) => parseInt(width, 10))
113
+ : null;
114
+
115
+ return value;
116
+ },
117
+ },
118
+ };
119
+ },
120
+
121
+ tableRole: "cell",
122
+
123
+ isolating: true,
124
+
125
+ parseHTML() {
126
+ return [
127
+ {
128
+ tag: "td",
129
+ // As `td` elements can contain multiple paragraphs, we need to merge their contents
130
+ // into a single one so that ProseMirror can parse everything correctly.
131
+ getContent: (node, schema) =>
132
+ parseTableContent(node as HTMLElement, schema),
133
+ },
134
+ ];
135
+ },
136
+
137
+ renderHTML({ HTMLAttributes }) {
138
+ return [
139
+ "td",
140
+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
141
+ 0,
142
+ ];
143
+ },
144
+ });
145
+
146
+ const TiptapTableNode = Node.create({
21
147
  name: "table",
22
148
  content: "tableRow+",
23
149
  group: "blockContent",
@@ -134,7 +260,7 @@ export const TableBlockContent = createStronglyTypedTiptapNode({
134
260
  },
135
261
  });
136
262
 
137
- const TableParagraph = createStronglyTypedTiptapNode({
263
+ const TiptapTableParagraph = Node.create({
138
264
  name: "tableParagraph",
139
265
  group: "tableContent",
140
266
  content: "inline*",
@@ -179,7 +305,9 @@ const TableParagraph = createStronglyTypedTiptapNode({
179
305
  * This extension allows you to create table rows.
180
306
  * @see https://www.tiptap.dev/api/nodes/table-row
181
307
  */
182
- export const TableRow = Node.create<{ HTMLAttributes: Record<string, any> }>({
308
+ const TiptapTableRow = Node.create<{
309
+ HTMLAttributes: Record<string, any>;
310
+ }>({
183
311
  name: "tableRow",
184
312
 
185
313
  addOptions() {
@@ -241,47 +369,37 @@ function parseTableContent(node: HTMLElement, schema: Schema) {
241
369
  return Fragment.fromArray(extractedContent);
242
370
  }
243
371
 
244
- export const Table = createBlockSpecFromStronglyTypedTiptapNode(
245
- TableBlockContent,
246
- tablePropSchema,
247
- [
248
- TableExtension,
249
- TableParagraph,
250
- TableHeader.extend({
251
- /**
252
- * We allow table headers and cells to have multiple tableContent nodes because
253
- * when merging cells, prosemirror-tables will concat the contents of the cells naively.
254
- * This would cause that content to overflow into other cells when prosemirror tries to enforce the cell structure.
255
- *
256
- * So, we manually fix this up when reading back in the `nodeToBlock` and only ever place a single tableContent back into the cell.
257
- */
258
- content: "tableContent+",
259
- parseHTML() {
260
- return [
261
- {
262
- tag: "th",
263
- // As `th` elements can contain multiple paragraphs, we need to merge their contents
264
- // into a single one so that ProseMirror can parse everything correctly.
265
- getContent: (node, schema) =>
266
- parseTableContent(node as HTMLElement, schema),
267
- },
268
- ];
269
- },
270
- }),
271
- TableCell.extend({
272
- content: "tableContent+",
273
- parseHTML() {
274
- return [
275
- {
276
- tag: "td",
277
- // As `td` elements can contain multiple paragraphs, we need to merge their contents
278
- // into a single one so that ProseMirror can parse everything correctly.
279
- getContent: (node, schema) =>
280
- parseTableContent(node as HTMLElement, schema),
281
- },
282
- ];
283
- },
284
- }),
285
- TableRow,
286
- ],
287
- );
372
+ export type TableBlockConfig = BlockConfig<
373
+ "table",
374
+ {
375
+ textColor: {
376
+ default: "default";
377
+ };
378
+ },
379
+ "table"
380
+ >;
381
+
382
+ export const createTableBlockSpec = () =>
383
+ createBlockSpecFromTiptapNode(
384
+ { node: TiptapTableNode, type: "table", content: "table" },
385
+ tablePropSchema,
386
+ [
387
+ createBlockNoteExtension({
388
+ key: "table-extensions",
389
+ tiptapExtensions: [
390
+ TableExtension,
391
+ TiptapTableParagraph,
392
+ TiptapTableHeader,
393
+ TiptapTableCell,
394
+ TiptapTableRow,
395
+ ],
396
+ }),
397
+ ],
398
+ );
399
+
400
+ // We need to declare this here because we aren't using the table extensions from tiptap, so the types are not automatically inferred.
401
+ declare module "@tiptap/core" {
402
+ interface NodeConfig {
403
+ tableRole?: string;
404
+ }
405
+ }
@@ -28,7 +28,7 @@ export const createToggleWrapper = (
28
28
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
29
29
  destroy?: () => void;
30
30
  } => {
31
- if ("isToggleable" in block.props && !block.props.isToggleable) {
31
+ if (!("isToggleable" in block.props) || !block.props.isToggleable) {
32
32
  return {
33
33
  dom: renderedElement,
34
34
  };
@@ -0,0 +1,143 @@
1
+ import { createBlockConfig, createBlockSpec } from "../../schema/index.js";
2
+ import { defaultProps, parseDefaultProps } from "../defaultProps.js";
3
+ import { parseFigureElement } from "../File/helpers/parse/parseFigureElement.js";
4
+ import { createResizableFileBlockWrapper } from "../File/helpers/render/createResizableFileBlockWrapper.js";
5
+ import { createFigureWithCaption } from "../File/helpers/toExternalHTML/createFigureWithCaption.js";
6
+ import { createLinkWithCaption } from "../File/helpers/toExternalHTML/createLinkWithCaption.js";
7
+ import { parseVideoElement } from "./parseVideoElement.js";
8
+
9
+ export const FILE_VIDEO_ICON_SVG =
10
+ '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 3.9934C2 3.44476 2.45531 3 2.9918 3H21.0082C21.556 3 22 3.44495 22 3.9934V20.0066C22 20.5552 21.5447 21 21.0082 21H2.9918C2.44405 21 2 20.5551 2 20.0066V3.9934ZM8 5V19H16V5H8ZM4 5V7H6V5H4ZM18 5V7H20V5H18ZM4 9V11H6V9H4ZM18 9V11H20V9H18ZM4 13V15H6V13H4ZM18 13V15H20V13H18ZM4 17V19H6V17H4ZM18 17V19H20V17H18Z"></path></svg>';
11
+
12
+ export interface VideoOptions {
13
+ icon?: string;
14
+ }
15
+
16
+ export type VideoBlockConfig = ReturnType<typeof createVideoBlockConfig>;
17
+
18
+ export const createVideoBlockConfig = createBlockConfig(
19
+ (_ctx: VideoOptions) => ({
20
+ type: "video" as const,
21
+ propSchema: {
22
+ textAlignment: defaultProps.textAlignment,
23
+ backgroundColor: defaultProps.backgroundColor,
24
+ name: { default: "" as const },
25
+ url: { default: "" as const },
26
+ caption: { default: "" as const },
27
+ showPreview: { default: true },
28
+ previewWidth: { default: undefined, type: "number" as const },
29
+ },
30
+ content: "none" as const,
31
+ }),
32
+ );
33
+
34
+ export const videoParse = (_config: VideoOptions) => (element: HTMLElement) => {
35
+ if (element.tagName === "VIDEO") {
36
+ // Ignore if parent figure has already been parsed.
37
+ if (element.closest("figure")) {
38
+ return undefined;
39
+ }
40
+
41
+ const { backgroundColor } = parseDefaultProps(element);
42
+
43
+ return {
44
+ ...parseVideoElement(element as HTMLVideoElement),
45
+ backgroundColor,
46
+ };
47
+ }
48
+
49
+ if (element.tagName === "FIGURE") {
50
+ const parsedFigure = parseFigureElement(element, "video");
51
+ if (!parsedFigure) {
52
+ return undefined;
53
+ }
54
+
55
+ const { targetElement, caption } = parsedFigure;
56
+
57
+ const { backgroundColor } = parseDefaultProps(element);
58
+
59
+ return {
60
+ ...parseVideoElement(targetElement as HTMLVideoElement),
61
+ backgroundColor,
62
+ caption,
63
+ };
64
+ }
65
+
66
+ return undefined;
67
+ };
68
+
69
+ export const createVideoBlockSpec = createBlockSpec(
70
+ createVideoBlockConfig,
71
+ (config) => ({
72
+ meta: {
73
+ fileBlockAccept: ["video/*"],
74
+ },
75
+ parse: videoParse(config),
76
+ render(block, editor) {
77
+ const icon = document.createElement("div");
78
+ icon.innerHTML = config.icon ?? FILE_VIDEO_ICON_SVG;
79
+
80
+ const videoWrapper = document.createElement("div");
81
+ videoWrapper.className = "bn-visual-media-wrapper";
82
+
83
+ const video = document.createElement("video");
84
+ video.className = "bn-visual-media";
85
+ if (editor.resolveFileUrl) {
86
+ editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
87
+ video.src = downloadUrl;
88
+ });
89
+ } else {
90
+ video.src = block.props.url;
91
+ }
92
+ video.controls = true;
93
+ video.contentEditable = "false";
94
+ video.draggable = false;
95
+ video.width = block.props.previewWidth;
96
+ videoWrapper.appendChild(video);
97
+
98
+ return createResizableFileBlockWrapper(
99
+ block,
100
+ editor,
101
+ { dom: videoWrapper },
102
+ videoWrapper,
103
+ icon.firstElementChild as HTMLElement,
104
+ );
105
+ },
106
+ toExternalHTML(block) {
107
+ if (!block.props.url) {
108
+ const div = document.createElement("p");
109
+ div.textContent = "Add video";
110
+
111
+ return {
112
+ dom: div,
113
+ };
114
+ }
115
+
116
+ let video;
117
+ if (block.props.showPreview) {
118
+ video = document.createElement("video");
119
+ video.src = block.props.url;
120
+ if (block.props.previewWidth) {
121
+ video.width = block.props.previewWidth;
122
+ }
123
+ } else {
124
+ video = document.createElement("a");
125
+ video.href = block.props.url;
126
+ video.textContent = block.props.name || block.props.url;
127
+ }
128
+
129
+ if (block.props.caption) {
130
+ if (block.props.showPreview) {
131
+ return createFigureWithCaption(video, block.props.caption);
132
+ } else {
133
+ return createLinkWithCaption(video, block.props.caption);
134
+ }
135
+ }
136
+
137
+ return {
138
+ dom: video,
139
+ };
140
+ },
141
+ runsBefore: ["file"],
142
+ }),
143
+ );
@@ -100,13 +100,13 @@ export const defaultBlockToHTML = <
100
100
  // This is used when parsing blocks like list items and table cells, as they may
101
101
  // contain multiple paragraphs that ProseMirror will not be able to handle
102
102
  // properly.
103
- export function mergeParagraphs(element: HTMLElement) {
103
+ export function mergeParagraphs(element: HTMLElement, separator = "<br>") {
104
104
  const paragraphs = element.querySelectorAll("p");
105
105
  if (paragraphs.length > 1) {
106
106
  const firstParagraph = paragraphs[0];
107
107
  for (let i = 1; i < paragraphs.length; i++) {
108
108
  const paragraph = paragraphs[i];
109
- firstParagraph.innerHTML += "<br>" + paragraph.innerHTML;
109
+ firstParagraph.innerHTML += separator + paragraph.innerHTML;
110
110
  paragraph.remove();
111
111
  }
112
112
  }