Commit 22519b57 authored by memoclaw's avatar memoclaw

fix(web): prevent MemoContent prop leaks

parent 45b21530
...@@ -15,7 +15,7 @@ interface TagProps extends React.HTMLAttributes<HTMLSpanElement> { ...@@ -15,7 +15,7 @@ interface TagProps extends React.HTMLAttributes<HTMLSpanElement> {
children?: React.ReactNode; children?: React.ReactNode;
} }
export const Tag: React.FC<TagProps> = ({ "data-tag": dataTag, children, className, style, ...props }) => { export const Tag: React.FC<TagProps> = ({ "data-tag": dataTag, children, className, style, node: _node, ...props }) => {
const { parentPage } = useMemoViewContext(); const { parentPage } = useMemoViewContext();
const location = useLocation(); const location = useLocation();
const navigateTo = useNavigateTo(); const navigateTo = useNavigateTo();
...@@ -66,7 +66,7 @@ export const Tag: React.FC<TagProps> = ({ "data-tag": dataTag, children, classNa ...@@ -66,7 +66,7 @@ export const Tag: React.FC<TagProps> = ({ "data-tag": dataTag, children, classNa
return ( return (
<span <span
className={cn( className={cn(
"inline-flex items-center px-1 text-sm rounded-full border cursor-pointer transition-opacity hover:opacity-75", "inline-flex items-center align-baseline px-1.5 py-0.5 text-[0.9em] leading-none font-normal rounded-full border cursor-pointer transition-opacity hover:opacity-75",
!bgHex && "border-primary text-primary bg-primary/15", !bgHex && "border-primary text-primary bg-primary/15",
className, className,
)} )}
......
...@@ -55,10 +55,11 @@ const MemoContent = (props: MemoContentProps) => { ...@@ -55,10 +55,11 @@ const MemoContent = (props: MemoContentProps) => {
components={{ components={{
// Child components consume from MemoViewContext directly // Child components consume from MemoViewContext directly
input: ((inputProps: React.ComponentProps<"input"> & { node?: Element }) => { input: ((inputProps: React.ComponentProps<"input"> & { node?: Element }) => {
if (inputProps.node && isTaskListItemNode(inputProps.node)) { const { node, ...rest } = inputProps;
if (node && isTaskListItemNode(node)) {
return <TaskListItem {...inputProps} />; return <TaskListItem {...inputProps} />;
} }
return <input {...inputProps} />; return <input {...rest} />;
}) as React.ComponentType<React.ComponentProps<"input">>, }) as React.ComponentType<React.ComponentProps<"input">>,
span: ((spanProps: React.ComponentProps<"span"> & { node?: Element }) => { span: ((spanProps: React.ComponentProps<"span"> & { node?: Element }) => {
const { node, ...rest } = spanProps; const { node, ...rest } = spanProps;
...@@ -68,16 +69,40 @@ const MemoContent = (props: MemoContentProps) => { ...@@ -68,16 +69,40 @@ const MemoContent = (props: MemoContentProps) => {
return <span {...rest} />; return <span {...rest} />;
}) as React.ComponentType<React.ComponentProps<"span">>, }) as React.ComponentType<React.ComponentProps<"span">>,
// Headings // Headings
h1: ({ children }) => <Heading level={1}>{children}</Heading>, h1: ({ children, ...props }) => (
h2: ({ children }) => <Heading level={2}>{children}</Heading>, <Heading level={1} {...props}>
h3: ({ children }) => <Heading level={3}>{children}</Heading>, {children}
h4: ({ children }) => <Heading level={4}>{children}</Heading>, </Heading>
h5: ({ children }) => <Heading level={5}>{children}</Heading>, ),
h6: ({ children }) => <Heading level={6}>{children}</Heading>, h2: ({ children, ...props }) => (
<Heading level={2} {...props}>
{children}
</Heading>
),
h3: ({ children, ...props }) => (
<Heading level={3} {...props}>
{children}
</Heading>
),
h4: ({ children, ...props }) => (
<Heading level={4} {...props}>
{children}
</Heading>
),
h5: ({ children, ...props }) => (
<Heading level={5} {...props}>
{children}
</Heading>
),
h6: ({ children, ...props }) => (
<Heading level={6} {...props}>
{children}
</Heading>
),
// Block elements // Block elements
p: ({ children }) => <Paragraph>{children}</Paragraph>, p: ({ children, ...props }) => <Paragraph {...props}>{children}</Paragraph>,
blockquote: ({ children }) => <Blockquote>{children}</Blockquote>, blockquote: ({ children, ...props }) => <Blockquote {...props}>{children}</Blockquote>,
hr: () => <HorizontalRule />, hr: (props) => <HorizontalRule {...props} />,
// Lists // Lists
ul: ({ children, ...props }) => <List {...props}>{children}</List>, ul: ({ children, ...props }) => <List {...props}>{children}</List>,
ol: ({ children, ...props }) => ( ol: ({ children, ...props }) => (
...@@ -88,15 +113,15 @@ const MemoContent = (props: MemoContentProps) => { ...@@ -88,15 +113,15 @@ const MemoContent = (props: MemoContentProps) => {
li: ({ children, ...props }) => <ListItem {...props}>{children}</ListItem>, li: ({ children, ...props }) => <ListItem {...props}>{children}</ListItem>,
// Inline elements // Inline elements
a: ({ children, ...props }) => <Link {...props}>{children}</Link>, a: ({ children, ...props }) => <Link {...props}>{children}</Link>,
code: ({ children }) => <InlineCode>{children}</InlineCode>, code: ({ children, ...props }) => <InlineCode {...props}>{children}</InlineCode>,
img: ({ ...props }) => <Image {...props} />, img: ({ ...props }) => <Image {...props} />,
// Code blocks // Code blocks
pre: CodeBlock, pre: CodeBlock,
// Tables // Tables
table: ({ children }) => <Table>{children}</Table>, table: ({ children, ...props }) => <Table {...props}>{children}</Table>,
thead: ({ children }) => <TableHead>{children}</TableHead>, thead: ({ children, ...props }) => <TableHead {...props}>{children}</TableHead>,
tbody: ({ children }) => <TableBody>{children}</TableBody>, tbody: ({ children, ...props }) => <TableBody {...props}>{children}</TableBody>,
tr: ({ children }) => <TableRow>{children}</TableRow>, tr: ({ children, ...props }) => <TableRow {...props}>{children}</TableRow>,
th: ({ children, ...props }) => <TableHeaderCell {...props}>{children}</TableHeaderCell>, th: ({ children, ...props }) => <TableHeaderCell {...props}>{children}</TableHeaderCell>,
td: ({ children, ...props }) => <TableCell {...props}>{children}</TableCell>, td: ({ children, ...props }) => <TableCell {...props}>{children}</TableCell>,
}} }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment