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..ce8ed33e7 --- /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 20cf2ab4e..cb549f83f 100644 --- a/bricks/markdown/src/markdown-editor/index.tsx +++ b/bricks/markdown/src/markdown-editor/index.tsx @@ -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"; @@ -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"; @@ -316,6 +318,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 bffc8a426..10e1e0103 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 */ + +.listItem { + display: flex; + align-items: flex-start; + gap: 0.5rem; +} + +li p { + margin: 0 !important; + line-height: 1.5rem !important; +}