Skip to content

Commit

Permalink
Overhaul WiP
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrl-escp committed Jun 11, 2024
1 parent 8785a49 commit c43a5b8
Show file tree
Hide file tree
Showing 18 changed files with 2,074 additions and 3,633 deletions.
3,313 changes: 301 additions & 3,012 deletions package-lock.json

Large diffs are not rendered by default.

2,010 changes: 1,499 additions & 511 deletions public/flast.js

Large diffs are not rendered by default.

76 changes: 29 additions & 47 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<script setup>
import IconBandaid from './components/icons/IconBandaid.vue';
import IconGithub from './components/icons/IconGithub.vue';
import InputCodeEditor from './components/InputCodeEditor.vue';
import FileLoader from './components/FileLoader.vue';
import ParseButton from './components/ParseButton.vue';
import NodesList from './components/NodesList.vue';
import FilterEditor from './components/FilterEditor.vue';
import store from './store';
import {computed} from 'vue';
import ToasterView from './components/ToasterView.vue';
import ExplorationTab from './tabs/ExplorationTab.vue';
import IconGithub from './components/icons/IconGithub.vue';
import IconBandaid from './components/icons/IconBandaid.vue';
// import TransformationTab from './tabs/TransformationTab.vue';
const tabs = {
explore: ExplorationTab,
// transform: TransformationTab,
};
const availableTabs = computed(() => Object.keys(tabs));
const navItems = [
FileLoader,
ParseButton,
];
</script>

