Skip to content
Draft
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
41 changes: 41 additions & 0 deletions bricks/markdown/src/markdown-editor/components/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useNodeViewContext } from "@prosemirror-adapter/react";
import type { FC } from "react";
import React from "react";
import classNames from "classnames";

export const ListItem: FC = () => {
const { contentRef, node, setAttrs, selected } = useNodeViewContext();
const { attrs } = node;
const checked = attrs?.checked;
const isBullet = attrs?.listType === "bullet";
return (
<li
className={classNames("listItem", {
"ProseMirror-selectednode": selected,
})}
>
<span style={{ display: "flex", height: "1.5rem", alignItems: "center" }}>
{checked != null ? (
<input
style={{ borderRadius: "0.25rem" }}
onChange={() => setAttrs({ checked: !checked })}
type="checkbox"
checked={checked}
/>
) : isBullet ? (
<span
style={{
height: "0.5rem",
width: "0.5rem",
borderRadius: "9999px",
backgroundColor: "rgb(129,161,193)",
}}
/>
) : (
<span style={{ color: "rgb(136,192,208)" }}>{attrs?.label}</span>
)}
</span>
<div style={{ minWidth: "0" }} ref={contentRef} />
</li>
);
};
7 changes: 7 additions & 0 deletions bricks/markdown/src/markdown-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
wrapInOrderedListCommand,
wrapInBlockquoteCommand,
codeBlockSchema,
listItemSchema,
} from "@milkdown/preset-commonmark";
import { nord } from "@milkdown/theme-nord";
import { history, redoCommand, undoCommand } from "@milkdown/plugin-history";
Expand Down Expand Up @@ -48,6 +49,7 @@ import {
tableTooltipCtx,
} from "./components/TableWidget.tsx";
import { CodeBlock } from "./components/CodeBlock.tsx";
import { ListItem } from "./components/ListItem.tsx";
import type { FormItem, FormItemProps } from "@next-bricks/form/form-item";
import { FormItemElementBase } from "@next-shared/form";

Expand Down Expand Up @@ -316,6 +318,11 @@ export function MarkdownEditorComponent(props: MarkdownEditorProps) {
$view(codeBlockSchema.node, () =>
nodeViewFactory({ component: CodeBlock })
)
)
.use(
$view(listItemSchema.node, () =>
nodeViewFactory({ component: ListItem })
)
);
}, []);

Expand Down
13 changes: 13 additions & 0 deletions bricks/markdown/src/markdown-editor/markdown-editor.shadow.css
Original file line number Diff line number Diff line change
Expand Up @@ -1988,3 +1988,16 @@ pre[class*="language-"] {
.token.entity {
cursor: help;
}

/* checkbox */

.listItem {
display: flex;
align-items: flex-start;
gap: 0.5rem;
}

li p {
margin: 0 !important;
line-height: 1.5rem !important;
}