@blocknote/core 0.38.0 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/dist/BlockNoteSchema-DmZ6UQfY.cjs +11 -0
  2. package/dist/BlockNoteSchema-DmZ6UQfY.cjs.map +1 -0
  3. package/dist/BlockNoteSchema-oR047ACf.js +4275 -0
  4. package/dist/BlockNoteSchema-oR047ACf.js.map +1 -0
  5. package/dist/blocknote.cjs +4 -12
  6. package/dist/blocknote.cjs.map +1 -1
  7. package/dist/blocknote.js +3401 -7305
  8. package/dist/blocknote.js.map +1 -1
  9. package/dist/blocks.cjs +2 -0
  10. package/dist/blocks.cjs.map +1 -0
  11. package/dist/blocks.js +71 -0
  12. package/dist/blocks.js.map +1 -0
  13. package/dist/style.css +1 -1
  14. package/dist/tsconfig.tsbuildinfo +1 -1
  15. package/dist/webpack-stats.json +1 -1
  16. package/package.json +19 -16
  17. package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
  18. package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
  19. package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
  20. package/src/api/blockManipulation/setupTestEnv.ts +0 -1
  21. package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +6 -10
  22. package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
  23. package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
  24. package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
  25. package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
  26. package/src/api/pmUtil.ts +1 -1
  27. package/src/api/positionMapping.test.ts +58 -15
  28. package/src/api/positionMapping.ts +2 -4
  29. package/src/blocks/Audio/block.ts +174 -0
  30. package/src/blocks/BlockNoteSchema.ts +59 -0
  31. package/src/blocks/Code/block.ts +303 -0
  32. package/src/blocks/Code/shiki.ts +73 -0
  33. package/src/blocks/File/block.ts +98 -0
  34. package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +5 -2
  35. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +15 -6
  36. package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
  37. package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +21 -2
  38. package/src/blocks/Heading/block.ts +138 -0
  39. package/src/blocks/Image/block.ts +190 -0
  40. package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
  41. package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
  42. package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
  43. package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
  44. package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
  45. package/src/blocks/PageBreak/block.ts +72 -0
  46. package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
  47. package/src/blocks/Paragraph/block.ts +80 -0
  48. package/src/blocks/Quote/block.ts +90 -0
  49. package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
  50. package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
  51. package/src/blocks/Video/block.ts +143 -0
  52. package/src/blocks/defaultBlockHelpers.ts +2 -2
  53. package/src/blocks/defaultBlockTypeGuards.ts +143 -174
  54. package/src/blocks/defaultBlocks.ts +107 -35
  55. package/src/blocks/defaultProps.ts +145 -4
  56. package/src/blocks/index.ts +26 -0
  57. package/src/blocks/utils/listItemEnterHandler.ts +42 -0
  58. package/src/editor/Block.css +54 -18
  59. package/src/editor/BlockNoteEditor.ts +256 -211
  60. package/src/editor/BlockNoteExtension.ts +92 -0
  61. package/src/editor/BlockNoteExtensions.ts +18 -17
  62. package/src/editor/defaultColors.ts +2 -2
  63. package/src/exporter/Exporter.ts +1 -1
  64. package/src/exporter/mapping.ts +1 -1
  65. package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
  66. package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
  67. package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
  68. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
  69. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
  70. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
  71. package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
  72. package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
  73. package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
  74. package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
  75. package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
  76. package/src/extensions/Comments/CommentsPlugin.ts +1 -1
  77. package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
  78. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
  79. package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
  80. package/src/extensions/Placeholder/PlaceholderPlugin.ts +6 -6
  81. package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
  82. package/src/extensions/SideMenu/SideMenuPlugin.ts +1 -3
  83. package/src/extensions/SideMenu/dragging.ts +2 -2
  84. package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +4 -7
  85. package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
  86. package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
  87. package/src/extensions/TableHandles/TableHandlesPlugin.ts +8 -8
  88. package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
  89. package/src/extensions/TextColor/TextColorExtension.ts +3 -17
  90. package/src/extensions/TextColor/TextColorMark.ts +4 -9
  91. package/src/extensions/UniqueID/UniqueID.ts +6 -13
  92. package/src/index.ts +2 -28
  93. package/src/schema/blocks/createSpec.ts +342 -169
  94. package/src/schema/blocks/internal.ts +77 -138
  95. package/src/schema/blocks/types.ts +264 -94
  96. package/src/schema/index.ts +1 -0
  97. package/src/schema/inlineContent/createSpec.ts +99 -21
  98. package/src/schema/inlineContent/internal.ts +16 -7
  99. package/src/schema/inlineContent/types.ts +24 -2
  100. package/src/schema/propTypes.ts +15 -9
  101. package/src/schema/schema.ts +209 -0
  102. package/src/schema/styles/createSpec.ts +79 -31
  103. package/src/schema/styles/internal.ts +61 -2
  104. package/src/schema/styles/types.ts +17 -3
  105. package/src/util/topo-sort.test.ts +125 -0
  106. package/src/util/topo-sort.ts +160 -0
  107. package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
  108. package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
  109. package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
  110. package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
  111. package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
  112. package/types/src/api/pmUtil.d.ts +1 -1
  113. package/types/src/blocks/Audio/block.d.ts +58 -0
  114. package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
  115. package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
  116. package/types/src/blocks/Code/shiki.d.ts +4 -0
  117. package/types/src/blocks/File/block.d.ts +37 -0
  118. package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
  119. package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
  120. package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
  121. package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
  122. package/types/src/blocks/Heading/block.d.ts +71 -0
  123. package/types/src/blocks/Image/block.d.ts +102 -0
  124. package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
  125. package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
  126. package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
  127. package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
  128. package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
  129. package/types/src/blocks/PageBreak/block.d.ts +11 -0
  130. package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
  131. package/types/src/blocks/Paragraph/block.d.ts +25 -0
  132. package/types/src/blocks/Quote/block.d.ts +17 -0
  133. package/types/src/blocks/Table/block.d.ts +21 -0
  134. package/types/src/blocks/Video/block.d.ts +67 -0
  135. package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
  136. package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
  137. package/types/src/blocks/defaultBlocks.d.ts +221 -1060
  138. package/types/src/blocks/defaultProps.d.ts +17 -1
  139. package/types/src/blocks/index.d.ts +24 -0
  140. package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
  141. package/types/src/editor/BlockNoteEditor.d.ts +36 -67
  142. package/types/src/editor/BlockNoteExtension.d.ts +67 -0
  143. package/types/src/editor/BlockNoteExtensions.d.ts +1 -1
  144. package/types/src/editor/defaultColors.d.ts +8 -76
  145. package/types/src/exporter/Exporter.d.ts +1 -1
  146. package/types/src/exporter/mapping.d.ts +1 -1
  147. package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
  148. package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
  149. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
  150. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
  151. package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
  152. package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
  153. package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
  154. package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
  155. package/types/src/index.d.ts +2 -25
  156. package/types/src/schema/blocks/createSpec.d.ts +16 -36
  157. package/types/src/schema/blocks/internal.d.ts +11 -33
  158. package/types/src/schema/blocks/types.d.ts +181 -57
  159. package/types/src/schema/index.d.ts +1 -0
  160. package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
  161. package/types/src/schema/inlineContent/internal.d.ts +7 -15
  162. package/types/src/schema/inlineContent/types.d.ts +15 -1
  163. package/types/src/schema/propTypes.d.ts +4 -4
  164. package/types/src/schema/schema.d.ts +40 -0
  165. package/types/src/schema/styles/createSpec.d.ts +6 -4
  166. package/types/src/schema/styles/internal.d.ts +6 -3
  167. package/types/src/schema/styles/types.d.ts +11 -2
  168. package/types/src/util/topo-sort.d.ts +18 -0
  169. package/types/src/util/topo-sort.test.d.ts +1 -0
  170. package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -144
  171. package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
  172. package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
  173. package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
  174. package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -159
  175. package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
  176. package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
  177. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
  178. package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
  179. package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
  180. package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
  181. package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
  182. package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
  183. package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
  184. package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -158
  185. package/src/editor/BlockNoteSchema.ts +0 -107
  186. package/src/editor/BlockNoteTipTapEditor.ts +0 -335
  187. package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
  188. package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
  189. package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
  190. package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
  191. package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
  192. package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
  193. package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
  194. package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
  195. package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
  196. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
  197. package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
  198. package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
  199. package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
  200. package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
  201. package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
  202. package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
  203. package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
  204. package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
  205. package/types/src/editor/BlockNoteSchema.d.ts +0 -34
  206. package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
  207. /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
  208. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
  209. /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
  210. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
  211. /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
  212. /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
  213. /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
  214. /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
  215. /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
  216. /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
  217. /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
  218. /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
  219. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
  220. /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
  221. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
  222. /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
  223. /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
  224. /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
  225. /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
  226. /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
  227. /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
  228. /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
