@blocknote/core 0.38.0 → 0.39.1-capitol
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockNoteSchema-Bsa_tSAC.cjs +11 -0
- package/dist/BlockNoteSchema-Bsa_tSAC.cjs.map +1 -0
- package/dist/BlockNoteSchema-CZez1nQf.js +4244 -0
- package/dist/BlockNoteSchema-CZez1nQf.js.map +1 -0
- package/dist/blocknote.cjs +4 -12
- package/dist/blocknote.cjs.map +1 -1
- package/dist/blocknote.js +3401 -7305
- package/dist/blocknote.js.map +1 -1
- package/dist/blocks.cjs +2 -0
- package/dist/blocks.cjs.map +1 -0
- package/dist/blocks.js +71 -0
- package/dist/blocks.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/package.json +19 -17
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +2 -2
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.ts +34 -25
- package/src/api/blockManipulation/setupTestEnv.ts +0 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +6 -10
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/clipboard/toClipboard/copyExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +128 -28
- package/src/api/exporters/html/util/serializeBlocksInternalHTML.ts +101 -41
- package/src/api/pmUtil.ts +1 -1
- package/src/api/positionMapping.test.ts +58 -15
- package/src/api/positionMapping.ts +2 -4
- package/src/blocks/Audio/block.ts +174 -0
- package/src/blocks/BlockNoteSchema.ts +59 -0
- package/src/blocks/Code/block.ts +299 -0
- package/src/blocks/File/block.ts +98 -0
- package/src/blocks/{FileBlockContent → File}/helpers/render/createAddFileButton.ts +5 -2
- package/src/blocks/{FileBlockContent → File}/helpers/render/createFileBlockWrapper.ts +15 -6
- package/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.ts +15 -2
- package/src/blocks/{FileBlockContent → File}/helpers/render/createResizableFileBlockWrapper.ts +21 -2
- package/src/blocks/Heading/block.ts +138 -0
- package/src/blocks/Image/block.ts +190 -0
- package/src/blocks/ListItem/BulletListItem/block.ts +116 -0
- package/src/blocks/ListItem/CheckListItem/block.ts +175 -0
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +173 -0
- package/src/blocks/ListItem/NumberedListItem/block.ts +133 -0
- package/src/blocks/ListItem/ToggleListItem/block.ts +78 -0
- package/src/blocks/PageBreak/block.ts +72 -0
- package/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.ts +9 -7
- package/src/blocks/Paragraph/block.ts +80 -0
- package/src/blocks/Quote/block.ts +90 -0
- package/src/blocks/{TableBlockContent/TableBlockContent.ts → Table/block.ts} +169 -51
- package/src/blocks/ToggleWrapper/createToggleWrapper.ts +1 -1
- package/src/blocks/Video/block.ts +143 -0
- package/src/blocks/defaultBlockHelpers.ts +2 -2
- package/src/blocks/defaultBlockTypeGuards.ts +143 -174
- package/src/blocks/defaultBlocks.ts +107 -35
- package/src/blocks/defaultProps.ts +145 -4
- package/src/blocks/index.ts +26 -0
- package/src/blocks/utils/listItemEnterHandler.ts +42 -0
- package/src/editor/Block.css +54 -18
- package/src/editor/BlockNoteEditor.ts +256 -211
- package/src/editor/BlockNoteExtension.ts +92 -0
- package/src/editor/BlockNoteExtensions.ts +18 -17
- package/src/editor/defaultColors.ts +2 -2
- package/src/exporter/Exporter.ts +1 -1
- package/src/exporter/mapping.ts +1 -1
- package/src/extensions/BackgroundColor/BackgroundColorExtension.ts +3 -20
- package/src/extensions/BackgroundColor/BackgroundColorMark.ts +6 -8
- package/src/extensions/BlockChange/BlockChangePlugin.ts +2 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor-forked.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-editor.json +2 -2
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap-forked.html +1 -1
- package/src/extensions/Collaboration/__snapshots__/fork-yjs-snap.html +1 -1
- package/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.ts +52 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/index.ts +4 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.ts +4 -0
- package/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.ts +78 -0
- package/src/extensions/Comments/CommentsPlugin.ts +1 -1
- package/src/extensions/FilePanel/FilePanelPlugin.ts +5 -10
- package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +1 -1
- package/src/extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +4 -3
- package/src/extensions/Placeholder/PlaceholderPlugin.ts +6 -6
- package/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts +1 -23
- package/src/extensions/SideMenu/SideMenuPlugin.ts +1 -3
- package/src/extensions/SideMenu/dragging.ts +2 -2
- package/src/extensions/SuggestionMenu/SuggestionPlugin.ts +4 -7
- package/src/extensions/SuggestionMenu/getDefaultEmojiPickerItems.ts +6 -2
- package/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +24 -17
- package/src/extensions/TableHandles/TableHandlesPlugin.ts +8 -8
- package/src/extensions/TextAlignment/TextAlignmentExtension.ts +5 -11
- package/src/extensions/TextColor/TextColorExtension.ts +3 -17
- package/src/extensions/TextColor/TextColorMark.ts +4 -9
- package/src/extensions/UniqueID/UniqueID.ts +6 -13
- package/src/index.ts +2 -28
- package/src/schema/blocks/createSpec.ts +342 -169
- package/src/schema/blocks/internal.ts +77 -138
- package/src/schema/blocks/types.ts +264 -94
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/createSpec.ts +99 -21
- package/src/schema/inlineContent/internal.ts +16 -7
- package/src/schema/inlineContent/types.ts +24 -2
- package/src/schema/propTypes.ts +15 -9
- package/src/schema/schema.ts +209 -0
- package/src/schema/styles/createSpec.ts +79 -31
- package/src/schema/styles/internal.ts +61 -2
- package/src/schema/styles/types.ts +17 -3
- package/src/util/topo-sort.test.ts +125 -0
- package/src/util/topo-sort.ts +160 -0
- package/types/src/api/blockManipulation/commands/splitBlock/splitBlock.d.ts +2 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/blockManipulation/setupTestEnv.d.ts +29 -543
- package/types/src/api/exporters/html/util/serializeBlocksExternalHTML.d.ts +1 -1
- package/types/src/api/exporters/html/util/serializeBlocksInternalHTML.d.ts +1 -1
- package/types/src/api/exporters/markdown/util/convertVideoToMarkdownRehypePlugin.d.ts +2 -0
- package/types/src/api/exporters/markdown/util/removeUnderlinesRehypePlugin.d.ts +6 -0
- package/types/src/api/pmUtil.d.ts +1 -1
- package/types/src/blocks/Audio/block.d.ts +58 -0
- package/types/src/blocks/BlockNoteSchema.d.ts +18 -0
- package/types/src/blocks/{CodeBlockContent/CodeBlockContent.d.ts → Code/block.d.ts} +25 -26
- package/types/src/blocks/Code/shiki.d.ts +4 -0
- package/types/src/blocks/Divider/block.d.ts +3 -0
- package/types/src/blocks/File/block.d.ts +37 -0
- package/types/src/blocks/File/helpers/render/createAddFileButton.d.ts +6 -0
- package/types/src/blocks/File/helpers/render/createFileBlockWrapper.d.ts +25 -0
- package/types/src/blocks/{FileBlockContent → File}/helpers/render/createFileNameWithIcon.d.ts +6 -2
- package/types/src/blocks/File/helpers/render/createResizableFileBlockWrapper.d.ts +31 -0
- package/types/src/blocks/Heading/block.d.ts +71 -0
- package/types/src/blocks/Image/block.d.ts +102 -0
- package/types/src/blocks/ListItem/BulletListItem/block.d.ts +25 -0
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +33 -0
- package/types/src/blocks/ListItem/NumberedListItem/IndexingPlugin.d.ts +8 -0
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +33 -0
- package/types/src/blocks/ListItem/ToggleListItem/block.d.ts +25 -0
- package/types/src/blocks/PageBreak/block.d.ts +11 -0
- package/types/src/blocks/{PageBreakBlockContent → PageBreak}/getPageBreakSlashMenuItems.d.ts +4 -2
- package/types/src/blocks/Paragraph/block.d.ts +25 -0
- package/types/src/blocks/Quote/block.d.ts +17 -0
- package/types/src/blocks/Table/block.d.ts +21 -0
- package/types/src/blocks/Video/block.d.ts +67 -0
- package/types/src/blocks/defaultBlockHelpers.d.ts +1 -1
- package/types/src/blocks/defaultBlockTypeGuards.d.ts +15 -36
- package/types/src/blocks/defaultBlocks.d.ts +221 -1060
- package/types/src/blocks/defaultProps.d.ts +17 -1
- package/types/src/blocks/index.d.ts +24 -0
- package/types/src/blocks/utils/listItemEnterHandler.d.ts +2 -0
- package/types/src/editor/BlockNoteEditor.d.ts +36 -67
- package/types/src/editor/BlockNoteExtension.d.ts +67 -0
- package/types/src/editor/BlockNoteExtensions.d.ts +1 -1
- package/types/src/editor/defaultColors.d.ts +8 -76
- package/types/src/editor/managers/BlockManager.d.ts +114 -0
- package/types/src/editor/managers/CollaborationManager.d.ts +115 -0
- package/types/src/editor/managers/EventManager.d.ts +58 -0
- package/types/src/editor/managers/ExportManager.d.ts +64 -0
- package/types/src/editor/managers/ExtensionManager.d.ts +68 -0
- package/types/src/editor/managers/SelectionManager.d.ts +54 -0
- package/types/src/editor/managers/StateManager.d.ts +115 -0
- package/types/src/editor/managers/StyleManager.d.ts +48 -0
- package/types/src/editor/managers/index.d.ts +8 -0
- package/types/src/exporter/Exporter.d.ts +1 -1
- package/types/src/exporter/mapping.d.ts +1 -1
- package/types/src/extensions/BackgroundColor/BackgroundColorMark.d.ts +4 -1
- package/types/src/extensions/Collaboration/schemaMigration/SchemaMigrationPlugin.d.ts +7 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/index.d.ts +3 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/migrationRule.d.ts +3 -0
- package/types/src/extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.d.ts +2 -0
- package/types/src/extensions/Comments/CommentsPlugin.d.ts +1 -1
- package/types/src/extensions/FilePanel/FilePanelPlugin.d.ts +4 -4
- package/types/src/extensions/TextColor/TextColorMark.d.ts +4 -1
- package/types/src/index.d.ts +2 -25
- package/types/src/schema/blocks/createSpec.d.ts +16 -36
- package/types/src/schema/blocks/internal.d.ts +11 -33
- package/types/src/schema/blocks/types.d.ts +181 -57
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/createSpec.d.ts +36 -2
- package/types/src/schema/inlineContent/internal.d.ts +7 -15
- package/types/src/schema/inlineContent/types.d.ts +15 -1
- package/types/src/schema/propTypes.d.ts +4 -4
- package/types/src/schema/schema.d.ts +40 -0
- package/types/src/schema/styles/createSpec.d.ts +6 -4
- package/types/src/schema/styles/internal.d.ts +6 -3
- package/types/src/schema/styles/types.d.ts +11 -2
- package/types/src/util/topo-sort.d.ts +18 -0
- package/types/src/util/topo-sort.test.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/blocks/AudioBlockContent/AudioBlockContent.ts +0 -144
- package/src/blocks/CodeBlockContent/CodeBlockContent.ts +0 -445
- package/src/blocks/FileBlockContent/FileBlockContent.ts +0 -100
- package/src/blocks/HeadingBlockContent/HeadingBlockContent.ts +0 -159
- package/src/blocks/ImageBlockContent/ImageBlockContent.ts +0 -159
- package/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.ts +0 -134
- package/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.ts +0 -299
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.ts +0 -86
- package/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.ts +0 -172
- package/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.ts +0 -104
- package/src/blocks/PageBreakBlockContent/PageBreakBlockContent.ts +0 -49
- package/src/blocks/PageBreakBlockContent/schema.ts +0 -40
- package/src/blocks/ParagraphBlockContent/ParagraphBlockContent.ts +0 -78
- package/src/blocks/QuoteBlockContent/QuoteBlockContent.ts +0 -121
- package/src/blocks/VideoBlockContent/VideoBlockContent.ts +0 -158
- package/src/editor/BlockNoteSchema.ts +0 -107
- package/src/editor/BlockNoteTipTapEditor.ts +0 -335
- package/types/src/blocks/AudioBlockContent/AudioBlockContent.d.ts +0 -99
- package/types/src/blocks/FileBlockContent/FileBlockContent.d.ts +0 -90
- package/types/src/blocks/FileBlockContent/helpers/render/createAddFileButton.d.ts +0 -6
- package/types/src/blocks/FileBlockContent/helpers/render/createFileBlockWrapper.d.ts +0 -9
- package/types/src/blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.d.ts +0 -9
- package/types/src/blocks/HeadingBlockContent/HeadingBlockContent.d.ts +0 -67
- package/types/src/blocks/ImageBlockContent/ImageBlockContent.d.ts +0 -131
- package/types/src/blocks/ListItemBlockContent/BulletListItemBlockContent/BulletListItemBlockContent.d.ts +0 -46
- package/types/src/blocks/ListItemBlockContent/CheckListItemBlockContent/CheckListItemBlockContent.d.ts +0 -55
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListIndexingPlugin.d.ts +0 -2
- package/types/src/blocks/ListItemBlockContent/NumberedListItemBlockContent/NumberedListItemBlockContent.d.ts +0 -58
- package/types/src/blocks/ListItemBlockContent/ToggleListItemBlockContent/ToggleListItemBlockContent.d.ts +0 -46
- package/types/src/blocks/PageBreakBlockContent/PageBreakBlockContent.d.ts +0 -31
- package/types/src/blocks/PageBreakBlockContent/schema.d.ts +0 -86
- package/types/src/blocks/ParagraphBlockContent/ParagraphBlockContent.d.ts +0 -52
- package/types/src/blocks/QuoteBlockContent/QuoteBlockContent.d.ts +0 -52
- package/types/src/blocks/TableBlockContent/TableBlockContent.d.ts +0 -39
- package/types/src/blocks/VideoBlockContent/VideoBlockContent.d.ts +0 -131
- package/types/src/editor/BlockNoteSchema.d.ts +0 -34
- package/types/src/editor/BlockNoteTipTapEditor.d.ts +0 -43
- /package/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.ts +0 -0
- /package/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.ts +0 -0
- /package/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.ts +0 -0
- /package/src/blocks/{ImageBlockContent → Image}/parseImageElement.ts +0 -0
- /package/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.ts +0 -0
- /package/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.ts +0 -0
- /package/src/blocks/{TableBlockContent → Table}/TableExtension.ts +0 -0
- /package/src/blocks/{VideoBlockContent → Video}/parseVideoElement.ts +0 -0
- /package/types/src/blocks/{AudioBlockContent → Audio}/parseAudioElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseEmbedElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/parse/parseFigureElement.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createFigureWithCaption.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File}/helpers/toExternalHTML/createLinkWithCaption.d.ts +0 -0
- /package/types/src/blocks/{FileBlockContent → File/helpers}/uploadToTmpFilesDotOrg_DEV_ONLY.d.ts +0 -0
- /package/types/src/blocks/{ImageBlockContent → Image}/parseImageElement.d.ts +0 -0
- /package/types/src/blocks/{ListItemBlockContent → ListItem}/ListItemKeyboardShortcuts.d.ts +0 -0
- /package/types/src/blocks/{ListItemBlockContent → ListItem}/getListItemContent.d.ts +0 -0
- /package/types/src/blocks/{TableBlockContent → Table}/TableExtension.d.ts +0 -0
- /package/types/src/blocks/{VideoBlockContent → Video}/parseVideoElement.d.ts +0 -0
package/types/src/index.d.ts
CHANGED
|
@@ -7,33 +7,10 @@ export * from "./api/getBlockInfoFromPos.js";
|
|
|
7
7
|
export * from "./api/getBlocksChangedByTransaction.js";
|
|
8
8
|
export * from "./api/nodeUtil.js";
|
|
9
9
|
export * from "./api/pmUtil.js";
|
|
10
|
-
export * from "./blocks/
|
|
11
|
-
export * from "./blocks/CodeBlockContent/CodeBlockContent.js";
|
|
12
|
-
export * from "./blocks/defaultBlockHelpers.js";
|
|
13
|
-
export * from "./blocks/defaultBlocks.js";
|
|
14
|
-
export * from "./blocks/defaultBlockTypeGuards.js";
|
|
15
|
-
export * from "./blocks/defaultProps.js";
|
|
16
|
-
export * from "./blocks/FileBlockContent/FileBlockContent.js";
|
|
17
|
-
export * from "./blocks/FileBlockContent/helpers/parse/parseEmbedElement.js";
|
|
18
|
-
export * from "./blocks/FileBlockContent/helpers/parse/parseFigureElement.js";
|
|
19
|
-
export * from "./blocks/FileBlockContent/helpers/render/createAddFileButton.js";
|
|
20
|
-
export * from "./blocks/FileBlockContent/helpers/render/createFileBlockWrapper.js";
|
|
21
|
-
export * from "./blocks/FileBlockContent/helpers/render/createFileNameWithIcon.js";
|
|
22
|
-
export * from "./blocks/FileBlockContent/helpers/render/createResizableFileBlockWrapper.js";
|
|
23
|
-
export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createFigureWithCaption.js";
|
|
24
|
-
export * from "./blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js";
|
|
25
|
-
export * from "./blocks/FileBlockContent/uploadToTmpFilesDotOrg_DEV_ONLY.js";
|
|
26
|
-
export * from "./blocks/ImageBlockContent/ImageBlockContent.js";
|
|
27
|
-
export * from "./blocks/PageBreakBlockContent/getPageBreakSlashMenuItems.js";
|
|
28
|
-
export * from "./blocks/PageBreakBlockContent/PageBreakBlockContent.js";
|
|
29
|
-
export * from "./blocks/PageBreakBlockContent/schema.js";
|
|
30
|
-
export * from "./blocks/ToggleWrapper/createToggleWrapper.js";
|
|
31
|
-
export { EMPTY_CELL_HEIGHT, EMPTY_CELL_WIDTH, } from "./blocks/TableBlockContent/TableExtension.js";
|
|
32
|
-
export * from "./blocks/VideoBlockContent/VideoBlockContent.js";
|
|
10
|
+
export * from "./blocks/index.js";
|
|
33
11
|
export * from "./editor/BlockNoteEditor.js";
|
|
34
12
|
export * from "./editor/BlockNoteExtension.js";
|
|
35
13
|
export * from "./editor/BlockNoteExtensions.js";
|
|
36
|
-
export * from "./editor/BlockNoteSchema.js";
|
|
37
14
|
export * from "./editor/defaultColors.js";
|
|
38
15
|
export * from "./editor/selectionTypes.js";
|
|
39
16
|
export * from "./exporter/index.js";
|
|
@@ -56,7 +33,7 @@ export * from "./util/combineByGroup.js";
|
|
|
56
33
|
export * from "./util/string.js";
|
|
57
34
|
export * from "./util/table.js";
|
|
58
35
|
export * from "./util/typescript.js";
|
|
59
|
-
export type { CodeBlockOptions } from "./blocks/
|
|
36
|
+
export type { CodeBlockOptions } from "./blocks/Code/block.js";
|
|
60
37
|
export { assertEmpty, UnreachableCaseError } from "./util/typescript.js";
|
|
61
38
|
export * from "./util/EventEmitter.js";
|
|
62
39
|
export { selectedFragmentToHTML } from "./api/clipboard/toClipboard/copyExtension.js";
|
|
@@ -1,39 +1,19 @@
|
|
|
1
1
|
import { Editor } from "@tiptap/core";
|
|
2
2
|
import { TagParseRule } from "@tiptap/pm/model";
|
|
3
|
-
import { NodeView
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { BlockConfig, BlockFromConfig, BlockSchemaWithBlock, PartialBlockFromConfig } from "./types.js";
|
|
8
|
-
export type CustomBlockConfig = BlockConfig & {
|
|
9
|
-
content: "inline" | "none";
|
|
10
|
-
};
|
|
11
|
-
export type CustomBlockImplementation<T extends CustomBlockConfig, I extends InlineContentSchema, S extends StyleSchema> = {
|
|
12
|
-
render: (
|
|
13
|
-
/**
|
|
14
|
-
* The custom block to render
|
|
15
|
-
*/
|
|
16
|
-
block: BlockFromConfig<T, I, S>,
|
|
17
|
-
/**
|
|
18
|
-
* The BlockNote editor instance
|
|
19
|
-
* This is typed generically. If you want an editor with your custom schema, you need to
|
|
20
|
-
* cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
|
|
21
|
-
*/
|
|
22
|
-
editor: BlockNoteEditor<BlockSchemaWithBlock<T["type"], T>, I, S>) => {
|
|
23
|
-
dom: HTMLElement;
|
|
24
|
-
contentDOM?: HTMLElement;
|
|
25
|
-
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
26
|
-
destroy?: () => void;
|
|
27
|
-
};
|
|
28
|
-
toExternalHTML?: (block: BlockFromConfig<T, I, S>, editor: BlockNoteEditor<BlockSchemaWithBlock<T["type"], T>, I, S>) => {
|
|
29
|
-
dom: HTMLElement;
|
|
30
|
-
contentDOM?: HTMLElement;
|
|
31
|
-
};
|
|
32
|
-
parse?: (el: HTMLElement) => PartialBlockFromConfig<T, I, S>["props"] | undefined;
|
|
33
|
-
};
|
|
3
|
+
import { NodeView } from "@tiptap/pm/view";
|
|
4
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
5
|
+
import { PropSchema } from "../propTypes.js";
|
|
6
|
+
import { BlockConfig, BlockImplementation, BlockSpec, LooseBlockSpec } from "./types.js";
|
|
34
7
|
export declare function applyNonSelectableBlockFix(nodeView: NodeView, editor: Editor): void;
|
|
35
|
-
export declare function getParseRules(config: BlockConfig,
|
|
36
|
-
export declare function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
8
|
+
export declare function getParseRules<TName extends string, TProps extends PropSchema, TContent extends "inline" | "none" | "table">(config: BlockConfig<TName, TProps, TContent>, implementation: BlockImplementation<TName, TProps, TContent>): TagParseRule[];
|
|
9
|
+
export declare function addNodeAndExtensionsToSpec<TName extends string, TProps extends PropSchema, TContent extends "inline" | "none" | "table">(blockConfig: BlockConfig<TName, TProps, TContent>, blockImplementation: BlockImplementation<TName, TProps, TContent>, extensions?: BlockNoteExtension<any>[], priority?: number): LooseBlockSpec<TName, TProps, TContent>;
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to create a block config.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createBlockConfig<TCallback extends (options: Partial<Record<string, any>>) => BlockConfig<any, any, any>, TOptions extends Parameters<TCallback>[0], TName extends ReturnType<TCallback>["type"], TProps extends ReturnType<TCallback>["propSchema"], TContent extends ReturnType<TCallback>["content"]>(callback: TCallback): TOptions extends undefined ? () => BlockConfig<TName, TProps, TContent> : (options: TOptions) => BlockConfig<TName, TProps, TContent>;
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to create a block definition.
|
|
16
|
+
* Can accept either functions that return the required objects, or the objects directly.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createBlockSpec<const TName extends string, const TProps extends PropSchema, const TContent extends "inline" | "none", const TOptions extends Partial<Record<string, any>> | undefined = undefined>(blockConfigOrCreator: BlockConfig<TName, TProps, TContent>, blockImplementationOrCreator: BlockImplementation<TName, TProps, TContent> | (TOptions extends undefined ? () => BlockImplementation<TName, TProps, TContent> : (options: Partial<TOptions>) => BlockImplementation<TName, TProps, TContent>), extensionsOrCreator?: BlockNoteExtension<any>[] | (TOptions extends undefined ? () => BlockNoteExtension<any>[] : (options: Partial<TOptions>) => BlockNoteExtension<any>[])): (options?: Partial<TOptions>) => BlockSpec<TName, TProps, TContent>;
|
|
19
|
+
export declare function createBlockSpec<const TName extends string, const TProps extends PropSchema, const TContent extends "inline" | "none", const BlockConf extends BlockConfig<TName, TProps, TContent>, const TOptions extends Partial<Record<string, any>>>(blockCreator: (options: Partial<TOptions>) => BlockConf, blockImplementationOrCreator: BlockImplementation<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]> | (TOptions extends undefined ? () => BlockImplementation<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]> : (options: Partial<TOptions>) => BlockImplementation<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]>), extensionsOrCreator?: BlockNoteExtension<any>[] | (TOptions extends undefined ? () => BlockNoteExtension<any>[] : (options: Partial<TOptions>) => BlockNoteExtension<any>[])): (options?: Partial<TOptions>) => BlockSpec<BlockConf["type"], BlockConf["propSchema"], BlockConf["content"]>;
|
|
@@ -1,45 +1,23 @@
|
|
|
1
|
-
import { Attributes, Editor,
|
|
1
|
+
import { Attributes, Editor, Node } from "@tiptap/core";
|
|
2
2
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
3
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
3
4
|
import { InlineContentSchema } from "../inlineContent/types.js";
|
|
4
5
|
import { PropSchema, Props } from "../propTypes.js";
|
|
5
6
|
import { StyleSchema } from "../styles/types.js";
|
|
6
|
-
import { BlockConfig,
|
|
7
|
+
import { BlockConfig, BlockSchemaWithBlock, LooseBlockSpec, SpecificBlock } from "./types.js";
|
|
7
8
|
export declare function propsToAttributes(propSchema: PropSchema): Attributes;
|
|
8
|
-
export declare function getBlockFromPos<BType extends string, Config extends BlockConfig, BSchema extends BlockSchemaWithBlock<BType, Config>, I extends InlineContentSchema, S extends StyleSchema>(getPos: (
|
|
9
|
+
export declare function getBlockFromPos<BType extends string, Config extends BlockConfig, BSchema extends BlockSchemaWithBlock<BType, Config>, I extends InlineContentSchema, S extends StyleSchema>(getPos: () => number | undefined, editor: BlockNoteEditor<BSchema, I, S>, tipTapEditor: Editor, type: BType): SpecificBlock<BSchema, BType, I, S>;
|
|
9
10
|
export declare function wrapInBlockStructure<BType extends string, PSchema extends PropSchema>(element: {
|
|
10
|
-
dom: HTMLElement;
|
|
11
|
+
dom: HTMLElement | DocumentFragment;
|
|
11
12
|
contentDOM?: HTMLElement;
|
|
12
13
|
destroy?: () => void;
|
|
13
|
-
}, blockType: BType, blockProps: Props<PSchema
|
|
14
|
+
}, blockType: BType, blockProps: Partial<Props<PSchema>>, propSchema: PSchema, isFileBlock?: boolean, domAttributes?: Record<string, string>): {
|
|
14
15
|
dom: HTMLElement;
|
|
15
16
|
contentDOM?: HTMLElement;
|
|
16
17
|
destroy?: () => void;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
export declare function createStronglyTypedTiptapNode<Name extends string, Content extends "inline*" | "tableRow+" | "blockContainer+" | "column column+" | "">(config: NodeConfig & {
|
|
25
|
-
name: Name;
|
|
26
|
-
content: Content;
|
|
27
|
-
}): StronglyTypedTipTapNode<Name, Content>;
|
|
28
|
-
export declare function createInternalBlockSpec<T extends BlockConfig>(config: T, implementation: TiptapBlockImplementation<T, any, InlineContentSchema, StyleSchema>): {
|
|
29
|
-
config: T;
|
|
30
|
-
implementation: TiptapBlockImplementation<T, any, InlineContentSchema, StyleSchema>;
|
|
31
|
-
};
|
|
32
|
-
export declare function createBlockSpecFromStronglyTypedTiptapNode<T extends Node, P extends PropSchema>(node: T, propSchema: P, requiredExtensions?: Array<Extension | Node>): {
|
|
33
|
-
config: {
|
|
34
|
-
type: T["name"];
|
|
35
|
-
content: T["config"]["content"] extends "inline*" ? "inline" : T["config"]["content"] extends "tableRow+" ? "table" : "none";
|
|
36
|
-
propSchema: P;
|
|
37
|
-
};
|
|
38
|
-
implementation: TiptapBlockImplementation<{
|
|
39
|
-
type: T["name"];
|
|
40
|
-
content: T["config"]["content"] extends "inline*" ? "inline" : T["config"]["content"] extends "tableRow+" ? "table" : "none";
|
|
41
|
-
propSchema: P;
|
|
42
|
-
}, any, InlineContentSchema, StyleSchema>;
|
|
43
|
-
};
|
|
44
|
-
export declare function getBlockSchemaFromSpecs<T extends BlockSpecs>(specs: T): BlockSchemaFromSpecs<T>;
|
|
45
|
-
export {};
|
|
19
|
+
export declare function createBlockSpecFromTiptapNode<const T extends {
|
|
20
|
+
node: Node;
|
|
21
|
+
type: string;
|
|
22
|
+
content: "inline" | "table" | "none";
|
|
23
|
+
}, P extends PropSchema>(config: T, propSchema: P, extensions?: BlockNoteExtension<any>[]): LooseBlockSpec<T["type"], P, T["content"]>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/** Define the main block types **/
|
|
2
|
-
import type {
|
|
2
|
+
import type { Node, NodeViewRendererProps } from "@tiptap/core";
|
|
3
|
+
import type { Fragment, Schema } from "prosemirror-model";
|
|
4
|
+
import type { ViewMutationRecord } from "prosemirror-view";
|
|
3
5
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
6
|
+
import type { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
4
7
|
import type { InlineContent, InlineContentSchema, PartialInlineContent } from "../inlineContent/types.js";
|
|
5
8
|
import type { PropSchema, Props } from "../propTypes.js";
|
|
6
9
|
import type { StyleSchema } from "../styles/types.js";
|
|
@@ -8,58 +11,88 @@ export type BlockNoteDOMElement = "editor" | "block" | "blockGroup" | "blockCont
|
|
|
8
11
|
export type BlockNoteDOMAttributes = Partial<{
|
|
9
12
|
[DOMElement in BlockNoteDOMElement]: Record<string, string>;
|
|
10
13
|
}>;
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
default: boolean;
|
|
25
|
-
};
|
|
26
|
-
previewWidth?: {
|
|
27
|
-
default: undefined;
|
|
28
|
-
type: "number";
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
content: "none";
|
|
32
|
-
isSelectable?: boolean;
|
|
33
|
-
isFileBlock: true;
|
|
14
|
+
export interface BlockConfigMeta {
|
|
15
|
+
/**
|
|
16
|
+
* Defines which keyboard shortcut should be used to insert a hard break into the block's inline content.
|
|
17
|
+
* @default "shift+enter"
|
|
18
|
+
*/
|
|
19
|
+
hardBreakShortcut?: "shift+enter" | "enter" | "none";
|
|
20
|
+
/**
|
|
21
|
+
* Whether the block is selectable
|
|
22
|
+
*/
|
|
23
|
+
selectable?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The accept mime types for the file block
|
|
26
|
+
*/
|
|
34
27
|
fileBlockAccept?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.code} block
|
|
30
|
+
*/
|
|
31
|
+
code?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.defining} block
|
|
34
|
+
*/
|
|
35
|
+
defining?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the block is a {@link https://prosemirror.net/docs/ref/#model.NodeSpec.isolating} block
|
|
38
|
+
*/
|
|
39
|
+
isolating?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* BlockConfig contains the "schema" info about a Block type
|
|
43
|
+
* i.e. what props it supports, what content it supports, etc.
|
|
44
|
+
*/
|
|
45
|
+
export interface BlockConfig<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" | "table" = "inline" | "none" | "table"> {
|
|
46
|
+
/**
|
|
47
|
+
* The type of the block (unique identifier within a schema)
|
|
48
|
+
*/
|
|
49
|
+
type: T;
|
|
50
|
+
/**
|
|
51
|
+
* The properties that the block supports
|
|
52
|
+
* @todo will be zod schema in the future
|
|
53
|
+
*/
|
|
54
|
+
readonly propSchema: PS;
|
|
55
|
+
/**
|
|
56
|
+
* The content that the block supports
|
|
57
|
+
*/
|
|
58
|
+
content: C;
|
|
59
|
+
}
|
|
60
|
+
export type CustomBlockConfig<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" = "inline" | "none"> = BlockConfig<T, PS, C>;
|
|
61
|
+
export type BlockSpec<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" | "table" = "inline" | "none" | "table"> = {
|
|
62
|
+
config: BlockConfig<T, PS, C>;
|
|
63
|
+
implementation: BlockImplementation<T, PS, C>;
|
|
64
|
+
extensions?: BlockNoteExtension<any>[];
|
|
35
65
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
/**
|
|
67
|
+
* This allows de-coupling the types that we display to users versus the types we expose internally.
|
|
68
|
+
*
|
|
69
|
+
* This prevents issues with type-inference across parameters that Typescript cannot handle.
|
|
70
|
+
* Specifically, the blocks shape cannot be properly inferred to a specific type like we expose to the user.
|
|
71
|
+
*/
|
|
72
|
+
export type LooseBlockSpec<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" | "table" = "inline" | "none" | "table"> = {
|
|
73
|
+
config: BlockConfig<T, PS, C>;
|
|
74
|
+
implementation: Omit<BlockImplementation<T, PS, C>, "render" | "toExternalHTML"> & {
|
|
75
|
+
render: (
|
|
76
|
+
/**
|
|
77
|
+
* The custom block to render
|
|
78
|
+
*/
|
|
79
|
+
block: any,
|
|
80
|
+
/**
|
|
81
|
+
* The BlockNote editor instance
|
|
82
|
+
*/
|
|
83
|
+
editor: BlockNoteEditor<any>) => {
|
|
84
|
+
dom: HTMLElement | DocumentFragment;
|
|
85
|
+
contentDOM?: HTMLElement;
|
|
86
|
+
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
87
|
+
destroy?: () => void;
|
|
88
|
+
};
|
|
89
|
+
toExternalHTML?: (block: any, editor: BlockNoteEditor<any>) => {
|
|
90
|
+
dom: HTMLElement | DocumentFragment;
|
|
91
|
+
contentDOM?: HTMLElement;
|
|
92
|
+
} | undefined;
|
|
93
|
+
node: Node;
|
|
58
94
|
};
|
|
59
|
-
|
|
60
|
-
export type BlockSpec<T extends BlockConfig, B extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> = {
|
|
61
|
-
config: T;
|
|
62
|
-
implementation: TiptapBlockImplementation<NoInfer<T>, B, I, S>;
|
|
95
|
+
extensions?: BlockNoteExtension<any>[];
|
|
63
96
|
};
|
|
64
97
|
type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
|
|
65
98
|
[Type in keyof Blocks]: Type extends string ? Blocks[Type] extends {
|
|
@@ -67,13 +100,45 @@ type NamesMatch<Blocks extends Record<string, BlockConfig>> = Blocks extends {
|
|
|
67
100
|
} ? Blocks[Type] : never : never;
|
|
68
101
|
} ? Blocks : never;
|
|
69
102
|
export type BlockSchema = NamesMatch<Record<string, BlockConfig>>;
|
|
70
|
-
export type BlockSpecs =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
103
|
+
export type BlockSpecs = {
|
|
104
|
+
[k in string]: {
|
|
105
|
+
config: BlockSpec<k>["config"];
|
|
106
|
+
implementation: Omit<BlockSpec<k>["implementation"], "render" | "toExternalHTML"> & {
|
|
107
|
+
render: (
|
|
108
|
+
/**
|
|
109
|
+
* The custom block to render
|
|
110
|
+
*/
|
|
111
|
+
block: any,
|
|
112
|
+
/**
|
|
113
|
+
* The BlockNote editor instance
|
|
114
|
+
*/
|
|
115
|
+
editor: BlockNoteEditor<any>) => {
|
|
116
|
+
dom: HTMLElement | DocumentFragment;
|
|
117
|
+
contentDOM?: HTMLElement;
|
|
118
|
+
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
119
|
+
destroy?: () => void;
|
|
120
|
+
};
|
|
121
|
+
toExternalHTML?: (block: any, editor: BlockNoteEditor<any>) => {
|
|
122
|
+
dom: HTMLElement | DocumentFragment;
|
|
123
|
+
contentDOM?: HTMLElement;
|
|
124
|
+
} | undefined;
|
|
125
|
+
};
|
|
126
|
+
extensions?: BlockNoteExtension<any>[];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
export type BlockImplementations = Record<string, BlockImplementation<any, any>>;
|
|
130
|
+
export type BlockSchemaFromSpecs<BS extends BlockSpecs> = {
|
|
131
|
+
[K in keyof BS]: BS[K]["config"];
|
|
74
132
|
};
|
|
75
|
-
export type
|
|
76
|
-
[
|
|
133
|
+
export type BlockSpecsFromSchema<BS extends BlockSchema> = {
|
|
134
|
+
[K in keyof BS]: {
|
|
135
|
+
config: BlockConfig<BS[K]["type"], BS[K]["propSchema"], BS[K]["content"]>;
|
|
136
|
+
implementation: BlockImplementation<BS[K]["type"], BS[K]["propSchema"], BS[K]["content"]>;
|
|
137
|
+
extensions?: BlockNoteExtension<any>[];
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export type BlockSchemaWithBlock<T extends string, C extends BlockConfig> = {
|
|
141
|
+
[k in T]: C;
|
|
77
142
|
};
|
|
78
143
|
export type TableCellProps = {
|
|
79
144
|
backgroundColor: string;
|
|
@@ -138,7 +203,7 @@ type PartialBlockFromConfigNoChildren<B extends BlockConfig, I extends InlineCon
|
|
|
138
203
|
id?: string;
|
|
139
204
|
type?: B["type"];
|
|
140
205
|
props?: Partial<Props<B["propSchema"]>>;
|
|
141
|
-
content?: B["content"] extends "inline" ? PartialInlineContent<I, S> : B["content"] extends "table" ? PartialTableContent<I, S> : undefined;
|
|
206
|
+
content?: B["content"] extends "inline" ? PartialInlineContent<I, S> : B["content"] extends "table" ? PartialTableContent<I, S> : B["content"] extends "none" ? undefined : never;
|
|
142
207
|
};
|
|
143
208
|
type PartialBlocksWithoutChildren<BSchema extends BlockSchema, I extends InlineContentSchema, S extends StyleSchema> = {
|
|
144
209
|
[BType in keyof BSchema]: PartialBlockFromConfigNoChildren<BSchema[BType], I, S>;
|
|
@@ -155,4 +220,63 @@ export type PartialBlockFromConfig<B extends BlockConfig, I extends InlineConten
|
|
|
155
220
|
export type BlockIdentifier = {
|
|
156
221
|
id: string;
|
|
157
222
|
} | string;
|
|
223
|
+
export type BlockImplementation<TName extends string = string, TProps extends PropSchema = PropSchema, TContent extends "inline" | "none" | "table" = "inline" | "none" | "table"> = {
|
|
224
|
+
/**
|
|
225
|
+
* Metadata
|
|
226
|
+
*/
|
|
227
|
+
meta?: BlockConfigMeta;
|
|
228
|
+
/**
|
|
229
|
+
* A function that converts the block into a DOM element
|
|
230
|
+
*/
|
|
231
|
+
render: (this: Record<string, never> | ({
|
|
232
|
+
blockContentDOMAttributes: Record<string, string>;
|
|
233
|
+
} & ({
|
|
234
|
+
renderType: "nodeView";
|
|
235
|
+
props: NodeViewRendererProps;
|
|
236
|
+
} | {
|
|
237
|
+
renderType: "dom";
|
|
238
|
+
props: undefined;
|
|
239
|
+
})),
|
|
240
|
+
/**
|
|
241
|
+
* The custom block to render
|
|
242
|
+
*/
|
|
243
|
+
block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>,
|
|
244
|
+
/**
|
|
245
|
+
* The BlockNote editor instance
|
|
246
|
+
*/
|
|
247
|
+
editor: BlockNoteEditor<Record<TName, BlockConfig<TName, TProps, TContent>>>) => {
|
|
248
|
+
dom: HTMLElement | DocumentFragment;
|
|
249
|
+
contentDOM?: HTMLElement;
|
|
250
|
+
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
251
|
+
destroy?: () => void;
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Exports block to external HTML. If not defined, the output will be the same
|
|
255
|
+
* as `render(...).dom`.
|
|
256
|
+
*/
|
|
257
|
+
toExternalHTML?: (this: Partial<{
|
|
258
|
+
blockContentDOMAttributes: Record<string, string>;
|
|
259
|
+
}>, block: BlockFromConfig<BlockConfig<TName, TProps, TContent>, any, any>, editor: BlockNoteEditor<Record<TName, BlockConfig<TName, TProps, TContent>>>) => {
|
|
260
|
+
dom: HTMLElement | DocumentFragment;
|
|
261
|
+
contentDOM?: HTMLElement;
|
|
262
|
+
} | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Parses an external HTML element into a block of this type when it returns the block props object, otherwise undefined
|
|
265
|
+
*/
|
|
266
|
+
parse?: (el: HTMLElement) => Partial<Props<TProps>> | undefined;
|
|
267
|
+
/**
|
|
268
|
+
* The blocks that this block should run before.
|
|
269
|
+
* This is used to determine the order in which blocks are parsed
|
|
270
|
+
*/
|
|
271
|
+
runsBefore?: string[];
|
|
272
|
+
/**
|
|
273
|
+
* Advanced parsing function that controls how content within the block is parsed.
|
|
274
|
+
* This is not recommended to use, and is only useful for advanced use cases.
|
|
275
|
+
*/
|
|
276
|
+
parseContent?: (options: {
|
|
277
|
+
el: HTMLElement;
|
|
278
|
+
schema: Schema;
|
|
279
|
+
}) => Fragment;
|
|
280
|
+
};
|
|
281
|
+
export type CustomBlockImplementation<T extends string = string, PS extends PropSchema = PropSchema, C extends "inline" | "none" = "inline" | "none"> = BlockImplementation<T, PS, C>;
|
|
158
282
|
export {};
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { TagParseRule } from "@tiptap/pm/model";
|
|
2
2
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
3
|
+
import { Props } from "../propTypes.js";
|
|
3
4
|
import { StyleSchema } from "../styles/types.js";
|
|
4
5
|
import { CustomInlineContentConfig, InlineContentFromConfig, InlineContentSpec, PartialCustomInlineContentFromConfig } from "./types.js";
|
|
5
6
|
export type CustomInlineContentImplementation<T extends CustomInlineContentConfig, S extends StyleSchema> = {
|
|
7
|
+
meta?: {
|
|
8
|
+
draggable?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Parses an external HTML element into a inline content of this type when it returns the block props object, otherwise undefined
|
|
12
|
+
*/
|
|
13
|
+
parse?: (el: HTMLElement) => Partial<Props<T["propSchema"]>> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Renders an inline content to DOM elements
|
|
16
|
+
*/
|
|
6
17
|
render: (
|
|
7
18
|
/**
|
|
8
19
|
* The custom inline content to render
|
|
9
20
|
*/
|
|
10
|
-
inlineContent: InlineContentFromConfig<T, S>,
|
|
21
|
+
inlineContent: InlineContentFromConfig<T, S>,
|
|
22
|
+
/**
|
|
23
|
+
* A callback that allows overriding the inline content element
|
|
24
|
+
*/
|
|
25
|
+
updateInlineContent: (update: PartialCustomInlineContentFromConfig<T, S>) => void,
|
|
11
26
|
/**
|
|
12
27
|
* The BlockNote editor instance
|
|
13
28
|
* This is typed generically. If you want an editor with your custom schema, you need to
|
|
@@ -16,7 +31,26 @@ export type CustomInlineContentImplementation<T extends CustomInlineContentConfi
|
|
|
16
31
|
editor: BlockNoteEditor<any, any, S>) => {
|
|
17
32
|
dom: HTMLElement;
|
|
18
33
|
contentDOM?: HTMLElement;
|
|
34
|
+
destroy?: () => void;
|
|
19
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Renders an inline content to external HTML elements for use outside the editor
|
|
38
|
+
* If not provided, falls back to the render method
|
|
39
|
+
*/
|
|
40
|
+
toExternalHTML?: (
|
|
41
|
+
/**
|
|
42
|
+
* The custom inline content to render
|
|
43
|
+
*/
|
|
44
|
+
inlineContent: InlineContentFromConfig<T, S>,
|
|
45
|
+
/**
|
|
46
|
+
* The BlockNote editor instance
|
|
47
|
+
* This is typed generically. If you want an editor with your custom schema, you need to
|
|
48
|
+
* cast it manually, e.g.: `const e = editor as BlockNoteEditor<typeof mySchema>;`
|
|
49
|
+
*/
|
|
50
|
+
editor: BlockNoteEditor<any, any, S>) => {
|
|
51
|
+
dom: HTMLElement | DocumentFragment;
|
|
52
|
+
contentDOM?: HTMLElement;
|
|
53
|
+
} | undefined;
|
|
20
54
|
};
|
|
21
|
-
export declare function getInlineContentParseRules(config:
|
|
55
|
+
export declare function getInlineContentParseRules<C extends CustomInlineContentConfig>(config: C, customParseFunction?: CustomInlineContentImplementation<C, any>["parse"]): TagParseRule[];
|
|
22
56
|
export declare function createInlineContentSpec<T extends CustomInlineContentConfig, S extends StyleSchema>(inlineContentConfig: T, inlineContentImplementation: CustomInlineContentImplementation<T, S>): InlineContentSpec<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KeyboardShortcutCommand, Node } from "@tiptap/core";
|
|
2
2
|
import { PropSchema, Props } from "../propTypes.js";
|
|
3
|
-
import { CustomInlineContentConfig,
|
|
3
|
+
import { CustomInlineContentConfig, InlineContentImplementation, InlineContentSchemaFromSpecs, InlineContentSpec, InlineContentSpecs } from "./types.js";
|
|
4
4
|
export declare function addInlineContentAttributes<IType extends string, PSchema extends PropSchema>(element: {
|
|
5
5
|
dom: HTMLElement;
|
|
6
6
|
contentDOM?: HTMLElement;
|
|
@@ -11,18 +11,10 @@ export declare function addInlineContentAttributes<IType extends string, PSchema
|
|
|
11
11
|
export declare function addInlineContentKeyboardShortcuts<T extends CustomInlineContentConfig>(config: T): {
|
|
12
12
|
[p: string]: KeyboardShortcutCommand;
|
|
13
13
|
};
|
|
14
|
-
export declare function createInternalInlineContentSpec<T extends
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type: T["name"];
|
|
21
|
-
propSchema: P;
|
|
22
|
-
content: "none" | "styled";
|
|
23
|
-
};
|
|
24
|
-
implementation: {
|
|
25
|
-
node: Node;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
14
|
+
export declare function createInternalInlineContentSpec<const T extends CustomInlineContentConfig>(config: T, implementation: InlineContentImplementation<NoInfer<T>>): InlineContentSpec<T>;
|
|
15
|
+
export declare function createInlineContentSpecFromTipTapNode<T extends Node, P extends PropSchema>(node: T, propSchema: P, implementation: Omit<InlineContentImplementation<CustomInlineContentConfig>, "node">): InlineContentSpec<{
|
|
16
|
+
readonly type: T["name"];
|
|
17
|
+
readonly propSchema: P;
|
|
18
|
+
readonly content: "none" | "styled";
|
|
19
|
+
}>;
|
|
28
20
|
export declare function getInlineContentSchemaFromSpecs<T extends InlineContentSpecs>(specs: T): InlineContentSchemaFromSpecs<T>;
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { Node } from "@tiptap/core";
|
|
2
2
|
import { PropSchema, Props } from "../propTypes.js";
|
|
3
3
|
import { StyleSchema, Styles } from "../styles/types.js";
|
|
4
|
+
import { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
5
|
+
import { ViewMutationRecord } from "prosemirror-view";
|
|
4
6
|
export type CustomInlineContentConfig = {
|
|
5
7
|
type: string;
|
|
6
8
|
content: "styled" | "none";
|
|
7
|
-
draggable?: boolean;
|
|
8
9
|
readonly propSchema: PropSchema;
|
|
9
10
|
};
|
|
10
11
|
export type InlineContentConfig = CustomInlineContentConfig | "text" | "link";
|
|
11
12
|
export type InlineContentImplementation<T extends InlineContentConfig> = T extends "link" | "text" ? undefined : {
|
|
13
|
+
meta?: {
|
|
14
|
+
draggable?: boolean;
|
|
15
|
+
};
|
|
12
16
|
node: Node;
|
|
17
|
+
toExternalHTML?: (inlineContent: any, editor: BlockNoteEditor<any, any, any>) => {
|
|
18
|
+
dom: HTMLElement | DocumentFragment;
|
|
19
|
+
contentDOM?: HTMLElement;
|
|
20
|
+
} | undefined;
|
|
21
|
+
render: (inlineContent: any, updateInlineContent: (update: any) => void, editor: BlockNoteEditor<any, any, any>) => {
|
|
22
|
+
dom: HTMLElement | DocumentFragment;
|
|
23
|
+
contentDOM?: HTMLElement;
|
|
24
|
+
ignoreMutation?: (mutation: ViewMutationRecord) => boolean;
|
|
25
|
+
destroy?: () => void;
|
|
26
|
+
};
|
|
13
27
|
};
|
|
14
28
|
export type InlineContentSchemaWithInlineContent<IType extends string, C extends InlineContentConfig> = {
|
|
15
29
|
[k in IType]: C;
|
|
@@ -8,19 +8,19 @@ export type PropSpec<PType extends boolean | number | string> = {
|
|
|
8
8
|
};
|
|
9
9
|
export type PropSchema = Record<string, PropSpec<boolean | number | string>>;
|
|
10
10
|
export type Props<PSchema extends PropSchema> = {
|
|
11
|
-
[PName in keyof PSchema]: (PSchema[PName] extends {
|
|
11
|
+
[PName in keyof PSchema]: (NonNullable<PSchema[PName]> extends {
|
|
12
12
|
default: boolean;
|
|
13
13
|
} | {
|
|
14
14
|
type: "boolean";
|
|
15
|
-
} ? PSchema[PName]["values"] extends readonly boolean[] ? PSchema[PName]["values"][number] : boolean : PSchema[PName] extends {
|
|
15
|
+
} ? NonNullable<PSchema[PName]>["values"] extends readonly boolean[] ? NonNullable<PSchema[PName]>["values"][number] : boolean : NonNullable<PSchema[PName]> extends {
|
|
16
16
|
default: number;
|
|
17
17
|
} | {
|
|
18
18
|
type: "number";
|
|
19
|
-
} ? PSchema[PName]["values"] extends readonly number[] ? PSchema[PName]["values"][number] : number : PSchema[PName] extends {
|
|
19
|
+
} ? NonNullable<PSchema[PName]>["values"] extends readonly number[] ? NonNullable<PSchema[PName]>["values"][number] : number : NonNullable<PSchema[PName]> extends {
|
|
20
20
|
default: string;
|
|
21
21
|
} | {
|
|
22
22
|
type: "string";
|
|
23
|
-
} ? PSchema[PName]["values"] extends readonly string[] ? PSchema[PName]["values"][number] : string : never) extends infer T ? PSchema[PName] extends {
|
|
23
|
+
} ? NonNullable<PSchema[PName]>["values"] extends readonly string[] ? NonNullable<PSchema[PName]>["values"][number] : string : never) extends infer T ? PSchema[PName] extends {
|
|
24
24
|
optional: true;
|
|
25
25
|
} ? T | undefined : T : never;
|
|
26
26
|
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BlockNoteEditor } from "../editor/BlockNoteEditor.js";
|
|
2
|
+
import { BlockNoDefaults, BlockSchema, BlockSpecs, InlineContentConfig, InlineContentSchema, InlineContentSpec, InlineContentSpecs, LooseBlockSpec, PartialBlockNoDefaults, StyleSchema, StyleSpecs } from "./index.js";
|
|
3
|
+
export declare class CustomBlockNoteSchema<BSchema extends BlockSchema, ISchema extends InlineContentSchema, SSchema extends StyleSchema> {
|
|
4
|
+
private opts;
|
|
5
|
+
readonly BlockNoteEditor: BlockNoteEditor<BSchema, ISchema, SSchema>;
|
|
6
|
+
readonly Block: BlockNoDefaults<BSchema, ISchema, SSchema>;
|
|
7
|
+
readonly PartialBlock: PartialBlockNoDefaults<BSchema, ISchema, SSchema>;
|
|
8
|
+
inlineContentSpecs: InlineContentSpecs;
|
|
9
|
+
styleSpecs: StyleSpecs;
|
|
10
|
+
blockSpecs: {
|
|
11
|
+
[K in keyof BSchema]: K extends string ? LooseBlockSpec<K, BSchema[K]["propSchema"], BSchema[K]["content"]> : never;
|
|
12
|
+
};
|
|
13
|
+
blockSchema: BSchema;
|
|
14
|
+
inlineContentSchema: ISchema;
|
|
15
|
+
styleSchema: SSchema;
|
|
16
|
+
constructor(opts: {
|
|
17
|
+
blockSpecs: BlockSpecs;
|
|
18
|
+
inlineContentSpecs: InlineContentSpecs;
|
|
19
|
+
styleSpecs: StyleSpecs;
|
|
20
|
+
});
|
|
21
|
+
private init;
|
|
22
|
+
/**
|
|
23
|
+
* Adds additional block specs to the current schema in a builder pattern.
|
|
24
|
+
* This method allows extending the schema after it has been created.
|
|
25
|
+
*
|
|
26
|
+
* @param additionalBlockSpecs - Additional block specs to add to the schema
|
|
27
|
+
* @returns The current schema instance for chaining
|
|
28
|
+
*/
|
|
29
|
+
extend<AdditionalBlockSpecs extends BlockSpecs = Record<string, never>, AdditionalInlineContentSpecs extends Record<string, InlineContentSpec<InlineContentConfig>> = Record<string, never>, AdditionalStyleSpecs extends StyleSpecs = Record<string, never>>(opts: {
|
|
30
|
+
blockSpecs?: AdditionalBlockSpecs;
|
|
31
|
+
inlineContentSpecs?: AdditionalInlineContentSpecs;
|
|
32
|
+
styleSpecs?: AdditionalStyleSpecs;
|
|
33
|
+
}): CustomBlockNoteSchema<AdditionalBlockSpecs extends undefined | Record<string, never> ? BSchema : BSchema & {
|
|
34
|
+
[K in keyof AdditionalBlockSpecs]: K extends string ? AdditionalBlockSpecs[K]["config"] : never;
|
|
35
|
+
}, AdditionalInlineContentSpecs extends undefined | Record<string, never> ? ISchema : ISchema & {
|
|
36
|
+
[K in keyof AdditionalInlineContentSpecs]: AdditionalInlineContentSpecs[K]["config"];
|
|
37
|
+
}, AdditionalStyleSpecs extends undefined | Record<string, never> ? SSchema : SSchema & {
|
|
38
|
+
[K in keyof AdditionalStyleSpecs]: AdditionalStyleSpecs[K]["config"];
|
|
39
|
+
}>;
|
|
40
|
+
}
|