highlight args when click input/output
This commit is contained in:
1 parent
b9345c6706
commit
fea5e0cad8
4 files changed
+87
-19
No files matched your search
+70
-18
@@ -17,11 +17,11 @@ import { useShallow } from "zustand/react/shallow";
|
|||||||
import {
|
import {
|
||||||
EditEvent,
|
EditEvent,
|
||||||
EditNode,
|
EditNode,
|
||||||
EditTree,
|
|
||||||
EditorStore,
|
EditorStore,
|
||||||
|
EditTree,
|
||||||
useWorkspace,
|
useWorkspace,
|
||||||
} from "../contexts/workspace-context";
|
} from "../contexts/workspace-context";
|
||||||
import { NodeModel, TreeGraphData, TreeModel } from "../misc/b3type";
|
import { isExprType, NodeModel, TreeGraphData, TreeModel } from "../misc/b3type";
|
||||||
import * as b3util from "../misc/b3util";
|
import * as b3util from "../misc/b3util";
|
||||||
import { message } from "../misc/hooks";
|
import { message } from "../misc/hooks";
|
||||||
import i18n from "../misc/i18n";
|
import i18n from "../misc/i18n";
|
||||||
@@ -195,6 +195,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
|
|
||||||
const onSearchChange = (option: FilterOption) => {
|
const onSearchChange = (option: FilterOption) => {
|
||||||
option.results.length = 0;
|
option.results.length = 0;
|
||||||
|
editor.searchingText = option.filterStr;
|
||||||
filterNodes(option, editor.data);
|
filterNodes(option, editor.data);
|
||||||
setFilterOption({
|
setFilterOption({
|
||||||
...option,
|
...option,
|
||||||
@@ -237,11 +238,16 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const parseExpr = (expr: string) => {
|
||||||
|
return expr.split(/[^a-zA-Z0-9_]/);
|
||||||
|
};
|
||||||
|
|
||||||
const findHightlight = (node: TreeGraphData, highlight: string[], changed?: TreeGraphData[]) => {
|
const findHightlight = (node: TreeGraphData, highlight: string[], changed?: TreeGraphData[]) => {
|
||||||
changed ||= [];
|
changed ||= [];
|
||||||
if (node.highlightInput || node.highlightOutput) {
|
if (node.highlightInput || node.highlightOutput || node.highlightArgs) {
|
||||||
node.highlightInput = false;
|
node.highlightInput = false;
|
||||||
node.highlightOutput = false;
|
node.highlightOutput = false;
|
||||||
|
node.highlightArgs = false;
|
||||||
changed.push(node);
|
changed.push(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,6 +271,31 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node.def.args?.forEach((arg) => {
|
||||||
|
if (isExprType(arg.type)) {
|
||||||
|
const expr: string | string[] = node.args?.[arg.name];
|
||||||
|
if (typeof expr === "string") {
|
||||||
|
for (const v of parseExpr(expr)) {
|
||||||
|
if (highlight.includes(v)) {
|
||||||
|
node.highlightArgs = true;
|
||||||
|
changed.push(node);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (expr instanceof Array) {
|
||||||
|
loop: for (const str of expr) {
|
||||||
|
for (const v of parseExpr(str)) {
|
||||||
|
if (highlight.includes(v)) {
|
||||||
|
node.highlightArgs = true;
|
||||||
|
changed.push(node);
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
node.children?.forEach((child: TreeGraphData) => findHightlight(child, highlight, changed));
|
node.children?.forEach((child: TreeGraphData) => findHightlight(child, highlight, changed));
|
||||||
|
|
||||||
return changed;
|
return changed;
|
||||||
@@ -312,28 +343,32 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
includeString(node.desc || node.def.desc, option)
|
includeString(node.desc || node.def.desc, option)
|
||||||
) {
|
) {
|
||||||
found = true;
|
found = true;
|
||||||
} else if (node.input) {
|
}
|
||||||
|
if (!found && node.input) {
|
||||||
for (const str of node.input) {
|
for (const str of node.input) {
|
||||||
if (includeString(str, option)) {
|
if (includeString(str, option)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node.args) {
|
}
|
||||||
|
if (!found && node.args) {
|
||||||
for (const str in node.args) {
|
for (const str in node.args) {
|
||||||
if (includeString(str, option)) {
|
if (includeString(str, option) || includeString(node.args[str], option)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node.output) {
|
}
|
||||||
|
if (!found && node.output) {
|
||||||
for (const str of node.output) {
|
for (const str of node.output) {
|
||||||
if (includeString(str, option)) {
|
if (includeString(str, option)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (node.path) {
|
}
|
||||||
|
if (!found && node.path) {
|
||||||
if (includeString(node.path, option)) {
|
if (includeString(node.path, option)) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
@@ -847,10 +882,32 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
data.output?.forEach((v) => v && highlight.push(v));
|
data.output?.forEach((v) => v && highlight.push(v));
|
||||||
}
|
}
|
||||||
const changed = findHightlight(editor.data, highlight);
|
const changed = findHightlight(editor.data, highlight);
|
||||||
changed.forEach((v) => {
|
if (changed.length > 0) {
|
||||||
const item = editor.graph.findById(v.id);
|
const refreshHighlight = (node: TreeGraphData) => {
|
||||||
item.draw();
|
const item = editor.graph.findById(node.id);
|
||||||
});
|
if (highlight.length > 0) {
|
||||||
|
node.highlightGray = !(
|
||||||
|
node.highlightInput ||
|
||||||
|
node.highlightOutput ||
|
||||||
|
node.highlightArgs
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
node.highlightGray = false;
|
||||||
|
}
|
||||||
|
item.draw();
|
||||||
|
if (node.children) {
|
||||||
|
node.children.forEach(refreshHighlight);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
refreshHighlight(editor.data);
|
||||||
|
}
|
||||||
|
if (highlight.length === 0 && editor.searchingText) {
|
||||||
|
onSearchChange({
|
||||||
|
...filterOption,
|
||||||
|
filterType: "content",
|
||||||
|
filterStr: editor.searchingText,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.graph.on("node:contextmenu", (e: G6GraphEvent) => {
|
editor.graph.on("node:contextmenu", (e: G6GraphEvent) => {
|
||||||
@@ -1044,10 +1101,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
useKeyDown(Hotkey.Undo, keysRef, () => undo());
|
useKeyDown(Hotkey.Undo, keysRef, () => undo());
|
||||||
useKeyDown(Hotkey.Redo, keysRef, () => redo());
|
useKeyDown(Hotkey.Redo, keysRef, () => redo());
|
||||||
useKeyDown([Hotkey.Insert, Hotkey.Enter], keysRef, () => createNode());
|
useKeyDown([Hotkey.Insert, Hotkey.Enter], keysRef, () => createNode());
|
||||||
useKeyDown([Hotkey.Delete, Hotkey.Backspace], keysRef, () => {
|
useKeyDown([Hotkey.Delete, Hotkey.Backspace], keysRef, () => deleteNode());
|
||||||
console.log("delete");
|
|
||||||
deleteNode();
|
|
||||||
});
|
|
||||||
|
|
||||||
editor.dispatch = (event: EditEvent, data: unknown) => {
|
editor.dispatch = (event: EditEvent, data: unknown) => {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
@@ -1060,7 +1114,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "delete": {
|
case "delete": {
|
||||||
console.log("delete1");
|
|
||||||
deleteNode();
|
deleteNode();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1223,7 +1276,6 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
||||||
searchByType("id");
|
searchByType("id");
|
||||||
}
|
}
|
||||||
console.log(e.code);
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -351,6 +351,19 @@ G6.registerNode(
|
|||||||
const args: any = data.args;
|
const args: any = data.args;
|
||||||
if (nodeDef.args && args && Object.keys(args).length > 0) {
|
if (nodeDef.args && args && Object.keys(args).length > 0) {
|
||||||
const { str, line } = toBreakWord(`${i18n.t("regnode.args")}${JSON.stringify(args)}`, 200);
|
const { str, line } = toBreakWord(`${i18n.t("regnode.args")}${JSON.stringify(args)}`, 200);
|
||||||
|
if (data.highlightArgs) {
|
||||||
|
addShape("rect", {
|
||||||
|
attrs: {
|
||||||
|
x: x - 2,
|
||||||
|
y: y + 17,
|
||||||
|
width: w - 6,
|
||||||
|
height: 18,
|
||||||
|
fill: "#0d1117",
|
||||||
|
radius: [r, r, r, r],
|
||||||
|
},
|
||||||
|
name: "args-text-bg",
|
||||||
|
});
|
||||||
|
}
|
||||||
addShape("text", {
|
addShape("text", {
|
||||||
attrs: {
|
attrs: {
|
||||||
textBaseline: "top",
|
textBaseline: "top",
|
||||||
@@ -359,7 +372,8 @@ G6.registerNode(
|
|||||||
w,
|
w,
|
||||||
lineHeight: 20,
|
lineHeight: 20,
|
||||||
text: str,
|
text: str,
|
||||||
fill: textColor,
|
fill: data.highlightArgs ? "white" : textColor,
|
||||||
|
fontWeight: data.highlightArgs ? "bolder" : undefined,
|
||||||
},
|
},
|
||||||
name: "args-text",
|
name: "args-text",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export class EditorStore {
|
|||||||
unsave: boolean = false;
|
unsave: boolean = false;
|
||||||
modifiedTime: number = Date.now();
|
modifiedTime: number = Date.now();
|
||||||
alertReload: boolean = false;
|
alertReload: boolean = false;
|
||||||
|
searchingText?: string;
|
||||||
|
|
||||||
historyStack: NodeModel[] = [];
|
historyStack: NodeModel[] = [];
|
||||||
historyIndex: number = 0;
|
historyIndex: number = 0;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export interface TreeGraphData extends G6TreeGraphData {
|
|||||||
size?: number[];
|
size?: number[];
|
||||||
highlightInput?: boolean;
|
highlightInput?: boolean;
|
||||||
highlightOutput?: boolean;
|
highlightOutput?: boolean;
|
||||||
|
highlightArgs?: boolean;
|
||||||
highlightGray?: boolean;
|
highlightGray?: boolean;
|
||||||
status?: number;
|
status?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user