فهرست منبع

chore: remove unused files

Ahmad Kholid 2 سال پیش
والد
کامیت
8b16eeb038
7فایلهای تغییر یافته به همراه0 افزوده شده و 726 حذف شده
  1. 0 49
      src/popup/App.vue
  2. 0 11
      src/popup/index.html
  3. 0 20
      src/popup/index.js
  4. 0 382
      src/popup/pages/Home.vue
  5. 0 236
      src/popup/pages/Recording.vue
  6. 0 21
      src/popup/router.js
  7. 0 7
      webpack.config.js

+ 0 - 49
src/popup/App.vue

@@ -1,49 +0,0 @@
-<template>
-  <template v-if="retrieved">
-    <router-view />
-    <ui-dialog />
-  </template>
-</template>
-<script setup>
-import { ref, onMounted } from 'vue';
-import { useRouter } from 'vue-router';
-import browser from 'webextension-polyfill';
-import { useStore } from '@/stores/main';
-import { useWorkflowStore } from '@/stores/workflow';
-import { useHostedWorkflowStore } from '@/stores/hostedWorkflow';
-import { loadLocaleMessages, setI18nLanguage } from '@/lib/vueI18n';
-
-const store = useStore();
-const router = useRouter();
-const workflowStore = useWorkflowStore();
-const hostedWorkflowStore = useHostedWorkflowStore();
-
-const retrieved = ref(false);
-
-browser.storage.local.get('isRecording').then(({ isRecording }) => {
-  if (isRecording) router.push('/recording');
-});
-
-onMounted(async () => {
-  try {
-    await store.loadSettings();
-    await loadLocaleMessages(store.settings.locale, 'popup');
-    await setI18nLanguage(store.settings.locale);
-
-    await workflowStore.loadData();
-    await hostedWorkflowStore.loadData();
-
-    retrieved.value = true;
-  } catch (error) {
-    console.error(error);
-    retrieved.value = true;
-  }
-});
-</script>
-<style>
-body {
-  height: 500px;
-  width: 350px;
-  font-size: 16px;
-}
-</style>

+ 0 - 11
src/popup/index.html

@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <meta charset="UTF-8" />
-    <title></title>
-  </head>
-
-  <body>
-    <div id="app" class="scroll"></div>
-  </body>
-</html>

+ 0 - 20
src/popup/index.js

@@ -1,20 +0,0 @@
-import { createApp } from 'vue';
-import App from './App.vue';
-import router from './router';
-import pinia from '../lib/pinia';
-import compsUi from '../lib/compsUi';
-import vueI18n from '../lib/vueI18n';
-import vRemixicon, { icons } from '../lib/vRemixicon';
-import '../assets/css/tailwind.css';
-import '../assets/css/fonts.css';
-import '../assets/css/flow.css';
-
-createApp(App)
-  .use(router)
-  .use(compsUi)
-  .use(vueI18n)
-  .use(pinia)
-  .use(vRemixicon, icons)
-  .mount('#app');
-
-if (module.hot) module.hot.accept();

+ 0 - 382
src/popup/pages/Home.vue

