Skip to content

Commit cd788ad

Browse files
committed
refactor: move draggable to implementation
1 parent 3174b5b commit cd788ad

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

docs/content/docs/features/custom-schemas/custom-inline-content.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ type CustomInlineContentConfig = {
5151
type: string;
5252
content: "styled" | "none";
5353
readonly propSchema: PropSchema;
54-
draggable?: boolean;
5554
};
5655
```
5756

@@ -100,14 +99,15 @@ If you do not want the prop to have a default value, you can define it as an obj
10099
mentioned._
101100
</Callout>
102101

103-
`draggable?:` Whether the inline content should be draggable.
104-
105102
### Inline Content Implementation (`ReactCustomInlineContentImplementation`)
106103

107104
The Inline Content Implementation defines how the inline content should be rendered to HTML.
108105

109106
```typescript
110107
type ReactCustomInlineContentImplementation = {
108+
meta?: {
109+
draggable?: boolean;
110+
};
111111
render: React.FC<{
112112
inlineContent: InlineContent;
113113
contentRef?: (node: HTMLElement | null) => void;
@@ -124,6 +124,8 @@ type ReactCustomInlineContentImplementation = {
124124

125125
- `draggable:` Specifies whether the inline content can be dragged within the editor. If set to `true`, the inline content will be draggable. Defaults to `false` if not specified. If this is true, you should add `data-drag-handle` to the DOM element that should function as the drag handle.
126126

127+
`meta?.draggable?:` Whether the inline content should be draggable.
128+
127129
<Callout type="info">
128130
_Note that since inline content is, by definition, inline, your component
129131
should also return an HTML inline element._

examples/06-custom-schema/draggable-inline-content/src/App.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ const draggableButton = createReactInlineContentSpec(
1515
default: "",
1616
},
1717
},
18-
draggable: true,
19-
content: "none"
18+
content: "none",
2019
},
2120
{
21+
meta: {
22+
draggable: true,
23+
},
2224
render: (props) => {
2325
return (
2426
<span
@@ -30,12 +32,13 @@ const draggableButton = createReactInlineContentSpec(
3032
borderRadius: "4px",
3133
cursor: "move",
3234
}}
33-
data-drag-handle>
35+
data-drag-handle
36+
>
3437
<span>{props.inlineContent.props.title}</span>
3538
</span>
3639
);
3740
},
38-
}
41+
},
3942
);
4043

4144
const schema = BlockNoteSchema.create({

packages/core/src/schema/inlineContent/createSpec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export type CustomInlineContentImplementation<
2323
T extends CustomInlineContentConfig,
2424
S extends StyleSchema,
2525
> = {
26+
meta?: {
27+
draggable?: boolean;
28+
};
29+
2630
/**
2731
* Parses an external HTML element into a inline content of this type when it returns the block props object, otherwise undefined
2832
*/
@@ -130,6 +134,7 @@ export function createInlineContentSpec<
130134
name: inlineContentConfig.type,
131135
inline: true,
132136
group: "inline",
137+
draggable: inlineContentImplementation.meta?.draggable,
133138
selectable: inlineContentConfig.content === "styled",
134139
atom: inlineContentConfig.content === "none",
135140
content: inlineContentConfig.content === "styled" ? "inline*" : "",

packages/core/src/schema/inlineContent/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { ViewMutationRecord } from "prosemirror-view";
77
export type CustomInlineContentConfig = {
88
type: string;
99
content: "styled" | "none"; // | "plain"
10-
draggable?: boolean;
1110
readonly propSchema: PropSchema;
12-
// content: "inline" | "none" | "table";
1311
};
1412
// InlineContentConfig contains the "schema" info about an InlineContent type
1513
// i.e. what props it supports, what content it supports, etc.
@@ -22,6 +20,9 @@ export type InlineContentImplementation<T extends InlineContentConfig> =
2220
T extends "link" | "text"
2321
? undefined
2422
: {
23+
meta?: {
24+
draggable?: boolean;
25+
};
2526
node: Node;
2627
toExternalHTML?: (
2728
inlineContent: any,

packages/react/src/schema/ReactInlineContentSpec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export function createReactInlineContentSpec<
110110
group: "inline",
111111
selectable: inlineContentConfig.content === "styled",
112112
atom: inlineContentConfig.content === "none",
113-
draggable: inlineContentConfig.draggable,
113+
draggable: inlineContentImplementation.meta?.draggable,
114114
content: (inlineContentConfig.content === "styled"
115115
? "inline*"
116116
: "") as T["content"] extends "styled" ? "inline*" : "",

0 commit comments

Comments
 (0)