Skip to content

Commit

Permalink
v1.15.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Jul 11, 2022
2 parents 2d0d13e + ffb6552 commit ca3d4da
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.15.1",
"version": "1.15.2",
"description": "An extension for automating your browser by connecting blocks",
"license": "MIT",
"repository": {
Expand Down
50 changes: 23 additions & 27 deletions src/background/workflowEngine/blocksHandler/handlerBlocksGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,32 @@ function blocksGroup({ data, id }, { prevBlockData }) {
return;
}

if (!this.engine.extractedGroup[id]) {
const { blocks, connections } = data.blocks.reduce(
(acc, block, index) => {
const nextBlock = data.blocks[index + 1]?.itemId;

acc.blocks[block.itemId] = {
label: block.id,
data: block.data,
id: nextBlock ? block.itemId : id,
};

if (nextBlock) {
const outputId = `${block.itemId}-output-1`;

if (!acc.connections[outputId]) {
acc.connections[outputId] = [];
}
acc.connections[outputId].push(nextBlock);
}
const { blocks, connections } = data.blocks.reduce(
(acc, block, index) => {
const nextBlock = data.blocks[index + 1]?.itemId;

return acc;
},
{ blocks: {}, connections: {} }
);
acc.blocks[block.itemId] = {
label: block.id,
data: block.data,
id: nextBlock ? block.itemId : id,
};

Object.assign(this.engine.blocks, blocks);
Object.assign(this.engine.connectionsMap, connections);
if (nextBlock) {
const outputId = `${block.itemId}-output-1`;

this.engine.extractedGroup[id] = true;
}
if (!acc.connections[outputId]) {
acc.connections[outputId] = [];
}
acc.connections[outputId].push(nextBlock);
}

return acc;
},
{ blocks: {}, connections: {} }
);

Object.assign(this.engine.blocks, blocks);
Object.assign(this.engine.connectionsMap, connections);

resolve({
data: prevBlockData,
Expand Down
6 changes: 6 additions & 0 deletions src/components/newtab/settings/jsBlockWrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { reactive } from 'vue';

export const store = reactive({
whiteSpace: 'pre',
statePrettier: Math.random(),
});
30 changes: 30 additions & 0 deletions src/components/newtab/shared/SharedCodemirror.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { keymap } from '@codemirror/view';
import { javascript } from '@codemirror/lang-javascript';
import { EditorState } from '@codemirror/state';
import { EditorView, basicSetup } from 'codemirror';
import { format } from 'prettier';
import { store } from '../settings/jsBlockWrap';
import parserBabel from './parser-babel.mjs';
const props = defineProps({
lang: {
Expand Down Expand Up @@ -96,8 +99,35 @@ onMounted(() => {
onBeforeUnmount(() => {
view?.destroy();
});
let savedStatePrettier = store.statePrettier;
watch(store, (value) => {
if (value.statePrettier !== savedStatePrettier) {
// prettier logic here
const code = props.modelValue;
view.dispatch({
changes: {
from: 0,
to: view.state.doc.length,
insert: format(code, {
parser: 'babel',
plugins: [parserBabel],
}),
},
});
savedStatePrettier = value.statePrettier;
}
});
</script>
<style>
.cm-content {
flex-basis: fit-content;
}
.cm-line {
white-space: v-bind(store.whiteSpace);
}
.codemirror.hide-gutters .cm-gutters {
display: none !important;
}
Expand Down
27 changes: 27 additions & 0 deletions src/components/newtab/shared/parser-babel.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/newtab/workflow/WorkflowDetailsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</p>
<p
class="leading-tight cursor-pointer"
:class="descriptionCollapsed ? 'line-clamp' : null"
:class="descriptionCollapsed ? 'line-clamp' : 'whitespace-pre-wrap'"
@click="descriptionCollapsed = !descriptionCollapsed"
>
<!-- description here -->
Expand Down
28 changes: 26 additions & 2 deletions src/components/newtab/workflow/edit/EditJavascriptCode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,23 @@
class="overflow-auto"
/>
<template v-if="!data.everyNewTab">
<p class="mt-1 text-sm">
{{ t('workflow.blocks.javascript-code.availabeFuncs') }}
<p class="mt-1 text-sm flex justify-between">
<span>{{
t('workflow.blocks.javascript-code.availabeFuncs')
}}</span>
<span>
<span
class="underline cursor-pointer select-none"
@click="store.statePrettier = Math.random()"
>prettier</span
>
&bull;
<span
class="underline cursor-pointer select-none"
@click="modifyWhiteSpace"
>wrap line</span
>
</span>
</p>
<p
class="space-x-1 whitespace-nowrap overflow-x-auto overflow-y-hidden pb-1 scroll"
Expand Down Expand Up @@ -113,6 +128,15 @@ import { watch, reactive, defineAsyncComponent } from 'vue';
import { useI18n } from 'vue-i18n';
import { syntaxTree } from '@codemirror/language';
import { autocompletion, snippet } from '@codemirror/autocomplete';
import { store } from '../../settings/jsBlockWrap';
function modifyWhiteSpace() {
if (store.whiteSpace === 'pre') {
store.whiteSpace = 'pre-wrap';
} else {
store.whiteSpace = 'pre';
}
}
const SharedCodemirror = defineAsyncComponent(() =>
import('@/components/newtab/shared/SharedCodemirror.vue')
Expand Down
4 changes: 2 additions & 2 deletions src/composable/shortcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ export function useShortcut(shortcuts, handler) {
if (shortcutId) event.preventDefault();

if (typeof params.data === 'function') {
params.data(params);
params.data(params, event);
} else if (handler) {
handler(params);
handler(params, event);
}
};
const addShortcutData = ({ combo, id, readable, ...rest }) => {
Expand Down
21 changes: 16 additions & 5 deletions src/newtab/pages/workflows/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ import {
shallowRef,
onBeforeUnmount,
} from 'vue';
import cloneDeep from 'lodash.clonedeep';
import { getNodesInside } from '@braks/vue-flow';
import { useI18n } from 'vue-i18n';
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router';
Expand Down Expand Up @@ -809,14 +810,17 @@ function copyElements(nodes, edges, initialPos) {
}
}
return {
const copyNode = cloneDeep({
type,
data,
label,
id: newNodeId,
selected: true,
position: nodePos,
};
});
copyNode.data = reactive(copyNode.data);
return copyNode;
});
const newEdges = edges.reduce(
(acc, { target, targetHandle, source, sourceHandle }) => {
Expand All @@ -825,14 +829,15 @@ function copyElements(nodes, edges, initialPos) {
if (!targetId || !sourceId) return acc;
acc.push({
const copyEdge = cloneDeep({
selected: true,
target: targetId,
source: sourceId,
id: `edge-${nanoid()}`,
targetHandle: targetHandle.replace(target, targetId),
sourceHandle: sourceHandle.replace(source, sourceId),
});
acc.push(copyEdge);
return acc;
},
Expand Down Expand Up @@ -900,12 +905,18 @@ async function fetchConnectedTable() {
connectedTable.value = table;
}
function undoRedoCommand(type, { target }) {
const els = ['INPUT', 'SELECT', 'TEXTAREA'];
if (els.includes(target.tagName) || target.isContentEditable) return;
executeCommand(type);
}
const shortcut = useShortcut([
getShortcut('editor:toggle-sidebar', toggleSidebar),
getShortcut('editor:duplicate-block', duplicateElements),
getShortcut('action:undo', () => executeCommand('undo')),
getShortcut('action:redo', () => executeCommand('redo')),
getShortcut('action:undo', (_, event) => undoRedoCommand('undo', event)),
getShortcut('action:redo', (_, event) => undoRedoCommand('redo', event)),
]);
watch(
Expand Down

0 comments on commit ca3d4da

Please sign in to comment.