Skip to content

Commit

Permalink
Merge pull request #332 from kentaro-m/issue-298
Browse files Browse the repository at this point in the history
Save text when textarea is unmounted
  • Loading branch information
kentaro-m authored Jan 29, 2025
2 parents 490845c + 349d97d commit 59715a5
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions packages/components/properties-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -760,17 +760,18 @@ function SystemPromptTextarea({
}
ref.dataset.refId = id;

function handleBlur() {
function updateValue() {
if (ref === null) {
return;
}
if (defaultValue !== ref.value) {
onValueChange?.(ref.value);
}
}
ref.addEventListener("blur", handleBlur);
ref.addEventListener("blur", updateValue);
return () => {
ref.removeEventListener("blur", handleBlur);
ref.removeEventListener("blur", updateValue);
updateValue();
};
}}
/>
Expand Down Expand Up @@ -1132,7 +1133,7 @@ function TabsContentPrompt({
return;
}

function handleBlur() {
function updateInstruction() {
if (ref === null) {
return;
}
Expand All @@ -1143,9 +1144,10 @@ function TabsContentPrompt({
});
}
}
ref.addEventListener("blur", handleBlur);
ref.addEventListener("blur", updateInstruction);
return () => {
ref.removeEventListener("blur", handleBlur);
ref.removeEventListener("blur", updateInstruction);
updateInstruction();
};
}}
/>
Expand Down Expand Up @@ -1532,17 +1534,18 @@ function TabContentText({
className="flex-1 text-[14px] bg-[hsla(222,21%,40%,0.3)] rounded-[8px] text-white p-[14px] font-rosart outline-none resize-none my-[16px]"
defaultValue={content.text}
ref={(el) => {
function handleBlur() {
function updateText() {
if (el?.value != null && content.text !== el.value) {
onContentChange?.({
...content,
text: el.value,
});
}
}
el?.addEventListener("blur", handleBlur);
el?.addEventListener("blur", updateText);
return () => {
el?.removeEventListener("blur", handleBlur);
el?.removeEventListener("blur", updateText);
updateText();
};
}}
/>
Expand Down

0 comments on commit 59715a5

Please sign in to comment.