<template>
Expand All @@ -21,11 +23,9 @@ const navItems = [
<icon-bandaid/>
<span class="nav-title">fl<b>AST</b>er</span>
</span>
<span class="nav-items">
<span v-for="navItem of navItems" :key="navItem" class="nav-item">
<component :is="navItem"></component>
</span>
</span>
<!-- <span class="tabs">-->
<!-- <button class="btn tab-btn" v-for="tabName in availableTabs" :key="tabName" @click="store.currentTab = tabName">{{tabName}}</button>-->
<!-- </span>-->
<span title="View code on GitHub">
<a href="https://github.com/ctrl-escp/flaster" title="flASTer on GitHub">
<span class="github-text">View on GitHub</span>
Expand All @@ -34,15 +34,11 @@ const navItems = [
</span>
</nav>
</header>
<div class="panes">
<div class="pane-top">
<input-code-editor/>
<nodes-list/>
</div>
<div class="pane-bottom">
<filter-editor/>
</div>
</div>
<main>
<keep-alive>
<component :is="tabs[store.currentTab]"/>
</keep-alive>
</main>
<toaster-view/>
</template>

Expand All @@ -61,6 +57,10 @@ a:link {
margin-right: 10px;
}
main {
margin-top: .5rem;
}
nav {
background-color: #212121;
display: flex;
Expand All @@ -70,15 +70,6 @@ nav {
height: var(--nav-height);
}
.nav-items {
display: flex;
flex-direction: row;
}
.nav-item {
margin: 0 5px;
}
.nav-left {
display: flex;
align-items: center;
Expand All @@ -88,22 +79,13 @@ nav {
font-size: 2.4rem;
}
.pane-bottom {
flex: 1;
display: flex;
}
.tab-btn {
text-transform: capitalize;
.pane-top {
flex: 1;
display: flex;
flex-wrap: wrap;
}
.panes {
.tabs {
display: flex;
flex-direction: column;
height: calc(95vh - var(--nav-height));
gap: .2rem;
width: 100%;
gap: 1rem;
}
</style>
5 changes: 5 additions & 0 deletions src/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ body {
transform: translate(1px, 1px);
}

.btn:disabled {
transform: none;
cursor: not-allowed;
}

.highlighted-code {
background-color: rgba(255, 234, 0, 0.27);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import {store} from '../store.js';
import store from '../store';
import {ref, onMounted} from 'vue';
import {lintKeymap} from '@codemirror/lint';
import {EditorState} from '@codemirror/state';
Expand Down
22 changes: 22 additions & 0 deletions src/components/CodeViewSwitch.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script setup>
import {onMounted, ref} from 'vue';
import store from '../store';
const messages = {
isOriginal: 'Show Transformed Code',
isTransformed: 'Show Original Code',
};
const codeViewBtn = ref(null);
onMounted(() => {});
</script>

<template>
<button ref="codeViewBtn" class="btn" @click="store.isShowingTransformedCode = !store.isShowingTransformedCode" :disabled="!store.isTransformed">
{{ store.isShowingTransformedCode ? messages.isTransformed : messages.isOriginal }}
</button>
</template>

<style scoped>
</style>
16 changes: 5 additions & 11 deletions src/components/FileLoader.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script setup>
import store from '../store';
import {onMounted, ref} from 'vue';
import {store} from '../store.js';
const messages = {
noFile: 'Load file',
noFile: 'Load File',
loaded: '',
};
const status = ref(null);
const inputCodeEditorId = 'inputCodeEditor';
const inputCodeEditorId = store.editorIds.inputCodeEditor;
onMounted(() => {
if (status.value) status.value.innerText = messages.noFile;
Expand All @@ -20,18 +20,12 @@ function fileChanged(el) {
if (files.length) file = files[0];
if (file) {
file.text().then(c => {
const editor = store.getEditor(inputCodeEditorId);
editor.dispatch({
changes: [
{from: 0, to: editor.state.doc.length},
{from: 0, insert: c},
],
});
store.setContent(store.getEditor(inputCodeEditorId), c);
store.resetParsedState();
});
status.value.innerText = messages.loaded + file.name.substring(0, 30);
} else {
store.getEditor(inputCodeEditorId).dispatch({changes: {from: 0, insert: ''}});
store.setContent(store.getEditor(inputCodeEditorId), '');
status.value.innerText = messages.noFile;
store.resetParsedState();
}
Expand Down
18 changes: 8 additions & 10 deletions src/components/FilterEditor.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import store from '../store';
import {computed} from 'vue';
import {store} from '../store.js';
import CodeEditor from './CodeEditor.vue';
import IconCheckboxActive from './icons/IconCheckboxActive.vue';
import IconCheckboxInactive from './icons/IconCheckboxInactive.vue';
Expand All @@ -24,6 +24,7 @@ function applyFilter(filterSrc) {
try {
filterSrc = filterSrc.trim();
store.filteredNodes = store.filteredNodes.filter(eval(`n => ${filterSrc}`));
// noinspection JSCheckFunctionSignatures
store.filters.push({
src: filterSrc,
enabled: true,
Expand Down Expand Up @@ -75,14 +76,7 @@ function combineEnabledFilters() {
}
function setFilterEditorContent(filterSrc) {
const editor = store.getEditor(store.editorIds.filterEditor);
editor.dispatch({
changes: {
from: 0,
to: editor.state.doc.length,
insert: filterSrc
}
});
store.setContent(store.getEditor(store.editorIds.filterEditor),filterSrc);
}
</script>

Expand Down Expand Up @@ -133,6 +127,10 @@ function setFilterEditorContent(filterSrc) {
min-width: 41%;
}
.applied-filters-wrapper > fieldset {
min-width: 40vw;
}
.btn-apply {
background-color: greenyellow;
}
Expand Down Expand Up @@ -178,10 +176,10 @@ function setFilterEditorContent(filterSrc) {
.filter-line {
display: flex;
flex: 1;
}
.filter-src {
width: 900px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand Down
6 changes: 3 additions & 3 deletions src/components/InputCodeEditor.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import store from '../store';
import CodeEditor from './CodeEditor.vue';
import {store} from '../store.js';
const initialValue = `// This is the default code for flASTer
// Click the button at the top to load a file or paste directly into the editor
Expand All @@ -14,15 +14,15 @@ const initialValue = `// This is the default code for flASTer

<template>
<fieldset class="code-editor-wrapper">
<legend>Your code</legend>
<legend>Your code <span v-if="store.isShowingTransformedCode">(transformed)</span></legend>
<code-editor :editor-id="store.editorIds.inputCodeEditor" :initial-value="initialValue"/>
</fieldset>
</template>

<style scoped>
.code-editor-wrapper {
flex: 1;
min-width: 0;
min-width: 40vw;
padding: 0;
width: 100%;
height: 50vh;
Expand Down
3 changes: 2 additions & 1 deletion src/components/NodesList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import {store} from '../store.js';
import store from '../store';
import {computed, onMounted, reactive} from 'vue';
const state = reactive({
Expand Down Expand Up @@ -113,6 +113,7 @@ legend {
.node-src {
max-width: calc(50vw - 20rem);
min-width: 30vw;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand Down
13 changes: 6 additions & 7 deletions src/components/ParseButton.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script setup>
import store from '../store';
import {onMounted, ref} from 'vue';
import {store} from '../store.js';
const messages = {
parseContent: 'Parse content',
contentParsed: 'Content is parsed ',
astParseFail: 'Unable to parse AST',
emptyCode: 'No content',
parseContent: 'Parse Content',
contentParsed: 'Content is Parsed ',
astParseFail: 'Unable to Parse AST',
emptyCode: 'No Content',
};
const parsedStatusEl = ref(null);
Expand All @@ -33,7 +33,6 @@ function resetParsedState() {
store.ast = [];
store.matchingNodes = [];
setContentUnparsed();
store.updateNodesInfoMsg();
store.page = 0;
}
Expand All @@ -47,7 +46,7 @@ function parseContent() {
try {
resetParsedState();
const code = store.getEditor(store.editorIds.inputCodeEditor).state.doc.toString();
if (!code.length) store.logMessage(messages.emptyCode, 'error');
if (!code?.length) store.logMessage(messages.emptyCode, 'error');
else {
new Promise(() => {
store.filteredNodes = store.ast = [];
Expand Down
4 changes: 2 additions & 2 deletions src/components/ToasterView.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import {onMounted, reactive, ref} from 'vue';
import {store} from '../store.js';
import store from '../store';
import {onMounted, reactive} from 'vue';
import ToasterMessage from './ToasterMessage.vue';
const TOAST_TIMEOUT = 3.5 * 1000;
Expand Down
28 changes: 0 additions & 28 deletions src/store.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/store/exploration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default {

nodesPageSize: 100,
page: 0,
isContentParsed: false,
isTransformed: false,
isShowingTransformedCode: false,
filteredNodes: [],
filters: [],
areFiltersActive: true,
// placeholders
resetParsedState() {},
parseContent() {},
};
Loading

0 comments on commit c43a5b8

Please sign in to comment.