Skip to content

Commit ed517c6

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

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 41 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
wrapInOrderedListCommand,
2020
wrapInBlockquoteCommand,
2121
codeBlockSchema,
22+
listItemSchema,
2223
} from "@milkdown/preset-commonmark";
2324
import { nord } from "@milkdown/theme-nord";
2425
import { history, redoCommand, undoCommand } from "@milkdown/plugin-history";
@@ -48,11 +49,13 @@ import {
4849
tableTooltipCtx,
4950
} from "./components/TableWidget.tsx";
5051
import { CodeBlock } from "./components/CodeBlock.tsx";
52+
import { ListItem } from "./components/ListItem.tsx";
5153
import type { FormItem, FormItemProps } from "@next-bricks/form/form-item";
5254
import { FormItemElementBase } from "@next-shared/form";
5355

5456
const WrappedFormItem = wrapBrick<FormItem, FormItemProps>("eo-form-item");
5557

58+
5659
const WrappedIcon = wrapBrick<GeneralIcon, GeneralIconProps>("eo-icon");
5760

5861
const MenuButton: FC<MenuButtonProps> = ({ icon, onClick, tooltip }) => {
@@ -308,6 +311,11 @@ export function MarkdownEditorComponent(props: MarkdownEditorProps) {
308311
$view(codeBlockSchema.node, () =>
309312
nodeViewFactory({ component: CodeBlock })
310313
)
314+
)
315+
.use(
316+
$view(listItemSchema.node, () =>
317+
nodeViewFactory({ component: ListItem })
318+
)
311319
);
312320
}, []);
313321

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

Lines changed: 13 additions & 0 deletions
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)