@blocknote/core 0.53.0 → 0.54.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 (197) hide show
  1. package/dist/BlockNoteExtension-BJCLnwrE.cjs +2 -0
  2. package/dist/BlockNoteExtension-BJCLnwrE.cjs.map +1 -0
  3. package/dist/BlockNoteExtension-CbvDA0F7.js +80 -0
  4. package/dist/BlockNoteExtension-CbvDA0F7.js.map +1 -0
  5. package/dist/{UserStore-QbbPFj0z.js → UserStore-C4TzkGEn.js} +3 -3
  6. package/dist/{UserStore-DCG6lsla.cjs.map → UserStore-C4TzkGEn.js.map} +1 -1
  7. package/dist/{UserStore-DCG6lsla.cjs → UserStore-mj3fXW4D.cjs} +2 -2
  8. package/dist/UserStore-mj3fXW4D.cjs.map +1 -0
  9. package/dist/blocknote.cjs +1 -1
  10. package/dist/blocknote.js +6 -6
  11. package/dist/{blocks-BEJW9OM_.js → blocks-CzQLehlc.js} +571 -568
  12. package/dist/blocks-CzQLehlc.js.map +1 -0
  13. package/dist/blocks-CzkqclGj.cjs +12 -0
  14. package/dist/blocks-CzkqclGj.cjs.map +1 -0
  15. package/dist/blocks.cjs +1 -1
  16. package/dist/blocks.js +2 -2
  17. package/dist/comments.cjs +1 -1
  18. package/dist/comments.cjs.map +1 -1
  19. package/dist/comments.js +7 -7
  20. package/dist/comments.js.map +1 -1
  21. package/dist/en-BuzSuuTq.cjs +2 -0
  22. package/dist/en-BuzSuuTq.cjs.map +1 -0
  23. package/dist/{en-CGKXfWma.js → en-uzHzj6eH.js} +10 -1
  24. package/dist/en-uzHzj6eH.js.map +1 -0
  25. package/dist/extensions-CSB9ZvuL.cjs +58 -0
  26. package/dist/extensions-CSB9ZvuL.cjs.map +1 -0
  27. package/dist/{extensions-BR5hkAio.js → extensions-DGuhtOgB.js} +662 -427
  28. package/dist/extensions-DGuhtOgB.js.map +1 -0
  29. package/dist/extensions.cjs +1 -1
  30. package/dist/extensions.js +4 -4
  31. package/dist/locales.cjs +1 -1
  32. package/dist/locales.cjs.map +1 -1
  33. package/dist/locales.js +199 -1
  34. package/dist/locales.js.map +1 -1
  35. package/dist/{src-BUXut68d.js → src-BkfZVfaO.js} +967 -899
  36. package/dist/src-BkfZVfaO.js.map +1 -0
  37. package/dist/src-DM3syMdf.cjs +23 -0
  38. package/dist/src-DM3syMdf.cjs.map +1 -0
  39. package/dist/style.css +1 -1
  40. package/dist/webpack-stats.json +1 -1
  41. package/dist/y.cjs +1 -1
  42. package/dist/y.cjs.map +1 -1
  43. package/dist/y.js +59 -56
  44. package/dist/y.js.map +1 -1
  45. package/dist/yjs.cjs +1 -1
  46. package/dist/yjs.cjs.map +1 -1
  47. package/dist/yjs.js +88 -76
  48. package/dist/yjs.js.map +1 -1
  49. package/package.json +17 -18
  50. package/src/api/blockManipulation/commands/updateBlock/__snapshots__/updateBlock.test.ts.snap +2505 -763
  51. package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +42 -0
  52. package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +16 -4
  53. package/src/api/exporters/markdown/htmlToMarkdown.ts +45 -10
  54. package/src/api/nodeConversions/blockToNode.ts +5 -1
  55. package/src/api/nodeConversions/nodeToBlock.ts +3 -0
  56. package/src/api/pmUtil.ts +16 -8
  57. package/src/blocks/Code/CodeBlockOptions.ts +83 -0
  58. package/src/blocks/Code/block.test.ts +1 -1
  59. package/src/blocks/Code/block.ts +29 -281
  60. package/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.ts +120 -0
  61. package/src/blocks/Code/helpers/parse/parsePreCode.ts +45 -0
  62. package/src/blocks/Code/helpers/render/createCodeBlock.ts +98 -0
  63. package/src/blocks/Code/helpers/toExternalHTML/createPreCode.ts +14 -0
  64. package/src/blocks/index.ts +3 -0
  65. package/src/comments/extension.ts +2 -4
  66. package/src/editor/Block.css +273 -2
  67. package/src/editor/BlockNoteEditor.ts +25 -4
  68. package/src/editor/BlockNoteExtension.ts +1 -1
  69. package/src/editor/managers/ExtensionManager/extensions.ts +6 -0
  70. package/src/exporter/ExportImage.ts +50 -0
  71. package/src/exporter/Exporter.test.ts +48 -0
  72. package/src/exporter/Exporter.ts +46 -12
  73. package/src/exporter/index.ts +1 -0
  74. package/src/exporter/mapping.ts +4 -1
  75. package/src/extensions/FormattingToolbar/FormattingToolbar.ts +10 -8
  76. package/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.ts +109 -0
  77. package/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.ts +192 -0
  78. package/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.ts +142 -0
  79. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.ts +120 -0
  80. package/src/extensions/SyntaxHighlighting/SyntaxHighlighting.ts +89 -0
  81. package/src/extensions/SyntaxHighlighting/inlineHighlight.test.ts +135 -0
  82. package/src/extensions/SyntaxHighlighting/shiki.ts +116 -0
  83. package/src/extensions/Versioning/inMemoryVersioning.ts +13 -3
  84. package/src/extensions/index.ts +4 -0
  85. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +51 -2
  86. package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +22 -2
  87. package/src/i18n/locales/ar.ts +9 -0
  88. package/src/i18n/locales/de.ts +9 -0
  89. package/src/i18n/locales/en.ts +9 -0
  90. package/src/i18n/locales/es.ts +9 -0
  91. package/src/i18n/locales/fa.ts +9 -0
  92. package/src/i18n/locales/fr.ts +9 -0
  93. package/src/i18n/locales/he.ts +9 -0
  94. package/src/i18n/locales/hr.ts +9 -0
  95. package/src/i18n/locales/is.ts +9 -0
  96. package/src/i18n/locales/it.ts +9 -0
  97. package/src/i18n/locales/ja.ts +9 -0
  98. package/src/i18n/locales/ko.ts +9 -0
  99. package/src/i18n/locales/nl.ts +9 -0
  100. package/src/i18n/locales/no.ts +9 -0
  101. package/src/i18n/locales/pl.ts +9 -0
  102. package/src/i18n/locales/pt.ts +9 -0
  103. package/src/i18n/locales/ru.ts +9 -0
  104. package/src/i18n/locales/sk.ts +9 -0
  105. package/src/i18n/locales/uk.ts +9 -0
  106. package/src/i18n/locales/uz.ts +9 -0
  107. package/src/i18n/locales/vi.ts +9 -0
  108. package/src/i18n/locales/zh-tw.ts +9 -0
  109. package/src/i18n/locales/zh.ts +9 -0
  110. package/src/index.ts +5 -1
  111. package/src/schema/blocks/createSpec.ts +2 -3
  112. package/src/schema/blocks/types.ts +53 -3
  113. package/src/schema/contentTypePropagation.test.ts +1 -1
  114. package/src/schema/inlineContent/createSpec.test.ts +161 -0
  115. package/src/schema/inlineContent/createSpec.ts +171 -12
  116. package/src/schema/inlineContent/internal.ts +21 -2
  117. package/src/schema/inlineContent/types.ts +35 -5
  118. package/src/user/UserStore.ts +1 -1
  119. package/src/util/Store.test.ts +132 -0
  120. package/src/util/Store.ts +135 -0
  121. package/src/y/extensions/AttributionExtension.test.ts +10 -0
  122. package/src/y/extensions/Versioning.test.ts +20 -7
  123. package/src/yjs/comments/RESTYjsThreadStore.test.ts +85 -0
  124. package/src/yjs/comments/RESTYjsThreadStore.ts +7 -1
  125. package/src/yjs/extensions/ForkYDoc.test.ts +37 -0
  126. package/src/yjs/extensions/ForkYDoc.ts +26 -1
  127. package/src/yjs/extensions/RelativePositionMapping.ts +8 -2
  128. package/src/yjs/extensions/Versioning.test.ts +17 -5
  129. package/types/src/api/pmUtil.d.ts +7 -7
  130. package/types/src/blocks/Code/CodeBlockOptions.d.ts +61 -0
  131. package/types/src/blocks/Code/block.d.ts +3 -53
  132. package/types/src/blocks/Code/helpers/extensions/CodeKeyboardShortcutsExtension.d.ts +35 -0
  133. package/types/src/blocks/Code/helpers/parse/parsePreCode.d.ts +8 -0
  134. package/types/src/blocks/Code/helpers/render/createCodeBlock.d.ts +18 -0
  135. package/types/src/blocks/Code/helpers/toExternalHTML/createPreCode.d.ts +5 -0
  136. package/types/src/blocks/index.d.ts +3 -0
  137. package/types/src/comments/extension.d.ts +1 -15
  138. package/types/src/editor/BlockNoteEditor.d.ts +3 -3
  139. package/types/src/editor/BlockNoteExtension.d.ts +1 -1
  140. package/types/src/exporter/ExportImage.d.ts +36 -0
  141. package/types/src/exporter/Exporter.d.ts +21 -0
  142. package/types/src/exporter/Exporter.test.d.ts +1 -0
  143. package/types/src/exporter/index.d.ts +1 -0
  144. package/types/src/exporter/mapping.d.ts +1 -1
  145. package/types/src/extensions/FilePanel/FilePanel.d.ts +1 -1
  146. package/types/src/extensions/FormattingToolbar/FormattingToolbar.d.ts +1 -1
  147. package/types/src/extensions/InlineContentBoundaryEdit/InlineContentBoundaryEdit.d.ts +5 -0
  148. package/types/src/extensions/ShowSelection/ShowSelection.d.ts +1 -5
  149. package/types/src/extensions/SideMenu/SideMenu.d.ts +1 -1
  150. package/types/src/extensions/SourceBlockWithPreview/SourceBlockWithPreview.d.ts +45 -0
  151. package/types/src/extensions/SourceInlineContentWithPreview/SourceInlineContentWithPreview.d.ts +49 -0
  152. package/types/src/extensions/SuggestionMenu/SuggestionMenu.d.ts +1 -11
  153. package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.d.ts +44 -0
  154. package/types/src/extensions/SyntaxHighlighting/SyntaxHighlighting.test.d.ts +1 -0
  155. package/types/src/extensions/SyntaxHighlighting/inlineHighlight.test.d.ts +1 -0
  156. package/types/src/extensions/SyntaxHighlighting/shiki.d.ts +13 -0
  157. package/types/src/extensions/TableHandles/TableHandles.d.ts +1 -1
  158. package/types/src/extensions/Versioning/Versioning.d.ts +1 -35
  159. package/types/src/extensions/index.d.ts +4 -0
  160. package/types/src/i18n/locales/en.d.ts +9 -0
  161. package/types/src/i18n/locales/fa.d.ts +9 -0
  162. package/types/src/i18n/locales/sk.d.ts +9 -0
  163. package/types/src/index.d.ts +2 -1
  164. package/types/src/schema/blocks/types.d.ts +36 -3
  165. package/types/src/schema/inlineContent/createSpec.d.ts +35 -3
  166. package/types/src/schema/inlineContent/createSpec.test.d.ts +1 -0
  167. package/types/src/schema/inlineContent/internal.d.ts +3 -2
  168. package/types/src/schema/inlineContent/types.d.ts +22 -3
  169. package/types/src/user/UserStore.d.ts +1 -1
  170. package/types/src/util/Store.d.ts +45 -0
  171. package/types/src/util/Store.test.d.ts +1 -0
  172. package/types/src/y/extensions/AttributionExtension.d.ts +1 -1
  173. package/types/src/y/extensions/DiffVersioningExtension.d.ts +1 -1
  174. package/types/src/y/extensions/ForkYDoc.d.ts +1 -5
  175. package/types/src/y/extensions/index.d.ts +2 -10
  176. package/types/src/yjs/comments/RESTYjsThreadStore.test.d.ts +1 -0
  177. package/types/src/yjs/extensions/ForkYDoc.d.ts +1 -5
  178. package/types/src/yjs/extensions/index.d.ts +1 -5
  179. package/dist/BlockNoteExtension-B_IEJHS8.js +0 -38
  180. package/dist/BlockNoteExtension-B_IEJHS8.js.map +0 -1
  181. package/dist/BlockNoteExtension-M0znTzxP.cjs +0 -2
  182. package/dist/BlockNoteExtension-M0znTzxP.cjs.map +0 -1
  183. package/dist/UserStore-QbbPFj0z.js.map +0 -1
  184. package/dist/blocks-BEJW9OM_.js.map +0 -1
  185. package/dist/blocks-BPmJglFo.cjs +0 -12
  186. package/dist/blocks-BPmJglFo.cjs.map +0 -1
  187. package/dist/en-C5Z4Ag9_.cjs +0 -2
  188. package/dist/en-C5Z4Ag9_.cjs.map +0 -1
  189. package/dist/en-CGKXfWma.js.map +0 -1
  190. package/dist/extensions-AitWbYdJ.cjs +0 -52
  191. package/dist/extensions-AitWbYdJ.cjs.map +0 -1
  192. package/dist/extensions-BR5hkAio.js.map +0 -1
  193. package/dist/src-BHPuOo7W.cjs +0 -21
  194. package/dist/src-BHPuOo7W.cjs.map +0 -1
  195. package/dist/src-BUXut68d.js.map +0 -1
  196. package/src/blocks/Code/shiki.ts +0 -73
  197. package/types/src/blocks/Code/shiki.d.ts +0 -4
