@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
@@ -7,33 +7,10 @@ export * from "./api/getBlockInfoFromPos.js";
7
7
  export * from "./api/getBlocksChangedByTransaction.js";
8
8
  export * from "./api/nodeUtil.js";
9
9
  export * from "./api/pmUtil.js";
10
- export * from "./blocks/AudioBlockContent/AudioBlockContent.js";
11
- export * from "./blocks/CodeBlockContent/CodeBlockContent.js";
12
- export * from "./blocks/defaultBlockHelpers.js";
13
- export * from "./blocks/defaultBlocks.js";
14
- export * from "./blocks/defaultBlockTypeGuards.js";
15
- export * from "./blocks/defaultProps.js";
16
- export * from "./blocks/FileBlockContent/FileBlockContent.js";
17
- export * from "./blocks/FileBlockContent/helpers/parse/parseEmbedElement.js";
18
- export * from "./blocks/FileBlockContent/helpers/parse/parseFigureElement.js";
19
- export * from "./blocks/FileBlockContent/helpers/render/createAddFileButton.js";
20
- export * from "./blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js";
21
- export * from "./blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js";
22
- export * from "./blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js";
23
- export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js";
24
- export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
25
- export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js";
26
- export * from "./blocks/ImageBlockContent/ImageBlockContent.js";
27
- export * from "./blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.js";
28
- export * from "./blocks/PageBreakBlockContent/PageBreakBlockContent.js";
29
- export * from "./blocks/PageBreakBlockContent/schema.js";
30
- export * from "./blocks/ToggleWrapper/createToggleWrapper.js";
31
- export { EMPTY_CELL_HEIGHT, EMPTY_CELL_WIDTH, } from "./blocks/TableBlockContent/TableExtension.js";
32
- export * from "./blocks/VideoBlockContent/VideoBlockContent.js";
10
+ export * from "./blocks/index.js";
33
11
  export * from "./editor/BlockNoteEditor.js";
34
12
  export * from "./editor/BlockNoteExtension.js";
35
13
  export * from "./editor/BlockNoteExtensions.js";
36
- export * from "./editor/BlockNoteSchema.js";
37
14
  export * from "./editor/defaultColors.js";
38
15
  export * from "./editor/selectionTypes.js";
39
16
  export * from "./exporter/index.js";
@@ -56,7 +33,7 @@ export * from "./util/combineByGroup.js";
56
33
  export * from "./util/string.js";
57
34
  export * from "./util/table.js";
58
35
  export * from "./util/typescript.js";
59
- export type { CodeBlockOptions } from "./blocks/CodeBlockContent/CodeBlockContent.js";
36
+ export type { CodeBlockOptions } from "./blocks/Code/block.js";
60
37
  export { assertEmpty, UnreachableCaseError } from "./util/typescript.js";
61
38
  export * from "./util/EventEmitter.js";
62
39
  export { selectedFragmentToHTML } from "./api/clipboard/toClipboard/copyExtension.js";
@@ -1,39 +1,19 @@
1
1
  import { Editor } from "@tiptap/core";
2
2
  import { TagParseRule } from "@tiptap/pm/model";
3
- import { NodeView, ViewMutationRecord } from "@tiptap/pm/view";
4
- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
5
- import { InlineContentSchema } from "../inlineContent/types.js";
6
- import { StyleSchema } from "../styles/types.js";
7
- import { BlockConfig, BlockFromConfig, BlockSchemaWithBlock, PartialBlockFromConfig } from "./types.js";
8
- export type CustomBlockConfig = BlockConfig & {
9
- content: "inline" | "none";
10
- };
11
- export type CustomBlockImplementation<T extends CustomBlockConfig, I extends InlineContentSchema, S extends StyleSchema> = {
12
- render: (
13
- /**
14
- * The custom block to render
15
- */
16
- block: BlockFromConfig<T, I, S>,
17
- /**
18
- * The BlockNote editor instance
19
- * This is typed generically. If you want an editor with your custom schema, you need to
20
- * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
21
- */
22
- editor: BlockNoteEditor<BlockSchemaWithBlock<T["type"], T>, I, S>) => {
23
- dom: HTMLElement;
24
- contentDOM?: HTMLElement;
25
- ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
26
- destroy?: () => void;
27
- };
28
- toExternalHTML?: (block: BlockFromConfig<T, I, S>, editor: BlockNoteEditor<BlockSchemaWithBlock<T["type"], T>, I, S>) => {
29
- dom: HTMLElement;
30
- contentDOM?: HTMLElement;
31
- };
32
- parse?: (el: HTMLElement) => PartialBlockFromConfig<T, I, S>["props"] | undefined;
33
- };
3
+ import { NodeView } from "@tiptap/pm/view";
4
+ import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
5
+ import { PropSchema } from "../propTypes.js";
6
+ import { BlockConfig, BlockImplementation, BlockSpec, LooseBlockSpec } from "./types.js";
34
7
  export declare function applyNonSelectableBlockFix(nodeView: NodeView, editor: Editor): void;
