Skip to content

Commit 949efdf

Browse files
committed
移除 ColumnIcon 组件及相关代码,优化插入自动完成组件的逻辑
1 parent 294f991 commit 949efdf

File tree

1 file changed

+63
-50
lines changed

1 file changed

+63
-50
lines changed

src/MarkdownEditor/editor/tools/InsertAutocomplete.tsx

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ const Quote = () => {
6464
);
6565
};
6666

67-
const ColumnIcon = () => {
68-
return (
69-
<svg
70-
className="ant-menu-item-icon"
71-
viewBox="0 0 1024 1024"
72-
version="1.1"
73-
width="1em"
74-
height="1em"
75-
>
76-
<path
77-
fill="currentColor"
78-
d="M880 112c17.7 0 32 14.3 32 32v736c0 17.7-14.3 32-32 32H144c-17.7 0-32-14.3-32-32V144c0-17.7 14.3-32 32-32z m-404 72H184v656h292V184z m364 0H548v656h292V184z"
79-
/>
80-
</svg>
81-
);
82-
};
67+
// const ColumnIcon = () => {
68+
// return (
69+
// <svg
70+
// className="ant-menu-item-icon"
71+
// viewBox="0 0 1024 1024"
72+
// version="1.1"
73+
// width="1em"
74+
// height="1em"
75+
// >
76+
// <path
77+
// fill="currentColor"
78+
// d="M880 112c17.7 0 32 14.3 32 32v736c0 17.7-14.3 32-32 32H144c-17.7 0-32-14.3-32-32V144c0-17.7 14.3-32 32-32z m-404 72H184v656h292V184z m364 0H548v656h292V184z"
79+
// />
80+
// </svg>
81+
// );
82+
// };
8383

8484
export type InsertAutocompleteItem = {
8585
label: string[];
@@ -130,12 +130,12 @@ export const getInsertOptions: (ctx: { isTop: boolean }) => InsertOptions[] = (
130130
task: 'insertTable',
131131
icon: <TableOutlined />,
132132
},
133-
{
134-
label: ['分栏', 'Column'],
135-
key: 'column',
136-
task: 'insertColumn',
137-
icon: <ColumnIcon />,
138-
},
133+
// {
134+
// label: ['分栏', 'Column'],
135+
// key: 'column',
136+
// task: 'insertColumn',
137+
// icon: <ColumnIcon />,
138+
// },
139139
{
140140
label: ['引用', 'Quote'],
141141
key: 'quote',
@@ -666,34 +666,47 @@ export const InsertAutocomplete: React.FC<InsertAutocompleteProps> = observer(
666666
{!state.insertLink && !state.insertAttachment && (
667667
<>
668668
<Menu
669-
items={state.filterOptions.map((l) => {
670-
return {
671-
label: l?.label?.[0],
672-
key: l?.key,
673-
icon: l.children?.[0]?.icon,
674-
children: l?.children?.map((el) => ({
675-
label: el.label[0],
676-
key: el.key,
677-
icon: el.icon,
678-
onClick: (_) => {
679-
_.domEvent.stopPropagation();
680-
_.domEvent.preventDefault();
681-
const task = state.options[state.index];
682-
if (!task) {
683-
const myInsertOptions = props?.insertOptions?.find?.(
684-
(o) => o.key === el.key,
685-
);
686-
if (!myInsertOptions) return;
687-
runInsertTask(myInsertOptions, {
688-
isCustom: true,
689-
});
690-
return;
691-
}
692-
runInsertTask(task);
693-
},
694-
})),
695-
};
696-
})}
669+
items={state.filterOptions
670+
.map((l) => {
671+
return {
672+
label: l?.label?.[0],
673+
key: l?.key,
674+
icon: l.children?.[0]?.icon,
675+
children: l?.children?.map((el) => ({
676+
label: el.label[0],
677+
key: el.key,
678+
icon: el.icon,
679+
onClick: (_: any) => {
680+
_.domEvent.stopPropagation();
681+
_.domEvent.preventDefault();
682+
683+
const task = state.filterOptions
684+
.map((o) => o.children)
685+
.flat(1)
686+
.find((o) => {
687+
return o.key === el.key;
688+
});
689+
if (!task) {
690+
const myInsertOptions =
691+
props?.insertOptions?.find?.(
692+
(o) => o.key === el.key,
693+
);
694+
if (!myInsertOptions) return;
695+
runInsertTask(myInsertOptions, {
696+
isCustom: true,
697+
});
698+
return;
699+
} else {
700+
runInsertTask(task);
701+
}
702+
},
703+
})),
704+
};
705+
})
706+
.map((l) => {
707+
return l.children;
708+
})
709+
.flat(1)}
697710
/>
698711
</>
699712
)}

0 commit comments

Comments
 (0)