toggle focus filter

This commit is contained in:
codetypes committed 2024-04-28 23:20:56 +08:00
1 parent 7b1d14c3b2
commit 118deb24d7
3 files changed
+64 -36

No files matched your search

+45 -28
View File
@@ -146,7 +146,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
filterFocus: false, filterFocus: false,
}); });
const onSearchChange = useDebounceCallback((option: FilterOption) => { const onSearchChange = (option: FilterOption) => {
option.results.length = 0; option.results.length = 0;
filterNodes(option, findDataById("1")); filterNodes(option, findDataById("1"));
setFilterOption({ setFilterOption({
@@ -159,7 +159,10 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
} else { } else {
selectNode(null); selectNode(null);
} }
}, 200); editor.graph.findAll("node", () => true).forEach((item) => item.draw());
};
const onDebounceSearchChange = useDebounceCallback(onSearchChange, 200);
const onChange = () => { const onChange = () => {
if (!editor.unsave) { if (!editor.unsave) {
@@ -224,33 +227,41 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
}; };
const filterNodes = (option: FilterOption, node: TreeGraphData | null) => { const filterNodes = (option: FilterOption, node: TreeGraphData | null) => {
if (node && option.filterStr) { if (node) {
if (includeString(node.name, option) || includeString(node.desc || node.def.desc, option)) { node.highlightGray = option.filterFocus;
option.results.push(node.id); if (option.filterStr) {
} else if (node.input) { let found = false;
for (const str of node.input) { if (includeString(node.name, option) || includeString(node.desc || node.def.desc, option)) {
if (includeString(str, option)) { found = true;
option.results.push(node.id); } else if (node.input) {
break; for (const str of node.input) {
if (includeString(str, option)) {
found = true;
break;
}
}
} else if (node.args) {
for (const str in node.args) {
if (includeString(str, option)) {
found = true;
break;
}
}
} else if (node.output) {
for (const str of node.output) {
if (includeString(str, option)) {
found = true;
break;
}
}
} else if (node.path) {
if (includeString(node.path, option)) {
found = true;
} }
} }
} else if (node.args) { if (found) {
for (const str in node.args) {
if (includeString(str, option)) {
option.results.push(node.id);
break;
}
}
} else if (node.output) {
for (const str of node.output) {
if (includeString(str, option)) {
option.results.push(node.id);
break;
}
}
} else if (node.path) {
if (includeString(node.path, option)) {
option.results.push(node.id); option.results.push(node.id);
node.highlightGray = false;
} }
} }
node.children?.forEach((child: TreeGraphData) => filterNodes(option, child)); node.children?.forEach((child: TreeGraphData) => filterNodes(option, child));
@@ -1102,7 +1113,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
paddingRight: "2px", paddingRight: "2px",
}} }}
onChange={(e) => onChange={(e) =>
onSearchChange({ onDebounceSearchChange({
...filterOption, ...filterOption,
filterStr: e.currentTarget.value, filterStr: e.currentTarget.value,
index: 0, index: 0,
@@ -1172,7 +1183,13 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
style={{ width: "30px" }} style={{ width: "30px" }}
onClick={() => { onClick={() => {
setShowingSearch(false); setShowingSearch(false);
setFilterOption({ ...filterOption, results: [], index: 0 }); onSearchChange({
results: [],
index: 0,
filterCase: false,
filterFocus: false,
filterStr: "",
});
keysRef.current?.focus(); keysRef.current?.focus();
}} }}
/> />
+18 -8
View File
@@ -90,6 +90,16 @@ G6.registerNode(
const h = size[1]; const h = size[1];
const r = 4; const r = 4;
let bgColor = "white";
let textColor = "black";
if (cfg.highlightGray) {
bgColor = "#0d1117";
color = "#30363d";
textColor = "#666";
console.log("hdight", cfg.id);
}
type ShapeCfg = Parameters<typeof group.addShape>[1]; type ShapeCfg = Parameters<typeof group.addShape>[1];
const addShape = (type: string, shapeCfg: ShapeCfg, clickEnabled: boolean = false) => { const addShape = (type: string, shapeCfg: ShapeCfg, clickEnabled: boolean = false) => {
shapeCfg.draggable = clickEnabled; shapeCfg.draggable = clickEnabled;
@@ -107,7 +117,7 @@ G6.registerNode(
height: h, height: h,
stroke: color, stroke: color,
lineWidth: 2, lineWidth: 2,
fill: "white", fill: bgColor,
radius: r, radius: r,
}, },
name: "main-box", name: "main-box",
@@ -171,7 +181,7 @@ G6.registerNode(
text: cfg.id, text: cfg.id,
textAlign: "right", textAlign: "right",
fill: "white", fill: "white",
stroke: "black", stroke: textColor,
lineWidth: 2, lineWidth: 2,
}, },
name: "id-text", name: "id-text",
@@ -217,7 +227,7 @@ G6.registerNode(
fontWeight: 800, fontWeight: 800,
lineHeight: 20, lineHeight: 20,
text: cfg.name, text: cfg.name,
fill: "black", fill: textColor,
}, },
name: "name-text", name: "name-text",
}); });
@@ -237,7 +247,7 @@ G6.registerNode(
lineHeight: 20, lineHeight: 20,
fontWeight: 800, fontWeight: 800,
text: `${desc}`, text: `${desc}`,
fill: "black", fill: textColor,
}, },
name: "desc-text", name: "desc-text",
}); });
@@ -254,7 +264,7 @@ G6.registerNode(
w, w,
lineHeight: 20, lineHeight: 20,
text: str, text: str,
fill: "black", fill: textColor,
}, },
name: "args-text", name: "args-text",
}); });
@@ -286,7 +296,7 @@ G6.registerNode(
y: y + 20, y: y + 20,
lineHeight: 20, lineHeight: 20,
text: str, text: str,
fill: cfg.highlightInput ? "white" : "black", fill: cfg.highlightInput ? "white" : textColor,
fontWeight: cfg.highlightInput ? "bolder" : undefined, fontWeight: cfg.highlightInput ? "bolder" : undefined,
}, },
name: "input-text", name: "input-text",
@@ -324,7 +334,7 @@ G6.registerNode(
y: y + 20, y: y + 20,
lineHeight: 20, lineHeight: 20,
text: str, text: str,
fill: cfg.highlightOutput ? "white" : "black", fill: cfg.highlightOutput ? "white" : textColor,
fontWeight: cfg.highlightOutput ? "bolder" : undefined, fontWeight: cfg.highlightOutput ? "bolder" : undefined,
}, },
name: "output-text", name: "output-text",
@@ -344,7 +354,7 @@ G6.registerNode(
y: y + 20, y: y + 20,
lineHeight: 20, lineHeight: 20,
text: `${path}`, text: `${path}`,
fill: "black", fill: textColor,
}, },
name: "subtree-text", name: "subtree-text",
}); });
+1
View File
@@ -61,6 +61,7 @@ export interface TreeGraphData extends G6TreeGraphData {
size?: number[]; size?: number[];
highlightInput?: boolean; highlightInput?: boolean;
highlightOutput?: boolean; highlightOutput?: boolean;
highlightGray?: boolean;
} }
export const unknownNodeDef: NodeDef = { export const unknownNodeDef: NodeDef = {