Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Checkbox/TODO list item block #729

Merged
merged 26 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cbc659c
v0.12.0
matthewlipski Mar 5, 2024
5ad8d6a
Merge branch 'main' into releases
matthewlipski Mar 15, 2024
686622a
v0.12.1
matthewlipski Mar 15, 2024
7d2ff32
Merge branch 'main' into releases
matthewlipski Mar 15, 2024
733b53b
v0.12.2
matthewlipski Mar 15, 2024
a2fc6d2
Merge branch 'main' into releases
matthewlipski Mar 28, 2024
fe37d2c
v0.12.3
matthewlipski Mar 28, 2024
0370cf5
Merge branch 'main' into releases
matthewlipski Apr 3, 2024
54716a4
v0.12.4
matthewlipski Apr 3, 2024
8179f73
Merge remote-tracking branch 'origin/main' into releases
YousefED May 5, 2024
501dc35
v0.13.0
YousefED May 5, 2024
1fb427a
Merge remote-tracking branch 'origin/main' into releases
YousefED May 6, 2024
1d4d4ff
v0.13.1
YousefED May 6, 2024
14386b8
Added check list default block
matthewlipski May 6, 2024
66bc32b
Implemented PR feedback
matthewlipski May 8, 2024
afc299e
Updated screenshots
matthewlipski May 8, 2024
462feac
Fixed check list item HTML/Markdown conversion
matthewlipski May 10, 2024
386520b
Merge branch 'main' into check-list-block
matthewlipski May 22, 2024
0dab655
Updated locales
matthewlipski May 22, 2024
6713eb7
Updated screenshots
matthewlipski May 22, 2024
e6b8f01
Updated check list external HTML
matthewlipski May 22, 2024
e97a02d
Updated check list parse HTML
matthewlipski May 22, 2024
55aecdd
Made check list item not editable when the editor isn't
matthewlipski May 22, 2024
82f4582
Fixes to check list item parsing, rendering, and exporting
matthewlipski May 22, 2024
b4a7458
Implemented PR feedback
matthewlipski May 23, 2024
650c2ac
Small fix
matthewlipski May 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.12.4",
"version": "0.13.1",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -9,11 +9,11 @@
"lint": "next lint"
},
"dependencies": {
"@blocknote/core": "^0.12.4",
"@blocknote/react": "^0.12.4",
"@blocknote/ariakit": "^0.12.4",
"@blocknote/mantine": "^0.12.4",
"@blocknote/shadcn": "^0.12.4",
"@blocknote/ariakit": "^0.13.1",
"@blocknote/core": "^0.13.0",
"@blocknote/mantine": "^0.13.1",
"@blocknote/react": "^0.13.1",
"@blocknote/shadcn": "^0.13.1",
"@headlessui/react": "^1.7.18",
"@mantine/core": "^7.7.1",
"@next/bundle-analyzer": "^14.1.0",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": false,
"useWorkspaces": true,
"version": "0.12.4"
"version": "0.13.1"
}
62 changes: 31 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/ariakit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"homepage": "https://github.com/TypeCellOS/BlockNote",
"private": false,
"license": "MPL-2.0",
"version": "0.12.4",
"version": "0.13.1",
"files": [
"dist",
"types",
Expand Down Expand Up @@ -49,8 +49,8 @@
},
"dependencies": {
"@ariakit/react": "^0.4.3",
"@blocknote/core": "0.12.4",
"@blocknote/react": "0.12.4",
"@blocknote/core": "^0.13.0",
"@blocknote/react": "^0.13.1",
"react": "^18",
"react-dom": "^18"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"homepage": "https://github.com/TypeCellOS/BlockNote",
"private": false,
"license": "MPL-2.0",
"version": "0.12.4",
"version": "0.13.0",
"files": [
"dist",
"types",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ul><li><p class="bn-inline-content">Bullet List Item 1</p></li><li><p class="bn-inline-content">Bullet List Item 2</p></li></ul><ol><li><p class="bn-inline-content">Numbered List Item 1</p></li><li><p class="bn-inline-content">Numbered List Item 2</p></li></ol><ul><li><div><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></div></li><li><div><input type="checkbox" checked><p class="bn-inline-content">Check List Item 2</p></div></li></ul>
Original file line number Diff line number Diff line change
@@ -0,0 +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="bulletListItem"><p class="bn-inline-content">Bullet List Item 1</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2"><div class="bn-block-content" data-content-type="bulletListItem"><p class="bn-inline-content">Bullet List Item 2</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="3"><div class="bn-block" data-node-type="blockContainer" data-id="3"><div class="bn-block-content" data-content-type="numberedListItem" data-index="null"><p class="bn-inline-content">Numbered List Item 1</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="4"><div class="bn-block" data-node-type="blockContainer" data-id="4"><div class="bn-block-content" data-content-type="numberedListItem" data-index="null"><p class="bn-inline-content">Numbered List Item 2</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="5"><div class="bn-block" data-node-type="blockContainer" data-id="5"><div class="bn-block-content" data-content-type="checkListItem" data-checked="false"><div><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="6"><div class="bn-block" data-node-type="blockContainer" data-id="6"><div class="bn-block-content" data-content-type="checkListItem" data-checked="true"><div><input type="checkbox" checked=""><p class="bn-inline-content">Check List Item 2</p></div></div></div></div></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ul><li><p class="bn-inline-content">Bullet List Item 1</p></li><li><p class="bn-inline-content">Bullet List Item 2</p><ol><li><p class="bn-inline-content">Numbered List Item 1</p></li><li><p class="bn-inline-content">Numbered List Item 2</p><ul><li><div><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></div></li><li><div><input type="checkbox" checked><p class="bn-inline-content">Check List Item 2</p></div></li></ul></li></ol></li></ul>
Original file line number Diff line number Diff line change
@@ -0,0 +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="bulletListItem"><p class="bn-inline-content">Bullet List Item 1</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="2"><div class="bn-block" data-node-type="blockContainer" data-id="2"><div class="bn-block-content" data-content-type="bulletListItem"><p class="bn-inline-content">Bullet List Item 2</p></div><div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="3"><div class="bn-block" data-node-type="blockContainer" data-id="3"><div class="bn-block-content" data-content-type="numberedListItem" data-index="null"><p class="bn-inline-content">Numbered List Item 1</p></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="4"><div class="bn-block" data-node-type="blockContainer" data-id="4"><div class="bn-block-content" data-content-type="numberedListItem" data-index="null"><p class="bn-inline-content">Numbered List Item 2</p></div><div class="bn-block-group" data-node-type="blockGroup"><div class="bn-block-outer" data-node-type="blockOuter" data-id="5"><div class="bn-block" data-node-type="blockContainer" data-id="5"><div class="bn-block-content" data-content-type="checkListItem" data-checked="false"><div><input type="checkbox"><p class="bn-inline-content">Check List Item 1</p></div></div></div></div><div class="bn-block-outer" data-node-type="blockOuter" data-id="6"><div class="bn-block" data-node-type="blockContainer" data-id="6"><div class="bn-block-content" data-content-type="checkListItem" data-checked="true"><div><input type="checkbox" checked=""><p class="bn-inline-content">Check List Item 2</p></div></div></div></div></div></div></div></div></div></div></div>
5 changes: 4 additions & 1 deletion packages/core/src/api/exporters/html/externalHTMLExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export const createExternalHTMLExporter = <
.use(rehypeParse, { fragment: true })
.use(simplifyBlocks, {
orderedListItemBlockTypes: new Set<string>(["numberedListItem"]),
unorderedListItemBlockTypes: new Set<string>(["bulletListItem"]),
unorderedListItemBlockTypes: new Set<string>([
"bulletListItem",
"checkListItem",
]),
})
.use(rehypeStringify)
.processSync(serializeProseMirrorFragment(fragment, serializer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) {
) as HASTElement;

// Adds only the content inside the block to the active list.
listItemElement.children.push(blockContent.children[0]);
listItemElement.children.push(...blockContent.children);
// Nested blocks have already been processed in the recursive function call, so the resulting elements are
// also added to the active list.
if (blockGroup !== null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
* Bullet List Item 1
* Bullet List Item 2

1. Numbered List Item 1
2. Numbered List Item 2

* \[ ] Check List Item 1
* \[x] Check List Item 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* Bullet List Item 1

* Bullet List Item 2

1. Numbered List Item 1

2. Numbered List Item 2

* \[ ] Check List Item 1
* \[x] Check List Item 2
2 changes: 2 additions & 0 deletions packages/core/src/api/exporters/markdown/markdownExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import type { BlockNoteEditor } from "../../../editor/BlockNoteEditor";
import { BlockSchema, InlineContentSchema, StyleSchema } from "../../../schema";
import { createExternalHTMLExporter } from "../html/externalHTMLExporter";
import { removeUnderlines } from "./removeUnderlinesRehypePlugin";
import { addSpacesToCheckboxes } from "./util/addSpacesToCheckboxesRehypePlugin";

export function cleanHTMLToMarkdown(cleanHTMLString: string) {
const markdownString = unified()
.use(rehypeParse, { fragment: true })
.use(removeUnderlines)
.use(addSpacesToCheckboxes)
.use(rehypeRemark)
.use(remarkGfm)
.use(remarkStringify)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Element as HASTElement, Parent as HASTParent } from "hast";
import { fromDom } from "hast-util-from-dom";

/**
* Rehype plugin which adds a space after each checkbox input element. This is
* because remark doesn't add any spaces between the checkbox input and the text
* itself, but these are needed for correct Markdown syntax.
*/
export function addSpacesToCheckboxes() {
const helper = (tree: HASTParent) => {
if (tree.children && "length" in tree.children && tree.children.length) {
for (let i = tree.children.length - 1; i >= 0; i--) {
const child = tree.children[i];
const nextChild =
i + 1 < tree.children.length ? tree.children[i + 1] : undefined;

// Checks for paragraph element after checkbox input element.
if (
child.type === "element" &&
child.tagName === "input" &&
child.properties?.type === "checkbox" &&
nextChild?.type === "element" &&
nextChild.tagName === "p"
) {
// Converts paragraph to span, otherwise remark will think it needs to
// be on a new line.
nextChild.tagName = "span";
// Adds a space after the checkbox input element.
nextChild.children.splice(
0,
0,
fromDom(document.createTextNode(" ")) as HASTElement
);
} else {
helper(child as HASTParent);
}
}
}
};

return helper;
}
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,56 @@ exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert
}
`;

exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert lists/basic to/from prosemirror 1`] = `
{
"attrs": {
"backgroundColor": "default",
"id": "1",
"textColor": "default",
},
"content": [
{
"attrs": {
"textAlignment": "left",
},
"content": [
{
"text": "Bullet List Item 1",
"type": "text",
},
],
"type": "bulletListItem",
},
],
"type": "blockContainer",
}
`;

exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert lists/nested to/from prosemirror 1`] = `
{
"attrs": {
"backgroundColor": "default",
"id": "1",
"textColor": "default",
},
"content": [
{
"attrs": {
"textAlignment": "left",
},
"content": [
{
"text": "Bullet List Item 1",
"type": "text",
},
],
"type": "bulletListItem",
},
],
"type": "blockContainer",
}
`;

exports[`Test BlockNote-Prosemirror conversion > Case: default schema > Convert paragraph/basic to/from prosemirror 1`] = `
{
"attrs": {
Expand Down