mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-21 20:55:12 -04:00
run prettier linter
This commit is contained in:
@@ -14,11 +14,9 @@ async function readFileContent(file) {
|
||||
// Check for common text file formats, to avoid
|
||||
// accidentally loading images or other files
|
||||
function isCodeFile(file) {
|
||||
const codeExtensions = [
|
||||
'.js', '.strudel', '.str'
|
||||
];
|
||||
const codeExtensions = ['.js', '.strudel', '.str'];
|
||||
const fileName = file.name.toLowerCase();
|
||||
return codeExtensions.some(ext => fileName.endsWith(ext)) || file.type.startsWith('text/');
|
||||
return codeExtensions.some((ext) => fileName.endsWith(ext)) || file.type.startsWith('text/');
|
||||
}
|
||||
|
||||
// Create drag and drop extension
|
||||
@@ -30,7 +28,7 @@ export const dragDropPlugin = ViewPlugin.fromClass(
|
||||
this.handleDragOver = this.handleDragOver.bind(this);
|
||||
this.handleDragEnter = this.handleDragEnter.bind(this);
|
||||
this.handleDragLeave = this.handleDragLeave.bind(this);
|
||||
|
||||
|
||||
// Add event listeners
|
||||
view.dom.addEventListener('drop', this.handleDrop);
|
||||
view.dom.addEventListener('dragover', this.handleDragOver);
|
||||
@@ -65,10 +63,10 @@ export const dragDropPlugin = ViewPlugin.fromClass(
|
||||
this.view.dom.classList.remove('cm-drag-over');
|
||||
|
||||
const files = Array.from(e.dataTransfer.files);
|
||||
|
||||
|
||||
// Filter for code files only
|
||||
const codeFiles = files.filter(isCodeFile);
|
||||
|
||||
|
||||
if (codeFiles.length === 0) {
|
||||
logger('No code files were dropped. Please drop text-based files.', 'warning');
|
||||
return;
|
||||
@@ -80,29 +78,27 @@ export const dragDropPlugin = ViewPlugin.fromClass(
|
||||
codeFiles.map(async (file) => {
|
||||
const content = await readFileContent(file);
|
||||
return `// File: ${file.name}\n${content}`;
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// Combine content
|
||||
const newContent = fileContents.join('\n\n');
|
||||
|
||||
|
||||
// Replace entire editor contents
|
||||
this.view.dispatch({
|
||||
changes: { from: 0, to: this.view.state.doc.length, insert: newContent },
|
||||
selection: { anchor: newContent.length }
|
||||
selection: { anchor: newContent.length },
|
||||
});
|
||||
|
||||
// Focus the editor
|
||||
this.view.focus();
|
||||
|
||||
|
||||
// Show success message
|
||||
const fileNames = codeFiles.map(f => f.name).join(', ');
|
||||
const fileNames = codeFiles.map((f) => f.name).join(', ');
|
||||
logger(`Successfully loaded ${codeFiles.length} file(s): ${fileNames}`, 'highlight');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error reading dropped files:', error);
|
||||
logger(`Error loading files: ${error.message}`, 'error');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,5 +108,5 @@ export const dragDropPlugin = ViewPlugin.fromClass(
|
||||
this.view.dom.removeEventListener('dragenter', this.handleDragEnter);
|
||||
this.view.dom.removeEventListener('dragleave', this.handleDragLeave);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
/* Drag and drop styles */
|
||||
#code .cm-editor.cm-drag-over {
|
||||
outline: 2px dashed #4CAF50;
|
||||
outline: 2px dashed #4caf50;
|
||||
outline-offset: -2px;
|
||||
background-color: rgba(76, 175, 80, 0.05) !important;
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ export default function DownloadButton({ context }) {
|
||||
const handleDownload = useCallback(() => {
|
||||
// Get the current code from the editor
|
||||
const code = context.editorRef?.current?.code || '';
|
||||
|
||||
|
||||
// Create a blob with the code
|
||||
const blob = new Blob([code], { type: 'text/javascript' });
|
||||
|
||||
|
||||
// Create a temporary URL for the blob
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
|
||||
|
||||
// Create a temporary anchor element and trigger download
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
@@ -18,7 +18,7 @@ export default function DownloadButton({ context }) {
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
|
||||
|
||||
// Clean up the URL
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, []);
|
||||
@@ -30,22 +30,10 @@ export default function DownloadButton({ context }) {
|
||||
title="Download pattern as .js file"
|
||||
aria-label="Download pattern"
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M8 12L3 7L4.4 5.6L7 8.2V0H9V8.2L11.6 5.6L13 7L8 12Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M14 14V10H16V16H0V10H2V14H14Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M8 12L3 7L4.4 5.6L7 8.2V0H9V8.2L11.6 5.6L13 7L8 12Z" fill="currentColor" />
|
||||
<path d="M14 14V10H16V16H0V10H2V14H14Z" fill="currentColor" />
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user