Ver Fonte

feat: add go-back and go-forward block

Ahmad Kholid há 3 anos atrás
pai
commit
b3f17c675b

+ 1 - 12
.eslintrc.js

@@ -40,18 +40,7 @@ module.exports = {
     ],
     // disallow reassignment of function parameters
     // disallow parameter object manipulation except for specific exclusions
-    'no-param-reassign': [
-      'error',
-      {
-        props: true,
-        ignorePropertyModificationsFor: [
-          'state', // for vuex state
-          'acc', // for reduce accumulators
-          'e', // for e.returnvalue
-          'arr',
-        ],
-      },
-    ],
+    'no-param-reassign': 'off',
     'import/no-extraneous-dependencies': 'off',
     // disallow default export over named export
     'import/prefer-default-export': 'off',

+ 54 - 1
src/background/blocks-handler.js

@@ -1,4 +1,3 @@
-/* to-do onError block options => continue or stop workflow */
 /* eslint-disable no-underscore-dangle */
 import browser from 'webextension-polyfill';
 import { objectHasKey } from '@/utils/helper';
@@ -34,6 +33,60 @@ export function trigger(block) {
   });
 }
 
+export function goBack(block) {
+  return new Promise((resolve, reject) => {
+    const nextBlockId = getBlockConnection(block);
+
+    if (!this.tabId) {
+      const error = new Error("Can't connect to a tab");
+      error.nextBlockId = nextBlockId;
+      reject(error);
+
+      return;
+    }
+
+    browser.tabs
+      .goBack(this.tabId)
+      .then(() => {
+        resolve({
+          nextBlockId,
+          data: '',
+        });
+      })
+      .catch((error) => {
+        error.nextBlockId = nextBlockId;
+        reject(error);
+      });
+  });
+}
+
+export function forwardPage(block) {
+  return new Promise((resolve, reject) => {
+    const nextBlockId = getBlockConnection(block);
+
+    if (!this.tabId) {
+      const error = new Error("Can't connect to a tab");
+      error.nextBlockId = nextBlockId;
+      reject(error);
+
+      return;
+    }
+
+    browser.tabs
+      .goForward(this.tabId)
+      .then(() => {
+        resolve({
+          nextBlockId,
+          data: '',
+        });
+      })
+      .catch((error) => {
+        error.nextBlockId = nextBlockId;
+        reject(error);
+      });
+  });
+}
+
 export function newTab(block) {
   return new Promise((resolve, reject) => {
     browser.tabs

+ 1 - 7
src/components/newtab/workflow/WorkflowBuilder.vue

@@ -98,13 +98,7 @@ export default {
       if (props.data) {
         /* to-do delete replace method */
         const data =
-          typeof props.data === 'string'
-            ? JSON.parse(
-                props.data
-                  .replace(/open-website/g, 'new-tab')
-                  .replace(/BlockOpenWebsite/g, 'BlockNewTab')
-              )
-            : props.data;
+          typeof props.data === 'string' ? JSON.parse(props.data) : props.data;
 
         editor.value.import(data);
       } else {

+ 4 - 0
src/lib/v-remixicon.js

@@ -1,6 +1,8 @@
 import vRemixicon from 'v-remixicon';
 import {
   riHome5Line,
+  riArrowGoBackLine,
+  riArrowGoForwardLine,
   riDatabase2Line,
   riSettings3Line,
   riWindowLine,
@@ -54,6 +56,8 @@ import {
 
 export const icons = {
   riHome5Line,
+  riArrowGoBackLine,
+  riArrowGoForwardLine,
   riDatabase2Line,
   riSettings3Line,
   riWindowLine,

+ 60 - 30
src/utils/shared.js

@@ -1,4 +1,4 @@
-/* to-do screenshot, assets, tab loaded, opened tab, and close tab block? */
+/* to-do screenshot, cookies, assets, tab loaded, opened tab, and close tab block? */
 /* prev and next page block? */
 
 export const tasks = {
@@ -24,6 +24,61 @@ export const tasks = {
       isUrlRegex: false,
     },
   },
+  'active-tab': {
+    name: 'Active tab',
+    description: 'Execute the next block on the current active tab',
+    icon: 'riWindowLine',
+    component: 'BlockBasic',
+    category: 'browser',
+    disableEdit: true,
+    inputs: 1,
+    outputs: 1,
+    allowedInputs: true,
+    maxConnection: 1,
+    data: {},
+  },
+  'new-tab': {
+    name: 'New tab',
+    description: 'Create a new tab',
+    icon: 'riGlobalLine',
+    component: 'BlockNewTab',
+    editComponent: 'EditTrigger',
+    category: 'browser',
+    inputs: 1,
+    outputs: 1,
+    allowedInputs: true,
+    maxConnection: 1,
+    data: {
+      url: '',
+      active: true,
+    },
+  },
+  'go-back': {
+    name: 'Go back',
+    description: 'Go back to the previous page',
+    icon: 'riArrowGoBackLine',
+    component: 'BlockBasic',
+    category: 'browser',
+    inputs: 1,
+    outputs: 1,
+    maxConnection: 1,
+    disableEdit: true,
+    allowedInputs: true,
+    data: {},
+  },
+  'forward-page': {
+    name: 'Go forward',
+    description: 'Go forward to the next page',
+    icon: 'riArrowGoForwardLine',
+    component: 'BlockBasic',
+    category: 'browser',
+    inputs: 1,
+    outputs: 1,
+    maxConnection: 1,
+    disableEdit: true,
+    allowedInputs: true,
+    data: {},
+  },
   'event-click': {
     name: 'Click element',
     icon: 'riCursorLine',
@@ -77,35 +132,6 @@ export const tasks = {
       dataColumn: '',
     },
   },
-  'active-tab': {
-    name: 'Active tab',
-    description: 'Execute the next block on the current active tab',
-    icon: 'riWindowLine',
-    component: 'BlockBasic',
-    category: 'general',
-    disableEdit: true,
-    inputs: 1,
-    outputs: 1,
-    allowedInputs: true,
-    maxConnection: 1,
-    data: {},
-  },
-  'new-tab': {
-    name: 'New tab',
-    description: 'Create a new tab',
-    icon: 'riGlobalLine',
-    component: 'BlockNewTab',
-    editComponent: 'EditTrigger',
-    category: 'general',
-    inputs: 1,
-    outputs: 1,
-    allowedInputs: true,
-    maxConnection: 1,
-    data: {
-      url: '',
-      active: true,
-    },
-  },
   'export-data': {
     name: 'Export data',
     icon: 'riDownloadLine',
@@ -291,6 +317,10 @@ export const categories = {
     name: 'Web interaction',
     color: 'bg-green-200',
   },
+  browser: {
+    name: 'Browser',
+    color: 'bg-orange-200',
+  },
   general: {
     name: 'General',
     color: 'bg-yellow-200',