@@ -1,335 +0,0 @@
1
- import {
2
- Editor,
3
- EditorOptions,
4
- Editor as TiptapEditor,
5
- createDocument,
6
- } from "@tiptap/core";
7
-
8
- import { Node } from "@tiptap/pm/model";
9
-
10
- import { EditorView } from "@tiptap/pm/view";
11
-
12
- import { EditorState, Transaction } from "@tiptap/pm/state";
13
- import { blockToNode } from "../api/nodeConversions/blockToNode.js";
14
- import { PartialBlock } from "../blocks/defaultBlocks.js";
15
- import { StyleSchema } from "../schema/index.js";
16
- import type { BlockNoteEditor } from "./BlockNoteEditor.js";
17
-
18
- export type BlockNoteTipTapEditorOptions = Partial<
19
- Omit<EditorOptions, "content">
20
- > & {
21
- content: PartialBlock<any, any, any>[];
22
- };
23
-
24
- /**
25
- * Custom Editor class that extends TiptapEditor and separates
26
- * the creation of the view from the constructor.
27
- */
28
- export class BlockNoteTipTapEditor extends TiptapEditor {
29
- private _state: EditorState;
30
-
31
- public static create = (
32
- options: BlockNoteTipTapEditorOptions,
33
- styleSchema: StyleSchema,
34
- ) => {
35
- // because we separate the constructor from the creation of the view,
36
- // we need to patch setTimeout to prevent this code from having any effect:
37
- // https://github.com/ueberdosis/tiptap/blob/45bac803283446795ad1b03f43d3746fa54a68ff/packages/core/src/Editor.ts#L117
38
- const oldSetTimeout = globalThis?.window?.setTimeout;
39
- if (typeof globalThis?.window?.setTimeout !== "undefined") {
40
- globalThis.window.setTimeout = (() => {
41
- return 0;
42
- }) as any;
43
- }
44
- try {
45
- return new BlockNoteTipTapEditor(options, styleSchema);
46
- } finally {
47
- if (oldSetTimeout) {
48
- globalThis.window.setTimeout = oldSetTimeout;
49
- }
50
- }
51
- };
52
-
53
- protected constructor(
54
- options: BlockNoteTipTapEditorOptions,
55
- styleSchema: StyleSchema,
56
- ) {
57
- // possible fix for next.js server side rendering
58
- // const d = globalThis.document;
59
- // const w = globalThis.window;
60
- // if (!globalThis.document) {
61
- // globalThis.document = {
62
- // createElement: () => {},
63
- // };
64
- // }
65
-
66
- // options.injectCSS = false
67
-
68
- super({ ...options, content: undefined });
69
- // try {
70
- // globalThis.window = w;
71
- // } catch(e) {}
72
- // try {
73
- // globalThis.document = d;
74
- // } catch(e) {}
75
-
76
- // This is a hack to make "initial content detection" by y-prosemirror (and also tiptap isEmpty)
77
- // properly detect whether or not the document has changed.
78
- // We change the doc.createAndFill function to make sure the initial block id is set, instead of null
79
- const schema = this.schema;
80
- let cache: any;
81
- const oldCreateAndFill = schema.nodes.doc.createAndFill;
82
- (schema.nodes.doc as any).createAndFill = (...args: any) => {
83
- if (cache) {
84
- return cache;
85
- }
86
- const ret = oldCreateAndFill.apply(schema.nodes.doc, args);
87
-
88
- // create a copy that we can mutate (otherwise, assigning attrs is not safe and corrupts the pm state)
89
- const jsonNode = JSON.parse(JSON.stringify(ret!.toJSON()));
90
- jsonNode.content[0].content[0].attrs.id = "initialBlockId";
91
-
92
- cache = Node.fromJSON(schema, jsonNode);
93
- return cache;
94
- };
95
-
96
- let doc: Node;
97
-
98
- try {
99
- const pmNodes = options?.content.map((b) =>
100
- blockToNode(b, this.schema, styleSchema).toJSON(),
101
- );
102
- doc = createDocument(
103
- {
104
- type: "doc",
105
- content: [
106
- {
107
- type: "blockGroup",
108
- content: pmNodes,
109
- },
110
- ],
111
- },
112
- this.schema,
113
- this.options.parseOptions,
114
- );
115
- } catch (e) {
116
- // eslint-disable-next-line no-console
117
- console.error(
118
- "Error creating document from blocks passed as `initialContent`. Caused by exception: ",
119
- e,
120
- );
121
- throw new Error(
122
- "Error creating document from blocks passed as `initialContent`:\n" +
123
- +JSON.stringify(options.content),
124
- );
125
- }
126
-
127
- // Create state immediately, so that it's available independently from the View,
128
- // the way Prosemirror "intends it to be". This also makes sure that we can access
129
- // the state before the view is created / mounted.
130
- this._state = EditorState.create({
131
- doc,
132
- schema: this.schema,
133
- // selection: selection || undefined,
134
- });
135
- }
136
-
137
- get state() {
138
- if (this.view) {
139
- this._state = this.view.state;
140
- }
141
- return this._state;
142
- }
143
-
144
- dispatch(transaction: Transaction) {
145
- if (!this.view) {
146
- // before view has been initialized
147
- this._state = this.state.apply(transaction);
148
- this.emit("transaction", {
149
- editor: this,
150
- transaction,
151
- });
152
- return;
153
- }
154
- // This is a verbatim copy of the default dispatch method, but with the following changes:
155
- // - We provide the appendedTransactions to a new `v3-update` event
156
- // In the future, we can remove this dispatch method entirely and rely on the new `update` event signature which does what we want by providing the appendedTransactions
157
- ////////////////////////////////////////////////////////////////////////////////
158
- // if the editor / the view of the editor was destroyed
159
- // the transaction should not be dispatched as there is no view anymore.
160
- if (this.view.isDestroyed) {
161
- return;
162
- }
163
-
164
- if (this.isCapturingTransaction) {
165
- // Do the default capture behavior
166
- (this as any).dispatchTransaction(transaction);
167
-
168
- return;
169
- }
170
-
171
- const { state, transactions: appendedTransactions } =
172
- this.state.applyTransaction(transaction);
173
- const selectionHasChanged = !this.state.selection.eq(state.selection);
174
-
175
- this.emit("beforeTransaction", {
176
- editor: this,
177
- transaction,
178
- nextState: state,
179
- });
180
- this.view.updateState(state);
181
- this.emit("transaction", {
182
- editor: this,
183
- transaction,
184
- });
185
-
186
- if (selectionHasChanged) {
187
- this.emit("selectionUpdate", {
188
- editor: this,
189
- transaction,
190
- });
191
- }
192
-
193
- const focus = transaction.getMeta("focus");
194
- const blur = transaction.getMeta("blur");
195
-
196
- if (focus) {
197
- this.emit("focus", {
198
- editor: this,
199
- event: focus.event,
200
- transaction,
201
- });
202
- }
203
-
204
- if (blur) {
205
- this.emit("blur", {
206
- editor: this,
207
- event: blur.event,
208
- transaction,
209
- });
210
- }
211
-
212
- if (!transaction.docChanged || transaction.getMeta("preventUpdate")) {
213
- return;
214
- }
215
-
216
- this.emit("update", {
217
- editor: this,
218
- transaction,
219
- });
220
- this.emit("v3-update", {
221
- editor: this,
222
- transaction,
223
- appendedTransactions: appendedTransactions.slice(1),
224
- });
225
- }
226
-
227
- // a helper method that can enable plugins before the view has been initialized
228
- // currently only used for testing
229
- forceEnablePlugins() {
230
- if (this.view) {
231
- throw new Error(
232
- "forcePluginsEnabled called after view has been initialized",
233
- );
234
- }
235
- this._state = this.state.reconfigure({
236
- plugins: this.extensionManager.plugins,
237
- });
238
- }
239
-
240
- /**
241
- * Replace the default `createView` method with a custom one - which we call on mount
242
- */
243
- private createViewAlternative(
244
- blockNoteEditor: BlockNoteEditor<any, any, any>,
245
- contentComponent?: any,
246
- ) {
247
- (this as any).contentComponent = contentComponent;
248
-
249
- const markViews: any = {};
250
- this.extensionManager.extensions.forEach((extension) => {
251
- if (extension.type === "mark" && extension.config.addMarkView) {
252
- // Note: migrate to using `addMarkView` from tiptap as soon as this lands
253
- // (currently tiptap doesn't support markviews)
254
- markViews[extension.name] =
255
- extension.config.addMarkView(blockNoteEditor);
256
- }
257
- });
258
-
259
- this.view = new EditorView(
260
- { mount: this.options.element as any }, // use mount option so that we reuse the existing element instead of creating a new one
261
- {
262
- ...this.options.editorProps,
263
- // @ts-ignore
264
- dispatchTransaction: this.dispatch.bind(this),
265
- state: this.state,
266
- markViews,
267
- nodeViews: this.extensionManager.nodeViews,
268
- },
269
- );
270
-
271
- // `editor.view` is not yet available at this time.
272
- // Therefore we will add all plugins directly afterwards.
273
- //
274
- // To research: this is the default tiptap behavior, but might actually not be necessary
275
- // it feels like it's a workaround for plugins that don't account for the view not being available yet
276
- const newState = this.state.reconfigure({
277
- plugins: this.extensionManager.plugins,
278
- });
279
-
280
- this.view.updateState(newState);
281
-
282
- // emit the created event, call here manually because we blocked the default call in the constructor
283
- // (https://github.com/ueberdosis/tiptap/blob/45bac803283446795ad1b03f43d3746fa54a68ff/packages/core/src/Editor.ts#L117)
284
- this.commands.focus(
285
- this.options.autofocus ||
286
- this.options.element.getAttribute("data-bn-autofocus") === "true",
287
- { scrollIntoView: false },
288
- );
289
- this.emit("create", { editor: this });
290
- this.isInitialized = true;
291
- }
292
-
293
- /**
294
- * Mounts / unmounts the editor to a dom element
295
- *
296
- * @param element DOM element to mount to, ur null / undefined to destroy
297
- */
298
- public mount = (
299
- blockNoteEditor: BlockNoteEditor<any, any, any>,
300
- element?: HTMLElement | null,
301
- contentComponent?: any,
302
- ) => {
303
- if (!element) {
304
- this.destroy();
305
- this.isInitialized = false;
306
- } else {
307
- this.options.element = element;
308
- this.createViewAlternative(blockNoteEditor, contentComponent);
309
- }
310
- };
311
- }
312
-
313
- (BlockNoteTipTapEditor.prototype as any).createView = function () {
314
- // no-op
315
- // Disable default call to `createView` in the Editor constructor.
316
- // We should call `createView` manually only when a DOM element is available
317
-
318
- // additional fix because onPaste and onDrop depend on installing plugins in constructor which we don't support
319
- // (note: can probably be removed after tiptap upgrade fixed in 2.8.0)
320
- this.options.onPaste = this.options.onDrop = undefined;
321
- };
322
-
323
- declare module "@tiptap/core" {
324
- interface EditorEvents {
325
- /**
326
- * This is a custom event that will be emitted in Tiptap V3.
327
- * We use it to provide the appendedTransactions, until Tiptap V3 is released.
328
- */
329
- "v3-update": {
330
- editor: Editor;
331
- transaction: Transaction;
332
- appendedTransactions: Transaction[];
333
- };
334
- }
335
- }
@@ -1,99 +0,0 @@
1
- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
2
- import { BlockFromConfig, Props } from "../../schema/index.js";
3
- export declare const FILE_AUDIO_ICON_SVG = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><path d=\"M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z\"></path></svg>";
4
- export declare const audioPropSchema: {
5
- backgroundColor: {
6
- default: "default";
7
- };
8
- name: {
9
- default: "";
10
- };
11
- url: {
12
- default: "";
13
- };
14
- caption: {
15
- default: "";
16
- };
17
- showPreview: {
18
- default: true;
19
- };
20
- };
21
- export declare const audioBlockConfig: {
22
- type: "audio";
23
- propSchema: {
24
- backgroundColor: {
25
- default: "default";
26
- };
27
- name: {
28
- default: "";
29
- };
30
- url: {
31
- default: "";
32
- };
33
- caption: {
34
- default: "";
35
- };
36
- showPreview: {
37
- default: true;
38
- };
39
- };
40
- content: "none";
41
- isFileBlock: true;
42
- fileBlockAccept: string[];
43
- };
44
- export declare const audioRender: (block: BlockFromConfig<typeof audioBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>) => {
45
- dom: HTMLElement;
46
- destroy?: () => void;
47
- };
48
- export declare const audioParse: (element: HTMLElement) => Partial<Props<typeof audioBlockConfig.propSchema>> | undefined;
49
- export declare const audioToExternalHTML: (block: BlockFromConfig<typeof audioBlockConfig, any, any>) => {
50
- dom: HTMLElement;
51
- };
52
- export declare const AudioBlock: {
53
- config: {
54
- type: "audio";
55
- propSchema: {
56
- backgroundColor: {
57
- default: "default";
58
- };
59
- name: {
60
- default: "";
61
- };
62
- url: {
63
- default: "";
64
- };
65
- caption: {
66
- default: "";
67
- };
68
- showPreview: {
69
- default: true;
70
- };
71
- };
72
- content: "none";
73
- isFileBlock: true;
74
- fileBlockAccept: string[];
75
- };
76
- implementation: import("../../index.js").TiptapBlockImplementation<{
77
- type: "audio";
78
- propSchema: {
79
- backgroundColor: {
80
- default: "default";
81
- };
82
- name: {
83
- default: "";
84
- };
85
- url: {
86
- default: "";
87
- };
88
- caption: {
89
- default: "";
90
- };
91
- showPreview: {
92
- default: true;
93
- };
94
- };
95
- content: "none";
96
- isFileBlock: true;
97
- fileBlockAccept: string[];
98
- }, any, import("../../index.js").InlineContentSchema, import("../../index.js").StyleSchema>;
99
- };
@@ -1,90 +0,0 @@
1
- import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
2
- import { BlockFromConfig } from "../../schema/index.js";
3
- export declare const filePropSchema: {
4
- backgroundColor: {
5
- default: "default";
6
- };
7
- name: {
8
- default: "";
9
- };
10
- url: {
11
- default: "";
12
- };
13
- caption: {
14
- default: "";
15
- };
16
- };
17
- export declare const fileBlockConfig: {
18
- type: "file";
19
- propSchema: {
20
- backgroundColor: {
21
- default: "default";
22
- };
23
- name: {
24
- default: "";
25
- };
26
- url: {
27
- default: "";
28
- };
29
- caption: {
30
- default: "";
31
- };
32
- };
33
- content: "none";
34
- isFileBlock: true;
35
- };
36
- export declare const fileRender: (block: BlockFromConfig<typeof fileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>) => {
37
- dom: HTMLElement;
38
- destroy?: () => void;
39
- };
40
- export declare const fileParse: (element: HTMLElement) => {
41
- url: string | undefined;
42
- } | {
43
- caption: string | undefined;
44
- url: string | undefined;
45
- } | undefined;
46
- export declare const fileToExternalHTML: (block: BlockFromConfig<typeof fileBlockConfig, any, any>) => {
47
- dom: HTMLParagraphElement;
48
- } | {
49
- dom: HTMLAnchorElement;
50
- };
51
- export declare const FileBlock: {
52
- config: {
53
- type: "file";
54
- propSchema: {
55
- backgroundColor: {
56
- default: "default";
57
- };
58
- name: {
59
- default: "";
60
- };
61
- url: {
62
- default: "";
63
- };
64
- caption: {
65
- default: "";
66
- };
67
- };
68
- content: "none";
69
- isFileBlock: true;
70
- };
71
- implementation: import("../../index.js").TiptapBlockImplementation<{
72
- type: "file";
73
- propSchema: {
74
- backgroundColor: {
75
- default: "default";
76
- };
77
- name: {
78
- default: "";
79
- };
80
- url: {
81
- default: "";
82
- };
83
- caption: {
84
- default: "";
85
- };
86
- };
87
- content: "none";
88
- isFileBlock: true;
89
- }, any, import("../../index.js").InlineContentSchema, import("../../index.js").StyleSchema>;
90
- };
@@ -1,6 +0,0 @@
1
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
- import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
3
- export declare const createAddFileButton: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>, buttonIcon?: HTMLElement) => {
4
- dom: HTMLDivElement;
5
- destroy: () => void;
6
- };
@@ -1,9 +0,0 @@
1
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
- import { BlockFromConfig, BlockSchemaWithBlock, FileBlockConfig } from "../../../../schema/index.js";
3
- export declare const createFileBlockWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<BlockSchemaWithBlock<FileBlockConfig["type"], FileBlockConfig>, any, any>, element?: {
4
- dom: HTMLElement;
5
- destroy?: () => void;
6
- }, buttonIcon?: HTMLElement) => {
7
- dom: HTMLElement;
8
- destroy?: () => void;
9
- };
@@ -1,9 +0,0 @@
1
- import type { BlockNoteEditor } from "../../../../editor/BlockNoteEditor.js";
2
- import { BlockFromConfig, FileBlockConfig } from "../../../../schema/index.js";
3
- export declare const createResizableFileBlockWrapper: (block: BlockFromConfig<FileBlockConfig, any, any>, editor: BlockNoteEditor<any, any, any>, element: {
4
- dom: HTMLElement;
5
- destroy?: () => void;
6
- }, resizeHandlesContainerElement: HTMLElement, buttonIcon?: HTMLElement) => {
7
- dom: HTMLElement;
8
- destroy: () => void;
9
- };
@@ -1,67 +0,0 @@
1
- export declare const headingPropSchema: {
2
- level: {
3
- default: number;
4
- values: readonly [1, 2, 3, 4, 5, 6];
5
- };
6
- isToggleable: {
7
- default: false;
8
- };
9
- backgroundColor: {
10
- default: "default";
11
- };
12
- textColor: {
13
- default: "default";
14
- };
15
- textAlignment: {
16
- default: "left";
17
- values: readonly ["left", "center", "right", "justify"];
18
- };
19
- };
20
- export declare const Heading: {
21
- config: {
22
- type: "heading";
23
- content: "inline";
24
- propSchema: {
25
- level: {
26
- default: number;
27
- values: readonly [1, 2, 3, 4, 5, 6];
28
- };
29
- isToggleable: {
30
- default: false;
31
- };
32
- backgroundColor: {
33
- default: "default";
34
- };
35
- textColor: {
36
- default: "default";
37
- };
38
- textAlignment: {
39
- default: "left";
40
- values: readonly ["left", "center", "right", "justify"];
41
- };
42
- };
43
- };
44
- implementation: import("../../index.js").TiptapBlockImplementation<{
45
- type: "heading";
46
- content: "inline";
47
- propSchema: {
48
- level: {
49
- default: number;
50
- values: readonly [1, 2, 3, 4, 5, 6];
51
- };
52
- isToggleable: {
53
- default: false;
54
- };
55
- backgroundColor: {
56
- default: "default";
57
- };
58
- textColor: {
59
- default: "default";
60
- };
61
- textAlignment: {
62
- default: "left";
63
- values: readonly ["left", "center", "right", "justify"];
64
- };
65
- };
66
- }, any, import("../../index.js").InlineContentSchema, import("../../index.js").StyleSchema>;
67
- };