improve merge class names

This commit is contained in:
codetypes committed 2024-04-28 21:03:07 +08:00
1 parent 4022f268e5
commit f09fd55343
2 files changed
+10 -9

No files matched your search

+9 -8
View File
@@ -991,6 +991,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
}; };
// check should rebuild graph
useEffect(() => { useEffect(() => {
if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) { if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) {
return; return;
@@ -1007,12 +1008,14 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
}); });
// check should subtree
useEffect(() => { useEffect(() => {
if (workspace.editing === editor) { if (workspace.editing === editor) {
checkSubtree(); checkSubtree();
} }
}, [workspace.editing]); }, [workspace.editing]);
// check should repaint node
useEffect(() => { useEffect(() => {
if (editor.graph) { if (editor.graph) {
editor.graph.changeData(editor.data); editor.graph.changeData(editor.data);
@@ -1021,11 +1024,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} }
}, [t]); }, [t]);
type MenuInfo = Parameters<Exclude<MenuProps["onClick"], undefined>>[0];
const onClick = useCallback((info: MenuInfo) => {
editor.dispatch(info.key as EditEvent);
}, []);
const nextResult = () => { const nextResult = () => {
if (results.length > 0) { if (results.length > 0) {
const idx = (resultIndex + 1) % results.length; const idx = (resultIndex + 1) % results.length;
@@ -1091,7 +1089,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
size="small" size="small"
className={mergeClassNames( className={mergeClassNames(
"b3-editor-button-filter", "b3-editor-button-filter",
filterCase ? "b3-editor-button-filter-selected" : "" filterCase && "b3-editor-button-filter-selected"
)} )}
icon={<VscCaseSensitive style={{ width: "18px", height: "18px" }} />} icon={<VscCaseSensitive style={{ width: "18px", height: "18px" }} />}
onClick={() => { onClick={() => {
@@ -1104,7 +1102,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
size="small" size="small"
className={mergeClassNames( className={mergeClassNames(
"b3-editor-button-filter", "b3-editor-button-filter",
filterFocus ? "b3-editor-button-filter-selected" : "" filterFocus && "b3-editor-button-filter-selected"
)} )}
icon={<RiFocus3Line />} icon={<RiFocus3Line />}
onClick={() => setFilterFocus(!filterFocus)} onClick={() => setFilterFocus(!filterFocus)}
@@ -1147,7 +1145,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
</Flex> </Flex>
)} )}
<Dropdown menu={{ items: menuItems, onClick }} trigger={["contextMenu"]}> <Dropdown
menu={{ items: menuItems, onClick: (info) => editor.dispatch(info.key as EditEvent) }}
trigger={["contextMenu"]}
>
<div tabIndex={-1} style={{ width: "100%", height: "100%" }} ref={graphRef} /> <div tabIndex={-1} style={{ width: "100%", height: "100%" }} ref={graphRef} />
</Dropdown> </Dropdown>
</div> </div>
+1 -1
View File
@@ -10,6 +10,6 @@ export const writeJson = (path: string, data: any) => {
fs.writeFileSync(path, str, "utf-8"); fs.writeFileSync(path, str, "utf-8");
}; };
export function mergeClassNames(...cls: string[]): string { export function mergeClassNames(...cls: (string | boolean)[]): string {
return cls.filter((v) => !!v).join(" "); return cls.filter((v) => !!v).join(" ");
} }