@blocknote/core 0.38.0 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/dist/BlockNoteSchema-DmZ6UQfY.cjs +11 -0
  2. package/dist/BlockNoteSchema-DmZ6UQfY.cjs.map +1 -0
  3. package/dist/BlockNoteSchema-oR047ACf.js +4275 -0
  4. package/dist/BlockNoteSchema-oR047ACf.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/tsconfig.tsbuildinfo +1 -1
  15. package/dist/webpack-stats.json +1 -1
  16. package/package.json +19 -16
  17. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
  18. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
  19. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
  20. package/src/api/blockManipulation/setupTestEnv.ts +0 -1
  21. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +6 -10
  22. package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
  23. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
  24. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
  25. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
  26. package/src/api/pmUtil.ts +1 -1
  27. package/src/api/positionMapping.test.ts +58 -15
  28. package/src/api/positionMapping.ts +2 -4
  29. package/src/blocks/Audio/block.ts +174 -0
  30. package/src/blocks/BlockNoteSchema.ts +59 -0
  31. package/src/blocks/Code/block.ts +303 -0
  32. package/src/blocks/Code/shiki.ts +73 -0
  33. package/src/blocks/File/block.ts +98 -0
  34. package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +5 -2
  35. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +15 -6
  36. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
  37. package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +21 -2
  38. package/src/blocks/Heading/block.ts +138 -0
  39. package/src/blocks/Image/block.ts +190 -0
  40. package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
  41. package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
  42. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
  43. package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
  44. package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
  45. package/src/blocks/PageBreak/block.ts +72 -0
  46. package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
  47. package/src/blocks/Paragraph/block.ts +80 -0
  48. package/src/blocks/Quote/block.ts +90 -0
  49. package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
  50. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
  51. package/src/blocks/Video/block.ts +143 -0
  52. package/src/blocks/defaultBlockHelpers.ts +2 -2
  53. package/src/blocks/defaultBlockTypeGuards.ts +143 -174
  54. package/src/blocks/defaultBlocks.ts +107 -35
  55. package/src/blocks/defaultProps.ts +145 -4
  56. package/src/blocks/index.ts +26 -0
  57. package/src/blocks/utils/listItemEnterHandler.ts +42 -0
  58. package/src/editor/Block.css +54 -18
  59. package/src/editor/BlockNoteEditor.ts +256 -211
  60. package/src/editor/BlockNoteExtension.ts +92 -0
  61. package/src/editor/BlockNoteExtensions.ts +18 -17
  62. package/src/editor/defaultColors.ts +2 -2
  63. package/src/exporter/Exporter.ts +1 -1
  64. package/src/exporter/mapping.ts +1 -1
  65. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
  66. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
  67. package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
  68. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
  69. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
  70. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  71. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  72. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
  73. package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
  74. package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
  75. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
  76. package/src/extensions/Comments/CommentsPlugin.ts +1 -1
  77. package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
  78. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
  79. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
  80. package/src/extensions/Placeholder/PlaceholderPlugin.ts +6 -6
  81. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
  82. package/src/extensions/SideMenu/SideMenuPlugin.ts +1 -3
  83. package/src/extensions/SideMenu/dragging.ts +2 -2
  84. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +4 -7
  85. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
  86. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
  87. package/src/extensions/TableHandles/TableHandlesPlugin.ts +8 -8
  88. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
  89. package/src/extensions/TextColor/TextColorExtension.ts +3 -17
  90. package/src/extensions/TextColor/TextColorMark.ts +4 -9
  91. package/src/extensions/UniqueID/UniqueID.ts +6 -13
  92. package/src/index.ts +2 -28
  93. package/src/schema/blocks/createSpec.ts +342 -169
  94. package/src/schema/blocks/internal.ts +77 -138
  95. package/src/schema/blocks/types.ts +264 -94
  96. package/src/schema/index.ts +1 -0
  97. package/src/schema/inlineContent/createSpec.ts +99 -21
  98. package/src/schema/inlineContent/internal.ts +16 -7
  99. package/src/schema/inlineContent/types.ts +24 -2
  100. package/src/schema/propTypes.ts +15 -9
  101. package/src/schema/schema.ts +209 -0
  102. package/src/schema/styles/createSpec.ts +79 -31
  103. package/src/schema/styles/internal.ts +61 -2
  104. package/src/schema/styles/types.ts +17 -3
  105. package/src/util/topo-sort.test.ts +125 -0
  106. package/src/util/topo-sort.ts +160 -0
  107. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
  108. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  109. package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
  110. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
  111. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
  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/File/block.d.ts +37 -0
  118. package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
  119. package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
  120. package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
  121. package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
  122. package/types/src/blocks/Heading/block.d.ts +71 -0
  123. package/types/src/blocks/Image/block.d.ts +102 -0
  124. package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
  125. package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
  126. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
  127. package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
  128. package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
  129. package/types/src/blocks/PageBreak/block.d.ts +11 -0
  130. package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
  131. package/types/src/blocks/Paragraph/block.d.ts +25 -0
  132. package/types/src/blocks/Quote/block.d.ts +17 -0
  133. package/types/src/blocks/Table/block.d.ts +21 -0
  134. package/types/src/blocks/Video/block.d.ts +67 -0
  135. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
  136. package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
  137. package/types/src/blocks/defaultBlocks.d.ts +221 -1060
  138. package/types/src/blocks/defaultProps.d.ts +17 -1
  139. package/types/src/blocks/index.d.ts +24 -0
  140. package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
  141. package/types/src/editor/BlockNoteEditor.d.ts +36 -67
  142. package/types/src/editor/BlockNoteExtension.d.ts +67 -0
  143. package/types/src/editor/BlockNoteExtensions.d.ts +1 -1
  144. package/types/src/editor/defaultColors.d.ts +8 -76
  145. package/types/src/exporter/Exporter.d.ts +1 -1
  146. package/types/src/exporter/mapping.d.ts +1 -1
  147. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
  148. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
  149. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
  150. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
  151. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
  152. package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
  153. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  154. package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
  155. package/types/src/index.d.ts +2 -25
  156. package/types/src/schema/blocks/createSpec.d.ts +16 -36
  157. package/types/src/schema/blocks/internal.d.ts +11 -33
  158. package/types/src/schema/blocks/types.d.ts +181 -57
  159. package/types/src/schema/index.d.ts +1 -0
  160. package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
  161. package/types/src/schema/inlineContent/internal.d.ts +7 -15
  162. package/types/src/schema/inlineContent/types.d.ts +15 -1
  163. package/types/src/schema/propTypes.d.ts +4 -4
  164. package/types/src/schema/schema.d.ts +40 -0
  165. package/types/src/schema/styles/createSpec.d.ts +6 -4
  166. package/types/src/schema/styles/internal.d.ts +6 -3
  167. package/types/src/schema/styles/types.d.ts +11 -2
  168. package/types/src/util/topo-sort.d.ts +18 -0
  169. package/types/src/util/topo-sort.test.d.ts +1 -0
  170. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -144
  171. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
  172. package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
  173. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
  174. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -159
  175. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
  176. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
  177. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
  178. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
  179. package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
  180. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
  181. package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
  182. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
  183. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
  184. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -158
  185. package/src/editor/BlockNoteSchema.ts +0 -107
  186. package/src/editor/BlockNoteTipTapEditor.ts +0 -335
  187. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
  188. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
  189. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
  190. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
  191. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
  192. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
  193. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
  194. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
  195. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
  196. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
  197. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
  198. package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
  199. package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
  200. package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
  201. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
  202. package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
  203. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
  204. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
  205. package/types/src/editor/BlockNoteSchema.d.ts +0 -34
  206. package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
  207. /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
  208. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
  209. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
  210. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
  211. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
  212. /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  213. /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
  214. /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
  215. /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
  216. /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
  217. /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
  218. /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
  219. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
  220. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
  221. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
  222. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
  223. /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
  224. /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
  225. /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
  226. /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
  227. /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
  228. /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
