@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
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Attribute,
|
|
3
|
-
Attributes,
|
|
4
|
-
Editor,
|
|
5
|
-
Extension,
|
|
6
|
-
Node,
|
|
7
|
-
NodeConfig,
|
|
8
|
-
} from "@tiptap/core";
|
|
1
|
+
import { Attribute, Attributes, Editor, Node } from "@tiptap/core";
|
|
9
2
|
import { defaultBlockToHTML } from "../../blocks/defaultBlockHelpers.js";
|
|
10
|
-
import { inheritedProps } from "../../blocks/defaultProps.js";
|
|
11
3
|
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor.js";
|
|
4
|
+
import { BlockNoteExtension } from "../../editor/BlockNoteExtension.js";
|
|
12
5
|
import { mergeCSSClasses } from "../../util/browser.js";
|
|
13
6
|
import { camelToDataKebab } from "../../util/string.js";
|
|
14
7
|
import { InlineContentSchema } from "../inlineContent/types.js";
|
|
@@ -16,12 +9,9 @@ import { PropSchema, Props } from "../propTypes.js";
|
|
|
16
9
|
import { StyleSchema } from "../styles/types.js";
|
|
17
10
|
import {
|
|
18
11
|
BlockConfig,
|
|
19
|
-
BlockSchemaFromSpecs,
|
|
20
12
|
BlockSchemaWithBlock,
|
|
21
|
-
|
|
22
|
-
BlockSpecs,
|
|
13
|
+
LooseBlockSpec,
|
|
23
14
|
SpecificBlock,
|
|
24
|
-
TiptapBlockImplementation,
|
|
25
15
|
} from "./types.js";
|
|
26
16
|
|
|
27
17
|
// Function that uses the 'propSchema' of a blockConfig to create a TipTap
|
|
@@ -30,64 +20,62 @@ import {
|
|
|
30
20
|
export function propsToAttributes(propSchema: PropSchema): Attributes {
|
|
31
21
|
const tiptapAttributes: Record<string, Attribute> = {};
|
|
32
22
|
|
|
33
|
-
Object.entries(propSchema)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
23
|
+
Object.entries(propSchema).forEach(([name, spec]) => {
|
|
24
|
+
tiptapAttributes[name] = {
|
|
25
|
+
default: spec.default,
|
|
26
|
+
keepOnSplit: true,
|
|
27
|
+
// Props are displayed in kebab-case as HTML attributes. If a prop's
|
|
28
|
+
// value is the same as its default, we don't display an HTML
|
|
29
|
+
// attribute for it.
|
|
30
|
+
parseHTML: (element) => {
|
|
31
|
+
const value = element.getAttribute(camelToDataKebab(name));
|
|
32
|
+
|
|
33
|
+
if (value === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
(spec.default === undefined && spec.type === "boolean") ||
|
|
39
|
+
(spec.default !== undefined && typeof spec.default === "boolean")
|
|
40
|
+
) {
|
|
41
|
+
if (value === "true") {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
if (value ===
|
|
46
|
-
return
|
|
45
|
+
if (value === "false") {
|
|
46
|
+
return false;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(spec.default !== undefined && typeof spec.default === "boolean")
|
|
52
|
-
) {
|
|
53
|
-
if (value === "true") {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
if (
|
|
53
|
+
(spec.default === undefined && spec.type === "number") ||
|
|
54
|
+
(spec.default !== undefined && typeof spec.default === "number")
|
|
55
|
+
) {
|
|
56
|
+
const asNumber = parseFloat(value);
|
|
57
|
+
const isNumeric =
|
|
58
|
+
!Number.isNaN(asNumber) && Number.isFinite(asNumber);
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
if (isNumeric) {
|
|
61
|
+
return asNumber;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
(spec.default !== undefined && typeof spec.default === "number")
|
|
67
|
-
) {
|
|
68
|
-
const asNumber = parseFloat(value);
|
|
69
|
-
const isNumeric =
|
|
70
|
-
!Number.isNaN(asNumber) && Number.isFinite(asNumber);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
return value;
|
|
68
|
+
},
|
|
69
|
+
renderHTML: (attributes) => {
|
|
70
|
+
// don't render to html if the value is the same as the default
|
|
71
|
+
return attributes[name] !== spec.default
|
|
72
|
+
? {
|
|
73
|
+
[camelToDataKebab(name)]: attributes[name],
|
|
74
74
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return value;
|
|
80
|
-
},
|
|
81
|
-
renderHTML: (attributes) => {
|
|
82
|
-
// don't render to html if the value is the same as the default
|
|
83
|
-
return attributes[name] !== spec.default
|
|
84
|
-
? {
|
|
85
|
-
[camelToDataKebab(name)]: attributes[name],
|
|
86
|
-
}
|
|
87
|
-
: {};
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
});
|
|
75
|
+
: {};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
});
|
|
91
79
|
|
|
92
80
|
return tiptapAttributes;
|
|
93
81
|
}
|
|
@@ -101,18 +89,16 @@ export function getBlockFromPos<
|
|
|
101
89
|
I extends InlineContentSchema,
|
|
102
90
|
S extends StyleSchema,
|
|
103
91
|
>(
|
|
104
|
-
getPos: (
|
|
92
|
+
getPos: () => number | undefined,
|
|
105
93
|
editor: BlockNoteEditor<BSchema, I, S>,
|
|
106
94
|
tipTapEditor: Editor,
|
|
107
95
|
type: BType,
|
|
108
96
|
) {
|
|
97
|
+
const pos = getPos();
|
|
109
98
|
// Gets position of the node
|
|
110
|
-
if (
|
|
111
|
-
throw new Error(
|
|
112
|
-
"Cannot find node position as getPos is a boolean, not a function.",
|
|
113
|
-
);
|
|
99
|
+
if (pos === undefined) {
|
|
100
|
+
throw new Error("Cannot find node position");
|
|
114
101
|
}
|
|
115
|
-
const pos = getPos();
|
|
116
102
|
// Gets parent blockContainer node
|
|
117
103
|
const blockContainer = tipTapEditor.state.doc.resolve(pos!).node();
|
|
118
104
|
// Gets block identifier
|
|
@@ -145,12 +131,12 @@ export function wrapInBlockStructure<
|
|
|
145
131
|
PSchema extends PropSchema,
|
|
146
132
|
>(
|
|
147
133
|
element: {
|
|
148
|
-
dom: HTMLElement;
|
|
134
|
+
dom: HTMLElement | DocumentFragment;
|
|
149
135
|
contentDOM?: HTMLElement;
|
|
150
136
|
destroy?: () => void;
|
|
151
137
|
},
|
|
152
138
|
blockType: BType,
|
|
153
|
-
blockProps: Props<PSchema
|
|
139
|
+
blockProps: Partial<Props<PSchema>>,
|
|
154
140
|
propSchema: PSchema,
|
|
155
141
|
isFileBlock = false,
|
|
156
142
|
domAttributes?: Record<string, string>,
|
|
@@ -183,7 +169,7 @@ export function wrapInBlockStructure<
|
|
|
183
169
|
for (const [prop, value] of Object.entries(blockProps)) {
|
|
184
170
|
const spec = propSchema[prop];
|
|
185
171
|
const defaultValue = spec.default;
|
|
186
|
-
if (
|
|
172
|
+
if (value !== defaultValue) {
|
|
187
173
|
blockContent.setAttribute(camelToDataKebab(prop), value);
|
|
188
174
|
}
|
|
189
175
|
}
|
|
@@ -194,7 +180,7 @@ export function wrapInBlockStructure<
|
|
|
194
180
|
|
|
195
181
|
blockContent.appendChild(element.dom);
|
|
196
182
|
|
|
197
|
-
if (element.contentDOM
|
|
183
|
+
if (element.contentDOM) {
|
|
198
184
|
element.contentDOM.className = mergeCSSClasses(
|
|
199
185
|
"bn-inline-content",
|
|
200
186
|
element.contentDOM.className,
|
|
@@ -207,76 +193,29 @@ export function wrapInBlockStructure<
|
|
|
207
193
|
};
|
|
208
194
|
}
|
|
209
195
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
| "",
|
|
219
|
-
> = Node & { name: Name; config: { content: Content } };
|
|
220
|
-
|
|
221
|
-
export function createStronglyTypedTiptapNode<
|
|
222
|
-
Name extends string,
|
|
223
|
-
Content extends
|
|
224
|
-
| "inline*"
|
|
225
|
-
| "tableRow+"
|
|
226
|
-
| "blockContainer+"
|
|
227
|
-
| "column column+"
|
|
228
|
-
| "",
|
|
229
|
-
>(config: NodeConfig & { name: Name; content: Content }) {
|
|
230
|
-
return Node.create(config) as StronglyTypedTipTapNode<Name, Content>; // force re-typing (should be safe as it's type-checked from the config)
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// This helper function helps to instantiate a blockspec with a
|
|
234
|
-
// config and implementation that conform to the type of Config
|
|
235
|
-
export function createInternalBlockSpec<T extends BlockConfig>(
|
|
196
|
+
export function createBlockSpecFromTiptapNode<
|
|
197
|
+
const T extends {
|
|
198
|
+
node: Node;
|
|
199
|
+
type: string;
|
|
200
|
+
content: "inline" | "table" | "none";
|
|
201
|
+
},
|
|
202
|
+
P extends PropSchema,
|
|
203
|
+
>(
|
|
236
204
|
config: T,
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
InlineContentSchema,
|
|
241
|
-
StyleSchema
|
|
242
|
-
>,
|
|
243
|
-
) {
|
|
205
|
+
propSchema: P,
|
|
206
|
+
extensions?: BlockNoteExtension<any>[],
|
|
207
|
+
): LooseBlockSpec<T["type"], P, T["content"]> {
|
|
244
208
|
return {
|
|
245
|
-
config
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export function createBlockSpecFromStronglyTypedTiptapNode<
|
|
251
|
-
T extends Node,
|
|
252
|
-
P extends PropSchema,
|
|
253
|
-
>(node: T, propSchema: P, requiredExtensions?: Array<Extension | Node>) {
|
|
254
|
-
return createInternalBlockSpec(
|
|
255
|
-
{
|
|
256
|
-
type: node.name as T["name"],
|
|
257
|
-
content: (node.config.content === "inline*"
|
|
258
|
-
? "inline"
|
|
259
|
-
: node.config.content === "tableRow+"
|
|
260
|
-
? "table"
|
|
261
|
-
: "none") as T["config"]["content"] extends "inline*"
|
|
262
|
-
? "inline"
|
|
263
|
-
: T["config"]["content"] extends "tableRow+"
|
|
264
|
-
? "table"
|
|
265
|
-
: "none",
|
|
209
|
+
config: {
|
|
210
|
+
type: config.type as T["type"],
|
|
211
|
+
content: config.content,
|
|
266
212
|
propSchema,
|
|
267
213
|
},
|
|
268
|
-
{
|
|
269
|
-
node,
|
|
270
|
-
|
|
271
|
-
toInternalHTML: defaultBlockToHTML,
|
|
214
|
+
implementation: {
|
|
215
|
+
node: config.node,
|
|
216
|
+
render: defaultBlockToHTML,
|
|
272
217
|
toExternalHTML: defaultBlockToHTML,
|
|
273
|
-
// parse: () => undefined, // parse rules are in node already
|
|
274
218
|
},
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export function getBlockSchemaFromSpecs<T extends BlockSpecs>(specs: T) {
|
|
279
|
-
return Object.fromEntries(
|
|
280
|
-
Object.entries(specs).map(([key, value]) => [key, value.config]),
|
|
281
|
-
) as BlockSchemaFromSpecs<T>;
|
|
219
|
+
extensions,
|
|
220
|
+
};
|
|
282
221
|
}
|