Skip to content

Commit c84c858

Browse files
committed
feat: add executable code blocks with 15+ languages, Monaco editor, and secure backend proxy
1 parent 4d2febc commit c84c858

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

.husky/pre-commit

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
echo "🔍 Running pre-commit checks..."
5+
6+
# Type checking
7+
echo "📝 Type checking..."
8+
npm run type-check
9+
if [ $? -ne 0 ]; then
10+
echo "❌ Type check failed"
11+
exit 1
12+
fi
13+
14+
# Linting
15+
echo "🔍 Linting..."
16+
npm run lint
17+
if [ $? -ne 0 ]; then
18+
echo "❌ Lint failed"
19+
exit 1
20+
fi
21+
22+
echo "✅ All pre-commit checks passed!"

src/components/editor/Editor/Toolbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ export function Toolbar({ editor }: ToolbarProps) {
399399
<Button
400400
variant={editor.isActive('executableCodeBlock') ? 'default' : 'ghost'}
401401
size="sm"
402-
onClick={() => editor.chain().focus().setExecutableCodeBlock({ language: 'javascript', executable: true }).run()}
402+
onClick={() => editor.chain().focus().setExecutableCodeBlock({ language: 'javascript' }).run()}
403403
title="Executable Code Block"
404404
>
405405
<Codesandbox className="h-4 w-4" />

src/components/editor/extensions/ExecutableCodeBlockNodeView.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ interface ExecutableCodeBlockNodeViewProps {
6060
attrs: {
6161
language?: string;
6262
executable?: boolean;
63+
output?: ExecutionResult | null;
6364
};
6465
textContent: string;
66+
nodeSize: number;
6567
};
6668
updateAttributes: (attributes: Record<string, unknown>) => void;
6769
selected: boolean;
68-
getPos: () => number;
70+
getPos: () => number | undefined;
6971
editor: TiptapEditor;
7072
}
7173

@@ -96,7 +98,7 @@ export function ExecutableCodeBlockNodeView({ node, updateAttributes, selected:
9698
const [isResizing, setIsResizing] = useState(false);
9799
const [monacoThemeOverride, setMonacoThemeOverride] = useState<'light' | 'dark'>('dark');
98100
const nodeRef = useRef<HTMLDivElement>(null);
99-
const updateTimeoutRef = useRef<NodeJS.Timeout>();
101+
const updateTimeoutRef = useRef<NodeJS.Timeout | undefined>(undefined);
100102
const monacoRef = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
101103
const resizeStartY = useRef<number>(0);
102104
const resizeStartHeight = useRef<number>(300);
@@ -138,8 +140,10 @@ export function ExecutableCodeBlockNodeView({ node, updateAttributes, selected:
138140
document.removeEventListener('mousemove', handleMouseMove);
139141
document.removeEventListener('mouseup', handleMouseUp);
140142
if (updateTimeoutRef.current) {
143+
if (updateTimeoutRef.current) {
141144
clearTimeout(updateTimeoutRef.current);
142145
}
146+
}
143147
};
144148
}, [isResizing]);
145149

@@ -186,7 +190,9 @@ export function ExecutableCodeBlockNodeView({ node, updateAttributes, selected:
186190
if (value !== undefined) {
187191
setCode(value);
188192
// Debounce the node content update to avoid performance issues
189-
clearTimeout(updateTimeoutRef.current);
193+
if (updateTimeoutRef.current) {
194+
clearTimeout(updateTimeoutRef.current);
195+
}
190196
updateTimeoutRef.current = setTimeout(() => {
191197
updateNodeContent(value);
192198
}, 300);
@@ -196,7 +202,7 @@ export function ExecutableCodeBlockNodeView({ node, updateAttributes, selected:
196202
const updateNodeContent = (newCode: string) => {
197203
try {
198204
const pos = getPos();
199-
if (pos >= 0) {
205+
if (pos !== undefined && pos >= 0) {
200206
const transaction = editor.view.state.tr.replaceWith(
201207
pos + 1,
202208
pos + node.nodeSize - 1,

src/components/editor/extensions/SlashCommands.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const commands: CommandItem[] = [
163163
editor.chain()
164164
.focus()
165165
.deleteRange(range)
166-
.setExecutableCodeBlock({ language: 'javascript', executable: true })
166+
.setExecutableCodeBlock({ language: 'javascript' })
167167
.insertContent('<p></p>')
168168
.run();
169169
},

0 commit comments

Comments
 (0)