diff --git a/bricks/markdown/src/markdown-editor/components/ListItem.tsx b/bricks/markdown/src/markdown-editor/components/ListItem.tsx new file mode 100644 index 000000000..78986f870 --- /dev/null +++ b/bricks/markdown/src/markdown-editor/components/ListItem.tsx @@ -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 ( +
  • + + {checked != null ? ( + setAttrs({ checked: !checked })} + type="checkbox" + checked={checked} + /> + ) : isBullet ? ( + + ) : ( + {attrs?.label} + )} + +
    +
  • + ); +}; diff --git a/bricks/markdown/src/markdown-editor/index.tsx b/bricks/markdown/src/markdown-editor/index.tsx index 47580dd1f..2ea4b66af 100644 --- a/bricks/markdown/src/markdown-editor/index.tsx +++ b/bricks/markdown/src/markdown-editor/index.tsx @@ -20,6 +20,7 @@ import { wrapInOrderedListCommand, wrapInBlockquoteCommand, codeBlockSchema, + listItemSchema, } from "@milkdown/preset-commonmark"; import { nord } from "@milkdown/theme-nord"; import { history, redoCommand, undoCommand } from "@milkdown/plugin-history"; @@ -49,6 +50,7 @@ import { tableTooltipCtx, } from "./components/TableWidget.tsx"; import { CodeBlock } from "./components/CodeBlock.tsx"; +import { ListItem } from "./components/ListItem.tsx"; const WrappedIcon = wrapBrick("eo-icon"); @@ -281,6 +283,11 @@ export function MarkdownEditorComponent(props: MarkdownEditorProps) { $view(codeBlockSchema.node, () => nodeViewFactory({ component: CodeBlock }) ) + ) + .use( + $view(listItemSchema.node, () => + nodeViewFactory({ component: ListItem }) + ) ); }, []); diff --git a/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css b/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css index 02107204f..49ba87db9 100644 --- a/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css +++ b/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css @@ -1988,3 +1988,16 @@ pre[class*="language-"] { .token.entity { cursor: help; } + +/* checkbox */ + +.checkboxLi { + display: flex; + align-items: flex-start; + gap: 0.5rem; +} + +li p { + margin: 0 !important; + line-height: 1.5rem !important; +}