Skip to content

Commit bd44df9

Browse files
committed
Merge branch 'refs/heads/main' into releases
# Conflicts: # package-lock.json # packages/shadcn/package.json
2 parents de69d1d + f85a0d9 commit bd44df9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+660
-423
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ariakit/src/ariakitStyles.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ responsible for the majority of the styling. */
140140
padding-bottom: 7px;
141141
}
142142

143-
.bn-ak-menu:not(:focus) .bn-ak-menu-item:not(:focus)[aria-expanded="true"] {
143+
.bn-ak-menu:not(:focus)
144+
.bn-ak-menu-item:not(:focus)[aria-expanded="true"] {
144145
background-color: hsl(204 4% 0% / 7.5%);
145146
color: currentColor;
146147
}

packages/ariakit/src/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { BlockSchema, InlineContentSchema, StyleSchema } from "@blocknote/core";
1+
import {
2+
BlockSchema,
3+
InlineContentSchema,
4+
mergeCSSClasses,
5+
StyleSchema,
6+
} from "@blocknote/core";
27
import {
38
BlockNoteViewRaw,
49
Components,
@@ -95,9 +100,14 @@ export const BlockNoteView = <
95100
>(
96101
props: ComponentProps<typeof BlockNoteViewRaw<BSchema, ISchema, SSchema>>
97102
) => {
103+
const { className, ...rest } = props;
104+
98105
return (
99106
<ComponentsContext.Provider value={components}>
100-
<BlockNoteViewRaw {...props} />
107+
<BlockNoteViewRaw
108+
className={mergeCSSClasses("bn-ariakit", className || "")}
109+
{...rest}
110+
/>
101111
</ComponentsContext.Provider>
102112
);
103113
};

packages/ariakit/src/style.css

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,22 @@
2828
gap: 0.5rem;
2929
}
3030

31-
.bn-tab-panel {
31+
.bn-ariakit .bn-tab-panel {
3232
align-items: center;
3333
display: flex;
3434
flex-direction: column;
3535
gap: 0.5rem;
3636
}
3737

38-
.bn-file-input {
38+
.bn-ariakit .bn-file-input {
3939
max-width: 100%;
4040
}
4141

4242
.bn-ak-button {
4343
outline-style: none;
4444
}
4545

46-
.bn-ak-menu-item[aria-selected="true"],
47-
.bn-ak-menu-item:hover {
46+
.bn-ak-menu-item[aria-selected="true"], .bn-ak-menu-item:hover {
4847
background-color: hsl(204 100% 40%);
4948
color: hsl(204 20% 100%);
5049
}
@@ -53,12 +52,11 @@
5352
display: flex;
5453
}
5554

56-
.bn-dropdown {
55+
.bn-ariakit .bn-dropdown {
5756
overflow: visible;
5857
}
5958

60-
.bn-suggestion-menu,
61-
.bn-color-picker-dropdown {
59+
.bn-ariakit .bn-suggestion-menu, .bn-ariakit .bn-color-picker-dropdown {
6260
overflow: scroll;
6361
}
6462

@@ -85,7 +83,7 @@
8583
padding-inline: 4px;
8684
}
8785

88-
.bn-side-menu {
86+
.bn-ariakit .bn-side-menu {
8987
align-items: center;
9088
display: flex;
9189
justify-content: center;
@@ -97,35 +95,34 @@
9795
width: fit-content;
9896
}
9997

100-
.bn-panel-popover {
98+
.bn-ariakit .bn-panel-popover {
10199
background-color: transparent;
102100
border: none;
103101
box-shadow: none;
104102
}
105103

106-
.bn-table-handle {
104+
.bn-ariakit .bn-table-handle {
107105
height: fit-content;
108106
padding: 0;
109107
width: fit-content;
110108
}
111109

112-
.bn-side-menu,
113-
.bn-table-handle {
110+
.bn-ariakit .bn-side-menu,
111+
.bn-ariakit .bn-table-handle {
114112
color: gray;
115113
}
116114

117115
.bn-ak-button:where(.dark, .dark *) {
118116
color: hsl(204 20% 100%);
119117
}
120118

121-
.bn-ak-tab,
122-
.bn-file-input {
119+
.bn-ak-tab, .bn-ariakit .bn-file-input {
123120
background-color: transparent;
124121
color: black;
125122
}
126123

127124
.bn-ak-tab:where(.dark, .dark *),
128-
.bn-file-input:where(.dark, .dark *) {
125+
.bn-ariakit .bn-file-input:where(.dark, .dark *) {
129126
color: white;
130127
}
131128

packages/core/src/api/exporters/markdown/__snapshots__/lists/basic/markdown.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
1. Numbered List Item 1
55
2. Numbered List Item 2
66

7-
* \[ ] Check List Item 1
8-
* \[x] Check List Item 2
7+
* [ ] Check List Item 1
8+
* [x] Check List Item 2

packages/core/src/api/exporters/markdown/__snapshots__/lists/nested/markdown.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
2. Numbered List Item 2
88

9-
* \[ ] Check List Item 1
10-
* \[x] Check List Item 2
9+
* [ ] Check List Item 1
10+
* [x] Check List Item 2

packages/core/src/api/exporters/markdown/markdownExporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function cleanHTMLToMarkdown(cleanHTMLString: string) {
1818
.use(addSpacesToCheckboxes)
1919
.use(rehypeRemark)
2020
.use(remarkGfm)
21-
.use(remarkStringify)
21+
.use(remarkStringify, { handlers: { text: (node) => node.value } })
2222
.processSync(cleanHTMLString);
2323

2424
return markdownString.value as string;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const acceptedMIMETypes = [
2+
"blocknote/html",
3+
"Files",
4+
"text/html",
5+
"text/plain",
6+
] as const;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Extension } from "@tiptap/core";
2+
import { Plugin } from "prosemirror-state";
3+
4+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
5+
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../schema";
6+
import { handleFileInsertion } from "./handleFileInsertion";
7+
import { acceptedMIMETypes } from "./acceptedMIMETypes";
8+
9+
export const createDropFileExtension = <
10+
BSchema extends BlockSchema,
11+
I extends InlineContentSchema,
12+
S extends StyleSchema
13+
>(
14+
editor: BlockNoteEditor<BSchema, I, S>
15+
) =>
16+
Extension.create<{ editor: BlockNoteEditor<BSchema, I, S> }, undefined>({
17+
name: "dropFile",
18+
addProseMirrorPlugins() {
19+
return [
20+
new Plugin({
21+
props: {
22+
handleDOMEvents: {
23+
drop(_view, event) {
24+
if (!editor.isEditable) {
25+
return;
26+
}
27+
28+
let format: (typeof acceptedMIMETypes)[number] | null = null;
29+
for (const mimeType of acceptedMIMETypes) {
30+
if (event.dataTransfer!.types.includes(mimeType)) {
31+
format = mimeType;
32+
break;
33+
}
34+
}
35+
if (format === null) {
36+
return true;
37+
}
38+
39+
if (format === "Files") {
40+
handleFileInsertion(event, editor);
41+
return true;
42+
}
43+
44+
return false;
45+
},
46+
},
47+
},
48+
}),
49+
];
50+
},
51+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import type { BlockNoteEditor } from "../../editor/BlockNoteEditor";
2+
import { PartialBlock } from "../../blocks/defaultBlocks";
3+
import { insertOrUpdateBlock } from "../../extensions/SuggestionMenu/getDefaultSlashMenuItems";
4+
import {
5+
BlockSchema,
6+
FileBlockConfig,
7+
InlineContentSchema,
8+
StyleSchema,
9+
} from "../../schema";
10+
import { acceptedMIMETypes } from "./acceptedMIMETypes";
11+
12+
function checkMIMETypesMatch(mimeType1: string, mimeType2: string) {
13+
const types1 = mimeType1.split("/");
14+
const types2 = mimeType2.split("/");
15+
16+
if (types1.length !== 2) {
17+
throw new Error(`The string ${mimeType1} is not a valid MIME type.`);
18+
}
19+
if (types2.length !== 2) {
20+
throw new Error(`The string ${mimeType2} is not a valid MIME type.`);
21+
}
22+
23+
if (types1[1] === "*" || types2[1] === "*") {
24+
return types1[0] === types2[0];
25+
}
26+
if (types1[0] === "*" || types2[0] === "*") {
27+
return types1[1] === types2[1];
28+
}
29+
30+
return types1[0] === types2[0] && types1[1] === types2[1];
31+
}
32+
33+
export async function handleFileInsertion<
34+
BSchema extends BlockSchema,
35+
I extends InlineContentSchema,
36+
S extends StyleSchema
37+
>(event: DragEvent | ClipboardEvent, editor: BlockNoteEditor<BSchema, I, S>) {
38+
if (!editor.uploadFile) {
39+
return;
40+
}
41+
42+
const dataTransfer =
43+
"dataTransfer" in event ? event.dataTransfer : event.clipboardData;
44+
if (dataTransfer === null) {
45+
return;
46+
}
47+
48+
let format: (typeof acceptedMIMETypes)[number] | null = null;
49+
for (const mimeType of acceptedMIMETypes) {
50+
if (dataTransfer.types.includes(mimeType)) {
51+
format = mimeType;
52+
break;
53+
}
54+
}
55+
if (format !== "Files") {
56+
return;
57+
}
58+
59+
const items = dataTransfer.items;
60+
if (!items) {
61+
return;
62+
}
63+
64+
event.preventDefault();
65+
66+
const fileBlockConfigs = Object.values(editor.schema.blockSchema).filter(
67+
(blockConfig) => blockConfig.isFileBlock
68+
) as FileBlockConfig[];
69+
70+
for (let i = 0; i < items.length; i++) {
71+
// Gets file block corresponding to MIME type.
72+
let fileBlockType = "file";
73+
for (const fileBlockConfig of fileBlockConfigs) {
74+
for (const mimeType of fileBlockConfig.fileBlockAcceptMimeTypes || []) {
75+
if (checkMIMETypesMatch(items[i].type, mimeType)) {
76+
fileBlockType = fileBlockConfig.type;
77+
break;
78+
}
79+
}
80+
}
81+
82+
const file = items[i].getAsFile();
83+
if (file) {
84+
const updateData = await editor.uploadFile(file);
85+
86+
if (typeof updateData === "string") {
87+
const fileBlock = {
88+
type: fileBlockType,
89+
props: {
90+
name: file.name,
91+
url: updateData,
92+
},
93+
} as PartialBlock<BSchema, I, S>;
94+
95+
insertOrUpdateBlock(editor, fileBlock);
96+
}
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)