From 10f46839d76719c5db2734deee5228b4c26f1836 Mon Sep 17 00:00:00 2001 From: kehua Date: Mon, 24 Jul 2023 15:28:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat():=20v3=20markdown=E6=9E=84=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81checkbox=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref: POKEMON-583 --- .../markdown-editor/components/ListItem.tsx | 41 +++++++++++++++++++ bricks/markdown/src/markdown-editor/index.tsx | 8 ++++ .../markdown-editor.shadow.css | 13 ++++++ 3 files changed, 62 insertions(+) create mode 100644 bricks/markdown/src/markdown-editor/components/ListItem.tsx 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 20cf2ab4e..75c400133 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,11 +49,13 @@ 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"; const WrappedFormItem = wrapBrick("eo-form-item"); + const WrappedIcon = wrapBrick("eo-icon"); const MenuButton: FC = ({ icon, onClick, tooltip }) => { @@ -316,6 +319,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..6fdb6b09b 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; +} From d6b04f04db4d177356c001a2f2988c15cbbd8c82 Mon Sep 17 00:00:00 2001 From: kehua Date: Wed, 26 Jul 2023 12:05:40 +0800 Subject: [PATCH 2/3] feat(): update classname --- bricks/markdown/src/markdown-editor/components/ListItem.tsx | 2 +- bricks/markdown/src/markdown-editor/markdown-editor.shadow.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bricks/markdown/src/markdown-editor/components/ListItem.tsx b/bricks/markdown/src/markdown-editor/components/ListItem.tsx index 78986f870..ce8ed33e7 100644 --- a/bricks/markdown/src/markdown-editor/components/ListItem.tsx +++ b/bricks/markdown/src/markdown-editor/components/ListItem.tsx @@ -10,7 +10,7 @@ export const ListItem: FC = () => { const isBullet = attrs?.listType === "bullet"; return (
  • diff --git a/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css b/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css index 6fdb6b09b..10e1e0103 100644 --- a/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css +++ b/bricks/markdown/src/markdown-editor/markdown-editor.shadow.css @@ -1991,7 +1991,7 @@ pre[class*="language-"] { /* checkbox */ -.checkboxLi { +.listItem { display: flex; align-items: flex-start; gap: 0.5rem; From 05bec0d43f0955388daecbd079cc1cc85d81180d Mon Sep 17 00:00:00 2001 From: kehua Date: Tue, 1 Aug 2023 17:01:43 +0800 Subject: [PATCH 3/3] style(): remove the blank line --- bricks/markdown/src/markdown-editor/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/bricks/markdown/src/markdown-editor/index.tsx b/bricks/markdown/src/markdown-editor/index.tsx index 75c400133..cb549f83f 100644 --- a/bricks/markdown/src/markdown-editor/index.tsx +++ b/bricks/markdown/src/markdown-editor/index.tsx @@ -55,7 +55,6 @@ import { FormItemElementBase } from "@next-shared/form"; const WrappedFormItem = wrapBrick("eo-form-item"); - const WrappedIcon = wrapBrick("eo-icon"); const MenuButton: FC = ({ icon, onClick, tooltip }) => {