35
- export declare function getParseRules(config: BlockConfig, customParseFunction: CustomBlockImplementation<any, any, any>["parse"]): TagParseRule[];
36
- export declare function createBlockSpec<T extends CustomBlockConfig, I extends InlineContentSchema, S extends StyleSchema>(blockConfig: T, blockImplementation: CustomBlockImplementation<NoInfer<T>, I, S>): {
37
- config: T;
38
- implementation: import("./types.js").TiptapBlockImplementation<T, any, InlineContentSchema, StyleSchema>;
39
- };
8
+ export declare function getParseRules<TName extends string, TProps extends PropSchema, TContent extends "inline" | "none" | "table">(config: BlockConfig<TName, TProps, TContent>, implementation: BlockImplementation<TName, TProps, TContent>): TagParseRule[];
9
+ export declare function addNodeAndExtensionsToSpec<TName extends string, TProps extends PropSchema, TContent extends "inline" | "none" | "table">(blockConfig: BlockConfig<TName, TProps, TContent>, blockImplementation: BlockImplementation<TName, TProps, TContent>, extensions?: BlockNoteExtension<any>[], priority?: number): LooseBlockSpec<TName, TProps, TContent>;
10
+ /**
11
+ * Helper function to create a block config.
12
+ */
13
+ export declare function createBlockConfig<TCallback extends (options: Partial<Record<string, any>>) => BlockConfig<any, any, any>, TOptions extends Parameters<TCallback>[0], TName extends ReturnType<TCallback>["type"], TProps extends ReturnType<TCallback>["propSchema"], TContent extends ReturnType<TCallback>["content"]>(callback: TCallback): TOptions extends undefined ? () => BlockConfig<TName, TProps, TContent> : (options: TOptions) => BlockConfig<TName, TProps, TContent>;
14
+ /**
15
+ * Helper function to create a block definition.
16
+ * Can accept either functions that return the required objects, or the objects directly.
17
+ */
18
+ export declare function createBlockSpec<const TName extends string, const TProps extends PropSchema, const TContent extends "inline" | "none", const TOptions extends Partial<Record<string, any>> | undefined = undefined>(blockConfigOrCreator: BlockConfig<TName, TProps, TContent>, blockImplementationOrCreator: BlockImplementation<TName, TProps, TContent> | (TOptions extends undefined ? () => BlockImplementation<TName, TProps, TContent> : (options: Partial<TOptions>) => BlockImplementation<TName, TProps, TContent>), extensionsOrCreator?: BlockNoteExtension<any>[] | (TOptions extends undefined ? () => BlockNoteExtension<any>[] : (options: Partial<TOptions>) => BlockNoteExtension<any>[])): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent>;
19
+ export declare function createBlockSpec<const TName extends string, const TProps extends PropSchema, const TContent extends "inline" | "none", const BlockConf extends BlockConfig<TName, TProps, TContent>, const TOptions extends Partial<Record<string, any>>>(blockCreator: (options: Partial<TOptions>) => BlockConf, blockImplementationOrCreator: BlockImplementation<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]> | (TOptions extends undefined ? () => BlockImplementation<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]> : (options: Partial<TOptions>) => BlockImplementation<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]>), extensionsOrCreator?: BlockNoteExtension<any>[] | (TOptions extends undefined ? () => BlockNoteExtension<any>[] : (options: Partial<TOptions>) => BlockNoteExtension<any>[])): (options?: Partial<TOptions>) => BlockSpec<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]>;
@@ -1,45 +1,23 @@
1
- import { Attributes, Editor, Extension, Node, NodeConfig } from "@tiptap/core";
1
+ import { Attributes, Editor, Node } from "@tiptap/core";
2
2
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3
+ import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
3
4
  import { InlineContentSchema } from "../inlineContent/types.js";
4
5
  import { PropSchema, Props } from "../propTypes.js";
5
6
  import { StyleSchema } from "../styles/types.js";
6
- import { BlockConfig, BlockSchemaFromSpecs, BlockSchemaWithBlock, BlockSpecs, SpecificBlock, TiptapBlockImplementation } from "./types.js";
7
+ import { BlockConfig, BlockSchemaWithBlock, LooseBlockSpec, SpecificBlock } from "./types.js";
7
8
  export declare function propsToAttributes(propSchema: PropSchema): Attributes;
