Skip to content

Commit

Permalink
手动设置为可选
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Nov 7, 2024
1 parent 61c105f commit 00f245c
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 21 deletions.
34 changes: 27 additions & 7 deletions src/MarkdownEditor/editor/elements/LinkCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,28 @@ export function LinkCard({
EditorUtils.focus(store?.editor);
}
}}
style={{
display: 'flex',
}}
>
<div
style={{
display: 'flex',
height: '100%',
minWidth: '0',
fontSize: 60,
minHeight: '100px',
lineHeight: '100px',
}}
>
{children.at(0)}
</div>
<DragHandle />
<div
ref={htmlRef}
style={{
flex: 1,
}}
className={classNames(`${baseCls}-container`, hashId)}
>
<div
Expand Down Expand Up @@ -149,16 +167,18 @@ export function LinkCard({
/>
</div>
</div>
<span
<div
style={{
fontSize: (htmlRef.current?.clientHeight || 200) * 0.75,
width: '2px',
height: (htmlRef.current?.clientHeight || 200) * 0.75,
lineHeight: 1,
display: 'flex',
height: '100%',
minWidth: '4px',
minHeight: '100px',
fontSize: 60,
lineHeight: '100px',
}}
>
{children}
</span>
{children.at(-1)}
</div>
</div>
</div>,
);
Expand Down
6 changes: 4 additions & 2 deletions src/MarkdownEditor/editor/elements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export const MElement = (props: RenderElementProps) => {
return (
<span
style={{
minWidth: 2,
minWidth: 4,
height: '100%',
}}
{...props.attributes}
>
Expand All @@ -108,7 +109,8 @@ export const MElement = (props: RenderElementProps) => {
return (
<span
style={{
minWidth: 2,
minWidth: 4,
height: '100%',
alignSelf: 'end',
}}
{...props.attributes}
Expand Down
77 changes: 70 additions & 7 deletions src/MarkdownEditor/editor/parser/parserMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,16 @@ const parserBlock = (
alt: img.alt,
height: img?.height,
url: decodeURIComponent(img?.url || ''),
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
};
} else {
if (currentNode.value === '<br/>') {
Expand Down Expand Up @@ -401,7 +410,16 @@ const parserBlock = (
alt: img.alt,
height: img?.height,
url: img?.url,
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
};
} else {
el = { text: currentNode.value };
Expand All @@ -418,7 +436,16 @@ const parserBlock = (
case 'image':
el = {
type: 'media',
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
url: decodeURIComponent(currentNode?.url),
alt: currentNode.alt,
} as MediaNode;
Expand Down Expand Up @@ -517,7 +544,16 @@ const parserBlock = (
type: 'attach',
url: decodeURIComponent(attach?.url),
size: attach.size,
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
name: name ? name[1] : attach.url,
};
break;
Expand All @@ -538,7 +574,16 @@ const parserBlock = (
...config,
type: 'link-card',
url: decodeURIComponent(link?.url),
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
name: link.title,
};
break;
Expand All @@ -556,7 +601,16 @@ const parserBlock = (
}
el.push({
type: 'media',
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
url: decodeURIComponent(c.url),
alt: c.alt,
});
Expand All @@ -566,7 +620,16 @@ const parserBlock = (
el.push({
type: 'media',
align: img.align,
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
url: decodeURIComponent(img?.url || ''),
height: img.height,
alt: img.alt,
Expand Down
11 changes: 10 additions & 1 deletion src/MarkdownEditor/editor/plugins/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,16 @@ export const MdElements: Record<string, MdNode> = {
type: 'media',
alt: match[1],
url: match[2],
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
},
]);
return true;
Expand Down
15 changes: 14 additions & 1 deletion src/MarkdownEditor/editor/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ export const withMarkdown = (editor: Editor) => {
}
return;
}
const parentNode = Node.get(editor, Path.parent(operation.path));
if ('link-card' === parentNode.type) {
Transforms.removeNodes(editor, {
at: Path.parent(operation.path),
});
return;
}
}

apply(operation);
Expand All @@ -173,7 +180,13 @@ export const withMarkdown = (editor: Editor) => {
Range.isCollapsed(selection)
) {
const node = Node.get(editor, Path.parent(selection.anchor.path));
if (node.type === 'card-before' || node.type === 'card-after') {
if (node.type === 'card-before') {
return;
}
if (node.type === 'card-after') {
Transforms.removeNodes(editor, {
at: Path.parent(selection.anchor.path),
});
return;
}
}
Expand Down
33 changes: 30 additions & 3 deletions src/MarkdownEditor/editor/utils/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@ export class KeyboardTask {
{
type: 'media',
url: url,
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
},
],
{
Expand All @@ -194,7 +203,16 @@ export class KeyboardTask {
{
type: 'media',
url: url,
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
},
],
{
Expand All @@ -208,7 +226,16 @@ export class KeyboardTask {
{
type: 'media',
url: url,
children: [{ text: '' }],
children: [
{
type: 'card-before',
children: [{ text: '' }],
},
{
type: 'card-after',
children: [{ text: '' }],
},
],
},
],
{
Expand Down

1 comment on commit 00f245c

@vercel
Copy link

@vercel vercel bot commented on 00f245c Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.