Skip to content

Commit 52a018c

Browse files
committed
refactor: move meta to block implementation instead of block config
1 parent 422cccb commit 52a018c

File tree

20 files changed

+81
-87
lines changed

20 files changed

+81
-87
lines changed

examples/06-custom-schema/04-pdf-file-block/src/PDF.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export const PDF = createReactBlockSpec(
5252
},
5353
},
5454
content: "none",
55+
},
56+
{
5557
meta: {
5658
fileBlockAccept: ["application/pdf"],
5759
},
58-
},
59-
{
6060
render: (props) => (
6161
<ResizableFileBlockWrapper
6262
{...(props as any)}

packages/core/src/api/clipboard/fromClipboard/handleFileInsertion.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ export async function handleFileInsertion<
108108
for (let i = 0; i < items.length; i++) {
109109
// Gets file block corresponding to MIME type.
110110
let fileBlockType = "file";
111-
for (const fileBlockConfig of Object.values(editor.schema.blockSchema)) {
112-
for (const mimeType of fileBlockConfig.meta?.fileBlockAccept || []) {
111+
for (const blockSpec of Object.values(editor.schema.blockSpecs)) {
112+
for (const mimeType of blockSpec.implementation.meta?.fileBlockAccept ||
113+
[]) {
113114
const isFileExtension = mimeType.startsWith(".");
114115
const file = items[i].getAsFile();
115116

@@ -124,7 +125,7 @@ export async function handleFileInsertion<
124125
mimeType,
125126
))
126127
) {
127-
fileBlockType = fileBlockConfig.type;
128+
fileBlockType = blockSpec.config.type;
128129
break;
129130
}
130131
}

packages/core/src/blocks/Audio/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ export const createAudioBlockConfig = createBlockConfig(
4242
},
4343
},
4444
content: "none",
45-
meta: {
46-
fileBlockAccept: ["audio/*"],
47-
},
4845
}) as const,
4946
);
5047

@@ -157,6 +154,9 @@ export const audioToExternalHTML =
157154
export const createAudioBlockSpec = createBlockSpec(
158155
createAudioBlockConfig,
159156
(config) => ({
157+
meta: {
158+
fileBlockAccept: ["audio/*"],
159+
},
160160
parse: audioParse(config),
161161
render: audioRender(config),
162162
toExternalHTML: audioToExternalHTML(config),

packages/core/src/blocks/Code/block.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ export const createCodeBlockConfig = createBlockConfig(
6161
},
6262
},
6363
content: "inline",
64-
meta: {
65-
code: true,
66-
defining: true,
67-
isolating: false,
68-
},
6964
}) as const,
7065
);
7166

7267
export const createCodeBlockSpec = createBlockSpec(
7368
createCodeBlockConfig,
7469
(options) => ({
70+
meta: {
71+
code: true,
72+
defining: true,
73+
isolating: false,
74+
},
7575
parse: (e) => {
7676
if (e.tagName !== "PRE") {
7777
return undefined;

packages/core/src/blocks/File/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ export const createFileBlockConfig = createBlockConfig(
2525
},
2626
},
2727
content: "none" as const,
28-
meta: {
29-
fileBlockAccept: ["*/*"],
30-
},
3128
}) as const,
3229
);
3330

@@ -59,6 +56,9 @@ export const fileParse = () => (element: HTMLElement) => {
5956
};
6057

6158
export const createFileBlockSpec = createBlockSpec(createFileBlockConfig, {
59+
meta: {
60+
fileBlockAccept: ["*/*"],
61+
},
6262
parse: fileParse(),
6363
render(block, editor) {
6464
return createFileBlockWrapper(block, editor);

packages/core/src/blocks/Heading/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export const createHeadingBlockConfig = createBlockConfig(
3030
: {}),
3131
},
3232
content: "inline",
33-
meta: {
34-
isolating: false,
35-
},
3633
}) as const,
3734
);
3835

3936
export const createHeadingBlockSpec = createBlockSpec(
4037
createHeadingBlockConfig,
4138
({ allowToggleHeadings = true }: HeadingOptions = {}) => ({
39+
meta: {
40+
isolating: false,
41+
},
4242
parse(e) {
4343
let level: number;
4444
switch (e.tagName) {

packages/core/src/blocks/Image/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ export const createImageBlockConfig = createBlockConfig(
4747
},
4848
},
4949
content: "none" as const,
50-
meta: {
51-
fileBlockAccept: ["image/*"],
52-
},
5350
}) as const,
5451
);
5552

@@ -172,6 +169,9 @@ export const imageToExternalHTML =
172169
export const createImageBlockSpec = createBlockSpec(
173170
createImageBlockConfig,
174171
(config) => ({
172+
meta: {
173+
fileBlockAccept: ["image/*"],
174+
},
175175
parse: imageParse(config),
176176
render: imageRender(config),
177177
toExternalHTML: imageToExternalHTML(config),

packages/core/src/blocks/ListItem/BulletListItem/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ export const createBulletListItemBlockConfig = createBlockConfig(
1414
...defaultProps,
1515
},
1616
content: "inline",
17-
meta: {
18-
isolating: false,
19-
},
2017
}) as const,
2118
);
2219

2320
export const createBulletListItemBlockSpec = createBlockSpec(
2421
createBulletListItemBlockConfig,
2522
{
23+
meta: {
24+
isolating: false,
25+
},
2626
parse(element) {
2727
if (element.tagName !== "LI") {
2828
return false;

packages/core/src/blocks/ListItem/CheckListItem/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ export const createCheckListItemConfig = createBlockConfig(
1515
checked: { default: false, type: "boolean" },
1616
},
1717
content: "inline",
18-
meta: {
19-
isolating: false,
20-
},
2118
}) as const,
2219
);
2320

2421
export const createCheckListItemBlockSpec = createBlockSpec(
2522
createCheckListItemConfig,
2623
{
24+
meta: {
25+
isolating: false,
26+
},
2727
parse(element) {
2828
if (element.tagName === "input") {
2929
// Ignore if we already parsed an ancestor list item to avoid double-parsing.

packages/core/src/blocks/ListItem/NumberedListItem/block.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export const createNumberedListItemBlockConfig = createBlockConfig(
1616
start: { default: undefined, type: "number" } as const,
1717
},
1818
content: "inline",
19-
meta: {
20-
isolating: false,
21-
},
2219
}) as const,
2320
);
2421

2522
export const createNumberedListItemBlockSpec = createBlockSpec(
2623
createNumberedListItemBlockConfig,
2724
{
25+
meta: {
26+
isolating: false,
27+
},
2828
parse(element) {
2929
if (element.tagName !== "LI") {
3030
return false;

0 commit comments

Comments
 (0)