@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,40 +0,0 @@
1
- import { BlockNoteSchema } from "../../editor/BlockNoteSchema.js";
2
- import {
3
- BlockSchema,
4
- InlineContentSchema,
5
- StyleSchema,
6
- } from "../../schema/index.js";
7
- import { PageBreak } from "./PageBreakBlockContent.js";
8
-
9
- export const pageBreakSchema = BlockNoteSchema.create({
10
- blockSpecs: {
11
- pageBreak: PageBreak,
12
- },
13
- });
14
-
15
- /**
16
- * Adds page break support to the given schema.
17
- */
18
- export const withPageBreak = <
19
- B extends BlockSchema,
20
- I extends InlineContentSchema,
21
- S extends StyleSchema,
22
- >(
23
- schema: BlockNoteSchema<B, I, S>,
24
- ) => {
25
- return BlockNoteSchema.create({
26
- blockSpecs: {
27
- ...schema.blockSpecs,
28
- ...pageBreakSchema.blockSpecs,
29
- },
30
- inlineContentSpecs: schema.inlineContentSpecs,
31
- styleSpecs: schema.styleSpecs,
32
- }) as any as BlockNoteSchema<
33
- // typescript needs some help here
34
- B & {
35
- pageBreak: typeof PageBreak.config;
36
- },
37
- I,
38
- S
39
- >;
40
- };
@@ -1,78 +0,0 @@
1
- import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
2
- import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
3
- import {
4
- createBlockSpecFromStronglyTypedTiptapNode,
5
- createStronglyTypedTiptapNode,
6
- } from "../../schema/index.js";
7
- import { createDefaultBlockDOMOutputSpec } from "../defaultBlockHelpers.js";
8
- import { defaultProps } from "../defaultProps.js";
9
-
10
- export const paragraphPropSchema = {
11
- ...defaultProps,
12
- };
13
-
14
- export const ParagraphBlockContent = createStronglyTypedTiptapNode({
15
- name: "paragraph",
16
- content: "inline*",
17
- group: "blockContent",
18
-
19
- addKeyboardShortcuts() {
20
- return {
21
- "Mod-Alt-0": () => {
22
- const blockInfo = getBlockInfoFromSelection(this.editor.state);
23
- if (
24
- !blockInfo.isBlockContainer ||
25
- blockInfo.blockContent.node.type.spec.content !== "inline*"
26
- ) {
27
- return true;
28
- }
29
-
30
- return this.editor.commands.command(
31
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
32
- type: "paragraph",
33
- props: {},
34
- }),
35
- );
36
- },
37
- };
38
- },
39
-
40
- parseHTML() {
41
- return [
42
- // Parse from internal HTML.
43
- {
44
- tag: "div[data-content-type=" + this.name + "]",
45
- contentElement: ".bn-inline-content",
46
- },
47
- // Parse from external HTML.
48
- {
49
- tag: "p",
50
- getAttrs: (element) => {
51
- if (typeof element === "string" || !element.textContent?.trim()) {
52
- return false;
53
- }
54
-
55
- return {};
56
- },
57
- node: "paragraph",
58
- },
59
- ];
60
- },
61
-
62
- renderHTML({ HTMLAttributes }) {
63
- return createDefaultBlockDOMOutputSpec(
64
- this.name,
65
- "p",
66
- {
67
- ...(this.options.domAttributes?.blockContent || {}),
68
- ...HTMLAttributes,
69
- },
70
- this.options.domAttributes?.inlineContent || {},
71
- );
72
- },
73
- });
74
-
75
- export const Paragraph = createBlockSpecFromStronglyTypedTiptapNode(
76
- ParagraphBlockContent,
77
- paragraphPropSchema,
78
- );
@@ -1,121 +0,0 @@
1
- import {
2
- createBlockSpecFromStronglyTypedTiptapNode,
3
- createStronglyTypedTiptapNode,
4
- } from "../../schema/index.js";
5
- import {
6
- createDefaultBlockDOMOutputSpec,
7
- mergeParagraphs,
8
- } from "../defaultBlockHelpers.js";
9
- import { defaultProps } from "../defaultProps.js";
10
- import { getBlockInfoFromSelection } from "../../api/getBlockInfoFromPos.js";
11
- import { updateBlockCommand } from "../../api/blockManipulation/commands/updateBlock/updateBlock.js";
12
- import { InputRule } from "@tiptap/core";
13
- import { DOMParser } from "prosemirror-model";
14
-
15
- export const quotePropSchema = {
16
- ...defaultProps,
17
- };
18
-
19
- export const QuoteBlockContent = createStronglyTypedTiptapNode({
20
- name: "quote",
21
- content: "inline*",
22
- group: "blockContent",
23
-
24
- addInputRules() {
25
- return [
26
- // Creates a block quote when starting with ">".
27
- new InputRule({
28
- find: new RegExp(`^>\\s$`),
29
- handler: ({ state, chain, range }) => {
30
- const blockInfo = getBlockInfoFromSelection(state);
31
- if (
32
- !blockInfo.isBlockContainer ||
33
- blockInfo.blockContent.node.type.spec.content !== "inline*"
34
- ) {
35
- return;
36
- }
37
-
38
- chain()
39
- .command(
40
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
41
- type: "quote",
42
- props: {},
43
- }),
44
- )
45
- // Removes the ">" character used to set the list.
46
- .deleteRange({ from: range.from, to: range.to });
47
- },
48
- }),
49
- ];
50
- },
51
-
52
- addKeyboardShortcuts() {
53
- return {
54
- "Mod-Alt-q": () => {
55
- const blockInfo = getBlockInfoFromSelection(this.editor.state);
56
- if (
57
- !blockInfo.isBlockContainer ||
58
- blockInfo.blockContent.node.type.spec.content !== "inline*"
59
- ) {
60
- return true;
61
- }
62
-
63
- return this.editor.commands.command(
64
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
65
- type: "quote",
66
- }),
67
- );
68
- },
69
- };
70
- },
71
-
72
- parseHTML() {
73
- return [
74
- // Parse from internal HTML.
75
- {
76
- tag: "div[data-content-type=" + this.name + "]",
77
- contentElement: ".bn-inline-content",
78
- },
79
- // Parse from external HTML.
80
- {
81
- tag: "blockquote",
82
- node: "quote",
83
- getContent: (node, schema) => {
84
- // Parse the blockquote content as inline content
85
- const element = node as HTMLElement;
86
-
87
- // Clone to avoid modifying the original
88
- const clone = element.cloneNode(true) as HTMLElement;
89
-
90
- // Merge multiple paragraphs into one with line breaks
91
- mergeParagraphs(clone);
92
-
93
- // Parse the content directly as a paragraph to extract inline content
94
- const parser = DOMParser.fromSchema(schema);
95
- const parsed = parser.parse(clone, {
96
- topNode: schema.nodes.paragraph.create(),
97
- });
98
-
99
- return parsed.content;
100
- },
101
- },
102
- ];
103
- },
104
-
105
- renderHTML({ HTMLAttributes }) {
106
- return createDefaultBlockDOMOutputSpec(
107
- this.name,
108
- "blockquote",
109
- {
110
- ...(this.options.domAttributes?.blockContent || {}),
111
- ...HTMLAttributes,
112
- },
113
- this.options.domAttributes?.inlineContent || {},
114
- );
115
- },
116
- });
117
-
118
- export const Quote = createBlockSpecFromStronglyTypedTiptapNode(
119
- QuoteBlockContent,
120
- quotePropSchema,
121
- );
@@ -1,158 +0,0 @@
1
- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
2
- import {
3
- BlockFromConfig,
4
- createBlockSpec,
5
- FileBlockConfig,
6
- Props,
7
- PropSchema,
8
- } from "../../schema/index.js";
9
- import { defaultProps } from "../defaultProps.js";
10
- import { parseFigureElement } from "../FileBlockContent/helpers/parse/parseFigureElement.js";
11
- import { createFigureWithCaption } from "../FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js";
12
- import { createLinkWithCaption } from "../FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
13
- import { createResizableFileBlockWrapper } from "../FileBlockContent/helpers/render/createResizableFileBlockWrapper.js";
14
- import { parseVideoElement } from "./parseVideoElement.js";
15
-
16
- export const FILE_VIDEO_ICON_SVG =
17
- '<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>';
18
-
19
- export const videoPropSchema = {
20
- textAlignment: defaultProps.textAlignment,
21
- backgroundColor: defaultProps.backgroundColor,
22
- // File name.
23
- name: {
24
- default: "" as const,
25
- },
26
- // File url.
27
- url: {
28
- default: "" as const,
29
- },
30
- // File caption.
31
- caption: {
32
- default: "" as const,
33
- },
34
-
35
- showPreview: {
36
- default: true,
37
- },
38
- // File preview width in px.
39
- previewWidth: {
40
- default: undefined,
41
- type: "number",
42
- },
43
- } satisfies PropSchema;
44
-
45
- export const videoBlockConfig = {
46
- type: "video" as const,
47
- propSchema: videoPropSchema,
48
- content: "none",
49
- isFileBlock: true,
50
- fileBlockAccept: ["video/*"],
51
- } satisfies FileBlockConfig;
52
-
53
- export const videoRender = (
54
- block: BlockFromConfig<typeof videoBlockConfig, any, any>,
55
- editor: BlockNoteEditor<any, any, any>,
56
- ) => {
57
- const icon = document.createElement("div");
58
- icon.innerHTML = FILE_VIDEO_ICON_SVG;
59
-
60
- const videoWrapper = document.createElement("div");
61
- videoWrapper.className = "bn-visual-media-wrapper";
62
-
63
- const video = document.createElement("video");
64
- video.className = "bn-visual-media";
65
- if (editor.resolveFileUrl) {
66
- editor.resolveFileUrl(block.props.url).then((downloadUrl) => {
67
- video.src = downloadUrl;
68
- });
69
- } else {
70
- video.src = block.props.url;
71
- }
72
- video.controls = true;
73
- video.contentEditable = "false";
74
- video.draggable = false;
75
- video.width = block.props.previewWidth;
76
- videoWrapper.appendChild(video);
77
-
78
- return createResizableFileBlockWrapper(
79
- block,
80
- editor,
81
- { dom: videoWrapper },
82
- videoWrapper,
83
- icon.firstElementChild as HTMLElement,
84
- );
85
- };
86
-
87
- export const videoParse = (
88
- element: HTMLElement,
89
- ): Partial<Props<typeof videoBlockConfig.propSchema>> | undefined => {
90
- if (element.tagName === "VIDEO") {
91
- // Ignore if parent figure has already been parsed.
92
- if (element.closest("figure")) {
93
- return undefined;
94
- }
95
-
96
- return parseVideoElement(element as HTMLVideoElement);
97
- }
98
-
99
- if (element.tagName === "FIGURE") {
100
- const parsedFigure = parseFigureElement(element, "video");
101
- if (!parsedFigure) {
102
- return undefined;
103
- }
104
-
105
- const { targetElement, caption } = parsedFigure;
106
-
107
- return {
108
- ...parseVideoElement(targetElement as HTMLVideoElement),
109
- caption,
110
- };
111
- }
112
-
113
- return undefined;
114
- };
115
-
116
- export const videoToExternalHTML = (
117
- block: BlockFromConfig<typeof videoBlockConfig, any, any>,
118
- ) => {
119
- if (!block.props.url) {
120
- const div = document.createElement("p");
121
- div.textContent = "Add video";
122
-
123
- return {
124
- dom: div,
125
- };
126
- }
127
-
128
- let video;
129
- if (block.props.showPreview) {
130
- video = document.createElement("video");
131
- video.src = block.props.url;
132
- if (block.props.previewWidth) {
133
- video.width = block.props.previewWidth;
134
- }
135
- } else {
136
- video = document.createElement("a");
137
- video.href = block.props.url;
138
- video.textContent = block.props.name || block.props.url;
139
- }
140
-
141
- if (block.props.caption) {
142
- if (block.props.showPreview) {
143
- return createFigureWithCaption(video, block.props.caption);
144
- } else {
145
- return createLinkWithCaption(video, block.props.caption);
146
- }
147
- }
148
-
149
- return {
150
- dom: video,
151
- };
152
- };
153
-
154
- export const VideoBlock = createBlockSpec(videoBlockConfig, {
155
- render: videoRender,
156
- parse: videoParse,
157
- toExternalHTML: videoToExternalHTML,
158
- });
@@ -1,107 +0,0 @@
1
- import {
2
- defaultBlockSpecs,
3
- defaultInlineContentSpecs,
4
- defaultStyleSpecs,
5
- } from "../blocks/defaultBlocks.js";
6
- import type {
7
- BlockNoDefaults,
8
- PartialBlockNoDefaults,
9
- } from "../schema/blocks/types.js";
10
- import {
11
- BlockSchema,
12
- BlockSchemaFromSpecs,
13
- BlockSpecs,
14
- InlineContentSchema,
15
- InlineContentSchemaFromSpecs,
16
- InlineContentSpecs,
17
- StyleSchema,
18
- StyleSchemaFromSpecs,
19
- StyleSpecs,
20
- getBlockSchemaFromSpecs,
21
- getInlineContentSchemaFromSpecs,
22
- getStyleSchemaFromSpecs,
23
- } from "../schema/index.js";
24
- import type { BlockNoteEditor } from "./BlockNoteEditor.js";
25
-
26
- function removeUndefined<T extends Record<string, any> | undefined>(obj: T): T {
27
- if (!obj) {
28
- return obj;
29
- }
30
- return Object.fromEntries(
31
- Object.entries(obj).filter(([, value]) => value !== undefined),
32
- ) as T;
33
- }
34
-
35
- export class BlockNoteSchema<
36
- BSchema extends BlockSchema,
37
- ISchema extends InlineContentSchema,
38
- SSchema extends StyleSchema,
39
- > {
40
- public readonly blockSpecs: BlockSpecs;
41
- public readonly inlineContentSpecs: InlineContentSpecs;
42
- public readonly styleSpecs: StyleSpecs;
43
-
44
- public readonly blockSchema: BSchema;
45
- public readonly inlineContentSchema: ISchema;
46
- public readonly styleSchema: SSchema;
47
-
48
- // Helper so that you can use typeof schema.BlockNoteEditor
49
- public readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema> =
50
- "only for types" as any;
51
-
52
- public readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema> =
53
- "only for types" as any;
54
-
55
- public readonly PartialBlock: PartialBlockNoDefaults<
56
- BSchema,
57
- ISchema,
58
- SSchema
59
- > = "only for types" as any;
60
-
61
- public static create<
62
- BSpecs extends BlockSpecs = typeof defaultBlockSpecs,
63
- ISpecs extends InlineContentSpecs = typeof defaultInlineContentSpecs,
64
- SSpecs extends StyleSpecs = typeof defaultStyleSpecs,
65
- >(options?: {
66
- /**
67
- * A list of custom block types that should be available in the editor.
68
- */
69
- blockSpecs?: BSpecs;
70
- /**
71
- * A list of custom InlineContent types that should be available in the editor.
72
- */
73
- inlineContentSpecs?: ISpecs;
74
- /**
75
- * A list of custom Styles that should be available in the editor.
76
- */
77
- styleSpecs?: SSpecs;
78
- }) {
79
- return new BlockNoteSchema<
80
- BlockSchemaFromSpecs<BSpecs>,
81
- InlineContentSchemaFromSpecs<ISpecs>,
82
- StyleSchemaFromSpecs<SSpecs>
83
- >(options);
84
- // as BlockNoteSchema<
85
- // BlockSchemaFromSpecs<BSpecs>,
86
- // InlineContentSchemaFromSpecs<ISpecs>,
87
- // StyleSchemaFromSpecs<SSpecs>
88
- // >;
89
- }
90
-
91
- constructor(opts?: {
92
- blockSpecs?: BlockSpecs;
93
- inlineContentSpecs?: InlineContentSpecs;
94
- styleSpecs?: StyleSpecs;
95
- }) {
96
- this.blockSpecs = removeUndefined(opts?.blockSpecs) || defaultBlockSpecs;
97
- this.inlineContentSpecs =
98
- removeUndefined(opts?.inlineContentSpecs) || defaultInlineContentSpecs;
99
- this.styleSpecs = removeUndefined(opts?.styleSpecs) || defaultStyleSpecs;
100
-
101
- this.blockSchema = getBlockSchemaFromSpecs(this.blockSpecs) as any;
102
- this.inlineContentSchema = getInlineContentSchemaFromSpecs(
103
- this.inlineContentSpecs,
104
- ) as any;
105
- this.styleSchema = getStyleSchemaFromSpecs(this.styleSpecs) as any;
106
- }
107
- }