@blocknote/core 0.37.0 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) 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 +3311 -7230
  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/{en-CvDoFvhc.js → en-Bq3Es3Np.js} +6 -12
  14. package/dist/en-Bq3Es3Np.js.map +1 -0
  15. package/dist/en-D3B48eJ7.cjs +2 -0
  16. package/dist/en-D3B48eJ7.cjs.map +1 -0
  17. package/dist/locales.cjs +1 -1
  18. package/dist/locales.cjs.map +1 -1
  19. package/dist/locales.js +109 -229
  20. package/dist/locales.js.map +1 -1
  21. package/dist/style.css +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -0
  23. package/dist/webpack-stats.json +1 -1
  24. package/package.json +25 -22
  25. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
  26. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
  27. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
  28. package/src/api/blockManipulation/setupTestEnv.ts +0 -1
  29. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +4 -8
  30. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -3
  31. package/src/api/exporters/html/externalHTMLExporter.ts +0 -1
  32. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
  33. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
  34. package/src/api/exporters/markdown/markdownExporter.ts +13 -22
  35. package/src/api/exporters/markdown/util/addSpacesToCheckboxesRehypePlugin.ts +2 -12
  36. package/src/api/parsers/html/parseHTML.ts +3 -2
  37. package/src/api/parsers/html/util/nestedLists.test.ts +8 -8
  38. package/src/api/parsers/markdown/parseMarkdown.ts +17 -14
  39. package/src/api/pmUtil.ts +1 -1
  40. package/src/api/positionMapping.test.ts +197 -33
  41. package/src/api/positionMapping.ts +4 -6
  42. package/src/blocks/Audio/block.ts +174 -0
  43. package/src/blocks/BlockNoteSchema.ts +59 -0
  44. package/src/blocks/Code/block.ts +303 -0
  45. package/src/blocks/Code/shiki.ts +73 -0
  46. package/src/blocks/File/block.ts +98 -0
  47. package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +8 -4
  48. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +16 -13
  49. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
  50. package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +63 -19
  51. package/src/blocks/Heading/block.ts +138 -0
  52. package/src/blocks/Image/block.ts +190 -0
  53. package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
  54. package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
  55. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
  56. package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
  57. package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
  58. package/src/blocks/PageBreak/block.ts +72 -0
  59. package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
  60. package/src/blocks/Paragraph/block.ts +80 -0
  61. package/src/blocks/Quote/block.ts +90 -0
  62. package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
  63. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
  64. package/src/blocks/Video/block.ts +143 -0
  65. package/src/blocks/defaultBlockHelpers.ts +2 -2
  66. package/src/blocks/defaultBlockTypeGuards.ts +143 -174
  67. package/src/blocks/defaultBlocks.ts +107 -35
  68. package/src/blocks/defaultProps.ts +145 -4
  69. package/src/blocks/index.ts +26 -0
  70. package/src/blocks/utils/listItemEnterHandler.ts +42 -0
  71. package/src/editor/Block.css +54 -18
  72. package/src/editor/BlockNoteEditor.ts +265 -230
  73. package/src/editor/BlockNoteExtension.ts +92 -0
  74. package/src/editor/BlockNoteExtensions.ts +20 -16
  75. package/src/editor/defaultColors.ts +2 -2
  76. package/src/exporter/Exporter.ts +1 -1
  77. package/src/exporter/mapping.ts +1 -1
  78. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
  79. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
  80. package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
  81. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
  82. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
  83. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  84. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  85. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
  86. package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
  87. package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
  88. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
  89. package/src/extensions/Comments/CommentsPlugin.ts +2 -0
  90. package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
  91. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
  92. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
  93. package/src/extensions/Placeholder/PlaceholderPlugin.ts +2 -2
  94. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
  95. package/src/extensions/SideMenu/SideMenuPlugin.ts +0 -2
  96. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +0 -5
  97. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
  98. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
  99. package/src/extensions/TableHandles/TableHandlesPlugin.ts +2 -2
  100. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
  101. package/src/extensions/TextColor/TextColorExtension.ts +3 -17
  102. package/src/extensions/TextColor/TextColorMark.ts +4 -9
  103. package/src/extensions/UniqueID/UniqueID.ts +6 -13
  104. package/src/i18n/locales/ar.ts +6 -12
  105. package/src/i18n/locales/de.ts +6 -12
  106. package/src/i18n/locales/en.ts +6 -12
  107. package/src/i18n/locales/es.ts +6 -12
  108. package/src/i18n/locales/fr.ts +6 -12
  109. package/src/i18n/locales/he.ts +6 -12
  110. package/src/i18n/locales/hr.ts +6 -12
  111. package/src/i18n/locales/is.ts +6 -12
  112. package/src/i18n/locales/it.ts +6 -12
  113. package/src/i18n/locales/ja.ts +6 -12
  114. package/src/i18n/locales/ko.ts +6 -12
  115. package/src/i18n/locales/nl.ts +6 -12
  116. package/src/i18n/locales/no.ts +6 -12
  117. package/src/i18n/locales/pl.ts +6 -12
  118. package/src/i18n/locales/pt.ts +6 -12
  119. package/src/i18n/locales/ru.ts +6 -12
  120. package/src/i18n/locales/sk.ts +6 -12
  121. package/src/i18n/locales/uk.ts +6 -12
  122. package/src/i18n/locales/vi.ts +6 -12
  123. package/src/i18n/locales/zh-tw.ts +6 -12
  124. package/src/i18n/locales/zh.ts +6 -12
  125. package/src/index.ts +2 -29
  126. package/src/schema/blocks/createSpec.ts +342 -169
  127. package/src/schema/blocks/internal.ts +77 -138
  128. package/src/schema/blocks/types.ts +264 -94
  129. package/src/schema/index.ts +1 -0
  130. package/src/schema/inlineContent/createSpec.ts +99 -21
  131. package/src/schema/inlineContent/internal.ts +16 -7
  132. package/src/schema/inlineContent/types.ts +24 -2
  133. package/src/schema/propTypes.ts +15 -9
  134. package/src/schema/schema.ts +209 -0
  135. package/src/schema/styles/createSpec.ts +79 -31
  136. package/src/schema/styles/internal.ts +61 -2
  137. package/src/schema/styles/types.ts +17 -3
  138. package/src/util/topo-sort.test.ts +125 -0
  139. package/src/util/topo-sort.ts +160 -0
  140. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
  141. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  142. package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
  143. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
  144. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
  145. package/types/src/api/exporters/markdown/markdownExporter.d.ts +1 -1
  146. package/types/src/api/parsers/html/parseHTML.d.ts +1 -1
  147. package/types/src/api/parsers/markdown/parseMarkdown.d.ts +2 -2
  148. package/types/src/api/pmUtil.d.ts +1 -1
  149. package/types/src/blocks/Audio/block.d.ts +58 -0
  150. package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
  151. package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
  152. package/types/src/blocks/Code/shiki.d.ts +4 -0
  153. package/types/src/blocks/File/block.d.ts +37 -0
  154. package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
  155. package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
  156. package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
  157. package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
  158. package/types/src/blocks/Heading/block.d.ts +71 -0
  159. package/types/src/blocks/Image/block.d.ts +102 -0
  160. package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
  161. package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
  162. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
  163. package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
  164. package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
  165. package/types/src/blocks/PageBreak/block.d.ts +11 -0
  166. package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
  167. package/types/src/blocks/Paragraph/block.d.ts +25 -0
  168. package/types/src/blocks/Quote/block.d.ts +17 -0
  169. package/types/src/blocks/Table/block.d.ts +21 -0
  170. package/types/src/blocks/Video/block.d.ts +67 -0
  171. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
  172. package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
  173. package/types/src/blocks/defaultBlocks.d.ts +221 -1060
  174. package/types/src/blocks/defaultProps.d.ts +17 -1
  175. package/types/src/blocks/index.d.ts +24 -0
  176. package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
  177. package/types/src/editor/BlockNoteEditor.d.ts +39 -75
  178. package/types/src/editor/BlockNoteExtension.d.ts +67 -0
  179. package/types/src/editor/BlockNoteExtensions.d.ts +2 -0
  180. package/types/src/editor/defaultColors.d.ts +8 -76
  181. package/types/src/exporter/Exporter.d.ts +1 -1
  182. package/types/src/exporter/mapping.d.ts +1 -1
  183. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
  184. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
  185. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
  186. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
  187. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
  188. package/types/src/extensions/Comments/CommentsPlugin.d.ts +3 -1
  189. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  190. package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
  191. package/types/src/i18n/locales/en.d.ts +1 -12
  192. package/types/src/i18n/locales/sk.d.ts +1 -12
  193. package/types/src/index.d.ts +2 -26
  194. package/types/src/schema/blocks/createSpec.d.ts +16 -36
  195. package/types/src/schema/blocks/internal.d.ts +11 -33
  196. package/types/src/schema/blocks/types.d.ts +181 -57
  197. package/types/src/schema/index.d.ts +1 -0
  198. package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
  199. package/types/src/schema/inlineContent/internal.d.ts +7 -15
  200. package/types/src/schema/inlineContent/types.d.ts +15 -1
  201. package/types/src/schema/propTypes.d.ts +4 -4
  202. package/types/src/schema/schema.d.ts +40 -0
  203. package/types/src/schema/styles/createSpec.d.ts +6 -4
  204. package/types/src/schema/styles/internal.d.ts +6 -3
  205. package/types/src/schema/styles/types.d.ts +11 -2
  206. package/types/src/util/topo-sort.d.ts +18 -0
  207. package/types/src/util/topo-sort.test.d.ts +1 -0
  208. package/dist/en-CvDoFvhc.js.map +0 -1
  209. package/dist/en-ub2yVBX0.cjs +0 -2
  210. package/dist/en-ub2yVBX0.cjs.map +0 -1
  211. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -145
  212. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
  213. package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
  214. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
  215. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -160
  216. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
  217. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
  218. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
  219. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
  220. package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
  221. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
  222. package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
  223. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
  224. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
  225. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -159
  226. package/src/editor/BlockNoteSchema.ts +0 -107
  227. package/src/editor/BlockNoteTipTapEditor.ts +0 -335
  228. package/src/util/esmDependencies.ts +0 -51
  229. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
  230. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
  231. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
  232. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
  233. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
  234. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
  235. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
  236. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
  237. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
  238. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
  239. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
  240. package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
  241. package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
  242. package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
  243. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
  244. package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
  245. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
  246. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
  247. package/types/src/editor/BlockNoteSchema.d.ts +0 -34
  248. package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
  249. package/types/src/util/esmDependencies.d.ts +0 -24
  250. /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
  251. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
  252. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
  253. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
  254. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
  255. /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  256. /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
  257. /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
  258. /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
  259. /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
  260. /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
  261. /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
  262. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
  263. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
  264. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
  265. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
  266. /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
  267. /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
  268. /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
  269. /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
  270. /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
  271. /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
