Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="bn-inline-content">I enjoy working with <span data-inline-content-type="mention" data-user="Matthew">@Matthew</span></p>
<p class="bn-inline-content">I enjoy working with <span data-inline-content-type="mention" data-user="Matthew">@Matthew</span></p>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Props } from "../blocks/types";
import { StyleSchema } from "../styles/types";
import {
addInlineContentAttributes,
addInlineContentKeyboardShortcuts,
createInlineContentSpecFromTipTapNode,
} from "./internal";
import {
Expand Down Expand Up @@ -83,6 +84,10 @@ export function createInlineContentSpec<
return propsToAttributes(inlineContentConfig.propSchema);
},

addKeyboardShortcuts() {
return addInlineContentKeyboardShortcuts(inlineContentConfig);
},

parseHTML() {
return getInlineContentParseRules(inlineContentConfig);
},
Expand Down
26 changes: 24 additions & 2 deletions packages/core/src/extensions/Blocks/api/inlineContent/internal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Node } from "@tiptap/core";
import { KeyboardShortcutCommand, Node } from "@tiptap/core";
import { camelToDataKebab } from "../blocks/internal";
import { Props, PropSchema } from "../blocks/types";
import { PropSchema, Props } from "../blocks/types";
import {
CustomInlineContentConfig,
InlineContentConfig,
InlineContentImplementation,
InlineContentSchemaFromSpecs,
Expand Down Expand Up @@ -45,6 +46,27 @@ export function addInlineContentAttributes<
return element;
}

// see https://github.com/TypeCellOS/BlockNote/pull/435
export function addInlineContentKeyboardShortcuts<
T extends CustomInlineContentConfig
>(
config: T
): {
[p: string]: KeyboardShortcutCommand;
} {
return {
Backspace: ({ editor }) => {
const resolvedPos = editor.state.selection.$from;

return (
editor.state.selection.empty &&
resolvedPos.node().type.name === config.type &&
resolvedPos.parentOffset === 0
);
},
};
}

// This helper function helps to instantiate a InlineContentSpec with a
// config and implementation that conform to the type of Config
export function createInternalInlineContentSpec<T extends InlineContentConfig>(
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/ReactInlineContentSpec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
addInlineContentAttributes,
addInlineContentKeyboardShortcuts,
camelToDataKebab,
createInternalInlineContentSpec,
createStronglyTypedTiptapNode,
Expand Down Expand Up @@ -100,6 +101,10 @@ export function createReactInlineContentSpec<
return propsToAttributes(inlineContentConfig.propSchema);
},

addKeyboardShortcuts() {
return addInlineContentKeyboardShortcuts(inlineContentConfig);
},

parseHTML() {
return getInlineContentParseRules(inlineContentConfig);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="bn-inline-content">I enjoy working with <span data-inline-content-type="mention" data-user="Matthew">@Matthew</span></p>
<p class="bn-inline-content">I enjoy working with <span data-inline-content-type="mention" data-user="Matthew">@Matthew</span></p>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">I enjoy working with <span data-inline-content-type="mention" data-user="Matthew">@Matthew</span></p></div></div></div></div>
<div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="1"><div class="bn-block" data-node-type="blockContainer" data-id="1"><div class="bn-block-content" data-content-type="paragraph"><p class="bn-inline-content">I enjoy working with <span data-inline-content-type="mention" data-user="Matthew">@Matthew</span></p></div></div></div></div>