Skip to content

Commit

Permalink
use ts compiler to validate node body
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorS67 committed Nov 18, 2024
1 parent be101f3 commit 09d84bb
Show file tree
Hide file tree
Showing 42 changed files with 1,265 additions and 444 deletions.
26 changes: 26 additions & 0 deletions packages/app/src/apis/tscompiler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function useCreateNode() {
const createNode = useCallback(
async (
nodeType: string,
nodeSubType: string,
registerArgs?: Record<string, unknown>,
) => {
const node = await send('get-node', {
type: nodeType,
subType: nodeSubType,
registerArgs,
});

console.log(`create node: ${JSON.stringify(node)}`);

if (!node.error) {
return node;
}

return null;
},
[],
);

return { createNode };
}

Check failure on line 26 in packages/app/src/apis/tscompiler.ts

View workflow job for this annotation

GitHub Actions / Check linting

Insert `⏎`
97 changes: 57 additions & 40 deletions packages/app/src/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { debounce } from '@mui/material';
import { useLatest, useThrottleFn } from 'ahooks';
import { useRecoilValue } from 'recoil';

import { useStableCallback } from '../hooks/useStableCallback';
import { editingCodeIdState } from '../state/editor';
import { themeState } from '../state/settings';
import { CodeEditorProps } from '../types/editor.type';
import { getColorMode } from '../utils/colorMode';
Expand All @@ -20,7 +18,7 @@ export const CodeEditor: FC<CodeEditorProps> = ({
fontSize,
fontFamily,
isReadOnly,
autoFocus,
autoFocus = true,
showLineNumbers,
scrollBeyondLastLine = false,
theme,
Expand All @@ -36,53 +34,51 @@ export const CodeEditor: FC<CodeEditorProps> = ({

const appTheme = useRecoilValue(themeState);

const [tokenDisposable, setTokenDisposable] = useState<monaco.IDisposable>();
const [completionDisposable, setCompletionDisposable] =
useState<monaco.IDisposable>();
// const [tokenDisposable, setTokenDisposable] = useState<monaco.IDisposable>();
// const [completionDisposable, setCompletionDisposable] =
// useState<monaco.IDisposable>();

useEffect(() => {
return () => {
if (
tokenDisposable?.dispose &&
typeof tokenDisposable.dispose === 'function'
) {
tokenDisposable.dispose();
setTokenDisposable(undefined);
}
};
}, [tokenDisposable]);
// useEffect(() => {
// setTokenDisposable(defineTokens(keywords, properties, variables));

useEffect(() => {
return () => {
if (
completionDisposable?.dispose &&
typeof completionDisposable.dispose === 'function'
) {
completionDisposable.dispose();
setCompletionDisposable(undefined);
}
};
}, [completionDisposable]);
// return () => {
// if (
// tokenDisposable?.dispose &&
// typeof tokenDisposable.dispose === 'function'
// ) {
// tokenDisposable.dispose();
// }
// };
// }, []);

useEffect(() => {
if (!editorContainer.current) return;
// useEffect(() => {
// setCompletionDisposable(defineSuggestions(keywords, properties, variables));

if (!tokenDisposable) {
setTokenDisposable(defineTokens(keywords, properties, variables));
}
// return () => {
// console.log(`MONACO: ${typeof completionDisposable?.dispose}`)

if (!completionDisposable) {
setCompletionDisposable(
defineSuggestions(keywords, properties, variables),
);
}
// if (
// completionDisposable?.dispose &&
// typeof completionDisposable.dispose === 'function'
// ) {
// console.log('MONACO: defineSuggestions dispose')

// completionDisposable.dispose();
// }
// };
// }, []);

useEffect(() => {
if (!editorContainer.current) return;

const colorMode: string | null = getColorMode();
if (!colorMode) return;

const actualTheme: string =
theme === 'encre-code' || !theme ? `encre-code-${colorMode}` : theme;

const completionDisposable = defineSuggestions(keywords, properties, variables);

Check failure on line 80 in packages/app/src/components/CodeEditor.tsx

View workflow job for this annotation

GitHub Actions / Check linting

Replace `keywords,·properties,·variables` with `⏎······keywords,⏎······properties,⏎······variables,⏎····`

const editor = monaco.editor.create(editorContainer.current, {
theme: actualTheme,
lineNumbers: showLineNumbers ? 'on' : 'off',
Expand Down Expand Up @@ -128,7 +124,7 @@ export const CodeEditor: FC<CodeEditorProps> = ({
};

const contentHeight = editor.getContentHeight();
editorContainer.current.style.height = `${contentHeight}px`;
editorContainer.current.style.height = `${contentHeight + 100}px`;
editor.layout();

const onResizeDebounced = debounce(onResize, 300);
Expand All @@ -137,7 +133,7 @@ export const CodeEditor: FC<CodeEditorProps> = ({
editor.onDidChangeModelContent(() => {
onChangeLatest.current?.(editor.getValue());
if (editorContainer.current) {
editorContainer.current.style.height = `${editor.getContentHeight()}px`;
editorContainer.current.style.height = `${editor.getContentHeight() + 100}px`;

Check failure on line 136 in packages/app/src/components/CodeEditor.tsx

View workflow job for this annotation

GitHub Actions / Check linting

Replace `editor.getContentHeight()·+·100` with `⏎··········editor.getContentHeight()·+·100⏎········`
}

editor.layout();
Expand All @@ -150,9 +146,29 @@ export const CodeEditor: FC<CodeEditorProps> = ({

const latestBeforeDispose = onChangeLatest.current;

// setTokenDisposable(defineTokens(keywords, properties, variables));

// setCompletionDisposable(defineSuggestions(keywords, properties, variables));

// setCommandDisposable(defineCommands(keywords));

defineTokens(keywords, properties, variables);

return () => {
// const tokenDisposable = defineTokens(keywords, properties, variables);
// tokenDisposable.dispose();
// if (
// completionDisposable?.dispose &&
// typeof completionDisposable.dispose === 'function'
// ) {
// console.log('MONACO: defineSuggestions dispose')

// completionDisposable.dispose();
// }

latestBeforeDispose?.(editor.getValue());
editor.dispose();
completionDisposable.dispose();
window.removeEventListener('resize', onResizeDebounced);
};
}, []);
Expand Down Expand Up @@ -194,6 +210,7 @@ export const CodeEditor: FC<CodeEditorProps> = ({
style={{
minWidth: 0,
minHeight: 0,
maxHeight: '100%',
display: 'flex',
flex: 1,
height: '100%',
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/components/ConditionUIContextContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,15 @@ export const ConditionUIContextItem: FC<ConditionUIContextItemProps> = ({
)}
</div>

{selectedIndex !== undefined && selectedIndex === index ? (
{/* {selectedIndex !== undefined && selectedIndex === index ? (
<div className="ui-context-editor">
<KnownNodeContentBody
node={node}
uiContexts={[uiContext]}
onEditorClick={onConditionEditorClick}
/>
</div>
) : null}
) : null} */}
</>
);
};
10 changes: 6 additions & 4 deletions packages/app/src/components/MouseIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isDraggingMultipleCommentsState,
} from '../state/comment';
import { editingCodeIdState } from '../state/editor';
import { editingNodeIdState } from '../state/node';
import { isSelectingMultiWiresState } from '../state/wire';

export const MouseIcon: FC = () => {
Expand All @@ -30,26 +31,27 @@ export const MouseIcon: FC = () => {
isSelectingMultiWiresState,
);
const editingCodeId = useRecoilValue(editingCodeIdState);
const editingNodeId = useRecoilValue(editingNodeIdState);

useGlobalHotkey(
'Space',
useCallback(
(e: KeyboardEvent) => {
if (!editingCodeId) {
if (!editingNodeId) {
e.preventDefault();
setIsOnlyDraggingCanvas(true);
}
},
[editingCodeId],
[editingNodeId],
),
useCallback(
(e: KeyboardEvent) => {
if (!editingCodeId) {
if (!editingNodeId) {
e.preventDefault();
setIsOnlyDraggingCanvas(false);
}
},
[editingCodeId],
[editingNodeId],
),
);

Expand Down
4 changes: 3 additions & 1 deletion packages/app/src/components/NodeCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ export const NodeCanvas: FC<NodeCanvasProps> = ({
handleContextMenu,
} = useContextMenu();

useEditorClick();
useEditorClick({
onDeselect: () => setShowContextMenu(false)

Check failure on line 269 in packages/app/src/components/NodeCanvas.tsx

View workflow job for this annotation

GitHub Actions / Check linting

Insert `,`
});

const nodesToDrag = useMemo(() => {
return [...new Set([...draggingNodes, ...draggingNodesInComments])];
Expand Down
Loading

0 comments on commit 09d84bb

Please sign in to comment.