diff --git a/ui/src/components/workflow/designer/nodes/_shared.tsx b/ui/src/components/workflow/designer/nodes/_shared.tsx index 708e9a8a..8fca70dc 100644 --- a/ui/src/components/workflow/designer/nodes/_shared.tsx +++ b/ui/src/components/workflow/designer/nodes/_shared.tsx @@ -23,7 +23,7 @@ const useInternalRenamingInput = ({ nodeRender }: { nodeRender: NodeRenderReturn const [inputVisible, setInputVisible] = useState(false); const [inputValue, setInputValue] = useState(""); - const handleNodeRenameClick = () => { + const showInput = () => { setInputVisible(true); setInputValue(nodeRender.data?.name); setTimeout(() => { @@ -31,12 +31,13 @@ const useInternalRenamingInput = ({ nodeRender }: { nodeRender: NodeRenderReturn }, 0); }; - const handleNodeNameChange = (value: string) => { - setInputValue(value); + const hideInput = () => { + setInputVisible(false); + setInputValue(nodeRender.data?.name); }; - const handleNodeNameConfirm = async (value: string) => { - value = value.trim(); + const handleInputBlur = async (e: React.FocusEvent) => { + const value = e.target.value.trim(); if (!value || value === (nodeRender.data?.name || "")) { setInputVisible(false); return; @@ -47,13 +48,37 @@ const useInternalRenamingInput = ({ nodeRender }: { nodeRender: NodeRenderReturn nodeRender.updateData({ ...nodeRender.data, name: value }); }; + const handleInputChange = (e: React.ChangeEvent) => { + setInputValue(e.target.value); + }; + + const handleInputMouseDown = (e: React.MouseEvent) => { + e.stopPropagation(); + }; + + const handleInputMouseUp = (e: React.MouseEvent) => { + e.stopPropagation(); + }; + + const handleInputPressEnter = (e: React.KeyboardEvent) => { + e.currentTarget.blur(); + }; + return { inputRef: inputRef, + inputProps: { + value: inputValue, + onBlur: handleInputBlur, + onChange: handleInputChange, + onPressEnter: handleInputPressEnter, + onMouseDown: handleInputMouseDown, + onMouseUp: handleInputMouseUp, + }, visible: inputVisible, value: inputValue, - onClick: handleNodeRenameClick, - onChange: handleNodeNameChange, - onConfirm: handleNodeNameConfirm, + + show: showInput, + hide: hideInput, }; }; @@ -296,14 +321,7 @@ export const BaseNode = ({ className, style, children, description }: BaseNodePr ); }; - const { - inputRef, - visible: inputVisible, - value: inputValue, - onClick: handleNodeRenameClick, - onChange: handleNodeNameChange, - onConfirm: handleNodeNameConfirm, - } = useInternalRenamingInput({ nodeRender }); + const { inputRef, inputProps, visible: inputVisible, show: showInput } = useInternalRenamingInput({ nodeRender }); return ( { switch (key) { case "rename": - handleNodeRenameClick(); + showInput(); break; } }} @@ -362,15 +380,7 @@ export const BaseNode = ({ className, style, children, description }: BaseNodePr {!playground.config.readonlyOrDisabled && (
- handleNodeNameConfirm(e.target.value)} - onChange={(e) => handleNodeNameChange(e.target.value)} - onPressEnter={(e) => e.currentTarget.blur()} - /> +
)} @@ -387,14 +397,7 @@ export const BranchNode = ({ className, style, children, description }: BranchNo const nodeRender = useNodeRenderContext(); const nodeRegistry = nodeRender.node.getNodeRegistry(); - const { - inputRef, - visible: inputVisible, - value: inputValue, - onClick: handleNodeRenameClick, - onChange: handleNodeNameChange, - onConfirm: handleNodeNameConfirm, - } = useInternalRenamingInput({ nodeRender }); + const { inputRef, inputProps, visible: inputVisible, show: showInput } = useInternalRenamingInput({ nodeRender }); return ( { switch (key) { case "rename": - handleNodeRenameClick(); + showInput(); break; } }} @@ -445,15 +448,7 @@ export const BranchNode = ({ className, style, children, description }: BranchNo {!playground.config.readonlyOrDisabled && (
- handleNodeNameConfirm(e.target.value)} - onChange={(e) => handleNodeNameChange(e.target.value)} - onPressEnter={(e) => e.currentTarget.blur()} - /> +
)}