MCPcopy Create free account
hub / github.com/EsperoTech/yaade / ScriptTab

Function ScriptTab

client/src/components/scriptPanel/ScriptTab.tsx:52–126  ·  view source on GitHub ↗
({
  currentScript,
  dispatchCurrentScript,
}: ScriptTabProps)

Source from the content-addressed store, hash-verified

50});
51
52export default function ScriptTab({
53 currentScript,
54 dispatchCurrentScript,
55}: ScriptTabProps) {
56 const { colorMode } = useColorMode();
57 const toast = useToast();
58 const ref = useRef<HTMLDivElement>(null);
59 const extensions = [javascript(), theme, indentUnit.of(' ')];
60
61 const script = useMemo(
62 () => currentScript.data.script ?? '',
63 [currentScript.data.script],
64 );
65
66 const setScript = useCallback(
67 (s: string) => {
68 dispatchCurrentScript({
69 type: CurrentScriptActionType.PATCH_DATA,
70 data: { script: s },
71 });
72 },
73 [dispatchCurrentScript],
74 );
75
76 const { setContainer } = useCodeMirror({
77 container: ref.current,
78 onChange: (value: string) => setScript(value),
79 extensions: [extensions],
80 theme: colorMode,
81 value: script,
82 style: { height: '100%' },
83 });
84
85 useEffect(() => {
86 if (ref.current) {
87 setContainer(ref.current);
88 }
89 }, [ref, setContainer]);
90
91 function handleBeautifyClick() {
92 try {
93 const beautifiedBody = beautify(script, { format: 'js' });
94 setScript(beautifiedBody);
95 } catch (e) {
96 errorToast('Could not format script.', toast);
97 }
98 }
99
100 return (
101 <div style={{ height: '100%' }}>
102 <div className={styles.menu}>
103 <div style={{ display: 'flex', justifyContent: 'flex-end', width: '100%' }}>
104 <IconButton
105 aria-label="beautify-content"
106 isRound
107 variant="ghost"
108 size="xs"
109 onClick={handleBeautifyClick}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected