Skip to content

Commit

Permalink
Merge pull request #85 from haxzie/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
haxzie authored Jun 30, 2022
2 parents 42f806d + 016a22e commit fa31ae2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export default {
this.targetDropEditor = editor;
},
openDroppedFile(event) {
event.preventDefault();
const editorTopBeDropped = this.targetDropEditor;
const fileId = this.getDraggingFileId;
this.setDraggingId({ id: null });
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editors/CodeEditor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default {
theme: "vs-dark",
fontSize: 16,
fontLigatures: true,
wordWrap: "wordWrapColumn",
wordWrapMinified: true,
wrappingIndent: "indent",
minimap: {
enabled: false,
},
Expand Down Expand Up @@ -69,7 +72,7 @@ export default {
this.applyAppTheme();
try {
this.resizeObserver = new ResizeObserver(_ => {
this.resizeObserver = new ResizeObserver((_) => {
editor.layout();
});
this.resizeObserver.observe(this.$refs.editor.$el);
Expand All @@ -90,6 +93,7 @@ export default {
ts: "typescript",
py: "python",
json: "json",
geojson: "json",
html: "html",
css: "css",
md: "markdown",
Expand Down
1 change: 1 addition & 0 deletions src/components/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default {
overflow: hidden;
text-overflow: ellipsis;
pointer-events: none;
max-width: 120px;
}
&:last-child {
Expand Down
2 changes: 2 additions & 0 deletions src/models/vFile.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const fileTypes = {
DIRECTORY: "directory",
MARKDOWN: "markdown"
}

export const ALLOWED_FILES = [];
export default class VFile {
constructor({ id, parent, type = fileTypes.FILE, name, contents, created_at, editable }) {
this.id = id || `${type}_${uuid()}`;
Expand Down
42 changes: 37 additions & 5 deletions src/pages/Home.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<template>
<main>
<div id="main-layout" :class="[{ hidePanel: !getActivePanelId }]">
<div
id="main-layout"
:class="[{ hidePanel: !getActivePanelId }]"
@drop.prevent="captureDrop"
@dragover.prevent
>
<SideNavigationBar />
<div v-show="getActivePanelId" class="explorer-panel">
<FileExplorer v-if="getActivePanelId === 'explorer'" />
<SearchPanel :key="'search'" v-if="getActivePanelId === 'search'" />
</div>
<Editor />
</div>
<FileCreationModal/>
<FileCreationModal />
<CommandCenter />
<SlideYUpTransition>
<router-view></router-view>
Expand All @@ -22,9 +27,9 @@ import Editor from "@/components/Editor";
import CommandCenter from "@/components/CommandCenter";
import SideNavigationBar from "@/components/SideNavigationBar";
import SearchPanel from "@/components/SearchPanel";
import { mapGetters } from "vuex";
import { mapActions, mapGetters } from "vuex";
import { SlideYUpTransition } from "vue2-transitions";
import FileCreationModal from "@/components/FileCreationModal"
import FileCreationModal from "@/components/FileCreationModal";
export default {
components: {
Expand All @@ -35,7 +40,7 @@ export default {
SideNavigationBar,
SearchPanel,
SlideYUpTransition,
FileCreationModal
FileCreationModal,
},
data() {
return {};
Expand All @@ -44,9 +49,36 @@ export default {
...mapGetters("UI", ["getActivePanelId"]),
},
methods: {
...mapActions("Files", ["createFile"]),
...mapActions("Editor", ["openLocalFile"]),
setActivePanel(optionId) {
this.activePanel = optionId;
},
async captureDrop(event) {
const { dataTransfer } = event;
const files = dataTransfer.files;
if (files && files.length > 0) {
const filename = files[0]?.name;
const regex = new RegExp(`.*[.geojson|.kml|.csv]`, "i");
if (filename && regex.test(filename)) {
const file = files[0];
if (file.type.startsWith("image") || file.type.startsWith("video")) {
// we donot support videos or images yet
return;
}
// check file size, open only if below 10MB
if (file.size / 1024 / 1024 < 10) {
try {
console.log(`Opening`, file);
await this.openLocalFile({ file })
} catch (error) {
console.error(error);
return;
}
}
}
}
},
},
};
</script>
Expand Down
21 changes: 21 additions & 0 deletions src/store/modules/Editor/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import OpenFileFootprint from "@/models/openFileFootprint.model";
import { EDITORS } from "./initialState";
import { saveAs } from "file-saver";
import fileStorage from "@/utils/StorageDrivers/IndexedDB"; // Switch storage drivers if needed
import { wrap } from "comlink";
const worker = new Worker("./fileLoader.worker.js", { type: "module" });
const fileLoader = wrap(worker);

export default {
/**
Expand Down Expand Up @@ -38,6 +41,24 @@ export default {
});
},

/**
* Opens a local file from a file object being passed
* @param {Object} file
* @param {String} editor
*/
openLocalFile: async ({ commit, state, dispatch }, { file, editor }) => {
editor = editor || state.activeEditor;
const fileData = await fileLoader.loadLocalFile(file);
if (fileData) {
const createdFile = await dispatch("Files/createFile", {
name: file.name,
contents: fileData,
editable: false
}, { root: true });
dispatch("openFile", { id: createdFile.id, editor: editor });
}
},

/**
* Opens a list of files in primary editor
* @param {Object} context
Expand Down
20 changes: 20 additions & 0 deletions src/store/modules/Editor/fileLoader.worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expose } from "comlink";

async function fileReader(file) {
const reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
reader.readAsText(file);
});
}

async function loadLocalFile(file) {
const text = await fileReader(file);
return text;
}

expose({
loadLocalFile,
fileReader,
});

0 comments on commit fa31ae2

Please sign in to comment.