@@ -1,382 +0,0 @@
-<template>
-  <div
-    :class="[!showTab ? 'h-48' : 'h-56']"
-    class="bg-accent rounded-b-2xl absolute top-0 left-0 w-full"
-  ></div>
-  <div
-    :class="[!showTab ? 'mb-6' : 'mb-2']"
-    class="dark placeholder-black relative z-10 text-white px-5 pt-8"
-  >
-    <div class="flex items-center mb-4">
-      <h1 class="text-xl font-semibold text-white">Automa</h1>
-      <div class="flex-grow"></div>
-      <ui-button
-        v-tooltip.group="t('home.record.title')"
-        icon
-        class="mr-2"
-        @click="state.newRecordingModal = true"
-      >
-        <v-remixicon name="riRecordCircleLine" />
-      </ui-button>
-      <ui-button
-        v-tooltip.group="
-          t(`home.elementSelector.${state.haveAccess ? 'name' : 'noAccess'}`)
-        "
-        icon
-        class="mr-2"
-        @click="initElementSelector"
-      >
-        <v-remixicon name="riFocus3Line" />
-      </ui-button>
-      <ui-button
-        v-tooltip.group="t('common.dashboard')"
-        icon
-        :title="t('common.dashboard')"
-        @click="openDashboard('')"
-      >
-        <v-remixicon name="riHome5Line" />
-      </ui-button>
-    </div>
-    <div class="flex">
-      <ui-input
-        v-model="state.query"
-        :placeholder="`${t('common.search')}...`"
-        autocomplete="off"
-        prepend-icon="riSearch2Line"
-        class="w-full search-input"
-      />
-    </div>
-    <ui-tabs
-      v-if="showTab"
-      v-model="state.activeTab"
-      fill
-      class="mt-1"
-      @change="onTabChange"
-    >
-      <ui-tab value="local">
-        {{ t(`home.workflow.type.local`) }}
-      </ui-tab>
-      <ui-tab v-if="hostedWorkflowStore.toArray.length > 0" value="host">
-        {{ t(`home.workflow.type.host`) }}
-      </ui-tab>
-      <ui-tab v-if="userStore.user?.teams" value="team"> Teams </ui-tab>
-    </ui-tabs>
-  </div>
-  <home-team-workflows
-    v-if="state.retrieved"
-    v-show="state.activeTab === 'team'"
-    :search="state.query"
-  />
-  <div
-    v-if="state.activeTab !== 'team'"
-    class="px-5 z-20 relative pb-5 space-y-2"
-  >
-    <ui-card v-if="workflowStore.getWorkflows.length === 0" class="text-center">
-      <img src="@/assets/svg/alien.svg" />
-      <p class="font-semibold">{{ t('message.empty') }}</p>
-      <ui-button
-        variant="accent"
-        class="mt-6"
-        @click="openDashboard('/workflows')"
-      >
-        {{ t('home.workflow.new') }}
-      </ui-button>
-    </ui-card>
-    <div v-if="pinnedWorkflows.length > 0" class="mt-1 mb-4 border-b pb-4">
-      <div class="flex items-center text-gray-300 mb-1">
-        <v-remixicon name="riPushpin2Line" size="20" class="mr-2" />
-        <span>Pinned workflows</span>
-      </div>
-      <home-workflow-card
-        v-for="workflow in pinnedWorkflows"
-        :key="workflow.id"
-        :workflow="workflow"
-        :tab="state.activeTab"
-        :pinned="true"
-        class="mb-2"
-        @details="openWorkflowPage"
-        @update="updateWorkflow(workflow.id, $event)"
-        @execute="executeWorkflow"
-        @rename="renameWorkflow"
-        @delete="deleteWorkflow"
-        @toggle-pin="togglePinWorkflow(workflow)"
-      />
-    </div>
-    <home-workflow-card
-      v-for="workflow in workflows"
-      :key="workflow.id"
-      :workflow="workflow"
-      :tab="state.activeTab"
-      :pinned="state.pinnedWorkflows.includes(workflow.id)"
-      @details="openWorkflowPage"
-      @update="updateWorkflow(workflow.id, $event)"
-      @execute="executeWorkflow"
-      @rename="renameWorkflow"
-      @delete="deleteWorkflow"
-      @toggle-pin="togglePinWorkflow(workflow)"
-    />
-  </div>
-  <ui-modal v-model="state.newRecordingModal" custom-content>
-    <ui-card
-      :style="{ height: `${state.cardHeight}px` }"
-      class="w-full recording-card overflow-hidden rounded-b-none"
-      padding="p-0"
-    >
-      <div class="flex items-center px-4 pt-4 pb-2">
-        <p class="flex-1 font-semibold">
-          {{ t('home.record.title') }}
-        </p>
-        <v-remixicon
-          class="text-gray-600 dark:text-gray-300 cursor-pointer"
-          name="riCloseLine"
-          size="20"
-          @click="state.newRecordingModal = false"
-        ></v-remixicon>
-      </div>
-      <home-start-recording
-        @record="recordWorkflow"
-        @close="state.newRecordingModal = false"
-        @update="state.cardHeight = recordingCardHeight[$event] || 255"
-      />
-    </ui-card>
-  </ui-modal>
-</template>
-<script setup>
-import { computed, onMounted, shallowReactive } from 'vue';
-import { useI18n } from 'vue-i18n';
-import browser from 'webextension-polyfill';
-import { useUserStore } from '@/stores/user';
-import { useDialog } from '@/composable/dialog';
-import { sendMessage } from '@/utils/message';
-import { useWorkflowStore } from '@/stores/workflow';
-import { useGroupTooltip } from '@/composable/groupTooltip';
-import { useTeamWorkflowStore } from '@/stores/teamWorkflow';
-import { useHostedWorkflowStore } from '@/stores/hostedWorkflow';
-import automa from '@business';
-import HomeWorkflowCard from '@/components/popup/home/HomeWorkflowCard.vue';
-import HomeTeamWorkflows from '@/components/popup/home/HomeTeamWorkflows.vue';
-import HomeStartRecording from '@/components/popup/home/HomeStartRecording.vue';
-
-const recordingCardHeight = {
-  new: 255,
-  existing: 480,
-};
-
-const { t } = useI18n();
-const dialog = useDialog();
-const userStore = useUserStore();
-const workflowStore = useWorkflowStore();
-const teamWorkflowStore = useTeamWorkflowStore();
-const hostedWorkflowStore = useHostedWorkflowStore();
-
-useGroupTooltip();
-
-const state = shallowReactive({
-  query: '',
-  teams: [],
-  cardHeight: 255,
-  retrieved: false,
-  haveAccess: true,
-  activeTab: 'local',
-  pinnedWorkflows: [],
-  newRecordingModal: false,
-});
-
-const pinnedWorkflows = computed(() => {
-  if (state.activeTab !== 'local') return [];
-
-  const list = [];
-  state.pinnedWorkflows.forEach((workflowId) => {
-    const workflow = workflowStore.getById(workflowId);
-    if (
-      !workflow ||
-      !workflow.name
-        .toLocaleLowerCase()
-        .includes(state.query.toLocaleLowerCase())
-    )
-      return;
-
-    list.push(workflow);
-  });
-
-  return list;
-});
-const hostedWorkflows = computed(() => {
-  if (state.activeTab !== 'host') return [];
-
-  return hostedWorkflowStore.toArray.filter((workflow) =>
-    workflow.name.toLocaleLowerCase().includes(state.query.toLocaleLowerCase())
-  );
-});
-const localWorkflows = computed(() => {
-  if (state.activeTab !== 'local') return [];
-
-  return workflowStore.getWorkflows
-    .filter(({ name }) =>
-      name.toLocaleLowerCase().includes(state.query.toLocaleLowerCase())
-    )
-    .sort((a, b) => (a.createdAt > b.createdAt ? -1 : 1));
-});
-const workflows = computed(() =>
-  state.activeTab === 'local' ? localWorkflows.value : hostedWorkflows.value
-);
-const showTab = computed(
-  () => hostedWorkflowStore.toArray.length > 0 || userStore.user?.teams
-);
-
-function togglePinWorkflow(workflow) {
-  const index = state.pinnedWorkflows.indexOf(workflow.id);
-  const copyData = [...state.pinnedWorkflows];
-
-  if (index === -1) {
-    copyData.push(workflow.id);
-  } else {
-    copyData.splice(index, 1);
-  }
-
-  state.pinnedWorkflows = copyData;
-  browser.storage.local.set({
-    pinnedWorkflows: copyData,
-  });
-}
-function executeWorkflow(workflow) {
-  sendMessage('workflow:execute', workflow, 'background');
-}
-function updateWorkflow(id, data) {
-  return workflowStore.update({
-    id,
-    data,
-  });
-}
-function renameWorkflow({ id, name }) {
-  dialog.prompt({
-    title: t('home.workflow.rename'),
-    placeholder: t('common.name'),
-    okText: t('common.rename'),
-    inputValue: name,
-    onConfirm: (newName) => {
-      updateWorkflow(id, { name: newName });
-    },
-  });
-}
-function deleteWorkflow({ id, name }) {
-  dialog.confirm({
-    title: t('home.workflow.delete'),
-    okVariant: 'danger',
-    body: t('message.delete', { name }),
-    onConfirm: () => {
-      if (state.activeTab === 'local') {
-        workflowStore.delete(id);
-      } else {
-        hostedWorkflowStore.delete(id);
-      }
-    },
-  });
-}
-function openDashboard(url) {
-  sendMessage('open:dashboard', url, 'background');
-}
-async function initElementSelector() {
-  const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
-  const result = await browser.tabs.sendMessage(tab.id, {
-    type: 'automa-element-selector',
-  });
-
-  if (!result) {
-    await browser.tabs.executeScript(tab.id, {
-      allFrames: true,
-      file: './elementSelector.bundle.js',
-    });
-  }
-
-  window.close();
-}
-async function recordWorkflow(options = {}) {
-  try {
-    const flows = [];
-    const [activeTab] = await browser.tabs.query({
-      active: true,
-      currentWindow: true,
-    });
-
-    if (activeTab && activeTab.url.startsWith('http')) {
-      flows.push({
-        id: 'new-tab',
-        description: activeTab.url,
-        data: { url: activeTab.url },
-      });
-    }
-
-    await browser.storage.local.set({
-      isRecording: true,
-      recording: {
-        flows,
-        name: 'unnamed',
-        activeTab: {
-          id: activeTab.id,
-          url: activeTab.url,
-        },
-        ...options,
-      },
-    });
-    await browser.browserAction.setBadgeBackgroundColor({ color: '#ef4444' });
-    await browser.browserAction.setBadgeText({ text: 'rec' });
-
-    const tabs = await browser.tabs.query({});
-    for (const tab of tabs) {
-      if (
-        tab.url.startsWith('http') &&
-        !tab.url.includes('chrome.google.com')
-      ) {
-        await browser.tabs.executeScript(tab.id, {
-          allFrames: true,
-          file: 'recordWorkflow.bundle.js',
-        });
-      }
-    }
-
-    window.close();
-  } catch (error) {
-    console.error(error);
-  }
-}
-function openWorkflowPage({ id, hostId }) {
-  let url = `/workflows/${id}`;
-
-  if (state.activeTab === 'host') {
-    url = `/workflows/${hostId}/host`;
-  }
-
-  openDashboard(url);
-}
-function onTabChange(value) {
-  localStorage.setItem('popup-tab', value);
-}
-
-onMounted(async () => {
-  const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
-  state.haveAccess = /^(https?)/.test(tab.url);
-
-  const storage = await browser.storage.local.get('pinnedWorkflows');
-  state.pinnedWorkflows = storage.pinnedWorkflows || [];
-
-  await userStore.loadUser({ storage: localStorage, ttl: 1000 * 60 * 5 });
-  await teamWorkflowStore.loadData();
-
-  let activeTab = localStorage.getItem('popup-tab') || 'local';
-
-  await automa('app');
-
-  if (activeTab === 'team' && !userStore.user?.teams) activeTab = 'local';
-  else if (activeTab === 'host' && hostedWorkflowStore.toArray.length < 0)
-    activeTab = 'local';
-
-  state.retrieved = true;
-  state.activeTab = activeTab;
-});
-</script>
-<style>
-.recording-card {
-  transition: height 300ms cubic-bezier(0.4, 0, 0.2, 1) !important;
-}
-</style>