@@ -1,172 +0,0 @@
1
- import { InputRule } from "@tiptap/core";
2
- import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
3
- import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
4
- import {
5
- PropSchema,
6
- createBlockSpecFromStronglyTypedTiptapNode,
7
- createStronglyTypedTiptapNode,
8
- propsToAttributes,
9
- } from "../../../schema/index.js";
10
- import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers.js";
11
- import { defaultProps } from "../../defaultProps.js";
12
- import { getListItemContent } from "../getListItemContent.js";
13
- import { handleEnter } from "../ListItemKeyboardShortcuts.js";
14
- import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin.js";
15
-
16
- export const numberedListItemPropSchema = {
17
- ...defaultProps,
18
- start: { default: undefined, type: "number" },
19
- } satisfies PropSchema;
20
-
21
- const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
22
- name: "numberedListItem",
23
- content: "inline*",
24
- group: "blockContent",
25
- priority: 90,
26
- addAttributes() {
27
- return {
28
- ...propsToAttributes(numberedListItemPropSchema),
29
- // the index attribute is only used internally (it's not part of the blocknote schema)
30
- // that's why it's defined explicitly here, and not part of the prop schema
31
- index: {
32
- default: null,
33
- parseHTML: (element) => element.getAttribute("data-index"),
34
- renderHTML: (attributes) => {
35
- return {
36
- "data-index": attributes.index,
37
- };
38
- },
39
- },
40
- };
41
- },
42
-
43
- addInputRules() {
44
- return [
45
- // Creates an ordered list when starting with "1.".
46
- new InputRule({
47
- find: new RegExp(`^(\\d+)\\.\\s$`),
48
- handler: ({ state, chain, range, match }) => {
49
- const blockInfo = getBlockInfoFromSelection(state);
50
- if (
51
- !blockInfo.isBlockContainer ||
52
- blockInfo.blockContent.node.type.spec.content !== "inline*" ||
53
- blockInfo.blockNoteType === "numberedListItem" ||
54
- blockInfo.blockNoteType === "heading"
55
- ) {
56
- return;
57
- }
58
- const startIndex = parseInt(match[1]);
59
-
60
- chain()
61
- .command(
62
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
63
- type: "numberedListItem",
64
- props:
65
- (startIndex === 1 && {}) ||
66
- ({
67
- start: startIndex,
68
- } as any),
69
- }),
70
- )
71
- // Removes the "1." characters used to set the list.
72
- .deleteRange({ from: range.from, to: range.to });
73
- },
74
- }),
75
- ];
76
- },
77
-
78
- addKeyboardShortcuts() {
79
- return {
80
- Enter: () => handleEnter(this.options.editor),
81
- "Mod-Shift-7": () => {
82
- const blockInfo = getBlockInfoFromSelection(this.editor.state);
83
- if (
84
- !blockInfo.isBlockContainer ||
85
- blockInfo.blockContent.node.type.spec.content !== "inline*"
86
- ) {
87
- return true;
88
- }
89
-
90
- return this.editor.commands.command(
91
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
92
- type: "numberedListItem",
93
- props: {},
94
- }),
95
- );
96
- },
97
- };
98
- },
99
-
100
- addProseMirrorPlugins() {
101
- return [NumberedListIndexingPlugin()];
102
- },
103
-
104
- parseHTML() {
105
- return [
106
- // Parse from internal HTML.
107
- {
108
- tag: "div[data-content-type=" + this.name + "]",
109
- contentElement: ".bn-inline-content",
110
- },
111
- // Parse from external HTML.
112
- {
113
- tag: "li",
114
- getAttrs: (element) => {
115
- if (typeof element === "string") {
116
- return false;
117
- }
118
-
119
- const parent = element.parentElement;
120
-
121
- if (parent === null) {
122
- return false;
123
- }
124
-
125
- if (
126
- parent.tagName === "OL" ||
127
- (parent.tagName === "DIV" && parent.parentElement?.tagName === "OL")
128
- ) {
129
- const startIndex =
130
- parseInt(parent.getAttribute("start") || "1") || 1;
131
-
132
- if (element.previousSibling || startIndex === 1) {
133
- return {};
134
- }
135
-
136
- return {
137
- start: startIndex,
138
- };
139
- }
140
-
141
- return false;
142
- },
143
- // As `li` elements can contain multiple paragraphs, we need to merge their contents
144
- // into a single one so that ProseMirror can parse everything correctly.
145
- getContent: (node, schema) =>
146
- getListItemContent(node, schema, this.name),
147
- priority: 300,
148
- node: "numberedListItem",
149
- },
150
- ];
151
- },
152
-
153
- renderHTML({ HTMLAttributes }) {
154
- return createDefaultBlockDOMOutputSpec(
155
- this.name,
156
- // We use a <p> tag, because for <li> tags we'd need an <ol> element to
157
- // put them in to be semantically correct, which we can't have due to the
158
- // schema.
159
- "p",
160
- {
161
- ...(this.options.domAttributes?.blockContent || {}),
162
- ...HTMLAttributes,
163
- },
164
- this.options.domAttributes?.inlineContent || {},
165
- );
166
- },
167
- });
168
-
169
- export const NumberedListItem = createBlockSpecFromStronglyTypedTiptapNode(
170
- NumberedListItemBlockContent,
171
- numberedListItemPropSchema,
172
- );
@@ -1,104 +0,0 @@
1
- import { updateBlockCommand } from "../../../api/blockManipulation/commands/updateBlock/updateBlock.js";
2
- import { getBlockInfoFromSelection } from "../../../api/getBlockInfoFromPos.js";
3
- import {
4
- PropSchema,
5
- createBlockSpecFromStronglyTypedTiptapNode,
6
- createStronglyTypedTiptapNode,
7
- getBlockFromPos,
8
- } from "../../../schema/index.js";
9
- import { createDefaultBlockDOMOutputSpec } from "../../defaultBlockHelpers.js";
10
- import { defaultProps } from "../../defaultProps.js";
11
- import { createToggleWrapper } from "../../ToggleWrapper/createToggleWrapper.js";
12
- import { handleEnter } from "../ListItemKeyboardShortcuts.js";
13
-
14
- export const toggleListItemPropSchema = {
15
- ...defaultProps,
16
- } satisfies PropSchema;
17
-
18
- const ToggleListItemBlockContent = createStronglyTypedTiptapNode({
19
- name: "toggleListItem",
20
- content: "inline*",
21
- group: "blockContent",
22
- // This is to make sure that the list item Enter keyboard handler takes
23
- // priority over the default one.
24
- priority: 90,
25
- addKeyboardShortcuts() {
26
- return {
27
- Enter: () => handleEnter(this.options.editor),
28
- "Mod-Shift-6": () => {
29
- const blockInfo = getBlockInfoFromSelection(this.editor.state);
30
- if (
31
- !blockInfo.isBlockContainer ||
32
- blockInfo.blockContent.node.type.spec.content !== "inline*"
33
- ) {
34
- return true;
35
- }
36
-
37
- return this.editor.commands.command(
38
- updateBlockCommand(blockInfo.bnBlock.beforePos, {
39
- type: "toggleListItem",
40
- props: {},
41
- }),
42
- );
43
- },
44
- };
45
- },
46
-
47
- parseHTML() {
48
- return [
49
- // Parse from internal HTML.
50
- {
51
- tag: "div[data-content-type=" + this.name + "]",
52
- contentElement: ".bn-inline-content",
53
- },
54
- ];
55
- },
56
-
57
- renderHTML({ HTMLAttributes }) {
58
- return createDefaultBlockDOMOutputSpec(
59
- this.name,
60
- "p",
61
- {
62
- ...(this.options.domAttributes?.blockContent || {}),
63
- ...HTMLAttributes,
64
- },
65
- this.options.domAttributes?.inlineContent || {},
66
- );
67
- },
68
-
69
- addNodeView() {
70
- return ({ HTMLAttributes, getPos }) => {
71
- const { dom, contentDOM } = createDefaultBlockDOMOutputSpec(
72
- this.name,
73
- "p",
74
- {
75
- ...(this.options.domAttributes?.blockContent || {}),
76
- ...HTMLAttributes,
77
- },
78
- this.options.domAttributes?.inlineContent || {},
79
- );
80
-
81
- const editor = this.options.editor;
82
- const block = getBlockFromPos(getPos, editor, this.editor, this.name);
83
-
84
- const toggleWrapper = createToggleWrapper(
85
- block as any,
86
- editor,
87
- contentDOM,
88
- );
89
- dom.appendChild(toggleWrapper.dom);
90
-
91
- return {
92
- dom,
93
- contentDOM,
94
- ignoreMutation: toggleWrapper.ignoreMutation,
95
- destroy: toggleWrapper.destroy,
96
- };
97
- };
98
- },
99
- });
100
-
101
- export const ToggleListItem = createBlockSpecFromStronglyTypedTiptapNode(
102
- ToggleListItemBlockContent,
103
- toggleListItemPropSchema,
104
- );
@@ -1,49 +0,0 @@
1
- import {
2
- createBlockSpec,
3
- CustomBlockConfig,
4
- Props,
5
- } from "../../schema/index.js";
6
-
7
- export const pageBreakConfig = {
8
- type: "pageBreak" as const,
9
- propSchema: {},
10
- content: "none",
11
- isFileBlock: false,
12
- isSelectable: false,
13
- } satisfies CustomBlockConfig;
14
- export const pageBreakRender = () => {
15
- const pageBreak = document.createElement("div");
16
-
17
- pageBreak.className = "bn-page-break";
18
- pageBreak.setAttribute("data-page-break", "");
19
-
20
- return {
21
- dom: pageBreak,
22
- };
23
- };
24
- export const pageBreakParse = (
25
- element: HTMLElement,
26
- ): Partial<Props<typeof pageBreakConfig.propSchema>> | undefined => {
27
- if (element.tagName === "DIV" && element.hasAttribute("data-page-break")) {
28
- return {
29
- type: "pageBreak",
30
- };
31
- }
32
-
33
- return undefined;
34
- };
35
- export const pageBreakToExternalHTML = () => {
36
- const pageBreak = document.createElement("div");
37
-
38
- pageBreak.setAttribute("data-page-break", "");
39
-
40
- return {
41
- dom: pageBreak,
42
- };
43
- };
44
-
45
- export const PageBreak = createBlockSpec(pageBreakConfig, {
46
- render: pageBreakRender,
47
- parse: pageBreakParse,
48
- toExternalHTML: pageBreakToExternalHTML,
49
- });
@@ -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
- );