8
- export declare function getBlockFromPos<BType extends string, Config extends BlockConfig, BSchema extends BlockSchemaWithBlock<BType, Config>, I extends InlineContentSchema, S extends StyleSchema>(getPos: (() => number) | boolean, editor: BlockNoteEditor<BSchema, I, S>, tipTapEditor: Editor, type: BType): SpecificBlock<BSchema, BType, I, S>;
9
+ export declare function getBlockFromPos<BType extends string, Config extends BlockConfig, BSchema extends BlockSchemaWithBlock<BType, Config>, I extends InlineContentSchema, S extends StyleSchema>(getPos: () => number | undefined, editor: BlockNoteEditor<BSchema, I, S>, tipTapEditor: Editor, type: BType): SpecificBlock<BSchema, BType, I, S>;
9
10
  export declare function wrapInBlockStructure<BType extends string, PSchema extends PropSchema>(element: {
10
- dom: HTMLElement;
11
+ dom: HTMLElement | DocumentFragment;
11
12
  contentDOM?: HTMLElement;
12
13
  destroy?: () => void;
13
- }, blockType: BType, blockProps: Props<PSchema>, propSchema: PSchema, isFileBlock?: boolean, domAttributes?: Record<string, string>): {
14
+ }, blockType: BType, blockProps: Partial<Props<PSchema>>, propSchema: PSchema, isFileBlock?: boolean, domAttributes?: Record<string, string>): {
14
15
  dom: HTMLElement;
15
16
  contentDOM?: HTMLElement;
16
17
  destroy?: () => void;
17
18
  };
18
- type StronglyTypedTipTapNode<Name extends string, Content extends "inline*" | "tableRow+" | "blockContainer+" | "column column+" | ""> = Node & {
19
- name: Name;
20
- config: {
21
- content: Content;
22
- };
23
- };
24
- export declare function createStronglyTypedTiptapNode<Name extends string, Content extends "inline*" | "tableRow+" | "blockContainer+" | "column column+" | "">(config: NodeConfig & {
25
- name: Name;
26
- content: Content;
27
- }): StronglyTypedTipTapNode<Name, Content>;
28
- export declare function createInternalBlockSpec<T extends BlockConfig>(config: T, implementation: TiptapBlockImplementation<T, any, InlineContentSchema, StyleSchema>): {
29
- config: T;
30
- implementation: TiptapBlockImplementation<T, any, InlineContentSchema, StyleSchema>;
31
- };
32
- export declare function createBlockSpecFromStronglyTypedTiptapNode<T extends Node, P extends PropSchema>(node: T, propSchema: P, requiredExtensions?: Array<Extension | Node>): {
33
- config: {
34
- type: T["name"];
35
- content: T["config"]["content"] extends "inline*" ? "inline" : T["config"]["content"] extends "tableRow+" ? "table" : "none";
36
- propSchema: P;
37
- };
38
- implementation: TiptapBlockImplementation<{
39
- type: T["name"];
40
- content: T["config"]["content"] extends "inline*" ? "inline" : T["config"]["content"] extends "tableRow+" ? "table" : "none";
41
- propSchema: P;
42
- }, any, InlineContentSchema, StyleSchema>;
43
- };
44
- export declare function getBlockSchemaFromSpecs<T extends BlockSpecs>(specs: T): BlockSchemaFromSpecs<T>;
45
- export {};
19
+ export declare function createBlockSpecFromTiptapNode<const T extends {
20
+ node: Node;
21
+ type: string;
22
+ content: "inline" | "table" | "none";
23
+ }, P extends PropSchema>(config: T, propSchema: P, extensions?: BlockNoteExtension<any>[]): LooseBlockSpec<T["type"], P, T["content"]>;
@@ -1,6 +1,9 @@
1
1
  /** Define the main block types **/
2
- import type { Extension, Node } from "@tiptap/core";
2
+ import type { Node, NodeViewRendererProps } from "@tiptap/core";
3
+ import type { Fragment, Schema } from "prosemirror-model";
4
+ import type { ViewMutationRecord } from "prosemirror-view";
3
5
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
6
+ import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
4
7
  import type { InlineContent, InlineContentSchema, PartialInlineContent } from "../inlineContent/types.js";
5
8
  import type { PropSchema, Props } from "../propTypes.js";
6
9
  import type { StyleSchema } from "../styles/types.js";
@@ -8,58 +11,88 @@ export type BlockNoteDOMElement = "editor" | "block" | "blockGroup" | "blockCont
8
11
  export type BlockNoteDOMAttributes = Partial<{
9
12
  [DOMElement in BlockNoteDOMElement]: Record<string, string>;
10
13
  }>;