@@ -1,14 +1,7 @@
1
- import {
2
- Attribute,
3
- Attributes,
4
- Editor,
5
- Extension,
6
- Node,
7
- NodeConfig,
8
- } from "@tiptap/core";
1
+ import { Attribute, Attributes, Editor, Node } from "@tiptap/core";
9
2
  import { defaultBlockToHTML } from "../../blocks/defaultBlockHelpers.js";
10
- import { inheritedProps } from "../../blocks/defaultProps.js";
11
3
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
4
+ import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
12
5
  import { mergeCSSClasses } from "../../util/browser.js";
13
6
  import { camelToDataKebab } from "../../util/string.js";
14
7
  import { InlineContentSchema } from "../inlineContent/types.js";
@@ -16,12 +9,9 @@ import { PropSchema, Props } from "../propTypes.js";
16
9
  import { StyleSchema } from "../styles/types.js";
17
10
  import {
18
11
  BlockConfig,
19
- BlockSchemaFromSpecs,
20
12
  BlockSchemaWithBlock,
21
- BlockSpec,
22
- BlockSpecs,
13
+ LooseBlockSpec,
23
14
  SpecificBlock,
24
- TiptapBlockImplementation,
25
15
  } from "./types.js";
26
16
 
27
17
  // Function that uses the 'propSchema' of a blockConfig to create a TipTap