+ 0 - 236
src/popup/pages/Recording.vue

@@ -1,236 +0,0 @@
-<template>
-  <div class="p-5">
-    <div class="flex items-center">
-      <button
-        v-tooltip="t('recording.stop')"
-        class="h-12 w-12 rounded-full focus:ring-0 bg-red-400 relative flex items-center justify-center"
-        @click="stopRecording"
-      >
-        <span
-          class="absolute animate-ping bg-red-400 rounded-full"
-          style="height: 80%; width: 80%; animation-duration: 1.3s"
-        ></span>
-        <ui-spinner v-if="state.isGenerating" color="text-white" />
-        <v-remixicon v-else name="riStopLine" class="z-10 relative" />
-      </button>
-      <div class="ml-4 flex-1 overflow-hidden">
-        <p class="text-sm">{{ t('recording.title') }}</p>
-        <p class="font-semibold text-xl leading-tight text-overflow">
-          {{ state.name }}
-        </p>
-      </div>
-    </div>
-    <p class="font-semibold mt-6 mb-2">Flows</p>
-    <ui-list class="space-y-1">
-      <ui-list-item
-        v-for="(item, index) in state.flows"
-        :key="index"
-        class="group"
-        small
-      >
-        <v-remixicon :name="tasks[item.id].icon" />
-        <div class="overflow-hidden flex-1 mx-2">
-          <p class="leading-tight">
-            {{ t(`workflow.blocks.${item.id}.name`) }}
-          </p>
-          <p
-            :title="item.data.description || item.description"
-            class="text-overflow text-sm leading-tight text-gray-600"
-          >
-            {{ item.data.description || item.description }}
-          </p>
-        </div>
-        <v-remixicon
-          name="riDeleteBin7Line"
-          class="invisible group-hover:visible cursor-pointer"
-          @click="removeBlock(index)"
-        />
-      </ui-list-item>
-    </ui-list>
-  </div>
-</template>
-<script setup>
-import { onMounted, reactive, toRaw } from 'vue';
-import { useI18n } from 'vue-i18n';
-import { useRouter } from 'vue-router';
-import { nanoid } from 'nanoid';
-import defu from 'defu';
-import browser from 'webextension-polyfill';
-import { tasks } from '@/utils/shared';
-import { useWorkflowStore } from '@/stores/workflow';
-
-const { t } = useI18n();
-const router = useRouter();
-const workflowStore = useWorkflowStore();
-
-const state = reactive({
-  name: '',
-  flows: [],
-  activeTab: {},
-  isGenerating: false,
-});
-
-function generateDrawflow(startBlock, startBlockData) {
-  let nextNodeId = nanoid();
-  const triggerId = startBlock?.id || nanoid();
-  let prevNodeId = startBlock?.id || triggerId;
-
-  const nodes = [];
-  const edges = [];
-
-  const addEdge = (data = {}) => {
-    edges.push({
-      ...data,
-      id: nanoid(),
-      class: `source-${data.sourceHandle} targte-${data.targetHandle}`,
-    });
-  };
-  addEdge({
-    source: prevNodeId,
-    target: nextNodeId,
-    targetHandle: `${nextNodeId}-input-1`,
-    sourceHandle: startBlock?.output || `${prevNodeId}-output-1`,
-  });
-
-  if (!startBlock) {
-    nodes.push({
-      position: {
-        x: 50,
-        y: 300,
-      },
-      id: triggerId,
-      label: 'trigger',
-      type: 'BlockBasic',
-      data: tasks.trigger.data,
-    });
-  }
-
-  const position = {
-    y: startBlockData ? startBlockData.position.y + 120 : 300,
-    x: startBlockData ? startBlockData.position.x + 280 : 320,
-  };
-  const groups = {};
-
-  state.flows.forEach((block, index) => {
-    if (block.groupId) {
-      if (!groups[block.groupId]) groups[block.groupId] = [];
-
-      groups[block.groupId].push({
-        id: block.id,
-        itemId: nanoid(),
-        data: defu(block.data, tasks[block.id].data),
-      });
-
-      const nextNodeInGroup = state.flows[index + 1]?.groupId;
-      if (nextNodeInGroup) return;
-
-      block.id = 'blocks-group';
-      block.data = { blocks: groups[block.groupId] };
-
-      delete groups[block.groupId];
-    }
-
-    const node = {
-      id: nextNodeId,
-      label: block.id,
-      type: tasks[block.id].component,
-      data: defu(block.data, tasks[block.id].data),
-      position: JSON.parse(JSON.stringify(position)),
-    };
-
-    prevNodeId = nextNodeId;
-    nextNodeId = nanoid();
-
-    if (index !== state.flows.length - 1) {
-      addEdge({
-        target: nextNodeId,
-        source: prevNodeId,
-        targetHandle: `${nextNodeId}-input-1`,
-        sourceHandle: `${prevNodeId}-output-1`,
-      });
-    }
-
-    const inNewRow = (index + 1) % 5 === 0;
-
-    position.x = inNewRow ? 50 : position.x + 280;
-    position.y = inNewRow ? position.y + 150 : position.y;
-
-    nodes.push(node);
-  });
-
-  return {
-    edges,
-    nodes,
-  };
-}
-async function stopRecording() {
-  if (state.isGenerating) return;
-
-  try {
-    state.isGenerating = true;
-
-    if (state.flows.length !== 0) {
-      if (state.workflowId) {
-        const workflow = workflowStore.getById(state.workflowId);
-        const startBlock = workflow.drawflow.nodes.find(
-          (node) => node.id === state.connectFrom.id
-        );
-        const updatedDrawflow = generateDrawflow(state.connectFrom, startBlock);
-
-        const drawflow = {
-          ...workflow.drawflow,
-          nodes: [...workflow.drawflow.nodes, ...updatedDrawflow.nodes],
-          edges: [...workflow.drawflow.edges, ...updatedDrawflow.edges],
-        };
-
-        await workflowStore.update({
-          id: state.workflowId,
-          data: { drawflow },
-        });
-      } else {
-        const drawflow = generateDrawflow();
-
-        await workflowStore.insert({
-          drawflow,
-          name: state.name,
-        });
-      }
-    }
-
-    await browser.storage.local.remove(['isRecording', 'recording']);
-    await browser.browserAction.setBadgeText({ text: '' });
-
-    const tabs = (await browser.tabs.query({})).filter((tab) =>
-      tab.url.startsWith('http')
-    );
-    Promise.allSettled(
-      tabs.map(({ id }) =>
-        browser.tabs.sendMessage(id, { type: 'recording:stop' })
-      )
-    );
-
-    state.isGenerating = false;
-
-    router.push('/');
-  } catch (error) {
-    state.isGenerating = false;
-    console.error(error);
-  }
-}
-function removeBlock(index) {
-  state.flows.splice(index, 1);
-
-  browser.storage.local.set({ recording: toRaw(state) });
-}
-
-onMounted(async () => {
-  const { recording, isRecording } = await browser.storage.local.get([
-    'recording',
-    'isRecording',
-  ]);
-
-  if (!isRecording && !recording) return;
-
-  Object.assign(state, recording);
-});
-</script>