11
- export type FileBlockConfig = {
12
- type: string;
13
- readonly propSchema: PropSchema & {
14
- caption: {
15
- default: "";
16
- };
17
- name: {
18
- default: "";
19
- };
20
- url?: {
21
- default: "";
22
- };
23
- showPreview?: {
24
- default: boolean;
25
- };
26
- previewWidth?: {
27
- default: undefined;
28
- type: "number";
29
- };
30
- };
31
- content: "none";
32
- isSelectable?: boolean;
33
- isFileBlock: true;
14
+ export interface BlockConfigMeta {
15
+ /**
16
+ * Defines which keyboard shortcut should be used to insert a hard break into the block's inline content.
17
+ * @default "shift+enter"
18
+ */
19
+ hardBreakShortcut?: "shift+enter" | "enter" | "none";
20
+ /**
21
+ * Whether the block is selectable
22
+ */
23
+ selectable?: boolean;
24
+ /**
25
+ * The accept mime types for the file block
26
+ */
34
27
  fileBlockAccept?: string[];
28
+ /**
29
+ * Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.code} block
30
+ */
31
+ code?: boolean;
32
+ /**
33
+ * Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.defining} block
34
+ */
35
+ defining?: boolean;
36
+ /**
37
+ * Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.isolating} block
38
+ */
39
+ isolating?: boolean;
40
+ }
41
+ /**
42
+ * BlockConfig contains the "schema" info about a Block type
43
+ * i.e. what props it supports, what content it supports, etc.
44
+ */
45
+ export interface BlockConfig<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" | "table" = "inline" | "none" | "table"> {
46
+ /**
47
+ * The type of the block (unique identifier within a schema)
48
+ */
49
+ type: T;
50
+ /**
51
+ * The properties that the block supports
52
+ * @todo will be zod schema in the future
53
+ */
54
+ readonly propSchema: PS;
55
+ /**
56
+ * The content that the block supports
57
+ */
58
+ content: C;
59
+ }
60
+ export type CustomBlockConfig<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" = "inline" | "none"> = BlockConfig<T, PS, C>;
61
+ export type BlockSpec<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" | "table" = "inline" | "none" | "table"> = {
62
+ config: BlockConfig<T, PS, C>;
63
+ implementation: BlockImplementation<T, PS, C>;
64
+ extensions?: BlockNoteExtension<any>[];
35
65
  };
36
- export type BlockConfig = {
37
- type: string;
38
- readonly propSchema: PropSchema;
39
- content: "inline" | "none" | "table";
40
- isSelectable?: boolean;
41
- isFileBlock?: false;
42
- hardBreakShortcut?: "shift+enter" | "enter" | "none";
43
- } | FileBlockConfig;
44
- export type TiptapBlockImplementation<T extends BlockConfig, B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> = {
45
- requiredExtensions?: Array<Extension | Node>;
46
- node: Node;
47
- toInternalHTML: (block: BlockFromConfigNoChildren<T, I, S> & {
48
- children: BlockNoDefaults<B, I, S>[];
49
- }, editor: BlockNoteEditor<B, I, S>) => {
50
- dom: HTMLElement;
51
- contentDOM?: HTMLElement;
52
- };
53
- toExternalHTML: (block: BlockFromConfigNoChildren<T, I, S> & {
54
- children: BlockNoDefaults<B, I, S>[];
55
- }, editor: BlockNoteEditor<B, I, S>) => {
56
- dom: HTMLElement;
57
- contentDOM?: HTMLElement;
66
+ /**
67
+ * This allows de-coupling the types that we display to users versus the types we expose internally.
68
+ *
69
+ * This prevents issues with type-inference across parameters that Typescript cannot handle.
70
+ * Specifically, the blocks shape cannot be properly inferred to a specific type like we expose to the user.
71
+ */
72
+ export type LooseBlockSpec<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" | "table" = "inline" | "none" | "table"> = {
73
+ config: BlockConfig<T, PS, C>;
74
+ implementation: Omit<BlockImplementation<T, PS, C>, "render" | "toExternalHTML"> & {
75
+ render: (
76
+ /**
77
+ * The custom block to render
78
+ */
79
+ block: any,
80
+ /**
81
+ * The BlockNote editor instance
82
+ */
83
+ editor: BlockNoteEditor<any>) => {
84
+ dom: HTMLElement | DocumentFragment;
85
+ contentDOM?: HTMLElement;
86
+ ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
87
+ destroy?: () => void;
88
+ };
89
+ toExternalHTML?: (block: any, editor: BlockNoteEditor<any>) => {
90
+ dom: HTMLElement | DocumentFragment;
91
+ contentDOM?: HTMLElement;
92
+ } | undefined;
93
+ node: Node;
58
94
  };
59
- };
60
- export type BlockSpec<T extends BlockConfig, B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> = {
61
- config: T;
62
- implementation: TiptapBlockImplementation<NoInfer<T>, B, I, S>;
95
+ extensions?: BlockNoteExtension<any>[];
63
96
  };
64
97
  type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
65
98
  [Type in keyof Blocks]: Type extends string ? Blocks[Type] extends {
@@ -67,13 +100,45 @@ type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
67
100
  } ? Blocks[Type] : never : never;
68
101
  } ? Blocks : never;
