mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-07 12:16:04 +00:00
Merge pull request #242 from gnh1201/dev
Set throttle to the prompt context
This commit is contained in:
commit
26af578178
|
@ -2,7 +2,13 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>WelsonJS Editor</title>
|
<title>WelsonJS Editor</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta name="title" content="WelsonJS Editor">
|
||||||
|
<meta name="description" content="WelsonJS can build a Windows app on the Windows built-in JavaScript engine.">
|
||||||
|
<meta name="keywords" content="ecmascript, javascript, windows">
|
||||||
|
<meta name="robots" content="noindex, nofollow">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="language" content="English">
|
||||||
|
<meta name="author" content="Namhyeon Go (abuse@catswords.net)">
|
||||||
<style>
|
<style>
|
||||||
html, body, #app, #app > .app {
|
html, body, #app, #app > .app {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
@ -44,6 +50,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
<script src="http://localhost:3000/ajax/libs/lodash/4.17.21/lodash.min.js" integrity="sha384-H6KKS1H1WwuERMSm+54dYLzjg0fKqRK5ZRyASdbrI/lwrCc6bXEmtGYr5SwvP1pZ" crossorigin="anonymous"></script>
|
||||||
<script src="http://localhost:3000/ajax/libs/jsoneditor/10.1.3/jsoneditor.min.js" integrity="sha384-NdVVc20Tze856ZAWEoJNCk0mL4zJrGztRwULc5Hz25HUXQQgYtmjFtgVAxR4p5dD" crossorigin="anonymous"></script>
|
<script src="http://localhost:3000/ajax/libs/jsoneditor/10.1.3/jsoneditor.min.js" integrity="sha384-NdVVc20Tze856ZAWEoJNCk0mL4zJrGztRwULc5Hz25HUXQQgYtmjFtgVAxR4p5dD" crossorigin="anonymous"></script>
|
||||||
<script src="http://localhost:3000/ajax/libs/react/18.3.1/umd/react.production.min.js" integrity="sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z" crossorigin="anonymous"></script>
|
<script src="http://localhost:3000/ajax/libs/react/18.3.1/umd/react.production.min.js" integrity="sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z" crossorigin="anonymous"></script>
|
||||||
<script src="http://localhost:3000/ajax/libs/react-dom/18.3.1/umd/react-dom.production.min.js" integrity="sha384-gTGxhz21lVGYNMcdJOyq01Edg0jhn/c22nsx0kyqP0TxaV5WVdsSH1fSDUf5YJj1" crossorigin="anonymous"></script>
|
<script src="http://localhost:3000/ajax/libs/react-dom/18.3.1/umd/react-dom.production.min.js" integrity="sha384-gTGxhz21lVGYNMcdJOyq01Edg0jhn/c22nsx0kyqP0TxaV5WVdsSH1fSDUf5YJj1" crossorigin="anonymous"></script>
|
||||||
|
@ -185,11 +192,40 @@
|
||||||
if (!containerRef.current)
|
if (!containerRef.current)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const options = {};
|
const invoke = () => {
|
||||||
|
try {
|
||||||
|
if (promptEditorRef.current) {
|
||||||
|
const updated = promptEditorRef.current.get();
|
||||||
|
promptMessagesRef.current = updated;
|
||||||
|
} else {
|
||||||
|
throw new Error("promptEditorRef.current is null");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Invalid JSON structure", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const throttledInvoke = _.throttle(invoke, 300, {
|
||||||
|
leading: true,
|
||||||
|
trailing: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
onChange: throttledInvoke
|
||||||
|
};
|
||||||
|
|
||||||
const instance = new JSONEditor(containerRef.current, options);
|
const instance = new JSONEditor(containerRef.current, options);
|
||||||
instance.set(promptMessagesRef.current);
|
instance.set(promptMessagesRef.current);
|
||||||
|
|
||||||
promptEditorRef.current = instance;
|
promptEditorRef.current = instance;
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (instance) {
|
||||||
|
throttledInvoke.flush();
|
||||||
|
throttledInvoke.cancel();
|
||||||
|
instance.destroy();
|
||||||
|
}
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return _e('div', { id: 'promptEditor', ref: containerRef });
|
return _e('div', { id: 'promptEditor', ref: containerRef });
|
||||||
|
|
Loading…
Reference in New Issue
Block a user