Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format code option to JS editor #1817

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"html2canvas": "^1.4.1",
"idb": "^7.0.2",
"js-base64": "^3.7.5",
"js-beautify": "^1.15.1",
"json5": "^2.2.3",
"jsonpath": "^1.1.1",
"jspdf": "^2.5.1",
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ html.dark {
}

body, :host {
font-family: 'Inter var' !important;
font-family: 'Inter var', sans-serif !important;
font-size: 16px !important;
font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
@apply bg-gray-50 dark:bg-gray-900 leading-normal;
Expand Down Expand Up @@ -131,4 +131,4 @@ pre {

.input-label {
@apply ml-1 text-sm text-gray-600 dark:text-gray-200;
}
}
4 changes: 2 additions & 2 deletions src/components/newtab/workflow/edit/EditInteractionBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
/>
</div>
<edit-autocomplete v-if="!hideSelector" class="mb-1">
<ui-input
<ui-textarea
v-if="!hideSelector"
:model-value="data.selector"
:placeholder="t('workflow.blocks.base.selector')"
autocomplete="off"
autoresize
class="w-full"
@change="updateData({ selector: $event })"
/>
Expand Down
19 changes: 16 additions & 3 deletions src/components/newtab/workflow/edit/EditJavascriptCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,16 @@
class="overflow-auto"
/>
<template v-if="!data.everyNewTab">
<p class="mt-1 flex justify-between text-sm">
<p class="mt-1 flex justify-between text-sm py-3">
<span>{{
t('workflow.blocks.javascript-code.availabeFuncs')
}}</span>
<span>
<span
class="cursor-pointer select-none underline pr-10"
@click="formatCode"
>format code</span
>
<span
class="cursor-pointer select-none underline"
@click="modifyWhiteSpace"
Expand Down Expand Up @@ -149,14 +154,15 @@
</div>
</template>
<script setup>
import { watch, reactive, defineAsyncComponent, inject } from 'vue';
import { defineAsyncComponent, inject, reactive, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { autocompletion } from '@codemirror/autocomplete';
import {
automaFuncsSnippets,
automaFuncsCompletion,
automaFuncsSnippets,
completeFromGlobalScope,
} from '@/utils/codeEditorAutocomplete';
import beautify from 'js-beautify';
import { store } from '../../settings/jsBlockWrap';

function modifyWhiteSpace() {
Expand Down Expand Up @@ -212,6 +218,13 @@ function updateData(value) {
function addScript() {
state.preloadScripts.push({ src: '', removeAfterExec: true });
}
function formatCode() {
try {
state.code = beautify.js(state.code, { indent_size: 2 });
} catch (error) {
console.error('Error formatting code:', error);
}
}

const codemirrorExts = [
autocompletion({
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/UiExpand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { watch, ref } from 'vue';
const props = defineProps({
modelValue: {
type: Boolean,
default: false,
default: true,
},
panelClass: {
type: String,
Expand Down
1 change: 0 additions & 1 deletion src/components/ui/UiTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
ref="textarea"
:value="modelValue"
class="ui-textarea ui-input bg-input w-full rounded-lg px-4 py-2 transition"
:class="{ 'overflow-hidden resize-none': autoresize }"
@input="emitValue"
@keyup="$emit('keyup', $event)"
@keydown="$emit('keydown', $event)"
Expand Down
Loading