Skip to content

Commit

Permalink
feat: add element selector when record workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed May 9, 2022
1 parent 467dfcd commit 7957883
Show file tree
Hide file tree
Showing 30 changed files with 1,338 additions and 531 deletions.
2 changes: 1 addition & 1 deletion src/assets/css/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@apply dark:border-gray-700;
}

:host, body {
body {
font-family: 'Inter var';
font-size: 16px;
font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
Expand Down
5 changes: 3 additions & 2 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ browser.webNavigation.onCommitted.addListener(

const lastFlow = recording.flows[recording.flows.length - 1];
const isClickSubmit =
lastFlow.id === 'event-click' && transitionType === 'form_submit';
lastFlow.id === 'event-click' &&
(transitionType === 'form_submit' || lastFlow.isClickLink);

if (isClickSubmit) return;

Expand Down Expand Up @@ -235,11 +236,11 @@ browser.tabs.onActivated.addListener(async ({ tabId }) => {
recording.activeTab = { id, url };
recording.flows.push({
id: 'switch-tab',
description: title,
data: {
url,
matchPattern: url,
createIfNoMatch: true,
description: title || url,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ import { tasks } from '@/utils/shared';
import EditForms from '@/components/newtab/workflow/edit/EditForms.vue';
import EditTriggerEvent from '@/components/newtab/workflow/edit/EditTriggerEvent.vue';
import EditScrollElement from '@/components/newtab/workflow/edit/EditScrollElement.vue';
import handleForms from '../blocksHandler/handlerForms';
import handleGetText from '../blocksHandler/handlerGetText';
import handleEventClick from '../blocksHandler/handlerEventClick';
import handelTriggerEvent from '../blocksHandler/handlerTriggerEvent';
import handleElementScroll from '../blocksHandler/handlerElementScroll';
import handleForms from '@/content/blocksHandler/handlerForms';
import handleGetText from '@/content/blocksHandler/handlerGetText';
import handleEventClick from '@/content/blocksHandler/handlerEventClick';
import handelTriggerEvent from '@/content/blocksHandler/handlerTriggerEvent';
import handleElementScroll from '@/content/blocksHandler/handlerElementScroll';
const props = defineProps({
selector: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
style="max-height: calc(100vh - 17rem)"
>
<ui-tab-panel value="attributes">
<app-element-list
<selector-element-list
:elements="selectedElements"
@highlight="$emit('highlight', $event)"
>
Expand All @@ -39,10 +39,10 @@
/>
</div>
</template>
</app-element-list>
</selector-element-list>
</ui-tab-panel>
<ui-tab-panel value="options">
<app-element-list
<selector-element-list
:elements="selectElements"
element-name="Select element options"
@highlight="
Expand Down Expand Up @@ -73,10 +73,10 @@
/>
</div>
</template>
</app-element-list>
</selector-element-list>
</ui-tab-panel>
<ui-tab-panel value="blocks">
<app-blocks
<selector-blocks
:elements="selectedElements"
:selector="elSelector"
@execute="$emit('execute', $event)"
Expand All @@ -86,8 +86,8 @@
</ui-tab-panels>
</template>
<script setup>
import AppBlocks from './AppBlocks.vue';
import AppElementList from './AppElementList.vue';
import SelectorBlocks from './SelectorBlocks.vue';
import SelectorElementList from './SelectorElementList.vue';
defineProps({
activeTab: {
Expand Down
File renamed without changes.
95 changes: 95 additions & 0 deletions src/components/content/shared/SharedElementHighlighter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<template>
<svg
class="automa-element-highlighter"
style="
height: 100%;
width: 100%;
top: 0;
left: 0;
pointer-events: none;
position: fixed;
z-index: 10;
"
>
<g v-for="(colors, key) in data" :key="key">
<rect
v-for="(item, index) in items[key]"
v-bind="{
x: item.x,
y: item.y,
width: item.width,
height: item.height,
'stroke-dasharray': item.outline ? '5,5' : null,
fill: getFillColor(item, colors),
stroke: getStrokeColor(item, colors),
}"
:key="key + index"
stroke-width="2"
></rect>
</g>
</svg>
</template>
<script setup>
import { onMounted, onBeforeUnmount } from 'vue';
import { debounce } from '@/utils/helper';
const props = defineProps({
disabled: {
type: Boolean,
default: false,
},
data: {
type: Object,
default: () => ({}),
},
items: {
type: Object,
default: () => ({}),
},
});
const emit = defineEmits(['update']);
let lastScrollPosY = window.scrollY;
let lastScrollPosX = window.scrollX;
const handleScroll = debounce(() => {
if (props.hide) return;
const yPos = window.scrollY - lastScrollPosY;
const xPos = window.scrollX - lastScrollPosX;
const updatePositions = (key) =>
props.items[key]?.map((item) => {
const copyItem = { ...item };
copyItem.x -= xPos;
copyItem.y -= yPos;
return copyItem;
}) || [];
Object.keys(props.data).forEach((key) => {
const newPositions = updatePositions(key);
emit('update', { key, items: newPositions });
});
lastScrollPosX = window.scrollX;
lastScrollPosY = window.scrollY;
}, 100);
function getFillColor(item, colors) {
if (item.outline) return null;
return item.highlight ? colors.fill : colors.activeFill || colors.fill;
}
function getStrokeColor(item, colors) {
return item.highlight ? colors.stroke : colors.activeStroke || colors.stroke;
}
onMounted(() => {
window.addEventListener('scroll', handleScroll);
});
onBeforeUnmount(() => {
window.removeEventListener('scroll', handleScroll);
});
</script>
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
<template>
<div class="flex items-center p-2 rounded-lg bg-accent">
<p class="flex-1">Connect a workflow</p>
</div>
<workflow-list
v-if="!activeWorkflow"
:workflows="state.workflows"
@select="state.activeWorkflow = $event"
/>
<div v-else class="mt-4 px-4 pb-4">
<div class="flex items-center">
<button class="group" @click="state.activeWorkflow = ''">
<div class="px-4 pb-4">
<div class="flex items-center mt-4">
<button @click="$emit('goBack')">
<v-remixicon
name="riArrowLeftLine"
class="group-hover:-translate-x-1 -ml-1 transition-transform align-bottom inline-block"
class="-ml-1 mr-1 align-bottom inline-block"
/>
</button>
<p class="flex-1 text-overflow font-semibold ml-1">
{{ activeWorkflow.name }}
<p class="font-semibold flex-1 text-overflow">
{{ workflow.name }}
</p>
</div>
<p class="mt-2">Select a block output to start</p>
<p class="mt-2">
{{ t('home.record.selectBlock') }}
</p>
<div
ref="editorContainer"
class="parent-drawflow h-40 min-h w-full rounded-lg bg-box-transparent"
class="parent-drawflow h-56 min-h w-full rounded-lg bg-box-transparent"
></div>
<workflow-add-block v-if="activeBlock" />
<ui-button
:disabled="!state.activeBlock"
variant="accent"
class="mt-6 w-full"
@click="startRecording"
>
{{ t('home.record.button') }}
</ui-button>
</div>
</template>
<script setup>
import {
shallowReactive,
computed,
watch,
ref,
getCurrentInstance,
shallowRef,
inject,
onMounted,
} from 'vue';
import browser from 'webextension-polyfill';
import { useI18n } from 'vue-i18n';
import { findTriggerBlock } from '@/utils/helper';
import drawflow from '@/lib/drawflow';
import WorkflowList from './WorkflowList.vue';
import WorkflowAddBlock from './WorkflowAddBlock.vue';
const rootElement = inject('rootElement');
const props = defineProps({
workflow: {
type: Object,
default: () => ({}),
},
});
const emit = defineEmits(['goBack', 'record']);
const { t } = useI18n();
const context = getCurrentInstance().appContext.app._context;
const editor = shallowRef(null);
const editorContainer = ref(null);
const activeBlock = shallowRef(null);
const state = shallowReactive({
workflows: [],
activeWorkflow: '',
activeBlock: null,
blockOutput: 'output_1',
});
const activeWorkflow = computed(() =>
state.workflows.find(({ id }) => id === state.activeWorkflow)
);
function onEditorClick(event) {
const [target] = event.composedPath();
const nodeEl = target.closest('.drawflow-node');
Expand All @@ -76,14 +75,23 @@ function onEditorClick(event) {
const nodeId = nodeEl.id.slice(5);
const node = editor.value.getNodeFromId(nodeId);
const outputs = Object.keys(node.outputs);
if (outputs.length === 0) {
alert(t('home.record.anotherBlock'));
state.activeBlock = null;
state.blockOutput = null;
return;
}
let outputEl = target.closest('.output');
if (outputEl) {
/* eslint-disable-next-line */
state.blockOutput = outputEl.classList[1];
outputEl.classList.add('active');
} else {
const firstOutput = Object.keys(node.outputs)[0];
const firstOutput = outputs[0];
state.blockOutput = firstOutput || '';
outputEl = nodeEl.querySelector(`.${firstOutput}`);
Expand All @@ -92,26 +100,35 @@ function onEditorClick(event) {
if (outputEl) outputEl.classList.add('active');
nodeEl.classList.add('selected');
activeBlock.value = node;
state.activeBlock = node;
}
}
function startRecording() {
const options = {
name: props.workflow.name,
workflowId: props.workflow.id,
connectFrom: {
id: state.activeBlock.id,
output: state.blockOutput,
},
};
watch(editorContainer, (element) => {
if (!activeWorkflow.value) return;
emit('record', options);
}
const flowData = activeWorkflow.value.drawflow;
onMounted(() => {
const flowData = props.workflow.drawflow;
const flow = typeof flowData === 'string' ? JSON.parse(flowData) : flowData;
const triggerBlock = findTriggerBlock(flow);
const editorInstance = drawflow(element, {
const editorInstance = drawflow(editorContainer.value, {
context,
options: {
zoom: 0.5,
zoom_min: 0.1,
zoom_max: 0.8,
minimap: true,
editor_mode: 'fixed',
rootElement: rootElement.shadowRoot,
},
});
Expand All @@ -134,13 +151,8 @@ watch(editorContainer, (element) => {
}
editor.value = editorInstance;
element.addEventListener('click', onEditorClick);
editorContainer.value.addEventListener('click', onEditorClick);
});
(async () => {
const { workflows } = await browser.storage.local.get('workflows');
state.workflows = (workflows || []).reverse();
})();
</script>
<style>
.output.active {
Expand Down
Loading

0 comments on commit 7957883

Please sign in to comment.