+ 0 - 21
src/popup/router.js

@@ -1,21 +0,0 @@
-import { createRouter, createWebHashHistory } from 'vue-router';
-import Home from './pages/Home.vue';
-import Recording from './pages/Recording.vue';
-
-const routes = [
-  {
-    path: '/',
-    name: 'home',
-    component: Home,
-  },
-  {
-    path: '/recording',
-    name: 'recording',
-    component: Recording,
-  },
-];
-
-export default createRouter({
-  routes,
-  history: createWebHashHistory(),
-});

+ 0 - 7
webpack.config.js

@@ -42,7 +42,6 @@ const options = {
   entry: {
     sandbox: path.join(__dirname, 'src', 'sandbox', 'index.js'),
     newtab: path.join(__dirname, 'src', 'newtab', 'index.js'),
-    popup: path.join(__dirname, 'src', 'popup', 'index.js'),
     params: path.join(__dirname, 'src', 'params', 'index.js'),
     background: path.join(__dirname, 'src', 'background', 'index.js'),
     contentScript: path.join(__dirname, 'src', 'content', 'index.js'),
@@ -200,12 +199,6 @@ const options = {
       chunks: ['sandbox'],
       cache: false,
     }),
-    new HtmlWebpackPlugin({
-      template: path.join(__dirname, 'src', 'popup', 'index.html'),
-      filename: 'popup.html',
-      chunks: ['popup'],
-      cache: false,
-    }),
     new HtmlWebpackPlugin({
       template: path.join(__dirname, 'src', 'params', 'index.html'),
       filename: 'params.html',