Skip to content

Commit a49eda5

Browse files
author
kehua
committed
feat(): v3 markdown构件支持checkbox语法
Ref: POKEMON-583
1 parent caa77ef commit a49eda5

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useNodeViewContext } from "@prosemirror-adapter/react";
2+
import type { FC } from "react";
3+
import React from "react";
4+
import classNames from "classnames";
5+
6+
export const ListItem: FC = () => {
7+
const { contentRef, node, setAttrs, selected } = useNodeViewContext();
8+
const { attrs } = node;
9+
const checked = attrs?.checked;
10+
const isBullet = attrs?.listType === "bullet";
11+
return (
12+
<li
13+
className={classNames("checkboxLi", {
14+
"ProseMirror-selectednode": selected,
15+
})}
16+
>
17+
<span style={{ display: "flex", height: "1.5rem", alignItems: "center" }}>
18+
{checked != null ? (
19+
<input
20+
style={{ borderRadius: "0.25rem" }}
21+
onChange={() => setAttrs({ checked: !checked })}
22+
type="checkbox"
23+
checked={checked}
24+
/>
25+
) : isBullet ? (
26+
<span
27+
style={{
28+
height: "0.5rem",
29+
width: "0.5rem",
30+
borderRadius: "9999px",
31+
backgroundColor: "rgb(129,161,193)",
32+
}}
33+
/>
34+
) : (
35+
<span style={{ color: "rgb(136,192,208)" }}>{attrs?.label}</span>
36+
)}
37+
</span>
38+
<div style={{ minWidth: "0" }} ref={contentRef} />
39+
</li>
40+
);
41+
};

bricks/markdown/src/markdown-editor/index.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
wrapInOrderedListCommand,
2121
wrapInBlockquoteCommand,
2222
codeBlockSchema,
23+
listItemSchema,
2324
} from "@milkdown/preset-commonmark";
2425
import { nord } from "@milkdown/theme-nord";
2526
import { history, redoCommand, undoCommand } from "@milkdown/plugin-history";
@@ -49,6 +50,7 @@ import {
4950
tableTooltipCtx,
5051
} from "./components/TableWidget.tsx";
5152
import { CodeBlock } from "./components/CodeBlock.tsx";
53+
import { ListItem } from "./components/ListItem.tsx";
5254

5355
const WrappedIcon = wrapBrick<GeneralIcon, GeneralIconProps>("eo-icon");
5456

@@ -281,6 +283,11 @@ export function MarkdownEditorComponent(props: MarkdownEditorProps) {
281283
$view(codeBlockSchema.node, () =>
282284
nodeViewFactory({ component: CodeBlock })
283285
)
286+
)
287+
.use(
288+
$view(listItemSchema.node, () =>
289+
nodeViewFactory({ component: ListItem })
290+
)
284291
);
285292
}, []);
286293

bricks/markdown/src/markdown-editor/markdown-editor.shadow.css

+13
Original file line numberDiff line numberDiff line change
@@ -1988,3 +1988,16 @@ pre[class*="language-"] {
19881988
.token.entity {
19891989
cursor: help;
19901990
}
1991+
1992+
/* checkbox */
1993+
1994+
.checkboxLi {
1995+
display: flex;
1996+
align-items: flex-start;
1997+
gap: 0.5rem;
1998+
}
1999+
2000+
li p {
2001+
margin: 0 !important;
2002+
line-height: 1.5rem !important;
2003+
}

0 commit comments

Comments
 (0)