code review

This commit is contained in:
Chandler Abraham
2025-05-31 14:47:51 -07:00
parent b11de530f4
commit e3bc15a8d2
2 changed files with 5 additions and 31 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ import { initTheme, activateTheme, theme } from './themes.mjs';
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
import { widgetPlugin, updateWidgets } from './widget.mjs';
import { persistentAtom } from '@nanostores/persistent';
import { dragDropPlugin, dragDropStyles } from './dragdrop.mjs';
import { dragDropPlugin } from './dragdrop.mjs';
const extensions = {
isLineWrappingEnabled: (on) => (on ? EditorView.lineWrapping : []),
+4 -30
View File
@@ -11,13 +11,11 @@ async function readFileContent(file) {
});
}
// Helper function to check if file is a code file
// Check for common text file formats, to avoid
// accidentally loading images or other files
function isCodeFile(file) {
const codeExtensions = [
'.js', '.mjs', '.ts', '.tsx', '.jsx',
'.json', '.txt', '.md', '.tidal', '.strudel',
'.html', '.css', '.scss', '.yaml', '.yml',
'.xml', '.csv', '.log', '.ini', '.conf'
'.js', '.strudel', '.str'
];
const fileName = file.name.toLowerCase();
return codeExtensions.some(ext => fileName.endsWith(ext)) || file.type.startsWith('text/');
@@ -101,25 +99,10 @@ export const dragDropPlugin = ViewPlugin.fromClass(
const fileNames = codeFiles.map(f => f.name).join(', ');
logger(`Successfully loaded ${codeFiles.length} file(s): ${fileNames}`, 'highlight');
// Dispatch custom event for external notification handling
this.view.dom.dispatchEvent(new CustomEvent('files-dropped', {
detail: {
success: true,
fileCount: codeFiles.length,
fileNames: fileNames
}
}));
} catch (error) {
console.error('Error reading dropped files:', error);
logger(`Error loading files: ${error.message}`, 'error');
// Dispatch error event
this.view.dom.dispatchEvent(new CustomEvent('files-dropped', {
detail: {
success: false,
error: error.message
}
}));
}
}
@@ -130,13 +113,4 @@ export const dragDropPlugin = ViewPlugin.fromClass(
this.view.dom.removeEventListener('dragleave', this.handleDragLeave);
}
}
);
// CSS for drag over effect
export const dragDropStyles = `
.cm-editor.cm-drag-over {
outline: 2px dashed #4CAF50;
outline-offset: -2px;
background-color: rgba(76, 175, 80, 0.05);
}
`;
);