@@ -30,64 +20,62 @@ import {
30
20
  export function propsToAttributes(propSchema: PropSchema): Attributes {
31
21
  const tiptapAttributes: Record<string, Attribute> = {};
32
22
 
33
- Object.entries(propSchema)
34
- .filter(([name, _spec]) => !inheritedProps.includes(name))
35
- .forEach(([name, spec]) => {
36
- tiptapAttributes[name] = {
37
- default: spec.default,
38
- keepOnSplit: true,
39
- // Props are displayed in kebab-case as HTML attributes. If a prop's
40
- // value is the same as its default, we don't display an HTML
41
- // attribute for it.
42
- parseHTML: (element) => {
43
- const value = element.getAttribute(camelToDataKebab(name));
23
+ Object.entries(propSchema).forEach(([name, spec]) => {
24
+ tiptapAttributes[name] = {
25
+ default: spec.default,
26
+ keepOnSplit: true,
27
+ // Props are displayed in kebab-case as HTML attributes. If a prop's
28
+ // value is the same as its default, we don't display an HTML
29
+ // attribute for it.
30
+ parseHTML: (element) => {
31
+ const value = element.getAttribute(camelToDataKebab(name));
32
+
33
+ if (value === null) {
34
+ return null;
35
+ }
36
+
37
+ if (
38
+ (spec.default === undefined && spec.type === "boolean") ||
39
+ (spec.default !== undefined && typeof spec.default === "boolean")
40
+ ) {
41
+ if (value === "true") {
42
+ return true;
43
+ }
44
44
 
45
- if (value === null) {
46
- return null;
45
+ if (value === "false") {
46
+ return false;
47
47
  }
48
48
 
49
- if (
50
- (spec.default === undefined && spec.type === "boolean") ||
51
- (spec.default !== undefined && typeof spec.default === "boolean")
52
- ) {
53
- if (value === "true") {
54
- return true;
55
- }
49
+ return null;
50
+ }
56
51
 
57
- if (value === "false") {
58
- return false;
59
- }
52
+ if (
53
+ (spec.default === undefined && spec.type === "number") ||
54
+ (spec.default !== undefined && typeof spec.default === "number")
55
+ ) {
56
+ const asNumber = parseFloat(value);
57
+ const isNumeric =
58
+ !Number.isNaN(asNumber) && Number.isFinite(asNumber);
60
59
 
61
- return null;
60
+ if (isNumeric) {
61
+ return asNumber;
62
62
  }
63
63
 
64
- if (
65
- (spec.default === undefined && spec.type === "number") ||
66
- (spec.default !== undefined && typeof spec.default === "number")
67
- ) {
68
- const asNumber = parseFloat(value);
69
- const isNumeric =
70
- !Number.isNaN(asNumber) && Number.isFinite(asNumber);
64
+ return null;
65
+ }
71
66
 
72
- if (isNumeric) {
73
- return asNumber;
67
+ return value;
68
+ },
69
+ renderHTML: (attributes) => {
70
+ // don't render to html if the value is the same as the default
71
+ return attributes[name] !== spec.default
72
+ ? {
73
+ [camelToDataKebab(name)]: attributes[name],
74
74
  }
75
-
76
- return null;
77
- }
78
-
79
- return value;
80
- },
81
- renderHTML: (attributes) => {
82
- // don't render to html if the value is the same as the default
83
- return attributes[name] !== spec.default
84
- ? {
85
- [camelToDataKebab(name)]: attributes[name],
86
- }
87
- : {};
88
- },
89
- };
90
- });
75
+ : {};
76
+ },
77
+ };
78
+ });
91
79
 
92
80
  return tiptapAttributes;
93
81
  }
@@ -101,18 +89,16 @@ export function getBlockFromPos<
101
89
  I extends InlineContentSchema,
102
90
  S extends StyleSchema,
103
91
  >(
104
- getPos: (() => number) | boolean,
92
+ getPos: () => number | undefined,
105
93
  editor: BlockNoteEditor<BSchema, I, S>,
106
94
  tipTapEditor: Editor,
107
95
  type: BType,
108
96
  ) {
97
+ const pos = getPos();
109
98
  // Gets position of the node
110
- if (typeof getPos === "boolean") {
111
- throw new Error(
112
- "Cannot find node position as getPos is a boolean, not a function.",
113
- );
99
+ if (pos === undefined) {
100
+ throw new Error("Cannot find node position");
114
101
  }
115
- const pos = getPos();
116
102
  // Gets parent blockContainer node
117
103
  const blockContainer = tipTapEditor.state.doc.resolve(pos!).node();
118
104
  // Gets block identifier
@@ -145,12 +131,12 @@ export function wrapInBlockStructure<
145
131
  PSchema extends PropSchema,
146
132
  >(
147
133
  element: {
148
- dom: HTMLElement;
134
+ dom: HTMLElement | DocumentFragment;
149
135
  contentDOM?: HTMLElement;
150
136
  destroy?: () => void;
151
137
  },
152
138
  blockType: BType,
153
- blockProps: Props<PSchema>,
139
+ blockProps: Partial<Props<PSchema>>,
154
140
  propSchema: PSchema,
155
141
  isFileBlock = false,
156
142
  domAttributes?: Record<string, string>,
@@ -183,7 +169,7 @@ export function wrapInBlockStructure<
183
169
  for (const [prop, value] of Object.entries(blockProps)) {
184
170
  const spec = propSchema[prop];
185
171
  const defaultValue = spec.default;
186
- if (!inheritedProps.includes(prop) && value !== defaultValue) {
172
+ if (value !== defaultValue) {
187
173
  blockContent.setAttribute(camelToDataKebab(prop), value);
188
174
  }
189
175
  }
@@ -194,7 +180,7 @@ export function wrapInBlockStructure<
194
180
 
195
181
  blockContent.appendChild(element.dom);
196
182
 
197
- if (element.contentDOM !== undefined) {
183
+ if (element.contentDOM) {
198
184
  element.contentDOM.className = mergeCSSClasses(
199
185
  "bn-inline-content",
200
186
  element.contentDOM.className,
@@ -207,76 +193,29 @@ export function wrapInBlockStructure<
207
193
  };
208
194
  }
209
195
 
210
- // Helper type to keep track of the `name` and `content` properties after calling Node.create.
211
- type StronglyTypedTipTapNode<
212
- Name extends string,
213
- Content extends
214
- | "inline*"
215
- | "tableRow+"
216
- | "blockContainer+"
217
- | "column column+"
218
- | "",
219
- > = Node & { name: Name; config: { content: Content } };
220
-
221
- export function createStronglyTypedTiptapNode<
222
- Name extends string,
223
- Content extends
224
- | "inline*"
225
- | "tableRow+"
226
- | "blockContainer+"
227
- | "column column+"
228
- | "",
229
- >(config: NodeConfig & { name: Name; content: Content }) {
230
- return Node.create(config) as StronglyTypedTipTapNode<Name, Content>; // force re-typing (should be safe as it's type-checked from the config)
231
- }
232
-
233
- // This helper function helps to instantiate a blockspec with a
234
- // config and implementation that conform to the type of Config
235
- export function createInternalBlockSpec<T extends BlockConfig>(
196
+ export function createBlockSpecFromTiptapNode<
197
+ const T extends {
198
+ node: Node;
199
+ type: string;
200
+ content: "inline" | "table" | "none";
201
+ },
202
+ P extends PropSchema,
203
+ >(
236
204
  config: T,
237
- implementation: TiptapBlockImplementation<
238
- T,
239
- any,
240
- InlineContentSchema,
241
- StyleSchema
242
- >,
243
- ) {
205
+ propSchema: P,
206
+ extensions?: BlockNoteExtension<any>[],
207
+ ): LooseBlockSpec<T["type"], P, T["content"]> {
244
208
  return {
245
- config,
246
- implementation,
247
- } satisfies BlockSpec<T, any, InlineContentSchema, StyleSchema>;
248
- }
249
-
250
- export function createBlockSpecFromStronglyTypedTiptapNode<
251
- T extends Node,
252
- P extends PropSchema,
253
- >(node: T, propSchema: P, requiredExtensions?: Array<Extension | Node>) {
254
- return createInternalBlockSpec(
255
- {
256
- type: node.name as T["name"],
257
- content: (node.config.content === "inline*"
258
- ? "inline"
259
- : node.config.content === "tableRow+"
260
- ? "table"
261
- : "none") as T["config"]["content"] extends "inline*"
262
- ? "inline"
263
- : T["config"]["content"] extends "tableRow+"
264
- ? "table"
265
- : "none",
209
+ config: {
210
+ type: config.type as T["type"],
211
+ content: config.content,
266
212
  propSchema,
267
213
  },
268
- {
269
- node,
270
- requiredExtensions,
271
- toInternalHTML: defaultBlockToHTML,
214
+ implementation: {
215
+ node: config.node,
216
+ render: defaultBlockToHTML,
272
217
  toExternalHTML: defaultBlockToHTML,
273
- // parse: () => undefined, // parse rules are in node already
274
218
  },
275
- );
276
- }
277
-
278
- export function getBlockSchemaFromSpecs<T extends BlockSpecs>(specs: T) {
279
- return Object.fromEntries(
280
- Object.entries(specs).map(([key, value]) => [key, value.config]),
281
- ) as BlockSchemaFromSpecs<T>;
219
+ extensions,
220
+ };
282
221
  }