Skip to content

Commit fa31ae2

Browse files
authored
Merge pull request #85 from haxzie/dev
Release
2 parents 42f806d + 016a22e commit fa31ae2

File tree

7 files changed

+87
-6
lines changed

7 files changed

+87
-6
lines changed

src/components/Editor.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export default {
274274
this.targetDropEditor = editor;
275275
},
276276
openDroppedFile(event) {
277+
event.preventDefault();
277278
const editorTopBeDropped = this.targetDropEditor;
278279
const fileId = this.getDraggingFileId;
279280
this.setDraggingId({ id: null });

src/components/Editors/CodeEditor/index.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export default {
3636
theme: "vs-dark",
3737
fontSize: 16,
3838
fontLigatures: true,
39+
wordWrap: "wordWrapColumn",
40+
wordWrapMinified: true,
41+
wrappingIndent: "indent",
3942
minimap: {
4043
enabled: false,
4144
},
@@ -69,7 +72,7 @@ export default {
6972
this.applyAppTheme();
7073
7174
try {
72-
this.resizeObserver = new ResizeObserver(_ => {
75+
this.resizeObserver = new ResizeObserver((_) => {
7376
editor.layout();
7477
});
7578
this.resizeObserver.observe(this.$refs.editor.$el);
@@ -90,6 +93,7 @@ export default {
9093
ts: "typescript",
9194
py: "python",
9295
json: "json",
96+
geojson: "json",
9397
html: "html",
9498
css: "css",
9599
md: "markdown",

src/components/TopBar.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export default {
125125
overflow: hidden;
126126
text-overflow: ellipsis;
127127
pointer-events: none;
128+
max-width: 120px;
128129
}
129130
130131
&:last-child {

src/models/vFile.model.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const fileTypes = {
55
DIRECTORY: "directory",
66
MARKDOWN: "markdown"
77
}
8+
9+
export const ALLOWED_FILES = [];
810
export default class VFile {
911
constructor({ id, parent, type = fileTypes.FILE, name, contents, created_at, editable }) {
1012
this.id = id || `${type}_${uuid()}`;

src/pages/Home.vue

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<template>
22
<main>
3-
<div id="main-layout" :class="[{ hidePanel: !getActivePanelId }]">
3+
<div
4+
id="main-layout"
5+
:class="[{ hidePanel: !getActivePanelId }]"
6+
@drop.prevent="captureDrop"
7+
@dragover.prevent
8+
>
49
<SideNavigationBar />
510
<div v-show="getActivePanelId" class="explorer-panel">
611
<FileExplorer v-if="getActivePanelId === 'explorer'" />
712
<SearchPanel :key="'search'" v-if="getActivePanelId === 'search'" />
813
</div>
914
<Editor />
1015
</div>
11-
<FileCreationModal/>
16+
<FileCreationModal />
1217
<CommandCenter />
1318
<SlideYUpTransition>
1419
<router-view></router-view>
@@ -22,9 +27,9 @@ import Editor from "@/components/Editor";
2227
import CommandCenter from "@/components/CommandCenter";
2328
import SideNavigationBar from "@/components/SideNavigationBar";
2429
import SearchPanel from "@/components/SearchPanel";
25-
import { mapGetters } from "vuex";
30+
import { mapActions, mapGetters } from "vuex";
2631
import { SlideYUpTransition } from "vue2-transitions";
27-
import FileCreationModal from "@/components/FileCreationModal"
32+
import FileCreationModal from "@/components/FileCreationModal";
2833
2934
export default {
3035
components: {
@@ -35,7 +40,7 @@ export default {
3540
SideNavigationBar,
3641
SearchPanel,
3742
SlideYUpTransition,
38-
FileCreationModal
43+
FileCreationModal,
3944
},
4045
data() {
4146
return {};
@@ -44,9 +49,36 @@ export default {
4449
...mapGetters("UI", ["getActivePanelId"]),
4550
},
4651
methods: {
52+
...mapActions("Files", ["createFile"]),
53+
...mapActions("Editor", ["openLocalFile"]),
4754
setActivePanel(optionId) {
4855
this.activePanel = optionId;
4956
},
57+
async captureDrop(event) {
58+
const { dataTransfer } = event;
59+
const files = dataTransfer.files;
60+
if (files && files.length > 0) {
61+
const filename = files[0]?.name;
62+
const regex = new RegExp(`.*[.geojson|.kml|.csv]`, "i");
63+
if (filename && regex.test(filename)) {
64+
const file = files[0];
65+
if (file.type.startsWith("image") || file.type.startsWith("video")) {
66+
// we donot support videos or images yet
67+
return;
68+
}
69+
// check file size, open only if below 10MB
70+
if (file.size / 1024 / 1024 < 10) {
71+
try {
72+
console.log(`Opening`, file);
73+
await this.openLocalFile({ file })
74+
} catch (error) {
75+
console.error(error);
76+
return;
77+
}
78+
}
79+
}
80+
}
81+
},
5082
},
5183
};
5284
</script>

src/store/modules/Editor/actions.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import OpenFileFootprint from "@/models/openFileFootprint.model";
33
import { EDITORS } from "./initialState";
44
import { saveAs } from "file-saver";
55
import fileStorage from "@/utils/StorageDrivers/IndexedDB"; // Switch storage drivers if needed
6+
import { wrap } from "comlink";
7+
const worker = new Worker("./fileLoader.worker.js", { type: "module" });
8+
const fileLoader = wrap(worker);
69

710
export default {
811
/**
@@ -38,6 +41,24 @@ export default {
3841
});
3942
},
4043

44+
/**
45+
* Opens a local file from a file object being passed
46+
* @param {Object} file
47+
* @param {String} editor
48+
*/
49+
openLocalFile: async ({ commit, state, dispatch }, { file, editor }) => {
50+
editor = editor || state.activeEditor;
51+
const fileData = await fileLoader.loadLocalFile(file);
52+
if (fileData) {
53+
const createdFile = await dispatch("Files/createFile", {
54+
name: file.name,
55+
contents: fileData,
56+
editable: false
57+
}, { root: true });
58+
dispatch("openFile", { id: createdFile.id, editor: editor });
59+
}
60+
},
61+
4162
/**
4263
* Opens a list of files in primary editor
4364
* @param {Object} context
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expose } from "comlink";
2+
3+
async function fileReader(file) {
4+
const reader = new FileReader();
5+
return new Promise((resolve, reject) => {
6+
reader.onload = () => resolve(reader.result);
7+
reader.onerror = (error) => reject(error);
8+
reader.readAsText(file);
9+
});
10+
}
11+
12+
async function loadLocalFile(file) {
13+
const text = await fileReader(file);
14+
return text;
15+
}
16+
17+
expose({
18+
loadLocalFile,
19+
fileReader,
20+
});

0 commit comments

Comments
 (0)