69
102
  export type BlockSchema = NamesMatch<Record<string, BlockConfig>>;
70
- export type BlockSpecs = Record<string, BlockSpec<any, any, InlineContentSchema, StyleSchema>>;
71
- export type BlockImplementations = Record<string, TiptapBlockImplementation<any, any, any, any>>;
72
- export type BlockSchemaFromSpecs<T extends BlockSpecs> = {
73
- [K in keyof T]: T[K]["config"];
103
+ export type BlockSpecs = {
104
+ [k in string]: {
105
+ config: BlockSpec<k>["config"];
106
+ implementation: Omit<BlockSpec<k>["implementation"], "render" | "toExternalHTML"> & {
107
+ render: (
108
+ /**
109
+ * The custom block to render
110
+ */
111
+ block: any,
112
+ /**
113
+ * The BlockNote editor instance
114
+ */
115
+ editor: BlockNoteEditor<any>) => {
116
+ dom: HTMLElement | DocumentFragment;
117
+ contentDOM?: HTMLElement;
118
+ ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
119
+ destroy?: () => void;
120
+ };
121
+ toExternalHTML?: (block: any, editor: BlockNoteEditor<any>) => {
122
+ dom: HTMLElement | DocumentFragment;
123
+ contentDOM?: HTMLElement;
124
+ } | undefined;
125
+ };
126
+ extensions?: BlockNoteExtension<any>[];
127
+ };
128
+ };
129
+ export type BlockImplementations = Record<string, BlockImplementation<any, any>>;
130
+ export type BlockSchemaFromSpecs<BS extends BlockSpecs> = {
131
+ [K in keyof BS]: BS[K]["config"];
74
132
  };
75
- export type BlockSchemaWithBlock<BType extends string, C extends BlockConfig> = {
76
- [k in BType]: C;
133
+ export type BlockSpecsFromSchema<BS extends BlockSchema> = {
134
+ [K in keyof BS]: {
135
+ config: BlockConfig<BS[K]["type"], BS[K]["propSchema"], BS[K]["content"]>;
136
+ implementation: BlockImplementation<BS[K]["type"], BS[K]["propSchema"], BS[K]["content"]>;
137
+ extensions?: BlockNoteExtension<any>[];
138
+ };
139
+ };
140
+ export type BlockSchemaWithBlock<T extends string, C extends BlockConfig> = {
141
+ [k in T]: C;
77
142
  };
78
143
  export type TableCellProps = {
79
144
  backgroundColor: string;
@@ -138,7 +203,7 @@ type PartialBlockFromConfigNoChildren<B extends BlockConfig, I extends InlineCon
138
203
  id?: string;
139
204
  type?: B["type"];
140
205
  props?: Partial<Props<B["propSchema"]>>;
141
- content?: B["content"] extends "inline" ? PartialInlineContent<I, S> : B["content"] extends "table" ? PartialTableContent<I, S> : undefined;
206
+ content?: B["content"] extends "inline" ? PartialInlineContent<I, S> : B["content"] extends "table" ? PartialTableContent<I, S> : B["content"] extends "none" ? undefined : never;
142
207
  };
143
208
  type PartialBlocksWithoutChildren<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> = {
144
209
  [BType in keyof BSchema]: PartialBlockFromConfigNoChildren<BSchema[BType], I, S>;
@@ -155,4 +220,63 @@ export type PartialBlockFromConfig<B extends BlockConfig, I extends InlineConten
155
220
  export type BlockIdentifier = {
156
221
  id: string;
157
222
  } | string;
223
+ export type BlockImplementation<TName extends string = string, TProps extends PropSchema = PropSchema, TContent extends "inline" | "none" | "table" = "inline" | "none" | "table"> = {
224
+ /**
225
+ * Metadata
226
+ */
227
+ meta?: BlockConfigMeta;
228
+ /**
229
+ * A function that converts the block into a DOM element
230
+ */
231
+ render: (this: Record<string, never> | ({
232
+ blockContentDOMAttributes: Record<string, string>;
233
+ } & ({
234
+ renderType: "nodeView";
235
+ props: NodeViewRendererProps;
236
+ } | {
237
+ renderType: "dom";
238
+ props: undefined;
239
+ })),
240
+ /**
241
+ * The custom block to render
242
+ */
243
+ block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>,
244
+ /**
245
+ * The BlockNote editor instance
246
+ */
247
+ editor: BlockNoteEditor<Record<TName, BlockConfig<TName, TProps, TContent>>>) => {
248
+ dom: HTMLElement | DocumentFragment;
249
+ contentDOM?: HTMLElement;
250
+ ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
251
+ destroy?: () => void;
252
+ };
253
+ /**
254
+ * Exports block to external HTML. If not defined, the output will be the same
255
+ * as `render(...).dom`.
256
+ */
257
+ toExternalHTML?: (this: Partial<{
258
+ blockContentDOMAttributes: Record<string, string>;
259
+ }>, block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>, editor: BlockNoteEditor<Record<TName, BlockConfig<TName, TProps, TContent>>>) => {
260
+ dom: HTMLElement | DocumentFragment;
261
+ contentDOM?: HTMLElement;
262
+ } | undefined;
263
+ /**
264
+ * Parses an external HTML element into a block of this type when it returns the block props object, otherwise undefined
265
+ */
266
+ parse?: (el: HTMLElement) => Partial<Props<TProps>> | undefined;
267
+ /**
268
+ * The blocks that this block should run before.
269
+ * This is used to determine the order in which blocks are parsed
270
+ */
271
+ runsBefore?: string[];
272
+ /**
273
+ * Advanced parsing function that controls how content within the block is parsed.
274
+ * This is not recommended to use, and is only useful for advanced use cases.
275
+ */
276
+ parseContent?: (options: {
277
+ el: HTMLElement;
278
+ schema: Schema;
279
+ }) => Fragment;
280
+ };
281
+ export type CustomBlockImplementation<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" = "inline" | "none"> = BlockImplementation<T, PS, C>;
158
282
  export {};
@@ -8,3 +8,4 @@ export * from "./propTypes.js";
8
8
  export * from "./styles/createSpec.js";
9
9
  export * from "./styles/internal.js";
10
10
  export * from "./styles/types.js";
11
+ export * from "./schema.js";
@@ -1,13 +1,28 @@
1
1
  import { TagParseRule } from "@tiptap/pm/model";
2
2
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3
+ import { Props } from "../propTypes.js";
3
4
  import { StyleSchema } from "../styles/types.js";
4
5
  import { CustomInlineContentConfig, InlineContentFromConfig, InlineContentSpec, PartialCustomInlineContentFromConfig } from "./types.js";
5
6
  export type CustomInlineContentImplementation<T extends CustomInlineContentConfig, S extends StyleSchema> = {
7
+ meta?: {
8
+ draggable?: boolean;
9
+ };
10
+ /**
11
+ * Parses an external HTML element into a inline content of this type when it returns the block props object, otherwise undefined
12
+ */
13
+ parse?: (el: HTMLElement) => Partial<Props<T["propSchema"]>> | undefined;
14
+ /**
15
+ * Renders an inline content to DOM elements
16
+ */
6
17
  render: (
7
18
  /**
8
19
  * The custom inline content to render
9
20
  */
10
- inlineContent: InlineContentFromConfig<T, S>, updateInlineContent: (update: PartialCustomInlineContentFromConfig<T, S>) => void,
21
+ inlineContent: InlineContentFromConfig<T, S>,
22
+ /**
23
+ * A callback that allows overriding the inline content element
24
+ */
25
+ updateInlineContent: (update: PartialCustomInlineContentFromConfig<T, S>) => void,
11
26
  /**
12
27
  * The BlockNote editor instance
13
28
  * This is typed generically. If you want an editor with your custom schema, you need to
@@ -16,7 +31,26 @@ export type CustomInlineContentImplementation<T extends CustomInlineContentConfi
16
31
  editor: BlockNoteEditor<any, any, S>) => {
17
32
  dom: HTMLElement;
18
33
  contentDOM?: HTMLElement;
34
+ destroy?: () => void;
19
35
  };
36
+ /**
37
+ * Renders an inline content to external HTML elements for use outside the editor
38
+ * If not provided, falls back to the render method
39
+ */
40
+ toExternalHTML?: (
41
+ /**
42
+ * The custom inline content to render
43
+ */
44
+ inlineContent: InlineContentFromConfig<T, S>,
45
+ /**
46
+ * The BlockNote editor instance
47
+ * This is typed generically. If you want an editor with your custom schema, you need to
48
+ * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
49
+ */
50
+ editor: BlockNoteEditor<any, any, S>) => {
51
+ dom: HTMLElement | DocumentFragment;
52
+ contentDOM?: HTMLElement;
53
+ } | undefined;
20
54
  };
21
- export declare function getInlineContentParseRules(config: CustomInlineContentConfig): TagParseRule[];
55
+ export declare function getInlineContentParseRules<C extends CustomInlineContentConfig>(config: C, customParseFunction?: CustomInlineContentImplementation<C, any>["parse"]): TagParseRule[];
22
56
  export declare function createInlineContentSpec<T extends CustomInlineContentConfig, S extends StyleSchema>(inlineContentConfig: T, inlineContentImplementation: CustomInlineContentImplementation<T, S>): InlineContentSpec<T>;
@@ -1,6 +1,6 @@
1
1
  import { KeyboardShortcutCommand, Node } from "@tiptap/core";
2
2
  import { PropSchema, Props } from "../propTypes.js";
3
- import { CustomInlineContentConfig, InlineContentConfig, InlineContentImplementation, InlineContentSchemaFromSpecs, InlineContentSpecs } from "./types.js";
3
+ import { CustomInlineContentConfig, InlineContentImplementation, InlineContentSchemaFromSpecs, InlineContentSpec, InlineContentSpecs } from "./types.js";
4
4
  export declare function addInlineContentAttributes<IType extends string, PSchema extends PropSchema>(element: {
5
5
  dom: HTMLElement;
6
6
  contentDOM?: HTMLElement;
@@ -11,18 +11,10 @@ export declare function addInlineContentAttributes<IType extends string, PSchema
11
11
  export declare function addInlineContentKeyboardShortcuts<T extends CustomInlineContentConfig>(config: T): {
12
12
  [p: string]: KeyboardShortcutCommand;
13
13
  };
14
- export declare function createInternalInlineContentSpec<T extends InlineContentConfig>(config: T, implementation: InlineContentImplementation<T>): {
15
- config: T;
16
- implementation: InlineContentImplementation<T>;
17
- };
18
- export declare function createInlineContentSpecFromTipTapNode<T extends Node, P extends PropSchema>(node: T, propSchema: P): {
19
- config: {
20
- type: T["name"];
21
- propSchema: P;
22
- content: "none" | "styled";
23
- };
24
- implementation: {
25
- node: Node;
26
- };
27
- };
14
+ export declare function createInternalInlineContentSpec<const T extends CustomInlineContentConfig>(config: T, implementation: InlineContentImplementation<NoInfer<T>>): InlineContentSpec<T>;
15
+ export declare function createInlineContentSpecFromTipTapNode<T extends Node, P extends PropSchema>(node: T, propSchema: P, implementation: Omit<InlineContentImplementation<CustomInlineContentConfig>, "node">): InlineContentSpec<{
16
+ readonly type: T["name"];
17
+ readonly propSchema: P;
18
+ readonly content: "none" | "styled";
19
+ }>;
28
20
  export declare function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(specs: T): InlineContentSchemaFromSpecs<T>;
@@ -1,15 +1,29 @@
1
1
  import { Node } from "@tiptap/core";
2
2
  import { PropSchema, Props } from "../propTypes.js";
3
3
  import { StyleSchema, Styles } from "../styles/types.js";
4
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
5
+ import { ViewMutationRecord } from "prosemirror-view";
4
6
  export type CustomInlineContentConfig = {
5
7
  type: string;
6
8
  content: "styled" | "none";
7
- draggable?: boolean;
8
9
  readonly propSchema: PropSchema;
9
10
  };
10
11
  export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
11
12
  export type InlineContentImplementation<T extends InlineContentConfig> = T extends "link" | "text" ? undefined : {
13
+ meta?: {
14
+ draggable?: boolean;
15
+ };
12
16
  node: Node;
17
+ toExternalHTML?: (inlineContent: any, editor: BlockNoteEditor<any, any, any>) => {
18
+ dom: HTMLElement | DocumentFragment;
19
+ contentDOM?: HTMLElement;
20
+ } | undefined;
21
+ render: (inlineContent: any, updateInlineContent: (update: any) => void, editor: BlockNoteEditor<any, any, any>) => {
22
+ dom: HTMLElement | DocumentFragment;
23
+ contentDOM?: HTMLElement;
24
+ ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
25
+ destroy?: () => void;
26
+ };
13
27
  };
14
28
  export type InlineContentSchemaWithInlineContent<IType extends string, C extends InlineContentConfig> = {
15
29
  [k in IType]: C;
@@ -8,19 +8,19 @@ export type PropSpec<PType extends boolean | number | string> = {
8
8
  };
9
9
  export type PropSchema = Record<string, PropSpec<boolean | number | string>>;
10
10
  export type Props<PSchema extends PropSchema> = {
11
- [PName in keyof PSchema]: (PSchema[PName] extends {
11
+ [PName in keyof PSchema]: (NonNullable<PSchema[PName]> extends {
12
12
  default: boolean;
13
13
  } | {
14
14
  type: "boolean";
15
- } ? PSchema[PName]["values"] extends readonly boolean[] ? PSchema[PName]["values"][number] : boolean : PSchema[PName] extends {
15
+ } ? NonNullable<PSchema[PName]>["values"] extends readonly boolean[] ? NonNullable<PSchema[PName]>["values"][number] : boolean : NonNullable<PSchema[PName]> extends {
16
16
  default: number;
17
17
  } | {
18
18
  type: "number";
19
- } ? PSchema[PName]["values"] extends readonly number[] ? PSchema[PName]["values"][number] : number : PSchema[PName] extends {
19
+ } ? NonNullable<PSchema[PName]>["values"] extends readonly number[] ? NonNullable<PSchema[PName]>["values"][number] : number : NonNullable<PSchema[PName]> extends {
20
20
  default: string;
21
21
  } | {
22
22
  type: "string";
23
- } ? PSchema[PName]["values"] extends readonly string[] ? PSchema[PName]["values"][number] : string : never) extends infer T ? PSchema[PName] extends {
23
+ } ? NonNullable<PSchema[PName]>["values"] extends readonly string[] ? NonNullable<PSchema[PName]>["values"][number] : string : never) extends infer T ? PSchema[PName] extends {
24
24
  optional: true;
25
25
  } ? T | undefined : T : never;
26
26
  };
@@ -0,0 +1,40 @@
1
+ import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
2
+ import { BlockNoDefaults, BlockSchema, BlockSpecs, InlineContentConfig, InlineContentSchema, InlineContentSpec, InlineContentSpecs, LooseBlockSpec, PartialBlockNoDefaults, StyleSchema, StyleSpecs } from "./index.js";
3
+ export declare class CustomBlockNoteSchema<BSchema extends BlockSchema, ISchema extends InlineContentSchema, SSchema extends StyleSchema> {
4
+ private opts;
5
+ readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema>;
6
+ readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema>;
7
+ readonly PartialBlock: PartialBlockNoDefaults<BSchema, ISchema, SSchema>;
8
+ inlineContentSpecs: InlineContentSpecs;
9
+ styleSpecs: StyleSpecs;
10
+ blockSpecs: {
11
+ [K in keyof BSchema]: K extends string ? LooseBlockSpec<K, BSchema[K]["propSchema"], BSchema[K]["content"]> : never;
12
+ };
13
+ blockSchema: BSchema;
14
+ inlineContentSchema: ISchema;
15
+ styleSchema: SSchema;
16
+ constructor(opts: {
17
+ blockSpecs: BlockSpecs;
18
+ inlineContentSpecs: InlineContentSpecs;
19
+ styleSpecs: StyleSpecs;
20
+ });
21
+ private init;
22
+ /**
23
+ * Adds additional block specs to the current schema in a builder pattern.
24
+ * This method allows extending the schema after it has been created.
25
+ *
26
+ * @param additionalBlockSpecs - Additional block specs to add to the schema
27
+ * @returns The current schema instance for chaining
28
+ */
29
+ extend<AdditionalBlockSpecs extends BlockSpecs = Record<string, never>, AdditionalInlineContentSpecs extends Record<string, InlineContentSpec<InlineContentConfig>> = Record<string, never>, AdditionalStyleSpecs extends StyleSpecs = Record<string, never>>(opts: {
30
+ blockSpecs?: AdditionalBlockSpecs;
31
+ inlineContentSpecs?: AdditionalInlineContentSpecs;
32
+ styleSpecs?: AdditionalStyleSpecs;
33
+ }): CustomBlockNoteSchema<AdditionalBlockSpecs extends undefined | Record<string, never> ? BSchema : BSchema & {
34
+ [K in keyof AdditionalBlockSpecs]: K extends string ? AdditionalBlockSpecs[K]["config"] : never;
35
+ }, AdditionalInlineContentSpecs extends undefined | Record<string, never> ? ISchema : ISchema & {
36
+ [K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K]["config"];
37
+ }, AdditionalStyleSpecs extends undefined | Record<string, never> ? SSchema : SSchema & {
38
+ [K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K]["config"];
39
+ }>;
40
+ }