Browse Source

feat: handle submit event when recording

Ahmad Kholid 3 years ago
parent
commit
0ba96bf67a

+ 1 - 2
src/background/index.js

@@ -188,13 +188,12 @@ browser.commands.onCommand.addListener((name) => {
 browser.webNavigation.onCommitted.addListener(
 browser.webNavigation.onCommitted.addListener(
   ({ frameId, tabId, url, transitionType }) => {
   ({ frameId, tabId, url, transitionType }) => {
     const allowedType = ['link', 'typed', 'form_submit'];
     const allowedType = ['link', 'typed', 'form_submit'];
-
     if (frameId !== 0 || !allowedType.includes(transitionType)) return;
     if (frameId !== 0 || !allowedType.includes(transitionType)) return;
 
 
     updateRecording((recording) => {
     updateRecording((recording) => {
       if (tabId !== recording.activeTab.id) return;
       if (tabId !== recording.activeTab.id) return;
 
 
-      const lastFlow = recording.flows[recording.flows.length - 1];
+      const lastFlow = recording.flows.at(-1) ?? {};
       const isClickSubmit =
       const isClickSubmit =
         lastFlow.id === 'event-click' &&
         lastFlow.id === 'event-click' &&
         (transitionType === 'form_submit' || lastFlow.isClickLink);
         (transitionType === 'form_submit' || lastFlow.isClickLink);

+ 9 - 1
src/content/services/recordWorkflow/App.vue

@@ -182,6 +182,7 @@
       hoveredElements: selectState.hoveredElements,
       hoveredElements: selectState.hoveredElements,
       selectedElements: selectState.selectedElements,
       selectedElements: selectState.selectedElements,
     }"
     }"
+    style="z-index: 99999999"
     @update="selectState[$event.key] = $event.items"
     @update="selectState[$event.key] = $event.items"
   />
   />
   <teleport to="body">
   <teleport to="body">
@@ -194,6 +195,7 @@
         top: 0;
         top: 0;
         width: 100%;
         width: 100%;
         height: 100%;
         height: 100%;
+        background-color: rgba(0, 0, 0, 0.3);
       "
       "
     ></div>
     ></div>
   </teleport>
   </teleport>
@@ -338,6 +340,7 @@ function clearSelectState() {
   selectState.listId = '';
   selectState.listId = '';
   selectState.list = false;
   selectState.list = false;
   selectState.status = 'idle';
   selectState.status = 'idle';
+  selectState.isSelecting = false;
   selectState.hoveredElements = [];
   selectState.hoveredElements = [];
   selectState.selectedElements = [];
   selectState.selectedElements = [];
 
 
@@ -419,6 +422,7 @@ function onKeyup({ key }) {
 }
 }
 function startSelecting(list = false) {
 function startSelecting(list = false) {
   selectState.list = list;
   selectState.list = list;
+  selectState.isSelecting = true;
   selectState.status = 'selecting';
   selectState.status = 'selecting';
 
 
   document.body.setAttribute('automa-selecting', '');
   document.body.setAttribute('automa-selecting', '');
@@ -426,6 +430,8 @@ function startSelecting(list = false) {
   window.addEventListener('keyup', onKeyup);
   window.addEventListener('keyup', onKeyup);
 }
 }
 function onMousemove({ clientX, clientY, target: eventTarget }) {
 function onMousemove({ clientX, clientY, target: eventTarget }) {
+  if (!selectState.isSelecting) return;
+
   if (draggingState.dragging) {
   if (draggingState.dragging) {
     draggingState.xPos = clientX - mouseRelativePos.x;
     draggingState.xPos = clientX - mouseRelativePos.x;
     draggingState.yPos = clientY - mouseRelativePos.y;
     draggingState.yPos = clientY - mouseRelativePos.y;
@@ -469,6 +475,8 @@ function getElementPath(el, root = document.documentElement) {
   return path;
   return path;
 }
 }
 function onClick(event) {
 function onClick(event) {
+  if (!selectState.isSelecting) return;
+
   const { target: eventTarget, clientY, clientX } = event;
   const { target: eventTarget, clientY, clientX } = event;
 
 
   if (eventTarget.id === 'automa-recording') return;
   if (eventTarget.id === 'automa-recording') return;
@@ -578,7 +586,7 @@ onMounted(() => {
     .then(({ recording, workflows }) => {
     .then(({ recording, workflows }) => {
       const workflow = workflows.find(({ id }) => recording.workflowId === id);
       const workflow = workflows.find(({ id }) => recording.workflowId === id);
 
 
-      addBlockState.workflowColumns = workflow.table || [];
+      addBlockState.workflowColumns = workflow?.table || [];
     });
     });
 });
 });
 onBeforeUnmount(detachListeners);
 onBeforeUnmount(detachListeners);

+ 34 - 13
src/content/services/recordWorkflow/recordEvents.js

@@ -74,25 +74,46 @@ function changeListener({ target }) {
       recording.flows.pop();
       recording.flows.pop();
     }
     }
 
 
+    if (
+      block.data.type === 'text-field' &&
+      block.data.type === lastFlow?.data?.type
+    )
+      return;
+
     recording.flows.push(block);
     recording.flows.push(block);
   });
   });
 }
 }
-function keyEventListener({
-  target,
-  code,
-  key,
-  keyCode,
-  altKey,
-  ctrlKey,
-  metaKey,
-  shiftKey,
-  type,
-  repeat,
-}) {
+function keyEventListener(event) {
+  const {
+    target,
+    code,
+    key,
+    keyCode,
+    altKey,
+    ctrlKey,
+    metaKey,
+    shiftKey,
+    type,
+    repeat,
+  } = event;
   if (isAutomaInstance(target)) return;
   if (isAutomaInstance(target)) return;
 
 
   const isTextField = textFieldEl(target);
   const isTextField = textFieldEl(target);
-  if (isTextField) return;
+  if (isTextField) {
+    const enterKey = type === 'keydown' && key === 'Enter';
+    const inputEl = target.form && target.tagName === 'INPUT';
+
+    if (enterKey && inputEl) {
+      event.preventDefault();
+      target.dispatchEvent(new Event('change', { bubbles: true }));
+
+      setTimeout(() => {
+        target.form.submit();
+      }, 500);
+    }
+
+    return;
+  }
 
 
   const selector = finder(target);
   const selector = finder(target);