@@ -261,41 +261,7 @@ export type VersioningExtensionOptions<Input = any, Output = any, Attributions =
261
261
  };
262
262
  export declare const VersioningExtension: (options: VersioningExtensionOptions<any, any, any> | ((editor: BlockNoteEditor<any, any, any>) => VersioningExtensionOptions)) => import("../../index.js").ExtensionFactoryInstance<{
263
263
  readonly key: "versioning";
264
- readonly store: import("@tanstack/store").Store<{
265
- snapshots: VersionSnapshot[];
266
- /**
267
- * The id of the version currently shown in the editor (the "new" side of
268
- * a diff). `undefined` means the live, editable document. Is the
269
- * {@link CURRENT_VERSION_ID} symbol when previewing the live document as a
270
- * read-only diff against a snapshot.
271
- */
272
- previewedSnapshotId?: string | typeof CURRENT_VERSION_ID;
273
- /**
274
- * The id of the snapshot the preview is being diffed against (the
275
- * "baseline" / old side). `undefined` when not showing a diff. Always a
276
- * real snapshot id (never the current entry), but typed as the same union
277
- * as {@link VersionSnapshot.id} since it's copied from one. Used to render
278
- * the "Comparing to" indicator in the sidebar.
279
- */
280
- compareToSnapshotId?: string | typeof CURRENT_VERSION_ID;
281
- }, (cb: {
282
- snapshots: VersionSnapshot[];
283
- /**
284
- * The id of the version currently shown in the editor (the "new" side of
285
- * a diff). `undefined` means the live, editable document. Is the
286
- * {@link CURRENT_VERSION_ID} symbol when previewing the live document as a
287
- * read-only diff against a snapshot.
288
- */
289
- previewedSnapshotId?: string | typeof CURRENT_VERSION_ID;
290
- /**
291
- * The id of the snapshot the preview is being diffed against (the
292
- * "baseline" / old side). `undefined` when not showing a diff. Always a
293
- * real snapshot id (never the current entry), but typed as the same union
294
- * as {@link VersionSnapshot.id} since it's copied from one. Used to render
295
- * the "Comparing to" indicator in the sidebar.
296
- */
297
- compareToSnapshotId?: string | typeof CURRENT_VERSION_ID;
298
- }) => {
264
+ readonly store: import("../../index.js").Store<{
299
265
  snapshots: VersionSnapshot[];
300
266
  /**
301
267
  * The id of the version currently shown in the editor (the "new" side of
@@ -3,6 +3,7 @@ export * from "./DropCursor/DropCursor.js";
3
3
  export * from "./FilePanel/FilePanel.js";
4
4
  export * from "./FormattingToolbar/FormattingToolbar.js";
5
5
  export * from "./History/History.js";
6
+ export * from "./InlineContentBoundaryEdit/InlineContentBoundaryEdit.js";
6
7
  export * from "./LinkToolbar/LinkToolbar.js";
7
8
  export * from "./LinkToolbar/protocols.js";
8
9
  export * from "./NodeSelectionKeyboard/NodeSelectionKeyboard.js";
@@ -11,7 +12,10 @@ export * from "./PositionMapping/PositionMapping.js";
11
12
  export * from "./PreviousBlockType/PreviousBlockType.js";
12
13
  export * from "./ShowSelection/ShowSelection.js";
13
14
  export * from "./SideMenu/SideMenu.js";
15
+ export * from "./SourceBlockWithPreview/SourceBlockWithPreview.js";
16
+ export * from "./SourceInlineContentWithPreview/SourceInlineContentWithPreview.js";
14
17
  export * from "./SuggestionMenu/DefaultGridSuggestionItem.js";
18
+ export * from "./SyntaxHighlighting/SyntaxHighlighting.js";
15
19
  export * from "./SuggestionMenu/DefaultSuggestionItem.js";
16
20
  export * from "./SuggestionMenu/getDefaultEmojiPickerItems.js";
17
21
  export * from "./SuggestionMenu/getDefaultSlashMenuItems.js";
@@ -152,6 +152,10 @@ export declare const en: {
152
152
  toggle_blocks: {
153
153
  add_block_button: string;
154
154
  };
155
+ code_block: {
156
+ add_source_button_text: string;
157
+ ok_button_text: string;
158
+ };
155
159
  side_menu: {
156
160
  add_block_label: string;
157
161
  drag_handle_label: string;
@@ -324,6 +328,11 @@ export declare const en: {
324
328
  deleted_by: (users: string) => string;
325
329
  formatting_change_by: (formats: string, users: string) => string;
326
330
  };
331
+ exporter: {
332
+ open_file: string;
333
+ open_video_file: string;
334
+ open_audio_file: string;
335
+ };
327
336
  generic: {
328
337
  ctrl_shortcut: string;
329
338
  };
@@ -152,6 +152,10 @@ export declare const fa: {
152
152
  toggle_blocks: {
153
153
  add_block_button: string;
154
154
  };
155
+ code_block: {
156
+ add_source_button_text: string;
157
+ ok_button_text: string;
158
+ };
155
159
  side_menu: {
156
160
  add_block_label: string;
157
161
  drag_handle_label: string;
@@ -324,6 +328,11 @@ export declare const fa: {
324
328
  deleted_by: (users: string) => string;
325
329
  formatting_change_by: (formats: string, users: string) => string;
326
330
  };
331
+ exporter: {
332
+ open_file: string;
333
+ open_video_file: string;
334
+ open_audio_file: string;
335
+ };
327
336
  generic: {
328
337
  ctrl_shortcut: string;
329
338
  };
@@ -152,6 +152,10 @@ export declare const sk: {
152
152
  toggle_blocks: {
153
153
  add_block_button: string;
154
154
  };
155
+ code_block: {
156
+ add_source_button_text: string;
157
+ ok_button_text: string;
158
+ };
155
159
  side_menu: {
156
160
  add_block_label: string;
157
161
  drag_handle_label: string;
@@ -359,6 +363,11 @@ export declare const sk: {
359
363
  deleted_by: (users: string) => string;
360
364
  formatting_change_by: (formats: string, users: string) => string;
361
365
  };
366
+ exporter: {
367
+ open_file: string;
368
+ open_video_file: string;
369
+ open_audio_file: string;
370
+ };
362
371
  generic: {
363
372
  ctrl_shortcut: string;
364
373
  };
@@ -23,10 +23,11 @@ export * from "./user/index.js";
23
23
  export * from "./util/browser.js";
24
24
  export * from "./util/combineByGroup.js";
25
25
  export * from "./util/expandToWords.js";
26
+ export * from "./util/Store.js";
26
27
  export * from "./util/string.js";
27
28
  export * from "./util/table.js";
28
29
  export * from "./util/typescript.js";
29
- export type { CodeBlockOptions } from "./blocks/Code/block.js";
30
+ export type { CodeBlockOptions, CodeBlockPreview, } from "./blocks/Code/CodeBlockOptions.js";
30
31
  export { assertEmpty, UnreachableCaseError } from "./util/typescript.js";
31
32
  export * from "./util/EventEmitter.js";
32
33
  export { selectedFragmentToHTML } from "./api/clipboard/toClipboard/copyExtension.js";
@@ -1,6 +1,6 @@
1
1
  /** Define the main block types **/
2
2
  import type { Node, NodeViewRendererProps } from "@tiptap/core";
3
- import type { Fragment, Schema } from "prosemirror-model";
3
+ import type { Fragment, Node as ProsemirrorNode, Schema } from "prosemirror-model";
4
4
  import type { ViewMutationRecord } from "prosemirror-view";
5
5
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
6
6
  import type { Extension, ExtensionFactoryInstance } from "../../editor/BlockNoteExtension.js";
@@ -11,7 +11,7 @@ export type BlockNoteDOMElement = "editor" | "block" | "blockGroup" | "blockCont
11
11
  export type BlockNoteDOMAttributes = Partial<{
12
12
  [DOMElement in BlockNoteDOMElement]: Record<string, string>;
13
13
  }>;
14
- export interface BlockConfigMeta {
14
+ export interface BlockConfigMeta<TName extends string = string, TProps extends PropSchema = PropSchema> {
15
15
  /**
16
16
  * Defines which keyboard shortcut should be used to insert a hard break into the block's inline content.
17
17
  * @default "shift+enter"
@@ -37,6 +37,19 @@ export interface BlockConfigMeta {
37
37
  * Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.isolating} block
38
38
  */
39
39
  isolating?: boolean;
40
+ /**
41
+ * Enables syntax highlighting of the contents of the block with the result of this callback
42
+ */
43
+ highlight?(block: {
44
+ type: TName;
45
+ props: Props<TProps>;
46
+ }): string | undefined;
47
+ /**
48
+ * Marks the block as rendering a preview with an editable source popup, driven
49
+ * by the editor-wide `SourceBlockWithPreviewExtension`. When `true`, the
50
+ * block's source is hidden behind its preview and edited via the popup.
51
+ */
52
+ hasPreview?: boolean;
40
53
  }
41
54
  /**
42
55
  * BlockConfig contains the "schema" info about a Block type
@@ -102,6 +115,7 @@ export type LooseBlockSpec<T extends string = string, PS extends PropSchema = Pr
102
115
  dom: HTMLElement | DocumentFragment;
103
116
  contentDOM?: HTMLElement;
104
117
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
118
+ update?: (node: ProsemirrorNode) => boolean;
105
119
  destroy?: () => void;
106
120
  };
107
121
  toExternalHTML?: (block: any, editor: BlockNoteEditor<any>, context: {
@@ -137,6 +151,7 @@ export type BlockSpecs = {
137
151
  dom: HTMLElement | DocumentFragment;
138
152
  contentDOM?: HTMLElement;
139
153
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
154
+ update?: (node: ProsemirrorNode) => boolean;
140
155
  destroy?: () => void;
141
156
  };
142
157
  toExternalHTML?: (block: any, editor: BlockNoteEditor<any>, context: {
@@ -191,6 +206,13 @@ export type PlainContent = (StyledText<{}> & {
191
206
  export type PartialPlainContent = string | (string | (StyledText<{}> & {
192
207
  styles: Record<string, never>;
193
208
  }))[];
209
+ /**
210
+ * The text of a block's `"plain"` content (e.g. a code block's source code).
211
+ * Accepts the partial form too: block render/export paths can receive
212
+ * `PartialBlock`s (e.g. the HTML serializers take them directly), where
213
+ * plain content may still be the bare-string sugar.
214
+ */
215
+ export declare function plainContentToString(content: PlainContent | PartialPlainContent): string;
194
216
  export type BlockFromConfigNoChildren<B extends BlockConfig, I extends InlineContentSchema, S extends StyleSchema> = {
195
217
  id: string;
196
218
  type: B["type"];
@@ -254,7 +276,7 @@ export type BlockImplementation<TName extends string = string, TProps extends Pr
254
276
  /**
255
277
  * Metadata
256
278
  */
257
- meta?: BlockConfigMeta;
279
+ meta?: BlockConfigMeta<TName, TProps>;
258
280
  /**
259
281
  * A function that converts the block into a DOM element
260
282
  */
@@ -279,6 +301,17 @@ export type BlockImplementation<TName extends string = string, TProps extends Pr
279
301
  dom: HTMLElement | DocumentFragment;
280
302
  contentDOM?: HTMLElement;
281
303
  ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
304
+ /**
305
+ * Called by ProseMirror when this block's node is updated (e.g. its content
306
+ * or props change). Return `true` to handle the update in place - keeping
307
+ * the existing DOM - or `false` to have the node view recreated via
308
+ * `render`. When omitted, ProseMirror keeps the node view and reconciles its
309
+ * `contentDOM` in place as long as the node type stays the same.
310
+ *
311
+ * Useful for blocks whose `render` builds custom DOM that needs to stay in
312
+ * sync with the node (e.g. a code block rendering a preview of its content).
313
+ */
314
+ update?: (node: ProsemirrorNode) => boolean;
282
315
  destroy?: () => void;
283
316
  };
284
317
  /**
@@ -1,4 +1,4 @@
1
- import { TagParseRule } from "@tiptap/pm/model";
1
+ import { Fragment, Node as ProsemirrorNode, Schema, TagParseRule } from "@tiptap/pm/model";
2
2
  import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
3
3
  import { Props } from "../propTypes.js";
4
4
  import { StyleSchema } from "../styles/types.js";
@@ -6,11 +6,33 @@ import { CustomInlineContentConfig, InlineContentFromConfig, InlineContentSpec,
6
6
  export type CustomInlineContentImplementation<T extends CustomInlineContentConfig, S extends StyleSchema> = {
7
7
  meta?: {
8
8
  draggable?: boolean;
9
+ code?: boolean;
10
+ /**
11
+ * When {@link code} is `true`, this can syntax highlight the contents of the
12
+ * inline content with the result of this callback.
13
+ */
14
+ highlight?(inlineContent: Pick<InlineContentFromConfig<T, S>, "type" | "props">): string | undefined;
15
+ /**
16
+ * Marks the inline content as rendering a preview with an editable source
17
+ * popup, driven by the editor-wide
18
+ * `SourceInlineContentWithPreviewExtension`.
19
+ */
20
+ hasPreview?: boolean;
9
21
  };
10
22
  /**
11
23
  * Parses an external HTML element into a inline content of this type when it returns the block props object, otherwise undefined
12
24
  */
13
25
  parse?: (el: HTMLElement) => Partial<Props<T["propSchema"]>> | undefined;
26
+ /**
27
+ * Advanced parsing function that controls how the content within the inline
28
+ * content is parsed. This is not recommended to use, and is only useful for
29
+ * advanced use cases. Only applies to inline content with `content: "styled"`.
30
+ * Return `undefined` to fall through to the default inline content parsing.
31
+ */
32
+ parseContent?: (options: {
33
+ el: HTMLElement;
34
+ schema: Schema;
35
+ }) => Fragment | undefined;
14
36
  /**
15
37
  * Renders an inline content to DOM elements
16
38
  */
@@ -28,7 +50,17 @@ export type CustomInlineContentImplementation<T extends CustomInlineContentConfi
28
50
  * This is typed generically. If you want an editor with your custom schema, you need to
29
51
  * cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
30
52
  */
31
- editor: BlockNoteEditor<any, any, S>) => {
53
+ editor: BlockNoteEditor<any, any, S>,
54
+ /**
55
+ * The ProseMirror node backing this inline content.
56
+ */
57
+ node: ProsemirrorNode,
58
+ /**
59
+ * Returns this inline content's position in the document. When rendered
60
+ * outside the editor (i.e. serialized to HTML), this is a no-op that returns
61
+ * `undefined`.
62
+ */
63
+ getPos: () => number | undefined) => {
32
64
  dom: HTMLElement;
33
65
  contentDOM?: HTMLElement;
34
66
  destroy?: () => void;
@@ -53,5 +85,5 @@ export type CustomInlineContentImplementation<T extends CustomInlineContentConfi
53
85
  } | undefined;
54
86
  runsBefore?: string[];
55
87
  };
56
- export declare function getInlineContentParseRules<C extends CustomInlineContentConfig>(config: C, customParseFunction?: CustomInlineContentImplementation<C, any>["parse"]): TagParseRule[];
88
+ export declare function getInlineContentParseRules<C extends CustomInlineContentConfig>(config: C, customParseFunction?: CustomInlineContentImplementation<C, any>["parse"], customParseContentFunction?: CustomInlineContentImplementation<C, any>["parseContent"]): TagParseRule[];
57
89
  export declare function createInlineContentSpec<T extends CustomInlineContentConfig, S extends StyleSchema>(inlineContentConfig: T, inlineContentImplementation: CustomInlineContentImplementation<T, S>): InlineContentSpec<T>;
@@ -1,4 +1,5 @@
1
1
  import { KeyboardShortcutCommand, Node } from "@tiptap/core";
2
+ import { Extension, ExtensionFactoryInstance } from "../../editor/BlockNoteExtension.js";
2
3
  import { PropSchema, Props } from "../propTypes.js";
3
4
  import { CustomInlineContentConfig, InlineContentImplementation, InlineContentSchemaFromSpecs, InlineContentSpec, InlineContentSpecs } from "./types.js";
4
5
  export declare function addInlineContentAttributes<IType extends string, PSchema extends PropSchema>(element: {
@@ -11,10 +12,10 @@ export declare function addInlineContentAttributes<IType extends string, PSchema
11
12
  export declare function addInlineContentKeyboardShortcuts<T extends CustomInlineContentConfig>(config: T): {
12
13
  [p: string]: KeyboardShortcutCommand;
13
14
  };
14
- export declare function createInternalInlineContentSpec<const T extends CustomInlineContentConfig>(config: T, implementation: InlineContentImplementation<NoInfer<T>>): InlineContentSpec<T>;
15
+ export declare function createInternalInlineContentSpec<const T extends CustomInlineContentConfig>(config: T, implementation: InlineContentImplementation<NoInfer<T>>, extensions?: (Extension | ExtensionFactoryInstance)[]): InlineContentSpec<T>;
15
16
  export declare function createInlineContentSpecFromTipTapNode<T extends Node, P extends PropSchema>(node: T, propSchema: P, implementation: Omit<InlineContentImplementation<CustomInlineContentConfig>, "node">): InlineContentSpec<{
16
17
  readonly type: T["name"];
17
18
  readonly propSchema: P;
18
- readonly content: "none" | "styled";
19
+ readonly content: "none" | "plain" | "styled";
19
20
  }>;
20
21
  export declare function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(specs: T): InlineContentSchemaFromSpecs<T>;
@@ -1,17 +1,35 @@
1
1
  import { Node } from "@tiptap/core";
2
2
  import { ViewMutationRecord } from "prosemirror-view";
3
- import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
4
3
  import { PropSchema, Props } from "../propTypes.js";
5
4
  import { StyleSchema, Styles } from "../styles/types.js";
5
+ import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
6
+ import { Extension, ExtensionFactoryInstance } from "../../editor/BlockNoteExtension.js";
6
7
  export type CustomInlineContentConfig = {
7
8
  type: string;
8
9
  content: "styled" | "none" | "plain";
9
10
  readonly propSchema: PropSchema;
10
11
  };
11
12
  export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
12
- export type InlineContentImplementation<T extends InlineContentConfig> = T extends "link" | "text" ? undefined : {
13
+ export type InlineContentImplementation<T extends InlineContentConfig> = T extends CustomInlineContentConfig ? {
13
14
  meta?: {
15
+ /**
16
+ * Whether the inline content is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.code} block
17
+ */
18
+ code?: boolean;
19
+ /**
20
+ * When {@link code} is `true`, this can syntax highlight the contents of the block with the result of this callback
21
+ */
22
+ highlight?(inlineContent: Pick<CustomInlineContentFromConfig<T, any>, "type" | "props">): string | undefined;
23
+ /**
24
+ * Whether the inline content is draggable
25
+ */
14
26
  draggable?: boolean;
27
+ /**
28
+ * Marks the inline content as rendering a preview with an editable
29
+ * source popup, driven by the editor-wide
30
+ * `SourceInlineContentWithPreviewExtension`.
31
+ */
32
+ hasPreview?: boolean;
15
33
  };
16
34
  node: Node;
17
35
  toExternalHTML?: (inlineContent: any, editor: BlockNoteEditor<any, any, any>) => {
@@ -25,13 +43,14 @@ export type InlineContentImplementation<T extends InlineContentConfig> = T exten
25
43
  destroy?: () => void;
26
44
  };
27
45
  runsBefore?: string[];
28
- };
46
+ } : undefined;
29
47
  export type InlineContentSchemaWithInlineContent<IType extends string, C extends InlineContentConfig> = {
30
48
  [k in IType]: C;
31
49
  };
32
50
  export type InlineContentSpec<T extends InlineContentConfig> = {
33
51
  config: T;
34
52
  implementation: InlineContentImplementation<T>;
53
+ extensions?: (Extension | ExtensionFactoryInstance)[];
35
54
  };
36
55
  export type InlineContentSchema = Record<string, InlineContentConfig>;
37
56
  export type InlineContentSpecs = {
@@ -1,4 +1,4 @@
1
- import { Store } from "@tanstack/store";
1
+ import { Store } from "../util/Store.js";
2
2
  /**
3
3
  * A collaborator of the document.
4
4
  */
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The value a {@link Listener} is called with when a {@link Store} updates.
3
+ */
4
+ export interface ListenerValue<T> {
5
+ readonly prevVal: T;
6
+ readonly currentVal: T;
7
+ }
8
+ /**
9
+ * A callback invoked when a {@link Store}'s state changes.
10
+ */
11
+ export type Listener<T> = (value: ListenerValue<T>) => void;
12
+ /**
13
+ * A new state, or a function deriving it from the previous state.
14
+ */
15
+ export type Updater<T> = T | ((prev: T) => T);
16
+ export interface StoreOptions<TState> {
17
+ /**
18
+ * Called after the state has been updated, before listeners are notified.
19
+ */
20
+ onUpdate?: (state: TState, prevState: TState) => void;
21
+ }
22
+ /**
23
+ * A minimal observable state container.
24
+ *
25
+ * Extensions expose one of these as their `store` so that both React (via
26
+ * `useExtensionState`) and vanilla consumers can read and subscribe to their state.
27
+ */
28
+ export declare class Store<TState> {
29
+ listeners: Set<Listener<TState>>;
30
+ state: TState;
31
+ prevState: TState;
32
+ options?: StoreOptions<TState>;
33
+ constructor(initialState: TState, options?: StoreOptions<TState>);
34
+ subscribe: (listener: Listener<TState>) => () => void;
35
+ /**
36
+ * Update the store state, either with a new state or a function deriving it from the
37
+ * previous one.
38
+ */
39
+ setState(updater: (prevState: TState) => TState): void;
40
+ setState(updater: TState): void;
41
+ /**
42
+ * @internal Only to be called by {@link flush}.
43
+ */
44
+ _notify(): void;
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -55,7 +55,7 @@ export declare const AttributionExtension: (options?: {
55
55
  } | undefined) => import("../../index.js").ExtensionFactoryInstance<{
56
56
  key: string;
57
57
  userStore: import("../../index.js").UserStore<import("../../index.js").User>;
58
- store: import("@tanstack/store").Store<AttributionTooltipState | undefined, (cb: AttributionTooltipState | undefined) => AttributionTooltipState | undefined>;
58
+ store: import("../../index.js").Store<AttributionTooltipState | undefined>;
59
59
  prosemirrorPlugins: Plugin<null>[];
60
60
  mount({ dom, root, signal }: {
61
61
  dom: HTMLElement;
@@ -47,7 +47,7 @@ export declare const DiffVersioningExtension: (options?: DiffVersioningExtension
47
47
  blockNoteExtensions: import("../../index.js").ExtensionFactoryInstance<{
48
48
  key: string;
49
49
  userStore: import("../../index.js").UserStore<User>;
50
- store: import("@tanstack/store").Store<import("./AttributionExtension.js").AttributionTooltipState | undefined, (cb: import("./AttributionExtension.js").AttributionTooltipState | undefined) => import("./AttributionExtension.js").AttributionTooltipState | undefined>;
50
+ store: import("../../index.js").Store<import("./AttributionExtension.js").AttributionTooltipState | undefined>;
51
51
  prosemirrorPlugins: import("prosemirror-state").Plugin<null>[];
52
52
  mount({ dom, root, signal }: {
53
53
  dom: HTMLElement;
@@ -1,11 +1,7 @@
1
1
  import { CollaborationOptions } from "./index.js";
2
2
  export declare const ForkYDocExtension: (options: CollaborationOptions) => import("../../index.js").ExtensionFactoryInstance<{
3
3
  readonly key: "yForkDoc";
4
- readonly store: import("@tanstack/store").Store<{
5
- isForked: boolean;
6
- }, (cb: {
7
- isForked: boolean;
8
- }) => {
4
+ readonly store: import("../../index.js").Store<{
9
5
  isForked: boolean;
10
6
  }>;
11
7
  /**
@@ -68,15 +68,7 @@ export declare const CollaborationExtension: (options: CollaborationOptions) =>
68
68
  readonly userStore: import("../../index.js").UserStore<import("../../index.js").User>;
69
69
  readonly blockNoteExtensions: (import("../../index.js").ExtensionFactoryInstance<{
70
70
  readonly key: "versioning";
71
- readonly store: import("@tanstack/store").Store<{
72
- snapshots: import("../../index.js").VersionSnapshot[];
73
- previewedSnapshotId?: string | typeof import("../../index.js").CURRENT_VERSION_ID;
74
- compareToSnapshotId?: string | typeof import("../../index.js").CURRENT_VERSION_ID;
75
- }, (cb: {
76
- snapshots: import("../../index.js").VersionSnapshot[];
77
- previewedSnapshotId?: string | typeof import("../../index.js").CURRENT_VERSION_ID;
78
- compareToSnapshotId?: string | typeof import("../../index.js").CURRENT_VERSION_ID;
79
- }) => {
71
+ readonly store: import("../../index.js").Store<{
80
72
  snapshots: import("../../index.js").VersionSnapshot[];
81
73
  previewedSnapshotId?: string | typeof import("../../index.js").CURRENT_VERSION_ID;
82
74
  compareToSnapshotId?: string | typeof import("../../index.js").CURRENT_VERSION_ID;
@@ -106,7 +98,7 @@ export declare const CollaborationExtension: (options: CollaborationOptions) =>
106
98
  }> | import("../../index.js").ExtensionFactoryInstance<{
107
99
  key: string;
108
100
  userStore: import("../../index.js").UserStore<import("../../index.js").User>;
109
- store: import("@tanstack/store").Store<import("./AttributionExtension.js").AttributionTooltipState | undefined, (cb: import("./AttributionExtension.js").AttributionTooltipState | undefined) => import("./AttributionExtension.js").AttributionTooltipState | undefined>;
101
+ store: import("../../index.js").Store<import("./AttributionExtension.js").AttributionTooltipState | undefined>;
110
102
  prosemirrorPlugins: import("prosemirror-state").Plugin<null>[];
111
103
  mount({ dom, root, signal }: {
112
104
  dom: HTMLElement;
@@ -1,11 +1,7 @@
1
1
  import type { CollaborationOptions } from "./index.js";
2
2
  export declare const ForkYDocExtension: (options: CollaborationOptions) => import("../../index.js").ExtensionFactoryInstance<{
3
3
  readonly key: "yForkDoc";
4
- readonly store: import("@tanstack/store").Store<{
5
- isForked: boolean;
6
- }, (cb: {
7
- isForked: boolean;
8
- }) => {
4
+ readonly store: import("../../index.js").Store<{
9
5
  isForked: boolean;
10
6
  }>;
11
7
  /**
@@ -35,11 +35,7 @@ export declare const CollaborationExtension: (options: CollaborationOptions) =>
35
35
  readonly key: "fixUpSchema";
36
36
  }>, import("../..").ExtensionFactoryInstance<{
37
37
  readonly key: "yForkDoc";
38
- readonly store: import("@tanstack/store").Store<{
39
- isForked: boolean;
40
- }, (cb: {
41
- isForked: boolean;
42
- }) => {
38
+ readonly store: import("../..").Store<{
43
39
  isForked: boolean;
44
40
  }>;
45
41
  readonly fork: ({ initialUpdate, }?: {
@@ -1,38 +0,0 @@
1
- import { getExtensionField as e } from "@tiptap/core";
2
- import { Store as t } from "@tanstack/store";
3
- //#region src/schema/markGroups.ts
4
- var n = "annotation";
5
- function r(t) {
6
- return t && t.options.extensions.some((t) => {
7
- if (t.type !== "mark") return !1;
8
- let n = e(t, "group");
9
- return typeof n == "string" && n.split(" ").includes("annotation");
10
- }) ? n : "";
11
- }
12
- //#endregion
13
- //#region src/editor/managers/ExtensionManager/symbol.ts
14
- var i = Symbol("originalFactory");
15
- //#endregion
16
- //#region src/editor/BlockNoteExtension.ts
17
- function a(e) {
18
- if (typeof e == "object" && "key" in e) return function t() {
19
- return e[i] = t, e;
20
- };
21
- if (typeof e != "function") throw Error("factory must be a function");
22
- return function t(n) {
23
- return (r) => {
24
- let a = e({
25
- editor: r.editor,
26
- options: n
27
- });
28
- return a[i] = t, a;
29
- };
30
- };
31
- }
32
- function o(e, n) {
33
- return new t(e, n);
34
- }
35
- //#endregion
36
- export { r as a, n as i, o as n, i as r, a as t };
37
-
38
- //# sourceMappingURL=BlockNoteExtension-B_IEJHS8.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlockNoteExtension-B_IEJHS8.js","names":[],"sources":["../src/schema/markGroups.ts","../src/editor/managers/ExtensionManager/symbol.ts","../src/editor/BlockNoteExtension.ts"],"sourcesContent":["import { Editor, getExtensionField } from \"@tiptap/core\";\n\n/**\n * ProseMirror mark group for \"non-formatting\" marks: comments and the\n * suggestion/diff marks (the AI `insertion`/`deletion`/`modification` marks and\n * the Yjs `y-attributed-*` marks). These annotate content without representing\n * inline formatting and are ignored by BlockNote's content model\n * (`blocknoteIgnore`).\n *\n * They are the only marks allowed on `\"plain\"` blocks (e.g. code blocks), which\n * otherwise disallow all formatting marks. A block references this group rather\n * than the individual marks because each of them comes from an optional\n * extension (comments, AI suggestions, Yjs attribution) and so is only present\n * when that extension is configured.\n */\nexport const NON_FORMATTING_MARK_GROUP = \"annotation\";\n\n/**\n * The `marks` field value for `\"plain\"` blocks (e.g. code blocks), which hold\n * unstyled text and so disallow formatting marks but still allow the\n * non-formatting ones.\n *\n * Every mark in {@link NON_FORMATTING_MARK_GROUP} comes from an optional\n * extension, so a node spec that referenced the group unconditionally would make\n * ProseMirror throw \"Unknown mark type: 'annotation'\" while building the schema\n * of an editor that has none of them registered — an empty mark group is an\n * unknown reference just like a missing mark is. (This mirrors `suggestionMarks`\n * for the block-level suggestion group.)\n *\n * Returns the group name (which ProseMirror expands to every mark in it) when at\n * least one such mark is registered, or `\"\"` otherwise. Evaluated at\n * schema-build time, where the tiptap editor's fully-flattened extension list is\n * available on `this.editor`.\n */\nexport function nonFormattingMarks(editor: Editor | undefined): string {\n if (!editor) {\n return \"\";\n }\n const hasNonFormattingMark = editor.options.extensions.some((extension) => {\n if (extension.type !== \"mark\") {\n return false;\n }\n const group = getExtensionField(extension, \"group\") as string | undefined;\n return (\n typeof group === \"string\" &&\n group.split(\" \").includes(NON_FORMATTING_MARK_GROUP)\n );\n });\n return hasNonFormattingMark ? NON_FORMATTING_MARK_GROUP : \"\";\n}\n","/**\n * Symbol used to track the original factory function for extensions.\n * This allows us to retrieve the original factory for comparison and other operations.\n */\nexport const originalFactorySymbol = Symbol(\"originalFactory\");\n","import { Store, StoreOptions } from \"@tanstack/store\";\nimport { type AnyExtension } from \"@tiptap/core\";\nimport type { Plugin as ProsemirrorPlugin } from \"prosemirror-state\";\nimport type { PartialBlockNoDefaults } from \"../schema/index.js\";\nimport type { BlockNoteEditor } from \"./BlockNoteEditor.js\";\nimport { originalFactorySymbol } from \"./managers/ExtensionManager/symbol.js\";\n\n/**\n * This function is called when the extension is destroyed.\n */\ntype OnDestroy = () => void;\n\n/**\n * Describes a BlockNote extension.\n */\nexport interface Extension<State = any, Key extends string = string> {\n /**\n * The unique identifier for the extension.\n */\n readonly key: Key;\n\n /**\n * Triggered when the extension is mounted to the editor.\n */\n readonly mount?: (ctx: {\n /**\n * The DOM element that the editor is mounted to.\n */\n dom: HTMLElement;\n /**\n * The root document of the {@link document} that the editor is mounted to.\n */\n root: Document | ShadowRoot;\n /**\n * An {@link AbortSignal} that will be aborted when the extension is destroyed.\n */\n signal: AbortSignal;\n }) => void | OnDestroy;\n\n /**\n * The store for the extension.\n */\n readonly store?: Store<State>;\n\n /**\n * Declares what {@link Extension}s that this extension depends on.\n */\n readonly runsBefore?: ReadonlyArray<string>;\n\n /**\n * Input rules for a block: An input rule is what is used to replace text in a block when a regular expression match is found.\n * As an example, typing `#` in a paragraph block will trigger an input rule to replace the text with a heading block.\n */\n readonly inputRules?: ReadonlyArray<InputRule>;\n\n /**\n * A mapping of a keyboard shortcut to a function that will be called when the shortcut is pressed\n *\n * The keys are in the format:\n * - Key names may be strings like `Shift-Ctrl-Enter`—a key identifier prefixed with zero or more modifiers\n * - Key identifiers are based on the strings that can appear in KeyEvent.key\n * - Use lowercase letters to refer to letter keys (or uppercase letters if you want shift to be held)\n * - You may use `Space` as an alias for the \" \" name\n * - Modifiers can be given in any order: `Shift-` (or `s-`), `Alt-` (or `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or `Meta-`)\n * - For characters that are created by holding shift, the Shift- prefix is implied, and should not be added explicitly\n * - You can use Mod- as a shorthand for Cmd- on Mac and Ctrl- on other platforms\n *\n * @example\n * ```typescript\n * keyboardShortcuts: {\n * \"Mod-Enter\": (ctx) => { return true; },\n * \"Shift-Ctrl-Space\": (ctx) => { return true; },\n * \"a\": (ctx) => { return true; },\n * \"Space\": (ctx) => { return true; }\n * }\n * ```\n */\n readonly keyboardShortcuts?: Record<\n string,\n (ctx: { editor: BlockNoteEditor<any, any, any> }) => boolean\n >;\n\n /**\n * Add additional prosemirror plugins to the editor.\n */\n readonly prosemirrorPlugins?: ReadonlyArray<ProsemirrorPlugin>;\n\n /**\n * Add additional tiptap extensions to the editor.\n */\n readonly tiptapExtensions?: ReadonlyArray<AnyExtension>;\n\n /**\n * Add additional BlockNote extensions to the editor.\n */\n readonly blockNoteExtensions?: ReadonlyArray<ExtensionFactoryInstance>;\n}\n\n/**\n * An input rule is what is used to replace text in a block when a regular expression match is found.\n * As an example, typing `#` in a paragraph block will trigger an input rule to replace the text with a heading block.\n */\ntype InputRule = {\n /**\n * The regex to match when to trigger the input rule\n */\n find: RegExp;\n /**\n * The function to call when the input rule is matched\n * @returns undefined if the input rule should not be triggered, or an object with the type and props to update the block\n */\n replace: (props: {\n /**\n * The result of the regex match\n */\n match: RegExpMatchArray;\n // TODO this will be a Point, when we have the Location API\n /**\n * The range of the text that was matched\n */\n range: { from: number; to: number };\n /**\n * The editor instance\n */\n editor: BlockNoteEditor<any, any, any>;\n }) => undefined | PartialBlockNoDefaults<any, any, any>;\n};\n\n/**\n * These are the arguments that are passed to an {@link ExtensionFactoryInstance}.\n */\nexport interface ExtensionOptions<\n Options extends Record<string, any> | undefined =\n | Record<string, any>\n | undefined,\n> {\n options: Options;\n editor: BlockNoteEditor<any, any, any>;\n}\n\n// a type that maps the extension key to the return type of the extension factory\nexport type ExtensionMap<T extends ReadonlyArray<ExtensionFactoryInstance>> = {\n [K in T[number] extends ExtensionFactoryInstance<infer Ext>\n ? Ext[\"key\"]\n : never]: T[number] extends ExtensionFactoryInstance<infer Ext>\n ? Ext\n : never;\n};\n\n/**\n * This is a type that represents the function which will actually create the extension.\n * It requires the editor instance to be passed in, but will already have the options applied automatically.\n *\n * @note Only the BlockNoteEditor should instantiate this function, not the user. Look at {@link createExtension} for user-facing functions.\n */\nexport type ExtensionFactoryInstance<\n Ext extends Extension<any, any> = Extension<any, any>,\n> = (ctx: Omit<ExtensionOptions<any>, \"options\">) => Ext;\n\n/**\n * This is the return type of the {@link createExtension} function.\n * It is a function that can be invoked with the extension's options to create a new extension factory.\n */\nexport type ExtensionFactory<\n State = any,\n Key extends string = string,\n Factory extends (ctx: any) => Extension<State, Key> = (\n ctx: ExtensionOptions<any>,\n ) => Extension<State, Key>,\n> =\n Parameters<Factory>[0] extends ExtensionOptions<infer Options>\n ? undefined extends Options\n ? (\n options?: Exclude<Options, undefined>,\n ) => ExtensionFactoryInstance<ReturnType<Factory>>\n : (options: Options) => ExtensionFactoryInstance<ReturnType<Factory>>\n : () => ExtensionFactoryInstance<ReturnType<Factory>>;\n\n/**\n * Constructs a BlockNote {@link ExtensionFactory} from a factory function or object\n */\n// This overload is for `createExtension({ key: \"test\", ... })`\nexport function createExtension<\n const State = any,\n const Key extends string = string,\n const Ext extends Extension<State, Key> = Extension<State, Key>,\n>(factory: Ext): ExtensionFactoryInstance<Ext>;\n// This overload is for `createExtension(({editor, options}) => ({ key: \"test\", ... }))`\nexport function createExtension<\n const State = any,\n const Options extends Record<string, any> | undefined = any,\n const Key extends string = string,\n const Factory extends (ctx: any) => Extension<State, Key> = (\n ctx: ExtensionOptions<Options>,\n ) => Extension<State, Key>,\n>(factory: Factory): ExtensionFactory<State, Key, Factory>;\n// This overload is for both of the above overloads as it is the implementation of the function\nexport function createExtension<\n const State = any,\n const Options extends Record<string, any> | undefined = any,\n const Key extends string = string,\n const Factory extends\n | Extension<State, Key>\n | ((ctx: any) => Extension<State, Key>) = (\n ctx: ExtensionOptions<Options>,\n ) => Extension<State, Key>,\n>(\n factory: Factory,\n): Factory extends Extension<State, Key>\n ? ExtensionFactoryInstance<Factory>\n : Factory extends (ctx: any) => Extension<State, Key>\n ? ExtensionFactory<State, Key, Factory>\n : never {\n if (typeof factory === \"object\" && \"key\" in factory) {\n return function factoryFn() {\n (factory as any)[originalFactorySymbol] = factoryFn;\n return factory;\n } as any;\n }\n\n if (typeof factory !== \"function\") {\n throw new Error(\"factory must be a function\");\n }\n\n return function factoryFn(options: Options) {\n return (ctx: { editor: BlockNoteEditor<any, any, any> }) => {\n const extension = factory({ editor: ctx.editor, options });\n // We stick a symbol onto the extension to allow us to retrieve the original factory for comparison later.\n // This enables us to do things like: `editor.getExtension(YSync).prosemirrorPlugins`\n (extension as any)[originalFactorySymbol] = factoryFn;\n return extension;\n };\n } as any;\n}\n\nexport function createStore<T = any>(\n initialState: T,\n options?: StoreOptions<T>,\n): Store<T> {\n return new Store(initialState, options);\n}\n"],"mappings":";;;AAeA,IAAa,IAA4B;AAmBzC,SAAgB,EAAmB,GAAoC;CAcrE,OAbK,KAGwB,EAAO,QAAQ,WAAW,MAAM,MAAc;EACzE,IAAI,EAAU,SAAS,QACrB,OAAO;EAET,IAAM,IAAQ,EAAkB,GAAW,OAAO;EAClD,OACE,OAAO,KAAU,YACjB,EAAM,MAAM,GAAG,EAAE,SAAA,YAAkC;CAEvD,CACO,IAAuB,IAA4B;AAC5D;;;AC7CA,IAAa,IAAwB,OAAO,iBAAiB;;;ACiM7D,SAAgB,EAUd,GAKU;CACV,IAAI,OAAO,KAAY,YAAY,SAAS,GAC1C,OAAO,SAAS,IAAY;EAE1B,OADA,EAAiB,KAAyB,GACnC;CACT;CAGF,IAAI,OAAO,KAAY,YACrB,MAAU,MAAM,4BAA4B;CAG9C,OAAO,SAAS,EAAU,GAAkB;EAC1C,QAAQ,MAAoD;GAC1D,IAAM,IAAY,EAAQ;IAAE,QAAQ,EAAI;IAAQ;GAAQ,CAAC;GAIzD,OADA,EAAmB,KAAyB,GACrC;EACT;CACF;AACF;AAEA,SAAgB,EACd,GACA,GACU;CACV,OAAO,IAAI,EAAM,GAAc,CAAO;AACxC"}
@@ -1,2 +0,0 @@
1
- let e=require("@tiptap/core"),t=require("@tanstack/store");var n=`annotation`;function r(t){return t&&t.options.extensions.some(t=>{if(t.type!==`mark`)return!1;let n=(0,e.getExtensionField)(t,`group`);return typeof n==`string`&&n.split(` `).includes(`annotation`)})?n:``}var i=Symbol(`originalFactory`);function a(e){if(typeof e==`object`&&`key`in e)return function t(){return e[i]=t,e};if(typeof e!=`function`)throw Error(`factory must be a function`);return function t(n){return r=>{let a=e({editor:r.editor,options:n});return a[i]=t,a}}}function o(e,n){return new t.Store(e,n)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
2
- //# sourceMappingURL=BlockNoteExtension-M0znTzxP.cjs.map